jazz-tools 0.7.0-alpha.4 → 0.7.0-alpha.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. package/.eslintrc.cjs +3 -10
  2. package/.prettierrc.js +9 -0
  3. package/.turbo/turbo-build.log +3 -19
  4. package/.turbo/turbo-lint.log +4 -0
  5. package/.turbo/turbo-test.log +140 -0
  6. package/CHANGELOG.md +252 -0
  7. package/README.md +10 -2
  8. package/dist/coValues/account.js +104 -50
  9. package/dist/coValues/account.js.map +1 -1
  10. package/dist/coValues/coList.js +165 -112
  11. package/dist/coValues/coList.js.map +1 -1
  12. package/dist/coValues/coMap.js +243 -163
  13. package/dist/coValues/coMap.js.map +1 -1
  14. package/dist/coValues/coStream.js +256 -73
  15. package/dist/coValues/coStream.js.map +1 -1
  16. package/dist/coValues/deepLoading.js +57 -0
  17. package/dist/coValues/deepLoading.js.map +1 -0
  18. package/dist/coValues/extensions/imageDef.js +14 -8
  19. package/dist/coValues/extensions/imageDef.js.map +1 -1
  20. package/dist/coValues/group.js +49 -38
  21. package/dist/coValues/group.js.map +1 -1
  22. package/dist/coValues/interfaces.js +66 -26
  23. package/dist/coValues/interfaces.js.map +1 -1
  24. package/dist/implementation/devtoolsFormatters.js +114 -0
  25. package/dist/implementation/devtoolsFormatters.js.map +1 -0
  26. package/dist/implementation/refs.js +60 -19
  27. package/dist/implementation/refs.js.map +1 -1
  28. package/dist/implementation/schema.js +44 -1
  29. package/dist/implementation/schema.js.map +1 -1
  30. package/dist/implementation/subscriptionScope.js +19 -1
  31. package/dist/implementation/subscriptionScope.js.map +1 -1
  32. package/dist/implementation/symbols.js +5 -0
  33. package/dist/implementation/symbols.js.map +1 -0
  34. package/dist/index.js +4 -5
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal.js +4 -1
  37. package/dist/internal.js.map +1 -1
  38. package/dist/tests/coList.test.js +51 -52
  39. package/dist/tests/coList.test.js.map +1 -1
  40. package/dist/tests/coMap.test.js +196 -75
  41. package/dist/tests/coMap.test.js.map +1 -1
  42. package/dist/tests/coStream.test.js +95 -85
  43. package/dist/tests/coStream.test.js.map +1 -1
  44. package/dist/tests/deepLoading.test.js +188 -0
  45. package/dist/tests/deepLoading.test.js.map +1 -0
  46. package/dist/tests/groupsAndAccounts.test.js +83 -0
  47. package/dist/tests/groupsAndAccounts.test.js.map +1 -0
  48. package/package.json +17 -9
  49. package/src/coValues/account.ts +184 -153
  50. package/src/coValues/coList.ts +220 -173
  51. package/src/coValues/coMap.ts +322 -312
  52. package/src/coValues/coStream.ts +397 -135
  53. package/src/coValues/deepLoading.ts +215 -0
  54. package/src/coValues/extensions/imageDef.ts +16 -17
  55. package/src/coValues/group.ts +95 -111
  56. package/src/coValues/interfaces.ts +217 -115
  57. package/src/implementation/devtoolsFormatters.ts +110 -0
  58. package/src/implementation/inspect.ts +1 -1
  59. package/src/implementation/refs.ts +91 -38
  60. package/src/implementation/schema.ts +87 -46
  61. package/src/implementation/subscriptionScope.ts +44 -12
  62. package/src/implementation/symbols.ts +11 -0
  63. package/src/index.ts +13 -9
  64. package/src/internal.ts +6 -2
  65. package/src/tests/coList.test.ts +67 -66
  66. package/src/tests/coMap.test.ts +226 -123
  67. package/src/tests/coStream.test.ts +141 -131
  68. package/src/tests/deepLoading.test.ts +301 -0
  69. package/src/tests/groupsAndAccounts.test.ts +91 -0
@@ -1,30 +1,36 @@
1
1
  var _a;
