@xyo-network/module-abstract 2.111.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/dist/neutral/index.d.ts +221 -6
  2. package/package.json +23 -42
  3. package/xy.config.ts +12 -0
  4. package/dist/browser/AbstractModule.d.cts +0 -104
  5. package/dist/browser/AbstractModule.d.cts.map +0 -1
  6. package/dist/browser/AbstractModule.d.mts +0 -104
  7. package/dist/browser/AbstractModule.d.mts.map +0 -1
  8. package/dist/browser/AbstractModule.d.ts +0 -104
  9. package/dist/browser/AbstractModule.d.ts.map +0 -1
  10. package/dist/browser/AbstractModuleInstance.d.cts +0 -54
  11. package/dist/browser/AbstractModuleInstance.d.cts.map +0 -1
  12. package/dist/browser/AbstractModuleInstance.d.mts +0 -54
  13. package/dist/browser/AbstractModuleInstance.d.mts.map +0 -1
  14. package/dist/browser/AbstractModuleInstance.d.ts +0 -54
  15. package/dist/browser/AbstractModuleInstance.d.ts.map +0 -1
  16. package/dist/browser/BaseEmitter.d.cts +0 -17
  17. package/dist/browser/BaseEmitter.d.cts.map +0 -1
  18. package/dist/browser/BaseEmitter.d.mts +0 -17
  19. package/dist/browser/BaseEmitter.d.mts.map +0 -1
  20. package/dist/browser/BaseEmitter.d.ts +0 -17
  21. package/dist/browser/BaseEmitter.d.ts.map +0 -1
  22. package/dist/browser/Error.d.cts +0 -19
  23. package/dist/browser/Error.d.cts.map +0 -1
  24. package/dist/browser/Error.d.mts +0 -19
  25. package/dist/browser/Error.d.mts.map +0 -1
  26. package/dist/browser/Error.d.ts +0 -19
  27. package/dist/browser/Error.d.ts.map +0 -1
  28. package/dist/browser/QueryValidator/ModuleConfigQueryValidator.d.cts +0 -17
  29. package/dist/browser/QueryValidator/ModuleConfigQueryValidator.d.cts.map +0 -1
  30. package/dist/browser/QueryValidator/ModuleConfigQueryValidator.d.mts +0 -17
  31. package/dist/browser/QueryValidator/ModuleConfigQueryValidator.d.mts.map +0 -1
  32. package/dist/browser/QueryValidator/ModuleConfigQueryValidator.d.ts +0 -17
  33. package/dist/browser/QueryValidator/ModuleConfigQueryValidator.d.ts.map +0 -1
  34. package/dist/browser/QueryValidator/QueryValidator.d.cts +0 -8
  35. package/dist/browser/QueryValidator/QueryValidator.d.cts.map +0 -1
  36. package/dist/browser/QueryValidator/QueryValidator.d.mts +0 -8
  37. package/dist/browser/QueryValidator/QueryValidator.d.mts.map +0 -1
  38. package/dist/browser/QueryValidator/QueryValidator.d.ts +0 -8
  39. package/dist/browser/QueryValidator/QueryValidator.d.ts.map +0 -1
  40. package/dist/browser/QueryValidator/SupportedQueryValidator.d.cts +0 -18
  41. package/dist/browser/QueryValidator/SupportedQueryValidator.d.cts.map +0 -1
  42. package/dist/browser/QueryValidator/SupportedQueryValidator.d.mts +0 -18
  43. package/dist/browser/QueryValidator/SupportedQueryValidator.d.mts.map +0 -1
  44. package/dist/browser/QueryValidator/SupportedQueryValidator.d.ts +0 -18
  45. package/dist/browser/QueryValidator/SupportedQueryValidator.d.ts.map +0 -1
  46. package/dist/browser/QueryValidator/index.d.cts +0 -4
  47. package/dist/browser/QueryValidator/index.d.cts.map +0 -1
  48. package/dist/browser/QueryValidator/index.d.mts +0 -4
  49. package/dist/browser/QueryValidator/index.d.mts.map +0 -1
  50. package/dist/browser/QueryValidator/index.d.ts +0 -4
  51. package/dist/browser/QueryValidator/index.d.ts.map +0 -1
  52. package/dist/browser/determineAccount.d.cts +0 -14
  53. package/dist/browser/determineAccount.d.cts.map +0 -1
  54. package/dist/browser/determineAccount.d.mts +0 -14
  55. package/dist/browser/determineAccount.d.mts.map +0 -1
  56. package/dist/browser/determineAccount.d.ts +0 -14
  57. package/dist/browser/determineAccount.d.ts.map +0 -1
  58. package/dist/browser/index.cjs +0 -1069
  59. package/dist/browser/index.cjs.map +0 -1
  60. package/dist/browser/index.d.cts +0 -6
  61. package/dist/browser/index.d.cts.map +0 -1
  62. package/dist/browser/index.d.mts +0 -6
  63. package/dist/browser/index.d.mts.map +0 -1
  64. package/dist/browser/index.d.ts +0 -6
  65. package/dist/browser/index.d.ts.map +0 -1
  66. package/dist/browser/index.mjs +0 -1048
  67. package/dist/browser/index.mjs.map +0 -1
  68. package/dist/neutral/AbstractModule.d.cts +0 -104
  69. package/dist/neutral/AbstractModule.d.cts.map +0 -1
  70. package/dist/neutral/AbstractModule.d.mts +0 -104
  71. package/dist/neutral/AbstractModule.d.mts.map +0 -1
  72. package/dist/neutral/AbstractModule.d.ts +0 -104
  73. package/dist/neutral/AbstractModule.d.ts.map +0 -1
  74. package/dist/neutral/AbstractModuleInstance.d.cts +0 -54
  75. package/dist/neutral/AbstractModuleInstance.d.cts.map +0 -1
  76. package/dist/neutral/AbstractModuleInstance.d.mts +0 -54
  77. package/dist/neutral/AbstractModuleInstance.d.mts.map +0 -1
  78. package/dist/neutral/AbstractModuleInstance.d.ts +0 -54
  79. package/dist/neutral/AbstractModuleInstance.d.ts.map +0 -1
  80. package/dist/neutral/BaseEmitter.d.cts +0 -17
  81. package/dist/neutral/BaseEmitter.d.cts.map +0 -1
  82. package/dist/neutral/BaseEmitter.d.mts +0 -17
  83. package/dist/neutral/BaseEmitter.d.mts.map +0 -1
  84. package/dist/neutral/BaseEmitter.d.ts +0 -17
  85. package/dist/neutral/BaseEmitter.d.ts.map +0 -1
  86. package/dist/neutral/Error.d.cts +0 -19
  87. package/dist/neutral/Error.d.cts.map +0 -1
  88. package/dist/neutral/Error.d.mts +0 -19
  89. package/dist/neutral/Error.d.mts.map +0 -1
  90. package/dist/neutral/Error.d.ts +0 -19
  91. package/dist/neutral/Error.d.ts.map +0 -1
  92. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.cts +0 -17
  93. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.cts.map +0 -1
  94. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.mts +0 -17
  95. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.mts.map +0 -1
  96. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.ts +0 -17
  97. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.ts.map +0 -1
  98. package/dist/neutral/QueryValidator/QueryValidator.d.cts +0 -8
  99. package/dist/neutral/QueryValidator/QueryValidator.d.cts.map +0 -1
  100. package/dist/neutral/QueryValidator/QueryValidator.d.mts +0 -8
  101. package/dist/neutral/QueryValidator/QueryValidator.d.mts.map +0 -1
  102. package/dist/neutral/QueryValidator/QueryValidator.d.ts +0 -8
  103. package/dist/neutral/QueryValidator/QueryValidator.d.ts.map +0 -1
  104. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.cts +0 -18
  105. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.cts.map +0 -1
  106. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.mts +0 -18
  107. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.mts.map +0 -1
  108. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.ts +0 -18
  109. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.ts.map +0 -1
  110. package/dist/neutral/QueryValidator/index.d.cts +0 -4
  111. package/dist/neutral/QueryValidator/index.d.cts.map +0 -1
  112. package/dist/neutral/QueryValidator/index.d.mts +0 -4
  113. package/dist/neutral/QueryValidator/index.d.mts.map +0 -1
  114. package/dist/neutral/QueryValidator/index.d.ts +0 -4
  115. package/dist/neutral/QueryValidator/index.d.ts.map +0 -1
  116. package/dist/neutral/determineAccount.d.cts +0 -14
  117. package/dist/neutral/determineAccount.d.cts.map +0 -1
  118. package/dist/neutral/determineAccount.d.mts +0 -14
  119. package/dist/neutral/determineAccount.d.mts.map +0 -1
  120. package/dist/neutral/determineAccount.d.ts +0 -14
  121. package/dist/neutral/determineAccount.d.ts.map +0 -1
  122. package/dist/neutral/index.cjs +0 -1069
  123. package/dist/neutral/index.cjs.map +0 -1
  124. package/dist/neutral/index.d.cts +0 -6
  125. package/dist/neutral/index.d.cts.map +0 -1
  126. package/dist/neutral/index.d.mts +0 -6
  127. package/dist/neutral/index.d.mts.map +0 -1
  128. package/dist/neutral/index.d.ts.map +0 -1
  129. package/dist/node/AbstractModule.d.cts +0 -104
  130. package/dist/node/AbstractModule.d.cts.map +0 -1
  131. package/dist/node/AbstractModule.d.mts +0 -104
  132. package/dist/node/AbstractModule.d.mts.map +0 -1
  133. package/dist/node/AbstractModule.d.ts +0 -104
  134. package/dist/node/AbstractModule.d.ts.map +0 -1
  135. package/dist/node/AbstractModuleInstance.d.cts +0 -54
  136. package/dist/node/AbstractModuleInstance.d.cts.map +0 -1
  137. package/dist/node/AbstractModuleInstance.d.mts +0 -54
  138. package/dist/node/AbstractModuleInstance.d.mts.map +0 -1
  139. package/dist/node/AbstractModuleInstance.d.ts +0 -54
  140. package/dist/node/AbstractModuleInstance.d.ts.map +0 -1
  141. package/dist/node/BaseEmitter.d.cts +0 -17
  142. package/dist/node/BaseEmitter.d.cts.map +0 -1
  143. package/dist/node/BaseEmitter.d.mts +0 -17
  144. package/dist/node/BaseEmitter.d.mts.map +0 -1
  145. package/dist/node/BaseEmitter.d.ts +0 -17
  146. package/dist/node/BaseEmitter.d.ts.map +0 -1
  147. package/dist/node/Error.d.cts +0 -19
  148. package/dist/node/Error.d.cts.map +0 -1
  149. package/dist/node/Error.d.mts +0 -19
  150. package/dist/node/Error.d.mts.map +0 -1
  151. package/dist/node/Error.d.ts +0 -19
  152. package/dist/node/Error.d.ts.map +0 -1
  153. package/dist/node/QueryValidator/ModuleConfigQueryValidator.d.cts +0 -17
  154. package/dist/node/QueryValidator/ModuleConfigQueryValidator.d.cts.map +0 -1
  155. package/dist/node/QueryValidator/ModuleConfigQueryValidator.d.mts +0 -17
  156. package/dist/node/QueryValidator/ModuleConfigQueryValidator.d.mts.map +0 -1
  157. package/dist/node/QueryValidator/ModuleConfigQueryValidator.d.ts +0 -17
  158. package/dist/node/QueryValidator/ModuleConfigQueryValidator.d.ts.map +0 -1
  159. package/dist/node/QueryValidator/QueryValidator.d.cts +0 -8
  160. package/dist/node/QueryValidator/QueryValidator.d.cts.map +0 -1
  161. package/dist/node/QueryValidator/QueryValidator.d.mts +0 -8
  162. package/dist/node/QueryValidator/QueryValidator.d.mts.map +0 -1
  163. package/dist/node/QueryValidator/QueryValidator.d.ts +0 -8
  164. package/dist/node/QueryValidator/QueryValidator.d.ts.map +0 -1
  165. package/dist/node/QueryValidator/SupportedQueryValidator.d.cts +0 -18
  166. package/dist/node/QueryValidator/SupportedQueryValidator.d.cts.map +0 -1
  167. package/dist/node/QueryValidator/SupportedQueryValidator.d.mts +0 -18
  168. package/dist/node/QueryValidator/SupportedQueryValidator.d.mts.map +0 -1
  169. package/dist/node/QueryValidator/SupportedQueryValidator.d.ts +0 -18
  170. package/dist/node/QueryValidator/SupportedQueryValidator.d.ts.map +0 -1
  171. package/dist/node/QueryValidator/index.d.cts +0 -4
  172. package/dist/node/QueryValidator/index.d.cts.map +0 -1
  173. package/dist/node/QueryValidator/index.d.mts +0 -4
  174. package/dist/node/QueryValidator/index.d.mts.map +0 -1
  175. package/dist/node/QueryValidator/index.d.ts +0 -4
  176. package/dist/node/QueryValidator/index.d.ts.map +0 -1
  177. package/dist/node/determineAccount.d.cts +0 -14
  178. package/dist/node/determineAccount.d.cts.map +0 -1
  179. package/dist/node/determineAccount.d.mts +0 -14
  180. package/dist/node/determineAccount.d.mts.map +0 -1
  181. package/dist/node/determineAccount.d.ts +0 -14
  182. package/dist/node/determineAccount.d.ts.map +0 -1
  183. package/dist/node/index.cjs +0 -1099
  184. package/dist/node/index.cjs.map +0 -1
  185. package/dist/node/index.d.cts +0 -6
  186. package/dist/node/index.d.cts.map +0 -1
  187. package/dist/node/index.d.mts +0 -6
  188. package/dist/node/index.d.mts.map +0 -1
  189. package/dist/node/index.d.ts +0 -6
  190. package/dist/node/index.d.ts.map +0 -1
  191. package/dist/node/index.mjs +0 -1068
  192. package/dist/node/index.mjs.map +0 -1
