@xyo-network/module-model 2.64.6 → 2.64.7
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.
- package/dist/cjs/Queries/{ModuleAccount → ModuleAddress}/Payload.js.map +1 -1
- package/dist/cjs/Queries/ModuleAddress/Query.js +5 -0
- package/dist/cjs/Queries/ModuleAddress/Query.js.map +1 -0
- package/dist/cjs/Queries/ModuleAddress/index.js.map +1 -0
- package/dist/cjs/Queries/index.js +1 -1
- package/dist/cjs/isModule.js +40 -8
- package/dist/cjs/isModule.js.map +1 -1
- package/dist/cjs/withModule.js +4 -3
- package/dist/cjs/withModule.js.map +1 -1
- package/dist/docs.json +4361 -2290
- package/dist/esm/Queries/{ModuleAccount → ModuleAddress}/Payload.js.map +1 -1
- package/dist/esm/Queries/ModuleAddress/Query.js +2 -0
- package/dist/esm/Queries/ModuleAddress/Query.js.map +1 -0
- package/dist/esm/Queries/ModuleAddress/index.js.map +1 -0
- package/dist/esm/Queries/index.js +1 -1
- package/dist/esm/isModule.js +37 -7
- package/dist/esm/isModule.js.map +1 -1
- package/dist/esm/withModule.js +4 -3
- package/dist/esm/withModule.js.map +1 -1
- package/dist/types/Module.d.ts +12 -7
- package/dist/types/Module.d.ts.map +1 -1
- package/dist/types/Queries/{ModuleAccount → ModuleAddress}/Payload.d.ts.map +1 -1
- package/dist/types/Queries/ModuleAddress/Query.d.ts +7 -0
- package/dist/types/Queries/{ModuleAccount → ModuleAddress}/Query.d.ts.map +1 -1
- package/dist/types/Queries/ModuleAddress/index.d.ts.map +1 -0
- package/dist/types/Queries/index.d.ts +3 -3
- package/dist/types/Query/QueryBoundWitness.d.ts +2 -0
- package/dist/types/Query/QueryBoundWitness.d.ts.map +1 -1
- package/dist/types/isModule.d.ts +12 -4
- package/dist/types/isModule.d.ts.map +1 -1
- package/dist/types/withModule.d.ts +5 -5
- package/dist/types/withModule.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/Module.ts +20 -8
- package/src/Queries/ModuleAddress/Query.ts +8 -0
- package/src/Queries/index.ts +3 -3
- package/src/isModule.ts +49 -13
- package/src/withModule.ts +6 -6
- package/dist/cjs/Queries/ModuleAccount/Query.js +0 -5
- package/dist/cjs/Queries/ModuleAccount/Query.js.map +0 -1
- package/dist/cjs/Queries/ModuleAccount/index.js.map +0 -1
- package/dist/esm/Queries/ModuleAccount/Query.js +0 -2
- package/dist/esm/Queries/ModuleAccount/Query.js.map +0 -1
- package/dist/esm/Queries/ModuleAccount/index.js.map +0 -1
- package/dist/types/Queries/ModuleAccount/Query.d.ts +0 -7
- package/dist/types/Queries/ModuleAccount/index.d.ts.map +0 -1
- package/src/Queries/ModuleAccount/Query.ts +0 -8
- /package/dist/cjs/Queries/{ModuleAccount → ModuleAddress}/Payload.js +0 -0
- /package/dist/cjs/Queries/{ModuleAccount → ModuleAddress}/index.js +0 -0
- /package/dist/esm/Queries/{ModuleAccount → ModuleAddress}/Payload.js +0 -0
- /package/dist/esm/Queries/{ModuleAccount → ModuleAddress}/index.js +0 -0
- /package/dist/types/Queries/{ModuleAccount → ModuleAddress}/Payload.d.ts +0 -0
- /package/dist/types/Queries/{ModuleAccount → ModuleAddress}/index.d.ts +0 -0
- /package/src/Queries/{ModuleAccount → ModuleAddress}/Payload.ts +0 -0
- /package/src/Queries/{ModuleAccount → ModuleAddress}/index.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.js","sourceRoot":"","sources":["../../../../src/Queries/
|
|
1
|
+
{"version":3,"file":"Payload.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAddress/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAGnE,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,aAAa,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAddress/Query.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAA6B,kCAAkC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAddress/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
package/dist/esm/isModule.js
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
|
+
import { ModuleAddressQuerySchema, ModuleDiscoverQuerySchema } from './Queries';
|
|
2
|
+
export const isType = (value, expectedType) => {
|
|
3
|
+
if (expectedType === 'array') {
|
|
4
|
+
return Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
else if (expectedType === 'payload') {
|
|
7
|
+
return typeof value === 'object' && typeof value.schema === 'string';
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return typeof value === expectedType;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const IsInstanceFactory = {
|
|
14
|
+
create: (shape, additionalCheck) => {
|
|
15
|
+
return (module) => {
|
|
16
|
+
return ((additionalCheck?.(module) ?? true) &&
|
|
17
|
+
(Object.entries(shape ?? {}).reduce((prev, [key, type]) => prev && isType(module[key], type), true) ?? true));
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
};
|
|
1
21
|
export const IsModuleFactory = {
|
|
2
|
-
create: (
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
additionalCheck) => {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
create: (expectedQueries, additionalCheck) => {
|
|
6
23
|
return (module) => {
|
|
7
|
-
return ((
|
|
24
|
+
return (isModuleInstance(module) &&
|
|
8
25
|
(additionalCheck?.(module) ?? true) &&
|
|
9
|
-
(
|
|
26
|
+
(expectedQueries?.reduce((prev, query) => prev && module.queries.includes(query), true) ?? true));
|
|
10
27
|
};
|
|
11
28
|
},
|
|
12
29
|
};
|
|
13
|
-
export const
|
|
30
|
+
export const isModuleInstance = IsInstanceFactory.create({
|
|
31
|
+
account: 'object',
|
|
32
|
+
address: 'string',
|
|
33
|
+
config: 'object',
|
|
34
|
+
discover: 'function',
|
|
35
|
+
downResolver: 'object',
|
|
36
|
+
manifest: 'function',
|
|
37
|
+
params: 'object',
|
|
38
|
+
queries: 'array',
|
|
39
|
+
query: 'function',
|
|
40
|
+
queryable: 'function',
|
|
41
|
+
upResolver: 'object',
|
|
42
|
+
});
|
|
43
|
+
export const isModule = IsModuleFactory.create([ModuleAddressQuerySchema, ModuleDiscoverQuerySchema]);
|
|
14
44
|
//# sourceMappingURL=isModule.js.map
|
package/dist/esm/isModule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isModule.js","sourceRoot":"","sources":["../../src/isModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isModule.js","sourceRoot":"","sources":["../../src/isModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAU/E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAU,EAAE,YAAuB,EAAE,EAAE;IAC5D,IAAI,YAAY,KAAK,OAAO,EAAE;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;KAC5B;SAAM,IAAI,YAAY,KAAK,SAAS,EAAE;QACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAA;KACrE;SAAM;QACL,OAAO,OAAO,KAAK,KAAK,YAAY,CAAA;KACrC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,CAA4B,KAAyB,EAAE,eAA0C,EAAwB,EAAE;QACjI,OAAO,CAAC,MAAW,EAAe,EAAE;YAClC,OAAO,CACL,CAAC,eA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,CAAC,wBAAwB,EAAE,yBAAyB,CAAC,CAAC,CAAA"}
|
package/dist/esm/withModule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isModule } from './isModule';
|
|
2
|
-
export const
|
|
1
|
+
import { isModule, isModuleInstance } from './isModule';
|
|
2
|
+
export const WithFactory = {
|
|
3
3
|
create: (typeCheck) => {
|
|
4
4
|
return (
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -10,5 +10,6 @@ export const WithModuleFactory = {
|
|
|
10
10
|
};
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
|
-
export const withModule =
|
|
13
|
+
export const withModule = WithFactory.create(isModule);
|
|
14
|
+
export const withModuleInstance = WithFactory.create(isModuleInstance);
|
|
14
15
|
//# sourceMappingURL=withModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withModule.js","sourceRoot":"","sources":["../../src/withModule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"withModule.js","sourceRoot":"","sources":["../../src/withModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE1E,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,CAAmB,SAA+B,EAAE,EAAE;QAC5D,OAAO;QACL,8DAA8D;QAC9D,MAAW;QACX,8DAA8D;QAC9D,OAAyB,EACV,EAAE;YACjB,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACxD,CAAC,CAAA;IACH,CAAC;CACF,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA"}
|
package/dist/types/Module.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { AnyConfigSchema, ModuleConfig } from './Config';
|
|
|
7
7
|
import { ModuleFilter } from './ModuleFilter';
|
|
8
8
|
import { ModuleParams } from './ModuleParams';
|
|
9
9
|
import { ModuleQueryResult } from './ModuleQueryResult';
|
|
10
|
+
import { AddressPreviousHashPayload } from './Queries';
|
|
10
11
|
import { QueryBoundWitness } from './Query';
|
|
11
12
|
export interface ModuleResolver {
|
|
12
13
|
addResolver: (resolver: ModuleResolver) => this;
|
|
@@ -17,19 +18,19 @@ export interface ModuleResolver {
|
|
|
17
18
|
* is supplied, all modules are returned
|
|
18
19
|
* @param filter Filter criteria for the desired modules
|
|
19
20
|
*/
|
|
20
|
-
resolve<T extends
|
|
21
|
+
resolve<T extends ModuleInstance = ModuleInstance>(filter?: ModuleFilter): Promisable<T[]>;
|
|
21
22
|
/**
|
|
22
23
|
* Resolves a single module, or undefined if no modules matched the filter.
|
|
23
24
|
* @param filter The desired Module's Address or Name
|
|
24
25
|
*/
|
|
25
|
-
resolveOne<T extends
|
|
26
|
+
resolveOne<T extends ModuleInstance = ModuleInstance>(filter: string): Promisable<T | undefined>;
|
|
26
27
|
}
|
|
27
|
-
export type ModuleEventArgs<TModule extends
|
|
28
|
+
export type ModuleEventArgs<TModule extends ModuleInstance = ModuleInstance, TArgs extends EventArgs | undefined = undefined> = TArgs extends EventArgs ? {
|
|
28
29
|
module: TModule;
|
|
29
30
|
} & TArgs : {
|
|
30
31
|
module: TModule;
|
|
31
32
|
};
|
|
32
|
-
export type ModuleQueriedEventArgs = ModuleEventArgs<
|
|
33
|
+
export type ModuleQueriedEventArgs = ModuleEventArgs<ModuleInstance, {
|
|
33
34
|
payloads?: Payload[];
|
|
34
35
|
query: QueryBoundWitness;
|
|
35
36
|
result: ModuleQueryResult;
|
|
@@ -37,13 +38,16 @@ export type ModuleQueriedEventArgs = ModuleEventArgs<Module, {
|
|
|
37
38
|
export interface ModuleEventData extends EventData {
|
|
38
39
|
moduleQueried: ModuleQueriedEventArgs;
|
|
39
40
|
}
|
|
41
|
+
export type ModuleQueryFunctions = {
|
|
42
|
+
addressPreviousHash: () => Promisable<AddressPreviousHashPayload>;
|
|
43
|
+
discover: () => Promisable<Payload[]>;
|
|
44
|
+
manifest: () => Promisable<ModuleManifest>;
|
|
45
|
+
};
|
|
40
46
|
export type ModuleFields<TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>> = {
|
|
41
|
-
account?: AccountInstance;
|
|
42
47
|
address: string;
|
|
43
48
|
config: TParams['config'];
|
|
44
49
|
readonly downResolver: ModuleResolver;
|
|
45
50
|
loadAccount?: () => Promisable<AccountInstance>;
|
|
46
|
-
manifest: () => Promisable<ModuleManifest>;
|
|
47
51
|
params: TParams;
|
|
48
52
|
queries: string[];
|
|
49
53
|
query: <T extends QueryBoundWitness = QueryBoundWitness, TConf extends ModuleConfig = ModuleConfig>(query: T, payloads?: Payload[], queryConfig?: TConf) => Promisable<ModuleQueryResult>;
|
|
@@ -51,5 +55,6 @@ export type ModuleFields<TParams extends ModuleParams<AnyConfigSchema<ModuleConf
|
|
|
51
55
|
start?: () => Promisable<void>;
|
|
52
56
|
readonly upResolver: ModuleResolver;
|
|
53
57
|
};
|
|
54
|
-
export type Module<TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>, TEventData extends ModuleEventData = ModuleEventData> = ModuleFields<TParams> & EventFunctions<TEventData
|
|
58
|
+
export type Module<TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>, TEventData extends ModuleEventData = ModuleEventData> = ModuleFields<TParams> & EventFunctions<TEventData> & ModuleQueryFunctions;
|
|
59
|
+
export type ModuleInstance<TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>, TEventData extends ModuleEventData = ModuleEventData> = Module<TParams, TEventData>;
|
|
55
60
|
//# sourceMappingURL=Module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Module.d.ts","sourceRoot":"","sources":["../../src/Module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE3C,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAA;IAC/C,gBAAgB,EAAE,OAAO,CAAA;IACzB,cAAc,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAA;IAClD;;;;OAIG;IACH,OAAO,CAAC,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"Module.d.ts","sourceRoot":"","sources":["../../src/Module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B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AAE,cAAc,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,MAAM,CAChB,OAAO,SAAS,YAAY,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,EACzG,UAAU,SAAS,eAAe,GAAG,eAAe,IAClD,YAAY,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,oBAAoB,CAAA;AAE7E,MAAM,MAAM,cAAc,CACxB,OAAO,SAAS,YAAY,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,EACzG,UAAU,SAAS,eAAe,GAAG,eAAe,IAClD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../../../src/Queries/
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../../../src/Queries/ModuleAddress/Payload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,eAAO,MAAM,yBAAyB,QAAmC,CAAA;AACzE,MAAM,MAAM,yBAAyB,GAAG,OAAO,yBAAyB,CAAA;AAExE,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,yBAAyB,CAAA;CAClC,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Query } from '../../Query';
|
|
2
|
+
export type ModuleAddressQuerySchema = 'network.xyo.query.module.address';
|
|
3
|
+
export declare const ModuleAddressQuerySchema: ModuleAddressQuerySchema;
|
|
4
|
+
export type ModuleAddressQuery = Query<{
|
|
5
|
+
schema: ModuleAddressQuerySchema;
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=Query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../../../../src/Queries/
|
|
1
|
+
{"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../../../../src/Queries/ModuleAddress/Query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,MAAM,MAAM,wBAAwB,GAAG,kCAAkC,CAAA;AACzE,eAAO,MAAM,wBAAwB,EAAE,wBAA6D,CAAA;AAEpG,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC;IACrC,MAAM,EAAE,wBAAwB,CAAA;CACjC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Queries/ModuleAddress/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Query } from '../Query';
|
|
2
2
|
import { ModuleDiscoverQuery } from './Discover';
|
|
3
|
-
import {
|
|
3
|
+
import { ModuleAddressQuery } from './ModuleAddress';
|
|
4
4
|
import { ModuleSubscribeQuery } from './Subscribe';
|
|
5
5
|
export * from './Discover';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './ModuleAddress';
|
|
7
7
|
export * from './Subscribe';
|
|
8
|
-
export type ModuleQueryBase = ModuleDiscoverQuery |
|
|
8
|
+
export type ModuleQueryBase = ModuleDiscoverQuery | ModuleAddressQuery | ModuleSubscribeQuery;
|
|
9
9
|
export type ModuleQuery<T extends Query | void = void> = T extends Query ? ModuleQueryBase | T : ModuleQueryBase;
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -11,5 +11,7 @@ export declare const isQueryBoundWitness: (x?: Payload | null) => x is import("@
|
|
|
11
11
|
query: string;
|
|
12
12
|
resultSet?: string | undefined;
|
|
13
13
|
schema: BoundWitnessSchema;
|
|
14
|
+
} & {
|
|
15
|
+
schema: "network.xyo.boundwitness";
|
|
14
16
|
};
|
|
15
17
|
//# sourceMappingURL=QueryBoundWitness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBoundWitness.d.ts","sourceRoot":"","sources":["../../../src/Query/QueryBoundWitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAkB,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AACxD,eAAO,MAAM,uBAAuB,EAAE,uBAA4C,CAAA;AAElF,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,kBAAkB,CAAA;CAC3B,CAAC,CAAA;AAEF,eAAO,MAAM,mBAAmB,OAAQ,OAAO,GAAG,IAAI;WAL7C,MAAM;;YAEL,kBAAkB
|
|
1
|
+
{"version":3,"file":"QueryBoundWitness.d.ts","sourceRoot":"","sources":["../../../src/Query/QueryBoundWitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAkB,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AACxD,eAAO,MAAM,uBAAuB,EAAE,uBAA4C,CAAA;AAElF,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,kBAAkB,CAAA;CAC3B,CAAC,CAAA;AAEF,eAAO,MAAM,mBAAmB,OAAQ,OAAO,GAAG,IAAI;WAL7C,MAAM;;YAEL,kBAAkB;;;CAGyH,CAAA"}
|
package/dist/types/isModule.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type
|
|
1
|
+
import { ModuleInstance } from './Module';
|
|
2
|
+
export type InstanceTypeCheck<T extends object = object> = (module: object) => module is T;
|
|
3
|
+
export type ModuleTypeCheck<T extends ModuleInstance = ModuleInstance> = InstanceTypeCheck<T>;
|
|
4
|
+
export type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function' | 'payload';
|
|
5
|
+
export type InstanceTypeShape = Record<string | number | symbol, FieldType>;
|
|
6
|
+
export declare const isType: (value: any, expectedType: FieldType) => boolean;
|
|
7
|
+
export declare const IsInstanceFactory: {
|
|
8
|
+
create: <T extends object = object>(shape?: InstanceTypeShape, additionalCheck?: ((module: any) => boolean) | undefined) => InstanceTypeCheck<T>;
|
|
9
|
+
};
|
|
3
10
|
export declare const IsModuleFactory: {
|
|
4
|
-
create: <T extends
|
|
11
|
+
create: <T extends ModuleInstance = ModuleInstance>(expectedQueries?: string[], additionalCheck?: ((module: any) => boolean) | undefined) => ModuleTypeCheck<T>;
|
|
5
12
|
};
|
|
6
|
-
export declare const
|
|
13
|
+
export declare const isModuleInstance: InstanceTypeCheck<ModuleInstance>;
|
|
14
|
+
export declare const isModule: ModuleTypeCheck<ModuleInstance>;
|
|
7
15
|
//# sourceMappingURL=isModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isModule.d.ts","sourceRoot":"","sources":["../../src/isModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isModule.d.ts","sourceRoot":"","sources":["../../src/isModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAGzC,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,IAAI,CAAC,CAAA;AAE1F,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAE7F,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;AAEtI,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,SAAS,CAAC,CAAA;AAE3E,eAAO,MAAM,MAAM,UAAW,GAAG,gBAAgB,SAAS,YAQzD,CAAA;AAED,eAAO,MAAM,iBAAiB;gDACgB,iBAAiB,8BAA6B,GAAG,KAAK,OAAO;CAQ1G,CAAA;AAED,eAAO,MAAM,eAAe;0EAC4C,MAAM,EAAE,8BAA6B,GAAG,KAAK,OAAO;CAS3H,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,cAAc,CAY7D,CAAA;AAEF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAiG,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
create: <T extends Module = Module>(typeCheck: ModuleTypeCheck<T>) => <R extends void = void>(module: any, closure: (module: any) => R) => R | undefined;
|
|
1
|
+
import { InstanceTypeCheck } from './isModule';
|
|
2
|
+
export declare const WithFactory: {
|
|
3
|
+
create: <T extends object>(typeCheck: InstanceTypeCheck<T>) => <R extends void = void>(module: any, closure: (module: T) => R) => R | undefined;
|
|
5
4
|
};
|
|
6
|
-
export declare const withModule: <R extends void = void>(module: any, closure: (module:
|
|
5
|
+
export declare const withModule: <R extends void = void>(module: any, closure: (module: import("./Module").ModuleInstance) => R) => R | undefined;
|
|
6
|
+
export declare const withModuleInstance: <R extends void = void>(module: any, closure: (module: import("./Module").ModuleInstance) => R) => R | undefined;
|
|
7
7
|
//# sourceMappingURL=withModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withModule.d.ts","sourceRoot":"","sources":["../../src/withModule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"withModule.d.ts","sourceRoot":"","sources":["../../src/withModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA8B,MAAM,YAAY,CAAA;AAE1E,eAAO,MAAM,WAAW;mGAIV,GAAG;CAOhB,CAAA;AAED,eAAO,MAAM,UAAU,kCATT,GAAG,6EASqC,CAAA;AACtD,eAAO,MAAM,kBAAkB,kCAVjB,GAAG,6EAUqD,CAAA"}
|
package/package.json
CHANGED
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xyo-network/account-model": "^2.64.
|
|
14
|
-
"@xyo-network/address-payload-plugin": "^2.64.
|
|
15
|
-
"@xyo-network/boundwitness-model": "^2.64.
|
|
16
|
-
"@xyo-network/core": "^2.64.
|
|
17
|
-
"@xyo-network/manifest-model": "^2.64.
|
|
18
|
-
"@xyo-network/module-events": "^2.64.
|
|
19
|
-
"@xyo-network/payload-model": "^2.64.
|
|
20
|
-
"@xyo-network/promise": "^2.64.
|
|
21
|
-
"@xyo-network/wallet-model": "^2.64.
|
|
13
|
+
"@xyo-network/account-model": "^2.64.7",
|
|
14
|
+
"@xyo-network/address-payload-plugin": "^2.64.7",
|
|
15
|
+
"@xyo-network/boundwitness-model": "^2.64.7",
|
|
16
|
+
"@xyo-network/core": "^2.64.7",
|
|
17
|
+
"@xyo-network/manifest-model": "^2.64.7",
|
|
18
|
+
"@xyo-network/module-events": "^2.64.7",
|
|
19
|
+
"@xyo-network/payload-model": "^2.64.7",
|
|
20
|
+
"@xyo-network/promise": "^2.64.7",
|
|
21
|
+
"@xyo-network/wallet-model": "^2.64.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@xylabs/ts-scripts-yarn3": "^2.18.5",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
},
|
|
59
59
|
"sideEffects": false,
|
|
60
60
|
"types": "dist/types/index.d.ts",
|
|
61
|
-
"version": "2.64.
|
|
61
|
+
"version": "2.64.7"
|
|
62
62
|
}
|
package/src/Module.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { AnyConfigSchema, ModuleConfig } from './Config'
|
|
|
8
8
|
import { ModuleFilter } from './ModuleFilter'
|
|
9
9
|
import { ModuleParams } from './ModuleParams'
|
|
10
10
|
import { ModuleQueryResult } from './ModuleQueryResult'
|
|
11
|
+
import { AddressPreviousHashPayload } from './Queries'
|
|
11
12
|
import { QueryBoundWitness } from './Query'
|
|
12
13
|
|
|
13
14
|
export interface ModuleResolver {
|
|
@@ -19,15 +20,18 @@ export interface ModuleResolver {
|
|
|
19
20
|
* is supplied, all modules are returned
|
|
20
21
|
* @param filter Filter criteria for the desired modules
|
|
21
22
|
*/
|
|
22
|
-
resolve<T extends
|
|
23
|
+
resolve<T extends ModuleInstance = ModuleInstance>(filter?: ModuleFilter): Promisable<T[]>
|
|
23
24
|
/**
|
|
24
25
|
* Resolves a single module, or undefined if no modules matched the filter.
|
|
25
26
|
* @param filter The desired Module's Address or Name
|
|
26
27
|
*/
|
|
27
|
-
resolveOne<T extends
|
|
28
|
+
resolveOne<T extends ModuleInstance = ModuleInstance>(filter: string): Promisable<T | undefined>
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
export type ModuleEventArgs<
|
|
31
|
+
export type ModuleEventArgs<
|
|
32
|
+
TModule extends ModuleInstance = ModuleInstance,
|
|
33
|
+
TArgs extends EventArgs | undefined = undefined,
|
|
34
|
+
> = TArgs extends EventArgs
|
|
31
35
|
? {
|
|
32
36
|
module: TModule
|
|
33
37
|
} & TArgs
|
|
@@ -36,7 +40,7 @@ export type ModuleEventArgs<TModule extends Module = Module, TArgs extends Event
|
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
export type ModuleQueriedEventArgs = ModuleEventArgs<
|
|
39
|
-
|
|
43
|
+
ModuleInstance,
|
|
40
44
|
{
|
|
41
45
|
payloads?: Payload[]
|
|
42
46
|
query: QueryBoundWitness
|
|
@@ -48,8 +52,13 @@ export interface ModuleEventData extends EventData {
|
|
|
48
52
|
moduleQueried: ModuleQueriedEventArgs
|
|
49
53
|
}
|
|
50
54
|
|
|
55
|
+
export type ModuleQueryFunctions = {
|
|
56
|
+
addressPreviousHash: () => Promisable<AddressPreviousHashPayload>
|
|
57
|
+
discover: () => Promisable<Payload[]>
|
|
58
|
+
manifest: () => Promisable<ModuleManifest>
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
export type ModuleFields<TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>> = {
|
|
52
|
-
account?: AccountInstance
|
|
53
62
|
address: string
|
|
54
63
|
config: TParams['config']
|
|
55
64
|
|
|
@@ -58,8 +67,6 @@ export type ModuleFields<TParams extends ModuleParams<AnyConfigSchema<ModuleConf
|
|
|
58
67
|
|
|
59
68
|
loadAccount?: () => Promisable<AccountInstance>
|
|
60
69
|
|
|
61
|
-
manifest: () => Promisable<ModuleManifest>
|
|
62
|
-
|
|
63
70
|
params: TParams
|
|
64
71
|
|
|
65
72
|
queries: string[]
|
|
@@ -84,4 +91,9 @@ export type ModuleFields<TParams extends ModuleParams<AnyConfigSchema<ModuleConf
|
|
|
84
91
|
export type Module<
|
|
85
92
|
TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>,
|
|
86
93
|
TEventData extends ModuleEventData = ModuleEventData,
|
|
87
|
-
> = ModuleFields<TParams> & EventFunctions<TEventData>
|
|
94
|
+
> = ModuleFields<TParams> & EventFunctions<TEventData> & ModuleQueryFunctions
|
|
95
|
+
|
|
96
|
+
export type ModuleInstance<
|
|
97
|
+
TParams extends ModuleParams<AnyConfigSchema<ModuleConfig>> = ModuleParams<AnyConfigSchema<ModuleConfig>>,
|
|
98
|
+
TEventData extends ModuleEventData = ModuleEventData,
|
|
99
|
+
> = Module<TParams, TEventData>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Query } from '../../Query'
|
|
2
|
+
|
|
3
|
+
export type ModuleAddressQuerySchema = 'network.xyo.query.module.address'
|
|
4
|
+
export const ModuleAddressQuerySchema: ModuleAddressQuerySchema = 'network.xyo.query.module.address'
|
|
5
|
+
|
|
6
|
+
export type ModuleAddressQuery = Query<{
|
|
7
|
+
schema: ModuleAddressQuerySchema
|
|
8
|
+
}>
|
package/src/Queries/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Query } from '../Query'
|
|
2
2
|
import { ModuleDiscoverQuery } from './Discover'
|
|
3
|
-
import {
|
|
3
|
+
import { ModuleAddressQuery } from './ModuleAddress'
|
|
4
4
|
import { ModuleSubscribeQuery } from './Subscribe'
|
|
5
5
|
|
|
6
6
|
export * from './Discover'
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './ModuleAddress'
|
|
8
8
|
export * from './Subscribe'
|
|
9
9
|
|
|
10
|
-
export type ModuleQueryBase = ModuleDiscoverQuery |
|
|
10
|
+
export type ModuleQueryBase = ModuleDiscoverQuery | ModuleAddressQuery | ModuleSubscribeQuery
|
|
11
11
|
|
|
12
12
|
export type ModuleQuery<T extends Query | void = void> = T extends Query ? ModuleQueryBase | T : ModuleQueryBase
|
package/src/isModule.ts
CHANGED
|
@@ -1,24 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { ModuleInstance } from './Module'
|
|
3
|
+
import { ModuleAddressQuerySchema, ModuleDiscoverQuerySchema } from './Queries'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
export type InstanceTypeCheck<T extends object = object> = (module: object) => module is T
|
|
6
|
+
|
|
7
|
+
export type ModuleTypeCheck<T extends ModuleInstance = ModuleInstance> = InstanceTypeCheck<T>
|
|
8
|
+
|
|
9
|
+
export type FieldType = 'string' | 'number' | 'object' | 'symbol' | 'symbol' | 'undefined' | 'null' | 'array' | 'function' | 'payload'
|
|
10
|
+
|
|
11
|
+
export type InstanceTypeShape = Record<string | number | symbol, FieldType>
|
|
12
|
+
|
|
13
|
+
export const isType = (value: any, expectedType: FieldType) => {
|
|
14
|
+
if (expectedType === 'array') {
|
|
15
|
+
return Array.isArray(value)
|
|
16
|
+
} else if (expectedType === 'payload') {
|
|
17
|
+
return typeof value === 'object' && typeof value.schema === 'string'
|
|
18
|
+
} else {
|
|
19
|
+
return typeof value === expectedType
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const IsInstanceFactory = {
|
|
24
|
+
create: <T extends object = object>(shape?: InstanceTypeShape, additionalCheck?: (module: any) => boolean): InstanceTypeCheck<T> => {
|
|
25
|
+
return (module: any): module is T => {
|
|
26
|
+
return (
|
|
27
|
+
(additionalCheck?.(module) ?? true) &&
|
|
28
|
+
(Object.entries(shape ?? {}).reduce((prev, [key, type]) => prev && isType(module[key], type), true) ?? true)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}
|
|
5
33
|
|
|
6
34
|
export const IsModuleFactory = {
|
|
7
|
-
create: <T extends
|
|
8
|
-
baseCheck?: ModuleTypeCheck,
|
|
9
|
-
expectedFunctions?: string[],
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
additionalCheck?: (module: any) => boolean,
|
|
12
|
-
): ModuleTypeCheck<T> => {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
create: <T extends ModuleInstance = ModuleInstance>(expectedQueries?: string[], additionalCheck?: (module: any) => boolean): ModuleTypeCheck<T> => {
|
|
14
36
|
return (module: any): module is T => {
|
|
15
37
|
return (
|
|
16
|
-
(
|
|
38
|
+
isModuleInstance(module) &&
|
|
17
39
|
(additionalCheck?.(module) ?? true) &&
|
|
18
|
-
(
|
|
40
|
+
(expectedQueries?.reduce((prev, query) => prev && module.queries.includes(query), true) ?? true)
|
|
19
41
|
)
|
|
20
42
|
}
|
|
21
43
|
},
|
|
22
44
|
}
|
|
23
45
|
|
|
24
|
-
export const
|
|
46
|
+
export const isModuleInstance: InstanceTypeCheck<ModuleInstance> = IsInstanceFactory.create<ModuleInstance>({
|
|
47
|
+
account: 'object',
|
|
48
|
+
address: 'string',
|
|
49
|
+
config: 'object',
|
|
50
|
+
discover: 'function',
|
|
51
|
+
downResolver: 'object',
|
|
52
|
+
manifest: 'function',
|
|
53
|
+
params: 'object',
|
|
54
|
+
queries: 'array',
|
|
55
|
+
query: 'function',
|
|
56
|
+
queryable: 'function',
|
|
57
|
+
upResolver: 'object',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
export const isModule: ModuleTypeCheck<ModuleInstance> = IsModuleFactory.create<ModuleInstance>([ModuleAddressQuerySchema, ModuleDiscoverQuerySchema])
|
package/src/withModule.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { isModule,
|
|
2
|
-
import { Module } from './Module'
|
|
1
|
+
import { InstanceTypeCheck, isModule, isModuleInstance } from './isModule'
|
|
3
2
|
|
|
4
|
-
export const
|
|
5
|
-
create: <T extends
|
|
3
|
+
export const WithFactory = {
|
|
4
|
+
create: <T extends object>(typeCheck: InstanceTypeCheck<T>) => {
|
|
6
5
|
return <R extends void = void>(
|
|
7
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
7
|
module: any,
|
|
9
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
closure: (module:
|
|
9
|
+
closure: (module: T) => R,
|
|
11
10
|
): R | undefined => {
|
|
12
11
|
return typeCheck(module) ? closure(module) : undefined
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
export const withModule =
|
|
16
|
+
export const withModule = WithFactory.create(isModule)
|
|
17
|
+
export const withModuleInstance = WithFactory.create(isModuleInstance)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAccount/Query.ts"],"names":[],"mappings":";;;AAGa,QAAA,wBAAwB,GAA6B,kCAAkC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAccount/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,kDAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAccount/Query.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAA6B,kCAAkC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/Queries/ModuleAccount/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Query } from '../../Query';
|
|
2
|
-
export type ModuleAccountQuerySchema = 'network.xyo.query.module.account';
|
|
3
|
-
export declare const ModuleAccountQuerySchema: ModuleAccountQuerySchema;
|
|
4
|
-
export type ModuleAccountQuery = Query<{
|
|
5
|
-
schema: ModuleAccountQuerySchema;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=Query.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Queries/ModuleAccount/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Query } from '../../Query'
|
|
2
|
-
|
|
3
|
-
export type ModuleAccountQuerySchema = 'network.xyo.query.module.account'
|
|
4
|
-
export const ModuleAccountQuerySchema: ModuleAccountQuerySchema = 'network.xyo.query.module.account'
|
|
5
|
-
|
|
6
|
-
export type ModuleAccountQuery = Query<{
|
|
7
|
-
schema: ModuleAccountQuerySchema
|
|
8
|
-
}>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|