@lunora/codegen 1.0.0-alpha.381 → 1.0.0-alpha.383
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 +207 -95
- package/dist/index.d.ts +207 -95
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{GENERATED_HEADER-DPEvCN8Z.mjs → GENERATED_HEADER-Bzf6ZJ9r.mjs} +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-Ipxibja6.mjs → MUTATORS_FILENAME-BGvYo46g.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-B-t7jQSm.mjs → NOTIFY_FILENAME-BJJObZHG.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-DA0ZNkhl.mjs → OPENRPC_VERSION-CSjT8wJW.mjs} +1 -1
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_FILENAME-D3x_KiFb.mjs → SCHEMA_SNAPSHOT_FILENAME-kN0pgKNu.mjs} +9 -9
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-BdxZuSxk.mjs +2 -0
- package/dist/packem_shared/{SHAPES_FILENAME-mgEi072Z.mjs → SHAPES_FILENAME-KyidzoqS.mjs} +1 -1
- package/dist/packem_shared/SchemaSnapshotParseError-ycDz8gOB.mjs +17 -0
- package/dist/packem_shared/{buildOpenApiDocument-Ct2wK_Tj.mjs → buildOpenApiDocument-afHH7rN5.mjs} +1 -1
- package/dist/packem_shared/{context-property-calls-DKMO9ShK.mjs → context-property-calls-B75cjwpy.mjs} +1 -1
- package/dist/packem_shared/{context-root-BPfMNAJM.mjs → context-root-D4Njep-A.mjs} +1 -1
- package/dist/packem_shared/{database-calls-hLzaOquW.mjs → database-calls-aAjZJdma.mjs} +1 -1
- package/dist/packem_shared/{discoverFunctions-a0IT8OSb.mjs → discoverFunctions-CoQM_L6f.mjs} +1 -1
- package/dist/packem_shared/{discoverHttpRoutes-DHDfKLoa.mjs → discoverHttpRoutes-BQM2CPSF.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-PUg-BESh.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-IAa3lRR4.mjs → discoverInserts-DldQpEfF.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-_Ey4eJLn.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-E9k4Ykku.mjs +1 -0
- package/dist/packem_shared/{discoverQueries-DZOGiEPs.mjs → discoverQueries-Bq2hqYHP.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-CeNnalpk.mjs +1 -0
- package/dist/packem_shared/{discoverRlsProcedures-B0DYk-gW.mjs → discoverRlsProcedures-MboagP9z.mjs} +1 -1
- package/dist/packem_shared/{discoverSchema-DmkjooXZ.mjs → discoverSchema-Cycd1-H0.mjs} +1 -1
- package/dist/packem_shared/{emitAgents-CrSmVS4d.mjs → emitAgents-BeM6PZv4.mjs} +1 -1
- package/dist/packem_shared/{emitApi-D6uqyYd_.mjs → emitApi-GFmStqmq.mjs} +1 -1
- package/dist/packem_shared/{emitApp-DT4eMX6J.mjs → emitApp-D-6FIpYb.mjs} +65 -47
- package/dist/packem_shared/{emitCrons-C3RiGYk7.mjs → emitCrons-Drdn8Mjn.mjs} +1 -1
- package/dist/packem_shared/{emitDataModel-BMMht_iZ.mjs → emitDataModel-LTnwnhV6.mjs} +1 -1
- package/dist/packem_shared/{emitDrizzleSchema-BmCxM6tO.mjs → emitDrizzleSchema-CM9jh_F0.mjs} +1 -1
- package/dist/packem_shared/{emitFunctions-NGByI1FZ.mjs → emitFunctions-CfSXBV_A.mjs} +1 -1
- package/dist/packem_shared/{emitServer-4NV3vaOg.mjs → emitServer-4l7MPmK0.mjs} +1 -1
- package/dist/packem_shared/emitShard-B4fVJcJA.mjs +1 -0
- package/dist/packem_shared/{index-BjDVAPNW.mjs → index-11LAY5JO.mjs} +1 -1
- package/dist/packem_shared/parse-validator-BisfC8bR.mjs +1 -0
- package/dist/packem_shared/{qualifiers-CPQCkXC4.mjs → qualifiers-D1Q_3wo2.mjs} +1 -1
- package/dist/packem_shared/{server-BY1v1bTx.mjs → server-D69SOfX8.mjs} +1 -1
- package/dist/packem_shared/{shard-DmDBaK79.mjs → shard-CB0Ospyw.mjs} +1 -1
- package/dist/packem_shared/{shard-runtime-BtEGoPTf.mjs → shard-runtime-lkQU8trx.mjs} +72 -68
- package/dist/packem_shared/{shared-BErjtci3.mjs → shared-A1XHcT4t.mjs} +1 -1
- package/package.json +4 -4
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-SplX7j_9.mjs +0 -2
- package/dist/packem_shared/SchemaSnapshotParseError-CjKSMuex.mjs +0 -18
- package/dist/packem_shared/discoverHyperdriveCalls-i8Zcf64H.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-Bj6fPF4u.mjs +0 -1
- package/dist/packem_shared/discoverMigrations-Bv8kNIgy.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-Lq6G--TZ.mjs +0 -1
- package/dist/packem_shared/emitShard-VIGqeQvE.mjs +0 -1
- package/dist/packem_shared/parse-validator-CP5CL6Q7.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as
|
|
1
|
+
import{LunoraError as k}from"@lunora/errors";import{r as b}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as R}from"./CAPABILITY_PROBES-DKYJ2K4t.mjs";import{a as l,G as f,I as w}from"./shared-A1XHcT4t.mjs";import{s as S}from"./platform-8oj7iXQy.mjs";const Q=e=>e?{importFragment:"serveRelationFanout, ",override:`
|
|
2
2
|
protected override async runRelationFanoutRead(functionPath: string, args: Record<string, unknown>): Promise<unknown> {
|
|
3
3
|
this.ensureServable();
|
|
4
4
|
|
|
@@ -6,14 +6,14 @@ import{LunoraError as N}from"@lunora/errors";import{r as b}from"./json-data-Chfs
|
|
|
6
6
|
|
|
7
7
|
return serveRelationFanout(schema as unknown as SchemaLike, db, functionPath, args);
|
|
8
8
|
}
|
|
9
|
-
`}:{importFragment:"",override:""},
|
|
10
|
-
${
|
|
9
|
+
`}:{importFragment:"",override:""},y=(e,r,t,{cast:n="",sync:s=[]}={})=>{const i=`throw new Error(${JSON.stringify(r)});`,c=t.map(u=>` ${u}: ${s===!0||s.includes(u)?"":"async "}() => {
|
|
10
|
+
${i}
|
|
11
11
|
},`).join(`
|
|
12
12
|
`);return`
|
|
13
13
|
const ${e} = {
|
|
14
14
|
${c}
|
|
15
15
|
}${n};
|
|
16
|
-
`},
|
|
16
|
+
`},x={build:"",configField:"",contextField:"",importLines:[],stub:""},M=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,26 +22,26 @@ 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
|
+
`},K=(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: readIdentity() ?? null, userId: readUserId() ?? 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:""}:x,H=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:""}:x,G=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:""}:x,V=(e,r,t)=>{if(!r)return{constant:"",evaluateOverride:"",subscriptionOverride:""};const n=a=>`
|
|
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: ${a},
|
|
44
|
+
});`,s=`
|
|
45
45
|
/** Statically-discovered feature flags (\`ctx.flags.<type>("key")\` reads) served via \`__lunora_admin__:listFlags\` + the reactive \`__lunora_flags__:\` channel. */
|
|
46
46
|
const LUNORA_FLAG_KEYS = ${b(e,'ReadonlyArray<{ key: string; type: "boolean" | "number" | "object" | "string" }>')};
|
|
47
47
|
`,c=`
|
|
@@ -66,7 +66,7 @@ const LUNORA_FLAG_KEYS = ${b(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
66
66
|
|
|
67
67
|
return { configured: true, flags: evaluations };
|
|
68
68
|
}
|
|
69
|
-
`,
|
|
69
|
+
`,u=`
|
|
70
70
|
protected override runFlagSubscriptionRead(_functionPath: string, args: Record<string, unknown>, identity?: SubscriptionIdentity): Promise<unknown> {${n("() => flagsConfig.identify?.({ identity: identity?.identity ?? null, userId: identity?.userId ?? null })")}
|
|
71
71
|
const key = typeof args.key === "string" ? args.key : "";
|
|
72
72
|
|
|
@@ -99,7 +99,7 @@ const LUNORA_FLAG_KEYS = ${b(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
99
99
|
|
|
100
100
|
return flags.boolean(key, typeof args.default === "boolean" ? args.default : false, context);
|
|
101
101
|
}
|
|
102
|
-
`;return{constant:
|
|
102
|
+
`;return{constant:s,evaluateOverride:c,subscriptionOverride:u}},L=()=>({build:`
|
|
103
103
|
const aiBinding = config.ai?.(env) ?? (env as Record<string, unknown>).AI;
|
|
104
104
|
// Correlate AI-Gateway-routed calls with the Lunora trace: thread the
|
|
105
105
|
// function path + trace id into createAi, which folds them into the
|
|
@@ -116,9 +116,9 @@ const LUNORA_FLAG_KEYS = ${b(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
116
116
|
telemetry: { metrics, trace },
|
|
117
117
|
});
|
|
118
118
|
`,configField:`
|
|
119
|
-
ai?: (env: Record<string, unknown>) => AiBindingLike;`,importLines:['import type { AiBindingLike, LunoraAi } from "@lunora/ai/create";','import { createAi } from "@lunora/ai/create";'],stub:""}),
|
|
119
|
+
ai?: (env: Record<string, unknown>) => AiBindingLike;`,importLines:['import type { AiBindingLike, LunoraAi } from "@lunora/ai/create";','import { createAi } from "@lunora/ai/create";'],stub:""}),A=()=>({build:`
|
|
120
120
|
const access = lazyAccessFacade(readIdentity, readUserId);
|
|
121
|
-
`,configField:"",importLines:['import { lazyAccessFacade } from "@lunora/cloudflare-access/context";'],stub:""}),
|
|
121
|
+
`,configField:"",importLines:['import { lazyAccessFacade } from "@lunora/cloudflare-access/context";'],stub:""}),_=()=>({build:`
|
|
122
122
|
const r2sqlEnv = env as Record<string, unknown>;
|
|
123
123
|
const r2sqlAccountId = (r2sqlEnv.R2_SQL_ACCOUNT_ID ?? r2sqlEnv.CLOUDFLARE_ACCOUNT_ID) as string | undefined;
|
|
124
124
|
const r2sqlToken = r2sqlEnv.R2_SQL_TOKEN as string | undefined;
|
|
@@ -129,36 +129,36 @@ const LUNORA_FLAG_KEYS = ${b(e,'ReadonlyArray<{ key: string; type: "boolean" | "
|
|
|
129
129
|
? createR2Sql({ accountId: r2sqlAccountId, apiToken: r2sqlToken, bucket: r2sqlBucket })
|
|
130
130
|
: r2sqlStub;
|
|
131
131
|
`,configField:`
|
|
132
|
-
r2sql?: (env: Record<string, unknown>) => R2SqlClient;`,importLines:['import type { R2SqlClient } from "@lunora/bindings/r2sql";','import { createR2Sql } from "@lunora/bindings/r2sql";'],stub:
|
|
132
|
+
r2sql?: (env: Record<string, unknown>) => R2SqlClient;`,importLines:['import type { R2SqlClient } from "@lunora/bindings/r2sql";','import { createR2Sql } from "@lunora/bindings/r2sql";'],stub:y("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"]})}),C=()=>({build:`
|
|
133
133
|
const x402: X402Pay = config.x402
|
|
134
134
|
? lazyX402Pay(config.x402(env), { getSecret: (name: string) => secrets.get(name) })
|
|
135
135
|
: x402Stub;
|
|
136
136
|
`,configField:`
|
|
137
|
-
x402?: (env: Record<string, unknown>) => X402PayConfig;`,importLines:['import type { X402Pay, X402PayConfig } from "@lunora/x402/pay";','import { lazyX402Pay } from "@lunora/x402/pay";'],stub:
|
|
138
|
-
`,
|
|
139
|
-
${
|
|
137
|
+
x402?: (env: Record<string, unknown>) => X402PayConfig;`,importLines:['import type { X402Pay, X402PayConfig } from "@lunora/x402/pay";','import { lazyX402Pay } from "@lunora/x402/pay";'],stub:y("x402Stub: X402Pay","ctx.x402: no pay rail configured. Pass `x402` to createShardDO().",["fetch"],{cast:" as unknown as X402Pay",sync:["fetch"]})}),F={access:A,ai:L,r2sql:_,x402:C},E=e=>e.shardBinding==="bespoke",O=e=>typeof e.shardBinding=="object",m=" ",P=(e,r,t)=>{const n=`${e}Binding`,{factory:s}=t;let i=`(${n} as ${r})`;if(s!==void 0){const c=`${n} as ${t.bindingType??r}`;i=s.option===void 0?`${s.name}(${c})`:`${s.name}({ ${s.option}: ${c} })`}return`${n} ? ${i} : ${e}Stub`},q=(e,r,t)=>{const n=P(e,r,t),s=`${m}const ${e}Binding = config.${e}?.(env) ?? (env as Record<string, unknown>).${t.envName};
|
|
138
|
+
`,i=t.unvouchableReads??[];return i.length===0?`
|
|
139
|
+
${s}${m}const ${e}: ${r} = ${n};
|
|
140
140
|
`:`
|
|
141
|
-
${
|
|
141
|
+
${s}${m}// ${t.envName} is not this shard's SQLite, so nothing appends a \`__cdc_log\` entry
|
|
142
142
|
${m}// when a value changes — a subscription that read one can never be proven
|
|
143
143
|
${m}// current on reconnect and must re-snapshot. Reads only; writes stay unstamped.
|
|
144
144
|
${m}const ${e}: ${r} = markUnvouchableReads(${n}, options.onRead, [
|
|
145
|
-
${
|
|
145
|
+
${i.map(c=>`${m} ${JSON.stringify(c)},`).join(`
|
|
146
146
|
`)}
|
|
147
147
|
${m}]);
|
|
148
|
-
`},
|
|
149
|
-
${m}const ${e}: ${
|
|
148
|
+
`},W=(e,r,t)=>{const{binding:n,clientType:s}=t,i=y(`${e}Stub: ${s}`,t.missingMessage,t.stubMethods,{sync:t.syncStubMethods});if(n===void 0){const a=t.instrument===void 0?`config.${e}(env)`:`this.${t.instrument}(config.${e}(env), logFunctionPath, traceAnchor, observability)`;return{build:`
|
|
149
|
+
${m}const ${e}: ${s} = config.${e} ? ${a} : ${e}Stub;
|
|
150
150
|
`,configField:`
|
|
151
|
-
${e}?: (env: Record<string, unknown>) => ${
|
|
152
|
-
${e}?: (env: Record<string, unknown>) => ${c};`,importLines:[`import type { ${
|
|
153
|
-
${d},`):(n+=
|
|
154
|
-
export class ${
|
|
151
|
+
${e}?: (env: Record<string, unknown>) => ${s};`,importLines:[`import type { ${s} } from "${r}";`],stub:i}}const c=n.bindingType??s,u=[...new Set([c,s])].toSorted((a,o)=>a.localeCompare(o));return{build:q(e,s,n),configField:`
|
|
152
|
+
${e}?: (env: Record<string, unknown>) => ${c};`,importLines:[`import type { ${u.join(", ")} } from "${r}";`,...n.factory===void 0?[]:[`import { ${n.factory.name} } from "${r}";`]],stub:i}},J=e=>{const r=[],t=[];let n="",s="",i="",c="",u="";for(const a of R.filter(({key:o})=>e.has(o))){let o;if(E(a))o=F[a.key]();else if(O(a))o=W(a.contextProperty,a.moduleSpecifier,a.shardBinding);else continue;const d=a.contextProperty;t.push(...o.importLines),s+=o.configField,u+=o.stub,a.tier==="every"?(i+=o.build,c+=`
|
|
153
|
+
${d},`):(n+=o.build,r.push(d))}return{actionBuild:n,actionFields:r,configFields:s,everyBuild:i,everyFields:c,importLines:t,stubs:u}},Y=(e,r)=>{if(e.length===0)return"";const t=r?`, ${JSON.stringify(r)}`:"",n=e.map(o=>{l(o.exportName,`container export "${o.exportName}"`),l(o.className,`container class "${o.className}"`);const d=o.sandbox===!0?"LunoraSandboxContainer":"LunoraContainer";return`/** Container DO for the \`${o.exportName}\` definition (binding \`${o.bindingName}\`). */
|
|
154
|
+
export class ${o.className} extends ${d} {
|
|
155
155
|
public constructor(ctx: ConstructorParameters<typeof ${d}>[0], env: Record<string, unknown>) {
|
|
156
|
-
super(ctx, env, ${
|
|
156
|
+
super(ctx, env, ${o.exportName}, "${o.exportName}"${t});
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
`}).join(`
|
|
160
|
-
`),
|
|
161
|
-
`:"";return`${
|
|
160
|
+
`),s=e.map(o=>o.exportName).join(", "),i=e.some(o=>o.sandbox===!0),c=e.some(o=>o.sandbox!==!0)?`import { LunoraContainer } from "@lunora/container/do";
|
|
161
|
+
`:"";return`${f}/**
|
|
162
162
|
* Container-enabled Durable Object classes for the containers declared in
|
|
163
163
|
* \`lunora/containers.ts\`. Re-export them from your worker entry — wrangler
|
|
164
164
|
* requires each \`containers[].class_name\` to be exported by the worker:
|
|
@@ -170,19 +170,19 @@ export class ${i.className} extends ${d} {
|
|
|
170
170
|
* \`handle.egress\` controls) routes container outbound traffic through this
|
|
171
171
|
* WorkerEntrypoint, so it too must be exported by the deployed worker.
|
|
172
172
|
*/
|
|
173
|
-
${c}${
|
|
173
|
+
${c}${i?`import { LunoraSandboxContainer } from "@lunora/container/sandbox";
|
|
174
174
|
`:""}
|
|
175
|
-
import { ${
|
|
175
|
+
import { ${s} } from "../containers.js";
|
|
176
176
|
|
|
177
177
|
export { ContainerProxy } from "@lunora/container/do";
|
|
178
|
-
${
|
|
178
|
+
${i?`
|
|
179
179
|
/**
|
|
180
180
|
* \`DirectoryBackup\` and \`S3Mount\` route a \`sandbox: true\` container's storage
|
|
181
181
|
* traffic through these WorkerEntrypoints, so the deployed worker must export them.
|
|
182
182
|
*/
|
|
183
183
|
export { DirectoryBackupGateway, S3Gateway } from "@lunora/container/sandbox";
|
|
184
184
|
`:""}
|
|
185
|
-
${n}`},
|
|
185
|
+
${n}`},z=(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 s=n.schedulingPolicy!==void 0||n.maxInstances===void 0?"":`, maxInstances: ${String(n.maxInstances)}`;return` { binding: "${n.bindingName}", exportName: "${n.exportName}"${s} },`}).join(`
|
|
186
186
|
`);return{build:`
|
|
187
187
|
const containers = createContainerContext(env, LUNORA_CONTAINERS, ${r?JSON.stringify(r):"undefined"}, this.getCurrentTraceparent(), this.getCurrentSampleErrors());
|
|
188
188
|
`,contextField:`
|
|
@@ -191,14 +191,14 @@ ${n}`},Y=(e,r)=>{if(e.length===0)return{build:"",contextField:"",importLines:[],
|
|
|
191
191
|
const LUNORA_CONTAINERS: ReadonlyArray<ContainerBindingSpec> = [
|
|
192
192
|
${t}
|
|
193
193
|
];
|
|
194
|
-
`}},X=e=>{if(e.length===0)return"";const r=e.map(
|
|
195
|
-
export class ${
|
|
194
|
+
`}},X=(e,r={})=>{if(e.length===0)return"";const t=r.lazy===!0,n=e.map(i=>{l(i.exportName,`workflow export "${i.exportName}"`),l(i.className,`workflow class "${i.className}"`);const c=t?`async () => (await import("../workflows.js")).${i.exportName}`:i.exportName;return`/** WorkflowEntrypoint for the \`${i.exportName}\` definition, reached as \`ctx.exports.${i.className}\`. */
|
|
195
|
+
export class ${i.className} extends LunoraWorkflow<WorkflowParamsOf<typeof ${i.exportName}>, WorkflowOutputOf<typeof ${i.exportName}>> {
|
|
196
196
|
public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
197
|
-
super(ctx, env, ${
|
|
197
|
+
super(ctx, env, ${c}, "${i.exportName}");
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
`)
|
|
201
|
-
`),
|
|
200
|
+
`}).join(`
|
|
201
|
+
`),s=e.map(i=>i.exportName).join(", ");return`${f}/**
|
|
202
202
|
* WorkflowEntrypoint classes for the workflows declared in
|
|
203
203
|
* \`lunora/workflows.ts\`. Re-export them from your worker entry — wrangler
|
|
204
204
|
* requires each \`workflows[].class_name\` to be exported by the worker:
|
|
@@ -207,7 +207,7 @@ export class ${n.className} extends LunoraWorkflow<WorkflowParamsOf<typeof ${n.e
|
|
|
207
207
|
*/
|
|
208
208
|
import LunoraWorkflow from "@lunora/workflow/do";
|
|
209
209
|
|
|
210
|
-
import { ${
|
|
210
|
+
import ${t?"type ":""}{ ${s} } from "../workflows.js";
|
|
211
211
|
|
|
212
212
|
/** Params type carried by a \`defineWorkflow\` definition (its phantom \`__params\`), so each entrypoint keeps the authored \`ctx.params\` type. */
|
|
213
213
|
type WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params }
|
|
@@ -219,37 +219,41 @@ type WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params
|
|
|
219
219
|
/** Output type carried by a \`defineWorkflow\` definition (its phantom \`__output\`), so each entrypoint keeps the authored return type. */
|
|
220
220
|
type WorkflowOutputOf<Definition> = Definition extends { __output?: infer Output } ? Output : unknown;
|
|
221
221
|
|
|
222
|
-
${
|
|
223
|
-
export class ${
|
|
222
|
+
${n}`},Z=(e,r={})=>{if(e.length===0)return"";const n=e.filter(o=>o.voice).length>0,s=r.lazy===!0&&!n,i=e.map(o=>{l(o.exportName,`agent export "${o.exportName}"`),l(o.className,`agent class "${o.className}"`);const d=`/** WorkflowEntrypoint for the \`${o.exportName}\` agent, reached as \`ctx.exports.${o.className}\`. */
|
|
223
|
+
export class ${o.className} extends LunoraWorkflow<AgentRunInput, AgentRunResult> {
|
|
224
224
|
public constructor(ctx: ConstructorParameters<typeof LunoraWorkflow>[0], env: Record<string, unknown>) {
|
|
225
|
-
super(ctx, env,
|
|
225
|
+
super(ctx, env, ${s?`async () => {
|
|
226
|
+
const [{ compileAgentWorkflow }, { ${o.exportName}: definition }] = await Promise.all([import("@lunora/agent"), import("../agents.js")]);
|
|
227
|
+
|
|
228
|
+
return compileAgentWorkflow(definition, "${o.exportName}");
|
|
229
|
+
}`:`compileAgentWorkflow(${o.exportName}, "${o.exportName}")`}, "${o.exportName}");
|
|
226
230
|
}
|
|
227
231
|
}
|
|
228
|
-
`;if(!
|
|
229
|
-
/** Voice-session Durable Object for the \`${
|
|
230
|
-
export class ${
|
|
232
|
+
`;if(!o.voice)return d;const p=o.voiceClassName??"",g=o.voiceBindingName??"";l(p,`agent voice class "${p}"`);const N=`
|
|
233
|
+
/** Voice-session Durable Object for the \`${o.exportName}\` agent (binding \`${g}\`). */
|
|
234
|
+
export class ${p} extends VoiceSessionDO {
|
|
231
235
|
public constructor(ctx: ConstructorParameters<typeof VoiceSessionDO>[0], env: Record<string, unknown>) {
|
|
232
|
-
super(ctx, env, ${
|
|
236
|
+
super(ctx, env, ${o.exportName}, "${o.exportName}");
|
|
233
237
|
}
|
|
234
238
|
}
|
|
235
|
-
`;return`${
|
|
236
|
-
`),
|
|
239
|
+
`;return`${d}${N}`}).join(`
|
|
240
|
+
`),c=e.map(o=>o.exportName).join(", ");let u='import { compileAgentWorkflow } from "@lunora/agent";';return n?u='import { compileAgentWorkflow, VoiceSessionDO } from "@lunora/agent";':s&&(u=""),`${f}/**
|
|
237
241
|
* WorkflowEntrypoint classes for the agents declared in \`lunora/agents.ts\`.
|
|
238
242
|
* Each \`defineAgent\` compiles a replay-safe tool-loop onto a Cloudflare
|
|
239
243
|
* Workflow. Re-export them from your worker entry — wrangler requires each
|
|
240
244
|
* \`workflows[].class_name\` to be exported by the worker:
|
|
241
245
|
*
|
|
242
|
-
* \`export * from "./lunora/_generated/agents.js";\`${
|
|
246
|
+
* \`export * from "./lunora/_generated/agents.js";\`${n?"\n *\n * Voice-enabled agents ALSO get a `VoiceSessionDO` subclass here — a real\n * Durable Object (unlike the Workflow), so wrangler needs both its\n * `durable_objects` binding and its `class_name` export (the same re-export\n * line covers it).":""}
|
|
243
247
|
*/
|
|
244
248
|
import LunoraWorkflow from "@lunora/workflow/do";
|
|
245
|
-
${
|
|
246
|
-
import type { AgentRunInput, AgentRunResult } from "@lunora/agent";
|
|
247
|
-
|
|
248
|
-
import { ${
|
|
249
|
-
|
|
250
|
-
${
|
|
251
|
-
`),{routes:
|
|
252
|
-
`);return`${
|
|
249
|
+
${u===""?"":`${u}
|
|
250
|
+
`}import type { AgentRunInput, AgentRunResult } from "@lunora/agent";
|
|
251
|
+
${s?"":`
|
|
252
|
+
import { ${c} } from "../agents.js";
|
|
253
|
+
`}
|
|
254
|
+
${i}`},h=e=>e.env===void 0?"the top level":`env.${e.env}`,$=(e,r)=>{const t=e.filter(a=>a.mode==="push"),n=new Map(t.map(a=>[a.bindingName,a])),s=new Map(e.map(a=>[a.name,a])),i=new Map(t.map(a=>[a.name,a])),c=new Map,u=[];for(const a of r){const o=n.get(a.binding);if(o===void 0||a.queue===o.name)continue;const d=s.get(a.queue);if(d!==void 0){u.push(`${h(a)} maps \`${a.binding}\` to "${a.queue}", the declared name of queue \`${d.exportName}\` — batches for "${a.queue}" go to \`${d.exportName}\`, never \`${o.exportName}\`.`);continue}const p=i.get(a.queue);if(p===void 0)i.set(a.queue,o),c.set(a.queue,a);else if(p!==o){const g=c.get(a.queue);u.push(`"${a.queue}" is aliased to \`${p.exportName}\` by ${g===void 0?"an earlier producer":h(g)} and to \`${o.exportName}\` by ${h(a)} — batches for it go to \`${p.exportName}\`.`)}}return{conflicts:u,routes:i}},ee=(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"})),te=(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,u])=>`import { ${u.map(a=>a.exportName).join(", ")} } from "../${c}.js";`).join(`
|
|
255
|
+
`),{routes:s}=$(e,r),i=[...s].map(([c,u])=>` ${JSON.stringify(c)}: { binding: ${JSON.stringify(u.bindingName)}, definition: ${u.exportName}, exportName: ${JSON.stringify(u.exportName)} },`).join(`
|
|
256
|
+
`);return`${f}/**
|
|
253
257
|
* Push-consumer registry for the queues declared in \`lunora/queues.ts\`. The
|
|
254
258
|
* composed worker's \`queue(batch, env, ctx)\` entry routes each delivered batch
|
|
255
259
|
* by \`batch.queue\` to the matching \`defineQueue\` handler. Wired automatically
|
|
@@ -261,9 +265,9 @@ ${n}
|
|
|
261
265
|
|
|
262
266
|
/** Wrangler queue name (declared, or a per-environment rename) → { binding, definition, exportName } for batch routing. */
|
|
263
267
|
export const LUNORA_QUEUE_REGISTRY: QueueRegistry = {
|
|
264
|
-
${
|
|
268
|
+
${i}
|
|
265
269
|
};
|
|
266
|
-
`},
|
|
270
|
+
`},ne=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(`
|
|
267
271
|
`);return{build:`
|
|
268
272
|
const workflows = createWorkflowContext(env, LUNORA_WORKFLOWS, this.state.exports);
|
|
269
273
|
`,contextField:`
|
|
@@ -272,7 +276,7 @@ ${u}
|
|
|
272
276
|
const LUNORA_WORKFLOWS: ReadonlyArray<WorkflowBindingSpec> = [
|
|
273
277
|
${r}
|
|
274
278
|
];
|
|
275
|
-
`}},
|
|
279
|
+
`}},re=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(`
|
|
276
280
|
`);return{build:`
|
|
277
281
|
const queues = createQueueContext(env, LUNORA_QUEUES);
|
|
278
282
|
`,contextField:`
|
|
@@ -281,7 +285,7 @@ ${r}
|
|
|
281
285
|
const LUNORA_QUEUES: ReadonlyArray<QueueBindingSpec> = [
|
|
282
286
|
${r}
|
|
283
287
|
];
|
|
284
|
-
`}},
|
|
288
|
+
`}},oe=(e,r)=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};const t=e.map(n=>{l(n.exportName,`topic export "${n.exportName}"`);const s=S(r,n.exportName).map(i=>`{ binding: "${i.bindingName}", exportName: "${i.exportName}" }`).join(", ");return` { exportName: "${n.exportName}", subscriptions: [${s}] },`}).join(`
|
|
285
289
|
`);return{build:`
|
|
286
290
|
const topics = createTopicContext(env, LUNORA_TOPICS);
|
|
287
291
|
`,contextField:`
|
|
@@ -290,7 +294,7 @@ ${r}
|
|
|
290
294
|
const LUNORA_TOPICS: ReadonlyArray<TopicBindingSpec> = [
|
|
291
295
|
${t}
|
|
292
296
|
];
|
|
293
|
-
`}},
|
|
297
|
+
`}},se=(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(`
|
|
294
298
|
`);return{build:`
|
|
295
299
|
const services = createServices(env, LUNORA_SERVICES);
|
|
296
300
|
`,importLines:[`import type { ServiceBindingSpec } from "${r}";`,`import { createServices } from "${r}";`],specs:`
|
|
@@ -298,7 +302,7 @@ ${t}
|
|
|
298
302
|
const LUNORA_SERVICES: ReadonlyArray<ServiceBindingSpec> = [
|
|
299
303
|
${t}
|
|
300
304
|
];
|
|
301
|
-
`}},
|
|
305
|
+
`}},ae=(e,r)=>{if(e.length===0)return{build:"",contextField:"",importLines:[],specs:""};for(const n of e)l(n.exportName,`agent export "${n.exportName}"`),l(n.className,`agent class "${n.className}"`);const t=e.map(n=>` { className: "${n.className}", exportName: "${n.exportName}"${n.publicRun===!0?", publicRun: true":""} },`).join(`
|
|
302
306
|
`);return{build:`
|
|
303
307
|
const agents = createAgentContext(env, LUNORA_AGENTS, { exports: this.state.exports });
|
|
304
308
|
`,contextField:r?`
|
|
@@ -309,14 +313,14 @@ ${t}
|
|
|
309
313
|
const LUNORA_AGENTS: ReadonlyArray<AgentBindingSpec> = [
|
|
310
314
|
${t}
|
|
311
315
|
];
|
|
312
|
-
`}}
|
|
313
|
-
${
|
|
316
|
+
`}},v=(e,r,t,n,s)=>({constant:`
|
|
317
|
+
${s}
|
|
314
318
|
const ${e} = ${b(n,r)};
|
|
315
319
|
`,override:`
|
|
316
320
|
protected override ${t}(): ${r} {
|
|
317
321
|
return ${e};
|
|
318
322
|
}
|
|
319
|
-
`}),
|
|
323
|
+
`}),ie=(e,r)=>{if(e.length===0)return{constant:"",override:""};const t={...r.length===0?{}:{eventTypes:r.map(n=>n.type)},workflows:e.map(n=>({className:n.className,exportName:n.exportName,name:n.name}))};return v("LUNORA_WORKFLOWS_INFO","WorkflowsResult","workflowsMetadata",t,"/** Read-only declared-workflow metadata (discovered from `lunora/workflows.ts`) served via `__lunora_admin__:listWorkflows` for the studio's workflows view. */")},ce=(e,r)=>{if(e.length===0||r.length===0)return{constant:"",override:""};for(const t of r)if(l(t.exportName,"workflow event export name"),!w.test(t.filePath))throw new k("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe workflow event file path: ${JSON.stringify(t.filePath)}`);return{constant:`
|
|
320
324
|
/** Declared workflow events (\`defineWorkflowEvent\` exports), loaded by type when an admin \`sendWorkflowEvent\` parses its payload. */
|
|
321
325
|
const LUNORA_WORKFLOW_EVENTS: ReadonlyMap<string, () => Promise<{ payload: { parse: (value: unknown) => unknown } }>> = new Map([
|
|
322
326
|
${r.map(t=>` [${JSON.stringify(t.type)}, () => import("../${t.filePath}.js").then((module) => module.${t.exportName})],`).join(`
|
|
@@ -326,7 +330,7 @@ ${r.map(t=>` [${JSON.stringify(t.type)}, () => import("../${t.filePath}.js").
|
|
|
326
330
|
protected override async workflowEvent(type: string): Promise<{ payload: { parse: (value: unknown) => unknown } } | undefined> {
|
|
327
331
|
return LUNORA_WORKFLOW_EVENTS.get(type)?.();
|
|
328
332
|
}
|
|
329
|
-
`}},
|
|
333
|
+
`}},ue=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. */")},T=["attach","cancelPayment","cancelSubscription","capturePayment","check","createCheckout","createPortalSession","handleWebhook","listBalances","listSubscriptions","refundPayment","track"],le=e=>e?{imports:['import type { LunoraDatabaseLike as LunoraPaymentDbLike, LunoraPayment, PaymentsFromContextOptions } from "@lunora/payment";','import { paymentsFromContext } from "@lunora/payment";'],build:`
|
|
330
334
|
const paymentsByContext = new WeakMap<object, LunoraPayment>();
|
|
331
335
|
`,configField:`
|
|
332
336
|
payment?: (env: Record<string, unknown>) => PaymentsFromContextOptions;`,contextField:`
|
|
@@ -341,4 +345,4 @@ ${r.map(t=>` [${JSON.stringify(t.type)}, () => import("../${t.filePath}.js").
|
|
|
341
345
|
}
|
|
342
346
|
|
|
343
347
|
return payments;
|
|
344
|
-
},`,stub:
|
|
348
|
+
},`,stub:y("paymentStub: LunoraPayment","ctx.payments: no payment configured. Pass `payment` to createShardDO().",T,{cast:" as unknown as LunoraPayment",sync:!0})}:{build:"",configField:"",contextField:"",imports:[],stub:""},de=(e,r,t,n,s)=>["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","SensitiveScope",...s?["SearchBackfillProgress"]:[],"TransactionHeadroomTracker","SchemaLike","ShardDOState","DeliveryAuthorization","ShardRankPageResult","SqlExec","StorageRulesResult","StudioFeaturesResult","SubscriptionIdentity","SystemReaderStorageLike","TelemetrySink",...e?["VectorBackfillProgress"]:[],...r?["WorkflowsResult"]:[],...e?["WriteHook"]:[]];export{K as a,V as b,G as c,re as d,J as e,oe as f,se as g,z as h,ne as i,ae as j,le as k,ie as l,ce as m,ue as n,M as o,de as p,Q as q,y as r,H as s,Z as t,Y as u,X as v,ee as w,te as x};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as y}from"@lunora/errors";import{v as A}from"./parse-validator-
|
|
1
|
+
import{LunoraError as y}from"@lunora/errors";import{v as A}from"./parse-validator-BisfC8bR.mjs";import{R as I}from"./reserved-words-CW1QFbTd.mjs";import{acceptsAbsentIr as R}from"./LUNORA_ERROR_CODES-CjACC-MQ.mjs";import{n as E}from"./dispatch-namespace-DwTjD7BU.mjs";const k=/^(?:"(?:[^"\\]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"|'[^'\\]*'|-?\d+(?:\.\d+)?|true|false|null)$/u,O=e=>Object.keys(e).filter(n=>A(e[n])),B=e=>O(e.args).length>0,F=`// GENERATED by @lunora/codegen — do not edit.
|
|
2
2
|
// Run \`lunora codegen\` to regenerate.
|
|
3
3
|
|
|
4
4
|
`,G=(e=!1)=>e?{client:"lunorash/client",do:"lunorash/do",flags:"lunorash/flags",server:"lunorash/server",serverDataModel:"lunorash/server/data-model",serverDrizzle:"lunorash/server/drizzle",serverTypes:"lunorash/server/types",values:"lunorash/values"}:{client:"@lunora/client",do:"@lunora/do",flags:"@lunora/flags",server:"@lunora/server",serverDataModel:"@lunora/server/data-model",serverDrizzle:"@lunora/server/drizzle",serverTypes:"@lunora/server/types",values:"@lunora/values"},b=/^[A-Za-z_$][\w$]*$/u,U=/^[\w./-]+$/u,w=(e,n)=>{if(!b.test(e)||I.has(e))throw new y("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},V=(e,n)=>{if(!b.test(e))throw new y("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},H=e=>e.charAt(0).toUpperCase()+e.slice(1),g=e=>b.test(e)?e:JSON.stringify(e),j=e=>e==="__proto__"?`[${JSON.stringify(e)}]`:g(e),D=e=>{const n=new Map;for(const r of e){const t=n.get(r.filePath)??[];t.push(r),n.set(r.filePath,t)}return[...n.entries()].toSorted(([r],[t])=>r.localeCompare(t))},Y=(e,n,r)=>{const[t,l]=r==="type"?[g,";"]:[j,","],d={children:new Map};for(const[o,h]of D(e)){let a=d;for(const m of E(o)){let c=a.children.get(m);c===void 0&&(c={children:new Map},a.children.set(m,c)),a=c}a.file={entries:h,path:o}}const u=o=>o.file?.path??u(o.children.values().next().value),p=(o,h)=>{const a=" ".repeat(h),{entries:m=[],path:c=""}=o.file??{},$=m.find(s=>o.children.has(s.exportName));if($!==void 0){const s=u(o.children.get($.exportName));throw new y("NAMESPACE_COLLISION",`Namespace collision: the export "${$.exportName}" of "${c}" and "${s}" both resolve to api.${[...E(c),$.exportName].join(".")}. Rename the export or the folder.`)}const S=m.toSorted((s,f)=>s.exportName.localeCompare(f.exportName)).map(s=>`${a}${n(s)}`),_=[...o.children.entries()].toSorted(([s],[f])=>s.localeCompare(f)).map(([s,f])=>`${a}${t(s)}: {
|
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.383",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -50,15 +50,15 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
54
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
53
|
+
"@lunora/advisor": "1.0.0-alpha.279",
|
|
54
|
+
"@lunora/agent": "1.0.0-alpha.271",
|
|
55
55
|
"@lunora/container": "1.0.0-alpha.103",
|
|
56
56
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
57
57
|
"@lunora/platform": "1.0.0-alpha.77",
|
|
58
58
|
"@lunora/queue": "1.0.0-alpha.137",
|
|
59
59
|
"@lunora/scheduler": "1.0.0-alpha.162",
|
|
60
60
|
"@lunora/values": "1.0.0-alpha.89",
|
|
61
|
-
"@lunora/workflow": "1.0.0-alpha.
|
|
61
|
+
"@lunora/workflow": "1.0.0-alpha.105",
|
|
62
62
|
"@visulima/fs": "7.0.0",
|
|
63
63
|
"jiti": "^2.7.0",
|
|
64
64
|
"quicktype-core": "^26.0.0",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const k=(e,t=2166136261)=>{let i=t;for(let r=0;r<e.length;r+=1)i^=e.charCodeAt(r),i=Math.imul(i,16777619);return(i>>>0).toString(16).padStart(8,"0")},q=e=>`${k(e,2166136261)}${k(e,16777619)}`,X=1;function A(e){const t={},i=Object.keys(e);i.sort();for(const r of i)t[r]=e[r];return t}const C=e=>`${JSON.stringify(e,void 0,2)}
|
|
2
|
-
`,Z=e=>q(C(e)),u=e=>typeof e=="object"&&e!==null,I=e=>u(e)&&u(e.fields)&&u(e.indexes)&&u(e.relations)&&typeof e.shardMode=="string",N=e=>{if(e===void 0||e.trim()==="")return{status:"absent"};let t;try{t=JSON.parse(e)}catch(r){return{error:`baseline is not valid JSON: ${r instanceof Error?r.message:String(r)}`,status:"invalid"}}if(!u(t)||t.version!==1||!u(t.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(1)})`,status:"invalid"};for(const[r,o]of Object.entries(t.tables))if(!I(o))return{error:`baseline table "${r}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof t.jurisdiction=="string"?t.jurisdiction:void 0,migrationIds:Array.isArray(t.migrationIds)?t.migrationIds:[],tables:t.tables,version:1},status:"ok"}},R=(e,t)=>e.unique===t.unique&&e.fields.length===t.fields.length&&e.fields.every((i,r)=>i===t.fields[r]),S=e=>e.unique!==void 0,m=({nullable:e,optional:t,refined:i,unique:r,...o})=>JSON.stringify(A(o)),O=e=>({form:JSON.stringify([m(e),e.optional===!0,e.nullable===!0]),refined:e.refined===!0}),w=e=>e.kind==="union"&&e.members?e.members.map(t=>O(t)):[O({...e,nullable:!1,optional:!1})],V=(e,t)=>{if(t.kind!=="union")return!1;const i=w(t);return w(e).every(r=>i.some(o=>o.form===r.form&&(r.refined||!o.refined)))},c=e=>{switch(e.kind){case"array":return`array(${e.of?c(e.of):"?"})`;case"from":return e.output===void 0?"from":`from(${e.output})`;case"id":return`id(${e.ref??"?"})`;case"literal":return`literal(${e.literal??"?"})`;case"object":return`object({ ${Object.keys(e.fields??{}).join(", ")} })`;case"record":return`record(${e.key?c(e.key):"?"}, ${e.of?c(e.of):"?"})`;case"union":return(e.members??[]).map(t=>c(t)).join(" | ");default:return e.kind}},p=(e,t,i)=>({remediation:"backfill",scope:"table",severity:"breaking",summary:i,table:e,type:t}),h=(e,t,i)=>({remediation:"none",scope:"table",severity:"safe",summary:i,table:e,type:t}),M=(e,t)=>{const i=JSON.stringify(e),r=JSON.stringify(t);return i===r?0:i<r?-1:1},f=e=>({...e,...e.kind==="from"?{output:void 0}:{},...e.fields?{fields:Object.fromEntries(Object.entries(e.fields).map(([t,i])=>[t,f(i)]))}:{},...e.key?{key:f(e.key)}:{},...e.of?{of:f(e.of)}:{},...e.members?{members:e.members.map(t=>f(t)).toSorted(M)}:{}}),x=e=>e.kind==="union"?e.members??[]:[e],L=(e,t)=>{const i=[...e],r=[...t],o=new Set,n=new Set,s=(d,a)=>{for(const[b,$]of i.entries()){if(n.has(b))continue;const y=r.findIndex((_,E)=>!o.has(E)&&d($,_));y!==-1&&(o.add(y),n.add(b),a&&([i[b],r[y]]=v($,r[y])))}};return s((d,a)=>JSON.stringify(d)===JSON.stringify(a),!1),s((d,a)=>m(f(d))===m(f(a)),!0),[i,r]},v=(e,t)=>{if(e.kind==="union"||t.kind==="union"){const[o,n]=L(x(e),x(t)),s=(d,a)=>d.kind==="union"?{...d,members:a.toSorted(M)}:a[0];return[s(e,o),s(t,n)]}if(e.kind!==t.kind)return[e,t];if(e.kind==="from")return e.output===void 0||t.output===void 0?[{...e,output:void 0},{...t,output:void 0}]:[e,t];const i={...e.fields?{fields:{...e.fields}}:{}},r={...t.fields?{fields:{...t.fields}}:{}};for(const o of["key","of"])e[o]&&t[o]&&([i[o],r[o]]=v(e[o],t[o]));for(const o of Object.keys(e.fields??{})){const n=e.fields?.[o],s=t.fields?.[o];n&&s&&i.fields&&r.fields&&([i.fields[o],r.fields[o]]=v(n,s))}return[{...e,...i},{...t,...r}]},D=(e,t,i,r,o)=>{const[n,s]=v(i,r);if(n.kind===s.kind&&(!o||m(n)===m(s)))return;if(o&&V(n,s))return h(e,"widenedFieldShape",`field ${e}.${t} widened: ${c(n)} → ${c(s)} — every stored value stays valid`);if(n.kind!==s.kind)return p(e,"changedFieldKind",`field ${e}.${t} changed type: ${n.kind} → ${s.kind} — add a data migration to convert existing values`);const d=Object.values(s.fields??{});return o&&n.kind==="object"&&Object.keys(n.fields??{}).length===0&&d.length>0&&d.every(a=>a.optional)?h(e,"widenedFieldShape",`field ${e}.${t} now records its optional object shape — stored values stay valid`):p(e,"changedFieldShape",`field ${e}.${t} changed shape: ${c(n)} → ${c(s)} — stored values were written against the old shape; add a data migration to convert them`)},H=(e,t,i,r)=>{const o=[];return i.unique!==r.unique&&o.push(r.unique===!0?p(e,"addedFieldConstraint",`field ${e}.${t} became unique — existing duplicates would violate it; add a data migration to de-duplicate first`):h(e,"relaxedFieldConstraint",`field ${e}.${t} is no longer unique`)),i.nullable!==r.nullable&&o.push(r.nullable===!0?h(e,"relaxedFieldConstraint",`field ${e}.${t} became nullable`):p(e,"addedFieldConstraint",`field ${e}.${t} is no longer nullable — rows holding NULL would be invalid; add a data migration to backfill them`)),i.refined!==r.refined&&o.push(r.refined===!0?p(e,"addedFieldConstraint",`field ${e}.${t} gained a validation refinement — stored values were never checked against it; add a data migration if any could fail`):h(e,"relaxedFieldConstraint",`field ${e}.${t} dropped its validation refinement`)),o},J=(e,t,i,r)=>{const o=[],n=S(i)&&S(r),s=D(e,t,i,r,n);return s&&o.push(s),n&&o.push(...H(e,t,i,r)),i.optional&&!r.optional?o.push({remediation:"backfill",severity:"breaking",summary:`field ${e}.${t} became required — rows missing it would be invalid; add a data migration to backfill it`,table:e,scope:"table",type:"fieldOptionalToRequired"}):!i.optional&&r.optional&&o.push({remediation:"none",scope:"table",severity:"safe",summary:`field ${e}.${t} became optional`,table:e,type:"fieldRequiredToOptional"}),o},P=(e,t,i)=>i.optional?{remediation:"none",scope:"table",severity:"safe",summary:`added optional field ${e}.${t}`,table:e,type:"addedOptionalField"}:{remediation:"backfill",severity:"breaking",summary:`added required field ${e}.${t} — existing rows have no value; add a data migration to backfill it`,table:e,scope:"table",type:"addedRequiredField"},B=(e,t,i,r)=>{for(const[o,n]of Object.entries(i.fields)){const s=t.fields[o];s===void 0?r.push(P(e,o,n)):r.push(...J(e,o,s,n))}for(const o of Object.keys(t.fields))i.fields[o]===void 0&&r.push({remediation:"backfill",severity:"breaking",summary:`removed field ${e}.${o} — add a data migration if stored data must be cleaned up`,table:e,scope:"table",type:"removedField"})},G=(e,t,i,r)=>{for(const[o,n]of Object.entries(i.indexes)){const s=t.indexes[o];if(s===void 0){r.push(n.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`added unique index ${o} on ${e} — existing duplicates would violate it; add a data migration to de-duplicate first`,table:e,type:"addedIndex"}:{remediation:"none",scope:"table",severity:"safe",summary:`added index ${o} on ${e}`,table:e,type:"addedIndex"});continue}R(s,n)||r.push({remediation:"code",severity:"breaking",summary:`index ${o} on ${e} changed shape — a query may have relied on the old index`,table:e,scope:"table",type:"changedIndex"})}for(const o of Object.keys(t.indexes))i.indexes[o]===void 0&&r.push({remediation:"code",severity:"breaking",summary:`removed index ${o} on ${e} — a query that used \`.withIndex("${o}")\` would break`,table:e,scope:"table",type:"removedIndex"})},U=(e,t,i,r)=>{for(const o of Object.keys(i.relations))t.relations[o]===void 0&&r.push({remediation:"none",scope:"schema",severity:"safe",summary:`added relation ${e}.${o}`,table:e,type:"addedRelation"});for(const o of Object.keys(t.relations))i.relations[o]===void 0&&r.push({remediation:"code",scope:"schema",severity:"breaking",summary:`removed relation ${e}.${o}`,table:e,type:"removedRelation"})},F="shardBy:_unknown_",g="global",W=(e,t)=>e===g&&t.startsWith(`${g}:`)||t===g&&e.startsWith(`${g}:`),K=(e,t,i)=>{if(t===i)return i!==F?void 0:{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${e} declares a non-literal .shardBy(...) key, so codegen cannot read which column partitions it — every such key records as "${F}" and two DIFFERENT keys would compare equal. Pass the shard key as a string literal; until then this is reported on every run, because the alternative is a silent pass on a re-home that strands every row (export/import is the only way back).`,table:e,type:"changedShardMode"};if(!W(t,i))return{remediation:"rehome",severity:"breaking",summary:`table ${e} changed shard mode: ${t} → ${i} — its physical storage moves, and existing rows do NOT follow the schema; re-home them with an export/import round trip (https://lunora.sh/docs/concepts/sharding#migrating-a-populated-table)`,table:e,scope:"table",type:"changedShardMode"}},j=e=>e.memory!==void 0,T=e=>e.after??0,l=e=>e.after===void 0?`.ttl("${e.field}")`:`.ttl("${e.field}", { after: ${String(e.after)} })`,z=(e,t,i)=>{if(t===void 0&&i===void 0)return;const r=d=>({remediation:"backfill",scope:"table",severity:"breaking",summary:d,table:e,type:"changedTtlPolicy"}),o=d=>({remediation:"none",scope:"table",severity:"safe",summary:d,table:e,type:"changedTtlPolicy"});if(i===void 0)return o(`table ${e} dropped its TTL policy — its rows are no longer swept`);if(t===void 0)return r(`table ${e} gained a TTL policy ${l(i)} — every row already past the cutoff is deleted on the next alarm sweep; add a data migration to refresh or clear "${i.field}" on the rows written before it`);if(t.field!==i.field)return r(`table ${e} moved its TTL to a different column: ${l(t)} → ${l(i)} — rows are now expired by a column they were never written against; add a data migration to populate "${i.field}"`);const n=T(t),s=T(i);return s<n?r(`table ${e} shortened its TTL: ${l(t)} → ${l(i)} — rows that were not expired under the old offset are deleted on the next alarm sweep; add a data migration to refresh "${i.field}" on the rows that must survive`):s>n?o(`table ${e} lengthened its TTL: ${l(t)} → ${l(i)}`):void 0},Q=(e,t,i)=>{const r=[];return t.memory!==i.memory&&r.push(i.memory===!0?{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${e} became a .memory() table — every row is deleted in every shard on the next Durable Object cold start, and no data migration survives that; export the rows first if they must be kept, or revert`,table:e,type:"changedMemoryMode"}:{remediation:"none",scope:"table",severity:"safe",summary:`table ${e} is no longer a .memory() table — its rows now survive a cold start`,table:e,type:"changedMemoryMode"}),t.commitOrdered!==i.commitOrdered&&r.push(i.commitOrdered===!0?{remediation:"backfill",scope:"table",severity:"breaking",summary:`table ${e} became .commitOrdered() — rows written before it carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed never offers them; add a data migration over the table to stamp them (the rewrite allocates a sequence)`,table:e,type:"changedCommitOrdering"}:{remediation:"code",scope:"table",severity:"breaking",summary:`table ${e} is no longer .commitOrdered() — new rows carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed stops advancing without erroring; update the consumers before deploying`,table:e,type:"changedCommitOrdering"}),r},Y=(e,t,i,r)=>{const o=K(e,t.shardMode,i.shardMode);if(o&&r.push(o),j(t)&&j(i)){r.push(...Q(e,t,i));const n=z(e,t.ttl,i.ttl);n&&r.push(n)}B(e,t,i,r),G(e,t,i,r),U(e,t,i,r)},ee=(e,t)=>{const i=[],r=e?.tables??{};for(const[o,n]of Object.entries(t.tables)){const s=r[o];if(s===void 0){i.push({remediation:"none",scope:"table",severity:"safe",summary:`added table ${o}`,table:o,type:"addedTable"});continue}Y(o,s,n,i)}for(const o of Object.keys(r))t.tables[o]===void 0&&i.push({remediation:"rehome",scope:"table",severity:"breaking",summary:`removed table ${o} — its rows stay in each shard's SQLite, unreachable through the schema; export the shard first if the data must be kept`,table:o,type:"removedTable"});if(e!==void 0&&e.jurisdiction!==t.jurisdiction){const o=e.jurisdiction??"(none)",n=t.jurisdiction??"(none)";i.push({remediation:"rehome",scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${o} to ${n} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:i}};export{X as SCHEMA_SNAPSHOT_VERSION,c as describeShape,J as diffExistingField,ee as diffSchemaSnapshots,Z as hashSchemaSnapshot,I as isValidTableSnapshot,N as parseSnapshotJson,C as serializeSchemaSnapshot,A as sortKeys};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import{LunoraError as A}from"@lunora/errors";import{SCHEMA_SNAPSHOT_VERSION as E,sortKeys as f,diffSchemaSnapshots as I,parseSnapshotJson as L}from"./SCHEMA_SNAPSHOT_VERSION-SplX7j_9.mjs";import{isHyperdriveGlobalTable as O}from"./isD1GlobalTable-udvHAAzD.mjs";const _=e=>{const t=e.shardMode;return t==="global"?`global:${O(e)?"hyperdrive":"d1"}`:t==="root"?t:`shardBy:${t.field}`},v=(e,t)=>{const s=JSON.stringify(e),i=JSON.stringify(t);return s===i?0:s<i?-1:1},l=e=>{const t=e.kind==="optional",s=t?e.inner:void 0,i=s??e,r={kind:t?s?.kind??"unknown":e.kind,nullable:i.column?.notNull===!1||e.column?.notNull===!1,optional:t,unique:i.column?.unique===!0||e.column?.unique===!0,...D[i.kind]?.(i)};return(i.hasRefinement===!0||e.hasRefinement===!0)&&(r.refined=!0),r},N=e=>{const t={};for(const[s,i]of Object.entries(e))t[s]=l(i);return f(t)},j=/import\(\s*["'`](?:[A-Za-z]:)?[\\/]/u,D={array:e=>e.inner?{of:l(e.inner)}:{},from:e=>e.tsType===void 0||j.test(e.tsType)?{}:{output:e.tsType},id:e=>e.tableName===void 0?{}:{ref:e.tableName},literal:e=>e.literalValue===void 0?{}:{literal:e.literalValue},object:e=>e.shape?{fields:N(e.shape)}:{},record:e=>({...e.keyType?{key:l(e.keyType)}:{},...e.valueType?{of:l(e.valueType)}:{}}),union:e=>e.members?{members:e.members.map(t=>l(t)).toSorted(v)}:{}},M=e=>{const t={};for(const[n,a]of Object.entries(e.shape))t[n]=l(a);const s={};for(const n of e.indexes)s[n.name]={fields:[...n.fields],unique:n.unique??!1};const i={};for(const n of e.relations)i[n.name]=n.through===void 0?{field:n.field,kind:n.kind,table:n.table}:{kind:n.kind,table:n.table,through:{...n.through}};const r={commitOrdered:e.commitOrdered===!0,fields:f(t),indexes:f(s),memory:e.memory===!0,relations:f(i),shardMode:_(e)};return e.ttl&&(r.ttl=e.ttl.after===void 0?{field:e.ttl.field}:{after:e.ttl.after,field:e.ttl.field}),r},z=(e,t)=>{const s={};for(const r of e.tables)s[r.name]=M(r);const i=[...t].sort();return{jurisdiction:e.jurisdiction,migrationIds:i,tables:f(s),version:E}};class R extends A{constructor(t){super("SCHEMA_SNAPSHOT_PARSE",t,{name:"SchemaSnapshotParseError"})}}const J=e=>{const t=L(e);if(t.status==="invalid")throw new R(t.error);return t.status==="ok"?t.snapshot:void 0},B={build:{allowDrift:!0,updateBaseline:!1},deploy:{allowDrift:!0,updateBaseline:!0},prepare:{allowDrift:!0,updateBaseline:!0},verify:{allowDrift:!0,updateBaseline:!1}},S=" • For backward-compatible changes (e.g. adding an optional field): pass `--allow-schema-drift` to skip the block.",k=" • To accept the new shape without a migration (you know data is compatible): pass `--update-schema-baseline`.",P=e=>{const t=e===void 0?void 0:B[e];if(e===void 0||t===void 0)return`${S}
|
|
2
|
-
${k}
|
|
3
|
-
`;const s=t.updateBaseline?k:` • To accept the new shape without a migration, run \`lunora prepare --update-schema-baseline\` — \`lunora ${e}\` does not take that flag.`;return`${S}
|
|
4
|
-
${s}
|
|
5
|
-
`},p=e=>e.map(t=>` - ${t.summary}`).join(`
|
|
6
|
-
`),T=e=>e.remediation==="backfill"&&e.table!==void 0,x=/^[A-Za-z_]\w*$/u,F=e=>` lunora migrate create backfill_${e} --table ${e}`,C=(e,t,s)=>{const i=[...new Set(e.filter(n=>T(n)).map(n=>n.table))],r=[];if(i.length>0){r.push(" • Add a `defineMigration({ id, table, up })` in lunora/ for each affected table, then re-run this command — the baseline is re-blessed on a successful deploy, not by `lunora migrate` itself.\n");const n=i.filter(a=>x.test(a));n.length>0&&r.push(`
|
|
7
|
-
Scaffold the missing migration(s) — the generated \`up\` is an identity placeholder you must fill in:
|
|
8
|
-
${n.map(a=>F(a)).join(`
|
|
9
|
-
`)}
|
|
10
|
-
|
|
11
|
-
`)}return t.length>0&&r.push(` • Migration(s) ${t.join(", ")} declare a non-literal \`table\`, so codegen cannot tell which table they visit and they cover nothing. Use a string literal.
|
|
12
|
-
`),r.push(P(s)),[`${s??"deploy"} blocked: ${String(e.length)} unresolved breaking schema change(s) since the last blessed schema baseline:`,p(e),"",`To fix:
|
|
13
|
-
${r.join("")}Docs: https://lunora.dev/docs/migrations`].join(`
|
|
14
|
-
`)},V=e=>{const{allowDrift:t=!1,baseline:s,command:i,current:r,migrations:n}=e,a=I(s,r),u=a.changes.filter(o=>o.severity==="breaking"),b=r.migrationIds.filter(o=>!(s?.migrationIds??[]).includes(o)),m=n.filter(o=>b.includes(o.id)),c=(o,h)=>({blocked:o,changes:a.changes,newMigrationIds:b,reason:h}),w=new Set(m.filter(o=>o.table!=="").map(o=>o.table)),$=m.filter(o=>o.table==="").map(o=>o.id);if(a.changes.length===0||s===void 0)return c(!1,"");if(u.length===0)return c(!1,`schema drift detected (all additive/safe):
|
|
15
|
-
${p(a.changes)}`);const g=u.filter(o=>!T(o)||!w.has(o.table));if(g.length===0){const o=new Set(u.map(d=>d.table)),h=m.filter(d=>o.has(d.table)).map(d=>d.id);return c(!1,`breaking schema drift detected, covered by ${String(h.length)} new migration(s) (${h.join(", ")}):
|
|
16
|
-
${p(u)}`)}const y=C(g,$,i);return t?c(!1,`${y}
|
|
17
|
-
|
|
18
|
-
(overridden by --allow-schema-drift)`):c(!0,y)};export{R as SchemaSnapshotParseError,z as buildSchemaSnapshot,V as evaluateSchemaDrift,J as parseSchemaSnapshot};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./context-property-calls-DKMO9ShK.mjs";const t=(r,e)=>o(r,e,"sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./isTestPath-JdN4KXhV.mjs";import"./attribution-DUbGYT4N.mjs";import"./database-calls-hLzaOquW.mjs";import"./classify-procedure-call-DtqiTjPg.mjs";import{d as a}from"./index-BjDVAPNW.mjs";export{a as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{SyntaxKind as f,Node as s}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{a as u}from"./module-specifiers-BctA0m_p.mjs";import{listLunoraSourceFiles as m,lunoraRelativePath as p,findObjectProperty as h}from"./isTestPath-JdN4KXhV.mjs";import{b as I,a as b}from"./attribution-DUbGYT4N.mjs";const P=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(s.isImportSpecifier(t))return u(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},d=(r,i)=>{const t=h(r,i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},v=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==f.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!P(e))return;const o=t.getArguments()[0];if(!o||!s.isObjectLiteralExpression(o))return;const n=d(o,"id"),a=b(r,"member");if(a!==void 0){if(n===void 0||n.trim()==="")throw g(o,`Migration "${a}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:a,filePath:i,id:n,table:d(o,"table")??""}}},M=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},E=(r,i)=>{const t=m(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),a=p(i,o);for(const l of I(n)){const c=v(l,a);c&&e.push(c)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),M(e),e};export{E as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as r}from"./context-property-calls-DKMO9ShK.mjs";const t=(s,o)=>r(s,o,"r2sql");export{t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./SCHEMA_SNAPSHOT_VERSION-SplX7j_9.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-DmDBaK79.mjs";import"./shard-runtime-BtEGoPTf.mjs";import"./shared-BErjtci3.mjs";import"./platform-8oj7iXQy.mjs";import"./schema-BgM8A3XV.mjs";export{d as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as y}from"@lunora/errors";import{Node as i,VariableDeclarationKind as h}from"ts-morph";import{diagnosticAt as v}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as E}from"./property-name-7cBlgK_O.mjs";let f;const U=e=>{f=e},k=/^[A-Za-z_$][\w$]*$/u,m=new Set(["$defaultFn","$onUpdateFn","$type","default","defaultNow","nullable","serverDefault","unique"]),A=(e,t)=>{const r={notNull:!0,...e.column};switch(t){case"$defaultFn":case"default":case"defaultNow":case"serverDefault":{r.hasDefault=!0;break}case"$onUpdateFn":{r.hasOnUpdate=!0;break}case"$type":break;case"nullable":{r.notNull=!1;break}case"unique":{r.unique=!0;break}}return{...e,column:r}},N=new Set(["any","bigint","boolean","bytes","date","geoPoint","null","number","string","timestamp"]),p=new Set(["check","email","int","length","max","min","pattern","positive","url"]),T=new Set(["meta"]),I=new Set(["strip"]),l=new Set,g=new Set,b=e=>{const t=e.getSymbol();let r=(t?.getAliasedSymbol()??t)?.getValueDeclaration();if(r!==void 0&&i.isShorthandPropertyAssignment(r)){const n=r.getValueSymbol();r=(n?.getAliasedSymbol()??n)?.getValueDeclaration()}if(!(r===void 0||!i.isVariableDeclaration(r)))return r.getInitializer()},L=e=>{const t=e.getParent();return!i.isVariableDeclaration(t)||t.getVariableStatement()?.getDeclarationKind()===h.Const},d=e=>{if(i.isParenthesizedExpression(e)||i.isAsExpression(e)||i.isSatisfiesExpression(e))return d(e.getExpression());if(i.isObjectLiteralExpression(e))return e;if(i.isPropertyAccessExpression(e)){const r=e.getSymbol()?.getValueDeclaration(),n=r!==void 0&&i.isPropertyAssignment(r)?r.getInitializer():void 0;return n===void 0?void 0:d(n)}if(!i.isIdentifier(e)||l.has(e))return;const t=b(e);if(!(t===void 0||!L(t))){l.add(e);try{return d(t)}finally{l.delete(e)}}},w="v",D=e=>{if(i.isIdentifier(e))return!0;let t=e;for(;i.isCallExpression(t);){const r=t.getExpression();if(!i.isPropertyAccessExpression(r))return!1;t=r.getExpression()}return i.isIdentifier(t)&&t.getText()===w},u=e=>{if(i.isIdentifier(e)&&!l.has(e)){const t=b(e);if(t!==void 0&&D(t)){l.add(e);try{return u(t)}finally{l.delete(e)}}}return i.isCallExpression(e)?F(e):{kind:"any",sourceText:e.getText()}},S=e=>{const t=d(e);if(t===void 0||g.has(t))return{};g.add(t);try{return V(t)}finally{g.delete(t)}},R=e=>{throw v(e,`computed property name ${e.getText()} must be a string literal — codegen resolves object keys statically.`)},V=e=>{const t={};for(const r of e.getProperties()){if(i.isSpreadAssignment(r)){Object.assign(t,S(r.getExpression()));continue}const n=i.isShorthandPropertyAssignment(r);if(!n&&!i.isPropertyAssignment(r))continue;const a=n?r.getNameNode():r.getInitializer();if(!a)continue;const s=r.getNameNode(),o=E(s)??R(s);if(!k.test(o))throw new y("INTERNAL",`@lunora/codegen: field name is not a valid JS identifier: ${JSON.stringify(o)}`);t[o]=u(a)}return t},c=(e,t)=>e&&i.isExpression(e)?u(e):t,x=e=>e.sensitive===!0?!0:[e.inner,e.keyType,e.valueType,...e.members??[],...Object.values(e.shape??{})].some(r=>r!==void 0&&x(r)),O=e=>e===void 0?"undefined":i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e)?JSON.stringify(e.getLiteralValue()):e.getText(),M=e=>{const t=e&&f?f(e):void 0;return t===void 0?{kind:"from"}:{kind:"from",tsType:t}},P=(e,t,r)=>{if(N.has(e))return{kind:e};const[n,a]=t;switch(e){case"array":return{inner:c(n,{kind:"any"}),kind:"array"};case"from":return M(n);case"id":{if(!n||!i.isStringLiteral(n))throw v(n??r,`v.id(...) target table must be a string literal — codegen resolves foreign-key targets statically. Got ${n?n.getText():"no argument"}.`);return{kind:"id",tableName:n.getLiteralText()}}case"literal":return{kind:"literal",literalValue:O(n)};case"object":return{kind:"object",shape:n&&i.isExpression(n)?S(n):{}};case"optional":return{inner:c(n,{kind:"any"}),kind:"optional"};case"record":return{keyType:c(n,{kind:"string"}),kind:"record",valueType:c(a,{kind:"any"})};case"sensitive":return{...c(n,{kind:"any"}),sensitive:!0};case"storage":return n&&i.isStringLiteral(n)?{bucket:n.getLiteralText(),kind:"storage"}:{kind:"storage"};case"union":return{kind:"union",members:t.filter(s=>i.isExpression(s)).map(s=>u(s))};default:throw new y("INTERNAL",`Unsupported validator kind: ${e}`)}},$=e=>{const[t]=e;if(e.length!==1||t===void 0||!i.isNumericLiteral(t))return;const r=Number(t.getText().replaceAll("_",""));return Number.isSafeInteger(r)&&r>=0?r:void 0},F=e=>{const t=e.getExpression();if(!i.isPropertyAccessExpression(t))return{kind:"any",sourceText:e.getText()};const r=t.getName(),n=e.getArguments();if(m.has(r)||p.has(r)||T.has(r)||I.has(r)){const a=t.getExpression(),s=i.isExpression(a)?u(a):{kind:"any"};if(m.has(r))return A(s,r);if(!p.has(r))return s;const o=r==="max"&&s.kind==="string"?$(n):void 0;return o!==void 0?{...s,hasRefinement:!0,stringMaxLength:Math.min(s.stringMaxLength??o,o)}:{...s,hasRefinement:!0,unmodelledRefinement:!0}}return P(r,n,e)};export{u as a,V as p,d as r,U as s,x as v};
|