@data-client/vue 0.2.0 → 0.3.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.
- package/README.md +1 -24
- package/dist/index.js +185 -35
- package/dist/index.umd.min.js +1 -1
- package/lib/consumers/index.d.ts +2 -0
- package/lib/consumers/index.d.ts.map +1 -1
- package/lib/consumers/index.js +3 -1
- package/lib/consumers/useCache.d.ts +12 -0
- package/lib/consumers/useCache.d.ts.map +1 -0
- package/lib/consumers/useCache.js +63 -0
- package/lib/consumers/useDLE.d.ts +18 -0
- package/lib/consumers/useDLE.d.ts.map +1 -0
- package/lib/consumers/useDLE.js +88 -0
- package/lib/consumers/useFetch.d.ts +3 -2
- package/lib/consumers/useFetch.d.ts.map +1 -1
- package/lib/consumers/useFetch.js +10 -8
- package/lib/consumers/useLive.d.ts +3 -2
- package/lib/consumers/useLive.d.ts.map +1 -1
- package/lib/consumers/useLive.js +1 -1
- package/lib/consumers/useQuery.d.ts +3 -2
- package/lib/consumers/useQuery.d.ts.map +1 -1
- package/lib/consumers/useQuery.js +7 -3
- package/lib/consumers/useSubscription.d.ts +2 -1
- package/lib/consumers/useSubscription.d.ts.map +1 -1
- package/lib/consumers/useSubscription.js +1 -2
- package/lib/consumers/useSuspense.d.ts +3 -2
- package/lib/consumers/useSuspense.d.ts.map +1 -1
- package/lib/consumers/useSuspense.js +15 -20
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/providers/DataClientPlugin.d.ts +6 -0
- package/lib/providers/DataClientPlugin.d.ts.map +1 -1
- package/lib/providers/DataClientPlugin.js +15 -11
- package/lib/providers/index.d.ts +1 -1
- package/lib/providers/index.d.ts.map +1 -1
- package/lib/providers/index.js +1 -1
- package/lib/test/index.d.ts +3 -4
- package/lib/test/index.d.ts.map +1 -1
- package/lib/test/index.js +3 -5
- package/lib/test/mountDataClient.d.ts +29 -0
- package/lib/test/mountDataClient.d.ts.map +1 -0
- package/lib/test/mountDataClient.js +114 -0
- package/lib/test/renderDataCompose.d.ts +19 -0
- package/lib/test/renderDataCompose.d.ts.map +1 -0
- package/lib/test/renderDataCompose.js +135 -0
- package/lib/types.d.ts +10 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/package.json +6 -6
- package/src/__tests__/context.test.ts +195 -0
- package/src/__tests__/integration-garbage-collection.web.ts +12 -15
- package/src/__tests__/useCache.web.ts +391 -0
- package/src/__tests__/useDLE.web.ts +660 -0
- package/src/__tests__/useQuery.web.ts +332 -50
- package/src/__tests__/useSubscription.web.ts +233 -119
- package/src/__tests__/useSuspense.web.ts +176 -50
- package/src/consumers/index.ts +2 -0
- package/src/consumers/useCache.ts +122 -0
- package/src/consumers/useDLE.ts +160 -0
- package/src/consumers/useFetch.ts +24 -13
- package/src/consumers/useLive.ts +6 -2
- package/src/consumers/useQuery.ts +14 -5
- package/src/consumers/useSubscription.ts +5 -1
- package/src/consumers/useSuspense.ts +29 -17
- package/src/index.ts +4 -0
- package/src/providers/DataClientPlugin.ts +25 -10
- package/src/providers/__tests__/DataClientPlugin.test.ts +204 -4
- package/src/providers/__tests__/createDataClient.test.ts +234 -0
- package/src/providers/__tests__/getDefaultManagers.test.ts +180 -0
- package/src/providers/index.ts +5 -1
- package/src/test/README.md +77 -16
- package/src/test/__tests__/mountDataClient.test.ts +426 -0
- package/src/test/__tests__/renderDataCompose.test.ts +586 -0
- package/src/test/index.ts +3 -9
- package/src/test/mountDataClient.ts +169 -0
- package/src/test/renderDataCompose.ts +150 -0
- package/src/types.ts +11 -0
- package/ts3.4/consumers/index.d.ts +2 -0
- package/ts3.4/consumers/useCache.d.ts +14 -0
- package/ts3.4/consumers/useDLE.d.ts +20 -0
- package/ts3.4/consumers/useFetch.d.ts +3 -6
- package/ts3.4/consumers/useLive.d.ts +3 -6
- package/ts3.4/consumers/useQuery.d.ts +3 -2
- package/ts3.4/consumers/useSubscription.d.ts +2 -3
- package/ts3.4/consumers/useSuspense.d.ts +3 -6
- package/ts3.4/index.d.ts +1 -0
- package/ts3.4/providers/DataClientPlugin.d.ts +6 -0
- package/ts3.4/providers/index.d.ts +1 -1
- package/ts3.4/test/index.d.ts +3 -4
- package/ts3.4/test/mountDataClient.d.ts +29 -0
- package/ts3.4/test/renderDataCompose.d.ts +19 -0
- package/ts3.4/types.d.ts +10 -0
- package/lib/test/renderDataClient.d.ts +0 -40
- package/lib/test/renderDataClient.d.ts.map +0 -1
- package/lib/test/renderDataClient.js +0 -264
- package/src/__tests__/__snapshots__/useSubscription.web.ts.snap +0 -7
- package/src/test/renderDataClient.ts +0 -316
- package/ts3.4/test/renderDataClient.d.ts +0 -40
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
State,
|
|
3
|
+
Manager,
|
|
4
|
+
Controller,
|
|
5
|
+
NetworkManager,
|
|
6
|
+
SubscriptionManager,
|
|
7
|
+
PollingSubscription,
|
|
8
|
+
type GCInterface,
|
|
9
|
+
} from '@data-client/core';
|
|
10
|
+
import { mount, type VueWrapper } from '@vue/test-utils';
|
|
11
|
+
import {
|
|
12
|
+
defineComponent,
|
|
13
|
+
h,
|
|
14
|
+
Suspense,
|
|
15
|
+
inject,
|
|
16
|
+
type Reactive,
|
|
17
|
+
reactive,
|
|
18
|
+
} from 'vue';
|
|
19
|
+
|
|
20
|
+
import { Interceptor, Fixture } from './fixtureTypes.js';
|
|
21
|
+
import MockController from './MockController.js';
|
|
22
|
+
import mockInitialState from './mockState.js';
|
|
23
|
+
import { ControllerKey } from '../context.js';
|
|
24
|
+
import { DataClientPlugin } from '../providers/DataClientPlugin.js';
|
|
25
|
+
|
|
26
|
+
export interface RenderDataClientOptions<P = any> {
|
|
27
|
+
props?: Reactive<P>;
|
|
28
|
+
initialFixtures?: readonly Fixture[];
|
|
29
|
+
resolverFixtures?: readonly (Fixture | Interceptor)[];
|
|
30
|
+
getInitialInterceptorData?: () => any;
|
|
31
|
+
managers?: Manager[];
|
|
32
|
+
initialState?: State<unknown>;
|
|
33
|
+
gcPolicy?: GCInterface;
|
|
34
|
+
wrapper?: any;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface RenderDataClientResult {
|
|
38
|
+
wrapper: VueWrapper<any>;
|
|
39
|
+
controller: Controller;
|
|
40
|
+
app: any;
|
|
41
|
+
cleanup: () => void;
|
|
42
|
+
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Renders a Vue component with DataClient plugin and fixtures for testing
|
|
47
|
+
*
|
|
48
|
+
* @param component - The Vue component to test
|
|
49
|
+
* @param options - Configuration including optional reactive props ref, fixtures, managers, etc.
|
|
50
|
+
*/
|
|
51
|
+
export function mountDataClient<P = any>(
|
|
52
|
+
component: any,
|
|
53
|
+
options: RenderDataClientOptions<P> = {},
|
|
54
|
+
): RenderDataClientResult {
|
|
55
|
+
const {
|
|
56
|
+
initialFixtures = [],
|
|
57
|
+
resolverFixtures,
|
|
58
|
+
getInitialInterceptorData = () => ({}),
|
|
59
|
+
managers,
|
|
60
|
+
initialState,
|
|
61
|
+
gcPolicy,
|
|
62
|
+
wrapper,
|
|
63
|
+
} = options;
|
|
64
|
+
|
|
65
|
+
// Extract props from options, or create empty ref if not provided
|
|
66
|
+
const props = options.props || reactive({});
|
|
67
|
+
|
|
68
|
+
// Create mock controller with fixtures
|
|
69
|
+
const MockControllerClass = MockController(
|
|
70
|
+
Controller,
|
|
71
|
+
resolverFixtures ?
|
|
72
|
+
{
|
|
73
|
+
fixtures: [...resolverFixtures],
|
|
74
|
+
getInitialInterceptorData,
|
|
75
|
+
}
|
|
76
|
+
: {},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Create managers
|
|
80
|
+
const nm = new NetworkManager();
|
|
81
|
+
const sm = new SubscriptionManager(PollingSubscription);
|
|
82
|
+
const defaultManagers = [nm, sm];
|
|
83
|
+
const finalManagers = managers ?? defaultManagers;
|
|
84
|
+
|
|
85
|
+
// Create initial state
|
|
86
|
+
const mockState = mockInitialState([...initialFixtures]);
|
|
87
|
+
const finalInitialState = initialState ?? mockState;
|
|
88
|
+
|
|
89
|
+
// Create a wrapper component that provides the data client context
|
|
90
|
+
const DataClientWrapper = defineComponent({
|
|
91
|
+
name: 'DataClientWrapper',
|
|
92
|
+
setup(_, { expose }) {
|
|
93
|
+
// Inject the controller provided by the plugin
|
|
94
|
+
const controller = inject(ControllerKey) as Controller;
|
|
95
|
+
|
|
96
|
+
// Expose controller for testing
|
|
97
|
+
expose({
|
|
98
|
+
controller,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return () => {
|
|
102
|
+
const innerComponent =
|
|
103
|
+
wrapper ?
|
|
104
|
+
h(wrapper, props as any, () => h(component, props as any))
|
|
105
|
+
: h(component, props as any);
|
|
106
|
+
|
|
107
|
+
return h(
|
|
108
|
+
Suspense,
|
|
109
|
+
{},
|
|
110
|
+
{
|
|
111
|
+
default: () => innerComponent,
|
|
112
|
+
fallback: () =>
|
|
113
|
+
h('div', { 'data-testid': 'suspense-fallback' }, 'Loading...'),
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Mount the wrapper with DataClientPlugin
|
|
121
|
+
const wrapper_instance = mount(DataClientWrapper, {
|
|
122
|
+
global: {
|
|
123
|
+
plugins: [
|
|
124
|
+
[
|
|
125
|
+
DataClientPlugin,
|
|
126
|
+
{
|
|
127
|
+
managers: finalManagers,
|
|
128
|
+
initialState: finalInitialState,
|
|
129
|
+
Controller: MockControllerClass,
|
|
130
|
+
gcPolicy,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Get controller from the wrapper
|
|
138
|
+
const controller = (wrapper_instance.vm as any).controller;
|
|
139
|
+
|
|
140
|
+
// Cleanup function
|
|
141
|
+
const cleanup = () => {
|
|
142
|
+
nm.cleanupDate = Infinity;
|
|
143
|
+
if ((nm as any)['rejectors']) {
|
|
144
|
+
Object.values((nm as any)['rejectors'] as Record<string, any>).forEach(
|
|
145
|
+
(rej: any) => {
|
|
146
|
+
rej();
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
} else if (nm['fetching']) {
|
|
150
|
+
nm['fetching'].forEach(({ reject }: any) => reject());
|
|
151
|
+
}
|
|
152
|
+
nm['clearAll']();
|
|
153
|
+
finalManagers.forEach(manager => manager.cleanup());
|
|
154
|
+
wrapper_instance.unmount();
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// All settled function
|
|
158
|
+
const allSettled = (): Promise<PromiseSettledResult<unknown>[]> => {
|
|
159
|
+
return nm.allSettled() ?? Promise.resolve([]);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
wrapper: wrapper_instance,
|
|
164
|
+
controller,
|
|
165
|
+
app: wrapper_instance.vm,
|
|
166
|
+
cleanup,
|
|
167
|
+
allSettled,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type Controller } from '@data-client/core';
|
|
2
|
+
import { type VueWrapper } from '@vue/test-utils';
|
|
3
|
+
import { defineComponent, h, watch, reactive, nextTick, isRef } from 'vue';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
mountDataClient,
|
|
7
|
+
type RenderDataClientOptions,
|
|
8
|
+
} from './mountDataClient.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Renders a Vue composable with DataClient provider for testing
|
|
12
|
+
* Similar to renderDataHook from @data-client/test but for Vue composables
|
|
13
|
+
*
|
|
14
|
+
* @param composable - The composable function to test
|
|
15
|
+
* @param options - Configuration including optional reactive props ref, fixtures, managers, etc.
|
|
16
|
+
*/
|
|
17
|
+
export async function renderDataCompose<P = any, R = any>(
|
|
18
|
+
composable: (props: P) => R,
|
|
19
|
+
options: RenderDataClientOptions<P> = {},
|
|
20
|
+
): Promise<{
|
|
21
|
+
result: R;
|
|
22
|
+
wrapper: VueWrapper<any>;
|
|
23
|
+
controller: Controller;
|
|
24
|
+
cleanup: () => void;
|
|
25
|
+
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
26
|
+
waitForNextUpdate: () => Promise<void>;
|
|
27
|
+
}> {
|
|
28
|
+
// Extract props from options, or create empty ref if not provided
|
|
29
|
+
const props = options.props || reactive({});
|
|
30
|
+
|
|
31
|
+
let resultRef: any;
|
|
32
|
+
let resolveNextUpdate: (() => void) | null = null;
|
|
33
|
+
let resolveComposableInit: (() => void) | null = null;
|
|
34
|
+
|
|
35
|
+
// Promise that resolves when the composable has been called
|
|
36
|
+
const composableInitialized = new Promise<void>(resolve => {
|
|
37
|
+
resolveComposableInit = resolve;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const TestComponent = defineComponent({
|
|
41
|
+
name: 'TestComposableComponent',
|
|
42
|
+
props: {
|
|
43
|
+
composableProps: {
|
|
44
|
+
type: Object,
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
setup(componentProps, { expose }) {
|
|
49
|
+
// Call the composable once with reactive props - Vue's useSuspense will handle the async behavior
|
|
50
|
+
const composableValue = composable(componentProps.composableProps as P);
|
|
51
|
+
|
|
52
|
+
// Store the composable value directly without wrapping
|
|
53
|
+
resultRef = composableValue;
|
|
54
|
+
|
|
55
|
+
// Signal that the composable has been initialized
|
|
56
|
+
if (resolveComposableInit) {
|
|
57
|
+
resolveComposableInit();
|
|
58
|
+
resolveComposableInit = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// If composable returns a Promise, wait for it to resolve before triggering update callbacks
|
|
62
|
+
if (composableValue instanceof Promise) {
|
|
63
|
+
composableValue
|
|
64
|
+
.then(() => {
|
|
65
|
+
if (resolveNextUpdate) {
|
|
66
|
+
resolveNextUpdate();
|
|
67
|
+
resolveNextUpdate = null;
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.catch(() => {
|
|
71
|
+
if (resolveNextUpdate) {
|
|
72
|
+
resolveNextUpdate();
|
|
73
|
+
resolveNextUpdate = null;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
// If composable returns a value directly, trigger update immediately
|
|
78
|
+
if (resolveNextUpdate) {
|
|
79
|
+
resolveNextUpdate();
|
|
80
|
+
resolveNextUpdate = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Watch for changes to the result if it's reactive
|
|
85
|
+
if (isRef(resultRef)) {
|
|
86
|
+
watch(resultRef, () => {
|
|
87
|
+
if (resolveNextUpdate) {
|
|
88
|
+
resolveNextUpdate();
|
|
89
|
+
resolveNextUpdate = null;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
expose({ result: resultRef });
|
|
95
|
+
return { result: resultRef };
|
|
96
|
+
},
|
|
97
|
+
render() {
|
|
98
|
+
return h('div', { 'data-testid': 'composable-result' });
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Wrap the component to accept composableProps from the external ref
|
|
103
|
+
const WrappedTestComponent = defineComponent({
|
|
104
|
+
name: 'WrappedTestComponent',
|
|
105
|
+
setup() {
|
|
106
|
+
return () =>
|
|
107
|
+
h(TestComponent, {
|
|
108
|
+
composableProps: props,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const { wrapper, controller, cleanup, allSettled } = mountDataClient(
|
|
114
|
+
WrappedTestComponent,
|
|
115
|
+
options,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// Wait for the composable to be initialized before returning
|
|
119
|
+
await composableInitialized;
|
|
120
|
+
// Give Vue's reactivity system time to process the initial values
|
|
121
|
+
await nextTick();
|
|
122
|
+
|
|
123
|
+
const waitForNextUpdate = async (): Promise<void> => {
|
|
124
|
+
// For Promises (like useSuspense), wait for them to resolve
|
|
125
|
+
const valueToCheck = isRef(resultRef) ? resultRef.value : resultRef;
|
|
126
|
+
if (valueToCheck instanceof Promise) {
|
|
127
|
+
return new Promise(resolve => {
|
|
128
|
+
resolveNextUpdate = resolve;
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
if (resolveNextUpdate === resolve) {
|
|
131
|
+
resolveNextUpdate = null;
|
|
132
|
+
resolve();
|
|
133
|
+
}
|
|
134
|
+
}, 1000);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
await allSettled();
|
|
139
|
+
await nextTick();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
result: resultRef,
|
|
144
|
+
wrapper,
|
|
145
|
+
controller,
|
|
146
|
+
cleanup,
|
|
147
|
+
allSettled,
|
|
148
|
+
waitForNextUpdate,
|
|
149
|
+
};
|
|
150
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
|
|
3
|
+
/** Maps each parameter to accept raw value, Ref, ComputedRef, or getter */
|
|
4
|
+
export type MaybeRefsOrGetters<T extends readonly any[]> = {
|
|
5
|
+
readonly [K in keyof T]: MaybeRefOrGetter<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/** Maps each parameter to accept raw value, Ref, ComputedRef, or getter, with nullable support */
|
|
9
|
+
export type MaybeRefsOrGettersNullable<T extends readonly any[]> = {
|
|
10
|
+
readonly [K in keyof T]: MaybeRefOrGetter<T[K] | null>;
|
|
11
|
+
};
|
|
@@ -5,5 +5,7 @@ export { default as useLive } from './useLive.js';
|
|
|
5
5
|
export { default as useLoading } from './useLoading.js';
|
|
6
6
|
export { default as useDebounce } from './useDebounce.js';
|
|
7
7
|
export { default as useFetch } from './useFetch.js';
|
|
8
|
+
export { default as useCache } from './useCache.js';
|
|
9
|
+
export { default as useDLE } from './useDLE.js';
|
|
8
10
|
export { useController as useController } from '../context.js';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EndpointInterface, DenormalizeNullable, Schema, FetchFunction, ResolveType } from '@data-client/core';
|
|
2
|
+
import { ComputedRef } from 'vue';
|
|
3
|
+
import { MaybeRefsOrGetters, MaybeRefsOrGettersNullable } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Read an Endpoint's response if it is ready.
|
|
6
|
+
*
|
|
7
|
+
* `useCache` guarantees referential equality globally.
|
|
8
|
+
* @see https://dataclient.io/docs/api/useCache
|
|
9
|
+
*/
|
|
10
|
+
export default function useCache<E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, undefined | boolean>, 'key' | 'schema' | 'invalidIfStale'>>(endpoint: E, ...args: MaybeRefsOrGetters<Parameters<E['key']>>): ComputedRef<E['schema'] extends undefined | null ? E extends (...args: any) => any ? ResolveType<E> | undefined : any : DenormalizeNullable<E['schema']>>;
|
|
11
|
+
export default function useCache<E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, undefined | boolean>, 'key' | 'schema' | 'invalidIfStale'>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E['key']>> | readonly [
|
|
12
|
+
null
|
|
13
|
+
]): ComputedRef<E['schema'] extends undefined | null ? E extends (...args: any) => any ? ResolveType<E> | undefined : any : DenormalizeNullable<E['schema']>>;
|
|
14
|
+
//# sourceMappingURL=useCache.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Denormalize, DenormalizeNullable, ErrorTypes, EndpointInterface, FetchFunction, Schema, ResolveType } from '@data-client/core';
|
|
2
|
+
import { ComputedRef } from 'vue';
|
|
3
|
+
import { MaybeRefsOrGetters, MaybeRefsOrGettersNullable } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Use async data with { data, loading, error } (DLE)
|
|
6
|
+
* @see https://dataclient.io/docs/api/useDLE
|
|
7
|
+
*/
|
|
8
|
+
export default function useDLE<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGetters<Parameters<E>>): {
|
|
9
|
+
data: ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> | undefined : Denormalize<E['schema']> | DenormalizeNullable<E['schema']>>;
|
|
10
|
+
loading: ComputedRef<boolean>;
|
|
11
|
+
error: ComputedRef<ErrorTypes | undefined>;
|
|
12
|
+
};
|
|
13
|
+
export default function useDLE<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E>> | readonly [
|
|
14
|
+
null
|
|
15
|
+
]): {
|
|
16
|
+
data: ComputedRef<E['schema'] extends undefined | null ? undefined : DenormalizeNullable<E['schema']>>;
|
|
17
|
+
loading: ComputedRef<boolean>;
|
|
18
|
+
error: ComputedRef<ErrorTypes | undefined>;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=useDLE.d.ts.map
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { EndpointInterface, Denormalize, Schema, FetchFunction, DenormalizeNullable } from '@data-client/core';
|
|
2
|
+
import { MaybeRefsOrGetters, MaybeRefsOrGettersNullable } from '../types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Fetch an Endpoint if it is not in cache or stale.
|
|
4
5
|
* Non-suspense; returns the fetch Promise when a request is issued, otherwise undefined.
|
|
5
6
|
* Mirrors React useFetch semantics.
|
|
6
7
|
* @see https://dataclient.io/docs/api/useFetch
|
|
7
8
|
*/
|
|
8
|
-
export default function useFetch<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args:
|
|
9
|
-
|
|
10
|
-
]): E['schema'] extends undefined | null ? ReturnType<E> : Promise<Denormalize<E['schema']>>;
|
|
11
|
-
export default function useFetch<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
12
|
-
...Parameters<E>
|
|
13
|
-
] | readonly [
|
|
9
|
+
export default function useFetch<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGetters<Parameters<E>>): E['schema'] extends undefined | null ? ReturnType<E> : Promise<Denormalize<E['schema']>>;
|
|
10
|
+
export default function useFetch<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E>> | readonly [
|
|
14
11
|
null
|
|
15
12
|
]): E['schema'] extends undefined | null ? ReturnType<E> | undefined : Promise<DenormalizeNullable<E['schema']>> | undefined;
|
|
16
13
|
//# sourceMappingURL=useFetch.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EndpointInterface, Denormalize, Schema, FetchFunction, ResolveType, DenormalizeNullable } from '@data-client/core';
|
|
2
2
|
import { DeepReadonly, ComputedRef } from 'vue';
|
|
3
|
+
import { MaybeRefsOrGetters, MaybeRefsOrGettersNullable } from '../types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Ensure an endpoint is available. Keeps it fresh once it is.
|
|
5
6
|
*
|
|
@@ -8,12 +9,8 @@ import { DeepReadonly, ComputedRef } from 'vue';
|
|
|
8
9
|
* @throws {Promise} If data is not yet available.
|
|
9
10
|
* @throws {NetworkError} If fetch fails.
|
|
10
11
|
*/
|
|
11
|
-
export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args:
|
|
12
|
-
|
|
13
|
-
]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> : Denormalize<E['schema']>>>>;
|
|
14
|
-
export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
15
|
-
...Parameters<E>
|
|
16
|
-
] | readonly [
|
|
12
|
+
export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGetters<Parameters<E>>): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> : Denormalize<E['schema']>>>>;
|
|
13
|
+
export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E>> | readonly [
|
|
17
14
|
null
|
|
18
15
|
]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> | undefined : DenormalizeNullable<E['schema']>>>>;
|
|
19
16
|
//# sourceMappingURL=useLive.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DenormalizeNullable,
|
|
1
|
+
import { DenormalizeNullable, Queryable, SchemaArgs } from '@data-client/core';
|
|
2
2
|
import { ComputedRef } from 'vue';
|
|
3
|
+
import { MaybeRefsOrGetters } from '../types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Query the store (non-suspense).
|
|
5
6
|
*
|
|
@@ -8,5 +9,5 @@ import { ComputedRef } from 'vue';
|
|
|
8
9
|
* Mirrors React's useQuery semantics using Vue reactivity.
|
|
9
10
|
* @see https://dataclient.io/docs/api/useQuery
|
|
10
11
|
*/
|
|
11
|
-
export default function useQuery<S extends Queryable>(schema: S, ...args:
|
|
12
|
+
export default function useQuery<S extends Queryable>(schema: S, ...args: MaybeRefsOrGetters<SchemaArgs<S>>): ComputedRef<DenormalizeNullable<S> | undefined>;
|
|
12
13
|
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { EndpointInterface, Schema, FetchFunction } from '@data-client/core';
|
|
2
|
+
import { MaybeRefsOrGettersNullable } from '../types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Keeps a resource fresh by subscribing to updates.
|
|
4
5
|
* Mirrors React hook API. Pass `null` as first arg to unsubscribe.
|
|
5
6
|
* @see https://dataclient.io/docs/api/useSubscription
|
|
6
7
|
*/
|
|
7
|
-
export default function useSubscription<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
8
|
-
...Parameters<E>
|
|
9
|
-
] | readonly [
|
|
8
|
+
export default function useSubscription<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E>> | readonly [
|
|
10
9
|
null
|
|
11
10
|
]): void;
|
|
12
11
|
//# sourceMappingURL=useSubscription.d.ts.map
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { EndpointInterface, Denormalize, Schema, FetchFunction, DenormalizeNullable, ResolveType } from '@data-client/core';
|
|
2
2
|
import { DeepReadonly, ComputedRef } from 'vue';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default function useSuspense<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
7
|
-
...Parameters<E>
|
|
8
|
-
] | readonly [
|
|
3
|
+
import { MaybeRefsOrGetters, MaybeRefsOrGettersNullable } from '../types.js';
|
|
4
|
+
export default function useSuspense<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGetters<Parameters<E>>): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> : Denormalize<E['schema']>>>>;
|
|
5
|
+
export default function useSuspense<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E>> | readonly [
|
|
9
6
|
null
|
|
10
7
|
]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> | undefined : DenormalizeNullable<E['schema']>>>>;
|
|
11
8
|
//# sourceMappingURL=useSuspense.d.ts.map
|
package/ts3.4/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { EndpointExtraOptions, FetchFunction, ResolveType, EndpointInterface, En
|
|
|
3
3
|
export * from './consumers/index.js';
|
|
4
4
|
export * from './providers/index.js';
|
|
5
5
|
export * from './managers/index.js';
|
|
6
|
+
export { MaybeRefsOrGetters, MaybeRefsOrGettersNullable, } from './types.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Controller } from '@data-client/core';
|
|
1
2
|
import { App } from 'vue';
|
|
2
3
|
import { ProvideOptions } from './createDataClient.js';
|
|
3
4
|
/**
|
|
@@ -19,4 +20,9 @@ import { ProvideOptions } from './createDataClient.js';
|
|
|
19
20
|
export declare const DataClientPlugin: {
|
|
20
21
|
install(app: App, options?: ProvideOptions): import("./createDataClient.js").ProvidedDataClient;
|
|
21
22
|
};
|
|
23
|
+
declare module 'vue' {
|
|
24
|
+
interface ComponentCustomProperties {
|
|
25
|
+
$dataClient: Controller;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
22
28
|
//# sourceMappingURL=DataClientPlugin.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { getDefaultManagers } from './getDefaultManagers.js';
|
|
2
|
-
export { createDataClient } from './createDataClient.js';
|
|
2
|
+
export { createDataClient, ProvideOptions, ProvidedDataClient } from './createDataClient.js';
|
|
3
3
|
export { DataClientPlugin } from './DataClientPlugin.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/ts3.4/test/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { default as MockController } from './MockController.js';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { mountDataClient } from './mountDataClient.js';
|
|
3
|
+
export { renderDataCompose } from './renderDataCompose.js';
|
|
4
|
+
export { RenderDataClientOptions, RenderDataClientResult, } from './mountDataClient.js';
|
|
4
5
|
export { FixtureEndpoint, SuccessFixtureEndpoint, ErrorFixtureEndpoint, Fixture, SuccessFixture, ErrorFixture, Interceptor, } from './fixtureTypes.js';
|
|
5
6
|
export { default as mockInitialState } from './mockState.js';
|
|
6
|
-
export { DataClientPlugin, createDataClient } from '../providers/index.js';
|
|
7
|
-
export { ProvideOptions, ProvidedDataClient, } from '../providers/createDataClient.js';
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { State, Manager, Controller, GCInterface } from '@data-client/core';
|
|
2
|
+
import { VueWrapper } from '@vue/test-utils';
|
|
3
|
+
import { Reactive } from 'vue';
|
|
4
|
+
import { Interceptor, Fixture } from './fixtureTypes.js';
|
|
5
|
+
export interface RenderDataClientOptions<P = any> {
|
|
6
|
+
props?: Reactive<P>;
|
|
7
|
+
initialFixtures?: readonly Fixture[];
|
|
8
|
+
resolverFixtures?: readonly (Fixture | Interceptor)[];
|
|
9
|
+
getInitialInterceptorData?: () => any;
|
|
10
|
+
managers?: Manager[];
|
|
11
|
+
initialState?: State<unknown>;
|
|
12
|
+
gcPolicy?: GCInterface;
|
|
13
|
+
wrapper?: any;
|
|
14
|
+
}
|
|
15
|
+
export interface RenderDataClientResult {
|
|
16
|
+
wrapper: VueWrapper<any>;
|
|
17
|
+
controller: Controller;
|
|
18
|
+
app: any;
|
|
19
|
+
cleanup: () => void;
|
|
20
|
+
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Renders a Vue component with DataClient plugin and fixtures for testing
|
|
24
|
+
*
|
|
25
|
+
* @param component - The Vue component to test
|
|
26
|
+
* @param options - Configuration including optional reactive props ref, fixtures, managers, etc.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mountDataClient<P = any>(component: any, options?: RenderDataClientOptions<P>): RenderDataClientResult;
|
|
29
|
+
//# sourceMappingURL=mountDataClient.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Controller } from '@data-client/core';
|
|
2
|
+
import { VueWrapper } from '@vue/test-utils';
|
|
3
|
+
import { RenderDataClientOptions } from './mountDataClient.js';
|
|
4
|
+
/**
|
|
5
|
+
* Renders a Vue composable with DataClient provider for testing
|
|
6
|
+
* Similar to renderDataHook from @data-client/test but for Vue composables
|
|
7
|
+
*
|
|
8
|
+
* @param composable - The composable function to test
|
|
9
|
+
* @param options - Configuration including optional reactive props ref, fixtures, managers, etc.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderDataCompose<P = any, R = any>(composable: (props: P) => R, options?: RenderDataClientOptions<P>): Promise<{
|
|
12
|
+
result: R;
|
|
13
|
+
wrapper: VueWrapper<any>;
|
|
14
|
+
controller: Controller;
|
|
15
|
+
cleanup: () => void;
|
|
16
|
+
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
17
|
+
waitForNextUpdate: () => Promise<void>;
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=renderDataCompose.d.ts.map
|
package/ts3.4/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
/** Maps each parameter to accept raw value, Ref, ComputedRef, or getter */
|
|
3
|
+
export type MaybeRefsOrGetters<T extends readonly any[]> = {
|
|
4
|
+
readonly [K in keyof T]: MaybeRefOrGetter<T[K]>;
|
|
5
|
+
};
|
|
6
|
+
/** Maps each parameter to accept raw value, Ref, ComputedRef, or getter, with nullable support */
|
|
7
|
+
export type MaybeRefsOrGettersNullable<T extends readonly any[]> = {
|
|
8
|
+
readonly [K in keyof T]: MaybeRefOrGetter<T[K] | null>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { State, Manager, Controller, type GCInterface } from '@data-client/core';
|
|
2
|
-
import { type VueWrapper } from '@vue/test-utils';
|
|
3
|
-
import { Interceptor, Fixture } from './fixtureTypes.js';
|
|
4
|
-
export interface RenderDataClientOptions<P = any> {
|
|
5
|
-
initialProps?: P;
|
|
6
|
-
initialFixtures?: readonly Fixture[];
|
|
7
|
-
resolverFixtures?: readonly (Fixture | Interceptor)[];
|
|
8
|
-
getInitialInterceptorData?: () => any;
|
|
9
|
-
managers?: Manager[];
|
|
10
|
-
initialState?: State<unknown>;
|
|
11
|
-
gcPolicy?: GCInterface;
|
|
12
|
-
wrapper?: any;
|
|
13
|
-
}
|
|
14
|
-
export interface RenderDataClientResult {
|
|
15
|
-
wrapper: VueWrapper<any>;
|
|
16
|
-
controller: Controller;
|
|
17
|
-
app: any;
|
|
18
|
-
cleanup: () => void;
|
|
19
|
-
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Renders a Vue component with DataClient provider for testing
|
|
23
|
-
* Similar to renderDataClient from @data-client/test but for Vue
|
|
24
|
-
*/
|
|
25
|
-
export declare function renderDataClient<P = any>(component: any, options?: RenderDataClientOptions<P>): RenderDataClientResult;
|
|
26
|
-
/**
|
|
27
|
-
* Renders a Vue composable with DataClient provider for testing
|
|
28
|
-
* Similar to renderDataHook from @data-client/test but for Vue composables
|
|
29
|
-
*/
|
|
30
|
-
export declare function renderDataComposable<P = any, R = any>(composable: (props: P) => R, options?: RenderDataClientOptions<P>): {
|
|
31
|
-
result: {
|
|
32
|
-
current: R | undefined;
|
|
33
|
-
};
|
|
34
|
-
wrapper: VueWrapper<any>;
|
|
35
|
-
controller: Controller;
|
|
36
|
-
cleanup: () => void;
|
|
37
|
-
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
38
|
-
waitForNextUpdate: () => Promise<void>;
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=renderDataClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderDataClient.d.ts","sourceRoot":"","sources":["../../src/test/renderDataClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EAIV,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAWzD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAMzD,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,GAAG;IAC9C,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,eAAe,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,gBAAgB,CAAC,EAAE,SAAS,CAAC,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC;IACtD,yBAAyB,CAAC,EAAE,MAAM,GAAG,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;CAC5D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,GAAG,EACtC,SAAS,EAAE,GAAG,EACd,OAAO,GAAE,uBAAuB,CAAC,CAAC,CAAM,GACvC,sBAAsB,CAsIxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EACnD,UAAU,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EAC3B,OAAO,GAAE,uBAAuB,CAAC,CAAC,CAAM,GACvC;IACD,MAAM,EAAE;QAAE,OAAO,EAAE,CAAC,GAAG,SAAS,CAAA;KAAE,CAAC;IACnC,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3D,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC,CAiHA"}
|