jazz-tools 0.17.13 → 0.17.15

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/dist/index.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  randomSessionProvider,
38
38
  subscribeToCoValue,
39
39
  zodReExport_exports
40
- } from "./chunk-SFP5PBPX.js";
40
+ } from "./chunk-LZOF6WP5.js";
41
41
 
42
42
  // src/tools/auth/clerk/index.ts
43
43
  import {
package/dist/testing.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  createAnonymousJazzContext,
7
7
  createJazzContext,
8
8
  randomSessionProvider
9
- } from "./chunk-SFP5PBPX.js";
9
+ } from "./chunk-LZOF6WP5.js";
10
10
 
11
11
  // src/tools/testing.ts
12
12
  import { LocalNode } from "cojson";
@@ -1 +1 @@
1
- {"version":3,"file":"zodCo.d.ts","sourceRoot":"","sources":["../../../../src/tools/implementation/zodSchema/zodCo.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,eAAe,EACf,KAAK,eAAe,EAUrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAE5B,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EACL,cAAc,EAEf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC,eAAO,MAAM,YAAY,GAAI,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,cAAc,SACvD,KAAK,KACX,WAAW,CAAC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WAClD,CAAC,KACT,YAAY,CAAC,CAAC,CAGhB,CAAC;AAcF,eAAO,MAAM,gBAAgB,GAC3B,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,cAAc;UAtCf,EAAG,IACzB,CAAE,UAAS;WAAkB,EAAG,IAAI,CAAC,YAAY,CAAC,EAChD,IAAC,CAAC,UAAU;iBAAiB,EAAG,IAAI,CAAC,YAGvC,CAAC,EAAE,IAAI,CAAC,UAAU;WAmCT,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,KAC1C,eAAe,CAAC,KAAK,CAQvB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,qBAAqB,WAClD,CAAC,KACT,YAAY,CAAC,CAAC,CAGhB,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAO,gBAGtC,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,eAGrC,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAO,cAGpC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,OAAO,eAAe,CAAC;AAC3D,eAAO,MAAM,cAAc,QAAO,qBAEjC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,iBAAiB,UACnD,CAAC,KACR,gBAAgB,CAAC,CAAC,CAEpB,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,OAAO,SAAS,2BAA2B,iBAE5B,MAAM,WACZ,OAAO,KACf,0BAA0B,CAAC,OAAO,CAMpC,CAAC"}
package/package.json CHANGED
@@ -140,7 +140,7 @@
140
140
  },
141
141
  "type": "module",
142
142
  "license": "MIT",
143
- "version": "0.17.13",
143
+ "version": "0.17.15",
144
144
  "dependencies": {
145
145
  "@manuscripts/prosemirror-recreate-steps": "^0.1.4",
146
146
  "@scure/base": "1.2.1",
@@ -156,9 +156,9 @@
156
156
  "prosemirror-state": "^1.4.3",
157
157
  "prosemirror-transform": "^1.9.0",
158
158
  "zod": "3.25.76",
159
- "cojson": "0.17.13",
160
- "cojson-storage-indexeddb": "0.17.13",
161
- "cojson-transport-ws": "0.17.13"
159
+ "cojson": "0.17.15",
160
+ "cojson-storage-indexeddb": "0.17.15",
161
+ "cojson-transport-ws": "0.17.15"
162
162
  },
