alchemy 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/alchemize.d.ts +4 -0
- package/lib/alchemize.d.ts.map +1 -1
- package/lib/alchemize.js +4 -0
- package/lib/alchemize.js.map +1 -1
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +4 -0
- package/lib/apply.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +3 -2
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bound.d.ts +8 -0
- package/lib/cloudflare/bound.d.ts.map +1 -0
- package/lib/cloudflare/bound.js +2 -0
- package/lib/cloudflare/bound.js.map +1 -0
- package/lib/cloudflare/bucket.d.ts +3 -3
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js +1 -1
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/static-site.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +12 -6
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +14 -2
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/encrypt.d.ts +17 -0
- package/lib/encrypt.d.ts.map +1 -0
- package/lib/encrypt.js +45 -0
- package/lib/encrypt.js.map +1 -0
- package/lib/github/secret.d.ts +2 -1
- package/lib/github/secret.d.ts.map +1 -1
- package/lib/github/secret.js +21 -25
- package/lib/github/secret.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/input.d.ts +2 -1
- package/lib/input.d.ts.map +1 -1
- package/lib/output.d.ts +2 -1
- package/lib/output.d.ts.map +1 -1
- package/lib/output.js.map +1 -1
- package/lib/secret.d.ts +12 -0
- package/lib/secret.d.ts.map +1 -0
- package/lib/secret.js +30 -0
- package/lib/secret.js.map +1 -0
- package/lib/serde.d.ts +3 -0
- package/lib/serde.d.ts.map +1 -0
- package/lib/serde.js +37 -0
- package/lib/serde.js.map +1 -0
- package/lib/state.d.ts.map +1 -1
- package/lib/state.js +3 -2
- package/lib/state.js.map +1 -1
- package/package.json +3 -6
- package/src/alchemize.ts +9 -0
- package/src/apply.ts +3 -0
- package/src/cloudflare/bindings.ts +4 -2
- package/src/cloudflare/bound.ts +18 -0
- package/src/cloudflare/bucket.ts +3 -3
- package/src/cloudflare/static-site.ts +1 -1
- package/src/cloudflare/worker.ts +77 -59
- package/src/encrypt.ts +79 -0
- package/src/github/secret.ts +34 -33
- package/src/index.ts +1 -0
- package/src/input.ts +13 -10
- package/src/output.ts +13 -9
- package/src/secret.ts +41 -0
- package/src/serde.ts +46 -0
- package/src/state.ts +3 -2
package/lib/github/secret.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../../src/github/secret.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAgB,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../../src/github/secret.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAgB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA8ChE;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,QAAQ,CACxC,gBAAgB,EAChB,KAAK,EACH,GAAgC,EAChC,KAAwB,EACY,EAAE;IACtC,mFAAmF;IACnF,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAEjE,wCAAwC;IACxC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,gBAAgB,CAAC,OAAO,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W,CAAC,KAAK,CAAC,CAAC;IAE7C,uEAAuE;IACvE,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAEhE,0CAA0C;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AACzE,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export * from "./input";
|
|
|
6
6
|
export * from "./output";
|
|
7
7
|
export * from "./print";
|
|
8
8
|
export { Resource, type Context, type CreateContext, type DeleteContext, type UpdateContext, } from "./resource";
|
|
9
|
+
export * from "./secret";
|
|
9
10
|
export type { FileSystemStateStore as StateStore } from "./state";
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,oBAAoB,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,oBAAoB,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,QAAQ,GAKT,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,QAAQ,GAKT,MAAM,YAAY,CAAC;AACpB,cAAc,UAAU,CAAC"}
|
package/lib/input.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Output } from "./output";
|
|
2
|
+
import type { Secret } from "./secret";
|
|
2
3
|
export type Inputs<P extends any[]> = P extends [infer First, ...infer Rest] ? [Input<First>, ...Inputs<Rest>] : [];
|
|
3
|
-
export type Input<T = any> = T | Output<T> | (T extends any[] ? Inputs<T> : never) | (T extends string | number | boolean ? Output<T> : never) | (T extends object ? {
|
|
4
|
+
export type Input<T = any> = T extends Secret ? T | Output<T> : T | Output<T> | (T extends any[] ? Inputs<T> : never) | (T extends string | number | boolean ? Output<T> : never) | (T extends object ? {
|
|
4
5
|
[k in keyof T]: Input<T[k]>;
|
|
5
6
|
} : never);
|
|
6
7
|
//# sourceMappingURL=input.d.ts.map
|
package/lib/input.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GACxE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,GAC/B,EAAE,CAAC;AAEP,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GACxE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,GAC/B,EAAE,CAAC;AAEP,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,MAAM,GACzC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAET,CAAC,GACD,MAAM,CAAC,CAAC,CAAC,GACT,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GACrC,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GACzD,CAAC,CAAC,SAAS,MAAM,GACb;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5B,GACD,KAAK,CAAC,CAAC"}
|
package/lib/output.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Secret } from "./secret";
|
|
1
2
|
export declare function isOutput<T>(value: any): value is Output<T>;
|
|
2
3
|
export type Outputs<P extends readonly any[]> = P extends [
|
|
3
4
|
infer First,
|
|
@@ -13,7 +14,7 @@ export declare class OutputChain<T, U> {
|
|
|
13
14
|
apply<V>(fn: (value: U) => Output<V>): Output<V>;
|
|
14
15
|
apply<V>(fn: (value: U) => V): Output<V>;
|
|
15
16
|
}
|
|
16
|
-
export type Resolved<O> = O extends Output<infer U> ? U : O extends null ? O : O extends any[] ? ResolveN<O> : O extends object ? {
|
|
17
|
+
export type Resolved<O> = O extends Output<infer U> ? U : O extends Secret ? Secret : O extends null ? O : O extends any[] ? ResolveN<O> : O extends object ? {
|
|
17
18
|
[k in keyof O]: Resolved<O[k]>;
|
|
18
19
|
} : O;
|
|
19
20
|
type ResolveN<O extends any[]> = O extends [infer First, ...infer Rest] ? [Resolved<First>, ...ResolveN<Rest>] : [];
|
package/lib/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAI1D;AAED,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS;IACxD,MAAM,KAAK;IACX,GAAG,MAAM,IAAI;CACd,GACG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,OA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,CAAC,CAAC;AAEd,KAAK,QAAQ,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GACnE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,GACpC,EAAE,CAAC;AAGP,MAAM,MAAM,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,IAAI,GACtC,MAAM,CAAC,GAAG,CAAC,GACX,GAAG,SAAS,GAAG,EAAE,GACf,OAAO,CAAC,GAAG,CAAC,GACZ,GAAG,SAAS,MAAM,GAChB;KACG,CAAC,IAAI,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACjC,GACD,MAAM,CAAC,GAAG,CAAC,CAAC"}
|
package/lib/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAI,KAAU;IACpC,OAAO,CACL,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CACxE,CAAC;AACJ,CAAC;AAaD,MAAM,OAAO,WAAW;IAGJ;IAFF,EAAE,CAAkB;IACpC,YACkB,MAAiB,EACjC,EAAmB;QADH,WAAM,GAAN,MAAM,CAAW;QAGjC,IAAI,MAIS,CAAC;QACd,IAAI,CAAC,EAAE,GAAG,CAAC,KAAQ,EAAE,EAAE;YACrB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,MAAM,GAAG;oBACP,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;iBACjB,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC,KAAU,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;IAIM,KAAK,CAAI,EAAqB;QACnC,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;CACF"}
|
package/lib/secret.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Input } from "./input";
|
|
2
|
+
import { type Output } from "./output";
|
|
3
|
+
export declare function secret<S extends Input<string> | undefined>(unencrypted: S): S extends undefined ? never : S extends Output<string> ? Output<Secret> : Secret;
|
|
4
|
+
export declare class Secret {
|
|
5
|
+
readonly unencrypted: string;
|
|
6
|
+
readonly type = "secret";
|
|
7
|
+
constructor(unencrypted: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function setSecretPassphrase(passphrase: string): void;
|
|
10
|
+
export declare function getSecretPassphrase(): string;
|
|
11
|
+
export declare function tryGetSecretPassphrase(): string | undefined;
|
|
12
|
+
//# sourceMappingURL=secret.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret.d.ts","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,MAAM,EAAY,MAAM,UAAU,CAAC;AAIjD,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,EACxD,WAAW,EAAE,CAAC,GACb,CAAC,SAAS,SAAS,GAClB,KAAK,GACL,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,GACtB,MAAM,CAAC,MAAM,CAAC,GACd,MAAM,CAOX;AAED,qBAAa,MAAM;IAEL,QAAQ,CAAC,WAAW,EAAE,MAAM;IADxC,SAAgB,IAAI,YAAY;gBACX,WAAW,EAAE,MAAM;CACzC;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,QAErD;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAM5C;AAED,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,SAAS,CAE3D"}
|
package/lib/secret.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { isOutput } from "./output";
|
|
3
|
+
const passphraseContext = new AsyncLocalStorage();
|
|
4
|
+
export function secret(unencrypted) {
|
|
5
|
+
if (unencrypted === undefined) {
|
|
6
|
+
throw new Error("Secret cannot be undefined");
|
|
7
|
+
}
|
|
8
|
+
return (isOutput(unencrypted) ? unencrypted.apply(secret) : new Secret(unencrypted));
|
|
9
|
+
}
|
|
10
|
+
export class Secret {
|
|
11
|
+
unencrypted;
|
|
12
|
+
type = "secret";
|
|
13
|
+
constructor(unencrypted) {
|
|
14
|
+
this.unencrypted = unencrypted;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function setSecretPassphrase(passphrase) {
|
|
18
|
+
passphraseContext.enterWith(passphrase);
|
|
19
|
+
}
|
|
20
|
+
export function getSecretPassphrase() {
|
|
21
|
+
const passphrase = passphraseContext.getStore();
|
|
22
|
+
if (!passphrase) {
|
|
23
|
+
throw new Error("No passphrase set");
|
|
24
|
+
}
|
|
25
|
+
return passphrase;
|
|
26
|
+
}
|
|
27
|
+
export function tryGetSecretPassphrase() {
|
|
28
|
+
return passphraseContext.getStore();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=secret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAe,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAU,CAAC;AAE1D,MAAM,UAAU,MAAM,CACpB,WAAc;IAMd,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,CACL,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,CACrE,CAAC;AACX,CAAC;AAED,MAAM,OAAO,MAAM;IAEI;IADL,IAAI,GAAG,QAAQ,CAAC;IAChC,YAAqB,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;IAAG,CAAC;CAC7C;AAED,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,iBAAiB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAChD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAC;AACtC,CAAC"}
|
package/lib/serde.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serde.d.ts","sourceRoot":"","sources":["../src/serde.ts"],"names":[],"mappings":"AAGA,wBAAsB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAkBxD;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAsB1D"}
|
package/lib/serde.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { decryptWithKey, encryptWithKey } from "./encrypt";
|
|
2
|
+
import { Secret, getSecretPassphrase } from "./secret";
|
|
3
|
+
export async function serialize(value) {
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return Promise.all(value.map(serialize));
|
|
6
|
+
}
|
|
7
|
+
else if (value instanceof Secret) {
|
|
8
|
+
return {
|
|
9
|
+
"@secret": await encryptWithKey(value.unencrypted, getSecretPassphrase()),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
else if (value && typeof value === "object") {
|
|
13
|
+
return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, value]) => [
|
|
14
|
+
key,
|
|
15
|
+
await serialize(value),
|
|
16
|
+
])));
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
export async function deserialize(value) {
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
return await Promise.all(value.map(async (item) => await deserialize(item)));
|
|
23
|
+
}
|
|
24
|
+
else if (value && typeof value === "object") {
|
|
25
|
+
if (typeof value["@secret"] === "string") {
|
|
26
|
+
return new Secret(await decryptWithKey(value["@secret"], getSecretPassphrase()));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, value]) => [
|
|
30
|
+
key,
|
|
31
|
+
await deserialize(value),
|
|
32
|
+
])));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=serde.js.map
|
package/lib/serde.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serde.js","sourceRoot":"","sources":["../src/serde.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAU;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IA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,EAAE,CAAC;gBAChD,GAAG;gBACH,MAAM,WAAW,CAAC,KAAK,CAAC;aACzB,CAAC,CACH,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/state.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,KAAK;IACpB,MAAM,EACF,UAAU,GACV,SAAS,GACT,UAAU,GACV,SAAS,GACT,UAAU,GACV,SAAS,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,+CAA+C;IAC/C,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,6CAA6C;IAC7C,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1B,mDAAmD;IACnD,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACxD,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAID,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC;AAE7D,qBAAa,oBAAqB,YAAW,UAAU;IACrD,SAAgB,IAAI,EAAE,MAAM,CAAC;gBACjB,GAAG,EAAE,MAAM;IAIjB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAIxB,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAgBzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAe5C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAIrC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAgB/C,OAAO;CAMtB"}
|
package/lib/state.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ignore } from "./error";
|
|
4
|
+
import { deserialize, serialize } from "./serde";
|
|
4
5
|
const stateFile = path.join(process.cwd(), ".alchemy");
|
|
5
6
|
export class FileSystemStateStore {
|
|
6
7
|
path;
|
|
@@ -36,7 +37,7 @@ export class FileSystemStateStore {
|
|
|
36
37
|
async get(key) {
|
|
37
38
|
try {
|
|
38
39
|
const content = await fs.promises.readFile(await this.getPath(key), "utf8");
|
|
39
|
-
return JSON.parse(content);
|
|
40
|
+
return (await deserialize(JSON.parse(content)));
|
|
40
41
|
}
|
|
41
42
|
catch (error) {
|
|
42
43
|
if (error.code === "ENOENT") {
|
|
@@ -46,7 +47,7 @@ export class FileSystemStateStore {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
async set(key, value) {
|
|
49
|
-
return fs.promises.writeFile(await this.getPath(key), JSON.stringify(value, null, 2));
|
|
50
|
+
return fs.promises.writeFile(await this.getPath(key), JSON.stringify(await serialize(value), null, 2));
|
|
50
51
|
}
|
|
51
52
|
async delete(key) {
|
|
52
53
|
return fs.promises.unlink(await this.getPath(key));
|
package/lib/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAkCjD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;AAIvD,MAAM,OAAO,oBAAoB;IACf,IAAI,CAAS;IAC7B,YAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SA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,KAAK,SAAS,EAAE,CAAC;gBACpB,OAAO,EAAW,CAAC;YACrB,CAAC;YACD,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAU,CAAC;QAC5B,CAAC,CAAC,CACH,CACF,CAAC,IAAI,EAAE,CACT,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,GAAW;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemy",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"publish:npm": "rm -rf ./lib && tsc -b && npm publish"
|
|
7
|
+
"publish:npm": "rm -rf ./*.tsbuildinfo && rm -rf ./lib && tsc -b && npm publish"
|
|
8
8
|
},
|
|
9
9
|
"files": ["lib", "src"],
|
|
10
10
|
"exports": {
|
|
11
11
|
".": "./lib/index.js",
|
|
12
|
-
"./agent": "./lib/agent/index.js",
|
|
13
12
|
"./aws": "./lib/aws/index.js",
|
|
14
13
|
"./aws/oidc": "./lib/aws/oidc/index.js",
|
|
15
14
|
"./cloudflare": "./lib/cloudflare/index.js",
|
|
16
15
|
"./esbuild": "./lib/esbuild.js",
|
|
17
|
-
"./markdown": "./lib/markdown/index.js",
|
|
18
16
|
"./fs": "./lib/fs.js",
|
|
19
17
|
"./github": "./lib/github/index.js",
|
|
20
|
-
"./stripe": "./lib/stripe/index.js"
|
|
21
|
-
"./typescript": "./lib/typescript/index.js"
|
|
18
|
+
"./stripe": "./lib/stripe/index.js"
|
|
22
19
|
},
|
|
23
20
|
"peerDependencies": {
|
|
24
21
|
"@ai-sdk/openai": "^1.1.9",
|
package/src/alchemize.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { evaluate } from "./apply";
|
|
|
2
2
|
import { destroy } from "./destroy";
|
|
3
3
|
import { defaultStage, defaultStateStore, providers } from "./global";
|
|
4
4
|
import { type Scope, getScope } from "./scope";
|
|
5
|
+
import { setSecretPassphrase } from "./secret";
|
|
5
6
|
import type { StateStoreType } from "./state";
|
|
6
7
|
|
|
7
8
|
export interface AlchemizeOptions {
|
|
@@ -37,6 +38,11 @@ export interface AlchemizeOptions {
|
|
|
37
38
|
* @default false
|
|
38
39
|
*/
|
|
39
40
|
quiet?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A passphrase to use to encrypt/decrypt secrets.
|
|
44
|
+
*/
|
|
45
|
+
password?: string;
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
/**
|
|
@@ -52,6 +58,9 @@ export async function alchemize(options?: AlchemizeOptions) {
|
|
|
52
58
|
scope.getScopePath(stage),
|
|
53
59
|
);
|
|
54
60
|
const callbacks = scope.callbacks;
|
|
61
|
+
if (options?.password) {
|
|
62
|
+
setSecretPassphrase(options.password);
|
|
63
|
+
}
|
|
55
64
|
|
|
56
65
|
if (nodes.size > 0) {
|
|
57
66
|
await stateStore.init?.();
|
package/src/apply.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isResource,
|
|
9
9
|
} from "./resource";
|
|
10
10
|
import { type Scope as IScope, getScope } from "./scope";
|
|
11
|
+
import { Secret } from "./secret";
|
|
11
12
|
import type { StateStore } from "./state";
|
|
12
13
|
|
|
13
14
|
export interface ApplyOptions {
|
|
@@ -110,6 +111,8 @@ export async function evaluate<T>(
|
|
|
110
111
|
);
|
|
111
112
|
} else if (output instanceof Date) {
|
|
112
113
|
return new Evaluated(output as T);
|
|
114
|
+
} else if (output instanceof Secret) {
|
|
115
|
+
return new Evaluated(output as T);
|
|
113
116
|
} else if (output && typeof output === "object") {
|
|
114
117
|
const entries = Object.entries(output);
|
|
115
118
|
const evaluatedEntries = await Promise.all(
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Based on Cloudflare API documentation:
|
|
4
4
|
* https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { Secret } from "../secret";
|
|
7
|
+
import type { R2Bucket } from "./bucket";
|
|
7
8
|
import type { DurableObjectNamespace } from "./durable-object-namespace";
|
|
8
9
|
import type { KVNamespace } from "./kv-namespace";
|
|
9
10
|
import type { Worker } from "./worker";
|
|
@@ -19,7 +20,8 @@ export type Binding =
|
|
|
19
20
|
| DurableObjectNamespace
|
|
20
21
|
| KVNamespace
|
|
21
22
|
| Worker
|
|
22
|
-
|
|
|
23
|
+
| R2Bucket
|
|
24
|
+
| Secret
|
|
23
25
|
| string;
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Secret } from "../secret";
|
|
2
|
+
import type { Binding } from "./bindings";
|
|
3
|
+
import type { R2Bucket as _R2Bucket } from "./bucket";
|
|
4
|
+
import type { DurableObjectNamespace as _DurableObjectNamespace } from "./durable-object-namespace";
|
|
5
|
+
import type { KVNamespace as _KVNamespace } from "./kv-namespace";
|
|
6
|
+
import type { Worker as _Worker } from "./worker";
|
|
7
|
+
|
|
8
|
+
export type Bound<T extends Binding> = T extends _DurableObjectNamespace
|
|
9
|
+
? DurableObjectNamespace
|
|
10
|
+
: T extends _KVNamespace
|
|
11
|
+
? KVNamespace
|
|
12
|
+
: T extends _Worker
|
|
13
|
+
? Worker
|
|
14
|
+
: T extends _R2Bucket
|
|
15
|
+
? R2Bucket
|
|
16
|
+
: T extends Secret
|
|
17
|
+
? string
|
|
18
|
+
: never;
|
package/src/cloudflare/bucket.ts
CHANGED
|
@@ -71,14 +71,14 @@ interface CloudflareBucketResponse {
|
|
|
71
71
|
messages: string[];
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export function isBucket(resource: any): resource is Resolved<
|
|
74
|
+
export function isBucket(resource: any): resource is Resolved<R2Bucket> {
|
|
75
75
|
return (
|
|
76
76
|
resource && typeof resource === "object" && resource.id && resource.location
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
export class
|
|
81
|
-
"cloudflare::
|
|
80
|
+
export class R2Bucket extends Resource(
|
|
81
|
+
"cloudflare::R2Bucket",
|
|
82
82
|
async (ctx: Context<BucketOutput>, props: BucketProps) => {
|
|
83
83
|
// Create Cloudflare API client with automatic account discovery
|
|
84
84
|
const api = await createCloudflareApi();
|
package/src/cloudflare/worker.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import * as fs from "fs/promises";
|
|
2
2
|
import { apply } from "../apply";
|
|
3
3
|
import { Bundle, type BundleProps } from "../esbuild";
|
|
4
|
+
import type { Input } from "../input";
|
|
4
5
|
import type { Resolved } from "../output";
|
|
5
6
|
import { type Context, Resource } from "../resource";
|
|
7
|
+
import { Secret } from "../secret";
|
|
6
8
|
import { withExponentialBackoff } from "../utils/retry";
|
|
7
9
|
import { type CloudflareApi, createCloudflareApi } from "./api";
|
|
8
10
|
import type { Bindings, WorkerBindingSpec } from "./bindings";
|
|
11
|
+
import type { Bound } from "./bound";
|
|
9
12
|
import { isBucket } from "./bucket";
|
|
10
13
|
import type { DurableObjectNamespace } from "./durable-object-namespace";
|
|
11
14
|
import { isDurableObjectNamespace } from "./durable-object-namespace";
|
|
@@ -15,7 +18,7 @@ import type { SingleStepMigration } from "./worker-migration";
|
|
|
15
18
|
/**
|
|
16
19
|
* Properties for creating or updating a Worker
|
|
17
20
|
*/
|
|
18
|
-
export interface WorkerProps {
|
|
21
|
+
export interface WorkerProps<B extends Bindings = Bindings> {
|
|
19
22
|
/**
|
|
20
23
|
* The worker script content (JavaScript or WASM)
|
|
21
24
|
* One of script, entryPoint, or bundle must be provided
|
|
@@ -58,7 +61,7 @@ export interface WorkerProps {
|
|
|
58
61
|
/**
|
|
59
62
|
* Bindings to attach to the worker
|
|
60
63
|
*/
|
|
61
|
-
bindings?:
|
|
64
|
+
bindings?: B;
|
|
62
65
|
|
|
63
66
|
/**
|
|
64
67
|
* Environment variables to attach to the worker
|
|
@@ -97,7 +100,8 @@ export interface WorkerProps {
|
|
|
97
100
|
/**
|
|
98
101
|
* Output returned after Worker creation/update
|
|
99
102
|
*/
|
|
100
|
-
export interface WorkerOutput extends
|
|
103
|
+
export interface WorkerOutput<B extends Bindings = Bindings>
|
|
104
|
+
extends Omit<WorkerProps<B>, "url"> {
|
|
101
105
|
type: "service";
|
|
102
106
|
|
|
103
107
|
/**
|
|
@@ -124,83 +128,91 @@ export interface WorkerOutput extends Omit<WorkerProps, "url"> {
|
|
|
124
128
|
/**
|
|
125
129
|
* The bindings that were created
|
|
126
130
|
*/
|
|
127
|
-
bindings:
|
|
131
|
+
bindings: B;
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
export function isWorker(resource: any): resource is Resolved<Worker> {
|
|
131
135
|
return resource && typeof resource === "object" && resource.type === "worker";
|
|
132
136
|
}
|
|
133
137
|
|
|
134
|
-
export class Worker extends Resource(
|
|
138
|
+
export class Worker<B extends Bindings = Bindings> extends Resource(
|
|
135
139
|
"cloudflare::Worker",
|
|
136
140
|
{
|
|
137
141
|
alwaysUpdate: true,
|
|
138
142
|
},
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
applyWorker,
|
|
144
|
+
) {
|
|
145
|
+
public declare readonly Env: {
|
|
146
|
+
[bindingName in keyof B]: Bound<B[bindingName]>;
|
|
147
|
+
};
|
|
148
|
+
constructor(id: string, input: Input<WorkerProps<B>>, ...inputs: any[]) {
|
|
149
|
+
super(id, input as any, ...inputs);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
142
152
|
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
async function applyWorker(ctx: Context<WorkerOutput>, props: WorkerProps) {
|
|
154
|
+
// Create Cloudflare API client with automatic account discovery
|
|
155
|
+
const api = await createCloudflareApi();
|
|
145
156
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
throw new Error("One of script or entryPoint must be provided");
|
|
149
|
-
}
|
|
157
|
+
// Use the provided name
|
|
158
|
+
const workerName = props.name;
|
|
150
159
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
160
|
+
// Validate input - we need either script, entryPoint, or bundle
|
|
161
|
+
if (!props.script && !props.entrypoint) {
|
|
162
|
+
throw new Error("One of script or entryPoint must be provided");
|
|
163
|
+
}
|
|
156
164
|
|
|
157
|
-
|
|
165
|
+
if (ctx.event === "delete") {
|
|
166
|
+
return deleteWorker(ctx, api, workerName);
|
|
167
|
+
} else if (ctx.event === "create") {
|
|
168
|
+
await assertWorkerDoesNotExist(ctx, api, workerName);
|
|
169
|
+
}
|
|
158
170
|
|
|
159
|
-
|
|
171
|
+
const oldBindings = await ctx.get<Bindings>("bindings");
|
|
160
172
|
|
|
161
|
-
|
|
162
|
-
const scriptContent =
|
|
163
|
-
props.script ?? (await bundleWorkerScript(ctx, props));
|
|
173
|
+
const scriptMetadata = await prepareWorkerMetadata(ctx, oldBindings, props);
|
|
164
174
|
|
|
165
|
-
|
|
166
|
-
|
|
175
|
+
// Get the script content - either from props.script, or by bundling
|
|
176
|
+
const scriptContent = props.script ?? (await bundleWorkerScript(ctx, props));
|
|
167
177
|
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
// Upload the worker script
|
|
179
|
+
await putWorker(ctx, api, workerName, scriptContent, scriptMetadata);
|
|
170
180
|
|
|
171
|
-
|
|
172
|
-
|
|
181
|
+
// TODO: it is less than ideal that this can fail, resulting in state problem
|
|
182
|
+
await ctx.set("bindings", props.bindings);
|
|
173
183
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
ctx,
|
|
177
|
-
api,
|
|
178
|
-
workerName,
|
|
179
|
-
props.url ?? false,
|
|
180
|
-
);
|
|
184
|
+
// Handle routes if requested
|
|
185
|
+
await setupRoutes(api, workerName, props.routes || []);
|
|
181
186
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
187
|
+
// Handle worker URL if requested
|
|
188
|
+
const workerUrl = await configureURL(
|
|
189
|
+
ctx,
|
|
190
|
+
api,
|
|
191
|
+
workerName,
|
|
192
|
+
props.url ?? false,
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Get current timestamp
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
|
|
198
|
+
// Construct the output
|
|
199
|
+
const output: WorkerOutput = {
|
|
200
|
+
type: "service",
|
|
201
|
+
id: workerName,
|
|
202
|
+
name: workerName,
|
|
203
|
+
script: scriptContent,
|
|
204
|
+
format: props.format || "esm", // Include format in the output
|
|
205
|
+
routes: props.routes || [],
|
|
206
|
+
bindings: props.bindings ?? {},
|
|
207
|
+
env: props.env,
|
|
208
|
+
observability: scriptMetadata.observability,
|
|
209
|
+
createdAt: now,
|
|
210
|
+
updatedAt: now,
|
|
211
|
+
url: workerUrl,
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
return output;
|
|
215
|
+
}
|
|
204
216
|
|
|
205
217
|
async function deleteWorker(
|
|
206
218
|
ctx: Context<WorkerOutput>,
|
|
@@ -445,6 +457,12 @@ async function prepareWorkerMetadata(
|
|
|
445
457
|
name: bindingName,
|
|
446
458
|
bucket_name: binding.name || binding.id,
|
|
447
459
|
});
|
|
460
|
+
} else if (binding instanceof Secret) {
|
|
461
|
+
meta.bindings.push({
|
|
462
|
+
type: "secret_text",
|
|
463
|
+
name: bindingName,
|
|
464
|
+
text: binding.unencrypted,
|
|
465
|
+
});
|
|
448
466
|
} else {
|
|
449
467
|
// @ts-expect-error - we should never reach here
|
|
450
468
|
throw new Error(`Unsupported binding type: ${binding.type}`);
|