@lunora/codegen 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (42) hide show
  1. package/LICENSE.md +6 -0
  2. package/__assets__/package-og.svg +1 -1
  3. package/dist/index.d.mts +1950 -734
  4. package/dist/index.d.ts +1950 -734
  5. package/dist/index.mjs +32 -24
  6. package/dist/packem_shared/AGENTS_FILENAME-Cxx7wiSs.mjs +158 -0
  7. package/dist/packem_shared/{CONTAINERS_FILENAME-0K-pjNb8.mjs → CONTAINERS_FILENAME-DjpXMqhp.mjs} +1 -1
  8. package/dist/packem_shared/{CodegenDiagnosticError-54jWDxA9.mjs → CodegenDiagnosticError-DyQ5FwkM.mjs} +7 -5
  9. package/dist/packem_shared/FLAGS_FILENAME-Dg4mKUuz.mjs +139 -0
  10. package/dist/packem_shared/GENERATED_HEADER-C5paWNYO.mjs +4 -0
  11. package/dist/packem_shared/{LUNORA_ERROR_CODES-CySpQPD3.mjs → LUNORA_ERROR_CODES-DvTLozCu.mjs} +8 -1
  12. package/dist/packem_shared/MUTATORS_FILENAME-BZOfUhlY.mjs +81 -0
  13. package/dist/packem_shared/{OPENRPC_VERSION-C7zKVeKi.mjs → OPENRPC_VERSION-7A2weq2u.mjs} +2 -2
  14. package/dist/packem_shared/QUEUES_FILENAME-Xv6Vy-Ku.mjs +145 -0
  15. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-G5dkcxPR.mjs +3502 -0
  16. package/dist/packem_shared/{SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs → SCHEMA_SNAPSHOT_VERSION-D0ARY6rL.mjs} +18 -2
  17. package/dist/packem_shared/SHAPES_FILENAME-DOhPGi-6.mjs +94 -0
  18. package/dist/packem_shared/WORKFLOWS_FILENAME-Dtuzvluc.mjs +158 -0
  19. package/dist/packem_shared/{buildOpenApiDocument-Cns1EkCQ.mjs → buildOpenApiDocument-B7mEdzA2.mjs} +2 -2
  20. package/dist/packem_shared/{discoverAuthApiCalls-C35R6z0T.mjs → discoverAuthApiCalls-Dx3K42rk.mjs} +1 -1
  21. package/dist/packem_shared/{discoverCrons-BL6iGuJ3.mjs → discoverCrons-DvqkEWdx.mjs} +68 -36
  22. package/dist/packem_shared/{discoverFunctions-DEgAcRuD.mjs → discoverFunctions-BJ-qR7Rg.mjs} +72 -14
  23. package/dist/packem_shared/{discoverHttpRoutes-C978pBiG.mjs → discoverHttpRoutes-daCzuTe8.mjs} +10 -2
  24. package/dist/packem_shared/{discoverInserts-CRQdXvHO.mjs → discoverInserts-DI4q5NxE.mjs} +24 -2
  25. package/dist/packem_shared/{discoverMaskProcedures-B64zA740.mjs → discoverMaskProcedures-BcTOEKNU.mjs} +58 -2
  26. package/dist/packem_shared/{discoverMigrations-Doj_-BAA.mjs → discoverMigrations-VNUFvCwr.mjs} +10 -4
  27. package/dist/packem_shared/{discoverNondeterministicCalls-4KiPQxQU.mjs → discoverNondeterministicCalls-S0N2xLCq.mjs} +1 -1
  28. package/dist/packem_shared/{discoverQueries-BkIi0dBD.mjs → discoverQueries-CJnnnLpd.mjs} +1 -1
  29. package/dist/packem_shared/{discoverR2sqlCalls-BpDqvcUn.mjs → discoverR2sqlCalls-pnpicWfz.mjs} +1 -1
  30. package/dist/packem_shared/{discoverRlsMetadata-DpRB1HMe.mjs → discoverRlsMetadata-DppniPUH.mjs} +1 -1
  31. package/dist/packem_shared/discoverSandboxUsage-BUM2r90k.mjs +38 -0
  32. package/dist/packem_shared/{discoverSchema-DB_QrIQe.mjs → discoverSchema-BaSAvooG.mjs} +326 -14
  33. package/dist/packem_shared/{discoverStorageRulesMetadata-DAqJUxUv.mjs → discoverStorageRulesMetadata-CnHl2rXD.mjs} +1 -1
  34. package/dist/packem_shared/{GENERATED_HEADER-DF1hQcix.mjs → emit-ClTbCLy4.mjs} +1458 -154
  35. package/dist/packem_shared/{emitApp-Ci_hcJNO.mjs → emitApp-CzzrjVqH.mjs} +129 -31
  36. package/dist/packem_shared/formatAdvisories-BmF7Mplc.mjs +115 -0
  37. package/dist/packem_shared/{parse-validator-tuQtHrsr.mjs → parse-validator-BSJo1HGP.mjs} +18 -6
  38. package/dist/packem_shared/redact-oTmsol5A.mjs +33 -0
  39. package/package.json +10 -7
  40. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BqOtU2lC.mjs +0 -922
  41. package/dist/packem_shared/WORKFLOWS_FILENAME-DRDQdhfq.mjs +0 -84
  42. package/dist/packem_shared/formatAdvisories-8NIv1k0I.mjs +0 -69
