@effect-app/vue 2.66.0 → 2.67.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/src/mutate.ts CHANGED
@@ -7,13 +7,13 @@ import { tuple } from "effect-app/Function"
7
7
  import { computed, type ComputedRef, shallowRef } from "vue"
8
8
  import { makeQueryKey } from "./lib.js"
9
9
 
10
- export const getQueryKey = (h: { name: string }) => {
10
+ export const getQueryKey = (h: { id: string }) => {
11
11
  const key = makeQueryKey(h)
12
12
  const ns = key.filter((_) => _.startsWith("$"))
13
13
  // we invalidate the parent namespace e.g $project/$configuration.get, we invalidate $project
14
14
  // for $project/$configuration/$something.get, we invalidate $project/$configuration
15
15
  const k = ns.length ? ns.length > 1 ? ns.slice(0, ns.length - 1) : ns : undefined
16
- if (!k) throw new Error("empty query key for: " + h.name)
16
+ if (!k) throw new Error("empty query key for: " + h.id)
17
17
  return k
18
18
  }
19
19
 
@@ -147,20 +147,20 @@ export const makeMutation = () => {
147
147
  * Pass a function that returns an Effect, e.g from a client action
148
148
  * Executes query cache invalidation based on default rules or provided option.
149
149
  */
150
- <I, E, A, R, Request extends TaggedRequestClassAny, Name extends string>(
151
- self: RequestHandlerWithInput<I, A, E, R, Request, Name>,
150
+ <I, E, A, R, Request extends TaggedRequestClassAny, Id extends string>(
151
+ self: RequestHandlerWithInput<I, A, E, R, Request, Id>,
152
152
  options?: MutationOptionsBase
153
- ): (i: I) => Effect.Effect<A, E, R>
153
+ ): ((i: I) => Effect.Effect<A, E, R>) & { readonly id: Id }
154
154
  /**
155
155
  * Pass an Effect, e.g from a client action
156
156
  * Executes query cache invalidation based on default rules or provided option.
157
157
  */
158
- <E, A, R, Request extends TaggedRequestClassAny, Name extends string>(
159
- self: RequestHandler<A, E, R, Request, Name>,
158
+ <E, A, R, Request extends TaggedRequestClassAny, Id extends string>(
159
+ self: RequestHandler<A, E, R, Request, Id>,
160
160
  options?: MutationOptionsBase
161
- ): Effect.Effect<A, E, R>
162
- } = <I, E, A, R, Request extends TaggedRequestClassAny, Name extends string>(
163
- self: RequestHandlerWithInput<I, A, E, R, Request, Name> | RequestHandler<A, E, R, Request, Name>,
161
+ ): Effect.Effect<A, E, R> & { readonly id: Id }
162
+ } = <I, E, A, R, Request extends TaggedRequestClassAny, Id extends string>(
163
+ self: RequestHandlerWithInput<I, A, E, R, Request, Id> | RequestHandler<A, E, R, Request, Id>,
164
164
  options?: MutationOptionsBase
165
165
  ) => {
166
166
  const queryClient = useQueryClient()
@@ -180,7 +180,7 @@ export const makeMutation = () => {
180
180
  const queryKey = getQueryKey(self)
181
181
 
182
182
  if (options?.queryInvalidation) {
183
- const opts = options.queryInvalidation(queryKey, self.name)
183
+ const opts = options.queryInvalidation(queryKey, self.id)
184
184
  if (!opts.length) {
185
185
  return Effect.void
186
186
  }
@@ -208,7 +208,7 @@ export const makeMutation = () => {
208
208
  const handler = self.handler
209
209
  const r = Effect.isEffect(handler) ? handle(handler) : (i: I) => handle(handler(i))
210
210
 
211
- return r as any
211
+ return Object.assign(r, { id: self.id }) as any
212
212
  }
213
213
  return useMutation
214
214
  }
package/src/query.ts CHANGED
@@ -75,7 +75,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
75
75
  handler
76
76
  .pipe(
77
77
  Effect.tapDefect(reportRuntimeError),
78
- Effect.withSpan(`query ${q.name}`, { captureStackTrace: false }),
78
+ Effect.withSpan(`query ${q.id}`, { captureStackTrace: false }),
79
79
  meta?.["span"] ? Effect.withParentSpan(meta["span"] as Span) : (_) => _
80
80
  ),
81
81
  { signal }
@@ -100,7 +100,7 @@ export const makeQuery = <R>(getRuntime: () => Runtime.Runtime<R>) => {
100
100
  handler(req.value)
101
101
  .pipe(
102
102
  Effect.tapDefect(reportRuntimeError),
103
- Effect.withSpan(`query ${q.name}`, { captureStackTrace: false }),
103
+ Effect.withSpan(`query ${q.id}`, { captureStackTrace: false }),
104
104
  meta?.["span"] ? Effect.withParentSpan(meta["span"] as Span) : (_) => _
105
105
  ),
106
106
  { signal }
@@ -23,9 +23,31 @@ describe("alt2", () => {
23
23
  let executed = false
24
24
 
25
25
  const someMutation = {
26
- name: "Test Action",
27
- mutate: (() => {}) as unknown as (a: number, b: string) => Effect.Effect<string, number, boolean>
28
- }
26
+ id: "Test Action",
27
+ mutate: (() => {}) as unknown as (a: number, b: string) => Effect.Effect<string, number, CommandContext>
28
+ } as const
29
+ const someMutation2 = Object.assign(
30
+ (() => {}) as unknown as (a: number, b: string) => Effect.Effect<string, number, CommandContext>,
31
+ {
32
+ id: "Test Action"
33
+ } as const
34
+ )
35
+ const command1 = Command.alt2(someMutation2)((fn) =>
36
+ fn(
37
+ function*() {
38
+ expect(typeof fn.mutate).toBe("function")
39
+ expect(fn.id).toBe("Test Action")
40
+ expect(fn.namespace).toBe("action.Test Action")
41
+ expect(fn.namespaced("a")).toBe("action.Test Action.a")
42
+ }
43
+ )
44
+ )
45
+ yield* unwrap(command1.handle())
46
+ expect(command1.action).toBe("Test Action")
47
+ expect(command1.id).toBe("Test Action")
48
+ expect(command1.namespace).toBe("action.Test Action")
49
+ expect(command1.namespaced("a")).toBe("action.Test Action.a")
50
+
29
51
  const command = Command.alt2(someMutation)((fn) =>
30
52
  fn(
31
53
  function*() {
@@ -55,7 +77,7 @@ describe("alt2", () => {
55
77
  Effect.tap(() => executed = true)
56
78
  )
57
79
  )
58
- console.log(command)
80
+
59
81
  expect(command.action).toBe("Test Action")
60
82
  expect(command.id).toBe("Test Action")
61
83
  expect(command.namespace).toBe("action.Test Action")
@@ -13,12 +13,16 @@ export declare const useExperimental: (options?: {
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
- name: Id;
17
- }) => 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>;
16
+ id: Id;
17
+ } | (((...args: Args) => Effect.Effect<A_1, E_1, R_2>) & {
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>;
18
20
  alt2: <const Id extends string, MutArgs extends Array<unknown>, MutA, MutE, MutR>(id: Id | {
19
- name: Id;
21
+ id: Id;
20
22
  mutate: (...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>;
21
- }) => <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> & {
23
+ } | (((...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>) & {
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> & {
22
26
  mutate: (...args: MutArgs) => Effect.Effect<MutA, MutE, MutR>;
23
27
  }) => (...args: Args_1) => Effect.Effect<A_2, E_2, R_3>) => Commander.CommandOut<Args_1, A_2, E_2, R_3, Id>;
24
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>>;
@@ -1 +1 @@
1
- {"version":3,"file":"stubs.d.ts","sourceRoot":"","sources":["../stubs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,o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