@lunora/codegen 1.0.0-alpha.42 → 1.0.0-alpha.421

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.
Files changed (130) hide show
  1. package/LICENSE.md +201 -104
  2. package/README.md +4 -4
  3. package/dist/index.d.mts +4583 -2045
  4. package/dist/index.d.ts +4583 -2045
  5. package/dist/index.mjs +1 -35
  6. package/dist/packem_shared/AGENTS_FILENAME-C4tHmiZZ.mjs +1 -0
  7. package/dist/packem_shared/ALL_NOTIFY_CHANNELS-BgkkvuUe.mjs +1 -0
  8. package/dist/packem_shared/CAPABILITY_PROBES-DCzOjTN7.mjs +25 -0
  9. package/dist/packem_shared/COMPANION_BINDING-Da_v9XpC.mjs +1 -0
  10. package/dist/packem_shared/CONTAINERS_FILENAME-d3XTFcqV.mjs +1 -0
  11. package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
  12. package/dist/packem_shared/DEFAULT_TARGET-CVYzxQ0y.mjs +1 -0
  13. package/dist/packem_shared/ENV_FILENAME-DJ11PXN5.mjs +1 -0
  14. package/dist/packem_shared/FLAGS_FILENAME-DeSjFBWq.mjs +1 -0
  15. package/dist/packem_shared/GENERATED_HEADER-DgrhC3Iv.mjs +1 -0
  16. package/dist/packem_shared/LUNORA_ERROR_CODES-D7AVT7qF.mjs +1 -0
  17. package/dist/packem_shared/MUTATORS_FILENAME-C0ZV0hh6.mjs +1 -0
  18. package/dist/packem_shared/OPENRPC_VERSION-BOBo0zdQ.mjs +3 -0
  19. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs +1 -0
  20. package/dist/packem_shared/QUEUES_FILENAME-DbuJZnrY.mjs +1 -0
  21. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CvXFQ6RH.mjs +57 -0
  22. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs +2 -0
  23. package/dist/packem_shared/SHAPES_FILENAME-BxRvP1ab.mjs +1 -0
  24. package/dist/packem_shared/SchemaSnapshotParseError-CV7mmuPi.mjs +17 -0
  25. package/dist/packem_shared/WORKFLOWS_FILENAME-7FysJsMZ.mjs +1 -0
  26. package/dist/packem_shared/attribution-Cwt30DDJ.mjs +1 -0
  27. package/dist/packem_shared/buildOpenApiDocument-DmV_PBFv.mjs +3 -0
  28. package/dist/packem_shared/capabilitiesUsedBy-BNvoiCu1.mjs +1 -0
  29. package/dist/packem_shared/classify-procedure-call-BmEirzc_.mjs +1 -0
  30. package/dist/packem_shared/companionServiceBinding-BZjm486n.mjs +1 -0
  31. package/dist/packem_shared/context-property-calls-BT1J7BqY.mjs +1 -0
  32. package/dist/packem_shared/context-root-BpDEhvNE.mjs +1 -0
  33. package/dist/packem_shared/createCodegenProject-dC6oJh5H.mjs +1 -0
  34. package/dist/packem_shared/database-calls-d-Sssc-3.mjs +1 -0
  35. package/dist/packem_shared/declared-output-Iaar469J.mjs +1 -0
  36. package/dist/packem_shared/describeErrorLevelFindings-DlkgCw8a.mjs +1 -0
  37. package/dist/packem_shared/discoverAuthApiCalls-CuqaLRa0.mjs +1 -0
  38. package/dist/packem_shared/discoverCrons-bT8F5GyL.mjs +1 -0
  39. package/dist/packem_shared/discoverFunctions-BNqI2S6a.mjs +1 -0
  40. package/dist/packem_shared/discoverHttpRoutes-CesuhqW1.mjs +1 -0
  41. package/dist/packem_shared/discoverHyperdriveCalls-BmAoOGGq.mjs +1 -0
  42. package/dist/packem_shared/discoverInserts-DIarYU2P.mjs +1 -0
  43. package/dist/packem_shared/discoverMaskProcedures-jkRrWS86.mjs +1 -0
  44. package/dist/packem_shared/discoverMigrations-C9AlZYFi.mjs +1 -0
  45. package/dist/packem_shared/discoverNondeterministicCalls-ZeZDQJAI.mjs +1 -0
  46. package/dist/packem_shared/discoverQueries-DLZHcDzB.mjs +1 -0
  47. package/dist/packem_shared/discoverR2sqlCalls-D_HWbbky.mjs +1 -0
  48. package/dist/packem_shared/discoverRlsMetadata-C0UkQkWd.mjs +1 -0
  49. package/dist/packem_shared/discoverRlsProcedures-BbSdCvmA.mjs +1 -0
  50. package/dist/packem_shared/discoverSandboxUsage-Dgvv6F_7.mjs +1 -0
  51. package/dist/packem_shared/discoverSchema-BLTROO8Z.mjs +1 -0
  52. package/dist/packem_shared/discoverStorageRulesMetadata-DeBgC7po.mjs +1 -0
  53. package/dist/packem_shared/dispatch-namespace-DwTjD7BU.mjs +1 -0
  54. package/dist/packem_shared/emitAgents-vWoT8-Yb.mjs +1 -0
  55. package/dist/packem_shared/emitApi-lwadq5G7.mjs +147 -0
  56. package/dist/packem_shared/emitApp-LFKtDRYu.mjs +1162 -0
  57. package/dist/packem_shared/emitCrons-CCRKs482.mjs +138 -0
  58. package/dist/packem_shared/emitDataModel-BvCZS4Yq.mjs +114 -0
  59. package/dist/packem_shared/emitDrizzleSchema-BzOChEYW.mjs +15 -0
  60. package/dist/packem_shared/emitFunctions-ppMX7E3X.mjs +528 -0
  61. package/dist/packem_shared/emitServer-CGRV_uIq.mjs +1 -0
  62. package/dist/packem_shared/emitShard-CDWgekIG.mjs +1 -0
  63. package/dist/packem_shared/exported-procedure-chains-CfH5jrzD.mjs +1 -0
  64. package/dist/packem_shared/fingerprintSchemaSources-TN-rU6Of.mjs +1 -0
  65. package/dist/packem_shared/formatAdvisories-Bue5tbp6.mjs +2 -0
  66. package/dist/packem_shared/handler-reference-BkOkxxg8.mjs +1 -0
  67. package/dist/packem_shared/index-CfSmiylg.mjs +1 -0
  68. package/dist/packem_shared/index-DFMCX2vk.mjs +1 -0
  69. package/dist/packem_shared/ip-reads-D4nRZgML.mjs +1 -0
  70. package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
  71. package/dist/packem_shared/isTestPath-Uwb5a6Kq.mjs +1 -0
  72. package/dist/packem_shared/isTypedSchema-CDv3pJB6.mjs +4 -0
  73. package/dist/packem_shared/json-data-Chfs2Cz5.mjs +1 -0
  74. package/dist/packem_shared/loadProjectConfig-BXwH3_gn.mjs +1 -0
  75. package/dist/packem_shared/module-specifiers-BctA0m_p.mjs +1 -0
  76. package/dist/packem_shared/modules-DdOd-7Wp.mjs +1 -0
  77. package/dist/packem_shared/parse-validator-BisfC8bR.mjs +1 -0
  78. package/dist/packem_shared/platform-8oj7iXQy.mjs +1 -0
  79. package/dist/packem_shared/policies-Dn_tuTZd.mjs +1 -0
  80. package/dist/packem_shared/project-config-file-DR7xrrNB.mjs +1 -0
  81. package/dist/packem_shared/property-name-7cBlgK_O.mjs +1 -0
  82. package/dist/packem_shared/qualifiers-qqH8fRTo.mjs +1 -0
  83. package/dist/packem_shared/readPackageDependencies-RHhGiz0k.mjs +1 -0
  84. package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
  85. package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
  86. package/dist/packem_shared/schema-BgM8A3XV.mjs +1 -0
  87. package/dist/packem_shared/schemaFromIr-CByOxuZb.mjs +1 -0
  88. package/dist/packem_shared/server-Dfxmm5Zw.mjs +377 -0
  89. package/dist/packem_shared/shard-CWAD5mYy.mjs +1897 -0
  90. package/dist/packem_shared/shard-runtime-G5mZQjY0.mjs +351 -0
  91. package/dist/packem_shared/shared-Cn7dMQ_u.mjs +13 -0
  92. package/dist/packem_shared/unwrap-handler-return-DvbyiLjc.mjs +1 -0
  93. package/dist/sdk/index.d.mts +288 -0
  94. package/dist/sdk/index.d.ts +288 -0
  95. package/dist/sdk/index.mjs +394 -0
  96. package/package.json +22 -9
  97. package/dist/packem_shared/CONTAINERS_FILENAME-DjpXMqhp.mjs +0 -224
  98. package/dist/packem_shared/CodegenDiagnosticError-DyQ5FwkM.mjs +0 -24
  99. package/dist/packem_shared/FLAGS_FILENAME-fEZtzWXi.mjs +0 -139
  100. package/dist/packem_shared/GENERATED_HEADER-D6RK1WF1.mjs +0 -3
  101. package/dist/packem_shared/LUNORA_ERROR_CODES-DvTLozCu.mjs +0 -68
  102. package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +0 -81
  103. package/dist/packem_shared/OPENRPC_VERSION-CzhfvCIQ.mjs +0 -60
  104. package/dist/packem_shared/QUEUES_FILENAME-Xv6Vy-Ku.mjs +0 -145
  105. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Cl1EBMdR.mjs +0 -3438
  106. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs +0 -249
  107. package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +0 -94
  108. package/dist/packem_shared/WORKFLOWS_FILENAME-B2By8S4s.mjs +0 -152
  109. package/dist/packem_shared/buildOpenApiDocument-bg-NnLka.mjs +0 -183
  110. package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
  111. package/dist/packem_shared/discoverAuthApiCalls-WMx8L2FG.mjs +0 -62
  112. package/dist/packem_shared/discoverCrons-D-jrpm97.mjs +0 -256
  113. package/dist/packem_shared/discoverFunctions-CZ91aenA.mjs +0 -518
  114. package/dist/packem_shared/discoverHttpRoutes-DNZLDCmm.mjs +0 -131
  115. package/dist/packem_shared/discoverInserts-DFRJhmCv.mjs +0 -61
  116. package/dist/packem_shared/discoverMaskProcedures-B5iFnZ-X.mjs +0 -273
  117. package/dist/packem_shared/discoverMigrations-CdKtMlBc.mjs +0 -97
  118. package/dist/packem_shared/discoverNondeterministicCalls-C_PrQPkA.mjs +0 -122
  119. package/dist/packem_shared/discoverQueries-B8W9UPrt.mjs +0 -62
  120. package/dist/packem_shared/discoverR2sqlCalls-Bm7Rfnf4.mjs +0 -80
  121. package/dist/packem_shared/discoverRlsMetadata-B4GL4ZKm.mjs +0 -280
  122. package/dist/packem_shared/discoverSchema-DFWVgU5o.mjs +0 -874
  123. package/dist/packem_shared/discoverStorageRulesMetadata-nosjYcvN.mjs +0 -97
  124. package/dist/packem_shared/emit-31Yg1Ee5.mjs +0 -3474
  125. package/dist/packem_shared/emitApp-DCP7Pr6M.mjs +0 -668
  126. package/dist/packem_shared/formatAdvisories-DRhEiJUz.mjs +0 -114
  127. package/dist/packem_shared/parse-validator-BSJo1HGP.mjs +0 -144
  128. package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
  129. package/dist/packem_shared/redact-oTmsol5A.mjs +0 -33
  130. package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
