@lunora/codegen 1.0.0-alpha.387 → 1.0.0-alpha.389
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 +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{CAPABILITY_PROBES-DKYJ2K4t.mjs → CAPABILITY_PROBES-BuNEmlCO.mjs} +3 -3
- package/dist/packem_shared/{DEFAULT_TARGET-3OLdJhTj.mjs → DEFAULT_TARGET-hkUrVddn.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CtfWbIuc.mjs +31 -0
- package/dist/packem_shared/{capabilitiesUsedBy-CN8HACEL.mjs → capabilitiesUsedBy-CkMimFS2.mjs} +1 -1
- package/dist/packem_shared/{emitAgents-iTKWSKan.mjs → emitAgents-Dg5j1R-4.mjs} +1 -1
- package/dist/packem_shared/{emitApp-L7PnfjJK.mjs → emitApp-Blxf5Bvs.mjs} +38 -29
- package/dist/packem_shared/{emitCrons-BvqxeNRr.mjs → emitCrons-BQjDleCe.mjs} +37 -22
- package/dist/packem_shared/{emitFunctions-C4PzKb4H.mjs → emitFunctions-D6n4ENZO.mjs} +44 -33
- package/dist/packem_shared/emitServer-Bo1CO-pn.mjs +1 -0
- package/dist/packem_shared/{emitShard-CyFV41Mb.mjs → emitShard-g-4f3Zle.mjs} +1 -1
- package/dist/packem_shared/{server-qWq5nN-R.mjs → server-59fi39OH.mjs} +1 -1
- package/dist/packem_shared/{shard-t1Jkywmh.mjs → shard-D_mnxT3r.mjs} +2 -2
- package/dist/packem_shared/{shard-runtime-C1P_uVye.mjs → shard-runtime-CHda0G1i.mjs} +1 -1
- package/package.json +9 -9
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CA_Jy0Mi.mjs +0 -31
- package/dist/packem_shared/emitServer-BgI9yXW1.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as L}from"@lunora/errors";import{L as pe,i as ge,G as U,d as J,I as F,s as fe,b as C,r as ye,c as $e}from"./shared-DhqnD5R3.mjs";import{v as we}from"./parse-validator-BisfC8bR.mjs";import{renderAgentFunctionRegistry as
|
|
1
|
+
import{LunoraError as L}from"@lunora/errors";import{L as pe,i as ge,G as U,d as J,I as F,s as fe,b as C,r as ye,c as $e}from"./shared-DhqnD5R3.mjs";import{v as we}from"./parse-validator-BisfC8bR.mjs";import{renderAgentFunctionRegistry as be,renderSandboxFunctionRegistry as Re}from"./emitApi-DWJW8Vu9.mjs";import{b as ke,a as Ne,r as j,c as ve}from"./qualifiers-ClaCHu0X.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const Oe=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),B=t=>t.column!==void 0,Se=(t,r)=>{switch(t){case"bigint":return`if (typeof ${r} !== "bigint") return DEFER;
|
|
2
2
|
`;case"boolean":return`if (typeof ${r} !== "boolean") return DEFER;
|
|
3
3
|
`;case"date":case"number":case"timestamp":return`if (typeof ${r} !== "number" || !Number.isFinite(${r})) return DEFER;
|
|
4
4
|
`;case"null":return`if (${r} !== null) return DEFER;
|
|
@@ -17,18 +17,18 @@ if (${n} !== undefined) {
|
|
|
17
17
|
${c.pre}${d} = ${c.out};
|
|
18
18
|
${l} = true;
|
|
19
19
|
}
|
|
20
|
-
`;return{entry:`...(${l} ? { ${s}: ${d} } : {})`,pre:f}}const i=E(r,n,o);if(i)return{entry:`${s}: ${i.out}`,pre:i.pre}},Te=new Set(Object.getOwnPropertyNames(Object.prototype)),
|
|
21
|
-
`,u=d}const l=Le(i,a,u,n);if(!l)return;o+=l.pre,s.push(l.entry)}return{entries:s.join(", "),pre:o}},
|
|
22
|
-
`},Fe=(t,r,n)=>{const o=t.shape??{},s=
|
|
23
|
-
${
|
|
24
|
-
`;return{out:a,pre:c}},H=t=>{let r=0;const o=
|
|
20
|
+
`;return{entry:`...(${l} ? { ${s}: ${d} } : {})`,pre:f}}const i=E(r,n,o);if(i)return{entry:`${s}: ${i.out}`,pre:i.pre}},Te=new Set(Object.getOwnPropertyNames(Object.prototype)),q=(t,r,n)=>{let o="";const s=[];for(const i of Object.keys(t)){const a=t[i];if(!a)return;const c=JSON.stringify(i);let u=`${r}[${c}]`;if(Te.has(i)){const d=`__f${String(n.next())}`;o+=`const ${d} = Object.hasOwn(${r}, ${c}) ? ${r}[${c}] : undefined;
|
|
21
|
+
`,u=d}const l=Le(i,a,u,n);if(!l)return;o+=l.pre,s.push(l.entry)}return{entries:s.join(", "),pre:o}},z=t=>{const r=`Object.getPrototypeOf(${t})`;return`if (${r} !== Object.prototype && ${r} !== null) return DEFER;
|
|
22
|
+
`},Fe=(t,r,n)=>{const o=t.shape??{},s=q(o,r,n);if(!s)return;const i=n.next(),a=`__obj${String(i)}`,c=`if (typeof ${r} !== "object" || ${r} === null || Array.isArray(${r})) return DEFER;
|
|
23
|
+
${z(r)}${s.pre}const ${a} = { ${s.entries} };
|
|
24
|
+
`;return{out:a,pre:c}},H=t=>{let r=0;const o=q(t,"source",{next:()=>(r+=1,r)});if(o)return`(source) => {
|
|
25
25
|
if (typeof source !== "object" || source === null || Array.isArray(source)) return DEFER;
|
|
26
|
-
${
|
|
27
|
-
}`},Ee=(t,r)=>`lunora_${g(t)}_${String(r)}`,D=t=>JSON.stringify(Object.entries(t).toSorted(([r],[n])=>r.localeCompare(n)).map(([r,n])=>{const o=n.kind==="optional",s=o?n.inner??{kind:"unknown"}:n,i=s.kind==="array"?s.inner?.kind:void 0,a=s.kind==="id"?s.tableName:void 0;return{kind:s.kind,name:r,optional:o,...we(n)?{sensitive:!0}:{},...a===void 0?{}:{table:a},...i===void 0||i==="unknown"?{}:{element:i}}})),
|
|
26
|
+
${z("source")}${o.pre}return { ${o.entries} };
|
|
27
|
+
}`},Ee=(t,r)=>`lunora_${g(t)}_${String(r)}`,D=t=>JSON.stringify(Object.entries(t).toSorted(([r],[n])=>r.localeCompare(n)).map(([r,n])=>{const o=n.kind==="optional",s=o?n.inner??{kind:"unknown"}:n,i=s.kind==="array"?s.inner?.kind:void 0,a=s.kind==="id"?s.tableName:void 0;return{kind:s.kind,name:r,optional:o,...we(n)?{sensitive:!0}:{},...a===void 0?{}:{table:a},...i===void 0||i==="unknown"?{}:{element:i}}})),_e=t=>t?"sensitive?: true; ":"",Me=t=>t?` /** Lazy-mode stub only: the manifest's argument descriptors, read before the module loads. */
|
|
28
28
|
argumentDescriptors?: FunctionManifestEntry["argumentDescriptors"];
|
|
29
29
|
/** Lazy-mode stub only: the manifest's cache and REST exposure. */
|
|
30
30
|
expose?: FunctionManifestEntry["expose"];
|
|
31
|
-
`:"",W=(t,r,n,o)=>{const s=new Map,i=a=>{s.has(a)||s.set(a,Ee(a,s.size))};for(const a of t)i(a.filePath);for(const a of r)i(a.filePath);for(const a of n)i(a.filePath);for(const a of o)i(a.filePath);return s},Q=(t,r,n,o)=>new Set([...t.filter(s=>s.typeDerivedArgs).map(s=>s.filePath),...r.map(s=>s.filePath),...n.map(s=>s.filePath),...o.map(s=>s.filePath)]),
|
|
31
|
+
`:"",W=(t,r,n,o)=>{const s=new Map,i=a=>{s.has(a)||s.set(a,Ee(a,s.size))};for(const a of t)i(a.filePath);for(const a of r)i(a.filePath);for(const a of n)i(a.filePath);for(const a of o)i(a.filePath);return s},Q=(t,r,n,o)=>new Set([...t.filter(s=>s.typeDerivedArgs).map(s=>s.filePath),...r.map(s=>s.filePath),...n.map(s=>s.filePath),...o.map(s=>s.filePath)]),_=t=>Array.isArray(t)?`Object.freeze([${t.map(r=>_(r)).join(", ")}])`:t!==null&&typeof t=="object"?`Object.freeze({ ${Object.entries(t).map(([n,o])=>`${JSON.stringify(n)}: ${_(o)}`).join(", ")} })`:typeof t=="number"&&(!Number.isFinite(t)||Object.is(t,-0))?Object.is(t,-0)?"-0":String(t):JSON.stringify(t),P=t=>`${t}[functionPath]`,Ie=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
|
|
32
32
|
const registered = await loadFunction(functionPath);
|
|
33
33
|
|
|
34
34
|
if (!registered) {
|
|
@@ -62,17 +62,17 @@ ${q("source")}${o.pre}return { ${o.entries} };
|
|
|
62
62
|
|
|
63
63
|
return (await registered.handler(context, args ?? {})) as R;
|
|
64
64
|
};`,Ce=(t,r,n=[],o=[],s=!1)=>{const i=W(t,r,n,o),a=Q(t,r,n,o),c=[...i.entries()].filter(([e])=>!s||a.has(e)?!0:t.some(p=>p.filePath===e&&p.channel?.kind==="room")).map(([e,p])=>{if(!F.test(e))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);return`import ${s&&!a.has(e)?"type ":""}* as ${p} from "../${e}.js";`}).join(`
|
|
65
|
-
`),u=t.map(e=>{if(!s||a.has(e.filePath))return` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`;const p=fe(e.args),w=JSON.stringify({argumentDescriptors:JSON.parse(D(e.args)),kind:e.kind,...p.length===0?{}:{sensitiveArgs:p},...e.channel?{channel:e.channel}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}},...e.socket===void 0?{}:{auth:e.socket.auth,socketPath:e.socket.path}}).slice(1,-1),k=e.meta===void 0?"":`, [Symbol.for("lunora.procedure.meta")]: ${
|
|
65
|
+
`),u=t.map(e=>{if(!s||a.has(e.filePath))return` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`;const p=fe(e.args),w=JSON.stringify({argumentDescriptors:JSON.parse(D(e.args)),kind:e.kind,...p.length===0?{}:{sensitiveArgs:p},...e.channel?{channel:e.channel}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}},...e.socket===void 0?{}:{auth:e.socket.auth,socketPath:e.socket.path}}).slice(1,-1),k=e.meta===void 0?"":`, [Symbol.for("lunora.procedure.meta")]: ${_(e.meta)}`;return` "${g(e.filePath)}:${e.exportName}": { args: {}, handler: unloadedFunctionHandler, ${w}${k} } satisfies RegisteredLunoraFunction & Pick<FunctionManifestEntry, "argumentDescriptors" | "channel" | "expose">,`}).join(`
|
|
66
66
|
`),l=r.map(e=>` ${JSON.stringify(e.id)}: ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredDataMigration,`).join(`
|
|
67
67
|
`),d=n.map(e=>` "${g(e.filePath)}:${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
68
68
|
`),f=o.map(e=>` "${e.exportName}": ${i.get(e.filePath)??""}.${e.exportName} as unknown as RegisteredShape,`).join(`
|
|
69
|
-
`),y=n.map(e=>`${g(e.filePath)}:${e.exportName}`),$=[...t.filter(e=>e.readsIp===!0).map(e=>`${g(e.filePath)}:${e.exportName}`),...o.filter(e=>e.readsIp===!0).map(e=>e.exportName)],
|
|
69
|
+
`),y=n.map(e=>`${g(e.filePath)}:${e.exportName}`),$=[...t.filter(e=>e.readsIp===!0).map(e=>`${g(e.filePath)}:${e.exportName}`),...o.filter(e=>e.readsIp===!0).map(e=>e.exportName)],R=[u,d].filter(e=>e.length>0).join(`
|
|
70
70
|
`),x=t.filter(e=>!s||a.has(e.filePath)).map(e=>{if(e.lifecycle||e.typeDerivedArgs||Object.keys(e.args).length===0)return;const p=H(e.args);return p===void 0?void 0:`installCompiledValidatorMap(${i.get(e.filePath)??""}.${e.exportName}.args, ${p});`}).filter(e=>e!==void 0).join(`
|
|
71
71
|
`),A=t.filter(e=>e.channel?.kind==="room").map(e=>` ${JSON.stringify(e.channel?.name??"")}: RoomMessageOf<typeof ${i.get(e.filePath)??""}[${JSON.stringify(e.exportName)}]>;`).join(`
|
|
72
72
|
`),v=[...t.map(e=>({args:e.args,definition:e,path:`${g(e.filePath)}:${e.exportName}`})),...n.map(e=>({args:e.args,definition:{...e,expose:void 0,kind:"mutation",lifecycle:void 0,visibility:void 0,x402:void 0},path:`${g(e.filePath)}:${e.exportName}`}))],O=s?v.filter(({definition:e})=>!a.has(e.filePath)):[];for(const{definition:e}of v)if(s&&e.x402&&e.x402.price===void 0)throw new L("INTERNAL",`@lunora/codegen: lazy function registry needs a literal \`.x402({ price })\` value in ${e.filePath}:${e.exportName}`);const m=s?O.map(({definition:e,path:p})=>{const w=i.get(e.filePath)??"",k="channel"in e?e.channel:void 0,N={argumentDescriptors:JSON.parse(D(e.args)),exportName:e.exportName,kind:e.kind,moduleId:w,...k?{channel:k}:{},...e.expose?{expose:e.expose}:{},...e.lifecycle?{lifecycle:e.lifecycle}:{},...e.visibility?{visibility:e.visibility}:{},...e.x402?.price===void 0?{}:{x402:{price:e.x402.price}}};return` ${JSON.stringify(p)}: ${JSON.stringify(N)},`}).join(`
|
|
73
|
-
`):"",
|
|
74
|
-
`):"";return{dispatchBody:
|
|
75
|
-
${
|
|
73
|
+
`):"",b=[...new Set(O.map(({definition:e})=>e.filePath))],S=s?b.map(e=>{if(!F.test(e))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(e)}`);const p=i.get(e)??"";return` ${JSON.stringify(p)}: () => import(${JSON.stringify(`./fn/${p}.js`)}),`}).join(`
|
|
74
|
+
`):"";return{dispatchBody:R.length>0?`
|
|
75
|
+
${R}
|
|
76
76
|
`:"",importBlock:c.length>0?`${c}
|
|
77
77
|
|
|
78
78
|
`:"",installBlock:x,manifestBody:m.length>0?`
|
|
@@ -152,7 +152,7 @@ export type LunoraRoomMessages = {
|
|
|
152
152
|
${n}
|
|
153
153
|
};
|
|
154
154
|
`,typeImport:`import type { RoomMessageOf } from "${r}";
|
|
155
|
-
`}:{channelField:"",messagesBlock:"",typeImport:""},
|
|
155
|
+
`}:{channelField:"",messagesBlock:"",typeImport:""},qe=(t,r,n)=>t?r?`
|
|
156
156
|
/**
|
|
157
157
|
* Room routes are static metadata so building the worker never evaluates user handlers.
|
|
158
158
|
*/
|
|
@@ -212,20 +212,20 @@ export const LUNORA_ROOMS: Readonly<Record<string, string>> = (() => {
|
|
|
212
212
|
|
|
213
213
|
return registry;
|
|
214
214
|
})();
|
|
215
|
-
`:"",
|
|
215
|
+
`:"",ze=(t,r)=>{const n=je(t),o=n.types?`
|
|
216
216
|
${n.types}
|
|
217
217
|
`:"",s=n.implementation?`
|
|
218
218
|
${n.implementation}
|
|
219
219
|
`:"",i=Ne(n.types),a=i.length>0?`import type { ${i.join(", ")} } from "./dataModel.js";
|
|
220
220
|
`:"",c=t.length>0?"context":"_context";let u="";if(t.length>0){let l=Ie;r||(l=l.replace("await loadFunction(functionPath)",P("LUNORA_FUNCTIONS"))),u=`${l}
|
|
221
221
|
|
|
222
|
-
`}return{callRegisteredHelper:u,dataModelImport:a,implementation:s,parameter:c,types:o}},Ye=t=>{const{agents:r=[],functions:n,lazyFunctions:o=!1,migrations:s=[],mutators:i=[],shapes:a=[],useUmbrella:c=!1,usesSandbox:u=!1}=t,l=J(c),{dispatchBody:d,importBlock:f,installBlock:y,ipReaderPaths:$,manifestBody:
|
|
222
|
+
`}return{callRegisteredHelper:u,dataModelImport:a,implementation:s,parameter:c,types:o}},Ye=t=>{const{agents:r=[],functions:n,lazyFunctions:o=!1,migrations:s=[],mutators:i=[],shapes:a=[],useUmbrella:c=!1,usesSandbox:u=!1}=t,l=J(c),{dispatchBody:d,importBlock:f,installBlock:y,ipReaderPaths:$,manifestBody:R,migrationBody:x,moduleLoaders:A,mutatorPaths:v,roomMessagesBody:O,shapeBody:m}=Ce(n,s,i,a,o),b=be(r,n),S=Re(u,n),e=r.length>0||n.some(h=>ge(h)),p=e?` /**
|
|
223
223
|
* Names of the arguments whose validators carry a \`v.sensitive\` marker. Read by the
|
|
224
224
|
* shard before any validator is loaded, so a lazy function's secret args are
|
|
225
225
|
* masked even on a dispatch that fails before its module evaluates.
|
|
226
226
|
*/
|
|
227
227
|
sensitiveArgs?: readonly string[];
|
|
228
|
-
`:"",w=[
|
|
228
|
+
`:"",w=[b.lines,S.lines].filter(h=>h.length>0).join(`
|
|
229
229
|
`);let k=d;w.length>0&&(k=d.length>0?`${d.trimEnd()}
|
|
230
230
|
${w}
|
|
231
231
|
`:`
|
|
@@ -235,7 +235,7 @@ ${w}
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
`:"",K=a.length>0?`import type { RegisteredShape } from "${l.server}";
|
|
238
|
-
`:"",
|
|
238
|
+
`:"",M=n.some(h=>h.channel?.kind==="room"),T=Be(M,l.server,O),Y=a.length>0?`
|
|
239
239
|
/**
|
|
240
240
|
* Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
|
|
241
241
|
* The generated ShardDO's \`resolveShape\` override looks a shape up by name and
|
|
@@ -257,7 +257,7 @@ export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${v.map(h=>JSO
|
|
|
257
257
|
* was read at, which a claims fingerprint leaves out.
|
|
258
258
|
*/
|
|
259
259
|
export const LUNORA_IP_READER_PATHS: ReadonlySet<string> = new Set([${$.map(h=>JSON.stringify(h)).join(", ")}]);
|
|
260
|
-
`:"",ee=
|
|
260
|
+
`:"",ee=qe(M,o,n),{fields:te,lifecycleMember:I,registry:re}=Je(n,o),ne=y.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${l.values}";
|
|
261
261
|
`:"",oe=y.length>0?`
|
|
262
262
|
/**
|
|
263
263
|
* AOT-compiled argument validators (Worker-safe, no \`eval\`). Each is installed
|
|
@@ -265,9 +265,9 @@ export const LUNORA_IP_READER_PATHS: ReadonlySet<string> = new Set([${$.map(h=>J
|
|
|
265
265
|
* parser as a zero-allocation fast path; anything it can't model is deferred.
|
|
266
266
|
*/
|
|
267
267
|
${y}
|
|
268
|
-
`:"",se=
|
|
268
|
+
`:"",se=ze(n,o),{callRegisteredHelper:ae,dataModelImport:ie,implementation:ce,parameter:le,types:de}=se,ue=Me(o),he=o?`
|
|
269
269
|
export interface FunctionManifestEntry {
|
|
270
|
-
argumentDescriptors: ReadonlyArray<{ element?: string; kind: string; name: string; optional: boolean; ${
|
|
270
|
+
argumentDescriptors: ReadonlyArray<{ element?: string; kind: string; name: string; optional: boolean; ${_e(e)}table?: string }>;
|
|
271
271
|
channel?: { kind: "room"; name: string };
|
|
272
272
|
exportName: string;
|
|
273
273
|
expose?: { cache?: { credentialHeaders?: ReadonlyArray<string>; maxAge?: number; scope?: "private" | "public"; staleWhileRevalidate?: number; tag?: string; vary?: string }; rest?: boolean };
|
|
@@ -279,10 +279,10 @@ export interface FunctionManifestEntry {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
/** Static, codegen-derived facts. Request gates can inspect these without evaluating a user module. */
|
|
282
|
-
export const LUNORA_FUNCTION_MANIFEST: Readonly<Record<string, FunctionManifestEntry>> = {${
|
|
282
|
+
export const LUNORA_FUNCTION_MANIFEST: Readonly<Record<string, FunctionManifestEntry>> = {${R}};
|
|
283
283
|
|
|
284
284
|
const MODULE_LOADERS: Record<string, () => Promise<Record<string, unknown>>> = {${A}};
|
|
285
|
-
const
|
|
285
|
+
const settledLoads = new Map<string, Promise<Record<string, unknown>>>();
|
|
286
286
|
const resolvedModules = new Map<string, Record<string, unknown>>();
|
|
287
287
|
const boundFunctions = new Set<string>();
|
|
288
288
|
const unloadedFunctionHandler = (): never => {
|
|
@@ -329,7 +329,11 @@ export const loadFunction = async (functionPath: string): Promise<RegisteredLuno
|
|
|
329
329
|
return registered;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
|
|
332
|
+
// Only a SETTLED load is shared. An in-flight one is not: a Durable Object holds its other events
|
|
333
|
+
// back while a cold load runs (\`holdShardWhileLoading\`), and workerd only lets through I/O that
|
|
334
|
+
// began inside that hold, so awaiting an import another request started would wait out the hold's
|
|
335
|
+
// timeout and reset the object. A second \`import()\` still evaluates the module only once.
|
|
336
|
+
let pending = settledLoads.get(manifest.moduleId);
|
|
333
337
|
|
|
334
338
|
if (pending === undefined) {
|
|
335
339
|
const loader = MODULE_LOADERS[manifest.moduleId];
|
|
@@ -338,8 +342,15 @@ export const loadFunction = async (functionPath: string): Promise<RegisteredLuno
|
|
|
338
342
|
throw new Error(\`no lazy module loader registered for "\${functionPath}"\`);
|
|
339
343
|
}
|
|
340
344
|
|
|
341
|
-
|
|
342
|
-
|
|
345
|
+
const started = loader();
|
|
346
|
+
const settle = (): void => {
|
|
347
|
+
if (!settledLoads.has(manifest.moduleId)) {
|
|
348
|
+
settledLoads.set(manifest.moduleId, started);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
started.then(settle, settle);
|
|
353
|
+
pending = started;
|
|
343
354
|
}
|
|
344
355
|
|
|
345
356
|
// A module that failed to evaluate stays failed for the isolate: the runtime has already cached
|
|
@@ -350,7 +361,7 @@ export const loadFunction = async (functionPath: string): Promise<RegisteredLuno
|
|
|
350
361
|
return getLoadedFunction(functionPath);
|
|
351
362
|
};
|
|
352
363
|
|
|
353
|
-
`:"",me=o&&
|
|
364
|
+
`:"",me=o&&R!==""?`
|
|
354
365
|
/**
|
|
355
366
|
* Evaluate every lazy module now and report the ones that fail, keyed by function path. A lazy
|
|
356
367
|
* registry defers a broken module's error to its first call; \`lunora build\` and \`deploy\` run this
|
|
@@ -359,7 +370,7 @@ export const loadFunction = async (functionPath: string): Promise<RegisteredLuno
|
|
|
359
370
|
export const loadAllFunctions = async (): Promise<{ checked: number; failures: ReadonlyArray<{ functionPath: string; message: string }> }> => {
|
|
360
371
|
const functionPaths = Object.keys(LUNORA_FUNCTION_MANIFEST);
|
|
361
372
|
// Concurrent, so the total is bounded by the slowest module rather than by all of them added up. A module
|
|
362
|
-
// shared by several functions is evaluated once (
|
|
373
|
+
// shared by several functions is evaluated once (the module registry dedupes concurrent imports), and failures keep manifest order.
|
|
363
374
|
const failures = (
|
|
364
375
|
await Promise.all(
|
|
365
376
|
functionPaths.map(async (functionPath) => {
|
|
@@ -376,7 +387,7 @@ export const loadAllFunctions = async (): Promise<{ checked: number; failures: R
|
|
|
376
387
|
|
|
377
388
|
return { checked: functionPaths.length, failures };
|
|
378
389
|
};
|
|
379
|
-
`:"";return ke(`${U}${f}${
|
|
390
|
+
`:"";return ke(`${U}${f}${b.importLine}${S.importLine}${ne}${K}${T.typeImport}import { LunoraError } from "${l.server}";
|
|
380
391
|
import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
|
|
381
392
|
${ie}
|
|
382
393
|
/**
|
|
@@ -424,7 +435,7 @@ ${T.channelField} /**
|
|
|
424
435
|
*/
|
|
425
436
|
x402?: { readonly price: number | string };
|
|
426
437
|
${ue}${p}}
|
|
427
|
-
${
|
|
438
|
+
${b.prelude}${S.prelude}${he}${me}
|
|
428
439
|
/**
|
|
429
440
|
* Static dispatch table. The key matches the \`__lunoraRef\` the client
|
|
430
441
|
* emits (\`api[namespace][fn].__lunoraRef === "namespace:fn"\`).
|
|
@@ -506,12 +517,12 @@ export interface RegisteredDataMigration {
|
|
|
506
517
|
* shard DO's admin RPC and the CLI resolve migrations to run through this map.
|
|
507
518
|
*/
|
|
508
519
|
export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${x}};
|
|
509
|
-
`,c)},Ze="fn",Xe=t=>{if(t.lazyFunctions!==!0)return{};const{functions:r}=t,n=t.migrations??[],o=t.mutators??[],s=t.shapes??[],i=W(r,n,o,s),a=Q(r,n,o,s),c=[...new Set(r.filter(d=>!a.has(d.filePath)).map(d=>d.filePath))],u=J(t.useUmbrella??!1),l={};for(const d of c){if(!F.test(d))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(d)}`);const f=i.get(d)??"",y=`../../${d}.js`,$=r.filter(m=>m.filePath===d&&!m.lifecycle&&Object.keys(m.args).length>0).flatMap(m=>{const
|
|
520
|
+
`,c)},Ze="fn",Xe=t=>{if(t.lazyFunctions!==!0)return{};const{functions:r}=t,n=t.migrations??[],o=t.mutators??[],s=t.shapes??[],i=W(r,n,o,s),a=Q(r,n,o,s),c=[...new Set(r.filter(d=>!a.has(d.filePath)).map(d=>d.filePath))],u=J(t.useUmbrella??!1),l={};for(const d of c){if(!F.test(d))throw new L("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(d)}`);const f=i.get(d)??"",y=`../../${d}.js`,$=r.filter(m=>m.filePath===d&&!m.lifecycle&&Object.keys(m.args).length>0).flatMap(m=>{const b=H(m.args);return b===void 0?[]:[`installCompiledValidatorMap(${f}.${m.exportName}.args, ${b});`]}),R=$.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${u.values}";
|
|
510
521
|
`:"",x=$.length>0?`import * as ${f} from "${y}";
|
|
511
522
|
`:"",A=$.length>0?`
|
|
512
523
|
/** Install the precompiled argument parsers before the module is dispatched. */
|
|
513
524
|
${$.join(`
|
|
514
525
|
`)}
|
|
515
526
|
`:"",O=r.some(m=>m.filePath===d&&m.exportName==="default")||n.some(m=>m.filePath===d&&m.exportName==="default")?`export { default } from "${y}";
|
|
516
|
-
`:"";l[`${f}.ts`]=`${U}${
|
|
527
|
+
`:"";l[`${f}.ts`]=`${U}${R}${x}${A}export * from "${y}";
|
|
517
528
|
${O}`}return l};export{Ze as LAZY_FUNCTION_DIRECTORY,Ye as emitFunctions,Xe as emitLazyFunctionModules};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./CAPABILITY_PROBES-BuNEmlCO.mjs";import{e}from"./server-59fi39OH.mjs";import"./shared-DhqnD5R3.mjs";import"./platform-8oj7iXQy.mjs";export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-
|
|
1
|
+
import"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as d}from"./shard-D_mnxT3r.mjs";import"./shard-runtime-CHda0G1i.mjs";import"./shared-DhqnD5R3.mjs";import"./platform-8oj7iXQy.mjs";import"./schema-BgM8A3XV.mjs";export{d as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CAPABILITIES as Qe}from"./CAPABILITY_PROBES-
|
|
1
|
+
import{CAPABILITIES as Qe}from"./CAPABILITY_PROBES-BuNEmlCO.mjs";import{existsSync as D,readdirSync as de,readlinkSync as ce,lstatSync as qe,statSync as Le}from"node:fs";import{join as h,relative as y,dirname as d,sep as ue,isAbsolute as _e,resolve as Ve,basename as Ge}from"node:path";import{ts as c,Project as He}from"ts-morph";import{G as pe,a as N,u as Ke,d as Ue}from"./shared-DhqnD5R3.mjs";import{p as Je}from"./platform-8oj7iXQy.mjs";const me=/(?:\.d)?\.([cm]?)tsx?$/u,ze=t=>t.replace(me,".d.$1ts"),ye=(t,o)=>{const a=y(t,o).split(ue).join("/").replace(me,".$1js");return a.startsWith(".")?a:`./${a}`},he=t=>t.replaceAll("\\","/"),Y=(t,o,a)=>he(h(t,ze(y(o,a)))),Ye=t=>ye(".",h("services",t.name,y(d(t.wranglerPath),t.main))),Xe=t=>{const o=[],a=e=>{(c.isImportDeclaration(e)||c.isExportDeclaration(e))&&e.moduleSpecifier!==void 0&&c.isStringLiteral(e.moduleSpecifier)?o.push(e.moduleSpecifier):c.isImportTypeNode(e)&&c.isLiteralTypeNode(e.argument)&&c.isStringLiteral(e.argument.literal)&&o.push(e.argument.literal),c.forEachChild(e,a)};return a(t),o},T=t=>{const{mtimeMs:o,size:a}=Le(t);return`${String(o)}:${String(a)}`},Ze=new Set([".git",".wrangler","dist","node_modules","target"]),fe=t=>de(t,{withFileTypes:!0}).flatMap(o=>{const a=h(t,o.name);return o.isSymbolicLink()?[`${a}->${ce(a)}`]:o.isDirectory()&&o.name.startsWith("@")?[`${a}:${T(a)}`,...fe(a)]:[]}),be=t=>[`${t}:${T(t)}`,...fe(t)],ge=t=>{const o=h(t,"node_modules"),a=D(o)?be(o):[],e=d(t);return e===t?a:[...a,...ge(e)]},et=(t,o)=>{const a=[];try{const e=s=>{for(const n of de(s,{withFileTypes:!0})){const l=h(s,n.name);if(l!==o)if(n.isSymbolicLink())a.push(`${l}->${ce(l)}`);else if(n.isDirectory()){if(n.name==="node_modules")a.push(...be(l));else if(!Ze.has(n.name)){if(!qe(l).isDirectory())throw new Error(`${l} changed during the scan`);e(l)}}else a.push(`${l}:${T(l)}`)}};e(t),a.push(...ge(t))}catch{return}return[...new Set(a)].toSorted((e,s)=>e.localeCompare(s)).join(`
|
|
2
2
|
`)},tt=t=>Ge(d(t)).startsWith("@")?d(d(t)):d(t),se=(t,o)=>!y(o,t).startsWith("..")&&!t.split(ue).includes("node_modules"),ie=(t,o)=>{const a=[];let e=t;for(;e!==d(e)&&!D(h(e,"package.json"));)a.push(e),e=d(e);if(D(h(e,"package.json"))){for(const s of[...a,e,h(e,"package.json")])o.add(s);return e}},at=(t,o,a)=>{let e=t;for(;y(e,o).startsWith("..")&&e!==d(e);)a.add(e),e=d(e);a.add(e)},rt=(t,o)=>{const a=new Set;t.some(e=>se(e,o))&&ie(o,a);for(const e of t){if(se(e,o)){for(let n=d(e);n!==o&&n!==d(n);n=d(n))a.add(n);continue}const s=ie(d(e),a);s===void 0?at(d(e),o,a):a.add(tt(s))}return[...a].map(e=>[e,T(e)])},xe=new Map,le=([t,o])=>{try{return T(t)===o}catch{return!1}},ot=(t,o,a)=>{const e=xe.get(t);return e?.optionsKey===o&&e.stamps.every(n=>le(n))&&e.directories.every(n=>le(n))&&a!==void 0&&e.tree===a?e.files:void 0},nt=(t,o,a)=>{const e=[...o.stamps,...o.directories].every(([,s])=>Math.floor(Number.parseFloat(s))<=a);o.tree!==void 0&&e&&xe.set(t,{...o,tree:o.tree})},st=(t,o)=>({directories:rt(o,t),stamps:o.map(a=>[a,T(a)])}),ht=(t,o)=>{const a=d(t.wranglerPath),e=y(a,t.main);if(e.startsWith("..")||_e(e))throw new Error(`@lunora/codegen: service "${t.name}": its entry module (${t.main}) must be inside ${a} to be typed as RPC`);const s=h(o,"services",t.name),n=c.findConfigFile(a,i=>c.sys.fileExists(i)),l=new He({compilerOptions:{composite:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,incremental:!1,noEmit:!1,noEmitOnError:!1,outDir:s,rootDir:a},skipAddingFilesFromTsConfig:!0,...n===void 0?{}:{tsConfigFilePath:n}}),m=JSON.stringify([t.name,t.main,t.wranglerPath,o]),v=JSON.stringify(l.getCompilerOptions()),w=et(a,Ve(o)),g=ot(m,v,w);if(g!==void 0)return g;const A=Date.now();l.addSourceFileAtPath(t.main),l.resolveSourceFileDependencies();const $=l.getProgram().compilerObject.getSourceFiles().map(i=>i.fileName).filter(i=>D(i)),{directories:F,stamps:S}=st(a,$),u={...l.getCompilerOptions(),preserveSymlinks:!0},O=new Map(l.getSourceFiles().map(i=>i.getFilePath()).filter(i=>!i.endsWith(".d.ts")&&!y(a,i).startsWith("..")).map(i=>[Y(s,a,i),i])),f={};for(const i of l.emitToMemory({emitOnlyDtsFiles:!0}).getFiles()){const B=O.get(he(i.filePath));if(B===void 0)continue;const R=c.createSourceFile(i.filePath,i.text,c.ScriptTarget.Latest,!1);let{text:b}=i;for(const k of Xe(R).toReversed()){const x=c.resolveModuleName(k.text,B,u,c.sys).resolvedModule?.resolvedFileName;if(x===void 0)continue;const I=Y(s,a,x),W=O.has(I)?I:x;b=`${b.slice(0,k.getStart(R))}${JSON.stringify(ye(d(i.filePath),W))}${b.slice(k.getEnd())}`}f[y(o,i.filePath)]=`${pe}${b}`}if(f[y(o,Y(s,a,t.main))]===void 0)throw new Error(`@lunora/codegen: service "${t.name}": TypeScript emitted no declaration for its entry module ${t.main}`);return nt(m,{files:f,optionsKey:v,directories:F,stamps:S,tree:w},A),f},it=(t,o=[])=>{const a=new Set;for(const e of t.tables)for(const s of Object.values(e.shape)){const n=Ke(s);n.kind==="storage"&&typeof n.bucket=="string"&&n.bucket!==""&&a.add(n.bucket)}for(const e of o)e!==""&&e!=="default"&&a.add(e);return["default",...[...a].toSorted((e,s)=>e.localeCompare(s))]},ft=({agents:t=[],capabilities:o=new Set,containers:a=[],env:e,hasVectors:s=!0,hasFlags:n=!1,hasNotify:l=!1,identity:m,queues:v=[],schema:w,services:g=[],storageRuleBuckets:A=[],topics:$=[],useUmbrella:F=!1,workflows:S=[]}={})=>{const u=Ue(F),O=it(w??{tables:[]},A).map(r=>JSON.stringify(r)).join(" | "),f=r=>r.sandbox===!0?"SandboxContainerAccessor":"ContainerAccessor",i=[...new Set(a.map(r=>f(r)))].toSorted((r,p)=>r.localeCompare(p)),B=a.length>0?`import type { ${i.join(", ")} } from "@lunora/container";
|
|
3
3
|
`:"",R=a.length>0?`
|
|
4
4
|
readonly containers: {${a.map(r=>`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as me}from"@lunora/errors";import{serializeSchemaSnapshot as Zt,hashSchemaSnapshot as er}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{isHyperdriveGlobalTable as tr,isD1GlobalTable as rr}from"./isD1GlobalTable-udvHAAzD.mjs";import{r as nr}from"./json-data-Chfs2Cz5.mjs";import{r as M,e as ar,a as sr,b as or,c as ir,d as dr,f as cr,g as lr,h as ur,i as hr,j as pr,k as mr,l as fr,m as gr,n as br,o as yr,p as wr,q as vr,s as kr}from"./shard-runtime-
|
|
1
|
+
import{LunoraError as me}from"@lunora/errors";import{serializeSchemaSnapshot as Zt,hashSchemaSnapshot as er}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{isHyperdriveGlobalTable as tr,isD1GlobalTable as rr}from"./isD1GlobalTable-udvHAAzD.mjs";import{r as nr}from"./json-data-Chfs2Cz5.mjs";import{r as M,e as ar,a as sr,b as or,c as ir,d as dr,f as cr,g as lr,h as ur,i as hr,j as pr,k as mr,l as fr,m as gr,n as br,o as yr,p as wr,q as vr,s as kr}from"./shard-runtime-CHda0G1i.mjs";import{u as q,h as Sr,s as Rr,a as xr,I as Ar,c as Or,G as Dr,d as Tr}from"./shared-DhqnD5R3.mjs";import{p as _r}from"./platform-8oj7iXQy.mjs";import{i as Ir}from"./schema-BgM8A3XV.mjs";const p=(r,t)=>`((): (() => ${t}) => { let cached: ${t} | undefined; return () => (cached ??= JSON.parse(${JSON.stringify(JSON.stringify(r))}) as ${t}); })()`,fe=["categories","description","facing","level","remediation","title"],Er=r=>{const t={};return{advisoryRows:r.map(o=>{let n=t[o.name];return n||(n=Object.fromEntries(fe.filter(a=>a in o).map(a=>[a,o[a]])),t[o.name]=n),Object.fromEntries(Object.entries(o).filter(([a,i])=>!fe.includes(a)||JSON.stringify(i)!==JSON.stringify(n[a])))}),advisoryRules:t}},Cr=` /**
|
|
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
|
|
@@ -1573,7 +1573,7 @@ ${C?` for (const path of LUNORA_IP_READER_PATHS) {
|
|
|
1573
1573
|
return;
|
|
1574
1574
|
}
|
|
1575
1575
|
|
|
1576
|
-
return
|
|
1576
|
+
return this.holdShardWhileLoading(() => loadFunction(functionPath));
|
|
1577
1577
|
}
|
|
1578
1578
|
`:"",Ut=pe===""?`
|
|
1579
1579
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as k}from"@lunora/errors";import{r as b}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as R}from"./CAPABILITY_PROBES-
|
|
1
|
+
import{LunoraError as k}from"@lunora/errors";import{r as b}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as R}from"./CAPABILITY_PROBES-BuNEmlCO.mjs";import{a as l,G as f,I as w}from"./shared-DhqnD5R3.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
|
|
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.389",
|
|
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.
|
|
55
|
-
"@lunora/container": "1.0.0-alpha.
|
|
53
|
+
"@lunora/advisor": "1.0.0-alpha.284",
|
|
54
|
+
"@lunora/agent": "1.0.0-alpha.276",
|
|
55
|
+
"@lunora/container": "1.0.0-alpha.108",
|
|
56
56
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
57
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
58
|
-
"@lunora/queue": "1.0.0-alpha.
|
|
59
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
60
|
-
"@lunora/values": "1.0.0-alpha.
|
|
61
|
-
"@lunora/workflow": "1.0.0-alpha.
|
|
57
|
+
"@lunora/platform": "1.0.0-alpha.79",
|
|
58
|
+
"@lunora/queue": "1.0.0-alpha.142",
|
|
59
|
+
"@lunora/scheduler": "1.0.0-alpha.167",
|
|
60
|
+
"@lunora/values": "1.0.0-alpha.94",
|
|
61
|
+
"@lunora/workflow": "1.0.0-alpha.110",
|
|
62
62
|
"@visulima/fs": "7.0.0",
|
|
63
63
|
"jiti": "^2.7.0",
|
|
64
64
|
"quicktype-core": "^26.0.0",
|