@mxpicture/gcp-functions-tools 0.1.59
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/change/ChangeHandler.d.ts +13 -0
- package/dist/change/ChangeHandler.js +144 -0
- package/dist/change/GitChanges.d.ts +34 -0
- package/dist/change/GitChanges.js +91 -0
- package/dist/change/index.d.ts +3 -0
- package/dist/change/index.js +4 -0
- package/dist/change/types.change.d.ts +32 -0
- package/dist/change/types.change.js +4 -0
- package/dist/common/Barrel.d.ts +23 -0
- package/dist/common/Barrel.js +75 -0
- package/dist/common/Collector.d.ts +22 -0
- package/dist/common/Collector.js +37 -0
- package/dist/common/Directories.d.ts +25 -0
- package/dist/common/Directories.js +52 -0
- package/dist/common/Evaluate.d.ts +12 -0
- package/dist/common/Evaluate.js +120 -0
- package/dist/common/Extractor.d.ts +35 -0
- package/dist/common/Extractor.js +198 -0
- package/dist/common/generator.common.d.ts +14 -0
- package/dist/common/generator.common.js +45 -0
- package/dist/common/index.d.ts +6 -0
- package/dist/common/index.js +7 -0
- package/dist/generator/Generator.d.ts +34 -0
- package/dist/generator/Generator.js +111 -0
- package/dist/generator/GeneratorAnnotations.d.ts +9 -0
- package/dist/generator/GeneratorAnnotations.js +23 -0
- package/dist/generator/GeneratorBackend.d.ts +13 -0
- package/dist/generator/GeneratorBackend.js +131 -0
- package/dist/generator/GeneratorDoc.d.ts +9 -0
- package/dist/generator/GeneratorDoc.js +23 -0
- package/dist/generator/GeneratorFrontend.d.ts +12 -0
- package/dist/generator/GeneratorFrontend.js +94 -0
- package/dist/generator/GeneratorRoutes.d.ts +11 -0
- package/dist/generator/GeneratorRoutes.js +53 -0
- package/dist/generator/GeneratorZod.d.ts +26 -0
- package/dist/generator/GeneratorZod.js +151 -0
- package/dist/generator/index.d.ts +7 -0
- package/dist/generator/index.js +8 -0
- package/dist/meta/index.d.ts +9 -0
- package/dist/meta/index.js +10 -0
- package/dist/meta/meta.annotations.d.ts +11 -0
- package/dist/meta/meta.annotations.js +1 -0
- package/dist/meta/meta.common.d.ts +42 -0
- package/dist/meta/meta.common.js +87 -0
- package/dist/meta/meta.decorators.d.ts +26 -0
- package/dist/meta/meta.decorators.js +21 -0
- package/dist/meta/meta.enum.d.ts +87 -0
- package/dist/meta/meta.enum.js +99 -0
- package/dist/meta/meta.imports.d.ts +11 -0
- package/dist/meta/meta.imports.js +54 -0
- package/dist/meta/meta.main.d.ts +32 -0
- package/dist/meta/meta.main.js +10 -0
- package/dist/meta/meta.names.d.ts +8 -0
- package/dist/meta/meta.names.js +35 -0
- package/dist/meta/meta.properties.d.ts +62 -0
- package/dist/meta/meta.properties.js +37 -0
- package/dist/meta/meta.types.d.ts +109 -0
- package/dist/meta/meta.types.js +26 -0
- package/dist/vscode/OSUser.d.ts +15 -0
- package/dist/vscode/OSUser.js +62 -0
- package/dist/vscode/VSCodeCommon.d.ts +50 -0
- package/dist/vscode/VSCodeCommon.js +133 -0
- package/dist/vscode/VSCodeSettings.d.ts +10 -0
- package/dist/vscode/VSCodeSettings.js +41 -0
- package/dist/vscode/VSCodeWorkspace.d.ts +22 -0
- package/dist/vscode/VSCodeWorkspace.js +43 -0
- package/dist/vscode/index.d.ts +4 -0
- package/dist/vscode/index.js +5 -0
- package/package.json +48 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { guardMetaFileExtension, guardMetaFileType, MetaFileExtension, MetaFileType, } from "./meta.enum.js";
|
|
3
|
+
import { format } from "prettier";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
export var TargetType;
|
|
6
|
+
(function (TargetType) {
|
|
7
|
+
TargetType["common"] = "common";
|
|
8
|
+
TargetType["frontend"] = "frontend";
|
|
9
|
+
TargetType["backend"] = "backend";
|
|
10
|
+
})(TargetType || (TargetType = {}));
|
|
11
|
+
export const isTemplateFile = (filename) => isTsFile(filename, MetaFileType.template);
|
|
12
|
+
export const isTsFile = (filename, type) => isAnyFile(filename, type, MetaFileExtension.ts);
|
|
13
|
+
export const isAnyFile = (filename, type, ext) => {
|
|
14
|
+
try {
|
|
15
|
+
const parts = extractFileParts(filename);
|
|
16
|
+
if (type && type !== parts.type)
|
|
17
|
+
return false;
|
|
18
|
+
if (ext && ext !== parts.ext)
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
export const extractFileParts = (filename) => {
|
|
27
|
+
const parts = filename.split(".");
|
|
28
|
+
if (parts.length < 3)
|
|
29
|
+
throw new Error(`Filename "${filename}" invalid (3 parts divided by ".")`);
|
|
30
|
+
const _type = parts.shift();
|
|
31
|
+
const _ext = parts.pop();
|
|
32
|
+
const type = guardMetaFileType(_type);
|
|
33
|
+
const ext = guardMetaFileExtension(_ext);
|
|
34
|
+
if (!type)
|
|
35
|
+
throw new Error(`Filename "${filename}" invalid (type: ${_type})`);
|
|
36
|
+
if (!ext)
|
|
37
|
+
throw new Error(`Filename "${filename}" invalid (extension: ${_ext})`);
|
|
38
|
+
return {
|
|
39
|
+
filename,
|
|
40
|
+
type,
|
|
41
|
+
ext,
|
|
42
|
+
middlePart: parts.join("."),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export const concatFileParts = (parts) => [parts.type, parts.middlePart, parts.generated ? "gen" : null, parts.ext]
|
|
46
|
+
.filter((p) => !!p)
|
|
47
|
+
.join(".");
|
|
48
|
+
export const toFilename = (p) => concatFileParts({
|
|
49
|
+
...extractFileParts(p.filename),
|
|
50
|
+
type: p.type,
|
|
51
|
+
ext: p.ext ?? MetaFileExtension.ts,
|
|
52
|
+
generated: p.generated,
|
|
53
|
+
});
|
|
54
|
+
export const formatCode = async (...lines) => format(lines.join("\n"), { parser: "typescript" });
|
|
55
|
+
export const formatJson = async (...lines) => format(lines.join("\n"), { parser: "json" });
|
|
56
|
+
// // export const toFilePath = (
|
|
57
|
+
// // filePath: string,
|
|
58
|
+
// // type: MetaFileType,
|
|
59
|
+
// // ext: MetaFileExtension = MetaFileExtension.ts,
|
|
60
|
+
// // ): string | undefined => {
|
|
61
|
+
// // const name = toFilename(basename(filePath), type, ext);
|
|
62
|
+
// // const dir = dirname(filePath);
|
|
63
|
+
// // return name ? `${dir}/${name}` : undefined;
|
|
64
|
+
// // };
|
|
65
|
+
export const lowerFirstLetter = (val) => val.length > 1
|
|
66
|
+
? val.charAt(0).toLocaleLowerCase() + val.slice(1)
|
|
67
|
+
: val.toLocaleLowerCase();
|
|
68
|
+
export const upperFirstLetter = (val) => val.length > 1
|
|
69
|
+
? val.charAt(0).toUpperCase() + val.slice(1)
|
|
70
|
+
: val.toUpperCase();
|
|
71
|
+
export const createSourceFiles = (filePaths) => {
|
|
72
|
+
const program = ts.createProgram(filePaths, {
|
|
73
|
+
target: ts.ScriptTarget.ES2023,
|
|
74
|
+
module: ts.ModuleKind.Node20,
|
|
75
|
+
strict: true,
|
|
76
|
+
});
|
|
77
|
+
const checker = program.getTypeChecker();
|
|
78
|
+
const results = [];
|
|
79
|
+
for (const filePath of filePaths) {
|
|
80
|
+
const sourceFile = program.getSourceFile(filePath);
|
|
81
|
+
if (!sourceFile)
|
|
82
|
+
continue;
|
|
83
|
+
results.push({ sourceFile, filePath, checker });
|
|
84
|
+
}
|
|
85
|
+
return results;
|
|
86
|
+
};
|
|
87
|
+
export const calcHash = (input) => createHash("sha256").update(input).digest("hex");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MetaPropertyDecorator } from "./meta.properties.js";
|
|
2
|
+
import type { MetaInterfaceOptions, MetaNumberOptions, MetaStringOptions, MetaArrayOptions, MetaObjectOptions, MetaDateOptions, MetaBooleanOptions, WithoutType, MetaKeyOptions, MetaCreateTimeOptions, MetaUpdateTimeOptions, MetaMainInterfaceOptions } from "./meta.types.js";
|
|
3
|
+
import { MetaMainDecorator } from "./meta.main.js";
|
|
4
|
+
export declare const MetaInterface: (options: WithoutType<MetaInterfaceOptions>, decoratorType?: MetaMainDecorator.MetaInterface) => <T extends {
|
|
5
|
+
new (...args: any[]): {};
|
|
6
|
+
}>(constructor: T) => T;
|
|
7
|
+
export declare const MetaMainInterface: (options: WithoutType<MetaMainInterfaceOptions>, decoratorType?: MetaMainDecorator.MetaMainInterface) => <T extends {
|
|
8
|
+
new (...args: any[]): {};
|
|
9
|
+
}>(constructor: T) => T;
|
|
10
|
+
export declare const MetaKey: (options: Omit<WithoutType<MetaKeyOptions>, "optional">, decoratorType?: MetaPropertyDecorator.MetaKey) => (target: any, propertyKey: string) => void;
|
|
11
|
+
export type MetaCreateTimeOptionsBase = WithoutType<MetaCreateTimeOptions>;
|
|
12
|
+
export declare const MetaCreateTime: <Opt extends MetaCreateTimeOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaCreateTime) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? Date | undefined : Date) ? unknown : never)) => void;
|
|
13
|
+
export type MetaUpdateTimeOptionsBase = WithoutType<MetaUpdateTimeOptions>;
|
|
14
|
+
export declare const MetaUpdateTime: <Opt extends MetaUpdateTimeOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaUpdateTime) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? Date | undefined : Date) ? unknown : never)) => void;
|
|
15
|
+
export type MetaNumberOptionsBase = WithoutType<MetaNumberOptions>;
|
|
16
|
+
export declare const MetaNumber: <Opt extends MetaNumberOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaNumber) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? number | undefined : number) ? unknown : never)) => void;
|
|
17
|
+
export type MetaStringOptionsBase = WithoutType<MetaStringOptions>;
|
|
18
|
+
export declare const MetaString: <Opt extends MetaStringOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaString) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? string | undefined : string) ? unknown : never)) => void;
|
|
19
|
+
export type MetaArrayOptionsBase = WithoutType<MetaArrayOptions>;
|
|
20
|
+
export declare const MetaArray: <Opt extends MetaArrayOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaArray) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? unknown[] | undefined : unknown[]) ? unknown : never)) => void;
|
|
21
|
+
export type MetaObjectOptionsBase = WithoutType<MetaObjectOptions>;
|
|
22
|
+
export declare const MetaObject: <Opt extends MetaObjectOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaObject) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? object | undefined : object) ? unknown : never)) => void;
|
|
23
|
+
export type MetaDateOptionsBase = WithoutType<MetaDateOptions>;
|
|
24
|
+
export declare const MetaDate: <Opt extends MetaDateOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaDate) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? Date | undefined : Date) ? unknown : never)) => void;
|
|
25
|
+
export type MetaBooleanOptionsBase = WithoutType<MetaBooleanOptions>;
|
|
26
|
+
export declare const MetaBoolean: <Opt extends MetaBooleanOptionsBase>(options: Opt, decoratorType?: MetaPropertyDecorator.MetaBoolean) => <T, K extends Extract<keyof T, string>>(target: T, propertyKey: K & (T[K] extends (Opt["optional"] extends true ? boolean | undefined : boolean) ? unknown : never)) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
import { MetaPropertyDecorator } from "./meta.properties.js";
|
|
5
|
+
import { MetaMainDecorator } from "./meta.main.js";
|
|
6
|
+
// after adding new decorator add it to MetaPropDecorator too
|
|
7
|
+
export const MetaInterface = (options, decoratorType = MetaMainDecorator.MetaInterface) => (constructor) => {
|
|
8
|
+
return constructor;
|
|
9
|
+
};
|
|
10
|
+
export const MetaMainInterface = (options, decoratorType = MetaMainDecorator.MetaMainInterface) => (constructor) => {
|
|
11
|
+
return constructor;
|
|
12
|
+
};
|
|
13
|
+
export const MetaKey = (options, decoratorType = MetaPropertyDecorator.MetaKey) => (target, propertyKey) => { };
|
|
14
|
+
export const MetaCreateTime = (options, decoratorType = MetaPropertyDecorator.MetaCreateTime) => (target, propertyKey) => { };
|
|
15
|
+
export const MetaUpdateTime = (options, decoratorType = MetaPropertyDecorator.MetaUpdateTime) => (target, propertyKey) => { };
|
|
16
|
+
export const MetaNumber = (options, decoratorType = MetaPropertyDecorator.MetaNumber) => (target, propertyKey) => { };
|
|
17
|
+
export const MetaString = (options, decoratorType = MetaPropertyDecorator.MetaString) => (target, propertyKey) => { };
|
|
18
|
+
export const MetaArray = (options, decoratorType = MetaPropertyDecorator.MetaArray) => (target, propertyKey) => { };
|
|
19
|
+
export const MetaObject = (options, decoratorType = MetaPropertyDecorator.MetaObject) => (target, propertyKey) => { };
|
|
20
|
+
export const MetaDate = (options, decoratorType = MetaPropertyDecorator.MetaDate) => (target, propertyKey) => { };
|
|
21
|
+
export const MetaBoolean = (options, decoratorType = MetaPropertyDecorator.MetaBoolean) => (target, propertyKey) => { };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export declare enum MetaFileType {
|
|
2
|
+
doc = "doc",
|
|
3
|
+
template = "template",
|
|
4
|
+
routes = "routes",
|
|
5
|
+
backend = "backend",
|
|
6
|
+
frontend = "frontend",
|
|
7
|
+
zod = "zod",
|
|
8
|
+
annotations = "annotations"
|
|
9
|
+
}
|
|
10
|
+
export declare const guardMetaFileType: (type: string | undefined) => MetaFileType | undefined;
|
|
11
|
+
export declare enum MetaFileExtension {
|
|
12
|
+
ts = "ts",
|
|
13
|
+
json = "json"
|
|
14
|
+
}
|
|
15
|
+
export declare const guardMetaFileExtension: (ext: string | undefined) => MetaFileExtension | undefined;
|
|
16
|
+
export declare enum MetaPropertyType {
|
|
17
|
+
string = "string",
|
|
18
|
+
number = "number",
|
|
19
|
+
boolean = "boolean",
|
|
20
|
+
date = "date",
|
|
21
|
+
array = "array",
|
|
22
|
+
object = "object",
|
|
23
|
+
key = "key",
|
|
24
|
+
createTime = "createTime",
|
|
25
|
+
updateTime = "updateTime"
|
|
26
|
+
}
|
|
27
|
+
export declare enum MetaMainType {
|
|
28
|
+
interface = "interface",
|
|
29
|
+
mainInterface = "mainInterface"
|
|
30
|
+
}
|
|
31
|
+
export declare enum MetaPropertyArrayType {
|
|
32
|
+
string = "string",
|
|
33
|
+
number = "number",
|
|
34
|
+
boolean = "boolean",
|
|
35
|
+
date = "date",
|
|
36
|
+
object = "object"
|
|
37
|
+
}
|
|
38
|
+
export declare enum MetaNumberFormat {
|
|
39
|
+
int32 = "int32",
|
|
40
|
+
uint32 = "uint32",
|
|
41
|
+
float32 = "float32",
|
|
42
|
+
float64 = "float64",
|
|
43
|
+
safeint = "safeint"
|
|
44
|
+
}
|
|
45
|
+
export declare enum MetaStringFormat {
|
|
46
|
+
email = "email",
|
|
47
|
+
url = "url",
|
|
48
|
+
emoji = "emoji",
|
|
49
|
+
uuid = "uuid",
|
|
50
|
+
guid = "guid",
|
|
51
|
+
nanoid = "nanoid",
|
|
52
|
+
cuid = "cuid",
|
|
53
|
+
cuid2 = "cuid2",
|
|
54
|
+
ulid = "ulid",
|
|
55
|
+
xid = "xid",
|
|
56
|
+
ksuid = "ksuid",
|
|
57
|
+
datetime = "datetime",
|
|
58
|
+
date = "date",
|
|
59
|
+
time = "time",
|
|
60
|
+
duration = "duration",
|
|
61
|
+
ipv4 = "ipv4",
|
|
62
|
+
ipv6 = "ipv6",
|
|
63
|
+
cidrv4 = "cidrv4",
|
|
64
|
+
cidrv6 = "cidrv6",
|
|
65
|
+
base64 = "base64",
|
|
66
|
+
base64url = "base64url",
|
|
67
|
+
json_string = "json_string",
|
|
68
|
+
e164 = "e164",
|
|
69
|
+
lowercase = "lowercase",
|
|
70
|
+
uppercase = "uppercase",
|
|
71
|
+
regex = "regex",
|
|
72
|
+
jwt = "jwt",
|
|
73
|
+
starts_with = "starts_with",
|
|
74
|
+
ends_with = "ends_with",
|
|
75
|
+
includes = "includes"
|
|
76
|
+
}
|
|
77
|
+
export declare enum CrudRouteName {
|
|
78
|
+
create = "create",
|
|
79
|
+
update = "update",
|
|
80
|
+
delete = "delete",
|
|
81
|
+
get = "get",
|
|
82
|
+
query = "query",
|
|
83
|
+
count = "count",
|
|
84
|
+
exists = "exists"
|
|
85
|
+
}
|
|
86
|
+
export declare const isCrudRoute: (routeName: string) => boolean;
|
|
87
|
+
export declare const hasCrudRoute: (routeNames: string[]) => boolean;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export var MetaFileType;
|
|
2
|
+
(function (MetaFileType) {
|
|
3
|
+
MetaFileType["doc"] = "doc";
|
|
4
|
+
MetaFileType["template"] = "template";
|
|
5
|
+
MetaFileType["routes"] = "routes";
|
|
6
|
+
MetaFileType["backend"] = "backend";
|
|
7
|
+
MetaFileType["frontend"] = "frontend";
|
|
8
|
+
MetaFileType["zod"] = "zod";
|
|
9
|
+
MetaFileType["annotations"] = "annotations";
|
|
10
|
+
})(MetaFileType || (MetaFileType = {}));
|
|
11
|
+
export const guardMetaFileType = (type) => type && Object.values(MetaFileType).filter((t) => t === type)
|
|
12
|
+
? type
|
|
13
|
+
: undefined;
|
|
14
|
+
export var MetaFileExtension;
|
|
15
|
+
(function (MetaFileExtension) {
|
|
16
|
+
MetaFileExtension["ts"] = "ts";
|
|
17
|
+
MetaFileExtension["json"] = "json";
|
|
18
|
+
})(MetaFileExtension || (MetaFileExtension = {}));
|
|
19
|
+
export const guardMetaFileExtension = (ext) => ext && Object.values(MetaFileExtension).filter((e) => e === ext)
|
|
20
|
+
? ext
|
|
21
|
+
: undefined;
|
|
22
|
+
export var MetaPropertyType;
|
|
23
|
+
(function (MetaPropertyType) {
|
|
24
|
+
MetaPropertyType["string"] = "string";
|
|
25
|
+
MetaPropertyType["number"] = "number";
|
|
26
|
+
MetaPropertyType["boolean"] = "boolean";
|
|
27
|
+
MetaPropertyType["date"] = "date";
|
|
28
|
+
MetaPropertyType["array"] = "array";
|
|
29
|
+
MetaPropertyType["object"] = "object";
|
|
30
|
+
MetaPropertyType["key"] = "key";
|
|
31
|
+
MetaPropertyType["createTime"] = "createTime";
|
|
32
|
+
MetaPropertyType["updateTime"] = "updateTime";
|
|
33
|
+
})(MetaPropertyType || (MetaPropertyType = {}));
|
|
34
|
+
export var MetaMainType;
|
|
35
|
+
(function (MetaMainType) {
|
|
36
|
+
MetaMainType["interface"] = "interface";
|
|
37
|
+
MetaMainType["mainInterface"] = "mainInterface";
|
|
38
|
+
})(MetaMainType || (MetaMainType = {}));
|
|
39
|
+
export var MetaPropertyArrayType;
|
|
40
|
+
(function (MetaPropertyArrayType) {
|
|
41
|
+
MetaPropertyArrayType["string"] = "string";
|
|
42
|
+
MetaPropertyArrayType["number"] = "number";
|
|
43
|
+
MetaPropertyArrayType["boolean"] = "boolean";
|
|
44
|
+
MetaPropertyArrayType["date"] = "date";
|
|
45
|
+
MetaPropertyArrayType["object"] = "object";
|
|
46
|
+
})(MetaPropertyArrayType || (MetaPropertyArrayType = {}));
|
|
47
|
+
export var MetaNumberFormat;
|
|
48
|
+
(function (MetaNumberFormat) {
|
|
49
|
+
MetaNumberFormat["int32"] = "int32";
|
|
50
|
+
MetaNumberFormat["uint32"] = "uint32";
|
|
51
|
+
MetaNumberFormat["float32"] = "float32";
|
|
52
|
+
MetaNumberFormat["float64"] = "float64";
|
|
53
|
+
MetaNumberFormat["safeint"] = "safeint";
|
|
54
|
+
})(MetaNumberFormat || (MetaNumberFormat = {}));
|
|
55
|
+
export var MetaStringFormat;
|
|
56
|
+
(function (MetaStringFormat) {
|
|
57
|
+
MetaStringFormat["email"] = "email";
|
|
58
|
+
MetaStringFormat["url"] = "url";
|
|
59
|
+
MetaStringFormat["emoji"] = "emoji";
|
|
60
|
+
MetaStringFormat["uuid"] = "uuid";
|
|
61
|
+
MetaStringFormat["guid"] = "guid";
|
|
62
|
+
MetaStringFormat["nanoid"] = "nanoid";
|
|
63
|
+
MetaStringFormat["cuid"] = "cuid";
|
|
64
|
+
MetaStringFormat["cuid2"] = "cuid2";
|
|
65
|
+
MetaStringFormat["ulid"] = "ulid";
|
|
66
|
+
MetaStringFormat["xid"] = "xid";
|
|
67
|
+
MetaStringFormat["ksuid"] = "ksuid";
|
|
68
|
+
MetaStringFormat["datetime"] = "datetime";
|
|
69
|
+
MetaStringFormat["date"] = "date";
|
|
70
|
+
MetaStringFormat["time"] = "time";
|
|
71
|
+
MetaStringFormat["duration"] = "duration";
|
|
72
|
+
MetaStringFormat["ipv4"] = "ipv4";
|
|
73
|
+
MetaStringFormat["ipv6"] = "ipv6";
|
|
74
|
+
MetaStringFormat["cidrv4"] = "cidrv4";
|
|
75
|
+
MetaStringFormat["cidrv6"] = "cidrv6";
|
|
76
|
+
MetaStringFormat["base64"] = "base64";
|
|
77
|
+
MetaStringFormat["base64url"] = "base64url";
|
|
78
|
+
MetaStringFormat["json_string"] = "json_string";
|
|
79
|
+
MetaStringFormat["e164"] = "e164";
|
|
80
|
+
MetaStringFormat["lowercase"] = "lowercase";
|
|
81
|
+
MetaStringFormat["uppercase"] = "uppercase";
|
|
82
|
+
MetaStringFormat["regex"] = "regex";
|
|
83
|
+
MetaStringFormat["jwt"] = "jwt";
|
|
84
|
+
MetaStringFormat["starts_with"] = "starts_with";
|
|
85
|
+
MetaStringFormat["ends_with"] = "ends_with";
|
|
86
|
+
MetaStringFormat["includes"] = "includes";
|
|
87
|
+
})(MetaStringFormat || (MetaStringFormat = {}));
|
|
88
|
+
export var CrudRouteName;
|
|
89
|
+
(function (CrudRouteName) {
|
|
90
|
+
CrudRouteName["create"] = "create";
|
|
91
|
+
CrudRouteName["update"] = "update";
|
|
92
|
+
CrudRouteName["delete"] = "delete";
|
|
93
|
+
CrudRouteName["get"] = "get";
|
|
94
|
+
CrudRouteName["query"] = "query";
|
|
95
|
+
CrudRouteName["count"] = "count";
|
|
96
|
+
CrudRouteName["exists"] = "exists";
|
|
97
|
+
})(CrudRouteName || (CrudRouteName = {}));
|
|
98
|
+
export const isCrudRoute = (routeName) => !!Object.values(CrudRouteName).find((r) => r === routeName);
|
|
99
|
+
export const hasCrudRoute = (routeNames) => !!routeNames.find((routeName) => isCrudRoute(routeName));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { MetaImport } from "./meta.types.js";
|
|
3
|
+
export interface ExtractedImport {
|
|
4
|
+
module: string;
|
|
5
|
+
defaultImport?: string;
|
|
6
|
+
namedImports?: string[];
|
|
7
|
+
namespaceImport?: string;
|
|
8
|
+
isTypeOnly?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const extractNamedImports: (sourceFile: ts.SourceFile | string) => MetaImport[];
|
|
11
|
+
export declare const extractImports: (sourceFile: ts.SourceFile) => ExtractedImport[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { createSourceFiles } from "./meta.common.js";
|
|
3
|
+
export const extractNamedImports = (sourceFile) => {
|
|
4
|
+
if (typeof sourceFile === "string") {
|
|
5
|
+
const files = createSourceFiles([sourceFile]);
|
|
6
|
+
if (files.length === 0)
|
|
7
|
+
return [];
|
|
8
|
+
sourceFile = files[0].sourceFile;
|
|
9
|
+
}
|
|
10
|
+
const results = [];
|
|
11
|
+
const imports = extractImports(sourceFile);
|
|
12
|
+
for (const imp of imports) {
|
|
13
|
+
if (!imp.namedImports || imp.namedImports.length === 0)
|
|
14
|
+
continue;
|
|
15
|
+
results.push({
|
|
16
|
+
path: imp.module,
|
|
17
|
+
props: [...imp.namedImports],
|
|
18
|
+
isType: imp.isTypeOnly,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return results;
|
|
22
|
+
};
|
|
23
|
+
export const extractImports = (sourceFile) => {
|
|
24
|
+
const imports = [];
|
|
25
|
+
sourceFile.forEachChild((node) => {
|
|
26
|
+
if (ts.isImportDeclaration(node) && node.moduleSpecifier) {
|
|
27
|
+
const moduleName = node.moduleSpecifier.text;
|
|
28
|
+
let defaultImport;
|
|
29
|
+
let namedImports = [];
|
|
30
|
+
let namespaceImport;
|
|
31
|
+
if (!node.importClause)
|
|
32
|
+
return;
|
|
33
|
+
if (node.importClause.name)
|
|
34
|
+
defaultImport = node.importClause.name.text;
|
|
35
|
+
const isTypeOnly = node.importClause.phaseModifier === ts.SyntaxKind.TypeKeyword;
|
|
36
|
+
if (node.importClause.namedBindings) {
|
|
37
|
+
if (ts.isNamedImports(node.importClause.namedBindings)) {
|
|
38
|
+
namedImports = node.importClause.namedBindings.elements.map((el) => el.name.text);
|
|
39
|
+
}
|
|
40
|
+
else if (ts.isNamespaceImport(node.importClause.namedBindings)) {
|
|
41
|
+
namespaceImport = node.importClause.namedBindings.name.text;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
imports.push({
|
|
45
|
+
module: moduleName,
|
|
46
|
+
defaultImport,
|
|
47
|
+
namedImports: namedImports.length ? namedImports : undefined,
|
|
48
|
+
namespaceImport,
|
|
49
|
+
isTypeOnly,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return imports;
|
|
54
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MetaMainType } from "./meta.enum.js";
|
|
2
|
+
import { MetaPropertyData } from "./meta.properties.js";
|
|
3
|
+
import { MetaImport, MetaInterfaceOptions, MetaMainBaseOptions, MetaMainInterfaceOptions, MetaRouteParams, WithoutBase } from "./meta.types.js";
|
|
4
|
+
export type MetaMainDecoratorMap<DEF = any> = Record<MetaMainDecorator, DEF>;
|
|
5
|
+
export type WithMainDecoratorMap<T, R extends MetaMainDecoratorMap<T>> = R;
|
|
6
|
+
export declare enum MetaMainDecorator {
|
|
7
|
+
MetaInterface = "MetaInterface",
|
|
8
|
+
MetaMainInterface = "MetaMainInterface"
|
|
9
|
+
}
|
|
10
|
+
export declare const metaMainOptionsMap: MetaMainOptionsMap;
|
|
11
|
+
export type MetaMainOptionsMap = WithMainDecoratorMap<MetaMainType, {
|
|
12
|
+
[MetaMainDecorator.MetaInterface]: MetaMainType.interface;
|
|
13
|
+
[MetaMainDecorator.MetaMainInterface]: MetaMainType.mainInterface;
|
|
14
|
+
}>;
|
|
15
|
+
export type MetaMainOptionsBase = WithMainDecoratorMap<MetaMainBaseOptions, {
|
|
16
|
+
[MetaMainDecorator.MetaInterface]: MetaInterfaceOptions;
|
|
17
|
+
[MetaMainDecorator.MetaMainInterface]: MetaMainInterfaceOptions;
|
|
18
|
+
}>;
|
|
19
|
+
export type MetaMainOptions = Partial<WithMainDecoratorMap<WithoutBase<MetaMainBaseOptions>, {
|
|
20
|
+
[MetaMainDecorator.MetaInterface]: WithoutBase<MetaMainOptionsBase[MetaMainDecorator.MetaInterface]>;
|
|
21
|
+
[MetaMainDecorator.MetaMainInterface]: WithoutBase<MetaMainOptionsBase[MetaMainDecorator.MetaMainInterface]>;
|
|
22
|
+
}>>;
|
|
23
|
+
export type MetaRoutes = Record<string, MetaRouteParams>;
|
|
24
|
+
export interface MetaMainData {
|
|
25
|
+
templateName: string;
|
|
26
|
+
title: string;
|
|
27
|
+
inputFilePath: string;
|
|
28
|
+
repoInputFilePath: string;
|
|
29
|
+
properties: MetaPropertyData[];
|
|
30
|
+
routes: MetaRoutes;
|
|
31
|
+
additionalImports?: MetaImport[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MetaMainType } from "./meta.enum.js";
|
|
2
|
+
export var MetaMainDecorator;
|
|
3
|
+
(function (MetaMainDecorator) {
|
|
4
|
+
MetaMainDecorator["MetaInterface"] = "MetaInterface";
|
|
5
|
+
MetaMainDecorator["MetaMainInterface"] = "MetaMainInterface";
|
|
6
|
+
})(MetaMainDecorator || (MetaMainDecorator = {}));
|
|
7
|
+
export const metaMainOptionsMap = {
|
|
8
|
+
[MetaMainDecorator.MetaInterface]: MetaMainType.interface,
|
|
9
|
+
[MetaMainDecorator.MetaMainInterface]: MetaMainType.mainInterface,
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MetaFileType } from "./meta.enum.js";
|
|
2
|
+
import { MetaNames } from "./meta.types.js";
|
|
3
|
+
export declare const metaRename: (name: string, type: MetaFileType | string) => string;
|
|
4
|
+
export declare const metaBasename: (name: string) => string;
|
|
5
|
+
export declare const isMetaNameType: (name: string, type: MetaFileType) => boolean;
|
|
6
|
+
export declare const metaNames: (basename: string) => MetaNames;
|
|
7
|
+
export declare const metaFrontendNames: (basename: string) => MetaNames;
|
|
8
|
+
export declare const metaBackendNames: (basename: string) => MetaNames;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { lowerFirstLetter, TargetType, upperFirstLetter, } from "./meta.common.js";
|
|
2
|
+
import { MetaFileType } from "./meta.enum.js";
|
|
3
|
+
export const metaRename = (name, type) => `${metaBasename(name)}${upperFirstLetter(type)}`;
|
|
4
|
+
export const metaBasename = (name) => {
|
|
5
|
+
for (const type of Object.values(MetaFileType)) {
|
|
6
|
+
if (isMetaNameType(name, type))
|
|
7
|
+
return `${name.substring(0, name.length - type.length)}`;
|
|
8
|
+
}
|
|
9
|
+
return name.substring(0);
|
|
10
|
+
};
|
|
11
|
+
export const isMetaNameType = (name, type) => name.endsWith(upperFirstLetter(type));
|
|
12
|
+
export const metaNames = (basename) => ({
|
|
13
|
+
basename,
|
|
14
|
+
targetType: TargetType.common,
|
|
15
|
+
template: metaRename(basename, MetaFileType.template),
|
|
16
|
+
doc: metaRename(basename, MetaFileType.doc),
|
|
17
|
+
routes: metaRename(basename, MetaFileType.routes),
|
|
18
|
+
api: "",
|
|
19
|
+
func: "",
|
|
20
|
+
store: metaRename(basename, "store"),
|
|
21
|
+
shape: lowerFirstLetter(metaRename(basename, "shape")),
|
|
22
|
+
schema: lowerFirstLetter(metaRename(basename, "schema")),
|
|
23
|
+
});
|
|
24
|
+
export const metaFrontendNames = (basename) => ({
|
|
25
|
+
...metaNames(basename),
|
|
26
|
+
targetType: TargetType.frontend,
|
|
27
|
+
api: metaRename(basename, "feApi"),
|
|
28
|
+
func: metaRename(basename, "feFunction"),
|
|
29
|
+
});
|
|
30
|
+
export const metaBackendNames = (basename) => ({
|
|
31
|
+
...metaNames(basename),
|
|
32
|
+
targetType: TargetType.frontend,
|
|
33
|
+
api: metaRename(basename, "beApi"),
|
|
34
|
+
func: metaRename(basename, "beFunction"),
|
|
35
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { MetaPropertyType } from "./meta.enum.js";
|
|
2
|
+
import { MetaPropertyBaseOptions, WithoutBase, MetaKeyOptions, MetaCreateTimeOptions, MetaUpdateTimeOptions, MetaNumberOptions, MetaStringOptions, MetaArrayOptions, MetaObjectOptions, MetaDateOptions, MetaBooleanOptions } from "./meta.types.js";
|
|
3
|
+
export type MetaPropertyDecoratorMap<DEF = any> = Record<MetaPropertyDecorator, DEF>;
|
|
4
|
+
export type WithPropertyDecoratorMap<T, R extends MetaPropertyDecoratorMap<T>> = R;
|
|
5
|
+
export declare enum MetaPropertyDecorator {
|
|
6
|
+
MetaKey = "MetaKey",
|
|
7
|
+
MetaCreateTime = "MetaCreateTime",
|
|
8
|
+
MetaUpdateTime = "MetaUpdateTime",
|
|
9
|
+
MetaNumber = "MetaNumber",
|
|
10
|
+
MetaString = "MetaString",
|
|
11
|
+
MetaArray = "MetaArray",
|
|
12
|
+
MetaObject = "MetaObject",
|
|
13
|
+
MetaDate = "MetaDate",
|
|
14
|
+
MetaBoolean = "MetaBoolean"
|
|
15
|
+
}
|
|
16
|
+
export declare const metaPropertyOptionsMap: MetaPropertyOptionsMap;
|
|
17
|
+
export type MetaPropertyOptionsMap = WithPropertyDecoratorMap<MetaPropertyType, {
|
|
18
|
+
[MetaPropertyDecorator.MetaKey]: MetaPropertyType.key;
|
|
19
|
+
[MetaPropertyDecorator.MetaCreateTime]: MetaPropertyType.createTime;
|
|
20
|
+
[MetaPropertyDecorator.MetaUpdateTime]: MetaPropertyType.updateTime;
|
|
21
|
+
[MetaPropertyDecorator.MetaNumber]: MetaPropertyType.number;
|
|
22
|
+
[MetaPropertyDecorator.MetaString]: MetaPropertyType.string;
|
|
23
|
+
[MetaPropertyDecorator.MetaArray]: MetaPropertyType.array;
|
|
24
|
+
[MetaPropertyDecorator.MetaObject]: MetaPropertyType.object;
|
|
25
|
+
[MetaPropertyDecorator.MetaDate]: MetaPropertyType.date;
|
|
26
|
+
[MetaPropertyDecorator.MetaBoolean]: MetaPropertyType.boolean;
|
|
27
|
+
}>;
|
|
28
|
+
export type MetaPropertyOptionsBase = WithPropertyDecoratorMap<MetaPropertyBaseOptions, {
|
|
29
|
+
[MetaPropertyDecorator.MetaKey]: MetaKeyOptions;
|
|
30
|
+
[MetaPropertyDecorator.MetaCreateTime]: MetaCreateTimeOptions;
|
|
31
|
+
[MetaPropertyDecorator.MetaUpdateTime]: MetaUpdateTimeOptions;
|
|
32
|
+
[MetaPropertyDecorator.MetaNumber]: MetaNumberOptions;
|
|
33
|
+
[MetaPropertyDecorator.MetaString]: MetaStringOptions;
|
|
34
|
+
[MetaPropertyDecorator.MetaArray]: MetaArrayOptions;
|
|
35
|
+
[MetaPropertyDecorator.MetaObject]: MetaObjectOptions;
|
|
36
|
+
[MetaPropertyDecorator.MetaDate]: MetaDateOptions;
|
|
37
|
+
[MetaPropertyDecorator.MetaBoolean]: MetaBooleanOptions;
|
|
38
|
+
}>;
|
|
39
|
+
export type MetaPropertyOptions = Partial<WithPropertyDecoratorMap<WithoutBase<MetaPropertyBaseOptions>, {
|
|
40
|
+
[MetaPropertyDecorator.MetaKey]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaKey]>;
|
|
41
|
+
[MetaPropertyDecorator.MetaCreateTime]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaCreateTime]>;
|
|
42
|
+
[MetaPropertyDecorator.MetaUpdateTime]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaUpdateTime]>;
|
|
43
|
+
[MetaPropertyDecorator.MetaNumber]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaNumber]>;
|
|
44
|
+
[MetaPropertyDecorator.MetaString]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaString]>;
|
|
45
|
+
[MetaPropertyDecorator.MetaArray]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaArray]>;
|
|
46
|
+
[MetaPropertyDecorator.MetaObject]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaObject]>;
|
|
47
|
+
[MetaPropertyDecorator.MetaDate]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaDate]>;
|
|
48
|
+
[MetaPropertyDecorator.MetaBoolean]: WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaBoolean]>;
|
|
49
|
+
}>>;
|
|
50
|
+
export interface MetaPropertyData extends MetaPropertyBaseOptions, MetaPropertyOptions {
|
|
51
|
+
propertyKey: string;
|
|
52
|
+
propertyType: string;
|
|
53
|
+
}
|
|
54
|
+
export declare const castMetaPropertyNumber: (prop: MetaPropertyData) => MetaNumberOptions | null;
|
|
55
|
+
export declare const castMetaPropertyKey: (prop: MetaPropertyData) => MetaKeyOptions | null;
|
|
56
|
+
export declare const castMetaPropertyCreateTime: (prop: MetaPropertyData) => MetaCreateTimeOptions | null;
|
|
57
|
+
export declare const castMetaPropertyUpdateTime: (prop: MetaPropertyData) => MetaUpdateTimeOptions | null;
|
|
58
|
+
export declare const castMetaPropertyString: (prop: MetaPropertyData) => MetaStringOptions | null;
|
|
59
|
+
export declare const castMetaPropertyArray: (prop: MetaPropertyData) => MetaArrayOptions | null;
|
|
60
|
+
export declare const castMetaPropertyObject: (prop: MetaPropertyData) => MetaObjectOptions | null;
|
|
61
|
+
export declare const castMetaPropertyDate: (prop: MetaPropertyData) => MetaDateOptions | null;
|
|
62
|
+
export declare const castMetaPropertyBoolean: (prop: MetaPropertyData) => MetaBooleanOptions | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MetaPropertyType } from "./meta.enum.js";
|
|
2
|
+
export var MetaPropertyDecorator;
|
|
3
|
+
(function (MetaPropertyDecorator) {
|
|
4
|
+
MetaPropertyDecorator["MetaKey"] = "MetaKey";
|
|
5
|
+
MetaPropertyDecorator["MetaCreateTime"] = "MetaCreateTime";
|
|
6
|
+
MetaPropertyDecorator["MetaUpdateTime"] = "MetaUpdateTime";
|
|
7
|
+
MetaPropertyDecorator["MetaNumber"] = "MetaNumber";
|
|
8
|
+
MetaPropertyDecorator["MetaString"] = "MetaString";
|
|
9
|
+
MetaPropertyDecorator["MetaArray"] = "MetaArray";
|
|
10
|
+
MetaPropertyDecorator["MetaObject"] = "MetaObject";
|
|
11
|
+
MetaPropertyDecorator["MetaDate"] = "MetaDate";
|
|
12
|
+
MetaPropertyDecorator["MetaBoolean"] = "MetaBoolean";
|
|
13
|
+
})(MetaPropertyDecorator || (MetaPropertyDecorator = {}));
|
|
14
|
+
export const metaPropertyOptionsMap = {
|
|
15
|
+
[MetaPropertyDecorator.MetaKey]: MetaPropertyType.key,
|
|
16
|
+
[MetaPropertyDecorator.MetaCreateTime]: MetaPropertyType.createTime,
|
|
17
|
+
[MetaPropertyDecorator.MetaUpdateTime]: MetaPropertyType.updateTime,
|
|
18
|
+
[MetaPropertyDecorator.MetaNumber]: MetaPropertyType.number,
|
|
19
|
+
[MetaPropertyDecorator.MetaString]: MetaPropertyType.string,
|
|
20
|
+
[MetaPropertyDecorator.MetaArray]: MetaPropertyType.array,
|
|
21
|
+
[MetaPropertyDecorator.MetaObject]: MetaPropertyType.object,
|
|
22
|
+
[MetaPropertyDecorator.MetaDate]: MetaPropertyType.date,
|
|
23
|
+
[MetaPropertyDecorator.MetaBoolean]: MetaPropertyType.boolean,
|
|
24
|
+
};
|
|
25
|
+
export const castMetaPropertyNumber = (prop) => prop.type === MetaPropertyType.number ? prop : null;
|
|
26
|
+
export const castMetaPropertyKey = (prop) => prop.type === MetaPropertyType.key ? prop : null;
|
|
27
|
+
export const castMetaPropertyCreateTime = (prop) => prop.type === MetaPropertyType.createTime
|
|
28
|
+
? prop
|
|
29
|
+
: null;
|
|
30
|
+
export const castMetaPropertyUpdateTime = (prop) => prop.type === MetaPropertyType.updateTime
|
|
31
|
+
? prop
|
|
32
|
+
: null;
|
|
33
|
+
export const castMetaPropertyString = (prop) => prop.type === MetaPropertyType.string ? prop : null;
|
|
34
|
+
export const castMetaPropertyArray = (prop) => prop.type === MetaPropertyType.array ? prop : null;
|
|
35
|
+
export const castMetaPropertyObject = (prop) => prop.type === MetaPropertyType.object ? prop : null;
|
|
36
|
+
export const castMetaPropertyDate = (prop) => prop.type === MetaPropertyType.date ? prop : null;
|
|
37
|
+
export const castMetaPropertyBoolean = (prop) => prop.type === MetaPropertyType.boolean ? prop : null;
|