@data-client/vue 0.2.0 → 0.3.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/README.md +2 -25
- package/dist/index.js +200 -42
- 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 -4
- package/lib/consumers/useFetch.d.ts.map +1 -1
- package/lib/consumers/useFetch.js +10 -10
- 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 +5 -6
- package/lib/consumers/useQuery.d.ts.map +1 -1
- package/lib/consumers/useQuery.js +9 -7
- 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 +11 -2
- package/lib/consumers/useSuspense.d.ts.map +1 -1
- package/lib/consumers/useSuspense.js +25 -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/getDefaultManagers.d.ts +4 -1
- package/lib/providers/getDefaultManagers.d.ts.map +1 -1
- package/lib/providers/getDefaultManagers.js +5 -2
- 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 +11 -9
- 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 -15
- package/src/consumers/useLive.ts +6 -2
- package/src/consumers/useQuery.ts +16 -9
- package/src/consumers/useSubscription.ts +5 -1
- package/src/consumers/useSuspense.ts +37 -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/getDefaultManagers.ts +4 -1
- 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/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/consumers/index.d.ts +0 -9
- package/ts3.4/consumers/useDebounce.d.ts +0 -19
- package/ts3.4/consumers/useFetch.d.ts +0 -16
- package/ts3.4/consumers/useLive.d.ts +0 -19
- package/ts3.4/consumers/useLoading.d.ts +0 -22
- package/ts3.4/consumers/useQuery.d.ts +0 -12
- package/ts3.4/consumers/useSubscription.d.ts +0 -12
- package/ts3.4/consumers/useSuspense.d.ts +0 -11
- package/ts3.4/context.d.ts +0 -10
- package/ts3.4/index.d.ts +0 -6
- package/ts3.4/managers/index.d.ts +0 -2
- package/ts3.4/providers/DataClientPlugin.d.ts +0 -22
- package/ts3.4/providers/createDataClient.d.ts +0 -25
- package/ts3.4/providers/getDefaultManagers.d.ts +0 -14
- package/ts3.4/providers/index.d.ts +0 -4
- package/ts3.4/test/MockController.d.ts +0 -8
- package/ts3.4/test/collapseFixture.d.ts +0 -6
- package/ts3.4/test/createFixtureMap.d.ts +0 -6
- package/ts3.4/test/fixtureTypes.d.ts +0 -99
- package/ts3.4/test/index.d.ts +0 -8
- package/ts3.4/test/mockState.d.ts +0 -4
- package/ts3.4/test/renderDataClient.d.ts +0 -40
|
@@ -1,316 +0,0 @@
|
|
|
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
|
-
ref,
|
|
16
|
-
watch,
|
|
17
|
-
nextTick,
|
|
18
|
-
inject,
|
|
19
|
-
} from 'vue';
|
|
20
|
-
|
|
21
|
-
import { Interceptor, Fixture } from './fixtureTypes.js';
|
|
22
|
-
import MockController from './MockController.js';
|
|
23
|
-
import mockInitialState from './mockState.js';
|
|
24
|
-
import { ControllerKey } from '../context.js';
|
|
25
|
-
import { DataClientPlugin } from '../providers/DataClientPlugin.js';
|
|
26
|
-
|
|
27
|
-
export interface RenderDataClientOptions<P = any> {
|
|
28
|
-
initialProps?: P;
|
|
29
|
-
initialFixtures?: readonly Fixture[];
|
|
30
|
-
resolverFixtures?: readonly (Fixture | Interceptor)[];
|
|
31
|
-
getInitialInterceptorData?: () => any;
|
|
32
|
-
managers?: Manager[];
|
|
33
|
-
initialState?: State<unknown>;
|
|
34
|
-
gcPolicy?: GCInterface;
|
|
35
|
-
wrapper?: any;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface RenderDataClientResult {
|
|
39
|
-
wrapper: VueWrapper<any>;
|
|
40
|
-
controller: Controller;
|
|
41
|
-
app: any;
|
|
42
|
-
cleanup: () => void;
|
|
43
|
-
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Renders a Vue component with DataClient provider for testing
|
|
48
|
-
* Similar to renderDataClient from @data-client/test but for Vue
|
|
49
|
-
*/
|
|
50
|
-
export function renderDataClient<P = any>(
|
|
51
|
-
component: any,
|
|
52
|
-
options: RenderDataClientOptions<P> = {},
|
|
53
|
-
): RenderDataClientResult {
|
|
54
|
-
const {
|
|
55
|
-
initialProps,
|
|
56
|
-
initialFixtures = [],
|
|
57
|
-
resolverFixtures,
|
|
58
|
-
getInitialInterceptorData = () => ({}),
|
|
59
|
-
managers,
|
|
60
|
-
initialState,
|
|
61
|
-
gcPolicy,
|
|
62
|
-
wrapper,
|
|
63
|
-
} = options;
|
|
64
|
-
|
|
65
|
-
// Create mock controller with fixtures
|
|
66
|
-
const MockControllerClass = MockController(
|
|
67
|
-
Controller,
|
|
68
|
-
resolverFixtures ?
|
|
69
|
-
{
|
|
70
|
-
fixtures: [...resolverFixtures],
|
|
71
|
-
getInitialInterceptorData,
|
|
72
|
-
}
|
|
73
|
-
: {},
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// Create managers
|
|
77
|
-
const nm = new NetworkManager();
|
|
78
|
-
const sm = new SubscriptionManager(PollingSubscription);
|
|
79
|
-
const defaultManagers = [nm, sm];
|
|
80
|
-
const finalManagers = managers ?? defaultManagers;
|
|
81
|
-
|
|
82
|
-
// Create initial state
|
|
83
|
-
const mockState = mockInitialState([...initialFixtures]);
|
|
84
|
-
const finalInitialState = initialState ?? mockState;
|
|
85
|
-
|
|
86
|
-
// Create a wrapper component that provides the data client context
|
|
87
|
-
const DataClientWrapper = defineComponent({
|
|
88
|
-
name: 'DataClientWrapper',
|
|
89
|
-
setup(_, { expose }) {
|
|
90
|
-
// Inject the controller provided by the plugin
|
|
91
|
-
const controller = inject(ControllerKey) as Controller;
|
|
92
|
-
|
|
93
|
-
// Create a reactive props object that will be updated when setProps is called
|
|
94
|
-
const componentProps = ref(initialProps || {});
|
|
95
|
-
|
|
96
|
-
// Expose controller and props updater for testing
|
|
97
|
-
expose({
|
|
98
|
-
controller,
|
|
99
|
-
updateProps: (newProps: any) => {
|
|
100
|
-
// Update the ref value to trigger reactivity
|
|
101
|
-
componentProps.value = { ...newProps };
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return () => {
|
|
106
|
-
// Use key on the component to force re-mount when props change
|
|
107
|
-
// This ensures setup() is re-run with new props
|
|
108
|
-
const componentKey = JSON.stringify(componentProps.value);
|
|
109
|
-
const innerComponent =
|
|
110
|
-
wrapper ?
|
|
111
|
-
h(wrapper, { ...componentProps.value, key: componentKey }, () =>
|
|
112
|
-
h(component, { ...componentProps.value, key: componentKey }),
|
|
113
|
-
)
|
|
114
|
-
: h(component, { ...componentProps.value, key: componentKey });
|
|
115
|
-
|
|
116
|
-
return h(
|
|
117
|
-
Suspense,
|
|
118
|
-
{},
|
|
119
|
-
{
|
|
120
|
-
default: () => innerComponent,
|
|
121
|
-
fallback: () =>
|
|
122
|
-
h('div', { 'data-testid': 'suspense-fallback' }, 'Loading...'),
|
|
123
|
-
},
|
|
124
|
-
);
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Mount the wrapper with DataClientPlugin
|
|
130
|
-
const wrapper_instance = mount(DataClientWrapper, {
|
|
131
|
-
global: {
|
|
132
|
-
plugins: [
|
|
133
|
-
[
|
|
134
|
-
DataClientPlugin,
|
|
135
|
-
{
|
|
136
|
-
managers: finalManagers,
|
|
137
|
-
initialState: finalInitialState,
|
|
138
|
-
Controller: MockControllerClass,
|
|
139
|
-
gcPolicy,
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Get controller and updateProps from the wrapper
|
|
147
|
-
const controller = (wrapper_instance.vm as any).controller;
|
|
148
|
-
const updateProps = (wrapper_instance.vm as any).updateProps;
|
|
149
|
-
|
|
150
|
-
// Override setProps to trigger reactive updates
|
|
151
|
-
wrapper_instance.setProps = async (props: any) => {
|
|
152
|
-
updateProps(props);
|
|
153
|
-
await nextTick();
|
|
154
|
-
// Force a re-render by awaiting next tick again
|
|
155
|
-
await nextTick();
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
// Cleanup function
|
|
159
|
-
const cleanup = () => {
|
|
160
|
-
nm.cleanupDate = Infinity;
|
|
161
|
-
if ((nm as any)['rejectors']) {
|
|
162
|
-
Object.values((nm as any)['rejectors'] as Record<string, any>).forEach(
|
|
163
|
-
(rej: any) => {
|
|
164
|
-
rej();
|
|
165
|
-
},
|
|
166
|
-
);
|
|
167
|
-
} else if (nm['fetching']) {
|
|
168
|
-
nm['fetching'].forEach(({ reject }: any) => reject());
|
|
169
|
-
}
|
|
170
|
-
nm['clearAll']();
|
|
171
|
-
finalManagers.forEach(manager => manager.cleanup());
|
|
172
|
-
wrapper_instance.unmount();
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// All settled function
|
|
176
|
-
const allSettled = (): Promise<PromiseSettledResult<unknown>[]> => {
|
|
177
|
-
return nm.allSettled() ?? Promise.resolve([]);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
wrapper: wrapper_instance,
|
|
182
|
-
controller,
|
|
183
|
-
app: wrapper_instance.vm,
|
|
184
|
-
cleanup,
|
|
185
|
-
allSettled,
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Renders a Vue composable with DataClient provider for testing
|
|
191
|
-
* Similar to renderDataHook from @data-client/test but for Vue composables
|
|
192
|
-
*/
|
|
193
|
-
export function renderDataComposable<P = any, R = any>(
|
|
194
|
-
composable: (props: P) => R,
|
|
195
|
-
options: RenderDataClientOptions<P> = {},
|
|
196
|
-
): {
|
|
197
|
-
result: { current: R | undefined };
|
|
198
|
-
wrapper: VueWrapper<any>;
|
|
199
|
-
controller: Controller;
|
|
200
|
-
cleanup: () => void;
|
|
201
|
-
allSettled: () => Promise<PromiseSettledResult<unknown>[]>;
|
|
202
|
-
waitForNextUpdate: () => Promise<void>;
|
|
203
|
-
} {
|
|
204
|
-
let resultRef: any;
|
|
205
|
-
let resolveNextUpdate: (() => void) | null = null;
|
|
206
|
-
|
|
207
|
-
const TestComponent = defineComponent({
|
|
208
|
-
name: 'TestComposableComponent',
|
|
209
|
-
props: {
|
|
210
|
-
composableProps: {
|
|
211
|
-
type: Object,
|
|
212
|
-
default: () => ({}),
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
setup(props, { expose }) {
|
|
216
|
-
// Create the result ref inside the component
|
|
217
|
-
resultRef = ref<R | undefined>(undefined);
|
|
218
|
-
|
|
219
|
-
// Call the composable with reactive props - Vue's useSuspense will handle the async behavior
|
|
220
|
-
const composableValue = composable(props.composableProps as P);
|
|
221
|
-
|
|
222
|
-
// If composable returns a Promise, we're suspended - keep result as undefined initially
|
|
223
|
-
if (composableValue instanceof Promise) {
|
|
224
|
-
resultRef.value = undefined;
|
|
225
|
-
|
|
226
|
-
// Wait for the Promise to resolve, then set the result to the Promise itself
|
|
227
|
-
composableValue
|
|
228
|
-
.then(() => {
|
|
229
|
-
resultRef.value = composableValue; // Set to the Promise, not the resolved value
|
|
230
|
-
if (resolveNextUpdate) {
|
|
231
|
-
resolveNextUpdate();
|
|
232
|
-
resolveNextUpdate = null;
|
|
233
|
-
}
|
|
234
|
-
})
|
|
235
|
-
.catch(() => {
|
|
236
|
-
// Even on error, we're no longer suspended
|
|
237
|
-
resultRef.value = undefined;
|
|
238
|
-
if (resolveNextUpdate) {
|
|
239
|
-
resolveNextUpdate();
|
|
240
|
-
resolveNextUpdate = null;
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
} else {
|
|
244
|
-
// If composable returns a value directly, we're not suspended
|
|
245
|
-
resultRef.value = composableValue;
|
|
246
|
-
if (resolveNextUpdate) {
|
|
247
|
-
resolveNextUpdate();
|
|
248
|
-
resolveNextUpdate = null;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Watch for changes to the result
|
|
253
|
-
watch(resultRef, newValue => {
|
|
254
|
-
if (newValue !== undefined && resolveNextUpdate) {
|
|
255
|
-
resolveNextUpdate();
|
|
256
|
-
resolveNextUpdate = null;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
expose({ result: resultRef.value });
|
|
261
|
-
return { result: resultRef.value };
|
|
262
|
-
},
|
|
263
|
-
render() {
|
|
264
|
-
return h('div', { 'data-testid': 'composable-result' });
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// Wrap the component to accept composableProps
|
|
269
|
-
const WrappedTestComponent = defineComponent({
|
|
270
|
-
name: 'WrappedTestComponent',
|
|
271
|
-
setup() {
|
|
272
|
-
const composableProps = ref(options.initialProps || {});
|
|
273
|
-
|
|
274
|
-
return () => h(TestComponent, { composableProps: composableProps.value });
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const { wrapper, controller, cleanup, allSettled } = renderDataClient(
|
|
279
|
-
WrappedTestComponent,
|
|
280
|
-
options,
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
const waitForNextUpdate = (): Promise<void> => {
|
|
284
|
-
return new Promise(resolve => {
|
|
285
|
-
// If result is already available, resolve immediately
|
|
286
|
-
if (resultRef.value !== undefined) {
|
|
287
|
-
resolve();
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Otherwise, wait for the result to be set
|
|
292
|
-
resolveNextUpdate = resolve;
|
|
293
|
-
|
|
294
|
-
// Also set up a timeout to prevent hanging
|
|
295
|
-
setTimeout(() => {
|
|
296
|
-
if (resolveNextUpdate === resolve) {
|
|
297
|
-
resolveNextUpdate = null;
|
|
298
|
-
resolve();
|
|
299
|
-
}
|
|
300
|
-
}, 1000);
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
return {
|
|
305
|
-
result: {
|
|
306
|
-
get current() {
|
|
307
|
-
return resultRef?.value;
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
wrapper,
|
|
311
|
-
controller,
|
|
312
|
-
cleanup,
|
|
313
|
-
allSettled,
|
|
314
|
-
waitForNextUpdate,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { default as useSuspense } from './useSuspense.js';
|
|
2
|
-
export { default as useSubscription } from './useSubscription.js';
|
|
3
|
-
export { default as useQuery } from './useQuery.js';
|
|
4
|
-
export { default as useLive } from './useLive.js';
|
|
5
|
-
export { default as useLoading } from './useLoading.js';
|
|
6
|
-
export { default as useDebounce } from './useDebounce.js';
|
|
7
|
-
export { default as useFetch } from './useFetch.js';
|
|
8
|
-
export { useController as useController } from '../context.js';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Ref } from 'vue';
|
|
2
|
-
/**
|
|
3
|
-
* Keeps value updated after delay time
|
|
4
|
-
*
|
|
5
|
-
* @see https://dataclient.io/docs/api/useDebounce
|
|
6
|
-
* @param value Any immutable value (can be a ref)
|
|
7
|
-
* @param delay Time in milliseconds to wait til updating the value
|
|
8
|
-
* @param updatable Whether to update at all
|
|
9
|
-
* @example
|
|
10
|
-
```
|
|
11
|
-
const [debouncedQuery, isPending] = useDebounce(query, 200);
|
|
12
|
-
const list = useSuspense(getThings, { query: debouncedQuery.value });
|
|
13
|
-
```
|
|
14
|
-
*/
|
|
15
|
-
export default function useDebounce<T>(value: T | Ref<T>, delay: number, updatable?: boolean | Ref<boolean>): [
|
|
16
|
-
Ref<T>,
|
|
17
|
-
Ref<boolean>
|
|
18
|
-
];
|
|
19
|
-
//# sourceMappingURL=useDebounce.d.ts.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EndpointInterface, Denormalize, Schema, FetchFunction, DenormalizeNullable } from '@data-client/core';
|
|
2
|
-
/**
|
|
3
|
-
* Fetch an Endpoint if it is not in cache or stale.
|
|
4
|
-
* Non-suspense; returns the fetch Promise when a request is issued, otherwise undefined.
|
|
5
|
-
* Mirrors React useFetch semantics.
|
|
6
|
-
* @see https://dataclient.io/docs/api/useFetch
|
|
7
|
-
*/
|
|
8
|
-
export default function useFetch<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
9
|
-
...Parameters<E>
|
|
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 [
|
|
14
|
-
null
|
|
15
|
-
]): E['schema'] extends undefined | null ? ReturnType<E> | undefined : Promise<DenormalizeNullable<E['schema']>> | undefined;
|
|
16
|
-
//# sourceMappingURL=useFetch.d.ts.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { EndpointInterface, Denormalize, Schema, FetchFunction, ResolveType, DenormalizeNullable } from '@data-client/core';
|
|
2
|
-
import { DeepReadonly, ComputedRef } from 'vue';
|
|
3
|
-
/**
|
|
4
|
-
* Ensure an endpoint is available. Keeps it fresh once it is.
|
|
5
|
-
*
|
|
6
|
-
* useSuspense() + useSubscription()
|
|
7
|
-
* @see https://dataclient.io/docs/api/useLive
|
|
8
|
-
* @throws {Promise} If data is not yet available.
|
|
9
|
-
* @throws {NetworkError} If fetch fails.
|
|
10
|
-
*/
|
|
11
|
-
export default function useLive<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
12
|
-
...Parameters<E>
|
|
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 [
|
|
17
|
-
null
|
|
18
|
-
]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> | undefined : DenormalizeNullable<E['schema']>>>>;
|
|
19
|
-
//# sourceMappingURL=useLive.d.ts.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Ref } from 'vue';
|
|
2
|
-
/**
|
|
3
|
-
* Takes an async function and tracks resolution as a boolean.
|
|
4
|
-
*
|
|
5
|
-
* @see https://dataclient.io/docs/api/useLoading
|
|
6
|
-
* @param func A function returning a promise
|
|
7
|
-
* @example
|
|
8
|
-
```
|
|
9
|
-
function Button({ onClick, children, ...props }) {
|
|
10
|
-
const [clickHandler, loading] = useLoading(onClick);
|
|
11
|
-
return h('button', { onClick: clickHandler, ...props },
|
|
12
|
-
loading.value ? 'Loading...' : children
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
*/
|
|
17
|
-
export default function useLoading<F extends (...args: any) => Promise<any>>(func: F): [
|
|
18
|
-
F,
|
|
19
|
-
Ref<boolean>,
|
|
20
|
-
Ref<Error | undefined>
|
|
21
|
-
];
|
|
22
|
-
//# sourceMappingURL=useLoading.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DenormalizeNullable, NI, Queryable, SchemaArgs } from '@data-client/core';
|
|
2
|
-
import { ComputedRef } from 'vue';
|
|
3
|
-
/**
|
|
4
|
-
* Query the store (non-suspense).
|
|
5
|
-
*
|
|
6
|
-
* Returns a readonly computed ref of the query result. The value is undefined when
|
|
7
|
-
* the result is not found or invalid.
|
|
8
|
-
* Mirrors React's useQuery semantics using Vue reactivity.
|
|
9
|
-
* @see https://dataclient.io/docs/api/useQuery
|
|
10
|
-
*/
|
|
11
|
-
export default function useQuery<S extends Queryable>(schema: S, ...args: NI<SchemaArgs<S>>): ComputedRef<DenormalizeNullable<S> | undefined>;
|
|
12
|
-
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EndpointInterface, Schema, FetchFunction } from '@data-client/core';
|
|
2
|
-
/**
|
|
3
|
-
* Keeps a resource fresh by subscribing to updates.
|
|
4
|
-
* Mirrors React hook API. Pass `null` as first arg to unsubscribe.
|
|
5
|
-
* @see https://dataclient.io/docs/api/useSubscription
|
|
6
|
-
*/
|
|
7
|
-
export default function useSubscription<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
8
|
-
...Parameters<E>
|
|
9
|
-
] | readonly [
|
|
10
|
-
null
|
|
11
|
-
]): void;
|
|
12
|
-
//# sourceMappingURL=useSubscription.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { EndpointInterface, Denormalize, Schema, FetchFunction, DenormalizeNullable, ResolveType } from '@data-client/core';
|
|
2
|
-
import { DeepReadonly, ComputedRef } from 'vue';
|
|
3
|
-
export default function useSuspense<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
4
|
-
...Parameters<E>
|
|
5
|
-
]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> : Denormalize<E['schema']>>>>;
|
|
6
|
-
export default function useSuspense<E extends EndpointInterface<FetchFunction, Schema | undefined, undefined | false>>(endpoint: E, ...args: readonly [
|
|
7
|
-
...Parameters<E>
|
|
8
|
-
] | readonly [
|
|
9
|
-
null
|
|
10
|
-
]): Promise<DeepReadonly<ComputedRef<E['schema'] extends undefined | null ? ResolveType<E> | undefined : DenormalizeNullable<E['schema']>>>>;
|
|
11
|
-
//# sourceMappingURL=useSuspense.d.ts.map
|
package/ts3.4/context.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Controller } from '@data-client/core';
|
|
2
|
-
import { State } from '@data-client/core';
|
|
3
|
-
import { InjectionKey, ShallowRef } from 'vue';
|
|
4
|
-
export declare const StateKey: InjectionKey<ShallowRef<State<unknown>>>;
|
|
5
|
-
export declare const ControllerKey: InjectionKey<Controller>;
|
|
6
|
-
/** Fallback state ref used when no provider is found. */
|
|
7
|
-
export declare const FallbackStateRef: ShallowRef<State<unknown>>;
|
|
8
|
-
export declare function useController(): Controller;
|
|
9
|
-
export declare function injectState(): ShallowRef<State<unknown>>;
|
|
10
|
-
//# sourceMappingURL=context.d.ts.map
|
package/ts3.4/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { Controller, ExpiryStatus, actionTypes } from '@data-client/core';
|
|
2
|
-
export { EndpointExtraOptions, FetchFunction, ResolveType, EndpointInterface, EntityInterface, Queryable, SchemaArgs, Schema, SchemaClass, DenormalizeNullable, Denormalize, Normalize, NormalizeNullable, FetchAction, InvalidateAction, UnsubscribeAction, SubscribeAction, ResetAction, SetAction, SetResponseAction, ActionTypes, NetworkError, UnknownError, ErrorTypes, AbstractInstanceType, UpdateFunction, State, PK, Dispatch, Middleware, MiddlewareAPI, Manager, GCInterface, GCOptions, CreateCountRef, DataClientDispatch, GenericDispatch, } from '@data-client/core';
|
|
3
|
-
export * from './consumers/index.js';
|
|
4
|
-
export * from './providers/index.js';
|
|
5
|
-
export * from './managers/index.js';
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { App } from 'vue';
|
|
2
|
-
import { ProvideOptions } from './createDataClient.js';
|
|
3
|
-
/**
|
|
4
|
-
* Vue 3 Plugin for Reactive Data Client
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { createApp } from 'vue';
|
|
9
|
-
* import { DataClientPlugin } from '@data-client/vue';
|
|
10
|
-
*
|
|
11
|
-
* const app = createApp(App);
|
|
12
|
-
* app.use(DataClientPlugin, {
|
|
13
|
-
* managers: getDefaultManagers(),
|
|
14
|
-
* initialState: customInitialState,
|
|
15
|
-
* });
|
|
16
|
-
* app.mount('#app');
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare const DataClientPlugin: {
|
|
20
|
-
install(app: App, options?: ProvideOptions): import("./createDataClient.js").ProvidedDataClient;
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=DataClientPlugin.d.ts.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Controller as DataController } from '@data-client/core';
|
|
2
|
-
import { State, Manager, GCInterface } from '@data-client/core';
|
|
3
|
-
import { ShallowRef, App } from 'vue';
|
|
4
|
-
export interface ProvideOptions {
|
|
5
|
-
managers?: Manager[];
|
|
6
|
-
initialState?: State<unknown>;
|
|
7
|
-
Controller?: typeof DataController;
|
|
8
|
-
gcPolicy?: GCInterface;
|
|
9
|
-
app?: App;
|
|
10
|
-
}
|
|
11
|
-
export interface ProvidedDataClient {
|
|
12
|
-
controller: InstanceType<typeof DataController>;
|
|
13
|
-
/** Optimistic overlay state ref provided to consumers */
|
|
14
|
-
stateRef: ShallowRef<State<unknown>>;
|
|
15
|
-
/** Start the provider (called on mount) */
|
|
16
|
-
start: () => void;
|
|
17
|
-
/** Stop the provider (called on unmount) */
|
|
18
|
-
stop: () => void;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Core provider logic that can be used by both composable and plugin.
|
|
22
|
-
* This function handles the actual setup of the data client without Vue-specific concerns.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createDataClient(options?: ProvideOptions): ProvidedDataClient;
|
|
25
|
-
//# sourceMappingURL=createDataClient.d.ts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DevToolsConfig, Manager } from '@data-client/core';
|
|
2
|
-
import { NetworkManager, SubscriptionManager, DevToolsManager } from '@data-client/core';
|
|
3
|
-
/** Returns the default Managers used by DataProvider. */
|
|
4
|
-
declare let getDefaultManagers: (options?: GetManagersOptions) => Manager[];
|
|
5
|
-
export { getDefaultManagers };
|
|
6
|
-
export type GetManagersOptions = {
|
|
7
|
-
devToolsManager?: DevToolsManager | DevToolsConfig | null;
|
|
8
|
-
networkManager?: NetworkManager | ConstructorArgs<typeof NetworkManager> | null;
|
|
9
|
-
subscriptionManager?: SubscriptionManager | ConstructorArgs<typeof SubscriptionManager> | null;
|
|
10
|
-
};
|
|
11
|
-
export type ConstructorArgs<T extends {
|
|
12
|
-
new (...args: any): any;
|
|
13
|
-
}> = T extends new (options: infer O) => any ? O : never;
|
|
14
|
-
//# sourceMappingURL=getDefaultManagers.d.ts.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Controller } from '@data-client/core';
|
|
2
|
-
import { Fixture, Interceptor } from './fixtureTypes';
|
|
3
|
-
export interface MockProps<T = any> {
|
|
4
|
-
fixtures?: (Fixture | Interceptor<T>)[];
|
|
5
|
-
getInitialInterceptorData?: () => T;
|
|
6
|
-
}
|
|
7
|
-
export default function MockController<TBase extends typeof Controller, T>(Base: TBase, { fixtures, getInitialInterceptorData, }?: MockProps<T>): TBase;
|
|
8
|
-
//# sourceMappingURL=MockController.d.ts.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Fixture, ResponseInterceptor } from './fixtureTypes';
|
|
2
|
-
export declare function collapseFixture(fixture: Fixture | ResponseInterceptor, args: any[], interceptorData: any): Promise<{
|
|
3
|
-
response: any;
|
|
4
|
-
error: boolean | undefined;
|
|
5
|
-
}>;
|
|
6
|
-
//# sourceMappingURL=collapseFixture.d.ts.map
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { EndpointInterface, ResolveType } from '@data-client/core';
|
|
2
|
-
type Updater = (result: any, ...args: any) => Record<string, (...args: any) => any>;
|
|
3
|
-
export interface SuccessFixtureEndpoint<E extends EndpointInterface & {
|
|
4
|
-
update?: Updater;
|
|
5
|
-
} = EndpointInterface> {
|
|
6
|
-
readonly endpoint: E;
|
|
7
|
-
readonly args: Parameters<E>;
|
|
8
|
-
readonly response: ResolveType<E> | ((...args: Parameters<E>) => ResolveType<E>);
|
|
9
|
-
readonly error?: false;
|
|
10
|
-
/** Number of miliseconds to wait before resolving */
|
|
11
|
-
readonly delay?: number;
|
|
12
|
-
/** Waits to run `response()` after `delay` time */
|
|
13
|
-
readonly delayCollapse?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export interface ResponseInterceptor<T = any, E extends EndpointInterface & {
|
|
16
|
-
update?: Updater;
|
|
17
|
-
testKey(key: string): boolean;
|
|
18
|
-
} = EndpointInterface & {
|
|
19
|
-
testKey(key: string): boolean;
|
|
20
|
-
}> {
|
|
21
|
-
readonly endpoint: E;
|
|
22
|
-
response(this: T, ...args: Parameters<E>): ResolveType<E>;
|
|
23
|
-
/** Number of miliseconds (or function that returns) to wait before resolving */
|
|
24
|
-
readonly delay?: number | ((...args: Parameters<E>) => number);
|
|
25
|
-
/** Waits to run `response()` after `delay` time */
|
|
26
|
-
readonly delayCollapse?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export interface FetchInterceptor<T = any, E extends EndpointInterface & {
|
|
29
|
-
update?: Updater;
|
|
30
|
-
testKey(key: string): boolean;
|
|
31
|
-
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
32
|
-
extend(options: any): any;
|
|
33
|
-
} = EndpointInterface & {
|
|
34
|
-
testKey(key: string): boolean;
|
|
35
|
-
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
36
|
-
extend(options: any): any;
|
|
37
|
-
}> {
|
|
38
|
-
readonly endpoint: E;
|
|
39
|
-
fetchResponse(this: T, input: RequestInfo, init: RequestInit): ResolveType<E>;
|
|
40
|
-
/** Number of miliseconds (or function that returns) to wait before resolving */
|
|
41
|
-
readonly delay?: number | ((...args: Parameters<E>) => number);
|
|
42
|
-
/** Waits to run `response()` after `delay` time */
|
|
43
|
-
readonly delayCollapse?: boolean;
|
|
44
|
-
}
|
|
45
|
-
/** Interceptors match and compute dynamic responses based on args
|
|
46
|
-
*
|
|
47
|
-
* @see https://dataclient.io/docs/api/Fixtures#interceptor
|
|
48
|
-
*/
|
|
49
|
-
export type Interceptor<T = any, E extends EndpointInterface & {
|
|
50
|
-
update?: Updater;
|
|
51
|
-
testKey(key: string): boolean;
|
|
52
|
-
fetchResponse?(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
53
|
-
extend?(options: any): any;
|
|
54
|
-
} = EndpointInterface & {
|
|
55
|
-
testKey(key: string): boolean;
|
|
56
|
-
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
57
|
-
extend(options: any): any;
|
|
58
|
-
}> = ResponseInterceptor<T, E> | (E extends ({
|
|
59
|
-
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
60
|
-
extend(options: any): any;
|
|
61
|
-
}) ? FetchInterceptor<T, E> : never);
|
|
62
|
-
export interface ErrorFixtureEndpoint<E extends EndpointInterface & {
|
|
63
|
-
update?: Updater;
|
|
64
|
-
} = EndpointInterface> {
|
|
65
|
-
readonly endpoint: E;
|
|
66
|
-
readonly args: Parameters<E>;
|
|
67
|
-
readonly response: any;
|
|
68
|
-
readonly error: true;
|
|
69
|
-
/** Number of miliseconds to wait before resolving */
|
|
70
|
-
readonly delay?: number;
|
|
71
|
-
/** Waits to run `response()` after `delay` time */
|
|
72
|
-
readonly delayCollapse?: boolean;
|
|
73
|
-
}
|
|
74
|
-
export type FixtureEndpoint<E extends EndpointInterface & {
|
|
75
|
-
update?: Updater;
|
|
76
|
-
} = EndpointInterface> = SuccessFixtureEndpoint<E> | ErrorFixtureEndpoint<E>;
|
|
77
|
-
/** Represents a successful response
|
|
78
|
-
*
|
|
79
|
-
* @see https://dataclient.io/docs/api/Fixtures#successfixture
|
|
80
|
-
*/
|
|
81
|
-
export type SuccessFixture<E extends EndpointInterface & {
|
|
82
|
-
update?: Updater;
|
|
83
|
-
} = EndpointInterface> = SuccessFixtureEndpoint<E>;
|
|
84
|
-
/** Represents a failed/errored response
|
|
85
|
-
*
|
|
86
|
-
* @see https://dataclient.io/docs/api/Fixtures#errorfixtures
|
|
87
|
-
*/
|
|
88
|
-
export type ErrorFixture<E extends EndpointInterface & {
|
|
89
|
-
update?: Updater;
|
|
90
|
-
} = EndpointInterface> = ErrorFixtureEndpoint<E>;
|
|
91
|
-
/** Represents a static response
|
|
92
|
-
*
|
|
93
|
-
* @see https://dataclient.io/docs/api/Fixtures
|
|
94
|
-
*/
|
|
95
|
-
export type Fixture<E extends EndpointInterface & {
|
|
96
|
-
update?: Updater;
|
|
97
|
-
} = EndpointInterface> = FixtureEndpoint<E>;
|
|
98
|
-
export {};
|
|
99
|
-
//# sourceMappingURL=fixtureTypes.d.ts.map
|