@lunora/codegen 1.0.0-alpha.12 → 1.0.0-alpha.120

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 (79) hide show
  1. package/LICENSE.md +6 -0
  2. package/dist/index.d.mts +2986 -958
  3. package/dist/index.d.ts +2986 -958
  4. package/dist/index.mjs +1 -30
  5. package/dist/packem_shared/AGENTS_FILENAME-CPHo8Se5.mjs +1 -0
  6. package/dist/packem_shared/CONTAINERS_FILENAME-Bvn6LZP6.mjs +1 -0
  7. package/dist/packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs +1 -0
  8. package/dist/packem_shared/DEFAULT_TARGET-CIH5PRk1.mjs +1 -0
  9. package/dist/packem_shared/FLAGS_FILENAME-DtBWyUKq.mjs +1 -0
  10. package/dist/packem_shared/GENERATED_HEADER-Cx5Qh2XJ.mjs +1 -0
  11. package/dist/packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs +1 -0
  12. package/dist/packem_shared/MUTATORS_FILENAME-B2-W8Bm3.mjs +1 -0
  13. package/dist/packem_shared/NOTIFY_FILENAME-IJXY4yHt.mjs +1 -0
  14. package/dist/packem_shared/OPENRPC_VERSION-14yZ-O3V.mjs +3 -0
  15. package/dist/packem_shared/QUEUES_FILENAME-BnGLtAIu.mjs +1 -0
  16. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CbOqo05-.mjs +9 -0
  17. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-B0cTpK1D.mjs +2 -0
  18. package/dist/packem_shared/SDK_LANGUAGES-CFyux-74.mjs +371 -0
  19. package/dist/packem_shared/SHAPES_FILENAME-DTp6VI6K.mjs +1 -0
  20. package/dist/packem_shared/SchemaSnapshotParseError-BoHDfCO3.mjs +16 -0
  21. package/dist/packem_shared/WORKFLOWS_FILENAME-B8y51Frf.mjs +1 -0
  22. package/dist/packem_shared/buildOpenApiDocument-DI8bgteQ.mjs +3 -0
  23. package/dist/packem_shared/describeErrorLevelFindings-D23VSkFP.mjs +1 -0
  24. package/dist/packem_shared/discover-ast-D33zP-NZ.mjs +1 -0
  25. package/dist/packem_shared/discover-queries-Dfj_0WJG.mjs +1 -0
  26. package/dist/packem_shared/discoverAuthApiCalls-DUjcl0SB.mjs +1 -0
  27. package/dist/packem_shared/discoverCrons-BUJO2ipU.mjs +1 -0
  28. package/dist/packem_shared/discoverFunctions-006teuNG.mjs +1 -0
  29. package/dist/packem_shared/discoverHttpRoutes-BxF4FRZL.mjs +1 -0
  30. package/dist/packem_shared/discoverInserts-YX8AmrzL.mjs +1 -0
  31. package/dist/packem_shared/discoverMaskProcedures-BCl3fNrQ.mjs +1 -0
  32. package/dist/packem_shared/discoverMigrations-4Jjf5DJE.mjs +1 -0
  33. package/dist/packem_shared/discoverNondeterministicCalls-BA91Z-vF.mjs +1 -0
  34. package/dist/packem_shared/discoverQueries-C5S9tFoD.mjs +1 -0
  35. package/dist/packem_shared/discoverR2sqlCalls-M2ob41UX.mjs +1 -0
  36. package/dist/packem_shared/discoverRlsMetadata-Dwt2p8IK.mjs +1 -0
  37. package/dist/packem_shared/discoverSandboxUsage-L0lV17de.mjs +1 -0
  38. package/dist/packem_shared/discoverSchema-gJ93Xjpx.mjs +1 -0
  39. package/dist/packem_shared/discoverStorageRulesMetadata-69Y8wZb2.mjs +1 -0
  40. package/dist/packem_shared/emit-C0azW4mT.mjs +2171 -0
  41. package/dist/packem_shared/emitApp-Dyr-onNf.mjs +550 -0
  42. package/dist/packem_shared/formatAdvisories-CkEu1eye.mjs +2 -0
  43. package/dist/packem_shared/isTypedSchema-B_qlBbE-.mjs +2 -0
  44. package/dist/packem_shared/module-specifiers-WF8iAydP.mjs +1 -0
  45. package/dist/packem_shared/parse-validator-C5ycrhR3.mjs +1 -0
  46. package/dist/packem_shared/paths-C-9fwEgQ.mjs +1 -0
  47. package/dist/packem_shared/readPackageDependencies-C6h6FZuP.mjs +1 -0
  48. package/dist/packem_shared/redact-Cy14LEnc.mjs +1 -0
  49. package/dist/packem_shared/schemaFromIr-BWFnvCVg.mjs +1 -0
  50. package/package.json +12 -7
  51. package/dist/packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs +0 -224
  52. package/dist/packem_shared/CodegenDiagnosticError-DeblMkzO.mjs +0 -23
  53. package/dist/packem_shared/GENERATED_HEADER-BEA7oWGC.mjs +0 -2841
  54. package/dist/packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs +0 -61
  55. package/dist/packem_shared/OPENRPC_VERSION-CQ3f8YQ-.mjs +0 -60
  56. package/dist/packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs +0 -119
  57. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BXtduJFE.mjs +0 -954
  58. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs +0 -245
  59. package/dist/packem_shared/WORKFLOWS_FILENAME-D62dcBGg.mjs +0 -84
  60. package/dist/packem_shared/buildOpenApiDocument-699G4RP4.mjs +0 -183
  61. package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
  62. package/dist/packem_shared/discoverAuthApiCalls-CoirYbg6.mjs +0 -62
  63. package/dist/packem_shared/discoverCrons-Cev7RRAf.mjs +0 -257
  64. package/dist/packem_shared/discoverFunctions-BWMczzBx.mjs +0 -465
  65. package/dist/packem_shared/discoverHttpRoutes-CfP6cMzt.mjs +0 -131
  66. package/dist/packem_shared/discoverInserts-C7zxXkUf.mjs +0 -61
  67. package/dist/packem_shared/discoverMaskProcedures-Cm81kwrb.mjs +0 -217
  68. package/dist/packem_shared/discoverMigrations-Bi5nJ0mJ.mjs +0 -97
  69. package/dist/packem_shared/discoverNondeterministicCalls-C4M8AXmQ.mjs +0 -122
  70. package/dist/packem_shared/discoverQueries-B0wGT-xe.mjs +0 -62
  71. package/dist/packem_shared/discoverR2sqlCalls-BVNMd428.mjs +0 -80
  72. package/dist/packem_shared/discoverRlsMetadata-BS9GOGC5.mjs +0 -280
  73. package/dist/packem_shared/discoverSchema-BnWHHJ4T.mjs +0 -822
  74. package/dist/packem_shared/discoverStorageRulesMetadata-Da8BKXcI.mjs +0 -97
  75. package/dist/packem_shared/emitApp-DiK0QSBn.mjs +0 -617
  76. package/dist/packem_shared/formatAdvisories-8NIv1k0I.mjs +0 -69
  77. package/dist/packem_shared/parse-validator-Cabb60UV.mjs +0 -133
  78. package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
  79. package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
