@xylex-group/athena 3.0.2 → 3.0.3
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/README.md +1 -1
- package/dist/billing.cjs +1 -1
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.js +1 -1
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +909 -13
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +910 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +840 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +841 -11
- package/dist/index.js.map +1 -1
- package/dist/{module-CkUM6v58.d.ts → module-BruTcxe0.d.ts} +1 -1
- package/dist/{module-CB25egcO.d.cts → module-CPG3ULxQ.d.cts} +1 -1
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +1 -1
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.js +1 -1
- package/dist/next/server.js.map +1 -1
- package/dist/{pipeline-D4W-Cc-A.d.cts → pipeline-CIzV9f7b.d.cts} +1 -1
- package/dist/{pipeline-B8aN2EHe.d.ts → pipeline-DNlc8Ayn.d.ts} +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/{types-BaAMXCqK.d.ts → types-D6tZ9aoq.d.ts} +34 -1
- package/dist/{types-BBm-kEBL.d.cts → types-DFr2cL1N.d.cts} +34 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2009,7 +2009,7 @@ function buildAthenaGatewayUrl(baseUrl, path) {
|
|
|
2009
2009
|
|
|
2010
2010
|
// package.json
|
|
2011
2011
|
var package_default = {
|
|
2012
|
-
version: "3.0.
|
|
2012
|
+
version: "3.0.3"
|
|
2013
2013
|
};
|
|
2014
2014
|
|
|
2015
2015
|
// src/sdk-version.ts
|
|
@@ -11719,6 +11719,12 @@ var ATHENA_DIRECT_TARGETS = {
|
|
|
11719
11719
|
};
|
|
11720
11720
|
var DEFAULT_OUTPUT_FORMAT = "table-builder";
|
|
11721
11721
|
var DEFAULT_OUTPUT_PRESET = "athena-direct";
|
|
11722
|
+
var DEFAULT_ARTIFACT_WRITE_POLICY = "merge";
|
|
11723
|
+
var ARTIFACT_WRITE_POLICIES = /* @__PURE__ */ new Set([
|
|
11724
|
+
"merge",
|
|
11725
|
+
"skip",
|
|
11726
|
+
"overwrite"
|
|
11727
|
+
]);
|
|
11722
11728
|
var DEFAULT_NAMING = {
|
|
11723
11729
|
modelType: "pascal",
|
|
11724
11730
|
modelConst: "camel",
|
|
@@ -11998,6 +12004,23 @@ function normalizeFilterConfig(input) {
|
|
|
11998
12004
|
excludeTables: normalizeTableSelection(input?.excludeTables)
|
|
11999
12005
|
};
|
|
12000
12006
|
}
|
|
12007
|
+
function normalizeArtifactWritePolicy(value, fieldName) {
|
|
12008
|
+
if (value === void 0 || value === null || value === "") {
|
|
12009
|
+
return DEFAULT_ARTIFACT_WRITE_POLICY;
|
|
12010
|
+
}
|
|
12011
|
+
if (typeof value === "string" && ARTIFACT_WRITE_POLICIES.has(value)) {
|
|
12012
|
+
return value;
|
|
12013
|
+
}
|
|
12014
|
+
throw new Error(
|
|
12015
|
+
`Invalid output.artifactWrite.${fieldName}: expected one of merge | skip | overwrite, received ${JSON.stringify(value)}.`
|
|
12016
|
+
);
|
|
12017
|
+
}
|
|
12018
|
+
function normalizeArtifactWriteConfig(input) {
|
|
12019
|
+
return {
|
|
12020
|
+
database: normalizeArtifactWritePolicy(input?.database, "database"),
|
|
12021
|
+
registry: normalizeArtifactWritePolicy(input?.registry, "registry")
|
|
12022
|
+
};
|
|
12023
|
+
}
|
|
12001
12024
|
function normalizeOutputConfig(output) {
|
|
12002
12025
|
const preset = output?.preset ?? DEFAULT_OUTPUT_PRESET;
|
|
12003
12026
|
return {
|
|
@@ -12009,7 +12032,8 @@ function normalizeOutputConfig(output) {
|
|
|
12009
12032
|
},
|
|
12010
12033
|
placeholderMap: {
|
|
12011
12034
|
...output?.placeholderMap ?? {}
|
|
12012
|
-
}
|
|
12035
|
+
},
|
|
12036
|
+
artifactWrite: normalizeArtifactWriteConfig(output?.artifactWrite)
|
|
12013
12037
|
};
|
|
12014
12038
|
}
|
|
12015
12039
|
function normalizeProviderConfig(provider) {
|
|
@@ -13270,9 +13294,764 @@ function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
|
13270
13294
|
}
|
|
13271
13295
|
throw new Error(`Unsupported generator provider kind: ${providerConfig.kind ?? "unknown"}`);
|
|
13272
13296
|
}
|
|
13273
|
-
|
|
13274
|
-
|
|
13297
|
+
|
|
13298
|
+
// src/generator/artifact-merge.ts
|
|
13299
|
+
var IMPORT_RE = /^import\s+(?:type\s+)?(?:\{([^}]*)\}|([A-Za-z_$][\w$]*))\s+from\s+(['"])([^'"]+)\3\s*;?\s*$/gm;
|
|
13300
|
+
var DEFINE_EXPORT_RE = /export\s+const\s+([A-Za-z_$][\w$]*)\s*=\s*(define(?:Database|Registry))\s*\(\s*\{/g;
|
|
13301
|
+
var META_EXPORT_RE = /export\s+const\s+__athena_schema_meta\s*=\s*\{/g;
|
|
13302
|
+
var KNOWN_META_KEYS = /* @__PURE__ */ new Set([
|
|
13303
|
+
"schemaVersion",
|
|
13304
|
+
"generatedAt",
|
|
13305
|
+
"database",
|
|
13306
|
+
"outputPreset",
|
|
13307
|
+
"outputFormat"
|
|
13308
|
+
]);
|
|
13309
|
+
function detectNewline(source) {
|
|
13310
|
+
return source.includes("\r\n") ? "\r\n" : "\n";
|
|
13311
|
+
}
|
|
13312
|
+
function detectStyle(source) {
|
|
13313
|
+
const newline = detectNewline(source);
|
|
13314
|
+
const single = (source.match(/'/g) ?? []).length;
|
|
13315
|
+
const double = (source.match(/"/g) ?? []).length;
|
|
13316
|
+
const quote = double > single ? '"' : "'";
|
|
13317
|
+
const importLines = source.split(/\r?\n/).filter((line) => line.trimStart().startsWith("import "));
|
|
13318
|
+
const semicolons = importLines.length > 0 ? importLines.filter((line) => line.trimEnd().endsWith(";")).length >= importLines.length / 2 : false;
|
|
13319
|
+
const objectLines = source.split(/\r?\n/).map((line) => line.trim()).filter((line) => /^[A-Za-z0-9_'"]+\s*:\s*.+/.test(line));
|
|
13320
|
+
const trailingComma = objectLines.length > 0 ? objectLines.filter((line) => line.endsWith(",")).length >= Math.ceil(objectLines.length / 2) : true;
|
|
13321
|
+
const indentMatch = source.match(/\n([ \t]+)\S/);
|
|
13322
|
+
const indent = indentMatch?.[1] ?? " ";
|
|
13323
|
+
return { quote, semicolons, trailingComma, indent, newline };
|
|
13324
|
+
}
|
|
13325
|
+
function quoteString(value, quote) {
|
|
13326
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(new RegExp(quote, "g"), `\\${quote}`);
|
|
13327
|
+
return `${quote}${escaped}${quote}`;
|
|
13328
|
+
}
|
|
13329
|
+
function parseNamedImports(source) {
|
|
13330
|
+
const imports = [];
|
|
13331
|
+
IMPORT_RE.lastIndex = 0;
|
|
13332
|
+
let match;
|
|
13333
|
+
while ((match = IMPORT_RE.exec(source)) !== null) {
|
|
13334
|
+
const named = match[1];
|
|
13335
|
+
const defaultName = match[2];
|
|
13336
|
+
const module = match[4];
|
|
13337
|
+
const names = named ? named.split(",").map((part) => part.trim()).filter(Boolean).map((part) => {
|
|
13338
|
+
const alias = part.split(/\s+as\s+/);
|
|
13339
|
+
return (alias[1] ?? alias[0]).trim();
|
|
13340
|
+
}) : defaultName ? [defaultName] : [];
|
|
13341
|
+
imports.push({
|
|
13342
|
+
names,
|
|
13343
|
+
module,
|
|
13344
|
+
raw: match[0],
|
|
13345
|
+
start: match.index,
|
|
13346
|
+
end: match.index + match[0].length
|
|
13347
|
+
});
|
|
13348
|
+
}
|
|
13349
|
+
return imports;
|
|
13350
|
+
}
|
|
13351
|
+
function findMatchingBrace(source, openIndex) {
|
|
13352
|
+
let depth = 0;
|
|
13353
|
+
let inSingle = false;
|
|
13354
|
+
let inDouble = false;
|
|
13355
|
+
let inTemplate = false;
|
|
13356
|
+
let escaped = false;
|
|
13357
|
+
for (let i = openIndex; i < source.length; i += 1) {
|
|
13358
|
+
const ch = source[i];
|
|
13359
|
+
if (escaped) {
|
|
13360
|
+
escaped = false;
|
|
13361
|
+
continue;
|
|
13362
|
+
}
|
|
13363
|
+
if (ch === "\\" && (inSingle || inDouble || inTemplate)) {
|
|
13364
|
+
escaped = true;
|
|
13365
|
+
continue;
|
|
13366
|
+
}
|
|
13367
|
+
if (!inDouble && !inTemplate && ch === "'") {
|
|
13368
|
+
inSingle = !inSingle;
|
|
13369
|
+
continue;
|
|
13370
|
+
}
|
|
13371
|
+
if (!inSingle && !inTemplate && ch === '"') {
|
|
13372
|
+
inDouble = !inDouble;
|
|
13373
|
+
continue;
|
|
13374
|
+
}
|
|
13375
|
+
if (!inSingle && !inDouble && ch === "`") {
|
|
13376
|
+
inTemplate = !inTemplate;
|
|
13377
|
+
continue;
|
|
13378
|
+
}
|
|
13379
|
+
if (inSingle || inDouble || inTemplate) {
|
|
13380
|
+
continue;
|
|
13381
|
+
}
|
|
13382
|
+
if (ch === "{") {
|
|
13383
|
+
depth += 1;
|
|
13384
|
+
} else if (ch === "}") {
|
|
13385
|
+
depth -= 1;
|
|
13386
|
+
if (depth === 0) {
|
|
13387
|
+
return i;
|
|
13388
|
+
}
|
|
13389
|
+
}
|
|
13390
|
+
}
|
|
13391
|
+
return -1;
|
|
13392
|
+
}
|
|
13393
|
+
function parseObjectEntries(body) {
|
|
13394
|
+
const entries = [];
|
|
13395
|
+
const lines = body.split(/\r?\n/);
|
|
13396
|
+
for (const line of lines) {
|
|
13397
|
+
const trimmed = line.trim();
|
|
13398
|
+
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("/*")) {
|
|
13399
|
+
continue;
|
|
13400
|
+
}
|
|
13401
|
+
const withoutComma = trimmed.endsWith(",") ? trimmed.slice(0, -1).trimEnd() : trimmed;
|
|
13402
|
+
const match = withoutComma.match(/^([A-Za-z_$][\w$]*|['"][^'"]+['"])\s*:\s*(.+)$/);
|
|
13403
|
+
if (!match) {
|
|
13404
|
+
continue;
|
|
13405
|
+
}
|
|
13406
|
+
const keyRaw = match[1];
|
|
13407
|
+
const key = keyRaw.startsWith("'") || keyRaw.startsWith('"') ? keyRaw.slice(1, -1) : keyRaw;
|
|
13408
|
+
entries.push({
|
|
13409
|
+
key,
|
|
13410
|
+
value: match[2].trim(),
|
|
13411
|
+
raw: trimmed
|
|
13412
|
+
});
|
|
13413
|
+
}
|
|
13414
|
+
return entries;
|
|
13415
|
+
}
|
|
13416
|
+
function parseDefineBlocks(source) {
|
|
13417
|
+
const blocks = [];
|
|
13418
|
+
DEFINE_EXPORT_RE.lastIndex = 0;
|
|
13419
|
+
let match;
|
|
13420
|
+
while ((match = DEFINE_EXPORT_RE.exec(source)) !== null) {
|
|
13421
|
+
const exportName = match[1];
|
|
13422
|
+
const callName = match[2];
|
|
13423
|
+
const openBrace = match.index + match[0].lastIndexOf("{");
|
|
13424
|
+
const closeBrace = findMatchingBrace(source, openBrace);
|
|
13425
|
+
if (closeBrace < 0) {
|
|
13426
|
+
continue;
|
|
13427
|
+
}
|
|
13428
|
+
const body = source.slice(openBrace + 1, closeBrace);
|
|
13429
|
+
const fullEnd = (() => {
|
|
13430
|
+
let i = closeBrace + 1;
|
|
13431
|
+
while (i < source.length && /\s/.test(source[i])) i += 1;
|
|
13432
|
+
if (source[i] === ")") i += 1;
|
|
13433
|
+
while (i < source.length && /\s/.test(source[i])) i += 1;
|
|
13434
|
+
if (source[i] === ";") i += 1;
|
|
13435
|
+
return i;
|
|
13436
|
+
})();
|
|
13437
|
+
blocks.push({
|
|
13438
|
+
kind: callName === "defineDatabase" ? "database" : "registry",
|
|
13439
|
+
exportName,
|
|
13440
|
+
callName,
|
|
13441
|
+
entries: parseObjectEntries(body),
|
|
13442
|
+
bodyStart: openBrace + 1,
|
|
13443
|
+
bodyEnd: closeBrace,
|
|
13444
|
+
fullStart: match.index,
|
|
13445
|
+
fullEnd,
|
|
13446
|
+
raw: source.slice(match.index, fullEnd)
|
|
13447
|
+
});
|
|
13448
|
+
}
|
|
13449
|
+
return blocks;
|
|
13450
|
+
}
|
|
13451
|
+
function parseMetaBlock(source) {
|
|
13452
|
+
META_EXPORT_RE.lastIndex = 0;
|
|
13453
|
+
const match = META_EXPORT_RE.exec(source);
|
|
13454
|
+
if (!match) {
|
|
13455
|
+
return void 0;
|
|
13456
|
+
}
|
|
13457
|
+
const openBrace = match.index + match[0].lastIndexOf("{");
|
|
13458
|
+
const closeBrace = findMatchingBrace(source, openBrace);
|
|
13459
|
+
if (closeBrace < 0) {
|
|
13460
|
+
return void 0;
|
|
13461
|
+
}
|
|
13462
|
+
let fullEnd = closeBrace + 1;
|
|
13463
|
+
const after = source.slice(fullEnd);
|
|
13464
|
+
const asConst = after.match(/^\s*as\s+const\s*;?/);
|
|
13465
|
+
if (asConst) {
|
|
13466
|
+
fullEnd += asConst[0].length;
|
|
13467
|
+
} else if (source[fullEnd] === ";") {
|
|
13468
|
+
fullEnd += 1;
|
|
13469
|
+
}
|
|
13470
|
+
return {
|
|
13471
|
+
entries: parseObjectEntries(source.slice(openBrace + 1, closeBrace)),
|
|
13472
|
+
bodyStart: openBrace + 1,
|
|
13473
|
+
bodyEnd: closeBrace,
|
|
13474
|
+
fullStart: match.index,
|
|
13475
|
+
fullEnd,
|
|
13476
|
+
raw: source.slice(match.index, fullEnd)
|
|
13477
|
+
};
|
|
13478
|
+
}
|
|
13479
|
+
function hasImportBinding(imports, name, module) {
|
|
13480
|
+
return imports.some(
|
|
13481
|
+
(item) => item.names.includes(name) && (module === void 0)
|
|
13482
|
+
);
|
|
13483
|
+
}
|
|
13484
|
+
function findImportForName(imports, name) {
|
|
13485
|
+
return imports.find((item) => item.names.includes(name));
|
|
13486
|
+
}
|
|
13487
|
+
function normalizeModulePath(modulePath) {
|
|
13488
|
+
return modulePath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\.ts$/, "");
|
|
13489
|
+
}
|
|
13490
|
+
function formatImport(names, modulePath, style) {
|
|
13491
|
+
const body = `import { ${names.join(", ")} } from ${quoteString(modulePath, style.quote)}`;
|
|
13492
|
+
return style.semicolons ? `${body};` : body;
|
|
13493
|
+
}
|
|
13494
|
+
function formatObjectEntry(key, value, style, isLast) {
|
|
13495
|
+
const needsQuote = !/^[A-Za-z_$][\w$]*$/.test(key);
|
|
13496
|
+
const renderedKey = needsQuote ? quoteString(key, style.quote) : key;
|
|
13497
|
+
const comma = !isLast || style.trailingComma ? "," : "";
|
|
13498
|
+
return `${style.indent}${renderedKey}: ${value}${comma}`;
|
|
13499
|
+
}
|
|
13500
|
+
function replaceRange(source, start, end, insertion) {
|
|
13501
|
+
return source.slice(0, start) + insertion + source.slice(end);
|
|
13502
|
+
}
|
|
13503
|
+
function collectDuplicateKeys(entries) {
|
|
13504
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13505
|
+
const dupes = [];
|
|
13506
|
+
for (const entry of entries) {
|
|
13507
|
+
if (seen.has(entry.key)) {
|
|
13508
|
+
dupes.push(entry.key);
|
|
13509
|
+
}
|
|
13510
|
+
seen.add(entry.key);
|
|
13511
|
+
}
|
|
13512
|
+
return dupes;
|
|
13513
|
+
}
|
|
13514
|
+
function collectDuplicateImportBindings(imports) {
|
|
13515
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13516
|
+
const dupes = [];
|
|
13517
|
+
for (const item of imports) {
|
|
13518
|
+
for (const name of item.names) {
|
|
13519
|
+
if (seen.has(name)) {
|
|
13520
|
+
dupes.push(name);
|
|
13521
|
+
}
|
|
13522
|
+
seen.add(name);
|
|
13523
|
+
}
|
|
13524
|
+
}
|
|
13525
|
+
return dupes;
|
|
13526
|
+
}
|
|
13527
|
+
function lintArtifactSource(source, kind) {
|
|
13528
|
+
const errors = [];
|
|
13529
|
+
const imports = parseNamedImports(source);
|
|
13530
|
+
const dupImports = collectDuplicateImportBindings(imports);
|
|
13531
|
+
if (dupImports.length > 0) {
|
|
13532
|
+
errors.push(`duplicate import bindings: ${dupImports.join(", ")}`);
|
|
13533
|
+
}
|
|
13534
|
+
const blocks = parseDefineBlocks(source).filter((block2) => block2.kind === kind);
|
|
13535
|
+
if (blocks.length === 0) {
|
|
13536
|
+
errors.push(`missing export const \u2026 = define${kind === "database" ? "Database" : "Registry"}({\u2026})`);
|
|
13537
|
+
return errors;
|
|
13538
|
+
}
|
|
13539
|
+
if (blocks.length > 1) {
|
|
13540
|
+
errors.push(`multiple define${kind === "database" ? "Database" : "Registry"} exports found`);
|
|
13541
|
+
}
|
|
13542
|
+
const block = blocks[0];
|
|
13543
|
+
const dupKeys = collectDuplicateKeys(block.entries);
|
|
13544
|
+
if (dupKeys.length > 0) {
|
|
13545
|
+
errors.push(`duplicate object keys: ${dupKeys.join(", ")}`);
|
|
13546
|
+
}
|
|
13547
|
+
for (const entry of block.entries) {
|
|
13548
|
+
const valueId = entry.value.match(/^[A-Za-z_$][\w$]*$/)?.[0];
|
|
13549
|
+
if (valueId && !hasImportBinding(imports, valueId) && valueId !== block.exportName) {
|
|
13550
|
+
if (!source.includes(`const ${valueId}`) && !source.includes(`function ${valueId}`)) {
|
|
13551
|
+
errors.push(`value "${valueId}" for key "${entry.key}" is not imported`);
|
|
13552
|
+
}
|
|
13553
|
+
}
|
|
13554
|
+
}
|
|
13555
|
+
if (kind === "database" && !hasImportBinding(imports, "defineDatabase")) {
|
|
13556
|
+
errors.push("missing defineDatabase import");
|
|
13557
|
+
}
|
|
13558
|
+
if (kind === "registry" && !hasImportBinding(imports, "defineRegistry")) {
|
|
13559
|
+
errors.push("missing defineRegistry import");
|
|
13560
|
+
}
|
|
13561
|
+
return errors;
|
|
13562
|
+
}
|
|
13563
|
+
function preservedCustomUnits(existing, generated, kind) {
|
|
13564
|
+
const custom = [];
|
|
13565
|
+
const existingImports = parseNamedImports(existing);
|
|
13566
|
+
const generatedImports = parseNamedImports(generated);
|
|
13567
|
+
const generatedModules = new Set(generatedImports.map((item) => normalizeModulePath(item.module)));
|
|
13568
|
+
const generatedNames = new Set(generatedImports.flatMap((item) => item.names));
|
|
13569
|
+
for (const item of existingImports) {
|
|
13570
|
+
const moduleNorm = normalizeModulePath(item.module);
|
|
13571
|
+
if (moduleNorm.includes("@xylex-group/athena")) {
|
|
13572
|
+
continue;
|
|
13573
|
+
}
|
|
13574
|
+
const unexpectedNames = item.names.filter((name) => !generatedNames.has(name));
|
|
13575
|
+
if (unexpectedNames.length > 0 && !generatedModules.has(moduleNorm)) {
|
|
13576
|
+
custom.push(`import { ${unexpectedNames.join(", ")} } from '${item.module}'`);
|
|
13577
|
+
} else if (unexpectedNames.length > 0) {
|
|
13578
|
+
custom.push(`import binding(s): ${unexpectedNames.join(", ")}`);
|
|
13579
|
+
}
|
|
13580
|
+
}
|
|
13581
|
+
const existingBlocks = parseDefineBlocks(existing).filter((block) => block.kind === kind);
|
|
13582
|
+
const generatedBlocks = parseDefineBlocks(generated).filter((block) => block.kind === kind);
|
|
13583
|
+
const generatedKeys = new Set(generatedBlocks[0]?.entries.map((entry) => entry.key) ?? []);
|
|
13584
|
+
for (const entry of existingBlocks[0]?.entries ?? []) {
|
|
13585
|
+
if (!generatedKeys.has(entry.key)) {
|
|
13586
|
+
custom.push(`${kind} entry: ${entry.key}: ${entry.value}`);
|
|
13587
|
+
}
|
|
13588
|
+
}
|
|
13589
|
+
if (kind === "registry") {
|
|
13590
|
+
const existingMeta = parseMetaBlock(existing);
|
|
13591
|
+
const generatedMeta = parseMetaBlock(generated);
|
|
13592
|
+
const generatedMetaKeys = new Set(generatedMeta?.entries.map((entry) => entry.key) ?? []);
|
|
13593
|
+
for (const entry of existingMeta?.entries ?? []) {
|
|
13594
|
+
if (!generatedMetaKeys.has(entry.key) && !KNOWN_META_KEYS.has(entry.key)) {
|
|
13595
|
+
custom.push(`meta entry: ${entry.key}: ${entry.value}`);
|
|
13596
|
+
}
|
|
13597
|
+
}
|
|
13598
|
+
}
|
|
13599
|
+
const exportConstRe = /^export\s+const\s+([A-Za-z_$][\w$]*)\b/gm;
|
|
13600
|
+
const generatedExports = /* @__PURE__ */ new Set();
|
|
13601
|
+
let match;
|
|
13602
|
+
exportConstRe.lastIndex = 0;
|
|
13603
|
+
while ((match = exportConstRe.exec(generated)) !== null) {
|
|
13604
|
+
generatedExports.add(match[1]);
|
|
13605
|
+
}
|
|
13606
|
+
exportConstRe.lastIndex = 0;
|
|
13607
|
+
while ((match = exportConstRe.exec(existing)) !== null) {
|
|
13608
|
+
if (!generatedExports.has(match[1]) && match[1] !== "__athena_schema_meta") {
|
|
13609
|
+
custom.push(`export const ${match[1]}`);
|
|
13610
|
+
}
|
|
13611
|
+
}
|
|
13612
|
+
return custom;
|
|
13613
|
+
}
|
|
13614
|
+
function insertImportAfterPackageImports(source, importLine, style) {
|
|
13615
|
+
const imports = parseNamedImports(source);
|
|
13616
|
+
if (imports.length === 0) {
|
|
13617
|
+
return `${importLine}${style.newline}${source}`;
|
|
13618
|
+
}
|
|
13619
|
+
let anchor = imports[imports.length - 1];
|
|
13620
|
+
for (let i = imports.length - 1; i >= 0; i -= 1) {
|
|
13621
|
+
if (imports[i].module.startsWith(".")) {
|
|
13622
|
+
anchor = imports[i];
|
|
13623
|
+
break;
|
|
13624
|
+
}
|
|
13625
|
+
}
|
|
13626
|
+
const insertAt = anchor.end;
|
|
13627
|
+
const before = source.slice(0, insertAt);
|
|
13628
|
+
const after = source.slice(insertAt);
|
|
13629
|
+
const needsLeadingNl = !before.endsWith("\n");
|
|
13630
|
+
const prefix = needsLeadingNl ? style.newline : "";
|
|
13631
|
+
return `${before}${prefix}${importLine}${after.startsWith("\n") || after.startsWith("\r\n") ? "" : style.newline}${after}`;
|
|
13632
|
+
}
|
|
13633
|
+
function rewriteObjectBody(entries, style) {
|
|
13634
|
+
if (entries.length === 0) {
|
|
13635
|
+
return style.newline;
|
|
13636
|
+
}
|
|
13637
|
+
const lines = entries.map(
|
|
13638
|
+
(entry, index) => formatObjectEntry(entry.key, entry.value, style, index === entries.length - 1)
|
|
13639
|
+
);
|
|
13640
|
+
return `${style.newline}${lines.join(style.newline)}${style.newline}`;
|
|
13641
|
+
}
|
|
13642
|
+
function mergeDatabaseArtifact(existing, generated) {
|
|
13643
|
+
const style = detectStyle(existing);
|
|
13644
|
+
const generatedStyle = detectStyle(generated);
|
|
13645
|
+
const effectiveStyle = {
|
|
13646
|
+
...style,
|
|
13647
|
+
// Prefer existing fingerprint; fall back to generated if existing is empty-ish
|
|
13648
|
+
quote: existing.includes('"') || existing.includes("'") ? style.quote : generatedStyle.quote
|
|
13649
|
+
};
|
|
13650
|
+
const generatedImports = parseNamedImports(generated);
|
|
13651
|
+
const existingBlocks = parseDefineBlocks(existing).filter((block) => block.kind === "database");
|
|
13652
|
+
const generatedBlocks = parseDefineBlocks(generated).filter((block) => block.kind === "database");
|
|
13653
|
+
if (existingBlocks.length === 0 || generatedBlocks.length === 0) {
|
|
13654
|
+
return {
|
|
13655
|
+
action: "skip",
|
|
13656
|
+
skipReason: "merge-unparseable",
|
|
13657
|
+
added: [],
|
|
13658
|
+
preservedCustom: [],
|
|
13659
|
+
conflicts: [],
|
|
13660
|
+
lintErrors: [],
|
|
13661
|
+
detail: "could not locate defineDatabase({\u2026}) export for merge"
|
|
13662
|
+
};
|
|
13663
|
+
}
|
|
13664
|
+
const generatedBlock = generatedBlocks[0];
|
|
13665
|
+
const conflicts = [];
|
|
13666
|
+
const added = [];
|
|
13667
|
+
let next = existing;
|
|
13668
|
+
if (!hasImportBinding(parseNamedImports(next), "defineDatabase")) {
|
|
13669
|
+
const pkgImport = generatedImports.find((item) => item.names.includes("defineDatabase"));
|
|
13670
|
+
if (pkgImport) {
|
|
13671
|
+
const line = formatImport(["defineDatabase"], pkgImport.module, effectiveStyle);
|
|
13672
|
+
next = insertImportAfterPackageImports(next, line, effectiveStyle);
|
|
13673
|
+
added.push("import defineDatabase");
|
|
13674
|
+
}
|
|
13675
|
+
}
|
|
13676
|
+
let workingImports = parseNamedImports(next);
|
|
13677
|
+
let workingBlocks = parseDefineBlocks(next).filter((block) => block.kind === "database");
|
|
13678
|
+
let workingBlock = workingBlocks[0];
|
|
13679
|
+
const entryMap = new Map(workingBlock.entries.map((entry) => [entry.key, entry]));
|
|
13680
|
+
for (const desired of generatedBlock.entries) {
|
|
13681
|
+
const existingEntry = entryMap.get(desired.key);
|
|
13682
|
+
if (existingEntry) {
|
|
13683
|
+
if (existingEntry.value !== desired.value) {
|
|
13684
|
+
conflicts.push(
|
|
13685
|
+
`key "${desired.key}" maps to ${existingEntry.value} (existing) vs ${desired.value} (generated)`
|
|
13686
|
+
);
|
|
13687
|
+
}
|
|
13688
|
+
continue;
|
|
13689
|
+
}
|
|
13690
|
+
const desiredImport = generatedImports.find((item) => item.names.includes(desired.value));
|
|
13691
|
+
if (desiredImport) {
|
|
13692
|
+
const existingForName = findImportForName(workingImports, desired.value);
|
|
13693
|
+
if (existingForName) {
|
|
13694
|
+
if (normalizeModulePath(existingForName.module) !== normalizeModulePath(desiredImport.module)) {
|
|
13695
|
+
conflicts.push(
|
|
13696
|
+
`binding "${desired.value}" imported from '${existingForName.module}' vs '${desiredImport.module}'`
|
|
13697
|
+
);
|
|
13698
|
+
continue;
|
|
13699
|
+
}
|
|
13700
|
+
} else {
|
|
13701
|
+
const line = formatImport([desired.value], desiredImport.module, effectiveStyle);
|
|
13702
|
+
next = insertImportAfterPackageImports(next, line, effectiveStyle);
|
|
13703
|
+
added.push(`import ${desired.value}`);
|
|
13704
|
+
workingImports = parseNamedImports(next);
|
|
13705
|
+
}
|
|
13706
|
+
}
|
|
13707
|
+
workingBlocks = parseDefineBlocks(next).filter((block) => block.kind === "database");
|
|
13708
|
+
workingBlock = workingBlocks[0];
|
|
13709
|
+
const nextEntries = [...workingBlock.entries, { key: desired.key, value: desired.value, raw: "" }];
|
|
13710
|
+
const body = rewriteObjectBody(nextEntries, effectiveStyle);
|
|
13711
|
+
next = replaceRange(next, workingBlock.bodyStart, workingBlock.bodyEnd, body);
|
|
13712
|
+
entryMap.set(desired.key, { key: desired.key, value: desired.value, raw: "" });
|
|
13713
|
+
added.push(`database entry: ${desired.key}`);
|
|
13714
|
+
}
|
|
13715
|
+
if (conflicts.length > 0 && added.length === 0) {
|
|
13716
|
+
return {
|
|
13717
|
+
action: "skip",
|
|
13718
|
+
skipReason: "merge-conflict",
|
|
13719
|
+
added: [],
|
|
13720
|
+
preservedCustom: preservedCustomUnits(existing, generated, "database"),
|
|
13721
|
+
conflicts,
|
|
13722
|
+
lintErrors: [],
|
|
13723
|
+
detail: conflicts.join("; ")
|
|
13724
|
+
};
|
|
13725
|
+
}
|
|
13726
|
+
const lintErrors = lintArtifactSource(next, "database");
|
|
13727
|
+
if (lintErrors.length > 0) {
|
|
13728
|
+
return {
|
|
13729
|
+
action: "skip",
|
|
13730
|
+
skipReason: "merge-lint-failed",
|
|
13731
|
+
added,
|
|
13732
|
+
preservedCustom: preservedCustomUnits(existing, generated, "database"),
|
|
13733
|
+
conflicts,
|
|
13734
|
+
lintErrors,
|
|
13735
|
+
detail: lintErrors.join("; ")
|
|
13736
|
+
};
|
|
13737
|
+
}
|
|
13738
|
+
const preservedCustom = preservedCustomUnits(next, generated, "database");
|
|
13739
|
+
if (next === existing || next.replace(/\r\n/g, "\n") === existing.replace(/\r\n/g, "\n")) {
|
|
13740
|
+
return {
|
|
13741
|
+
action: "unchanged",
|
|
13742
|
+
content: existing,
|
|
13743
|
+
skipReason: "already-current",
|
|
13744
|
+
added: [],
|
|
13745
|
+
preservedCustom,
|
|
13746
|
+
conflicts,
|
|
13747
|
+
lintErrors: [],
|
|
13748
|
+
detail: conflicts.length > 0 ? conflicts.join("; ") : void 0
|
|
13749
|
+
};
|
|
13750
|
+
}
|
|
13751
|
+
return {
|
|
13752
|
+
action: "write",
|
|
13753
|
+
content: next.endsWith("\n") ? next : `${next}${effectiveStyle.newline}`,
|
|
13754
|
+
writeReason: "merged",
|
|
13755
|
+
added,
|
|
13756
|
+
preservedCustom,
|
|
13757
|
+
conflicts,
|
|
13758
|
+
lintErrors: []
|
|
13759
|
+
};
|
|
13760
|
+
}
|
|
13761
|
+
function mergeMetaFields(existingMeta, generatedMeta) {
|
|
13762
|
+
const added = [];
|
|
13763
|
+
if (!generatedMeta) {
|
|
13764
|
+
return { entries: existingMeta?.entries ?? [], changed: false, added };
|
|
13765
|
+
}
|
|
13766
|
+
if (!existingMeta) {
|
|
13767
|
+
return {
|
|
13768
|
+
entries: generatedMeta.entries,
|
|
13769
|
+
changed: true,
|
|
13770
|
+
added: generatedMeta.entries.map((entry) => `meta entry: ${entry.key}`)
|
|
13771
|
+
};
|
|
13772
|
+
}
|
|
13773
|
+
const map = new Map(existingMeta.entries.map((entry) => [entry.key, entry]));
|
|
13774
|
+
let changed = false;
|
|
13775
|
+
for (const desired of generatedMeta.entries) {
|
|
13776
|
+
const current = map.get(desired.key);
|
|
13777
|
+
if (!current) {
|
|
13778
|
+
map.set(desired.key, desired);
|
|
13779
|
+
added.push(`meta entry: ${desired.key}`);
|
|
13780
|
+
changed = true;
|
|
13781
|
+
continue;
|
|
13782
|
+
}
|
|
13783
|
+
if (KNOWN_META_KEYS.has(desired.key) && current.value !== desired.value) {
|
|
13784
|
+
map.set(desired.key, desired);
|
|
13785
|
+
added.push(`meta refresh: ${desired.key}`);
|
|
13786
|
+
changed = true;
|
|
13787
|
+
}
|
|
13788
|
+
}
|
|
13789
|
+
const ordered = [];
|
|
13790
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13791
|
+
for (const entry of existingMeta.entries) {
|
|
13792
|
+
const next = map.get(entry.key);
|
|
13793
|
+
if (next) {
|
|
13794
|
+
ordered.push(next);
|
|
13795
|
+
seen.add(entry.key);
|
|
13796
|
+
}
|
|
13797
|
+
}
|
|
13798
|
+
for (const entry of generatedMeta.entries) {
|
|
13799
|
+
if (!seen.has(entry.key)) {
|
|
13800
|
+
const next = map.get(entry.key);
|
|
13801
|
+
if (next) {
|
|
13802
|
+
ordered.push(next);
|
|
13803
|
+
seen.add(entry.key);
|
|
13804
|
+
}
|
|
13805
|
+
}
|
|
13806
|
+
}
|
|
13807
|
+
for (const [key, entry] of map) {
|
|
13808
|
+
if (!seen.has(key)) {
|
|
13809
|
+
ordered.push(entry);
|
|
13810
|
+
}
|
|
13811
|
+
}
|
|
13812
|
+
return { entries: ordered, changed, added };
|
|
13275
13813
|
}
|
|
13814
|
+
function mergeRegistryArtifact(existing, generated) {
|
|
13815
|
+
const style = detectStyle(existing);
|
|
13816
|
+
const effectiveStyle = style;
|
|
13817
|
+
const generatedImports = parseNamedImports(generated);
|
|
13818
|
+
const existingBlocks = parseDefineBlocks(existing).filter((block) => block.kind === "registry");
|
|
13819
|
+
const generatedBlocks = parseDefineBlocks(generated).filter((block) => block.kind === "registry");
|
|
13820
|
+
if (existingBlocks.length === 0 || generatedBlocks.length === 0) {
|
|
13821
|
+
return {
|
|
13822
|
+
action: "skip",
|
|
13823
|
+
skipReason: "merge-unparseable",
|
|
13824
|
+
added: [],
|
|
13825
|
+
preservedCustom: [],
|
|
13826
|
+
conflicts: [],
|
|
13827
|
+
lintErrors: [],
|
|
13828
|
+
detail: "could not locate defineRegistry({\u2026}) export for merge"
|
|
13829
|
+
};
|
|
13830
|
+
}
|
|
13831
|
+
const existingBlock = existingBlocks[0];
|
|
13832
|
+
const generatedBlock = generatedBlocks[0];
|
|
13833
|
+
const conflicts = [];
|
|
13834
|
+
const added = [];
|
|
13835
|
+
let next = existing;
|
|
13836
|
+
if (!hasImportBinding(parseNamedImports(next), "defineRegistry")) {
|
|
13837
|
+
const pkgImport = generatedImports.find((item) => item.names.includes("defineRegistry"));
|
|
13838
|
+
if (pkgImport) {
|
|
13839
|
+
next = insertImportAfterPackageImports(
|
|
13840
|
+
next,
|
|
13841
|
+
formatImport(["defineRegistry"], pkgImport.module, effectiveStyle),
|
|
13842
|
+
effectiveStyle
|
|
13843
|
+
);
|
|
13844
|
+
added.push("import defineRegistry");
|
|
13845
|
+
}
|
|
13846
|
+
}
|
|
13847
|
+
const preferredDbValue = existingBlock.entries[0]?.value ?? generatedBlock.entries[0]?.value;
|
|
13848
|
+
const generatedDbImport = generatedImports.find((item) => item.names.includes(generatedBlock.entries[0]?.value ?? "")) ?? generatedImports.find((item) => item.module.startsWith("."));
|
|
13849
|
+
if (preferredDbValue && generatedDbImport) {
|
|
13850
|
+
const existingForName = findImportForName(parseNamedImports(next), preferredDbValue);
|
|
13851
|
+
if (!existingForName) {
|
|
13852
|
+
const modulePath = generatedDbImport.module;
|
|
13853
|
+
const importName = findImportForName(generatedImports, preferredDbValue)?.names[0] ?? generatedBlock.entries[0]?.value ?? preferredDbValue;
|
|
13854
|
+
if (!hasImportBinding(parseNamedImports(next), importName)) {
|
|
13855
|
+
next = insertImportAfterPackageImports(
|
|
13856
|
+
next,
|
|
13857
|
+
formatImport([importName], modulePath, effectiveStyle),
|
|
13858
|
+
effectiveStyle
|
|
13859
|
+
);
|
|
13860
|
+
added.push(`import ${importName}`);
|
|
13861
|
+
}
|
|
13862
|
+
} else if (normalizeModulePath(existingForName.module) !== normalizeModulePath(generatedDbImport.module)) {
|
|
13863
|
+
conflicts.push(
|
|
13864
|
+
`binding "${preferredDbValue}" imported from '${existingForName.module}' vs '${generatedDbImport.module}'`
|
|
13865
|
+
);
|
|
13866
|
+
}
|
|
13867
|
+
}
|
|
13868
|
+
let workingBlocks = parseDefineBlocks(next).filter((block) => block.kind === "registry");
|
|
13869
|
+
let workingBlock = workingBlocks[0];
|
|
13870
|
+
const entryMap = new Map(workingBlock.entries.map((entry) => [entry.key, entry]));
|
|
13871
|
+
for (const desired of generatedBlock.entries) {
|
|
13872
|
+
const existingEntry = entryMap.get(desired.key);
|
|
13873
|
+
if (existingEntry) {
|
|
13874
|
+
continue;
|
|
13875
|
+
}
|
|
13876
|
+
const dbImport = parseNamedImports(next).find(
|
|
13877
|
+
(item) => item.module.startsWith(".") && item.names.some((name) => name !== "defineRegistry")
|
|
13878
|
+
);
|
|
13879
|
+
const value = dbImport?.names[0] ?? desired.value;
|
|
13880
|
+
const nextEntries = [...workingBlock.entries, { key: desired.key, value, raw: "" }];
|
|
13881
|
+
const body = rewriteObjectBody(nextEntries, effectiveStyle);
|
|
13882
|
+
next = replaceRange(next, workingBlock.bodyStart, workingBlock.bodyEnd, body);
|
|
13883
|
+
entryMap.set(desired.key, { key: desired.key, value, raw: "" });
|
|
13884
|
+
added.push(`registry entry: ${desired.key}`);
|
|
13885
|
+
workingBlocks = parseDefineBlocks(next).filter((block) => block.kind === "registry");
|
|
13886
|
+
workingBlock = workingBlocks[0];
|
|
13887
|
+
}
|
|
13888
|
+
const existingMeta = parseMetaBlock(next);
|
|
13889
|
+
const generatedMeta = parseMetaBlock(generated);
|
|
13890
|
+
const structuralAdded = added.length > 0;
|
|
13891
|
+
if (generatedMeta) {
|
|
13892
|
+
if (!existingMeta) {
|
|
13893
|
+
const blocks = parseDefineBlocks(next).filter((block) => block.kind === "registry");
|
|
13894
|
+
const insertAt = blocks[0]?.fullStart ?? next.length;
|
|
13895
|
+
const metaBody = rewriteObjectBody(generatedMeta.entries, effectiveStyle);
|
|
13896
|
+
const metaBlock = `export const __athena_schema_meta = {${metaBody}} as const${effectiveStyle.semicolons ? ";" : ""}${effectiveStyle.newline}${effectiveStyle.newline}`;
|
|
13897
|
+
next = replaceRange(next, insertAt, insertAt, metaBlock);
|
|
13898
|
+
added.push("__athena_schema_meta");
|
|
13899
|
+
} else {
|
|
13900
|
+
const desiredEntries = structuralAdded ? generatedMeta.entries : generatedMeta.entries.filter((entry) => {
|
|
13901
|
+
return !existingMeta.entries.some((current) => current.key === entry.key);
|
|
13902
|
+
});
|
|
13903
|
+
if (structuralAdded) {
|
|
13904
|
+
const merged = mergeMetaFields(existingMeta, generatedMeta);
|
|
13905
|
+
if (merged.changed) {
|
|
13906
|
+
const metaNow = parseMetaBlock(next);
|
|
13907
|
+
if (metaNow) {
|
|
13908
|
+
const body = rewriteObjectBody(merged.entries, effectiveStyle);
|
|
13909
|
+
next = replaceRange(next, metaNow.bodyStart, metaNow.bodyEnd, body);
|
|
13910
|
+
added.push(...merged.added);
|
|
13911
|
+
}
|
|
13912
|
+
}
|
|
13913
|
+
} else if (desiredEntries.length > 0) {
|
|
13914
|
+
const map = new Map(existingMeta.entries.map((entry) => [entry.key, entry]));
|
|
13915
|
+
for (const entry of desiredEntries) {
|
|
13916
|
+
map.set(entry.key, entry);
|
|
13917
|
+
added.push(`meta entry: ${entry.key}`);
|
|
13918
|
+
}
|
|
13919
|
+
const ordered = [
|
|
13920
|
+
...existingMeta.entries.map((entry) => map.get(entry.key)),
|
|
13921
|
+
...desiredEntries.filter((entry) => !existingMeta.entries.some((e) => e.key === entry.key))
|
|
13922
|
+
];
|
|
13923
|
+
const metaNow = parseMetaBlock(next);
|
|
13924
|
+
if (metaNow) {
|
|
13925
|
+
const body = rewriteObjectBody(ordered, effectiveStyle);
|
|
13926
|
+
next = replaceRange(next, metaNow.bodyStart, metaNow.bodyEnd, body);
|
|
13927
|
+
}
|
|
13928
|
+
}
|
|
13929
|
+
}
|
|
13930
|
+
}
|
|
13931
|
+
if (conflicts.length > 0 && added.length === 0) {
|
|
13932
|
+
return {
|
|
13933
|
+
action: "skip",
|
|
13934
|
+
skipReason: "merge-conflict",
|
|
13935
|
+
added: [],
|
|
13936
|
+
preservedCustom: preservedCustomUnits(existing, generated, "registry"),
|
|
13937
|
+
conflicts,
|
|
13938
|
+
lintErrors: [],
|
|
13939
|
+
detail: conflicts.join("; ")
|
|
13940
|
+
};
|
|
13941
|
+
}
|
|
13942
|
+
const lintErrors = lintArtifactSource(next, "registry");
|
|
13943
|
+
if (lintErrors.length > 0) {
|
|
13944
|
+
return {
|
|
13945
|
+
action: "skip",
|
|
13946
|
+
skipReason: "merge-lint-failed",
|
|
13947
|
+
added,
|
|
13948
|
+
preservedCustom: preservedCustomUnits(existing, generated, "registry"),
|
|
13949
|
+
conflicts,
|
|
13950
|
+
lintErrors,
|
|
13951
|
+
detail: lintErrors.join("; ")
|
|
13952
|
+
};
|
|
13953
|
+
}
|
|
13954
|
+
const preservedCustom = preservedCustomUnits(next, generated, "registry");
|
|
13955
|
+
if (next.replace(/\r\n/g, "\n") === existing.replace(/\r\n/g, "\n")) {
|
|
13956
|
+
return {
|
|
13957
|
+
action: "unchanged",
|
|
13958
|
+
content: existing,
|
|
13959
|
+
skipReason: "already-current",
|
|
13960
|
+
added: [],
|
|
13961
|
+
preservedCustom,
|
|
13962
|
+
conflicts,
|
|
13963
|
+
lintErrors: []
|
|
13964
|
+
};
|
|
13965
|
+
}
|
|
13966
|
+
return {
|
|
13967
|
+
action: "write",
|
|
13968
|
+
content: next.endsWith("\n") ? next : `${next}${effectiveStyle.newline}`,
|
|
13969
|
+
writeReason: "merged",
|
|
13970
|
+
added,
|
|
13971
|
+
preservedCustom,
|
|
13972
|
+
conflicts,
|
|
13973
|
+
lintErrors: []
|
|
13974
|
+
};
|
|
13975
|
+
}
|
|
13976
|
+
function mergeProtectedArtifact(kind, existing, generated, policy) {
|
|
13977
|
+
if (policy === "overwrite") {
|
|
13978
|
+
if (existing.replace(/\r\n/g, "\n") === generated.replace(/\r\n/g, "\n")) {
|
|
13979
|
+
return {
|
|
13980
|
+
action: "unchanged",
|
|
13981
|
+
content: existing,
|
|
13982
|
+
skipReason: "already-current",
|
|
13983
|
+
added: [],
|
|
13984
|
+
preservedCustom: [],
|
|
13985
|
+
conflicts: [],
|
|
13986
|
+
lintErrors: []
|
|
13987
|
+
};
|
|
13988
|
+
}
|
|
13989
|
+
return {
|
|
13990
|
+
action: "write",
|
|
13991
|
+
content: generated,
|
|
13992
|
+
writeReason: "overwritten",
|
|
13993
|
+
added: ["full overwrite"],
|
|
13994
|
+
preservedCustom: [],
|
|
13995
|
+
conflicts: [],
|
|
13996
|
+
lintErrors: []
|
|
13997
|
+
};
|
|
13998
|
+
}
|
|
13999
|
+
if (policy === "skip") {
|
|
14000
|
+
return {
|
|
14001
|
+
action: "skip",
|
|
14002
|
+
skipReason: "protected-existing-file",
|
|
14003
|
+
added: [],
|
|
14004
|
+
preservedCustom: preservedCustomUnits(existing, generated, kind),
|
|
14005
|
+
conflicts: [],
|
|
14006
|
+
lintErrors: [],
|
|
14007
|
+
detail: "artifactWrite policy is skip"
|
|
14008
|
+
};
|
|
14009
|
+
}
|
|
14010
|
+
return kind === "database" ? mergeDatabaseArtifact(existing, generated) : mergeRegistryArtifact(existing, generated);
|
|
14011
|
+
}
|
|
14012
|
+
function resolveArtifactWritePlan(file, existingContent, policy) {
|
|
14013
|
+
if (existingContent === null) {
|
|
14014
|
+
return {
|
|
14015
|
+
action: "write",
|
|
14016
|
+
content: file.content,
|
|
14017
|
+
writeReason: "created",
|
|
14018
|
+
added: ["created"],
|
|
14019
|
+
preservedCustom: [],
|
|
14020
|
+
conflicts: [],
|
|
14021
|
+
lintErrors: []
|
|
14022
|
+
};
|
|
14023
|
+
}
|
|
14024
|
+
if (file.kind === "model" || file.kind === "schema" || policy === "always") {
|
|
14025
|
+
if (existingContent.replace(/\r\n/g, "\n") === file.content.replace(/\r\n/g, "\n")) {
|
|
14026
|
+
return {
|
|
14027
|
+
action: "unchanged",
|
|
14028
|
+
content: existingContent,
|
|
14029
|
+
skipReason: "already-current",
|
|
14030
|
+
added: [],
|
|
14031
|
+
preservedCustom: [],
|
|
14032
|
+
conflicts: [],
|
|
14033
|
+
lintErrors: []
|
|
14034
|
+
};
|
|
14035
|
+
}
|
|
14036
|
+
return {
|
|
14037
|
+
action: "write",
|
|
14038
|
+
content: file.content,
|
|
14039
|
+
writeReason: existingContent ? "overwritten" : "created",
|
|
14040
|
+
added: ["overwritten"],
|
|
14041
|
+
preservedCustom: [],
|
|
14042
|
+
conflicts: [],
|
|
14043
|
+
lintErrors: []
|
|
14044
|
+
};
|
|
14045
|
+
}
|
|
14046
|
+
return mergeProtectedArtifact(
|
|
14047
|
+
file.kind,
|
|
14048
|
+
existingContent,
|
|
14049
|
+
file.content,
|
|
14050
|
+
policy
|
|
14051
|
+
);
|
|
14052
|
+
}
|
|
14053
|
+
|
|
14054
|
+
// src/generator/pipeline.ts
|
|
13276
14055
|
async function fileExists(path) {
|
|
13277
14056
|
try {
|
|
13278
14057
|
await promises.stat(path);
|
|
@@ -13281,25 +14060,70 @@ async function fileExists(path) {
|
|
|
13281
14060
|
return false;
|
|
13282
14061
|
}
|
|
13283
14062
|
}
|
|
13284
|
-
async function
|
|
14063
|
+
async function readExisting(path) {
|
|
14064
|
+
try {
|
|
14065
|
+
return await promises.readFile(path, "utf8");
|
|
14066
|
+
} catch {
|
|
14067
|
+
return null;
|
|
14068
|
+
}
|
|
14069
|
+
}
|
|
14070
|
+
function policyForArtifact(file, config) {
|
|
14071
|
+
if (file.kind === "model" || file.kind === "schema") {
|
|
14072
|
+
return "always";
|
|
14073
|
+
}
|
|
14074
|
+
if (file.kind === "database") {
|
|
14075
|
+
return config.output.artifactWrite.database;
|
|
14076
|
+
}
|
|
14077
|
+
return config.output.artifactWrite.registry;
|
|
14078
|
+
}
|
|
14079
|
+
async function writeArtifacts(files, cwd, config, dryRun) {
|
|
13285
14080
|
const writtenFiles = [];
|
|
14081
|
+
const writtenDetails = [];
|
|
13286
14082
|
const skippedFiles = [];
|
|
13287
14083
|
for (const file of files) {
|
|
13288
14084
|
const absolutePath = path.resolve(cwd, file.path);
|
|
13289
|
-
|
|
14085
|
+
const exists = await fileExists(absolutePath);
|
|
14086
|
+
const existingContent = exists ? await readExisting(absolutePath) : null;
|
|
14087
|
+
const policy = policyForArtifact(file, config);
|
|
14088
|
+
const plan = resolveArtifactWritePlan(file, existingContent, policy);
|
|
14089
|
+
if (plan.action === "skip" || plan.action === "unchanged") {
|
|
13290
14090
|
skippedFiles.push({
|
|
13291
14091
|
kind: file.kind,
|
|
13292
14092
|
path: file.path,
|
|
13293
|
-
reason: "
|
|
14093
|
+
reason: plan.skipReason ?? "already-current",
|
|
14094
|
+
detail: plan.detail,
|
|
14095
|
+
preservedCustom: plan.preservedCustom.length > 0 ? plan.preservedCustom : void 0,
|
|
14096
|
+
conflicts: plan.conflicts.length > 0 ? plan.conflicts : void 0,
|
|
14097
|
+
lintErrors: plan.lintErrors.length > 0 ? plan.lintErrors : void 0
|
|
13294
14098
|
});
|
|
13295
14099
|
continue;
|
|
13296
14100
|
}
|
|
13297
|
-
|
|
13298
|
-
|
|
14101
|
+
if (!plan.content || !plan.writeReason) {
|
|
14102
|
+
skippedFiles.push({
|
|
14103
|
+
kind: file.kind,
|
|
14104
|
+
path: file.path,
|
|
14105
|
+
reason: "merge-lint-failed",
|
|
14106
|
+
detail: "merge produced no content",
|
|
14107
|
+
lintErrors: plan.lintErrors
|
|
14108
|
+
});
|
|
14109
|
+
continue;
|
|
14110
|
+
}
|
|
14111
|
+
if (!dryRun) {
|
|
14112
|
+
await promises.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
14113
|
+
await promises.writeFile(absolutePath, plan.content, "utf8");
|
|
14114
|
+
}
|
|
13299
14115
|
writtenFiles.push(file.path);
|
|
14116
|
+
writtenDetails.push({
|
|
14117
|
+
kind: file.kind,
|
|
14118
|
+
path: file.path,
|
|
14119
|
+
reason: plan.writeReason,
|
|
14120
|
+
added: plan.added.length > 0 ? plan.added : void 0,
|
|
14121
|
+
preservedCustom: plan.preservedCustom.length > 0 ? plan.preservedCustom : void 0
|
|
14122
|
+
});
|
|
13300
14123
|
}
|
|
13301
14124
|
return {
|
|
13302
14125
|
writtenFiles,
|
|
14126
|
+
writtenDetails,
|
|
13303
14127
|
skippedFiles
|
|
13304
14128
|
};
|
|
13305
14129
|
}
|
|
@@ -13315,12 +14139,18 @@ async function runSchemaGenerator(options = {}) {
|
|
|
13315
14139
|
schemas: resolveProviderSchemas(config.provider)
|
|
13316
14140
|
});
|
|
13317
14141
|
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
13318
|
-
const writeResult =
|
|
14142
|
+
const writeResult = await writeArtifacts(
|
|
14143
|
+
generated.files,
|
|
14144
|
+
cwd,
|
|
14145
|
+
config,
|
|
14146
|
+
options.dryRun === true
|
|
14147
|
+
);
|
|
13319
14148
|
return {
|
|
13320
14149
|
...generated,
|
|
13321
14150
|
configPath,
|
|
13322
14151
|
config,
|
|
13323
14152
|
writtenFiles: writeResult.writtenFiles,
|
|
14153
|
+
writtenDetails: writeResult.writtenDetails,
|
|
13324
14154
|
skippedFiles: writeResult.skippedFiles
|
|
13325
14155
|
};
|
|
13326
14156
|
}
|