react-rock 3.2.10 → 3.2.12
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.cjs +252 -287
- package/Store.cjs.map +1 -1
- package/Store.d.ts +25 -25
- package/Store.js +252 -287
- package/Store.js.map +1 -1
- package/index.cjs +2 -2
- package/index.cjs.map +1 -1
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +230 -230
- package/types.d.ts +60 -60
package/Store.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { RowSchema, MetaSchema, MakeRowType, CreateManyArgs, CreateArgs, UpdateArgs, DeleteArgs, FindArgs, MoveArgs } from './types.js';
|
|
2
2
|
import { Infer } from 'xanv';
|
|
3
3
|
|
|
4
|
-
declare class Store<RS extends RowSchema, MS extends MetaSchema | undefined = undefined> {
|
|
5
|
-
private _rows;
|
|
6
|
-
private _meta;
|
|
7
|
-
private _hooks;
|
|
8
|
-
private _timer;
|
|
9
|
-
private _row_schema;
|
|
10
|
-
private _meta_schema?;
|
|
11
|
-
private _last_id;
|
|
12
|
-
constructor(rowSchema: RS, metaSchema?: MS);
|
|
13
|
-
private observe;
|
|
14
|
-
dispatch(observeIdOrCallbabck?: string | ((cb: Function, key: string) => void)): void;
|
|
15
|
-
rows(observe?: boolean): MakeRowType<RS>[];
|
|
16
|
-
metas(observe?: boolean): Map<keyof Infer<MS>, Infer<MS>[keyof Infer<MS>]>;
|
|
17
|
-
createMany(args: CreateManyArgs<RS>): MakeRowType<RS>[];
|
|
18
|
-
create(args: CreateArgs<RS>): MakeRowType<RS>;
|
|
19
|
-
update(args: UpdateArgs<RS>): MakeRowType<RS>[] | null;
|
|
20
|
-
delete(args: DeleteArgs<RS>): number;
|
|
21
|
-
find(args: FindArgs<RS>): MakeRowType<RS>[];
|
|
22
|
-
findOne(args: FindArgs<RS>): MakeRowType<RS> | null;
|
|
23
|
-
getIndex(args: FindArgs<RS>): number;
|
|
24
|
-
move(args: MoveArgs<RS>): boolean;
|
|
25
|
-
setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], observe?: boolean): void;
|
|
26
|
-
getMeta<T extends keyof Infer<MS>>(key: T, observe?: boolean): Infer<MS>[T] | undefined;
|
|
27
|
-
deleteMeta<T extends keyof Infer<MS>>(key: T, observe?: boolean): void;
|
|
28
|
-
clearMeta(observe?: boolean): void;
|
|
4
|
+
declare class Store<RS extends RowSchema, MS extends MetaSchema | undefined = undefined> {
|
|
5
|
+
private _rows;
|
|
6
|
+
private _meta;
|
|
7
|
+
private _hooks;
|
|
8
|
+
private _timer;
|
|
9
|
+
private _row_schema;
|
|
10
|
+
private _meta_schema?;
|
|
11
|
+
private _last_id;
|
|
12
|
+
constructor(rowSchema: RS, metaSchema?: MS);
|
|
13
|
+
private observe;
|
|
14
|
+
dispatch(observeIdOrCallbabck?: string | ((cb: Function, key: string) => void)): void;
|
|
15
|
+
rows(observe?: boolean): MakeRowType<RS>[];
|
|
16
|
+
metas(observe?: boolean): Map<keyof Infer<MS>, Infer<MS>[keyof Infer<MS>]>;
|
|
17
|
+
createMany(args: CreateManyArgs<RS>): MakeRowType<RS>[];
|
|
18
|
+
create(args: CreateArgs<RS>): MakeRowType<RS>;
|
|
19
|
+
update(args: UpdateArgs<RS>): MakeRowType<RS>[] | null;
|
|
20
|
+
delete(args: DeleteArgs<RS>): number;
|
|
21
|
+
find(args: FindArgs<RS>): MakeRowType<RS>[];
|
|
22
|
+
findOne(args: FindArgs<RS>): MakeRowType<RS> | null;
|
|
23
|
+
getIndex(args: FindArgs<RS>): number;
|
|
24
|
+
move(args: MoveArgs<RS>): boolean;
|
|
25
|
+
setMeta<T extends keyof Infer<MS>>(key: T, value: Infer<MS>[T], observe?: boolean): void;
|
|
26
|
+
getMeta<T extends keyof Infer<MS>>(key: T, observe?: boolean): Infer<MS>[T] | undefined;
|
|
27
|
+
deleteMeta<T extends keyof Infer<MS>>(key: T, observe?: boolean): void;
|
|
28
|
+
clearMeta(observe?: boolean): void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export { Store as default };
|
package/Store.js
CHANGED
|
@@ -2,293 +2,258 @@
|
|
|
2
2
|
import { useId, useState, useEffect } from 'react';
|
|
3
3
|
import { xv } from 'xanv';
|
|
4
4
|
|
|
5
|
-
const uid = useId;
|
|
6
|
-
const ustate = useState;
|
|
7
|
-
const ueffect = useEffect;
|
|
8
|
-
class Store {
|
|
9
|
-
constructor(rowSchema, metaSchema) {
|
|
10
|
-
this._rows = [];
|
|
11
|
-
this._meta = new Map();
|
|
12
|
-
this._hooks = new Map();
|
|
13
|
-
this._timer = null;
|
|
14
|
-
this._last_id = 0;
|
|
15
|
-
this.observe = (observeId) => {
|
|
16
|
-
try {
|
|
17
|
-
const hid = uid();
|
|
18
|
-
const id = observeId || hid;
|
|
19
|
-
const [, dispatch] = ustate(0);
|
|
20
|
-
this._hooks.set(id, () => dispatch(Math.random()));
|
|
21
|
-
ueffect(() => () => {
|
|
22
|
-
this._hooks.delete(id);
|
|
23
|
-
}, []);
|
|
24
|
-
}
|
|
25
|
-
catch (error) { }
|
|
26
|
-
};
|
|
27
|
-
this._row_schema = Object.assign(Object.assign({}, rowSchema), { rid: xv.number(), vid: xv.number().default(() => Math.round((Math.random() + Math.random()) * 9999999999)) });
|
|
28
|
-
this._meta_schema = metaSchema;
|
|
29
|
-
}
|
|
30
|
-
dispatch(observeIdOrCallbabck) {
|
|
31
|
-
clearTimeout(this._timer);
|
|
32
|
-
const isFn = typeof observeIdOrCallbabck === "function";
|
|
33
|
-
this._timer = setTimeout(() => {
|
|
34
|
-
this._hooks.forEach((cb, key) => {
|
|
35
|
-
try {
|
|
36
|
-
if (isFn) {
|
|
37
|
-
observeIdOrCallbabck(cb, key);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
if (observeIdOrCallbabck) {
|
|
41
|
-
if (key === observeIdOrCallbabck) {
|
|
42
|
-
cb();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
cb();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (_err) {
|
|
51
|
-
this._hooks.delete(key);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}, 0);
|
|
55
|
-
}
|
|
56
|
-
rows(observe = true) {
|
|
57
|
-
observe && this.observe();
|
|
58
|
-
return this._rows;
|
|
59
|
-
}
|
|
60
|
-
metas(observe = true) {
|
|
61
|
-
observe && this.observe();
|
|
62
|
-
return this._meta;
|
|
63
|
-
}
|
|
64
|
-
createMany(args) {
|
|
65
|
-
const { data,
|
|
66
|
-
const res = [];
|
|
67
|
-
for (let row of data) {
|
|
68
|
-
const created = this.create({
|
|
69
|
-
data: row,
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
res.push(created);
|
|
73
|
-
}
|
|
74
|
-
if (!
|
|
75
|
-
this.dispatch(observeId);
|
|
76
|
-
}
|
|
77
|
-
return res;
|
|
78
|
-
}
|
|
79
|
-
// Row Methods
|
|
80
|
-
create(args) {
|
|
81
|
-
const { data,
|
|
82
|
-
// validate and create row
|
|
83
|
-
let r = {};
|
|
84
|
-
for (let key in this._row_schema) {
|
|
85
|
-
if (key === "rid" || key === "vid")
|
|
86
|
-
continue;
|
|
87
|
-
const schema = this._row_schema[key];
|
|
88
|
-
r[key] = schema.parse(data[key]);
|
|
89
|
-
}
|
|
90
|
-
this._last_id = this._last_id + 1;
|
|
91
|
-
const _row = Object.assign(Object.assign({}, r), { rid: this._last_id, vid: this._row_schema.vid.parse(undefined) });
|
|
92
|
-
this._rows.push(_row);
|
|
93
|
-
if (!
|
|
94
|
-
this.dispatch(observeId);
|
|
95
|
-
}
|
|
96
|
-
return _row;
|
|
97
|
-
}
|
|
98
|
-
// update
|
|
99
|
-
update(args) {
|
|
100
|
-
const { data, where,
|
|
101
|
-
// validate row
|
|
102
|
-
let r = {};
|
|
103
|
-
for (let key in data) {
|
|
104
|
-
if (key === "rid" || key === 'vid')
|
|
105
|
-
continue;
|
|
106
|
-
const schema = this._row_schema[key];
|
|
107
|
-
r[key] = schema.parse(data[key]);
|
|
108
|
-
}
|
|
109
|
-
const rows = this.find({ where });
|
|
110
|
-
if (rows.length > 0) {
|
|
111
|
-
for (let index = 0; index < rows.length; index++) {
|
|
112
|
-
const _row = rows[index];
|
|
113
|
-
const rid = _row.rid;
|
|
114
|
-
rows[index] = Object.assign(Object.assign(Object.assign({}, _row), r), { rid, vid: this._row_schema.vid.parse(undefined) });
|
|
115
|
-
const rowIndex = this._rows.findIndex(r => r.rid === rid);
|
|
116
|
-
this._rows[rowIndex] = rows[index];
|
|
117
|
-
}
|
|
118
|
-
if (!
|
|
119
|
-
this.dispatch(observeId);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return this.find({ where,
|
|
123
|
-
}
|
|
124
|
-
// delete
|
|
125
|
-
delete(args) {
|
|
126
|
-
const { where,
|
|
127
|
-
const rows = this.find({
|
|
128
|
-
where,
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
let deletedCount = 0;
|
|
132
|
-
if (rows.length > 0) {
|
|
133
|
-
this._rows = this._rows.filter(r => !rows.find(dr => dr.rid === r.rid));
|
|
134
|
-
deletedCount = rows.length;
|
|
135
|
-
if (!
|
|
136
|
-
this.dispatch(observeId);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return deletedCount;
|
|
140
|
-
}
|
|
141
|
-
// find
|
|
142
|
-
find(args) {
|
|
143
|
-
|
|
144
|
-
if (!
|
|
145
|
-
this.observe(observeId);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
getIndex(args) {
|
|
258
|
-
const row = this.findOne(args);
|
|
259
|
-
if (row) {
|
|
260
|
-
return this._rows.findIndex(r => r.rid === row.rid);
|
|
261
|
-
}
|
|
262
|
-
return -1;
|
|
263
|
-
}
|
|
264
|
-
move(args) {
|
|
265
|
-
const { fromIndex, toIndex, disablelObservation, observeId } = args;
|
|
266
|
-
if (fromIndex < 0 || toIndex < 0)
|
|
267
|
-
return false;
|
|
268
|
-
const [movedRow] = this._rows.splice(fromIndex, 1);
|
|
269
|
-
this._rows.splice(toIndex, 0, movedRow);
|
|
270
|
-
if (!disablelObservation) {
|
|
271
|
-
this.dispatch(observeId);
|
|
272
|
-
}
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
// Meta Methods
|
|
276
|
-
setMeta(key, value, observe = true) {
|
|
277
|
-
this._meta.set(key, this._meta_schema ? this._meta_schema[key].parse(value) : value);
|
|
278
|
-
observe && this.dispatch();
|
|
279
|
-
}
|
|
280
|
-
getMeta(key, observe = true) {
|
|
281
|
-
observe && this.observe();
|
|
282
|
-
return this._meta.get(key);
|
|
283
|
-
}
|
|
284
|
-
deleteMeta(key, observe = true) {
|
|
285
|
-
this._meta.delete(key);
|
|
286
|
-
observe && this.dispatch();
|
|
287
|
-
}
|
|
288
|
-
clearMeta(observe = true) {
|
|
289
|
-
this._meta.clear();
|
|
290
|
-
observe && this.dispatch();
|
|
291
|
-
}
|
|
5
|
+
const uid = useId;
|
|
6
|
+
const ustate = useState;
|
|
7
|
+
const ueffect = useEffect;
|
|
8
|
+
class Store {
|
|
9
|
+
constructor(rowSchema, metaSchema) {
|
|
10
|
+
this._rows = [];
|
|
11
|
+
this._meta = new Map();
|
|
12
|
+
this._hooks = new Map();
|
|
13
|
+
this._timer = null;
|
|
14
|
+
this._last_id = 0;
|
|
15
|
+
this.observe = (observeId) => {
|
|
16
|
+
try {
|
|
17
|
+
const hid = uid();
|
|
18
|
+
const id = observeId || hid;
|
|
19
|
+
const [, dispatch] = ustate(0);
|
|
20
|
+
this._hooks.set(id, () => dispatch(Math.random()));
|
|
21
|
+
ueffect(() => () => {
|
|
22
|
+
this._hooks.delete(id);
|
|
23
|
+
}, []);
|
|
24
|
+
}
|
|
25
|
+
catch (error) { }
|
|
26
|
+
};
|
|
27
|
+
this._row_schema = Object.assign(Object.assign({}, rowSchema), { rid: xv.number(), vid: xv.number().default(() => Math.round((Math.random() + Math.random()) * 9999999999)) });
|
|
28
|
+
this._meta_schema = metaSchema;
|
|
29
|
+
}
|
|
30
|
+
dispatch(observeIdOrCallbabck) {
|
|
31
|
+
clearTimeout(this._timer);
|
|
32
|
+
const isFn = typeof observeIdOrCallbabck === "function";
|
|
33
|
+
this._timer = setTimeout(() => {
|
|
34
|
+
this._hooks.forEach((cb, key) => {
|
|
35
|
+
try {
|
|
36
|
+
if (isFn) {
|
|
37
|
+
observeIdOrCallbabck(cb, key);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (observeIdOrCallbabck) {
|
|
41
|
+
if (key === observeIdOrCallbabck) {
|
|
42
|
+
cb();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
cb();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (_err) {
|
|
51
|
+
this._hooks.delete(key);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}, 0);
|
|
55
|
+
}
|
|
56
|
+
rows(observe = true) {
|
|
57
|
+
observe && this.observe();
|
|
58
|
+
return this._rows;
|
|
59
|
+
}
|
|
60
|
+
metas(observe = true) {
|
|
61
|
+
observe && this.observe();
|
|
62
|
+
return this._meta;
|
|
63
|
+
}
|
|
64
|
+
createMany(args) {
|
|
65
|
+
const { data, disableObservation, observeId } = args;
|
|
66
|
+
const res = [];
|
|
67
|
+
for (let row of data) {
|
|
68
|
+
const created = this.create({
|
|
69
|
+
data: row,
|
|
70
|
+
disableObservation: true
|
|
71
|
+
});
|
|
72
|
+
res.push(created);
|
|
73
|
+
}
|
|
74
|
+
if (!disableObservation) {
|
|
75
|
+
this.dispatch(observeId);
|
|
76
|
+
}
|
|
77
|
+
return res;
|
|
78
|
+
}
|
|
79
|
+
// Row Methods
|
|
80
|
+
create(args) {
|
|
81
|
+
const { data, disableObservation, observeId } = args;
|
|
82
|
+
// validate and create row
|
|
83
|
+
let r = {};
|
|
84
|
+
for (let key in this._row_schema) {
|
|
85
|
+
if (key === "rid" || key === "vid")
|
|
86
|
+
continue;
|
|
87
|
+
const schema = this._row_schema[key];
|
|
88
|
+
r[key] = schema.parse(data[key]);
|
|
89
|
+
}
|
|
90
|
+
this._last_id = this._last_id + 1;
|
|
91
|
+
const _row = Object.assign(Object.assign({}, r), { rid: this._last_id, vid: this._row_schema.vid.parse(undefined) });
|
|
92
|
+
this._rows.push(_row);
|
|
93
|
+
if (!disableObservation) {
|
|
94
|
+
this.dispatch(observeId);
|
|
95
|
+
}
|
|
96
|
+
return _row;
|
|
97
|
+
}
|
|
98
|
+
// update
|
|
99
|
+
update(args) {
|
|
100
|
+
const { data, where, disableObservation, observeId } = args;
|
|
101
|
+
// validate row
|
|
102
|
+
let r = {};
|
|
103
|
+
for (let key in data) {
|
|
104
|
+
if (key === "rid" || key === 'vid')
|
|
105
|
+
continue;
|
|
106
|
+
const schema = this._row_schema[key];
|
|
107
|
+
r[key] = schema.parse(data[key]);
|
|
108
|
+
}
|
|
109
|
+
const rows = this.find({ where });
|
|
110
|
+
if (rows.length > 0) {
|
|
111
|
+
for (let index = 0; index < rows.length; index++) {
|
|
112
|
+
const _row = rows[index];
|
|
113
|
+
const rid = _row.rid;
|
|
114
|
+
rows[index] = Object.assign(Object.assign(Object.assign({}, _row), r), { rid, vid: this._row_schema.vid.parse(undefined) });
|
|
115
|
+
const rowIndex = this._rows.findIndex(r => r.rid === rid);
|
|
116
|
+
this._rows[rowIndex] = rows[index];
|
|
117
|
+
}
|
|
118
|
+
if (!disableObservation) {
|
|
119
|
+
this.dispatch(observeId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return this.find({ where, disableObservation: true });
|
|
123
|
+
}
|
|
124
|
+
// delete
|
|
125
|
+
delete(args) {
|
|
126
|
+
const { where, disableObservation, observeId } = args;
|
|
127
|
+
const rows = this.find({
|
|
128
|
+
where,
|
|
129
|
+
disableObservation: true
|
|
130
|
+
});
|
|
131
|
+
let deletedCount = 0;
|
|
132
|
+
if (rows.length > 0) {
|
|
133
|
+
this._rows = this._rows.filter(r => !rows.find(dr => dr.rid === r.rid));
|
|
134
|
+
deletedCount = rows.length;
|
|
135
|
+
if (!disableObservation) {
|
|
136
|
+
this.dispatch(observeId);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return deletedCount;
|
|
140
|
+
}
|
|
141
|
+
// find
|
|
142
|
+
find(args) {
|
|
143
|
+
const { where, disableObservation, observeId } = args;
|
|
144
|
+
if (!disableObservation) {
|
|
145
|
+
this.observe(observeId);
|
|
146
|
+
}
|
|
147
|
+
const rows = [];
|
|
148
|
+
for (const row of this._rows) {
|
|
149
|
+
let match = true;
|
|
150
|
+
for (const wcol in where) {
|
|
151
|
+
const condition = where[wcol];
|
|
152
|
+
const rvalue = row[wcol];
|
|
153
|
+
if (typeof condition === "object" && condition !== null) {
|
|
154
|
+
if (condition.contain !== undefined) {
|
|
155
|
+
if (typeof rvalue !== "string" || !rvalue.includes(condition.contain)) {
|
|
156
|
+
match = false;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (condition.startWith !== undefined) {
|
|
161
|
+
if (typeof rvalue !== "string" || !rvalue.startsWith(condition.startWith)) {
|
|
162
|
+
match = false;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (condition.endWith !== undefined) {
|
|
167
|
+
if (typeof rvalue !== "string" || !rvalue.endsWith(condition.endWith)) {
|
|
168
|
+
match = false;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (condition.equalWith !== undefined && rvalue !== condition.equalWith) {
|
|
173
|
+
match = false;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (condition.notEqualWith !== undefined && rvalue === condition.notEqualWith) {
|
|
177
|
+
match = false;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
if (condition.gt !== undefined) {
|
|
181
|
+
if (typeof rvalue !== "number" || !(rvalue > condition.gt)) {
|
|
182
|
+
match = false;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (condition.lt !== undefined) {
|
|
187
|
+
if (typeof rvalue !== "number" || !(rvalue < condition.lt)) {
|
|
188
|
+
match = false;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (condition.gte !== undefined) {
|
|
193
|
+
if (typeof rvalue !== "number" || !(rvalue >= condition.gte)) {
|
|
194
|
+
match = false;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (condition.lte !== undefined) {
|
|
199
|
+
if (typeof rvalue !== "number" || !(rvalue <= condition.lte)) {
|
|
200
|
+
match = false;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
if (condition !== rvalue) {
|
|
207
|
+
match = false;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (match) {
|
|
213
|
+
rows.push(row);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return rows;
|
|
217
|
+
}
|
|
218
|
+
findOne(args) {
|
|
219
|
+
const rows = this.find(args);
|
|
220
|
+
return rows.length > 0 ? rows[0] : null;
|
|
221
|
+
}
|
|
222
|
+
getIndex(args) {
|
|
223
|
+
const row = this.findOne(args);
|
|
224
|
+
if (row) {
|
|
225
|
+
return this._rows.findIndex(r => r.rid === row.rid);
|
|
226
|
+
}
|
|
227
|
+
return -1;
|
|
228
|
+
}
|
|
229
|
+
move(args) {
|
|
230
|
+
const { fromIndex, toIndex, disableObservation, observeId } = args;
|
|
231
|
+
if (fromIndex < 0 || toIndex < 0)
|
|
232
|
+
return false;
|
|
233
|
+
const [movedRow] = this._rows.splice(fromIndex, 1);
|
|
234
|
+
this._rows.splice(toIndex, 0, movedRow);
|
|
235
|
+
if (!disableObservation) {
|
|
236
|
+
this.dispatch(observeId);
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
// Meta Methods
|
|
241
|
+
setMeta(key, value, observe = true) {
|
|
242
|
+
this._meta.set(key, this._meta_schema ? this._meta_schema[key].parse(value) : value);
|
|
243
|
+
observe && this.dispatch();
|
|
244
|
+
}
|
|
245
|
+
getMeta(key, observe = true) {
|
|
246
|
+
observe && this.observe();
|
|
247
|
+
return this._meta.get(key);
|
|
248
|
+
}
|
|
249
|
+
deleteMeta(key, observe = true) {
|
|
250
|
+
this._meta.delete(key);
|
|
251
|
+
observe && this.dispatch();
|
|
252
|
+
}
|
|
253
|
+
clearMeta(observe = true) {
|
|
254
|
+
this._meta.clear();
|
|
255
|
+
observe && this.dispatch();
|
|
256
|
+
}
|
|
292
257
|
}
|
|
293
258
|
|
|
294
259
|
export { Store as default };
|