@effect-app/vue 2.67.1 → 2.67.2
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 +6 -0
- package/dist/experimental/commander.d.ts +5 -5
- package/dist/experimental/commander.d.ts.map +1 -1
- package/dist/experimental/commander.js +176 -174
- package/dist/experimental/intl.d.ts +1 -1
- package/dist/experimental/makeUseCommand.d.ts +4 -4
- package/dist/experimental/toast.d.ts +1 -1
- package/dist/makeClient.d.ts +6 -6
- package/dist/mutate.d.ts +2 -0
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +27 -20
- package/package.json +1 -1
- package/src/experimental/commander.ts +262 -253
- package/src/mutate.ts +51 -42
- package/test/dist/stubs.d.ts +4 -4
- package/test/dist/stubs.d.ts.map +1 -1
package/src/mutate.ts
CHANGED
|
@@ -17,6 +17,10 @@ export const getQueryKey = (h: { id: string }) => {
|
|
|
17
17
|
return k
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export const getQueryKeyInt = (id: string) => {
|
|
21
|
+
return getQueryKey({ id })
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
export function mutationResultToVue<A, E>(
|
|
21
25
|
mutationResult: Result.Result<A, E>
|
|
22
26
|
): Res<A, E> {
|
|
@@ -141,6 +145,52 @@ export const asResult: {
|
|
|
141
145
|
return tuple(computed(() => state.value), act) as any
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
export const useInvalidateQueries = (id: string, options?: MutationOptionsBase["queryInvalidation"]) => {
|
|
149
|
+
const queryClient = useQueryClient()
|
|
150
|
+
|
|
151
|
+
const invalidateQueries = (
|
|
152
|
+
filters?: InvalidateQueryFilters,
|
|
153
|
+
options?: InvalidateOptions
|
|
154
|
+
) =>
|
|
155
|
+
Effect.currentSpan.pipe(
|
|
156
|
+
Effect.orElseSucceed(() => null),
|
|
157
|
+
Effect.flatMap((span) =>
|
|
158
|
+
Effect.promise(() => queryClient.invalidateQueries(filters, { ...options, updateMeta: { span } }))
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
const invalidateCache = Effect.suspend(() => {
|
|
163
|
+
const queryKey = getQueryKeyInt(id)
|
|
164
|
+
|
|
165
|
+
if (options) {
|
|
166
|
+
const opts = options(queryKey, id)
|
|
167
|
+
if (!opts.length) {
|
|
168
|
+
return Effect.void
|
|
169
|
+
}
|
|
170
|
+
return Effect
|
|
171
|
+
.andThen(
|
|
172
|
+
Effect.annotateCurrentSpan({ queryKey, opts }),
|
|
173
|
+
Effect.forEach(opts, (_) => invalidateQueries(_.filters, _.options), { concurrency: "inherit" })
|
|
174
|
+
)
|
|
175
|
+
.pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!queryKey) return Effect.void
|
|
179
|
+
|
|
180
|
+
return Effect
|
|
181
|
+
.andThen(
|
|
182
|
+
Effect.annotateCurrentSpan({ queryKey }),
|
|
183
|
+
invalidateQueries({ queryKey })
|
|
184
|
+
)
|
|
185
|
+
.pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
const handle = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
189
|
+
Effect.tapBoth(self, { onFailure: () => invalidateCache, onSuccess: () => invalidateCache })
|
|
190
|
+
|
|
191
|
+
return handle
|
|
192
|
+
}
|
|
193
|
+
|
|
144
194
|
export const makeMutation = () => {
|
|
145
195
|
const useMutation: {
|
|
146
196
|
/**
|
|
@@ -163,48 +213,7 @@ export const makeMutation = () => {
|
|
|
163
213
|
self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>,
|
|
164
214
|
options?: MutationOptionsBase
|
|
165
215
|
) => {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
const invalidateQueries = (
|
|
169
|
-
filters?: InvalidateQueryFilters,
|
|
170
|
-
options?: InvalidateOptions
|
|
171
|
-
) =>
|
|
172
|
-
Effect.currentSpan.pipe(
|
|
173
|
-
Effect.orElseSucceed(() => null),
|
|
174
|
-
Effect.flatMap((span) =>
|
|
175
|
-
Effect.promise(() => queryClient.invalidateQueries(filters, { ...options, updateMeta: { span } }))
|
|
176
|
-
)
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
const invalidateCache = Effect.suspend(() => {
|
|
180
|
-
const queryKey = getQueryKey(self)
|
|
181
|
-
|
|
182
|
-
if (options?.queryInvalidation) {
|
|
183
|
-
const opts = options.queryInvalidation(queryKey, self.id)
|
|
184
|
-
if (!opts.length) {
|
|
185
|
-
return Effect.void
|
|
186
|
-
}
|
|
187
|
-
return Effect
|
|
188
|
-
.andThen(
|
|
189
|
-
Effect.annotateCurrentSpan({ queryKey, opts }),
|
|
190
|
-
Effect.forEach(opts, (_) => invalidateQueries(_.filters, _.options), { concurrency: "inherit" })
|
|
191
|
-
)
|
|
192
|
-
.pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (!queryKey) return Effect.void
|
|
196
|
-
|
|
197
|
-
return Effect
|
|
198
|
-
.andThen(
|
|
199
|
-
Effect.annotateCurrentSpan({ queryKey }),
|
|
200
|
-
invalidateQueries({ queryKey })
|
|
201
|
-
)
|
|
202
|
-
.pipe(Effect.withSpan("client.query.invalidation", { captureStackTrace: false }))
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
const handle = (self: Effect.Effect<A, E, R>) =>
|
|
206
|
-
Effect.tapBoth(self, { onFailure: () => invalidateCache, onSuccess: () => invalidateCache })
|
|
207
|
-
|
|
216
|
+
const handle = useInvalidateQueries(self.id, options?.queryInvalidation)
|
|
208
217
|
const handler = self.handler
|
|
209
218
|
const r = Effect.isEffect(handler) ? handle(handler) : (i: I) => handle(handler(i))
|
|
210
219
|
|
package/test/dist/stubs.d.ts
CHANGED
|
@@ -9,22 +9,22 @@ export declare const useExperimental: (options?: {
|
|
|
9
9
|
messages?: Record<string, string> | Record<string, MessageFormatElement[]>;
|
|
10
10
|
toasts: any[];
|
|
11
11
|
}) => {
|
|
12
|
-
alt: <const Id extends string>(id: Id) => <Args extends Array<unknown>, A, E, R_1 extends Toast.Toast | WithToast | import("../src/experimental/commander.js").CommandContext>(handler: (...args: Args) => Effect.Effect<A, E, R_1>) => Commander.CommandOut<Args, A, E, R_1, Id
|
|
12
|
+
alt: <const Id extends string>(id: Id) => Commander.CommandContextLocal<Id> & (<Args extends Array<unknown>, A, E, R_1 extends Toast.Toast | WithToast | import("../src/experimental/commander.js").CommandContext>(handler: (...args: Args) => Effect.Effect<A, E, R_1>) => Commander.CommandOut<Args, A, E, R_1, Id>);
|
|
13
13
|
fn: <const Id extends string>(id: Id) => Commander.Gen<Toast.Toast | WithToast, Id> & Commander.NonGen<Toast.Toast | WithToast, Id>;
|
|
14
14
|
wrap: <const Id extends string, Args extends Array<unknown>, A_1, E_1, R_2>(mutation: {
|
|
15
15
|
mutate: (...args: Args) => Effect.Effect<A_1, E_1, R_2>;
|
|
16
16
|
id: Id;
|
|
17
17
|
} | (((...args: Args) => Effect.Effect<A_1, E_1, R_2>) & {
|
|
18
18
|
id: Id;
|
|
19
|
-
})) => Commander.GenWrap<Toast.Toast | WithToast, Id, Args, A_1, E_1, R_2> & Commander.NonGenWrap<Toast.Toast | WithToast, Id, Args, A_1, E_1, R_2>;
|
|
19
|
+
})) => Commander.CommandContextLocal<Id> & Commander.GenWrap<Toast.Toast | WithToast, Id, Args, A_1, E_1, R_2> & Commander.NonGenWrap<Toast.Toast | WithToast, Id, Args, A_1, E_1, R_2>;
|
|
20
20
|
alt2: <const Id extends string, MutArgs extends Array<unknown>, MutA, MutE, MutR>(id: Id | {
|
|
21
21
|
id: Id;
|
|
22
22
|
mutate: (...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>;
|
|
23
23
|
} | (((...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>) & {
|
|
24
24
|
id: Id;
|
|
25
|
-
})) => <Args_1 extends Array<unknown>, A_2, E_2, R_3 extends Toast.Toast | WithToast | import("../src/experimental/commander.js").CommandContext>(handler: (ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal<Id> & {
|
|
25
|
+
})) => Commander.CommandContextLocal<Id> & (<Args_1 extends Array<unknown>, A_2, E_2, R_3 extends Toast.Toast | WithToast | import("../src/experimental/commander.js").CommandContext>(handler: (ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal<Id> & {
|
|
26
26
|
mutate: (...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>;
|
|
27
|
-
}) => (...args: Args_1) => Effect.Effect<A_2, E_2, R_3>) => Commander.CommandOut<Args_1, A_2, E_2, R_3, Id
|
|
27
|
+
}) => (...args: Args_1) => Effect.Effect<A_2, E_2, R_3>) => Commander.CommandOut<Args_1, A_2, E_2, R_3, Id>);
|
|
28
28
|
takeOver: <Args_1 extends any[], A_3, E_3, R_4, const Id extends string>(command: Commander.CommandOut<Args_1, A_3, E_3, R_4, Id>) => (...args: Args_1) => Effect.Effect<A_3, E_3, import("../src/experimental/commander.js").CommandContext | Exclude<Exclude<R_4, import("../src/experimental/commander.js").CommandContext>, import("effect/Tracer").ParentSpan>>;
|
|
29
29
|
confirmOrInterrupt: (message?: string | undefined) => Effect.Effect<void, never, import("../src/experimental/commander.js").CommandContext>;
|
|
30
30
|
confirm: (message?: string | undefined) => Effect.Effect<boolean, never, import("../src/experimental/commander.js").CommandContext>;
|
package/test/dist/stubs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubs.d.ts","sourceRoot":"","sources":["../stubs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAE1C,OAAO,EAAE,SAA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