react-rock 3.2.3 → 3.2.5

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.
package/Store.d.ts CHANGED
@@ -6,20 +6,21 @@ declare class Store<RS extends RowSchema, MS extends MetaSchema | undefined = un
6
6
  private _meta;
7
7
  private _hooks;
8
8
  private _timer;
9
- private _rowSchema;
10
- private _metaSchema?;
9
+ private _row_schema;
10
+ private _meta_schema?;
11
+ private _last_id;
11
12
  constructor(rowSchema: RS, metaSchema?: MS);
12
- private useHook;
13
- readonly dispatch: () => void;
13
+ private use;
14
+ private dispatch;
14
15
  rows(use?: boolean): MakeRowType<RS>[];
15
16
  metas(use?: boolean): Map<keyof Infer<MS>, Infer<MS>[keyof Infer<MS>]>;
16
17
  create(row: Partial<MakeRowType<RS>>, dispatch?: boolean): MakeRowType<RS>;
17
18
  create(row: Partial<MakeRowType<RS>>[], dispatch?: boolean): MakeRowType<RS>[];
18
- update(row: Partial<MakeRowType<RS>>, where?: WhereType<RS> | null, dispatch?: boolean): MakeRowType<RS> | null;
19
+ update(row: Partial<MakeRowType<RS>>, where?: WhereType<RS> | null, dispatch?: boolean): MakeRowType<RS>[] | null;
19
20
  delete(where?: WhereType<RS> | null, dispatch?: boolean): number;
20
21
  find(where?: WhereType<RS> | null, use?: boolean): MakeRowType<RS>[];
21
22
  findOne(where: WhereType<RS>, use?: boolean): MakeRowType<RS> | null;
22
- findById(id: string, use?: boolean): MakeRowType<RS> | null;
23
+ findById(rid: string, use?: boolean): MakeRowType<RS> | null;
23
24
  getIndex(where: WhereType<RS>, use?: boolean): number;
24
25
  move(fromIndex: number, toIndex: number, dispatch?: boolean): boolean;
25
26
  setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], dispatch?: boolean): void;
package/Store.js CHANGED
@@ -10,20 +10,17 @@ class Store {
10
10
  this._meta = new Map();
11
11
  this._hooks = new Map();
12
12
  this._timer = null;
13
- this.useHook = () => {
13
+ this._last_id = 0;
14
+ this.use = () => {
14
15
  try {
15
- const id = react.useId();
16
+ const hid = react.useId();
16
17
  const [, dispatch] = react.useState(0);
17
- this._hooks.set(id, () => dispatch(Math.random()));
18
- react.useEffect(() => {
19
- return () => {
20
- this._hooks.delete(id);
21
- };
18
+ this._hooks.set(hid, () => dispatch(Math.random()));
19
+ react.useEffect(() => () => {
20
+ this._hooks.delete(hid);
22
21
  }, []);
23
- return id;
24
- }
25
- catch (error) {
26
22
  }
23
+ catch (error) { }
27
24
  };
28
25
  this.dispatch = () => {
29
26
  clearTimeout(this._timer);
@@ -38,15 +35,15 @@ class Store {
38
35
  });
39
36
  }, 0);
40
37
  };
41
- this._rowSchema = Object.assign(Object.assign({}, rowSchema), { id: xanv.xv.number(), ovserve: xanv.xv.number().default(() => Date.now()) });
42
- this._metaSchema = metaSchema;
38
+ this._row_schema = Object.assign(Object.assign({}, rowSchema), { rid: xanv.xv.number(), vid: xanv.xv.number().default(() => Math.round((Math.random() + Math.random()) * 9999999999)) });
39
+ this._meta_schema = metaSchema;
43
40
  }
44
41
  rows(use = true) {
45
- use && this.useHook();
42
+ use && this.use();
46
43
  return this._rows;
47
44
  }
48
45
  metas(use = true) {
49
- use && this.useHook();
46
+ use && this.use();
50
47
  return this._meta;
51
48
  }
