@lunora/codegen 1.0.0-alpha.3 → 1.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +1084 -25
- package/dist/index.d.ts +1084 -25
- package/dist/index.mjs +29 -23
- package/dist/packem_shared/{CONTAINERS_FILENAME-0K-pjNb8.mjs → CONTAINERS_FILENAME-DjpXMqhp.mjs} +1 -1
- package/dist/packem_shared/{CodegenDiagnosticError-54jWDxA9.mjs → CodegenDiagnosticError-DyQ5FwkM.mjs} +7 -5
- package/dist/packem_shared/FLAGS_FILENAME-BjpS5w08.mjs +139 -0
- package/dist/packem_shared/{GENERATED_HEADER-CuLyj0WQ.mjs → GENERATED_HEADER-f6nMvllu.mjs} +853 -65
- package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +81 -0
- package/dist/packem_shared/{OPENRPC_VERSION-BGUrsrt_.mjs → OPENRPC_VERSION-u5SqDDGk.mjs} +1 -1
- package/dist/packem_shared/QUEUES_FILENAME-BF0iUmx7.mjs +119 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Ca-TlVEc.mjs +3481 -0
- package/dist/packem_shared/{SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs → SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs} +18 -2
- package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +94 -0
- package/dist/packem_shared/{WORKFLOWS_FILENAME-DRDQdhfq.mjs → WORKFLOWS_FILENAME-CCC_42o3.mjs} +42 -2
- package/dist/packem_shared/{buildOpenApiDocument-CXwnbp4b.mjs → buildOpenApiDocument-AgKWmlry.mjs} +1 -1
- package/dist/packem_shared/{discoverAuthApiCalls-C35R6z0T.mjs → discoverAuthApiCalls-URDoTADN.mjs} +1 -1
- package/dist/packem_shared/{discoverCrons-BL6iGuJ3.mjs → discoverCrons-DdZOeroL.mjs} +20 -17
- package/dist/packem_shared/{discoverFunctions-DEgAcRuD.mjs → discoverFunctions-BJdF7lRs.mjs} +63 -9
- package/dist/packem_shared/{discoverHttpRoutes-C978pBiG.mjs → discoverHttpRoutes-CcwP-Rkr.mjs} +2 -2
- package/dist/packem_shared/{discoverInserts-CRQdXvHO.mjs → discoverInserts-BpFhM32L.mjs} +24 -2
- package/dist/packem_shared/{discoverMaskProcedures-B64zA740.mjs → discoverMaskProcedures-DT-v8wvj.mjs} +58 -2
- package/dist/packem_shared/{discoverMigrations-Doj_-BAA.mjs → discoverMigrations-cG1idBVM.mjs} +10 -4
- package/dist/packem_shared/{discoverNondeterministicCalls-4KiPQxQU.mjs → discoverNondeterministicCalls-CEOjmfk4.mjs} +1 -1
- package/dist/packem_shared/{discoverQueries-BkIi0dBD.mjs → discoverQueries-DeVBQVAG.mjs} +1 -1
- package/dist/packem_shared/{discoverR2sqlCalls-BpDqvcUn.mjs → discoverR2sqlCalls-CWCAU-xJ.mjs} +1 -1
- package/dist/packem_shared/{discoverRlsMetadata-DpRB1HMe.mjs → discoverRlsMetadata-BL0oukaK.mjs} +1 -1
- package/dist/packem_shared/{discoverSchema-BBulgGbH.mjs → discoverSchema-CeXJWVKV.mjs} +349 -17
- package/dist/packem_shared/{discoverStorageRulesMetadata-DAqJUxUv.mjs → discoverStorageRulesMetadata-CFHByjIl.mjs} +1 -1
- package/dist/packem_shared/{emitApp-CzSxVDaG.mjs → emitApp-BUCrHOeI.mjs} +94 -8
- package/dist/packem_shared/{formatAdvisories-8NIv1k0I.mjs → formatAdvisories-C9wNBNvL.mjs} +47 -3
- package/dist/packem_shared/{parse-validator-tuQtHrsr.mjs → parse-validator-D6zI2i85.mjs} +5 -3
- package/dist/packem_shared/redact-oTmsol5A.mjs +33 -0
- package/package.json +9 -7
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BQ_kCZ81.mjs +0 -903
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { Node, SyntaxKind } from 'ts-morph';
|
|
4
|
+
import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
|
|
5
|
+
|
|
6
|
+
const MUTATORS_FILENAME = "mutators.ts";
|
|
7
|
+
const MUTATOR_MODULE_SPECIFIERS = /* @__PURE__ */ new Set(["@lunora/server", "lunorash/server"]);
|
|
8
|
+
const isDefineMutator = (identifier) => {
|
|
9
|
+
const symbol = identifier.getSymbol();
|
|
10
|
+
if (!symbol) {
|
|
11
|
+
return identifier.getText() === "defineMutator";
|
|
12
|
+
}
|
|
13
|
+
for (const declaration of symbol.getDeclarations()) {
|
|
14
|
+
if (!Node.isImportSpecifier(declaration)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (!MUTATOR_MODULE_SPECIFIERS.has(declaration.getImportDeclaration().getModuleSpecifierValue())) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return declaration.getNameNode().getText() === "defineMutator";
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
const isMutatorNamespaceImport = (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 && MUTATOR_MODULE_SPECIFIERS.has(importDeclaration.getModuleSpecifierValue());
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
const isDefineMutatorCallee = (callee) => {
|
|
39
|
+
if (Node.isIdentifier(callee)) {
|
|
40
|
+
return isDefineMutator(callee);
|
|
41
|
+
}
|
|
42
|
+
if (Node.isPropertyAccessExpression(callee)) {
|
|
43
|
+
const object = callee.getExpression();
|
|
44
|
+
return callee.getName() === "defineMutator" && Node.isIdentifier(object) && isMutatorNamespaceImport(object);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
const mutatorsFromSource = (source) => {
|
|
49
|
+
const mutators = [];
|
|
50
|
+
for (const declaration of source.getVariableDeclarations()) {
|
|
51
|
+
if (!declaration.isExported()) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const initializer = declaration.getInitializer();
|
|
55
|
+
if (initializer?.getKind() !== SyntaxKind.CallExpression) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const callee = initializer.getExpression();
|
|
59
|
+
if (!isDefineMutatorCallee(callee)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const nameNode = declaration.getNameNode();
|
|
63
|
+
if (!Node.isIdentifier(nameNode)) {
|
|
64
|
+
throw diagnosticAt(nameNode, "defineMutator exports must be plain named exports (no destructuring)");
|
|
65
|
+
}
|
|
66
|
+
mutators.push({ exportName: nameNode.getText(), filePath: "mutators" });
|
|
67
|
+
}
|
|
68
|
+
return mutators;
|
|
69
|
+
};
|
|
70
|
+
const discoverMutators = (project, lunoraDirectory) => {
|
|
71
|
+
const mutatorsPath = join(lunoraDirectory, MUTATORS_FILENAME);
|
|
72
|
+
if (!existsSync(mutatorsPath)) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const source = project.getSourceFile(mutatorsPath) ?? project.addSourceFileAtPath(mutatorsPath);
|
|
76
|
+
const mutators = mutatorsFromSource(source);
|
|
77
|
+
mutators.sort((a, b) => a.exportName.localeCompare(b.exportName));
|
|
78
|
+
return mutators;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { MUTATORS_FILENAME, discoverMutators, isDefineMutatorCallee };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GENERATED_HEADER } from './GENERATED_HEADER-
|
|
1
|
+
import { GENERATED_HEADER } from './GENERATED_HEADER-f6nMvllu.mjs';
|
|
2
2
|
import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
|
|
3
3
|
import { argsObjectSchema, LUNORA_ERROR_CODES } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
|
|
4
4
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { queueDefaultName, queueBindingName } from '@lunora/queue';
|
|
4
|
+
import { SyntaxKind, Node } from 'ts-morph';
|
|
5
|
+
import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
|
|
6
|
+
|
|
7
|
+
const QUEUES_FILENAME = "queues.ts";
|
|
8
|
+
const isDefineQueue = (identifier) => {
|
|
9
|
+
const symbol = identifier.getSymbol();
|
|
10
|
+
if (!symbol) {
|
|
11
|
+
return identifier.getText() === "defineQueue";
|
|
12
|
+
}
|
|
13
|
+
for (const declaration of symbol.getDeclarations()) {
|
|
14
|
+
if (!Node.isImportSpecifier(declaration)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (declaration.getImportDeclaration().getModuleSpecifierValue() !== "@lunora/queue") {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return declaration.getNameNode().getText() === "defineQueue";
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
const stringProperty = (expression, exportName, property) => {
|
|
25
|
+
if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
|
|
26
|
+
return expression.getLiteralValue();
|
|
27
|
+
}
|
|
28
|
+
throw diagnosticAt(
|
|
29
|
+
expression,
|
|
30
|
+
`queue "${exportName}": \`${property}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
const numberProperty = (expression, exportName, property) => {
|
|
34
|
+
if (Node.isNumericLiteral(expression)) {
|
|
35
|
+
return expression.getLiteralValue();
|
|
36
|
+
}
|
|
37
|
+
throw diagnosticAt(
|
|
38
|
+
expression,
|
|
39
|
+
`queue "${exportName}": \`${property}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
const queueNameOverride = (argument, exportName) => {
|
|
43
|
+
const nameProperty = argument.getProperty("name");
|
|
44
|
+
if (!nameProperty || !Node.isPropertyAssignment(nameProperty)) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
const name = stringProperty(nameProperty.getInitializerOrThrow(), exportName, "name");
|
|
48
|
+
if (name.length === 0) {
|
|
49
|
+
throw diagnosticAt(nameProperty, `queue "${exportName}": \`name\` must be a non-empty string when provided`);
|
|
50
|
+
}
|
|
51
|
+
return name;
|
|
52
|
+
};
|
|
53
|
+
const queueFromCall = (call, exportName) => {
|
|
54
|
+
const argument = call.getArguments()[0];
|
|
55
|
+
if (!argument || !Node.isObjectLiteralExpression(argument)) {
|
|
56
|
+
throw diagnosticAt(call, `queue "${exportName}": defineQueue must be passed an inline object literal`);
|
|
57
|
+
}
|
|
58
|
+
const ir = {
|
|
59
|
+
bindingName: queueBindingName(exportName),
|
|
60
|
+
exportName,
|
|
61
|
+
mode: "push",
|
|
62
|
+
name: queueNameOverride(argument, exportName) ?? queueDefaultName(exportName),
|
|
63
|
+
tuning: {}
|
|
64
|
+
};
|
|
65
|
+
const modeProperty = argument.getProperty("mode");
|
|
66
|
+
if (modeProperty && Node.isPropertyAssignment(modeProperty)) {
|
|
67
|
+
const mode = stringProperty(modeProperty.getInitializerOrThrow(), exportName, "mode");
|
|
68
|
+
if (mode !== "push" && mode !== "pull") {
|
|
69
|
+
throw diagnosticAt(modeProperty, `queue "${exportName}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(mode)})`);
|
|
70
|
+
}
|
|
71
|
+
ir.mode = mode;
|
|
72
|
+
}
|
|
73
|
+
const dlqProperty = argument.getProperty("deadLetterQueue");
|
|
74
|
+
if (dlqProperty && Node.isPropertyAssignment(dlqProperty)) {
|
|
75
|
+
ir.tuning.deadLetterQueue = stringProperty(dlqProperty.getInitializerOrThrow(), exportName, "deadLetterQueue");
|
|
76
|
+
}
|
|
77
|
+
for (const property of ["maxBatchSize", "maxBatchTimeout", "maxRetries", "retryDelay"]) {
|
|
78
|
+
const node = argument.getProperty(property);
|
|
79
|
+
if (node && Node.isPropertyAssignment(node)) {
|
|
80
|
+
ir.tuning[property] = numberProperty(node.getInitializerOrThrow(), exportName, property);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return ir;
|
|
84
|
+
};
|
|
85
|
+
const queuesFromSource = (source) => {
|
|
86
|
+
const queues = [];
|
|
87
|
+
for (const declaration of source.getVariableDeclarations()) {
|
|
88
|
+
if (!declaration.isExported()) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const initializer = declaration.getInitializer();
|
|
92
|
+
if (initializer?.getKind() !== SyntaxKind.CallExpression) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const call = initializer;
|
|
96
|
+
const callee = call.getExpression();
|
|
97
|
+
if (!Node.isIdentifier(callee) || !isDefineQueue(callee)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const nameNode = declaration.getNameNode();
|
|
101
|
+
if (!Node.isIdentifier(nameNode)) {
|
|
102
|
+
throw diagnosticAt(nameNode, "defineQueue exports must be plain named exports (no destructuring)");
|
|
103
|
+
}
|
|
104
|
+
queues.push(queueFromCall(call, nameNode.getText()));
|
|
105
|
+
}
|
|
106
|
+
return queues;
|
|
107
|
+
};
|
|
108
|
+
const discoverQueues = (project, lunoraDirectory) => {
|
|
109
|
+
const queuesPath = join(lunoraDirectory, QUEUES_FILENAME);
|
|
110
|
+
if (!existsSync(queuesPath)) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const source = project.getSourceFile(queuesPath) ?? project.addSourceFileAtPath(queuesPath);
|
|
114
|
+
const queues = queuesFromSource(source);
|
|
115
|
+
queues.sort((a, b) => a.exportName.localeCompare(b.exportName));
|
|
116
|
+
return queues;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { QUEUES_FILENAME, discoverQueues };
|