@lunora/config 1.0.0-alpha.38 → 1.0.0-alpha.381

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 (137) hide show
  1. package/LICENSE.md +135 -0
  2. package/README.md +3 -3
  3. package/dist/cli/index.d.mts +2 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.mjs +1 -0
  6. package/dist/cloudflare/index.d.mts +1306 -0
  7. package/dist/cloudflare/index.d.ts +1306 -0
  8. package/dist/cloudflare/index.mjs +1 -0
  9. package/dist/index.d.mts +845 -974
  10. package/dist/index.d.ts +845 -974
  11. package/dist/index.mjs +1 -23
  12. package/dist/packem_shared/ACCENT-CotPTfv7.mjs +7 -0
  13. package/dist/packem_shared/AGENT_MODE_ENV-D8MvSwPE.mjs +1 -0
  14. package/dist/packem_shared/AGENT_RULES_DIR-Bd6JPtNa.mjs +1 -0
  15. package/dist/packem_shared/ALLOW_FORWARDED_ENV-BUndghJx.mjs +1 -0
  16. package/dist/packem_shared/BINDING_MANIFEST_VERSION-CfXEYG8e.mjs +1 -0
  17. package/dist/packem_shared/CLOUDFLARE_CLI_CONFIG_WARNING_ENV-BKMrOuXV.mjs +1 -0
  18. package/dist/packem_shared/CLOUDFLARE_DRIVER-CULavrYO.mjs +1 -0
  19. package/dist/packem_shared/CLOUDFLARE_TOOLCHAIN_VERSIONS-DV5E_f_q.mjs +1 -0
  20. package/dist/packem_shared/CODEGEN_ENV-CkUo3_GU.mjs +1 -0
  21. package/dist/packem_shared/COMPOSED_WORKER_ENTRY-Ciiba5g_.mjs +1 -0
  22. package/dist/packem_shared/DEFAULT_DEPLOY_TARGET-rR7buNQw.mjs +1 -0
  23. package/dist/packem_shared/DEFAULT_OBSERVABILITY-bN6UkTMx.mjs +1 -0
  24. package/dist/packem_shared/DEV_BINDINGS_FILE-C0ZN_XlP.mjs +4 -0
  25. package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-CqLorAxT.mjs +6 -0
  26. package/dist/packem_shared/DEV_WORKER_ENV_VALUE-2XFXmRrP.mjs +1 -0
  27. package/dist/packem_shared/GLOBAL_FETCH_STRICTLY_PUBLIC_FLAG-f8CnJha3.mjs +1 -0
  28. package/dist/packem_shared/HYPERDRIVE_PLACEHOLDER_ID-DZn1Fk4-.mjs +2 -0
  29. package/dist/packem_shared/LINKED_PROJECT_DIR-Ba5qPEwo.mjs +2 -0
  30. package/dist/packem_shared/LUNORA_EVENT_SOURCE-B9ZVohjO.mjs +1 -0
  31. package/dist/packem_shared/LUNORA_IGNORED_PATHS-U93uPxrW.mjs +19 -0
  32. package/dist/packem_shared/LUNORA_TAG-DQTGPqcJ.mjs +1 -0
  33. package/dist/packem_shared/LunoraReporter-f277GLNT.mjs +6 -0
  34. package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-38Plje8b.mjs +1 -0
  35. package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-BlERq9JI.mjs +1 -0
  36. package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-DnbYTTWX.mjs +1 -0
  37. package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-D4UcOP_t.mjs +1 -0
  38. package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-DXjL7k72.mjs +1 -0
  39. package/dist/packem_shared/SEED_ENDPOINT-2B56PN_H.mjs +1 -0
  40. package/dist/packem_shared/STUDIO_PATH-CTsEIa6_.mjs +1 -0
  41. package/dist/packem_shared/UNEXPORTED_CLASS_MARKER-mdcw5KDY.mjs +1 -0
  42. package/dist/packem_shared/WORKERS_CACHE_MIN_DATE-0k9ABJtF.mjs +1 -0
  43. package/dist/packem_shared/WRANGLER_FILES-UNW-xY5u.mjs +1 -0
  44. package/dist/packem_shared/acceptsConnection-DHhUYGjT.mjs +2 -0
  45. package/dist/packem_shared/addArgsFor-CYZKhNIo.mjs +1 -0
  46. package/dist/packem_shared/applyAdditiveEdit-CH0VhMJ2.mjs +6 -0
  47. package/dist/packem_shared/applyModify-DKP2l6S9.mjs +1 -0
  48. package/dist/packem_shared/applyStudioAssetCache-DHQEJuuv.mjs +1 -0
  49. package/dist/packem_shared/assertWranglerSatisfiesSchema-B4DcaiJY.mjs +3 -0
  50. package/dist/packem_shared/assetContentType-CUb5bpbI.mjs +1 -0
  51. package/dist/packem_shared/bindingsNeedingDatabase-6eD6Qtqf.mjs +3 -0
  52. package/dist/packem_shared/blockingFindingsMessage-BVbijPdn.mjs +1 -0
  53. package/dist/packem_shared/buildPackageSecretsBlock-BWV_VxqV.mjs +19 -0
  54. package/dist/packem_shared/celld-config-D-L6uskI.mjs +3 -0
  55. package/dist/packem_shared/classifyPolicyEdit-DJi9Fk8G.mjs +24 -0
  56. package/dist/packem_shared/createConfirm-D5mKTMHj.mjs +7 -0
  57. package/dist/packem_shared/createDiscoveryCache-npJI4uej.mjs +1 -0
  58. package/dist/packem_shared/deploy-driver.d-Cl96-c1l.d.mts +184 -0
  59. package/dist/packem_shared/deploy-driver.d-Cl96-c1l.d.ts +184 -0
  60. package/dist/packem_shared/describePreservedCrons-C5KPuPy3.mjs +1 -0
  61. package/dist/packem_shared/describeWithheld-CbyzZjZF.mjs +1 -0
  62. package/dist/packem_shared/detectFramework-Dfpvu6rD.mjs +1 -0
  63. package/dist/packem_shared/discover-info-DC2MrAIM.mjs +1 -0
  64. package/dist/packem_shared/discoverAgentInfo-pqFMJBtJ.mjs +1 -0
  65. package/dist/packem_shared/discoverContainerInfo-DzXr7Vm3.mjs +1 -0
  66. package/dist/packem_shared/discoverSchemaInfo-BBRlXZop.mjs +1 -0
  67. package/dist/packem_shared/discoverWorkflowInfo-zW7Tt0Tn.mjs +1 -0
  68. package/dist/packem_shared/guards-Buu_E7mP.mjs +1 -0
  69. package/dist/packem_shared/hasCloudflareCredentials-CNPVIVBb.mjs +1 -0
  70. package/dist/packem_shared/index.d-Cmx4jMFV.d.ts +270 -0
  71. package/dist/packem_shared/index.d-DkNi7r6E.d.mts +270 -0
  72. package/dist/packem_shared/infer-bindings.d-Dp1zxdUZ.d.mts +298 -0
  73. package/dist/packem_shared/infer-bindings.d-Dp1zxdUZ.d.ts +298 -0
  74. package/dist/packem_shared/inferLunoraBindings-CH8xwMCn.mjs +1 -0
  75. package/dist/packem_shared/interpretRemote-CcmGeGZ_.mjs +1 -0
  76. package/dist/packem_shared/lunora-manifest-DuH_Cmyu.mjs +6 -0
  77. package/dist/packem_shared/materializeServiceDevConfigs-k_oLCcBT.mjs +1 -0
  78. package/dist/packem_shared/mergeWranglerEnvironment-D5ekKj5x.mjs +1 -0
  79. package/dist/packem_shared/package-secrets-registry-BeheNwsP.mjs +1 -0
  80. package/dist/packem_shared/parseDevVariable-teAAahVD.mjs +1 -0
  81. package/dist/packem_shared/parseSchema-D1Wbr1qv.mjs +1 -0
  82. package/dist/packem_shared/policy-scaffold.d-D2H4_G01.d.mts +86 -0
  83. package/dist/packem_shared/policy-scaffold.d-D2H4_G01.d.ts +86 -0
  84. package/dist/packem_shared/process-tree-once-Ou4SfxKM.mjs +1 -0
  85. package/dist/packem_shared/readProjectDependencies-l3uhUKjo.mjs +1 -0
  86. package/dist/packem_shared/reconcile-services-DFqH4eMQ.mjs +1 -0
  87. package/dist/packem_shared/reconcileBindingsSafely-D9H8UIvK.mjs +1 -0
  88. package/dist/packem_shared/reconcileWranglerCompatibilityDate-hocXEuRA.mjs +1 -0
  89. package/dist/packem_shared/renderStudioHtml-ByowDtMl.mjs +15 -0
  90. package/dist/packem_shared/resolveSchemaDirectory-Ca5P6KuP.mjs +1 -0
  91. package/dist/packem_shared/runPostCodegenHook-Dx3yTsYZ.mjs +1 -0
  92. package/dist/packem_shared/scanWranglerVariablesForSecrets-BFTVje1q.mjs +1 -0
  93. package/dist/packem_shared/serveJsonHandler-Dv0EdCb9.mjs +1 -0
  94. package/dist/packem_shared/startCelldDevSession-BLFsd6jG.mjs +1 -0
  95. package/dist/packem_shared/streamContainerLogs-0nko1qpv.mjs +2 -0
  96. package/dist/packem_shared/validate-bindings-PVHSAU6M.mjs +1 -0
  97. package/dist/packem_shared/withTailConsumer-CF3pk_Ov.mjs +1 -0
  98. package/dist/packem_shared/worker-entry-checks-AIASCYl7.mjs +1 -0
  99. package/dist/packem_shared/wranglerCodegenInputs-CbisphsH.mjs +1 -0
  100. package/dist/packem_shared/wranglerToAlchemy-CBO2ucRm.mjs +6 -0
  101. package/dist/packem_shared/write-atomic-CY97nWi1.mjs +1 -0
  102. package/dist/studio-host/index.d.mts +320 -110
  103. package/dist/studio-host/index.d.ts +320 -110
  104. package/dist/studio-host/index.mjs +1 -7
  105. package/package.json +32 -7
  106. package/dist/packem_shared/ACCENT-DW1XJn8i.mjs +0 -40
  107. package/dist/packem_shared/AGENT_RULES_DIR-lcgC08aE.mjs +0 -40
  108. package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-dJPNTEnK.mjs +0 -37
  109. package/dist/packem_shared/LINKED_PROJECT_DIR-CXwXzV_C.mjs +0 -52
  110. package/dist/packem_shared/LUNORA_CONFIG_FILE-CtcIcB5-.mjs +0 -34
  111. package/dist/packem_shared/LUNORA_EVENT_SOURCE-D2fDeGB6.mjs +0 -86
  112. package/dist/packem_shared/LunoraReporter-Ci-bDCK9.mjs +0 -70
  113. package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-B8t_SdoZ.mjs +0 -70
  114. package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-CiC2IGKx.mjs +0 -103
  115. package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-BC7_e9Bz.mjs +0 -105
  116. package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-2YYyWJUq.mjs +0 -561
  117. package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-Df-Wrix-.mjs +0 -99
  118. package/dist/packem_shared/SEED_ENDPOINT-DVCjaGO-.mjs +0 -61
  119. package/dist/packem_shared/WRANGLER_FILES-DwSuC-Kn.mjs +0 -25
  120. package/dist/packem_shared/applyAdditiveEdit-C-snTFEV.mjs +0 -228
  121. package/dist/packem_shared/buildPackageSecretsBlock-BCHtfQ2A.mjs +0 -280
  122. package/dist/packem_shared/classifyPolicyEdit-BHeAqF8P.mjs +0 -99
  123. package/dist/packem_shared/createConfirm-fvpdgJ9s.mjs +0 -100
  124. package/dist/packem_shared/detectFramework-Br-BcPBq.mjs +0 -41
  125. package/dist/packem_shared/discoverContainerInfo-BXFs6Wav.mjs +0 -19
  126. package/dist/packem_shared/discoverSchemaInfo-BB-CKlTK.mjs +0 -25
  127. package/dist/packem_shared/discoverWorkflowInfo-CedvR0mn.mjs +0 -19
  128. package/dist/packem_shared/inferLunoraBindings-ByMwG-gH.mjs +0 -352
  129. package/dist/packem_shared/loadStudioAssets-Csk5RS4E.mjs +0 -28
  130. package/dist/packem_shared/parseDevVariable-CJiq2IwE.mjs +0 -30
  131. package/dist/packem_shared/parseSchema-DSeyktvG.mjs +0 -107
  132. package/dist/packem_shared/policy-scaffold.d-DCmwn7zQ.d.mts +0 -74
  133. package/dist/packem_shared/policy-scaffold.d-DCmwn7zQ.d.ts +0 -74
  134. package/dist/packem_shared/reconcileWranglerBindings-Cruwwx1M.mjs +0 -334
  135. package/dist/packem_shared/renderStudioHtml-449Ysn75.mjs +0 -37
  136. package/dist/packem_shared/serveJsonHandler-B4OLTGLS.mjs +0 -86
  137. package/dist/packem_shared/streamContainerLogs-BZ4cOZwH.mjs +0 -157
