json-fs-query 1.1.0 → 2.0.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.
Files changed (113) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +295 -98
  3. package/browser/jsonFsQuery.js +12733 -10934
  4. package/browser/jsonFsQuery.min.js +1 -1
  5. package/dist/data/introspect/create.d.ts +1 -1
  6. package/dist/data/introspect/create.js +35 -4
  7. package/dist/data/introspect/create.min.js +1 -1
  8. package/dist/data/introspect/definitions/field.d.ts +6 -2
  9. package/dist/data/introspect/definitions/field.js +7 -1
  10. package/dist/data/introspect/definitions/field.min.js +1 -1
  11. package/dist/data/introspect/index.d.ts +6 -3
  12. package/dist/data/introspect/index.js +10 -19
  13. package/dist/data/introspect/index.min.js +1 -1
  14. package/dist/data/introspect/policies/foreignKeyExists.js +28 -28
  15. package/dist/data/introspect/policies/hasDependents.js +53 -53
  16. package/dist/data/introspect/policies/keyUnique.js +34 -34
  17. package/dist/data/introspect/policies/typeCheck.d.ts +9 -1
  18. package/dist/data/introspect/policies/typeCheck.js +16 -2
  19. package/dist/data/introspect/policies/typeCheck.min.js +1 -1
  20. package/dist/data/queries/createRecord.d.ts +11 -0
  21. package/dist/data/queries/createRecord.js +58 -0
  22. package/dist/data/queries/createRecord.min.js +1 -0
  23. package/dist/data/queries/deleteEntity.js +100 -100
  24. package/dist/data/queries/describeRecord.d.ts +9 -0
  25. package/dist/data/queries/describeRecord.js +29 -0
  26. package/dist/data/queries/describeRecord.min.js +1 -0
  27. package/dist/data/queries/dropRecord.d.ts +9 -0
  28. package/dist/data/queries/dropRecord.js +61 -0
  29. package/dist/data/queries/dropRecord.min.js +1 -0
  30. package/dist/data/queries/insertEntity.js +122 -117
  31. package/dist/data/queries/insertEntity.min.js +1 -1
  32. package/dist/data/queries/parser.d.ts +1 -1
  33. package/dist/data/queries/parser.js +7 -15
  34. package/dist/data/queries/parser.min.js +1 -1
  35. package/dist/data/queries/query.d.ts +6 -0
  36. package/dist/data/queries/query.js +15 -6
  37. package/dist/data/queries/query.min.js +1 -1
  38. package/dist/data/queries/queryStatus.d.ts +15 -0
  39. package/dist/data/queries/queryStatus.js +52 -0
  40. package/dist/data/queries/queryStatus.min.js +1 -0
  41. package/dist/data/queries/quote.d.ts +11 -0
  42. package/dist/data/queries/quote.js +17 -0
  43. package/dist/data/queries/quote.min.js +1 -0
  44. package/dist/data/queries/showRecords.d.ts +6 -0
  45. package/dist/data/queries/showRecords.js +21 -0
  46. package/dist/data/queries/showRecords.min.js +1 -0
  47. package/dist/data/queries/sortBy.js +27 -27
  48. package/dist/data/queries/updateEntity.js +245 -193
  49. package/dist/data/queries/updateEntity.min.js +1 -1
  50. package/dist/data/queries/where.d.ts +7 -7
  51. package/dist/data/queries/where.js +67 -67
  52. package/dist/data/utilities/compareAs.d.ts +19 -19
  53. package/dist/data/utilities/compareAs.js +57 -57
  54. package/dist/data/utilities/config.d.ts +15 -0
  55. package/dist/data/utilities/config.js +31 -1
  56. package/dist/data/utilities/config.min.js +1 -1
  57. package/dist/data/utilities/databaseLock.d.ts +16 -0
  58. package/dist/data/utilities/databaseLock.js +63 -0
  59. package/dist/data/utilities/databaseLock.min.js +1 -0
  60. package/dist/data/utilities/fieldType.d.ts +15 -15
  61. package/dist/data/utilities/fieldType.js +22 -22
  62. package/dist/data/utilities/getConditionIndexedList.js +47 -47
  63. package/dist/data/utilities/matchIndexedJoins.js +62 -62
  64. package/dist/data/utilities/mergeJoin.js +47 -47
  65. package/dist/data/utilities/parsers/findConditions.d.ts +18 -15
  66. package/dist/data/utilities/parsers/findConditions.js +15 -6
  67. package/dist/data/utilities/parsers/findConditions.min.js +1 -1
  68. package/dist/data/utilities/parsers/findInsertValues.js +3 -2
  69. package/dist/data/utilities/parsers/findInsertValues.min.js +1 -1
  70. package/dist/data/utilities/parsers/findSelects.js +6 -3
  71. package/dist/data/utilities/parsers/findSelects.min.js +1 -1
  72. package/dist/data/utilities/parsers/findSortClauses.js +5 -2
  73. package/dist/data/utilities/parsers/findSortClauses.min.js +1 -1
  74. package/dist/data/utilities/parsers/findUpdateValues.js +3 -2
  75. package/dist/data/utilities/parsers/findUpdateValues.min.js +1 -1
  76. package/dist/data/utilities/parsers/maskStrings.d.ts +39 -0
  77. package/dist/data/utilities/parsers/maskStrings.js +123 -0
  78. package/dist/data/utilities/parsers/maskStrings.min.js +1 -0
  79. package/dist/data/utilities/parsers/parseCreate.d.ts +20 -0
  80. package/dist/data/utilities/parsers/parseCreate.js +330 -0
  81. package/dist/data/utilities/parsers/parseCreate.min.js +1 -0
  82. package/dist/data/utilities/parsers/parseLiteralValue.d.ts +2 -1
  83. package/dist/data/utilities/parsers/parseLiteralValue.js +6 -3
  84. package/dist/data/utilities/parsers/parseLiteralValue.min.js +1 -1
  85. package/dist/data/utilities/parsers/parseQuery.d.ts +3 -0
  86. package/dist/data/utilities/parsers/parseQuery.js +28 -2
  87. package/dist/data/utilities/parsers/parseQuery.min.js +1 -1
  88. package/dist/data/utilities/parsers/parseSchemaStatement.d.ts +13 -0
  89. package/dist/data/utilities/parsers/parseSchemaStatement.js +82 -0
  90. package/dist/data/utilities/parsers/parseSchemaStatement.min.js +1 -0
  91. package/dist/data/utilities/parsers/scanQuery.d.ts +52 -0
  92. package/dist/data/utilities/parsers/scanQuery.js +158 -0
  93. package/dist/data/utilities/parsers/scanQuery.min.js +1 -0
  94. package/dist/data/utilities/parsers/splitQueries.d.ts +6 -0
  95. package/dist/data/utilities/parsers/splitQueries.js +20 -2
  96. package/dist/data/utilities/parsers/splitQueries.min.js +1 -1
  97. package/dist/data/utilities/parsers/startsQuery.d.ts +5 -0
  98. package/dist/data/utilities/parsers/startsQuery.js +10 -0
  99. package/dist/data/utilities/parsers/startsQuery.min.js +1 -0
  100. package/dist/data/utilities/recordExists.d.ts +6 -0
  101. package/dist/data/utilities/recordExists.js +18 -0
  102. package/dist/data/utilities/recordExists.min.js +1 -0
  103. package/dist/data/utilities/removeFromIndex.d.ts +14 -14
  104. package/dist/data/utilities/removeFromIndex.js +45 -45
  105. package/dist/data/utilities/runQuery.js +135 -112
  106. package/dist/data/utilities/runQuery.min.js +1 -1
  107. package/dist/data/utilities/updateIndex.d.ts +17 -17
  108. package/dist/data/utilities/updateIndex.js +57 -57
  109. package/dist/data/utilities/useJoinClause.js +56 -56
  110. package/dist/index.d.ts +2 -0
  111. package/dist/index.js +14 -0
  112. package/dist/index.min.js +1 -1
  113. package/package.json +68 -60
