Skip to content

Commit

Permalink
Export jwt and daemon packages (#843)
Browse files Browse the repository at this point in the history
* Export jwt and daemon packages

Signed-off-by: Marcos Candeia <[email protected]>

* Fix slow types

Signed-off-by: Marcos Candeia <[email protected]>

---------

Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia authored Sep 18, 2024
1 parent 9243f8f commit ff1f3c1
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 7 deletions.
2 changes: 1 addition & 1 deletion commons/jwt/jwks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const fetchKeyFromAddr = async (
if (!response.ok) {
return null;
}
const { keys = [] } = await response.json<JwksKeys>();
const { keys = [] } = await response.json() as JwksKeys;
const key = kid ? keys.find((key) => key?.kid === kid) ?? keys[0] : keys[0];
if (!key) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion commons/jwt/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const setFromString = (publicKey: string, privateKey: string) => {
/**
* Returns a tuple of [publicKey, privateKey] in a JsonWebKey format.
*/
export const getKeyPair = async () => {
export const getKeyPair = async (): Promise<[JsonWebKey, JsonWebKey]> => {
keys ??= getOrGenerateKeyPair();
return await keys;
};
3 changes: 3 additions & 0 deletions commons/jwt/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { newJwtIssuer } from "./jwt.ts";
export type { JwtIssuer } from "./jwt.ts";
export { getKeyPair } from "./keys.ts";
4 changes: 4 additions & 0 deletions daemon/cmd.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { iteratorFrom, logs } from "./loggings/stream.ts";

export interface CmdAPI {
response: null;
}

/**
* Returns a http handler that runs a command and pipes the output to the response
*/
Expand Down
2 changes: 1 addition & 1 deletion daemon/fs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export const createFSAPIs = () => {

const result = applyPatch(content, patch);

if (!result.conflict) {
if (!result.conflict && result.content) {
await ensureFile(filepath);
await Deno.writeTextFile(filepath, result.content);
}
Expand Down
10 changes: 8 additions & 2 deletions daemon/fs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ const applyJSONPatch = <T>(content: T, patch: Patch["payload"]) => {
}
};

export const applyPatch = (content: string | null, patch: Patch) => {
export const applyPatch = (content: string | null, patch: Patch): {
conflict: true | false;
content?: string;
} => {
if (patch.type === "json") {
const result = applyJSONPatch(JSON.parse(content ?? "{}"), patch.payload);

Expand Down Expand Up @@ -117,7 +120,10 @@ export const applyPatch = (content: string | null, patch: Patch) => {
throw new Error(`Unknown patch type: ${patch.type}`);
};

export const generatePatch = (from: string | null, to: string | null) => {
export const generatePatch = (
from: string | null,
to: string | null,
): Patch => {
try {
return {
type: "json" as const,
Expand Down
20 changes: 20 additions & 0 deletions daemon/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export type { CmdAPI } from "./cmd.ts";
export type { DeleteAPI, ListAPI, PatchAPI, ReadAPI } from "./fs/api.ts";
export { applyPatch, generatePatch } from "./fs/common.ts";
export type {
BlockMetadata,
GitStatus,
Metadata,
PageBlockMetadata,
Patch,
SyncUpdate,
} from "./fs/common.ts";
export type {
CheckoutAPI,
GitDiffAPI,
GitLogAPI,
GitStatusAPI,
PublishAPI,
RebaseAPI,
} from "./git.ts";
export type { DaemonEvent } from "./sse/channel.ts";
2 changes: 2 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"./blocks": "./blocks/mod.ts",
"./hooks": "./hooks/mod.ts",
"./scripts/run": "./daemon/main.ts",
"./daemon": "./daemon/mod.ts",
"./jwt": "./commons/jwt/mod.ts",
"./scripts/bundle": "./scripts/apps/bundle.ts",
"./scripts/dev": "./scripts/dev.ts"
},
Expand Down
4 changes: 3 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export type {
WorkflowContext,
} from "./blocks/mod.ts";
export * from "./commons/workflows/mod.ts";
export * from "./commons/workflows/types.ts";
export * as JsonViewer from "./components/JsonViewer.tsx";
export type { Framework } from "./components/section.tsx";
export * from "./deco.ts";
export { Context } from "./deco.ts";
export type { ValueType, WorkflowGen } from "./deps.ts";
export { ValueType } from "./deps.ts";
export type { WorkflowGen } from "./deps.ts";
export type {
Block,
BlockFromKey,
Expand Down
11 changes: 11 additions & 0 deletions mod.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ export {
proxy,
withManifest,
} from "./clients/withManifest.ts";
export type {
AvailableActions,
AvailableFunctions,
AvailableLoaders,
Invoke,
InvokeAsPayload,
InvokeResult,
ManifestAction,
ManifestFunction,
ManifestLoader,
} from "./utils/invoke.types.ts";
28 changes: 28 additions & 0 deletions scripts/codemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const runCodeMod = async (context?: CodeModContext): Promise<void> => {
yPrompt: false,
targets: [
rewriteImports({
"deco/blocks/mod.ts": {
Matcher: {
moduleSpecifier: EXPORTS.DECO,
},
},
"deco/runtime/htmx/mod.ts": {
asset: {
moduleSpecifier: EXPORTS.HTMX,
Expand Down Expand Up @@ -380,6 +385,16 @@ export const runCodeMod = async (context?: CodeModContext): Promise<void> => {
},
},
"deco/mod.ts": {
status: {
moduleSpecifier: EXPORTS.DECO,
},
Resolvable: {
moduleSpecifier: EXPORTS.DECO,
isTypeOnly: true,
},
shortcircuit: {
moduleSpecifier: EXPORTS.DECO,
},
LoaderReturnType: {
moduleSpecifier: EXPORTS.DECO,
isTypeOnly: true,
Expand Down Expand Up @@ -454,6 +469,10 @@ export const runCodeMod = async (context?: CodeModContext): Promise<void> => {
moduleSpecifier: EXPORTS.DECO,
isTypeOnly: true,
},
ActionContext: {
moduleSpecifier: EXPORTS.DECO,
isTypeOnly: true,
},
FnContext: {
moduleSpecifier: EXPORTS.DECO,
isTypeOnly: true,
Expand All @@ -476,6 +495,12 @@ export const runCodeMod = async (context?: CodeModContext): Promise<void> => {
notFound: {
moduleSpecifier: EXPORTS.DECO,
},
forbidden: {
moduleSpecifier: EXPORTS.DECO,
},
unauthorized: {
moduleSpecifier: EXPORTS.DECO,
},
badRequest: {
moduleSpecifier: EXPORTS.DECO,
},
Expand Down Expand Up @@ -561,6 +586,9 @@ export const runCodeMod = async (context?: CodeModContext): Promise<void> => {
PromiseOrValue: {
moduleSpecifier: EXPORTS.UTILS,
},
singleFlight: {
moduleSpecifier: EXPORTS.UTILS,
},
notUndefined: {
moduleSpecifier: EXPORTS.UTILS,
},
Expand Down
8 changes: 7 additions & 1 deletion utils/mod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export { default as JsonViewer } from "../components/JsonViewer.tsx";
export { isAwaitable, notUndefined } from "../engine/core/utils.ts";
export {
isAwaitable,
notUndefined,
singleFlight,
} from "../engine/core/utils.ts";
export type { PromiseOrValue } from "../engine/core/utils.ts";
export { decoManifestBuilder } from "../engine/manifest/manifestGen.ts";
export { adminUrlFor, isAdmin } from "./admin.ts";
export { readFromStream } from "./http.ts";
export { metabasePreview } from "./metabase.tsx";
export { tryOrDefault } from "./object.ts";
export type { DotNestedKeys } from "./object.ts";
export { createServerTimings } from "./timings.ts";

0 comments on commit ff1f3c1

Please sign in to comment.