@rebasepro/common 0.1.0 → 0.2.1
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/LICENSE +1 -1
- package/README.md +178 -110
- package/dist/index.es.js +71 -9
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +72 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/util/entities.d.ts +2 -2
- package/dist/util/relations.d.ts +1 -1
- package/package.json +12 -15
- package/src/collections/CollectionRegistry.d.ts +56 -0
- package/src/collections/CollectionRegistry.ts +17 -42
- package/src/collections/index.d.ts +1 -0
- package/src/data/buildRebaseData.d.ts +14 -0
- package/src/index.d.ts +3 -0
- package/src/types/json-logic-js.d.ts +1 -1
- package/src/util/builders.d.ts +57 -0
- package/src/util/builders.ts +1 -0
- package/src/util/callbacks.d.ts +6 -0
- package/src/util/collections.d.ts +11 -0
- package/src/util/common.d.ts +2 -0
- package/src/util/conditions.d.ts +26 -0
- package/src/util/entities.d.ts +58 -0
- package/src/util/entities.ts +6 -2
- package/src/util/enums.d.ts +3 -0
- package/src/util/index.d.ts +16 -0
- package/src/util/navigation_from_path.d.ts +34 -0
- package/src/util/navigation_utils.d.ts +20 -0
- package/src/util/parent_references_from_path.d.ts +6 -0
- package/src/util/paths.d.ts +14 -0
- package/src/util/permissions.d.ts +5 -0
- package/src/util/references.d.ts +2 -0
- package/src/util/relations.d.ts +22 -0
- package/src/util/relations.ts +69 -8
- package/src/util/resolutions.d.ts +72 -0
- package/src/util/resolutions.ts +3 -3
- package/src/util/storage.d.ts +24 -0
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@rebasepro/types"), require("@rebasepro/utils"), require("json-logic-js"), require("fast-equals")
|
|
3
|
-
})(this, function(exports2, types, utils, jsonLogic, fastEquals
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@rebasepro/types"), require("@rebasepro/utils"), require("json-logic-js"), require("fast-equals")) : typeof define === "function" && define.amd ? define(["exports", "@rebasepro/types", "@rebasepro/utils", "json-logic-js", "fast-equals"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase Util"] = {}, global.types, global.utils, global.jsonLogic, global.fastEquals));
|
|
3
|
+
})(this, function(exports2, types, utils, jsonLogic, fastEquals) {
|
|
4
4
|
"use strict";
|
|
5
5
|
const DEFAULT_ONE_OF_TYPE = "type";
|
|
6
6
|
const DEFAULT_ONE_OF_VALUE = "value";
|
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
return [];
|
|
60
60
|
} else if (type === "map") {
|
|
61
61
|
return {};
|
|
62
|
+
} else if (type === "vector") {
|
|
63
|
+
return null;
|
|
64
|
+
} else if (type === "binary") {
|
|
65
|
+
return null;
|
|
62
66
|
} else {
|
|
63
67
|
return null;
|
|
64
68
|
}
|
|
@@ -1170,14 +1174,56 @@
|
|
|
1170
1174
|
}
|
|
1171
1175
|
return Object.keys(propertyCallbacks).length > 0 ? propertyCallbacks : void 0;
|
|
1172
1176
|
};
|
|
1173
|
-
function sanitizeRelation(relation, sourceCollection) {
|
|
1177
|
+
function sanitizeRelation(relation, sourceCollection, resolveCollection) {
|
|
1174
1178
|
if (!relation.target) {
|
|
1175
1179
|
throw new Error("Relation is missing a `target` collection.");
|
|
1176
1180
|
}
|
|
1177
|
-
const
|
|
1181
|
+
const rawTarget = relation.target;
|
|
1182
|
+
let targetCollection;
|
|
1183
|
+
if (typeof rawTarget === "string") {
|
|
1184
|
+
if (resolveCollection) {
|
|
1185
|
+
targetCollection = resolveCollection(rawTarget);
|
|
1186
|
+
}
|
|
1187
|
+
if (!targetCollection) {
|
|
1188
|
+
targetCollection = {
|
|
1189
|
+
slug: rawTarget,
|
|
1190
|
+
name: rawTarget
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
} else if (typeof rawTarget === "function") {
|
|
1194
|
+
const evaluated = rawTarget();
|
|
1195
|
+
if (typeof evaluated === "string") {
|
|
1196
|
+
if (resolveCollection) {
|
|
1197
|
+
targetCollection = resolveCollection(evaluated);
|
|
1198
|
+
}
|
|
1199
|
+
if (!targetCollection) {
|
|
1200
|
+
targetCollection = {
|
|
1201
|
+
slug: evaluated,
|
|
1202
|
+
name: evaluated
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
} else {
|
|
1206
|
+
targetCollection = evaluated;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (!targetCollection) {
|
|
1210
|
+
throw new Error("Relation is missing a valid `target` collection.");
|
|
1211
|
+
}
|
|
1178
1212
|
const newRelation = {
|
|
1179
1213
|
...relation
|
|
1180
1214
|
};
|
|
1215
|
+
newRelation.target = () => {
|
|
1216
|
+
if (typeof rawTarget === "string") {
|
|
1217
|
+
return resolveCollection && resolveCollection(rawTarget) || targetCollection;
|
|
1218
|
+
} else if (typeof rawTarget === "function") {
|
|
1219
|
+
const evaluated = rawTarget();
|
|
1220
|
+
if (typeof evaluated === "string") {
|
|
1221
|
+
return resolveCollection && resolveCollection(evaluated) || targetCollection;
|
|
1222
|
+
}
|
|
1223
|
+
return evaluated;
|
|
1224
|
+
}
|
|
1225
|
+
return targetCollection;
|
|
1226
|
+
};
|
|
1181
1227
|
if (!newRelation.relationName) {
|
|
1182
1228
|
newRelation.relationName = utils.toSnakeCase(targetCollection.slug);
|
|
1183
1229
|
}
|
|
@@ -1230,6 +1276,17 @@
|
|
|
1230
1276
|
break;
|
|
1231
1277
|
}
|
|
1232
1278
|
}
|
|
1279
|
+
if (!isManyToManyInverse && targetCollection.properties) {
|
|
1280
|
+
for (const [propKey, prop] of Object.entries(targetCollection.properties)) {
|
|
1281
|
+
if (prop.type !== "relation") continue;
|
|
1282
|
+
const relProp = prop;
|
|
1283
|
+
const relName = relProp.relationName || propKey;
|
|
1284
|
+
if (relName === newRelation.inverseRelationName && relProp.cardinality === "many" && (relProp.direction === "owning" || !relProp.direction)) {
|
|
1285
|
+
isManyToManyInverse = true;
|
|
1286
|
+
break;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1233
1290
|
} catch (e) {
|
|
1234
1291
|
}
|
|
1235
1292
|
}
|
|
@@ -1597,11 +1654,17 @@
|
|
|
1597
1654
|
return false;
|
|
1598
1655
|
}
|
|
1599
1656
|
this.reset();
|
|
1657
|
+
collections.forEach((c) => {
|
|
1658
|
+
if (c.slug) {
|
|
1659
|
+
this.collectionsBySlug.set(c.slug, c);
|
|
1660
|
+
}
|
|
1661
|
+
this.collectionsByTableName.set(getTableName(c), c);
|
|
1662
|
+
});
|
|
1600
1663
|
const normalizedCollections = collections.map((c) => this.normalizeCollection({
|
|
1601
1664
|
...c
|
|
1602
1665
|
}));
|
|
1603
1666
|
normalizedCollections.forEach((c, index) => {
|
|
1604
|
-
const raw =
|
|
1667
|
+
const raw = utils.deepClone(collections[index]);
|
|
1605
1668
|
this.rootCollections.push(c);
|
|
1606
1669
|
this.rawRootCollections.push(raw);
|
|
1607
1670
|
const normalized = this.normalizeCollection(c);
|
|
@@ -1621,7 +1684,7 @@
|
|
|
1621
1684
|
if (!subCollection) return;
|
|
1622
1685
|
this._registerRecursively(this.normalizeCollection({
|
|
1623
1686
|
...subCollection
|
|
1624
|
-
}),
|
|
1687
|
+
}), utils.deepClone(subCollection));
|
|
1625
1688
|
});
|
|
1626
1689
|
}
|
|
1627
1690
|
});
|
|
@@ -1629,7 +1692,7 @@
|
|
|
1629
1692
|
return true;
|
|
1630
1693
|
}
|
|
1631
1694
|
register(collection, rawCollection) {
|
|
1632
|
-
const raw = rawCollection ?
|
|
1695
|
+
const raw = rawCollection ? utils.deepClone(rawCollection) : utils.deepClone(collection);
|
|
1633
1696
|
this.rootCollections.push(collection);
|
|
1634
1697
|
this.rawRootCollections.push(raw);
|
|
1635
1698
|
this._registerRecursively(collection, raw);
|
|
@@ -1653,7 +1716,7 @@
|
|
|
1653
1716
|
if (!subCollection) return;
|
|
1654
1717
|
this._registerRecursively(this.normalizeCollection({
|
|
1655
1718
|
...subCollection
|
|
1656
|
-
}),
|
|
1719
|
+
}), utils.deepClone(subCollection));
|
|
1657
1720
|
});
|
|
1658
1721
|
}
|
|
1659
1722
|
}
|
|
@@ -1675,7 +1738,7 @@
|
|
|
1675
1738
|
if (types.getDataSourceCapabilities(result.driver).supportsRelations) {
|
|
1676
1739
|
mergedRelations = mergedRelationsRaw.map((r) => {
|
|
1677
1740
|
try {
|
|
1678
|
-
return sanitizeRelation(r, result);
|
|
1741
|
+
return sanitizeRelation(r, result, (slug) => this.get(slug));
|
|
1679
1742
|
} catch {
|
|
1680
1743
|
return r;
|
|
1681
1744
|
}
|