@kdeveloper/kvark 0.5.3 → 0.6.0

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.
@@ -0,0 +1,42 @@
1
+ import { f as WritableAtom, i as Atom, n as StoreClient, t as Store } from "../store-DQL8VJhU.mjs";
2
+ import * as _$vue from "vue";
3
+ import { PropType, ShallowRef } from "vue";
4
+
5
+ //#region src/vue/provider.d.ts
6
+ declare const Provider: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
7
+ store: {
8
+ type: PropType<Store>;
9
+ required: true;
10
+ };
11
+ }>, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
12
+ [key: string]: any;
13
+ }>[] | undefined, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
14
+ store: {
15
+ type: PropType<Store>;
16
+ required: true;
17
+ };
18
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
19
+ declare function useStore(): Store;
20
+ //#endregion
21
+ //#region src/vue/use-atom-value.d.ts
22
+ type ObservedValue<V> = {
23
+ value: V;
24
+ isStale: boolean;
25
+ error: unknown;
26
+ };
27
+ declare function useAtomValue<V>(atom: Atom<V>): Readonly<ShallowRef<V>>;
28
+ declare function useAtomValue<V>(atom: Atom<V>, opts: {
29
+ observe: true;
30
+ }): Readonly<ShallowRef<ObservedValue<V>>>;
31
+ //#endregion
32
+ //#region src/vue/use-set-atom.d.ts
33
+ declare function useSetAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): (...args: A) => Promise<void>;
34
+ //#endregion
35
+ //#region src/vue/use-atom.d.ts
36
+ declare function useAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): readonly [Readonly<ShallowRef<V>>, (...args: A) => Promise<void>];
37
+ //#endregion
38
+ //#region src/vue/use-atom-context.d.ts
39
+ declare function useAtomContext<R>(callback: (ctx: StoreClient) => Promise<R>): () => Promise<R>;
40
+ //#endregion
41
+ export { Provider, useAtom, useAtomContext, useAtomValue, useSetAtom, useStore };
42
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/vue/provider.ts","../../src/vue/use-atom-value.ts","../../src/vue/use-set-atom.ts","../../src/vue/use-atom.ts","../../src/vue/use-atom-context.ts"],"mappings":";;;;;cAWa,QAAA,QAAQ,eAAA,CAGgB,KAAA,CAHhB,gBAAA;;UAGQ,QAAA,CAAS,KAAA;;;sBAHjB,KAAA,CAAA,YAAA;;gIAGgB,KAAA,CAAA,gBAAA;;UAAR,QAAA,CAAS,KAAA;;;;iBAQtB,QAAA,CAAA,GAAY,KAAA;;;KClBvB,aAAA;EACH,KAAA,EAAO,CAAA;EACP,OAAA;EACA,KAAA;AAAA;AAAA,iBAGc,YAAA,GAAA,CAAgB,IAAA,EAAM,IAAA,CAAK,CAAA,IAAK,QAAA,CAAS,UAAA,CAAW,CAAA;AAAA,iBACpD,YAAA,GAAA,CACd,IAAA,EAAM,IAAA,CAAK,CAAA,GACX,IAAA;EAAQ,OAAA;AAAA,IACP,QAAA,CAAS,UAAA,CAAW,aAAA,CAAc,CAAA;;;iBCXrB,UAAA,iCAAA,CACd,IAAA,EAAM,YAAA,CAAa,CAAA,EAAG,CAAA,QACjB,IAAA,EAAM,CAAA,KAAM,OAAA;;;iBCAH,OAAA,iCAAA,CACd,IAAA,EAAM,YAAA,CAAa,CAAA,EAAG,CAAA,cACX,QAAA,CAAS,UAAA,CAAW,CAAA,QAAS,IAAA,EAAM,CAAA,KAAM,OAAA;;;iBCJtC,cAAA,GAAA,CAAkB,QAAA,GAAW,GAAA,EAAK,WAAA,KAAgB,OAAA,CAAQ,CAAA,UAAW,OAAA,CAAQ,CAAA"}
@@ -0,0 +1,86 @@
1
+ import { defineComponent, inject, provide, readonly, shallowRef, watchEffect } from "vue";
2
+ //#region src/vue/provider.ts
3
+ const StoreKey = Symbol("kvark-store");
4
+ const Provider = defineComponent({
5
+ name: "KvarkProvider",
6
+ props: { store: {
7
+ type: Object,
8
+ required: true
9
+ } },
10
+ setup(props, { slots }) {
11
+ provide(StoreKey, props.store);
12
+ return () => slots["default"]?.();
13
+ }
14
+ });
15
+ function useStore() {
16
+ const store = inject(StoreKey);
17
+ if (store == null) throw new Error("useStore must be used within a <Provider>");
18
+ return store;
19
+ }
20
+ //#endregion
21
+ //#region src/vue/use-atom-value.ts
22
+ function useAtomValue(atom, opts) {
23
+ const store = useStore();
24
+ function derive(snapshot) {
25
+ if (snapshot.status === "pending") {
26
+ store.resolve(atom);
27
+ if (opts?.observe === true) return {
28
+ value: void 0,
29
+ isStale: false,
30
+ error: void 0
31
+ };
32
+ return;
33
+ }
34
+ if (snapshot.status === "stale") {
35
+ store.resolve(atom);
36
+ if (opts?.observe === true) return {
37
+ value: snapshot.value,
38
+ isStale: true,
39
+ error: void 0
40
+ };
41
+ return snapshot.value;
42
+ }
43
+ if (snapshot.status === "error") {
44
+ if (opts?.observe === true && snapshot.value !== void 0) return {
45
+ value: snapshot.value,
46
+ isStale: false,
47
+ error: snapshot.error
48
+ };
49
+ throw snapshot.error;
50
+ }
51
+ if (opts?.observe === true) return {
52
+ value: snapshot.value,
53
+ isStale: false,
54
+ error: void 0
55
+ };
56
+ return snapshot.value;
57
+ }
58
+ const result = shallowRef(derive(store.getSnapshot(atom)));
59
+ watchEffect((onCleanup) => {
60
+ onCleanup(store.subscribe(atom, () => {
61
+ result.value = derive(store.getSnapshot(atom));
62
+ }));
63
+ });
64
+ return readonly(result);
65
+ }
66
+ //#endregion
67
+ //#region src/vue/use-set-atom.ts
68
+ function useSetAtom(atom) {
69
+ const store = useStore();
70
+ return (...args) => store.set(atom, ...args);
71
+ }
72
+ //#endregion
73
+ //#region src/vue/use-atom.ts
74
+ function useAtom(atom) {
75
+ return [useAtomValue(atom), useSetAtom(atom)];
76
+ }
77
+ //#endregion
78
+ //#region src/vue/use-atom-context.ts
79
+ function useAtomContext(callback) {
80
+ const store = useStore();
81
+ return () => callback(store.getClient());
82
+ }
83
+ //#endregion
84
+ export { Provider, useAtom, useAtomContext, useAtomValue, useSetAtom, useStore };
85
+
86
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/vue/provider.ts","../../src/vue/use-atom-value.ts","../../src/vue/use-set-atom.ts","../../src/vue/use-atom.ts","../../src/vue/use-atom-context.ts"],"sourcesContent":["import {\n type InjectionKey,\n type PropType,\n defineComponent,\n inject,\n provide,\n} from \"vue\";\nimport { Store } from \"@/internal/store.js\";\n\nconst StoreKey: InjectionKey<Store> = Symbol(\"kvark-store\");\n\nexport const Provider = defineComponent({\n name: \"KvarkProvider\",\n props: {\n store: { type: Object as PropType<Store>, required: true },\n },\n setup(props, { slots }) {\n provide(StoreKey, props.store);\n return () => slots[\"default\"]?.();\n },\n});\n\nexport function useStore(): Store {\n const store = inject(StoreKey);\n if (store == null) {\n throw new Error(\"useStore must be used within a <Provider>\");\n }\n return store;\n}\n","import { type ShallowRef, readonly, shallowRef, watchEffect } from \"vue\";\nimport type { Atom, AtomState } from \"@/internal/types.js\";\nimport { useStore } from \"@/vue/provider.js\";\n\ntype ObservedValue<V> = {\n value: V;\n isStale: boolean;\n error: unknown;\n};\n\nexport function useAtomValue<V>(atom: Atom<V>): Readonly<ShallowRef<V>>;\nexport function useAtomValue<V>(\n atom: Atom<V>,\n opts: { observe: true },\n): Readonly<ShallowRef<ObservedValue<V>>>;\nexport function useAtomValue<V>(\n atom: Atom<V>,\n opts?: { observe: true },\n): Readonly<ShallowRef<V | ObservedValue<V>>> {\n const store = useStore();\n\n function derive(snapshot: AtomState<V>): V | ObservedValue<V> {\n if (snapshot.status === \"pending\") {\n void store.resolve(atom);\n if (opts?.observe === true) {\n return { value: undefined as V, isStale: false, error: undefined };\n }\n return undefined as V;\n }\n\n if (snapshot.status === \"stale\") {\n void store.resolve(atom);\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 { value: snapshot.value as V, isStale: false, error: snapshot.error };\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\n const result = shallowRef(derive(store.getSnapshot(atom)));\n\n watchEffect((onCleanup) => {\n const unsub = store.subscribe(atom, () => {\n result.value = derive(store.getSnapshot(atom));\n });\n onCleanup(unsub);\n });\n\n return readonly(result) as Readonly<ShallowRef<V | ObservedValue<V>>>;\n}\n","import type { WritableAtom } from \"@/internal/types.js\";\nimport { useStore } from \"@/vue/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 (...args: A): Promise<void> => store.set(atom, ...args);\n}\n","import type { ShallowRef } from \"vue\";\nimport type { WritableAtom } from \"@/internal/types.js\";\nimport { useAtomValue } from \"@/vue/use-atom-value.js\";\nimport { useSetAtom } from \"@/vue/use-set-atom.js\";\n\nexport function useAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): readonly [Readonly<ShallowRef<V>>, (...args: A) => Promise<void>] {\n const value = useAtomValue(atom);\n const setter = useSetAtom(atom);\n return [value, setter] as const;\n}\n","import type { StoreClient } from \"@/internal/store.js\";\nimport { useStore } from \"@/vue/provider.js\";\n\nexport function useAtomContext<R>(callback: (ctx: StoreClient) => Promise<R>): () => Promise<R> {\n const store = useStore();\n return (): Promise<R> => callback(store.getClient());\n}\n"],"mappings":";;AASA,MAAM,WAAgC,OAAO,cAAc;AAE3D,MAAa,WAAW,gBAAgB;CACtC,MAAM;CACN,OAAO,EACL,OAAO;EAAE,MAAM;EAA2B,UAAU;EAAM,EAC3D;CACD,MAAM,OAA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,MACmE;AAGnE,QAAO,CAFO,aAAa,KAAK,EACjB,WAAW,KAAK,CACT;;;;ACPxB,SAAgB,eAAkB,UAA8D;CAC9F,MAAM,QAAQ,UAAU;AACxB,cAAyB,SAAS,MAAM,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdeveloper/kvark",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "Atomic state management with explicit dependency graphs",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -19,6 +19,10 @@
19
19
  "types": "./dist/react/index.d.mts",
