on-zero 0.4.26 → 0.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/cjs/createZeroClient.cjs +14 -1
  2. package/dist/cjs/createZeroClient.native.js +15 -1
  3. package/dist/cjs/createZeroClient.native.js.map +1 -1
  4. package/dist/cjs/httpPull/auth.test.cjs +197 -0
  5. package/dist/cjs/httpPull/auth.test.native.js +279 -0
  6. package/dist/cjs/httpPull/auth.test.native.js.map +1 -0
  7. package/dist/cjs/httpPull/churn.test.cjs +132 -0
  8. package/dist/cjs/httpPull/churn.test.native.js +155 -0
  9. package/dist/cjs/httpPull/churn.test.native.js.map +1 -0
  10. package/dist/cjs/httpPull/fixtureSchema.cjs +76 -0
  11. package/dist/cjs/httpPull/fixtureSchema.native.js +82 -0
  12. package/dist/cjs/httpPull/fixtureSchema.native.js.map +1 -0
  13. package/dist/cjs/httpPull/fixtureServer.cjs +340 -0
  14. package/dist/cjs/httpPull/fixtureServer.native.js +534 -0
  15. package/dist/cjs/httpPull/fixtureServer.native.js.map +1 -0
  16. package/dist/cjs/httpPull/integration.test.cjs +53 -0
  17. package/dist/cjs/httpPull/integration.test.native.js +60 -0
  18. package/dist/cjs/httpPull/integration.test.native.js.map +1 -0
  19. package/dist/cjs/httpPull/rebase.test.cjs +360 -0
  20. package/dist/cjs/httpPull/rebase.test.native.js +420 -0
  21. package/dist/cjs/httpPull/rebase.test.native.js.map +1 -0
  22. package/dist/cjs/httpPull/relations.test.cjs +107 -0
  23. package/dist/cjs/httpPull/relations.test.native.js +119 -0
  24. package/dist/cjs/httpPull/relations.test.native.js.map +1 -0
  25. package/dist/cjs/httpPull/testHarness.cjs +100 -0
  26. package/dist/cjs/httpPull/testHarness.native.js +112 -0
  27. package/dist/cjs/httpPull/testHarness.native.js.map +1 -0
  28. package/dist/cjs/httpPull/transport.test.cjs +588 -0
  29. package/dist/cjs/httpPull/transport.test.native.js +677 -0
  30. package/dist/cjs/httpPull/transport.test.native.js.map +1 -0
  31. package/dist/cjs/httpPullTransport.cjs +447 -0
  32. package/dist/cjs/httpPullTransport.native.js +710 -0
  33. package/dist/cjs/httpPullTransport.native.js.map +1 -0
  34. package/dist/cjs/index.cjs +1 -0
  35. package/dist/cjs/index.native.js +1 -0
  36. package/dist/cjs/index.native.js.map +1 -1
  37. package/dist/esm/createZeroClient.mjs +14 -1
  38. package/dist/esm/createZeroClient.mjs.map +1 -1
  39. package/dist/esm/createZeroClient.native.js +15 -1
  40. package/dist/esm/createZeroClient.native.js.map +1 -1
  41. package/dist/esm/httpPull/auth.test.mjs +198 -0
  42. package/dist/esm/httpPull/auth.test.mjs.map +1 -0
  43. package/dist/esm/httpPull/auth.test.native.js +277 -0
  44. package/dist/esm/httpPull/auth.test.native.js.map +1 -0
  45. package/dist/esm/httpPull/churn.test.mjs +133 -0
  46. package/dist/esm/httpPull/churn.test.mjs.map +1 -0
  47. package/dist/esm/httpPull/churn.test.native.js +153 -0
  48. package/dist/esm/httpPull/churn.test.native.js.map +1 -0
  49. package/dist/esm/httpPull/fixtureSchema.mjs +50 -0
  50. package/dist/esm/httpPull/fixtureSchema.mjs.map +1 -0
  51. package/dist/esm/httpPull/fixtureSchema.native.js +53 -0
  52. package/dist/esm/httpPull/fixtureSchema.native.js.map +1 -0
  53. package/dist/esm/httpPull/fixtureServer.mjs +315 -0
  54. package/dist/esm/httpPull/fixtureServer.mjs.map +1 -0
  55. package/dist/esm/httpPull/fixtureServer.native.js +506 -0
  56. package/dist/esm/httpPull/fixtureServer.native.js.map +1 -0
  57. package/dist/esm/httpPull/integration.test.mjs +54 -0
  58. package/dist/esm/httpPull/integration.test.mjs.map +1 -0
  59. package/dist/esm/httpPull/integration.test.native.js +58 -0
  60. package/dist/esm/httpPull/integration.test.native.js.map +1 -0
  61. package/dist/esm/httpPull/rebase.test.mjs +361 -0
  62. package/dist/esm/httpPull/rebase.test.mjs.map +1 -0
  63. package/dist/esm/httpPull/rebase.test.native.js +418 -0
  64. package/dist/esm/httpPull/rebase.test.native.js.map +1 -0
  65. package/dist/esm/httpPull/relations.test.mjs +108 -0
  66. package/dist/esm/httpPull/relations.test.mjs.map +1 -0
  67. package/dist/esm/httpPull/relations.test.native.js +117 -0
  68. package/dist/esm/httpPull/relations.test.native.js.map +1 -0
  69. package/dist/esm/httpPull/testHarness.mjs +72 -0
  70. package/dist/esm/httpPull/testHarness.mjs.map +1 -0
  71. package/dist/esm/httpPull/testHarness.native.js +81 -0
  72. package/dist/esm/httpPull/testHarness.native.js.map +1 -0
  73. package/dist/esm/httpPull/transport.test.mjs +589 -0
  74. package/dist/esm/httpPull/transport.test.mjs.map +1 -0
  75. package/dist/esm/httpPull/transport.test.native.js +675 -0
  76. package/dist/esm/httpPull/transport.test.native.js.map +1 -0
  77. package/dist/esm/httpPullTransport.mjs +421 -0
  78. package/dist/esm/httpPullTransport.mjs.map +1 -0
  79. package/dist/esm/httpPullTransport.native.js +681 -0
  80. package/dist/esm/httpPullTransport.native.js.map +1 -0
  81. package/dist/esm/index.js +1 -0
  82. package/dist/esm/index.js.map +1 -1
  83. package/dist/esm/index.mjs +1 -0
  84. package/dist/esm/index.mjs.map +1 -1
  85. package/dist/esm/index.native.js +1 -0
  86. package/dist/esm/index.native.js.map +1 -1
  87. package/package.json +2 -2
  88. package/src/createZeroClient.tsx +22 -0
  89. package/src/httpPull/auth.test.ts +208 -0
  90. package/src/httpPull/churn.test.ts +147 -0
  91. package/src/httpPull/fixtureSchema.ts +82 -0
  92. package/src/httpPull/fixtureServer.ts +391 -0
  93. package/src/httpPull/integration.test.ts +57 -0
  94. package/src/httpPull/rebase.test.ts +368 -0
  95. package/src/httpPull/relations.test.ts +135 -0
  96. package/src/httpPull/testHarness.ts +95 -0
  97. package/src/httpPull/transport.test.ts +603 -0
  98. package/src/httpPullTransport.ts +587 -0
  99. package/src/index.ts +1 -0
  100. package/types/createZeroClient.d.ts +3 -1
  101. package/types/createZeroClient.d.ts.map +1 -1
  102. package/types/httpPull/auth.test.d.ts +2 -0
  103. package/types/httpPull/auth.test.d.ts.map +1 -0
  104. package/types/httpPull/churn.test.d.ts +2 -0
  105. package/types/httpPull/churn.test.d.ts.map +1 -0
  106. package/types/httpPull/fixtureSchema.d.ts +111 -0
  107. package/types/httpPull/fixtureSchema.d.ts.map +1 -0
  108. package/types/httpPull/fixtureServer.d.ts +14 -0
  109. package/types/httpPull/fixtureServer.d.ts.map +1 -0
  110. package/types/httpPull/integration.test.d.ts +2 -0
  111. package/types/httpPull/integration.test.d.ts.map +1 -0
  112. package/types/httpPull/rebase.test.d.ts +2 -0
  113. package/types/httpPull/rebase.test.d.ts.map +1 -0
  114. package/types/httpPull/relations.test.d.ts +2 -0
  115. package/types/httpPull/relations.test.d.ts.map +1 -0
  116. package/types/httpPull/testHarness.d.ts +32 -0
  117. package/types/httpPull/testHarness.d.ts.map +1 -0
  118. package/types/httpPull/transport.test.d.ts +2 -0
  119. package/types/httpPull/transport.test.d.ts.map +1 -0
  120. package/types/httpPullTransport.d.ts +13 -0
  121. package/types/httpPullTransport.d.ts.map +1 -0
  122. package/types/index.d.ts +1 -0
  123. package/types/index.d.ts.map +1 -1
