@molecule/app-query-vue 0.0.0-stage → 1.1.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,64 @@
1
+ /**
2
+ * Vue query observer contracts.
3
+ *
4
+ * The Vue counterpart of `@molecule/app-query-react`'s types: the same names
5
+ * and the same plain state fields, with node-valued props typed as Vue's
6
+ * `VNodeChild`. {@link useQuery} returns the result wrapped in a `Ref`, so
7
+ * templates auto-unwrap it and reactive updates re-render.
8
+ *
9
+ * @module
10
+ */
11
+ import type { MaybeRefOrGetter, VNodeChild } from 'vue';
12
+ import type { QueryOptions, QueryState } from '@molecule/app-query';
13
+ /**
14
+ * A mounted query's state and its explicit cache and refresh actions.
15
+ */
16
+ export interface UseQueryResult<T> extends QueryState<T> {
17
+ /**
18
+ * Publish a saved document to this key and all its observers. Render `data`
19
+ * directly instead of copying it to a local ref: later cache updates then
20
+ * remain visible. A function receives this key's current cached document,
21
+ * never retained previous-page data. Returning `undefined` leaves the cache
22
+ * unchanged. A disabled (`null`) query does nothing, including not calling an
23
+ * updater. Like Vue's reactive writes, an updater runs against the cache as
24
+ * it is when the call lands. A saved callback stays bound to its original
25
+ * key. The write supersedes older in-flight reads, using the bonded client's
26
+ * `set` contract.
27
+ */
28
+ setData: (value: T | ((previous: T | undefined) => T | undefined)) => void;
29
+ /**
30
+ * Fetch this key again, even when its cached document is fresh. Observers
31
+ * receive the updated state. Resolves with that state, including an error
32
+ * when the request fails; a disabled (`null`) query resolves idle without a
33
+ * request.
34
+ */
35
+ refetch: () => Promise<QueryState<T>>;
36
+ }
37
+ /**
38
+ * A loaded document owns its controls; absent documents expose only status
39
+ * content.
40
+ */
41
+ export interface QueryContentProps<T> {
42
+ /** State from useQuery, or any compatible query observer. */
43
+ query: Pick<QueryState<T>, 'data' | 'status' | 'error'>;
44
+ /**
45
+ * Mounted only with a real document, including false, zero and an empty
46
+ * list. A render function (React's render-prop name) or the default slot,
47
+ * which receives the document as its scoped-slot prop `{ data }`.
48
+ */
49
+ children: (data: NonNullable<T>) => VNodeChild;
50
+ /** Initial idle/loading content. Render a status node, never a fake item or action. */
51
+ pending?: VNodeChild;
52
+ /** Content for a loaded null record. Null is distinct from an unfinished request. */
53
+ missing?: VNodeChild;
54
+ /** A failed initial read. Cached data stays visible if its refresh fails. */
55
+ error?: (error: unknown) => VNodeChild;
56
+ }
57
+ /**
58
+ * What {@link useQuery} observes: the same options object React's hook takes,
59
+ * or a ref/getter of one. Passing a ref or getter lets one mounted composable
60
+ * follow a changed key on the SAME instance — the Vue counterpart of React
61
+ * re-rendering `useQuery` with a new options object.
62
+ */
63
+ export type QueryOptionsInput<T> = MaybeRefOrGetter<QueryOptions<T> | null>;
64
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEnE;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD;;;;;;;;;;OAUG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,IAAI,CAAA;IAC1E;;;;;OAKG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,6DAA6D;IAC7D,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,CAAA;IACvD;;;;OAIG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,UAAU,CAAA;IAC9C,uFAAuF;IACvF,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,qFAAqF;IACrF,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,UAAU,CAAA;CACvC;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Warm the cache ahead of a navigation. `prefetchQuery` itself is
3
+ * framework-neutral and lives in `@molecule/app-query`; this module re-exports
4
+ * it and adds the Vue composable and link handlers.
5
+ *
6
+ * @module
7
+ */
8
+ import type { QueryOptions } from '@molecule/app-query';
9
+ export { prefetchQuery } from '@molecule/app-query';
10
+ /**
11
+ * A stable `prefetch(options)` function for event handlers.
12
+ *
13
+ * @returns The prefetch function, one per mounted composable.
14
+ */
15
+ export declare function usePrefetch(): <T>(options: QueryOptions<T>) => void;
16
+ /**
17
+ * The handlers {@link intentPrefetchProps} returns. The names are Vue's
18
+ * listener spellings of pointer enter, focus and touch start, so they spread
19
+ * onto an element rendered with `h()` (or a component that forwards attrs) and
20
+ * attach as real DOM listeners.
21
+ */
22
+ export interface IntentPrefetchProps {
23
+ onPointerenter: () => void;
24
+ onFocus: () => void;
25
+ onTouchstart: () => void;
26
+ }
27
+ /**
28
+ * Event handlers that warm a document at the first sign of intent: the
29
+ * pointer arriving, keyboard focus, or a touch starting. Spread them onto a
30
+ * link: `h('a', { href, ...intentPrefetchProps(packageQuery(name)) }, name)`.
31
+ *
32
+ * @param options - Key, fetch, freshness.
33
+ * @returns The handlers.
34
+ */
35
+ export declare function intentPrefetchProps<T>(options: QueryOptions<T>): IntentPrefetchProps;
36
+ //# sourceMappingURL=usePrefetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrefetch.d.ts","sourceRoot":"","sources":["../src/usePrefetch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAInE;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAGpF"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Warm the cache ahead of a navigation. `prefetchQuery` itself is
3
+ * framework-neutral and lives in `@molecule/app-query`; this module re-exports
4
+ * it and adds the Vue composable and link handlers.
5
+ *
6
+ * @module
7
+ */
8
+ import { prefetchQuery } from '@molecule/app-query';
9
+ export { prefetchQuery } from '@molecule/app-query';
10
+ /**
11
+ * A stable `prefetch(options)` function for event handlers.
12
+ *
13
+ * @returns The prefetch function, one per mounted composable.
14
+ */
15
+ export function usePrefetch() {
16
+ return (options) => {
17
+ prefetchQuery(options);
18
+ };
19
+ }
20
+ /**
21
+ * Event handlers that warm a document at the first sign of intent: the
22
+ * pointer arriving, keyboard focus, or a touch starting. Spread them onto a
23
+ * link: `h('a', { href, ...intentPrefetchProps(packageQuery(name)) }, name)`.
24
+ *
25
+ * @param options - Key, fetch, freshness.
26
+ * @returns The handlers.
27
+ */
28
+ export function intentPrefetchProps(options) {
29
+ const go = () => prefetchQuery(options);
30
+ return { onPointerenter: go, onFocus: go, onTouchstart: go };
31
+ }
32
+ //# sourceMappingURL=usePrefetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrefetch.js","sourceRoot":"","sources":["../src/usePrefetch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD;;;;GAIG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,CAAI,OAAwB,EAAQ,EAAE;QAC3C,aAAa,CAAC,OAAO,CAAC,CAAA;IACxB,CAAC,CAAA;AACH,CAAC;AAcD;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAI,OAAwB;IAC7D,MAAM,EAAE,GAAG,GAAS,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC7C,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAA;AAC9D,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Observe one document from the shared cache.
3
+ * @module
4
+ */
5
+ import { type Ref } from 'vue';
6
+ import type { QueryOptionsInput, UseQueryResult } from './types.js';
7
+ /**
8
+ * The document for `options.key`, kept current: cached data is returned on the
9
+ * very first read (so a warmed page never flashes a loading state), a stale or
10
+ * missing document is fetched, and every change updates the returned ref.
11
+ * Pass `null` to observe nothing. A key change resets to that key's state; the
12
+ * hook never hands a caller another key's document — unless the caller opts
13
+ * into {@link QueryOptions.keepPreviousData}, and then only within one
14
+ * {@link QueryOptions.principal}.
15
+ *
16
+ * Pass the options as a `ref` or getter to follow a changed key on the SAME
17
+ * instance — a computed of the route, the viewer or the page. That is the Vue
18
+ * counterpart of React re-rendering `useQuery` with a new options object: the
19
+ * request stays stable while the key holds, a parent state change neither
20
+ * restarts it nor cancels it, so a response that arrives after one still
21
+ * lands. It is aborted only when the key changes or the component unmounts
22
+ * (the `signal` given to `options.fetch`). Use this instead of a hand-written
23
+ * `watch` + `fetch`: a watcher whose cleanup sets a `cancelled` flag, and
24
+ * whose source includes a function rebuilt each run, cancels its own request
25
+ * on every re-run and then skips the refetch.
26
+ * An explicit `refetch()` is an awaited cache fetch; it can finish after the
27
+ * observer unmounts, like an explicit `client.fetch(options)` caller.
28
+ *
29
+ * For a LIST, put the route's page, filter and selected view in the key and
30
+ * pass `keepPreviousData` with a `principal`: a Next/Previous or filter change
31
+ * then keeps the rows already on screen until the new page answers, instead of
32
+ * rendering a loading state over an empty list. The key names everything the
33
+ * answer depends on, and the app's HTTP client sends the session, so a list
34
+ * the server can filter or personalize per viewer puts the viewer in its key
35
+ * and passes the same value as `principal` (`'anonymous'` when signed out): an
36
+ * account switch then drops the previous account's document immediately. Only
37
+ * an endpoint that answers every viewer the same takes a viewer-free key with
38
+ * `principal: 'public'`.
39
+ *
40
+ * For custom mutation handlers, `setData(saved)` publishes the server's
41
+ * response to this key and every observer. Use `setData(current => next)` for
42
+ * a local cache update. Render `data` directly; a component-local copy stops
43
+ * observing later server responses. Prefer `createQueryResource` when the
44
+ * API's reads and writes can share one resource definition. Mount
45
+ * record-dependent actions inside `QueryContent` (or an explicit non-null data
46
+ * branch), so a visible action cannot return early because its initial record
47
+ * is still missing. Keep loaded actions mounted during refreshes.
48
+ * Server-backed toggles use `useOptimisticValue` from `@molecule/app-vue` to
49
+ * keep their displayed label and queued clicks on the same state while a save
50
+ * finishes.
51
+ *
52
+ * @param options - Key, fetch, freshness, and optionally `principal` with
53
+ * `keepPreviousData`; or `null`. A ref or getter of either, so one mounted
54
+ * composable can follow a changed key.
55
+ * @returns A ref of the document's state with `setData()` and `refetch()`.
56
+ * `isPreviousData` is `true` while `data` is the previous key's document for
57
+ * the same principal.
58
+ * @throws {Error} When `keepPreviousData` is set without `principal` — the
59
+ * hook cannot tell a route change from a principal switch, so it refuses
60
+ * rather than risk showing one principal's document to another.
61
+ */
62
+ export declare function useQuery<T>(queryOptions: QueryOptionsInput<T>): Ref<UseQueryResult<T>>;
63
+ //# sourceMappingURL=useQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIL,KAAK,GAAG,EAIT,MAAM,KAAK,CAAA;AAKZ,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AA8BnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CA4JtF"}
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Observe one document from the shared cache.
3
+ * @module
4
+ */
5
+ import { computed, getCurrentScope, onScopeDispose, shallowRef, toValue, watch, } from 'vue';
6
+ import { getQueryClient, hashQueryKey } from '@molecule/app-query';
7
+ const IDLE = {
8
+ data: undefined,
9
+ status: 'idle',
10
+ error: undefined,
11
+ isFetching: false,
12
+ updatedAt: undefined,
13
+ };
14
+ /**
15
+ * The document for `options.key`, kept current: cached data is returned on the
16
+ * very first read (so a warmed page never flashes a loading state), a stale or
17
+ * missing document is fetched, and every change updates the returned ref.
18
+ * Pass `null` to observe nothing. A key change resets to that key's state; the
19
+ * hook never hands a caller another key's document — unless the caller opts
20
+ * into {@link QueryOptions.keepPreviousData}, and then only within one
21
+ * {@link QueryOptions.principal}.
22
+ *
23
+ * Pass the options as a `ref` or getter to follow a changed key on the SAME
24
+ * instance — a computed of the route, the viewer or the page. That is the Vue
25
+ * counterpart of React re-rendering `useQuery` with a new options object: the
26
+ * request stays stable while the key holds, a parent state change neither
27
+ * restarts it nor cancels it, so a response that arrives after one still
28
+ * lands. It is aborted only when the key changes or the component unmounts
29
+ * (the `signal` given to `options.fetch`). Use this instead of a hand-written
30
+ * `watch` + `fetch`: a watcher whose cleanup sets a `cancelled` flag, and
31
+ * whose source includes a function rebuilt each run, cancels its own request
32
+ * on every re-run and then skips the refetch.
33
+ * An explicit `refetch()` is an awaited cache fetch; it can finish after the
34
+ * observer unmounts, like an explicit `client.fetch(options)` caller.
35
+ *
36
+ * For a LIST, put the route's page, filter and selected view in the key and
37
+ * pass `keepPreviousData` with a `principal`: a Next/Previous or filter change
38
+ * then keeps the rows already on screen until the new page answers, instead of
39
+ * rendering a loading state over an empty list. The key names everything the
40
+ * answer depends on, and the app's HTTP client sends the session, so a list
41
+ * the server can filter or personalize per viewer puts the viewer in its key
42
+ * and passes the same value as `principal` (`'anonymous'` when signed out): an
43
+ * account switch then drops the previous account's document immediately. Only
44
+ * an endpoint that answers every viewer the same takes a viewer-free key with
45
+ * `principal: 'public'`.
46
+ *
47
+ * For custom mutation handlers, `setData(saved)` publishes the server's
48
+ * response to this key and every observer. Use `setData(current => next)` for
49
+ * a local cache update. Render `data` directly; a component-local copy stops
50
+ * observing later server responses. Prefer `createQueryResource` when the
51
+ * API's reads and writes can share one resource definition. Mount
52
+ * record-dependent actions inside `QueryContent` (or an explicit non-null data
53
+ * branch), so a visible action cannot return early because its initial record
54
+ * is still missing. Keep loaded actions mounted during refreshes.
55
+ * Server-backed toggles use `useOptimisticValue` from `@molecule/app-vue` to
56
+ * keep their displayed label and queued clicks on the same state while a save
57
+ * finishes.
58
+ *
59
+ * @param options - Key, fetch, freshness, and optionally `principal` with
60
+ * `keepPreviousData`; or `null`. A ref or getter of either, so one mounted
61
+ * composable can follow a changed key.
62
+ * @returns A ref of the document's state with `setData()` and `refetch()`.
63
+ * `isPreviousData` is `true` while `data` is the previous key's document for
64
+ * the same principal.
65
+ * @throws {Error} When `keepPreviousData` is set without `principal` — the
66
+ * hook cannot tell a route change from a principal switch, so it refuses
67
+ * rather than risk showing one principal's document to another.
68
+ */
69
+ export function useQuery(queryOptions) {
70
+ // Options are validated on every read, the way React's hook refuses on every
71
+ // render; this first read happens before anything subscribes or fetches.
72
+ const optionsRef = computed(() => {
73
+ const options = toValue(queryOptions);
74
+ if (options?.keepPreviousData === true && options.principal === undefined) {
75
+ throw new Error('useQuery: keepPreviousData requires principal — the viewer the document is for (the signed-in id, "anonymous" while signed out, or "public" for an endpoint that answers every viewer the same) so a viewer switch never shows the previous document.');
76
+ }
77
+ return options;
78
+ });
79
+ const initial = optionsRef.value;
80
+ const initialHash = initial ? hashQueryKey(initial.key) : '';
81
+ // The subscription's last delivered state, and the hash it belongs to.
82
+ const state = shallowRef({
83
+ hash: initialHash,
84
+ value: initial ? getQueryClient().getState(initial.key) : IDLE,
85
+ });
86
+ // The previous document is remembered ACROSS reactive updates, so the update
87
+ // that first observes a new key still has the rows a person is looking at.
88
+ const loaded = shallowRef(null);
89
+ // A key's document belongs to the principal that was current when the hook
90
+ // started observing that key: a principal change the key does not reflect
91
+ // never relabels the document on screen as the new principal's.
92
+ const observed = shallowRef(null);
93
+ const hash = computed(() => {
94
+ const options = optionsRef.value;
95
+ return options ? hashQueryKey(options.key) : '';
96
+ });
97
+ const principal = computed(() => optionsRef.value?.principal);
98
+ const value = computed(() => {
99
+ const currentHash = hash.value;
100
+ const options = optionsRef.value;
101
+ const current = state.value.hash === currentHash
102
+ ? state.value.value
103
+ : options
104
+ ? getQueryClient().getState(options.key)
105
+ : IDLE;
106
+ const previous = options?.keepPreviousData === true ? loaded.value : null;
107
+ if (previous !== null &&
108
+ previous.principal === options?.principal &&
109
+ previous.hash !== currentHash &&
110
+ current.data === undefined &&
111
+ (current.status === 'idle' || current.status === 'loading')) {
112
+ return {
113
+ ...current,
114
+ data: previous.value.data,
115
+ updatedAt: previous.value.updatedAt,
116
+ isPreviousData: true,
117
+ };
118
+ }
119
+ return current;
120
+ });
121
+ /** Binds the actions to one observed key; the old actions keep that key when it changes. */
122
+ const bindActions = (options, boundHash) => {
123
+ const setData = (input) => {
124
+ if (!options)
125
+ return;
126
+ const client = getQueryClient();
127
+ const next = typeof input === 'function'
128
+ ? input(client.get(options.key))
129
+ : input;
130
+ if (next !== undefined)
131
+ client.set(options.key, next);
132
+ };
133
+ const refetch = async () => {
134
+ if (!options)
135
+ return IDLE;
136
+ const client = getQueryClient();
137
+ client.invalidate(options.key);
138
+ try {
139
+ await client.fetch(options);
140
+ }
141
+ catch (_error) {
142
+ // The cache publishes the failure to every observer. Return that state just as the
143
+ // initial subscription does, so an event handler can safely use `void query.refetch()`.
144
+ }
145
+ return client.getState(options.key);
146
+ };
147
+ return { hash: boundHash, setData, refetch };
148
+ };
149
+ const actions = shallowRef(bindActions(initial, initialHash));
150
+ /** The memory update React runs after every render (its first effect). */
151
+ const remember = () => {
152
+ const currentHash = hash.value;
153
+ const currentPrincipal = principal.value;
154
+ const current = value.value;
155
+ if (observed.value?.hash !== currentHash)
156
+ observed.value = { hash: currentHash, principal: currentPrincipal };
157
+ // A document is remembered only as its own principal's answer. While a
158
+ // retained previous document is showing, the memory is what makes it
159
+ // survive the fetch; keep it until this key answers. Anything else (no
160
+ // principal, a switch, a failure, a key observed under another principal)
161
+ // clears it, so a later key change can never fall back to another
162
+ // principal's document.
163
+ if (current.isPreviousData === true)
164
+ return;
165
+ loaded.value =
166
+ currentPrincipal !== undefined &&
167
+ observed.value.principal === currentPrincipal &&
168
+ current.data !== undefined &&
169
+ current.status === 'success'
170
+ ? { hash: currentHash, principal: currentPrincipal, value: current }
171
+ : null;
172
+ };
173
+ /** The subscription React runs after every render (its second effect). */
174
+ let unsubscribe = null;
175
+ const observe = () => {
176
+ unsubscribe?.();
177
+ unsubscribe = null;
178
+ const options = optionsRef.value;
179
+ const currentHash = hash.value;
180
+ if (!options) {
181
+ state.value = { hash: '', value: IDLE };
182
+ return;
183
+ }
184
+ const client = getQueryClient();
185
+ unsubscribe = client.subscribe(options, (next) => {
186
+ state.value = { hash: currentHash, value: next };
187
+ });
188
+ };
189
+ // A composable mounts once the way React's effects run after its first render:
190
+ // remember, then subscribe.
191
+ remember();
192
+ observe();
193
+ // The memory watcher is created first, so a flush that both re-derives the
194
+ // value and swaps keys updates the memory before it resubscribes — React
195
+ // runs its memory effect before its subscription effect.
196
+ watch(value, () => remember());
197
+ watch(hash, () => {
198
+ const currentHash = hash.value;
199
+ if (actions.value.hash !== currentHash)
200
+ actions.value = bindActions(optionsRef.value, currentHash);
201
+ observe();
202
+ });
203
+ if (getCurrentScope()) {
204
+ onScopeDispose(() => {
205
+ unsubscribe?.();
206
+ unsubscribe = null;
207
+ });
208
+ }
209
+ return computed(() => ({
210
+ ...value.value,
211
+ setData: actions.value.setData,
212
+ refetch: actions.value.refetch,
213
+ }));
214
+ }
215
+ //# sourceMappingURL=useQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,QAAQ,EACR,eAAe,EACf,cAAc,EAEd,UAAU,EACV,OAAO,EACP,KAAK,GACN,MAAM,KAAK,CAAA;AAGZ,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAIlE,MAAM,IAAI,GAAsB;IAC9B,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,SAAS;CACrB,CAAA;AAsBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,UAAU,QAAQ,CAAI,YAAkC;IAC5D,6EAA6E;IAC7E,yEAAyE;IACzE,MAAM,UAAU,G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AAQ,EAAE,CAAC,CAAA;IAC9B,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE;QACf,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAA;QAC9B,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW;YACpC,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;QAC5D,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;IAEF,IAAI,eAAe,EAAE,EAAE,CAAC;QACtB,cAAc,CAAC,GAAG,EAAE;YAClB,WAAW,EAAE,EAAE,CAAA;YACf,WAAW,GAAG,IAAI,CAAA;QACpB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,QAAQ,CAAoB,GAAG,EAAE,CAAC,CAAC;QACxC,GAAG,KAAK,CAAC,KAAK;QACd,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;QAC9B,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;KAC/B,CAAC,CAAC,CAAA;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,69 @@
1
1
  {
2
2
  "name": "@molecule/app-query-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Vue hooks for @molecule/app-query — read a cached document synchronously, observe it, and prefetch on intent",
5
+ "homepage": "https://www.molecule.dev/packages/app-query-vue",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "vue-tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "query",
28
+ "cache",
29
+ "prefetch",
30
+ "vue",
31
+ "hooks"
32
+ ],
33
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
34
+ "license": "Apache-2.0",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/molecule-dev/molecule.git",
38
+ "directory": "packages/app/features/query-vue"
39
+ },
40
+ "engines": {
41
+ "node": ">=20"
42
+ },
43
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "peerDependencies": {
48
+ "@molecule/app-query": "^1.2.0",
49
+ "vue": "^3.4.0"
50
+ },
51
+ "devDependencies": {
52
+ "@molecule/app-framework-conformance": "0.0.0",
53
+ "@molecule/app-i18n": "1.2.1",
54
+ "@molecule/app-icons": "1.0.4",
55
+ "@molecule/app-query": "1.2.0",
56
+ "@molecule/app-query-memory": "1.0.5",
57
+ "@molecule/app-query-tanstack": "1.0.5",
58
+ "@molecule/app-ui": "1.3.11",
59
+ "@molecule/app-ui-vue": "1.1.2",
60
+ "@molecule/app-vue": "3.6.0",
61
+ "@types/node": "26.6.5",
62
+ "jsdom": "30.1.3",
63
+ "typescript": "6.0.3",
64
+ "vite": "8.3.5",
65
+ "vitest": "4.1.12",
66
+ "vue": "3.5.44",
67
+ "vue-tsc": "3.3.13"
68
+ }
69
+ }