stroid 0.0.4 → 0.1.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/CHANGELOG.md +136 -25
- package/README.md +514 -81
- package/dist/_tsup-dts-rollup.d.cts +2411 -0
- package/dist/_tsup-dts-rollup.d.ts +2411 -0
- package/dist/async.cjs +34 -0
- package/dist/async.cjs.map +1 -0
- package/dist/async.d.cts +9 -0
- package/dist/async.d.ts +9 -30
- package/dist/async.js +34 -1
- package/dist/async.js.map +1 -0
- package/dist/computed.cjs +13 -0
- package/dist/computed.cjs.map +1 -0
- package/dist/computed.d.cts +7 -0
- package/dist/computed.d.ts +7 -0
- package/dist/computed.js +13 -0
- package/dist/computed.js.map +1 -0
- package/dist/core.cjs +24 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +15 -0
- package/dist/core.d.ts +15 -1
- package/dist/core.js +24 -1
- package/dist/core.js.map +1 -0
- package/dist/devtools.cjs +2 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +5 -0
- package/dist/devtools.d.ts +5 -0
- package/dist/devtools.js +2 -0
- package/dist/devtools.js.map +1 -0
- package/dist/feature.cjs +2 -0
- package/dist/feature.cjs.map +1 -0
- package/dist/feature.d.cts +14 -0
- package/dist/feature.d.ts +14 -0
- package/dist/feature.js +2 -0
- package/dist/feature.js.map +1 -0
- package/dist/helpers.cjs +24 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +3 -0
- package/dist/helpers.d.ts +3 -0
- package/dist/helpers.js +24 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +35 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -3
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -0
- package/dist/install.cjs +2 -0
- package/dist/install.cjs.map +1 -0
- package/dist/install.d.cts +4 -0
- package/dist/install.d.ts +4 -0
- package/dist/install.js +2 -0
- package/dist/install.js.map +1 -0
- package/dist/persist.cjs +2 -0
- package/dist/persist.cjs.map +1 -0
- package/dist/persist.d.cts +1 -0
- package/dist/persist.d.ts +1 -0
- package/dist/persist.js +2 -0
- package/dist/persist.js.map +1 -0
- package/dist/react.cjs +36 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +7 -0
- package/dist/react.d.ts +7 -20
- package/dist/react.js +36 -1
- package/dist/react.js.map +1 -0
- package/dist/runtime-admin.cjs +2 -0
- package/dist/runtime-admin.cjs.map +1 -0
- package/dist/runtime-admin.d.cts +2 -0
- package/dist/runtime-admin.d.ts +2 -0
- package/dist/runtime-admin.js +2 -0
- package/dist/runtime-admin.js.map +1 -0
- package/dist/runtime-tools.cjs +4 -0
- package/dist/runtime-tools.cjs.map +1 -0
- package/dist/runtime-tools.d.cts +9 -0
- package/dist/runtime-tools.d.ts +9 -0
- package/dist/runtime-tools.js +4 -0
- package/dist/runtime-tools.js.map +1 -0
- package/dist/selectors.cjs +2 -0
- package/dist/selectors.cjs.map +1 -0
- package/dist/selectors.d.cts +2 -0
- package/dist/selectors.d.ts +2 -0
- package/dist/selectors.js +2 -0
- package/dist/selectors.js.map +1 -0
- package/dist/server.cjs +12 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +2 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +12 -0
- package/dist/server.js.map +1 -0
- package/dist/sync.cjs +2 -0
- package/dist/sync.cjs.map +1 -0
- package/dist/sync.d.cts +1 -0
- package/dist/sync.d.ts +1 -0
- package/dist/sync.js +2 -0
- package/dist/sync.js.map +1 -0
- package/dist/testing.cjs +24 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +4 -0
- package/dist/testing.d.ts +4 -16
- package/dist/testing.js +24 -1
- package/dist/testing.js.map +1 -0
- package/package.json +86 -6
- package/dist/chunk-5F2FD6DX.js +0 -17
- package/dist/chunk-G6JMMJYH.js +0 -5
- package/dist/chunk-JBYLHJKN.js +0 -3
- package/dist/chunk-K6QIWMMW.js +0 -1
- package/dist/core-CKzRwVaY.d.ts +0 -213
package/package.json
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stroid",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Named-store state engine for JavaScript/React with optional persistence, async caching, sync, and devtools.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"state-management",
|
|
7
|
+
"state",
|
|
8
|
+
"store",
|
|
9
|
+
"react",
|
|
10
|
+
"hooks",
|
|
11
|
+
"typescript",
|
|
12
|
+
"async",
|
|
13
|
+
"cache",
|
|
14
|
+
"persistence",
|
|
15
|
+
"sync",
|
|
16
|
+
"broadcastchannel",
|
|
17
|
+
"devtools",
|
|
18
|
+
"ssr"
|
|
19
|
+
],
|
|
5
20
|
"type": "module",
|
|
6
21
|
"main": "dist/index.js",
|
|
7
22
|
"exports": {
|
|
@@ -13,10 +28,54 @@
|
|
|
13
28
|
"types": "./dist/core.d.ts",
|
|
14
29
|
"import": "./dist/core.js"
|
|
15
30
|
},
|
|
31
|
+
"./runtime-tools": {
|
|
32
|
+
"types": "./dist/runtime-tools.d.ts",
|
|
33
|
+
"import": "./dist/runtime-tools.js"
|
|
34
|
+
},
|
|
35
|
+
"./runtime-admin": {
|
|
36
|
+
"types": "./dist/runtime-admin.d.ts",
|
|
37
|
+
"import": "./dist/runtime-admin.js"
|
|
38
|
+
},
|
|
39
|
+
"./selectors": {
|
|
40
|
+
"types": "./dist/selectors.d.ts",
|
|
41
|
+
"import": "./dist/selectors.js"
|
|
42
|
+
},
|
|
43
|
+
"./computed": {
|
|
44
|
+
"types": "./dist/computed.d.ts",
|
|
45
|
+
"import": "./dist/computed.js"
|
|
46
|
+
},
|
|
47
|
+
"./helpers": {
|
|
48
|
+
"types": "./dist/helpers.d.ts",
|
|
49
|
+
"import": "./dist/helpers.js"
|
|
50
|
+
},
|
|
51
|
+
"./server": {
|
|
52
|
+
"types": "./dist/server.d.ts",
|
|
53
|
+
"import": "./dist/server.js"
|
|
54
|
+
},
|
|
16
55
|
"./async": {
|
|
17
56
|
"types": "./dist/async.d.ts",
|
|
18
57
|
"import": "./dist/async.js"
|
|
19
58
|
},
|
|
59
|
+
"./feature": {
|
|
60
|
+
"types": "./dist/feature.d.ts",
|
|
61
|
+
"import": "./dist/feature.js"
|
|
62
|
+
},
|
|
63
|
+
"./install": {
|
|
64
|
+
"types": "./dist/install.d.ts",
|
|
65
|
+
"import": "./dist/install.js"
|
|
66
|
+
},
|
|
67
|
+
"./persist": {
|
|
68
|
+
"types": "./dist/persist.d.ts",
|
|
69
|
+
"import": "./dist/persist.js"
|
|
70
|
+
},
|
|
71
|
+
"./sync": {
|
|
72
|
+
"types": "./dist/sync.d.ts",
|
|
73
|
+
"import": "./dist/sync.js"
|
|
74
|
+
},
|
|
75
|
+
"./devtools": {
|
|
76
|
+
"types": "./dist/devtools.d.ts",
|
|
77
|
+
"import": "./dist/devtools.js"
|
|
78
|
+
},
|
|
20
79
|
"./react": {
|
|
21
80
|
"types": "./dist/react.d.ts",
|
|
22
81
|
"import": "./dist/react.js"
|
|
@@ -42,11 +101,22 @@
|
|
|
42
101
|
"url": "https://github.com/Himesh-Bhattarai/stroid/issues"
|
|
43
102
|
},
|
|
44
103
|
"homepage": "https://github.com/Himesh-Bhattarai/stroid#readme",
|
|
45
|
-
"sideEffects":
|
|
104
|
+
"sideEffects": [
|
|
105
|
+
"./src/persist.ts",
|
|
106
|
+
"./src/sync.ts",
|
|
107
|
+
"./src/devtools.ts",
|
|
108
|
+
"./dist/persist.js",
|
|
109
|
+
"./dist/sync.js",
|
|
110
|
+
"./dist/devtools.js"
|
|
111
|
+
],
|
|
46
112
|
"scripts": {
|
|
47
|
-
"test": "node --import tsx --test
|
|
113
|
+
"test": "node --import ./tests/preload.mjs --import tsx --import ./tests/setup.ts --test tests/async-cleanup.test.ts tests/async-revalidate-cleanup.test.ts tests/async.test.ts tests/computed.test.ts tests/coverage-extra.test.ts tests/feature-api.test.ts tests/helpers.test.ts tests/options-adapter.test.ts tests/persist.test.ts tests/react-hooks.test.tsx tests/regressions.test.ts tests/selectors-devfreeze.test.ts tests/ssr-carrier.test.ts tests/store.core.test.ts tests/store.node-env.test.ts tests/strict-missing-features.test.ts tests/sync.core.test.ts tests/testing.test.ts tests/utils.test.ts",
|
|
114
|
+
"test:coverage": "c8 --check-coverage --lines 80 --branches 80 --functions 80 --statements 80 node --import ./tests/preload.mjs --import tsx --import ./tests/setup.ts --test tests/async-cleanup.test.ts tests/async-revalidate-cleanup.test.ts tests/async.test.ts tests/computed.test.ts tests/coverage-extra.test.ts tests/feature-api.test.ts tests/helpers.test.ts tests/options-adapter.test.ts tests/persist.test.ts tests/react-hooks.test.tsx tests/regressions.test.ts tests/selectors-devfreeze.test.ts tests/ssr-carrier.test.ts tests/store.core.test.ts tests/store.node-env.test.ts tests/strict-missing-features.test.ts tests/sync.core.test.ts tests/testing.test.ts tests/utils.test.ts",
|
|
115
|
+
"test:heavy": "node --import tsx --test tests/heavy/store.heavy.ts",
|
|
116
|
+
"test:types": "npm run build && tsc -p tsconfig.typetests.json",
|
|
48
117
|
"typecheck": "tsc -p tsconfig.types.json",
|
|
49
|
-
"build": "tsup"
|
|
118
|
+
"build": "tsup",
|
|
119
|
+
"test:all": "npm test && npm run test:types"
|
|
50
120
|
},
|
|
51
121
|
"engines": {
|
|
52
122
|
"node": ">=18"
|
|
@@ -56,15 +126,25 @@
|
|
|
56
126
|
"react": ">=18"
|
|
57
127
|
},
|
|
58
128
|
"devDependencies": {
|
|
129
|
+
"@microsoft/api-extractor": "^7.57.7",
|
|
130
|
+
"@testing-library/dom": "^10.4.0",
|
|
131
|
+
"@testing-library/react": "^16.2.0",
|
|
59
132
|
"@types/node": "^22.9.0",
|
|
60
133
|
"@types/react": "^18.2.46",
|
|
134
|
+
"c8": "^10.1.2",
|
|
61
135
|
"eslint": "^8.57.0",
|
|
62
136
|
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
63
137
|
"eslint-plugin-import": "^2.29.1",
|
|
64
138
|
"eslint-plugin-n": "^16.6.2",
|
|
65
139
|
"eslint-plugin-promise": "^6.1.1",
|
|
140
|
+
"immer": "^11.1.4",
|
|
141
|
+
"jsdom": "^25.0.1",
|
|
142
|
+
"react": "^18.2.0",
|
|
143
|
+
"react-dom": "^18.2.0",
|
|
144
|
+
"redux": "^5.0.1",
|
|
66
145
|
"tsup": "^8.5.1",
|
|
67
146
|
"tsx": "^4.7.0",
|
|
68
|
-
"typescript": "^5.7.2"
|
|
147
|
+
"typescript": "^5.7.2",
|
|
148
|
+
"zustand": "^5.0.11"
|
|
69
149
|
}
|
|
70
150
|
}
|
package/dist/chunk-5F2FD6DX.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var Mt=typeof process<"u"&&typeof process.env?.NODE_ENV=="string"?process.env.NODE_ENV:void 0,zt=typeof import.meta<"u"&&import.meta?.env?.MODE?import.meta.env.MODE:void 0,bt=typeof globalThis<"u"&&typeof globalThis.__STROID_DEV__=="boolean"?globalThis.__STROID_DEV__:void 0,Ft=typeof process<"u"?"development":"production",qt=Mt??zt??Ft,H=typeof bt=="boolean"?bt:qt!=="production",w=()=>H,p=H?t=>{console.warn(`[stroid] ${t}`);}:()=>{},R=H?t=>{console.error(`[stroid] ${t}`);}:()=>{},j=H?t=>{console.log(`[stroid] ${t}`);}:()=>{},st=null,Lt=()=>{if(st)return st;let t,e=[];for(let n=0;n<256;n++){t=n;for(let r=0;r<8;r++)t=t&1?3988292384^t>>>1:t>>>1;e[n]=t>>>0;}return st=e,e},vt=t=>{let e=Lt(),n=-1;for(let r=0;r<t.length;r++)n=n>>>0,n=n>>>8^e[(n^t.charCodeAt(r))&255];return (n^-1)>>>0},G=t=>{try{return vt(JSON.stringify(t))}catch{return vt(String(t))}},Ut=typeof globalThis<"u"&&typeof globalThis.structuredClone=="function",h=t=>{try{return Ut?structuredClone(t):JSON.parse(JSON.stringify(t))}catch{return Array.isArray(t)?[...t]:t&&typeof t=="object"?{...t}:t}};var it=(t,e)=>{try{let n=h(t);return e(n),n}catch(n){throw new Error(`produceClone failed (possible circular reference or unserializable data): ${n?.message??n}`)}},at=(t,e)=>{if(!t)return {ok:true};try{if(typeof t.safeParse=="function"){let n=t.safeParse(e);return n.success?{ok:!0,data:n.data}:{ok:!1,error:n.error}}if(typeof t.parse=="function")return t.parse(e),{ok:!0,data:e};if(typeof t.validateSync=="function")return t.validateSync(e),{ok:!0,data:e};if(typeof t.isValidSync=="function")return t.isValidSync(e)?{ok:!0,data:e}:{ok:!1,error:"Schema validation failed"};if(typeof t.validate=="function")return t.validate(e)?{ok:!0,data:e}:{ok:!1,error:t.errors||"Schema validation failed"};if(typeof t=="function"){let n=t(e);return n===!1?{ok:!1,error:"Schema validation failed"}:{ok:!0,data:n===!0?e:n}}return {ok:!0,data:e}}catch(n){return {ok:false,error:n?.message??n}}};var C=t=>t===null?"null":Array.isArray(t)?"array":t instanceof Map?"map":t instanceof Set?"set":t instanceof Date?"date":typeof t=="function"?"function":typeof t,F=t=>{let e=C(t);return e==="function"?(R(`Functions cannot be stored in stroid.
|
|
2
|
-
Store data only - handle functions outside the store.`),false):e==="map"||e==="set"?(p(`Map/Set detected. stroid converts these to plain objects.
|
|
3
|
-
Use arrays or plain objects for best results.`),true):(e==="date"&&p(`Date object detected. stroid stores it as ISO string.
|
|
4
|
-
Use new Date(value) to convert back when reading.`),true)},O=t=>{let e=C(t);if(e==="date")return w()&&p("Date detected; stored as ISO string. Use new Date(value) when reading."),t.toISOString();if(e==="map")return w()&&p("Map detected; converting to plain object."),Object.fromEntries(t);if(e==="set")return w()&&p("Set detected; converting to array."),Array.from(t);if(e==="object"){let n={};for(let r in t)n[r]=O(t[r]);return n}return e==="array"?t.map(O):t},kt=10,Kt=5,q=t=>Array.isArray(t)?[...t]:typeof t=="string"&&!t.includes(".")?[t]:typeof t=="string"?t.split("."):[String(t)],ct=t=>{let e=q(t),n=e.length;return n>kt?(R(`Path depth of ${n} exceeded maximum of ${kt}.
|
|
5
|
-
"${e.join(".")}"
|
|
6
|
-
This is a data design issue. Split into separate stores:
|
|
7
|
-
createStore("${e[0]}", ...) and createStore("${e[1]}", ...)`),false):(n>Kt&&p(`Deep nesting detected (${n} levels): "${e.join(".")}"
|
|
8
|
-
Consider splitting into separate stores for better readability.`),true)},wt=(t,e)=>{let n=q(e),r=t;for(let o of n){if(r==null){p(`Path "${n.join(".")}" not found - reached null at "${o}"`);return}if(typeof r!="object"){p(`Cannot go deeper at "${o}" - value is not an object`);return}r=r[o];}return r},xt=(t,e,n)=>{let r=q(e);if(r.length===0)return t;let o=(s,a)=>{let l=r[a],f=a===r.length-1;if(Array.isArray(s)){let i=Number(l);if(!Number.isInteger(i))return s;let d=[...s];return f?(d[i]=n,d):(d[i]=o(d[i],a+1),d)}if(s&&typeof s=="object"){let i={...s};return f?(i[l]=n,i):(i[l]=o(i[l],a+1),i)}return s};return o(t,0)},$t=t=>typeof t!="string"||t.trim()===""?(R(`Store name must be a non-empty string. Got: ${JSON.stringify(t)}`),false):t.includes(" ")?(R(`Store name "${t}" contains spaces.
|
|
9
|
-
Use camelCase or kebab-case: "userName" or "user-name"`),false):true,Tt=(t,e)=>{let n=e.find(r=>{let o=r.toLowerCase(),s=t.toLowerCase();return o.includes(s)||s.includes(o)||Bt(o,s)<=2});n?p(`Store "${t}" not found. Did you mean "${n}"?`):R(`Store "${t}" not found.
|
|
10
|
-
Available stores: [${e.join(", ")}]
|
|
11
|
-
Call createStore("${t}", data) first.`);},Bt=(t,e)=>{let n=Array.from({length:e.length+1},(r,o)=>Array.from({length:t.length+1},(s,a)=>o===0?a:a===0?o:0));for(let r=1;r<=e.length;r++)for(let o=1;o<=t.length;o++)n[r][o]=e[r-1]===t[o-1]?n[r-1][o-1]:Math.min(n[r-1][o-1],n[r][o-1],n[r-1][o])+1;return n[e.length][t.length]};var L=t=>{if(typeof t!="object"||t===null)return t;Object.freeze(t);for(let e of Object.keys(t)){let n=t[e];typeof n=="object"&&n!==null&&!Object.isFrozen(n)&&L(n);}return t};var u=Object.create(null),_=Object.create(null),D=Object.create(null),c=Object.create(null),x=Object.create(null),B=Object.create(null),V=Object.create(null),Y=Object.create(null),Z=new Set,lt=false,U=0,et=`stroid_${Math.random().toString(16).slice(2)}`,ut={},Q=Object.create(null),N=Object.create(null),_t=false,Rt=t=>typeof t=="string"?t:t.name,K,X=(()=>{let t=new Map;return {getItem:e=>t.has(e)?t.get(e):null,setItem:(e,n)=>{t.set(e,n);},removeItem:e=>{t.delete(e);},type:"memory"}})(),Ot=()=>{if(lt)return;lt=true;let t=()=>{lt=false,Z.forEach(e=>{let n=_[e];if(!n||n.length===0)return;let r=typeof performance<"u"&&performance.now?performance.now():Date.now(),o=h(u[e]);n.forEach(f=>{try{f(o);}catch(i){p(`Subscriber for "${e}" threw: ${i?.message??i}`);}});let a=(typeof performance<"u"&&performance.now?performance.now():Date.now())-r,l=c[e]?.metrics||{notifyCount:0,totalNotifyMs:0,lastNotifyMs:0};l.notifyCount+=1,l.totalNotifyMs+=a,l.lastNotifyMs=a,c[e]&&(c[e].metrics=l);}),Z.clear();};typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t);},J=t=>{Z.add(t),U===0&&Ot();},M=t=>u[t]!==void 0?true:(Tt(t,Object.keys(u)),false),Jt=(t,e,n,r)=>{let o=q(n);if(o.length===0)return {ok:true};if(e==null){let a=`Cannot set "${o.join(".")}" on "${t}" because the store value is ${e===null?"null":"undefined"}.`;return p(a),{ok:false,reason:a}}let s=e;for(let a=0;a<o.length;a++){let l=o[a],f=a===o.length-1;if(s==null||typeof s!="object"){let d=`Path "${o.join(".")}" is invalid for "${t}" - "${o.slice(0,a).join(".")||"root"}" is not an object.`;return p(d),{ok:false,reason:d}}if(Array.isArray(s)){let d=Number(l);if(!Number.isInteger(d)||d<0){let g=`Path "${o.join(".")}" targets non-numeric index "${l}" on an array in "${t}".`;return p(g),{ok:false,reason:g}}let y=s;if(d>=y.length){let g=`Path "${o.join(".")}" is invalid for "${t}" - index ${d} is out of bounds (length ${y.length}).`;return p(g),{ok:false,reason:g}}if(f){let g=y[d];if(g!==void 0){let k=C(g),T=C(r);if(k!==T){let P=`Type mismatch setting "${o.join(".")}" on "${t}": expected ${k}, received ${T}.`;return p(P),{ok:false,reason:P}}}return {ok:true}}s=y[d];continue}if(!Object.prototype.hasOwnProperty.call(s,l)){let d=`Path "${o.join(".")}" does not exist on store "${t}" (missing "${l}").`;return p(d),{ok:false,reason:d}}if(f){let d=s[l];if(d!==void 0){let y=C(d),g=C(r);if(y!==g){let k=`Type mismatch setting "${o.join(".")}" on "${t}": expected ${y}, received ${g}.`;return p(k),{ok:false,reason:k}}}return {ok:true}}s=s[l];}return {ok:true}},dt=t=>{try{return typeof window>"u"?X:t==="session"||t==="sessionStorage"?window.sessionStorage??X:window.localStorage??X}catch{return X}},Wt=(t,e)=>{N[t]&&(N[t].lastPresent=e);},Ht=(t,e)=>{if(!t)return null;let n={key:`stroid_${e}`,serialize:JSON.stringify,deserialize:JSON.parse,encrypt:r=>r,decrypt:r=>r,onMigrationFail:"reset"};return t===true?{driver:dt("localStorage"),...n}:typeof t=="string"?{driver:dt(t),...n}:{driver:t.driver||t.storage||dt("localStorage"),key:t.key||n.key,serialize:t.serialize||n.serialize,deserialize:t.deserialize||n.deserialize,encrypt:t.encrypt||n.encrypt,decrypt:t.decrypt||n.decrypt,onMigrationFail:t.onMigrationFail||"reset",onStorageCleared:t.onStorageCleared}},Gt=t=>{let e=c[t]?.options?.persist,n=e?.onStorageCleared;if(!e||typeof n!="function"||typeof window>"u"||typeof window.addEventListener!="function")return;N[t]?.dispose();let r=window,o=()=>{try{return e.driver.getItem?.(e.key)!=null}catch{return false}},s=f=>{let i=N[t],d=o();if(i){if(!i.lastPresent||d){i.lastPresent=d;return}i.lastPresent=false,n({name:t,key:e.key,reason:f});}},a=f=>{if(f.key===null){s("clear");return}f.key===e.key&&f.newValue===null&&s("remove");},l=()=>{s("missing");};r.addEventListener("storage",a),r.addEventListener("focus",l),N[t]={lastPresent:o(),dispose:()=>{r.removeEventListener("storage",a),r.removeEventListener("focus",l);}};},Xt=t=>{if(!c[t]?.options?.devtools||typeof window>"u")return;let n=window.__REDUX_DEVTOOLS_EXTENSION__||window.__REDUX_DEVTOOLS_EXTENSION__;if(!n||typeof n.connect!="function"){p(`DevTools requested for "${t}" but Redux DevTools extension not found.`);return}K||(K=n.connect({name:"stroid"}),K.init(u));},tt=(t,e)=>{let n=c[t]?.options?.redactor;if(typeof n=="function")try{return n(h(e))}catch{return e}return e},Yt=t=>typeof TextEncoder<"u"?new TextEncoder().encode(t).length:typeof Buffer<"u"?Buffer.byteLength(t):t.length,v=(t,e)=>{c[t]?.options?.onError?.(e),p(e);},ft=(t,e,n)=>{v(t,n);let r=c[t]?.options?.persist?.onMigrationFail??"reset";if(r==="keep")return {state:e,requiresValidation:false};if(typeof r=="function")try{let o=r(h(e));if(o!==void 0)return {state:O(o),requiresValidation:!0};v(t,`onMigrationFail for "${t}" returned undefined. Falling back to initial state.`);}catch(o){v(t,`onMigrationFail for "${t}" failed: ${o?.message??o}`);}return {state:h(D[t]),requiresValidation:false}},Zt=(t,e)=>{if(typeof t!="object"||typeof e!="object"||t===null||e===null)return null;let n=t,r=e,o=[],s=[],a=[],l=new Set(Object.keys(n)),f=new Set(Object.keys(r));return f.forEach(i=>{l.has(i)?Object.is(n[i],r[i])||a.push(i):o.push(i);}),l.forEach(i=>{f.has(i)||s.push(i);}),{added:o,removed:s,changed:a}},nt=(t,e,n,r)=>{let o=c[t]?.options?.historyLimit??50;if(o===0)return;x[t]||(x[t]=[]);let s={ts:Date.now(),action:e,prev:tt(t,n),next:tt(t,r),diff:Zt(n,r)};x[t].push(s),x[t].length>o&&x[t].splice(0,x[t].length-o);},rt=(t,e,n=false)=>{if(!(!K||!n&&!c[t]?.options?.devtools))try{let r={...u,[t]:tt(t,u[t])};K.send({type:`${t}/${e}`},r);}catch{}},Vt=(t,e)=>{let n=c[t]?.options?.middleware||[];if(!Array.isArray(n))return e.next;let r=e.next;for(let o of n){if(typeof o!="function")continue;let s;try{s=o({action:e.action,name:t,prev:e.prev,next:r,path:e.path});}catch(a){let l=`Middleware for "${t}" failed: ${a?.message??a}`;c[t]?.options?.onError?.(l),p(l);continue}s!==void 0&&(r=s);}return r},A=(t,e)=>{let n=c[t]?.options?.schema;if(!n)return {ok:true};let r=at(n,e);return r.ok||v(t,`Schema validation failed for "${t}": ${r.error}`),r},pt=t=>{let e=c[t]?.options?.persist;e&&(ut[t]&&clearTimeout(ut[t]),ut[t]=setTimeout(()=>{try{let n=e.serialize(u[t]),r=G(n),o=JSON.stringify({v:c[t]?.version??1,checksum:r,data:n}),s=e.encrypt(o);e.driver.setItem?.(e.key,s),Wt(t,!0);}catch(n){v(t,`Could not persist store "${t}" (${n?.message||n})`);}},0));},Qt=(t,{silent:e}={silent:false})=>{let n=c[t]?.options?.persist;if(n)try{let r=n.driver.getItem?.(n.key)??null;if(!r)return;let o=n.decrypt(r),s=JSON.parse(o),{v:a=1,checksum:l,data:f}=s||{};if(!f)return;if(l!==G(f)){v(t,`Checksum mismatch loading store "${t}". Falling back to initial state.`),u[t]=h(D[t]);return}let i=n.deserialize(f),d=c[t]?.version??1;if(a!==d){let g=c[t]?.options?.migrations||{},k=Object.keys(g).map(S=>Number(S)).filter(S=>S>a&&S<=d).sort((S,m)=>S-m);if(k.length===0){let S=ft(t,i,`No migration path from v${a} to v${d} for "${t}". Applying onMigrationFail strategy.`);if(i=S.state,!S.requiresValidation){u[t]=i;return}}let T=!1,P=!0;if(k.forEach(S=>{if(!T)try{let m=g[S](i);m!==void 0&&(i=m);}catch(m){let z=ft(t,i,`Migration to v${S} failed for "${t}": ${m?.message||m}`);i=z.state,P=z.requiresValidation,T=!0;}}),T){if(!P){u[t]=i;return}if(!A(t,i).ok){u[t]=h(D[t]);return}u[t]=i;return}}if(!A(t,i).ok){if(a!==d){let g=ft(t,i,`Persisted state for "${t}" failed schema after version change. Applying onMigrationFail strategy.`);if(!g.requiresValidation){u[t]=g.state;return}if(A(t,g.state).ok){u[t]=g.state;return}}v(t,`Persisted state for "${t}" failed schema; resetting to initial.`),u[t]=h(D[t]);return}u[t]=i,e||j(`Store "${t}" loaded from persistence`);}catch(r){v(t,`Could not load store "${t}" (${r?.message||r})`);}},W=(t,e,n={})=>{if(!$t(t)||!F(e))return;let r=typeof window>"u",o=typeof process<"u"?process.env?.NODE_ENV:void 0,s=r&&o==="production",a=n.allowSSRGlobalStore??false;if(s&&!a){w()&&R(`createStore("${t}") is blocked on the server in production to prevent cross-request memory leaks.
|
|
12
|
-
Call createStoreForRequest(...) inside each request scope or pass { allowSSRGlobalStore: true } to opt in.`);return}if(u[t]!==void 0){let b=`Store "${t}" already exists. Call setStore("${t}", data) to update instead.`;return p(b),c[t]?.options?.onError?.(b),{name:t}}let{persist:l=false,devtools:f=false,middleware:i=[],onSet:d,onReset:y,onDelete:g,onCreate:k,onError:T,validator:P,schema:S,migrations:m={},version:z=1,redactor:Ct,historyLimit:Nt=50,sync:At,allowSSRGlobalStore:St=a}=n;r&&!St&&!_t&&w()&&(_t=true,p(`createStore("${t}") called in a server environment. Use createStoreForRequest(...) per request to avoid cross-request leaks or pass { allowSSRGlobalStore: true } if you really want a global store on the server.`));let I=Ht(l,t);if(I?.key){let b=Q[I.key];b&&b!==t&&w()?p(`Persist key collision: "${I.key}" already used by store "${b}". Store "${t}" will overwrite the same storage key.`):Q[I.key]=t;}let E=O(e),It={persist:I,devtools:!!f,middleware:i??[],onSet:d,onReset:y,onDelete:g,onCreate:k,onError:T,validator:P,schema:S,migrations:m,version:z,redactor:Ct,historyLimit:Nt,sync:At??false,allowSSRGlobalStore:St},ht=S?at(S,E):{ok:true};if(!ht.ok){let b=`Schema validation failed for "${t}": ${ht.error}`;T?.(b),p(b);return}if(P&&P(E)===false){let b=`Validator blocked initial state for "${t}"`;T?.(b),p(b);return}return u[t]=E,_[t]=_[t]||[],D[t]=h(E),c[t]={createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),updateCount:0,version:z,metrics:{notifyCount:0,totalNotifyMs:0,lastNotifyMs:0},options:It},I&&(pt(t),Qt(t,{silent:true}),Gt(t)),c[t].options.onCreate?.(E),Xt(t),ne(t),nt(t,"create",null,E),j(`Store "${t}" created -> ${JSON.stringify(E)}`),{name:t}};function $(t,e,n){let r=Rt(t);if(!M(r))return;let o,s=u[r];if(typeof e=="function"&&n===void 0)o=it(s,e);else if(typeof e=="object"&&!Array.isArray(e)&&n===void 0){if(!F(e))return;o={...s,...O(e)};}else if(typeof e=="string"||Array.isArray(e)){if(!ct(e))return;let d=O(n),y=Jt(r,s,e,d);if(!y.ok){w()&&c[r]?.options?.onError?.(y.reason??`Invalid path for "${r}".`);return}o=xt(s,e,d);}else {R(`setStore("${r}") - invalid arguments.
|
|
13
|
-
Usage:
|
|
14
|
-
setStore("${r}", "field", value)
|
|
15
|
-
setStore("${r}", "nested.field", value)
|
|
16
|
-
setStore("${r}", { field: value })`);return}if(!F(o))return;let a=O(o);if(!A(r,a).ok)return;let f=c[r]?.options?.validator;if(f&&f(a)===false){c[r]?.options?.onError?.(`Validator blocked update for "${r}"`);return}let i=Vt(r,{action:"set",prev:s,next:a,path:e});u[r]=w()?L(i):i,c[r].updatedAt=new Date().toISOString(),c[r].updateCount++,yt(r),c[r].options?.persist&&pt(r),c[r].options.onSet?.(s,i),nt(r,"set",s,i),rt(r,"set"),ot(r),J(r),j(`Store "${r}" updated`);}var ue=t=>{U++;try{t();}finally{U=Math.max(0,U-1),U===0&&Z.size>0&&Ot();}};function gt(t,e){let n=Rt(t);if(!M(n))return null;let r=u[n];return e===void 0?Array.isArray(r)?[...r]:r&&typeof r=="object"?{...r}:r:ct(e)?wt(r,e):null}var Dt=t=>{if(!M(t))return;_[t]?.forEach(o=>o(null)),c[t].options.onDelete?.(u[t]);let n=c[t].options.persist,r=c[t].options.devtools;delete u[t],delete _[t],delete D[t],delete c[t];try{n?.driver?.removeItem&&n.driver.removeItem(n.key);}catch{}n?.key&&Q[n.key]===t&&delete Q[n.key],N[t]?.dispose(),delete N[t],B[t]?.close(),delete B[t],Y[t]?.(),delete Y[t],delete V[t],r&&rt(t,"delete",true),j(`Store "${t}" deleted`);},Et=t=>{if(!M(t)||!D[t])return;let e=u[t],n=h(D[t]);u[t]=w()?L(n):n,c[t].updatedAt=new Date().toISOString(),yt(t),c[t].options.onReset?.(e,n),nt(t,"reset",e,n),rt(t,"reset"),ot(t),J(t),j(`Store "${t}" reset to initial state/value`);},de=(t,e)=>{if(!M(t)||!F(e))return;let n=u[t];if(typeof n!="object"||Array.isArray(n)||n===null){R(`mergeStore("${t}") only works on object stores.
|
|
17
|
-
Use setStore("${t}", value) instead.`);return}let r={...n,...O(e)};if(!A(t,r).ok)return;let s=c[t]?.options?.validator;if(s&&s(r)===false){c[t]?.options?.onError?.(`Validator blocked update for "${t}"`);return}let a=Vt(t,{action:"merge",prev:n,next:r,path:null});u[t]=w()?L(a):a,c[t].updatedAt=new Date().toISOString(),c[t].updateCount++,yt(t),c[t].options?.persist&&pt(t),c[t].options.onSet?.(n,a),nt(t,"merge",n,a),rt(t,"merge"),ot(t),J(t),j(`Store "${t}" merged with data`);},fe=()=>{let t=Object.keys(u);t.forEach(Dt),p(`All stores cleared (${t.length} stores removed)`);},te=t=>u[t]!==void 0,pe=()=>Object.keys(u),ge=t=>M(t)?{...c[t]}:null,jt=(t,e)=>(_[t]||(_[t]=[]),_[t].push(e),()=>{_[t]=_[t].filter(n=>n!==e);}),ye=t=>u[t]??null,yt=t=>(V[t]=(V[t]??0)+1,V[t]),Pt=(t,e)=>(V[t]=Math.max(V[t]??0,e)+1,V[t]),ee=(t,e)=>{let n=V[t]??0,r=typeof e.clock=="number"?e.clock:0;if(r!==n)return r-n;let o=new Date(c[t]?.updatedAt||0).getTime(),s=typeof e.updatedAt=="number"?e.updatedAt:0;if(s!==o)return s-o;let a=et;return (e.source??"").localeCompare(a)},mt=t=>{let e=B[t];if(e)try{e.postMessage({type:"sync-request",source:et,name:t,requestedAt:Date.now()});}catch(n){v(t,`Failed to request sync snapshot for "${t}": ${n?.message??n}`);}},ne=t=>{let e=c[t]?.options?.sync;if(!e)return;if(typeof window>"u"||typeof BroadcastChannel>"u"){v(t,`Sync enabled for "${t}" but BroadcastChannel not available in this environment.`);return}let n=typeof e=="object"&&e.channel?e.channel:`stroid_sync_${t}`;try{let r=new BroadcastChannel(n);if(B[t]=r,r.onmessage=o=>{let s=o.data;if(!s||s.source===et||s.name!==t)return;if(s.type==="sync-request"){ot(t);return}let a=typeof e=="object"?e.conflictResolver:null;if(ee(t,{clock:s.clock,updatedAt:s.updatedAt,source:s.source})<=0){let i=new Date(c[t]?.updatedAt||0).getTime(),d=s.updatedAt;if(a){let y=a({local:u[t],incoming:s.data,localUpdated:i,incomingUpdated:d});if(y!==void 0){if(!A(t,y).ok)return;u[t]=y,c[t].updatedAt=new Date(Math.max(i,d)).toISOString(),c[t].updateCount++,Pt(t,typeof s.clock=="number"?s.clock:0),J(t);}}return}A(t,s.data).ok&&(u[t]=s.data,c[t].updatedAt=new Date(s.updatedAt).toISOString(),c[t].updateCount++,Pt(t,typeof s.clock=="number"?s.clock:0),J(t));},typeof window<"u"&&typeof window.addEventListener=="function"){Y[t]?.();let o=window,s=()=>{mt(t);};o.addEventListener("focus",s),o.addEventListener("online",s),Y[t]=()=>{o.removeEventListener("focus",s),o.removeEventListener("online",s);};}queueMicrotask(()=>{mt(t);});}catch(r){p(`Failed to setup sync for "${t}": ${r?.message||r}`);}},ot=t=>{let e=B[t];if(e)try{let n=c[t]?.options?.sync,r={type:"sync-state",source:et,name:t,clock:V[t]??0,updatedAt:Date.parse(c[t]?.updatedAt||new Date().toISOString()),data:tt(t,u[t]),checksum:G(u[t])},o=typeof n=="object"&&typeof n.maxPayloadBytes=="number"?n.maxPayloadBytes:64*1024,s=Yt(JSON.stringify(r));if(s>o){v(t,`Sync payload for "${t}" exceeds ${o} bytes (${s} bytes). Skipping BroadcastChannel sync.`);return}e.postMessage(r);}catch(n){v(t,`Failed to broadcast sync for "${t}": ${n?.message??n}`);}},Se=(t,e)=>{let n,r;return ()=>{let o=u[t];return o===void 0?null:(o===n||(n=o,r=e(o)),r??null)}},re=(t,e,n=Object.is,r)=>{if(typeof e!="function"||typeof r!="function")return p(`subscribeWithSelector("${t}") requires selector and listener functions.`),()=>{};let o=e(u[t]);return jt(t,a=>{let l=e(a);if(!n(l,o)){let f=o;o=l,r(l,f);}})},he=(t,e=0,n={})=>(W(t,{value:e},n),{inc:(r=1)=>$(t,o=>{o.value+=r;}),dec:(r=1)=>$(t,o=>{o.value-=r;}),set:r=>$(t,"value",r),reset:()=>Et(t),get:()=>gt(t,"value")}),be=(t,e=[],n={})=>(W(t,{items:e},n),{push:r=>$(t,o=>{o.items.push(r);}),removeAt:r=>$(t,o=>{o.items.splice(r,1);}),clear:()=>$(t,{items:[]}),replace:r=>$(t,{items:r}),all:()=>gt(t,"items")}),ve=(t,e={})=>(W(t,{entities:{},ids:[]},e),{upsert:n=>$(t,r=>{let o=n.id??n._id??(typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}_${Math.random().toString(16).slice(2)}`);r.ids.includes(o)||r.ids.push(o),r.entities[o]=n;}),remove:n=>$(t,r=>{r.ids=r.ids.filter(o=>o!==n),delete r.entities[n];}),all:()=>{let n=u[t];return n?n.ids.map(r=>n.entities[r]):[]},get:n=>gt(t,`entities.${n}`),clear:()=>Et(t)}),ke=()=>h(u),we=(t,e)=>{if(!x[t])return [];let n=x[t];return e&&e>0?n.slice(-e):[...n]},xe=t=>{t?delete x[t]:Object.keys(x).forEach(e=>delete x[e]);},$e=t=>{let e=c[t];return e?.metrics?{...e.metrics}:null},Te=t=>{let e={};return typeof t=="function"&&t({create:(r,o,s={})=>(e[r]=h(o),e[r]),set:(r,o)=>{if(e[r])return e[r]=typeof o=="function"?it(e[r],o):o,e[r]},get:r=>h(e[r])}),{snapshot:()=>h(e),hydrate:(r={})=>oe(e,r)}},oe=(t,e={})=>{!t||typeof t!="object"||Object.entries(t).forEach(([n,r])=>{te(n)?$(n,r):W(n,r,e[n]||e.default||{});});},_e=(t,e={})=>{let n=e.name||`zstore_${Date.now()}`,r=(l,f=false)=>{let i=u[n]??{},d=typeof l=="function"?l(i):l,y=f?d:{...i,...d};$(n,y);},o=()=>u[n],s={setState:r,getState:o,subscribe:l=>jt(n,l),subscribeWithSelector:(l,f=Object.is,i)=>re(n,l,f,i??(()=>{})),destroy:()=>Dt(n)},a=t(r,o,s);return W(n,a,e),s};export{oe as A,_e as B,w as a,p as b,R as c,W as d,$ as e,ue as f,gt as g,Dt as h,Et as i,de as j,fe as k,te as l,pe as m,ge as n,jt as o,ye as p,Se as q,re as r,he as s,be as t,ve as u,ke as v,we as w,xe as x,$e as y,Te as z};
|
package/dist/chunk-G6JMMJYH.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import {c,a as a$1,b as b$1,l,d,e,o}from'./chunk-5F2FD6DX.js';var R={},u={},f={},b={},x=new Set,_={},a={},Y=e=>new Promise(t=>setTimeout(t,e)),Z=(e,t)=>{if(!t)return false;let r=b[e];return r?Date.now()-r.timestamp<t:false},n={cacheHits:0,cacheMisses:0,dedupes:0,requests:0,failures:0,avgMs:0,lastMs:0},ee=e=>{delete R[e],x.delete(e);let t=r=>r===e||r.startsWith(`${e}:`);Object.keys(u).forEach(r=>{t(r)&&delete u[r];}),Object.keys(f).forEach(r=>{t(r)&&delete f[r];}),Object.keys(b).forEach(r=>{t(r)&&delete b[r];});},D=(e,t)=>{a[e]||(a[e]=new Set),a[e].add(t),T(e);},L=(e,t)=>{let r=a[e];r&&(r.delete(t),r.size===0&&delete a[e]);},T=e=>{_[e]||(_[e]=o(e,t=>{if(t!==null)return;let r=a[e];r&&(r.forEach(o=>{try{o();}catch{}}),delete a[e]),_[e]?.(),delete _[e],ee(e);}));},te=async(e$1,t,r={})=>{if(!e$1||typeof e$1!="string"){c("fetchStore requires a store name as first argument");return}if(!t){c(`fetchStore("${e$1}") requires a URL or Promise as second argument`);return}let{transform:o,onSuccess:w,onError:W,method:H,headers:U,body:K,ttl:B,staleWhileRevalidate:I=false,dedupe:N=true,retry:V=0,retryDelay:z=400,retryBackoff:J=1.7,signal:E,cacheKey:M}=r;!E&&a$1()&&!x.has(e$1)&&(x.add(e$1),b$1(`fetchStore("${e$1}") called without an AbortSignal. Provide "signal" to enable cancellation (recommended).`));let s=M?`${e$1}:${M}`:e$1;if(l(e$1)||d(e$1,{data:null,loading:false,error:null,status:"idle"}),T(e$1),Z(s,B)){n.cacheHits+=1;let g=b[s].data;if(e(e$1,{data:g,loading:false,error:null,status:"success",cached:true}),!I)return g}else n.cacheMisses+=1;if(N&&u[s])return n.dedupes+=1,u[s];let $=(f[s]??0)+1;f[s]=$,e(e$1,{loading:true,error:null,status:"loading"}),n.requests+=1;let G=Date.now(),v=!E&&typeof AbortController<"u"?new AbortController:null,Q=E||v?.signal,S=v?()=>{v.signal.aborted||v.abort();}:null;S&&D(e$1,S);let q=(async()=>{let g=0,F=z??400;for(;;)try{let i;if(typeof t=="string"){let X=re({method:H,headers:U,body:K,signal:Q,...r}),l=await fetch(t,X);if(!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);(l.headers.get("content-type")||"").includes("application/json")?i=await l.json():i=await l.text();}else if(typeof t.then=="function")i=await t;else return c(`fetchStore("${e$1}") - second argument must be a URL string or Promise.
|
|
2
|
-
Examples:
|
|
3
|
-
fetchStore("users", "https://api.example.com/users")
|
|
4
|
-
fetchStore("users", axios.get("/users"))`),null;let h=o?o(i):i;if(f[s]!==$)return null;b[s]={timestamp:Date.now(),data:h},l(e$1)&&e(e$1,{data:h,loading:!1,error:null,status:"success"}),w?.(h);let c$1=Date.now()-G;return n.lastMs=c$1,n.avgMs=(n.avgMs*(n.requests-1)+c$1)/n.requests,h}catch(i){if(g+=1,i?.name==="AbortError")return b$1(`fetchStore("${e$1}") aborted`),l(e$1)&&e(e$1,{loading:false,error:"aborted",status:"aborted"}),null;if(g<=(V??0)){await Y(F),F*=J??1.7;continue}if(f[s]!==$)return null;let c=i?.message||"Something went wrong";return l(e$1)&&e(e$1,{data:null,loading:false,error:c,status:"error"}),W?.(c),n.failures+=1,b$1(`fetchStore("${e$1}") failed: ${c}`),null}})().finally(()=>{delete u[s],S&&L(e$1,S);});return u[s]=q,R[e$1]={url:t,options:{...r,cacheKey:M}},q},j=async e=>{let t=R[e];if(!t){a$1()&&b$1(`refetchStore("${e}") - no previous fetch found.
|
|
5
|
-
Call fetchStore("${e}", url) first.`);return}return te(e,t.url,t.options)},A=new Set,C={},ae=e=>{if(typeof window>"u"||typeof window.addEventListener!="function")return ()=>{};let t=e??"*";if(A.has(t))return C[t]??(()=>{});let r=()=>{t==="*"?Object.keys(R).forEach(w=>{j(w);}):j(t);};window.addEventListener("focus",r),window.addEventListener("online",r),A.add(t);let o=()=>{window.removeEventListener("focus",r),window.removeEventListener("online",r),A.delete(t),delete C[t],t!=="*"&&L(t,o);};return C[t]=o,t!=="*"&&D(t,o),o},re=e=>{let t={};return e.method&&(t.method=e.method.toUpperCase()),e.headers?t.headers=e.headers:t.headers={"Content-Type":"application/json"},e.body&&(t.body=typeof e.body=="string"?e.body:JSON.stringify(e.body)),e.signal&&(t.signal=e.signal),t},ce=()=>({...n});export{te as a,j as b,ae as c,ce as d};
|
package/dist/chunk-JBYLHJKN.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import {r,o,p,l,b,a,e}from'./chunk-5F2FD6DX.js';import {useCallback,useSyncExternalStore,useEffect,useRef}from'react';var m=(t,e)=>{if(!e)return t;let o=e.split("."),n=t;for(let r of o){if(n==null)return null;n=n[r];}return n??null},h=new Set,w=(t,e)=>{if(Object.is(t,e))return true;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return false;let o=Object.keys(t),n=Object.keys(e);if(o.length!==n.length)return false;for(let r of o)if(!Object.prototype.hasOwnProperty.call(e,r)||!Object.is(t[r],e[r]))return false;return true};function c(t,e,o$1=Object.is){let n=typeof e=="function",r$1=typeof e=="string"?e:void 0,u=n?e:void 0,p$1=useCallback(s=>n?r(t,i=>u(i),o$1,s):o(t,()=>s()),[t,n,u,o$1]),S=useCallback(()=>{let s=p(t);return n?s==null?null:u(s):m(s,r$1)},[t,n,u,r$1]),l$1=useSyncExternalStore(p$1,S,S);return useEffect(()=>{l(t)||b(`useStore("${t}") - store not found yet.
|
|
2
|
-
Component will update automatically when createStore("${t}") is called.`),a()&&!n&&!r$1&&!h.has(t)&&(h.add(t),b(`useStore("${t}") without a selector/path subscribes to the entire store and may re-render on every change.
|
|
3
|
-
Prefer useSelector/useStoreField for better performance.`));},[t,n,r$1]),l$1}var v=(t,e)=>c(t,e),C=(t,e,o=w)=>{let n=useRef(null),r$1=useCallback(l=>{if(l==null)return null;let s=e(l),i=n.current;return i!==null&&o(s,i)?i:(n.current=s,s)},[e,o]),u=useCallback(()=>{let l=p(t);return r$1(l)},[t,r$1]),p$1=useCallback(l=>r(t,s=>r$1(s),o,()=>l()),[t,r$1,o]);return useSyncExternalStore(p$1,u,u)},E=(t,e)=>{let o=p(t);return o==null?null:m(o,e)};var A=t=>{let e=c(t);return {data:e?.data??null,loading:e?.loading??false,error:e?.error??null,status:e?.status??"idle",isEmpty:!e?.data&&!e?.loading&&!e?.error}};var _=(t,e$1)=>{let o=c(t,e$1),n=useCallback(r=>{let u=r?.target?r.target.value:r;e(t,e$1,u);},[t,e$1]);return {value:o,onChange:n}};export{c as a,v as b,C as c,E as d,A as e,_ as f};
|
package/dist/chunk-K6QIWMMW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {c,g,e,b,l as l$1}from'./chunk-5F2FD6DX.js';var l=class r{constructor(t,e=[]){this._storeName=t,this._path=e;}nested(t){return typeof t!="string"||t.trim()===""?(c(`nested() expects a string key. Got: ${JSON.stringify(t)}`),this):new r(this._storeName,[...this._path,t])}target(t){return typeof t!="string"||t.trim()===""?(c(`target() expects a string key. Got: ${JSON.stringify(t)}`),new a(this._storeName,this._path,null)):new a(this._storeName,this._path,t)}get value(){return this._path.length===0?g(this._storeName):g(this._storeName,this._path.join("."))}set(t){this._path.length===0?e(this._storeName,t):e(this._storeName,this._path.join("."),t);}},a=class{constructor(t,e,o){this._storeName=t,this._parentPath=e,this._key=o,this._fullPath=o?[...e,o].join("."):e.join(".");}get value(){return this._key?g(this._storeName,this._fullPath):(b("target() was called without a key - returning null"),null)}set(t){if(!this._key){b("target() was called without a key - cannot set value");return}e(this._storeName,this._fullPath,t);}},p=r=>(l$1(r)||b(`chain("${r}") called before store exists; operations will no-op until created.`),new l(r));export{p as a};
|
package/dist/core-CKzRwVaY.d.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
type PathInput = string | readonly string[] | string[];
|
|
2
|
-
|
|
3
|
-
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
4
|
-
type PrevDepth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
5
|
-
type PathInternal<T, Depth extends number> = Depth extends 0 ? never : T extends Primitive ? never : {
|
|
6
|
-
[K in keyof T & (string | number)]: T[K] extends Primitive | Array<unknown> ? `${K}` : `${K}` | `${K}.${PathInternal<T[K], PrevDepth[Depth]>}`;
|
|
7
|
-
}[keyof T & (string | number)];
|
|
8
|
-
type Path<T, Depth extends number = 6> = PathInternal<T, Depth>;
|
|
9
|
-
type PathValue<T, P extends Path<T>> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K]> ? PathValue<T[K], Rest> : never : never : P extends keyof T ? T[P] : never;
|
|
10
|
-
type PartialDeep<T> = T extends Primitive ? T : {
|
|
11
|
-
[K in keyof T]?: PartialDeep<T[K]>;
|
|
12
|
-
};
|
|
13
|
-
type StoreValue = unknown;
|
|
14
|
-
interface StoreDefinition<Name extends string = string, State = StoreValue> {
|
|
15
|
-
name: Name;
|
|
16
|
-
state?: State;
|
|
17
|
-
}
|
|
18
|
-
interface PersistConfig {
|
|
19
|
-
driver: {
|
|
20
|
-
getItem?: (k: string) => string | null;
|
|
21
|
-
setItem?: (k: string, v: string) => void;
|
|
22
|
-
removeItem?: (k: string) => void;
|
|
23
|
-
[key: string]: unknown;
|
|
24
|
-
};
|
|
25
|
-
key: string;
|
|
26
|
-
serialize: (v: unknown) => string;
|
|
27
|
-
deserialize: (v: string) => unknown;
|
|
28
|
-
encrypt: (v: string) => string;
|
|
29
|
-
decrypt: (v: string) => string;
|
|
30
|
-
onMigrationFail?: "reset" | "keep" | ((state: unknown) => unknown);
|
|
31
|
-
onStorageCleared?: (info: {
|
|
32
|
-
name: string;
|
|
33
|
-
key: string;
|
|
34
|
-
reason: "clear" | "remove" | "missing";
|
|
35
|
-
}) => void;
|
|
36
|
-
}
|
|
37
|
-
interface MiddlewareCtx {
|
|
38
|
-
action: string;
|
|
39
|
-
name: string;
|
|
40
|
-
prev: StoreValue;
|
|
41
|
-
next: StoreValue;
|
|
42
|
-
path: unknown;
|
|
43
|
-
}
|
|
44
|
-
interface StoreOptions<State = StoreValue> {
|
|
45
|
-
persist?: boolean | string | PersistConfig;
|
|
46
|
-
devtools?: boolean;
|
|
47
|
-
middleware?: Array<(ctx: MiddlewareCtx) => StoreValue | void>;
|
|
48
|
-
onSet?: (prev: State, next: State) => void;
|
|
49
|
-
onReset?: (prev: State, next: State) => void;
|
|
50
|
-
onDelete?: (prev: State) => void;
|
|
51
|
-
onCreate?: (initial: State) => void;
|
|
52
|
-
onError?: (err: string) => void;
|
|
53
|
-
validator?: (next: State) => boolean;
|
|
54
|
-
schema?: unknown;
|
|
55
|
-
migrations?: Record<number, (state: State) => State>;
|
|
56
|
-
version?: number;
|
|
57
|
-
redactor?: (state: State) => State;
|
|
58
|
-
historyLimit?: number;
|
|
59
|
-
allowSSRGlobalStore?: boolean;
|
|
60
|
-
sync?: boolean | {
|
|
61
|
-
channel?: string;
|
|
62
|
-
maxPayloadBytes?: number;
|
|
63
|
-
conflictResolver?: (args: {
|
|
64
|
-
local: StoreValue;
|
|
65
|
-
incoming: StoreValue;
|
|
66
|
-
localUpdated: number;
|
|
67
|
-
incomingUpdated: number;
|
|
68
|
-
}) => StoreValue | void;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
type NormalizedOptions = {
|
|
72
|
-
persist: PersistConfig | null;
|
|
73
|
-
devtools: boolean;
|
|
74
|
-
middleware: Array<(ctx: MiddlewareCtx) => StoreValue | void>;
|
|
75
|
-
onSet?: (prev: StoreValue, next: StoreValue) => void;
|
|
76
|
-
onReset?: (prev: StoreValue, next: StoreValue) => void;
|
|
77
|
-
onDelete?: (prev: StoreValue) => void;
|
|
78
|
-
onCreate?: (initial: StoreValue) => void;
|
|
79
|
-
onError?: (err: string) => void;
|
|
80
|
-
validator?: (next: StoreValue) => boolean;
|
|
81
|
-
schema?: unknown;
|
|
82
|
-
migrations: Record<number, (state: any) => any>;
|
|
83
|
-
version: number;
|
|
84
|
-
redactor?: (state: StoreValue) => StoreValue;
|
|
85
|
-
historyLimit: number;
|
|
86
|
-
allowSSRGlobalStore?: boolean;
|
|
87
|
-
sync?: boolean | {
|
|
88
|
-
channel?: string;
|
|
89
|
-
maxPayloadBytes?: number;
|
|
90
|
-
conflictResolver?: (args: {
|
|
91
|
-
local: StoreValue;
|
|
92
|
-
incoming: StoreValue;
|
|
93
|
-
localUpdated: number;
|
|
94
|
-
incomingUpdated: number;
|
|
95
|
-
}) => StoreValue | void;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
interface MetaEntry {
|
|
99
|
-
createdAt: string;
|
|
100
|
-
updatedAt: string;
|
|
101
|
-
updateCount: number;
|
|
102
|
-
version: number;
|
|
103
|
-
metrics: {
|
|
104
|
-
notifyCount: number;
|
|
105
|
-
totalNotifyMs: number;
|
|
106
|
-
lastNotifyMs: number;
|
|
107
|
-
};
|
|
108
|
-
options: NormalizedOptions;
|
|
109
|
-
}
|
|
110
|
-
interface HistoryEntry {
|
|
111
|
-
ts: number;
|
|
112
|
-
action: string;
|
|
113
|
-
prev: StoreValue;
|
|
114
|
-
next: StoreValue;
|
|
115
|
-
diff: {
|
|
116
|
-
added: string[];
|
|
117
|
-
removed: string[];
|
|
118
|
-
changed: string[];
|
|
119
|
-
} | null;
|
|
120
|
-
}
|
|
121
|
-
type Subscriber = (value: StoreValue | null) => void;
|
|
122
|
-
declare const createStore: <Name extends string, State>(name: Name, initialData: State, option?: StoreOptions<State>) => StoreDefinition<Name, State> | undefined;
|
|
123
|
-
declare function setStore<Name extends string, State, P extends Path<State>>(name: StoreDefinition<Name, State>, path: P, value: PathValue<State, P>): void;
|
|
124
|
-
declare function setStore<Name extends string, State>(name: StoreDefinition<Name, State>, mutator: (draft: State) => void): void;
|
|
125
|
-
declare function setStore<Name extends string, State>(name: StoreDefinition<Name, State>, data: PartialDeep<State>): void;
|
|
126
|
-
declare function setStore(name: string, data: Record<string, unknown>): void;
|
|
127
|
-
declare function setStore(name: string, path: string | string[], value: unknown): void;
|
|
128
|
-
declare function setStore(name: string, mutator: (draft: any) => void): void;
|
|
129
|
-
declare const setStoreBatch: (fn: () => void) => void;
|
|
130
|
-
declare function getStore<Name extends string, State, P extends Path<State>>(name: StoreDefinition<Name, State>, path: P): PathValue<State, P> | null;
|
|
131
|
-
declare function getStore<Name extends string, State>(name: StoreDefinition<Name, State>, path?: undefined): State | null;
|
|
132
|
-
declare function getStore(name: string, path?: PathInput): StoreValue | null;
|
|
133
|
-
declare const deleteStore: (name: string) => void;
|
|
134
|
-
declare const resetStore: (name: string) => void;
|
|
135
|
-
declare const mergeStore: (name: string, data: Record<string, unknown>) => void;
|
|
136
|
-
declare const clearAllStores: () => void;
|
|
137
|
-
declare const hasStore: (name: string) => boolean;
|
|
138
|
-
declare const listStores: () => string[];
|
|
139
|
-
declare const getStoreMeta: (name: string) => MetaEntry | null;
|
|
140
|
-
declare const createSelector: <TState, TResult>(storeName: string, selectorFn: (state: TState) => TResult) => () => NonNullable<TResult> | null;
|
|
141
|
-
declare const subscribeWithSelector: <R>(name: string, selector: (state: any) => R, equality: ((a: R, b: R) => boolean) | undefined, listener: (next: R, prev: R) => void) => (() => void);
|
|
142
|
-
declare const createCounterStore: (name: string, initial?: number, options?: StoreOptions) => {
|
|
143
|
-
inc: (n?: number) => void;
|
|
144
|
-
dec: (n?: number) => void;
|
|
145
|
-
set: (v: number) => void;
|
|
146
|
-
reset: () => void;
|
|
147
|
-
get: () => unknown;
|
|
148
|
-
};
|
|
149
|
-
declare const createListStore: <T>(name: string, initial?: T[], options?: StoreOptions) => {
|
|
150
|
-
push: (item: T) => void;
|
|
151
|
-
removeAt: (index: number) => void;
|
|
152
|
-
clear: () => void;
|
|
153
|
-
replace: (items: T[]) => void;
|
|
154
|
-
all: () => T[];
|
|
155
|
-
};
|
|
156
|
-
declare const createEntityStore: <T extends {
|
|
157
|
-
id?: string;
|
|
158
|
-
_id?: string;
|
|
159
|
-
}>(name: string, options?: StoreOptions) => {
|
|
160
|
-
upsert: (entity: T) => void;
|
|
161
|
-
remove: (id: string) => void;
|
|
162
|
-
all: () => T[];
|
|
163
|
-
get: (id: string) => T | null;
|
|
164
|
-
clear: () => void;
|
|
165
|
-
};
|
|
166
|
-
declare const getInitialState: () => Record<string, StoreValue>;
|
|
167
|
-
declare const getHistory: (name: string, limit?: number) => HistoryEntry[];
|
|
168
|
-
declare const clearHistory: (name?: string) => void;
|
|
169
|
-
declare const getMetrics: (name: string) => MetaEntry["metrics"] | null;
|
|
170
|
-
declare const createStoreForRequest: (initializer?: (api: {
|
|
171
|
-
create: (name: string, data: any, options?: StoreOptions) => any;
|
|
172
|
-
set: (name: string, updater: any) => any;
|
|
173
|
-
get: (name: string) => any;
|
|
174
|
-
}) => void) => {
|
|
175
|
-
snapshot: () => Record<string, any>;
|
|
176
|
-
hydrate: (options?: Record<string, StoreOptions> & {
|
|
177
|
-
default?: StoreOptions;
|
|
178
|
-
}) => void;
|
|
179
|
-
};
|
|
180
|
-
declare const hydrateStores: (snapshot: Record<string, any>, options?: Record<string, StoreOptions> & {
|
|
181
|
-
default?: StoreOptions;
|
|
182
|
-
}) => void;
|
|
183
|
-
declare const createZustandCompatStore: <T>(initializer: (set: (partial: Partial<T>, replace?: boolean) => void, get: () => T, api: any) => T, options?: StoreOptions & {
|
|
184
|
-
name?: string;
|
|
185
|
-
}) => {
|
|
186
|
-
setState: (partial: Partial<T> | ((state: T) => Partial<T>), replace?: boolean) => void;
|
|
187
|
-
getState: () => T;
|
|
188
|
-
subscribe: (listener: Subscriber) => () => void;
|
|
189
|
-
subscribeWithSelector: (selector: (state: T) => any, equality?: (value1: any, value2: any) => boolean, listener?: (next: any, prev: any) => void) => () => void;
|
|
190
|
-
destroy: () => void;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
declare class StroidChain {
|
|
194
|
-
private _storeName;
|
|
195
|
-
private _path;
|
|
196
|
-
constructor(storeName: string, path?: string[]);
|
|
197
|
-
nested(key: string): StroidChain;
|
|
198
|
-
target(key: string): TargetNode;
|
|
199
|
-
get value(): unknown;
|
|
200
|
-
set(newValue: unknown): void;
|
|
201
|
-
}
|
|
202
|
-
declare class TargetNode {
|
|
203
|
-
private _storeName;
|
|
204
|
-
private _parentPath;
|
|
205
|
-
private _key;
|
|
206
|
-
private _fullPath;
|
|
207
|
-
constructor(storeName: string, parentPath: string[], key: string | null);
|
|
208
|
-
get value(): unknown;
|
|
209
|
-
set(newValue: unknown): void;
|
|
210
|
-
}
|
|
211
|
-
declare const chain: (storeName: string) => StroidChain;
|
|
212
|
-
|
|
213
|
-
export { clearAllStores as a, clearHistory as b, chain as c, createCounterStore as d, createEntityStore as e, createListStore as f, createSelector as g, createStore as h, createStoreForRequest as i, createZustandCompatStore as j, deleteStore as k, getHistory as l, getInitialState as m, getMetrics as n, getStore as o, getStoreMeta as p, hasStore as q, hydrateStores as r, listStores as s, mergeStore as t, resetStore as u, setStore as v, setStoreBatch as w, subscribeWithSelector as x };
|