20
20
  "import": "./dist/react/index.mjs"
21
21
  },
22
+ "./vue": {
23
+ "types": "./dist/vue/index.d.mts",
24
+ "import": "./dist/vue/index.mjs"
25
+ },
22
26
  "./family": {
23
27
  "types": "./dist/family.d.mts",
24
28
  "import": "./dist/family.mjs"
@@ -29,6 +33,7 @@
29
33
  "@testing-library/react": "^16.3.2",
30
34
  "@types/react": "^19.2.14",
31
35
  "@types/react-dom": "^19.2.3",
36
+ "@vue/test-utils": "^2.4.6",
32
37
  "jsdom": "^29.0.1",
33
38
  "oxfmt": "^0.42.0",
34
39
  "oxlint": "^1.57.0",
@@ -36,10 +41,20 @@
36
41
  "react-dom": "^19.2.4",
37
42
  "tsdown": "^0.21.6",
38
43
  "typescript": "^6.0.2",
39
- "vitest": "^4.1.2"
44
+ "vitest": "^4.1.2",
45
+ "vue": "^3.5.31"
40
46
  },
41
47
  "peerDependencies": {
42
- "react": ">=18"
48
+ "react": ">=18",
49
+ "vue": ">=3.4"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "react": {
53
+ "optional": true
54
+ },
55
+ "vue": {
56
+ "optional": true
57
+ }
43
58
  },
44
59
  "engines": {
45
60
  "node": ">=20"