effect-zero 0.0.0-alpha.0 → 0.1.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/dist/server.js ADDED
@@ -0,0 +1,235 @@
1
+ import * as Cause from "effect/Cause";
2
+ import * as Chunk from "effect/Chunk";
3
+ import * as Context from "effect/Context";
4
+ import * as Data from "effect/Data";
5
+ import * as Deferred from "effect/Deferred";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Exit from "effect/Exit";
8
+ import * as Fn from "effect/Function";
9
+ import * as Match from "effect/Match";
10
+ import * as Option from "effect/Option";
11
+ import * as Predicate from "effect/Predicate";
12
+ import * as Rec from "effect/Record";
13
+ import * as Runtime from "effect/Runtime";
14
+ import * as Schema from "effect/Schema";
15
+ import * as Stream from "effect/Stream";
16
+ import * as Str from "effect/String";
17
+ import * as SynchronizedRef from "effect/SynchronizedRef";
18
+ import { MutatorArgsSchemaSym } from "./mutators.js";
19
+ import { ZeroMutationResponse, } from "./types.js";
20
+ import { prefixId } from "./utils.js";
21
+ // NOTE(zero): Using the "Lifting the Generic" technique.
22
+ // NOTE(zero): Could choose to not accept `Database<T>` as a param and instead create some `ZeroDatabase` service inside the
23
+ // `make` function, which various other functions require. However, this means that the user will have to manually
24
+ // specify the `T` type parameter which seemed a bit clunky.
25
+ export const makeServer = (options) => {
26
+ const ZeroServerTransactionContext = Context.Tag(prefixId("ZeroServerTransactionContext"))();
27
+ // TODO: Maybe prefix this / suffix this with a tag passed in to `make`?
28
+ const execute = Effect.fn(function* (effect) {
29
+ const runtime =
30
+ // TODO: Is there a cleaner way to write this?
31
+ yield* Effect.runtime();
32
+ const result = yield* Deferred.make();
33
+ const transactionInput = yield* ZeroTransactionInput;
34
+ yield* Effect.tryPromise({
35
+ try: (signal) => options.database.transaction(async (transaction, transactionHooks) => {
36
+ const exit = await Effect.zipRight(checkAndIncrementLastMutationID, effect).pipe(Effect.provideService(ZeroServerTransactionContext, { transaction, transactionHooks }), options.clientTransaction
37
+ ? Effect.provideService(options.clientTransaction, transaction)
38
+ : // TODO: Is there a cleaner way to write this?
39
+ (effect) => effect, (effect) => Runtime.runPromiseExit(runtime, effect, { signal }));
40
+ Deferred.unsafeDone(result, exit);
41
+ return Exit.getOrElse(exit, () => {
42
+ // This error's purpose is to differentiate between "external" errors
43
+ // that originate from the user-defined mutator code and "internal" errors
44
+ // that originate from our own code and the Zero API.
45
+ // Both types are caught in the "catch" block below, but at this point we only need to handle
46
+ // the "internal" errors wrapping them in a `ZeroDatabaseError`, because "external" errors
47
+ // are already covered by passing the Exit result to the Deferred, which is why
48
+ // we have the ZeroTransactionUserError silenced below in the pipe.
49
+ throw new ZeroTransactionUserError();
50
+ });
51
+ }, transactionInput),
52
+ catch: (error) => {
53
+ if (ZeroTransactionUserError.is(error)) {
54
+ return error;
55
+ }
56
+ // This is for errors that occur when calling `database.transaction` despite the provided `effect` succeeding.
57
+ // This can be caused by e.g. the database connection timing out or other database-related issues.
58
+ return new ZeroDatabaseError({ cause: Cause.fail(error) });
59
+ },
60
+ }).pipe(Effect.catchTag("ZeroTransactionUserError", () => Effect.void));
61
+ return yield* result;
62
+ }, ZeroServerMutationContext.guard);
63
+ const use = (fn) => Effect.flatMap(ZeroServerTransactionContext, (ctx) => Effect.tryPromise({
64
+ try: (signal) => fn(ctx.transaction, { signal }),
65
+ catch: Fn.identity,
66
+ }));
67
+ const checkAndIncrementLastMutationID = Effect.gen(function* () {
68
+ const { transactionHooks } = yield* ZeroServerTransactionContext;
69
+ const { clientID, mutationID: receivedMutationID } = yield* ZeroTransactionInput;
70
+ const { lastMutationID } = yield* Effect.tryPromise({
71
+ try: () => transactionHooks.updateClientMutationID(),
72
+ catch: (error) => new UpdateClientMutationIDError({ cause: Cause.fail(error) }),
73
+ });
74
+ if (receivedMutationID < lastMutationID) {
75
+ return yield* new MutationAlreadyProcessedError({
76
+ clientID,
77
+ received: receivedMutationID,
78
+ actual: lastMutationID,
79
+ });
80
+ }
81
+ if (receivedMutationID > lastMutationID) {
82
+ return yield* new OutOfOrderMutationError({
83
+ clientID,
84
+ receivedMutationID,
85
+ lastMutationID,
86
+ });
87
+ }
88
+ });
89
+ const processPush = Effect.fn(function* (mutators, params, request) {
90
+ if (request.pushVersion !== 1) {
91
+ return { error: "unsupportedPushVersion" };
92
+ }
93
+ const responses = yield* Stream.fromIterable(request.mutations).pipe(Stream.mapEffect(Effect.fn(function* (mutation) {
94
+ if (mutation.type !== "custom") {
95
+ return yield* new CustomMutationExpectedError({});
96
+ }
97
+ return yield* processMutation(mutators, mutation).pipe(Effect.map((result) => ZeroMutationResponse.make({ id: { id: mutation.id, clientID: mutation.clientID }, result })), Effect.provideService(ZeroTransactionInput, {
98
+ clientID: mutation.clientID,
99
+ mutationID: mutation.id,
100
+ clientGroupID: request.clientGroupID,
101
+ upstreamSchema: params.schema,
102
+ }));
103
+ })),
104
+ // We only stop processing if the mutation is out of order.
105
+ // If the mutation has already been processed or if it returns an application error,
106
+ // we continue processing the next mutation.
107
+ Stream.takeUntil(({ result }) => Predicate.hasProperty(result, "error") && result.error === "oooMutation"), Stream.runCollect, Effect.annotateLogs({ module: prefixId("ZeroServer"), method: "processPush" }));
108
+ return { mutations: Chunk.toArray(responses) };
109
+ });
110
+ const processMutation = Effect.fn(function* (mutators, mutation) {
111
+ // Support both "namespace|name" and "namespace.name" formats, and single-segment names.
112
+ const [namespace, name] = mutation.name.includes("|")
113
+ ? Str.split(mutation.name, "|")
114
+ : Str.split(mutation.name, ".");
115
+ const mutator = yield* Fn.pipe(mutators, Rec.get(namespace), Option.flatMap((mutator) => Match.value([mutator, name]).pipe(Match.when([Predicate.isRecord, Predicate.isString], ([mutator, name]) => Rec.get(name)(mutator)), Match.when([Predicate.isFunction, Predicate.isUndefined], ([mutator]) => Option.some(mutator)), Match.orElse(() => Option.none()))), Effect.catchTag("NoSuchElementException", () => new MutatorNotFoundError({ mutationName: mutation.name })));
116
+ const args = yield* Schema.decode(mutator[MutatorArgsSchemaSym])(mutation.args[0]).pipe(Effect.catchTag("ParseError", (e) => new ZeroServerArgsParseError({ cause: Cause.fail(e) })));
117
+ return yield* mutator(args).pipe(
118
+ // Case #2 "One transaction then fail"
119
+ // If the transaction was executed successfully, swallow the error and just log it, otherwise re-throw it
120
+ Effect.catchAllCause(Effect.fn(function* (e) {
121
+ const wasTransactionExecuted = yield* ZeroServerMutationContext.wasTransactionExecuted;
122
+ if (wasTransactionExecuted) {
123
+ return yield* Effect.logError("Error occurred after transaction execution completed", e);
124
+ }
125
+ return yield* Effect.failCause(e);
126
+ })),
127
+ // Case #4 "Zero transactions then succeed"
128
+ // Check that the transaction was executed during the mutation
129
+ Effect.tap(Effect.gen(function* () {
130
+ const wasTransactionExecuted = yield* ZeroServerMutationContext.wasTransactionExecuted;
131
+ if (!wasTransactionExecuted) {
132
+ return yield* new NoTransactionError();
133
+ }
134
+ })), Effect.as({}), Effect.catchIf(OutOfOrderMutationError.is, (e) => Effect.logError(e.message).pipe(Effect.as({ error: "oooMutation", details: e.message }))), Effect.catchIf(MutationAlreadyProcessedError.is, (e) => Effect.logWarning(e.message).pipe(Effect.as({ error: "alreadyProcessed", details: e.message }))),
135
+ // Case #5 "Zero transactions then fail" / #6 "Fail before transaction"
136
+ // Catches all errors that are produced before the transaction is executed
137
+ Effect.catchAllCause((cause) => new ZeroMutationUserError({ cause })));
138
+ }, Effect.catchAll((e) => processMutationError(e)), Effect.provide(ZeroServerMutationContext.Default));
139
+ const processMutationError = Effect.fn(function* (e) {
140
+ const { clientID, mutationID } = yield* ZeroTransactionInput;
141
+ yield* Effect.logError(`Unexpected error processing mutation ${mutationID} for client ${clientID}`, Cause.fail(e));
142
+ const errorMessage = Match.value(e).pipe(Match.when(ZeroMutationUserError.is, (e) => e.message), Match.orElse(() => "Internal error"));
143
+ const appError = {
144
+ error: "app",
145
+ details: errorMessage,
146
+ };
147
+ yield* execute(Effect.flatMap(ZeroServerTransactionContext, ({ transactionHooks }) => {
148
+ return Effect.tryPromise({
149
+ try: () => transactionHooks.writeMutationResult({ id: { id: mutationID, clientID }, result: appError }),
150
+ catch: (error) => new WriteMutationResultError({ cause: Cause.fail(error) }),
151
+ });
152
+ })).pipe(Effect.catchAllCause(Effect.logError));
153
+ yield* Effect.logWarning(`Mutation ${mutationID} for client ${clientID} was retried after an error: ${e}`);
154
+ return appError;
155
+ });
156
+ return {
157
+ Transaction: Object.assign(ZeroServerTransactionContext, { execute, use }),
158
+ processPush,
159
+ };
160
+ };
161
+ class ZeroTransactionInput extends Context.Tag(prefixId("ZeroTransactionInput"))() {
162
+ }
163
+ class ZeroServerMutationContext extends Effect.Service()(prefixId("ZeroServerMutationContext"), {
164
+ effect: Effect.gen(function* () {
165
+ return { wasTransactionExecuted: yield* SynchronizedRef.make(false) };
166
+ }),
167
+ }) {
168
+ static wasTransactionExecuted = Effect.flatMap(ZeroServerMutationContext, (ctx) => ctx.wasTransactionExecuted);
169
+ // Ensures that only one transaction is executed at a time and checks that another transaction wasn't already executed.
170
+ static guard = (effect) => Effect.flatMap(this, ({ wasTransactionExecuted }) => SynchronizedRef.modifyEffect(wasTransactionExecuted, Effect.fn(function* (wasTransactionExecuted) {
171
+ if (wasTransactionExecuted) {
172
+ return yield* new MultipleTransactionsError();
173
+ }
174
+ const result = yield* effect;
175
+ return [result, true];
176
+ })));
177
+ }
178
+ class ZeroDatabaseError extends Data.TaggedError("ZeroDatabaseError") {
179
+ }
180
+ class UpdateClientMutationIDError extends Data.TaggedError("UpdateClientMutationIDError") {
181
+ }
182
+ class MutatorNotFoundError extends Data.TaggedError("MutatorNotFoundError") {
183
+ message = `Mutator not found for mutation ${this.mutationName}`;
184
+ }
185
+ class WriteMutationResultError extends Data.TaggedError("WriteMutationResultError") {
186
+ }
187
+ class CustomMutationExpectedError extends Data.TaggedError("CustomMutationExpectedError") {
188
+ }
189
+ export class MultipleTransactionsError extends Data.TaggedError("MultipleTransactionsError") {
190
+ message = "Multiple transactions detected in a mutation, only one transaction is allowed.";
191
+ }
192
+ export class NoTransactionError extends Data.TaggedError("NoTransactionError") {
193
+ message = "No transaction detected in a mutation, a transaction is required.";
194
+ }
195
+ const OutOfOrderMutationErrorTypeId = Symbol.for(prefixId("OutOfOrderMutationError"));
196
+ export class OutOfOrderMutationError extends Data.TaggedError("OutOfOrderMutationError") {
197
+ [OutOfOrderMutationErrorTypeId] = OutOfOrderMutationErrorTypeId;
198
+ get message() {
199
+ return `Client ${this.clientID} sent mutation ID ${this.receivedMutationID} but expected ${this.lastMutationID}`;
200
+ }
201
+ static is(e) {
202
+ return Predicate.hasProperty(e, OutOfOrderMutationErrorTypeId);
203
+ }
204
+ }
205
+ const MutationAlreadyProcessedErrorTypeId = Symbol.for(prefixId("MutationAlreadyProcessedError"));
206
+ export class MutationAlreadyProcessedError extends Data.TaggedError("MutationAlreadyProcessedError") {
207
+ [MutationAlreadyProcessedErrorTypeId] = MutationAlreadyProcessedErrorTypeId;
208
+ get message() {
209
+ return `Ignoring mutation from ${this.clientID} with ID ${this.received} as it was already processed. Expected: ${this.actual}`;
210
+ }
211
+ static is(e) {
212
+ return Predicate.hasProperty(e, MutationAlreadyProcessedErrorTypeId);
213
+ }
214
+ }
215
+ const ZeroTransactionUserErrorTypeId = Symbol.for(prefixId("ZeroTransactionUserError"));
216
+ export class ZeroTransactionUserError extends Data.TaggedError("ZeroTransactionUserError") {
217
+ [ZeroTransactionUserErrorTypeId] = ZeroTransactionUserErrorTypeId;
218
+ static is(e) {
219
+ return Predicate.hasProperty(e, ZeroTransactionUserErrorTypeId);
220
+ }
221
+ }
222
+ const ZeroMutationUserErrorTypeId = Symbol.for(prefixId("ZeroMutationUserError"));
223
+ export class ZeroMutationUserError extends Data.TaggedError("ZeroMutationUserError") {
224
+ [ZeroMutationUserErrorTypeId] = ZeroMutationUserErrorTypeId;
225
+ static is(e) {
226
+ return Predicate.hasProperty(e, ZeroMutationUserErrorTypeId);
227
+ }
228
+ get message() {
229
+ const err = Cause.squash(this.cause);
230
+ return err instanceof Error ? err.message : "exception was not of type `Error`";
231
+ }
232
+ }
233
+ class ZeroServerArgsParseError extends Data.TaggedError("ZeroServerArgsParseError") {
234
+ }
235
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAsD,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAIL,oBAAoB,GAKrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQtC,yDAAyD;AACzD,4HAA4H;AAC5H,kHAAkH;AAClH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAe,OAAyE,EAAE,EAAE;IACpH,MAAM,4BAA4B,GAAG,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CACF;AAED,MAAM,2BAA2B,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAAC;AAClF,MAAM,OAAO,qBAAsB,SAAQ,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAEjF;IACS,CAAC,2BAA2B,CAAC,GAAG,2BAA2B,CAAC;IACrE,MAAM,CAAC,EAAE,CAAC,CAAU;QAClB,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,2BAA2B,CAAC,CAAC;IAC/D,CAAC;IAED,IAAa,OAAO;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,mCAAmC,CAAC;IAClF,CAAC;CACF;AAED,MAAM,wBAAyB,SAAQ,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAEhF;CAAG"}
@@ -0,0 +1,10 @@
1
+ import type { JSONValue, ReadonlyJSONValue } from "@rocicorp/zero";
2
+ import type { HumanReadable, QueryResult } from "@rocicorp/zero/react";
3
+ export declare function getDefaultSnapshot<TReturn>(singular: boolean): QueryResult<TReturn>;
4
+ /**
5
+ * Returns a new snapshot or one of the empty predefined ones. Returning the
6
+ * predefined ones is important to prevent unnecessary re-renders in React.
7
+ */
8
+ export declare function getSnapshot<TReturn>(singular: boolean, data: HumanReadable<TReturn>, resultType: string): QueryResult<TReturn>;
9
+ export declare function deepClone(value: ReadonlyJSONValue): JSONValue;
10
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAYvE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAEnF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EACjC,QAAQ,EAAE,OAAO,EACjB,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,WAAW,CAAC,OAAO,CAAC,CActB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAG7D"}
@@ -0,0 +1,67 @@
1
+ // TODO(zero): clean this up
2
+ const emptyArray = [];
3
+ const resultTypeUnknown = { type: "unknown" };
4
+ const resultTypeComplete = { type: "complete" };
5
+ const emptySnapshotSingularUnknown = [undefined, resultTypeUnknown];
6
+ const emptySnapshotSingularComplete = [undefined, resultTypeComplete];
7
+ const emptySnapshotPluralUnknown = [emptyArray, resultTypeUnknown];
8
+ const emptySnapshotPluralComplete = [emptyArray, resultTypeComplete];
9
+ export function getDefaultSnapshot(singular) {
10
+ return (singular ? emptySnapshotSingularUnknown : emptySnapshotPluralUnknown);
11
+ }
12
+ /**
13
+ * Returns a new snapshot or one of the empty predefined ones. Returning the
14
+ * predefined ones is important to prevent unnecessary re-renders in React.
15
+ */
16
+ export function getSnapshot(singular, data, resultType) {
17
+ if (singular && data === undefined) {
18
+ return (resultType === "complete"
19
+ ? emptySnapshotSingularComplete
20
+ : emptySnapshotSingularUnknown);
21
+ }
22
+ if (!singular && data.length === 0) {
23
+ return (resultType === "complete" ? emptySnapshotPluralComplete : emptySnapshotPluralUnknown);
24
+ }
25
+ return [data, resultType === "complete" ? resultTypeComplete : resultTypeUnknown];
26
+ }
27
+ export function deepClone(value) {
28
+ const seen = [];
29
+ return internalDeepClone(value, seen);
30
+ }
31
+ function internalDeepClone(value, seen) {
32
+ switch (typeof value) {
33
+ case "boolean":
34
+ case "number":
35
+ case "string":
36
+ case "undefined":
37
+ return value;
38
+ case "object": {
39
+ if (value === null) {
40
+ return null;
41
+ }
42
+ if (seen.includes(value)) {
43
+ throw new Error("Cyclic object");
44
+ }
45
+ seen.push(value);
46
+ if (Array.isArray(value)) {
47
+ const rv = value.map((v) => internalDeepClone(v, seen));
48
+ seen.pop();
49
+ return rv;
50
+ }
51
+ const obj = {};
52
+ for (const k in value) {
53
+ if (Object.hasOwn(value, k)) {
54
+ const v = value[k];
55
+ if (v !== undefined) {
56
+ obj[k] = internalDeepClone(v, seen);
57
+ }
58
+ }
59
+ }
60
+ seen.pop();
61
+ return obj;
62
+ }
63
+ default:
64
+ throw new Error(`Invalid type: ${typeof value}`);
65
+ }
66
+ }
67
+ //# sourceMappingURL=snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAS5B,MAAM,UAAU,GAAc,EAAE,CAAC;AAEjC,MAAM,iBAAiB,GAAG,EAAE,IAAI,EAAE,SAAS,EAAW,CAAC;AACvD,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,UAAU,EAAW,CAAC;AAEzD,MAAM,4BAA4B,GAAG,CAAC,SAAS,EAAE,iBAAiB,CAAU,CAAC;AAC7E,MAAM,6BAA6B,GAAG,CAAC,SAAS,EAAE,kBAAkB,CAAU,CAAC;AAC/E,MAAM,0BAA0B,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAU,CAAC;AAC5E,MAAM,2BAA2B,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAU,CAAC;AAE9E,MAAM,UAAU,kBAAkB,CAAU,QAAiB;IAC3D,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,0BAA0B,CAAyB,CAAC;AACxG,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,QAAiB,EACjB,IAA4B,EAC5B,UAAkB;IAElB,IAAI,QAAQ,IAAI,IAAI,KAAK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,IAAI,CAAC,CAAC,CAAC;gBACxD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,MAAM,GAAG,GAAc,EAAE,CAAC;YAE1B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;gBACtB,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;oBAC5B,MAAM,CAAC,GAAI,KAA2C,CAAC,CAAC,CAAC,CAAC;oBAC1D,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;wBACpB,GAAG,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;oBACtC,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,OAAO,GAAG,CAAC;QACb,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,iBAAiB,OAAO,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
@@ -0,0 +1,174 @@
1
+ import * as Schema from "effect/Schema";
2
+ export declare const ZeroMutation: Schema.Union<[Schema.Struct<{
3
+ type: Schema.Literal<["crud"]>;
4
+ id: typeof Schema.Number;
5
+ clientID: typeof Schema.String;
6
+ name: Schema.Literal<["_zero_crud"]>;
7
+ args: Schema.Tuple<[Schema.Struct<{
8
+ ops: Schema.Array$<Schema.Union<[Schema.Struct<{
9
+ op: Schema.Literal<["insert"]>;
10
+ tableName: typeof Schema.String;
11
+ primaryKey: Schema.Array$<typeof Schema.String>;
12
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.Unknown, typeof Schema.Undefined]>>;
13
+ }>, Schema.Struct<{
14
+ op: Schema.Literal<["upsert"]>;
15
+ tableName: typeof Schema.String;
16
+ primaryKey: Schema.Array$<typeof Schema.String>;
17
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.Unknown, typeof Schema.Undefined]>>;
18
+ }>, Schema.Struct<{
19
+ op: Schema.Literal<["update"]>;
20
+ tableName: typeof Schema.String;
21
+ primaryKey: Schema.Array$<typeof Schema.String>;
22
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.Unknown, typeof Schema.Undefined]>>;
23
+ }>, Schema.Struct<{
24
+ op: Schema.Literal<["delete"]>;
25
+ tableName: typeof Schema.String;
26
+ primaryKey: Schema.Array$<typeof Schema.String>;
27
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.String, typeof Schema.Number, typeof Schema.Boolean]>>;
28
+ }>]>>;
29
+ }>]>;
30
+ timestamp: typeof Schema.Number;
31
+ }>, Schema.Struct<{
32
+ type: Schema.Literal<["custom"]>;
33
+ id: typeof Schema.Number;
34
+ clientID: typeof Schema.String;
35
+ name: typeof Schema.String;
36
+ args: Schema.Array$<typeof Schema.Unknown>;
37
+ timestamp: typeof Schema.Number;
38
+ }>]>;
39
+ export type ZeroMutation = typeof ZeroMutation.Type;
40
+ export declare const ZeroPushBody: Schema.Struct<{
41
+ clientGroupID: typeof Schema.String;
42
+ mutations: Schema.Array$<Schema.Union<[Schema.Struct<{
43
+ type: Schema.Literal<["crud"]>;
44
+ id: typeof Schema.Number;
45
+ clientID: typeof Schema.String;
46
+ name: Schema.Literal<["_zero_crud"]>;
47
+ args: Schema.Tuple<[Schema.Struct<{
48
+ ops: Schema.Array$<Schema.Union<[Schema.Struct<{
49
+ op: Schema.Literal<["insert"]>;
50
+ tableName: typeof Schema.String;
51
+ primaryKey: Schema.Array$<typeof Schema.String>;
52
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.Unknown, typeof Schema.Undefined]>>;
53
+ }>, Schema.Struct<{
54
+ op: Schema.Literal<["upsert"]>;
55
+ tableName: typeof Schema.String;
56
+ primaryKey: Schema.Array$<typeof Schema.String>;
57
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.Unknown, typeof Schema.Undefined]>>;
58
+ }>, Schema.Struct<{
59
+ op: Schema.Literal<["update"]>;
60
+ tableName: typeof Schema.String;
61
+ primaryKey: Schema.Array$<typeof Schema.String>;
62
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.Unknown, typeof Schema.Undefined]>>;
63
+ }>, Schema.Struct<{
64
+ op: Schema.Literal<["delete"]>;
65
+ tableName: typeof Schema.String;
66
+ primaryKey: Schema.Array$<typeof Schema.String>;
67
+ value: Schema.Record$<typeof Schema.String, Schema.Union<[typeof Schema.String, typeof Schema.Number, typeof Schema.Boolean]>>;
68
+ }>]>>;
69
+ }>]>;
70
+ timestamp: typeof Schema.Number;
71
+ }>, Schema.Struct<{
72
+ type: Schema.Literal<["custom"]>;
73
+ id: typeof Schema.Number;
74
+ clientID: typeof Schema.String;
75
+ name: typeof Schema.String;
76
+ args: Schema.Array$<typeof Schema.Unknown>;
77
+ timestamp: typeof Schema.Number;
78
+ }>]>>;
79
+ pushVersion: typeof Schema.Number;
80
+ schemaVersion: Schema.optional<typeof Schema.Number>;
81
+ timestamp: typeof Schema.Number;
82
+ requestID: typeof Schema.String;
83
+ }>;
84
+ export type ZeroPushBody = typeof ZeroPushBody.Type;
85
+ export declare const ZeroAppError: Schema.Struct<{
86
+ error: Schema.Literal<["app"]>;
87
+ details: Schema.optional<typeof Schema.Unknown>;
88
+ }>;
89
+ export type ZeroAppError = typeof ZeroAppError.Type;
90
+ export declare const ZeroError: Schema.Struct<{
91
+ error: Schema.Union<[Schema.Literal<["oooMutation"]>, Schema.Literal<["alreadyProcessed"]>]>;
92
+ details: Schema.optional<typeof Schema.Unknown>;
93
+ }>;
94
+ export type ZeroError = typeof ZeroError.Type;
95
+ export declare const ZeroMutationResult: Schema.Union<[Schema.Union<[Schema.Struct<{
96
+ error: Schema.Literal<["app"]>;
97
+ details: Schema.optional<typeof Schema.Unknown>;
98
+ }>, Schema.Struct<{
99
+ error: Schema.Union<[Schema.Literal<["oooMutation"]>, Schema.Literal<["alreadyProcessed"]>]>;
100
+ details: Schema.optional<typeof Schema.Unknown>;
101
+ }>]>, Schema.Struct<{
102
+ data: Schema.optional<typeof Schema.Unknown>;
103
+ }>]>;
104
+ export type ZeroMutationResult = typeof ZeroMutationResult.Type;
105
+ export declare const ZeroMutationResponse: Schema.Struct<{
106
+ id: Schema.Struct<{
107
+ id: typeof Schema.Number;
108
+ clientID: typeof Schema.String;
109
+ }>;
110
+ result: Schema.Union<[Schema.Union<[Schema.Struct<{
111
+ error: Schema.Literal<["app"]>;
112
+ details: Schema.optional<typeof Schema.Unknown>;
113
+ }>, Schema.Struct<{
114
+ error: Schema.Union<[Schema.Literal<["oooMutation"]>, Schema.Literal<["alreadyProcessed"]>]>;
115
+ details: Schema.optional<typeof Schema.Unknown>;
116
+ }>]>, Schema.Struct<{
117
+ data: Schema.optional<typeof Schema.Unknown>;
118
+ }>]>;
119
+ }>;
120
+ export type ZeroMutationResponse = typeof ZeroMutationResponse.Type;
121
+ export declare const ZeroPushResponse: Schema.Union<[Schema.Struct<{
122
+ mutations: Schema.Array$<Schema.Struct<{
123
+ id: Schema.Struct<{
124
+ id: typeof Schema.Number;
125
+ clientID: typeof Schema.String;
126
+ }>;
127
+ result: Schema.Union<[Schema.Union<[Schema.Struct<{
128
+ error: Schema.Literal<["app"]>;
129
+ details: Schema.optional<typeof Schema.Unknown>;
130
+ }>, Schema.Struct<{
131
+ error: Schema.Union<[Schema.Literal<["oooMutation"]>, Schema.Literal<["alreadyProcessed"]>]>;
132
+ details: Schema.optional<typeof Schema.Unknown>;
133
+ }>]>, Schema.Struct<{
134
+ data: Schema.optional<typeof Schema.Unknown>;
135
+ }>]>;
136
+ }>>;
137
+ }>, Schema.Union<[Schema.Struct<{
138
+ error: Schema.Literal<["unsupportedPushVersion"]>;
139
+ mutationIDs: Schema.optional<Schema.Array$<Schema.Struct<{
140
+ id: typeof Schema.Number;
141
+ clientID: typeof Schema.String;
142
+ }>>>;
143
+ }>, Schema.Struct<{
144
+ error: Schema.Literal<["unsupportedSchemaVersion"]>;
145
+ mutationIDs: Schema.optional<Schema.Array$<Schema.Struct<{
146
+ id: typeof Schema.Number;
147
+ clientID: typeof Schema.String;
148
+ }>>>;
149
+ }>, Schema.Struct<{
150
+ error: Schema.Literal<["http"]>;
151
+ status: typeof Schema.Number;
152
+ details: typeof Schema.String;
153
+ mutationIDs: Schema.optional<Schema.Array$<Schema.Struct<{
154
+ id: typeof Schema.Number;
155
+ clientID: typeof Schema.String;
156
+ }>>>;
157
+ }>, Schema.Struct<{
158
+ error: Schema.Literal<["zeroPusher"]>;
159
+ details: typeof Schema.String;
160
+ mutationIDs: Schema.optional<Schema.Array$<Schema.Struct<{
161
+ id: typeof Schema.Number;
162
+ clientID: typeof Schema.String;
163
+ }>>>;
164
+ }>]>]>;
165
+ export type ZeroPushResponse = typeof ZeroPushResponse.Type;
166
+ /**
167
+ * The schema for the querystring parameters of the custom push endpoint.
168
+ */
169
+ export declare const ZeroPushParams: Schema.Struct<{
170
+ schema: typeof Schema.String;
171
+ appID: typeof Schema.String;
172
+ }>;
173
+ export type ZeroPushParams = typeof ZeroPushParams.Type;
174
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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,CAAC,IAAI,CAAC;AAUpD,eAAO,MAAM,YAAY;;;EAIvB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;AAEpD,eAAO,MAAM,SAAS;;;EAGpB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAU9C,eAAO,MAAM,kBAAkB;;;;;;;;IAAkD,CAAC;AAClF,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAC;AAEhE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;EAG/B,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAC;AA0CpE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAA0C,CAAC;AACxE,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAC;AAQ5D;;GAEG;AACH,eAAO,MAAM,cAAc;;;EAGzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC"}