jazz-tools 0.19.6 → 0.19.8

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 (111) hide show
  1. package/.turbo/turbo-build.log +51 -47
  2. package/CHANGELOG.md +24 -0
  3. package/dist/{chunk-GCBXV2KC.js → chunk-2S3Z2CN6.js} +122 -53
  4. package/dist/chunk-2S3Z2CN6.js.map +1 -0
  5. package/dist/expo/polyfills.js +22 -0
  6. package/dist/expo/polyfills.js.map +1 -0
  7. package/dist/index.js +26 -6
  8. package/dist/index.js.map +1 -1
  9. package/dist/react-core/hooks.d.ts.map +1 -1
  10. package/dist/react-core/index.js +17 -6
  11. package/dist/react-core/index.js.map +1 -1
  12. package/dist/react-native/index.d.ts +1 -1
  13. package/dist/react-native/index.d.ts.map +1 -1
  14. package/dist/react-native/index.js +713 -9
  15. package/dist/react-native/index.js.map +1 -1
  16. package/dist/react-native/polyfills.js +22 -0
  17. package/dist/react-native/polyfills.js.map +1 -0
  18. package/dist/react-native-core/index.d.ts.map +1 -1
  19. package/dist/react-native-core/index.js.map +1 -1
  20. package/dist/testing.js +1 -1
  21. package/dist/tools/coValues/account.d.ts +3 -3
  22. package/dist/tools/coValues/account.d.ts.map +1 -1
  23. package/dist/tools/coValues/coFeed.d.ts +3 -3
  24. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  25. package/dist/tools/coValues/coList.d.ts +4 -4
  26. package/dist/tools/coValues/coList.d.ts.map +1 -1
  27. package/dist/tools/coValues/coMap.d.ts +7 -7
  28. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  29. package/dist/tools/coValues/coPlainText.d.ts +2 -2
  30. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  31. package/dist/tools/coValues/coVector.d.ts +2 -2
  32. package/dist/tools/coValues/coVector.d.ts.map +1 -1
  33. package/dist/tools/coValues/deepLoading.d.ts +24 -0
  34. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  35. package/dist/tools/coValues/group.d.ts +2 -2
  36. package/dist/tools/coValues/group.d.ts.map +1 -1
  37. package/dist/tools/coValues/interfaces.d.ts +6 -6
  38. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  39. package/dist/tools/coValues/schemaUnion.d.ts +2 -2
  40. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  41. package/dist/tools/config.d.ts +3 -0
  42. package/dist/tools/config.d.ts.map +1 -0
  43. package/dist/tools/exports.d.ts +2 -0
  44. package/dist/tools/exports.d.ts.map +1 -1
  45. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
  46. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  47. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +2 -2
  48. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  49. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -2
  50. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  51. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +4 -4
  52. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  53. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +4 -4
  54. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  55. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +4 -4
  56. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  57. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +2 -2
  58. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  59. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +2 -2
  60. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  61. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -2
  62. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  63. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +2 -2
  64. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  65. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  66. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  67. package/dist/tools/subscribe/SubscriptionScope.d.ts +10 -1
  68. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  69. package/dist/tools/subscribe/errorReporting.d.ts +31 -0
  70. package/dist/tools/subscribe/errorReporting.d.ts.map +1 -0
  71. package/dist/tools/testing.d.ts.map +1 -1
  72. package/dist/tools/tests/errorReporting.test.d.ts +2 -0
  73. package/dist/tools/tests/errorReporting.test.d.ts.map +1 -0
  74. package/package.json +13 -5
  75. package/src/react-core/hooks.ts +16 -0
  76. package/src/react-native/index.ts +1 -1
  77. package/src/react-native-core/index.ts +2 -0
  78. package/src/react-native-core/polyfills/index.js +28 -0
  79. package/src/tools/coValues/account.ts +3 -4
  80. package/src/tools/coValues/coFeed.ts +3 -2
  81. package/src/tools/coValues/coList.ts +4 -4
  82. package/src/tools/coValues/coMap.ts +4 -4
  83. package/src/tools/coValues/coPlainText.ts +2 -2
  84. package/src/tools/coValues/coVector.ts +2 -2
  85. package/src/tools/coValues/deepLoading.ts +31 -0
  86. package/src/tools/coValues/group.ts +2 -2
  87. package/src/tools/coValues/interfaces.ts +19 -23
  88. package/src/tools/coValues/schemaUnion.ts +2 -2
  89. package/src/tools/config.ts +9 -0
  90. package/src/tools/exports.ts +4 -0
  91. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
  92. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +2 -2
  93. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -2
  94. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +4 -4
  95. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +4 -4
  96. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +4 -10
  97. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +2 -2
  98. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +2 -2
  99. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +2 -2
  100. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +2 -2
  101. package/src/tools/subscribe/JazzError.ts +9 -6
  102. package/src/tools/subscribe/SubscriptionScope.ts +126 -36
  103. package/src/tools/subscribe/errorReporting.ts +67 -0
  104. package/src/tools/tests/coDiscriminatedUnion.test.ts +69 -2
  105. package/src/tools/tests/deepLoading.test.ts +47 -47
  106. package/src/tools/tests/errorReporting.test.ts +103 -0
  107. package/src/tools/tests/load.test.ts +21 -1
  108. package/src/tools/tests/request.test.ts +2 -1
  109. package/src/tools/tests/subscribe.test.ts +44 -0
  110. package/tsup.config.ts +16 -0
  111. package/dist/chunk-GCBXV2KC.js.map +0 -1
