@lunora/codegen 1.0.0-alpha.274 → 1.0.0-alpha.275
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 +78 -9
- package/dist/index.d.ts +78 -9
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{AGENTS_FILENAME-lBe4g_sU.mjs → AGENTS_FILENAME-NQIB6wh3.mjs} +1 -1
- package/dist/packem_shared/{CONTAINERS_FILENAME-CY43AXXN.mjs → CONTAINERS_FILENAME-CK3xJGwm.mjs} +1 -1
- package/dist/packem_shared/{FLAGS_FILENAME-DXltN9DD.mjs → FLAGS_FILENAME-DYMd1xqw.mjs} +1 -1
- package/dist/packem_shared/GENERATED_HEADER-D-P7ii4H.mjs +1 -0
- package/dist/packem_shared/{MUTATORS_FILENAME-BxRrG_s-.mjs → MUTATORS_FILENAME-BrEGrcPU.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-J5MGAkca.mjs → NOTIFY_FILENAME-B42rW2NJ.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-B8RT1JYn.mjs → OPENRPC_VERSION-BaD2A2YR.mjs} +1 -1
- package/dist/packem_shared/{QUEUES_FILENAME-DeJw5eqU.mjs → QUEUES_FILENAME-Dj5yK34Z.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DWriXOYw.mjs +11 -0
- package/dist/packem_shared/{SHAPES_FILENAME-CeBFuc8M.mjs → SHAPES_FILENAME-CVc2VCnS.mjs} +1 -1
- package/dist/packem_shared/{WORKFLOWS_FILENAME-B47AB5pc.mjs → WORKFLOWS_FILENAME-Ze98LsB3.mjs} +1 -1
- package/dist/packem_shared/{attribution-NRssTEkk.mjs → attribution-Dw35rOaJ.mjs} +1 -1
- package/dist/packem_shared/{buildOpenApiDocument-6VJGU6fU.mjs → buildOpenApiDocument-BjHdW7b2.mjs} +1 -1
- package/dist/packem_shared/{capabilitiesUsedBy-DARbl-4Z.mjs → capabilitiesUsedBy-FnnYmnSl.mjs} +1 -1
- package/dist/packem_shared/chain-nWiSr1yy.mjs +1 -0
- package/dist/packem_shared/{classify-procedure-call-BBKuBvKg.mjs → classify-procedure-call-DxuPQkJA.mjs} +1 -1
- package/dist/packem_shared/{context-property-calls-tlnXE-wv.mjs → context-property-calls-BLTVj9HH.mjs} +1 -1
- package/dist/packem_shared/{context-root-IuI71QkK.mjs → context-root-B04bYCE-.mjs} +1 -1
- package/dist/packem_shared/{database-calls-BFY_pIUf.mjs → database-calls-DWDtdDbS.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-TA2a8bZI.mjs → discoverAuthApiCalls-XK_WCMDG.mjs} +1 -1
- package/dist/packem_shared/discoverCrons-B5bVCaNF.mjs +1 -0
- package/dist/packem_shared/{discoverFunctions-4sef11AC.mjs → discoverFunctions-Be-XuuSW.mjs} +1 -1
- package/dist/packem_shared/{discoverHttpRoutes-CLGXL19M.mjs → discoverHttpRoutes-CMOxt2Y9.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-mrho5AnY.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-CKEO1mZZ.mjs → discoverInserts-BhIpUWXN.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-DCw165tP.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-DYQbnqow.mjs → discoverMigrations-dVVZtuJa.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-BfdM93-8.mjs → discoverNondeterministicCalls-Dtb1aoGV.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-DEkIMaBP.mjs → discoverQueries-BSOjEsk3.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-KONCqZr2.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-rpiO4wSi.mjs → discoverRlsMetadata-9YDlDDoh.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-BtT8-r93.mjs → discoverRlsProcedures-c0DnIR4z.mjs} +1 -1
- package/dist/packem_shared/{discoverSandboxUsage-B8P9QjWZ.mjs → discoverSandboxUsage-CfEU2hM-.mjs} +1 -1
- package/dist/packem_shared/{discoverSchema-BdmC-kO2.mjs → discoverSchema-BTFFWy3i.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-C2hYksmI.mjs → discoverStorageRulesMetadata-f89BWody.mjs} +1 -1
- package/dist/packem_shared/{emitAgents-CzxW-qj5.mjs → emitAgents-CG2R-Zz6.mjs} +1 -1
- package/dist/packem_shared/{emitApi-xDIHPRPH.mjs → emitApi-zY6egN77.mjs} +44 -63
- package/dist/packem_shared/{emitApp-BdVXkH7A.mjs → emitApp-DUGS6Ve2.mjs} +1 -1
- package/dist/packem_shared/{emitCrons-DKeoaeqU.mjs → emitCrons-B8TBAOZ4.mjs} +1 -1
- package/dist/packem_shared/{emitDataModel-DSk9AkJe.mjs → emitDataModel-B68T_eX6.mjs} +5 -5
- package/dist/packem_shared/{emitDrizzleSchema-DohtnI8c.mjs → emitDrizzleSchema-DLtfKTI4.mjs} +2 -2
- package/dist/packem_shared/{emitFunctions-evl8Mx1a.mjs → emitFunctions-DkkcTDqh.mjs} +39 -47
- package/dist/packem_shared/{emitServer-CYjqZ3W8.mjs → emitServer-BbjIwe2-.mjs} +1 -1
- package/dist/packem_shared/{emitShard-tQej36w1.mjs → emitShard-CSLqD-Hr.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-DqU-ZCbG.mjs → exported-procedure-chains-C5VKkd9T.mjs} +1 -1
- package/dist/packem_shared/{fingerprintSchemaSources-ChYfrghz.mjs → fingerprintSchemaSources-BJSIxwhY.mjs} +1 -1
- package/dist/packem_shared/{handler-reference-B3coD2YR.mjs → handler-reference-2Hs4WKnz.mjs} +1 -1
- package/dist/packem_shared/{index-CRO3TRxd.mjs → index-CefI-Sba.mjs} +1 -1
- package/dist/packem_shared/isTestPath-CgyyLk8U.mjs +1 -0
- package/dist/packem_shared/{modules-6EEBTEDo.mjs → modules-BIpFLz3Z.mjs} +1 -1
- package/dist/packem_shared/paths-DwTjD7BU.mjs +1 -0
- package/dist/packem_shared/{qualifiers-Cw8dEDbh.mjs → qualifiers-COHdrghK.mjs} +1 -1
- package/dist/packem_shared/{server-dr22ile6.mjs → server-BmY5wwKY.mjs} +1 -1
- package/dist/packem_shared/{shard-C1ZGdOG1.mjs → shard-Dr5gMNyz.mjs} +1 -1
- package/dist/packem_shared/{shard-runtime-DGrBvQWg.mjs → shard-runtime-BI2SZ54Z.mjs} +1 -1
- package/dist/packem_shared/shared-Be3TGzxM.mjs +13 -0
- package/dist/packem_shared/{unwrap-handler-return-Dy8h5-I6.mjs → unwrap-handler-return-T5sJhEss.mjs} +1 -1
- package/package.json +4 -4
- package/dist/packem_shared/GENERATED_HEADER-dFyrHgQ0.mjs +0 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-UlgFl8hS.mjs +0 -11
- package/dist/packem_shared/chain-6qc9c0JF.mjs +0 -1
- package/dist/packem_shared/discoverCrons-PQeDYVPc.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-imtma-ic.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-Cr6hDinL.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-BRIyb8Cl.mjs +0 -1
- package/dist/packem_shared/isTestPath-DCyIyPa7.mjs +0 -1
- package/dist/packem_shared/paths-C-9fwEgQ.mjs +0 -1
- package/dist/packem_shared/shared-BXUKWh7t.mjs +0 -9
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import{LunoraError as B}from"@lunora/errors";import{L as H,G as q,I as J,d as Q,
|
|
1
|
+
import{LunoraError as B}from"@lunora/errors";import{L as H,G as q,I as J,d as Q,b as S,r as G,c as z}from"./shared-Be3TGzxM.mjs";import{s as g}from"./paths-DwTjD7BU.mjs";import{renderAgentFunctionRegistry as V,renderSandboxFunctionRegistry as W}from"./emitApi-zY6egN77.mjs";import{a as K,b as Y,r as O,c as X}from"./qualifiers-COHdrghK.mjs";const Z=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),A=n=>n.column!==void 0,ee=(n,e)=>{switch(n){case"bigint":return`if (typeof ${e} !== "bigint") return DEFER;
|
|
2
2
|
`;case"boolean":return`if (typeof ${e} !== "boolean") return DEFER;
|
|
3
3
|
`;case"date":case"number":case"timestamp":return`if (typeof ${e} !== "number" || !Number.isFinite(${e})) return DEFER;
|
|
4
4
|
`;case"null":return`if (${e} !== null) return DEFER;
|
|
5
5
|
`;default:return`if (typeof ${e} !== "string") return DEFER;
|
|
6
|
-
`}},
|
|
7
|
-
`,
|
|
8
|
-
`}},v=(n,e,r)=>{if(!A(n)&&!(n.unmodelledRefinement||n.sourceText!==void 0)){if(
|
|
9
|
-
const ${
|
|
6
|
+
`}},te=(n,e)=>n.stringMaxLength===void 0?"":`if (${e}.length > ${String(n.stringMaxLength)}) return DEFER;
|
|
7
|
+
`,ne=(n,e)=>{const r=n.literalValue?.trim();if(!(r===void 0||!H.test(r)))return{out:e,pre:`if (${e} !== ${r}) return DEFER;
|
|
8
|
+
`}},v=(n,e,r)=>{if(!A(n)&&!(n.unmodelledRefinement||n.sourceText!==void 0)){if(Z.has(n.kind))return n.kind==="any"?{out:e,pre:""}:{out:e,pre:ee(n.kind,e)+te(n,e)};switch(n.kind){case"array":return re(n,e,r);case"literal":return ne(n,e);case"object":return se(n,e,r);default:return}}},re=(n,e,r)=>{const{inner:o}=n;if(!o)return;const a=r.next(),s=`__arr${String(a)}`,i=`__i${String(a)}`,c=`__e${String(a)}`,l=v(o,c,r);if(!l)return;const u=`if (!Array.isArray(${e})) return DEFER;
|
|
9
|
+
const ${s} = new Array(${e}.length);
|
|
10
10
|
for (let ${i} = 0; ${i} < ${e}.length; ${i}++) {
|
|
11
|
-
const ${
|
|
12
|
-
${l.pre}${
|
|
11
|
+
const ${c} = ${e}[${i}];
|
|
12
|
+
${l.pre}${s}[${i}] = ${l.out};
|
|
13
13
|
}
|
|
14
|
-
`;return{out:
|
|
14
|
+
`;return{out:s,pre:u}},oe=(n,e,r,o)=>{const a=JSON.stringify(n);if(e.kind==="optional"){if(e.hasRefinement||e.sourceText!==void 0||A(e))return;const{inner:i}=e;if(!i)return;const c=v(i,r,o);if(!c)return;const l=o.next(),u=`__has${String(l)}`,d=`__val${String(l)}`,f=`let ${u} = false;
|
|
15
15
|
let ${d};
|
|
16
16
|
if (${r} !== undefined) {
|
|
17
|
-
${
|
|
17
|
+
${c.pre}${d} = ${c.out};
|
|
18
18
|
${u} = true;
|
|
19
19
|
}
|
|
20
|
-
`;return{entry:`...(${u} ? { ${
|
|
21
|
-
`,l=d}const u=
|
|
22
|
-
`},
|
|
23
|
-
${T(e)}${
|
|
24
|
-
`;return{out:i,pre:
|
|
20
|
+
`;return{entry:`...(${u} ? { ${a}: ${d} } : {})`,pre:f}}const s=v(e,r,o);if(s)return{entry:`${a}: ${s.out}`,pre:s.pre}},ae=new Set(Object.getOwnPropertyNames(Object.prototype)),_=(n,e,r)=>{let o="";const a=[];for(const s of Object.keys(n)){const i=n[s];if(!i)return;const c=JSON.stringify(s);let l=`${e}[${c}]`;if(ae.has(s)){const d=`__f${String(r.next())}`;o+=`const ${d} = Object.hasOwn(${e}, ${c}) ? ${e}[${c}] : undefined;
|
|
21
|
+
`,l=d}const u=oe(s,i,l,r);if(!u)return;o+=u.pre,a.push(u.entry)}return{entries:a.join(", "),pre:o}},T=n=>{const e=`Object.getPrototypeOf(${n})`;return`if (${e} !== Object.prototype && ${e} !== null) return DEFER;
|
|
22
|
+
`},se=(n,e,r)=>{const o=n.shape??{},a=_(o,e,r);if(!a)return;const s=r.next(),i=`__obj${String(s)}`,c=`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) return DEFER;
|
|
23
|
+
${T(e)}${a.pre}const ${i} = { ${a.entries} };
|
|
24
|
+
`;return{out:i,pre:c}},ie=n=>{let e=0;const o=_(n,"source",{next:()=>(e+=1,e)});if(o)return`(source) => {
|
|
25
25
|
if (typeof source !== "object" || source === null || Array.isArray(source)) return DEFER;
|
|
26
|
-
${T("source")}${
|
|
27
|
-
}`},
|
|
26
|
+
${T("source")}${o.pre}return { ${o.entries} };
|
|
27
|
+
}`},ce=(n,e)=>`lunora_${g(n)}_${String(e)}`,le=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
|
|
28
28
|
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
29
29
|
|
|
30
30
|
if (!registered) {
|
|
@@ -57,66 +57,58 @@ ${T("source")}${c.pre}return { ${c.entries} };
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
return (await registered.handler(context, args ?? {})) as R;
|
|
60
|
-
};`,
|
|
61
|
-
`),
|
|
62
|
-
`),l=e.map(t=>` ${JSON.stringify(t.id)}: ${
|
|
63
|
-
`),u=r.map(t=>` "${
|
|
64
|
-
`),d=
|
|
65
|
-
`),f=r.map(t=>`${
|
|
66
|
-
`),R=n.map(t=>{if(t.lifecycle||Object.keys(t.args).length===0)return;const
|
|
67
|
-
`);return{dispatchBody:
|
|
68
|
-
${
|
|
60
|
+
};`,ue=(n,e,r=[],o=[])=>{const a=new Map,s=t=>{a.has(t)||a.set(t,ce(t,a.size))};for(const t of n)s(t.filePath);for(const t of e)s(t.filePath);for(const t of r)s(t.filePath);for(const t of o)s(t.filePath);const i=[...a.entries()].map(([t,m])=>{if(!J.test(t))throw new B("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(t)}`);return`import * as ${m} from "../${t}.js";`}).join(`
|
|
61
|
+
`),c=n.map(t=>` "${g(t.filePath)}:${t.exportName}": ${a.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
62
|
+
`),l=e.map(t=>` ${JSON.stringify(t.id)}: ${a.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredDataMigration,`).join(`
|
|
63
|
+
`),u=r.map(t=>` "${g(t.filePath)}:${t.exportName}": ${a.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
64
|
+
`),d=o.map(t=>` "${t.exportName}": ${a.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredShape,`).join(`
|
|
65
|
+
`),f=r.map(t=>`${g(t.filePath)}:${t.exportName}`),p=[c,u].filter(t=>t.length>0).join(`
|
|
66
|
+
`),R=n.map(t=>{if(t.lifecycle||Object.keys(t.args).length===0)return;const m=ie(t.args);return m===void 0?void 0:`installCompiledValidatorMap(${a.get(t.filePath)??""}.${t.exportName}.args, ${m});`}).filter(t=>t!==void 0).join(`
|
|
67
|
+
`);return{dispatchBody:p.length>0?`
|
|
68
|
+
${p}
|
|
69
69
|
`:"",importBlock:i.length>0?`${i}
|
|
70
70
|
|
|
71
71
|
`:"",installBlock:R,migrationBody:l.length>0?`
|
|
72
72
|
${l}
|
|
73
73
|
`:"",mutatorPaths:f,shapeBody:d.length>0?`
|
|
74
74
|
${d}
|
|
75
|
-
`:""}},
|
|
76
|
-
`);return` ${z(p(o))}: {
|
|
77
|
-
${i}
|
|
78
|
-
};`}).join(`
|
|
79
|
-
`);return{implementation:e.map(([o,a])=>{const i=p(o),s=a.map(l=>` ${x(l.exportName)}: (args) => callRegistered(context, "${i}:${l.exportName}", args),`).join(`
|
|
80
|
-
`);return` ${x(i)}: {
|
|
81
|
-
${s}
|
|
82
|
-
},`}).join(`
|
|
83
|
-
`),types:r}},pe=n=>{const e={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const r of n)r.lifecycle&&e[r.lifecycle].push(`${p(r.filePath)}:${r.exportName}`);return e},be=n=>{const{agents:e=[],functions:r,migrations:c=[],mutators:o=[],shapes:a=[],useUmbrella:i=!1,usesSandbox:s=!1}=n,l=r.length>0,u=Q(i),{dispatchBody:d,importBlock:f,installBlock:m,migrationBody:R,mutatorPaths:t,shapeBody:g}=de(r,c,o,a),b=V(e,r),w=W(s,r),k=[b.lines,w.lines].filter(h=>h.length>0).join(`
|
|
75
|
+
`:""}},de=n=>{const e=S(n,o=>{const a=O(G(o.args),o.filePath),s=a==="{}"?"?":"",i=O(X(o),o.filePath);return o.kind==="stream"?`${o.exportName}: (args${s}: ${a}) => Promise<AsyncIterable<${i}>>;`:`${o.exportName}: (args${s}: ${a}) => Promise<${i}>;`},"type");return{implementation:S(n,o=>`${z(o.exportName)}: (args) => callRegistered(context, "${g(o.filePath)}:${o.exportName}", args),`,"value"),types:e}},he=n=>{const e={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const r of n)r.lifecycle&&e[r.lifecycle].push(`${g(r.filePath)}:${r.exportName}`);return e},$e=n=>{const{agents:e=[],functions:r,migrations:o=[],mutators:a=[],shapes:s=[],useUmbrella:i=!1,usesSandbox:c=!1}=n,l=r.length>0,u=Q(i),{dispatchBody:d,importBlock:f,installBlock:p,migrationBody:R,mutatorPaths:t,shapeBody:m}=ue(r,o,a,s),b=V(e,r),w=W(c,r),k=[b.lines,w.lines].filter(h=>h.length>0).join(`
|
|
84
76
|
`);let N=d;k.length>0&&(N=d.length>0?`${d.trimEnd()}
|
|
85
77
|
${k}
|
|
86
78
|
`:`
|
|
87
79
|
${k}
|
|
88
|
-
`);const y=
|
|
89
|
-
`:"",L=
|
|
80
|
+
`);const y=he(r),P=s.length>0?`import type { RegisteredShape } from "${u.server}";
|
|
81
|
+
`:"",L=s.length>0?`
|
|
90
82
|
/**
|
|
91
83
|
* Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
|
|
92
84
|
* The generated ShardDO's \`resolveShape\` override looks a shape up by name and
|
|
93
85
|
* evaluates its trusted \`compileWhere(ctx, args)\` to authorize + scope a
|
|
94
86
|
* \`shape_subscribe\` (reads-as-permissions).
|
|
95
87
|
*/
|
|
96
|
-
export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${
|
|
97
|
-
`:"",
|
|
88
|
+
export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${m}};
|
|
89
|
+
`:"",E=t.length>0?`
|
|
98
90
|
/**
|
|
99
91
|
* Custom-mutator function paths — the \`LUNORA_FUNCTIONS\` keys the generated
|
|
100
92
|
* ShardDO's \`isCustomMutator\` override routes through the client-watermark push
|
|
101
93
|
* protocol (\`x-lunora-client-id\`/\`x-lunora-client-seq\` ordering).
|
|
102
94
|
*/
|
|
103
95
|
export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${t.map(h=>JSON.stringify(h)).join(", ")}]);
|
|
104
|
-
`:"",
|
|
105
|
-
`:"",
|
|
96
|
+
`:"",C=p.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${u.values}";
|
|
97
|
+
`:"",j=p.length>0?`
|
|
106
98
|
/**
|
|
107
99
|
* AOT-compiled argument validators (Worker-safe, no \`eval\`). Each is installed
|
|
108
100
|
* onto its function's live \`.args\` object and consulted by the interpreted
|
|
109
101
|
* parser as a zero-allocation fast path; anything it can't model is deferred.
|
|
110
102
|
*/
|
|
111
|
-
${
|
|
112
|
-
`:"",$=
|
|
103
|
+
${p}
|
|
104
|
+
`:"",$=de(r),F=$.types?`
|
|
113
105
|
${$.types}
|
|
114
106
|
`:"",M=$.implementation?`
|
|
115
107
|
${$.implementation}
|
|
116
|
-
`:"",
|
|
117
|
-
`:"",I=l?"context":"_context",U=l?`${
|
|
108
|
+
`:"",x=K($.types),D=x.length>0?`import type { ${x.join(", ")} } from "./dataModel.js";
|
|
109
|
+
`:"",I=l?"context":"_context",U=l?`${le}
|
|
118
110
|
|
|
119
|
-
`:"";return
|
|
111
|
+
`:"";return Y(`${q}${f}${b.importLine}${w.importLine}${C}${P}import { LunoraError } from "${u.server}";
|
|
120
112
|
import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
|
|
121
113
|
${D}
|
|
122
114
|
/**
|
|
@@ -170,7 +162,7 @@ ${b.prelude}${w.prelude}
|
|
|
170
162
|
* emits (\`api[namespace][fn].__lunoraRef === "namespace:fn"\`).
|
|
171
163
|
*/
|
|
172
164
|
export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${N}};
|
|
173
|
-
${
|
|
165
|
+
${j}${L}${E}
|
|
174
166
|
/**
|
|
175
167
|
* Lifecycle manifest: the function paths the generated ShardDO dispatches when a
|
|
176
168
|
* client's WebSocket connects (\`connect\`) or disconnects (\`disconnect\`), once
|
|
@@ -246,4 +238,4 @@ export interface RegisteredDataMigration {
|
|
|
246
238
|
* shard DO's admin RPC and the CLI resolve migrations to run through this map.
|
|
247
239
|
*/
|
|
248
240
|
export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${R}};
|
|
249
|
-
`,i)};export{
|
|
241
|
+
`,i)};export{$e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./CAPABILITY_PROBES-brcmKenl.mjs";import"./ir-DBSvhNa-.mjs";import{e}from"./server-
|
|
1
|
+
import"./CAPABILITY_PROBES-brcmKenl.mjs";import"./ir-DBSvhNa-.mjs";import{e}from"./server-BmY5wwKY.mjs";import"./shared-Be3TGzxM.mjs";export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as f}from"./shard-
|
|
1
|
+
import"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import"./isD1GlobalTable-udvHAAzD.mjs";import"./ir-DBSvhNa-.mjs";import"./json-data-Chfs2Cz5.mjs";import{e as f}from"./shard-Dr5gMNyz.mjs";import"./shard-runtime-BI2SZ54Z.mjs";import"./shared-Be3TGzxM.mjs";export{f as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as s}from"ts-morph";import{b as t,d as c}from"./attribution-
|
|
1
|
+
import{Node as s}from"ts-morph";import{b as t,d as c}from"./attribution-Dw35rOaJ.mjs";import{c as n}from"./classify-procedure-call-DxuPQkJA.mjs";const m=a=>{const i=[];for(const e of t(a)){const r=e.getInitializer(),o=r&&s.isCallExpression(r)?n(r):void 0;o?.receiver&&i.push({name:c(e)??e.getName(),receiver:o.receiver})}return i};export{m as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash as i}from"node:crypto";import{existsSync as s,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{listLunoraSourceFiles as h}from"./isTestPath-
|
|
1
|
+
import{createHash as i}from"node:crypto";import{existsSync as s,readFileSync as c}from"node:fs";import{join as u}from"node:path";import{listLunoraSourceFiles as h}from"./isTestPath-CgyyLk8U.mjs";const S=t=>{if(!s(t))return"unreadable";const e=h(t,{includeSkipped:!0}),o=u(t,"schema.ts");s(o)&&e.push(o);const r=i("sha256");for(const a of e.toSorted((n,p)=>n.localeCompare(p)))try{r.update(a).update("\0").update(c(a))}catch{}return r.digest("hex")};export{S as default};
|
package/dist/packem_shared/{handler-reference-B3coD2YR.mjs → handler-reference-2Hs4WKnz.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-
|
|
1
|
+
import{dirname as F}from"node:path";import{Node as e}from"ts-morph";import{unwrapExpression as m,lunoraRelativePath as u}from"./isTestPath-CgyyLk8U.mjs";import{r as v,d as b}from"./attribution-Dw35rOaJ.mjs";const h=i=>e.isPropertyAssignment(i)?m(i.getInitializer()):e.isShorthandPropertyAssignment(i)?i.getNameNode():void 0,A=(i,s)=>{const o=i===void 0?void 0:h(i);if(o===void 0||!e.isIdentifier(o))return;const a=v(o),g=a?.getAliasedSymbol()??a;for(const t of g?.getDeclarations()??[]){const n=e.isVariableDeclaration(t)?m(t.getInitializer()):t;if(!(e.isFunctionDeclaration(n)||e.isArrowFunction(n)||e.isFunctionExpression(n))||!(e.isFunctionDeclaration(t)||e.isVariableDeclaration(t)))continue;const r=t.getSourceFile(),c=u(s,r.getFilePath()),l=!c.startsWith("../"),d=l?c:u(F(s),r.getFilePath()),f=b(t);return{body:n,...r===o.getSourceFile()?{}:{file:d},...l&&f!==void 0?{site:{exportName:f,file:d}}:{}}}};export{A as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-
|
|
1
|
+
import{Node as i}from"ts-morph";import{listLunoraSourceFiles as u,lunoraRelativePath as f}from"./isTestPath-CgyyLk8U.mjs";import{b as m,d as p}from"./attribution-Dw35rOaJ.mjs";import{t as d}from"./database-calls-DWDtdDbS.mjs";import{w as g,c as h}from"./classify-procedure-call-DxuPQkJA.mjs";import{a as k}from"./project-config-file-Bv2l-Kmm.mjs";const l=e=>{if(!(!i.isPropertyAssignment(e)&&!i.isShorthandPropertyAssignment(e)&&!i.isMethodDeclaration(e)&&!i.isGetAccessorDeclaration(e)))return k(e)},v=e=>g(e,"use","mask"),D=e=>{if(i.isPropertyAssignment(e)){const s=e.getInitializer();if(s&&i.isStringLiteral(s)){const t=s.getLiteralText();if(t==="redact"||t==="hash")return t}}return"custom"},P=e=>{const s=e.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return[];const t=[];for(const r of s.getProperties()){const o=l(r);if(o===void 0||!i.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!i.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=l(a);c!==void 0&&t.push({column:c,table:o})}}return t},y=e=>{const s=v(e);return{maskColumns:s.flatMap(t=>P(t)),usesMask:s.length>0}},C=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),M=new Set(["delete","insert","patch","replace"]),b=(e,s)=>{if(!i.isVariableDeclaration(e))return;const t=e.getInitializer();if(!t||!i.isCallExpression(t))return;const r=h(t);if(!r)return;const o=r.receiver?y(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=d(e,C,M);return{exportName:p(e)??e.getName(),file:s,maskColumns:o.maskColumns,tablesRead:n,tablesWritten:a,usesMask:o.usesMask,visibility:r.visibility}},E=(e,s)=>{const t=[];for(const r of u(s)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=f(s,r);for(const a of m(o)){const c=b(a,n);c&&t.push(c)}}return t};export{l as a,E as d,v as m,D as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as h,statSync as P,readdirSync as A,realpathSync as C,lstatSync as j}from"node:fs";import{dirname as d,join as g,relative as w,sep as O,resolve as k,extname as F,basename as D}from"node:path";import{findUpSync as z,FIND_UP_STOP as V,matcher as K}from"@visulima/fs";import{SyntaxKind as p,Node as i,VariableDeclarationKind as $}from"ts-morph";import{diagnosticAt as M}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{p as U,a as B,r as W}from"./project-config-file-Bv2l-Kmm.mjs";import{findProjectConfigFile as N}from"./PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs";const X=/\.ts$/u,f=(t,e)=>w(t,e).split(O).join("/").replace(X,""),H=new Set(["_generated","node_modules"]),_=new Set(["__fixtures__","__mocks__","__snapshots__","__tests__"]),L=/\.(?:bench|e2e|e2e-spec|spec|spec-d|test|test-d)(?:\.tsx?)?$/u,Se=t=>{const e=t.split("/");return L.test(e.at(-1)??"")||e.slice(0,-1).some(s=>_.has(s))},E=(t,e,s)=>e?H.has(t)||!s&&_.has(t):!s&&L.test(t),v=new Map,m=()=>!1,Y=t=>{const e=z(c=>N(c)??(h(g(c,"package.json"))||h(g(c,".git"))?V:void 0),{cwd:d(k(t))}),s=e===void 0?void 0:P(e,{throwIfNoEntry:!1});if(e===void 0||s===void 0)return m;const n=`${String(s.mtimeMs)}:${String(s.size)}`,r=v.get(e);if(r?.key===n)return r.isExcluded;const{codegen:o}=W(d(e));o?.unreadable&&console.warn("@lunora/codegen: `codegen.exclude` in lunora.config is not an array of string literals without `!` negations — ignoring it.");const a=o?.exclude?.length?K(o.exclude):m;return v.set(e,{isExcluded:a,key:n}),a},q=(t,e,s)=>t==="schema.ts"&&e===s,G=t=>{try{return P(t)}catch{console.warn(`@lunora/codegen: skipping ${t} — it is a symlink that does not resolve (or vanished mid-scan).`);return}},R=(t,e,s,n,r)=>{let o,a;try{o=A(t),a=C(t)}catch{return e}if(n.has(a))return e;n.add(a);for(const c of o){const u=g(t,c),l=G(u);l===void 0||r(c,w(s,u).split(O).join("/"),l.isDirectory())||(l.isDirectory()?R(u,e,s,n,r):l.isFile()&&F(c)===".ts"&&!q(c,t,s)&&e.push(u))}return e},T=(t,e={})=>{const s=e.includeSkipped??!1,n=s?m:Y(t);return R(t,[],t,new Set,(r,o,a)=>E(r,a,s)||n(o))},Q=["src/server","src/index.ts","src/worker.ts"],J=new Set([".ts",".tsx"]),b=(t,e=[])=>{let s;try{s=j(t)}catch{return e}if(s.isFile())return J.has(F(t))&&!E(D(t),!1,!1)&&e.push(t),e;if(!s.isDirectory())return e;for(const n of A(t))E(n,!0,!1)||b(g(t,n),e);return e},Z=t=>{const e=d(t),s=T(t).map(o=>({displayPath:f(t,o),filePath:o})),n=new Set(s.map(o=>o.filePath)),r=N(e);for(const o of[...Q.flatMap(a=>b(g(e,a))),...r===void 0?[]:[r]])n.has(o)||(n.add(o),s.push({displayPath:f(e,o),filePath:o}));return s},ee=t=>Array.isArray(t),I=(t,e,s,n)=>{const r=[];for(const{displayPath:o,filePath:a}of e){const c=t.getSourceFile(a)??t.addSourceFileAtPath(a);for(const u of c.getDescendantsOfKind(s)){const l=n(u,o);ee(l)?r.push(...l):l!==void 0&&r.push(l)}}return r},te=t=>T(t).map(e=>({displayPath:f(t,e),filePath:e})),se=(t,e,s,n)=>I(t,te(e),s,n),he=(t,e,s)=>se(t,e,p.CallExpression,s),ve=(t,e,s)=>I(t,Z(e),p.CallExpression,s),ye=t=>U(t.getPropertyNameNode()??t.getNameNode()),S=(t,e)=>t?.getProperties().find(s=>!i.isSpreadAssignment(s)&&B(s)===e),Pe=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(i.isArrowFunction(o)||i.isFunctionExpression(o))?o:void 0}const s=t.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;const n=S(s,"handler");if(!n||!i.isPropertyAssignment(n))return;const r=n.getInitializer();return r&&(i.isArrowFunction(r)||i.isFunctionExpression(r))?r:void 0},Ae=(t,e)=>{if(!t||!i.isObjectLiteralExpression(t))return;const s=S(t,e);return s&&i.isPropertyAssignment(s)?s.getInitializer():void 0},ie=t=>{const e=t?.getParent();return i.isVariableDeclaration(t)&&i.isVariableDeclarationList(e)&&e.getDeclarationKind()===$.Const},ne=t=>{let e=t,s=e.getParent();for(;s!==void 0&&(i.isParenthesizedExpression(s)||i.isAsExpression(s)||i.isSatisfiesExpression(s)||i.isTypeAssertion(s)||i.isNonNullExpression(s));)e=s,s=e.getParent();return e},y=t=>{const e=ne(t),s=e.getParent();if(s===void 0)return!1;if(i.isBinaryExpression(s)){const r=s.getOperatorToken().getKind();return s.getLeft()===e&&r>=p.FirstAssignment&&r<=p.LastAssignment}if(i.isPrefixUnaryExpression(s)||i.isPostfixUnaryExpression(s)){const r=s.getOperatorToken();return r===p.PlusPlusToken||r===p.MinusMinusToken}return i.isDeleteExpression(s)?!0:i.isForOfStatement(s)||i.isForInStatement(s)?s.getInitializer()===e:i.isPropertyAssignment(s)?s.getInitializer()===e&&y(s):(i.isShorthandPropertyAssignment(s)||i.isSpreadAssignment(s)||i.isSpreadElement(s)||i.isObjectLiteralExpression(s)||i.isArrayLiteralExpression(s))&&y(s)},re=t=>{const e=t?.getDeclarations().find(n=>i.isVariableDeclaration(n));if(!ie(e))return;const s=e.getParent().getParent();return i.isVariableStatement(s)&&i.isSourceFile(s.getParent())?e.getInitializer():void 0},oe=t=>re(t.getSymbol()),we=t=>{if(!t)return;if(i.isObjectLiteralExpression(t))return t;if(!i.isIdentifier(t))return;const e=oe(t);return e!==void 0&&i.isObjectLiteralExpression(e)?e:void 0},x=t=>{let e=t;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e)||i.isNonNullExpression(e));)e=e.getExpression();return e},ae=(t,e)=>{let s=x(t);for(;i.isAwaitExpression(s)||i.isPropertyAccessExpression(s)||i.isElementAccessExpression(s)||i.isCallExpression(s);){const n=i.isCallExpression(s)?e?.(s):void 0;if(n!==void 0)return{verdict:n};s=x(s.getExpression())}return{root:s}},Oe=t=>ae(t).root,Fe=(t,e)=>t?.compilerNode===e.compilerNode,Ne=t=>{if(i.isPropertyAccessExpression(t))return{member:t.getName(),object:t.getExpression()};const e=i.isElementAccessExpression(t)?t.getArgumentExpression():void 0;return i.isElementAccessExpression(t)&&i.isStringLiteral(e)?{member:e.getLiteralValue(),object:t.getExpression()}:void 0},_e=t=>{const e=t.getParent();return i.isReturnStatement(e)||i.isArrowFunction(e)&&e.getBody()===t?t.getFirstAncestor(n=>i.isFunctionLikeDeclaration(n)||i.isArrowFunction(n)):void 0},Le=t=>{const e=x(t);return e&&i.isCallExpression(e)?e:void 0},Re=t=>{const e=t.getExportAssignment(r=>!r.isExportEquals());if(!e)return;const s=e.getExpression();if(!i.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&i.isVariableDeclaration(n)?n.getInitializer():s},Te=t=>{const e=t.getArguments()[1];return e&&i.isStringLiteral(e)?e.getLiteralValue():""},be=(t,e)=>{if(!i.isObjectLiteralExpression(t))return;const s=S(t,e);if(!s||!i.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&i.isStringLiteral(n)?n.getLiteralText():void 0},ce=t=>{const e=t.getStatements(),[s]=e;if(e.length!==1||s===void 0||!i.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&i.isObjectLiteralExpression(n)?n:void 0},Ie=t=>{if(i.isObjectLiteralExpression(t))return t;if(i.isParenthesizedExpression(t)){const e=t.getExpression();return i.isObjectLiteralExpression(e)?e:void 0}return i.isBlock(t)?ce(t):void 0},Ce=t=>(e,s,n)=>{if(i.isStringLiteral(e)||i.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw M(e,`${t} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)},le=new Set(["api","internal"]),je=new Set(["run","runAction","runMutation","runQuery"]),ue=t=>{if(t===void 0||!i.isPropertyAccessExpression(t))return;const e=[];let s=t;for(;i.isPropertyAccessExpression(s);)e.unshift(s.getName()),s=s.getExpression();return i.isIdentifier(s)&&le.has(s.getText())&&e.length>=2?e:void 0},ke=t=>{const e=ue(t);return e===void 0?void 0:`${e.slice(0,-1).join("_")}:${String(e.at(-1))}`};export{je as RUN_METHODS,X as TS_EXTENSION_RE,ye as bindingKeyName,Oe as chainRootOf,he as collectCallRows,se as collectNodeRows,ve as collectSecurityCallRows,Re as defaultExportExpression,S as findObjectProperty,ke as functionKeyOf,ue as functionReferenceSegments,Pe as handlerOf,ie as isConstDeclaration,Fe as isSameNode,Se as isTestPath,y as isWriteTarget,Te as limitNameOf,T as listLunoraSourceFiles,Z as listSecurityScanFiles,f as lunoraRelativePath,Ne as memberAccessOf,Ie as objectLiteralFromCallbackBody,we as optionsObjectLiteral,ne as outermostValueWrapper,Ae as propertyInitializer,B as propertyKeyName,U as propertyNameText,_e as returningFunctionOf,Ce as stringPropertyFor,be as stringPropertyOf,re as symbolConstInitializer,x as unwrapExpression,Le as unwrapToCallExpression,ae as walkChain};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{basename as b}from"node:path";import{Node as d}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as g}from"./paths-
|
|
1
|
+
import{basename as b}from"node:path";import{Node as d}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as g}from"./paths-DwTjD7BU.mjs";import{listLunoraSourceFiles as $,lunoraRelativePath as v,unwrapToCallExpression as E,defaultExportExpression as S,findObjectProperty as M}from"./isTestPath-CgyyLk8U.mjs";const h=(e,o)=>e.find(t=>t.ownsFolder!==!1&&o.startsWith(`${t.name}/`))?.name,F="module.ts",w=(e,o,t)=>{if(d.isStringLiteral(e)||d.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw c(e,`module "${o}": \`${t}\` must be a static string literal — codegen reads it without running the file`)},L=(e,o,t)=>{if(!d.isArrayLiteralExpression(e))throw c(e,`module "${o}": \`${t}\` must be an inline array of table names`);return e.getElements().map(n=>w(n,o,t))},p=(e,o,t)=>{const n=M(e,o);if(n!==void 0){if(!d.isPropertyAssignment(n))throw c(n,`module "${t}": write \`${o}\` inline as \`${o}: …\` — codegen reads it without running the file`);return n.getInitializerOrThrow()}},A=(e,o,t)=>{const n=e.getSourceFile(o)??e.addSourceFileAtPath(o),s=E(S(n)),a=s?.getExpression();if(!s||!a||!d.isIdentifier(a)||a.getText()!=="defineModule")return;if(t==="")throw c(s,"defineModule: lunora/module.ts would make the whole app one module — move it into the folder it describes (lunora/<module>/module.ts)");const i=s.getArguments()[0],m={name:t,tables:[]};if(i===void 0)return m;if(!d.isObjectLiteralExpression(i))throw c(i,`module "${t}": defineModule must be passed an inline object literal`);const r=p(i,"description",t);r!==void 0&&(m.description=w(r,t,"description"));const l=p(i,"tables",t);return l!==void 0&&(m.tables=L(l,t,"tables")),m},k=(e,o)=>{const t=[];for(const n of $(o)){if(b(n)!==F)continue;const s=v(o,n),a=A(e,n,s==="module"?"":s.slice(0,-7));a&&t.push(a)}return t.toSorted((n,s)=>n.name.localeCompare(s.name))},T=(e,o)=>{const t=new Set(e.map(r=>r.name)),n=new Set(e.flatMap(r=>r.tables)),s=o.tables.filter(r=>r.extensionKey!==void 0&&!n.has(r.name)),a=Map.groupBy(s,r=>String(r.extensionKey)),i=e.map(r=>{const l=a.get(r.name);return l===void 0?r:{...r,tables:[...r.tables,...l.map(u=>u.name)]}}),m=[...a].filter(([r])=>!t.has(r)).map(([r,l])=>{const u=l.every(f=>f.extensionFromPackage===!0);return{installed:!0,name:r,...u?{ownsFolder:!1}:{},tables:l.map(f=>f.name)}});return[...i,...m].toSorted((r,l)=>r.name.localeCompare(l.name))},x=e=>{for(const o of e){const t=e.find(n=>n.name.startsWith(`${o.name}/`));if(t)throw new Error(`@lunora/codegen: module "${t.name}" is nested inside ${o.installed===!0?"installed component":"module"} "${o.name}" — a file can belong to one module only, so move one of the two`)}},y=(e,o)=>{const t=new Set(o.tables.map(s=>s.name)),n=new Map;for(const s of e)for(const a of s.tables){if(!t.has(a))throw new Error(`@lunora/codegen: module "${s.name}" declares table "${a}", which lunora/schema.ts does not define`);const i=n.get(a);if(i!==void 0)throw new Error(`@lunora/codegen: table "${a}" is claimed by both module "${i}" and module "${s.name}" — a table has one owner`);n.set(a,s.name)}},C=(e,o,t)=>{if(e.length===0)return;const n=new Set(o.map(s=>s.name));for(const s of t){const a=g(s);if(h(o,s)===void 0&&n.has(a))throw new Error(`@lunora/codegen: lunora/${s}.ts sits beside module "${a}" and shares its name — move it into lunora/${a}/ or rename one of them`)}},z=(e,o,t)=>{const n=T(e,o);return x(n),y(n,o),C(e,n,t),n},K=(e,o)=>h(e,o)??g(o);export{h as a,k as d,K as m,z as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=/\/index$/u,n=/[^\dA-Za-z]/gu,c=e=>e.replace(a,"").split("/").map(s=>s.replaceAll(n,"_")),t=e=>c(e).join("_");export{c as n,t as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as E}from"./declared-output-Iaar469J.mjs";import{v as u}from"./shared-
|
|
1
|
+
import{d as E}from"./declared-output-Iaar469J.mjs";import{v as u}from"./shared-Be3TGzxM.mjs";const p=/import\("(?<spec>(?:\.\.?\/)*_generated\/[^"]+)"\)/gu,l=/^(?:\.\.?\/)*_generated\//u,i=/\.[A-Za-z]\w*$/u,R=t=>t.replaceAll(p,(e,r)=>{const o=r.replace(l,"./");return`import("${i.test(o)?o:`${o}.js`}")`}),_=/import\("(?<spec>[^"]+)"\)/gu,a="node_modules/",m=/^@types\//u,A=t=>t.replaceAll(_,(e,r)=>{const o=r.lastIndexOf(a);if(o===-1||o>0&&r[o-1]!=="/")return e;const s=r.slice(o+a.length);return s===""||m.test(s)?e:`import("${s}")`}),I=/import\("(?<spec>\.\.?\/[^"]+)"\)/gu,f=/^(?:\.\.?\/)+/u,g=t=>{const e=[];for(const r of t.split("/"))if(!(r===""||r===".")){if(r===".."&&e.length>0&&e.at(-1)!==".."){e.pop();continue}e.push(r)}return e.join("/")},S=(t,e)=>t.replaceAll(I,(r,o)=>{if(l.test(o.replace(f,"")))return r;const s=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"",c=`../${g(`${s}/${o}`)}`;return`import("${i.test(c)?c:`${c}.js`}")`}),v=(t,e)=>R(S(A(t),e)),d=["client","do","errors","flags","observability","platform","ratelimit","runtime","server","values"],L=new RegExp(String.raw`import\("@lunora/(?<pkg>${d.join("|")})(?<subpath>/[^"]*)?"\)`,"gu"),T={flags:new Set(["/web"]),platform:new Set},M=(t,e)=>e?t.replaceAll(L,(r,o,s)=>{const n=T[o];return s&&n&&!n.has(s)?r:`import("lunorash/${o}${s??""}")`}):t,O=t=>["Doc","Id"].filter(e=>new RegExp(String.raw`(?<![.$\w])${e}<`,"u").test(t)),U=t=>E(t)?u(t.output):t.returnType;export{O as a,M as b,U as c,v as r};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CAPABILITIES as Re}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{p as Se}from"./ir-DBSvhNa-.mjs";import{join as q,relative as m,dirname as Q,isAbsolute as De,sep as Me}from"node:path";import{ts as i,Project as Ce}from"ts-morph";import{G as Z,a as $,u as Ne,d as Ae}from"./shared-
|
|
1
|
+
import{CAPABILITIES as Re}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{p as Se}from"./ir-DBSvhNa-.mjs";import{join as q,relative as m,dirname as Q,isAbsolute as De,sep as Me}from"node:path";import{ts as i,Project as Ce}from"ts-morph";import{G as Z,a as $,u as Ne,d as Ae}from"./shared-Be3TGzxM.mjs";const ee=/(?:\.d)?\.([cm]?)tsx?$/u,Fe=t=>t.replace(ee,".d.$1ts"),te=(t,n)=>{const a=m(t,n).split(Me).join("/").replace(ee,".$1js");return a.startsWith(".")?a:`./${a}`},ae=t=>t.replaceAll("\\","/"),E=(t,n,a)=>ae(q(t,Fe(m(n,a)))),Pe=t=>te(".",q("services",t.name,m(Q(t.wranglerPath),t.main))),We=t=>{const n=[],a=r=>{(i.isImportDeclaration(r)||i.isExportDeclaration(r))&&r.moduleSpecifier!==void 0&&i.isStringLiteral(r.moduleSpecifier)?n.push(r.moduleSpecifier):i.isImportTypeNode(r)&&i.isLiteralTypeNode(r.argument)&&i.isStringLiteral(r.argument.literal)&&n.push(r.argument.literal),i.forEachChild(r,a)};return a(t),n},Ge=(t,n)=>{const a=Q(t.wranglerPath),r=m(a,t.main);if(r.startsWith("..")||De(r))throw new Error(`@lunora/codegen: service "${t.name}": its entry module (${t.main}) must be inside ${a} to be typed as RPC`);const d=q(n,"services",t.name),c=i.findConfigFile(a,o=>i.sys.fileExists(o)),p=new Ce({compilerOptions:{composite:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,incremental:!1,noEmit:!1,noEmitOnError:!1,outDir:d,rootDir:a},skipAddingFilesFromTsConfig:!0,...c===void 0?{}:{tsConfigFilePath:c}});p.addSourceFileAtPath(t.main),p.resolveSourceFileDependencies();const u={...p.getCompilerOptions(),preserveSymlinks:!0},x=new Map(p.getSourceFiles().map(o=>o.getFilePath()).filter(o=>!o.endsWith(".d.ts")&&!m(a,o).startsWith("..")).map(o=>[E(d,a,o),o])),y={};for(const o of p.emitToMemory({emitOnlyDtsFiles:!0}).getFiles()){const g=x.get(ae(o.filePath));if(g===void 0)continue;const h=i.createSourceFile(o.filePath,o.text,i.ScriptTarget.Latest,!1);let{text:f}=o;for(const b of We(h).toReversed()){const s=i.resolveModuleName(b.text,g,u,i.sys).resolvedModule?.resolvedFileName;if(s===void 0)continue;const T=E(d,a,s),v=x.has(T)?T:s;f=`${f.slice(0,b.getStart(h))}${JSON.stringify(te(Q(o.filePath),v))}${f.slice(b.getEnd())}`}y[m(n,o.filePath)]=`${Z}${f}`}if(y[m(n,E(d,a,t.main))]===void 0)throw new Error(`@lunora/codegen: service "${t.name}": TypeScript emitted no declaration for its entry module ${t.main}`);return y},je=(t,n=[])=>{const a=new Set;for(const r of t.tables)for(const d of Object.values(r.shape)){const c=Ne(d);c.kind==="storage"&&typeof c.bucket=="string"&&c.bucket!==""&&a.add(c.bucket)}for(const r of n)r!==""&&r!=="default"&&a.add(r);return["default",...[...a].toSorted((r,d)=>r.localeCompare(d))]},He=({agents:t=[],capabilities:n=new Set,containers:a=[],env:r,hasVectors:d=!0,hasFlags:c=!1,hasNotify:p=!1,identity:u,queues:x=[],schema:y,services:o=[],storageRuleBuckets:g=[],topics:h=[],useUmbrella:f=!1,workflows:b=[]}={})=>{const s=Ae(f),T=je(y??{tables:[]},g).map(e=>JSON.stringify(e)).join(" | "),v=e=>e.sandbox===!0?"SandboxContainerAccessor":"ContainerAccessor",re=[...new Set(a.map(e=>v(e)))].toSorted((e,l)=>e.localeCompare(l)),oe=a.length>0?`import type { ${re.join(", ")} } from "@lunora/container";
|
|
2
2
|
`:"",ne=a.length>0?`
|
|
3
3
|
readonly containers: {${a.map(e=>`
|
|
4
4
|
readonly ${e.exportName}: ${v(e)};`).join("")}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as vt}from"@lunora/errors";import{serializeSchemaSnapshot as kt,hashSchemaSnapshot as St}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{isHyperdriveGlobalTable as Rt,isD1GlobalTable as xt}from"./isD1GlobalTable-udvHAAzD.mjs";import{p as At,i as Dt}from"./ir-DBSvhNa-.mjs";import{r as h}from"./json-data-Chfs2Cz5.mjs";import{r as C,e as Tt,a as Ot,b as Et,c as Ct,d as Lt,f as It,g as _t,h as Mt,i as Pt,j as qt,k as Nt,l as $t,m as Ft,n as Ut,o as Bt,p as Wt,q as jt}from"./shard-runtime-
|
|
1
|
+
import{LunoraError as vt}from"@lunora/errors";import{serializeSchemaSnapshot as kt,hashSchemaSnapshot as St}from"./SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs";import{isHyperdriveGlobalTable as Rt,isD1GlobalTable as xt}from"./isD1GlobalTable-udvHAAzD.mjs";import{p as At,i as Dt}from"./ir-DBSvhNa-.mjs";import{r as h}from"./json-data-Chfs2Cz5.mjs";import{r as C,e as Tt,a as Ot,b as Et,c as Ct,d as Lt,f as It,g as _t,h as Mt,i as Pt,j as qt,k as Nt,l as $t,m as Ft,n as Ut,o as Bt,p as Wt,q as jt}from"./shard-runtime-BI2SZ54Z.mjs";import{u as K,i as Ht,G as Vt,d as Kt}from"./shared-Be3TGzxM.mjs";const Gt=` /**
|
|
2
2
|
* The bare writer every admin/maintenance entry point writes through.
|
|
3
3
|
*
|
|
4
4
|
* Admin and maintenance writes go through the SAME reactive-cache hooks as a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s as b}from"./ir-DBSvhNa-.mjs";import{r as y}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as $}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{a as u,G as p}from"./shared-
|
|
1
|
+
import{s as b}from"./ir-DBSvhNa-.mjs";import{r as y}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as $}from"./CAPABILITY_PROBES-brcmKenl.mjs";import{a as u,G as p}from"./shared-Be3TGzxM.mjs";const I=e=>e?{importFragment:"serveRelationFanout, ",override:`
|
|
2
2
|
protected override async runRelationFanoutRead(functionPath: string, args: Record<string, unknown>): Promise<unknown> {
|
|
3
3
|
this.ensureMigrated();
|
|
4
4
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{LunoraError as y}from"@lunora/errors";import{n as E}from"./paths-DwTjD7BU.mjs";import{R}from"./reserved-words-CW1QFbTd.mjs";import{acceptsAbsentIr as A}from"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";const S=/^(?:"(?:[^"\\]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"|'[^'\\]*'|-?\d+(?:\.\d+)?|true|false|null)$/u,M=`// GENERATED by @lunora/codegen — do not edit.
|
|
2
|
+
// Run \`lunora codegen\` to regenerate.
|
|
3
|
+
|
|
4
|
+
`,K=(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,B=/^[\w./-]+$/u,w=(e,n)=>{if(!b.test(e)||R.has(e))throw new y("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},F=(e,n)=>{if(!b.test(e))throw new y("INTERNAL",`@lunora/codegen: ${n} is not a valid JS identifier: ${JSON.stringify(e)}`)},G=e=>e.charAt(0).toUpperCase()+e.slice(1),g=e=>b.test(e)?e:JSON.stringify(e),k=e=>e==="__proto__"?`[${JSON.stringify(e)}]`:g(e),O=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))},U=(e,n,r)=>{const[t,l]=r==="type"?[g,";"]:[k,","],d={children:new Map};for(const[o,$]of O(e)){let a=d;for(const f of E(o)){let c=a.children.get(f);c===void 0&&(c={children:new Map},a.children.set(f,c)),a=c}a.file={entries:$,path:o}}const u=o=>o.file?.path??u(o.children.values().next().value),p=(o,$)=>{const a=" ".repeat($),{entries:f=[],path:c=""}=o.file??{},h=f.find(s=>o.children.has(s.exportName));if(h!==void 0){const s=u(o.children.get(h.exportName));throw new y("NAMESPACE_COLLISION",`Namespace collision: the export "${h.exportName}" of "${c}" and "${s}" both resolve to api.${[...E(c),h.exportName].join(".")}. Rename the export or the folder.`)}const _=f.toSorted((s,m)=>s.exportName.localeCompare(m.exportName)).map(s=>`${a}${n(s)}`),I=[...o.children.entries()].toSorted(([s],[m])=>s.localeCompare(m)).map(([s,m])=>`${a}${t(s)}: {
|
|
5
|
+
${p(m,$+1).join(`
|
|
6
|
+
`)}
|
|
7
|
+
${a}}${l}`);return[..._,...I]};return p(d,1).join(`
|
|
8
|
+
`)},j={any:"unknown",bigint:"bigint",boolean:"boolean",bytes:"ArrayBuffer",date:"number",geoPoint:"{ lat: number; lng: number }",null:"null",number:"number",storage:"string",string:"string",timestamp:"number"},D=e=>{if(e===void 0)return"unknown";if(!S.test(e))throw new y("INTERNAL",`@lunora/codegen: v.literal() argument is not a parseable string/number/boolean/null literal: ${JSON.stringify(e)}`);return e},i=e=>e.column?.notNull===!1?`${T(e)} | null`:T(e),T=e=>{const n=j[e.kind];if(n!==void 0)return n;switch(e.kind){case"array":return`Array<${e.inner?i(e.inner):"unknown"}>`;case"from":return e.tsType??"unknown";case"id":{const r=e.tableName??"_unknown_";return w(r,"v.id() table name"),`Id<"${r}">`}case"literal":return D(e.literalValue);case"object":return e.shape?`{ ${Object.entries(e.shape).map(([t,l])=>N(t,l)).join("; ")} }`:"Record<string, unknown>";case"optional":return`${e.inner?i(e.inner):"unknown"} | undefined`;case"record":{const r=e.keyType?i(e.keyType):"string",t=e.valueType?i(e.valueType):"unknown";return`Record<${r}, ${t}>`}case"union":return e.members&&e.members.length>0?e.members.map(r=>i(r)).join(" | "):"never";default:return"unknown"}},N=(e,n)=>{const r=g(e);if(n.kind==="optional"){const t=n.inner?i(n.inner):"unknown";return`${r}?: ${t}`}return A(n)?`${r}?: ${i(n)}`:`${r}: ${i(n)}`},V=e=>{const n=Object.entries(e);return n.length===0?"{}":`{ ${n.map(([r,t])=>N(r,t)).join("; ")} }`},x=e=>e.kind==="optional"||!!e.column?.hasDefault,L=e=>e.kind==="optional"&&e.inner?e.inner:e,v=e=>{w(e.name,"table name");const n=Object.entries(e.shape).map(([t,l])=>{const d=L(l),u=i(d),p=g(t);return x(l)?` ${p}?: ${u};`:` ${p}: ${u};`}).join(`
|
|
9
|
+
`),r=n?`
|
|
10
|
+
${n}
|
|
11
|
+
`:"";return`export interface Insert_${e.name} {
|
|
12
|
+
_id?: Id<"${e.name}">;
|
|
13
|
+
_creationTime?: number;${r}}`};export{M as G,B as I,S as L,w as a,U as b,k as c,K as d,g as e,v as f,F as g,x as i,G as p,V as r,L as u,i as v};
|
package/dist/packem_shared/{unwrap-handler-return-Dy8h5-I6.mjs → unwrap-handler-return-T5sJhEss.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./isTestPath-DCyIyPa7.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
|
|
1
|
+
import{Node as l,SyntaxKind as g}from"ts-morph";import{lunoraRelativePath as L}from"./isTestPath-CgyyLk8U.mjs";import{posix as D}from"node:path";let S,v;const Ae=e=>{const t=S,n=[];S=n;try{return{erased:n,value:e()}}finally{S=t}},Te=e=>{S?.push(...e)},j=e=>{for(const t of e.getAncestors())if(l.isVariableDeclaration(t))return t.getName()},w=(e,t)=>{S?.push({exportName:j(e),filePath:e.getSourceFile().getFilePath(),line:e.getStartLineNumber(),rendered:t})},Ne=e=>{v!==void 0&&w(v,e)},xe=(e,t)=>{const n=v;v=e;try{return t()}finally{v=n}},k=(e,t)=>{const n=e.exportName??`line ${e.line.toString()}`;return{cacheKey:`procedure_return_type_erased:${t}:${n}`,categories:["SCHEMA"],description:"Codegen renders a procedure's return type into `_generated/`, where only names that resolve from that directory may appear. A type it can neither name nor reproduce structurally — a class instance, a call or index signature, a recursive or very deeply nested shape — is emitted as `unknown` instead, so callers lose the shape while the runtime still returns it.",detail:`\`${n}\` in \`${t}\` (line ${e.line.toString()}) returns \`${e.rendered}\`, which codegen could not reproduce — its generated type is \`unknown\`.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:e.exportName,filePath:t,line:e.line,rendered:e.rendered},name:"procedure_return_type_erased",remediation:"Declare the shape explicitly with `.output(...)`, or export the type from the module that declares it so codegen can name it. A class instance cannot cross the wire at all — return a plain object.",title:"Procedure return type is missing from the generated type"}},De=(e,t)=>{const n=new Map;for(const r of e){const s=k(r,L(t,r.filePath));n.set(s.cacheKey,s)}return[...n.values()].toSorted((r,s)=>r.cacheKey.localeCompare(s.cacheKey))},P=/\bany\b(?!\s*(?:\?\s*)?:)/u,U=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,O=e=>P.test(e.replaceAll(U,"")),K="/_generated/",B=e=>{const t=[e.getSymbol(),e.getAliasSymbol()].flatMap(n=>n?.getDeclarations()??[]);return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},F=/^(?<quote>["'])(?<specifier>.*)\k<quote>$/su,T=e=>{for(const t of e.getAncestors())if(l.isModuleDeclaration(t)){const n=F.exec(t.getName());if(n?.groups?.specifier!==void 0)return n.groups.specifier}},h=new WeakMap,V=(e,t)=>{const n=e.getSymbol();if(n===void 0)return;let r=h.get(n.compilerSymbol);return r===void 0&&(r=new Map,h.set(n.compilerSymbol,r)),r.has(t)||r.set(t,n.getExport(t)??e.getExportSymbols().find(s=>s.getName()===t)),r.get(t)},_=(e,t)=>e.getNamespaceImport()!==void 0||e.getNamedImports().some(n=>n.getName()===t),W=(e,t,n)=>e.getModuleSpecifierValue()===t&&_(e,n)?n:void 0,q=(e,t)=>{const n=e.getDefaultImport();if(n===void 0)return;const r=n.getSymbol();return(r?.getAliasedSymbol()??r)?.getDeclarations().includes(t)===!0?"default":void 0},G=(e,t,n)=>{if(!_(e,n))return;const r=e.getModuleSpecifierSourceFile(),s=r===void 0?void 0:V(r,n);return(s?.getAliasedSymbol()??s)?.getDeclarations().includes(t)===!0?n:void 0},X=/^\.\.?(?:$|\/)/u,H=new Map([[".cjs",".cjs"],[".cts",".cjs"],[".d.ts",".js"],[".js",".js"],[".jsx",".jsx"],[".mjs",".mjs"],[".mts",".mjs"],[".ts",".js"],[".tsx",".js"]]),Y=(e,t)=>{const n=t.getModuleSpecifierValue();if(!X.test(n))return;const r=t.getModuleSpecifierSourceFile(),s=r===void 0?void 0:H.get(r.getExtension());if(r===void 0||s===void 0)return;const i=`${D.join(r.getDirectoryPath(),r.getBaseNameWithoutExtension())}${s}`,o=D.relative(e.getDirectoryPath(),i);return o.startsWith(".")?o:`./${o}`},J=(e,t,n)=>{const r=T(t);for(const s of e.getImportDeclarations()){const i=r===void 0?q(s,t)??G(s,t,n):W(s,r,n);if(i!==void 0)return{exportName:i,specifier:Y(e,s)??s.getModuleSpecifierValue()}}},z=(e,t)=>Object.keys(t.getProject().getCompilerOptions().paths??{}).some(n=>{const r=n.indexOf("*");return r===-1?e===n:e.startsWith(n.slice(0,r))&&e.endsWith(n.slice(r+1))}),m={kind:"verbatim"},p={kind:"expand"},Q=new Set([g.ClassDeclaration,g.EnumDeclaration,g.EnumMember,g.InterfaceDeclaration,g.TypeAliasDeclaration]),Z=e=>T(e)!==void 0||l.isExportable(e)&&e.isExported(),ee=(e,t)=>new RegExp(String.raw`(?<![$\w])${t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`)}(?![$\w])`,"u").test(e),M=(e,t,n,r)=>{const s=e.getSourceFile();if(s.getSymbol()===void 0&&T(e)===void 0||!Q.has(e.getKind()))return m;const i=s.getFilePath();if(i.includes(K))return m;if(i===n)return p;const o=l.isEnumMember(e)?e.getParent():e;if(!l.hasName(o))return p;const a=J(t.getSourceFile(),o,o.getName());return a===void 0?Z(o)||!ee(r(),o.getName())?m:p:z(a.specifier,t)?p:{kind:"qualify",qualified:a}},te=new Set([g.ClassDeclaration,g.EnumDeclaration,g.FunctionDeclaration,g.ModuleDeclaration]),I=e=>{const t=e?.getDeclarations()??[];return t.length>0&&t.every(n=>n.getSourceFile().getSymbol()===void 0)},ne=e=>{for(const t of e.getDeclarations()){const n=t.getFirstChildByKind(g.ComputedPropertyName);if(n!==void 0){let r=n.getExpression();for(;l.isPropertyAccessExpression(r);)r=r.getExpression();return r}}},re=(e,t)=>{if(e.getProperties().some(s=>{if(!s.getName().startsWith("__@"))return!1;const i=ne(s);return i===void 0||!I(i.getSymbol())}))return!0;const r=e.getSymbol();return r!==void 0&&r.getDeclarations().some(s=>te.has(s.getKind()))&&!I(r)&&t().startsWith("typeof ")},R=(e,t,n)=>{const r=e.getAliasSymbol(),s=e.getSymbol(),i=new Set((r??s)?.getDeclarations());let o=!1,a;const c=()=>(a??=e.getText(t),a);for(const u of[s,r].flatMap(d=>d?.getDeclarations()??[])){const d=M(u,t,n,c);if(d.kind==="qualify"&&i.has(u))return d;o||=d.kind!=="verbatim"}return o||re(e,c)?p:m},se=(e,t,n)=>{const r=l.isPropertySignature(e)||l.isPropertyDeclaration(e)?e.getTypeNode():void 0;if(r===void 0)return m;let s=!1;for(const i of[r,...r.getDescendantsOfKind(g.TypeReference)].filter(o=>l.isTypeReference(o))){const o=i.getTypeName().getSymbol();for(const a of(o?.getAliasedSymbol()??o)?.getDeclarations()??[]){const c=M(a,t,n,()=>i.getText());if(c.kind==="qualify")return c;s||=c.kind!=="verbatim"}}return s?p:m},oe=/^[A-Za-z_$][\w$]*$/u,ie=e=>oe.test(e)?e:JSON.stringify(e),$=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},y=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0&&!e.getProperties().some(t=>t.getName().startsWith("__@")),E=(e,t,n,r=new Set)=>r.has(e)?!1:(r.add(e),R(e,t,n).kind!=="verbatim"||$(e).some(s=>E(s,t,n,r))?!0:y(e)?e.getProperties().some(s=>s.getDeclarations().some(i=>se(i,t,n).kind!=="verbatim")?!0:E(s.getTypeAtLocation(t),t,n,r)):!1),ae=(e,t)=>{const n=e.getValueDeclaration()??e.getDeclarations()[0];return n&&(l.isPropertySignature(n)||l.isPropertyDeclaration(n))&&n.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},C=(e,t)=>e!==void 0&&(y(e)||e.isString()||e.isNumber()||e.isBigInt()||e.isBoolean()||e.isLiteral()||e.isBooleanLiteral()||e.isEnumLiteral()||e.isTemplateLiteral()||e.isNull()||e.isUndefined()||e.isAny()||e.isUnknown()||e.isNever()||e.isVoid())?t:`(${t})`,ce=32,ue=8,le=(e,t,n,r,s,i)=>{const o=e.getArrayElementType(),a=o?i(o,t,n,r,s):void 0;if(a!==void 0)return`${C(o,a)}[]`},ge=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getUnionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(c)}return o.join(" | ")},de=(e,t,n,r,s,i)=>{const o=[];for(const a of e.getIntersectionTypes()){const c=i(a,t,n,r,s);if(c===void 0)return;o.push(C(a,c))}return o.join(" & ")},me=(e,t,n,r,s,i)=>{if(!y(e))return;const o=[];for(const a of e.getProperties()){const c=a.getTypeAtLocation(t),u=ae(a,c),d=u&&c.isUnion()?c.getUnionTypes().filter(A=>!A.isUndefined()):[c],N=[];for(const A of d){const x=i(A,t,n,r+1,s);if(x===void 0)return;N.push(x)}o.push(`${ie(a.getName())}${u?"?":""}: ${N.join(" | ")}`)}return o.length>0?`{ ${o.join("; ")} }`:"{}"},fe=e=>{const t=e.getLiteralValue();return typeof t=="string"?JSON.stringify(t):typeof t=="number"?String(t):void 0},pe=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isClassDeclaration(t)||l.isClassExpression(t)),b=(e,t,n,r,s=new Set)=>{if(r.has(e)||s.has(e))return!1;if(n>ce)return!0;const i=new Set(r).add(e);if($(e).some(u=>b(u,t,n+1,i,s)))return!0;const o=e.getArrayElementType();if(o!==void 0)return b(o,t,n+1,i,s);if(B(e))return s.add(e),!1;if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0||[e.getSymbol(),e.getAliasSymbol()].flatMap(u=>u?.getDeclarations()??[]).some(u=>l.isClassDeclaration(u)||l.isClassExpression(u)))return!0;const c=y(e)&&e.getProperties().some(u=>b(u.getTypeAtLocation(t),t,n+1,i,s));return c||s.add(e),c},Se=(e,t,n,r,s,i,o)=>{const a=[];for(const c of t.getAliasSymbol()===void 0?t.getTypeArguments():t.getAliasTypeArguments()){const u=o(c,n,r,s+1,i);if(u===void 0)return;a.push(u)}return`import("${e.specifier}").${e.exportName}${a.length>0?`<${a.join(", ")}>`:""}`},ve=e=>[e.getSymbol(),e.getAliasSymbol()].flatMap(t=>t?.getDeclarations()??[]).some(t=>l.isEnumDeclaration(t)||l.isEnumMember(t)),f=(e,t,n,r,s)=>{if(r>ue||s.has(e))return;const i=R(e,t,n);if(i.kind==="verbatim"&&!E(e,t,n))return e.getText(t);const o=new Set(s).add(e);if(!pe(e)){if(e.isEnumLiteral())return fe(e);if(i.kind==="qualify"&&!ve(e)){const a=Se(i.qualified,e,t,n,r,o,f);if(a!==void 0)return a}return e.isArray()?le(e,t,n,r,o,f):e.isUnion()?ge(e,t,n,r,o,f):e.isIntersection()?de(e,t,n,r,o,f):me(e,t,n,r,o,f)}},he=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let n=t.getReturnType();const s=(n.getSymbol()??n.getAliasSymbol())?.getName();if(s==="Promise"||s==="AsyncIterable"||s==="AsyncIterableIterator"||s==="AsyncGenerator"){const a=n.getTypeArguments()[0];a&&(n=a)}const i=n.getText(e);if(!i||i==="any"||i==="never"||O(i)||b(n,e,0,new Set))return"unknown";const o=e.getSourceFile().getFilePath();if(E(n,e,o)){const a=f(n,e,o,0,new Set);return a===void 0&&w(e,i),a??"unknown"}return i};export{E as a,Ne as b,Ae as c,De as d,f as e,O as i,xe as p,Te as r,he as u};
|
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.275",
|
|
4
4
|
"description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
50
|
-
"@lunora/agent": "1.0.0-alpha.
|
|
49
|
+
"@lunora/advisor": "1.0.0-alpha.198",
|
|
50
|
+
"@lunora/agent": "1.0.0-alpha.186",
|
|
51
51
|
"@lunora/container": "1.0.0-alpha.69",
|
|
52
52
|
"@lunora/errors": "1.0.0-alpha.50",
|
|
53
53
|
"@lunora/platform": "1.0.0-alpha.57",
|
|
54
54
|
"@lunora/queue": "1.0.0-alpha.94",
|
|
55
|
-
"@lunora/scheduler": "1.0.0-alpha.
|
|
55
|
+
"@lunora/scheduler": "1.0.0-alpha.113",
|
|
56
56
|
"@lunora/values": "1.0.0-alpha.60",
|
|
57
57
|
"@lunora/workflow": "1.0.0-alpha.71",
|
|
58
58
|
"@visulima/fs": "6.0.28",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{G as t,I as i,a as n,f as p,d as o,i as d,p as I,r as f,e as y,c as E,b as T,u as c,v as O}from"./shared-BXUKWh7t.mjs";import"./reserved-words-CW1QFbTd.mjs";import"./LUNORA_ERROR_CODES-C2s0xWQD.mjs";export{t as GENERATED_HEADER,i as IMPORT_PATH_RE,n as assertIdentifier,p as assertPropertyIdentifier,o as baseSpecifiers,d as isOptionalOnInsert,I as pascalCase,f as renderArgsType,y as renderInsertInterface,E as renderObjectKey,T as renderPropertyKey,c as unwrapOptional,O as validatorToType};
|