jazz-tools 0.7.0-alpha.3 → 0.7.0-alpha.6
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/dist/coValues/account.js +3 -3
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +2 -2
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +11 -11
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +3 -3
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +2 -2
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +3 -3
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +3 -3
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/encoding.js +5 -0
- package/dist/implementation/encoding.js.map +1 -0
- package/dist/implementation/refs.js +4 -4
- package/dist/implementation/refs.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/tests/coMap.test.js +2 -2
- package/dist/tests/coMap.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +11 -11
- package/src/coValues/coList.ts +22 -15
- package/src/coValues/coMap.ts +30 -40
- package/src/coValues/coStream.ts +12 -12
- package/src/coValues/extensions/imageDef.ts +2 -3
- package/src/coValues/group.ts +13 -13
- package/src/coValues/interfaces.ts +3 -3
- package/src/implementation/{schema.ts → encoding.ts} +14 -17
- package/src/implementation/refs.ts +9 -10
- package/src/index.ts +2 -2
- package/src/internal.ts +1 -1
- package/src/tests/coMap.test.ts +3 -3
- package/dist/implementation/schema.js +0 -6
- package/dist/implementation/schema.js.map +0 -1
@@ -2,22 +2,22 @@ import type { JsonValue } from "cojson";
|
|
2
2
|
import type { CoValue, CoValueClass } from "../internal.js";
|
3
3
|
import type { Schema, TypeId } from "@effect/schema/Schema";
|
4
4
|
|
5
|
-
export type
|
6
|
-
export type
|
7
|
-
export type
|
5
|
+
export type JsonEncoded = "json";
|
6
|
+
export type EncodedAs<V> = { encoded: Encoder<V> };
|
7
|
+
export type RefEncoded<V extends CoValue> = {
|
8
8
|
ref: () => CoValueClass<V>;
|
9
9
|
};
|
10
10
|
|
11
|
-
export type
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export type Encoding =
|
12
|
+
| JsonEncoded
|
13
|
+
| RefEncoded<CoValue>
|
14
|
+
| EncodedAs<any>;
|
15
15
|
|
16
|
-
export type
|
17
|
-
?
|
16
|
+
export type EncodingFor<Field> = NonNullable<Field> extends CoValue
|
17
|
+
? RefEncoded<NonNullable<Field>>
|
18
18
|
: NonNullable<Field> extends JsonValue
|
19
|
-
?
|
20
|
-
:
|
19
|
+
? JsonEncoded
|
20
|
+
: EncodedAs<NonNullable<Field>>;
|
21
21
|
|
22
22
|
export type EffectSchemaWithInputAndOutput<A, I = A> = Schema<
|
23
23
|
any,
|
@@ -38,12 +38,9 @@ export const Encoders = {
|
|
38
38
|
Date,
|
39
39
|
};
|
40
40
|
|
41
|
-
export const indexSignature = Symbol.for("indexSignature");
|
42
|
-
export type indexSignature = typeof indexSignature;
|
43
|
-
|
44
41
|
export type EnsureCoValueNullable<
|
45
42
|
V,
|
46
|
-
Key extends string
|
43
|
+
Key extends string,
|
47
44
|
> = NonNullable<V> extends CoValue
|
48
45
|
? null extends V
|
49
46
|
? V
|
@@ -53,12 +50,12 @@ export type EnsureCoValueNullable<
|
|
53
50
|
V | null,
|
54
51
|
]
|
55
52
|
: [
|
56
|
-
`👋 CoMap fields that are CoValue references should be nullable, declare
|
53
|
+
`👋 CoMap fields that are CoValue references should be nullable, declare _item as:`,
|
57
54
|
V | null,
|
58
55
|
]
|
59
56
|
: V;
|
60
57
|
|
61
|
-
export type
|
58
|
+
export type ValidItem<Item, ContainerType extends string> =
|
62
59
|
NonNullable<Item> extends CoValue
|
63
60
|
? null extends Item
|
64
61
|
? any
|
@@ -7,11 +7,10 @@ import type {
|
|
7
7
|
Me,
|
8
8
|
SubclassedConstructor,
|
9
9
|
UnavailableError,
|
10
|
-
indexSignature,
|
11
10
|
} from "../internal.js";
|
12
11
|
import { subscriptionsScopes } from "../internal.js";
|
13
12
|
|
14
|
-
export class
|
13
|
+
export class Ref<V extends CoValue> {
|
15
14
|
private cachedValue: V | undefined;
|
16
15
|
|
17
16
|
constructor(
|
@@ -63,7 +62,7 @@ export class ValueRef<V extends CoValue> {
|
|
63
62
|
if (raw === "unavailable") {
|
64
63
|
return "unavailable";
|
65
64
|
} else {
|
66
|
-
return new
|
65
|
+
return new Ref(
|
67
66
|
this.id,
|
68
67
|
this.controlledAccount,
|
69
68
|
this.valueConstructor
|
@@ -95,17 +94,17 @@ export class ValueRef<V extends CoValue> {
|
|
95
94
|
}
|
96
95
|
}
|
97
96
|
|
98
|
-
export function makeRefs<Keys extends string | number
|
97
|
+
export function makeRefs<Keys extends string | number>(
|
99
98
|
getIdForKey: (key: Keys) => ID<CoValue> | undefined,
|
100
99
|
getKeysWithIds: () => Keys[],
|
101
100
|
controlledAccount: Account & Me,
|
102
101
|
valueConstructorForKey: (key: Keys) => SubclassedConstructor<CoValue>
|
103
|
-
): { [K in Keys]:
|
104
|
-
[Symbol.iterator]: () => IterableIterator<
|
102
|
+
): { [K in Keys]: Ref<CoValue> } & {
|
103
|
+
[Symbol.iterator]: () => IterableIterator<Ref<CoValue>>;
|
105
104
|
length: number;
|
106
105
|
} {
|
107
|
-
const refs = {} as { [K in Keys]:
|
108
|
-
[Symbol.iterator]: () => IterableIterator<
|
106
|
+
const refs = {} as { [K in Keys]: Ref<CoValue> } & {
|
107
|
+
[Symbol.iterator]: () => IterableIterator<Ref<CoValue>>;
|
109
108
|
length: number;
|
110
109
|
};
|
111
110
|
return new Proxy(refs, {
|
@@ -113,7 +112,7 @@ export function makeRefs<Keys extends string | number | indexSignature>(
|
|
113
112
|
if (key === Symbol.iterator) {
|
114
113
|
return function* () {
|
115
114
|
for (const key of getKeysWithIds()) {
|
116
|
-
yield new
|
115
|
+
yield new Ref(
|
117
116
|
getIdForKey(key)!,
|
118
117
|
controlledAccount,
|
119
118
|
valueConstructorForKey(key)
|
@@ -127,7 +126,7 @@ export function makeRefs<Keys extends string | number | indexSignature>(
|
|
127
126
|
}
|
128
127
|
const id = getIdForKey(key as Keys);
|
129
128
|
if (!id) return undefined;
|
130
|
-
return new
|
129
|
+
return new Ref(
|
131
130
|
id as ID<CoValue>,
|
132
131
|
controlledAccount,
|
133
132
|
valueConstructorForKey(key as Keys)
|
package/src/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
/** @category Internal types */
|
2
1
|
export {
|
2
|
+
/** @category Internal types */
|
3
3
|
cojsonReady as jazzReady,
|
4
4
|
InviteSecret,
|
5
5
|
Peer,
|
@@ -14,7 +14,7 @@ export { ID, CoValue } from "./internal.js";
|
|
14
14
|
|
15
15
|
export { Encoders } from "./internal.js";
|
16
16
|
|
17
|
-
export { CoMap
|
17
|
+
export { CoMap } from "./internal.js";
|
18
18
|
export { CoList } from "./internal.js";
|
19
19
|
export { CoStream, BinaryCoStream } from "./internal.js";
|
20
20
|
export { Group, Profile } from "./internal.js";
|
package/src/internal.ts
CHANGED
@@ -9,7 +9,7 @@ export * from "./coValues/group.js";
|
|
9
9
|
|
10
10
|
export * from "./implementation/errors.js";
|
11
11
|
export * from "./implementation/refs.js";
|
12
|
-
export * from "./implementation/
|
12
|
+
export * from "./implementation/encoding.js";
|
13
13
|
export * from "./implementation/subscriptionScope.js";
|
14
14
|
|
15
15
|
export * from "./coValues/extensions/imageDef.js";
|
package/src/tests/coMap.test.ts
CHANGED
@@ -4,7 +4,7 @@ import { webcrypto } from "node:crypto";
|
|
4
4
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
5
5
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
6
|
import { Effect, Queue } from "effect";
|
7
|
-
import { Account, jazzReady, Encoders,
|
7
|
+
import { Account, jazzReady, Encoders, CoMap } from "..";
|
8
8
|
|
9
9
|
if (!("crypto" in globalThis)) {
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -389,11 +389,11 @@ describe("CoMap resolution", async () => {
|
|
389
389
|
});
|
390
390
|
|
391
391
|
class TestRecord extends CoMap<TestRecord> {
|
392
|
-
declare
|
392
|
+
declare _item: number;
|
393
393
|
}
|
394
394
|
interface TestRecord extends Record<string, number> {}
|
395
395
|
TestRecord.encoding({
|
396
|
-
|
396
|
+
_item: "json",
|
397
397
|
});
|
398
398
|
|
399
399
|
test("Construction with index signature", async () => {
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/implementation/schema.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,IAAI;CACP,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC"}
|