@effect-app/vue 4.0.0-beta.175 → 4.0.0-beta.177
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/CHANGELOG.md +15 -0
- package/dist/makeClient.d.ts +20 -15
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +30 -9
- package/dist/mutate.d.ts +13 -13
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +9 -7
- package/package.json +2 -2
- package/src/makeClient.ts +64 -38
- package/src/mutate.ts +37 -26
- package/test/dist/stubs.d.ts +706 -46
- package/test/dist/stubs.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-app/vue",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.177",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/effect-ts-app/libs/tree/main/packages/vue",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@vueuse/core": "^14.2.1",
|
|
12
12
|
"change-case": "^5.4.4",
|
|
13
13
|
"query-string": "^9.3.1",
|
|
14
|
-
"effect-app": "4.0.0-beta.
|
|
14
|
+
"effect-app": "4.0.0-beta.177"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@effect/atom-vue": "^4.0.0-beta.59",
|
package/src/makeClient.ts
CHANGED
|
@@ -148,8 +148,15 @@ export interface MutationExtWithInput<
|
|
|
148
148
|
* Namespace invalidation targets parent namespace keys
|
|
149
149
|
* (for example `$project/$configuration.get` invalidates `$project`).
|
|
150
150
|
* Override invalidation in client options via `queryInvalidation`.
|
|
151
|
+
*
|
|
152
|
+
* Pass `options` to attach a `select` Effect that runs after the mutation
|
|
153
|
+
* succeeds (its output is returned to the caller) and/or override the default
|
|
154
|
+
* `queryInvalidation`.
|
|
151
155
|
*/
|
|
152
|
-
|
|
156
|
+
<B = A, E2 = never, R2 = never>(
|
|
157
|
+
input: I,
|
|
158
|
+
options?: MutationOptionsBase<A, B, E2, R2>
|
|
159
|
+
): Effect.Effect<B, E | E2, R | R2>
|
|
153
160
|
|
|
154
161
|
project: <ProjSchema extends S.Top>(
|
|
155
162
|
schema: EA extends ProjSchema["Encoded"] ? ProjSchema : never
|
|
@@ -178,7 +185,19 @@ export interface MutationExt<
|
|
|
178
185
|
E,
|
|
179
186
|
R,
|
|
180
187
|
EA = unknown
|
|
181
|
-
> extends MutationExtensions<RT, Id, void, A, E, R
|
|
188
|
+
> extends MutationExtensions<RT, Id, void, A, E, R> {
|
|
189
|
+
/**
|
|
190
|
+
* Send the request to the endpoint and return the raw Effect response.
|
|
191
|
+
* Also invalidates query caches using the request namespace by default.
|
|
192
|
+
*
|
|
193
|
+
* Pass `options` to attach a `select` Effect that runs after the mutation
|
|
194
|
+
* succeeds (its output is returned to the caller) and/or override the default
|
|
195
|
+
* `queryInvalidation`.
|
|
196
|
+
*/
|
|
197
|
+
<B = A, E2 = never, R2 = never>(
|
|
198
|
+
options?: MutationOptionsBase<A, B, E2, R2>
|
|
199
|
+
): Effect.Effect<B, E | E2, R | R2>
|
|
200
|
+
|
|
182
201
|
project: <ProjSchema extends S.Top>(
|
|
183
202
|
schema: EA extends ProjSchema["Encoded"] ? ProjSchema : never
|
|
184
203
|
) => MutationExt<
|
|
@@ -295,32 +314,33 @@ export type Queries<RT, Req> = Req extends
|
|
|
295
314
|
|
|
296
315
|
const _useMutation = makeMutation()
|
|
297
316
|
|
|
317
|
+
const wrapWithSpan = (self: { id: string; handler: any }, mut: any) => {
|
|
318
|
+
const span = (eff: Effect.Effect<any, any, any>) =>
|
|
319
|
+
Effect.withSpan(`mutation ${self.id}`, {}, { captureStackTrace: false })(eff)
|
|
320
|
+
return Effect.isEffect(self.handler)
|
|
321
|
+
? (options?: MutationOptionsBase) => span(mut(options))
|
|
322
|
+
: (input: any, options?: MutationOptionsBase) => span(mut(input, options))
|
|
323
|
+
}
|
|
324
|
+
|
|
298
325
|
/**
|
|
299
326
|
* Pass an Effect or a function that returns an Effect, e.g from a client action
|
|
300
327
|
* Executes query cache invalidation based on default rules or provided option.
|
|
301
328
|
* adds a span with the mutation id
|
|
302
329
|
*/
|
|
303
|
-
export const useMutation: typeof _useMutation = <
|
|
330
|
+
export const useMutation: typeof _useMutation = (<
|
|
304
331
|
I,
|
|
305
332
|
E,
|
|
306
333
|
A,
|
|
307
334
|
R,
|
|
308
335
|
Request extends Req,
|
|
309
|
-
Name extends string
|
|
310
|
-
B = A,
|
|
311
|
-
E2 = never,
|
|
312
|
-
R2 = never
|
|
336
|
+
Name extends string
|
|
313
337
|
>(
|
|
314
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name
|
|
315
|
-
options?: MutationOptionsBase<A, B, E2, R2>
|
|
338
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name>
|
|
316
339
|
) =>
|
|
317
340
|
Object.assign(
|
|
318
|
-
|
|
319
|
-
_useMutation(self as any, options),
|
|
320
|
-
Effect.withSpan(`mutation ${self.id}`, {}, { captureStackTrace: false })
|
|
321
|
-
) as any,
|
|
341
|
+
wrapWithSpan(self, _useMutation(self as any)),
|
|
322
342
|
{ id: self.id }
|
|
323
|
-
)
|
|
343
|
+
)) as any
|
|
324
344
|
|
|
325
345
|
/**
|
|
326
346
|
* Pass an Effect or a function that returns an Effect, e.g from a client action
|
|
@@ -329,27 +349,20 @@ export const useMutation: typeof _useMutation = <
|
|
|
329
349
|
*/
|
|
330
350
|
export const useMutationInt = (): typeof _useMutation => {
|
|
331
351
|
const _useMutation = useMakeMutation()
|
|
332
|
-
return <
|
|
352
|
+
return (<
|
|
333
353
|
I,
|
|
334
354
|
E,
|
|
335
355
|
A,
|
|
336
356
|
R,
|
|
337
357
|
Request extends Req,
|
|
338
|
-
Name extends string
|
|
339
|
-
B = A,
|
|
340
|
-
E2 = never,
|
|
341
|
-
R2 = never
|
|
358
|
+
Name extends string
|
|
342
359
|
>(
|
|
343
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name
|
|
344
|
-
options?: MutationOptionsBase<A, B, E2, R2>
|
|
360
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name>
|
|
345
361
|
) =>
|
|
346
362
|
Object.assign(
|
|
347
|
-
|
|
348
|
-
_useMutation(self as any, options),
|
|
349
|
-
Effect.withSpan(`mutation ${self.id}`, {}, { captureStackTrace: false })
|
|
350
|
-
) as any,
|
|
363
|
+
wrapWithSpan(self, _useMutation(self as any)),
|
|
351
364
|
{ id: self.id }
|
|
352
|
-
)
|
|
365
|
+
)) as any
|
|
353
366
|
}
|
|
354
367
|
|
|
355
368
|
export type ClientFrom<M extends RequestsAny> = RequestHandlers<never, never, M, ExtractModuleName<M>>
|
|
@@ -575,6 +588,23 @@ export const makeClient = <RT_, RTHooks>(
|
|
|
575
588
|
]
|
|
576
589
|
}
|
|
577
590
|
|
|
591
|
+
const withDefaultInvalidation = (
|
|
592
|
+
mut: any,
|
|
593
|
+
isWithInput: boolean,
|
|
594
|
+
defaultInvalidation?: MutationOptionsBase["queryInvalidation"]
|
|
595
|
+
) => {
|
|
596
|
+
if (!defaultInvalidation) return mut
|
|
597
|
+
const apply = (callerOpts?: MutationOptionsBase) => ({
|
|
598
|
+
...callerOpts,
|
|
599
|
+
queryInvalidation: callerOpts?.queryInvalidation
|
|
600
|
+
? mergeInvalidation(defaultInvalidation, callerOpts.queryInvalidation)
|
|
601
|
+
: defaultInvalidation
|
|
602
|
+
})
|
|
603
|
+
return isWithInput
|
|
604
|
+
? (input: any, callerOpts?: MutationOptionsBase) => mut(input, apply(callerOpts))
|
|
605
|
+
: (callerOpts?: MutationOptionsBase) => mut(apply(callerOpts))
|
|
606
|
+
}
|
|
607
|
+
|
|
578
608
|
const makeQueryResources = <Resources extends InvalidationResources>(resources: Resources | undefined) => {
|
|
579
609
|
if (!resources) {
|
|
580
610
|
return {} as Record<string, Record<string, unknown>>
|
|
@@ -667,7 +697,7 @@ export const makeClient = <RT_, RTHooks>(
|
|
|
667
697
|
if (client[key].Request.type !== "command") {
|
|
668
698
|
return acc
|
|
669
699
|
}
|
|
670
|
-
const fromRequestConfig = client[key].Request.config?.invalidatesQueries as
|
|
700
|
+
const fromRequestConfig = client[key].Request.config?.["invalidatesQueries"] as
|
|
671
701
|
| InvalidationCallback<InvalidationResourcesFor<M>>
|
|
672
702
|
| undefined
|
|
673
703
|
const fromRequest = fromRequestConfig
|
|
@@ -679,11 +709,9 @@ export const makeClient = <RT_, RTHooks>(
|
|
|
679
709
|
: undefined
|
|
680
710
|
const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key])
|
|
681
711
|
const makeProjectedMutation = (handler: any): any => {
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
)
|
|
686
|
-
const wrap = Command.wrap({ mutate: Effect.isEffect(mut) ? () => mut : mut, id: client[key].id })
|
|
712
|
+
const isWithInput = !Effect.isEffect(handler.handler)
|
|
713
|
+
const mut: any = withDefaultInvalidation(mutation(handler), isWithInput, mergedInvalidation)
|
|
714
|
+
const wrap = Command.wrap({ mutate: mut, id: client[key].id })
|
|
687
715
|
return Object.assign(mut, {
|
|
688
716
|
wrap,
|
|
689
717
|
project: (projectionSchema: any) => {
|
|
@@ -760,7 +788,7 @@ export const makeClient = <RT_, RTHooks>(
|
|
|
760
788
|
}
|
|
761
789
|
: {
|
|
762
790
|
mutate: ((handler: any) => {
|
|
763
|
-
const fromRequestConfig = client[key].Request.config?.invalidatesQueries as
|
|
791
|
+
const fromRequestConfig = client[key].Request.config?.["invalidatesQueries"] as
|
|
764
792
|
| InvalidationCallback<InvalidationResourcesFor<M>>
|
|
765
793
|
| undefined
|
|
766
794
|
const fromRequest = fromRequestConfig
|
|
@@ -774,15 +802,13 @@ export const makeClient = <RT_, RTHooks>(
|
|
|
774
802
|
: undefined
|
|
775
803
|
const mergedInvalidation = mergeInvalidation(fromRequest, invalidation?.[key])
|
|
776
804
|
const makeProjectedMutation = (h: any): any => {
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
mergedInvalidation ? { queryInvalidation: mergedInvalidation } : undefined
|
|
780
|
-
) as any
|
|
805
|
+
const isWithInput = !Effect.isEffect(h.handler)
|
|
806
|
+
const mutate = withDefaultInvalidation(mutation(h), isWithInput, mergedInvalidation)
|
|
781
807
|
return Object.assign(
|
|
782
808
|
mutate,
|
|
783
809
|
{
|
|
784
810
|
wrap: Command.wrap({
|
|
785
|
-
mutate
|
|
811
|
+
mutate,
|
|
786
812
|
id: client[key].id
|
|
787
813
|
}),
|
|
788
814
|
project: (projectionSchema: any) => {
|
package/src/mutate.ts
CHANGED
|
@@ -269,32 +269,45 @@ export const invalidateQueries = (
|
|
|
269
269
|
return handle
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
export interface MutationFnWithInput<I, A, E, R, Id extends string> {
|
|
273
|
+
<B = A, E2 = never, R2 = never>(
|
|
274
|
+
input: I,
|
|
275
|
+
options?: MutationOptionsBase<A, B, E2, R2>
|
|
276
|
+
): Effect.Effect<B, E | E2, R | R2>
|
|
277
|
+
readonly id: Id
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface MutationFn<A, E, R, Id extends string> {
|
|
281
|
+
<B = A, E2 = never, R2 = never>(
|
|
282
|
+
options?: MutationOptionsBase<A, B, E2, R2>
|
|
283
|
+
): Effect.Effect<B, E | E2, R | R2>
|
|
284
|
+
readonly id: Id
|
|
285
|
+
}
|
|
286
|
+
|
|
272
287
|
export const makeMutation = () => {
|
|
273
288
|
const useMutation: {
|
|
274
289
|
/**
|
|
275
290
|
* Pass a function that returns an Effect, e.g from a client action
|
|
276
291
|
* Executes query cache invalidation based on default rules or provided option.
|
|
277
292
|
*/
|
|
278
|
-
<I, E, A, R, Request extends Req, Id extends string
|
|
279
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Id
|
|
280
|
-
|
|
281
|
-
): ((i: I) => Effect.Effect<B, E | E2, R | R2>) & { readonly id: Id }
|
|
293
|
+
<I, E, A, R, Request extends Req, Id extends string>(
|
|
294
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Id>
|
|
295
|
+
): MutationFnWithInput<I, A, E, R, Id>
|
|
282
296
|
/**
|
|
283
297
|
* Pass an Effect, e.g from a client action
|
|
284
298
|
* Executes query cache invalidation based on default rules or provided option.
|
|
285
299
|
*/
|
|
286
|
-
<E, A, R, Request extends Req, Id extends string
|
|
287
|
-
self: RequestHandler<A, E, R, Request, Id
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>,
|
|
292
|
-
options?: MutationOptionsBase<A, B, E2, R2>
|
|
300
|
+
<E, A, R, Request extends Req, Id extends string>(
|
|
301
|
+
self: RequestHandler<A, E, R, Request, Id>
|
|
302
|
+
): MutationFn<A, E, R, Id>
|
|
303
|
+
} = <I, E, A, R, Request extends Req, Id extends string>(
|
|
304
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>
|
|
293
305
|
) => {
|
|
294
306
|
const queryClient = useQueryClient()
|
|
295
|
-
const handle = invalidateQueries(queryClient, self, options as any)
|
|
296
307
|
const handler = self.handler
|
|
297
|
-
const r = Effect.isEffect(handler)
|
|
308
|
+
const r = Effect.isEffect(handler)
|
|
309
|
+
? (options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler)
|
|
310
|
+
: (i: I, options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler(i), i)
|
|
298
311
|
|
|
299
312
|
return Object.assign(r, { id: self.id }) as any
|
|
300
313
|
}
|
|
@@ -310,25 +323,23 @@ export const useMakeMutation = () => {
|
|
|
310
323
|
* Pass a function that returns an Effect, e.g from a client action
|
|
311
324
|
* Executes query cache invalidation based on default rules or provided option.
|
|
312
325
|
*/
|
|
313
|
-
<I, E, A, R, Request extends Req, Id extends string
|
|
314
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Id
|
|
315
|
-
|
|
316
|
-
): ((i: I) => Effect.Effect<B, E | E2, R | R2>) & { readonly id: Id }
|
|
326
|
+
<I, E, A, R, Request extends Req, Id extends string>(
|
|
327
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Id>
|
|
328
|
+
): MutationFnWithInput<I, A, E, R, Id>
|
|
317
329
|
/**
|
|
318
330
|
* Pass an Effect, e.g from a client action
|
|
319
331
|
* Executes query cache invalidation based on default rules or provided option.
|
|
320
332
|
*/
|
|
321
|
-
<E, A, R, Request extends Req, Id extends string
|
|
322
|
-
self: RequestHandler<A, E, R, Request, Id
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>,
|
|
327
|
-
options?: MutationOptionsBase<A, B, E2, R2>
|
|
333
|
+
<E, A, R, Request extends Req, Id extends string>(
|
|
334
|
+
self: RequestHandler<A, E, R, Request, Id>
|
|
335
|
+
): MutationFn<A, E, R, Id>
|
|
336
|
+
} = <I, E, A, R, Request extends Req, Id extends string>(
|
|
337
|
+
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>
|
|
328
338
|
) => {
|
|
329
|
-
const handle = invalidateQueries(queryClient, self, options as any)
|
|
330
339
|
const handler = self.handler
|
|
331
|
-
const r = Effect.isEffect(handler)
|
|
340
|
+
const r = Effect.isEffect(handler)
|
|
341
|
+
? (options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler)
|
|
342
|
+
: (i: I, options?: MutationOptionsBase) => invalidateQueries(queryClient, self, options)(handler(i), i)
|
|
332
343
|
|
|
333
344
|
return Object.assign(r, { id: self.id }) as any
|
|
334
345
|
}
|