@speclynx/apidom-ns-json-schema-draft-4 2.13.1 → 3.0.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 +15 -0
- package/dist/apidom-ns-json-schema-draft-4.browser.js +246 -100
- package/dist/apidom-ns-json-schema-draft-4.browser.min.js +1 -1
- package/package.json +5 -5
- package/src/refractor/index.cjs +4 -2
- package/src/refractor/index.mjs +4 -2
- package/src/refractor/plugins/replace-empty-element.cjs +4 -3
- package/src/refractor/plugins/replace-empty-element.mjs +4 -3
- package/src/refractor/visitors/FallbackVisitor.cjs +1 -1
- package/src/refractor/visitors/FallbackVisitor.mjs +1 -1
- package/src/refractor/visitors/SpecificationVisitor.cjs +2 -2
- package/src/refractor/visitors/SpecificationVisitor.mjs +2 -2
- package/src/refractor/visitors/Visitor.cjs +10 -8
- package/src/refractor/visitors/Visitor.mjs +11 -9
- package/src/refractor/visitors/generics/FixedFieldsVisitor.cjs +4 -3
- package/src/refractor/visitors/generics/FixedFieldsVisitor.mjs +4 -3
- package/src/refractor/visitors/generics/PatternedFieldsVisitor.cjs +4 -2
- package/src/refractor/visitors/generics/PatternedFieldsVisitor.mjs +4 -2
- package/src/refractor/visitors/json-schema/index.cjs +5 -4
- package/src/refractor/visitors/json-schema/index.mjs +6 -5
- package/types/apidom-ns-json-schema-draft-4.d.ts +6 -2
|
@@ -617,7 +617,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
617
617
|
const refract = (value, {
|
|
618
618
|
element = 'jSONSchemaDraft4',
|
|
619
619
|
plugins = [],
|
|
620
|
-
specificationObj = _specification_ts__WEBPACK_IMPORTED_MODULE_5__["default"]
|
|
620
|
+
specificationObj = _specification_ts__WEBPACK_IMPORTED_MODULE_5__["default"],
|
|
621
|
+
consume = false
|
|
621
622
|
} = {}) => {
|
|
622
623
|
const genericElement = (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_3__.refract)(value);
|
|
623
624
|
const resolvedSpec = (0,_speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_1__.resolveSpecification)(specificationObj);
|
|
@@ -634,7 +635,8 @@ const refract = (value, {
|
|
|
634
635
|
*/
|
|
635
636
|
const RootVisitorClass = (0,ramda__WEBPACK_IMPORTED_MODULE_4__["default"])(specPath, resolvedSpec);
|
|
636
637
|
const rootVisitor = new RootVisitorClass({
|
|
637
|
-
specObj: resolvedSpec
|
|
638
|
+
specObj: resolvedSpec,
|
|
639
|
+
consume
|
|
638
640
|
});
|
|
639
641
|
(0,_speclynx_apidom_traverse__WEBPACK_IMPORTED_MODULE_2__.traverse)(genericElement, rootVisitor);
|
|
640
642
|
|
|
@@ -868,8 +870,9 @@ const schema = {
|
|
|
868
870
|
}
|
|
869
871
|
};
|
|
870
872
|
const findElementFactory = (ancestor, keyName) => {
|
|
871
|
-
const elementType = (0,_speclynx_apidom_traverse__WEBPACK_IMPORTED_MODULE_8__.getNodeType)(ancestor);
|
|
872
|
-
const
|
|
873
|
+
const elementType = (0,_speclynx_apidom_traverse__WEBPACK_IMPORTED_MODULE_8__.getNodeType)(ancestor);
|
|
874
|
+
const classType = ancestor.isMetaEmpty ? undefined : ancestor.classes.at(0); // @ts-ignore
|
|
875
|
+
const keyMapping = schema[elementType] || schema[classType];
|
|
873
876
|
return typeof keyMapping === 'undefined' ? undefined : Object.hasOwn(keyMapping, '[key: *]') ? keyMapping['[key: *]'] : keyMapping[keyName];
|
|
874
877
|
};
|
|
875
878
|
|
|
@@ -899,7 +902,7 @@ const plugin = () => () => ({
|
|
|
899
902
|
if (typeof elementFactory !== 'function') return;
|
|
900
903
|
const replacement = elementFactory.call({
|
|
901
904
|
context
|
|
902
|
-
}, undefined,
|
|
905
|
+
}, undefined, element.isMetaEmpty ? undefined : element.meta.cloneDeep(), element.isAttributesEmpty ? undefined : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(element.attributes));
|
|
903
906
|
_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_5__["default"].transfer(element, replacement);
|
|
904
907
|
_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_6__["default"].transfer(element, replacement);
|
|
905
908
|
path.replaceWith(replacement);
|
|
@@ -1214,7 +1217,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1214
1217
|
*/
|
|
1215
1218
|
class FallbackVisitor extends _Visitor_ts__WEBPACK_IMPORTED_MODULE_1__["default"] {
|
|
1216
1219
|
enter(path) {
|
|
1217
|
-
this.element = (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_0__.cloneDeep)(path.node);
|
|
1220
|
+
this.element = this.consume ? path.node : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_0__.cloneDeep)(path.node);
|
|
1218
1221
|
path.stop();
|
|
1219
1222
|
}
|
|
1220
1223
|
}
|
|
@@ -1255,7 +1258,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1255
1258
|
*/
|
|
1256
1259
|
class SpecificationVisitor extends _Visitor_ts__WEBPACK_IMPORTED_MODULE_6__["default"] {
|
|
1257
1260
|
specObj;
|
|
1258
|
-
passingOptionsNames = ['specObj', 'parent'];
|
|
1261
|
+
passingOptionsNames = ['specObj', 'parent', 'consume'];
|
|
1259
1262
|
constructor({
|
|
1260
1263
|
specObj,
|
|
1261
1264
|
...rest
|
|
@@ -1301,7 +1304,7 @@ class SpecificationVisitor extends _Visitor_ts__WEBPACK_IMPORTED_MODULE_6__["def
|
|
|
1301
1304
|
*/
|
|
1302
1305
|
const visitor = this.retrieveVisitorInstance(specPath, options);
|
|
1303
1306
|
if (visitor instanceof _FallbackVisitor_ts__WEBPACK_IMPORTED_MODULE_7__["default"] && visitor?.constructor === _FallbackVisitor_ts__WEBPACK_IMPORTED_MODULE_7__["default"]) {
|
|
1304
|
-
return (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__.cloneDeep)(element);
|
|
1307
|
+
return this.consume ? element : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__.cloneDeep)(element);
|
|
1305
1308
|
}
|
|
1306
1309
|
(0,_speclynx_apidom_traverse__WEBPACK_IMPORTED_MODULE_5__.traverse)(element, visitor, options);
|
|
1307
1310
|
return visitor.element;
|
|
@@ -1319,7 +1322,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1319
1322
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
1320
1323
|
/* harmony export */ });
|
|
1321
1324
|
/* harmony import */ var _speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8400);
|
|
1322
|
-
/* harmony import */ var _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
1325
|
+
/* harmony import */ var _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2111);
|
|
1323
1326
|
/* harmony import */ var _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5810);
|
|
1324
1327
|
/* harmony import */ var _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9686);
|
|
1325
1328
|
|
|
@@ -1334,19 +1337,21 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1334
1337
|
*/
|
|
1335
1338
|
class Visitor {
|
|
1336
1339
|
element;
|
|
1340
|
+
consume = false;
|
|
1341
|
+
consumeSafe = false;
|
|
1337
1342
|
constructor(options) {
|
|
1338
1343
|
Object.assign(this, options);
|
|
1339
1344
|
}
|
|
1340
1345
|
copyMetaAndAttributes(from, to) {
|
|
1341
|
-
if (!from.isMetaEmpty
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
to.meta = (
|
|
1346
|
+
if (!from.isMetaEmpty && !to.isMetaEmpty) {
|
|
1347
|
+
to.meta = to.meta.merge(from.meta);
|
|
1348
|
+
} else if (!from.isMetaEmpty) {
|
|
1349
|
+
to.meta = from.meta.cloneDeep();
|
|
1345
1350
|
}
|
|
1346
|
-
if (!from.isAttributesEmpty
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
to.attributes = (0,
|
|
1351
|
+
if (!from.isAttributesEmpty && !to.isAttributesEmpty) {
|
|
1352
|
+
to.attributes = (0,_speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_0__["default"])(to.attributes, from.attributes);
|
|
1353
|
+
} else if (!from.isAttributesEmpty) {
|
|
1354
|
+
to.attributes = (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(from.attributes);
|
|
1350
1355
|
}
|
|
1351
1356
|
_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_2__["default"].transfer(from, to);
|
|
1352
1357
|
_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_3__["default"].transfer(from, to);
|
|
@@ -1460,12 +1465,13 @@ class FixedFieldsVisitor extends _SpecificationVisitor_ts__WEBPACK_IMPORTED_MODU
|
|
|
1460
1465
|
const keyValue = (0,_speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_3__["default"])(key);
|
|
1461
1466
|
if ((0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_0__.isStringElement)(key) && fields.includes(keyValue) && !this.ignoredFields.includes(keyValue)) {
|
|
1462
1467
|
const fixedFieldElement = this.toRefractedElement([...specPath, 'fixedFields', keyValue], value);
|
|
1463
|
-
const newMemberElement = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_2__["default"]((0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(key), fixedFieldElement);
|
|
1468
|
+
const newMemberElement = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_2__["default"](this.consume ? key : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(key), fixedFieldElement);
|
|
1464
1469
|
this.copyMetaAndAttributes(memberElement, newMemberElement);
|
|
1465
|
-
newMemberElement.classes.push('fixed-field');
|
|
1466
1470
|
this.element.content.push(newMemberElement);
|
|
1471
|
+
// consume: release processed generic subtree
|
|
1472
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
1467
1473
|
} else if (!this.ignoredFields.includes(keyValue)) {
|
|
1468
|
-
this.element.content.push((0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(memberElement));
|
|
1474
|
+
this.element.content.push(this.consume ? memberElement : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(memberElement));
|
|
1469
1475
|
}
|
|
1470
1476
|
});
|
|
1471
1477
|
this.copyMetaAndAttributes(objectElement, this.element);
|
|
@@ -1556,12 +1562,14 @@ class PatternedFieldsVisitor extends _SpecificationVisitor_ts__WEBPACK_IMPORTED_
|
|
|
1556
1562
|
if (!this.ignoredFields.includes(keyValue) && this.fieldPatternPredicate(keyValue)) {
|
|
1557
1563
|
const specPath = this.specPath(value);
|
|
1558
1564
|
const patternedFieldElement = this.toRefractedElement(specPath, value);
|
|
1559
|
-
const newMemberElement = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_2__["default"]((0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(key), patternedFieldElement);
|
|
1565
|
+
const newMemberElement = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_2__["default"](this.consume ? key : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(key), patternedFieldElement);
|
|
1560
1566
|
this.copyMetaAndAttributes(memberElement, newMemberElement);
|
|
1561
1567
|
newMemberElement.classes.push('patterned-field');
|
|
1562
1568
|
this.element.content.push(newMemberElement);
|
|
1569
|
+
// consume: release processed generic subtree
|
|
1570
|
+
if (this.consume && this.consumeSafe && !memberElement.isFrozen) memberElement.value = undefined;
|
|
1563
1571
|
} else if (!this.ignoredFields.includes(keyValue)) {
|
|
1564
|
-
this.element.content.push((0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(memberElement));
|
|
1572
|
+
this.element.content.push(this.consume ? memberElement : (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(memberElement));
|
|
1565
1573
|
}
|
|
1566
1574
|
});
|
|
1567
1575
|
this.copyMetaAndAttributes(objectElement, this.element);
|
|
@@ -2123,13 +2131,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2123
2131
|
/* harmony import */ var ramda_adjunct__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3031);
|
|
2124
2132
|
/* harmony import */ var ramda_adjunct__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6513);
|
|
2125
2133
|
/* harmony import */ var _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5162);
|
|
2126
|
-
/* harmony import */ var
|
|
2127
|
-
/* harmony import */ var
|
|
2128
|
-
/* harmony import */ var
|
|
2129
|
-
/* harmony import */ var
|
|
2130
|
-
/* harmony import */ var
|
|
2131
|
-
/* harmony import */ var _elements_JSONSchema_ts__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(6256);
|
|
2132
|
-
/* harmony import */ var _predicates_ts__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(7269);
|
|
2134
|
+
/* harmony import */ var _speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4673);
|
|
2135
|
+
/* harmony import */ var _generics_FixedFieldsVisitor_ts__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(4720);
|
|
2136
|
+
/* harmony import */ var _bases_ts__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(6763);
|
|
2137
|
+
/* harmony import */ var _elements_JSONSchema_ts__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(6256);
|
|
2138
|
+
/* harmony import */ var _predicates_ts__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(7269);
|
|
2133
2139
|
|
|
2134
2140
|
|
|
2135
2141
|
|
|
@@ -2146,10 +2152,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2146
2152
|
/**
|
|
2147
2153
|
* @public
|
|
2148
2154
|
*/
|
|
2149
|
-
class JSONSchemaVisitor extends
|
|
2155
|
+
class JSONSchemaVisitor extends _bases_ts__WEBPACK_IMPORTED_MODULE_7__.JSONSchemaVisitorBase {
|
|
2150
2156
|
constructor(options) {
|
|
2151
2157
|
super(options);
|
|
2152
|
-
this.element = new
|
|
2158
|
+
this.element = new _elements_JSONSchema_ts__WEBPACK_IMPORTED_MODULE_8__["default"]();
|
|
2159
|
+
this.consumeSafe = true;
|
|
2153
2160
|
this.specPath = (0,ramda__WEBPACK_IMPORTED_MODULE_0__["default"])(['document', 'objects', 'JSONSchema']);
|
|
2154
2161
|
}
|
|
2155
2162
|
get defaultDialectIdentifier() {
|
|
@@ -2162,27 +2169,27 @@ class JSONSchemaVisitor extends _bases_ts__WEBPACK_IMPORTED_MODULE_9__.JSONSchem
|
|
|
2162
2169
|
|
|
2163
2170
|
// for further processing consider this JSONSchema Element as parent for all sub-schemas
|
|
2164
2171
|
this.parent = this.element;
|
|
2165
|
-
return
|
|
2172
|
+
return _generics_FixedFieldsVisitor_ts__WEBPACK_IMPORTED_MODULE_6__["default"].prototype.ObjectElement.call(this, path);
|
|
2166
2173
|
}
|
|
2167
2174
|
handleDialectIdentifier(objectElement) {
|
|
2168
2175
|
// handle $schema keyword in embedded resources
|
|
2169
2176
|
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_2__["default"])(this.parent) && !(0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__.isStringElement)(objectElement.get('$schema'))) {
|
|
2170
2177
|
// no parent available and no $schema is defined, set default $schema
|
|
2171
2178
|
this.element.meta.set('inheritedDialectIdentifier', this.defaultDialectIdentifier);
|
|
2172
|
-
} else if ((0,
|
|
2179
|
+
} else if ((0,_predicates_ts__WEBPACK_IMPORTED_MODULE_9__.isJSONSchemaElement)(this.parent) && !(0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__.isStringElement)(objectElement.get('$schema'))) {
|
|
2173
2180
|
// parent is available and no $schema is defined, set parent $schema
|
|
2174
|
-
const inheritedDialectIdentifier = (0,ramda__WEBPACK_IMPORTED_MODULE_1__["default"])(
|
|
2181
|
+
const inheritedDialectIdentifier = (0,ramda__WEBPACK_IMPORTED_MODULE_1__["default"])(this.parent.meta.get('inheritedDialectIdentifier'), (0,_speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_5__["default"])(this.parent.$schema));
|
|
2175
2182
|
this.element.meta.set('inheritedDialectIdentifier', inheritedDialectIdentifier);
|
|
2176
2183
|
}
|
|
2177
2184
|
}
|
|
2178
2185
|
handleSchemaIdentifier(objectElement, identifierKeyword = 'id') {
|
|
2179
2186
|
// handle schema identifier in embedded resources
|
|
2180
|
-
// fetch parent's ancestorsSchemaIdentifiers
|
|
2181
|
-
const ancestorsSchemaIdentifiers = this.parent !== undefined ? (
|
|
2187
|
+
// fetch parent's ancestorsSchemaIdentifiers (stored as plain string[])
|
|
2188
|
+
const ancestorsSchemaIdentifiers = this.parent !== undefined ? [...(this.parent.meta.get('ancestorsSchemaIdentifiers') ?? [])] : [];
|
|
2182
2189
|
// get current schema identifier
|
|
2183
|
-
const schemaIdentifier = (0,
|
|
2190
|
+
const schemaIdentifier = (0,_speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_5__["default"])(objectElement.get(identifierKeyword));
|
|
2184
2191
|
|
|
2185
|
-
// remember schema identifier if it's a non-empty
|
|
2192
|
+
// remember schema identifier if it's a non-empty string
|
|
2186
2193
|
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_3__["default"])(schemaIdentifier)) {
|
|
2187
2194
|
ancestorsSchemaIdentifiers.push(schemaIdentifier);
|
|
2188
2195
|
}
|
|
@@ -17533,7 +17540,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
17533
17540
|
* @public
|
|
17534
17541
|
*/
|
|
17535
17542
|
const emptyElement = element => {
|
|
17536
|
-
const meta = !element.isMetaEmpty ?
|
|
17543
|
+
const meta = !element.isMetaEmpty ? element.meta.cloneDeep() : undefined;
|
|
17537
17544
|
const attributes = !element.isAttributesEmpty ? (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(element.attributes) : undefined;
|
|
17538
17545
|
|
|
17539
17546
|
// @ts-ignore
|
|
@@ -17549,7 +17556,7 @@ const getMergeFunction = (keyElement, options) => {
|
|
|
17549
17556
|
};
|
|
17550
17557
|
const getMetaMergeFunction = options => {
|
|
17551
17558
|
if (typeof options.customMetaMerge !== 'function') {
|
|
17552
|
-
return targetMeta =>
|
|
17559
|
+
return targetMeta => targetMeta.cloneDeep();
|
|
17553
17560
|
}
|
|
17554
17561
|
return options.customMetaMerge;
|
|
17555
17562
|
};
|
|
@@ -17621,8 +17628,20 @@ const deepmerge = (targetElement, sourceElement, options) => {
|
|
|
17621
17628
|
const mergedElement = sourceIsArrayElement && typeof mergedOptions.arrayElementMerge === 'function' ? mergedOptions.arrayElementMerge(targetElement, sourceElement, mergedOptions) : mergedOptions.objectElementMerge(targetElement, sourceElement, mergedOptions);
|
|
17622
17629
|
|
|
17623
17630
|
// merging meta & attributes
|
|
17624
|
-
|
|
17625
|
-
|
|
17631
|
+
if (!targetElement.isMetaEmpty && !sourceElement.isMetaEmpty) {
|
|
17632
|
+
mergedElement.meta = getMetaMergeFunction(mergedOptions)(targetElement.meta, sourceElement.meta);
|
|
17633
|
+
} else if (!targetElement.isMetaEmpty) {
|
|
17634
|
+
mergedElement.meta = targetElement.meta.cloneDeep();
|
|
17635
|
+
} else if (!sourceElement.isMetaEmpty) {
|
|
17636
|
+
mergedElement.meta = sourceElement.meta.cloneDeep();
|
|
17637
|
+
}
|
|
17638
|
+
if (!targetElement.isAttributesEmpty && !sourceElement.isAttributesEmpty) {
|
|
17639
|
+
mergedElement.attributes = getAttributesMergeFunction(mergedOptions)(targetElement.attributes, sourceElement.attributes);
|
|
17640
|
+
} else if (!targetElement.isAttributesEmpty) {
|
|
17641
|
+
mergedElement.attributes = (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(targetElement.attributes);
|
|
17642
|
+
} else if (!sourceElement.isAttributesEmpty) {
|
|
17643
|
+
mergedElement.attributes = (0,_speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__.cloneDeep)(sourceElement.attributes);
|
|
17644
|
+
}
|
|
17626
17645
|
return mergedElement;
|
|
17627
17646
|
};
|
|
17628
17647
|
deepmerge.all = (list, options) => {
|
|
@@ -17955,6 +17974,104 @@ class KeyValuePair {
|
|
|
17955
17974
|
|
|
17956
17975
|
/***/ },
|
|
17957
17976
|
|
|
17977
|
+
/***/ 1844
|
|
17978
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
17979
|
+
|
|
17980
|
+
__webpack_require__.r(__webpack_exports__);
|
|
17981
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
17982
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
17983
|
+
/* harmony export */ });
|
|
17984
|
+
/* harmony import */ var ramda__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8138);
|
|
17985
|
+
|
|
17986
|
+
/**
|
|
17987
|
+
* Lightweight meta container for Element metadata.
|
|
17988
|
+
*
|
|
17989
|
+
* Data is stored as own properties on the instance; methods live on the prototype.
|
|
17990
|
+
* `Object.keys()`, `Object.entries()`, etc. only see data properties.
|
|
17991
|
+
*
|
|
17992
|
+
* @public
|
|
17993
|
+
*/
|
|
17994
|
+
class Metadata {
|
|
17995
|
+
// Set via prototype assignment in registration.ts to avoid circular dependency
|
|
17996
|
+
|
|
17997
|
+
get(name) {
|
|
17998
|
+
return this[name];
|
|
17999
|
+
}
|
|
18000
|
+
set(name, value) {
|
|
18001
|
+
this[name] = value;
|
|
18002
|
+
}
|
|
18003
|
+
hasKey(name) {
|
|
18004
|
+
return Object.hasOwn(this, name);
|
|
18005
|
+
}
|
|
18006
|
+
keys() {
|
|
18007
|
+
return Object.keys(this);
|
|
18008
|
+
}
|
|
18009
|
+
remove(name) {
|
|
18010
|
+
delete this[name];
|
|
18011
|
+
}
|
|
18012
|
+
get isEmpty() {
|
|
18013
|
+
return Object.keys(this).length === 0;
|
|
18014
|
+
}
|
|
18015
|
+
get isFrozen() {
|
|
18016
|
+
return Object.isFrozen(this);
|
|
18017
|
+
}
|
|
18018
|
+
freeze() {
|
|
18019
|
+
for (const value of Object.values(this)) {
|
|
18020
|
+
if (value instanceof this.Element) {
|
|
18021
|
+
value.freeze();
|
|
18022
|
+
} else if (Array.isArray(value) || value !== null && typeof value === 'object') {
|
|
18023
|
+
Object.freeze(value);
|
|
18024
|
+
}
|
|
18025
|
+
}
|
|
18026
|
+
Object.freeze(this);
|
|
18027
|
+
}
|
|
18028
|
+
|
|
18029
|
+
/**
|
|
18030
|
+
* Creates a shallow clone. Same references, new container.
|
|
18031
|
+
*/
|
|
18032
|
+
cloneShallow() {
|
|
18033
|
+
const clone = new Metadata();
|
|
18034
|
+
Object.assign(clone, this);
|
|
18035
|
+
return clone;
|
|
18036
|
+
}
|
|
18037
|
+
|
|
18038
|
+
/**
|
|
18039
|
+
* Merges another Metadata into a new instance.
|
|
18040
|
+
* Arrays are concatenated, all other values are overwritten by source.
|
|
18041
|
+
*/
|
|
18042
|
+
merge(source) {
|
|
18043
|
+
const result = this.cloneShallow();
|
|
18044
|
+
for (const [key, value] of Object.entries(source)) {
|
|
18045
|
+
const existing = result.get(key);
|
|
18046
|
+
if (Array.isArray(existing) && Array.isArray(value)) {
|
|
18047
|
+
result.set(key, [...existing, ...value]);
|
|
18048
|
+
} else {
|
|
18049
|
+
result.set(key, value);
|
|
18050
|
+
}
|
|
18051
|
+
}
|
|
18052
|
+
return result;
|
|
18053
|
+
}
|
|
18054
|
+
|
|
18055
|
+
/**
|
|
18056
|
+
* Creates a deep clone. Elements are deep cloned,
|
|
18057
|
+
* all other values are deep cloned via ramda clone.
|
|
18058
|
+
*/
|
|
18059
|
+
cloneDeep() {
|
|
18060
|
+
const copy = new Metadata();
|
|
18061
|
+
for (const [key, value] of Object.entries(this)) {
|
|
18062
|
+
if (value instanceof this.Element) {
|
|
18063
|
+
copy.set(key, this.cloneDeepElement(value));
|
|
18064
|
+
} else {
|
|
18065
|
+
copy.set(key, (0,ramda__WEBPACK_IMPORTED_MODULE_0__["default"])(value));
|
|
18066
|
+
}
|
|
18067
|
+
}
|
|
18068
|
+
return copy;
|
|
18069
|
+
}
|
|
18070
|
+
}
|
|
18071
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Metadata);
|
|
18072
|
+
|
|
18073
|
+
/***/ },
|
|
18074
|
+
|
|
17958
18075
|
/***/ 5156
|
|
17959
18076
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
17960
18077
|
|
|
@@ -18595,7 +18712,7 @@ const cloneShallowElement = element => {
|
|
|
18595
18712
|
const copy = new Ctor();
|
|
18596
18713
|
copy.element = element.element;
|
|
18597
18714
|
if (!element.isMetaEmpty) {
|
|
18598
|
-
copy.meta =
|
|
18715
|
+
copy.meta = element.meta.cloneDeep();
|
|
18599
18716
|
}
|
|
18600
18717
|
if (!element.isAttributesEmpty) {
|
|
18601
18718
|
copy.attributes = cloneDeep(element.attributes);
|
|
@@ -18623,8 +18740,8 @@ const cloneShallowElement = element => {
|
|
|
18623
18740
|
|
|
18624
18741
|
/**
|
|
18625
18742
|
* Creates a shallow clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
|
|
18626
|
-
* The element itself is cloned, but content references are shared
|
|
18627
|
-
*
|
|
18743
|
+
* The element itself is cloned, but content references are shared.
|
|
18744
|
+
* Meta and attributes are deep cloned to preserve semantic information.
|
|
18628
18745
|
* @public
|
|
18629
18746
|
*/
|
|
18630
18747
|
const cloneShallow = value => {
|
|
@@ -19686,7 +19803,7 @@ class CollectionElement extends _Element_mjs__WEBPACK_IMPORTED_MODULE_0__["defau
|
|
|
19686
19803
|
* Search the tree recursively and find the element with the matching ID.
|
|
19687
19804
|
*/
|
|
19688
19805
|
getById(id) {
|
|
19689
|
-
return this.find(item => item.id
|
|
19806
|
+
return this.find(item => item.id === id).first;
|
|
19690
19807
|
}
|
|
19691
19808
|
|
|
19692
19809
|
/**
|
|
@@ -19715,18 +19832,24 @@ class CollectionElement extends _Element_mjs__WEBPACK_IMPORTED_MODULE_0__["defau
|
|
|
19715
19832
|
|
|
19716
19833
|
__webpack_require__.r(__webpack_exports__);
|
|
19717
19834
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
19835
|
+
/* harmony export */ Metadata: () => (/* reexport safe */ _Metadata_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]),
|
|
19718
19836
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
19719
19837
|
/* harmony export */ });
|
|
19720
19838
|
/* harmony import */ var ramda__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3654);
|
|
19721
|
-
/* harmony import */ var
|
|
19722
|
-
/* harmony import */ var
|
|
19839
|
+
/* harmony import */ var _Metadata_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1844);
|
|
19840
|
+
/* harmony import */ var _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6663);
|
|
19841
|
+
/* harmony import */ var _ObjectSlice_mjs__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8504);
|
|
19723
19842
|
|
|
19724
19843
|
|
|
19725
19844
|
|
|
19845
|
+
// shared singleton for frozen elements with no meta — avoids allocation on every access
|
|
19846
|
+
const FROZEN_EMPTY_METADATA = Object.freeze(new _Metadata_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]());
|
|
19847
|
+
|
|
19726
19848
|
/**
|
|
19727
19849
|
* Valid content types for an Element.
|
|
19728
19850
|
* @public
|
|
19729
19851
|
*/
|
|
19852
|
+
|
|
19730
19853
|
/**
|
|
19731
19854
|
* Base Element class that all ApiDOM elements extend.
|
|
19732
19855
|
*
|
|
@@ -19824,7 +19947,7 @@ class Element {
|
|
|
19824
19947
|
_attributes;
|
|
19825
19948
|
|
|
19826
19949
|
// ============================================================
|
|
19827
|
-
// Prototype-assigned properties (set in
|
|
19950
|
+
// Prototype-assigned properties (set in registration.ts)
|
|
19828
19951
|
// Using 'declare' allows TypeScript to know about these
|
|
19829
19952
|
// without generating runtime code.
|
|
19830
19953
|
// ============================================================
|
|
@@ -19885,13 +20008,13 @@ class Element {
|
|
|
19885
20008
|
}
|
|
19886
20009
|
|
|
19887
20010
|
// KeyValuePair
|
|
19888
|
-
if (value instanceof
|
|
20011
|
+
if (value instanceof _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_2__["default"]) {
|
|
19889
20012
|
this._content = value;
|
|
19890
20013
|
return;
|
|
19891
20014
|
}
|
|
19892
20015
|
|
|
19893
20016
|
// ObjectSlice - extract elements array
|
|
19894
|
-
if (value instanceof
|
|
20017
|
+
if (value instanceof _ObjectSlice_mjs__WEBPACK_IMPORTED_MODULE_3__["default"]) {
|
|
19895
20018
|
this._content = value.elements;
|
|
19896
20019
|
return;
|
|
19897
20020
|
}
|
|
@@ -19912,24 +20035,22 @@ class Element {
|
|
|
19912
20035
|
|
|
19913
20036
|
/**
|
|
19914
20037
|
* Metadata about this element (id, classes, title, description, links).
|
|
19915
|
-
* Lazily creates
|
|
20038
|
+
* Lazily creates a Metadata instance if not set.
|
|
19916
20039
|
*/
|
|
19917
20040
|
get meta() {
|
|
19918
20041
|
if (!this._meta) {
|
|
19919
|
-
if (this.isFrozen)
|
|
19920
|
-
|
|
19921
|
-
meta.freeze();
|
|
19922
|
-
return meta;
|
|
19923
|
-
}
|
|
19924
|
-
this._meta = new this.ObjectElement();
|
|
20042
|
+
if (this.isFrozen) return FROZEN_EMPTY_METADATA;
|
|
20043
|
+
this._meta = new _Metadata_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]();
|
|
19925
20044
|
}
|
|
19926
20045
|
return this._meta;
|
|
19927
20046
|
}
|
|
19928
20047
|
set meta(value) {
|
|
19929
|
-
if (value instanceof
|
|
20048
|
+
if (value instanceof _Metadata_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]) {
|
|
19930
20049
|
this._meta = value;
|
|
19931
|
-
} else {
|
|
19932
|
-
|
|
20050
|
+
} else if (value && typeof value === 'object') {
|
|
20051
|
+
const meta = new _Metadata_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]();
|
|
20052
|
+
Object.assign(meta, value);
|
|
20053
|
+
this._meta = meta;
|
|
19933
20054
|
}
|
|
19934
20055
|
}
|
|
19935
20056
|
|
|
@@ -19962,10 +20083,8 @@ class Element {
|
|
|
19962
20083
|
|
|
19963
20084
|
/** Unique identifier for this element. */
|
|
19964
20085
|
get id() {
|
|
19965
|
-
if (this.isFrozen) {
|
|
19966
|
-
return this.getMetaProperty('id', '');
|
|
19967
|
-
}
|
|
19968
20086
|
if (!this.hasMetaProperty('id')) {
|
|
20087
|
+
if (this.isFrozen) return '';
|
|
19969
20088
|
this.setMetaProperty('id', '');
|
|
19970
20089
|
}
|
|
19971
20090
|
return this.meta.get('id');
|
|
@@ -19976,10 +20095,8 @@ class Element {
|
|
|
19976
20095
|
|
|
19977
20096
|
/** CSS-like class names. */
|
|
19978
20097
|
get classes() {
|
|
19979
|
-
if (this.isFrozen) {
|
|
19980
|
-
return this.getMetaProperty('classes', []);
|
|
19981
|
-
}
|
|
19982
20098
|
if (!this.hasMetaProperty('classes')) {
|
|
20099
|
+
if (this.isFrozen) return [];
|
|
19983
20100
|
this.setMetaProperty('classes', []);
|
|
19984
20101
|
}
|
|
19985
20102
|
return this.meta.get('classes');
|
|
@@ -19990,11 +20107,13 @@ class Element {
|
|
|
19990
20107
|
|
|
19991
20108
|
/** Hyperlinks associated with this element. */
|
|
19992
20109
|
get links() {
|
|
19993
|
-
if (this.isFrozen) {
|
|
19994
|
-
return this.getMetaProperty('links', []);
|
|
19995
|
-
}
|
|
19996
20110
|
if (!this.hasMetaProperty('links')) {
|
|
19997
|
-
this.
|
|
20111
|
+
if (this.isFrozen) {
|
|
20112
|
+
const empty = new this.ArrayElement();
|
|
20113
|
+
empty.freeze();
|
|
20114
|
+
return empty;
|
|
20115
|
+
}
|
|
20116
|
+
this.setMetaProperty('links', new this.ArrayElement());
|
|
19998
20117
|
}
|
|
19999
20118
|
return this.meta.get('links');
|
|
20000
20119
|
}
|
|
@@ -20014,7 +20133,7 @@ class Element {
|
|
|
20014
20133
|
if (Array.isArray(content)) {
|
|
20015
20134
|
return content;
|
|
20016
20135
|
}
|
|
20017
|
-
if (content instanceof
|
|
20136
|
+
if (content instanceof _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_2__["default"]) {
|
|
20018
20137
|
const children = [];
|
|
20019
20138
|
if (content.key) children.push(content.key);
|
|
20020
20139
|
if (content.value) children.push(content.value);
|
|
@@ -20044,7 +20163,6 @@ class Element {
|
|
|
20044
20163
|
|
|
20045
20164
|
// Freeze meta and attributes
|
|
20046
20165
|
if (this._meta) {
|
|
20047
|
-
this._meta.parent = this;
|
|
20048
20166
|
this._meta.freeze();
|
|
20049
20167
|
}
|
|
20050
20168
|
if (this._attributes) {
|
|
@@ -20079,7 +20197,7 @@ class Element {
|
|
|
20079
20197
|
if (_content instanceof Element) {
|
|
20080
20198
|
return _content.toValue();
|
|
20081
20199
|
}
|
|
20082
|
-
if (_content instanceof
|
|
20200
|
+
if (_content instanceof _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_2__["default"]) {
|
|
20083
20201
|
return _content.toValue();
|
|
20084
20202
|
}
|
|
20085
20203
|
if (Array.isArray(_content)) {
|
|
@@ -20135,7 +20253,7 @@ class Element {
|
|
|
20135
20253
|
* @throws Error if this element has no ID
|
|
20136
20254
|
*/
|
|
20137
20255
|
toRef(path) {
|
|
20138
|
-
const idValue = this.id
|
|
20256
|
+
const idValue = this.id;
|
|
20139
20257
|
if (idValue === '') {
|
|
20140
20258
|
throw new Error('Cannot create reference to an element without an ID');
|
|
20141
20259
|
}
|
|
@@ -20147,26 +20265,16 @@ class Element {
|
|
|
20147
20265
|
}
|
|
20148
20266
|
|
|
20149
20267
|
/**
|
|
20150
|
-
* Gets a meta property.
|
|
20268
|
+
* Gets a meta property value.
|
|
20151
20269
|
*
|
|
20152
20270
|
* When the property doesn't exist:
|
|
20153
|
-
* - With defaultValue: returns
|
|
20271
|
+
* - With defaultValue: returns the provided default value
|
|
20154
20272
|
* - Without defaultValue: returns undefined
|
|
20155
|
-
*
|
|
20156
|
-
* Note: Each call with a default creates a new instance. Use setMetaProperty
|
|
20157
|
-
* first if you need reference equality across multiple accesses.
|
|
20158
20273
|
*/
|
|
20159
20274
|
|
|
20160
20275
|
getMetaProperty(name, defaultValue) {
|
|
20161
20276
|
if (!this.hasMetaProperty(name)) {
|
|
20162
|
-
|
|
20163
|
-
return undefined;
|
|
20164
|
-
}
|
|
20165
|
-
const element = this.refract(defaultValue);
|
|
20166
|
-
if (element && this.isFrozen) {
|
|
20167
|
-
element.freeze();
|
|
20168
|
-
}
|
|
20169
|
-
return element;
|
|
20277
|
+
return defaultValue;
|
|
20170
20278
|
}
|
|
20171
20279
|
return this.meta.get(name);
|
|
20172
20280
|
}
|
|
@@ -20179,20 +20287,17 @@ class Element {
|
|
|
20179
20287
|
}
|
|
20180
20288
|
|
|
20181
20289
|
/**
|
|
20182
|
-
*
|
|
20290
|
+
* Checks whether a meta property exists.
|
|
20183
20291
|
*/
|
|
20184
20292
|
hasMetaProperty(name) {
|
|
20185
|
-
|
|
20186
|
-
return this.meta.hasKey(name);
|
|
20187
|
-
}
|
|
20188
|
-
return false;
|
|
20293
|
+
return this._meta !== undefined && this._meta.hasKey(name);
|
|
20189
20294
|
}
|
|
20190
20295
|
|
|
20191
20296
|
/**
|
|
20192
20297
|
* Checks if meta is empty.
|
|
20193
20298
|
*/
|
|
20194
20299
|
get isMetaEmpty() {
|
|
20195
|
-
return this._meta === undefined || this.
|
|
20300
|
+
return this._meta === undefined || this._meta.isEmpty;
|
|
20196
20301
|
}
|
|
20197
20302
|
|
|
20198
20303
|
/**
|
|
@@ -20218,7 +20323,7 @@ class Element {
|
|
|
20218
20323
|
}
|
|
20219
20324
|
|
|
20220
20325
|
/**
|
|
20221
|
-
*
|
|
20326
|
+
* Checks whether an attributes property exists.
|
|
20222
20327
|
*/
|
|
20223
20328
|
hasAttributesProperty(name) {
|
|
20224
20329
|
if (!this.isAttributesEmpty) {
|
|
@@ -20237,6 +20342,7 @@ class Element {
|
|
|
20237
20342
|
|
|
20238
20343
|
// Re-export types for convenience
|
|
20239
20344
|
|
|
20345
|
+
|
|
20240
20346
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Element);
|
|
20241
20347
|
|
|
20242
20348
|
/***/ },
|
|
@@ -20669,6 +20775,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
20669
20775
|
/* harmony import */ var _elements_Style_mjs__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(9686);
|
|
20670
20776
|
/* harmony import */ var _ObjectSlice_mjs__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(8504);
|
|
20671
20777
|
/* harmony import */ var _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(6663);
|
|
20778
|
+
/* harmony import */ var _Metadata_mjs__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(1844);
|
|
20779
|
+
/* harmony import */ var _clone_index_mjs__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(2111);
|
|
20780
|
+
|
|
20781
|
+
|
|
20672
20782
|
|
|
20673
20783
|
|
|
20674
20784
|
|
|
@@ -20728,14 +20838,16 @@ function refract(value) {
|
|
|
20728
20838
|
}
|
|
20729
20839
|
|
|
20730
20840
|
// Set up prototype assignments for circular dependency resolution.
|
|
20731
|
-
// These allow Element instances to
|
|
20732
|
-
//
|
|
20841
|
+
// These allow Element and Metadata instances to reference classes they can't import
|
|
20842
|
+
// directly (which would cause circular imports).
|
|
20733
20843
|
// Using 'declare' in the class definitions enables type-safe access to these properties.
|
|
20734
20844
|
_primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.ObjectElement = _primitives_ObjectElement_mjs__WEBPACK_IMPORTED_MODULE_8__["default"];
|
|
20735
20845
|
_primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.ArrayElement = _primitives_ArrayElement_mjs__WEBPACK_IMPORTED_MODULE_6__["default"];
|
|
20736
20846
|
_primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.RefElement = _elements_RefElement_mjs__WEBPACK_IMPORTED_MODULE_10__["default"];
|
|
20737
20847
|
_primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.MemberElement = _primitives_MemberElement_mjs__WEBPACK_IMPORTED_MODULE_7__["default"];
|
|
20738
20848
|
_primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.refract = refract;
|
|
20849
|
+
_Metadata_mjs__WEBPACK_IMPORTED_MODULE_18__["default"].prototype.Element = _primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"];
|
|
20850
|
+
_Metadata_mjs__WEBPACK_IMPORTED_MODULE_18__["default"].prototype.cloneDeepElement = element => (0,_clone_index_mjs__WEBPACK_IMPORTED_MODULE_19__.cloneDeep)(element);
|
|
20739
20851
|
|
|
20740
20852
|
/**
|
|
20741
20853
|
* Contains all of the element classes, and related structures and methods
|
|
@@ -20799,7 +20911,13 @@ class JSONSerialiser {
|
|
|
20799
20911
|
element: element.element
|
|
20800
20912
|
};
|
|
20801
20913
|
if (!element.isMetaEmpty) {
|
|
20802
|
-
|
|
20914
|
+
const serialisedMeta = this.serialiseMeta(element);
|
|
20915
|
+
if (serialisedMeta) {
|
|
20916
|
+
payload.meta = serialisedMeta.meta;
|
|
20917
|
+
if (serialisedMeta.rawKeys.length > 0) {
|
|
20918
|
+
payload.__meta_raw__ = serialisedMeta.rawKeys;
|
|
20919
|
+
}
|
|
20920
|
+
}
|
|
20803
20921
|
}
|
|
20804
20922
|
if (!element.isAttributesEmpty) {
|
|
20805
20923
|
payload.attributes = this.serialiseObject(element.attributes);
|
|
@@ -20846,7 +20964,7 @@ class JSONSerialiser {
|
|
|
20846
20964
|
element.element = value.element;
|
|
20847
20965
|
}
|
|
20848
20966
|
|
|
20849
|
-
// Extract
|
|
20967
|
+
// Extract special meta keys without mutating input, filter remaining meta
|
|
20850
20968
|
let mappingsDoc;
|
|
20851
20969
|
let stylesDoc;
|
|
20852
20970
|
let metaToDeserialize = value.meta;
|
|
@@ -20860,8 +20978,15 @@ class JSONSerialiser {
|
|
|
20860
20978
|
stylesDoc = __styles__;
|
|
20861
20979
|
metaToDeserialize = Object.keys(rest).length > 0 ? rest : undefined;
|
|
20862
20980
|
}
|
|
20981
|
+
|
|
20982
|
+
// determine which meta keys were raw primitives before serialization
|
|
20983
|
+
const rawKeys = value.__meta_raw__ ? new Set(value.__meta_raw__) : undefined;
|
|
20863
20984
|
if (metaToDeserialize) {
|
|
20864
|
-
|
|
20985
|
+
for (const [key, doc] of Object.entries(metaToDeserialize)) {
|
|
20986
|
+
const deserialized = this.deserialise(doc);
|
|
20987
|
+
// unwrap keys that were raw primitives before serialization
|
|
20988
|
+
element.setMetaProperty(key, rawKeys?.has(key) ? deserialized.toValue() : deserialized);
|
|
20989
|
+
}
|
|
20865
20990
|
}
|
|
20866
20991
|
|
|
20867
20992
|
// Restore source position from __mappings__
|
|
@@ -20924,6 +21049,27 @@ class JSONSerialiser {
|
|
|
20924
21049
|
}
|
|
20925
21050
|
return content;
|
|
20926
21051
|
}
|
|
21052
|
+
serialiseMeta(element) {
|
|
21053
|
+
const meta = {};
|
|
21054
|
+
const rawKeys = [];
|
|
21055
|
+
let hasEntries = false;
|
|
21056
|
+
for (const [key, value] of Object.entries(element.meta)) {
|
|
21057
|
+
if (value instanceof this.namespace.elements.Element) {
|
|
21058
|
+
meta[key] = this.serialise(value);
|
|
21059
|
+
hasEntries = true;
|
|
21060
|
+
} else if (value !== undefined) {
|
|
21061
|
+
// refract primitives to maintain JSON Refract spec compatibility
|
|
21062
|
+
const refracted = element.refract(value);
|
|
21063
|
+
meta[key] = this.serialise(refracted);
|
|
21064
|
+
rawKeys.push(key);
|
|
21065
|
+
hasEntries = true;
|
|
21066
|
+
}
|
|
21067
|
+
}
|
|
21068
|
+
return hasEntries ? {
|
|
21069
|
+
meta,
|
|
21070
|
+
rawKeys
|
|
21071
|
+
} : undefined;
|
|
21072
|
+
}
|
|
20927
21073
|
serialiseObject(obj) {
|
|
20928
21074
|
const result = {};
|
|
20929
21075
|
obj.forEach((value, key) => {
|