seitu 0.10.7 → 0.10.9

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.
@@ -7,7 +7,7 @@ import type { ValidationSchemaErrorProps } from '../validate';
7
7
  * @example
8
8
  * ```ts
9
9
  * import { createWebStorageValue } from 'seitu/web'
10
- * import { repairWebStorageValueObjectWithDefault } from 'seitu/utils'
10
+ * import { repairValueObjectWithDefault } from 'seitu/utils'
11
11
  * import * as z from 'zod'
12
12
  *
13
13
  * const value = createWebStorageValue({
@@ -15,13 +15,13 @@ import type { ValidationSchemaErrorProps } from '../validate';
15
15
  * schema: z.object({ a: z.number(), b: z.string() }),
16
16
  * key: 'storage-key',
17
17
  * defaultValue: { a: 0, b: 'default' },
18
- * onValidationError: repairWebStorageValueObjectWithDefault,
18
+ * onValidationError: repairValueObjectWithDefault,
19
19
  * })
20
20
  * value.get() // { a: 0, b: 'default' }
21
21
  * window.localStorage.setItem('storage-key', JSON.stringify({ a: 1 }))
22
22
  * value.get() // { a: 1, b: 'default' }
23
23
  * ```
24
24
  */
25
- export declare function repairWebStorageValueObjectWithDefault<O extends Record<string, unknown>>(props: ValidationSchemaErrorProps<O>): O & {
25
+ export declare function repairValueObjectWithDefault<O extends Record<string, unknown>>(props: ValidationSchemaErrorProps<O>): O & {
26
26
  [k: string]: any;
27
27
  };
package/dist/utils.js CHANGED
@@ -6,4 +6,4 @@ function e(e) {
6
6
  };
7
7
  }
8
8
  //#endregion
