@rebasepro/common 0.1.2 → 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/dist/index.es.js +66 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +66 -3
- 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 -14
- package/src/collections/CollectionRegistry.d.ts +56 -0
- package/src/collections/CollectionRegistry.ts +12 -36
- 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
|
@@ -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,6 +1654,12 @@
|
|
|
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
|
}));
|
|
@@ -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
|
}
|