@@ -1,61 +0,0 @@
1
- import { jsonSchemaFromNode, objectSchemaFromNodes } from '@lunora/values';
2
-
3
- const literalConst = (literalValue) => {
4
- if (literalValue === void 0) {
5
- return {};
6
- }
7
- const trimmed = literalValue.trim();
8
- if (trimmed === "true") {
9
- return { const: true };
10
- }
11
- if (trimmed === "false") {
12
- return { const: false };
13
- }
14
- if (trimmed === "null") {
15
- return { const: null, type: "null" };
16
- }
17
- if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
18
- return { const: trimmed.slice(1, -1), type: "string" };
19
- }
20
- const asNumber = Number(trimmed);
21
- if (!Number.isNaN(asNumber)) {
22
- return { const: asNumber };
23
- }
24
- return { const: trimmed };
25
- };
26
- const irReader = {
27
- constraints: () => void 0,
28
- inner: (validator) => validator.inner,
29
- isNullable: (validator) => validator.column?.notNull === false,
30
- // `ValidatorIR.kind` is a loose `string` (build-time AST); narrow it to the
31
- // shared reader's `ValidatorKind`. Unknown kinds fall through the mapper's
32
- // `default` branch to an empty schema, exactly as before.
33
- kind: (validator) => validator.kind,
34
- literalSchema: (validator) => literalConst(validator.literalValue),
35
- members: (validator) => validator.members ?? [],
36
- shape: (validator) => validator.shape ?? {},
37
- tableName: (validator) => validator.tableName,
38
- valueChild: (validator) => validator.valueType
39
- };
40
- const validatorIrToJsonSchema = (validator) => jsonSchemaFromNode(validator, irReader);
41
- const objectSchema = (shape) => objectSchemaFromNodes(shape, irReader);
42
- const argsObjectSchema = (args) => objectSchema(args);
43
- const LUNORA_ERROR_CODES = [
44
- "BAD_REQUEST",
45
- "CONFLICT",
46
- "COUNT_RLS_UNSUPPORTED",
47
- "FORBIDDEN",
48
- "FUNCTION_NOT_FOUND",
49
- "INTERNAL",
50
- "INTERNAL_SERVER_ERROR",
51
- "METHOD_NOT_ALLOWED",
52
- "NOT_FOUND",
53
- "NOT_IMPLEMENTED",
54
- "PAYLOAD_TOO_LARGE",
55
- "TOO_MANY_REQUESTS",
56
- "UNAUTHORIZED",
57
- "UNPROCESSABLE",
58
- "VALIDATION_ERROR"
59
- ];
60
-
61
- export { LUNORA_ERROR_CODES, argsObjectSchema, literalConst, objectSchema, validatorIrToJsonSchema };
@@ -1,60 +0,0 @@
1
- import { GENERATED_HEADER } from './GENERATED_HEADER-BEA7oWGC.mjs';
2
- import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
3
- import { argsObjectSchema, LUNORA_ERROR_CODES } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
4
-
5
- const OPENRPC_VERSION = "1.3.2";
6
- const inferredResultSchema = () => {
7
- return { description: "Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON." };
8
- };
9
- const rpcMethod = (definition) => {
10
- const namespace = sanitizeNamespace(definition.filePath);
11
- const functionPath = `${namespace}:${definition.exportName}`;
12
- return {
13
- description: `Invoke the \`${definition.kind}\` \`${functionPath}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${functionPath}", "args": { … } }\`).`,
14
- errors: LUNORA_ERROR_CODES.map((code, index) => {
15
- return { code: -32e3 - index, data: { code }, message: code };
16
- }),
17
- name: functionPath,
18
- params: [
19
- {
20
- description: "The function's argument object (the RPC envelope's `args`).",
21
- name: "args",
22
- // A function with no declared args still takes an (empty) args
23
- // object; `required` reflects whether the function declares any
24
- // arguments at all.
25
- required: Object.keys(definition.args).length > 0,
26
- schema: argsObjectSchema(definition.args)
27
- }
28
- ],
29
- result: {
30
- name: "result",
31
- schema: inferredResultSchema()
32
- },
33
- summary: `${definition.kind}: ${functionPath}`,
34
- "x-lunora-function-kind": definition.kind,
35
- // OpenRPC has no first-class tag grouping; surface the file namespace as
36
- // an `x-tags` extension so tooling can group methods by source file.
37
- "x-tags": [{ name: namespace }]
38
- };
39
- };
40
- const buildOpenRpcDocument = (input) => {
41
- const version = input.version ?? "0.0.0";
42
- const rpcFunctions = input.functions.filter((definition) => definition.visibility !== "internal" && definition.kind !== "stream");
43
- const methods = rpcFunctions.map((definition) => rpcMethod(definition)).toSorted((a, b) => a.name.localeCompare(b.name));
44
- const document = {
45
- info: {
46
- description: "Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",
47
- title: "Lunora RPC",
48
- version
49
- },
50
- methods,
51
- openrpc: OPENRPC_VERSION
52
- };
53
- return document;
54
- };
55
- const emitOpenRpc = (input) => `${JSON.stringify(buildOpenRpcDocument(input), void 0, 2)}
56
- `;
57
- const emitOpenRpcModule = (document_) => `${GENERATED_HEADER}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(document_, void 0, 4)};
58
- `;
59
-
60
- export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule };
@@ -1,119 +0,0 @@
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-DeblMkzO.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 };