@lunora/codegen 1.0.0-alpha.23 → 1.0.0-alpha.230

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 (96) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/index.d.mts +3344 -1166
  4. package/dist/index.d.ts +3344 -1166
  5. package/dist/index.mjs +1 -34
  6. package/dist/packem_shared/AGENTS_FILENAME-DoPI92Wu.mjs +1 -0
  7. package/dist/packem_shared/CONTAINERS_FILENAME-B6TFs82W.mjs +1 -0
  8. package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
  9. package/dist/packem_shared/DEFAULT_TARGET-kmm2i4Fw.mjs +1 -0
  10. package/dist/packem_shared/FLAGS_FILENAME-BedPDCsR.mjs +1 -0
  11. package/dist/packem_shared/GENERATED_HEADER-Cfw75xC4.mjs +1 -0
  12. package/dist/packem_shared/LUNORA_ERROR_CODES-C2s0xWQD.mjs +1 -0
  13. package/dist/packem_shared/MUTATORS_FILENAME-B6cKrN_m.mjs +1 -0
  14. package/dist/packem_shared/NOTIFY_FILENAME-Cri3NT5U.mjs +1 -0
  15. package/dist/packem_shared/OPENRPC_VERSION-DDd0VJyT.mjs +3 -0
  16. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-DzOu-lSc.mjs +1 -0
  17. package/dist/packem_shared/QUEUES_FILENAME-CxkPcMH1.mjs +1 -0
  18. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Cssrg7G6.mjs +9 -0
  19. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-C0oHwiJZ.mjs +2 -0
  20. package/dist/packem_shared/SDK_LANGUAGES-Df_CnJx5.mjs +372 -0
  21. package/dist/packem_shared/SHAPES_FILENAME-zJgzynXR.mjs +1 -0
  22. package/dist/packem_shared/SchemaSnapshotParseError-lUWe6lPo.mjs +18 -0
  23. package/dist/packem_shared/WORKFLOWS_FILENAME-B_ZJxRSx.mjs +1 -0
  24. package/dist/packem_shared/buildOpenApiDocument-D6SBl-tk.mjs +3 -0
  25. package/dist/packem_shared/chain-H2N_uKgj.mjs +1 -0
  26. package/dist/packem_shared/classify-procedure-call-BztLe76A.mjs +1 -0
  27. package/dist/packem_shared/context-property-calls-CjDzLU8p.mjs +1 -0
  28. package/dist/packem_shared/declared-output-Iaar469J.mjs +1 -0
  29. package/dist/packem_shared/describeErrorLevelFindings-D23VSkFP.mjs +1 -0
  30. package/dist/packem_shared/discoverAuthApiCalls-FxrdBeVt.mjs +1 -0
  31. package/dist/packem_shared/discoverCrons-MfKw7IFf.mjs +1 -0
  32. package/dist/packem_shared/discoverFunctions-BsmX-sEq.mjs +1 -0
  33. package/dist/packem_shared/discoverHttpRoutes-BcXI9CNt.mjs +1 -0
  34. package/dist/packem_shared/discoverHyperdriveCalls-D9qXqTq3.mjs +1 -0
  35. package/dist/packem_shared/discoverInserts-CFJ3IVeI.mjs +1 -0
  36. package/dist/packem_shared/discoverMaskProcedures-CV_Cc2_g.mjs +1 -0
  37. package/dist/packem_shared/discoverMigrations-DbrHwcGE.mjs +1 -0
  38. package/dist/packem_shared/discoverNondeterministicCalls-CSQ_GDcA.mjs +1 -0
  39. package/dist/packem_shared/discoverQueries-C7y8i_Ga.mjs +1 -0
  40. package/dist/packem_shared/discoverR2sqlCalls-fu7fC0i_.mjs +1 -0
  41. package/dist/packem_shared/discoverRlsMetadata-CPmAGL0W.mjs +1 -0
  42. package/dist/packem_shared/discoverRlsProcedures-BO4qC77y.mjs +1 -0
  43. package/dist/packem_shared/discoverSandboxUsage-CgmfgDTS.mjs +1 -0
  44. package/dist/packem_shared/discoverSchema-D8DBDHEg.mjs +1 -0
  45. package/dist/packem_shared/discoverStorageRulesMetadata-D8VYflWt.mjs +1 -0
  46. package/dist/packem_shared/emit-D_prE7y6.mjs +2691 -0
  47. package/dist/packem_shared/emitApp-rCWsXXGd.mjs +853 -0
  48. package/dist/packem_shared/exported-procedure-chains-CmCDiPBV.mjs +1 -0
  49. package/dist/packem_shared/formatAdvisories-DwmUKYuc.mjs +2 -0
  50. package/dist/packem_shared/index-BoaHhVtM.mjs +1 -0
  51. package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
  52. package/dist/packem_shared/isTypedSchema-CKzc3ioR.mjs +4 -0
  53. package/dist/packem_shared/listLunoraSourceFiles-DP-5e-RE.mjs +1 -0
  54. package/dist/packem_shared/loadProjectConfig-CKsFNgn3.mjs +1 -0
  55. package/dist/packem_shared/module-specifiers-WF8iAydP.mjs +1 -0
  56. package/dist/packem_shared/parse-validator-C94Yiabo.mjs +1 -0
  57. package/dist/packem_shared/paths-C-9fwEgQ.mjs +1 -0
  58. package/dist/packem_shared/queries-B-f4jO-x.mjs +1 -0
  59. package/dist/packem_shared/readPackageDependencies-C6h6FZuP.mjs +1 -0
  60. package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
  61. package/dist/packem_shared/schemaFromIr-BWFnvCVg.mjs +1 -0
  62. package/dist/packem_shared/unwrap-handler-return-CoV_GK33.mjs +1 -0
  63. package/package.json +16 -7
  64. package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
  65. package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
  66. package/dist/packem_shared/FLAGS_FILENAME-B1vE0LIo.mjs +0 -139
  67. package/dist/packem_shared/GENERATED_HEADER-DUkXYD5R.mjs +0 -3260
  68. package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
  69. package/dist/packem_shared/LUNORA_SOLUTION_RULES-BTejmZp-.mjs +0 -131
  70. package/dist/packem_shared/MUTATORS_FILENAME-BhqdPtKp.mjs +0 -81
  71. package/dist/packem_shared/OPENRPC_VERSION-CjBUaolx.mjs +0 -60
  72. package/dist/packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs +0 -119
  73. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BUcGCXi3.mjs +0 -1130
  74. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs +0 -245
  75. package/dist/packem_shared/SHAPES_FILENAME-ChV7MqgE.mjs +0 -94
  76. package/dist/packem_shared/WORKFLOWS_FILENAME-CCisG0Vy.mjs +0 -124
  77. package/dist/packem_shared/buildOpenApiDocument-WxYTLh11.mjs +0 -183
  78. package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
  79. package/dist/packem_shared/discoverAuthApiCalls-CoirYbg6.mjs +0 -62
  80. package/dist/packem_shared/discoverCrons-Cev7RRAf.mjs +0 -257
  81. package/dist/packem_shared/discoverFunctions-BWMczzBx.mjs +0 -465
  82. package/dist/packem_shared/discoverHttpRoutes-CfP6cMzt.mjs +0 -131
  83. package/dist/packem_shared/discoverInserts-C7zxXkUf.mjs +0 -61
  84. package/dist/packem_shared/discoverMaskProcedures-Cm81kwrb.mjs +0 -217
  85. package/dist/packem_shared/discoverMigrations-Bi5nJ0mJ.mjs +0 -97
  86. package/dist/packem_shared/discoverNondeterministicCalls-C4M8AXmQ.mjs +0 -122
  87. package/dist/packem_shared/discoverQueries-B0wGT-xe.mjs +0 -62
  88. package/dist/packem_shared/discoverR2sqlCalls-BVNMd428.mjs +0 -80
  89. package/dist/packem_shared/discoverRlsMetadata-BS9GOGC5.mjs +0 -280
  90. package/dist/packem_shared/discoverSchema-KYq55qu3.mjs +0 -864
  91. package/dist/packem_shared/discoverStorageRulesMetadata-Da8BKXcI.mjs +0 -97
  92. package/dist/packem_shared/emitApp-DD0i1ks0.mjs +0 -666
  93. package/dist/packem_shared/formatAdvisories-DdjK7sgh.mjs +0 -81
  94. package/dist/packem_shared/parse-validator-Cabb60UV.mjs +0 -133
  95. package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
  96. package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