@@ -1,84 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { workflowDefaultName, workflowClassName, workflowBindingName } from '@lunora/workflow';
4
- import { SyntaxKind, Node } from 'ts-morph';
5
- import { diagnosticAt } from './CodegenDiagnosticError-54jWDxA9.mjs';
6
-
7
- const WORKFLOWS_FILENAME = "workflows.ts";
8
- const isDefineWorkflow = (identifier) => {
9
- const symbol = identifier.getSymbol();
10
- if (!symbol) {
11
- return identifier.getText() === "defineWorkflow";
12
- }
13
- for (const declaration of symbol.getDeclarations()) {
14
- if (!Node.isImportSpecifier(declaration)) {
15
- continue;
16
- }
17
- if (declaration.getImportDeclaration().getModuleSpecifierValue() !== "@lunora/workflow") {
18
- return false;
19
- }
20
- return declaration.getNameNode().getText() === "defineWorkflow";
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
- `workflow "${exportName}": \`${property}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`
31
- );
32
- };
33
- const workflowFromCall = (call, exportName) => {
34
- const argument = call.getArguments()[0];
35
- if (!argument || !Node.isObjectLiteralExpression(argument)) {
36
- throw diagnosticAt(call, `workflow "${exportName}": defineWorkflow must be passed an inline object literal`);
37
- }
38
- const ir = {
39
- bindingName: workflowBindingName(exportName),
40
- className: workflowClassName(exportName),
41
- exportName,
42
- name: workflowDefaultName(exportName)
43
- };
44
- const nameProperty = argument.getProperty("name");
45
- if (nameProperty && Node.isPropertyAssignment(nameProperty)) {
46
- ir.name = stringProperty(nameProperty.getInitializerOrThrow(), exportName, "name");
47
- }
48
- return ir;
49
- };
50
- const workflowsFromSource = (source) => {
51
- const workflows = [];
52
- for (const declaration of source.getVariableDeclarations()) {
53
- if (!declaration.isExported()) {
54
- continue;
55
- }
56
- const initializer = declaration.getInitializer();
57
- if (initializer?.getKind() !== SyntaxKind.CallExpression) {
58
- continue;
59
- }
60
- const call = initializer;
61
- const callee = call.getExpression();
62
- if (!Node.isIdentifier(callee) || !isDefineWorkflow(callee)) {
63
- continue;
64
- }
65
- const nameNode = declaration.getNameNode();
66
- if (!Node.isIdentifier(nameNode)) {
67
- throw diagnosticAt(nameNode, "defineWorkflow exports must be plain named exports (no destructuring)");
68
- }
69
- workflows.push(workflowFromCall(call, nameNode.getText()));
70
- }
71
- return workflows;
72
- };
73
- const discoverWorkflows = (project, lunoraDirectory) => {
74
- const workflowsPath = join(lunoraDirectory, WORKFLOWS_FILENAME);
75
- if (!existsSync(workflowsPath)) {
76
- return [];
77
- }
78
- const source = project.getSourceFile(workflowsPath) ?? project.addSourceFileAtPath(workflowsPath);
79
- const workflows = workflowsFromSource(source);
80
- workflows.sort((a, b) => a.exportName.localeCompare(b.exportName));
81
- return workflows;
82
- };
83
-
84
- export { WORKFLOWS_FILENAME, discoverWorkflows };
@@ -1,69 +0,0 @@
1
- import { runAdvisor } from '@lunora/advisor';
2
-
3
- const flattenIndexes = (table) => [
4
- ...table.indexes.map((index) => {
5
- return { fields: index.fields, kind: "index", name: index.name, unique: index.unique };
6
- }),
7
- ...table.searchIndexes.map((index) => {
8
- return { fields: [index.field, ...index.filterFields ?? []], kind: "search", name: index.name };
9
- }),
10
- ...table.rankIndexes.map((index) => {
11
- return { fields: [...index.sortBy.map((key) => key.field), ...index.partitionBy ?? []], kind: "rank", name: index.name };
12
- }),
13
- ...table.vectorIndexes.filter((index) => index.field !== void 0).map((index) => {
14
- return { fields: [index.field], kind: "vector", name: index.name };
15
- })
16
- ];
17
- const toAdvisorSchema = (schema) => {
18
- return {
19
- tables: schema.tables.map((table) => {
20
- return {
21
- externallyManaged: table.externallyManaged ?? false,
22
- fields: Object.keys(table.shape),
23
- indexes: flattenIndexes(table),
24
- name: table.name,
25
- relations: table.relations.map((relation) => {
26
- return {
27
- field: relation.field,
28
- kind: relation.kind,
29
- name: relation.name,
30
- onDelete: relation.onDelete,
31
- references: relation.references,
32
- table: relation.table
33
- };
34
- })
35
- };
36
- })
37
- };
38
- };
39
- const lintSchema = (schema, queries = [], inserts, authApiCalls, rlsProcedures, containers, workflows, workflowCalls, maskProcedures, nondeterministicCalls, procedureProtections, argumentValidators, secretLiterals, sqlInterpolations, adminRoutes, r2sqlCalls) => runAdvisor(
40
- {
41
- adminRoutes,
42
- argValidators: argumentValidators,
43
- authApiCalls,
44
- containers,
45
- inserts,
46
- maskProcedures,
47
- nondeterministicCalls,
48
- procedureProtections,
49
- queries,
50
- r2sqlCalls,
51
- rlsProcedures,
52
- schema: toAdvisorSchema(schema),
53
- secretLiterals,
54
- sqlInterpolations,
55
- workflowCalls,
56
- workflows
57
- },
58
- { source: "static" }
59
- );
60
- const formatAdvisories = (findings) => {
61
- if (findings.length === 0) {
62
- return "";
63
- }
64
- const header = `@lunora/codegen: ${String(findings.length)} schema advisor finding${findings.length === 1 ? "" : "s"}`;
65
- const lines = findings.map((finding) => ` [${finding.level}] ${finding.name}: ${finding.detail}`);
66
- return [header, ...lines].join("\n");
67
- };
68
-
69
- export { formatAdvisories, lintSchema };