jazz-tools 0.7.0-alpha.2 → 0.7.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # jazz-autosub
2
2
 
3
+ ## 0.7.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Make refs type more precise
8
+
3
9
  ## 0.7.0-alpha.2
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { subscriptionsScopes } from '../internal.js';
2
+ import { subscriptionsScopes } from "../internal.js";
3
3
  export class ValueRef {
4
4
  constructor(id, controlledAccount, valueConstructor) {
5
5
  this.id = id;
@@ -12,7 +12,9 @@ export class ValueRef {
12
12
  // TODO: cache it for object identity!!!
13
13
  const raw = this.controlledAccount._raw.core.node.getLoaded(this.id);
14
14
  if (raw) {
15
- const value = new this.valueConstructor(undefined, { fromRaw: raw });
15
+ const value = new this.valueConstructor(undefined, {
16
+ fromRaw: raw,
17
+ });
16
18
  this.cachedValue = value;
17
19
  return value;
18
20
  }
@@ -42,8 +44,7 @@ export class ValueRef {
42
44
  return "unavailable";
43
45
  }
44
46
  else {
45
- return new ValueRef(this.id, this.controlledAccount, this.valueConstructor)
46
- .value;
47
+ return new ValueRef(this.id, this.controlledAccount, this.valueConstructor).value;
47
48
  }
48
49
  }
49
50
  async load(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,OAAO,QAAQ;IAGjB,YACa,EAAS,EACT,iBAA+B,EAC/B,gBAA0C;QAF1C,OAAE,GAAF,EAAE,CAAO;QACT,sBAAiB,GAAjB,iBAAiB,CAAc;QAC/B,qBAAgB,GAAhB,gBAAgB,CAA0B;IACpD,CAAC;IAEJ,IAAI,KA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,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC;YACnC,CAAC;YACD,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,CAAC,EAAE;gBAAE,OAAO,SAAS,CAAC;YAC1B,OAAO,IAAI,QAAQ,CACf,EAAiB,EACjB,iBAAiB,EACjB,sBAAsB,CAAC,GAAW,CAAC,CACtC,CAAC;QACN,CAAC;QACD,OAAO;YACH,OAAO,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "types": "src/index.ts",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
- "version": "0.7.0-alpha.2",
8
+ "version": "0.7.0-alpha.3",
9
9
  "dependencies": {
10
10
  "@effect/schema": "^0.64.20",
11
11
  "effect": "^2.4.18",
@@ -1,7 +1,15 @@
1
1
  import { Effect } from "effect";
2
2
  import type { CoID, RawCoValue } from "cojson";
3
- import type { Account, CoValue, ID, Me, SubclassedConstructor, UnavailableError, indexSignature} from '../internal.js';
4
- import { subscriptionsScopes } from '../internal.js';
3
+ import type {
4
+ Account,
5
+ CoValue,
6
+ ID,
7
+ Me,
8
+ SubclassedConstructor,
9
+ UnavailableError,
10
+ indexSignature,
11
+ } from "../internal.js";
12
+ import { subscriptionsScopes } from "../internal.js";
5
13
 
6
14
  export class ValueRef<V extends CoValue> {
7
15
  private cachedValue: V | undefined;
@@ -19,7 +27,9 @@ export class ValueRef<V extends CoValue> {
19
27
  this.id as unknown as CoID<RawCoValue>
20
28
  );
21
29
  if (raw) {
22
- const value = new this.valueConstructor(undefined, { fromRaw: raw }) as V;
30
+ const value = new this.valueConstructor(undefined, {
31
+ fromRaw: raw,
32
+ }) as V;
23
33
  this.cachedValue = value;
24
34
  return value;
25
35
  } else {
@@ -43,7 +53,9 @@ export class ValueRef<V extends CoValue> {
43
53
  });
44
54
  }
45
55
 
46
- private async loadHelper(options?: {onProgress: (p: number) => void}): Promise<V | "unavailable"> {
56
+ private async loadHelper(options?: {
57
+ onProgress: (p: number) => void;
58
+ }): Promise<V | "unavailable"> {
47
59
  const raw = await this.controlledAccount._raw.core.node.load(
48
60
  this.id as unknown as CoID<RawCoValue>,
49
61
  options?.onProgress
@@ -51,12 +63,17 @@ export class ValueRef<V extends CoValue> {
51
63
  if (raw === "unavailable") {
52
64
  return "unavailable";
53
65
  } else {
54
- return new ValueRef(this.id, this.controlledAccount, this.valueConstructor)
55
- .value!;
66
+ return new ValueRef(
67
+ this.id,
68
+ this.controlledAccount,
69
+ this.valueConstructor
70
+ ).value!;
56
71
  }
57
72
  }
58
73
 
59
- async load(options?: {onProgress: (p: number) => void}): Promise<V | undefined> {
74
+ async load(options?: {
75
+ onProgress: (p: number) => void;
76
+ }): Promise<V | undefined> {
60
77
  const result = await this.loadHelper(options);
61
78
  if (result === "unavailable") {
62
79
  return undefined;
@@ -82,9 +99,15 @@ export function makeRefs<Keys extends string | number | indexSignature>(
82
99
  getIdForKey: (key: Keys) => ID<CoValue> | undefined,
83
100
  getKeysWithIds: () => Keys[],
84
101
  controlledAccount: Account & Me,
85
- valueConstructorForKey: (key: Keys) => SubclassedConstructor<CoValue>,
86
- ): { [K in Keys]: ValueRef<CoValue> } {
87
- const refs = {} as { [K in Keys]: ValueRef<CoValue> };
102
+ valueConstructorForKey: (key: Keys) => SubclassedConstructor<CoValue>
103
+ ): { [K in Keys]: ValueRef<CoValue> } & {
104
+ [Symbol.iterator]: () => IterableIterator<ValueRef<CoValue>>;
105
+ length: number;
106
+ } {
107
+ const refs = {} as { [K in Keys]: ValueRef<CoValue> } & {
108
+ [Symbol.iterator]: () => IterableIterator<ValueRef<CoValue>>;
109
+ length: number;
110
+ };
88
111
  return new Proxy(refs, {
89
112
  get(target, key) {
90
113
  if (key === Symbol.iterator) {