@lunora/codegen 1.0.0-alpha.35 → 1.0.0-alpha.351

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 +4354 -2174
  3. package/dist/index.d.ts +4354 -2174
  4. package/dist/index.mjs +1 -35
  5. package/dist/packem_shared/AGENTS_FILENAME-isdHqPIt.mjs +1 -0
  6. package/dist/packem_shared/CAPABILITY_PROBES-brcmKenl.mjs +25 -0
  7. package/dist/packem_shared/CONTAINERS_FILENAME-mK4cZpcz.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-BQk3SX8D.mjs +1 -0
  11. package/dist/packem_shared/GENERATED_HEADER-BXK9A_wP.mjs +1 -0
  12. package/dist/packem_shared/LUNORA_ERROR_CODES-CIAJQeKB.mjs +1 -0
  13. package/dist/packem_shared/MUTATORS_FILENAME-Cy9h3EVW.mjs +1 -0
  14. package/dist/packem_shared/NOTIFY_FILENAME-9to_l_Kh.mjs +1 -0
  15. package/dist/packem_shared/OPENRPC_VERSION-DfSmacMR.mjs +3 -0
  16. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs +1 -0
  17. package/dist/packem_shared/QUEUES_FILENAME-Civ-7SiI.mjs +1 -0
  18. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-smszfFJZ.mjs +31 -0
  19. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C7Um0EnM.mjs +2 -0
  20. package/dist/packem_shared/SHAPES_FILENAME-DVJbfDZ8.mjs +1 -0
  21. package/dist/packem_shared/SchemaSnapshotParseError-H9eQX4ui.mjs +18 -0
  22. package/dist/packem_shared/WORKFLOWS_FILENAME-kXq07aGl.mjs +1 -0
  23. package/dist/packem_shared/attribution-CG8-kUcl.mjs +1 -0
  24. package/dist/packem_shared/buildOpenApiDocument-DWdj2jvW.mjs +3 -0
  25. package/dist/packem_shared/capabilitiesUsedBy-DjRHg-Zk.mjs +1 -0
  26. package/dist/packem_shared/chain-74gjwZMP.mjs +1 -0
  27. package/dist/packem_shared/classify-procedure-call-BkaeM9Ej.mjs +1 -0
  28. package/dist/packem_shared/context-property-calls-dFjpeIlP.mjs +1 -0
  29. package/dist/packem_shared/context-root-CNR6TAsP.mjs +1 -0
  30. package/dist/packem_shared/createCodegenProject-ClPr_MXM.mjs +1 -0
  31. package/dist/packem_shared/database-calls-UPlhi3Ks.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-CScPrUD-.mjs +1 -0
  35. package/dist/packem_shared/discoverCrons-B1_NUt19.mjs +1 -0
  36. package/dist/packem_shared/discoverFunctions-CJG4S6CK.mjs +1 -0
  37. package/dist/packem_shared/discoverHttpRoutes-DCDgDIYv.mjs +1 -0
  38. package/dist/packem_shared/discoverHyperdriveCalls-CL-d0IVo.mjs +1 -0
  39. package/dist/packem_shared/discoverInserts-BcoTjXqI.mjs +1 -0
  40. package/dist/packem_shared/discoverMaskProcedures-Bw-BOIbA.mjs +1 -0
  41. package/dist/packem_shared/discoverMigrations-BWxx8Wv9.mjs +1 -0
  42. package/dist/packem_shared/discoverNondeterministicCalls-mFJNU8qY.mjs +1 -0
  43. package/dist/packem_shared/discoverQueries-CxQRVuIV.mjs +1 -0
  44. package/dist/packem_shared/discoverR2sqlCalls-B4oeTYEM.mjs +1 -0
  45. package/dist/packem_shared/discoverRlsMetadata-D0B4nCmG.mjs +1 -0
  46. package/dist/packem_shared/discoverRlsProcedures-Cl6UKT7L.mjs +1 -0
  47. package/dist/packem_shared/discoverSandboxUsage--Z1vx7GM.mjs +1 -0
  48. package/dist/packem_shared/discoverSchema-Cwt-DQgh.mjs +1 -0
  49. package/dist/packem_shared/discoverStorageRulesMetadata-CitX6ziW.mjs +1 -0
  50. package/dist/packem_shared/dispatch-namespace-DwTjD7BU.mjs +1 -0
  51. package/dist/packem_shared/emitAgents--VDKoet4.mjs +1 -0
  52. package/dist/packem_shared/emitApi-zynTVppI.mjs +147 -0
  53. package/dist/packem_shared/emitApp-UV2Ugx7C.mjs +989 -0
  54. package/dist/packem_shared/emitCrons-lc-hnJYn.mjs +96 -0
  55. package/dist/packem_shared/emitDataModel-CuFqq97x.mjs +114 -0
  56. package/dist/packem_shared/emitDrizzleSchema-bct1OuH5.mjs +15 -0
  57. package/dist/packem_shared/emitFunctions-D7mopPiT.mjs +506 -0
  58. package/dist/packem_shared/emitServer-DqjvPPKJ.mjs +1 -0
  59. package/dist/packem_shared/emitShard-DEZcDjgF.mjs +1 -0
  60. package/dist/packem_shared/exported-procedure-chains-D1WlRfqJ.mjs +1 -0
  61. package/dist/packem_shared/fingerprintSchemaSources-BKXkgkj4.mjs +1 -0
  62. package/dist/packem_shared/formatAdvisories-BCVASH7N.mjs +2 -0
  63. package/dist/packem_shared/handler-reference-CClSR4bi.mjs +1 -0
  64. package/dist/packem_shared/index-CN8FVvr-.mjs +1 -0
  65. package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
  66. package/dist/packem_shared/isTestPath-C3QumE88.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-l-Db0C4S.mjs +1 -0
  72. package/dist/packem_shared/parse-validator-iVTounLK.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-Bl5fSmav.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-BWFnvCVg.mjs +1 -0
  82. package/dist/packem_shared/server-DlEPJi5i.mjs +369 -0
  83. package/dist/packem_shared/shard-B5e5ovr_.mjs +1796 -0
  84. package/dist/packem_shared/shard-runtime-ByYXjCKY.mjs +333 -0
  85. package/dist/packem_shared/shared-8vTRkL2-.mjs +13 -0
  86. package/dist/packem_shared/unwrap-handler-return-CGdJGvGh.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-CLwPlCQe.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-4YIeMkOI.mjs +0 -60
  98. package/dist/packem_shared/QUEUES_FILENAME-BF0iUmx7.mjs +0 -119
  99. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-C6Q0h0O5.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-bp1pYSV6.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-DdZOeroL.mjs +0 -257
  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-CBwEvCXQ.mjs +0 -3451
  119. package/dist/packem_shared/emitApp-nQ2oC-8G.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,96 @@