9
- export { e as repairWebStorageValueObjectWithDefault };
9
+ export { e as repairValueObjectWithDefault };
package/dist/web.js CHANGED
@@ -67,23 +67,23 @@ function s(e) {
67
67
  //#endregion
68
68
  //#region src/web/web-storage.ts
69
69
  function c(n) {
70
- let i = !1, { subscribe: a, notify: o } = t({ onFirstSubscribe: () => {
71
- let e = () => {
72
- i || o();
70
+ let i = { ...n.defaultValues }, { subscribe: a, notify: o } = t({ onFirstSubscribe: () => {
71
+ let e = (e) => {
72
+ Object.keys(i).some((t) => String(n.keyTransform ? n.keyTransform(t) : t) === e.key) && o();
73
73
  };
74
74
  return typeof window < "u" && window.addEventListener("storage", e), () => {
75
75
  typeof window < "u" && window.removeEventListener("storage", e);
76
76
  };
77
- } }), s = { ...n.defaultValues }, c = Object.keys(n.defaultValues), l = /* @__PURE__ */ new Map(), u, d = () => {
77
+ } }), s = Object.keys(n.defaultValues), c = /* @__PURE__ */ new Map(), l, u = () => {
78
78
  if (typeof window > "u") return n.defaultValues;
79
- let t = window[n.type], r = u !== void 0, i = {};
80
- for (let e of c) {
79
+ let t = window[n.type], r = l !== void 0, i = {};
80
+ for (let e of s) {
81
81
  let a = String(n.keyTransform ? n.keyTransform(e) : e), o = t.getItem(a);
82
- i[e] = o, r && l.get(e) !== o && (r = !1);
82
+ i[e] = o, r && c.get(e) !== o && (r = !1);
83
83
  }
84
- if (r) return u;
84
+ if (r) return l;
85
85
  let a = { ...n.defaultValues };
86
- for (let t of c) {
86
+ for (let t of s) {
87
87
  let r = i[t];
88
88
  r === null ? a[t] = n.defaultValues[t] : a[t] = e(n.schemas[t], r, {
89
89
  defaultValue: n.defaultValues[t],
@@ -94,27 +94,27 @@ function c(n) {
94
94
  value: r,
95
95
  defaultValue: n.defaultValues[t]
96
96
  }) : void 0
97
- }), l.set(String(t), i[String(t)]);
97
+ }), c.set(String(t), i[String(t)]);
98
98
  }
99
- return u = a, a;
100
- }, f = r(d, a, o);
99
+ return l = a, a;
100
+ }, d = r(u, a, o);
101
101
  return {
102
- ...f,
102
+ ...d,
103
103
  set: (e) => {
104
- let t = typeof e == "function" ? e(d()) : e;
104
+ let t = typeof e == "function" ? e(u()) : e;
105
105
  if (typeof window > "u") return;
106
106
  let r = window[n.type];
107
- i = !0, Object.entries(t).forEach(([e, t]) => {
107
+ Object.entries(t).forEach(([e, t]) => {
108
108
  let i = typeof t == "string" ? t : JSON.stringify(t);
109
109
  r.setItem(n.keyTransform ? n.keyTransform(e) : e, i), window.dispatchEvent(new StorageEvent("storage", {
110
110
  key: n.keyTransform ? n.keyTransform(e) : e,
111
111
  newValue: i
112
112
  }));
113
- }), i = !1, u = void 0, o();
113
+ }), l = void 0;
114
114
  },
115
115
  "~": {
116
- ...f["~"],
117
- getDefaultValue: (e) => s[e],
116
+ ...d["~"],
117
+ getDefaultValue: (e) => i[e],
118
118
  type: n.type
119
119
  }
120
120
  };
@@ -123,45 +123,45 @@ function c(n) {
123
123
  //#region src/web/web-storage-value.ts
124
124
  var l = Symbol("no-cache");
125
125
  function u(i) {
126
- let a = "storage" in i ? i.storage["~"].type : i.type, o = !1, s = ("schema" in i ? i.defaultValue : i.storage["~"].getDefaultValue(i.key)) ?? null, { subscribe: c, notify: u } = t({ onFirstSubscribe: () => {
126
+ let a = "storage" in i ? i.storage["~"].type : i.type, o = ("schema" in i ? i.defaultValue : i.storage["~"].getDefaultValue(i.key)) ?? null, { subscribe: s, notify: c } = t({ onFirstSubscribe: () => {
127
127
  let e = (e) => {
128
- o || e.key === i.key && u();
128
+ e.key === i.key && c();
129
129
  };
130
130
  return typeof window < "u" && window.addEventListener("storage", e), () => {
131
131
  typeof window < "u" && window.removeEventListener("storage", e);
132
132
  };
133
- } }), d = l, f, p = () => {
134
- if (typeof window > "u") return s;
133
+ } }), u = l, d, f = () => {
134
+ if (typeof window > "u") return o;
135
135
  let t = window[a].getItem(i.key);
136
- if (d !== l && t === d) return f;
137
- if (d = t, t === null) return f = s, f;
136
+ if (u !== l && t === u) return d;
137
+ if (u = t, t === null) return d = o, d;
138
138
  let r = n(t);
139
139
  try {
140
- return "schema" in i ? (f = e(i.schema, t, {
141
- defaultValue: s,
140
+ return "schema" in i ? (d = e(i.schema, t, {
141
+ defaultValue: o,
142
142
  label: `createWebStorageValue:${i.key}`,
143
143
  onError: i.onValidationError ? (e, t) => i.onValidationError({
144
- defaultValue: s,
144
+ defaultValue: o,
145
145
  issues: [...e],
146
146
  value: t
147
147
  }) : void 0
148
- }), f) : (f = r, f);
148
+ }), d) : (d = r, d);
149
149
  } catch {
150
- return f = s !== void 0 && typeof s != "string" ? s : r, f;
150
+ return d = o !== void 0 && typeof o != "string" ? o : r, d;
151
151
  }
152
152
  };
153
153
  return {
154
- ...r(p, c, u),
154
+ ...r(f, s, c),
155
155
  set: (e) => {
156
156
  if (typeof window > "u") return;
157
- let t = window[a], n = typeof e == "function" ? e(p()) : e;
158
- o = !0, t.setItem(i.key, typeof n == "string" ? n : JSON.stringify(n)), window.dispatchEvent(new StorageEvent("storage", {
157
+ let t = window[a], n = typeof e == "function" ? e(f()) : e;
158
+ t.setItem(i.key, typeof n == "string" ? n : JSON.stringify(n)), window.dispatchEvent(new StorageEvent("storage", {
159
159
  key: i.key,
160
160
  newValue: n
161
- })), o = !1, d = l, u();
161
+ })), u = l;
162
162
  },
163
163
  remove: () => {
164
- typeof window > "u" || (window[a].removeItem(i.key), d = l);
164
+ typeof window > "u" || (window[a].removeItem(i.key), u = l);
165
165
  }
166
166
  };
167
167
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seitu",
3
3
  "displayName": "Seitu",
4
4
  "type": "module",
5
- "version": "0.10.7",
5
+ "version": "0.10.9",
6
6
  "private": false,
7
7
  "author": "Valerii Strilets",
8
8
  "license": "MIT",