@xyo-network/react-payload-plugin 2.38.11 → 2.38.12
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/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/docs.json +273 -541
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +0 -1
- package/dist/cjs/hooks/index.d.ts +0 -2
- package/dist/cjs/hooks/index.d.ts.map +0 -1
- package/dist/cjs/hooks/index.js +0 -5
- package/dist/cjs/hooks/index.js.map +0 -1
- package/dist/cjs/hooks/useGetSchema.d.ts +0 -22
- package/dist/cjs/hooks/useGetSchema.d.ts.map +0 -1
- package/dist/cjs/hooks/useGetSchema.js +0 -51
- package/dist/cjs/hooks/useGetSchema.js.map +0 -1
- package/dist/esm/hooks/index.d.ts +0 -2
- package/dist/esm/hooks/index.d.ts.map +0 -1
- package/dist/esm/hooks/index.js +0 -2
- package/dist/esm/hooks/index.js.map +0 -1
- package/dist/esm/hooks/useGetSchema.d.ts +0 -22
- package/dist/esm/hooks/useGetSchema.d.ts.map +0 -1
- package/dist/esm/hooks/useGetSchema.js +0 -47
- package/dist/esm/hooks/useGetSchema.js.map +0 -1
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useGetSchema.stories.tsx +0 -76
- package/src/hooks/useGetSchema.tsx +0 -54
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './components';
|
|
|
2
2
|
export * from './contexts';
|
|
3
3
|
export * from './createPayloadRenderPlugin';
|
|
4
4
|
export * from './DefaultPayloadRenderPlugin';
|
|
5
|
-
export * from './hooks';
|
|
6
5
|
export * from './XyoPayloadRenderPlugin';
|
|
7
6
|
export * from './XyoPayloadRenderPluginResolver';
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,0BAA0B,CAAA;AACxC,cAAc,kCAAkC,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export * from './components';
|
|
|
2
2
|
export * from './contexts';
|
|
3
3
|
export * from './createPayloadRenderPlugin';
|
|
4
4
|
export * from './DefaultPayloadRenderPlugin';
|
|
5
|
-
export * from './hooks';
|
|
6
5
|
export * from './XyoPayloadRenderPlugin';
|
|
7
6
|
export * from './XyoPayloadRenderPluginResolver';
|
|
8
7
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,0BAA0B,CAAA;AACxC,cAAc,kCAAkC,CAAA"}
|
package/package.json
CHANGED
|
@@ -12,10 +12,9 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/react-flexbox": "^2.15.1",
|
|
14
14
|
"@xylabs/react-identicon": "^2.15.1",
|
|
15
|
-
"@xylabs/react-shared": "^2.15.1",
|
|
16
15
|
"@xylabs/sdk-js": "^2.6.9",
|
|
17
|
-
"@xyo-network/react-payload-details": "^2.38.
|
|
18
|
-
"@xyo-network/react-shared": "^2.38.
|
|
16
|
+
"@xyo-network/react-payload-details": "^2.38.12",
|
|
17
|
+
"@xyo-network/react-shared": "^2.38.12",
|
|
19
18
|
"lodash": "^4.17.21",
|
|
20
19
|
"tslib": "^2.4.0"
|
|
21
20
|
},
|
|
@@ -23,7 +22,8 @@
|
|
|
23
22
|
"@mui/icons-material": "^5.10.3",
|
|
24
23
|
"@mui/material": "^5.10.3",
|
|
25
24
|
"@mui/styles": "^5.10.3",
|
|
26
|
-
"@xyo-network/
|
|
25
|
+
"@xyo-network/diviner": "*",
|
|
26
|
+
"@xyo-network/module": "*",
|
|
27
27
|
"@xyo-network/payload": "*",
|
|
28
28
|
"@xyo-network/payload-plugin": "*",
|
|
29
29
|
"@xyo-network/schema-payload-plugin": "*",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
},
|
|
78
78
|
"sideEffects": false,
|
|
79
79
|
"types": "dist/esm/index.d.ts",
|
|
80
|
-
"version": "2.38.
|
|
80
|
+
"version": "2.38.12"
|
|
81
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
package/dist/cjs/hooks/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { XyoApiError } from '@xyo-network/api';
|
|
2
|
-
/**
|
|
3
|
-
* Gets a Huri and schema payload from a schema string
|
|
4
|
-
*/
|
|
5
|
-
declare const useGetSchemaPayload: (schema?: string) => {
|
|
6
|
-
apiError: XyoApiError<any, any> | undefined;
|
|
7
|
-
notFound: boolean;
|
|
8
|
-
schemaHuri: import("@xyo-network/payload").Huri<import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & {
|
|
9
|
-
schema: string;
|
|
10
|
-
}> | undefined;
|
|
11
|
-
schemaPayload: (import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & {
|
|
12
|
-
definition: {
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
$id?: string | undefined;
|
|
15
|
-
};
|
|
16
|
-
extends?: string | undefined;
|
|
17
|
-
name?: string | undefined;
|
|
18
|
-
schema: "network.xyo.schema";
|
|
19
|
-
}) | null | undefined;
|
|
20
|
-
};
|
|
21
|
-
export { useGetSchemaPayload };
|
|
22
|
-
//# sourceMappingURL=useGetSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSchema.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetSchema.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAM9C;;GAEG;AACH,QAAA,MAAM,mBAAmB,YAAa,MAAM;;;;;;;;;;;;;;;CAyC3C,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useGetSchemaPayload = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const react_shared_1 = require("@xylabs/react-shared");
|
|
6
|
-
const payload_1 = require("@xyo-network/payload");
|
|
7
|
-
const utils_1 = require("@xyo-network/utils");
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
/**
|
|
10
|
-
* Gets a Huri and schema payload from a schema string
|
|
11
|
-
*/
|
|
12
|
-
const useGetSchemaPayload = (schema) => {
|
|
13
|
-
const [notFound, setNotFound] = (0, react_1.useState)(false);
|
|
14
|
-
const [apiError, setApiError] = (0, react_1.useState)();
|
|
15
|
-
const [schemaCacheEntry, setSchemaCacheEntry] = (0, react_1.useState)();
|
|
16
|
-
const [schemaLocal, setSchemaLocal] = (0, react_1.useState)();
|
|
17
|
-
(0, react_shared_1.useAsyncEffect)(
|
|
18
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
-
(mounted) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const firstRequest = !notFound && !schemaCacheEntry && !apiError;
|
|
21
|
-
const schemaChanged = schema !== schemaLocal;
|
|
22
|
-
if ((schema && firstRequest) || (schema && schemaChanged)) {
|
|
23
|
-
try {
|
|
24
|
-
const schemaCacheEntry = yield utils_1.XyoSchemaCache.instance.get(schema);
|
|
25
|
-
if (mounted()) {
|
|
26
|
-
setSchemaCacheEntry(schemaCacheEntry);
|
|
27
|
-
setNotFound(schemaCacheEntry === null || schemaCacheEntry === undefined);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
console.error(e);
|
|
32
|
-
if (mounted()) {
|
|
33
|
-
setApiError(e);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (schemaChanged) {
|
|
38
|
-
setSchemaLocal(schema);
|
|
39
|
-
}
|
|
40
|
-
}), [apiError, notFound, schema, schemaLocal, schemaCacheEntry]);
|
|
41
|
-
return {
|
|
42
|
-
apiError,
|
|
43
|
-
notFound,
|
|
44
|
-
schemaHuri: schemaCacheEntry === null || schemaCacheEntry === void 0 ? void 0 : schemaCacheEntry.huri,
|
|
45
|
-
schemaPayload: schemaCacheEntry
|
|
46
|
-
? new payload_1.XyoPayloadBuilder(schemaCacheEntry === null || schemaCacheEntry === void 0 ? void 0 : schemaCacheEntry.payload).fields(schemaCacheEntry.payload).build()
|
|
47
|
-
: schemaCacheEntry,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.useGetSchemaPayload = useGetSchemaPayload;
|
|
51
|
-
//# sourceMappingURL=useGetSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSchema.js","sourceRoot":"","sources":["../../../src/hooks/useGetSchema.tsx"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAErD,kDAAwD;AAExD,8CAAwE;AACxE,iCAAgC;AAEhC;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,MAAe,EAAE,EAAE;IAC9C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAA;IAC/C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,GAAe,CAAA;IACvD,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,IAAA,gBAAQ,GAA0C,CAAA;IAClG,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,GAAU,CAAA;IAExD,IAAA,6BAAc;IACZ,uDAAuD;IACvD,CAAO,OAAO,EAAE,EAAE;QAChB,MAAM,YAAY,GAAG,CAAC,QAAQ,IAAI,CAAC,gBAAgB,IAAI,CAAC,QAAQ,CAAA;QAChE,MAAM,aAAa,GAAG,MAAM,KAAK,WAAW,CAAA;QAE5C,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,EAAE;YACzD,IAAI;gBACF,MAAM,gBAAgB,GAAG,MAAM,sBAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBAClE,IAAI,OAAO,EAAE,EAAE;oBACb,mBAAmB,CAAC,gBAAgB,CAAC,CAAA;oBACrC,WAAW,CAAC,gBAAgB,KAAK,IAAI,IAAI,gBAAgB,KAAK,SAAS,CAAC,CAAA;iBACzE;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBAChB,IAAI,OAAO,EAAE,EAAE;oBACb,WAAW,CAAC,CAAgB,CAAC,CAAA;iBAC9B;aACF;SACF;QACD,IAAI,aAAa,EAAE;YACjB,cAAc,CAAC,MAAM,CAAC,CAAA;SACvB;IACH,CAAC,CAAA,EACD,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAC5D,CAAA;IAED,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,UAAU,EAAE,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,IAAI;QAClC,aAAa,EAAE,gBAAgB;YAC7B,CAAC,CAAC,IAAI,2BAAiB,CAAmB,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,OAAO,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE;YAC7G,CAAC,CAAC,gBAAgB;KACrB,CAAA;AACH,CAAC,CAAA;AAEQ,kDAAmB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
package/dist/esm/hooks/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { XyoApiError } from '@xyo-network/api';
|
|
2
|
-
/**
|
|
3
|
-
* Gets a Huri and schema payload from a schema string
|
|
4
|
-
*/
|
|
5
|
-
declare const useGetSchemaPayload: (schema?: string) => {
|
|
6
|
-
apiError: XyoApiError<any, any> | undefined;
|
|
7
|
-
notFound: boolean;
|
|
8
|
-
schemaHuri: import("@xyo-network/payload").Huri<import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & {
|
|
9
|
-
schema: string;
|
|
10
|
-
}> | undefined;
|
|
11
|
-
schemaPayload: (import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & {
|
|
12
|
-
definition: {
|
|
13
|
-
[key: string]: unknown;
|
|
14
|
-
$id?: string | undefined;
|
|
15
|
-
};
|
|
16
|
-
extends?: string | undefined;
|
|
17
|
-
name?: string | undefined;
|
|
18
|
-
schema: "network.xyo.schema";
|
|
19
|
-
}) | null | undefined;
|
|
20
|
-
};
|
|
21
|
-
export { useGetSchemaPayload };
|
|
22
|
-
//# sourceMappingURL=useGetSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSchema.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetSchema.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAM9C;;GAEG;AACH,QAAA,MAAM,mBAAmB,YAAa,MAAM;;;;;;;;;;;;;;;CAyC3C,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useAsyncEffect } from '@xylabs/react-shared';
|
|
2
|
-
import { XyoPayloadBuilder } from '@xyo-network/payload';
|
|
3
|
-
import { XyoSchemaCache } from '@xyo-network/utils';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
/**
|
|
6
|
-
* Gets a Huri and schema payload from a schema string
|
|
7
|
-
*/
|
|
8
|
-
const useGetSchemaPayload = (schema) => {
|
|
9
|
-
const [notFound, setNotFound] = useState(false);
|
|
10
|
-
const [apiError, setApiError] = useState();
|
|
11
|
-
const [schemaCacheEntry, setSchemaCacheEntry] = useState();
|
|
12
|
-
const [schemaLocal, setSchemaLocal] = useState();
|
|
13
|
-
useAsyncEffect(
|
|
14
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
|
-
async (mounted) => {
|
|
16
|
-
const firstRequest = !notFound && !schemaCacheEntry && !apiError;
|
|
17
|
-
const schemaChanged = schema !== schemaLocal;
|
|
18
|
-
if ((schema && firstRequest) || (schema && schemaChanged)) {
|
|
19
|
-
try {
|
|
20
|
-
const schemaCacheEntry = await XyoSchemaCache.instance.get(schema);
|
|
21
|
-
if (mounted()) {
|
|
22
|
-
setSchemaCacheEntry(schemaCacheEntry);
|
|
23
|
-
setNotFound(schemaCacheEntry === null || schemaCacheEntry === undefined);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
console.error(e);
|
|
28
|
-
if (mounted()) {
|
|
29
|
-
setApiError(e);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (schemaChanged) {
|
|
34
|
-
setSchemaLocal(schema);
|
|
35
|
-
}
|
|
36
|
-
}, [apiError, notFound, schema, schemaLocal, schemaCacheEntry]);
|
|
37
|
-
return {
|
|
38
|
-
apiError,
|
|
39
|
-
notFound,
|
|
40
|
-
schemaHuri: schemaCacheEntry?.huri,
|
|
41
|
-
schemaPayload: schemaCacheEntry
|
|
42
|
-
? new XyoPayloadBuilder(schemaCacheEntry?.payload).fields(schemaCacheEntry.payload).build()
|
|
43
|
-
: schemaCacheEntry,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
export { useGetSchemaPayload };
|
|
47
|
-
//# sourceMappingURL=useGetSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSchema.js","sourceRoot":"","sources":["../../../src/hooks/useGetSchema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,EAAE,cAAc,EAAuB,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,MAAe,EAAE,EAAE;IAC9C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC/C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,EAAe,CAAA;IACvD,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,EAA0C,CAAA;IAClG,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAU,CAAA;IAExD,cAAc;IACZ,uDAAuD;IACvD,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,MAAM,YAAY,GAAG,CAAC,QAAQ,IAAI,CAAC,gBAAgB,IAAI,CAAC,QAAQ,CAAA;QAChE,MAAM,aAAa,GAAG,MAAM,KAAK,WAAW,CAAA;QAE5C,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,EAAE;YACzD,IAAI;gBACF,MAAM,gBAAgB,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBAClE,IAAI,OAAO,EAAE,EAAE;oBACb,mBAAmB,CAAC,gBAAgB,CAAC,CAAA;oBACrC,WAAW,CAAC,gBAAgB,KAAK,IAAI,IAAI,gBAAgB,KAAK,SAAS,CAAC,CAAA;iBACzE;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBAChB,IAAI,OAAO,EAAE,EAAE;oBACb,WAAW,CAAC,CAAgB,CAAC,CAAA;iBAC9B;aACF;SACF;QACD,IAAI,aAAa,EAAE;YACjB,cAAc,CAAC,MAAM,CAAC,CAAA;SACvB;IACH,CAAC,EACD,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAC5D,CAAA;IAED,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,UAAU,EAAE,gBAAgB,EAAE,IAAI;QAClC,aAAa,EAAE,gBAAgB;YAC7B,CAAC,CAAC,IAAI,iBAAiB,CAAmB,gBAAgB,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE;YAC7G,CAAC,CAAC,gBAAgB;KACrB,CAAA;AACH,CAAC,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
package/src/hooks/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useGetSchema'
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { FormControl, TextField, Typography } from '@mui/material'
|
|
2
|
-
import { ComponentStory, Meta } from '@storybook/react'
|
|
3
|
-
import { FlexCol, FlexRow } from '@xylabs/react-flexbox'
|
|
4
|
-
import { XyoSchemaCache } from '@xyo-network/utils'
|
|
5
|
-
import { lazy, Suspense, useEffect, useState } from 'react'
|
|
6
|
-
|
|
7
|
-
import { useGetSchemaPayload } from './useGetSchema'
|
|
8
|
-
|
|
9
|
-
const JsonView = lazy(() => import(/* webpackChunkName: "jsonView" */ 'react-json-view'))
|
|
10
|
-
|
|
11
|
-
XyoSchemaCache.instance.proxy = 'https://beta.api.archivist.xyo.network/domain'
|
|
12
|
-
|
|
13
|
-
const UseGetSchemaComponent: React.FC<{ schema: string }> = ({ schema }) => {
|
|
14
|
-
const exampleSchemas = ['network.xyo.domain', 'network.xyo.payload', 'network.xyo.schema']
|
|
15
|
-
const [schemaFieldValue, setSchemaFieldValue] = useState('')
|
|
16
|
-
const { schemaPayload } = useGetSchemaPayload(schemaFieldValue)
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (schema) {
|
|
20
|
-
setSchemaFieldValue(schema)
|
|
21
|
-
}
|
|
22
|
-
}, [schema])
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<>
|
|
26
|
-
<Typography variant="body1" fontWeight="bold" mb={2}>
|
|
27
|
-
Example schemas to test:
|
|
28
|
-
{exampleSchemas.map((schema, index) => (
|
|
29
|
-
<Typography
|
|
30
|
-
component="span"
|
|
31
|
-
mx={1}
|
|
32
|
-
key={index}
|
|
33
|
-
onClick={() => setSchemaFieldValue(schema)}
|
|
34
|
-
sx={{ cursor: 'pointer', textDecoration: 'underline' }}
|
|
35
|
-
>
|
|
36
|
-
{schema}
|
|
37
|
-
</Typography>
|
|
38
|
-
))}
|
|
39
|
-
</Typography>
|
|
40
|
-
<FormControl>
|
|
41
|
-
<TextField value={schemaFieldValue} label="Schema Name" onChange={(e) => setSchemaFieldValue(e.target.value)} />
|
|
42
|
-
</FormControl>
|
|
43
|
-
<FlexRow my={3} justifyContent="start">
|
|
44
|
-
<Suspense fallback={<FlexCol busy />}>
|
|
45
|
-
<JsonView src={schemaPayload || {}} />
|
|
46
|
-
</Suspense>
|
|
47
|
-
</FlexRow>
|
|
48
|
-
</>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const StorybookEntry: Meta = {
|
|
53
|
-
argTypes: {},
|
|
54
|
-
component: UseGetSchemaComponent,
|
|
55
|
-
parameters: {
|
|
56
|
-
docs: {
|
|
57
|
-
page: null,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
title: 'payload/useGetSchema',
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const Template: ComponentStory<typeof UseGetSchemaComponent> = ({ schema }) => {
|
|
64
|
-
return <UseGetSchemaComponent schema={schema} />
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const Default = Template.bind({})
|
|
68
|
-
Default.args = { schema: 'network.xyo.schema' }
|
|
69
|
-
|
|
70
|
-
const Domain = Template.bind({})
|
|
71
|
-
Domain.args = { schema: 'network.xyo.domain' }
|
|
72
|
-
|
|
73
|
-
export { Default, Domain }
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line import/no-default-export
|
|
76
|
-
export default StorybookEntry
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
2
|
-
import { XyoApiError } from '@xyo-network/api'
|
|
3
|
-
import { XyoPayloadBuilder } from '@xyo-network/payload'
|
|
4
|
-
import { XyoSchemaPayload } from '@xyo-network/schema-payload-plugin'
|
|
5
|
-
import { XyoSchemaCache, XyoSchemaCacheEntry } from '@xyo-network/utils'
|
|
6
|
-
import { useState } from 'react'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Gets a Huri and schema payload from a schema string
|
|
10
|
-
*/
|
|
11
|
-
const useGetSchemaPayload = (schema?: string) => {
|
|
12
|
-
const [notFound, setNotFound] = useState(false)
|
|
13
|
-
const [apiError, setApiError] = useState<XyoApiError>()
|
|
14
|
-
const [schemaCacheEntry, setSchemaCacheEntry] = useState<XyoSchemaCacheEntry | null | undefined>()
|
|
15
|
-
const [schemaLocal, setSchemaLocal] = useState<string>()
|
|
16
|
-
|
|
17
|
-
useAsyncEffect(
|
|
18
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
-
async (mounted) => {
|
|
20
|
-
const firstRequest = !notFound && !schemaCacheEntry && !apiError
|
|
21
|
-
const schemaChanged = schema !== schemaLocal
|
|
22
|
-
|
|
23
|
-
if ((schema && firstRequest) || (schema && schemaChanged)) {
|
|
24
|
-
try {
|
|
25
|
-
const schemaCacheEntry = await XyoSchemaCache.instance.get(schema)
|
|
26
|
-
if (mounted()) {
|
|
27
|
-
setSchemaCacheEntry(schemaCacheEntry)
|
|
28
|
-
setNotFound(schemaCacheEntry === null || schemaCacheEntry === undefined)
|
|
29
|
-
}
|
|
30
|
-
} catch (e) {
|
|
31
|
-
console.error(e)
|
|
32
|
-
if (mounted()) {
|
|
33
|
-
setApiError(e as XyoApiError)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (schemaChanged) {
|
|
38
|
-
setSchemaLocal(schema)
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
[apiError, notFound, schema, schemaLocal, schemaCacheEntry],
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
apiError,
|
|
46
|
-
notFound,
|
|
47
|
-
schemaHuri: schemaCacheEntry?.huri,
|
|
48
|
-
schemaPayload: schemaCacheEntry
|
|
49
|
-
? new XyoPayloadBuilder<XyoSchemaPayload>(schemaCacheEntry?.payload).fields(schemaCacheEntry.payload).build()
|
|
50
|
-
: schemaCacheEntry,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { useGetSchemaPayload }
|