effect-zero 0.3.3 → 0.4.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/src/server.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReadonlyJSONValue, Schema as ZeroSchema } from "@rocicorp/zero";
2
- import { handleGetQueriesRequest } from "@rocicorp/zero/server";
2
+ import { handleQueryRequest } from "@rocicorp/zero/server";
3
3
  import * as Arr from "effect/Array";
4
4
  import * as Cause from "effect/Cause";
5
5
  import * as Chunk from "effect/Chunk";
@@ -29,6 +29,10 @@ import type * as ServerTransaction from "./server-transaction.js";
29
29
  import * as Types from "./types/push.js";
30
30
  import type { TransformRequestMessage } from "./types/queries.js";
31
31
 
32
+ // Updated to:
33
+ // https://github.com/rocicorp/mono/blob/3082c9fa061891067b4bd7dc9fe74f798270d8d7/packages/zero-server/src/push-processor.ts
34
+ // https://github.com/rocicorp/mono/blob/3082c9fa061891067b4bd7dc9fe74f798270d8d7/packages/zero-server/src/process-mutations.ts
35
+
32
36
  type ServerTransactionContext<TSchema extends ZeroSchema, TTransaction> = Omit<
33
37
  ReturnType<typeof ServerTransaction.make<string, TSchema, TTransaction>>,
34
38
  "use"
@@ -54,6 +58,7 @@ export const processPush = Effect.fn(function* <
54
58
  if (mutation.type !== "custom") {
55
59
  return yield* new CustomMutationExpectedError();
56
60
  }
61
+
57
62
  return yield* processMutation<Mutators.ExtractMutatorsRequirements<TMutators>>(mutators, mutation).pipe(
58
63
  Effect.catchAll((e) => processMutationError(transaction, e)),
59
64
  Effect.map((result) =>
@@ -65,6 +70,7 @@ export const processPush = Effect.fn(function* <
65
70
  clientGroupID: request.clientGroupID,
66
71
  upstreamSchema: params.schema,
67
72
  }),
73
+ Effect.provide(ServerSynchronizationContext.Default),
68
74
  );
69
75
  }),
70
76
  ),
@@ -76,7 +82,7 @@ export const processPush = Effect.fn(function* <
76
82
  );
77
83
 
78
84
  return { mutations: Chunk.toArray(responses) } satisfies Types.PushResponse;
79
- }, Effect.provide(ServerSynchronizationContext.Default));
85
+ });
80
86
 
81
87
  const processMutation = Effect.fn(function* <R>(mutators: Mutators.AnyMutators<R>, mutation: Types.Mutation) {
82
88
  // Support both "namespace|name" and "namespace.name" formats, and single-segment names.
@@ -179,7 +185,7 @@ class MutationUserError extends Data.TaggedError("MutationUserError")<{
179
185
  }
180
186
  }
181
187
 
182
- export const handleGetQueries = Effect.fn(function* <E, R1, R2>(
188
+ export const handleQuery = Effect.fn(function* <E, R1, R2>(
183
189
  queries: MakeQueryResult<E, R1, R2>[],
184
190
  schema: ZeroSchema,
185
191
  payload: TransformRequestMessage,
@@ -187,19 +193,15 @@ export const handleGetQueries = Effect.fn(function* <E, R1, R2>(
187
193
  const runtime = yield* Effect.runtime<R1 | R2>();
188
194
  return yield* Effect.tryPromise({
189
195
  try: () =>
190
- handleGetQueriesRequest(
196
+ handleQueryRequest(
191
197
  (name, args) =>
192
198
  Arr.findFirst(queries, (q) => q[QueryNameSymbol] === name).pipe(
193
199
  Effect.catchTag("NoSuchElementException", () => new QueryNotFound({ name })),
194
200
  Effect.flatMap((query) => query[RunQuerySymbol]({ _tag: "Encoded", args })),
195
- Effect.map((query) => ({ query })),
196
- (effect) => Runtime.runPromiseExit(runtime, effect),
197
- (exit) =>
198
- exit.then(
199
- Exit.getOrElse((cause) => {
200
- throw new QueryUserError<E>({ cause });
201
- }),
202
- ),
201
+ (effect) => Runtime.runSyncExit(runtime, effect),
202
+ Exit.getOrElse((cause) => {
203
+ throw new QueryUserError<E>({ cause });
204
+ }),
203
205
  ),
204
206
  schema,
205
207
  payload as ReadonlyJSONValue,
@@ -207,7 +209,7 @@ export const handleGetQueries = Effect.fn(function* <E, R1, R2>(
207
209
  catch: (e) =>
208
210
  Option.liftPredicate(e, QueryUserError.is<E>).pipe(
209
211
  Option.flatMap((e) => Cause.failureOption(e.cause)),
210
- Option.getOrElse(() => new GetQueriesError({ cause: Cause.fail(e) })),
212
+ Option.getOrElse(() => new QueryRequestError({ cause: Cause.fail(e) })),
211
213
  ),
212
214
  });
213
215
  });
@@ -228,4 +230,4 @@ class QueryUserError<E> extends Data.TaggedError("QueryUserError")<{
228
230
  }
229
231
  }
230
232
 
231
- class GetQueriesError extends Data.TaggedError("GetQueriesError")<{ cause: Cause.Cause<unknown> }> {}
233
+ class QueryRequestError extends Data.TaggedError("QueryRequestError")<{ cause: Cause.Cause<unknown> }> {}
package/src/snapshot.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  // https://github.com/rocicorp/mono/blob/30f209f2946b4cf2cd2dee459849351498f11308/packages/zero-react/src/use-query.tsx
3
3
  // https://github.com/rocicorp/mono/blob/30f209f2946b4cf2cd2dee459849351498f11308/packages/shared/src/deep-clone.ts#L4
4
4
 
5
- import type { JSONValue, ReadonlyJSONValue } from "@rocicorp/zero";
6
- import type { HumanReadable, QueryResult } from "@rocicorp/zero/react";
5
+ import type { HumanReadable, JSONValue, ReadonlyJSONValue } from "@rocicorp/zero";
6
+ import type { QueryResult } from "@rocicorp/zero/react";
7
7
 
8
8
  const emptyArray: unknown[] = [];
9
9