@lunora/codegen 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (35) hide show
  1. package/__assets__/package-og.svg +1 -1
  2. package/dist/index.d.mts +1084 -25
  3. package/dist/index.d.ts +1084 -25
  4. package/dist/index.mjs +29 -23
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-0K-pjNb8.mjs → CONTAINERS_FILENAME-DjpXMqhp.mjs} +1 -1
  6. package/dist/packem_shared/{CodegenDiagnosticError-54jWDxA9.mjs → CodegenDiagnosticError-DyQ5FwkM.mjs} +7 -5
  7. package/dist/packem_shared/FLAGS_FILENAME-BjpS5w08.mjs +139 -0
  8. package/dist/packem_shared/{GENERATED_HEADER-CuLyj0WQ.mjs → GENERATED_HEADER-f6nMvllu.mjs} +853 -65
  9. package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +81 -0
  10. package/dist/packem_shared/{OPENRPC_VERSION-BGUrsrt_.mjs → OPENRPC_VERSION-u5SqDDGk.mjs} +1 -1
  11. package/dist/packem_shared/QUEUES_FILENAME-BF0iUmx7.mjs +119 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Cpfn80SH.mjs +3481 -0
  13. package/dist/packem_shared/{SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs → SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs} +18 -2
  14. package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +94 -0
  15. package/dist/packem_shared/{WORKFLOWS_FILENAME-DRDQdhfq.mjs → WORKFLOWS_FILENAME-CCC_42o3.mjs} +42 -2
  16. package/dist/packem_shared/{buildOpenApiDocument-CXwnbp4b.mjs → buildOpenApiDocument-AgKWmlry.mjs} +1 -1
  17. package/dist/packem_shared/{discoverAuthApiCalls-C35R6z0T.mjs → discoverAuthApiCalls-URDoTADN.mjs} +1 -1
  18. package/dist/packem_shared/{discoverCrons-BL6iGuJ3.mjs → discoverCrons-DdZOeroL.mjs} +20 -17
  19. package/dist/packem_shared/{discoverFunctions-DEgAcRuD.mjs → discoverFunctions-BJdF7lRs.mjs} +63 -9
  20. package/dist/packem_shared/{discoverHttpRoutes-C978pBiG.mjs → discoverHttpRoutes-CcwP-Rkr.mjs} +2 -2
  21. package/dist/packem_shared/{discoverInserts-CRQdXvHO.mjs → discoverInserts-BpFhM32L.mjs} +24 -2
  22. package/dist/packem_shared/{discoverMaskProcedures-B64zA740.mjs → discoverMaskProcedures-DT-v8wvj.mjs} +58 -2
  23. package/dist/packem_shared/{discoverMigrations-Doj_-BAA.mjs → discoverMigrations-cG1idBVM.mjs} +10 -4
  24. package/dist/packem_shared/{discoverNondeterministicCalls-4KiPQxQU.mjs → discoverNondeterministicCalls-CEOjmfk4.mjs} +1 -1
  25. package/dist/packem_shared/{discoverQueries-BkIi0dBD.mjs → discoverQueries-DeVBQVAG.mjs} +1 -1
  26. package/dist/packem_shared/{discoverR2sqlCalls-BpDqvcUn.mjs → discoverR2sqlCalls-CWCAU-xJ.mjs} +1 -1
  27. package/dist/packem_shared/{discoverRlsMetadata-DpRB1HMe.mjs → discoverRlsMetadata-BL0oukaK.mjs} +1 -1
  28. package/dist/packem_shared/{discoverSchema-BBulgGbH.mjs → discoverSchema-CeXJWVKV.mjs} +349 -17
  29. package/dist/packem_shared/{discoverStorageRulesMetadata-DAqJUxUv.mjs → discoverStorageRulesMetadata-CFHByjIl.mjs} +1 -1
  30. package/dist/packem_shared/{emitApp-CzSxVDaG.mjs → emitApp-DKt3rPtr.mjs} +84 -8
  31. package/dist/packem_shared/{formatAdvisories-8NIv1k0I.mjs → formatAdvisories-C9wNBNvL.mjs} +47 -3
  32. package/dist/packem_shared/{parse-validator-tuQtHrsr.mjs → parse-validator-D6zI2i85.mjs} +5 -3
  33. package/dist/packem_shared/redact-oTmsol5A.mjs +33 -0
  34. package/package.json +9 -7
  35. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BQ_kCZ81.mjs +0 -903
@@ -1,3 +1,5 @@
1
+ import { LunoraError } from '@lunora/errors';
2
+
1
3
  const SCHEMA_SNAPSHOT_VERSION = 1;
