seitu 0.10.5 → 0.10.7
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/core/schema-store.d.ts +9 -12
- package/dist/{core-DSqQS36s.js → core-CIQELdxV.js} +8 -15
- package/dist/core.js +1 -1
- package/dist/validate.d.ts +2 -6
- package/dist/web/web-storage-value.d.ts +2 -2
- package/dist/web/web-storage.d.ts +10 -5
- package/dist/web.js +1 -1
- package/package.json +2 -2
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type { ValidationSchemaErrorProps } from '../validate';
|
|
2
|
+
import type { ValidationSchemaErrorProps, ValidationSchemaOutput } from '../validate';
|
|
3
3
|
import type { Readable, Subscribable, Writable } from './index';
|
|
4
|
-
export interface SchemaStore<O extends
|
|
5
|
-
'~': {
|
|
6
|
-
getDefaultValue: <K extends keyof O>(key: K) => O[K];
|
|
7
|
-
} & Subscribable<O>['~'];
|
|
4
|
+
export interface SchemaStore<O> extends Subscribable<O>, Readable<O>, Writable<O, O> {
|
|
8
5
|
}
|
|
9
|
-
export interface SchemaStoreOptions<
|
|
10
|
-
schema:
|
|
11
|
-
defaultValue:
|
|
6
|
+
export interface SchemaStoreOptions<S extends StandardSchemaV1<unknown>> {
|
|
7
|
+
schema: S;
|
|
8
|
+
defaultValue: ValidationSchemaOutput<S>;
|
|
12
9
|
/**
|
|
13
10
|
* Handle validation errors.
|
|
14
11
|
*
|
|
15
12
|
* If returns a value, it will be validated and used as the store value.
|
|
16
13
|
* If returns undefined, the default value will be returned.
|
|
17
14
|
*/
|
|
18
|
-
onValidationError?: (props: ValidationSchemaErrorProps<
|
|
15
|
+
onValidationError?: (props: ValidationSchemaErrorProps<ValidationSchemaOutput<S>>) => void | ValidationSchemaOutput<S>;
|
|
19
16
|
}
|
|
20
17
|
/**
|
|
21
18
|
* Creates a reactive schema store: state is validated on read, supports partial `set`, and
|
|
@@ -23,7 +20,7 @@ export interface SchemaStoreOptions<O extends Record<string, unknown>> {
|
|
|
23
20
|
*
|
|
24
21
|
* @example
|
|
25
22
|
* ```ts twoslash
|
|
26
|
-
* import { createSchemaStore
|
|
23
|
+
* import { createSchemaStore } from 'seitu'
|
|
27
24
|
* import * as z from 'zod'
|
|
28
25
|
*
|
|
29
26
|
* const store = createSchemaStore({
|
|
@@ -31,8 +28,8 @@ export interface SchemaStoreOptions<O extends Record<string, unknown>> {
|
|
|
31
28
|
* defaultValue: { count: 0, name: '' },
|
|
32
29
|
* })
|
|
33
30
|
* store.get()
|
|
34
|
-
* store.set({ count: 1 })
|
|
31
|
+
* store.set({ count: 1, name: 'alice' })
|
|
35
32
|
* store.subscribe(console.log)
|
|
36
33
|
* ```
|
|
37
34
|
*/
|
|
38
|
-
export declare function createSchemaStore<
|
|
35
|
+
export declare function createSchemaStore<S extends StandardSchemaV1<unknown>>(options: SchemaStoreOptions<S>): SchemaStore<ValidationSchemaOutput<S>>;
|
|
@@ -86,30 +86,23 @@ function o(e, t, n) {
|
|
|
86
86
|
//#endregion
|
|
87
87
|
//#region src/core/schema-store.ts
|
|
88
88
|
function s(n) {
|
|
89
|
-
let r = c(n.defaultValue), { subscribe: i, notify: a } = t(), s =
|
|
90
|
-
let e = r.get()
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
return o(n.schema, t, {
|
|
95
|
-
defaultValue: s,
|
|
89
|
+
let r = c(n.defaultValue), { subscribe: i, notify: a } = t(), s = () => {
|
|
90
|
+
let e = r.get();
|
|
91
|
+
return o(n.schema, e, {
|
|
92
|
+
defaultValue: n.defaultValue,
|
|
96
93
|
label: "createSchemaStore",
|
|
97
94
|
onError: n.onValidationError ? (e, t) => n.onValidationError({
|
|
98
95
|
issues: [...e],
|
|
99
96
|
value: t,
|
|
100
|
-
defaultValue:
|
|
97
|
+
defaultValue: n.defaultValue
|
|
101
98
|
}) : void 0
|
|
102
99
|
});
|
|
103
|
-
}
|
|
100
|
+
};
|
|
104
101
|
return {
|
|
105
|
-
...
|
|
102
|
+
...e(s, i, a),
|
|
106
103
|
set: (e) => {
|
|
107
|
-
let t = typeof e == "function" ? e(
|
|
104
|
+
let t = typeof e == "function" ? e(s()) : e;
|
|
108
105
|
r.set(t), a();
|
|
109
|
-
},
|
|
110
|
-
"~": {
|
|
111
|
-
...u["~"],
|
|
112
|
-
getDefaultValue: (e) => s[e]
|
|
113
106
|
}
|
|
114
107
|
};
|
|
115
108
|
}
|
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as e, d as t, i as n, l as r, n as i, r as a, s as o, t as s, u as c } from "./core-
|
|
1
|
+
import { c as e, d as t, i as n, l as r, n as i, r as a, s as o, t as s, u as c } from "./core-CIQELdxV.js";
|
|
2
2
|
export { r as createComputed, e as createDebounce, o as createDebounceFn, c as createReadableSubscription, n as createSchemaStore, a as createStore, t as createSubscription, i as createThrottle, s as createThrottleFn };
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
|
|
3
|
-
export type ValidationObjectSchemas = Record<string, StandardSchemaV1<unknown, unknown>>;
|
|
4
|
-
export type ValidationObjectSchemasOutput<S extends ValidationObjectSchemas> = Simplify<{
|
|
5
|
-
[K in keyof S]: StandardSchemaV1.InferOutput<S[K]>;
|
|
6
|
-
}>;
|
|
2
|
+
export type ValidationSchemaOutput<S extends StandardSchemaV1<unknown>> = StandardSchemaV1.InferOutput<S>;
|
|
7
3
|
export interface ValidationSchemaErrorProps<O> {
|
|
8
4
|
defaultValue: O;
|
|
9
5
|
issues: StandardSchemaV1.Issue[];
|
|
10
6
|
value: unknown;
|
|
11
7
|
}
|
|
12
|
-
export interface
|
|
8
|
+
export interface ValidationSchemaObjectErrorProps<O extends Record<string, unknown>> {
|
|
13
9
|
defaultValue: O[keyof O];
|
|
14
10
|
issues: StandardSchemaV1.Issue[];
|
|
15
11
|
value: unknown;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { Readable, Removable, Subscribable, Writable } from '../core/index';
|
|
3
|
-
import type { ValidationSchemaErrorProps,
|
|
3
|
+
import type { ValidationSchemaErrorProps, ValidationSchemaObjectErrorProps } from '../validate';
|
|
4
4
|
import type { WebStorage } from './web-storage';
|
|
5
5
|
export interface WebStorageValue<V> extends Subscribable<V>, Readable<V>, Writable<V>, Removable {
|
|
6
6
|
}
|
|
7
7
|
export interface WebStorageValueOptionsWithStorage<Storage extends WebStorage<any>, K extends keyof Storage['~']['output']> {
|
|
8
8
|
storage: Storage;
|
|
9
9
|
key: K;
|
|
10
|
-
onValidationError?: (props:
|
|
10
|
+
onValidationError?: (props: ValidationSchemaObjectErrorProps<Storage['~']['output']>) => void;
|
|
11
11
|
}
|
|
12
12
|
export interface WebStorageValueOptionsWithSchema<S extends StandardSchemaV1<unknown>> {
|
|
13
13
|
type: 'localStorage' | 'sessionStorage';
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { Readable, Subscribable, Writable } from '../core/index';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { Simplify } from '../utils';
|
|
4
|
+
import type { ValidationSchemaObjectErrorProps } from '../validate';
|
|
5
|
+
export type WebStorageInput = Record<string, StandardSchemaV1<unknown, unknown>>;
|
|
6
|
+
export type WebStorageOutput<S extends WebStorageInput> = Simplify<{
|
|
7
|
+
[K in keyof S]: StandardSchemaV1.InferOutput<S[K]>;
|
|
8
|
+
}>;
|
|
9
|
+
export interface WebStorageOptions<S extends WebStorageInput> {
|
|
5
10
|
schemas: S;
|
|
6
|
-
defaultValues:
|
|
11
|
+
defaultValues: WebStorageOutput<S>;
|
|
7
12
|
type: 'localStorage' | 'sessionStorage';
|
|
8
13
|
keyTransform?: (key: keyof S) => string;
|
|
9
|
-
onValidationError?: (props:
|
|
14
|
+
onValidationError?: (props: ValidationSchemaObjectErrorProps<WebStorageOutput<S>>) => void | StandardSchemaV1.InferOutput<S[keyof S]>;
|
|
10
15
|
}
|
|
11
16
|
export interface WebStorage<O extends Record<string, unknown>> extends Subscribable<O>, Readable<O>, Writable<Partial<O>, O> {
|
|
12
17
|
'~': {
|
|
@@ -62,4 +67,4 @@ export interface WebStorage<O extends Record<string, unknown>> extends Subscriba
|
|
|
62
67
|
* }
|
|
63
68
|
* ```
|
|
64
69
|
*/
|
|
65
|
-
export declare function createWebStorage<S extends
|
|
70
|
+
export declare function createWebStorage<S extends WebStorageInput>(options: WebStorageOptions<S>): WebStorage<WebStorageOutput<S>>;
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, d as t, o as n, u as r } from "./core-
|
|
1
|
+
import { a as e, d as t, o as n, u as r } from "./core-CIQELdxV.js";
|
|
2
2
|
//#region src/web/is-online.ts
|
|
3
3
|
function i() {
|
|
4
4
|
let { subscribe: e, notify: n } = t({ onFirstSubscribe: () => (typeof window < "u" && (window.addEventListener("online", n), window.addEventListener("offline", n)), () => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "seitu",
|
|
3
3
|
"displayName": "Seitu",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.10.
|
|
5
|
+
"version": "0.10.7",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Valerii Strilets",
|
|
8
8
|
"license": "MIT",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"happy-dom": "^20.8.9",
|
|
82
82
|
"react-dom": "^19.2.4",
|
|
83
83
|
"type-fest": "^5.5.0",
|
|
84
|
-
"typescript": "^
|
|
84
|
+
"typescript": "^6.0.2",
|
|
85
85
|
"vite": "^8.0.3",
|
|
86
86
|
"vite-plugin-dts": "^4.5.4",
|
|
87
87
|
"vitest": "^4.1.2",
|