163
163
  "devDependencies": {
164
164
  "@scure/bip39": "^1.3.0",
@@ -20,7 +20,9 @@ import {
20
20
  createCoreFileStreamSchema,
21
21
  hydrateCoreCoValueSchema,
22
22
  isAnyCoValueSchema,
23
+ isCoValueClass,
23
24
  } from "../../internal.js";
25
+ import { removeGetters } from "../schemaUtils.js";
24
26
  import {
25
27
  CoDiscriminatedUnionSchema,
26
28
  DiscriminableCoValueSchemas,
@@ -34,14 +36,41 @@ import {
34
36
  } from "./schemaTypes/RichTextSchema.js";
35
37
  import { z } from "./zodReExport.js";
36
38
 
37
- export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
38
- shape: Shape,
39
- ): CoMapSchema<Shape> => {
39
+ /**
40
+ * Checking for the presence of the `_zod` property is the recommended way
41
+ * to determine if a schema is a Zod v4 schema.
42
+ *
43
+ * @see https://zod.dev/library-authors?id=how-to-support-zod-3-and-zod-4-simultaneously
44
+ */
45
+ const isZodV4Schema = (schema: unknown): schema is z.core.$ZodType => {
46
+ return typeof schema === "object" && schema !== null && "_zod" in schema;
47
+ };
48
+
49
+ const isValidShape = (shape: z.core.$ZodLooseShape) => {
50
+ return Object.values(removeGetters(shape)).every(
51
+ (schema) =>
52
+ isZodV4Schema(schema) ||
53
+ isAnyCoValueSchema(schema) ||
54
+ isCoValueClass(schema),
55
+ );
56
+ };
57
+
58
+ const validateCoMapShape = (shape: z.core.$ZodLooseShape) => {
40
59
  if (isAnyCoValueSchema(shape as any)) {
41
60
  throw new Error(
42
61
  "co.map() expects an object as its argument, not a CoValue schema",
43
62
  );
63
+ } else if (!isValidShape(shape)) {
64
+ throw new Error(
65
+ "co.map() supports only Zod v4 schemas and CoValue schemas",
66
+ );
44
67
  }
68
+ };
69
+
70
+ export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
71
+ shape: Shape,
72
+ ): CoMapSchema<Shape> => {
73
+ validateCoMapShape(shape);
45
74
  const coreSchema = createCoreCoMapSchema(shape);
46
75
  return hydrateCoreCoValueSchema(coreSchema);
47
76
  };
@@ -117,16 +146,24 @@ export const coListDefiner = <T extends AnyZodOrCoValueSchema>(
117
146
  return hydrateCoreCoValueSchema(coreSchema);
118
147
  };
119
148
 
120
- export const coProfileDefiner = <
121
- Shape extends z.core.$ZodLooseShape = Simplify<DefaultProfileShape>,
122
- >(
123
- shape: Shape & Partial<DefaultProfileShape> = {} as any,
124
- ): CoProfileSchema<Shape> => {
149
+ const validateProfileShape = (shape: z.core.$ZodLooseShape) => {
125
150
  if (isAnyCoValueSchema(shape as any)) {
126
151
  throw new Error(
127
152
  "co.profile() expects an object as its argument, not a CoValue schema",
128
153
  );
154
+ } else if (!isValidShape(shape)) {
155
+ throw new Error(
156
+ "co.profile() supports only Zod v4 schemas and CoValue schemas",
157
+ );
129
158
  }
159
+ };
160
+
161
+ export const coProfileDefiner = <
162
+ Shape extends z.core.$ZodLooseShape = Simplify<DefaultProfileShape>,
163
+ >(
164
+ shape: Shape & Partial<DefaultProfileShape> = {} as any,
165
+ ): CoProfileSchema<Shape> => {
166
+ validateProfileShape(shape);
130
167
  const ehnancedShape = Object.assign(shape, {
131
168
  name: z.string(),
132
169
  inbox: z.optional(z.string()),
@@ -1,4 +1,4 @@
1
- import { assert, beforeEach, expect, test } from "vitest";
1
+ import { assert, beforeEach, describe, expect, test } from "vitest";
2
2
  import { Account, Group, co, z } from "../exports.js";
3
3
  import {
4
4
  createJazzTestAccount,
@@ -137,10 +137,20 @@ test("loading raw accounts should work", async () => {
137
137
  expect(loadedAccount.profile!.name).toBe("test 1");
138
138
  });
139
139
 
140
- test("co.profile() should throw an error if passed a CoValue schema", async () => {
141
- expect(() => co.profile(co.map({}))).toThrow(
142
- "co.profile() expects an object as its argument, not a CoValue schema",
143
- );
140
+ describe("co.profile() schema", () => {
141
+ test("co.profile() should throw an error if passed a CoValue schema", async () => {
142
+ expect(() => co.profile(co.map({}))).toThrow(
143
+ "co.profile() expects an object as its argument, not a CoValue schema",
144
+ );
145
+ });
146
+
147
+ test("co.profile() should throw an error if its shape does not contain valid schemas", () => {
148
+ expect(() =>
149
+ co.profile({
150
+ field: "a string is not a valid schema",
151
+ }),
152
+ ).toThrow("co.profile() supports only Zod v4 schemas and CoValue schemas");
153
+ });
144
154
  });
145
155
 
146
156
  test("should support recursive props on co.profile", async () => {
@@ -2375,6 +2375,14 @@ describe("co.map schema", () => {
2375
2375
  "co.map() expects an object as its argument, not a CoValue schema",
2376
2376
  );
2377
2377
  });
2378
+
2379
+ test("co.map() should throw an error if its shape does not contain valid schemas", () => {
2380
+ expect(() =>
2381
+ co.map({
2382
+ field: "a string is not a valid schema",
2383
+ }),
2384
+ ).toThrow("co.map() supports only Zod v4 schemas and CoValue schemas");
2385
+ });
2378
2386
  });
2379
2387
 
2380
2388
  describe("Updating a nested reference", () => {