@@ -0,0 +1,138 @@
1
+ import{G as i,d as c}from"./shared-Cn7dMQ_u.mjs";import{i as g}from"./schema-BgM8A3XV.mjs";const f=r=>r?`${i}/**
2
+ * The \`SchedulerDO\` Durable Object class, re-exported so a worker entry can
3
+ * forward it — wrangler binds only what the entry exports:
4
+ *
5
+ * \`export * from "./lunora/_generated/scheduler.js";\`
6
+ *
7
+ * A Vite-first (class-A) app needs no such line: the generated worker entry
8
+ * forwards this module for you whenever it exists.
9
+ */
10
+ export { SchedulerDO } from "@lunora/scheduler";
11
+ `:"",u=(r,t,o)=>{if(!r.some(n=>g(n)))return"";const e=o?JSON.stringify(o):"undefined";return`${i}import { WorkerEntrypoint } from "cloudflare:workers";
12
+ import { hostedShardRegistry } from "${c(t).do}";
13
+
14
+ /**
15
+ * The \`ShardRegistryDO\` Durable Object class — the live set of shard keys per
16
+ * \`.shardBy()\` table, which cross-shard export, CDC sync and migrations fan out
17
+ * to. Re-exported so a worker entry can forward it (wrangler binds only what the
18
+ * entry exports), next to \`.shardRegistry((env) => env.SHARD_REGISTRY)\`:
19
+ *
20
+ * \`export { ShardRegistryDO } from "./lunora/_generated/shardRegistry.js";\`
21
+ *
22
+ * Name the class in a hand-written entry: binding inference provisions
23
+ * \`SHARD_REGISTRY\` off the entry's named exports, and cannot see through an
24
+ * \`export *\`. A Vite-first (class-A) app needs neither line — its generated
25
+ * worker entry does both whenever this module exists.
26
+ */
27
+ export { ShardRegistryDO } from "${c(t).do}";
28
+
29
+ /**
30
+ * The registry's RPC surface. A worker that calls a registry this worker hosts binds
31
+ * this class with a service binding (\`services: [{ binding, service, entrypoint:
32
+ * "ShardRegistryEntrypoint" }]\`), so it needs no secret: the binding is the capability.
33
+ * The host signs its own calls into the registry with its \`LUNORA_RELAY_SECRET\`.
34
+ */
35
+ export class ShardRegistryEntrypoint extends WorkerEntrypoint<{ SHARD_REGISTRY: unknown; LUNORA_RELAY_SECRET?: string }> {
36
+ public register(table: string, shardKey: string): Promise<void> {
37
+ return hostedShardRegistry(this.env, ${e}).register(table, shardKey);
38
+ }
39
+
40
+ public unregister(table: string, shardKey: string): Promise<void> {
41
+ return hostedShardRegistry(this.env, ${e}).unregister(table, shardKey);
42
+ }
43
+
44
+ public listShardKeys(table: string): Promise<string[]> {
45
+ return hostedShardRegistry(this.env, ${e}).listShardKeys(table);
46
+ }
47
+
48
+ public snapshot(): Promise<Record<string, string[]>> {
49
+ return hostedShardRegistry(this.env, ${e}).snapshot();
50
+ }
51
+ }
52
+ `},R=r=>`${i}/**
53
+ * The \`AdminRevocationDO\` Durable Object class: remembers revoked named admin
54
+ * tokens where a point-in-time restore of the default shard cannot rewind them.
55
+ * Re-exported so a worker entry can forward it (wrangler binds only what the
56
+ * entry exports), next to \`.adminRevocations((env) => env.ADMIN_REVOCATIONS)\`:
57
+ *
58
+ * \`export { AdminRevocationDO } from "./lunora/_generated/adminRevocations.js";\`
59
+ *
60
+ * Name the class in a hand-written entry: binding inference provisions
61
+ * \`ADMIN_REVOCATIONS\` off the entry's named exports, and cannot see through an
62
+ * \`export *\`. A Vite-first (class-A) app needs neither line. Without the
63
+ * binding no named admin token can be created, and any that exist are refused.
64
+ */
65
+ export { AdminRevocationDO } from "${c(r).do}";
66
+ `,b=r=>`${i}/**
67
+ * Host the shard, the scheduler, the shard registry and the admin revocation
68
+ * store in ONE Durable Object class, so the app spends one of the account's
69
+ * classes instead of four. A
70
+ * Vite-first (class-A) app needs nothing more: its generated worker entry builds
71
+ * \`LunoraDO\` from these. A hand-written entry does the same by hand:
72
+ *
73
+ * \`export const LunoraDO = mergeDurableObjects({ shard: app.ShardDO, scheduler: SchedulerDO, shardRegistry: ShardRegistryDO, adminRevocations: AdminRevocationDO });\`
74
+ *
75
+ * and passes \`roleNamespace(env.SHARD, "scheduler")\` / \`roleNamespace(env.SHARD, "shardRegistry")\` /
76
+ * \`roleNamespace(env.SHARD, "adminRevocations")\` to \`.scheduler()\` / \`.shardRegistry()\` / \`.adminRevocations()\`. Merge before the first deploy only:
77
+ * data already in \`ShardDO\` does not move, and a deployed merge cannot be undone.
78
+ */
79
+ export { mergeDurableObjects, roleNamespace } from "${c(r).do}";
80
+ `,w=r=>{const t=new Map;for(const s of r){const d=t.get(s.cron);d?d.push(s):t.set(s.cron,[s])}const o=[...t.keys()].map(s=>` ${JSON.stringify(s)},`).join(`
81
+ `),e=o.length>0?`
82
+ ${o}
83
+ `:"",n=[...t.entries()].map(([s,d])=>{const l=d.map(a=>{const m=a.workflow?`workflow: ${JSON.stringify(a.workflow.className)}`:`functionPath: ${JSON.stringify(a.functionPath)}`;return` { name: ${JSON.stringify(a.name)}, ${m}, args: ${JSON.stringify(a.args)} },`}).join(`
84
+ `);return` ${JSON.stringify(s)}: [
85
+ ${l}
86
+ ],`}).join(`
87
+ `),h=n.length>0?`
88
+ ${n}
89
+ `:"";return`${i}/**
90
+ * One scheduled cron invocation. Exactly one target is set: \`functionPath\` is
91
+ * the \`namespace:fn\` dispatch ref (matches \`__lunoraRef\`), invoked on the
92
+ * shard; \`workflow\` is a workflow class name (its \`ctx.exports\` key) whose durable workflow is
93
+ * started fresh per fire. \`args\` are forwarded verbatim (a workflow's become
94
+ * its \`params\`).
95
+ */
96
+ export interface LunoraCronJob {
97
+ args: Record<string, unknown>;
98
+ functionPath?: string;
99
+ name: string;
100
+ workflow?: string;
101
+ }
102
+
103
+ /**
104
+ * Deduplicated cron schedules — mirror of wrangler's \`triggers.crons\`. The
105
+ * Lunora vite plugin keeps \`wrangler.jsonc\` in sync with this array.
106
+ */
107
+ export const LUNORA_CRON_TRIGGERS: ReadonlyArray<string> = [${e}];
108
+
109
+ /**
110
+ * Dispatcher map keyed by cron expression. The Worker's \`scheduled()\` handler
111
+ * looks up \`event.cron\` here and dispatches every job in the list.
112
+ */
113
+ export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${h}};
114
+ `},S=r=>{const t=[...r].toSorted((e,n)=>e.name.localeCompare(n.name)).map(e=>{const n=[`name: ${JSON.stringify(e.name)}`,`table: ${JSON.stringify(e.table)}`];return e.field!==void 0&&n.push(`field: ${JSON.stringify(e.field)}`),e.dimensions!==void 0&&n.push(`dimensions: ${JSON.stringify(e.dimensions)}`),e.metric!==void 0&&n.push(`metric: ${JSON.stringify(e.metric)}`),e.metadata!==void 0&&n.push(`metadata: ${JSON.stringify(e.metadata)}`),` { ${n.join(", ")} },`}).join(`
115
+ `),o=t.length>0?`
116
+ ${t}
117
+ `:"";return`${i}/**
118
+ * One vector index declared in \`schema.ts\` — an inline \`.vectorize()\` column
119
+ * or a standalone \`defineVectorIndex()\`. \`field\` is the source column (absent
120
+ * for a \`select\`-derived Shape B index); \`metadata\` lists the row fields
121
+ * mirrored into Vectorize for filtering.
122
+ */
123
+ export interface LunoraVectorIndex {
124
+ dimensions?: number;
125
+ field?: string;
126
+ metadata?: ReadonlyArray<string>;
127
+ metric?: "cosine" | "dot-product" | "euclidean";
128
+ name: string;
129
+ table: string;
130
+ }
131
+
132
+ /**
133
+ * Static registry of every vector index in the schema, sorted by name.
134
+ * Vectorize cannot enumerate indexes at runtime, so the worker passes this to
135
+ * \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
136
+ */
137
+ export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${o}];
138
+ `},v=r=>[...new Set(r.map(t=>t.cron))];export{R as emitAdminRevocations,w as emitCrons,b as emitDurableObjects,f as emitScheduler,u as emitShardRegistry,S as emitVectors,v as emitWranglerCronTriggers};
@@ -0,0 +1,114 @@
1
+ import{r as k}from"./qualifiers-qqH8fRTo.mjs";import{a as i,e as o,v as d,f as v,G as M}from"./shared-Cn7dMQ_u.mjs";const _="schema",w=a=>{for(const e of a.tables)i(e.name,"table name");const l=a.tables.map(e=>`"${e.name}"`).join(" | ")||"never",m=a.tables.filter(e=>e.extensionKey===void 0).map(e=>`"${e.name}"`).join(" | ")||"never",p=a.tables.map(e=>{const t=Object.entries(e.shape).map(([g,r])=>{const s=o(g);if(r.kind==="optional"){const h=r.inner?d(r.inner):"unknown";return` ${s}?: ${h};`}return` ${s}: ${d(r)};`}).join(`
2
+ `),n=t?`
3
+ ${t}
4
+ `:"",N=e.commitOrdered===!0?`
5
+ _commitSeq: number;`:"";return`export interface Doc_${e.name} {
6
+ _id: Id<"${e.name}">;
7
+ _creationTime: number;${N}${n}}`}).join(`
8
+
9
+ `),c=a.tables.map(e=>` ${e.name}: Doc_${e.name};`).join(`
10
+ `),y=a.tables.map(e=>{const t=e.indexes.map(n=>JSON.stringify(n.name)).join(" | ");return` ${e.name}: ${t||"never"};`}).join(`
11
+ `),x=a.tables.map(e=>{const t=e.searchIndexes.map(n=>JSON.stringify(n.name)).join(" | ");return` ${e.name}: ${t||"never"};`}).join(`
12
+ `),b=a.tables.map(e=>{const t=e.rankIndexes.map(n=>JSON.stringify(n.name)).join(" | ");return` ${e.name}: ${t||"never"};`}).join(`
13
+ `),f=a.tables.map(e=>{const t=e.shardMode==="global"?"":(e.geoIndexes??[]).map(n=>JSON.stringify(n.name)).join(" | ");return` ${e.name}: ${t||"never"};`}).join(`
14
+ `),T=a.vectorIndexes.map(e=>JSON.stringify(e.name)).join(" | ")||"never",$=a.tables.map(e=>v(e)).join(`
15
+
16
+ `),u=a.tables.map(e=>` ${e.name}: Insert_${e.name};`).join(`
17
+ `),I=a.tables.map(e=>{const t=e.relations.map(n=>(i(n.table,"relation target table"),n.kind==="one"?` ${o(n.name)}: OneRelation<"${n.table}", ${JSON.stringify(n.field)}>;`:` ${o(n.name)}: ManyRelation<"${n.table}">;`)).join(`
18
+ `);return t?` ${e.name}: {
19
+ ${t}
20
+ };`:` ${e.name}: {};`}).join(`
21
+ `);return k(`${M}export type TableName = ${l};
22
+
23
+ /**
24
+ * The tables **this app declared** — every {@link TableName} except those an add-on
25
+ * contributed through \`defineSchema(...).extend(...)\`.
26
+ *
27
+ * An add-on's tables are real tables and stay in \`TableName\` (they are queryable,
28
+ * they appear in \`DataModel\`), but an app enumerating "my tables" should not have to
29
+ * know they exist: an account-deletion sweep, an export, a migration allowlist, or a
30
+ * helper generic over a table union is about the app's own data, and every add-on
31
+ * added or removed would otherwise silently change the correct answer.
32
+ *
33
+ * \`\`\`ts
34
+ * // Doesn't need to mention \`ratelimit_buckets\`, and won't drift when an add-on lands.
35
+ * const EXPORTED: readonly AppTableName[] = ["nodes", "tagColors"];
36
+ * \`\`\`
37
+ */
38
+ export type AppTableName = ${m};
39
+
40
+ export type Id<TName extends string> = string & { readonly __table: TName };
41
+
42
+ ${p}
43
+
44
+ export interface DataModel {
45
+ ${c}
46
+ }
47
+
48
+ export type Doc<T extends keyof DataModel> = DataModel[T];
49
+
50
+ /**
51
+ * Per-table index name union. \`never\` for tables without secondary indexes.
52
+ * Used by \`TableReader.withIndex()\` to constrain callers to declared names.
53
+ */
54
+ export interface IndexNamesByTable {
55
+ ${y}
56
+ }
57
+
58
+ export type IndexName<T extends keyof DataModel> = IndexNamesByTable[T];
59
+
60
+ /** Per-table search-index name union. \`never\` for tables without searchIndex. */
61
+ export interface SearchIndexNamesByTable {
62
+ ${x}
63
+ }
64
+
65
+ export type SearchIndexName<T extends keyof DataModel> = SearchIndexNamesByTable[T];
66
+
67
+ /** Per-table rank-index name union. \`never\` for tables without a rankIndex. */
68
+ export interface RankIndexNamesByTable {
69
+ ${b}
70
+ }
71
+
72
+ export type RankIndexName<T extends keyof DataModel> = RankIndexNamesByTable[T];
73
+
74
+ /** Per-table geo-index name union. \`never\` for tables without a geoIndex. */
75
+ export interface GeoIndexNamesByTable {
76
+ ${f}
77
+ }
78
+
79
+ export type GeoIndexName<T extends keyof DataModel> = GeoIndexNamesByTable[T];
80
+
81
+ /** Union of declared vector index names. \`never\` when none are declared. */
82
+ export type VectorIndexName = ${T};
83
+
84
+ ${$}
85
+
86
+ /** Per-table insert shape, accepted by \`ctx.db.<table>.insert(...)\`. */
87
+ export interface InsertModel {
88
+ ${u}
89
+ }
90
+
91
+ export type Insert<T extends keyof DataModel> = InsertModel[T];
92
+
93
+ /**
94
+ * Phantom relation descriptors. They carry the relation kind and target table
95
+ * as type parameters only — there is no runtime value — so the \`with\` argument
96
+ * and its return type can be inferred from {@link Relations}.
97
+ */
98
+ export interface OneRelation<Target extends keyof DataModel, Field extends string> {
99
+ readonly __field: Field;
100
+ readonly __relationKind: "one";
101
+ readonly __target: Target;
102
+ }
103
+
104
+ export interface ManyRelation<Target extends keyof DataModel> {
105
+ readonly __relationKind: "many";
106
+ readonly __target: Target;
107
+ }
108
+
109
+ /** Per-table relation map keyed by accessor name. \`{}\` for tables with none. */
110
+ export interface Relations {
111
+ ${I}
112
+ }
113
+
114
+ `,_)};export{_ as SCHEMA_MODULE_PATH,w as emitDataModel};
@@ -0,0 +1,15 @@
1
+ import{SCHEMA_MODULE_PATH as c}from"./emitDataModel-BvCZS4Yq.mjs";import{r as m}from"./qualifiers-qqH8fRTo.mjs";import{G as b,a as z,d as T,v as f,u as A,g as x,c as h}from"./shared-Cn7dMQ_u.mjs";const d=e=>{switch(e.kind){case"array":case"object":case"record":case"union":return{builder:"text",mode:"json",notNull:!0,typeAnnotation:f(e)};case"bigint":return{builder:"blob",mode:"bigint",notNull:!0};case"boolean":return{builder:"integer",mode:"boolean",notNull:!0};case"bytes":return{builder:"blob",mode:"buffer",notNull:!0};case"date":case"timestamp":return{builder:"integer",notNull:!0};case"from":return{builder:"text",notNull:!0,typeAnnotation:f(e)};case"id":return{builder:"text",notNull:!0};case"literal":{const t=e.literalValue??"";return t.startsWith('"')||t.startsWith("'")?{builder:"text",notNull:!0}:t==="true"||t==="false"?{builder:"integer",mode:"boolean",notNull:!0}:t==="null"?{builder:"text",notNull:!0}:{builder:"real",notNull:!0}}case"null":return{builder:"text",notNull:!0};case"number":return{builder:"real",notNull:!0};case"optional":return{...e.inner?d(e.inner):{builder:"text",notNull:!1},notNull:!1};case"storage":case"string":return{builder:"text",notNull:!0};default:return{builder:"text",notNull:!0}}},N=(e,t)=>{const r=A(e);return r.kind==="id"&&r.tableName!==void 0&&t.has(r.tableName)?r.tableName:void 0},j=(e,t,r)=>{x(e,"drizzle column name");const n=d(t),o=n.mode?`, { mode: "${n.mode}" }`:"";let l=`${n.builder}("${e}"${o})`;n.typeAnnotation&&(l+=`.$type<${n.typeAnnotation}>()`);const s=N(t,r);return s!==void 0&&(l+=`.references((): AnySQLiteColumn => ${s}._id)`),n.notNull&&t.column?.notNull!==!1&&(l+=".notNull()"),l},I=e=>{const t=e.unique?"uniqueIndex":"index",r=e.fields.map(n=>(x(n,"drizzle index field"),`t.${n}`)).join(", ");return` ${h(e.name)}: ${t}(${JSON.stringify(e.name)}).on(${r}),`},S=(e,t)=>{z(e.name,"table name");const r=[' _id: text("_id").primaryKey(),',' _creationTime: integer("_creationTime").notNull(),',...Object.entries(e.shape).map(([o,l])=>` ${o}: ${j(o,l,t)},`)].join(`
2
+ `),n=e.indexes.length>0?`, (t) => ({
3
+ ${e.indexes.map(o=>I(o)).join(`
4
+ `)}
5
+ })`:"";return`export const ${e.name} = sqliteTable("${e.name}", {
6
+ ${r}
7
+ }${n});`},C=e=>e.typeAnnotation?.includes('Id<"')??!1,D=(e,t)=>{const r=new Set(["integer","sqliteTable","text"]),n=new Set;let o=!1,l=!1;for(const s of e){for(const i of Object.values(s.shape)){const a=d(i);r.add(a.builder),l=l||C(a),o=o||N(i,t)!==void 0}for(const i of s.indexes)n.add(i.unique?"uniqueIndex":"index")}return{columns:[...r].toSorted((s,i)=>s.localeCompare(i)),indexes:[...n].toSorted((s,i)=>s.localeCompare(i)),needsAnyColumn:o,needsId:l}},p=(e,t=!1)=>{if(e.length===0)return`${b}export {};
8
+ `;const r=T(t),n=new Set(e.map(u=>u.name)),{columns:o,indexes:l,needsAnyColumn:s,needsId:i}=D(e,n),a=[...l,...o].toSorted((u,g)=>u.localeCompare(g)),$=e.map(u=>S(u,n)).join(`
9
+
10
+ `),y=[s?`import type { AnySQLiteColumn } from "${r.serverDrizzle}";
11
+ `:"",i?`import type { Id } from "./dataModel.js";
12
+ `:""].join("");return`${b}import { ${a.join(", ")} } from "${r.serverDrizzle}";
13
+ ${y}
14
+ ${$}
15
+ `},v=(e,t=!1)=>{const r=e.tables.filter(o=>o.shardMode==="global"),n=e.tables.filter(o=>o.shardMode!=="global");return{global:m(p(r,t),c),shard:m(p(n,t),c)}};export{v as default};