jazz-tools 0.18.16 → 0.18.18

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 (112) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.d.ts +14 -0
  2. package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
  3. package/.svelte-kit/__package__/jazz.class.svelte.js +37 -0
  4. package/.svelte-kit/__package__/media/image.svelte +104 -98
  5. package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
  6. package/.svelte-kit/__package__/testing.d.ts +1 -1
  7. package/.svelte-kit/__package__/testing.d.ts.map +1 -1
  8. package/.svelte-kit/__package__/testing.js +1 -1
  9. package/.svelte-kit/__package__/tests/TestConnectionStatus.svelte +8 -0
  10. package/.svelte-kit/__package__/tests/TestConnectionStatus.svelte.d.ts +27 -0
  11. package/.svelte-kit/__package__/tests/TestConnectionStatus.svelte.d.ts.map +1 -0
  12. package/.svelte-kit/__package__/tests/media/image.svelte.test.js +16 -2
  13. package/.svelte-kit/__package__/tests/sync-connection-status.svelte.test.d.ts +2 -0
  14. package/.svelte-kit/__package__/tests/sync-connection-status.svelte.test.d.ts.map +1 -0
  15. package/.svelte-kit/__package__/tests/sync-connection-status.svelte.test.js +47 -0
  16. package/.turbo/turbo-build.log +52 -52
  17. package/CHANGELOG.md +27 -0
  18. package/dist/browser/BrowserContextManager.d.ts +4 -0
  19. package/dist/browser/BrowserContextManager.d.ts.map +1 -1
  20. package/dist/browser/createBrowserContext.d.ts +4 -0
  21. package/dist/browser/createBrowserContext.d.ts.map +1 -1
  22. package/dist/browser/index.js +36 -4
  23. package/dist/browser/index.js.map +1 -1
  24. package/dist/{chunk-GRN6OAUX.js → chunk-FHRKDKDY.js} +80 -6
  25. package/dist/chunk-FHRKDKDY.js.map +1 -0
  26. package/dist/index.js +1 -1
  27. package/dist/react/hooks.d.ts +1 -1
  28. package/dist/react/hooks.d.ts.map +1 -1
  29. package/dist/react/index.d.ts +1 -1
  30. package/dist/react/index.d.ts.map +1 -1
  31. package/dist/react/index.js +6 -2
  32. package/dist/react/index.js.map +1 -1
  33. package/dist/react/media/image.d.ts.map +1 -1
  34. package/dist/react-core/hooks.d.ts +26 -0
  35. package/dist/react-core/hooks.d.ts.map +1 -1
  36. package/dist/react-core/index.js +16 -1
  37. package/dist/react-core/index.js.map +1 -1
  38. package/dist/react-core/testing.d.ts +1 -1
  39. package/dist/react-core/testing.d.ts.map +1 -1
  40. package/dist/react-core/testing.js +3 -1
  41. package/dist/react-core/testing.js.map +1 -1
  42. package/dist/react-core/tests/useSyncConnectionStatus.test.d.ts +2 -0
  43. package/dist/react-core/tests/useSyncConnectionStatus.test.d.ts.map +1 -0
  44. package/dist/react-native-core/ReactNativeContextManager.d.ts +4 -0
  45. package/dist/react-native-core/ReactNativeContextManager.d.ts.map +1 -1
  46. package/dist/react-native-core/hooks.d.ts +1 -1
  47. package/dist/react-native-core/hooks.d.ts.map +1 -1
  48. package/dist/react-native-core/index.js +41 -7
  49. package/dist/react-native-core/index.js.map +1 -1
  50. package/dist/react-native-core/media/image.d.ts.map +1 -1
  51. package/dist/react-native-core/platform.d.ts +4 -0
  52. package/dist/react-native-core/platform.d.ts.map +1 -1
  53. package/dist/svelte/jazz.class.svelte.d.ts +14 -0
  54. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  55. package/dist/svelte/jazz.class.svelte.js +37 -0
  56. package/dist/svelte/media/image.svelte +104 -98
  57. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  58. package/dist/svelte/testing.d.ts +1 -1
  59. package/dist/svelte/testing.d.ts.map +1 -1
  60. package/dist/svelte/testing.js +1 -1
  61. package/dist/svelte/tests/TestConnectionStatus.svelte +8 -0
  62. package/dist/svelte/tests/TestConnectionStatus.svelte.d.ts +27 -0
  63. package/dist/svelte/tests/TestConnectionStatus.svelte.d.ts.map +1 -0
  64. package/dist/svelte/tests/media/image.svelte.test.js +16 -2
  65. package/dist/svelte/tests/sync-connection-status.svelte.test.d.ts +2 -0
  66. package/dist/svelte/tests/sync-connection-status.svelte.test.d.ts.map +1 -0
  67. package/dist/svelte/tests/sync-connection-status.svelte.test.js +47 -0
  68. package/dist/testing.js +34 -4
  69. package/dist/testing.js.map +1 -1
  70. package/dist/tools/implementation/ContextManager.d.ts +4 -0
  71. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  72. package/dist/tools/implementation/refs.d.ts +1 -1
  73. package/dist/tools/implementation/refs.d.ts.map +1 -1
  74. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +4 -0
  75. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  76. package/dist/tools/subscribe/SubscriptionScope.d.ts +7 -0
  77. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  78. package/dist/tools/subscribe/index.d.ts.map +1 -1
  79. package/dist/tools/testing.d.ts +8 -0
  80. package/dist/tools/testing.d.ts.map +1 -1
  81. package/dist/tools/types.d.ts +4 -0
  82. package/dist/tools/types.d.ts.map +1 -1
  83. package/package.json +4 -4
  84. package/src/browser/createBrowserContext.ts +34 -4
  85. package/src/react/hooks.tsx +1 -0
  86. package/src/react/index.ts +1 -0
  87. package/src/react/media/image.tsx +2 -0
  88. package/src/react/tests/media/image.test.tsx +20 -2
  89. package/src/react-core/hooks.ts +42 -0
  90. package/src/react-core/testing.tsx +1 -0
  91. package/src/react-core/tests/useAccountWithSelector.test.ts +98 -2
  92. package/src/react-core/tests/useSyncConnectionStatus.test.ts +48 -0
  93. package/src/react-native-core/hooks.tsx +1 -0
  94. package/src/react-native-core/media/image.tsx +4 -1
  95. package/src/react-native-core/platform.ts +32 -4
  96. package/src/svelte/jazz.class.svelte.ts +44 -0
  97. package/src/svelte/media/image.svelte +104 -98
  98. package/src/svelte/testing.ts +1 -0
  99. package/src/svelte/tests/TestConnectionStatus.svelte +8 -0
  100. package/src/svelte/tests/media/image.svelte.test.ts +18 -2
  101. package/src/svelte/tests/sync-connection-status.svelte.test.ts +61 -0
  102. package/src/tools/implementation/ContextManager.ts +8 -0
  103. package/src/tools/implementation/refs.ts +27 -3
  104. package/src/tools/subscribe/CoValueCoreSubscription.ts +14 -0
  105. package/src/tools/subscribe/SubscriptionScope.ts +67 -2
  106. package/src/tools/subscribe/index.ts +8 -0
  107. package/src/tools/testing.ts +29 -0
  108. package/src/tools/tests/ContextManager.test.ts +2 -2
  109. package/src/tools/tests/coMap.test.ts +42 -0
  110. package/src/tools/tests/subscribe.test.ts +1 -4
  111. package/src/tools/types.ts +4 -0
  112. package/dist/chunk-GRN6OAUX.js.map +0 -1
