effect-zero 0.1.1 → 0.2.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.
Files changed (66) hide show
  1. package/README.md +138 -95
  2. package/dist/client-transaction.d.ts +22 -0
  3. package/dist/client-transaction.d.ts.map +1 -0
  4. package/dist/client-transaction.js +15 -0
  5. package/dist/client-transaction.js.map +1 -0
  6. package/dist/client.d.ts +10 -38
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +23 -50
  9. package/dist/client.js.map +1 -1
  10. package/dist/internal/server.d.ts +54 -0
  11. package/dist/internal/server.d.ts.map +1 -0
  12. package/dist/internal/server.js +64 -0
  13. package/dist/internal/server.js.map +1 -0
  14. package/dist/internal/utils.d.ts.map +1 -0
  15. package/dist/internal/utils.js.map +1 -0
  16. package/dist/mutators.d.ts +18 -23
  17. package/dist/mutators.d.ts.map +1 -1
  18. package/dist/mutators.js +9 -18
  19. package/dist/mutators.js.map +1 -1
  20. package/dist/query.d.ts +30 -0
  21. package/dist/query.d.ts.map +1 -0
  22. package/dist/query.js +54 -0
  23. package/dist/query.js.map +1 -0
  24. package/dist/server-transaction.d.ts +42 -0
  25. package/dist/server-transaction.d.ts.map +1 -0
  26. package/dist/server-transaction.js +88 -0
  27. package/dist/server-transaction.js.map +1 -0
  28. package/dist/server.d.ts +111 -168
  29. package/dist/server.d.ts.map +1 -1
  30. package/dist/server.js +80 -201
  31. package/dist/server.js.map +1 -1
  32. package/dist/snapshot.d.ts.map +1 -1
  33. package/dist/snapshot.js +3 -1
  34. package/dist/snapshot.js.map +1 -1
  35. package/dist/types/common.d.ts +4 -0
  36. package/dist/types/common.d.ts.map +1 -0
  37. package/dist/types/common.js +4 -0
  38. package/dist/types/common.js.map +1 -0
  39. package/dist/{types.d.ts → types/push.d.ts} +15 -15
  40. package/dist/types/push.d.ts.map +1 -0
  41. package/dist/{types.js → types/push.js} +54 -54
  42. package/dist/types/push.js.map +1 -0
  43. package/dist/types/queries.d.ts +29 -0
  44. package/dist/types/queries.d.ts.map +1 -0
  45. package/dist/types/queries.js +42 -0
  46. package/dist/types/queries.js.map +1 -0
  47. package/package.json +45 -21
  48. package/src/client-transaction.ts +30 -0
  49. package/src/client.ts +66 -116
  50. package/src/internal/server.ts +90 -0
  51. package/src/mutators.ts +42 -44
  52. package/src/query.ts +117 -0
  53. package/src/server-transaction.ts +141 -0
  54. package/src/server.ts +174 -320
  55. package/src/snapshot.ts +0 -2
  56. package/src/types/common.ts +4 -0
  57. package/src/types/push.ts +197 -0
  58. package/src/types/queries.ts +56 -0
  59. package/dist/types.d.ts.map +0 -1
  60. package/dist/types.js.map +0 -1
  61. package/dist/utils.d.ts.map +0 -1
  62. package/dist/utils.js.map +0 -1
  63. package/src/types.ts +0 -201
  64. /package/dist/{utils.d.ts → internal/utils.d.ts} +0 -0
  65. /package/dist/{utils.js → internal/utils.js} +0 -0
  66. /package/src/{utils.ts → internal/utils.ts} +0 -0
