@lunora/codegen 1.0.0-alpha.26 → 1.0.0-alpha.260
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/LICENSE.md +6 -0
- package/README.md +1 -1
- package/dist/index.d.mts +3851 -1254
- package/dist/index.d.ts +3851 -1254
- package/dist/index.mjs +1 -34
- package/dist/packem_shared/AGENTS_FILENAME-UhIaG4BZ.mjs +1 -0
- package/dist/packem_shared/CAPABILITY_PROBES-DFsutD7g.mjs +25 -0
- package/dist/packem_shared/CONTAINERS_FILENAME-DhUL5rDc.mjs +1 -0
- package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
- package/dist/packem_shared/DEFAULT_TARGET-7sHexLjO.mjs +1 -0
- package/dist/packem_shared/FLAGS_FILENAME-BINQ51Zq.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-dFyrHgQ0.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-D1Q6EUII.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-bbHHFQ_t.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-CGu1_YK7.mjs +3 -0
- package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs +1 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSLmXUQA.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BVhRHIbS.mjs +11 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs +2 -0
- package/dist/packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs +372 -0
- package/dist/packem_shared/SHAPES_FILENAME-DuR5hLW1.mjs +1 -0
- package/dist/packem_shared/SchemaSnapshotParseError-CPOXlFhI.mjs +18 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-IqUyMQgM.mjs +1 -0
- package/dist/packem_shared/attribution-sW_DHmLO.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-DOsv1HEF.mjs +3 -0
- package/dist/packem_shared/capabilitiesUsedBy-CzqyN9dX.mjs +1 -0
- package/dist/packem_shared/chain-BTbLDrrU.mjs +1 -0
- package/dist/packem_shared/classify-procedure-call-OnJoKgqu.mjs +1 -0
- package/dist/packem_shared/context-property-calls-BEBjylgc.mjs +1 -0
- package/dist/packem_shared/context-root-KWXRWlv6.mjs +1 -0
- package/dist/packem_shared/database-calls-rLPCL3-U.mjs +1 -0
- package/dist/packem_shared/declared-output-Iaar469J.mjs +1 -0
- package/dist/packem_shared/describeErrorLevelFindings-vzaGS9KL.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-CNj9-Jch.mjs +1 -0
- package/dist/packem_shared/discoverCrons-BqTY53L5.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-DPH4drkg.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-MRFziTCb.mjs +1 -0
- package/dist/packem_shared/discoverHyperdriveCalls-BcVkR6nw.mjs +1 -0
- package/dist/packem_shared/discoverInserts-Duz40u-s.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-DYJhbHF3.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-D2P2n7JE.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-Cxf6T2Oi.mjs +1 -0
- package/dist/packem_shared/discoverQueries-CWmNPVHm.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-DnKwop5c.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-BXXEFXjf.mjs +1 -0
- package/dist/packem_shared/discoverRlsProcedures-Des596JU.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-Bjl8A_hj.mjs +1 -0
- package/dist/packem_shared/discoverSchema-Cd3iH6q5.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-DGFonj0I.mjs +1 -0
- package/dist/packem_shared/emitAgents-Dotqck8w.mjs +1 -0
- package/dist/packem_shared/emitApi-xDIHPRPH.mjs +154 -0
- package/dist/packem_shared/emitApp-RNU41dtm.mjs +860 -0
- package/dist/packem_shared/emitCrons-DsXsg1uG.mjs +83 -0
- package/dist/packem_shared/emitDataModel-DSk9AkJe.mjs +113 -0
- package/dist/packem_shared/emitDrizzleSchema-DohtnI8c.mjs +15 -0
- package/dist/packem_shared/emitFunctions-evl8Mx1a.mjs +249 -0
- package/dist/packem_shared/emitServer-DymRagL2.mjs +368 -0
- package/dist/packem_shared/emitShard-DHMYSP4m.mjs +1 -0
- package/dist/packem_shared/exported-procedure-chains-58yS9zc8.mjs +1 -0
- package/dist/packem_shared/fingerprintSchemaSources-BzFVnBfa.mjs +1 -0
- package/dist/packem_shared/formatAdvisories-DwmUKYuc.mjs +2 -0
- package/dist/packem_shared/handler-reference-C1oBljnl.mjs +1 -0
- package/dist/packem_shared/index-BusOvbeQ.mjs +1 -0
- package/dist/packem_shared/ir-DBSvhNa-.mjs +1 -0
- package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
- package/dist/packem_shared/isTypedSchema-CKzc3ioR.mjs +4 -0
- package/dist/packem_shared/json-data-Chfs2Cz5.mjs +1 -0
- package/dist/packem_shared/listLunoraSourceFiles-DRes9d5p.mjs +1 -0
- package/dist/packem_shared/loadProjectConfig-CuGQsqYS.mjs +1 -0
- package/dist/packem_shared/module-specifiers-WF8iAydP.mjs +1 -0
- package/dist/packem_shared/modules-CsA-QVJ6.mjs +1 -0
- package/dist/packem_shared/parse-validator-B4mFs19C.mjs +1 -0
- package/dist/packem_shared/paths-C-9fwEgQ.mjs +1 -0
- package/dist/packem_shared/qualifiers-Cw8dEDbh.mjs +1 -0
- package/dist/packem_shared/readPackageDependencies-C6h6FZuP.mjs +1 -0
- package/dist/packem_shared/readServiceBindings-CnvEGOir.mjs +1 -0
- package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
- package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-BWFnvCVg.mjs +1 -0
- package/dist/packem_shared/shard-WXSIZRpD.mjs +1438 -0
- package/dist/packem_shared/shard-runtime-B1nU9CRa.mjs +321 -0
- package/dist/packem_shared/shared-BXUKWh7t.mjs +9 -0
- package/dist/packem_shared/unwrap-handler-return-D7E2TKkS.mjs +1 -0
- package/package.json +16 -7
- package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
- package/dist/packem_shared/FLAGS_FILENAME-B1vE0LIo.mjs +0 -139
- package/dist/packem_shared/GENERATED_HEADER-CYaSI_qY.mjs +0 -3268
- package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
- package/dist/packem_shared/LUNORA_SOLUTION_RULES-BTejmZp-.mjs +0 -131
- package/dist/packem_shared/MUTATORS_FILENAME-BhqdPtKp.mjs +0 -81
- package/dist/packem_shared/OPENRPC_VERSION-CRe5l79E.mjs +0 -60
- package/dist/packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs +0 -119
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-cgOjZTVY.mjs +0 -1137
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs +0 -245
- package/dist/packem_shared/SHAPES_FILENAME-ChV7MqgE.mjs +0 -94
- package/dist/packem_shared/WORKFLOWS_FILENAME-CCisG0Vy.mjs +0 -124
- package/dist/packem_shared/buildOpenApiDocument-BlpXQe2K.mjs +0 -183
- package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
- package/dist/packem_shared/discoverAuthApiCalls-CoirYbg6.mjs +0 -62
- package/dist/packem_shared/discoverCrons-Cev7RRAf.mjs +0 -257
- package/dist/packem_shared/discoverFunctions-BWMczzBx.mjs +0 -465
- package/dist/packem_shared/discoverHttpRoutes-CfP6cMzt.mjs +0 -131
- package/dist/packem_shared/discoverInserts-C7zxXkUf.mjs +0 -61
- package/dist/packem_shared/discoverMaskProcedures-Cm81kwrb.mjs +0 -217
- package/dist/packem_shared/discoverMigrations-Bi5nJ0mJ.mjs +0 -97
- package/dist/packem_shared/discoverNondeterministicCalls-C4M8AXmQ.mjs +0 -122
- package/dist/packem_shared/discoverQueries-B0wGT-xe.mjs +0 -62
- package/dist/packem_shared/discoverR2sqlCalls-BVNMd428.mjs +0 -80
- package/dist/packem_shared/discoverRlsMetadata-BS9GOGC5.mjs +0 -280
- package/dist/packem_shared/discoverSchema-KYq55qu3.mjs +0 -864
- package/dist/packem_shared/discoverStorageRulesMetadata-Da8BKXcI.mjs +0 -97
- package/dist/packem_shared/emitApp-C38fHt_1.mjs +0 -675
- package/dist/packem_shared/formatAdvisories-DdjK7sgh.mjs +0 -81
- package/dist/packem_shared/parse-validator-Cabb60UV.mjs +0 -133
- package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
- package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import{i as f}from"./ir-DBSvhNa-.mjs";import{G as c,d as m}from"./shared-BXUKWh7t.mjs";const u=n=>n?`${c}/**
|
|
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=(n,r)=>n.some(o=>f(o))?`${c}/**
|
|
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 "${m(r).do}";
|
|
25
|
+
`:"",w=n=>{const r=new Map;for(const s of n){const a=r.get(s.cron);a?a.push(s):r.set(s.cron,[s])}const o=[...r.keys()].map(s=>` ${JSON.stringify(s)},`).join(`
|
|
26
|
+
`),e=o.length>0?`
|
|
27
|
+
${o}
|
|
28
|
+
`:"",t=[...r.entries()].map(([s,a])=>{const l=a.map(i=>{const h=i.workflow?`workflow: ${JSON.stringify(i.workflow.className)}`:`functionPath: ${JSON.stringify(i.functionPath)}`;return` { name: ${JSON.stringify(i.name)}, ${h}, args: ${JSON.stringify(i.args)} },`}).join(`
|
|
29
|
+
`);return` ${JSON.stringify(s)}: [
|
|
30
|
+
${l}
|
|
31
|
+
],`}).join(`
|
|
32
|
+
`),d=t.length>0?`
|
|
33
|
+
${t}
|
|
34
|
+
`:"";return`${c}/**
|
|
35
|
+
* One scheduled cron invocation. Exactly one target is set: \`functionPath\` is
|
|
36
|
+
* the \`namespace:fn\` dispatch ref (matches \`__lunoraRef\`), invoked on the
|
|
37
|
+
* shard; \`workflow\` is a workflow class name (its \`ctx.exports\` key) whose durable workflow is
|
|
38
|
+
* started fresh per fire. \`args\` are forwarded verbatim (a workflow's become
|
|
39
|
+
* its \`params\`).
|
|
40
|
+
*/
|
|
41
|
+
export interface LunoraCronJob {
|
|
42
|
+
args: Record<string, unknown>;
|
|
43
|
+
functionPath?: string;
|
|
44
|
+
name: string;
|
|
45
|
+
workflow?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Deduplicated cron schedules — mirror of wrangler's \`triggers.crons\`. The
|
|
50
|
+
* Lunora vite plugin keeps \`wrangler.jsonc\` in sync with this array.
|
|
51
|
+
*/
|
|
52
|
+
export const LUNORA_CRON_TRIGGERS: ReadonlyArray<string> = [${e}];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Dispatcher map keyed by cron expression. The Worker's \`scheduled()\` handler
|
|
56
|
+
* looks up \`event.cron\` here and dispatches every job in the list.
|
|
57
|
+
*/
|
|
58
|
+
export const LUNORA_CRONS: Record<string, ReadonlyArray<LunoraCronJob>> = {${d}};
|
|
59
|
+
`},S=n=>{const r=[...n].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(`
|
|
60
|
+
`),o=r.length>0?`
|
|
61
|
+
${r}
|
|
62
|
+
`:"";return`${c}/**
|
|
63
|
+
* One vector index declared in \`schema.ts\` — an inline \`.vectorize()\` column
|
|
64
|
+
* or a standalone \`defineVectorIndex()\`. \`field\` is the source column (absent
|
|
65
|
+
* for a \`select\`-derived Shape B index); \`metadata\` lists the row fields
|
|
66
|
+
* mirrored into Vectorize for filtering.
|
|
67
|
+
*/
|
|
68
|
+
export interface LunoraVectorIndex {
|
|
69
|
+
dimensions?: number;
|
|
70
|
+
field?: string;
|
|
71
|
+
metadata?: ReadonlyArray<string>;
|
|
72
|
+
metric?: "cosine" | "dot-product" | "euclidean";
|
|
73
|
+
name: string;
|
|
74
|
+
table: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Static registry of every vector index in the schema, sorted by name.
|
|
79
|
+
* Vectorize cannot enumerate indexes at runtime, so the worker passes this to
|
|
80
|
+
* \`createWorker({ vectorIntrospector })\` to back the studio's vector browser.
|
|
81
|
+
*/
|
|
82
|
+
export const LUNORA_VECTOR_INDEXES: ReadonlyArray<LunoraVectorIndex> = [${o}];
|
|
83
|
+
`},R=n=>[...new Set(n.map(r=>r.cron))];export{w as emitCrons,u as emitScheduler,y as emitShardRegistry,S as emitVectors,R as emitWranglerCronTriggers};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import{b as k}from"./qualifiers-Cw8dEDbh.mjs";import{a as s,b as i,v as d,e as v,G as M}from"./shared-BXUKWh7t.mjs";const D="schema",w=a=>{for(const e of a.tables)s(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(([h,r])=>{const o=i(h);if(r.kind==="optional"){const g=r.inner?d(r.inner):"unknown";return` ${o}?: ${g};`}return` ${o}: ${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
|
+
`),T=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
|
+
`),f=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=>(s(n.table,"relation target table"),` ${i(n.name)}: ${n.kind==="one"?"OneRelation":"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
|
+
${T}
|
|
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 = ${f};
|
|
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> {
|
|
99
|
+
readonly __relationKind: "one";
|
|
100
|
+
readonly __target: Target;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ManyRelation<Target extends keyof DataModel> {
|
|
104
|
+
readonly __relationKind: "many";
|
|
105
|
+
readonly __target: Target;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Per-table relation map keyed by accessor name. \`{}\` for tables with none. */
|
|
109
|
+
export interface Relations {
|
|
110
|
+
${I}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
`,D)};export{D as SCHEMA_MODULE_PATH,w as emitDataModel};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{SCHEMA_MODULE_PATH as c}from"./emitDataModel-DSk9AkJe.mjs";import{b as m}from"./qualifiers-Cw8dEDbh.mjs";import{G as b,a as g,d as T,v as f,u as A,f as x,c as h}from"./shared-BXUKWh7t.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)=>{g(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,z)=>u.localeCompare(z)),$=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};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import{LunoraError as B}from"@lunora/errors";import{L as H,G as q,I as J,d as Q,r as G,b as z,c as x}from"./shared-BXUKWh7t.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{renderAgentFunctionRegistry as V,renderSandboxFunctionRegistry as W,groupByFileSorted as K}from"./emitApi-xDIHPRPH.mjs";import{r as Y,a as X,b as O,c as Z}from"./qualifiers-Cw8dEDbh.mjs";const ee=new Set(["any","bigint","boolean","date","id","null","number","storage","string","timestamp"]),A=n=>n.column!==void 0,te=(n,e)=>{switch(n){case"bigint":return`if (typeof ${e} !== "bigint") return DEFER;
|
|
2
|
+
`;case"boolean":return`if (typeof ${e} !== "boolean") return DEFER;
|
|
3
|
+
`;case"date":case"number":case"timestamp":return`if (typeof ${e} !== "number" || !Number.isFinite(${e})) return DEFER;
|
|
4
|
+
`;case"null":return`if (${e} !== null) return DEFER;
|
|
5
|
+
`;default:return`if (typeof ${e} !== "string") return DEFER;
|
|
6
|
+
`}},ne=(n,e)=>n.stringMaxLength===void 0?"":`if (${e}.length > ${String(n.stringMaxLength)}) return DEFER;
|
|
7
|
+
`,re=(n,e)=>{const r=n.literalValue?.trim();if(!(r===void 0||!H.test(r)))return{out:e,pre:`if (${e} !== ${r}) return DEFER;
|
|
8
|
+
`}},v=(n,e,r)=>{if(!A(n)&&!(n.unmodelledRefinement||n.sourceText!==void 0)){if(ee.has(n.kind))return n.kind==="any"?{out:e,pre:""}:{out:e,pre:te(n.kind,e)+ne(n,e)};switch(n.kind){case"array":return oe(n,e,r);case"literal":return re(n,e);case"object":return ie(n,e,r);default:return}}},oe=(n,e,r)=>{const{inner:c}=n;if(!c)return;const o=r.next(),a=`__arr${String(o)}`,i=`__i${String(o)}`,s=`__e${String(o)}`,l=v(c,s,r);if(!l)return;const u=`if (!Array.isArray(${e})) return DEFER;
|
|
9
|
+
const ${a} = new Array(${e}.length);
|
|
10
|
+
for (let ${i} = 0; ${i} < ${e}.length; ${i}++) {
|
|
11
|
+
const ${s} = ${e}[${i}];
|
|
12
|
+
${l.pre}${a}[${i}] = ${l.out};
|
|
13
|
+
}
|
|
14
|
+
`;return{out:a,pre:u}},ae=(n,e,r,c)=>{const o=JSON.stringify(n);if(e.kind==="optional"){if(e.hasRefinement||e.sourceText!==void 0||A(e))return;const{inner:i}=e;if(!i)return;const s=v(i,r,c);if(!s)return;const l=c.next(),u=`__has${String(l)}`,d=`__val${String(l)}`,f=`let ${u} = false;
|
|
15
|
+
let ${d};
|
|
16
|
+
if (${r} !== undefined) {
|
|
17
|
+
${s.pre}${d} = ${s.out};
|
|
18
|
+
${u} = true;
|
|
19
|
+
}
|
|
20
|
+
`;return{entry:`...(${u} ? { ${o}: ${d} } : {})`,pre:f}}const a=v(e,r,c);if(a)return{entry:`${o}: ${a.out}`,pre:a.pre}},se=new Set(Object.getOwnPropertyNames(Object.prototype)),_=(n,e,r)=>{let c="";const o=[];for(const a of Object.keys(n)){const i=n[a];if(!i)return;const s=JSON.stringify(a);let l=`${e}[${s}]`;if(se.has(a)){const d=`__f${String(r.next())}`;c+=`const ${d} = Object.hasOwn(${e}, ${s}) ? ${e}[${s}] : undefined;
|
|
21
|
+
`,l=d}const u=ae(a,i,l,r);if(!u)return;c+=u.pre,o.push(u.entry)}return{entries:o.join(", "),pre:c}},T=n=>{const e=`Object.getPrototypeOf(${n})`;return`if (${e} !== Object.prototype && ${e} !== null) return DEFER;
|
|
22
|
+
`},ie=(n,e,r)=>{const c=n.shape??{},o=_(c,e,r);if(!o)return;const a=r.next(),i=`__obj${String(a)}`,s=`if (typeof ${e} !== "object" || ${e} === null || Array.isArray(${e})) return DEFER;
|
|
23
|
+
${T(e)}${o.pre}const ${i} = { ${o.entries} };
|
|
24
|
+
`;return{out:i,pre:s}},ce=n=>{let e=0;const c=_(n,"source",{next:()=>(e+=1,e)});if(c)return`(source) => {
|
|
25
|
+
if (typeof source !== "object" || source === null || Array.isArray(source)) return DEFER;
|
|
26
|
+
${T("source")}${c.pre}return { ${c.entries} };
|
|
27
|
+
}`},le=(n,e)=>`lunora_${p(n)}_${String(e)}`,ue=`const callRegistered = async <R>(context: CallerCtx, functionPath: string, args: Record<string, unknown> | undefined): Promise<R> => {
|
|
28
|
+
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
29
|
+
|
|
30
|
+
if (!registered) {
|
|
31
|
+
throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A mutation is routed through the caller's own \`ctx.runMutation\` rather than
|
|
35
|
+
// invoked directly, so \`createCaller(ctx).ns.someMutation()\` gets exactly what
|
|
36
|
+
// \`ctx.runMutation(api.ns.someMutation)\` gets: the BEGIN/COMMIT span (or the
|
|
37
|
+
// enclosing one, when the caller is already inside a transaction), the jobs it
|
|
38
|
+
// schedules held until that span commits, and the deferred object deletes
|
|
39
|
+
// flushed only once it has. Called straight, a mutation composed from an action
|
|
40
|
+
// or a stream had none of the three — its writes autocommitted one row at a
|
|
41
|
+
// time and its \`ctx.scheduler\` calls dispatched immediately, so a mid-handler
|
|
42
|
+
// throw left the earlier writes durable and the job already enqueued.
|
|
43
|
+
//
|
|
44
|
+
// The fallback covers a context that is not a shard dispatch (\`runMutation\` is
|
|
45
|
+
// installed by \`buildCtx\` on every kind but a query's TYPE omits it); there is
|
|
46
|
+
// no transaction to join in that case, so a direct call is all there is.
|
|
47
|
+
//
|
|
48
|
+
// A query is routed through \`ctx.runQuery\` for the same reason: that is what
|
|
49
|
+
// hands it a query view of a mutation's or action's ctx (no request origin,
|
|
50
|
+
// query-guarded \`run*\`) instead of the caller's own.
|
|
51
|
+
if (registered.kind === "mutation" || registered.kind === "query") {
|
|
52
|
+
const run = (context as { runMutation?: unknown; runQuery?: unknown })[registered.kind === "mutation" ? "runMutation" : "runQuery"];
|
|
53
|
+
|
|
54
|
+
if (typeof run === "function") {
|
|
55
|
+
return (await run.call(context, { __lunoraRef: functionPath }, args ?? {})) as R;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (await registered.handler(context, args ?? {})) as R;
|
|
60
|
+
};`,de=(n,e,r=[],c=[])=>{const o=new Map,a=t=>{o.has(t)||o.set(t,le(t,o.size))};for(const t of n)a(t.filePath);for(const t of e)a(t.filePath);for(const t of r)a(t.filePath);for(const t of c)a(t.filePath);const i=[...o.entries()].map(([t,g])=>{if(!J.test(t))throw new B("INTERNAL",`@lunora/codegen: refusing to emit import for unsafe file path: ${JSON.stringify(t)}`);return`import * as ${g} from "../${t}.js";`}).join(`
|
|
61
|
+
`),s=n.map(t=>` "${p(t.filePath)}:${t.exportName}": ${o.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
62
|
+
`),l=e.map(t=>` ${JSON.stringify(t.id)}: ${o.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredDataMigration,`).join(`
|
|
63
|
+
`),u=r.map(t=>` "${p(t.filePath)}:${t.exportName}": ${o.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredLunoraFunction,`).join(`
|
|
64
|
+
`),d=c.map(t=>` "${t.exportName}": ${o.get(t.filePath)??""}.${t.exportName} as unknown as RegisteredShape,`).join(`
|
|
65
|
+
`),f=r.map(t=>`${p(t.filePath)}:${t.exportName}`),m=[s,u].filter(t=>t.length>0).join(`
|
|
66
|
+
`),R=n.map(t=>{if(t.lifecycle||Object.keys(t.args).length===0)return;const g=ce(t.args);return g===void 0?void 0:`installCompiledValidatorMap(${o.get(t.filePath)??""}.${t.exportName}.args, ${g});`}).filter(t=>t!==void 0).join(`
|
|
67
|
+
`);return{dispatchBody:m.length>0?`
|
|
68
|
+
${m}
|
|
69
|
+
`:"",importBlock:i.length>0?`${i}
|
|
70
|
+
|
|
71
|
+
`:"",installBlock:R,migrationBody:l.length>0?`
|
|
72
|
+
${l}
|
|
73
|
+
`:"",mutatorPaths:f,shapeBody:d.length>0?`
|
|
74
|
+
${d}
|
|
75
|
+
`:""}},he=n=>{const e=K(n),r=e.map(([o,a])=>{const i=a.map(s=>{const l=O(G(s.args),s.filePath),u=l==="{}"?"?":"",d=O(Z(s),s.filePath);return s.kind==="stream"?` ${s.exportName}: (args${u}: ${l}) => Promise<AsyncIterable<${d}>>;`:` ${s.exportName}: (args${u}: ${l}) => Promise<${d}>;`}).join(`
|
|
76
|
+
`);return` ${z(p(o))}: {
|
|
77
|
+
${i}
|
|
78
|
+
};`}).join(`
|
|
79
|
+
`);return{implementation:e.map(([o,a])=>{const i=p(o),s=a.map(l=>` ${x(l.exportName)}: (args) => callRegistered(context, "${i}:${l.exportName}", args),`).join(`
|
|
80
|
+
`);return` ${x(i)}: {
|
|
81
|
+
${s}
|
|
82
|
+
},`}).join(`
|
|
83
|
+
`),types:r}},pe=n=>{const e={connect:[],disconnect:[],init:[],reactor:[],whisper:[]};for(const r of n)r.lifecycle&&e[r.lifecycle].push(`${p(r.filePath)}:${r.exportName}`);return e},be=n=>{const{agents:e=[],functions:r,migrations:c=[],mutators:o=[],shapes:a=[],useUmbrella:i=!1,usesSandbox:s=!1}=n,l=r.length>0,u=Q(i),{dispatchBody:d,importBlock:f,installBlock:m,migrationBody:R,mutatorPaths:t,shapeBody:g}=de(r,c,o,a),b=V(e,r),w=W(s,r),k=[b.lines,w.lines].filter(h=>h.length>0).join(`
|
|
84
|
+
`);let N=d;k.length>0&&(N=d.length>0?`${d.trimEnd()}
|
|
85
|
+
${k}
|
|
86
|
+
`:`
|
|
87
|
+
${k}
|
|
88
|
+
`);const y=pe(r),P=a.length>0?`import type { RegisteredShape } from "${u.server}";
|
|
89
|
+
`:"",L=a.length>0?`
|
|
90
|
+
/**
|
|
91
|
+
* Replication-shape registry — one entry per \`defineShape\` in \`lunora/shapes.ts\`.
|
|
92
|
+
* The generated ShardDO's \`resolveShape\` override looks a shape up by name and
|
|
93
|
+
* evaluates its trusted \`compileWhere(ctx, args)\` to authorize + scope a
|
|
94
|
+
* \`shape_subscribe\` (reads-as-permissions).
|
|
95
|
+
*/
|
|
96
|
+
export const LUNORA_SHAPES: Record<string, RegisteredShape> = {${g}};
|
|
97
|
+
`:"",j=t.length>0?`
|
|
98
|
+
/**
|
|
99
|
+
* Custom-mutator function paths — the \`LUNORA_FUNCTIONS\` keys the generated
|
|
100
|
+
* ShardDO's \`isCustomMutator\` override routes through the client-watermark push
|
|
101
|
+
* protocol (\`x-lunora-client-id\`/\`x-lunora-client-seq\` ordering).
|
|
102
|
+
*/
|
|
103
|
+
export const LUNORA_MUTATOR_PATHS: ReadonlySet<string> = new Set([${t.map(h=>JSON.stringify(h)).join(", ")}]);
|
|
104
|
+
`:"",E=m.length>0?`import { DEFER_VALIDATION as DEFER, installCompiledValidatorMap } from "${u.values}";
|
|
105
|
+
`:"",C=m.length>0?`
|
|
106
|
+
/**
|
|
107
|
+
* AOT-compiled argument validators (Worker-safe, no \`eval\`). Each is installed
|
|
108
|
+
* onto its function's live \`.args\` object and consulted by the interpreted
|
|
109
|
+
* parser as a zero-allocation fast path; anything it can't model is deferred.
|
|
110
|
+
*/
|
|
111
|
+
${m}
|
|
112
|
+
`:"",$=he(r),F=$.types?`
|
|
113
|
+
${$.types}
|
|
114
|
+
`:"",M=$.implementation?`
|
|
115
|
+
${$.implementation}
|
|
116
|
+
`:"",S=Y($.types),D=S.length>0?`import type { ${S.join(", ")} } from "./dataModel.js";
|
|
117
|
+
`:"",I=l?"context":"_context",U=l?`${ue}
|
|
118
|
+
|
|
119
|
+
`:"";return X(`${q}${f}${b.importLine}${w.importLine}${E}${P}import { LunoraError } from "${u.server}";
|
|
120
|
+
import type { ActionCtx, MutationCtx, QueryCtx } from "./server.js";
|
|
121
|
+
${D}
|
|
122
|
+
/**
|
|
123
|
+
* Single registered function, narrowed to the shape \`handleRpc\` needs.
|
|
124
|
+
* The real argument validators / return types are checked elsewhere — at
|
|
125
|
+
* the dispatch site we erase to \`unknown\` so a single map can host every
|
|
126
|
+
* registered function.
|
|
127
|
+
*/
|
|
128
|
+
export interface RegisteredLunoraFunction {
|
|
129
|
+
kind: "action" | "mutation" | "query" | "stream";
|
|
130
|
+
args: Record<string, unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Present on a \`"stream"\` declared \`durable\`: its run is persisted and
|
|
133
|
+
* survives the socket that opened it. Absent on every other kind, and on an
|
|
134
|
+
* ephemeral stream.
|
|
135
|
+
*/
|
|
136
|
+
durable?: { ttlMs?: number };
|
|
137
|
+
/**
|
|
138
|
+
* For \`"action" | "mutation" | "query"\` the handler is awaited and its result returned.
|
|
139
|
+
* For \`"stream"\` the handler returns an \`AsyncIterable\` synchronously and takes an
|
|
140
|
+
* \`AbortSignal\` as a third argument — the runtime drives it frame-by-frame.
|
|
141
|
+
*/
|
|
142
|
+
handler: ((context: unknown, args: Record<string, unknown>) => Promise<unknown> | unknown) | ((context: unknown, args: Record<string, unknown>, signal?: AbortSignal) => AsyncIterable<unknown>);
|
|
143
|
+
/**
|
|
144
|
+
* The lifecycle moment a hook fires on, when this registration came from
|
|
145
|
+
* \`onConnect\`/\`onDisconnect\`/\`onShardInit\`/\`onQueryChange\`/\`onWhisper\`.
|
|
146
|
+
* Read at dispatch to decide whether the function runs system-trusted:
|
|
147
|
+
* \`init\` and \`reactor\` have no caller identity, so RLS has no user to scope
|
|
148
|
+
* to. \`whisper\` does have one — it runs under the asking socket's identity.
|
|
149
|
+
*/
|
|
150
|
+
lifecycle?: "connect" | "disconnect" | "init" | "reactor" | "whisper";
|
|
151
|
+
/**
|
|
152
|
+
* Hoisted by the builder when the \`.use()\` chain carries a step with a
|
|
153
|
+
* per-dispatch effect — \`rateLimit(...)\` consuming budget, a single-use
|
|
154
|
+
* captcha token being burned. Read by \`isCacheableQuery\`: the chain runs
|
|
155
|
+
* inside the dispatch callback, and a reactive-cache HIT skips that
|
|
156
|
+
* callback, so such a query must never be memoized.
|
|
157
|
+
*/
|
|
158
|
+
perDispatch?: boolean;
|
|
159
|
+
/** \`"internal"\` functions are rejected on the external RPC path; absence === public. */
|
|
160
|
+
visibility?: "internal" | "public";
|
|
161
|
+
/**
|
|
162
|
+
* \`.x402({ price })\` tag on a paid public procedure. The origin worker
|
|
163
|
+
* paywalls it; the shard refuses to subscribe it (\`isPaidFunction\`).
|
|
164
|
+
*/
|
|
165
|
+
x402?: { readonly price: number | string };
|
|
166
|
+
}
|
|
167
|
+
${b.prelude}${w.prelude}
|
|
168
|
+
/**
|
|
169
|
+
* Static dispatch table. The key matches the \`__lunoraRef\` the client
|
|
170
|
+
* emits (\`api[namespace][fn].__lunoraRef === "namespace:fn"\`).
|
|
171
|
+
*/
|
|
172
|
+
export const LUNORA_FUNCTIONS: Record<string, RegisteredLunoraFunction> = {${N}};
|
|
173
|
+
${C}${L}${j}
|
|
174
|
+
/**
|
|
175
|
+
* Lifecycle manifest: the function paths the generated ShardDO dispatches when a
|
|
176
|
+
* client's WebSocket connects (\`connect\`) or disconnects (\`disconnect\`), once
|
|
177
|
+
* per Durable Object instance before any handler runs (\`init\`), after a
|
|
178
|
+
* write flush when a watched read's result changed (\`reactor\`), and before a
|
|
179
|
+
* socket joins or broadcasts to a whisper topic (\`whisper\`). Each path also
|
|
180
|
+
* resolves through {@link LUNORA_FUNCTIONS}. The socket-scoped moments run under
|
|
181
|
+
* the socket's verified identity; \`init\` and \`reactor\` have no caller, so they
|
|
182
|
+
* run anonymous — all via system dispatch.
|
|
183
|
+
*/
|
|
184
|
+
export const LUNORA_LIFECYCLE_HOOKS: {
|
|
185
|
+
connect: readonly string[];
|
|
186
|
+
disconnect: readonly string[];
|
|
187
|
+
init: readonly string[];
|
|
188
|
+
reactor: readonly string[];
|
|
189
|
+
whisper: readonly string[];
|
|
190
|
+
} = {
|
|
191
|
+
connect: [${y.connect.map(h=>JSON.stringify(h)).join(", ")}],
|
|
192
|
+
disconnect: [${y.disconnect.map(h=>JSON.stringify(h)).join(", ")}],
|
|
193
|
+
init: [${y.init.map(h=>JSON.stringify(h)).join(", ")}],
|
|
194
|
+
reactor: [${y.reactor.map(h=>JSON.stringify(h)).join(", ")}],
|
|
195
|
+
whisper: [${y.whisper.map(h=>JSON.stringify(h)).join(", ")}],
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Resolve and invoke a registered function from an external caller. Throws a
|
|
200
|
+
* LunoraError-shaped object (404) when the path is unknown — the runtime's
|
|
201
|
+
* structural error mapper turns that into the right HTTP status. Internal
|
|
202
|
+
* functions are treated as not-found so their existence never leaks to clients.
|
|
203
|
+
*/
|
|
204
|
+
export const dispatchLunoraFunction = async (functionPath: string, context: unknown, args: Record<string, unknown>): Promise<unknown> => {
|
|
205
|
+
const registered = LUNORA_FUNCTIONS[functionPath];
|
|
206
|
+
|
|
207
|
+
if (!registered || registered.visibility === "internal") {
|
|
208
|
+
throw new LunoraError("FUNCTION_NOT_FOUND", \`function not registered: \${functionPath}\`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return registered.handler(context, args);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A handler context accepted by {@link createCaller}. The runtime context the
|
|
216
|
+
* shard DO builds is uniform across kinds, so any handler's \`ctx\` works here.
|
|
217
|
+
*/
|
|
218
|
+
export type CallerCtx = ActionCtx | MutationCtx | QueryCtx;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Typed, in-process server-to-server caller. Every registered function — public
|
|
222
|
+
* *and* internal — is reachable; each call dispatches against the same shard
|
|
223
|
+
* with the supplied \`context\`, exactly like \`ctx.runQuery\`/\`runMutation\`/
|
|
224
|
+
* \`runAction\` but without re-stating the function path.
|
|
225
|
+
*/
|
|
226
|
+
export interface Caller {${F}}
|
|
227
|
+
|
|
228
|
+
${U}/** Build a {@link Caller} bound to \`context\` (typically a handler's \`ctx\`). */
|
|
229
|
+
export const createCaller = (${I}: CallerCtx): Caller => ({${M}});
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Single registered data migration, narrowed to the shape the per-shard runner
|
|
233
|
+
* consumes. \`up\`/\`down\` are erased to a structural transform; the authoring
|
|
234
|
+
* validation lives in \`defineMigration\`.
|
|
235
|
+
*/
|
|
236
|
+
export interface RegisteredDataMigration {
|
|
237
|
+
batchSize?: number;
|
|
238
|
+
down?: (document: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
239
|
+
id: string;
|
|
240
|
+
table: string;
|
|
241
|
+
up: (document: Record<string, unknown>) => Record<string, unknown> | undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Registry of online data migrations keyed by \`defineMigration\`'s \`id\`. The
|
|
246
|
+
* shard DO's admin RPC and the CLI resolve migrations to run through this map.
|
|
247
|
+
*/
|
|
248
|
+
export const LUNORA_MIGRATIONS: Record<string, RegisteredDataMigration> = {${R}};
|
|
249
|
+
`,i)};export{be as default};
|