seitu 0.13.0 → 0.14.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.
@@ -123,12 +123,11 @@ function tryParseJson(value) {
123
123
  //#endregion
124
124
  //#region src/validate.ts
125
125
  function validateSchema(schema, value, options) {
126
- const parsed = tryParseJson(value);
127
- const result = schema["~standard"].validate(parsed);
126
+ const result = schema["~standard"].validate(value);
128
127
  if (result instanceof Promise) throw new TypeError(`[${options.label}] Validation schema should not return a Promise.`);
129
128
  if (!result.issues) return result.value;
130
129
  if (options.onError) {
131
- const corrected = options.onError(result.issues, parsed);
130
+ const corrected = options.onError(result.issues, value);
132
131
  if (corrected !== void 0) {
133
132
  const validated = schema["~standard"].validate(corrected);
134
133
  if (validated instanceof Promise) throw new TypeError(`[${options.label}] Validation schema should not return a Promise.`);
@@ -161,7 +160,7 @@ function validateSchema(schema, value, options) {
161
160
  function createSchemaStore(options) {
162
161
  const store = createStore(options.defaultValue);
163
162
  const get = () => {
164
- const stored = store.get();
163
+ const stored = tryParseJson(store.get());
165
164
  return validateSchema(options.schema, stored, {
166
165
  defaultValue: options.defaultValue,
167
166
  label: "createSchemaStore",
package/dist/core.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { S as createSubscription, _ as Readable, a as Store, b as Writable, c as SchemaStoreOptions, d as createDebouncedFn, f as Debounced, g as Clearable, h as createComputed, i as createThrottled, l as createSchemaStore, m as Computed, n as createThrottledFn, o as createStore, p as createDebounced, r as Throttled, s as SchemaStore, t as ThrottledFn, u as DebouncedFn, v as Subscribable, x as createReadableSubscription, y as SubscribeOptions } from "./index-ChvHgGIa.mjs";
1
+ import { S as createSubscription, _ as Readable, a as Store, b as Writable, c as SchemaStoreOptions, d as createDebouncedFn, f as Debounced, g as Clearable, h as createComputed, i as createThrottled, l as createSchemaStore, m as Computed, n as createThrottledFn, o as createStore, p as createDebounced, r as Throttled, s as SchemaStore, t as ThrottledFn, u as DebouncedFn, v as Subscribable, x as createReadableSubscription, y as SubscribeOptions } from "./index-Dzu3WPwr.mjs";
2
2
  export { Clearable, Computed, Debounced, DebouncedFn, Readable, SchemaStore, SchemaStoreOptions, Store, Subscribable, SubscribeOptions, Throttled, ThrottledFn, Writable, createComputed, createDebounced, createDebouncedFn, createReadableSubscription, createSchemaStore, createStore, createSubscription, createThrottled, createThrottledFn };
package/dist/core.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { c as createDebounced, d as createSubscription, i as createSchemaStore, l as createComputed, n as createThrottled, r as createStore, s as createDebouncedFn, t as createThrottledFn, u as createReadableSubscription } from "./core-BKImMfak.mjs";
1
+ import { c as createDebounced, d as createSubscription, i as createSchemaStore, l as createComputed, n as createThrottled, r as createStore, s as createDebouncedFn, t as createThrottledFn, u as createReadableSubscription } from "./core-CwV8yAwb.mjs";
2
2
  export { createComputed, createDebounced, createDebouncedFn, createReadableSubscription, createSchemaStore, createStore, createSubscription, createThrottled, createThrottledFn };
@@ -1,4 +1,4 @@
1
- import { i as StandardSchemaV1, r as ValidationSchemaOutput, t as ValidationSchemaErrorProps } from "./validate-BzLxGOQt.mjs";
1
+ import { i as StandardSchemaV1, r as ValidationSchemaOutput, t as ValidationSchemaErrorProps } from "./validate-IWiN_jFZ.mjs";
2
2
 
3
3
  //#region src/core/subscription.d.ts
4
4
  interface SubscribeOptions {
package/dist/react.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Readable, v as Subscribable } from "./index-ChvHgGIa.mjs";
1
+ import { _ as Readable, v as Subscribable } from "./index-Dzu3WPwr.mjs";
2
2
  import * as React$1 from "react";
3
3
 
4
4
  //#region src/react/hooks.d.ts
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ValidationSchemaErrorProps } from "./validate-BzLxGOQt.mjs";
1
+ import { t as ValidationSchemaErrorProps } from "./validate-IWiN_jFZ.mjs";
2
2
 
3
3
  //#region src/utils/validation.d.ts
4
4
  /**
package/dist/utils.mjs CHANGED
@@ -1,32 +1,2 @@
1
- //#region src/utils/validation.ts
2
- /**
3
- * Repair broken web storage value object if value was object but not all keys are in the default value object.
4
- *
5
- * @returns A new object with the existing keys in the value object that are not in the default value object.
6
- *
7
- * @example
8
- * ```ts
9
- * import { createWebStorageValue } from 'seitu/web'
10
- * import { repairValueObjectWithDefault } from 'seitu/utils'
11
- * import * as z from 'zod'
12
- *
13
- * const value = createWebStorageValue({
14
- * type: 'localStorage',
15
- * schema: z.object({ a: z.number(), b: z.string() }),
16
- * key: 'storage-key',
17
- * defaultValue: { a: 0, b: 'default' },
18
- * onValidationError: repairValueObjectWithDefault,
19
- * })
20
- * value.get() // { a: 0, b: 'default' }
21
- * window.localStorage.setItem('storage-key', JSON.stringify({ a: 1 }))
22
- * value.get() // { a: 1, b: 'default' }
23
- * ```
24
- */
25
- function repairValueObjectWithDefault(props) {
26
- return {
27
- ...props.defaultValue,
28
- ...typeof props.value === "object" && props.value !== null ? Object.fromEntries(Object.entries(props.value).filter(([key, val]) => key in props.defaultValue && typeof val === typeof props.defaultValue[key])) : {}
29
- };
30
- }
31
- //#endregion
1
+ import { t as repairValueObjectWithDefault } from "./validation-B8XxyKZ0.mjs";
32
2
  export { repairValueObjectWithDefault };
@@ -0,0 +1,32 @@
1
+ //#region src/utils/validation.ts
2
+ /**
3
+ * Repair broken web storage value object if value was object but not all keys are in the default value object.
4
+ *
5
+ * @returns A new object with the existing keys in the value object that are not in the default value object.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createWebStorageValue } from 'seitu/web'
10
+ * import { repairValueObjectWithDefault } from 'seitu/utils'
11
+ * import * as z from 'zod'
12
+ *
13
+ * const value = createWebStorageValue({
14
+ * type: 'localStorage',
15
+ * schema: z.object({ a: z.number(), b: z.string() }),
16
+ * key: 'storage-key',
17
+ * defaultValue: { a: 0, b: 'default' },
18
+ * onValidationError: repairValueObjectWithDefault,
19
+ * })
20
+ * value.get() // { a: 0, b: 'default' }
21
+ * window.localStorage.setItem('storage-key', JSON.stringify({ a: 1 }))
22
+ * value.get() // { a: 1, b: 'default' }
23
+ * ```
24
+ */
25
+ function repairValueObjectWithDefault(props) {
26
+ return {
27
+ ...props.defaultValue,
28
+ ...typeof props.value === "object" && props.value !== null ? Object.fromEntries(Object.entries(props.value).filter(([key, val]) => key in props.defaultValue && typeof val === typeof props.defaultValue[key])) : {}
29
+ };
30
+ }
31
+ //#endregion
32
+ export { repairValueObjectWithDefault as t };
package/dist/vue.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Readable, v as Subscribable } from "./index-ChvHgGIa.mjs";
1
+ import { _ as Readable, v as Subscribable } from "./index-Dzu3WPwr.mjs";
2
2
  import { MaybeRefOrGetter, ShallowRef } from "vue";
3
3
 
4
4
  //#region src/vue/composables.d.ts
package/dist/web.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as Readable, b as Writable, g as Clearable, v as Subscribable } from "./index-ChvHgGIa.mjs";
2
- import { i as StandardSchemaV1, n as ValidationSchemaObjectErrorProps, t as ValidationSchemaErrorProps } from "./validate-BzLxGOQt.mjs";
1
+ import { _ as Readable, b as Writable, g as Clearable, v as Subscribable } from "./index-Dzu3WPwr.mjs";
2
+ import { i as StandardSchemaV1, n as ValidationSchemaObjectErrorProps, t as ValidationSchemaErrorProps } from "./validate-IWiN_jFZ.mjs";
3
3
 
4
4
  //#region src/web/is-online.d.ts
5
5
  interface IsOnline extends Subscribable<boolean>, Readable<boolean> {}
package/dist/web.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { a as validateSchema, d as createSubscription, o as tryParseJson, u as createReadableSubscription } from "./core-BKImMfak.mjs";
1
+ import { a as validateSchema, d as createSubscription, o as tryParseJson, u as createReadableSubscription } from "./core-CwV8yAwb.mjs";
2
+ import { t as repairValueObjectWithDefault } from "./validation-B8XxyKZ0.mjs";
2
3
  //#region src/web/is-online.ts
3
4
  /**
4
5
  * Creates a reactive handle for browser online status.
@@ -321,7 +322,7 @@ function createWebStorage(options) {
321
322
  for (const key of keys) {
322
323
  const raw = currentRaws[key];
323
324
  if (raw === null) output[key] = options.defaultValues[key];
324
- else output[key] = validateSchema(options.schemas[key], raw, {
325
+ else output[key] = validateSchema(options.schemas[key], tryParseJson(raw), {
325
326
  defaultValue: options.defaultValues[key],
326
327
  label: `createWebStorage:${String(key)}`,
327
328
  onError: options.onValidationError ? (issues, parsed) => options.onValidationError({
@@ -344,7 +345,7 @@ function createWebStorage(options) {
344
345
  const resolvedValue = typeof value === "function" ? value(get()) : value;
345
346
  const storage = window[options.type];
346
347
  Object.entries(resolvedValue).forEach(([key, value]) => {
347
- const storageValue = typeof value === "string" ? value : JSON.stringify(value);
348
+ const storageValue = JSON.stringify(value);
348
349
  storage.setItem(options.keyTransform ? options.keyTransform(key) : key, storageValue);
349
350
  window.dispatchEvent(new StorageEvent("storage", {
350
351
  key: options.keyTransform ? options.keyTransform(key) : key,
@@ -378,6 +379,7 @@ function createWebStorage(options) {
378
379
  function createWebStorageValue(options) {
379
380
  const type = "storage" in options ? options.storage["~"].type : options.type;
380
381
  const defaultValue = ("schema" in options ? options.defaultValue : options.storage["~"].getDefaultValue(options.key)) ?? null;
382
+ const isDefaultValueObject = typeof defaultValue === "object" && defaultValue !== null;
381
383
  const { subscribe, notify } = createSubscription({ onFirstSubscribe: () => {
382
384
  const listener = (event) => {
383
385
  if (event.key === options.key) notify();
@@ -404,11 +406,25 @@ function createWebStorageValue(options) {
404
406
  cachedValue = validateSchema(options.schema, parsed, {
405
407
  defaultValue,
406
408
  label: `createWebStorageValue:${options.key}`,
407
- onError: options.onValidationError ? (issues, parsed) => options.onValidationError({
408
- defaultValue,
409
- issues: [...issues],
410
- value: parsed
411
- }) : void 0
409
+ onError: options.onValidationError ? (issues, parsed) => {
410
+ const toReturn = options.onValidationError({
411
+ defaultValue,
412
+ issues: [...issues],
413
+ value: parsed
414
+ });
415
+ if (toReturn === void 0 && isDefaultValueObject) return repairValueObjectWithDefault({
416
+ defaultValue,
417
+ issues: [...issues],
418
+ value: parsed
419
+ });
420
+ return toReturn;
421
+ } : (issues, parsed) => {
422
+ if (isDefaultValueObject) return repairValueObjectWithDefault({
423
+ defaultValue,
424
+ issues: [...issues],
425
+ value: parsed
426
+ });
427
+ }
412
428
  });
413
429
  return cachedValue;
414
430
  } else {
@@ -426,7 +442,7 @@ function createWebStorageValue(options) {
426
442
  if (typeof window === "undefined") return;
427
443
  const storage = window[type];
428
444
  const newValue = typeof value === "function" ? value(get()) : value;
429
- const storageValue = typeof newValue === "string" ? newValue : JSON.stringify(newValue);
445
+ const storageValue = JSON.stringify(newValue);
430
446
  storage.setItem(options.key, storageValue);
431
447
  window.dispatchEvent(new StorageEvent("storage", {
432
448
  key: options.key,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seitu",
3
3
  "displayName": "Seitu",
4
4
  "type": "module",
5
- "version": "0.13.0",
5
+ "version": "0.14.1",
6
6
  "private": false,
7
7
  "author": "Valerii Strilets",
8
8
  "license": "MIT",
@@ -78,14 +78,14 @@
78
78
  "@testing-library/react": "^16.3.2",
79
79
  "@types/react": "^19.2.14",
80
80
  "happy-dom": "^20.9.0",
81
- "react-dom": "^19.2.5",
82
- "tsdown": "^0.21.10",
81
+ "react-dom": "^19.2.6",
82
+ "tsdown": "^0.22.0",
83
83
  "type-fest": "^5.6.0",
84
84
  "typescript": "^6.0.3",
85
- "vite": "^8.0.10",
86
- "vitest": "^4.1.5",
87
- "vue": "^3.5.33",
88
- "zod": "^4.4.1"
85
+ "vite": "^8.0.13",
86
+ "vitest": "^4.1.6",
87
+ "vue": "^3.5.34",
88
+ "zod": "^4.4.3"
89
89
  },
90
90
  "scripts": {
91
91
  "build": "tsdown",