effect-zero 0.3.3 → 0.4.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/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 +15 -13
- package/dist/query.js.map +1 -1
- package/dist/query.test.js +4 -2
- package/dist/query.test.js.map +1 -1
- package/dist/result.d.ts +1 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/server.d.ts +35 -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 +3 -3
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/snapshot.js +66 -8
- package/dist/snapshot.js.map +1 -1
- package/dist/types/error.d.ts +59 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +58 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/push.d.ts +53 -1
- package/dist/types/push.d.ts.map +1 -1
- package/dist/types/push.js +63 -10
- package/dist/types/push.js.map +1 -1
- package/dist/types/queries.d.ts +28 -9
- package/dist/types/queries.d.ts.map +1 -1
- package/dist/types/queries.js +14 -15
- package/dist/types/queries.js.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 +32 -26
- package/src/client.ts +3 -3
- package/src/internal/query-result.ts +2 -5
- package/src/query.ts +36 -34
- package/src/result.ts +1 -1
- package/src/server.ts +16 -14
- package/src/snapshot.ts +71 -12
- package/src/types/error.ts +71 -0
- package/src/types/push.ts +69 -10
- package/src/types/queries.ts +16 -16
package/dist/types/queries.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const TransformRequestMessage: Schema.Tuple2<Schema.Literal<["tra
|
|
|
5
5
|
args: Schema.Array$<typeof Schema.Unknown>;
|
|
6
6
|
}>>>;
|
|
7
7
|
export type TransformRequestMessage = typeof TransformRequestMessage.Type;
|
|
8
|
-
export declare const TransformResponseMessage: Schema.Tuple2<Schema.Literal<["transformed"]>, Schema.Array$<Schema.Union<[Schema.Struct<{
|
|
8
|
+
export declare const TransformResponseMessage: Schema.Union<[Schema.Tuple2<Schema.Literal<["transformed"]>, Schema.Array$<Schema.Union<[Schema.Struct<{
|
|
9
9
|
id: typeof Schema.String;
|
|
10
10
|
name: typeof Schema.String;
|
|
11
11
|
ast: typeof Schema.Unknown;
|
|
@@ -13,17 +13,36 @@ export declare const TransformResponseMessage: Schema.Tuple2<Schema.Literal<["tr
|
|
|
13
13
|
error: Schema.Literal<["app"]>;
|
|
14
14
|
id: typeof Schema.String;
|
|
15
15
|
name: typeof Schema.String;
|
|
16
|
-
|
|
16
|
+
message: Schema.optional<typeof Schema.String>;
|
|
17
|
+
details: Schema.optional<typeof Schema.Unknown>;
|
|
17
18
|
}>, Schema.Struct<{
|
|
18
|
-
error: Schema.Literal<["
|
|
19
|
+
error: Schema.Literal<["parse"]>;
|
|
19
20
|
id: typeof Schema.String;
|
|
20
21
|
name: typeof Schema.String;
|
|
22
|
+
message: typeof Schema.String;
|
|
23
|
+
details: Schema.optional<typeof Schema.Unknown>;
|
|
24
|
+
}>]>]>>>, Schema.Tuple2<Schema.Literal<["transformFailed"]>, Schema.Union<[Schema.Struct<{
|
|
25
|
+
origin: Schema.Literal<["server"]>;
|
|
26
|
+
reason: Schema.Literal<["database", "parse", "internal"]>;
|
|
27
|
+
kind: Schema.Literal<["TransformFailed"]>;
|
|
28
|
+
details: Schema.optional<typeof Schema.Unknown>;
|
|
29
|
+
queryIDs: Schema.Array$<typeof Schema.String>;
|
|
30
|
+
message: typeof Schema.String;
|
|
31
|
+
}>, Schema.Struct<{
|
|
32
|
+
origin: Schema.Literal<["zeroCache"]>;
|
|
33
|
+
reason: Schema.Literal<["http"]>;
|
|
21
34
|
status: typeof Schema.Number;
|
|
22
|
-
|
|
35
|
+
bodyPreview: Schema.optional<typeof Schema.String>;
|
|
36
|
+
kind: Schema.Literal<["TransformFailed"]>;
|
|
37
|
+
details: Schema.optional<typeof Schema.Unknown>;
|
|
38
|
+
queryIDs: Schema.Array$<typeof Schema.String>;
|
|
39
|
+
message: typeof Schema.String;
|
|
23
40
|
}>, Schema.Struct<{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
details: typeof Schema.Unknown
|
|
28
|
-
|
|
41
|
+
origin: Schema.Literal<["zeroCache"]>;
|
|
42
|
+
reason: Schema.Literal<["timeout", "parse", "internal"]>;
|
|
43
|
+
kind: Schema.Literal<["TransformFailed"]>;
|
|
44
|
+
details: Schema.optional<typeof Schema.Unknown>;
|
|
45
|
+
queryIDs: Schema.Array$<typeof Schema.String>;
|
|
46
|
+
message: typeof Schema.String;
|
|
47
|
+
}>]>>]>;
|
|
29
48
|
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AA6CxC,eAAO,MAAM,uBAAuB;;;;IAAkE,CAAC;AACvG,MAAM,MAAM,uBAAuB,GAAG,OAAO,uBAAuB,CAAC,IAAI,CAAC;AAS1E,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAA2D,CAAC"}
|
package/dist/types/queries.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
import { JsonSchema } from "./common.js";
|
|
3
|
+
import { TransformFailedBody } from "./error.js";
|
|
3
4
|
// The code below was converted to Effect Schema from:
|
|
4
|
-
// https://github.com/rocicorp/mono/blob/
|
|
5
|
+
// https://github.com/rocicorp/mono/blob/8e0f600fb3a9185facf60cfd4971d260b266690e/packages/zero-protocol/src/custom-queries.ts
|
|
5
6
|
/** TODO: Defined as unknown for now */
|
|
6
7
|
const Ast = Schema.Unknown;
|
|
7
8
|
const TransformRequestBody = Schema.Array(Schema.Struct({
|
|
@@ -14,29 +15,27 @@ const TransformedQuery = Schema.Struct({
|
|
|
14
15
|
name: Schema.String,
|
|
15
16
|
ast: Ast,
|
|
16
17
|
});
|
|
17
|
-
const
|
|
18
|
+
const AppErroredQuery = Schema.Struct({
|
|
18
19
|
error: Schema.Literal("app"),
|
|
19
20
|
id: Schema.String,
|
|
20
21
|
name: Schema.String,
|
|
21
|
-
|
|
22
|
+
// optional for backwards compatibility
|
|
23
|
+
message: Schema.optional(Schema.String),
|
|
24
|
+
details: Schema.optional(JsonSchema),
|
|
22
25
|
});
|
|
23
|
-
const
|
|
24
|
-
error: Schema.Literal("
|
|
26
|
+
const ParseErroredQuery = Schema.Struct({
|
|
27
|
+
error: Schema.Literal("parse"),
|
|
25
28
|
id: Schema.String,
|
|
26
29
|
name: Schema.String,
|
|
27
|
-
|
|
30
|
+
message: Schema.String,
|
|
31
|
+
details: Schema.optional(JsonSchema),
|
|
28
32
|
});
|
|
29
|
-
const
|
|
30
|
-
error: Schema.Literal("http"),
|
|
31
|
-
id: Schema.String,
|
|
32
|
-
name: Schema.String,
|
|
33
|
-
status: Schema.Number,
|
|
34
|
-
details: JsonSchema,
|
|
35
|
-
});
|
|
36
|
-
const ErroredQuery = Schema.Union(AppQueryError, HttpQueryError, ErrorSchema);
|
|
33
|
+
const ErroredQuery = Schema.Union(AppErroredQuery, ParseErroredQuery);
|
|
37
34
|
const TransformResponseBody = Schema.Array(Schema.Union(TransformedQuery, ErroredQuery));
|
|
38
35
|
export const TransformRequestMessage = Schema.Tuple(Schema.Literal("transform"), TransformRequestBody);
|
|
39
36
|
// biome-ignore lint/correctness/noUnusedVariables: borrowed code
|
|
40
37
|
const TransformErrorMessage = Schema.Tuple(Schema.Literal("transformError"), Schema.Array(ErroredQuery));
|
|
41
|
-
|
|
38
|
+
const TransformFailedMessage = Schema.Tuple(Schema.Literal("transformFailed"), TransformFailedBody);
|
|
39
|
+
const TransformOkMessage = Schema.Tuple(Schema.Literal("transformed"), TransformResponseBody);
|
|
40
|
+
export const TransformResponseMessage = Schema.Union(TransformOkMessage, TransformFailedMessage);
|
|
42
41
|
//# sourceMappingURL=queries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,sDAAsD;AACtD,8HAA8H;AAE9H,uCAAuC;AACvC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC;AAE3B,MAAM,oBAAoB,GAAG,MAAM,CAAC,KAAK,CACvC,MAAM,CAAC,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;CAC/B,CAAC,CACH,CAAC;AAEF,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,EA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AAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAEpG,MAAM,kBAAkB,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,qBAAqB,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test.d.ts","sourceRoot":"","sources":["../src/types.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from "@effect/vitest";
|
|
2
|
+
import { queryInternalsTag } from "@rocicorp/zero/bindings";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as ClientTransaction from "./client-transaction.js";
|
|
6
|
+
import * as Mutators from "./mutators.js";
|
|
7
|
+
import * as Query from "./query.js";
|
|
8
|
+
import * as Server from "./server.js";
|
|
9
|
+
import * as ServerTransaction from "./server-transaction.js";
|
|
10
|
+
// Mock Zero schema for type tests
|
|
11
|
+
const mockZeroSchema = {
|
|
12
|
+
tables: {
|
|
13
|
+
messages: {
|
|
14
|
+
tableName: "messages",
|
|
15
|
+
columns: {
|
|
16
|
+
id: { type: "string" },
|
|
17
|
+
body: { type: "string" },
|
|
18
|
+
},
|
|
19
|
+
primaryKey: ["id"],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
// Mock database for type tests
|
|
24
|
+
const mockDatabase = {};
|
|
25
|
+
describe("Type tests", () => {
|
|
26
|
+
describe("Mutators", () => {
|
|
27
|
+
it("mutators should have correct argument types", () => {
|
|
28
|
+
const mutatorSchema = Mutators.schema({
|
|
29
|
+
messages: {
|
|
30
|
+
create: Schema.Struct({
|
|
31
|
+
id: Schema.String,
|
|
32
|
+
body: Schema.String,
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
optionalVoidArg: Schema.Void,
|
|
36
|
+
noArgs: Schema.Void,
|
|
37
|
+
transformArgs: Schema.Struct({
|
|
38
|
+
foo: Schema.NumberFromString,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
const clientTransaction = ClientTransaction.make("TestClientTransaction", mockZeroSchema);
|
|
42
|
+
const mutators = Mutators.make(mutatorSchema, {
|
|
43
|
+
messages: {
|
|
44
|
+
create: (msg) => clientTransaction.use(async () => {
|
|
45
|
+
// Use msg to verify type
|
|
46
|
+
const _id = msg.id;
|
|
47
|
+
const _body = msg.body;
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
optionalVoidArg: Effect.fn(function* (_a) { }),
|
|
51
|
+
noArgs: Effect.fn(function* () { }),
|
|
52
|
+
transformArgs: Effect.fn(function* (_a) { }),
|
|
53
|
+
});
|
|
54
|
+
// Test void/undefined optional parameter
|
|
55
|
+
expectTypeOf().toEqualTypeOf();
|
|
56
|
+
// Test no-arg mutator
|
|
57
|
+
expectTypeOf().toEqualTypeOf();
|
|
58
|
+
// Test nested mutator with struct schema
|
|
59
|
+
expectTypeOf().toEqualTypeOf();
|
|
60
|
+
// Test transformed args - mutator receives decoded (Type) version
|
|
61
|
+
expectTypeOf().toEqualTypeOf();
|
|
62
|
+
});
|
|
63
|
+
it("nested mutators using Effect.fn should have correct argument types", () => {
|
|
64
|
+
const mutatorSchema = Mutators.schema({
|
|
65
|
+
todo: {
|
|
66
|
+
create: Schema.Struct({
|
|
67
|
+
id: Schema.String,
|
|
68
|
+
title: Schema.String,
|
|
69
|
+
}),
|
|
70
|
+
toggle: Schema.Struct({
|
|
71
|
+
id: Schema.String,
|
|
72
|
+
done: Schema.Boolean,
|
|
73
|
+
}),
|
|
74
|
+
delete: Schema.Void,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const clientTransaction = ClientTransaction.make("TestClientTransactionNested", mockZeroSchema);
|
|
78
|
+
// Note: When using Effect.fn with destructuring, TypeScript infers the parameter as `any`.
|
|
79
|
+
// The runtime still correctly validates/transforms args via the schema.
|
|
80
|
+
// To get proper type inference, use explicit parameter types or regular arrow functions.
|
|
81
|
+
const mutators = Mutators.make(mutatorSchema, {
|
|
82
|
+
todo: {
|
|
83
|
+
// Using arrow function with explicit type for best inference
|
|
84
|
+
create: (args) => clientTransaction.use(async () => {
|
|
85
|
+
const _id = args.id;
|
|
86
|
+
const _title = args.title;
|
|
87
|
+
}),
|
|
88
|
+
// Using Effect.fn with explicit type annotation
|
|
89
|
+
toggle: Effect.fn(function* (args) {
|
|
90
|
+
yield* clientTransaction.use(async () => { });
|
|
91
|
+
}),
|
|
92
|
+
// Using Effect.fn with no args (void schema)
|
|
93
|
+
delete: Effect.fn(function* () {
|
|
94
|
+
yield* clientTransaction.use(async () => { });
|
|
95
|
+
}),
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
// Test nested mutator with arrow function - preserves type
|
|
99
|
+
expectTypeOf().toEqualTypeOf();
|
|
100
|
+
// Test nested mutator with Effect.fn and explicit type annotation - preserves type
|
|
101
|
+
expectTypeOf().toEqualTypeOf();
|
|
102
|
+
// Test nested mutator with void schema - delete
|
|
103
|
+
expectTypeOf().toEqualTypeOf();
|
|
104
|
+
});
|
|
105
|
+
it("nested mutator requirements should propagate", () => {
|
|
106
|
+
class NestedDummyTag extends Effect.Service()("effect-zero/test/NestedDummyTag", {
|
|
107
|
+
succeed: {},
|
|
108
|
+
}) {
|
|
109
|
+
}
|
|
110
|
+
class NestedDummyTag2 extends Effect.Service()("effect-zero/test/NestedDummyTag2", {
|
|
111
|
+
succeed: {},
|
|
112
|
+
}) {
|
|
113
|
+
}
|
|
114
|
+
const clientTransaction = ClientTransaction.make("TestClientTransactionNestedReq", mockZeroSchema);
|
|
115
|
+
const serverTransaction = ServerTransaction.make("TestServerTransactionNestedReq", mockDatabase, clientTransaction);
|
|
116
|
+
const mutatorSchema = Mutators.schema({
|
|
117
|
+
nested: {
|
|
118
|
+
withTag1: Schema.Void,
|
|
119
|
+
withTag2: Schema.Void,
|
|
120
|
+
noTags: Schema.Void,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const mutators = Mutators.make(mutatorSchema, {
|
|
124
|
+
nested: {
|
|
125
|
+
withTag1: Effect.fn(function* () {
|
|
126
|
+
yield* NestedDummyTag;
|
|
127
|
+
}),
|
|
128
|
+
withTag2: Effect.fn(function* () {
|
|
129
|
+
yield* NestedDummyTag2;
|
|
130
|
+
}),
|
|
131
|
+
noTags: Effect.fn(function* () { }),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const serverEffect = Server.processPush(serverTransaction, mutators, {}, {});
|
|
135
|
+
// Server effect should require both NestedDummyTag and NestedDummyTag2
|
|
136
|
+
expectTypeOf().toEqualTypeOf();
|
|
137
|
+
});
|
|
138
|
+
it("mutator requirements should propagate", () => {
|
|
139
|
+
class DummyTag extends Effect.Service()("effect-zero/test/DummyTag", {
|
|
140
|
+
succeed: {},
|
|
141
|
+
}) {
|
|
142
|
+
}
|
|
143
|
+
class DummyTag2 extends Effect.Service()("effect-zero/test/DummyTag2", {
|
|
144
|
+
succeed: {},
|
|
145
|
+
}) {
|
|
146
|
+
}
|
|
147
|
+
const clientTransaction = ClientTransaction.make("TestClientTransaction2", mockZeroSchema);
|
|
148
|
+
const serverTransaction = ServerTransaction.make("TestServerTransaction", mockDatabase, clientTransaction);
|
|
149
|
+
const mutatorSchema = Mutators.schema({
|
|
150
|
+
dummy: Schema.Void,
|
|
151
|
+
dummy2: Schema.Void,
|
|
152
|
+
});
|
|
153
|
+
const mutators = Mutators.make(mutatorSchema, {
|
|
154
|
+
dummy: Effect.fn(function* () {
|
|
155
|
+
yield* DummyTag;
|
|
156
|
+
}),
|
|
157
|
+
dummy2: Effect.fn(function* () {
|
|
158
|
+
yield* DummyTag2;
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
const serverEffect = Server.processPush(serverTransaction, mutators, {}, {});
|
|
162
|
+
// Server effect should require both DummyTag and DummyTag2
|
|
163
|
+
expectTypeOf().toEqualTypeOf();
|
|
164
|
+
});
|
|
165
|
+
it("processPush has no extra requirements when mutators have none", () => {
|
|
166
|
+
const clientTransaction = ClientTransaction.make("TestClientTransaction3", mockZeroSchema);
|
|
167
|
+
const serverTransaction = ServerTransaction.make("TestServerTransaction2", mockDatabase, clientTransaction);
|
|
168
|
+
const mutatorSchema = Mutators.schema({
|
|
169
|
+
simple: Schema.Void,
|
|
170
|
+
});
|
|
171
|
+
const mutators = Mutators.make(mutatorSchema, {
|
|
172
|
+
simple: Effect.fn(function* () { }),
|
|
173
|
+
});
|
|
174
|
+
const effect = Server.processPush(serverTransaction, mutators, {}, {});
|
|
175
|
+
expectTypeOf().toEqualTypeOf();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe("Query", () => {
|
|
179
|
+
// biome-ignore lint/suspicious/noExplicitAny: allowed in tests
|
|
180
|
+
const makeMockQuery = () => {
|
|
181
|
+
const mockQuery = {
|
|
182
|
+
[queryInternalsTag]: true,
|
|
183
|
+
format: { singular: false },
|
|
184
|
+
nameAndArgs: () => mockQuery,
|
|
185
|
+
};
|
|
186
|
+
return mockQuery;
|
|
187
|
+
};
|
|
188
|
+
it("query should accept and passthrough encoded non-JSON args", () => {
|
|
189
|
+
const transformArgsQuery = Query.make({
|
|
190
|
+
name: "transformArgs",
|
|
191
|
+
payload: Schema.DateFromNumber,
|
|
192
|
+
query: Effect.fn(function* (a) {
|
|
193
|
+
// Inside the query, 'a' should be the decoded type (Date)
|
|
194
|
+
expectTypeOf().toEqualTypeOf();
|
|
195
|
+
return yield* Effect.succeed(makeMockQuery());
|
|
196
|
+
}),
|
|
197
|
+
});
|
|
198
|
+
// Query function should accept decoded type (Date)
|
|
199
|
+
expectTypeOf().toEqualTypeOf();
|
|
200
|
+
});
|
|
201
|
+
it("query with string tuple should have correct parameter types", () => {
|
|
202
|
+
const stringQuery = Query.make({
|
|
203
|
+
name: "stringQuery",
|
|
204
|
+
payload: Schema.String,
|
|
205
|
+
query: Effect.fn(function* (s) {
|
|
206
|
+
expectTypeOf().toEqualTypeOf();
|
|
207
|
+
return yield* Effect.succeed(makeMockQuery());
|
|
208
|
+
}),
|
|
209
|
+
});
|
|
210
|
+
expectTypeOf().toEqualTypeOf();
|
|
211
|
+
});
|
|
212
|
+
// Queries were changed to only support a single argument in 0.25
|
|
213
|
+
//
|
|
214
|
+
// it("query with multiple args should have correct parameter types", () => {
|
|
215
|
+
// const multiArgQuery = Query.make({
|
|
216
|
+
// name: "multiArgQuery",
|
|
217
|
+
// payload: Schema.Tuple(Schema.String, Schema.Number),
|
|
218
|
+
// query: Effect.fn(function* (s, n) {
|
|
219
|
+
// expectTypeOf<typeof s>().toEqualTypeOf<string>();
|
|
220
|
+
// expectTypeOf<typeof n>().toEqualTypeOf<number>();
|
|
221
|
+
// return yield* Effect.succeed(makeMockQuery());
|
|
222
|
+
// }),
|
|
223
|
+
// });
|
|
224
|
+
// expectTypeOf<Parameters<typeof multiArgQuery>>().toEqualTypeOf<[string, number]>();
|
|
225
|
+
// });
|
|
226
|
+
it("query with no args should have empty parameter types", () => {
|
|
227
|
+
const noArgQuery = Query.make({
|
|
228
|
+
name: "noArgQuery",
|
|
229
|
+
payload: Schema.Void,
|
|
230
|
+
query: Effect.fn(function* () {
|
|
231
|
+
return yield* Effect.succeed(makeMockQuery());
|
|
232
|
+
}),
|
|
233
|
+
});
|
|
234
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: Necessary for type check
|
|
235
|
+
expectTypeOf().toEqualTypeOf();
|
|
236
|
+
});
|
|
237
|
+
it("query with complex struct arg should have correct parameter types", () => {
|
|
238
|
+
const complexQuery = Query.make({
|
|
239
|
+
name: "complexQuery",
|
|
240
|
+
payload: Schema.Struct({
|
|
241
|
+
id: Schema.String,
|
|
242
|
+
nested: Schema.Struct({ value: Schema.Number }),
|
|
243
|
+
}),
|
|
244
|
+
query: Effect.fn(function* (arg) {
|
|
245
|
+
expectTypeOf().toEqualTypeOf();
|
|
246
|
+
return yield* Effect.succeed(makeMockQuery());
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
expectTypeOf().toEqualTypeOf();
|
|
250
|
+
});
|
|
251
|
+
it("MakeQueryResult should be satisfied by query results", () => {
|
|
252
|
+
const query1 = Query.make({
|
|
253
|
+
name: "q1",
|
|
254
|
+
payload: Schema.Tuple(Schema.String),
|
|
255
|
+
query: () => Effect.succeed(makeMockQuery()),
|
|
256
|
+
});
|
|
257
|
+
const query2 = Query.make({
|
|
258
|
+
name: "q2",
|
|
259
|
+
payload: Schema.Tuple(),
|
|
260
|
+
query: () => Effect.succeed(makeMockQuery()),
|
|
261
|
+
});
|
|
262
|
+
// This should compile without error
|
|
263
|
+
const queries = [query1, query2];
|
|
264
|
+
expectTypeOf(queries).toExtend();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
//# sourceMappingURL=types.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test.js","sourceRoot":"","sources":["../src/types.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAE7D,kCAAkC;AA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AO,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;gBAChD,CAAC,CAAC;aACH,CAAC,CAAC;YAEH,YAAY,EAAmC,CAAC,aAAa,EAE1D,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;YAC9D,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC;gBACxB,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;gBACpC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;aAC7C,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC;gBACxB,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE;gBACvB,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;aAC7C,CAAC,CAAC;YAEH,oCAAoC;YACpC,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAmC,CAAC;YACnE,YAAY,CAAC,OAAO,CAAC,CAAC,QAAQ,EAA2B,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-zero",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://github.com/realms-labs/effect-zero"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@effect-atom/atom": "^0.4.3",
|
|
20
20
|
"@effect/language-service": "^0.55.2",
|
|
21
21
|
"@effect/vitest": "^0.27.0",
|
|
22
|
-
"@rocicorp/zero": "^0.
|
|
22
|
+
"@rocicorp/zero": "^0.26.1",
|
|
23
23
|
"@types/bun": "latest",
|
|
24
24
|
"@types/fs-extra": "^11.0.4",
|
|
25
25
|
"effect": "^3.19.3",
|
|
@@ -40,22 +40,16 @@
|
|
|
40
40
|
"default": "./dist/server.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
"./
|
|
44
|
-
"import": {
|
|
45
|
-
"types": "./dist/result.d.ts",
|
|
46
|
-
"default": "./dist/result.js"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"./server-transaction": {
|
|
43
|
+
"./query": {
|
|
50
44
|
"import": {
|
|
51
|
-
"types": "./dist/
|
|
52
|
-
"default": "./dist/
|
|
45
|
+
"types": "./dist/query.d.ts",
|
|
46
|
+
"default": "./dist/query.js"
|
|
53
47
|
}
|
|
54
48
|
},
|
|
55
|
-
"./
|
|
49
|
+
"./mutators": {
|
|
56
50
|
"import": {
|
|
57
|
-
"types": "./dist/
|
|
58
|
-
"default": "./dist/
|
|
51
|
+
"types": "./dist/mutators.d.ts",
|
|
52
|
+
"default": "./dist/mutators.js"
|
|
59
53
|
}
|
|
60
54
|
},
|
|
61
55
|
"./snapshot": {
|
|
@@ -64,28 +58,28 @@
|
|
|
64
58
|
"default": "./dist/snapshot.js"
|
|
65
59
|
}
|
|
66
60
|
},
|
|
67
|
-
"./
|
|
61
|
+
"./client-transaction": {
|
|
68
62
|
"import": {
|
|
69
|
-
"types": "./dist/
|
|
70
|
-
"default": "./dist/
|
|
63
|
+
"types": "./dist/client-transaction.d.ts",
|
|
64
|
+
"default": "./dist/client-transaction.js"
|
|
71
65
|
}
|
|
72
66
|
},
|
|
73
|
-
"./
|
|
67
|
+
"./server-transaction": {
|
|
74
68
|
"import": {
|
|
75
|
-
"types": "./dist/
|
|
76
|
-
"default": "./dist/
|
|
69
|
+
"types": "./dist/server-transaction.d.ts",
|
|
70
|
+
"default": "./dist/server-transaction.js"
|
|
77
71
|
}
|
|
78
72
|
},
|
|
79
|
-
"./
|
|
73
|
+
"./result": {
|
|
80
74
|
"import": {
|
|
81
|
-
"types": "./dist/
|
|
82
|
-
"default": "./dist/
|
|
75
|
+
"types": "./dist/result.d.ts",
|
|
76
|
+
"default": "./dist/result.js"
|
|
83
77
|
}
|
|
84
78
|
},
|
|
85
|
-
"./
|
|
79
|
+
"./client": {
|
|
86
80
|
"import": {
|
|
87
|
-
"types": "./dist/
|
|
88
|
-
"default": "./dist/
|
|
81
|
+
"types": "./dist/client.d.ts",
|
|
82
|
+
"default": "./dist/client.js"
|
|
89
83
|
}
|
|
90
84
|
},
|
|
91
85
|
"./types/push": {
|
|
@@ -99,6 +93,18 @@
|
|
|
99
93
|
"types": "./dist/types/queries.d.ts",
|
|
100
94
|
"default": "./dist/types/queries.js"
|
|
101
95
|
}
|
|
96
|
+
},
|
|
97
|
+
"./types/error": {
|
|
98
|
+
"import": {
|
|
99
|
+
"types": "./dist/types/error.d.ts",
|
|
100
|
+
"default": "./dist/types/error.js"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"./types/common": {
|
|
104
|
+
"import": {
|
|
105
|
+
"types": "./dist/types/common.d.ts",
|
|
106
|
+
"default": "./dist/types/common.js"
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
}
|
package/src/client.ts
CHANGED
|
@@ -20,7 +20,7 @@ type ClientTransactionContext<TSchema extends ZeroSchema> = Omit<
|
|
|
20
20
|
export const make = Effect.fn(function* <TSchema extends ZeroSchema, TMutators extends Mutators.AnyMutators>(
|
|
21
21
|
transaction: ClientTransactionContext<TSchema>,
|
|
22
22
|
mutators: TMutators,
|
|
23
|
-
options: Omit<ZeroOptions<TSchema
|
|
23
|
+
options: Omit<ZeroOptions<TSchema, UnwrapMutators<TSchema, TMutators>>, "schema" | "mutators">,
|
|
24
24
|
) {
|
|
25
25
|
const runtime =
|
|
26
26
|
yield* Effect.runtime<
|
|
@@ -28,7 +28,7 @@ export const make = Effect.fn(function* <TSchema extends ZeroSchema, TMutators e
|
|
|
28
28
|
>();
|
|
29
29
|
|
|
30
30
|
function unwrapMutator<E>(mutator: Mutators.AnyMutator<Mutators.ExtractMutatorsRequirements<TMutators>, E>) {
|
|
31
|
-
return async (tx: ZeroTransaction<TSchema>, args: unknown) => {
|
|
31
|
+
return async (tx: ZeroTransaction<TSchema>, args: unknown, _ctx: unknown) => {
|
|
32
32
|
const exit = await Schema.decode(mutator[Mutators.MutatorSchemaSymbol])(args).pipe(
|
|
33
33
|
Effect.catchTag("ParseError", (e) => new ClientArgsParseError({ cause: Cause.fail(e) })),
|
|
34
34
|
Effect.flatMap(mutator),
|
|
@@ -44,7 +44,7 @@ export const make = Effect.fn(function* <TSchema extends ZeroSchema, TMutators e
|
|
|
44
44
|
|
|
45
45
|
const unwrappedMutators = Rec.map(mutators, (v) =>
|
|
46
46
|
Match.value(v).pipe(Match.when(Predicate.isFunction, unwrapMutator), Match.orElse(Rec.map(unwrapMutator))),
|
|
47
|
-
) as UnwrapMutators<TSchema, TMutators
|
|
47
|
+
) as ZeroOptions<TSchema, UnwrapMutators<TSchema, TMutators>>["mutators"];
|
|
48
48
|
|
|
49
49
|
return yield* Effect.acquireRelease(
|
|
50
50
|
Effect.sync(() => {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
QueryResult as ZeroQueryResult,
|
|
4
|
-
QueryResultDetails as ZeroQueryResultDetails,
|
|
5
|
-
} from "@rocicorp/zero/react";
|
|
1
|
+
import type { HumanReadable, QueryResultDetails as ZeroQueryResultDetails } from "@rocicorp/zero";
|
|
2
|
+
import type { QueryResult as ZeroQueryResult } from "@rocicorp/zero/react";
|
|
6
3
|
import * as Match from "effect/Match";
|
|
7
4
|
|
|
8
5
|
// Our internal representation of Zero's QueryResult type.
|