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.
Files changed (40) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/coValues/account.js +3 -3
  3. package/dist/coValues/account.js.map +1 -1
  4. package/dist/coValues/coList.js +2 -2
  5. package/dist/coValues/coList.js.map +1 -1
  6. package/dist/coValues/coMap.js +11 -11
  7. package/dist/coValues/coMap.js.map +1 -1
  8. package/dist/coValues/coStream.js +3 -3
  9. package/dist/coValues/coStream.js.map +1 -1
  10. package/dist/coValues/extensions/imageDef.js +2 -2
  11. package/dist/coValues/extensions/imageDef.js.map +1 -1
  12. package/dist/coValues/group.js +3 -3
  13. package/dist/coValues/group.js.map +1 -1
  14. package/dist/coValues/interfaces.js +3 -3
  15. package/dist/coValues/interfaces.js.map +1 -1
  16. package/dist/implementation/encoding.js +5 -0
  17. package/dist/implementation/encoding.js.map +1 -0
  18. package/dist/implementation/refs.js +4 -4
  19. package/dist/implementation/refs.js.map +1 -1
  20. package/dist/index.js +3 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/internal.js +1 -1
  23. package/dist/internal.js.map +1 -1
  24. package/dist/tests/coMap.test.js +2 -2
  25. package/dist/tests/coMap.test.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/coValues/account.ts +11 -11
  28. package/src/coValues/coList.ts +22 -15
  29. package/src/coValues/coMap.ts +30 -40
  30. package/src/coValues/coStream.ts +12 -12
  31. package/src/coValues/extensions/imageDef.ts +2 -3
  32. package/src/coValues/group.ts +13 -13
  33. package/src/coValues/interfaces.ts +3 -3
  34. package/src/implementation/{schema.ts → encoding.ts} +14 -17
  35. package/src/implementation/refs.ts +9 -10
  36. package/src/index.ts +2 -2
  37. package/src/internal.ts +1 -1
  38. package/src/tests/coMap.test.ts +3 -3
  39. package/dist/implementation/schema.js +0 -6
  40. 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 PrimitiveField = "json";
6
- export type EncodedField<V> = { encoded: Encoder<V> };
7
- export type RefField<V extends CoValue> = {
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 FieldDescriptor =
12
- | PrimitiveField
13
- | RefField<CoValue>
14
- | EncodedField<any>;
11
+ export type Encoding =
12
+ | JsonEncoded
13
+ | RefEncoded<CoValue>
14
+ | EncodedAs<any>;
15
15
 
16
- export type FieldDescriptorFor<Field> = NonNullable<Field> extends CoValue
17
- ? RefField<NonNullable<Field>>
16
+ export type EncodingFor<Field> = NonNullable<Field> extends CoValue
17
+ ? RefEncoded<NonNullable<Field>>
18
18
  : NonNullable<Field> extends JsonValue
19
- ? PrimitiveField
20
- : EncodedField<NonNullable<Field>>;
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 | indexSignature,
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 [indexSignature] as:`,
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 EnsureItemNullable<Item, ContainerType extends string> =
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 ValueRef<V extends CoValue> {
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 ValueRef(
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 | indexSignature>(
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]: ValueRef<CoValue> } & {
104
- [Symbol.iterator]: () => IterableIterator<ValueRef<CoValue>>;
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]: ValueRef<CoValue> } & {
108
- [Symbol.iterator]: () => IterableIterator<ValueRef<CoValue>>;
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 ValueRef(
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 ValueRef(
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, indexSignature } from "./internal.js";
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/schema.js";
12
+ export * from "./implementation/encoding.js";
13
13
  export * from "./implementation/subscriptionScope.js";
14
14
 
15
15
  export * from "./coValues/extensions/imageDef.js";
@@ -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, indexSignature, CoMap } from "..";
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 [indexSignature]: number;
392
+ declare _item: number;
393
393
  }
394
394
  interface TestRecord extends Record<string, number> {}
395
395
  TestRecord.encoding({
396
- [indexSignature]: "json",
396
+ _item: "json",
397
397
  });
398
398
 
399
399
  test("Construction with index signature", async () => {
@@ -1,6 +0,0 @@
1
- import { Date } from "@effect/schema/Schema";
2
- export const Encoders = {
3
- Date,
4
- };
5
- export const indexSignature = Symbol.for("indexSignature");
6
- //# sourceMappingURL=schema.js.map
@@ -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"}