@blue-labs/repository-generator 3.10.0 → 4.0.0-rc.0

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.
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";const c=require("fs"),a=require("path"),f=require("../generateRepository-BwxSxjH3.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();
2
+ "use strict";const c=require("fs"),a=require("path"),f=require("../generateRepository-CNSvDkC2.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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import * as l from "fs";
3
3
  import * as i from "path";
4
- import { g as u } from "../generateRepository-C2IfsNUG.mjs";
4
+ import { g as u } from "../generateRepository-DBYEfJm2.mjs";
5
5
  function a(e) {
6
6
  const o = {
7
7
  repoRoot: process.cwd(),
@@ -0,0 +1 @@
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;
@@ -1,14 +1,14 @@
1
- import * as _ from "path";
1
+ import * as V from "path";
2
2
  import A from "path";
3
- import w from "fs";
4
- import { Properties as x, yamlBlueParse as j, BlueIdCalculator as C } from "@blue-labs/language";
5
- import { OBJECT_CONTRACTS as L, RESERVED_ATTRIBUTES_POINTER_SEGMENTS as Y, validateAttributesAddedPointer as W, parsePointer as G, OBJECT_SCHEMA as T, validateNoCycles as q, validateStableDoesNotDependOnDev as z } from "@blue-labs/repository-contract";
3
+ import b from "fs";
4
+ import { Properties as M, yamlBlueParse as O, Blue as x, createNodeProvider as C, BlueIdCalculator as U } from "@blue-labs/language";
5
+ import { OBJECT_CONTRACTS as F, RESERVED_ATTRIBUTES_POINTER_SEGMENTS as L, validateAttributesAddedPointer as Y, parsePointer as G, OBJECT_SCHEMA as E, validateNoCycles as W, validateStableDoesNotDependOnDev as q } from "@blue-labs/repository-contract";
6
6
  import J from "fast-json-patch";
7
- import H from "js-yaml";
8
- const N = /* @__PURE__ */ new Set([...x.CORE_TYPES]), g = x.CORE_TYPE_NAME_TO_BLUE_ID_MAP, R = "Blue Repository", l = {
7
+ import z from "js-yaml";
8
+ const k = /* @__PURE__ */ new Set([...M.CORE_TYPES]), N = M.CORE_TYPE_NAME_TO_BLUE_ID_MAP, P = "Blue Repository", l = {
9
9
  Dev: "dev",
10
10
  Stable: "stable"
11
- }, K = /* @__PURE__ */ new Set([
11
+ }, H = /* @__PURE__ */ new Set([
12
12
  ".git",
13
13
  ".github",
14
14
  ".husky",
@@ -17,66 +17,66 @@ const N = /* @__PURE__ */ new Set([...x.CORE_TYPES]), g = x.CORE_TYPE_NAME_TO_BL
17
17
  ".vscode",
18
18
  ".idea"
19
19
  ]);
20
- function Q(e) {
21
- const s = w.readdirSync(e, { withFileTypes: !0 }), t = /* @__PURE__ */ new Map();
20
+ function K(e) {
21
+ const s = b.readdirSync(e, { withFileTypes: !0 }), t = /* @__PURE__ */ new Map();
22
22
  for (const n of s) {
23
- if (!n.isDirectory() || K.has(n.name))
23
+ if (!n.isDirectory() || H.has(n.name))
24
24
  continue;
25
- const r = A.join(e, n.name), o = U(r);
25
+ const r = A.join(e, n.name), o = D(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 = X(i), u = Z(a, i), f = `${n.name}/${u}`, p = t.get(f);
28
+ const c = i.endsWith(".dev.blue") ? l.Dev : l.Stable, a = Q(i), u = X(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 y = ee(a, i);
35
+ const d = Z(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: y
42
+ references: d
43
43
  });
44
44
  }
45
45
  }
46
46
  return t;
47
47
  }
48
- function X(e) {
49
- const s = w.readFileSync(e, "utf8"), t = j(s);
50
- if (!O(t))
48
+ function Q(e) {
49
+ const s = b.readFileSync(e, "utf8"), t = O(s);
50
+ if (!R(t))
51
51
  throw new Error(`Type file ${e} must contain a YAML object.`);
52
52
  return t;
53
53
  }
54
- function Z(e, s) {
55
- if (!O(e) || typeof e.name != "string")
54
+ function X(e, s) {
55
+ if (!R(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 U(e) {
60
- const s = w.readdirSync(e, { withFileTypes: !0 }), t = [];
59
+ function D(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(...U(A.join(e, n.name)));
63
+ t.push(...D(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 ee(e, s) {
70
+ function Z(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 (!O(r))
76
+ if (!R(r))
77
77
  return;
78
78
  const o = (i) => {
79
- if (typeof i == "string" && !N.has(i)) {
79
+ if (typeof i == "string" && !k.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 ee(e, s) {
88
88
  };
89
89
  return n(e), t;
90
90
  }
91
- function O(e) {
91
+ function R(e) {
92
92
  return typeof e == "object" && e !== null && !Array.isArray(e);
93
93
  }
94
- function te(e) {
94
+ function ee(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 ne(e) {
109
+ function te(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 re(e, s) {
128
+ function ne(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,62 +143,88 @@ 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 d(e) {
146
+ function y(e) {
147
147
  return typeof e == "object" && e !== null && !Array.isArray(e);
148
148
  }
149
- function h(e) {
150
- return d(e) ? Object.getPrototypeOf(e) === Object.prototype : !1;
149
+ function v(e) {
150
+ return y(e) ? Object.getPrototypeOf(e) === Object.prototype : !1;
151
151
  }
152
- function S(e) {
152
+ function B(e) {
153
153
  if (Array.isArray(e))
154
- return e.map((s) => S(s));
155
- if (h(e)) {
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] = S(n);
158
+ s[t] = B(n);
159
159
  return s;
160
160
  }
161
161
  return e;
162
162
  }
163
- function B(e) {
163
+ function T(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
- function se(e, s) {
171
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
172
- for (const r of e) {
173
- const o = s.get(r);
174
- if (!o)
170
+ function re(e, s) {
171
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), o = new x(), i = C(
172
+ (a) => se(r, a).map(
173
+ (u) => o.jsonValueToNode(u)
174
+ )
175
+ ), c = new x({ nodeProvider: i });
176
+ for (const a of e) {
177
+ const u = s.get(a);
178
+ if (!u)
175
179
  continue;
176
- const i = P(
177
- S(o.content),
180
+ const f = S(
181
+ B(u.content),
178
182
  t
179
- ), c = k(i), a = N.has(o.typeName) ? oe(o.typeName) : C.INSTANCE.calculateSync(c);
180
- t.set(r, a), n.set(r, c);
183
+ ), p = c.jsonValueToNode(f), d = k.has(u.typeName), m = d ? ie(u.typeName) : c.calculateBlueIdSync(p), h = c.nodeToJson(p, "official");
184
+ t.set(a, m), n.set(a, h), d || r.set(m, h), c.registerBlueIds({ [a]: m });
181
185
  }
182
- return { aliasToBlueId: t, aliasToPreprocessed: n };
186
+ return { aliasToBlueId: t, aliasToStorageContent: n };
183
187
  }
184
- function P(e, s, t = !1, n = !1) {
188
+ function se(e, s) {
189
+ const t = oe(s);
190
+ if (t === void 0)
191
+ return [];
192
+ const n = e.get(t.baseBlueId);
193
+ if (n === void 0)
194
+ return [];
195
+ if (t.index === void 0)
196
+ return Array.isArray(n) ? n : [n];
197
+ if (!Array.isArray(n))
198
+ return t.index === 0 ? [n] : [];
199
+ const r = n[t.index];
200
+ return r === void 0 ? [] : [r];
201
+ }
202
+ function oe(e) {
203
+ const s = e.indexOf("#");
204
+ if (s === -1)
205
+ return { baseBlueId: e };
206
+ const t = e.slice(0, s), n = e.slice(s + 1), r = Number(n);
207
+ if (!(!Number.isInteger(r) || r < 0))
208
+ return { baseBlueId: t, index: r };
209
+ }
210
+ function S(e, s, t = !1, n = !1) {
185
211
  if (Array.isArray(e))
186
212
  return e.map(
187
- (o) => P(
213
+ (o) => S(
188
214
  o,
189
215
  s,
190
216
  t,
191
217
  n
192
218
  )
193
219
  );
194
- if (!d(e))
220
+ if (!y(e))
195
221
  return e;
196
222
  const r = {};
197
223
  for (const [o, i] of Object.entries(e)) {
198
- const c = n || o === L;
224
+ const c = n || o === F;
199
225
  if ((o === "type" || o === "itemType" || o === "keyType" || o === "valueType") && typeof i == "string" && !(t && c)) {
200
- if (N.has(i)) {
201
- const a = g[i];
226
+ if (k.has(i)) {
227
+ const a = N[i];
202
228
  if (!a)
203
229
  throw new Error(`Missing primitive BlueId for ${i}.`);
204
230
  r[o] = { blueId: a };
@@ -210,7 +236,7 @@ function P(e, s, t = !1, n = !1) {
210
236
  }
211
237
  continue;
212
238
  }
213
- r[o] = P(
239
+ r[o] = S(
214
240
  i,
215
241
  s,
216
242
  t,
@@ -219,148 +245,104 @@ function P(e, s, t = !1, n = !1) {
219
245
  }
220
246
  return r;
221
247
  }
222
- function k(e, s = !1) {
223
- if (Array.isArray(e))
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];
248
+ function ie(e) {
249
+ const s = N[e];
247
250
  if (!s)
248
251
  throw new Error(`Missing primitive BlueId for ${e}.`);
249
252
  return s;
250
253
  }
251
- function V(e) {
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([
254
+ const _ = new Set(Object.values(N)), ae = /* @__PURE__ */ new Set([
273
255
  "type",
274
256
  "itemType",
275
257
  "valueType",
276
258
  "keyType"
277
- ]), le = /* @__PURE__ */ new Set(["name", "description"]), m = {
259
+ ]), ce = /* @__PURE__ */ new Set(["name", "description"]), g = {
278
260
  Unchanged: "unchanged",
279
261
  NonBreaking: "non-breaking",
280
262
  Breaking: "breaking"
281
263
  };
282
- function de(e, s, t, n, r) {
264
+ function ue(e, s, t, n, r) {
283
265
  const o = J.compare(
284
266
  e,
285
267
  s
286
268
  );
287
269
  if (o.length === 0)
288
- return { status: m.Unchanged, attributesAdded: [] };
270
+ return { status: g.Unchanged, attributesAdded: [] };
289
271
  const i = [];
290
272
  let c = !1;
291
273
  for (const a of o) {
292
- if (he(a, e, r)) {
274
+ if (de(a, e, r)) {
293
275
  c = !0;
294
276
  continue;
295
277
  }
296
278
  if (a.op !== "add")
297
- return { status: m.Breaking, attributesAdded: [] };
298
- if (!me(a))
299
- return { status: m.Breaking, attributesAdded: [] };
279
+ return { status: g.Breaking, attributesAdded: [] };
280
+ if (!pe(a))
281
+ return { status: g.Breaking, attributesAdded: [] };
300
282
  i.push(a.path);
301
283
  }
302
284
  return i.length === 0 && !c ? {
303
- status: m.Breaking,
285
+ status: g.Breaking,
304
286
  attributesAdded: []
305
- } : (i.length > 0 && ye(i, t, n), { status: m.NonBreaking, attributesAdded: i });
287
+ } : (i.length > 0 && fe(i, t, n), { status: g.NonBreaking, attributesAdded: i });
306
288
  }
307
- function ye(e, s, t) {
289
+ function fe(e, s, t) {
308
290
  for (const n of e)
309
291
  try {
310
- W(n);
292
+ Y(n);
311
293
  } catch (r) {
312
294
  throw new Error(
313
295
  `Invalid attribute pointer "${n}" for ${s}/${t}: ${r.message}`
314
296
  );
315
297
  }
316
298
  }
317
- function me(e) {
299
+ function pe(e) {
318
300
  if (e.op !== "add")
319
301
  return !1;
320
- const s = F(e.path);
302
+ const s = j(e.path);
321
303
  if (s.length === 0)
322
304
  return !1;
323
305
  const t = s.at(-1);
324
- return t && /^\d+$/.test(t) || t && pe.has(t) || s.some(
325
- (n) => Y.has(n)
326
- ) ? !1 : d(e.value) ? !ge(e.value) : t ? le.has(t) : !1;
306
+ return t && /^\d+$/.test(t) || t && ae.has(t) || s.some(
307
+ (n) => L.has(n)
308
+ ) ? !1 : y(e.value) ? !le(e.value) : t ? ce.has(t) : !1;
327
309
  }
328
- function F(e) {
310
+ function j(e) {
329
311
  try {
330
312
  return G(e);
331
313
  } catch {
332
314
  return [];
333
315
  }
334
316
  }
335
- function ge(e) {
317
+ function le(e) {
336
318
  const s = [e];
337
319
  for (; s.length; ) {
338
320
  const t = s.pop();
339
321
  if (t) {
340
322
  if (Object.prototype.hasOwnProperty.call(t, "value") || Object.prototype.hasOwnProperty.call(t, "items"))
341
323
  return !0;
342
- if (Object.prototype.hasOwnProperty.call(t, T)) {
343
- const n = t[T];
344
- if (d(n) && n.required === !0)
324
+ if (Object.prototype.hasOwnProperty.call(t, E)) {
325
+ const n = t[E];
326
+ if (y(n) && n.required === !0)
345
327
  return !0;
346
328
  }
347
329
  for (const [n, r] of Object.entries(t))
348
- n !== T && d(r) && s.push(r);
330
+ n !== E && y(r) && s.push(r);
349
331
  }
350
332
  }
351
333
  return !1;
352
334
  }
353
- function he(e, s, t) {
335
+ function de(e, s, t) {
354
336
  if (e.op !== "replace" || typeof e.path != "string")
355
337
  return !1;
356
- const n = F(e.path);
338
+ const n = j(e.path);
357
339
  if (n.length < 2)
358
340
  return !1;
359
341
  const r = n.at(-1), o = n.at(-2);
360
342
  if (!(r === "blueId" && o !== void 0 && (o === "type" || o === "itemType" || o === "keyType" || o === "valueType")))
361
343
  return !1;
362
- const i = be(s, 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;
363
- if (c && D.has(c) || a && D.has(a) || !c || !a)
344
+ const i = ye(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
+ if (c && _.has(c) || a && _.has(a) || !c || !a)
364
346
  return !1;
365
347
  const u = t.get(c), f = t.get(a);
366
348
  if (!u || !f)
@@ -370,7 +352,7 @@ function he(e, s, t) {
370
352
  return !0;
371
353
  return !1;
372
354
  }
373
- function be(e, s) {
355
+ function ye(e, s) {
374
356
  let t = e;
375
357
  for (const n of s)
376
358
  if (Array.isArray(t)) {
@@ -378,13 +360,13 @@ function be(e, s) {
378
360
  if (Number.isNaN(r) || r < 0 || r >= t.length)
379
361
  return;
380
362
  t = t[r];
381
- } else if (d(t))
363
+ } else if (y(t))
382
364
  t = t[n];
383
365
  else
384
366
  return;
385
367
  return t;
386
368
  }
387
- function we(e) {
369
+ function me(e) {
388
370
  const s = /* @__PURE__ */ new Map();
389
371
  if (!e)
390
372
  return s;
@@ -393,14 +375,14 @@ function we(e) {
393
375
  continue;
394
376
  const n = /* @__PURE__ */ new Map();
395
377
  for (const r of t.types || []) {
396
- const o = r.content, i = h(o) && typeof o.name == "string" ? o.name : void 0;
378
+ const o = r.content, i = v(o) && typeof o.name == "string" ? o.name : void 0;
397
379
  i && n.set(i, r);
398
380
  }
399
381
  s.set(t.name, n);
400
382
  }
401
383
  return s;
402
384
  }
403
- function Ie(e, s) {
385
+ function ge(e, s) {
404
386
  for (const [t, n] of s)
405
387
  for (const [r, o] of n) {
406
388
  const i = `${t}/${r}`;
@@ -410,11 +392,11 @@ function Ie(e, s) {
410
392
  );
411
393
  }
412
394
  }
413
- function Ee({
395
+ function he({
414
396
  discovered: e,
415
397
  previousTypes: s,
416
398
  aliasToBlueId: t,
417
- aliasToPreprocessed: n,
399
+ aliasToStorageContent: n,
418
400
  nextRepoVersionIndex: r
419
401
  }) {
420
402
  const o = /* @__PURE__ */ new Map(), i = ve(s, t);
@@ -427,7 +409,7 @@ function Ee({
427
409
  throw new Error(
428
410
  `Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`
429
411
  );
430
- const p = n.get(c) ?? a.content, y = a.status === l.Dev ? Te({ blueId: u, nextRepoVersionIndex: r, previousType: f }) : !f || f.status === l.Dev ? Ae({ blueId: u, nextRepoVersionIndex: r }) : Se({
412
+ const p = n.get(c) ?? a.content, d = a.status === l.Dev ? be({ blueId: u, nextRepoVersionIndex: r, previousType: f }) : !f || f.status === l.Dev ? we({ blueId: u, nextRepoVersionIndex: r }) : Ie({
431
413
  alias: c,
432
414
  blueId: u,
433
415
  nextRepoVersionIndex: r,
@@ -437,9 +419,9 @@ function Ee({
437
419
  typeName: a.typeName,
438
420
  blueIdAliases: i
439
421
  });
440
- y.content = p, y.status = a.status;
441
- const b = o.get(a.packageName) ?? [];
442
- b.push(y), o.set(a.packageName, b);
422
+ d.content = p, d.status = a.status;
423
+ const m = o.get(a.packageName) ?? [];
424
+ m.push(d), o.set(a.packageName, m);
443
425
  }
444
426
  return o;
445
427
  }
@@ -462,7 +444,7 @@ function ve(e, s) {
462
444
  n(o, r);
463
445
  return t;
464
446
  }
465
- function Te({
447
+ function be({
466
448
  blueId: e,
467
449
  nextRepoVersionIndex: s,
468
450
  previousType: t
@@ -471,7 +453,7 @@ function Te({
471
453
  return {
472
454
  status: l.Dev,
473
455
  content: {},
474
- versions: o && n?.versions ? B(n.versions) : [
456
+ versions: o && n?.versions ? T(n.versions) : [
475
457
  {
476
458
  repositoryVersionIndex: s,
477
459
  typeBlueId: e,
@@ -480,7 +462,7 @@ function Te({
480
462
  ]
481
463
  };
482
464
  }
483
- function Ae({
465
+ function we({
484
466
  blueId: e,
485
467
  nextRepoVersionIndex: s
486
468
  }) {
@@ -496,7 +478,7 @@ function Ae({
496
478
  ]
497
479
  };
498
480
  }
499
- function Se({
481
+ function Ie({
500
482
  alias: e,
501
483
  blueId: s,
502
484
  nextRepoVersionIndex: t,
@@ -506,19 +488,19 @@ function Se({
506
488
  typeName: i,
507
489
  blueIdAliases: c
508
490
  }) {
509
- if (!h(n.content))
491
+ if (!v(n.content))
510
492
  throw new Error(
511
493
  `Type ${e} has non-object content; cannot compute diff for stable versioning.`
512
494
  );
513
- const a = de(
495
+ const a = ue(
514
496
  n.content,
515
497
  r,
516
498
  o,
517
499
  i,
518
500
  c
519
501
  );
520
- if (a.status === m.Unchanged) {
521
- const u = B(n.versions || []), f = u.at(-1);
502
+ if (a.status === g.Unchanged) {
503
+ const u = T(n.versions || []), f = u.at(-1);
522
504
  if (f && f.typeBlueId !== s)
523
505
  throw new Error(
524
506
  `Type ${e} content is unchanged but BlueId differs from previous metadata.`
@@ -529,12 +511,12 @@ function Se({
529
511
  versions: u
530
512
  };
531
513
  }
532
- if (a.status === m.NonBreaking)
514
+ if (a.status === g.NonBreaking)
533
515
  return {
534
516
  status: l.Stable,
535
517
  content: {},
536
518
  versions: [
537
- ...B(n.versions || []),
519
+ ...T(n.versions || []),
538
520
  {
539
521
  repositoryVersionIndex: t,
540
522
  typeBlueId: s,
@@ -546,7 +528,7 @@ function Se({
546
528
  `Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`
547
529
  );
548
530
  }
549
- function Be(e) {
531
+ function Ee(e) {
550
532
  return Array.from(e.entries()).map(([s, t]) => ({
551
533
  name: s,
552
534
  types: t.map((n) => ({
@@ -555,43 +537,43 @@ function Be(e) {
555
537
  (r, o) => r.repositoryVersionIndex - o.repositoryVersionIndex
556
538
  )
557
539
  })).sort((n, r) => {
558
- const o = h(n.content) && typeof n.content.name == "string" ? n.content.name : "", i = h(r.content) && typeof r.content.name == "string" ? r.content.name : "";
540
+ 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
541
  return o.localeCompare(i);
560
542
  })
561
543
  })).sort((s, t) => s.name.localeCompare(t.name));
562
544
  }
563
- function Pe(e) {
564
- return C.INSTANCE.calculateSync(
545
+ function Ae(e) {
546
+ return U.INSTANCE.calculateSync(
565
547
  e
566
548
  );
567
549
  }
568
- function ke(e, s, t) {
550
+ function Be(e, s, t) {
569
551
  const n = s?.repositoryVersions.at(-1), r = !n || n !== t, o = s?.repositoryVersions ? [...s.repositoryVersions] : [];
570
552
  return r && o.push(t), { document: {
571
- name: R,
553
+ name: P,
572
554
  packages: e,
573
555
  repositoryVersions: o
574
556
  }, changed: r };
575
557
  }
576
- function Ne(e, s, t) {
558
+ function Te(e, s, t) {
577
559
  const n = {
578
- name: R,
560
+ name: P,
579
561
  repositoryVersions: s,
580
- packages: Re(e, t)
562
+ packages: Se(e, t)
581
563
  };
582
- q(n), z(n);
564
+ W(n), q(n);
583
565
  }
584
- function Re(e, s) {
566
+ function Se(e, s) {
585
567
  const t = {};
586
568
  for (const n of e) {
587
- const r = Oe(n.name, s), o = {}, i = {};
569
+ const r = ke(n.name, s), o = {}, i = {};
588
570
  for (const c of n.types) {
589
571
  const a = c.versions?.[c.versions.length - 1]?.typeBlueId;
590
572
  if (!a)
591
573
  throw new Error(
592
574
  `Type ${n.name} is missing a current BlueId in versions.`
593
575
  );
594
- const u = $e(c);
576
+ const u = Ne(c);
595
577
  o[a] = {
596
578
  status: c.status,
597
579
  name: u,
@@ -608,81 +590,81 @@ function Re(e, s) {
608
590
  }
609
591
  return t;
610
592
  }
611
- function Oe(e, s) {
593
+ function ke(e, s) {
612
594
  const t = {}, n = `${e}/`;
613
595
  return s.forEach((r, o) => {
614
596
  o.startsWith(n) && (t[o] = r);
615
597
  }), t;
616
598
  }
617
- function $e(e) {
618
- const s = h(e.content) && typeof e.content.name == "string" ? e.content.name : null;
599
+ function Ne(e) {
600
+ const s = v(e.content) && typeof e.content.name == "string" ? e.content.name : null;
619
601
  if (!s)
620
602
  throw new Error('Type content is missing required "name" field.');
621
603
  return s;
622
604
  }
623
- function _e(e) {
624
- if (!w.existsSync(e))
605
+ function Pe(e) {
606
+ if (!b.existsSync(e))
625
607
  return { previous: null };
626
- const s = w.readFileSync(e, "utf8"), t = j(s);
627
- if (!t || !d(t))
608
+ const s = b.readFileSync(e, "utf8"), t = O(s);
609
+ if (!t || !y(t))
628
610
  throw new Error("Existing BlueRepository.blue is not a valid object.");
629
611
  const n = t, r = n.packages, o = n.repositoryVersions, i = Array.isArray(r) && r.every(
630
- (p) => d(p) && typeof p.name == "string" && Array.isArray(p.types)
612
+ (p) => y(p) && typeof p.name == "string" && Array.isArray(p.types)
631
613
  ), c = Array.isArray(o) && o.every((p) => typeof p == "string");
632
614
  if (!i || !c)
633
615
  throw new Error(
634
616
  "Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }"
635
617
  );
636
618
  const a = r, u = o, f = {
637
- name: typeof n.name == "string" ? n.name : R,
619
+ name: typeof n.name == "string" ? n.name : P,
638
620
  packages: a,
639
621
  repositoryVersions: u
640
622
  };
641
623
  return { existingYaml: s, previous: f };
642
624
  }
643
- function Ve(e) {
644
- return H.dump(e, { lineWidth: -1 });
625
+ function Re(e) {
626
+ return z.dump(e, { lineWidth: -1 });
645
627
  }
646
- function Fe(e) {
647
- const s = _.resolve(e.repoRoot), t = _.resolve(e.blueRepositoryPath), { existingYaml: n, previous: r } = _e(t), o = Q(s), i = we(r);
648
- Ie(o, i);
649
- const c = te(o), a = ne(c);
650
- re(c, o);
651
- const { aliasToBlueId: u, aliasToPreprocessed: f } = se(
628
+ function De(e) {
629
+ const s = V.resolve(e.repoRoot), t = V.resolve(e.blueRepositoryPath), { existingYaml: n, previous: r } = Pe(t), o = K(s), i = me(r);
630
+ ge(o, i);
631
+ const c = ee(o), a = te(c);
632
+ ne(c, o);
633
+ const { aliasToBlueId: u, aliasToStorageContent: f } = re(
652
634
  a,
653
635
  o
654
- ), p = r ? r.repositoryVersions.length : 0, y = Ee({
636
+ ), p = r ? r.repositoryVersions.length : 0, d = he({
655
637
  discovered: o,
656
638
  previousTypes: i,
657
639
  aliasToBlueId: u,
658
- aliasToPreprocessed: f,
640
+ aliasToStorageContent: f,
659
641
  nextRepoVersionIndex: p
660
- }), b = Be(y), E = Pe(b), { document: I, changed: v } = ke(
661
- b,
642
+ }), m = Ee(d), h = Ae(m), { document: w, changed: I } = Be(
643
+ m,
662
644
  r,
663
- E
645
+ h
664
646
  );
665
- Ne(
666
- I.packages,
667
- I.repositoryVersions,
647
+ Te(
648
+ w.packages,
649
+ w.repositoryVersions,
668
650
  u
669
651
  );
670
- const $ = Ve(I);
671
- if (r && !v && n && n !== $)
652
+ const $ = Re(w);
653
+ if (r && !I && n && n !== $)
672
654
  throw new Error(
673
655
  "BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode."
674
656
  );
675
657
  return e.verbose && console.info(
676
- `[repository-generator] RepoBlueId: ${E} (${v ? "changed" : "unchanged"})`
658
+ `[repository-generator] RepoBlueId: ${h} (${I ? "changed" : "unchanged"})`
677
659
  ), {
678
- document: I,
679
- currentRepoBlueId: E,
660
+ document: w,
661
+ currentRepoBlueId: h,
680
662
  previousRepoBlueId: r?.repositoryVersions.at(-1),
681
- changed: v || !n,
663
+ changed: I || !n,
682
664
  yaml: $,
683
665
  existingYaml: n
684
666
  };
685
667
  }
686
668
  export {
687
- Fe as g
669
+ De as g
688
670
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./generateRepository-BwxSxjH3.js");exports.generateRepository=e.generateRepository;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./generateRepository-CNSvDkC2.js");exports.generateRepository=e.generateRepository;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as r } from "./generateRepository-C2IfsNUG.mjs";
1
+ import { g as r } from "./generateRepository-DBYEfJm2.mjs";
2
2
  export {
3
3
  r as generateRepository
4
4
  };
@@ -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
- aliasToPreprocessed: Map<Alias, JsonMap>;
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;AAIjE,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,mBAAmB,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAC1C,CAwBA;AAED,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;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAChB,qBAAqB,UAAQ,GAC5B,SAAS,CA2CX"}
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;AAIjE,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,CAuCA;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"}
@@ -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,CAIjE;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"}
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
- aliasToPreprocessed: Map<Alias, JsonMap>;
9
+ aliasToStorageContent: Map<Alias, JsonMap>;
10
10
  nextRepoVersionIndex: number;
11
11
  }
12
- export declare function buildPackages({ discovered, previousTypes, aliasToBlueId, aliasToPreprocessed, nextRepoVersionIndex, }: BuildPackagesArgs): Map<PackageName, BlueTypeMetadata[]>;
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,mBAAmB,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACzC,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,aAAa,CAAC,EAC5B,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,oBAAoB,GACrB,EAAE,iBAAiB,GAAG,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAC,CAkD1D"}
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.10.0",
3
+ "version": "4.0.0-rc.0",
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.0",
9
+ "@blue-labs/repository-contract": "4.0.0-rc.0",
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.0"
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;