@lunora/codegen 1.0.0-alpha.250 → 1.0.0-alpha.251
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 +40 -61
- package/dist/index.d.ts +40 -61
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/CAPABILITY_PROBES-BbW-W0N2.mjs +22 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-qrQnFo7L.mjs +11 -0
- package/dist/packem_shared/emitAgents-DtZrevpx.mjs +1 -0
- package/dist/packem_shared/{emitApp-T_My13i6.mjs → emitApp-Cp0kB4-N.mjs} +21 -21
- package/dist/packem_shared/{emitServer-DQxwHVPM.mjs → emitServer-BOpHpi8r.mjs} +50 -54
- package/dist/packem_shared/{emitShard-BDfiH_JF.mjs → emitShard-HB5NPFdO.mjs} +1 -1
- package/dist/packem_shared/{shard-f7coQFS9.mjs → shard-CyNCZP7J.mjs} +60 -60
- package/dist/packem_shared/{shard-runtime-CyEbIjPA.mjs → shard-runtime-DMN3MgIM.mjs} +21 -21
- package/dist/packem_shared/sourceCapabilitySignals-oZFprILA.mjs +1 -0
- package/package.json +7 -7
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-jefy8GTn.mjs +0 -11
- package/dist/packem_shared/capabilities-CqnIsyA9.mjs +0 -20
- package/dist/packem_shared/contextPropertiesRead-BGy4tGCY.mjs +0 -1
- package/dist/packem_shared/emitAgents-3XP5C-VJ.mjs +0 -1
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import{relative as
|
|
2
|
-
`:"",
|
|
3
|
-
readonly
|
|
4
|
-
`:"",
|
|
5
|
-
readonly payments: LunoraPayment;`:"",ae=S?`import type { X402Pay } from "@lunora/x402/pay";
|
|
6
|
-
`:"",re=S?`
|
|
7
|
-
readonly x402: X402Pay;`:"",F=e=>e.sandbox===!0?"SandboxContainerAccessor":"ContainerAccessor",oe=[...new Set(r.map(e=>F(e)))].toSorted((e,a)=>e.localeCompare(a)),ne=r.length>0?`import type { ${oe.join(", ")} } from "@lunora/container";
|
|
8
|
-
`:"",se=r.length>0?`
|
|
1
|
+
import{relative as Ie,isAbsolute as $e,sep as Be}from"node:path";import{LunoraError as _}from"@lunora/errors";import{CAPABILITIES as Re}from"./CAPABILITY_PROBES-BbW-W0N2.mjs";import{p as Oe}from"./ir-DBSvhNa-.mjs";import{a as p,G as Ne,u as Ce,d as Me}from"./shared-DjUziztz.mjs";const De=/\.([cm]?)tsx?$/u,Ae=(l,i=[])=>{const r=new Set;for(const t of l.tables)for(const d of Object.values(t.shape)){const n=Ce(d);n.kind==="storage"&&typeof n.bucket=="string"&&n.bucket!==""&&r.add(n.bucket)}for(const t of i)t!==""&&t!=="default"&&r.add(t);return["default",...[...r].toSorted((t,d)=>t.localeCompare(d))]},Ee=({agents:l=[],capabilities:i=new Set,containers:r=[],env:t,hasVectors:d=!0,hasFlags:n=!1,hasNotify:H=!1,identity:s,queues:R=[],schema:O,generatedDirectory:N="",services:y=[],storageRuleBuckets:z=[],topics:C=[],useUmbrella:U=!1,workflows:M=[]}={})=>{const o=Me(U),D=i.has("payments"),J=Ae(O??{tables:[]},z).map(e=>JSON.stringify(e)).join(" | "),K=D?`import type { LunoraPayment } from "@lunora/payment";
|
|
2
|
+
`:"",Y=D?`
|
|
3
|
+
readonly payments: LunoraPayment;`:"",A=e=>e.sandbox===!0?"SandboxContainerAccessor":"ContainerAccessor",X=[...new Set(r.map(e=>A(e)))].toSorted((e,a)=>e.localeCompare(a)),Z=r.length>0?`import type { ${X.join(", ")} } from "@lunora/container";
|
|
4
|
+
`:"",ee=r.length>0?`
|
|
9
5
|
readonly containers: {${r.map(e=>`
|
|
10
|
-
readonly ${e.exportName}: ${
|
|
11
|
-
};`:"",
|
|
12
|
-
readonly ${e.bindingName}?: unknown;`)),...
|
|
6
|
+
readonly ${e.exportName}: ${A(e)};`).join("")}
|
|
7
|
+
};`:"",S=[...i.has("ai")?[" /** Workers AI binding (the conventional `env.AI`), narrowing `ctx.ai`. */\n readonly AI?: unknown;"]:[],...r.map(e=>(p(e.bindingName,`container binding "${e.bindingName}"`),` /** Durable Object namespace for the \`${e.exportName}\` container. */
|
|
8
|
+
readonly ${e.bindingName}?: unknown;`)),...R.map(e=>(p(e.bindingName,`queue binding "${e.bindingName}"`),` /** Queue producer binding for the \`${e.exportName}\` queue. */
|
|
13
9
|
readonly ${e.bindingName}?: unknown;`))].join(`
|
|
14
|
-
`),
|
|
10
|
+
`),te=`
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
13
|
* This project's Cloudflare bindings, as far as codegen can discover them from
|
|
@@ -24,24 +20,24 @@ import{relative as Ne,isAbsolute as Me,sep as Ae}from"node:path";import{LunoraEr
|
|
|
24
20
|
* surface, so treat them as \`Fetcher\`/\`Service<unknown>\` and cast.
|
|
25
21
|
*/
|
|
26
22
|
export interface CloudflareBindings {
|
|
27
|
-
readonly [binding: string]: unknown;${
|
|
28
|
-
${
|
|
23
|
+
readonly [binding: string]: unknown;${S?`
|
|
24
|
+
${S}`:""}
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
/** Alias for {@link CloudflareBindings} — the typed shape of \`env\`. */
|
|
32
|
-
export type Env = CloudflareBindings;`,
|
|
33
|
-
readonly vectors: VectorSearch<VectorIndexName>;`:"",
|
|
34
|
-
readonly vectors: VectorSearchReader<VectorIndexName>;`:"",
|
|
28
|
+
export type Env = CloudflareBindings;`,F=e=>Re.map(a=>a.serverCtxField!==void 0&&e.includes(a.tier)&&i.has(a.key)?a.serverCtxField:"").join(""),W=F(["every"]),ae=F(["every","action"]),c=d&&(O?.vectorIndexes.length??0)>0,m=c?' | "vectors"':"",Q=c?`
|
|
29
|
+
readonly vectors: VectorSearch<VectorIndexName>;`:"",re=c?`
|
|
30
|
+
readonly vectors: VectorSearchReader<VectorIndexName>;`:"",oe=c?`import type { VectorSearch, VectorSearchReader } from "${o.server}";
|
|
35
31
|
import type { VectorIndexName } from "./dataModel.js";
|
|
36
|
-
`:"",
|
|
32
|
+
`:"",h=n?`
|
|
37
33
|
/** Feature-flag evaluation (OpenFeature). Reads are memoized per request; evaluations never throw — a provider error resolves to the supplied default. */
|
|
38
|
-
readonly flags: import("${o.flags}").LunoraFlags;`:"",
|
|
34
|
+
readonly flags: import("${o.flags}").LunoraFlags;`:"",b=H?`
|
|
39
35
|
/** Multi-channel notifications (@lunora/notify): send / chat / inApp / webhook plus the push device sub-facade. Sends are external I/O — confine them to action handlers. */
|
|
40
36
|
readonly notify: import("@lunora/notify").LunoraNotify;
|
|
41
37
|
/** Device push sub-facade — the same object as ctx.notify.push (register / send / broadcast). Sends belong in action handlers. */
|
|
42
|
-
readonly push: import("@lunora/notify").LunoraPush;`:"",u=
|
|
38
|
+
readonly push: import("@lunora/notify").LunoraPush;`:"",u=M.length>0,ne=u?`import type { WorkflowHandle } from "@lunora/workflow";
|
|
43
39
|
import type * as lunoraWorkflowDefinitions from "../workflows.js";
|
|
44
|
-
`:"",
|
|
40
|
+
`:"",se=u?`
|
|
45
41
|
|
|
46
42
|
/** Params type carried by a \`defineWorkflow\` definition (its phantom \`__params\`). */
|
|
47
43
|
type WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params }
|
|
@@ -52,56 +48,56 @@ type WorkflowParamsOf<Definition> = Definition extends { __params?: infer Params
|
|
|
52
48
|
|
|
53
49
|
/** This project's declared workflows, addressable from \`ctx.workflows\` by their \`lunora/workflows.ts\` export name. */
|
|
54
50
|
export interface LunoraWorkflows {
|
|
55
|
-
${
|
|
51
|
+
${M.map(e=>` get(name: ${JSON.stringify(e.exportName)}): WorkflowHandle<WorkflowParamsOf<typeof lunoraWorkflowDefinitions.${e.exportName}>>;`).join(`
|
|
56
52
|
`)}
|
|
57
|
-
}`:"",
|
|
58
|
-
readonly workflows: LunoraWorkflows;`:"",
|
|
53
|
+
}`:"",j=u?' | "workflows"':"",P=u?`
|
|
54
|
+
readonly workflows: LunoraWorkflows;`:"",E=Oe(R),f=E.length>0,x=C.length>0,g=[...f?["QueueProducer"]:[],...x?["TopicPublisher"]:[]],ie=g.length>0?`import type { ${g.join(", ")} } from "@lunora/queue";
|
|
59
55
|
import type * as lunoraQueueDefinitions from "../queues.js";
|
|
60
|
-
`:"",
|
|
56
|
+
`:"",de=g.length>0?"\n\n/** Message body type carried by a `defineQueue` / `defineTopic` definition (its phantom `__lunoraBody`). */\ntype QueueBodyOf<Definition> = Definition extends { __lunoraBody?: infer Body } ? (unknown extends Body ? unknown : NonNullable<Body>) : unknown;":"",le=f?`
|
|
61
57
|
|
|
62
58
|
/** This project's declared queues, addressable from \`ctx.queues\` by their \`lunora/queues.ts\` export name. */
|
|
63
59
|
export interface LunoraQueues {
|
|
64
|
-
${
|
|
60
|
+
${E.map(e=>` readonly ${e.exportName}: QueueProducer<QueueBodyOf<typeof lunoraQueueDefinitions.${e.exportName}>>;`).join(`
|
|
65
61
|
`)}
|
|
66
|
-
}`:"",
|
|
62
|
+
}`:"",ce=x?`
|
|
67
63
|
|
|
68
64
|
/** This project's declared topics, addressable from \`ctx.topics\` by their \`lunora/queues.ts\` export name. */
|
|
69
65
|
export interface LunoraTopics {
|
|
70
|
-
${
|
|
66
|
+
${C.map(e=>` readonly ${e.exportName}: TopicPublisher<QueueBodyOf<typeof lunoraQueueDefinitions.${e.exportName}>>;`).join(`
|
|
71
67
|
`)}
|
|
72
|
-
}`:"",
|
|
73
|
-
readonly queues: LunoraQueues;`:"",
|
|
74
|
-
readonly topics: LunoraTopics;`:"",
|
|
75
|
-
${
|
|
76
|
-
`).join("")}`:"",
|
|
68
|
+
}`:"",ue=`${de}${le}${ce}`,q=f?`
|
|
69
|
+
readonly queues: LunoraQueues;`:"",L=x?`
|
|
70
|
+
readonly topics: LunoraTopics;`:"",T=y.length>0,pe=e=>{if(N==="")throw new _("INTERNAL","@lunora/codegen: emitServer needs `generatedDirectory` to import an RPC service's types");const a=Ie(N,e);if($e(a))throw new _("INTERNAL",`@lunora/codegen: an RPC service's entry (${e}) must be on the same drive as the app`);const B=a.split(Be).join("/").replace(De,".$1js");return B.startsWith(".")?B:`./${B}`},G=y.filter(e=>e.rpcEntrypoint!==void 0),ye=G.length>0?"ServiceFetcher, ServiceRpc":"ServiceFetcher",me=T?`import type { ${ye} } from "${o.server}";
|
|
71
|
+
${G.map(e=>`import type * as lunoraService_${e.name} from ${JSON.stringify(pe(e.main))};
|
|
72
|
+
`).join("")}`:"",he=T?`
|
|
77
73
|
|
|
78
74
|
/** This project's service bindings (\`lunora.config\` \`services\`), addressable from \`ctx.services\` in actions. */
|
|
79
75
|
export interface LunoraServices {
|
|
80
76
|
${y.map(e=>{p(e.name,`service "${e.name}"`);const a=e.rpcEntrypoint===void 0?"ServiceFetcher":`ServiceRpc<typeof lunoraService_${e.name}.${e.rpcEntrypoint}>`;return` readonly ${e.name}: ${a};`}).join(`
|
|
81
77
|
`)}
|
|
82
|
-
}`:"",
|
|
83
|
-
readonly services: LunoraServices;`:"",
|
|
84
|
-
`:"",
|
|
78
|
+
}`:"",be=T?`
|
|
79
|
+
readonly services: LunoraServices;`:"",v=l.length>0,fe=v?`import type { AgentHandle } from "@lunora/agent";
|
|
80
|
+
`:"",xe=v?`
|
|
85
81
|
|
|
86
82
|
/** This project's declared agents, addressable from \`ctx.agents\` by their \`lunora/agents.ts\` export name. */
|
|
87
83
|
export interface LunoraAgents {
|
|
88
84
|
${l.map(e=>(p(e.exportName,`agent export "${e.exportName}"`),` readonly ${e.exportName}: AgentHandle;`)).join(`
|
|
89
85
|
`)}
|
|
90
|
-
}`:"",
|
|
91
|
-
readonly agents: LunoraAgents;`:""
|
|
86
|
+
}`:"",V=v?`
|
|
87
|
+
readonly agents: LunoraAgents;`:"",ge=s?`import type { InferIdentity } from "${o.server}";
|
|
92
88
|
import type * as lunoraIdentityContract from "../identity.js";
|
|
93
|
-
`:"",
|
|
89
|
+
`:"",Te=s?`
|
|
94
90
|
|
|
95
91
|
/** This app's declared identity claim contract (\`defineIdentity\` in \`lunora/identity.ts\`) — the typed shape of \`ctx.auth.getIdentity()\`, the RLS policy \`ctx.auth.identity\`, and the \`authorizeShard\`/\`authorizeFanOut\` identity argument. */
|
|
96
|
-
export type Identity = InferIdentity<typeof lunoraIdentityContract.${
|
|
92
|
+
export type Identity = InferIdentity<typeof lunoraIdentityContract.${s.exportName}>;
|
|
97
93
|
|
|
98
94
|
/** \`ctx.auth\` narrowed so \`getIdentity()\` resolves the declared {@link Identity} contract instead of the untyped claim bag. */
|
|
99
|
-
type NarrowedAuth = Omit<QueryCtxBase["auth"], "getIdentity"> & { getIdentity: () => Promise<Identity | null> };`:"",
|
|
100
|
-
readonly auth: NarrowedAuth;`:"",
|
|
101
|
-
`:"",
|
|
95
|
+
type NarrowedAuth = Omit<QueryCtxBase["auth"], "getIdentity"> & { getIdentity: () => Promise<Identity | null> };`:"",k=s?' | "auth"':"",w=s?`
|
|
96
|
+
readonly auth: NarrowedAuth;`:"",ve=s?", Identity":"",ke=t?`import type * as lunoraEnvContract from "../env.js";
|
|
97
|
+
`:"",we=t?`
|
|
102
98
|
|
|
103
99
|
/** This app's declared env contract (\`defineEnv\` in \`lunora/env.ts\`) — the validated, coercion-aware shape of \`ctx.env\`. */
|
|
104
|
-
export type LunoraEnv = ReturnType<typeof lunoraEnvContract.${t.exportName}>;`:""
|
|
100
|
+
export type LunoraEnv = ReturnType<typeof lunoraEnvContract.${t.exportName}>;`:"",I=t?' | "env"':"",$=t?"\n /** Validated, typed environment declared by `defineEnv` in `lunora/env.ts` — parsed & coercion-aware config values (`ctx.env.STRIPE_KEY`); a missing or invalid value throws at read time. */\n readonly env: LunoraEnv;":"";return`${Ne}import { createPolicyDsl, defineMutator as defineMutatorBase, initLunora, v as vBase } from "${o.server}";
|
|
105
101
|
import type {
|
|
106
102
|
ActionBuilder,
|
|
107
103
|
ActionCtx as ActionCtxBase,
|
|
@@ -158,7 +154,7 @@ export type {
|
|
|
158
154
|
} from "${o.serverDataModel}";
|
|
159
155
|
|
|
160
156
|
import type { DataModel, Doc, GeoIndexNamesByTable, Id as IdOfTable, IndexNamesByTable, Insert, InsertModel, RankIndexNamesByTable, Relations, SearchIndexNamesByTable, TableName } from "./dataModel.js";
|
|
161
|
-
${
|
|
157
|
+
${oe}${K}${Z}${ne}${ie}${me}${fe}${ge}${ke}
|
|
162
158
|
export type { AppTableName, DataModel, Doc, Id, TableName } from "./dataModel.js";
|
|
163
159
|
|
|
164
160
|
/**
|
|
@@ -218,7 +214,7 @@ export interface OrmWriter extends OrmReader {
|
|
|
218
214
|
}
|
|
219
215
|
|
|
220
216
|
/** Storage buckets this schema declares (\`v.storage("name")\`), narrowing \`ctx.storage.bucket(name)\`. */
|
|
221
|
-
export type StorageBucketName = ${
|
|
217
|
+
export type StorageBucketName = ${J};${te}${se}${ue}${he}${xe}${Te}${we}
|
|
222
218
|
|
|
223
219
|
/**
|
|
224
220
|
* Project-typed contexts. The base contexts from \`@lunora/server\` are
|
|
@@ -281,22 +277,22 @@ type AsIdTable<T extends string> = T extends TableName ? T : string extends T ?
|
|
|
281
277
|
*/
|
|
282
278
|
type TypedAsId = <T extends string>(tableName: AsIdTable<T>, id: string) => IdOfTable<T & TableName>;
|
|
283
279
|
|
|
284
|
-
export interface QueryCtx extends Omit<QueryCtxBase, "db" | "storage"${
|
|
280
|
+
export interface QueryCtx extends Omit<QueryCtxBase, "db" | "storage"${m}${k}${I}> {
|
|
285
281
|
readonly db: Omit<DatabaseReader, "asId" | "query" | "get"> & DatabaseReaderFacade & { asId: TypedAsId; query: TypedTableQuery; get: TypedTableGet };
|
|
286
282
|
readonly orm: OrmReader;
|
|
287
|
-
readonly storage: ReadOnlyStorage<StorageBucketName>;${
|
|
283
|
+
readonly storage: ReadOnlyStorage<StorageBucketName>;${re}${W}${h}${b}${$}${w}
|
|
288
284
|
}
|
|
289
285
|
|
|
290
|
-
export interface MutationCtx extends Omit<MutationCtxBase, "db" | "storage"${
|
|
286
|
+
export interface MutationCtx extends Omit<MutationCtxBase, "db" | "storage"${m}${j}${k}${I}> {
|
|
291
287
|
readonly db: Omit<DatabaseWriter, "asId" | "query" | "get"> & DatabaseWriterFacade & { asId: TypedAsId; query: TypedTableQuery; get: TypedTableGet };
|
|
292
288
|
readonly orm: OrmWriter;
|
|
293
|
-
readonly storage: MutationStorage<StorageBucketName>;${
|
|
289
|
+
readonly storage: MutationStorage<StorageBucketName>;${Q}${W}${h}${b}${$}${P}${q}${L}${V}${w}
|
|
294
290
|
}
|
|
295
291
|
|
|
296
|
-
export interface ActionCtx extends Omit<ActionCtxBase, "db" | "storage"${
|
|
292
|
+
export interface ActionCtx extends Omit<ActionCtxBase, "db" | "storage"${m}${j}${k}${I}> {
|
|
297
293
|
readonly db: Omit<DatabaseWriter, "asId" | "query" | "get"> & DatabaseWriterFacade & { asId: TypedAsId; query: TypedTableQuery; get: TypedTableGet };
|
|
298
294
|
readonly orm: OrmWriter;
|
|
299
|
-
readonly storage: StorageBase<StorageBucketName>;${
|
|
295
|
+
readonly storage: StorageBase<StorageBucketName>;${Q}${ae}${Y}${ee}${h}${b}${be}${$}${P}${q}${L}${V}${w}
|
|
300
296
|
}
|
|
301
297
|
|
|
302
298
|
/**
|
|
@@ -354,7 +350,7 @@ export const defineMutator = defineMutatorBase as unknown as <Args extends Recor
|
|
|
354
350
|
* Runtime-identical to \`@lunora/server\`'s \`definePolicy\`; only the types narrow,
|
|
355
351
|
* so the \`rls()\` chain discovers a policy authored either way the same.
|
|
356
352
|
*/
|
|
357
|
-
export const definePolicy = createPolicyDsl<DataModel, Relations${
|
|
353
|
+
export const definePolicy = createPolicyDsl<DataModel, Relations${ve}>();
|
|
358
354
|
|
|
359
355
|
/**
|
|
360
356
|
* The validator builder \`v\`, with \`v.id(...)\` constrained to THIS schema's
|
|
@@ -371,4 +367,4 @@ export const definePolicy = createPolicyDsl<DataModel, Relations${Re}>();
|
|
|
371
367
|
export const v = vBase as unknown as Omit<typeof vBase, "id"> & {
|
|
372
368
|
id: <T extends TableName>(table: T) => ColumnValidator<IdOfTable<T>, IdOfTable<T>>;
|
|
373
369
|
};
|
|
374
|
-
`};export{
|
|
370
|
+
`};export{Ee 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-CyNCZP7J.mjs";import"./shard-runtime-DMN3MgIM.mjs";import"./shared-DjUziztz.mjs";export{f as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LunoraError as
|
|
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 Ot,a as Tt,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-DMN3MgIM.mjs";import{u as K,i as Ht,G as Vt,d as Kt}from"./shared-DjUziztz.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
|
|
@@ -30,7 +30,7 @@ import{LunoraError as xt}from"@lunora/errors";import{serializeSchemaSnapshot as
|
|
|
30
30
|
schema: schema as unknown as SchemaLike,
|
|
31
31
|
sql: this.sql as SqlExec,
|
|
32
32
|
});
|
|
33
|
-
}`,p=(
|
|
33
|
+
}`,p=(a="")=>` const writer = this.adminWriter(${a});`,Qt=`${Gt}
|
|
34
34
|
|
|
35
35
|
protected override async runShardDataMigration(args: RunShardMigrationArgs): Promise<MigrationRunResult> {
|
|
36
36
|
this.ensureMigrated();
|
|
@@ -225,11 +225,11 @@ ${p()}
|
|
|
225
225
|
await applyCdcChanges(writer, args.changes);
|
|
226
226
|
|
|
227
227
|
return { applied: args.changes.length };
|
|
228
|
-
}`,
|
|
228
|
+
}`,zt=({actionOnlyBuild:a,actionOnlyFields:r,agentsBuild:e,agentsContextField:n,containersBuild:t,containersContextField:o,databaseOptions:d,everyContextBuild:m,everyContextField:f,facadeBlock:c,globalDatabaseLine:w,notifyBuild:S,ormContextField:y,paymentsBuild:L,paymentsContextField:i,queuesBuild:g,queuesContextField:I,topicsBuild:_,topicsContextField:M,vectorsBuild:A,vectorsContextField:P,workflowsBuild:q,workflowsContextField:R})=>{const l=r.length>0,D=l?`
|
|
229
229
|
// ActionCtx-only helpers (external, non-deterministic I/O): constructed
|
|
230
230
|
// and attached only for an \`action\` so query/mutation ctx never carry them.
|
|
231
231
|
if (isAction) {
|
|
232
|
-
${
|
|
232
|
+
${a.replaceAll(/^(?=.)/gmu," ")}${r.map(k=>` ctx.${k} = ${k};`).join(`
|
|
233
233
|
`)}
|
|
234
234
|
}
|
|
235
235
|
`:"";return` private buildCtx(options: { bookmarks?: DispatchBookmark; functionPath?: string; headroom?: TransactionHeadroomTracker; identity?: SubscriptionIdentity; kind?: "query"; onRead?: (table: string, idOrScan?: string) => void; onReadRange?: (range: KeyRange) => void; scope?: QueryReadScope; trusted?: boolean } = {}): unknown {
|
|
@@ -253,7 +253,7 @@ ${n.replaceAll(/^(?=.)/gmu," ")}${r.map(k=>` ctx.${k} = ${k};`
|
|
|
253
253
|
userId: this.getCurrentUserId(),
|
|
254
254
|
};
|
|
255
255
|
const { identity, ip, userId } = caller;
|
|
256
|
-
${A}${m}${t}${
|
|
256
|
+
${A}${m}${t}${q}${g}${_}${e}
|
|
257
257
|
// Which dispatch this ctx belongs to. Drives the two deferral facades
|
|
258
258
|
// below and the \`ctx.run*\` caller guard; a ctx built for an
|
|
259
259
|
// admin/lifecycle path has no registered function, and so no kind. An
|
|
@@ -423,7 +423,7 @@ ${S}
|
|
|
423
423
|
scheduler,
|
|
424
424
|
span,
|
|
425
425
|
storage: contextStorage,
|
|
426
|
-
trace,${P}${f}${i}${o}${R}${I}${M}${
|
|
426
|
+
trace,${P}${f}${i}${o}${R}${I}${M}${n}
|
|
427
427
|
};
|
|
428
428
|
${l?` const isAction = contextKind === "action";
|
|
429
429
|
`:""}${D}
|
|
@@ -496,7 +496,7 @@ ${r.map(k=>` delete descriptors.${k};
|
|
|
496
496
|
installRun(ctx, contextKind);
|
|
497
497
|
|
|
498
498
|
return ctx;
|
|
499
|
-
}`},
|
|
499
|
+
}`},Xt=`// Bound in-process \`ctx.run*\` composition depth so a self- or cyclically-
|
|
500
500
|
// referencing call fails loudly with a clear error instead of overflowing the
|
|
501
501
|
// stack. Tracked across the awaited handler chain (one DO invocation is
|
|
502
502
|
// single-threaded), so the counter reflects true nesting depth.
|
|
@@ -562,7 +562,7 @@ const dispatchRun = async (
|
|
|
562
562
|
} finally {
|
|
563
563
|
runDepth -= 1;
|
|
564
564
|
}
|
|
565
|
-
};`,
|
|
565
|
+
};`,Jt=` public override async handleRpc(functionPath: string, args: Record<string, unknown>, headroom?: TransactionHeadroomTracker, scope?: QueryReadScope, bookmarks?: DispatchBookmark): Promise<unknown> {
|
|
566
566
|
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
567
567
|
|
|
568
568
|
// Internal functions are reachable server-side only: via \`ctx.run*\`
|
|
@@ -739,7 +739,7 @@ const dispatchRun = async (
|
|
|
739
739
|
// \`ctx.scheduler\` call that reached the buffer in the first place.
|
|
740
740
|
protected override scheduleOutboxScheduler(): SchedulerLike | undefined {
|
|
741
741
|
return config.scheduler?.((this.env ?? {}) as Record<string, unknown>) as SchedulerLike | undefined;
|
|
742
|
-
}`,
|
|
742
|
+
}`,Yt=` protected override async executeSubscription(functionPath: string, args: Record<string, unknown>, identity?: SubscriptionIdentity): Promise<{ ranges?: Map<string, KeyRange[]>; result: unknown; tables: Set<string> } | null> {
|
|
743
743
|
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
744
744
|
|
|
745
745
|
if (!registered || registered.kind !== "query" || registered.visibility === "internal") {
|
|
@@ -778,7 +778,7 @@ const dispatchRun = async (
|
|
|
778
778
|
// \`ctx.auth\` stream as nobody — or as a concurrent RPC's caller.
|
|
779
779
|
iterator: (signal) => (registered.handler as (context: unknown, args: Record<string, unknown>, signal: AbortSignal) => AsyncIterable<unknown>)(this.buildCtx({ functionPath, identity }), args, signal),
|
|
780
780
|
};
|
|
781
|
-
}`,
|
|
781
|
+
}`,Zt=a=>{const r={};for(const e of a.tables){const n={};for(const[t,o]of Object.entries(e.shape)){const d=K(o);d.kind==="id"&&d.tableName!==void 0&&(n[t]=d.tableName)}Object.keys(n).length>0&&(r[e.name]=n)}return r},er=a=>{const r={};for(const e of a.tables){const n=[];for(const[t,o]of Object.entries(e.shape))K(o).kind==="storage"&&n.push(t);n.length>0&&(r[e.name]=n)}return r},tr=a=>{const r={};for(const e of a.tables){const n=[...e.indexes.map(t=>({fields:[...t.fields],name:t.name,type:"index",...t.unique===!0?{unique:!0}:{}})),...e.searchIndexes.map(t=>({fields:[t.field,...t.filterFields??[]],name:t.name,type:"search"})),...(e.geoIndexes??[]).map(t=>({fields:[t.field],name:t.name,type:"geo"})),...e.rankIndexes.map(t=>({fields:t.sortBy.map(o=>o.field),name:t.name,type:"rank"})),...e.vectorIndexes.map(t=>({fields:t.field===void 0?[]:[t.field],name:t.name,type:"vector"}))];n.length>0&&(r[e.name]=n)}return r},rr=a=>{const r=[];for(const e of a.tables)!e.ttl||e.shardMode==="global"||r.push({...e.ttl.after===void 0?{}:{after:e.ttl.after},field:e.ttl.field,...e.softDelete?{softDeleteField:e.softDelete.field}:{},table:e.name});return r},ar=a=>{if(a.kind!=="union"||a.members===void 0||a.members.length===0)return;const r=[];for(const e of a.members){if(e.kind!=="literal"||e.literalValue===void 0)return;try{const n=JSON.parse(e.literalValue);if(typeof n!="string")return;r.push(n)}catch{return}}return r},nr=(a,r,e)=>{const n=K(r),t={name:a,optional:Ht(r),type:n.kind};if(n.kind==="id"&&n.tableName!==void 0){t.ref=n.tableName;const d=e.get(a);d!==void 0&&(t.onDelete=d)}n.kind==="storage"&&(t.isStorage=!0,n.bucket!==void 0&&(t.bucket=n.bucket));const o=ar(n);return o!==void 0&&(t.enumValues=o),n.column?.notNull===!1&&(t.nullable=!0),t},sr=a=>{const r={};for(const e of a.tables){const n=[{name:"_id",optional:!1,pk:!0,type:"id"},{name:"_creationTime",optional:!1,type:"number"},...e.commitOrdered===!0?[{name:"_commitSeq",optional:!1,type:"number"}]:[]],t=new Map(e.relations.filter(o=>o.kind==="one").map(o=>[o.field,o.onDelete]));for(const[o,d]of Object.entries(e.shape))n.push(nr(o,d,t));r[e.name]=n}return r},or=({hasMutators:a,hasShapes:r,rlsData:e})=>{const n=r?`
|
|
782
782
|
protected override resolveShape(name: string, args: Record<string, unknown>, identity?: SubscriptionIdentity): { columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string } | undefined {
|
|
783
783
|
const shape = LUNORA_SHAPES[name];
|
|
784
784
|
|
|
@@ -845,11 +845,11 @@ const dispatchRun = async (
|
|
|
845
845
|
`:"",t=r?[...new Set(e.policies.filter(c=>c.on==="read"&&c.table!=="").map(c=>c.table))].toSorted((c,w)=>c.localeCompare(w)):[],o=t.length>0?`
|
|
846
846
|
/** Refuses to boot a shape that would replicate around the read policies its table is governed by (\`defineShape({ use })\` is how a shape opts in; \`use: []\` acknowledges an ungoverned one). */
|
|
847
847
|
assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(t)}, (schema as unknown as { rlsMode?: string }).rlsMode === "required");
|
|
848
|
-
`:"";return{customMutatorOverride:
|
|
848
|
+
`:"";return{customMutatorOverride:a?`
|
|
849
849
|
protected override isCustomMutator(functionPath: string): boolean {
|
|
850
850
|
return LUNORA_MUTATOR_PATHS.has(functionPath);
|
|
851
851
|
}
|
|
852
|
-
`:"",shapeGuardImport:r?"assertShapeShardable, ":"",shapeReadPolicyAssertion:o,shapeReadPolicyImport:o===""?"":"assertShapesDeclareReadPolicies, ",shapeResolveOverride:
|
|
852
|
+
`:"",shapeGuardImport:r?"assertShapeShardable, ":"",shapeReadPolicyAssertion:o,shapeReadPolicyImport:o===""?"":"assertShapesDeclareReadPolicies, ",shapeResolveOverride:n}},ir=(a,r)=>a?`
|
|
853
853
|
protected override async readGlobalShapeRows(resolved: { columns?: readonly string[]; effectiveWhere?: WhereInput; global?: boolean; table: string }, identity?: SubscriptionIdentity): Promise<Array<{ doc: Record<string, unknown>; id: string }>> {
|
|
854
854
|
const env = this.env as Record<string, unknown>;
|
|
855
855
|
// A shape read performs no writes, so the widened request only needs
|
|
@@ -908,7 +908,7 @@ assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(t)}, (schema as
|
|
|
908
908
|
|
|
909
909
|
return globalDb.cdcChangedTables?.(sinceSeq, { cursorOnly });
|
|
910
910
|
}
|
|
911
|
-
`:"",
|
|
911
|
+
`:"",dr=a=>({externalSourceOverride:a?`
|
|
912
912
|
protected override async pollExternalSources(trace?: TraceRefLike): Promise<number | undefined> {
|
|
913
913
|
const env = (this.env ?? {}) as Record<string, unknown>;
|
|
914
914
|
const sourced = Object.entries((schema as unknown as SchemaLike).tables)
|
|
@@ -1048,7 +1048,7 @@ assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(t)}, (schema as
|
|
|
1048
1048
|
|
|
1049
1049
|
return nextDueAt;
|
|
1050
1050
|
}
|
|
1051
|
-
`:"",sourceBootstrap:
|
|
1051
|
+
`:"",sourceBootstrap:a?`
|
|
1052
1052
|
const autoSourced = Object.values((schema as unknown as SchemaLike).tables).some((definition) => {
|
|
1053
1053
|
const source = (definition as { externalSource?: ExternalSourceLike }).externalSource;
|
|
1054
1054
|
|
|
@@ -1058,11 +1058,11 @@ assertShapesDeclareReadPolicies(LUNORA_SHAPES, ${JSON.stringify(t)}, (schema as
|
|
|
1058
1058
|
if (autoSourced) {
|
|
1059
1059
|
void this.scheduleSourcePoll();
|
|
1060
1060
|
}
|
|
1061
|
-
`:"",sourceClientCacheConst:
|
|
1061
|
+
`:"",sourceClientCacheConst:a?`
|
|
1062
1062
|
const sourceClientCache = new WeakMap<object, Map<string, SourceClientLike>>();
|
|
1063
1063
|
const sourcePollAtCache = new WeakMap<object, Map<string, number>>();
|
|
1064
|
-
`:""}),
|
|
1065
|
-
`:"",d=e?"namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey, ":"",f=`, { ${["deferAfterCommit: (work) => this.deferAfterCommit(work)",...e?["namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey",`shardedIndexNames: [${r.map(S=>JSON.stringify(S)).join(", ")}]`]:[]].join(", ")} }`,c=
|
|
1064
|
+
`:""}),cr=(a,r)=>{const e=r.length>0,t=a?C("vectorsStub: VectorSearchLike",'throw new Error("ctx.vectors: no vectors configured. Pass `vectors` to createShardDO().");',["deleteByIds","getByIds","query","upsert","upsertNow"]):"",o=e?` const vectorShardKey = this.currentShardKey();
|
|
1065
|
+
`:"",d=e?"namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey, ":"",f=`, { ${["deferAfterCommit: (work) => this.deferAfterCommit(work)",...e?["namespace: vectorShardKey === ROOT_SHARD_NAME ? undefined : vectorShardKey",`shardedIndexNames: [${r.map(S=>JSON.stringify(S)).join(", ")}]`]:[]].join(", ")} }`,c=a?`
|
|
1066
1066
|
const vectorSync = this.vectorSync(env);
|
|
1067
1067
|
// Vectorize lives outside this shard's SQLite, so a query whose result
|
|
1068
1068
|
// depends on a similarity search cannot be proven current on reconnect —
|
|
@@ -1072,7 +1072,7 @@ const sourcePollAtCache = new WeakMap<object, Map<string, number>>();
|
|
|
1072
1072
|
const bareVectors = vectorSync?.vectors ?? vectorsStub;
|
|
1073
1073
|
const vectors = markUnvouchableReads(bareVectors, options.onRead, ["getByIds", "query"]);
|
|
1074
1074
|
const onWrite = vectorSync?.onWrite;
|
|
1075
|
-
`:"";return{vectorSyncMethod:
|
|
1075
|
+
`:"";return{vectorSyncMethod:a?`
|
|
1076
1076
|
private vectorSync(env: Record<string, unknown>): { backfill: VectorBackfillSync; onWrite: WriteHook; vectors: VectorSearchLike } | undefined {
|
|
1077
1077
|
if (!config.vectors) {
|
|
1078
1078
|
return undefined;
|
|
@@ -1105,14 +1105,14 @@ ${o} const vectors = createContextVectors(lunora${f});
|
|
|
1105
1105
|
ordered: async (read, work) => this.runOrderedAfterWrites(read, work),
|
|
1106
1106
|
});
|
|
1107
1107
|
}
|
|
1108
|
-
`:"",vectorsBuild:c,vectorsStub:t}},
|
|
1108
|
+
`:"",vectorsBuild:c,vectorsStub:t}},kr=({advisories:a=[],advisorProcedures:r=[],agents:e=[],capabilities:n=new Set,containers:t=[],env:o,flagKeys:d=[],hasFlags:m=!1,hasNotify:f=!1,hasVectors:c=!0,maskMetadata:w,mutators:S=[],queues:y=[],rlsMetadata:L,schema:i,schemaSnapshot:g,shapes:I=[],storageRules:_,studioFeatures:M,services:A=[],topics:P=[],useUmbrella:q=!1,workflows:R=[]})=>{const l=Kt(q),D=S.length>0,v=I.length>0,k=g===void 0?"":kt(g),te=g===void 0?"":`
|
|
1109
1109
|
/** 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. */
|
|
1110
|
-
const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.stringify(
|
|
1111
|
-
`,re=g===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",b=
|
|
1112
|
-
vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",
|
|
1113
|
-
d1?: (env: Record<string, unknown>, request?: { bookmark?: string; cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown>; onBookmark?: (bookmark: string | undefined) => void; userId?: string }) => DatabaseWriterLike | undefined;`:"",
|
|
1114
|
-
hyperdriveGlobal?: (env: Record<string, unknown>, request?: { cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown>; userId?: string }) => DatabaseWriterLike | undefined;`:"",
|
|
1115
|
-
sourceClient?: (env: Record<string, unknown>, binding: string) => { query: <Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) => Promise<Row[]> } | undefined;`:"",
|
|
1110
|
+
const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.stringify(St(g))}, json: ${JSON.stringify(k)} };
|
|
1111
|
+
`,re=g===void 0?"":", schemaSnapshot: LUNORA_SCHEMA_SNAPSHOT",b=Ot(n),O=Tt(m,l.flags),N=Et(d,m,l.flags),$=jt(f),F=Ct(o),{build:ae,contextField:ne,importLines:se,specs:oe}=Lt(At(y)),{build:ie,contextField:de,importLines:ce,specs:le}=It(P,y),U=_t(A,l.server),{build:he,contextField:ue,importLines:pe,specs:me}=Mt(t,i.jurisdiction),{build:ge,contextField:be,importLines:fe,specs:we}=Pt(R),{build:ye,contextField:ve,importLines:ke,specs:Se}=qt(e),{build:Re,configField:xe,contextField:Ae,imports:De,stub:Oe}=Nt(n.has("payments")),Te=a,Ee=r,G=L??{policies:[],roles:[]},Ce=w??{columns:[]},Le=_??{rules:[]},Ie=M??{analytics:!1,auth:!1,containers:!1,flags:!1,kv:!1,mail:!1,notifications:!1,payments:!1,queues:!1,scheduler:!1,storage:!1,vectors:!1,workflows:!1},{constant:_e,override:Me}=$t(R),{constant:Pe,override:qe}=Ft(y),u=c&&i.vectorIndexes.length>0,B=new Set(i.tables.filter(s=>Dt(s)).map(s=>s.name)),Q=u&&i.vectorIndexes.some(s=>B.has(s.table)),x=i.tables.some(s=>s.shardMode==="global"),W=Ut(B),j=i.tables.some(s=>Rt(s)),z=i.tables.some(s=>xt(s)),T=i.tables.some(s=>s.externalSource!==void 0),X=i.tables.some(s=>s.memory===!0),H=i.tables.some(s=>s.shardMode!=="global"&&s.searchIndexes.length>0);if(z&&j)throw new vt("INTERNAL",'lunora codegen: mixing `.global()` (D1) and `.global({ backend: "hyperdrive" })` tables in one app is not supported yet — use a single global backend.');const V=i.tables.length>0,Ne=Zt(i),$e=tr(i),Fe=sr(i),Ue=er(i),J=rr(i),Y=Bt(u,R.length>0,y.length>0,m,H);v&&Y.push("WhereInput");const Z=Wt(x),{customMutatorOverride:Be,shapeGuardImport:We,shapeReadPolicyAssertion:je,shapeReadPolicyImport:He,shapeResolveOverride:Ve}=or({hasMutators:D,hasShapes:v,rlsData:G}),E=[`import type { ${Y.join(", ")} } from "${l.do}";`,`import { applyCdcChanges, ${H?"backfillSearchIndexes, ":""}${u?"backfillVectorIndexes, ":""}buildReprojectionMigration, ${X?"clearMemoryTables, ":""}${We}createReadFootprint, createShardCtxDb, exportShardRows, importShardRows, ${T?"isSourceDue, pullExternalSourceIncrementalTick, pullExternalSourceTick, ":""}markUnvouchableReads, ${Q?"ROOT_SHARD_NAME, ":""}runDataMigration, runShardMigrations, ${Z.importFragment}ShardDO as ShardDOBase } from "${l.do}";`,...T?[`import type { ExternalSourceLike, SourceClientLike, TraceRefLike } from "${l.do}";`]:[],v?`import { asBucketStorage, ${He}beginDeferredDeletes, beginDeferredSchedules, composeShapeReadWhere, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${l.server}";`:`import { asBucketStorage, beginDeferredDeletes, beginDeferredSchedules, createSecrets, flushDeferredDeletes, LunoraError, withDeferredDeletes, withDeferredSchedules } from "${l.server}";`];V&&E.push(`import { bindOrm, bindTableFacade } from "${l.server}";`),u&&E.push('import type { SchemaLike as VectorSchemaLike, VectorBackfillSync, VectorizeIndexLike, VectorSearchLike } from "@lunora/bindings/vectors";','import { createContextVectors, createVectorBackfillSync, createVectors, createVectorSyncHook, vectorBackfillTargets } from "@lunora/bindings/vectors";'),E.push(...b.importLines,...O.importLines,...$.importLines,...F.importLines,...pe,...fe,...se,...ce,...U.importLines,...ke,...De,"",'import schema from "../schema.js";',`import { ${["LUNORA_FUNCTIONS","LUNORA_LIFECYCLE_HOOKS","LUNORA_MIGRATIONS",...D?["LUNORA_MUTATOR_PATHS"]:[],...v?["LUNORA_SHAPES"]:[]].join(", ")} } from "./functions.js";`);const Ke=u?`
|
|
1112
|
+
vectors?: (env: Record<string, unknown>) => Record<string, VectorizeIndexLike>;`:"",Ge=z?`
|
|
1113
|
+
d1?: (env: Record<string, unknown>, request?: { bookmark?: string; cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown>; onBookmark?: (bookmark: string | undefined) => void; userId?: string }) => DatabaseWriterLike | undefined;`:"",Qe=j?`
|
|
1114
|
+
hyperdriveGlobal?: (env: Record<string, unknown>, request?: { cdc?: boolean; cdcRetentionMs?: number; identity?: Record<string, unknown>; userId?: string }) => DatabaseWriterLike | undefined;`:"",ze=T?`
|
|
1115
|
+
sourceClient?: (env: Record<string, unknown>, binding: string) => { query: <Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) => Promise<Row[]> } | undefined;`:"",Xe='throw new Error("ctx.db.<globalTable>: no global backend configured. Pass `d1` or `hyperdriveGlobal` to createShardDO().");',Je='throw new Error("ctx.scheduler: no scheduler configured. Pass `scheduler` to createShardDO().");',Ye='throw new Error("ctx.storage: no storage configured. Pass `storage` to createShardDO().");',Ze=x?C("globalDbStub: DatabaseWriterLike",Xe,["aggregate","count","delete","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","normalizeId","patch","query","rank","rankPage","replace"],{sync:["normalizeId","query"]}):"",{vectorSyncMethod:et,vectorsBuild:tt,vectorsStub:rt}=cr(u,Q?i.vectorIndexes.filter(s=>B.has(s.table)).map(s=>s.name):[]),at=`{
|
|
1116
1116
|
...this.ctxDbTuning(),
|
|
1117
1117
|
auth: { identity: identity ?? null, userId: userId ?? null },
|
|
1118
1118
|
broadcast: (delta) => {
|
|
@@ -1164,22 +1164,22 @@ const LUNORA_SCHEMA_SNAPSHOT: { hash: string; json: string } = { hash: ${JSON.st
|
|
|
1164
1164
|
sql: this.sql as SqlExec,
|
|
1165
1165
|
storage,${x?`
|
|
1166
1166
|
globalDb,`:""}
|
|
1167
|
-
}`,
|
|
1168
|
-
vectors,`:"",
|
|
1169
|
-
orm: bindOrm(facade),`:"",ee=j?"config.hyperdriveGlobal":"config.d1",
|
|
1167
|
+
}`,nt=u?`
|
|
1168
|
+
vectors,`:"",st=V?`
|
|
1169
|
+
orm: bindOrm(facade),`:"",ee=j?"config.hyperdriveGlobal":"config.d1",ot=x?` const globalRequest = { ...this.globalCdcOptions(config.cdc ?? false), bookmark: this.getInboundBookmark(), identity, onBookmark: (bookmarkValue: string | undefined) => { if (options.bookmarks !== undefined) { options.bookmarks.value = bookmarkValue; } }, userId };
|
|
1170
1170
|
const globalDb: DatabaseWriterLike = ${ee}?.(env, globalRequest) ?? globalDbStub;
|
|
1171
|
-
`:"",
|
|
1171
|
+
`:"",it=ir(v&&x,ee),{externalSourceOverride:dt,sourceBootstrap:ct,sourceClientCacheConst:lt}=dr(T),ht=`
|
|
1172
1172
|
protected override async runShardInit(): Promise<void> {
|
|
1173
1173
|
this.ensureMigrated();
|
|
1174
1174
|
${X?` clearMemoryTables(this.sql as SqlExec, schema as unknown as SchemaLike);
|
|
1175
1175
|
`:""}
|
|
1176
1176
|
await this.dispatchShardInit();
|
|
1177
1177
|
}
|
|
1178
|
-
`,
|
|
1178
|
+
`,ut=J.length>0?`
|
|
1179
1179
|
if (LUNORA_TTL_SWEEPS.length > 0) {
|
|
1180
1180
|
void this.scheduleTtlSweep();
|
|
1181
1181
|
}
|
|
1182
|
-
`:"",
|
|
1182
|
+
`:"",pt=`
|
|
1183
1183
|
public constructor(state: ShardDOState, env: unknown) {
|
|
1184
1184
|
super(state, env, {
|
|
1185
1185
|
// Every writer this file builds spreads the ctxDbTuning() slice —
|
|
@@ -1192,7 +1192,7 @@ ${X?` clearMemoryTables(this.sql as SqlExec, schema as unknown as Sch
|
|
|
1192
1192
|
...(config.reactiveCache ? { reactiveCache: config.reactiveCache === true ? {} : config.reactiveCache } : {}),
|
|
1193
1193
|
...(config.relationExistsPushDown === undefined ? {} : { relationExistsPushDown: config.relationExistsPushDown }),
|
|
1194
1194
|
});
|
|
1195
|
-
${
|
|
1195
|
+
${ct}${ut} }
|
|
1196
1196
|
|
|
1197
1197
|
protected override isCacheableQuery(functionPath: string): boolean {
|
|
1198
1198
|
// NOT \`kind === "query"\` alone. A cache hit answers without running
|
|
@@ -1216,14 +1216,14 @@ ${pt}${bt} }
|
|
|
1216
1216
|
protected override isPaidFunction(functionPath: string): boolean {
|
|
1217
1217
|
return LUNORA_FUNCTIONS[functionPath]?.x402 !== undefined;
|
|
1218
1218
|
}
|
|
1219
|
-
`,
|
|
1219
|
+
`,mt=V?`
|
|
1220
1220
|
const facade = db as unknown as Record<string, ReturnType<typeof bindTableFacade>>;
|
|
1221
1221
|
${i.tables.map(s=>` facade[${JSON.stringify(s.name)}] = bindTableFacade(db, ${JSON.stringify(s.name)});`).join(`
|
|
1222
1222
|
`)}
|
|
1223
|
-
`:"",
|
|
1223
|
+
`:"",gt=`${b.everyBuild}${O.build}${F.build}
|
|
1224
1224
|
const secrets = createSecrets(env);
|
|
1225
|
-
`,
|
|
1226
|
-
secrets,`,
|
|
1225
|
+
`,bt=`${b.everyFields}${O.contextField}${$.contextField}${F.contextField}
|
|
1226
|
+
secrets,`,ft=$.build,wt=[...b.actionFields,...A.length>0?["services"]:[]],yt=`${b.actionBuild}${U.build}`;return`${Vt}${E.join(`
|
|
1227
1227
|
`)}
|
|
1228
1228
|
|
|
1229
1229
|
type FunctionKind = "action" | "mutation" | "query";
|
|
@@ -1233,13 +1233,13 @@ interface FunctionReference {
|
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
1235
|
/** Foreign-key columns per table (\`v.id("target")\` fields) for the data browser. */
|
|
1236
|
-
const LUNORA_TABLE_REFS = ${h(
|
|
1236
|
+
const LUNORA_TABLE_REFS = ${h(Ne,"Record<string, Record<string, string>>")};
|
|
1237
1237
|
|
|
1238
1238
|
/** Declared indexes per table (secondary, search, geo, rank, vector) for the schema viewer. */
|
|
1239
|
-
const LUNORA_TABLE_INDEXES = ${h(
|
|
1239
|
+
const LUNORA_TABLE_INDEXES = ${h($e,'Record<string, Array<{ fields: string[]; name: string; type: "geo" | "index" | "rank" | "search" | "vector"; unique?: boolean }>>')};
|
|
1240
1240
|
|
|
1241
1241
|
/** Columns per table (typed, with PK/FK markers) for the studio's schema diagram, served via \`__lunora_admin__:describeTable\`. */
|
|
1242
|
-
const LUNORA_TABLE_COLUMNS = ${h(
|
|
1242
|
+
const LUNORA_TABLE_COLUMNS = ${h(Fe,`Record<
|
|
1243
1243
|
string,
|
|
1244
1244
|
Array<{
|
|
1245
1245
|
bucket?: string;
|
|
@@ -1256,29 +1256,29 @@ const LUNORA_TABLE_COLUMNS = ${h(je,`Record<
|
|
|
1256
1256
|
>`)};
|
|
1257
1257
|
|
|
1258
1258
|
/** Storage-key columns per table (\`v.storage(...)\` fields) for the file browser's records↔files join. */
|
|
1259
|
-
const LUNORA_STORAGE_COLUMNS = ${h(
|
|
1259
|
+
const LUNORA_STORAGE_COLUMNS = ${h(Ue,"Record<string, string[]>")};
|
|
1260
1260
|
|
|
1261
1261
|
/** Declarative TTL policies (\`.ttl(field, { after? })\`) the DO alarm sweep auto-expires rows for. */
|
|
1262
1262
|
const LUNORA_TTL_SWEEPS = ${h(J,"Array<{ after?: number; field: string; softDeleteField?: string; table: string }>")};
|
|
1263
1263
|
|
|
1264
1264
|
/** Static schema advisories (computed by @lunora/advisor at codegen time) served via \`__lunora_admin__:getAdvisories\`. */
|
|
1265
|
-
const LUNORA_ADVISORIES = ${h(
|
|
1265
|
+
const LUNORA_ADVISORIES = ${h(Te,"AdvisoryFinding[]")};
|
|
1266
1266
|
|
|
1267
1267
|
/** Every declared procedure (discovered by @lunora/codegen) served via \`__lunora_admin__:getAdvisorProcedures\` — the health map's denominator. */
|
|
1268
|
-
const LUNORA_ADVISOR_PROCEDURES = ${h(
|
|
1268
|
+
const LUNORA_ADVISOR_PROCEDURES = ${h(Ee,"AdvisorProcedure[]")};
|
|
1269
1269
|
|
|
1270
1270
|
/** Read-only RLS metadata (policies + roles discovered from \`.use(rls(...))\` chains) served via \`__lunora_admin__:rlsPolicies\` for the studio's RLS inspector. */
|
|
1271
1271
|
const LUNORA_RLS_METADATA = ${h(G,"RlsPoliciesResult")};
|
|
1272
|
-
${
|
|
1272
|
+
${je}
|
|
1273
1273
|
/** 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. */
|
|
1274
|
-
const LUNORA_MASK_METADATA = ${h(
|
|
1274
|
+
const LUNORA_MASK_METADATA = ${h(Ce,"MaskPoliciesResult")};
|
|
1275
1275
|
|
|
1276
1276
|
/** Read-only storage access-rule metadata (discovered from \`.use(storageRules(...))\` chains) served via \`__lunora_admin__:storageRules\` for the studio's access-rules view. */
|
|
1277
|
-
const LUNORA_STORAGE_RULES = ${h(
|
|
1277
|
+
const LUNORA_STORAGE_RULES = ${h(Le,"StorageRulesResult")};
|
|
1278
1278
|
|
|
1279
1279
|
/** 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. */
|
|
1280
|
-
const LUNORA_STUDIO_FEATURES = ${h(
|
|
1281
|
-
${te}${W.constant}${
|
|
1280
|
+
const LUNORA_STUDIO_FEATURES = ${h(Ie,"StudioFeaturesResult")};
|
|
1281
|
+
${te}${W.constant}${N.constant}${_e}${Pe}${me}${we}${oe}${le}${U.specs}${Se}
|
|
1282
1282
|
export interface ShardDOConfig {
|
|
1283
1283
|
/** Opt into change-data-capture: records a post-image to \`__cdc_log\` on every write (backs streaming export + replay-PITR). */
|
|
1284
1284
|
cdc?: boolean;
|
|
@@ -1293,27 +1293,27 @@ export interface ShardDOConfig {
|
|
|
1293
1293
|
/** \`unknown\` because \`@lunora/scheduler\`'s \`Scheduler\` is not assignable to \`SchedulerLike\`; the shard casts it. */
|
|
1294
1294
|
scheduler?: (env: Record<string, unknown>) => unknown;
|
|
1295
1295
|
/** \`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. */
|
|
1296
|
-
storage?: (env: Record<string, unknown>, origin?: string) => unknown;${
|
|
1296
|
+
storage?: (env: Record<string, unknown>, origin?: string) => unknown;${Ke}${b.configFields}${O.configField}${xe}${Ge}${Qe}${ze}${W.configField}
|
|
1297
1297
|
}
|
|
1298
|
-
${C("schedulerStub",
|
|
1299
|
-
${
|
|
1298
|
+
${C("schedulerStub",Je,["cancel","runAfter","runAt"])}${C("storageStub",Ye,["delete","download","getMetadata","getSignedUrl","getUrl","head","list","upload"],{sync:["getUrl"]})}${Ze}${lt}${rt}${b.stubs}${Oe}
|
|
1299
|
+
${Xt}
|
|
1300
1300
|
|
|
1301
1301
|
/**
|
|
1302
1302
|
* Build the project's shard Durable Object. Export the result as \`ShardDO\`
|
|
1303
1303
|
* from the worker entry so wrangler binds it by name.
|
|
1304
1304
|
*/
|
|
1305
1305
|
export const createShardDO = (config: ShardDOConfig = {}): new (state: ShardDOState, env: unknown) => ShardDOBase =>
|
|
1306
|
-
class extends ShardDOBase {${
|
|
1306
|
+
class extends ShardDOBase {${pt}
|
|
1307
1307
|
private migrated = false;
|
|
1308
1308
|
|
|
1309
|
-
${
|
|
1309
|
+
${Jt}
|
|
1310
1310
|
${Z.override}
|
|
1311
|
-
${
|
|
1312
|
-
${
|
|
1311
|
+
${Yt}
|
|
1312
|
+
${Be}${Ve}${it}${dt}
|
|
1313
1313
|
protected override lifecycleHookPaths(event: "connect" | "disconnect" | "init" | "reactor" | "whisper"): readonly string[] {
|
|
1314
1314
|
return LUNORA_LIFECYCLE_HOOKS[event];
|
|
1315
1315
|
}
|
|
1316
|
-
${W.override}${
|
|
1316
|
+
${W.override}${ht}
|
|
1317
1317
|
// One \`onQueryChange\` dispatch. Mirrors \`executeSubscription\` — the
|
|
1318
1318
|
// socket-terminated half of the same reactivity — and differs only in who
|
|
1319
1319
|
// consumes the result: the base's \`dispatchReactors\` stores the digest as
|
|
@@ -1401,7 +1401,7 @@ ${W.override}${gt}
|
|
|
1401
1401
|
protected override studioFeatures(): StudioFeaturesResult {
|
|
1402
1402
|
return LUNORA_STUDIO_FEATURES;
|
|
1403
1403
|
}
|
|
1404
|
-
${
|
|
1404
|
+
${N.evaluateOverride}${N.subscriptionOverride}${Me}${qe}
|
|
1405
1405
|
protected override advisories(): AdvisoryFinding[] {
|
|
1406
1406
|
return LUNORA_ADVISORIES;
|
|
1407
1407
|
}
|
|
@@ -1410,7 +1410,7 @@ ${q.evaluateOverride}${q.subscriptionOverride}${Ne}${Be}
|
|
|
1410
1410
|
return LUNORA_ADVISOR_PROCEDURES;
|
|
1411
1411
|
}
|
|
1412
1412
|
|
|
1413
|
-
${
|
|
1413
|
+
${Qt}
|
|
1414
1414
|
|
|
1415
1415
|
protected override ensureMigrated(): void {
|
|
1416
1416
|
if (this.migrated) {
|
|
@@ -1429,7 +1429,7 @@ ${H?`
|
|
|
1429
1429
|
|
|
1430
1430
|
return backfillSearchIndexes(this.sql as SqlExec, schema as unknown as SchemaLike, options);
|
|
1431
1431
|
}
|
|
1432
|
-
`:""}${
|
|
1433
|
-
${
|
|
1432
|
+
`:""}${et}
|
|
1433
|
+
${zt({actionOnlyFields:wt,agentsBuild:ye,agentsContextField:ve,containersBuild:he,containersContextField:ue,databaseOptions:at,everyContextBuild:gt,everyContextField:bt,facadeBlock:mt,globalDatabaseLine:ot,notifyBuild:ft,ormContextField:st,paymentsBuild:Re,paymentsContextField:Ae,queuesBuild:ae,queuesContextField:ne,topicsBuild:ie,topicsContextField:de,vectorsBuild:tt,vectorsContextField:nt,workflowsBuild:ge,workflowsContextField:be,actionOnlyBuild:yt})}
|
|
1434
1434
|
};
|
|
1435
|
-
`};export{
|
|
1435
|
+
`};export{er as b,kr as e};
|