@lunora/codegen 1.0.0-alpha.55 → 1.0.0-alpha.57
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/dist/index.d.mts +59 -5
- package/dist/index.d.ts +59 -5
- package/dist/index.mjs +1 -38
- package/dist/packem_shared/AGENTS_FILENAME-BesaDYkL.mjs +1 -0
- package/dist/packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs +1 -0
- package/dist/packem_shared/CodegenDiagnosticError-DPezpZTz.mjs +1 -0
- package/dist/packem_shared/FLAGS_FILENAME-DW5oGq1q.mjs +1 -0
- package/dist/packem_shared/GENERATED_HEADER-hlHbtIBb.mjs +1 -0
- package/dist/packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs +1 -0
- package/dist/packem_shared/MUTATORS_FILENAME-BKKPROzu.mjs +1 -0
- package/dist/packem_shared/NOTIFY_FILENAME-C-c7Lg-U.mjs +1 -0
- package/dist/packem_shared/OPENRPC_VERSION-DWoqALFJ.mjs +3 -0
- package/dist/packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs +1 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Cuf8KyVF.mjs +3 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs +15 -0
- package/dist/packem_shared/SHAPES_FILENAME-DTkSJSsg.mjs +1 -0
- package/dist/packem_shared/WORKFLOWS_FILENAME-Bk5upkGM.mjs +1 -0
- package/dist/packem_shared/buildOpenApiDocument-BRCc5AIx.mjs +3 -0
- package/dist/packem_shared/discover-ast-CezKqEhE.mjs +1 -0
- package/dist/packem_shared/discoverAuthApiCalls-DOfSQqVK.mjs +1 -0
- package/dist/packem_shared/discoverCrons-B09_uEuL.mjs +1 -0
- package/dist/packem_shared/discoverFunctions-BdibLQmc.mjs +1 -0
- package/dist/packem_shared/discoverHttpRoutes-BOWz6y_n.mjs +1 -0
- package/dist/packem_shared/discoverInserts-BtteTyNy.mjs +1 -0
- package/dist/packem_shared/discoverMaskProcedures-COPmwMBm.mjs +1 -0
- package/dist/packem_shared/discoverMigrations-iGMlp9YJ.mjs +1 -0
- package/dist/packem_shared/discoverNondeterministicCalls-Dmgc4QBx.mjs +1 -0
- package/dist/packem_shared/discoverQueries-CcfuGKHh.mjs +1 -0
- package/dist/packem_shared/discoverR2sqlCalls-CjZKvg-N.mjs +1 -0
- package/dist/packem_shared/discoverRlsMetadata-BXmNOgry.mjs +1 -0
- package/dist/packem_shared/discoverSandboxUsage-CDdBqWcM.mjs +1 -0
- package/dist/packem_shared/discoverSchema-m2voTncu.mjs +1 -0
- package/dist/packem_shared/discoverStorageRulesMetadata-b71cJJHz.mjs +1 -0
- package/dist/packem_shared/emit-BYVxPDqO.mjs +2127 -0
- package/dist/packem_shared/emitApp-CHCOfQer.mjs +413 -0
- package/dist/packem_shared/formatAdvisories-DZvv-0MG.mjs +2 -0
- package/dist/packem_shared/parse-validator-CSDlMEvE.mjs +1 -0
- package/dist/packem_shared/paths-BmX5O1sG.mjs +1 -0
- package/dist/packem_shared/redact-CQ8-to6l.mjs +1 -0
- package/dist/packem_shared/schemaFromIr-R1ZFzVyy.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/AGENTS_FILENAME-Cxx7wiSs.mjs +0 -158
- package/dist/packem_shared/CONTAINERS_FILENAME-DjpXMqhp.mjs +0 -224
- package/dist/packem_shared/CodegenDiagnosticError-DyQ5FwkM.mjs +0 -24
- package/dist/packem_shared/FLAGS_FILENAME-D5igzqwR.mjs +0 -139
- package/dist/packem_shared/GENERATED_HEADER-C8tAvxqP.mjs +0 -4
- package/dist/packem_shared/LUNORA_ERROR_CODES-DvTLozCu.mjs +0 -68
- package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +0 -81
- package/dist/packem_shared/NOTIFY_FILENAME-CK2IrsrP.mjs +0 -152
- package/dist/packem_shared/OPENRPC_VERSION-DvDChMhC.mjs +0 -60
- package/dist/packem_shared/QUEUES_FILENAME-Xv6Vy-Ku.mjs +0 -145
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-YAL6GrxI.mjs +0 -3597
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-DGD73E_n.mjs +0 -252
- package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +0 -94
- package/dist/packem_shared/WORKFLOWS_FILENAME-Dtuzvluc.mjs +0 -158
- package/dist/packem_shared/buildOpenApiDocument-DCQSLuFc.mjs +0 -262
- package/dist/packem_shared/discover-ast-CT6BgBr4.mjs +0 -13
- package/dist/packem_shared/discoverAuthApiCalls-Dhwgf4J4.mjs +0 -62
- package/dist/packem_shared/discoverCrons-UbQLLmMS.mjs +0 -286
- package/dist/packem_shared/discoverFunctions-COG_Xkyz.mjs +0 -544
- package/dist/packem_shared/discoverHttpRoutes-CVXWZkzo.mjs +0 -139
- package/dist/packem_shared/discoverInserts-DdWnXmLS.mjs +0 -61
- package/dist/packem_shared/discoverMaskProcedures-BG58_fw3.mjs +0 -273
- package/dist/packem_shared/discoverMigrations-Bw1U01zr.mjs +0 -97
- package/dist/packem_shared/discoverNondeterministicCalls-BbXEFZUT.mjs +0 -122
- package/dist/packem_shared/discoverQueries-CDmxu2ET.mjs +0 -62
- package/dist/packem_shared/discoverR2sqlCalls-Bn7QVv7J.mjs +0 -80
- package/dist/packem_shared/discoverRlsMetadata-D9uN35no.mjs +0 -280
- package/dist/packem_shared/discoverSandboxUsage-B5jDU6Bt.mjs +0 -38
- package/dist/packem_shared/discoverSchema-BJp5_T4o.mjs +0 -906
- package/dist/packem_shared/discoverStorageRulesMetadata-BqMhuEjo.mjs +0 -97
- package/dist/packem_shared/emit-DIbr7U31.mjs +0 -3884
- package/dist/packem_shared/emitApp-DbMM8iHe.mjs +0 -706
- package/dist/packem_shared/formatAdvisories-Cans5TWS.mjs +0 -131
- package/dist/packem_shared/parse-validator-BDGV8iue.mjs +0 -144
- package/dist/packem_shared/paths-BRd6JHuF.mjs +0 -11
- package/dist/packem_shared/redact-oTmsol5A.mjs +0 -33
- package/dist/packem_shared/schemaFromIr-DTYsLBaA.mjs +0 -57
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { G as GENERATED_HEADER } from './emit-DIbr7U31.mjs';
|
|
2
|
-
import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
|
|
3
|
-
import { argsObjectSchema, LUNORA_ERROR_CODES } from './LUNORA_ERROR_CODES-DvTLozCu.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,145 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { LunoraError } from '@lunora/errors';
|
|
4
|
-
import { queueDefaultName, queueBindingName } from '@lunora/queue';
|
|
5
|
-
import { SyntaxKind, Node } from 'ts-morph';
|
|
6
|
-
import { diagnosticAt } from './CodegenDiagnosticError-DyQ5FwkM.mjs';
|
|
7
|
-
|
|
8
|
-
const QUEUES_FILENAME = "queues.ts";
|
|
9
|
-
const isDefineQueue = (identifier) => {
|
|
10
|
-
const symbol = identifier.getSymbol();
|
|
11
|
-
if (!symbol) {
|
|
12
|
-
return identifier.getText() === "defineQueue";
|
|
13
|
-
}
|
|
14
|
-
for (const declaration of symbol.getDeclarations()) {
|
|
15
|
-
if (!Node.isImportSpecifier(declaration)) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (declaration.getImportDeclaration().getModuleSpecifierValue() !== "@lunora/queue") {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return declaration.getNameNode().getText() === "defineQueue";
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
const stringProperty = (expression, exportName, property) => {
|
|
26
|
-
if (Node.isStringLiteral(expression) || Node.isNoSubstitutionTemplateLiteral(expression)) {
|
|
27
|
-
return expression.getLiteralValue();
|
|
28
|
-
}
|
|
29
|
-
throw diagnosticAt(
|
|
30
|
-
expression,
|
|
31
|
-
`queue "${exportName}": \`${property}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
const numberProperty = (expression, exportName, property) => {
|
|
35
|
-
if (Node.isNumericLiteral(expression)) {
|
|
36
|
-
return expression.getLiteralValue();
|
|
37
|
-
}
|
|
38
|
-
throw diagnosticAt(
|
|
39
|
-
expression,
|
|
40
|
-
`queue "${exportName}": \`${property}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
const queueNameOverride = (argument, exportName) => {
|
|
44
|
-
const nameProperty = argument.getProperty("name");
|
|
45
|
-
if (!nameProperty || !Node.isPropertyAssignment(nameProperty)) {
|
|
46
|
-
return void 0;
|
|
47
|
-
}
|
|
48
|
-
const name = stringProperty(nameProperty.getInitializerOrThrow(), exportName, "name");
|
|
49
|
-
if (name.length === 0) {
|
|
50
|
-
throw diagnosticAt(nameProperty, `queue "${exportName}": \`name\` must be a non-empty string when provided`);
|
|
51
|
-
}
|
|
52
|
-
return name;
|
|
53
|
-
};
|
|
54
|
-
const queueFromCall = (call, exportName) => {
|
|
55
|
-
const argument = call.getArguments()[0];
|
|
56
|
-
if (!argument || !Node.isObjectLiteralExpression(argument)) {
|
|
57
|
-
throw diagnosticAt(call, `queue "${exportName}": defineQueue must be passed an inline object literal`);
|
|
58
|
-
}
|
|
59
|
-
const ir = {
|
|
60
|
-
bindingName: queueBindingName(exportName),
|
|
61
|
-
exportName,
|
|
62
|
-
mode: "push",
|
|
63
|
-
name: queueNameOverride(argument, exportName) ?? queueDefaultName(exportName),
|
|
64
|
-
tuning: {}
|
|
65
|
-
};
|
|
66
|
-
const modeProperty = argument.getProperty("mode");
|
|
67
|
-
if (modeProperty && Node.isPropertyAssignment(modeProperty)) {
|
|
68
|
-
const mode = stringProperty(modeProperty.getInitializerOrThrow(), exportName, "mode");
|
|
69
|
-
if (mode !== "push" && mode !== "pull") {
|
|
70
|
-
throw diagnosticAt(modeProperty, `queue "${exportName}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(mode)})`);
|
|
71
|
-
}
|
|
72
|
-
ir.mode = mode;
|
|
73
|
-
}
|
|
74
|
-
const dlqProperty = argument.getProperty("deadLetterQueue");
|
|
75
|
-
if (dlqProperty && Node.isPropertyAssignment(dlqProperty)) {
|
|
76
|
-
ir.tuning.deadLetterQueue = stringProperty(dlqProperty.getInitializerOrThrow(), exportName, "deadLetterQueue");
|
|
77
|
-
}
|
|
78
|
-
for (const property of ["maxBatchSize", "maxBatchTimeout", "maxRetries", "retryDelay"]) {
|
|
79
|
-
const node = argument.getProperty(property);
|
|
80
|
-
if (node && Node.isPropertyAssignment(node)) {
|
|
81
|
-
ir.tuning[property] = numberProperty(node.getInitializerOrThrow(), exportName, property);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return ir;
|
|
85
|
-
};
|
|
86
|
-
const queuesFromSource = (source) => {
|
|
87
|
-
const queues = [];
|
|
88
|
-
for (const declaration of source.getVariableDeclarations()) {
|
|
89
|
-
if (!declaration.isExported()) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const initializer = declaration.getInitializer();
|
|
93
|
-
if (initializer?.getKind() !== SyntaxKind.CallExpression) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const call = initializer;
|
|
97
|
-
const callee = call.getExpression();
|
|
98
|
-
if (!Node.isIdentifier(callee) || !isDefineQueue(callee)) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const nameNode = declaration.getNameNode();
|
|
102
|
-
if (!Node.isIdentifier(nameNode)) {
|
|
103
|
-
throw diagnosticAt(nameNode, "defineQueue exports must be plain named exports (no destructuring)");
|
|
104
|
-
}
|
|
105
|
-
queues.push(queueFromCall(call, nameNode.getText()));
|
|
106
|
-
}
|
|
107
|
-
return queues;
|
|
108
|
-
};
|
|
109
|
-
const assertUniqueNames = (queues) => {
|
|
110
|
-
const seenNames = /* @__PURE__ */ new Map();
|
|
111
|
-
const seenBindings = /* @__PURE__ */ new Map();
|
|
112
|
-
for (const queue of queues) {
|
|
113
|
-
const priorName = seenNames.get(queue.name);
|
|
114
|
-
if (priorName !== void 0) {
|
|
115
|
-
throw new LunoraError(
|
|
116
|
-
"DUPLICATE_QUEUE_NAME",
|
|
117
|
-
`Duplicate queue name "${queue.name}": produced by both "${priorName}" and "${queue.exportName}". Deployed queue names must be unique across the project.`,
|
|
118
|
-
{ status: 500 }
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
seenNames.set(queue.name, queue.exportName);
|
|
122
|
-
const priorBinding = seenBindings.get(queue.bindingName);
|
|
123
|
-
if (priorBinding !== void 0) {
|
|
124
|
-
throw new LunoraError(
|
|
125
|
-
"DUPLICATE_QUEUE_BINDING",
|
|
126
|
-
`Duplicate queue binding "${queue.bindingName}": produced by both "${priorBinding}" and "${queue.exportName}". Queue export names must yield unique binding names.`,
|
|
127
|
-
{ status: 500 }
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
seenBindings.set(queue.bindingName, queue.exportName);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
const discoverQueues = (project, lunoraDirectory) => {
|
|
134
|
-
const queuesPath = join(lunoraDirectory, QUEUES_FILENAME);
|
|
135
|
-
if (!existsSync(queuesPath)) {
|
|
136
|
-
return [];
|
|
137
|
-
}
|
|
138
|
-
const source = project.getSourceFile(queuesPath) ?? project.addSourceFileAtPath(queuesPath);
|
|
139
|
-
const queues = queuesFromSource(source);
|
|
140
|
-
queues.sort((a, b) => a.exportName.localeCompare(b.exportName));
|
|
141
|
-
assertUniqueNames(queues);
|
|
142
|
-
return queues;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export { QUEUES_FILENAME, discoverQueues };
|