@lunora/codegen 1.0.0-alpha.37 → 1.0.0-alpha.370

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 (124) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.mts +4370 -2174
  3. package/dist/index.d.ts +4370 -2174
  4. package/dist/index.mjs +1 -35
  5. package/dist/packem_shared/AGENTS_FILENAME-BedyJsOT.mjs +1 -0
  6. package/dist/packem_shared/CAPABILITY_PROBES-DKYJ2K4t.mjs +25 -0
  7. package/dist/packem_shared/CONTAINERS_FILENAME-T1v8pyHN.mjs +1 -0
  8. package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
  9. package/dist/packem_shared/DEFAULT_TARGET-3OLdJhTj.mjs +1 -0
  10. package/dist/packem_shared/FLAGS_FILENAME-BEMyglH0.mjs +1 -0
  11. package/dist/packem_shared/GENERATED_HEADER-BPc7maFN.mjs +1 -0
  12. package/dist/packem_shared/LUNORA_ERROR_CODES-CIAJQeKB.mjs +1 -0
  13. package/dist/packem_shared/MUTATORS_FILENAME-PNPCtUl2.mjs +1 -0
  14. package/dist/packem_shared/NOTIFY_FILENAME-HXIKioYv.mjs +1 -0
  15. package/dist/packem_shared/OPENRPC_VERSION-CTR_g_IE.mjs +3 -0
  16. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs +1 -0
  17. package/dist/packem_shared/QUEUES_FILENAME-Dt5RG_P0.mjs +1 -0
  18. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DDRbBN-I.mjs +31 -0
  19. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-SplX7j_9.mjs +2 -0
  20. package/dist/packem_shared/SHAPES_FILENAME-mgEi072Z.mjs +1 -0
  21. package/dist/packem_shared/SchemaSnapshotParseError-CjKSMuex.mjs +18 -0
  22. package/dist/packem_shared/WORKFLOWS_FILENAME-VAXgqqP-.mjs +1 -0
  23. package/dist/packem_shared/attribution-DUbGYT4N.mjs +1 -0
  24. package/dist/packem_shared/buildOpenApiDocument-Cju685VK.mjs +3 -0
  25. package/dist/packem_shared/capabilitiesUsedBy-CN8HACEL.mjs +1 -0
  26. package/dist/packem_shared/chain-DuEHFGVW.mjs +1 -0
  27. package/dist/packem_shared/classify-procedure-call-DtqiTjPg.mjs +1 -0
  28. package/dist/packem_shared/context-property-calls-CDMYbegz.mjs +1 -0
  29. package/dist/packem_shared/context-root-Bd08qiVR.mjs +1 -0
  30. package/dist/packem_shared/createCodegenProject-DmXl8m_P.mjs +1 -0
  31. package/dist/packem_shared/database-calls-BSyvN1No.mjs +1 -0
  32. package/dist/packem_shared/declared-output-Iaar469J.mjs +1 -0
  33. package/dist/packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs +1 -0
  34. package/dist/packem_shared/discoverAuthApiCalls-Ce3BdKQr.mjs +1 -0
  35. package/dist/packem_shared/discoverCrons-D-vJXsgx.mjs +1 -0
  36. package/dist/packem_shared/discoverFunctions-BdEY3nbv.mjs +1 -0
  37. package/dist/packem_shared/discoverHttpRoutes-Hy2UrcrN.mjs +1 -0
  38. package/dist/packem_shared/discoverHyperdriveCalls-Cn3087D8.mjs +1 -0
  39. package/dist/packem_shared/discoverInserts-DIzIGlyG.mjs +1 -0
  40. package/dist/packem_shared/discoverMaskProcedures-B68Jryv8.mjs +1 -0
  41. package/dist/packem_shared/discoverMigrations-Bv8kNIgy.mjs +1 -0
  42. package/dist/packem_shared/discoverNondeterministicCalls-DZ_kIie5.mjs +1 -0
  43. package/dist/packem_shared/discoverQueries-KjOdhrk6.mjs +1 -0
  44. package/dist/packem_shared/discoverR2sqlCalls-B4N8iXlU.mjs +1 -0
  45. package/dist/packem_shared/discoverRlsMetadata-Dq6iSXnC.mjs +1 -0
  46. package/dist/packem_shared/discoverRlsProcedures-DhOEyJLg.mjs +1 -0
  47. package/dist/packem_shared/discoverSandboxUsage-CdGRnVU2.mjs +1 -0
  48. package/dist/packem_shared/discoverSchema-DmkjooXZ.mjs +1 -0
  49. package/dist/packem_shared/discoverStorageRulesMetadata-CJ7h6SPK.mjs +1 -0
  50. package/dist/packem_shared/dispatch-namespace-DwTjD7BU.mjs +1 -0
  51. package/dist/packem_shared/emitAgents-B6IWt2Gq.mjs +1 -0
  52. package/dist/packem_shared/emitApi-CCjh0ICg.mjs +147 -0
  53. package/dist/packem_shared/emitApp-CzDMr_iP.mjs +1058 -0
  54. package/dist/packem_shared/emitCrons-CY8IQfAI.mjs +123 -0
  55. package/dist/packem_shared/emitDataModel-Bba2y2yt.mjs +114 -0
  56. package/dist/packem_shared/emitDrizzleSchema-CD4hPtUP.mjs +15 -0
  57. package/dist/packem_shared/emitFunctions-C3WOlVN0.mjs +506 -0
  58. package/dist/packem_shared/emitServer-DEkbCE0n.mjs +1 -0
  59. package/dist/packem_shared/emitShard-N6sEBh_g.mjs +1 -0
  60. package/dist/packem_shared/exported-procedure-chains-BaCIhnJ7.mjs +1 -0
  61. package/dist/packem_shared/fingerprintSchemaSources-DIYx5eO0.mjs +1 -0
  62. package/dist/packem_shared/formatAdvisories-BCVASH7N.mjs +2 -0
  63. package/dist/packem_shared/handler-reference-D1wpw_qR.mjs +1 -0
  64. package/dist/packem_shared/index-Cm7HdvL5.mjs +1 -0
  65. package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
  66. package/dist/packem_shared/isTestPath-JdN4KXhV.mjs +1 -0
  67. package/dist/packem_shared/isTypedSchema-CDv3pJB6.mjs +4 -0
  68. package/dist/packem_shared/json-data-Chfs2Cz5.mjs +1 -0
  69. package/dist/packem_shared/loadProjectConfig-B7RmxIeD.mjs +1 -0
  70. package/dist/packem_shared/module-specifiers-BctA0m_p.mjs +1 -0
  71. package/dist/packem_shared/modules-DEBCI7Gm.mjs +1 -0
  72. package/dist/packem_shared/parse-validator-CP5CL6Q7.mjs +1 -0
  73. package/dist/packem_shared/platform-8oj7iXQy.mjs +1 -0
  74. package/dist/packem_shared/property-name-7cBlgK_O.mjs +1 -0
  75. package/dist/packem_shared/qualifiers-vzi-FQv3.mjs +1 -0
  76. package/dist/packem_shared/readPackageDependencies-RHhGiz0k.mjs +1 -0
  77. package/dist/packem_shared/readServiceBindings-BA49C6aN.mjs +1 -0
  78. package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
  79. package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
  80. package/dist/packem_shared/schema-BgM8A3XV.mjs +1 -0
  81. package/dist/packem_shared/schemaFromIr-CByOxuZb.mjs +1 -0
  82. package/dist/packem_shared/server-DC4PW_2M.mjs +369 -0
  83. package/dist/packem_shared/shard-D9_wgrV7.mjs +1803 -0
  84. package/dist/packem_shared/shard-runtime-B9K29SyO.mjs +343 -0
  85. package/dist/packem_shared/shared-Br_OnErI.mjs +13 -0
  86. package/dist/packem_shared/unwrap-handler-return-DTcee6Ng.mjs +1 -0
  87. package/dist/sdk/index.d.mts +288 -0
  88. package/dist/sdk/index.d.ts +288 -0
  89. package/dist/sdk/index.mjs +372 -0
  90. package/package.json +21 -8
  91. package/dist/packem_shared/CONTAINERS_FILENAME-DjpXMqhp.mjs +0 -224
  92. package/dist/packem_shared/CodegenDiagnosticError-DyQ5FwkM.mjs +0 -24
  93. package/dist/packem_shared/FLAGS_FILENAME-BjpS5w08.mjs +0 -139
  94. package/dist/packem_shared/GENERATED_HEADER-DPA3P7aE.mjs +0 -3
  95. package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
  96. package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +0 -81
  97. package/dist/packem_shared/OPENRPC_VERSION-BUv-bV3M.mjs +0 -60
  98. package/dist/packem_shared/QUEUES_FILENAME-BF0iUmx7.mjs +0 -119
  99. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CCiIKql3.mjs +0 -3425
  100. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs +0 -249
  101. package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +0 -94
  102. package/dist/packem_shared/WORKFLOWS_FILENAME-CCC_42o3.mjs +0 -124
  103. package/dist/packem_shared/buildOpenApiDocument-CYHG8Yuq.mjs +0 -183
  104. package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
  105. package/dist/packem_shared/discoverAuthApiCalls-URDoTADN.mjs +0 -62
  106. package/dist/packem_shared/discoverCrons-BNL5hAPv.mjs +0 -256
  107. package/dist/packem_shared/discoverFunctions-BJdF7lRs.mjs +0 -514
  108. package/dist/packem_shared/discoverHttpRoutes-CcwP-Rkr.mjs +0 -131
  109. package/dist/packem_shared/discoverInserts-BpFhM32L.mjs +0 -61
  110. package/dist/packem_shared/discoverMaskProcedures-DT-v8wvj.mjs +0 -273
  111. package/dist/packem_shared/discoverMigrations-cG1idBVM.mjs +0 -97
  112. package/dist/packem_shared/discoverNondeterministicCalls-CEOjmfk4.mjs +0 -122
  113. package/dist/packem_shared/discoverQueries-DeVBQVAG.mjs +0 -62
  114. package/dist/packem_shared/discoverR2sqlCalls-CWCAU-xJ.mjs +0 -80
  115. package/dist/packem_shared/discoverRlsMetadata-BL0oukaK.mjs +0 -280
  116. package/dist/packem_shared/discoverSchema-CeXJWVKV.mjs +0 -874
  117. package/dist/packem_shared/discoverStorageRulesMetadata-CFHByjIl.mjs +0 -97
  118. package/dist/packem_shared/emit-Bl3STBW9.mjs +0 -3424
  119. package/dist/packem_shared/emitApp-CPfFyx9U.mjs +0 -668
  120. package/dist/packem_shared/formatAdvisories-DLIqHq5l.mjs +0 -114
  121. package/dist/packem_shared/parse-validator-D6zI2i85.mjs +0 -134
  122. package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
  123. package/dist/packem_shared/redact-oTmsol5A.mjs +0 -33
  124. package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
