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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parser=void 0;var _splitQueries=require("../utilities/parsers/splitQueries"),_parseQuery=require("../utilities/parsers/parseQuery");const parser=(e="")=>{const r=(0,_splitQueries.splitQueries)(e),s=[];let t="";for(const e of r){t=t?`${t}${e}`:e;let r={};try{r=(0,_parseQuery.parseQuery)(t),t=""}catch(e){continue}s.push(r)}if(t)throw new Error(`Failed to interpret: ${t}`);return s};exports.parser=parser;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parser=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _splitQueries=require("../utilities/parsers/splitQueries"),_parseQuery=require("../utilities/parsers/parseQuery");const parser=(e="")=>{const r=(0,_splitQueries.splitQueries)(e);return r.map(((e,s)=>{try{return(0,_parseQuery.parseQuery)(e)}catch(t){const i=r.length>1?` query ${s+1} of ${r.length}`:"";throw new Error(`Failed to interpret${i}: ${e} (${t.message})`)}}))};exports.parser=parser;
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Parse a query string (one query, or several separated by `;`) and run each query in turn, resolving to one result
3
+ * per query. The queries of one call run together, under the database lock: no other call's queries run between
4
+ * them (see withDatabaseLock).
5
+ * @param queryString
6
+ */
1
7
  export declare const query: (queryString?: string) => Promise<any[]>;
2
8
  //# sourceMappingURL=query.d.ts.map
@@ -6,13 +6,22 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.query = void 0;
7
7
  var _parser = require("./parser");
8
8
  var _runQuery = require("../utilities/runQuery");
9
+ var _databaseLock = require("../utilities/databaseLock");
10
+ /**
11
+ * Parse a query string (one query, or several separated by `;`) and run each query in turn, resolving to one result
12
+ * per query. The queries of one call run together, under the database lock: no other call's queries run between
13
+ * them (see withDatabaseLock).
14
+ * @param queryString
15
+ */
9
16
  const query = async (queryString = '') => {
10
17
  const parsedQueries = (0, _parser.parser)(queryString);
11
- const queryResults = [];
12
- for (const parsed of parsedQueries) {
13
- const dataSet = await (0, _runQuery.runQuery)(parsed);
14
- queryResults.push(dataSet[parsed.entity]);
15
- }
16
- return queryResults;
18
+ return (0, _databaseLock.withDatabaseLock)(async () => {
19
+ const queryResults = [];
20
+ for (const parsed of parsedQueries) {
21
+ const dataSet = await (0, _runQuery.runQuery)(parsed);
22
+ queryResults.push(dataSet[parsed.entity]);
23
+ }
24
+ return queryResults;
25
+ });
17
26
  };
18
27
  exports.query = query;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.query=void 0;var _parser=require("./parser"),_runQuery=require("../utilities/runQuery");const query=async(r="")=>{const e=(0,_parser.parser)(r),u=[];for(const r of e){const e=await(0,_runQuery.runQuery)(r);u.push(e[r.entity])}return u};exports.query=query;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.query=void 0;var _parser=require("./parser"),_runQuery=require("../utilities/runQuery"),_databaseLock=require("../utilities/databaseLock");const query=async(e="")=>{const r=(0,_parser.parser)(e);return(0,_databaseLock.withDatabaseLock)((async()=>{const e=[];for(const t of r){const r=await(0,_runQuery.runQuery)(t);e.push(r[t.entity])}return e}))};exports.query=query;
