json-fs-query 0.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/.browserslistrc +1 -0
- package/.nvmrc +1 -0
- package/LICENSE +674 -0
- package/MAIN.md +15 -0
- package/README.md +63 -0
- package/babel.config.js +3 -0
- package/build-tools.config.json +30 -0
- package/dist/data/introspect/create.d.ts +11 -0
- package/dist/data/introspect/create.js +45 -0
- package/dist/data/introspect/create.min.js +1 -0
- package/dist/data/introspect/definitions/field.d.ts +28 -0
- package/dist/data/introspect/definitions/field.js +36 -0
- package/dist/data/introspect/definitions/field.min.js +1 -0
- package/dist/data/introspect/definitions/key.d.ts +26 -0
- package/dist/data/introspect/definitions/key.js +53 -0
- package/dist/data/introspect/definitions/key.min.js +1 -0
- package/dist/data/introspect/definitions/keyReference.d.ts +18 -0
- package/dist/data/introspect/definitions/keyReference.js +20 -0
- package/dist/data/introspect/definitions/keyReference.min.js +1 -0
- package/dist/data/introspect/definitions/record.d.ts +26 -0
- package/dist/data/introspect/definitions/record.js +32 -0
- package/dist/data/introspect/definitions/record.min.js +1 -0
- package/dist/data/introspect/describe.d.ts +2 -0
- package/dist/data/introspect/describe.js +15 -0
- package/dist/data/introspect/describe.min.js +1 -0
- package/dist/data/introspect/drop.d.ts +2 -0
- package/dist/data/introspect/drop.js +37 -0
- package/dist/data/introspect/drop.min.js +1 -0
- package/dist/data/introspect/index.d.ts +8 -0
- package/dist/data/introspect/index.js +30 -0
- package/dist/data/introspect/index.min.js +1 -0
- package/dist/data/introspect/policies/foreignKeyExists.d.ts +9 -0
- package/dist/data/introspect/policies/foreignKeyExists.js +25 -0
- package/dist/data/introspect/policies/foreignKeyExists.min.js +1 -0
- package/dist/data/introspect/policies/keyGenerate.d.ts +2 -0
- package/dist/data/introspect/policies/keyGenerate.js +17 -0
- package/dist/data/introspect/policies/keyGenerate.min.js +1 -0
- package/dist/data/introspect/policies/keyUnique.d.ts +2 -0
- package/dist/data/introspect/policies/keyUnique.js +21 -0
- package/dist/data/introspect/policies/keyUnique.min.js +1 -0
- package/dist/data/introspect/policies/typeCheck.d.ts +12 -0
- package/dist/data/introspect/policies/typeCheck.js +57 -0
- package/dist/data/introspect/policies/typeCheck.min.js +1 -0
- package/dist/data/introspect/policies/typeEnum.d.ts +2 -0
- package/dist/data/introspect/policies/typeEnum.js +14 -0
- package/dist/data/introspect/policies/typeEnum.min.js +1 -0
- package/dist/data/introspect/policies/useDefault.d.ts +2 -0
- package/dist/data/introspect/policies/useDefault.js +13 -0
- package/dist/data/introspect/policies/useDefault.min.js +1 -0
- package/dist/data/queries/deleteEntity.d.ts +2 -0
- package/dist/data/queries/deleteEntity.js +79 -0
- package/dist/data/queries/deleteEntity.min.js +1 -0
- package/dist/data/queries/groupBy.d.ts +2 -0
- package/dist/data/queries/groupBy.js +22 -0
- package/dist/data/queries/groupBy.min.js +1 -0
- package/dist/data/queries/insertEntity.d.ts +2 -0
- package/dist/data/queries/insertEntity.js +115 -0
- package/dist/data/queries/insertEntity.min.js +1 -0
- package/dist/data/queries/joinEntity.d.ts +2 -0
- package/dist/data/queries/joinEntity.js +27 -0
- package/dist/data/queries/joinEntity.min.js +1 -0
- package/dist/data/queries/mergeJoins.d.ts +2 -0
- package/dist/data/queries/mergeJoins.js +19 -0
- package/dist/data/queries/mergeJoins.min.js +1 -0
- package/dist/data/queries/parser.d.ts +2 -0
- package/dist/data/queries/parser.js +30 -0
- package/dist/data/queries/parser.min.js +1 -0
- package/dist/data/queries/query.d.ts +2 -0
- package/dist/data/queries/query.js +18 -0
- package/dist/data/queries/query.min.js +1 -0
- package/dist/data/queries/readEntity.d.ts +2 -0
- package/dist/data/queries/readEntity.js +14 -0
- package/dist/data/queries/readEntity.min.js +1 -0
- package/dist/data/queries/sortBy.d.ts +2 -0
- package/dist/data/queries/sortBy.js +25 -0
- package/dist/data/queries/sortBy.min.js +1 -0
- package/dist/data/queries/updateEntity.d.ts +2 -0
- package/dist/data/queries/updateEntity.js +164 -0
- package/dist/data/queries/updateEntity.min.js +1 -0
- package/dist/data/queries/where.d.ts +7 -0
- package/dist/data/queries/where.js +56 -0
- package/dist/data/queries/where.min.js +1 -0
- package/dist/data/utilities/deregisterRecord.d.ts +8 -0
- package/dist/data/utilities/deregisterRecord.js +34 -0
- package/dist/data/utilities/deregisterRecord.min.js +1 -0
- package/dist/data/utilities/getConditionIndexedList.d.ts +3 -0
- package/dist/data/utilities/getConditionIndexedList.js +47 -0
- package/dist/data/utilities/getConditionIndexedList.min.js +1 -0
- package/dist/data/utilities/getJoinIndexedList.d.ts +3 -0
- package/dist/data/utilities/getJoinIndexedList.js +59 -0
- package/dist/data/utilities/getJoinIndexedList.min.js +1 -0
- package/dist/data/utilities/getMatchingIndexes.d.ts +2 -0
- package/dist/data/utilities/getMatchingIndexes.js +28 -0
- package/dist/data/utilities/getMatchingIndexes.min.js +1 -0
- package/dist/data/utilities/matchIndexedJoins.d.ts +2 -0
- package/dist/data/utilities/matchIndexedJoins.js +61 -0
- package/dist/data/utilities/matchIndexedJoins.min.js +1 -0
- package/dist/data/utilities/mergeJoin.d.ts +2 -0
- package/dist/data/utilities/mergeJoin.js +44 -0
- package/dist/data/utilities/mergeJoin.min.js +1 -0
- package/dist/data/utilities/parsers/findCommand.d.ts +10 -0
- package/dist/data/utilities/parsers/findCommand.js +25 -0
- package/dist/data/utilities/parsers/findCommand.min.js +1 -0
- package/dist/data/utilities/parsers/findConditions.d.ts +15 -0
- package/dist/data/utilities/parsers/findConditions.js +28 -0
- package/dist/data/utilities/parsers/findConditions.min.js +1 -0
- package/dist/data/utilities/parsers/findGroupBy.d.ts +9 -0
- package/dist/data/utilities/parsers/findGroupBy.js +22 -0
- package/dist/data/utilities/parsers/findGroupBy.min.js +1 -0
- package/dist/data/utilities/parsers/findInsertValues.d.ts +13 -0
- package/dist/data/utilities/parsers/findInsertValues.js +34 -0
- package/dist/data/utilities/parsers/findInsertValues.min.js +1 -0
- package/dist/data/utilities/parsers/findJoinClauses.d.ts +13 -0
- package/dist/data/utilities/parsers/findJoinClauses.js +27 -0
- package/dist/data/utilities/parsers/findJoinClauses.min.js +1 -0
- package/dist/data/utilities/parsers/findJoinEntity.d.ts +9 -0
- package/dist/data/utilities/parsers/findJoinEntity.js +22 -0
- package/dist/data/utilities/parsers/findJoinEntity.min.js +1 -0
- package/dist/data/utilities/parsers/findLimit.d.ts +9 -0
- package/dist/data/utilities/parsers/findLimit.js +22 -0
- package/dist/data/utilities/parsers/findLimit.min.js +1 -0
- package/dist/data/utilities/parsers/findMergeJoins.d.ts +12 -0
- package/dist/data/utilities/parsers/findMergeJoins.js +26 -0
- package/dist/data/utilities/parsers/findMergeJoins.min.js +1 -0
- package/dist/data/utilities/parsers/findOffset.d.ts +9 -0
- package/dist/data/utilities/parsers/findOffset.js +22 -0
- package/dist/data/utilities/parsers/findOffset.min.js +1 -0
- package/dist/data/utilities/parsers/findSelects.d.ts +12 -0
- package/dist/data/utilities/parsers/findSelects.js +30 -0
- package/dist/data/utilities/parsers/findSelects.min.js +1 -0
- package/dist/data/utilities/parsers/findSortClauses.d.ts +12 -0
- package/dist/data/utilities/parsers/findSortClauses.js +30 -0
- package/dist/data/utilities/parsers/findSortClauses.min.js +1 -0
- package/dist/data/utilities/parsers/findUpdateValues.d.ts +15 -0
- package/dist/data/utilities/parsers/findUpdateValues.js +34 -0
- package/dist/data/utilities/parsers/findUpdateValues.min.js +1 -0
- package/dist/data/utilities/parsers/isEntityProperty.d.ts +2 -0
- package/dist/data/utilities/parsers/isEntityProperty.js +8 -0
- package/dist/data/utilities/parsers/isEntityProperty.min.js +1 -0
- package/dist/data/utilities/parsers/parseLiteralValue.d.ts +12 -0
- package/dist/data/utilities/parsers/parseLiteralValue.js +34 -0
- package/dist/data/utilities/parsers/parseLiteralValue.min.js +1 -0
- package/dist/data/utilities/parsers/parseQuery.d.ts +33 -0
- package/dist/data/utilities/parsers/parseQuery.js +51 -0
- package/dist/data/utilities/parsers/parseQuery.min.js +1 -0
- package/dist/data/utilities/parsers/removeFromQuery.d.ts +2 -0
- package/dist/data/utilities/parsers/removeFromQuery.js +8 -0
- package/dist/data/utilities/parsers/removeFromQuery.min.js +1 -0
- package/dist/data/utilities/parsers/splitEntityProperty.d.ts +5 -0
- package/dist/data/utilities/parsers/splitEntityProperty.js +23 -0
- package/dist/data/utilities/parsers/splitEntityProperty.min.js +1 -0
- package/dist/data/utilities/parsers/splitQueries.d.ts +2 -0
- package/dist/data/utilities/parsers/splitQueries.js +11 -0
- package/dist/data/utilities/parsers/splitQueries.min.js +1 -0
- package/dist/data/utilities/reconcileJoin.d.ts +2 -0
- package/dist/data/utilities/reconcileJoin.js +26 -0
- package/dist/data/utilities/reconcileJoin.min.js +1 -0
- package/dist/data/utilities/reconcileJoins.d.ts +2 -0
- package/dist/data/utilities/reconcileJoins.js +27 -0
- package/dist/data/utilities/reconcileJoins.min.js +1 -0
- package/dist/data/utilities/registerRecord.d.ts +8 -0
- package/dist/data/utilities/registerRecord.js +67 -0
- package/dist/data/utilities/registerRecord.min.js +1 -0
- package/dist/data/utilities/removeFromIndex.d.ts +14 -0
- package/dist/data/utilities/removeFromIndex.js +46 -0
- package/dist/data/utilities/removeFromIndex.min.js +1 -0
- package/dist/data/utilities/restrictIndexedList.d.ts +2 -0
- package/dist/data/utilities/restrictIndexedList.js +45 -0
- package/dist/data/utilities/restrictIndexedList.min.js +1 -0
- package/dist/data/utilities/retrieveFile.d.ts +2 -0
- package/dist/data/utilities/retrieveFile.js +28 -0
- package/dist/data/utilities/retrieveFile.min.js +1 -0
- package/dist/data/utilities/retrieveIndexes.d.ts +2 -0
- package/dist/data/utilities/retrieveIndexes.js +24 -0
- package/dist/data/utilities/retrieveIndexes.min.js +1 -0
- package/dist/data/utilities/retrieveRecord.d.ts +2 -0
- package/dist/data/utilities/retrieveRecord.js +9 -0
- package/dist/data/utilities/retrieveRecord.min.js +1 -0
- package/dist/data/utilities/retrieveRecords.d.ts +2 -0
- package/dist/data/utilities/retrieveRecords.js +21 -0
- package/dist/data/utilities/retrieveRecords.min.js +1 -0
- package/dist/data/utilities/runQuery.d.ts +2 -0
- package/dist/data/utilities/runQuery.js +72 -0
- package/dist/data/utilities/runQuery.min.js +1 -0
- package/dist/data/utilities/updateIndex.d.ts +17 -0
- package/dist/data/utilities/updateIndex.js +56 -0
- package/dist/data/utilities/updateIndex.min.js +1 -0
- package/dist/data/utilities/useJoinClause.d.ts +6 -0
- package/dist/data/utilities/useJoinClause.js +51 -0
- package/dist/data/utilities/useJoinClause.min.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +35 -0
- package/dist/index.min.js +1 -0
- package/gulpfile.mjs +15 -0
- package/package.json +44 -0
- package/src/data/introspect/create.test.js +67 -0
- package/src/data/introspect/create.ts +29 -0
- package/src/data/introspect/definitions/field.test.js +23 -0
- package/src/data/introspect/definitions/field.ts +48 -0
- package/src/data/introspect/definitions/key.test.js +100 -0
- package/src/data/introspect/definitions/key.ts +64 -0
- package/src/data/introspect/definitions/keyReference.test.js +8 -0
- package/src/data/introspect/definitions/keyReference.ts +23 -0
- package/src/data/introspect/definitions/record.ts +42 -0
- package/src/data/introspect/describe.test.js +36 -0
- package/src/data/introspect/describe.ts +9 -0
- package/src/data/introspect/drop.test.js +77 -0
- package/src/data/introspect/drop.ts +20 -0
- package/src/data/introspect/index.ts +8 -0
- package/src/data/introspect/policies/foreignKeyExists.test.js +44 -0
- package/src/data/introspect/policies/foreignKeyExists.ts +15 -0
- package/src/data/introspect/policies/keyGenerate.ts +11 -0
- package/src/data/introspect/policies/keyUnique.ts +11 -0
- package/src/data/introspect/policies/typeCheck.test.js +84 -0
- package/src/data/introspect/policies/typeCheck.ts +49 -0
- package/src/data/introspect/policies/typeEnum.ts +6 -0
- package/src/data/introspect/policies/useDefault.ts +6 -0
- package/src/data/queries/deleteEntity.test.js +86 -0
- package/src/data/queries/deleteEntity.ts +56 -0
- package/src/data/queries/groupBy.test.js +135 -0
- package/src/data/queries/groupBy.ts +16 -0
- package/src/data/queries/insertEntity.test.js +156 -0
- package/src/data/queries/insertEntity.ts +113 -0
- package/src/data/queries/joinEntity.test.js +109 -0
- package/src/data/queries/joinEntity.ts +20 -0
- package/src/data/queries/mergeJoins.test.js +174 -0
- package/src/data/queries/mergeJoins.ts +13 -0
- package/src/data/queries/parser.test.js +343 -0
- package/src/data/queries/parser.ts +24 -0
- package/src/data/queries/query.test.js +233 -0
- package/src/data/queries/query.ts +12 -0
- package/src/data/queries/readEntity.test.js +85 -0
- package/src/data/queries/readEntity.ts +8 -0
- package/src/data/queries/sortBy.test.js +131 -0
- package/src/data/queries/sortBy.ts +18 -0
- package/src/data/queries/updateEntity.test.js +228 -0
- package/src/data/queries/updateEntity.ts +162 -0
- package/src/data/queries/where.test.js +129 -0
- package/src/data/queries/where.ts +54 -0
- package/src/data/utilities/deregisterRecord.test.js +26 -0
- package/src/data/utilities/deregisterRecord.ts +24 -0
- package/src/data/utilities/getConditionIndexedList.ts +43 -0
- package/src/data/utilities/getJoinIndexedList.ts +53 -0
- package/src/data/utilities/getMatchingIndexes.ts +21 -0
- package/src/data/utilities/matchIndexedJoins.ts +45 -0
- package/src/data/utilities/mergeJoin.test.js +102 -0
- package/src/data/utilities/mergeJoin.ts +28 -0
- package/src/data/utilities/parsers/findCommand.ts +25 -0
- package/src/data/utilities/parsers/findConditions.test.js +38 -0
- package/src/data/utilities/parsers/findConditions.ts +32 -0
- package/src/data/utilities/parsers/findGroupBy.ts +20 -0
- package/src/data/utilities/parsers/findInsertValues.test.js +26 -0
- package/src/data/utilities/parsers/findInsertValues.ts +32 -0
- package/src/data/utilities/parsers/findJoinClauses.ts +29 -0
- package/src/data/utilities/parsers/findJoinEntity.ts +20 -0
- package/src/data/utilities/parsers/findLimit.ts +20 -0
- package/src/data/utilities/parsers/findMergeJoins.ts +27 -0
- package/src/data/utilities/parsers/findOffset.ts +20 -0
- package/src/data/utilities/parsers/findSelects.ts +31 -0
- package/src/data/utilities/parsers/findSortClauses.ts +31 -0
- package/src/data/utilities/parsers/findUpdateValues.test.js +37 -0
- package/src/data/utilities/parsers/findUpdateValues.ts +32 -0
- package/src/data/utilities/parsers/isEntityProperty.ts +1 -0
- package/src/data/utilities/parsers/parseLiteralValue.test.js +41 -0
- package/src/data/utilities/parsers/parseLiteralValue.ts +29 -0
- package/src/data/utilities/parsers/parseQuery.ts +73 -0
- package/src/data/utilities/parsers/removeFromQuery.ts +1 -0
- package/src/data/utilities/parsers/splitEntityProperty.test.js +8 -0
- package/src/data/utilities/parsers/splitEntityProperty.ts +17 -0
- package/src/data/utilities/parsers/splitQueries.test.js +33 -0
- package/src/data/utilities/parsers/splitQueries.ts +4 -0
- package/src/data/utilities/reconcileJoin.test.js +38 -0
- package/src/data/utilities/reconcileJoin.ts +23 -0
- package/src/data/utilities/reconcileJoins.test.js +160 -0
- package/src/data/utilities/reconcileJoins.ts +15 -0
- package/src/data/utilities/registerRecord.test.js +44 -0
- package/src/data/utilities/registerRecord.ts +44 -0
- package/src/data/utilities/removeFromIndex.test.js +44 -0
- package/src/data/utilities/removeFromIndex.ts +34 -0
- package/src/data/utilities/restrictIndexedList.ts +38 -0
- package/src/data/utilities/retrieveFile.test.js +49 -0
- package/src/data/utilities/retrieveFile.ts +19 -0
- package/src/data/utilities/retrieveIndexes.ts +17 -0
- package/src/data/utilities/retrieveRecord.ts +3 -0
- package/src/data/utilities/retrieveRecords.test.js +223 -0
- package/src/data/utilities/retrieveRecords.ts +16 -0
- package/src/data/utilities/runQuery.test.js +88 -0
- package/src/data/utilities/runQuery.ts +75 -0
- package/src/data/utilities/updateIndex.test.js +44 -0
- package/src/data/utilities/updateIndex.ts +45 -0
- package/src/data/utilities/useJoinClause.test.js +94 -0
- package/src/data/utilities/useJoinClause.ts +44 -0
- package/src/global.d.ts +1 -0
- package/src/index.test.js +52 -0
- package/src/index.ts +17 -0
- package/test-data/__RECORDS.json +32 -0
- package/test-data/__indexes/exercise_muscle/fk_exercise_id.json +14 -0
- package/test-data/__indexes/exercise_muscle/fk_muscle_id.json +14 -0
- package/test-data/__indexes/exercise_muscle/pk__id.json +14 -0
- package/test-data/__indexes/exercises/pk__id.json +14 -0
- package/test-data/__indexes/muscles/pk__id.json +58 -0
- package/test-data/__indexes/workouts/fk_exercise_id.json +23 -0
- package/test-data/__indexes/workouts/index_date.json +18 -0
- package/test-data/__indexes/workouts/pk__id.json +26 -0
- package/test-data/copyDatabase.ts +64 -0
- package/test-data/exercise_muscle/bench_press_pectorals.json +6 -0
- package/test-data/exercise_muscle/deadlift_hamstrings.json +6 -0
- package/test-data/exercise_muscle/squat_quadriceps.json +6 -0
- package/test-data/exercise_muscle.json +69 -0
- package/test-data/exercises/bench_press.json +5 -0
- package/test-data/exercises/deadlift.json +5 -0
- package/test-data/exercises/squat.json +5 -0
- package/test-data/exercises.json +34 -0
- package/test-data/muscles/abdominal.json +6 -0
- package/test-data/muscles/biceps.json +6 -0
- package/test-data/muscles/calves.json +6 -0
- package/test-data/muscles/deltoids.json +6 -0
- package/test-data/muscles/erector_spinae.json +6 -0
- package/test-data/muscles/forearms.json +6 -0
- package/test-data/muscles/gluteus_maximus.json +6 -0
- package/test-data/muscles/hamstrings.json +6 -0
- package/test-data/muscles/latissimus_dorsi.json +6 -0
- package/test-data/muscles/obliques.json +6 -0
- package/test-data/muscles/pectorals.json +6 -0
- package/test-data/muscles/quadriceps.json +6 -0
- package/test-data/muscles/trapezius.json +6 -0
- package/test-data/muscles/triceps.json +6 -0
- package/test-data/muscles.json +50 -0
- package/test-data/workouts/2024-06-02-001.json +10 -0
- package/test-data/workouts/2024-06-02-002.json +10 -0
- package/test-data/workouts/2024-06-02-003.json +10 -0
- package/test-data/workouts/2024-06-05-001.json +10 -0
- package/test-data/workouts/2024-06-05-002.json +10 -0
- package/test-data/workouts/2024-06-05-003.json +10 -0
- package/test-data/workouts.json +84 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeFromQuery=void 0;const removeFromQuery=(e,r)=>r.replace(e,"").trim();exports.removeFromQuery=removeFromQuery;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.splitEntityProperty = void 0
|
|
7
|
+
const entityMatch = /^[a-z0-9_-]+/i
|
|
8
|
+
const propertyMatch = /\.([a-z0-9_-]+)$/i
|
|
9
|
+
const splitEntityProperty = entityProp => {
|
|
10
|
+
const entityFound = entityProp.match(entityMatch)
|
|
11
|
+
if (!entityFound) {
|
|
12
|
+
throw new Error(`Unable to use property: ${entityProp}`)
|
|
13
|
+
}
|
|
14
|
+
const propFound = entityProp.match(propertyMatch)
|
|
15
|
+
if (!propFound) {
|
|
16
|
+
throw new Error(`Unable to use property: ${entityProp}`)
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
entity: entityFound[0],
|
|
20
|
+
property: propFound[1]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.splitEntityProperty = splitEntityProperty
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitEntityProperty=void 0;const entityMatch=/^[a-z0-9_-]+/i,propertyMatch=/\.([a-z0-9_-]+)$/i,splitEntityProperty=t=>{const r=t.match(entityMatch);if(!r)throw new Error(`Unable to use property: ${t}`);const e=t.match(propertyMatch);if(!e)throw new Error(`Unable to use property: ${t}`);return{entity:r[0],property:e[1]}};exports.splitEntityProperty=splitEntityProperty;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.splitQueries = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.filter.js')
|
|
9
|
+
const queryMatch = /\s*(?=(?:delete|insert|read|update)\s+[a-z0-9._-]+)\s*/i
|
|
10
|
+
const splitQueries = (queries = '') => queries.split(queryMatch).filter(query => query.length > 0)
|
|
11
|
+
exports.splitQueries = splitQueries
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.splitQueries=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.filter.js");const queryMatch=/\s*(?=(?:delete|insert|read|update)\s+[a-z0-9._-]+)\s*/i,splitQueries=(e="")=>e.split(queryMatch).filter((e=>e.length>0));exports.splitQueries=splitQueries;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.reconcileJoin = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
9
|
+
const _where = require('../queries/where')
|
|
10
|
+
const reconcileJoin = (dataSet, entityName, entityKey, joinEntity, joinProp) => {
|
|
11
|
+
const entity = dataSet[entityName][entityKey]
|
|
12
|
+
if (entity.hasOwnProperty(joinEntity) && Array.isArray(entity[joinEntity])) {
|
|
13
|
+
entity[joinEntity].forEach((mergedEntity, k) => {
|
|
14
|
+
const matchedEntity = (0, _where.where)(dataSet[joinEntity], {
|
|
15
|
+
property: joinProp,
|
|
16
|
+
comparator: '=',
|
|
17
|
+
value: mergedEntity[joinProp]
|
|
18
|
+
})
|
|
19
|
+
if (matchedEntity.length) {
|
|
20
|
+
dataSet[entityName][entityKey][joinEntity][k] = matchedEntity[0]
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
return dataSet
|
|
25
|
+
}
|
|
26
|
+
exports.reconcileJoin = reconcileJoin
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.reconcileJoin=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js");var _where=require("../queries/where");const reconcileJoin=(e,r,o,t,s)=>{const c=e[r][o];return c.hasOwnProperty(t)&&Array.isArray(c[t])&&c[t].forEach(((c,i)=>{const n=(0,_where.where)(e[t],{property:s,comparator:"=",value:c[s]});n.length&&(e[r][o][t][i]=n[0])})),e};exports.reconcileJoin=reconcileJoin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.reconcileJoins = void 0
|
|
7
|
+
const _splitEntityProperty = require('./parsers/splitEntityProperty')
|
|
8
|
+
const _reconcileJoin = require('./reconcileJoin')
|
|
9
|
+
const reconcileJoins = (propertyA, propertyB, dataSet) => {
|
|
10
|
+
const {
|
|
11
|
+
entity: entityA,
|
|
12
|
+
property: propA
|
|
13
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(propertyA)
|
|
14
|
+
const {
|
|
15
|
+
entity: entityB,
|
|
16
|
+
property: propB
|
|
17
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(propertyB)
|
|
18
|
+
for (const entityName in dataSet) {
|
|
19
|
+
for (const entityKey in dataSet[entityName]) {
|
|
20
|
+
const entity = dataSet[entityName][entityKey]
|
|
21
|
+
dataSet = (0, _reconcileJoin.reconcileJoin)(dataSet, entityName, entityKey, entityA, propA)
|
|
22
|
+
dataSet = (0, _reconcileJoin.reconcileJoin)(dataSet, entityName, entityKey, entityB, propB)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return dataSet
|
|
26
|
+
}
|
|
27
|
+
exports.reconcileJoins = reconcileJoins
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.reconcileJoins=void 0;var _splitEntityProperty=require("./parsers/splitEntityProperty"),_reconcileJoin=require("./reconcileJoin");const reconcileJoins=(e,r,t)=>{const{entity:i,property:o}=(0,_splitEntityProperty.splitEntityProperty)(e),{entity:n,property:c}=(0,_splitEntityProperty.splitEntityProperty)(r);for(let e in t)for(let r in t[e]){t[e][r];t=(0,_reconcileJoin.reconcileJoin)(t,e,r,i,o),t=(0,_reconcileJoin.reconcileJoin)(t,e,r,n,c)}return t};exports.reconcileJoins=reconcileJoins;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { recordDefinition } from '../introspect/definitions/record';
|
|
2
|
+
/**
|
|
3
|
+
* Add a record's filename to the __RECORDS registry, creating the registry file the first time
|
|
4
|
+
* a record is created if it doesn't already exist.
|
|
5
|
+
* @param recordName
|
|
6
|
+
*/
|
|
7
|
+
export declare const registerRecord: (recordName: string) => Promise<recordDefinition>;
|
|
8
|
+
//# sourceMappingURL=registerRecord.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.registerRecord = void 0
|
|
7
|
+
require('core-js/modules/es.array.includes.js')
|
|
8
|
+
require('core-js/modules/es.json.stringify.js')
|
|
9
|
+
const gulpConfig = require('js-build-tools/gulp.config')
|
|
10
|
+
const {
|
|
11
|
+
readFile,
|
|
12
|
+
writeFile
|
|
13
|
+
} = require('fs/promises')
|
|
14
|
+
/**
|
|
15
|
+
* __RECORDS is itself an ordinary record - path/definition/keys/entries - whose entries are the
|
|
16
|
+
* filenames of every other record that has been created. This is the schema it's given the first
|
|
17
|
+
* time a record is registered and no __RECORDS.json exists yet, matching what a hand-authored
|
|
18
|
+
* database (see test-data/__RECORDS.json) already expects to find.
|
|
19
|
+
*/
|
|
20
|
+
const defaultRegistry = () => ({
|
|
21
|
+
path: '',
|
|
22
|
+
definition: [{
|
|
23
|
+
name: 'path',
|
|
24
|
+
type: 'string',
|
|
25
|
+
optional: false,
|
|
26
|
+
autoGenerate: false
|
|
27
|
+
}, {
|
|
28
|
+
name: 'definition',
|
|
29
|
+
type: 'object',
|
|
30
|
+
optional: false,
|
|
31
|
+
autoGenerate: false
|
|
32
|
+
}, {
|
|
33
|
+
name: 'keys',
|
|
34
|
+
type: 'array',
|
|
35
|
+
optional: false,
|
|
36
|
+
autoGenerate: false
|
|
37
|
+
}, {
|
|
38
|
+
name: 'entries',
|
|
39
|
+
type: 'array',
|
|
40
|
+
optional: false,
|
|
41
|
+
autoGenerate: false
|
|
42
|
+
}],
|
|
43
|
+
keys: [],
|
|
44
|
+
entries: []
|
|
45
|
+
})
|
|
46
|
+
/**
|
|
47
|
+
* Add a record's filename to the __RECORDS registry, creating the registry file the first time
|
|
48
|
+
* a record is created if it doesn't already exist.
|
|
49
|
+
* @param recordName
|
|
50
|
+
*/
|
|
51
|
+
const registerRecord = async recordName => {
|
|
52
|
+
const databasePath = gulpConfig.get('databasePath', 'database/')
|
|
53
|
+
const registryPath = `${databasePath}__RECORDS.json`
|
|
54
|
+
let registry
|
|
55
|
+
try {
|
|
56
|
+
registry = JSON.parse(await readFile(registryPath, 'utf8'))
|
|
57
|
+
} catch (err) {
|
|
58
|
+
registry = defaultRegistry()
|
|
59
|
+
}
|
|
60
|
+
const fileName = `${recordName}.json`
|
|
61
|
+
if (!registry.entries.includes(fileName)) {
|
|
62
|
+
registry.entries.push(fileName)
|
|
63
|
+
}
|
|
64
|
+
await writeFile(registryPath, JSON.stringify(registry, null, 2))
|
|
65
|
+
return registry
|
|
66
|
+
}
|
|
67
|
+
exports.registerRecord = registerRecord
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerRecord=void 0,require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.json.stringify.js");const gulpConfig=require("js-build-tools/gulp.config"),{readFile:readFile,writeFile:writeFile}=require("fs/promises"),defaultRegistry=()=>({path:"",definition:[{name:"path",type:"string",optional:!1,autoGenerate:!1},{name:"definition",type:"object",optional:!1,autoGenerate:!1},{name:"keys",type:"array",optional:!1,autoGenerate:!1},{name:"entries",type:"array",optional:!1,autoGenerate:!1}],keys:[],entries:[]}),registerRecord=async e=>{const t=`${gulpConfig.get("databasePath","database/")}__RECORDS.json`;let r;try{r=JSON.parse(await readFile(t,"utf8"))}catch(e){r=defaultRegistry()}const i=`${e}.json`;return r.entries.includes(i)||r.entries.push(i),await writeFile(t,JSON.stringify(r,null,2)),r};exports.registerRecord=registerRecord;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export declare const removeFromIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string) => Promise<indexEntry[] | null>;
|
|
14
|
+
//# sourceMappingURL=removeFromIndex.d.ts.map
|
|
@@ -0,0 +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
|
+
const gulpConfig = require('js-build-tools/gulp.config')
|
|
12
|
+
const {
|
|
13
|
+
readFile,
|
|
14
|
+
writeFile
|
|
15
|
+
} = require('fs/promises')
|
|
16
|
+
/**
|
|
17
|
+
* Remove a single entry file from the index that backs one of a record's keys, dropping a value
|
|
18
|
+
* entirely once its last file is removed. A key with no lookup, or an index file that doesn't
|
|
19
|
+
* exist yet, is left untouched.
|
|
20
|
+
* @param path
|
|
21
|
+
* @param key
|
|
22
|
+
* @param value
|
|
23
|
+
* @param fileName
|
|
24
|
+
*/
|
|
25
|
+
const removeFromIndex = async (path = '', key = null, value = undefined, fileName = '') => {
|
|
26
|
+
if (!key || !key.lookup) {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
const databasePath = gulpConfig.get('databasePath', 'database/')
|
|
30
|
+
const indexPath = `${databasePath}__indexes/${path}/${key.lookup}`
|
|
31
|
+
let index = []
|
|
32
|
+
try {
|
|
33
|
+
index = JSON.parse(await readFile(indexPath, 'utf8'))
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
index = index.map(entry => entry.value == value
|
|
38
|
+
? {
|
|
39
|
+
value: entry.value,
|
|
40
|
+
record: entry.record.filter(record => record !== fileName)
|
|
41
|
+
}
|
|
42
|
+
: entry).filter(entry => entry.record.length)
|
|
43
|
+
await writeFile(indexPath, JSON.stringify(index, null, 2))
|
|
44
|
+
return index
|
|
45
|
+
}
|
|
46
|
+
exports.removeFromIndex = removeFromIndex
|
|
@@ -0,0 +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");const gulpConfig=require("js-build-tools/gulp.config"),{readFile:readFile,writeFile:writeFile}=require("fs/promises"),removeFromIndex=async(e="",r=null,o=void 0,t="")=>{if(!r||!r.lookup)return null;const i=`${gulpConfig.get("databasePath","database/")}__indexes/${e}/${r.lookup}`;let s=[];try{s=JSON.parse(await readFile(i,"utf8"))}catch(e){return null}return s=s.map((e=>e.value==o?{value:e.value,record:e.record.filter((e=>e!==t))}:e)).filter((e=>e.record.length)),await writeFile(i,JSON.stringify(s,null,2)),s};exports.removeFromIndex=removeFromIndex;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.restrictIndexedList = void 0
|
|
7
|
+
const _splitEntityProperty = require('./parsers/splitEntityProperty')
|
|
8
|
+
const restrictIndexedList = (joinClause, filterJoins, indexedClone) => {
|
|
9
|
+
const {
|
|
10
|
+
entity: entityA,
|
|
11
|
+
property: propertyA
|
|
12
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA)
|
|
13
|
+
const {
|
|
14
|
+
entity: entityB,
|
|
15
|
+
property: propertyB
|
|
16
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB)
|
|
17
|
+
if (filterJoins.hasOwnProperty(entityA)) {
|
|
18
|
+
const existingEntities = filterJoins[entityA]
|
|
19
|
+
if (!indexedClone.hasOwnProperty(entityA)) {
|
|
20
|
+
indexedClone[entityA] = {}
|
|
21
|
+
}
|
|
22
|
+
if (!indexedClone[entityA].hasOwnProperty(propertyA)) {
|
|
23
|
+
indexedClone[entityA][propertyA] = {}
|
|
24
|
+
}
|
|
25
|
+
indexedClone[entityA][propertyA] = [{
|
|
26
|
+
value: existingEntities[0][propertyA],
|
|
27
|
+
record: existingEntities
|
|
28
|
+
}]
|
|
29
|
+
}
|
|
30
|
+
if (filterJoins.hasOwnProperty(entityB)) {
|
|
31
|
+
const existingEntities = filterJoins[entityB]
|
|
32
|
+
if (!indexedClone.hasOwnProperty(entityB)) {
|
|
33
|
+
indexedClone[entityB] = {}
|
|
34
|
+
}
|
|
35
|
+
if (!indexedClone[entityB].hasOwnProperty(propertyB)) {
|
|
36
|
+
indexedClone[entityB][propertyB] = {}
|
|
37
|
+
}
|
|
38
|
+
indexedClone[entityB][propertyB] = [{
|
|
39
|
+
value: existingEntities[0][propertyB],
|
|
40
|
+
record: existingEntities
|
|
41
|
+
}]
|
|
42
|
+
}
|
|
43
|
+
return indexedClone
|
|
44
|
+
}
|
|
45
|
+
exports.restrictIndexedList = restrictIndexedList
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.restrictIndexedList=void 0;var _splitEntityProperty=require("./parsers/splitEntityProperty");const restrictIndexedList=(t,r,e)=>{const{entity:s,property:p}=(0,_splitEntityProperty.splitEntityProperty)(t.propertyA),{entity:i,property:o}=(0,_splitEntityProperty.splitEntityProperty)(t.propertyB);if(r.hasOwnProperty(s)){const t=r[s];e.hasOwnProperty(s)||(e[s]={}),e[s].hasOwnProperty(p)||(e[s][p]={}),e[s][p]=[{value:t[0][p],record:t}]}if(r.hasOwnProperty(i)){const t=r[i];e.hasOwnProperty(i)||(e[i]={}),e[i].hasOwnProperty(o)||(e[i][o]={}),e[i][o]=[{value:t[0][o],record:t}]}return e};exports.restrictIndexedList=restrictIndexedList;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.weak-map.delete-all.js')
|
|
4
|
+
Object.defineProperty(exports, '__esModule', {
|
|
5
|
+
value: true
|
|
6
|
+
})
|
|
7
|
+
exports.retrieveFile = void 0
|
|
8
|
+
const jsEnv = _interopRequireWildcard(require('browser-or-node'))
|
|
9
|
+
const gulpConfig = _interopRequireWildcard(require('js-build-tools/gulp.config'))
|
|
10
|
+
function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; let o; let i; const f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
|
|
11
|
+
const retrieveFile = async path => {
|
|
12
|
+
let retrieveFn = url => fetch(url).then(res => res.json())
|
|
13
|
+
const relativePath = jsEnv.isBrowser ? gulpConfig.get('relativePath', '') : ''
|
|
14
|
+
if (jsEnv.isNode) {
|
|
15
|
+
const {
|
|
16
|
+
readFile
|
|
17
|
+
} = require('fs/promises')
|
|
18
|
+
retrieveFn = url => readFile(url).then(res => JSON.parse(res))
|
|
19
|
+
}
|
|
20
|
+
const databasePath = gulpConfig.get('databasePath', 'database/')
|
|
21
|
+
const fetchUrl = `${relativePath}${databasePath}${path}`
|
|
22
|
+
const recordInfo = await retrieveFn(fetchUrl).catch(err => console.error(err))
|
|
23
|
+
if (!recordInfo) {
|
|
24
|
+
throw new Error(`Could not read ${path}`)
|
|
25
|
+
}
|
|
26
|
+
return recordInfo
|
|
27
|
+
}
|
|
28
|
+
exports.retrieveFile = retrieveFile
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.retrieveFile=void 0;var jsEnv=_interopRequireWildcard(require("browser-or-node")),gulpConfig=_interopRequireWildcard(require("js-build-tools/gulp.config"));function _interopRequireWildcard(e,r){if("function"==typeof WeakMap)var t=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,r){if(!r&&e&&e.__esModule)return e;var o,n,a={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return a;if(o=r?i:t){if(o.has(e))return o.get(e);o.set(e,a)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((n=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(n.get||n.set)?o(a,r,n):a[r]=e[r]);return a})(e,r)}const retrieveFile=async e=>{let r=e=>fetch(e).then((e=>e.json())),t=jsEnv.isBrowser?gulpConfig.get("relativePath",""):"";if(jsEnv.isNode){const{readFile:e}=require("fs/promises");r=r=>e(r).then((e=>JSON.parse(e)))}const i=`${t}${gulpConfig.get("databasePath","database/")}${e}`,o=await r(i).catch((e=>console.error(e)));if(!o)throw new Error(`Could not read ${e}`);return o};exports.retrieveFile=retrieveFile;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.retrieveIndexes = void 0
|
|
7
|
+
require('core-js/modules/es.array.includes.js')
|
|
8
|
+
const _retrieveFile = require('./retrieveFile')
|
|
9
|
+
const _retrieveRecord = require('./retrieveRecord')
|
|
10
|
+
const retrieveIndexes = async (entity = '', properties = [], recordData = {}) => {
|
|
11
|
+
if (!recordData.hasOwnProperty(entity)) {
|
|
12
|
+
recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity)
|
|
13
|
+
}
|
|
14
|
+
const indexSet = {}
|
|
15
|
+
for (const property of properties) {
|
|
16
|
+
for (const key of recordData[entity].keys) {
|
|
17
|
+
if (key.fields.includes(property)) {
|
|
18
|
+
indexSet[property] = await (0, _retrieveFile.retrieveFile)(`__indexes/${entity}/${key.lookup}`)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return indexSet
|
|
23
|
+
}
|
|
24
|
+
exports.retrieveIndexes = retrieveIndexes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.retrieveIndexes=void 0,require("core-js/modules/es.array.includes.js");var _retrieveFile=require("./retrieveFile"),_retrieveRecord=require("./retrieveRecord");const retrieveIndexes=async(e="",r=[],i={})=>{i.hasOwnProperty(e)||(i[e]=await(0,_retrieveRecord.retrieveRecord)(e));const t={};for(let s of r)for(let r of i[e].keys)r.fields.includes(s)&&(t[s]=await(0,_retrieveFile.retrieveFile)(`__indexes/${e}/${r.lookup}`));return t};exports.retrieveIndexes=retrieveIndexes;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.retrieveRecord = void 0
|
|
7
|
+
const _retrieveFile = require('./retrieveFile')
|
|
8
|
+
const retrieveRecord = async (entity = '') => await (0, _retrieveFile.retrieveFile)(`${entity}.json`)
|
|
9
|
+
exports.retrieveRecord = retrieveRecord
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.retrieveRecord=void 0;var _retrieveFile=require("./retrieveFile");const retrieveRecord=async(e="")=>await(0,_retrieveFile.retrieveFile)(`${e}.json`);exports.retrieveRecord=retrieveRecord;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.retrieveRecords = void 0
|
|
7
|
+
const _retrieveFile = require('./retrieveFile')
|
|
8
|
+
const _retrieveRecord = require('./retrieveRecord')
|
|
9
|
+
const retrieveRecords = async (entity = '') => {
|
|
10
|
+
const recordFile = await (0, _retrieveRecord.retrieveRecord)(entity)
|
|
11
|
+
const dataSet = []
|
|
12
|
+
for (const file of recordFile.entries) {
|
|
13
|
+
const data = await (0, _retrieveFile.retrieveFile)(`${recordFile.path}/${file}`).catch(err => console.error(err))
|
|
14
|
+
if (!data) {
|
|
15
|
+
throw new Error(`Could not read entity ${file}`)
|
|
16
|
+
}
|
|
17
|
+
dataSet.push(data)
|
|
18
|
+
}
|
|
19
|
+
return dataSet
|
|
20
|
+
}
|
|
21
|
+
exports.retrieveRecords = retrieveRecords
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.retrieveRecords=void 0;var _retrieveFile=require("./retrieveFile"),_retrieveRecord=require("./retrieveRecord");const retrieveRecords=async(e="")=>{const r=await(0,_retrieveRecord.retrieveRecord)(e),t=[];for(let e of r.entries){const i=await(0,_retrieveFile.retrieveFile)(`${r.path}/${e}`).catch((e=>console.error(e)));if(!i)throw new Error(`Could not read entity ${e}`);t.push(i)}return t};exports.retrieveRecords=retrieveRecords;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.runQuery = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.reduce.js')
|
|
9
|
+
const _deleteEntity = require('../queries/deleteEntity')
|
|
10
|
+
const _insertEntity = require('../queries/insertEntity')
|
|
11
|
+
const _readEntity = require('../queries/readEntity')
|
|
12
|
+
const _updateEntity = require('../queries/updateEntity')
|
|
13
|
+
const _joinEntity = require('../queries/joinEntity')
|
|
14
|
+
const _mergeJoins = require('../queries/mergeJoins')
|
|
15
|
+
const _where = require('../queries/where')
|
|
16
|
+
const _sortBy = require('../queries/sortBy')
|
|
17
|
+
const _groupBy = require('../queries/groupBy')
|
|
18
|
+
const _retrieveRecord = require('./retrieveRecord')
|
|
19
|
+
const _getConditionIndexedList = require('./getConditionIndexedList')
|
|
20
|
+
const _getJoinIndexedList = require('./getJoinIndexedList')
|
|
21
|
+
const runQuery = async parsed => {
|
|
22
|
+
const recordData = {
|
|
23
|
+
[parsed.entity]: await (0, _retrieveRecord.retrieveRecord)(parsed.entity)
|
|
24
|
+
}
|
|
25
|
+
if (typeof parsed.joinEntity !== 'undefined') {
|
|
26
|
+
recordData[parsed.joinEntity] = await (0, _retrieveRecord.retrieveRecord)(parsed.joinEntity)
|
|
27
|
+
}
|
|
28
|
+
let dataSet = {
|
|
29
|
+
[parsed.entity]: []
|
|
30
|
+
}
|
|
31
|
+
parsed = await (0, _getConditionIndexedList.getConditionIndexedList)(parsed, recordData, dataSet)
|
|
32
|
+
parsed = await (0, _getJoinIndexedList.getJoinIndexedList)(parsed, recordData, dataSet)
|
|
33
|
+
// delete/update act on whatever is already in dataSet[entity] - unlike read, which loads
|
|
34
|
+
// everything and lets the where-reduce below narrow it down afterward, they never get a second
|
|
35
|
+
// pass. So the matching rows have to be fully resolved (indexed conditions already are, via
|
|
36
|
+
// getConditionIndexedList above; anything left in parsed.conditions is not) before either runs.
|
|
37
|
+
if (parsed.command === 'delete' || parsed.command === 'update') {
|
|
38
|
+
dataSet = await (0, _readEntity.readEntity)(parsed.entity, dataSet)
|
|
39
|
+
dataSet[parsed.entity] = parsed.conditions.reduce((remainingData, condition) => (0, _where.where)(remainingData, condition), dataSet[parsed.entity])
|
|
40
|
+
}
|
|
41
|
+
switch (parsed.command) {
|
|
42
|
+
case 'delete':
|
|
43
|
+
dataSet = await (0, _deleteEntity.deleteEntity)(parsed.entity, dataSet)
|
|
44
|
+
break
|
|
45
|
+
case 'insert':
|
|
46
|
+
dataSet = await (0, _insertEntity.insertEntity)(parsed.entity, parsed.insertValues, dataSet)
|
|
47
|
+
break
|
|
48
|
+
case 'read':
|
|
49
|
+
dataSet = await (0, _readEntity.readEntity)(parsed.entity, dataSet)
|
|
50
|
+
break
|
|
51
|
+
case 'update':
|
|
52
|
+
dataSet = await (0, _updateEntity.updateEntity)(parsed.entity, parsed.updateValues, dataSet)
|
|
53
|
+
break
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Unknown command: ${parsed.command}`)
|
|
56
|
+
}
|
|
57
|
+
dataSet = await (0, _joinEntity.joinEntity)(parsed.entity, parsed.joinEntity, dataSet, parsed.joinClauses)
|
|
58
|
+
dataSet = await (0, _mergeJoins.mergeJoins)(dataSet, parsed.mergeJoins)
|
|
59
|
+
// delete/update already had parsed.conditions applied above, before they ran. Re-applying the
|
|
60
|
+
// same conditions here would be wrong, not just redundant, for update specifically: if the
|
|
61
|
+
// update just changed the very field a condition filters on, re-checking that condition against
|
|
62
|
+
// the now-changed data would filter the just-updated rows back out.
|
|
63
|
+
if (parsed.command !== 'delete' && parsed.command !== 'update') {
|
|
64
|
+
dataSet[parsed.entity] = parsed.conditions.reduce((remainingData, condition) => {
|
|
65
|
+
return (0, _where.where)(remainingData, condition)
|
|
66
|
+
}, dataSet[parsed.entity])
|
|
67
|
+
}
|
|
68
|
+
dataSet[parsed.entity] = (0, _sortBy.sortBy)(dataSet[parsed.entity], parsed.sortClauses)
|
|
69
|
+
dataSet[parsed.entity] = (0, _groupBy.groupBy)(dataSet[parsed.entity], parsed.groupBy)
|
|
70
|
+
return dataSet
|
|
71
|
+
}
|
|
72
|
+
exports.runQuery = runQuery
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runQuery=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _deleteEntity=require("../queries/deleteEntity"),_insertEntity=require("../queries/insertEntity"),_readEntity=require("../queries/readEntity"),_updateEntity=require("../queries/updateEntity"),_joinEntity=require("../queries/joinEntity"),_mergeJoins=require("../queries/mergeJoins"),_where=require("../queries/where"),_sortBy=require("../queries/sortBy"),_groupBy=require("../queries/groupBy"),_retrieveRecord=require("./retrieveRecord"),_getConditionIndexedList=require("./getConditionIndexedList"),_getJoinIndexedList=require("./getJoinIndexedList");const runQuery=async e=>{const t={[e.entity]:await(0,_retrieveRecord.retrieveRecord)(e.entity)};void 0!==e.joinEntity&&(t[e.joinEntity]=await(0,_retrieveRecord.retrieveRecord)(e.joinEntity));let i={[e.entity]:[]};switch(e=await(0,_getConditionIndexedList.getConditionIndexedList)(e,t,i),"delete"!==(e=await(0,_getJoinIndexedList.getJoinIndexedList)(e,t,i)).command&&"update"!==e.command||(i=await(0,_readEntity.readEntity)(e.entity,i),i[e.entity]=e.conditions.reduce(((e,t)=>(0,_where.where)(e,t)),i[e.entity])),e.command){case"delete":i=await(0,_deleteEntity.deleteEntity)(e.entity,i);break;case"insert":i=await(0,_insertEntity.insertEntity)(e.entity,e.insertValues,i);break;case"read":i=await(0,_readEntity.readEntity)(e.entity,i);break;case"update":i=await(0,_updateEntity.updateEntity)(e.entity,e.updateValues,i);break;default:throw new Error(`Unknown command: ${e.command}`)}return i=await(0,_joinEntity.joinEntity)(e.entity,e.joinEntity,i,e.joinClauses),i=await(0,_mergeJoins.mergeJoins)(i,e.mergeJoins),"delete"!==e.command&&"update"!==e.command&&(i[e.entity]=e.conditions.reduce(((e,t)=>(0,_where.where)(e,t)),i[e.entity])),i[e.entity]=(0,_sortBy.sortBy)(i[e.entity],e.sortClauses),i[e.entity]=(0,_groupBy.groupBy)(i[e.entity],e.groupBy),i};exports.runQuery=runQuery;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { keyDefinition } from '../introspect/definitions/key';
|
|
2
|
+
import { recordPath } from '../introspect/definitions/record';
|
|
3
|
+
export type indexEntry = {
|
|
4
|
+
value: any;
|
|
5
|
+
record: string[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Add a single entry file to the index that backs one of a record's keys, creating the index
|
|
9
|
+
* file (and its __indexes/{record} directory) the first time a value is indexed. Keys with no
|
|
10
|
+
* lookup (multi-field keys are not indexed here) are left untouched.
|
|
11
|
+
* @param path
|
|
12
|
+
* @param key
|
|
13
|
+
* @param value
|
|
14
|
+
* @param fileName
|
|
15
|
+
*/
|
|
16
|
+
export declare const updateIndex: (path?: recordPath, key?: keyDefinition, value?: any, fileName?: string) => Promise<indexEntry[] | null>;
|
|
17
|
+
//# sourceMappingURL=updateIndex.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.updateIndex = void 0
|
|
7
|
+
require('core-js/modules/es.array.includes.js')
|
|
8
|
+
require('core-js/modules/es.json.stringify.js')
|
|
9
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
10
|
+
require('core-js/modules/esnext.iterator.find.js')
|
|
11
|
+
const gulpConfig = require('js-build-tools/gulp.config')
|
|
12
|
+
const {
|
|
13
|
+
readFile,
|
|
14
|
+
writeFile,
|
|
15
|
+
mkdir
|
|
16
|
+
} = require('fs/promises')
|
|
17
|
+
/**
|
|
18
|
+
* Add a single entry file to the index that backs one of a record's keys, creating the index
|
|
19
|
+
* file (and its __indexes/{record} directory) the first time a value is indexed. Keys with no
|
|
20
|
+
* lookup (multi-field keys are not indexed here) are left untouched.
|
|
21
|
+
* @param path
|
|
22
|
+
* @param key
|
|
23
|
+
* @param value
|
|
24
|
+
* @param fileName
|
|
25
|
+
*/
|
|
26
|
+
const updateIndex = async (path = '', key = null, value = undefined, fileName = '') => {
|
|
27
|
+
if (!key || !key.lookup) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
const databasePath = gulpConfig.get('databasePath', 'database/')
|
|
31
|
+
const indexDir = `${databasePath}__indexes/${path}`
|
|
32
|
+
const indexPath = `${indexDir}/${key.lookup}`
|
|
33
|
+
let index = []
|
|
34
|
+
try {
|
|
35
|
+
index = JSON.parse(await readFile(indexPath, 'utf8'))
|
|
36
|
+
} catch (err) {
|
|
37
|
+
index = []
|
|
38
|
+
}
|
|
39
|
+
const existingEntry = index.find(entry => entry.value == value)
|
|
40
|
+
if (existingEntry) {
|
|
41
|
+
if (!existingEntry.record.includes(fileName)) {
|
|
42
|
+
existingEntry.record.push(fileName)
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
index.push({
|
|
46
|
+
value,
|
|
47
|
+
record: [fileName]
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
await mkdir(indexDir, {
|
|
51
|
+
recursive: true
|
|
52
|
+
})
|
|
53
|
+
await writeFile(indexPath, JSON.stringify(index, null, 2))
|
|
54
|
+
return index
|
|
55
|
+
}
|
|
56
|
+
exports.updateIndex = updateIndex
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateIndex=void 0,require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.json.stringify.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.find.js");const gulpConfig=require("js-build-tools/gulp.config"),{readFile:readFile,writeFile:writeFile,mkdir:mkdir}=require("fs/promises"),updateIndex=async(e="",r=null,s=void 0,i="")=>{if(!r||!r.lookup)return null;const t=`${gulpConfig.get("databasePath","database/")}__indexes/${e}`,u=`${t}/${r.lookup}`;let o=[];try{o=JSON.parse(await readFile(u,"utf8"))}catch(e){o=[]}const d=o.find((e=>e.value==s));return d?d.record.includes(i)||d.record.push(i):o.push({value:s,record:[i]}),await mkdir(t,{recursive:!0}),await writeFile(u,JSON.stringify(o,null,2)),o};exports.updateIndex=updateIndex;
|