@@ -1,20 +1,20 @@
1
- /**
2
- * Normalize a value to a field's declared type for an equality comparison - never written back,
3
- * only compared. Writes are coerced to the declared type (typeCheck), but values already stored
4
- * may not match it (ids declared string, so they can hold an integer or a UUID, are often stored
5
- * as numbers), and query literals carry their own type. A declared type is what says '3' and 3
6
- * are the same value. A missing or unrecognized type returns the value unchanged.
7
- * @param type
8
- * @param value
9
- */
10
- export declare const compareAs: (type: string | undefined, value: any) => any;
11
- /**
12
- * Whether two values are equal for a field of the given declared type: both are normalized to
13
- * that type (see compareAs) and compared strictly. A field with no declared type, or one that
14
- * can't be normalized (object, array, or an unrecognized type), keeps loose equality.
15
- * @param type
16
- * @param a
17
- * @param b
18
- */
19
- export declare const sameValue: (type: string | undefined, a: any, b: any) => boolean;
1
+ /**
2
+ * Normalize a value to a field's declared type for an equality comparison - never written back,
3
+ * only compared. Writes are coerced to the declared type (typeCheck), but values already stored
4
+ * may not match it (ids declared string, so they can hold an integer or a UUID, are often stored
5
+ * as numbers), and query literals carry their own type. A declared type is what says '3' and 3
6
+ * are the same value. A missing or unrecognized type returns the value unchanged.
7
+ * @param type
8
+ * @param value
9
+ */
10
+ export declare const compareAs: (type: string | undefined, value: any) => any;
11
+ /**
12
+ * Whether two values are equal for a field of the given declared type: both are normalized to
13
+ * that type (see compareAs) and compared strictly. A field with no declared type, or one that
14
+ * can't be normalized (object, array, or an unrecognized type), keeps loose equality.
15
+ * @param type
16
+ * @param a
17
+ * @param b
18
+ */
19
+ export declare const sameValue: (type: string | undefined, a: any, b: any) => boolean;
20
20
  //# sourceMappingURL=compareAs.d.ts.map
