@nestia/editor 11.0.0-dev.20260313-5 → 11.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.
- package/LICENSE +21 -21
- package/README.md +93 -93
- package/dist/assets/{index-BvyKi6Cn.js → index-DUWBgT-P.js} +3830 -3830
- package/dist/index.html +19 -19
- package/package.json +8 -4
- package/src/NestiaEditorApplication.tsx +94 -94
- package/src/NestiaEditorIframe.tsx +245 -245
- package/src/NestiaEditorModule.ts +136 -136
- package/src/NestiaEditorUploader.tsx +154 -154
- package/src/internal/NestiaEditorComposer.ts +90 -90
- package/src/internal/NestiaEditorFileUploader.tsx +68 -68
- package/src/main.tsx +10 -10
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { NestiaMigrateApplication } from "@nestia/migrate";
|
|
2
|
-
import {
|
|
3
|
-
OpenApiV3,
|
|
4
|
-
OpenApiV3_1,
|
|
5
|
-
OpenApiV3_2,
|
|
6
|
-
SwaggerV2,
|
|
7
|
-
} from "@typia/interface";
|
|
8
|
-
import * as prettierEsTreePlugin from "prettier/plugins/estree";
|
|
9
|
-
import * as prettierTsPlugin from "prettier/plugins/typescript";
|
|
10
|
-
import { format } from "prettier/standalone";
|
|
11
|
-
import { IValidation } from "typia";
|
|
12
|
-
|
|
13
|
-
export namespace NestiaEditorComposer {
|
|
14
|
-
export interface IProps {
|
|
15
|
-
document:
|
|
16
|
-
| SwaggerV2.IDocument
|
|
17
|
-
| OpenApiV3.IDocument
|
|
18
|
-
| OpenApiV3_1.IDocument
|
|
19
|
-
| OpenApiV3_2.IDocument;
|
|
20
|
-
e2e: boolean;
|
|
21
|
-
keyword: boolean;
|
|
22
|
-
simulate: boolean;
|
|
23
|
-
package?: string;
|
|
24
|
-
/** @internal */
|
|
25
|
-
files?: Record<string, string>;
|
|
26
|
-
}
|
|
27
|
-
export interface IOutput {
|
|
28
|
-
files: Record<string, string>;
|
|
29
|
-
openFile: string;
|
|
30
|
-
startScript: string[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const nest = (props: IProps): Promise<IValidation<IOutput>> =>
|
|
34
|
-
compose({
|
|
35
|
-
openFile: "README.md,test/start.ts",
|
|
36
|
-
startScript: ["build:test,test", ""],
|
|
37
|
-
migrate: (app) => app.nest(props),
|
|
38
|
-
})(props);
|
|
39
|
-
|
|
40
|
-
export const sdk = async (props: IProps): Promise<IValidation<IOutput>> => {
|
|
41
|
-
console.log("NestiaEditorComposer.sdk()", props);
|
|
42
|
-
return compose({
|
|
43
|
-
openFile: "README.md,test/start.ts",
|
|
44
|
-
startScript: ["swagger", "hello"],
|
|
45
|
-
migrate: (app) => app.sdk(props),
|
|
46
|
-
})(props);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const compose =
|
|
50
|
-
(config: {
|
|
51
|
-
openFile: string;
|
|
52
|
-
startScript: string[];
|
|
53
|
-
migrate: (app: NestiaMigrateApplication) => Record<string, string>;
|
|
54
|
-
}) =>
|
|
55
|
-
async (props: IProps): Promise<IValidation<IOutput>> => {
|
|
56
|
-
if (props.files !== undefined)
|
|
57
|
-
return {
|
|
58
|
-
success: true,
|
|
59
|
-
data: {
|
|
60
|
-
files: props.files,
|
|
61
|
-
openFile: config.openFile,
|
|
62
|
-
startScript: config.startScript,
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
const result: IValidation<NestiaMigrateApplication> =
|
|
66
|
-
await NestiaMigrateApplication.validate(props.document);
|
|
67
|
-
if (result.success === false) return result;
|
|
68
|
-
|
|
69
|
-
const app: NestiaMigrateApplication = result.data;
|
|
70
|
-
const files: Record<string, string> = config.migrate(app);
|
|
71
|
-
for (const [key, value] of Object.entries(files))
|
|
72
|
-
if (key.substring(key.length - 3) === ".ts")
|
|
73
|
-
try {
|
|
74
|
-
files[key] = await format(value, {
|
|
75
|
-
parser: "typescript",
|
|
76
|
-
plugins: [prettierEsTreePlugin, prettierTsPlugin],
|
|
77
|
-
});
|
|
78
|
-
} catch (exp) {
|
|
79
|
-
console.log(exp);
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
success: true,
|
|
83
|
-
data: {
|
|
84
|
-
files,
|
|
85
|
-
openFile: config.openFile,
|
|
86
|
-
startScript: config.startScript,
|
|
87
|
-
},
|
|
88
|
-
} satisfies IValidation<IOutput>;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
1
|
+
import { NestiaMigrateApplication } from "@nestia/migrate";
|
|
2
|
+
import {
|
|
3
|
+
OpenApiV3,
|
|
4
|
+
OpenApiV3_1,
|
|
5
|
+
OpenApiV3_2,
|
|
6
|
+
SwaggerV2,
|
|
7
|
+
} from "@typia/interface";
|
|
8
|
+
import * as prettierEsTreePlugin from "prettier/plugins/estree";
|
|
9
|
+
import * as prettierTsPlugin from "prettier/plugins/typescript";
|
|
10
|
+
import { format } from "prettier/standalone";
|
|
11
|
+
import { IValidation } from "typia";
|
|
12
|
+
|
|
13
|
+
export namespace NestiaEditorComposer {
|
|
14
|
+
export interface IProps {
|
|
15
|
+
document:
|
|
16
|
+
| SwaggerV2.IDocument
|
|
17
|
+
| OpenApiV3.IDocument
|
|
18
|
+
| OpenApiV3_1.IDocument
|
|
19
|
+
| OpenApiV3_2.IDocument;
|
|
20
|
+
e2e: boolean;
|
|
21
|
+
keyword: boolean;
|
|
22
|
+
simulate: boolean;
|
|
23
|
+
package?: string;
|
|
24
|
+
/** @internal */
|
|
25
|
+
files?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
export interface IOutput {
|
|
28
|
+
files: Record<string, string>;
|
|
29
|
+
openFile: string;
|
|
30
|
+
startScript: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const nest = (props: IProps): Promise<IValidation<IOutput>> =>
|
|
34
|
+
compose({
|
|
35
|
+
openFile: "README.md,test/start.ts",
|
|
36
|
+
startScript: ["build:test,test", ""],
|
|
37
|
+
migrate: (app) => app.nest(props),
|
|
38
|
+
})(props);
|
|
39
|
+
|
|
40
|
+
export const sdk = async (props: IProps): Promise<IValidation<IOutput>> => {
|
|
41
|
+
console.log("NestiaEditorComposer.sdk()", props);
|
|
42
|
+
return compose({
|
|
43
|
+
openFile: "README.md,test/start.ts",
|
|
44
|
+
startScript: ["swagger", "hello"],
|
|
45
|
+
migrate: (app) => app.sdk(props),
|
|
46
|
+
})(props);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const compose =
|
|
50
|
+
(config: {
|
|
51
|
+
openFile: string;
|
|
52
|
+
startScript: string[];
|
|
53
|
+
migrate: (app: NestiaMigrateApplication) => Record<string, string>;
|
|
54
|
+
}) =>
|
|
55
|
+
async (props: IProps): Promise<IValidation<IOutput>> => {
|
|
56
|
+
if (props.files !== undefined)
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
data: {
|
|
60
|
+
files: props.files,
|
|
61
|
+
openFile: config.openFile,
|
|
62
|
+
startScript: config.startScript,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const result: IValidation<NestiaMigrateApplication> =
|
|
66
|
+
await NestiaMigrateApplication.validate(props.document);
|
|
67
|
+
if (result.success === false) return result;
|
|
68
|
+
|
|
69
|
+
const app: NestiaMigrateApplication = result.data;
|
|
70
|
+
const files: Record<string, string> = config.migrate(app);
|
|
71
|
+
for (const [key, value] of Object.entries(files))
|
|
72
|
+
if (key.substring(key.length - 3) === ".ts")
|
|
73
|
+
try {
|
|
74
|
+
files[key] = await format(value, {
|
|
75
|
+
parser: "typescript",
|
|
76
|
+
plugins: [prettierEsTreePlugin, prettierTsPlugin],
|
|
77
|
+
});
|
|
78
|
+
} catch (exp) {
|
|
79
|
+
console.log(exp);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
success: true,
|
|
83
|
+
data: {
|
|
84
|
+
files,
|
|
85
|
+
openFile: config.openFile,
|
|
86
|
+
startScript: config.startScript,
|
|
87
|
+
},
|
|
88
|
+
} satisfies IValidation<IOutput>;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
|
|
2
|
-
import { load } from "js-yaml";
|
|
3
|
-
import React from "react";
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import FileUpload from "react-mui-fileuploader";
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import { ExtendedFileProps } from "react-mui-fileuploader/dist/types/index.types";
|
|
8
|
-
|
|
9
|
-
export function NestiaEditorFileUploader(
|
|
10
|
-
props: NestiaEditorFileUploader.IProps,
|
|
11
|
-
) {
|
|
12
|
-
const [elements, setElements] = React.useState<ExtendedFileProps[]>([]);
|
|
13
|
-
const onChange = async (array: ExtendedFileProps[]) => {
|
|
14
|
-
if (array.length === 0) {
|
|
15
|
-
props.onChange(null, null);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const file: ExtendedFileProps = array[array.length - 1]!;
|
|
19
|
-
const buffer: ArrayBuffer = await file.arrayBuffer();
|
|
20
|
-
const content: string = new TextDecoder().decode(buffer);
|
|
21
|
-
const extension: "json" | "yaml" = file.name.split(".").pop()! as
|
|
22
|
-
| "json"
|
|
23
|
-
| "yaml";
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const json:
|
|
27
|
-
| SwaggerV2.IDocument
|
|
28
|
-
| OpenApiV3.IDocument
|
|
29
|
-
| OpenApiV3_1.IDocument =
|
|
30
|
-
extension === "json" ? JSON.parse(content) : load(content);
|
|
31
|
-
props.onChange(json, null);
|
|
32
|
-
} catch {
|
|
33
|
-
props.onChange(
|
|
34
|
-
null,
|
|
35
|
-
extension === "json" ? "Invalid JSON file" : "Invalid YAML file",
|
|
36
|
-
);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (array.length > 1) setElements([file]);
|
|
40
|
-
};
|
|
41
|
-
return (
|
|
42
|
-
<FileUpload
|
|
43
|
-
defaultFiles={elements}
|
|
44
|
-
onFilesChange={onChange}
|
|
45
|
-
acceptedType=".json, .yaml"
|
|
46
|
-
getBase64={false}
|
|
47
|
-
multiFile={false}
|
|
48
|
-
maxUploadFiles={1}
|
|
49
|
-
title="Swagger file uploader"
|
|
50
|
-
header="Drag and drop a Swagger file here"
|
|
51
|
-
buttonLabel="Click Here"
|
|
52
|
-
rightLabel="to select swagger.json/yaml file"
|
|
53
|
-
buttonRemoveLabel="Clear"
|
|
54
|
-
/>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
export namespace NestiaEditorFileUploader {
|
|
58
|
-
export interface IProps {
|
|
59
|
-
onChange: (
|
|
60
|
-
swagger:
|
|
61
|
-
| SwaggerV2.IDocument
|
|
62
|
-
| OpenApiV3.IDocument
|
|
63
|
-
| OpenApiV3_1.IDocument
|
|
64
|
-
| null,
|
|
65
|
-
error: string | null,
|
|
66
|
-
) => void;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
import { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
|
|
2
|
+
import { load } from "js-yaml";
|
|
3
|
+
import React from "react";
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import FileUpload from "react-mui-fileuploader";
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { ExtendedFileProps } from "react-mui-fileuploader/dist/types/index.types";
|
|
8
|
+
|
|
9
|
+
export function NestiaEditorFileUploader(
|
|
10
|
+
props: NestiaEditorFileUploader.IProps,
|
|
11
|
+
) {
|
|
12
|
+
const [elements, setElements] = React.useState<ExtendedFileProps[]>([]);
|
|
13
|
+
const onChange = async (array: ExtendedFileProps[]) => {
|
|
14
|
+
if (array.length === 0) {
|
|
15
|
+
props.onChange(null, null);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const file: ExtendedFileProps = array[array.length - 1]!;
|
|
19
|
+
const buffer: ArrayBuffer = await file.arrayBuffer();
|
|
20
|
+
const content: string = new TextDecoder().decode(buffer);
|
|
21
|
+
const extension: "json" | "yaml" = file.name.split(".").pop()! as
|
|
22
|
+
| "json"
|
|
23
|
+
| "yaml";
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const json:
|
|
27
|
+
| SwaggerV2.IDocument
|
|
28
|
+
| OpenApiV3.IDocument
|
|
29
|
+
| OpenApiV3_1.IDocument =
|
|
30
|
+
extension === "json" ? JSON.parse(content) : load(content);
|
|
31
|
+
props.onChange(json, null);
|
|
32
|
+
} catch {
|
|
33
|
+
props.onChange(
|
|
34
|
+
null,
|
|
35
|
+
extension === "json" ? "Invalid JSON file" : "Invalid YAML file",
|
|
36
|
+
);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (array.length > 1) setElements([file]);
|
|
40
|
+
};
|
|
41
|
+
return (
|
|
42
|
+
<FileUpload
|
|
43
|
+
defaultFiles={elements}
|
|
44
|
+
onFilesChange={onChange}
|
|
45
|
+
acceptedType=".json, .yaml"
|
|
46
|
+
getBase64={false}
|
|
47
|
+
multiFile={false}
|
|
48
|
+
maxUploadFiles={1}
|
|
49
|
+
title="Swagger file uploader"
|
|
50
|
+
header="Drag and drop a Swagger file here"
|
|
51
|
+
buttonLabel="Click Here"
|
|
52
|
+
rightLabel="to select swagger.json/yaml file"
|
|
53
|
+
buttonRemoveLabel="Clear"
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
export namespace NestiaEditorFileUploader {
|
|
58
|
+
export interface IProps {
|
|
59
|
+
onChange: (
|
|
60
|
+
swagger:
|
|
61
|
+
| SwaggerV2.IDocument
|
|
62
|
+
| OpenApiV3.IDocument
|
|
63
|
+
| OpenApiV3_1.IDocument
|
|
64
|
+
| null,
|
|
65
|
+
error: string | null,
|
|
66
|
+
) => void;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/main.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { StrictMode } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
|
-
|
|
4
|
-
import { NestiaEditorApplication } from "./NestiaEditorApplication";
|
|
5
|
-
|
|
6
|
-
createRoot(document.getElementById("root")!).render(
|
|
7
|
-
<StrictMode>
|
|
8
|
-
<NestiaEditorApplication />
|
|
9
|
-
</StrictMode>,
|
|
10
|
-
);
|
|
1
|
+
import { StrictMode } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
|
|
4
|
+
import { NestiaEditorApplication } from "./NestiaEditorApplication";
|
|
5
|
+
|
|
6
|
+
createRoot(document.getElementById("root")!).render(
|
|
7
|
+
<StrictMode>
|
|
8
|
+
<NestiaEditorApplication />
|
|
9
|
+
</StrictMode>,
|
|
10
|
+
);
|