jazz-tools 0.17.5 → 0.17.6
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/.turbo/turbo-build.log +46 -46
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-EEKKLGF2.js → chunk-SJHXI5AB.js} +4 -2
- package/dist/chunk-SJHXI5AB.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/media/{chunk-JBLT443O.js → chunk-E5J3WLQW.js} +2 -2
- package/dist/media/{chunk-JBLT443O.js.map → chunk-E5J3WLQW.js.map} +1 -1
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.js +1 -1
- package/dist/media/utils.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/testing.js +9 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +9 -0
- package/dist/tools/testing.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/media/utils.test.ts +3 -2
- package/src/media/utils.ts +5 -1
- package/src/tools/implementation/schema.ts +3 -1
- package/src/tools/testing.ts +18 -0
- package/src/tools/tests/coMap.test.ts +19 -1
- package/dist/chunk-EEKKLGF2.js.map +0 -1
package/src/media/utils.test.ts
CHANGED
@@ -347,7 +347,6 @@ describe("loadImageBySize", async () => {
|
|
347
347
|
|
348
348
|
it("returns the image already loaded", async () => {
|
349
349
|
const account = await setupJazzTestSync({ asyncPeers: true });
|
350
|
-
const account2 = await createJazzTestAccount();
|
351
350
|
|
352
351
|
setActiveAccount(account);
|
353
352
|
|
@@ -363,9 +362,11 @@ describe("loadImageBySize", async () => {
|
|
363
362
|
group,
|
364
363
|
);
|
365
364
|
|
365
|
+
const account2 = await createJazzTestAccount();
|
366
366
|
setActiveAccount(account2);
|
367
367
|
|
368
|
-
const result = await loadImageBySize(imageDef, 1024, 1024);
|
368
|
+
const result = await loadImageBySize(imageDef.id, 1024, 1024);
|
369
|
+
expect(result).not.toBeNull();
|
369
370
|
expect(result?.image.id).toBe(imageDef["1024x1024"]!.id);
|
370
371
|
expect(result?.image.isBinaryStreamEnded()).toBe(true);
|
371
372
|
expect(result?.image.asBase64()).toStrictEqual(expect.any(String));
|
package/src/media/utils.ts
CHANGED
@@ -185,7 +185,11 @@ export async function loadImageBySize(
|
|
185
185
|
const bestTarget =
|
186
186
|
sortedSizes.find((el) => el.match > 0.95) || sortedSizes.at(-1)!;
|
187
187
|
|
188
|
-
|
188
|
+
// The image's `wxh` keys reference FileStream.
|
189
|
+
// image[bestTarget.size[2]] returns undefined if FileStream hasn't loaded yet.
|
190
|
+
// Since we only need the file's ID to fetch it later, we check the raw _refs
|
191
|
+
// which contain only the linked covalue's ID.
|
192
|
+
const file = image._refs[bestTarget.size[2]];
|
189
193
|
|
190
194
|
if (!file) {
|
191
195
|
return null;
|
@@ -171,7 +171,9 @@ export function instantiateRefEncodedWithInit<V extends CoValue>(
|
|
171
171
|
`Cannot automatically create CoValue from value: ${JSON.stringify(init)}. Use the CoValue schema's create() method instead.`,
|
172
172
|
);
|
173
173
|
}
|
174
|
-
const
|
174
|
+
const node = parentOwner._raw.core.node;
|
175
|
+
const rawGroup = node.createGroup();
|
176
|
+
const owner = new Group({ fromRaw: rawGroup });
|
175
177
|
owner.addMember(parentOwner.castAs(Group));
|
176
178
|
// @ts-expect-error - create is a static method in all CoValue classes
|
177
179
|
return schema.ref.create(init, owner);
|
package/src/tools/testing.ts
CHANGED
@@ -154,6 +154,24 @@ export function setActiveAccount(account: Account) {
|
|
154
154
|
activeAccountContext.set(account);
|
155
155
|
}
|
156
156
|
|
157
|
+
/**
|
158
|
+
* Run a callback without an active account.
|
159
|
+
*
|
160
|
+
* Takes care of restoring the active account after the callback is run.
|
161
|
+
*
|
162
|
+
* @param callback - The callback to run.
|
163
|
+
* @returns The result of the callback.
|
164
|
+
*/
|
165
|
+
export function runWithoutActiveAccount<Result>(
|
166
|
+
callback: () => Result,
|
167
|
+
): Result {
|
168
|
+
const me = Account.getMe();
|
169
|
+
activeAccountContext.set(null);
|
170
|
+
const result = callback();
|
171
|
+
activeAccountContext.set(me);
|
172
|
+
return result;
|
173
|
+
}
|
174
|
+
|
157
175
|
export async function createJazzTestGuest() {
|
158
176
|
const ctx = await createAnonymousJazzContext({
|
159
177
|
crypto: await PureJSCrypto.create(),
|
@@ -12,10 +12,15 @@ import {
|
|
12
12
|
} from "vitest";
|
13
13
|
import { Group, co, subscribeToCoValue, z } from "../exports.js";
|
14
14
|
import { Account } from "../index.js";
|
15
|
-
import {
|
15
|
+
import {
|
16
|
+
Loaded,
|
17
|
+
activeAccountContext,
|
18
|
+
coValueClassFromCoValueClassOrSchema,
|
19
|
+
} from "../internal.js";
|
16
20
|
import {
|
17
21
|
createJazzTestAccount,
|
18
22
|
getPeerConnectedToTestSyncServer,
|
23
|
+
runWithoutActiveAccount,
|
19
24
|
setupJazzTestSync,
|
20
25
|
} from "../testing.js";
|
21
26
|
import { setupTwoNodes, waitFor } from "./utils.js";
|
@@ -214,6 +219,19 @@ describe("CoMap", async () => {
|
|
214
219
|
const map = Schema.create({ text: "" });
|
215
220
|
expect(map.text.toString()).toBe("");
|
216
221
|
});
|
222
|
+
|
223
|
+
it("creates a group for the new CoValue when there is no active account", () => {
|
224
|
+
const Schema = co.map({ text: co.plainText() });
|
225
|
+
|
226
|
+
const parentGroup = Group.create();
|
227
|
+
runWithoutActiveAccount(() => {
|
228
|
+
const map = Schema.create({ text: "Hello" }, parentGroup);
|
229
|
+
|
230
|
+
expect(
|
231
|
+
map.text._owner.getParentGroups().map((group: Group) => group.id),
|
232
|
+
).toContain(parentGroup.id);
|
233
|
+
});
|
234
|
+
});
|
217
235
|
});
|
218
236
|
|
219
237
|
test("CoMap with self reference", () => {
|