jazz-tools 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/native/coValues/account.js.map +1 -0
  3. package/dist/native/coValues/coList.js.map +1 -0
  4. package/dist/native/coValues/coMap.js.map +1 -0
  5. package/dist/{coValues → native/coValues}/coStream.js +1 -0
  6. package/dist/native/coValues/coStream.js.map +1 -0
  7. package/dist/native/coValues/deepLoading.js.map +1 -0
  8. package/dist/native/coValues/extensions/imageDef.js.map +1 -0
  9. package/dist/native/coValues/group.js.map +1 -0
  10. package/dist/native/coValues/interfaces.js.map +1 -0
  11. package/dist/{implementation → native/implementation}/createContext.js +8 -1
  12. package/dist/native/implementation/createContext.js.map +1 -0
  13. package/dist/native/implementation/devtoolsFormatters.js.map +1 -0
  14. package/dist/{implementation → native/implementation}/errors.js.map +1 -1
  15. package/dist/native/implementation/inspect.js.map +1 -0
  16. package/dist/native/implementation/refs.js.map +1 -0
  17. package/dist/native/implementation/schema.js.map +1 -0
  18. package/dist/native/implementation/subscriptionScope.js.map +1 -0
  19. package/dist/native/implementation/symbols.js.map +1 -0
  20. package/dist/native/index.native.js +12 -0
  21. package/dist/native/index.native.js.map +1 -0
  22. package/dist/native/internal.js.map +1 -0
  23. package/dist/web/coValues/account.js +208 -0
  24. package/dist/web/coValues/account.js.map +1 -0
  25. package/dist/web/coValues/coList.js +395 -0
  26. package/dist/web/coValues/coList.js.map +1 -0
  27. package/dist/web/coValues/coMap.js +501 -0
  28. package/dist/web/coValues/coMap.js.map +1 -0
  29. package/dist/web/coValues/coStream.js +413 -0
  30. package/dist/web/coValues/coStream.js.map +1 -0
  31. package/dist/web/coValues/deepLoading.js +60 -0
  32. package/dist/web/coValues/deepLoading.js.map +1 -0
  33. package/dist/web/coValues/extensions/imageDef.js +37 -0
  34. package/dist/web/coValues/extensions/imageDef.js.map +1 -0
  35. package/dist/web/coValues/group.js +120 -0
  36. package/dist/web/coValues/group.js.map +1 -0
  37. package/dist/web/coValues/interfaces.js +109 -0
  38. package/dist/web/coValues/interfaces.js.map +1 -0
  39. package/dist/web/implementation/createContext.js +151 -0
  40. package/dist/web/implementation/createContext.js.map +1 -0
  41. package/dist/web/implementation/devtoolsFormatters.js +115 -0
  42. package/dist/web/implementation/devtoolsFormatters.js.map +1 -0
  43. package/dist/web/implementation/errors.js +2 -0
  44. package/dist/web/implementation/errors.js.map +1 -0
  45. package/dist/web/implementation/inspect.js +2 -0
  46. package/dist/web/implementation/inspect.js.map +1 -0
  47. package/dist/web/implementation/refs.js +127 -0
  48. package/dist/web/implementation/refs.js.map +1 -0
  49. package/dist/web/implementation/schema.js +91 -0
  50. package/dist/web/implementation/schema.js.map +1 -0
  51. package/dist/web/implementation/subscriptionScope.js +97 -0
  52. package/dist/web/implementation/subscriptionScope.js.map +1 -0
  53. package/dist/web/implementation/symbols.js +4 -0
  54. package/dist/web/implementation/symbols.js.map +1 -0
  55. package/dist/{index.js → web/index.web.js} +3 -3
  56. package/dist/{index.js.map → web/index.web.js.map} +1 -1
  57. package/dist/web/internal.js +17 -0
  58. package/dist/web/internal.js.map +1 -0
  59. package/package.json +25 -7
  60. package/src/coValues/account.ts +4 -1
  61. package/src/coValues/coStream.ts +26 -4
  62. package/src/coValues/group.ts +4 -1
  63. package/src/implementation/createContext.ts +12 -10
  64. package/src/{index.ts → index.native.ts} +2 -3
  65. package/src/index.web.ts +36 -0
  66. package/src/tests/coList.test.ts +2 -2
  67. package/src/tests/coMap.test.ts +11 -9
  68. package/src/tests/coStream.test.ts +2 -2
  69. package/src/tests/deepLoading.test.ts +2 -2
  70. package/src/tests/groupsAndAccounts.test.ts +1 -1
  71. package/tsconfig.json +5 -4
  72. package/tsconfig.native.json +11 -0
  73. package/tsconfig.web.json +11 -0
  74. package/dist/coValues/account.js.map +0 -1
  75. package/dist/coValues/coList.js.map +0 -1
  76. package/dist/coValues/coMap.js.map +0 -1
  77. package/dist/coValues/coStream.js.map +0 -1
  78. package/dist/coValues/deepLoading.js.map +0 -1
  79. package/dist/coValues/extensions/imageDef.js.map +0 -1
  80. package/dist/coValues/group.js.map +0 -1
  81. package/dist/coValues/interfaces.js.map +0 -1
  82. package/dist/implementation/createContext.js.map +0 -1
  83. package/dist/implementation/devtoolsFormatters.js.map +0 -1
  84. package/dist/implementation/inspect.js.map +0 -1
  85. package/dist/implementation/refs.js.map +0 -1
  86. package/dist/implementation/schema.js.map +0 -1
  87. package/dist/implementation/subscriptionScope.js.map +0 -1
  88. package/dist/implementation/symbols.js.map +0 -1
  89. package/dist/internal.js.map +0 -1
  90. package/dist/tests/coList.test.js +0 -221
  91. package/dist/tests/coList.test.js.map +0 -1
  92. package/dist/tests/coMap.test.js +0 -615
  93. package/dist/tests/coMap.test.js.map +0 -1
  94. package/dist/tests/coStream.test.js +0 -324
  95. package/dist/tests/coStream.test.js.map +0 -1
  96. package/dist/tests/deepLoading.test.js +0 -175
  97. package/dist/tests/deepLoading.test.js.map +0 -1
  98. package/dist/tests/groupsAndAccounts.test.js +0 -69
  99. package/dist/tests/groupsAndAccounts.test.js.map +0 -1
  100. /package/dist/{coValues → native/coValues}/account.js +0 -0
  101. /package/dist/{coValues → native/coValues}/coList.js +0 -0
  102. /package/dist/{coValues → native/coValues}/coMap.js +0 -0
  103. /package/dist/{coValues → native/coValues}/deepLoading.js +0 -0
  104. /package/dist/{coValues → native/coValues}/extensions/imageDef.js +0 -0
  105. /package/dist/{coValues → native/coValues}/group.js +0 -0
  106. /package/dist/{coValues → native/coValues}/interfaces.js +0 -0
  107. /package/dist/{implementation → native/implementation}/devtoolsFormatters.js +0 -0
  108. /package/dist/{implementation → native/implementation}/errors.js +0 -0
  109. /package/dist/{implementation → native/implementation}/inspect.js +0 -0
  110. /package/dist/{implementation → native/implementation}/refs.js +0 -0
  111. /package/dist/{implementation → native/implementation}/schema.js +0 -0
  112. /package/dist/{implementation → native/implementation}/subscriptionScope.js +0 -0
  113. /package/dist/{implementation → native/implementation}/symbols.js +0 -0
  114. /package/dist/{internal.js → native/internal.js} +0 -0