52
49
  create(row, dispatch = true) {
@@ -60,16 +57,14 @@ class Store {
60
57
  }
61
58
  // validate and create row
62
59
  let r = {};
63
- for (let key in this._rowSchema) {
64
- const schema = this._rowSchema[key];
65
- const value = row[key];
66
- if (key === "id" || key === "observe")
60
+ for (let key in this._row_schema) {
61
+ if (key === "rid" || key === "vid")
67
62
  continue;
68
- r[key] = schema.parse(value);
63
+ const schema = this._row_schema[key];
64
+ r[key] = schema.parse(row[key]);
69
65
  }
70
- const _row = Object.assign(Object.assign({}, r), { id: this._rows.length > 0
71
- ? this._rows[this._rows.length - 1].id + 1
72
- : 1, observe: Date.now() });
66
+ this._last_id = this._last_id + 1;
67
+ const _row = Object.assign(Object.assign({}, r), { rid: this._last_id, vid: this._row_schema.vid.parse(undefined) });
73
68
  this._rows.push(_row);
74
69
  dispatch && this.dispatch();
75
70
  return _row;
@@ -78,31 +73,31 @@ class Store {
78
73
  update(row, where, dispatch = true) {
79
74
  // validate row
80
75
  let r = {};
81
- for (let key in this._rowSchema) {
82
- const schema = this._rowSchema[key];
83
- const value = row[key];
84
- if (key === "id" || key === "observe")
76
+ for (let key in row) {
77
+ if (key === "rid" || key === 'vid')
85
78
  continue;
86
- if (value !== undefined) {
87
- r[key] = schema.parse(value);
88
- }
79
+ const schema = this._row_schema[key];
80
+ r[key] = schema.parse(row[key]);
89
81
  }
90
82
  const rows = this.find(where);
91
83
  if (rows.length > 0) {
92
- for (let index = 0; index < this._rows.length; index++) {
84
+ for (let index = 0; index < rows.length; index++) {
93
85
  const _row = rows[index];
94
- rows[index] = Object.assign(Object.assign(Object.assign({}, _row), r), { id: _row.id, observe: Date.now() });
86
+ const rid = _row.rid;
87
+ rows[index] = Object.assign(Object.assign(Object.assign({}, _row), r), { rid, vid: this._row_schema.vid.parse(undefined) });
88
+ const rowIndex = this._rows.findIndex(r => r.rid === rid);
89
+ this._rows[rowIndex] = rows[index];
95
90
  }
96
91
  dispatch && this.dispatch();
97
92
  }
98
- return null;
93
+ return this.find(where);
99
94
  }
100
95
  // delete
101
96
  delete(where, dispatch = true) {
102
97
  const rows = this.find(where, false);
103
98
  let deletedCount = 0;
104
99
  if (rows.length > 0) {
105
- this._rows = this._rows.filter(r => !rows.find(dr => dr.id === r.id));
100
+ this._rows = this._rows.filter(r => !rows.find(dr => dr.rid === r.rid));
106
101
  deletedCount = rows.length;
107
102
  dispatch && this.dispatch();
108
103
  }
@@ -110,21 +105,21 @@ class Store {
110
105
  }
111
106
  // find
112
107
  find(where, use = true) {
113
- use && this.useHook();
108
+ use && this.use();
114
109
  if (!where) {
115
110
  return this._rows;
116
111
  }
117
112
  const rows = [];
118
113
  for (let key in where) {
119
- const wvalue = where[key];
120
- if (typeof wvalue === "object" && wvalue !== null) {
114
+ const wv = where[key];
115
+ if (typeof wv === "object" && wv !== null) {
121
116
  // QueryValueType
122
117
  for (let row of this._rows) {
123
118
  let match = true;
124
119
  const rvalue = row[key];
125
- if (wvalue.contain !== undefined) {
126
- if (typeof rvalue === "string" && typeof wvalue.contain === "string") {
127
- if (!rvalue.includes(wvalue.contain)) {
120
+ if (wv.contain !== undefined) {
121
+ if (typeof rvalue === "string" && typeof wv.contain === "string") {
122
+ if (!rvalue.includes(wv.contain)) {
128
123
  match = false;
129
124
  }
130
125
  }
@@ -132,9 +127,9 @@ class Store {
132
127
  match = false;
133
128
  }
134
129
  }
135
- if (wvalue.startWith !== undefined) {
136
- if (typeof rvalue === "string" && typeof wvalue.startWith === "string") {
137
- if (!rvalue.startsWith(wvalue.startWith)) {
130
+ if (wv.startWith !== undefined) {
131
+ if (typeof rvalue === "string" && typeof wv.startWith === "string") {
132
+ if (!rvalue.startsWith(wv.startWith)) {
138
133
  match = false;
139
134
  }
140
135
  }
@@ -142,9 +137,9 @@ class Store {
142
137
  match = false;
143
138
  }
144
139
  }
145
- if (wvalue.endWith !== undefined) {
146
- if (typeof rvalue === "string" && typeof wvalue.endWith === "string") {
147
- if (!rvalue.endsWith(wvalue.endWith)) {
140
+ if (wv.endWith !== undefined) {
141
+ if (typeof rvalue === "string" && typeof wv.endWith === "string") {
142
+ if (!rvalue.endsWith(wv.endWith)) {
148
143
  match = false;
149
144
  }
150
145
  }
@@ -152,19 +147,19 @@ class Store {
152
147
  match = false;
153
148
  }
154
149
  }
155
- if (wvalue.equalWith !== undefined) {
156
- if (rvalue !== wvalue.equalWith) {
150
+ if (wv.equalWith !== undefined) {
151
+ if (rvalue !== wv.equalWith) {
157
152
  match = false;
158
153
  }
159
154
  }
160
- if (wvalue.notEqualWith !== undefined) {
161
- if (rvalue === wvalue.notEqualWith) {
155
+ if (wv.notEqualWith !== undefined) {
156
+ if (rvalue === wv.notEqualWith) {
162
157
  match = false;
163
158
  }
164
159
  }
165
- if (wvalue.gt !== undefined) {
160
+ if (wv.gt !== undefined) {
166
161
  if (typeof rvalue === "number") {
167
- if (!(rvalue > wvalue.gt)) {
162
+ if (!(rvalue > wv.gt)) {
168
163
  match = false;
169
164
  }
170
165
  }
@@ -172,9 +167,9 @@ class Store {
172
167
  match = false;
173
168
  }
174
169
  }
175
- if (wvalue.lt !== undefined) {
170
+ if (wv.lt !== undefined) {
176
171
  if (typeof rvalue === "number") {
177
- if (!(rvalue < wvalue.lt)) {
172
+ if (!(rvalue < wv.lt)) {
178
173
  match = false;
179
174
  }
180
175
  }
@@ -182,9 +177,9 @@ class Store {
182
177
  match = false;
183
178
  }
184
179
  }
185
- if (wvalue.gte !== undefined) {
180
+ if (wv.gte !== undefined) {
186
181
  if (typeof rvalue === "number") {
187
- if (!(rvalue >= wvalue.gte)) {
182
+ if (!(rvalue >= wv.gte)) {
188
183
  match = false;
189
184
  }
190
185
  }
@@ -192,9 +187,9 @@ class Store {
192
187
  match = false;
193
188
  }
194
189
  }
195
- if (wvalue.lte !== undefined) {
190
+ if (wv.lte !== undefined) {
196
191
  if (typeof rvalue === "number") {
197
- if (!(rvalue <= wvalue.lte)) {
192
+ if (!(rvalue <= wv.lte)) {
198
193
  match = false;
199
194
  }
200
195
  }
@@ -208,9 +203,9 @@ class Store {
208
203
  }
209
204
  }
210
205
  else {
211
- // RowValueType
206
+ // RowvType
212
207
  for (let row of this._rows) {
213
- if (row[key] === wvalue) {
208
+ if (row[key] === wv) {
214
209
  rows.push(row);
215
210
  }
216
211
  }
@@ -222,14 +217,14 @@ class Store {
222
217
  const rows = this.find(where, use);
223
218
  return rows.length > 0 ? rows[0] : null;
224
219
  }
225
- findById(id, use = true) {
226
- return this.findOne({ id }, use);
220
+ findById(rid, use = true) {
221
+ return this.findOne({ rid }, use);
227
222
  }
228
223
  getIndex(where, use = true) {
229
- use && this.useHook();
224
+ use && this.use();
230
225
  const row = this.findOne(where, false);
231
226
  if (row) {
232
- return this._rows.findIndex(r => r.id === row.id);
227
+ return this._rows.findIndex(r => r.rid === row.rid);
233
228
  }
234
229
  return -1;
235
230
  }
@@ -245,11 +240,11 @@ class Store {
245
240
  }
246
241
  // Meta Methods
247
242
  setMeta(key, value, dispatch = true) {
248
- this._meta.set(key, value);
243
+ this._meta.set(key, this._meta_schema ? this._meta_schema[key].parse(value) : value);
249
244
  dispatch && this.dispatch();
250
245
  }
251
246
  getMeta(key, use = true) {
252
- use && this.useHook();
247
+ use && this.use();
253
248
  return this._meta.get(key);
254
249
  }
255
250
  deleteMeta(key, dispatch = true) {
package/Store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Store.js","sources":["../src/Store.ts"],"sourcesContent":["\"use client\"\r\nimport { useEffect, useId, useState } from \"react\"\r\nimport { MakeMetaType, MakeRowType, MetaSchema, RowSchema, WhereType } from \"./types\"\r\nimport { Infer, xv } from \"xanv\"\r\n\r\nclass Store<RS extends RowSchema, MS extends MetaSchema | undefined = undefined> {\r\n private _rows: MakeRowType<RS>[] = []\r\n private _meta: Map<keyof MakeMetaType<MS>, MakeMetaType<MS>[keyof MakeMetaType<MS>]> = new Map()\r\n private _hooks: Map<string, Function> = new Map()\r\n private _timer: any = null\r\n\r\n private _rowSchema: RS\r\n private _metaSchema?: MS\r\n\r\n constructor(rowSchema: RS, metaSchema?: MS) {\r\n this._rowSchema = {\r\n ...rowSchema,\r\n id: xv.number(),\r\n ovserve: xv.number().default(() => Date.now()),\r\n }\r\n this._metaSchema = metaSchema\r\n }\r\n\r\n private useHook = () => {\r\n try {\r\n const id = useId()\r\n const [, dispatch] = useState(0)\r\n this._hooks.set(id, () => dispatch(Math.random()))\r\n\r\n useEffect(() => {\r\n return () => {\r\n this._hooks.delete(id)\r\n }\r\n }, [])\r\n return id\r\n } catch (error) {\r\n\r\n }\r\n }\r\n\r\n readonly dispatch = () => {\r\n clearTimeout(this._timer)\r\n this._timer = setTimeout(() => {\r\n this._hooks.forEach((cb, key) => {\r\n try {\r\n cb()\r\n } catch (_err) {\r\n this._hooks.delete(key)\r\n }\r\n })\r\n }, 0)\r\n }\r\n\r\n rows(use = true) {\r\n use && this.useHook()\r\n return this._rows\r\n }\r\n\r\n metas(use = true) {\r\n use && this.useHook()\r\n return this._meta\r\n }\r\n\r\n // Row Methods\r\n create(row: Partial<MakeRowType<RS>>, dispatch?: boolean): MakeRowType<RS>\r\n create(row: Partial<MakeRowType<RS>>[], dispatch?: boolean): MakeRowType<RS>[]\r\n create(row: Partial<MakeRowType<RS>> | Partial<MakeRowType<RS>>[], dispatch = true): MakeRowType<RS> | MakeRowType<RS>[] {\r\n if (Array.isArray(row)) {\r\n const rows: MakeRowType<RS>[] = []\r\n for (const r of row) {\r\n rows.push(this.create(r, false))\r\n }\r\n dispatch && this.dispatch()\r\n return rows\r\n }\r\n\r\n // validate and create row\r\n let r = {} as MakeRowType<RS>\r\n for (let key in this._rowSchema) {\r\n const schema = this._rowSchema[key]\r\n const value = (row as any)[key]\r\n if (key === \"id\" || key === \"observe\") continue;\r\n (r as any)[key] = schema.parse(value)\r\n }\r\n\r\n const _row: MakeRowType<RS> = {\r\n ...r,\r\n id: this._rows.length > 0\r\n ? this._rows[this._rows.length - 1].id + 1\r\n : 1,\r\n observe: Date.now(),\r\n }\r\n\r\n this._rows.push(_row)\r\n dispatch && this.dispatch()\r\n return _row\r\n }\r\n\r\n\r\n // update\r\n update(row: Partial<MakeRowType<RS>>, where?: WhereType<RS> | null, dispatch = true): MakeRowType<RS> | null {\r\n\r\n // validate row\r\n let r = {} as MakeRowType<RS>\r\n for (let key in this._rowSchema) {\r\n const schema = this._rowSchema[key]\r\n const value = (row as any)[key]\r\n if (key === \"id\" || key === \"observe\") continue;\r\n if (value !== undefined) {\r\n (r as any)[key] = schema.parse(value)\r\n }\r\n }\r\n\r\n const rows = this.find(where)\r\n if (rows.length > 0) {\r\n for (let index = 0; index < this._rows.length; index++) {\r\n const _row = rows[index];\r\n rows[index] = {\r\n ..._row,\r\n ...r,\r\n id: _row.id,\r\n observe: Date.now(),\r\n }\r\n }\r\n dispatch && this.dispatch()\r\n }\r\n return null\r\n }\r\n\r\n // delete\r\n delete(where?: WhereType<RS> | null, dispatch = true): number {\r\n const rows = this.find(where, false)\r\n\r\n let deletedCount = 0\r\n if (rows.length > 0) {\r\n this._rows = this._rows.filter(r => !rows.find(dr => dr.id === r.id))\r\n deletedCount = rows.length\r\n dispatch && this.dispatch()\r\n }\r\n return deletedCount\r\n }\r\n\r\n // find\r\n find(where?: WhereType<RS> | null, use = true): MakeRowType<RS>[] {\r\n use && this.useHook()\r\n\r\n if (!where) {\r\n return this._rows\r\n }\r\n\r\n const rows: MakeRowType<RS>[] = []\r\n for (let key in where) {\r\n const wvalue = (where as any)[key]\r\n if (typeof wvalue === \"object\" && wvalue !== null) {\r\n // QueryValueType\r\n for (let row of this._rows) {\r\n let match = true\r\n const rvalue = (row as any)[key]\r\n if (wvalue.contain !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wvalue.contain === \"string\") {\r\n if (!rvalue.includes(wvalue.contain)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.startWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wvalue.startWith === \"string\") {\r\n if (!rvalue.startsWith(wvalue.startWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.endWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wvalue.endWith === \"string\") {\r\n if (!rvalue.endsWith(wvalue.endWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.equalWith !== undefined) {\r\n if (rvalue !== wvalue.equalWith) {\r\n match = false\r\n }\r\n }\r\n if (wvalue.notEqualWith !== undefined) {\r\n if (rvalue === wvalue.notEqualWith) {\r\n match = false\r\n }\r\n }\r\n if (wvalue.gt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue > wvalue.gt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.lt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue < wvalue.lt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.gte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue >= wvalue.gte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.lte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue <= wvalue.lte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (match) {\r\n rows.push(row)\r\n }\r\n }\r\n } else {\r\n // RowValueType\r\n for (let row of this._rows) {\r\n if ((row as any)[key] === wvalue) {\r\n rows.push(row)\r\n }\r\n }\r\n }\r\n }\r\n return rows\r\n }\r\n\r\n findOne(where: WhereType<RS>, use = true): MakeRowType<RS> | null {\r\n const rows = this.find(where, use)\r\n return rows.length > 0 ? rows[0] : null\r\n }\r\n\r\n findById(id: string, use = true): MakeRowType<RS> | null {\r\n return this.findOne({ id }, use)\r\n }\r\n\r\n getIndex(where: WhereType<RS>, use = true): number {\r\n use && this.useHook()\r\n const row = this.findOne(where, false)\r\n if (row) {\r\n return this._rows.findIndex(r => r.id === row.id)\r\n }\r\n return -1\r\n }\r\n\r\n move(fromIndex: number, toIndex: number, dispatch = true): boolean {\r\n if (fromIndex < 0 || fromIndex >= this._rows.length) return false\r\n if (toIndex < 0 || toIndex >= this._rows.length) return false\r\n const [movedRow] = this._rows.splice(fromIndex, 1)\r\n this._rows.splice(toIndex, 0, movedRow)\r\n dispatch && this.dispatch()\r\n return true\r\n }\r\n\r\n // Meta Methods\r\n setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], dispatch = true) {\r\n this._meta.set(key, value)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n getMeta<T extends keyof Infer<MS>>(key: T, use = true): Infer<MS>[T] | undefined {\r\n use && this.useHook()\r\n return this._meta.get(key) as Infer<MS>[T] | undefined\r\n }\r\n\r\n deleteMeta<T extends keyof Infer<MS>>(key: T, dispatch = true) {\r\n this._meta.delete(key)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n clearMeta(dispatch = true) {\r\n this._meta.clear()\r\n dispatch && this.dispatch()\r\n }\r\n}\r\n\r\nexport default Store"],"names":[],"mappings":";;;;;;AAKA;;;AAEW;AACA;;;;AAiBF;;AAEA;;AAGG;AACG;AACH;;AAEH;AACF;AAAC;AAED;AACJ;;AAGG;AACA;;;AAGS;AACF;AAAC;AACC;AACF;AACJ;;AAEN;AApCG;AAKA;;;AAkCA;;;;AAKA;;;AAOH;AACG;;AAEG;AACG;AACF;AACD;AACA;AACF;;;AAID;;AAEG;AACA;;;AAEF;AAED;AAGM;;AAKN;AACA;AACA;;;AAKH;;;AAIG;;AAEG;AACA;;;;AAGC;AACH;;AAGD;AACG;AACG;;AAOF;AACD;AACF;AACD;;;AAIH;;;AAIG;AACG;AACA;AACA;AACF;AACD;;;AAIH;AACG;;;AAIC;;AAGD;AACG;;;AAGG;;AAEG;AACA;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;AACF;AACH;AACH;AAAM;;AAEJ;AACG;AACG;AACF;AACH;AACH;AACH;AACD;;AAGH;;AAEG;;AAGH;;;AAIA;AACG;;AAEA;AACG;AACF;;;AAIJ;;AACwD;;AACJ;AACjD;;AAEA;AACA;;;AAIH;;AAEG;;AAGH;AACG;;;AAIH;AACG;AACA;;;AAIA;AACA;;AAEL;;"}
1
+ {"version":3,"file":"Store.js","sources":["../src/Store.ts"],"sourcesContent":["\"use client\"\r\nimport { useEffect, useId, useState } from \"react\"\r\nimport { MakeMetaType, MakeRowType, MetaSchema, RowSchema, WhereType } from \"./types\"\r\nimport { Infer, xv } from \"xanv\"\r\n\r\nclass Store<RS extends RowSchema, MS extends MetaSchema | undefined = undefined> {\r\n private _rows: MakeRowType<RS>[] = []\r\n private _meta: Map<keyof MakeMetaType<MS>, MakeMetaType<MS>[keyof MakeMetaType<MS>]> = new Map()\r\n private _hooks: Map<string, Function> = new Map()\r\n private _timer: any = null\r\n private _row_schema: RS\r\n private _meta_schema?: MS\r\n private _last_id = 0\r\n\r\n constructor(rowSchema: RS, metaSchema?: MS) {\r\n this._row_schema = {\r\n ...rowSchema,\r\n rid: xv.number(),\r\n vid: xv.number().default(() => Math.round((Math.random() + Math.random()) * 9999999999)),\r\n }\r\n this._meta_schema = metaSchema\r\n }\r\n\r\n private use = () => {\r\n try {\r\n const hid = useId()\r\n const [, dispatch] = useState(0)\r\n this._hooks.set(hid, () => dispatch(Math.random()))\r\n useEffect(() => () => {\r\n this._hooks.delete(hid)\r\n }, [])\r\n } catch (error) { }\r\n }\r\n\r\n private dispatch = () => {\r\n clearTimeout(this._timer)\r\n this._timer = setTimeout(() => {\r\n this._hooks.forEach((cb, key) => {\r\n try {\r\n cb()\r\n } catch (_err) {\r\n this._hooks.delete(key)\r\n }\r\n })\r\n }, 0)\r\n }\r\n\r\n rows(use = true) {\r\n use && this.use()\r\n return this._rows\r\n }\r\n\r\n metas(use = true) {\r\n use && this.use()\r\n return this._meta\r\n }\r\n\r\n // Row Methods\r\n create(row: Partial<MakeRowType<RS>>, dispatch?: boolean): MakeRowType<RS>\r\n create(row: Partial<MakeRowType<RS>>[], dispatch?: boolean): MakeRowType<RS>[]\r\n create(row: Partial<MakeRowType<RS>> | Partial<MakeRowType<RS>>[], dispatch = true): MakeRowType<RS> | MakeRowType<RS>[] {\r\n if (Array.isArray(row)) {\r\n const rows: MakeRowType<RS>[] = []\r\n for (const r of row) {\r\n rows.push(this.create(r, false))\r\n }\r\n dispatch && this.dispatch()\r\n return rows\r\n }\r\n\r\n // validate and create row\r\n let r: any = {} as MakeRowType<RS>\r\n for (let key in this._row_schema) {\r\n if (key === \"rid\" || key === \"vid\") continue;\r\n const schema = this._row_schema[key]\r\n r[key] = schema.parse(row[key])\r\n }\r\n\r\n this._last_id = this._last_id + 1;\r\n const _row: MakeRowType<RS> = {\r\n ...r,\r\n rid: this._last_id,\r\n vid: this._row_schema.vid.parse(undefined),\r\n }\r\n\r\n this._rows.push(_row)\r\n dispatch && this.dispatch()\r\n return _row\r\n }\r\n\r\n\r\n // update\r\n update(row: Partial<MakeRowType<RS>>, where?: WhereType<RS> | null, dispatch = true): MakeRowType<RS>[] | null {\r\n\r\n // validate row\r\n let r: any = {} as MakeRowType<RS>\r\n for (let key in row) {\r\n if (key === \"rid\" || key === 'vid') continue;\r\n const schema = this._row_schema[key]\r\n r[key] = schema.parse(row[key])\r\n }\r\n\r\n const rows = this.find(where)\r\n if (rows.length > 0) {\r\n for (let index = 0; index < rows.length; index++) {\r\n const _row = rows[index];\r\n const rid = _row.rid\r\n\r\n rows[index] = {\r\n ..._row,\r\n ...r,\r\n rid,\r\n vid: this._row_schema.vid.parse(undefined),\r\n }\r\n const rowIndex = this._rows.findIndex(r => r.rid === rid)\r\n this._rows[rowIndex] = rows[index]\r\n }\r\n dispatch && this.dispatch()\r\n }\r\n return this.find(where)\r\n }\r\n\r\n // delete\r\n delete(where?: WhereType<RS> | null, dispatch = true): number {\r\n const rows = this.find(where, false)\r\n\r\n let deletedCount = 0\r\n if (rows.length > 0) {\r\n this._rows = this._rows.filter(r => !rows.find(dr => dr.rid === r.rid))\r\n deletedCount = rows.length\r\n dispatch && this.dispatch()\r\n }\r\n return deletedCount\r\n }\r\n\r\n // find\r\n find(where?: WhereType<RS> | null, use = true): MakeRowType<RS>[] {\r\n use && this.use()\r\n\r\n if (!where) {\r\n return this._rows\r\n }\r\n\r\n const rows: MakeRowType<RS>[] = []\r\n for (let key in where) {\r\n const wv = (where as any)[key]\r\n if (typeof wv === \"object\" && wv !== null) {\r\n // QueryValueType\r\n for (let row of this._rows) {\r\n let match = true\r\n const rvalue = (row as any)[key]\r\n if (wv.contain !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wv.contain === \"string\") {\r\n if (!rvalue.includes(wv.contain)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.startWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wv.startWith === \"string\") {\r\n if (!rvalue.startsWith(wv.startWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.endWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wv.endWith === \"string\") {\r\n if (!rvalue.endsWith(wv.endWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.equalWith !== undefined) {\r\n if (rvalue !== wv.equalWith) {\r\n match = false\r\n }\r\n }\r\n if (wv.notEqualWith !== undefined) {\r\n if (rvalue === wv.notEqualWith) {\r\n match = false\r\n }\r\n }\r\n if (wv.gt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue > wv.gt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.lt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue < wv.lt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.gte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue >= wv.gte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.lte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue <= wv.lte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (match) {\r\n rows.push(row)\r\n }\r\n }\r\n } else {\r\n // RowvType\r\n for (let row of this._rows) {\r\n if ((row as any)[key] === wv) {\r\n rows.push(row)\r\n }\r\n }\r\n }\r\n }\r\n return rows\r\n }\r\n\r\n findOne(where: WhereType<RS>, use = true): MakeRowType<RS> | null {\r\n const rows = this.find(where, use)\r\n return rows.length > 0 ? rows[0] : null\r\n }\r\n\r\n findById(rid: string, use = true): MakeRowType<RS> | null {\r\n return this.findOne({ rid }, use)\r\n }\r\n\r\n getIndex(where: WhereType<RS>, use = true): number {\r\n use && this.use()\r\n const row = this.findOne(where, false)\r\n if (row) {\r\n return this._rows.findIndex(r => r.rid === row.rid)\r\n }\r\n return -1\r\n }\r\n\r\n move(fromIndex: number, toIndex: number, dispatch = true): boolean {\r\n if (fromIndex < 0 || fromIndex >= this._rows.length) return false\r\n if (toIndex < 0 || toIndex >= this._rows.length) return false\r\n const [movedRow] = this._rows.splice(fromIndex, 1)\r\n this._rows.splice(toIndex, 0, movedRow)\r\n dispatch && this.dispatch()\r\n return true\r\n }\r\n\r\n // Meta Methods\r\n setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], dispatch = true) {\r\n this._meta.set(key, this._meta_schema ? (this._meta_schema[key] as any).parse(value) : value)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n getMeta<T extends keyof Infer<MS>>(key: T, use = true): Infer<MS>[T] | undefined {\r\n use && this.use()\r\n return this._meta.get(key) as Infer<MS>[T] | undefined\r\n }\r\n\r\n deleteMeta<T extends keyof Infer<MS>>(key: T, dispatch = true) {\r\n this._meta.delete(key)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n clearMeta(dispatch = true) {\r\n this._meta.clear()\r\n dispatch && this.dispatch()\r\n }\r\n}\r\n\r\nexport default Store"],"names":[],"mappings":";;;;;;AAKA;;;AAEW;AACA;;;;;AAiBF;;AAEA;AACA;AACG;;AAEL;;AACJ;;AAGG;AACA;;;AAGS;AACF;AAAC;AACC;AACF;AACJ;;AAEN;;AAzBG;;;AA4BA;;;;AAKA;;;AAOH;AACG;;AAEG;AACG;AACF;AACD;AACA;AACF;;;AAID;AACG;;;AAEA;AACF;;;AASD;AACA;AACA;;;AAKH;;;AAIG;AACG;;;AAEA;AACF;;AAGD;AACG;AACG;AACA;;AAQA;;AAEF;AACD;AACF;AACD;;;AAIH;;;AAIG;AACG;AACA;AACA;AACF;AACD;;;AAIH;AACG;;;AAIC;;AAGD;AACG;;;AAGG;;AAEG;AACA;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;AACF;AACH;AACH;AAAM;;AAEJ;AACG;AACG;AACF;AACH;AACH;AACH;AACD;;AAGH;;AAEG;;AAGH;;;AAIA;AACG;;AAEA;AACG;AACF;;;AAIJ;;AACwD;;AACJ;AACjD;;AAEA;AACA;;;AAIH;AACG;AACA;;AAGH;AACG;;;AAIH;AACG;AACA;;;AAIA;AACA;;AAEL;;"}
package/Store.mjs CHANGED
@@ -8,20 +8,17 @@ class Store {
8
8
  this._meta = new Map();
9
9
  this._hooks = new Map();
10
10
  this._timer = null;
11
- this.useHook = () => {
11
+ this._last_id = 0;
12
+ this.use = () => {
12
13
  try {
13
- const id = useId();
14
+ const hid = useId();
14
15
  const [, dispatch] = useState(0);
15
- this._hooks.set(id, () => dispatch(Math.random()));
16
- useEffect(() => {
17
- return () => {
18
- this._hooks.delete(id);
19
- };
16
+ this._hooks.set(hid, () => dispatch(Math.random()));
17
+ useEffect(() => () => {
18
+ this._hooks.delete(hid);
20
19
  }, []);
21
- return id;
22
- }
23
- catch (error) {
24
20
  }
21
+ catch (error) { }
25
22
  };
26
23
  this.dispatch = () => {
27
24
  clearTimeout(this._timer);
@@ -36,15 +33,15 @@ class Store {
36
33
  });
37
34
  }, 0);
38
35
  };
39
- this._rowSchema = Object.assign(Object.assign({}, rowSchema), { id: xv.number(), ovserve: xv.number().default(() => Date.now()) });
40
- this._metaSchema = metaSchema;
36
+ this._row_schema = Object.assign(Object.assign({}, rowSchema), { rid: xv.number(), vid: xv.number().default(() => Math.round((Math.random() + Math.random()) * 9999999999)) });
37
+ this._meta_schema = metaSchema;
41
38
  }
42
39
  rows(use = true) {
43
- use && this.useHook();
40
+ use && this.use();
44
41
  return this._rows;
45
42
  }
46
43
  metas(use = true) {
47
- use && this.useHook();
44
+ use && this.use();
48
45
  return this._meta;
49
46
  }
50
47
  create(row, dispatch = true) {
@@ -58,16 +55,14 @@ class Store {
58
55
  }
59
56
  // validate and create row
60
57
  let r = {};
61
- for (let key in this._rowSchema) {
62
- const schema = this._rowSchema[key];
63
- const value = row[key];
64
- if (key === "id" || key === "observe")
58
+ for (let key in this._row_schema) {
59
+ if (key === "rid" || key === "vid")
65
60
  continue;
66
- r[key] = schema.parse(value);
61
+ const schema = this._row_schema[key];
62
+ r[key] = schema.parse(row[key]);
67
63
  }
68
- const _row = Object.assign(Object.assign({}, r), { id: this._rows.length > 0
69
- ? this._rows[this._rows.length - 1].id + 1
70
- : 1, observe: Date.now() });
64
+ this._last_id = this._last_id + 1;
65
+ const _row = Object.assign(Object.assign({}, r), { rid: this._last_id, vid: this._row_schema.vid.parse(undefined) });
71
66
  this._rows.push(_row);
72
67
  dispatch && this.dispatch();
73
68
  return _row;
@@ -76,31 +71,31 @@ class Store {
76
71
  update(row, where, dispatch = true) {
77
72
  // validate row
78
73
  let r = {};
79
- for (let key in this._rowSchema) {
80
- const schema = this._rowSchema[key];
81
- const value = row[key];
82
- if (key === "id" || key === "observe")
74
+ for (let key in row) {
75
+ if (key === "rid" || key === 'vid')
83
76
  continue;
84
- if (value !== undefined) {
85
- r[key] = schema.parse(value);
86
- }
77
+ const schema = this._row_schema[key];
78
+ r[key] = schema.parse(row[key]);
87
79
  }
88
80
  const rows = this.find(where);
89
81
  if (rows.length > 0) {
90
- for (let index = 0; index < this._rows.length; index++) {
82
+ for (let index = 0; index < rows.length; index++) {
91
83
  const _row = rows[index];
92
- rows[index] = Object.assign(Object.assign(Object.assign({}, _row), r), { id: _row.id, observe: Date.now() });
84
+ const rid = _row.rid;
85
+ rows[index] = Object.assign(Object.assign(Object.assign({}, _row), r), { rid, vid: this._row_schema.vid.parse(undefined) });
86
+ const rowIndex = this._rows.findIndex(r => r.rid === rid);
87
+ this._rows[rowIndex] = rows[index];
93
88
  }
94
89
  dispatch && this.dispatch();
95
90
  }
96
- return null;
91
+ return this.find(where);
97
92
  }
98
93
  // delete
99
94
  delete(where, dispatch = true) {
100
95
  const rows = this.find(where, false);
101
96
  let deletedCount = 0;
102
97
  if (rows.length > 0) {
103
- this._rows = this._rows.filter(r => !rows.find(dr => dr.id === r.id));
98
+ this._rows = this._rows.filter(r => !rows.find(dr => dr.rid === r.rid));
104
99
  deletedCount = rows.length;
105
100
  dispatch && this.dispatch();
106
101
  }
@@ -108,21 +103,21 @@ class Store {
108
103
  }
109
104
  // find
110
105
  find(where, use = true) {
111
- use && this.useHook();
106
+ use && this.use();
112
107
  if (!where) {
113
108
  return this._rows;
114
109
  }
115
110
  const rows = [];
116
111
  for (let key in where) {
117
- const wvalue = where[key];
118
- if (typeof wvalue === "object" && wvalue !== null) {
112
+ const wv = where[key];
113
+ if (typeof wv === "object" && wv !== null) {
119
114
  // QueryValueType
120
115
  for (let row of this._rows) {
121
116
  let match = true;
122
117
  const rvalue = row[key];
123
- if (wvalue.contain !== undefined) {
124
- if (typeof rvalue === "string" && typeof wvalue.contain === "string") {
125
- if (!rvalue.includes(wvalue.contain)) {
118
+ if (wv.contain !== undefined) {
119
+ if (typeof rvalue === "string" && typeof wv.contain === "string") {
120
+ if (!rvalue.includes(wv.contain)) {
126
121
  match = false;
127
122
  }
128
123
  }
@@ -130,9 +125,9 @@ class Store {
130
125
  match = false;
131
126
  }
132
127
  }
133
- if (wvalue.startWith !== undefined) {
134
- if (typeof rvalue === "string" && typeof wvalue.startWith === "string") {
135
- if (!rvalue.startsWith(wvalue.startWith)) {
128
+ if (wv.startWith !== undefined) {
129
+ if (typeof rvalue === "string" && typeof wv.startWith === "string") {
130
+ if (!rvalue.startsWith(wv.startWith)) {
136
131
  match = false;
137
132
  }
138
133
  }
@@ -140,9 +135,9 @@ class Store {
140
135
  match = false;
141
136
  }
142
137
  }
143
- if (wvalue.endWith !== undefined) {
144
- if (typeof rvalue === "string" && typeof wvalue.endWith === "string") {
145
- if (!rvalue.endsWith(wvalue.endWith)) {
138
+ if (wv.endWith !== undefined) {
139
+ if (typeof rvalue === "string" && typeof wv.endWith === "string") {
140
+ if (!rvalue.endsWith(wv.endWith)) {
146
141
  match = false;
147
142
  }
148
143
  }
@@ -150,19 +145,19 @@ class Store {
150
145
  match = false;
151
146
  }
152
147
  }
153
- if (wvalue.equalWith !== undefined) {
154
- if (rvalue !== wvalue.equalWith) {
148
+ if (wv.equalWith !== undefined) {
149
+ if (rvalue !== wv.equalWith) {
155
150
  match = false;
156
151
  }
157
152
  }
158
- if (wvalue.notEqualWith !== undefined) {
159
- if (rvalue === wvalue.notEqualWith) {
153
+ if (wv.notEqualWith !== undefined) {
154
+ if (rvalue === wv.notEqualWith) {
160
155
  match = false;
161
156
  }
162
157
  }
163
- if (wvalue.gt !== undefined) {
158
+ if (wv.gt !== undefined) {
164
159
  if (typeof rvalue === "number") {
165
- if (!(rvalue > wvalue.gt)) {
160
+ if (!(rvalue > wv.gt)) {
166
161
  match = false;
167
162
  }
168
163
  }
@@ -170,9 +165,9 @@ class Store {
170
165
  match = false;
171
166
  }
172
167
  }
173
- if (wvalue.lt !== undefined) {
168
+ if (wv.lt !== undefined) {
174
169
  if (typeof rvalue === "number") {
175
- if (!(rvalue < wvalue.lt)) {
170
+ if (!(rvalue < wv.lt)) {
176
171
  match = false;
177
172
  }
178
173
  }
@@ -180,9 +175,9 @@ class Store {
180
175
  match = false;
181
176
  }
182
177
  }
183
- if (wvalue.gte !== undefined) {
178
+ if (wv.gte !== undefined) {
184
179
  if (typeof rvalue === "number") {
185
- if (!(rvalue >= wvalue.gte)) {
180
+ if (!(rvalue >= wv.gte)) {
186
181
  match = false;
187
182
  }
188
183
  }
@@ -190,9 +185,9 @@ class Store {
190
185
  match = false;
191
186
  }
192
187
  }
193
- if (wvalue.lte !== undefined) {
188
+ if (wv.lte !== undefined) {
194
189
  if (typeof rvalue === "number") {
195
- if (!(rvalue <= wvalue.lte)) {
190
+ if (!(rvalue <= wv.lte)) {
196
191
  match = false;
197
192
  }
198
193
  }
@@ -206,9 +201,9 @@ class Store {
206
201
  }
207
202
  }
208
203
  else {
209
- // RowValueType
204
+ // RowvType
210
205
  for (let row of this._rows) {
211
- if (row[key] === wvalue) {
206
+ if (row[key] === wv) {
212
207
  rows.push(row);
213
208
  }
214
209
  }
@@ -220,14 +215,14 @@ class Store {
220
215
  const rows = this.find(where, use);
221
216
  return rows.length > 0 ? rows[0] : null;
222
217
  }
223
- findById(id, use = true) {
224
- return this.findOne({ id }, use);
218
+ findById(rid, use = true) {
219
+ return this.findOne({ rid }, use);
225
220
  }
226
221
  getIndex(where, use = true) {
227
- use && this.useHook();
222
+ use && this.use();
228
223
  const row = this.findOne(where, false);
229
224
  if (row) {
230
- return this._rows.findIndex(r => r.id === row.id);
225
+ return this._rows.findIndex(r => r.rid === row.rid);
231
226
  }
232
227
  return -1;
233
228
  }
@@ -243,11 +238,11 @@ class Store {
243
238
  }
244
239
  // Meta Methods
245
240
  setMeta(key, value, dispatch = true) {
246
- this._meta.set(key, value);
241
+ this._meta.set(key, this._meta_schema ? this._meta_schema[key].parse(value) : value);
247
242
  dispatch && this.dispatch();
248
243
  }
249
244
  getMeta(key, use = true) {
250
- use && this.useHook();
245
+ use && this.use();
251
246
  return this._meta.get(key);
252
247
  }
253
248
  deleteMeta(key, dispatch = true) {
package/Store.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Store.mjs","sources":["../src/Store.ts"],"sourcesContent":["\"use client\"\r\nimport { useEffect, useId, useState } from \"react\"\r\nimport { MakeMetaType, MakeRowType, MetaSchema, RowSchema, WhereType } from \"./types\"\r\nimport { Infer, xv } from \"xanv\"\r\n\r\nclass Store<RS extends RowSchema, MS extends MetaSchema | undefined = undefined> {\r\n private _rows: MakeRowType<RS>[] = []\r\n private _meta: Map<keyof MakeMetaType<MS>, MakeMetaType<MS>[keyof MakeMetaType<MS>]> = new Map()\r\n private _hooks: Map<string, Function> = new Map()\r\n private _timer: any = null\r\n\r\n private _rowSchema: RS\r\n private _metaSchema?: MS\r\n\r\n constructor(rowSchema: RS, metaSchema?: MS) {\r\n this._rowSchema = {\r\n ...rowSchema,\r\n id: xv.number(),\r\n ovserve: xv.number().default(() => Date.now()),\r\n }\r\n this._metaSchema = metaSchema\r\n }\r\n\r\n private useHook = () => {\r\n try {\r\n const id = useId()\r\n const [, dispatch] = useState(0)\r\n this._hooks.set(id, () => dispatch(Math.random()))\r\n\r\n useEffect(() => {\r\n return () => {\r\n this._hooks.delete(id)\r\n }\r\n }, [])\r\n return id\r\n } catch (error) {\r\n\r\n }\r\n }\r\n\r\n readonly dispatch = () => {\r\n clearTimeout(this._timer)\r\n this._timer = setTimeout(() => {\r\n this._hooks.forEach((cb, key) => {\r\n try {\r\n cb()\r\n } catch (_err) {\r\n this._hooks.delete(key)\r\n }\r\n })\r\n }, 0)\r\n }\r\n\r\n rows(use = true) {\r\n use && this.useHook()\r\n return this._rows\r\n }\r\n\r\n metas(use = true) {\r\n use && this.useHook()\r\n return this._meta\r\n }\r\n\r\n // Row Methods\r\n create(row: Partial<MakeRowType<RS>>, dispatch?: boolean): MakeRowType<RS>\r\n create(row: Partial<MakeRowType<RS>>[], dispatch?: boolean): MakeRowType<RS>[]\r\n create(row: Partial<MakeRowType<RS>> | Partial<MakeRowType<RS>>[], dispatch = true): MakeRowType<RS> | MakeRowType<RS>[] {\r\n if (Array.isArray(row)) {\r\n const rows: MakeRowType<RS>[] = []\r\n for (const r of row) {\r\n rows.push(this.create(r, false))\r\n }\r\n dispatch && this.dispatch()\r\n return rows\r\n }\r\n\r\n // validate and create row\r\n let r = {} as MakeRowType<RS>\r\n for (let key in this._rowSchema) {\r\n const schema = this._rowSchema[key]\r\n const value = (row as any)[key]\r\n if (key === \"id\" || key === \"observe\") continue;\r\n (r as any)[key] = schema.parse(value)\r\n }\r\n\r\n const _row: MakeRowType<RS> = {\r\n ...r,\r\n id: this._rows.length > 0\r\n ? this._rows[this._rows.length - 1].id + 1\r\n : 1,\r\n observe: Date.now(),\r\n }\r\n\r\n this._rows.push(_row)\r\n dispatch && this.dispatch()\r\n return _row\r\n }\r\n\r\n\r\n // update\r\n update(row: Partial<MakeRowType<RS>>, where?: WhereType<RS> | null, dispatch = true): MakeRowType<RS> | null {\r\n\r\n // validate row\r\n let r = {} as MakeRowType<RS>\r\n for (let key in this._rowSchema) {\r\n const schema = this._rowSchema[key]\r\n const value = (row as any)[key]\r\n if (key === \"id\" || key === \"observe\") continue;\r\n if (value !== undefined) {\r\n (r as any)[key] = schema.parse(value)\r\n }\r\n }\r\n\r\n const rows = this.find(where)\r\n if (rows.length > 0) {\r\n for (let index = 0; index < this._rows.length; index++) {\r\n const _row = rows[index];\r\n rows[index] = {\r\n ..._row,\r\n ...r,\r\n id: _row.id,\r\n observe: Date.now(),\r\n }\r\n }\r\n dispatch && this.dispatch()\r\n }\r\n return null\r\n }\r\n\r\n // delete\r\n delete(where?: WhereType<RS> | null, dispatch = true): number {\r\n const rows = this.find(where, false)\r\n\r\n let deletedCount = 0\r\n if (rows.length > 0) {\r\n this._rows = this._rows.filter(r => !rows.find(dr => dr.id === r.id))\r\n deletedCount = rows.length\r\n dispatch && this.dispatch()\r\n }\r\n return deletedCount\r\n }\r\n\r\n // find\r\n find(where?: WhereType<RS> | null, use = true): MakeRowType<RS>[] {\r\n use && this.useHook()\r\n\r\n if (!where) {\r\n return this._rows\r\n }\r\n\r\n const rows: MakeRowType<RS>[] = []\r\n for (let key in where) {\r\n const wvalue = (where as any)[key]\r\n if (typeof wvalue === \"object\" && wvalue !== null) {\r\n // QueryValueType\r\n for (let row of this._rows) {\r\n let match = true\r\n const rvalue = (row as any)[key]\r\n if (wvalue.contain !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wvalue.contain === \"string\") {\r\n if (!rvalue.includes(wvalue.contain)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.startWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wvalue.startWith === \"string\") {\r\n if (!rvalue.startsWith(wvalue.startWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.endWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wvalue.endWith === \"string\") {\r\n if (!rvalue.endsWith(wvalue.endWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.equalWith !== undefined) {\r\n if (rvalue !== wvalue.equalWith) {\r\n match = false\r\n }\r\n }\r\n if (wvalue.notEqualWith !== undefined) {\r\n if (rvalue === wvalue.notEqualWith) {\r\n match = false\r\n }\r\n }\r\n if (wvalue.gt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue > wvalue.gt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.lt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue < wvalue.lt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.gte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue >= wvalue.gte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wvalue.lte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue <= wvalue.lte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (match) {\r\n rows.push(row)\r\n }\r\n }\r\n } else {\r\n // RowValueType\r\n for (let row of this._rows) {\r\n if ((row as any)[key] === wvalue) {\r\n rows.push(row)\r\n }\r\n }\r\n }\r\n }\r\n return rows\r\n }\r\n\r\n findOne(where: WhereType<RS>, use = true): MakeRowType<RS> | null {\r\n const rows = this.find(where, use)\r\n return rows.length > 0 ? rows[0] : null\r\n }\r\n\r\n findById(id: string, use = true): MakeRowType<RS> | null {\r\n return this.findOne({ id }, use)\r\n }\r\n\r\n getIndex(where: WhereType<RS>, use = true): number {\r\n use && this.useHook()\r\n const row = this.findOne(where, false)\r\n if (row) {\r\n return this._rows.findIndex(r => r.id === row.id)\r\n }\r\n return -1\r\n }\r\n\r\n move(fromIndex: number, toIndex: number, dispatch = true): boolean {\r\n if (fromIndex < 0 || fromIndex >= this._rows.length) return false\r\n if (toIndex < 0 || toIndex >= this._rows.length) return false\r\n const [movedRow] = this._rows.splice(fromIndex, 1)\r\n this._rows.splice(toIndex, 0, movedRow)\r\n dispatch && this.dispatch()\r\n return true\r\n }\r\n\r\n // Meta Methods\r\n setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], dispatch = true) {\r\n this._meta.set(key, value)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n getMeta<T extends keyof Infer<MS>>(key: T, use = true): Infer<MS>[T] | undefined {\r\n use && this.useHook()\r\n return this._meta.get(key) as Infer<MS>[T] | undefined\r\n }\r\n\r\n deleteMeta<T extends keyof Infer<MS>>(key: T, dispatch = true) {\r\n this._meta.delete(key)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n clearMeta(dispatch = true) {\r\n this._meta.clear()\r\n dispatch && this.dispatch()\r\n }\r\n}\r\n\r\nexport default Store"],"names":[],"mappings":";;;;AAKA;;;AAEW;AACA;;;;AAiBF;;AAEA;;AAGG;AACG;AACH;;AAEH;AACF;AAAC;AAED;AACJ;;AAGG;AACA;;;AAGS;AACF;AAAC;AACC;AACF;AACJ;;AAEN;AApCG;AAKA;;;AAkCA;;;;AAKA;;;AAOH;AACG;;AAEG;AACG;AACF;AACD;AACA;AACF;;;AAID;;AAEG;AACA;;;AAEF;AAED;AAGM;;AAKN;AACA;AACA;;;AAKH;;;AAIG;;AAEG;AACA;;;;AAGC;AACH;;AAGD;AACG;AACG;;AAOF;AACD;AACF;AACD;;;AAIH;;;AAIG;AACG;AACA;AACA;AACF;AACD;;;AAIH;AACG;;;AAIC;;AAGD;AACG;;;AAGG;;AAEG;AACA;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;AACF;AACH;AACH;AAAM;;AAEJ;AACG;AACG;AACF;AACH;AACH;AACH;AACD;;AAGH;;AAEG;;AAGH;;;AAIA;AACG;;AAEA;AACG;AACF;;;AAIJ;;AACwD;;AACJ;AACjD;;AAEA;AACA;;;AAIH;;AAEG;;AAGH;AACG;;;AAIH;AACG;AACA;;;AAIA;AACA;;AAEL;;"}
1
+ {"version":3,"file":"Store.mjs","sources":["../src/Store.ts"],"sourcesContent":["\"use client\"\r\nimport { useEffect, useId, useState } from \"react\"\r\nimport { MakeMetaType, MakeRowType, MetaSchema, RowSchema, WhereType } from \"./types\"\r\nimport { Infer, xv } from \"xanv\"\r\n\r\nclass Store<RS extends RowSchema, MS extends MetaSchema | undefined = undefined> {\r\n private _rows: MakeRowType<RS>[] = []\r\n private _meta: Map<keyof MakeMetaType<MS>, MakeMetaType<MS>[keyof MakeMetaType<MS>]> = new Map()\r\n private _hooks: Map<string, Function> = new Map()\r\n private _timer: any = null\r\n private _row_schema: RS\r\n private _meta_schema?: MS\r\n private _last_id = 0\r\n\r\n constructor(rowSchema: RS, metaSchema?: MS) {\r\n this._row_schema = {\r\n ...rowSchema,\r\n rid: xv.number(),\r\n vid: xv.number().default(() => Math.round((Math.random() + Math.random()) * 9999999999)),\r\n }\r\n this._meta_schema = metaSchema\r\n }\r\n\r\n private use = () => {\r\n try {\r\n const hid = useId()\r\n const [, dispatch] = useState(0)\r\n this._hooks.set(hid, () => dispatch(Math.random()))\r\n useEffect(() => () => {\r\n this._hooks.delete(hid)\r\n }, [])\r\n } catch (error) { }\r\n }\r\n\r\n private dispatch = () => {\r\n clearTimeout(this._timer)\r\n this._timer = setTimeout(() => {\r\n this._hooks.forEach((cb, key) => {\r\n try {\r\n cb()\r\n } catch (_err) {\r\n this._hooks.delete(key)\r\n }\r\n })\r\n }, 0)\r\n }\r\n\r\n rows(use = true) {\r\n use && this.use()\r\n return this._rows\r\n }\r\n\r\n metas(use = true) {\r\n use && this.use()\r\n return this._meta\r\n }\r\n\r\n // Row Methods\r\n create(row: Partial<MakeRowType<RS>>, dispatch?: boolean): MakeRowType<RS>\r\n create(row: Partial<MakeRowType<RS>>[], dispatch?: boolean): MakeRowType<RS>[]\r\n create(row: Partial<MakeRowType<RS>> | Partial<MakeRowType<RS>>[], dispatch = true): MakeRowType<RS> | MakeRowType<RS>[] {\r\n if (Array.isArray(row)) {\r\n const rows: MakeRowType<RS>[] = []\r\n for (const r of row) {\r\n rows.push(this.create(r, false))\r\n }\r\n dispatch && this.dispatch()\r\n return rows\r\n }\r\n\r\n // validate and create row\r\n let r: any = {} as MakeRowType<RS>\r\n for (let key in this._row_schema) {\r\n if (key === \"rid\" || key === \"vid\") continue;\r\n const schema = this._row_schema[key]\r\n r[key] = schema.parse(row[key])\r\n }\r\n\r\n this._last_id = this._last_id + 1;\r\n const _row: MakeRowType<RS> = {\r\n ...r,\r\n rid: this._last_id,\r\n vid: this._row_schema.vid.parse(undefined),\r\n }\r\n\r\n this._rows.push(_row)\r\n dispatch && this.dispatch()\r\n return _row\r\n }\r\n\r\n\r\n // update\r\n update(row: Partial<MakeRowType<RS>>, where?: WhereType<RS> | null, dispatch = true): MakeRowType<RS>[] | null {\r\n\r\n // validate row\r\n let r: any = {} as MakeRowType<RS>\r\n for (let key in row) {\r\n if (key === \"rid\" || key === 'vid') continue;\r\n const schema = this._row_schema[key]\r\n r[key] = schema.parse(row[key])\r\n }\r\n\r\n const rows = this.find(where)\r\n if (rows.length > 0) {\r\n for (let index = 0; index < rows.length; index++) {\r\n const _row = rows[index];\r\n const rid = _row.rid\r\n\r\n rows[index] = {\r\n ..._row,\r\n ...r,\r\n rid,\r\n vid: this._row_schema.vid.parse(undefined),\r\n }\r\n const rowIndex = this._rows.findIndex(r => r.rid === rid)\r\n this._rows[rowIndex] = rows[index]\r\n }\r\n dispatch && this.dispatch()\r\n }\r\n return this.find(where)\r\n }\r\n\r\n // delete\r\n delete(where?: WhereType<RS> | null, dispatch = true): number {\r\n const rows = this.find(where, false)\r\n\r\n let deletedCount = 0\r\n if (rows.length > 0) {\r\n this._rows = this._rows.filter(r => !rows.find(dr => dr.rid === r.rid))\r\n deletedCount = rows.length\r\n dispatch && this.dispatch()\r\n }\r\n return deletedCount\r\n }\r\n\r\n // find\r\n find(where?: WhereType<RS> | null, use = true): MakeRowType<RS>[] {\r\n use && this.use()\r\n\r\n if (!where) {\r\n return this._rows\r\n }\r\n\r\n const rows: MakeRowType<RS>[] = []\r\n for (let key in where) {\r\n const wv = (where as any)[key]\r\n if (typeof wv === \"object\" && wv !== null) {\r\n // QueryValueType\r\n for (let row of this._rows) {\r\n let match = true\r\n const rvalue = (row as any)[key]\r\n if (wv.contain !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wv.contain === \"string\") {\r\n if (!rvalue.includes(wv.contain)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.startWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wv.startWith === \"string\") {\r\n if (!rvalue.startsWith(wv.startWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.endWith !== undefined) {\r\n if (typeof rvalue === \"string\" && typeof wv.endWith === \"string\") {\r\n if (!rvalue.endsWith(wv.endWith)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.equalWith !== undefined) {\r\n if (rvalue !== wv.equalWith) {\r\n match = false\r\n }\r\n }\r\n if (wv.notEqualWith !== undefined) {\r\n if (rvalue === wv.notEqualWith) {\r\n match = false\r\n }\r\n }\r\n if (wv.gt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue > wv.gt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.lt !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue < wv.lt)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.gte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue >= wv.gte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (wv.lte !== undefined) {\r\n if (typeof rvalue === \"number\") {\r\n if (!(rvalue <= wv.lte)) {\r\n match = false\r\n }\r\n } else {\r\n match = false\r\n }\r\n }\r\n if (match) {\r\n rows.push(row)\r\n }\r\n }\r\n } else {\r\n // RowvType\r\n for (let row of this._rows) {\r\n if ((row as any)[key] === wv) {\r\n rows.push(row)\r\n }\r\n }\r\n }\r\n }\r\n return rows\r\n }\r\n\r\n findOne(where: WhereType<RS>, use = true): MakeRowType<RS> | null {\r\n const rows = this.find(where, use)\r\n return rows.length > 0 ? rows[0] : null\r\n }\r\n\r\n findById(rid: string, use = true): MakeRowType<RS> | null {\r\n return this.findOne({ rid }, use)\r\n }\r\n\r\n getIndex(where: WhereType<RS>, use = true): number {\r\n use && this.use()\r\n const row = this.findOne(where, false)\r\n if (row) {\r\n return this._rows.findIndex(r => r.rid === row.rid)\r\n }\r\n return -1\r\n }\r\n\r\n move(fromIndex: number, toIndex: number, dispatch = true): boolean {\r\n if (fromIndex < 0 || fromIndex >= this._rows.length) return false\r\n if (toIndex < 0 || toIndex >= this._rows.length) return false\r\n const [movedRow] = this._rows.splice(fromIndex, 1)\r\n this._rows.splice(toIndex, 0, movedRow)\r\n dispatch && this.dispatch()\r\n return true\r\n }\r\n\r\n // Meta Methods\r\n setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], dispatch = true) {\r\n this._meta.set(key, this._meta_schema ? (this._meta_schema[key] as any).parse(value) : value)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n getMeta<T extends keyof Infer<MS>>(key: T, use = true): Infer<MS>[T] | undefined {\r\n use && this.use()\r\n return this._meta.get(key) as Infer<MS>[T] | undefined\r\n }\r\n\r\n deleteMeta<T extends keyof Infer<MS>>(key: T, dispatch = true) {\r\n this._meta.delete(key)\r\n dispatch && this.dispatch()\r\n }\r\n\r\n clearMeta(dispatch = true) {\r\n this._meta.clear()\r\n dispatch && this.dispatch()\r\n }\r\n}\r\n\r\nexport default Store"],"names":[],"mappings":";;;;AAKA;;;AAEW;AACA;;;;;AAiBF;;AAEA;AACA;AACG;;AAEL;;AACJ;;AAGG;AACA;;;AAGS;AACF;AAAC;AACC;AACF;AACJ;;AAEN;;AAzBG;;;AA4BA;;;;AAKA;;;AAOH;AACG;;AAEG;AACG;AACF;AACD;AACA;AACF;;;AAID;AACG;;;AAEA;AACF;;;AASD;AACA;AACA;;;AAKH;;;AAIG;AACG;;;AAEA;AACF;;AAGD;AACG;AACG;AACA;;AAQA;;AAEF;AACD;AACF;AACD;;;AAIH;;;AAIG;AACG;AACA;AACA;AACF;AACD;;;AAIH;AACG;;;AAIC;;AAGD;AACG;;;AAGG;;AAEG;AACA;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;;;;AAIO;AACH;AAAM;;AAEN;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;AAEC;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;;;AAGI;AACH;AAAM;;AAEN;AACH;AACD;AACG;AACF;AACH;AACH;AAAM;;AAEJ;AACG;AACG;AACF;AACH;AACH;AACH;AACD;;AAGH;;AAEG;;AAGH;;;AAIA;AACG;;AAEA;AACG;AACF;;;AAIJ;;AACwD;;AACJ;AACjD;;AAEA;AACA;;;AAIH;AACG;AACA;;AAGH;AACG;;;AAIH;AACG;AACA;;;AAIA;AACA;;AAEL;;"}
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import Store from './Store.js';
2
2
  import { RowSchema, MetaSchema } from './types.js';
3
+ export { MakeMetaType, MakeRowType, QueryValueType, RowValueType, StoreRID, StoreVID, WhereType } from './types.js';
3
4
 
4
5
  declare const createStore: <RS extends RowSchema, MS extends MetaSchema | undefined = undefined>(rowSchema: RS, metaSchema?: MS | undefined) => Store<RS, MS>;
5
6
 
6
- export { createStore as default };
7
+ export { MetaSchema, RowSchema, Store, createStore as default };
package/index.js CHANGED
@@ -1,11 +1,14 @@
1
1
  "use client";
2
2
  'use strict';
3
3
 
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
4
6
  var Store = require('./Store.js');
5
7
 
6
8
  const createStore = (rowSchema, metaSchema) => {
7
9
  return new Store(rowSchema, metaSchema);
8
10
  };
9
11
 
10
- module.exports = createStore;
12
+ exports.Store = Store;
13
+ exports.default = createStore;
11
14
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["\"use client\"\r\nimport Store from \"./Store\"\r\nimport { MetaSchema, RowSchema } from \"./types\"\r\n\r\nconst createStore = <RS extends RowSchema, MS extends MetaSchema | undefined = undefined>(rowSchema: RS, metaSchema?: MS) => {\r\n return new Store(rowSchema, metaSchema)\r\n}\r\n\r\nexport default createStore"],"names":[],"mappings":";;;;;AAIA;AACI;AACJ;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["\"use client\"\r\nimport Store from \"./Store\"\r\nimport { MetaSchema, RowSchema } from \"./types\"\r\n\r\nconst createStore = <RS extends RowSchema, MS extends MetaSchema | undefined = undefined>(rowSchema: RS, metaSchema?: MS) => {\r\n return new Store(rowSchema, metaSchema)\r\n}\r\n\r\nexport * from \"./types\"\r\nexport { Store }\r\n\r\nexport default createStore"],"names":[],"mappings":";;;;;;;AAIA;AACI;AACJ;;;"}
package/index.mjs CHANGED
@@ -5,5 +5,5 @@ const createStore = (rowSchema, metaSchema) => {
5
5
  return new Store(rowSchema, metaSchema);
6
6
  };
7
7
 
8
- export { createStore as default };
8
+ export { Store, createStore as default };
9
9
  //# sourceMappingURL=index.mjs.map
package/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["\"use client\"\r\nimport Store from \"./Store\"\r\nimport { MetaSchema, RowSchema } from \"./types\"\r\n\r\nconst createStore = <RS extends RowSchema, MS extends MetaSchema | undefined = undefined>(rowSchema: RS, metaSchema?: MS) => {\r\n return new Store(rowSchema, metaSchema)\r\n}\r\n\r\nexport default createStore"],"names":[],"mappings":";;;AAIA;AACI;AACJ;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["\"use client\"\r\nimport Store from \"./Store\"\r\nimport { MetaSchema, RowSchema } from \"./types\"\r\n\r\nconst createStore = <RS extends RowSchema, MS extends MetaSchema | undefined = undefined>(rowSchema: RS, metaSchema?: MS) => {\r\n return new Store(rowSchema, metaSchema)\r\n}\r\n\r\nexport * from \"./types\"\r\nexport { Store }\r\n\r\nexport default createStore"],"names":[],"mappings":";;;AAIA;AACI;AACJ;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-rock",
3
- "version": "3.2.3",
3
+ "version": "3.2.5",
4
4
  "author": "Naxrul Ahmed",
5
5
  "description": "React-Rock is a modern, lightweight state management library designed to simplify handling global state in React applications. With a minimal API and powerful features like freezing data updates for optimized re-renders, React-Rock allows you to manage state more efficiently while ensuring your app remains fast and responsive.",
6
6
  "main": "./index.js",
package/types.d.ts CHANGED
@@ -6,10 +6,13 @@ type RowSchema = {
6
6
  type MetaSchema = {
7
7
  [key: string]: XVInstanceType;
8
8
  };
9
+ type StoreRID = number;
10
+ type StoreVID = number;
9
11
  type MakeRowType<RS> = Infer<RS> & {
10
- id: number;
11
- observe: number;
12
+ rid: StoreRID;
13
+ vid: StoreVID;
12
14
  };
15
+ type MakeMetaType<MS> = Infer<MS>;
13
16
  type RowValueType = string | number | boolean | null | undefined;
14
17
  type QueryValueType = {
15
18
  contain?: RowValueType;
@@ -23,7 +26,7 @@ type QueryValueType = {
23
26
  lte?: number;
24
27
  };
25
28
  type WhereType<RS> = {
26
- [key in keyof Infer<RS>]?: RowValueType | QueryValueType;
29
+ [key in keyof MakeRowType<RS>]?: RowValueType | QueryValueType;
27
30
  };
28
31
 
29
- export type { MakeRowType, MetaSchema, QueryValueType, RowSchema, RowValueType, WhereType };
32
+ export type { MakeMetaType, MakeRowType, MetaSchema, QueryValueType, RowSchema, RowValueType, StoreRID, StoreVID, WhereType };