@superutils/store 0.1.17 → 0.1.19
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/README.md +69 -50
- package/dist/browser/index.min.js +2 -2
- package/dist/browser/index.min.js.map +1 -1
- package/dist/index.cjs +59 -25
- package/dist/index.d.cts +426 -330
- package/dist/index.d.ts +426 -330
- package/dist/index.js +59 -26
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/createObjectStore.ts
|
|
2
|
-
import { objToMap, isObj as isObj2 } from "@superutils/core";
|
|
2
|
+
import { objToMap, isObj as isObj2, isMap as isMap2 } from "@superutils/core";
|
|
3
3
|
|
|
4
4
|
// src/createStore.ts
|
|
5
5
|
import { isFn as isFn2, isObj } from "@superutils/core";
|
|
@@ -85,7 +85,11 @@ var _Store = class _Store {
|
|
|
85
85
|
this.handleSubjectChange = (data) => {
|
|
86
86
|
var _a;
|
|
87
87
|
if (!isMap(data)) return this.subject$.next(/* @__PURE__ */ new Map());
|
|
88
|
-
fallbackIfFails(
|
|
88
|
+
fallbackIfFails(
|
|
89
|
+
this.write,
|
|
90
|
+
[data],
|
|
91
|
+
this.triggerOnErrorCb("write" /* write */)
|
|
92
|
+
);
|
|
89
93
|
fallbackIfFails(
|
|
90
94
|
(_a = this.onChange) == null ? void 0 : _a.bind(this),
|
|
91
95
|
[data],
|
|
@@ -247,7 +251,8 @@ var _Store = class _Store {
|
|
|
247
251
|
return false;
|
|
248
252
|
}
|
|
249
253
|
};
|
|
250
|
-
|
|
254
|
+
var _a;
|
|
255
|
+
this.name = `${(_a = name != null ? name : options == null ? void 0 : options.name) != null ? _a : ""}`.trim() || null;
|
|
251
256
|
const {
|
|
252
257
|
cacheDisabled = false,
|
|
253
258
|
delay,
|
|
@@ -258,7 +263,7 @@ var _Store = class _Store {
|
|
|
258
263
|
parse,
|
|
259
264
|
spaces,
|
|
260
265
|
storage = fallbackIfFails(
|
|
261
|
-
() => !name ? void 0 : globalThis.localStorage,
|
|
266
|
+
() => !this.name ? void 0 : globalThis.localStorage,
|
|
262
267
|
[],
|
|
263
268
|
void 0
|
|
264
269
|
),
|
|
@@ -309,37 +314,64 @@ var Store = _Store;
|
|
|
309
314
|
var Store_default = Store;
|
|
310
315
|
|
|
311
316
|
// src/createStore.ts
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
317
|
+
var isStoreKey = (store, key) => OPTIONAL_STORE_PROPS.includes(key) || store[key] !== void 0;
|
|
318
|
+
var OPTIONAL_STORE_PROPS = [
|
|
319
|
+
"delayOptions",
|
|
320
|
+
"name",
|
|
321
|
+
"onChange",
|
|
322
|
+
"onError",
|
|
323
|
+
"parse",
|
|
324
|
+
"spaces",
|
|
325
|
+
"storage",
|
|
326
|
+
"stringify",
|
|
327
|
+
"validate"
|
|
328
|
+
];
|
|
329
|
+
function createStore(options, context) {
|
|
330
|
+
const store = new Store_default(options == null ? void 0 : options.name, options);
|
|
331
|
+
const _context = isFn2(context) ? context(store) : context;
|
|
332
|
+
if (!isObj(_context, false)) return store;
|
|
333
|
+
return new Proxy(store, {
|
|
334
|
+
get: (store2, key, receiver) => (
|
|
335
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
336
|
+
Reflect.get(
|
|
337
|
+
isStoreKey(store2, key) ? store2 : _context,
|
|
338
|
+
key,
|
|
339
|
+
receiver
|
|
340
|
+
)
|
|
341
|
+
),
|
|
342
|
+
set: (store2, key, value, receiver) => Reflect.set(
|
|
343
|
+
isStoreKey(store2, key) ? store2 : _context,
|
|
344
|
+
key,
|
|
345
|
+
value,
|
|
346
|
+
receiver
|
|
347
|
+
)
|
|
323
348
|
});
|
|
324
|
-
return store;
|
|
325
349
|
}
|
|
326
350
|
var createStore_default = createStore;
|
|
327
351
|
|
|
328
352
|
// src/createObjectStore.ts
|
|
329
|
-
function createObjectStore(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
name
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return JSON.stringify(this.toObject(data));
|
|
353
|
+
function createObjectStore(options, context) {
|
|
354
|
+
options = {
|
|
355
|
+
// only required for persistent store and can be overriden by options
|
|
356
|
+
...(options == null ? void 0 : options.name) && {
|
|
357
|
+
parse: (str) => objToMap(JSON.parse(str != null ? str : "{}")),
|
|
358
|
+
stringify(data) {
|
|
359
|
+
return JSON.stringify(this.toObject(data));
|
|
360
|
+
}
|
|
338
361
|
},
|
|
339
362
|
...options,
|
|
340
363
|
initialValue: !isObj2(options == null ? void 0 : options.initialValue, true) ? options == null ? void 0 : options.initialValue : objToMap(options.initialValue)
|
|
341
|
-
}
|
|
364
|
+
};
|
|
365
|
+
const store = createStore_default(
|
|
366
|
+
...[options, context]
|
|
367
|
+
);
|
|
342
368
|
store.type = "object";
|
|
369
|
+
const setAll = store.setAll.bind(store);
|
|
370
|
+
store.setAll = (obj, replace) => {
|
|
371
|
+
if (obj && !isMap2(obj)) obj = objToMap(obj);
|
|
372
|
+
return setAll(obj, replace);
|
|
373
|
+
};
|
|
374
|
+
store.toMap = (data) => !data ? store.getAll() : objToMap(data);
|
|
343
375
|
return store;
|
|
344
376
|
}
|
|
345
377
|
|
|
@@ -347,6 +379,7 @@ function createObjectStore(name, options) {
|
|
|
347
379
|
import { objToMap as objToMap2 } from "@superutils/core";
|
|
348
380
|
var index_default = Store_default;
|
|
349
381
|
export {
|
|
382
|
+
OPTIONAL_STORE_PROPS,
|
|
350
383
|
Store,
|
|
351
384
|
Store_OnErrorType,
|
|
352
385
|
createObjectStore,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Toufiqur Rahaman Chowdhury",
|
|
3
3
|
"description": "Generic, reactive, persistent and fully-typed Map-like data store with advanced search, filtering, and sorting capabilities.",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@superutils/core": "^1.2.
|
|
5
|
+
"@superutils/core": "^1.2.22",
|
|
6
6
|
"rxjs": "^7.8.2"
|
|
7
7
|
},
|
|
8
8
|
"exports": {
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"sideEffects": false,
|
|
46
46
|
"type": "module",
|
|
47
47
|
"types": "./dist/index.d.ts",
|
|
48
|
-
"version": "0.1.
|
|
49
|
-
"gitHead": "
|
|
48
|
+
"version": "0.1.19",
|
|
49
|
+
"gitHead": "35722628393f7eface789fea15e80e521c509831"
|
|
50
50
|
}
|