seitu 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Valerii Strilets
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Seitu
2
+
3
+ [![npm version](https://badge.fury.io/js/seitu.svg)](https://npmjs.com/package/seitu)
4
+ ![You need Seitu](https://img.shields.io/badge/You_need-Seitu-purple)
5
+
6
+ Seitu is a lightweight, framework-agnostic, type-safe utilities library for JavaScript applications on the client and server sides.
7
+
8
+ ## Documentation
9
+
10
+ You can find the documentation [here](https://seitu.letstri.dev).
11
+
12
+ ## Example
13
+
14
+ To quick start you only need to write the following code:
15
+
16
+ ```tsx
17
+ import { useSubscription } from 'seitu/react'
18
+ import { sessionStorageValue } from 'seitu/web'
19
+ import * as z from 'zod'
20
+
21
+ const value = sessionStorageValue({
22
+ key: 'test',
23
+ defaultValue: 0,
24
+ schema: z.number(),
25
+ })
26
+
27
+ value.get() // 0
28
+ value.set(1)
29
+ value.remove()
30
+ value.subscribe(v => console.log(v))
31
+
32
+ function Counter() {
33
+ const count = useSubscription(value)
34
+
35
+ return (
36
+ <div>
37
+ <span>{count}</span>
38
+ <button onClick={() => value.set(c => c + 1)}>Increment</button>
39
+ </div>
40
+ )
41
+ }
42
+ ```
43
+
44
+ Seitu has other powerful features, so check out the [docs](https://seitu.letstri.dev/docs) or the [examples](https://github.com/letstri/seitu/tree/main/examples) directory.
45
+
46
+ ## License
47
+
48
+ MIT License - see the [LICENSE](https://github.com/letstri/seitu/blob/main/LICENSE) file for details
@@ -0,0 +1 @@
1
+ export * from './subscription';
@@ -0,0 +1,19 @@
1
+ export interface Subscribable<V> {
2
+ 'subscribe': (callback: (value: V) => any) => () => void;
3
+ '~types': {
4
+ output: V;
5
+ };
6
+ }
7
+ export interface Readable<T> {
8
+ get: () => T;
9
+ }
10
+ export interface Writable<T, P extends Partial<T> = T> {
11
+ set: (value: T | ((prev: P) => T)) => any;
12
+ }
13
+ export interface Removable {
14
+ remove: () => void;
15
+ }
16
+ export declare function createSubscription<V>(): {
17
+ subscribe: (callback: (value: V) => any) => () => void;
18
+ notify: (value: V) => void;
19
+ };
package/dist/core.js ADDED
@@ -0,0 +1,14 @@
1
+ function e() {
2
+ let e = new Set();
3
+ return {
4
+ subscribe(t) {
5
+ return e.add(t), () => {
6
+ e.delete(t);
7
+ };
8
+ },
9
+ notify(t) {
10
+ e.forEach((e) => e(t));
11
+ }
12
+ };
13
+ }
14
+ export { e as createSubscription };
@@ -0,0 +1,71 @@
1
+ import type { Readable, Subscribable } from '../core/subscription';
2
+ /**
3
+ * Use this hook to access a subscription for any function that implements the Subscription interface.
4
+ *
5
+ * @kind hook
6
+ *
7
+ * @example
8
+ * ```tsx twoslash title="/app/page.tsx"
9
+ * 'use client'
10
+ *
11
+ * import { sessionStorageValue } from 'seitu/web'
12
+ * import { useSubscription } from 'seitu/react'
13
+ * import * as z from 'zod'
14
+ *
15
+ * export default function Page() {
16
+ * const value = useSubscription(sessionStorageValue({
17
+ * key: 'test',
18
+ * defaultValue: 0,
19
+ * schema: z.number(),
20
+ * }))
21
+ *
22
+ * return <div>{value}</div>
23
+ * }
24
+ * ```
25
+ *
26
+ * @example
27
+ * ```tsx twoslash title="/app/page.tsx"
28
+ * 'use client'
29
+ *
30
+ * import { sessionStorageValue } from 'seitu/web'
31
+ * import { useSubscription } from 'seitu/react'
32
+ * import * as z from 'zod'
33
+ *
34
+ * const sessionStorage = sessionStorageValue({
35
+ * key: 'test',
36
+ * defaultValue: 0,
37
+ * schema: z.number(),
38
+ * })
39
+ *
40
+ * export default function Page() {
41
+ * const value = useSubscription(sessionStorage)
42
+ *
43
+ * return <div>{value}</div>
44
+ * }
45
+ * ```
46
+ *
47
+ * @example
48
+ * ```tsx twoslash title="/app/page.tsx"
49
+ * 'use client'
50
+ *
51
+ * import { createSessionStorage, sessionStorageValue } from 'seitu/web'
52
+ * import { useSubscription } from 'seitu/react'
53
+ * import * as z from 'zod'
54
+ *
55
+ * const sessionStorage = createSessionStorage({
56
+ * schemas: {
57
+ * count: z.number(),
58
+ * name: z.string(),
59
+ * },
60
+ * defaultValues: { count: 0, name: '' },
61
+ * })
62
+ *
63
+ * // Usage with selector, re-renders only when count changes
64
+ * export default function Page() {
65
+ * const count = useSubscription(sessionStorage, value => value.count)
66
+ *
67
+ * return <div>{count}</div>
68
+ * }
69
+ * ```
70
+ */
71
+ export declare function useSubscription<S extends Subscribable<any> & Readable<any>, R = S['~types']['output']>(subscription: S, selector?: (value: S['~types']['output']) => R): R;
@@ -0,0 +1 @@
1
+ export * from './hooks';