@speclynx/apidom-datamodel 1.12.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/LICENSES/AFL-3.0.txt +182 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/BSD-3-Clause.txt +26 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +74 -0
- package/README.md +479 -0
- package/dist/apidom-datamodel.browser.js +2717 -0
- package/dist/apidom-datamodel.browser.min.js +1 -0
- package/package.json +53 -0
- package/src/KeyValuePair.cjs +38 -0
- package/src/KeyValuePair.mjs +34 -0
- package/src/Namespace.cjs +212 -0
- package/src/Namespace.mjs +206 -0
- package/src/ObjectSlice.cjs +206 -0
- package/src/ObjectSlice.mjs +202 -0
- package/src/elements/LinkElement.cjs +44 -0
- package/src/elements/LinkElement.mjs +39 -0
- package/src/elements/RefElement.cjs +31 -0
- package/src/elements/RefElement.mjs +26 -0
- package/src/index.cjs +25 -0
- package/src/index.mjs +6 -0
- package/src/primitives/ArrayElement.cjs +176 -0
- package/src/primitives/ArrayElement.mjs +169 -0
- package/src/primitives/BooleanElement.cjs +20 -0
- package/src/primitives/BooleanElement.mjs +15 -0
- package/src/primitives/CollectionElement.cjs +194 -0
- package/src/primitives/CollectionElement.mjs +187 -0
- package/src/primitives/Element.cjs +438 -0
- package/src/primitives/Element.mjs +433 -0
- package/src/primitives/MemberElement.cjs +54 -0
- package/src/primitives/MemberElement.mjs +49 -0
- package/src/primitives/NullElement.cjs +28 -0
- package/src/primitives/NullElement.mjs +23 -0
- package/src/primitives/NumberElement.cjs +20 -0
- package/src/primitives/NumberElement.mjs +15 -0
- package/src/primitives/ObjectElement.cjs +222 -0
- package/src/primitives/ObjectElement.mjs +216 -0
- package/src/primitives/StringElement.cjs +27 -0
- package/src/primitives/StringElement.mjs +22 -0
- package/src/registration.cjs +87 -0
- package/src/registration.mjs +70 -0
- package/src/serialisers/JSONSerialiser.cjs +144 -0
- package/src/serialisers/JSONSerialiser.mjs +140 -0
- package/src/types.cjs +3 -0
- package/src/types.mjs +1 -0
- package/types/apidom-datamodel.d.ts +887 -0
|
@@ -0,0 +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={};e.r(t),e.d(t,{ArrayElement:()=>C,BooleanElement:()=>S,CollectionElement:()=>x,Element:()=>A,JSONSerialiser:()=>n,KeyValuePair:()=>k,LinkElement:()=>F,MemberElement:()=>D,Namespace:()=>L,NullElement:()=>M,NumberElement:()=>P,ObjectElement:()=>K,ObjectSlice:()=>j,RefElement:()=>N,StringElement:()=>V,refract:()=>$});const n=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};e._meta&&e._meta.length>0&&(t.meta=this.serialiseObject(e.meta)),e._attributes&&e._attributes.length>0&&(t.attributes=this.serialiseObject(e.attributes));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));t.element!==e.element&&(t.element=e.element),e.meta&&this.deserialiseObject(e.meta,t.meta),e.attributes&&this.deserialiseObject(e.attributes,t.attributes);const n=this.deserialiseContent(e.content);return void 0===n&&null!==t.content||(t.content=n),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]))})}};function r(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function s(e){return function t(n){return 0===arguments.length||r(n)?t:e.apply(this,arguments)}}function i(e){return function t(n,i){switch(arguments.length){case 0:return t;case 1:return r(n)?t:s(function(t){return e(n,t)});default:return r(n)&&r(i)?t:r(n)?s(function(t){return e(t,i)}):r(i)?s(function(t){return e(n,t)}):e(n,i)}}}function o(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n}function a(e,t,n){for(var r=0,s=n.length;r<s;){if(e(t,n[r]))return!0;r+=1}return!1}function c(e,t){return Object.prototype.hasOwnProperty.call(t,e)}const l="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 h=function(){return"[object Arguments]"===u.call(arguments)?function(e){return"[object Arguments]"===u.call(e)}:function(e){return c("callee",e)}}();var f=!{toString:null}.propertyIsEnumerable("toString"),m=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],p=function(){return arguments.propertyIsEnumerable("length")}(),y=function(e,t){for(var n=0;n<e.length;){if(e[n]===t)return!0;n+=1}return!1};const d="function"!=typeof Object.keys||p?s(function(e){if(Object(e)!==e)return[];var t,n,r=[],s=p&&h(e);for(t in e)!c(t,e)||s&&"length"===t||(r[r.length]=t);if(f)for(n=m.length-1;n>=0;)c(t=m[n],e)&&!y(r,t)&&(r[r.length]=t),n-=1;return r}):s(function(e){return Object(e)!==e?[]:Object.keys(e)});const b=s(function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)});function g(e,t,n,r){var s=o(e);function i(e,t){return v(e,t,n.slice(),r.slice())}return!a(function(e,t){return!a(i,t,e)},o(t),s)}function v(e,t,n,r){if(l(e,t))return!0;var s,i,o=b(e);if(o!==b(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||!l(e.valueOf(),t.valueOf()))return!1;break;case"Date":if(!l(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 a=n.length-1;a>=0;){if(n[a]===e)return r[a]===t;a-=1}switch(o){case"Map":return e.size===t.size&&g(e.entries(),t.entries(),n.concat([e]),r.concat([t]));case"Set":return e.size===t.size&&g(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 u=d(e);if(u.length!==d(t).length)return!1;var h=n.concat([e]),f=r.concat([t]);for(a=u.length-1;a>=0;){var m=u[a];if(!c(m,t)||!v(t[m],e[m],h,f))return!1;a-=1}return!0}const _=i(function(e,t){return v(e,t,[],[])});class E{key;value;constructor(e,t){this.key=e,this.value=t}clone(){return new E(this.key?.clone(),this.value?.clone())}toValue(){return{key:this.key?.toValue(),value:this.value?.toValue()}}}const k=E;class w{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 w(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 w(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}clone(){return new w(this.elements.map(e=>e.clone()))}includesKey(e){return this.elements.some(t=>t.key?.equals(e))}[Symbol.iterator](){return this.elements[Symbol.iterator]()}}const j=w;class O{_storedElement="element";_content;_meta;_attributes;parent;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 O)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 k)this._content=e;else if(e instanceof j)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 O?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 O?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 title(){return this.getMetaProperty("title","")}set title(e){this.setMetaProperty("title",e)}get description(){return this.getMetaProperty("description","")}set description(e){this.setMetaProperty("description",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 k){const t=[];return e.key&&t.push(e.key),e.value&&t.push(e.value),t}return e instanceof O?[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)}}clone(){const e=new(0,this.constructor);e.element=this.element,this._meta&&(e._meta=this._meta.clone()),this._attributes&&(e._attributes=this._attributes.clone());const{_content:t}=this;return t instanceof O||t instanceof k?e._content=t.clone():Array.isArray(t)?e._content=t.map(e=>e.clone()):e._content=t,e}toValue(){const{_content:e}=this;return e instanceof O||e instanceof k?e.toValue():Array.isArray(e)?e.map(e=>e.toValue()):e}equals(e){return _(this.toValue(),e)}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)}}const A=O;const M=class extends A{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 V=class extends A{constructor(e,t,n){super(e,t,n),this.element="string"}primitive(){return"string"}get length(){return this.content?.length??0}};const P=class extends A{constructor(e,t,n){super(e,t,n),this.element="number"}primitive(){return"number"}};const S=class extends A{constructor(e,t,n){super(e,t,n),this.element="boolean"}primitive(){return"boolean"}};class z extends A{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){return this._content.push(this.refract(e)),this}add(e){this.push(e)}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}"fantasy-land/empty"(){return this.empty()}concat(e){return new(0,this.constructor)(this._content.concat(e._content))}"fantasy-land/concat"(e){return this.concat(e)}[Symbol.iterator](){return this._content[Symbol.iterator]()}}const x=z;class q extends x{static empty(){return new this}static"fantasy-land/empty"(){return q.empty()}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([])}"fantasy-land/map"(e){return new this.constructor(this.map(e))}"fantasy-land/chain"(e){return this.map(t=>e(t)).reduce((e,t)=>e.concat(t),this.empty())}"fantasy-land/filter"(e){return new this.constructor(this._content.filter(e))}"fantasy-land/reduce"(e,t){return this._content.reduce(e,t)}}const C=q;const D=class extends A{constructor(e,t,n,r){super(new k,n,r),this.element="member",void 0!==e&&(this.key=e),void 0!==t&&(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=this.refract(e)}};const K=class extends x{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 D(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 j(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 j(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 A{constructor(e,t,n){super(e||[],t,n),this.element="ref",this.path||(this.path="element")}get path(){return this.attributes.get("path")}set path(e){this.attributes.set("path",e)}};const F=class extends A{constructor(e,t,n){super(e||[],t,n),this.element="link"}get relation(){return this.attributes.get("relation")}set relation(e){this.attributes.set("relation",e)}get href(){return this.attributes.get("href")}set href(e){this.attributes.set("href",e)}},I=e=>null===e,R=e=>"string"==typeof e,B=e=>"number"==typeof e,U=e=>"boolean"==typeof e,T=e=>null!==e&&"object"==typeof e;class G{elementMap={};elementDetection=[];Element;KeyValuePair;_elements;_attributeElementKeys=[];_attributeElementArrayKeys=[];constructor(e){this.Element=A,this.KeyValuePair=k,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",M).register("string",V).register("number",P).register("boolean",S).register("array",C).register("object",K).register("member",D).register("ref",N).register("link",F),this.detect(I,M,!1).detect(R,V,!1).detect(B,P,!1).detect(U,S,!1).detect(Array.isArray,C,!1).detect(T,K,!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 n(this)}}n.prototype.Namespace=G;const L=G;function J(e){return void 0===e?new M:$(e)}function $(e){if(e instanceof A)return e;if("string"==typeof e)return new V(e);if("number"==typeof e)return new P(e);if("boolean"==typeof e)return new S(e);if(null===e)return new M;if(Array.isArray(e))return new C(e.map(J));if("object"==typeof e)return new K(e);throw new Error("Cannot refract value of type "+typeof e)}return A.prototype.ObjectElement=K,A.prototype.ArrayElement=C,A.prototype.RefElement=N,A.prototype.MemberElement=D,A.prototype.refract=$,t})());
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@speclynx/apidom-datamodel",
|
|
3
|
+
"version": "1.12.2",
|
|
4
|
+
"description": "Data model primitives for ApiDOM.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"unpkg": "./dist/apidom-datamodel.browser.min.js",
|
|
12
|
+
"main": "./src/index.cjs",
|
|
13
|
+
"exports": {
|
|
14
|
+
"types": "./types/apidom-datamodel.d.ts",
|
|
15
|
+
"import": "./src/index.mjs",
|
|
16
|
+
"require": "./src/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"types": "./types/apidom-datamodel.d.ts",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
|
|
21
|
+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
|
|
22
|
+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir src --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
|
|
23
|
+
"build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress",
|
|
24
|
+
"lint": "eslint ./",
|
|
25
|
+
"lint:fix": "eslint ./ --fix",
|
|
26
|
+
"clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types",
|
|
27
|
+
"typescript:check-types": "tsc --noEmit",
|
|
28
|
+
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
|
|
29
|
+
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
|
|
30
|
+
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
|
|
31
|
+
"postpack": "rimraf NOTICE LICENSES"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/speclynx/apidom.git"
|
|
36
|
+
},
|
|
37
|
+
"author": "Vladimir Gorej",
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@babel/runtime-corejs3": "^7.28.4",
|
|
41
|
+
"ramda": "~0.32.0"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"src/**/*.mjs",
|
|
45
|
+
"src/**/*.cjs",
|
|
46
|
+
"dist/",
|
|
47
|
+
"types/apidom-datamodel.d.ts",
|
|
48
|
+
"LICENSES",
|
|
49
|
+
"NOTICE",
|
|
50
|
+
"README.md",
|
|
51
|
+
"CHANGELOG.md"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a key-value pair used in MemberElement content.
|
|
7
|
+
* This is used internally to store object member data.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam K - Key element type
|
|
10
|
+
* @typeParam V - Value element type
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
class KeyValuePair {
|
|
14
|
+
key;
|
|
15
|
+
value;
|
|
16
|
+
constructor(key, value) {
|
|
17
|
+
this.key = key;
|
|
18
|
+
this.value = value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a deep clone of the KeyValuePair.
|
|
23
|
+
*/
|
|
24
|
+
clone() {
|
|
25
|
+
return new KeyValuePair(this.key?.clone(), this.value?.clone());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts to a plain JavaScript object representation.
|
|
30
|
+
*/
|
|
31
|
+
toValue() {
|
|
32
|
+
return {
|
|
33
|
+
key: this.key?.toValue(),
|
|
34
|
+
value: this.value?.toValue()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var _default = exports.default = KeyValuePair;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a key-value pair used in MemberElement content.
|
|
3
|
+
* This is used internally to store object member data.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam K - Key element type
|
|
6
|
+
* @typeParam V - Value element type
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
class KeyValuePair {
|
|
10
|
+
key;
|
|
11
|
+
value;
|
|
12
|
+
constructor(key, value) {
|
|
13
|
+
this.key = key;
|
|
14
|
+
this.value = value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a deep clone of the KeyValuePair.
|
|
19
|
+
*/
|
|
20
|
+
clone() {
|
|
21
|
+
return new KeyValuePair(this.key?.clone(), this.value?.clone());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Converts to a plain JavaScript object representation.
|
|
26
|
+
*/
|
|
27
|
+
toValue() {
|
|
28
|
+
return {
|
|
29
|
+
key: this.key?.toValue(),
|
|
30
|
+
value: this.value?.toValue()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export default KeyValuePair;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _JSONSerialiser = _interopRequireDefault(require("./serialisers/JSONSerialiser.cjs"));
|
|
8
|
+
var elements = _interopRequireWildcard(require("./registration.cjs"));
|
|
9
|
+
const isNull = value => value === null;
|
|
10
|
+
const isString = value => typeof value === 'string';
|
|
11
|
+
const isNumber = value => typeof value === 'number';
|
|
12
|
+
const isBoolean = value => typeof value === 'boolean';
|
|
13
|
+
const isObject = value => value !== null && typeof value === 'object';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Constructor type for Element classes.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Function to test if a value should be converted to a specific element type.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Tuple of detection test and element class.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Options for Namespace constructor.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Plugin interface for extending Namespace.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Map of registered element classes.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A refract element implementation with an extensible namespace, able to
|
|
48
|
+
* load other namespaces into it.
|
|
49
|
+
*
|
|
50
|
+
* The namespace allows you to register your own classes to be instantiated
|
|
51
|
+
* when a particular refract element is encountered, and allows you to specify
|
|
52
|
+
* which elements get instantiated for existing JavaScript objects.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
class Namespace {
|
|
57
|
+
elementMap = {};
|
|
58
|
+
elementDetection = [];
|
|
59
|
+
Element;
|
|
60
|
+
KeyValuePair;
|
|
61
|
+
_elements;
|
|
62
|
+
_attributeElementKeys = [];
|
|
63
|
+
_attributeElementArrayKeys = [];
|
|
64
|
+
constructor(options) {
|
|
65
|
+
this.Element = elements.Element;
|
|
66
|
+
this.KeyValuePair = elements.KeyValuePair;
|
|
67
|
+
if (!options || !options.noDefault) {
|
|
68
|
+
this.useDefault();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Use a namespace plugin or load a generic plugin.
|
|
74
|
+
*/
|
|
75
|
+
use(plugin) {
|
|
76
|
+
if (plugin.namespace) {
|
|
77
|
+
plugin.namespace({
|
|
78
|
+
base: this
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (plugin.load) {
|
|
82
|
+
plugin.load({
|
|
83
|
+
base: this
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Use the default namespace. This preloads all the default elements
|
|
91
|
+
* into this registry instance.
|
|
92
|
+
*/
|
|
93
|
+
useDefault() {
|
|
94
|
+
// Set up classes for default elements
|
|
95
|
+
this.register('null', elements.NullElement).register('string', elements.StringElement).register('number', elements.NumberElement).register('boolean', elements.BooleanElement).register('array', elements.ArrayElement).register('object', elements.ObjectElement).register('member', elements.MemberElement).register('ref', elements.RefElement).register('link', elements.LinkElement);
|
|
96
|
+
|
|
97
|
+
// Add instance detection functions to convert existing objects into
|
|
98
|
+
// the corresponding refract elements.
|
|
99
|
+
this.detect(isNull, elements.NullElement, false).detect(isString, elements.StringElement, false).detect(isNumber, elements.NumberElement, false).detect(isBoolean, elements.BooleanElement, false).detect(Array.isArray, elements.ArrayElement, false).detect(isObject, elements.ObjectElement, false);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Register a new element class for an element.
|
|
105
|
+
*/
|
|
106
|
+
register(name, ElementClass) {
|
|
107
|
+
this._elements = undefined;
|
|
108
|
+
this.elementMap[name] = ElementClass;
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Unregister a previously registered class for an element.
|
|
114
|
+
*/
|
|
115
|
+
unregister(name) {
|
|
116
|
+
this._elements = undefined;
|
|
117
|
+
delete this.elementMap[name];
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Add a new detection function to determine which element
|
|
123
|
+
* class to use when converting existing JS instances into
|
|
124
|
+
* refract elements.
|
|
125
|
+
*/
|
|
126
|
+
detect(test, ElementClass, givenPrepend) {
|
|
127
|
+
const prepend = givenPrepend === undefined ? true : givenPrepend;
|
|
128
|
+
if (prepend) {
|
|
129
|
+
this.elementDetection.unshift([test, ElementClass]);
|
|
130
|
+
} else {
|
|
131
|
+
this.elementDetection.push([test, ElementClass]);
|
|
132
|
+
}
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Convert an existing JavaScript object into refract element instances.
|
|
138
|
+
* If the item passed in is already refracted, then it is returned unmodified.
|
|
139
|
+
*/
|
|
140
|
+
toElement(value) {
|
|
141
|
+
if (value instanceof this.Element) {
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
let element;
|
|
145
|
+
for (const [test, ElementClass] of this.elementDetection) {
|
|
146
|
+
if (test(value)) {
|
|
147
|
+
element = new ElementClass(value);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return element;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get an element class given an element name.
|
|
156
|
+
*/
|
|
157
|
+
getElementClass(element) {
|
|
158
|
+
const ElementClass = this.elementMap[element];
|
|
159
|
+
if (ElementClass === undefined) {
|
|
160
|
+
// Fall back to the base element. We may not know what
|
|
161
|
+
// to do with the `content`, but downstream software
|
|
162
|
+
// may know.
|
|
163
|
+
return this.Element;
|
|
164
|
+
}
|
|
165
|
+
return ElementClass;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Convert a refract document into refract element instances.
|
|
170
|
+
*/
|
|
171
|
+
fromRefract(doc) {
|
|
172
|
+
return this.serialiser.deserialise(doc);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Convert an element to a Refracted JSON object.
|
|
177
|
+
*/
|
|
178
|
+
toRefract(element) {
|
|
179
|
+
return this.serialiser.serialise(element);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get an object that contains all registered element classes, where
|
|
184
|
+
* the key is the PascalCased element name and the value is the class.
|
|
185
|
+
*/
|
|
186
|
+
get elements() {
|
|
187
|
+
if (this._elements === undefined) {
|
|
188
|
+
this._elements = {
|
|
189
|
+
Element: this.Element
|
|
190
|
+
};
|
|
191
|
+
Object.keys(this.elementMap).forEach(name => {
|
|
192
|
+
// Currently, all registered element types use a camelCaseName.
|
|
193
|
+
// Converting to PascalCase is as simple as upper-casing the first letter.
|
|
194
|
+
const pascal = name[0].toUpperCase() + name.substring(1);
|
|
195
|
+
this._elements[pascal] = this.elementMap[name];
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return this._elements;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Convenience method for getting a JSON Serialiser configured with the
|
|
203
|
+
* current namespace.
|
|
204
|
+
*/
|
|
205
|
+
get serialiser() {
|
|
206
|
+
return new _JSONSerialiser.default(this);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Set up the circular reference for JSONSerialiser
|
|
211
|
+
_JSONSerialiser.default.prototype.Namespace = Namespace;
|
|
212
|
+
var _default = exports.default = Namespace;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import JSONSerialiser from "./serialisers/JSONSerialiser.mjs";
|
|
2
|
+
import * as elements from "./registration.mjs";
|
|
3
|
+
const isNull = value => value === null;
|
|
4
|
+
const isString = value => typeof value === 'string';
|
|
5
|
+
const isNumber = value => typeof value === 'number';
|
|
6
|
+
const isBoolean = value => typeof value === 'boolean';
|
|
7
|
+
const isObject = value => value !== null && typeof value === 'object';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructor type for Element classes.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Function to test if a value should be converted to a specific element type.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Tuple of detection test and element class.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Options for Namespace constructor.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Plugin interface for extending Namespace.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Map of registered element classes.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A refract element implementation with an extensible namespace, able to
|
|
42
|
+
* load other namespaces into it.
|
|
43
|
+
*
|
|
44
|
+
* The namespace allows you to register your own classes to be instantiated
|
|
45
|
+
* when a particular refract element is encountered, and allows you to specify
|
|
46
|
+
* which elements get instantiated for existing JavaScript objects.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
class Namespace {
|
|
51
|
+
elementMap = {};
|
|
52
|
+
elementDetection = [];
|
|
53
|
+
Element;
|
|
54
|
+
KeyValuePair;
|
|
55
|
+
_elements;
|
|
56
|
+
_attributeElementKeys = [];
|
|
57
|
+
_attributeElementArrayKeys = [];
|
|
58
|
+
constructor(options) {
|
|
59
|
+
this.Element = elements.Element;
|
|
60
|
+
this.KeyValuePair = elements.KeyValuePair;
|
|
61
|
+
if (!options || !options.noDefault) {
|
|
62
|
+
this.useDefault();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Use a namespace plugin or load a generic plugin.
|
|
68
|
+
*/
|
|
69
|
+
use(plugin) {
|
|
70
|
+
if (plugin.namespace) {
|
|
71
|
+
plugin.namespace({
|
|
72
|
+
base: this
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (plugin.load) {
|
|
76
|
+
plugin.load({
|
|
77
|
+
base: this
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Use the default namespace. This preloads all the default elements
|
|
85
|
+
* into this registry instance.
|
|
86
|
+
*/
|
|
87
|
+
useDefault() {
|
|
88
|
+
// Set up classes for default elements
|
|
89
|
+
this.register('null', elements.NullElement).register('string', elements.StringElement).register('number', elements.NumberElement).register('boolean', elements.BooleanElement).register('array', elements.ArrayElement).register('object', elements.ObjectElement).register('member', elements.MemberElement).register('ref', elements.RefElement).register('link', elements.LinkElement);
|
|
90
|
+
|
|
91
|
+
// Add instance detection functions to convert existing objects into
|
|
92
|
+
// the corresponding refract elements.
|
|
93
|
+
this.detect(isNull, elements.NullElement, false).detect(isString, elements.StringElement, false).detect(isNumber, elements.NumberElement, false).detect(isBoolean, elements.BooleanElement, false).detect(Array.isArray, elements.ArrayElement, false).detect(isObject, elements.ObjectElement, false);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Register a new element class for an element.
|
|
99
|
+
*/
|
|
100
|
+
register(name, ElementClass) {
|
|
101
|
+
this._elements = undefined;
|
|
102
|
+
this.elementMap[name] = ElementClass;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Unregister a previously registered class for an element.
|
|
108
|
+
*/
|
|
109
|
+
unregister(name) {
|
|
110
|
+
this._elements = undefined;
|
|
111
|
+
delete this.elementMap[name];
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Add a new detection function to determine which element
|
|
117
|
+
* class to use when converting existing JS instances into
|
|
118
|
+
* refract elements.
|
|
119
|
+
*/
|
|
120
|
+
detect(test, ElementClass, givenPrepend) {
|
|
121
|
+
const prepend = givenPrepend === undefined ? true : givenPrepend;
|
|
122
|
+
if (prepend) {
|
|
123
|
+
this.elementDetection.unshift([test, ElementClass]);
|
|
124
|
+
} else {
|
|
125
|
+
this.elementDetection.push([test, ElementClass]);
|
|
126
|
+
}
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Convert an existing JavaScript object into refract element instances.
|
|
132
|
+
* If the item passed in is already refracted, then it is returned unmodified.
|
|
133
|
+
*/
|
|
134
|
+
toElement(value) {
|
|
135
|
+
if (value instanceof this.Element) {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
let element;
|
|
139
|
+
for (const [test, ElementClass] of this.elementDetection) {
|
|
140
|
+
if (test(value)) {
|
|
141
|
+
element = new ElementClass(value);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return element;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get an element class given an element name.
|
|
150
|
+
*/
|
|
151
|
+
getElementClass(element) {
|
|
152
|
+
const ElementClass = this.elementMap[element];
|
|
153
|
+
if (ElementClass === undefined) {
|
|
154
|
+
// Fall back to the base element. We may not know what
|
|
155
|
+
// to do with the `content`, but downstream software
|
|
156
|
+
// may know.
|
|
157
|
+
return this.Element;
|
|
158
|
+
}
|
|
159
|
+
return ElementClass;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Convert a refract document into refract element instances.
|
|
164
|
+
*/
|
|
165
|
+
fromRefract(doc) {
|
|
166
|
+
return this.serialiser.deserialise(doc);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Convert an element to a Refracted JSON object.
|
|
171
|
+
*/
|
|
172
|
+
toRefract(element) {
|
|
173
|
+
return this.serialiser.serialise(element);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Get an object that contains all registered element classes, where
|
|
178
|
+
* the key is the PascalCased element name and the value is the class.
|
|
179
|
+
*/
|
|
180
|
+
get elements() {
|
|
181
|
+
if (this._elements === undefined) {
|
|
182
|
+
this._elements = {
|
|
183
|
+
Element: this.Element
|
|
184
|
+
};
|
|
185
|
+
Object.keys(this.elementMap).forEach(name => {
|
|
186
|
+
// Currently, all registered element types use a camelCaseName.
|
|
187
|
+
// Converting to PascalCase is as simple as upper-casing the first letter.
|
|
188
|
+
const pascal = name[0].toUpperCase() + name.substring(1);
|
|
189
|
+
this._elements[pascal] = this.elementMap[name];
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return this._elements;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Convenience method for getting a JSON Serialiser configured with the
|
|
197
|
+
* current namespace.
|
|
198
|
+
*/
|
|
199
|
+
get serialiser() {
|
|
200
|
+
return new JSONSerialiser(this);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Set up the circular reference for JSONSerialiser
|
|
205
|
+
JSONSerialiser.prototype.Namespace = Namespace;
|
|
206
|
+
export default Namespace;
|