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
@@ -1,42 +1,43 @@
|
|
1
|
-
import { cojsonInternals } from "cojson";
|
1
|
+
import { Profile, cojsonInternals } from "cojson";
|
2
2
|
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
3
3
|
import { assert, describe, expect, expectTypeOf, test, vi } from "vitest";
|
4
4
|
import {
|
5
|
-
Account,
|
6
|
-
CoFeed,
|
7
|
-
CoList,
|
8
|
-
CoMap,
|
9
5
|
Group,
|
10
6
|
ID,
|
11
|
-
Profile,
|
12
7
|
SessionID,
|
13
|
-
co,
|
14
8
|
createJazzContextFromExistingCredentials,
|
15
9
|
isControlledAccount,
|
10
|
+
z,
|
16
11
|
} from "../index.js";
|
17
|
-
import {
|
12
|
+
import {
|
13
|
+
Account,
|
14
|
+
CoListSchema,
|
15
|
+
Loaded,
|
16
|
+
co,
|
17
|
+
randomSessionProvider,
|
18
|
+
} from "../internal.js";
|
18
19
|
import { createJazzTestAccount, linkAccounts } from "../testing.js";
|
19
20
|
import { waitFor } from "./utils.js";
|
20
21
|
|
21
22
|
const Crypto = await WasmCrypto.create();
|
22
23
|
const { connectedPeers } = cojsonInternals;
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
25
|
+
const InnermostMap = co.map({
|
26
|
+
value: z.string(),
|
27
|
+
});
|
28
28
|
|
29
|
-
|
29
|
+
const TestFeed = co.feed(InnermostMap);
|
30
30
|
|
31
|
-
|
32
|
-
stream
|
33
|
-
}
|
31
|
+
const InnerMap = co.map({
|
32
|
+
stream: TestFeed,
|
33
|
+
});
|
34
34
|
|
35
|
-
|
35
|
+
const TestList = co.list(InnerMap);
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
const TestMap = co.map({
|
38
|
+
list: TestList,
|
39
|
+
optionalRef: z.optional(InnermostMap),
|
40
|
+
});
|
40
41
|
|
41
42
|
describe("Deep loading with depth arg", async () => {
|
42
43
|
const me = await Account.create({
|
@@ -71,7 +72,7 @@ describe("Deep loading with depth arg", async () => {
|
|
71
72
|
[
|
72
73
|
InnerMap.create(
|
73
74
|
{
|
74
|
-
stream:
|
75
|
+
stream: TestFeed.create(
|
75
76
|
[InnermostMap.create({ value: "hello" }, ownership)],
|
76
77
|
ownership,
|
77
78
|
),
|
@@ -87,7 +88,7 @@ describe("Deep loading with depth arg", async () => {
|
|
87
88
|
|
88
89
|
test("load without resolve", async () => {
|
89
90
|
const map1 = await TestMap.load(map.id, { loadAs: meOnSecondPeer });
|
90
|
-
expectTypeOf(map1).toEqualTypeOf<TestMap | null>();
|
91
|
+
expectTypeOf(map1).branded.toEqualTypeOf<Loaded<typeof TestMap> | null>();
|
91
92
|
|
92
93
|
assert(map1, "map1 is null");
|
93
94
|
|
@@ -99,9 +100,9 @@ describe("Deep loading with depth arg", async () => {
|
|
99
100
|
loadAs: meOnSecondPeer,
|
100
101
|
resolve: { list: true },
|
101
102
|
});
|
102
|
-
expectTypeOf(map2).toEqualTypeOf<
|
103
|
-
| (TestMap & {
|
104
|
-
list: TestList
|
103
|
+
expectTypeOf(map2).branded.toEqualTypeOf<
|
104
|
+
| (Loaded<typeof TestMap> & {
|
105
|
+
list: Loaded<typeof TestList>;
|
105
106
|
})
|
106
107
|
| null
|
107
108
|
>();
|
@@ -115,9 +116,9 @@ describe("Deep loading with depth arg", async () => {
|
|
115
116
|
loadAs: meOnSecondPeer,
|
116
117
|
resolve: { list: { $each: true } },
|
117
118
|
});
|
118
|
-
expectTypeOf(map3).toEqualTypeOf<
|
119
|
-
| (TestMap & {
|
120
|
-
list: TestList & InnerMap[];
|
119
|
+
expectTypeOf(map3).branded.toEqualTypeOf<
|
120
|
+
| (Loaded<typeof TestMap> & {
|
121
|
+
list: Loaded<typeof TestList> & Loaded<typeof InnerMap>[];
|
121
122
|
})
|
122
123
|
| null
|
123
124
|
>();
|
@@ -131,9 +132,9 @@ describe("Deep loading with depth arg", async () => {
|
|
131
132
|
loadAs: meOnSecondPeer,
|
132
133
|
resolve: { optionalRef: true } as const,
|
133
134
|
});
|
134
|
-
expectTypeOf(map3a).toEqualTypeOf<
|
135
|
-
| (TestMap & {
|
136
|
-
optionalRef: InnermostMap | undefined;
|
135
|
+
expectTypeOf(map3a).branded.toEqualTypeOf<
|
136
|
+
| (Loaded<typeof TestMap> & {
|
137
|
+
optionalRef: Loaded<typeof InnermostMap> | undefined;
|
137
138
|
})
|
138
139
|
| null
|
139
140
|
>();
|
@@ -146,15 +147,16 @@ describe("Deep loading with depth arg", async () => {
|
|
146
147
|
loadAs: meOnSecondPeer,
|
147
148
|
resolve: { list: { $each: { stream: true } } },
|
148
149
|
});
|
149
|
-
expectTypeOf(map4).toEqualTypeOf<
|
150
|
-
| (TestMap & {
|
151
|
-
list: TestList &
|
150
|
+
expectTypeOf(map4).branded.toEqualTypeOf<
|
151
|
+
| (Loaded<typeof TestMap> & {
|
152
|
+
list: Loaded<typeof TestList> &
|
153
|
+
(Loaded<typeof InnerMap> & { stream: Loaded<typeof TestFeed> })[];
|
152
154
|
})
|
153
155
|
| null
|
154
156
|
>();
|
155
157
|
assert(map4, "map4 is null");
|
156
158
|
expect(map4.list[0]?.stream).toBeTruthy();
|
157
|
-
expect(map4.list[0]?.stream?.[me.id]).toBeTruthy();
|
159
|
+
expect(map4.list[0]?.stream?.perAccount[me.id]).toBeTruthy();
|
158
160
|
expect(map4.list[0]?.stream?.byMe?.value).toBe(null);
|
159
161
|
});
|
160
162
|
|
@@ -164,73 +166,76 @@ describe("Deep loading with depth arg", async () => {
|
|
164
166
|
resolve: { list: { $each: { stream: { $each: true } } } },
|
165
167
|
});
|
166
168
|
type ExpectedMap5 =
|
167
|
-
| (TestMap & {
|
168
|
-
list: TestList &
|
169
|
-
(InnerMap & {
|
170
|
-
stream:
|
171
|
-
byMe?: { value: InnermostMap };
|
172
|
-
inCurrentSession?: { value: InnermostMap };
|
169
|
+
| (Loaded<typeof TestMap> & {
|
170
|
+
list: Loaded<typeof TestList> &
|
171
|
+
(Loaded<typeof InnerMap> & {
|
172
|
+
stream: Loaded<typeof TestFeed> & {
|
173
|
+
byMe?: { value: Loaded<typeof InnermostMap> };
|
174
|
+
inCurrentSession?: { value: Loaded<typeof InnermostMap> };
|
173
175
|
perSession: {
|
174
176
|
[sessionID: SessionID]: {
|
175
|
-
value: InnermostMap
|
177
|
+
value: Loaded<typeof InnermostMap>;
|
176
178
|
};
|
177
179
|
};
|
178
180
|
} & {
|
179
|
-
[key: ID<Account>]: { value: InnermostMap };
|
181
|
+
[key: ID<Account>]: { value: Loaded<typeof InnermostMap> };
|
180
182
|
};
|
181
183
|
})[];
|
182
184
|
})
|
183
185
|
| null;
|
184
|
-
expectTypeOf(map5).toEqualTypeOf<ExpectedMap5>();
|
186
|
+
expectTypeOf(map5).branded.toEqualTypeOf<ExpectedMap5>();
|
185
187
|
assert(map5, "map5 is null");
|
186
188
|
|
187
|
-
expect(map5.list[0]?.stream?.[me.id]?.value).toBeTruthy();
|
189
|
+
expect(map5.list[0]?.stream?.perAccount[me.id]?.value).toBeTruthy();
|
188
190
|
expect(map5.list[0]?.stream?.byMe?.value).toBeTruthy();
|
189
191
|
});
|
190
192
|
});
|
191
193
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
class CustomAccount extends Account {
|
197
|
-
profile = co.ref(CustomProfile);
|
198
|
-
root = co.ref(TestMap);
|
194
|
+
const CustomProfile = co.profile({
|
195
|
+
name: z.string(),
|
196
|
+
stream: TestFeed,
|
197
|
+
});
|
199
198
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
const CustomAccount = co
|
200
|
+
.account({
|
201
|
+
profile: CustomProfile,
|
202
|
+
root: TestMap,
|
203
|
+
})
|
204
|
+
.withMigration(async (account, creationProps) => {
|
204
205
|
if (creationProps) {
|
205
|
-
const profileGroup = Group.create(
|
206
|
-
|
206
|
+
const profileGroup = Group.create(account);
|
207
|
+
account.profile = CustomProfile.create(
|
207
208
|
{
|
208
209
|
name: creationProps.name,
|
209
|
-
stream:
|
210
|
+
stream: TestFeed.create([], account),
|
210
211
|
},
|
211
212
|
profileGroup,
|
212
213
|
);
|
213
|
-
|
214
|
+
account.root = TestMap.create(
|
215
|
+
{ list: TestList.create([], account) },
|
216
|
+
account,
|
217
|
+
);
|
214
218
|
}
|
215
219
|
|
216
|
-
const
|
220
|
+
const accountLoaded = await account.ensureLoaded({
|
217
221
|
resolve: {
|
218
222
|
profile: { stream: true },
|
219
223
|
root: { list: true },
|
220
224
|
},
|
221
225
|
});
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
226
|
+
|
227
|
+
// using assignment to check type compatibility
|
228
|
+
const _T:
|
229
|
+
| (Loaded<typeof CustomAccount> & {
|
230
|
+
profile: Loaded<typeof CustomProfile> & {
|
231
|
+
stream: Loaded<typeof TestFeed>;
|
232
|
+
};
|
233
|
+
root: Loaded<typeof TestMap> & {
|
234
|
+
list: Loaded<typeof TestList>;
|
235
|
+
};
|
236
|
+
})
|
237
|
+
| null = accountLoaded;
|
238
|
+
});
|
234
239
|
|
235
240
|
test("Deep loading within account", async () => {
|
236
241
|
const me = await CustomAccount.create({
|
@@ -244,22 +249,24 @@ test("Deep loading within account", async () => {
|
|
244
249
|
root: { list: true },
|
245
250
|
},
|
246
251
|
});
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
252
|
+
|
253
|
+
// using assignment to check type compatibility
|
254
|
+
const _T:
|
255
|
+
| (Loaded<typeof CustomAccount> & {
|
256
|
+
profile: Loaded<typeof CustomProfile> & {
|
257
|
+
stream: Loaded<typeof TestFeed>;
|
258
|
+
};
|
259
|
+
root: Loaded<typeof TestMap> & {
|
260
|
+
list: Loaded<typeof TestList>;
|
261
|
+
};
|
262
|
+
})
|
263
|
+
| null = meLoaded;
|
257
264
|
|
258
265
|
expect(meLoaded.profile.stream).toBeTruthy();
|
259
266
|
expect(meLoaded.root.list).toBeTruthy();
|
260
267
|
});
|
261
268
|
|
262
|
-
|
269
|
+
const RecordLike = co.record(z.string(), TestMap);
|
263
270
|
|
264
271
|
test("Deep loading a record-like coMap", async () => {
|
265
272
|
const me = await Account.create({
|
@@ -309,9 +316,9 @@ test("Deep loading a record-like coMap", async () => {
|
|
309
316
|
},
|
310
317
|
});
|
311
318
|
expectTypeOf(recordLoaded).toEqualTypeOf<
|
312
|
-
| (RecordLike & {
|
313
|
-
[key: string]: TestMap & {
|
314
|
-
list: TestList & InnerMap[];
|
319
|
+
| (Loaded<typeof RecordLike> & {
|
320
|
+
[key: string]: Loaded<typeof TestMap> & {
|
321
|
+
list: Loaded<typeof TestList> & Loaded<typeof InnerMap>[];
|
315
322
|
};
|
316
323
|
})
|
317
324
|
| null
|
@@ -356,18 +363,19 @@ test("The resolve type doesn't accept extra keys", async () => {
|
|
356
363
|
},
|
357
364
|
});
|
358
365
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
366
|
+
// using assignment to check type compatibility
|
367
|
+
const _T:
|
368
|
+
| (Loaded<typeof CustomAccount> & {
|
369
|
+
profile: Loaded<typeof CustomProfile> & {
|
370
|
+
stream: Loaded<typeof TestFeed>;
|
371
|
+
extraKey: never;
|
372
|
+
};
|
373
|
+
root: Loaded<typeof TestMap> & {
|
374
|
+
list: Loaded<typeof TestList>;
|
375
|
+
extraKey: never;
|
376
|
+
};
|
377
|
+
})
|
378
|
+
| null = meLoaded;
|
371
379
|
} catch (e) {
|
372
380
|
expect(e).toBeInstanceOf(Error);
|
373
381
|
}
|
@@ -438,7 +446,7 @@ describe("Deep loading with unauthorized account", async () => {
|
|
438
446
|
[
|
439
447
|
InnerMap.create(
|
440
448
|
{
|
441
|
-
stream:
|
449
|
+
stream: TestFeed.create([], group),
|
442
450
|
},
|
443
451
|
onlyBob,
|
444
452
|
),
|
@@ -524,7 +532,7 @@ describe("Deep loading with unauthorized account", async () => {
|
|
524
532
|
[
|
525
533
|
InnerMap.create(
|
526
534
|
{
|
527
|
-
stream:
|
535
|
+
stream: TestFeed.create([], onlyBob),
|
528
536
|
},
|
529
537
|
group,
|
530
538
|
),
|
@@ -560,7 +568,7 @@ describe("Deep loading with unauthorized account", async () => {
|
|
560
568
|
[
|
561
569
|
InnerMap.create(
|
562
570
|
{
|
563
|
-
stream:
|
571
|
+
stream: TestFeed.create([value], group),
|
564
572
|
},
|
565
573
|
group,
|
566
574
|
),
|
@@ -585,25 +593,25 @@ describe("Deep loading with unauthorized account", async () => {
|
|
585
593
|
errorSpy.mockReset();
|
586
594
|
});
|
587
595
|
|
588
|
-
test("setting
|
589
|
-
|
590
|
-
|
591
|
-
}
|
596
|
+
test("setting undefined via proxy", async () => {
|
597
|
+
const Lv3 = co.map({
|
598
|
+
string: z.string(),
|
599
|
+
});
|
592
600
|
|
593
|
-
|
594
|
-
lv3
|
595
|
-
}
|
601
|
+
const Lv2 = co.map({
|
602
|
+
lv3: z.optional(Lv3),
|
603
|
+
});
|
596
604
|
|
597
|
-
|
598
|
-
|
599
|
-
}
|
605
|
+
const Lv1 = co.map({
|
606
|
+
lv2: Lv2,
|
607
|
+
});
|
600
608
|
|
601
609
|
const map = Lv1.create(
|
602
610
|
{ lv2: Lv2.create({ lv3: Lv3.create({ string: "hello" }, bob) }, bob) },
|
603
611
|
bob,
|
604
612
|
);
|
605
613
|
|
606
|
-
map.lv2!.lv3 =
|
614
|
+
map.lv2!.lv3 = undefined;
|
607
615
|
|
608
616
|
const loadedMap = await Lv1.load(map.id, {
|
609
617
|
resolve: { lv2: { lv3: true } },
|
@@ -614,10 +622,10 @@ describe("Deep loading with unauthorized account", async () => {
|
|
614
622
|
});
|
615
623
|
|
616
624
|
test("unaccessible record element with $onError", async () => {
|
617
|
-
|
618
|
-
name
|
619
|
-
}
|
620
|
-
|
625
|
+
const Person = co.map({
|
626
|
+
name: z.string(),
|
627
|
+
});
|
628
|
+
const Friends = co.record(z.string(), Person);
|
621
629
|
|
622
630
|
const map = Friends.create(
|
623
631
|
{
|
@@ -639,15 +647,15 @@ describe("Deep loading with unauthorized account", async () => {
|
|
639
647
|
});
|
640
648
|
|
641
649
|
test("unaccessible nested record element with $onError", async () => {
|
642
|
-
|
643
|
-
name
|
644
|
-
}
|
645
|
-
|
650
|
+
const Person = co.map({
|
651
|
+
name: z.string(),
|
652
|
+
});
|
653
|
+
const Friends = co.record(z.string(), Person);
|
646
654
|
|
647
|
-
|
648
|
-
name
|
649
|
-
friends
|
650
|
-
}
|
655
|
+
const User = co.map({
|
656
|
+
name: z.string(),
|
657
|
+
friends: Friends,
|
658
|
+
});
|
651
659
|
|
652
660
|
const map = User.create(
|
653
661
|
{
|
@@ -675,19 +683,21 @@ describe("Deep loading with unauthorized account", async () => {
|
|
675
683
|
});
|
676
684
|
|
677
685
|
test("unaccessible element down the chain with $onError on a record", async () => {
|
678
|
-
|
679
|
-
name
|
680
|
-
|
681
|
-
}
|
682
|
-
class Dog extends CoMap {
|
683
|
-
name = co.string;
|
684
|
-
}
|
685
|
-
class Friends extends CoMap.Record(co.ref(Person)) {}
|
686
|
+
const Dog = co.map({
|
687
|
+
name: z.string(),
|
688
|
+
});
|
686
689
|
|
687
|
-
|
688
|
-
name
|
689
|
-
|
690
|
-
}
|
690
|
+
const Person = co.map({
|
691
|
+
name: z.string(),
|
692
|
+
dog: Dog,
|
693
|
+
});
|
694
|
+
|
695
|
+
const Friends = co.record(z.string(), Person);
|
696
|
+
|
697
|
+
const User = co.map({
|
698
|
+
name: z.string(),
|
699
|
+
friends: Friends,
|
700
|
+
});
|
691
701
|
|
692
702
|
const map = User.create(
|
693
703
|
{
|
@@ -724,11 +734,13 @@ describe("Deep loading with unauthorized account", async () => {
|
|
724
734
|
});
|
725
735
|
|
726
736
|
test("unaccessible list element with $onError and $each with depth", async () => {
|
727
|
-
|
728
|
-
name
|
729
|
-
friends
|
730
|
-
|
731
|
-
|
737
|
+
const Person = co.map({
|
738
|
+
name: z.string(),
|
739
|
+
get friends(): z.ZodOptional<typeof Friends> {
|
740
|
+
return z.optional(Friends);
|
741
|
+
},
|
742
|
+
});
|
743
|
+
const Friends: CoListSchema<typeof Person> = co.list(Person); // TODO: annoying that we have to annotate
|
732
744
|
|
733
745
|
const list = Friends.create(
|
734
746
|
[
|
@@ -774,10 +786,10 @@ describe("Deep loading with unauthorized account", async () => {
|
|
774
786
|
});
|
775
787
|
|
776
788
|
test("unaccessible record element with $onError", async () => {
|
777
|
-
|
778
|
-
name
|
779
|
-
}
|
780
|
-
|
789
|
+
const Person = co.map({
|
790
|
+
name: z.string(),
|
791
|
+
});
|
792
|
+
const Friend = co.record(z.string(), Person);
|
781
793
|
|
782
794
|
const map = Friend.create(
|
783
795
|
{
|
@@ -799,19 +811,21 @@ describe("Deep loading with unauthorized account", async () => {
|
|
799
811
|
});
|
800
812
|
|
801
813
|
test("unaccessible ref catched with $onError", async () => {
|
802
|
-
|
803
|
-
name
|
804
|
-
|
805
|
-
}
|
806
|
-
class Dog extends CoMap {
|
807
|
-
name = co.string;
|
808
|
-
}
|
809
|
-
class Friends extends CoMap.Record(co.ref(Person)) {}
|
814
|
+
const Dog = co.map({
|
815
|
+
name: z.string(),
|
816
|
+
});
|
810
817
|
|
811
|
-
|
812
|
-
name
|
813
|
-
|
814
|
-
}
|
818
|
+
const Person = co.map({
|
819
|
+
name: z.string(),
|
820
|
+
dog: Dog,
|
821
|
+
});
|
822
|
+
|
823
|
+
const Friends = co.record(z.string(), Person);
|
824
|
+
|
825
|
+
const User = co.map({
|
826
|
+
name: z.string(),
|
827
|
+
friends: Friends,
|
828
|
+
});
|
815
829
|
|
816
830
|
const map = User.create(
|
817
831
|
{
|
@@ -848,9 +862,9 @@ describe("Deep loading with unauthorized account", async () => {
|
|
848
862
|
});
|
849
863
|
|
850
864
|
test("using $onError on the resolve root", async () => {
|
851
|
-
|
852
|
-
name
|
853
|
-
}
|
865
|
+
const Person = co.map({
|
866
|
+
name: z.string(),
|
867
|
+
});
|
854
868
|
|
855
869
|
const map = Person.create({ name: "John" }, onlyBob);
|
856
870
|
const user = await Person.load(map.id, {
|
@@ -863,15 +877,16 @@ describe("Deep loading with unauthorized account", async () => {
|
|
863
877
|
});
|
864
878
|
|
865
879
|
test("doesn't break on Map.Record key deletion when the key is referenced in the depth", async () => {
|
866
|
-
|
867
|
-
|
868
|
-
|
880
|
+
const JazzProfile = co.map({
|
881
|
+
name: z.string(),
|
882
|
+
firstName: z.string(),
|
883
|
+
});
|
869
884
|
|
870
|
-
|
885
|
+
const JazzySnapStore = co.record(z.string(), JazzProfile);
|
871
886
|
|
872
887
|
const snapStore = JazzySnapStore.create({
|
873
|
-
profile1: JazzProfile.create({ firstName: "John" }),
|
874
|
-
profile2: JazzProfile.create({ firstName: "John" }),
|
888
|
+
profile1: JazzProfile.create({ name: "John", firstName: "John" }),
|
889
|
+
profile2: JazzProfile.create({ name: "John", firstName: "John" }),
|
875
890
|
});
|
876
891
|
|
877
892
|
const spy = vi.fn();
|
@@ -899,13 +914,14 @@ test("doesn't break on Map.Record key deletion when the key is referenced in the
|
|
899
914
|
});
|
900
915
|
|
901
916
|
test("throw when calling ensureLoaded on a ref that's required but missing", async () => {
|
902
|
-
|
903
|
-
|
904
|
-
|
917
|
+
const JazzProfile = co.map({
|
918
|
+
name: z.string(),
|
919
|
+
firstName: z.string(),
|
920
|
+
});
|
905
921
|
|
906
|
-
|
907
|
-
profile
|
908
|
-
}
|
922
|
+
const JazzRoot = co.map({
|
923
|
+
profile: JazzProfile,
|
924
|
+
});
|
909
925
|
|
910
926
|
const me = await Account.create({
|
911
927
|
creationProps: { name: "Tester McTesterson" },
|
@@ -926,7 +942,7 @@ test("throw when calling ensureLoaded on a ref that's required but missing", asy
|
|
926
942
|
});
|
927
943
|
|
928
944
|
test("throw when calling ensureLoaded on a ref that is not defined in the schema", async () => {
|
929
|
-
|
945
|
+
const JazzRoot = co.map({});
|
930
946
|
|
931
947
|
const me = await Account.create({
|
932
948
|
creationProps: { name: "Tester McTesterson" },
|
@@ -944,11 +960,12 @@ test("throw when calling ensureLoaded on a ref that is not defined in the schema
|
|
944
960
|
});
|
945
961
|
|
946
962
|
test("should not throw when calling ensureLoaded a record with a deleted ref", async () => {
|
947
|
-
|
948
|
-
|
949
|
-
|
963
|
+
const JazzProfile = co.map({
|
964
|
+
name: z.string(),
|
965
|
+
firstName: z.string(),
|
966
|
+
});
|
950
967
|
|
951
|
-
|
968
|
+
const JazzySnapStore = co.record(z.string(), JazzProfile);
|
952
969
|
|
953
970
|
const me = await Account.create({
|
954
971
|
creationProps: { name: "Tester McTesterson" },
|
@@ -957,7 +974,7 @@ test("should not throw when calling ensureLoaded a record with a deleted ref", a
|
|
957
974
|
|
958
975
|
const root = JazzySnapStore.create(
|
959
976
|
{
|
960
|
-
profile: JazzProfile.create({ firstName: "John" }, me),
|
977
|
+
profile: JazzProfile.create({ name: "John", firstName: "John" }, me),
|
961
978
|
},
|
962
979
|
me,
|
963
980
|
);
|