2
4
  const encodeShardMode = (mode) => {
3
5
  if (mode === "global" || mode === "root") {
@@ -39,6 +41,7 @@ const buildSchemaSnapshot = (schema, migrationIds) => {
39
41
  tables[table.name] = tableSnapshotOf(table);
40
42
  }
41
43
  return {
44
+ jurisdiction: schema.jurisdiction,
42
45
  migrationIds: [...migrationIds].toSorted((a, b) => a.localeCompare(b)),
43
46
  tables: sortKeys(tables),
44
47
  version: SCHEMA_SNAPSHOT_VERSION
@@ -46,8 +49,10 @@ const buildSchemaSnapshot = (schema, migrationIds) => {
46
49
  };
47
50
  const serializeSchemaSnapshot = (snapshot) => `${JSON.stringify(snapshot, void 0, 2)}
48
51
  `;
49
- class SchemaSnapshotParseError extends Error {
50
- name = "SchemaSnapshotParseError";
52
+ class SchemaSnapshotParseError extends LunoraError {
53
+ constructor(message) {
54
+ super("SCHEMA_SNAPSHOT_PARSE", message, { name: "SchemaSnapshotParseError" });
55
+ }
51
56
  }
52
57
  const isRecord = (value) => typeof value === "object" && value !== null;
53
58
  const isValidTableSnapshot = (value) => isRecord(value) && isRecord(value.fields) && isRecord(value.indexes) && isRecord(value.relations) && typeof value.shardMode === "string";
@@ -69,7 +74,9 @@ const parseSchemaSnapshot = (content) => {
69
74
  throw new SchemaSnapshotParseError(`baseline table "${name}" has an invalid structure`);
70
75
  }
71
76
  }
77
+ const jurisdiction = typeof parsed.jurisdiction === "string" ? parsed.jurisdiction : void 0;
72
78
  return {
79
+ jurisdiction,
73
80
  migrationIds: Array.isArray(parsed.migrationIds) ? parsed.migrationIds : [],
74
81
  tables: parsed.tables,
75
82
  version: SCHEMA_SNAPSHOT_VERSION
@@ -189,6 +196,15 @@ const diffSchemaSnapshots = (baseline, current) => {
189
196
  });
190
197
  }
191
198
  }
199
+ if (baseline !== void 0 && baseline.jurisdiction !== current.jurisdiction) {
200
+ const from = baseline.jurisdiction ?? "(none)";
201
+ const to = current.jurisdiction ?? "(none)";
202
+ changes.push({
203
+ severity: "breaking",
204
+ summary: `Durable Object jurisdiction changed from ${from} to ${to} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,
205
+ type: "changedJurisdiction"
206
+ });
207
+ }
192
208
  return { changes };
193
209
  };
194
210
  const evaluateSchemaDrift = (options) => {
@@ -0,0 +1,94 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { SyntaxKind, Node } from 'ts-morph';
4
+ import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
5
+
6
+ const SHAPES_FILENAME = "shapes.ts";
7
+ const SHAPE_MODULE_SPECIFIERS = /* @__PURE__ */ new Set(["@lunora/server", "lunorash/server"]);
8
+ const isDefineShape = (identifier) => {
9
+ const symbol = identifier.getSymbol();
10
+ if (!symbol) {
11
+ return identifier.getText() === "defineShape";
12
+ }
13
+ for (const declaration of symbol.getDeclarations()) {
14
+ if (!Node.isImportSpecifier(declaration)) {
15
+ continue;
16
+ }
17
+ if (!SHAPE_MODULE_SPECIFIERS.has(declaration.getImportDeclaration().getModuleSpecifierValue())) {
18
+ return false;
19
+ }
20
+ return declaration.getNameNode().getText() === "defineShape";
21
+ }
22
+ return false;
23
+ };
24
+ const isShapeNamespaceImport = (identifier) => {
25
+ const symbol = identifier.getSymbol();
26
+ if (!symbol) {
27
+ return false;
28
+ }
29
+ for (const declaration of symbol.getDeclarations()) {
30
+ if (!Node.isNamespaceImport(declaration)) {
31
+ continue;
32
+ }
33
+ const importDeclaration = declaration.getFirstAncestorByKind(SyntaxKind.ImportDeclaration);
34
+ return importDeclaration !== void 0 && SHAPE_MODULE_SPECIFIERS.has(importDeclaration.getModuleSpecifierValue());
35
+ }
36
+ return false;
37
+ };
38
+ const isDefineShapeCallee = (callee) => {
39
+ if (Node.isIdentifier(callee)) {
40
+ return isDefineShape(callee);
41
+ }
42
+ if (Node.isPropertyAccessExpression(callee)) {
43
+ const object = callee.getExpression();
44
+ return callee.getName() === "defineShape" && Node.isIdentifier(object) && isShapeNamespaceImport(object);
45
+ }
46
+ return false;
47
+ };
48
+ const tableLiteralFrom = (call) => {
49
+ const [config] = call.getArguments();
50
+ if (!config || !Node.isObjectLiteralExpression(config)) {
51
+ return void 0;
52
+ }
53
+ const tableProperty = config.getProperty("table");
54
+ if (!tableProperty || !Node.isPropertyAssignment(tableProperty)) {
55
+ return void 0;
56
+ }
57
+ const value = tableProperty.getInitializer();
58
+ return value && Node.isStringLiteral(value) ? value.getLiteralValue() : void 0;
59
+ };
60
+ const shapesFromSource = (source) => {
61
+ const shapes = [];
62
+ for (const declaration of source.getVariableDeclarations()) {
63
+ if (!declaration.isExported()) {
64
+ continue;
65
+ }
66
+ const initializer = declaration.getInitializer();
67
+ if (initializer?.getKind() !== SyntaxKind.CallExpression) {
68
+ continue;
69
+ }
70
+ const callExpression = initializer;
71
+ const callee = callExpression.getExpression();
72
+ if (!isDefineShapeCallee(callee)) {
73
+ continue;
74
+ }
75
+ const nameNode = declaration.getNameNode();
76
+ if (!Node.isIdentifier(nameNode)) {
77
+ throw diagnosticAt(nameNode, "defineShape exports must be plain named exports (no destructuring)");
78
+ }
79
+ shapes.push({ exportName: nameNode.getText(), filePath: "shapes", table: tableLiteralFrom(callExpression) });
80
+ }
81
+ return shapes;
82
+ };
83
+ const discoverShapes = (project, lunoraDirectory) => {
84
+ const shapesPath = join(lunoraDirectory, SHAPES_FILENAME);
85
+ if (!existsSync(shapesPath)) {
86
+ return [];
87
+ }
88
+ const source = project.getSourceFile(shapesPath) ?? project.addSourceFileAtPath(shapesPath);
89
+ const shapes = shapesFromSource(source);
90
+ shapes.sort((a, b) => a.exportName.localeCompare(b.exportName));
91
+ return shapes;
92
+ };
93
+
94
+ export { SHAPES_FILENAME, discoverShapes };
@@ -2,9 +2,10 @@ import { existsSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { workflowDefaultName, workflowClassName, workflowBindingName } from '@lunora/workflow';
4
4
  import { SyntaxKind, Node } from 'ts-morph';
5
- import { diagnosticAt } from './CodegenDiagnosticError-54jWDxA9.mjs';
5
+ import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
6
6
 
7
7
  const WORKFLOWS_FILENAME = "workflows.ts";
8
+ const STEP_METHODS = /* @__PURE__ */ new Set(["do", "sleep", "sleepUntil", "waitForEvent"]);
8
9
  const isDefineWorkflow = (identifier) => {
9
10
  const symbol = identifier.getSymbol();
10
11
  if (!symbol) {
@@ -30,6 +31,44 @@ const stringProperty = (expression, exportName, property) => {
30
31
  `workflow "${exportName}": \`${property}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`
31
32
  );
32
33
  };
34
+ const isStepCall = (call) => {
35
+ const callee = call.getExpression();
36
+ if (!Node.isPropertyAccessExpression(callee) || !STEP_METHODS.has(callee.getName())) {
37
+ return false;
38
+ }
39
+ const receiver = callee.getExpression();
40
+ if (Node.isPropertyAccessExpression(receiver) && receiver.getName() === "step") {
41
+ return true;
42
+ }
43
+ return Node.isIdentifier(receiver) && receiver.getText() === "step";
44
+ };
45
+ const stepsFromHandler = (argument) => {
46
+ const handlerProperty = argument.getProperty("handler");
47
+ if (!handlerProperty) {
48
+ return [];
49
+ }
50
+ const body = Node.isPropertyAssignment(handlerProperty) ? handlerProperty.getInitializer() : handlerProperty;
51
+ if (!body) {
52
+ return [];
53
+ }
54
+ const steps = [];
55
+ for (const call of body.getDescendantsOfKind(SyntaxKind.CallExpression)) {
56
+ if (!isStepCall(call)) {
57
+ continue;
58
+ }
59
+ const nameArgument = call.getArguments()[0];
60
+ if (!nameArgument || !(Node.isStringLiteral(nameArgument) || Node.isNoSubstitutionTemplateLiteral(nameArgument))) {
61
+ continue;
62
+ }
63
+ steps.push({
64
+ line: call.getStartLineNumber(),
65
+ // `isStepCall` already proved the callee is a `.<method>` property access.
66
+ method: call.getExpression().getName(),
67
+ name: nameArgument.getLiteralValue()
68
+ });
69
+ }
70
+ return steps;
71
+ };
33
72
  const workflowFromCall = (call, exportName) => {
34
73
  const argument = call.getArguments()[0];
35
74
  if (!argument || !Node.isObjectLiteralExpression(argument)) {
@@ -39,7 +78,8 @@ const workflowFromCall = (call, exportName) => {
39
78
  bindingName: workflowBindingName(exportName),
40
79
  className: workflowClassName(exportName),
41
80
  exportName,
42
- name: workflowDefaultName(exportName)
81
+ name: workflowDefaultName(exportName),
82
+ steps: stepsFromHandler(argument)
43
83
  };
44
84
  const nameProperty = argument.getProperty("name");
45
85
  if (nameProperty && Node.isPropertyAssignment(nameProperty)) {
@@ -1,4 +1,4 @@
1
- import { GENERATED_HEADER } from './GENERATED_HEADER-CuLyj0WQ.mjs';
1
+ import { GENERATED_HEADER } from './GENERATED_HEADER-f6nMvllu.mjs';
2
2
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
3
3
  import { LUNORA_ERROR_CODES, objectSchema, argsObjectSchema, validatorIrToJsonSchema } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
4
4
 
@@ -1,7 +1,7 @@
1
1
  import { relative, sep } from 'node:path';
2
2
  import { SyntaxKind, Node } from 'ts-morph';
3
3
  import { T as TS_EXTENSION_RE, e as enclosingExportName } from './discover-ast-CT6BgBr4.mjs';
4
- import { listLunoraSourceFiles } from './discoverFunctions-DEgAcRuD.mjs';
4
+ import { listLunoraSourceFiles } from './discoverFunctions-BJdF7lRs.mjs';
5
5
 
6
6
  const isAuthApiCall = (call) => {
7
7
  const callee = call.getExpression();
@@ -1,6 +1,7 @@
1
1
  import { isValidCronExpression, compileCronSchedule, CRON_SCHEDULE_KINDS } from '@lunora/scheduler';
2
2
  import { SyntaxKind, Node } from 'ts-morph';
3
- import { listLunoraSourceFiles } from './discoverFunctions-DEgAcRuD.mjs';
3
+ import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
4
+ import { listLunoraSourceFiles } from './discoverFunctions-BJdF7lRs.mjs';
4
5
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
5
6
 
6
7
  const CRON_METHODS = /* @__PURE__ */ new Set([...CRON_SCHEDULE_KINDS, "cron"]);
@@ -71,7 +72,7 @@ const literalValue = (node, jobName) => {
71
72
  if (Node.isArrayLiteralExpression(node)) {
72
73
  return node.getElements().map((element) => literalValue(element, jobName));
73
74
  }
74
- throw Object.assign(new Error(`Cron job "${jobName}" passes a non-static value where a literal is required; codegen can only read literals.`), {
75
+ throw diagnosticAt(node, `Cron job "${jobName}" passes a non-static value where a literal is required; codegen can only read literals.`, {
75
76
  code: "CRON_NON_STATIC_VALUE",
76
77
  name: "LunoraError",
77
78
  status: 500
@@ -81,8 +82,9 @@ const objectLiteralValue = (object, jobName) => {
81
82
  const result = {};
82
83
  for (const property of object.getProperties()) {
83
84
  if (!Node.isPropertyAssignment(property)) {
84
- throw Object.assign(
85
- new Error(`Cron job "${jobName}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`),
85
+ throw diagnosticAt(
86
+ property,
87
+ `Cron job "${jobName}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,
86
88
  {
87
89
  code: "CRON_NON_STATIC_VALUE",
88
90
  name: "LunoraError",
@@ -100,8 +102,9 @@ const objectLiteralValue = (object, jobName) => {
100
102
  const functionPathFromArgument = (call, index, jobName) => {
101
103
  const argument = call.getArguments()[index];
102
104
  if (!argument || !Node.isPropertyAccessExpression(argument)) {
103
- throw Object.assign(
104
- new Error(`Cron job "${jobName}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`),
105
+ throw diagnosticAt(
106
+ call,
107
+ `Cron job "${jobName}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,
105
108
  {
106
109
  code: "CRON_NON_STATIC_FN",
107
110
  name: "LunoraError",
@@ -112,7 +115,7 @@ const functionPathFromArgument = (call, index, jobName) => {
112
115
  const functionName = argument.getName();
113
116
  const receiver = argument.getExpression();
114
117
  if (!Node.isPropertyAccessExpression(receiver)) {
115
- throw Object.assign(new Error(`Cron job "${jobName}" function reference must be of the form internal.file.fn (two property accesses).`), {
118
+ throw diagnosticAt(argument, `Cron job "${jobName}" function reference must be of the form internal.file.fn (two property accesses).`, {
116
119
  code: "CRON_NON_STATIC_FN",
117
120
  name: "LunoraError",
118
121
  status: 500
@@ -133,8 +136,9 @@ const resolveTarget = (call, index, jobName, workflowsByName) => {
133
136
  if (workflow) {
134
137
  return workflowTarget(workflow);
135
138
  }
136
- throw Object.assign(
137
- new Error(`Cron job "${jobName}" targets workflows.${argument.getName()}, but no such workflow is declared in lunora/workflows.ts.`),
139
+ throw diagnosticAt(
140
+ argument,
141
+ `Cron job "${jobName}" targets workflows.${argument.getName()}, but no such workflow is declared in lunora/workflows.ts.`,
138
142
  {
139
143
  code: "CRON_NON_STATIC_FN",
140
144
  name: "LunoraError",
@@ -149,10 +153,9 @@ const resolveTarget = (call, index, jobName, workflowsByName) => {
149
153
  if (workflow) {
150
154
  return workflowTarget(workflow);
151
155
  }
152
- throw Object.assign(
153
- new Error(
154
- `Cron job "${jobName}" references "${argument.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts.`
155
- ),
156
+ throw diagnosticAt(
157
+ argument,
158
+ `Cron job "${jobName}" references "${argument.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts.`,
156
159
  {
157
160
  code: "CRON_NON_STATIC_FN",
158
161
  name: "LunoraError",
@@ -172,7 +175,7 @@ const cronFromCall = (call, callee, builderNames, workflowsByName) => {
172
175
  }
173
176
  const name = stringArgument(call, 0);
174
177
  if (name === void 0 || name.trim() === "") {
175
- throw Object.assign(new Error(`A cron ".${method}(...)" registration must pass a non-empty string-literal name as its first argument.`), {
178
+ throw diagnosticAt(call, `A cron ".${method}(...)" registration must pass a non-empty string-literal name as its first argument.`, {
176
179
  code: "CRON_NAME_NOT_STATIC",
177
180
  name: "LunoraError",
178
181
  status: 500
@@ -182,14 +185,14 @@ const cronFromCall = (call, callee, builderNames, workflowsByName) => {
182
185
  if (method === "cron") {
183
186
  const expression = stringArgument(call, 1);
184
187
  if (expression === void 0) {
185
- throw Object.assign(new Error(`Cron job "${name}" must pass a string-literal cron expression to ".cron(...)".`), {
188
+ throw diagnosticAt(call, `Cron job "${name}" must pass a string-literal cron expression to ".cron(...)".`, {
186
189
  code: "CRON_EXPR_NOT_STATIC",
187
190
  name: "LunoraError",
188
191
  status: 500
189
192
  });
190
193
  }
191
194
  if (!isValidCronExpression(expression)) {
192
- throw Object.assign(new Error(`Cron job "${name}" has an invalid cron expression "${expression}" — expected 5 or 6 space-separated fields.`), {
195
+ throw diagnosticAt(call, `Cron job "${name}" has an invalid cron expression "${expression}" — expected 5 or 6 space-separated fields.`, {
193
196
  code: "CRON_EXPR_INVALID",
194
197
  name: "LunoraError",
195
198
  status: 500
@@ -199,7 +202,7 @@ const cronFromCall = (call, callee, builderNames, workflowsByName) => {
199
202
  } else {
200
203
  const scheduleArgument = call.getArguments()[1];
201
204
  if (!scheduleArgument || !Node.isObjectLiteralExpression(scheduleArgument)) {
202
- throw Object.assign(new Error(`Cron job "${name}" must pass an object-literal schedule to ".${method}(...)".`), {
205
+ throw diagnosticAt(call, `Cron job "${name}" must pass an object-literal schedule to ".${method}(...)".`, {
203
206
  code: "CRON_SCHEDULE_NOT_STATIC",
204
207
  name: "LunoraError",
205
208
  status: 500
@@ -1,7 +1,7 @@
1
1
  import { readdirSync, lstatSync } from 'node:fs';
2
2
  import { join, extname, relative, sep } from 'node:path';
3
3
  import { Node, SyntaxKind } from 'ts-morph';
4
- import { a as parseObjectShape } from './parse-validator-tuQtHrsr.mjs';
4
+ import { a as parseObjectShape } from './parse-validator-D6zI2i85.mjs';
5
5
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
6
6
 
7
7
  const FUNCTION_KINDS = /* @__PURE__ */ new Set(["action", "mutation", "query", "stream"]);
@@ -290,23 +290,72 @@ const classifyProcedureCall = (call) => {
290
290
  if (!Node.isIdentifier(callee)) {
291
291
  return void 0;
292
292
  }
293
- const calleeName = resolveCalleeKind(callee);
294
- if (!calleeName) {
293
+ const calleeName2 = resolveCalleeKind(callee);
294
+ if (!calleeName2) {
295
295
  return void 0;
296
296
  }
297
- if (FUNCTION_KINDS.has(calleeName)) {
298
- return { kind: calleeName, visibility: "public" };
297
+ if (FUNCTION_KINDS.has(calleeName2)) {
298
+ return { kind: calleeName2, visibility: "public" };
299
299
  }
300
- const internalKind = INTERNAL_FACTORIES[calleeName];
300
+ const internalKind = INTERNAL_FACTORIES[calleeName2];
301
301
  if (internalKind) {
302
302
  return { kind: internalKind, visibility: "internal" };
303
303
  }
304
- const lifecycle = LIFECYCLE_FACTORIES[calleeName];
304
+ const lifecycle = LIFECYCLE_FACTORIES[calleeName2];
305
305
  if (lifecycle) {
306
306
  return { kind: "mutation", lifecycle, visibility: "internal" };
307
307
  }
308
308
  return void 0;
309
309
  };
310
+ const inlineHandler = (argument) => argument !== void 0 && (Node.isArrowFunction(argument) || Node.isFunctionExpression(argument)) ? argument : void 0;
311
+ const isDatabaseAccessor = (receiver) => Node.isPropertyAccessExpression(receiver) && receiver.getName() === "db" || Node.isIdentifier(receiver) && receiver.getText() === "db";
312
+ const procedureHandler = (initializer) => {
313
+ const argument = initializer.getArguments()[0];
314
+ const direct = inlineHandler(argument);
315
+ if (direct !== void 0) {
316
+ return direct;
317
+ }
318
+ if (argument === void 0 || !Node.isObjectLiteralExpression(argument)) {
319
+ return void 0;
320
+ }
321
+ const property = argument.getProperty("handler");
322
+ return property !== void 0 && Node.isPropertyAssignment(property) ? inlineHandler(property.getInitializer()) : void 0;
323
+ };
324
+ const calleeName = (callee) => {
325
+ if (Node.isIdentifier(callee)) {
326
+ return callee.getText();
327
+ }
328
+ return Node.isPropertyAccessExpression(callee) ? callee.getName() : "";
329
+ };
330
+ const chainHasStep = (receiver, method) => {
331
+ let node = receiver;
332
+ while (Node.isCallExpression(node)) {
333
+ const callee = node.getExpression();
334
+ if (!Node.isPropertyAccessExpression(callee)) {
335
+ break;
336
+ }
337
+ if (callee.getName() === method) {
338
+ return true;
339
+ }
340
+ node = callee.getExpression();
341
+ }
342
+ return false;
343
+ };
344
+ const chainUsesWrappedCall = (receiver, method, wrappedCallee) => {
345
+ let node = receiver;
346
+ while (Node.isCallExpression(node)) {
347
+ const callee = node.getExpression();
348
+ if (!Node.isPropertyAccessExpression(callee)) {
349
+ break;
350
+ }
351
+ const argument = node.getArguments()[0];
352
+ if (callee.getName() === method && argument !== void 0 && Node.isCallExpression(argument) && calleeName(argument.getExpression()) === wrappedCallee) {
353
+ return true;
354
+ }
355
+ node = callee.getExpression();
356
+ }
357
+ return false;
358
+ };
310
359
  const listLunoraSourceFiles = (directory, accumulator = []) => {
311
360
  let entries;
312
361
  try {
@@ -344,7 +393,12 @@ const discoverFromCall = (call) => {
344
393
  if (classified.lifecycle) {
345
394
  return { args: {}, kind: classified.kind, lifecycle: classified.lifecycle, returnType: "void", visibility: classified.visibility };
346
395
  }
347
- return { args: argsFromCall(call), kind: classified.kind, returnType: returnTypeFromCall(call), visibility: classified.visibility };
396
+ return {
397
+ args: argsFromCall(call),
398
+ kind: classified.kind,
399
+ returnType: returnTypeFromCall(call),
400
+ visibility: classified.visibility
401
+ };
348
402
  };
349
403
  const RE_EXPORT_RESOLVE_LIMIT = 8;
350
404
  const resolveExpressionToCall = (node, depth = 0) => {
@@ -457,4 +511,4 @@ const discoverFunctions = (project, lunoraDirectory) => {
457
511
  return functions;
458
512
  };
459
513
 
460
- export { classifyProcedureCall, discoverFunctions, listLunoraSourceFiles, lunoraRelativePath };
514
+ export { chainHasStep, chainUsesWrappedCall, classifyProcedureCall, discoverFunctions, inlineHandler, isDatabaseAccessor, listLunoraSourceFiles, lunoraRelativePath, procedureHandler };
@@ -1,7 +1,7 @@
1
1
  import { relative, sep } from 'node:path';
2
2
  import { Node } from 'ts-morph';
3
- import { listLunoraSourceFiles } from './discoverFunctions-DEgAcRuD.mjs';
4
- import { p as parseValidator, a as parseObjectShape } from './parse-validator-tuQtHrsr.mjs';
3
+ import { listLunoraSourceFiles } from './discoverFunctions-BJdF7lRs.mjs';
4
+ import { p as parseValidator, a as parseObjectShape } from './parse-validator-D6zI2i85.mjs';
5
5
 
6
6
  const TS_EXTENSION_RE = /\.ts$/u;
7
7
  const HTTP_VERBS = /* @__PURE__ */ new Set(["delete", "get", "head", "options", "patch", "post", "put"]);
@@ -1,6 +1,6 @@
1
1
  import { SyntaxKind, Node } from 'ts-morph';
2
2
  import { e as enclosingExportName } from './discover-ast-CT6BgBr4.mjs';
3
- import { listLunoraSourceFiles, lunoraRelativePath } from './discoverFunctions-DEgAcRuD.mjs';
3
+ import { listLunoraSourceFiles, lunoraRelativePath } from './discoverFunctions-BJdF7lRs.mjs';
4
4
 
5
5
  const isDatabaseInsertCall = (call) => {
6
6
  const callee = call.getExpression();
@@ -13,9 +13,31 @@ const isDatabaseInsertCall = (call) => {
13
13
  }
14
14
  return Node.isIdentifier(receiver) && receiver.getText() === "db";
15
15
  };
16
+ const resolveStringConst = (identifier) => {
17
+ if (!Node.isIdentifier(identifier)) {
18
+ return void 0;
19
+ }
20
+ const symbol = identifier.getSymbol();
21
+ const declarations = symbol?.getAliasedSymbol()?.getDeclarations() ?? symbol?.getDeclarations() ?? [];
22
+ for (const declaration of declarations) {
23
+ if (Node.isVariableDeclaration(declaration)) {
24
+ const initializer = declaration.getInitializer();
25
+ if (initializer && Node.isStringLiteral(initializer)) {
26
+ return initializer.getLiteralText();
27
+ }
28
+ }
29
+ }
30
+ return void 0;
31
+ };
16
32
  const tableOf = (call) => {
17
33
  const argument = call.getArguments()[0];
18
- return argument && Node.isStringLiteral(argument) ? argument.getLiteralText() : "";
34
+ if (!argument) {
35
+ return "";
36
+ }
37
+ if (Node.isStringLiteral(argument)) {
38
+ return argument.getLiteralText();
39
+ }
40
+ return resolveStringConst(argument) ?? "";
19
41
  };
20
42
  const discoverInserts = (project, lunoraDirectory) => {
21
43
  const writes = [];
@@ -1,5 +1,5 @@
1
1
  import { Node, SyntaxKind } from 'ts-morph';
2
- import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-DEgAcRuD.mjs';
2
+ import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-BJdF7lRs.mjs';
3
3
 
4
4
  const isMaskCall = (node) => {
5
5
  if (!Node.isCallExpression(node)) {
@@ -213,5 +213,61 @@ const discoverMaskMetadata = (project, lunoraDirectory) => {
213
213
  }
214
214
  return { columns: [...columnsByKey.values()] };
215
215
  };
216
+ const extractMaskStrategyRows = (maskCall, exportName, relativePath) => {
217
+ const argument = maskCall.getArguments()[0];
218
+ if (!argument || !Node.isObjectLiteralExpression(argument)) {
219
+ return [];
220
+ }
221
+ const rows = [];
222
+ for (const tableProperty of argument.getProperties()) {
223
+ const table = memberName(tableProperty);
224
+ if (table === void 0 || !Node.isPropertyAssignment(tableProperty)) {
225
+ continue;
226
+ }
227
+ const initializer = tableProperty.getInitializer();
228
+ if (!initializer || !Node.isObjectLiteralExpression(initializer)) {
229
+ continue;
230
+ }
231
+ for (const columnProperty of initializer.getProperties()) {
232
+ const column = memberName(columnProperty);
233
+ if (column === void 0) {
234
+ continue;
235
+ }
236
+ const strategy = strategyOf(columnProperty);
237
+ if (strategy === "custom") {
238
+ continue;
239
+ }
240
+ rows.push({ column, exportName, file: relativePath, line: columnProperty.getStartLineNumber(), strategy, table });
241
+ }
242
+ }
243
+ return rows;
244
+ };
245
+ const maskStrategyRowsFromDeclaration = (declaration, relativePath) => {
246
+ if (!Node.isVariableDeclaration(declaration)) {
247
+ return [];
248
+ }
249
+ const initializer = declaration.getInitializer();
250
+ const classified = initializer && Node.isCallExpression(initializer) ? classifyProcedureCall(initializer) : void 0;
251
+ if (!classified?.receiver) {
252
+ return [];
253
+ }
254
+ return maskCallsInChain(classified.receiver).flatMap((maskCall) => extractMaskStrategyRows(maskCall, declaration.getName(), relativePath));
255
+ };
256
+ const discoverMaskStrategies = (project, lunoraDirectory) => {
257
+ const rows = [];
258
+ for (const filePath of listLunoraSourceFiles(lunoraDirectory)) {
259
+ const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
260
+ const relativePath = lunoraRelativePath(lunoraDirectory, filePath);
261
+ for (const statement of sourceFile.getVariableStatements()) {
262
+ if (!statement.isExported()) {
263
+ continue;
264
+ }
265
+ for (const declaration of statement.getDeclarations()) {
266
+ rows.push(...maskStrategyRowsFromDeclaration(declaration, relativePath));
267
+ }
268
+ }
269
+ }
270
+ return rows;
271
+ };
216
272
 
217
- export { discoverMaskProcedures as default, discoverMaskMetadata };
273
+ export { discoverMaskProcedures as default, discoverMaskMetadata, discoverMaskStrategies };
@@ -1,6 +1,7 @@
1
1
  import { relative, sep } from 'node:path';
2
2
  import { SyntaxKind, Node } from 'ts-morph';
3
- import { listLunoraSourceFiles } from './discoverFunctions-DEgAcRuD.mjs';
3
+ import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
4
+ import { listLunoraSourceFiles } from './discoverFunctions-BJdF7lRs.mjs';
4
5
 
5
6
  const TS_EXTENSION_RE = /\.ts$/u;
6
7
  const isDefineMigration = (identifier) => {
@@ -43,9 +44,14 @@ const migrationFromDeclaration = (declaration, relativePath) => {
43
44
  const id = stringProperty(argument, "id");
44
45
  const exportName = declaration.getName();
45
46
  if (id === void 0 || id.trim() === "") {
46
- throw Object.assign(
47
- new Error(`Migration "${exportName}" in "${relativePath}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`),
48
- { code: "MIGRATION_ID_NOT_STATIC", name: "LunoraError", status: 500 }
47
+ throw diagnosticAt(
48
+ argument,
49
+ `Migration "${exportName}" in "${relativePath}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,
50
+ {
51
+ code: "MIGRATION_ID_NOT_STATIC",
52
+ name: "LunoraError",
53
+ status: 500
54
+ }
49
55
  );
50
56
  }
51
57
  return { exportName, filePath: relativePath, id, table: stringProperty(argument, "table") ?? "" };
@@ -1,5 +1,5 @@
1
1
  import { Node, SyntaxKind } from 'ts-morph';
2
- import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-DEgAcRuD.mjs';
2
+ import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-BJdF7lRs.mjs';
3
3
 
4
4
  const PROPERTY_CALLS = {
5
5
  "crypto.getRandomValues": "crypto.getRandomValues",
@@ -1,5 +1,5 @@
1
1
  import { SyntaxKind, Node } from 'ts-morph';
2
- import { listLunoraSourceFiles, lunoraRelativePath } from './discoverFunctions-DEgAcRuD.mjs';
2
+ import { listLunoraSourceFiles, lunoraRelativePath } from './discoverFunctions-BJdF7lRs.mjs';
3
3
 
4
4
  const INDEX_METHODS = /* @__PURE__ */ new Set(["withIndex", "withSearchIndex"]);
5
5
  const isDatabaseQueryCall = (call) => {
@@ -1,5 +1,5 @@
1
1
  import { Node, SyntaxKind } from 'ts-morph';
2
- import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-DEgAcRuD.mjs';
2
+ import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-BJdF7lRs.mjs';
3
3
 
4
4
  const handlerOf = (call, receiver) => {
5
5
  if (receiver) {
@@ -1,5 +1,5 @@
1
1
  import { Node, SyntaxKind } from 'ts-morph';
2
- import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-DEgAcRuD.mjs';
2
+ import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-BJdF7lRs.mjs';
3
3
 
4
4
  const isRlsCall = (node) => {
5
5
  if (!Node.isCallExpression(node)) {