effect-zero 0.3.2 → 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/README.md +23 -16
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/internal/query-result.d.ts +2 -1
- package/dist/internal/query-result.d.ts.map +1 -1
- package/dist/internal/query-result.js.map +1 -1
- package/dist/query.d.ts +12 -13
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +11 -14
- package/dist/query.js.map +1 -1
- package/dist/query.test.d.ts +2 -0
- package/dist/query.test.d.ts.map +1 -0
- package/dist/query.test.js +86 -0
- package/dist/query.test.js.map +1 -0
- package/dist/result.d.ts +1 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/server.d.ts +33 -14
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +8 -8
- package/dist/server.js.map +1 -1
- package/dist/snapshot.d.ts +2 -2
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/types.test.d.ts +2 -0
- package/dist/types.test.d.ts.map +1 -0
- package/dist/types.test.js +268 -0
- package/dist/types.test.js.map +1 -0
- package/package.json +26 -26
- package/src/client.ts +3 -3
- package/src/internal/query-result.ts +2 -5
- package/src/query.ts +27 -35
- package/src/result.ts +1 -1
- package/src/server.ts +16 -14
- package/src/snapshot.ts +2 -2
- package/src/internal/server.test.ts +0 -37
package/src/server.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReadonlyJSONValue, Schema as ZeroSchema } from "@rocicorp/zero";
|
|
2
|
-
import {
|
|
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
|
-
}
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
196
|
-
(
|
|
197
|
-
|
|
198
|
-
|
|
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
|
|
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
|
|
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 {
|
|
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
|
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "@effect/vitest";
|
|
2
|
-
import * as Cause from "effect/Cause";
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Exit from "effect/Exit";
|
|
5
|
-
import { NoTransactionError, ServerSynchronizationContext } from "./server.js";
|
|
6
|
-
|
|
7
|
-
describe("ServerSynchronizationContext", () => {
|
|
8
|
-
it.effect(
|
|
9
|
-
"finalize should return NoTransactionError when called without guard",
|
|
10
|
-
Effect.fn(function* ({ expect }) {
|
|
11
|
-
const result = yield* Effect.void.pipe(
|
|
12
|
-
ServerSynchronizationContext.finalize,
|
|
13
|
-
Effect.provide(ServerSynchronizationContext.Default),
|
|
14
|
-
Effect.exit,
|
|
15
|
-
);
|
|
16
|
-
Exit.match(result, {
|
|
17
|
-
onSuccess: () => expect.fail("Expected failure"),
|
|
18
|
-
onFailure: (cause) => expect(cause).toStrictEqual(Cause.fail(new NoTransactionError())),
|
|
19
|
-
});
|
|
20
|
-
}),
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
it.effect(
|
|
24
|
-
"finalize shouldn't return errors when called with guard",
|
|
25
|
-
Effect.fn(function* ({ expect }) {
|
|
26
|
-
const result = yield* Effect.void.pipe(
|
|
27
|
-
ServerSynchronizationContext.guard,
|
|
28
|
-
ServerSynchronizationContext.finalize,
|
|
29
|
-
Effect.provide(ServerSynchronizationContext.Default),
|
|
30
|
-
Effect.exit,
|
|
31
|
-
);
|
|
32
|
-
if (Exit.isFailure(result)) {
|
|
33
|
-
expect.fail("Expected success", result.cause);
|
|
34
|
-
}
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
});
|