@lunora/codegen 1.0.0-alpha.43 → 1.0.0-alpha.431

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 (131) hide show
  1. package/LICENSE.md +201 -104
  2. package/README.md +4 -4
  3. package/dist/index.d.mts +4575 -2150
  4. package/dist/index.d.ts +4575 -2150
  5. package/dist/index.mjs +1 -36
  6. package/dist/packem_shared/AGENTS_FILENAME-BSW65Q9R.mjs +1 -0
  7. package/dist/packem_shared/ALL_NOTIFY_CHANNELS-DI0zmZGs.mjs +1 -0
  8. package/dist/packem_shared/CAPABILITY_PROBES-DCzOjTN7.mjs +25 -0
  9. package/dist/packem_shared/COMPANION_BINDING-Da_v9XpC.mjs +1 -0
  10. package/dist/packem_shared/CONTAINERS_FILENAME-Dy3qWGfI.mjs +1 -0
  11. package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
  12. package/dist/packem_shared/DEFAULT_TARGET-CnglMKg_.mjs +1 -0
  13. package/dist/packem_shared/ENV_FILENAME-DFx_jlpa.mjs +1 -0
  14. package/dist/packem_shared/FLAGS_FILENAME-CDaIBL6L.mjs +1 -0
  15. package/dist/packem_shared/GENERATED_HEADER-DgrhC3Iv.mjs +1 -0
  16. package/dist/packem_shared/LUNORA_ERROR_CODES-D7AVT7qF.mjs +1 -0
  17. package/dist/packem_shared/MUTATORS_FILENAME-SLAN2VXq.mjs +1 -0
  18. package/dist/packem_shared/OPENRPC_VERSION-DkWde9eh.mjs +3 -0
  19. package/dist/packem_shared/PROJECT_CONFIG_FILENAMES-CLfsyvjA.mjs +1 -0
  20. package/dist/packem_shared/QUEUES_FILENAME-CVkpGqoY.mjs +1 -0
  21. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CGC3sVJb.mjs +57 -0
  22. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DTLoSaNn.mjs +2 -0
  23. package/dist/packem_shared/SHAPES_FILENAME-Cf4sum4C.mjs +1 -0
  24. package/dist/packem_shared/SchemaSnapshotParseError-CV7mmuPi.mjs +17 -0
  25. package/dist/packem_shared/WORKFLOWS_FILENAME-Dtxo_XBw.mjs +1 -0
  26. package/dist/packem_shared/attribution-B8xa6AeK.mjs +1 -0
  27. package/dist/packem_shared/buildOpenApiDocument-C3zlve6K.mjs +3 -0
  28. package/dist/packem_shared/capabilitiesUsedBy-BcDkRoOu.mjs +1 -0
  29. package/dist/packem_shared/classify-procedure-call-BK_MMoue.mjs +1 -0
  30. package/dist/packem_shared/companionServiceBinding-BZjm486n.mjs +1 -0
  31. package/dist/packem_shared/context-property-calls-As5I0QR6.mjs +1 -0
  32. package/dist/packem_shared/context-root-CO8PbZi5.mjs +1 -0
  33. package/dist/packem_shared/createCodegenProject-C4XuJSap.mjs +1 -0
  34. package/dist/packem_shared/database-calls-Cug60vT9.mjs +1 -0
  35. package/dist/packem_shared/declared-output-Iaar469J.mjs +1 -0
  36. package/dist/packem_shared/describeErrorLevelFindings-DlkgCw8a.mjs +1 -0
  37. package/dist/packem_shared/discoverAuthApiCalls-DcvsgL5u.mjs +1 -0
  38. package/dist/packem_shared/discoverCrons-MpIC14pg.mjs +1 -0
  39. package/dist/packem_shared/discoverFunctions-CGwHnz_a.mjs +1 -0
  40. package/dist/packem_shared/discoverHttpRoutes-BtMgsfzG.mjs +1 -0
  41. package/dist/packem_shared/discoverHyperdriveCalls-B--Nvx36.mjs +1 -0
  42. package/dist/packem_shared/discoverInserts-Dx7Lxey3.mjs +1 -0
  43. package/dist/packem_shared/discoverMaskProcedures-Dj_hkZz2.mjs +1 -0
  44. package/dist/packem_shared/discoverMigrations-DaBdK1Bv.mjs +1 -0
  45. package/dist/packem_shared/discoverNondeterministicCalls-MeKjo_UX.mjs +1 -0
  46. package/dist/packem_shared/discoverQueries-BlhMsXuk.mjs +1 -0
  47. package/dist/packem_shared/discoverR2sqlCalls-DHvclvkv.mjs +1 -0
  48. package/dist/packem_shared/discoverRlsMetadata-CO-pRHOx.mjs +1 -0
  49. package/dist/packem_shared/discoverRlsProcedures-CUfhUqfY.mjs +1 -0
  50. package/dist/packem_shared/discoverSandboxUsage-CdrJNRFd.mjs +1 -0
  51. package/dist/packem_shared/discoverSchema-CL9PLdOu.mjs +1 -0
  52. package/dist/packem_shared/discoverStorageRulesMetadata-D_pYyr1i.mjs +1 -0
  53. package/dist/packem_shared/dispatch-namespace-DwTjD7BU.mjs +1 -0
  54. package/dist/packem_shared/emitAgents-vWoT8-Yb.mjs +1 -0
  55. package/dist/packem_shared/emitApi-lwadq5G7.mjs +147 -0
  56. package/dist/packem_shared/emitApp-xbr1VKI7.mjs +1209 -0
  57. package/dist/packem_shared/emitCrons-CCRKs482.mjs +138 -0
  58. package/dist/packem_shared/emitDataModel-Cen7mAmM.mjs +114 -0
  59. package/dist/packem_shared/emitDrizzleSchema-lRoq3OJs.mjs +15 -0
  60. package/dist/packem_shared/emitFunctions-ppMX7E3X.mjs +528 -0
  61. package/dist/packem_shared/emitServer-CGRV_uIq.mjs +1 -0
  62. package/dist/packem_shared/emitShard-DhgRjlEf.mjs +1 -0
  63. package/dist/packem_shared/exported-procedure-chains-ej9ozyZB.mjs +1 -0
  64. package/dist/packem_shared/fingerprintSchemaSources-BqPD3mw0.mjs +1 -0
  65. package/dist/packem_shared/formatAdvisories-Bue5tbp6.mjs +2 -0
  66. package/dist/packem_shared/handler-reference-_zhtPddp.mjs +1 -0
  67. package/dist/packem_shared/index-BwLaIVqA.mjs +1 -0
  68. package/dist/packem_shared/index-CQuAXbal.mjs +1 -0
  69. package/dist/packem_shared/ip-reads-D8rPYtZ6.mjs +1 -0
  70. package/dist/packem_shared/isD1GlobalTable-udvHAAzD.mjs +1 -0
  71. package/dist/packem_shared/isTestPath-DJeZ18i9.mjs +1 -0
  72. package/dist/packem_shared/isTypedSchema-CDv3pJB6.mjs +4 -0
  73. package/dist/packem_shared/json-data-Chfs2Cz5.mjs +1 -0
  74. package/dist/packem_shared/loadProjectConfig-BXwH3_gn.mjs +1 -0
  75. package/dist/packem_shared/module-specifiers-BctA0m_p.mjs +1 -0
  76. package/dist/packem_shared/modules-isOWiSYI.mjs +1 -0
  77. package/dist/packem_shared/parse-validator-BisfC8bR.mjs +1 -0
  78. package/dist/packem_shared/platform-8oj7iXQy.mjs +1 -0
  79. package/dist/packem_shared/policies-CrNWTJQi.mjs +1 -0
  80. package/dist/packem_shared/project-config-file-DR7xrrNB.mjs +1 -0
  81. package/dist/packem_shared/property-name-7cBlgK_O.mjs +1 -0
  82. package/dist/packem_shared/qualifiers-qqH8fRTo.mjs +1 -0
  83. package/dist/packem_shared/readPackageDependencies-RHhGiz0k.mjs +1 -0
  84. package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
  85. package/dist/packem_shared/reserved-words-CW1QFbTd.mjs +1 -0
  86. package/dist/packem_shared/schema-BgM8A3XV.mjs +1 -0
  87. package/dist/packem_shared/schemaFromIr-CByOxuZb.mjs +1 -0
  88. package/dist/packem_shared/server-Dfxmm5Zw.mjs +377 -0
  89. package/dist/packem_shared/shard-WWiw5i1B.mjs +1922 -0
  90. package/dist/packem_shared/shard-runtime-G5mZQjY0.mjs +351 -0
  91. package/dist/packem_shared/shared-Cn7dMQ_u.mjs +13 -0
  92. package/dist/packem_shared/unwrap-handler-return-BnsKyz9W.mjs +1 -0
  93. package/dist/sdk/index.d.mts +288 -0
  94. package/dist/sdk/index.d.ts +288 -0
  95. package/dist/sdk/index.mjs +394 -0
  96. package/package.json +32 -10
  97. package/dist/packem_shared/AGENTS_FILENAME-BksnAJgx.mjs +0 -116
  98. package/dist/packem_shared/CONTAINERS_FILENAME-DjpXMqhp.mjs +0 -224
  99. package/dist/packem_shared/CodegenDiagnosticError-DyQ5FwkM.mjs +0 -24
  100. package/dist/packem_shared/FLAGS_FILENAME-fEZtzWXi.mjs +0 -139
  101. package/dist/packem_shared/GENERATED_HEADER-B-FzJ297.mjs +0 -4
  102. package/dist/packem_shared/LUNORA_ERROR_CODES-DvTLozCu.mjs +0 -68
  103. package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +0 -81
  104. package/dist/packem_shared/OPENRPC_VERSION-DqTYxQ22.mjs +0 -60
  105. package/dist/packem_shared/QUEUES_FILENAME-Xv6Vy-Ku.mjs +0 -145
  106. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BbF69nj9.mjs +0 -3497
  107. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs +0 -249
  108. package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +0 -94
  109. package/dist/packem_shared/WORKFLOWS_FILENAME-B2By8S4s.mjs +0 -152
  110. package/dist/packem_shared/buildOpenApiDocument-BrN41JMl.mjs +0 -183
  111. package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
  112. package/dist/packem_shared/discoverAuthApiCalls-WMx8L2FG.mjs +0 -62
  113. package/dist/packem_shared/discoverCrons-DJJ3ZE5F.mjs +0 -271
  114. package/dist/packem_shared/discoverFunctions-CZ91aenA.mjs +0 -518
  115. package/dist/packem_shared/discoverHttpRoutes-DNZLDCmm.mjs +0 -131
  116. package/dist/packem_shared/discoverInserts-DFRJhmCv.mjs +0 -61
  117. package/dist/packem_shared/discoverMaskProcedures-B5iFnZ-X.mjs +0 -273
  118. package/dist/packem_shared/discoverMigrations-CdKtMlBc.mjs +0 -97
  119. package/dist/packem_shared/discoverNondeterministicCalls-C_PrQPkA.mjs +0 -122
  120. package/dist/packem_shared/discoverQueries-B8W9UPrt.mjs +0 -62
  121. package/dist/packem_shared/discoverR2sqlCalls-Bm7Rfnf4.mjs +0 -80
  122. package/dist/packem_shared/discoverRlsMetadata-B4GL4ZKm.mjs +0 -280
  123. package/dist/packem_shared/discoverSchema-DFWVgU5o.mjs +0 -874
  124. package/dist/packem_shared/discoverStorageRulesMetadata-nosjYcvN.mjs +0 -97
  125. package/dist/packem_shared/emit-DtherCpQ.mjs +0 -3727
  126. package/dist/packem_shared/emitApp-D7daY94X.mjs +0 -691
  127. package/dist/packem_shared/formatAdvisories-DRhEiJUz.mjs +0 -114
  128. package/dist/packem_shared/parse-validator-BSJo1HGP.mjs +0 -144
  129. package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
  130. package/dist/packem_shared/redact-oTmsol5A.mjs +0 -33
  131. 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-CZ91aenA.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,271 +0,0 @@
