json-fs-query 1.0.4 → 1.0.5
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 +21 -21
- package/dist/data/introspect/definitions/field.d.ts +27 -27
- package/dist/data/introspect/definitions/field.js +9 -9
- package/dist/data/introspect/definitions/key.d.ts +25 -25
- package/dist/data/introspect/definitions/key.js +19 -19
- package/dist/data/introspect/definitions/keyReference.d.ts +17 -17
- package/dist/data/introspect/definitions/keyReference.js +6 -6
- package/dist/data/introspect/definitions/record.d.ts +25 -25
- package/dist/data/introspect/definitions/record.js +11 -11
- package/dist/data/introspect/describe.js +10 -10
- package/dist/data/introspect/drop.js +22 -22
- package/dist/data/introspect/index.d.ts +7 -7
- package/dist/data/introspect/index.js +19 -19
- package/dist/data/introspect/policies/foreignKeyExists.d.ts +8 -8
- package/dist/data/introspect/policies/foreignKeyExists.js +11 -11
- package/dist/data/introspect/policies/hasDependents.d.ts +12 -12
- package/dist/data/introspect/policies/hasDependents.js +21 -21
- package/dist/data/introspect/policies/keyGenerate.d.ts +1 -1
- package/dist/data/introspect/policies/keyGenerate.js +12 -12
- package/dist/data/introspect/policies/keyUnique.d.ts +9 -9
- package/dist/data/introspect/policies/keyUnique.js +12 -12
- package/dist/data/introspect/policies/typeCheck.d.ts +11 -11
- package/dist/data/introspect/policies/typeCheck.js +23 -23
- package/dist/data/introspect/policies/typeEnum.d.ts +1 -1
- package/dist/data/introspect/policies/typeEnum.js +14 -14
- package/dist/data/introspect/policies/useDefault.d.ts +1 -1
- package/dist/data/introspect/policies/useDefault.js +13 -13
- package/dist/data/queries/deleteEntity.d.ts +1 -1
- package/dist/data/queries/deleteEntity.js +57 -57
- package/dist/data/queries/groupBy.d.ts +1 -1
- package/dist/data/queries/groupBy.js +14 -14
- package/dist/data/queries/insertEntity.d.ts +1 -1
- package/dist/data/queries/insertEntity.js +56 -56
- package/dist/data/queries/joinEntity.d.ts +1 -1
- package/dist/data/queries/joinEntity.js +18 -18
- package/dist/data/queries/joinEntity.min.js +1 -1
- package/dist/data/queries/limitOffset.d.ts +7 -7
- package/dist/data/queries/limitOffset.js +10 -10
- package/dist/data/queries/mergeJoins.d.ts +1 -1
- package/dist/data/queries/mergeJoins.js +12 -12
- package/dist/data/queries/mergeJoins.min.js +1 -1
- package/dist/data/queries/parser.d.ts +1 -1
- package/dist/data/queries/parser.js +30 -30
- package/dist/data/queries/parser.min.js +1 -1
- package/dist/data/queries/query.d.ts +1 -1
- package/dist/data/queries/query.js +13 -13
- package/dist/data/queries/query.min.js +1 -1
- package/dist/data/queries/readEntity.js +9 -9
- package/dist/data/queries/selectFields.d.ts +9 -9
- package/dist/data/queries/selectFields.js +17 -17
- package/dist/data/queries/sortBy.d.ts +1 -1
- package/dist/data/queries/sortBy.js +25 -25
- package/dist/data/queries/sortBy.min.js +1 -1
- package/dist/data/queries/updateEntity.d.ts +1 -1
- package/dist/data/queries/updateEntity.js +74 -74
- package/dist/data/queries/where.d.ts +6 -6
- package/dist/data/queries/where.js +29 -29
- package/dist/data/utilities/computeKeyValue.d.ts +12 -12
- package/dist/data/utilities/computeKeyValue.js +11 -11
- package/dist/data/utilities/config.d.ts +27 -27
- package/dist/data/utilities/config.js +12 -12
- package/dist/data/utilities/deregisterRecord.d.ts +7 -7
- package/dist/data/utilities/deregisterRecord.js +20 -20
- package/dist/data/utilities/getConditionIndexedList.js +27 -27
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
- package/dist/data/utilities/getJoinIndexedList.js +39 -39
- package/dist/data/utilities/getJoinIndexedList.min.js +1 -1
- package/dist/data/utilities/getMatchingIndexes.js +15 -15
- package/dist/data/utilities/getMatchingIndexes.min.js +1 -1
- package/dist/data/utilities/matchIndexedJoins.js +24 -24
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
- package/dist/data/utilities/mergeJoin.js +23 -23
- 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 +15 -15
- package/dist/data/utilities/parsers/findConditions.d.ts +14 -14
- package/dist/data/utilities/parsers/findConditions.js +14 -14
- 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 +12 -12
- package/dist/data/utilities/parsers/findInsertValues.d.ts +12 -12
- package/dist/data/utilities/parsers/findInsertValues.js +19 -19
- package/dist/data/utilities/parsers/findJoinClauses.d.ts +12 -12
- package/dist/data/utilities/parsers/findJoinClauses.js +13 -13
- 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 +12 -12
- package/dist/data/utilities/parsers/findLimit.d.ts +8 -8
- package/dist/data/utilities/parsers/findLimit.js +12 -12
- package/dist/data/utilities/parsers/findMergeJoins.d.ts +11 -11
- package/dist/data/utilities/parsers/findMergeJoins.js +13 -13
- 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 +12 -12
- package/dist/data/utilities/parsers/findSelects.d.ts +11 -11
- package/dist/data/utilities/parsers/findSelects.js +15 -15
- 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 +15 -15
- 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 +17 -17
- package/dist/data/utilities/parsers/isEntityProperty.js +8 -8
- package/dist/data/utilities/parsers/parseLiteralValue.d.ts +11 -11
- package/dist/data/utilities/parsers/parseLiteralValue.js +12 -12
- package/dist/data/utilities/parsers/parseQuery.d.ts +32 -32
- package/dist/data/utilities/parsers/parseQuery.js +25 -25
- package/dist/data/utilities/parsers/parseQuery.min.js +1 -1
- package/dist/data/utilities/parsers/removeFromQuery.js +8 -8
- package/dist/data/utilities/parsers/splitEntityProperty.js +23 -23
- package/dist/data/utilities/parsers/splitQueries.js +11 -11
- package/dist/data/utilities/reconcileJoin.js +14 -14
- package/dist/data/utilities/reconcileJoins.js +13 -13
- package/dist/data/utilities/reconcileJoins.min.js +1 -1
- package/dist/data/utilities/registerRecord.d.ts +7 -7
- package/dist/data/utilities/registerRecord.js +20 -20
- package/dist/data/utilities/removeFromIndex.d.ts +13 -13
- package/dist/data/utilities/removeFromIndex.js +24 -26
- package/dist/data/utilities/restrictIndexedList.js +18 -18
- package/dist/data/utilities/retrieveFile.js +19 -19
- package/dist/data/utilities/retrieveFile.min.js +1 -1
- package/dist/data/utilities/retrieveIndexes.d.ts +1 -1
- package/dist/data/utilities/retrieveIndexes.js +13 -13
- package/dist/data/utilities/retrieveIndexes.min.js +1 -1
- package/dist/data/utilities/retrieveRecord.js +7 -7
- package/dist/data/utilities/retrieveRecords.js +14 -14
- package/dist/data/utilities/retrieveRecords.min.js +1 -1
- package/dist/data/utilities/runQuery.d.ts +1 -1
- package/dist/data/utilities/runQuery.js +49 -49
- package/dist/data/utilities/updateIndex.d.ts +16 -16
- package/dist/data/utilities/updateIndex.js +25 -25
- package/dist/data/utilities/useJoinClause.d.ts +5 -5
- package/dist/data/utilities/useJoinClause.js +22 -22
- package/dist/index.d.ts +4 -4
- package/dist/index.js +25 -25
- package/package.json +4 -4
|
@@ -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,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.hasDependents = void 0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
12
|
/**
|
|
13
13
|
* Check whether any other record, in any entity, still has a single-field foreign key pointing
|
|
14
14
|
* at entity.property = value - the mirror image of foreignKeyExists(), which checks the opposite
|
|
@@ -21,32 +21,32 @@ const _splitEntityProperty = require('../../utilities/parsers/splitEntityPropert
|
|
|
21
21
|
* @param value
|
|
22
22
|
*/
|
|
23
23
|
const hasDependents = async (entity, property, value) => {
|
|
24
|
-
const entityFiles = await (0, _describe.describe)()
|
|
24
|
+
const entityFiles = await (0, _describe.describe)();
|
|
25
25
|
for (const entityFile of entityFiles) {
|
|
26
|
-
const otherEntity = entityFile.replace(/\.json$/, '')
|
|
27
|
-
const otherRecord = await (0, _retrieveRecord.retrieveRecord)(otherEntity)
|
|
26
|
+
const otherEntity = entityFile.replace(/\.json$/, '');
|
|
27
|
+
const otherRecord = await (0, _retrieveRecord.retrieveRecord)(otherEntity);
|
|
28
28
|
for (const key of otherRecord.keys) {
|
|
29
29
|
if (key.type !== 'foreign' || key.fields.length !== 1 || !key.references || key.references.length !== 1) {
|
|
30
|
-
continue
|
|
30
|
+
continue;
|
|
31
31
|
}
|
|
32
32
|
const {
|
|
33
33
|
entity: refEntity,
|
|
34
34
|
property: refProperty
|
|
35
|
-
} = (0, _splitEntityProperty.splitEntityProperty)(key.references[0].fields[0])
|
|
35
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(key.references[0].fields[0]);
|
|
36
36
|
if (refEntity !== entity || refProperty !== property) {
|
|
37
|
-
continue
|
|
37
|
+
continue;
|
|
38
38
|
}
|
|
39
|
-
const records = await (0, _retrieveRecords.retrieveRecords)(otherEntity)
|
|
39
|
+
const records = await (0, _retrieveRecords.retrieveRecords)(otherEntity);
|
|
40
40
|
const found = (0, _where.where)(records, {
|
|
41
41
|
property: key.fields[0],
|
|
42
42
|
comparator: '=',
|
|
43
43
|
value
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
if (found.length) {
|
|
46
|
-
return true
|
|
46
|
+
return true;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
return false
|
|
51
|
-
}
|
|
52
|
-
exports.hasDependents = hasDependents
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.keyGenerate = void 0
|
|
7
|
-
|
|
5
|
+
});
|
|
6
|
+
exports.keyGenerate = void 0;
|
|
7
|
+
var _keyUnique = require("./keyUnique");
|
|
8
8
|
const keyGenerate = async (entity, references = []) => {
|
|
9
|
-
let uuid = null
|
|
10
|
-
let isUnique = false
|
|
9
|
+
let uuid = null;
|
|
10
|
+
let isUnique = false;
|
|
11
11
|
while (!isUnique) {
|
|
12
|
-
uuid = crypto.randomUUID()
|
|
13
|
-
isUnique = await (0, _keyUnique.keyUnique)(entity, references, [uuid])
|
|
12
|
+
uuid = crypto.randomUUID();
|
|
13
|
+
isUnique = await (0, _keyUnique.keyUnique)(entity, references, [uuid]);
|
|
14
14
|
}
|
|
15
|
-
return uuid
|
|
16
|
-
}
|
|
17
|
-
exports.keyGenerate = keyGenerate
|
|
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,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.keyUnique = void 0
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
});
|
|
6
|
+
exports.keyUnique = void 0;
|
|
7
|
+
var _retrieveRecords = require("../../utilities/retrieveRecords");
|
|
8
|
+
var _where = require("../../queries/where");
|
|
9
9
|
/**
|
|
10
10
|
* Check that no existing record already has this combination of values across all of the given
|
|
11
11
|
* fields - a single field for a normal unique/primary key, or several for a composite one.
|
|
@@ -16,16 +16,16 @@ const _where = require('../../queries/where')
|
|
|
16
16
|
*/
|
|
17
17
|
const keyUnique = async (entity, references = [], checkKeys = []) => {
|
|
18
18
|
if (!references.length || references.length !== checkKeys.length) {
|
|
19
|
-
return false
|
|
19
|
+
return false;
|
|
20
20
|
}
|
|
21
|
-
let records = await (0, _retrieveRecords.retrieveRecords)(entity)
|
|
21
|
+
let records = await (0, _retrieveRecords.retrieveRecords)(entity);
|
|
22
22
|
for (let i = 0; i < references.length; i++) {
|
|
23
23
|
records = (0, _where.where)(records, {
|
|
24
24
|
property: references[i],
|
|
25
25
|
comparator: '=',
|
|
26
26
|
value: checkKeys[i]
|
|
27
|
-
})
|
|
27
|
+
});
|
|
28
28
|
}
|
|
29
|
-
return !records.length
|
|
30
|
-
}
|
|
31
|
-
exports.keyUnique = keyUnique
|
|
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,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.typeCheck = void 0
|
|
5
|
+
});
|
|
6
|
+
exports.typeCheck = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Validate (and where sensible, coerce) a value against a field's declared type. Runs only
|
|
9
9
|
* against values being written by insertEntity/updateEntity - it never re-validates data already
|
|
@@ -16,42 +16,42 @@ exports.typeCheck = void 0
|
|
|
16
16
|
*/
|
|
17
17
|
const typeCheck = (type = 'string', value = undefined) => {
|
|
18
18
|
if (typeof value === 'undefined') {
|
|
19
|
-
return value
|
|
19
|
+
return value;
|
|
20
20
|
}
|
|
21
21
|
switch (type) {
|
|
22
22
|
case 'string':
|
|
23
|
-
return typeof value === 'string' ? value : String(value)
|
|
23
|
+
return typeof value === 'string' ? value : String(value);
|
|
24
24
|
case 'int':
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
|
29
31
|
}
|
|
30
|
-
return coerced
|
|
31
|
-
}
|
|
32
32
|
case 'boolean':
|
|
33
33
|
if (typeof value === 'boolean') {
|
|
34
|
-
return value
|
|
34
|
+
return value;
|
|
35
35
|
}
|
|
36
36
|
if (value === 'true') {
|
|
37
|
-
return true
|
|
37
|
+
return true;
|
|
38
38
|
}
|
|
39
39
|
if (value === 'false') {
|
|
40
|
-
return false
|
|
40
|
+
return false;
|
|
41
41
|
}
|
|
42
|
-
throw new Error(`Value "${value}" is not a valid boolean`)
|
|
42
|
+
throw new Error(`Value "${value}" is not a valid boolean`);
|
|
43
43
|
case 'object':
|
|
44
44
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
45
|
-
throw new Error(`Value "${value}" is not a valid object`)
|
|
45
|
+
throw new Error(`Value "${value}" is not a valid object`);
|
|
46
46
|
}
|
|
47
|
-
return value
|
|
47
|
+
return value;
|
|
48
48
|
case 'array':
|
|
49
49
|
if (!Array.isArray(value)) {
|
|
50
|
-
throw new Error(`Value "${value}" is not a valid array`)
|
|
50
|
+
throw new Error(`Value "${value}" is not a valid array`);
|
|
51
51
|
}
|
|
52
|
-
return value
|
|
52
|
+
return value;
|
|
53
53
|
default:
|
|
54
|
-
return value
|
|
54
|
+
return value;
|
|
55
55
|
}
|
|
56
|
-
}
|
|
57
|
-
exports.typeCheck = typeCheck
|
|
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
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.typeEnum = void 0
|
|
7
|
-
require(
|
|
8
|
-
const typeEnum = (values = [], value = '', optional = false) => {
|
|
9
|
-
if (values.includes(value)) {
|
|
10
|
-
return true
|
|
11
|
-
}
|
|
12
|
-
return typeof value === 'undefined' && optional
|
|
13
|
-
}
|
|
14
|
-
exports.typeEnum = typeEnum
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.typeEnum = void 0;
|
|
7
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
|
+
const typeEnum = (values = [], value = '', optional = false) => {
|
|
9
|
+
if (values.includes(value)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return typeof value === 'undefined' && optional;
|
|
13
|
+
};
|
|
14
|
+
exports.typeEnum = typeEnum;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const useDefault: (defaultValue?: string, value?: any) => any;
|
|
1
|
+
export declare const useDefault: (defaultValue?: string, value?: any) => any;
|
|
2
2
|
//# sourceMappingURL=useDefault.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.useDefault = void 0
|
|
7
|
-
const useDefault = (defaultValue = '', value = undefined) => {
|
|
8
|
-
if (typeof value === 'undefined') {
|
|
9
|
-
return defaultValue
|
|
10
|
-
}
|
|
11
|
-
return value
|
|
12
|
-
}
|
|
13
|
-
exports.useDefault = useDefault
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDefault = void 0;
|
|
7
|
+
const useDefault = (defaultValue = '', value = undefined) => {
|
|
8
|
+
if (typeof value === 'undefined') {
|
|
9
|
+
return defaultValue;
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
exports.useDefault = useDefault;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const deleteEntity: (entity?: string, dataSet?: Object) => Promise<Object>;
|
|
1
|
+
export declare const deleteEntity: (entity?: string, dataSet?: Object) => Promise<Object>;
|
|
2
2
|
//# sourceMappingURL=deleteEntity.d.ts.map
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.deleteEntity = void 0
|
|
7
|
-
require(
|
|
8
|
-
require(
|
|
9
|
-
require(
|
|
10
|
-
require(
|
|
11
|
-
require(
|
|
12
|
-
require(
|
|
13
|
-
require(
|
|
14
|
-
require(
|
|
15
|
-
require(
|
|
16
|
-
require(
|
|
17
|
-
require(
|
|
18
|
-
require(
|
|
19
|
-
require(
|
|
20
|
-
require(
|
|
21
|
-
require(
|
|
22
|
-
require(
|
|
23
|
-
require(
|
|
24
|
-
require(
|
|
25
|
-
require(
|
|
26
|
-
require(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
5
|
+
});
|
|
6
|
+
exports.deleteEntity = void 0;
|
|
7
|
+
require("core-js/modules/es.json.stringify.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
9
|
+
require("core-js/modules/esnext.iterator.find.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
11
|
+
require("core-js/modules/esnext.set.add-all.js");
|
|
12
|
+
require("core-js/modules/esnext.set.delete-all.js");
|
|
13
|
+
require("core-js/modules/esnext.set.difference.js");
|
|
14
|
+
require("core-js/modules/esnext.set.every.js");
|
|
15
|
+
require("core-js/modules/esnext.set.filter.js");
|
|
16
|
+
require("core-js/modules/esnext.set.find.js");
|
|
17
|
+
require("core-js/modules/esnext.set.intersection.js");
|
|
18
|
+
require("core-js/modules/esnext.set.is-disjoint-from.js");
|
|
19
|
+
require("core-js/modules/esnext.set.is-subset-of.js");
|
|
20
|
+
require("core-js/modules/esnext.set.is-superset-of.js");
|
|
21
|
+
require("core-js/modules/esnext.set.join.js");
|
|
22
|
+
require("core-js/modules/esnext.set.map.js");
|
|
23
|
+
require("core-js/modules/esnext.set.reduce.js");
|
|
24
|
+
require("core-js/modules/esnext.set.some.js");
|
|
25
|
+
require("core-js/modules/esnext.set.symmetric-difference.js");
|
|
26
|
+
require("core-js/modules/esnext.set.union.js");
|
|
27
|
+
var _retrieveRecord = require("../utilities/retrieveRecord");
|
|
28
|
+
var _retrieveFile = require("../utilities/retrieveFile");
|
|
29
|
+
var _removeFromIndex = require("../utilities/removeFromIndex");
|
|
30
|
+
var _computeKeyValue = require("../utilities/computeKeyValue");
|
|
31
|
+
var _hasDependents = require("../introspect/policies/hasDependents");
|
|
32
|
+
var _config = require("../utilities/config");
|
|
33
33
|
const {
|
|
34
34
|
rm,
|
|
35
35
|
writeFile
|
|
36
|
-
} = require('fs/promises')
|
|
36
|
+
} = require('fs/promises');
|
|
37
37
|
/**
|
|
38
38
|
* RESTRICT: reject the whole delete (before removing anything) if any row being deleted is still
|
|
39
39
|
* referenced by a single-field foreign key elsewhere. Only meaningful for a single-field primary
|
|
@@ -45,15 +45,15 @@ const {
|
|
|
45
45
|
*/
|
|
46
46
|
const assertNoDependents = async (entity, primaryKey, toDelete) => {
|
|
47
47
|
if (!(0, _config.getSetting)('enforceForeignKeys', true) || primaryKey.fields.length !== 1) {
|
|
48
|
-
return
|
|
48
|
+
return;
|
|
49
49
|
}
|
|
50
|
-
const property = primaryKey.fields[0]
|
|
50
|
+
const property = primaryKey.fields[0];
|
|
51
51
|
for (const row of toDelete) {
|
|
52
52
|
if (await (0, _hasDependents.hasDependents)(entity, property, row[property])) {
|
|
53
|
-
throw new Error(`Cannot delete from "${entity}" where "${property}" = ${row[property]} - other records still reference it`)
|
|
53
|
+
throw new Error(`Cannot delete from "${entity}" where "${property}" = ${row[property]} - other records still reference it`);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
57
|
/**
|
|
58
58
|
* A record object carries no memory of which entry file it was read from, and files are not
|
|
59
59
|
* guaranteed to be named after any field's value, so the only reliable way to find a record's
|
|
@@ -65,36 +65,36 @@ const assertNoDependents = async (entity, primaryKey, toDelete) => {
|
|
|
65
65
|
* @param deletedValues
|
|
66
66
|
*/
|
|
67
67
|
const removeMatchingEntries = async (entity, record, primaryKey, deletedValues) => {
|
|
68
|
-
const databasePath = (0, _config.getSetting)('databasePath', 'database/')
|
|
69
|
-
const remainingEntries = []
|
|
68
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
69
|
+
const remainingEntries = [];
|
|
70
70
|
for (const fileName of record.entries) {
|
|
71
|
-
const data = await (0, _retrieveFile.retrieveFile)(`${record.path}/${fileName}`)
|
|
71
|
+
const data = await (0, _retrieveFile.retrieveFile)(`${record.path}/${fileName}`);
|
|
72
72
|
if (!deletedValues.has((0, _computeKeyValue.computeKeyValue)(primaryKey.fields, data))) {
|
|
73
|
-
remainingEntries.push(fileName)
|
|
74
|
-
continue
|
|
73
|
+
remainingEntries.push(fileName);
|
|
74
|
+
continue;
|
|
75
75
|
}
|
|
76
|
-
await rm(`${databasePath}${record.path}/${fileName}`)
|
|
76
|
+
await rm(`${databasePath}${record.path}/${fileName}`);
|
|
77
77
|
for (const key of record.keys) {
|
|
78
|
-
await (0, _removeFromIndex.removeFromIndex)(record.path, key, (0, _computeKeyValue.computeKeyValue)(key.fields, data), fileName)
|
|
78
|
+
await (0, _removeFromIndex.removeFromIndex)(record.path, key, (0, _computeKeyValue.computeKeyValue)(key.fields, data), fileName);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
return remainingEntries
|
|
82
|
-
}
|
|
81
|
+
return remainingEntries;
|
|
82
|
+
};
|
|
83
83
|
const deleteEntity = async (entity = '', dataSet = {}) => {
|
|
84
|
-
const databasePath = (0, _config.getSetting)('databasePath', 'database/')
|
|
85
|
-
const record = await (0, _retrieveRecord.retrieveRecord)(entity)
|
|
86
|
-
const primaryKey = record.keys.find(key => key.type === 'primary')
|
|
84
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
85
|
+
const record = await (0, _retrieveRecord.retrieveRecord)(entity);
|
|
86
|
+
const primaryKey = record.keys.find(key => key.type === 'primary');
|
|
87
87
|
if (!primaryKey) {
|
|
88
|
-
throw new Error(`Cannot delete from "${entity}" without a primary key`)
|
|
88
|
+
throw new Error(`Cannot delete from "${entity}" without a primary key`);
|
|
89
89
|
}
|
|
90
|
-
const toDelete = dataSet[entity] || []
|
|
90
|
+
const toDelete = dataSet[entity] || [];
|
|
91
91
|
if (!toDelete.length) {
|
|
92
|
-
return dataSet
|
|
92
|
+
return dataSet;
|
|
93
93
|
}
|
|
94
|
-
await assertNoDependents(entity, primaryKey, toDelete)
|
|
95
|
-
const deletedValues = new Set(toDelete.map(row => (0, _computeKeyValue.computeKeyValue)(primaryKey.fields, row)))
|
|
96
|
-
record.entries = await removeMatchingEntries(entity, record, primaryKey, deletedValues)
|
|
97
|
-
await writeFile(`${databasePath}${record.path}.json`, JSON.stringify(record, null, 2))
|
|
98
|
-
return dataSet
|
|
99
|
-
}
|
|
100
|
-
exports.deleteEntity = deleteEntity
|
|
94
|
+
await assertNoDependents(entity, primaryKey, toDelete);
|
|
95
|
+
const deletedValues = new Set(toDelete.map(row => (0, _computeKeyValue.computeKeyValue)(primaryKey.fields, row)));
|
|
96
|
+
record.entries = await removeMatchingEntries(entity, record, primaryKey, deletedValues);
|
|
97
|
+
await writeFile(`${databasePath}${record.path}.json`, JSON.stringify(record, null, 2));
|
|
98
|
+
return dataSet;
|
|
99
|
+
};
|
|
100
|
+
exports.deleteEntity = deleteEntity;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const groupBy: (dataSet?: any[], groupProperty?: string) => any;
|
|
1
|
+
export declare const groupBy: (dataSet?: any[], groupProperty?: string) => any;
|
|
2
2
|
//# sourceMappingURL=groupBy.d.ts.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.groupBy = void 0
|
|
7
|
-
require(
|
|
8
|
-
require(
|
|
5
|
+
});
|
|
6
|
+
exports.groupBy = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.reduce.js");
|
|
9
9
|
const groupBy = (dataSet = [], groupProperty = '') => {
|
|
10
10
|
if (!groupProperty) {
|
|
11
|
-
return dataSet
|
|
11
|
+
return dataSet;
|
|
12
12
|
}
|
|
13
13
|
return dataSet.reduce((groupedData, data) => {
|
|
14
|
-
const property = data[groupProperty]
|
|
14
|
+
const property = data[groupProperty];
|
|
15
15
|
if (!Object.prototype.hasOwnProperty.call(groupedData, property)) {
|
|
16
|
-
groupedData[property] = []
|
|
16
|
+
groupedData[property] = [];
|
|
17
17
|
}
|
|
18
|
-
groupedData[property].push(data)
|
|
19
|
-
return groupedData
|
|
20
|
-
}, {})
|
|
21
|
-
}
|
|
22
|
-
exports.groupBy = groupBy
|
|
18
|
+
groupedData[property].push(data);
|
|
19
|
+
return groupedData;
|
|
20
|
+
}, {});
|
|
21
|
+
};
|
|
22
|
+
exports.groupBy = groupBy;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const insertEntity: (entity?: string, values?: Object[], dataSet?: Object) => Promise<Object>;
|
|
1
|
+
export declare const insertEntity: (entity?: string, values?: Object[], dataSet?: Object) => Promise<Object>;
|
|
2
2
|
//# sourceMappingURL=insertEntity.d.ts.map
|