@blue-labs/repository-generator 3.11.0 → 4.0.0-rc.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/dist/bin/blue-repo-generator.js +1 -1
- package/dist/bin/blue-repo-generator.mjs +1 -1
- package/dist/{generateRepository-C2IfsNUG.mjs → generateRepository-BiRDvOfc.mjs} +191 -173
- 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 +2 -2
- 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/dist/lib/core/repoDoc.d.ts.map +1 -1
- package/dist/lib/core/versions.d.ts +2 -2
- package/dist/lib/core/versions.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/generateRepository-BwxSxjH3.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
|
-
import
|
|
4
|
-
import { Properties as
|
|
5
|
-
import { OBJECT_CONTRACTS as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
const N = /* @__PURE__ */ new Set([...
|
|
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
9
|
Dev: "dev",
|
|
10
10
|
Stable: "stable"
|
|
11
|
-
},
|
|
11
|
+
}, X = /* @__PURE__ */ new Set([
|
|
12
12
|
".git",
|
|
13
13
|
".github",
|
|
14
14
|
".husky",
|
|
@@ -18,62 +18,62 @@ const N = /* @__PURE__ */ new Set([...x.CORE_TYPES]), g = x.CORE_TYPE_NAME_TO_BL
|
|
|
18
18
|
".idea"
|
|
19
19
|
]);
|
|
20
20
|
function Q(e) {
|
|
21
|
-
const s =
|
|
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
|
|
35
|
+
const d = te(a, i);
|
|
36
36
|
t.set(f, {
|
|
37
37
|
packageName: n.name,
|
|
38
38
|
typeName: u,
|
|
39
39
|
status: c,
|
|
40
40
|
content: a,
|
|
41
41
|
filePath: i,
|
|
42
|
-
references:
|
|
42
|
+
references: d
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return t;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
const s =
|
|
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
|
|
60
|
-
const s =
|
|
59
|
+
function C(e) {
|
|
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
79
|
if (typeof i == "string" && !N.has(i)) {
|
|
@@ -88,10 +88,10 @@ function ee(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 te(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 ne(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;
|
|
@@ -143,43 +143,105 @@ function re(e, s) {
|
|
|
143
143
|
`Stable type ${r} depends on a dev type. Stable types may only depend on other stable types.`
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function y(e) {
|
|
147
147
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
return
|
|
149
|
+
function v(e) {
|
|
150
|
+
return y(e) ? Object.getPrototypeOf(e) === Object.prototype : !1;
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function B(e) {
|
|
153
153
|
if (Array.isArray(e))
|
|
154
|
-
return e.map((s) =>
|
|
155
|
-
if (
|
|
154
|
+
return e.map((s) => B(s));
|
|
155
|
+
if (v(e)) {
|
|
156
156
|
const s = {};
|
|
157
157
|
for (const [t, n] of Object.entries(e))
|
|
158
|
-
s[t] =
|
|
158
|
+
s[t] = B(n);
|
|
159
159
|
return s;
|
|
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
|
-
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
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)
|
|
175
215
|
continue;
|
|
176
|
-
const
|
|
177
|
-
|
|
216
|
+
const f = P(
|
|
217
|
+
B(u.content),
|
|
178
218
|
t
|
|
179
|
-
),
|
|
180
|
-
t.set(
|
|
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 });
|
|
181
221
|
}
|
|
182
|
-
return { aliasToBlueId: t,
|
|
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 };
|
|
183
245
|
}
|
|
184
246
|
function P(e, s, t = !1, n = !1) {
|
|
185
247
|
if (Array.isArray(e))
|
|
@@ -191,14 +253,14 @@ function P(e, s, t = !1, n = !1) {
|
|
|
191
253
|
n
|
|
192
254
|
)
|
|
193
255
|
);
|
|
194
|
-
if (!
|
|
256
|
+
if (!y(e))
|
|
195
257
|
return e;
|
|
196
258
|
const r = {};
|
|
197
259
|
for (const [o, i] of Object.entries(e)) {
|
|
198
|
-
const c = n || o ===
|
|
260
|
+
const c = n || o === G;
|
|
199
261
|
if ((o === "type" || o === "itemType" || o === "keyType" || o === "valueType") && typeof i == "string" && !(t && c)) {
|
|
200
262
|
if (N.has(i)) {
|
|
201
|
-
const a =
|
|
263
|
+
const a = k[i];
|
|
202
264
|
if (!a)
|
|
203
265
|
throw new Error(`Missing primitive BlueId for ${i}.`);
|
|
204
266
|
r[o] = { blueId: a };
|
|
@@ -219,92 +281,48 @@ function P(e, s, t = !1, n = !1) {
|
|
|
219
281
|
}
|
|
220
282
|
return r;
|
|
221
283
|
}
|
|
222
|
-
function
|
|
223
|
-
|
|
224
|
-
return { items: e.map((n) => k(n)) };
|
|
225
|
-
if (h(e)) {
|
|
226
|
-
if (ae(e))
|
|
227
|
-
return { blueId: e.blueId };
|
|
228
|
-
const t = ce(e), n = {};
|
|
229
|
-
for (const [r, o] of Object.entries(e)) {
|
|
230
|
-
if (M(o)) {
|
|
231
|
-
fe(r, t) ? n[r] = o : n[r] = V(
|
|
232
|
-
o
|
|
233
|
-
);
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
n[r] = k(
|
|
237
|
-
o,
|
|
238
|
-
t
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
return n;
|
|
242
|
-
}
|
|
243
|
-
return M(e) ? s ? e : V(e) : e;
|
|
244
|
-
}
|
|
245
|
-
function oe(e) {
|
|
246
|
-
const s = g[e];
|
|
284
|
+
function pe(e) {
|
|
285
|
+
const s = k[e];
|
|
247
286
|
if (!s)
|
|
248
287
|
throw new Error(`Missing primitive BlueId for ${e}.`);
|
|
249
288
|
return s;
|
|
250
289
|
}
|
|
251
|
-
|
|
252
|
-
const s = ie(e), t = { value: e };
|
|
253
|
-
return s && (t.type = { blueId: s }), t;
|
|
254
|
-
}
|
|
255
|
-
function ie(e) {
|
|
256
|
-
return typeof e == "string" ? g.Text : typeof e == "boolean" ? g.Boolean : typeof e == "number" ? Number.isInteger(e) ? g.Integer : g.Double : null;
|
|
257
|
-
}
|
|
258
|
-
function M(e) {
|
|
259
|
-
return e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean";
|
|
260
|
-
}
|
|
261
|
-
function ae(e) {
|
|
262
|
-
const s = Object.entries(e);
|
|
263
|
-
return s.length === 1 && s[0]?.[0] === "blueId" && typeof s[0]?.[1] == "string";
|
|
264
|
-
}
|
|
265
|
-
function ce(e) {
|
|
266
|
-
return Object.prototype.hasOwnProperty.call(e, "type") || Object.prototype.hasOwnProperty.call(e, "itemType") || Object.prototype.hasOwnProperty.call(e, "keyType") || Object.prototype.hasOwnProperty.call(e, "valueType");
|
|
267
|
-
}
|
|
268
|
-
const ue = /* @__PURE__ */ new Set(["name", "description", "blueId"]);
|
|
269
|
-
function fe(e, s) {
|
|
270
|
-
return !!(ue.has(e) || s && e === "value");
|
|
271
|
-
}
|
|
272
|
-
const D = new Set(Object.values(g)), pe = /* @__PURE__ */ new Set([
|
|
290
|
+
const _ = new Set(Object.values(k)), le = /* @__PURE__ */ new Set([
|
|
273
291
|
"type",
|
|
274
292
|
"itemType",
|
|
275
293
|
"valueType",
|
|
276
294
|
"keyType"
|
|
277
|
-
]),
|
|
295
|
+
]), de = /* @__PURE__ */ new Set(["name", "description"]), h = {
|
|
278
296
|
Unchanged: "unchanged",
|
|
279
297
|
NonBreaking: "non-breaking",
|
|
280
298
|
Breaking: "breaking"
|
|
281
299
|
};
|
|
282
|
-
function
|
|
283
|
-
const o =
|
|
300
|
+
function ye(e, s, t, n, r) {
|
|
301
|
+
const o = H.compare(
|
|
284
302
|
e,
|
|
285
303
|
s
|
|
286
304
|
);
|
|
287
305
|
if (o.length === 0)
|
|
288
|
-
return { status:
|
|
306
|
+
return { status: h.Unchanged, attributesAdded: [] };
|
|
289
307
|
const i = [];
|
|
290
308
|
let c = !1;
|
|
291
309
|
for (const a of o) {
|
|
292
|
-
if (
|
|
310
|
+
if (we(a, e, r)) {
|
|
293
311
|
c = !0;
|
|
294
312
|
continue;
|
|
295
313
|
}
|
|
296
314
|
if (a.op !== "add")
|
|
297
|
-
return { status:
|
|
315
|
+
return { status: h.Breaking, attributesAdded: [] };
|
|
298
316
|
if (!me(a))
|
|
299
|
-
return { status:
|
|
317
|
+
return { status: h.Breaking, attributesAdded: [] };
|
|
300
318
|
i.push(a.path);
|
|
301
319
|
}
|
|
302
320
|
return i.length === 0 && !c ? {
|
|
303
|
-
status:
|
|
321
|
+
status: h.Breaking,
|
|
304
322
|
attributesAdded: []
|
|
305
|
-
} : (i.length > 0 &&
|
|
323
|
+
} : (i.length > 0 && ge(i, t, n), { status: h.NonBreaking, attributesAdded: i });
|
|
306
324
|
}
|
|
307
|
-
function
|
|
325
|
+
function ge(e, s, t) {
|
|
308
326
|
for (const n of e)
|
|
309
327
|
try {
|
|
310
328
|
W(n);
|
|
@@ -317,22 +335,22 @@ function ye(e, s, t) {
|
|
|
317
335
|
function me(e) {
|
|
318
336
|
if (e.op !== "add")
|
|
319
337
|
return !1;
|
|
320
|
-
const s =
|
|
338
|
+
const s = U(e.path);
|
|
321
339
|
if (s.length === 0)
|
|
322
340
|
return !1;
|
|
323
341
|
const t = s.at(-1);
|
|
324
|
-
return t && /^\d+$/.test(t) || t &&
|
|
342
|
+
return t && /^\d+$/.test(t) || t && le.has(t) || s.some(
|
|
325
343
|
(n) => Y.has(n)
|
|
326
|
-
) ? !1 :
|
|
344
|
+
) ? !1 : y(e.value) ? !he(e.value) : t ? de.has(t) : !1;
|
|
327
345
|
}
|
|
328
|
-
function
|
|
346
|
+
function U(e) {
|
|
329
347
|
try {
|
|
330
|
-
return
|
|
348
|
+
return q(e);
|
|
331
349
|
} catch {
|
|
332
350
|
return [];
|
|
333
351
|
}
|
|
334
352
|
}
|
|
335
|
-
function
|
|
353
|
+
function he(e) {
|
|
336
354
|
const s = [e];
|
|
337
355
|
for (; s.length; ) {
|
|
338
356
|
const t = s.pop();
|
|
@@ -341,26 +359,26 @@ function ge(e) {
|
|
|
341
359
|
return !0;
|
|
342
360
|
if (Object.prototype.hasOwnProperty.call(t, T)) {
|
|
343
361
|
const n = t[T];
|
|
344
|
-
if (
|
|
362
|
+
if (y(n) && n.required === !0)
|
|
345
363
|
return !0;
|
|
346
364
|
}
|
|
347
365
|
for (const [n, r] of Object.entries(t))
|
|
348
|
-
n !== T &&
|
|
366
|
+
n !== T && y(r) && s.push(r);
|
|
349
367
|
}
|
|
350
368
|
}
|
|
351
369
|
return !1;
|
|
352
370
|
}
|
|
353
|
-
function
|
|
371
|
+
function we(e, s, t) {
|
|
354
372
|
if (e.op !== "replace" || typeof e.path != "string")
|
|
355
373
|
return !1;
|
|
356
|
-
const n =
|
|
374
|
+
const n = U(e.path);
|
|
357
375
|
if (n.length < 2)
|
|
358
376
|
return !1;
|
|
359
377
|
const r = n.at(-1), o = n.at(-2);
|
|
360
378
|
if (!(r === "blueId" && o !== void 0 && (o === "type" || o === "itemType" || o === "keyType" || o === "valueType")))
|
|
361
379
|
return !1;
|
|
362
|
-
const i =
|
|
363
|
-
if (c &&
|
|
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)
|
|
364
382
|
return !1;
|
|
365
383
|
const u = t.get(c), f = t.get(a);
|
|
366
384
|
if (!u || !f)
|
|
@@ -370,7 +388,7 @@ function he(e, s, t) {
|
|
|
370
388
|
return !0;
|
|
371
389
|
return !1;
|
|
372
390
|
}
|
|
373
|
-
function
|
|
391
|
+
function ve(e, s) {
|
|
374
392
|
let t = e;
|
|
375
393
|
for (const n of s)
|
|
376
394
|
if (Array.isArray(t)) {
|
|
@@ -378,13 +396,13 @@ function be(e, s) {
|
|
|
378
396
|
if (Number.isNaN(r) || r < 0 || r >= t.length)
|
|
379
397
|
return;
|
|
380
398
|
t = t[r];
|
|
381
|
-
} else if (
|
|
399
|
+
} else if (y(t))
|
|
382
400
|
t = t[n];
|
|
383
401
|
else
|
|
384
402
|
return;
|
|
385
403
|
return t;
|
|
386
404
|
}
|
|
387
|
-
function
|
|
405
|
+
function be(e) {
|
|
388
406
|
const s = /* @__PURE__ */ new Map();
|
|
389
407
|
if (!e)
|
|
390
408
|
return s;
|
|
@@ -393,7 +411,7 @@ function we(e) {
|
|
|
393
411
|
continue;
|
|
394
412
|
const n = /* @__PURE__ */ new Map();
|
|
395
413
|
for (const r of t.types || []) {
|
|
396
|
-
const o = r.content, i =
|
|
414
|
+
const o = r.content, i = v(o) && typeof o.name == "string" ? o.name : void 0;
|
|
397
415
|
i && n.set(i, r);
|
|
398
416
|
}
|
|
399
417
|
s.set(t.name, n);
|
|
@@ -414,10 +432,10 @@ function Ee({
|
|
|
414
432
|
discovered: e,
|
|
415
433
|
previousTypes: s,
|
|
416
434
|
aliasToBlueId: t,
|
|
417
|
-
|
|
435
|
+
aliasToStorageContent: n,
|
|
418
436
|
nextRepoVersionIndex: r
|
|
419
437
|
}) {
|
|
420
|
-
const o = /* @__PURE__ */ new Map(), i =
|
|
438
|
+
const o = /* @__PURE__ */ new Map(), i = Te(s, t);
|
|
421
439
|
for (const [c, a] of e) {
|
|
422
440
|
const u = t.get(c);
|
|
423
441
|
if (!u)
|
|
@@ -427,7 +445,7 @@ function Ee({
|
|
|
427
445
|
throw new Error(
|
|
428
446
|
`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`
|
|
429
447
|
);
|
|
430
|
-
const p = n.get(c) ?? a.content,
|
|
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({
|
|
431
449
|
alias: c,
|
|
432
450
|
blueId: u,
|
|
433
451
|
nextRepoVersionIndex: r,
|
|
@@ -437,13 +455,13 @@ function Ee({
|
|
|
437
455
|
typeName: a.typeName,
|
|
438
456
|
blueIdAliases: i
|
|
439
457
|
});
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
458
|
+
d.content = p, d.status = a.status;
|
|
459
|
+
const g = o.get(a.packageName) ?? [];
|
|
460
|
+
g.push(d), o.set(a.packageName, g);
|
|
443
461
|
}
|
|
444
462
|
return o;
|
|
445
463
|
}
|
|
446
|
-
function
|
|
464
|
+
function Te(e, s) {
|
|
447
465
|
const t = /* @__PURE__ */ new Map(), n = (r, o) => {
|
|
448
466
|
const i = t.get(r);
|
|
449
467
|
if (i) {
|
|
@@ -462,7 +480,7 @@ function ve(e, s) {
|
|
|
462
480
|
n(o, r);
|
|
463
481
|
return t;
|
|
464
482
|
}
|
|
465
|
-
function
|
|
483
|
+
function Ae({
|
|
466
484
|
blueId: e,
|
|
467
485
|
nextRepoVersionIndex: s,
|
|
468
486
|
previousType: t
|
|
@@ -471,7 +489,7 @@ function Te({
|
|
|
471
489
|
return {
|
|
472
490
|
status: l.Dev,
|
|
473
491
|
content: {},
|
|
474
|
-
versions: o && n?.versions ?
|
|
492
|
+
versions: o && n?.versions ? S(n.versions) : [
|
|
475
493
|
{
|
|
476
494
|
repositoryVersionIndex: s,
|
|
477
495
|
typeBlueId: e,
|
|
@@ -480,7 +498,7 @@ function Te({
|
|
|
480
498
|
]
|
|
481
499
|
};
|
|
482
500
|
}
|
|
483
|
-
function
|
|
501
|
+
function Be({
|
|
484
502
|
blueId: e,
|
|
485
503
|
nextRepoVersionIndex: s
|
|
486
504
|
}) {
|
|
@@ -506,19 +524,19 @@ function Se({
|
|
|
506
524
|
typeName: i,
|
|
507
525
|
blueIdAliases: c
|
|
508
526
|
}) {
|
|
509
|
-
if (!
|
|
527
|
+
if (!v(n.content))
|
|
510
528
|
throw new Error(
|
|
511
529
|
`Type ${e} has non-object content; cannot compute diff for stable versioning.`
|
|
512
530
|
);
|
|
513
|
-
const a =
|
|
531
|
+
const a = ye(
|
|
514
532
|
n.content,
|
|
515
533
|
r,
|
|
516
534
|
o,
|
|
517
535
|
i,
|
|
518
536
|
c
|
|
519
537
|
);
|
|
520
|
-
if (a.status ===
|
|
521
|
-
const u =
|
|
538
|
+
if (a.status === h.Unchanged) {
|
|
539
|
+
const u = S(n.versions || []), f = u.at(-1);
|
|
522
540
|
if (f && f.typeBlueId !== s)
|
|
523
541
|
throw new Error(
|
|
524
542
|
`Type ${e} content is unchanged but BlueId differs from previous metadata.`
|
|
@@ -529,12 +547,12 @@ function Se({
|
|
|
529
547
|
versions: u
|
|
530
548
|
};
|
|
531
549
|
}
|
|
532
|
-
if (a.status ===
|
|
550
|
+
if (a.status === h.NonBreaking)
|
|
533
551
|
return {
|
|
534
552
|
status: l.Stable,
|
|
535
553
|
content: {},
|
|
536
554
|
versions: [
|
|
537
|
-
...
|
|
555
|
+
...S(n.versions || []),
|
|
538
556
|
{
|
|
539
557
|
repositoryVersionIndex: t,
|
|
540
558
|
typeBlueId: s,
|
|
@@ -546,7 +564,7 @@ function Se({
|
|
|
546
564
|
`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`
|
|
547
565
|
);
|
|
548
566
|
}
|
|
549
|
-
function
|
|
567
|
+
function Pe(e) {
|
|
550
568
|
return Array.from(e.entries()).map(([s, t]) => ({
|
|
551
569
|
name: s,
|
|
552
570
|
types: t.map((n) => ({
|
|
@@ -555,13 +573,13 @@ function Be(e) {
|
|
|
555
573
|
(r, o) => r.repositoryVersionIndex - o.repositoryVersionIndex
|
|
556
574
|
)
|
|
557
575
|
})).sort((n, r) => {
|
|
558
|
-
const o =
|
|
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 : "";
|
|
559
577
|
return o.localeCompare(i);
|
|
560
578
|
})
|
|
561
579
|
})).sort((s, t) => s.name.localeCompare(t.name));
|
|
562
580
|
}
|
|
563
|
-
function
|
|
564
|
-
return
|
|
581
|
+
function Ne(e) {
|
|
582
|
+
return F.INSTANCE.calculateSync(
|
|
565
583
|
e
|
|
566
584
|
);
|
|
567
585
|
}
|
|
@@ -573,25 +591,25 @@ function ke(e, s, t) {
|
|
|
573
591
|
repositoryVersions: o
|
|
574
592
|
}, changed: r };
|
|
575
593
|
}
|
|
576
|
-
function
|
|
594
|
+
function Re(e, s, t) {
|
|
577
595
|
const n = {
|
|
578
596
|
name: R,
|
|
579
597
|
repositoryVersions: s,
|
|
580
|
-
packages:
|
|
598
|
+
packages: Ve(e, t)
|
|
581
599
|
};
|
|
582
|
-
|
|
600
|
+
J(n), z(n);
|
|
583
601
|
}
|
|
584
|
-
function
|
|
602
|
+
function Ve(e, s) {
|
|
585
603
|
const t = {};
|
|
586
604
|
for (const n of e) {
|
|
587
|
-
const r =
|
|
605
|
+
const r = $e(n.name, s), o = {}, i = {};
|
|
588
606
|
for (const c of n.types) {
|
|
589
607
|
const a = c.versions?.[c.versions.length - 1]?.typeBlueId;
|
|
590
608
|
if (!a)
|
|
591
609
|
throw new Error(
|
|
592
610
|
`Type ${n.name} is missing a current BlueId in versions.`
|
|
593
611
|
);
|
|
594
|
-
const u =
|
|
612
|
+
const u = xe(c);
|
|
595
613
|
o[a] = {
|
|
596
614
|
status: c.status,
|
|
597
615
|
name: u,
|
|
@@ -608,26 +626,26 @@ function Re(e, s) {
|
|
|
608
626
|
}
|
|
609
627
|
return t;
|
|
610
628
|
}
|
|
611
|
-
function
|
|
629
|
+
function $e(e, s) {
|
|
612
630
|
const t = {}, n = `${e}/`;
|
|
613
631
|
return s.forEach((r, o) => {
|
|
614
632
|
o.startsWith(n) && (t[o] = r);
|
|
615
633
|
}), t;
|
|
616
634
|
}
|
|
617
|
-
function
|
|
618
|
-
const s =
|
|
635
|
+
function xe(e) {
|
|
636
|
+
const s = v(e.content) && typeof e.content.name == "string" ? e.content.name : null;
|
|
619
637
|
if (!s)
|
|
620
638
|
throw new Error('Type content is missing required "name" field.');
|
|
621
639
|
return s;
|
|
622
640
|
}
|
|
623
|
-
function
|
|
624
|
-
if (!
|
|
641
|
+
function Me(e) {
|
|
642
|
+
if (!b.existsSync(e))
|
|
625
643
|
return { previous: null };
|
|
626
|
-
const s =
|
|
627
|
-
if (!t || !
|
|
644
|
+
const s = b.readFileSync(e, "utf8"), t = j(s);
|
|
645
|
+
if (!t || !y(t))
|
|
628
646
|
throw new Error("Existing BlueRepository.blue is not a valid object.");
|
|
629
647
|
const n = t, r = n.packages, o = n.repositoryVersions, i = Array.isArray(r) && r.every(
|
|
630
|
-
(p) =>
|
|
648
|
+
(p) => y(p) && typeof p.name == "string" && Array.isArray(p.types)
|
|
631
649
|
), c = Array.isArray(o) && o.every((p) => typeof p == "string");
|
|
632
650
|
if (!i || !c)
|
|
633
651
|
throw new Error(
|
|
@@ -640,45 +658,45 @@ function _e(e) {
|
|
|
640
658
|
};
|
|
641
659
|
return { existingYaml: s, previous: f };
|
|
642
660
|
}
|
|
643
|
-
function
|
|
644
|
-
return
|
|
661
|
+
function Oe(e) {
|
|
662
|
+
return K.dump(e, { lineWidth: -1 });
|
|
645
663
|
}
|
|
646
664
|
function Fe(e) {
|
|
647
|
-
const s =
|
|
665
|
+
const s = x.resolve(e.repoRoot), t = x.resolve(e.blueRepositoryPath), { existingYaml: n, previous: r } = Me(t), o = Q(s), i = be(r);
|
|
648
666
|
Ie(o, i);
|
|
649
|
-
const c =
|
|
650
|
-
|
|
651
|
-
const { aliasToBlueId: u,
|
|
667
|
+
const c = ne(o), a = re(c);
|
|
668
|
+
se(c, o);
|
|
669
|
+
const { aliasToBlueId: u, aliasToStorageContent: f } = ce(
|
|
652
670
|
a,
|
|
653
671
|
o
|
|
654
|
-
), p = r ? r.repositoryVersions.length : 0,
|
|
672
|
+
), p = r ? r.repositoryVersions.length : 0, d = Ee({
|
|
655
673
|
discovered: o,
|
|
656
674
|
previousTypes: i,
|
|
657
675
|
aliasToBlueId: u,
|
|
658
|
-
|
|
676
|
+
aliasToStorageContent: f,
|
|
659
677
|
nextRepoVersionIndex: p
|
|
660
|
-
}),
|
|
661
|
-
|
|
678
|
+
}), g = Pe(d), w = Ne(g), { document: I, changed: E } = ke(
|
|
679
|
+
g,
|
|
662
680
|
r,
|
|
663
|
-
|
|
681
|
+
w
|
|
664
682
|
);
|
|
665
|
-
|
|
683
|
+
Re(
|
|
666
684
|
I.packages,
|
|
667
685
|
I.repositoryVersions,
|
|
668
686
|
u
|
|
669
687
|
);
|
|
670
|
-
const $ =
|
|
671
|
-
if (r && !
|
|
688
|
+
const $ = Oe(I);
|
|
689
|
+
if (r && !E && n && n !== $)
|
|
672
690
|
throw new Error(
|
|
673
691
|
"BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode."
|
|
674
692
|
);
|
|
675
693
|
return e.verbose && console.info(
|
|
676
|
-
`[repository-generator] RepoBlueId: ${
|
|
694
|
+
`[repository-generator] RepoBlueId: ${w} (${E ? "changed" : "unchanged"})`
|
|
677
695
|
), {
|
|
678
696
|
document: I,
|
|
679
|
-
currentRepoBlueId:
|
|
697
|
+
currentRepoBlueId: w,
|
|
680
698
|
previousRepoBlueId: r?.repositoryVersions.at(-1),
|
|
681
|
-
changed:
|
|
699
|
+
changed: E || !n,
|
|
682
700
|
yaml: $,
|
|
683
701
|
existingYaml: n
|
|
684
702
|
};
|
|
@@ -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"}
|
|
@@ -2,8 +2,8 @@ import { JsonValue } from '@blue-labs/shared-utils';
|
|
|
2
2
|
import { Alias, DiscoveredType, JsonMap } from './internalTypes';
|
|
3
3
|
export declare function computeBlueIds(topoOrder: Alias[], discovered: Map<Alias, DiscoveredType>): {
|
|
4
4
|
aliasToBlueId: Map<Alias, string>;
|
|
5
|
-
|
|
5
|
+
aliasToStorageContent: Map<Alias, JsonMap>;
|
|
6
6
|
};
|
|
7
|
+
export declare function lookupStorageContentByBlueId(contentByBlueId: ReadonlyMap<string, JsonValue>, blueId: string): JsonValue[];
|
|
7
8
|
export declare function substituteAliases(content: JsonValue, aliasToBlueId: Map<Alias, string>, skipContracts?: boolean, underContracts?: boolean): JsonValue;
|
|
8
|
-
export declare function normalizeForBlueId(value: JsonValue, parentHasExplicitType?: boolean): JsonValue;
|
|
9
9
|
//# sourceMappingURL=blueIds.d.ts.map
|
|
@@ -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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repoDoc.d.ts","sourceRoot":"","sources":["../../../src/lib/core/repoDoc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,GAC/C,WAAW,EAAE,CAwBf;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"repoDoc.d.ts","sourceRoot":"","sources":["../../../src/lib/core/repoDoc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAO9C,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,GAC/C,WAAW,EAAE,CAwBf;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAMjE;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,WAAW,EAAE,EACvB,QAAQ,EAAE,sBAAsB,GAAG,IAAI,EACvC,iBAAiB,EAAE,MAAM,GACxB;IAAE,QAAQ,EAAE,sBAAsB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAmBxD"}
|
|
@@ -6,9 +6,9 @@ interface BuildPackagesArgs {
|
|
|
6
6
|
discovered: Map<Alias, DiscoveredType>;
|
|
7
7
|
previousTypes: PackageTypeMap;
|
|
8
8
|
aliasToBlueId: Map<Alias, string>;
|
|
9
|
-
|
|
9
|
+
aliasToStorageContent: Map<Alias, JsonMap>;
|
|
10
10
|
nextRepoVersionIndex: number;
|
|
11
11
|
}
|
|
12
|
-
export declare function buildPackages({ discovered, previousTypes, aliasToBlueId,
|
|
12
|
+
export declare function buildPackages({ discovered, previousTypes, aliasToBlueId, aliasToStorageContent, nextRepoVersionIndex, }: BuildPackagesArgs): Map<PackageName, BlueTypeMetadata[]>;
|
|
13
13
|
export {};
|
|
14
14
|
//# sourceMappingURL=versions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../src/lib/core/versions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,KAAK,EACL,cAAc,EACd,OAAO,EACP,cAAc,EAEd,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,GACtC,cAAc,CA0BhB;AAED,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,EACtC,aAAa,EAAE,cAAc,QAe9B;AAED,UAAU,iBAAiB;IACzB,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACvC,aAAa,EAAE,cAAc,CAAC;IAC9B,aAAa,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClC,
|
|
1
|
+
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../../../src/lib/core/versions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,KAAK,EACL,cAAc,EACd,OAAO,EACP,cAAc,EAEd,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,GACtC,cAAc,CA0BhB;AAED,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,EACtC,aAAa,EAAE,cAAc,QAe9B;AAED,UAAU,iBAAiB;IACzB,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACvC,aAAa,EAAE,cAAc,CAAC;IAC9B,aAAa,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAClC,qBAAqB,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3C,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,aAAa,CAAC,EAC5B,UAAU,EACV,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,oBAAoB,GACrB,EAAE,iBAAiB,GAAG,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAC,CAkD1D"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blue-labs/repository-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
4
4
|
"bin": {
|
|
5
5
|
"blue-repo-generator": "./dist/bin/blue-repo-generator.mjs"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@blue-labs/language": "
|
|
9
|
-
"@blue-labs/repository-contract": "
|
|
8
|
+
"@blue-labs/language": "4.0.0-rc.1",
|
|
9
|
+
"@blue-labs/repository-contract": "4.0.0-rc.1",
|
|
10
10
|
"fast-json-patch": "3.1.1",
|
|
11
11
|
"js-yaml": "4.1.0",
|
|
12
|
-
"@blue-labs/shared-utils": "
|
|
12
|
+
"@blue-labs/shared-utils": "4.0.0-rc.1"
|
|
13
13
|
},
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const T=require("path"),E=require("fs"),w=require("@blue-labs/language"),y=require("@blue-labs/repository-contract"),U=require("fast-json-patch"),q=require("js-yaml");function F(e){const r=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(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const M=F(T),N=new Set([...w.Properties.CORE_TYPES]),h=w.Properties.CORE_TYPE_NAME_TO_BLUE_ID_MAP,R="Blue Repository",l={Dev:"dev",Stable:"stable"},L=new Set([".git",".github",".husky","node_modules",".nx",".vscode",".idea"]);function Y(e){const r=E.readdirSync(e,{withFileTypes:!0}),t=new Map;for(const n of r){if(!n.isDirectory()||L.has(n.name))continue;const s=T.join(e,n.name),o=x(s);if(o.length!==0)for(const i of o){const c=i.endsWith(".dev.blue")?l.Dev:l.Stable,a=W(i),u=G(a,i),f=`${n.name}/${u}`,p=t.get(f);if(p)throw p.status!==c?new Error(`Type ${f} has both stable and dev definitions (${p.filePath} and ${i}).`):new Error(`Type ${f} is defined multiple times (${p.filePath} and ${i}).`);const g=z(a,i);t.set(f,{packageName:n.name,typeName:u,status:c,content:a,filePath:i,references:g})}}return t}function W(e){const r=E.readFileSync(e,"utf8"),t=w.yamlBlueParse(r);if(!$(t))throw new Error(`Type file ${e} must contain a YAML object.`);return t}function G(e,r){if(!$(e)||typeof e.name!="string")throw new Error(`Type file ${r} is missing required "name" field.`);return e.name}function x(e){const r=E.readdirSync(e,{withFileTypes:!0}),t=[];for(const n of r){if(n.isDirectory()){t.push(...x(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 z(e,r){const t=new Set,n=s=>{if(Array.isArray(s)){s.forEach(i=>n(i));return}if(!$(s))return;const o=i=>{if(typeof i=="string"&&!N.has(i)){if(!i.includes("/"))throw new Error(`Invalid type reference "${i}" in ${r}. Use <Package>/<Type> for non-primitive references.`);t.add(i)}};o(s.type),o(s.itemType),o(s.keyType),o(s.valueType),Object.values(s).forEach(i=>n(i))};return n(e),t}function $(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function J(e){const r=new Map;for(const[t,n]of e){const s=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.`);s.add(o)}r.set(t,s)}return r}function H(e){const r=[],t=new Map,n=(s,o)=>{const i=t.get(s);if(i==="visited")return;if(i==="visiting"){const a=[...o,s].join(" -> ");throw new Error(`Circular type dependency detected: ${a}`)}t.set(s,"visiting"),o.push(s);const c=e.get(s)||new Set;for(const a of c)n(a,o);o.pop(),t.set(s,"visited"),r.push(s)};for(const s of e.keys())t.has(s)||n(s,[]);return r}function K(e,r){const t=new Map,n=s=>{if(t.has(s))return t.get(s)??!1;const o=e.get(s)||new Set;for(const i of o){const c=r.get(i);if(c&&(c.status===l.Dev||n(i)))return t.set(s,!0),!0}return t.set(s,!1),!1};for(const[s,o]of r)if(o.status===l.Stable&&n(s))throw new Error(`Stable type ${s} depends on a dev type. Stable types may only depend on other stable types.`)}function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function b(e){return d(e)?Object.getPrototypeOf(e)===Object.prototype:!1}function B(e){if(Array.isArray(e))return e.map(r=>B(r));if(b(e)){const r={};for(const[t,n]of Object.entries(e))r[t]=B(n);return r}return e}function P(e){return e.map(r=>({repositoryVersionIndex:r.repositoryVersionIndex,typeBlueId:r.typeBlueId,attributesAdded:[...r.attributesAdded]}))}function Q(e,r){const t=new Map,n=new Map;for(const s of e){const o=r.get(s);if(!o)continue;const i=k(B(o.content),t),c=O(i),a=N.has(o.typeName)?X(o.typeName):w.BlueIdCalculator.INSTANCE.calculateSync(c);t.set(s,a),n.set(s,c)}return{aliasToBlueId:t,aliasToPreprocessed:n}}function k(e,r,t=!1,n=!1){if(Array.isArray(e))return e.map(o=>k(o,r,t,n));if(!d(e))return e;const s={};for(const[o,i]of Object.entries(e)){const c=n||o===y.OBJECT_CONTRACTS;if((o==="type"||o==="itemType"||o==="keyType"||o==="valueType")&&typeof i=="string"&&!(t&&c)){if(N.has(i)){const a=h[i];if(!a)throw new Error(`Missing primitive BlueId for ${i}.`);s[o]={blueId:a}}else{const a=i,u=r.get(a);if(!u)throw new Error(`Missing BlueId for alias ${a}.`);s[o]={blueId:u}}continue}s[o]=k(i,r,t,c)}return s}function O(e,r=!1){if(Array.isArray(e))return{items:e.map(n=>O(n))};if(b(e)){if(ee(e))return{blueId:e.blueId};const t=te(e),n={};for(const[s,o]of Object.entries(e)){if(D(o)){re(s,t)?n[s]=o:n[s]=V(o);continue}n[s]=O(o,t)}return n}return D(e)?r?e:V(e):e}function X(e){const r=h[e];if(!r)throw new Error(`Missing primitive BlueId for ${e}.`);return r}function V(e){const r=Z(e),t={value:e};return r&&(t.type={blueId:r}),t}function Z(e){return typeof e=="string"?h.Text:typeof e=="boolean"?h.Boolean:typeof e=="number"?Number.isInteger(e)?h.Integer:h.Double:null}function D(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function ee(e){const r=Object.entries(e);return r.length===1&&r[0]?.[0]==="blueId"&&typeof r[0]?.[1]=="string"}function te(e){return Object.prototype.hasOwnProperty.call(e,"type")||Object.prototype.hasOwnProperty.call(e,"itemType")||Object.prototype.hasOwnProperty.call(e,"keyType")||Object.prototype.hasOwnProperty.call(e,"valueType")}const ne=new Set(["name","description","blueId"]);function re(e,r){return!!(ne.has(e)||r&&e==="value")}const j=new Set(Object.values(h)),se=new Set(["type","itemType","valueType","keyType"]),oe=new Set(["name","description"]),m={Unchanged:"unchanged",NonBreaking:"non-breaking",Breaking:"breaking"};function ie(e,r,t,n,s){const o=U.compare(e,r);if(o.length===0)return{status:m.Unchanged,attributesAdded:[]};const i=[];let c=!1;for(const a of o){if(fe(a,e,s)){c=!0;continue}if(a.op!=="add")return{status:m.Breaking,attributesAdded:[]};if(!ce(a))return{status:m.Breaking,attributesAdded:[]};i.push(a.path)}return i.length===0&&!c?{status:m.Breaking,attributesAdded:[]}:(i.length>0&&ae(i,t,n),{status:m.NonBreaking,attributesAdded:i})}function ae(e,r,t){for(const n of e)try{y.validateAttributesAddedPointer(n)}catch(s){throw new Error(`Invalid attribute pointer "${n}" for ${r}/${t}: ${s.message}`)}}function ce(e){if(e.op!=="add")return!1;const r=C(e.path);if(r.length===0)return!1;const t=r.at(-1);return t&&/^\d+$/.test(t)||t&&se.has(t)||r.some(n=>y.RESERVED_ATTRIBUTES_POINTER_SEGMENTS.has(n))?!1:d(e.value)?!ue(e.value):t?oe.has(t):!1}function C(e){try{return y.parsePointer(e)}catch{return[]}}function ue(e){const r=[e];for(;r.length;){const t=r.pop();if(t){if(Object.prototype.hasOwnProperty.call(t,"value")||Object.prototype.hasOwnProperty.call(t,"items"))return!0;if(Object.prototype.hasOwnProperty.call(t,y.OBJECT_SCHEMA)){const n=t[y.OBJECT_SCHEMA];if(d(n)&&n.required===!0)return!0}for(const[n,s]of Object.entries(t))n!==y.OBJECT_SCHEMA&&d(s)&&r.push(s)}}return!1}function fe(e,r,t){if(e.op!=="replace"||typeof e.path!="string")return!1;const n=C(e.path);if(n.length<2)return!1;const s=n.at(-1),o=n.at(-2);if(!(s==="blueId"&&o!==void 0&&(o==="type"||o==="itemType"||o==="keyType"||o==="valueType")))return!1;const i=pe(r,n),c=typeof i=="string"?i:d(i)&&typeof i.blueId=="string"?i.blueId:null,a=typeof e.value=="string"?e.value:d(e.value)&&typeof e.value.blueId=="string"?e.value.blueId:null;if(c&&j.has(c)||a&&j.has(a)||!c||!a)return!1;const u=t.get(c),f=t.get(a);if(!u||!f)return!1;for(const p of u)if(f.has(p))return!0;return!1}function pe(e,r){let t=e;for(const n of r)if(Array.isArray(t)){const s=Number(n);if(Number.isNaN(s)||s<0||s>=t.length)return;t=t[s]}else if(d(t))t=t[n];else return;return t}function le(e){const r=new Map;if(!e)return r;for(const t of e.packages||[]){if(typeof t.name!="string")continue;const n=new Map;for(const s of t.types||[]){const o=s.content,i=b(o)&&typeof o.name=="string"?o.name:void 0;i&&n.set(i,s)}r.set(t.name,n)}return r}function de(e,r){for(const[t,n]of r)for(const[s,o]of n){const i=`${t}/${s}`;if(!e.has(i)&&o.status===l.Stable)throw new Error(`Stable type ${i} was removed. Breaking changes require a new logical type name.`)}}function ye({discovered:e,previousTypes:r,aliasToBlueId:t,aliasToPreprocessed:n,nextRepoVersionIndex:s}){const o=new Map,i=ge(r,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=r.get(a.packageName)?.get(a.typeName)??null;if(f&&f.status===l.Stable&&a.status===l.Dev)throw new Error(`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`);const p=n.get(c)??a.content,g=a.status===l.Dev?me({blueId:u,nextRepoVersionIndex:s,previousType:f}):!f||f.status===l.Dev?he({blueId:u,nextRepoVersionIndex:s}):be({alias:c,blueId:u,nextRepoVersionIndex:s,previousType:f,currentContent:p,packageName:a.packageName,typeName:a.typeName,blueIdAliases:i});g.content=p,g.status=a.status;const I=o.get(a.packageName)??[];I.push(g),o.set(a.packageName,I)}return o}function ge(e,r){const t=new Map,n=(s,o)=>{const i=t.get(s);if(i){i.add(o);return}t.set(s,new Set([o]))};for(const[s,o]of e)for(const[i,c]of o){const a=`${s}/${i}`;for(const u of c.versions??[])typeof u.typeBlueId=="string"&&n(u.typeBlueId,a)}for(const[s,o]of r)n(o,s);return t}function me({blueId:e,nextRepoVersionIndex:r,previousType:t}){const n=t&&t.status===l.Dev?t:null,s=n?.versions?.length===1?n.versions[0]:null,o=s&&s.typeBlueId===e;return{status:l.Dev,content:{},versions:o&&n?.versions?P(n.versions):[{repositoryVersionIndex:r,typeBlueId:e,attributesAdded:[]}]}}function he({blueId:e,nextRepoVersionIndex:r}){return{status:l.Stable,content:{},versions:[{repositoryVersionIndex:r,typeBlueId:e,attributesAdded:[]}]}}function be({alias:e,blueId:r,nextRepoVersionIndex:t,previousType:n,currentContent:s,packageName:o,typeName:i,blueIdAliases:c}){if(!b(n.content))throw new Error(`Type ${e} has non-object content; cannot compute diff for stable versioning.`);const a=ie(n.content,s,o,i,c);if(a.status===m.Unchanged){const u=P(n.versions||[]),f=u.at(-1);if(f&&f.typeBlueId!==r)throw new Error(`Type ${e} content is unchanged but BlueId differs from previous metadata.`);return{status:l.Stable,content:{},versions:u}}if(a.status===m.NonBreaking)return{status:l.Stable,content:{},versions:[...P(n.versions||[]),{repositoryVersionIndex:t,typeBlueId:r,attributesAdded:a.attributesAdded}]};throw new Error(`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`)}function we(e){return Array.from(e.entries()).map(([r,t])=>({name:r,types:t.map(n=>({...n,versions:[...n.versions].sort((s,o)=>s.repositoryVersionIndex-o.repositoryVersionIndex)})).sort((n,s)=>{const o=b(n.content)&&typeof n.content.name=="string"?n.content.name:"",i=b(s.content)&&typeof s.content.name=="string"?s.content.name:"";return o.localeCompare(i)})})).sort((r,t)=>r.name.localeCompare(t.name))}function Ie(e){return w.BlueIdCalculator.INSTANCE.calculateSync(e)}function Ee(e,r,t){const n=r?.repositoryVersions.at(-1),s=!n||n!==t,o=r?.repositoryVersions?[...r.repositoryVersions]:[];return s&&o.push(t),{document:{name:R,packages:e,repositoryVersions:o},changed:s}}function ve(e,r,t){const n={name:R,repositoryVersions:r,packages:Te(e,t)};y.validateNoCycles(n),y.validateStableDoesNotDependOnDev(n)}function Te(e,r){const t={};for(const n of e){const s=Ae(n.name,r),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=Se(c);o[a]={status:c.status,name:u,versions:c.versions??[]},i[a]=c.content}t[n.name]={name:n.name,aliases:s,typesMeta:o,contents:i,schemas:{}}}return t}function Ae(e,r){const t={},n=`${e}/`;return r.forEach((s,o)=>{o.startsWith(n)&&(t[o]=s)}),t}function Se(e){const r=b(e.content)&&typeof e.content.name=="string"?e.content.name:null;if(!r)throw new Error('Type content is missing required "name" field.');return r}function Be(e){if(!E.existsSync(e))return{previous:null};const r=E.readFileSync(e,"utf8"),t=w.yamlBlueParse(r);if(!t||!d(t))throw new Error("Existing BlueRepository.blue is not a valid object.");const n=t,s=n.packages,o=n.repositoryVersions,i=Array.isArray(s)&&s.every(p=>d(p)&&typeof p.name=="string"&&Array.isArray(p.types)),c=Array.isArray(o)&&o.every(p=>typeof p=="string");if(!i||!c)throw new Error("Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }");const a=s,u=o,f={name:typeof n.name=="string"?n.name:R,packages:a,repositoryVersions:u};return{existingYaml:r,previous:f}}function Pe(e){return q.dump(e,{lineWidth:-1})}function ke(e){const r=M.resolve(e.repoRoot),t=M.resolve(e.blueRepositoryPath),{existingYaml:n,previous:s}=Be(t),o=Y(r),i=le(s);de(o,i);const c=J(o),a=H(c);K(c,o);const{aliasToBlueId:u,aliasToPreprocessed:f}=Q(a,o),p=s?s.repositoryVersions.length:0,g=ye({discovered:o,previousTypes:i,aliasToBlueId:u,aliasToPreprocessed:f,nextRepoVersionIndex:p}),I=we(g),A=Ie(I),{document:v,changed:S}=Ee(I,s,A);ve(v.packages,v.repositoryVersions,u);const _=Pe(v);if(s&&!S&&n&&n!==_)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: ${A} (${S?"changed":"unchanged"})`),{document:v,currentRepoBlueId:A,previousRepoBlueId:s?.repositoryVersions.at(-1),changed:S||!n,yaml:_,existingYaml:n}}exports.generateRepository=ke;
|