@kdeveloper/kvark 0.3.1 → 0.3.2
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/{index.d.ts → atom-DDF0_oHR.d.mts} +6 -5
- package/dist/atom-DDF0_oHR.d.mts.map +1 -0
- package/dist/family.d.mts +24 -0
- package/dist/family.d.mts.map +1 -0
- package/dist/family.mjs +2 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +2 -0
- package/dist/react/{index.d.ts → index.d.mts} +23 -14
- package/dist/react/index.d.mts.map +1 -0
- package/dist/react/index.mjs +69 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/store-BnIMQg3L.mjs +387 -0
- package/dist/store-BnIMQg3L.mjs.map +1 -0
- package/dist/store-D4q7TShr.d.mts +78 -0
- package/dist/store-D4q7TShr.d.mts.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-QWP5ITSY.js +0 -464
- package/dist/chunk-QWP5ITSY.js.map +0 -1
- package/dist/family.d.ts +0 -23
- package/dist/family.js +0 -11
- package/dist/family.js.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/react/index.js +0 -87
- package/dist/react/index.js.map +0 -1
- package/dist/store-CAz6uZcN.d.ts +0 -75
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/react/index.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CONFIG
|
|
3
|
-
} from "../chunk-QWP5ITSY.js";
|
|
4
|
-
|
|
5
|
-
// src/react/provider.tsx
|
|
6
|
-
import { createContext, useContext } from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
var StoreContext = createContext(null);
|
|
9
|
-
function Provider({ store, children }) {
|
|
10
|
-
return /* @__PURE__ */ jsx(StoreContext, { value: store, children });
|
|
11
|
-
}
|
|
12
|
-
function useStore() {
|
|
13
|
-
const store = useContext(StoreContext);
|
|
14
|
-
if (store == null) {
|
|
15
|
-
throw new Error("useStore must be used within a <Provider>");
|
|
16
|
-
}
|
|
17
|
-
return store;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// src/react/use-atom-value.ts
|
|
21
|
-
import { useSyncExternalStore } from "react";
|
|
22
|
-
function useAtomValue(atom, opts) {
|
|
23
|
-
const store = useStore();
|
|
24
|
-
const snapshot = useSyncExternalStore(
|
|
25
|
-
(notify) => store.subscribe(atom, notify),
|
|
26
|
-
() => store.getSnapshot(atom),
|
|
27
|
-
() => store.getServerSnapshot(atom)
|
|
28
|
-
);
|
|
29
|
-
const stalePolicy = atom[CONFIG].stalePolicy ?? "keep";
|
|
30
|
-
if (snapshot.status === "pending") {
|
|
31
|
-
throw store.resolve(atom);
|
|
32
|
-
}
|
|
33
|
-
if (snapshot.status === "stale") {
|
|
34
|
-
if (stalePolicy === "suspend") {
|
|
35
|
-
throw store.resolve(atom);
|
|
36
|
-
}
|
|
37
|
-
void store.resolve(atom);
|
|
38
|
-
if (opts?.observe === true) {
|
|
39
|
-
return { value: snapshot.value, isStale: true, error: void 0 };
|
|
40
|
-
}
|
|
41
|
-
return snapshot.value;
|
|
42
|
-
}
|
|
43
|
-
if (snapshot.status === "error") {
|
|
44
|
-
if (opts?.observe === true && snapshot.value !== void 0) {
|
|
45
|
-
return {
|
|
46
|
-
value: snapshot.value,
|
|
47
|
-
isStale: false,
|
|
48
|
-
error: snapshot.error
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
throw snapshot.error;
|
|
52
|
-
}
|
|
53
|
-
if (opts?.observe === true) {
|
|
54
|
-
return { value: snapshot.value, isStale: false, error: void 0 };
|
|
55
|
-
}
|
|
56
|
-
return snapshot.value;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/react/use-set-atom.ts
|
|
60
|
-
import { useCallback } from "react";
|
|
61
|
-
function useSetAtom(atom) {
|
|
62
|
-
const store = useStore();
|
|
63
|
-
return useCallback((...args) => store.set(atom, ...args), [store, atom]);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/react/use-atom.ts
|
|
67
|
-
function useAtom(atom) {
|
|
68
|
-
const value = useAtomValue(atom);
|
|
69
|
-
const setter = useSetAtom(atom);
|
|
70
|
-
return [value, setter];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/react/use-atom-callback.ts
|
|
74
|
-
import { useCallback as useCallback2 } from "react";
|
|
75
|
-
function useAtomCallback(callback) {
|
|
76
|
-
const store = useStore();
|
|
77
|
-
return useCallback2(() => callback(store.getClient()), [store, callback]);
|
|
78
|
-
}
|
|
79
|
-
export {
|
|
80
|
-
Provider,
|
|
81
|
-
useAtom,
|
|
82
|
-
useAtomCallback,
|
|
83
|
-
useAtomValue,
|
|
84
|
-
useSetAtom,
|
|
85
|
-
useStore
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/provider.tsx","../../src/react/use-atom-value.ts","../../src/react/use-set-atom.ts","../../src/react/use-atom.ts","../../src/react/use-atom-callback.ts"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport { Store } from \"../internal/store.js\";\n\nconst StoreContext = createContext<Store | null>(null);\n\nexport type ProviderProps = {\n store: Store;\n children: ReactNode;\n};\n\nexport function Provider({ store, children }: ProviderProps): ReactNode {\n return <StoreContext value={store}>{children}</StoreContext>;\n}\n\nexport function useStore(): Store {\n const store = useContext(StoreContext);\n if (store == null) {\n throw new Error(\"useStore must be used within a <Provider>\");\n }\n return store;\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { Atom, AtomState, StalePolicy } from \"../internal/types.js\";\nimport { CONFIG } from \"../internal/types.js\";\nimport { useStore } from \"./provider.js\";\n\ntype ObservedValue<V> = {\n value: V;\n isStale: boolean;\n error: unknown;\n};\n\nexport function useAtomValue<V>(atom: Atom<V>): V;\nexport function useAtomValue<V>(atom: Atom<V>, opts: { observe: true }): ObservedValue<V>;\nexport function useAtomValue<V>(atom: Atom<V>, opts?: { observe: true }): V | ObservedValue<V> {\n const store = useStore();\n\n const snapshot: AtomState<V> = useSyncExternalStore(\n (notify) => store.subscribe(atom, notify),\n () => store.getSnapshot(atom),\n () => store.getServerSnapshot(atom),\n );\n\n const stalePolicy: StalePolicy = atom[CONFIG].stalePolicy ?? \"keep\";\n\n if (snapshot.status === \"pending\") {\n throw store.resolve(atom);\n }\n\n if (snapshot.status === \"stale\") {\n if (stalePolicy === \"suspend\") {\n throw store.resolve(atom);\n }\n // \"keep\" or \"reset\" while stale: trigger background revalidation\n void store.resolve(atom);\n\n if (opts?.observe === true) {\n return { value: snapshot.value, isStale: true, error: undefined };\n }\n return snapshot.value;\n }\n\n if (snapshot.status === \"error\") {\n if (opts?.observe === true && snapshot.value !== undefined) {\n return {\n value: snapshot.value as V,\n isStale: false,\n error: snapshot.error,\n };\n }\n throw snapshot.error;\n }\n\n // status === \"fresh\"\n if (opts?.observe === true) {\n return { value: snapshot.value, isStale: false, error: undefined };\n }\n return snapshot.value;\n}\n","import { useCallback } from \"react\";\nimport type { WritableAtom } from \"../internal/types.js\";\nimport { useStore } from \"./provider.js\";\n\nexport function useSetAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): (...args: A) => Promise<void> {\n const store = useStore();\n return useCallback((...args: A): Promise<void> => store.set(atom, ...args), [store, atom]);\n}\n","import type { WritableAtom } from \"../internal/types.js\";\nimport { useAtomValue } from \"./use-atom-value.js\";\nimport { useSetAtom } from \"./use-set-atom.js\";\n\nexport function useAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): readonly [V, (...args: A) => Promise<void>] {\n const value = useAtomValue(atom);\n const setter = useSetAtom(atom);\n return [value, setter] as const;\n}\n","import { useCallback } from \"react\";\nimport type { StoreClient } from \"../internal/store.js\";\nimport { useStore } from \"./provider.js\";\n\nexport function useAtomCallback<R>(callback: (ctx: StoreClient) => Promise<R>): () => Promise<R> {\n const store = useStore();\n return useCallback((): Promise<R> => callback(store.getClient()), [store, callback]);\n}\n"],"mappings":";;;;;AAAA,SAAS,eAAe,kBAAkC;AAWjD;AART,IAAM,eAAe,cAA4B,IAAI;AAO9C,SAAS,SAAS,EAAE,OAAO,SAAS,GAA6B;AACtE,SAAO,oBAAC,gBAAa,OAAO,OAAQ,UAAS;AAC/C;AAEO,SAAS,WAAkB;AAChC,QAAM,QAAQ,WAAW,YAAY;AACrC,MAAI,SAAS,MAAM;AACjB,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACA,SAAO;AACT;;;ACpBA,SAAS,4BAA4B;AAa9B,SAAS,aAAgB,MAAe,MAAgD;AAC7F,QAAM,QAAQ,SAAS;AAEvB,QAAM,WAAyB;AAAA,IAC7B,CAAC,WAAW,MAAM,UAAU,MAAM,MAAM;AAAA,IACxC,MAAM,MAAM,YAAY,IAAI;AAAA,IAC5B,MAAM,MAAM,kBAAkB,IAAI;AAAA,EACpC;AAEA,QAAM,cAA2B,KAAK,MAAM,EAAE,eAAe;AAE7D,MAAI,SAAS,WAAW,WAAW;AACjC,UAAM,MAAM,QAAQ,IAAI;AAAA,EAC1B;AAEA,MAAI,SAAS,WAAW,SAAS;AAC/B,QAAI,gBAAgB,WAAW;AAC7B,YAAM,MAAM,QAAQ,IAAI;AAAA,IAC1B;AAEA,SAAK,MAAM,QAAQ,IAAI;AAEvB,QAAI,MAAM,YAAY,MAAM;AAC1B,aAAO,EAAE,OAAO,SAAS,OAAO,SAAS,MAAM,OAAO,OAAU;AAAA,IAClE;AACA,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,SAAS,WAAW,SAAS;AAC/B,QAAI,MAAM,YAAY,QAAQ,SAAS,UAAU,QAAW;AAC1D,aAAO;AAAA,QACL,OAAO,SAAS;AAAA,QAChB,SAAS;AAAA,QACT,OAAO,SAAS;AAAA,MAClB;AAAA,IACF;AACA,UAAM,SAAS;AAAA,EACjB;AAGA,MAAI,MAAM,YAAY,MAAM;AAC1B,WAAO,EAAE,OAAO,SAAS,OAAO,SAAS,OAAO,OAAO,OAAU;AAAA,EACnE;AACA,SAAO,SAAS;AAClB;;;ACzDA,SAAS,mBAAmB;AAIrB,SAAS,WACd,MAC+B;AAC/B,QAAM,QAAQ,SAAS;AACvB,SAAO,YAAY,IAAI,SAA2B,MAAM,IAAI,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC;AAC3F;;;ACLO,SAAS,QACd,MAC6C;AAC7C,QAAM,QAAQ,aAAa,IAAI;AAC/B,QAAM,SAAS,WAAW,IAAI;AAC9B,SAAO,CAAC,OAAO,MAAM;AACvB;;;ACVA,SAAS,eAAAA,oBAAmB;AAIrB,SAAS,gBAAmB,UAA8D;AAC/F,QAAM,QAAQ,SAAS;AACvB,SAAOC,aAAY,MAAkB,SAAS,MAAM,UAAU,CAAC,GAAG,CAAC,OAAO,QAAQ,CAAC;AACrF;","names":["useCallback","useCallback"]}
|
package/dist/store-CAz6uZcN.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
declare const CONFIG: unique symbol;
|
|
2
|
-
declare const WRITABLE: unique symbol;
|
|
3
|
-
type AtomState<Value> = {
|
|
4
|
-
status: "pending";
|
|
5
|
-
value: undefined;
|
|
6
|
-
error: undefined;
|
|
7
|
-
} | {
|
|
8
|
-
status: "stale";
|
|
9
|
-
value: Value;
|
|
10
|
-
error: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
status: "fresh";
|
|
13
|
-
value: Value;
|
|
14
|
-
error: undefined;
|
|
15
|
-
} | {
|
|
16
|
-
status: "error";
|
|
17
|
-
value: Value | undefined;
|
|
18
|
-
error: unknown;
|
|
19
|
-
};
|
|
20
|
-
type StalePolicy = "keep" | "suspend" | "reset";
|
|
21
|
-
type AtomContext<Deps extends Record<string, Atom<unknown>>> = {
|
|
22
|
-
get: <K extends keyof Deps>(key: K) => Promise<AtomValue<Deps[K]>>;
|
|
23
|
-
signal: AbortSignal;
|
|
24
|
-
};
|
|
25
|
-
type WritableAtomContext<Deps extends Record<string, Atom<unknown>>, Value> = AtomContext<Deps> & {
|
|
26
|
-
setOptimisticValue: (value: Value) => void;
|
|
27
|
-
};
|
|
28
|
-
type AtomConfig<Value, Deps extends Record<string, Atom<unknown>>, Args extends readonly unknown[]> = {
|
|
29
|
-
dependencies?: Deps;
|
|
30
|
-
stalePolicy?: StalePolicy;
|
|
31
|
-
debugLabel?: string;
|
|
32
|
-
get: (ctx: AtomContext<Deps>) => Promise<Value>;
|
|
33
|
-
set?: (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;
|
|
34
|
-
onMount?: (set: (value: Value) => void) => (() => void) | void;
|
|
35
|
-
};
|
|
36
|
-
interface InternalAtomConfig<Value> {
|
|
37
|
-
dependencies?: Record<string, Atom<unknown>>;
|
|
38
|
-
stalePolicy?: StalePolicy;
|
|
39
|
-
debugLabel?: string;
|
|
40
|
-
get: (ctx: AtomContext<Record<string, Atom<unknown>>>) => Promise<Value>;
|
|
41
|
-
set?: (ctx: WritableAtomContext<Record<string, Atom<unknown>>, Value>, ...args: readonly unknown[]) => Promise<void>;
|
|
42
|
-
onMount?: (set: (value: unknown) => void) => (() => void) | void;
|
|
43
|
-
}
|
|
44
|
-
interface Atom<out Value> {
|
|
45
|
-
readonly [CONFIG]: InternalAtomConfig<Value>;
|
|
46
|
-
readonly debugLabel: string | undefined;
|
|
47
|
-
}
|
|
48
|
-
interface WritableAtom<out Value, in out Args extends readonly unknown[]> extends Atom<Value> {
|
|
49
|
-
readonly [WRITABLE]: Args;
|
|
50
|
-
}
|
|
51
|
-
type AtomValue<A> = A extends Atom<infer V> ? V : never;
|
|
52
|
-
type IsWritable<A> = A extends WritableAtom<unknown, readonly unknown[]> ? true : false;
|
|
53
|
-
type AtomArgs<A> = A extends WritableAtom<unknown, infer Args> ? Args : never;
|
|
54
|
-
|
|
55
|
-
interface StoreClient {
|
|
56
|
-
get<V>(atom: Atom<V>): Promise<V>;
|
|
57
|
-
set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void>;
|
|
58
|
-
invalidate(atom: Atom<unknown>): void;
|
|
59
|
-
invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void;
|
|
60
|
-
subscribe<V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): () => void;
|
|
61
|
-
}
|
|
62
|
-
declare class Store {
|
|
63
|
-
#private;
|
|
64
|
-
resolve<V>(atom: Atom<V>): Promise<V>;
|
|
65
|
-
invalidate(atom: Atom<unknown>): void;
|
|
66
|
-
invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void;
|
|
67
|
-
subscribe<V>(atom: Atom<V>, listener: () => void): () => void;
|
|
68
|
-
getSnapshot<V>(atom: Atom<V>): AtomState<V>;
|
|
69
|
-
getServerSnapshot<V>(atom: Atom<V>): AtomState<V>;
|
|
70
|
-
set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void>;
|
|
71
|
-
getClient(): StoreClient;
|
|
72
|
-
}
|
|
73
|
-
declare function createStore(): Store;
|
|
74
|
-
|
|
75
|
-
export { type Atom as A, type IsWritable as I, type StalePolicy as S, type WritableAtom as W, type AtomContext as a, type AtomConfig as b, type AtomState as c, type AtomValue as d, createStore as e, Store as f, type StoreClient as g, type WritableAtomContext as h, type AtomArgs as i };
|