@@ -0,0 +1,123 @@
1
+ import{G as a,d as c}from"./shared-Br_OnErI.mjs";import{i as y}from"./schema-BgM8A3XV.mjs";const f=s=>s?`${a}/**
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=(s,r,o)=>{if(!s.some(t=>y(t)))return"";const e=o?JSON.stringify(o):"undefined";return`${a}import { WorkerEntrypoint } from "cloudflare:workers";
12
+ import { hostedShardRegistry } from "${c(r).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(r).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=s=>`${a}/**
53
+ * Host the shard, the scheduler and the shard registry in ONE Durable Object
54
+ * class, so the app spends one of the account's classes instead of three. A
55
+ * Vite-first (class-A) app needs nothing more: its generated worker entry builds
56
+ * \`LunoraDO\` from these. A hand-written entry does the same by hand:
57
+ *
58
+ * \`export const LunoraDO = mergeDurableObjects({ shard: app.ShardDO, scheduler: SchedulerDO, shardRegistry: ShardRegistryDO });\`
59
+ *
60
+ * and passes \`roleNamespace(env.SHARD, "scheduler")\` / \`roleNamespace(env.SHARD, "shardRegistry")\`
61
+ * to \`.scheduler()\` / \`.shardRegistry()\`. Merge before the first deploy only:
62
+ * data already in \`ShardDO\` does not move, and a deployed merge cannot be undone.
63
+ */
64
+ export { mergeDurableObjects, roleNamespace } from "${c(s).do}";
65
+ `,S=s=>{const r=new Map;for(const n of s){const d=r.get(n.cron);d?d.push(n):r.set(n.cron,[n])}const o=[...r.keys()].map(n=>` ${JSON.stringify(n)},`).join(`
66
+ `),e=o.length>0?`
67
+ ${o}
68
+ `:"",t=[...r.entries()].map(([n,d])=>{const l=d.map(i=>{const g=i.workflow?`workflow: ${JSON.stringify(i.workflow.className)}`:`functionPath: ${JSON.stringify(i.functionPath)}`;return` { name: ${JSON.stringify(i.name)}, ${g}, args: ${JSON.stringify(i.args)} },`}).join(`
69
+ `);return` ${JSON.stringify(n)}: [
70
+ ${l}
71
+ ],`}).join(`
72
+ `),h=t.length>0?`
73
+ ${t}
74
+ `:"";return`${a}/**
75
+ * One scheduled cron invocation. Exactly one target is set: \`functionPath\` is
76
+ * the \`namespace:fn\` dispatch ref (matches \`__lunoraRef\`), invoked on the
77
+ * shard; \`workflow\` is a workflow class name (its \`ctx.exports\` key) whose durable workflow is
78
+ * started fresh per fire. \`args\` are forwarded verbatim (a workflow's become
79
+ * its \`params\`).
80
+ */
81
+ export interface LunoraCronJob {
82
+ args: Record<string, unknown>;
83
+ functionPath?: string;
84
+ name: string;
85
+ workflow?: string;
86
+ }
87
+
88
+ /**
89
+ * Deduplicated cron schedules — mirror of wrangler's \`triggers.crons\`. The
90
+ * Lunora vite plugin keeps \`wrangler.jsonc\` in sync with this array.
91
+ */
92
+ export const LUNORA_CRON_TRIGGERS: ReadonlyArray<string> = [${e}];
93
+
94
+ /**
95
+ * Dispatcher map keyed by cron expression. The Worker's \`scheduled()\` handler
96
+ * looks up \`event.cron\` here and dispatches every job in the list.
97
+ */
98
+ export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${h}};
99
+ `},b=s=>{const r=[...s].toSorted((e,t)=>e.name.localeCompare(t.name)).map(e=>{const t=[`name: ${JSON.stringify(e.name)}`,`table: ${JSON.stringify(e.table)}`];return e.field!==void 0&&t.push(`field: ${JSON.stringify(e.field)}`),e.dimensions!==void 0&&t.push(`dimensions: ${JSON.stringify(e.dimensions)}`),e.metric!==void 0&&t.push(`metric: ${JSON.stringify(e.metric)}`),e.metadata!==void 0&&t.push(`metadata: ${JSON.stringify(e.metadata)}`),` { ${t.join(", ")} },`}).join(`
100
+ `),o=r.length>0?`
101
+ ${r}
102
+ `:"";return`${a}/**
103
+ * One vector index declared in \`schema.ts\` — an inline \`.vectorize()\` column
104
+ * or a standalone \`defineVectorIndex()\`. \`field\` is the source column (absent
105
+ * for a \`select\`-derived Shape B index); \`metadata\` lists the row fields
106
+ * mirrored into Vectorize for filtering.
107
+ */
108
+ export interface LunoraVectorIndex {
109
+ dimensions?: number;
110
+ field?: string;
111
+ metadata?: ReadonlyArray<string>;
112
+ metric?: "cosine" | "dot-product" | "euclidean";
113
+ name: string;
114
+ table: string;
115
+ }
116
+
117
+ /**
118
+ * Static registry of every vector index in the schema, sorted by name.
119
+ * Vectorize cannot enumerate indexes at runtime, so the worker passes this to
120
+ * \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
121
+ */
122
+ export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${o}];
123
+ `},w=s=>[...new Set(s.map(r=>r.cron))];export{S as emitCrons,R as emitDurableObjects,f as emitScheduler,u as emitShardRegistry,b as emitVectors,w as emitWranglerCronTriggers};
@@ -0,0 +1,114 @@
1
+ import{r as k}from"./qualifiers-vzi-FQv3.mjs";import{a as i,e as o,v as d,f as v,G as M}from"./shared-Br_OnErI.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-Bba2y2yt.mjs";import{r as m}from"./qualifiers-vzi-FQv3.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-Br_OnErI.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};