2
- import { Account, CoMap, CoValueBase, ValueRef, isControlledAccount, } from "../internal.js";
2
+ import { Account, CoMap, CoValueBase, Ref, co, isControlledAccount, AccountAndGroupProxyHandler, MembersSym, } from "../internal.js";
3
+ /** @category Identity & Permissions */
3
4
  export class Profile extends CoMap {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.name = co.string;
8
+ }
4
9
  }
5
- Profile.encoding({ name: "json" });
10
+ /** @category Identity & Permissions */
6
11
  export class Group extends CoValueBase {
7
- get _encoding() {
8
- return this.constructor._encoding;
12
+ get _schema() {
13
+ return this.constructor._schema;
9
14
  }
10
15
  get _refs() {
11
16
  const profileID = this._raw.get("profile");
12
17
  const rootID = this._raw.get("root");
13
18
  return {
14
19
  profile: profileID &&
15
- new ValueRef(profileID, this._loadedAs, this._encoding.profile.ref()),
20
+ new Ref(profileID, this._loadedAs, this._schema.profile),
16
21
  root: rootID &&
17
- new ValueRef(rootID, this._loadedAs, this._encoding.root.ref()),
22
+ new Ref(rootID, this._loadedAs, this._schema.root),
18
23
  };
19
24
  }
20
- constructor(init, options) {
25
+ /** @deprecated Don't use constructor directly, use .create */
26
+ constructor(options) {
21
27
  super();
22
28
  let raw;
23
29
  if (options && "fromRaw" in options) {
24
30
  raw = options.fromRaw;
25
31
  }
26
32
  else {
27
- const initOwner = options?.owner || init?.owner;
33
+ const initOwner = options.owner;
28
34
  if (!initOwner)
29
35
  throw new Error("No owner provided");
30
36
  if (initOwner instanceof Account &&
@@ -42,39 +48,42 @@ export class Group extends CoValueBase {
42
48
  enumerable: false,
43
49
  },
44
50
  _raw: { value: raw, enumerable: false },
45
- profile: {
46
- get: () => {
47
- const ref = this._refs.profile;
48
- return ref ? ref.accessFrom(this) : undefined;
49
- },
50
- set: (value) => {
51
- if (value) {
52
- this._raw.set("profile", value.id);
53
- }
54
- },
55
- },
56
- root: {
57
- get: () => {
58
- const ref = this._refs.root;
59
- return ref ? ref.accessFrom(this) : undefined;
60
- },
61
- set: (value) => {
62
- if (value) {
63
- this._raw.set("root", value.id);
64
- }
65
- },
66
- },
67
51
  });
52
+ return new Proxy(this, AccountAndGroupProxyHandler);
53
+ }
54
+ static create(options) {
55
+ return new this(options);
68
56
  }
69
57
  myRole() {
70
58
  return this._raw.myRole();
71
59
  }
72
60
  addMember(member, role) {
73
61
  this._raw.addMember(member === "everyone" ? member : member._raw, role);
62
+ return this;
74
63
  }
75
- static define(fields) {
76
- this._encoding || (this._encoding = {});
77
- Object.assign(this._encoding, fields);
64
+ get members() {
65
+ return this._raw
66
+ .keys()
67
+ .filter((key) => {
68
+ return key === "everyone" || key.startsWith("co_");
69
+ })
70
+ .map((id) => {
71
+ const role = this._raw.get(id);
72
+ const accountID = id === "everyone"
73
+ ? undefined
74
+ : id;
75
+ const ref = accountID &&
76
+ new Ref(accountID, this._loadedAs, this._schema[MembersSym]);
77
+ const accessRef = () => ref?.accessFrom(this, "members." + id);
78
+ return {
79
+ id: id,
80
+ role,
81
+ ref,
82
+ get account() {
83
+ return accessRef();
84
+ },
85
+ };
86
+ });
78
87
  }
79
88
  }
80
89
  _a = Group;
@@ -82,12 +91,14 @@ _a = Group;
82
91
  _a.prototype._type = "Group";
83
92
  })();
84
93
  (() => {
85
- _a._encoding = {
86
- profile: { json: true },
87
- root: { json: true },
94
+ _a._schema = {
95
+ profile: "json",
96
+ root: "json",
97
+ [MembersSym]: () => Account,
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
99
  };
89
- Object.defineProperty(_a.prototype, "_encoding", {
90
- get: () => _a._encoding,
100
+ Object.defineProperty(_a.prototype, "_schema", {
101
+ get: () => _a._schema,
91
102
  });
92
103
  })();
93
104
  //# sourceMappingURL=group.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/coValues/group.ts"],"names":[],"mappings":";AAQA,OAAO,EACH,OAAO,EACP,KAAK,EACL,WAAW,EACX,QAAQ,EACR,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,OAAQ,SAAQ,KAAuB;CAEnD;AACD,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAEnC,MAAM,OAAO,KAMT,SAAQ,WAAW;IAWnB,IAAI,SAAS;QAQT,OAAQ,IAAI,CAAC,WAA4B,CAAC,SAAS,CAAC;IACxD,CAAC;IAiBD,IAAI,KAAK;QAML,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAE1B,CAAC;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MA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7C,GAAG,EAAE,GAAG,EAAE,CAAC,GAAK,OAAO;KAC1B,CAAC,CAAC;AACP,CAAC,GAAA,CAAA"}
@@ -1,49 +1,80 @@
1
- import { Effect, Sink, Stream } from "effect";
1
+ import { Effect, Option, Sink, Stream } from "effect";
2
2
  import { RawAccount } from "cojson";
3
- import { Account, AccountCtx, Group, SubscriptionScope, ValueRef, inspect, } from "../internal.js";
3
+ import { Account, AccountCtx, Group, SubscriptionScope, Ref, inspect, subscriptionsScopes, } from "../internal.js";
4
+ import { fulfillsDepth } from "./deepLoading.js";
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
6
  export function isCoValue(value) {
5
7
  return value && value._type !== undefined;
6
8
  }
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ export function isCoValueClass(value) {
11
+ return typeof value === "function" && value.fromRaw !== undefined;
12
+ }
13
+ /** @internal */
7
14
  export class CoValueBase {
8
15
  get _owner() {
9
- return this._raw.group instanceof RawAccount
16
+ const owner = this._raw.group instanceof RawAccount
10
17
  ? Account.fromRaw(this._raw.group)
11
18
  : Group.fromRaw(this._raw.group);
19
+ const subScope = subscriptionsScopes.get(this);
20
+ if (subScope) {
21
+ subScope.onRefAccessedOrSet(this.id, owner.id);
22
+ subscriptionsScopes.set(owner, subScope);
23
+ }
24
+ return owner;
12
25
  }
26
+ /** @private */
13
27
  get _loadedAs() {
14
28
  return Account.fromNode(this._raw.core.node);
15
29
  }
16
- constructor(..._args) { }
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ constructor(..._args) {
32
+ Object.defineProperty(this, "_instanceID", {
33
+ value: `instance-${Math.random().toString(36).slice(2)}`,
34
+ enumerable: false,
35
+ });
36
+ }
37
+ /** @category Internals */
17
38
  static fromRaw(raw) {
18
- return new this(undefined, { fromRaw: raw });
39
+ return new this({ fromRaw: raw });
19
40
  }
20
- static loadEf(id) {
21
- return Effect.gen(this, function* (_) {
22
- const account = yield* _(AccountCtx);
23
- return yield* _(new ValueRef(id, account, this).loadEf());
24
- });
41
+ static load(...args) {
42
+ const { id, as, depth } = args.length === 3
43
+ ? { id: args[0], as: args[1], depth: args[2] }
44
+ : { id: args[0].id, as: args[0]._loadedAs, depth: args[1] };
45
+ return Effect.runPromise(this.loadEf(id, depth).pipe(Effect.mapError(() => undefined), Effect.merge, Effect.provideService(AccountCtx, as)));
25
46
  }
26
- static load(id, options) {
27
- return new ValueRef(id, options.as, this).load(options?.onProgress && { onProgress: options.onProgress });
47
+ /** @category Subscription & Loading */
48
+ static loadEf(id, depth) {
49
+ return this.subscribeEf(id, depth).pipe(Stream.runHead, Effect.andThen(Effect.mapError((_noSuchElem) => "unavailable")));
28
50
  }
29
- static subscribe(id, options, onUpdate) {
30
- void Effect.runPromise(Effect.provideService(this.subscribeEf(id).pipe(Stream.run(Sink.forEach((update) => Effect.sync(() => onUpdate(update))))), AccountCtx, options.as));
51
+ static subscribe(...args) {
52
+ const { id, as, depth, listener } = args.length === 4
53
+ ? {
54
+ id: args[0],
55
+ as: args[1],
56
+ depth: args[2],
57
+ listener: args[3],
58
+ }
59
+ : {
60
+ id: args[0].id,
61
+ as: args[0]._loadedAs,
62
+ depth: args[1],
63
+ listener: args[2],
64
+ };
65
+ void Effect.runPromise(Effect.provideService(this.subscribeEf(id, depth).pipe(Stream.run(Sink.forEach((update) => Effect.sync(() => listener(update))))), AccountCtx, as));
31
66
  return function unsubscribe() { };
32
67
  }
33
- static subscribeEf(id) {
34
- return Stream.fromEffect(this.loadEf(id)).pipe(Stream.flatMap((value) => Stream.asyncScoped((emit) => Effect.gen(this, function* (_) {
35
- const subscription = new SubscriptionScope(value, this, (update) => {
36
- void emit.single(update);
37
- });
68
+ /** @category Subscription & Loading */
69
+ static subscribeEf(id, depth) {
70
+ return AccountCtx.pipe(Effect.andThen((account) => new Ref(id, account, this).loadEf()), Stream.fromEffect, Stream.flatMap((value) => Stream.asyncScoped((emit) => Effect.gen(this, function* (_) {
71
+ const subscription = new SubscriptionScope(value, this, (update) => void emit.single(update));
38
72
  yield* _(Effect.addFinalizer(() => Effect.sync(() => subscription.unsubscribeAll())));
39
- }))));
40
- }
41
- subscribe(listener) {
42
- return this.constructor.subscribe(this.id, { as: this._loadedAs }, listener);
43
- }
44
- subscribeEf() {
45
- return Stream.provideService(this.constructor.subscribeEf(this.id), AccountCtx, this._loadedAs);
73
+ }))), Stream.filterMap((update) => Option.fromNullable(fulfillsDepth(depth, update)
74
+ ? update
75
+ : undefined)));
46
76
  }
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
78
  toJSON() {
48
79
  return {
49
80
  id: this.id,
@@ -54,5 +85,14 @@ export class CoValueBase {
54
85
  [inspect]() {
55
86
  return this.toJSON();
56
87
  }
88
+ /** @category Type Helpers*/
89
+ as(otherSchema) {
90
+ const cast = otherSchema.fromRaw(this._raw);
91
+ const subScope = subscriptionsScopes.get(this);
92
+ if (subScope) {
93
+ subscriptionsScopes.set(cast, subScope);
94
+ }
95
+ return cast;
96
+ }
57
97
  }
58
98
  //# sourceMappingURL=interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/coValues/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACH,OAAO,EACP,UAAU,EACV,KAAK,EACL,iBAAiB,EACjB,QAAQ,EACR,OAAO,GACV,MAAM,gBAAgB,CAAC;AAqExB,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,OAAO,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AAC9C,CAAC;AAOD,MAAM,OAAO,WAAW;IAKpB,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,YAAY,UAAU;YACxC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,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AClB,CACJ,CACJ,CAAC;IACN,CAAC;IAED,8DAA8D;IAC9D,MAAM;QACF,OAAO;YACH,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,uBAAuB;SACjC,CAAC;IACN,CAAC;IAED,CAAC,OAAO,CAAC;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;IAED,4BAA4B;IAC5B,EAAE,CAAyB,WAAc;QACrC,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAoB,CAAC;QAC/D,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,QAAQ,EAAE,CAAC;YACX,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
@@ -0,0 +1,114 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { ItemsSym } from "./symbols.js";
3
+ globalThis.devtoolsFormatters = [
4
+ {
5
+ header: (object) => {
6
+ if (object._type === "CoMap") {
7
+ return ["div", {}, ["span", {}, object.constructor.name]];
8
+ }
9
+ else if (object._type === "CoList") {
10
+ return [
11
+ "div",
12
+ {},
13
+ [
14
+ "span",
15
+ {},
16
+ object.constructor.name + "(" + object.length + ") ",
17
+ ],
18
+ ];
19
+ }
20
+ else if (object._type === "Account") {
21
+ return [
22
+ "div",
23
+ {},
24
+ [
25
+ "span",
26
+ {},
27
+ object.constructor.name +
28
+ "(" +
29
+ object._refs.profile.value?.name +
30
+ (object.isMe ? " ME" : "") +
31
+ ")",
32
+ ],
33
+ ];
34
+ }
35
+ else {
36
+ return null;
37
+ }
38
+ },
39
+ hasBody: function () {
40
+ return true;
41
+ },
42
+ body: function (object) {
43
+ if (object._type === "CoMap" || object._type === "Account") {
44
+ return [
45
+ "div",
46
+ { style: "margin-left: 15px" },
47
+ ["div", "id: ", ["object", { object: object.id }]],
48
+ ...Object.entries(object).map(([k, v]) => [
49
+ "div",
50
+ { style: "white-space: nowrap;" },
51
+ [
52
+ "span",
53
+ { style: "font-weight: bold; opacity: 0.6" },
54
+ k,
55
+ ": ",
56
+ ],
57
+ ["object", { object: v }],
58
+ ...(typeof object._schema[k] === "function"
59
+ ? v === null
60
+ ? [
61
+ [
62
+ "span",
63
+ { style: "opacity: 0.5" },
64
+ ` (pending ${object._schema[k].name} `,
65
+ [
66
+ "object",
67
+ { object: object._refs[k] },
68
+ ],
69
+ ")",
70
+ ],
71
+ ]
72
+ : []
73
+ : []),
74
+ ]),
75
+ ];
76
+ }
77
+ else if (object._type === "CoList") {
78
+ return [
79
+ "div",
80
+ { style: "margin-left: 15px" },
81
+ ["div", "id: ", ["object", { object: object.id }]],
82
+ ...object.map((v, i) => [
83
+ "div",
84
+ { style: "white-space: nowrap;" },
85
+ [
86
+ "span",
87
+ { style: "font-weight: bold; opacity: 0.6" },
88
+ i,
89
+ ": ",
90
+ ],
91
+ ["object", { object: v }],
92
+ ...(typeof object._schema[ItemsSym] === "function"
93
+ ? v === null
94
+ ? [
95
+ [
96
+ "span",
97
+ { style: "opacity: 0.5" },
98
+ ` (pending ${object._schema[ItemsSym].name} `,
99
+ [
100
+ "object",
101
+ { object: object._refs[i] },
102
+ ],
103
+ ")",
104
+ ],
105
+ ]
106
+ : []
107
+ : []),
108
+ ]),
109
+ ];
110
+ }
111
+ },
112
+ },
113
+ ];
114
+ //# sourceMappingURL=devtoolsFormatters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtoolsFormatters.js","sourceRoot":"","sources":["../../src/implementation/devtoolsFormatters.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvC,UAAkB,CAAC,kBAAkB,GAAG;IACrC;QACI,MAAM,EAAE,CAAC,MAAW,E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QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;wBACzB,GAAG,CAAC,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,UAAU;4BAC9C,CAAC,CAAC,CAAC,KAAK,IAAI;gCACR,CAAC,CAAC;oCACI;wCACI,MAAM;wCACN,EAAE,KAAK,EAAE,cAAc,EAAE;wCACzB,aAAa,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,GAAG;wCAC7C;4CACI,QAAQ;4CACR,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;yCAC9B;wCACD,GAAG;qCACN;iCACJ;gCACH,CAAC,CAAC,EAAE;4BACR,CAAC,CAAC,EAAE,CAAC;qBACZ,CAAC;iBACL,CAAC;YACN,CAAC;QACL,CAAC;KACJ;CACJ,CAAC"}
@@ -1,21 +1,27 @@
1
1
  import { Effect } from "effect";
2
- import { subscriptionsScopes } from "../internal.js";
3
- export class ValueRef {
4
- constructor(id, controlledAccount, valueConstructor) {
2
+ import { instantiateRefEncoded, isRefEncoded, subscriptionsScopes, } from "../internal.js";
3
+ const refCache = new WeakMap();
4
+ const TRACE_ACCESSES = false;
5
+ export class Ref {
6
+ constructor(id, controlledAccount, schema) {
5
7
  this.id = id;
6
8
  this.controlledAccount = controlledAccount;
7
- this.valueConstructor = valueConstructor;
9
+ this.schema = schema;
10
+ if (!isRefEncoded(schema)) {
11
+ throw new Error("Ref must be constructed with a ref schema");
12
+ }
8
13
  }
9
14
  get value() {
10
- if (this.cachedValue)
11
- return this.cachedValue;
12
- // TODO: cache it for object identity!!!
13
15
  const raw = this.controlledAccount._raw.core.node.getLoaded(this.id);
14
16
  if (raw) {
15
- const value = new this.valueConstructor(undefined, {
16
- fromRaw: raw,
17
- });
18
- this.cachedValue = value;
17
+ let value = refCache.get(raw);
18
+ if (value) {
19
+ // console.log("Using cached value for " + this.id);
20
+ }
21
+ else {
22
+ value = instantiateRefEncoded(this.schema, raw);
23
+ refCache.set(raw, value);
24
+ }
19
25
  return value;
20
26
  }
21
27
  else {
@@ -44,7 +50,7 @@ export class ValueRef {
44
50
  return "unavailable";
45
51
  }
46
52
  else {
47
- return new ValueRef(this.id, this.controlledAccount, this.valueConstructor).value;
53
+ return new Ref(this.id, this.controlledAccount, this.schema).value;
48
54
  }
49
55
  }
50
56
  async load(options) {
@@ -56,23 +62,45 @@ export class ValueRef {
56
62
  return result;
57
63
  }
58
64
  }
59
- accessFrom(fromScopeValue) {
65
+ accessFrom(fromScopeValue, key) {
60
66
  const subScope = subscriptionsScopes.get(fromScopeValue);
61
- subScope?.onRefAccessedOrSet(this.id);
67
+ subScope?.onRefAccessedOrSet(fromScopeValue.id, this.id);
68
+ TRACE_ACCESSES &&
69
+ console.log(subScope?.scopeID, "accessing", fromScopeValue, key, this.id);
62
70
  if (this.value && subScope) {
63
71
  subscriptionsScopes.set(this.value, subScope);
64
72
  }
65
- return this.value;
73
+ if (subScope) {
74
+ const cached = subScope.cachedValues[this.id];
75
+ if (cached) {
76
+ TRACE_ACCESSES && console.log("cached", cached);
77
+ return cached;
78
+ }
79
+ else if (this.value !== null) {
80
+ const freshValueInstance = instantiateRefEncoded(this.schema, this.value?._raw);
81
+ TRACE_ACCESSES &&
82
+ console.log("freshValueInstance", freshValueInstance);
83
+ subScope.cachedValues[this.id] = freshValueInstance;
84
+ subscriptionsScopes.set(freshValueInstance, subScope);
85
+ return freshValueInstance;
86
+ }
87
+ else {
88
+ return null;
89
+ }
90
+ }
91
+ else {
92
+ return this.value;
93
+ }
66
94
  }
67
95
  }
68
- export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, valueConstructorForKey) {
96
+ export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, refSchemaForKey) {
69
97
  const refs = {};
70
98
  return new Proxy(refs, {
71
- get(target, key) {
99
+ get(_target, key) {
72
100
  if (key === Symbol.iterator) {
73
101
  return function* () {
74
102
  for (const key of getKeysWithIds()) {
75
- yield new ValueRef(getIdForKey(key), controlledAccount, valueConstructorForKey(key));
103
+ yield new Ref(getIdForKey(key), controlledAccount, refSchemaForKey(key));
76
104
  }
77
105
  };
78
106
  }
@@ -84,11 +112,24 @@ export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, valueCo
84
112
  const id = getIdForKey(key);
85
113
  if (!id)
86
114
  return undefined;
87
- return new ValueRef(id, controlledAccount, valueConstructorForKey(key));
115
+ return new Ref(id, controlledAccount, refSchemaForKey(key));
88
116
  },
89
117
  ownKeys() {
90
118
  return getKeysWithIds().map((key) => key.toString());
91
119
  },
120
+ getOwnPropertyDescriptor(target, key) {
121
+ const id = getIdForKey(key);
122
+ if (id) {
123
+ return {
124
+ enumerable: true,
125
+ configurable: true,
126
+ writable: true,
127
+ };
128
+ }
129
+ else {
130
+ return Reflect.getOwnPropertyDescriptor(target, key);
131
+ }
132
+ },
92
133
  });
93
134
  }
94
135
  //# sourceMappingURL=refs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAWhC,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,KAAK;QACL,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC;QAC9C,wCAAwC;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CACvD,IAAI,CAAC,EAAiC,CACzC,CAAC;QACF,IAAI,GAAG,EAAE,CAAC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AC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,wBAAwB,CAAC,MAAM,EAAE,GAAG;YAChC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAW,CAAC,CAAC;YACpC,IAAI,EAAE,EAAE,CAAC;gBACL,OAAO;oBACH,UAAU,EAAE,IAAI;oBAChB,YAAY,EAAE,IAAI;oBAClB,QAAQ,EAAE,IAAI;iBACjB,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACzD,CAAC;QACL,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
@@ -1,6 +1,49 @@
1
+ import { isCoValueClass, } from "../internal.js";
2
+ /** @category Schema definition */
3
+ export const co = {
4
+ string: {
5
+ [SchemaInit]: "json",
6
+ },
7
+ number: {
8
+ [SchemaInit]: "json",
9
+ },
10
+ boolean: {
11
+ [SchemaInit]: "json",
12
+ },
13
+ null: {
14
+ [SchemaInit]: "json",
15
+ },
16
+ literal: (..._lit) => {
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ return { [SchemaInit]: "json" };
19
+ },
20
+ json: () => {
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ return { [SchemaInit]: "json" };
23
+ },
24
+ encoded: (arg) => {
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ return { [SchemaInit]: { encoded: arg } };
27
+ },
28
+ ref: (arg) => {
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ return { [SchemaInit]: arg };
31
+ },
32
+ items: ItemsSym,
33
+ members: MembersSym,
34
+ };
35
+ export function isRefEncoded(schema) {
36
+ return typeof schema === "function";
37
+ }
38
+ export function instantiateRefEncoded(schema, raw) {
39
+ return isCoValueClass(schema)
40
+ ? schema.fromRaw(raw)
41
+ : schema(raw).fromRaw(raw);
42
+ }
1
43
  import { Date } from "@effect/schema/Schema";
44
+ import { SchemaInit, ItemsSym, MembersSym } from "./symbols.js";
45
+ /** @category Schema definition */
2
46
  export const Encoders = {
3
47
  Date,
4
48
  };
5
- export const indexSignature = Symbol.for("indexSignature");
6
49
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/implementation/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,cAAc,GACjB,MAAM,gBAAgB,CAAC;AAaxB,kCAAkC;AAClC,MAAM,CAAC,MAAM,EAAE,GAAG;IACd,MAAM,EAAE;QACJ,CAAC,UAAU,CAAC,EAAE,MAAuB;KACf;IAC1B,MAAM,EAAE;QACJ,CAAC,UAAU,CAAC,EAAE,MAAuB;KACf;IAC1B,OAAO,EAAE;QACL,CAAC,UAAU,CAAC,EAAE,MAAuB;KACd;IAC3B,IAAI,EAAE;QACF,CAAC,UAAU,CAAC,EAAE,MAAuB;KACjB;IACxB,OAAO,EAAE,CACL,GAAG,IAAO,EACG,EAAE;QACf,8DAA8D;QAC9D,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,MAAuB,EAAS,CAAC;IAC5D,CAAC;IACD,IAAI,EAAE,GAA+B,EAAE;QACnC,8DAA8D;QAC9D,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,MAAuB,EAAS,CAAC;IAC5D,CAAC;IACD,OAAO,EAAE,CAAI,GAAe,EAAS,EAAE;QACnC,8DAA8D;QAC9D,OAAO,EAAE,CAAC,UAAU,CAAC,E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