@@ -0,0 +1,103 @@
1
+ import { beforeEach, describe, expect, test, vi } from "vitest";
2
+ import { Group, z } from "../index.js";
3
+ import { setCustomErrorReporter } from "../config.js";
4
+ import { CoValueLoadingState } from "../internal.js";
5
+ import { createJazzTestAccount, linkAccounts } from "../testing.js";
6
+ import { co } from "../exports.js";
7
+
8
+ const TestMap = co.map({
9
+ value: z.string(),
10
+ });
11
+
12
+ describe("Custom error reporter", () => {
13
+ beforeEach(() => {
14
+ // Clean up error reporter before each test
15
+ setCustomErrorReporter(undefined);
16
+ });
17
+
18
+ test("with custom error reporter enabled, console.error is not called", async () => {
19
+ const bob = await createJazzTestAccount({
20
+ creationProps: { name: "Bob" },
21
+ });
22
+
23
+ const alice = await createJazzTestAccount({
24
+ creationProps: { name: "Alice" },
25
+ });
26
+
27
+ linkAccounts(bob, alice);
28
+
29
+ await alice.$jazz.waitForAllCoValuesSync();
30
+
31
+ const onlyBob = bob;
32
+ const group = Group.create(bob);
33
+
34
+ group.addMember(alice, "reader");
35
+
36
+ let capturedError: Error | undefined;
37
+ let capturedProps: { jazzError: any } | undefined;
38
+
39
+ setCustomErrorReporter((error, props) => {
40
+ capturedError = error;
41
+ capturedProps = props;
42
+ });
43
+
44
+ const consoleErrorSpy = vi
45
+ .spyOn(console, "error")
46
+ .mockImplementation(() => {});
47
+
48
+ const map = TestMap.create({ value: "hello" }, onlyBob);
49
+
50
+ const mapOnAlice = await TestMap.load(map.$jazz.id, { loadAs: alice });
51
+
52
+ // Access the value to trigger error logging
53
+ expect(mapOnAlice.$jazz.loadingState).toBe(
54
+ CoValueLoadingState.UNAUTHORIZED,
55
+ );
56
+
57
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
58
+ expect(capturedError).toBeDefined();
59
+ expect(capturedProps).toBeDefined();
60
+ expect(capturedProps?.jazzError).toBeDefined();
61
+
62
+ consoleErrorSpy.mockRestore();
63
+ });
64
+
65
+ test("without custom error reporter, console.error is called", async () => {
66
+ const bob = await createJazzTestAccount({
67
+ creationProps: { name: "Bob" },
68
+ });
69
+
70
+ const alice = await createJazzTestAccount({
71
+ creationProps: { name: "Alice" },
72
+ });
73
+
74
+ linkAccounts(bob, alice);
75
+
76
+ await alice.$jazz.waitForAllCoValuesSync();
77
+
78
+ const onlyBob = bob;
79
+ const group = Group.create(bob);
80
+
81
+ group.addMember(alice, "reader");
82
+
83
+ // Ensure no custom error reporter is set
84
+ setCustomErrorReporter(undefined);
85
+
86
+ const consoleErrorSpy = vi
87
+ .spyOn(console, "error")
88
+ .mockImplementation(() => {});
89
+
90
+ const map = TestMap.create({ value: "hello" }, onlyBob);
91
+
92
+ const mapOnAlice = await TestMap.load(map.$jazz.id, { loadAs: alice });
93
+
94
+ // Access the value to trigger error logging
95
+ expect(mapOnAlice.$jazz.loadingState).toBe(
96
+ CoValueLoadingState.UNAUTHORIZED,
97
+ );
98
+
99
+ expect(consoleErrorSpy).toHaveBeenCalled();
100
+
101
+ consoleErrorSpy.mockRestore();
102
+ });
103
+ });
@@ -1,6 +1,13 @@
1
1
  import { cojsonInternals, emptyKnownState } from "cojson";
