@xyo-network/react-node 2.45.0-rc.3 → 2.45.0-rc.4
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/hooks/createUseModuleHook.js +6 -3
- package/dist/cjs/hooks/createUseModuleHook.js.map +1 -1
- package/dist/docs.json +356 -155
- package/dist/esm/hooks/createUseModuleHook.js +6 -3
- package/dist/esm/hooks/createUseModuleHook.js.map +1 -1
- package/dist/types/hooks/createUseModuleHook.d.ts +1 -0
- package/dist/types/hooks/createUseModuleHook.d.ts.map +1 -1
- package/dist/types/hooks/useModule.d.ts +11 -0
- package/dist/types/hooks/useModule.d.ts.map +1 -1
- package/dist/types/hooks/useNode.d.ts +1 -0
- package/dist/types/hooks/useNode.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/hooks/createUseModuleHook.tsx +10 -3
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { useAsyncEffect } from '@xylabs/react-shared';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
export const createUseModuleHook = (wrapFunc, useNodeHook) => {
|
|
5
|
-
function use(
|
|
5
|
+
function use(nameOrAddressOrWrapOrAccount, wrap = false) {
|
|
6
|
+
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap;
|
|
7
|
+
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap;
|
|
8
|
+
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined;
|
|
6
9
|
const [node, nodeError] = useNodeHook(nameOrAddress, true);
|
|
7
10
|
const [module, setModule] = useState();
|
|
8
11
|
const [error, setError] = useState();
|
|
@@ -16,7 +19,7 @@ export const createUseModuleHook = (wrapFunc, useNodeHook) => {
|
|
|
16
19
|
}
|
|
17
20
|
else {
|
|
18
21
|
const module = await node?.resolve(nameOrAddress);
|
|
19
|
-
const finalModule =
|
|
22
|
+
const finalModule = shouldWrap ? wrapFunc(module, account) : module;
|
|
20
23
|
if (mounted()) {
|
|
21
24
|
setModule(finalModule);
|
|
22
25
|
}
|
|
@@ -28,7 +31,7 @@ export const createUseModuleHook = (wrapFunc, useNodeHook) => {
|
|
|
28
31
|
setModule(undefined);
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
}, [wrap, node, nameOrAddress, nodeError]);
|
|
34
|
+
}, [wrap, node, nameOrAddress, nodeError, shouldWrap, account]);
|
|
32
35
|
return [module, error];
|
|
33
36
|
}
|
|
34
37
|
return use;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUseModuleHook.js","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAIrD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAOhC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAKjC,QAAmB,EACnB,WAA4G,EAC5G,EAAE;
|
|
1
|
+
{"version":3,"file":"createUseModuleHook.js","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAIrD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAOhC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAKjC,QAAmB,EACnB,WAA4G,EAC5G,EAAE;IAMF,SAAS,GAAG,CACV,4BAAyD,EACzD,OAA0B,KAAK;QAE/B,MAAM,UAAU,GAAG,OAAO,4BAA4B,KAAK,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAI,CAAA;QAC1G,MAAM,OAAO,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4B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AA;AACZ,CAAC,CAAA"}
|
|
@@ -45,6 +45,7 @@ export declare const createUseModuleHook: <TModule extends Module<import("@xyo-n
|
|
|
45
45
|
}>>, TWrapFunc extends WrapFunc<TModule, TWrapper> = WrapFunc<TModule, TWrapper>>(wrapFunc: TWrapFunc, useNodeHook: (nodeOrAddress: string | undefined, wrap: true) => [NodeWrapper | undefined, Error | undefined]) => {
|
|
46
46
|
(name?: string): [TModule | undefined, Error | undefined];
|
|
47
47
|
(name: string | undefined, wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
48
|
+
(wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
48
49
|
(address: string): [TModule | undefined, Error | undefined];
|
|
49
50
|
(address: string, wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
50
51
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUseModuleHook.d.ts","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,MAAM,QAAQ,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI,CACtG,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,KACd,QAAQ,GAAG,SAAS,CAAA;AAEzB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oIAMD,MAAM,GAAG,SAAS,QAAQ,IAAI,KAAK,CAAC,WAAW,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC;YAExF,MAAM;WACP,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"createUseModuleHook.d.ts","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,MAAM,QAAQ,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI,CACtG,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,KACd,QAAQ,GAAG,SAAS,CAAA;AAEzB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oIAMD,MAAM,GAAG,SAAS,QAAQ,IAAI,KAAK,CAAC,WAAW,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC;YAExF,MAAM;WACP,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,OAAO;WACxC,IAAI,GAAG,OAAO;cACX,MAAM;cACN,MAAM,QAAQ,IAAI,GAAG,OAAO;CAsCnD,CAAA"}
|
|
@@ -22,6 +22,17 @@ export declare const useModule: {
|
|
|
22
22
|
} & {
|
|
23
23
|
schema: string;
|
|
24
24
|
}>> | undefined, Error | undefined];
|
|
25
|
+
(wrap: true | import("@xyo-network/account").Account): [ModuleWrapper<Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
26
|
+
name?: string | undefined;
|
|
27
|
+
security?: {
|
|
28
|
+
allowAnonymous?: boolean | undefined;
|
|
29
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
30
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
storeQueries?: boolean | undefined;
|
|
33
|
+
} & {
|
|
34
|
+
schema: string;
|
|
35
|
+
}>> | undefined, Error | undefined];
|
|
25
36
|
(address: string): [Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
26
37
|
name?: string | undefined;
|
|
27
38
|
security?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAK3D,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"useModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAK3D,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA0E,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { NodeModule, NodeWrapper } from '@xyo-network/node';
|
|
|
2
2
|
export declare const useNode: {
|
|
3
3
|
(name?: string | undefined): [NodeModule | undefined, Error | undefined];
|
|
4
4
|
(name: string | undefined, wrap: true | import("@xyo-network/account").Account): [NodeWrapper | undefined, Error | undefined];
|
|
5
|
+
(wrap: true | import("@xyo-network/account").Account): [NodeWrapper | undefined, Error | undefined];
|
|
5
6
|
(address: string): [NodeModule | undefined, Error | undefined];
|
|
6
7
|
(address: string, wrap: true | import("@xyo-network/account").Account): [NodeWrapper | undefined, Error | undefined];
|
|
7
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAK3D,eAAO,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"useNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAK3D,eAAO,MAAM,OAAO;;;;;;CAGlB,CAAA"}
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@xyo-network/module-model": "^2.51.1",
|
|
22
22
|
"@xyo-network/node": "^2.51.1",
|
|
23
23
|
"@xyo-network/payload-model": "^2.51.1",
|
|
24
|
-
"@xyo-network/react-shared": "^2.45.0-rc.
|
|
24
|
+
"@xyo-network/react-shared": "^2.45.0-rc.4",
|
|
25
25
|
"@xyo-network/witness": "^2.51.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -83,6 +83,6 @@
|
|
|
83
83
|
},
|
|
84
84
|
"sideEffects": false,
|
|
85
85
|
"types": "dist/types/index.d.ts",
|
|
86
|
-
"version": "2.45.0-rc.
|
|
86
|
+
"version": "2.45.0-rc.4",
|
|
87
87
|
"stableVersion": "2.44.1"
|
|
88
88
|
}
|
|
@@ -20,9 +20,16 @@ export const createUseModuleHook = <
|
|
|
20
20
|
) => {
|
|
21
21
|
function use(name?: string): [TModule | undefined, Error | undefined]
|
|
22
22
|
function use(name: string | undefined, wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
23
|
+
function use(wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
23
24
|
function use(address: string): [TModule | undefined, Error | undefined]
|
|
24
25
|
function use(address: string, wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
25
|
-
function use(
|
|
26
|
+
function use(
|
|
27
|
+
nameOrAddressOrWrapOrAccount?: string | boolean | Account,
|
|
28
|
+
wrap: boolean | Account = false,
|
|
29
|
+
): [TWrapper | TModule | undefined, Error | undefined] {
|
|
30
|
+
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap
|
|
31
|
+
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap
|
|
32
|
+
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined
|
|
26
33
|
const [node, nodeError] = useNodeHook(nameOrAddress, true)
|
|
27
34
|
const [module, setModule] = useState<TModule | TWrapper>()
|
|
28
35
|
const [error, setError] = useState<Error>()
|
|
@@ -35,7 +42,7 @@ export const createUseModuleHook = <
|
|
|
35
42
|
setModule(undefined)
|
|
36
43
|
} else {
|
|
37
44
|
const module = await node?.resolve<TModule>(nameOrAddress)
|
|
38
|
-
const finalModule =
|
|
45
|
+
const finalModule = shouldWrap ? wrapFunc(module, account) : module
|
|
39
46
|
if (mounted()) {
|
|
40
47
|
setModule(finalModule)
|
|
41
48
|
}
|
|
@@ -47,7 +54,7 @@ export const createUseModuleHook = <
|
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
},
|
|
50
|
-
[wrap, node, nameOrAddress, nodeError],
|
|
57
|
+
[wrap, node, nameOrAddress, nodeError, shouldWrap, account],
|
|
51
58
|
)
|
|
52
59
|
|
|
53
60
|
return [module, error]
|