@@ -34,5 +34,19 @@ export declare class AccountCoState<A extends (AccountClass<Account> & CoValueFr
34
34
  get agent(): import("jazz-tools").AnonymousJazzAgent | InstanceOfSchema<A>;
35
35
  get isAuthenticated(): boolean;
36
36
  }
37
+ /**
38
+ * Class that provides the current connection status to the Jazz sync server.
39
+ *
40
+ * @returns `true` when connected to the server, `false` when disconnected
41
+ *
42
+ * @remarks
43
+ * On connection drop, this will return `false` only when Jazz detects the disconnection
44
+ * after 5 seconds of not receiving a ping from the server.
45
+ */
46
+ export declare class SyncConnectionStatus {
47
+ #private;
48
+ constructor();
49
+ get current(): boolean;
50
+ }
37
51
  export {};
38
52
  //# sourceMappingURL=jazz.class.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jazz.class.svelte.d.ts","sourceRoot":"","sources":["../../../src/svelte/jazz.class.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAUpB,KAAK,cAAc,CAAC,CAAC,SAAS,oBAAoB,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,IAAI;IAC/E,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,E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C,CAAC,GAAG,SAAS,GAAG,IAAI;IAM7C,MAAM,aAEJ;IAEF,IAAI,OAAO,oCAIV;IAED,IAAI,KAAK,kEAQR;IAID,IAAI,eAAe,YAElB;CACF;AAED;;;;;;;;GAQG;AACH,qBAAa,oBAAoB;;;IA6B/B,IAAI,OAAO,YAGV;CACF"}
@@ -123,3 +123,40 @@ export class AccountCoState {
123
123
  return this.#isAuthenticated.current;
124
124
  }
125
125
  }
126
+ /**
127
+ * Class that provides the current connection status to the Jazz sync server.
128
+ *
129
+ * @returns `true` when connected to the server, `false` when disconnected
130
+ *
131
+ * @remarks
132
+ * On connection drop, this will return `false` only when Jazz detects the disconnection
133
+ * after 5 seconds of not receiving a ping from the server.
134
+ */
135
+ export class SyncConnectionStatus {
136
+ #ctx = getJazzContext();
137
+ #subscribe;
138
+ #update = () => { };
139
+ constructor() {
140
+ this.#subscribe = createSubscriber((update) => {
141
+ this.#update = update;
142
+ });
143
+ $effect.pre(() => {
144
+ const ctx = this.#ctx.current;
145
+ return untrack(() => {
146
+ if (!ctx) {
147
+ return;
148
+ }
149
+ const unsubscribe = ctx.addConnectionListener(() => {
150
+ this.#update();
151
+ });
152
+ return () => {
153
+ unsubscribe();
154
+ };
155
+ });
156
+ });
157
+ }
158
+ get current() {
159
+ this.#subscribe();
160
+ return this.#ctx.current?.connected() ?? false;
161
+ }
162
+ }
@@ -1,118 +1,122 @@
1
1
  <script lang="ts">
