jazz-tools 0.14.9 → 0.14.14

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 (48) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +14 -0
  3. package/dist/{chunk-ORL6R2EV.js → chunk-GRIN3FQP.js} +43 -3
  4. package/dist/chunk-GRIN3FQP.js.map +1 -0
  5. package/dist/coValues/extensions/imageDef.d.ts +2 -2
  6. package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
  7. package/dist/exports.d.ts +1 -1
  8. package/dist/exports.d.ts.map +1 -1
  9. package/dist/implementation/ContextManager.d.ts +5 -2
  10. package/dist/implementation/ContextManager.d.ts.map +1 -1
  11. package/dist/implementation/createContext.d.ts +1 -1
  12. package/dist/implementation/createContext.d.ts.map +1 -1
  13. package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +1 -1
  14. package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -1
  15. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +1 -0
  16. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  17. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +1 -0
  18. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  19. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +1 -0
  20. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  21. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +1 -1
  22. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
  23. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +1 -1
  24. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
  25. package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -1
  26. package/dist/implementation/zodSchema/zodReExport.d.ts +1 -1
  27. package/dist/implementation/zodSchema/zodReExport.d.ts.map +1 -1
  28. package/dist/index.js +3 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/subscribe/SubscriptionScope.d.ts +1 -0
  31. package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
  32. package/dist/testing.js +1 -1
  33. package/package.json +1 -1
  34. package/src/coValues/extensions/imageDef.ts +2 -7
  35. package/src/exports.ts +1 -0
  36. package/src/implementation/ContextManager.ts +34 -2
  37. package/src/implementation/createContext.ts +2 -2
  38. package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +21 -1
  39. package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +1 -0
  40. package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +1 -0
  41. package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +1 -0
  42. package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +9 -1
  43. package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +9 -1
  44. package/src/implementation/zodSchema/zodCo.ts +3 -0
  45. package/src/implementation/zodSchema/zodReExport.ts +2 -0
  46. package/src/subscribe/SubscriptionScope.ts +6 -0
  47. package/src/tests/zod.test.ts +35 -17
  48. package/dist/chunk-ORL6R2EV.js.map +0 -1
@@ -5,7 +5,13 @@ import {
5
5
  isUnionOfPrimitivesDeeply,
6
6
  schemaUnionDiscriminatorFor,
7
7
  } from "../unionUtils.js";
8
- import { ZodLazy, ZodReadonly, z } from "../zodReExport.js";
8
+ import {
9
+ ZodCatch,
10
+ ZodDefault,
11
+ ZodLazy,
12
+ ZodReadonly,
13
+ z,
14
+ } from "../zodReExport.js";
9
15
  import { ZodPrimitiveSchema } from "../zodSchema.js";
10
16
  import { zodSchemaToCoSchemaOrKeepPrimitive } from "./zodSchemaToCoSchema.js";
11
17
 
@@ -23,6 +29,8 @@ type FieldSchema =
23
29
  | z.core.$ZodLiteral<any>
24
30
  | z.core.$ZodCatch<z.core.$ZodType>
25
31
  | z.core.$ZodEnum<any>
32
+ | z.core.$ZodDefault<z.core.$ZodType>
33
+ | z.core.$ZodCatch<z.core.$ZodType>
26
34
  | (z.core.$ZodCustom<any, any> & { builtin: any });
27
35
 
