@blue-labs/repository-generator 4.0.0-rc.0 → 4.0.0-rc.2
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/bin/blue-repo-generator.js +1 -1
- package/dist/bin/blue-repo-generator.mjs +1 -1
- package/dist/{generateRepository-DBYEfJm2.mjs → generateRepository-BiRDvOfc.mjs} +165 -129
- package/dist/generateRepository-DDbll3Cz.js +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/core/ExpressionPreserver.d.ts +6 -0
- package/dist/lib/core/ExpressionPreserver.d.ts.map +1 -0
- package/dist/lib/core/blueIds.d.ts.map +1 -1
- package/dist/lib/core/mergingProcessor.d.ts +3 -0
- package/dist/lib/core/mergingProcessor.d.ts.map +1 -0
- package/package.json +4 -4
- package/dist/generateRepository-CNSvDkC2.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";const c=require("fs"),a=require("path"),f=require("../generateRepository-
|
|
2
|
+
"use strict";const c=require("fs"),a=require("path"),f=require("../generateRepository-DDbll3Cz.js");function u(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const l=u(c),i=u(a);function d(e){const o={repoRoot:process.cwd(),blueRepository:"BlueRepository.blue",verbose:!1,json:!1,failOnDiff:!0};for(let t=0;t<e.length;t++){const r=e[t];switch(r){case"--repo-root":o.repoRoot=e[++t];break;case"--blue-repository":o.blueRepository=e[++t];break;case"--mode":o.mode=e[++t];break;case"--verbose":o.verbose=!0;break;case"--json":o.json=!0;break;case"--allow-diff":o.failOnDiff=!1;break;default:throw new Error(`Unknown argument: ${r}`)}}if(!o.mode||o.mode!=="check"&&o.mode!=="write")throw new Error('Missing or invalid --mode (expected "check" or "write").');return o}function s(e,o){e&&console.log(JSON.stringify(o,null,2))}function p(){try{const e=d(process.argv.slice(2)),o=i.resolve(e.repoRoot),t=i.resolve(o,e.blueRepository),r=f.generateRepository({repoRoot:o,blueRepositoryPath:t,verbose:e.verbose}),n=r.existingYaml!==void 0&&r.existingYaml===r.yaml;if(e.mode==="check"){if(!r.existingYaml){if(s(e.json,{repoBlueId:r.currentRepoBlueId,changed:!0,reason:"BlueRepository.blue is missing."}),e.failOnDiff)throw new Error("BlueRepository.blue is missing. Run with --mode write to create it.");console.warn("BlueRepository.blue is missing. Run with --mode write.");return}if(!n){if(s(e.json,{repoBlueId:r.currentRepoBlueId,changed:!0,reason:"BlueRepository.blue is out of date."}),e.failOnDiff)throw new Error("BlueRepository.blue is out of date. Run with --mode write.");console.warn("BlueRepository.blue is out of date. Run with --mode write.");return}console.log("BlueRepository.blue is up to date."),s(e.json,{repoBlueId:r.currentRepoBlueId,changed:!1});return}if(!r.existingYaml||r.changed)l.mkdirSync(i.dirname(t),{recursive:!0}),l.writeFileSync(t,r.yaml,"utf8"),e.verbose&&console.info(`Wrote BlueRepository.blue with RepoBlueId ${r.currentRepoBlueId}`);else if(n)e.verbose&&console.info("No changes detected; BlueRepository.blue left untouched.");else throw new Error("RepoBlueId is unchanged but BlueRepository.blue differs. Please revert manual edits or regenerate from a clean state.");console.log(r.currentRepoBlueId),s(e.json,{repoBlueId:r.currentRepoBlueId,changed:r.changed||!n})}catch(e){const o=e instanceof Error?e.message:"Unknown error encountered.";console.error(o),process.exit(1)}}p();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as x from "path";
|
|
2
2
|
import A from "path";
|
|
3
3
|
import b from "fs";
|
|
4
|
-
import { Properties as
|
|
5
|
-
import { OBJECT_CONTRACTS as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
const
|
|
4
|
+
import { Properties as D, yamlBlueParse as j, MergingProcessors as m, Blue as M, createNodeProvider as L, BlueIdCalculator as F } from "@blue-labs/language";
|
|
5
|
+
import { OBJECT_CONTRACTS as G, RESERVED_ATTRIBUTES_POINTER_SEGMENTS as Y, validateAttributesAddedPointer as W, parsePointer as q, OBJECT_SCHEMA as T, validateNoCycles as J, validateStableDoesNotDependOnDev as z } from "@blue-labs/repository-contract";
|
|
6
|
+
import H from "fast-json-patch";
|
|
7
|
+
import K from "js-yaml";
|
|
8
|
+
const N = /* @__PURE__ */ new Set([...D.CORE_TYPES]), k = D.CORE_TYPE_NAME_TO_BLUE_ID_MAP, R = "Blue Repository", l = {
|
|
9
9
|
Dev: "dev",
|
|
10
10
|
Stable: "stable"
|
|
11
|
-
},
|
|
11
|
+
}, X = /* @__PURE__ */ new Set([
|
|
12
12
|
".git",
|
|
13
13
|
".github",
|
|
14
14
|
".husky",
|
|
@@ -17,22 +17,22 @@ const k = /* @__PURE__ */ new Set([...M.CORE_TYPES]), N = M.CORE_TYPE_NAME_TO_BL
|
|
|
17
17
|
".vscode",
|
|
18
18
|
".idea"
|
|
19
19
|
]);
|
|
20
|
-
function
|
|
20
|
+
function Q(e) {
|
|
21
21
|
const s = b.readdirSync(e, { withFileTypes: !0 }), t = /* @__PURE__ */ new Map();
|
|
22
22
|
for (const n of s) {
|
|
23
|
-
if (!n.isDirectory() ||
|
|
23
|
+
if (!n.isDirectory() || X.has(n.name))
|
|
24
24
|
continue;
|
|
25
|
-
const r = A.join(e, n.name), o =
|
|
25
|
+
const r = A.join(e, n.name), o = C(r);
|
|
26
26
|
if (o.length !== 0)
|
|
27
27
|
for (const i of o) {
|
|
28
|
-
const c = i.endsWith(".dev.blue") ? l.Dev : l.Stable, a =
|
|
28
|
+
const c = i.endsWith(".dev.blue") ? l.Dev : l.Stable, a = Z(i), u = ee(a, i), f = `${n.name}/${u}`, p = t.get(f);
|
|
29
29
|
if (p)
|
|
30
30
|
throw p.status !== c ? new Error(
|
|
31
31
|
`Type ${f} has both stable and dev definitions (${p.filePath} and ${i}).`
|
|
32
32
|
) : new Error(
|
|
33
33
|
`Type ${f} is defined multiple times (${p.filePath} and ${i}).`
|
|
34
34
|
);
|
|
35
|
-
const d =
|
|
35
|
+
const d = te(a, i);
|
|
36
36
|
t.set(f, {
|
|
37
37
|
packageName: n.name,
|
|
38
38
|
typeName: u,
|
|
@@ -45,38 +45,38 @@ function K(e) {
|
|
|
45
45
|
}
|
|
46
46
|
return t;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
const s = b.readFileSync(e, "utf8"), t =
|
|
50
|
-
if (!
|
|
48
|
+
function Z(e) {
|
|
49
|
+
const s = b.readFileSync(e, "utf8"), t = j(s);
|
|
50
|
+
if (!V(t))
|
|
51
51
|
throw new Error(`Type file ${e} must contain a YAML object.`);
|
|
52
52
|
return t;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
if (!
|
|
54
|
+
function ee(e, s) {
|
|
55
|
+
if (!V(e) || typeof e.name != "string")
|
|
56
56
|
throw new Error(`Type file ${s} is missing required "name" field.`);
|
|
57
57
|
return e.name;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function C(e) {
|
|
60
60
|
const s = b.readdirSync(e, { withFileTypes: !0 }), t = [];
|
|
61
61
|
for (const n of s) {
|
|
62
62
|
if (n.isDirectory()) {
|
|
63
|
-
t.push(...
|
|
63
|
+
t.push(...C(A.join(e, n.name)));
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
(n.name.endsWith(".blue") || n.name.endsWith(".dev.blue")) && t.push(A.join(e, n.name));
|
|
67
67
|
}
|
|
68
68
|
return t;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function te(e, s) {
|
|
71
71
|
const t = /* @__PURE__ */ new Set(), n = (r) => {
|
|
72
72
|
if (Array.isArray(r)) {
|
|
73
73
|
r.forEach((i) => n(i));
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
if (!
|
|
76
|
+
if (!V(r))
|
|
77
77
|
return;
|
|
78
78
|
const o = (i) => {
|
|
79
|
-
if (typeof i == "string" && !
|
|
79
|
+
if (typeof i == "string" && !N.has(i)) {
|
|
80
80
|
if (!i.includes("/"))
|
|
81
81
|
throw new Error(
|
|
82
82
|
`Invalid type reference "${i}" in ${s}. Use <Package>/<Type> for non-primitive references.`
|
|
@@ -88,10 +88,10 @@ function Z(e, s) {
|
|
|
88
88
|
};
|
|
89
89
|
return n(e), t;
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function V(e) {
|
|
92
92
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function ne(e) {
|
|
95
95
|
const s = /* @__PURE__ */ new Map();
|
|
96
96
|
for (const [t, n] of e) {
|
|
97
97
|
const r = /* @__PURE__ */ new Set();
|
|
@@ -106,7 +106,7 @@ function ee(e) {
|
|
|
106
106
|
}
|
|
107
107
|
return s;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function re(e) {
|
|
110
110
|
const s = [], t = /* @__PURE__ */ new Map(), n = (r, o) => {
|
|
111
111
|
const i = t.get(r);
|
|
112
112
|
if (i === "visited")
|
|
@@ -125,7 +125,7 @@ function te(e) {
|
|
|
125
125
|
t.has(r) || n(r, []);
|
|
126
126
|
return s;
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function se(e, s) {
|
|
129
129
|
const t = /* @__PURE__ */ new Map(), n = (r) => {
|
|
130
130
|
if (t.has(r))
|
|
131
131
|
return t.get(r) ?? !1;
|
|
@@ -160,33 +160,69 @@ function B(e) {
|
|
|
160
160
|
}
|
|
161
161
|
return e;
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function S(e) {
|
|
164
164
|
return e.map((s) => ({
|
|
165
165
|
repositoryVersionIndex: s.repositoryVersionIndex,
|
|
166
166
|
typeBlueId: s.typeBlueId,
|
|
167
167
|
attributesAdded: [...s.attributesAdded]
|
|
168
168
|
}));
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
const oe = /^\$\{([\s\S]*)\}$/;
|
|
171
|
+
class ie {
|
|
172
|
+
process(s, t) {
|
|
173
|
+
const n = t.getValue();
|
|
174
|
+
if (O(n)) {
|
|
175
|
+
const r = t.clone();
|
|
176
|
+
return r.setValue(n), r.setProperties(void 0), r.setItems(void 0), r.setType(void 0), r;
|
|
177
|
+
}
|
|
178
|
+
return s;
|
|
179
|
+
}
|
|
180
|
+
postProcess(s, t) {
|
|
181
|
+
const n = t.getValue();
|
|
182
|
+
if (O(n) && s.getValue() !== n) {
|
|
183
|
+
const r = s.clone();
|
|
184
|
+
return r.setValue(n), r;
|
|
185
|
+
}
|
|
186
|
+
return s;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function O(e) {
|
|
190
|
+
return typeof e != "string" || !oe.test(e) ? !1 : e.indexOf("${") === e.lastIndexOf("${");
|
|
191
|
+
}
|
|
192
|
+
function ae() {
|
|
193
|
+
return new m.SequentialMergingProcessor([
|
|
194
|
+
new m.ValuePropagator(),
|
|
195
|
+
new ie(),
|
|
196
|
+
new m.TypeAssigner(),
|
|
197
|
+
new m.ListProcessor(),
|
|
198
|
+
new m.DictionaryProcessor(),
|
|
199
|
+
new m.MetadataPropagator(),
|
|
200
|
+
new m.BasicTypesVerifier()
|
|
201
|
+
]);
|
|
202
|
+
}
|
|
203
|
+
function ce(e, s) {
|
|
204
|
+
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), o = new M(), i = L(
|
|
205
|
+
(a) => ue(r, a).map(
|
|
173
206
|
(u) => o.jsonValueToNode(u)
|
|
174
207
|
)
|
|
175
|
-
), c = new
|
|
208
|
+
), c = new M({
|
|
209
|
+
nodeProvider: i,
|
|
210
|
+
mergingProcessor: ae()
|
|
211
|
+
});
|
|
176
212
|
for (const a of e) {
|
|
177
213
|
const u = s.get(a);
|
|
178
214
|
if (!u)
|
|
179
215
|
continue;
|
|
180
|
-
const f =
|
|
216
|
+
const f = P(
|
|
181
217
|
B(u.content),
|
|
182
218
|
t
|
|
183
|
-
), p = c.jsonValueToNode(f), d =
|
|
184
|
-
t.set(a,
|
|
219
|
+
), p = c.jsonValueToNode(f), d = N.has(u.typeName), g = d ? pe(u.typeName) : c.calculateBlueIdSync(p), w = c.nodeToJson(p, "official");
|
|
220
|
+
t.set(a, g), n.set(a, w), d || r.set(g, w), c.registerBlueIds({ [a]: g });
|
|
185
221
|
}
|
|
186
222
|
return { aliasToBlueId: t, aliasToStorageContent: n };
|
|
187
223
|
}
|
|
188
|
-
function
|
|
189
|
-
const t =
|
|
224
|
+
function ue(e, s) {
|
|
225
|
+
const t = fe(s);
|
|
190
226
|
if (t === void 0)
|
|
191
227
|
return [];
|
|
192
228
|
const n = e.get(t.baseBlueId);
|
|
@@ -199,7 +235,7 @@ function se(e, s) {
|
|
|
199
235
|
const r = n[t.index];
|
|
200
236
|
return r === void 0 ? [] : [r];
|
|
201
237
|
}
|
|
202
|
-
function
|
|
238
|
+
function fe(e) {
|
|
203
239
|
const s = e.indexOf("#");
|
|
204
240
|
if (s === -1)
|
|
205
241
|
return { baseBlueId: e };
|
|
@@ -207,10 +243,10 @@ function oe(e) {
|
|
|
207
243
|
if (!(!Number.isInteger(r) || r < 0))
|
|
208
244
|
return { baseBlueId: t, index: r };
|
|
209
245
|
}
|
|
210
|
-
function
|
|
246
|
+
function P(e, s, t = !1, n = !1) {
|
|
211
247
|
if (Array.isArray(e))
|
|
212
248
|
return e.map(
|
|
213
|
-
(o) =>
|
|
249
|
+
(o) => P(
|
|
214
250
|
o,
|
|
215
251
|
s,
|
|
216
252
|
t,
|
|
@@ -221,10 +257,10 @@ function S(e, s, t = !1, n = !1) {
|
|
|
221
257
|
return e;
|
|
222
258
|
const r = {};
|
|
223
259
|
for (const [o, i] of Object.entries(e)) {
|
|
224
|
-
const c = n || o ===
|
|
260
|
+
const c = n || o === G;
|
|
225
261
|
if ((o === "type" || o === "itemType" || o === "keyType" || o === "valueType") && typeof i == "string" && !(t && c)) {
|
|
226
|
-
if (
|
|
227
|
-
const a =
|
|
262
|
+
if (N.has(i)) {
|
|
263
|
+
const a = k[i];
|
|
228
264
|
if (!a)
|
|
229
265
|
throw new Error(`Missing primitive BlueId for ${i}.`);
|
|
230
266
|
r[o] = { blueId: a };
|
|
@@ -236,7 +272,7 @@ function S(e, s, t = !1, n = !1) {
|
|
|
236
272
|
}
|
|
237
273
|
continue;
|
|
238
274
|
}
|
|
239
|
-
r[o] =
|
|
275
|
+
r[o] = P(
|
|
240
276
|
i,
|
|
241
277
|
s,
|
|
242
278
|
t,
|
|
@@ -245,103 +281,103 @@ function S(e, s, t = !1, n = !1) {
|
|
|
245
281
|
}
|
|
246
282
|
return r;
|
|
247
283
|
}
|
|
248
|
-
function
|
|
249
|
-
const s =
|
|
284
|
+
function pe(e) {
|
|
285
|
+
const s = k[e];
|
|
250
286
|
if (!s)
|
|
251
287
|
throw new Error(`Missing primitive BlueId for ${e}.`);
|
|
252
288
|
return s;
|
|
253
289
|
}
|
|
254
|
-
const _ = new Set(Object.values(
|
|
290
|
+
const _ = new Set(Object.values(k)), le = /* @__PURE__ */ new Set([
|
|
255
291
|
"type",
|
|
256
292
|
"itemType",
|
|
257
293
|
"valueType",
|
|
258
294
|
"keyType"
|
|
259
|
-
]),
|
|
295
|
+
]), de = /* @__PURE__ */ new Set(["name", "description"]), h = {
|
|
260
296
|
Unchanged: "unchanged",
|
|
261
297
|
NonBreaking: "non-breaking",
|
|
262
298
|
Breaking: "breaking"
|
|
263
299
|
};
|
|
264
|
-
function
|
|
265
|
-
const o =
|
|
300
|
+
function ye(e, s, t, n, r) {
|
|
301
|
+
const o = H.compare(
|
|
266
302
|
e,
|
|
267
303
|
s
|
|
268
304
|
);
|
|
269
305
|
if (o.length === 0)
|
|
270
|
-
return { status:
|
|
306
|
+
return { status: h.Unchanged, attributesAdded: [] };
|
|
271
307
|
const i = [];
|
|
272
308
|
let c = !1;
|
|
273
309
|
for (const a of o) {
|
|
274
|
-
if (
|
|
310
|
+
if (we(a, e, r)) {
|
|
275
311
|
c = !0;
|
|
276
312
|
continue;
|
|
277
313
|
}
|
|
278
314
|
if (a.op !== "add")
|
|
279
|
-
return { status:
|
|
280
|
-
if (!
|
|
281
|
-
return { status:
|
|
315
|
+
return { status: h.Breaking, attributesAdded: [] };
|
|
316
|
+
if (!me(a))
|
|
317
|
+
return { status: h.Breaking, attributesAdded: [] };
|
|
282
318
|
i.push(a.path);
|
|
283
319
|
}
|
|
284
320
|
return i.length === 0 && !c ? {
|
|
285
|
-
status:
|
|
321
|
+
status: h.Breaking,
|
|
286
322
|
attributesAdded: []
|
|
287
|
-
} : (i.length > 0 &&
|
|
323
|
+
} : (i.length > 0 && ge(i, t, n), { status: h.NonBreaking, attributesAdded: i });
|
|
288
324
|
}
|
|
289
|
-
function
|
|
325
|
+
function ge(e, s, t) {
|
|
290
326
|
for (const n of e)
|
|
291
327
|
try {
|
|
292
|
-
|
|
328
|
+
W(n);
|
|
293
329
|
} catch (r) {
|
|
294
330
|
throw new Error(
|
|
295
331
|
`Invalid attribute pointer "${n}" for ${s}/${t}: ${r.message}`
|
|
296
332
|
);
|
|
297
333
|
}
|
|
298
334
|
}
|
|
299
|
-
function
|
|
335
|
+
function me(e) {
|
|
300
336
|
if (e.op !== "add")
|
|
301
337
|
return !1;
|
|
302
|
-
const s =
|
|
338
|
+
const s = U(e.path);
|
|
303
339
|
if (s.length === 0)
|
|
304
340
|
return !1;
|
|
305
341
|
const t = s.at(-1);
|
|
306
|
-
return t && /^\d+$/.test(t) || t &&
|
|
307
|
-
(n) =>
|
|
308
|
-
) ? !1 : y(e.value) ? !
|
|
342
|
+
return t && /^\d+$/.test(t) || t && le.has(t) || s.some(
|
|
343
|
+
(n) => Y.has(n)
|
|
344
|
+
) ? !1 : y(e.value) ? !he(e.value) : t ? de.has(t) : !1;
|
|
309
345
|
}
|
|
310
|
-
function
|
|
346
|
+
function U(e) {
|
|
311
347
|
try {
|
|
312
|
-
return
|
|
348
|
+
return q(e);
|
|
313
349
|
} catch {
|
|
314
350
|
return [];
|
|
315
351
|
}
|
|
316
352
|
}
|
|
317
|
-
function
|
|
353
|
+
function he(e) {
|
|
318
354
|
const s = [e];
|
|
319
355
|
for (; s.length; ) {
|
|
320
356
|
const t = s.pop();
|
|
321
357
|
if (t) {
|
|
322
358
|
if (Object.prototype.hasOwnProperty.call(t, "value") || Object.prototype.hasOwnProperty.call(t, "items"))
|
|
323
359
|
return !0;
|
|
324
|
-
if (Object.prototype.hasOwnProperty.call(t,
|
|
325
|
-
const n = t[
|
|
360
|
+
if (Object.prototype.hasOwnProperty.call(t, T)) {
|
|
361
|
+
const n = t[T];
|
|
326
362
|
if (y(n) && n.required === !0)
|
|
327
363
|
return !0;
|
|
328
364
|
}
|
|
329
365
|
for (const [n, r] of Object.entries(t))
|
|
330
|
-
n !==
|
|
366
|
+
n !== T && y(r) && s.push(r);
|
|
331
367
|
}
|
|
332
368
|
}
|
|
333
369
|
return !1;
|
|
334
370
|
}
|
|
335
|
-
function
|
|
371
|
+
function we(e, s, t) {
|
|
336
372
|
if (e.op !== "replace" || typeof e.path != "string")
|
|
337
373
|
return !1;
|
|
338
|
-
const n =
|
|
374
|
+
const n = U(e.path);
|
|
339
375
|
if (n.length < 2)
|
|
340
376
|
return !1;
|
|
341
377
|
const r = n.at(-1), o = n.at(-2);
|
|
342
378
|
if (!(r === "blueId" && o !== void 0 && (o === "type" || o === "itemType" || o === "keyType" || o === "valueType")))
|
|
343
379
|
return !1;
|
|
344
|
-
const i =
|
|
380
|
+
const i = ve(s, n), c = typeof i == "string" ? i : y(i) && typeof i.blueId == "string" ? i.blueId : null, a = typeof e.value == "string" ? e.value : y(e.value) && typeof e.value.blueId == "string" ? e.value.blueId : null;
|
|
345
381
|
if (c && _.has(c) || a && _.has(a) || !c || !a)
|
|
346
382
|
return !1;
|
|
347
383
|
const u = t.get(c), f = t.get(a);
|
|
@@ -352,7 +388,7 @@ function de(e, s, t) {
|
|
|
352
388
|
return !0;
|
|
353
389
|
return !1;
|
|
354
390
|
}
|
|
355
|
-
function
|
|
391
|
+
function ve(e, s) {
|
|
356
392
|
let t = e;
|
|
357
393
|
for (const n of s)
|
|
358
394
|
if (Array.isArray(t)) {
|
|
@@ -366,7 +402,7 @@ function ye(e, s) {
|
|
|
366
402
|
return;
|
|
367
403
|
return t;
|
|
368
404
|
}
|
|
369
|
-
function
|
|
405
|
+
function be(e) {
|
|
370
406
|
const s = /* @__PURE__ */ new Map();
|
|
371
407
|
if (!e)
|
|
372
408
|
return s;
|
|
@@ -382,7 +418,7 @@ function me(e) {
|
|
|
382
418
|
}
|
|
383
419
|
return s;
|
|
384
420
|
}
|
|
385
|
-
function
|
|
421
|
+
function Ie(e, s) {
|
|
386
422
|
for (const [t, n] of s)
|
|
387
423
|
for (const [r, o] of n) {
|
|
388
424
|
const i = `${t}/${r}`;
|
|
@@ -392,14 +428,14 @@ function ge(e, s) {
|
|
|
392
428
|
);
|
|
393
429
|
}
|
|
394
430
|
}
|
|
395
|
-
function
|
|
431
|
+
function Ee({
|
|
396
432
|
discovered: e,
|
|
397
433
|
previousTypes: s,
|
|
398
434
|
aliasToBlueId: t,
|
|
399
435
|
aliasToStorageContent: n,
|
|
400
436
|
nextRepoVersionIndex: r
|
|
401
437
|
}) {
|
|
402
|
-
const o = /* @__PURE__ */ new Map(), i =
|
|
438
|
+
const o = /* @__PURE__ */ new Map(), i = Te(s, t);
|
|
403
439
|
for (const [c, a] of e) {
|
|
404
440
|
const u = t.get(c);
|
|
405
441
|
if (!u)
|
|
@@ -409,7 +445,7 @@ function he({
|
|
|
409
445
|
throw new Error(
|
|
410
446
|
`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`
|
|
411
447
|
);
|
|
412
|
-
const p = n.get(c) ?? a.content, d = a.status === l.Dev ?
|
|
448
|
+
const p = n.get(c) ?? a.content, d = a.status === l.Dev ? Ae({ blueId: u, nextRepoVersionIndex: r, previousType: f }) : !f || f.status === l.Dev ? Be({ blueId: u, nextRepoVersionIndex: r }) : Se({
|
|
413
449
|
alias: c,
|
|
414
450
|
blueId: u,
|
|
415
451
|
nextRepoVersionIndex: r,
|
|
@@ -420,12 +456,12 @@ function he({
|
|
|
420
456
|
blueIdAliases: i
|
|
421
457
|
});
|
|
422
458
|
d.content = p, d.status = a.status;
|
|
423
|
-
const
|
|
424
|
-
|
|
459
|
+
const g = o.get(a.packageName) ?? [];
|
|
460
|
+
g.push(d), o.set(a.packageName, g);
|
|
425
461
|
}
|
|
426
462
|
return o;
|
|
427
463
|
}
|
|
428
|
-
function
|
|
464
|
+
function Te(e, s) {
|
|
429
465
|
const t = /* @__PURE__ */ new Map(), n = (r, o) => {
|
|
430
466
|
const i = t.get(r);
|
|
431
467
|
if (i) {
|
|
@@ -444,7 +480,7 @@ function ve(e, s) {
|
|
|
444
480
|
n(o, r);
|
|
445
481
|
return t;
|
|
446
482
|
}
|
|
447
|
-
function
|
|
483
|
+
function Ae({
|
|
448
484
|
blueId: e,
|
|
449
485
|
nextRepoVersionIndex: s,
|
|
450
486
|
previousType: t
|
|
@@ -453,7 +489,7 @@ function be({
|
|
|
453
489
|
return {
|
|
454
490
|
status: l.Dev,
|
|
455
491
|
content: {},
|
|
456
|
-
versions: o && n?.versions ?
|
|
492
|
+
versions: o && n?.versions ? S(n.versions) : [
|
|
457
493
|
{
|
|
458
494
|
repositoryVersionIndex: s,
|
|
459
495
|
typeBlueId: e,
|
|
@@ -462,7 +498,7 @@ function be({
|
|
|
462
498
|
]
|
|
463
499
|
};
|
|
464
500
|
}
|
|
465
|
-
function
|
|
501
|
+
function Be({
|
|
466
502
|
blueId: e,
|
|
467
503
|
nextRepoVersionIndex: s
|
|
468
504
|
}) {
|
|
@@ -478,7 +514,7 @@ function we({
|
|
|
478
514
|
]
|
|
479
515
|
};
|
|
480
516
|
}
|
|
481
|
-
function
|
|
517
|
+
function Se({
|
|
482
518
|
alias: e,
|
|
483
519
|
blueId: s,
|
|
484
520
|
nextRepoVersionIndex: t,
|
|
@@ -492,15 +528,15 @@ function Ie({
|
|
|
492
528
|
throw new Error(
|
|
493
529
|
`Type ${e} has non-object content; cannot compute diff for stable versioning.`
|
|
494
530
|
);
|
|
495
|
-
const a =
|
|
531
|
+
const a = ye(
|
|
496
532
|
n.content,
|
|
497
533
|
r,
|
|
498
534
|
o,
|
|
499
535
|
i,
|
|
500
536
|
c
|
|
501
537
|
);
|
|
502
|
-
if (a.status ===
|
|
503
|
-
const u =
|
|
538
|
+
if (a.status === h.Unchanged) {
|
|
539
|
+
const u = S(n.versions || []), f = u.at(-1);
|
|
504
540
|
if (f && f.typeBlueId !== s)
|
|
505
541
|
throw new Error(
|
|
506
542
|
`Type ${e} content is unchanged but BlueId differs from previous metadata.`
|
|
@@ -511,12 +547,12 @@ function Ie({
|
|
|
511
547
|
versions: u
|
|
512
548
|
};
|
|
513
549
|
}
|
|
514
|
-
if (a.status ===
|
|
550
|
+
if (a.status === h.NonBreaking)
|
|
515
551
|
return {
|
|
516
552
|
status: l.Stable,
|
|
517
553
|
content: {},
|
|
518
554
|
versions: [
|
|
519
|
-
...
|
|
555
|
+
...S(n.versions || []),
|
|
520
556
|
{
|
|
521
557
|
repositoryVersionIndex: t,
|
|
522
558
|
typeBlueId: s,
|
|
@@ -528,7 +564,7 @@ function Ie({
|
|
|
528
564
|
`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`
|
|
529
565
|
);
|
|
530
566
|
}
|
|
531
|
-
function
|
|
567
|
+
function Pe(e) {
|
|
532
568
|
return Array.from(e.entries()).map(([s, t]) => ({
|
|
533
569
|
name: s,
|
|
534
570
|
types: t.map((n) => ({
|
|
@@ -542,38 +578,38 @@ function Ee(e) {
|
|
|
542
578
|
})
|
|
543
579
|
})).sort((s, t) => s.name.localeCompare(t.name));
|
|
544
580
|
}
|
|
545
|
-
function
|
|
546
|
-
return
|
|
581
|
+
function Ne(e) {
|
|
582
|
+
return F.INSTANCE.calculateSync(
|
|
547
583
|
e
|
|
548
584
|
);
|
|
549
585
|
}
|
|
550
|
-
function
|
|
586
|
+
function ke(e, s, t) {
|
|
551
587
|
const n = s?.repositoryVersions.at(-1), r = !n || n !== t, o = s?.repositoryVersions ? [...s.repositoryVersions] : [];
|
|
552
588
|
return r && o.push(t), { document: {
|
|
553
|
-
name:
|
|
589
|
+
name: R,
|
|
554
590
|
packages: e,
|
|
555
591
|
repositoryVersions: o
|
|
556
592
|
}, changed: r };
|
|
557
593
|
}
|
|
558
|
-
function
|
|
594
|
+
function Re(e, s, t) {
|
|
559
595
|
const n = {
|
|
560
|
-
name:
|
|
596
|
+
name: R,
|
|
561
597
|
repositoryVersions: s,
|
|
562
|
-
packages:
|
|
598
|
+
packages: Ve(e, t)
|
|
563
599
|
};
|
|
564
|
-
|
|
600
|
+
J(n), z(n);
|
|
565
601
|
}
|
|
566
|
-
function
|
|
602
|
+
function Ve(e, s) {
|
|
567
603
|
const t = {};
|
|
568
604
|
for (const n of e) {
|
|
569
|
-
const r =
|
|
605
|
+
const r = $e(n.name, s), o = {}, i = {};
|
|
570
606
|
for (const c of n.types) {
|
|
571
607
|
const a = c.versions?.[c.versions.length - 1]?.typeBlueId;
|
|
572
608
|
if (!a)
|
|
573
609
|
throw new Error(
|
|
574
610
|
`Type ${n.name} is missing a current BlueId in versions.`
|
|
575
611
|
);
|
|
576
|
-
const u =
|
|
612
|
+
const u = xe(c);
|
|
577
613
|
o[a] = {
|
|
578
614
|
status: c.status,
|
|
579
615
|
name: u,
|
|
@@ -590,22 +626,22 @@ function Se(e, s) {
|
|
|
590
626
|
}
|
|
591
627
|
return t;
|
|
592
628
|
}
|
|
593
|
-
function
|
|
629
|
+
function $e(e, s) {
|
|
594
630
|
const t = {}, n = `${e}/`;
|
|
595
631
|
return s.forEach((r, o) => {
|
|
596
632
|
o.startsWith(n) && (t[o] = r);
|
|
597
633
|
}), t;
|
|
598
634
|
}
|
|
599
|
-
function
|
|
635
|
+
function xe(e) {
|
|
600
636
|
const s = v(e.content) && typeof e.content.name == "string" ? e.content.name : null;
|
|
601
637
|
if (!s)
|
|
602
638
|
throw new Error('Type content is missing required "name" field.');
|
|
603
639
|
return s;
|
|
604
640
|
}
|
|
605
|
-
function
|
|
641
|
+
function Me(e) {
|
|
606
642
|
if (!b.existsSync(e))
|
|
607
643
|
return { previous: null };
|
|
608
|
-
const s = b.readFileSync(e, "utf8"), t =
|
|
644
|
+
const s = b.readFileSync(e, "utf8"), t = j(s);
|
|
609
645
|
if (!t || !y(t))
|
|
610
646
|
throw new Error("Existing BlueRepository.blue is not a valid object.");
|
|
611
647
|
const n = t, r = n.packages, o = n.repositoryVersions, i = Array.isArray(r) && r.every(
|
|
@@ -616,55 +652,55 @@ function Pe(e) {
|
|
|
616
652
|
"Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }"
|
|
617
653
|
);
|
|
618
654
|
const a = r, u = o, f = {
|
|
619
|
-
name: typeof n.name == "string" ? n.name :
|
|
655
|
+
name: typeof n.name == "string" ? n.name : R,
|
|
620
656
|
packages: a,
|
|
621
657
|
repositoryVersions: u
|
|
622
658
|
};
|
|
623
659
|
return { existingYaml: s, previous: f };
|
|
624
660
|
}
|
|
625
|
-
function
|
|
626
|
-
return
|
|
661
|
+
function Oe(e) {
|
|
662
|
+
return K.dump(e, { lineWidth: -1 });
|
|
627
663
|
}
|
|
628
|
-
function
|
|
629
|
-
const s =
|
|
630
|
-
|
|
631
|
-
const c =
|
|
632
|
-
|
|
633
|
-
const { aliasToBlueId: u, aliasToStorageContent: f } =
|
|
664
|
+
function Fe(e) {
|
|
665
|
+
const s = x.resolve(e.repoRoot), t = x.resolve(e.blueRepositoryPath), { existingYaml: n, previous: r } = Me(t), o = Q(s), i = be(r);
|
|
666
|
+
Ie(o, i);
|
|
667
|
+
const c = ne(o), a = re(c);
|
|
668
|
+
se(c, o);
|
|
669
|
+
const { aliasToBlueId: u, aliasToStorageContent: f } = ce(
|
|
634
670
|
a,
|
|
635
671
|
o
|
|
636
|
-
), p = r ? r.repositoryVersions.length : 0, d =
|
|
672
|
+
), p = r ? r.repositoryVersions.length : 0, d = Ee({
|
|
637
673
|
discovered: o,
|
|
638
674
|
previousTypes: i,
|
|
639
675
|
aliasToBlueId: u,
|
|
640
676
|
aliasToStorageContent: f,
|
|
641
677
|
nextRepoVersionIndex: p
|
|
642
|
-
}),
|
|
643
|
-
|
|
678
|
+
}), g = Pe(d), w = Ne(g), { document: I, changed: E } = ke(
|
|
679
|
+
g,
|
|
644
680
|
r,
|
|
645
|
-
|
|
681
|
+
w
|
|
646
682
|
);
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
683
|
+
Re(
|
|
684
|
+
I.packages,
|
|
685
|
+
I.repositoryVersions,
|
|
650
686
|
u
|
|
651
687
|
);
|
|
652
|
-
const $ =
|
|
653
|
-
if (r && !
|
|
688
|
+
const $ = Oe(I);
|
|
689
|
+
if (r && !E && n && n !== $)
|
|
654
690
|
throw new Error(
|
|
655
691
|
"BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode."
|
|
656
692
|
);
|
|
657
693
|
return e.verbose && console.info(
|
|
658
|
-
`[repository-generator] RepoBlueId: ${
|
|
694
|
+
`[repository-generator] RepoBlueId: ${w} (${E ? "changed" : "unchanged"})`
|
|
659
695
|
), {
|
|
660
|
-
document:
|
|
661
|
-
currentRepoBlueId:
|
|
696
|
+
document: I,
|
|
697
|
+
currentRepoBlueId: w,
|
|
662
698
|
previousRepoBlueId: r?.repositoryVersions.at(-1),
|
|
663
|
-
changed:
|
|
699
|
+
changed: E || !n,
|
|
664
700
|
yaml: $,
|
|
665
701
|
existingYaml: n
|
|
666
702
|
};
|
|
667
703
|
}
|
|
668
704
|
export {
|
|
669
|
-
|
|
705
|
+
Fe as g
|
|
670
706
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const T=require("path"),I=require("fs"),p=require("@blue-labs/language"),h=require("@blue-labs/repository-contract"),j=require("fast-json-patch"),C=require("js-yaml");function U(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return s.default=e,Object.freeze(s)}const $=U(T),N=new Set([...p.Properties.CORE_TYPES]),k=p.Properties.CORE_TYPE_NAME_TO_BLUE_ID_MAP,M="Blue Repository",d={Dev:"dev",Stable:"stable"},q=new Set([".git",".github",".husky","node_modules",".nx",".vscode",".idea"]);function L(e){const s=I.readdirSync(e,{withFileTypes:!0}),t=new Map;for(const n of s){if(!n.isDirectory()||q.has(n.name))continue;const r=T.join(e,n.name),o=_(r);if(o.length!==0)for(const i of o){const c=i.endsWith(".dev.blue")?d.Dev:d.Stable,a=F(i),u=G(a,i),f=`${n.name}/${u}`,l=t.get(f);if(l)throw l.status!==c?new Error(`Type ${f} has both stable and dev definitions (${l.filePath} and ${i}).`):new Error(`Type ${f} is defined multiple times (${l.filePath} and ${i}).`);const y=Y(a,i);t.set(f,{packageName:n.name,typeName:u,status:c,content:a,filePath:i,references:y})}}return t}function F(e){const s=I.readFileSync(e,"utf8"),t=p.yamlBlueParse(s);if(!R(t))throw new Error(`Type file ${e} must contain a YAML object.`);return t}function G(e,s){if(!R(e)||typeof e.name!="string")throw new Error(`Type file ${s} is missing required "name" field.`);return e.name}function _(e){const s=I.readdirSync(e,{withFileTypes:!0}),t=[];for(const n of s){if(n.isDirectory()){t.push(..._(T.join(e,n.name)));continue}(n.name.endsWith(".blue")||n.name.endsWith(".dev.blue"))&&t.push(T.join(e,n.name))}return t}function Y(e,s){const t=new Set,n=r=>{if(Array.isArray(r)){r.forEach(i=>n(i));return}if(!R(r))return;const o=i=>{if(typeof i=="string"&&!N.has(i)){if(!i.includes("/"))throw new Error(`Invalid type reference "${i}" in ${s}. Use <Package>/<Type> for non-primitive references.`);t.add(i)}};o(r.type),o(r.itemType),o(r.keyType),o(r.valueType),Object.values(r).forEach(i=>n(i))};return n(e),t}function R(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function J(e){const s=new Map;for(const[t,n]of e){const r=new Set;for(const o of n.references){if(!e.has(o))throw new Error(`Type ${t} references unknown alias ${o}. Ensure the target type exists.`);r.add(o)}s.set(t,r)}return s}function W(e){const s=[],t=new Map,n=(r,o)=>{const i=t.get(r);if(i==="visited")return;if(i==="visiting"){const a=[...o,r].join(" -> ");throw new Error(`Circular type dependency detected: ${a}`)}t.set(r,"visiting"),o.push(r);const c=e.get(r)||new Set;for(const a of c)n(a,o);o.pop(),t.set(r,"visited"),s.push(r)};for(const r of e.keys())t.has(r)||n(r,[]);return s}function H(e,s){const t=new Map,n=r=>{if(t.has(r))return t.get(r)??!1;const o=e.get(r)||new Set;for(const i of o){const c=s.get(i);if(c&&(c.status===d.Dev||n(i)))return t.set(r,!0),!0}return t.set(r,!1),!1};for(const[r,o]of s)if(o.status===d.Stable&&n(r))throw new Error(`Stable type ${r} depends on a dev type. Stable types may only depend on other stable types.`)}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e){return g(e)?Object.getPrototypeOf(e)===Object.prototype:!1}function A(e){if(Array.isArray(e))return e.map(s=>A(s));if(v(e)){const s={};for(const[t,n]of Object.entries(e))s[t]=A(n);return s}return e}function P(e){return e.map(s=>({repositoryVersionIndex:s.repositoryVersionIndex,typeBlueId:s.typeBlueId,attributesAdded:[...s.attributesAdded]}))}const z=/^\$\{([\s\S]*)\}$/;class K{process(s,t){const n=t.getValue();if(O(n)){const r=t.clone();return r.setValue(n),r.setProperties(void 0),r.setItems(void 0),r.setType(void 0),r}return s}postProcess(s,t){const n=t.getValue();if(O(n)&&s.getValue()!==n){const r=s.clone();return r.setValue(n),r}return s}}function O(e){return typeof e!="string"||!z.test(e)?!1:e.indexOf("${")===e.lastIndexOf("${")}function X(){return new p.MergingProcessors.SequentialMergingProcessor([new p.MergingProcessors.ValuePropagator,new K,new p.MergingProcessors.TypeAssigner,new p.MergingProcessors.ListProcessor,new p.MergingProcessors.DictionaryProcessor,new p.MergingProcessors.MetadataPropagator,new p.MergingProcessors.BasicTypesVerifier])}function Q(e,s){const t=new Map,n=new Map,r=new Map,o=new p.Blue,i=p.createNodeProvider(a=>Z(r,a).map(u=>o.jsonValueToNode(u))),c=new p.Blue({nodeProvider:i,mergingProcessor:X()});for(const a of e){const u=s.get(a);if(!u)continue;const f=S(A(u.content),t),l=c.jsonValueToNode(f),y=N.has(u.typeName),m=y?te(u.typeName):c.calculateBlueIdSync(l),w=c.nodeToJson(l,"official");t.set(a,m),n.set(a,w),y||r.set(m,w),c.registerBlueIds({[a]:m})}return{aliasToBlueId:t,aliasToStorageContent:n}}function Z(e,s){const t=ee(s);if(t===void 0)return[];const n=e.get(t.baseBlueId);if(n===void 0)return[];if(t.index===void 0)return Array.isArray(n)?n:[n];if(!Array.isArray(n))return t.index===0?[n]:[];const r=n[t.index];return r===void 0?[]:[r]}function ee(e){const s=e.indexOf("#");if(s===-1)return{baseBlueId:e};const t=e.slice(0,s),n=e.slice(s+1),r=Number(n);if(!(!Number.isInteger(r)||r<0))return{baseBlueId:t,index:r}}function S(e,s,t=!1,n=!1){if(Array.isArray(e))return e.map(o=>S(o,s,t,n));if(!g(e))return e;const r={};for(const[o,i]of Object.entries(e)){const c=n||o===h.OBJECT_CONTRACTS;if((o==="type"||o==="itemType"||o==="keyType"||o==="valueType")&&typeof i=="string"&&!(t&&c)){if(N.has(i)){const a=k[i];if(!a)throw new Error(`Missing primitive BlueId for ${i}.`);r[o]={blueId:a}}else{const a=i,u=s.get(a);if(!u)throw new Error(`Missing BlueId for alias ${a}.`);r[o]={blueId:u}}continue}r[o]=S(i,s,t,c)}return r}function te(e){const s=k[e];if(!s)throw new Error(`Missing primitive BlueId for ${e}.`);return s}const x=new Set(Object.values(k)),ne=new Set(["type","itemType","valueType","keyType"]),re=new Set(["name","description"]),b={Unchanged:"unchanged",NonBreaking:"non-breaking",Breaking:"breaking"};function se(e,s,t,n,r){const o=j.compare(e,s);if(o.length===0)return{status:b.Unchanged,attributesAdded:[]};const i=[];let c=!1;for(const a of o){if(ce(a,e,r)){c=!0;continue}if(a.op!=="add")return{status:b.Breaking,attributesAdded:[]};if(!ie(a))return{status:b.Breaking,attributesAdded:[]};i.push(a.path)}return i.length===0&&!c?{status:b.Breaking,attributesAdded:[]}:(i.length>0&&oe(i,t,n),{status:b.NonBreaking,attributesAdded:i})}function oe(e,s,t){for(const n of e)try{h.validateAttributesAddedPointer(n)}catch(r){throw new Error(`Invalid attribute pointer "${n}" for ${s}/${t}: ${r.message}`)}}function ie(e){if(e.op!=="add")return!1;const s=D(e.path);if(s.length===0)return!1;const t=s.at(-1);return t&&/^\d+$/.test(t)||t&&ne.has(t)||s.some(n=>h.RESERVED_ATTRIBUTES_POINTER_SEGMENTS.has(n))?!1:g(e.value)?!ae(e.value):t?re.has(t):!1}function D(e){try{return h.parsePointer(e)}catch{return[]}}function ae(e){const s=[e];for(;s.length;){const t=s.pop();if(t){if(Object.prototype.hasOwnProperty.call(t,"value")||Object.prototype.hasOwnProperty.call(t,"items"))return!0;if(Object.prototype.hasOwnProperty.call(t,h.OBJECT_SCHEMA)){const n=t[h.OBJECT_SCHEMA];if(g(n)&&n.required===!0)return!0}for(const[n,r]of Object.entries(t))n!==h.OBJECT_SCHEMA&&g(r)&&s.push(r)}}return!1}function ce(e,s,t){if(e.op!=="replace"||typeof e.path!="string")return!1;const n=D(e.path);if(n.length<2)return!1;const r=n.at(-1),o=n.at(-2);if(!(r==="blueId"&&o!==void 0&&(o==="type"||o==="itemType"||o==="keyType"||o==="valueType")))return!1;const i=ue(s,n),c=typeof i=="string"?i:g(i)&&typeof i.blueId=="string"?i.blueId:null,a=typeof e.value=="string"?e.value:g(e.value)&&typeof e.value.blueId=="string"?e.value.blueId:null;if(c&&x.has(c)||a&&x.has(a)||!c||!a)return!1;const u=t.get(c),f=t.get(a);if(!u||!f)return!1;for(const l of u)if(f.has(l))return!0;return!1}function ue(e,s){let t=e;for(const n of s)if(Array.isArray(t)){const r=Number(n);if(Number.isNaN(r)||r<0||r>=t.length)return;t=t[r]}else if(g(t))t=t[n];else return;return t}function fe(e){const s=new Map;if(!e)return s;for(const t of e.packages||[]){if(typeof t.name!="string")continue;const n=new Map;for(const r of t.types||[]){const o=r.content,i=v(o)&&typeof o.name=="string"?o.name:void 0;i&&n.set(i,r)}s.set(t.name,n)}return s}function le(e,s){for(const[t,n]of s)for(const[r,o]of n){const i=`${t}/${r}`;if(!e.has(i)&&o.status===d.Stable)throw new Error(`Stable type ${i} was removed. Breaking changes require a new logical type name.`)}}function pe({discovered:e,previousTypes:s,aliasToBlueId:t,aliasToStorageContent:n,nextRepoVersionIndex:r}){const o=new Map,i=de(s,t);for(const[c,a]of e){const u=t.get(c);if(!u)throw new Error(`Failed to compute BlueId for type ${c}.`);const f=s.get(a.packageName)?.get(a.typeName)??null;if(f&&f.status===d.Stable&&a.status===d.Dev)throw new Error(`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`);const l=n.get(c)??a.content,y=a.status===d.Dev?ye({blueId:u,nextRepoVersionIndex:r,previousType:f}):!f||f.status===d.Dev?ge({blueId:u,nextRepoVersionIndex:r}):me({alias:c,blueId:u,nextRepoVersionIndex:r,previousType:f,currentContent:l,packageName:a.packageName,typeName:a.typeName,blueIdAliases:i});y.content=l,y.status=a.status;const m=o.get(a.packageName)??[];m.push(y),o.set(a.packageName,m)}return o}function de(e,s){const t=new Map,n=(r,o)=>{const i=t.get(r);if(i){i.add(o);return}t.set(r,new Set([o]))};for(const[r,o]of e)for(const[i,c]of o){const a=`${r}/${i}`;for(const u of c.versions??[])typeof u.typeBlueId=="string"&&n(u.typeBlueId,a)}for(const[r,o]of s)n(o,r);return t}function ye({blueId:e,nextRepoVersionIndex:s,previousType:t}){const n=t&&t.status===d.Dev?t:null,r=n?.versions?.length===1?n.versions[0]:null,o=r&&r.typeBlueId===e;return{status:d.Dev,content:{},versions:o&&n?.versions?P(n.versions):[{repositoryVersionIndex:s,typeBlueId:e,attributesAdded:[]}]}}function ge({blueId:e,nextRepoVersionIndex:s}){return{status:d.Stable,content:{},versions:[{repositoryVersionIndex:s,typeBlueId:e,attributesAdded:[]}]}}function me({alias:e,blueId:s,nextRepoVersionIndex:t,previousType:n,currentContent:r,packageName:o,typeName:i,blueIdAliases:c}){if(!v(n.content))throw new Error(`Type ${e} has non-object content; cannot compute diff for stable versioning.`);const a=se(n.content,r,o,i,c);if(a.status===b.Unchanged){const u=P(n.versions||[]),f=u.at(-1);if(f&&f.typeBlueId!==s)throw new Error(`Type ${e} content is unchanged but BlueId differs from previous metadata.`);return{status:d.Stable,content:{},versions:u}}if(a.status===b.NonBreaking)return{status:d.Stable,content:{},versions:[...P(n.versions||[]),{repositoryVersionIndex:t,typeBlueId:s,attributesAdded:a.attributesAdded}]};throw new Error(`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`)}function he(e){return Array.from(e.entries()).map(([s,t])=>({name:s,types:t.map(n=>({...n,versions:[...n.versions].sort((r,o)=>r.repositoryVersionIndex-o.repositoryVersionIndex)})).sort((n,r)=>{const o=v(n.content)&&typeof n.content.name=="string"?n.content.name:"",i=v(r.content)&&typeof r.content.name=="string"?r.content.name:"";return o.localeCompare(i)})})).sort((s,t)=>s.name.localeCompare(t.name))}function be(e){return p.BlueIdCalculator.INSTANCE.calculateSync(e)}function we(e,s,t){const n=s?.repositoryVersions.at(-1),r=!n||n!==t,o=s?.repositoryVersions?[...s.repositoryVersions]:[];return r&&o.push(t),{document:{name:M,packages:e,repositoryVersions:o},changed:r}}function ve(e,s,t){const n={name:M,repositoryVersions:s,packages:Ie(e,t)};h.validateNoCycles(n),h.validateStableDoesNotDependOnDev(n)}function Ie(e,s){const t={};for(const n of e){const r=Ee(n.name,s),o={},i={};for(const c of n.types){const a=c.versions?.[c.versions.length-1]?.typeBlueId;if(!a)throw new Error(`Type ${n.name} is missing a current BlueId in versions.`);const u=Te(c);o[a]={status:c.status,name:u,versions:c.versions??[]},i[a]=c.content}t[n.name]={name:n.name,aliases:r,typesMeta:o,contents:i,schemas:{}}}return t}function Ee(e,s){const t={},n=`${e}/`;return s.forEach((r,o)=>{o.startsWith(n)&&(t[o]=r)}),t}function Te(e){const s=v(e.content)&&typeof e.content.name=="string"?e.content.name:null;if(!s)throw new Error('Type content is missing required "name" field.');return s}function Be(e){if(!I.existsSync(e))return{previous:null};const s=I.readFileSync(e,"utf8"),t=p.yamlBlueParse(s);if(!t||!g(t))throw new Error("Existing BlueRepository.blue is not a valid object.");const n=t,r=n.packages,o=n.repositoryVersions,i=Array.isArray(r)&&r.every(l=>g(l)&&typeof l.name=="string"&&Array.isArray(l.types)),c=Array.isArray(o)&&o.every(l=>typeof l=="string");if(!i||!c)throw new Error("Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }");const a=r,u=o,f={name:typeof n.name=="string"?n.name:M,packages:a,repositoryVersions:u};return{existingYaml:s,previous:f}}function Ae(e){return C.dump(e,{lineWidth:-1})}function Pe(e){const s=$.resolve(e.repoRoot),t=$.resolve(e.blueRepositoryPath),{existingYaml:n,previous:r}=Be(t),o=L(s),i=fe(r);le(o,i);const c=J(o),a=W(c);H(c,o);const{aliasToBlueId:u,aliasToStorageContent:f}=Q(a,o),l=r?r.repositoryVersions.length:0,y=pe({discovered:o,previousTypes:i,aliasToBlueId:u,aliasToStorageContent:f,nextRepoVersionIndex:l}),m=he(y),w=be(m),{document:E,changed:B}=we(m,r,w);ve(E.packages,E.repositoryVersions,u);const V=Ae(E);if(r&&!B&&n&&n!==V)throw new Error("BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode.");return e.verbose&&console.info(`[repository-generator] RepoBlueId: ${w} (${B?"changed":"unchanged"})`),{document:E,currentRepoBlueId:w,previousRepoBlueId:r?.repositoryVersions.at(-1),changed:B||!n,yaml:V,existingYaml:n}}exports.generateRepository=Pe;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./generateRepository-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./generateRepository-DDbll3Cz.js");exports.generateRepository=e.generateRepository;
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BlueNode, MergingProcessor } from '@blue-labs/language';
|
|
2
|
+
export declare class ExpressionPreserver implements MergingProcessor {
|
|
3
|
+
process(target: BlueNode, source: BlueNode): BlueNode;
|
|
4
|
+
postProcess(target: BlueNode, source: BlueNode): BlueNode;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ExpressionPreserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressionPreserver.d.ts","sourceRoot":"","sources":["../../../src/lib/core/ExpressionPreserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAItE,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,QAAQ;IAerD,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,QAAQ;CAW1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blueIds.d.ts","sourceRoot":"","sources":["../../../src/lib/core/blueIds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"blueIds.d.ts","sourceRoot":"","sources":["../../../src/lib/core/blueIds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAKjE,wBAAgB,cAAc,CAC5B,SAAS,EAAE,KAAK,EAAE,EAClB,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,GACrC;IACD,aAAa,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClC,qBAAqB,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAC5C,CA0CA;AAED,wBAAgB,4BAA4B,CAC1C,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/C,MAAM,EAAE,MAAM,GACb,SAAS,EAAE,CAqBb;AAoBD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,EAClB,aAAa,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,EACjC,aAAa,UAAQ,EACrB,cAAc,UAAQ,GACrB,SAAS,CAuDX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergingProcessor.d.ts","sourceRoot":"","sources":["../../../src/lib/core/mergingProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AAG/E,wBAAgB,yCAAyC,IAAI,gBAAgB,CAU5E"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blue-labs/repository-generator",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"bin": {
|
|
5
5
|
"blue-repo-generator": "./dist/bin/blue-repo-generator.mjs"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@blue-labs/language": "4.0.0-rc.
|
|
9
|
-
"@blue-labs/repository-contract": "4.0.0-rc.
|
|
8
|
+
"@blue-labs/language": "4.0.0-rc.2",
|
|
9
|
+
"@blue-labs/repository-contract": "4.0.0-rc.2",
|
|
10
10
|
"fast-json-patch": "3.1.1",
|
|
11
11
|
"js-yaml": "4.1.0",
|
|
12
|
-
"@blue-labs/shared-utils": "4.0.0-rc.
|
|
12
|
+
"@blue-labs/shared-utils": "4.0.0-rc.2"
|
|
13
13
|
},
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const B=require("path"),I=require("fs"),h=require("@blue-labs/language"),m=require("@blue-labs/repository-contract"),D=require("fast-json-patch"),j=require("js-yaml");function C(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return s.default=e,Object.freeze(s)}const M=C(B),N=new Set([...h.Properties.CORE_TYPES]),P=h.Properties.CORE_TYPE_NAME_TO_BLUE_ID_MAP,R="Blue Repository",p={Dev:"dev",Stable:"stable"},U=new Set([".git",".github",".husky","node_modules",".nx",".vscode",".idea"]);function q(e){const s=I.readdirSync(e,{withFileTypes:!0}),t=new Map;for(const n of s){if(!n.isDirectory()||U.has(n.name))continue;const r=B.join(e,n.name),o=_(r);if(o.length!==0)for(const i of o){const c=i.endsWith(".dev.blue")?p.Dev:p.Stable,a=F(i),u=L(a,i),f=`${n.name}/${u}`,l=t.get(f);if(l)throw l.status!==c?new Error(`Type ${f} has both stable and dev definitions (${l.filePath} and ${i}).`):new Error(`Type ${f} is defined multiple times (${l.filePath} and ${i}).`);const d=Y(a,i);t.set(f,{packageName:n.name,typeName:u,status:c,content:a,filePath:i,references:d})}}return t}function F(e){const s=I.readFileSync(e,"utf8"),t=h.yamlBlueParse(s);if(!$(t))throw new Error(`Type file ${e} must contain a YAML object.`);return t}function L(e,s){if(!$(e)||typeof e.name!="string")throw new Error(`Type file ${s} is missing required "name" field.`);return e.name}function _(e){const s=I.readdirSync(e,{withFileTypes:!0}),t=[];for(const n of s){if(n.isDirectory()){t.push(..._(B.join(e,n.name)));continue}(n.name.endsWith(".blue")||n.name.endsWith(".dev.blue"))&&t.push(B.join(e,n.name))}return t}function Y(e,s){const t=new Set,n=r=>{if(Array.isArray(r)){r.forEach(i=>n(i));return}if(!$(r))return;const o=i=>{if(typeof i=="string"&&!N.has(i)){if(!i.includes("/"))throw new Error(`Invalid type reference "${i}" in ${s}. Use <Package>/<Type> for non-primitive references.`);t.add(i)}};o(r.type),o(r.itemType),o(r.keyType),o(r.valueType),Object.values(r).forEach(i=>n(i))};return n(e),t}function $(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function G(e){const s=new Map;for(const[t,n]of e){const r=new Set;for(const o of n.references){if(!e.has(o))throw new Error(`Type ${t} references unknown alias ${o}. Ensure the target type exists.`);r.add(o)}s.set(t,r)}return s}function J(e){const s=[],t=new Map,n=(r,o)=>{const i=t.get(r);if(i==="visited")return;if(i==="visiting"){const a=[...o,r].join(" -> ");throw new Error(`Circular type dependency detected: ${a}`)}t.set(r,"visiting"),o.push(r);const c=e.get(r)||new Set;for(const a of c)n(a,o);o.pop(),t.set(r,"visited"),s.push(r)};for(const r of e.keys())t.has(r)||n(r,[]);return s}function W(e,s){const t=new Map,n=r=>{if(t.has(r))return t.get(r)??!1;const o=e.get(r)||new Set;for(const i of o){const c=s.get(i);if(c&&(c.status===p.Dev||n(i)))return t.set(r,!0),!0}return t.set(r,!1),!1};for(const[r,o]of s)if(o.status===p.Stable&&n(r))throw new Error(`Stable type ${r} depends on a dev type. Stable types may only depend on other stable types.`)}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function w(e){return y(e)?Object.getPrototypeOf(e)===Object.prototype:!1}function T(e){if(Array.isArray(e))return e.map(s=>T(s));if(w(e)){const s={};for(const[t,n]of Object.entries(e))s[t]=T(n);return s}return e}function S(e){return e.map(s=>({repositoryVersionIndex:s.repositoryVersionIndex,typeBlueId:s.typeBlueId,attributesAdded:[...s.attributesAdded]}))}function H(e,s){const t=new Map,n=new Map,r=new Map,o=new h.Blue,i=h.createNodeProvider(a=>z(r,a).map(u=>o.jsonValueToNode(u))),c=new h.Blue({nodeProvider:i});for(const a of e){const u=s.get(a);if(!u)continue;const f=k(T(u.content),t),l=c.jsonValueToNode(f),d=N.has(u.typeName),g=d?Q(u.typeName):c.calculateBlueIdSync(l),v=c.nodeToJson(l,"official");t.set(a,g),n.set(a,v),d||r.set(g,v),c.registerBlueIds({[a]:g})}return{aliasToBlueId:t,aliasToStorageContent:n}}function z(e,s){const t=K(s);if(t===void 0)return[];const n=e.get(t.baseBlueId);if(n===void 0)return[];if(t.index===void 0)return Array.isArray(n)?n:[n];if(!Array.isArray(n))return t.index===0?[n]:[];const r=n[t.index];return r===void 0?[]:[r]}function K(e){const s=e.indexOf("#");if(s===-1)return{baseBlueId:e};const t=e.slice(0,s),n=e.slice(s+1),r=Number(n);if(!(!Number.isInteger(r)||r<0))return{baseBlueId:t,index:r}}function k(e,s,t=!1,n=!1){if(Array.isArray(e))return e.map(o=>k(o,s,t,n));if(!y(e))return e;const r={};for(const[o,i]of Object.entries(e)){const c=n||o===m.OBJECT_CONTRACTS;if((o==="type"||o==="itemType"||o==="keyType"||o==="valueType")&&typeof i=="string"&&!(t&&c)){if(N.has(i)){const a=P[i];if(!a)throw new Error(`Missing primitive BlueId for ${i}.`);r[o]={blueId:a}}else{const a=i,u=s.get(a);if(!u)throw new Error(`Missing BlueId for alias ${a}.`);r[o]={blueId:u}}continue}r[o]=k(i,s,t,c)}return r}function Q(e){const s=P[e];if(!s)throw new Error(`Missing primitive BlueId for ${e}.`);return s}const V=new Set(Object.values(P)),X=new Set(["type","itemType","valueType","keyType"]),Z=new Set(["name","description"]),b={Unchanged:"unchanged",NonBreaking:"non-breaking",Breaking:"breaking"};function ee(e,s,t,n,r){const o=D.compare(e,s);if(o.length===0)return{status:b.Unchanged,attributesAdded:[]};const i=[];let c=!1;for(const a of o){if(se(a,e,r)){c=!0;continue}if(a.op!=="add")return{status:b.Breaking,attributesAdded:[]};if(!ne(a))return{status:b.Breaking,attributesAdded:[]};i.push(a.path)}return i.length===0&&!c?{status:b.Breaking,attributesAdded:[]}:(i.length>0&&te(i,t,n),{status:b.NonBreaking,attributesAdded:i})}function te(e,s,t){for(const n of e)try{m.validateAttributesAddedPointer(n)}catch(r){throw new Error(`Invalid attribute pointer "${n}" for ${s}/${t}: ${r.message}`)}}function ne(e){if(e.op!=="add")return!1;const s=x(e.path);if(s.length===0)return!1;const t=s.at(-1);return t&&/^\d+$/.test(t)||t&&X.has(t)||s.some(n=>m.RESERVED_ATTRIBUTES_POINTER_SEGMENTS.has(n))?!1:y(e.value)?!re(e.value):t?Z.has(t):!1}function x(e){try{return m.parsePointer(e)}catch{return[]}}function re(e){const s=[e];for(;s.length;){const t=s.pop();if(t){if(Object.prototype.hasOwnProperty.call(t,"value")||Object.prototype.hasOwnProperty.call(t,"items"))return!0;if(Object.prototype.hasOwnProperty.call(t,m.OBJECT_SCHEMA)){const n=t[m.OBJECT_SCHEMA];if(y(n)&&n.required===!0)return!0}for(const[n,r]of Object.entries(t))n!==m.OBJECT_SCHEMA&&y(r)&&s.push(r)}}return!1}function se(e,s,t){if(e.op!=="replace"||typeof e.path!="string")return!1;const n=x(e.path);if(n.length<2)return!1;const r=n.at(-1),o=n.at(-2);if(!(r==="blueId"&&o!==void 0&&(o==="type"||o==="itemType"||o==="keyType"||o==="valueType")))return!1;const i=oe(s,n),c=typeof i=="string"?i:y(i)&&typeof i.blueId=="string"?i.blueId:null,a=typeof e.value=="string"?e.value:y(e.value)&&typeof e.value.blueId=="string"?e.value.blueId:null;if(c&&V.has(c)||a&&V.has(a)||!c||!a)return!1;const u=t.get(c),f=t.get(a);if(!u||!f)return!1;for(const l of u)if(f.has(l))return!0;return!1}function oe(e,s){let t=e;for(const n of s)if(Array.isArray(t)){const r=Number(n);if(Number.isNaN(r)||r<0||r>=t.length)return;t=t[r]}else if(y(t))t=t[n];else return;return t}function ie(e){const s=new Map;if(!e)return s;for(const t of e.packages||[]){if(typeof t.name!="string")continue;const n=new Map;for(const r of t.types||[]){const o=r.content,i=w(o)&&typeof o.name=="string"?o.name:void 0;i&&n.set(i,r)}s.set(t.name,n)}return s}function ae(e,s){for(const[t,n]of s)for(const[r,o]of n){const i=`${t}/${r}`;if(!e.has(i)&&o.status===p.Stable)throw new Error(`Stable type ${i} was removed. Breaking changes require a new logical type name.`)}}function ce({discovered:e,previousTypes:s,aliasToBlueId:t,aliasToStorageContent:n,nextRepoVersionIndex:r}){const o=new Map,i=ue(s,t);for(const[c,a]of e){const u=t.get(c);if(!u)throw new Error(`Failed to compute BlueId for type ${c}.`);const f=s.get(a.packageName)?.get(a.typeName)??null;if(f&&f.status===p.Stable&&a.status===p.Dev)throw new Error(`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`);const l=n.get(c)??a.content,d=a.status===p.Dev?fe({blueId:u,nextRepoVersionIndex:r,previousType:f}):!f||f.status===p.Dev?le({blueId:u,nextRepoVersionIndex:r}):pe({alias:c,blueId:u,nextRepoVersionIndex:r,previousType:f,currentContent:l,packageName:a.packageName,typeName:a.typeName,blueIdAliases:i});d.content=l,d.status=a.status;const g=o.get(a.packageName)??[];g.push(d),o.set(a.packageName,g)}return o}function ue(e,s){const t=new Map,n=(r,o)=>{const i=t.get(r);if(i){i.add(o);return}t.set(r,new Set([o]))};for(const[r,o]of e)for(const[i,c]of o){const a=`${r}/${i}`;for(const u of c.versions??[])typeof u.typeBlueId=="string"&&n(u.typeBlueId,a)}for(const[r,o]of s)n(o,r);return t}function fe({blueId:e,nextRepoVersionIndex:s,previousType:t}){const n=t&&t.status===p.Dev?t:null,r=n?.versions?.length===1?n.versions[0]:null,o=r&&r.typeBlueId===e;return{status:p.Dev,content:{},versions:o&&n?.versions?S(n.versions):[{repositoryVersionIndex:s,typeBlueId:e,attributesAdded:[]}]}}function le({blueId:e,nextRepoVersionIndex:s}){return{status:p.Stable,content:{},versions:[{repositoryVersionIndex:s,typeBlueId:e,attributesAdded:[]}]}}function pe({alias:e,blueId:s,nextRepoVersionIndex:t,previousType:n,currentContent:r,packageName:o,typeName:i,blueIdAliases:c}){if(!w(n.content))throw new Error(`Type ${e} has non-object content; cannot compute diff for stable versioning.`);const a=ee(n.content,r,o,i,c);if(a.status===b.Unchanged){const u=S(n.versions||[]),f=u.at(-1);if(f&&f.typeBlueId!==s)throw new Error(`Type ${e} content is unchanged but BlueId differs from previous metadata.`);return{status:p.Stable,content:{},versions:u}}if(a.status===b.NonBreaking)return{status:p.Stable,content:{},versions:[...S(n.versions||[]),{repositoryVersionIndex:t,typeBlueId:s,attributesAdded:a.attributesAdded}]};throw new Error(`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`)}function de(e){return Array.from(e.entries()).map(([s,t])=>({name:s,types:t.map(n=>({...n,versions:[...n.versions].sort((r,o)=>r.repositoryVersionIndex-o.repositoryVersionIndex)})).sort((n,r)=>{const o=w(n.content)&&typeof n.content.name=="string"?n.content.name:"",i=w(r.content)&&typeof r.content.name=="string"?r.content.name:"";return o.localeCompare(i)})})).sort((s,t)=>s.name.localeCompare(t.name))}function ye(e){return h.BlueIdCalculator.INSTANCE.calculateSync(e)}function ge(e,s,t){const n=s?.repositoryVersions.at(-1),r=!n||n!==t,o=s?.repositoryVersions?[...s.repositoryVersions]:[];return r&&o.push(t),{document:{name:R,packages:e,repositoryVersions:o},changed:r}}function me(e,s,t){const n={name:R,repositoryVersions:s,packages:he(e,t)};m.validateNoCycles(n),m.validateStableDoesNotDependOnDev(n)}function he(e,s){const t={};for(const n of e){const r=be(n.name,s),o={},i={};for(const c of n.types){const a=c.versions?.[c.versions.length-1]?.typeBlueId;if(!a)throw new Error(`Type ${n.name} is missing a current BlueId in versions.`);const u=ve(c);o[a]={status:c.status,name:u,versions:c.versions??[]},i[a]=c.content}t[n.name]={name:n.name,aliases:r,typesMeta:o,contents:i,schemas:{}}}return t}function be(e,s){const t={},n=`${e}/`;return s.forEach((r,o)=>{o.startsWith(n)&&(t[o]=r)}),t}function ve(e){const s=w(e.content)&&typeof e.content.name=="string"?e.content.name:null;if(!s)throw new Error('Type content is missing required "name" field.');return s}function we(e){if(!I.existsSync(e))return{previous:null};const s=I.readFileSync(e,"utf8"),t=h.yamlBlueParse(s);if(!t||!y(t))throw new Error("Existing BlueRepository.blue is not a valid object.");const n=t,r=n.packages,o=n.repositoryVersions,i=Array.isArray(r)&&r.every(l=>y(l)&&typeof l.name=="string"&&Array.isArray(l.types)),c=Array.isArray(o)&&o.every(l=>typeof l=="string");if(!i||!c)throw new Error("Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }");const a=r,u=o,f={name:typeof n.name=="string"?n.name:R,packages:a,repositoryVersions:u};return{existingYaml:s,previous:f}}function Ie(e){return j.dump(e,{lineWidth:-1})}function Ee(e){const s=M.resolve(e.repoRoot),t=M.resolve(e.blueRepositoryPath),{existingYaml:n,previous:r}=we(t),o=q(s),i=ie(r);ae(o,i);const c=G(o),a=J(c);W(c,o);const{aliasToBlueId:u,aliasToStorageContent:f}=H(a,o),l=r?r.repositoryVersions.length:0,d=ce({discovered:o,previousTypes:i,aliasToBlueId:u,aliasToStorageContent:f,nextRepoVersionIndex:l}),g=de(d),v=ye(g),{document:E,changed:A}=ge(g,r,v);me(E.packages,E.repositoryVersions,u);const O=Ie(E);if(r&&!A&&n&&n!==O)throw new Error("BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode.");return e.verbose&&console.info(`[repository-generator] RepoBlueId: ${v} (${A?"changed":"unchanged"})`),{document:E,currentRepoBlueId:v,previousRepoBlueId:r?.repositoryVersions.at(-1),changed:A||!n,yaml:O,existingYaml:n}}exports.generateRepository=Ee;
|