1
- import { LunoraError } from '@lunora/errors';
2
- import { isValidCronExpression, compileCronSchedule, CRON_SCHEDULE_KINDS } from '@lunora/scheduler';
3
- import { SyntaxKind, Node } from 'ts-morph';
4
- import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
5
- import { listLunoraSourceFiles } from './discoverFunctions-CZ91aenA.mjs';
6
- import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
7
-
8
- const CRON_METHODS = /* @__PURE__ */ new Set([...CRON_SCHEDULE_KINDS, "cron"]);
9
- const CRON_JOBS_SOURCES = /* @__PURE__ */ new Set(["@lunora/scheduler", "@lunora/server"]);
10
- const isCronJobsFactory = (identifier) => {
11
- const symbol = identifier.getSymbol();
12
- if (!symbol) {
13
- return identifier.getText() === "cronJobs";
14
- }
15
- for (const declaration of symbol.getDeclarations()) {
16
- if (!Node.isImportSpecifier(declaration)) {
17
- continue;
18
- }
19
- if (!CRON_JOBS_SOURCES.has(declaration.getImportDeclaration().getModuleSpecifierValue())) {
20
- return false;
21
- }
22
- return declaration.getNameNode().getText() === "cronJobs";
23
- }
24
- return false;
25
- };
26
- const collectCronBuilderNames = (source) => {
27
- const names = /* @__PURE__ */ new Set();
28
- for (const declaration of source.getVariableDeclarations()) {
29
- const initializer = declaration.getInitializer();
30
- if (initializer?.getKind() !== SyntaxKind.CallExpression) {
31
- continue;
32
- }
33
- const callee = initializer.getExpression();
34
- if (Node.isIdentifier(callee) && isCronJobsFactory(callee)) {
35
- names.add(declaration.getName());
36
- }
37
- }
38
- return names;
39
- };
40
- const rootIdentifierOf = (node) => {
41
- let current = node;
42
- while (Node.isCallExpression(current) || Node.isPropertyAccessExpression(current)) {
43
- current = current.getExpression();
44
- }
45
- return Node.isIdentifier(current) ? current.getText() : void 0;
46
- };
47
- const stringArgument = (call, index) => {
48
- const argument = call.getArguments()[index];
49
- return argument && Node.isStringLiteral(argument) ? argument.getLiteralValue() : void 0;
50
- };
51
- const literalValue = (node, jobName) => {
52
- if (Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)) {
53
- return node.getLiteralValue();
54
- }
55
- if (Node.isNumericLiteral(node)) {
56
- return node.getLiteralValue();
57
- }
58
- if (Node.isTrueLiteral(node)) {
59
- return true;
60
- }
61
- if (Node.isFalseLiteral(node)) {
62
- return false;
63
- }
64
- if (Node.isPrefixUnaryExpression(node) && node.getOperatorToken() === SyntaxKind.MinusToken) {
65
- const operand = node.getOperand();
66
- if (Node.isNumericLiteral(operand)) {
67
- return -operand.getLiteralValue();
68
- }
69
- }
70
- if (Node.isObjectLiteralExpression(node)) {
71
- return objectLiteralValue(node, jobName);
72
- }
73
- if (Node.isArrayLiteralExpression(node)) {
74
- return node.getElements().map((element) => literalValue(element, jobName));
75
- }
76
- throw diagnosticAt(node, `Cron job "${jobName}" passes a non-static value where a literal is required; codegen can only read literals.`, {
77
- code: "CRON_NON_STATIC_VALUE",
78
- name: "LunoraError",
79
- status: 500
80
- });
81
- };
82
- const objectLiteralValue = (object, jobName) => {
83
- const result = {};
84
- for (const property of object.getProperties()) {
85
- if (!Node.isPropertyAssignment(property)) {
86
- throw diagnosticAt(
87
- property,
88
- `Cron job "${jobName}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,
89
- {
90
- code: "CRON_NON_STATIC_VALUE",
91
- name: "LunoraError",
92
- status: 500
93
- }
94
- );
95
- }
96
- const initializer = property.getInitializer();
97
- if (initializer) {
98
- result[property.getName()] = literalValue(initializer, jobName);
99
- }
100
- }
101
- return result;
102
- };
103
- const functionPathFromArgument = (call, index, jobName) => {
104
- const argument = call.getArguments()[index];
105
- if (!argument || !Node.isPropertyAccessExpression(argument)) {
106
- throw diagnosticAt(
107
- call,
108
- `Cron job "${jobName}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,
109
- {
110
- code: "CRON_NON_STATIC_FN",
111
- name: "LunoraError",
112
- status: 500
113
- }
114
- );
115
- }
116
- const functionName = argument.getName();
117
- const receiver = argument.getExpression();
118
- if (!Node.isPropertyAccessExpression(receiver)) {
119
- throw diagnosticAt(argument, `Cron job "${jobName}" function reference must be of the form internal.file.fn (two property accesses).`, {
120
- code: "CRON_NON_STATIC_FN",
121
- name: "LunoraError",
122
- status: 500
123
- });
124
- }
125
- const namespace = receiver.getName();
126
- return `${sanitizeNamespace(namespace)}:${functionName}`;
127
- };
128
- const workflowTarget = (workflow) => {
129
- return { workflow: { binding: workflow.bindingName, exportName: workflow.exportName } };
130
- };
131
- const agentTarget = (agent) => {
132
- return { workflow: { binding: agent.bindingName, exportName: agent.exportName } };
133
- };
134
- const resolveReferenceAccess = (argument, receiverName, byName, jobName, kind, build) => {
135
- const receiver = argument.getExpression();
136
- if (!Node.isIdentifier(receiver) || receiver.getText() !== receiverName) {
137
- return void 0;
138
- }
139
- const definition = byName.get(argument.getName());
140
- if (definition) {
141
- return build(definition);
142
- }
143
- throw diagnosticAt(
144
- argument,
145
- `Cron job "${jobName}" targets ${receiverName}.${argument.getName()}, but no such ${kind} is declared in lunora/${kind}s.ts.`,
146
- {
147
- code: "CRON_NON_STATIC_FN",
148
- name: "LunoraError",
149
- status: 500
150
- }
151
- );
152
- };
153
- const resolveTarget = (call, index, jobName, workflowsByName, agentsByName) => {
154
- const argument = call.getArguments()[index];
155
- if (argument && Node.isPropertyAccessExpression(argument)) {
156
- const workflowReference = resolveReferenceAccess(argument, "workflows", workflowsByName, jobName, "workflow", workflowTarget);
157
- if (workflowReference) {
158
- return workflowReference;
159
- }
160
- const agentReference = resolveReferenceAccess(argument, "agents", agentsByName, jobName, "agent", agentTarget);
161
- if (agentReference) {
162
- return agentReference;
163
- }
164
- return { functionPath: functionPathFromArgument(call, index, jobName) };
165
- }
166
- if (argument && Node.isIdentifier(argument)) {
167
- const workflow = workflowsByName.get(argument.getText());
168
- if (workflow) {
169
- return workflowTarget(workflow);
170
- }
171
- throw diagnosticAt(
172
- argument,
173
- `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.`,
174
- {
175
- code: "CRON_NON_STATIC_FN",
176
- name: "LunoraError",
177
- status: 500
178
- }
179
- );
180
- }
181
- return { functionPath: functionPathFromArgument(call, index, jobName) };
182
- };
183
- const cronFromCall = (call, callee, builderNames, workflowsByName, agentsByName) => {
184
- const method = callee.getName();
185
- if (!CRON_METHODS.has(method)) {
186
- return void 0;
187
- }
188
- if (!builderNames.has(rootIdentifierOf(callee.getExpression()) ?? "")) {
189
- return void 0;
190
- }
191
- const name = stringArgument(call, 0);
192
- if (name === void 0 || name.trim() === "") {
193
- throw diagnosticAt(call, `A cron ".${method}(...)" registration must pass a non-empty string-literal name as its first argument.`, {
194
- code: "CRON_NAME_NOT_STATIC",
195
- name: "LunoraError",
196
- status: 500
197
- });
198
- }
199
- let cron;
200
- if (method === "cron") {
201
- const expression = stringArgument(call, 1);
202
- if (expression === void 0) {
203
- throw diagnosticAt(call, `Cron job "${name}" must pass a string-literal cron expression to ".cron(...)".`, {
204
- code: "CRON_EXPR_NOT_STATIC",
205
- name: "LunoraError",
206
- status: 500
207
- });
208
- }
209
- if (!isValidCronExpression(expression)) {
210
- throw diagnosticAt(call, `Cron job "${name}" has an invalid cron expression "${expression}" — expected 5 or 6 space-separated fields.`, {
211
- code: "CRON_EXPR_INVALID",
212
- name: "LunoraError",
213
- status: 500
214
- });
215
- }
216
- cron = expression;
217
- } else {
218
- const scheduleArgument = call.getArguments()[1];
219
- if (!scheduleArgument || !Node.isObjectLiteralExpression(scheduleArgument)) {
220
- throw diagnosticAt(call, `Cron job "${name}" must pass an object-literal schedule to ".${method}(...)".`, {
221
- code: "CRON_SCHEDULE_NOT_STATIC",
222
- name: "LunoraError",
223
- status: 500
224
- });
225
- }
226
- cron = compileCronSchedule(method, objectLiteralValue(scheduleArgument, name));
227
- }
228
- const target = resolveTarget(call, 2, name, workflowsByName, agentsByName);
229
- const argumentsNode = call.getArguments()[3];
230
- const args = argumentsNode && Node.isObjectLiteralExpression(argumentsNode) ? objectLiteralValue(argumentsNode, name) : {};
231
- return { args, cron, name, ...target };
232
- };
233
- const assertUniqueNames = (crons) => {
234
- const seen = /* @__PURE__ */ new Set();
235
- for (const cron of crons) {
236
- if (seen.has(cron.name)) {
237
- throw new LunoraError("DUPLICATE_CRON_NAME", `Duplicate cron job name "${cron.name}": cron names must be unique across the project.`, {
238
- status: 500
239
- });
240
- }
241
- seen.add(cron.name);
242
- }
243
- };
244
- const discoverCrons = (project, lunoraDirectory, workflows = [], agents = []) => {
245
- const filePaths = listLunoraSourceFiles(lunoraDirectory);
246
- const crons = [];
247
- const workflowsByName = new Map(workflows.map((workflow) => [workflow.exportName, workflow]));
248
- const agentsByName = new Map(agents.map((agent) => [agent.exportName, agent]));
249
- for (const filePath of filePaths) {
250
- const source = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
251
- const builderNames = collectCronBuilderNames(source);
252
- if (builderNames.size === 0) {
253
- continue;
254
- }
255
- for (const call of source.getDescendantsOfKind(SyntaxKind.CallExpression)) {
256
- const callee = call.getExpression();
257
- if (!Node.isPropertyAccessExpression(callee)) {
258
- continue;
259
- }
260
- const cron = cronFromCall(call, callee, builderNames, workflowsByName, agentsByName);
261
- if (cron) {
262
- crons.push(cron);
263
- }
264
- }
265
- }
266
- crons.sort((a, b) => a.name.localeCompare(b.name));
267
- assertUniqueNames(crons);
268
- return crons;
269
- };
270
-
271
- export { discoverCrons as default };