@speclynx/apidom-datamodel 2.10.3 → 2.11.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.11.0](https://github.com/speclynx/apidom/compare/v2.10.3...v2.11.0) (2026-02-12)
7
+
8
+ ### Features
9
+
10
+ - **datamodel:** introduce side-effect free element accessors ([#87](https://github.com/speclynx/apidom/issues/87)) ([f93b066](https://github.com/speclynx/apidom/commit/f93b066836f04570fa5781aea176885175a35ef4))
11
+
6
12
  ## [2.10.3](https://github.com/speclynx/apidom/compare/v2.10.2...v2.10.3) (2026-02-10)
7
13
 
8
14
  **Note:** Version bump only for package @speclynx/apidom-datamodel
@@ -1998,7 +1998,13 @@ class Element {
1998
1998
 
1999
1999
  /** Unique identifier for this element. */
2000
2000
  get id() {
2001
- return this.getMetaProperty('id', '');
2001
+ if (this.isFrozen) {
2002
+ return this.getMetaProperty('id', '');
2003
+ }
2004
+ if (!this.hasMetaProperty('id')) {
2005
+ this.setMetaProperty('id', '');
2006
+ }
2007
+ return this.meta.get('id');
2002
2008
  }
2003
2009
  set id(value) {
2004
2010
  this.setMetaProperty('id', value);
@@ -2006,7 +2012,13 @@ class Element {
2006
2012
 
2007
2013
  /** CSS-like class names. */
2008
2014
  get classes() {
2009
- return this.getMetaProperty('classes', []);
2015
+ if (this.isFrozen) {
2016
+ return this.getMetaProperty('classes', []);
2017
+ }
2018
+ if (!this.hasMetaProperty('classes')) {
2019
+ this.setMetaProperty('classes', []);
2020
+ }
2021
+ return this.meta.get('classes');
2010
2022
  }
2011
2023
  set classes(value) {
2012
2024
  this.setMetaProperty('classes', value);
@@ -2014,7 +2026,13 @@ class Element {
2014
2026
 
2015
2027
  /** Hyperlinks associated with this element. */
2016
2028
  get links() {
2017
- return this.getMetaProperty('links', []);
2029
+ if (this.isFrozen) {
2030
+ return this.getMetaProperty('links', []);
2031
+ }
2032
+ if (!this.hasMetaProperty('links')) {
2033
+ this.setMetaProperty('links', []);
2034
+ }
2035
+ return this.meta.get('links');
2018
2036
  }
2019
2037
  set links(value) {
2020
2038
  this.setMetaProperty('links', value);
@@ -2165,16 +2183,26 @@ class Element {
2165
2183
  }
2166
2184
 
2167
2185
  /**
2168
- * Gets a meta property, creating it with default value if not present.
2186
+ * Gets a meta property.
2187
+ *
2188
+ * When the property doesn't exist:
2189
+ * - With defaultValue: returns a new refracted element instance (not cached)
2190
+ * - Without defaultValue: returns undefined
2191
+ *
2192
+ * Note: Each call with a default creates a new instance. Use setMetaProperty
2193
+ * first if you need reference equality across multiple accesses.
2169
2194
  */
2195
+
2170
2196
  getMetaProperty(name, defaultValue) {
2171
- if (!this.meta.hasKey(name)) {
2172
- if (this.isFrozen) {
2173
- const element = this.refract(defaultValue);
2197
+ if (!this.hasMetaProperty(name)) {
2198
+ if (defaultValue === undefined) {
2199
+ return undefined;
2200
+ }
2201
+ const element = this.refract(defaultValue);
2202
+ if (element && this.isFrozen) {
2174
2203
  element.freeze();
2175
- return element;
2176
2204
  }
2177
- this.meta.set(name, defaultValue);
2205
+ return element;
2178
2206
  }
2179
2207
  return this.meta.get(name);
2180
2208
  }
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.apidomDatamodel=t():e.apidomDatamodel=t()}(self,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function r(e){return function t(r){return 0===arguments.length||n(r)?t:e.apply(this,arguments)}}function s(e){return function t(s,i){switch(arguments.length){case 0:return t;case 1:return n(s)?t:r(function(t){return e(s,t)});default:return n(s)&&n(i)?t:n(s)?r(function(t){return e(t,i)}):n(i)?r(function(t){return e(s,t)}):e(s,i)}}}function i(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}function o(e,t,n){for(var r=0,s=n.length;r<s;){if(e(t,n[r]))return!0;r+=1}return!1}function a(e,t){return Object.prototype.hasOwnProperty.call(t,e)}e.r(t),e.d(t,{AnnotationElement:()=>ke,ArrayElement:()=>I,BooleanElement:()=>L,CloneError:()=>fe,CollectionElement:()=>D,CommentElement:()=>Oe,DeepCloneError:()=>me,Element:()=>O,JSONSerialiser:()=>P,KeyValuePair:()=>E,LinkElement:()=>F,MemberElement:()=>K,Namespace:()=>Q,NullElement:()=>x,NumberElement:()=>z,ObjectElement:()=>R,ObjectSlice:()=>w,ParseResultElement:()=>je,RefElement:()=>N,ShallowCloneError:()=>pe,SourceMapElement:()=>C,StringElement:()=>j,cloneDeep:()=>be,cloneShallow:()=>Ee,hasElementSourceMap:()=>se,includesClasses:()=>oe,includesSymbols:()=>ie,isAnnotationElement:()=>Se,isArrayElement:()=>ee,isBooleanElement:()=>Z,isCommentElement:()=>Ve,isElement:()=>$,isLinkElement:()=>Ae,isMemberElement:()=>ne,isNullElement:()=>Y,isNumberElement:()=>X,isObjectElement:()=>te,isParseResultElement:()=>Ce,isPrimitiveElement:()=>re,isRefElement:()=>Me,isSourceMapElement:()=>Pe,isStringElement:()=>H,refract:()=>we});const c="function"==typeof Object.is?Object.is:function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t};var u=Object.prototype.toString;const l=function(){return"[object Arguments]"===u.call(arguments)?function(e){return"[object Arguments]"===u.call(e)}:function(e){return a("callee",e)}}();var h=!{toString:null}.propertyIsEnumerable("toString"),f=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],m=function(){return arguments.propertyIsEnumerable("length")}(),p=function(e,t){for(var n=0;n<e.length;){if(e[n]===t)return!0;n+=1}return!1};const y="function"!=typeof Object.keys||m?r(function(e){if(Object(e)!==e)return[];var t,n,r=[],s=m&&l(e);for(t in e)!a(t,e)||s&&"length"===t||(r[r.length]=t);if(h)for(n=f.length-1;n>=0;)a(t=f[n],e)&&!p(r,t)&&(r[r.length]=t),n-=1;return r}):r(function(e){return Object(e)!==e?[]:Object.keys(e)});const d=r(function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)});function b(e,t,n,r){var s=i(e);function a(e,t){return g(e,t,n.slice(),r.slice())}return!o(function(e,t){return!o(a,t,e)},i(t),s)}function g(e,t,n,r){if(c(e,t))return!0;var s,i,o=d(e);if(o!==d(t))return!1;if("function"==typeof e["fantasy-land/equals"]||"function"==typeof t["fantasy-land/equals"])return"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t)&&"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e);if("function"==typeof e.equals||"function"==typeof t.equals)return"function"==typeof e.equals&&e.equals(t)&&"function"==typeof t.equals&&t.equals(e);switch(o){case"Arguments":case"Array":case"Object":if("function"==typeof e.constructor&&"Promise"===(s=e.constructor,null==(i=String(s).match(/^function (\w*)/))?"":i[1]))return e===t;break;case"Boolean":case"Number":case"String":if(typeof e!=typeof t||!c(e.valueOf(),t.valueOf()))return!1;break;case"Date":if(!c(e.valueOf(),t.valueOf()))return!1;break;case"Error":return e.name===t.name&&e.message===t.message;case"RegExp":if(e.source!==t.source||e.global!==t.global||e.ignoreCase!==t.ignoreCase||e.multiline!==t.multiline||e.sticky!==t.sticky||e.unicode!==t.unicode)return!1}for(var u=n.length-1;u>=0;){if(n[u]===e)return r[u]===t;u-=1}switch(o){case"Map":return e.size===t.size&&b(e.entries(),t.entries(),n.concat([e]),r.concat([t]));case"Set":return e.size===t.size&&b(e.values(),t.values(),n.concat([e]),r.concat([t]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var l=y(e);if(l.length!==y(t).length)return!1;var h=n.concat([e]),f=r.concat([t]);for(u=l.length-1;u>=0;){var m=l[u];if(!a(m,t)||!g(t[m],e[m],h,f))return!1;u-=1}return!0}const v=s(function(e,t){return g(e,t,[],[])});const E=class{key;value;constructor(e,t){this.key=e,this.value=t}toValue(){return{key:this.key?.toValue(),value:this.value?.toValue()}}};class _{elements;constructor(e){this.elements=e??[]}toValue(){return this.elements.map(e=>({key:e.key?.toValue(),value:e.value?.toValue()}))}map(e,t){return this.elements.map(n=>{const r=n.value,s=n.key;if(void 0===r||void 0===s)throw new Error("MemberElement must have both key and value");return void 0!==t?e.call(t,r,s,n):e(r,s,n)})}filter(e,t){const n=this.elements.filter(n=>{const r=n.value,s=n.key;return void 0!==r&&void 0!==s&&(void 0!==t?e.call(t,r,s,n):e(r,s,n))});return new _(n)}reject(e,t){const n=[];for(const r of this.elements){const s=r.value,i=r.key;void 0!==s&&void 0!==i&&(e.call(t,s,i,r)||n.push(r))}return new _(n)}forEach(e,t){this.elements.forEach((n,r)=>{const s=n.value,i=n.key;void 0!==s&&void 0!==i&&(void 0!==t?e.call(t,s,i,n,r):e(s,i,n,r))})}find(e,t){return this.elements.find(n=>{const r=n.value,s=n.key;return void 0!==r&&void 0!==s&&(void 0!==t?e.call(t,r,s,n):e(r,s,n))})}keys(){return this.elements.map(e=>e.key?.toValue()).filter(e=>void 0!==e)}values(){return this.elements.map(e=>e.value?.toValue()).filter(e=>void 0!==e)}get length(){return this.elements.length}get isEmpty(){return 0===this.length}get first(){return this.elements[0]}get(e){return this.elements[e]}push(e){return this.elements.push(e),this}includesKey(e){return this.elements.some(t=>t.key?.equals(e))}[Symbol.iterator](){return this.elements[Symbol.iterator]()}}const w=_;class k{parent;startLine;startCharacter;startOffset;endLine;endCharacter;endOffset;_storedElement="element";_content;_meta;_attributes;constructor(e,t,n){void 0!==t&&(this.meta=t),void 0!==n&&(this.attributes=n),void 0!==e&&(this.content=e)}get element(){return this._storedElement}set element(e){this._storedElement=e}get content(){return this._content}set content(e){if(e instanceof k)this._content=e;else if(null!=e&&"string"!=typeof e&&"number"!=typeof e&&"boolean"!=typeof e&&"bigint"!=typeof e&&"symbol"!=typeof e)if(e instanceof E)this._content=e;else if(e instanceof w)this._content=e.elements;else if(Array.isArray(e))this._content=e.map(e=>this.refract(e));else{if("object"!=typeof e)throw new Error("Cannot set content to value of type "+typeof e);this._content=Object.entries(e).map(([e,t])=>new this.MemberElement(e,t))}else this._content=e}get meta(){if(!this._meta){if(this.isFrozen){const e=new this.ObjectElement;return e.freeze(),e}this._meta=new this.ObjectElement}return this._meta}set meta(e){e instanceof k?this._meta=e:this.meta.set(e??{})}get attributes(){if(!this._attributes){if(this.isFrozen){const e=new this.ObjectElement;return e.freeze(),e}this._attributes=new this.ObjectElement}return this._attributes}set attributes(e){e instanceof k?this._attributes=e:this.attributes.set(e??{})}get id(){return this.getMetaProperty("id","")}set id(e){this.setMetaProperty("id",e)}get classes(){return this.getMetaProperty("classes",[])}set classes(e){this.setMetaProperty("classes",e)}get links(){return this.getMetaProperty("links",[])}set links(e){this.setMetaProperty("links",e)}get children(){const{_content:e}=this;if(Array.isArray(e))return e;if(e instanceof E){const t=[];return e.key&&t.push(e.key),e.value&&t.push(e.value),t}return e instanceof k?[e]:[]}get isFrozen(){return Object.isFrozen(this)}freeze(){if(!this.isFrozen){this._meta&&(this._meta.parent=this,this._meta.freeze()),this._attributes&&(this._attributes.parent=this,this._attributes.freeze());for(const e of this.children)e.parent=this,e.freeze();Array.isArray(this._content)&&Object.freeze(this._content),Object.freeze(this)}}toValue(){const{_content:e}=this;return e instanceof k||e instanceof E?e.toValue():Array.isArray(e)?e.map(e=>e.toValue()):e}equals(e){const t=e instanceof k?e.toValue():e;return v(this.toValue(),t)}primitive(){}set(e){return this.content=e,this}toRef(e){const t=this.id.toValue();if(""===t)throw new Error("Cannot create reference to an element without an ID");const n=new this.RefElement(t);return"string"==typeof e&&(n.path=this.refract(e)),n}getMetaProperty(e,t){if(!this.meta.hasKey(e)){if(this.isFrozen){const e=this.refract(t);return e.freeze(),e}this.meta.set(e,t)}return this.meta.get(e)}setMetaProperty(e,t){this.meta.set(e,t)}hasMetaProperty(e){return!this.isMetaEmpty&&this.meta.hasKey(e)}get isMetaEmpty(){return void 0===this._meta||this.meta.isEmpty}getAttributesProperty(e,t){if(!this.hasAttributesProperty(e)){if(this.isFrozen){const e=this.refract(t);return e.freeze(),e}this.attributes.set(e,t)}return this.attributes.get(e)}setAttributesProperty(e,t){this.attributes.set(e,t)}hasAttributesProperty(e){return!this.isAttributesEmpty&&this.attributes.hasKey(e)}get isAttributesEmpty(){return void 0===this._attributes||this.attributes.isEmpty}}const O=k;const j=class extends O{constructor(e,t,n){super(e,t,n),this.element="string"}primitive(){return"string"}get length(){return this.content?.length??0}};class A extends j{constructor(e,t,n){super(e,t,n),this.element="sourceMap"}static transfer(e,t){t.startLine=e.startLine,t.startCharacter=e.startCharacter,t.startOffset=e.startOffset,t.endLine=e.endLine,t.endCharacter=e.endCharacter,t.endOffset=e.endOffset}static from(e){const{startLine:t,startCharacter:n,startOffset:r,endLine:s,endCharacter:i,endOffset:o}=e;if("number"!=typeof t||"number"!=typeof n||"number"!=typeof r||"number"!=typeof s||"number"!=typeof i||"number"!=typeof o)return;const a="sm1:"+[t,n,r,s,i,o].map(S).join("");const c=new A(a);return c.startLine=t,c.startCharacter=n,c.startOffset=r,c.endLine=s,c.endCharacter=i,c.endOffset=o,c}applyTo(e){this.content&&([e.startLine,e.startCharacter,e.startOffset,e.endLine,e.endCharacter,e.endOffset]=function(e){const t=e.startsWith("sm1:")?e.slice(4):e,n=[];let r=0;for(let e=0;e<6;e++){const e=V(t,r);n.push(e.value),r=e.next}return n}(this.content))}}const M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function S(e){let t=e>>>0,n="";do{let e=31&t;t>>>=5,0!==t&&(e|=32),n+=M[e]}while(0!==t);return n}function V(e,t=0){let n=0,r=0,s=t;for(;;){const t=e[s++],i=M.indexOf(t);if(-1===i)throw new Error(`Invalid Base64 VLQ char: ${t}`);if(n|=(31&i)<<r,r+=5,!!!(32&i))break}return{value:n>>>0,next:s}}const C=A;const P=class{namespace;constructor(e){this.namespace=e||new this.Namespace}serialise(e){if(!(e instanceof this.namespace.elements.Element))throw new TypeError(`Given element \`${e}\` is not an Element instance`);const t={element:e.element};if(e.isMetaEmpty||(t.meta=this.serialiseObject(e.meta)),e.isAttributesEmpty||(t.attributes=this.serialiseObject(e.attributes)),!(e instanceof C)){const n=C.from(e);n&&(t.meta||(t.meta={}),t.meta.__mappings__=this.serialise(n))}const n=this.serialiseContent(e.content);return void 0!==n&&(t.content=n),t}deserialise(e){if(!e.element)throw new Error("Given value is not an object containing an element name");const t=new(this.namespace.getElementClass(e.element));let n;t.element!==e.element&&(t.element=e.element);let r=e.meta;if(e.meta?.__mappings__){const{__mappings__:t,...s}=e.meta;n=t,r=Object.keys(s).length>0?s:void 0}if(r&&this.deserialiseObject(r,t.meta),n){this.deserialise(n).applyTo(t)}e.attributes&&this.deserialiseObject(e.attributes,t.attributes);const s=this.deserialiseContent(e.content);return void 0===s&&null!==t.content||(t.content=s),t}serialiseContent(e){if(e instanceof this.namespace.elements.Element)return this.serialise(e);if(e instanceof this.namespace.KeyValuePair){const t=e,n={key:this.serialise(t.key)};return t.value&&(n.value=this.serialise(t.value)),n}if(e&&Array.isArray(e)){if(0===e.length)return;return e.map(e=>this.serialise(e))}return e}deserialiseContent(e){if(e){if(e.element)return this.deserialise(e);if(e.key){const t=new this.namespace.KeyValuePair(this.deserialise(e.key));return e.value&&(t.value=this.deserialise(e.value)),t}if(Array.isArray(e))return e.map(e=>this.deserialise(e))}return e}serialiseObject(e){const t={};if(e.forEach((e,n)=>{e&&(t[n.toValue()]=this.serialise(e))}),0!==Object.keys(t).length)return t}deserialiseObject(e,t){Object.keys(e).forEach(n=>{t.set(n,this.deserialise(e[n]))})}};const x=class extends O{constructor(e,t,n){super(e??null,t,n),this.element="null"}primitive(){return"null"}set(e){throw new Error("Cannot set the value of null")}};const z=class extends O{constructor(e,t,n){super(e,t,n),this.element="number"}primitive(){return"number"}};const L=class extends O{constructor(e,t,n){super(e,t,n),this.element="boolean"}primitive(){return"boolean"}};class q extends O{constructor(e,t,n){super(e||[],t,n)}get length(){return this._content.length}get isEmpty(){return 0===this.length}get first(){return this._content[0]}get second(){return this._content[1]}get last(){return this._content.at(-1)}push(...e){for(const t of e)this._content.push(this.refract(t));return this}shift(){return this._content.shift()}unshift(e){this._content.unshift(this.refract(e))}includes(e){return this._content.some(t=>t.equals(e))}findElements(e,t){const n=t||{},r=!!n.recursive,s=void 0===n.results?[]:n.results;for(let t=0;t<this._content.length;t+=1){const n=this._content[t],i=n;r&&"function"==typeof i.findElements&&i.findElements(e,{results:s,recursive:r}),e(n,t,void 0)&&s.push(n)}return s}find(e){const t=this.findElements(e,{recursive:!0});return new this.ArrayElement(t)}findByElement(e){return this.find(t=>t.element===e)}findByClass(e){return this.find(t=>{const n=t.classes;return"function"==typeof n.includes&&n.includes(e)})}getById(e){return this.find(t=>t.id.toValue()===e).first}concat(e){return new(0,this.constructor)(this._content.concat(e._content))}[Symbol.iterator](){return this._content[Symbol.iterator]()}}const D=q;const I=class extends D{constructor(e,t,n){super(e||[],t,n),this.element="array"}primitive(){return"array"}get(e){return this._content[e]}getValue(e){const t=this.get(e);if(t)return t.toValue()}set(e,t){return"number"==typeof e&&void 0!==t?this._content[e]=this.refract(t):this.content=e,this}remove(e){return this._content.splice(e,1)[0]??null}map(e,t){return this._content.map(e,t)}flatMap(e,t){return this._content.flatMap(e,t)}compactMap(e,t){const n=[];for(const r of this._content){const s=e.call(t,r);s&&n.push(s)}return n}filter(e,t){const n=this._content.filter(e,t);return new this.constructor(n)}reject(e,t){const n=[];for(const r of this._content)e.call(t,r)||n.push(r);return new this.constructor(n)}reduce(e,t){let n,r;void 0!==t?(n=0,r=this.refract(t)):(n=1,r=this.first);for(let t=n;t<this.length;t+=1){const n=e(r,this._content[t],t,this);r=void 0===n?n:this.refract(n)}return r}forEach(e,t){this._content.forEach((n,r)=>{e.call(t,n,r)})}empty(){return new this.constructor([])}};const K=class extends O{constructor(e,t,n,r){super(new E,n,r),this.element="member",void 0!==e&&(this.key=e),arguments.length>=2&&(this.value=t)}primitive(){return"member"}get key(){return this._content.key}set key(e){this._content.key=this.refract(e)}get value(){return this._content.value}set value(e){this._content.value=void 0===e?void 0:this.refract(e)}};const R=class extends D{constructor(e,t,n){super(e||[],t,n),this.element="object"}primitive(){return"object"}toValue(){return this._content.reduce((e,t)=>(e[t.key.toValue()]=t.value?t.value.toValue():void 0,e),{})}get(e){const t=this.getMember(e);if(t)return t.value}getValue(e){const t=this.get(e);if(t)return t.toValue()}getMember(e){if(void 0!==e)return this._content.find(t=>t.key.toValue()===e)}remove(e){let t=null;return this.content=this._content.filter(n=>n.key.toValue()!==e||(t=n,!1)),t}getKey(e){const t=this.getMember(e);if(t)return t.key}set(e,t){if("string"==typeof e){const n=this.getMember(e);n?n.value=t:this._content.push(new K(e,t))}else if("object"==typeof e&&!Array.isArray(e))for(const t of Object.keys(e))this.set(t,e[t]);return this}keys(){return this._content.map(e=>e.key.toValue())}values(){return this._content.map(e=>e.value.toValue())}hasKey(e){return this._content.some(t=>t.key.equals(e))}items(){return this._content.map(e=>[e.key.toValue(),e.value.toValue()])}map(e,t){return this._content.map(n=>e.call(t,n.value,n.key,n))}compactMap(e,t){const n=[];return this.forEach((r,s,i)=>{const o=e.call(t,r,s,i);o&&n.push(o)}),n}filter(e,t){return new w(this._content).filter(e,t)}reject(e,t){const n=[];for(const r of this._content)e.call(t,r.value,r.key,r)||n.push(r);return new w(n)}forEach(e,t){this._content.forEach(n=>e.call(t,n.value,n.key,n))}reduce(e,t){let n,r;void 0!==t?(n=0,r=this.refract(t)):(n=1,r=this._content[0]?.value);for(let t=n;t<this._content.length;t+=1){const n=this._content[t],s=e(r,n.value,n.key,n,this);r=void 0===s?s:this.refract(s)}return r}empty(){return new this.constructor([])}};const N=class extends O{constructor(e,t,n){super(e||[],t,n),this.element="ref",this.path||(this.path="element")}get path(){if(this.hasAttributesProperty("path"))return this.attributes.get("path")}set path(e){this.attributes.set("path",e)}};const F=class extends O{constructor(e,t,n){super(e||[],t,n),this.element="link"}get relation(){if(this.hasAttributesProperty("relation"))return this.attributes.get("relation")}set relation(e){this.attributes.set("relation",e)}get href(){if(this.hasAttributesProperty("href"))return this.attributes.get("href")}set href(e){this.attributes.set("href",e)}},B=e=>null===e,T=e=>"string"==typeof e,U=e=>"number"==typeof e,W=e=>"boolean"==typeof e,G=e=>null!==e&&"object"==typeof e;class J{elementMap={};elementDetection=[];Element;KeyValuePair;_elements;_attributeElementKeys=[];_attributeElementArrayKeys=[];constructor(e){this.Element=O,this.KeyValuePair=E,e&&e.noDefault||this.useDefault()}use(e){return e.namespace&&e.namespace({base:this}),e.load&&e.load({base:this}),this}useDefault(){return this.register("null",x).register("string",j).register("number",z).register("boolean",L).register("array",I).register("object",R).register("member",K).register("ref",N).register("link",F).register("sourceMap",C),this.detect(B,x,!1).detect(T,j,!1).detect(U,z,!1).detect(W,L,!1).detect(Array.isArray,I,!1).detect(G,R,!1),this}register(e,t){return this._elements=void 0,this.elementMap[e]=t,this}unregister(e){return this._elements=void 0,delete this.elementMap[e],this}detect(e,t,n){return void 0===n||n?this.elementDetection.unshift([e,t]):this.elementDetection.push([e,t]),this}toElement(e){if(e instanceof this.Element)return e;let t;for(const[n,r]of this.elementDetection)if(n(e)){t=new r(e);break}return t}getElementClass(e){const t=this.elementMap[e];return void 0===t?this.Element:t}fromRefract(e){return this.serialiser.deserialise(e)}toRefract(e){return this.serialiser.serialise(e)}get elements(){return void 0===this._elements&&(this._elements={Element:this.Element},Object.keys(this.elementMap).forEach(e=>{const t=e[0].toUpperCase()+e.substring(1);this._elements[t]=this.elementMap[e]})),this._elements}get serialiser(){return new P(this)}}P.prototype.Namespace=J;const Q=J,$=e=>e instanceof O,H=e=>e instanceof j,X=e=>e instanceof z,Y=e=>e instanceof x,Z=e=>e instanceof L,ee=e=>e instanceof I,te=e=>e instanceof R,ne=e=>e instanceof K,re=e=>te(e)&&"object"===e.element||ee(e)&&"array"===e.element||Z(e)&&"boolean"===e.element||X(e)&&"number"===e.element||H(e)&&"string"===e.element||Y(e)&&"null"===e.element||ne(e)&&"member"===e.element,se=e=>"number"==typeof e.startLine&&"number"==typeof e.startCharacter&&"number"==typeof e.startOffset&&"number"==typeof e.endLine&&"number"==typeof e.endCharacter&&"number"==typeof e.endOffset,ie=(e,t)=>{if(0===t.length)return!0;if(!e.hasAttributesProperty("symbols"))return!1;const n=e.attributes.get("symbols");return!!ee(n)&&t.every(e=>n.includes(e))},oe=(e,t)=>0===t.length||!!$(e)&&(!e.isMetaEmpty&&(!!e.hasMetaProperty("classes")&&t.every(t=>e.classes.includes(t))));class ae extends AggregateError{constructor(e,t,n){super(e,t,n),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const ce=ae;class ue extends Error{static[Symbol.hasInstance](e){return super[Symbol.hasInstance](e)||Function.prototype[Symbol.hasInstance].call(ce,e)}constructor(e,t){super(e,t),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const le=ue;const he=class extends le{constructor(e,t){if(super(e,t),null!=t&&"object"==typeof t){const{cause:e,...n}=t;Object.assign(this,n)}}};const fe=class extends he{value;constructor(e,t){super(e,t),void 0!==t&&(this.value=t.value)}};const me=class extends fe{};const pe=class extends fe{},ye=(e,t)=>{const{visited:n=new WeakMap}=t,r={...t,visited:n};if(n.has(e))return n.get(e);const s=ve(e);n.set(e,s);const{content:i}=e;return Array.isArray(i)?s.content=i.map(e=>ye(e,r)):$(i)?s.content=ye(i,r):s.content=i instanceof E?de(i,r):i,s},de=(e,t)=>{const{visited:n=new WeakMap}=t,r={...t,visited:n};if(n.has(e))return n.get(e);const{key:s,value:i}=e,o=void 0!==s?ye(s,r):void 0,a=void 0!==i?ye(i,r):void 0,c=new E(o,a);return n.set(e,c),c},be=(e,t={})=>{if(e instanceof E)return de(e,t);if(e instanceof w)return((e,t)=>{const{visited:n=new WeakMap}=t,r={...t,visited:n};if(n.has(e))return n.get(e);const s=[...e].map(e=>ye(e,r)),i=new w(s);return n.set(e,i),i})(e,t);if($(e))return ye(e,t);throw new me("Value provided to cloneDeep function couldn't be cloned",{value:e})};be.safe=e=>{try{return be(e)}catch{return e}};const ge=e=>{const{key:t,value:n}=e;return new E(t,n)},ve=e=>{const t=new(0,e.constructor);t.element=e.element,e.isMetaEmpty||(t.meta=be(e.meta)),e.isAttributesEmpty||(t.attributes=be(e.attributes)),se(e)&&C.transfer(e,t);const{content:n}=e;return $(n)?t.content=ve(n):Array.isArray(n)?t.content=[...n]:t.content=n instanceof E?ge(n):n,t},Ee=e=>{if(e instanceof E)return ge(e);if(e instanceof w)return(e=>{const t=[...e];return new w(t)})(e);if($(e))return ve(e);throw new pe("Value provided to cloneShallow function couldn't be cloned",{value:e})};function _e(e){return void 0===e?new x:we(e)}function we(e){if(e instanceof O)return e;if("string"==typeof e)return new j(e);if("number"==typeof e)return new z(e);if("boolean"==typeof e)return new L(e);if(null===e)return new x;if(Array.isArray(e))return new I(e.map(_e));if("object"==typeof e)return new R(e);throw new Error("Cannot refract value of type "+typeof e)}Ee.safe=e=>{try{return Ee(e)}catch{return e}},O.prototype.ObjectElement=R,O.prototype.ArrayElement=I,O.prototype.RefElement=N,O.prototype.MemberElement=K,O.prototype.refract=we;const ke=class extends j{constructor(e,t,n){super(e,t,n),this.element="annotation"}get code(){if(this.hasAttributesProperty("code"))return this.attributes.get("code")}set code(e){this.attributes.set("code",e)}};const Oe=class extends j{constructor(e,t,n){super(e,t,n),this.element="comment"}};const je=class extends I{constructor(e,t,n){super(e,t,n),this.element="parseResult"}get api(){return this.filter(e=>oe(e,["api"])).first}get results(){return this.filter(e=>oe(e,["result"]))}get result(){return this.results.first}get annotations(){return this.filter(e=>"annotation"===e.element)}get warnings(){return this.filter(e=>"annotation"===e.element&&oe(e,["warning"]))}get errors(){return this.filter(e=>"annotation"===e.element&&oe(e,["error"]))}get isEmpty(){return 0===this.reject(e=>"annotation"===e.element).length}replaceResult(e){const{result:t}=this;if(void 0===t)return!1;const n=this._content,r=n.findIndex(e=>e===t);return-1!==r&&(n[r]=e,!0)}},Ae=e=>e instanceof F,Me=e=>e instanceof N,Se=e=>e instanceof ke,Ve=e=>e instanceof Oe,Ce=e=>e instanceof je,Pe=e=>e instanceof C;return t})());
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.apidomDatamodel=t():e.apidomDatamodel=t()}(self,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function r(e){return function t(r){return 0===arguments.length||n(r)?t:e.apply(this,arguments)}}function s(e){return function t(s,i){switch(arguments.length){case 0:return t;case 1:return n(s)?t:r(function(t){return e(s,t)});default:return n(s)&&n(i)?t:n(s)?r(function(t){return e(t,i)}):n(i)?r(function(t){return e(s,t)}):e(s,i)}}}function i(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}function o(e,t,n){for(var r=0,s=n.length;r<s;){if(e(t,n[r]))return!0;r+=1}return!1}function a(e,t){return Object.prototype.hasOwnProperty.call(t,e)}e.r(t),e.d(t,{AnnotationElement:()=>we,ArrayElement:()=>F,BooleanElement:()=>L,CloneError:()=>fe,CollectionElement:()=>D,CommentElement:()=>Oe,DeepCloneError:()=>me,Element:()=>O,JSONSerialiser:()=>C,KeyValuePair:()=>E,LinkElement:()=>N,MemberElement:()=>I,Namespace:()=>Q,NullElement:()=>x,NumberElement:()=>z,ObjectElement:()=>R,ObjectSlice:()=>k,ParseResultElement:()=>je,RefElement:()=>K,ShallowCloneError:()=>pe,SourceMapElement:()=>V,StringElement:()=>j,cloneDeep:()=>be,cloneShallow:()=>Ee,hasElementSourceMap:()=>se,includesClasses:()=>oe,includesSymbols:()=>ie,isAnnotationElement:()=>Pe,isArrayElement:()=>ee,isBooleanElement:()=>Z,isCommentElement:()=>Se,isElement:()=>$,isLinkElement:()=>Ae,isMemberElement:()=>ne,isNullElement:()=>Y,isNumberElement:()=>X,isObjectElement:()=>te,isParseResultElement:()=>Ve,isPrimitiveElement:()=>re,isRefElement:()=>Me,isSourceMapElement:()=>Ce,isStringElement:()=>H,refract:()=>ke});const c="function"==typeof Object.is?Object.is:function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t};var u=Object.prototype.toString;const l=function(){return"[object Arguments]"===u.call(arguments)?function(e){return"[object Arguments]"===u.call(e)}:function(e){return a("callee",e)}}();var h=!{toString:null}.propertyIsEnumerable("toString"),f=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],m=function(){return arguments.propertyIsEnumerable("length")}(),p=function(e,t){for(var n=0;n<e.length;){if(e[n]===t)return!0;n+=1}return!1};const y="function"!=typeof Object.keys||m?r(function(e){if(Object(e)!==e)return[];var t,n,r=[],s=m&&l(e);for(t in e)!a(t,e)||s&&"length"===t||(r[r.length]=t);if(h)for(n=f.length-1;n>=0;)a(t=f[n],e)&&!p(r,t)&&(r[r.length]=t),n-=1;return r}):r(function(e){return Object(e)!==e?[]:Object.keys(e)});const d=r(function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)});function b(e,t,n,r){var s=i(e);function a(e,t){return g(e,t,n.slice(),r.slice())}return!o(function(e,t){return!o(a,t,e)},i(t),s)}function g(e,t,n,r){if(c(e,t))return!0;var s,i,o=d(e);if(o!==d(t))return!1;if("function"==typeof e["fantasy-land/equals"]||"function"==typeof t["fantasy-land/equals"])return"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t)&&"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e);if("function"==typeof e.equals||"function"==typeof t.equals)return"function"==typeof e.equals&&e.equals(t)&&"function"==typeof t.equals&&t.equals(e);switch(o){case"Arguments":case"Array":case"Object":if("function"==typeof e.constructor&&"Promise"===(s=e.constructor,null==(i=String(s).match(/^function (\w*)/))?"":i[1]))return e===t;break;case"Boolean":case"Number":case"String":if(typeof e!=typeof t||!c(e.valueOf(),t.valueOf()))return!1;break;case"Date":if(!c(e.valueOf(),t.valueOf()))return!1;break;case"Error":return e.name===t.name&&e.message===t.message;case"RegExp":if(e.source!==t.source||e.global!==t.global||e.ignoreCase!==t.ignoreCase||e.multiline!==t.multiline||e.sticky!==t.sticky||e.unicode!==t.unicode)return!1}for(var u=n.length-1;u>=0;){if(n[u]===e)return r[u]===t;u-=1}switch(o){case"Map":return e.size===t.size&&b(e.entries(),t.entries(),n.concat([e]),r.concat([t]));case"Set":return e.size===t.size&&b(e.values(),t.values(),n.concat([e]),r.concat([t]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var l=y(e);if(l.length!==y(t).length)return!1;var h=n.concat([e]),f=r.concat([t]);for(u=l.length-1;u>=0;){var m=l[u];if(!a(m,t)||!g(t[m],e[m],h,f))return!1;u-=1}return!0}const v=s(function(e,t){return g(e,t,[],[])});const E=class{key;value;constructor(e,t){this.key=e,this.value=t}toValue(){return{key:this.key?.toValue(),value:this.value?.toValue()}}};class _{elements;constructor(e){this.elements=e??[]}toValue(){return this.elements.map(e=>({key:e.key?.toValue(),value:e.value?.toValue()}))}map(e,t){return this.elements.map(n=>{const r=n.value,s=n.key;if(void 0===r||void 0===s)throw new Error("MemberElement must have both key and value");return void 0!==t?e.call(t,r,s,n):e(r,s,n)})}filter(e,t){const n=this.elements.filter(n=>{const r=n.value,s=n.key;return void 0!==r&&void 0!==s&&(void 0!==t?e.call(t,r,s,n):e(r,s,n))});return new _(n)}reject(e,t){const n=[];for(const r of this.elements){const s=r.value,i=r.key;void 0!==s&&void 0!==i&&(e.call(t,s,i,r)||n.push(r))}return new _(n)}forEach(e,t){this.elements.forEach((n,r)=>{const s=n.value,i=n.key;void 0!==s&&void 0!==i&&(void 0!==t?e.call(t,s,i,n,r):e(s,i,n,r))})}find(e,t){return this.elements.find(n=>{const r=n.value,s=n.key;return void 0!==r&&void 0!==s&&(void 0!==t?e.call(t,r,s,n):e(r,s,n))})}keys(){return this.elements.map(e=>e.key?.toValue()).filter(e=>void 0!==e)}values(){return this.elements.map(e=>e.value?.toValue()).filter(e=>void 0!==e)}get length(){return this.elements.length}get isEmpty(){return 0===this.length}get first(){return this.elements[0]}get(e){return this.elements[e]}push(e){return this.elements.push(e),this}includesKey(e){return this.elements.some(t=>t.key?.equals(e))}[Symbol.iterator](){return this.elements[Symbol.iterator]()}}const k=_;class w{parent;startLine;startCharacter;startOffset;endLine;endCharacter;endOffset;_storedElement="element";_content;_meta;_attributes;constructor(e,t,n){void 0!==t&&(this.meta=t),void 0!==n&&(this.attributes=n),void 0!==e&&(this.content=e)}get element(){return this._storedElement}set element(e){this._storedElement=e}get content(){return this._content}set content(e){if(e instanceof w)this._content=e;else if(null!=e&&"string"!=typeof e&&"number"!=typeof e&&"boolean"!=typeof e&&"bigint"!=typeof e&&"symbol"!=typeof e)if(e instanceof E)this._content=e;else if(e instanceof k)this._content=e.elements;else if(Array.isArray(e))this._content=e.map(e=>this.refract(e));else{if("object"!=typeof e)throw new Error("Cannot set content to value of type "+typeof e);this._content=Object.entries(e).map(([e,t])=>new this.MemberElement(e,t))}else this._content=e}get meta(){if(!this._meta){if(this.isFrozen){const e=new this.ObjectElement;return e.freeze(),e}this._meta=new this.ObjectElement}return this._meta}set meta(e){e instanceof w?this._meta=e:this.meta.set(e??{})}get attributes(){if(!this._attributes){if(this.isFrozen){const e=new this.ObjectElement;return e.freeze(),e}this._attributes=new this.ObjectElement}return this._attributes}set attributes(e){e instanceof w?this._attributes=e:this.attributes.set(e??{})}get id(){return this.isFrozen?this.getMetaProperty("id",""):(this.hasMetaProperty("id")||this.setMetaProperty("id",""),this.meta.get("id"))}set id(e){this.setMetaProperty("id",e)}get classes(){return this.isFrozen?this.getMetaProperty("classes",[]):(this.hasMetaProperty("classes")||this.setMetaProperty("classes",[]),this.meta.get("classes"))}set classes(e){this.setMetaProperty("classes",e)}get links(){return this.isFrozen?this.getMetaProperty("links",[]):(this.hasMetaProperty("links")||this.setMetaProperty("links",[]),this.meta.get("links"))}set links(e){this.setMetaProperty("links",e)}get children(){const{_content:e}=this;if(Array.isArray(e))return e;if(e instanceof E){const t=[];return e.key&&t.push(e.key),e.value&&t.push(e.value),t}return e instanceof w?[e]:[]}get isFrozen(){return Object.isFrozen(this)}freeze(){if(!this.isFrozen){this._meta&&(this._meta.parent=this,this._meta.freeze()),this._attributes&&(this._attributes.parent=this,this._attributes.freeze());for(const e of this.children)e.parent=this,e.freeze();Array.isArray(this._content)&&Object.freeze(this._content),Object.freeze(this)}}toValue(){const{_content:e}=this;return e instanceof w||e instanceof E?e.toValue():Array.isArray(e)?e.map(e=>e.toValue()):e}equals(e){const t=e instanceof w?e.toValue():e;return v(this.toValue(),t)}primitive(){}set(e){return this.content=e,this}toRef(e){const t=this.id.toValue();if(""===t)throw new Error("Cannot create reference to an element without an ID");const n=new this.RefElement(t);return"string"==typeof e&&(n.path=this.refract(e)),n}getMetaProperty(e,t){if(!this.hasMetaProperty(e)){if(void 0===t)return;const e=this.refract(t);return e&&this.isFrozen&&e.freeze(),e}return this.meta.get(e)}setMetaProperty(e,t){this.meta.set(e,t)}hasMetaProperty(e){return!this.isMetaEmpty&&this.meta.hasKey(e)}get isMetaEmpty(){return void 0===this._meta||this.meta.isEmpty}getAttributesProperty(e,t){if(!this.hasAttributesProperty(e)){if(this.isFrozen){const e=this.refract(t);return e.freeze(),e}this.attributes.set(e,t)}return this.attributes.get(e)}setAttributesProperty(e,t){this.attributes.set(e,t)}hasAttributesProperty(e){return!this.isAttributesEmpty&&this.attributes.hasKey(e)}get isAttributesEmpty(){return void 0===this._attributes||this.attributes.isEmpty}}const O=w;const j=class extends O{constructor(e,t,n){super(e,t,n),this.element="string"}primitive(){return"string"}get length(){return this.content?.length??0}};class A extends j{constructor(e,t,n){super(e,t,n),this.element="sourceMap"}static transfer(e,t){t.startLine=e.startLine,t.startCharacter=e.startCharacter,t.startOffset=e.startOffset,t.endLine=e.endLine,t.endCharacter=e.endCharacter,t.endOffset=e.endOffset}static from(e){const{startLine:t,startCharacter:n,startOffset:r,endLine:s,endCharacter:i,endOffset:o}=e;if("number"!=typeof t||"number"!=typeof n||"number"!=typeof r||"number"!=typeof s||"number"!=typeof i||"number"!=typeof o)return;const a="sm1:"+[t,n,r,s,i,o].map(P).join("");const c=new A(a);return c.startLine=t,c.startCharacter=n,c.startOffset=r,c.endLine=s,c.endCharacter=i,c.endOffset=o,c}applyTo(e){this.content&&([e.startLine,e.startCharacter,e.startOffset,e.endLine,e.endCharacter,e.endOffset]=function(e){const t=e.startsWith("sm1:")?e.slice(4):e,n=[];let r=0;for(let e=0;e<6;e++){const e=S(t,r);n.push(e.value),r=e.next}return n}(this.content))}}const M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function P(e){let t=e>>>0,n="";do{let e=31&t;t>>>=5,0!==t&&(e|=32),n+=M[e]}while(0!==t);return n}function S(e,t=0){let n=0,r=0,s=t;for(;;){const t=e[s++],i=M.indexOf(t);if(-1===i)throw new Error(`Invalid Base64 VLQ char: ${t}`);if(n|=(31&i)<<r,r+=5,!!!(32&i))break}return{value:n>>>0,next:s}}const V=A;const C=class{namespace;constructor(e){this.namespace=e||new this.Namespace}serialise(e){if(!(e instanceof this.namespace.elements.Element))throw new TypeError(`Given element \`${e}\` is not an Element instance`);const t={element:e.element};if(e.isMetaEmpty||(t.meta=this.serialiseObject(e.meta)),e.isAttributesEmpty||(t.attributes=this.serialiseObject(e.attributes)),!(e instanceof V)){const n=V.from(e);n&&(t.meta||(t.meta={}),t.meta.__mappings__=this.serialise(n))}const n=this.serialiseContent(e.content);return void 0!==n&&(t.content=n),t}deserialise(e){if(!e.element)throw new Error("Given value is not an object containing an element name");const t=new(this.namespace.getElementClass(e.element));let n;t.element!==e.element&&(t.element=e.element);let r=e.meta;if(e.meta?.__mappings__){const{__mappings__:t,...s}=e.meta;n=t,r=Object.keys(s).length>0?s:void 0}if(r&&this.deserialiseObject(r,t.meta),n){this.deserialise(n).applyTo(t)}e.attributes&&this.deserialiseObject(e.attributes,t.attributes);const s=this.deserialiseContent(e.content);return void 0===s&&null!==t.content||(t.content=s),t}serialiseContent(e){if(e instanceof this.namespace.elements.Element)return this.serialise(e);if(e instanceof this.namespace.KeyValuePair){const t=e,n={key:this.serialise(t.key)};return t.value&&(n.value=this.serialise(t.value)),n}if(e&&Array.isArray(e)){if(0===e.length)return;return e.map(e=>this.serialise(e))}return e}deserialiseContent(e){if(e){if(e.element)return this.deserialise(e);if(e.key){const t=new this.namespace.KeyValuePair(this.deserialise(e.key));return e.value&&(t.value=this.deserialise(e.value)),t}if(Array.isArray(e))return e.map(e=>this.deserialise(e))}return e}serialiseObject(e){const t={};if(e.forEach((e,n)=>{e&&(t[n.toValue()]=this.serialise(e))}),0!==Object.keys(t).length)return t}deserialiseObject(e,t){Object.keys(e).forEach(n=>{t.set(n,this.deserialise(e[n]))})}};const x=class extends O{constructor(e,t,n){super(e??null,t,n),this.element="null"}primitive(){return"null"}set(e){throw new Error("Cannot set the value of null")}};const z=class extends O{constructor(e,t,n){super(e,t,n),this.element="number"}primitive(){return"number"}};const L=class extends O{constructor(e,t,n){super(e,t,n),this.element="boolean"}primitive(){return"boolean"}};class q extends O{constructor(e,t,n){super(e||[],t,n)}get length(){return this._content.length}get isEmpty(){return 0===this.length}get first(){return this._content[0]}get second(){return this._content[1]}get last(){return this._content.at(-1)}push(...e){for(const t of e)this._content.push(this.refract(t));return this}shift(){return this._content.shift()}unshift(e){this._content.unshift(this.refract(e))}includes(e){return this._content.some(t=>t.equals(e))}findElements(e,t){const n=t||{},r=!!n.recursive,s=void 0===n.results?[]:n.results;for(let t=0;t<this._content.length;t+=1){const n=this._content[t],i=n;r&&"function"==typeof i.findElements&&i.findElements(e,{results:s,recursive:r}),e(n,t,void 0)&&s.push(n)}return s}find(e){const t=this.findElements(e,{recursive:!0});return new this.ArrayElement(t)}findByElement(e){return this.find(t=>t.element===e)}findByClass(e){return this.find(t=>{const n=t.classes;return"function"==typeof n.includes&&n.includes(e)})}getById(e){return this.find(t=>t.id.toValue()===e).first}concat(e){return new(0,this.constructor)(this._content.concat(e._content))}[Symbol.iterator](){return this._content[Symbol.iterator]()}}const D=q;const F=class extends D{constructor(e,t,n){super(e||[],t,n),this.element="array"}primitive(){return"array"}get(e){return this._content[e]}getValue(e){const t=this.get(e);if(t)return t.toValue()}set(e,t){return"number"==typeof e&&void 0!==t?this._content[e]=this.refract(t):this.content=e,this}remove(e){return this._content.splice(e,1)[0]??null}map(e,t){return this._content.map(e,t)}flatMap(e,t){return this._content.flatMap(e,t)}compactMap(e,t){const n=[];for(const r of this._content){const s=e.call(t,r);s&&n.push(s)}return n}filter(e,t){const n=this._content.filter(e,t);return new this.constructor(n)}reject(e,t){const n=[];for(const r of this._content)e.call(t,r)||n.push(r);return new this.constructor(n)}reduce(e,t){let n,r;void 0!==t?(n=0,r=this.refract(t)):(n=1,r=this.first);for(let t=n;t<this.length;t+=1){const n=e(r,this._content[t],t,this);r=void 0===n?n:this.refract(n)}return r}forEach(e,t){this._content.forEach((n,r)=>{e.call(t,n,r)})}empty(){return new this.constructor([])}};const I=class extends O{constructor(e,t,n,r){super(new E,n,r),this.element="member",void 0!==e&&(this.key=e),arguments.length>=2&&(this.value=t)}primitive(){return"member"}get key(){return this._content.key}set key(e){this._content.key=this.refract(e)}get value(){return this._content.value}set value(e){this._content.value=void 0===e?void 0:this.refract(e)}};const R=class extends D{constructor(e,t,n){super(e||[],t,n),this.element="object"}primitive(){return"object"}toValue(){return this._content.reduce((e,t)=>(e[t.key.toValue()]=t.value?t.value.toValue():void 0,e),{})}get(e){const t=this.getMember(e);if(t)return t.value}getValue(e){const t=this.get(e);if(t)return t.toValue()}getMember(e){if(void 0!==e)return this._content.find(t=>t.key.toValue()===e)}remove(e){let t=null;return this.content=this._content.filter(n=>n.key.toValue()!==e||(t=n,!1)),t}getKey(e){const t=this.getMember(e);if(t)return t.key}set(e,t){if("string"==typeof e){const n=this.getMember(e);n?n.value=t:this._content.push(new I(e,t))}else if("object"==typeof e&&!Array.isArray(e))for(const t of Object.keys(e))this.set(t,e[t]);return this}keys(){return this._content.map(e=>e.key.toValue())}values(){return this._content.map(e=>e.value.toValue())}hasKey(e){return this._content.some(t=>t.key.equals(e))}items(){return this._content.map(e=>[e.key.toValue(),e.value.toValue()])}map(e,t){return this._content.map(n=>e.call(t,n.value,n.key,n))}compactMap(e,t){const n=[];return this.forEach((r,s,i)=>{const o=e.call(t,r,s,i);o&&n.push(o)}),n}filter(e,t){return new k(this._content).filter(e,t)}reject(e,t){const n=[];for(const r of this._content)e.call(t,r.value,r.key,r)||n.push(r);return new k(n)}forEach(e,t){this._content.forEach(n=>e.call(t,n.value,n.key,n))}reduce(e,t){let n,r;void 0!==t?(n=0,r=this.refract(t)):(n=1,r=this._content[0]?.value);for(let t=n;t<this._content.length;t+=1){const n=this._content[t],s=e(r,n.value,n.key,n,this);r=void 0===s?s:this.refract(s)}return r}empty(){return new this.constructor([])}};const K=class extends O{constructor(e,t,n){super(e||[],t,n),this.element="ref",this.path||(this.path="element")}get path(){if(this.hasAttributesProperty("path"))return this.attributes.get("path")}set path(e){this.attributes.set("path",e)}};const N=class extends O{constructor(e,t,n){super(e||[],t,n),this.element="link"}get relation(){if(this.hasAttributesProperty("relation"))return this.attributes.get("relation")}set relation(e){this.attributes.set("relation",e)}get href(){if(this.hasAttributesProperty("href"))return this.attributes.get("href")}set href(e){this.attributes.set("href",e)}},B=e=>null===e,T=e=>"string"==typeof e,U=e=>"number"==typeof e,W=e=>"boolean"==typeof e,G=e=>null!==e&&"object"==typeof e;class J{elementMap={};elementDetection=[];Element;KeyValuePair;_elements;_attributeElementKeys=[];_attributeElementArrayKeys=[];constructor(e){this.Element=O,this.KeyValuePair=E,e&&e.noDefault||this.useDefault()}use(e){return e.namespace&&e.namespace({base:this}),e.load&&e.load({base:this}),this}useDefault(){return this.register("null",x).register("string",j).register("number",z).register("boolean",L).register("array",F).register("object",R).register("member",I).register("ref",K).register("link",N).register("sourceMap",V),this.detect(B,x,!1).detect(T,j,!1).detect(U,z,!1).detect(W,L,!1).detect(Array.isArray,F,!1).detect(G,R,!1),this}register(e,t){return this._elements=void 0,this.elementMap[e]=t,this}unregister(e){return this._elements=void 0,delete this.elementMap[e],this}detect(e,t,n){return void 0===n||n?this.elementDetection.unshift([e,t]):this.elementDetection.push([e,t]),this}toElement(e){if(e instanceof this.Element)return e;let t;for(const[n,r]of this.elementDetection)if(n(e)){t=new r(e);break}return t}getElementClass(e){const t=this.elementMap[e];return void 0===t?this.Element:t}fromRefract(e){return this.serialiser.deserialise(e)}toRefract(e){return this.serialiser.serialise(e)}get elements(){return void 0===this._elements&&(this._elements={Element:this.Element},Object.keys(this.elementMap).forEach(e=>{const t=e[0].toUpperCase()+e.substring(1);this._elements[t]=this.elementMap[e]})),this._elements}get serialiser(){return new C(this)}}C.prototype.Namespace=J;const Q=J,$=e=>e instanceof O,H=e=>e instanceof j,X=e=>e instanceof z,Y=e=>e instanceof x,Z=e=>e instanceof L,ee=e=>e instanceof F,te=e=>e instanceof R,ne=e=>e instanceof I,re=e=>te(e)&&"object"===e.element||ee(e)&&"array"===e.element||Z(e)&&"boolean"===e.element||X(e)&&"number"===e.element||H(e)&&"string"===e.element||Y(e)&&"null"===e.element||ne(e)&&"member"===e.element,se=e=>"number"==typeof e.startLine&&"number"==typeof e.startCharacter&&"number"==typeof e.startOffset&&"number"==typeof e.endLine&&"number"==typeof e.endCharacter&&"number"==typeof e.endOffset,ie=(e,t)=>{if(0===t.length)return!0;if(!e.hasAttributesProperty("symbols"))return!1;const n=e.attributes.get("symbols");return!!ee(n)&&t.every(e=>n.includes(e))},oe=(e,t)=>0===t.length||!!$(e)&&(!e.isMetaEmpty&&(!!e.hasMetaProperty("classes")&&t.every(t=>e.classes.includes(t))));class ae extends AggregateError{constructor(e,t,n){super(e,t,n),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const ce=ae;class ue extends Error{static[Symbol.hasInstance](e){return super[Symbol.hasInstance](e)||Function.prototype[Symbol.hasInstance].call(ce,e)}constructor(e,t){super(e,t),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const le=ue;const he=class extends le{constructor(e,t){if(super(e,t),null!=t&&"object"==typeof t){const{cause:e,...n}=t;Object.assign(this,n)}}};const fe=class extends he{value;constructor(e,t){super(e,t),void 0!==t&&(this.value=t.value)}};const me=class extends fe{};const pe=class extends fe{},ye=(e,t)=>{const{visited:n=new WeakMap}=t,r={...t,visited:n};if(n.has(e))return n.get(e);const s=ve(e);n.set(e,s);const{content:i}=e;return Array.isArray(i)?s.content=i.map(e=>ye(e,r)):$(i)?s.content=ye(i,r):s.content=i instanceof E?de(i,r):i,s},de=(e,t)=>{const{visited:n=new WeakMap}=t,r={...t,visited:n};if(n.has(e))return n.get(e);const{key:s,value:i}=e,o=void 0!==s?ye(s,r):void 0,a=void 0!==i?ye(i,r):void 0,c=new E(o,a);return n.set(e,c),c},be=(e,t={})=>{if(e instanceof E)return de(e,t);if(e instanceof k)return((e,t)=>{const{visited:n=new WeakMap}=t,r={...t,visited:n};if(n.has(e))return n.get(e);const s=[...e].map(e=>ye(e,r)),i=new k(s);return n.set(e,i),i})(e,t);if($(e))return ye(e,t);throw new me("Value provided to cloneDeep function couldn't be cloned",{value:e})};be.safe=e=>{try{return be(e)}catch{return e}};const ge=e=>{const{key:t,value:n}=e;return new E(t,n)},ve=e=>{const t=new(0,e.constructor);t.element=e.element,e.isMetaEmpty||(t.meta=be(e.meta)),e.isAttributesEmpty||(t.attributes=be(e.attributes)),se(e)&&V.transfer(e,t);const{content:n}=e;return $(n)?t.content=ve(n):Array.isArray(n)?t.content=[...n]:t.content=n instanceof E?ge(n):n,t},Ee=e=>{if(e instanceof E)return ge(e);if(e instanceof k)return(e=>{const t=[...e];return new k(t)})(e);if($(e))return ve(e);throw new pe("Value provided to cloneShallow function couldn't be cloned",{value:e})};function _e(e){return void 0===e?new x:ke(e)}function ke(e){if(e instanceof O)return e;if("string"==typeof e)return new j(e);if("number"==typeof e)return new z(e);if("boolean"==typeof e)return new L(e);if(null===e)return new x;if(Array.isArray(e))return new F(e.map(_e));if("object"==typeof e)return new R(e);throw new Error("Cannot refract value of type "+typeof e)}Ee.safe=e=>{try{return Ee(e)}catch{return e}},O.prototype.ObjectElement=R,O.prototype.ArrayElement=F,O.prototype.RefElement=K,O.prototype.MemberElement=I,O.prototype.refract=ke;const we=class extends j{constructor(e,t,n){super(e,t,n),this.element="annotation"}get code(){if(this.hasAttributesProperty("code"))return this.attributes.get("code")}set code(e){this.attributes.set("code",e)}};const Oe=class extends j{constructor(e,t,n){super(e,t,n),this.element="comment"}};const je=class extends F{constructor(e,t,n){super(e,t,n),this.element="parseResult"}get api(){return this.filter(e=>oe(e,["api"])).first}get results(){return this.filter(e=>oe(e,["result"]))}get result(){return this.results.first}get annotations(){return this.filter(e=>"annotation"===e.element)}get warnings(){return this.filter(e=>"annotation"===e.element&&oe(e,["warning"]))}get errors(){return this.filter(e=>"annotation"===e.element&&oe(e,["error"]))}get isEmpty(){return 0===this.reject(e=>"annotation"===e.element).length}replaceResult(e){const{result:t}=this;if(void 0===t)return!1;const n=this._content,r=n.findIndex(e=>e===t);return-1!==r&&(n[r]=e,!0)}},Ae=e=>e instanceof N,Me=e=>e instanceof K,Pe=e=>e instanceof we,Se=e=>e instanceof Oe,Ve=e=>e instanceof je,Ce=e=>e instanceof V;return t})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-datamodel",
3
- "version": "2.10.3",
3
+ "version": "2.11.0",
4
4
  "description": "Data model primitives for ApiDOM.",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -39,7 +39,7 @@
39
39
  "license": "Apache-2.0",
40
40
  "dependencies": {
41
41
  "@babel/runtime-corejs3": "^7.28.4",
42
- "@speclynx/apidom-error": "^2.10.3",
42
+ "@speclynx/apidom-error": "^2.11.0",
43
43
  "ramda": "~0.32.0"
44
44
  },
45
45
  "files": [
@@ -52,5 +52,5 @@
52
52
  "README.md",
53
53
  "CHANGELOG.md"
54
54
  ],
55
- "gitHead": "d4801d19a42266df43ce85d07990fbf25a1548ad"
55
+ "gitHead": "ee7e9488621be61f5dc1b098b8af135dc83c9ac1"
56
56
  }
@@ -240,7 +240,13 @@ class Element {
240
240
 
241
241
  /** Unique identifier for this element. */
242
242
  get id() {
243
- return this.getMetaProperty('id', '');
243
+ if (this.isFrozen) {
244
+ return this.getMetaProperty('id', '');
245
+ }
246
+ if (!this.hasMetaProperty('id')) {
247
+ this.setMetaProperty('id', '');
248
+ }
249
+ return this.meta.get('id');
244
250
  }
245
251
  set id(value) {
246
252
  this.setMetaProperty('id', value);
@@ -248,7 +254,13 @@ class Element {
248
254
 
249
255
  /** CSS-like class names. */
250
256
  get classes() {
251
- return this.getMetaProperty('classes', []);
257
+ if (this.isFrozen) {
258
+ return this.getMetaProperty('classes', []);
259
+ }
260
+ if (!this.hasMetaProperty('classes')) {
261
+ this.setMetaProperty('classes', []);
262
+ }
263
+ return this.meta.get('classes');
252
264
  }
253
265
  set classes(value) {
254
266
  this.setMetaProperty('classes', value);
@@ -256,7 +268,13 @@ class Element {
256
268
 
257
269
  /** Hyperlinks associated with this element. */
258
270
  get links() {
259
- return this.getMetaProperty('links', []);
271
+ if (this.isFrozen) {
272
+ return this.getMetaProperty('links', []);
273
+ }
274
+ if (!this.hasMetaProperty('links')) {
275
+ this.setMetaProperty('links', []);
276
+ }
277
+ return this.meta.get('links');
260
278
  }
261
279
  set links(value) {
262
280
  this.setMetaProperty('links', value);
@@ -407,16 +425,26 @@ class Element {
407
425
  }
408
426
 
409
427
  /**
410
- * Gets a meta property, creating it with default value if not present.
428
+ * Gets a meta property.
429
+ *
430
+ * When the property doesn't exist:
431
+ * - With defaultValue: returns a new refracted element instance (not cached)
432
+ * - Without defaultValue: returns undefined
433
+ *
434
+ * Note: Each call with a default creates a new instance. Use setMetaProperty
435
+ * first if you need reference equality across multiple accesses.
411
436
  */
437
+
412
438
  getMetaProperty(name, defaultValue) {
413
- if (!this.meta.hasKey(name)) {
414
- if (this.isFrozen) {
415
- const element = this.refract(defaultValue);
439
+ if (!this.hasMetaProperty(name)) {
440
+ if (defaultValue === undefined) {
441
+ return undefined;
442
+ }
443
+ const element = this.refract(defaultValue);
444
+ if (element && this.isFrozen) {
416
445
  element.freeze();
417
- return element;
418
446
  }
419
- this.meta.set(name, defaultValue);
447
+ return element;
420
448
  }
421
449
  return this.meta.get(name);
422
450
  }
@@ -234,7 +234,13 @@ class Element {
234
234
 
235
235
  /** Unique identifier for this element. */
236
236
  get id() {
237
- return this.getMetaProperty('id', '');
237
+ if (this.isFrozen) {
238
+ return this.getMetaProperty('id', '');
239
+ }
240
+ if (!this.hasMetaProperty('id')) {
241
+ this.setMetaProperty('id', '');
242
+ }
243
+ return this.meta.get('id');
238
244
  }
239
245
  set id(value) {
240
246
  this.setMetaProperty('id', value);
@@ -242,7 +248,13 @@ class Element {
242
248
 
243
249
  /** CSS-like class names. */
244
250
  get classes() {
245
- return this.getMetaProperty('classes', []);
251
+ if (this.isFrozen) {
252
+ return this.getMetaProperty('classes', []);
253
+ }
254
+ if (!this.hasMetaProperty('classes')) {
255
+ this.setMetaProperty('classes', []);
256
+ }
257
+ return this.meta.get('classes');
246
258
  }
247
259
  set classes(value) {
248
260
  this.setMetaProperty('classes', value);
@@ -250,7 +262,13 @@ class Element {
250
262
 
251
263
  /** Hyperlinks associated with this element. */
252
264
  get links() {
253
- return this.getMetaProperty('links', []);
265
+ if (this.isFrozen) {
266
+ return this.getMetaProperty('links', []);
267
+ }
268
+ if (!this.hasMetaProperty('links')) {
269
+ this.setMetaProperty('links', []);
270
+ }
271
+ return this.meta.get('links');
254
272
  }
255
273
  set links(value) {
256
274
  this.setMetaProperty('links', value);
@@ -401,16 +419,26 @@ class Element {
401
419
  }
402
420
 
403
421
  /**
404
- * Gets a meta property, creating it with default value if not present.
422
+ * Gets a meta property.
423
+ *
424
+ * When the property doesn't exist:
425
+ * - With defaultValue: returns a new refracted element instance (not cached)
426
+ * - Without defaultValue: returns undefined
427
+ *
428
+ * Note: Each call with a default creates a new instance. Use setMetaProperty
429
+ * first if you need reference equality across multiple accesses.
405
430
  */
431
+
406
432
  getMetaProperty(name, defaultValue) {
407
- if (!this.meta.hasKey(name)) {
408
- if (this.isFrozen) {
409
- const element = this.refract(defaultValue);
433
+ if (!this.hasMetaProperty(name)) {
434
+ if (defaultValue === undefined) {
435
+ return undefined;
436
+ }
437
+ const element = this.refract(defaultValue);
438
+ if (element && this.isFrozen) {
410
439
  element.freeze();
411
- return element;
412
440
  }
413
- this.meta.set(name, defaultValue);
441
+ return element;
414
442
  }
415
443
  return this.meta.get(name);
416
444
  }
@@ -395,9 +395,17 @@ declare class Element_2 implements ToValue, Equatable, Freezable {
395
395
  */
396
396
  toRef(path?: string): Element_2;
397
397
  /**
398
- * Gets a meta property, creating it with default value if not present.
398
+ * Gets a meta property.
399
+ *
400
+ * When the property doesn't exist:
401
+ * - With defaultValue: returns a new refracted element instance (not cached)
402
+ * - Without defaultValue: returns undefined
403
+ *
404
+ * Note: Each call with a default creates a new instance. Use setMetaProperty
405
+ * first if you need reference equality across multiple accesses.
399
406
  */
400
407
  getMetaProperty(name: string, defaultValue: unknown): Element_2;
408
+ getMetaProperty(name: string): Element_2 | undefined;
401
409
  /**
402
410
  * Sets a meta property.
403
411
  */