on-zero 0.7.2-1784530701923 → 0.7.2
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/cjs/asyncTasks.cjs +51 -0
- package/dist/cjs/asyncTasks.native.js +84 -0
- package/dist/cjs/asyncTasks.native.js.map +1 -0
- package/dist/cjs/createZeroDirectServer.cjs +269 -0
- package/dist/cjs/createZeroDirectServer.native.js +287 -0
- package/dist/cjs/createZeroDirectServer.native.js.map +1 -0
- package/dist/cjs/createZeroSQLiteServer.cjs +50 -0
- package/dist/cjs/createZeroSQLiteServer.native.js +58 -0
- package/dist/cjs/createZeroSQLiteServer.native.js.map +1 -0
- package/dist/cjs/createZeroSQLiteServer.test.cjs +595 -0
- package/dist/cjs/createZeroSQLiteServer.test.native.js +647 -0
- package/dist/cjs/createZeroSQLiteServer.test.native.js.map +1 -0
- package/dist/cjs/createZeroServer.cjs +82 -0
- package/dist/cjs/createZeroServer.native.js +93 -0
- package/dist/cjs/createZeroServer.native.js.map +1 -0
- package/dist/cjs/createZeroServer.test.cjs +378 -0
- package/dist/cjs/createZeroServer.test.native.js +448 -0
- package/dist/cjs/createZeroServer.test.native.js.map +1 -0
- package/dist/cjs/createZeroServerCore.cjs +211 -0
- package/dist/cjs/createZeroServerCore.native.js +355 -0
- package/dist/cjs/createZeroServerCore.native.js.map +1 -0
- package/dist/cjs/helpers/createMutators.cjs +3 -4
- package/dist/cjs/helpers/createMutators.native.js +3 -6
- package/dist/cjs/helpers/createMutators.native.js.map +1 -1
- package/dist/cjs/httpPull/auth.test.cjs +197 -0
- package/dist/cjs/httpPull/auth.test.native.js +279 -0
- package/dist/cjs/httpPull/auth.test.native.js.map +1 -0
- package/dist/cjs/httpPull/churn.test.cjs +132 -0
- package/dist/cjs/httpPull/churn.test.native.js +155 -0
- package/dist/cjs/httpPull/churn.test.native.js.map +1 -0
- package/dist/cjs/httpPull/completeAck.test.cjs +69 -0
- package/dist/cjs/httpPull/completeAck.test.native.js +76 -0
- package/dist/cjs/httpPull/completeAck.test.native.js.map +1 -0
- package/dist/cjs/httpPull/fixtureServer.cjs +340 -0
- package/dist/cjs/httpPull/fixtureServer.native.js +534 -0
- package/dist/cjs/httpPull/fixtureServer.native.js.map +1 -0
- package/dist/cjs/httpPull/integration.test.cjs +53 -0
- package/dist/cjs/httpPull/integration.test.native.js +60 -0
- package/dist/cjs/httpPull/integration.test.native.js.map +1 -0
- package/dist/cjs/httpPull/rebase.test.cjs +360 -0
- package/dist/cjs/httpPull/rebase.test.native.js +420 -0
- package/dist/cjs/httpPull/rebase.test.native.js.map +1 -0
- package/dist/cjs/httpPull/relations.test.cjs +107 -0
- package/dist/cjs/httpPull/relations.test.native.js +119 -0
- package/dist/cjs/httpPull/relations.test.native.js.map +1 -0
- package/dist/cjs/httpPull/testHarness.cjs +100 -0
- package/dist/cjs/httpPull/testHarness.native.js +112 -0
- package/dist/cjs/httpPull/testHarness.native.js.map +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.native.js +1 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/run.cjs +1 -1
- package/dist/cjs/run.native.js +1 -1
- package/dist/cjs/server.cjs +22 -0
- package/dist/cjs/server.native.js +4 -0
- package/dist/cjs/server.native.js.map +1 -0
- package/dist/cjs/sqliteRuntime.cjs +318 -0
- package/dist/cjs/sqliteRuntime.native.js +438 -0
- package/dist/cjs/sqliteRuntime.native.js.map +1 -0
- package/dist/cjs/state.cjs +1 -1
- package/dist/cjs/state.native.js +1 -1
- package/dist/cjs/syncHost.cjs +179 -0
- package/dist/cjs/syncHost.native.js +388 -0
- package/dist/cjs/syncHost.native.js.map +1 -0
- package/dist/cjs/syncHost.test.cjs +240 -0
- package/dist/cjs/syncHost.test.native.js +290 -0
- package/dist/cjs/syncHost.test.native.js.map +1 -0
- package/dist/cjs/zeroRunner.cjs +1 -1
- package/dist/cjs/zeroRunner.native.js +1 -1
- package/dist/esm/asyncTasks.mjs +26 -0
- package/dist/esm/asyncTasks.mjs.map +1 -0
- package/dist/esm/asyncTasks.native.js +56 -0
- package/dist/esm/asyncTasks.native.js.map +1 -0
- package/dist/esm/createZeroDirectServer.mjs +241 -0
- package/dist/esm/createZeroDirectServer.mjs.map +1 -0
- package/dist/esm/createZeroDirectServer.native.js +256 -0
- package/dist/esm/createZeroDirectServer.native.js.map +1 -0
- package/dist/esm/createZeroSQLiteServer.mjs +24 -0
- package/dist/esm/createZeroSQLiteServer.mjs.map +1 -0
- package/dist/esm/createZeroSQLiteServer.native.js +29 -0
- package/dist/esm/createZeroSQLiteServer.native.js.map +1 -0
- package/dist/esm/createZeroSQLiteServer.test.mjs +596 -0
- package/dist/esm/createZeroSQLiteServer.test.mjs.map +1 -0
- package/dist/esm/createZeroSQLiteServer.test.native.js +645 -0
- package/dist/esm/createZeroSQLiteServer.test.native.js.map +1 -0
- package/dist/esm/createZeroServer.mjs +57 -0
- package/dist/esm/createZeroServer.mjs.map +1 -0
- package/dist/esm/createZeroServer.native.js +65 -0
- package/dist/esm/createZeroServer.native.js.map +1 -0
- package/dist/esm/createZeroServer.test.mjs +379 -0
- package/dist/esm/createZeroServer.test.mjs.map +1 -0
- package/dist/esm/createZeroServer.test.native.js +446 -0
- package/dist/esm/createZeroServer.test.native.js.map +1 -0
- package/dist/esm/createZeroServerCore.mjs +186 -0
- package/dist/esm/createZeroServerCore.mjs.map +1 -0
- package/dist/esm/createZeroServerCore.native.js +327 -0
- package/dist/esm/createZeroServerCore.native.js.map +1 -0
- package/dist/esm/helpers/createMutators.mjs +3 -4
- package/dist/esm/helpers/createMutators.mjs.map +1 -1
- package/dist/esm/helpers/createMutators.native.js +3 -6
- package/dist/esm/helpers/createMutators.native.js.map +1 -1
- package/dist/esm/httpPull/auth.test.mjs +198 -0
- package/dist/esm/httpPull/auth.test.mjs.map +1 -0
- package/dist/esm/httpPull/auth.test.native.js +277 -0
- package/dist/esm/httpPull/auth.test.native.js.map +1 -0
- package/dist/esm/httpPull/churn.test.mjs +133 -0
- package/dist/esm/httpPull/churn.test.mjs.map +1 -0
- package/dist/esm/httpPull/churn.test.native.js +153 -0
- package/dist/esm/httpPull/churn.test.native.js.map +1 -0
- package/dist/esm/httpPull/completeAck.test.mjs +70 -0
- package/dist/esm/httpPull/completeAck.test.mjs.map +1 -0
- package/dist/esm/httpPull/completeAck.test.native.js +74 -0
- package/dist/esm/httpPull/completeAck.test.native.js.map +1 -0
- package/dist/esm/httpPull/fixtureServer.mjs +315 -0
- package/dist/esm/httpPull/fixtureServer.mjs.map +1 -0
- package/dist/esm/httpPull/fixtureServer.native.js +506 -0
- package/dist/esm/httpPull/fixtureServer.native.js.map +1 -0
- package/dist/esm/httpPull/integration.test.mjs +54 -0
- package/dist/esm/httpPull/integration.test.mjs.map +1 -0
- package/dist/esm/httpPull/integration.test.native.js +58 -0
- package/dist/esm/httpPull/integration.test.native.js.map +1 -0
- package/dist/esm/httpPull/rebase.test.mjs +361 -0
- package/dist/esm/httpPull/rebase.test.mjs.map +1 -0
- package/dist/esm/httpPull/rebase.test.native.js +418 -0
- package/dist/esm/httpPull/rebase.test.native.js.map +1 -0
- package/dist/esm/httpPull/relations.test.mjs +108 -0
- package/dist/esm/httpPull/relations.test.mjs.map +1 -0
- package/dist/esm/httpPull/relations.test.native.js +117 -0
- package/dist/esm/httpPull/relations.test.native.js.map +1 -0
- package/dist/esm/httpPull/testHarness.mjs +72 -0
- package/dist/esm/httpPull/testHarness.mjs.map +1 -0
- package/dist/esm/httpPull/testHarness.native.js +81 -0
- package/dist/esm/httpPull/testHarness.native.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +1 -0
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/run.mjs +1 -1
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/run.native.js +1 -1
- package/dist/esm/server.mjs +4 -0
- package/dist/esm/server.mjs.map +1 -0
- package/dist/esm/server.native.js +2 -0
- package/dist/esm/server.native.js.map +1 -0
- package/dist/esm/sqliteRuntime.mjs +289 -0
- package/dist/esm/sqliteRuntime.mjs.map +1 -0
- package/dist/esm/sqliteRuntime.native.js +406 -0
- package/dist/esm/sqliteRuntime.native.js.map +1 -0
- package/dist/esm/state.mjs +1 -1
- package/dist/esm/state.native.js +1 -1
- package/dist/esm/syncHost.mjs +153 -0
- package/dist/esm/syncHost.mjs.map +1 -0
- package/dist/esm/syncHost.native.js +359 -0
- package/dist/esm/syncHost.native.js.map +1 -0
- package/dist/esm/syncHost.test.mjs +217 -0
- package/dist/esm/syncHost.test.mjs.map +1 -0
- package/dist/esm/syncHost.test.native.js +264 -0
- package/dist/esm/syncHost.test.native.js.map +1 -0
- package/dist/esm/zeroRunner.mjs +1 -1
- package/dist/esm/zeroRunner.mjs.map +1 -1
- package/dist/esm/zeroRunner.native.js +1 -1
- package/package.json +23 -8
- package/readme.md +65 -40
- package/src/asyncTasks.ts +36 -0
- package/src/createZeroClient.tsx +1 -1
- package/src/createZeroDirectServer.ts +411 -0
- package/src/createZeroSQLiteServer.test.ts +614 -0
- package/src/createZeroSQLiteServer.ts +56 -0
- package/src/createZeroServer.test.ts +421 -0
- package/src/createZeroServer.ts +105 -0
- package/src/createZeroServerCore.ts +296 -0
- package/src/helpers/createMutators.ts +2 -6
- package/src/httpPull/auth.test.ts +208 -0
- package/src/httpPull/churn.test.ts +147 -0
- package/src/httpPull/completeAck.test.ts +80 -0
- package/src/httpPull/fixtureServer.ts +391 -0
- package/src/httpPull/integration.test.ts +57 -0
- package/src/httpPull/rebase.test.ts +368 -0
- package/src/httpPull/relations.test.ts +135 -0
- package/src/httpPull/testHarness.ts +95 -0
- package/src/index.ts +1 -0
- package/src/run.ts +1 -1
- package/src/server.native.ts +3 -0
- package/src/server.ts +4 -0
- package/src/sqliteRuntime.ts +512 -0
- package/src/state.ts +1 -1
- package/src/syncHost.test.ts +223 -0
- package/src/syncHost.ts +294 -0
- package/src/types.ts +5 -0
- package/src/zeroRunner.ts +1 -1
- package/test-fixtures/server-return-types.ts +58 -21
- package/types/asyncTasks.d.ts +11 -0
- package/types/asyncTasks.d.ts.map +1 -0
- package/types/createZeroDirectServer.d.ts +80 -0
- package/types/createZeroDirectServer.d.ts.map +1 -0
- package/types/createZeroSQLiteServer.d.ts +12 -0
- package/types/createZeroSQLiteServer.d.ts.map +1 -0
- package/types/createZeroSQLiteServer.test.d.ts +2 -0
- package/types/createZeroSQLiteServer.test.d.ts.map +1 -0
- package/types/createZeroServer.d.ts +18 -0
- package/types/createZeroServer.d.ts.map +1 -0
- package/types/createZeroServer.test.d.ts +2 -0
- package/types/createZeroServer.test.d.ts.map +1 -0
- package/types/createZeroServerCore.d.ts +256 -0
- package/types/createZeroServerCore.d.ts.map +1 -0
- package/types/helpers/createMutators.d.ts +1 -2
- package/types/helpers/createMutators.d.ts.map +1 -1
- package/types/httpPull/auth.test.d.ts +2 -0
- package/types/httpPull/auth.test.d.ts.map +1 -0
- package/types/httpPull/churn.test.d.ts +2 -0
- package/types/httpPull/churn.test.d.ts.map +1 -0
- package/types/httpPull/completeAck.test.d.ts +2 -0
- package/types/httpPull/completeAck.test.d.ts.map +1 -0
- package/types/httpPull/fixtureSchema.d.ts +1 -1
- package/types/httpPull/fixtureServer.d.ts +14 -0
- package/types/httpPull/fixtureServer.d.ts.map +1 -0
- package/types/httpPull/integration.test.d.ts +2 -0
- package/types/httpPull/integration.test.d.ts.map +1 -0
- package/types/httpPull/rebase.test.d.ts +2 -0
- package/types/httpPull/rebase.test.d.ts.map +1 -0
- package/types/httpPull/relations.test.d.ts +2 -0
- package/types/httpPull/relations.test.d.ts.map +1 -0
- package/types/httpPull/testHarness.d.ts +32 -0
- package/types/httpPull/testHarness.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/server.d.ts +5 -0
- package/types/server.d.ts.map +1 -0
- package/types/server.native.d.ts +1 -0
- package/types/server.native.d.ts.map +1 -0
- package/types/sqliteRuntime.d.ts +71 -0
- package/types/sqliteRuntime.d.ts.map +1 -0
- package/types/syncHost.d.ts +42 -0
- package/types/syncHost.d.ts.map +1 -0
- package/types/syncHost.test.d.ts +2 -0
- package/types/syncHost.test.d.ts.map +1 -0
- package/types/types.d.ts +4 -0
- package/types/types.d.ts.map +1 -1
- package/dist/cjs/orez.cjs +0 -227
- package/dist/cjs/orez.native.js +0 -314
- package/dist/cjs/orez.native.js.map +0 -1
- package/dist/cjs/orez.test.cjs +0 -211
- package/dist/cjs/orez.test.native.js +0 -226
- package/dist/cjs/orez.test.native.js.map +0 -1
- package/dist/esm/orez.mjs +0 -202
- package/dist/esm/orez.mjs.map +0 -1
- package/dist/esm/orez.native.js +0 -286
- package/dist/esm/orez.native.js.map +0 -1
- package/dist/esm/orez.test.mjs +0 -188
- package/dist/esm/orez.test.mjs.map +0 -1
- package/dist/esm/orez.test.native.js +0 -200
- package/dist/esm/orez.test.native.js.map +0 -1
- package/src/orez.test.ts +0 -195
- package/src/orez.ts +0 -331
- package/types/orez.d.ts +0 -53
- package/types/orez.d.ts.map +0 -1
- package/types/orez.test.d.ts +0 -2
- package/types/orez.test.d.ts.map +0 -1
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var import_vitest = require("vitest");
|
|
4
|
+
var import_createZeroServer = require("./createZeroServer.native.js");
|
|
5
|
+
var import_fixtureSchema = require("./httpPull/fixtureSchema.native.js");
|
|
6
|
+
function _class_call_check(instance, Constructor) {
|
|
7
|
+
if (!(instance instanceof Constructor)) {
|
|
8
|
+
throw new TypeError("Cannot call a class as a function");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function _defineProperties(target, props) {
|
|
12
|
+
for (var i = 0; i < props.length; i++) {
|
|
13
|
+
var descriptor = props[i];
|
|
14
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
15
|
+
descriptor.configurable = true;
|
|
16
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
17
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
21
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
22
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
23
|
+
return Constructor;
|
|
24
|
+
}
|
|
25
|
+
function _define_property(obj, key, value) {
|
|
26
|
+
if (key in obj) {
|
|
27
|
+
Object.defineProperty(obj, key, {
|
|
28
|
+
value,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
obj[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
var FakePgClient = /* @__PURE__ */function () {
|
|
39
|
+
"use strict";
|
|
40
|
+
|
|
41
|
+
function FakePgClient2() {
|
|
42
|
+
_class_call_check(this, FakePgClient2);
|
|
43
|
+
_define_property(this, "lastMutationID", 0);
|
|
44
|
+
_define_property(this, "pendingLastMutationID", void 0);
|
|
45
|
+
_define_property(this, "mutationResultInserts", []);
|
|
46
|
+
}
|
|
47
|
+
_create_class(FakePgClient2, [{
|
|
48
|
+
key: "query",
|
|
49
|
+
value: async function query(sql) {
|
|
50
|
+
var params = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
51
|
+
if (sql === "BEGIN") {
|
|
52
|
+
this.pendingLastMutationID = void 0;
|
|
53
|
+
return {
|
|
54
|
+
rows: []
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (sql === "COMMIT") {
|
|
58
|
+
if (this.pendingLastMutationID !== void 0) {
|
|
59
|
+
this.lastMutationID = this.pendingLastMutationID;
|
|
60
|
+
}
|
|
61
|
+
this.pendingLastMutationID = void 0;
|
|
62
|
+
return {
|
|
63
|
+
rows: []
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (sql === "ROLLBACK") {
|
|
67
|
+
this.pendingLastMutationID = void 0;
|
|
68
|
+
return {
|
|
69
|
+
rows: []
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (sql.includes(".clients") && sql.includes('RETURNING "lastMutationID"')) {
|
|
73
|
+
var nextMutationID = this.lastMutationID + 1;
|
|
74
|
+
this.pendingLastMutationID = nextMutationID;
|
|
75
|
+
return {
|
|
76
|
+
rows: [{
|
|
77
|
+
lastMutationID: nextMutationID
|
|
78
|
+
}]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (sql.includes("information_schema.columns")) {
|
|
82
|
+
return {
|
|
83
|
+
rows: [...schemaRows("user", ["id", "name"]), ...schemaRows("project", ["id", "ownerId", "name"]), ...schemaRows("member", ["id", "projectId", "userId"])]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (sql.includes('INSERT INTO "zero_0"."mutations"') || sql.includes('INSERT INTO "zero_0".mutations')) {
|
|
87
|
+
this.mutationResultInserts.push(params);
|
|
88
|
+
return {
|
|
89
|
+
rows: []
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`unexpected fake pg query: ${sql}`);
|
|
93
|
+
}
|
|
94
|
+
}]);
|
|
95
|
+
return FakePgClient2;
|
|
96
|
+
}();
|
|
97
|
+
function schemaRows(table, columns) {
|
|
98
|
+
return columns.map(function (column) {
|
|
99
|
+
return {
|
|
100
|
+
schema: "public",
|
|
101
|
+
table,
|
|
102
|
+
column,
|
|
103
|
+
dataType: "text",
|
|
104
|
+
length: null,
|
|
105
|
+
precision: null,
|
|
106
|
+
scale: null,
|
|
107
|
+
typtype: "b",
|
|
108
|
+
typename: "text",
|
|
109
|
+
elemTyptype: null,
|
|
110
|
+
elemTypname: null
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function pushRequest(mutationIDs) {
|
|
115
|
+
var ids = Array.isArray(mutationIDs) ? mutationIDs : [mutationIDs];
|
|
116
|
+
return new Request("http://localhost/push?schema=zero_0&appID=zero", {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: {
|
|
119
|
+
"content-type": "application/json"
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
clientGroupID: "cg1",
|
|
123
|
+
mutations: ids.map(function (mutationID) {
|
|
124
|
+
return {
|
|
125
|
+
type: "custom",
|
|
126
|
+
id: mutationID,
|
|
127
|
+
clientID: "client-a",
|
|
128
|
+
name: "project.touch",
|
|
129
|
+
args: [{}],
|
|
130
|
+
timestamp: 1
|
|
131
|
+
};
|
|
132
|
+
}),
|
|
133
|
+
pushVersion: 1,
|
|
134
|
+
timestamp: 1,
|
|
135
|
+
requestID: `req-${ids.join("-")}`
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
(0, import_vitest.describe)("createZeroServer mutation recovery", function () {
|
|
140
|
+
(0, import_vitest.test)("discards async tasks from a rolled-back PostgreSQL mutation", async function () {
|
|
141
|
+
var pg = new FakePgClient();
|
|
142
|
+
var effectRuns = 0;
|
|
143
|
+
var consoleWarn = import_vitest.vi.spyOn(console, "warn").mockImplementation(function () {});
|
|
144
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
145
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
146
|
+
models: {
|
|
147
|
+
project: {
|
|
148
|
+
mutate: {
|
|
149
|
+
touch: async function (param) {
|
|
150
|
+
var {
|
|
151
|
+
server
|
|
152
|
+
} = param;
|
|
153
|
+
server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
|
|
154
|
+
effectRuns++;
|
|
155
|
+
});
|
|
156
|
+
throw new Error("rejected");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
createServerActions: function () {
|
|
162
|
+
return {};
|
|
163
|
+
},
|
|
164
|
+
pool: pg
|
|
165
|
+
});
|
|
166
|
+
var result = await zeroServer.handleMutationRequest({
|
|
167
|
+
authData: null,
|
|
168
|
+
request: pushRequest(1),
|
|
169
|
+
skipAsyncTasks: true
|
|
170
|
+
});
|
|
171
|
+
(0, import_vitest.expect)(result.response.mutations[0].result).toMatchObject({
|
|
172
|
+
error: "app",
|
|
173
|
+
message: "rejected"
|
|
174
|
+
});
|
|
175
|
+
(0, import_vitest.expect)(result.asyncTasks).toEqual([]);
|
|
176
|
+
(0, import_vitest.expect)(effectRuns).toBe(0);
|
|
177
|
+
(0, import_vitest.expect)(consoleWarn).toHaveBeenCalledWith("PushProcessor", import_vitest.expect.stringContaining("Error processing mutation"), import_vitest.expect.stringContaining("rejected"));
|
|
178
|
+
consoleWarn.mockRestore();
|
|
179
|
+
});
|
|
180
|
+
(0, import_vitest.test)("awaits barrier tasks before resolving the push response", async function () {
|
|
181
|
+
var pg = new FakePgClient();
|
|
182
|
+
var releaseBarrier;
|
|
183
|
+
var markBarrierStarted;
|
|
184
|
+
var barrierStarted = new Promise(function (resolve) {
|
|
185
|
+
markBarrierStarted = resolve;
|
|
186
|
+
});
|
|
187
|
+
var barrier = new Promise(function (resolve) {
|
|
188
|
+
releaseBarrier = resolve;
|
|
189
|
+
});
|
|
190
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
191
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
192
|
+
models: {
|
|
193
|
+
project: {
|
|
194
|
+
mutate: {
|
|
195
|
+
touch: async function (param) {
|
|
196
|
+
var {
|
|
197
|
+
server
|
|
198
|
+
} = param;
|
|
199
|
+
server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
|
|
200
|
+
markBarrierStarted();
|
|
201
|
+
await barrier;
|
|
202
|
+
}, {
|
|
203
|
+
barrier: true
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
createServerActions: function () {
|
|
210
|
+
return {};
|
|
211
|
+
},
|
|
212
|
+
pool: pg
|
|
213
|
+
});
|
|
214
|
+
var responseResolved = false;
|
|
215
|
+
var resultPromise = zeroServer.handleMutationRequest({
|
|
216
|
+
authData: null,
|
|
217
|
+
request: pushRequest(1)
|
|
218
|
+
}).then(function (result2) {
|
|
219
|
+
responseResolved = true;
|
|
220
|
+
return result2;
|
|
221
|
+
});
|
|
222
|
+
await barrierStarted;
|
|
223
|
+
await Promise.resolve();
|
|
224
|
+
(0, import_vitest.expect)(responseResolved).toBe(false);
|
|
225
|
+
releaseBarrier();
|
|
226
|
+
var result = await resultPromise;
|
|
227
|
+
(0, import_vitest.expect)(result.response.mutations[0].result).toEqual({});
|
|
228
|
+
});
|
|
229
|
+
(0, import_vitest.test)("does not fail the push when a background task rejects", async function () {
|
|
230
|
+
var pg = new FakePgClient();
|
|
231
|
+
var error = new Error("background failed");
|
|
232
|
+
var consoleError = import_vitest.vi.spyOn(console, "error").mockImplementation(function () {});
|
|
233
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
234
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
235
|
+
models: {
|
|
236
|
+
project: {
|
|
237
|
+
mutate: {
|
|
238
|
+
touch: async function (param) {
|
|
239
|
+
var {
|
|
240
|
+
server
|
|
241
|
+
} = param;
|
|
242
|
+
server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
|
|
243
|
+
throw error;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
createServerActions: function () {
|
|
250
|
+
return {};
|
|
251
|
+
},
|
|
252
|
+
pool: pg
|
|
253
|
+
});
|
|
254
|
+
var result = await zeroServer.handleMutationRequest({
|
|
255
|
+
authData: null,
|
|
256
|
+
request: pushRequest(1)
|
|
257
|
+
});
|
|
258
|
+
(0, import_vitest.expect)(result.response.mutations[0].result).toEqual({});
|
|
259
|
+
await import_vitest.vi.waitFor(function () {
|
|
260
|
+
(0, import_vitest.expect)(consoleError).toHaveBeenCalledWith("[on-zero] async task failed", error);
|
|
261
|
+
});
|
|
262
|
+
consoleError.mockRestore();
|
|
263
|
+
});
|
|
264
|
+
(0, import_vitest.test)("registers a promise that settles every background task with the request scheduler", async function () {
|
|
265
|
+
var pg = new FakePgClient();
|
|
266
|
+
var error = new Error("background failed");
|
|
267
|
+
var consoleError = import_vitest.vi.spyOn(console, "error").mockImplementation(function () {});
|
|
268
|
+
var releaseSibling;
|
|
269
|
+
var siblingGate = new Promise(function (resolve) {
|
|
270
|
+
releaseSibling = resolve;
|
|
271
|
+
});
|
|
272
|
+
var siblingFinished = false;
|
|
273
|
+
var scheduled;
|
|
274
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
275
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
276
|
+
models: {
|
|
277
|
+
project: {
|
|
278
|
+
mutate: {
|
|
279
|
+
touch: async function (param) {
|
|
280
|
+
var {
|
|
281
|
+
server
|
|
282
|
+
} = param;
|
|
283
|
+
server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
|
|
284
|
+
throw error;
|
|
285
|
+
});
|
|
286
|
+
server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
|
|
287
|
+
await siblingGate;
|
|
288
|
+
siblingFinished = true;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
createServerActions: function () {
|
|
295
|
+
return {};
|
|
296
|
+
},
|
|
297
|
+
pool: pg
|
|
298
|
+
});
|
|
299
|
+
var result = await zeroServer.handleMutationRequest({
|
|
300
|
+
authData: null,
|
|
301
|
+
request: pushRequest(1),
|
|
302
|
+
scheduleBackgroundTask: function (promise) {
|
|
303
|
+
scheduled = promise;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
(0, import_vitest.expect)(result.response.mutations[0].result).toEqual({});
|
|
307
|
+
(0, import_vitest.expect)(scheduled).toBeInstanceOf(Promise);
|
|
308
|
+
(0, import_vitest.expect)(siblingFinished).toBe(false);
|
|
309
|
+
var scheduledSettled = false;
|
|
310
|
+
void scheduled.then(function () {
|
|
311
|
+
scheduledSettled = true;
|
|
312
|
+
});
|
|
313
|
+
await Promise.resolve();
|
|
314
|
+
(0, import_vitest.expect)(scheduledSettled).toBe(false);
|
|
315
|
+
releaseSibling();
|
|
316
|
+
await scheduled;
|
|
317
|
+
(0, import_vitest.expect)(siblingFinished).toBe(true);
|
|
318
|
+
(0, import_vitest.expect)(consoleError).toHaveBeenCalledWith("[on-zero] async task failed", error);
|
|
319
|
+
consoleError.mockRestore();
|
|
320
|
+
});
|
|
321
|
+
(0, import_vitest.test)("awaits background tasks when the request has no scheduler", async function () {
|
|
322
|
+
var pg = new FakePgClient();
|
|
323
|
+
var markTaskStarted;
|
|
324
|
+
var taskStarted = new Promise(function (resolve) {
|
|
325
|
+
markTaskStarted = resolve;
|
|
326
|
+
});
|
|
327
|
+
var releaseTask;
|
|
328
|
+
var taskGate = new Promise(function (resolve) {
|
|
329
|
+
releaseTask = resolve;
|
|
330
|
+
});
|
|
331
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
332
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
333
|
+
models: {
|
|
334
|
+
project: {
|
|
335
|
+
mutate: {
|
|
336
|
+
touch: async function (param) {
|
|
337
|
+
var {
|
|
338
|
+
server
|
|
339
|
+
} = param;
|
|
340
|
+
server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
|
|
341
|
+
markTaskStarted();
|
|
342
|
+
await taskGate;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
createServerActions: function () {
|
|
349
|
+
return {};
|
|
350
|
+
},
|
|
351
|
+
pool: pg
|
|
352
|
+
});
|
|
353
|
+
var responseResolved = false;
|
|
354
|
+
var resultPromise = zeroServer.handleMutationRequest({
|
|
355
|
+
authData: null,
|
|
356
|
+
request: pushRequest(1)
|
|
357
|
+
}).then(function (result2) {
|
|
358
|
+
responseResolved = true;
|
|
359
|
+
return result2;
|
|
360
|
+
});
|
|
361
|
+
await taskStarted;
|
|
362
|
+
await Promise.resolve();
|
|
363
|
+
(0, import_vitest.expect)(responseResolved).toBe(false);
|
|
364
|
+
releaseTask();
|
|
365
|
+
var result = await resultPromise;
|
|
366
|
+
(0, import_vitest.expect)(result.response.mutations[0].result).toEqual({});
|
|
367
|
+
});
|
|
368
|
+
(0, import_vitest.test)("persists alreadyProcessed duplicate results for zero-cache recovery rows", async function () {
|
|
369
|
+
var pg = new FakePgClient();
|
|
370
|
+
var consoleWarn = import_vitest.vi.spyOn(console, "warn").mockImplementation(function () {});
|
|
371
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
372
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
373
|
+
models: {
|
|
374
|
+
project: {
|
|
375
|
+
mutate: {
|
|
376
|
+
touch: async function () {}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
createServerActions: function () {
|
|
381
|
+
return {};
|
|
382
|
+
},
|
|
383
|
+
pool: pg
|
|
384
|
+
});
|
|
385
|
+
var first = await zeroServer.handleMutationRequest({
|
|
386
|
+
authData: null,
|
|
387
|
+
request: pushRequest(1)
|
|
388
|
+
});
|
|
389
|
+
(0, import_vitest.expect)(first.response.mutations[0].result).toEqual({});
|
|
390
|
+
(0, import_vitest.expect)(pg.lastMutationID).toBe(1);
|
|
391
|
+
(0, import_vitest.expect)(pg.mutationResultInserts).toEqual([]);
|
|
392
|
+
var duplicate = await zeroServer.handleMutationRequest({
|
|
393
|
+
authData: null,
|
|
394
|
+
request: pushRequest(1)
|
|
395
|
+
});
|
|
396
|
+
var duplicateResult = duplicate.response.mutations[0].result;
|
|
397
|
+
(0, import_vitest.expect)(duplicateResult.error).toBe("alreadyProcessed");
|
|
398
|
+
(0, import_vitest.expect)(pg.lastMutationID).toBe(1);
|
|
399
|
+
(0, import_vitest.expect)(pg.mutationResultInserts).toEqual([["cg1", "client-a", 1, JSON.stringify({
|
|
400
|
+
error: "alreadyProcessed",
|
|
401
|
+
details: duplicateResult.details
|
|
402
|
+
})]]);
|
|
403
|
+
(0, import_vitest.expect)(consoleWarn).not.toHaveBeenCalled();
|
|
404
|
+
consoleWarn.mockRestore();
|
|
405
|
+
});
|
|
406
|
+
(0, import_vitest.test)("persists only alreadyProcessed results in a mixed recovery push", async function () {
|
|
407
|
+
var pg = new FakePgClient();
|
|
408
|
+
var zeroServer = (0, import_createZeroServer.createZeroServer)({
|
|
409
|
+
schema: import_fixtureSchema.zeroHttpFixtureSchema,
|
|
410
|
+
models: {
|
|
411
|
+
project: {
|
|
412
|
+
mutate: {
|
|
413
|
+
touch: async function () {}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
createServerActions: function () {
|
|
418
|
+
return {};
|
|
419
|
+
},
|
|
420
|
+
pool: pg
|
|
421
|
+
});
|
|
422
|
+
await zeroServer.handleMutationRequest({
|
|
423
|
+
authData: null,
|
|
424
|
+
request: pushRequest(1)
|
|
425
|
+
});
|
|
426
|
+
var mixed = await zeroServer.handleMutationRequest({
|
|
427
|
+
authData: null,
|
|
428
|
+
request: pushRequest([1, 2])
|
|
429
|
+
});
|
|
430
|
+
var results = mixed.response.mutations.map(function (mutation) {
|
|
431
|
+
return {
|
|
432
|
+
id: mutation.id.id,
|
|
433
|
+
result: mutation.result
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
(0, import_vitest.expect)(results[0].result.error).toBe("alreadyProcessed");
|
|
437
|
+
(0, import_vitest.expect)(results[1]).toEqual({
|
|
438
|
+
id: 2,
|
|
439
|
+
result: {}
|
|
440
|
+
});
|
|
441
|
+
(0, import_vitest.expect)(pg.lastMutationID).toBe(2);
|
|
442
|
+
(0, import_vitest.expect)(pg.mutationResultInserts).toEqual([["cg1", "client-a", 1, JSON.stringify({
|
|
443
|
+
error: "alreadyProcessed",
|
|
444
|
+
details: results[0].result.details
|
|
445
|
+
})]]);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
//# sourceMappingURL=createZeroServer.test.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["import_vitest","require","import_createZeroServer","import_fixtureSchema","_class_call_check","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","Object","defineProperty","key","_create_class","protoProps","staticProps","prototype","_define_property","obj","value","FakePgClient","FakePgClient2","query","sql","params","arguments","pendingLastMutationID","rows","lastMutationID","includes","nextMutationID","schemaRows","mutationResultInserts","push","Error","table","columns","map","column","schema","dataType","precision","scale","typtype","typename","elemTyptype","elemTypname","pushRequest","mutationIDs","ids","Array","isArray","Request","method","headers","body","JSON","stringify","clientGroupID","mutations","mutationID","type","id","clientID","name","args","timestamp","pushVersion","requestID","join","describe","test","pg","effectRuns","consoleWarn","vi","spyOn","console","mockImplementation","zeroServer","createZeroServer","zeroHttpFixtureSchema","models","project","mutate","touch","param","server","enqueueTask","createServerActions","pool","result","handleMutationRequest","authData","request","skipAsyncTasks","expect","response","toMatchObject","error","message","asyncTasks","toEqual","toBe","toHaveBeenCalledWith","stringContaining","mockRestore","releaseBarrier","markBarrierStarted","barrierStarted","Promise","resolve","barrier","responseResolved","resultPromise","then","result2","consoleError","waitFor","releaseSibling","siblingGate","siblingFinished","scheduled","scheduleBackgroundTask","promise","toBeInstanceOf","scheduledSettled","markTaskStarted","taskStarted","releaseTask","taskGate"],"sources":["../../src/createZeroServer.test.ts"],"sourcesContent":[null],"mappings":"AAAA;;AAEA,IAAAA,aAAA,GAAAC,OAAA,SAAiC;AACjC,IAAAC,uBAAsC,GAAAD,OAAA;AAEtC,IAAAE,oBAAmB,GAAAF,OAAA;AAAA,SACjBG,iBAAiBA,CAAAC,QAAA,EAAAC,WAAA;EACj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AAA,EAAAlB;IACA;IACA,IAAAyC,gBAAA,QAAO;IACP,IAAAC,aAAA,GAAAnC,UAAU,CAAAa,qBAAuB;MAC/BC,QAAA;MAAAC,OACE,EAAA/C,WAAA;IAAA,GAAAoE,IACA,WAAAC,OAAA;MAAAH,gBACA;MAAA,OACKG,OAAA;IAAU;IACN,MACPY,WAAS;IAAkB,MAC5BlB,OAAA,CAAAC,OAAA;IAAA,EACH,EAAAtH,aAAA,CAAAuG,MAAA,EAAAiB,gBAAA,EAAAV,IAAA;IACF0B,WAAC;IACF,IAAAtC,MAAA,SAAAuB,aAAA;IACF,IAAAzH,aAAA,CAAAuG,MAAA,EAAAL,MAAA,CAAAM,QAAA,CAAAtC,SAAA,IAAAgC,MAAA,EAAAW,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var createZeroServerCore_exports = {};
|
|
24
|
+
__export(createZeroServerCore_exports, {
|
|
25
|
+
createZeroServerCore: () => createZeroServerCore
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(createZeroServerCore_exports);
|
|
28
|
+
var import_server = require("@rocicorp/zero/server");
|
|
29
|
+
var import_asyncTasks = require("./asyncTasks.cjs");
|
|
30
|
+
var import_createZeroDirectServer = require("./createZeroDirectServer.cjs");
|
|
31
|
+
var import_createMutators = require("./helpers/createMutators.cjs");
|
|
32
|
+
var import_mutatorContext = require("./helpers/mutatorContext.cjs");
|
|
33
|
+
var import_queryContext = require("./helpers/queryContext.cjs");
|
|
34
|
+
function createZeroServerCore({
|
|
35
|
+
createDatabase,
|
|
36
|
+
createServerActions,
|
|
37
|
+
defaultAllowAdminRole = "all",
|
|
38
|
+
defaultMutateAuthData,
|
|
39
|
+
models,
|
|
40
|
+
mutations: mutationValidators,
|
|
41
|
+
persistAlreadyProcessed,
|
|
42
|
+
queries,
|
|
43
|
+
schema,
|
|
44
|
+
validateMutation,
|
|
45
|
+
validateQuery
|
|
46
|
+
}) {
|
|
47
|
+
const {
|
|
48
|
+
permissions,
|
|
49
|
+
server
|
|
50
|
+
} = (0, import_createZeroDirectServer.createZeroDirectServerRuntime)({
|
|
51
|
+
createDatabase,
|
|
52
|
+
createServerActions,
|
|
53
|
+
defaultAllowAdminRole,
|
|
54
|
+
defaultMutateAuthData,
|
|
55
|
+
models,
|
|
56
|
+
mutations: mutationValidators,
|
|
57
|
+
queries,
|
|
58
|
+
schema,
|
|
59
|
+
validateMutation,
|
|
60
|
+
validateQuery
|
|
61
|
+
});
|
|
62
|
+
const handleMutationRequest = async ({
|
|
63
|
+
authData,
|
|
64
|
+
request,
|
|
65
|
+
scheduleBackgroundTask,
|
|
66
|
+
skipAsyncTasks
|
|
67
|
+
}) => {
|
|
68
|
+
const tasks = (0, import_createZeroDirectServer.createAsyncTaskCollector)();
|
|
69
|
+
const recoveryRequest = request.clone();
|
|
70
|
+
const mutators = (0, import_createMutators.createMutators)({
|
|
71
|
+
enqueueTask: tasks.enqueueTask,
|
|
72
|
+
can: permissions.can,
|
|
73
|
+
createServerActions,
|
|
74
|
+
environment: "server",
|
|
75
|
+
models,
|
|
76
|
+
authData,
|
|
77
|
+
validateMutation,
|
|
78
|
+
mutationValidators
|
|
79
|
+
});
|
|
80
|
+
const processor = new import_server.PushProcessor(withTransactionLifecycle(createDatabase(), tasks.lifecycle));
|
|
81
|
+
const response = await processor.process(mutators, request);
|
|
82
|
+
if (persistAlreadyProcessed) {
|
|
83
|
+
const parsed = await parseAlreadyProcessed(recoveryRequest, response);
|
|
84
|
+
if (parsed) await persistAlreadyProcessed(parsed);
|
|
85
|
+
}
|
|
86
|
+
if (!skipAsyncTasks && tasks.committed.length) {
|
|
87
|
+
const entries = tasks.committed.map(entry => ({
|
|
88
|
+
...entry,
|
|
89
|
+
task: () => (0, import_mutatorContext.runWithAuthScope)(authData, entry.task)
|
|
90
|
+
}));
|
|
91
|
+
await (0, import_asyncTasks.runAsyncTaskEntries)(entries, {
|
|
92
|
+
background: scheduleBackgroundTask
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
response,
|
|
97
|
+
asyncTasks: tasks.committed
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const handleQueryRequest = async ({
|
|
101
|
+
authData,
|
|
102
|
+
request
|
|
103
|
+
}) => {
|
|
104
|
+
if (!queries) {
|
|
105
|
+
throw new Error("No queries registered with createZeroServer. Pass the syncedQueries registry to createZeroServer via the queries option.");
|
|
106
|
+
}
|
|
107
|
+
const handler = (name, args) => (0, import_createZeroDirectServer.resolveServerQuery)({
|
|
108
|
+
authData,
|
|
109
|
+
name,
|
|
110
|
+
args,
|
|
111
|
+
queries,
|
|
112
|
+
permissions,
|
|
113
|
+
validateQuery
|
|
114
|
+
});
|
|
115
|
+
const userID = typeof authData?.id === "string" ? authData.id : void 0;
|
|
116
|
+
const response = await (0, import_queryContext.runWithQueryContext)({
|
|
117
|
+
authData: authData || {}
|
|
118
|
+
}, () =>
|
|
119
|
+
// the legacy overload omits userID when auth does not identify a user.
|
|
120
|
+
userID === void 0 ? (0, import_server.handleQueryRequest)(handler, schema, request) : (0, import_server.handleQueryRequest)({
|
|
121
|
+
handler,
|
|
122
|
+
schema,
|
|
123
|
+
request,
|
|
124
|
+
userID
|
|
125
|
+
}));
|
|
126
|
+
return {
|
|
127
|
+
response
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
handleMutationRequest,
|
|
132
|
+
handleQueryRequest,
|
|
133
|
+
...server
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function withTransactionLifecycle(database, lifecycle) {
|
|
137
|
+
return {
|
|
138
|
+
async transaction(callback, input) {
|
|
139
|
+
try {
|
|
140
|
+
const value = await database.transaction(async (tx, hooks) => {
|
|
141
|
+
lifecycle.beginAttempt();
|
|
142
|
+
try {
|
|
143
|
+
const result = await callback(tx, {
|
|
144
|
+
...hooks,
|
|
145
|
+
async updateClientMutationID() {
|
|
146
|
+
const result2 = await hooks.updateClientMutationID();
|
|
147
|
+
if (input && input.mutationID < result2.lastMutationID) {
|
|
148
|
+
throw new ExpectedDuplicateMutation(input.clientID, input.mutationID, result2.lastMutationID);
|
|
149
|
+
}
|
|
150
|
+
return result2;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
lifecycle.completeAttempt();
|
|
154
|
+
return result;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
lifecycle.rollbackAttempt();
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}, input);
|
|
160
|
+
lifecycle.commitTransaction();
|
|
161
|
+
return value;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
lifecycle.rollbackTransaction();
|
|
164
|
+
if (error instanceof ExpectedDuplicateMutation) {
|
|
165
|
+
return {
|
|
166
|
+
id: {
|
|
167
|
+
clientID: error.clientID,
|
|
168
|
+
id: error.mutationID
|
|
169
|
+
},
|
|
170
|
+
result: {
|
|
171
|
+
error: "alreadyProcessed",
|
|
172
|
+
details: error.message
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
class ExpectedDuplicateMutation extends Error {
|
|
182
|
+
constructor(clientID, mutationID, expectedMutationID) {
|
|
183
|
+
super(`Ignoring mutation from ${clientID} with ID ${mutationID} as it was already processed. Expected: ${expectedMutationID}`);
|
|
184
|
+
this.clientID = clientID;
|
|
185
|
+
this.mutationID = mutationID;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function parseAlreadyProcessed(request, response) {
|
|
189
|
+
const mutations = alreadyProcessedMutations(response);
|
|
190
|
+
if (mutations.length === 0) return;
|
|
191
|
+
const upstreamSchema = new URL(request.url).searchParams.get("schema");
|
|
192
|
+
if (!upstreamSchema) return;
|
|
193
|
+
const body = await request.json();
|
|
194
|
+
if (typeof body.clientGroupID !== "string") return;
|
|
195
|
+
return {
|
|
196
|
+
clientGroupID: body.clientGroupID,
|
|
197
|
+
mutations,
|
|
198
|
+
upstreamSchema
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function alreadyProcessedMutations(response) {
|
|
202
|
+
if (!response || typeof response !== "object") return [];
|
|
203
|
+
const mutations = response.mutations;
|
|
204
|
+
if (!Array.isArray(mutations)) return [];
|
|
205
|
+
return mutations.filter(mutation => {
|
|
206
|
+
if (!mutation || typeof mutation !== "object") return false;
|
|
207
|
+
const id = mutation.id;
|
|
208
|
+
const result = mutation.result;
|
|
209
|
+
return !!id && typeof id === "object" && typeof id.clientID === "string" && typeof id.id === "number" && !!result && typeof result === "object" && result.error === "alreadyProcessed";
|
|
210
|
+
});
|
|
211
|
+
}
|