@kubun/store-graph 0.16.0 → 0.17.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.
@@ -75,7 +75,9 @@ function getOrderByFieldEntry(field) {
75
75
  const keys = [];
76
76
  let current = field;
77
77
  do {
78
- const [key, value] = Object.entries(current)[0];
78
+ const entry = Object.entries(current)[0];
79
+ if (entry == null) break;
80
+ const [key, value] = entry;
79
81
  keys.push(key);
80
82
  if (typeof value === 'string') {
81
83
  return {
@@ -181,11 +183,15 @@ function buildKeysetPredicate(eb, orderBy, values, nullKeys, id, forward, coerce
181
183
  const idCmp = forward ? '>' : '<';
182
184
  const clauses = [];
183
185
  for(let level = 0; level < fields.length; level += 1){
186
+ const advanceField = fields[level];
187
+ if (advanceField == null) continue;
184
188
  const conjuncts = [];
185
189
  for(let prior = 0; prior < level; prior += 1){
186
- conjuncts.push(equalTerm(eb, fields[prior]));
190
+ const priorField = fields[prior];
191
+ if (priorField == null) continue;
192
+ conjuncts.push(equalTerm(eb, priorField));
187
193
  }
188
- conjuncts.push(advanceTerm(eb, fields[level]));
194
+ conjuncts.push(advanceTerm(eb, advanceField));
189
195
  clauses.push(eb.and(conjuncts));
190
196
  }
191
197
  const tieBreak = [];
@@ -232,10 +238,11 @@ function applyBackwardPagination(queryBuilder, limit, before, orderBy, coerce) {
232
238
  }
233
239
  export function applyDocumentFilter(eb, filter, adapter, path = [], coerce) {
234
240
  const entries = Object.entries(filter);
235
- if (entries.length !== 1) {
241
+ const entry = entries[0];
242
+ if (entries.length !== 1 || entry == null) {
236
243
  throw new Error('Invalid document filter');
237
244
  }
238
- const [type, value] = entries[0];
245
+ const [type, value] = entry;
239
246
  switch(type){
240
247
  case 'where':
241
248
  return applyObjectFilter(eb, value, adapter, path, coerce);
@@ -273,11 +280,12 @@ export function escapeLikePattern(value) {
273
280
  }
274
281
  export function applyValueFilter(eb, keys, filter, adapter, coerce) {
275
282
  const entries = Object.entries(filter);
276
- if (entries.length !== 1) {
283
+ const entry = entries[0];
284
+ if (entries.length !== 1 || entry == null) {
277
285
  throw new Error('Invalid value filter');
278
286
  }
279
287
  const fieldName = getKeyPath(eb, keys);
280
- const [type, value] = entries[0];
288
+ const [type, value] = entry;
281
289
  const c = coerce ?? ((v)=>v);
282
290
  switch(type){
283
291
  case 'isNull':
@@ -365,10 +373,11 @@ export function knownFieldColumn(keys) {
365
373
  }
366
374
  function applyOrderByField(query, adapter, orderBy, isReverse, path = []) {
367
375
  const entries = Object.entries(orderBy);
368
- if (entries.length !== 1) {
376
+ const entry = entries[0];
377
+ if (entries.length !== 1 || entry == null) {
369
378
  throw new Error('Invalid order by field');
370
379
  }
371
- const [key, value] = entries[0];
380
+ const [key, value] = entry;
372
381
  const keys = [
373
382
  ...path,
374
383
  key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/store-graph",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -15,16 +15,16 @@
15
15
  "LICENSE.md"
16
16
  ],
17
17
  "dependencies": {
18
- "@kubun/db": "^0.16.0",
19
- "@kubun/db-adapter": "^0.16.0",
20
- "@kubun/id": "^0.16.0",
21
- "@kubun/protocol": "^0.16.0",
18
+ "@kubun/db": "^0.17.0",
19
+ "@kubun/db-adapter": "^0.17.0",
20
+ "@kubun/id": "^0.17.0",
21
+ "@kubun/protocol": "^0.17.0",
22
22
  "@sozai/codec": "^0.4.0",
23
23
  "kysely": "^0.29.5"
24
24
  },
25
25
  "devDependencies": {
26
- "@kubun/db-better-sqlite": "^0.16.0",
27
- "@kubun/db-postgres": "^0.16.0",
26
+ "@kubun/db-better-sqlite": "^0.17.0",
27
+ "@kubun/db-postgres": "^0.17.0",
28
28
  "@testcontainers/postgresql": "^12.1.0"
29
29
  },
30
30
  "publishConfig": {
@@ -33,8 +33,8 @@
33
33
  "scripts": {
34
34
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
35
35
  "build:clean": "del lib",
36
- "build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
37
- "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
36
+ "build:js": "del 'lib/**/*.js' && swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
37
+ "build:types": "del 'lib/**/*.d.ts' 'lib/**/*.d.ts.map' && tsc --emitDeclarationOnly --skipLibCheck",
38
38
  "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
39
39
  "test": "pnpm run test:types && pnpm run test:unit",
40
40
  "test:types": "tsc --noEmit -p tsconfig.test.json",