28
36
  export function zodFieldToCoFieldDef(schema: FieldSchema) {
@@ -62,6 +70,18 @@ export function zodFieldToCoFieldDef(schema: FieldSchema) {
62
70
  return zodFieldToCoFieldDef(
63
71
  (schema as unknown as ZodLazy).unwrap() as FieldSchema,
64
72
  );
73
+ } else if (
74
+ schema._zod.def.type === "default" ||
75
+ schema._zod.def.type === "catch"
76
+ ) {
77
+ console.warn(
78
+ "z.default()/z.catch() are not supported in collaborative schemas. They will be ignored.",
79
+ );
80
+
81
+ return zodFieldToCoFieldDef(
82
+ (schema as unknown as ZodDefault | ZodCatch).def
83
+ .innerType as FieldSchema,
84
+ );
65
85
  } else if (schema._zod.def.type === "literal") {
66
86
  if (
67
87
  schema._zod.def.values.some(
@@ -46,6 +46,7 @@ export type CoListSchema<T extends z.core.$ZodType> = z.core.$ZodArray<T> & {
46
46
  ) => void,
47
47
  ): () => void;
48
48
 
49
+ /** @deprecated Define your helper methods separately, in standalone functions. */
49
50
  withHelpers<S extends z.core.$ZodType, T extends object>(
50
51
  this: S,
51
52
  helpers: (Self: S) => T,
@@ -92,6 +92,7 @@ export type CoMapSchema<
92
92
  schema: T,
93
93
  ): CoMapSchema<Shape, z.core.$catchall<T>>;
94
94
 
95
+ /** @deprecated Define your helper methods separately, in standalone functions. */
95
96
  withHelpers<S extends z.core.$ZodType, T extends object>(
96
97
  this: S,
97
98
  helpers: (Self: S) => T,
@@ -78,6 +78,7 @@ export type CoRecordSchema<
78
78
  as?: Account | Group | AnonymousJazzAgent,
79
79
  ): ID<CoRecordInstanceCoValuesNullable<K, V>>;
80
80
 
81
+ /** @deprecated Define your helper methods separately, in standalone functions. */
81
82
  withHelpers<S extends z.core.$ZodType, T extends object>(
82
83
  this: S,
83
84
  helpers: (Self: S) => T,
@@ -99,7 +99,15 @@ export type InstanceOrPrimitiveOfSchema<
99
99
  infer Inner
100
100
  >
101
101
  ? InstanceOrPrimitiveOfSchema<Inner>
102
- : never
102
+ : S extends z.core.$ZodDefault<
103
+ infer Default
104
+ >
105
+ ? InstanceOrPrimitiveOfSchema<Default>
106
+ : S extends z.core.$ZodCatch<
107
+ infer Catch
108
+ >
109
+ ? InstanceOrPrimitiveOfSchema<Catch>
110
+ : never
103
111
  : S extends CoValueClass
104
112
  ? InstanceType<S>
105
113
  : never;
@@ -112,7 +112,15 @@ export type InstanceOrPrimitiveOfSchemaCoValuesNullable<
112
112
  infer Inner
113
113
  >
114
114
  ? InstanceOrPrimitiveOfSchema<Inner>
115
- : never
115
+ : S extends z.core.$ZodDefault<
116
+ infer Default
117
+ >
118
+ ? InstanceOrPrimitiveOfSchema<Default>
119
+ : S extends z.core.$ZodCatch<
120
+ infer Catch
121
+ >
122
+ ? InstanceOrPrimitiveOfSchema<Catch>
123
+ : never
116
124
  : S extends CoValueClass
117
125
  ? InstanceType<S> | null
118
126
  : never;
@@ -45,6 +45,7 @@ export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
45
45
  subscribe: CoMapSchema<Shape>["subscribe"];
46
46
  findUnique: CoMapSchema<Shape>["findUnique"];
47
47
  catchall: CoMapSchema<Shape>["catchall"];
48
+ /** @deprecated Define your helper methods separately, in standalone functions. */
48
49
  withHelpers: CoMapSchema<Shape>["withHelpers"];
49
50
  };
50
51
 
@@ -130,6 +131,7 @@ export const coAccountDefiner = <
130
131
  getMe: AccountSchema<Shape>["getMe"];
131
132
  load: AccountSchema<Shape>["load"];
132
133
  subscribe: AccountSchema<Shape>["subscribe"];
134
+ /** @deprecated Define your helper methods separately, in standalone functions. */
133
135
  withHelpers: AccountSchema<Shape>["withHelpers"];
134
136
  withMigration: AccountSchema<Shape>["withMigration"];
135
137
  };
@@ -210,6 +212,7 @@ export const coListDefiner = <T extends z.core.$ZodType>(
210
212
  create: CoListSchema<T>["create"];
211
213
  load: CoListSchema<T>["load"];
212
214
  subscribe: CoListSchema<T>["subscribe"];
215
+ /** @deprecated Define your helper methods separately, in standalone functions. */
213
216
  withHelpers: CoListSchema<T>["withHelpers"];
214
217
  };
215
218
 
@@ -36,6 +36,8 @@ export {
36
36
  type ZodOptional,
37
37
  type ZodReadonly,
38
38
  type ZodLazy,
39
+ type ZodDefault,
40
+ type ZodCatch,
39
41
  type output as infer,
40
42
  z,
41
43
  } from "zod/v4";
@@ -222,6 +222,12 @@ export class SubscriptionScope<D extends CoValue> {
222
222
  return true;
223
223
  }
224
224
 
225
+ getCurrentValue() {
226
+ if (!this.shouldSendUpdates()) return;
227
+ if (this.errorFromChildren) return this.errorFromChildren;
228
+ return this.value;
229
+ }
230
+
225
231
  triggerUpdate() {
226
232
  if (!this.shouldSendUpdates()) return;
227
233
  if (!this.dirty) return;
@@ -1,4 +1,4 @@
1
- import { describe, expect, it } from "vitest";
1
+ import { describe, expect, it, vi } from "vitest";
2
2
  import { z } from "../exports.js";
3
3
  import { co } from "../internal.js";
4
4
  import { createJazzTestAccount } from "../testing.js";
@@ -380,23 +380,41 @@ describe("co.map and Zod schema compatibility", () => {
380
380
  expect(map.longString).toBe("this is a long string");
381
381
  });
382
382
 
383
- // it("should fire error on default values", async () => {
384
- // const schema = co.map({
385
- // fish: z.string().default("tuna"),
386
- // });
387
- // const account = await createJazzTestAccount();
388
- // const map = schema.create({}, account);
389
- // expect(map.fish).toBe("tuna");
390
- // });
383
+ it("should log a warning on default values", async () => {
384
+ const consoleSpy = vi.spyOn(console, "warn");
391
385
 
392
- // it("should fire error catch values", async () => {
393
- // const schema = co.map({
394
- // number: z.number().catch(42),
395
- // });
396
- // const account = await createJazzTestAccount();
397
- // const map = schema.create({ number: 42 }, account);
398
- // expect(map.number).toBe(42);
399
- // });
386
+ const schema = co.map({
387
+ fish: z.string().default("tuna"),
388
+ });
389
+ const account = await createJazzTestAccount();
390
+ const map = schema.create(
391
+ {
392
+ fish: "salmon",
393
+ },
394
+ account,
395
+ );
396
+ expect(map.fish).toBe("salmon");
397
+
398
+ expect(consoleSpy).toHaveBeenCalledWith(
399
+ "z.default()/z.catch() are not supported in collaborative schemas. They will be ignored.",
400
+ );
401
+ consoleSpy.mockRestore();
402
+ });
403
+
404
+ it("should log a warning on catch values", async () => {
405
+ const consoleSpy = vi.spyOn(console, "warn");
406
+ const schema = co.map({
407
+ number: z.number().catch(42),
408
+ });
409
+ const account = await createJazzTestAccount();
410
+ const map = schema.create({ number: 18 }, account);
411
+ expect(map.number).toBe(18);
412
+
413
+ expect(consoleSpy).toHaveBeenCalledWith(
414
+ "z.default()/z.catch() are not supported in collaborative schemas. They will be ignored.",
415
+ );
416
+ consoleSpy.mockRestore();
417
+ });
400
418
 
401
419
  it("should handle branded types", async () => {
402
420
  const schema = co.map({