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,51 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.useJoinClause = void 0
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
8
|
+
require('core-js/modules/esnext.iterator.reduce.js')
|
|
9
|
+
const _readEntity = require('../queries/readEntity')
|
|
10
|
+
const _where = require('../queries/where')
|
|
11
|
+
const _splitEntityProperty = require('./parsers/splitEntityProperty')
|
|
12
|
+
const _siFunciona = _interopRequireDefault(require('si-funciona'))
|
|
13
|
+
function _interopRequireDefault (e) { return e && e.__esModule ? e : { default: e } }
|
|
14
|
+
const useJoinClause = async ({
|
|
15
|
+
propertyA = null,
|
|
16
|
+
comparator = '=',
|
|
17
|
+
propertyB = null
|
|
18
|
+
} = {}, dataSets = {}, filterJoins = {}) => {
|
|
19
|
+
const {
|
|
20
|
+
entity: entityA,
|
|
21
|
+
property: propA
|
|
22
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(propertyA)
|
|
23
|
+
const {
|
|
24
|
+
entity: entityB,
|
|
25
|
+
property: propB
|
|
26
|
+
} = (0, _splitEntityProperty.splitEntityProperty)(propertyB)
|
|
27
|
+
if (!dataSets.hasOwnProperty(entityA)) {
|
|
28
|
+
dataSets = await (0, _readEntity.readEntity)(entityA, dataSets)
|
|
29
|
+
}
|
|
30
|
+
if (!dataSets.hasOwnProperty(entityB)) {
|
|
31
|
+
dataSets = await (0, _readEntity.readEntity)(entityB, dataSets)
|
|
32
|
+
}
|
|
33
|
+
if (!filterJoins.hasOwnProperty(entityA)) {
|
|
34
|
+
filterJoins[entityA] = _siFunciona.default.cloneObject(dataSets[entityA])
|
|
35
|
+
}
|
|
36
|
+
if (!filterJoins.hasOwnProperty(entityB)) {
|
|
37
|
+
filterJoins[entityB] = _siFunciona.default.cloneObject(dataSets[entityB])
|
|
38
|
+
}
|
|
39
|
+
filterJoins[entityA] = filterJoins[entityB].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(filterJoins[entityA], {
|
|
40
|
+
property: propA,
|
|
41
|
+
comparator,
|
|
42
|
+
value: dataB[propB]
|
|
43
|
+
})), [])
|
|
44
|
+
filterJoins[entityB] = filterJoins[entityA].reduce((dataB, dataA) => _siFunciona.default.mergeArrays(dataB, (0, _where.where)(filterJoins[entityB], {
|
|
45
|
+
property: propB,
|
|
46
|
+
comparator,
|
|
47
|
+
value: dataA[propA]
|
|
48
|
+
})), [])
|
|
49
|
+
return filterJoins
|
|
50
|
+
}
|
|
51
|
+
exports.useJoinClause = useJoinClause
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useJoinClause=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var _readEntity=require("../queries/readEntity"),_where=require("../queries/where"),_splitEntityProperty=require("./parsers/splitEntityProperty"),_siFunciona=_interopRequireDefault(require("si-funciona"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const useJoinClause=async({propertyA:e=null,comparator:r="=",propertyB:t=null}={},i={},o={})=>{const{entity:n,property:s}=(0,_splitEntityProperty.splitEntityProperty)(e),{entity:u,property:a}=(0,_splitEntityProperty.splitEntityProperty)(t);return i.hasOwnProperty(n)||(i=await(0,_readEntity.readEntity)(n,i)),i.hasOwnProperty(u)||(i=await(0,_readEntity.readEntity)(u,i)),o.hasOwnProperty(n)||(o[n]=_siFunciona.default.cloneObject(i[n])),o.hasOwnProperty(u)||(o[u]=_siFunciona.default.cloneObject(i[u])),o[n]=o[u].reduce(((e,t)=>_siFunciona.default.mergeArrays(e,(0,_where.where)(o[n],{property:s,comparator:r,value:t[a]}))),[]),o[u]=o[n].reduce(((e,t)=>_siFunciona.default.mergeArrays(e,(0,_where.where)(o[u],{property:a,comparator:r,value:t[s]}))),[]),o};exports.useJoinClause=useJoinClause;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { query } from './data/queries/query';
|
|
2
|
+
export { create, drop, describe } from './data/introspect';
|
|
3
|
+
export { fieldProperties, fieldDefinition, fieldName, keyProperties, keyDefinition, indexType, indexLocation, referenceProperties, reference, recordProperties, recordDefinition, recordPath, entityPath } from './data/introspect';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.async-iterator.constructor.js')
|
|
4
|
+
require('core-js/modules/esnext.async-iterator.drop.js')
|
|
5
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
6
|
+
require('core-js/modules/esnext.iterator.drop.js')
|
|
7
|
+
Object.defineProperty(exports, '__esModule', {
|
|
8
|
+
value: true
|
|
9
|
+
})
|
|
10
|
+
Object.defineProperty(exports, 'create', {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _introspect.create
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
Object.defineProperty(exports, 'describe', {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _introspect.describe
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
Object.defineProperty(exports, 'drop', {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _introspect.drop
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
Object.defineProperty(exports, 'query', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _query.query
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
var _query = require('./data/queries/query')
|
|
35
|
+
var _introspect = require('./data/introspect')
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";require("core-js/modules/esnext.async-iterator.constructor.js"),require("core-js/modules/esnext.async-iterator.drop.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.drop.js"),Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"create",{enumerable:!0,get:function(){return _introspect.create}}),Object.defineProperty(exports,"describe",{enumerable:!0,get:function(){return _introspect.describe}}),Object.defineProperty(exports,"drop",{enumerable:!0,get:function(){return _introspect.drop}}),Object.defineProperty(exports,"query",{enumerable:!0,get:function(){return _query.query}});var _query=require("./data/queries/query"),_introspect=require("./data/introspect");
|
package/gulpfile.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "json-fs-query",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Use json files to manage and read data.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "gulp build",
|
|
9
|
+
"dev": "gulp",
|
|
10
|
+
"docs": "gulp docs",
|
|
11
|
+
"sass": "gulp sass",
|
|
12
|
+
"test": "gulp testFull",
|
|
13
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
14
|
+
"test:quick": "gulp testQuick",
|
|
15
|
+
"watch": "gulp watchFull",
|
|
16
|
+
"watch:test": "gulp watchTest"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/jheagle/json-file-db.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"database",
|
|
24
|
+
"filesystem",
|
|
25
|
+
"json",
|
|
26
|
+
"data"
|
|
27
|
+
],
|
|
28
|
+
"author": "Joshua Heagle <joshuaheagle@gmail.com>",
|
|
29
|
+
"license": "GPL-3.0-or-later",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/jheagle/json-file-db/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/jheagle/json-file-db#readme",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"gulp": "^5.0.1",
|
|
36
|
+
"js-build-tools": "^5.3.2",
|
|
37
|
+
"typedoc": "^0.28.20",
|
|
38
|
+
"test-filesystem": "^1.3.14"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"browser-or-node": "^3.0.0",
|
|
42
|
+
"si-funciona": "^2.3.4"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { create } from './create'
|
|
2
|
+
import { testHelpers } from 'js-build-tools/testHelpers'
|
|
3
|
+
|
|
4
|
+
const databasePath = 'create-database/'
|
|
5
|
+
const gulpConfig = testHelpers.gulpConfig
|
|
6
|
+
gulpConfig.set('databasePath', databasePath)
|
|
7
|
+
testHelpers.setDefaults(databasePath)
|
|
8
|
+
|
|
9
|
+
beforeEach(testHelpers.beforeEach)
|
|
10
|
+
|
|
11
|
+
afterEach(testHelpers.afterEach)
|
|
12
|
+
|
|
13
|
+
describe('create', () => {
|
|
14
|
+
test('create a new record', async () => {
|
|
15
|
+
expect.assertions(3)
|
|
16
|
+
const recordName = 'foo'
|
|
17
|
+
const definition = [
|
|
18
|
+
{
|
|
19
|
+
name: '_id',
|
|
20
|
+
type: 'string',
|
|
21
|
+
optional: false,
|
|
22
|
+
autoGenerate: true
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'bar',
|
|
26
|
+
type: 'string',
|
|
27
|
+
optional: true,
|
|
28
|
+
autoGenerate: false
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
const keys = [
|
|
32
|
+
{
|
|
33
|
+
type: 'primary',
|
|
34
|
+
fields: [
|
|
35
|
+
'_id'
|
|
36
|
+
],
|
|
37
|
+
lookup: 'pk__id.json'
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
const result = await create(recordName, definition, keys)
|
|
41
|
+
expect(result).toEqual({
|
|
42
|
+
path: recordName,
|
|
43
|
+
definition: definition,
|
|
44
|
+
keys: keys,
|
|
45
|
+
entries: []
|
|
46
|
+
})
|
|
47
|
+
expect(testHelpers.fileExists(`${databasePath}${recordName}.json`)).toBeTruthy()
|
|
48
|
+
expect(testHelpers.fileExists(`${databasePath}${recordName}`)).toBeTruthy()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('registers the new record in __RECORDS', async () => {
|
|
52
|
+
await create('foo', [], [])
|
|
53
|
+
const { readFile } = require('fs/promises')
|
|
54
|
+
const registry = JSON.parse(await readFile(`${databasePath}__RECORDS.json`, 'utf8'))
|
|
55
|
+
expect(registry.entries).toContain('foo.json')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('creates the database directory itself when it does not already exist', async () => {
|
|
59
|
+
const { rm } = require('fs/promises')
|
|
60
|
+
await rm(databasePath, { recursive: true, force: true })
|
|
61
|
+
expect(testHelpers.fileExists(databasePath)).toBeFalsy()
|
|
62
|
+
|
|
63
|
+
await create('foo', [], [])
|
|
64
|
+
|
|
65
|
+
expect(testHelpers.fileExists(`${databasePath}foo.json`)).toBeTruthy()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fileExists } from 'test-filesystem'
|
|
2
|
+
import { record, recordDefinition } from './definitions/record'
|
|
3
|
+
import { keyProperties } from './definitions/key'
|
|
4
|
+
import { fieldProperties } from './definitions/field'
|
|
5
|
+
import { registerRecord } from '../utilities/registerRecord'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a new record.
|
|
9
|
+
* @param recordName
|
|
10
|
+
* @param definition
|
|
11
|
+
* @param keys
|
|
12
|
+
*/
|
|
13
|
+
export const create = async (recordName: string, definition: fieldProperties[] = [], keys: keyProperties[] = []): Promise<recordDefinition | null> => {
|
|
14
|
+
const gulpConfig = require('js-build-tools/gulp.config')
|
|
15
|
+
const { writeFile, mkdir } = require('fs/promises')
|
|
16
|
+
const databasePath = gulpConfig.get('databasePath', 'database/')
|
|
17
|
+
if (recordName === '__RECORDS') {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
if (fileExists(`${databasePath}${recordName}.json`)) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
await mkdir(databasePath, { recursive: true })
|
|
24
|
+
const recordContent = record({ path: recordName, definition: definition, keys: keys })
|
|
25
|
+
await writeFile(`${databasePath}${recordName}.json`, JSON.stringify(recordContent, null, 2))
|
|
26
|
+
await mkdir(`${databasePath}${recordName}`, { recursive: true })
|
|
27
|
+
await registerRecord(recordName)
|
|
28
|
+
return recordContent
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { field } from './field'
|
|
2
|
+
|
|
3
|
+
describe('field', () => {
|
|
4
|
+
test('can create a field with default value', () => {
|
|
5
|
+
const generatedField = {
|
|
6
|
+
name: 'quantity',
|
|
7
|
+
type: 'string',
|
|
8
|
+
optional: true,
|
|
9
|
+
autoGenerate: false,
|
|
10
|
+
default: 0
|
|
11
|
+
}
|
|
12
|
+
expect(
|
|
13
|
+
field({
|
|
14
|
+
name: generatedField.name,
|
|
15
|
+
type: generatedField.type,
|
|
16
|
+
optional: generatedField.optional,
|
|
17
|
+
autoGenerate: generatedField.autoGenerate,
|
|
18
|
+
useDefault: true,
|
|
19
|
+
defaultValue: generatedField.default
|
|
20
|
+
})
|
|
21
|
+
).toEqual(generatedField)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type fieldName = string;
|
|
2
|
+
|
|
3
|
+
export type fieldDefinition = {
|
|
4
|
+
name: fieldName
|
|
5
|
+
type: string
|
|
6
|
+
optional: boolean
|
|
7
|
+
default?: any
|
|
8
|
+
autoGenerate: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type fieldProperties = {
|
|
12
|
+
name?: string
|
|
13
|
+
type?: string
|
|
14
|
+
optional?: boolean
|
|
15
|
+
useDefault?: boolean
|
|
16
|
+
defaultValue?: any
|
|
17
|
+
autoGenerate?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generate a field for a record.
|
|
22
|
+
* @param properties
|
|
23
|
+
* @param properties.name
|
|
24
|
+
* @param properties.type
|
|
25
|
+
* @param properties.optional
|
|
26
|
+
* @param properties.useDefault
|
|
27
|
+
* @param properties.defaultValue
|
|
28
|
+
* @param properties.autoGenerate
|
|
29
|
+
*/
|
|
30
|
+
export const field = ({
|
|
31
|
+
name = '',
|
|
32
|
+
type = 'string',
|
|
33
|
+
optional = false,
|
|
34
|
+
useDefault = false,
|
|
35
|
+
defaultValue = '',
|
|
36
|
+
autoGenerate = false
|
|
37
|
+
}: fieldProperties = {}): fieldDefinition => {
|
|
38
|
+
const returnField = {
|
|
39
|
+
name: name,
|
|
40
|
+
type: type,
|
|
41
|
+
optional: optional,
|
|
42
|
+
autoGenerate: autoGenerate,
|
|
43
|
+
}
|
|
44
|
+
if (useDefault) {
|
|
45
|
+
returnField['default'] = defaultValue
|
|
46
|
+
}
|
|
47
|
+
return returnField
|
|
48
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { key } from './key'
|
|
2
|
+
|
|
3
|
+
describe('key', () => {
|
|
4
|
+
test('can generate a primary key', () => {
|
|
5
|
+
const primaryKey = {
|
|
6
|
+
type: 'primary',
|
|
7
|
+
fields: [
|
|
8
|
+
'_id'
|
|
9
|
+
],
|
|
10
|
+
lookup: 'pk__id.json'
|
|
11
|
+
}
|
|
12
|
+
expect(key(primaryKey)).toEqual(primaryKey)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('can generate an index key', () => {
|
|
16
|
+
const indexKey = {
|
|
17
|
+
type: 'index',
|
|
18
|
+
fields: [
|
|
19
|
+
'date'
|
|
20
|
+
],
|
|
21
|
+
lookup: 'index_date.json'
|
|
22
|
+
}
|
|
23
|
+
expect(key(indexKey)).toEqual(indexKey)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('can generate an unique key', () => {
|
|
27
|
+
const uniqueKey = {
|
|
28
|
+
type: 'unique',
|
|
29
|
+
fields: [
|
|
30
|
+
'email'
|
|
31
|
+
],
|
|
32
|
+
lookup: 'unique_email.json'
|
|
33
|
+
}
|
|
34
|
+
expect(key(uniqueKey)).toEqual(uniqueKey)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('can generate a multi key', () => {
|
|
38
|
+
const multiKey = {
|
|
39
|
+
type: 'multi',
|
|
40
|
+
fields: [
|
|
41
|
+
'email',
|
|
42
|
+
'user_id'
|
|
43
|
+
],
|
|
44
|
+
lookup: 'multi_email_user_id.json'
|
|
45
|
+
}
|
|
46
|
+
expect(key(multiKey)).toEqual(multiKey)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('can generate a foreign key', () => {
|
|
50
|
+
const foreignKey = {
|
|
51
|
+
type: 'foreign',
|
|
52
|
+
fields: [
|
|
53
|
+
'user_id'
|
|
54
|
+
],
|
|
55
|
+
lookup: 'fk_user_id.json',
|
|
56
|
+
references: [
|
|
57
|
+
{
|
|
58
|
+
fields: [
|
|
59
|
+
'users._id'
|
|
60
|
+
],
|
|
61
|
+
lookup: 'users.json'
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
expect(key(foreignKey)).toEqual(foreignKey)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('will throw Error for invalid multi, insufficient fields', () => {
|
|
69
|
+
const multiKey = {
|
|
70
|
+
type: 'multi',
|
|
71
|
+
fields: [
|
|
72
|
+
'email'
|
|
73
|
+
],
|
|
74
|
+
lookup: 'multi_email_user_id.json'
|
|
75
|
+
}
|
|
76
|
+
expect(() => key(multiKey)).toThrow(Error)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('will throw Error for invalid foreign, insufficient references', () => {
|
|
80
|
+
const foreignKey = {
|
|
81
|
+
type: 'foreign',
|
|
82
|
+
fields: [
|
|
83
|
+
'user_id'
|
|
84
|
+
],
|
|
85
|
+
lookup: 'fk_user_id.json'
|
|
86
|
+
}
|
|
87
|
+
expect(() => key(foreignKey)).toThrow(Error)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('will throw Error for unknown key type', () => {
|
|
91
|
+
const strangeKey = {
|
|
92
|
+
type: 'strange',
|
|
93
|
+
fields: [
|
|
94
|
+
'blah'
|
|
95
|
+
],
|
|
96
|
+
lookup: 'strange_blah.json'
|
|
97
|
+
}
|
|
98
|
+
expect(() => key(strangeKey)).toThrow(Error)
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { keyReference, reference } from './keyReference'
|
|
2
|
+
import { fieldName } from './field'
|
|
3
|
+
|
|
4
|
+
export type indexType = string
|
|
5
|
+
|
|
6
|
+
export type indexLocation = string
|
|
7
|
+
|
|
8
|
+
export type keyDefinition = {
|
|
9
|
+
type: indexType
|
|
10
|
+
fields: Array<fieldName>
|
|
11
|
+
lookup: indexLocation
|
|
12
|
+
references?: Array<reference>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type keyProperties = {
|
|
16
|
+
type?: indexType
|
|
17
|
+
fields?: Array<fieldName>
|
|
18
|
+
lookup?: indexLocation
|
|
19
|
+
references?: Array<reference>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a field key.
|
|
24
|
+
* @param properties
|
|
25
|
+
* @param properties.type
|
|
26
|
+
* @param properties.fields
|
|
27
|
+
* @param properties.lookup
|
|
28
|
+
* @param properties.references
|
|
29
|
+
*/
|
|
30
|
+
export const key = ({
|
|
31
|
+
type = 'index',
|
|
32
|
+
fields = [],
|
|
33
|
+
lookup = '',
|
|
34
|
+
references = []
|
|
35
|
+
}: keyProperties = {}): keyDefinition => {
|
|
36
|
+
switch (type) {
|
|
37
|
+
case 'primary':
|
|
38
|
+
case 'index':
|
|
39
|
+
case 'unique':
|
|
40
|
+
references = []
|
|
41
|
+
break
|
|
42
|
+
case 'multi':
|
|
43
|
+
if (fields.length < 2) {
|
|
44
|
+
throw new Error('Multi key indicated with less than two fields')
|
|
45
|
+
}
|
|
46
|
+
break
|
|
47
|
+
case 'foreign':
|
|
48
|
+
if (references.length < 1) {
|
|
49
|
+
throw new Error('Foreign key must have one reference to an external record')
|
|
50
|
+
}
|
|
51
|
+
break
|
|
52
|
+
default:
|
|
53
|
+
throw new Error('Unrecognized key type; must be index, primary, unique, multi, or foreign')
|
|
54
|
+
}
|
|
55
|
+
const keyDefinition = {
|
|
56
|
+
type: type,
|
|
57
|
+
fields: fields,
|
|
58
|
+
lookup: lookup
|
|
59
|
+
}
|
|
60
|
+
if (typeof references !== 'undefined' && references.length > 0) {
|
|
61
|
+
keyDefinition['references'] = references.map(keyReference)
|
|
62
|
+
}
|
|
63
|
+
return keyDefinition
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fieldName } from './field'
|
|
2
|
+
import { recordPath } from './record'
|
|
3
|
+
|
|
4
|
+
export type reference = {
|
|
5
|
+
fields: fieldName[];
|
|
6
|
+
lookup: recordPath;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type referenceProperties = {
|
|
10
|
+
fields?: fieldName[];
|
|
11
|
+
lookup?: recordPath;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a reference to a remote (foreign; existing on another record) key.
|
|
16
|
+
* @param properties
|
|
17
|
+
* @param properties.fields
|
|
18
|
+
* @param properties.lookup
|
|
19
|
+
*/
|
|
20
|
+
export const keyReference = ({ fields = [], lookup = '' }: referenceProperties = {}): reference => ({
|
|
21
|
+
fields: fields,
|
|
22
|
+
lookup: lookup
|
|
23
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { field, fieldDefinition, fieldProperties } from './field'
|
|
2
|
+
import { key, keyDefinition, keyProperties } from './key'
|
|
3
|
+
|
|
4
|
+
export type recordPath = string
|
|
5
|
+
|
|
6
|
+
export type entityPath = string
|
|
7
|
+
|
|
8
|
+
export type recordDefinition = {
|
|
9
|
+
path: recordPath
|
|
10
|
+
definition: fieldDefinition[]
|
|
11
|
+
keys: keyDefinition[]
|
|
12
|
+
entries: entityPath[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type recordProperties = {
|
|
16
|
+
path?: recordPath
|
|
17
|
+
definition?: fieldProperties[]
|
|
18
|
+
keys?: keyProperties[]
|
|
19
|
+
entries?: entityPath[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param properties
|
|
25
|
+
* @param properties.path
|
|
26
|
+
* @param properties.definition
|
|
27
|
+
* @param properties.keys
|
|
28
|
+
* @param properties.entries
|
|
29
|
+
*/
|
|
30
|
+
export const record = ({
|
|
31
|
+
path = '',
|
|
32
|
+
definition = [],
|
|
33
|
+
keys = [],
|
|
34
|
+
entries = []
|
|
35
|
+
}: recordProperties = {}): recordDefinition => {
|
|
36
|
+
return {
|
|
37
|
+
path: path,
|
|
38
|
+
definition: definition.map(field),
|
|
39
|
+
keys: keys.map(key),
|
|
40
|
+
entries: entries
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { create } from './create'
|
|
2
|
+
import { describe as describeRecord } from './describe'
|
|
3
|
+
import { testHelpers } from 'js-build-tools/testHelpers'
|
|
4
|
+
|
|
5
|
+
const databasePath = 'describe-database/'
|
|
6
|
+
const gulpConfig = testHelpers.gulpConfig
|
|
7
|
+
gulpConfig.set('databasePath', databasePath)
|
|
8
|
+
testHelpers.setDefaults(databasePath)
|
|
9
|
+
|
|
10
|
+
beforeEach(testHelpers.beforeEach)
|
|
11
|
+
|
|
12
|
+
afterEach(testHelpers.afterEach)
|
|
13
|
+
|
|
14
|
+
const definition = [
|
|
15
|
+
{ name: '_id', type: 'string', optional: false, autoGenerate: true },
|
|
16
|
+
{ name: 'bar', type: 'string', optional: true, autoGenerate: false }
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const keys = [
|
|
20
|
+
{ type: 'primary', fields: ['_id'], lookup: 'pk__id.json' }
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
describe('describe', () => {
|
|
24
|
+
test('describes a record by returning its field definition', async () => {
|
|
25
|
+
await create('foo', definition, keys)
|
|
26
|
+
const result = await describeRecord('foo')
|
|
27
|
+
expect(result).toEqual(definition)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('describes __RECORDS by returning the list of known records', async () => {
|
|
31
|
+
await create('foo', definition, keys)
|
|
32
|
+
await create('bar', definition, keys)
|
|
33
|
+
const result = await describeRecord()
|
|
34
|
+
expect(result).toEqual(['foo.json', 'bar.json'])
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { retrieveFile } from '../utilities/retrieveFile'
|
|
2
|
+
|
|
3
|
+
export const describe = async (record = '__RECORDS') => {
|
|
4
|
+
const recordFile = await retrieveFile(`${record}.json`)
|
|
5
|
+
if (record === '__RECORDS') {
|
|
6
|
+
return recordFile.entries
|
|
7
|
+
}
|
|
8
|
+
return recordFile.definition
|
|
9
|
+
}
|