@@ -1,62 +0,0 @@
1
- import { relative, sep } from 'node:path';
2
- import { SyntaxKind, Node } from 'ts-morph';
3
- import { T as TS_EXTENSION_RE, e as enclosingExportName } from './discover-ast-CT6BgBr4.mjs';
4
- import { listLunoraSourceFiles } from './discoverFunctions-BWMczzBx.mjs';
5
-
6
- const isAuthApiCall = (call) => {
7
- const callee = call.getExpression();
8
- if (!Node.isPropertyAccessExpression(callee)) {
9
- return false;
10
- }
11
- const receiver = callee.getExpression();
12
- if (Node.isPropertyAccessExpression(receiver)) {
13
- return receiver.getName() === "authApi";
14
- }
15
- return Node.isIdentifier(receiver) && receiver.getText() === "authApi";
16
- };
17
- const hasHeadersProp = (call) => {
18
- const argument = call.getArguments()[0];
19
- if (argument === void 0) {
20
- return false;
21
- }
22
- if (!Node.isObjectLiteralExpression(argument)) {
23
- return true;
24
- }
25
- for (const property of argument.getProperties()) {
26
- if ((Node.isPropertyAssignment(property) || Node.isShorthandPropertyAssignment(property)) && property.getName() === "headers") {
27
- return true;
28
- }
29
- if (Node.isSpreadAssignment(property)) {
30
- return true;
31
- }
32
- }
33
- return false;
34
- };
35
- const discoverAuthApiCalls = (project, lunoraDirectory) => {
36
- const calls = [];
37
- for (const filePath of listLunoraSourceFiles(lunoraDirectory)) {
38
- const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
39
- const relativePath = relative(lunoraDirectory, filePath).replace(TS_EXTENSION_RE, "").split(sep).join("/");
40
- for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
41
- if (!isAuthApiCall(call)) {
42
- continue;
43
- }
44
- const exportName = enclosingExportName(call);
45
- if (exportName === "") {
46
- continue;
47
- }
48
- const callee = call.getExpression();
49
- const method = Node.isPropertyAccessExpression(callee) ? callee.getName() : "";
50
- calls.push({
51
- exportName,
52
- file: relativePath,
53
- hasHeaders: hasHeadersProp(call),
54
- line: call.getStartLineNumber(),
55
- method
56
- });
57
- }
58
- }
59
- return calls;
60
- };
61
-
62
- export { discoverAuthApiCalls as default };
@@ -1,257 +0,0 @@
1
- import { isValidCronExpression, compileCronSchedule, CRON_SCHEDULE_KINDS } from '@lunora/scheduler';
2
- import { SyntaxKind, Node } from 'ts-morph';
3
- import { diagnosticAt } from './CodegenDiagnosticError-DeblMkzO.mjs';
4
- import { listLunoraSourceFiles } from './discoverFunctions-BWMczzBx.mjs';
5
- import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
6
-
7
- const CRON_METHODS = /* @__PURE__ */ new Set([...CRON_SCHEDULE_KINDS, "cron"]);
8
- const CRON_JOBS_SOURCES = /* @__PURE__ */ new Set(["@lunora/scheduler", "@lunora/server"]);
9
- const isCronJobsFactory = (identifier) => {
10
- const symbol = identifier.getSymbol();
11
- if (!symbol) {
12
- return identifier.getText() === "cronJobs";
13
- }
14
- for (const declaration of symbol.getDeclarations()) {
15
- if (!Node.isImportSpecifier(declaration)) {
16
- continue;
17
- }
18
- if (!CRON_JOBS_SOURCES.has(declaration.getImportDeclaration().getModuleSpecifierValue())) {
19
- return false;
20
- }
21
- return declaration.getNameNode().getText() === "cronJobs";
22
- }
23
- return false;
24
- };
25
- const collectCronBuilderNames = (source) => {
26
- const names = /* @__PURE__ */ new Set();
27
- for (const declaration of source.getVariableDeclarations()) {
28
- const initializer = declaration.getInitializer();
29
- if (initializer?.getKind() !== SyntaxKind.CallExpression) {
30
- continue;
31
- }
32
- const callee = initializer.getExpression();
33
- if (Node.isIdentifier(callee) && isCronJobsFactory(callee)) {
34
- names.add(declaration.getName());
35
- }
36
- }
37
- return names;
38
- };
39
- const rootIdentifierOf = (node) => {
40
- let current = node;
41
- while (Node.isCallExpression(current) || Node.isPropertyAccessExpression(current)) {
42
- current = current.getExpression();
43
- }
44
- return Node.isIdentifier(current) ? current.getText() : void 0;
45
- };
46
- const stringArgument = (call, index) => {
47
- const argument = call.getArguments()[index];
48
- return argument && Node.isStringLiteral(argument) ? argument.getLiteralValue() : void 0;
49
- };
50
- const literalValue = (node, jobName) => {
51
- if (Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)) {
52
- return node.getLiteralValue();
53
- }
54
- if (Node.isNumericLiteral(node)) {
55
- return node.getLiteralValue();
56
- }
57
- if (Node.isTrueLiteral(node)) {
58
- return true;
59
- }
60
- if (Node.isFalseLiteral(node)) {
61
- return false;
62
- }
63
- if (Node.isPrefixUnaryExpression(node) && node.getOperatorToken() === SyntaxKind.MinusToken) {
64
- const operand = node.getOperand();
65
- if (Node.isNumericLiteral(operand)) {
66
- return -operand.getLiteralValue();
67
- }
68
- }
69
- if (Node.isObjectLiteralExpression(node)) {
70
- return objectLiteralValue(node, jobName);
71
- }
72
- if (Node.isArrayLiteralExpression(node)) {
73
- return node.getElements().map((element) => literalValue(element, jobName));
74
- }
75
- throw diagnosticAt(node, `Cron job "${jobName}" passes a non-static value where a literal is required; codegen can only read literals.`, {
76
- code: "CRON_NON_STATIC_VALUE",
77
- name: "LunoraError",
78
- status: 500
79
- });
80
- };
81
- const objectLiteralValue = (object, jobName) => {
82
- const result = {};
83
- for (const property of object.getProperties()) {
84
- if (!Node.isPropertyAssignment(property)) {
85
- throw diagnosticAt(
86
- property,
87
- `Cron job "${jobName}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,
88
- {
89
- code: "CRON_NON_STATIC_VALUE",
90
- name: "LunoraError",
91
- status: 500
92
- }
93
- );
94
- }
95
- const initializer = property.getInitializer();
96
- if (initializer) {
97
- result[property.getName()] = literalValue(initializer, jobName);
98
- }
99
- }
100
- return result;
101
- };
102
- const functionPathFromArgument = (call, index, jobName) => {
103
- const argument = call.getArguments()[index];
104
- if (!argument || !Node.isPropertyAccessExpression(argument)) {
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.`,
108
- {
109
- code: "CRON_NON_STATIC_FN",
110
- name: "LunoraError",
111
- status: 500
112
- }
113
- );
114
- }
115
- const functionName = argument.getName();
116
- const receiver = argument.getExpression();
117
- if (!Node.isPropertyAccessExpression(receiver)) {
118
- throw diagnosticAt(argument, `Cron job "${jobName}" function reference must be of the form internal.file.fn (two property accesses).`, {
119
- code: "CRON_NON_STATIC_FN",
120
- name: "LunoraError",
121
- status: 500
122
- });
123
- }
124
- const namespace = receiver.getName();
125
- return `${sanitizeNamespace(namespace)}:${functionName}`;
126
- };
127
- const workflowTarget = (workflow) => {
128
- return { workflow: { binding: workflow.bindingName, exportName: workflow.exportName } };
129
- };
130
- const resolveTarget = (call, index, jobName, workflowsByName) => {
131
- const argument = call.getArguments()[index];
132
- if (argument && Node.isPropertyAccessExpression(argument)) {
133
- const receiver = argument.getExpression();
134
- if (Node.isIdentifier(receiver) && receiver.getText() === "workflows") {
135
- const workflow = workflowsByName.get(argument.getName());
136
- if (workflow) {
137
- return workflowTarget(workflow);
138
- }
139
- throw diagnosticAt(
140
- argument,
141
- `Cron job "${jobName}" targets workflows.${argument.getName()}, but no such workflow is declared in lunora/workflows.ts.`,
142
- {
143
- code: "CRON_NON_STATIC_FN",
144
- name: "LunoraError",
145
- status: 500
146
- }
147
- );
148
- }
149
- return { functionPath: functionPathFromArgument(call, index, jobName) };
150
- }
151
- if (argument && Node.isIdentifier(argument)) {
152
- const workflow = workflowsByName.get(argument.getText());
153
- if (workflow) {
154
- return workflowTarget(workflow);
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.`,
159
- {
160
- code: "CRON_NON_STATIC_FN",
161
- name: "LunoraError",
162
- status: 500
163
- }
164
- );
165
- }
166
- return { functionPath: functionPathFromArgument(call, index, jobName) };
167
- };
168
- const cronFromCall = (call, callee, builderNames, workflowsByName) => {
169
- const method = callee.getName();
170
- if (!CRON_METHODS.has(method)) {
171
- return void 0;
172
- }
173
- if (!builderNames.has(rootIdentifierOf(callee.getExpression()) ?? "")) {
174
- return void 0;
175
- }
176
- const name = stringArgument(call, 0);
177
- if (name === void 0 || name.trim() === "") {
178
- throw diagnosticAt(call, `A cron ".${method}(...)" registration must pass a non-empty string-literal name as its first argument.`, {
179
- code: "CRON_NAME_NOT_STATIC",
180
- name: "LunoraError",
181
- status: 500
182
- });
183
- }
184
- let cron;
185
- if (method === "cron") {
186
- const expression = stringArgument(call, 1);
187
- if (expression === void 0) {
188
- throw diagnosticAt(call, `Cron job "${name}" must pass a string-literal cron expression to ".cron(...)".`, {
189
- code: "CRON_EXPR_NOT_STATIC",
190
- name: "LunoraError",
191
- status: 500
192
- });
193
- }
194
- if (!isValidCronExpression(expression)) {
195
- throw diagnosticAt(call, `Cron job "${name}" has an invalid cron expression "${expression}" — expected 5 or 6 space-separated fields.`, {
196
- code: "CRON_EXPR_INVALID",
197
- name: "LunoraError",
198
- status: 500
199
- });
200
- }
201
- cron = expression;
202
- } else {
203
- const scheduleArgument = call.getArguments()[1];
204
- if (!scheduleArgument || !Node.isObjectLiteralExpression(scheduleArgument)) {
205
- throw diagnosticAt(call, `Cron job "${name}" must pass an object-literal schedule to ".${method}(...)".`, {
206
- code: "CRON_SCHEDULE_NOT_STATIC",
207
- name: "LunoraError",
208
- status: 500
209
- });
210
- }
211
- cron = compileCronSchedule(method, objectLiteralValue(scheduleArgument, name));
212
- }
213
- const target = resolveTarget(call, 2, name, workflowsByName);
214
- const argumentsNode = call.getArguments()[3];
215
- const args = argumentsNode && Node.isObjectLiteralExpression(argumentsNode) ? objectLiteralValue(argumentsNode, name) : {};
216
- return { args, cron, name, ...target };
217
- };
218
- const assertUniqueNames = (crons) => {
219
- const seen = /* @__PURE__ */ new Set();
220
- for (const cron of crons) {
221
- if (seen.has(cron.name)) {
222
- throw Object.assign(new Error(`Duplicate cron job name "${cron.name}": cron names must be unique across the project.`), {
223
- code: "DUPLICATE_CRON_NAME",
224
- name: "LunoraError",
225
- status: 500
226
- });
227
- }
228
- seen.add(cron.name);
229
- }
230
- };
231
- const discoverCrons = (project, lunoraDirectory, workflows = []) => {
232
- const filePaths = listLunoraSourceFiles(lunoraDirectory);
233
- const crons = [];
234
- const workflowsByName = new Map(workflows.map((workflow) => [workflow.exportName, workflow]));
235
- for (const filePath of filePaths) {
236
- const source = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
237
- const builderNames = collectCronBuilderNames(source);
238
- if (builderNames.size === 0) {
239
- continue;
240
- }
241
- for (const call of source.getDescendantsOfKind(SyntaxKind.CallExpression)) {
242
- const callee = call.getExpression();
243
- if (!Node.isPropertyAccessExpression(callee)) {
244
- continue;
245
- }
246
- const cron = cronFromCall(call, callee, builderNames, workflowsByName);
247
- if (cron) {
248
- crons.push(cron);
249
- }
250
- }
251
- }
252
- crons.sort((a, b) => a.name.localeCompare(b.name));
253
- assertUniqueNames(crons);
254
- return crons;
255
- };
256
-
257
- export { discoverCrons as default };