ag-common 0.0.240 → 0.0.241
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/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +3 -0
- package/dist/ui/components/{CodeBlock/CodeBlock.js → OpenApiCodeBlock/OpenApiCodeBlock.js} +4 -4
- package/dist/ui/components/OpenApiCodeBlock/helpers/body.d.ts +6 -0
- package/dist/ui/components/OpenApiCodeBlock/helpers/body.js +35 -0
- package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/helpers/common.d.ts +5 -5
- package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/helpers/common.js +9 -37
- package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/helpers/security.d.ts +2 -2
- package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/helpers/security.js +1 -3
- package/dist/ui/components/OpenApiCodeBlock/index.d.ts +2 -0
- package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/index.js +1 -1
- package/dist/ui/components/OpenApiCodeBlock/types.d.ts +35 -0
- package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/types.js +0 -0
- package/dist/ui/components/index.d.ts +1 -1
- package/dist/ui/components/index.js +1 -1
- package/package.json +1 -1
- package/dist/ui/components/CodeBlock/CodeBlock.d.ts +0 -3
- package/dist/ui/components/CodeBlock/index.d.ts +0 -2
- package/dist/ui/components/CodeBlock/types.d.ts +0 -9
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.OpenApiCodeBlock = void 0;
|
|
7
7
|
const common_1 = require("./helpers/common");
|
|
8
8
|
const FlexRow_1 = require("../FlexRow");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
@@ -41,10 +41,10 @@ const Block = styled_components_1.default.div `
|
|
|
41
41
|
const Curl = styled_components_1.default.div `
|
|
42
42
|
white-space: pre;
|
|
43
43
|
`;
|
|
44
|
-
const
|
|
44
|
+
const OpenApiCodeBlock = (p) => {
|
|
45
45
|
var _a;
|
|
46
46
|
const { path, verb, error, headerLines, fullApiUrl, bodyLine, operation } = (0, common_1.getLines)(p);
|
|
47
|
-
if (error || !verb) {
|
|
47
|
+
if (error || !verb || !operation) {
|
|
48
48
|
return react_1.default.createElement(Base, null, error);
|
|
49
49
|
}
|
|
50
50
|
return (react_1.default.createElement(Base, null,
|
|
@@ -74,4 +74,4 @@ const CodeBlock = (p) => {
|
|
|
74
74
|
react_1.default.createElement("br", null),
|
|
75
75
|
bodyLine))));
|
|
76
76
|
};
|
|
77
|
-
exports.
|
|
77
|
+
exports.OpenApiCodeBlock = OpenApiCodeBlock;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBody = void 0;
|
|
7
|
+
const common_1 = require("./common");
|
|
8
|
+
const common_2 = require("../../../../common");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const getBody = (p) => {
|
|
11
|
+
const body = p.funcF.toString();
|
|
12
|
+
const bstart = (0, common_2.indexOfNumber)(body, '(', 1);
|
|
13
|
+
const bend = !bstart ? undefined : body.lastIndexOf(')');
|
|
14
|
+
if (!bstart || !bend) {
|
|
15
|
+
return { content: undefined, header: undefined };
|
|
16
|
+
}
|
|
17
|
+
const slice = body.substring(bstart + 1, bend);
|
|
18
|
+
const json = slice.replace(/([a-zA-Z0-9-]+[^"]):/gim, '"$1":');
|
|
19
|
+
const nice = JSON.stringify(JSON.parse(json), null, 2);
|
|
20
|
+
const content = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
21
|
+
"-d @- <<'EOF'",
|
|
22
|
+
react_1.default.createElement("br", null),
|
|
23
|
+
react_1.default.createElement(common_1.Highlight2, null, nice),
|
|
24
|
+
react_1.default.createElement("br", null),
|
|
25
|
+
"EOF"));
|
|
26
|
+
const header = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
27
|
+
react_1.default.createElement("span", null, "--header "),
|
|
28
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
29
|
+
react_1.default.createElement(common_1.Highlight, null, "'Content-Type: application/json'"))));
|
|
30
|
+
return {
|
|
31
|
+
content,
|
|
32
|
+
header,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.getBody = getBody;
|
|
@@ -11,11 +11,11 @@ export declare const getLines: <TDefaultApi>(p: ICodeBlock<TDefaultApi>) => {
|
|
|
11
11
|
bodyLine?: undefined;
|
|
12
12
|
operation?: undefined;
|
|
13
13
|
} | {
|
|
14
|
-
verb: string
|
|
15
|
-
path: string
|
|
14
|
+
verb: string;
|
|
15
|
+
path: string;
|
|
16
16
|
error: undefined;
|
|
17
17
|
headerLines: JSX.Element[];
|
|
18
|
-
fullApiUrl:
|
|
19
|
-
bodyLine: JSX.Element;
|
|
20
|
-
operation:
|
|
18
|
+
fullApiUrl: string;
|
|
19
|
+
bodyLine: JSX.Element | undefined;
|
|
20
|
+
operation: import("../types").IOpenApiOperation;
|
|
21
21
|
};
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getLines = exports.Highlight2 = exports.Highlight = void 0;
|
|
7
7
|
const security_1 = require("./security");
|
|
8
|
+
const body_1 = require("./body");
|
|
8
9
|
const string_1 = require("../../../../common/helpers/string");
|
|
9
10
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
10
11
|
const react_1 = __importDefault(require("react"));
|
|
@@ -28,50 +29,22 @@ const getOperation = (p) => {
|
|
|
28
29
|
let path;
|
|
29
30
|
let verb;
|
|
30
31
|
const func = getFunctionName(p);
|
|
31
|
-
Object.entries(p.schema.paths).forEach(([pathN, ops]) =>
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
Object.entries(ops).forEach(([verbN, op]) => {
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
Object.entries(p.schema.paths).forEach(([pathN, ops]) => Object.entries(ops).forEach(([verbN, op]) => {
|
|
35
33
|
if (op.operationId === func) {
|
|
36
34
|
path = pathN;
|
|
37
35
|
verb = verbN;
|
|
38
36
|
}
|
|
39
37
|
}));
|
|
40
38
|
if (!path || !verb) {
|
|
41
|
-
return { error: 'operation not found' };
|
|
39
|
+
return { error: 'operation not found', operation: undefined };
|
|
42
40
|
}
|
|
43
41
|
const operation = p.schema.paths[path][verb];
|
|
44
42
|
return { operation, verb, path };
|
|
45
43
|
};
|
|
46
|
-
const getBody = (p) => {
|
|
47
|
-
const body = p.funcF.toString();
|
|
48
|
-
const bstart = (0, string_1.indexOfNumber)(body, '(', 1);
|
|
49
|
-
const bend = !bstart ? undefined : body.lastIndexOf(')');
|
|
50
|
-
if (!bstart || !bend) {
|
|
51
|
-
return { content: react_1.default.createElement(react_1.default.Fragment, null), header: react_1.default.createElement(react_1.default.Fragment, null) };
|
|
52
|
-
}
|
|
53
|
-
const slice = body.substring(bstart + 1, bend);
|
|
54
|
-
const json = slice.replace(/([a-zA-Z0-9-]+[^"]):/gim, '"$1":');
|
|
55
|
-
const nice = JSON.stringify(JSON.parse(json), null, 2);
|
|
56
|
-
const content = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
57
|
-
"-d @- <<'EOF'",
|
|
58
|
-
react_1.default.createElement("br", null),
|
|
59
|
-
react_1.default.createElement(exports.Highlight2, null, nice),
|
|
60
|
-
react_1.default.createElement("br", null),
|
|
61
|
-
"EOF"));
|
|
62
|
-
const header = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
63
|
-
react_1.default.createElement("span", null, "--header "),
|
|
64
|
-
react_1.default.createElement(exports.Highlight, null,
|
|
65
|
-
react_1.default.createElement(exports.Highlight, null, "'Content-Type: application/json'"))));
|
|
66
|
-
return {
|
|
67
|
-
content,
|
|
68
|
-
header,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
44
|
const getLines = (p) => {
|
|
72
|
-
var _a
|
|
45
|
+
var _a;
|
|
73
46
|
const ops = getOperation(p);
|
|
74
|
-
if (ops.error) {
|
|
47
|
+
if (ops.error || !ops.operation) {
|
|
75
48
|
return { error: ops.error };
|
|
76
49
|
}
|
|
77
50
|
const { operation, path, verb } = ops;
|
|
@@ -81,18 +54,17 @@ const getLines = (p) => {
|
|
|
81
54
|
if (secline.error) {
|
|
82
55
|
return { error: secline.error };
|
|
83
56
|
}
|
|
84
|
-
const bodyLines = (_a = getBody(p)) !== null && _a !== void 0 ? _a : undefined;
|
|
57
|
+
const bodyLines = (_a = (0, body_1.getBody)(p)) !== null && _a !== void 0 ? _a : undefined;
|
|
85
58
|
const headerLines = [];
|
|
86
59
|
if (secline.content) {
|
|
87
60
|
headerLines.push(secline.content);
|
|
88
61
|
headerLines.push(react_1.default.createElement(react_1.default.Fragment, null,
|
|
89
|
-
|
|
90
|
-
"\\",
|
|
62
|
+
"\u00A0\\",
|
|
91
63
|
react_1.default.createElement("br", null)));
|
|
92
64
|
}
|
|
93
65
|
if (bodyLines.header) {
|
|
94
66
|
headerLines.push(bodyLines.header);
|
|
95
|
-
headerLines.push(react_1.default.createElement(react_1.default.Fragment, null, "
|
|
67
|
+
headerLines.push(react_1.default.createElement(react_1.default.Fragment, null, "\u00A0\\"));
|
|
96
68
|
}
|
|
97
69
|
return {
|
|
98
70
|
verb,
|
|
@@ -100,7 +72,7 @@ const getLines = (p) => {
|
|
|
100
72
|
error: undefined,
|
|
101
73
|
headerLines,
|
|
102
74
|
fullApiUrl,
|
|
103
|
-
bodyLine:
|
|
75
|
+
bodyLine: bodyLines === null || bodyLines === void 0 ? void 0 : bodyLines.content,
|
|
104
76
|
operation,
|
|
105
77
|
};
|
|
106
78
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ICodeBlock } from '../types';
|
|
2
|
+
import { ICodeBlock, IOpenApiOperation } from '../types';
|
|
3
3
|
export declare const getSecurityLine: <TDefaultApi>(p: ICodeBlock<TDefaultApi>, { operation }: {
|
|
4
|
-
operation:
|
|
4
|
+
operation: IOpenApiOperation;
|
|
5
5
|
}) => {
|
|
6
6
|
error?: string;
|
|
7
7
|
content: JSX.Element;
|
|
@@ -7,9 +7,7 @@ exports.getSecurityLine = void 0;
|
|
|
7
7
|
const common_1 = require("./common");
|
|
8
8
|
const string_1 = require("../../../../common/helpers/string");
|
|
9
9
|
const react_1 = __importDefault(require("react"));
|
|
10
|
-
const getSecurityLine = (p,
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
{ operation }) => {
|
|
10
|
+
const getSecurityLine = (p, { operation }) => {
|
|
13
11
|
var _a;
|
|
14
12
|
const security1 = (_a = operation.security) === null || _a === void 0 ? void 0 : _a[0];
|
|
15
13
|
const security2 = !security1 ? undefined : Object.keys(security1)[0];
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./OpenApiCodeBlock"), exports);
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface IOpenApiOperation {
|
|
2
|
+
description: string;
|
|
3
|
+
operationId: string;
|
|
4
|
+
security?: {
|
|
5
|
+
[name: string]: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface IOpenApiSecurityScheme {
|
|
9
|
+
in: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IOpenApi {
|
|
13
|
+
paths: {
|
|
14
|
+
[pathname: string]: {
|
|
15
|
+
[verb: string]: IOpenApiOperation;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
servers: {
|
|
19
|
+
url: string;
|
|
20
|
+
}[];
|
|
21
|
+
components: {
|
|
22
|
+
securitySchemes: {
|
|
23
|
+
[name: string]: IOpenApiSecurityScheme;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface ICodeBlock<TDefaultApi> {
|
|
28
|
+
/**
|
|
29
|
+
* openapi schema. eg
|
|
30
|
+
* const schema: any = require('common/openapi.generated').default;
|
|
31
|
+
*/
|
|
32
|
+
schema: IOpenApi;
|
|
33
|
+
apiKey?: string;
|
|
34
|
+
funcF: (f: TDefaultApi) => Promise<any>;
|
|
35
|
+
}
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ export * from './BorderGradient';
|
|
|
2
2
|
export * from './Button';
|
|
3
3
|
export * from './Chevron';
|
|
4
4
|
export * from './Close';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './OpenApiCodeBlock';
|
|
6
6
|
export * from './Confirm/Dialog';
|
|
7
7
|
export * from './DropdownList';
|
|
8
8
|
export * from './FlexColumn';
|
|
@@ -18,7 +18,7 @@ __exportStar(require("./BorderGradient"), exports);
|
|
|
18
18
|
__exportStar(require("./Button"), exports);
|
|
19
19
|
__exportStar(require("./Chevron"), exports);
|
|
20
20
|
__exportStar(require("./Close"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
21
|
+
__exportStar(require("./OpenApiCodeBlock"), exports);
|
|
22
22
|
__exportStar(require("./Confirm/Dialog"), exports);
|
|
23
23
|
__exportStar(require("./DropdownList"), exports);
|
|
24
24
|
__exportStar(require("./FlexColumn"), exports);
|
package/package.json
CHANGED