@lunora/codegen 1.0.0-alpha.319 → 1.0.0-alpha.320
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 +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-CjbDYC2a.mjs → NOTIFY_FILENAME-bAt7J3cs.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Bo67h-3B.mjs +11 -0
- package/dist/packem_shared/chain-Cm6BMT8g.mjs +1 -0
- package/dist/packem_shared/classify-procedure-call-DVxdUhZt.mjs +1 -0
- package/dist/packem_shared/{context-property-calls-Bw8u2Pz4.mjs → context-property-calls-Cn3upNgZ.mjs} +1 -1
- package/dist/packem_shared/{context-root-YkWLB6M2.mjs → context-root-BdxINX-T.mjs} +1 -1
- package/dist/packem_shared/{database-calls-BnVUlTx_.mjs → database-calls-BKozZUEW.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-CZgLhsMn.mjs +1 -0
- package/dist/packem_shared/discoverHyperdriveCalls-DV4IglLE.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-DUbjhNzk.mjs → discoverInserts-BjxXCACZ.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-DE-8CDen.mjs +1 -0
- package/dist/packem_shared/{discoverNondeterministicCalls-D7Ovq8ae.mjs → discoverNondeterministicCalls-DvhyKM-f.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-BNqjOBY_.mjs → discoverQueries-C8E7TeRT.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-DVcfMO6-.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-CbdfaVep.mjs → discoverRlsMetadata-QRsWRQbM.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsProcedures-BeLdV5RT.mjs → discoverRlsProcedures-Du7ITNTQ.mjs} +1 -1
- package/dist/packem_shared/{discoverStorageRulesMetadata-BBMy9JVZ.mjs → discoverStorageRulesMetadata-ClzKLdCV.mjs} +1 -1
- package/dist/packem_shared/{emitAgents-DuSp0uSJ.mjs → emitAgents-CR2_X_ov.mjs} +1 -1
- package/dist/packem_shared/emitFunctions-rjyb7h7k.mjs +422 -0
- package/dist/packem_shared/{emitShard-Ddgmq6De.mjs → emitShard-D3Po46nf.mjs} +1 -1
- package/dist/packem_shared/{exported-procedure-chains-DAl7xBBx.mjs → exported-procedure-chains-BNBUkXui.mjs} +1 -1
- package/dist/packem_shared/{index-DvmKcoFV.mjs → index-JnqBWRYO.mjs} +1 -1
- package/dist/packem_shared/{shard-DYYhXxEG.mjs → shard-CsOnD3Na.mjs} +226 -117
- package/dist/packem_shared/{shard-runtime-BQ6ZNigW.mjs → shard-runtime-BpoCV-aM.mjs} +13 -8
- package/package.json +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DwqkR6hn.mjs +0 -11
- package/dist/packem_shared/chain-CubC5VoS.mjs +0 -1
- package/dist/packem_shared/classify-procedure-call-CcgP-9I0.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-5Zy6K4uA.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-DFbp-ILH.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-BfVFPpAJ.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-TNwsmYje.mjs +0 -1
- package/dist/packem_shared/emitFunctions-amc10WSc.mjs +0 -291
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import{LunoraError as Q}from"@lunora/errors";import{L as G,G as z,I as V,d as W,b as A,r as K,c as Y}from"./shared-DnCokNcE.mjs";import{renderAgentFunctionRegistry as X,renderSandboxFunctionRegistry as Z}from"./emitApi-CDgIPAG2.mjs";import{a as ee,b as te,r as _,c as ne}from"./qualifiers-DEdXn5wP.mjs";import{s as g}from"./dispatch-namespace-DwTjD7BU.mjs";const re=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),L=n=>n.column!==void 0,oe=(n,e)=>{switch(n){case"bigint":return`if (typeof ${e} !== "bigint") return DEFER;
|
|
2
|
-
`;case"boolean":return`if (typeof ${e} !== "boolean") return DEFER;
|
|
3
|
-
`;case"date":case"number":case"timestamp":return`if (typeof ${e} !== "number" || !Number.isFinite(${e})) return DEFER;
|
|
4
|
-
`;case"null":return`if (${e} !== null) return DEFER;
|
|
5
|
-
`;default:return`if (typeof ${e} !== "string") return DEFER;
|
|
6
|
-
`}},se=(n,e)=>n.stringMaxLength===void 0?"":`if (${e}.length > ${String(n.stringMaxLength)}) return DEFER;
|
|
7
|
-
`,ae=(n,e)=>{const r=n.literalValue?.trim();if(!(r===void 0||!G.test(r)))return{out:e,pre:`if (${e} !== ${r}) return DEFER;
|
|
8
|
-
`}},N=(n,e,r)=>{if(!L(n)&&!(n.unmodelledRefinement||n.sourceText!==void 0)){if(re.has(n.kind))return n.kind==="any"?{out:e,pre:""}:{out:e,pre:oe(n.kind,e)+se(n,e)};switch(n.kind){case"array":return ie(n,e,r);case"literal":return ae(n,e);case"object":return ue(n,e,r);default:return}}},ie=(n,e,r)=>{const{inner:o}=n;if(!o)return;const s=r.next(),a=`__arr${String(s)}`,i=`__i${String(s)}`,c=`__e${String(s)}`,u=N(o,c,r);if(!u)return;const l=`if (!Array.isArray(${e})) return DEFER;
|
|
9
|
-
const ${a} = new Array(${e}.length);
|
|
10
|
-
for (let ${i} = 0; ${i} < ${e}.length; ${i}++) {
|
|
11
|
-
const ${c} = ${e}[${i}];
|
|
12
|
-
${u.pre}${a}[${i}] = ${u.out};
|
|
13
|
-
}
|
|
14
|
-
`;return{out:a,pre:l}},ce=(n,e,r,o)=>{const s=JSON.stringify(n);if(e.kind==="optional"){if(e.hasRefinement||e.sourceText!==void 0||L(e))return;const{inner:i}=e;if(!i)return;const c=N(i,r,o);if(!c)return;const u=o.next(),l=`__has${String(u)}`,h=`__val${String(u)}`,f=`let ${l} = false;
|
|
15
|
-
let ${h};
|
|
16
|
-
if (${r} !== undefined) {
|
|
17
|
-
${c.pre}${h} = ${c.out};
|
|
18
|
-
${l} = true;
|
|
19
|
-
}
|
|
20
|
-
`;return{entry:`...(${l} ? { ${s}: ${h} } : {})`,pre:f}}const a=N(e,r,o);if(a)return{entry:`${s}: ${a.out}`,pre:a.pre}},le=new Set(Object.getOwnPropertyNames(Object.prototype)),P=(n,e,r)=>{let o="";const s=[];for(const a of Object.keys(n)){const i=n[a];if(!i)return;const c=JSON.stringify(a);let u=`${e}[${c}]`;if(le.has(a)){const h=`__f${String(r.next())}`;o+=`const ${h} = Object.hasOwn(${e}, ${c}) ? ${e}[${c}] : undefined;
|
|
21
|
-
`,u=h}const l=ce(a,i,u,r);if(!l)return;o+=l.pre,s.push(l.entry)}return{entries:s.join(", "),pre:o}},M=n=>{const e=`Object.getPrototypeOf(${n})`;return`if (${e} !== Object.prototype && ${e} !== null) return DEFER;
|
|
22
|
-
`},ue=(n,e,r)=>{const o=n.shape??{},s=P(o,e,r);if(!s)return;const a=r.next(),i=`__obj${String(a)}`,c=`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) return DEFER;
|
|
23
|
-
${M(e)}${s.pre}const ${i} = { ${s.entries} };
|
|
24
|
-
`;return{out:i,pre:c}},de=n=>{let e=0;const o=P(n,"source",{next:()=>(e+=1,e)});if(o)return`(source) => {
|
|
25
|
-
if (typeof source !== "object" || source === null || Array.isArray(source)) return DEFER;
|
|
26
|
-
${M("source")}${o.pre}return { ${o.entries} };
|
|
27
|
-
}`},he=(n,e)=>`lunora_${g(n)}_${String(e)}`,me=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
|
|
28
|
-
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
29
|
-
|
|
30
|
-
if (!registered) {
|
|
31
|
-
throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// A mutation is routed through the caller's own \`ctx.runMutation\` rather than
|
|
35
|
-
// invoked directly, so \`createCaller(ctx).ns.someMutation()\` gets exactly what
|
|
36
|
-
// \`ctx.runMutation(api.ns.someMutation)\` gets: the BEGIN/COMMIT span (or the
|
|
37
|
-
// enclosing one, when the caller is already inside a transaction), the jobs it
|
|
38
|
-
// schedules held until that span commits, and the deferred object deletes
|
|
39
|
-
// flushed only once it has. Called straight, a mutation composed from an action
|
|
40
|
-
// or a stream had none of the three — its writes autocommitted one row at a
|
|
41
|
-
// time and its \`ctx.scheduler\` calls dispatched immediately, so a mid-handler
|
|
42
|
-
// throw left the earlier writes durable and the job already enqueued.
|
|
43
|
-
//
|
|
44
|
-
// The fallback covers a context that is not a shard dispatch (\`runMutation\` is
|
|
45
|
-
// installed by \`buildCtx\` on every kind but a query's TYPE omits it); there is
|
|
46
|
-
// no transaction to join in that case, so a direct call is all there is.
|
|
47
|
-
//
|
|
48
|
-
// A query is routed through \`ctx.runQuery\` for the same reason: that is what
|
|
49
|
-
// hands it a query view of a mutation's or action's ctx (no request origin,
|
|
50
|
-
// query-guarded \`run*\`) instead of the caller's own.
|
|
51
|
-
if (registered.kind === "mutation" || registered.kind === "query") {
|
|
52
|
-
const run = (context as { runMutation?: unknown; runQuery?: unknown })[registered.kind === "mutation" ? "runMutation" : "runQuery"];
|
|
53
|
-
|
|
54
|
-
if (typeof run === "function") {
|
|
55
|
-
return (await run.call(context, { __lunoraRef: functionPath }, args ?? {})) as R;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (await registered.handler(context, args ?? {})) as R;
|
|
60
|
-
};`,pe=(n,e,r=[],o=[])=>{const s=new Map,a=t=>{s.has(t)||s.set(t,he(t,s.size))};for(const t of n)a(t.filePath);for(const t of e)a(t.filePath);for(const t of r)a(t.filePath);for(const t of o)a(t.filePath);const i=[...s.entries()].map(([t,p])=>{if(!V.test(t))throw new Q("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(t)}`);return`import * as ${p} from "../${t}.js";`}).join(`
|
|
61
|
-
`),c=n.map(t=>` "${g(t.filePath)}:${t.exportName}": ${s.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
62
|
-
`),u=e.map(t=>` ${JSON.stringify(t.id)}: ${s.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredDataMigration,`).join(`
|
|
63
|
-
`),l=r.map(t=>` "${g(t.filePath)}:${t.exportName}": ${s.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
64
|
-
`),h=o.map(t=>` "${t.exportName}": ${s.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredShape,`).join(`
|
|
65
|
-
`),f=r.map(t=>`${g(t.filePath)}:${t.exportName}`),m=[c,l].filter(t=>t.length>0).join(`
|
|
66
|
-
`),b=n.map(t=>{if(t.lifecycle||Object.keys(t.args).length===0)return;const p=de(t.args);return p===void 0?void 0:`installCompiledValidatorMap(${s.get(t.filePath)??""}.${t.exportName}.args, ${p});`}).filter(t=>t!==void 0).join(`
|
|
67
|
-
`),R=n.filter(t=>t.channel?.kind==="room").map(t=>` ${JSON.stringify(t.channel?.name??"")}: RoomMessageOf<typeof ${s.get(t.filePath)??""}[${JSON.stringify(t.exportName)}]>;`).join(`
|
|
68
|
-
`);return{dispatchBody:m.length>0?`
|
|
69
|
-
${m}
|
|
70
|
-
`:"",importBlock:i.length>0?`${i}
|
|
71
|
-
|
|
72
|
-
`:"",installBlock:b,migrationBody:u.length>0?`
|
|
73
|
-
${u}
|
|
74
|
-
`:"",mutatorPaths:f,roomMessagesBody:R,shapeBody:h.length>0?`
|
|
75
|
-
${h}
|
|
76
|
-
`:""}},ge=n=>{const e=A(n,o=>{const s=_(K(o.args),o.filePath),a=s==="{}"?"?":"",i=_(ne(o),o.filePath);return o.kind==="stream"?`${o.exportName}: (args${a}: ${s}) => Promise<AsyncIterable<${i}>>;`:`${o.exportName}: (args${a}: ${s}) => Promise<${i}>;`},"type");return{implementation:A(n,o=>`${Y(o.exportName)}: (args) => callRegistered(context, "${g(o.filePath)}:${o.exportName}", args),`,"value"),types:e}},fe=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},ye=(n,e,r)=>n?{channelField:` /**
|
|
77
|
-
* Set on a \`defineRoom\` registration: the room's name (without the \`room:\`
|
|
78
|
-
* topic prefix). The generated \`LUNORA_ROOMS\` map keys it on the room's
|
|
79
|
-
* \`room:<name>\` whisper topic so the ShardDO resolves a room topic to this
|
|
80
|
-
* path.
|
|
81
|
-
*/
|
|
82
|
-
channel?: { readonly kind: "room"; readonly name: string };
|
|
83
|
-
`,messagesBlock:`
|
|
84
|
-
/**
|
|
85
|
-
* The message type each \`defineRoom\` carries, read off the room's own registration. The generated \`rooms\` references type a client's \`connectRoom\` from it.
|
|
86
|
-
*/
|
|
87
|
-
export type LunoraRoomMessages = {
|
|
88
|
-
${r}
|
|
89
|
-
};
|
|
90
|
-
`,typeImport:`import type { RoomMessageOf } from "${e}";
|
|
91
|
-
`}:{channelField:"",messagesBlock:"",typeImport:""},ve=n=>{const{agents:e=[],functions:r,migrations:o=[],mutators:s=[],shapes:a=[],useUmbrella:i=!1,usesSandbox:c=!1}=n,u=r.length>0,l=W(i),{dispatchBody:h,importBlock:f,installBlock:m,migrationBody:b,mutatorPaths:R,roomMessagesBody:t,shapeBody:p}=pe(r,o,s,a),w=X(e,r),k=Z(c,r),v=[w.lines,k.lines].filter(d=>d.length>0).join(`
|
|
92
|
-
`);let S=h;v.length>0&&(S=h.length>0?`${h.trimEnd()}
|
|
93
|
-
${v}
|
|
94
|
-
`:`
|
|
95
|
-
${v}
|
|
96
|
-
`);const y=fe(r),E=a.length>0?`import type { RegisteredShape } from "${l.server}";
|
|
97
|
-
`:"",x=r.some(d=>d.channel?.kind==="room"),O=ye(x,l.server,t),C=a.length>0?`
|
|
98
|
-
/**
|
|
99
|
-
* Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
|
|
100
|
-
* The generated ShardDO's \`resolveShape\` override looks a shape up by name and
|
|
101
|
-
* evaluates its trusted \`compileWhere(ctx, args)\` to authorize + scope a
|
|
102
|
-
* \`shape_subscribe\` (reads-as-permissions).
|
|
103
|
-
*/
|
|
104
|
-
export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${p}};
|
|
105
|
-
`:"",F=R.length>0?`
|
|
106
|
-
/**
|
|
107
|
-
* Custom-mutator function paths — the \`LUNORA_FUNCTIONS\` keys the generated
|
|
108
|
-
* ShardDO's \`isCustomMutator\` override routes through the client-watermark push
|
|
109
|
-
* protocol (\`x-lunora-client-id\`/\`x-lunora-client-seq\` ordering).
|
|
110
|
-
*/
|
|
111
|
-
export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${R.map(d=>JSON.stringify(d)).join(", ")}]);
|
|
112
|
-
`:"",j=x?`
|
|
113
|
-
/**
|
|
114
|
-
* Room registry: the whisper topic of each \`defineRoom\` registration → its
|
|
115
|
-
* function path. The generated ShardDO's \`roomHandlerPath\` override resolves a
|
|
116
|
-
* room topic through this map so a room's typed \`onJoin\`/\`onMessage\`/\`onLeave\`
|
|
117
|
-
* dispatch server-side, reusing the whisper channel for membership and fan-out.
|
|
118
|
-
* Two registrations under one name throw at module load: the map would otherwise
|
|
119
|
-
* silently keep whichever came last.
|
|
120
|
-
*/
|
|
121
|
-
export const LUNORA_ROOMS: Readonly<Record<string, string>> = (() => {
|
|
122
|
-
const registry: Record<string, string> = {};
|
|
123
|
-
const owners = new Map<string, unknown>();
|
|
124
|
-
|
|
125
|
-
for (const [path, fn] of Object.entries(LUNORA_FUNCTIONS)) {
|
|
126
|
-
if (fn.channel?.kind !== "room") {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const topic = \`room:\${fn.channel.name}\`;
|
|
131
|
-
const owner = owners.get(topic);
|
|
132
|
-
|
|
133
|
-
// The same registration exported under two names (an alias) is one room.
|
|
134
|
-
if (owner !== undefined && owner !== fn) {
|
|
135
|
-
throw new Error(\`two defineRoom registrations are named "\${fn.channel.name}"; room names must be unique\`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (owner === undefined) {
|
|
139
|
-
owners.set(topic, fn);
|
|
140
|
-
registry[topic] = path;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return registry;
|
|
145
|
-
})();
|
|
146
|
-
`:"",I=m.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${l.values}";
|
|
147
|
-
`:"",D=m.length>0?`
|
|
148
|
-
/**
|
|
149
|
-
* AOT-compiled argument validators (Worker-safe, no \`eval\`). Each is installed
|
|
150
|
-
* onto its function's live \`.args\` object and consulted by the interpreted
|
|
151
|
-
* parser as a zero-allocation fast path; anything it can't model is deferred.
|
|
152
|
-
*/
|
|
153
|
-
${m}
|
|
154
|
-
`:"",$=ge(r),U=$.types?`
|
|
155
|
-
${$.types}
|
|
156
|
-
`:"",B=$.implementation?`
|
|
157
|
-
${$.implementation}
|
|
158
|
-
`:"",T=ee($.types),H=T.length>0?`import type { ${T.join(", ")} } from "./dataModel.js";
|
|
159
|
-
`:"",J=u?"context":"_context",q=u?`${me}
|
|
160
|
-
|
|
161
|
-
`:"";return te(`${z}${f}${w.importLine}${k.importLine}${I}${E}${O.typeImport}import { LunoraError } from "${l.server}";
|
|
162
|
-
import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
|
|
163
|
-
${H}
|
|
164
|
-
/**
|
|
165
|
-
* Single registered function, narrowed to the shape \`handleRpc\` needs.
|
|
166
|
-
* The real argument validators / return types are checked elsewhere — at
|
|
167
|
-
* the dispatch site we erase to \`unknown\` so a single map can host every
|
|
168
|
-
* registered function.
|
|
169
|
-
*/
|
|
170
|
-
export interface RegisteredLunoraFunction {
|
|
171
|
-
kind: "action" | "mutation" | "query" | "stream";
|
|
172
|
-
args: Record<string, unknown>;
|
|
173
|
-
/**
|
|
174
|
-
* Present on a \`"stream"\` declared \`durable\`: its run is persisted and
|
|
175
|
-
* survives the socket that opened it. Absent on every other kind, and on an
|
|
176
|
-
* ephemeral stream.
|
|
177
|
-
*/
|
|
178
|
-
durable?: { ttlMs?: number };
|
|
179
|
-
/**
|
|
180
|
-
* For \`"action" | "mutation" | "query"\` the handler is awaited and its result returned.
|
|
181
|
-
* For \`"stream"\` the handler returns an \`AsyncIterable\` synchronously and takes an
|
|
182
|
-
* \`AbortSignal\` as a third argument — the runtime drives it frame-by-frame.
|
|
183
|
-
*/
|
|
184
|
-
handler: ((context: unknown, args: Record<string, unknown>) => Promise<unknown> | unknown) | ((context: unknown, args: Record<string, unknown>, signal?: AbortSignal) => AsyncIterable<unknown>);
|
|
185
|
-
/**
|
|
186
|
-
* The lifecycle moment a hook fires on, when this registration came from
|
|
187
|
-
* \`onConnect\`/\`onDisconnect\`/\`onShardInit\`/\`onQueryChange\`/\`onWhisper\`.
|
|
188
|
-
* Read at dispatch to decide whether the function runs system-trusted:
|
|
189
|
-
* \`init\` and \`reactor\` have no caller identity, so RLS has no user to scope
|
|
190
|
-
* to. \`whisper\` does have one — it runs under the asking socket's identity.
|
|
191
|
-
*/
|
|
192
|
-
lifecycle?: "connect" | "disconnect" | "init" | "reactor" | "whisper";
|
|
193
|
-
${O.channelField} /**
|
|
194
|
-
* Hoisted by the builder when the \`.use()\` chain carries a step with a
|
|
195
|
-
* per-dispatch effect — \`rateLimit(...)\` consuming budget, a single-use
|
|
196
|
-
* captcha token being burned. Read by \`isCacheableQuery\`: the chain runs
|
|
197
|
-
* inside the dispatch callback, and a reactive-cache HIT skips that
|
|
198
|
-
* callback, so such a query must never be memoized.
|
|
199
|
-
*/
|
|
200
|
-
perDispatch?: boolean;
|
|
201
|
-
/** \`"internal"\` functions are rejected on the external RPC path; absence === public. */
|
|
202
|
-
visibility?: "internal" | "public";
|
|
203
|
-
/**
|
|
204
|
-
* \`.x402({ price })\` tag on a paid public procedure. The origin worker
|
|
205
|
-
* paywalls it; the shard refuses to subscribe it (\`isPaidFunction\`).
|
|
206
|
-
*/
|
|
207
|
-
x402?: { readonly price: number | string };
|
|
208
|
-
}
|
|
209
|
-
${w.prelude}${k.prelude}
|
|
210
|
-
/**
|
|
211
|
-
* Static dispatch table. The key matches the \`__lunoraRef\` the client
|
|
212
|
-
* emits (\`api[namespace][fn].__lunoraRef === "namespace:fn"\`).
|
|
213
|
-
*/
|
|
214
|
-
export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${S}};
|
|
215
|
-
${D}${C}${F}${j}${O.messagesBlock}
|
|
216
|
-
/**
|
|
217
|
-
* Lifecycle manifest: the function paths the generated ShardDO dispatches when a
|
|
218
|
-
* client's WebSocket connects (\`connect\`) or disconnects (\`disconnect\`), once
|
|
219
|
-
* per Durable Object instance before any handler runs (\`init\`), after a
|
|
220
|
-
* write flush when a watched read's result changed (\`reactor\`), and before a
|
|
221
|
-
* socket joins or broadcasts to a whisper topic (\`whisper\`). Each path also
|
|
222
|
-
* resolves through {@link LUNORA_FUNCTIONS}. The socket-scoped moments run under
|
|
223
|
-
* the socket's verified identity; \`init\` and \`reactor\` have no caller, so they
|
|
224
|
-
* run anonymous — all via system dispatch.
|
|
225
|
-
*/
|
|
226
|
-
export const LUNORA_LIFECYCLE_HOOKS: {
|
|
227
|
-
connect: readonly string[];
|
|
228
|
-
disconnect: readonly string[];
|
|
229
|
-
init: readonly string[];
|
|
230
|
-
reactor: readonly string[];
|
|
231
|
-
whisper: readonly string[];
|
|
232
|
-
} = {
|
|
233
|
-
connect: [${y.connect.map(d=>JSON.stringify(d)).join(", ")}],
|
|
234
|
-
disconnect: [${y.disconnect.map(d=>JSON.stringify(d)).join(", ")}],
|
|
235
|
-
init: [${y.init.map(d=>JSON.stringify(d)).join(", ")}],
|
|
236
|
-
reactor: [${y.reactor.map(d=>JSON.stringify(d)).join(", ")}],
|
|
237
|
-
whisper: [${y.whisper.map(d=>JSON.stringify(d)).join(", ")}],
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Resolve and invoke a registered function from an external caller. Throws a
|
|
242
|
-
* LunoraError-shaped object (404) when the path is unknown — the runtime's
|
|
243
|
-
* structural error mapper turns that into the right HTTP status. Internal
|
|
244
|
-
* functions are treated as not-found so their existence never leaks to clients.
|
|
245
|
-
*/
|
|
246
|
-
export const dispatchLunoraFunction = async (functionPath: string, context: unknown, args: Record<string, unknown>): Promise<unknown> => {
|
|
247
|
-
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
248
|
-
|
|
249
|
-
if (!registered || registered.visibility === "internal") {
|
|
250
|
-
throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return registered.handler(context, args);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* A handler context accepted by {@link createCaller}. The runtime context the
|
|
258
|
-
* shard DO builds is uniform across kinds, so any handler's \`ctx\` works here.
|
|
259
|
-
*/
|
|
260
|
-
export type CallerCtx = ActionCtx | MutationCtx | QueryCtx;
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Typed, in-process server-to-server caller. Every registered function — public
|
|
264
|
-
* *and* internal — is reachable; each call dispatches against the same shard
|
|
265
|
-
* with the supplied \`context\`, exactly like \`ctx.runQuery\`/\`runMutation\`/
|
|
266
|
-
* \`runAction\` but without re-stating the function path.
|
|
267
|
-
*/
|
|
268
|
-
export interface Caller {${U}}
|
|
269
|
-
|
|
270
|
-
${q}/** Build a {@link Caller} bound to \`context\` (typically a handler's \`ctx\`). */
|
|
271
|
-
export const createCaller = (${J}: CallerCtx): Caller => ({${B}});
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Single registered data migration, narrowed to the shape the per-shard runner
|
|
275
|
-
* consumes. \`up\`/\`down\` are erased to a structural transform; the authoring
|
|
276
|
-
* validation lives in \`defineMigration\`.
|
|
277
|
-
*/
|
|
278
|
-
export interface RegisteredDataMigration {
|
|
279
|
-
batchSize?: number;
|
|
280
|
-
down?: (document: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
281
|
-
id: string;
|
|
282
|
-
table: string;
|
|
283
|
-
up: (document: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Registry of online data migrations keyed by \`defineMigration\`'s \`id\`. The
|
|
288
|
-
* shard DO's admin RPC and the CLI resolve migrations to run through this map.
|
|
289
|
-
*/
|
|
290
|
-
export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${b}};
|
|
291
|
-
`,i)};export{ve as default};
|