@blue-labs/repository-generator 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/blue-repo-generator.js +1 -1
- package/dist/bin/blue-repo-generator.mjs +1 -1
- package/dist/generateRepository-BHDjJhJX.js +1 -0
- package/dist/{generateRepository-B7eem2l_.mjs → generateRepository-BmCNamuV.mjs} +184 -149
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/core/constants.d.ts +2 -0
- package/dist/lib/core/constants.d.ts.map +1 -1
- package/dist/lib/core/discovery.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/generateRepository-DUT9zf8k.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-BHDjJhJX.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();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const T=require("path"),S=require("fs"),g=require("@blue-labs/language"),B=require("@blue-labs/repository-contract"),W=require("fast-json-patch"),H=require("js-yaml");function K(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const D=K(T),V=new Set([...g.Properties.CORE_TYPES]),z=new Set([...g.Properties.BASIC_TYPES]),C=g.Properties.CORE_TYPE_NAME_TO_BLUE_ID_MAP,X=new Set(["name","description","type","itemType","keyType","valueType","value","items","blueId","blue","schema","mergePolicy","contracts"]),_="Blue Repository",h={Dev:"dev",Stable:"stable"},Z=new Set([".git",".github",".husky","node_modules",".nx",".vscode",".idea"]);function Q(e){const r=S.readdirSync(e,{withFileTypes:!0}),n=new Map;for(const t of r){if(!t.isDirectory()||Z.has(t.name))continue;const o=T.join(e,t.name),s=L(o);if(s.length!==0)for(const a of s){const c=a.endsWith(".dev.blue")?h.Dev:h.Stable,i=ee(a),f=te(i,a),u=`${t.name}/${f}`,l=n.get(u);if(l)throw l.status!==c?new Error(`Type ${u} has both stable and dev definitions (${l.filePath} and ${a}).`):new Error(`Type ${u} is defined multiple times (${l.filePath} and ${a}).`);const y=ne(i,a);n.set(u,{packageName:t.name,typeName:f,status:c,content:i,filePath:a,references:y})}}return n}function ee(e){const r=S.readFileSync(e,"utf8"),n=g.yamlBlueParse(r);if(!k(n))throw new Error(`Type file ${e} must contain a YAML object.`);return re(n),n}function te(e,r){if(!k(e)||typeof e.name!="string")throw new Error(`Type file ${r} is missing required "name" field.`);return e.name}function L(e){const r=S.readdirSync(e,{withFileTypes:!0}),n=[];for(const t of r){if(t.isDirectory()){n.push(...L(T.join(e,t.name)));continue}(t.name.endsWith(".blue")||t.name.endsWith(".dev.blue"))&&n.push(T.join(e,t.name))}return n}function ne(e,r){const n=new Set,t=o=>{if(Array.isArray(o)){o.forEach(a=>t(a));return}if(!k(o))return;const s=a=>{if(typeof a=="string"&&!V.has(a)){if(!a.includes("/"))throw new Error(`Invalid type reference "${a}" in ${r}. Use <Package>/<Type> for non-primitive references.`);n.add(a)}};s(o.type),s(o.itemType),s(o.keyType),s(o.valueType),Object.values(o).forEach(a=>t(a))};return t(e),n}function re(e){const r=n=>{if(Array.isArray(n)){n.forEach(t=>r(t));return}if(k(n)){if(typeof n.type=="string"&&z.has(n.type)){const t=Object.keys(n).find(o=>!X.has(o));if(t!==void 0)throw new Error(`"${t}" is not an allowed fields here`)}Object.entries(n).filter(([t])=>t!=="schema").forEach(([,t])=>r(t))}};r(e)}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function oe(e){const r=new Map;for(const[n,t]of e){const o=new Set;for(const s of t.references){if(!e.has(s))throw new Error(`Type ${n} references unknown alias ${s}. Ensure the target type exists.`);o.add(s)}r.set(n,o)}return r}function se(e){const r=[],n=new Map,t=new Map,o=[],s=new Set;let a=0;const c=i=>{n.set(i,a),t.set(i,a),a+=1,o.push(i),s.add(i);for(const u of e.get(i)??[]){if(!n.has(u)){c(u),t.set(i,Math.min(t.get(i)??0,t.get(u)??0));continue}s.has(u)&&t.set(i,Math.min(t.get(i)??0,n.get(u)??0))}if(t.get(i)!==n.get(i))return;const f=[];for(;o.length>0;){const u=o.pop();if(!u||(s.delete(u),f.push(u),u===i))break}r.push(f.sort((u,l)=>u.localeCompare(l)))};for(const i of e.keys())n.has(i)||c(i);return r}function ie(e){const r=se(e),n=new Map;r.forEach((c,i)=>{c.forEach(f=>n.set(f,i))});const t=new Map;r.forEach((c,i)=>t.set(i,new Set));for(const[c,i]of e){const f=n.get(c);if(f!==void 0)for(const u of i){const l=n.get(u);l!==void 0&&l!==f&&t.get(f)?.add(l)}}const o=[],s=new Set,a=c=>{if(!s.has(c)){s.add(c);for(const i of t.get(c)??[])a(i);o.push(c)}};for(const c of t.keys())a(c);return o.map(c=>r[c]??[])}function ae(e,r){const n=new Map,t=(o,s=new Set)=>{if(n.has(o))return n.get(o)??!1;if(s.has(o))return!1;s.add(o);const a=e.get(o)||new Set;for(const c of a){const i=r.get(c);if(i&&(i.status===h.Dev||t(c,s)))return s.delete(o),n.set(o,!0),!0}return s.delete(o),n.set(o,!1),!1};for(const[o,s]of r)if(s.status===h.Stable&&t(o))throw new Error(`Stable type ${o} depends on a dev type. Stable types may only depend on other stable types.`)}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function w(e){return I(e)?Object.getPrototypeOf(e)===Object.prototype:!1}function P(e){if(Array.isArray(e))return e.map(r=>P(r));if(w(e)){const r={};for(const[n,t]of Object.entries(e))r[n]=P(t);return r}return e}function $(e){return e.map(r=>({repositoryVersionIndex:r.repositoryVersionIndex,typeBlueId:r.typeBlueId,attributesAdded:[...r.attributesAdded]}))}const ce=/^\$\{([\s\S]*)\}$/;class ue{process(r,n){const t=n.getValue();if(j(t)){const o=n.clone();return o.setValue(t),o.setProperties(void 0),o.setItems(void 0),o.setType(void 0),o}return r}postProcess(r,n){const t=n.getValue();if(j(t)&&r.getValue()!==t){const o=r.clone();return o.setValue(t),o}return r}}function j(e){return typeof e!="string"||!ce.test(e)?!1:e.indexOf("${")===e.lastIndexOf("${")}function fe(){return new g.MergingProcessors.SequentialMergingProcessor([new g.MergingProcessors.ValuePropagator,new ue,new g.MergingProcessors.TypeAssigner,new g.MergingProcessors.ListProcessor,new g.MergingProcessors.DictionaryProcessor,new g.MergingProcessors.MetadataPropagator,new g.MergingProcessors.BasicTypesVerifier])}const q="00000000000000000000000000000000000000000000";function le(e,r,n,t){const o=new Map,s=new Map,a=new Map,c=new g.Blue,i=g.createNodeProvider(l=>pe(l)?[new g.BlueNode().setReferenceBlueId(l)]:de(a,l).map(y=>c.jsonValueToNode(y))),u={blue:new g.Blue({nodeProvider:i,mergingProcessor:fe()}),contentByBlueId:a};for(const l of e){if(me(l,n)){ge({component:l,discovered:r,previousTypes:t,aliasToBlueId:o,aliasToStorageContent:s,context:u});continue}const y=l[0];if(!y)continue;const m=r.get(y);m&&ye({alias:y,type:m,previousTypes:t,aliasToBlueId:o,aliasToStorageContent:s,context:u})}return{aliasToBlueId:o,aliasToStorageContent:s}}function de(e,r){const n=G(r);if(n===void 0)return[];const t=e.get(n.baseBlueId);if(t===void 0)return[];if(n.index===void 0)return Array.isArray(t)?t:[t];if(!Array.isArray(t))return n.index===0?[t]:[];const o=t[n.index];return o===void 0?[]:[o]}function G(e){const r=e.indexOf("#");if(r===-1)return{baseBlueId:e};const n=e.slice(0,r),t=e.slice(r+1),o=Number(t);if(!(!Number.isInteger(o)||o<0))return{baseBlueId:n,index:o}}function pe(e){return e===q||/^this#\d+$/.test(e)}function M(e,r,n=!1,t=!1){if(Array.isArray(e))return e.map(s=>M(s,r,n,t));if(!I(e))return e;const o={};for(const[s,a]of Object.entries(e)){const c=t||s===B.OBJECT_CONTRACTS;if((s==="type"||s==="itemType"||s==="keyType"||s==="valueType")&&typeof a=="string"&&!(n&&c)){if(V.has(a)){const i=C[a];if(!i)throw new Error(`Missing primitive BlueId for ${a}.`);o[s]={blueId:i}}else{const i=a,f=r(i);if(!f)throw new Error(`Missing BlueId for alias ${i}.`);o[s]={blueId:f}}continue}o[s]=M(a,r,n,c)}return o}function ye({alias:e,type:r,previousTypes:n,aliasToBlueId:t,aliasToStorageContent:o,context:s}){const{node:a,storageContent:c}=N(r,m=>t.get(m),s.blue),i=V.has(r.typeName),f=i?ve(r.typeName):s.blue.calculateBlueIdSync(a),u=Y(n,r,c),l=u?.blueId??f,y=u?.content??c;t.set(e,l),o.set(e,y),i||s.contentByBlueId.set(l,y),s.blue.registerBlueIds({[e]:l})}function ge({component:e,discovered:r,previousTypes:n,aliasToBlueId:t,aliasToStorageContent:o,context:s}){const a=new Set(e),c=new Map;e.forEach((d,p)=>c.set(d,p));const i=e.map(d=>{const p=R(r,d),{node:v}=N(p,b=>a.has(b)?q:t.get(b),s.blue);return{alias:d,preliminaryBlueId:s.blue.calculateBlueIdSync(v)}});be(i),i.sort(Ie);const f=new Map;i.forEach(({alias:d},p)=>{f.set(d,p)});const u=new Map;for(const d of e){const p=R(r,d),v=N(p,b=>{if(!a.has(b))return t.get(b);const x=f.get(b);if(x===void 0)throw new Error(`Failed to resolve cyclic reference ${b}.`);return`this#${x}`},s.blue);u.set(d,v)}const l=he(e,r,n,u);if(l){for(const d of e){const p=l.get(d);if(!p)throw new Error(`Failed to preserve cyclic BlueId for type ${d}.`);t.set(d,p.blueId),o.set(d,p.content),s.blue.registerBlueIds({[d]:p.blueId})}we(s.contentByBlueId,l);return}const y=i.map(({alias:d})=>{const p=u.get(d);if(!p)throw new Error(`Failed to build cyclic content for type ${d}.`);return p.node}),m=i.map(({alias:d})=>{const p=u.get(d);if(!p)throw new Error(`Failed to build cyclic content for type ${d}.`);return p.storageContent}),A=s.blue.calculateBlueIdSync(y);s.contentByBlueId.set(A,m),i.forEach(({alias:d},p)=>{const v=u.get(d);if(!v)throw new Error(`Failed to build cyclic content for type ${d}.`);const b=`${A}#${p}`;t.set(d,b),o.set(d,v.storageContent),s.blue.registerBlueIds({[d]:b})})}function me(e,r){if(e.length>1)return!0;const n=e[0];return n?r.get(n)?.has(n)??!1:!1}function N(e,r,n){const t=M(P(e.content),r),o=n.jsonValueToNode(t);return{node:o,storageContent:n.nodeToJson(o,"official")}}function R(e,r){const n=e.get(r);if(!n)throw new Error(`Unknown type alias ${r}.`);return n}function he(e,r,n,t){const o=new Map;for(const s of e){const a=R(r,s),c=t.get(s);if(!c)throw new Error(`Failed to build cyclic content for type ${s}.`);const i=Y(n,a,c.storageContent);if(!i)return null;o.set(s,i)}return o}function Y(e,r,n){const t=e.get(r.packageName)?.get(r.typeName),o=t?.versions?.at(-1)?.typeBlueId;return!o||!t||!w(t.content)||!O(t.content,n)?null:{blueId:o,content:P(t.content)}}function we(e,r){const n=new Map;for(const{blueId:t,content:o}of r.values()){const s=G(t);if(!s||s.index===void 0){e.set(t,o);continue}const a=n.get(s.baseBlueId)??[];a.push({index:s.index,content:o}),n.set(s.baseBlueId,a)}for(const[t,o]of n){const a=[...o].sort((c,i)=>c.index-i.index).map((c,i)=>{if(c.index!==i)throw new Error(`Cyclic repository content for ${t} is missing index ${i}.`);return c.content});e.set(t,a)}}function be(e){const r=new Map;for(const n of e){const t=r.get(n.preliminaryBlueId);if(t)throw new Error(`Direct cyclic type set has ambiguous canonical ordering: ${t} and ${n.alias} share preliminary BlueId '${n.preliminaryBlueId}'.`);r.set(n.preliminaryBlueId,n.alias)}}function Ie(e,r){return e.preliminaryBlueId<r.preliminaryBlueId?-1:e.preliminaryBlueId>r.preliminaryBlueId?1:0}function O(e,r){if(e===r)return!0;if(Array.isArray(e)||Array.isArray(r))return!Array.isArray(e)||!Array.isArray(r)||e.length!==r.length?!1:e.every((n,t)=>O(n,r[t]));if(w(e)||w(r)){if(!w(e)||!w(r))return!1;const n=Object.keys(e).sort(),t=Object.keys(r).sort();return n.length!==t.length?!1:n.every((o,s)=>o===t[s]&&O(e[o],r[o]))}return!1}function ve(e){const r=C[e];if(!r)throw new Error(`Missing primitive BlueId for ${e}.`);return r}const U=new Set(Object.values(C)),Be=new Set(["type","itemType","valueType","keyType"]),Ee=new Set(["name","description"]),E={Unchanged:"unchanged",NonBreaking:"non-breaking",Breaking:"breaking"};function Ae(e,r,n,t,o){const s=W.compare(e,r);if(s.length===0)return{status:E.Unchanged,attributesAdded:[]};const a=[];let c=!1;for(const i of s){if(ke(i,e,o)){c=!0;continue}if(i.op!=="add")return{status:E.Breaking,attributesAdded:[]};if(!Te(i))return{status:E.Breaking,attributesAdded:[]};a.push(i.path)}return a.length===0&&!c?{status:E.Breaking,attributesAdded:[]}:(a.length>0&&Se(a,n,t),{status:E.NonBreaking,attributesAdded:a})}function Se(e,r,n){for(const t of e)try{B.validateAttributesAddedPointer(t)}catch(o){throw new Error(`Invalid attribute pointer "${t}" for ${r}/${n}: ${o.message}`)}}function Te(e){if(e.op!=="add")return!1;const r=J(e.path);if(r.length===0)return!1;const n=r.at(-1);return n&&/^\d+$/.test(n)||n&&Be.has(n)||r.some(t=>B.RESERVED_ATTRIBUTES_POINTER_SEGMENTS.has(t))?!1:I(e.value)?!Pe(e.value):n?Ee.has(n):!1}function J(e){try{return B.parsePointer(e)}catch{return[]}}function Pe(e){const r=[e];for(;r.length;){const n=r.pop();if(n){if(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"items"))return!0;if(Object.prototype.hasOwnProperty.call(n,B.OBJECT_SCHEMA)){const t=n[B.OBJECT_SCHEMA];if(I(t)&&t.required===!0)return!0}for(const[t,o]of Object.entries(n))t!==B.OBJECT_SCHEMA&&I(o)&&r.push(o)}}return!1}function ke(e,r,n){if(e.op!=="replace"||typeof e.path!="string")return!1;const t=J(e.path);if(t.length<2)return!1;const o=t.at(-1),s=t.at(-2);if(!(o==="blueId"&&s!==void 0&&(s==="type"||s==="itemType"||s==="keyType"||s==="valueType")))return!1;const a=$e(r,t),c=typeof a=="string"?a:I(a)&&typeof a.blueId=="string"?a.blueId:null,i=typeof e.value=="string"?e.value:I(e.value)&&typeof e.value.blueId=="string"?e.value.blueId:null;if(c&&U.has(c)||i&&U.has(i)||!c||!i)return!1;const f=n.get(c),u=n.get(i);if(!f||!u)return!1;for(const l of f)if(u.has(l))return!0;return!1}function $e(e,r){let n=e;for(const t of r)if(Array.isArray(n)){const o=Number(t);if(Number.isNaN(o)||o<0||o>=n.length)return;n=n[o]}else if(I(n))n=n[t];else return;return n}function Me(e){const r=new Map;if(!e)return r;for(const n of e.packages||[]){if(typeof n.name!="string")continue;const t=new Map;for(const o of n.types||[]){const s=o.content,a=w(s)&&typeof s.name=="string"?s.name:void 0;a&&t.set(a,o)}r.set(n.name,t)}return r}function Ne(e,r){for(const[n,t]of r)for(const[o,s]of t){const a=`${n}/${o}`;if(!e.has(a)&&s.status===h.Stable)throw new Error(`Stable type ${a} was removed. Breaking changes require a new logical type name.`)}}function Re({discovered:e,previousTypes:r,aliasToBlueId:n,aliasToStorageContent:t,nextRepoVersionIndex:o}){const s=new Map,a=Oe(r,n);for(const[c,i]of e){const f=n.get(c);if(!f)throw new Error(`Failed to compute BlueId for type ${c}.`);const u=r.get(i.packageName)?.get(i.typeName)??null;if(u&&u.status===h.Stable&&i.status===h.Dev)throw new Error(`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`);const l=t.get(c)??i.content,y=i.status===h.Dev?Ve({blueId:f,nextRepoVersionIndex:o,previousType:u}):!u||u.status===h.Dev?Ce({blueId:f,nextRepoVersionIndex:o}):_e({alias:c,blueId:f,nextRepoVersionIndex:o,previousType:u,currentContent:l,packageName:i.packageName,typeName:i.typeName,blueIdAliases:a});y.content=l,y.status=i.status;const m=s.get(i.packageName)??[];m.push(y),s.set(i.packageName,m)}return s}function Oe(e,r){const n=new Map,t=(o,s)=>{const a=n.get(o);if(a){a.add(s);return}n.set(o,new Set([s]))};for(const[o,s]of e)for(const[a,c]of s){const i=`${o}/${a}`;for(const f of c.versions??[])typeof f.typeBlueId=="string"&&t(f.typeBlueId,i)}for(const[o,s]of r)t(s,o);return n}function Ve({blueId:e,nextRepoVersionIndex:r,previousType:n}){const t=n&&n.status===h.Dev?n:null,o=t?.versions?.length===1?t.versions[0]:null,s=o&&o.typeBlueId===e;return{status:h.Dev,content:{},versions:s&&t?.versions?$(t.versions):[{repositoryVersionIndex:r,typeBlueId:e,attributesAdded:[]}]}}function Ce({blueId:e,nextRepoVersionIndex:r}){return{status:h.Stable,content:{},versions:[{repositoryVersionIndex:r,typeBlueId:e,attributesAdded:[]}]}}function _e({alias:e,blueId:r,nextRepoVersionIndex:n,previousType:t,currentContent:o,packageName:s,typeName:a,blueIdAliases:c}){if(!w(t.content))throw new Error(`Type ${e} has non-object content; cannot compute diff for stable versioning.`);const i=Ae(t.content,o,s,a,c);if(i.status===E.Unchanged){const f=$(t.versions||[]),u=f.at(-1);if(u&&u.typeBlueId!==r)throw new Error(`Type ${e} content is unchanged but BlueId differs from previous metadata.`);return{status:h.Stable,content:{},versions:f}}if(i.status===E.NonBreaking)return{status:h.Stable,content:{},versions:[...$(t.versions||[]),{repositoryVersionIndex:n,typeBlueId:r,attributesAdded:i.attributesAdded}]};throw new Error(`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`)}function xe(e){return Array.from(e.entries()).map(([r,n])=>({name:r,types:n.map(t=>({...t,versions:[...t.versions].sort((o,s)=>o.repositoryVersionIndex-s.repositoryVersionIndex)})).sort((t,o)=>{const s=w(t.content)&&typeof t.content.name=="string"?t.content.name:"",a=w(o.content)&&typeof o.content.name=="string"?o.content.name:"";return s.localeCompare(a)})})).sort((r,n)=>r.name.localeCompare(n.name))}function F(e){return g.BlueIdCalculator.INSTANCE.calculateSync(e)}function De(e,r,n){const t=r?.repositoryVersions.at(-1),o=!t||t!==n,s=r?.repositoryVersions?[...r.repositoryVersions]:[];return o&&s.push(n),{document:{name:_,packages:e,repositoryVersions:s},changed:o}}function je(e,r,n){const t={name:_,repositoryVersions:r,packages:Ue(e,n)};B.validateStableDoesNotDependOnDev(t)}function Ue(e,r){const n={};for(const t of e){const o=Fe(t.name,r),s={},a={};for(const c of t.types){const i=c.versions?.[c.versions.length-1]?.typeBlueId;if(!i)throw new Error(`Type ${t.name} is missing a current BlueId in versions.`);const f=Le(c);s[i]={status:c.status,name:f,versions:c.versions??[]},a[i]=c.content}n[t.name]={name:t.name,aliases:o,typesMeta:s,contents:a,schemas:{}}}return n}function Fe(e,r){const n={},t=`${e}/`;return r.forEach((o,s)=>{s.startsWith(t)&&(n[s]=o)}),n}function Le(e){const r=w(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 qe(e){if(!S.existsSync(e))return{previous:null};const r=S.readFileSync(e,"utf8"),n=g.yamlBlueParse(r);if(!n||!I(n))throw new Error("Existing BlueRepository.blue is not a valid object.");const t=n,o=t.packages,s=t.repositoryVersions,a=Array.isArray(o)&&o.every(l=>I(l)&&typeof l.name=="string"&&Array.isArray(l.types)),c=Array.isArray(s)&&s.every(l=>typeof l=="string");if(!a||!c)throw new Error("Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }");const i=o,f=s,u={name:typeof t.name=="string"?t.name:_,packages:i,repositoryVersions:f};return{existingYaml:r,previous:u}}function Ge(e){return H.dump(e,{lineWidth:-1})}function Ye(e){const r=D.resolve(e.repoRoot),n=D.resolve(e.blueRepositoryPath),{existingYaml:t,previous:o}=qe(n),s=Q(r),a=Me(o);Ne(s,a);const c=oe(s),i=ie(c);ae(c,s);const{aliasToBlueId:f,aliasToStorageContent:u}=le(i,s,c,a),l=o?o.repositoryVersions.length:0,y=Re({discovered:s,previousTypes:a,aliasToBlueId:f,aliasToStorageContent:u,nextRepoVersionIndex:l}),m=xe(y),A=o&&Je(o.packages,m)?o.repositoryVersions.at(-1)??F(m):F(m),{document:d,changed:p}=De(m,o,A);je(d.packages,d.repositoryVersions,f);const v=Ge(d);if(o&&!p&&t&&t!==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: ${A} (${p?"changed":"unchanged"})`),{document:d,currentRepoBlueId:A,previousRepoBlueId:o?.repositoryVersions.at(-1),changed:p||!t,yaml:v,existingYaml:t}}function Je(e,r){return JSON.stringify(e)===JSON.stringify(r)}exports.generateRepository=Ye;
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as j from "path";
|
|
2
2
|
import k from "path";
|
|
3
3
|
import A from "fs";
|
|
4
|
-
import { Properties as
|
|
5
|
-
import { OBJECT_CONTRACTS as Q, RESERVED_ATTRIBUTES_POINTER_SEGMENTS as ee, validateAttributesAddedPointer as te, parsePointer as ne, OBJECT_SCHEMA as
|
|
4
|
+
import { Properties as _, yamlBlueParse as Y, MergingProcessors as v, Blue as U, createNodeProvider as H, BlueNode as X, BlueIdCalculator as Z } from "@blue-labs/language";
|
|
5
|
+
import { OBJECT_CONTRACTS as Q, RESERVED_ATTRIBUTES_POINTER_SEGMENTS as ee, validateAttributesAddedPointer as te, parsePointer as ne, OBJECT_SCHEMA as P, validateStableDoesNotDependOnDev as re } from "@blue-labs/repository-contract";
|
|
6
6
|
import oe from "fast-json-patch";
|
|
7
7
|
import se from "js-yaml";
|
|
8
|
-
const
|
|
8
|
+
const O = /* @__PURE__ */ new Set([..._.CORE_TYPES]), ie = /* @__PURE__ */ new Set([
|
|
9
|
+
..._.BASIC_TYPES
|
|
10
|
+
]), x = _.CORE_TYPE_NAME_TO_BLUE_ID_MAP, ae = /* @__PURE__ */ new Set([
|
|
11
|
+
"name",
|
|
12
|
+
"description",
|
|
13
|
+
"type",
|
|
14
|
+
"itemType",
|
|
15
|
+
"keyType",
|
|
16
|
+
"valueType",
|
|
17
|
+
"value",
|
|
18
|
+
"items",
|
|
19
|
+
"blueId",
|
|
20
|
+
"blue",
|
|
21
|
+
"schema",
|
|
22
|
+
"mergePolicy",
|
|
23
|
+
"contracts"
|
|
24
|
+
]), C = "Blue Repository", m = {
|
|
9
25
|
Dev: "dev",
|
|
10
26
|
Stable: "stable"
|
|
11
|
-
},
|
|
27
|
+
}, ce = /* @__PURE__ */ new Set([
|
|
12
28
|
".git",
|
|
13
29
|
".github",
|
|
14
30
|
".husky",
|
|
@@ -17,22 +33,22 @@ const V = /* @__PURE__ */ new Set([...G.CORE_TYPES]), x = G.CORE_TYPE_NAME_TO_BL
|
|
|
17
33
|
".vscode",
|
|
18
34
|
".idea"
|
|
19
35
|
]);
|
|
20
|
-
function
|
|
36
|
+
function ue(e) {
|
|
21
37
|
const r = A.readdirSync(e, { withFileTypes: !0 }), n = /* @__PURE__ */ new Map();
|
|
22
38
|
for (const t of r) {
|
|
23
|
-
if (!t.isDirectory() ||
|
|
39
|
+
if (!t.isDirectory() || ce.has(t.name))
|
|
24
40
|
continue;
|
|
25
|
-
const o = k.join(e, t.name), s =
|
|
41
|
+
const o = k.join(e, t.name), s = q(o);
|
|
26
42
|
if (s.length !== 0)
|
|
27
43
|
for (const a of s) {
|
|
28
|
-
const c = a.endsWith(".dev.blue") ? m.Dev : m.Stable, i =
|
|
44
|
+
const c = a.endsWith(".dev.blue") ? m.Dev : m.Stable, i = fe(a), f = le(i, a), u = `${t.name}/${f}`, l = n.get(u);
|
|
29
45
|
if (l)
|
|
30
46
|
throw l.status !== c ? new Error(
|
|
31
47
|
`Type ${u} has both stable and dev definitions (${l.filePath} and ${a}).`
|
|
32
48
|
) : new Error(
|
|
33
49
|
`Type ${u} is defined multiple times (${l.filePath} and ${a}).`
|
|
34
50
|
);
|
|
35
|
-
const y =
|
|
51
|
+
const y = de(i, a);
|
|
36
52
|
n.set(u, {
|
|
37
53
|
packageName: t.name,
|
|
38
54
|
typeName: f,
|
|
@@ -45,38 +61,38 @@ function ae(e) {
|
|
|
45
61
|
}
|
|
46
62
|
return n;
|
|
47
63
|
}
|
|
48
|
-
function
|
|
49
|
-
const r = A.readFileSync(e, "utf8"), n =
|
|
50
|
-
if (!
|
|
64
|
+
function fe(e) {
|
|
65
|
+
const r = A.readFileSync(e, "utf8"), n = Y(r);
|
|
66
|
+
if (!T(n))
|
|
51
67
|
throw new Error(`Type file ${e} must contain a YAML object.`);
|
|
52
|
-
return n;
|
|
68
|
+
return pe(n), n;
|
|
53
69
|
}
|
|
54
|
-
function
|
|
55
|
-
if (!
|
|
70
|
+
function le(e, r) {
|
|
71
|
+
if (!T(e) || typeof e.name != "string")
|
|
56
72
|
throw new Error(`Type file ${r} is missing required "name" field.`);
|
|
57
73
|
return e.name;
|
|
58
74
|
}
|
|
59
|
-
function
|
|
75
|
+
function q(e) {
|
|
60
76
|
const r = A.readdirSync(e, { withFileTypes: !0 }), n = [];
|
|
61
77
|
for (const t of r) {
|
|
62
78
|
if (t.isDirectory()) {
|
|
63
|
-
n.push(...
|
|
79
|
+
n.push(...q(k.join(e, t.name)));
|
|
64
80
|
continue;
|
|
65
81
|
}
|
|
66
82
|
(t.name.endsWith(".blue") || t.name.endsWith(".dev.blue")) && n.push(k.join(e, t.name));
|
|
67
83
|
}
|
|
68
84
|
return n;
|
|
69
85
|
}
|
|
70
|
-
function
|
|
86
|
+
function de(e, r) {
|
|
71
87
|
const n = /* @__PURE__ */ new Set(), t = (o) => {
|
|
72
88
|
if (Array.isArray(o)) {
|
|
73
89
|
o.forEach((a) => t(a));
|
|
74
90
|
return;
|
|
75
91
|
}
|
|
76
|
-
if (!
|
|
92
|
+
if (!T(o))
|
|
77
93
|
return;
|
|
78
94
|
const s = (a) => {
|
|
79
|
-
if (typeof a == "string" && !
|
|
95
|
+
if (typeof a == "string" && !O.has(a)) {
|
|
80
96
|
if (!a.includes("/"))
|
|
81
97
|
throw new Error(
|
|
82
98
|
`Invalid type reference "${a}" in ${r}. Use <Package>/<Type> for non-primitive references.`
|
|
@@ -88,10 +104,29 @@ function fe(e, r) {
|
|
|
88
104
|
};
|
|
89
105
|
return t(e), n;
|
|
90
106
|
}
|
|
91
|
-
function
|
|
107
|
+
function pe(e) {
|
|
108
|
+
const r = (n) => {
|
|
109
|
+
if (Array.isArray(n)) {
|
|
110
|
+
n.forEach((t) => r(t));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (T(n)) {
|
|
114
|
+
if (typeof n.type == "string" && ie.has(n.type)) {
|
|
115
|
+
const t = Object.keys(n).find(
|
|
116
|
+
(o) => !ae.has(o)
|
|
117
|
+
);
|
|
118
|
+
if (t !== void 0)
|
|
119
|
+
throw new Error(`"${t}" is not an allowed fields here`);
|
|
120
|
+
}
|
|
121
|
+
Object.entries(n).filter(([t]) => t !== "schema").forEach(([, t]) => r(t));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
r(e);
|
|
125
|
+
}
|
|
126
|
+
function T(e) {
|
|
92
127
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
93
128
|
}
|
|
94
|
-
function
|
|
129
|
+
function ye(e) {
|
|
95
130
|
const r = /* @__PURE__ */ new Map();
|
|
96
131
|
for (const [n, t] of e) {
|
|
97
132
|
const o = /* @__PURE__ */ new Set();
|
|
@@ -106,7 +141,7 @@ function le(e) {
|
|
|
106
141
|
}
|
|
107
142
|
return r;
|
|
108
143
|
}
|
|
109
|
-
function
|
|
144
|
+
function ge(e) {
|
|
110
145
|
const r = [], n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), o = [], s = /* @__PURE__ */ new Set();
|
|
111
146
|
let a = 0;
|
|
112
147
|
const c = (i) => {
|
|
@@ -141,8 +176,8 @@ function de(e) {
|
|
|
141
176
|
n.has(i) || c(i);
|
|
142
177
|
return r;
|
|
143
178
|
}
|
|
144
|
-
function
|
|
145
|
-
const r =
|
|
179
|
+
function me(e) {
|
|
180
|
+
const r = ge(e), n = /* @__PURE__ */ new Map();
|
|
146
181
|
r.forEach((c, i) => {
|
|
147
182
|
c.forEach((f) => n.set(f, i));
|
|
148
183
|
});
|
|
@@ -170,7 +205,7 @@ function pe(e) {
|
|
|
170
205
|
a(c);
|
|
171
206
|
return o.map((c) => r[c] ?? []);
|
|
172
207
|
}
|
|
173
|
-
function
|
|
208
|
+
function he(e, r) {
|
|
174
209
|
const n = /* @__PURE__ */ new Map(), t = (o, s = /* @__PURE__ */ new Set()) => {
|
|
175
210
|
if (n.has(o))
|
|
176
211
|
return n.get(o) ?? !1;
|
|
@@ -208,18 +243,18 @@ function S(e) {
|
|
|
208
243
|
}
|
|
209
244
|
return e;
|
|
210
245
|
}
|
|
211
|
-
function
|
|
246
|
+
function $(e) {
|
|
212
247
|
return e.map((r) => ({
|
|
213
248
|
repositoryVersionIndex: r.repositoryVersionIndex,
|
|
214
249
|
typeBlueId: r.typeBlueId,
|
|
215
250
|
attributesAdded: [...r.attributesAdded]
|
|
216
251
|
}));
|
|
217
252
|
}
|
|
218
|
-
const
|
|
219
|
-
class
|
|
253
|
+
const we = /^\$\{([\s\S]*)\}$/;
|
|
254
|
+
class Ie {
|
|
220
255
|
process(r, n) {
|
|
221
256
|
const t = n.getValue();
|
|
222
|
-
if (
|
|
257
|
+
if (F(t)) {
|
|
223
258
|
const o = n.clone();
|
|
224
259
|
return o.setValue(t), o.setProperties(void 0), o.setItems(void 0), o.setType(void 0), o;
|
|
225
260
|
}
|
|
@@ -227,38 +262,38 @@ class me {
|
|
|
227
262
|
}
|
|
228
263
|
postProcess(r, n) {
|
|
229
264
|
const t = n.getValue();
|
|
230
|
-
if (
|
|
265
|
+
if (F(t) && r.getValue() !== t) {
|
|
231
266
|
const o = r.clone();
|
|
232
267
|
return o.setValue(t), o;
|
|
233
268
|
}
|
|
234
269
|
return r;
|
|
235
270
|
}
|
|
236
271
|
}
|
|
237
|
-
function
|
|
238
|
-
return typeof e != "string" || !
|
|
239
|
-
}
|
|
240
|
-
function
|
|
241
|
-
return new
|
|
242
|
-
new
|
|
243
|
-
new
|
|
244
|
-
new
|
|
245
|
-
new
|
|
246
|
-
new
|
|
247
|
-
new
|
|
248
|
-
new
|
|
272
|
+
function F(e) {
|
|
273
|
+
return typeof e != "string" || !we.test(e) ? !1 : e.indexOf("${") === e.lastIndexOf("${");
|
|
274
|
+
}
|
|
275
|
+
function be() {
|
|
276
|
+
return new v.SequentialMergingProcessor([
|
|
277
|
+
new v.ValuePropagator(),
|
|
278
|
+
new Ie(),
|
|
279
|
+
new v.TypeAssigner(),
|
|
280
|
+
new v.ListProcessor(),
|
|
281
|
+
new v.DictionaryProcessor(),
|
|
282
|
+
new v.MetadataPropagator(),
|
|
283
|
+
new v.BasicTypesVerifier()
|
|
249
284
|
]);
|
|
250
285
|
}
|
|
251
|
-
const
|
|
252
|
-
function
|
|
253
|
-
const o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = new
|
|
286
|
+
const W = "00000000000000000000000000000000000000000000";
|
|
287
|
+
function ve(e, r, n, t) {
|
|
288
|
+
const o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), c = new U(), i = H((l) => Ee(l) ? [new X().setReferenceBlueId(l)] : Be(a, l).map(
|
|
254
289
|
(y) => c.jsonValueToNode(y)
|
|
255
|
-
)), u = { blue: new
|
|
290
|
+
)), u = { blue: new U({
|
|
256
291
|
nodeProvider: i,
|
|
257
|
-
mergingProcessor:
|
|
292
|
+
mergingProcessor: be()
|
|
258
293
|
}), contentByBlueId: a };
|
|
259
294
|
for (const l of e) {
|
|
260
|
-
if (
|
|
261
|
-
|
|
295
|
+
if (Te(l, n)) {
|
|
296
|
+
Se({
|
|
262
297
|
component: l,
|
|
263
298
|
discovered: r,
|
|
264
299
|
previousTypes: t,
|
|
@@ -272,7 +307,7 @@ function we(e, r, n, t) {
|
|
|
272
307
|
if (!y)
|
|
273
308
|
continue;
|
|
274
309
|
const g = r.get(y);
|
|
275
|
-
g &&
|
|
310
|
+
g && Ae({
|
|
276
311
|
alias: y,
|
|
277
312
|
type: g,
|
|
278
313
|
previousTypes: t,
|
|
@@ -283,7 +318,7 @@ function we(e, r, n, t) {
|
|
|
283
318
|
}
|
|
284
319
|
return { aliasToBlueId: o, aliasToStorageContent: s };
|
|
285
320
|
}
|
|
286
|
-
function
|
|
321
|
+
function Be(e, r) {
|
|
287
322
|
const n = J(r);
|
|
288
323
|
if (n === void 0)
|
|
289
324
|
return [];
|
|
@@ -305,13 +340,13 @@ function J(e) {
|
|
|
305
340
|
if (!(!Number.isInteger(o) || o < 0))
|
|
306
341
|
return { baseBlueId: n, index: o };
|
|
307
342
|
}
|
|
308
|
-
function
|
|
309
|
-
return e ===
|
|
343
|
+
function Ee(e) {
|
|
344
|
+
return e === W || /^this#\d+$/.test(e);
|
|
310
345
|
}
|
|
311
|
-
function
|
|
346
|
+
function N(e, r, n = !1, t = !1) {
|
|
312
347
|
if (Array.isArray(e))
|
|
313
348
|
return e.map(
|
|
314
|
-
(s) =>
|
|
349
|
+
(s) => N(
|
|
315
350
|
s,
|
|
316
351
|
r,
|
|
317
352
|
n,
|
|
@@ -324,7 +359,7 @@ function $(e, r, n = !1, t = !1) {
|
|
|
324
359
|
for (const [s, a] of Object.entries(e)) {
|
|
325
360
|
const c = t || s === Q;
|
|
326
361
|
if ((s === "type" || s === "itemType" || s === "keyType" || s === "valueType") && typeof a == "string" && !(n && c)) {
|
|
327
|
-
if (
|
|
362
|
+
if (O.has(a)) {
|
|
328
363
|
const i = x[a];
|
|
329
364
|
if (!i)
|
|
330
365
|
throw new Error(`Missing primitive BlueId for ${a}.`);
|
|
@@ -337,7 +372,7 @@ function $(e, r, n = !1, t = !1) {
|
|
|
337
372
|
}
|
|
338
373
|
continue;
|
|
339
374
|
}
|
|
340
|
-
o[s] =
|
|
375
|
+
o[s] = N(
|
|
341
376
|
a,
|
|
342
377
|
r,
|
|
343
378
|
n,
|
|
@@ -346,7 +381,7 @@ function $(e, r, n = !1, t = !1) {
|
|
|
346
381
|
}
|
|
347
382
|
return o;
|
|
348
383
|
}
|
|
349
|
-
function
|
|
384
|
+
function Ae({
|
|
350
385
|
alias: e,
|
|
351
386
|
type: r,
|
|
352
387
|
previousTypes: n,
|
|
@@ -354,18 +389,18 @@ function Be({
|
|
|
354
389
|
aliasToStorageContent: o,
|
|
355
390
|
context: s
|
|
356
391
|
}) {
|
|
357
|
-
const { node: a, storageContent: c } =
|
|
392
|
+
const { node: a, storageContent: c } = R(
|
|
358
393
|
r,
|
|
359
394
|
(g) => t.get(g),
|
|
360
395
|
s.blue
|
|
361
|
-
), i =
|
|
396
|
+
), i = O.has(r.typeName), f = i ? Re(r.typeName) : s.blue.calculateBlueIdSync(a), u = K(
|
|
362
397
|
n,
|
|
363
398
|
r,
|
|
364
399
|
c
|
|
365
400
|
), l = u?.blueId ?? f, y = u?.content ?? c;
|
|
366
401
|
t.set(e, l), o.set(e, y), i || s.contentByBlueId.set(l, y), s.blue.registerBlueIds({ [e]: l });
|
|
367
402
|
}
|
|
368
|
-
function
|
|
403
|
+
function Se({
|
|
369
404
|
component: e,
|
|
370
405
|
discovered: r,
|
|
371
406
|
previousTypes: n,
|
|
@@ -376,9 +411,9 @@ function ve({
|
|
|
376
411
|
const a = new Set(e), c = /* @__PURE__ */ new Map();
|
|
377
412
|
e.forEach((d, p) => c.set(d, p));
|
|
378
413
|
const i = e.map((d) => {
|
|
379
|
-
const p = M(r, d), { node: b } =
|
|
414
|
+
const p = M(r, d), { node: b } = R(
|
|
380
415
|
p,
|
|
381
|
-
(w) => a.has(w) ?
|
|
416
|
+
(w) => a.has(w) ? W : t.get(w),
|
|
382
417
|
s.blue
|
|
383
418
|
);
|
|
384
419
|
return {
|
|
@@ -386,28 +421,28 @@ function ve({
|
|
|
386
421
|
preliminaryBlueId: s.blue.calculateBlueIdSync(b)
|
|
387
422
|
};
|
|
388
423
|
});
|
|
389
|
-
|
|
424
|
+
$e(i), i.sort(Ne);
|
|
390
425
|
const f = /* @__PURE__ */ new Map();
|
|
391
426
|
i.forEach(({ alias: d }, p) => {
|
|
392
427
|
f.set(d, p);
|
|
393
428
|
});
|
|
394
429
|
const u = /* @__PURE__ */ new Map();
|
|
395
430
|
for (const d of e) {
|
|
396
|
-
const p = M(r, d), b =
|
|
431
|
+
const p = M(r, d), b = R(
|
|
397
432
|
p,
|
|
398
433
|
(w) => {
|
|
399
434
|
if (!a.has(w))
|
|
400
435
|
return t.get(w);
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
436
|
+
const D = f.get(w);
|
|
437
|
+
if (D === void 0)
|
|
403
438
|
throw new Error(`Failed to resolve cyclic reference ${w}.`);
|
|
404
|
-
return `this#${
|
|
439
|
+
return `this#${D}`;
|
|
405
440
|
},
|
|
406
441
|
s.blue
|
|
407
442
|
);
|
|
408
443
|
u.set(d, b);
|
|
409
444
|
}
|
|
410
|
-
const l =
|
|
445
|
+
const l = Pe(
|
|
411
446
|
e,
|
|
412
447
|
r,
|
|
413
448
|
n,
|
|
@@ -420,7 +455,7 @@ function ve({
|
|
|
420
455
|
throw new Error(`Failed to preserve cyclic BlueId for type ${d}.`);
|
|
421
456
|
t.set(d, p.blueId), o.set(d, p.content), s.blue.registerBlueIds({ [d]: p.blueId });
|
|
422
457
|
}
|
|
423
|
-
|
|
458
|
+
ke(s.contentByBlueId, l);
|
|
424
459
|
return;
|
|
425
460
|
}
|
|
426
461
|
const y = i.map(({ alias: d }) => {
|
|
@@ -442,14 +477,14 @@ function ve({
|
|
|
442
477
|
t.set(d, w), o.set(d, b.storageContent), s.blue.registerBlueIds({ [d]: w });
|
|
443
478
|
});
|
|
444
479
|
}
|
|
445
|
-
function
|
|
480
|
+
function Te(e, r) {
|
|
446
481
|
if (e.length > 1)
|
|
447
482
|
return !0;
|
|
448
483
|
const n = e[0];
|
|
449
484
|
return n ? r.get(n)?.has(n) ?? !1 : !1;
|
|
450
485
|
}
|
|
451
|
-
function
|
|
452
|
-
const t =
|
|
486
|
+
function R(e, r, n) {
|
|
487
|
+
const t = N(
|
|
453
488
|
S(e.content),
|
|
454
489
|
r
|
|
455
490
|
), o = n.jsonValueToNode(t);
|
|
@@ -464,7 +499,7 @@ function M(e, r) {
|
|
|
464
499
|
throw new Error(`Unknown type alias ${r}.`);
|
|
465
500
|
return n;
|
|
466
501
|
}
|
|
467
|
-
function
|
|
502
|
+
function Pe(e, r, n, t) {
|
|
468
503
|
const o = /* @__PURE__ */ new Map();
|
|
469
504
|
for (const s of e) {
|
|
470
505
|
const a = M(r, s), c = t.get(s);
|
|
@@ -483,12 +518,12 @@ function Ae(e, r, n, t) {
|
|
|
483
518
|
}
|
|
484
519
|
function K(e, r, n) {
|
|
485
520
|
const t = e.get(r.packageName)?.get(r.typeName), o = t?.versions?.at(-1)?.typeBlueId;
|
|
486
|
-
return !o || !t || !h(t.content) || !
|
|
521
|
+
return !o || !t || !h(t.content) || !V(t.content, n) ? null : {
|
|
487
522
|
blueId: o,
|
|
488
523
|
content: S(t.content)
|
|
489
524
|
};
|
|
490
525
|
}
|
|
491
|
-
function
|
|
526
|
+
function ke(e, r) {
|
|
492
527
|
const n = /* @__PURE__ */ new Map();
|
|
493
528
|
for (const { blueId: t, content: o } of r.values()) {
|
|
494
529
|
const s = J(t);
|
|
@@ -510,7 +545,7 @@ function Se(e, r) {
|
|
|
510
545
|
e.set(t, a);
|
|
511
546
|
}
|
|
512
547
|
}
|
|
513
|
-
function
|
|
548
|
+
function $e(e) {
|
|
514
549
|
const r = /* @__PURE__ */ new Map();
|
|
515
550
|
for (const n of e) {
|
|
516
551
|
const t = r.get(n.preliminaryBlueId);
|
|
@@ -521,66 +556,66 @@ function Te(e) {
|
|
|
521
556
|
r.set(n.preliminaryBlueId, n.alias);
|
|
522
557
|
}
|
|
523
558
|
}
|
|
524
|
-
function
|
|
559
|
+
function Ne(e, r) {
|
|
525
560
|
return e.preliminaryBlueId < r.preliminaryBlueId ? -1 : e.preliminaryBlueId > r.preliminaryBlueId ? 1 : 0;
|
|
526
561
|
}
|
|
527
|
-
function
|
|
562
|
+
function V(e, r) {
|
|
528
563
|
if (e === r)
|
|
529
564
|
return !0;
|
|
530
565
|
if (Array.isArray(e) || Array.isArray(r))
|
|
531
|
-
return !Array.isArray(e) || !Array.isArray(r) || e.length !== r.length ? !1 : e.every((n, t) =>
|
|
566
|
+
return !Array.isArray(e) || !Array.isArray(r) || e.length !== r.length ? !1 : e.every((n, t) => V(n, r[t]));
|
|
532
567
|
if (h(e) || h(r)) {
|
|
533
568
|
if (!h(e) || !h(r))
|
|
534
569
|
return !1;
|
|
535
570
|
const n = Object.keys(e).sort(), t = Object.keys(r).sort();
|
|
536
571
|
return n.length !== t.length ? !1 : n.every(
|
|
537
|
-
(o, s) => o === t[s] &&
|
|
572
|
+
(o, s) => o === t[s] && V(e[o], r[o])
|
|
538
573
|
);
|
|
539
574
|
}
|
|
540
575
|
return !1;
|
|
541
576
|
}
|
|
542
|
-
function
|
|
577
|
+
function Re(e) {
|
|
543
578
|
const r = x[e];
|
|
544
579
|
if (!r)
|
|
545
580
|
throw new Error(`Missing primitive BlueId for ${e}.`);
|
|
546
581
|
return r;
|
|
547
582
|
}
|
|
548
|
-
const
|
|
583
|
+
const L = new Set(Object.values(x)), Me = /* @__PURE__ */ new Set([
|
|
549
584
|
"type",
|
|
550
585
|
"itemType",
|
|
551
586
|
"valueType",
|
|
552
587
|
"keyType"
|
|
553
|
-
]),
|
|
588
|
+
]), Ve = /* @__PURE__ */ new Set(["name", "description"]), B = {
|
|
554
589
|
Unchanged: "unchanged",
|
|
555
590
|
NonBreaking: "non-breaking",
|
|
556
591
|
Breaking: "breaking"
|
|
557
592
|
};
|
|
558
|
-
function
|
|
593
|
+
function _e(e, r, n, t, o) {
|
|
559
594
|
const s = oe.compare(
|
|
560
595
|
e,
|
|
561
596
|
r
|
|
562
597
|
);
|
|
563
598
|
if (s.length === 0)
|
|
564
|
-
return { status:
|
|
599
|
+
return { status: B.Unchanged, attributesAdded: [] };
|
|
565
600
|
const a = [];
|
|
566
601
|
let c = !1;
|
|
567
602
|
for (const i of s) {
|
|
568
|
-
if (
|
|
603
|
+
if (De(i, e, o)) {
|
|
569
604
|
c = !0;
|
|
570
605
|
continue;
|
|
571
606
|
}
|
|
572
607
|
if (i.op !== "add")
|
|
573
|
-
return { status:
|
|
574
|
-
if (!
|
|
575
|
-
return { status:
|
|
608
|
+
return { status: B.Breaking, attributesAdded: [] };
|
|
609
|
+
if (!xe(i))
|
|
610
|
+
return { status: B.Breaking, attributesAdded: [] };
|
|
576
611
|
a.push(i.path);
|
|
577
612
|
}
|
|
578
613
|
return a.length === 0 && !c ? {
|
|
579
|
-
status:
|
|
614
|
+
status: B.Breaking,
|
|
580
615
|
attributesAdded: []
|
|
581
|
-
} : (a.length > 0 &&
|
|
616
|
+
} : (a.length > 0 && Oe(a, n, t), { status: B.NonBreaking, attributesAdded: a });
|
|
582
617
|
}
|
|
583
|
-
function
|
|
618
|
+
function Oe(e, r, n) {
|
|
584
619
|
for (const t of e)
|
|
585
620
|
try {
|
|
586
621
|
te(t);
|
|
@@ -590,16 +625,16 @@ function Re(e, r, n) {
|
|
|
590
625
|
);
|
|
591
626
|
}
|
|
592
627
|
}
|
|
593
|
-
function
|
|
628
|
+
function xe(e) {
|
|
594
629
|
if (e.op !== "add")
|
|
595
630
|
return !1;
|
|
596
631
|
const r = z(e.path);
|
|
597
632
|
if (r.length === 0)
|
|
598
633
|
return !1;
|
|
599
634
|
const n = r.at(-1);
|
|
600
|
-
return n && /^\d+$/.test(n) || n &&
|
|
635
|
+
return n && /^\d+$/.test(n) || n && Me.has(n) || r.some(
|
|
601
636
|
(t) => ee.has(t)
|
|
602
|
-
) ? !1 : I(e.value) ? !
|
|
637
|
+
) ? !1 : I(e.value) ? !Ce(e.value) : n ? Ve.has(n) : !1;
|
|
603
638
|
}
|
|
604
639
|
function z(e) {
|
|
605
640
|
try {
|
|
@@ -608,25 +643,25 @@ function z(e) {
|
|
|
608
643
|
return [];
|
|
609
644
|
}
|
|
610
645
|
}
|
|
611
|
-
function
|
|
646
|
+
function Ce(e) {
|
|
612
647
|
const r = [e];
|
|
613
648
|
for (; r.length; ) {
|
|
614
649
|
const n = r.pop();
|
|
615
650
|
if (n) {
|
|
616
651
|
if (Object.prototype.hasOwnProperty.call(n, "value") || Object.prototype.hasOwnProperty.call(n, "items"))
|
|
617
652
|
return !0;
|
|
618
|
-
if (Object.prototype.hasOwnProperty.call(n,
|
|
619
|
-
const t = n[
|
|
653
|
+
if (Object.prototype.hasOwnProperty.call(n, P)) {
|
|
654
|
+
const t = n[P];
|
|
620
655
|
if (I(t) && t.required === !0)
|
|
621
656
|
return !0;
|
|
622
657
|
}
|
|
623
658
|
for (const [t, o] of Object.entries(n))
|
|
624
|
-
t !==
|
|
659
|
+
t !== P && I(o) && r.push(o);
|
|
625
660
|
}
|
|
626
661
|
}
|
|
627
662
|
return !1;
|
|
628
663
|
}
|
|
629
|
-
function
|
|
664
|
+
function De(e, r, n) {
|
|
630
665
|
if (e.op !== "replace" || typeof e.path != "string")
|
|
631
666
|
return !1;
|
|
632
667
|
const t = z(e.path);
|
|
@@ -635,8 +670,8 @@ function Oe(e, r, n) {
|
|
|
635
670
|
const o = t.at(-1), s = t.at(-2);
|
|
636
671
|
if (!(o === "blueId" && s !== void 0 && (s === "type" || s === "itemType" || s === "keyType" || s === "valueType")))
|
|
637
672
|
return !1;
|
|
638
|
-
const a =
|
|
639
|
-
if (c &&
|
|
673
|
+
const a = je(r, t), c = typeof a == "string" ? a : I(a) && typeof a.blueId == "string" ? a.blueId : null, i = typeof e.value == "string" ? e.value : I(e.value) && typeof e.value.blueId == "string" ? e.value.blueId : null;
|
|
674
|
+
if (c && L.has(c) || i && L.has(i) || !c || !i)
|
|
640
675
|
return !1;
|
|
641
676
|
const f = n.get(c), u = n.get(i);
|
|
642
677
|
if (!f || !u)
|
|
@@ -646,7 +681,7 @@ function Oe(e, r, n) {
|
|
|
646
681
|
return !0;
|
|
647
682
|
return !1;
|
|
648
683
|
}
|
|
649
|
-
function
|
|
684
|
+
function je(e, r) {
|
|
650
685
|
let n = e;
|
|
651
686
|
for (const t of r)
|
|
652
687
|
if (Array.isArray(n)) {
|
|
@@ -660,7 +695,7 @@ function Ce(e, r) {
|
|
|
660
695
|
return;
|
|
661
696
|
return n;
|
|
662
697
|
}
|
|
663
|
-
function
|
|
698
|
+
function Ue(e) {
|
|
664
699
|
const r = /* @__PURE__ */ new Map();
|
|
665
700
|
if (!e)
|
|
666
701
|
return r;
|
|
@@ -676,7 +711,7 @@ function _e(e) {
|
|
|
676
711
|
}
|
|
677
712
|
return r;
|
|
678
713
|
}
|
|
679
|
-
function
|
|
714
|
+
function Fe(e, r) {
|
|
680
715
|
for (const [n, t] of r)
|
|
681
716
|
for (const [o, s] of t) {
|
|
682
717
|
const a = `${n}/${o}`;
|
|
@@ -686,14 +721,14 @@ function De(e, r) {
|
|
|
686
721
|
);
|
|
687
722
|
}
|
|
688
723
|
}
|
|
689
|
-
function
|
|
724
|
+
function Le({
|
|
690
725
|
discovered: e,
|
|
691
726
|
previousTypes: r,
|
|
692
727
|
aliasToBlueId: n,
|
|
693
728
|
aliasToStorageContent: t,
|
|
694
729
|
nextRepoVersionIndex: o
|
|
695
730
|
}) {
|
|
696
|
-
const s = /* @__PURE__ */ new Map(), a =
|
|
731
|
+
const s = /* @__PURE__ */ new Map(), a = Ge(r, n);
|
|
697
732
|
for (const [c, i] of e) {
|
|
698
733
|
const f = n.get(c);
|
|
699
734
|
if (!f)
|
|
@@ -703,7 +738,7 @@ function je({
|
|
|
703
738
|
throw new Error(
|
|
704
739
|
`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`
|
|
705
740
|
);
|
|
706
|
-
const l = t.get(c) ?? i.content, y = i.status === m.Dev ?
|
|
741
|
+
const l = t.get(c) ?? i.content, y = i.status === m.Dev ? Ye({ blueId: f, nextRepoVersionIndex: o, previousType: u }) : !u || u.status === m.Dev ? qe({ blueId: f, nextRepoVersionIndex: o }) : We({
|
|
707
742
|
alias: c,
|
|
708
743
|
blueId: f,
|
|
709
744
|
nextRepoVersionIndex: o,
|
|
@@ -719,7 +754,7 @@ function je({
|
|
|
719
754
|
}
|
|
720
755
|
return s;
|
|
721
756
|
}
|
|
722
|
-
function
|
|
757
|
+
function Ge(e, r) {
|
|
723
758
|
const n = /* @__PURE__ */ new Map(), t = (o, s) => {
|
|
724
759
|
const a = n.get(o);
|
|
725
760
|
if (a) {
|
|
@@ -738,7 +773,7 @@ function Ue(e, r) {
|
|
|
738
773
|
t(s, o);
|
|
739
774
|
return n;
|
|
740
775
|
}
|
|
741
|
-
function
|
|
776
|
+
function Ye({
|
|
742
777
|
blueId: e,
|
|
743
778
|
nextRepoVersionIndex: r,
|
|
744
779
|
previousType: n
|
|
@@ -747,7 +782,7 @@ function Fe({
|
|
|
747
782
|
return {
|
|
748
783
|
status: m.Dev,
|
|
749
784
|
content: {},
|
|
750
|
-
versions: s && t?.versions ?
|
|
785
|
+
versions: s && t?.versions ? $(t.versions) : [
|
|
751
786
|
{
|
|
752
787
|
repositoryVersionIndex: r,
|
|
753
788
|
typeBlueId: e,
|
|
@@ -756,7 +791,7 @@ function Fe({
|
|
|
756
791
|
]
|
|
757
792
|
};
|
|
758
793
|
}
|
|
759
|
-
function
|
|
794
|
+
function qe({
|
|
760
795
|
blueId: e,
|
|
761
796
|
nextRepoVersionIndex: r
|
|
762
797
|
}) {
|
|
@@ -772,7 +807,7 @@ function Le({
|
|
|
772
807
|
]
|
|
773
808
|
};
|
|
774
809
|
}
|
|
775
|
-
function
|
|
810
|
+
function We({
|
|
776
811
|
alias: e,
|
|
777
812
|
blueId: r,
|
|
778
813
|
nextRepoVersionIndex: n,
|
|
@@ -786,15 +821,15 @@ function Ge({
|
|
|
786
821
|
throw new Error(
|
|
787
822
|
`Type ${e} has non-object content; cannot compute diff for stable versioning.`
|
|
788
823
|
);
|
|
789
|
-
const i =
|
|
824
|
+
const i = _e(
|
|
790
825
|
t.content,
|
|
791
826
|
o,
|
|
792
827
|
s,
|
|
793
828
|
a,
|
|
794
829
|
c
|
|
795
830
|
);
|
|
796
|
-
if (i.status ===
|
|
797
|
-
const f =
|
|
831
|
+
if (i.status === B.Unchanged) {
|
|
832
|
+
const f = $(t.versions || []), u = f.at(-1);
|
|
798
833
|
if (u && u.typeBlueId !== r)
|
|
799
834
|
throw new Error(
|
|
800
835
|
`Type ${e} content is unchanged but BlueId differs from previous metadata.`
|
|
@@ -805,12 +840,12 @@ function Ge({
|
|
|
805
840
|
versions: f
|
|
806
841
|
};
|
|
807
842
|
}
|
|
808
|
-
if (i.status ===
|
|
843
|
+
if (i.status === B.NonBreaking)
|
|
809
844
|
return {
|
|
810
845
|
status: m.Stable,
|
|
811
846
|
content: {},
|
|
812
847
|
versions: [
|
|
813
|
-
|
|
848
|
+
...$(t.versions || []),
|
|
814
849
|
{
|
|
815
850
|
repositoryVersionIndex: n,
|
|
816
851
|
typeBlueId: r,
|
|
@@ -822,7 +857,7 @@ function Ge({
|
|
|
822
857
|
`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`
|
|
823
858
|
);
|
|
824
859
|
}
|
|
825
|
-
function
|
|
860
|
+
function Je(e) {
|
|
826
861
|
return Array.from(e.entries()).map(([r, n]) => ({
|
|
827
862
|
name: r,
|
|
828
863
|
types: n.map((t) => ({
|
|
@@ -836,38 +871,38 @@ function qe(e) {
|
|
|
836
871
|
})
|
|
837
872
|
})).sort((r, n) => r.name.localeCompare(n.name));
|
|
838
873
|
}
|
|
839
|
-
function
|
|
874
|
+
function G(e) {
|
|
840
875
|
return Z.INSTANCE.calculateSync(
|
|
841
876
|
e
|
|
842
877
|
);
|
|
843
878
|
}
|
|
844
|
-
function
|
|
879
|
+
function Ke(e, r, n) {
|
|
845
880
|
const t = r?.repositoryVersions.at(-1), o = !t || t !== n, s = r?.repositoryVersions ? [...r.repositoryVersions] : [];
|
|
846
881
|
return o && s.push(n), { document: {
|
|
847
|
-
name:
|
|
882
|
+
name: C,
|
|
848
883
|
packages: e,
|
|
849
884
|
repositoryVersions: s
|
|
850
885
|
}, changed: o };
|
|
851
886
|
}
|
|
852
|
-
function
|
|
887
|
+
function ze(e, r, n) {
|
|
853
888
|
const t = {
|
|
854
|
-
name:
|
|
889
|
+
name: C,
|
|
855
890
|
repositoryVersions: r,
|
|
856
|
-
packages:
|
|
891
|
+
packages: He(e, n)
|
|
857
892
|
};
|
|
858
893
|
re(t);
|
|
859
894
|
}
|
|
860
|
-
function
|
|
895
|
+
function He(e, r) {
|
|
861
896
|
const n = {};
|
|
862
897
|
for (const t of e) {
|
|
863
|
-
const o =
|
|
898
|
+
const o = Xe(t.name, r), s = {}, a = {};
|
|
864
899
|
for (const c of t.types) {
|
|
865
900
|
const i = c.versions?.[c.versions.length - 1]?.typeBlueId;
|
|
866
901
|
if (!i)
|
|
867
902
|
throw new Error(
|
|
868
903
|
`Type ${t.name} is missing a current BlueId in versions.`
|
|
869
904
|
);
|
|
870
|
-
const f =
|
|
905
|
+
const f = Ze(c);
|
|
871
906
|
s[i] = {
|
|
872
907
|
status: c.status,
|
|
873
908
|
name: f,
|
|
@@ -884,22 +919,22 @@ function Je(e, r) {
|
|
|
884
919
|
}
|
|
885
920
|
return n;
|
|
886
921
|
}
|
|
887
|
-
function
|
|
922
|
+
function Xe(e, r) {
|
|
888
923
|
const n = {}, t = `${e}/`;
|
|
889
924
|
return r.forEach((o, s) => {
|
|
890
925
|
s.startsWith(t) && (n[s] = o);
|
|
891
926
|
}), n;
|
|
892
927
|
}
|
|
893
|
-
function
|
|
928
|
+
function Ze(e) {
|
|
894
929
|
const r = h(e.content) && typeof e.content.name == "string" ? e.content.name : null;
|
|
895
930
|
if (!r)
|
|
896
931
|
throw new Error('Type content is missing required "name" field.');
|
|
897
932
|
return r;
|
|
898
933
|
}
|
|
899
|
-
function
|
|
934
|
+
function Qe(e) {
|
|
900
935
|
if (!A.existsSync(e))
|
|
901
936
|
return { previous: null };
|
|
902
|
-
const r = A.readFileSync(e, "utf8"), n =
|
|
937
|
+
const r = A.readFileSync(e, "utf8"), n = Y(r);
|
|
903
938
|
if (!n || !I(n))
|
|
904
939
|
throw new Error("Existing BlueRepository.blue is not a valid object.");
|
|
905
940
|
const t = n, o = t.packages, s = t.repositoryVersions, a = Array.isArray(o) && o.every(
|
|
@@ -910,42 +945,42 @@ function He(e) {
|
|
|
910
945
|
"Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }"
|
|
911
946
|
);
|
|
912
947
|
const i = o, f = s, u = {
|
|
913
|
-
name: typeof t.name == "string" ? t.name :
|
|
948
|
+
name: typeof t.name == "string" ? t.name : C,
|
|
914
949
|
packages: i,
|
|
915
950
|
repositoryVersions: f
|
|
916
951
|
};
|
|
917
952
|
return { existingYaml: r, previous: u };
|
|
918
953
|
}
|
|
919
|
-
function
|
|
954
|
+
function et(e) {
|
|
920
955
|
return se.dump(e, { lineWidth: -1 });
|
|
921
956
|
}
|
|
922
|
-
function
|
|
923
|
-
const r =
|
|
924
|
-
|
|
925
|
-
const c =
|
|
926
|
-
|
|
927
|
-
const { aliasToBlueId: f, aliasToStorageContent: u } =
|
|
957
|
+
function ct(e) {
|
|
958
|
+
const r = j.resolve(e.repoRoot), n = j.resolve(e.blueRepositoryPath), { existingYaml: t, previous: o } = Qe(n), s = ue(r), a = Ue(o);
|
|
959
|
+
Fe(s, a);
|
|
960
|
+
const c = ye(s), i = me(c);
|
|
961
|
+
he(c, s);
|
|
962
|
+
const { aliasToBlueId: f, aliasToStorageContent: u } = ve(
|
|
928
963
|
i,
|
|
929
964
|
s,
|
|
930
965
|
c,
|
|
931
966
|
a
|
|
932
|
-
), l = o ? o.repositoryVersions.length : 0, y =
|
|
967
|
+
), l = o ? o.repositoryVersions.length : 0, y = Le({
|
|
933
968
|
discovered: s,
|
|
934
969
|
previousTypes: a,
|
|
935
970
|
aliasToBlueId: f,
|
|
936
971
|
aliasToStorageContent: u,
|
|
937
972
|
nextRepoVersionIndex: l
|
|
938
|
-
}), g =
|
|
973
|
+
}), g = Je(y), E = o && tt(o.packages, g) ? o.repositoryVersions.at(-1) ?? G(g) : G(g), { document: d, changed: p } = Ke(
|
|
939
974
|
g,
|
|
940
975
|
o,
|
|
941
976
|
E
|
|
942
977
|
);
|
|
943
|
-
|
|
978
|
+
ze(
|
|
944
979
|
d.packages,
|
|
945
980
|
d.repositoryVersions,
|
|
946
981
|
f
|
|
947
982
|
);
|
|
948
|
-
const b =
|
|
983
|
+
const b = et(d);
|
|
949
984
|
if (o && !p && t && t !== b)
|
|
950
985
|
throw new Error(
|
|
951
986
|
"BlueRepository.blue content differs from regenerated output while RepoBlueId is unchanged. Please revert manual edits or rerun in write mode."
|
|
@@ -961,9 +996,9 @@ function st(e) {
|
|
|
961
996
|
existingYaml: t
|
|
962
997
|
};
|
|
963
998
|
}
|
|
964
|
-
function
|
|
999
|
+
function tt(e, r) {
|
|
965
1000
|
return JSON.stringify(e) === JSON.stringify(r);
|
|
966
1001
|
}
|
|
967
1002
|
export {
|
|
968
|
-
|
|
1003
|
+
ct as g
|
|
969
1004
|
};
|
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-BHDjJhJX.js");exports.generateRepository=e.generateRepository;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const PRIMITIVE_TYPES: Set<string>;
|
|
2
|
+
export declare const SCALAR_PRIMITIVE_TYPES: Set<string>;
|
|
2
3
|
export declare const PRIMITIVE_BLUE_IDS: Record<string, string>;
|
|
4
|
+
export declare const RESERVED_LANGUAGE_KEYS: Set<string>;
|
|
3
5
|
export declare const BLUE_REPOSITORY_NAME = "Blue Repository";
|
|
4
6
|
export declare const BLUE_TYPE_STATUS: {
|
|
5
7
|
readonly Dev: "dev";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/core/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,aAA8C,CAAC;AAC3E,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CACZ,CAAC;AAE3C,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAC/B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,eAAO,MAAM,oBAAoB,aAQ/B,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/core/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,aAA8C,CAAC;AAC3E,eAAO,MAAM,sBAAsB,aAEjC,CAAC;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CACZ,CAAC;AAE3C,eAAO,MAAM,sBAAsB,aAcjC,CAAC;AAEH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAC/B,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAE3D,eAAO,MAAM,oBAAoB,aAQ/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/lib/core/discovery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAW,KAAK,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/lib/core/discovery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAW,KAAK,EAAE,MAAM,iBAAiB,CAAC;AASjE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAgD1E"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blue-labs/repository-generator",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"bin": {
|
|
5
5
|
"blue-repo-generator": "./dist/bin/blue-repo-generator.mjs"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@blue-labs/language": "4.1.
|
|
9
|
-
"@blue-labs/repository-contract": "4.1.
|
|
8
|
+
"@blue-labs/language": "4.1.2",
|
|
9
|
+
"@blue-labs/repository-contract": "4.1.2",
|
|
10
10
|
"fast-json-patch": "3.1.1",
|
|
11
11
|
"js-yaml": "4.1.0",
|
|
12
|
-
"@blue-labs/shared-utils": "4.1.
|
|
12
|
+
"@blue-labs/shared-utils": "4.1.2"
|
|
13
13
|
},
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const T=require("path"),S=require("fs"),g=require("@blue-labs/language"),v=require("@blue-labs/repository-contract"),Y=require("fast-json-patch"),H=require("js-yaml");function z(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const D=z(T),O=new Set([...g.Properties.CORE_TYPES]),V=g.Properties.CORE_TYPE_NAME_TO_BLUE_ID_MAP,C="Blue Repository",h={Dev:"dev",Stable:"stable"},K=new Set([".git",".github",".husky","node_modules",".nx",".vscode",".idea"]);function X(e){const r=S.readdirSync(e,{withFileTypes:!0}),n=new Map;for(const t of r){if(!t.isDirectory()||K.has(t.name))continue;const o=T.join(e,t.name),s=q(o);if(s.length!==0)for(const a of s){const c=a.endsWith(".dev.blue")?h.Dev:h.Stable,i=Z(a),f=Q(i,a),u=`${t.name}/${f}`,l=n.get(u);if(l)throw l.status!==c?new Error(`Type ${u} has both stable and dev definitions (${l.filePath} and ${a}).`):new Error(`Type ${u} is defined multiple times (${l.filePath} and ${a}).`);const y=ee(i,a);n.set(u,{packageName:t.name,typeName:f,status:c,content:i,filePath:a,references:y})}}return n}function Z(e){const r=S.readFileSync(e,"utf8"),n=g.yamlBlueParse(r);if(!x(n))throw new Error(`Type file ${e} must contain a YAML object.`);return n}function Q(e,r){if(!x(e)||typeof e.name!="string")throw new Error(`Type file ${r} is missing required "name" field.`);return e.name}function q(e){const r=S.readdirSync(e,{withFileTypes:!0}),n=[];for(const t of r){if(t.isDirectory()){n.push(...q(T.join(e,t.name)));continue}(t.name.endsWith(".blue")||t.name.endsWith(".dev.blue"))&&n.push(T.join(e,t.name))}return n}function ee(e,r){const n=new Set,t=o=>{if(Array.isArray(o)){o.forEach(a=>t(a));return}if(!x(o))return;const s=a=>{if(typeof a=="string"&&!O.has(a)){if(!a.includes("/"))throw new Error(`Invalid type reference "${a}" in ${r}. Use <Package>/<Type> for non-primitive references.`);n.add(a)}};s(o.type),s(o.itemType),s(o.keyType),s(o.valueType),Object.values(o).forEach(a=>t(a))};return t(e),n}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function te(e){const r=new Map;for(const[n,t]of e){const o=new Set;for(const s of t.references){if(!e.has(s))throw new Error(`Type ${n} references unknown alias ${s}. Ensure the target type exists.`);o.add(s)}r.set(n,o)}return r}function ne(e){const r=[],n=new Map,t=new Map,o=[],s=new Set;let a=0;const c=i=>{n.set(i,a),t.set(i,a),a+=1,o.push(i),s.add(i);for(const u of e.get(i)??[]){if(!n.has(u)){c(u),t.set(i,Math.min(t.get(i)??0,t.get(u)??0));continue}s.has(u)&&t.set(i,Math.min(t.get(i)??0,n.get(u)??0))}if(t.get(i)!==n.get(i))return;const f=[];for(;o.length>0;){const u=o.pop();if(!u||(s.delete(u),f.push(u),u===i))break}r.push(f.sort((u,l)=>u.localeCompare(l)))};for(const i of e.keys())n.has(i)||c(i);return r}function re(e){const r=ne(e),n=new Map;r.forEach((c,i)=>{c.forEach(f=>n.set(f,i))});const t=new Map;r.forEach((c,i)=>t.set(i,new Set));for(const[c,i]of e){const f=n.get(c);if(f!==void 0)for(const u of i){const l=n.get(u);l!==void 0&&l!==f&&t.get(f)?.add(l)}}const o=[],s=new Set,a=c=>{if(!s.has(c)){s.add(c);for(const i of t.get(c)??[])a(i);o.push(c)}};for(const c of t.keys())a(c);return o.map(c=>r[c]??[])}function oe(e,r){const n=new Map,t=(o,s=new Set)=>{if(n.has(o))return n.get(o)??!1;if(s.has(o))return!1;s.add(o);const a=e.get(o)||new Set;for(const c of a){const i=r.get(c);if(i&&(i.status===h.Dev||t(c,s)))return s.delete(o),n.set(o,!0),!0}return s.delete(o),n.set(o,!1),!1};for(const[o,s]of r)if(s.status===h.Stable&&t(o))throw new Error(`Stable type ${o} depends on a dev type. Stable types may only depend on other stable types.`)}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function w(e){return I(e)?Object.getPrototypeOf(e)===Object.prototype:!1}function P(e){if(Array.isArray(e))return e.map(r=>P(r));if(w(e)){const r={};for(const[n,t]of Object.entries(e))r[n]=P(t);return r}return e}function k(e){return e.map(r=>({repositoryVersionIndex:r.repositoryVersionIndex,typeBlueId:r.typeBlueId,attributesAdded:[...r.attributesAdded]}))}const se=/^\$\{([\s\S]*)\}$/;class ie{process(r,n){const t=n.getValue();if(j(t)){const o=n.clone();return o.setValue(t),o.setProperties(void 0),o.setItems(void 0),o.setType(void 0),o}return r}postProcess(r,n){const t=n.getValue();if(j(t)&&r.getValue()!==t){const o=r.clone();return o.setValue(t),o}return r}}function j(e){return typeof e!="string"||!se.test(e)?!1:e.indexOf("${")===e.lastIndexOf("${")}function ae(){return new g.MergingProcessors.SequentialMergingProcessor([new g.MergingProcessors.ValuePropagator,new ie,new g.MergingProcessors.TypeAssigner,new g.MergingProcessors.ListProcessor,new g.MergingProcessors.DictionaryProcessor,new g.MergingProcessors.MetadataPropagator,new g.MergingProcessors.BasicTypesVerifier])}const L="00000000000000000000000000000000000000000000";function ce(e,r,n,t){const o=new Map,s=new Map,a=new Map,c=new g.Blue,i=g.createNodeProvider(l=>fe(l)?[new g.BlueNode().setReferenceBlueId(l)]:ue(a,l).map(y=>c.jsonValueToNode(y))),u={blue:new g.Blue({nodeProvider:i,mergingProcessor:ae()}),contentByBlueId:a};for(const l of e){if(pe(l,n)){de({component:l,discovered:r,previousTypes:t,aliasToBlueId:o,aliasToStorageContent:s,context:u});continue}const y=l[0];if(!y)continue;const m=r.get(y);m&&le({alias:y,type:m,previousTypes:t,aliasToBlueId:o,aliasToStorageContent:s,context:u})}return{aliasToBlueId:o,aliasToStorageContent:s}}function ue(e,r){const n=G(r);if(n===void 0)return[];const t=e.get(n.baseBlueId);if(t===void 0)return[];if(n.index===void 0)return Array.isArray(t)?t:[t];if(!Array.isArray(t))return n.index===0?[t]:[];const o=t[n.index];return o===void 0?[]:[o]}function G(e){const r=e.indexOf("#");if(r===-1)return{baseBlueId:e};const n=e.slice(0,r),t=e.slice(r+1),o=Number(t);if(!(!Number.isInteger(o)||o<0))return{baseBlueId:n,index:o}}function fe(e){return e===L||/^this#\d+$/.test(e)}function $(e,r,n=!1,t=!1){if(Array.isArray(e))return e.map(s=>$(s,r,n,t));if(!I(e))return e;const o={};for(const[s,a]of Object.entries(e)){const c=t||s===v.OBJECT_CONTRACTS;if((s==="type"||s==="itemType"||s==="keyType"||s==="valueType")&&typeof a=="string"&&!(n&&c)){if(O.has(a)){const i=V[a];if(!i)throw new Error(`Missing primitive BlueId for ${a}.`);o[s]={blueId:i}}else{const i=a,f=r(i);if(!f)throw new Error(`Missing BlueId for alias ${i}.`);o[s]={blueId:f}}continue}o[s]=$(a,r,n,c)}return o}function le({alias:e,type:r,previousTypes:n,aliasToBlueId:t,aliasToStorageContent:o,context:s}){const{node:a,storageContent:c}=M(r,m=>t.get(m),s.blue),i=O.has(r.typeName),f=i?we(r.typeName):s.blue.calculateBlueIdSync(a),u=J(n,r,c),l=u?.blueId??f,y=u?.content??c;t.set(e,l),o.set(e,y),i||s.contentByBlueId.set(l,y),s.blue.registerBlueIds({[e]:l})}function de({component:e,discovered:r,previousTypes:n,aliasToBlueId:t,aliasToStorageContent:o,context:s}){const a=new Set(e),c=new Map;e.forEach((d,p)=>c.set(d,p));const i=e.map(d=>{const p=N(r,d),{node:B}=M(p,b=>a.has(b)?L:t.get(b),s.blue);return{alias:d,preliminaryBlueId:s.blue.calculateBlueIdSync(B)}});me(i),i.sort(he);const f=new Map;i.forEach(({alias:d},p)=>{f.set(d,p)});const u=new Map;for(const d of e){const p=N(r,d),B=M(p,b=>{if(!a.has(b))return t.get(b);const _=f.get(b);if(_===void 0)throw new Error(`Failed to resolve cyclic reference ${b}.`);return`this#${_}`},s.blue);u.set(d,B)}const l=ye(e,r,n,u);if(l){for(const d of e){const p=l.get(d);if(!p)throw new Error(`Failed to preserve cyclic BlueId for type ${d}.`);t.set(d,p.blueId),o.set(d,p.content),s.blue.registerBlueIds({[d]:p.blueId})}ge(s.contentByBlueId,l);return}const y=i.map(({alias:d})=>{const p=u.get(d);if(!p)throw new Error(`Failed to build cyclic content for type ${d}.`);return p.node}),m=i.map(({alias:d})=>{const p=u.get(d);if(!p)throw new Error(`Failed to build cyclic content for type ${d}.`);return p.storageContent}),A=s.blue.calculateBlueIdSync(y);s.contentByBlueId.set(A,m),i.forEach(({alias:d},p)=>{const B=u.get(d);if(!B)throw new Error(`Failed to build cyclic content for type ${d}.`);const b=`${A}#${p}`;t.set(d,b),o.set(d,B.storageContent),s.blue.registerBlueIds({[d]:b})})}function pe(e,r){if(e.length>1)return!0;const n=e[0];return n?r.get(n)?.has(n)??!1:!1}function M(e,r,n){const t=$(P(e.content),r),o=n.jsonValueToNode(t);return{node:o,storageContent:n.nodeToJson(o,"official")}}function N(e,r){const n=e.get(r);if(!n)throw new Error(`Unknown type alias ${r}.`);return n}function ye(e,r,n,t){const o=new Map;for(const s of e){const a=N(r,s),c=t.get(s);if(!c)throw new Error(`Failed to build cyclic content for type ${s}.`);const i=J(n,a,c.storageContent);if(!i)return null;o.set(s,i)}return o}function J(e,r,n){const t=e.get(r.packageName)?.get(r.typeName),o=t?.versions?.at(-1)?.typeBlueId;return!o||!t||!w(t.content)||!R(t.content,n)?null:{blueId:o,content:P(t.content)}}function ge(e,r){const n=new Map;for(const{blueId:t,content:o}of r.values()){const s=G(t);if(!s||s.index===void 0){e.set(t,o);continue}const a=n.get(s.baseBlueId)??[];a.push({index:s.index,content:o}),n.set(s.baseBlueId,a)}for(const[t,o]of n){const a=[...o].sort((c,i)=>c.index-i.index).map((c,i)=>{if(c.index!==i)throw new Error(`Cyclic repository content for ${t} is missing index ${i}.`);return c.content});e.set(t,a)}}function me(e){const r=new Map;for(const n of e){const t=r.get(n.preliminaryBlueId);if(t)throw new Error(`Direct cyclic type set has ambiguous canonical ordering: ${t} and ${n.alias} share preliminary BlueId '${n.preliminaryBlueId}'.`);r.set(n.preliminaryBlueId,n.alias)}}function he(e,r){return e.preliminaryBlueId<r.preliminaryBlueId?-1:e.preliminaryBlueId>r.preliminaryBlueId?1:0}function R(e,r){if(e===r)return!0;if(Array.isArray(e)||Array.isArray(r))return!Array.isArray(e)||!Array.isArray(r)||e.length!==r.length?!1:e.every((n,t)=>R(n,r[t]));if(w(e)||w(r)){if(!w(e)||!w(r))return!1;const n=Object.keys(e).sort(),t=Object.keys(r).sort();return n.length!==t.length?!1:n.every((o,s)=>o===t[s]&&R(e[o],r[o]))}return!1}function we(e){const r=V[e];if(!r)throw new Error(`Missing primitive BlueId for ${e}.`);return r}const U=new Set(Object.values(V)),be=new Set(["type","itemType","valueType","keyType"]),Ie=new Set(["name","description"]),E={Unchanged:"unchanged",NonBreaking:"non-breaking",Breaking:"breaking"};function Be(e,r,n,t,o){const s=Y.compare(e,r);if(s.length===0)return{status:E.Unchanged,attributesAdded:[]};const a=[];let c=!1;for(const i of s){if(Se(i,e,o)){c=!0;continue}if(i.op!=="add")return{status:E.Breaking,attributesAdded:[]};if(!Ee(i))return{status:E.Breaking,attributesAdded:[]};a.push(i.path)}return a.length===0&&!c?{status:E.Breaking,attributesAdded:[]}:(a.length>0&&ve(a,n,t),{status:E.NonBreaking,attributesAdded:a})}function ve(e,r,n){for(const t of e)try{v.validateAttributesAddedPointer(t)}catch(o){throw new Error(`Invalid attribute pointer "${t}" for ${r}/${n}: ${o.message}`)}}function Ee(e){if(e.op!=="add")return!1;const r=W(e.path);if(r.length===0)return!1;const n=r.at(-1);return n&&/^\d+$/.test(n)||n&&be.has(n)||r.some(t=>v.RESERVED_ATTRIBUTES_POINTER_SEGMENTS.has(t))?!1:I(e.value)?!Ae(e.value):n?Ie.has(n):!1}function W(e){try{return v.parsePointer(e)}catch{return[]}}function Ae(e){const r=[e];for(;r.length;){const n=r.pop();if(n){if(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"items"))return!0;if(Object.prototype.hasOwnProperty.call(n,v.OBJECT_SCHEMA)){const t=n[v.OBJECT_SCHEMA];if(I(t)&&t.required===!0)return!0}for(const[t,o]of Object.entries(n))t!==v.OBJECT_SCHEMA&&I(o)&&r.push(o)}}return!1}function Se(e,r,n){if(e.op!=="replace"||typeof e.path!="string")return!1;const t=W(e.path);if(t.length<2)return!1;const o=t.at(-1),s=t.at(-2);if(!(o==="blueId"&&s!==void 0&&(s==="type"||s==="itemType"||s==="keyType"||s==="valueType")))return!1;const a=Te(r,t),c=typeof a=="string"?a:I(a)&&typeof a.blueId=="string"?a.blueId:null,i=typeof e.value=="string"?e.value:I(e.value)&&typeof e.value.blueId=="string"?e.value.blueId:null;if(c&&U.has(c)||i&&U.has(i)||!c||!i)return!1;const f=n.get(c),u=n.get(i);if(!f||!u)return!1;for(const l of f)if(u.has(l))return!0;return!1}function Te(e,r){let n=e;for(const t of r)if(Array.isArray(n)){const o=Number(t);if(Number.isNaN(o)||o<0||o>=n.length)return;n=n[o]}else if(I(n))n=n[t];else return;return n}function Pe(e){const r=new Map;if(!e)return r;for(const n of e.packages||[]){if(typeof n.name!="string")continue;const t=new Map;for(const o of n.types||[]){const s=o.content,a=w(s)&&typeof s.name=="string"?s.name:void 0;a&&t.set(a,o)}r.set(n.name,t)}return r}function ke(e,r){for(const[n,t]of r)for(const[o,s]of t){const a=`${n}/${o}`;if(!e.has(a)&&s.status===h.Stable)throw new Error(`Stable type ${a} was removed. Breaking changes require a new logical type name.`)}}function $e({discovered:e,previousTypes:r,aliasToBlueId:n,aliasToStorageContent:t,nextRepoVersionIndex:o}){const s=new Map,a=Me(r,n);for(const[c,i]of e){const f=n.get(c);if(!f)throw new Error(`Failed to compute BlueId for type ${c}.`);const u=r.get(i.packageName)?.get(i.typeName)??null;if(u&&u.status===h.Stable&&i.status===h.Dev)throw new Error(`Type ${c} was stable previously and cannot be downgraded to dev. Use a new logical name instead.`);const l=t.get(c)??i.content,y=i.status===h.Dev?Ne({blueId:f,nextRepoVersionIndex:o,previousType:u}):!u||u.status===h.Dev?Re({blueId:f,nextRepoVersionIndex:o}):Oe({alias:c,blueId:f,nextRepoVersionIndex:o,previousType:u,currentContent:l,packageName:i.packageName,typeName:i.typeName,blueIdAliases:a});y.content=l,y.status=i.status;const m=s.get(i.packageName)??[];m.push(y),s.set(i.packageName,m)}return s}function Me(e,r){const n=new Map,t=(o,s)=>{const a=n.get(o);if(a){a.add(s);return}n.set(o,new Set([s]))};for(const[o,s]of e)for(const[a,c]of s){const i=`${o}/${a}`;for(const f of c.versions??[])typeof f.typeBlueId=="string"&&t(f.typeBlueId,i)}for(const[o,s]of r)t(s,o);return n}function Ne({blueId:e,nextRepoVersionIndex:r,previousType:n}){const t=n&&n.status===h.Dev?n:null,o=t?.versions?.length===1?t.versions[0]:null,s=o&&o.typeBlueId===e;return{status:h.Dev,content:{},versions:s&&t?.versions?k(t.versions):[{repositoryVersionIndex:r,typeBlueId:e,attributesAdded:[]}]}}function Re({blueId:e,nextRepoVersionIndex:r}){return{status:h.Stable,content:{},versions:[{repositoryVersionIndex:r,typeBlueId:e,attributesAdded:[]}]}}function Oe({alias:e,blueId:r,nextRepoVersionIndex:n,previousType:t,currentContent:o,packageName:s,typeName:a,blueIdAliases:c}){if(!w(t.content))throw new Error(`Type ${e} has non-object content; cannot compute diff for stable versioning.`);const i=Be(t.content,o,s,a,c);if(i.status===E.Unchanged){const f=k(t.versions||[]),u=f.at(-1);if(u&&u.typeBlueId!==r)throw new Error(`Type ${e} content is unchanged but BlueId differs from previous metadata.`);return{status:h.Stable,content:{},versions:f}}if(i.status===E.NonBreaking)return{status:h.Stable,content:{},versions:[...k(t.versions||[]),{repositoryVersionIndex:n,typeBlueId:r,attributesAdded:i.attributesAdded}]};throw new Error(`Breaking change detected in stable type ${e}. Introduce a new type name for breaking changes.`)}function Ve(e){return Array.from(e.entries()).map(([r,n])=>({name:r,types:n.map(t=>({...t,versions:[...t.versions].sort((o,s)=>o.repositoryVersionIndex-s.repositoryVersionIndex)})).sort((t,o)=>{const s=w(t.content)&&typeof t.content.name=="string"?t.content.name:"",a=w(o.content)&&typeof o.content.name=="string"?o.content.name:"";return s.localeCompare(a)})})).sort((r,n)=>r.name.localeCompare(n.name))}function F(e){return g.BlueIdCalculator.INSTANCE.calculateSync(e)}function Ce(e,r,n){const t=r?.repositoryVersions.at(-1),o=!t||t!==n,s=r?.repositoryVersions?[...r.repositoryVersions]:[];return o&&s.push(n),{document:{name:C,packages:e,repositoryVersions:s},changed:o}}function xe(e,r,n){const t={name:C,repositoryVersions:r,packages:_e(e,n)};v.validateStableDoesNotDependOnDev(t)}function _e(e,r){const n={};for(const t of e){const o=De(t.name,r),s={},a={};for(const c of t.types){const i=c.versions?.[c.versions.length-1]?.typeBlueId;if(!i)throw new Error(`Type ${t.name} is missing a current BlueId in versions.`);const f=je(c);s[i]={status:c.status,name:f,versions:c.versions??[]},a[i]=c.content}n[t.name]={name:t.name,aliases:o,typesMeta:s,contents:a,schemas:{}}}return n}function De(e,r){const n={},t=`${e}/`;return r.forEach((o,s)=>{s.startsWith(t)&&(n[s]=o)}),n}function je(e){const r=w(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 Ue(e){if(!S.existsSync(e))return{previous:null};const r=S.readFileSync(e,"utf8"),n=g.yamlBlueParse(r);if(!n||!I(n))throw new Error("Existing BlueRepository.blue is not a valid object.");const t=n,o=t.packages,s=t.repositoryVersions,a=Array.isArray(o)&&o.every(l=>I(l)&&typeof l.name=="string"&&Array.isArray(l.types)),c=Array.isArray(s)&&s.every(l=>typeof l=="string");if(!a||!c)throw new Error("Invalid BlueRepository.blue structure: expected { packages: BluePackage[], repositoryVersions: string[] }");const i=o,f=s,u={name:typeof t.name=="string"?t.name:C,packages:i,repositoryVersions:f};return{existingYaml:r,previous:u}}function Fe(e){return H.dump(e,{lineWidth:-1})}function qe(e){const r=D.resolve(e.repoRoot),n=D.resolve(e.blueRepositoryPath),{existingYaml:t,previous:o}=Ue(n),s=X(r),a=Pe(o);ke(s,a);const c=te(s),i=re(c);oe(c,s);const{aliasToBlueId:f,aliasToStorageContent:u}=ce(i,s,c,a),l=o?o.repositoryVersions.length:0,y=$e({discovered:s,previousTypes:a,aliasToBlueId:f,aliasToStorageContent:u,nextRepoVersionIndex:l}),m=Ve(y),A=o&&Le(o.packages,m)?o.repositoryVersions.at(-1)??F(m):F(m),{document:d,changed:p}=Ce(m,o,A);xe(d.packages,d.repositoryVersions,f);const B=Fe(d);if(o&&!p&&t&&t!==B)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} (${p?"changed":"unchanged"})`),{document:d,currentRepoBlueId:A,previousRepoBlueId:o?.repositoryVersions.at(-1),changed:p||!t,yaml:B,existingYaml:t}}function Le(e,r){return JSON.stringify(e)===JSON.stringify(r)}exports.generateRepository=qe;
|