@@ -1,61 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { discoverSchema, schemaFromIr } from '@lunora/codegen';
3
- import { seedPlan } from '@lunora/seed';
4
- import { Project } from 'ts-morph';
5
- import { join } from 'node:path';
6
-
7
- const SEED_ENDPOINT = "/__lunora/seed";
8
- const MAX_SEED_ROWS = 1e3;
9
- const jsonReplacer = (_key, value) => {
10
- if (typeof value === "bigint") {
11
- return Number(value);
12
- }
13
- if (value instanceof ArrayBuffer) {
14
- return [...new Uint8Array(value)];
15
- }
16
- return value;
17
- };
18
- const clampCount = (count) => {
19
- if (typeof count !== "number" || !Number.isFinite(count)) {
20
- return 10;
21
- }
22
- return Math.min(Math.max(1, Math.floor(count)), MAX_SEED_ROWS);
23
- };
24
- const handleSeedRequest = (request) => {
25
- if (request.method !== "POST") {
26
- return { body: { error: "method-not-allowed", ok: false }, status: 405 };
27
- }
28
- const { body } = request;
29
- if (body === void 0 || typeof body !== "object") {
30
- return { body: { error: "invalid-request", ok: false }, status: 400 };
31
- }
32
- const { count, existingIds, seed, table } = body;
33
- if (typeof table !== "string" || table.length === 0) {
34
- return { body: { error: "missing-table", ok: false }, status: 400 };
35
- }
36
- const lunoraDirectory = request.schemaDirectory ?? "lunora";
37
- const schemaPath = join(request.projectRoot, lunoraDirectory, "schema.ts");
38
- if (!existsSync(schemaPath)) {
39
- return { body: { error: "schema-not-found", ok: false }, status: 404 };
40
- }
41
- const project = new Project({ skipAddingFilesFromTsConfig: true });
42
- const ir = discoverSchema(project, schemaPath);
43
- if (!ir.tables.some((candidate) => candidate.name === table)) {
44
- return { body: { error: "unknown-table", ok: false, table }, status: 404 };
45
- }
46
- const schema = schemaFromIr(ir);
47
- const plan = seedPlan(schema, {
48
- // Pass every sampled parent table as `existingIds` so the generator links
49
- // to live rows and never fabricates parents — matching the studio's
50
- // "existing rows are not affected, FKs point at what's there" semantics.
51
- existingIds: existingIds ?? {},
52
- defaultCount: clampCount(count),
53
- only: [table],
54
- seed: seed ?? 0
55
- });
56
- const rows = plan.find((entry) => entry.table === table)?.rows ?? [];
57
- const jsonSafeRows = JSON.parse(JSON.stringify(rows, jsonReplacer));
58
- return { body: { ok: true, rows: jsonSafeRows }, status: 200 };
59
- };
60
-
61
- export { SEED_ENDPOINT, handleSeedRequest };
@@ -1,25 +0,0 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { parse } from 'jsonc-parser';
3
- import { join } from 'node:path';
4
-
5
- const WRANGLER_FILES = ["wrangler.jsonc", "wrangler.json"];
6
- const findWranglerFile = (projectRoot) => {
7
- for (const candidate of WRANGLER_FILES) {
8
- const fullPath = join(projectRoot, candidate);
9
- if (existsSync(fullPath)) {
10
- return fullPath;
11
- }
12
- }
13
- return void 0;
14
- };
15
- const readWranglerJsonc = (wranglerPath) => {
16
- const text = readFileSync(wranglerPath, "utf8");
17
- const parseErrors = [];
18
- const value = parse(text, parseErrors, { allowTrailingComma: true });
19
- if (parseErrors.length > 0 || value === null || typeof value !== "object") {
20
- return { parsed: void 0, text };
21
- }
22
- return { parsed: value, text };
23
- };
24
-
25
- export { WRANGLER_FILES, findWranglerFile, readWranglerJsonc };
@@ -1,228 +0,0 @@
1
- import { Project, SyntaxKind } from 'ts-morph';
2
- import { collectCalls } from './parseSchema-DSeyktvG.mjs';
3
-
4
- const IDENTIFIER_PATTERN = /^[A-Za-z_$][\w$]*$/u;
5
- const VALIDATOR_METHODS = /* @__PURE__ */ new Set([
6
- "any",
7
- "array",
8
- "bigint",
9
- "boolean",
10
- "bytes",
11
- "date",
12
- "id",
13
- "literal",
14
- "null",
15
- "number",
16
- "object",
17
- "optional",
18
- "record",
19
- "storage",
20
- "string",
21
- "timestamp",
22
- "union"
23
- ]);
24
- const isValidatorExpression = (node) => {
25
- if (node.getKind() === SyntaxKind.ParenthesizedExpression) {
26
- return isValidatorExpression(node.asKindOrThrow(SyntaxKind.ParenthesizedExpression).getExpression());
27
- }
28
- if (node.getKind() !== SyntaxKind.CallExpression) {
29
- return false;
30
- }
31
- const call = node.asKindOrThrow(SyntaxKind.CallExpression);
32
- const callee = call.getExpression();
33
- if (callee.getKind() !== SyntaxKind.PropertyAccessExpression) {
34
- return false;
35
- }
36
- const access = callee.asKindOrThrow(SyntaxKind.PropertyAccessExpression);
37
- if (access.getExpression().getKind() !== SyntaxKind.Identifier || access.getExpression().getText() !== "v" || !VALIDATOR_METHODS.has(access.getName())) {
38
- return false;
39
- }
40
- return call.getArguments().every((argument) => isValidatorArgument(argument));
41
- };
42
- const isValidatorArgument = (node) => {
43
- const kind = node.getKind();
44
- if (kind === SyntaxKind.ParenthesizedExpression) {
45
- return isValidatorArgument(node.asKindOrThrow(SyntaxKind.ParenthesizedExpression).getExpression());
46
- }
47
- if (kind === SyntaxKind.StringLiteral || kind === SyntaxKind.NumericLiteral || kind === SyntaxKind.TrueKeyword || kind === SyntaxKind.FalseKeyword || kind === SyntaxKind.NullKeyword) {
48
- return true;
49
- }
50
- if (kind === SyntaxKind.PrefixUnaryExpression) {
51
- const unary = node.asKindOrThrow(SyntaxKind.PrefixUnaryExpression);
52
- return unary.getOperand().getKind() === SyntaxKind.NumericLiteral;
53
- }
54
- if (kind === SyntaxKind.ObjectLiteralExpression) {
55
- return node.asKindOrThrow(SyntaxKind.ObjectLiteralExpression).getProperties().every((property) => {
56
- if (property.getKind() !== SyntaxKind.PropertyAssignment) {
57
- return false;
58
- }
59
- const initializer = property.getInitializer();
60
- return initializer !== void 0 && isValidatorArgument(initializer);
61
- });
62
- }
63
- if (kind === SyntaxKind.ArrayLiteralExpression) {
64
- return node.asKindOrThrow(SyntaxKind.ArrayLiteralExpression).getElements().every((element) => isValidatorArgument(element));
65
- }
66
- return isValidatorExpression(node);
67
- };
68
- const isAllowedValidatorText = (validator) => {
69
- if (typeof validator !== "string" || validator.trim().length === 0) {
70
- return false;
71
- }
72
- const project = new Project({ compilerOptions: { allowJs: true }, useInMemoryFileSystem: true });
73
- const sourceFile = project.createSourceFile("validator.ts", `const __v = (${validator});`, { overwrite: true });
74
- if (project.getProgram().getSyntacticDiagnostics(sourceFile).length > 0) {
75
- return false;
76
- }
77
- if (sourceFile.getStatements().length !== 1) {
78
- return false;
79
- }
80
- const declaration = sourceFile.getVariableDeclaration("__v");
81
- const initializer = declaration?.getInitializer();
82
- return initializer !== void 0 && isValidatorExpression(initializer);
83
- };
84
- const ADDITIVE_KINDS = /* @__PURE__ */ new Set(["addIndex", "addOptionalColumn", "addTable"]);
85
- const classifyEdit = (edit) => ADDITIVE_KINDS.has(edit.kind) ? "additive" : "destructive";
86
- const isIdentifier = (value) => typeof value === "string" && IDENTIFIER_PATTERN.test(value);
87
- const validateAdditiveEdit = (edit) => {
88
- if (!isIdentifier(edit.table)) {
89
- return "invalid-identifier";
90
- }
91
- if (edit.kind === "addOptionalColumn") {
92
- if (!isIdentifier(edit.column)) {
93
- return "invalid-identifier";
94
- }
95
- if (!isAllowedValidatorText(edit.validator)) {
96
- return "invalid-validator";
97
- }
98
- }
99
- if (edit.kind === "addIndex") {
100
- if (!isIdentifier(edit.name)) {
101
- return "invalid-identifier";
102
- }
103
- if (!Array.isArray(edit.fields) || !edit.fields.every((field) => isIdentifier(field))) {
104
- return "invalid-identifier";
105
- }
106
- }
107
- return void 0;
108
- };
109
- const findTablesObject = (source) => {
110
- const project = new Project({ compilerOptions: { allowJs: true }, useInMemoryFileSystem: true });
111
- const sourceFile = project.createSourceFile("schema.ts", source, { overwrite: true });
112
- let defineSchemaCall;
113
- for (const call of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
114
- if (call.getExpression().getText() === "defineSchema") {
115
- defineSchemaCall = call;
116
- break;
117
- }
118
- }
119
- if (defineSchemaCall === void 0) {
120
- const aliased = sourceFile.getImportDeclarations().some((declaration) => declaration.getNamedImports().some((named) => named.getName() === "defineSchema" && named.getAliasNode() !== void 0));
121
- return { reason: aliased ? "aliased-define-schema" : "no-define-schema" };
122
- }
123
- const tablesArgument = defineSchemaCall.getArguments()[0];
124
- if (tablesArgument?.getKind() !== SyntaxKind.ObjectLiteralExpression) {
125
- return { reason: "non-object-argument" };
126
- }
127
- return { object: tablesArgument.asKindOrThrow(SyntaxKind.ObjectLiteralExpression), sourceFile };
128
- };
129
- const findTableProperty = (tablesObject, table) => {
130
- for (const property of tablesObject.getProperties()) {
131
- if (property.getKind() === SyntaxKind.PropertyAssignment && property.getNameNode().getText().replaceAll(/["']/gu, "") === table) {
132
- return property;
133
- }
134
- }
135
- return void 0;
136
- };
137
- const findDefineTableShape = (tableProperty) => {
138
- const defineTableCall = tableProperty.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "defineTable");
139
- const shape = defineTableCall?.getArguments()[0];
140
- return shape?.getKind() === SyntaxKind.ObjectLiteralExpression ? shape.asKindOrThrow(SyntaxKind.ObjectLiteralExpression) : void 0;
141
- };
142
- const applyAddTable = (tablesObject, edit) => {
143
- if (findTableProperty(tablesObject, edit.table) !== void 0) {
144
- return "duplicate-table";
145
- }
146
- tablesObject.addPropertyAssignment({
147
- initializer: `defineTable({
148
- // Add your column validators here.
149
- // Example:
150
- // text: v.string(),
151
- // createdAt: v.number(),
152
- })`,
153
- name: edit.table
154
- });
155
- return void 0;
156
- };
157
- const applyAddOptionalColumn = (tablesObject, edit) => {
158
- const tableProperty = findTableProperty(tablesObject, edit.table);
159
- if (tableProperty === void 0) {
160
- return "unknown-table";
161
- }
162
- const shape = findDefineTableShape(tableProperty);
163
- if (shape === void 0) {
164
- return "unknown-table";
165
- }
166
- const exists = shape.getProperties().some(
167
- (property) => property.getKind() === SyntaxKind.PropertyAssignment && property.getNameNode().getText().replaceAll(/["']/gu, "") === edit.column
168
- );
169
- if (exists) {
170
- return "duplicate-column";
171
- }
172
- shape.addPropertyAssignment({ initializer: `v.optional(${edit.validator})`, name: edit.column });
173
- return void 0;
174
- };
175
- const applyAddIndex = (tableProperty, edit) => {
176
- if (tableProperty === void 0) {
177
- return "unknown-table";
178
- }
179
- const initializer = tableProperty.getInitializer();
180
- if (initializer === void 0) {
181
- return "unknown-table";
182
- }
183
- const duplicate = collectCalls(initializer).some((call) => {
184
- const expression = call.getExpression();
185
- if (expression.getKind() !== SyntaxKind.PropertyAccessExpression) {
186
- return false;
187
- }
188
- const access = expression.asKindOrThrow(SyntaxKind.PropertyAccessExpression);
189
- const [nameArgument] = call.getArguments();
190
- return access.getName() === "index" && nameArgument?.getKind() === SyntaxKind.StringLiteral && nameArgument.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralText() === edit.name;
191
- });
192
- if (duplicate) {
193
- return "duplicate-index";
194
- }
195
- const fields = edit.fields.map((field) => JSON.stringify(field)).join(", ");
196
- const options = edit.unique === true ? ", { unique: true }" : "";
197
- tableProperty.setInitializer(`${initializer.getText()}.index(${JSON.stringify(edit.name)}, [${fields}]${options})`);
198
- return void 0;
199
- };
200
- const applyAdditiveEdit = (source, edit) => {
201
- if (classifyEdit(edit) === "destructive") {
202
- return { ok: false, reason: "destructive" };
203
- }
204
- const additive = edit;
205
- const invalid = validateAdditiveEdit(additive);
206
- if (invalid !== void 0) {
207
- return { ok: false, reason: invalid };
208
- }
209
- const located = findTablesObject(source);
210
- if ("reason" in located) {
211
- return { ok: false, reason: located.reason };
212
- }
213
- const { object: tablesObject, sourceFile } = located;
214
- let failure;
215
- if (additive.kind === "addTable") {
216
- failure = applyAddTable(tablesObject, additive);
217
- } else if (additive.kind === "addOptionalColumn") {
218
- failure = applyAddOptionalColumn(tablesObject, additive);
219
- } else {
220
- failure = applyAddIndex(findTableProperty(tablesObject, additive.table), additive);
221
- }
222
- if (failure !== void 0) {
223
- return { ok: false, reason: failure };
224
- }
225
- return { ok: true, text: sourceFile.getFullText() };
226
- };
227
-
228
- export { applyAdditiveEdit, classifyEdit };
@@ -1,280 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- import { existsSync, readFileSync, writeFileSync, renameSync, rmSync, statSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { DEV_VARS_FILE, DEV_VARS_EXAMPLE_FILE, splitDevVariableLine, parseDevVariableEntries, DEV_VARS_NEWLINE, unquoteDevVariable } from './DEV_VARS_EXAMPLE_FILE-dJPNTEnK.mjs';
5
- import { CORE_SECRETS, PACKAGE_SECRETS_REGISTRY, secretsForPackages } from './PACKAGE_SECRETS_REGISTRY-B8t_SdoZ.mjs';
6
-
7
- const requiredSecrets = (packageNames) => [...CORE_SECRETS, ...secretsForPackages(packageNames)];
8
- const SECRET_BYTES = 32;
9
- const SECRET_KEY = /(?:KEY|PASSWORD|SECRET|TOKEN)$/u;
10
- const PLACEHOLDER_MARKERS = [
11
- "replace",
12
- "openssl",
13
- "changeme",
14
- "change-me",
15
- "change_me",
16
- "change-this",
17
- "change_this",
18
- "your-",
19
- "your_",
20
- "example",
21
- "placeholder",
22
- "todo",
23
- "fill-me",
24
- "fill_me",
25
- "fill-in",
26
- "fill_in",
27
- "xxx"
28
- ];
29
- const REGEXP_SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/gu;
30
- const MARKER_ENDS_ALPHANUMERIC = /[a-z0-9]$/u;
31
- const isPlaceholderValue = (value) => {
32
- const normalised = value.trim().toLowerCase();
33
- if (normalised === "") {
34
- return true;
35
- }
36
- if (normalised.startsWith("<") && normalised.endsWith(">")) {
37
- return true;
38
- }
39
- return PLACEHOLDER_MARKERS.some((marker) => {
40
- const escaped = marker.replaceAll(REGEXP_SPECIAL_CHARS, String.raw`\$&`);
41
- const needsTrailingBoundary = MARKER_ENDS_ALPHANUMERIC.test(marker);
42
- const pattern = needsTrailingBoundary ? `(^|[^a-z0-9])${escaped}([^a-z0-9]|$)` : `(^|[^a-z0-9])${escaped}`;
43
- return new RegExp(pattern, "u").test(normalised);
44
- });
45
- };
46
- const isPlaceholder = (rawValue) => isPlaceholderValue(unquoteDevVariable(rawValue.trim()));
47
- const defaultRandomHex = (bytes) => randomBytes(bytes).toString("hex");
48
- const generatedSecretFor = (key, rawValue, randomHex) => SECRET_KEY.test(key) && isPlaceholder(rawValue) ? randomHex(SECRET_BYTES) : void 0;
49
- const PROVIDER_SECRET_KEYS = new Set(
50
- [...CORE_SECRETS, ...Object.values(PACKAGE_SECRETS_REGISTRY).flat()].filter((entry) => SECRET_KEY.test(entry.key) && entry.placeholderValue.startsWith("<")).map((entry) => entry.key)
51
- );
52
- const isMintableSecretKey = (key) => SECRET_KEY.test(key) && !PROVIDER_SECRET_KEYS.has(key);
53
- const generateSecretValue = (randomHex = defaultRandomHex) => randomHex(SECRET_BYTES);
54
- const planDevVariablesScaffold = (input) => {
55
- if (input.devVarsExists) {
56
- return { status: "exists" };
57
- }
58
- if (input.exampleContent === void 0) {
59
- return { status: "no-example" };
60
- }
61
- const randomHex = input.randomHex ?? defaultRandomHex;
62
- const generatedKeys = [];
63
- const lines = input.exampleContent.split(DEV_VARS_NEWLINE).map((line) => {
64
- const parsed = splitDevVariableLine(line);
65
- const secret = parsed ? generatedSecretFor(parsed.key, parsed.value, randomHex) : void 0;
66
- if (!parsed || secret === void 0) {
67
- return line;
68
- }
69
- generatedKeys.push(parsed.key);
70
- return `${parsed.key}="${secret}"`;
71
- });
72
- return { content: lines.join("\n"), generatedKeys, status: "generate" };
73
- };
74
- const planDevVariablesAugment = (input) => {
75
- const randomHex = input.randomHex ?? defaultRandomHex;
76
- const present = new Set(parseDevVariableEntries(input.existingContent).map((entry) => entry.key));
77
- const additions = [];
78
- const generatedKeys = [];
79
- const missingKeys = [];
80
- for (const line of input.exampleContent.split(DEV_VARS_NEWLINE)) {
81
- const parsed = splitDevVariableLine(line);
82
- if (!parsed || present.has(parsed.key)) {
83
- continue;
84
- }
85
- const secret = generatedSecretFor(parsed.key, parsed.value, randomHex);
86
- missingKeys.push(parsed.key);
87
- if (secret === void 0) {
88
- additions.push(`${parsed.key}="${unquoteDevVariable(parsed.value)}"`);
89
- } else {
90
- generatedKeys.push(parsed.key);
91
- additions.push(`${parsed.key}="${secret}"`);
92
- }
93
- }
94
- return { additions, generatedKeys, missingKeys };
95
- };
96
- const generatedSuffix = (keys) => keys.length > 0 ? ` (generated ${keys.join(", ")})` : "";
97
- const atomicCreateDevVariables = (path, content) => {
98
- const temporaryPath = `${path}.tmp-${String(process.pid)}`;
99
- try {
100
- writeFileSync(temporaryPath, content, { encoding: "utf8", flag: "wx", mode: 384 });
101
- renameSync(temporaryPath, path);
102
- } catch (error) {
103
- rmSync(temporaryPath, { force: true });
104
- throw error;
105
- }
106
- };
107
- const APPEND_MAX_ATTEMPTS = 5;
108
- const fingerprintOf = (path) => {
109
- try {
110
- const stats = statSync(path);
111
- return { mtimeMs: stats.mtimeMs, size: stats.size };
112
- } catch {
113
- return void 0;
114
- }
115
- };
116
- const sameFingerprint = (a, b) => {
117
- if (a === void 0 || b === void 0) {
118
- return false;
119
- }
120
- return a.mtimeMs === b.mtimeMs && a.size === b.size;
121
- };
122
- const appendDevVariables = (path, buildAdditions) => {
123
- for (let attempt = 0; attempt < APPEND_MAX_ATTEMPTS; attempt += 1) {
124
- const beforeFingerprint = fingerprintOf(path);
125
- const existing = readFileSync(path, "utf8");
126
- const additions = buildAdditions(existing);
127
- if (additions.length === 0) {
128
- return [];
129
- }
130
- const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
131
- const content = `${existing}${separator}${additions.join("\n")}
132
- `;
133
- const temporaryPath = `${path}.tmp-${String(process.pid)}-${randomBytes(6).toString("hex")}`;
134
- try {
135
- writeFileSync(temporaryPath, content, { encoding: "utf8", mode: 384 });
136
- const beforeRenameFingerprint = fingerprintOf(path);
137
- if (!sameFingerprint(beforeFingerprint, beforeRenameFingerprint)) {
138
- rmSync(temporaryPath, { force: true });
139
- continue;
140
- }
141
- renameSync(temporaryPath, path);
142
- return additions;
143
- } catch (error) {
144
- rmSync(temporaryPath, { force: true });
145
- throw error;
146
- }
147
- }
148
- throw new Error(`Failed to append to ${path} after ${String(APPEND_MAX_ATTEMPTS)} attempts — a concurrent writer kept winning the race.`);
149
- };
150
- const ensureDevVariables = async (deps) => {
151
- const devVariablesPath = join(deps.cwd, DEV_VARS_FILE);
152
- const examplePath = join(deps.cwd, DEV_VARS_EXAMPLE_FILE);
153
- if (!existsSync(examplePath)) {
154
- return { addedKeys: [], generatedKeys: [], status: "no-example" };
155
- }
156
- const exampleContent = readFileSync(examplePath, "utf8");
157
- if (!existsSync(devVariablesPath)) {
158
- const plan = planDevVariablesScaffold({ devVarsExists: false, exampleContent, randomHex: deps.randomHex });
159
- if (plan.status !== "generate") {
160
- return { addedKeys: [], generatedKeys: [], status: "no-example" };
161
- }
162
- const proceed2 = deps.yes === true || await deps.confirm(`No ${DEV_VARS_FILE} found. Generate it from ${DEV_VARS_EXAMPLE_FILE} (secrets auto-filled)?`);
163
- if (!proceed2) {
164
- deps.info(`Skipped — copy ${DEV_VARS_EXAMPLE_FILE} to ${DEV_VARS_FILE} and fill it in when you're ready.`);
165
- return { addedKeys: [], generatedKeys: [], status: "declined" };
166
- }
167
- if (existsSync(devVariablesPath)) {
168
- return { addedKeys: [], generatedKeys: [], status: "skipped-exists" };
169
- }
170
- atomicCreateDevVariables(devVariablesPath, plan.content);
171
- deps.info(`Created ${DEV_VARS_FILE}${generatedSuffix(plan.generatedKeys)}.`);
172
- return { addedKeys: [], generatedKeys: plan.generatedKeys, status: "generated" };
173
- }
174
- const augment = planDevVariablesAugment({ existingContent: readFileSync(devVariablesPath, "utf8"), exampleContent, randomHex: deps.randomHex });
175
- if (augment.missingKeys.length === 0) {
176
- return { addedKeys: [], generatedKeys: [], status: "exists" };
177
- }
178
- const list = augment.missingKeys.join(", ");
179
- const proceed = deps.yes === true || await deps.confirm(`${DEV_VARS_FILE} is missing ${String(augment.missingKeys.length)} key(s) from ${DEV_VARS_EXAMPLE_FILE} (${list}). Add them?`);
180
- if (!proceed) {
181
- deps.info(`Skipped — add ${list} to ${DEV_VARS_FILE} when you're ready.`);
182
- return { addedKeys: [], generatedKeys: [], status: "declined" };
183
- }
184
- const written = appendDevVariables(
185
- devVariablesPath,
186
- (currentContent) => planDevVariablesAugment({ existingContent: currentContent, exampleContent, randomHex: deps.randomHex }).additions
187
- );
188
- const writtenKeys = written.map((line) => splitDevVariableLine(line)?.key).filter((key) => key !== void 0);
189
- if (writtenKeys.length === 0) {
190
- return { addedKeys: [], generatedKeys: [], status: "exists" };
191
- }
192
- const writtenGeneratedKeys = augment.generatedKeys.filter((key) => writtenKeys.includes(key));
193
- deps.info(`Updated ${DEV_VARS_FILE} — added ${writtenKeys.join(", ")}${generatedSuffix(writtenGeneratedKeys)}.`);
194
- return { addedKeys: writtenKeys, generatedKeys: writtenGeneratedKeys, status: "augmented" };
195
- };
196
- const secretEntryBlock = (entry) => {
197
- const lines = [`# ${entry.description}`, `# Docs: ${entry.docsUrl}`, `${entry.key}="${entry.placeholderValue}"`];
198
- return lines.join("\n");
199
- };
200
- const buildPackageSecretsBlock = (packageNames, existingKeys) => {
201
- const entries = requiredSecrets(packageNames).filter((entry) => !existingKeys.has(entry.key));
202
- if (entries.length === 0) {
203
- return "";
204
- }
205
- return entries.map((entry) => secretEntryBlock(entry)).join("\n\n");
206
- };
207
- const ensureDevVariablesExample = (cwd, packageNames) => {
208
- const examplePath = join(cwd, DEV_VARS_EXAMPLE_FILE);
209
- const existing = existsSync(examplePath) ? readFileSync(examplePath, "utf8") : "";
210
- const existingKeys = new Set(parseDevVariableEntries(existing).map((entry) => entry.key));
211
- const block = buildPackageSecretsBlock(packageNames, existingKeys);
212
- if (block === "") {
213
- return [];
214
- }
215
- const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
216
- const newContent = `${existing}${separator}
217
- ${block}
218
- `;
219
- const temporaryPath = `${examplePath}.tmp-${String(process.pid)}`;
220
- try {
221
- writeFileSync(temporaryPath, newContent, { encoding: "utf8" });
222
- renameSync(temporaryPath, examplePath);
223
- } catch (error) {
224
- rmSync(temporaryPath, { force: true });
225
- throw error;
226
- }
227
- return requiredSecrets(packageNames).filter((entry) => !existingKeys.has(entry.key)).map((entry) => entry.key);
228
- };
229
- const planDevSecretsFill = (input) => {
230
- const randomHex = input.randomHex ?? defaultRandomHex;
231
- const filledKeys = [];
232
- const lines = input.existingContent.split(DEV_VARS_NEWLINE).map((line) => {
233
- const parsed = splitDevVariableLine(line);
234
- const secret = parsed ? generatedSecretFor(parsed.key, parsed.value, randomHex) : void 0;
235
- if (!parsed || secret === void 0) {
236
- return line;
237
- }
238
- filledKeys.push(parsed.key);
239
- return `${parsed.key}="${secret}"`;
240
- });
241
- const present = new Set(parseDevVariableEntries(input.existingContent).map((entry) => entry.key));
242
- const addedKeys = [];
243
- const additions = [];
244
- for (const entry of CORE_SECRETS) {
245
- if (present.has(entry.key)) {
246
- continue;
247
- }
248
- addedKeys.push(entry.key);
249
- additions.push(`# ${entry.description}`, `${entry.key}="${randomHex(SECRET_BYTES)}"`);
250
- }
251
- const body = lines.join("\n");
252
- if (additions.length === 0) {
253
- return { addedKeys, content: body, filledKeys };
254
- }
255
- const separator = body === "" || body.endsWith("\n") ? "" : "\n";
256
- return { addedKeys, content: `${body}${separator}${additions.join("\n")}
257
- `, filledKeys };
258
- };
259
- const fillDevSecrets = (deps) => {
260
- const devVariablesPath = join(deps.cwd, DEV_VARS_FILE);
261
- const exists = existsSync(devVariablesPath);
262
- const existingContent = exists ? readFileSync(devVariablesPath, "utf8") : "";
263
- const plan = planDevSecretsFill({ existingContent, randomHex: deps.randomHex });
264
- if (plan.filledKeys.length === 0 && plan.addedKeys.length === 0) {
265
- return { addedKeys: [], filledKeys: [], status: "unchanged" };
266
- }
267
- const temporaryPath = `${devVariablesPath}.tmp-${String(process.pid)}`;
268
- try {
269
- writeFileSync(temporaryPath, plan.content, { encoding: "utf8", mode: 384 });
270
- renameSync(temporaryPath, devVariablesPath);
271
- } catch (error) {
272
- rmSync(temporaryPath, { force: true });
273
- throw error;
274
- }
275
- const generated = [...plan.filledKeys, ...plan.addedKeys];
276
- deps.info?.(`Generated ${String(generated.length)} dev secret(s) in ${DEV_VARS_FILE}: ${generated.join(", ")}`);
277
- return { addedKeys: plan.addedKeys, filledKeys: plan.filledKeys, status: exists ? "filled" : "created" };
278
- };
279
-
280
- export { buildPackageSecretsBlock, ensureDevVariables, ensureDevVariablesExample as ensureDevVarsExample, fillDevSecrets, generateSecretValue, isMintableSecretKey, isPlaceholderValue, planDevSecretsFill, planDevVariablesAugment, planDevVariablesScaffold, requiredSecrets };