@strapi/database 5.12.0 → 5.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/dist/connection.js +43 -0
- package/dist/connection.js.map +1 -0
- package/dist/connection.mjs +41 -0
- package/dist/connection.mjs.map +1 -0
- package/dist/dialects/dialect.js +54 -0
- package/dist/dialects/dialect.js.map +1 -0
- package/dist/dialects/dialect.mjs +52 -0
- package/dist/dialects/dialect.mjs.map +1 -0
- package/dist/dialects/index.js +44 -0
- package/dist/dialects/index.js.map +1 -0
- package/dist/dialects/index.mjs +42 -0
- package/dist/dialects/index.mjs.map +1 -0
- package/dist/dialects/mysql/constants.js +8 -0
- package/dist/dialects/mysql/constants.js.map +1 -0
- package/dist/dialects/mysql/constants.mjs +5 -0
- package/dist/dialects/mysql/constants.mjs.map +1 -0
- package/dist/dialects/mysql/database-inspector.js +35 -0
- package/dist/dialects/mysql/database-inspector.js.map +1 -0
- package/dist/dialects/mysql/database-inspector.mjs +33 -0
- package/dist/dialects/mysql/database-inspector.mjs.map +1 -0
- package/dist/dialects/mysql/index.js +75 -0
- package/dist/dialects/mysql/index.js.map +1 -0
- package/dist/dialects/mysql/index.mjs +73 -0
- package/dist/dialects/mysql/index.mjs.map +1 -0
- package/dist/dialects/mysql/schema-inspector.js +297 -0
- package/dist/dialects/mysql/schema-inspector.js.map +1 -0
- package/dist/dialects/mysql/schema-inspector.mjs +295 -0
- package/dist/dialects/mysql/schema-inspector.mjs.map +1 -0
- package/dist/dialects/postgresql/index.js +62 -0
- package/dist/dialects/postgresql/index.js.map +1 -0
- package/dist/dialects/postgresql/index.mjs +60 -0
- package/dist/dialects/postgresql/index.mjs.map +1 -0
- package/dist/dialects/postgresql/schema-inspector.js +316 -0
- package/dist/dialects/postgresql/schema-inspector.js.map +1 -0
- package/dist/dialects/postgresql/schema-inspector.mjs +314 -0
- package/dist/dialects/postgresql/schema-inspector.mjs.map +1 -0
- package/dist/dialects/sqlite/index.js +82 -0
- package/dist/dialects/sqlite/index.js.map +1 -0
- package/dist/dialects/sqlite/index.mjs +80 -0
- package/dist/dialects/sqlite/index.mjs.map +1 -0
- package/dist/dialects/sqlite/schema-inspector.js +211 -0
- package/dist/dialects/sqlite/schema-inspector.js.map +1 -0
- package/dist/dialects/sqlite/schema-inspector.mjs +209 -0
- package/dist/dialects/sqlite/schema-inspector.mjs.map +1 -0
- package/dist/entity-manager/entity-repository.js +139 -0
- package/dist/entity-manager/entity-repository.js.map +1 -0
- package/dist/entity-manager/entity-repository.mjs +137 -0
- package/dist/entity-manager/entity-repository.mjs.map +1 -0
- package/dist/entity-manager/index.js +1186 -0
- package/dist/entity-manager/index.js.map +1 -0
- package/dist/entity-manager/index.mjs +1184 -0
- package/dist/entity-manager/index.mjs.map +1 -0
- package/dist/entity-manager/morph-relations.js +73 -0
- package/dist/entity-manager/morph-relations.js.map +1 -0
- package/dist/entity-manager/morph-relations.mjs +69 -0
- package/dist/entity-manager/morph-relations.mjs.map +1 -0
- package/dist/entity-manager/regular-relations.js +247 -0
- package/dist/entity-manager/regular-relations.js.map +1 -0
- package/dist/entity-manager/regular-relations.mjs +242 -0
- package/dist/entity-manager/regular-relations.mjs.map +1 -0
- package/dist/entity-manager/relations-orderer.js +221 -0
- package/dist/entity-manager/relations-orderer.js.map +1 -0
- package/dist/entity-manager/relations-orderer.mjs +218 -0
- package/dist/entity-manager/relations-orderer.mjs.map +1 -0
- package/dist/errors/database.js +13 -0
- package/dist/errors/database.js.map +1 -0
- package/dist/errors/database.mjs +11 -0
- package/dist/errors/database.mjs.map +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/index.mjs +7 -0
- package/dist/errors/index.mjs.map +1 -0
- package/dist/errors/invalid-date.js +13 -0
- package/dist/errors/invalid-date.js.map +1 -0
- package/dist/errors/invalid-date.mjs +11 -0
- package/dist/errors/invalid-date.mjs.map +1 -0
- package/dist/errors/invalid-datetime.js +13 -0
- package/dist/errors/invalid-datetime.js.map +1 -0
- package/dist/errors/invalid-datetime.mjs +11 -0
- package/dist/errors/invalid-datetime.mjs.map +1 -0
- package/dist/errors/invalid-relation.js +13 -0
- package/dist/errors/invalid-relation.js.map +1 -0
- package/dist/errors/invalid-relation.mjs +11 -0
- package/dist/errors/invalid-relation.mjs.map +1 -0
- package/dist/errors/invalid-time.js +13 -0
- package/dist/errors/invalid-time.js.map +1 -0
- package/dist/errors/invalid-time.mjs +11 -0
- package/dist/errors/invalid-time.mjs.map +1 -0
- package/dist/errors/not-null.js +17 -0
- package/dist/errors/not-null.js.map +1 -0
- package/dist/errors/not-null.mjs +15 -0
- package/dist/errors/not-null.mjs.map +1 -0
- package/dist/fields/biginteger.js +9 -0
- package/dist/fields/biginteger.js.map +1 -0
- package/dist/fields/biginteger.mjs +7 -0
- package/dist/fields/biginteger.mjs.map +1 -0
- package/dist/fields/boolean.js +48 -0
- package/dist/fields/boolean.js.map +1 -0
- package/dist/fields/boolean.mjs +46 -0
- package/dist/fields/boolean.mjs.map +1 -0
- package/dist/fields/date.js +16 -0
- package/dist/fields/date.js.map +1 -0
- package/dist/fields/date.mjs +14 -0
- package/dist/fields/date.mjs.map +1 -0
- package/dist/fields/datetime.js +37 -0
- package/dist/fields/datetime.js.map +1 -0
- package/dist/fields/datetime.mjs +16 -0
- package/dist/fields/datetime.mjs.map +1 -0
- package/dist/fields/field.js +16 -0
- package/dist/fields/field.js.map +1 -0
- package/dist/fields/field.mjs +14 -0
- package/dist/fields/field.mjs.map +1 -0
- package/dist/fields/index.js +45 -0
- package/dist/fields/index.js.map +1 -0
- package/dist/fields/index.mjs +43 -0
- package/dist/fields/index.mjs.map +1 -0
- package/dist/fields/json.js +36 -0
- package/dist/fields/json.js.map +1 -0
- package/dist/fields/json.mjs +34 -0
- package/dist/fields/json.mjs.map +1 -0
- package/dist/fields/number.js +20 -0
- package/dist/fields/number.js.map +1 -0
- package/dist/fields/number.mjs +18 -0
- package/dist/fields/number.mjs.map +1 -0
- package/dist/fields/shared/parsers.js +91 -0
- package/dist/fields/shared/parsers.js.map +1 -0
- package/dist/fields/shared/parsers.mjs +68 -0
- package/dist/fields/shared/parsers.mjs.map +1 -0
- package/dist/fields/string.js +16 -0
- package/dist/fields/string.js.map +1 -0
- package/dist/fields/string.mjs +14 -0
- package/dist/fields/string.mjs.map +1 -0
- package/dist/fields/time.js +17 -0
- package/dist/fields/time.js.map +1 -0
- package/dist/fields/time.mjs +15 -0
- package/dist/fields/time.mjs.map +1 -0
- package/dist/fields/timestamp.js +37 -0
- package/dist/fields/timestamp.js.map +1 -0
- package/dist/fields/timestamp.mjs +16 -0
- package/dist/fields/timestamp.mjs.map +1 -0
- package/dist/index.js +33 -8569
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -8532
- package/dist/index.mjs.map +1 -1
- package/dist/lifecycles/index.js +73 -0
- package/dist/lifecycles/index.js.map +1 -0
- package/dist/lifecycles/index.mjs +71 -0
- package/dist/lifecycles/index.mjs.map +1 -0
- package/dist/lifecycles/subscribers/index.js +10 -0
- package/dist/lifecycles/subscribers/index.js.map +1 -0
- package/dist/lifecycles/subscribers/index.mjs +8 -0
- package/dist/lifecycles/subscribers/index.mjs.map +1 -0
- package/dist/lifecycles/subscribers/models-lifecycles.js +13 -0
- package/dist/lifecycles/subscribers/models-lifecycles.js.map +1 -0
- package/dist/lifecycles/subscribers/models-lifecycles.mjs +11 -0
- package/dist/lifecycles/subscribers/models-lifecycles.mjs.map +1 -0
- package/dist/lifecycles/subscribers/timestamps.js +55 -0
- package/dist/lifecycles/subscribers/timestamps.js.map +1 -0
- package/dist/lifecycles/subscribers/timestamps.mjs +53 -0
- package/dist/lifecycles/subscribers/timestamps.mjs.map +1 -0
- package/dist/metadata/index.js +24 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/index.mjs +16 -0
- package/dist/metadata/index.mjs.map +1 -0
- package/dist/metadata/metadata.js +100 -0
- package/dist/metadata/metadata.js.map +1 -0
- package/dist/metadata/metadata.mjs +98 -0
- package/dist/metadata/metadata.mjs.map +1 -0
- package/dist/metadata/relations.js +545 -0
- package/dist/metadata/relations.js.map +1 -0
- package/dist/metadata/relations.mjs +536 -0
- package/dist/metadata/relations.mjs.map +1 -0
- package/dist/migrations/common.js +8 -0
- package/dist/migrations/common.js.map +1 -0
- package/dist/migrations/common.mjs +6 -0
- package/dist/migrations/common.mjs.map +1 -0
- package/dist/migrations/index.js +39 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/index.mjs +37 -0
- package/dist/migrations/index.mjs.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.js +179 -0
- package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.js.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.mjs +177 -0
- package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.mjs.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js +125 -0
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs +123 -0
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-03-locale.js +41 -0
- package/dist/migrations/internal-migrations/5.0.0-03-locale.js.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-03-locale.mjs +39 -0
- package/dist/migrations/internal-migrations/5.0.0-03-locale.mjs.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-04-published-at.js +45 -0
- package/dist/migrations/internal-migrations/5.0.0-04-published-at.js.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-04-published-at.mjs +43 -0
- package/dist/migrations/internal-migrations/5.0.0-04-published-at.mjs.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.js +43 -0
- package/dist/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.js.map +1 -0
- package/dist/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.mjs +41 -0
- package/dist/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.mjs.map +1 -0
- package/dist/migrations/internal-migrations/index.js +26 -0
- package/dist/migrations/internal-migrations/index.js.map +1 -0
- package/dist/migrations/internal-migrations/index.mjs +24 -0
- package/dist/migrations/internal-migrations/index.mjs.map +1 -0
- package/dist/migrations/internal.js +63 -0
- package/dist/migrations/internal.js.map +1 -0
- package/dist/migrations/internal.mjs +61 -0
- package/dist/migrations/internal.mjs.map +1 -0
- package/dist/migrations/logger.js +24 -0
- package/dist/migrations/logger.js.map +1 -0
- package/dist/migrations/logger.mjs +22 -0
- package/dist/migrations/logger.mjs.map +1 -0
- package/dist/migrations/storage.js +39 -0
- package/dist/migrations/storage.js.map +1 -0
- package/dist/migrations/storage.mjs +37 -0
- package/dist/migrations/storage.mjs.map +1 -0
- package/dist/migrations/users.js +87 -0
- package/dist/migrations/users.js.map +1 -0
- package/dist/migrations/users.mjs +85 -0
- package/dist/migrations/users.mjs.map +1 -0
- package/dist/query/helpers/join.js +127 -0
- package/dist/query/helpers/join.js.map +1 -0
- package/dist/query/helpers/join.mjs +122 -0
- package/dist/query/helpers/join.mjs.map +1 -0
- package/dist/query/helpers/order-by.js +167 -0
- package/dist/query/helpers/order-by.js.map +1 -0
- package/dist/query/helpers/order-by.mjs +163 -0
- package/dist/query/helpers/order-by.mjs.map +1 -0
- package/dist/query/helpers/populate/apply.js +592 -0
- package/dist/query/helpers/populate/apply.js.map +1 -0
- package/dist/query/helpers/populate/apply.mjs +590 -0
- package/dist/query/helpers/populate/apply.mjs.map +1 -0
- package/dist/query/helpers/populate/process.js +92 -0
- package/dist/query/helpers/populate/process.js.map +1 -0
- package/dist/query/helpers/populate/process.mjs +90 -0
- package/dist/query/helpers/populate/process.mjs.map +1 -0
- package/dist/query/helpers/search.js +67 -0
- package/dist/query/helpers/search.js.map +1 -0
- package/dist/query/helpers/search.mjs +65 -0
- package/dist/query/helpers/search.mjs.map +1 -0
- package/dist/query/helpers/streams/readable.js +131 -0
- package/dist/query/helpers/streams/readable.js.map +1 -0
- package/dist/query/helpers/streams/readable.mjs +129 -0
- package/dist/query/helpers/streams/readable.mjs.map +1 -0
- package/dist/query/helpers/transform.js +77 -0
- package/dist/query/helpers/transform.js.map +1 -0
- package/dist/query/helpers/transform.mjs +73 -0
- package/dist/query/helpers/transform.mjs.map +1 -0
- package/dist/query/helpers/where.js +372 -0
- package/dist/query/helpers/where.js.map +1 -0
- package/dist/query/helpers/where.mjs +369 -0
- package/dist/query/helpers/where.mjs.map +1 -0
- package/dist/query/query-builder.js +507 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +505 -0
- package/dist/query/query-builder.mjs.map +1 -0
- package/dist/repairs/index.js +13 -0
- package/dist/repairs/index.js.map +1 -0
- package/dist/repairs/index.mjs +11 -0
- package/dist/repairs/index.mjs.map +1 -0
- package/dist/repairs/operations/remove-orphan-morph-types.js +54 -0
- package/dist/repairs/operations/remove-orphan-morph-types.js.map +1 -0
- package/dist/repairs/operations/remove-orphan-morph-types.mjs +52 -0
- package/dist/repairs/operations/remove-orphan-morph-types.mjs.map +1 -0
- package/dist/schema/builder.js +354 -0
- package/dist/schema/builder.js.map +1 -0
- package/dist/schema/builder.mjs +352 -0
- package/dist/schema/builder.mjs.map +1 -0
- package/dist/schema/diff.js +379 -0
- package/dist/schema/diff.js.map +1 -0
- package/dist/schema/diff.mjs +377 -0
- package/dist/schema/diff.mjs.map +1 -0
- package/dist/schema/index.js +93 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/index.mjs +91 -0
- package/dist/schema/index.mjs.map +1 -0
- package/dist/schema/schema.js +266 -0
- package/dist/schema/schema.js.map +1 -0
- package/dist/schema/schema.mjs +264 -0
- package/dist/schema/schema.mjs.map +1 -0
- package/dist/schema/storage.js +58 -0
- package/dist/schema/storage.js.map +1 -0
- package/dist/schema/storage.mjs +56 -0
- package/dist/schema/storage.mjs.map +1 -0
- package/dist/transaction-context.js +65 -0
- package/dist/transaction-context.js.map +1 -0
- package/dist/transaction-context.mjs +63 -0
- package/dist/transaction-context.mjs.map +1 -0
- package/dist/utils/async-curry.js +19 -0
- package/dist/utils/async-curry.js.map +1 -0
- package/dist/utils/async-curry.mjs +17 -0
- package/dist/utils/async-curry.mjs.map +1 -0
- package/dist/utils/identifiers/hash.js +30 -0
- package/dist/utils/identifiers/hash.js.map +1 -0
- package/dist/utils/identifiers/hash.mjs +28 -0
- package/dist/utils/identifiers/hash.mjs.map +1 -0
- package/dist/utils/identifiers/index.js +414 -0
- package/dist/utils/identifiers/index.js.map +1 -0
- package/dist/utils/identifiers/index.mjs +411 -0
- package/dist/utils/identifiers/index.mjs.map +1 -0
- package/dist/utils/knex.js +21 -0
- package/dist/utils/knex.js.map +1 -0
- package/dist/utils/knex.mjs +18 -0
- package/dist/utils/knex.mjs.map +1 -0
- package/dist/utils/types.js +51 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/types.mjs +44 -0
- package/dist/utils/types.mjs.map +1 -0
- package/dist/validations/index.js +12 -0
- package/dist/validations/index.js.map +1 -0
- package/dist/validations/index.mjs +10 -0
- package/dist/validations/index.mjs.map +1 -0
- package/dist/validations/relations/bidirectional.js +64 -0
- package/dist/validations/relations/bidirectional.js.map +1 -0
- package/dist/validations/relations/bidirectional.mjs +62 -0
- package/dist/validations/relations/bidirectional.mjs.map +1 -0
- package/dist/validations/relations/index.js +13 -0
- package/dist/validations/relations/index.js.map +1 -0
- package/dist/validations/relations/index.mjs +11 -0
- package/dist/validations/relations/index.mjs.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash/fp');
|
|
4
|
+
var _$1 = require('lodash');
|
|
5
|
+
var invalidRelation = require('../errors/invalid-relation.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* When connecting relations, the order you connect them matters.
|
|
9
|
+
*
|
|
10
|
+
* Example, if you connect the following relations:
|
|
11
|
+
* { id: 5, position: { before: 1 } }
|
|
12
|
+
* { id: 1, position: { before: 2 } }
|
|
13
|
+
* { id: 2, position: { end: true } }
|
|
14
|
+
*
|
|
15
|
+
* Going through the connect array, id 5 has to be connected before id 1,
|
|
16
|
+
* so the order of id5 = id1 - 1. But the order value of id 1 is unknown.
|
|
17
|
+
* The only way to know the order of id 1 is to connect it first.
|
|
18
|
+
*
|
|
19
|
+
* This function makes sure the relations are connected in the right order:
|
|
20
|
+
* { id: 2, position: { end: true } }
|
|
21
|
+
* { id: 1, position: { before: 2 } }
|
|
22
|
+
* { id: 5, position: { before: 1 } }
|
|
23
|
+
*
|
|
24
|
+
*/ const sortConnectArray = (connectArr, initialArr = [], strictSort = true)=>{
|
|
25
|
+
const sortedConnect = [];
|
|
26
|
+
// Boolean to know if we have to recalculate the order of the relations
|
|
27
|
+
let needsSorting = false;
|
|
28
|
+
// Map to validate if relation is already in sortedConnect or DB.
|
|
29
|
+
const relationInInitialArray = initialArr.reduce((acc, rel)=>({
|
|
30
|
+
...acc,
|
|
31
|
+
[rel.id]: true
|
|
32
|
+
}), {});
|
|
33
|
+
// Map to store the first index where a relation id is connected
|
|
34
|
+
const mappedRelations = connectArr.reduce((mapper, relation)=>{
|
|
35
|
+
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
36
|
+
if (!adjacentRelId || !relationInInitialArray[adjacentRelId] && !mapper[adjacentRelId]) {
|
|
37
|
+
needsSorting = true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* We do not allow duplicate relations to be connected, so we need to check for uniqueness with components
|
|
41
|
+
* Note that the id here includes the uid for polymorphic relations
|
|
42
|
+
*
|
|
43
|
+
* So for normal relations, the same id means the same relation
|
|
44
|
+
* For component relations, it means the unique combo of (id, component name)
|
|
45
|
+
*/ // Check if there's an existing relation with this id
|
|
46
|
+
const existingRelation = mapper[relation.id];
|
|
47
|
+
// Check if existing relation has a component or not
|
|
48
|
+
const hasNoComponent = existingRelation && !('__component' in existingRelation);
|
|
49
|
+
// Check if the existing relation has the same component as the new relation
|
|
50
|
+
const hasSameComponent = existingRelation && existingRelation.__component === relation.__component;
|
|
51
|
+
// If we have an existing relation that is not unique (no component or same component) we won't accept it
|
|
52
|
+
if (existingRelation && (hasNoComponent || hasSameComponent)) {
|
|
53
|
+
throw new invalidRelation(`The relation with id ${relation.id} is already connected. ` + 'You cannot connect the same relation twice.');
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
[relation.id]: {
|
|
57
|
+
...relation,
|
|
58
|
+
computed: false
|
|
59
|
+
},
|
|
60
|
+
...mapper
|
|
61
|
+
};
|
|
62
|
+
}, {});
|
|
63
|
+
// If we don't need to sort the connect array, we can return it as is
|
|
64
|
+
if (!needsSorting) return connectArr;
|
|
65
|
+
// Recursively compute in which order the relation should be connected
|
|
66
|
+
const computeRelation = (relation, relationsSeenInBranch)=>{
|
|
67
|
+
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
68
|
+
const adjacentRelation = mappedRelations[adjacentRelId];
|
|
69
|
+
// If the relation has already been seen in the current branch,
|
|
70
|
+
// it means there is a circular reference
|
|
71
|
+
if (adjacentRelId && relationsSeenInBranch[adjacentRelId]) {
|
|
72
|
+
throw new invalidRelation('A circular reference was found in the connect array. ' + 'One relation is trying to connect before/after another one that is trying to connect before/after it');
|
|
73
|
+
}
|
|
74
|
+
// This relation has already been computed
|
|
75
|
+
if (mappedRelations[relation.id]?.computed) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
mappedRelations[relation.id].computed = true;
|
|
79
|
+
// Relation does not have a before or after attribute or is in the initial array
|
|
80
|
+
if (!adjacentRelId || relationInInitialArray[adjacentRelId]) {
|
|
81
|
+
sortedConnect.push(relation);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Look if id is referenced elsewhere in the array
|
|
85
|
+
if (mappedRelations[adjacentRelId]) {
|
|
86
|
+
computeRelation(adjacentRelation, {
|
|
87
|
+
...relationsSeenInBranch,
|
|
88
|
+
[relation.id]: true
|
|
89
|
+
});
|
|
90
|
+
sortedConnect.push(relation);
|
|
91
|
+
} else if (strictSort) {
|
|
92
|
+
// If we reach this point, it means that the adjacent relation is not in the connect array
|
|
93
|
+
// and it is not in the database.
|
|
94
|
+
throw new invalidRelation(`There was a problem connecting relation with id ${relation.id} at position ${JSON.stringify(relation.position)}. The relation with id ${adjacentRelId} needs to be connected first.`);
|
|
95
|
+
} else {
|
|
96
|
+
// We are in non-strict mode so we can push the relation.
|
|
97
|
+
sortedConnect.push({
|
|
98
|
+
id: relation.id,
|
|
99
|
+
position: {
|
|
100
|
+
end: true
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
// Iterate over connectArr and populate sortedConnect
|
|
106
|
+
connectArr.forEach((relation)=>computeRelation(relation, {}));
|
|
107
|
+
return sortedConnect;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Responsible for calculating the relations order when connecting them.
|
|
111
|
+
*
|
|
112
|
+
* The connect method takes an array of relations with positional attributes:
|
|
113
|
+
* - before: the id of the relation to connect before
|
|
114
|
+
* - after: the id of the relation to connect after
|
|
115
|
+
* - end: it should be at the end
|
|
116
|
+
* - start: it should be at the start
|
|
117
|
+
*
|
|
118
|
+
* Example:
|
|
119
|
+
* - Having a connect array like:
|
|
120
|
+
* [ { id: 4, before: 2 }, { id: 4, before: 3}, {id: 5, before: 4} ]
|
|
121
|
+
* - With the initial relations:
|
|
122
|
+
* [ { id: 2, order: 4 }, { id: 3, order: 10 } ]
|
|
123
|
+
* - Step by step, going through the connect array, the array of relations would be:
|
|
124
|
+
* [ { id: 4, order: 3.5 }, { id: 2, order: 4 }, { id: 3, order: 10 } ]
|
|
125
|
+
* [ { id: 2, order: 4 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]
|
|
126
|
+
* [ { id: 2, order: 4 }, { id: 5, order: 3.5 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]
|
|
127
|
+
* - The final step would be to recalculate fractional order values.
|
|
128
|
+
* [ { id: 2, order: 4 }, { id: 5, order: 3.33 }, { id: 4, order: 3.66 }, { id: 3, order: 10 } ]
|
|
129
|
+
*
|
|
130
|
+
* @param {Array<*>} initArr - array of relations to initialize the class with
|
|
131
|
+
* @param {string} idColumn - the column name of the id
|
|
132
|
+
* @param {string} orderColumn - the column name of the order
|
|
133
|
+
* @param {boolean} strict - if true, will throw an error if a relation is connected adjacent to
|
|
134
|
+
* another one that does not exist
|
|
135
|
+
* @return {*}
|
|
136
|
+
*/ const relationsOrderer = (initArr, idColumn, orderColumn, strict)=>{
|
|
137
|
+
const computedRelations = _.castArray(initArr ?? []).map((r)=>({
|
|
138
|
+
init: true,
|
|
139
|
+
id: r[idColumn],
|
|
140
|
+
order: Number(r[orderColumn]) || 1
|
|
141
|
+
}));
|
|
142
|
+
const maxOrder = _.maxBy('order', computedRelations)?.order || 0;
|
|
143
|
+
const findRelation = (id)=>{
|
|
144
|
+
const idx = computedRelations.findIndex((r)=>r.id === id);
|
|
145
|
+
return {
|
|
146
|
+
idx,
|
|
147
|
+
relation: computedRelations[idx]
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const removeRelation = (r)=>{
|
|
151
|
+
const { idx } = findRelation(r.id);
|
|
152
|
+
if (idx >= 0) {
|
|
153
|
+
computedRelations.splice(idx, 1);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const insertRelation = (r)=>{
|
|
157
|
+
let idx;
|
|
158
|
+
if (r.position?.before) {
|
|
159
|
+
const { idx: _idx, relation } = findRelation(r.position.before);
|
|
160
|
+
if (relation.init) {
|
|
161
|
+
r.order = relation.order - 0.5;
|
|
162
|
+
} else {
|
|
163
|
+
r.order = relation.order;
|
|
164
|
+
}
|
|
165
|
+
idx = _idx;
|
|
166
|
+
} else if (r.position?.after) {
|
|
167
|
+
const { idx: _idx, relation } = findRelation(r.position.after);
|
|
168
|
+
if (relation.init) {
|
|
169
|
+
r.order = relation.order + 0.5;
|
|
170
|
+
} else {
|
|
171
|
+
r.order = relation.order;
|
|
172
|
+
}
|
|
173
|
+
idx = _idx + 1;
|
|
174
|
+
} else if (r.position?.start) {
|
|
175
|
+
r.order = 0.5;
|
|
176
|
+
idx = 0;
|
|
177
|
+
} else {
|
|
178
|
+
r.order = maxOrder + 0.5;
|
|
179
|
+
idx = computedRelations.length;
|
|
180
|
+
}
|
|
181
|
+
// Insert the relation in the array
|
|
182
|
+
computedRelations.splice(idx, 0, r);
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
disconnect (relations) {
|
|
186
|
+
_.castArray(relations).forEach((relation)=>{
|
|
187
|
+
removeRelation(relation);
|
|
188
|
+
});
|
|
189
|
+
return this;
|
|
190
|
+
},
|
|
191
|
+
connect (relations) {
|
|
192
|
+
sortConnectArray(_.castArray(relations), computedRelations, strict).forEach((relation)=>{
|
|
193
|
+
this.disconnect(relation);
|
|
194
|
+
try {
|
|
195
|
+
insertRelation(relation);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
throw new Error(`There was a problem connecting relation with id ${relation.id} at position ${JSON.stringify(relation.position)}. The list of connect relations is not valid`);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return this;
|
|
201
|
+
},
|
|
202
|
+
get () {
|
|
203
|
+
return computedRelations;
|
|
204
|
+
},
|
|
205
|
+
/**
|
|
206
|
+
* Get a map between the relation id and its order
|
|
207
|
+
*/ getOrderMap () {
|
|
208
|
+
return _$1(computedRelations).groupBy('order').reduce((acc, relations)=>{
|
|
209
|
+
if (relations[0]?.init) return acc;
|
|
210
|
+
relations.forEach((relation, idx)=>{
|
|
211
|
+
acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
|
|
212
|
+
});
|
|
213
|
+
return acc;
|
|
214
|
+
}, {});
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
exports.relationsOrderer = relationsOrderer;
|
|
220
|
+
exports.sortConnectArray = sortConnectArray;
|
|
221
|
+
//# sourceMappingURL=relations-orderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relations-orderer.js","sources":["../../src/entity-manager/relations-orderer.ts"],"sourcesContent":["import { castArray, maxBy } from 'lodash/fp';\nimport _ from 'lodash';\n\nimport { InvalidRelationError } from '../errors';\nimport type { ID } from '../types';\n\ninterface Link {\n id: ID;\n position?: { before?: ID; after?: ID; start?: true; end?: true };\n order?: number;\n __component?: string;\n}\n\ninterface OrderedLink extends Link {\n init?: boolean;\n order: number;\n}\n\n/**\n * When connecting relations, the order you connect them matters.\n *\n * Example, if you connect the following relations:\n * { id: 5, position: { before: 1 } }\n * { id: 1, position: { before: 2 } }\n * { id: 2, position: { end: true } }\n *\n * Going through the connect array, id 5 has to be connected before id 1,\n * so the order of id5 = id1 - 1. But the order value of id 1 is unknown.\n * The only way to know the order of id 1 is to connect it first.\n *\n * This function makes sure the relations are connected in the right order:\n * { id: 2, position: { end: true } }\n * { id: 1, position: { before: 2 } }\n * { id: 5, position: { before: 1 } }\n *\n */\nconst sortConnectArray = (connectArr: Link[], initialArr: Link[] = [], strictSort = true) => {\n const sortedConnect: Link[] = [];\n // Boolean to know if we have to recalculate the order of the relations\n let needsSorting = false;\n // Map to validate if relation is already in sortedConnect or DB.\n const relationInInitialArray = initialArr.reduce(\n (acc, rel) => ({ ...acc, [rel.id]: true }),\n {} as Record<ID, boolean>\n );\n // Map to store the first index where a relation id is connected\n const mappedRelations = connectArr.reduce(\n (mapper, relation: Link) => {\n const adjacentRelId = relation.position?.before || relation.position?.after;\n\n if (!adjacentRelId || (!relationInInitialArray[adjacentRelId] && !mapper[adjacentRelId])) {\n needsSorting = true;\n }\n\n /**\n * We do not allow duplicate relations to be connected, so we need to check for uniqueness with components\n * Note that the id here includes the uid for polymorphic relations\n *\n * So for normal relations, the same id means the same relation\n * For component relations, it means the unique combo of (id, component name)\n */\n\n // Check if there's an existing relation with this id\n const existingRelation = mapper[relation.id];\n\n // Check if existing relation has a component or not\n const hasNoComponent = existingRelation && !('__component' in existingRelation);\n\n // Check if the existing relation has the same component as the new relation\n const hasSameComponent =\n existingRelation && existingRelation.__component === relation.__component;\n\n // If we have an existing relation that is not unique (no component or same component) we won't accept it\n if (existingRelation && (hasNoComponent || hasSameComponent)) {\n throw new InvalidRelationError(\n `The relation with id ${relation.id} is already connected. ` +\n 'You cannot connect the same relation twice.'\n );\n }\n\n return {\n [relation.id]: { ...relation, computed: false },\n ...mapper,\n };\n },\n {} as Record<ID, Link & { computed: boolean }>\n );\n\n // If we don't need to sort the connect array, we can return it as is\n if (!needsSorting) return connectArr;\n\n // Recursively compute in which order the relation should be connected\n const computeRelation = (relation: Link, relationsSeenInBranch: Record<ID, boolean>) => {\n const adjacentRelId = relation.position?.before || relation.position?.after;\n const adjacentRelation = mappedRelations[adjacentRelId as ID];\n\n // If the relation has already been seen in the current branch,\n // it means there is a circular reference\n if (adjacentRelId && relationsSeenInBranch[adjacentRelId]) {\n throw new InvalidRelationError(\n 'A circular reference was found in the connect array. ' +\n 'One relation is trying to connect before/after another one that is trying to connect before/after it'\n );\n }\n\n // This relation has already been computed\n if (mappedRelations[relation.id]?.computed) {\n return;\n }\n\n mappedRelations[relation.id].computed = true;\n\n // Relation does not have a before or after attribute or is in the initial array\n if (!adjacentRelId || relationInInitialArray[adjacentRelId]) {\n sortedConnect.push(relation);\n return;\n }\n\n // Look if id is referenced elsewhere in the array\n if (mappedRelations[adjacentRelId]) {\n computeRelation(adjacentRelation, { ...relationsSeenInBranch, [relation.id]: true });\n sortedConnect.push(relation);\n } else if (strictSort) {\n // If we reach this point, it means that the adjacent relation is not in the connect array\n // and it is not in the database.\n throw new InvalidRelationError(\n `There was a problem connecting relation with id ${\n relation.id\n } at position ${JSON.stringify(\n relation.position\n )}. The relation with id ${adjacentRelId} needs to be connected first.`\n );\n } else {\n // We are in non-strict mode so we can push the relation.\n sortedConnect.push({ id: relation.id, position: { end: true } });\n }\n };\n\n // Iterate over connectArr and populate sortedConnect\n connectArr.forEach((relation) => computeRelation(relation, {}));\n\n return sortedConnect;\n};\n\n/**\n * Responsible for calculating the relations order when connecting them.\n *\n * The connect method takes an array of relations with positional attributes:\n * - before: the id of the relation to connect before\n * - after: the id of the relation to connect after\n * - end: it should be at the end\n * - start: it should be at the start\n *\n * Example:\n * - Having a connect array like:\n * [ { id: 4, before: 2 }, { id: 4, before: 3}, {id: 5, before: 4} ]\n * - With the initial relations:\n * [ { id: 2, order: 4 }, { id: 3, order: 10 } ]\n * - Step by step, going through the connect array, the array of relations would be:\n * [ { id: 4, order: 3.5 }, { id: 2, order: 4 }, { id: 3, order: 10 } ]\n * [ { id: 2, order: 4 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]\n * [ { id: 2, order: 4 }, { id: 5, order: 3.5 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]\n * - The final step would be to recalculate fractional order values.\n * [ { id: 2, order: 4 }, { id: 5, order: 3.33 }, { id: 4, order: 3.66 }, { id: 3, order: 10 } ]\n *\n * @param {Array<*>} initArr - array of relations to initialize the class with\n * @param {string} idColumn - the column name of the id\n * @param {string} orderColumn - the column name of the order\n * @param {boolean} strict - if true, will throw an error if a relation is connected adjacent to\n * another one that does not exist\n * @return {*}\n */\nconst relationsOrderer = <TRelation extends Record<string, ID | number | null>>(\n initArr: TRelation[],\n idColumn: keyof TRelation,\n orderColumn: keyof TRelation,\n strict?: boolean\n) => {\n const computedRelations: OrderedLink[] = castArray(initArr ?? []).map((r) => ({\n init: true,\n id: r[idColumn] as ID,\n order: Number(r[orderColumn]) || 1,\n }));\n\n const maxOrder = maxBy('order', computedRelations)?.order || 0;\n\n const findRelation = (id: ID) => {\n const idx = computedRelations.findIndex((r) => r.id === id);\n return { idx, relation: computedRelations[idx] };\n };\n\n const removeRelation = (r: Link) => {\n const { idx } = findRelation(r.id);\n if (idx >= 0) {\n computedRelations.splice(idx, 1);\n }\n };\n\n const insertRelation = (r: Link) => {\n let idx;\n\n if (r.position?.before) {\n const { idx: _idx, relation } = findRelation(r.position.before);\n if (relation.init) {\n r.order = relation.order - 0.5;\n } else {\n r.order = relation.order;\n }\n idx = _idx;\n } else if (r.position?.after) {\n const { idx: _idx, relation } = findRelation(r.position.after);\n if (relation.init) {\n r.order = relation.order + 0.5;\n } else {\n r.order = relation.order;\n }\n\n idx = _idx + 1;\n } else if (r.position?.start) {\n r.order = 0.5;\n idx = 0;\n } else {\n r.order = maxOrder + 0.5;\n idx = computedRelations.length;\n }\n\n // Insert the relation in the array\n computedRelations.splice(idx, 0, r as OrderedLink);\n };\n\n return {\n disconnect(relations: Link | Link[]) {\n castArray(relations).forEach((relation) => {\n removeRelation(relation);\n });\n return this;\n },\n connect(relations: Link | Link[]) {\n sortConnectArray(castArray(relations), computedRelations, strict).forEach((relation) => {\n this.disconnect(relation);\n\n try {\n insertRelation(relation);\n } catch (err) {\n throw new Error(\n `There was a problem connecting relation with id ${\n relation.id\n } at position ${JSON.stringify(\n relation.position\n )}. The list of connect relations is not valid`\n );\n }\n });\n return this;\n },\n get() {\n return computedRelations;\n },\n /**\n * Get a map between the relation id and its order\n */\n getOrderMap() {\n return _(computedRelations)\n .groupBy('order')\n .reduce(\n (acc, relations) => {\n if (relations[0]?.init) return acc;\n relations.forEach((relation, idx) => {\n acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);\n });\n return acc;\n },\n {} as Record<ID, number>\n );\n },\n };\n};\n\nexport { relationsOrderer, sortConnectArray };\n"],"names":["sortConnectArray","connectArr","initialArr","strictSort","sortedConnect","needsSorting","relationInInitialArray","reduce","acc","rel","id","mappedRelations","mapper","relation","adjacentRelId","position","before","after","existingRelation","hasNoComponent","hasSameComponent","__component","InvalidRelationError","computed","computeRelation","relationsSeenInBranch","adjacentRelation","push","JSON","stringify","end","forEach","relationsOrderer","initArr","idColumn","orderColumn","strict","computedRelations","castArray","map","r","init","order","Number","maxOrder","maxBy","findRelation","idx","findIndex","removeRelation","splice","insertRelation","_idx","start","length","disconnect","relations","connect","err","Error","get","getOrderMap","_","groupBy","Math","floor"],"mappings":";;;;;;AAkBA;;;;;;;;;;;;;;;;;IAkBA,MAAMA,mBAAmB,CAACC,UAAAA,EAAoBC,aAAqB,EAAE,EAAEC,aAAa,IAAI,GAAA;AACtF,IAAA,MAAMC,gBAAwB,EAAE;;AAEhC,IAAA,IAAIC,YAAe,GAAA,KAAA;;AAEnB,IAAA,MAAMC,yBAAyBJ,UAAWK,CAAAA,MAAM,CAC9C,CAACC,GAAAA,EAAKC,OAAS;AAAE,YAAA,GAAGD,GAAG;YAAE,CAACC,GAAAA,CAAIC,EAAE,GAAG;AAAK,SAAA,GACxC,EAAC,CAAA;;AAGH,IAAA,MAAMC,eAAkBV,GAAAA,UAAAA,CAAWM,MAAM,CACvC,CAACK,MAAQC,EAAAA,QAAAA,GAAAA;AACP,QAAA,MAAMC,gBAAgBD,QAASE,CAAAA,QAAQ,EAAEC,MAAUH,IAAAA,QAAAA,CAASE,QAAQ,EAAEE,KAAAA;QAEtE,IAAI,CAACH,aAAkB,IAAA,CAACR,sBAAsB,CAACQ,aAAc,CAAA,IAAI,CAACF,MAAM,CAACE,aAAAA,CAAc,EAAG;YACxFT,YAAe,GAAA,IAAA;AACjB;AAEA;;;;;;AAMC;AAGD,QAAA,MAAMa,gBAAmBN,GAAAA,MAAM,CAACC,QAAAA,CAASH,EAAE,CAAC;;AAG5C,QAAA,MAAMS,cAAiBD,GAAAA,gBAAAA,IAAoB,EAAE,iBAAiBA,gBAAe,CAAA;;AAG7E,QAAA,MAAME,mBACJF,gBAAoBA,IAAAA,gBAAAA,CAAiBG,WAAW,KAAKR,SAASQ,WAAW;;AAG3E,QAAA,IAAIH,gBAAqBC,KAAAA,cAAkBC,IAAAA,gBAAe,CAAI,EAAA;YAC5D,MA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AAA,CAAEzB,mBACN0B,OAAO,CAAC,SACRxD,MAAM,CACL,CAACC,GAAKgD,EAAAA,SAAAA,GAAAA;AACJ,gBAAA,IAAIA,SAAS,CAAC,CAAE,CAAA,EAAEf,MAAM,OAAOjC,GAAAA;gBAC/BgD,SAAUzB,CAAAA,OAAO,CAAC,CAAClB,QAAUkC,EAAAA,GAAAA,GAAAA;oBAC3BvC,GAAG,CAACK,SAASH,EAAE,CAAC,GAAGsD,IAAKC,CAAAA,KAAK,CAACpD,QAAS6B,CAAAA,KAAK,IAAI,CAACK,MAAM,CAAA,KAAMS,SAAUF,CAAAA,MAAM,GAAG,CAAA,CAAA;AAClF,iBAAA,CAAA;gBACA,OAAO9C,GAAAA;AACT,aAAA,EACA,EAAC,CAAA;AAEP;AACF,KAAA;AACF;;;;;"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { castArray, maxBy } from 'lodash/fp';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import InvalidRelationError from '../errors/invalid-relation.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* When connecting relations, the order you connect them matters.
|
|
7
|
+
*
|
|
8
|
+
* Example, if you connect the following relations:
|
|
9
|
+
* { id: 5, position: { before: 1 } }
|
|
10
|
+
* { id: 1, position: { before: 2 } }
|
|
11
|
+
* { id: 2, position: { end: true } }
|
|
12
|
+
*
|
|
13
|
+
* Going through the connect array, id 5 has to be connected before id 1,
|
|
14
|
+
* so the order of id5 = id1 - 1. But the order value of id 1 is unknown.
|
|
15
|
+
* The only way to know the order of id 1 is to connect it first.
|
|
16
|
+
*
|
|
17
|
+
* This function makes sure the relations are connected in the right order:
|
|
18
|
+
* { id: 2, position: { end: true } }
|
|
19
|
+
* { id: 1, position: { before: 2 } }
|
|
20
|
+
* { id: 5, position: { before: 1 } }
|
|
21
|
+
*
|
|
22
|
+
*/ const sortConnectArray = (connectArr, initialArr = [], strictSort = true)=>{
|
|
23
|
+
const sortedConnect = [];
|
|
24
|
+
// Boolean to know if we have to recalculate the order of the relations
|
|
25
|
+
let needsSorting = false;
|
|
26
|
+
// Map to validate if relation is already in sortedConnect or DB.
|
|
27
|
+
const relationInInitialArray = initialArr.reduce((acc, rel)=>({
|
|
28
|
+
...acc,
|
|
29
|
+
[rel.id]: true
|
|
30
|
+
}), {});
|
|
31
|
+
// Map to store the first index where a relation id is connected
|
|
32
|
+
const mappedRelations = connectArr.reduce((mapper, relation)=>{
|
|
33
|
+
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
34
|
+
if (!adjacentRelId || !relationInInitialArray[adjacentRelId] && !mapper[adjacentRelId]) {
|
|
35
|
+
needsSorting = true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* We do not allow duplicate relations to be connected, so we need to check for uniqueness with components
|
|
39
|
+
* Note that the id here includes the uid for polymorphic relations
|
|
40
|
+
*
|
|
41
|
+
* So for normal relations, the same id means the same relation
|
|
42
|
+
* For component relations, it means the unique combo of (id, component name)
|
|
43
|
+
*/ // Check if there's an existing relation with this id
|
|
44
|
+
const existingRelation = mapper[relation.id];
|
|
45
|
+
// Check if existing relation has a component or not
|
|
46
|
+
const hasNoComponent = existingRelation && !('__component' in existingRelation);
|
|
47
|
+
// Check if the existing relation has the same component as the new relation
|
|
48
|
+
const hasSameComponent = existingRelation && existingRelation.__component === relation.__component;
|
|
49
|
+
// If we have an existing relation that is not unique (no component or same component) we won't accept it
|
|
50
|
+
if (existingRelation && (hasNoComponent || hasSameComponent)) {
|
|
51
|
+
throw new InvalidRelationError(`The relation with id ${relation.id} is already connected. ` + 'You cannot connect the same relation twice.');
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
[relation.id]: {
|
|
55
|
+
...relation,
|
|
56
|
+
computed: false
|
|
57
|
+
},
|
|
58
|
+
...mapper
|
|
59
|
+
};
|
|
60
|
+
}, {});
|
|
61
|
+
// If we don't need to sort the connect array, we can return it as is
|
|
62
|
+
if (!needsSorting) return connectArr;
|
|
63
|
+
// Recursively compute in which order the relation should be connected
|
|
64
|
+
const computeRelation = (relation, relationsSeenInBranch)=>{
|
|
65
|
+
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
66
|
+
const adjacentRelation = mappedRelations[adjacentRelId];
|
|
67
|
+
// If the relation has already been seen in the current branch,
|
|
68
|
+
// it means there is a circular reference
|
|
69
|
+
if (adjacentRelId && relationsSeenInBranch[adjacentRelId]) {
|
|
70
|
+
throw new InvalidRelationError('A circular reference was found in the connect array. ' + 'One relation is trying to connect before/after another one that is trying to connect before/after it');
|
|
71
|
+
}
|
|
72
|
+
// This relation has already been computed
|
|
73
|
+
if (mappedRelations[relation.id]?.computed) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
mappedRelations[relation.id].computed = true;
|
|
77
|
+
// Relation does not have a before or after attribute or is in the initial array
|
|
78
|
+
if (!adjacentRelId || relationInInitialArray[adjacentRelId]) {
|
|
79
|
+
sortedConnect.push(relation);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Look if id is referenced elsewhere in the array
|
|
83
|
+
if (mappedRelations[adjacentRelId]) {
|
|
84
|
+
computeRelation(adjacentRelation, {
|
|
85
|
+
...relationsSeenInBranch,
|
|
86
|
+
[relation.id]: true
|
|
87
|
+
});
|
|
88
|
+
sortedConnect.push(relation);
|
|
89
|
+
} else if (strictSort) {
|
|
90
|
+
// If we reach this point, it means that the adjacent relation is not in the connect array
|
|
91
|
+
// and it is not in the database.
|
|
92
|
+
throw new InvalidRelationError(`There was a problem connecting relation with id ${relation.id} at position ${JSON.stringify(relation.position)}. The relation with id ${adjacentRelId} needs to be connected first.`);
|
|
93
|
+
} else {
|
|
94
|
+
// We are in non-strict mode so we can push the relation.
|
|
95
|
+
sortedConnect.push({
|
|
96
|
+
id: relation.id,
|
|
97
|
+
position: {
|
|
98
|
+
end: true
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
// Iterate over connectArr and populate sortedConnect
|
|
104
|
+
connectArr.forEach((relation)=>computeRelation(relation, {}));
|
|
105
|
+
return sortedConnect;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Responsible for calculating the relations order when connecting them.
|
|
109
|
+
*
|
|
110
|
+
* The connect method takes an array of relations with positional attributes:
|
|
111
|
+
* - before: the id of the relation to connect before
|
|
112
|
+
* - after: the id of the relation to connect after
|
|
113
|
+
* - end: it should be at the end
|
|
114
|
+
* - start: it should be at the start
|
|
115
|
+
*
|
|
116
|
+
* Example:
|
|
117
|
+
* - Having a connect array like:
|
|
118
|
+
* [ { id: 4, before: 2 }, { id: 4, before: 3}, {id: 5, before: 4} ]
|
|
119
|
+
* - With the initial relations:
|
|
120
|
+
* [ { id: 2, order: 4 }, { id: 3, order: 10 } ]
|
|
121
|
+
* - Step by step, going through the connect array, the array of relations would be:
|
|
122
|
+
* [ { id: 4, order: 3.5 }, { id: 2, order: 4 }, { id: 3, order: 10 } ]
|
|
123
|
+
* [ { id: 2, order: 4 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]
|
|
124
|
+
* [ { id: 2, order: 4 }, { id: 5, order: 3.5 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]
|
|
125
|
+
* - The final step would be to recalculate fractional order values.
|
|
126
|
+
* [ { id: 2, order: 4 }, { id: 5, order: 3.33 }, { id: 4, order: 3.66 }, { id: 3, order: 10 } ]
|
|
127
|
+
*
|
|
128
|
+
* @param {Array<*>} initArr - array of relations to initialize the class with
|
|
129
|
+
* @param {string} idColumn - the column name of the id
|
|
130
|
+
* @param {string} orderColumn - the column name of the order
|
|
131
|
+
* @param {boolean} strict - if true, will throw an error if a relation is connected adjacent to
|
|
132
|
+
* another one that does not exist
|
|
133
|
+
* @return {*}
|
|
134
|
+
*/ const relationsOrderer = (initArr, idColumn, orderColumn, strict)=>{
|
|
135
|
+
const computedRelations = castArray(initArr ?? []).map((r)=>({
|
|
136
|
+
init: true,
|
|
137
|
+
id: r[idColumn],
|
|
138
|
+
order: Number(r[orderColumn]) || 1
|
|
139
|
+
}));
|
|
140
|
+
const maxOrder = maxBy('order', computedRelations)?.order || 0;
|
|
141
|
+
const findRelation = (id)=>{
|
|
142
|
+
const idx = computedRelations.findIndex((r)=>r.id === id);
|
|
143
|
+
return {
|
|
144
|
+
idx,
|
|
145
|
+
relation: computedRelations[idx]
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const removeRelation = (r)=>{
|
|
149
|
+
const { idx } = findRelation(r.id);
|
|
150
|
+
if (idx >= 0) {
|
|
151
|
+
computedRelations.splice(idx, 1);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const insertRelation = (r)=>{
|
|
155
|
+
let idx;
|
|
156
|
+
if (r.position?.before) {
|
|
157
|
+
const { idx: _idx, relation } = findRelation(r.position.before);
|
|
158
|
+
if (relation.init) {
|
|
159
|
+
r.order = relation.order - 0.5;
|
|
160
|
+
} else {
|
|
161
|
+
r.order = relation.order;
|
|
162
|
+
}
|
|
163
|
+
idx = _idx;
|
|
164
|
+
} else if (r.position?.after) {
|
|
165
|
+
const { idx: _idx, relation } = findRelation(r.position.after);
|
|
166
|
+
if (relation.init) {
|
|
167
|
+
r.order = relation.order + 0.5;
|
|
168
|
+
} else {
|
|
169
|
+
r.order = relation.order;
|
|
170
|
+
}
|
|
171
|
+
idx = _idx + 1;
|
|
172
|
+
} else if (r.position?.start) {
|
|
173
|
+
r.order = 0.5;
|
|
174
|
+
idx = 0;
|
|
175
|
+
} else {
|
|
176
|
+
r.order = maxOrder + 0.5;
|
|
177
|
+
idx = computedRelations.length;
|
|
178
|
+
}
|
|
179
|
+
// Insert the relation in the array
|
|
180
|
+
computedRelations.splice(idx, 0, r);
|
|
181
|
+
};
|
|
182
|
+
return {
|
|
183
|
+
disconnect (relations) {
|
|
184
|
+
castArray(relations).forEach((relation)=>{
|
|
185
|
+
removeRelation(relation);
|
|
186
|
+
});
|
|
187
|
+
return this;
|
|
188
|
+
},
|
|
189
|
+
connect (relations) {
|
|
190
|
+
sortConnectArray(castArray(relations), computedRelations, strict).forEach((relation)=>{
|
|
191
|
+
this.disconnect(relation);
|
|
192
|
+
try {
|
|
193
|
+
insertRelation(relation);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
throw new Error(`There was a problem connecting relation with id ${relation.id} at position ${JSON.stringify(relation.position)}. The list of connect relations is not valid`);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return this;
|
|
199
|
+
},
|
|
200
|
+
get () {
|
|
201
|
+
return computedRelations;
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* Get a map between the relation id and its order
|
|
205
|
+
*/ getOrderMap () {
|
|
206
|
+
return _(computedRelations).groupBy('order').reduce((acc, relations)=>{
|
|
207
|
+
if (relations[0]?.init) return acc;
|
|
208
|
+
relations.forEach((relation, idx)=>{
|
|
209
|
+
acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
|
|
210
|
+
});
|
|
211
|
+
return acc;
|
|
212
|
+
}, {});
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export { relationsOrderer, sortConnectArray };
|
|
218
|
+
//# sourceMappingURL=relations-orderer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relations-orderer.mjs","sources":["../../src/entity-manager/relations-orderer.ts"],"sourcesContent":["import { castArray, maxBy } from 'lodash/fp';\nimport _ from 'lodash';\n\nimport { InvalidRelationError } from '../errors';\nimport type { ID } from '../types';\n\ninterface Link {\n id: ID;\n position?: { before?: ID; after?: ID; start?: true; end?: true };\n order?: number;\n __component?: string;\n}\n\ninterface OrderedLink extends Link {\n init?: boolean;\n order: number;\n}\n\n/**\n * When connecting relations, the order you connect them matters.\n *\n * Example, if you connect the following relations:\n * { id: 5, position: { before: 1 } }\n * { id: 1, position: { before: 2 } }\n * { id: 2, position: { end: true } }\n *\n * Going through the connect array, id 5 has to be connected before id 1,\n * so the order of id5 = id1 - 1. But the order value of id 1 is unknown.\n * The only way to know the order of id 1 is to connect it first.\n *\n * This function makes sure the relations are connected in the right order:\n * { id: 2, position: { end: true } }\n * { id: 1, position: { before: 2 } }\n * { id: 5, position: { before: 1 } }\n *\n */\nconst sortConnectArray = (connectArr: Link[], initialArr: Link[] = [], strictSort = true) => {\n const sortedConnect: Link[] = [];\n // Boolean to know if we have to recalculate the order of the relations\n let needsSorting = false;\n // Map to validate if relation is already in sortedConnect or DB.\n const relationInInitialArray = initialArr.reduce(\n (acc, rel) => ({ ...acc, [rel.id]: true }),\n {} as Record<ID, boolean>\n );\n // Map to store the first index where a relation id is connected\n const mappedRelations = connectArr.reduce(\n (mapper, relation: Link) => {\n const adjacentRelId = relation.position?.before || relation.position?.after;\n\n if (!adjacentRelId || (!relationInInitialArray[adjacentRelId] && !mapper[adjacentRelId])) {\n needsSorting = true;\n }\n\n /**\n * We do not allow duplicate relations to be connected, so we need to check for uniqueness with components\n * Note that the id here includes the uid for polymorphic relations\n *\n * So for normal relations, the same id means the same relation\n * For component relations, it means the unique combo of (id, component name)\n */\n\n // Check if there's an existing relation with this id\n const existingRelation = mapper[relation.id];\n\n // Check if existing relation has a component or not\n const hasNoComponent = existingRelation && !('__component' in existingRelation);\n\n // Check if the existing relation has the same component as the new relation\n const hasSameComponent =\n existingRelation && existingRelation.__component === relation.__component;\n\n // If we have an existing relation that is not unique (no component or same component) we won't accept it\n if (existingRelation && (hasNoComponent || hasSameComponent)) {\n throw new InvalidRelationError(\n `The relation with id ${relation.id} is already connected. ` +\n 'You cannot connect the same relation twice.'\n );\n }\n\n return {\n [relation.id]: { ...relation, computed: false },\n ...mapper,\n };\n },\n {} as Record<ID, Link & { computed: boolean }>\n );\n\n // If we don't need to sort the connect array, we can return it as is\n if (!needsSorting) return connectArr;\n\n // Recursively compute in which order the relation should be connected\n const computeRelation = (relation: Link, relationsSeenInBranch: Record<ID, boolean>) => {\n const adjacentRelId = relation.position?.before || relation.position?.after;\n const adjacentRelation = mappedRelations[adjacentRelId as ID];\n\n // If the relation has already been seen in the current branch,\n // it means there is a circular reference\n if (adjacentRelId && relationsSeenInBranch[adjacentRelId]) {\n throw new InvalidRelationError(\n 'A circular reference was found in the connect array. ' +\n 'One relation is trying to connect before/after another one that is trying to connect before/after it'\n );\n }\n\n // This relation has already been computed\n if (mappedRelations[relation.id]?.computed) {\n return;\n }\n\n mappedRelations[relation.id].computed = true;\n\n // Relation does not have a before or after attribute or is in the initial array\n if (!adjacentRelId || relationInInitialArray[adjacentRelId]) {\n sortedConnect.push(relation);\n return;\n }\n\n // Look if id is referenced elsewhere in the array\n if (mappedRelations[adjacentRelId]) {\n computeRelation(adjacentRelation, { ...relationsSeenInBranch, [relation.id]: true });\n sortedConnect.push(relation);\n } else if (strictSort) {\n // If we reach this point, it means that the adjacent relation is not in the connect array\n // and it is not in the database.\n throw new InvalidRelationError(\n `There was a problem connecting relation with id ${\n relation.id\n } at position ${JSON.stringify(\n relation.position\n )}. The relation with id ${adjacentRelId} needs to be connected first.`\n );\n } else {\n // We are in non-strict mode so we can push the relation.\n sortedConnect.push({ id: relation.id, position: { end: true } });\n }\n };\n\n // Iterate over connectArr and populate sortedConnect\n connectArr.forEach((relation) => computeRelation(relation, {}));\n\n return sortedConnect;\n};\n\n/**\n * Responsible for calculating the relations order when connecting them.\n *\n * The connect method takes an array of relations with positional attributes:\n * - before: the id of the relation to connect before\n * - after: the id of the relation to connect after\n * - end: it should be at the end\n * - start: it should be at the start\n *\n * Example:\n * - Having a connect array like:\n * [ { id: 4, before: 2 }, { id: 4, before: 3}, {id: 5, before: 4} ]\n * - With the initial relations:\n * [ { id: 2, order: 4 }, { id: 3, order: 10 } ]\n * - Step by step, going through the connect array, the array of relations would be:\n * [ { id: 4, order: 3.5 }, { id: 2, order: 4 }, { id: 3, order: 10 } ]\n * [ { id: 2, order: 4 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]\n * [ { id: 2, order: 4 }, { id: 5, order: 3.5 }, { id: 4, order: 3.5 }, { id: 3, order: 10 } ]\n * - The final step would be to recalculate fractional order values.\n * [ { id: 2, order: 4 }, { id: 5, order: 3.33 }, { id: 4, order: 3.66 }, { id: 3, order: 10 } ]\n *\n * @param {Array<*>} initArr - array of relations to initialize the class with\n * @param {string} idColumn - the column name of the id\n * @param {string} orderColumn - the column name of the order\n * @param {boolean} strict - if true, will throw an error if a relation is connected adjacent to\n * another one that does not exist\n * @return {*}\n */\nconst relationsOrderer = <TRelation extends Record<string, ID | number | null>>(\n initArr: TRelation[],\n idColumn: keyof TRelation,\n orderColumn: keyof TRelation,\n strict?: boolean\n) => {\n const computedRelations: OrderedLink[] = castArray(initArr ?? []).map((r) => ({\n init: true,\n id: r[idColumn] as ID,\n order: Number(r[orderColumn]) || 1,\n }));\n\n const maxOrder = maxBy('order', computedRelations)?.order || 0;\n\n const findRelation = (id: ID) => {\n const idx = computedRelations.findIndex((r) => r.id === id);\n return { idx, relation: computedRelations[idx] };\n };\n\n const removeRelation = (r: Link) => {\n const { idx } = findRelation(r.id);\n if (idx >= 0) {\n computedRelations.splice(idx, 1);\n }\n };\n\n const insertRelation = (r: Link) => {\n let idx;\n\n if (r.position?.before) {\n const { idx: _idx, relation } = findRelation(r.position.before);\n if (relation.init) {\n r.order = relation.order - 0.5;\n } else {\n r.order = relation.order;\n }\n idx = _idx;\n } else if (r.position?.after) {\n const { idx: _idx, relation } = findRelation(r.position.after);\n if (relation.init) {\n r.order = relation.order + 0.5;\n } else {\n r.order = relation.order;\n }\n\n idx = _idx + 1;\n } else if (r.position?.start) {\n r.order = 0.5;\n idx = 0;\n } else {\n r.order = maxOrder + 0.5;\n idx = computedRelations.length;\n }\n\n // Insert the relation in the array\n computedRelations.splice(idx, 0, r as OrderedLink);\n };\n\n return {\n disconnect(relations: Link | Link[]) {\n castArray(relations).forEach((relation) => {\n removeRelation(relation);\n });\n return this;\n },\n connect(relations: Link | Link[]) {\n sortConnectArray(castArray(relations), computedRelations, strict).forEach((relation) => {\n this.disconnect(relation);\n\n try {\n insertRelation(relation);\n } catch (err) {\n throw new Error(\n `There was a problem connecting relation with id ${\n relation.id\n } at position ${JSON.stringify(\n relation.position\n )}. The list of connect relations is not valid`\n );\n }\n });\n return this;\n },\n get() {\n return computedRelations;\n },\n /**\n * Get a map between the relation id and its order\n */\n getOrderMap() {\n return _(computedRelations)\n .groupBy('order')\n .reduce(\n (acc, relations) => {\n if (relations[0]?.init) return acc;\n relations.forEach((relation, idx) => {\n acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);\n });\n return acc;\n },\n {} as Record<ID, number>\n );\n },\n };\n};\n\nexport { relationsOrderer, sortConnectArray };\n"],"names":["sortConnectArray","connectArr","initialArr","strictSort","sortedConnect","needsSorting","relationInInitialArray","reduce","acc","rel","id","mappedRelations","mapper","relation","adjacentRelId","position","before","after","existingRelation","hasNoComponent","hasSameComponent","__component","InvalidRelationError","computed","computeRelation","relationsSeenInBranch","adjacentRelation","push","JSON","stringify","end","forEach","relationsOrderer","initArr","idColumn","orderColumn","strict","computedRelations","castArray","map","r","init","order","Number","maxOrder","maxBy","findRelation","idx","findIndex","removeRelation","splice","insertRelation","_idx","start","length","disconnect","relations","connect","err","Error","get","getOrderMap","_","groupBy","Math","floor"],"mappings":";;;;AAkBA;;;;;;;;;;;;;;;;;IAkBA,MAAMA,mBAAmB,CAACC,UAAAA,EAAoBC,aAAqB,EAAE,EAAEC,aAAa,IAAI,GAAA;AACtF,IAAA,MAAMC,gBAAwB,EAAE;;AAEhC,IAAA,IAAIC,YAAe,GAAA,KAAA;;AAEnB,IAAA,MAAMC,yBAAyBJ,UAAWK,CAAAA,MAAM,CAC9C,CAACC,GAAAA,EAAKC,OAAS;AAAE,YAAA,GAAGD,GAAG;YAAE,CAACC,GAAAA,CAAIC,EAAE,GAAG;AAAK,SAAA,GACxC,EAAC,CAAA;;AAGH,IAAA,MAAMC,eAAkBV,GAAAA,UAAAA,CAAWM,MAAM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
constructor(message = 'A database error occured', details = {}){
|
|
5
|
+
super();
|
|
6
|
+
this.name = 'DatabaseError';
|
|
7
|
+
this.message = message;
|
|
8
|
+
this.details = details;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = DatabaseError;
|
|
13
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sources":["../../src/errors/database.ts"],"sourcesContent":["export default class DatabaseError extends Error {\n details: unknown;\n\n constructor(message = 'A database error occured', details = {}) {\n super();\n this.name = 'DatabaseError';\n this.message = message;\n this.details = details;\n }\n}\n"],"names":["DatabaseError","Error","constructor","message","details","name"],"mappings":";;AAAe,MAAMA,aAAsBC,SAAAA,KAAAA,CAAAA;AAGzCC,IAAAA,WAAAA,CAAYC,UAAU,0BAA0B,EAAEC,OAAU,GAAA,EAAE,CAAE;QAC9D,KAAK,EAAA;QACL,IAAI,CAACC,IAAI,GAAG,eAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACC,OAAO,GAAGA,OAAAA;AACjB;AACF;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class DatabaseError extends Error {
|
|
2
|
+
constructor(message = 'A database error occured', details = {}){
|
|
3
|
+
super();
|
|
4
|
+
this.name = 'DatabaseError';
|
|
5
|
+
this.message = message;
|
|
6
|
+
this.details = details;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { DatabaseError as default };
|
|
11
|
+
//# sourceMappingURL=database.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.mjs","sources":["../../src/errors/database.ts"],"sourcesContent":["export default class DatabaseError extends Error {\n details: unknown;\n\n constructor(message = 'A database error occured', details = {}) {\n super();\n this.name = 'DatabaseError';\n this.message = message;\n this.details = details;\n }\n}\n"],"names":["DatabaseError","Error","constructor","message","details","name"],"mappings":"AAAe,MAAMA,aAAsBC,SAAAA,KAAAA,CAAAA;AAGzCC,IAAAA,WAAAA,CAAYC,UAAU,0BAA0B,EAAEC,OAAU,GAAA,EAAE,CAAE;QAC9D,KAAK,EAAA;QACL,IAAI,CAACC,IAAI,GAAG,eAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACC,OAAO,GAAGA,OAAAA;AACjB;AACF;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var database = require('./database.js');
|
|
4
|
+
var notNull = require('./not-null.js');
|
|
5
|
+
var invalidTime = require('./invalid-time.js');
|
|
6
|
+
var invalidDate = require('./invalid-date.js');
|
|
7
|
+
var invalidDatetime = require('./invalid-datetime.js');
|
|
8
|
+
var invalidRelation = require('./invalid-relation.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.DatabaseError = database;
|
|
13
|
+
exports.NotNullError = notNull;
|
|
14
|
+
exports.InvalidTimeError = invalidTime;
|
|
15
|
+
exports.InvalidDateError = invalidDate;
|
|
16
|
+
exports.InvalidDateTimeError = invalidDatetime;
|
|
17
|
+
exports.InvalidRelationError = invalidRelation;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as DatabaseError } from './database.mjs';
|
|
2
|
+
export { default as NotNullError } from './not-null.mjs';
|
|
3
|
+
export { default as InvalidTimeError } from './invalid-time.mjs';
|
|
4
|
+
export { default as InvalidDateError } from './invalid-date.mjs';
|
|
5
|
+
export { default as InvalidDateTimeError } from './invalid-datetime.mjs';
|
|
6
|
+
export { default as InvalidRelationError } from './invalid-relation.mjs';
|
|
7
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var database = require('./database.js');
|
|
4
|
+
|
|
5
|
+
class InvalidDateError extends database {
|
|
6
|
+
constructor(message = 'Invalid date format, expected YYYY-MM-DD'){
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'InvalidDateFormat';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = InvalidDateError;
|
|
13
|
+
//# sourceMappingURL=invalid-date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-date.js","sources":["../../src/errors/invalid-date.ts"],"sourcesContent":["import DatabaseError from './database';\n\nexport default class InvalidDateError extends DatabaseError {\n constructor(message = 'Invalid date format, expected YYYY-MM-DD') {\n super(message);\n this.name = 'InvalidDateFormat';\n }\n}\n"],"names":["InvalidDateError","DatabaseError","constructor","message","name"],"mappings":";;;;AAEe,MAAMA,gBAAyBC,SAAAA,QAAAA,CAAAA;IAC5CC,WAAYC,CAAAA,OAAAA,GAAU,0CAA0C,CAAE;AAChE,QAAA,KAAK,CAACA,OAAAA,CAAAA;QACN,IAAI,CAACC,IAAI,GAAG,mBAAA;AACd;AACF;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import DatabaseError from './database.mjs';
|
|
2
|
+
|
|
3
|
+
class InvalidDateError extends DatabaseError {
|
|
4
|
+
constructor(message = 'Invalid date format, expected YYYY-MM-DD'){
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'InvalidDateFormat';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { InvalidDateError as default };
|
|
11
|
+
//# sourceMappingURL=invalid-date.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-date.mjs","sources":["../../src/errors/invalid-date.ts"],"sourcesContent":["import DatabaseError from './database';\n\nexport default class InvalidDateError extends DatabaseError {\n constructor(message = 'Invalid date format, expected YYYY-MM-DD') {\n super(message);\n this.name = 'InvalidDateFormat';\n }\n}\n"],"names":["InvalidDateError","DatabaseError","constructor","message","name"],"mappings":";;AAEe,MAAMA,gBAAyBC,SAAAA,aAAAA,CAAAA;IAC5CC,WAAYC,CAAAA,OAAAA,GAAU,0CAA0C,CAAE;AAChE,QAAA,KAAK,CAACA,OAAAA,CAAAA;QACN,IAAI,CAACC,IAAI,GAAG,mBAAA;AACd;AACF;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var database = require('./database.js');
|
|
4
|
+
|
|
5
|
+
class InvalidDateTimeError extends database {
|
|
6
|
+
constructor(message = 'Invalid relation format'){
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'InvalidDatetimeFormat';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = InvalidDateTimeError;
|
|
13
|
+
//# sourceMappingURL=invalid-datetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-datetime.js","sources":["../../src/errors/invalid-datetime.ts"],"sourcesContent":["import DatabaseError from './database';\n\nexport default class InvalidDateTimeError extends DatabaseError {\n constructor(message = 'Invalid relation format') {\n super(message);\n this.name = 'InvalidDatetimeFormat';\n }\n}\n"],"names":["InvalidDateTimeError","DatabaseError","constructor","message","name"],"mappings":";;;;AAEe,MAAMA,oBAA6BC,SAAAA,QAAAA,CAAAA;IAChDC,WAAYC,CAAAA,OAAAA,GAAU,yBAAyB,CAAE;AAC/C,QAAA,KAAK,CAACA,OAAAA,CAAAA;QACN,IAAI,CAACC,IAAI,GAAG,uBAAA;AACd;AACF;;;;"}
|