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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-24EJ3CKA.js → chunk-XRX3CCYY.js} +6 -2
- package/dist/chunk-XRX3CCYY.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +2 -2
- package/src/implementation/schema.ts +6 -1
- package/src/tests/coMap.test.ts +27 -1
- package/dist/chunk-24EJ3CKA.js.map +0 -1
package/dist/index.js
CHANGED
package/dist/testing.js
CHANGED
package/package.json
CHANGED
@@ -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.
|
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
|
package/src/tests/coMap.test.ts
CHANGED
@@ -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.
|
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";
|