jazz-tools 0.13.31 → 0.14.0
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 +8 -8
- package/CHANGELOG.md +14 -3
- package/dist/auth/DemoAuth.d.ts.map +1 -1
- package/dist/auth/PassphraseAuth.d.ts +1 -3
- package/dist/auth/PassphraseAuth.d.ts.map +1 -1
- package/dist/{chunk-IJU4XPFS.js → chunk-2ASOGEYA.js} +3535 -3291
- package/dist/chunk-2ASOGEYA.js.map +1 -0
- package/dist/coValues/CoValueBase.d.ts +22 -0
- package/dist/coValues/CoValueBase.d.ts.map +1 -0
- package/dist/coValues/account.d.ts +12 -12
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/coFeed.d.ts +24 -25
- package/dist/coValues/coFeed.d.ts.map +1 -1
- package/dist/coValues/coList.d.ts +10 -13
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coMap.d.ts +32 -35
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/deepLoading.d.ts +17 -21
- package/dist/coValues/deepLoading.d.ts.map +1 -1
- package/dist/coValues/extensions/imageDef.d.ts +12 -11
- package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/coValues/group.d.ts +5 -9
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/inbox.d.ts +2 -3
- package/dist/coValues/inbox.d.ts.map +1 -1
- package/dist/coValues/interfaces.d.ts +8 -34
- package/dist/coValues/interfaces.d.ts.map +1 -1
- package/dist/coValues/profile.d.ts +4 -14
- package/dist/coValues/profile.d.ts.map +1 -1
- package/dist/coValues/registeredSchemas.d.ts +1 -3
- package/dist/coValues/registeredSchemas.d.ts.map +1 -1
- package/dist/coValues/schemaUnion.d.ts +6 -6
- package/dist/exports.d.ts +12 -16
- package/dist/exports.d.ts.map +1 -1
- package/dist/implementation/ContextManager.d.ts +1 -1
- package/dist/implementation/ContextManager.d.ts.map +1 -1
- package/dist/implementation/activeAccountContext.d.ts +1 -1
- package/dist/implementation/activeAccountContext.d.ts.map +1 -1
- package/dist/implementation/createContext.d.ts +10 -10
- package/dist/implementation/createContext.d.ts.map +1 -1
- package/dist/implementation/invites.d.ts +6 -6
- package/dist/implementation/invites.d.ts.map +1 -1
- package/dist/implementation/refs.d.ts +2 -2
- package/dist/implementation/refs.d.ts.map +1 -1
- package/dist/implementation/schema.d.ts +21 -28
- package/dist/implementation/schema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +9 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +28 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +65 -0
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +28 -0
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -0
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +41 -0
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +35 -0
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +9 -0
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +20 -0
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +18 -0
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +24 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +21 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +29 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +29 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/implementation/zodSchema/unionUtils.d.ts +6 -0
- package/dist/implementation/zodSchema/unionUtils.d.ts.map +1 -0
- package/dist/implementation/zodSchema/zodCo.d.ts +35 -0
- package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -0
- package/dist/implementation/zodSchema/zodSchema.d.ts +38 -0
- package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -0
- package/dist/index.js +295 -10
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +34 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/subscribe/SubscriptionScope.d.ts +1 -2
- package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/subscribe/utils.d.ts +2 -2
- package/dist/subscribe/utils.d.ts.map +1 -1
- package/dist/testing.d.ts +10 -8
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/tests/utils.d.ts +6 -2
- package/dist/tests/utils.d.ts.map +1 -1
- package/dist/types.d.ts +1 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/auth/DemoAuth.ts +1 -2
- package/src/auth/PassphraseAuth.ts +1 -1
- package/src/coValues/CoValueBase.ts +83 -0
- package/src/coValues/account.ts +53 -43
- package/src/coValues/coFeed.ts +65 -83
- package/src/coValues/coList.ts +28 -21
- package/src/coValues/coMap.ts +54 -38
- package/src/coValues/coPlainText.ts +4 -1
- package/src/coValues/deepLoading.ts +35 -43
- package/src/coValues/extensions/imageDef.ts +21 -19
- package/src/coValues/group.ts +37 -38
- package/src/coValues/inbox.ts +24 -11
- package/src/coValues/interfaces.ts +29 -93
- package/src/coValues/profile.ts +12 -13
- package/src/coValues/registeredSchemas.ts +1 -3
- package/src/coValues/schemaUnion.ts +6 -6
- package/src/exports.ts +47 -25
- package/src/implementation/activeAccountContext.ts +1 -1
- package/src/implementation/createContext.ts +39 -24
- package/src/implementation/invites.ts +15 -12
- package/src/implementation/refs.ts +6 -4
- package/src/implementation/schema.ts +22 -34
- package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +101 -0
- package/src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +191 -0
- package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +102 -0
- package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +70 -0
- package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +59 -0
- package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +126 -0
- package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +98 -0
- package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +9 -0
- package/src/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +27 -0
- package/src/implementation/zodSchema/schemaTypes/RichTextSchema.ts +25 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +61 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +77 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +90 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +103 -0
- package/src/implementation/zodSchema/unionUtils.ts +139 -0
- package/src/implementation/zodSchema/zodCo.ts +409 -0
- package/src/implementation/zodSchema/zodSchema.ts +116 -0
- package/src/internal.ts +38 -0
- package/src/subscribe/SubscriptionScope.ts +3 -1
- package/src/subscribe/utils.ts +7 -2
- package/src/testing.ts +14 -16
- package/src/tests/ContextManager.test.ts +73 -47
- package/src/tests/DemoAuth.test.ts +1 -1
- package/src/tests/account.test.ts +6 -9
- package/src/tests/coFeed.test.ts +102 -63
- package/src/tests/coList.test.ts +82 -95
- package/src/tests/coMap.record.test.ts +53 -87
- package/src/tests/coMap.test.ts +297 -312
- package/src/tests/coPlainText.test.ts +19 -39
- package/src/tests/createContext.test.ts +33 -15
- package/src/tests/deepLoading.test.ts +196 -179
- package/src/tests/groupsAndAccounts.test.ts +81 -72
- package/src/tests/imageDef.test.ts +22 -13
- package/src/tests/inbox.test.ts +36 -29
- package/src/tests/load.test.ts +10 -10
- package/src/tests/patterns/requestToJoin.test.ts +31 -31
- package/src/tests/schema.test.ts +37 -38
- package/src/tests/schemaUnion.test.ts +54 -64
- package/src/tests/subscribe.test.ts +118 -116
- package/src/tests/testing.test.ts +33 -33
- package/src/tests/utils.ts +3 -2
- package/src/types.ts +1 -8
- package/dist/chunk-IJU4XPFS.js.map +0 -1
- package/dist/tests/deepLoading.test-d.d.ts +0 -2
- package/dist/tests/deepLoading.test-d.d.ts.map +0 -1
- package/src/tests/deepLoading.test-d.ts +0 -393
@@ -2,12 +2,11 @@ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
3
3
|
import {
|
4
4
|
Account,
|
5
|
-
CoPlainText,
|
6
5
|
cojsonInternals,
|
7
6
|
createJazzContextFromExistingCredentials,
|
8
7
|
isControlledAccount,
|
9
8
|
} from "../index.js";
|
10
|
-
import { randomSessionProvider } from "../internal.js";
|
9
|
+
import { co, randomSessionProvider } from "../internal.js";
|
11
10
|
|
12
11
|
const Crypto = await WasmCrypto.create();
|
13
12
|
|
@@ -20,7 +19,7 @@ describe("CoPlainText", () => {
|
|
20
19
|
crypto: Crypto,
|
21
20
|
});
|
22
21
|
|
23
|
-
const text =
|
22
|
+
const text = co.plainText().create("hello world", { owner: me });
|
24
23
|
|
25
24
|
return { me, text };
|
26
25
|
};
|
@@ -31,16 +30,7 @@ describe("CoPlainText", () => {
|
|
31
30
|
creationProps: { name: "Hermes Puggington" },
|
32
31
|
crypto: Crypto,
|
33
32
|
});
|
34
|
-
const text =
|
35
|
-
expect(text._owner.id).toBe(me.id);
|
36
|
-
});
|
37
|
-
|
38
|
-
test("should allow `new CoPlainText`", async () => {
|
39
|
-
const me = await Account.create({
|
40
|
-
creationProps: { name: "Hermes Puggington" },
|
41
|
-
crypto: Crypto,
|
42
|
-
});
|
43
|
-
const text = new CoPlainText({ text: "hello world", owner: me });
|
33
|
+
const text = co.plainText().create("hello world", me);
|
44
34
|
expect(text._owner.id).toBe(me.id);
|
45
35
|
});
|
46
36
|
|
@@ -49,28 +39,18 @@ describe("CoPlainText", () => {
|
|
49
39
|
creationProps: { name: "Hermes Puggington" },
|
50
40
|
crypto: Crypto,
|
51
41
|
});
|
52
|
-
const text =
|
42
|
+
const text = co.plainText().create("hello world", me);
|
53
43
|
const raw = text._raw;
|
54
|
-
const text2 =
|
44
|
+
const text2 = co.plainText().fromRaw(raw);
|
55
45
|
expect(text2._owner.id).toBe(me.id);
|
56
46
|
});
|
57
47
|
|
58
|
-
test("should allow creation of new instance from raw", async () => {
|
59
|
-
const me = await Account.create({
|
60
|
-
creationProps: { name: "Hermes Puggington" },
|
61
|
-
crypto: Crypto,
|
62
|
-
});
|
63
|
-
const raw = me._raw.createPlainText("hello world");
|
64
|
-
const text = new CoPlainText({ fromRaw: raw });
|
65
|
-
expect(text._owner.id).toBe(me.id);
|
66
|
-
});
|
67
|
-
|
68
48
|
test("should allow owner shorthand", async () => {
|
69
49
|
const me = await Account.create({
|
70
50
|
creationProps: { name: "Hermes Puggington" },
|
71
51
|
crypto: Crypto,
|
72
52
|
});
|
73
|
-
const text =
|
53
|
+
const text = co.plainText().create("hello world", me);
|
74
54
|
expect(text._owner.id).toBe(me.id);
|
75
55
|
});
|
76
56
|
});
|
@@ -84,7 +64,7 @@ describe("CoPlainText", () => {
|
|
84
64
|
|
85
65
|
describe("Mutation", () => {
|
86
66
|
test("insertion", () => {
|
87
|
-
const text =
|
67
|
+
const text = co.plainText().create("hello world", { owner: me });
|
88
68
|
|
89
69
|
text.insertAfter(4, " cruel");
|
90
70
|
expect(text + "").toEqual("hello cruel world");
|
@@ -94,14 +74,14 @@ describe("CoPlainText", () => {
|
|
94
74
|
});
|
95
75
|
|
96
76
|
test("deletion", () => {
|
97
|
-
const text =
|
77
|
+
const text = co.plainText().create("hello world", { owner: me });
|
98
78
|
|
99
79
|
text.deleteRange({ from: 3, to: 8 });
|
100
80
|
expect(text + "").toEqual("helrld");
|
101
81
|
});
|
102
82
|
|
103
83
|
test("applyDiff", () => {
|
104
|
-
const text =
|
84
|
+
const text = co.plainText().create("hello world", { owner: me });
|
105
85
|
text.applyDiff("hello cruel world");
|
106
86
|
expect(text.toString()).toEqual("hello cruel world");
|
107
87
|
});
|
@@ -109,39 +89,39 @@ describe("CoPlainText", () => {
|
|
109
89
|
|
110
90
|
describe("Properties", () => {
|
111
91
|
test("length", () => {
|
112
|
-
const text =
|
92
|
+
const text = co.plainText().create("hello world", { owner: me });
|
113
93
|
expect(text.length).toBe(11);
|
114
94
|
});
|
115
95
|
|
116
96
|
test("as string", () => {
|
117
|
-
const text =
|
97
|
+
const text = co.plainText().create("hello world", { owner: me });
|
118
98
|
expect(`${text}`).toBe("hello world");
|
119
99
|
});
|
120
100
|
|
121
101
|
test("as number", () => {
|
122
|
-
const text =
|
102
|
+
const text = co.plainText().create("hello world", { owner: me });
|
123
103
|
expect(Number(text)).toBe(NaN);
|
124
104
|
});
|
125
105
|
|
126
106
|
test("as number", () => {
|
127
|
-
const text =
|
107
|
+
const text = co.plainText().create("123", { owner: me });
|
128
108
|
expect(Number(text)).toBe(123);
|
129
109
|
});
|
130
110
|
|
131
111
|
test("toJSON", () => {
|
132
|
-
const text =
|
112
|
+
const text = co.plainText().create("hello world", { owner: me });
|
133
113
|
expect(text.toJSON()).toBe("hello world");
|
134
114
|
});
|
135
115
|
|
136
116
|
test("toString", () => {
|
137
|
-
const text =
|
117
|
+
const text = co.plainText().create("hello world", { owner: me });
|
138
118
|
expect(text.toString()).toBe("hello world");
|
139
119
|
});
|
140
120
|
});
|
141
121
|
|
142
122
|
describe("Position operations", () => {
|
143
123
|
test("idxBefore returns index before a position", () => {
|
144
|
-
const text =
|
124
|
+
const text = co.plainText().create("hello world", { owner: me });
|
145
125
|
|
146
126
|
// Get position at index 5 (between "hello" and " world")
|
147
127
|
const pos = text.posBefore(5);
|
@@ -155,7 +135,7 @@ describe("CoPlainText", () => {
|
|
155
135
|
});
|
156
136
|
|
157
137
|
test("idxAfter returns index after a position", () => {
|
158
|
-
const text =
|
138
|
+
const text = co.plainText().create("hello world", { owner: me });
|
159
139
|
|
160
140
|
// Get position at index 5 (between "hello" and " world")
|
161
141
|
const pos = text.posBefore(5);
|
@@ -197,7 +177,7 @@ describe("CoPlainText", () => {
|
|
197
177
|
});
|
198
178
|
|
199
179
|
// Load the text on the second peer
|
200
|
-
const loaded = await
|
180
|
+
const loaded = await co.plainText().load(id, { loadAs: meOnSecondPeer });
|
201
181
|
expect(loaded).toBeDefined();
|
202
182
|
expect(loaded!.toString()).toBe("hello world");
|
203
183
|
});
|
@@ -230,7 +210,7 @@ describe("CoPlainText", () => {
|
|
230
210
|
const queue = new cojsonInternals.Channel();
|
231
211
|
|
232
212
|
// Subscribe to text updates
|
233
|
-
|
213
|
+
co.plainText().subscribe(
|
234
214
|
text.id,
|
235
215
|
{ loadAs: meOnSecondPeer },
|
236
216
|
(subscribedText) => {
|
@@ -9,11 +9,14 @@ import {
|
|
9
9
|
ID,
|
10
10
|
InMemoryKVStore,
|
11
11
|
KvStoreContext,
|
12
|
+
co,
|
12
13
|
createAnonymousJazzContext,
|
13
14
|
createJazzContext,
|
14
15
|
createJazzContextForNewAccount,
|
15
16
|
createJazzContextFromExistingCredentials,
|
16
17
|
randomSessionProvider,
|
18
|
+
z,
|
19
|
+
zodSchemaToCoSchema,
|
17
20
|
} from "../exports";
|
18
21
|
import { activeAccountContext } from "../implementation/activeAccountContext";
|
19
22
|
import {
|
@@ -62,9 +65,12 @@ describe("createContext methods", () => {
|
|
62
65
|
});
|
63
66
|
|
64
67
|
test("handles custom account schema", async () => {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
const CustomAccount = co
|
69
|
+
.account({
|
70
|
+
root: co.map({}),
|
71
|
+
profile: co.profile(),
|
72
|
+
})
|
73
|
+
.withMigration(async () => {});
|
68
74
|
|
69
75
|
const account = await createJazzTestAccount({
|
70
76
|
isCurrentActiveAccount: true,
|
@@ -79,11 +85,13 @@ describe("createContext methods", () => {
|
|
79
85
|
credentials,
|
80
86
|
peersToLoadFrom: [getPeerConnectedToTestSyncServer()],
|
81
87
|
crypto: Crypto,
|
82
|
-
AccountSchema: CustomAccount,
|
88
|
+
AccountSchema: zodSchemaToCoSchema(CustomAccount),
|
83
89
|
sessionProvider: randomSessionProvider,
|
84
90
|
});
|
85
91
|
|
86
|
-
expect(context.account).toBeInstanceOf(
|
92
|
+
expect(context.account).toBeInstanceOf(
|
93
|
+
zodSchemaToCoSchema(CustomAccount),
|
94
|
+
);
|
87
95
|
});
|
88
96
|
|
89
97
|
test("calls onLogOut callback when logging out", async () => {
|
@@ -176,18 +184,23 @@ describe("createContext methods", () => {
|
|
176
184
|
});
|
177
185
|
|
178
186
|
test("handles custom account schema", async () => {
|
179
|
-
|
180
|
-
|
181
|
-
|
187
|
+
const CustomAccount = co
|
188
|
+
.account({
|
189
|
+
root: co.map({}),
|
190
|
+
profile: co.profile(),
|
191
|
+
})
|
192
|
+
.withMigration(async () => {});
|
182
193
|
|
183
194
|
const context = await createJazzContextForNewAccount({
|
184
195
|
creationProps: { name: "New User" },
|
185
196
|
peersToLoadFrom: [],
|
186
197
|
crypto: Crypto,
|
187
|
-
AccountSchema: CustomAccount,
|
198
|
+
AccountSchema: zodSchemaToCoSchema(CustomAccount),
|
188
199
|
});
|
189
200
|
|
190
|
-
expect(context.account).toBeInstanceOf(
|
201
|
+
expect(context.account).toBeInstanceOf(
|
202
|
+
zodSchemaToCoSchema(CustomAccount),
|
203
|
+
);
|
191
204
|
});
|
192
205
|
|
193
206
|
test("sets the active account to the new account", async () => {
|
@@ -321,19 +334,24 @@ describe("createContext methods", () => {
|
|
321
334
|
});
|
322
335
|
|
323
336
|
test("handles custom account schema", async () => {
|
324
|
-
|
325
|
-
|
326
|
-
|
337
|
+
const CustomAccount = co
|
338
|
+
.account({
|
339
|
+
root: co.map({}),
|
340
|
+
profile: co.profile(),
|
341
|
+
})
|
342
|
+
.withMigration(async () => {});
|
327
343
|
|
328
344
|
const context = await createJazzContext({
|
329
345
|
peersToLoadFrom: [],
|
330
346
|
crypto: Crypto,
|
331
347
|
authSecretStorage,
|
332
348
|
sessionProvider: randomSessionProvider,
|
333
|
-
AccountSchema: CustomAccount,
|
349
|
+
AccountSchema: zodSchemaToCoSchema(CustomAccount),
|
334
350
|
});
|
335
351
|
|
336
|
-
expect(context.account).toBeInstanceOf(
|
352
|
+
expect(context.account).toBeInstanceOf(
|
353
|
+
zodSchemaToCoSchema(CustomAccount),
|
354
|
+
);
|
337
355
|
});
|
338
356
|
});
|
339
357
|
});
|