@@ -1,58 +1,58 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sameValue = exports.compareAs = void 0;
7
- require("core-js/modules/es.array.includes.js");
8
- /**
9
- * Normalize a value to a field's declared type for an equality comparison - never written back,
10
- * only compared. Writes are coerced to the declared type (typeCheck), but values already stored
11
- * may not match it (ids declared string, so they can hold an integer or a UUID, are often stored
12
- * as numbers), and query literals carry their own type. A declared type is what says '3' and 3
13
- * are the same value. A missing or unrecognized type returns the value unchanged.
14
- * @param type
15
- * @param value
16
- */
17
- const compareAs = (type, value) => {
18
- if (value === null || typeof value === 'undefined') {
19
- return value;
20
- }
21
- switch (type) {
22
- case 'string':
23
- return typeof value === 'object' ? value : String(value);
24
- case 'int':
25
- {
26
- const coerced = Number(value);
27
- return Number.isNaN(coerced) ? value : coerced;
28
- }
29
- case 'boolean':
30
- if (value === 'true') {
31
- return true;
32
- }
33
- if (value === 'false') {
34
- return false;
35
- }
36
- return value;
37
- default:
38
- return value;
39
- }
40
- };
41
- exports.compareAs = compareAs;
42
- const comparableTypes = ['string', 'int', 'boolean'];
43
- /**
44
- * Whether two values are equal for a field of the given declared type: both are normalized to
45
- * that type (see compareAs) and compared strictly. A field with no declared type, or one that
46
- * can't be normalized (object, array, or an unrecognized type), keeps loose equality.
47
- * @param type
48
- * @param a
49
- * @param b
50
- */
51
- const sameValue = (type, a, b) => {
52
- if (!comparableTypes.includes(type)) {
53
- // eslint-disable-next-line eqeqeq
54
- return a == b;
55
- }
56
- return compareAs(type, a) === compareAs(type, b);
57
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sameValue = exports.compareAs = void 0;
7
+ require("core-js/modules/es.array.includes.js");
8
+ /**
9
+ * Normalize a value to a field's declared type for an equality comparison - never written back,
10
+ * only compared. Writes are coerced to the declared type (typeCheck), but values already stored
11
+ * may not match it (ids declared string, so they can hold an integer or a UUID, are often stored
12
+ * as numbers), and query literals carry their own type. A declared type is what says '3' and 3
13
+ * are the same value. A missing or unrecognized type returns the value unchanged.
14
+ * @param type
15
+ * @param value
16
+ */
17
+ const compareAs = (type, value) => {
18
+ if (value === null || typeof value === 'undefined') {
19
+ return value;
20
+ }
21
+ switch (type) {
22
+ case 'string':
23
+ return typeof value === 'object' ? value : String(value);
24
+ case 'int':
25
+ {
26
+ const coerced = Number(value);
27
+ return Number.isNaN(coerced) ? value : coerced;
28
+ }
29
+ case 'boolean':
30
+ if (value === 'true') {
31
+ return true;
32
+ }
33
+ if (value === 'false') {
34
+ return false;
35
+ }
36
+ return value;
37
+ default:
38
+ return value;
39
+ }
40
+ };
41
+ exports.compareAs = compareAs;
42
+ const comparableTypes = ['string', 'int', 'boolean'];
43
+ /**
44
+ * Whether two values are equal for a field of the given declared type: both are normalized to
45
+ * that type (see compareAs) and compared strictly. A field with no declared type, or one that
46
+ * can't be normalized (object, array, or an unrecognized type), keeps loose equality.
47
+ * @param type
48
+ * @param a
49
+ * @param b
50
+ */
51
+ const sameValue = (type, a, b) => {
52
+ if (!comparableTypes.includes(type)) {
53
+ // eslint-disable-next-line eqeqeq
54
+ return a == b;
55
+ }
56
+ return compareAs(type, a) === compareAs(type, b);
57
+ };
58
58
  exports.sameValue = sameValue;
@@ -3,6 +3,18 @@ export type RuntimeSettings = {
3
3
  relativePath: string;
4
4
  enforceForeignKeys: boolean;
5
5
  };
6
+ /**
7
+ * The folder a databasePath points to, so that `database/`, `./database` and its absolute path count as one database.
8
+ * Node only (only Node calls are counted, see trackDatabaseCall).
9
+ * @param databasePath
10
+ */
11
+ export declare const resolveDatabasePath: (databasePath: string) => string;
12
+ /**
13
+ * Count a database call (taken by withDatabaseLock as soon as a call is queued) until the returned function is called.
14
+ * While any call is counted, configure() refuses to point databasePath somewhere else: every step of a call reads
15
+ * databasePath again, so a change halfway would write part of the call to one folder and the rest to another.
16
+ */
17
+ export declare const trackDatabaseCall: () => (() => void);
6
18
  /**
7
19
  * Set where this package's data lives: databasePath (a filesystem path, used in Node) and/or
8
20
  * relativePath (a URL prefix prepended to databasePath, used when reading over fetch() in a
@@ -13,7 +25,10 @@ export type RuntimeSettings = {
13
25
  * that would leave another record's foreign key pointing at a value that no longer exists -
14
26
  * mirroring MySQL's own foreign_key_checks setting, which is also toggleable rather than always
15
27
  * on, since strict enforcement isn't always what every consumer wants.
28
+ *
29
+ * Changing databasePath while calls are still running or queued throws (see trackDatabaseCall): await them first.
16
30
  * @param newSettings
31
+ * @throws {Error} When databasePath would point to another folder while database calls are in progress.
17
32
  */
18
33
  export declare const configure: (newSettings: Partial<RuntimeSettings>) => void;
19
34
  /**
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSetting = exports.configure = void 0;
6
+ exports.trackDatabaseCall = exports.resolveDatabasePath = exports.getSetting = exports.configure = void 0;
7
7
  const defaults = {
8
8
  databasePath: 'database/',
9
9
  relativePath: '',
@@ -12,6 +12,29 @@ const defaults = {
12
12
  let settings = {
13
13
  ...defaults
14
14
  };
15
+ let activeCalls = 0;
16
+ /**
17
+ * The folder a databasePath points to, so that `database/`, `./database` and its absolute path count as one database.
18
+ * Node only (only Node calls are counted, see trackDatabaseCall).
19
+ * @param databasePath
20
+ */
21
+ const resolveDatabasePath = databasePath => require('path').resolve(databasePath);
22
+ /**
23
+ * Count a database call (taken by withDatabaseLock as soon as a call is queued) until the returned function is called.
24
+ * While any call is counted, configure() refuses to point databasePath somewhere else: every step of a call reads
25
+ * databasePath again, so a change halfway would write part of the call to one folder and the rest to another.
26
+ */
27
+ exports.resolveDatabasePath = resolveDatabasePath;
28
+ const trackDatabaseCall = () => {
29
+ activeCalls++;
30
+ let ended = false;
31
+ return () => {
32
+ if (!ended) {
33
+ ended = true;
34
+ activeCalls--;
35
+ }
36
+ };
37
+ };
15
38
  /**
16
39
  * Set where this package's data lives: databasePath (a filesystem path, used in Node) and/or
17
40
  * relativePath (a URL prefix prepended to databasePath, used when reading over fetch() in a
@@ -22,9 +45,16 @@ let settings = {
22
45
  * that would leave another record's foreign key pointing at a value that no longer exists -
23
46
  * mirroring MySQL's own foreign_key_checks setting, which is also toggleable rather than always
24
47
  * on, since strict enforcement isn't always what every consumer wants.
48
+ *
49
+ * Changing databasePath while calls are still running or queued throws (see trackDatabaseCall): await them first.
25
50
  * @param newSettings
51
+ * @throws {Error} When databasePath would point to another folder while database calls are in progress.
26
52
  */
53
+ exports.trackDatabaseCall = trackDatabaseCall;
27
54
  const configure = newSettings => {
55
+ if (activeCalls > 0 && typeof newSettings.databasePath !== 'undefined' && resolveDatabasePath(newSettings.databasePath) !== resolveDatabasePath(settings.databasePath)) {
56
+ throw new Error(`Can't change databasePath while ${activeCalls} database call(s) are still running or queued: await them first`);
57
+ }
28
58
  settings = {
29
59
  ...settings,
30
60
  ...newSettings
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getSetting=exports.configure=void 0;const defaults={databasePath:"database/",relativePath:"",enforceForeignKeys:!0};let settings={...defaults};const configure=t=>{settings={...settings,...t}};exports.configure=configure;const getSetting=(t,e)=>void 0!==settings[t]?settings[t]:e;exports.getSetting=getSetting;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.trackDatabaseCall=exports.resolveDatabasePath=exports.getSetting=exports.configure=void 0;const defaults={databasePath:"database/",relativePath:"",enforceForeignKeys:!0};let settings={...defaults},activeCalls=0;const resolveDatabasePath=t=>require("path").resolve(t);exports.resolveDatabasePath=resolveDatabasePath;const trackDatabaseCall=()=>{activeCalls++;let t=!1;return()=>{t||(t=!0,activeCalls--)}};exports.trackDatabaseCall=trackDatabaseCall;const configure=t=>{if(activeCalls>0&&void 0!==t.databasePath&&resolveDatabasePath(t.databasePath)!==resolveDatabasePath(settings.databasePath))throw new Error(`Can't change databasePath while ${activeCalls} database call(s) are still running or queued: await them first`);settings={...settings,...t}};exports.configure=configure;const getSetting=(t,a)=>void 0!==settings[t]?settings[t]:a;exports.getSetting=getSetting;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Run `task` once every earlier task on the same database (the configured databasePath) has finished, so that calls
3
+ * never interleave. Every write is several files in turn (an entry, the record's entry list, each index), each read and
4
+ * rewritten whole, so two writes running at once overwrite each other's changes: ten parallel inserts used to leave
5
+ * nine of the rows unreadable, and two parallel inserts of one unique value both succeeded. Reads take their turn too,
6
+ * so a read never sees a write half done. A task that throws still lets the next one run.
7
+ *
8
+ * Only the public functions (query, create, drop, describe) take the lock; what they call inside doesn't take it
9
+ * again, so it can't deadlock. In the browser nothing can be written, so tasks just run.
10
+ *
11
+ * The queue is per folder (`database/` and `./database` share one). Every step of a task reads databasePath when it
12
+ * runs, so configure() refuses to change it while tasks are queued or running (see trackDatabaseCall).
13
+ * @param task
14
+ */
15
+ export declare const withDatabaseLock: <T>(task: () => Promise<T>) => Promise<T>;
16
+ //# sourceMappingURL=databaseLock.d.ts.map
@@ -0,0 +1,63 @@
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.withDatabaseLock = void 0;
8
+ require("core-js/modules/esnext.map.delete-all.js");
9
+ require("core-js/modules/esnext.map.every.js");
10
+ require("core-js/modules/esnext.map.filter.js");
11
+ require("core-js/modules/esnext.map.find.js");
12
+ require("core-js/modules/esnext.map.find-key.js");
13
+ require("core-js/modules/esnext.map.includes.js");
14
+ require("core-js/modules/esnext.map.key-of.js");
15
+ require("core-js/modules/esnext.map.map-keys.js");
16
+ require("core-js/modules/esnext.map.map-values.js");
17
+ require("core-js/modules/esnext.map.merge.js");
18
+ require("core-js/modules/esnext.map.reduce.js");
19
+ require("core-js/modules/esnext.map.some.js");
20
+ require("core-js/modules/esnext.map.update.js");
21
+ var jsEnv = _interopRequireWildcard(require("browser-or-node"));
22
+ var _config = require("./config");
23
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.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); }
24
+ const queues = new Map();
25
+ /**
26
+ * Run `task` once every earlier task on the same database (the configured databasePath) has finished, so that calls
27
+ * never interleave. Every write is several files in turn (an entry, the record's entry list, each index), each read and
28
+ * rewritten whole, so two writes running at once overwrite each other's changes: ten parallel inserts used to leave
29
+ * nine of the rows unreadable, and two parallel inserts of one unique value both succeeded. Reads take their turn too,
30
+ * so a read never sees a write half done. A task that throws still lets the next one run.
31
+ *
32
+ * Only the public functions (query, create, drop, describe) take the lock; what they call inside doesn't take it
33
+ * again, so it can't deadlock. In the browser nothing can be written, so tasks just run.
34
+ *
35
+ * The queue is per folder (`database/` and `./database` share one). Every step of a task reads databasePath when it
36
+ * runs, so configure() refuses to change it while tasks are queued or running (see trackDatabaseCall).
37
+ * @param task
38
+ */
39
+ const withDatabaseLock = async task => {
40
+ if (!jsEnv.isNode) {
41
+ return task();
42
+ }
43
+ const database = (0, _config.resolveDatabasePath)((0, _config.getSetting)('databasePath', 'database/'));
44
+ const ended = (0, _config.trackDatabaseCall)();
45
+ const previous = queues.get(database) || Promise.resolve();
46
+ let release;
47
+ const turn = new Promise(resolve => {
48
+ release = resolve;
49
+ });
50
+ const queued = previous.then(() => turn);
51
+ queues.set(database, queued);
52
+ await previous;
53
+ try {
54
+ return await task();
55
+ } finally {
56
+ ended();
57
+ release();
58
+ if (queues.get(database) === queued) {
59
+ queues.delete(database);
60
+ }
61
+ }
62
+ };
63
+ exports.withDatabaseLock = withDatabaseLock;
@@ -0,0 +1 @@
1
+ "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.withDatabaseLock=void 0,require("core-js/modules/esnext.map.delete-all.js"),require("core-js/modules/esnext.map.every.js"),require("core-js/modules/esnext.map.filter.js"),require("core-js/modules/esnext.map.find.js"),require("core-js/modules/esnext.map.find-key.js"),require("core-js/modules/esnext.map.includes.js"),require("core-js/modules/esnext.map.key-of.js"),require("core-js/modules/esnext.map.map-keys.js"),require("core-js/modules/esnext.map.map-values.js"),require("core-js/modules/esnext.map.merge.js"),require("core-js/modules/esnext.map.reduce.js"),require("core-js/modules/esnext.map.some.js"),require("core-js/modules/esnext.map.update.js");var jsEnv=_interopRequireWildcard(require("browser-or-node")),_config=require("./config");function _interopRequireWildcard(e,r){if("function"==typeof WeakMap)var s=new WeakMap,t=new WeakMap;return(_interopRequireWildcard=function(e,r){if(!r&&e&&e.__esModule)return e;var o,a,u={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return u;if(o=r?t:s){if(o.has(e))return o.get(e);o.set(e,u)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?o(u,r,a):u[r]=e[r]);return u})(e,r)}const queues=new Map,withDatabaseLock=async e=>{if(!jsEnv.isNode)return e();const r=(0,_config.resolveDatabasePath)((0,_config.getSetting)("databasePath","database/")),s=(0,_config.trackDatabaseCall)(),t=queues.get(r)||Promise.resolve();let o;const a=new Promise((e=>{o=e})),u=t.then((()=>a));queues.set(r,u),await t;try{return await e()}finally{s(),o(),queues.get(r)===u&&queues.delete(r)}};exports.withDatabaseLock=withDatabaseLock;
@@ -1,16 +1,16 @@
1
- import { recordDefinition } from '../introspect/definitions/record';
2
- import { keyDefinition } from '../introspect/definitions/key';
3
- /**
4
- * The declared type of one of a record's fields, or undefined when the record or field is unknown.
5
- * @param record
6
- * @param property
7
- */
8
- export declare const fieldType: (record: recordDefinition | undefined, property: string) => string | undefined;
9
- /**
10
- * The declared type of the value a key indexes: its field's type for a single-field key. A
11
- * multi-field key's value is a composite (see computeKeyValue), so it has no single declared type.
12
- * @param record
13
- * @param key
14
- */
15
- export declare const keyValueType: (record: recordDefinition | undefined, key: keyDefinition) => string | undefined;
1
+ import { recordDefinition } from '../introspect/definitions/record';
2
+ import { keyDefinition } from '../introspect/definitions/key';
3
+ /**
4
+ * The declared type of one of a record's fields, or undefined when the record or field is unknown.
5
+ * @param record
6
+ * @param property
7
+ */
8
+ export declare const fieldType: (record: recordDefinition | undefined, property: string) => string | undefined;
9
+ /**
10
+ * The declared type of the value a key indexes: its field's type for a single-field key. A
11
+ * multi-field key's value is a composite (see computeKeyValue), so it has no single declared type.
12
+ * @param record
13
+ * @param key
14
+ */
15
+ export declare const keyValueType: (record: recordDefinition | undefined, key: keyDefinition) => string | undefined;
16
16
  //# sourceMappingURL=fieldType.d.ts.map
@@ -1,23 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keyValueType = exports.fieldType = void 0;
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.find.js");
9
- /**
10
- * The declared type of one of a record's fields, or undefined when the record or field is unknown.
11
- * @param record
12
- * @param property
13
- */
14
- const fieldType = (record, property) => record?.definition?.find(field => field.name === property)?.type;
15
- /**
16
- * The declared type of the value a key indexes: its field's type for a single-field key. A
17
- * multi-field key's value is a composite (see computeKeyValue), so it has no single declared type.
18
- * @param record
19
- * @param key
20
- */
21
- exports.fieldType = fieldType;
22
- const keyValueType = (record, key) => key.fields.length === 1 ? fieldType(record, key.fields[0]) : undefined;
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.keyValueType = exports.fieldType = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.find.js");
9
+ /**
10
+ * The declared type of one of a record's fields, or undefined when the record or field is unknown.
11
+ * @param record
12
+ * @param property
13
+ */
14
+ const fieldType = (record, property) => record?.definition?.find(field => field.name === property)?.type;
15
+ /**
16
+ * The declared type of the value a key indexes: its field's type for a single-field key. A
17
+ * multi-field key's value is a composite (see computeKeyValue), so it has no single declared type.
18
+ * @param record
19
+ * @param key
20
+ */
21
+ exports.fieldType = fieldType;
22
+ const keyValueType = (record, key) => key.fields.length === 1 ? fieldType(record, key.fields[0]) : undefined;
23
23
  exports.keyValueType = keyValueType;
@@ -1,48 +1,48 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getConditionIndexedList = void 0;
7
- var _isEntityProperty = require("./parsers/isEntityProperty");
8
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
9
- var _retrieveRecord = require("./retrieveRecord");
10
- var _where = require("../queries/where");
11
- var _retrieveFile = require("./retrieveFile");
12
- var _getMatchingIndexes = require("./getMatchingIndexes");
13
- const getConditionIndexedList = async (parsed, recordData, dataSet) => {
14
- const reducedConditions = [];
15
- for (const condition of parsed.conditions) {
16
- let entity = parsed.entity;
17
- let property = condition.property;
18
- if ((0, _isEntityProperty.isEntityProperty)(property)) {
19
- const entityProperty = (0, _splitEntityProperty.splitEntityProperty)(property);
20
- entity = entityProperty.entity;
21
- property = entityProperty.property;
22
- }
23
- if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
24
- recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
25
- }
26
- const indexed = {};
27
- const retrieveMatchedFiles = async (entity, property, recordData, condition, dataSet, indexed) => {
28
- const matchedRecords = (0, _where.where)(indexed[entity][property], {
29
- property: 'value',
30
- comparator: condition.comparator,
31
- value: condition.value,
32
- type: condition.type
33
- });
34
- for (const matchedRecord of matchedRecords) {
35
- for (const file of matchedRecord.record) {
36
- dataSet[entity].push(await (0, _retrieveFile.retrieveFile)(`${entity}/${file}`));
37
- }
38
- }
39
- };
40
- const isIndexed = await (0, _getMatchingIndexes.getMatchingIndexes)(entity, property, recordData, condition, dataSet, indexed, retrieveMatchedFiles);
41
- if (!isIndexed) {
42
- reducedConditions.push(condition);
43
- }
44
- }
45
- parsed.conditions = reducedConditions;
46
- return parsed;
47
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getConditionIndexedList = void 0;
7
+ var _isEntityProperty = require("./parsers/isEntityProperty");
8
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
9
+ var _retrieveRecord = require("./retrieveRecord");
10
+ var _where = require("../queries/where");
11
+ var _retrieveFile = require("./retrieveFile");
12
+ var _getMatchingIndexes = require("./getMatchingIndexes");
13
+ const getConditionIndexedList = async (parsed, recordData, dataSet) => {
14
+ const reducedConditions = [];
15
+ for (const condition of parsed.conditions) {
16
+ let entity = parsed.entity;
17
+ let property = condition.property;
18
+ if ((0, _isEntityProperty.isEntityProperty)(property)) {
19
+ const entityProperty = (0, _splitEntityProperty.splitEntityProperty)(property);
20
+ entity = entityProperty.entity;
21
+ property = entityProperty.property;
22
+ }
23
+ if (!Object.prototype.hasOwnProperty.call(recordData, entity)) {
24
+ recordData[entity] = await (0, _retrieveRecord.retrieveRecord)(entity);
25
+ }
26
+ const indexed = {};
27
+ const retrieveMatchedFiles = async (entity, property, recordData, condition, dataSet, indexed) => {
28
+ const matchedRecords = (0, _where.where)(indexed[entity][property], {
29
+ property: 'value',
30
+ comparator: condition.comparator,
31
+ value: condition.value,
32
+ type: condition.type
33
+ });
34
+ for (const matchedRecord of matchedRecords) {
35
+ for (const file of matchedRecord.record) {
36
+ dataSet[entity].push(await (0, _retrieveFile.retrieveFile)(`${entity}/${file}`));
37
+ }
38
+ }
39
+ };
40
+ const isIndexed = await (0, _getMatchingIndexes.getMatchingIndexes)(entity, property, recordData, condition, dataSet, indexed, retrieveMatchedFiles);
41
+ if (!isIndexed) {
42
+ reducedConditions.push(condition);
43
+ }
44
+ }
45
+ parsed.conditions = reducedConditions;
46
+ return parsed;
47
+ };
48
48
  exports.getConditionIndexedList = getConditionIndexedList;
@@ -1,63 +1,63 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.matchIndexedJoins = void 0;
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.reduce.js");
9
- var _siFunciona = _interopRequireDefault(require("si-funciona"));
10
- var _where = require("../queries/where");
11
- var _retrieveFile = require("./retrieveFile");
12
- var _splitEntityProperty = require("./parsers/splitEntityProperty");
13
- var _fieldType = require("./fieldType");
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity, property, recordData, joinClause, filterJoins, indexed) => {
16
- const {
17
- entity: entityA,
18
- property: propertyA
19
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
20
- const {
21
- entity: entityB,
22
- property: propertyB
23
- } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
24
- const properties = [{
25
- entityFirst: entityA,
26
- propertyFirst: propertyA,
27
- entitySecond: entityB,
28
- propertySecond: propertyB
29
- }, {
30
- entityFirst: entityB,
31
- propertyFirst: propertyB,
32
- entitySecond: entityA,
33
- propertySecond: propertyA
34
- }];
35
- for (const checkProp of properties) {
36
- if (!Object.prototype.hasOwnProperty.call(indexedClone, checkProp.entitySecond)) {
37
- indexedClone[checkProp.entitySecond] = _siFunciona.default.cloneObject(indexed[checkProp.entitySecond]);
38
- }
39
- const matchedRecords = indexedClone[checkProp.entitySecond][checkProp.propertySecond].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(indexedClone[checkProp.entityFirst][checkProp.propertyFirst], {
40
- property: 'value',
41
- comparator: joinClause.comparator,
42
- value: dataB.value,
43
- type: (0, _fieldType.fieldType)(recordData[checkProp.entityFirst], checkProp.propertyFirst)
44
- })), []);
45
- const skipPush = checkProp.entityFirst === entity;
46
- if (!Object.prototype.hasOwnProperty.call(dataSets, checkProp.entityFirst)) {
47
- dataSets[checkProp.entityFirst] = [];
48
- }
49
- for (const matchedRecord of matchedRecords) {
50
- for (const file of matchedRecord.record) {
51
- let entityRecord = file;
52
- if (typeof file === 'string') {
53
- entityRecord = await (0, _retrieveFile.retrieveFile)(`${checkProp.entityFirst}/${file}`);
54
- }
55
- if (!skipPush) {
56
- dataSets[checkProp.entityFirst].push(entityRecord);
57
- }
58
- filterJoins[checkProp.entityFirst].push(entityRecord);
59
- }
60
- }
61
- }
62
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.matchIndexedJoins = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.reduce.js");
9
+ var _siFunciona = _interopRequireDefault(require("si-funciona"));
10
+ var _where = require("../queries/where");
11
+ var _retrieveFile = require("./retrieveFile");
12
+ var _splitEntityProperty = require("./parsers/splitEntityProperty");
13
+ var _fieldType = require("./fieldType");
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ const matchIndexedJoins = (entity, indexedClone, dataSets) => async (focusEntity, property, recordData, joinClause, filterJoins, indexed) => {
16
+ const {
17
+ entity: entityA,
18
+ property: propertyA
19
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyA);
20
+ const {
21
+ entity: entityB,
22
+ property: propertyB
23
+ } = (0, _splitEntityProperty.splitEntityProperty)(joinClause.propertyB);
24
+ const properties = [{
25
+ entityFirst: entityA,
26
+ propertyFirst: propertyA,
27
+ entitySecond: entityB,
28
+ propertySecond: propertyB
29
+ }, {
30
+ entityFirst: entityB,
31
+ propertyFirst: propertyB,
32
+ entitySecond: entityA,
33
+ propertySecond: propertyA
34
+ }];
35
+ for (const checkProp of properties) {
36
+ if (!Object.prototype.hasOwnProperty.call(indexedClone, checkProp.entitySecond)) {
37
+ indexedClone[checkProp.entitySecond] = _siFunciona.default.cloneObject(indexed[checkProp.entitySecond]);
38
+ }
39
+ const matchedRecords = indexedClone[checkProp.entitySecond][checkProp.propertySecond].reduce((dataA, dataB) => _siFunciona.default.mergeArrays(dataA, (0, _where.where)(indexedClone[checkProp.entityFirst][checkProp.propertyFirst], {
40
+ property: 'value',
41
+ comparator: joinClause.comparator,
42
+ value: dataB.value,
43
+ type: (0, _fieldType.fieldType)(recordData[checkProp.entityFirst], checkProp.propertyFirst)
44
+ })), []);
45
+ const skipPush = checkProp.entityFirst === entity;
46
+ if (!Object.prototype.hasOwnProperty.call(dataSets, checkProp.entityFirst)) {
47
+ dataSets[checkProp.entityFirst] = [];
48
+ }
49
+ for (const matchedRecord of matchedRecords) {
50
+ for (const file of matchedRecord.record) {
51
+ let entityRecord = file;
52
+ if (typeof file === 'string') {
53
+ entityRecord = await (0, _retrieveFile.retrieveFile)(`${checkProp.entityFirst}/${file}`);
54
+ }
55
+ if (!skipPush) {
56
+ dataSets[checkProp.entityFirst].push(entityRecord);
57
+ }
58
+ filterJoins[checkProp.entityFirst].push(entityRecord);
59
+ }
60
+ }
61
+ }
62
+ };
63
63
  exports.matchIndexedJoins = matchIndexedJoins;