@@ -0,0 +1,100 @@
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 testHarness_exports = {};
24
+ __export(testHarness_exports, {
25
+ eventually: () => eventually,
26
+ sleep: () => sleep,
27
+ startZeroHttpHarness: () => startZeroHttpHarness,
28
+ waitForComplete: () => waitForComplete
29
+ });
30
+ module.exports = __toCommonJS(testHarness_exports);
31
+ var import_zero = require("@rocicorp/zero");
32
+ var import_fixtureSchema = require("./fixtureSchema.cjs");
33
+ var import_fixtureServer = require("./fixtureServer.cjs");
34
+ var import_httpPullTransport = require("../httpPullTransport.cjs");
35
+ let storageID = 0;
36
+ async function startZeroHttpHarness(opts) {
37
+ const server = await (0, import_fixtureServer.startZeroHttpServer)({
38
+ seed: opts?.seed
39
+ });
40
+ const baseFetch = (input, init) => globalThis.fetch(input, init);
41
+ const transportFetch = opts?.interceptFetch ? opts.interceptFetch(baseFetch) : baseFetch;
42
+ const transport = (0, import_httpPullTransport.installHttpPullTransport)({
43
+ origin: server.url,
44
+ fetch: transportFetch
45
+ });
46
+ const clients = [];
47
+ return {
48
+ server,
49
+ transport,
50
+ createZero(userID, createOpts) {
51
+ const zero = new import_zero.Zero({
52
+ server: server.url,
53
+ userID,
54
+ auth: `token-${userID}`,
55
+ schema: import_fixtureSchema.zeroHttpFixtureSchema,
56
+ kvStore: "mem",
57
+ storageKey: createOpts?.storageKey ?? `zero-http-harness-${++storageID}`,
58
+ mutators: import_fixtureSchema.zeroHttpFixtureMutators,
59
+ pingTimeoutMs: createOpts?.pingTimeoutMs
60
+ });
61
+ clients.push(zero);
62
+ return zero;
63
+ },
64
+ async close() {
65
+ await transport.pull().catch(() => {});
66
+ while (clients.length) await clients.pop()?.close();
67
+ transport.uninstall();
68
+ await server.close();
69
+ }
70
+ };
71
+ }
72
+ function waitForComplete(view) {
73
+ return new Promise((resolve, reject) => {
74
+ const timeout = setTimeout(() => reject(new Error("timed out waiting for complete query")), 5e3);
75
+ let cleanup = () => {};
76
+ cleanup = view.addListener((data, resultType) => {
77
+ if (resultType !== "complete") return;
78
+ clearTimeout(timeout);
79
+ cleanup();
80
+ resolve(JSON.parse(JSON.stringify(data)));
81
+ });
82
+ });
83
+ }
84
+ async function eventually(assertion, timeout = 3e3) {
85
+ const started = Date.now();
86
+ let lastError;
87
+ while (Date.now() - started < timeout) {
88
+ try {
89
+ await assertion();
90
+ return;
91
+ } catch (error) {
92
+ lastError = error;
93
+ await sleep(10);
94
+ }
95
+ }
96
+ throw lastError;
97
+ }
98
+ function sleep(ms) {
99
+ return new Promise(resolve => setTimeout(resolve, ms));
100
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var testHarness_exports = {};
26
+ __export(testHarness_exports, {
27
+ eventually: () => eventually,
28
+ sleep: () => sleep,
29
+ startZeroHttpHarness: () => startZeroHttpHarness,
30
+ waitForComplete: () => waitForComplete
31
+ });
32
+ module.exports = __toCommonJS(testHarness_exports);
33
+ var import_zero = require("@rocicorp/zero");
34
+ var import_fixtureSchema = require("./fixtureSchema.native.js");
35
+ var import_fixtureServer = require("./fixtureServer.native.js");
36
+ var import_httpPullTransport = require("../httpPullTransport.native.js");
37
+ var storageID = 0;
38
+ async function startZeroHttpHarness(opts) {
39
+ var server = await (0, import_fixtureServer.startZeroHttpServer)({
40
+ seed: opts === null || opts === void 0 ? void 0 : opts.seed
41
+ });
42
+ var baseFetch = function (input, init) {
43
+ return globalThis.fetch(input, init);
44
+ };
45
+ var transportFetch = (opts === null || opts === void 0 ? void 0 : opts.interceptFetch) ? opts.interceptFetch(baseFetch) : baseFetch;
46
+ var transport = (0, import_httpPullTransport.installHttpPullTransport)({
47
+ origin: server.url,
48
+ fetch: transportFetch
49
+ });
50
+ var clients = [];
51
+ return {
52
+ server,
53
+ transport,
54
+ createZero(userID, createOpts) {
55
+ var _createOpts_storageKey;
56
+ var zero = new import_zero.Zero({
57
+ server: server.url,
58
+ userID,
59
+ auth: `token-${userID}`,
60
+ schema: import_fixtureSchema.zeroHttpFixtureSchema,
61
+ kvStore: "mem",
62
+ storageKey: (_createOpts_storageKey = createOpts === null || createOpts === void 0 ? void 0 : createOpts.storageKey) !== null && _createOpts_storageKey !== void 0 ? _createOpts_storageKey : `zero-http-harness-${++storageID}`,
63
+ mutators: import_fixtureSchema.zeroHttpFixtureMutators,
64
+ pingTimeoutMs: createOpts === null || createOpts === void 0 ? void 0 : createOpts.pingTimeoutMs
65
+ });
66
+ clients.push(zero);
67
+ return zero;
68
+ },
69
+ async close() {
70
+ var _clients_pop;
71
+ await transport.pull().catch(function () {});
72
+ while (clients.length) await ((_clients_pop = clients.pop()) === null || _clients_pop === void 0 ? void 0 : _clients_pop.close());
73
+ transport.uninstall();
74
+ await server.close();
75
+ }
76
+ };
77
+ }
78
+ function waitForComplete(view) {
79
+ return new Promise(function (resolve, reject) {
80
+ var timeout = setTimeout(function () {
81
+ return reject(new Error("timed out waiting for complete query"));
82
+ }, 5e3);
83
+ var cleanup = function () {};
84
+ cleanup = view.addListener(function (data, resultType) {
85
+ if (resultType !== "complete") return;
86
+ clearTimeout(timeout);
87
+ cleanup();
88
+ resolve(JSON.parse(JSON.stringify(data)));
89
+ });
90
+ });
91
+ }
92
+ async function eventually(assertion) {
93
+ var timeout = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 3e3;
94
+ var started = Date.now();
95
+ var lastError;
96
+ while (Date.now() - started < timeout) {
97
+ try {
98
+ await assertion();
99
+ return;
100
+ } catch (error) {
101
+ lastError = error;
102
+ await sleep(10);
103
+ }
104
+ }
105
+ throw lastError;
106
+ }
107
+ function sleep(ms) {
108
+ return new Promise(function (resolve) {
109
+ return setTimeout(resolve, ms);
110
+ });
111
+ }
112
+ //# sourceMappingURL=testHarness.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","testHarness_exports","__export","eventually","sleep","startZeroHttpHarness","waitForComplete","module","exports","import_zero","require","import_fixtureSchema","import_fixtureServer","import_httpPullTransport","storageID","opts","server","startZeroHttpServer","seed","baseFetch","input","init","globalThis","fetch","transportFetch","interceptFetch","transport","installHttpPullTransport","origin","url","clients","createZero","userID","createOpts","_createOpts_storageKey","zero","Zero","auth","schema","zeroHttpFixtureSchema","kvStore","storageKey","mutators","zeroHttpFixtureMutators","pingTimeoutMs","push","close","_clients_pop","pull","catch","length","pop","uninstall","view","Promise","resolve","reject","timeout","setTimeout","Error","cleanup","addListener","data","resultType","clearTimeout","JSON","parse","stringify","assertion","arguments","started","Date","now","lastError","error"],"sources":["../../../src/httpPull/testHarness.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAA,UAAA;EAAAC,KAAA,EAAAA,CAAA,KAAAA,KAAA;EAAAC,oBAAA,EAAAA,CAAA,KAAAA,oBAAA;EAAAC,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAZ,YAAqB,C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