@@ -0,0 +1,109 @@
1
+ import { RawAccount } from "cojson";
2
+ import { Account, Group, SubscriptionScope, Ref, inspect, subscriptionsScopes, AnonymousJazzAgent, } from "../internal.js";
3
+ import { fulfillsDepth } from "./deepLoading.js";
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ export function isCoValue(value) {
6
+ return value && value._type !== undefined;
7
+ }
8
+ export function isCoValueClass(
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ value) {
11
+ return typeof value === "function" && value.fromRaw !== undefined;
12
+ }
13
+ /** @internal */
14
+ export class CoValueBase {
15
+ get _owner() {
16
+ const owner = this._raw.group instanceof RawAccount
17
+ ? Account.fromRaw(this._raw.group)
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;
25
+ }
26
+ /** @private */
27
+ get _loadedAs() {
28
+ if (this._raw.core.node.account instanceof RawAccount) {
29
+ return Account.fromRaw(this._raw.core.node.account);
30
+ }
31
+ return new AnonymousJazzAgent(this._raw.core.node);
32
+ }
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ constructor(..._args) {
35
+ Object.defineProperty(this, "_instanceID", {
36
+ value: `instance-${Math.random().toString(36).slice(2)}`,
37
+ enumerable: false,
38
+ });
39
+ }
40
+ /** @category Internals */
41
+ static fromRaw(raw) {
42
+ return new this({ fromRaw: raw });
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ toJSON() {
46
+ return {
47
+ id: this.id,
48
+ type: this._type,
49
+ error: "unknown CoValue class",
50
+ };
51
+ }
52
+ [inspect]() {
53
+ return this.toJSON();
54
+ }
55
+ /** @category Type Helpers */
56
+ castAs(cl) {
57
+ const casted = cl.fromRaw(this._raw);
58
+ const subscriptionScope = subscriptionsScopes.get(this);
59
+ if (subscriptionScope) {
60
+ subscriptionsScopes.set(casted, subscriptionScope);
61
+ }
62
+ return casted;
63
+ }
64
+ }
65
+ export function loadCoValue(cls, id, as, depth) {
66
+ return new Promise((resolve) => {
67
+ const unsubscribe = subscribeToCoValue(cls, id, as, depth, (value) => {
68
+ resolve(value);
69
+ unsubscribe();
70
+ }, () => {
71
+ resolve(undefined);
72
+ unsubscribe();
73
+ });
74
+ });
75
+ }
76
+ export function ensureCoValueLoaded(existing, depth) {
77
+ return loadCoValue(existing.constructor, existing.id, existing._loadedAs, depth);
78
+ }
79
+ export function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable) {
80
+ const ref = new Ref(id, as, { ref: cls, optional: false });
81
+ let unsubscribed = false;
82
+ let unsubscribe;
83
+ ref.load()
84
+ .then((value) => {
85
+ if (!value) {
86
+ onUnavailable && onUnavailable();
87
+ return;
88
+ }
89
+ if (unsubscribed)
90
+ return;
91
+ const subscription = new SubscriptionScope(value, cls, (update) => {
92
+ if (fulfillsDepth(depth, update)) {
93
+ listener(update);
94
+ }
95
+ });
96
+ unsubscribe = () => subscription.unsubscribeAll();
97
+ })
98
+ .catch((e) => {
99
+ console.error("Failed to load / subscribe to CoValue", e);
100
+ });
101
+ return function unsubscribeAtAnyPoint() {
102
+ unsubscribed = true;
103
+ unsubscribe && unsubscribe();
104
+ };
105
+ }
106
+ export function subscribeToExistingCoValue(existing, depth, listener) {
107
+ return subscribeToCoValue(existing.constructor, existing.id, existing._loadedAs, depth, listener);
108
+ }
109
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/coValues/interfaces.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACH,OAAO,EACP,KAAK,EACL,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,mBAAmB,EACnB,kBAAkB,GACrB,MAAM,gBAAgB,CAA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CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEP,OAAO,SAAS,qBAAqB;QACjC,YAAY,GAAG,IAAI,CAAC;QACpB,WAAW,IAAI,WAAW,EAAE,CAAC;IACjC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,0BAA0B,CACtC,QAAW,EACX,KAA0B,EAC1B,QAAiD;IAEjD,OAAO,kBAAkB,CACrB,QAAQ,CAAC,WAA8B,EACvC,QAAQ,CAAC,EAAE,EACX,QAAQ,CAAC,SAAS,EAClB,KAAK,EACL,QAAQ,CACX,CAAC;AACN,CAAC"}
@@ -0,0 +1,151 @@
1
+ import { ControlledAgent, LocalNode, } from "cojson";
2
+ import { Account } from "../internal.js";
3
+ export const fixedCredentialsAuth = (credentials) => {
4
+ return {
5
+ start: async () => ({
6
+ type: "existing",
7
+ credentials,
8
+ onSuccess: () => { },
9
+ onError: () => { },
10
+ logOut: () => { },
11
+ }),
12
+ };
13
+ };
14
+ export const ephemeralCredentialsAuth = () => {
15
+ return {
16
+ start: async () => ({
17
+ type: "new",
18
+ creationProps: { name: "Ephemeral" },
19
+ saveCredentials: async () => { },
20
+ onSuccess: () => { },
21
+ onError: () => { },
22
+ logOut: () => { },
23
+ }),
24
+ };
25
+ };
26
+ export async function randomSessionProvider(accountID, crypto) {
27
+ return {
28
+ sessionID: crypto.newRandomSessionID(accountID),
29
+ sessionDone: () => { },
30
+ };
31
+ }
32
+ export async function createJazzContext(options) {
33
+ // eslint-disable-next-line no-constant-condition
34
+ while (true) {
35
+ if (!("auth" in options)) {
36
+ return createAnonymousJazzContext({
37
+ peersToLoadFrom: options.peersToLoadFrom,
38
+ crypto: options.crypto,
39
+ });
40
+ }
41
+ const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
42
+ const AccountSchema = options.AccountSchema ?? Account;
43
+ let authResult;
44
+ try {
45
+ authResult = await auth.start(crypto);
46
+ }
47
+ catch (e) {
48
+ console.error("error", e);
49
+ throw e;
50
+ }
51
+ if (authResult.type === "existing") {
52
+ try {
53
+ const { sessionID, sessionDone } = await sessionProvider(authResult.credentials.accountID, crypto);
54
+ try {
55
+ const node = await LocalNode.withLoadedAccount({
56
+ accountID: authResult.credentials
57
+ .accountID,
58
+ accountSecret: authResult.credentials.secret,
59
+ sessionID: sessionID,
60
+ peersToLoadFrom: peersToLoadFrom,
61
+ crypto: crypto,
62
+ migration: async (rawAccount, _node, creationProps) => {
63
+ const account = new AccountSchema({
64
+ fromRaw: rawAccount,
65
+ });
66
+ await account.migrate?.(creationProps);
67
+ },
68
+ });
69
+ const account = AccountSchema.fromNode(node);
70
+ authResult.onSuccess();
71
+ return {
72
+ account,
73
+ done: () => {
74
+ node.gracefulShutdown();
75
+ sessionDone();
76
+ },
77
+ logOut: () => {
78
+ node.gracefulShutdown();
79
+ sessionDone();
80
+ authResult.logOut();
81
+ },
82
+ };
83
+ }
84
+ catch (e) {
85
+ authResult.onError(new Error("Error loading account", { cause: e }));
86
+ sessionDone();
87
+ }
88
+ }
89
+ catch (e) {
90
+ authResult.onError(new Error("Error acquiring sessionID", { cause: e }));
91
+ }
92
+ }
93
+ else if (authResult.type === "new") {
94
+ try {
95
+ // TODO: figure out a way to not "waste" the first SessionID
96
+ const { node } = await LocalNode.withNewlyCreatedAccount({
97
+ creationProps: authResult.creationProps,
98
+ peersToLoadFrom: peersToLoadFrom,
99
+ crypto: crypto,
100
+ initialAgentSecret: authResult.initialSecret,
101
+ migration: async (rawAccount, _node, creationProps) => {
102
+ const account = new AccountSchema({
103
+ fromRaw: rawAccount,
104
+ });
105
+ await account.migrate?.(creationProps);
106
+ },
107
+ });
108
+ const account = AccountSchema.fromNode(node);
109
+ await authResult.saveCredentials({
110
+ accountID: node.account.id,
111
+ secret: node.account.agentSecret,
112
+ });
113
+ authResult.onSuccess();
114
+ return {
115
+ account,
116
+ done: () => {
117
+ node.gracefulShutdown();
118
+ },
119
+ logOut: () => {
120
+ node.gracefulShutdown();
121
+ authResult.logOut();
122
+ },
123
+ };
124
+ }
125
+ catch (e) {
126
+ authResult.onError(new Error("Error creating account", { cause: e }));
127
+ }
128
+ }
129
+ }
130
+ }
131
+ export class AnonymousJazzAgent {
132
+ node;
133
+ _type = "Anonymous";
134
+ constructor(node) {
135
+ this.node = node;
136
+ }
137
+ }
138
+ export async function createAnonymousJazzContext({ peersToLoadFrom, crypto, }) {
139
+ const agentSecret = crypto.newRandomAgentSecret();
140
+ const rawAgent = new ControlledAgent(agentSecret, crypto);
141
+ const node = new LocalNode(rawAgent, crypto.newRandomSessionID(rawAgent.id), crypto);
142
+ for (const peer of peersToLoadFrom) {
143
+ node.syncManager.addPeer(peer);
144
+ }
145
+ return {
146
+ agent: new AnonymousJazzAgent(node),
147
+ done: () => { },
148
+ logOut: () => { },
149
+ };
150
+ }
151
+ //# sourceMappingURL=createContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/implementation/createContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,eAAe,EAEf,SAAS,GAKZ,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,OAAO,EAAoB,MAAM,gBAAgB,CAAC;AA2B3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,WAGpC,EAAc,EAAE;IACb,OAAO;QACH,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YAChB,IAAI,EAAE,UAAU;YAChB,WAAW;YACX,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;YACnB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;SACnB,CAAC;KACL,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAe,EAAE;IACrD,OAAO;QACH,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YAChB,IAAI,EAAE,KAAK;YACX,aAAa,EAAE,EAAE,IAAI,EAAE,WA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AK,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CACpD,CAAC;YACN,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC;AAED,MAAM,OAAO,kBAAkB;IAER;IADnB,KAAK,GAAG,WAAoB,CAAC;IAC7B,YAAmB,IAAe;QAAf,SAAI,GAAJ,IAAI,CAAW;IAAG,CAAC;CACzC;AAED,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,EAC7C,eAAe,EACf,MAAM,GAIT;IACG,MAAM,WAAW,GAAG,MAAM,CAAC,oBAAoB,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAE1D,MAAM,IAAI,GAAG,IAAI,SAAS,CACtB,QAAQ,EACR,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,EACtC,MAAM,CACT,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO;QACH,KAAK,EAAE,IAAI,kBAAkB,CAAC,IAAI,CAAC;QACnC,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;KACnB,CAAC;AACN,CAAC"}
@@ -0,0 +1,115 @@
1
+ /* istanbul ignore file -- @preserve */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import { ItemsSym } from "./symbols.js";
4
+ globalThis.devtoolsFormatters = [
5
+ {
6
+ header: (object) => {
7
+ if (object._type === "CoMap") {
8
+ return ["div", {}, ["span", {}, object.constructor.name]];
9
+ }
10
+ else if (object._type === "CoList") {
11
+ return [
12
+ "div",
13
+ {},
14
+ [
15
+ "span",
16
+ {},
17
+ object.constructor.name + "(" + object.length + ") ",
18
+ ],
19
+ ];
20
+ }
21
+ else if (object._type === "Account") {
22
+ return [
23
+ "div",
24
+ {},
25
+ [
26
+ "span",
27
+ {},
28
+ object.constructor.name +
29
+ "(" +
30
+ object._refs.profile.value?.name +
31
+ (object.isMe ? " ME" : "") +
32
+ ")",
33
+ ],
34
+ ];
35
+ }
36
+ else {
37
+ return null;
38
+ }
39
+ },
40
+ hasBody: function () {
41
+ return true;
42
+ },
43
+ body: function (object) {
44
+ if (object._type === "CoMap" || object._type === "Account") {
45
+ return [
46
+ "div",
47
+ { style: "margin-left: 15px" },
48
+ ["div", "id: ", ["object", { object: object.id }]],
49
+ ...Object.entries(object).map(([k, v]) => [
50
+ "div",
51
+ { style: "white-space: nowrap;" },
52
+ [
53
+ "span",
54
+ { style: "font-weight: bold; opacity: 0.6" },
55
+ k,
56
+ ": ",
57
+ ],
58
+ ["object", { object: v }],
59
+ ...(typeof object._schema[k] === "function"
60
+ ? v === null
61
+ ? [
62
+ [
63
+ "span",
64
+ { style: "opacity: 0.5" },
65
+ ` (pending ${object._schema[k].name} `,
66
+ [
67
+ "object",
68
+ { object: object._refs[k] },
69
+ ],
70
+ ")",
71
+ ],
72
+ ]
73
+ : []
74
+ : []),
75
+ ]),
76
+ ];
77
+ }
78
+ else if (object._type === "CoList") {
79
+ return [
80
+ "div",
81
+ { style: "margin-left: 15px" },
82
+ ["div", "id: ", ["object", { object: object.id }]],
83
+ ...object.map((v, i) => [
84
+ "div",
85
+ { style: "white-space: nowrap;" },
86
+ [
87
+ "span",
88
+ { style: "font-weight: bold; opacity: 0.6" },
89
+ i,
90
+ ": ",
91
+ ],
92
+ ["object", { object: v }],
93
+ ...(typeof object._schema[ItemsSym] === "function"
94
+ ? v === null
95
+ ? [
96
+ [
97
+ "span",
98
+ { style: "opacity: 0.5" },
99
+ ` (pending ${object._schema[ItemsSym].name} `,
100
+ [
101
+ "object",
102
+ { object: object._refs[i] },
103
+ ],
104
+ ")",
105
+ ],
106
+ ]
107
+ : []
108
+ : []),
109
+ ]),
110
+ ];
111
+ }
112
+ },
113
+ },
114
+ ];
115
+ //# sourceMappingURL=devtoolsFormatters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtoolsFormatters.js","sourceRoot":"","sources":["../../../src/implementation/devtoolsFormatters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvC,UAAkB,CAAC,kBAAkB,GAAG;IACrC;QACI,MAAM,EAAE,CAAC,MAAW,EAAE,EAAE;YACpB,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;gBAC3B,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACnC,OAAO;oBACH,KAAK;oBACL,EAAE;oBACF;wBACI,MAAM;wBACN,EAAE;wBACF,MAAM,CAAC,WAAW,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI;qBACvD;iBACJ,CAAC;YACN,CAAC;iBAAM,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACpC,OAAO;oBACH,KAAK;oBACL,EAAE;oBACF;wBACI,MAAM;wBACN,EAAE;wBACF,MAAM,CAAC,WAAW,CAAC,IAAI;4BACnB,GAAG;4BACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI;4BAChC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;4BAC1B,GAAG;qBACV;iBACJ,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,EAAE;YACL,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,EAA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AAQ,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;oBAClD,GAAI,MAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;wBAC/B,KAAK;wBACL,EAAE,KAAK,EAAE,sBAAsB,EAAE;wBACjC;4BACI,MAAM;4BACN,EAAE,KAAK,EAAE,iCAAiC,EAAE;4BAC5C,CAAC;4BACD,IAAI;yBACP;wBACD,CAAC,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/implementation/errors.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export const inspect = Symbol.for("nodejs.util.inspect.custom");
2
+ //# sourceMappingURL=inspect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../../src/implementation/inspect.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { instantiateRefEncoded, isRefEncoded, subscriptionsScopes, } from "../internal.js";
2
+ const refCache = new WeakMap();
3
+ const TRACE_ACCESSES = false;
4
+ export class Ref {
5
+ id;
6
+ controlledAccount;
7
+ schema;
8
+ constructor(id, controlledAccount, schema) {
9
+ this.id = id;
10
+ this.controlledAccount = controlledAccount;
11
+ this.schema = schema;
12
+ if (!isRefEncoded(schema)) {
13
+ throw new Error("Ref must be constructed with a ref schema");
14
+ }
15
+ }
16
+ get value() {
17
+ const node = "node" in this.controlledAccount
18
+ ? this.controlledAccount.node
19
+ : this.controlledAccount._raw.core.node;
20
+ const raw = node.getLoaded(this.id);
21
+ if (raw) {
22
+ let value = refCache.get(raw);
23
+ if (value) {
24
+ // console.log("Using cached value for " + this.id);
25
+ }
26
+ else {
27
+ value = instantiateRefEncoded(this.schema, raw);
28
+ refCache.set(raw, value);
29
+ }
30
+ return value;
31
+ }
32
+ else {
33
+ return null;
34
+ }
35
+ }
36
+ async loadHelper(options) {
37
+ const node = "node" in this.controlledAccount
38
+ ? this.controlledAccount.node
39
+ : this.controlledAccount._raw.core.node;
40
+ const raw = await node.load(this.id, options?.onProgress);
41
+ if (raw === "unavailable") {
42
+ return "unavailable";
43
+ }
44
+ else {
45
+ return new Ref(this.id, this.controlledAccount, this.schema).value;
46
+ }
47
+ }
48
+ async load(options) {
49
+ const result = await this.loadHelper(options);
50
+ if (result === "unavailable") {
51
+ return undefined;
52
+ }
53
+ else {
54
+ return result;
55
+ }
56
+ }
57
+ accessFrom(fromScopeValue, key) {
58
+ const subScope = subscriptionsScopes.get(fromScopeValue);
59
+ subScope?.onRefAccessedOrSet(fromScopeValue.id, this.id);
60
+ TRACE_ACCESSES &&
61
+ console.log(subScope?.scopeID, "accessing", fromScopeValue, key, this.id);
62
+ if (this.value && subScope) {
63
+ subscriptionsScopes.set(this.value, subScope);
64
+ }
65
+ if (subScope) {
66
+ const cached = subScope.cachedValues[this.id];
67
+ if (cached) {
68
+ TRACE_ACCESSES && console.log("cached", cached);
69
+ return cached;
70
+ }
71
+ else if (this.value !== null) {
72
+ const freshValueInstance = instantiateRefEncoded(this.schema, this.value?._raw);
73
+ TRACE_ACCESSES &&
74
+ console.log("freshValueInstance", freshValueInstance);
75
+ subScope.cachedValues[this.id] = freshValueInstance;
76
+ subscriptionsScopes.set(freshValueInstance, subScope);
77
+ return freshValueInstance;
78
+ }
79
+ else {
80
+ return null;
81
+ }
82
+ }
83
+ else {
84
+ return this.value;
85
+ }
86
+ }
87
+ }
88
+ export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, refSchemaForKey) {
89
+ const refs = {};
90
+ return new Proxy(refs, {
91
+ get(_target, key) {
92
+ if (key === Symbol.iterator) {
93
+ return function* () {
94
+ for (const key of getKeysWithIds()) {
95
+ yield new Ref(getIdForKey(key), controlledAccount, refSchemaForKey(key));
96
+ }
97
+ };
98
+ }
99
+ if (typeof key === "symbol")
100
+ return undefined;
101
+ if (key === "length") {
102
+ return getKeysWithIds().length;
103
+ }
104
+ const id = getIdForKey(key);
105
+ if (!id)
106
+ return undefined;
107
+ return new Ref(id, controlledAccount, refSchemaForKey(key));
108
+ },
109
+ ownKeys() {
110
+ return getKeysWithIds().map((key) => key.toString());
111
+ },
112
+ getOwnPropertyDescriptor(target, key) {
113
+ const id = getIdForKey(key);
114
+ if (id) {
115
+ return {
116
+ enumerable: true,
117
+ configurable: true,
118
+ writable: true,
119
+ };
120
+ }
121
+ else {
122
+ return Reflect.getOwnPropertyDescriptor(target, key);
123
+ }
124
+ },
125
+ });
126
+ }
127
+ //# sourceMappingURL=refs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs.js","sourceRoot":"","sources":["../../../src/implementation/refs.ts"],"names":[],"mappings":"AASA,OAAO,EACH,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA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C;YAC9C,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;gBACnB,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,GAAG,CACV,EAAiB,EACjB,iBAAiB,EACjB,eAAe,CAAC,GAAW,CAAC,CAC/B,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;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"}
@@ -0,0 +1,91 @@
1
+ import { isCoValueClass, } from "../internal.js";
2
+ const optional = {
3
+ ref: optionalRef,
4
+ json() {
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ return { [SchemaInit]: "json" };
7
+ },
8
+ encoded(arg) {
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ return { [SchemaInit]: { encoded: arg } };
11
+ },
12
+ string: {
13
+ [SchemaInit]: "json",
14
+ },
15
+ number: {
16
+ [SchemaInit]: "json",
17
+ },
18
+ boolean: {
19
+ [SchemaInit]: "json",
20
+ },
21
+ null: {
22
+ [SchemaInit]: "json",
23
+ },
24
+ literal(..._lit) {
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ return { [SchemaInit]: "json" };
27
+ },
28
+ };
29
+ /** @category Schema definition */
30
+ export const co = {
31
+ string: {
32
+ [SchemaInit]: "json",
33
+ },
34
+ number: {
35
+ [SchemaInit]: "json",
36
+ },
37
+ boolean: {
38
+ [SchemaInit]: "json",
39
+ },
40
+ null: {
41
+ [SchemaInit]: "json",
42
+ },
43
+ literal(..._lit) {
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ return { [SchemaInit]: "json" };
46
+ },
47
+ json() {
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ return { [SchemaInit]: "json" };
50
+ },
51
+ encoded(arg) {
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ return { [SchemaInit]: { encoded: arg } };
54
+ },
55
+ ref,
56
+ items: ItemsSym,
57
+ members: MembersSym,
58
+ optional,
59
+ };
60
+ function optionalRef(arg) {
61
+ return ref(arg, { optional: true });
62
+ }
63
+ function ref(arg, options) {
64
+ return {
65
+ [SchemaInit]: {
66
+ ref: arg,
67
+ optional: options?.optional || false,
68
+ },
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ };
71
+ }
72
+ export function isRefEncoded(schema) {
73
+ return (typeof schema === "object" &&
74
+ "ref" in schema &&
75
+ "optional" in schema &&
76
+ typeof schema.ref === "function");
77
+ }
78
+ export function instantiateRefEncoded(schema, raw) {
79
+ return isCoValueClass(schema.ref)
80
+ ? schema.ref.fromRaw(raw)
81
+ : schema.ref(raw).fromRaw(raw);
82
+ }
83
+ import { SchemaInit, ItemsSym, MembersSym } from "./symbols.js";
84
+ /** @category Schema definition */
85
+ export const Encoders = {
86
+ Date: {
87
+ encode: (value) => value.toISOString(),
88
+ decode: (value) => new Date(value),
89
+ },
90
+ };
91
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/implementation/schema.ts"],"names":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