1
+ import{G as i,d as c}from"./shared-8vTRkL2-.mjs";import{i as m}from"./schema-BgM8A3XV.mjs";const u=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
+ `:"",y=(r,t)=>r.some(o=>m(o))?`${i}/**
12
+ * The \`ShardRegistryDO\` Durable Object class — the live set of shard keys per
13
+ * \`.shardBy()\` table, which cross-shard export, CDC sync and migrations fan out
14
+ * to. Re-exported so a worker entry can forward it (wrangler binds only what the
15
+ * entry exports), next to \`.shardRegistry((env) => env.SHARD_REGISTRY)\`:
16
+ *
17
+ * \`export { ShardRegistryDO } from "./lunora/_generated/shardRegistry.js";\`
18
+ *
19
+ * Name the class in a hand-written entry: binding inference provisions
20
+ * \`SHARD_REGISTRY\` off the entry's named exports, and cannot see through an
21
+ * \`export *\`. A Vite-first (class-A) app needs neither line — its generated
22
+ * worker entry does both whenever this module exists.
23
+ */
24
+ export { ShardRegistryDO } from "${c(t).do}";
25
+ `:"",w=r=>`${i}/**
26
+ * Host the shard, the scheduler and the shard registry in ONE Durable Object
27
+ * class, so the app spends one of the account's classes instead of three. A
28
+ * Vite-first (class-A) app needs nothing more: its generated worker entry builds
29
+ * \`LunoraDO\` from these. A hand-written entry does the same by hand:
30
+ *
31
+ * \`export const LunoraDO = mergeDurableObjects({ shard: app.ShardDO, scheduler: SchedulerDO, shardRegistry: ShardRegistryDO });\`
32
+ *
33
+ * and passes \`roleNamespace(env.SHARD, "scheduler")\` / \`roleNamespace(env.SHARD, "shardRegistry")\`
34
+ * to \`.scheduler()\` / \`.shardRegistry()\`. Merge before the first deploy only:
35
+ * data already in \`ShardDO\` does not move, and a deployed merge cannot be undone.
36
+ */
37
+ export { mergeDurableObjects, roleNamespace } from "${c(r).do}";
38
+ `,O=r=>{const t=new Map;for(const n of r){const d=t.get(n.cron);d?d.push(n):t.set(n.cron,[n])}const o=[...t.keys()].map(n=>` ${JSON.stringify(n)},`).join(`
39
+ `),e=o.length>0?`
40
+ ${o}
41
+ `:"",s=[...t.entries()].map(([n,d])=>{const l=d.map(a=>{const f=a.workflow?`workflow: ${JSON.stringify(a.workflow.className)}`:`functionPath: ${JSON.stringify(a.functionPath)}`;return` { name: ${JSON.stringify(a.name)}, ${f}, args: ${JSON.stringify(a.args)} },`}).join(`
42
+ `);return` ${JSON.stringify(n)}: [
43
+ ${l}
44
+ ],`}).join(`
45
+ `),h=s.length>0?`
46
+ ${s}
47
+ `:"";return`${i}/**
48
+ * One scheduled cron invocation. Exactly one target is set: \`functionPath\` is
49
+ * the \`namespace:fn\` dispatch ref (matches \`__lunoraRef\`), invoked on the
50
+ * shard; \`workflow\` is a workflow class name (its \`ctx.exports\` key) whose durable workflow is
51
+ * started fresh per fire. \`args\` are forwarded verbatim (a workflow's become
52
+ * its \`params\`).
53
+ */
54
+ export interface LunoraCronJob {
55
+ args: Record<string, unknown>;
56
+ functionPath?: string;
57
+ name: string;
58
+ workflow?: string;
59
+ }
60
+
61
+ /**
62
+ * Deduplicated cron schedules — mirror of wrangler's \`triggers.crons\`. The
63
+ * Lunora vite plugin keeps \`wrangler.jsonc\` in sync with this array.
64
+ */
65
+ export const LUNORA_CRON_TRIGGERS: ReadonlyArray<string> = [${e}];
66
+
67
+ /**
68
+ * Dispatcher map keyed by cron expression. The Worker's \`scheduled()\` handler
69
+ * looks up \`event.cron\` here and dispatches every job in the list.
70
+ */
71
+ export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${h}};
72
+ `},S=r=>{const t=[...r].toSorted((e,s)=>e.name.localeCompare(s.name)).map(e=>{const s=[`name: ${JSON.stringify(e.name)}`,`table: ${JSON.stringify(e.table)}`];return e.field!==void 0&&s.push(`field: ${JSON.stringify(e.field)}`),e.dimensions!==void 0&&s.push(`dimensions: ${JSON.stringify(e.dimensions)}`),e.metric!==void 0&&s.push(`metric: ${JSON.stringify(e.metric)}`),e.metadata!==void 0&&s.push(`metadata: ${JSON.stringify(e.metadata)}`),` { ${s.join(", ")} },`}).join(`
73
+ `),o=t.length>0?`
74
+ ${t}
75
+ `:"";return`${i}/**
76
+ * One vector index declared in \`schema.ts\` — an inline \`.vectorize()\` column
77
+ * or a standalone \`defineVectorIndex()\`. \`field\` is the source column (absent
78
+ * for a \`select\`-derived Shape B index); \`metadata\` lists the row fields
79
+ * mirrored into Vectorize for filtering.
80
+ */
81
+ export interface LunoraVectorIndex {
82
+ dimensions?: number;
83
+ field?: string;
84
+ metadata?: ReadonlyArray<string>;
85
+ metric?: "cosine" | "dot-product" | "euclidean";
86
+ name: string;
87
+ table: string;
88
+ }
89
+
90
+ /**
91
+ * Static registry of every vector index in the schema, sorted by name.
92
+ * Vectorize cannot enumerate indexes at runtime, so the worker passes this to
93
+ * \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
94
+ */
95
+ export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${o}];
96
+ `},b=r=>[...new Set(r.map(t=>t.cron))];export{O as emitCrons,w as emitDurableObjects,u as emitScheduler,y as emitShardRegistry,S as emitVectors,b as emitWranglerCronTriggers};
@@ -0,0 +1,114 @@
1
+ import{r as k}from"./qualifiers-Bl5fSmav.mjs";import{a as i,e as o,v as d,f as v,G as M}from"./shared-8vTRkL2-.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-CuFqq97x.mjs";import{r as m}from"./qualifiers-Bl5fSmav.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-8vTRkL2-.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};