@signaldb/localstorage 1.0.0 → 1.0.1
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/dist/index.mjs +29 -25
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
import { createPersistenceAdapter as
|
|
2
|
-
function
|
|
3
|
-
const { serialize:
|
|
4
|
-
function
|
|
5
|
-
return
|
|
1
|
+
import { createPersistenceAdapter as p } from "@signaldb/core";
|
|
2
|
+
function I(c, o) {
|
|
3
|
+
const { serialize: a = JSON.stringify, deserialize: d = JSON.parse } = o || {}, s = `signaldb-collection-${c}`;
|
|
4
|
+
function i() {
|
|
5
|
+
return d(localStorage.getItem(s) || "[]");
|
|
6
6
|
}
|
|
7
|
-
return
|
|
7
|
+
return p({
|
|
8
8
|
async load() {
|
|
9
|
-
|
|
10
|
-
return Promise.resolve({ items: i });
|
|
9
|
+
return { items: i() };
|
|
11
10
|
},
|
|
12
|
-
async save(
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}), u.forEach((e) => {
|
|
17
|
-
const t = r.findIndex(({ id: o }) => o === e.id);
|
|
11
|
+
async save(l, { added: f, modified: u, removed: g }) {
|
|
12
|
+
const e = [...i()];
|
|
13
|
+
f.forEach((t) => {
|
|
14
|
+
const n = e.findIndex(({ id: r }) => r === t.id);
|
|
18
15
|
/* istanbul ignore if -- @preserve */
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
if (n !== -1) {
|
|
17
|
+
e[n] = t;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
e.push(t);
|
|
21
|
+
}), u.forEach((t) => {
|
|
22
|
+
const n = e.findIndex(({ id: r }) => r === t.id);
|
|
24
23
|
/* istanbul ignore if -- @preserve */
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (n === -1) {
|
|
25
|
+
e.push(t);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
e[n] = t;
|
|
29
|
+
}), g.forEach((t) => {
|
|
30
|
+
const n = e.findIndex(({ id: r }) => r === t.id);
|
|
31
|
+
/* istanbul ignore if -- @preserve */
|
|
32
|
+
n !== -1 && e.splice(n, 1);
|
|
33
|
+
}), localStorage.setItem(s, a(e));
|
|
29
34
|
},
|
|
30
35
|
async register() {
|
|
31
|
-
return Promise.resolve();
|
|
32
36
|
}
|
|
33
37
|
});
|
|
34
38
|
}
|
|
35
39
|
export {
|
|
36
|
-
|
|
40
|
+
I as default
|
|
37
41
|
};
|
|
38
42
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { createPersistenceAdapter } from '@signaldb/core';\n/**\n * Creates a persistence adapter for managing a SignalDB collection using browser `localStorage`.\n * This adapter reads and writes data to `localStorage`, with customizable serialization and deserialization.\n * @template T - The type of the items in the collection.\n * @template I - The type of the unique identifier for the items.\n * @param name - A unique name for the collection, used as the key in `localStorage`.\n * @param options - Optional configuration for serialization and deserialization.\n * @param options.serialize - A function to serialize items to a string (default: `JSON.stringify`).\n * @param options.deserialize - A function to deserialize a string into items (default: `JSON.parse`).\n * @returns A SignalDB persistence adapter for managing data in `localStorage`.\n * @example\n * import createLocalStorageAdapter from './createLocalStorageAdapter';\n *\n * const adapter = createLocalStorageAdapter('myCollection', {\n * serialize: (items) => JSON.stringify(items, null, 2), // Pretty-print JSON\n * deserialize: (itemsString) => JSON.parse(itemsString), // Default JSON parse\n * });\n *\n * const collection = new Collection({\n * persistence: adapter,\n * });\n *\n * // Perform operations on the collection, and changes will be reflected in local storage.\n */\nexport default function createLocalStorageAdapter(name, options) {\n const { serialize = JSON.stringify, deserialize = JSON.parse } = options || {};\n const collectionId = `signaldb-collection-${name}`;\n function getItems() {\n return deserialize(localStorage.getItem(collectionId) || '[]');\n }\n return createPersistenceAdapter({\n async load() {\n const items = getItems();\n return
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { createPersistenceAdapter } from '@signaldb/core';\n/**\n * Creates a persistence adapter for managing a SignalDB collection using browser `localStorage`.\n * This adapter reads and writes data to `localStorage`, with customizable serialization and deserialization.\n * @template T - The type of the items in the collection.\n * @template I - The type of the unique identifier for the items.\n * @param name - A unique name for the collection, used as the key in `localStorage`.\n * @param options - Optional configuration for serialization and deserialization.\n * @param options.serialize - A function to serialize items to a string (default: `JSON.stringify`).\n * @param options.deserialize - A function to deserialize a string into items (default: `JSON.parse`).\n * @returns A SignalDB persistence adapter for managing data in `localStorage`.\n * @example\n * import createLocalStorageAdapter from './createLocalStorageAdapter';\n *\n * const adapter = createLocalStorageAdapter('myCollection', {\n * serialize: (items) => JSON.stringify(items, null, 2), // Pretty-print JSON\n * deserialize: (itemsString) => JSON.parse(itemsString), // Default JSON parse\n * });\n *\n * const collection = new Collection({\n * persistence: adapter,\n * });\n *\n * // Perform operations on the collection, and changes will be reflected in local storage.\n */\nexport default function createLocalStorageAdapter(name, options) {\n const { serialize = JSON.stringify, deserialize = JSON.parse } = options || {};\n const collectionId = `signaldb-collection-${name}`;\n /**\n * Retrieves items from localStorage and deserializes them.\n * @returns The deserialized items from localStorage.\n */\n function getItems() {\n return deserialize(localStorage.getItem(collectionId) || '[]');\n }\n return createPersistenceAdapter({\n async load() {\n const items = getItems();\n return { items };\n },\n async save(_items, { added, modified, removed }) {\n const items = [...getItems()];\n added.forEach((item) => {\n const index = items.findIndex(({ id }) => id === item.id);\n /* istanbul ignore if -- @preserve */\n if (index !== -1) {\n items[index] = item;\n return;\n }\n items.push(item);\n });\n modified.forEach((item) => {\n const index = items.findIndex(({ id }) => id === item.id);\n /* istanbul ignore if -- @preserve */\n if (index === -1) {\n items.push(item);\n return;\n }\n items[index] = item;\n });\n removed.forEach((item) => {\n const index = items.findIndex(({ id }) => id === item.id);\n /* istanbul ignore if -- @preserve */\n if (index === -1)\n return;\n items.splice(index, 1);\n });\n localStorage.setItem(collectionId, serialize(items));\n return;\n },\n async register() {\n return;\n },\n });\n}\n"],"names":["createLocalStorageAdapter","name","options","serialize","deserialize","collectionId","getItems","createPersistenceAdapter","_items","added","modified","removed","items","item","index","id"],"mappings":";AAyBwB,SAAAA,EAA0BC,GAAMC,GAAS;AACvD,QAAA,EAAE,WAAAC,IAAY,KAAK,WAAW,aAAAC,IAAc,KAAK,UAAUF,KAAW,CAAC,GACvEG,IAAe,uBAAuBJ,CAAI;AAKhD,WAASK,IAAW;AAChB,WAAOF,EAAY,aAAa,QAAQC,CAAY,KAAK,IAAI;AAAA,EAAA;AAEjE,SAAOE,EAAyB;AAAA,IAC5B,MAAM,OAAO;AAET,aAAO,EAAE,OADKD,EAAS,EACR;AAAA,IACnB;AAAA,IACA,MAAM,KAAKE,GAAQ,EAAE,OAAAC,GAAO,UAAAC,GAAU,SAAAC,KAAW;AAC7C,YAAMC,IAAQ,CAAC,GAAGN,GAAU;AACtB,MAAAG,EAAA,QAAQ,CAACI,MAAS;AACd,cAAAC,IAAQF,EAAM,UAAU,CAAC,EAAE,IAAAG,QAASA,MAAOF,EAAK,EAAE;AAAA,QAAA;AAExD,YAAIC,MAAU,IAAI;AACd,UAAAF,EAAME,CAAK,IAAID;AACf;AAAA,QAAA;AAEJ,QAAAD,EAAM,KAAKC,CAAI;AAAA,MAAA,CAClB,GACQH,EAAA,QAAQ,CAACG,MAAS;AACjB,cAAAC,IAAQF,EAAM,UAAU,CAAC,EAAE,IAAAG,QAASA,MAAOF,EAAK,EAAE;AAAA,QAAA;AAExD,YAAIC,MAAU,IAAI;AACd,UAAAF,EAAM,KAAKC,CAAI;AACf;AAAA,QAAA;AAEJ,QAAAD,EAAME,CAAK,IAAID;AAAA,MAAA,CAClB,GACOF,EAAA,QAAQ,CAACE,MAAS;AAChB,cAAAC,IAAQF,EAAM,UAAU,CAAC,EAAE,IAAAG,QAASA,MAAOF,EAAK,EAAE;AAAA,QAAA;AAExD,QAAIC,MAAU,MAERF,EAAA,OAAOE,GAAO,CAAC;AAAA,MAAA,CACxB,GACD,aAAa,QAAQT,GAAcF,EAAUS,CAAK,CAAC;AAAA,IAEvD;AAAA,IACA,MAAM,WAAW;AAAA,IACb;AAAA,EACJ,CACH;AACL;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,r){typeof exports=="object"&&typeof module<"u"?module.exports=r(require("@signaldb/core")):typeof define=="function"&&define.amd?define(["@signaldb/core"],r):(i=typeof globalThis<"u"?globalThis:i||self,i.SignalDB=r(i.core))})(this,function(i){"use strict";function r(d,a){const{serialize:f=JSON.stringify,deserialize:u=JSON.parse}=a||{},o=`signaldb-collection-${d}`;function c(){return u(localStorage.getItem(o)||"[]")}return i.createPersistenceAdapter({async load(){return{items:c()}},async save(l,{added:p,modified:g,removed:h}){const e=[...c()];p.forEach(n=>{const t=e.findIndex(({id:s})=>s===n.id);/* istanbul ignore if -- @preserve */if(t!==-1){e[t]=n;return}e.push(n)}),g.forEach(n=>{const t=e.findIndex(({id:s})=>s===n.id);/* istanbul ignore if -- @preserve */if(t===-1){e.push(n);return}e[t]=n}),h.forEach(n=>{const t=e.findIndex(({id:s})=>s===n.id);/* istanbul ignore if -- @preserve */t!==-1&&e.splice(t,1)}),localStorage.setItem(o,f(e))},async register(){}})}return r});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { createPersistenceAdapter } from '@signaldb/core';\n/**\n * Creates a persistence adapter for managing a SignalDB collection using browser `localStorage`.\n * This adapter reads and writes data to `localStorage`, with customizable serialization and deserialization.\n * @template T - The type of the items in the collection.\n * @template I - The type of the unique identifier for the items.\n * @param name - A unique name for the collection, used as the key in `localStorage`.\n * @param options - Optional configuration for serialization and deserialization.\n * @param options.serialize - A function to serialize items to a string (default: `JSON.stringify`).\n * @param options.deserialize - A function to deserialize a string into items (default: `JSON.parse`).\n * @returns A SignalDB persistence adapter for managing data in `localStorage`.\n * @example\n * import createLocalStorageAdapter from './createLocalStorageAdapter';\n *\n * const adapter = createLocalStorageAdapter('myCollection', {\n * serialize: (items) => JSON.stringify(items, null, 2), // Pretty-print JSON\n * deserialize: (itemsString) => JSON.parse(itemsString), // Default JSON parse\n * });\n *\n * const collection = new Collection({\n * persistence: adapter,\n * });\n *\n * // Perform operations on the collection, and changes will be reflected in local storage.\n */\nexport default function createLocalStorageAdapter(name, options) {\n const { serialize = JSON.stringify, deserialize = JSON.parse } = options || {};\n const collectionId = `signaldb-collection-${name}`;\n function getItems() {\n return deserialize(localStorage.getItem(collectionId) || '[]');\n }\n return createPersistenceAdapter({\n async load() {\n const items = getItems();\n return
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { createPersistenceAdapter } from '@signaldb/core';\n/**\n * Creates a persistence adapter for managing a SignalDB collection using browser `localStorage`.\n * This adapter reads and writes data to `localStorage`, with customizable serialization and deserialization.\n * @template T - The type of the items in the collection.\n * @template I - The type of the unique identifier for the items.\n * @param name - A unique name for the collection, used as the key in `localStorage`.\n * @param options - Optional configuration for serialization and deserialization.\n * @param options.serialize - A function to serialize items to a string (default: `JSON.stringify`).\n * @param options.deserialize - A function to deserialize a string into items (default: `JSON.parse`).\n * @returns A SignalDB persistence adapter for managing data in `localStorage`.\n * @example\n * import createLocalStorageAdapter from './createLocalStorageAdapter';\n *\n * const adapter = createLocalStorageAdapter('myCollection', {\n * serialize: (items) => JSON.stringify(items, null, 2), // Pretty-print JSON\n * deserialize: (itemsString) => JSON.parse(itemsString), // Default JSON parse\n * });\n *\n * const collection = new Collection({\n * persistence: adapter,\n * });\n *\n * // Perform operations on the collection, and changes will be reflected in local storage.\n */\nexport default function createLocalStorageAdapter(name, options) {\n const { serialize = JSON.stringify, deserialize = JSON.parse } = options || {};\n const collectionId = `signaldb-collection-${name}`;\n /**\n * Retrieves items from localStorage and deserializes them.\n * @returns The deserialized items from localStorage.\n */\n function getItems() {\n return deserialize(localStorage.getItem(collectionId) || '[]');\n }\n return createPersistenceAdapter({\n async load() {\n const items = getItems();\n return { items };\n },\n async save(_items, { added, modified, removed }) {\n const items = [...getItems()];\n added.forEach((item) => {\n const index = items.findIndex(({ id }) => id === item.id);\n /* istanbul ignore if -- @preserve */\n if (index !== -1) {\n items[index] = item;\n return;\n }\n items.push(item);\n });\n modified.forEach((item) => {\n const index = items.findIndex(({ id }) => id === item.id);\n /* istanbul ignore if -- @preserve */\n if (index === -1) {\n items.push(item);\n return;\n }\n items[index] = item;\n });\n removed.forEach((item) => {\n const index = items.findIndex(({ id }) => id === item.id);\n /* istanbul ignore if -- @preserve */\n if (index === -1)\n return;\n items.splice(index, 1);\n });\n localStorage.setItem(collectionId, serialize(items));\n return;\n },\n async register() {\n return;\n },\n });\n}\n"],"names":["createLocalStorageAdapter","name","options","serialize","deserialize","collectionId","getItems","createPersistenceAdapter","_items","added","modified","removed","items","item","index","id"],"mappings":"4QAyBwB,SAAAA,EAA0BC,EAAMC,EAAS,CACvD,KAAA,CAAE,UAAAC,EAAY,KAAK,UAAW,YAAAC,EAAc,KAAK,OAAUF,GAAW,CAAC,EACvEG,EAAe,uBAAuBJ,CAAI,GAKhD,SAASK,GAAW,CAChB,OAAOF,EAAY,aAAa,QAAQC,CAAY,GAAK,IAAI,CAAA,CAEjE,OAAOE,2BAAyB,CAC5B,MAAM,MAAO,CAET,MAAO,CAAE,MADKD,EAAS,CACR,CACnB,EACA,MAAM,KAAKE,EAAQ,CAAE,MAAAC,EAAO,SAAAC,EAAU,QAAAC,GAAW,CAC7C,MAAMC,EAAQ,CAAC,GAAGN,GAAU,EACtBG,EAAA,QAASI,GAAS,CACd,MAAAC,EAAQF,EAAM,UAAU,CAAC,CAAE,GAAAG,KAASA,IAAOF,EAAK,EAAE,EAAA,qCAExD,GAAIC,IAAU,GAAI,CACdF,EAAME,CAAK,EAAID,EACf,MAAA,CAEJD,EAAM,KAAKC,CAAI,CAAA,CAClB,EACQH,EAAA,QAASG,GAAS,CACjB,MAAAC,EAAQF,EAAM,UAAU,CAAC,CAAE,GAAAG,KAASA,IAAOF,EAAK,EAAE,EAAA,qCAExD,GAAIC,IAAU,GAAI,CACdF,EAAM,KAAKC,CAAI,EACf,MAAA,CAEJD,EAAME,CAAK,EAAID,CAAA,CAClB,EACOF,EAAA,QAASE,GAAS,CAChB,MAAAC,EAAQF,EAAM,UAAU,CAAC,CAAE,GAAAG,KAASA,IAAOF,EAAK,EAAE,EAAA,qCAEpDC,IAAU,IAERF,EAAA,OAAOE,EAAO,CAAC,CAAA,CACxB,EACD,aAAa,QAAQT,EAAcF,EAAUS,CAAK,CAAC,CAEvD,EACA,MAAM,UAAW,CACb,CACJ,CACH,CACL"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signaldb/localstorage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "rimraf dist && vite build"
|
|
6
|
+
"build": "rimraf dist && vite build",
|
|
7
|
+
"analyze-bundle": "bundle-analyzer ./dist --upload-token=$BUNDLE_ANALYZER_UPLOAD_TOKEN --bundle-name=@signaldb/localstorage",
|
|
8
|
+
"test": "vitest"
|
|
7
9
|
},
|
|
8
10
|
"repository": {
|
|
9
11
|
"type": "git",
|