@@ -1,1099 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
-
23
- // src/index.ts
24
- var src_exports = {};
25
- __export(src_exports, {
26
- AbstractModule: () => AbstractModule,
27
- AbstractModuleInstance: () => AbstractModuleInstance,
28
- BaseEmitter: () => BaseEmitter,
29
- ModuleConfigQueryValidator: () => ModuleConfigQueryValidator,
30
- ModuleErrorBuilder: () => ModuleErrorBuilder,
31
- SupportedQueryValidator: () => SupportedQueryValidator,
32
- isQuerySupportedByModule: () => isQuerySupportedByModule
33
- });
34
- module.exports = __toCommonJS(src_exports);
35
-
36
- // src/AbstractModule.ts
37
- var import_assert2 = require("@xylabs/assert");
38
- var import_error = require("@xylabs/error");
39
- var import_exists = require("@xylabs/exists");
40
- var import_forget = require("@xylabs/forget");
41
- var import_lodash = require("@xylabs/lodash");
42
- var import_logger = require("@xylabs/logger");
43
- var import_object2 = require("@xylabs/object");
44
- var import_promise = require("@xylabs/promise");
45
- var import_account2 = require("@xyo-network/account");
46
- var import_archivist_model = require("@xyo-network/archivist-model");
47
- var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
48
- var import_boundwitness_wrapper3 = require("@xyo-network/boundwitness-wrapper");
49
- var import_config_payload_plugin = require("@xyo-network/config-payload-plugin");
50
- var import_module_model = require("@xyo-network/module-model");
51
- var import_payload_builder2 = require("@xyo-network/payload-builder");
52
- var import_query_payload_plugin = require("@xyo-network/query-payload-plugin");
53
- var import_lru_cache = require("lru-cache");
54
-
55
- // src/BaseEmitter.ts
56
- var import_object = require("@xylabs/object");
57
- var import_module_events = require("@xyo-network/module-events");
58
- var _BaseEmitter = class _BaseEmitter extends import_object.Base {
59
- // just here to query types
60
- eventData = {};
61
- events;
62
- constructor(params) {
63
- super(params);
64
- this.events = new import_module_events.Events();
65
- }
66
- clearListeners(eventNames) {
67
- return this.events.clearListeners(eventNames);
68
- }
69
- emit(eventName, eventArgs) {
70
- return this.events.emit(eventName, eventArgs);
71
- }
72
- emitSerial(eventName, eventArgs) {
73
- return this.events.emitSerial(eventName, eventArgs);
74
- }
75
- listenerCount(eventNames) {
76
- return this.events.listenerCount(eventNames);
77
- }
78
- off(eventNames, listener) {
79
- return this.events.off(eventNames, listener);
80
- }
81
- offAny(listener) {
82
- return this.events.offAny(listener);
83
- }
84
- on(eventNames, listener) {
85
- return this.events.on(eventNames, listener);
86
- }
87
- onAny(listener) {
88
- return this.events.onAny(listener);
89
- }
90
- once(eventName, listener) {
91
- return this.events.once(eventName, listener);
92
- }
93
- };
94
- __name(_BaseEmitter, "BaseEmitter");
95
- var BaseEmitter = _BaseEmitter;
96
-
97
- // src/determineAccount.ts
98
- var import_assert = require("@xylabs/assert");
99
- var import_account = require("@xyo-network/account");
100
- var isDetermineAccountFromAccountParams = /* @__PURE__ */ __name((params) => {
101
- (0, import_assert.assertEx)(!params.accountPath, () => "accountPath may not be provided when account is provided");
102
- return !!params.account;
103
- }, "isDetermineAccountFromAccountParams");
104
- var isDetermineAccountFromWalletParams = /* @__PURE__ */ __name((params) => {
105
- return !!params.wallet;
106
- }, "isDetermineAccountFromWalletParams");
107
- async function determineAccount(params, allowRandomAccount = true) {
108
- if (isDetermineAccountFromAccountParams(params)) {
109
- if (params.account === "random") {
110
- (0, import_assert.assertEx)(allowRandomAccount, () => "Random address not allowed");
111
- return await import_account.Account.random();
112
- }
113
- return params.account;
114
- }
115
- if (isDetermineAccountFromWalletParams(params)) {
116
- return (0, import_assert.assertEx)(params.accountPath ? await params.wallet.derivePath(params.accountPath) : params.wallet, () => "Failed to derive account from path");
117
- }
118
- console.warn("AbstractModule.determineAccount: No account or wallet provided - Creating Random account");
119
- return await import_account.Account.random();
120
- }
121
- __name(determineAccount, "determineAccount");
122
-
123
- // src/Error.ts
124
- var import_payload_builder = require("@xyo-network/payload-builder");
125
- var import_payload_model = require("@xyo-network/payload-model");
126
- var _ModuleErrorBuilder = class _ModuleErrorBuilder extends import_payload_builder.PayloadBuilder {
127
- _details;
128
- _message;
129
- _name;
130
- _query;
131
- _sources;
132
- constructor() {
133
- super({
134
- schema: import_payload_model.ModuleErrorSchema
135
- });
136
- }
137
- build() {
138
- this.fields({
139
- details: this._details,
140
- message: this._message,
141
- name: this._name,
142
- query: this._query,
143
- schema: import_payload_model.ModuleErrorSchema,
144
- sources: this._sources
145
- });
146
- return super.build();
147
- }
148
- details(details) {
149
- this._details = details;
150
- return this;
151
- }
152
- message(message) {
153
- this._message = message;
154
- return this;
155
- }
156
- name(name) {
157
- this._name = name;
158
- return this;
159
- }
160
- query(query) {
161
- this._query = query;
162
- return this;
163
- }
164
- sources(sources) {
165
- this._sources = sources;
166
- return this;
167
- }
168
- };
169
- __name(_ModuleErrorBuilder, "ModuleErrorBuilder");
170
- var ModuleErrorBuilder = _ModuleErrorBuilder;
171
-
172
- // src/QueryValidator/ModuleConfigQueryValidator.ts
173
- var import_boundwitness_wrapper = require("@xyo-network/boundwitness-wrapper");
174
- var delimiter = "";
175
- var _ModuleConfigQueryValidator = class _ModuleConfigQueryValidator {
176
- allowed = {};
177
- disallowed = {};
178
- hasAllowedRules;
179
- hasDisallowedRules;
180
- hasRules;
181
- constructor(config) {
182
- var _a, _b, _c, _d;
183
- if ((_a = config == null ? void 0 : config.security) == null ? void 0 : _a.allowed) {
184
- for (const [schema, addresses] of Object.entries((_b = config.security) == null ? void 0 : _b.allowed)) {
185
- this.allowed[schema] = addresses.map(toAddressesString);
186
- }
187
- }
188
- if ((_c = config == null ? void 0 : config.security) == null ? void 0 : _c.disallowed) {
189
- for (const [schema, addresses] of Object.entries((_d = config.security) == null ? void 0 : _d.disallowed)) {
190
- this.disallowed[schema] = addresses.map(toAddressesString);
191
- }
192
- }
193
- this.hasAllowedRules = Object.keys(this.allowed).length > 0;
194
- this.hasDisallowedRules = Object.keys(this.disallowed).length > 0;
195
- this.hasRules = this.hasAllowedRules || this.hasDisallowedRules;
196
- }
197
- queryable = /* @__PURE__ */ __name(async (query, payloads) => {
198
- if (!this.hasRules) return true;
199
- const addresses = query.addresses;
200
- if (addresses.length === 0) return false;
201
- const wrapper = await import_boundwitness_wrapper.QueryBoundWitnessWrapper.parseQuery(query, payloads);
202
- const schema = (await wrapper.getQuery()).schema;
203
- return this.queryAllowed(schema, addresses) && !this.queryDisallowed(schema, addresses);
204
- }, "queryable");
205
- queryAllowed = /* @__PURE__ */ __name((schema, addresses) => {
206
- var _a, _b;
207
- if (!this.hasAllowedRules) return true;
208
- if (addresses.length > 1) {
209
- const signatories = toAddressesString(addresses);
210
- const validCosigners = (_b = (_a = this.allowed) == null ? void 0 : _a[schema]) == null ? void 0 : _b.includes(signatories);
211
- if (validCosigners) return true;
212
- }
213
- return addresses.every((address) => {
214
- var _a2, _b2;
215
- return ((_b2 = (_a2 = this.allowed) == null ? void 0 : _a2[schema]) == null ? void 0 : _b2.includes(address)) || false;
216
- });
217
- }, "queryAllowed");
218
- queryDisallowed = /* @__PURE__ */ __name((schema, addresses) => {
219
- if (!this.hasDisallowedRules) return false;
220
- return addresses.some((address) => {
221
- var _a, _b;
222
- return (_b = (_a = this.disallowed) == null ? void 0 : _a[schema]) == null ? void 0 : _b.includes(address);
223
- });
224
- }, "queryDisallowed");
225
- };
226
- __name(_ModuleConfigQueryValidator, "ModuleConfigQueryValidator");
227
- var ModuleConfigQueryValidator = _ModuleConfigQueryValidator;
228
- var toAddressesString = /* @__PURE__ */ __name((addresses) => {
229
- return Array.isArray(addresses) ? addresses.sort().map((address) => address.toLowerCase()).join(delimiter) : addresses.toLowerCase();
230
- }, "toAddressesString");
231
-
232
- // src/QueryValidator/SupportedQueryValidator.ts
233
- var import_boundwitness_wrapper2 = require("@xyo-network/boundwitness-wrapper");
234
- var isQuerySupportedByModule = /* @__PURE__ */ __name(async (mod, query, payloads) => {
235
- const wrapper = await import_boundwitness_wrapper2.QueryBoundWitnessWrapper.parseQuery(query, payloads);
236
- const schema = (await wrapper.getQuery()).schema;
237
- return mod.queries.includes(schema);
238
- }, "isQuerySupportedByModule");
239
- var _SupportedQueryValidator = class _SupportedQueryValidator {
240
- mod;
241
- constructor(mod) {
242
- this.mod = mod;
243
- this.queryable = (query, payloads) => {
244
- return isQuerySupportedByModule(this.mod, query, payloads);
245
- };
246
- }
247
- queryable;
248
- };
249
- __name(_SupportedQueryValidator, "SupportedQueryValidator");
250
- var SupportedQueryValidator = _SupportedQueryValidator;
251
-
252
- // src/AbstractModule.ts
253
- var MODULE_NOT_STARTED = "Module not Started";
254
- var _AbstractModule = class _AbstractModule extends BaseEmitter {
255
- _account;
256
- // cache manifest based on maxDepth
257
- _cachedManifests = new import_lru_cache.LRUCache({
258
- max: 10,
259
- ttl: 1e3 * 60 * 5
260
- });
261
- _lastError;
262
- _startPromise = void 0;
263
- _started = void 0;
264
- moduleConfigQueryValidator;
265
- supportedQueryValidator;
266
- _busyCount = 0;
267
- _logger = void 0;
268
- _status = "stopped";
269
- constructor(privateConstructorKey, params, account) {
270
- (0, import_assert2.assertEx)(_AbstractModule.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
271
- const mutatedParams = {
272
- ...params
273
- };
274
- super(mutatedParams);
275
- this._account = account;
276
- this.supportedQueryValidator = new SupportedQueryValidator(this).queryable;
277
- this.moduleConfigQueryValidator = new ModuleConfigQueryValidator(mutatedParams == null ? void 0 : mutatedParams.config).queryable;
278
- }
279
- get account() {
280
- return (0, import_assert2.assertEx)(this._account, () => "Missing account");
281
- }
282
- get additionalSigners() {
283
- return this.params.additionalSigners ?? [];
284
- }
285
- get address() {
286
- var _a;
287
- return (_a = this._account) == null ? void 0 : _a.address;
288
- }
289
- get allowAnonymous() {
290
- var _a;
291
- return !!((_a = this.config.security) == null ? void 0 : _a.allowAnonymous);
292
- }
293
- get allowNameResolution() {
294
- return this.params.allowNameResolution ?? true;
295
- }
296
- get archiving() {
297
- return this.config.archiving;
298
- }
299
- get archivist() {
300
- return this.config.archivist;
301
- }
302
- get config() {
303
- return this.params.config;
304
- }
305
- get dead() {
306
- return this.status === "dead";
307
- }
308
- get ephemeralQueryAccountEnabled() {
309
- return !!this.params.ephemeralQueryAccountEnabled;
310
- }
311
- get id() {
312
- return this.modName ?? this.address;
313
- }
314
- get logger() {
315
- var _a;
316
- const consoleLogger = this.config.consoleLogger;
317
- this._logger = this._logger ?? consoleLogger ? new import_logger.ConsoleLogger(consoleLogger) : ((_a = this.params) == null ? void 0 : _a.logger) ?? _AbstractModule.defaultLogger ?? import_object2.Base.defaultLogger;
318
- return this._logger;
319
- }
320
- get modName() {
321
- return this.config.name;
322
- }
323
- get priority() {
324
- return import_module_model.ObjectResolverPriority.Normal;
325
- }
326
- get queries() {
327
- return [
328
- import_module_model.ModuleAddressQuerySchema,
329
- import_module_model.ModuleSubscribeQuerySchema,
330
- import_module_model.ModuleManifestQuerySchema,
331
- import_module_model.ModuleStateQuerySchema
332
- ];
333
- }
334
- get status() {
335
- return this._status;
336
- }
337
- get timestamp() {
338
- return this.config.timestamp ?? false;
339
- }
340
- set status(value) {
341
- if (this._status !== "dead") {
342
- this._status = value;
343
- }
344
- }
345
- static _getRootFunction(funcName) {
346
- let anyThis = this;
347
- while (anyThis.__proto__[funcName]) {
348
- anyThis = anyThis.__proto__;
349
- }
350
- return anyThis[funcName];
351
- }
352
- static _noOverride(functionName) {
353
- const thisFunc = this[functionName];
354
- const rootFunc = this._getRootFunction(functionName);
355
- (0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
356
- }
357
- static async create(params) {
358
- var _a, _b, _c, _d, _e, _f;
359
- this._noOverride("create");
360
- if (!this.configSchemas || this.configSchemas.length === 0) {
361
- throw new Error(`Missing configSchema [${(_a = params == null ? void 0 : params.config) == null ? void 0 : _a.schema}][${this.name}]`);
362
- }
363
- if (!this.defaultConfigSchema) {
364
- throw new Error(`Missing defaultConfigSchema [${(_b = params == null ? void 0 : params.config) == null ? void 0 : _b.schema}][${this.name}]`);
365
- }
366
- (0, import_assert2.assertEx)(((_c = params == null ? void 0 : params.config) == null ? void 0 : _c.name) === void 0 || (0, import_module_model.isModuleName)(params.config.name), () => {
367
- var _a2;
368
- return `Invalid module name: ${(_a2 = params == null ? void 0 : params.config) == null ? void 0 : _a2.name}`;
369
- });
370
- const { account } = params ?? {};
371
- const schema = ((_d = params == null ? void 0 : params.config) == null ? void 0 : _d.schema) ?? this.defaultConfigSchema;
372
- const allowedSchemas = this.configSchemas;
373
- (0, import_assert2.assertEx)(allowedSchemas.includes(schema), () => `Bad Config Schema [Received ${schema}] [Expected ${JSON.stringify(allowedSchemas)}]`);
374
- const mutatedConfig = {
375
- ...params == null ? void 0 : params.config,
376
- schema
377
- };
378
- (_e = params == null ? void 0 : params.logger) == null ? void 0 : _e.debug(`config: ${JSON.stringify(mutatedConfig, null, 2)}`);
379
- const mutatedParams = {
380
- ...params,
381
- config: mutatedConfig
382
- };
383
- const activeLogger = (params == null ? void 0 : params.logger) ?? _AbstractModule.defaultLogger;
384
- const generatedAccount = await _AbstractModule.determineAccount({
385
- account
386
- });
387
- const address = generatedAccount.address;
388
- mutatedParams.logger = activeLogger ? new import_logger.IdLogger(activeLogger, () => `0x${address}`) : void 0;
389
- const newModule = new this(_AbstractModule.privateConstructorKey, mutatedParams, generatedAccount, address);
390
- if (!_AbstractModule.enableLazyLoad) {
391
- await ((_f = newModule.start) == null ? void 0 : _f.call(newModule));
392
- }
393
- return newModule;
394
- }
395
- static async determineAccount(params) {
396
- return await determineAccount(params, this.allowRandomAccount);
397
- }
398
- static factory(params) {
399
- return import_module_model.ModuleFactory.withParams(this, params);
400
- }
401
- _getRootFunction(funcName) {
402
- let anyThis = this;
403
- while (anyThis.__proto__[funcName]) {
404
- anyThis = anyThis.__proto__;
405
- }
406
- return anyThis[funcName];
407
- }
408
- async busy(closure) {
409
- if (this._busyCount <= 0) {
410
- this._busyCount = 0;
411
- const args = {
412
- busy: true,
413
- mod: this
414
- };
415
- await this.emit("moduleBusy", args);
416
- }
417
- this._busyCount++;
418
- try {
419
- return await closure();
420
- } finally {
421
- this._busyCount--;
422
- if (this._busyCount <= 0) {
423
- this._busyCount = 0;
424
- const args = {
425
- busy: false,
426
- mod: this
427
- };
428
- await this.emit("moduleBusy", args);
429
- }
430
- }
431
- }
432
- emit(eventName, eventArgs) {
433
- return super.emit(eventName, eventArgs);
434
- }
435
- previousHash() {
436
- this._checkDead();
437
- return this.account.previousHash;
438
- }
439
- async query(query, payloads, queryConfig) {
440
- this._checkDead();
441
- this._noOverride("query");
442
- const sourceQuery = await import_payload_builder2.PayloadBuilder.build((0, import_assert2.assertEx)(import_boundwitness_wrapper3.QueryBoundWitnessWrapper.unwrap(query), () => "Invalid query"));
443
- return await this.busy(async () => {
444
- const resultPayloads = [];
445
- const errorPayloads = [];
446
- const queryAccount = this.ephemeralQueryAccountEnabled ? await import_account2.Account.random() : void 0;
447
- try {
448
- await this.started("throw");
449
- if (!this.allowAnonymous && query.addresses.length === 0) {
450
- throw new Error(`Anonymous Queries not allowed, but running anyway [${this.modName}], [${this.address}]`);
451
- }
452
- if (queryConfig == null ? void 0 : queryConfig.allowedQueries) {
453
- (0, import_assert2.assertEx)(queryConfig == null ? void 0 : queryConfig.allowedQueries.includes(sourceQuery.schema), () => `Query not allowed [${sourceQuery.schema}]`);
454
- }
455
- resultPayloads.push(...await this.queryHandler(sourceQuery, payloads, queryConfig));
456
- } catch (ex) {
457
- await (0, import_error.handleErrorAsync)(ex, async (err) => {
458
- const error = err;
459
- this._lastError = error;
460
- errorPayloads.push(await new ModuleErrorBuilder().sources([
461
- sourceQuery.$hash
462
- ]).name(this.modName ?? "<Unknown>").query(sourceQuery.schema).details(error.details).message(error.message).build());
463
- });
464
- }
465
- if (this.timestamp) {
466
- const timestamp = {
467
- schema: "network.xyo.timestamp",
468
- timestamp: Date.now()
469
- };
470
- resultPayloads.push(timestamp);
471
- }
472
- const result = await this.bindQueryResult(sourceQuery, resultPayloads, queryAccount ? [
473
- queryAccount
474
- ] : [], errorPayloads);
475
- const args = {
476
- mod: this,
477
- payloads,
478
- query: sourceQuery,
479
- result
480
- };
481
- await this.emit("moduleQueried", args);
482
- return result;
483
- });
484
- }
485
- async queryable(query, payloads, queryConfig) {
486
- if (this.dead) {
487
- return false;
488
- }
489
- if (!await this.started("warn")) return false;
490
- const configValidator = queryConfig ? new ModuleConfigQueryValidator(Object.assign({}, this.config, queryConfig)).queryable : this.moduleConfigQueryValidator;
491
- const validators = [
492
- this.supportedQueryValidator,
493
- configValidator
494
- ];
495
- return validators.every((validator) => validator(query, payloads));
496
- }
497
- start(_timeout) {
498
- this._startPromise = this._startPromise ?? this.startHandler();
499
- const result = this._startPromise;
500
- this.status = result ? "started" : "dead";
501
- return result;
502
- }
503
- async started(notStartedAction = "log", tryStart = true) {
504
- const started = await this._started;
505
- if (started === true) {
506
- return true;
507
- }
508
- if (!started) {
509
- this._started = (async () => {
510
- var _a, _b, _c;
511
- if (tryStart) {
512
- try {
513
- await this.start();
514
- return true;
515
- } catch (ex) {
516
- (0, import_error.handleError)(ex, (error) => {
517
- var _a2;
518
- (_a2 = this.logger) == null ? void 0 : _a2.warn(`Autostart of Module Failed: ${error.message})`);
519
- this._started = void 0;
520
- });
521
- }
522
- }
523
- switch (notStartedAction) {
524
- case "throw": {
525
- throw new Error(`${MODULE_NOT_STARTED} [${this.address}]`);
526
- }
527
- case "warn": {
528
- (_a = this.logger) == null ? void 0 : _a.warn(MODULE_NOT_STARTED);
529
- break;
530
- }
531
- case "error": {
532
- (_b = this.logger) == null ? void 0 : _b.error(MODULE_NOT_STARTED);
533
- break;
534
- }
535
- case "none": {
536
- break;
537
- }
538
- default: {
539
- (_c = this.logger) == null ? void 0 : _c.log(MODULE_NOT_STARTED);
540
- break;
541
- }
542
- }
543
- return false;
544
- })();
545
- }
546
- if (!this._started) {
547
- throw "Failed to create start promise";
548
- }
549
- return await this._started;
550
- }
551
- async stop(_timeout) {
552
- return await this.busy(async () => {
553
- const result = await this.stopHandler();
554
- this._started = void 0;
555
- this._startPromise = void 0;
556
- this.status = result ? "stopped" : "dead";
557
- return result;
558
- });
559
- }
560
- _checkDead() {
561
- if (this.dead) {
562
- throw new import_module_model.DeadModuleError(this.id, this._lastError);
563
- }
564
- }
565
- _noOverride(functionName) {
566
- const thisFunc = this[functionName];
567
- const rootFunc = this._getRootFunction(functionName);
568
- (0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
569
- }
570
- async archivistInstance(required = false) {
571
- const archivist = this.archivist;
572
- if (!archivist) {
573
- if (required) {
574
- throw new Error("No archivist specified");
575
- }
576
- return void 0;
577
- }
578
- const resolved = await this.upResolver.resolve(archivist) ?? await this.downResolver.resolve(archivist);
579
- if (required) {
580
- (0, import_assert2.assertEx)(resolved, () => `Unable to resolve archivist [${archivist}]`);
581
- }
582
- return resolved ? (0, import_archivist_model.asArchivistInstance)(resolved, () => `Specified archivist is not an Archivist [${archivist}]`) : void 0;
583
- }
584
- bindHashes(hashes, schema, account) {
585
- return new import_promise.PromiseEx((resolve) => {
586
- const result = this.bindHashesInternal(hashes, schema, account);
587
- resolve == null ? void 0 : resolve(result);
588
- return result;
589
- }, account);
590
- }
591
- async bindHashesInternal(hashes, schema, account = this.account) {
592
- var _a;
593
- const builder = new import_boundwitness_builder.BoundWitnessBuilder().hashes(hashes, schema).signer(account);
594
- const result = (await builder.build())[0];
595
- (_a = this.logger) == null ? void 0 : _a.debug(`result: ${JSON.stringify(result, null, 2)}`);
596
- return result;
597
- }
598
- bindQuery(query, payloads, account, additionalSigners) {
599
- return new import_promise.PromiseEx(async (resolve) => {
600
- const result = await this.bindQueryInternal(query, payloads, account, additionalSigners);
601
- resolve == null ? void 0 : resolve(result);
602
- return result;
603
- }, account);
604
- }
605
- async bindQueryInternal(query, payloads, account = this.account, additionalSigners = []) {
606
- const accounts = [
607
- account,
608
- ...additionalSigners
609
- ].filter(import_exists.exists);
610
- const builder = await new import_boundwitness_builder.QueryBoundWitnessBuilder().payloads(payloads).signers(accounts).query(query);
611
- let additional = [];
612
- if (this.config.certify) {
613
- additional = await this.certifyParents();
614
- await builder.additional(additional);
615
- }
616
- const [bw, payloadsOut, errors] = await builder.build();
617
- return [
618
- bw,
619
- [
620
- ...payloadsOut,
621
- ...additional
622
- ],
623
- errors
624
- ];
625
- }
626
- async bindQueryResult(query, payloads, additionalWitnesses = [], errors) {
627
- var _a;
628
- const builder = new import_boundwitness_builder.BoundWitnessBuilder().payloads(payloads).errors(errors).sourceQuery(query.$hash);
629
- const witnesses = [
630
- this.account,
631
- ...additionalWitnesses
632
- ].filter(import_exists.exists);
633
- builder.signers(witnesses);
634
- const result = [
635
- (await builder.build())[0],
636
- await Promise.all(payloads.map((payload) => import_payload_builder2.PayloadBuilder.build(payload))),
637
- await Promise.all((_a = errors ?? []) == null ? void 0 : _a.map((error) => import_payload_builder2.PayloadBuilder.build(error)))
638
- ];
639
- if (this.archiving && this.isAllowedArchivingQuery(query.schema)) {
640
- (0, import_forget.forget)(this.storeToArchivists(result.flat()));
641
- }
642
- return result;
643
- }
644
- async generateConfigAndAddress(_maxDepth) {
645
- const config = await import_payload_builder2.PayloadBuilder.build(this.config);
646
- const address = await new import_payload_builder2.PayloadBuilder({
647
- schema: import_module_model.AddressSchema
648
- }).fields({
649
- address: this.address
650
- }).build();
651
- const queries = await Promise.all(this.queries.map(async (query) => {
652
- return await new import_payload_builder2.PayloadBuilder({
653
- schema: import_query_payload_plugin.QuerySchema
654
- }).fields({
655
- query
656
- }).build();
657
- }));
658
- const configSchema = await import_payload_builder2.PayloadBuilder.build({
659
- config: config.schema,
660
- schema: import_config_payload_plugin.ConfigSchema
661
- });
662
- return (0, import_lodash.compact)([
663
- config,
664
- configSchema,
665
- address,
666
- ...queries
667
- ]);
668
- }
669
- async generateDescribe() {
670
- var _a;
671
- const description = {
672
- address: this.address,
673
- queries: this.queries,
674
- schema: import_module_model.ModuleDescriptionSchema
675
- };
676
- if ((_a = this.config) == null ? void 0 : _a.name) {
677
- description.name = this.modName;
678
- }
679
- const discover = await this.generateConfigAndAddress();
680
- description.children = (0, import_lodash.compact)((discover == null ? void 0 : discover.map((payload) => {
681
- const address = payload.schema === import_module_model.AddressSchema ? payload.address : void 0;
682
- return address == this.address ? void 0 : address;
683
- })) ?? []);
684
- return description;
685
- }
686
- /** @deprecated use archivistInstance() instead */
687
- async getArchivist() {
688
- return await this.archivistInstance();
689
- }
690
- isAllowedArchivingQuery(schema) {
691
- var _a;
692
- const queries = (_a = this.archiving) == null ? void 0 : _a.queries;
693
- if (queries) {
694
- return queries.includes(schema);
695
- }
696
- return true;
697
- }
698
- manifestHandler(_maxDepth = 1, _ignoreAddresses = []) {
699
- throw new Error("Not supported");
700
- }
701
- moduleAddressHandler() {
702
- const address = this.address;
703
- const name = this.modName;
704
- const previousHash = this.address;
705
- const moduleAccount = name ? {
706
- address,
707
- name,
708
- schema: import_module_model.AddressSchema
709
- } : {
710
- address,
711
- schema: import_module_model.AddressSchema
712
- };
713
- const moduleAccountPreviousHash = previousHash ? {
714
- address,
715
- previousHash,
716
- schema: import_module_model.AddressPreviousHashSchema
717
- } : {
718
- address,
719
- schema: import_module_model.AddressSchema
720
- };
721
- return [
722
- moduleAccount,
723
- moduleAccountPreviousHash
724
- ];
725
- }
726
- async queryHandler(query, payloads, queryConfig) {
727
- await this.started("throw");
728
- const wrapper = await import_boundwitness_wrapper3.QueryBoundWitnessWrapper.parseQuery(query, payloads);
729
- const queryPayload = await wrapper.getQuery();
730
- (0, import_assert2.assertEx)(await this.queryable(query, payloads, queryConfig));
731
- const resultPayloads = [];
732
- switch (queryPayload.schema) {
733
- case import_module_model.ModuleManifestQuerySchema: {
734
- resultPayloads.push(await this.manifestHandler(queryPayload.maxDepth));
735
- break;
736
- }
737
- case import_module_model.ModuleAddressQuerySchema: {
738
- resultPayloads.push(...await this.moduleAddressHandler());
739
- break;
740
- }
741
- case import_module_model.ModuleStateQuerySchema: {
742
- resultPayloads.push(...await this.stateHandler());
743
- break;
744
- }
745
- case import_module_model.ModuleSubscribeQuerySchema: {
746
- this.subscribeHandler();
747
- break;
748
- }
749
- default: {
750
- throw new Error(`Unsupported Query [${queryPayload.schema}]`);
751
- }
752
- }
753
- return resultPayloads;
754
- }
755
- async startHandler() {
756
- this.validateConfig();
757
- await Promise.resolve();
758
- this._started = true;
759
- return true;
760
- }
761
- async stateHandler() {
762
- return [
763
- await this.manifestHandler(),
764
- ...await this.generateConfigAndAddress(),
765
- await this.generateDescribe()
766
- ];
767
- }
768
- stopHandler(_timeout) {
769
- this._started = void 0;
770
- return true;
771
- }
772
- subscribeHandler() {
773
- return;
774
- }
775
- validateConfig(config, parents = []) {
776
- return Object.entries(config ?? this.config ?? {}).reduce((valid, [key, value]) => {
777
- var _a, _b;
778
- switch (typeof value) {
779
- case "function": {
780
- (_a = this.logger) == null ? void 0 : _a.warn(`Fields of type function not allowed in config [${parents == null ? void 0 : parents.join(".")}.${key}]`);
781
- return false;
782
- }
783
- case "object": {
784
- if (Array.isArray(value)) {
785
- return (
786
- // eslint-disable-next-line unicorn/no-array-reduce
787
- value.reduce((valid2, value2) => {
788
- return this.validateConfig(value2, [
789
- ...parents,
790
- key
791
- ]) && valid2;
792
- }, true) && valid
793
- );
794
- }
795
- if (!(0, import_module_model.serializableField)(value)) {
796
- (_b = this.logger) == null ? void 0 : _b.warn(`Fields that are not serializable to JSON are not allowed in config [${parents == null ? void 0 : parents.join(".")}.${key}]`);
797
- return false;
798
- }
799
- return value ? this.validateConfig(value, [
800
- ...parents,
801
- key
802
- ]) && valid : true;
803
- }
804
- default: {
805
- return valid;
806
- }
807
- }
808
- }, true);
809
- }
810
- };
811
- __name(_AbstractModule, "AbstractModule");
812
- __publicField(_AbstractModule, "allowRandomAccount", true);
813
- __publicField(_AbstractModule, "configSchemas", [
814
- import_module_model.ModuleConfigSchema
815
- ]);
816
- __publicField(_AbstractModule, "defaultConfigSchema", import_module_model.ModuleConfigSchema);
817
- __publicField(_AbstractModule, "defaultLogger", new import_logger.ConsoleLogger(import_logger.LogLevel.warn));
818
- __publicField(_AbstractModule, "enableLazyLoad", false);
819
- __publicField(_AbstractModule, "labels", {});
820
- __publicField(_AbstractModule, "uniqueName", (0, import_object2.globallyUnique)("AbstractModule", _AbstractModule, "xyo"));
821
- __publicField(_AbstractModule, "privateConstructorKey", Date.now().toString());
822
- var AbstractModule = _AbstractModule;
823
-
824
- // src/AbstractModuleInstance.ts
825
- var import_assert3 = require("@xylabs/assert");
826
- var import_exists2 = require("@xylabs/exists");
827
- var import_lodash2 = require("@xylabs/lodash");
828
- var import_object3 = require("@xylabs/object");
829
- var import_archivist_model2 = require("@xyo-network/archivist-model");
830
- var import_manifest_model = require("@xyo-network/manifest-model");
831
- var import_module_model2 = require("@xyo-network/module-model");
832
- var import_module_resolver = require("@xyo-network/module-resolver");
833
- var import_node_model = require("@xyo-network/node-model");
834
- var _AbstractModuleInstance = class _AbstractModuleInstance extends AbstractModule {
835
- _downResolver;
836
- _parents = [];
837
- _privateResolver;
838
- _upResolver;
839
- constructor(privateConstructorKey, params, account) {
840
- (0, import_assert3.assertEx)(AbstractModule.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
841
- const mutatedParams = {
842
- ...params
843
- };
844
- const addToResolvers = mutatedParams.addToResolvers ?? true;
845
- super(privateConstructorKey, mutatedParams, account);
846
- if (addToResolvers) {
847
- this.upResolver.add(this);
848
- this.downResolver.add(this);
849
- }
850
- }
851
- get downResolver() {
852
- this._downResolver = this._downResolver ?? new import_module_resolver.CompositeModuleResolver({
853
- allowNameResolution: this.allowNameResolution,
854
- moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
855
- root: this
856
- });
857
- return this._downResolver;
858
- }
859
- get modName() {
860
- return super.modName;
861
- }
862
- get moduleIdentifierTransformers() {
863
- return this.params.moduleIdentifierTransformers ?? import_module_model2.ResolveHelper.transformers;
864
- }
865
- get privateResolver() {
866
- this._privateResolver = this._privateResolver ?? new import_module_resolver.CompositeModuleResolver({
867
- allowNameResolution: this.allowNameResolution,
868
- moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
869
- root: this
870
- });
871
- return this._privateResolver;
872
- }
873
- get root() {
874
- return this;
875
- }
876
- get upResolver() {
877
- this._upResolver = this._upResolver ?? new import_module_resolver.CompositeModuleResolver({
878
- allowNameResolution: this.allowNameResolution,
879
- moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
880
- root: this
881
- });
882
- return this._upResolver;
883
- }
884
- addParent(mod) {
885
- const existingEntry = this._parents.find((parent) => parent.address === mod.address);
886
- if (!existingEntry) {
887
- this._parents.push((0, import_node_model.asNodeInstance)(mod, "Only NodeInstances can be parents"));
888
- }
889
- }
890
- async certifyParents() {
891
- const parents = await this.parents();
892
- return (await Promise.all(parents.map(async (parent) => {
893
- const [bw, payloads, errors] = await parent.certifyQuery(this.address);
894
- return errors.length === 0 ? [
895
- bw,
896
- ...payloads
897
- ] : [];
898
- }))).flat();
899
- }
900
- manifest(maxDepth) {
901
- this._checkDead();
902
- return this.busy(async () => {
903
- return await this.manifestHandler(maxDepth);
904
- });
905
- }
906
- async manifestQuery(account, maxDepth) {
907
- const queryPayload = {
908
- schema: import_module_model2.ModuleManifestQuerySchema,
909
- ...maxDepth === void 0 ? {} : {
910
- maxDepth
911
- }
912
- };
913
- return await this.sendQueryRaw(queryPayload, void 0, account);
914
- }
915
- moduleAddress() {
916
- this._checkDead();
917
- return this.busy(async () => {
918
- return await this.moduleAddressHandler();
919
- });
920
- }
921
- parents() {
922
- return this._parents;
923
- }
924
- privateChildren() {
925
- return [];
926
- }
927
- publicChildren() {
928
- return [];
929
- }
930
- removeParent(address) {
931
- this._parents = this._parents.filter((item) => item.address !== address);
932
- }
933
- async resolve(idOrFilter = "*", options = {}) {
934
- if (_AbstractModuleInstance.useNewResolver) {
935
- if (idOrFilter === "*") {
936
- const { maxDepth = 10, direction } = options;
937
- if (direction === "down") {
938
- return await (0, import_module_model2.resolveAllDown)(this, maxDepth);
939
- }
940
- if (direction === "up") {
941
- return await (0, import_module_model2.resolveAllUp)(this, maxDepth);
942
- }
943
- return await (0, import_module_model2.resolveAll)(this, maxDepth);
944
- } else if (typeof idOrFilter === "string") {
945
- return await (0, import_module_model2.resolvePathToInstance)(this, idOrFilter, true);
946
- } else {
947
- if ((0, import_module_model2.isNameModuleFilter)(idOrFilter)) {
948
- return (await Promise.all(idOrFilter.name.map(async (id) => await (0, import_module_model2.resolveLocalNameToInstance)(this, id)))).filter(import_exists2.exists);
949
- } else if ((0, import_module_model2.isAddressModuleFilter)(idOrFilter)) {
950
- return (await Promise.all(idOrFilter.address.map(async (id) => await (0, import_module_model2.resolveAddressToInstance)(this, id)))).filter(import_exists2.exists);
951
- } else {
952
- throw new TypeError("Invalid filter");
953
- }
954
- }
955
- } else {
956
- const config = {
957
- address: this.address,
958
- dead: this.dead,
959
- downResolver: this.downResolver,
960
- logger: this.logger,
961
- mod: this,
962
- transformers: this.moduleIdentifierTransformers,
963
- upResolver: this.upResolver
964
- };
965
- if (idOrFilter === "*") {
966
- return await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options);
967
- }
968
- switch (typeof idOrFilter) {
969
- case "string": {
970
- return await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options);
971
- }
972
- case "object": {
973
- return (await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options)).filter((mod) => mod.address !== this.address);
974
- }
975
- default: {
976
- return (await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options)).filter((mod) => mod.address !== this.address);
977
- }
978
- }
979
- }
980
- }
981
- resolveIdentifier(id, options) {
982
- const { direction = "all" } = options ?? {};
983
- switch (direction) {
984
- case "down": {
985
- return this.downResolver.resolveIdentifier(id, options);
986
- }
987
- default: {
988
- const mutatedOptions = {
989
- ...options,
990
- direction: "all"
991
- };
992
- return this.upResolver.resolveIdentifier(id, mutatedOptions);
993
- }
994
- }
995
- }
996
- async resolvePrivate(id = "*", options = {}) {
997
- return await this.privateResolver.resolve(id, options) ?? await this.upResolver.resolve(id, options) ?? await this.downResolver.resolve(id, options);
998
- }
999
- async siblings() {
1000
- return (await Promise.all((await this.parents()).map((parent) => parent.publicChildren()))).flat().filter(import_module_model2.duplicateModules);
1001
- }
1002
- /* override start(_timeout?: number): Promisable<boolean> {
1003
- if (this.parents.length === 0) {
1004
- this.logger.warn(`Module is being started without being attached to a parent: ${this.id} [${this.address}]`)
1005
- }
1006
- return super.start()
1007
- } */
1008
- state() {
1009
- this._checkDead();
1010
- return this.busy(async () => {
1011
- return await this.stateHandler();
1012
- });
1013
- }
1014
- async stateQuery(account) {
1015
- const queryPayload = {
1016
- schema: import_module_model2.ModuleStateQuerySchema
1017
- };
1018
- return await this.sendQueryRaw(queryPayload, void 0, account);
1019
- }
1020
- subscribe(_queryAccount) {
1021
- this._checkDead();
1022
- return this.subscribeHandler();
1023
- }
1024
- async manifestHandler(maxDepth = 1, _ignoreAddresses = []) {
1025
- const cachedResult = this._cachedManifests.get(maxDepth);
1026
- if (cachedResult) {
1027
- return cachedResult;
1028
- }
1029
- const modName = this.modName ?? "<Anonymous>";
1030
- const children = await this.publicChildren();
1031
- const childAddressToName = {};
1032
- for (const child of children) {
1033
- if (child.address !== this.address) {
1034
- childAddressToName[child.address] = child.modName ?? null;
1035
- }
1036
- }
1037
- const result = {
1038
- config: {
1039
- name: modName,
1040
- ...this.config
1041
- },
1042
- schema: import_manifest_model.ModuleManifestPayloadSchema,
1043
- status: {
1044
- address: this.address,
1045
- children: childAddressToName
1046
- }
1047
- };
1048
- this._cachedManifests.set(maxDepth, result);
1049
- return result;
1050
- }
1051
- async resolveArchivingArchivists() {
1052
- var _a;
1053
- const archivists = (_a = this.archiving) == null ? void 0 : _a.archivists;
1054
- if (!archivists) return [];
1055
- const resolved = await Promise.all(archivists.map((archivist) => this.resolve(archivist)));
1056
- return (0, import_lodash2.compact)(resolved.map((mod) => (0, import_archivist_model2.asArchivistInstance)(mod)));
1057
- }
1058
- async sendQuery(queryPayload, payloads, account) {
1059
- const queryResults = await this.sendQueryRaw(queryPayload, payloads, account);
1060
- const [, resultPayloads, errors] = queryResults;
1061
- if (errors && errors.length > 0) {
1062
- throw errors[0];
1063
- }
1064
- return resultPayloads;
1065
- }
1066
- async sendQueryRaw(queryPayload, payloads, account) {
1067
- const query = await this.bindQuery(queryPayload, payloads, account, this.additionalSigners);
1068
- return await this.query(query[0], query[1]);
1069
- }
1070
- async storeToArchivists(payloads) {
1071
- try {
1072
- const archivists = await this.resolveArchivingArchivists();
1073
- return (await Promise.all(archivists.map((archivist) => {
1074
- var _a;
1075
- return (_a = archivist.insert) == null ? void 0 : _a.call(archivist, payloads);
1076
- }))).map(([bw]) => bw);
1077
- } catch (ex) {
1078
- const error = ex;
1079
- this.logger.error(`Error storing to archivists: ${error.message}`);
1080
- return [];
1081
- }
1082
- }
1083
- };
1084
- __name(_AbstractModuleInstance, "AbstractModuleInstance");
1085
- __publicField(_AbstractModuleInstance, "uniqueName", (0, import_object3.globallyUnique)("AbstractModuleInstance", _AbstractModuleInstance, "xyo"));
1086
- // switches between old and new resolution system
1087
- __publicField(_AbstractModuleInstance, "useNewResolver", false);
1088
- var AbstractModuleInstance = _AbstractModuleInstance;
1089
- // Annotate the CommonJS export names for ESM import in node:
1090
- 0 && (module.exports = {
1091
- AbstractModule,
1092
- AbstractModuleInstance,
1093
- BaseEmitter,
1094
- ModuleConfigQueryValidator,
1095
- ModuleErrorBuilder,
1096
- SupportedQueryValidator,
1097
- isQuerySupportedByModule
1098
- });
1099
- //# sourceMappingURL=index.cjs.map