json-fs-query 2.0.0 → 2.1.1

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 (38) hide show
  1. package/README.md +32 -1
  2. package/browser/jsonFsQuery.js +641 -394
  3. package/browser/jsonFsQuery.min.js +1 -1
  4. package/dist/data/introspect/policies/typeCheck.js +4 -0
  5. package/dist/data/introspect/policies/typeCheck.min.js +1 -1
  6. package/dist/data/queries/sortBy.js +14 -1
  7. package/dist/data/queries/sortBy.min.js +1 -1
  8. package/dist/data/queries/where.js +20 -2
  9. package/dist/data/queries/where.min.js +1 -1
  10. package/dist/data/utilities/getConditionIndexedList.d.ts +13 -1
  11. package/dist/data/utilities/getConditionIndexedList.js +46 -11
  12. package/dist/data/utilities/getConditionIndexedList.min.js +1 -1
  13. package/dist/data/utilities/getMatchingIndexes.js +2 -2
  14. package/dist/data/utilities/getMatchingIndexes.min.js +1 -1
  15. package/dist/data/utilities/isSingleFieldKey.d.ts +10 -0
  16. package/dist/data/utilities/isSingleFieldKey.js +15 -0
  17. package/dist/data/utilities/isSingleFieldKey.min.js +1 -0
  18. package/dist/data/utilities/parsers/findConditions.d.ts +4 -3
  19. package/dist/data/utilities/parsers/findConditions.js +26 -9
  20. package/dist/data/utilities/parsers/findConditions.min.js +1 -1
  21. package/dist/data/utilities/parsers/findInsertValues.js +2 -2
  22. package/dist/data/utilities/parsers/findInsertValues.min.js +1 -1
  23. package/dist/data/utilities/parsers/findJoinEntity.js +3 -1
  24. package/dist/data/utilities/parsers/findJoinEntity.min.js +1 -1
  25. package/dist/data/utilities/parsers/findUpdateValues.js +2 -2
  26. package/dist/data/utilities/parsers/findUpdateValues.min.js +1 -1
  27. package/dist/data/utilities/parsers/maskStrings.js +5 -1
  28. package/dist/data/utilities/parsers/maskStrings.min.js +1 -1
  29. package/dist/data/utilities/parsers/parseCreate.js +4 -2
  30. package/dist/data/utilities/parsers/parseCreate.min.js +1 -1
  31. package/dist/data/utilities/parsers/parseLiteralValue.d.ts +16 -0
  32. package/dist/data/utilities/parsers/parseLiteralValue.js +28 -2
  33. package/dist/data/utilities/parsers/parseLiteralValue.min.js +1 -1
  34. package/dist/data/utilities/retrieveIndexes.js +2 -2
  35. package/dist/data/utilities/retrieveIndexes.min.js +1 -1
  36. package/dist/data/utilities/runQuery.js +28 -11
  37. package/dist/data/utilities/runQuery.min.js +1 -1
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -101,6 +101,19 @@ await query(`read exercises where name = ${quote(name)}`)
101
101
 
102
102
  `quote(value, '"')` wraps in double quotes instead.
103
103
 
104
+ ### Numbers
105
+
106
+ A number may be negative, have a fraction and an exponent: `12`, `-3`, `1.5`, `2.5e-4`. They work the same in
107
+ `values`, `set`, `where`, arrays and defaults:
108
+
109
+ ```sql
110
+ read workouts where reps > -1
111
+ update workouts set weight = 102.5 where _id = 4
112
+ ```
113
+
114
+ A whole number past 9007199254740991 (`Number.MAX_SAFE_INTEGER`), however it is written (`1e20`,
115
+ `9007199254740993.0`), is an error rather than being stored rounded: quote it to keep it as text. A fraction is stored as the nearest double, as in JSON.
116
+
104
117
  ### Arrays
105
118
 
106
119
  Arrays are JSON-style, and their strings can use either quote. They can be nested, and are used by `in` and
@@ -135,6 +148,24 @@ read workouts where reps > 8 and where date = '2024-06-02'
135
148
  `or where` is not supported yet, and is an error (in 1.x it was silently read as `and where`). And/or with grouping
136
149
  and precedence is planned.
137
150
 
151
+ ### Null and missing fields
152
+
153
+ A field can be missing (left out) or hold `null`, and both are their own cases, as in SQL: they match no
154
+ comparison (`=`, `!=`, `<`, `between`, `in`, `like`...), and a `null` never equals anything, not even another
155
+ `null`. These test for them instead:
156
+
157
+ | Condition | Matches when the field |
158
+ |---|---|
159
+ | `where note is null` | is there and holds `null` |
160
+ | `where note is not null` | is there and holds a value |
161
+ | `where note exists` | is there (`null` counts) |
162
+ | `where note does not exist` | is missing |
163
+
164
+ `where note = null` is an error that points to `is null`, since it could never match. Sorting puts missing first,
165
+ then `null`, then the values (`asc`; `desc` is the reverse).
166
+
167
+ In 2.0 and earlier, a `null` acted as `0` in comparisons and sorting (`where n < 5` matched it), and `= null` matched it.
168
+
138
169
  ### Creating a record: `create`
139
170
 
140
171
  The query form of `create()`. Inside the brackets: the fields, then the keys, separated by commas. Everything is
@@ -162,7 +193,7 @@ A field is `<name> <type>`, then any of these, in any order:
162
193
  | `optional` | may be left out (see "Fields" above) |
163
194
  | `null` / `not null` | may hold `null` / may not (the default) |
164
195
  | `auto` | a UUID is generated on insert; the type must be `string` |
165
- | `default <value>` | used when the field is left out: a string, a whole number, an array, `null`, `true` or `false` (so an `object` field can only default to `null` here; `create()` takes any default) |
196
+ | `default <value>` | used when the field is left out: a string, a number, an array, `null`, `true` or `false` (so an `object` field can only default to `null` here; `create()` takes any default) |
166
197
 
167
198
  The types are `string`, `int`, `boolean`, `object` and `array`; any other is an error.
168
199