@@ -0,0 +1,197 @@
1
+ import * as Schema from "effect/Schema";
2
+ import { JsonSchema } from "./common.js";
3
+
4
+ // The code below was converted to Effect Schema from:
5
+ // https://github.com/rocicorp/mono/blob/30f209f2946b4cf2cd2dee459849351498f11308/packages/zero-protocol/src/push.ts
6
+
7
+ const PrimaryKey = Schema.Array(Schema.String);
8
+
9
+ const PrimaryKeyValue = Schema.Union(Schema.String, Schema.Number, Schema.Boolean);
10
+
11
+ const PrimaryKeyValueRecord = Schema.Record({ key: Schema.String, value: PrimaryKeyValue });
12
+
13
+ const Value = Schema.Union(JsonSchema, Schema.Undefined);
14
+ const Row = Schema.Record({ key: Schema.String, value: Value });
15
+
16
+ const CRUD_MUTATION_NAME = "_zero_crud";
17
+
18
+ /**
19
+ * Inserts if entity with id does not already exist.
20
+ */
21
+ const InsertOp = Schema.Struct({
22
+ op: Schema.Literal("insert"),
23
+ tableName: Schema.String,
24
+ primaryKey: PrimaryKey,
25
+ value: Row,
26
+ });
27
+
28
+ /**
29
+ * Upsert semantics. Inserts if entity with id does not already exist,
30
+ * otherwise updates existing entity with id.
31
+ */
32
+ const UpsertOp = Schema.Struct({
33
+ op: Schema.Literal("upsert"),
34
+ tableName: Schema.String,
35
+ primaryKey: PrimaryKey,
36
+ value: Row,
37
+ });
38
+
39
+ /**
40
+ * Updates if entity with id exists, otherwise does nothing.
41
+ */
42
+ const UpdateOp = Schema.Struct({
43
+ op: Schema.Literal("update"),
44
+ tableName: Schema.String,
45
+ primaryKey: PrimaryKey,
46
+ // Partial value with at least the primary key fields
47
+ value: Row,
48
+ });
49
+
50
+ /**
51
+ * Deletes entity with id if it exists, otherwise does nothing.
52
+ */
53
+ const DeleteOp = Schema.Struct({
54
+ op: Schema.Literal("delete"),
55
+ tableName: Schema.String,
56
+ primaryKey: PrimaryKey,
57
+ // Partial value representing the primary key
58
+ value: PrimaryKeyValueRecord,
59
+ });
60
+
61
+ const CrudOp = Schema.Union(InsertOp, UpsertOp, UpdateOp, DeleteOp);
62
+
63
+ const CrudArg = Schema.Struct({
64
+ ops: Schema.Array(CrudOp),
65
+ });
66
+
67
+ const CrudArgs = Schema.Tuple(CrudArg);
68
+
69
+ const CrudMutation = Schema.Struct({
70
+ type: Schema.Literal("crud"),
71
+ id: Schema.Number,
72
+ clientID: Schema.String,
73
+ name: Schema.Literal(CRUD_MUTATION_NAME),
74
+ args: CrudArgs,
75
+ timestamp: Schema.Number,
76
+ });
77
+
78
+ const CustomMutation = Schema.Struct({
79
+ type: Schema.Literal("custom"),
80
+ id: Schema.Number,
81
+ clientID: Schema.String,
82
+ name: Schema.String,
83
+ args: Schema.Array(JsonSchema),
84
+ timestamp: Schema.Number,
85
+ });
86
+
87
+ export const Mutation = Schema.Union(CrudMutation, CustomMutation);
88
+ export type Mutation = typeof Mutation.Type;
89
+
90
+ export const PushBody = Schema.Struct({
91
+ clientGroupID: Schema.String,
92
+ mutations: Schema.Array(Mutation),
93
+ pushVersion: Schema.Number,
94
+ // For legacy (CRUD) mutations, the schema is tied to the client group /
95
+ // sync connection. For custom mutations, schema versioning is delegated
96
+ // to the custom protocol / api-server.
97
+ schemaVersion: Schema.optional(Schema.Number),
98
+ timestamp: Schema.Number,
99
+ requestID: Schema.String,
100
+ });
101
+ export type PushBody = typeof PushBody.Type;
102
+
103
+ // biome-ignore lint/correctness/noUnusedVariables: borrowed code
104
+ const PushMessage = Schema.Tuple(Schema.Literal("push"), PushBody);
105
+
106
+ const MutationId = Schema.Struct({
107
+ id: Schema.Number,
108
+ clientID: Schema.String,
109
+ });
110
+
111
+ export const AppError = Schema.Struct({
112
+ error: Schema.Literal("app"),
113
+ // The user can return any additional data here
114
+ details: Schema.optional(JsonSchema),
115
+ });
116
+
117
+ export type AppError = typeof AppError.Type;
118
+
119
+ export const ZeroError = Schema.Struct({
120
+ error: Schema.Union(Schema.Literal("oooMutation"), Schema.Literal("alreadyProcessed")),
121
+ details: Schema.optional(JsonSchema),
122
+ });
123
+
124
+ export type ZeroError = typeof ZeroError.Type;
125
+
126
+ const MutationOk = Schema.Struct({
127
+ // The user can return any additional data here
128
+ data: Schema.optional(JsonSchema),
129
+ });
130
+
131
+ const MutationError = Schema.Union(AppError, ZeroError);
132
+
133
+ export const MutationResult = Schema.Union(
134
+ // We flip the original order here as otherwise values of type MutationError would get parsed as MutationOk with empty `data`
135
+ MutationError,
136
+ MutationOk,
137
+ );
138
+ export type MutationResult = typeof MutationResult.Type;
139
+
140
+ export const MutationResponse = Schema.Struct({
141
+ id: MutationId,
142
+ result: MutationResult,
143
+ });
144
+ export type MutationResponse = typeof MutationResponse.Type;
145
+
146
+ const PushOk = Schema.Struct({
147
+ mutations: Schema.Array(MutationResponse),
148
+ });
149
+
150
+ const UnsupportedPushVersion = Schema.Struct({
151
+ error: Schema.Literal("unsupportedPushVersion"),
152
+ // optional for backwards compatibility
153
+ // This field is included so the client knows which mutations
154
+ // were not processed by the server.
155
+ mutationIDs: Schema.optional(Schema.Array(MutationId)),
156
+ });
157
+
158
+ const UnsupportedSchemaVersion = Schema.Struct({
159
+ error: Schema.Literal("unsupportedSchemaVersion"),
160
+ // optional for backwards compatibility
161
+ // This field is included so the client knows which mutations
162
+ // were not processed by the server.
163
+ mutationIDs: Schema.optional(Schema.Array(MutationId)),
164
+ });
165
+
166
+ const HttpError = Schema.Struct({
167
+ error: Schema.Literal("http"),
168
+ status: Schema.Number,
169
+ details: Schema.String,
170
+ mutationIDs: Schema.optional(Schema.Array(MutationId)),
171
+ });
172
+
173
+ const ZeroPusherError = Schema.Struct({
174
+ error: Schema.Literal("zeroPusher"),
175
+ details: Schema.String,
176
+ mutationIDs: Schema.optional(Schema.Array(MutationId)),
177
+ });
178
+
179
+ const PushError = Schema.Union(UnsupportedPushVersion, UnsupportedSchemaVersion, HttpError, ZeroPusherError);
180
+
181
+ export const PushResponse = Schema.Union(PushOk, PushError);
182
+ export type PushResponse = typeof PushResponse.Type;
183
+
184
+ // biome-ignore lint/correctness/noUnusedVariables: borrowed code
185
+ const PushResponseMessage = Schema.Tuple(Schema.Literal("pushResponse"), PushResponse);
186
+
187
+ // biome-ignore lint/correctness/noUnusedVariables: borrowed code
188
+ const AckMutationResponsesMessage = Schema.Tuple(Schema.Literal("ackMutationResponses"), MutationId);
189
+
190
+ /**
191
+ * The schema for the querystring parameters of the custom push endpoint.
192
+ */
193
+ export const PushParams = Schema.Struct({
194
+ schema: Schema.String,
195
+ appID: Schema.String,
196
+ });
197
+ export type PushParams = typeof PushParams.Type;
@@ -0,0 +1,56 @@
1
+ import * as Schema from "effect/Schema";
2
+ import { JsonSchema } from "./common.js";
3
+
4
+ // The code below was converted to Effect Schema from:
5
+ // https://github.com/rocicorp/mono/blob/9fe2b3cb770bad269ecaf12296c64a0739c23e4e/packages/zero-protocol/src/custom-queries.ts#L14
6
+
7
+ /** TODO: Defined as unknown for now */
8
+ const Ast = Schema.Unknown;
9
+
10
+ const TransformRequestBody = Schema.Array(
11
+ Schema.Struct({
12
+ id: Schema.String,
13
+ name: Schema.String,
14
+ args: Schema.Array(JsonSchema),
15
+ }),
16
+ );
17
+
18
+ const TransformedQuery = Schema.Struct({
19
+ id: Schema.String,
20
+ name: Schema.String,
21
+ ast: Ast,
22
+ });
23
+
24
+ const AppQueryError = Schema.Struct({
25
+ error: Schema.Literal("app"),
26
+ id: Schema.String,
27
+ name: Schema.String,
28
+ details: JsonSchema,
29
+ });
30
+
31
+ const ErrorSchema = Schema.Struct({
32
+ error: Schema.Literal("zero"),
33
+ id: Schema.String,
34
+ name: Schema.String,
35
+ details: JsonSchema,
36
+ });
37
+
38
+ const HttpQueryError = Schema.Struct({
39
+ error: Schema.Literal("http"),
40
+ id: Schema.String,
41
+ name: Schema.String,
42
+ status: Schema.Number,
43
+ details: JsonSchema,
44
+ });
45
+
46
+ const ErroredQuery = Schema.Union(AppQueryError, HttpQueryError, ErrorSchema);
47
+
48
+ const TransformResponseBody = Schema.Array(Schema.Union(TransformedQuery, ErroredQuery));
49
+
50
+ export const TransformRequestMessage = Schema.Tuple(Schema.Literal("transform"), TransformRequestBody);
51
+ export type TransformRequestMessage = typeof TransformRequestMessage.Type;
52
+
53
+ // biome-ignore lint/correctness/noUnusedVariables: borrowed code
54
+ const TransformErrorMessage = Schema.Tuple(Schema.Literal("transformError"), Schema.Array(ErroredQuery));
55
+
56
+ export const TransformResponseMessage = Schema.Tuple(Schema.Literal("transformed"), TransformResponseBody);
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAwFxC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAqD,CAAC;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AAEpD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CA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AC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;CAC3D,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAChC,0BAA0B,EAC1B,4BAA4B,EAC5B,aAAa,EACb,eAAe,CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAGxE,iEAAiE;AACjE,MAAM,uBAAuB,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,gBAAgB,CAAC,CAAC;AAE/F,iEAAiE;AACjE,MAAM,+BAA+B,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE,cAAc,CAAC,CAAC;AAE7G;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC,MAAM;CACrB,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC,uBAAmC,CAAC"}
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAmB,IAAO,EAAE,EAAE,CAAC,eAAe,IAAI,EAAW,CAAC"}
package/src/types.ts DELETED
@@ -1,201 +0,0 @@
1
- import * as Schema from "effect/Schema";
2
-
3
- // The code below was converted to Effect Schema from:
4
- // https://github.com/rocicorp/mono/blob/30f209f2946b4cf2cd2dee459849351498f11308/packages/zero-protocol/src/push.ts
5
-
6
- /** TODO: Defined as unknown for now */
7
- const JsonSchema = Schema.Unknown;
8
-
9
- const ZeroPrimaryKey = Schema.Array(Schema.String);
10
-
11
- const ZeroPrimaryKeyValue = Schema.Union(Schema.String, Schema.Number, Schema.Boolean);
12
-
13
- const ZeroPrimaryKeyValueRecord = Schema.Record({ key: Schema.String, value: ZeroPrimaryKeyValue });
14
-
15
- const ZeroValue = Schema.Union(JsonSchema, Schema.Undefined);
16
- const ZeroRow = Schema.Record({ key: Schema.String, value: ZeroValue });
17
-
18
- const CRUD_MUTATION_NAME = "_zero_crud";
19
-
20
- /**
21
- * Inserts if entity with id does not already exist.
22
- */
23
- const ZeroInsertOp = Schema.Struct({
24
- op: Schema.Literal("insert"),
25
- tableName: Schema.String,
26
- primaryKey: ZeroPrimaryKey,
27
- value: ZeroRow,
28
- });
29
-
30
- /**
31
- * Upsert semantics. Inserts if entity with id does not already exist,
32
- * otherwise updates existing entity with id.
33
- */
34
- const ZeroUpsertOp = Schema.Struct({
35
- op: Schema.Literal("upsert"),
36
- tableName: Schema.String,
37
- primaryKey: ZeroPrimaryKey,
38
- value: ZeroRow,
39
- });
40
-
41
- /**
42
- * Updates if entity with id exists, otherwise does nothing.
43
- */
44
- const ZeroUpdateOp = Schema.Struct({
45
- op: Schema.Literal("update"),
46
- tableName: Schema.String,
47
- primaryKey: ZeroPrimaryKey,
48
- // Partial value with at least the primary key fields
49
- value: ZeroRow,
50
- });
51
-
52
- /**
53
- * Deletes entity with id if it exists, otherwise does nothing.
54
- */
55
- const ZeroDeleteOp = Schema.Struct({
56
- op: Schema.Literal("delete"),
57
- tableName: Schema.String,
58
- primaryKey: ZeroPrimaryKey,
59
- // Partial value representing the primary key
60
- value: ZeroPrimaryKeyValueRecord,
61
- });
62
-
63
- const ZeroCrudOp = Schema.Union(ZeroInsertOp, ZeroUpsertOp, ZeroUpdateOp, ZeroDeleteOp);
64
-
65
- const ZeroCrudArg = Schema.Struct({
66
- ops: Schema.Array(ZeroCrudOp),
67
- });
68
-
69
- const ZeroCrudArgs = Schema.Tuple(ZeroCrudArg);
70
-
71
- const ZeroCrudMutation = Schema.Struct({
72
- type: Schema.Literal("crud"),
73
- id: Schema.Number,
74
- clientID: Schema.String,
75
- name: Schema.Literal(CRUD_MUTATION_NAME),
76
- args: ZeroCrudArgs,
77
- timestamp: Schema.Number,
78
- });
79
-
80
- const ZeroCustomMutation = Schema.Struct({
81
- type: Schema.Literal("custom"),
82
- id: Schema.Number,
83
- clientID: Schema.String,
84
- name: Schema.String,
85
- args: Schema.Array(JsonSchema),
86
- timestamp: Schema.Number,
87
- });
88
-
89
- export const ZeroMutation = Schema.Union(ZeroCrudMutation, ZeroCustomMutation);
90
- export type ZeroMutation = typeof ZeroMutation.Type;
91
-
92
- export const ZeroPushBody = Schema.Struct({
93
- clientGroupID: Schema.String,
94
- mutations: Schema.Array(ZeroMutation),
95
- pushVersion: Schema.Number,
96
- // For legacy (CRUD) mutations, the schema is tied to the client group /
97
- // sync connection. For custom mutations, schema versioning is delegated
98
- // to the custom protocol / api-server.
99
- schemaVersion: Schema.optional(Schema.Number),
100
- timestamp: Schema.Number,
101
- requestID: Schema.String,
102
- });
103
- export type ZeroPushBody = typeof ZeroPushBody.Type;
104
-
105
- // biome-ignore lint/correctness/noUnusedVariables: borrowed code
106
- const ZeroPushMessage = Schema.Tuple(Schema.Literal("push"), ZeroPushBody);
107
-
108
- const ZeroMutationId = Schema.Struct({
109
- id: Schema.Number,
110
- clientID: Schema.String,
111
- });
112
-
113
- export const ZeroAppError = Schema.Struct({
114
- error: Schema.Literal("app"),
115
- // The user can return any additional data here
116
- details: Schema.optional(JsonSchema),
117
- });
118
-
119
- export type ZeroAppError = typeof ZeroAppError.Type;
120
-
121
- export const ZeroError = Schema.Struct({
122
- error: Schema.Union(Schema.Literal("oooMutation"), Schema.Literal("alreadyProcessed")),
123
- details: Schema.optional(JsonSchema),
124
- });
125
-
126
- export type ZeroError = typeof ZeroError.Type;
127
-
128
- const ZeroMutationOk = Schema.Struct({
129
- // The user can return any additional data here
130
- data: Schema.optional(JsonSchema),
131
- });
132
-
133
- const ZeroMutationError = Schema.Union(ZeroAppError, ZeroError);
134
-
135
- // We flip the original order here as otherwise values of type ZeroMutationError would get parsed as ZeroMutationOk with empty `data`
136
- export const ZeroMutationResult = Schema.Union(ZeroMutationError, ZeroMutationOk);
137
- export type ZeroMutationResult = typeof ZeroMutationResult.Type;
138
-
139
- export const ZeroMutationResponse = Schema.Struct({
140
- id: ZeroMutationId,
141
- result: ZeroMutationResult,
142
- });
143
- export type ZeroMutationResponse = typeof ZeroMutationResponse.Type;
144
-
145
- const ZeroPushOk = Schema.Struct({
146
- mutations: Schema.Array(ZeroMutationResponse),
147
- });
148
-
149
- const ZeroUnsupportedPushVersion = Schema.Struct({
150
- error: Schema.Literal("unsupportedPushVersion"),
151
- // optional for backwards compatibility
152
- // This field is included so the client knows which mutations
153
- // were not processed by the server.
154
- mutationIDs: Schema.optional(Schema.Array(ZeroMutationId)),
155
- });
156
-
157
- const ZeroUnsupportedSchemaVersion = Schema.Struct({
158
- error: Schema.Literal("unsupportedSchemaVersion"),
159
- // optional for backwards compatibility
160
- // This field is included so the client knows which mutations
161
- // were not processed by the server.
162
- mutationIDs: Schema.optional(Schema.Array(ZeroMutationId)),
163
- });
164
-
165
- const ZeroHttpError = Schema.Struct({
166
- error: Schema.Literal("http"),
167
- status: Schema.Number,
168
- details: Schema.String,
169
- mutationIDs: Schema.optional(Schema.Array(ZeroMutationId)),
170
- });
171
-
172
- const ZeroPusherError = Schema.Struct({
173
- error: Schema.Literal("zeroPusher"),
174
- details: Schema.String,
175
- mutationIDs: Schema.optional(Schema.Array(ZeroMutationId)),
176
- });
177
-
178
- const ZeroPushError = Schema.Union(
179
- ZeroUnsupportedPushVersion,
180
- ZeroUnsupportedSchemaVersion,
181
- ZeroHttpError,
182
- ZeroPusherError,
183
- );
184
-
185
- export const ZeroPushResponse = Schema.Union(ZeroPushOk, ZeroPushError);
186
- export type ZeroPushResponse = typeof ZeroPushResponse.Type;
187
-
188
- // biome-ignore lint/correctness/noUnusedVariables: borrowed code
189
- const ZeroPushResponseMessage = Schema.Tuple(Schema.Literal("pushResponse"), ZeroPushResponse);
190
-
191
- // biome-ignore lint/correctness/noUnusedVariables: borrowed code
192
- const ZeroAckMutationResponsesMessage = Schema.Tuple(Schema.Literal("ackMutationResponses"), ZeroMutationId);
193
-
194
- /**
195
- * The schema for the querystring parameters of the custom push endpoint.
196
- */
197
- export const ZeroPushParams = Schema.Struct({
198
- schema: Schema.String,
199
- appID: Schema.String,
200
- });
201
- export type ZeroPushParams = typeof ZeroPushParams.Type;
File without changes
File without changes
File without changes