@lunora/codegen 1.0.0-alpha.278 → 1.0.0-alpha.279
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/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/QUEUES_FILENAME-CG1CuK-T.mjs +1 -0
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-Ckd4suI-.mjs → SCHEMA_SNAPSHOT_FILENAME-BNGM7Peq.mjs} +6 -6
- package/dist/packem_shared/emitAgents-BPxcXbC6.mjs +1 -0
- package/dist/packem_shared/{emitShard-CSLqD-Hr.mjs → emitShard-HJfeP8nZ.mjs} +1 -1
- package/dist/packem_shared/{shard-Dr5gMNyz.mjs → shard-D39UvC5v.mjs} +1 -1
- package/dist/packem_shared/{shard-runtime-BI2SZ54Z.mjs → shard-runtime-B7YKtoEK.mjs} +67 -67
- package/package.json +6 -6
- package/dist/packem_shared/QUEUES_FILENAME-Dj5yK34Z.mjs +0 -1
- package/dist/packem_shared/emitAgents-CG2R-Zz6.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{o as i,j as r,s as n,h as o,t as g,k as u,d as F,w as p,m as l,g as d,f,i as k,u as w,l as A,v as Q}from"./shard-runtime-B7YKtoEK.mjs";import"./shared-Be3TGzxM.mjs";export{i as buildDoTypeImports,r as emitAgentFragments,n as emitAgents,o as emitContainerFragments,g as emitContainers,u as emitPaymentFragments,F as emitQueueFragments,p as emitQueues,l as emitQueuesMetadataFragments,d as emitServiceFragments,f as emitTopicFragments,k as emitWorkflowFragments,w as emitWorkflows,A as emitWorkflowsMetadataFragments,Q as queueAliasFindings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as f}from"./shard-
|
|
1
|
+
import"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as f}from"./shard-D39UvC5v.mjs";import"./shard-runtime-B7YKtoEK.mjs";import"./shared-Be3TGzxM.mjs";export{f as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as vt}from"@lunora/errors";import{serializeSchemaSnapshot as kt,hashSchemaSnapshot as St}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{isHyperdriveGlobalTable as Rt,isD1GlobalTable as xt}from"./isD1GlobalTable-udvHAAzD.mjs";import{p as At,i as Dt}from"./ir-DBSvhNa-.mjs";import{r as h}from"./json-data-Chfs2Cz5.mjs";import{r as C,e as Tt,a as Ot,b as Et,c as Ct,d as Lt,f as It,g as _t,h as Mt,i as Pt,j as qt,k as Nt,l as $t,m as Ft,n as Ut,o as Bt,p as Wt,q as jt}from"./shard-runtime-
|
|
1
|
+
import{LunoraError as vt}from"@lunora/errors";import{serializeSchemaSnapshot as kt,hashSchemaSnapshot as St}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{isHyperdriveGlobalTable as Rt,isD1GlobalTable as xt}from"./isD1GlobalTable-udvHAAzD.mjs";import{p as At,i as Dt}from"./ir-DBSvhNa-.mjs";import{r as h}from"./json-data-Chfs2Cz5.mjs";import{r as C,e as Tt,a as Ot,b as Et,c as Ct,d as Lt,f as It,g as _t,h as Mt,i as Pt,j as qt,k as Nt,l as $t,m as Ft,n as Ut,o as Bt,p as Wt,q as jt}from"./shard-runtime-B7YKtoEK.mjs";import{u as K,i as Ht,G as Vt,d as Kt}from"./shared-Be3TGzxM.mjs";const Gt=` /**
|
|
2
2
|
* The bare writer every admin/maintenance entry point writes through.
|
|
3
3
|
*
|
|
4
4
|
* Admin and maintenance writes go through the SAME reactive-cache hooks as a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s as
|
|
1
|
+
import{s as N}from"./ir-DBSvhNa-.mjs";import{r as b}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as R}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{a as l,G as g}from"./shared-Be3TGzxM.mjs";const I=e=>e?{importFragment:"serveRelationFanout, ",override:`
|
|
2
2
|
protected override async runRelationFanoutRead(functionPath: string, args: Record<string, unknown>): Promise<unknown> {
|
|
3
3
|
this.ensureMigrated();
|
|
4
4
|
|
|
@@ -6,14 +6,14 @@ import{s as b}from"./ir-DBSvhNa-.mjs";import{r as y}from"./json-data-Chfs2Cz5.mj
|
|
|
6
6
|
|
|
7
7
|
return serveRelationFanout(schema as unknown as SchemaLike, db, functionPath, args);
|
|
8
8
|
}
|
|
9
|
-
`}:{importFragment:"",override:""},
|
|
10
|
-
${
|
|
9
|
+
`}:{importFragment:"",override:""},f=(e,r,t,{cast:n="",sync:a=[]}={})=>{const u=`throw new Error(${JSON.stringify(r)});`,c=t.map(s=>` ${s}: ${a===!0||a.includes(s)?"":"async "}() => {
|
|
10
|
+
${u}
|
|
11
11
|
},`).join(`
|
|
12
12
|
`);return`
|
|
13
13
|
const ${e} = {
|
|
14
14
|
${c}
|
|
15
15
|
}${n};
|
|
16
|
-
`},
|
|
16
|
+
`},h={build:"",configField:"",contextField:"",importLines:[],stub:""},D=e=>e.size===0?{configField:"",constant:"",override:""}:{configField:"\n /** The `ShardRegistryDO` namespace (typically `env.SHARD_REGISTRY`). This shard registers its key for each `.shardBy()` table it writes, so cross-shard export, sync and migrations reach it. */\n shardRegistry?: (env: Record<string, unknown>) => unknown;",constant:`
|
|
17
17
|
/** The \`.shardBy()\` tables this shard registers with the shard registry when it writes them. */
|
|
18
18
|
const SHARDED_TABLES: ReadonlySet<string> = new Set([${[...e].map(r=>JSON.stringify(r)).join(", ")}]);
|
|
19
19
|
`,override:`
|
|
@@ -22,29 +22,29 @@ const SHARDED_TABLES: ReadonlySet<string> = new Set([${[...e].map(r=>JSON.string
|
|
|
22
22
|
|
|
23
23
|
return namespace === undefined ? undefined : { namespace, shardedTables: SHARDED_TABLES };
|
|
24
24
|
}
|
|
25
|
-
`},
|
|
25
|
+
`},j=(e,r)=>e?{build:`
|
|
26
26
|
const flags: import("${r}").LunoraFlags = createFlags(flagsConfig, env, {
|
|
27
27
|
provider: () => config.flags?.(env),
|
|
28
28
|
targetingKey: () => flagsConfig.identify?.({ identity: identity ?? null, userId: userId ?? null }),
|
|
29
29
|
});
|
|
30
30
|
`,configField:`
|
|
31
31
|
flags?: (env: Record<string, unknown>) => import("${r}").Provider;`,contextField:`
|
|
32
|
-
flags,`,importLines:[`import { createFlags } from "${r}";`,'import flagsConfig from "../flags.js";'],stub:""}:
|
|
32
|
+
flags,`,importLines:[`import { createFlags } from "${r}";`,'import flagsConfig from "../flags.js";'],stub:""}:h,U=e=>e?{build:`
|
|
33
33
|
const { notify, push } = createNotify(notifyConfig, env, { log, metrics });
|
|
34
34
|
`,configField:"",contextField:`
|
|
35
35
|
notify,
|
|
36
|
-
push,`,importLines:['import { createNotify } from "@lunora/notify";','import notifyConfig from "../notify.js";'],stub:""}:
|
|
36
|
+
push,`,importLines:['import { createNotify } from "@lunora/notify";','import notifyConfig from "../notify.js";'],stub:""}:h,Q=e=>e?{build:`
|
|
37
37
|
const envConfig = lunoraEnvContract.${e.exportName}(env);
|
|
38
38
|
`,configField:"",contextField:`
|
|
39
|
-
env: envConfig,`,importLines:['import * as lunoraEnvContract from "../env.js";'],stub:""}:
|
|
39
|
+
env: envConfig,`,importLines:['import * as lunoraEnvContract from "../env.js";'],stub:""}:h,M=(e,r,t)=>{if(!r)return{constant:"",evaluateOverride:"",subscriptionOverride:""};const n=s=>`
|
|
40
40
|
const env = (this.env ?? {}) as Record<string, unknown>;
|
|
41
41
|
const flags: import("${t}").LunoraFlags = createFlags(flagsConfig, env, {
|
|
42
42
|
provider: () => config.flags?.(env),
|
|
43
|
-
targetingKey: ${
|
|
44
|
-
});`,
|
|
43
|
+
targetingKey: ${s},
|
|
44
|
+
});`,a=`
|
|
45
45
|
/** Statically-discovered feature flags (\`ctx.flags.<type>("key")\` reads) served via \`__lunora_admin__:listFlags\` + the reactive \`__lunora_flags__:\` channel. */
|
|
46
|
-
const LUNORA_FLAG_KEYS = ${
|
|
47
|
-
`,
|
|
46
|
+
const LUNORA_FLAG_KEYS = ${b(e,'ReadonlyArray<{ key: string; type: "boolean" | "number" | "object" | "string" }>')};
|
|
47
|
+
`,u=`
|
|
48
48
|
protected override async evaluateFlags(context?: Record<string, unknown>): Promise<FlagsResult> {${n("undefined")}
|
|
49
49
|
const evalContext = context as import("${t}").EvaluationContext | undefined;
|
|
50
50
|
const evaluations: FlagsResult["flags"] = [];
|
|
@@ -98,7 +98,7 @@ const LUNORA_FLAG_KEYS = ${y(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
98
98
|
|
|
99
99
|
return flags.boolean(key, typeof args.default === "boolean" ? args.default : false, context);
|
|
100
100
|
}
|
|
101
|
-
`;return{constant:
|
|
101
|
+
`;return{constant:a,evaluateOverride:u,subscriptionOverride:c}},k=()=>({build:`
|
|
102
102
|
const aiBinding = config.ai?.(env) ?? (env as Record<string, unknown>).AI;
|
|
103
103
|
// Correlate AI-Gateway-routed calls with the Lunora trace: thread the
|
|
104
104
|
// function path + trace id into createAi, which folds them into the
|
|
@@ -115,9 +115,9 @@ const LUNORA_FLAG_KEYS = ${y(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
115
115
|
telemetry: { metrics, trace },
|
|
116
116
|
});
|
|
117
117
|
`,configField:`
|
|
118
|
-
ai?: (env: Record<string, unknown>) => AiBindingLike;`,importLines:['import type { AiBindingLike, LunoraAi } from "@lunora/ai";','import { createAi } from "@lunora/ai";'],stub:""}),
|
|
118
|
+
ai?: (env: Record<string, unknown>) => AiBindingLike;`,importLines:['import type { AiBindingLike, LunoraAi } from "@lunora/ai";','import { createAi } from "@lunora/ai";'],stub:""}),S=()=>({build:`
|
|
119
119
|
const access = accessFacade(identity, userId);
|
|
120
|
-
`,configField:"",importLines:['import { accessFacade } from "@lunora/cloudflare-access/context";'],stub:""}),
|
|
120
|
+
`,configField:"",importLines:['import { accessFacade } from "@lunora/cloudflare-access/context";'],stub:""}),w=()=>({build:`
|
|
121
121
|
const r2sqlEnv = env as Record<string, unknown>;
|
|
122
122
|
const r2sqlAccountId = (r2sqlEnv.R2_SQL_ACCOUNT_ID ?? r2sqlEnv.CLOUDFLARE_ACCOUNT_ID) as string | undefined;
|
|
123
123
|
const r2sqlToken = r2sqlEnv.R2_SQL_TOKEN as string | undefined;
|
|
@@ -128,36 +128,36 @@ const LUNORA_FLAG_KEYS = ${y(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
128
128
|
? createR2Sql({ accountId: r2sqlAccountId, apiToken: r2sqlToken, bucket: r2sqlBucket })
|
|
129
129
|
: r2sqlStub;
|
|
130
130
|
`,configField:`
|
|
131
|
-
r2sql?: (env: Record<string, unknown>) => R2SqlClient;`,importLines:['import type { R2SqlClient } from "@lunora/bindings/r2sql";','import { createR2Sql } from "@lunora/bindings/r2sql";'],stub:
|
|
131
|
+
r2sql?: (env: Record<string, unknown>) => R2SqlClient;`,importLines:['import type { R2SqlClient } from "@lunora/bindings/r2sql";','import { createR2Sql } from "@lunora/bindings/r2sql";'],stub:f("r2sqlStub: R2SqlClient","ctx.r2sql: no R2 SQL credentials found. Set `R2_SQL_TOKEN`, `R2_SQL_ACCOUNT_ID` (or `CLOUDFLARE_ACCOUNT_ID`), and `R2_SQL_BUCKET` in your env/.dev.vars, or pass an `r2sql` config thunk to createShardDO().",["describe","explain","from","query","showDatabases","showTables"],{sync:["from"]})}),L=()=>({build:`
|
|
132
132
|
const x402: X402Pay = config.x402
|
|
133
133
|
? lazyX402Pay(config.x402(env), { getSecret: (name: string) => secrets.get(name) })
|
|
134
134
|
: x402Stub;
|
|
135
135
|
`,configField:`
|
|
136
|
-
x402?: (env: Record<string, unknown>) => X402PayConfig;`,importLines:['import type { X402Pay, X402PayConfig } from "@lunora/x402/pay";','import { lazyX402Pay } from "@lunora/x402/pay";'],stub:
|
|
137
|
-
`,
|
|
138
|
-
${
|
|
136
|
+
x402?: (env: Record<string, unknown>) => X402PayConfig;`,importLines:['import type { X402Pay, X402PayConfig } from "@lunora/x402/pay";','import { lazyX402Pay } from "@lunora/x402/pay";'],stub:f("x402Stub: X402Pay","ctx.x402: no pay rail configured. Pass `x402` to createShardDO().",["fetch"],{cast:" as unknown as X402Pay",sync:["fetch"]})}),A={access:S,ai:k,r2sql:w,x402:L},C=e=>e.shardBinding==="bespoke",_=e=>typeof e.shardBinding=="object",m=" ",F=(e,r,t)=>{const n=`${e}Binding`,{factory:a}=t;let u=`(${n} as ${r})`;if(a!==void 0){const c=`${n} as ${t.bindingType??r}`;u=a.option===void 0?`${a.name}(${c})`:`${a.name}({ ${a.option}: ${c} })`}return`${n} ? ${u} : ${e}Stub`},O=(e,r,t)=>{const n=F(e,r,t),a=`${m}const ${e}Binding = config.${e}?.(env) ?? (env as Record<string, unknown>).${t.envName};
|
|
137
|
+
`,u=t.unvouchableReads??[];return u.length===0?`
|
|
138
|
+
${a}${m}const ${e}: ${r} = ${n};
|
|
139
139
|
`:`
|
|
140
|
-
${
|
|
141
|
-
${
|
|
142
|
-
${
|
|
143
|
-
${
|
|
144
|
-
${
|
|
140
|
+
${a}${m}// ${t.envName} is not this shard's SQLite, so nothing appends a \`__cdc_log\` entry
|
|
141
|
+
${m}// when a value changes — a subscription that read one can never be proven
|
|
142
|
+
${m}// current on reconnect and must re-snapshot. Reads only; writes stay unstamped.
|
|
143
|
+
${m}const ${e}: ${r} = markUnvouchableReads(${n}, options.onRead, [
|
|
144
|
+
${u.map(c=>`${m} ${JSON.stringify(c)},`).join(`
|
|
145
145
|
`)}
|
|
146
|
-
${
|
|
147
|
-
`},
|
|
148
|
-
${
|
|
146
|
+
${m}]);
|
|
147
|
+
`},E=(e,r,t)=>{const{binding:n,clientType:a}=t,u=f(`${e}Stub: ${a}`,t.missingMessage,t.stubMethods,{sync:t.syncStubMethods});if(n===void 0){const o=t.instrument===void 0?`config.${e}(env)`:`this.${t.instrument}(config.${e}(env), logFunctionPath, traceAnchor, observability)`;return{build:`
|
|
148
|
+
${m}const ${e}: ${a} = config.${e} ? ${o} : ${e}Stub;
|
|
149
149
|
`,configField:`
|
|
150
|
-
${e}?: (env: Record<string, unknown>) => ${
|
|
151
|
-
${e}?: (env: Record<string, unknown>) => ${c};`,importLines:[`import type { ${
|
|
152
|
-
${
|
|
153
|
-
export class ${
|
|
154
|
-
public constructor(ctx: ConstructorParameters<typeof ${
|
|
155
|
-
super(ctx, env, ${
|
|
150
|
+
${e}?: (env: Record<string, unknown>) => ${a};`,importLines:[`import type { ${a} } from "${r}";`],stub:u}}const c=n.bindingType??a,s=[...new Set([c,a])].toSorted((o,i)=>o.localeCompare(i));return{build:O(e,a,n),configField:`
|
|
151
|
+
${e}?: (env: Record<string, unknown>) => ${c};`,importLines:[`import type { ${s.join(", ")} } from "${r}";`,...n.factory===void 0?[]:[`import { ${n.factory.name} } from "${r}";`]],stub:u}},K=e=>{const r=[],t=[];let n="",a="",u="",c="",s="";for(const o of R.filter(({key:i})=>e.has(i))){let i;if(C(o))i=A[o.key]();else if(_(o))i=E(o.contextProperty,o.moduleSpecifier,o.shardBinding);else continue;const d=o.contextProperty;t.push(...i.importLines),a+=i.configField,s+=i.stub,o.tier==="every"?(u+=i.build,c+=`
|
|
152
|
+
${d},`):(n+=i.build,r.push(d))}return{actionBuild:n,actionFields:r,configFields:a,everyBuild:u,everyFields:c,importLines:t,stubs:s}},G=(e,r)=>{if(e.length===0)return"";const t=r?`, ${JSON.stringify(r)}`:"",n=e.map(i=>{l(i.exportName,`container export "${i.exportName}"`),l(i.className,`container class "${i.className}"`);const d=i.sandbox===!0?"LunoraSandboxContainer":"LunoraContainer";return`/** Container DO for the \`${i.exportName}\` definition (binding \`${i.bindingName}\`). */
|
|
153
|
+
export class ${i.className} extends ${d} {
|
|
154
|
+
public constructor(ctx: ConstructorParameters<typeof ${d}>[0], env: Record<string, unknown>) {
|
|
155
|
+
super(ctx, env, ${i.exportName}, "${i.exportName}"${t});
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
`}).join(`
|
|
159
|
-
`),
|
|
160
|
-
`:"";return`${
|
|
159
|
+
`),a=e.map(i=>i.exportName).join(", "),u=e.some(i=>i.sandbox===!0),c=e.some(i=>i.sandbox!==!0)?`import { LunoraContainer } from "@lunora/container/do";
|
|
160
|
+
`:"";return`${g}/**
|
|
161
161
|
* Container-enabled Durable Object classes for the containers declared in
|
|
162
162
|
* \`lunora/containers.ts\`. Re-export them from your worker entry — wrangler
|
|
163
163
|
* requires each \`containers[].class_name\` to be exported by the worker:
|
|
@@ -169,19 +169,19 @@ export class ${s.className} extends ${m} {
|
|
|
169
169
|
* \`handle.egress\` controls) routes container outbound traffic through this
|
|
170
170
|
* WorkerEntrypoint, so it too must be exported by the deployed worker.
|
|
171
171
|
*/
|
|
172
|
-
${c}${
|
|
172
|
+
${c}${u?`import { LunoraSandboxContainer } from "@lunora/container/sandbox";
|
|
173
173
|
`:""}
|
|
174
|
-
import { ${
|
|
174
|
+
import { ${a} } from "../containers.js";
|
|
175
175
|
|
|
176
176
|
export { ContainerProxy } from "@lunora/container/do";
|
|
177
|
-
${
|
|
177
|
+
${u?`
|
|
178
178
|
/**
|
|
179
179
|
* \`DirectoryBackup\` and \`S3Mount\` route a \`sandbox: true\` container's storage
|
|
180
180
|
* traffic through these WorkerEntrypoints, so the deployed worker must export them.
|
|
181
181
|
*/
|
|
182
182
|
export { DirectoryBackupGateway, S3Gateway } from "@lunora/container/sandbox";
|
|
183
183
|
`:""}
|
|
184
|
-
${n}`},
|
|
184
|
+
${n}`},H=(e,r)=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};for(const n of e)l(n.exportName,`container export "${n.exportName}"`),l(n.bindingName,`container binding "${n.bindingName}"`);const t=e.map(n=>{const a=n.schedulingPolicy!==void 0||n.maxInstances===void 0?"":`, maxInstances: ${String(n.maxInstances)}`;return` { binding: "${n.bindingName}", exportName: "${n.exportName}"${a} },`}).join(`
|
|
185
185
|
`);return{build:`
|
|
186
186
|
const containers = createContainerContext(env, LUNORA_CONTAINERS, ${r?JSON.stringify(r):"undefined"}, this.getCurrentTraceparent(), this.getCurrentSampleErrors());
|
|
187
187
|
`,contextField:`
|
|
@@ -190,14 +190,14 @@ ${n}`},M=(e,r)=>{if(e.length===0)return{build:"",contextField:"",importLines:[],
|
|
|
190
190
|
const LUNORA_CONTAINERS: ReadonlyArray<ContainerBindingSpec> = [
|
|
191
191
|
${t}
|
|
192
192
|
];
|
|
193
|
-
`}},
|
|
193
|
+
`}},J=e=>{if(e.length===0)return"";const r=e.map(n=>(l(n.exportName,`workflow export "${n.exportName}"`),l(n.className,`workflow class "${n.className}"`),`/** WorkflowEntrypoint for the \`${n.exportName}\` definition, reached as \`ctx.exports.${n.className}\`. */
|
|
194
194
|
export class ${n.className} extends LunoraWorkflow<WorkflowParamsOf<typeof ${n.exportName}>, WorkflowOutputOf<typeof ${n.exportName}>> {
|
|
195
195
|
public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
196
196
|
super(ctx, env, ${n.exportName}, "${n.exportName}");
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
`)).join(`
|
|
200
|
-
`),t=e.map(n=>n.exportName).join(", ");return`${
|
|
200
|
+
`),t=e.map(n=>n.exportName).join(", ");return`${g}/**
|
|
201
201
|
* WorkflowEntrypoint classes for the workflows declared in
|
|
202
202
|
* \`lunora/workflows.ts\`. Re-export them from your worker entry — wrangler
|
|
203
203
|
* requires each \`workflows[].class_name\` to be exported by the worker:
|
|
@@ -218,21 +218,21 @@ type WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params
|
|
|
218
218
|
/** Output type carried by a \`defineWorkflow\` definition (its phantom \`__output\`), so each entrypoint keeps the authored return type. */
|
|
219
219
|
type WorkflowOutputOf<Definition> = Definition extends { __output?: infer Output } ? Output : unknown;
|
|
220
220
|
|
|
221
|
-
${r}`},
|
|
222
|
-
export class ${
|
|
221
|
+
${r}`},V=e=>{if(e.length===0)return"";const t=e.filter(s=>s.voice).length>0,n=e.map(s=>{l(s.exportName,`agent export "${s.exportName}"`),l(s.className,`agent class "${s.className}"`);const o=`/** WorkflowEntrypoint for the \`${s.exportName}\` agent, reached as \`ctx.exports.${s.className}\`. */
|
|
222
|
+
export class ${s.className} extends LunoraWorkflow<AgentRunInput, AgentRunResult> {
|
|
223
223
|
public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
224
|
-
super(ctx, env, compileAgentWorkflow(${
|
|
224
|
+
super(ctx, env, compileAgentWorkflow(${s.exportName}, "${s.exportName}"), "${s.exportName}");
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
`;if(!
|
|
228
|
-
/** Voice-session Durable Object for the \`${
|
|
229
|
-
export class ${
|
|
227
|
+
`;if(!s.voice)return o;const i=s.voiceClassName??"",d=s.voiceBindingName??"";l(i,`agent voice class "${i}"`);const p=`
|
|
228
|
+
/** Voice-session Durable Object for the \`${s.exportName}\` agent (binding \`${d}\`). */
|
|
229
|
+
export class ${i} extends VoiceSessionDO {
|
|
230
230
|
public constructor(ctx: ConstructorParameters<typeof VoiceSessionDO>[0], env: Record<string, unknown>) {
|
|
231
|
-
super(ctx, env, ${
|
|
231
|
+
super(ctx, env, ${s.exportName}, "${s.exportName}");
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
`;return`${
|
|
235
|
-
`),
|
|
234
|
+
`;return`${o}${p}`}).join(`
|
|
235
|
+
`),a=e.map(s=>s.exportName).join(", ");return`${g}/**
|
|
236
236
|
* WorkflowEntrypoint classes for the agents declared in \`lunora/agents.ts\`.
|
|
237
237
|
* Each \`defineAgent\` compiles a replay-safe tool-loop onto a Cloudflare
|
|
238
238
|
* Workflow. Re-export them from your worker entry — wrangler requires each
|
|
@@ -244,11 +244,11 @@ import LunoraWorkflow from "@lunora/workflow/do";
|
|
|
244
244
|
${t?'import { compileAgentWorkflow, VoiceSessionDO } from "@lunora/agent";':'import { compileAgentWorkflow } from "@lunora/agent";'}
|
|
245
245
|
import type { AgentRunInput, AgentRunResult } from "@lunora/agent";
|
|
246
246
|
|
|
247
|
-
import { ${
|
|
247
|
+
import { ${a} } from "../agents.js";
|
|
248
248
|
|
|
249
|
-
${n}`},
|
|
250
|
-
`),
|
|
251
|
-
`);return`${
|
|
249
|
+
${n}`},y=e=>e.env===void 0?"the top level":`env.${e.env}`,$=(e,r)=>{const t=e.filter(o=>o.mode==="push"),n=new Map(t.map(o=>[o.bindingName,o])),a=new Map(e.map(o=>[o.name,o])),u=new Map(t.map(o=>[o.name,o])),c=new Map,s=[];for(const o of r){const i=n.get(o.binding);if(i===void 0||o.queue===i.name)continue;const d=a.get(o.queue);if(d!==void 0){s.push(`${y(o)} maps \`${o.binding}\` to "${o.queue}", the declared name of queue \`${d.exportName}\` — batches for "${o.queue}" go to \`${d.exportName}\`, never \`${i.exportName}\`.`);continue}const p=u.get(o.queue);if(p===void 0)u.set(o.queue,i),c.set(o.queue,o);else if(p!==i){const x=c.get(o.queue);s.push(`"${o.queue}" is aliased to \`${p.exportName}\` by ${x===void 0?"an earlier producer":y(x)} and to \`${i.exportName}\` by ${y(o)} — batches for it go to \`${p.exportName}\`.`)}}return{conflicts:s,routes:u}},Y=(e,r)=>$(e,r).conflicts.map(t=>({cacheKey:`queue_alias_conflict:${t}`,categories:["SCHEMA"],description:"Codegen routes a delivered batch by its queue name. A wrangler.jsonc producer that maps a queue's binding to another name adds that name as a route, so it must not be another queue's declared name or an alias another scope gives a different queue.",detail:t,facing:"INTERNAL",level:"WARN",metadata:{},name:"queue_alias_conflict",remediation:"Give each queue a distinct name in every `env.<name>` block of wrangler.jsonc, then rerun codegen.",title:"Queue name routes to a different handler than wrangler.jsonc implies"})),X=(e,r=[])=>{const t=e.filter(c=>c.mode==="push");if(t.length===0)return"";for(const c of t)l(c.exportName,`queue export "${c.exportName}"`);const n=[...Map.groupBy(t,c=>c.filePath)].map(([c,s])=>`import { ${s.map(o=>o.exportName).join(", ")} } from "../${c}.js";`).join(`
|
|
250
|
+
`),{routes:a}=$(e,r),u=[...a].map(([c,s])=>` ${JSON.stringify(c)}: { binding: ${JSON.stringify(s.bindingName)}, definition: ${s.exportName}, exportName: ${JSON.stringify(s.exportName)} },`).join(`
|
|
251
|
+
`);return`${g}/**
|
|
252
252
|
* Push-consumer registry for the queues declared in \`lunora/queues.ts\`. The
|
|
253
253
|
* composed worker's \`queue(batch, env, ctx)\` entry routes each delivered batch
|
|
254
254
|
* by \`batch.queue\` to the matching \`defineQueue\` handler. Wired automatically
|
|
@@ -256,13 +256,13 @@ ${n}`},H=e=>{const r=e.filter(o=>o.mode==="push");if(r.length===0)return"";for(c
|
|
|
256
256
|
*/
|
|
257
257
|
import type { QueueRegistry } from "@lunora/queue";
|
|
258
258
|
|
|
259
|
-
${
|
|
259
|
+
${n}
|
|
260
260
|
|
|
261
|
-
/**
|
|
261
|
+
/** Wrangler queue name (declared, or a per-environment rename) → { binding, definition, exportName } for batch routing. */
|
|
262
262
|
export const LUNORA_QUEUE_REGISTRY: QueueRegistry = {
|
|
263
|
-
${
|
|
263
|
+
${u}
|
|
264
264
|
};
|
|
265
|
-
`},
|
|
265
|
+
`},z=e=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};for(const t of e)l(t.exportName,`workflow export "${t.exportName}"`),l(t.className,`workflow class "${t.className}"`);const r=e.map(t=>` { className: "${t.className}", exportName: "${t.exportName}" },`).join(`
|
|
266
266
|
`);return{build:`
|
|
267
267
|
const workflows = createWorkflowContext(env, LUNORA_WORKFLOWS, this.state.exports);
|
|
268
268
|
`,contextField:`
|
|
@@ -271,7 +271,7 @@ ${n}
|
|
|
271
271
|
const LUNORA_WORKFLOWS: ReadonlyArray<WorkflowBindingSpec> = [
|
|
272
272
|
${r}
|
|
273
273
|
];
|
|
274
|
-
`}},
|
|
274
|
+
`}},Z=e=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};for(const t of e)l(t.exportName,`queue export "${t.exportName}"`),l(t.bindingName,`queue binding "${t.bindingName}"`);const r=e.map(t=>` { binding: "${t.bindingName}", exportName: "${t.exportName}", name: ${JSON.stringify(t.name)} },`).join(`
|
|
275
275
|
`);return{build:`
|
|
276
276
|
const queues = createQueueContext(env, LUNORA_QUEUES);
|
|
277
277
|
`,contextField:`
|
|
@@ -280,7 +280,7 @@ ${r}
|
|
|
280
280
|
const LUNORA_QUEUES: ReadonlyArray<QueueBindingSpec> = [
|
|
281
281
|
${r}
|
|
282
282
|
];
|
|
283
|
-
`}},
|
|
283
|
+
`}},ee=(e,r)=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};const t=e.map(n=>{l(n.exportName,`topic export "${n.exportName}"`);const a=N(r,n.exportName).map(u=>`{ binding: "${u.bindingName}", exportName: "${u.exportName}" }`).join(", ");return` { exportName: "${n.exportName}", subscriptions: [${a}] },`}).join(`
|
|
284
284
|
`);return{build:`
|
|
285
285
|
const topics = createTopicContext(env, LUNORA_TOPICS);
|
|
286
286
|
`,contextField:`
|
|
@@ -289,7 +289,7 @@ ${r}
|
|
|
289
289
|
const LUNORA_TOPICS: ReadonlyArray<TopicBindingSpec> = [
|
|
290
290
|
${t}
|
|
291
291
|
];
|
|
292
|
-
`}},
|
|
292
|
+
`}},te=(e,r)=>{if(e.length===0)return{build:"",importLines:[],specs:""};const t=e.map(n=>(l(n.name,`service "${n.name}"`),l(n.binding,`service binding "${n.binding}"`),` { binding: "${n.binding}", name: "${n.name}"${n.rpcEntrypoint===void 0?"":", rpc: true"} },`)).join(`
|
|
293
293
|
`);return{build:`
|
|
294
294
|
const services = createServices(env, LUNORA_SERVICES);
|
|
295
295
|
`,importLines:[`import type { ServiceBindingSpec } from "${r}";`,`import { createServices } from "${r}";`],specs:`
|
|
@@ -297,7 +297,7 @@ ${t}
|
|
|
297
297
|
const LUNORA_SERVICES: ReadonlyArray<ServiceBindingSpec> = [
|
|
298
298
|
${t}
|
|
299
299
|
];
|
|
300
|
-
`}},
|
|
300
|
+
`}},ne=e=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};for(const t of e)l(t.exportName,`agent export "${t.exportName}"`),l(t.className,`agent class "${t.className}"`);const r=e.map(t=>` { className: "${t.className}", exportName: "${t.exportName}"${t.publicRun===!0?", publicRun: true":""} },`).join(`
|
|
301
301
|
`);return{build:`
|
|
302
302
|
const agents = createAgentContext(env, LUNORA_AGENTS, { exports: this.state.exports });
|
|
303
303
|
`,contextField:`
|
|
@@ -306,14 +306,14 @@ ${t}
|
|
|
306
306
|
const LUNORA_AGENTS: ReadonlyArray<AgentBindingSpec> = [
|
|
307
307
|
${r}
|
|
308
308
|
];
|
|
309
|
-
`}},
|
|
310
|
-
${
|
|
311
|
-
const ${e} = ${
|
|
309
|
+
`}},v=(e,r,t,n,a)=>({constant:`
|
|
310
|
+
${a}
|
|
311
|
+
const ${e} = ${b(n,r)};
|
|
312
312
|
`,override:`
|
|
313
313
|
protected override ${t}(): ${r} {
|
|
314
314
|
return ${e};
|
|
315
315
|
}
|
|
316
|
-
`}),
|
|
316
|
+
`}),re=e=>{if(e.length===0)return{constant:"",override:""};const r={workflows:e.map(t=>({className:t.className,exportName:t.exportName,name:t.name}))};return v("LUNORA_WORKFLOWS_INFO","WorkflowsResult","workflowsMetadata",r,"/** Read-only declared-workflow metadata (discovered from `lunora/workflows.ts`) served via `__lunora_admin__:listWorkflows` for the studio's workflows view. */")},oe=e=>{if(e.length===0)return{constant:"",override:""};const r={queues:e.map(t=>({binding:t.bindingName,...t.tuning.deadLetterQueue===void 0?{}:{deadLetterQueue:t.tuning.deadLetterQueue},exportName:t.exportName,mode:t.mode,name:t.name,...t.topic===void 0?{}:{topic:t.topic}}))};return v("LUNORA_QUEUES_INFO","QueuesResult","queuesMetadata",r,"/** Read-only declared-queue metadata (discovered from `lunora/queues.ts`) served via `__lunora_admin__:listQueues` for the studio's queues view. */")},P=["attach","cancelPayment","cancelSubscription","capturePayment","check","createCheckout","createPortalSession","handleWebhook","listBalances","listSubscriptions","refundPayment","track"],se=e=>e?{imports:['import type { LunoraDatabaseLike as LunoraPaymentDbLike, LunoraPayment, PaymentsFromContextOptions } from "@lunora/payment";','import { paymentsFromContext } from "@lunora/payment";'],build:`
|
|
317
317
|
let payments: LunoraPayment | undefined;
|
|
318
318
|
`,configField:`
|
|
319
319
|
payment?: (env: Record<string, unknown>) => PaymentsFromContextOptions;`,contextField:`
|
|
@@ -323,4 +323,4 @@ const ${e} = ${y(n,r)};
|
|
|
323
323
|
: paymentStub;
|
|
324
324
|
|
|
325
325
|
return payments;
|
|
326
|
-
},`,stub:
|
|
326
|
+
},`,stub:f("paymentStub: LunoraPayment","ctx.payments: no payment configured. Pass `payment` to createShardDO().",P,{cast:" as unknown as LunoraPayment",sync:!0})}:{build:"",configField:"",contextField:"",imports:[],stub:""},ae=(e,r,t,n,a)=>["AdvisorProcedure","AdvisoryFinding","DatabaseWriterLike","DataMigrationLike","DispatchBookmark","ExportRow",...n?["FlagsResult"]:[],"ImportShardResult","KeyRange","MaskPoliciesResult","MigrationRunResult","QueryReadScope",...t?["QueuesResult"]:[],"RelatedPage","RunShardApplyCdcArgs","RunShardExportArgs","RunShardFindRelatedArgs","RunShardImportArgs","RunShardMigrationArgs","RlsPoliciesResult","RunShardRankBeforeArgs","RunShardRankPageArgs","RunShardWriteArgs","RunShardWriteResult","SchedulerLike",...a?["SearchBackfillProgress"]:[],"TransactionHeadroomTracker","SchemaLike","ShardDOState","ShardRankPageResult","SqlExec","StorageRulesResult","StudioFeaturesResult","SubscriptionIdentity","SystemReaderStorageLike","TelemetrySink",...e?["VectorBackfillProgress"]:[],...r?["WorkflowsResult"]:[],...e?["WriteHook"]:[]];export{j as a,M as b,Q as c,Z as d,K as e,ee as f,te as g,H as h,z as i,ne as j,se as k,re as l,oe as m,D as n,ae as o,I as p,U as q,f as r,V as s,G as t,J as u,Y as v,X as w};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/codegen",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.279",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.201",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.189",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.71",
|
|
52
52
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
53
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
54
|
-
"@lunora/queue": "1.0.0-alpha.
|
|
55
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
53
|
+
"@lunora/platform": "1.0.0-alpha.58",
|
|
54
|
+
"@lunora/queue": "1.0.0-alpha.97",
|
|
55
|
+
"@lunora/scheduler": "1.0.0-alpha.116",
|
|
56
56
|
"@lunora/values": "1.0.0-alpha.61",
|
|
57
57
|
"@lunora/workflow": "1.0.0-alpha.72",
|
|
58
58
|
"@visulima/fs": "6.0.28",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{existsSync as y}from"node:fs";import{join as b}from"node:path";import{LunoraError as h}from"@lunora/errors";import{queueDefaultName as x,queueBindingName as w}from"@lunora/queue";import{SyntaxKind as v,Node as u}from"ts-morph";import{diagnosticAt as m}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{lunoraRelativePath as g,findObjectProperty as l,stringPropertyFor as S}from"./isTestPath-CgyyLk8U.mjs";import{a as F}from"./attribution-Dw35rOaJ.mjs";import{r as P}from"./handler-reference-2Hs4WKnz.mjs";import{d as E}from"./modules-BIpFLz3Z.mjs";const N="queues.ts",$=o=>{const e=t=>t==="defineQueue"||t==="defineSubscription"||t==="defineTopic",i=o.getSymbol();if(!i){const t=o.getText();return e(t)?t:void 0}for(const t of i.getDeclarations()){if(!u.isImportSpecifier(t))continue;if(t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue")return;const s=t.getNameNode().getText();return e(s)?s:void 0}},p=S("queue"),A=(o,e,i)=>{if(u.isNumericLiteral(o))return o.getLiteralValue();throw m(o,`queue "${e}": \`${i}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},I=(o,e)=>{const i=l(o,"name");if(!i||!u.isPropertyAssignment(i))return;const t=p(i.getInitializerOrThrow(),e,"name");if(t.length===0)throw m(i,`queue "${e}": \`name\` must be a non-empty string when provided`);return t},q=(o,e,i,t)=>{const s=P(l(o,"handler"),t)?.site,r={bindingName:w(e),exportName:e,filePath:g(t,o.getSourceFile().getFilePath()),mode:"push",name:I(o,e)??x(e),...i===void 0?{}:{topic:i},...s===void 0?{}:{handlerSite:s},tuning:{}},a=l(o,"mode");if(a&&u.isPropertyAssignment(a)){if(i!==void 0)throw m(a,`subscription "${e}": \`mode\` is not allowed — a subscription is always a push consumer`);const c=p(a.getInitializerOrThrow(),e,"mode");if(c!=="push"&&c!=="pull")throw m(a,`queue "${e}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(c)})`);r.mode=c}const n=l(o,"deadLetterQueue");n&&u.isPropertyAssignment(n)&&(r.tuning.deadLetterQueue=p(n.getInitializerOrThrow(),e,"deadLetterQueue"));for(const c of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const d=l(o,c);d&&u.isPropertyAssignment(d)&&(r.tuning[c]=A(d.getInitializerOrThrow(),e,c))}return r},T=(o,e,i)=>{const t=o.getArguments()[0];if(!t||!u.isObjectLiteralExpression(t))throw m(o,`queue "${e}": defineQueue must be passed an inline object literal`);return q(t,e,void 0,i)},f=(o,e)=>`${o}:${e}`,Q=o=>{const e=o.getSymbol(),i=(e?.isAlias()===!0?e.getAliasedSymbol():e)?.getDeclarations()[0];return i!==void 0&&u.isVariableDeclaration(i)?f(i.getSourceFile().getFilePath(),i.getName()):f(o.getSourceFile().getFilePath(),o.getText())},O=(o,e,i,t)=>{const[s,r]=o.getArguments(),a=s!==void 0&&u.isIdentifier(s)?i.get(Q(s)):void 0;if(a===void 0)throw m(s??o,`subscription "${e}": the first argument must name a \`defineTopic()\` export of lunora/queues.ts or a module's queues.ts`);if(!r||!u.isObjectLiteralExpression(r))throw m(o,`subscription "${e}": defineSubscription must be passed an inline object literal`);return q(r,e,a,t)},L=o=>{const e=[];for(const i of o.getVariableDeclarations()){const t=i.getInitializer();if(t?.getKind()!==v.CallExpression)continue;const s=t,r=s.getExpression(),a=u.isIdentifier(r)?$(r):void 0;if(a===void 0)continue;const n=i.getNameNode();if(!u.isIdentifier(n)){if(i.getVariableStatement()?.hasExportKeyword()!==!0)continue;throw m(n,`${a} exports must be plain named exports (no destructuring)`)}const c=F(i,"binding");c!==void 0&&e.push({call:s,exportName:c,factory:a,localName:n.getText()})}return e},U=(o,e)=>{const i=new Map;for(const t of o){const s=g(e,t.call.getSourceFile().getFilePath()),r=i.get(t.exportName);if(r!==void 0)throw m(t.call,`"${t.exportName}" is exported by both lunora/${r}.ts and lunora/${s}.ts — queue and topic export names must be unique across the app`);i.set(t.exportName,s)}},M=(o,e)=>{const i=o.flatMap(n=>L(n));U(i,e);const t=i.filter(n=>n.factory==="defineTopic"),s=new Map(t.map(n=>[f(n.call.getSourceFile().getFilePath(),n.localName),n.exportName])),r=[];for(const n of i)n.factory==="defineQueue"?r.push(T(n.call,n.exportName,e)):n.factory==="defineSubscription"&&r.push(O(n.call,n.exportName,s,e));const a=t.map(n=>({exportName:n.exportName,filePath:g(e,n.call.getSourceFile().getFilePath())}));return{queues:r,topics:a}},C=(o,e)=>[b(e,N),...E(o,e).map(i=>b(e,i.name,N))].filter(i=>y(i)),z=o=>{const e=new Map,i=new Map;for(const t of o){const s=e.get(t.name);if(s!==void 0)throw new h("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${t.name}": produced by both "${s}" and "${t.exportName}". Deployed queue names must be unique across the project.`,{status:500});e.set(t.name,t.exportName);const r=i.get(t.bindingName);if(r!==void 0)throw new h("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${t.bindingName}": produced by both "${r}" and "${t.exportName}". Queue export names must yield unique binding names.`,{status:500});i.set(t.bindingName,t.exportName)}},D=(o,e)=>{const i=C(o,e).map(a=>o.getSourceFile(a)??o.addSourceFileAtPath(a)),{queues:t,topics:s}=M(i,e),r=t.toSorted((a,n)=>a.exportName.localeCompare(n.exportName));return z(r),{queues:r,topics:s.toSorted((a,n)=>a.exportName.localeCompare(n.exportName))}},W=(o,e)=>D(o,e).queues;export{N as QUEUES_FILENAME,D as discoverQueueDeclarations,W as discoverQueues};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{o as i,j as r,s as o,h as n,t as g,k as F,d as u,v as p,m as f,g as l,f as d,i as k,u as w,l as Q}from"./shard-runtime-BI2SZ54Z.mjs";import"./shared-Be3TGzxM.mjs";export{i as buildDoTypeImports,r as emitAgentFragments,o as emitAgents,n as emitContainerFragments,g as emitContainers,F as emitPaymentFragments,u as emitQueueFragments,p as emitQueues,f as emitQueuesMetadataFragments,l as emitServiceFragments,d as emitTopicFragments,k as emitWorkflowFragments,w as emitWorkflows,Q as emitWorkflowsMetadataFragments};
|