@lunora/codegen 1.0.0-alpha.383 → 1.0.0-alpha.385
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 +43 -5
- package/dist/index.d.ts +43 -5
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{AGENTS_FILENAME-BedyJsOT.mjs → AGENTS_FILENAME-5mDMAMWy.mjs} +1 -1
- package/dist/packem_shared/{CONTAINERS_FILENAME-T1v8pyHN.mjs → CONTAINERS_FILENAME-BJYrxnq2.mjs} +1 -1
- package/dist/packem_shared/{GENERATED_HEADER-Bzf6ZJ9r.mjs → GENERATED_HEADER-B-tYRlRG.mjs} +1 -1
- package/dist/packem_shared/{MUTATORS_FILENAME-BGvYo46g.mjs → MUTATORS_FILENAME-D9WbOFm7.mjs} +1 -1
- package/dist/packem_shared/{NOTIFY_FILENAME-BJJObZHG.mjs → NOTIFY_FILENAME-CRU_TEKs.mjs} +1 -1
- package/dist/packem_shared/{OPENRPC_VERSION-CSjT8wJW.mjs → OPENRPC_VERSION-CT_E2DcI.mjs} +1 -1
- package/dist/packem_shared/{QUEUES_FILENAME-Dt5RG_P0.mjs → QUEUES_FILENAME-BeGwgqcw.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DXilYf6b.mjs +31 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs +2 -0
- package/dist/packem_shared/SHAPES_FILENAME-D9beIrs1.mjs +1 -0
- package/dist/packem_shared/{SchemaSnapshotParseError-ycDz8gOB.mjs → SchemaSnapshotParseError-DnAuFdpl.mjs} +8 -8
- package/dist/packem_shared/{WORKFLOWS_FILENAME-VAXgqqP-.mjs → WORKFLOWS_FILENAME--RWiu_Vy.mjs} +1 -1
- package/dist/packem_shared/{attribution-DUbGYT4N.mjs → attribution-CTMkuBkn.mjs} +1 -1
- package/dist/packem_shared/{buildOpenApiDocument-afHH7rN5.mjs → buildOpenApiDocument-67-fasdW.mjs} +1 -1
- package/dist/packem_shared/{context-property-calls-B75cjwpy.mjs → context-property-calls-ZK1UcTQR.mjs} +1 -1
- package/dist/packem_shared/{context-root-D4Njep-A.mjs → context-root-DtpwprsY.mjs} +1 -1
- package/dist/packem_shared/{database-calls-aAjZJdma.mjs → database-calls-Cn47SfSU.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-Ce3BdKQr.mjs → discoverAuthApiCalls-DZMYREsq.mjs} +1 -1
- package/dist/packem_shared/discoverFunctions-DU5ylqVC.mjs +1 -0
- package/dist/packem_shared/{discoverHttpRoutes-BQM2CPSF.mjs → discoverHttpRoutes-D9Q0lBBb.mjs} +1 -1
- package/dist/packem_shared/discoverHyperdriveCalls-DlyCZKX3.mjs +1 -0
- package/dist/packem_shared/{discoverInserts-DldQpEfF.mjs → discoverInserts-7Xdawmuk.mjs} +1 -1
- package/dist/packem_shared/discoverMaskProcedures-D6kAKDZG.mjs +1 -0
- package/dist/packem_shared/{discoverMigrations-E9k4Ykku.mjs → discoverMigrations-C649uAWL.mjs} +1 -1
- package/dist/packem_shared/{discoverNondeterministicCalls-DZ_kIie5.mjs → discoverNondeterministicCalls-DQgVTcLv.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-Bq2hqYHP.mjs → discoverQueries-C75OdGHl.mjs} +1 -1
- package/dist/packem_shared/discoverR2sqlCalls-BrDIti5c.mjs +1 -0
- package/dist/packem_shared/{discoverRlsMetadata-Dq6iSXnC.mjs → discoverRlsMetadata-DqZpiGts.mjs} +1 -1
- package/dist/packem_shared/discoverRlsProcedures-BiyDg2ej.mjs +1 -0
- package/dist/packem_shared/discoverSchema-Bs5JUiOE.mjs +1 -0
- package/dist/packem_shared/{discoverStorageRulesMetadata-CJ7h6SPK.mjs → discoverStorageRulesMetadata-H3RJzkH_.mjs} +1 -1
- package/dist/packem_shared/{emitAgents-BeM6PZv4.mjs → emitAgents-iTKWSKan.mjs} +1 -1
- package/dist/packem_shared/{emitApi-GFmStqmq.mjs → emitApi-DWJW8Vu9.mjs} +1 -1
- package/dist/packem_shared/{emitApp-D-6FIpYb.mjs → emitApp-L7PnfjJK.mjs} +1 -1
- package/dist/packem_shared/{emitCrons-Drdn8Mjn.mjs → emitCrons-BvqxeNRr.mjs} +1 -1
- package/dist/packem_shared/{emitDataModel-LTnwnhV6.mjs → emitDataModel-MjAOi3KM.mjs} +1 -1
- package/dist/packem_shared/{emitDrizzleSchema-CM9jh_F0.mjs → emitDrizzleSchema-Dszoyymv.mjs} +1 -1
- package/dist/packem_shared/{emitFunctions-CfSXBV_A.mjs → emitFunctions-CvMrX_cX.mjs} +100 -93
- package/dist/packem_shared/{emitServer-4l7MPmK0.mjs → emitServer-BgI9yXW1.mjs} +1 -1
- package/dist/packem_shared/emitShard-D4sAFu7Z.mjs +1 -0
- package/dist/packem_shared/{exported-procedure-chains-BaCIhnJ7.mjs → exported-procedure-chains-CRM-MVfP.mjs} +1 -1
- package/dist/packem_shared/handler-reference-90LXJART.mjs +1 -0
- package/dist/packem_shared/{index-11LAY5JO.mjs → index-CNI4vSyc.mjs} +1 -1
- package/dist/packem_shared/index-o449rQLQ.mjs +1 -0
- package/dist/packem_shared/ip-reads-Dotjify6.mjs +1 -0
- package/dist/packem_shared/{qualifiers-D1Q_3wo2.mjs → qualifiers-ClaCHu0X.mjs} +1 -1
- package/dist/packem_shared/{server-D69SOfX8.mjs → server-qWq5nN-R.mjs} +1 -1
- package/dist/packem_shared/{shard-CB0Ospyw.mjs → shard-BqfSKnmG.mjs} +94 -91
- package/dist/packem_shared/{shard-runtime-lkQU8trx.mjs → shard-runtime-C1P_uVye.mjs} +1 -1
- package/dist/packem_shared/{shared-A1XHcT4t.mjs → shared-DhqnD5R3.mjs} +6 -6
- package/dist/packem_shared/static-literal-BwDHHjEJ.mjs +1 -0
- package/dist/packem_shared/{unwrap-handler-return-eQRIZSOX.mjs → unwrap-handler-return-c2s2-nk9.mjs} +1 -1
- package/package.json +8 -8
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-kN0pgKNu.mjs +0 -31
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-BdxZuSxk.mjs +0 -2
- package/dist/packem_shared/SHAPES_FILENAME-KyidzoqS.mjs +0 -1
- package/dist/packem_shared/discoverFunctions-CoQM_L6f.mjs +0 -1
- package/dist/packem_shared/discoverHyperdriveCalls-PUg-BESh.mjs +0 -1
- package/dist/packem_shared/discoverMaskProcedures-_Ey4eJLn.mjs +0 -1
- package/dist/packem_shared/discoverR2sqlCalls-CeNnalpk.mjs +0 -1
- package/dist/packem_shared/discoverRlsProcedures-MboagP9z.mjs +0 -1
- package/dist/packem_shared/discoverSchema-Cycd1-H0.mjs +0 -1
- package/dist/packem_shared/emitShard-B4fVJcJA.mjs +0 -1
- package/dist/packem_shared/handler-reference-D1wpw_qR.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as
|
|
1
|
+
import{LunoraError as me}from"@lunora/errors";import{serializeSchemaSnapshot as Zt,hashSchemaSnapshot as er}from"./SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs";import{isHyperdriveGlobalTable as tr,isD1GlobalTable as rr}from"./isD1GlobalTable-udvHAAzD.mjs";import{r as nr}from"./json-data-Chfs2Cz5.mjs";import{r as M,e as ar,a as sr,b as or,c as ir,d as dr,f as cr,g as lr,h as ur,i as hr,j as pr,k as mr,l as fr,m as gr,n as br,o as yr,p as wr,q as vr,s as kr}from"./shard-runtime-C1P_uVye.mjs";import{u as q,h as Sr,s as Rr,a as xr,I as Ar,c as Or,G as Dr,d as Tr}from"./shared-DhqnD5R3.mjs";import{p as _r}from"./platform-8oj7iXQy.mjs";import{i as Ir}from"./schema-BgM8A3XV.mjs";const p=(r,t)=>`((): (() => ${t}) => { let cached: ${t} | undefined; return () => (cached ??= JSON.parse(${JSON.stringify(JSON.stringify(r))}) as ${t}); })()`,fe=["categories","description","facing","level","remediation","title"],Er=r=>{const t={};return{advisoryRows:r.map(o=>{let n=t[o.name];return n||(n=Object.fromEntries(fe.filter(a=>a in o).map(a=>[a,o[a]])),t[o.name]=n),Object.fromEntries(Object.entries(o).filter(([a,i])=>!fe.includes(a)||JSON.stringify(i)!==JSON.stringify(n[a])))}),advisoryRules:t}},Cr=` /**
|
|
2
2
|
* The bare writer every admin/maintenance entry point writes through.
|
|
3
3
|
*
|
|
4
4
|
* Admin and maintenance writes go through the SAME reactive-cache hooks as a
|
|
@@ -30,7 +30,7 @@ import{LunoraError as pe}from"@lunora/errors";import{serializeSchemaSnapshot as
|
|
|
30
30
|
schema: schema as unknown as SchemaLike,
|
|
31
31
|
sql: this.sql as SqlExec,
|
|
32
32
|
});
|
|
33
|
-
}`,b=(r="")=>` const writer = this.adminWriter(${r});`,
|
|
33
|
+
}`,b=(r="")=>` const writer = this.adminWriter(${r});`,Lr=`${Cr}
|
|
34
34
|
|
|
35
35
|
protected override async runShardDataMigration(args: RunShardMigrationArgs): Promise<MigrationRunResult> {
|
|
36
36
|
this.ensureMigrated();
|
|
@@ -234,13 +234,13 @@ ${b()}
|
|
|
234
234
|
await applyCdcChanges(writer, args.changes);
|
|
235
235
|
|
|
236
236
|
return { applied: args.changes.length };
|
|
237
|
-
}`,
|
|
238
|
-
orm: databaseContext.orm,`,
|
|
239
|
-
orm: { configurable: true, enumerable: true, value: mutationDatabase.orm, writable: true },`,
|
|
237
|
+
}`,Pr=({actionOnlyBuild:r,actionOnlyFields:t,agentsBuild:e,agentsContextField:o,containersBuild:n,containersContextField:a,databaseOptions:i,everyContextBuild:u,everyContextField:h,facadeBlock:m,globalDatabaseLine:R,hasSensitiveArgs:k=!1,lazyFunctions:f=!1,notifyBuild:c,ormContextField:y,paymentsBuild:F,paymentsContextField:x,queuesBuild:U,queuesContextField:B,topicsBuild:S,topicsContextField:j,vectorsBuild:d,vectorsContextField:w,workflowsBuild:I,workflowsContextField:W})=>{const E=t.length>0,C=y===""?"{ db }":"{ db, orm: bindOrm(facade) }",L=y===""?"":`
|
|
238
|
+
orm: databaseContext.orm,`,K=y===""?"":`
|
|
239
|
+
orm: { configurable: true, enumerable: true, value: mutationDatabase.orm, writable: true },`,H=E?`
|
|
240
240
|
// ActionCtx-only helpers (external, non-deterministic I/O): constructed
|
|
241
241
|
// and attached only for an \`action\` so query/mutation ctx never carry them.
|
|
242
242
|
if (isAction) {
|
|
243
|
-
${r.replaceAll(/^(?=.)/gmu," ")}${t.map(
|
|
243
|
+
${r.replaceAll(/^(?=.)/gmu," ")}${t.map(l=>` ctx.${l} = ${l};`).join(`
|
|
244
244
|
`)}
|
|
245
245
|
}
|
|
246
246
|
`:"";return` private buildCtx(options: { bookmarks?: DispatchBookmark | undefined; functionPath?: string | undefined; headroom?: TransactionHeadroomTracker | undefined; identity?: SubscriptionIdentity | undefined; kind?: "query" | undefined; onRead?: ((table: string, idOrScan?: string) => void) | undefined; onReadRange?: ((range: KeyRange) => void) | undefined; replayKey?: boolean | undefined; scope?: QueryReadScope | undefined; sensitive?: SensitiveScope | undefined; trusted?: boolean | undefined } = {}): unknown {
|
|
@@ -300,7 +300,7 @@ ${r.replaceAll(/^(?=.)/gmu," ")}${t.map(v=>` ctx.${v} = ${v};`
|
|
|
300
300
|
|
|
301
301
|
return caller.ip;
|
|
302
302
|
};
|
|
303
|
-
${d}${u}${n}${
|
|
303
|
+
${d}${u}${n}${I}${U}${S}${e}
|
|
304
304
|
// Which dispatch this ctx belongs to. Drives the two deferral facades
|
|
305
305
|
// below and the \`ctx.run*\` caller guard; a ctx built for an
|
|
306
306
|
// admin/lifecycle path has no registered function, and so no kind. An
|
|
@@ -406,7 +406,7 @@ ${d}${u}${n}${E}${B}${R}${e}
|
|
|
406
406
|
// so both write to the same trace.
|
|
407
407
|
const span = this.makeDispatchSpan(traceAnchor, observability, options.sensitive);
|
|
408
408
|
|
|
409
|
-
${
|
|
409
|
+
${R} // \`ctx.db\`, wrapped in automatic instrumentation: by default this
|
|
410
410
|
// adds aggregate counters (call count, total time, per-operation
|
|
411
411
|
// breakdown) to the wide event rather than a span per call, so a
|
|
412
412
|
// handler making hundreds of queries stays readable. See
|
|
@@ -415,11 +415,11 @@ ${x} // \`ctx.db\`, wrapped in automatic instrumentation: by default
|
|
|
415
415
|
// mutation must rebuild its DB and table/ORM views with its own queue.
|
|
416
416
|
const makeDatabaseContext = (scheduler: SchedulerLike) => {
|
|
417
417
|
const db: DatabaseWriterLike = this.instrumentDb(createShardCtxDb(${i}), logFunctionPath, traceAnchor, observability, options.sensitive);
|
|
418
|
-
${m} return ${
|
|
418
|
+
${m} return ${C};
|
|
419
419
|
};
|
|
420
420
|
const databaseContext = makeDatabaseContext(scheduler);
|
|
421
421
|
const db = databaseContext.db;
|
|
422
|
-
${
|
|
422
|
+
${F}
|
|
423
423
|
|
|
424
424
|
// \`ctx.trace\` / \`ctx.metrics\`: spans and measurements to the same sink.
|
|
425
425
|
// The trace anchor is threaded explicitly for the same reason \`identity\`
|
|
@@ -505,15 +505,15 @@ ${c}
|
|
|
505
505
|
// to the handler so code that signs its own URLs (a copy-in
|
|
506
506
|
// \`createStorage\`) can fall back to it too. \`undefined\` for a
|
|
507
507
|
// query and for a deferred dispatch, for the reasons given there.
|
|
508
|
-
origin: requestOrigin,${
|
|
508
|
+
origin: requestOrigin,${L}
|
|
509
509
|
scheduler,
|
|
510
510
|
span,
|
|
511
511
|
storage: contextStorage,
|
|
512
|
-
trace,${w}${h}${
|
|
512
|
+
trace,${w}${h}${x}${a}${W}${B}${j}${o}${k?`
|
|
513
513
|
[Symbol.for("lunora.admitSensitiveArgs")]: (args: Record<string, unknown>, names: ReadonlySet<string>): void => this.admitSensitiveValues(options.sensitive, args, names),`:""}
|
|
514
514
|
};
|
|
515
|
-
${
|
|
516
|
-
`:""}${
|
|
515
|
+
${E?` const isAction = contextKind === "action";
|
|
516
|
+
`:""}${H}
|
|
517
517
|
${f?` const captureScope = (): (() => void) => {
|
|
518
518
|
const requestScope = this.captureRequestScope();
|
|
519
519
|
return () => this.restoreRequestScope(requestScope);
|
|
@@ -547,7 +547,7 @@ ${f?` const captureScope = (): (() => void) => {
|
|
|
547
547
|
// refuses network I/O wherever it runs, so its \`fetch\` is overridden here.
|
|
548
548
|
return Object.defineProperties({}, {
|
|
549
549
|
...Object.getOwnPropertyDescriptors(target),
|
|
550
|
-
db: { configurable: true, enumerable: true, value: mutationDatabase.db, writable: true },${
|
|
550
|
+
db: { configurable: true, enumerable: true, value: mutationDatabase.db, writable: true },${K}
|
|
551
551
|
fetch: { configurable: true, enumerable: true, value: refuseFetch, writable: true },
|
|
552
552
|
random: { configurable: true, enumerable: true, value: mutationRandom, writable: true },
|
|
553
553
|
scheduler: { configurable: true, enumerable: true, value: mutationScheduler, writable: true },
|
|
@@ -610,7 +610,7 @@ ${f?` const captureScope = (): (() => void) => {
|
|
|
610
610
|
|
|
611
611
|
if (queryView === undefined) {
|
|
612
612
|
const descriptors: PropertyDescriptorMap = Object.getOwnPropertyDescriptors(ctx);
|
|
613
|
-
${t.map(
|
|
613
|
+
${t.map(l=>` delete descriptors.${l};
|
|
614
614
|
`).join("")} // Writable and configurable, like the plain fields they replace.
|
|
615
615
|
const field = (value: unknown): PropertyDescriptor => ({ configurable: true, enumerable: true, value, writable: true });
|
|
616
616
|
|
|
@@ -632,7 +632,7 @@ ${t.map(v=>` delete descriptors.${v};
|
|
|
632
632
|
installRun(ctx, contextKind);
|
|
633
633
|
|
|
634
634
|
return ctx;
|
|
635
|
-
}`},
|
|
635
|
+
}`},ge=`// Bound in-process \`ctx.run*\` composition depth so a self- or cyclically-
|
|
636
636
|
// referencing call fails loudly with a clear error instead of overflowing the
|
|
637
637
|
// stack. Tracked across the awaited handler chain (one DO invocation is
|
|
638
638
|
// single-threaded), so the counter reflects true nesting depth.
|
|
@@ -698,7 +698,7 @@ const dispatchRun = async (
|
|
|
698
698
|
} finally {
|
|
699
699
|
runDepth -= 1;
|
|
700
700
|
}
|
|
701
|
-
};`,
|
|
701
|
+
};`,Nr=r=>r?ge.replace(" runTransactional?: (work: () => Promise<unknown>) => Promise<unknown>,",` runTransactional?: (work: () => Promise<unknown>) => Promise<unknown>,
|
|
702
702
|
captureScope?: () => () => void,`).replace(` try {
|
|
703
703
|
// A mutation composed from an action`,` try {
|
|
704
704
|
let loaded = getLoadedFunction(functionPath);
|
|
@@ -719,7 +719,7 @@ const dispatchRun = async (
|
|
|
719
719
|
|
|
720
720
|
const loadedFunction = loaded;
|
|
721
721
|
|
|
722
|
-
// A mutation composed from an action`).replaceAll("registered.handler","loadedFunction.handler"):
|
|
722
|
+
// A mutation composed from an action`).replaceAll("registered.handler","loadedFunction.handler"):ge,$r=` public override async handleRpc(functionPath: string, args: Record<string, unknown>, headroom?: TransactionHeadroomTracker, scope?: QueryReadScope, bookmarks?: DispatchBookmark, sensitive?: SensitiveScope): Promise<unknown> {
|
|
723
723
|
// A dispatch that did not come through the shard's \`/rpc\` (a scheduled call,
|
|
724
724
|
// a lifecycle hook, an admin run) has no scope of its own, so it opens one here
|
|
725
725
|
// and releases it when the handler settles.
|
|
@@ -923,7 +923,7 @@ __COMMITTED_CATCH__ } finally {
|
|
|
923
923
|
// \`ctx.scheduler\` call that reached the buffer in the first place.
|
|
924
924
|
protected override scheduleOutboxScheduler(): SchedulerLike | undefined {
|
|
925
925
|
return config.scheduler?.((this.env ?? {}) as Record<string, unknown>) as SchedulerLike | undefined;
|
|
926
|
-
}
|
|
926
|
+
}`,Mr=` protected override async executeSubscription(functionPath: string, args: Record<string, unknown>, identity?: SubscriptionIdentity): Promise<{ identityTracked?: boolean; ranges?: Map<string, KeyRange[]>; result: unknown; tables: Set<string> } | null> {
|
|
927
927
|
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
928
928
|
|
|
929
929
|
if (!registered || registered.kind !== "query" || registered.visibility === "internal") {
|
|
@@ -967,7 +967,7 @@ __PREPARE_FUNCTION__ this.ensureServable();
|
|
|
967
967
|
// \`ctx.auth\` stream as nobody — or as a concurrent RPC's caller.
|
|
968
968
|
iterator: (signal) => (registered.handler as (context: unknown, args: Record<string, unknown>, signal: AbortSignal) => AsyncIterable<unknown>)(this.buildCtx({ functionPath, identity }), args, signal),
|
|
969
969
|
};
|
|
970
|
-
}`,
|
|
970
|
+
}`,qr=` } catch (error) {
|
|
971
971
|
// The write committed before this failed. Mark the error so the caller can tell
|
|
972
972
|
// a durable write from a rollback: the rethrow still reaches the caller unchanged.
|
|
973
973
|
if (typeof error === "object" && error !== null) {
|
|
@@ -975,7 +975,7 @@ __PREPARE_FUNCTION__ this.ensureServable();
|
|
|
975
975
|
}
|
|
976
976
|
|
|
977
977
|
throw error;
|
|
978
|
-
`,
|
|
978
|
+
`,Fr=(r,t=!1)=>{const e=t?` const registeredBeforeLoad = LUNORA_FUNCTIONS[functionPath];
|
|
979
979
|
|
|
980
980
|
if (registeredBeforeLoad?.visibility === "internal" && !this.isSystemDispatch()) {
|
|
981
981
|
throw new LunoraError("FUNCTION_NOT_FOUND", "function not registered: " + functionPath);
|
|
@@ -992,7 +992,7 @@ __PREPARE_FUNCTION__ this.ensureServable();
|
|
|
992
992
|
}
|
|
993
993
|
}
|
|
994
994
|
|
|
995
|
-
`:"";return
|
|
995
|
+
`:"";return $r.replace("__COMMITTED_CATCH__",r?qr:"").replace("__PREPARE_FUNCTION__",`${e}${o}`)},Ur=r=>{const t={};for(const e of r.tables){const o={};for(const[n,a]of Object.entries(e.shape)){const i=q(a);i.kind==="id"&&i.tableName!==void 0&&(o[n]=i.tableName)}Object.keys(o).length>0&&(t[e.name]=o)}return t},Br=r=>{const t={};for(const e of r.tables){const o=[];for(const[n,a]of Object.entries(e.shape))q(a).kind==="storage"&&o.push(n);o.length>0&&(t[e.name]=o)}return t},jr=r=>{const t={};for(const e of r.tables){const o=[...e.indexes.map(n=>({fields:[...n.fields],name:n.name,type:"index",...n.unique===!0?{unique:!0}:{}})),...e.searchIndexes.map(n=>({fields:[n.field,...n.filterFields??[]],name:n.name,type:"search"})),...(e.geoIndexes??[]).map(n=>({fields:[n.field],name:n.name,type:"geo"})),...e.rankIndexes.map(n=>({fields:n.sortBy.map(a=>a.field),name:n.name,type:"rank"})),...e.vectorIndexes.map(n=>({fields:n.field===void 0?[]:[n.field],name:n.name,type:"vector"}))];o.length>0&&(t[e.name]=o)}return t},Wr=r=>{const t=[];for(const e of r.tables)!e.ttl||e.shardMode==="global"||t.push({...e.ttl.after===void 0?{}:{after:e.ttl.after},field:e.ttl.field,...e.softDelete?{softDeleteField:e.softDelete.field}:{},table:e.name});return t},Kr=r=>{if(r.kind!=="union"||r.members===void 0||r.members.length===0)return;const t=[];for(const e of r.members){if(e.kind!=="literal"||e.literalValue===void 0)return;try{const o=JSON.parse(e.literalValue);if(typeof o!="string")return;t.push(o)}catch{return}}return t},Hr=new Set(["bigint","boolean","date","number","timestamp"]),Vr=r=>{const[t,e]=r.kind==="union"?r.members??[]:[];if(t===void 0||e===void 0||r.members?.length!==2)return;const o=a=>a.kind==="null"||a.kind==="literal"&&a.literalValue==="null",n=q(o(e)?t:e);return o(t)!==o(e)&&Hr.has(n.kind)?n:void 0},Gr=(r,t,e)=>{const o=q(t),n=Vr(o),a=n??o,i={name:r,optional:Sr(t),type:a.kind};if(a.kind==="id"&&a.tableName!==void 0){i.ref=a.tableName;const h=e.get(r);h!==void 0&&(i.onDelete=h)}a.kind==="storage"&&(i.isStorage=!0,a.bucket!==void 0&&(i.bucket=a.bucket));const u=Kr(a);return u!==void 0&&(i.enumValues=u),(a.column?.notNull===!1||n!==void 0)&&(i.nullable=!0),i},Qr=r=>{const t={};for(const e of r.tables){const o=[{name:"_id",optional:!1,pk:!0,type:"id"},{name:"_creationTime",optional:!1,type:"number"},...e.commitOrdered===!0?[{name:"_commitSeq",optional:!1,type:"number"}]:[]],n=new Map(e.relations.flatMap(a=>a.kind==="one"?[[a.field,a.onDelete]]:[]));for(const[a,i]of Object.entries(e.shape))o.push(Gr(a,i,n));t[e.name]=o}return t},zr=({hasMutators:r,hasSensitiveShapes:t,hasShapes:e,rlsData:o})=>{const n="{ columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string } | undefined",a=t?` protected override resolveShape(name: string, args: Record<string, unknown>, identity?: SubscriptionIdentity): ${n} {
|
|
996
996
|
const sensitive = this.openSensitiveScope(\`__shape__:\${name}\`, args);
|
|
997
997
|
|
|
998
998
|
try {
|
|
@@ -1074,7 +1074,7 @@ assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(h)}, (schema as
|
|
|
1074
1074
|
protected override isCustomMutator(functionPath: string): boolean {
|
|
1075
1075
|
return LUNORA_MUTATOR_PATHS.has(functionPath);
|
|
1076
1076
|
}
|
|
1077
|
-
`:"",shapeGuardImport:e?"assertShapeShardable, ":"",shapeReadPolicyAssertion:m,shapeReadPolicyImport:m===""?"":"assertShapesDeclareReadPolicies, ",shapeResolveOverride:u}},
|
|
1077
|
+
`:"",shapeGuardImport:e?"assertShapeShardable, ":"",shapeReadPolicyAssertion:m,shapeReadPolicyImport:m===""?"":"assertShapesDeclareReadPolicies, ",shapeResolveOverride:u}},Jr=(r,t)=>r?`
|
|
1078
1078
|
protected override async readGlobalShapeRows(resolved: { columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string }, identity?: SubscriptionIdentity): Promise<Array<{ doc: Record<string, unknown>; id: string }>> {
|
|
1079
1079
|
const env = this.env as Record<string, unknown>;
|
|
1080
1080
|
// A shape read performs no writes, so the widened request only needs
|
|
@@ -1140,7 +1140,7 @@ assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(h)}, (schema as
|
|
|
1140
1140
|
|
|
1141
1141
|
return globalDb.cdcChangedTables?.(sinceSeq, cursorOnly === undefined ? {} : { cursorOnly });
|
|
1142
1142
|
}
|
|
1143
|
-
`:"",
|
|
1143
|
+
`:"",Yr=r=>({externalSourceOverride:r?`
|
|
1144
1144
|
protected override async pollExternalSources(trace?: TraceRefLike): Promise<number | undefined> {
|
|
1145
1145
|
const env = (this.env ?? {}) as Record<string, unknown>;
|
|
1146
1146
|
const sourced = Object.entries((schema as unknown as SchemaLike).tables)
|
|
@@ -1293,8 +1293,8 @@ assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(h)}, (schema as
|
|
|
1293
1293
|
`:"",sourceClientCacheConst:r?`
|
|
1294
1294
|
const sourceClientCache = new WeakMap<object, Map<string, SourceClientLike>>();
|
|
1295
1295
|
const sourcePollAtCache = new WeakMap<object, Map<string, number>>();
|
|
1296
|
-
`:""}),
|
|
1297
|
-
`:"",i=e?"namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey, ":"",h=`, { ${["deferAfterCommit: (work) => this.deferAfterCommit(work)",...e?["namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey",`shardedIndexNames: [${t.map(
|
|
1296
|
+
`:""}),Xr=(r,t)=>{const e=t.length>0,n=r?M("vectorsStub: VectorSearchLike","ctx.vectors: no vectors configured. Pass `vectors` to createShardDO().",["deleteByIds","getByIds","query","upsert","upsertMany","upsertNow"]):"",a=e?` const vectorShardKey = this.currentShardKey();
|
|
1297
|
+
`:"",i=e?"namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey, ":"",h=`, { ${["deferAfterCommit: (work) => this.deferAfterCommit(work)",...e?["namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey",`shardedIndexNames: [${t.map(k=>JSON.stringify(k)).join(", ")}]`]:[]].join(", ")} }`,m=r?`
|
|
1298
1298
|
const vectorSync = this.vectorSync(env);
|
|
1299
1299
|
// Vectorize lives outside this shard's SQLite, so a query whose result
|
|
1300
1300
|
// depends on a similarity search cannot be proven current on reconnect —
|
|
@@ -1337,14 +1337,14 @@ ${a} const vectors = createContextVectors(lunora${h});
|
|
|
1337
1337
|
ordered: async (read, work) => this.runOrderedAfterWrites(read, work),
|
|
1338
1338
|
});
|
|
1339
1339
|
}
|
|
1340
|
-
`:"",vectorsBuild:m,vectorsStub:n}},
|
|
1340
|
+
`:"",vectorsBuild:m,vectorsStub:n}},fn=({advisories:r=[],advisorProcedures:t=[],agents:e=[],capabilities:o=new Set,containers:n=[],env:a,flagKeys:i=[],hasFlags:u=!1,hasNotify:h=!1,hasRooms:m=!1,hasSecretValues:R=!1,hasSensitiveArgs:k=!1,hasSockets:f=!1,lazyFunctions:c=!1,hasVectors:y=!0,liveStreamDeclarations:F=[],liveStreams:x=!1,maskMetadata:U,mutators:B=[],queues:S=[],rlsMetadata:j,schema:d,schemaSnapshot:w,shapes:I=[],storageRules:W,studioFeatures:E,hasIpReaders:C=!1,services:L=[],topics:K=[],useUmbrella:H=!1,workflowEvents:V=[],workflows:A=[]})=>{const l=Tr(H),ae=B.length>0,O=I.length>0,D=I.some(s=>Rr(s.args).length>0),G=k||D,be=w===void 0?"":Zt(w),ye=w===void 0?"":`
|
|
1341
1341
|
/** Structural schema snapshot + its content hash, recorded in the shard's \`__lunora_schema_history\` ledger on cold start so the studio can show a schema-version timeline and diff any two versions. */
|
|
1342
|
-
const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.stringify(
|
|
1343
|
-
`,
|
|
1344
|
-
return { ${
|
|
1342
|
+
const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.stringify(er(w))}, json: ${JSON.stringify(be)} };
|
|
1343
|
+
`,we=w===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",v=ar(o),P=sr(u,l.flags),Q=or(i,u,l.flags),z=kr(h),J=ir(a),{build:ve,contextField:ke,importLines:Se,specs:Re}=dr(_r(S)),{build:xe,contextField:Ae,importLines:Oe,specs:De}=cr(K,S),Y=lr(L,l.server),{build:Te,contextField:_e,importLines:Ie,specs:Ee}=ur(n,d.jurisdiction),{build:Ce,contextField:Le,importLines:Pe,specs:Ne}=hr(A),{build:$e,contextField:Me,importLines:qe,specs:Fe}=pr(e,R&&e.length>0),{build:Ue,configField:Be,contextField:je,imports:We,stub:Ke}=mr(o.has("payments")),He=r,{advisoryRules:Ve,advisoryRows:Ge}=Er(He),Qe=t,se=j??{policies:[],roles:[]},ze=U??{columns:[]},Je=W??{rules:[]},Ye=E??{analytics:!1,auth:!1,containers:!1,flags:!1,kv:!1,mail:!1,notifications:!1,payments:!1,privacy:!1,queues:!1,scheduler:!1,storage:!1,vectors:!1,workflows:!1},{constant:Xe,override:Ze}=fr(A,V),{constant:et,override:tt}=gr(A,V),{constant:rt,override:nt}=br(S),g=y&&d.vectorIndexes.length>0,X=new Set(d.tables.filter(s=>Ir(s)).map(s=>s.name)),oe=g&&d.vectorIndexes.some(s=>X.has(s.table)),T=d.tables.some(s=>s.shardMode==="global"),Z=yr(X),ee=d.tables.some(s=>tr(s)),ie=d.tables.some(s=>rr(s)),N=d.tables.some(s=>s.externalSource!==void 0),de=d.tables.some(s=>s.memory===!0),te=d.tables.some(s=>s.shardMode!=="global"&&s.searchIndexes.length>0);if(ie&&ee)throw new me("INTERNAL",'lunora codegen: mixing `.global()` (D1) and `.global({ backend: "hyperdrive" })` tables in one app is not supported yet — use a single global backend.');const re=d.tables.length>0,at=Ur(d),st=jr(d),ot=Qr(d),it=Br(d),ce=Wr(d),ne=wr(g,A.length>0,S.length>0,u,te);O&&ne.push("WhereInput"),D&&ne.push("SensitiveScope");const le=vr(T),{customMutatorOverride:dt,shapeGuardImport:ct,shapeReadPolicyAssertion:lt,shapeReadPolicyImport:ut,shapeResolveOverride:ht}=zr({hasMutators:ae,hasSensitiveShapes:D,hasShapes:O,rlsData:se}),_=x?F:[];for(const s of _)if(xr(s.exportName,"live stream export name"),!Ar.test(s.filePath))throw new me("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe live stream file path: ${JSON.stringify(s.filePath)}`);const pt=c?[]:_.map(s=>`import { ${s.exportName} as liveStream_${s.exportName} } from "../${s.filePath}.js";`),mt=` protected override liveStreams() {
|
|
1344
|
+
return { ${_.map(s=>`${Or(s.id)}: liveStream_${s.exportName}`).join(", ")} };
|
|
1345
1345
|
}
|
|
1346
|
-
`,
|
|
1347
|
-
${
|
|
1346
|
+
`,ft=` private readonly liveStreamLoaders = new Map<string, () => Promise<{ validatePublish: (topic: string, payload: unknown) => unknown }>>([
|
|
1347
|
+
${_.map(s=>` [${JSON.stringify(s.id)}, () => import("../${s.filePath}.js").then((module) => module.${s.exportName})],`).join(`
|
|
1348
1348
|
`)}
|
|
1349
1349
|
]);
|
|
1350
1350
|
|
|
@@ -1365,11 +1365,11 @@ ${I.map(s=>` [${JSON.stringify(s.id)}, () => import("../${s.filePath}
|
|
|
1365
1365
|
protected override liveStreams() {
|
|
1366
1366
|
return Object.fromEntries(this.loadedLiveStreams);
|
|
1367
1367
|
}
|
|
1368
|
-
`;let
|
|
1369
|
-
vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",
|
|
1370
|
-
d1?: (env: Record<string, unknown>, request?: { bookmark?: string; cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown> | undefined; onBookmark?: (bookmark: string | undefined) => void; userId?: string | undefined }) => DatabaseWriterLike | undefined;`:"",
|
|
1371
|
-
hyperdriveGlobal?: (env: Record<string, unknown>, request?: { cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown> | undefined; userId?: string | undefined }) => DatabaseWriterLike | undefined;`:"",
|
|
1372
|
-
sourceClient?: (env: Record<string, unknown>, binding: string) => { query: <Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) => Promise<Row[]> } | undefined;`:"",
|
|
1368
|
+
`;let ue="";_.length>0&&(ue=c?ft:mt);const $=[`import type { ${ne.join(", ")} } from "${l.do}";`,`import { applyCdcChanges, createStableIdFactory, createStableRandomFactory, ${te?"backfillSearchIndexes, ":""}${g?"backfillVectorIndexes, ":""}buildReprojectionMigration, ${de?"clearMemoryTables, ":""}${ct}createReadFootprint, createShardCtxDb, exportShardRows, importShardRows, ${N?"isSourceDue, pullExternalSourceIncrementalTick, pullExternalSourceTick, ":""}markUnvouchableReads, ${oe?"ROOT_SHARD_NAME, ":""}runDataMigration, runShardMigrations, ${le.importFragment}ShardDO as ShardDOBase } from "${l.do}";`,...N?[`import type { ExternalSourceLike, SourceClientLike, TraceRefLike } from "${l.do}";`]:[],O?`import { asBucketStorage, ${ut}beginDeferredDeletes, beginDeferredSchedules, composeShapeReadWhere, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${l.server}";`:`import { asBucketStorage, beginDeferredDeletes, beginDeferredSchedules, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${l.server}";`];re&&$.push(`import type { FacadeEntry } from "${l.server}";`,`import { bindOrm, defineLazyFacade } from "${l.server}";`),g&&$.push('import type { SchemaLike as VectorSchemaLike, VectorBackfillSync, VectorizeIndexLike, VectorSearchLike } from "@lunora/bindings/vectors";','import { createContextVectors, createVectorBackfillSync, createVectors, createVectorSyncHook, vectorBackfillTargets } from "@lunora/bindings/vectors";'),$.push(...v.importLines,...P.importLines,...z.importLines,...J.importLines,...Ie,...Pe,...Se,...Oe,...Y.importLines,...qe,...We,...G?[`import { sensitiveArgumentNames } from "${l.values}";`]:[],"",'import schema from "../schema.js";',...pt,`import { ${["LUNORA_FUNCTIONS","LUNORA_LIFECYCLE_HOOKS","LUNORA_MIGRATIONS",...c?["getLoadedFunction","loadFunction"]:[],...ae?["LUNORA_MUTATOR_PATHS"]:[],...C?["LUNORA_IP_READER_PATHS"]:[],...m?["LUNORA_ROOMS"]:[],...f?["LUNORA_SOCKETS"]:[],...O?["LUNORA_SHAPES"]:[]].join(", ")} } from "./functions.js";`);const gt=g?`
|
|
1369
|
+
vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",bt=ie?`
|
|
1370
|
+
d1?: (env: Record<string, unknown>, request?: { bookmark?: string; cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown> | undefined; onBookmark?: (bookmark: string | undefined) => void; userId?: string | undefined }) => DatabaseWriterLike | undefined;`:"",yt=ee?`
|
|
1371
|
+
hyperdriveGlobal?: (env: Record<string, unknown>, request?: { cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown> | undefined; userId?: string | undefined }) => DatabaseWriterLike | undefined;`:"",wt=N?`
|
|
1372
|
+
sourceClient?: (env: Record<string, unknown>, binding: string) => { query: <Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) => Promise<Row[]> } | undefined;`:"",vt="ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().",kt="ctx.scheduler: no scheduler configured. Pass `scheduler` to createShardDO().",St="ctx.storage: no storage configured. Pass `storage` to createShardDO().",Rt=T?M("globalDbStub: DatabaseWriterLike",vt,["aggregate","count","delete","explain","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","normalizeId","patch","query","rank","rankPage","replace"],{sync:["normalizeId","query"]}):"",{vectorSyncMethod:xt,vectorsBuild:At,vectorsStub:Ot}=Xr(g,oe?d.vectorIndexes.filter(s=>X.has(s.table)).map(s=>s.name):[]),Dt=`{
|
|
1373
1373
|
...this.ctxDbTuning(),
|
|
1374
1374
|
auth: {
|
|
1375
1375
|
get identity() {
|
|
@@ -1428,11 +1428,11 @@ ${I.map(s=>` [${JSON.stringify(s.id)}, () => import("../${s.filePath}
|
|
|
1428
1428
|
scheduler,
|
|
1429
1429
|
schema: schema as unknown as SchemaLike,
|
|
1430
1430
|
sql: this.sql as SqlExec,
|
|
1431
|
-
storage,${
|
|
1431
|
+
storage,${T?`
|
|
1432
1432
|
globalDb,`:""}
|
|
1433
|
-
}`,
|
|
1434
|
-
vectors,`:"",
|
|
1435
|
-
orm: bindOrm(facade),`:"",
|
|
1433
|
+
}`,Tt=g?`
|
|
1434
|
+
vectors,`:"",_t=re?`
|
|
1435
|
+
orm: bindOrm(facade),`:"",he=ee?"config.hyperdriveGlobal":"config.d1",It=T?` const bookmark = this.getInboundBookmark();
|
|
1436
1436
|
const globalRequest = {
|
|
1437
1437
|
...this.globalCdcOptions(config.cdc ?? false),
|
|
1438
1438
|
...(bookmark === undefined ? {} : { bookmark }),
|
|
@@ -1444,21 +1444,21 @@ ${I.map(s=>` [${JSON.stringify(s.id)}, () => import("../${s.filePath}
|
|
|
1444
1444
|
return readUserId();
|
|
1445
1445
|
},
|
|
1446
1446
|
};
|
|
1447
|
-
const globalDb: DatabaseWriterLike = ${
|
|
1448
|
-
`:"",
|
|
1447
|
+
const globalDb: DatabaseWriterLike = ${he}?.(env, globalRequest) ?? globalDbStub;
|
|
1448
|
+
`:"",Et=Jr(O&&T,he),Ct=m?` protected override roomHandlerPath(topic: string): string | undefined {
|
|
1449
1449
|
// Own properties only: a plain object would resolve \`toString\` and the like to inherited functions.
|
|
1450
1450
|
return Object.hasOwn(LUNORA_ROOMS, topic) ? LUNORA_ROOMS[topic] : undefined;
|
|
1451
1451
|
}
|
|
1452
|
-
`:"",
|
|
1452
|
+
`:"",Lt=f?` protected override socketRoute(path: string): { auth: boolean; functionPath: string } | undefined {
|
|
1453
1453
|
return LUNORA_SOCKETS[path];
|
|
1454
1454
|
}
|
|
1455
|
-
`:"",{externalSourceOverride:
|
|
1455
|
+
`:"",{externalSourceOverride:Pt,sourceBootstrap:Nt,sourceClientCacheConst:$t}=Yr(N),Mt=`
|
|
1456
1456
|
private shardInitDeferred = false;
|
|
1457
1457
|
private deferredShardInit?: Promise<void>;
|
|
1458
1458
|
|
|
1459
1459
|
protected override async runShardInit(): Promise<void> {
|
|
1460
1460
|
this.ensureMigrated();
|
|
1461
|
-
${
|
|
1461
|
+
${de?` clearMemoryTables(this.sql as SqlExec, schema as unknown as SchemaLike);
|
|
1462
1462
|
`:""}
|
|
1463
1463
|
if (this.blockedUniqueIndexes.length > 0) {
|
|
1464
1464
|
this.shardInitDeferred = true;
|
|
@@ -1498,11 +1498,11 @@ ${ie?` clearMemoryTables(this.sql as SqlExec, schema as unknown as Sc
|
|
|
1498
1498
|
|
|
1499
1499
|
await this.deferredShardInit;
|
|
1500
1500
|
}
|
|
1501
|
-
`,
|
|
1501
|
+
`,qt=ce.length>0?`
|
|
1502
1502
|
if (LUNORA_TTL_SWEEPS.length > 0) {
|
|
1503
1503
|
void this.scheduleTtlSweep();
|
|
1504
1504
|
}
|
|
1505
|
-
`:"",
|
|
1505
|
+
`:"",Ft=`
|
|
1506
1506
|
public constructor(state: ShardDOState, env: unknown) {
|
|
1507
1507
|
super(state, env, {
|
|
1508
1508
|
// Every writer this file builds spreads the ctxDbTuning() slice —
|
|
@@ -1519,7 +1519,10 @@ ${ie?` clearMemoryTables(this.sql as SqlExec, schema as unknown as Sc
|
|
|
1519
1519
|
// exists — a trigger that fails first still flushes and fuses.
|
|
1520
1520
|
...(config.observability === undefined ? {} : { telemetrySink: () => config.observability?.((env ?? {}) as Record<string, unknown>) }),
|
|
1521
1521
|
});
|
|
1522
|
-
${
|
|
1522
|
+
${C?` for (const path of LUNORA_IP_READER_PATHS) {
|
|
1523
|
+
this.ipKeyedFunctionPaths.add(path);
|
|
1524
|
+
}
|
|
1525
|
+
`:""}${Nt}${qt} }
|
|
1523
1526
|
|
|
1524
1527
|
protected override isCacheableQuery(functionPath: string): boolean {
|
|
1525
1528
|
// NOT \`kind === "query"\` alone. A cache hit answers without running
|
|
@@ -1543,7 +1546,7 @@ ${Pt}${Mt} }
|
|
|
1543
1546
|
protected override isPaidFunction(functionPath: string): boolean {
|
|
1544
1547
|
return LUNORA_FUNCTIONS[functionPath]?.x402 !== undefined;
|
|
1545
1548
|
}
|
|
1546
|
-
`,
|
|
1549
|
+
`,pe=c?`
|
|
1547
1550
|
protected override prepareFunction(functionPath: string, reason: "rpc" | "subscription" | "stream" | "reactor"): Promise<void> | undefined {
|
|
1548
1551
|
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
1549
1552
|
const allowsInternal = reason === "reactor" || (reason === "rpc" && this.isSystemDispatch());
|
|
@@ -1558,14 +1561,14 @@ ${Pt}${Mt} }
|
|
|
1558
1561
|
|
|
1559
1562
|
return loadFunction(functionPath).then(() => undefined);
|
|
1560
1563
|
}
|
|
1561
|
-
`:"",
|
|
1564
|
+
`:"",Ut=pe===""?`
|
|
1562
1565
|
|
|
1563
|
-
`:`${
|
|
1564
|
-
`,
|
|
1566
|
+
`:`${pe}
|
|
1567
|
+
`,Bt=G?`
|
|
1565
1568
|
protected override sensitiveArgNames(functionPath: string): ReadonlySet<string> {
|
|
1566
|
-
const registered = LUNORA_FUNCTIONS[functionPath];${
|
|
1569
|
+
const registered = LUNORA_FUNCTIONS[functionPath];${D?`
|
|
1567
1570
|
const shape = functionPath.startsWith("__shape__:") ? LUNORA_SHAPES[functionPath.slice("__shape__:".length)] : undefined;`:""}
|
|
1568
|
-
const fromValidators = sensitiveArgumentNames(registered?.args ?? ${
|
|
1571
|
+
const fromValidators = sensitiveArgumentNames(registered?.args ?? ${D?"shape?.args ?? ":""}{});
|
|
1569
1572
|
|
|
1570
1573
|
if (registered?.sensitiveArgs === undefined) {
|
|
1571
1574
|
return fromValidators;
|
|
@@ -1574,22 +1577,22 @@ ${Pt}${Mt} }
|
|
|
1574
1577
|
return new Set([...registered.sensitiveArgs, ...fromValidators]);
|
|
1575
1578
|
}
|
|
1576
1579
|
|
|
1577
|
-
`:"",
|
|
1580
|
+
`:"",jt=Nr(c),Wt=c?` const preparation = this.prepareFunction(functionPath, "subscription");
|
|
1578
1581
|
if (preparation !== undefined) await preparation;
|
|
1579
|
-
`:"",
|
|
1582
|
+
`:"",Kt=Mr.replace("__PREPARE_FUNCTION__",Wt),Ht=Fr(m,c),Vt=re?`
|
|
1580
1583
|
const facade = db as unknown as Record<string, FacadeEntry>;
|
|
1581
1584
|
${d.tables.map(s=>` defineLazyFacade(db, ${JSON.stringify(s.name)});`).join(`
|
|
1582
1585
|
`)}
|
|
1583
|
-
`:"",
|
|
1586
|
+
`:"",Gt=`${v.everyBuild}${P.build}${J.build}
|
|
1584
1587
|
const secrets = createSecrets(env);
|
|
1585
|
-
`,
|
|
1586
|
-
secrets,`,
|
|
1588
|
+
`,Qt=`${v.everyFields}${P.contextField}${z.contextField}${J.contextField}
|
|
1589
|
+
secrets,`,zt=z.build,Jt=x?`
|
|
1587
1590
|
const live = {
|
|
1588
1591
|
publish: async (ref: { __lunoraLive: string; topic: string }, payload: unknown, publishOptions?: { shardKey?: string }): Promise<void> => {
|
|
1589
1592
|
await this.publishLiveFromAction(ref.topic, payload, { ...publishOptions, stream: ref.__lunoraLive });
|
|
1590
1593
|
},
|
|
1591
1594
|
};
|
|
1592
|
-
`:"",
|
|
1595
|
+
`:"",Yt=[...v.actionFields,...L.length>0?["services"]:[],...x?["live"]:[]],Xt=`${v.actionBuild}${Y.build}${Jt}`;return`${Dr}${$.join(`
|
|
1593
1596
|
`)}
|
|
1594
1597
|
|
|
1595
1598
|
type FunctionKind = "action" | "mutation" | "query";
|
|
@@ -1599,13 +1602,13 @@ interface FunctionReference {
|
|
|
1599
1602
|
}
|
|
1600
1603
|
|
|
1601
1604
|
/** Foreign-key columns per table (\`v.id("target")\` fields) for the data browser. */
|
|
1602
|
-
const LUNORA_TABLE_REFS = ${p(
|
|
1605
|
+
const LUNORA_TABLE_REFS = ${p(at,"Record<string, Record<string, string>>")};
|
|
1603
1606
|
|
|
1604
1607
|
/** Declared indexes per table (secondary, search, geo, rank, vector) for the schema viewer. */
|
|
1605
|
-
const LUNORA_TABLE_INDEXES = ${p(
|
|
1608
|
+
const LUNORA_TABLE_INDEXES = ${p(st,'Record<string, Array<{ fields: string[]; name: string; type: "geo" | "index" | "rank" | "search" | "vector"; unique?: boolean }>>')};
|
|
1606
1609
|
|
|
1607
1610
|
/** Columns per table (typed, with PK/FK markers) for the studio's schema diagram, served via \`__lunora_admin__:describeTable\`. */
|
|
1608
|
-
const LUNORA_TABLE_COLUMNS = ${p(
|
|
1611
|
+
const LUNORA_TABLE_COLUMNS = ${p(ot,`Record<
|
|
1609
1612
|
string,
|
|
1610
1613
|
Array<{
|
|
1611
1614
|
bucket?: string;
|
|
@@ -1622,16 +1625,16 @@ const LUNORA_TABLE_COLUMNS = ${p(st,`Record<
|
|
|
1622
1625
|
>`)};
|
|
1623
1626
|
|
|
1624
1627
|
/** Storage-key columns per table (\`v.storage(...)\` fields) for the file browser's records↔files join. */
|
|
1625
|
-
const LUNORA_STORAGE_COLUMNS = ${p(
|
|
1628
|
+
const LUNORA_STORAGE_COLUMNS = ${p(it,"Record<string, string[]>")};
|
|
1626
1629
|
|
|
1627
1630
|
/** Declarative TTL policies (\`.ttl(field, { after? })\`) the DO alarm sweep auto-expires rows for. */
|
|
1628
|
-
const LUNORA_TTL_SWEEPS = ${
|
|
1631
|
+
const LUNORA_TTL_SWEEPS = ${nr(ce,"Array<{ after?: number; field: string; softDeleteField?: string; table: string }>")};
|
|
1629
1632
|
|
|
1630
1633
|
/** Static schema advisories (computed by @lunora/advisor at codegen time) served via \`__lunora_admin__:getAdvisories\`. */
|
|
1631
|
-
const LUNORA_ADVISORY_RULES = ${p(
|
|
1634
|
+
const LUNORA_ADVISORY_RULES = ${p(Ve,"Record<string, Partial<AdvisoryFinding>>")};
|
|
1632
1635
|
|
|
1633
1636
|
/** Per-finding rows; rule-level text lives once in \`LUNORA_ADVISORY_RULES\` and is merged back on first read. */
|
|
1634
|
-
const LUNORA_ADVISORY_ROWS = ${p(
|
|
1637
|
+
const LUNORA_ADVISORY_ROWS = ${p(Ge,"Array<Partial<AdvisoryFinding> & { name: string }>")};
|
|
1635
1638
|
|
|
1636
1639
|
const LUNORA_ADVISORIES = ((): (() => AdvisoryFinding[]) => {
|
|
1637
1640
|
let cached: AdvisoryFinding[] | undefined;
|
|
@@ -1639,23 +1642,23 @@ const LUNORA_ADVISORIES = ((): (() => AdvisoryFinding[]) => {
|
|
|
1639
1642
|
})();
|
|
1640
1643
|
|
|
1641
1644
|
/** Every declared procedure (discovered by @lunora/codegen) served via \`__lunora_admin__:getAdvisorProcedures\` — the health map's denominator. */
|
|
1642
|
-
const LUNORA_ADVISOR_PROCEDURES = ${p(
|
|
1645
|
+
const LUNORA_ADVISOR_PROCEDURES = ${p(Qe,"AdvisorProcedure[]")};
|
|
1643
1646
|
|
|
1644
1647
|
/** Read-only RLS metadata (policies + roles discovered from \`.use(rls(...))\` chains) served via \`__lunora_admin__:rlsPolicies\` for the studio's RLS inspector. */
|
|
1645
|
-
const LUNORA_RLS_METADATA = ${p(
|
|
1646
|
-
${
|
|
1648
|
+
const LUNORA_RLS_METADATA = ${p(se,"RlsPoliciesResult")};
|
|
1649
|
+
${lt}
|
|
1647
1650
|
/** Read-only masking metadata (table + column + strategy discovered from \`.use(mask(...))\` chains) served via \`__lunora_admin__:maskPolicies\` for the studio's data-browser mask preview. */
|
|
1648
|
-
const LUNORA_MASK_METADATA = ${p(
|
|
1651
|
+
const LUNORA_MASK_METADATA = ${p(ze,"MaskPoliciesResult")};
|
|
1649
1652
|
|
|
1650
1653
|
/** Read-only storage access-rule metadata (discovered from \`.use(storageRules(...))\` chains) served via \`__lunora_admin__:storageRules\` for the studio's access-rules view. */
|
|
1651
|
-
const LUNORA_STORAGE_RULES = ${p(
|
|
1654
|
+
const LUNORA_STORAGE_RULES = ${p(Je,"StorageRulesResult")};
|
|
1652
1655
|
|
|
1653
1656
|
/** Which optional package-backed features this app wires up (discovered from imports / \`ctx.*\` reads / schema signals) served via \`__lunora_admin__:studioFeatures\` so the studio hides nav pages whose package isn't enabled. */
|
|
1654
|
-
const LUNORA_STUDIO_FEATURES = ${p(
|
|
1657
|
+
const LUNORA_STUDIO_FEATURES = ${p(Ye,"StudioFeaturesResult")};
|
|
1655
1658
|
|
|
1656
1659
|
/** How long a shard with a UNIQUE index blocked by duplicate rows serves the cached diagnostic before re-attempting the build. */
|
|
1657
1660
|
const BLOCKED_MIGRATION_RETRY_MS = 5000;
|
|
1658
|
-
${
|
|
1661
|
+
${ye}${Z.constant}${Q.constant}${Xe}${et}${rt}${Ee}${Ne}${Re}${De}${Y.specs}${Fe}
|
|
1659
1662
|
export interface ShardDOConfig {
|
|
1660
1663
|
/** Opt into change-data-capture: records a post-image to \`__cdc_log\` on every write (backs streaming export + replay-PITR). */
|
|
1661
1664
|
cdc?: boolean;
|
|
@@ -1672,9 +1675,9 @@ export interface ShardDOConfig {
|
|
|
1672
1675
|
/** \`unknown\` because \`@lunora/scheduler\`'s \`Scheduler\` is not assignable to \`SchedulerLike\`; the shard casts it. */
|
|
1673
1676
|
scheduler?: (env: Record<string, unknown>) => unknown;
|
|
1674
1677
|
/** \`origin\` is the origin the current \`/rpc\` request reached the worker on — the fallback base for signed object URLs when no \`publicBaseUrl\` is configured. \`undefined\` off the synchronous dispatch path. */
|
|
1675
|
-
storage?: (env: Record<string, unknown>, origin?: string) => unknown;${
|
|
1678
|
+
storage?: (env: Record<string, unknown>, origin?: string) => unknown;${gt}${v.configFields}${P.configField}${Be}${bt}${yt}${wt}${Z.configField}
|
|
1676
1679
|
}
|
|
1677
|
-
${
|
|
1680
|
+
${M("schedulerStub",kt,["cancel","runAfter","runAt"])}${M("storageStub",St,["createMultipartUpload","delete","download","generateUploadUrl","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","list","resumeMultipartUpload","store","upload"],{sync:["getUrl","resumeMultipartUpload"]})}${Rt}${$t}${Ot}${v.stubs}${Ke}
|
|
1678
1681
|
// \`ctx.fetch\` is action-only. A query is re-run by every live subscription and a
|
|
1679
1682
|
// mutation may be replayed, so a network call in either returns a different answer
|
|
1680
1683
|
// on each run. Refused at runtime, not only linted: the advisor sees just the call
|
|
@@ -1686,24 +1689,24 @@ const refuseFetch = (): never => {
|
|
|
1686
1689
|
throw new LunoraError("FORBIDDEN", "ctx.fetch is action-only: network I/O belongs in an action, not a query or mutation");
|
|
1687
1690
|
};
|
|
1688
1691
|
|
|
1689
|
-
${
|
|
1692
|
+
${jt}
|
|
1690
1693
|
|
|
1691
1694
|
/**
|
|
1692
1695
|
* Build the project's shard Durable Object. Export the result as \`ShardDO\`
|
|
1693
1696
|
* from the worker entry so wrangler binds it by name.
|
|
1694
1697
|
*/
|
|
1695
1698
|
export const createShardDO = (config: ShardDOConfig = {}): new (state: ShardDOState, env: unknown) => ShardDOBase =>
|
|
1696
|
-
class extends ShardDOBase {${
|
|
1699
|
+
class extends ShardDOBase {${Ft}
|
|
1697
1700
|
private blockedUniqueIndexes: readonly string[] = [];
|
|
1698
1701
|
private migrated = false;
|
|
1699
|
-
private migrationRetryAt = 0;${
|
|
1700
|
-
${
|
|
1701
|
-
${
|
|
1702
|
-
${
|
|
1702
|
+
private migrationRetryAt = 0;${Ut}${Bt}${Ht}
|
|
1703
|
+
${le.override}
|
|
1704
|
+
${Kt}
|
|
1705
|
+
${dt}${ht}${Et}${Pt}
|
|
1703
1706
|
protected override lifecycleHookPaths(event: "connect" | "disconnect" | "init" | "reactor" | "whisper"): readonly string[] {
|
|
1704
1707
|
return LUNORA_LIFECYCLE_HOOKS[event];
|
|
1705
1708
|
}
|
|
1706
|
-
${
|
|
1709
|
+
${Ct}${Lt}${ue}${Z.override}${Mt}
|
|
1707
1710
|
// One \`onQueryChange\` dispatch. Mirrors \`executeSubscription\` — the
|
|
1708
1711
|
// socket-terminated half of the same reactivity — and differs only in who
|
|
1709
1712
|
// consumes the result: the base's \`dispatchReactors\` stores the digest as
|
|
@@ -1802,7 +1805,7 @@ ${c?` const requestScope = this.captureRequestScope();
|
|
|
1802
1805
|
protected override studioFeatures(): StudioFeaturesResult {
|
|
1803
1806
|
return LUNORA_STUDIO_FEATURES();
|
|
1804
1807
|
}
|
|
1805
|
-
${Q.evaluateOverride}${Q.subscriptionOverride}${
|
|
1808
|
+
${Q.evaluateOverride}${Q.subscriptionOverride}${Ze}${tt}${nt}
|
|
1806
1809
|
protected override advisories(): AdvisoryFinding[] {
|
|
1807
1810
|
return LUNORA_ADVISORIES();
|
|
1808
1811
|
}
|
|
@@ -1811,7 +1814,7 @@ ${Q.evaluateOverride}${Q.subscriptionOverride}${Xe}${et}${rt}
|
|
|
1811
1814
|
return LUNORA_ADVISOR_PROCEDURES();
|
|
1812
1815
|
}
|
|
1813
1816
|
|
|
1814
|
-
${
|
|
1817
|
+
${Lr}
|
|
1815
1818
|
|
|
1816
1819
|
/**
|
|
1817
1820
|
* Migrate the base schema. A UNIQUE index that existing duplicate rows block
|
|
@@ -1836,7 +1839,7 @@ ${Cr}
|
|
|
1836
1839
|
return;
|
|
1837
1840
|
}
|
|
1838
1841
|
|
|
1839
|
-
this.blockedUniqueIndexes = runShardMigrations(this.sql as SqlExec, schema as unknown as SchemaLike, { cdc: config.cdc ?? false, deferBlockedUniqueIndexes: true${
|
|
1842
|
+
this.blockedUniqueIndexes = runShardMigrations(this.sql as SqlExec, schema as unknown as SchemaLike, { cdc: config.cdc ?? false, deferBlockedUniqueIndexes: true${we} });
|
|
1840
1843
|
this.invalidateCompanionMemo();
|
|
1841
1844
|
this.migrated = this.blockedUniqueIndexes.length === 0;
|
|
1842
1845
|
this.migrationRetryAt = now + BLOCKED_MIGRATION_RETRY_MS;
|
|
@@ -1863,7 +1866,7 @@ ${te?`
|
|
|
1863
1866
|
|
|
1864
1867
|
return backfillSearchIndexes(this.sql as SqlExec, schema as unknown as SchemaLike, options);
|
|
1865
1868
|
}
|
|
1866
|
-
`:""}${
|
|
1867
|
-
${
|
|
1869
|
+
`:""}${xt}
|
|
1870
|
+
${Pr({hasSensitiveArgs:G,lazyFunctions:c,actionOnlyFields:Yt,agentsBuild:$e,agentsContextField:Me,containersBuild:Te,containersContextField:_e,databaseOptions:Dt,everyContextBuild:Gt,everyContextField:Qt,facadeBlock:Vt,globalDatabaseLine:It,notifyBuild:zt,ormContextField:_t,paymentsBuild:Ue,paymentsContextField:je,queuesBuild:ve,queuesContextField:ke,topicsBuild:xe,topicsContextField:Ae,vectorsBuild:At,vectorsContextField:Tt,workflowsBuild:Ce,workflowsContextField:Le,actionOnlyBuild:Xt})}
|
|
1868
1871
|
};
|
|
1869
|
-
`};export{
|
|
1872
|
+
`};export{Br as b,fn as e};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as k}from"@lunora/errors";import{r as b}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as R}from"./CAPABILITY_PROBES-DKYJ2K4t.mjs";import{a as l,G as f,I as w}from"./shared-
|
|
1
|
+
import{LunoraError as k}from"@lunora/errors";import{r as b}from"./json-data-Chfs2Cz5.mjs";import{CAPABILITIES as R}from"./CAPABILITY_PROBES-DKYJ2K4t.mjs";import{a as l,G as f,I as w}from"./shared-DhqnD5R3.mjs";import{s as S}from"./platform-8oj7iXQy.mjs";const Q=e=>e?{importFragment:"serveRelationFanout, ",override:`
|
|
2
2
|
protected override async runRelationFanoutRead(functionPath: string, args: Record<string, unknown>): Promise<unknown> {
|
|
3
3
|
this.ensureServable();
|
|
4
4
|
|