@blue-labs/repository-generator 4.0.2-rc.0 → 4.1.1
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 +2 -1
- package/dist/bin/blue-repo-generator.js +1 -1
- package/dist/bin/blue-repo-generator.mjs +1 -1
- package/dist/generateRepository-B7eem2l_.mjs +969 -0
- package/dist/generateRepository-DUT9zf8k.js +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/core/blueIds.d.ts +4 -2
- package/dist/lib/core/blueIds.d.ts.map +1 -1
- package/dist/lib/core/contractValidation.d.ts.map +1 -1
- package/dist/lib/core/graph.d.ts +3 -0
- package/dist/lib/core/graph.d.ts.map +1 -1
- package/dist/lib/generateRepository.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/generateRepository-BiRDvOfc.mjs +0 -706
- package/dist/generateRepository-DDbll3Cz.js +0 -1
|
@@ -1,706 +0,0 @@
|
|
|
1
|
-
import * as x from "path";
|
|
2
|
-
import A from "path";
|
|
3
|
-
import b from "fs";
|
|
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
|
-
Dev: "dev",
|
|
10
|
-
Stable: "stable"
|
|
11
|
-
}, X = /* @__PURE__ */ new Set([
|
|
12
|
-
".git",
|
|
13
|
-
".github",
|
|
14
|
-
".husky",
|
|
15
|
-
"node_modules",
|
|
16
|
-
".nx",
|
|
17
|
-
".vscode",
|
|
18
|
-
".idea"
|
|
19
|
-
]);
|
|
20
|
-
function Q(e) {
|
|
21
|
-
const s = b.readdirSync(e, { withFileTypes: !0 }), t = /* @__PURE__ */ new Map();
|
|
22
|
-
for (const n of s) {
|
|
23
|
-
if (!n.isDirectory() || X.has(n.name))
|
|
24
|
-
continue;
|
|
25
|
-
const r = A.join(e, n.name), o = C(r);
|
|
26
|
-
if (o.length !== 0)
|
|
27
|
-
for (const i of o) {
|
|
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
|
-
if (p)
|
|
30
|
-
throw p.status !== c ? new Error(
|
|
31
|
-
`Type ${f} has both stable and dev definitions (${p.filePath} and ${i}).`
|
|
32
|
-
) : new Error(
|
|
33
|
-
`Type ${f} is defined multiple times (${p.filePath} and ${i}).`
|
|
34
|
-
);
|
|
35
|
-
const d = te(a, i);
|
|
36
|
-
t.set(f, {
|
|
37
|
-
packageName: n.name,
|
|
38
|
-
typeName: u,
|
|
39
|
-
status: c,
|
|
40
|
-
content: a,
|
|
41
|
-
filePath: i,
|
|
42
|
-
references: d
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return t;
|
|
47
|
-
}
|
|
48
|
-
function Z(e) {
|
|
49
|
-
const s = b.readFileSync(e, "utf8"), t = j(s);
|
|
50
|
-
if (!V(t))
|
|
51
|
-
throw new Error(`Type file ${e} must contain a YAML object.`);
|
|
52
|
-
return t;
|
|
53
|
-
}
|
|
54
|
-
function ee(e, s) {
|
|
55
|
-
if (!V(e) || typeof e.name != "string")
|
|
56
|
-
throw new Error(`Type file ${s} is missing required "name" field.`);
|
|
57
|
-
return e.name;
|
|
58
|
-
}
|
|
59
|
-
function C(e) {
|
|
60
|
-
const s = b.readdirSync(e, { withFileTypes: !0 }), t = [];
|
|
61
|
-
for (const n of s) {
|
|
62
|
-
if (n.isDirectory()) {
|
|
63
|
-
t.push(...C(A.join(e, n.name)));
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
(n.name.endsWith(".blue") || n.name.endsWith(".dev.blue")) && t.push(A.join(e, n.name));
|
|
67
|
-
}
|
|
68
|
-
return t;
|
|
69
|
-
}
|
|
70
|
-
function te(e, s) {
|
|
71
|
-
const t = /* @__PURE__ */ new Set(), n = (r) => {
|
|
72
|
-
if (Array.isArray(r)) {
|
|
73
|
-
r.forEach((i) => n(i));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (!V(r))
|
|
77
|
-
return;
|
|
78
|
-
const o = (i) => {
|
|
79
|
-
if (typeof i == "string" && !N.has(i)) {
|
|
80
|
-
if (!i.includes("/"))
|
|
81
|
-
throw new Error(
|
|
82
|
-
`Invalid type reference "${i}" in ${s}. Use <Package>/<Type> for non-primitive references.`
|
|
83
|
-
);
|
|
84
|
-
t.add(i);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
o(r.type), o(r.itemType), o(r.keyType), o(r.valueType), Object.values(r).forEach((i) => n(i));
|
|
88
|
-
};
|
|
89
|
-
return n(e), t;
|
|
90
|
-
}
|
|
91
|
-
function V(e) {
|
|
92
|
-
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
93
|
-
}
|
|
94
|
-
function ne(e) {
|
|
95
|
-
const s = /* @__PURE__ */ new Map();
|
|
96
|
-
for (const [t, n] of e) {
|
|
97
|
-
const r = /* @__PURE__ */ new Set();
|
|
98
|
-
for (const o of n.references) {
|
|
99
|
-
if (!e.has(o))
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Type ${t} references unknown alias ${o}. Ensure the target type exists.`
|
|
102
|
-
);
|
|
103
|
-
r.add(o);
|
|
104
|
-
}
|
|
105
|
-
s.set(t, r);
|
|
106
|
-
}
|
|
107
|
-
return s;
|
|
108
|
-
}
|
|
109
|
-
function re(e) {
|
|
110
|
-
const s = [], t = /* @__PURE__ */ new Map(), n = (r, o) => {
|
|
111
|
-
const i = t.get(r);
|
|
112
|
-
if (i === "visited")
|
|
113
|
-
return;
|
|
114
|
-
if (i === "visiting") {
|
|
115
|
-
const a = [...o, r].join(" -> ");
|
|
116
|
-
throw new Error(`Circular type dependency detected: ${a}`);
|
|
117
|
-
}
|
|
118
|
-
t.set(r, "visiting"), o.push(r);
|
|
119
|
-
const c = e.get(r) || /* @__PURE__ */ new Set();
|
|
120
|
-
for (const a of c)
|
|
121
|
-
n(a, o);
|
|
122
|
-
o.pop(), t.set(r, "visited"), s.push(r);
|
|
123
|
-
};
|
|
124
|
-
for (const r of e.keys())
|
|
125
|
-
t.has(r) || n(r, []);
|
|
126
|
-
return s;
|
|
127
|
-
}
|
|
128
|
-
function se(e, s) {
|
|
129
|
-
const t = /* @__PURE__ */ new Map(), n = (r) => {
|
|
130
|
-
if (t.has(r))
|
|
131
|
-
return t.get(r) ?? !1;
|
|
132
|
-
const o = e.get(r) || /* @__PURE__ */ new Set();
|
|
133
|
-
for (const i of o) {
|
|
134
|
-
const c = s.get(i);
|
|
135
|
-
if (c && (c.status === l.Dev || n(i)))
|
|
136
|
-
return t.set(r, !0), !0;
|
|
137
|
-
}
|
|
138
|
-
return t.set(r, !1), !1;
|
|
139
|
-
};
|
|
140
|
-
for (const [r, o] of s)
|
|
141
|
-
if (o.status === l.Stable && n(r))
|
|
142
|
-
throw new Error(
|
|
143
|
-
`Stable type ${r} depends on a dev type. Stable types may only depend on other stable types.`
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
function y(e) {
|
|
147
|
-
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
148
|
-
}
|
|
149
|
-
function v(e) {
|
|
150
|
-
return y(e) ? Object.getPrototypeOf(e) === Object.prototype : !1;
|
|
151
|
-
}
|
|
152
|
-
function B(e) {
|
|
153
|
-
if (Array.isArray(e))
|
|
154
|
-
return e.map((s) => B(s));
|
|
155
|
-
if (v(e)) {
|
|
156
|
-
const s = {};
|
|
157
|
-
for (const [t, n] of Object.entries(e))
|
|
158
|
-
s[t] = B(n);
|
|
159
|
-
return s;
|
|
160
|
-
}
|
|
161
|
-
return e;
|
|
162
|
-
}
|
|
163
|
-
function S(e) {
|
|
164
|
-
return e.map((s) => ({
|
|
165
|
-
repositoryVersionIndex: s.repositoryVersionIndex,
|
|
166
|
-
typeBlueId: s.typeBlueId,
|
|
167
|
-
attributesAdded: [...s.attributesAdded]
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
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(
|
|
206
|
-
(u) => o.jsonValueToNode(u)
|
|
207
|
-
)
|
|
208
|
-
), c = new M({
|
|
209
|
-
nodeProvider: i,
|
|
210
|
-
mergingProcessor: ae()
|
|
211
|
-
});
|
|
212
|
-
for (const a of e) {
|
|
213
|
-
const u = s.get(a);
|
|
214
|
-
if (!u)
|
|
215
|
-
continue;
|
|
216
|
-
const f = P(
|
|
217
|
-
B(u.content),
|
|
218
|
-
t
|
|
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 });
|
|
221
|
-
}
|
|
222
|
-
return { aliasToBlueId: t, aliasToStorageContent: n };
|
|
223
|
-
}
|
|
224
|
-
function ue(e, s) {
|
|
225
|
-
const t = fe(s);
|
|
226
|
-
if (t === void 0)
|
|
227
|
-
return [];
|
|
228
|
-
const n = e.get(t.baseBlueId);
|
|
229
|
-
if (n === void 0)
|
|
230
|
-
return [];
|
|
231
|
-
if (t.index === void 0)
|
|
232
|
-
return Array.isArray(n) ? n : [n];
|
|
233
|
-
if (!Array.isArray(n))
|
|
234
|
-
return t.index === 0 ? [n] : [];
|
|
235
|
-
const r = n[t.index];
|
|
236
|
-
return r === void 0 ? [] : [r];
|
|
237
|
-
}
|
|
238
|
-
function fe(e) {
|
|
239
|
-
const s = e.indexOf("#");
|
|
240
|
-
if (s === -1)
|
|
241
|
-
return { baseBlueId: e };
|
|
242
|
-
const t = e.slice(0, s), n = e.slice(s + 1), r = Number(n);
|
|
243
|
-
if (!(!Number.isInteger(r) || r < 0))
|
|
244
|
-
return { baseBlueId: t, index: r };
|
|
245
|
-
}
|
|
246
|
-
function P(e, s, t = !1, n = !1) {
|
|
247
|
-
if (Array.isArray(e))
|
|
248
|
-
return e.map(
|
|
249
|
-
(o) => P(
|
|
250
|
-
o,
|
|
251
|
-
s,
|
|
252
|
-
t,
|
|
253
|
-
n
|
|
254
|
-
)
|
|
255
|
-
);
|
|
256
|
-
if (!y(e))
|
|
257
|
-
return e;
|
|
258
|
-
const r = {};
|
|
259
|
-
for (const [o, i] of Object.entries(e)) {
|
|
260
|
-
const c = n || o === G;
|
|
261
|
-
if ((o === "type" || o === "itemType" || o === "keyType" || o === "valueType") && typeof i == "string" && !(t && c)) {
|
|
262
|
-
if (N.has(i)) {
|
|
263
|
-
const a = k[i];
|
|
264
|
-
if (!a)
|
|
265
|
-
throw new Error(`Missing primitive BlueId for ${i}.`);
|
|
266
|
-
r[o] = { blueId: a };
|
|
267
|
-
} else {
|
|
268
|
-
const a = i, u = s.get(a);
|
|
269
|
-
if (!u)
|
|
270
|
-
throw new Error(`Missing BlueId for alias ${a}.`);
|
|
271
|
-
r[o] = { blueId: u };
|
|
272
|
-
}
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
r[o] = P(
|
|
276
|
-
i,
|
|
277
|
-
s,
|
|
278
|
-
t,
|
|
279
|
-
c
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
return r;
|
|
283
|
-
}
|
|
284
|
-
function pe(e) {
|
|
285
|
-
const s = k[e];
|
|
286
|
-
if (!s)
|
|
287
|
-
throw new Error(`Missing primitive BlueId for ${e}.`);
|
|
288
|
-
return s;
|
|
289
|
-
}
|
|
290
|
-
const _ = new Set(Object.values(k)), le = /* @__PURE__ */ new Set([
|
|
291
|
-
"type",
|
|
292
|
-
"itemType",
|
|
293
|
-
"valueType",
|
|
294
|
-
"keyType"
|
|
295
|
-
]), de = /* @__PURE__ */ new Set(["name", "description"]), h = {
|
|
296
|
-
Unchanged: "unchanged",
|
|
297
|
-
NonBreaking: "non-breaking",
|
|
298
|
-
Breaking: "breaking"
|
|
299
|
-
};
|
|
300
|
-
function ye(e, s, t, n, r) {
|
|
301
|
-
const o = H.compare(
|
|
302
|
-
e,
|
|
303
|
-
s
|
|
304
|
-
);
|
|
305
|
-
if (o.length === 0)
|
|
306
|
-
return { status: h.Unchanged, attributesAdded: [] };
|
|
307
|
-
const i = [];
|
|
308
|
-
let c = !1;
|
|
309
|
-
for (const a of o) {
|
|
310
|
-
if (we(a, e, r)) {
|
|
311
|
-
c = !0;
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
if (a.op !== "add")
|
|
315
|
-
return { status: h.Breaking, attributesAdded: [] };
|
|
316
|
-
if (!me(a))
|
|
317
|
-
return { status: h.Breaking, attributesAdded: [] };
|
|
318
|
-
i.push(a.path);
|
|
319
|
-
}
|
|
320
|
-
return i.length === 0 && !c ? {
|
|
321
|
-
status: h.Breaking,
|
|
322
|
-
attributesAdded: []
|
|
323
|
-
} : (i.length > 0 && ge(i, t, n), { status: h.NonBreaking, attributesAdded: i });
|
|
324
|
-
}
|
|
325
|
-
function ge(e, s, t) {
|
|
326
|
-
for (const n of e)
|
|
327
|
-
try {
|
|
328
|
-
W(n);
|
|
329
|
-
} catch (r) {
|
|
330
|
-
throw new Error(
|
|
331
|
-
`Invalid attribute pointer "${n}" for ${s}/${t}: ${r.message}`
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
function me(e) {
|
|
336
|
-
if (e.op !== "add")
|
|
337
|
-
return !1;
|
|
338
|
-
const s = U(e.path);
|
|
339
|
-
if (s.length === 0)
|
|
340
|
-
return !1;
|
|
341
|
-
const t = s.at(-1);
|
|
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;
|
|
345
|
-
}
|
|
346
|
-
function U(e) {
|
|
347
|
-
try {
|
|
348
|
-
return q(e);
|
|
349
|
-
} catch {
|
|
350
|
-
return [];
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
function he(e) {
|
|
354
|
-
const s = [e];
|
|
355
|
-
for (; s.length; ) {
|
|
356
|
-
const t = s.pop();
|
|
357
|
-
if (t) {
|
|
358
|
-
if (Object.prototype.hasOwnProperty.call(t, "value") || Object.prototype.hasOwnProperty.call(t, "items"))
|
|
359
|
-
return !0;
|
|
360
|
-
if (Object.prototype.hasOwnProperty.call(t, T)) {
|
|
361
|
-
const n = t[T];
|
|
362
|
-
if (y(n) && n.required === !0)
|
|
363
|
-
return !0;
|
|
364
|
-
}
|
|
365
|
-
for (const [n, r] of Object.entries(t))
|
|
366
|
-
n !== T && y(r) && s.push(r);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return !1;
|
|
370
|
-
}
|
|
371
|
-
function we(e, s, t) {
|
|
372
|
-
if (e.op !== "replace" || typeof e.path != "string")
|
|
373
|
-
return !1;
|
|
374
|
-
const n = U(e.path);
|
|
375
|
-
if (n.length < 2)
|
|
376
|
-
return !1;
|
|
377
|
-
const r = n.at(-1), o = n.at(-2);
|
|
378
|
-
if (!(r === "blueId" && o !== void 0 && (o === "type" || o === "itemType" || o === "keyType" || o === "valueType")))
|
|
379
|
-
return !1;
|
|
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;
|
|
381
|
-
if (c && _.has(c) || a && _.has(a) || !c || !a)
|
|
382
|
-
return !1;
|
|
383
|
-
const u = t.get(c), f = t.get(a);
|
|
384
|
-
if (!u || !f)
|
|
385
|
-
return !1;
|
|
386
|
-
for (const p of u)
|
|
387
|
-
if (f.has(p))
|
|
388
|
-
return !0;
|
|
389
|
-
return !1;
|
|
390
|
-
}
|
|
391
|
-
function ve(e, s) {
|
|
392
|
-
let t = e;
|
|
393
|
-
for (const n of s)
|
|
394
|
-
if (Array.isArray(t)) {
|
|
395
|
-
const r = Number(n);
|
|
396
|
-
if (Number.isNaN(r) || r < 0 || r >= t.length)
|
|
397
|
-
return;
|
|
398
|
-
t = t[r];
|
|
399
|
-
} else if (y(t))
|
|
400
|
-
t = t[n];
|
|
401
|
-
else
|
|
402
|
-
return;
|
|
403
|
-
return t;
|
|
404
|
-
}
|
|
405
|
-
function be(e) {
|
|
406
|
-
const s = /* @__PURE__ */ new Map();
|
|
407
|
-
if (!e)
|
|
408
|
-
return s;
|
|
409
|
-
for (const t of e.packages || []) {
|
|
410
|
-
if (typeof t.name != "string")
|
|
411
|
-
continue;
|
|
412
|
-
const n = /* @__PURE__ */ new Map();
|
|
413
|
-
for (const r of t.types || []) {
|
|
414
|
-
const o = r.content, i = v(o) && typeof o.name == "string" ? o.name : void 0;
|
|
415
|
-
i && n.set(i, r);
|
|
416
|
-
}
|
|
417
|
-
s.set(t.name, n);
|
|
418
|
-
}
|
|
419
|
-
return s;
|
|
420
|
-
}
|
|
421
|
-
function Ie(e, s) {
|
|
422
|
-
for (const [t, n] of s)
|
|
423
|
-
for (const [r, o] of n) {
|
|
424
|
-
const i = `${t}/${r}`;
|
|
425
|
-
if (!e.has(i) && o.status === l.Stable)
|
|
426
|
-
throw new Error(
|
|
427
|
-
`Stable type ${i} was removed. Breaking changes require a new logical type name.`
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
function Ee({
|
|
432
|
-
discovered: e,
|
|
433
|
-
previousTypes: s,
|
|
434
|
-
aliasToBlueId: t,
|
|
435
|
-
aliasToStorageContent: n,
|
|
436
|
-
nextRepoVersionIndex: r
|
|
437
|
-
}) {
|
|
438
|
-
const o = /* @__PURE__ */ new Map(), i = Te(s, t);
|
|
439
|
-
for (const [c, a] of e) {
|
|
440
|
-
const u = t.get(c);
|
|
441
|
-
if (!u)
|
|
442
|
-
throw new Error(`Failed to compute BlueId for type ${c}.`);
|
|
443
|
-
const f = s.get(a.packageName)?.get(a.typeName) ?? null;
|
|
444
|
-
if (f && f.status === l.Stable && a.status === l.Dev)
|
|
445
|
-
throw new Error(
|
|
446
|
-
`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`
|
|
447
|
-
);
|
|
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({
|
|
449
|
-
alias: c,
|
|
450
|
-
blueId: u,
|
|
451
|
-
nextRepoVersionIndex: r,
|
|
452
|
-
previousType: f,
|
|
453
|
-
currentContent: p,
|
|
454
|
-
packageName: a.packageName,
|
|
455
|
-
typeName: a.typeName,
|
|
456
|
-
blueIdAliases: i
|
|
457
|
-
});
|
|
458
|
-
d.content = p, d.status = a.status;
|
|
459
|
-
const g = o.get(a.packageName) ?? [];
|
|
460
|
-
g.push(d), o.set(a.packageName, g);
|
|
461
|
-
}
|
|
462
|
-
return o;
|
|
463
|
-
}
|
|
464
|
-
function Te(e, s) {
|
|
465
|
-
const t = /* @__PURE__ */ new Map(), n = (r, o) => {
|
|
466
|
-
const i = t.get(r);
|
|
467
|
-
if (i) {
|
|
468
|
-
i.add(o);
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
t.set(r, /* @__PURE__ */ new Set([o]));
|
|
472
|
-
};
|
|
473
|
-
for (const [r, o] of e)
|
|
474
|
-
for (const [i, c] of o) {
|
|
475
|
-
const a = `${r}/${i}`;
|
|
476
|
-
for (const u of c.versions ?? [])
|
|
477
|
-
typeof u.typeBlueId == "string" && n(u.typeBlueId, a);
|
|
478
|
-
}
|
|
479
|
-
for (const [r, o] of s)
|
|
480
|
-
n(o, r);
|
|
481
|
-
return t;
|
|
482
|
-
}
|
|
483
|
-
function Ae({
|
|
484
|
-
blueId: e,
|
|
485
|
-
nextRepoVersionIndex: s,
|
|
486
|
-
previousType: t
|
|
487
|
-
}) {
|
|
488
|
-
const n = t && t.status === l.Dev ? t : null, r = n?.versions?.length === 1 ? n.versions[0] : null, o = r && r.typeBlueId === e;
|
|
489
|
-
return {
|
|
490
|
-
status: l.Dev,
|
|
491
|
-
content: {},
|
|
492
|
-
versions: o && n?.versions ? S(n.versions) : [
|
|
493
|
-
{
|
|
494
|
-
repositoryVersionIndex: s,
|
|
495
|
-
typeBlueId: e,
|
|
496
|
-
attributesAdded: []
|
|
497
|
-
}
|
|
498
|
-
]
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
function Be({
|
|
502
|
-
blueId: e,
|
|
503
|
-
nextRepoVersionIndex: s
|
|
504
|
-
}) {
|
|
505
|
-
return {
|
|
506
|
-
status: l.Stable,
|
|
507
|
-
content: {},
|
|
508
|
-
versions: [
|
|
509
|
-
{
|
|
510
|
-
repositoryVersionIndex: s,
|
|
511
|
-
typeBlueId: e,
|
|
512
|
-
attributesAdded: []
|
|
513
|
-
}
|
|
514
|
-
]
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
function Se({
|
|
518
|
-
alias: e,
|
|
519
|
-
blueId: s,
|
|
520
|
-
nextRepoVersionIndex: t,
|
|
521
|
-
previousType: n,
|
|
522
|
-
currentContent: r,
|
|
523
|
-
packageName: o,
|
|
524
|
-
typeName: i,
|
|
525
|
-
blueIdAliases: c
|
|
526
|
-
}) {
|
|
527
|
-
if (!v(n.content))
|
|
528
|
-
throw new Error(
|
|
529
|
-
`Type ${e} has non-object content; cannot compute diff for stable versioning.`
|
|
530
|
-
);
|
|
531
|
-
const a = ye(
|
|
532
|
-
n.content,
|
|
533
|
-
r,
|
|
534
|
-
o,
|
|
535
|
-
i,
|
|
536
|
-
c
|
|
537
|
-
);
|
|
538
|
-
if (a.status === h.Unchanged) {
|
|
539
|
-
const u = S(n.versions || []), f = u.at(-1);
|
|
540
|
-
if (f && f.typeBlueId !== s)
|
|
541
|
-
throw new Error(
|
|
542
|
-
`Type ${e} content is unchanged but BlueId differs from previous metadata.`
|
|
543
|
-
);
|
|
544
|
-
return {
|
|
545
|
-
status: l.Stable,
|
|
546
|
-
content: {},
|
|
547
|
-
versions: u
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
if (a.status === h.NonBreaking)
|
|
551
|
-
return {
|
|
552
|
-
status: l.Stable,
|
|
553
|
-
content: {},
|
|
554
|
-
versions: [
|
|
555
|
-
...S(n.versions || []),
|
|
556
|
-
{
|
|
557
|
-
repositoryVersionIndex: t,
|
|
558
|
-
typeBlueId: s,
|
|
559
|
-
attributesAdded: a.attributesAdded
|
|
560
|
-
}
|
|
561
|
-
]
|
|
562
|
-
};
|
|
563
|
-
throw new Error(
|
|
564
|
-
`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
function Pe(e) {
|
|
568
|
-
return Array.from(e.entries()).map(([s, t]) => ({
|
|
569
|
-
name: s,
|
|
570
|
-
types: t.map((n) => ({
|
|
571
|
-
...n,
|
|
572
|
-
versions: [...n.versions].sort(
|
|
573
|
-
(r, o) => r.repositoryVersionIndex - o.repositoryVersionIndex
|
|
574
|
-
)
|
|
575
|
-
})).sort((n, r) => {
|
|
576
|
-
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 : "";
|
|
577
|
-
return o.localeCompare(i);
|
|
578
|
-
})
|
|
579
|
-
})).sort((s, t) => s.name.localeCompare(t.name));
|
|
580
|
-
}
|
|
581
|
-
function Ne(e) {
|
|
582
|
-
return F.INSTANCE.calculateSync(
|
|
583
|
-
e
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
function ke(e, s, t) {
|
|
587
|
-
const n = s?.repositoryVersions.at(-1), r = !n || n !== t, o = s?.repositoryVersions ? [...s.repositoryVersions] : [];
|
|
588
|
-
return r && o.push(t), { document: {
|
|
589
|
-
name: R,
|
|
590
|
-
packages: e,
|
|
591
|
-
repositoryVersions: o
|
|
592
|
-
}, changed: r };
|
|
593
|
-
}
|
|
594
|
-
function Re(e, s, t) {
|
|
595
|
-
const n = {
|
|
596
|
-
name: R,
|
|
597
|
-
repositoryVersions: s,
|
|
598
|
-
packages: Ve(e, t)
|
|
599
|
-
};
|
|
600
|
-
J(n), z(n);
|
|
601
|
-
}
|
|
602
|
-
function Ve(e, s) {
|
|
603
|
-
const t = {};
|
|
604
|
-
for (const n of e) {
|
|
605
|
-
const r = $e(n.name, s), o = {}, i = {};
|
|
606
|
-
for (const c of n.types) {
|
|
607
|
-
const a = c.versions?.[c.versions.length - 1]?.typeBlueId;
|
|
608
|
-
if (!a)
|
|
609
|
-
throw new Error(
|
|
610
|
-
`Type ${n.name} is missing a current BlueId in versions.`
|
|
611
|
-
);
|
|
612
|
-
const u = xe(c);
|
|
613
|
-
o[a] = {
|
|
614
|
-
status: c.status,
|
|
615
|
-
name: u,
|
|
616
|
-
versions: c.versions ?? []
|
|
617
|
-
}, i[a] = c.content;
|
|
618
|
-
}
|
|
619
|
-
t[n.name] = {
|
|
620
|
-
name: n.name,
|
|
621
|
-
aliases: r,
|
|
622
|
-
typesMeta: o,
|
|
623
|
-
contents: i,
|
|
624
|
-
schemas: {}
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
return t;
|
|
628
|
-
}
|
|
629
|
-
function $e(e, s) {
|
|
630
|
-
const t = {}, n = `${e}/`;
|
|
631
|
-
return s.forEach((r, o) => {
|
|
632
|
-
o.startsWith(n) && (t[o] = r);
|
|
633
|
-
}), t;
|
|
634
|
-
}
|
|
635
|
-
function xe(e) {
|
|
636
|
-
const s = v(e.content) && typeof e.content.name == "string" ? e.content.name : null;
|
|
637
|
-
if (!s)
|
|
638
|
-
throw new Error('Type content is missing required "name" field.');
|
|
639
|
-
return s;
|
|
640
|
-
}
|
|
641
|
-
function Me(e) {
|
|
642
|
-
if (!b.existsSync(e))
|
|
643
|
-
return { previous: null };
|
|
644
|
-
const s = b.readFileSync(e, "utf8"), t = j(s);
|
|
645
|
-
if (!t || !y(t))
|
|
646
|
-
throw new Error("Existing BlueRepository.blue is not a valid object.");
|
|
647
|
-
const n = t, r = n.packages, o = n.repositoryVersions, i = Array.isArray(r) && r.every(
|
|
648
|
-
(p) => y(p) && typeof p.name == "string" && Array.isArray(p.types)
|
|
649
|
-
), c = Array.isArray(o) && o.every((p) => typeof p == "string");
|
|
650
|
-
if (!i || !c)
|
|
651
|
-
throw new Error(
|
|
652
|
-
"Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }"
|
|
653
|
-
);
|
|
654
|
-
const a = r, u = o, f = {
|
|
655
|
-
name: typeof n.name == "string" ? n.name : R,
|
|
656
|
-
packages: a,
|
|
657
|
-
repositoryVersions: u
|
|
658
|
-
};
|
|
659
|
-
return { existingYaml: s, previous: f };
|
|
660
|
-
}
|
|
661
|
-
function Oe(e) {
|
|
662
|
-
return K.dump(e, { lineWidth: -1 });
|
|
663
|
-
}
|
|
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(
|
|
670
|
-
a,
|
|
671
|
-
o
|
|
672
|
-
), p = r ? r.repositoryVersions.length : 0, d = Ee({
|
|
673
|
-
discovered: o,
|
|
674
|
-
previousTypes: i,
|
|
675
|
-
aliasToBlueId: u,
|
|
676
|
-
aliasToStorageContent: f,
|
|
677
|
-
nextRepoVersionIndex: p
|
|
678
|
-
}), g = Pe(d), w = Ne(g), { document: I, changed: E } = ke(
|
|
679
|
-
g,
|
|
680
|
-
r,
|
|
681
|
-
w
|
|
682
|
-
);
|
|
683
|
-
Re(
|
|
684
|
-
I.packages,
|
|
685
|
-
I.repositoryVersions,
|
|
686
|
-
u
|
|
687
|
-
);
|
|
688
|
-
const $ = Oe(I);
|
|
689
|
-
if (r && !E && n && n !== $)
|
|
690
|
-
throw new Error(
|
|
691
|
-
"BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode."
|
|
692
|
-
);
|
|
693
|
-
return e.verbose && console.info(
|
|
694
|
-
`[repository-generator] RepoBlueId: ${w} (${E ? "changed" : "unchanged"})`
|
|
695
|
-
), {
|
|
696
|
-
document: I,
|
|
697
|
-
currentRepoBlueId: w,
|
|
698
|
-
previousRepoBlueId: r?.repositoryVersions.at(-1),
|
|
699
|
-
changed: E || !n,
|
|
700
|
-
yaml: $,
|
|
701
|
-
existingYaml: n
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
export {
|
|
705
|
-
Fe as g
|
|
706
|
-
};
|