2
2
  import { assert, beforeEach, expect, test } from "vitest";
3
- import { Account, Group, co, exportCoValue, z } from "../exports.js";
3
+ import {
4
+ Account,
5
+ Group,
6
+ co,
7
+ exportCoValue,
8
+ jazzConfig,
9
+ z,
10
+ } from "../exports.js";
4
11
  import { CoValueLoadingState } from "../internal.js";
5
12
  import {
6
13
  createJazzTestAccount,
@@ -12,6 +19,13 @@ import { assertLoaded, waitFor } from "./utils.js";
12
19
 
13
20
  cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY = 10;
14
21
 
22
+ let lastError: Error | undefined;
23
+ beforeEach(() => {
24
+ lastError = undefined;
25
+ jazzConfig.setCustomErrorReporter((error) => {
26
+ lastError = error;
27
+ });
28
+ });
15
29
  beforeEach(async () => {
16
30
  await setupJazzTestSync();
17
31
  await createJazzTestAccount({
@@ -42,6 +56,9 @@ test("return 'unavailable' if id is invalid", async () => {
42
56
 
43
57
  const john = await Person.load("test");
44
58
  expect(john.$jazz.loadingState).toBe(CoValueLoadingState.UNAVAILABLE);
59
+ expect(lastError?.message).toBe(
60
+ "Jazz Unavailable Error: unable to load test",
61
+ );
45
62
  });
46
63
 
47
64
  test("load a missing optional value (co.optional)", async () => {
@@ -185,6 +202,9 @@ test("returns 'unavailable' if the value is unavailable after retries", async ()
185
202
  const john = await Person.load(map.$jazz.id, { loadAs: alice });
186
203
 
187
204
  expect(john.$jazz.loadingState).toBe(CoValueLoadingState.UNAVAILABLE);
205
+ expect(lastError?.message).toBe(
206
+ "Jazz Unavailable Error: unable to load " + map.$jazz.id,
207
+ );
188
208
  });
189
209
 
190
210
  test("load works even when the coValue access is granted after the creation", async () => {
@@ -14,6 +14,7 @@ import {
14
14
  CoValueLoadingState,
15
15
  exportCoValue,
16
16
  importContentPieces,
17
+ Inaccessible,
17
18
  } from "../internal.js";
18
19
  import { createJazzTestAccount, linkAccounts } from "../testing.js";
19
20
 
@@ -663,7 +664,7 @@ describe("JazzRequestError handling", () => {
663
664
  createUnloadedCoValue(
664
665
  "some-covalue-id",
665
666
  CoValueLoadingState.UNAVAILABLE,
666
- ),
667
+ ) as Inaccessible<Account>,
667
668
  );
668
669
 
669
670
  return userRequest.handle(request, worker, async () => {
@@ -1297,6 +1297,50 @@ describe("subscribeToCoValue", () => {
1297
1297
  expect(result.data[chunks]).toBe("new entry");
1298
1298
  });
1299
1299
 
1300
+ it("should emit not emit when the content doesn't bring real changes", async () => {
1301
+ const alice = await createJazzTestAccount();
1302
+
1303
+ const Person = co.map({
1304
+ name: z.string(),
1305
+ });
1306
+ const PersonList = co.list(Person);
1307
+
1308
+ const group = Group.create(alice);
1309
+
1310
+ const person1 = Person.create({ name: "John" }, group);
1311
+ const person2 = Person.create({ name: "Jane" }, group);
1312
+
1313
+ const personList = PersonList.create([person1, person2], group);
1314
+
1315
+ const spy = vi.fn();
1316
+ // Test subscribing to the large coValue
1317
+ const unsubscribe = subscribeToCoValue(
1318
+ coValueClassFromCoValueClassOrSchema(PersonList),
1319
+ personList.$jazz.id,
1320
+ {
1321
+ loadAs: alice,
1322
+ resolve: {
1323
+ $each: true,
1324
+ },
1325
+ syncResolution: true,
1326
+ },
1327
+ spy,
1328
+ );
1329
+
1330
+ onTestFinished(unsubscribe);
1331
+
1332
+ expect(spy).toHaveBeenCalledTimes(1);
1333
+
1334
+ // Test that updates to the large coValue are properly subscribed
1335
+ spy.mockClear();
1336
+
1337
+ group.addMember("everyone", "reader");
1338
+
1339
+ await new Promise((resolve) => setTimeout(resolve, 5));
1340
+
1341
+ expect(spy).not.toHaveBeenCalled();
1342
+ });
1343
+
1300
1344
  it.fails(
1301
1345
  "should return the latest loaded state when a deeply loaded child becomes not accessible",
1302
1346
  async () => {
package/tsup.config.ts CHANGED
@@ -43,8 +43,16 @@ export default defineConfig([
43
43
  index: "src/expo/index.ts",
44
44
  testing: "src/expo/testing.ts",
45
45
  crypto: "src/expo/crypto.ts",
46
+ polyfills: "src/react-native-core/polyfills/index.js",
46
47
  },
47
48
  outDir: "dist/expo",
49
+ external: [
50
+ "jazz-tools",
51
+ "readable-stream",
52
+ "@azure/core-asynciterator-polyfill",
53
+ "react-native-get-random-values",
54
+ "react-native-fast-encoder",
55
+ ],
48
56
  },
49
57
  {
50
58
  ...cfg,
@@ -107,8 +115,16 @@ export default defineConfig([
107
115
  index: "src/react-native/index.ts",
108
116
  testing: "src/react-native/testing.ts",
109
117
  crypto: "src/react-native/crypto.ts",
118
+ polyfills: "src/react-native-core/polyfills/index.js",
110
119
  },
111
120
  outDir: "dist/react-native",
121
+ external: [
122
+ "jazz-tools",
123
+ "readable-stream",
124
+ "@azure/core-asynciterator-polyfill",
125
+ "react-native-get-random-values",
126
+ "react-native-fast-encoder",
127
+ ],
112
128
  },
113
129
  {
114
130
  ...cfg,