@rebasepro/types 0.20.0 → 0.20.1-canary.g4d882ca
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js
CHANGED
|
@@ -574,23 +574,41 @@ function nestAdminKeysOf(source, adminKeys) {
|
|
|
574
574
|
function nestAdminCollectionKeys(collection) {
|
|
575
575
|
return nestAdminKeysOf(collection, ADMIN_COLLECTION_KEYS);
|
|
576
576
|
}
|
|
577
|
+
/** A record of properties, keyed by name — a map's `properties`, or a `oneOf` block's. */
|
|
578
|
+
function nestEachProperty(properties) {
|
|
579
|
+
return Object.fromEntries(Object.entries(properties).map(([key, child]) => [key, isNestable(child) ? nestAdminPropertyKeys(child) : child]));
|
|
580
|
+
}
|
|
581
|
+
/** Anything the walk can descend into: a plain object, not an array. */
|
|
582
|
+
function isNestable(value) {
|
|
583
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
584
|
+
}
|
|
577
585
|
/**
|
|
578
586
|
* {@link nestAdminKeysOf} for a property, applied to its children too.
|
|
579
587
|
*
|
|
580
|
-
* A map property carries `properties`, an array property carries `of`, and
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
588
|
+
* A map property carries `properties`, an array property carries `of`, and an
|
|
589
|
+
* array of typed blocks carries `oneOf.properties` — a record of properties like
|
|
590
|
+
* a map's. All of them hold properties with `admin` blocks of their own. A flat
|
|
591
|
+
* `readOnly` left on a child is as dead — and as fatal at the next boot — as one
|
|
592
|
+
* left on the parent, so the walk goes all the way down.
|
|
593
|
+
*
|
|
594
|
+
* `oneOf` was the container this walk did not know about, and it is the one the
|
|
595
|
+
* block-based collection templates are built out of: every block inside them
|
|
596
|
+
* kept its flat `markdown`, and the collection they created would not boot.
|
|
584
597
|
*
|
|
585
598
|
* @group Models
|
|
586
599
|
*/
|
|
587
600
|
function nestAdminPropertyKeys(property) {
|
|
588
601
|
const nested = nestAdminKeysOf(property, ADMIN_PROPERTY_KEYS);
|
|
589
602
|
const children = nested.properties;
|
|
590
|
-
if (
|
|
603
|
+
if (isNestable(children)) nested.properties = nestEachProperty(children);
|
|
604
|
+
const oneOf = nested.oneOf;
|
|
605
|
+
if (isNestable(oneOf) && isNestable(oneOf.properties)) nested.oneOf = {
|
|
606
|
+
...oneOf,
|
|
607
|
+
properties: nestEachProperty(oneOf.properties)
|
|
608
|
+
};
|
|
591
609
|
const of = nested.of;
|
|
592
|
-
if (Array.isArray(of)) nested.of = of.map((entry) =>
|
|
593
|
-
else if (of
|
|
610
|
+
if (Array.isArray(of)) nested.of = of.map((entry) => isNestable(entry) ? nestAdminPropertyKeys(entry) : entry);
|
|
611
|
+
else if (isNestable(of)) nested.of = nestAdminPropertyKeys(of);
|
|
594
612
|
return nested;
|
|
595
613
|
}
|
|
596
614
|
//#endregion
|