jazz-tools 0.10.1 → 0.10.3

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
@@ -35,7 +35,7 @@ import {
35
35
  parseInviteLink,
36
36
  randomSessionProvider,
37
37
  subscribeToCoValue
38
- } from "./chunk-24EJ3CKA.js";
38
+ } from "./chunk-XRX3CCYY.js";
39
39
 
40
40
  // src/index.ts
41
41
  import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals } from "cojson";
package/dist/testing.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createAnonymousJazzContext,
6
6
  createJazzContext,
7
7
  randomSessionProvider
8
- } from "./chunk-24EJ3CKA.js";
8
+ } from "./chunk-XRX3CCYY.js";
9
9
 
10
10
  // src/testing.ts
11
11
  import { LocalNode } from "cojson";
package/package.json CHANGED
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "type": "module",
19
19
  "license": "MIT",
20
- "version": "0.10.1",
20
+ "version": "0.10.3",
21
21
  "dependencies": {
22
22
  "@scure/bip39": "^1.3.0",
23
- "cojson": "0.10.1"
23
+ "cojson": "0.10.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "8.3.5",
@@ -17,6 +17,11 @@ export const Encoders = {
17
17
  encode: (value: Date) => value.toISOString(),
18
18
  decode: (value: JsonValue) => new Date(value as string),
19
19
  },
20
+ OptionalDate: {
21
+ encode: (value: Date | undefined) => value?.toISOString() || null,
22
+ decode: (value: JsonValue) =>
23
+ value === null ? undefined : new Date(value as string),
24
+ },
20
25
  };
21
26
 
22
27
  export type CoMarker = { readonly __co: unique symbol };
@@ -54,7 +59,7 @@ const optional = {
54
59
  [SchemaInit]: "json" satisfies Schema,
55
60
  } as unknown as co<null | undefined>,
56
61
  Date: {
57
- [SchemaInit]: { encoded: Encoders.Date } satisfies Schema,
62
+ [SchemaInit]: { encoded: Encoders.OptionalDate } satisfies Schema,
58
63
  } as unknown as co<Date | undefined>,
59
64
  literal<T extends (string | number | boolean)[]>(
60
65
  ..._lit: T
@@ -25,7 +25,7 @@ class TestMap extends CoMap {
25
25
  encode: (value: string | undefined) => value || null,
26
26
  decode: (value: unknown) => (value as string) || undefined,
27
27
  });
28
- optionalDate = co.optional.encoded(Encoders.Date);
28
+ optionalDate = co.optional.Date;
29
29
 
30
30
  get roughColor() {
31
31
  return this.color + "ish";
@@ -106,6 +106,32 @@ describe("Simple CoMap operations", async () => {
106
106
  expect(emptyMap.color).toEqual(undefined);
107
107
  });
108
108
 
109
+ test("setting date as undefined should throw", () => {
110
+ expect(() =>
111
+ TestMap.create(
112
+ {
113
+ color: "red",
114
+ _height: 10,
115
+ birthday: undefined!,
116
+ },
117
+ { owner: me },
118
+ ),
119
+ ).toThrow();
120
+ });
121
+
122
+ test("setting optional date as undefined should not throw", () => {
123
+ const map = TestMap.create(
124
+ {
125
+ color: "red",
126
+ _height: 10,
127
+ birthday,
128
+ optionalDate: undefined,
129
+ },
130
+ { owner: me },
131
+ );
132
+ expect(map.optionalDate).toBeUndefined();
133
+ });
134
+
109
135
  describe("Mutation", () => {
110
136
  test("assignment & deletion", () => {
111
137
  map.color = "blue";