@mxpicture/gcp-functions-common 0.1.68 → 0.1.69
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/helper/helper.object.d.ts +1 -0
- package/dist/helper/helper.object.js +7 -0
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/meta/index.d.ts +2 -0
- package/dist/meta/index.js +3 -0
- package/dist/meta/meta.enum.d.ts +93 -0
- package/dist/meta/meta.enum.js +108 -0
- package/dist/meta/meta.properties.d.ts +79 -0
- package/dist/meta/meta.properties.js +76 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/types.annotation.d.ts +15 -0
- package/dist/types/types.annotation.js +32 -0
- package/dist/types/types.meta.d.ts +113 -0
- package/dist/types/types.meta.js +33 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stripObject: <T extends object>(route: T, allowedKeys: (keyof T)[]) => T;
|
package/dist/helper/index.d.ts
CHANGED
package/dist/helper/index.js
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
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 MetaTargetType {
|
|
17
|
+
common = "common",
|
|
18
|
+
frontend = "frontend",
|
|
19
|
+
backend = "backend"
|
|
20
|
+
}
|
|
21
|
+
export declare const guardMetaTargetType: (type: string | undefined) => MetaTargetType | undefined;
|
|
22
|
+
export declare enum MetaPropertyType {
|
|
23
|
+
string = "string",
|
|
24
|
+
number = "number",
|
|
25
|
+
boolean = "boolean",
|
|
26
|
+
date = "date",
|
|
27
|
+
array = "array",
|
|
28
|
+
object = "object",
|
|
29
|
+
key = "key",
|
|
30
|
+
createTime = "createTime",
|
|
31
|
+
updateTime = "updateTime"
|
|
32
|
+
}
|
|
33
|
+
export declare enum MetaMainType {
|
|
34
|
+
interface = "interface",
|
|
35
|
+
mainInterface = "mainInterface"
|
|
36
|
+
}
|
|
37
|
+
export declare enum MetaPropertyArrayType {
|
|
38
|
+
string = "string",
|
|
39
|
+
number = "number",
|
|
40
|
+
boolean = "boolean",
|
|
41
|
+
date = "date",
|
|
42
|
+
object = "object"
|
|
43
|
+
}
|
|
44
|
+
export declare enum MetaNumberFormat {
|
|
45
|
+
int32 = "int32",
|
|
46
|
+
uint32 = "uint32",
|
|
47
|
+
float32 = "float32",
|
|
48
|
+
float64 = "float64",
|
|
49
|
+
safeint = "safeint"
|
|
50
|
+
}
|
|
51
|
+
export declare enum MetaStringFormat {
|
|
52
|
+
email = "email",
|
|
53
|
+
url = "url",
|
|
54
|
+
emoji = "emoji",
|
|
55
|
+
uuid = "uuid",
|
|
56
|
+
guid = "guid",
|
|
57
|
+
nanoid = "nanoid",
|
|
58
|
+
cuid = "cuid",
|
|
59
|
+
cuid2 = "cuid2",
|
|
60
|
+
ulid = "ulid",
|
|
61
|
+
xid = "xid",
|
|
62
|
+
ksuid = "ksuid",
|
|
63
|
+
datetime = "datetime",
|
|
64
|
+
date = "date",
|
|
65
|
+
time = "time",
|
|
66
|
+
duration = "duration",
|
|
67
|
+
ipv4 = "ipv4",
|
|
68
|
+
ipv6 = "ipv6",
|
|
69
|
+
cidrv4 = "cidrv4",
|
|
70
|
+
cidrv6 = "cidrv6",
|
|
71
|
+
base64 = "base64",
|
|
72
|
+
base64url = "base64url",
|
|
73
|
+
json_string = "json_string",
|
|
74
|
+
e164 = "e164",
|
|
75
|
+
lowercase = "lowercase",
|
|
76
|
+
uppercase = "uppercase",
|
|
77
|
+
regex = "regex",
|
|
78
|
+
jwt = "jwt",
|
|
79
|
+
starts_with = "starts_with",
|
|
80
|
+
ends_with = "ends_with",
|
|
81
|
+
includes = "includes"
|
|
82
|
+
}
|
|
83
|
+
export declare enum CrudRouteName {
|
|
84
|
+
create = "create",
|
|
85
|
+
update = "update",
|
|
86
|
+
delete = "delete",
|
|
87
|
+
get = "get",
|
|
88
|
+
query = "query",
|
|
89
|
+
count = "count",
|
|
90
|
+
exists = "exists"
|
|
91
|
+
}
|
|
92
|
+
export declare const isCrudRoute: (routeName: string) => boolean;
|
|
93
|
+
export declare const hasCrudRoute: (routeNames: string[]) => boolean;
|
|
@@ -0,0 +1,108 @@
|
|
|
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 MetaTargetType;
|
|
23
|
+
(function (MetaTargetType) {
|
|
24
|
+
MetaTargetType["common"] = "common";
|
|
25
|
+
MetaTargetType["frontend"] = "frontend";
|
|
26
|
+
MetaTargetType["backend"] = "backend";
|
|
27
|
+
})(MetaTargetType || (MetaTargetType = {}));
|
|
28
|
+
export const guardMetaTargetType = (type) => type && Object.values(MetaTargetType).filter((t) => t === type)
|
|
29
|
+
? type
|
|
30
|
+
: undefined;
|
|
31
|
+
export var MetaPropertyType;
|
|
32
|
+
(function (MetaPropertyType) {
|
|
33
|
+
MetaPropertyType["string"] = "string";
|
|
34
|
+
MetaPropertyType["number"] = "number";
|
|
35
|
+
MetaPropertyType["boolean"] = "boolean";
|
|
36
|
+
MetaPropertyType["date"] = "date";
|
|
37
|
+
MetaPropertyType["array"] = "array";
|
|
38
|
+
MetaPropertyType["object"] = "object";
|
|
39
|
+
MetaPropertyType["key"] = "key";
|
|
40
|
+
MetaPropertyType["createTime"] = "createTime";
|
|
41
|
+
MetaPropertyType["updateTime"] = "updateTime";
|
|
42
|
+
})(MetaPropertyType || (MetaPropertyType = {}));
|
|
43
|
+
export var MetaMainType;
|
|
44
|
+
(function (MetaMainType) {
|
|
45
|
+
MetaMainType["interface"] = "interface";
|
|
46
|
+
MetaMainType["mainInterface"] = "mainInterface";
|
|
47
|
+
})(MetaMainType || (MetaMainType = {}));
|
|
48
|
+
export var MetaPropertyArrayType;
|
|
49
|
+
(function (MetaPropertyArrayType) {
|
|
50
|
+
MetaPropertyArrayType["string"] = "string";
|
|
51
|
+
MetaPropertyArrayType["number"] = "number";
|
|
52
|
+
MetaPropertyArrayType["boolean"] = "boolean";
|
|
53
|
+
MetaPropertyArrayType["date"] = "date";
|
|
54
|
+
MetaPropertyArrayType["object"] = "object";
|
|
55
|
+
})(MetaPropertyArrayType || (MetaPropertyArrayType = {}));
|
|
56
|
+
export var MetaNumberFormat;
|
|
57
|
+
(function (MetaNumberFormat) {
|
|
58
|
+
MetaNumberFormat["int32"] = "int32";
|
|
59
|
+
MetaNumberFormat["uint32"] = "uint32";
|
|
60
|
+
MetaNumberFormat["float32"] = "float32";
|
|
61
|
+
MetaNumberFormat["float64"] = "float64";
|
|
62
|
+
MetaNumberFormat["safeint"] = "safeint";
|
|
63
|
+
})(MetaNumberFormat || (MetaNumberFormat = {}));
|
|
64
|
+
export var MetaStringFormat;
|
|
65
|
+
(function (MetaStringFormat) {
|
|
66
|
+
MetaStringFormat["email"] = "email";
|
|
67
|
+
MetaStringFormat["url"] = "url";
|
|
68
|
+
MetaStringFormat["emoji"] = "emoji";
|
|
69
|
+
MetaStringFormat["uuid"] = "uuid";
|
|
70
|
+
MetaStringFormat["guid"] = "guid";
|
|
71
|
+
MetaStringFormat["nanoid"] = "nanoid";
|
|
72
|
+
MetaStringFormat["cuid"] = "cuid";
|
|
73
|
+
MetaStringFormat["cuid2"] = "cuid2";
|
|
74
|
+
MetaStringFormat["ulid"] = "ulid";
|
|
75
|
+
MetaStringFormat["xid"] = "xid";
|
|
76
|
+
MetaStringFormat["ksuid"] = "ksuid";
|
|
77
|
+
MetaStringFormat["datetime"] = "datetime";
|
|
78
|
+
MetaStringFormat["date"] = "date";
|
|
79
|
+
MetaStringFormat["time"] = "time";
|
|
80
|
+
MetaStringFormat["duration"] = "duration";
|
|
81
|
+
MetaStringFormat["ipv4"] = "ipv4";
|
|
82
|
+
MetaStringFormat["ipv6"] = "ipv6";
|
|
83
|
+
MetaStringFormat["cidrv4"] = "cidrv4";
|
|
84
|
+
MetaStringFormat["cidrv6"] = "cidrv6";
|
|
85
|
+
MetaStringFormat["base64"] = "base64";
|
|
86
|
+
MetaStringFormat["base64url"] = "base64url";
|
|
87
|
+
MetaStringFormat["json_string"] = "json_string";
|
|
88
|
+
MetaStringFormat["e164"] = "e164";
|
|
89
|
+
MetaStringFormat["lowercase"] = "lowercase";
|
|
90
|
+
MetaStringFormat["uppercase"] = "uppercase";
|
|
91
|
+
MetaStringFormat["regex"] = "regex";
|
|
92
|
+
MetaStringFormat["jwt"] = "jwt";
|
|
93
|
+
MetaStringFormat["starts_with"] = "starts_with";
|
|
94
|
+
MetaStringFormat["ends_with"] = "ends_with";
|
|
95
|
+
MetaStringFormat["includes"] = "includes";
|
|
96
|
+
})(MetaStringFormat || (MetaStringFormat = {}));
|
|
97
|
+
export var CrudRouteName;
|
|
98
|
+
(function (CrudRouteName) {
|
|
99
|
+
CrudRouteName["create"] = "create";
|
|
100
|
+
CrudRouteName["update"] = "update";
|
|
101
|
+
CrudRouteName["delete"] = "delete";
|
|
102
|
+
CrudRouteName["get"] = "get";
|
|
103
|
+
CrudRouteName["query"] = "query";
|
|
104
|
+
CrudRouteName["count"] = "count";
|
|
105
|
+
CrudRouteName["exists"] = "exists";
|
|
106
|
+
})(CrudRouteName || (CrudRouteName = {}));
|
|
107
|
+
export const isCrudRoute = (routeName) => !!Object.values(CrudRouteName).find((r) => r === routeName);
|
|
108
|
+
export const hasCrudRoute = (routeNames) => !!routeNames.find((routeName) => isCrudRoute(routeName));
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MetaArrayOptions, MetaBooleanOptions, MetaCreateTimeOptions, MetaDateOptions, MetaKeyOptions, MetaNumberOptions, MetaObjectOptions, MetaPropertyBaseOptions, MetaStringOptions, MetaUpdateTimeOptions, WithoutBase, WithoutType } from "../types/types.meta.js";
|
|
2
|
+
import { MetaPropertyType } from "./meta.enum.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 type MetaPropertyOptionsWoType = Partial<WithPropertyDecoratorMap<WithoutType<WithoutBase<MetaPropertyBaseOptions>>, {
|
|
51
|
+
[MetaPropertyDecorator.MetaKey]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaKey]>>;
|
|
52
|
+
[MetaPropertyDecorator.MetaCreateTime]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaCreateTime]>>;
|
|
53
|
+
[MetaPropertyDecorator.MetaUpdateTime]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaUpdateTime]>>;
|
|
54
|
+
[MetaPropertyDecorator.MetaNumber]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaNumber]>>;
|
|
55
|
+
[MetaPropertyDecorator.MetaString]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaString]>>;
|
|
56
|
+
[MetaPropertyDecorator.MetaArray]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaArray]>>;
|
|
57
|
+
[MetaPropertyDecorator.MetaObject]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaObject]>>;
|
|
58
|
+
[MetaPropertyDecorator.MetaDate]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaDate]>>;
|
|
59
|
+
[MetaPropertyDecorator.MetaBoolean]: WithoutType<WithoutBase<MetaPropertyOptionsBase[MetaPropertyDecorator.MetaBoolean]>>;
|
|
60
|
+
}>>;
|
|
61
|
+
export interface MetaPropertyData extends MetaPropertyBaseOptions, MetaPropertyOptions {
|
|
62
|
+
propertyKey: string;
|
|
63
|
+
propertyType: string;
|
|
64
|
+
}
|
|
65
|
+
export interface MetaPropertyDataWoType extends MetaPropertyBaseOptions, MetaPropertyOptionsWoType {
|
|
66
|
+
propertyKey: string;
|
|
67
|
+
propertyType: string;
|
|
68
|
+
}
|
|
69
|
+
export declare const stripMetaPropertyData: (data: MetaPropertyData) => MetaPropertyData;
|
|
70
|
+
export declare const stripMetaPropertyDataWoType: (data: MetaPropertyDataWoType) => MetaPropertyDataWoType;
|
|
71
|
+
export declare const castMetaPropertyNumber: (prop: MetaPropertyData) => MetaNumberOptions | null;
|
|
72
|
+
export declare const castMetaPropertyKey: (prop: MetaPropertyData) => MetaKeyOptions | null;
|
|
73
|
+
export declare const castMetaPropertyCreateTime: (prop: MetaPropertyData) => MetaCreateTimeOptions | null;
|
|
74
|
+
export declare const castMetaPropertyUpdateTime: (prop: MetaPropertyData) => MetaUpdateTimeOptions | null;
|
|
75
|
+
export declare const castMetaPropertyString: (prop: MetaPropertyData) => MetaStringOptions | null;
|
|
76
|
+
export declare const castMetaPropertyArray: (prop: MetaPropertyData) => MetaArrayOptions | null;
|
|
77
|
+
export declare const castMetaPropertyObject: (prop: MetaPropertyData) => MetaObjectOptions | null;
|
|
78
|
+
export declare const castMetaPropertyDate: (prop: MetaPropertyData) => MetaDateOptions | null;
|
|
79
|
+
export declare const castMetaPropertyBoolean: (prop: MetaPropertyData) => MetaBooleanOptions | null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { stripObject } from "../helper/helper.object.js";
|
|
2
|
+
import { MetaPropertyType } from "./meta.enum.js";
|
|
3
|
+
export var MetaPropertyDecorator;
|
|
4
|
+
(function (MetaPropertyDecorator) {
|
|
5
|
+
MetaPropertyDecorator["MetaKey"] = "MetaKey";
|
|
6
|
+
MetaPropertyDecorator["MetaCreateTime"] = "MetaCreateTime";
|
|
7
|
+
MetaPropertyDecorator["MetaUpdateTime"] = "MetaUpdateTime";
|
|
8
|
+
MetaPropertyDecorator["MetaNumber"] = "MetaNumber";
|
|
9
|
+
MetaPropertyDecorator["MetaString"] = "MetaString";
|
|
10
|
+
MetaPropertyDecorator["MetaArray"] = "MetaArray";
|
|
11
|
+
MetaPropertyDecorator["MetaObject"] = "MetaObject";
|
|
12
|
+
MetaPropertyDecorator["MetaDate"] = "MetaDate";
|
|
13
|
+
MetaPropertyDecorator["MetaBoolean"] = "MetaBoolean";
|
|
14
|
+
})(MetaPropertyDecorator || (MetaPropertyDecorator = {}));
|
|
15
|
+
export const metaPropertyOptionsMap = {
|
|
16
|
+
[MetaPropertyDecorator.MetaKey]: MetaPropertyType.key,
|
|
17
|
+
[MetaPropertyDecorator.MetaCreateTime]: MetaPropertyType.createTime,
|
|
18
|
+
[MetaPropertyDecorator.MetaUpdateTime]: MetaPropertyType.updateTime,
|
|
19
|
+
[MetaPropertyDecorator.MetaNumber]: MetaPropertyType.number,
|
|
20
|
+
[MetaPropertyDecorator.MetaString]: MetaPropertyType.string,
|
|
21
|
+
[MetaPropertyDecorator.MetaArray]: MetaPropertyType.array,
|
|
22
|
+
[MetaPropertyDecorator.MetaObject]: MetaPropertyType.object,
|
|
23
|
+
[MetaPropertyDecorator.MetaDate]: MetaPropertyType.date,
|
|
24
|
+
[MetaPropertyDecorator.MetaBoolean]: MetaPropertyType.boolean,
|
|
25
|
+
};
|
|
26
|
+
const metaPropertyData = {
|
|
27
|
+
propertyKey: undefined,
|
|
28
|
+
propertyType: undefined,
|
|
29
|
+
type: undefined,
|
|
30
|
+
title: undefined,
|
|
31
|
+
description: undefined,
|
|
32
|
+
optional: undefined,
|
|
33
|
+
[MetaPropertyDecorator.MetaKey]: undefined,
|
|
34
|
+
[MetaPropertyDecorator.MetaCreateTime]: undefined,
|
|
35
|
+
[MetaPropertyDecorator.MetaUpdateTime]: undefined,
|
|
36
|
+
[MetaPropertyDecorator.MetaNumber]: undefined,
|
|
37
|
+
[MetaPropertyDecorator.MetaString]: undefined,
|
|
38
|
+
[MetaPropertyDecorator.MetaArray]: undefined,
|
|
39
|
+
[MetaPropertyDecorator.MetaObject]: undefined,
|
|
40
|
+
[MetaPropertyDecorator.MetaDate]: undefined,
|
|
41
|
+
[MetaPropertyDecorator.MetaBoolean]: undefined,
|
|
42
|
+
};
|
|
43
|
+
const metaPropertyDataKeys = Object.keys(metaPropertyData);
|
|
44
|
+
export const stripMetaPropertyData = (data) => stripObject(data, metaPropertyDataKeys);
|
|
45
|
+
const metaPropertyDataWoType = {
|
|
46
|
+
propertyKey: undefined,
|
|
47
|
+
propertyType: undefined,
|
|
48
|
+
type: undefined,
|
|
49
|
+
title: undefined,
|
|
50
|
+
description: undefined,
|
|
51
|
+
optional: undefined,
|
|
52
|
+
[MetaPropertyDecorator.MetaKey]: undefined,
|
|
53
|
+
[MetaPropertyDecorator.MetaCreateTime]: undefined,
|
|
54
|
+
[MetaPropertyDecorator.MetaUpdateTime]: undefined,
|
|
55
|
+
[MetaPropertyDecorator.MetaNumber]: undefined,
|
|
56
|
+
[MetaPropertyDecorator.MetaString]: undefined,
|
|
57
|
+
[MetaPropertyDecorator.MetaArray]: undefined,
|
|
58
|
+
[MetaPropertyDecorator.MetaObject]: undefined,
|
|
59
|
+
[MetaPropertyDecorator.MetaDate]: undefined,
|
|
60
|
+
[MetaPropertyDecorator.MetaBoolean]: undefined,
|
|
61
|
+
};
|
|
62
|
+
const metaPropertyDataWoTypeKeys = Object.keys(metaPropertyDataWoType);
|
|
63
|
+
export const stripMetaPropertyDataWoType = (data) => stripObject(data, metaPropertyDataWoTypeKeys);
|
|
64
|
+
export const castMetaPropertyNumber = (prop) => prop.type === MetaPropertyType.number ? prop : null;
|
|
65
|
+
export const castMetaPropertyKey = (prop) => prop.type === MetaPropertyType.key ? prop : null;
|
|
66
|
+
export const castMetaPropertyCreateTime = (prop) => prop.type === MetaPropertyType.createTime
|
|
67
|
+
? prop
|
|
68
|
+
: null;
|
|
69
|
+
export const castMetaPropertyUpdateTime = (prop) => prop.type === MetaPropertyType.updateTime
|
|
70
|
+
? prop
|
|
71
|
+
: null;
|
|
72
|
+
export const castMetaPropertyString = (prop) => prop.type === MetaPropertyType.string ? prop : null;
|
|
73
|
+
export const castMetaPropertyArray = (prop) => prop.type === MetaPropertyType.array ? prop : null;
|
|
74
|
+
export const castMetaPropertyObject = (prop) => prop.type === MetaPropertyType.object ? prop : null;
|
|
75
|
+
export const castMetaPropertyDate = (prop) => prop.type === MetaPropertyType.date ? prop : null;
|
|
76
|
+
export const castMetaPropertyBoolean = (prop) => prop.type === MetaPropertyType.boolean ? prop : null;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
+
export * from "./types.annotation.js";
|
|
2
3
|
export * from "./types.document.js";
|
|
3
4
|
export * from "./types.filter.js";
|
|
4
5
|
export * from "./types.function.js";
|
|
6
|
+
export * from "./types.meta.js";
|
|
5
7
|
export * from "./types.routes.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MetaPropertyDataWoType } from "../meta/meta.properties.js";
|
|
2
|
+
export interface AnnotationsRoute {
|
|
3
|
+
name: string;
|
|
4
|
+
requestType: string;
|
|
5
|
+
responseType: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const stripAnnotationsRoute: (route: AnnotationsRoute) => AnnotationsRoute;
|
|
8
|
+
export type AnnotationsProperty = MetaPropertyDataWoType;
|
|
9
|
+
export declare const stripAnnotationsProperty: (prop: AnnotationsProperty) => AnnotationsProperty;
|
|
10
|
+
export interface AnnotationsHeader {
|
|
11
|
+
title: string;
|
|
12
|
+
properties: AnnotationsProperty[];
|
|
13
|
+
routes: AnnotationsRoute[];
|
|
14
|
+
}
|
|
15
|
+
export declare const stripAnnotationsHeader: (header: AnnotationsHeader) => AnnotationsHeader;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { stripObject } from "../helper/helper.object.js";
|
|
2
|
+
import { MetaPropertyDecorator, stripMetaPropertyDataWoType, } from "../meta/meta.properties.js";
|
|
3
|
+
import { withoutBaseIgnoreValues, withoutTypeIgnoreValues, } from "./types.meta.js";
|
|
4
|
+
const annotationsRoute = {
|
|
5
|
+
name: undefined,
|
|
6
|
+
requestType: undefined,
|
|
7
|
+
responseType: undefined,
|
|
8
|
+
};
|
|
9
|
+
const annotationsRouteKeys = Object.keys(annotationsRoute);
|
|
10
|
+
export const stripAnnotationsRoute = (route) => stripObject(route, annotationsRouteKeys);
|
|
11
|
+
export const stripAnnotationsProperty = (prop) => {
|
|
12
|
+
const decorators = Object.values(MetaPropertyDecorator);
|
|
13
|
+
const result = { ...stripMetaPropertyDataWoType(prop) };
|
|
14
|
+
const ignores = [...withoutBaseIgnoreValues, ...withoutTypeIgnoreValues];
|
|
15
|
+
for (const [key, params] of Object.entries(result))
|
|
16
|
+
if (decorators.find((d) => d === key))
|
|
17
|
+
for (const metaKey of Object.keys(params))
|
|
18
|
+
if (ignores.includes(metaKey))
|
|
19
|
+
delete params[metaKey];
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
const annotationsHeader = {
|
|
23
|
+
title: undefined,
|
|
24
|
+
properties: undefined,
|
|
25
|
+
routes: undefined,
|
|
26
|
+
};
|
|
27
|
+
const annotationsHeaderKeys = Object.keys(annotationsHeader);
|
|
28
|
+
export const stripAnnotationsHeader = (header) => {
|
|
29
|
+
header.routes = header.routes.map(stripAnnotationsRoute);
|
|
30
|
+
header.properties = header.properties.map(stripAnnotationsProperty);
|
|
31
|
+
return stripObject(header, annotationsHeaderKeys);
|
|
32
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript decorators for generating Zod schemas from classes
|
|
3
|
+
*
|
|
4
|
+
* Example usage:
|
|
5
|
+
*
|
|
6
|
+
* @Interface({title: "Medication"})
|
|
7
|
+
* export class MedicationDoc {
|
|
8
|
+
* @PropString()
|
|
9
|
+
* ingredient!: string;
|
|
10
|
+
* @PropNumber({title: "Dosage mg", min: 0, max: 50})
|
|
11
|
+
* dosageMg!: number;
|
|
12
|
+
* tradeNames!: string[];
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
import { MetaPropertyType, MetaNumberFormat, MetaStringFormat, MetaMainType, MetaTargetType } from "../meta/meta.enum.js";
|
|
16
|
+
export interface MetaRouteParams {
|
|
17
|
+
requestType: string;
|
|
18
|
+
responseType: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MetaMainBaseOptions {
|
|
21
|
+
type: MetaMainType;
|
|
22
|
+
title: string;
|
|
23
|
+
}
|
|
24
|
+
export interface MetaInterfaceOptions extends MetaMainBaseOptions {
|
|
25
|
+
type: MetaMainType.interface;
|
|
26
|
+
}
|
|
27
|
+
export interface MetaImport {
|
|
28
|
+
props: string[];
|
|
29
|
+
path: string;
|
|
30
|
+
isType?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface MetaMainInterfaceOptions extends MetaMainBaseOptions {
|
|
33
|
+
type: MetaMainType.mainInterface;
|
|
34
|
+
routes: Record<string, MetaRouteParams> | {
|
|
35
|
+
crud?: boolean;
|
|
36
|
+
};
|
|
37
|
+
additionalImports?: MetaImport[];
|
|
38
|
+
}
|
|
39
|
+
export interface MetaPropertyBaseOptions {
|
|
40
|
+
type: MetaPropertyType;
|
|
41
|
+
title?: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
optional?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const withoutBaseIgnoreValues: readonly ["title", "description", "optional"];
|
|
46
|
+
export type WithoutBaseIgnore = (typeof withoutBaseIgnoreValues)[number];
|
|
47
|
+
export type WithoutBase<T extends MetaPropertyBaseOptions | MetaMainBaseOptions> = Omit<T, WithoutBaseIgnore>;
|
|
48
|
+
export declare const withoutTypeIgnoreValues: readonly ["type"];
|
|
49
|
+
export type WithoutTypeIgnore = (typeof withoutTypeIgnoreValues)[number];
|
|
50
|
+
export type WithoutType<T extends MetaPropertyBaseOptions | MetaMainBaseOptions> = Omit<T, WithoutTypeIgnore>;
|
|
51
|
+
export interface MetaNumberOptions extends MetaPropertyBaseOptions {
|
|
52
|
+
type: MetaPropertyType.number;
|
|
53
|
+
min?: number;
|
|
54
|
+
minInclusive?: boolean;
|
|
55
|
+
max?: number;
|
|
56
|
+
maxInclusive?: boolean;
|
|
57
|
+
multipleOf?: number;
|
|
58
|
+
format?: MetaNumberFormat;
|
|
59
|
+
}
|
|
60
|
+
export interface MetaKeyOptions extends MetaPropertyBaseOptions {
|
|
61
|
+
type: MetaPropertyType.key;
|
|
62
|
+
}
|
|
63
|
+
export interface MetaCreateTimeOptions extends MetaPropertyBaseOptions {
|
|
64
|
+
type: MetaPropertyType.createTime;
|
|
65
|
+
}
|
|
66
|
+
export interface MetaUpdateTimeOptions extends MetaPropertyBaseOptions {
|
|
67
|
+
type: MetaPropertyType.updateTime;
|
|
68
|
+
}
|
|
69
|
+
export interface MetaStringOptions extends MetaPropertyBaseOptions {
|
|
70
|
+
type: MetaPropertyType.string;
|
|
71
|
+
minLength?: number;
|
|
72
|
+
maxLength?: number;
|
|
73
|
+
exactLength?: number;
|
|
74
|
+
regex?: string;
|
|
75
|
+
format?: MetaStringFormat | string;
|
|
76
|
+
}
|
|
77
|
+
export interface MetaArrayOptions extends MetaPropertyBaseOptions {
|
|
78
|
+
type: MetaPropertyType.array;
|
|
79
|
+
itemType?: MetaPropertyType;
|
|
80
|
+
minLength?: number;
|
|
81
|
+
maxLength?: number;
|
|
82
|
+
exactLength?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface MetaObjectOptions extends MetaPropertyBaseOptions {
|
|
85
|
+
type: MetaPropertyType.object;
|
|
86
|
+
}
|
|
87
|
+
export interface MetaDateOptions extends MetaPropertyBaseOptions {
|
|
88
|
+
type: MetaPropertyType.date;
|
|
89
|
+
}
|
|
90
|
+
export interface MetaBooleanOptions extends MetaPropertyBaseOptions {
|
|
91
|
+
type: MetaPropertyType.boolean;
|
|
92
|
+
}
|
|
93
|
+
export type MetaNamesMap = Record<string, string>;
|
|
94
|
+
export type WithMap<R extends MetaNamesMap> = R;
|
|
95
|
+
export type MetaNamesNoTarget = WithMap<{
|
|
96
|
+
basename: string;
|
|
97
|
+
template: string;
|
|
98
|
+
doc: string;
|
|
99
|
+
routes: string;
|
|
100
|
+
api: string;
|
|
101
|
+
func: string;
|
|
102
|
+
store: string;
|
|
103
|
+
shape: string;
|
|
104
|
+
schema: string;
|
|
105
|
+
annotations: string;
|
|
106
|
+
}>;
|
|
107
|
+
export interface MetaNames extends MetaNamesNoTarget {
|
|
108
|
+
targetType: MetaTargetType;
|
|
109
|
+
}
|
|
110
|
+
export type MetaNamesFromMap<R extends MetaNamesNoTarget> = {
|
|
111
|
+
[K in keyof R]: R[K];
|
|
112
|
+
};
|
|
113
|
+
export declare const metaNameProperties: (keyof MetaNamesNoTarget)[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript decorators for generating Zod schemas from classes
|
|
3
|
+
*
|
|
4
|
+
* Example usage:
|
|
5
|
+
*
|
|
6
|
+
* @Interface({title: "Medication"})
|
|
7
|
+
* export class MedicationDoc {
|
|
8
|
+
* @PropString()
|
|
9
|
+
* ingredient!: string;
|
|
10
|
+
* @PropNumber({title: "Dosage mg", min: 0, max: 50})
|
|
11
|
+
* dosageMg!: number;
|
|
12
|
+
* tradeNames!: string[];
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export const withoutBaseIgnoreValues = [
|
|
16
|
+
"title",
|
|
17
|
+
"description",
|
|
18
|
+
"optional",
|
|
19
|
+
];
|
|
20
|
+
export const withoutTypeIgnoreValues = ["type"];
|
|
21
|
+
const metaNameDummy = {
|
|
22
|
+
basename: "",
|
|
23
|
+
template: "",
|
|
24
|
+
doc: "",
|
|
25
|
+
routes: "",
|
|
26
|
+
api: "",
|
|
27
|
+
func: "",
|
|
28
|
+
store: "",
|
|
29
|
+
shape: "",
|
|
30
|
+
schema: "",
|
|
31
|
+
annotations: "",
|
|
32
|
+
};
|
|
33
|
+
export const metaNameProperties = Object.keys(metaNameDummy);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/gcp-functions-common",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.69",
|
|
4
4
|
"description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"./types": "./dist/types/index.js",
|
|
15
15
|
"./zod": "./dist/zod/index.js",
|
|
16
16
|
"./helper": "./dist/helper/index.js",
|
|
17
|
+
"./meta": "./dist/meta/index.js",
|
|
17
18
|
"./package.json": "./package.json"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|