@lunora/codegen 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (34) hide show
  1. package/__assets__/package-og.svg +1 -1
  2. package/dist/index.d.mts +444 -16
  3. package/dist/index.d.ts +444 -16
  4. package/dist/index.mjs +28 -22
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-0K-pjNb8.mjs → CONTAINERS_FILENAME-DlP6YM_Q.mjs} +1 -1
  6. package/dist/packem_shared/{CodegenDiagnosticError-54jWDxA9.mjs → CodegenDiagnosticError-DeblMkzO.mjs} +3 -2
  7. package/dist/packem_shared/FLAGS_FILENAME-B1vE0LIo.mjs +139 -0
  8. package/dist/packem_shared/{emitApi-hRVC-kE7.mjs → GENERATED_HEADER-CI272wRm.mjs} +873 -54
  9. package/dist/packem_shared/LUNORA_SOLUTION_RULES-BTejmZp-.mjs +131 -0
  10. package/dist/packem_shared/MUTATORS_FILENAME-BhqdPtKp.mjs +81 -0
  11. package/dist/packem_shared/{buildOpenRpcDocument-BZGY1-jT.mjs → OPENRPC_VERSION-t5pV2NIN.mjs} +1 -1
  12. package/dist/packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs +119 -0
  13. package/dist/packem_shared/{createCodegenProject-DGJm0_Pk.mjs → SCHEMA_SNAPSHOT_FILENAME-BMez-jgr.mjs} +187 -43
  14. package/dist/packem_shared/{buildSchemaSnapshot-DzLDbWk3.mjs → SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs} +12 -0
  15. package/dist/packem_shared/SHAPES_FILENAME-ChV7MqgE.mjs +94 -0
  16. package/dist/packem_shared/{discoverWorkflows-DRDQdhfq.mjs → WORKFLOWS_FILENAME-CCisG0Vy.mjs} +42 -2
  17. package/dist/packem_shared/{buildOpenApiDocument-yHVN66Xd.mjs → buildOpenApiDocument-Dx5QftUn.mjs} +1 -1
  18. package/dist/packem_shared/{discoverAuthApiCalls-C35R6z0T.mjs → discoverAuthApiCalls-CoirYbg6.mjs} +1 -1
  19. package/dist/packem_shared/{discoverCrons-BL6iGuJ3.mjs → discoverCrons-Cev7RRAf.mjs} +20 -17
  20. package/dist/packem_shared/{discoverFunctions-DEgAcRuD.mjs → discoverFunctions-BWMczzBx.mjs} +7 -2
  21. package/dist/packem_shared/{discoverHttpRoutes-C978pBiG.mjs → discoverHttpRoutes-CfP6cMzt.mjs} +2 -2
  22. package/dist/packem_shared/{discoverInserts-CRQdXvHO.mjs → discoverInserts-C7zxXkUf.mjs} +24 -2
  23. package/dist/packem_shared/{discoverMaskProcedures-B64zA740.mjs → discoverMaskProcedures-Cm81kwrb.mjs} +1 -1
  24. package/dist/packem_shared/{discoverMigrations-Doj_-BAA.mjs → discoverMigrations-Bi5nJ0mJ.mjs} +10 -4
  25. package/dist/packem_shared/{discoverNondeterministicCalls-4KiPQxQU.mjs → discoverNondeterministicCalls-C4M8AXmQ.mjs} +1 -1
  26. package/dist/packem_shared/{discoverQueries-BkIi0dBD.mjs → discoverQueries-B0wGT-xe.mjs} +1 -1
  27. package/dist/packem_shared/discoverR2sqlCalls-BVNMd428.mjs +80 -0
  28. package/dist/packem_shared/{discoverRlsMetadata-DpRB1HMe.mjs → discoverRlsMetadata-BS9GOGC5.mjs} +1 -1
  29. package/dist/packem_shared/{discoverSchema-BBulgGbH.mjs → discoverSchema-KYq55qu3.mjs} +338 -16
  30. package/dist/packem_shared/{discoverStorageRulesMetadata-DAqJUxUv.mjs → discoverStorageRulesMetadata-Da8BKXcI.mjs} +1 -1
  31. package/dist/packem_shared/{emitApp-CzZ6GbrD.mjs → emitApp-cOSypPuO.mjs} +74 -8
  32. package/dist/packem_shared/{lintSchema-DicbOHvH.mjs → formatAdvisories-DdjK7sgh.mjs} +15 -2
  33. package/dist/packem_shared/{parse-validator-tuQtHrsr.mjs → parse-validator-Cabb60UV.mjs} +2 -1
  34. package/package.json +8 -7
@@ -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-DeblMkzO.mjs';
4
+ import { listLunoraSourceFiles } from './discoverFunctions-BWMczzBx.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-Cabb60UV.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"]);
@@ -344,7 +344,12 @@ const discoverFromCall = (call) => {
344
344
  if (classified.lifecycle) {
345
345
  return { args: {}, kind: classified.kind, lifecycle: classified.lifecycle, returnType: "void", visibility: classified.visibility };
346
346
  }
347
- return { args: argsFromCall(call), kind: classified.kind, returnType: returnTypeFromCall(call), visibility: classified.visibility };
347
+ return {
348
+ args: argsFromCall(call),
349
+ kind: classified.kind,
350
+ returnType: returnTypeFromCall(call),
351
+ visibility: classified.visibility
352
+ };
348
353
  };