@@ -0,0 +1,15 @@
1
+ export type QueryStatus = {
2
+ complete: boolean;
3
+ waitingFor: string;
4
+ };
5
+ /**
6
+ * Whether some query text, typed so far, is ready to run, and if not what it is waiting for: for a prompt which
7
+ * reads a query over several lines (such as the CLI). Uses the same rules as the parser, so a `;` inside a string,
8
+ * a comment or brackets doesn't count, and an open quote, comment or bracket keeps the query going.
9
+ * @example
10
+ * queryStatus("read notes where text = 'it") // { complete: false, waitingFor: "'" }
11
+ * queryStatus('read notes;') // { complete: true, waitingFor: '' }
12
+ * @param text - everything typed so far; join the lines with '\n', since a `--` comment ends at the end of a line
13
+ */
14
+ export declare const queryStatus: (text?: string) => QueryStatus;
15
+ //# sourceMappingURL=queryStatus.d.ts.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.queryStatus = void 0;
7
+ var _scanQuery = require("../utilities/parsers/scanQuery");
8
+ /**
9
+ * Whether some query text, typed so far, is ready to run, and if not what it is waiting for: for a prompt which
10
+ * reads a query over several lines (such as the CLI). Uses the same rules as the parser, so a `;` inside a string,
11
+ * a comment or brackets doesn't count, and an open quote, comment or bracket keeps the query going.
12
+ * @example
13
+ * queryStatus("read notes where text = 'it") // { complete: false, waitingFor: "'" }
14
+ * queryStatus('read notes;') // { complete: true, waitingFor: '' }
15
+ * @param text - everything typed so far; join the lines with '\n', since a `--` comment ends at the end of a line
16
+ */
17
+ const queryStatus = (text = '') => {
18
+ const {
19
+ end,
20
+ closed,
21
+ terminated
22
+ } = (0, _scanQuery.scanQuery)(text);
23
+ if (terminated) {
24
+ return {
25
+ complete: true,
26
+ waitingFor: ''
27
+ };
28
+ }
29
+ if (end.quote) {
30
+ return {
31
+ complete: false,
32
+ waitingFor: end.quote
33
+ };
34
+ }
35
+ if (end.blockComment) {
36
+ return {
37
+ complete: false,
38
+ waitingFor: '/*'
39
+ };
40
+ }
41
+ if (!closed) {
42
+ return {
43
+ complete: false,
44
+ waitingFor: end.brackets[end.brackets.length - 1]
45
+ };
46
+ }
47
+ return {
48
+ complete: false,
49
+ waitingFor: ';'
50
+ };
51
+ };
52
+ exports.queryStatus = queryStatus;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.queryStatus=void 0;var _scanQuery=require("../utilities/parsers/scanQuery");const queryStatus=(e="")=>{const{end:t,closed:r,terminated:o}=(0,_scanQuery.scanQuery)(e);return o?{complete:!0,waitingFor:""}:t.quote?{complete:!1,waitingFor:t.quote}:t.blockComment?{complete:!1,waitingFor:"/*"}:r?{complete:!1,waitingFor:";"}:{complete:!1,waitingFor:t.brackets[t.brackets.length-1]}};exports.queryStatus=queryStatus;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Write a value as a quoted string for a query, so any text can be used in one: the backslash and the quote are
3
+ * escaped, so the parser reads back exactly the text given.
4
+ * @example
5
+ * query(`insert exercises values name = ${quote("Farmer's walk")}`)
6
+ * // insert exercises values name = 'Farmer\'s walk'
7
+ * @param value - the text to quote (anything else is converted with String first)
8
+ * @param quoteChar - the quote to wrap it in
9
+ */
10
+ export declare const quote: (value: any, quoteChar?: "'" | "\"") => string;
11
+ //# sourceMappingURL=quote.d.ts.map
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.quote = void 0;
7
+ /**
8
+ * Write a value as a quoted string for a query, so any text can be used in one: the backslash and the quote are
9
+ * escaped, so the parser reads back exactly the text given.
10
+ * @example
11
+ * query(`insert exercises values name = ${quote("Farmer's walk")}`)
12
+ * // insert exercises values name = 'Farmer\'s walk'
13
+ * @param value - the text to quote (anything else is converted with String first)
14
+ * @param quoteChar - the quote to wrap it in
15
+ */
16
+ const quote = (value, quoteChar = '\'') => `${quoteChar}${String(value).replace(/\\/g, '\\\\').split(quoteChar).join(`\\${quoteChar}`)}${quoteChar}`;
17
+ exports.quote = quote;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.quote=void 0;const quote=(e,t="'")=>`${t}${String(e).replace(/\\/g,"\\\\").split(t).join(`\\${t}`)}${t}`;exports.quote=quote;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Run `show records`: the name of every record in the __RECORDS registry, in the order they were created. A database
3
+ * with no records yet (no registry file) gives an empty list.
4
+ */
5
+ export declare const showRecords: () => Promise<string[]>;
6
+ //# sourceMappingURL=showRecords.d.ts.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.showRecords = void 0;
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.map.js");
9
+ var _retrieveRecord = require("../utilities/retrieveRecord");
10
+ var _recordExists = require("../utilities/recordExists");
11
+ /**
12
+ * Run `show records`: the name of every record in the __RECORDS registry, in the order they were created. A database
13
+ * with no records yet (no registry file) gives an empty list.
14
+ */
15
+ const showRecords = async () => {
16
+ if (!(0, _recordExists.recordExists)('__RECORDS')) {
17
+ return [];
18
+ }
19
+ return (await (0, _retrieveRecord.retrieveRecord)('__RECORDS')).entries.map(fileName => fileName.replace(/\.json$/, ''));
20
+ };
21
+ exports.showRecords = showRecords;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.showRecords=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _retrieveRecord=require("../utilities/retrieveRecord"),_recordExists=require("../utilities/recordExists");const showRecords=async()=>(0,_recordExists.recordExists)("__RECORDS")?(await(0,_retrieveRecord.retrieveRecord)("__RECORDS")).entries.map((e=>e.replace(/\.json$/,""))):[];exports.showRecords=showRecords;
@@ -1,28 +1,28 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sortBy = void 0;
7
- const sortBy = (dataSet = [], sortClauses = []) => {
8
- if (!sortClauses.length) {
9
- return dataSet;
10
- }
11
- dataSet.sort((a, b) => {
12
- for (const sortClause of sortClauses) {
13
- const property = sortClause.property;
14
- const direction = sortClause.direction;
15
- // Ordering compares the raw stored values, not by declared type (that's only for equality, see where), so
16
- // numeric ids in a string field still sort numerically. Loose so '3' and 3 still tie.
17
- // eslint-disable-next-line eqeqeq
18
- if (a[property] == b[property]) {
19
- continue;
20
- }
21
- const result = a[property] < b[property] ? -1 : 1;
22
- return direction === 'asc' ? result : result * -1;
23
- }
24
- return 0;
25
- });
26
- return dataSet;
27
- };
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortBy = void 0;
7
+ const sortBy = (dataSet = [], sortClauses = []) => {
8
+ if (!sortClauses.length) {
9
+ return dataSet;
10
+ }
11
+ dataSet.sort((a, b) => {
12
+ for (const sortClause of sortClauses) {
13
+ const property = sortClause.property;
14
+ const direction = sortClause.direction;
15
+ // Ordering compares the raw stored values, not by declared type (that's only for equality, see where), so
16
+ // numeric ids in a string field still sort numerically. Loose so '3' and 3 still tie.
17
+ // eslint-disable-next-line eqeqeq
18
+ if (a[property] == b[property]) {
19
+ continue;
20
+ }
21
+ const result = a[property] < b[property] ? -1 : 1;
22
+ return direction === 'asc' ? result : result * -1;
23
+ }
24
+ return 0;
25
+ });
26
+ return dataSet;
27
+ };
28
28
  exports.sortBy = sortBy;