2
- import { ImageDefinition } from "jazz-tools";
3
- import { highestResAvailable } from "jazz-tools/media";
4
- import { onDestroy } from "svelte";
5
- import { CoState } from "../jazz.class.svelte";
6
- import type { ImageProps } from "./image.types.js";
7
-
8
- const { imageId, width, height, ...rest }: ImageProps = $props();
9
-
10
- const imageState = new CoState(ImageDefinition, () => imageId);
11
- let lastBestImage: [string, string] | null = null;
12
-
13
- /**
14
- * For lazy loading, we use the browser's strategy for images with loading="lazy".
15
- * We use an empty image, and when the browser triggers the load event, we load the best available image.
16
- * On page loading, if the image url is already in browser's cache, the load event is triggered immediately.
17
- * This is why we need to use a different blob url for every image.
18
- */
19
- let waitingLazyLoading = $state(rest.loading === "lazy");
20
- const lazyPlaceholder = $derived.by(() =>
21
- waitingLazyLoading ? URL.createObjectURL(emptyPixelBlob) : undefined,
22
- );
23
-
24
- const dimensions = $derived.by<{
25
- width: number | undefined;
26
- height: number | undefined;
27
- }>(() => {
28
- const originalWidth = imageState.current?.originalSize?.[0];
29
- const originalHeight = imageState.current?.originalSize?.[1];
30
-
31
- // Both width and height are "original"
32
- if (width === "original" && height === "original") {
33
- return { width: originalWidth, height: originalHeight };
34
- }
2
+ import { ImageDefinition } from "jazz-tools";
3
+ import { highestResAvailable } from "jazz-tools/media";
4
+ import { onDestroy } from "svelte";
5
+ import { CoState } from "../jazz.class.svelte";
6
+ import type { ImageProps } from "./image.types.js";
7
+
8
+ const { imageId, width, height, ...rest }: ImageProps = $props();
9
+
10
+ const imageState = new CoState(ImageDefinition, () => imageId);
11
+ let lastBestImage: [string, string] | null = null;
12
+
13
+ /**
14
+ * For lazy loading, we use the browser's strategy for images with loading="lazy".
15
+ * We use an empty image, and when the browser triggers the load event, we load the best available image.
16
+ * On page loading, if the image url is already in browser's cache, the load event is triggered immediately.
17
+ * This is why we need to use a different blob url for every image.
18
+ */
19
+ let waitingLazyLoading = $state(rest.loading === "lazy");
20
+ const lazyPlaceholder = $derived.by(() =>
21
+ waitingLazyLoading ? URL.createObjectURL(emptyPixelBlob) : undefined,
22
+ );
23
+
24
+ const dimensions = $derived.by<{
25
+ width: number | undefined;
26
+ height: number | undefined;
27
+ }>(() => {
28
+ const originalWidth = imageState.current?.originalSize?.[0];
29
+ const originalHeight = imageState.current?.originalSize?.[1];
35
30
 
36
- // Width is "original", height is a number
37
- if (width === "original" && typeof height === "number") {
38
- if (originalWidth && originalHeight) {
39
- return {
40
- width: Math.round((height * originalWidth) / originalHeight),
41
- height,
42
- };
31
+ // Both width and height are "original"
32
+ if (width === "original" && height === "original") {
33
+ return { width: originalWidth, height: originalHeight };
43
34
  }
44
- return { width: undefined, height };
45
- }
46
35
 
47
- // Height is "original", width is a number
48
- if (height === "original" && typeof width === "number") {
49
- if (originalWidth && originalHeight) {
50
- return {
51
- width,
52
- height: Math.round((width * originalHeight) / originalWidth),
53
- };
36
+ // Width is "original", height is a number
37
+ if (width === "original" && typeof height === "number") {
38
+ if (originalWidth && originalHeight) {
39
+ return {
40
+ width: Math.round((height * originalWidth) / originalHeight),
41
+ height,
42
+ };
43
+ }
44
+ return { width: undefined, height };
54
45
  }
55
- return { width, height: undefined };
56
- }
57
46
 
58
- // In all other cases, use the property value:
59
- return {
60
- width: width === "original" ? originalWidth : width,
61
- height: height === "original" ? originalHeight : height,
62
- };
63
- });
47
+ // Height is "original", width is a number
48
+ if (height === "original" && typeof width === "number") {
49
+ if (originalWidth && originalHeight) {
50
+ return {
51
+ width,
52
+ height: Math.round((width * originalHeight) / originalWidth),
53
+ };
54
+ }
55
+ return { width, height: undefined };
56
+ }
64
57
 
65
- const src = $derived.by(() => {
66
- if (waitingLazyLoading) {
67
- return lazyPlaceholder;
68
- }
58
+ // In all other cases, use the property value:
59
+ return {
60
+ width: width === "original" ? originalWidth : width,
61
+ height: height === "original" ? originalHeight : height,
62
+ };
63
+ });
69
64
 
70
- const image = imageState.current;
71
- if (!image) return undefined;
65
+ const src = $derived.by(() => {
66
+ if (waitingLazyLoading) {
67
+ return lazyPlaceholder;
68
+ }
72
69
 
73
- const bestImage = highestResAvailable(
74
- image,
75
- dimensions.width || dimensions.height || 9999,
76
- dimensions.height || dimensions.width || 9999,
77
- );
70
+ const image = imageState.current;
71
+ if (image === undefined)
72
+ return "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
78
73
 
79
- if (!bestImage) return image.placeholderDataURL;
80
- if (lastBestImage?.[0] === bestImage.image.$jazz.id) return lastBestImage?.[1];
74
+ if (!image) return undefined;
81
75
 
82
- const blob = bestImage.image.toBlob();
76
+ const bestImage = highestResAvailable(
77
+ image,
78
+ dimensions.width || dimensions.height || 9999,
79
+ dimensions.height || dimensions.width || 9999,
80
+ );
83
81
 
84
- if (blob) {
85
- const url = URL.createObjectURL(blob);
86
- revokeObjectURL(lastBestImage?.[1]);
87
- lastBestImage = [bestImage.image.$jazz.id, url];
88
- return url;
89
- }
82
+ if (!bestImage) return image.placeholderDataURL;
83
+ if (lastBestImage?.[0] === bestImage.image.$jazz.id)
84
+ return lastBestImage?.[1];
85
+
86
+ const blob = bestImage.image.toBlob();
87
+
88
+ if (blob) {
89
+ const url = URL.createObjectURL(blob);
90
+ revokeObjectURL(lastBestImage?.[1]);
91
+ lastBestImage = [bestImage.image.$jazz.id, url];
92
+ return url;
93
+ }
90
94
 
91
- return image.placeholderDataURL;
92
- });
95
+ return image.placeholderDataURL;
96
+ });
93
97
 
94
- // Cleanup object URL on component destroy
95
- onDestroy(() => {
96
- revokeObjectURL(lastBestImage?.[1]);
97
- });
98
+ // Cleanup object URL on component destroy
99
+ onDestroy(() => {
100
+ revokeObjectURL(lastBestImage?.[1]);
101
+ });
98
102
 
99
- function revokeObjectURL(url: string | undefined) {
100
- if (url && url.startsWith("blob:")) {
101
- URL.revokeObjectURL(url);
103
+ function revokeObjectURL(url: string | undefined) {
104
+ if (url && url.startsWith("blob:")) {
105
+ URL.revokeObjectURL(url);
106
+ }
102
107
  }
103
- }
104
108
 
105
- const emptyPixelBlob = new Blob(
106
- [
107
- Uint8Array.from(
108
- atob(
109
- "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
109
+ const emptyPixelBlob = new Blob(
110
+ [
111
+ Uint8Array.from(
112
+ atob(
113
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
114
+ ),
115
+ (c) => c.charCodeAt(0),
110
116
  ),
111
- (c) => c.charCodeAt(0),
112
- ),
113
- ],
114
- { type: "image/png" },
115
- );
117
+ ],
118
+ { type: "image/png" },
119
+ );
116
120
  </script>
117
121
 
118
122
  <img
@@ -120,6 +124,8 @@ const emptyPixelBlob = new Blob(
120
124
  width={dimensions.width}
121
125
  height={dimensions.height}
122
126
  alt={rest.alt}
123
- onload={() => {waitingLazyLoading = false}}
127
+ onload={() => {
128
+ waitingLazyLoading = false;
129
+ }}
124
130
  {...rest}
125
131
  />
@@ -1 +1 @@
1
- {"version":3,"file":"image.svelte.d.ts","sourceRoot":"","sources":["../../../../src/svelte/media/image.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA2HnD,QAAA,MAAM,KAAK,gDAAsC,CAAC;AAClD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"image.svelte.d.ts","sourceRoot":"","sources":["../../../../src/svelte/media/image.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAiInD,QAAA,MAAM,KAAK,gDAAsC,CAAC;AAClD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
@@ -6,5 +6,5 @@ export declare function createJazzTestContext<Acc extends Account>(opts?: {
6
6
  };
7
7
  isAuthenticated?: boolean;
8
8
  }): Map<{} | {}, AuthSecretStorage | JazzContext<Acc>>;
9
- export { createJazzTestAccount, createJazzTestGuest, linkAccounts, setActiveAccount, setupJazzTestSync, } from "jazz-tools/testing";
9
+ export { createJazzTestAccount, createJazzTestGuest, linkAccounts, setActiveAccount, setupJazzTestSync, MockConnectionStatus, } from "jazz-tools/testing";
10
10
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/svelte/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE5E,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE7E,wBAAgB,qBAAqB,CAAC,GAAG,SAAS,OAAO,EACvD,IAAI,GAAE;IACJ,OAAO,CAAC,EAAE,GAAG,GAAG;QAAE,KAAK,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;CACtB,sDAyBP;AAED,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/svelte/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE5E,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE7E,wBAAgB,qBAAqB,CAAC,GAAG,SAAS,OAAO,EACvD,IAAI,GAAE;IACJ,OAAO,CAAC,EAAE,GAAG,GAAG;QAAE,KAAK,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;CACtB,sDAyBP;AAED,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
@@ -20,4 +20,4 @@ export function createJazzTestContext(opts = {}) {
20
20
  }
21
21
  return ctx;
22
22
  }
23
- export { createJazzTestAccount, createJazzTestGuest, linkAccounts, setActiveAccount, setupJazzTestSync, } from "jazz-tools/testing";
23
+ export { createJazzTestAccount, createJazzTestGuest, linkAccounts, setActiveAccount, setupJazzTestSync, MockConnectionStatus, } from "jazz-tools/testing";
@@ -0,0 +1,8 @@
1
+ <script>
2
+ import { SyncConnectionStatus } from "../jazz.class.svelte";
3
+ const connectionStatus = new SyncConnectionStatus();
4
+ </script>
5
+
6
+ <div>
7
+ <div data-testid="connected">{connectionStatus.current ? "true" : "false"}</div>
8
+ </div>
@@ -0,0 +1,27 @@
1
+ export default TestConnectionStatus;
2
+ type TestConnectionStatus = SvelteComponent<{
3
+ [x: string]: never;
4
+ }, {
5
+ [evt: string]: CustomEvent<any>;
6
+ }, {}> & {
7
+ $$bindings?: string | undefined;
8
+ };
9
+ declare const TestConnectionStatus: $$__sveltets_2_IsomorphicComponent<{
10
+ [x: string]: never;
11
+ }, {
12
+ [evt: string]: CustomEvent<any>;
13
+ }, {}, {}, string>;
14
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
15
+ new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
16
+ $$bindings?: Bindings;
17
+ } & Exports;
18
+ (internal: unknown, props: {
19
+ $$events?: Events;
20
+ $$slots?: Slots;
21
+ }): Exports & {
22
+ $set?: any;
23
+ $on?: any;
24
+ };
25
+ z_$$bindings?: Bindings;
26
+ }
27
+ //# sourceMappingURL=TestConnectionStatus.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TestConnectionStatus.svelte.d.ts","sourceRoot":"","sources":["../../../../src/svelte/tests/TestConnectionStatus.svelte.js"],"names":[],"mappings":";;;;;;;;AAyBA;;;;mBAA8H;6CATjF,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ,OAAO,OAAO,QAAQ;IAC3L,cAAc,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,WAAW,OAAO,SAAS;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IACtG,eAAe,QAAQ,CAAC"}
@@ -10,7 +10,7 @@ describe("Image", async () => {
10
10
  });
11
11
  const renderWithAccount = (props) => render(Image, props, { account });
12
12
  describe("initial rendering", () => {
13
- it("should render nothing if coValue is not found", async () => {
13
+ it("should render a blank placeholder while waiting for the coValue to load", async () => {
14
14
  const { container } = renderWithAccount({
15
15
  imageId: "co_zMTubMby3QiKDYnW9e2BEXW7Xaq",
16
16
  alt: "test",
@@ -20,7 +20,21 @@ describe("Image", async () => {
20
20
  expect(img.getAttribute("width")).toBe(null);
21
21
  expect(img.getAttribute("height")).toBe(null);
22
22
  expect(img.alt).toBe("test");
23
- expect(img.src).toBe("");
23
+ expect(img.src).toBe("data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
24
+ });
25
+ it("should render nothing if coValue is not found", async () => {
26
+ const { container } = renderWithAccount({
27
+ imageId: "co_zMTubMby3QiKDYnW9e2BEXW7Xaq",
28
+ alt: "test",
29
+ });
30
+ await waitFor(() => {
31
+ const img = container.querySelector("img");
32
+ expect(img).toBeDefined();
33
+ expect(img.getAttribute("width")).toBe(null);
34
+ expect(img.getAttribute("height")).toBe(null);
35
+ expect(img.alt).toBe("test");
36
+ expect(img.src).toBe("");
37
+ });
24
38
  });
25
39
  it("should render an empty image if the image is not loaded yet", async () => {
26
40
  const original = FileStream.create({ owner: account.$jazz.owner });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sync-connection-status.svelte.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-connection-status.svelte.test.d.ts","sourceRoot":"","sources":["../../../../src/svelte/tests/sync-connection-status.svelte.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ // @vitest-environment happy-dom
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { createJazzTestAccount, setupJazzTestSync, MockConnectionStatus, } from "../testing";
4
+ import { render, screen, waitFor } from "./testUtils";
5
+ import TestConnectionStatus from "./TestConnectionStatus.svelte";
6
+ describe("SyncConnectionStatus", () => {
7
+ beforeEach(async () => {
8
+ await setupJazzTestSync();
9
+ await createJazzTestAccount({
10
+ isCurrentActiveAccount: true,
11
+ });
12
+ });
13
+ afterEach(() => {
14
+ vi.clearAllMocks();
15
+ });
16
+ it("should return true by default in the test environment", async () => {
17
+ const { container } = render(TestConnectionStatus, {}, {
18
+ account: await createJazzTestAccount({
19
+ isCurrentActiveAccount: true,
20
+ }),
21
+ });
22
+ await waitFor(() => {
23
+ expect(screen.getByTestId("connected").textContent).toBe("true");
24
+ });
25
+ });
26
+ it("should handle updates", async () => {
27
+ const { container } = render(TestConnectionStatus, {}, {
28
+ account: await createJazzTestAccount({
29
+ isCurrentActiveAccount: true,
30
+ }),
31
+ });
32
+ // Initially should be connected
33
+ await waitFor(() => {
34
+ expect(screen.getByTestId("connected").textContent).toBe("true");
35
+ });
36
+ // Simulate disconnection
37
+ MockConnectionStatus.setIsConnected(false);
38
+ await waitFor(() => {
39
+ expect(screen.getByTestId("connected").textContent).toBe("false");
40
+ });
41
+ // Simulate reconnection
42
+ MockConnectionStatus.setIsConnected(true);
43
+ await waitFor(() => {
44
+ expect(screen.getByTestId("connected").textContent).toBe("true");
45
+ });
46
+ });
47
+ });
package/dist/testing.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  createAnonymousJazzContext,
7
7
  createJazzContext,
8
8
  randomSessionProvider
9
- } from "./chunk-GRN6OAUX.js";
9
+ } from "./chunk-FHRKDKDY.js";
10
10
 
11
11
  // src/tools/testing.ts
12
12
  import { LocalNode } from "cojson";
@@ -124,6 +124,23 @@ async function createJazzTestGuest() {
124
124
  guest: ctx.agent
125
125
  };
126
126
  }
127
+ var _MockConnectionStatus = class _MockConnectionStatus {
128
+ static setIsConnected(isConnected) {
129
+ _MockConnectionStatus.connected = isConnected;
130
+ for (const listener of _MockConnectionStatus.connectionListeners) {
131
+ listener(isConnected);
132
+ }
133
+ }
134
+ static addConnectionListener(listener) {
135
+ _MockConnectionStatus.connectionListeners.add(listener);
136
+ return () => {
137
+ _MockConnectionStatus.connectionListeners.delete(listener);
138
+ };
139
+ }
140
+ };
141
+ _MockConnectionStatus.connected = true;
142
+ _MockConnectionStatus.connectionListeners = /* @__PURE__ */ new Set();
143
+ var MockConnectionStatus = _MockConnectionStatus;
127
144
  var TestJazzContextManager = class _TestJazzContextManager extends JazzContextManager {
128
145
  static fromAccountOrGuest(account, props) {
129
146
  if (account && "guest" in account) {
@@ -157,7 +174,11 @@ var TestJazzContextManager = class _TestJazzContextManager extends JazzContextMa
157
174
  logOut: async () => {
158
175
  await storage.clear();
159
176
  node.gracefulShutdown();
160
- }
177
+ },
178
+ addConnectionListener: (listener) => {
179
+ return MockConnectionStatus.addConnectionListener(listener);
180
+ },
181
+ connected: () => MockConnectionStatus.connected
161
182
  },
162
183
  {
163
184
  credentials
@@ -176,7 +197,11 @@ var TestJazzContextManager = class _TestJazzContextManager extends JazzContextMa
176
197
  },
177
198
  logOut: async () => {
178
199
  node.gracefulShutdown();
179
- }
200
+ },
201
+ addConnectionListener: (listener) => {
202
+ return MockConnectionStatus.addConnectionListener(listener);
203
+ },
204
+ connected: () => MockConnectionStatus.connected
180
205
  });
181
206
  return context;
182
207
  }
@@ -204,7 +229,11 @@ var TestJazzContextManager = class _TestJazzContextManager extends JazzContextMa
204
229
  },
205
230
  logOut: () => {
206
231
  return context.logOut();
207
- }
232
+ },
233
+ addConnectionListener: (listener) => {
234
+ return MockConnectionStatus.addConnectionListener(listener);
235
+ },
236
+ connected: () => MockConnectionStatus.connected
208
237
  };
209
238
  }
210
239
  };
@@ -239,6 +268,7 @@ async function setupJazzTestSync({
239
268
  return account;
240
269
  }
241
270
  export {
271
+ MockConnectionStatus,
242
272
  TestJSCrypto,
243
273
  TestJazzContextManager,
244
274
  createJazzTestAccount,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tools/testing.ts"],"sourcesContent":["import { LocalNode } from \"cojson\";\nimport { cojsonInternals } from \"cojson\";\nimport { PureJSCrypto } from \"cojson/dist/crypto/PureJSCrypto\";\nimport {\n Account,\n AccountClass,\n type AnonymousJazzAgent,\n AuthCredentials,\n CoValueFromRaw,\n CoreAccountSchema,\n InstanceOfSchema,\n JazzContextManager,\n JazzContextManagerAuthProps,\n JazzContextManagerBaseProps,\n activeAccountContext,\n coValueClassFromCoValueClassOrSchema,\n createAnonymousJazzContext,\n createJazzContext,\n randomSessionProvider,\n} from \"./internal.js\";\n\nconst syncServer: { current: LocalNode | null; asyncPeers: boolean } = {\n current: null,\n asyncPeers: false,\n};\n\nexport class TestJSCrypto extends PureJSCrypto {\n static async create() {\n if (\"navigator\" in globalThis && navigator.userAgent?.includes(\"jsdom\")) {\n // Mocking crypto seal & encrypt to make it work with JSDom. Getting \"Error: Uint8Array expected\" there\n const crypto = new PureJSCrypto();\n\n crypto.seal = (options) =>\n `sealed_U${cojsonInternals.stableStringify(options.message)}` as any;\n crypto.unseal = (sealed) =>\n JSON.parse(sealed.substring(\"sealed_U\".length));\n crypto.encrypt = (message) =>\n `encrypted_U${cojsonInternals.stableStringify(message)}` as any;\n crypto.decryptRaw = (encrypted) =>\n encrypted.substring(\"encrypted_U\".length) as any;\n\n return crypto;\n }\n\n // For non-jsdom environments, we use the real crypto\n return new PureJSCrypto();\n }\n}\n\nexport function getPeerConnectedToTestSyncServer() {\n if (!syncServer.current) {\n throw new Error(\"Sync server not initialized\");\n }\n\n const [aPeer, bPeer] = cojsonInternals.connectedPeers(\n Math.random().toString(),\n Math.random().toString(),\n {\n peer1role: \"client\",\n peer2role: \"server\",\n },\n );\n\n if (syncServer.asyncPeers) {\n const push = aPeer.outgoing.push;\n\n aPeer.outgoing.push = (message) => {\n setTimeout(() => {\n push.call(aPeer.outgoing, message);\n });\n };\n\n bPeer.outgoing.push = (message) => {\n setTimeout(() => {\n push.call(bPeer.outgoing, message);\n });\n };\n }\n\n syncServer.current.syncManager.addPeer(aPeer);\n\n return bPeer;\n}\n\nconst SecretSeedMap = new Map<string, Uint8Array>();\nlet isMigrationActive = false;\n\nexport async function createJazzTestAccount<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | CoreAccountSchema,\n>(options?: {\n isCurrentActiveAccount?: boolean;\n AccountSchema?: S;\n creationProps?: Record<string, unknown>;\n}): Promise<InstanceOfSchema<S>> {\n const AccountClass = options?.AccountSchema\n ? coValueClassFromCoValueClassOrSchema(options.AccountSchema)\n : Account;\n const peers = [];\n if (syncServer.current) {\n peers.push(getPeerConnectedToTestSyncServer());\n }\n\n const crypto = await TestJSCrypto.create();\n const secretSeed = crypto.newRandomSecretSeed();\n\n const { node } = await LocalNode.withNewlyCreatedAccount({\n creationProps: {\n name: \"Test Account\",\n ...options?.creationProps,\n },\n initialAgentSecret: crypto.agentSecretFromSecretSeed(secretSeed),\n crypto,\n peersToLoadFrom: peers,\n migration: async (rawAccount, _node, creationProps) => {\n if (isMigrationActive) {\n throw new Error(\n \"It is not possible to create multiple accounts in parallel inside the test environment.\",\n );\n }\n\n isMigrationActive = true;\n\n // @ts-expect-error - AccountClass doesn't infer the fromRaw static method\n const account = AccountClass.fromRaw(rawAccount) as InstanceOfSchema<S>;\n\n // We need to set the account as current because the migration\n // will probably rely on the global me\n const prevActiveAccount = activeAccountContext.maybeGet();\n activeAccountContext.set(account);\n\n await account.applyMigration?.(creationProps);\n\n if (!options?.isCurrentActiveAccount) {\n activeAccountContext.set(prevActiveAccount);\n }\n\n isMigrationActive = false;\n },\n });\n\n const account = AccountClass.fromNode(node);\n SecretSeedMap.set(account.$jazz.id, secretSeed);\n\n if (options?.isCurrentActiveAccount) {\n activeAccountContext.set(account);\n }\n\n return account as InstanceOfSchema<S>;\n}\n\nexport function setActiveAccount(account: Account) {\n activeAccountContext.set(account);\n}\n\n/**\n * Run a callback without an active account.\n *\n * Takes care of restoring the active account after the callback is run.\n *\n * If the callback returns a promise, waits for it before restoring the active account.\n *\n * @param callback - The callback to run.\n * @returns The result of the callback.\n */\nexport function runWithoutActiveAccount<Result>(\n callback: () => Result,\n): Result {\n const me = Account.getMe();\n activeAccountContext.set(null);\n const result = callback();\n\n if (result instanceof Promise) {\n return result.finally(() => {\n activeAccountContext.set(me);\n return result;\n }) as Result;\n }\n\n activeAccountContext.set(me);\n return result;\n}\n\nexport async function createJazzTestGuest() {\n const ctx = await createAnonymousJazzContext({\n crypto: await PureJSCrypto.create(),\n peersToLoadFrom: [],\n });\n\n return {\n guest: ctx.agent,\n };\n}\n\nexport type TestJazzContextManagerProps<Acc extends Account> =\n JazzContextManagerBaseProps<Acc> & {\n defaultProfileName?: string;\n AccountSchema?: AccountClass<Acc> & CoValueFromRaw<Acc>;\n isAuthenticated?: boolean;\n };\n\nexport class TestJazzContextManager<\n Acc extends Account,\n> extends JazzContextManager<Acc, TestJazzContextManagerProps<Acc>> {\n static fromAccountOrGuest<Acc extends Account>(\n account?: Acc | { guest: AnonymousJazzAgent },\n props?: TestJazzContextManagerProps<Acc>,\n ) {\n if (account && \"guest\" in account) {\n return this.fromGuest<Acc>(account, props);\n }\n\n return this.fromAccount<Acc>(account ?? (Account.getMe() as Acc), props);\n }\n\n static fromAccount<Acc extends Account>(\n account: Acc,\n props?: TestJazzContextManagerProps<Acc>,\n ) {\n const context = new TestJazzContextManager<Acc>();\n\n const provider = props?.isAuthenticated ? \"testProvider\" : \"anonymous\";\n const storage = context.getAuthSecretStorage();\n const node = account.$jazz.localNode;\n\n const credentials = {\n accountID: account.$jazz.id,\n accountSecret: node.getCurrentAgent().agentSecret,\n secretSeed: SecretSeedMap.get(account.$jazz.id),\n provider,\n } satisfies AuthCredentials;\n\n storage.set(credentials);\n\n context.updateContext(\n {\n AccountSchema: account.constructor as AccountClass<Acc> &\n CoValueFromRaw<Acc>,\n ...props,\n },\n {\n me: account,\n node,\n done: () => {\n node.gracefulShutdown();\n },\n logOut: async () => {\n await storage.clear();\n node.gracefulShutdown();\n },\n },\n {\n credentials,\n },\n );\n\n return context;\n }\n\n static fromGuest<Acc extends Account>(\n { guest }: { guest: AnonymousJazzAgent },\n props: TestJazzContextManagerProps<Acc> = {},\n ) {\n const context = new TestJazzContextManager<Acc>();\n const node = guest.node;\n\n context.updateContext(props, {\n guest,\n node,\n done: () => {\n node.gracefulShutdown();\n },\n logOut: async () => {\n node.gracefulShutdown();\n },\n });\n\n return context;\n }\n\n async getNewContext(\n props: TestJazzContextManagerProps<Acc>,\n authProps?: JazzContextManagerAuthProps,\n ) {\n if (!syncServer.current) {\n throw new Error(\n \"You need to setup a test sync server with setupJazzTestSync to use the Auth functions\",\n );\n }\n\n const context = await createJazzContext({\n credentials: authProps?.credentials,\n defaultProfileName: props.defaultProfileName,\n newAccountProps: authProps?.newAccountProps,\n peersToLoadFrom: [getPeerConnectedToTestSyncServer()],\n crypto: await TestJSCrypto.create(),\n sessionProvider: randomSessionProvider,\n authSecretStorage: this.getAuthSecretStorage(),\n AccountSchema: props.AccountSchema,\n });\n\n return {\n me: context.account,\n node: context.node,\n done: () => {\n context.done();\n },\n logOut: () => {\n return context.logOut();\n },\n };\n }\n}\n\nexport async function linkAccounts(\n a: Account,\n b: Account,\n aRole: \"server\" | \"client\" = \"server\",\n bRole: \"server\" | \"client\" = \"server\",\n) {\n const [aPeer, bPeer] = cojsonInternals.connectedPeers(\n b.$jazz.id,\n a.$jazz.id,\n {\n peer1role: aRole,\n peer2role: bRole,\n },\n );\n\n a.$jazz.localNode.syncManager.addPeer(aPeer);\n b.$jazz.localNode.syncManager.addPeer(bPeer);\n\n await a.$jazz.waitForAllCoValuesSync();\n await b.$jazz.waitForAllCoValuesSync();\n}\n\nexport async function setupJazzTestSync({\n asyncPeers = false,\n}: {\n asyncPeers?: boolean;\n} = {}) {\n if (syncServer.current) {\n syncServer.current.gracefulShutdown();\n }\n\n const account = await Account.create({\n creationProps: {\n name: \"Test Account\",\n },\n crypto: await TestJSCrypto.create(),\n });\n\n syncServer.current = account.$jazz.localNode;\n syncServer.asyncPeers = asyncPeers;\n\n return account;\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAmB7B,IAAM,aAAiE;AAAA,EACrE,SAAS;AAAA,EACT,YAAY;AACd;AAEO,IAAM,eAAN,cAA2B,aAAa;AAAA,EAC7C,aAAa,SAAS;AACpB,QAAI,eAAe,cAAc,UAAU,WAAW,SAAS,OAAO,GAAG;AAEvE,YAAM,SAAS,IAAI,aAAa;AAEhC,aAAO,OAAO,CAAC,YACb,WAAW,gBAAgB,gBAAgB,QAAQ,OAAO,CAAC;AAC7D,aAAO,SAAS,CAAC,WACf,KAAK,MAAM,OAAO,UAAU,WAAW,MAAM,CAAC;AAChD,aAAO,UAAU,CAAC,YAChB,cAAc,gBAAgB,gBAAgB,OAAO,CAAC;AACxD,aAAO,aAAa,CAAC,cACnB,UAAU,UAAU,cAAc,MAAM;AAE1C,aAAO;AAAA,IACT;AAGA,WAAO,IAAI,aAAa;AAAA,EAC1B;AACF;AAEO,SAAS,mCAAmC;AACjD,MAAI,CAAC,WAAW,SAAS;AACvB,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAEA,QAAM,CAAC,OAAO,KAAK,IAAI,gBAAgB;AAAA,IACrC,KAAK,OAAO,EAAE,SAAS;AAAA,IACvB,KAAK,OAAO,EAAE,SAAS;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,QAAQ;AAAA,MACd,MAAM,MAAM;AACV,gBAAQ,KAAK;AAAA,MACf;AAAA,MACA,QAAQ,MAAM;AACZ,eAAO,QAAQ,OAAO;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;AAEA,eAAsB,aACpB,GACA,GACA,QAA6B,UAC7B,QAA6B,UAC7B;AACA,QAAM,CAAC,OAAO,KAAK,IAAI,gBAAgB;AAAA,IACrC,EAAE,MAAM;AAAA,IACR,EAAE,MAAM;AAAA,IACR;AAAA,MACE,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,IAAE,MAAM,UAAU,YAAY,QAAQ,KAAK;AAC3C,IAAE,MAAM,UAAU,YAAY,QAAQ,KAAK;AAE3C,QAAM,EAAE,MAAM,uBAAuB;AACrC,QAAM,EAAE,MAAM,uBAAuB;AACvC;AAEA,eAAsB,kBAAkB;AAAA,EACtC,aAAa;AACf,IAEI,CAAC,GAAG;AACN,MAAI,WAAW,SAAS;AACtB,eAAW,QAAQ,iBAAiB;AAAA,EACtC;AAEA,QAAM,UAAU,MAAM,QAAQ,OAAO;AAAA,IACnC,eAAe;AAAA,MACb,MAAM;AAAA,IACR;AAAA,IACA,QAAQ,MAAM,aAAa,OAAO;AAAA,EACpC,CAAC;AAED,aAAW,UAAU,QAAQ,MAAM;AACnC,aAAW,aAAa;AAExB,SAAO;AACT;","names":["AccountClass","account"]}
1
+ {"version":3,"sources":["../src/tools/testing.ts"],"sourcesContent":["import { LocalNode } from \"cojson\";\nimport { cojsonInternals } from \"cojson\";\nimport { PureJSCrypto } from \"cojson/dist/crypto/PureJSCrypto\";\nimport {\n Account,\n AccountClass,\n type AnonymousJazzAgent,\n AuthCredentials,\n CoValueFromRaw,\n CoreAccountSchema,\n InstanceOfSchema,\n JazzContextManager,\n JazzContextManagerAuthProps,\n JazzContextManagerBaseProps,\n activeAccountContext,\n coValueClassFromCoValueClassOrSchema,\n createAnonymousJazzContext,\n createJazzContext,\n randomSessionProvider,\n} from \"./internal.js\";\n\nconst syncServer: { current: LocalNode | null; asyncPeers: boolean } = {\n current: null,\n asyncPeers: false,\n};\n\nexport class TestJSCrypto extends PureJSCrypto {\n static async create() {\n if (\"navigator\" in globalThis && navigator.userAgent?.includes(\"jsdom\")) {\n // Mocking crypto seal & encrypt to make it work with JSDom. Getting \"Error: Uint8Array expected\" there\n const crypto = new PureJSCrypto();\n\n crypto.seal = (options) =>\n `sealed_U${cojsonInternals.stableStringify(options.message)}` as any;\n crypto.unseal = (sealed) =>\n JSON.parse(sealed.substring(\"sealed_U\".length));\n crypto.encrypt = (message) =>\n `encrypted_U${cojsonInternals.stableStringify(message)}` as any;\n crypto.decryptRaw = (encrypted) =>\n encrypted.substring(\"encrypted_U\".length) as any;\n\n return crypto;\n }\n\n // For non-jsdom environments, we use the real crypto\n return new PureJSCrypto();\n }\n}\n\nexport function getPeerConnectedToTestSyncServer() {\n if (!syncServer.current) {\n throw new Error(\"Sync server not initialized\");\n }\n\n const [aPeer, bPeer] = cojsonInternals.connectedPeers(\n Math.random().toString(),\n Math.random().toString(),\n {\n peer1role: \"client\",\n peer2role: \"server\",\n },\n );\n\n if (syncServer.asyncPeers) {\n const push = aPeer.outgoing.push;\n\n aPeer.outgoing.push = (message) => {\n setTimeout(() => {\n push.call(aPeer.outgoing, message);\n });\n };\n\n bPeer.outgoing.push = (message) => {\n setTimeout(() => {\n push.call(bPeer.outgoing, message);\n });\n };\n }\n\n syncServer.current.syncManager.addPeer(aPeer);\n\n return bPeer;\n}\n\nconst SecretSeedMap = new Map<string, Uint8Array>();\nlet isMigrationActive = false;\n\nexport async function createJazzTestAccount<\n S extends\n | (AccountClass<Account> & CoValueFromRaw<Account>)\n | CoreAccountSchema,\n>(options?: {\n isCurrentActiveAccount?: boolean;\n AccountSchema?: S;\n creationProps?: Record<string, unknown>;\n}): Promise<InstanceOfSchema<S>> {\n const AccountClass = options?.AccountSchema\n ? coValueClassFromCoValueClassOrSchema(options.AccountSchema)\n : Account;\n const peers = [];\n if (syncServer.current) {\n peers.push(getPeerConnectedToTestSyncServer());\n }\n\n const crypto = await TestJSCrypto.create();\n const secretSeed = crypto.newRandomSecretSeed();\n\n const { node } = await LocalNode.withNewlyCreatedAccount({\n creationProps: {\n name: \"Test Account\",\n ...options?.creationProps,\n },\n initialAgentSecret: crypto.agentSecretFromSecretSeed(secretSeed),\n crypto,\n peersToLoadFrom: peers,\n migration: async (rawAccount, _node, creationProps) => {\n if (isMigrationActive) {\n throw new Error(\n \"It is not possible to create multiple accounts in parallel inside the test environment.\",\n );\n }\n\n isMigrationActive = true;\n\n // @ts-expect-error - AccountClass doesn't infer the fromRaw static method\n const account = AccountClass.fromRaw(rawAccount) as InstanceOfSchema<S>;\n\n // We need to set the account as current because the migration\n // will probably rely on the global me\n const prevActiveAccount = activeAccountContext.maybeGet();\n activeAccountContext.set(account);\n\n await account.applyMigration?.(creationProps);\n\n if (!options?.isCurrentActiveAccount) {\n activeAccountContext.set(prevActiveAccount);\n }\n\n isMigrationActive = false;\n },\n });\n\n const account = AccountClass.fromNode(node);\n SecretSeedMap.set(account.$jazz.id, secretSeed);\n\n if (options?.isCurrentActiveAccount) {\n activeAccountContext.set(account);\n }\n\n return account as InstanceOfSchema<S>;\n}\n\nexport function setActiveAccount(account: Account) {\n activeAccountContext.set(account);\n}\n\n/**\n * Run a callback without an active account.\n *\n * Takes care of restoring the active account after the callback is run.\n *\n * If the callback returns a promise, waits for it before restoring the active account.\n *\n * @param callback - The callback to run.\n * @returns The result of the callback.\n */\nexport function runWithoutActiveAccount<Result>(\n callback: () => Result,\n): Result {\n const me = Account.getMe();\n activeAccountContext.set(null);\n const result = callback();\n\n if (result instanceof Promise) {\n return result.finally(() => {\n activeAccountContext.set(me);\n return result;\n }) as Result;\n }\n\n activeAccountContext.set(me);\n return result;\n}\n\nexport async function createJazzTestGuest() {\n const ctx = await createAnonymousJazzContext({\n crypto: await PureJSCrypto.create(),\n peersToLoadFrom: [],\n });\n\n return {\n guest: ctx.agent,\n };\n}\n\nexport class MockConnectionStatus {\n static connected: boolean = true;\n static connectionListeners = new Set<(isConnected: boolean) => void>();\n static setIsConnected(isConnected: boolean) {\n MockConnectionStatus.connected = isConnected;\n for (const listener of MockConnectionStatus.connectionListeners) {\n listener(isConnected);\n }\n }\n static addConnectionListener(listener: (isConnected: boolean) => void) {\n MockConnectionStatus.connectionListeners.add(listener);\n return () => {\n MockConnectionStatus.connectionListeners.delete(listener);\n };\n }\n}\n\nexport type TestJazzContextManagerProps<Acc extends Account> =\n JazzContextManagerBaseProps<Acc> & {\n defaultProfileName?: string;\n AccountSchema?: AccountClass<Acc> & CoValueFromRaw<Acc>;\n isAuthenticated?: boolean;\n };\n\nexport class TestJazzContextManager<\n Acc extends Account,\n> extends JazzContextManager<Acc, TestJazzContextManagerProps<Acc>> {\n static fromAccountOrGuest<Acc extends Account>(\n account?: Acc | { guest: AnonymousJazzAgent },\n props?: TestJazzContextManagerProps<Acc>,\n ) {\n if (account && \"guest\" in account) {\n return this.fromGuest<Acc>(account, props);\n }\n\n return this.fromAccount<Acc>(account ?? (Account.getMe() as Acc), props);\n }\n\n static fromAccount<Acc extends Account>(\n account: Acc,\n props?: TestJazzContextManagerProps<Acc>,\n ) {\n const context = new TestJazzContextManager<Acc>();\n\n const provider = props?.isAuthenticated ? \"testProvider\" : \"anonymous\";\n const storage = context.getAuthSecretStorage();\n const node = account.$jazz.localNode;\n\n const credentials = {\n accountID: account.$jazz.id,\n accountSecret: node.getCurrentAgent().agentSecret,\n secretSeed: SecretSeedMap.get(account.$jazz.id),\n provider,\n } satisfies AuthCredentials;\n\n storage.set(credentials);\n\n context.updateContext(\n {\n AccountSchema: account.constructor as AccountClass<Acc> &\n CoValueFromRaw<Acc>,\n ...props,\n },\n {\n me: account,\n node,\n done: () => {\n node.gracefulShutdown();\n },\n logOut: async () => {\n await storage.clear();\n node.gracefulShutdown();\n },\n addConnectionListener: (listener) => {\n return MockConnectionStatus.addConnectionListener(listener);\n },\n connected: () => MockConnectionStatus.connected,\n },\n {\n credentials,\n },\n );\n\n return context;\n }\n\n static fromGuest<Acc extends Account>(\n { guest }: { guest: AnonymousJazzAgent },\n props: TestJazzContextManagerProps<Acc> = {},\n ) {\n const context = new TestJazzContextManager<Acc>();\n const node = guest.node;\n\n context.updateContext(props, {\n guest,\n node,\n done: () => {\n node.gracefulShutdown();\n },\n logOut: async () => {\n node.gracefulShutdown();\n },\n addConnectionListener: (listener) => {\n return MockConnectionStatus.addConnectionListener(listener);\n },\n connected: () => MockConnectionStatus.connected,\n });\n\n return context;\n }\n\n async getNewContext(\n props: TestJazzContextManagerProps<Acc>,\n authProps?: JazzContextManagerAuthProps,\n ) {\n if (!syncServer.current) {\n throw new Error(\n \"You need to setup a test sync server with setupJazzTestSync to use the Auth functions\",\n );\n }\n\n const context = await createJazzContext({\n credentials: authProps?.credentials,\n defaultProfileName: props.defaultProfileName,\n newAccountProps: authProps?.newAccountProps,\n peersToLoadFrom: [getPeerConnectedToTestSyncServer()],\n crypto: await TestJSCrypto.create(),\n sessionProvider: randomSessionProvider,\n authSecretStorage: this.getAuthSecretStorage(),\n AccountSchema: props.AccountSchema,\n });\n\n return {\n me: context.account,\n node: context.node,\n done: () => {\n context.done();\n },\n logOut: () => {\n return context.logOut();\n },\n addConnectionListener: (listener: (isConnected: boolean) => void) => {\n return MockConnectionStatus.addConnectionListener(listener);\n },\n connected: () => MockConnectionStatus.connected,\n };\n }\n}\n\nexport async function linkAccounts(\n a: Account,\n b: Account,\n aRole: \"server\" | \"client\" = \"server\",\n bRole: \"server\" | \"client\" = \"server\",\n) {\n const [aPeer, bPeer] = cojsonInternals.connectedPeers(\n b.$jazz.id,\n a.$jazz.id,\n {\n peer1role: aRole,\n peer2role: bRole,\n },\n );\n\n a.$jazz.localNode.syncManager.addPeer(aPeer);\n b.$jazz.localNode.syncManager.addPeer(bPeer);\n\n await a.$jazz.waitForAllCoValuesSync();\n await b.$jazz.waitForAllCoValuesSync();\n}\n\nexport async function setupJazzTestSync({\n asyncPeers = false,\n}: {\n asyncPeers?: boolean;\n} = {}) {\n if (syncServer.current) {\n syncServer.current.gracefulShutdown();\n }\n\n const account = await Account.create({\n creationProps: {\n name: \"Test Account\",\n },\n crypto: await TestJSCrypto.create(),\n });\n\n syncServer.current = account.$jazz.localNode;\n syncServer.asyncPeers = asyncPeers;\n\n return account;\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAmB7B,IAAM,aAAiE;AAAA,EACrE,SAAS;AAAA,EACT,YAAY;AACd;AAEO,IAAM,eAAN,cAA2B,aAAa;AAAA,EAC7C,aAAa,SAAS;AACpB,QAAI,eAAe,cAAc,UAAU,WAAW,SAAS,OAAO,GAAG;AAEvE,YAAM,SAAS,IAAI,aAAa;AAEhC,aAAO,OAAO,CAAC,YACb,WAAW,gBAAgB,gBAAgB,QAAQ,OAAO,CAAC;AAC7D,aAAO,SAAS,CAAC,WACf,KAAK,MAAM,OAAO,UAAU,WAAW,MAAM,CAAC;AAChD,aAAO,UAAU,CAAC,YAChB,cAAc,gBAAgB,gBAAgB,OAAO,CAAC;AACxD,aAAO,aAAa,CAAC,cACnB,UAAU,UAAU,cAAc,MAAM;AAE1C,aAAO;AAAA,IACT;AAGA,WAAO,IAAI,aAAa;AAAA,EAC1B;AACF;AAEO,SAAS,mCAAmC;AACjD,MAAI,CAAC,WAAW,SAAS;AACvB,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAEA,QAAM,CAAC,OAAO,KAAK,IAAI,gBAAgB;AAAA,IACrC,KAAK,OAAO,EAAE,SAAS;AAAA,IACvB,KAAK,OAAO,EAAE,SAAS;AAAA,IACvB;AAAA,MACE,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,EACF;AAEA,MAAI,WAAW,YAAY;AACzB,UAAM,OAAO,MAAM,SAAS;AAE5B,UAAM,SAAS,OAAO,CAAC,YAAY;AACjC,iBAAW,MAAM;AAC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AQ,OAAO;AAAA,IACnC,eAAe;AAAA,MACb,MAAM;AAAA,IACR;AAAA,IACA,QAAQ,MAAM,aAAa,OAAO;AAAA,EACpC,CAAC;AAED,aAAW,UAAU,QAAQ,MAAM;AACnC,aAAW,aAAa;AAExB,SAAO;AACT;","names":["AccountClass","account"]}
@@ -24,12 +24,16 @@ type PlatformSpecificAuthContext<Acc extends Account> = {
24
24
  node: LocalNode;
25
25
  logOut: () => Promise<void>;
26
26
  done: () => void;
27
+ addConnectionListener: (listener: (connected: boolean) => void) => () => void;
28
+ connected: () => boolean;
27
29
  };
28
30
  type PlatformSpecificGuestContext = {
29
31
  guest: AnonymousJazzAgent;
30
32
  node: LocalNode;
31
33
  logOut: () => Promise<void>;
32
34
  done: () => void;
35
+ addConnectionListener: (listener: (connected: boolean) => void) => () => void;
36
+ connected: () => boolean;
33
37
  };
34
38
  type PlatformSpecificContext<Acc extends Account> = PlatformSpecificAuthContext<Acc> | PlatformSpecificGuestContext;
35
39
  export declare class JazzContextManager<Acc extends Account, P extends JazzContextManagerBaseProps<Acc>> {