on-zero 0.6.18 → 0.6.19
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.native.js.map +1 -1
- package/dist/cjs/createZeroClient.cjs +1 -28
- package/dist/cjs/createZeroClient.connection.test.cjs +11 -40
- package/dist/cjs/createZeroClient.connection.test.native.js +11 -40
- package/dist/cjs/createZeroClient.connection.test.native.js.map +1 -1
- package/dist/cjs/createZeroClient.native.js +1 -29
- package/dist/cjs/createZeroClient.native.js.map +1 -1
- package/dist/cjs/createZeroDirectServer.cjs +1 -1
- package/dist/cjs/createZeroDirectServer.native.js +1 -1
- package/dist/cjs/createZeroDirectServer.native.js.map +1 -1
- package/dist/cjs/createZeroServer.test.cjs +6 -0
- package/dist/cjs/createZeroServer.test.native.js +6 -0
- package/dist/cjs/createZeroServer.test.native.js.map +1 -1
- package/dist/cjs/createZeroServerCore.cjs +29 -1
- package/dist/cjs/createZeroServerCore.native.js +153 -1
- package/dist/cjs/createZeroServerCore.native.js.map +1 -1
- package/dist/cjs/httpPull/transport.test.cjs +127 -15
- package/dist/cjs/httpPull/transport.test.native.js +161 -16
- package/dist/cjs/httpPull/transport.test.native.js.map +1 -1
- package/dist/cjs/httpPullTransport.cjs +48 -18
- package/dist/cjs/httpPullTransport.native.js +57 -20
- package/dist/cjs/httpPullTransport.native.js.map +1 -1
- package/dist/cjs/modelRegistry.cjs +7 -4
- package/dist/cjs/modelRegistry.native.js +8 -4
- package/dist/cjs/modelRegistry.native.js.map +1 -1
- package/dist/cjs/mutations.cjs +15 -11
- package/dist/cjs/mutations.native.js +17 -11
- package/dist/cjs/mutations.native.js.map +1 -1
- package/dist/cjs/state.cjs +2 -3
- package/dist/cjs/state.native.js +2 -3
- package/dist/cjs/state.native.js.map +1 -1
- package/dist/cjs/syncHost.cjs +2 -1
- package/dist/cjs/syncHost.native.js +2 -1
- package/dist/cjs/syncHost.native.js.map +1 -1
- package/dist/cjs/usePermission.test.cjs +4 -2
- package/dist/cjs/usePermission.test.native.js +4 -2
- package/dist/cjs/usePermission.test.native.js.map +1 -1
- package/dist/esm/asyncTasks.mjs.map +1 -1
- package/dist/esm/asyncTasks.native.js.map +1 -1
- package/dist/esm/createZeroClient.connection.test.mjs +11 -40
- package/dist/esm/createZeroClient.connection.test.mjs.map +1 -1
- package/dist/esm/createZeroClient.connection.test.native.js +11 -40
- package/dist/esm/createZeroClient.connection.test.native.js.map +1 -1
- package/dist/esm/createZeroClient.mjs +2 -29
- package/dist/esm/createZeroClient.mjs.map +1 -1
- package/dist/esm/createZeroClient.native.js +2 -30
- package/dist/esm/createZeroClient.native.js.map +1 -1
- package/dist/esm/createZeroDirectServer.mjs +2 -2
- package/dist/esm/createZeroDirectServer.mjs.map +1 -1
- package/dist/esm/createZeroDirectServer.native.js +2 -2
- package/dist/esm/createZeroDirectServer.native.js.map +1 -1
- package/dist/esm/createZeroServer.test.mjs +6 -0
- package/dist/esm/createZeroServer.test.mjs.map +1 -1
- package/dist/esm/createZeroServer.test.native.js +6 -0
- package/dist/esm/createZeroServer.test.native.js.map +1 -1
- package/dist/esm/createZeroServerCore.mjs +29 -1
- package/dist/esm/createZeroServerCore.mjs.map +1 -1
- package/dist/esm/createZeroServerCore.native.js +153 -1
- package/dist/esm/createZeroServerCore.native.js.map +1 -1
- package/dist/esm/httpPull/transport.test.mjs +127 -15
- package/dist/esm/httpPull/transport.test.mjs.map +1 -1
- package/dist/esm/httpPull/transport.test.native.js +161 -16
- package/dist/esm/httpPull/transport.test.native.js.map +1 -1
- package/dist/esm/httpPullTransport.mjs +48 -18
- package/dist/esm/httpPullTransport.mjs.map +1 -1
- package/dist/esm/httpPullTransport.native.js +57 -20
- package/dist/esm/httpPullTransport.native.js.map +1 -1
- package/dist/esm/modelRegistry.mjs +7 -4
- package/dist/esm/modelRegistry.mjs.map +1 -1
- package/dist/esm/modelRegistry.native.js +8 -4
- package/dist/esm/modelRegistry.native.js.map +1 -1
- package/dist/esm/mutations.mjs +15 -11
- package/dist/esm/mutations.mjs.map +1 -1
- package/dist/esm/mutations.native.js +17 -11
- package/dist/esm/mutations.native.js.map +1 -1
- package/dist/esm/state.mjs +2 -3
- package/dist/esm/state.mjs.map +1 -1
- package/dist/esm/state.native.js +2 -3
- package/dist/esm/state.native.js.map +1 -1
- package/dist/esm/syncHost.mjs +2 -1
- package/dist/esm/syncHost.mjs.map +1 -1
- package/dist/esm/syncHost.native.js +2 -1
- package/dist/esm/syncHost.native.js.map +1 -1
- package/dist/esm/usePermission.test.mjs +6 -4
- package/dist/esm/usePermission.test.mjs.map +1 -1
- package/dist/esm/usePermission.test.native.js +6 -4
- package/dist/esm/usePermission.test.native.js.map +1 -1
- package/package.json +2 -2
- package/src/asyncTasks.ts +4 -1
- package/src/createZeroClient.connection.test.tsx +11 -35
- package/src/createZeroClient.tsx +7 -40
- package/src/createZeroDirectServer.ts +2 -2
- package/src/createZeroServer.test.ts +10 -0
- package/src/createZeroServerCore.ts +38 -1
- package/src/httpPull/transport.test.ts +143 -16
- package/src/httpPullTransport.ts +67 -30
- package/src/modelRegistry.ts +9 -4
- package/src/mutations.ts +19 -15
- package/src/state.ts +3 -3
- package/src/syncHost.ts +2 -2
- package/src/usePermission.test.ts +9 -3
- package/test-fixtures/server-return-types.ts +13 -1
- package/types/asyncTasks.d.ts +5 -1
- package/types/asyncTasks.d.ts.map +1 -1
- package/types/createZeroClient.d.ts.map +1 -1
- package/types/createZeroServerCore.d.ts.map +1 -1
- package/types/httpPullTransport.d.ts +13 -0
- package/types/httpPullTransport.d.ts.map +1 -1
- package/types/modelRegistry.d.ts.map +1 -1
- package/types/mutations.d.ts.map +1 -1
- package/types/state.d.ts +2 -2
- package/types/state.d.ts.map +1 -1
- package/types/syncHost.d.ts +1 -1
- package/types/syncHost.d.ts.map +1 -1
|
@@ -140,7 +140,16 @@ function withTransactionLifecycle(database, lifecycle) {
|
|
|
140
140
|
const value = await database.transaction(async (tx, hooks) => {
|
|
141
141
|
lifecycle.beginAttempt();
|
|
142
142
|
try {
|
|
143
|
-
const result = await callback(tx,
|
|
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
|
+
});
|
|
144
153
|
lifecycle.completeAttempt();
|
|
145
154
|
return result;
|
|
146
155
|
} catch (error) {
|
|
@@ -152,11 +161,30 @@ function withTransactionLifecycle(database, lifecycle) {
|
|
|
152
161
|
return value;
|
|
153
162
|
} catch (error) {
|
|
154
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
|
+
}
|
|
155
176
|
throw error;
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
};
|
|
159
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
|
+
}
|
|
160
188
|
async function parseAlreadyProcessed(request, response) {
|
|
161
189
|
const mutations = alreadyProcessedMutations(response);
|
|
162
190
|
if (mutations.length === 0) return;
|
|
@@ -33,11 +33,130 @@ var import_createZeroDirectServer = require("./createZeroDirectServer.native.js"
|
|
|
33
33
|
var import_createMutators = require("./helpers/createMutators.native.js");
|
|
34
34
|
var import_mutatorContext = require("./helpers/mutatorContext.native.js");
|
|
35
35
|
var import_queryContext = require("./helpers/queryContext.native.js");
|
|
36
|
+
function _assert_this_initialized(self) {
|
|
37
|
+
if (self === void 0) {
|
|
38
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
39
|
+
}
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
function _call_super(_this, derived, args) {
|
|
43
|
+
derived = _get_prototype_of(derived);
|
|
44
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
45
|
+
}
|
|
46
|
+
function _class_call_check(instance, Constructor) {
|
|
47
|
+
if (!(instance instanceof Constructor)) {
|
|
48
|
+
throw new TypeError("Cannot call a class as a function");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function _construct(Parent, args, Class) {
|
|
52
|
+
if (_is_native_reflect_construct()) {
|
|
53
|
+
_construct = Reflect.construct;
|
|
54
|
+
} else {
|
|
55
|
+
_construct = function construct(Parent2, args2, Class2) {
|
|
56
|
+
var a = [null];
|
|
57
|
+
a.push.apply(a, args2);
|
|
58
|
+
var Constructor = Function.bind.apply(Parent2, a);
|
|
59
|
+
var instance = new Constructor();
|
|
60
|
+
if (Class2) _set_prototype_of(instance, Class2.prototype);
|
|
61
|
+
return instance;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return _construct.apply(null, arguments);
|
|
65
|
+
}
|
|
66
|
+
function _define_property(obj, key, value) {
|
|
67
|
+
if (key in obj) {
|
|
68
|
+
Object.defineProperty(obj, key, {
|
|
69
|
+
value,
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
obj[key] = value;
|
|
76
|
+
}
|
|
77
|
+
return obj;
|
|
78
|
+
}
|
|
79
|
+
function _get_prototype_of(o) {
|
|
80
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
|
|
81
|
+
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
82
|
+
};
|
|
83
|
+
return _get_prototype_of(o);
|
|
84
|
+
}
|
|
85
|
+
function _inherits(subClass, superClass) {
|
|
86
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
87
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
88
|
+
}
|
|
89
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
90
|
+
constructor: {
|
|
91
|
+
value: subClass,
|
|
92
|
+
writable: true,
|
|
93
|
+
configurable: true
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
97
|
+
}
|
|
98
|
+
function _instanceof(left, right) {
|
|
99
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
100
|
+
return !!right[Symbol.hasInstance](left);
|
|
101
|
+
} else {
|
|
102
|
+
return left instanceof right;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function _is_native_function(fn) {
|
|
106
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
107
|
+
}
|
|
108
|
+
function _possible_constructor_return(self, call) {
|
|
109
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
110
|
+
return call;
|
|
111
|
+
}
|
|
112
|
+
return _assert_this_initialized(self);
|
|
113
|
+
}
|
|
114
|
+
function _set_prototype_of(o, p) {
|
|
115
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
|
|
116
|
+
o2.__proto__ = p2;
|
|
117
|
+
return o2;
|
|
118
|
+
};
|
|
119
|
+
return _set_prototype_of(o, p);
|
|
120
|
+
}
|
|
36
121
|
function _type_of(obj) {
|
|
37
122
|
"@swc/helpers - typeof";
|
|
38
123
|
|
|
39
124
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
40
125
|
}
|
|
126
|
+
function _wrap_native_super(Class) {
|
|
127
|
+
var _cache = typeof Map === "function" ? /* @__PURE__ */new Map() : void 0;
|
|
128
|
+
_wrap_native_super = function wrapNativeSuper(Class2) {
|
|
129
|
+
if (Class2 === null || !_is_native_function(Class2)) return Class2;
|
|
130
|
+
if (typeof Class2 !== "function") {
|
|
131
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
132
|
+
}
|
|
133
|
+
if (typeof _cache !== "undefined") {
|
|
134
|
+
if (_cache.has(Class2)) return _cache.get(Class2);
|
|
135
|
+
_cache.set(Class2, Wrapper);
|
|
136
|
+
}
|
|
137
|
+
function Wrapper() {
|
|
138
|
+
return _construct(Class2, arguments, _get_prototype_of(this).constructor);
|
|
139
|
+
}
|
|
140
|
+
Wrapper.prototype = Object.create(Class2.prototype, {
|
|
141
|
+
constructor: {
|
|
142
|
+
value: Wrapper,
|
|
143
|
+
enumerable: false,
|
|
144
|
+
writable: true,
|
|
145
|
+
configurable: true
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return _set_prototype_of(Wrapper, Class2);
|
|
149
|
+
};
|
|
150
|
+
return _wrap_native_super(Class);
|
|
151
|
+
}
|
|
152
|
+
function _is_native_reflect_construct() {
|
|
153
|
+
try {
|
|
154
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
155
|
+
} catch (_) {}
|
|
156
|
+
return (_is_native_reflect_construct = function () {
|
|
157
|
+
return !!result;
|
|
158
|
+
})();
|
|
159
|
+
}
|
|
41
160
|
function createZeroServerCore(param) {
|
|
42
161
|
var {
|
|
43
162
|
createDatabase,
|
|
@@ -159,7 +278,16 @@ function withTransactionLifecycle(database, lifecycle) {
|
|
|
159
278
|
var value = await database.transaction(async function (tx, hooks) {
|
|
160
279
|
lifecycle.beginAttempt();
|
|
161
280
|
try {
|
|
162
|
-
var result = await callback(tx,
|
|
281
|
+
var result = await callback(tx, {
|
|
282
|
+
...hooks,
|
|
283
|
+
async updateClientMutationID() {
|
|
284
|
+
var result2 = await hooks.updateClientMutationID();
|
|
285
|
+
if (input && input.mutationID < result2.lastMutationID) {
|
|
286
|
+
throw new ExpectedDuplicateMutation(input.clientID, input.mutationID, result2.lastMutationID);
|
|
287
|
+
}
|
|
288
|
+
return result2;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
163
291
|
lifecycle.completeAttempt();
|
|
164
292
|
return result;
|
|
165
293
|
} catch (error) {
|
|
@@ -171,11 +299,35 @@ function withTransactionLifecycle(database, lifecycle) {
|
|
|
171
299
|
return value;
|
|
172
300
|
} catch (error) {
|
|
173
301
|
lifecycle.rollbackTransaction();
|
|
302
|
+
if (_instanceof(error, ExpectedDuplicateMutation)) {
|
|
303
|
+
return {
|
|
304
|
+
id: {
|
|
305
|
+
clientID: error.clientID,
|
|
306
|
+
id: error.mutationID
|
|
307
|
+
},
|
|
308
|
+
result: {
|
|
309
|
+
error: "alreadyProcessed",
|
|
310
|
+
details: error.message
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
174
314
|
throw error;
|
|
175
315
|
}
|
|
176
316
|
}
|
|
177
317
|
};
|
|
178
318
|
}
|
|
319
|
+
var ExpectedDuplicateMutation = /* @__PURE__ */function (Error1) {
|
|
320
|
+
"use strict";
|
|
321
|
+
|
|
322
|
+
_inherits(ExpectedDuplicateMutation2, Error1);
|
|
323
|
+
function ExpectedDuplicateMutation2(clientID, mutationID, expectedMutationID) {
|
|
324
|
+
_class_call_check(this, ExpectedDuplicateMutation2);
|
|
325
|
+
var _this;
|
|
326
|
+
_this = _call_super(this, ExpectedDuplicateMutation2, [`Ignoring mutation from ${clientID} with ID ${mutationID} as it was already processed. Expected: ${expectedMutationID}`]), _define_property(_this, "clientID", void 0), _define_property(_this, "mutationID", void 0), _this.clientID = clientID, _this.mutationID = mutationID;
|
|
327
|
+
return _this;
|
|
328
|
+
}
|
|
329
|
+
return ExpectedDuplicateMutation2;
|
|
330
|
+
}(_wrap_native_super(Error));
|
|
179
331
|
async function parseAlreadyProcessed(request, response) {
|
|
180
332
|
var mutations = alreadyProcessedMutations(response);
|
|
181
333
|
if (mutations.length === 0) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createZeroServerCore_exports","__export","createZeroServerCore","module","exports","import_server","require","import_asyncTasks","import_createZeroDirectServer","import_createMutators","import_mutatorContext","import_queryContext","
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","createZeroServerCore_exports","__export","createZeroServerCore","module","exports","import_server","require","import_asyncTasks","import_createZeroDirectServer","import_createMutators","import_mutatorContext","import_queryContext","_assert_this_initialized","self","ReferenceError","_call_super","_this","derived","args","_get_prototype_of","_possible_constructor_return","_is_native_reflect_construct","Reflect","construct","constructor","apply","_class_call_check","instance","Constructor","TypeError","_construct","Parent","Class","Parent2","args2","Class2","a","push","Function","bind","_set_prototype_of","prototype","arguments","_define_property","obj","key","Object","defineProperty","enumerable","configurable","writable","o","setPrototypeOf","getPrototypeOf","o2","__proto__","_inherits","subClass","superClass","create","_instanceof","left","right","Symbol","hasInstance","_is_native_function","fn","toString","call","indexOf","_type_of","p","p2","_wrap_native_super","_cache","Map","wrapNativeSuper","has","get","set","Wrapper","result","Boolean","valueOf","_","param","createDatabase","createServerActions","defaultAllowAdminRole","defaultMutateAuthData","models","mutations","mutationValidators","persistAlreadyProcessed","queries","schema","validateMutation","validateQuery","permissions","server","createZeroDirectServerRuntime","handleMutationRequest","param2","authData","request","scheduleBackgroundTask","skipAsyncTasks","tasks","createAsyncTaskCollector","recoveryRequest","clone","mutators","createMutators","enqueueTask","can","environment","processor","PushProcessor","withTransactionLifecycle","lifecycle","response","process","parsed","parseAlreadyProcessed","committed","length","entries","map","entry","task","runWithAuthScope","runAsyncTaskEntries","background","asyncTasks"],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
|
view.destroy();
|
|
436
436
|
});
|
|
437
|
-
(0, import_vitest.test)("
|
|
438
|
-
const
|
|
437
|
+
(0, import_vitest.test)("pull and push 500 reconnects keep socket opens on their current Zero attempt", async () => {
|
|
438
|
+
const lifecycle = [];
|
|
439
|
+
const zeroLogs = [];
|
|
440
|
+
let failPull = false;
|
|
441
|
+
let failPush = false;
|
|
439
442
|
const fetch = import_vitest.vi.fn(async (input, init) => {
|
|
440
443
|
const request = recordRequest(input, init);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
if (request.path === "/pull") {
|
|
445
|
+
if (failPull) {
|
|
446
|
+
failPull = false;
|
|
447
|
+
return jsonResponse({
|
|
448
|
+
error: "injected pull outage"
|
|
449
|
+
}, {
|
|
450
|
+
status: 500
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
return jsonResponse({
|
|
454
|
+
cookie: request.body.cookie,
|
|
455
|
+
unchanged: true
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
if (failPush) {
|
|
459
|
+
failPush = false;
|
|
460
|
+
return jsonResponse({
|
|
461
|
+
error: "injected push outage"
|
|
462
|
+
}, {
|
|
463
|
+
status: 500
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
const mutation2 = request.body.mutations[0];
|
|
467
|
+
return jsonResponse({
|
|
468
|
+
pushResponse: {
|
|
469
|
+
mutations: [{
|
|
470
|
+
id: {
|
|
471
|
+
clientID: mutation2.clientID,
|
|
472
|
+
id: mutation2.id
|
|
473
|
+
},
|
|
474
|
+
result: {}
|
|
475
|
+
}]
|
|
476
|
+
}
|
|
477
|
+
});
|
|
444
478
|
});
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
479
|
+
const transport = (0, import_httpPullTransport.installHttpPullTransport)({
|
|
480
|
+
origin: ORIGIN,
|
|
481
|
+
fetch,
|
|
482
|
+
lifecycle: event => lifecycle.push(event)
|
|
483
|
+
});
|
|
484
|
+
transports.push(transport);
|
|
485
|
+
const zero = createZero({
|
|
486
|
+
logSink: {
|
|
487
|
+
log: (_level, context, ...args) => {
|
|
488
|
+
zeroLogs.push({
|
|
489
|
+
context: context ?? {},
|
|
490
|
+
args
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
await eventually(() => (0, import_vitest.expect)(zero.connection.state.current.name).toBe("connected"));
|
|
496
|
+
failPull = true;
|
|
497
|
+
await transport.pull().catch(() => {});
|
|
498
|
+
await eventually(() => (0, import_vitest.expect)(lifecycle.filter(event => event.type === "open")).toHaveLength(2), 5e3);
|
|
499
|
+
failPush = true;
|
|
500
|
+
const mutation = zero.mutate.project.create({
|
|
501
|
+
id: "p1",
|
|
502
|
+
ownerId: "u1",
|
|
503
|
+
name: "after reconnect"
|
|
504
|
+
});
|
|
505
|
+
await mutation.client;
|
|
506
|
+
await mutation.server.catch(() => {});
|
|
507
|
+
await eventually(() => (0, import_vitest.expect)(lifecycle.filter(event => event.type === "open")).toHaveLength(3), 5e3);
|
|
508
|
+
await eventually(() => (0, import_vitest.expect)(zero.connection.state.current.name).toBe("connected"), 5e3);
|
|
509
|
+
const opens = lifecycle.filter(event => event.type === "open");
|
|
510
|
+
(0, import_vitest.expect)(opens.map(({
|
|
511
|
+
generation,
|
|
512
|
+
activeGeneration
|
|
513
|
+
}) => [generation, activeGeneration])).toEqual([[1, 1], [2, 2], [3, 3]]);
|
|
514
|
+
(0, import_vitest.expect)(zeroLogs.some(({
|
|
515
|
+
args
|
|
516
|
+
}) => args.some(arg => String(arg).includes("connect start time is undefined")))).toBe(false);
|
|
517
|
+
});
|
|
518
|
+
(0, import_vitest.test)("a replacement socket supersedes stale open and connected events for the same client", async () => {
|
|
519
|
+
import_vitest.vi.useFakeTimers();
|
|
520
|
+
const lifecycle = [];
|
|
521
|
+
const transport = (0, import_httpPullTransport.installHttpPullTransport)({
|
|
522
|
+
origin: ORIGIN,
|
|
523
|
+
fetch: import_vitest.vi.fn(async () => jsonResponse({
|
|
524
|
+
cookie: null,
|
|
525
|
+
unchanged: true
|
|
526
|
+
})),
|
|
527
|
+
lifecycle: event => lifecycle.push(event)
|
|
528
|
+
});
|
|
529
|
+
transports.push(transport);
|
|
530
|
+
let connectStart = Date.now();
|
|
531
|
+
const errors = [];
|
|
532
|
+
const attachStockLifecycle = socket => {
|
|
533
|
+
socket.addEventListener("open", () => {
|
|
534
|
+
if (connectStart === void 0) {
|
|
535
|
+
errors.push("Got open event but connect start time is undefined.");
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
socket.addEventListener("message", event => {
|
|
539
|
+
const message = JSON.parse(String(event.data));
|
|
540
|
+
if (message[0] === "connected") connectStart = void 0;
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
const stale = openRawSocketWithMessages({
|
|
544
|
+
wsid: "stale"
|
|
545
|
+
}).socket;
|
|
546
|
+
attachStockLifecycle(stale);
|
|
547
|
+
const current = openRawSocketWithMessages({
|
|
548
|
+
wsid: "current"
|
|
549
|
+
}).socket;
|
|
550
|
+
attachStockLifecycle(current);
|
|
551
|
+
await import_vitest.vi.advanceTimersByTimeAsync(1);
|
|
552
|
+
(0, import_vitest.expect)(lifecycle.filter(event => event.type === "open").map(({
|
|
553
|
+
generation,
|
|
554
|
+
activeGeneration,
|
|
555
|
+
wsid
|
|
556
|
+
}) => [generation, activeGeneration, wsid])).toEqual([[2, 2, "current"]]);
|
|
557
|
+
(0, import_vitest.expect)(lifecycle).toContainEqual(import_vitest.expect.objectContaining({
|
|
558
|
+
type: "superseded",
|
|
559
|
+
generation: 1,
|
|
560
|
+
wsid: "stale"
|
|
561
|
+
}));
|
|
562
|
+
(0, import_vitest.expect)(errors).toEqual([]);
|
|
453
563
|
});
|
|
454
564
|
(0, import_vitest.test)("non-origin WebSockets pass through to the native implementation", () => {
|
|
455
565
|
const previous = globalThis.WebSocket;
|
|
@@ -565,7 +675,9 @@ function createZero(options = {}) {
|
|
|
565
675
|
storageKey: `zero-http-test-${++storageID}`,
|
|
566
676
|
mutators: import_fixtureSchema.zeroHttpFixtureMutators,
|
|
567
677
|
pingTimeoutMs: options.pingTimeoutMs,
|
|
568
|
-
onClientStateNotFound: options.onClientStateNotFound
|
|
678
|
+
onClientStateNotFound: options.onClientStateNotFound,
|
|
679
|
+
logLevel: options.logSink ? "debug" : void 0,
|
|
680
|
+
logSink: options.logSink
|
|
569
681
|
});
|
|
570
682
|
zeros.push(zero);
|
|
571
683
|
return zero;
|
|
@@ -630,7 +742,7 @@ function openRawSocketWithMessages(opts) {
|
|
|
630
742
|
url.searchParams.set("userID", "u1");
|
|
631
743
|
url.searchParams.set("baseCookie", "");
|
|
632
744
|
url.searchParams.set("lmid", "0");
|
|
633
|
-
url.searchParams.set("wsid", "ws-test");
|
|
745
|
+
url.searchParams.set("wsid", opts?.wsid ?? "ws-test");
|
|
634
746
|
const messages = [];
|
|
635
747
|
const socket = new WebSocket(url, encodeSecProtocol(["initConnection", {
|
|
636
748
|
desiredQueriesPatch: opts?.desiredQueriesPatch ?? []
|
|
@@ -512,26 +512,168 @@ var storageID = 0;
|
|
|
512
512
|
cleanup();
|
|
513
513
|
view.destroy();
|
|
514
514
|
});
|
|
515
|
-
(0, import_vitest.test)("
|
|
516
|
-
var
|
|
515
|
+
(0, import_vitest.test)("pull and push 500 reconnects keep socket opens on their current Zero attempt", async function () {
|
|
516
|
+
var lifecycle = [];
|
|
517
|
+
var zeroLogs = [];
|
|
518
|
+
var failPull = false;
|
|
519
|
+
var failPush = false;
|
|
517
520
|
var fetch = import_vitest.vi.fn(async function (input, init) {
|
|
518
521
|
var request = recordRequest(input, init);
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
+
if (request.path === "/pull") {
|
|
523
|
+
if (failPull) {
|
|
524
|
+
failPull = false;
|
|
525
|
+
return jsonResponse({
|
|
526
|
+
error: "injected pull outage"
|
|
527
|
+
}, {
|
|
528
|
+
status: 500
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
return jsonResponse({
|
|
532
|
+
cookie: request.body.cookie,
|
|
533
|
+
unchanged: true
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
if (failPush) {
|
|
537
|
+
failPush = false;
|
|
538
|
+
return jsonResponse({
|
|
539
|
+
error: "injected push outage"
|
|
540
|
+
}, {
|
|
541
|
+
status: 500
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
var mutation2 = request.body.mutations[0];
|
|
545
|
+
return jsonResponse({
|
|
546
|
+
pushResponse: {
|
|
547
|
+
mutations: [{
|
|
548
|
+
id: {
|
|
549
|
+
clientID: mutation2.clientID,
|
|
550
|
+
id: mutation2.id
|
|
551
|
+
},
|
|
552
|
+
result: {}
|
|
553
|
+
}]
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
var transport = (0, import_httpPullTransport.installHttpPullTransport)({
|
|
558
|
+
origin: ORIGIN,
|
|
559
|
+
fetch,
|
|
560
|
+
lifecycle: function (event) {
|
|
561
|
+
return lifecycle.push(event);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
transports.push(transport);
|
|
565
|
+
var zero = createZero({
|
|
566
|
+
logSink: {
|
|
567
|
+
log: function (_level, context) {
|
|
568
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
569
|
+
args[_key - 2] = arguments[_key];
|
|
570
|
+
}
|
|
571
|
+
zeroLogs.push({
|
|
572
|
+
context: context !== null && context !== void 0 ? context : {},
|
|
573
|
+
args
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
522
577
|
});
|
|
523
|
-
install(fetch);
|
|
524
|
-
createZero();
|
|
525
578
|
await eventually(function () {
|
|
526
|
-
return (0, import_vitest.expect)(
|
|
579
|
+
return (0, import_vitest.expect)(zero.connection.state.current.name).toBe("connected");
|
|
527
580
|
});
|
|
528
|
-
|
|
529
|
-
|
|
581
|
+
failPull = true;
|
|
582
|
+
await transport.pull().catch(function () {});
|
|
530
583
|
await eventually(function () {
|
|
531
|
-
return (0, import_vitest.expect)(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
584
|
+
return (0, import_vitest.expect)(lifecycle.filter(function (event) {
|
|
585
|
+
return event.type === "open";
|
|
586
|
+
})).toHaveLength(2);
|
|
587
|
+
}, 5e3);
|
|
588
|
+
failPush = true;
|
|
589
|
+
var mutation = zero.mutate.project.create({
|
|
590
|
+
id: "p1",
|
|
591
|
+
ownerId: "u1",
|
|
592
|
+
name: "after reconnect"
|
|
593
|
+
});
|
|
594
|
+
await mutation.client;
|
|
595
|
+
await mutation.server.catch(function () {});
|
|
596
|
+
await eventually(function () {
|
|
597
|
+
return (0, import_vitest.expect)(lifecycle.filter(function (event) {
|
|
598
|
+
return event.type === "open";
|
|
599
|
+
})).toHaveLength(3);
|
|
600
|
+
}, 5e3);
|
|
601
|
+
await eventually(function () {
|
|
602
|
+
return (0, import_vitest.expect)(zero.connection.state.current.name).toBe("connected");
|
|
603
|
+
}, 5e3);
|
|
604
|
+
var opens = lifecycle.filter(function (event) {
|
|
605
|
+
return event.type === "open";
|
|
606
|
+
});
|
|
607
|
+
(0, import_vitest.expect)(opens.map(function (param) {
|
|
608
|
+
var {
|
|
609
|
+
generation,
|
|
610
|
+
activeGeneration
|
|
611
|
+
} = param;
|
|
612
|
+
return [generation, activeGeneration];
|
|
613
|
+
})).toEqual([[1, 1], [2, 2], [3, 3]]);
|
|
614
|
+
(0, import_vitest.expect)(zeroLogs.some(function (param) {
|
|
615
|
+
var {
|
|
616
|
+
args
|
|
617
|
+
} = param;
|
|
618
|
+
return args.some(function (arg) {
|
|
619
|
+
return String(arg).includes("connect start time is undefined");
|
|
620
|
+
});
|
|
621
|
+
})).toBe(false);
|
|
622
|
+
});
|
|
623
|
+
(0, import_vitest.test)("a replacement socket supersedes stale open and connected events for the same client", async function () {
|
|
624
|
+
import_vitest.vi.useFakeTimers();
|
|
625
|
+
var lifecycle = [];
|
|
626
|
+
var transport = (0, import_httpPullTransport.installHttpPullTransport)({
|
|
627
|
+
origin: ORIGIN,
|
|
628
|
+
fetch: import_vitest.vi.fn(async function () {
|
|
629
|
+
return jsonResponse({
|
|
630
|
+
cookie: null,
|
|
631
|
+
unchanged: true
|
|
632
|
+
});
|
|
633
|
+
}),
|
|
634
|
+
lifecycle: function (event) {
|
|
635
|
+
return lifecycle.push(event);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
transports.push(transport);
|
|
639
|
+
var connectStart = Date.now();
|
|
640
|
+
var errors = [];
|
|
641
|
+
var attachStockLifecycle = function (socket) {
|
|
642
|
+
socket.addEventListener("open", function () {
|
|
643
|
+
if (connectStart === void 0) {
|
|
644
|
+
errors.push("Got open event but connect start time is undefined.");
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
socket.addEventListener("message", function (event) {
|
|
648
|
+
var message = JSON.parse(String(event.data));
|
|
649
|
+
if (message[0] === "connected") connectStart = void 0;
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
var stale = openRawSocketWithMessages({
|
|
653
|
+
wsid: "stale"
|
|
654
|
+
}).socket;
|
|
655
|
+
attachStockLifecycle(stale);
|
|
656
|
+
var current = openRawSocketWithMessages({
|
|
657
|
+
wsid: "current"
|
|
658
|
+
}).socket;
|
|
659
|
+
attachStockLifecycle(current);
|
|
660
|
+
await import_vitest.vi.advanceTimersByTimeAsync(1);
|
|
661
|
+
(0, import_vitest.expect)(lifecycle.filter(function (event) {
|
|
662
|
+
return event.type === "open";
|
|
663
|
+
}).map(function (param) {
|
|
664
|
+
var {
|
|
665
|
+
generation,
|
|
666
|
+
activeGeneration,
|
|
667
|
+
wsid
|
|
668
|
+
} = param;
|
|
669
|
+
return [generation, activeGeneration, wsid];
|
|
670
|
+
})).toEqual([[2, 2, "current"]]);
|
|
671
|
+
(0, import_vitest.expect)(lifecycle).toContainEqual(import_vitest.expect.objectContaining({
|
|
672
|
+
type: "superseded",
|
|
673
|
+
generation: 1,
|
|
674
|
+
wsid: "stale"
|
|
675
|
+
}));
|
|
676
|
+
(0, import_vitest.expect)(errors).toEqual([]);
|
|
535
677
|
});
|
|
536
678
|
(0, import_vitest.test)("non-origin WebSockets pass through to the native implementation", function () {
|
|
537
679
|
var previous = globalThis.WebSocket;
|
|
@@ -653,7 +795,9 @@ function createZero() {
|
|
|
653
795
|
storageKey: `zero-http-test-${++storageID}`,
|
|
654
796
|
mutators: import_fixtureSchema.zeroHttpFixtureMutators,
|
|
655
797
|
pingTimeoutMs: options.pingTimeoutMs,
|
|
656
|
-
onClientStateNotFound: options.onClientStateNotFound
|
|
798
|
+
onClientStateNotFound: options.onClientStateNotFound,
|
|
799
|
+
logLevel: options.logSink ? "debug" : void 0,
|
|
800
|
+
logSink: options.logSink
|
|
657
801
|
});
|
|
658
802
|
zeros.push(zero);
|
|
659
803
|
return zero;
|
|
@@ -728,7 +872,8 @@ function openRawSocketWithMessages(opts) {
|
|
|
728
872
|
url.searchParams.set("userID", "u1");
|
|
729
873
|
url.searchParams.set("baseCookie", "");
|
|
730
874
|
url.searchParams.set("lmid", "0");
|
|
731
|
-
|
|
875
|
+
var _opts_wsid;
|
|
876
|
+
url.searchParams.set("wsid", (_opts_wsid = opts === null || opts === void 0 ? void 0 : opts.wsid) !== null && _opts_wsid !== void 0 ? _opts_wsid : "ws-test");
|
|
732
877
|
var messages = [];
|
|
733
878
|
var _opts_desiredQueriesPatch, _opts_authToken;
|
|
734
879
|
var socket = new WebSocket(url, encodeSecProtocol(["initConnection", {
|