@medyll/idae-idbql 0.27.0 → 0.28.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.
@@ -1,5 +1,5 @@
1
- import type { IdbqlIndexedCore } from '../idbqlCore/idbqlCore.js';
2
- import { type Where, type ResultSet, type ResultsetOptions } from '@medyll/idae-query';
1
+ import type { IdbqlIndexedCore } from "../idbqlCore/idbqlCore.js";
2
+ import { type Where, type ResultSet, type ResultsetOptions } from "@medyll/idae-query";
3
3
  /**
4
4
  * Main entry point.
5
5
  * Creates a state object with indexedDB synchronization.
@@ -23,10 +23,11 @@ export declare class StateCollectionDyn<T> {
23
23
  private state;
24
24
  private idbBase;
25
25
  constructor(collectionName: string, idbBase: IdbqlIndexedCore);
26
- get collectionState(): any;
26
+ get collectionState(): any[];
27
27
  private testIdbql;
28
28
  private feed;
29
- where(qy: Where<T>, options?: ResultsetOptions): ResultSet<T>;
29
+ _where(qy: Where<T>, options?: ResultsetOptions): ResultSet<T>;
30
+ get where(): (qy: Where<T>, options?: ResultsetOptions) => ResultSet<T>;
30
31
  update(keyPathValue: string | number, data: Partial<T>): void;
31
32
  get(value: any, pathKey?: string): T[];
32
33
  getOne(value: any, pathKey?: string): T;
@@ -1,6 +1,6 @@
1
- import { idbqlEvent } from './idbqlEvent.svelte.js';
1
+ import { idbqlEvent } from "./idbqlEvent.svelte.js";
2
2
  //
3
- import { Operators, getResultset } from '@medyll/idae-query';
3
+ import { Operators, getResultset, } from "@medyll/idae-query";
4
4
  //
5
5
  /**
6
6
  * Main entry point.
@@ -34,7 +34,7 @@ export const createIdbqlState = (idbBase) => {
34
34
  return collections;
35
35
  },
36
36
  onCollection: addCollection,
37
- addCollection: addCollection
37
+ addCollection: addCollection,
38
38
  };
39
39
  };
40
40
  /**
@@ -49,15 +49,15 @@ export class StateCollectionDyn {
49
49
  state = idbqlEvent.dataState; // svelte state ;)
50
50
  idbBase;
51
51
  constructor(collectionName, idbBase) {
52
- if (!this.state?.[collectionName])
53
- this.state[collectionName] = [];
52
+ if (!idbqlEvent.dataState?.[collectionName])
53
+ idbqlEvent.dataState[collectionName] = [];
54
54
  this.collectionName = collectionName;
55
55
  this.idbBase = idbBase;
56
56
  this.feed();
57
57
  return this;
58
58
  }
59
59
  get collectionState() {
60
- return this.state[this.collectionName];
60
+ return idbqlEvent?.dataState?.[this.collectionName];
61
61
  }
62
62
  testIdbql(collection) {
63
63
  return this.idbBase && Boolean(this.idbBase?.[collection]);
@@ -65,26 +65,30 @@ export class StateCollectionDyn {
65
65
  feed() {
66
66
  if (this.idbBase && this.testIdbql(this.collectionName)) {
67
67
  this.idbBase[this.collectionName].getAll().then((data) => {
68
- this.state[this.collectionName] = data;
68
+ idbqlEvent.dataState[this.collectionName] = data;
69
69
  });
70
70
  }
71
71
  }
72
- where(qy, options) {
73
- let c = Operators.parse(this.collectionState ?? [], qy);
72
+ _where(qy, options) {
73
+ let dts = this.collectionState;
74
+ let c = Operators.parse(dts ?? [], qy);
74
75
  const r = getResultset(c);
75
76
  if (options)
76
77
  r.setOptions(options);
77
78
  return r;
78
79
  }
80
+ get where() {
81
+ return (qy, options) => this._where(qy, options);
82
+ }
79
83
  update(keyPathValue, data) {
80
84
  if (this.idbBase && this.testIdbql(this.collectionName)) {
81
85
  this.idbBase[this.collectionName].update(keyPathValue, data);
82
86
  }
83
87
  }
84
- get(value, pathKey = 'id') {
88
+ get(value, pathKey = "id") {
85
89
  return this.collectionState.filter((d) => d[pathKey] === value);
86
90
  }
87
- getOne(value, pathKey = 'id') {
91
+ getOne(value, pathKey = "id") {
88
92
  return this.collectionState.filter((d) => d[pathKey] === value)?.[0];
89
93
  }
90
94
  getAll() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@medyll/idae-idbql",
3
3
  "scope": "@medyll",
4
- "version": "0.27.0",
4
+ "version": "0.28.0",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && npm run package",
@@ -43,6 +43,6 @@
43
43
  "types": "./dist/index.d.ts",
44
44
  "type": "module",
45
45
  "dependencies": {
46
- "@medyll/idae-query": "^0.27.0"
46
+ "@medyll/idae-query": "^0.28.0"
47
47
  }
48
48
  }