349
354
  const RE_EXPORT_RESOLVE_LIMIT = 8;
350
355
  const resolveExpressionToCall = (node, depth = 0) => {
@@ -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-BWMczzBx.mjs';
4
+ import { p as parseValidator, a as parseObjectShape } from './parse-validator-Cabb60UV.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-BWMczzBx.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-BWMczzBx.mjs';
3
3
 
4
4
  const isMaskCall = (node) => {
5
5
  if (!Node.isCallExpression(node)) {
@@ -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-DeblMkzO.mjs';
4
+ import { listLunoraSourceFiles } from './discoverFunctions-BWMczzBx.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-BWMczzBx.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-BWMczzBx.mjs';
3
3
 
4
4
  const INDEX_METHODS = /* @__PURE__ */ new Set(["withIndex", "withSearchIndex"]);
5
5
  const isDatabaseQueryCall = (call) => {
@@ -0,0 +1,80 @@
1
+ import { Node, SyntaxKind } from 'ts-morph';
2
+ import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-BWMczzBx.mjs';
3
+
4
+ const handlerOf = (call, receiver) => {
5
+ if (receiver) {
6
+ const handler = call.getArguments()[0];
7
+ return handler && (Node.isArrowFunction(handler) || Node.isFunctionExpression(handler)) ? handler : void 0;
8
+ }
9
+ const first = call.getArguments()[0];
10
+ if (!first || !Node.isObjectLiteralExpression(first)) {
11
+ return void 0;
12
+ }
13
+ const handlerProperty = first.getProperty("handler");
14
+ if (!handlerProperty || !Node.isPropertyAssignment(handlerProperty)) {
15
+ return void 0;
16
+ }
17
+ const initializer = handlerProperty.getInitializer();
18
+ return initializer && (Node.isArrowFunction(initializer) || Node.isFunctionExpression(initializer)) ? initializer : void 0;
19
+ };
20
+ const exportedProcedureHandler = (declaration) => {
21
+ const initializer = declaration.getInitializer();
22
+ if (!initializer || !Node.isCallExpression(initializer)) {
23
+ return void 0;
24
+ }
25
+ const classified = classifyProcedureCall(initializer);
26
+ if (!classified || classified.kind !== "query" && classified.kind !== "mutation") {
27
+ return void 0;
28
+ }
29
+ const handler = handlerOf(initializer, classified.receiver);
30
+ return handler ? { exportName: declaration.getName(), handler, kind: classified.kind } : void 0;
31
+ };
32
+ const r2sqlCalleeOf = (access) => {
33
+ if (!Node.isPropertyAccessExpression(access) || access.getName() !== "r2sql") {
34
+ return void 0;
35
+ }
36
+ const receiver = access.getExpression();
37
+ if (!Node.isIdentifier(receiver) || receiver.getText() !== "ctx") {
38
+ return void 0;
39
+ }
40
+ const parent = access.getParent();
41
+ if (parent && Node.isPropertyAccessExpression(parent) && parent.getExpression() === access) {
42
+ return `ctx.r2sql.${parent.getName()}`;
43
+ }
44
+ return "ctx.r2sql";
45
+ };
46
+ const accessesInHandler = (procedure, file) => {
47
+ const found = [];
48
+ for (const access of procedure.handler.getDescendantsOfKind(SyntaxKind.PropertyAccessExpression)) {
49
+ const callee = r2sqlCalleeOf(access);
50
+ if (callee !== void 0) {
51
+ found.push({ callee, exportName: procedure.exportName, file, kind: procedure.kind, line: access.getStartLineNumber() });
52
+ }
53
+ }
54
+ return found;
55
+ };
56
+ const accessesInSourceFile = (sourceFile, relativePath) => {
57
+ const found = [];
58
+ for (const statement of sourceFile.getVariableStatements()) {
59
+ if (!statement.isExported()) {
60
+ continue;
61
+ }
62
+ for (const declaration of statement.getDeclarations()) {
63
+ const procedure = exportedProcedureHandler(declaration);
64
+ if (procedure) {
65
+ found.push(...accessesInHandler(procedure, relativePath));
66
+ }
67
+ }
68
+ }
69
+ return found;
70
+ };
71
+ const discoverR2sqlCalls = (project, lunoraDirectory) => {
72
+ const calls = [];
73
+ for (const filePath of listLunoraSourceFiles(lunoraDirectory)) {
74
+ const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
75
+ calls.push(...accessesInSourceFile(sourceFile, lunoraRelativePath(lunoraDirectory, filePath)));
76
+ }
77
+ return calls;
78
+ };
79
+
80
+ export { discoverR2sqlCalls as default };
@@ -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-BWMczzBx.mjs';
3
3
 
4
4
  const isRlsCall = (node) => {
5
5
  if (!Node.isCallExpression(node)) {