json-fs-query 1.0.6 → 1.1.0
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 +518 -361
- package/browser/jsonFsQuery.min.js +1 -1
- package/dist/data/introspect/policies/foreignKeyExists.js +28 -24
- package/dist/data/introspect/policies/foreignKeyExists.min.js +1 -1
- package/dist/data/introspect/policies/hasDependents.js +53 -51
- package/dist/data/introspect/policies/hasDependents.min.js +1 -1
- package/dist/data/introspect/policies/keyUnique.js +34 -30
- package/dist/data/introspect/policies/keyUnique.min.js +1 -1
- package/dist/data/queries/deleteEntity.js +100 -99
- package/dist/data/queries/deleteEntity.min.js +1 -1
- package/dist/data/queries/insertEntity.js +117 -116
- package/dist/data/queries/insertEntity.min.js +1 -1
- package/dist/data/queries/sortBy.js +27 -24
- package/dist/data/queries/updateEntity.js +193 -189
- package/dist/data/queries/updateEntity.min.js +1 -1
- package/dist/data/queries/where.d.ts +7 -6
- package/dist/data/queries/where.js +67 -55
- package/dist/data/queries/where.min.js +1 -1
- package/dist/data/utilities/compareAs.d.ts +20 -0
- package/dist/data/utilities/compareAs.js +58 -0
- package/dist/data/utilities/compareAs.min.js +1 -0
- package/dist/data/utilities/fieldType.d.ts +16 -0
- package/dist/data/utilities/fieldType.js +23 -0
- package/dist/data/utilities/fieldType.min.js +1 -0
- package/dist/data/utilities/getConditionIndexedList.js +47 -46
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
- package/dist/data/utilities/matchIndexedJoins.js +62 -60
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -1
- package/dist/data/utilities/mergeJoin.js +47 -43
- package/dist/data/utilities/mergeJoin.min.js +1 -1
- package/dist/data/utilities/parsers/findConditions.d.ts +15 -14
- package/dist/data/utilities/removeFromIndex.d.ts +14 -13
- package/dist/data/utilities/removeFromIndex.js +45 -43
- package/dist/data/utilities/removeFromIndex.min.js +1 -1
- package/dist/data/utilities/runQuery.js +112 -86
- package/dist/data/utilities/runQuery.min.js +1 -1
- package/dist/data/utilities/updateIndex.d.ts +17 -16
- package/dist/data/utilities/updateIndex.js +57 -55
- package/dist/data/utilities/updateIndex.min.js +1 -1
- package/dist/data/utilities/useJoinClause.js +56 -50
- package/dist/data/utilities/useJoinClause.min.js +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sameValue = exports.compareAs = void 0;
|
|
7
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
|
+
/**
|
|
9
|
+
* Normalize a value to a field's declared type for an equality comparison - never written back,
|
|
10
|
+
* only compared. Writes are coerced to the declared type (typeCheck), but values already stored
|
|
11
|
+
* may not match it (ids declared string, so they can hold an integer or a UUID, are often stored
|
|
12
|
+
* as numbers), and query literals carry their own type. A declared type is what says '3' and 3
|
|
13
|
+
* are the same value. A missing or unrecognized type returns the value unchanged.
|
|
14
|
+
* @param type
|
|
15
|
+
* @param value
|
|
16
|
+
*/
|
|
17
|
+
const compareAs = (type, value) => {
|
|
18
|
+
if (value === null || typeof value === 'undefined') {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
switch (type) {
|
|
22
|
+
case 'string':
|
|
23
|
+
return typeof value === 'object' ? value : String(value);
|
|
24
|
+
case 'int':
|
|
25
|
+
{
|
|
26
|
+
const coerced = Number(value);
|
|
27
|
+
return Number.isNaN(coerced) ? value : coerced;
|
|
28
|
+
}
|
|
29
|
+
case 'boolean':
|
|
30
|
+
if (value === 'true') {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (value === 'false') {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
default:
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.compareAs = compareAs;
|
|
42
|
+
const comparableTypes = ['string', 'int', 'boolean'];
|
|
43
|
+
/**
|
|
44
|
+
* Whether two values are equal for a field of the given declared type: both are normalized to
|
|
45
|
+
* that type (see compareAs) and compared strictly. A field with no declared type, or one that
|
|
46
|
+
* can't be normalized (object, array, or an unrecognized type), keeps loose equality.
|
|
47
|
+
* @param type
|
|
48
|
+
* @param a
|
|
49
|
+
* @param b
|
|
50
|
+
*/
|
|
51
|
+
const sameValue = (type, a, b) => {
|
|
52
|
+
if (!comparableTypes.includes(type)) {
|
|
53
|
+
// eslint-disable-next-line eqeqeq
|
|
54
|
+
return a == b;
|
|
55
|
+
}
|
|
56
|
+
return compareAs(type, a) === compareAs(type, b);
|
|
57
|
+
};
|
|
58
|
+
exports.sameValue = sameValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.sameValue=exports.compareAs=void 0,require("core-js/modules/es.array.includes.js");const compareAs=(e,r)=>{if(null==r)return r;switch(e){case"string":return"object"==typeof r?r:String(r);case"int":{const e=Number(r);return Number.isNaN(e)?r:e}case"boolean":return"true"===r||"false"!==r&&r;default:return r}};exports.compareAs=compareAs;const comparableTypes=["string","int","boolean"],sameValue=(e,r,s)=>comparableTypes.includes(e)?compareAs(e,r)===compareAs(e,s):r==s;exports.sameValue=sameValue;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { recordDefinition } from '../introspect/definitions/record';
|
|
2
|
+
import { keyDefinition } from '../introspect/definitions/key';
|
|
3
|
+
/**
|
|
4
|
+
* The declared type of one of a record's fields, or undefined when the record or field is unknown.
|
|
5
|
+
* @param record
|
|
6
|
+
* @param property
|
|
7
|
+
*/
|
|
8
|
+
export declare const fieldType: (record: recordDefinition | undefined, property: string) => string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The declared type of the value a key indexes: its field's type for a single-field key. A
|
|
11
|
+
* multi-field key's value is a composite (see computeKeyValue), so it has no single declared type.
|
|
12
|
+
* @param record
|
|
13
|
+
* @param key
|
|
14
|
+
*/
|
|
15
|
+
export declare const keyValueType: (record: recordDefinition | undefined, key: keyDefinition) => string | undefined;
|
|
16
|
+
//# sourceMappingURL=fieldType.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keyValueType = exports.fieldType = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.find.js");
|
|
9
|
+
/**
|
|
10
|
+
* The declared type of one of a record's fields, or undefined when the record or field is unknown.
|
|
11
|
+
* @param record
|
|
12
|
+
* @param property
|
|
13
|
+
*/
|
|
14
|
+
const fieldType = (record, property) => record?.definition?.find(field => field.name === property)?.type;
|
|
15
|
+
/**
|
|
16
|
+
* The declared type of the value a key indexes: its field's type for a single-field key. A
|
|
17
|
+
* multi-field key's value is a composite (see computeKeyValue), so it has no single declared type.
|
|
18
|
+
* @param record
|
|
19
|
+
* @param key
|
|
20
|
+
*/
|
|
21
|
+
exports.fieldType = fieldType;
|
|
22
|
+
const keyValueType = (record, key) => key.fields.length === 1 ? fieldType(record, key.fields[0]) : undefined;
|
|
23
|
+
exports.keyValueType = keyValueType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.keyValueType=exports.fieldType=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.find.js");const fieldType=(e,t)=>e?.definition?.find((e=>e.name===t))?.type;exports.fieldType=fieldType;const keyValueType=(e,t)=>1===t.fields.length?fieldType(e,t.fields[0]):void 0;exports.keyValueType=keyValueType;
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getConditionIndexedList = void 0;
|
|
7
|
-
var _isEntityProperty = require("./parsers/isEntityProperty");
|
|
8
|
-
var _splitEntityProperty = require("./parsers/splitEntityProperty");
|
|
9
|
-
var _retrieveRecord = require("./retrieveRecord");
|
|
10
|
-
var _where = require("../queries/where");
|
|
11
|
-
var _retrieveFile = require("./retrieveFile");
|
|
12
|
-
var _getMatchingIndexes = require("./getMatchingIndexes");
|
|
13
|
-
const getConditionIndexedList = async (parsed, recordData, dataSet) => {
|
|
14
|
-
const reducedConditions = [];
|
|
15
|
-
for (const condition of parsed.conditions) {
|
|
16
|
-
let entity = parsed.entity;
|
|
17
|
-
let property = condition.property;
|
|
18
|
-
if ((0, _isEntityProperty.isEntityProperty)(property)) {
|
|
19
|
-
const entityProperty = (0, _splitEntityProperty.splitEntityProperty)(property);
|
|
20
|
-
entity = entityProperty.entity;
|
|
21
|
-
property = entityProperty.property;
|
|
22
|
-
}
|
|
23
|
-
if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
|
|
24
|
-
recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
|
|
25
|
-
}
|
|
26
|
-
const indexed = {};
|
|
27
|
-
const retrieveMatchedFiles = async (entity, property, recordData, condition, dataSet, indexed) => {
|
|
28
|
-
const matchedRecords = (0, _where.where)(indexed[entity][property], {
|
|
29
|
-
property: 'value',
|
|
30
|
-
comparator: condition.comparator,
|
|
31
|
-
value: condition.value
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getConditionIndexedList = void 0;
|
|
7
|
+
var _isEntityProperty = require("./parsers/isEntityProperty");
|
|
8
|
+
var _splitEntityProperty = require("./parsers/splitEntityProperty");
|
|
9
|
+
var _retrieveRecord = require("./retrieveRecord");
|
|
10
|
+
var _where = require("../queries/where");
|
|
11
|
+
var _retrieveFile = require("./retrieveFile");
|
|
12
|
+
var _getMatchingIndexes = require("./getMatchingIndexes");
|
|
13
|
+
const getConditionIndexedList = async (parsed, recordData, dataSet) => {
|
|
14
|
+
const reducedConditions = [];
|
|
15
|
+
for (const condition of parsed.conditions) {
|
|
16
|
+
let entity = parsed.entity;
|
|
17
|
+
let property = condition.property;
|
|
18
|
+
if ((0, _isEntityProperty.isEntityProperty)(property)) {
|
|
19
|
+
const entityProperty = (0, _splitEntityProperty.splitEntityProperty)(property);
|
|
20
|
+
entity = entityProperty.entity;
|
|
21
|
+
property = entityProperty.property;
|
|
22
|
+
}
|
|
23
|
+
if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
|
|
24
|
+
recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
|
|
25
|
+
}
|
|
26
|
+
const indexed = {};
|
|
27
|
+
const retrieveMatchedFiles = async (entity, property, recordData, condition, dataSet, indexed) => {
|
|
28
|
+
const matchedRecords = (0, _where.where)(indexed[entity][property], {
|
|
29
|
+
property: 'value',
|
|
30
|
+
comparator: condition.comparator,
|
|
31
|
+
value: condition.value,
|
|
32
|
+
type: condition.type
|
|
33
|
+
});
|
|
34
|
+
for (const matchedRecord of matchedRecords) {
|
|
35
|
+
for (const file of matchedRecord.record) {
|
|
36
|
+
dataSet[entity].push(await (0, _retrieveFile.retrieveFile)(`${entity}/${file}`));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const isIndexed = await (0, _getMatchingIndexes.getMatchingIndexes)(entity, property, recordData, condition, dataSet, indexed, retrieveMatchedFiles);
|
|
41
|
+
if (!isIndexed) {
|
|
42
|
+
reducedConditions.push(condition);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
parsed.conditions = reducedConditions;
|
|
46
|
+
return parsed;
|
|
47
|
+
};
|
|
47
48
|
exports.getConditionIndexedList = getConditionIndexedList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getConditionIndexedList=void 0;var _isEntityProperty=require("./parsers/isEntityProperty"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_retrieveRecord=require("./retrieveRecord"),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_getMatchingIndexes=require("./getMatchingIndexes");const getConditionIndexedList=async(e,t,r)=>{const i=[];for(const o of e.conditions){let n=e.entity,s=o.property;if((0,_isEntityProperty.isEntityProperty)(s)){const e=(0,_splitEntityProperty.splitEntityProperty)(s);n=e.entity,s=e.property}Object.prototype.hasOwnProperty.call(t,n)||(t[n]=await(0,_retrieveRecord.retrieveRecord)(n));const p={},
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getConditionIndexedList=void 0;var _isEntityProperty=require("./parsers/isEntityProperty"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_retrieveRecord=require("./retrieveRecord"),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_getMatchingIndexes=require("./getMatchingIndexes");const getConditionIndexedList=async(e,t,r)=>{const i=[];for(const o of e.conditions){let n=e.entity,s=o.property;if((0,_isEntityProperty.isEntityProperty)(s)){const e=(0,_splitEntityProperty.splitEntityProperty)(s);n=e.entity,s=e.property}Object.prototype.hasOwnProperty.call(t,n)||(t[n]=await(0,_retrieveRecord.retrieveRecord)(n));const p={},y=async(e,t,r,i,o,n)=>{const s=(0,_where.where)(n[e][t],{property:"value",comparator:i.comparator,value:i.value,type:i.type});for(const t of s)for(const r of t.record)o[e].push(await(0,_retrieveFile.retrieveFile)(`${e}/${r}`))};await(0,_getMatchingIndexes.getMatchingIndexes)(n,s,t,o,r,p,y)||i.push(o)}return e.conditions=i,e};exports.getConditionIndexedList=getConditionIndexedList;
|
|
@@ -1,61 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.matchIndexedJoins = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.reduce.js");
|
|
9
|
-
var _siFunciona = _interopRequireDefault(require("si-funciona"));
|
|
10
|
-
var _where = require("../queries/where");
|
|
11
|
-
var _retrieveFile = require("./retrieveFile");
|
|
12
|
-
var _splitEntityProperty = require("./parsers/splitEntityProperty");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.matchIndexedJoins = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.reduce.js");
|
|
9
|
+
var _siFunciona = _interopRequireDefault(require("si-funciona"));
|
|
10
|
+
var _where = require("../queries/where");
|
|
11
|
+
var _retrieveFile = require("./retrieveFile");
|
|
12
|
+
var _splitEntityProperty = require("./parsers/splitEntityProperty");
|
|
13
|
+
var _fieldType = require("./fieldType");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity, property, recordData, joinClause, filterJoins, indexed) => {
|
|
16
|
+
const {
|
|
17
|
+
entity: entityA,
|
|
18
|
+
property: propertyA
|
|
19
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
|
|
20
|
+
const {
|
|
21
|
+
entity: entityB,
|
|
22
|
+
property: propertyB
|
|
23
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
|
|
24
|
+
const properties = [{
|
|
25
|
+
entityFirst: entityA,
|
|
26
|
+
propertyFirst: propertyA,
|
|
27
|
+
entitySecond: entityB,
|
|
28
|
+
propertySecond: propertyB
|
|
29
|
+
}, {
|
|
30
|
+
entityFirst: entityB,
|
|
31
|
+
propertyFirst: propertyB,
|
|
32
|
+
entitySecond: entityA,
|
|
33
|
+
propertySecond: propertyA
|
|
34
|
+
}];
|
|
35
|
+
for (const checkProp of properties) {
|
|
36
|
+
if (!Object.prototype.hasOwnProperty.call(indexedClone, checkProp.entitySecond)) {
|
|
37
|
+
indexedClone[checkProp.entitySecond] = _siFunciona.default.cloneObject(indexed[checkProp.entitySecond]);
|
|
38
|
+
}
|
|
39
|
+
const matchedRecords = indexedClone[checkProp.entitySecond][checkProp.propertySecond].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(indexedClone[checkProp.entityFirst][checkProp.propertyFirst], {
|
|
40
|
+
property: 'value',
|
|
41
|
+
comparator: joinClause.comparator,
|
|
42
|
+
value: dataB.value,
|
|
43
|
+
type: (0, _fieldType.fieldType)(recordData[checkProp.entityFirst], checkProp.propertyFirst)
|
|
44
|
+
})), []);
|
|
45
|
+
const skipPush = checkProp.entityFirst === entity;
|
|
46
|
+
if (!Object.prototype.hasOwnProperty.call(dataSets, checkProp.entityFirst)) {
|
|
47
|
+
dataSets[checkProp.entityFirst] = [];
|
|
48
|
+
}
|
|
49
|
+
for (const matchedRecord of matchedRecords) {
|
|
50
|
+
for (const file of matchedRecord.record) {
|
|
51
|
+
let entityRecord = file;
|
|
52
|
+
if (typeof file === 'string') {
|
|
53
|
+
entityRecord = await (0, _retrieveFile.retrieveFile)(`${checkProp.entityFirst}/${file}`);
|
|
54
|
+
}
|
|
55
|
+
if (!skipPush) {
|
|
56
|
+
dataSets[checkProp.entityFirst].push(entityRecord);
|
|
57
|
+
}
|
|
58
|
+
filterJoins[checkProp.entityFirst].push(entityRecord);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
61
63
|
exports.matchIndexedJoins = matchIndexedJoins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchIndexedJoins=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _siFunciona=_interopRequireDefault(require("si-funciona")),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_splitEntityProperty=require("./parsers/splitEntityProperty");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const matchIndexedJoins=(e,t,r)=>async(i,o,n,s,p,y)=>{const{entity:c,property:u}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyA),{entity:a,property:d}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyB),l=[{entityFirst:c,propertyFirst:u,entitySecond:a,propertySecond:d},{entityFirst:a,propertyFirst:d,entitySecond:c,propertySecond:u}];for(const i of l){Object.prototype.hasOwnProperty.call(t,i.entitySecond)||(t[i.entitySecond]=_siFunciona.default.cloneObject(y[i.entitySecond]));const o=t[i.entitySecond][i.propertySecond].reduce(((e,r)=>_siFunciona.default.mergeArrays(e,(0,_where.where)(t[i.entityFirst][i.propertyFirst],{property:"value",comparator:s.comparator,value:r.value}))),[]),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.matchIndexedJoins=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _siFunciona=_interopRequireDefault(require("si-funciona")),_where=require("../queries/where"),_retrieveFile=require("./retrieveFile"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_fieldType=require("./fieldType");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const matchIndexedJoins=(e,t,r)=>async(i,o,n,s,p,y)=>{const{entity:c,property:u}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyA),{entity:a,property:d}=(0,_splitEntityProperty.splitEntityProperty)(s.propertyB),l=[{entityFirst:c,propertyFirst:u,entitySecond:a,propertySecond:d},{entityFirst:a,propertyFirst:d,entitySecond:c,propertySecond:u}];for(const i of l){Object.prototype.hasOwnProperty.call(t,i.entitySecond)||(t[i.entitySecond]=_siFunciona.default.cloneObject(y[i.entitySecond]));const o=t[i.entitySecond][i.propertySecond].reduce(((e,r)=>_siFunciona.default.mergeArrays(e,(0,_where.where)(t[i.entityFirst][i.propertyFirst],{property:"value",comparator:s.comparator,value:r.value,type:(0,_fieldType.fieldType)(n[i.entityFirst],i.propertyFirst)}))),[]),c=i.entityFirst===e;Object.prototype.hasOwnProperty.call(r,i.entityFirst)||(r[i.entityFirst]=[]);for(const e of o)for(const t of e.record){let e=t;"string"==typeof t&&(e=await(0,_retrieveFile.retrieveFile)(`${i.entityFirst}/${t}`)),c||r[i.entityFirst].push(e),p[i.entityFirst].push(e)}}};exports.matchIndexedJoins=matchIndexedJoins;
|
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.mergeJoin = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
-
var _readEntity = require("../queries/readEntity");
|
|
10
|
-
var _splitEntityProperty = require("./parsers/splitEntityProperty");
|
|
11
|
-
var _where = require("../queries/where");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
dataSets
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mergeJoin = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
+
var _readEntity = require("../queries/readEntity");
|
|
10
|
+
var _splitEntityProperty = require("./parsers/splitEntityProperty");
|
|
11
|
+
var _where = require("../queries/where");
|
|
12
|
+
var _retrieveRecord = require("./retrieveRecord");
|
|
13
|
+
var _fieldType = require("./fieldType");
|
|
14
|
+
const mergeJoin = async (propertyA = '', propertyB = '', dataSets = {}) => {
|
|
15
|
+
const {
|
|
16
|
+
entity: entityA,
|
|
17
|
+
property: propA
|
|
18
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(propertyA);
|
|
19
|
+
const {
|
|
20
|
+
entity: entityB,
|
|
21
|
+
property: propB
|
|
22
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(propertyB);
|
|
23
|
+
dataSets = await (0, _readEntity.readEntity)(entityA, dataSets);
|
|
24
|
+
dataSets = await (0, _readEntity.readEntity)(entityB, dataSets);
|
|
25
|
+
const typeB = (0, _fieldType.fieldType)(await (0, _retrieveRecord.retrieveRecord)(entityB), propB);
|
|
26
|
+
dataSets[entityA] = dataSets[entityA].map(dataA => {
|
|
27
|
+
const matches = (0, _where.where)(dataSets[entityB], {
|
|
28
|
+
property: propB,
|
|
29
|
+
comparator: '=',
|
|
30
|
+
value: dataA[propA],
|
|
31
|
+
type: typeB
|
|
32
|
+
});
|
|
33
|
+
if (!matches.length) {
|
|
34
|
+
return dataA;
|
|
35
|
+
}
|
|
36
|
+
const mergeMatch = matches[0];
|
|
37
|
+
for (const prop in mergeMatch) {
|
|
38
|
+
if (prop === propB) {
|
|
39
|
+
// Skip the condition property since it is irrelevant
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
dataA[`${entityB}.${prop}`] = mergeMatch[prop];
|
|
43
|
+
}
|
|
44
|
+
return dataA;
|
|
45
|
+
});
|
|
46
|
+
return dataSets;
|
|
47
|
+
};
|
|
44
48
|
exports.mergeJoin = mergeJoin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeJoin=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _readEntity=require("../queries/readEntity"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_where=require("../queries/where");const mergeJoin=async(e="",r="",t={})=>{const{entity:i,property:o}=(0,_splitEntityProperty.splitEntityProperty)(e),{entity:n,property:s}=(0,_splitEntityProperty.splitEntityProperty)(r);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeJoin=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _readEntity=require("../queries/readEntity"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_where=require("../queries/where"),_retrieveRecord=require("./retrieveRecord"),_fieldType=require("./fieldType");const mergeJoin=async(e="",r="",t={})=>{const{entity:i,property:o}=(0,_splitEntityProperty.splitEntityProperty)(e),{entity:n,property:s}=(0,_splitEntityProperty.splitEntityProperty)(r);t=await(0,_readEntity.readEntity)(i,t),t=await(0,_readEntity.readEntity)(n,t);const p=(0,_fieldType.fieldType)(await(0,_retrieveRecord.retrieveRecord)(n),s);return t[i]=t[i].map((e=>{const r=(0,_where.where)(t[n],{property:s,comparator:"=",value:e[o],type:p});if(!r.length)return e;const i=r[0];for(const r in i)r!==s&&(e[`${n}.${r}`]=i[r]);return e})),t};exports.mergeJoin=mergeJoin;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { LiteralValue } from './parseLiteralValue';
|
|
2
|
-
import { ParsedQuery } from './parseQuery';
|
|
3
|
-
export type ConditionValue = LiteralValue;
|
|
4
|
-
export type ParsedCondition = {
|
|
5
|
-
property: string;
|
|
6
|
-
comparator: string;
|
|
7
|
-
value: ConditionValue;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { LiteralValue } from './parseLiteralValue';
|
|
2
|
+
import { ParsedQuery } from './parseQuery';
|
|
3
|
+
export type ConditionValue = LiteralValue;
|
|
4
|
+
export type ParsedCondition = {
|
|
5
|
+
property: string;
|
|
6
|
+
comparator: string;
|
|
7
|
+
value: ConditionValue;
|
|
8
|
+
type?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Extract condition clauses from the query.
|
|
12
|
+
* @param parsed
|
|
13
|
+
* @param query
|
|
14
|
+
*/
|
|
15
|
+
export declare const findConditions: (parsed: ParsedQuery, query: string) => string;
|
|
15
16
|
//# sourceMappingURL=findConditions.d.ts.map
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { keyDefinition } from '../introspect/definitions/key';
|
|
2
|
-
import { recordPath } from '../introspect/definitions/record';
|
|
3
|
-
import { indexEntry } from './updateIndex';
|
|
4
|
-
/**
|
|
5
|
-
* Remove a single entry file from the index that backs one of a record's keys, dropping a value
|
|
6
|
-
* entirely once its last file is removed. A key with no lookup, or an index file that doesn't
|
|
7
|
-
* exist yet, is left untouched.
|
|
8
|
-
* @param path
|
|
9
|
-
* @param key
|
|
10
|
-
* @param value
|
|
11
|
-
* @param fileName
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { keyDefinition } from '../introspect/definitions/key';
|
|
2
|
+
import { recordPath } from '../introspect/definitions/record';
|
|
3
|
+
import { indexEntry } from './updateIndex';
|
|
4
|
+
/**
|
|
5
|
+
* Remove a single entry file from the index that backs one of a record's keys, dropping a value
|
|
6
|
+
* entirely once its last file is removed. A key with no lookup, or an index file that doesn't
|
|
7
|
+
* exist yet, is left untouched.
|
|
8
|
+
* @param path
|
|
9
|
+
* @param key
|
|
10
|
+
* @param value
|
|
11
|
+
* @param fileName
|
|
12
|
+
* @param type - The declared type of the indexed value (see keyValueType), so '3' and 3 are one entry.
|
|
13
|
+
*/
|
|
14
|
+
export declare const removeFromIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string, type?: string) => Promise<indexEntry[] | null>;
|
|
14
15
|
//# sourceMappingURL=removeFromIndex.d.ts.map
|
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.removeFromIndex = 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.filter.js");
|
|
10
|
-
require("core-js/modules/esnext.iterator.map.js");
|
|
11
|
-
var _config = require("./config");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeFromIndex = 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.filter.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
11
|
+
var _config = require("./config");
|
|
12
|
+
var _compareAs = require("./compareAs");
|
|
13
|
+
const {
|
|
14
|
+
readFile,
|
|
15
|
+
writeFile
|
|
16
|
+
} = require('fs/promises');
|
|
17
|
+
/**
|
|
18
|
+
* Remove a single entry file from the index that backs one of a record's keys, dropping a value
|
|
19
|
+
* entirely once its last file is removed. A key with no lookup, or an index file that doesn't
|
|
20
|
+
* exist yet, is left untouched.
|
|
21
|
+
* @param path
|
|
22
|
+
* @param key
|
|
23
|
+
* @param value
|
|
24
|
+
* @param fileName
|
|
25
|
+
* @param type - The declared type of the indexed value (see keyValueType), so '3' and 3 are one entry.
|
|
26
|
+
*/
|
|
27
|
+
const removeFromIndex = async (path = '', key = null, value = undefined, fileName = '', type = undefined) => {
|
|
28
|
+
if (!key || !key.lookup) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const databasePath = (0, _config.getSetting)('databasePath', 'database/');
|
|
32
|
+
const indexPath = `${databasePath}__indexes/${path}/${key.lookup}`;
|
|
33
|
+
let index = [];
|
|
34
|
+
try {
|
|
35
|
+
index = JSON.parse(await readFile(indexPath, 'utf8'));
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
index = index.map(entry => (0, _compareAs.sameValue)(type, entry.value, value) ? {
|
|
40
|
+
value: entry.value,
|
|
41
|
+
record: entry.record.filter(record => record !== fileName)
|
|
42
|
+
} : entry).filter(entry => entry.record.length);
|
|
43
|
+
await writeFile(indexPath, JSON.stringify(index, null, 2));
|
|
44
|
+
return index;
|
|
45
|
+
};
|
|
44
46
|
exports.removeFromIndex = removeFromIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeFromIndex=void 0,require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js"),require("core-js/modules/esnext.iterator.map.js");var _config=require("./config");const{readFile:readFile,writeFile:writeFile}=require("fs/promises"),removeFromIndex=async(e="",r=null,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeFromIndex=void 0,require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js"),require("core-js/modules/esnext.iterator.map.js");var _config=require("./config"),_compareAs=require("./compareAs");const{readFile:readFile,writeFile:writeFile}=require("fs/promises"),removeFromIndex=async(e="",r=null,o=void 0,t="",i=void 0)=>{if(!r||!r.lookup)return null;const s=`${(0,_config.getSetting)("databasePath","database/")}__indexes/${e}/${r.lookup}`;let a=[];try{a=JSON.parse(await readFile(s,"utf8"))}catch(e){return null}return a=a.map((e=>(0,_compareAs.sameValue)(i,e.value,o)?{value:e.value,record:e.record.filter((e=>e!==t))}:e)).filter((e=>e.record.length)),await writeFile(s,JSON.stringify(a,null,2)),a};exports.removeFromIndex=removeFromIndex;
|