json-fs-query 1.0.4 → 1.0.6
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/browser/jsonFsQuery.js +10158 -27750
- package/browser/jsonFsQuery.min.js +1 -1
- package/dist/data/introspect/create.d.ts +10 -10
- package/dist/data/introspect/create.js +47 -47
- package/dist/data/introspect/definitions/field.d.ts +27 -27
- package/dist/data/introspect/definitions/field.js +36 -36
- package/dist/data/introspect/definitions/key.d.ts +25 -25
- package/dist/data/introspect/definitions/key.js +53 -53
- package/dist/data/introspect/definitions/keyReference.d.ts +17 -17
- package/dist/data/introspect/definitions/keyReference.js +20 -20
- package/dist/data/introspect/definitions/record.d.ts +25 -25
- package/dist/data/introspect/definitions/record.js +32 -32
- package/dist/data/introspect/describe.js +15 -15
- package/dist/data/introspect/drop.js +37 -37
- package/dist/data/introspect/index.d.ts +7 -7
- package/dist/data/introspect/index.js +30 -30
- package/dist/data/introspect/policies/foreignKeyExists.d.ts +8 -8
- package/dist/data/introspect/policies/foreignKeyExists.js +25 -25
- package/dist/data/introspect/policies/hasDependents.d.ts +12 -12
- package/dist/data/introspect/policies/hasDependents.js +52 -52
- package/dist/data/introspect/policies/keyGenerate.d.ts +1 -1
- package/dist/data/introspect/policies/keyGenerate.js +17 -17
- package/dist/data/introspect/policies/keyUnique.d.ts +9 -9
- package/dist/data/introspect/policies/keyUnique.js +31 -31
- package/dist/data/introspect/policies/typeCheck.d.ts +11 -11
- package/dist/data/introspect/policies/typeCheck.js +57 -57
- package/dist/data/introspect/policies/typeEnum.d.ts +1 -1
- package/dist/data/introspect/policies/typeEnum.js +9 -9
- package/dist/data/introspect/policies/useDefault.d.ts +1 -1
- package/dist/data/introspect/policies/useDefault.js +8 -8
- package/dist/data/queries/deleteEntity.d.ts +1 -1
- package/dist/data/queries/deleteEntity.js +100 -100
- package/dist/data/queries/groupBy.d.ts +1 -1
- package/dist/data/queries/groupBy.js +22 -22
- package/dist/data/queries/insertEntity.d.ts +1 -1
- package/dist/data/queries/insertEntity.js +117 -117
- package/dist/data/queries/joinEntity.d.ts +1 -1
- package/dist/data/queries/joinEntity.js +32 -32
- package/dist/data/queries/joinEntity.min.js +1 -1
- package/dist/data/queries/limitOffset.d.ts +7 -7
- package/dist/data/queries/limitOffset.js +21 -21
- package/dist/data/queries/mergeJoins.d.ts +1 -1
- package/dist/data/queries/mergeJoins.js +19 -19
- package/dist/data/queries/mergeJoins.min.js +1 -1
- package/dist/data/queries/parser.d.ts +1 -1
- package/dist/data/queries/parser.js +19 -19
- package/dist/data/queries/parser.min.js +1 -1
- package/dist/data/queries/query.d.ts +1 -1
- package/dist/data/queries/query.js +18 -18
- package/dist/data/queries/query.min.js +1 -1
- package/dist/data/queries/readEntity.js +14 -14
- package/dist/data/queries/selectFields.d.ts +9 -9
- package/dist/data/queries/selectFields.js +36 -36
- package/dist/data/queries/sortBy.d.ts +1 -1
- package/dist/data/queries/sortBy.js +15 -15
- package/dist/data/queries/sortBy.min.js +1 -1
- package/dist/data/queries/updateEntity.d.ts +1 -1
- package/dist/data/queries/updateEntity.js +190 -190
- package/dist/data/queries/where.d.ts +6 -6
- package/dist/data/queries/where.js +56 -56
- package/dist/data/utilities/computeKeyValue.d.ts +12 -12
- package/dist/data/utilities/computeKeyValue.js +26 -26
- package/dist/data/utilities/config.d.ts +27 -27
- package/dist/data/utilities/config.js +45 -45
- package/dist/data/utilities/deregisterRecord.d.ts +7 -7
- package/dist/data/utilities/deregisterRecord.js +34 -34
- package/dist/data/utilities/getConditionIndexedList.js +47 -47
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
- package/dist/data/utilities/getJoinIndexedList.js +76 -76
- package/dist/data/utilities/getJoinIndexedList.min.js +1 -1
- package/dist/data/utilities/getMatchingIndexes.js +28 -28
- package/dist/data/utilities/getMatchingIndexes.min.js +1 -1
- package/dist/data/utilities/matchIndexedJoins.js +61 -61
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
- package/dist/data/utilities/mergeJoin.js +44 -44
- package/dist/data/utilities/mergeJoin.min.js +1 -1
- package/dist/data/utilities/parsers/findCommand.d.ts +9 -9
- package/dist/data/utilities/parsers/findCommand.js +25 -25
- package/dist/data/utilities/parsers/findConditions.d.ts +14 -14
- package/dist/data/utilities/parsers/findConditions.js +28 -28
- package/dist/data/utilities/parsers/findConditions.min.js +1 -1
- package/dist/data/utilities/parsers/findGroupBy.d.ts +8 -8
- package/dist/data/utilities/parsers/findGroupBy.js +22 -22
- package/dist/data/utilities/parsers/findInsertValues.d.ts +12 -12
- package/dist/data/utilities/parsers/findInsertValues.js +34 -34
- package/dist/data/utilities/parsers/findJoinClauses.d.ts +12 -12
- package/dist/data/utilities/parsers/findJoinClauses.js +27 -27
- package/dist/data/utilities/parsers/findJoinClauses.min.js +1 -1
- package/dist/data/utilities/parsers/findJoinEntity.d.ts +8 -8
- package/dist/data/utilities/parsers/findJoinEntity.js +22 -22
- package/dist/data/utilities/parsers/findLimit.d.ts +8 -8
- package/dist/data/utilities/parsers/findLimit.js +22 -22
- package/dist/data/utilities/parsers/findMergeJoins.d.ts +11 -11
- package/dist/data/utilities/parsers/findMergeJoins.js +26 -26
- package/dist/data/utilities/parsers/findMergeJoins.min.js +1 -1
- package/dist/data/utilities/parsers/findOffset.d.ts +8 -8
- package/dist/data/utilities/parsers/findOffset.js +22 -22
- package/dist/data/utilities/parsers/findSelects.d.ts +11 -11
- package/dist/data/utilities/parsers/findSelects.js +30 -30
- package/dist/data/utilities/parsers/findSelects.min.js +1 -1
- package/dist/data/utilities/parsers/findSortClauses.d.ts +11 -11
- package/dist/data/utilities/parsers/findSortClauses.js +30 -30
- package/dist/data/utilities/parsers/findSortClauses.min.js +1 -1
- package/dist/data/utilities/parsers/findUpdateValues.d.ts +14 -14
- package/dist/data/utilities/parsers/findUpdateValues.js +34 -34
- package/dist/data/utilities/parsers/isEntityProperty.js +6 -6
- package/dist/data/utilities/parsers/parseLiteralValue.d.ts +11 -11
- package/dist/data/utilities/parsers/parseLiteralValue.js +34 -34
- package/dist/data/utilities/parsers/parseQuery.d.ts +32 -32
- package/dist/data/utilities/parsers/parseQuery.js +51 -51
- package/dist/data/utilities/parsers/parseQuery.min.js +1 -1
- package/dist/data/utilities/parsers/removeFromQuery.js +6 -6
- package/dist/data/utilities/parsers/splitEntityProperty.js +13 -13
- package/dist/data/utilities/parsers/splitQueries.js +9 -9
- package/dist/data/utilities/reconcileJoin.js +26 -26
- package/dist/data/utilities/reconcileJoins.js +26 -26
- package/dist/data/utilities/reconcileJoins.min.js +1 -1
- package/dist/data/utilities/registerRecord.d.ts +7 -7
- package/dist/data/utilities/registerRecord.js +67 -67
- package/dist/data/utilities/removeFromIndex.d.ts +13 -13
- package/dist/data/utilities/removeFromIndex.js +44 -46
- package/dist/data/utilities/restrictIndexedList.js +45 -45
- package/dist/data/utilities/retrieveFile.js +28 -28
- package/dist/data/utilities/retrieveFile.min.js +1 -1
- package/dist/data/utilities/retrieveIndexes.d.ts +1 -1
- package/dist/data/utilities/retrieveIndexes.js +24 -24
- package/dist/data/utilities/retrieveIndexes.min.js +1 -1
- package/dist/data/utilities/retrieveRecord.js +9 -9
- package/dist/data/utilities/retrieveRecords.js +21 -21
- package/dist/data/utilities/retrieveRecords.min.js +1 -1
- package/dist/data/utilities/runQuery.d.ts +1 -1
- package/dist/data/utilities/runQuery.js +87 -87
- package/dist/data/utilities/updateIndex.d.ts +16 -16
- package/dist/data/utilities/updateIndex.js +56 -56
- package/dist/data/utilities/useJoinClause.d.ts +5 -5
- package/dist/data/utilities/useJoinClause.js +51 -51
- package/dist/index.d.ts +4 -4
- package/dist/index.js +42 -42
- package/package.json +9 -5
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require(
|
|
4
|
-
require(
|
|
5
|
-
require(
|
|
6
|
-
require(
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
value: true
|
|
9
|
-
})
|
|
10
|
-
exports.drop = void 0
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
rm
|
|
16
|
-
} = require('fs/promises')
|
|
17
|
-
const drop = async record => {
|
|
18
|
-
const databasePath = (0, _config.getSetting)('databasePath', 'database/')
|
|
19
|
-
if (record === '__RECORDS') {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
const recordFile = await (0, _retrieveFile.retrieveFile)(`${record}.json`)
|
|
23
|
-
for (const file of recordFile.entries) {
|
|
24
|
-
await rm(`${databasePath}${recordFile.path}/${file}`)
|
|
25
|
-
}
|
|
26
|
-
await rm(`${databasePath}${recordFile.path}`, {
|
|
27
|
-
recursive: true,
|
|
28
|
-
force: true
|
|
29
|
-
})
|
|
30
|
-
await rm(`${databasePath}__indexes/${recordFile.path}`, {
|
|
31
|
-
recursive: true,
|
|
32
|
-
force: true
|
|
33
|
-
})
|
|
34
|
-
await rm(`${databasePath}${record}.json`)
|
|
35
|
-
await (0, _deregisterRecord.deregisterRecord)(record)
|
|
36
|
-
}
|
|
37
|
-
exports.drop = drop
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.async-iterator.constructor.js");
|
|
4
|
+
require("core-js/modules/esnext.async-iterator.drop.js");
|
|
5
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
6
|
+
require("core-js/modules/esnext.iterator.drop.js");
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.drop = void 0;
|
|
11
|
+
var _retrieveFile = require("../utilities/retrieveFile");
|
|
12
|
+
var _deregisterRecord = require("../utilities/deregisterRecord");
|
|
13
|
+
var _config = require("../utilities/config");
|
|
14
|
+
const {
|
|
15
|
+
rm
|
|
16
|
+
} = require('fs/promises');
|
|
17
|
+
const drop = async record => {
|
|
18
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
19
|
+
if (record === '__RECORDS') {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const recordFile = await (0, _retrieveFile.retrieveFile)(`${record}.json`);
|
|
23
|
+
for (const file of recordFile.entries) {
|
|
24
|
+
await rm(`${databasePath}${recordFile.path}/${file}`);
|
|
25
|
+
}
|
|
26
|
+
await rm(`${databasePath}${recordFile.path}`, {
|
|
27
|
+
recursive: true,
|
|
28
|
+
force: true
|
|
29
|
+
});
|
|
30
|
+
await rm(`${databasePath}__indexes/${recordFile.path}`, {
|
|
31
|
+
recursive: true,
|
|
32
|
+
force: true
|
|
33
|
+
});
|
|
34
|
+
await rm(`${databasePath}${record}.json`);
|
|
35
|
+
await (0, _deregisterRecord.deregisterRecord)(record);
|
|
36
|
+
};
|
|
37
|
+
exports.drop = drop;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { create } from './create';
|
|
2
|
-
export { drop } from './drop';
|
|
3
|
-
export { describe } from './describe';
|
|
4
|
-
export { fieldProperties, fieldDefinition, fieldName } from './definitions/field';
|
|
5
|
-
export { keyProperties, keyDefinition, indexType, indexLocation } from './definitions/key';
|
|
6
|
-
export { referenceProperties, reference } from './definitions/keyReference';
|
|
7
|
-
export { recordProperties, recordDefinition, recordPath, entityPath } from './definitions/record';
|
|
1
|
+
export { create } from './create';
|
|
2
|
+
export { drop } from './drop';
|
|
3
|
+
export { describe } from './describe';
|
|
4
|
+
export { fieldProperties, fieldDefinition, fieldName } from './definitions/field';
|
|
5
|
+
export { keyProperties, keyDefinition, indexType, indexLocation } from './definitions/key';
|
|
6
|
+
export { referenceProperties, reference } from './definitions/keyReference';
|
|
7
|
+
export { recordProperties, recordDefinition, recordPath, entityPath } from './definitions/record';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require(
|
|
4
|
-
require(
|
|
5
|
-
require(
|
|
6
|
-
require(
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
value: true
|
|
9
|
-
})
|
|
10
|
-
Object.defineProperty(exports,
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _create.create
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
Object.defineProperty(exports,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return _describe.describe
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
Object.defineProperty(exports,
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () {
|
|
25
|
-
return _drop.drop
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
var _create = require(
|
|
29
|
-
var _drop = require(
|
|
30
|
-
var _describe = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.async-iterator.constructor.js");
|
|
4
|
+
require("core-js/modules/esnext.async-iterator.drop.js");
|
|
5
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
6
|
+
require("core-js/modules/esnext.iterator.drop.js");
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "create", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _create.create;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "describe", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _describe.describe;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "drop", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _drop.drop;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
var _create = require("./create");
|
|
29
|
+
var _drop = require("./drop");
|
|
30
|
+
var _describe = require("./describe");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check whether any record in the referenced entity has the given property set to the given
|
|
3
|
-
* value - the mirror image of keyUnique(), which checks that no record already has a value.
|
|
4
|
-
* @param entity
|
|
5
|
-
* @param property
|
|
6
|
-
* @param value
|
|
7
|
-
*/
|
|
8
|
-
export declare const foreignKeyExists: (entity: string, property: string, value: any) => Promise<boolean>;
|
|
1
|
+
/**
|
|
2
|
+
* Check whether any record in the referenced entity has the given property set to the given
|
|
3
|
+
* value - the mirror image of keyUnique(), which checks that no record already has a value.
|
|
4
|
+
* @param entity
|
|
5
|
+
* @param property
|
|
6
|
+
* @param value
|
|
7
|
+
*/
|
|
8
|
+
export declare const foreignKeyExists: (entity: string, property: string, value: any) => Promise<boolean>;
|
|
9
9
|
//# sourceMappingURL=foreignKeyExists.d.ts.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.foreignKeyExists = void 0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Check whether any record in the referenced entity has the given property set to the given
|
|
11
|
-
* value - the mirror image of keyUnique(), which checks that no record already has a value.
|
|
12
|
-
* @param entity
|
|
13
|
-
* @param property
|
|
14
|
-
* @param value
|
|
15
|
-
*/
|
|
16
|
-
const foreignKeyExists = async (entity, property, value) => {
|
|
17
|
-
const records = await (0, _retrieveRecords.retrieveRecords)(entity)
|
|
18
|
-
const found = (0, _where.where)(records, {
|
|
19
|
-
property,
|
|
20
|
-
comparator: '=',
|
|
21
|
-
value
|
|
22
|
-
})
|
|
23
|
-
return found.length > 0
|
|
24
|
-
}
|
|
25
|
-
exports.foreignKeyExists = foreignKeyExists
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.foreignKeyExists = void 0;
|
|
7
|
+
var _retrieveRecords = require("../../utilities/retrieveRecords");
|
|
8
|
+
var _where = require("../../queries/where");
|
|
9
|
+
/**
|
|
10
|
+
* Check whether any record in the referenced entity has the given property set to the given
|
|
11
|
+
* value - the mirror image of keyUnique(), which checks that no record already has a value.
|
|
12
|
+
* @param entity
|
|
13
|
+
* @param property
|
|
14
|
+
* @param value
|
|
15
|
+
*/
|
|
16
|
+
const foreignKeyExists = async (entity, property, value) => {
|
|
17
|
+
const records = await (0, _retrieveRecords.retrieveRecords)(entity);
|
|
18
|
+
const found = (0, _where.where)(records, {
|
|
19
|
+
property,
|
|
20
|
+
comparator: '=',
|
|
21
|
+
value
|
|
22
|
+
});
|
|
23
|
+
return found.length > 0;
|
|
24
|
+
};
|
|
25
|
+
exports.foreignKeyExists = foreignKeyExists;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check whether any other record, in any entity, still has a single-field foreign key pointing
|
|
3
|
-
* at entity.property = value - the mirror image of foreignKeyExists(), which checks the opposite
|
|
4
|
-
* direction (that a new/updated foreign key value points at something real). Used to RESTRICT a
|
|
5
|
-
* delete or update that would otherwise leave a dangling reference behind. Scans every record in
|
|
6
|
-
* the database via the __RECORDS registry, the same "no index needed, just look" approach as
|
|
7
|
-
* keyUnique()/foreignKeyExists() - correctness over speed, matching this project's overall scale.
|
|
8
|
-
* @param entity
|
|
9
|
-
* @param property
|
|
10
|
-
* @param value
|
|
11
|
-
*/
|
|
12
|
-
export declare const hasDependents: (entity: string, property: string, value: any) => Promise<boolean>;
|
|
1
|
+
/**
|
|
2
|
+
* Check whether any other record, in any entity, still has a single-field foreign key pointing
|
|
3
|
+
* at entity.property = value - the mirror image of foreignKeyExists(), which checks the opposite
|
|
4
|
+
* direction (that a new/updated foreign key value points at something real). Used to RESTRICT a
|
|
5
|
+
* delete or update that would otherwise leave a dangling reference behind. Scans every record in
|
|
6
|
+
* the database via the __RECORDS registry, the same "no index needed, just look" approach as
|
|
7
|
+
* keyUnique()/foreignKeyExists() - correctness over speed, matching this project's overall scale.
|
|
8
|
+
* @param entity
|
|
9
|
+
* @param property
|
|
10
|
+
* @param value
|
|
11
|
+
*/
|
|
12
|
+
export declare const hasDependents: (entity: string, property: string, value: any) => Promise<boolean>;
|
|
13
13
|
//# sourceMappingURL=hasDependents.d.ts.map
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.hasDependents = void 0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Check whether any other record, in any entity, still has a single-field foreign key pointing
|
|
14
|
-
* at entity.property = value - the mirror image of foreignKeyExists(), which checks the opposite
|
|
15
|
-
* direction (that a new/updated foreign key value points at something real). Used to RESTRICT a
|
|
16
|
-
* delete or update that would otherwise leave a dangling reference behind. Scans every record in
|
|
17
|
-
* the database via the __RECORDS registry, the same "no index needed, just look" approach as
|
|
18
|
-
* keyUnique()/foreignKeyExists() - correctness over speed, matching this project's overall scale.
|
|
19
|
-
* @param entity
|
|
20
|
-
* @param property
|
|
21
|
-
* @param value
|
|
22
|
-
*/
|
|
23
|
-
const hasDependents = async (entity, property, value) => {
|
|
24
|
-
const entityFiles = await (0, _describe.describe)()
|
|
25
|
-
for (const entityFile of entityFiles) {
|
|
26
|
-
const otherEntity = entityFile.replace(/\.json$/, '')
|
|
27
|
-
const otherRecord = await (0, _retrieveRecord.retrieveRecord)(otherEntity)
|
|
28
|
-
for (const key of otherRecord.keys) {
|
|
29
|
-
if (key.type !== 'foreign' || key.fields.length !== 1 || !key.references || key.references.length !== 1) {
|
|
30
|
-
continue
|
|
31
|
-
}
|
|
32
|
-
const {
|
|
33
|
-
entity: refEntity,
|
|
34
|
-
property: refProperty
|
|
35
|
-
} = (0, _splitEntityProperty.splitEntityProperty)(key.references[0].fields[0])
|
|
36
|
-
if (refEntity !== entity || refProperty !== property) {
|
|
37
|
-
continue
|
|
38
|
-
}
|
|
39
|
-
const records = await (0, _retrieveRecords.retrieveRecords)(otherEntity)
|
|
40
|
-
const found = (0, _where.where)(records, {
|
|
41
|
-
property: key.fields[0],
|
|
42
|
-
comparator: '=',
|
|
43
|
-
value
|
|
44
|
-
})
|
|
45
|
-
if (found.length) {
|
|
46
|
-
return true
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return false
|
|
51
|
-
}
|
|
52
|
-
exports.hasDependents = hasDependents
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasDependents = void 0;
|
|
7
|
+
var _describe = require("../describe");
|
|
8
|
+
var _retrieveRecord = require("../../utilities/retrieveRecord");
|
|
9
|
+
var _retrieveRecords = require("../../utilities/retrieveRecords");
|
|
10
|
+
var _where = require("../../queries/where");
|
|
11
|
+
var _splitEntityProperty = require("../../utilities/parsers/splitEntityProperty");
|
|
12
|
+
/**
|
|
13
|
+
* Check whether any other record, in any entity, still has a single-field foreign key pointing
|
|
14
|
+
* at entity.property = value - the mirror image of foreignKeyExists(), which checks the opposite
|
|
15
|
+
* direction (that a new/updated foreign key value points at something real). Used to RESTRICT a
|
|
16
|
+
* delete or update that would otherwise leave a dangling reference behind. Scans every record in
|
|
17
|
+
* the database via the __RECORDS registry, the same "no index needed, just look" approach as
|
|
18
|
+
* keyUnique()/foreignKeyExists() - correctness over speed, matching this project's overall scale.
|
|
19
|
+
* @param entity
|
|
20
|
+
* @param property
|
|
21
|
+
* @param value
|
|
22
|
+
*/
|
|
23
|
+
const hasDependents = async (entity, property, value) => {
|
|
24
|
+
const entityFiles = await (0, _describe.describe)();
|
|
25
|
+
for (const entityFile of entityFiles) {
|
|
26
|
+
const otherEntity = entityFile.replace(/\.json$/, '');
|
|
27
|
+
const otherRecord = await (0, _retrieveRecord.retrieveRecord)(otherEntity);
|
|
28
|
+
for (const key of otherRecord.keys) {
|
|
29
|
+
if (key.type !== 'foreign' || key.fields.length !== 1 || !key.references || key.references.length !== 1) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const {
|
|
33
|
+
entity: refEntity,
|
|
34
|
+
property: refProperty
|
|
35
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(key.references[0].fields[0]);
|
|
36
|
+
if (refEntity !== entity || refProperty !== property) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const records = await (0, _retrieveRecords.retrieveRecords)(otherEntity);
|
|
40
|
+
const found = (0, _where.where)(records, {
|
|
41
|
+
property: key.fields[0],
|
|
42
|
+
comparator: '=',
|
|
43
|
+
value
|
|
44
|
+
});
|
|
45
|
+
if (found.length) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
exports.hasDependents = hasDependents;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const keyGenerate: (entity: any, references?: any[]) => Promise<any>;
|
|
1
|
+
export declare const keyGenerate: (entity: any, references?: any[]) => Promise<any>;
|
|
2
2
|
//# sourceMappingURL=keyGenerate.d.ts.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.keyGenerate = void 0
|
|
7
|
-
|
|
8
|
-
const keyGenerate = async (entity, references = []) => {
|
|
9
|
-
let uuid = null
|
|
10
|
-
let isUnique = false
|
|
11
|
-
while (!isUnique) {
|
|
12
|
-
uuid = crypto.randomUUID()
|
|
13
|
-
isUnique = await (0, _keyUnique.keyUnique)(entity, references, [uuid])
|
|
14
|
-
}
|
|
15
|
-
return uuid
|
|
16
|
-
}
|
|
17
|
-
exports.keyGenerate = keyGenerate
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keyGenerate = void 0;
|
|
7
|
+
var _keyUnique = require("./keyUnique");
|
|
8
|
+
const keyGenerate = async (entity, references = []) => {
|
|
9
|
+
let uuid = null;
|
|
10
|
+
let isUnique = false;
|
|
11
|
+
while (!isUnique) {
|
|
12
|
+
uuid = crypto.randomUUID();
|
|
13
|
+
isUnique = await (0, _keyUnique.keyUnique)(entity, references, [uuid]);
|
|
14
|
+
}
|
|
15
|
+
return uuid;
|
|
16
|
+
};
|
|
17
|
+
exports.keyGenerate = keyGenerate;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check that no existing record already has this combination of values across all of the given
|
|
3
|
-
* fields - a single field for a normal unique/primary key, or several for a composite one.
|
|
4
|
-
* references and checkKeys are parallel arrays: references[i]'s value must equal checkKeys[i].
|
|
5
|
-
* @param entity
|
|
6
|
-
* @param references
|
|
7
|
-
* @param checkKeys
|
|
8
|
-
*/
|
|
9
|
-
export declare const keyUnique: (entity: any, references?: any[], checkKeys?: any[]) => Promise<boolean>;
|
|
1
|
+
/**
|
|
2
|
+
* Check that no existing record already has this combination of values across all of the given
|
|
3
|
+
* fields - a single field for a normal unique/primary key, or several for a composite one.
|
|
4
|
+
* references and checkKeys are parallel arrays: references[i]'s value must equal checkKeys[i].
|
|
5
|
+
* @param entity
|
|
6
|
+
* @param references
|
|
7
|
+
* @param checkKeys
|
|
8
|
+
*/
|
|
9
|
+
export declare const keyUnique: (entity: any, references?: any[], checkKeys?: any[]) => Promise<boolean>;
|
|
10
10
|
//# sourceMappingURL=keyUnique.d.ts.map
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.keyUnique = void 0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Check that no existing record already has this combination of values across all of the given
|
|
11
|
-
* fields - a single field for a normal unique/primary key, or several for a composite one.
|
|
12
|
-
* references and checkKeys are parallel arrays: references[i]'s value must equal checkKeys[i].
|
|
13
|
-
* @param entity
|
|
14
|
-
* @param references
|
|
15
|
-
* @param checkKeys
|
|
16
|
-
*/
|
|
17
|
-
const keyUnique = async (entity, references = [], checkKeys = []) => {
|
|
18
|
-
if (!references.length || references.length !== checkKeys.length) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
let records = await (0, _retrieveRecords.retrieveRecords)(entity)
|
|
22
|
-
for (let i = 0; i < references.length; i++) {
|
|
23
|
-
records = (0, _where.where)(records, {
|
|
24
|
-
property: references[i],
|
|
25
|
-
comparator: '=',
|
|
26
|
-
value: checkKeys[i]
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
return !records.length
|
|
30
|
-
}
|
|
31
|
-
exports.keyUnique = keyUnique
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keyUnique = void 0;
|
|
7
|
+
var _retrieveRecords = require("../../utilities/retrieveRecords");
|
|
8
|
+
var _where = require("../../queries/where");
|
|
9
|
+
/**
|
|
10
|
+
* Check that no existing record already has this combination of values across all of the given
|
|
11
|
+
* fields - a single field for a normal unique/primary key, or several for a composite one.
|
|
12
|
+
* references and checkKeys are parallel arrays: references[i]'s value must equal checkKeys[i].
|
|
13
|
+
* @param entity
|
|
14
|
+
* @param references
|
|
15
|
+
* @param checkKeys
|
|
16
|
+
*/
|
|
17
|
+
const keyUnique = async (entity, references = [], checkKeys = []) => {
|
|
18
|
+
if (!references.length || references.length !== checkKeys.length) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
let records = await (0, _retrieveRecords.retrieveRecords)(entity);
|
|
22
|
+
for (let i = 0; i < references.length; i++) {
|
|
23
|
+
records = (0, _where.where)(records, {
|
|
24
|
+
property: references[i],
|
|
25
|
+
comparator: '=',
|
|
26
|
+
value: checkKeys[i]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return !records.length;
|
|
30
|
+
};
|
|
31
|
+
exports.keyUnique = keyUnique;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate (and where sensible, coerce) a value against a field's declared type. Runs only
|
|
3
|
-
* against values being written by insertEntity/updateEntity - it never re-validates data already
|
|
4
|
-
* on disk, so a field whose declared type doesn't match its already-stored values (which can
|
|
5
|
-
* happen, since nothing enforced this before) is left alone until something actually updates it.
|
|
6
|
-
* An unrecognized type name is treated as unconstrained rather than rejected, so a typo in a
|
|
7
|
-
* schema's field type can't silently block every write to that field.
|
|
8
|
-
* @param type
|
|
9
|
-
* @param value
|
|
10
|
-
*/
|
|
11
|
-
export declare const typeCheck: (type?: string, value?: any) => any;
|
|
1
|
+
/**
|
|
2
|
+
* Validate (and where sensible, coerce) a value against a field's declared type. Runs only
|
|
3
|
+
* against values being written by insertEntity/updateEntity - it never re-validates data already
|
|
4
|
+
* on disk, so a field whose declared type doesn't match its already-stored values (which can
|
|
5
|
+
* happen, since nothing enforced this before) is left alone until something actually updates it.
|
|
6
|
+
* An unrecognized type name is treated as unconstrained rather than rejected, so a typo in a
|
|
7
|
+
* schema's field type can't silently block every write to that field.
|
|
8
|
+
* @param type
|
|
9
|
+
* @param value
|
|
10
|
+
*/
|
|
11
|
+
export declare const typeCheck: (type?: string, value?: any) => any;
|
|
12
12
|
//# sourceMappingURL=typeCheck.d.ts.map
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.typeCheck = void 0
|
|
7
|
-
/**
|
|
8
|
-
* Validate (and where sensible, coerce) a value against a field's declared type. Runs only
|
|
9
|
-
* against values being written by insertEntity/updateEntity - it never re-validates data already
|
|
10
|
-
* on disk, so a field whose declared type doesn't match its already-stored values (which can
|
|
11
|
-
* happen, since nothing enforced this before) is left alone until something actually updates it.
|
|
12
|
-
* An unrecognized type name is treated as unconstrained rather than rejected, so a typo in a
|
|
13
|
-
* schema's field type can't silently block every write to that field.
|
|
14
|
-
* @param type
|
|
15
|
-
* @param value
|
|
16
|
-
*/
|
|
17
|
-
const typeCheck = (type = 'string', value = undefined) => {
|
|
18
|
-
if (typeof value === 'undefined') {
|
|
19
|
-
return value
|
|
20
|
-
}
|
|
21
|
-
switch (type) {
|
|
22
|
-
case 'string':
|
|
23
|
-
return typeof value === 'string' ? value : String(value)
|
|
24
|
-
case 'int':
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case 'boolean':
|
|
33
|
-
if (typeof value === 'boolean') {
|
|
34
|
-
return value
|
|
35
|
-
}
|
|
36
|
-
if (value === 'true') {
|
|
37
|
-
return true
|
|
38
|
-
}
|
|
39
|
-
if (value === 'false') {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
throw new Error(`Value "${value}" is not a valid boolean`)
|
|
43
|
-
case 'object':
|
|
44
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
45
|
-
throw new Error(`Value "${value}" is not a valid object`)
|
|
46
|
-
}
|
|
47
|
-
return value
|
|
48
|
-
case 'array':
|
|
49
|
-
if (!Array.isArray(value)) {
|
|
50
|
-
throw new Error(`Value "${value}" is not a valid array`)
|
|
51
|
-
}
|
|
52
|
-
return value
|
|
53
|
-
default:
|
|
54
|
-
return value
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.typeCheck = typeCheck
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.typeCheck = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Validate (and where sensible, coerce) a value against a field's declared type. Runs only
|
|
9
|
+
* against values being written by insertEntity/updateEntity - it never re-validates data already
|
|
10
|
+
* on disk, so a field whose declared type doesn't match its already-stored values (which can
|
|
11
|
+
* happen, since nothing enforced this before) is left alone until something actually updates it.
|
|
12
|
+
* An unrecognized type name is treated as unconstrained rather than rejected, so a typo in a
|
|
13
|
+
* schema's field type can't silently block every write to that field.
|
|
14
|
+
* @param type
|
|
15
|
+
* @param value
|
|
16
|
+
*/
|
|
17
|
+
const typeCheck = (type = 'string', value = undefined) => {
|
|
18
|
+
if (typeof value === 'undefined') {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
switch (type) {
|
|
22
|
+
case 'string':
|
|
23
|
+
return typeof value === 'string' ? value : String(value);
|
|
24
|
+
case 'int':
|
|
25
|
+
{
|
|
26
|
+
const coerced = Number(value);
|
|
27
|
+
if (Number.isNaN(coerced) || !Number.isInteger(coerced)) {
|
|
28
|
+
throw new Error(`Value "${value}" is not a valid int`);
|
|
29
|
+
}
|
|
30
|
+
return coerced;
|
|
31
|
+
}
|
|
32
|
+
case 'boolean':
|
|
33
|
+
if (typeof value === 'boolean') {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (value === 'true') {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (value === 'false') {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Value "${value}" is not a valid boolean`);
|
|
43
|
+
case 'object':
|
|
44
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
45
|
+
throw new Error(`Value "${value}" is not a valid object`);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
case 'array':
|
|
49
|
+
if (!Array.isArray(value)) {
|
|
50
|
+
throw new Error(`Value "${value}" is not a valid array`);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
default:
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.typeCheck = typeCheck;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const typeEnum: (values?: any[], value?: string, optional?: boolean) => boolean;
|
|
1
|
+
export declare const typeEnum: (values?: any[], value?: string, optional?: boolean) => boolean;
|
|
2
2
|
//# sourceMappingURL=typeEnum.d.ts.map
|