jazz-tools 0.16.3 → 0.16.5
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 +30 -30
- package/CHANGELOG.md +29 -0
- package/dist/{chunk-RAMDW4VL.js → chunk-H3BIFFQG.js} +32 -10
- package/dist/chunk-H3BIFFQG.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/group.d.ts +2 -2
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +20 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/tools/coValues/group.ts +3 -3
- package/src/tools/coValues/interfaces.ts +2 -3
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +59 -2
- package/src/tools/implementation/zodSchema/unionUtils.ts +7 -2
- package/src/tools/implementation/zodSchema/zodSchema.ts +1 -1
- package/src/tools/tests/coDiscriminatedUnion.test.ts +50 -0
- package/src/tools/tests/coMap.test-d.ts +143 -0
- package/src/tools/tests/coMap.test.ts +100 -53
- package/src/tools/tests/load.test.ts +19 -0
- package/dist/chunk-RAMDW4VL.js.map +0 -1
@@ -2181,84 +2181,131 @@ describe("CoMap migration", () => {
|
|
2181
2181
|
expect(loaded?.friend?.name).toEqual("Charlie");
|
2182
2182
|
expect(loaded?.friend?.version).toEqual(2);
|
2183
2183
|
});
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2184
|
+
});
|
2185
|
+
|
2186
|
+
describe("createdAt & lastUpdatedAt", () => {
|
2187
|
+
test("empty map created time", () => {
|
2188
|
+
const emptyMap = co.map({}).create({});
|
2189
|
+
|
2190
|
+
expect(emptyMap._lastUpdatedAt).toEqual(emptyMap._createdAt);
|
2191
|
+
});
|
2189
2192
|
|
2190
|
-
|
2191
|
-
|
2193
|
+
test("created time and last updated time", async () => {
|
2194
|
+
const Person = co.map({
|
2195
|
+
name: z.string(),
|
2192
2196
|
});
|
2193
2197
|
|
2194
|
-
|
2195
|
-
const Person = co.map({
|
2196
|
-
name: z.string(),
|
2197
|
-
});
|
2198
|
+
const person = Person.create({ name: "John" });
|
2198
2199
|
|
2199
|
-
|
2200
|
-
|
2200
|
+
const createdAt = person._createdAt;
|
2201
|
+
expect(person._lastUpdatedAt).toEqual(createdAt);
|
2201
2202
|
|
2202
|
-
|
2203
|
-
|
2204
|
-
expect(createdAtInSeconds).toEqual(currentTimestampInSeconds);
|
2205
|
-
expect(person._lastUpdatedAt).toEqual(createdAt);
|
2203
|
+
await new Promise((r) => setTimeout(r, 10));
|
2204
|
+
person.name = "Jane";
|
2206
2205
|
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2206
|
+
expect(person._createdAt).toEqual(createdAt);
|
2207
|
+
expect(person._lastUpdatedAt).not.toEqual(createdAt);
|
2208
|
+
});
|
2209
|
+
});
|
2210
2210
|
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2211
|
+
describe("co.map schema", () => {
|
2212
|
+
test("can access the inner schemas of a co.map", () => {
|
2213
|
+
const Person = co.map({
|
2214
|
+
name: co.plainText(),
|
2215
2215
|
});
|
2216
2216
|
|
2217
|
-
|
2217
|
+
const person = Person.create({
|
2218
|
+
name: Person.shape["name"].create("John"),
|
2219
|
+
});
|
2220
|
+
|
2221
|
+
expect(person.name.toString()).toEqual("John");
|
2222
|
+
});
|
2223
|
+
|
2224
|
+
describe("pick()", () => {
|
2225
|
+
test("creates a new CoMap schema by picking fields of another CoMap schema", () => {
|
2218
2226
|
const Person = co.map({
|
2219
2227
|
name: z.string(),
|
2228
|
+
age: z.number(),
|
2220
2229
|
});
|
2221
2230
|
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2231
|
+
const PersonWithName = Person.pick({
|
2232
|
+
name: true,
|
2233
|
+
});
|
2234
|
+
|
2235
|
+
const person = PersonWithName.create({
|
2236
|
+
name: "John",
|
2237
|
+
});
|
2227
2238
|
|
2228
|
-
|
2229
|
-
const createdAtInSeconds = Math.floor(createdAt / 1000);
|
2230
|
-
expect(createdAtInSeconds).toEqual(currentTimestampInSeconds);
|
2239
|
+
expect(person.name).toEqual("John");
|
2231
2240
|
});
|
2232
2241
|
|
2233
|
-
test("
|
2234
|
-
const Person = co
|
2235
|
-
|
2242
|
+
test("the new schema does not include catchall properties", () => {
|
2243
|
+
const Person = co
|
2244
|
+
.map({
|
2245
|
+
name: z.string(),
|
2246
|
+
age: z.number(),
|
2247
|
+
})
|
2248
|
+
.catchall(z.string());
|
2249
|
+
|
2250
|
+
const PersonWithName = Person.pick({
|
2251
|
+
name: true,
|
2236
2252
|
});
|
2237
2253
|
|
2238
|
-
|
2239
|
-
const person = Person.create(
|
2240
|
-
{},
|
2241
|
-
{ unique: "name", owner: Account.getMe() },
|
2242
|
-
);
|
2254
|
+
expect(PersonWithName.catchAll).toBeUndefined();
|
2243
2255
|
|
2244
|
-
const
|
2245
|
-
|
2246
|
-
|
2256
|
+
const person = PersonWithName.create({
|
2257
|
+
name: "John",
|
2258
|
+
});
|
2259
|
+
// @ts-expect-error - property `extraField` does not exist in person
|
2260
|
+
expect(person.extraField).toBeUndefined();
|
2247
2261
|
});
|
2248
2262
|
});
|
2249
|
-
});
|
2250
2263
|
|
2251
|
-
describe("
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2264
|
+
describe("partial()", () => {
|
2265
|
+
test("creates a new CoMap schema by making all properties optional", () => {
|
2266
|
+
const Dog = co.map({
|
2267
|
+
name: z.string(),
|
2268
|
+
breed: z.string(),
|
2269
|
+
});
|
2270
|
+
const Person = co.map({
|
2271
|
+
name: z.string(),
|
2272
|
+
age: z.number(),
|
2273
|
+
pet: Dog,
|
2274
|
+
});
|
2256
2275
|
|
2257
|
-
|
2258
|
-
|
2276
|
+
const DraftPerson = Person.partial();
|
2277
|
+
|
2278
|
+
const draftPerson = DraftPerson.create({});
|
2279
|
+
|
2280
|
+
expect(draftPerson.name).toBeUndefined();
|
2281
|
+
expect(draftPerson.age).toBeUndefined();
|
2282
|
+
expect(draftPerson.pet).toBeUndefined();
|
2283
|
+
|
2284
|
+
draftPerson.name = "John";
|
2285
|
+
draftPerson.age = 20;
|
2286
|
+
const rex = Dog.create({ name: "Rex", breed: "Labrador" });
|
2287
|
+
draftPerson.pet = rex;
|
2288
|
+
|
2289
|
+
expect(draftPerson.name).toEqual("John");
|
2290
|
+
expect(draftPerson.age).toEqual(20);
|
2291
|
+
expect(draftPerson.pet).toEqual(rex);
|
2259
2292
|
});
|
2260
2293
|
|
2261
|
-
|
2294
|
+
test("the new schema includes catchall properties", () => {
|
2295
|
+
const Person = co
|
2296
|
+
.map({
|
2297
|
+
name: z.string(),
|
2298
|
+
age: z.number(),
|
2299
|
+
})
|
2300
|
+
.catchall(z.string());
|
2301
|
+
|
2302
|
+
const DraftPerson = Person.partial();
|
2303
|
+
|
2304
|
+
const draftPerson = DraftPerson.create({});
|
2305
|
+
draftPerson.extraField = "extra";
|
2306
|
+
|
2307
|
+
expect(draftPerson.extraField).toEqual("extra");
|
2308
|
+
});
|
2262
2309
|
});
|
2263
2310
|
});
|
2264
2311
|
|
@@ -184,6 +184,25 @@ test("returns null if the value is unavailable after retries", async () => {
|
|
184
184
|
expect(john).toBeNull();
|
185
185
|
});
|
186
186
|
|
187
|
+
test("load works even when the coValue access is granted after the creation", async () => {
|
188
|
+
const alice = await createJazzTestAccount();
|
189
|
+
const bob = await createJazzTestAccount();
|
190
|
+
|
191
|
+
const Person = co.map({
|
192
|
+
name: z.string(),
|
193
|
+
});
|
194
|
+
|
195
|
+
const group = Group.create(alice);
|
196
|
+
const map = Person.create({ name: "John" }, group);
|
197
|
+
|
198
|
+
group.addMember("everyone", "reader");
|
199
|
+
|
200
|
+
const mapOnBob = await Person.load(map.id, { loadAs: bob });
|
201
|
+
|
202
|
+
expect(mapOnBob).not.toBeNull();
|
203
|
+
expect(mapOnBob?.name).toBe("John");
|
204
|
+
});
|
205
|
+
|
187
206
|
test("load a large coValue", async () => {
|
188
207
|
const syncServer = await setupJazzTestSync({ asyncPeers: true });
|
189
208
|
|