@mxpicture/gcp-functions-tools 0.1.65 → 0.1.67
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/common/Barrel.d.ts +1 -0
- package/dist/common/Barrel.js +5 -0
- package/dist/common/Directories.d.ts +17 -5
- package/dist/common/Directories.js +26 -9
- package/dist/generator/Generator.d.ts +4 -0
- package/dist/generator/Generator.js +12 -0
- package/dist/generator/GeneratorAnnotations.js +5 -5
- package/dist/generator/GeneratorBackend.js +4 -4
- package/dist/generator/GeneratorFrontend.js +3 -3
- package/dist/generator/GeneratorRoutes.js +1 -1
- package/dist/meta/meta.common.d.ts +1 -0
- package/dist/meta/meta.common.js +3 -0
- package/dist/meta/meta.names.js +1 -0
- package/dist/meta/meta.types.d.ts +1 -0
- package/dist/meta/meta.types.js +1 -0
- package/dist/testTemplates/template.medication.d.ts +35 -0
- package/dist/testTemplates/template.medication.js +134 -0
- package/dist/testTemplates/template.settings.d.ts +23 -0
- package/dist/testTemplates/template.settings.js +73 -0
- package/package.json +10 -3
package/dist/common/Barrel.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface BarrelFileGroup {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class Barrel {
|
|
13
13
|
readonly targetType: TargetType;
|
|
14
|
+
static ignorePackageJson: boolean;
|
|
14
15
|
static instances: Barrel[];
|
|
15
16
|
protected filePaths: string[];
|
|
16
17
|
static instance(targetType: TargetType): Barrel;
|
package/dist/common/Barrel.js
CHANGED
|
@@ -4,6 +4,7 @@ import { mkdir, writeFile, readFile } from "node:fs/promises";
|
|
|
4
4
|
import { directories } from "./Directories.js";
|
|
5
5
|
export class Barrel {
|
|
6
6
|
targetType;
|
|
7
|
+
static ignorePackageJson = false;
|
|
7
8
|
static instances = [];
|
|
8
9
|
filePaths = [];
|
|
9
10
|
static instance(targetType) {
|
|
@@ -39,6 +40,10 @@ export class Barrel {
|
|
|
39
40
|
await Promise.all(promises);
|
|
40
41
|
}
|
|
41
42
|
async ensurePackageBarrels(results) {
|
|
43
|
+
if (Barrel.ignorePackageJson) {
|
|
44
|
+
console.log("ensurePackageBarrels ignored");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
42
47
|
const filePath = directories.targetPackageJson(this.targetType);
|
|
43
48
|
const raw = await readFile(filePath, "utf8");
|
|
44
49
|
const pkg = JSON.parse(raw);
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { TargetType } from "../meta/meta.common.js";
|
|
2
2
|
import { MetaFileType } from "../meta/meta.enum.js";
|
|
3
|
+
export interface DirectoriesResolverParams {
|
|
4
|
+
targetType: TargetType;
|
|
5
|
+
fileType: MetaFileType;
|
|
6
|
+
}
|
|
7
|
+
export type DirectoriesResolver = (imp: DirectoriesResolverParams, // e.g ${TargetType}/${MetaFileType} --> common/doc,
|
|
8
|
+
current: DirectoriesResolverParams) => string;
|
|
3
9
|
export interface DirectoriesParams {
|
|
4
10
|
cwd: string;
|
|
5
11
|
templatesDir: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
frontend: string;
|
|
9
|
-
backend: string;
|
|
10
|
-
};
|
|
12
|
+
targetDir: string;
|
|
13
|
+
importResolver: DirectoriesResolver;
|
|
11
14
|
}
|
|
12
15
|
declare class Directories {
|
|
13
16
|
protected _params: DirectoriesParams | null;
|
|
@@ -19,6 +22,15 @@ declare class Directories {
|
|
|
19
22
|
toTargetPath(type: MetaFileType, filename: string, targetType: TargetType): string;
|
|
20
23
|
targetPackageJson(targetType: TargetType): string;
|
|
21
24
|
templatesPathRead(): Promise<string[]>;
|
|
25
|
+
resolveImport(imp: {
|
|
26
|
+
targetType: TargetType;
|
|
27
|
+
fileType: MetaFileType;
|
|
28
|
+
} | string, currentFile: {
|
|
29
|
+
targetType: TargetType;
|
|
30
|
+
fileType: MetaFileType;
|
|
31
|
+
} | string): string;
|
|
32
|
+
splitResolverPath(path: string): DirectoriesResolverParams;
|
|
33
|
+
concatResolverPath(params: DirectoriesResolverParams): string;
|
|
22
34
|
protected get params(): DirectoriesParams;
|
|
23
35
|
}
|
|
24
36
|
export declare const directories: Directories;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join, resolve } from "node:path";
|
|
2
|
-
import { isTemplateFile } from "../meta/meta.common.js";
|
|
2
|
+
import { guardTargetType, isTemplateFile, } from "../meta/meta.common.js";
|
|
3
|
+
import { guardMetaFileType } from "../meta/meta.enum.js";
|
|
3
4
|
import { readdir } from "node:fs/promises";
|
|
4
5
|
let __instance = null;
|
|
5
6
|
const instance = () => {
|
|
@@ -14,11 +15,8 @@ class Directories {
|
|
|
14
15
|
this._params = {
|
|
15
16
|
cwd: params.cwd,
|
|
16
17
|
templatesDir: resolve(params.cwd, params.templatesDir),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
frontend: resolve(params.cwd, params.targetDirs.frontend),
|
|
20
|
-
common: resolve(params.cwd, params.targetDirs.common),
|
|
21
|
-
},
|
|
18
|
+
targetDir: resolve(params.cwd, params.targetDir),
|
|
19
|
+
importResolver: params.importResolver,
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
22
|
get templatesDir() {
|
|
@@ -28,9 +26,7 @@ class Directories {
|
|
|
28
26
|
return `${this.targetBasePath(targetType)}/src`;
|
|
29
27
|
}
|
|
30
28
|
targetBasePath(targetType) {
|
|
31
|
-
return
|
|
32
|
-
? this.params.targetDirs[targetType]
|
|
33
|
-
: this.params.targetDirs.common;
|
|
29
|
+
return join(this.params.targetDir, targetType);
|
|
34
30
|
}
|
|
35
31
|
toTargetPath(type, filename, targetType) {
|
|
36
32
|
return join(this.targetDir(targetType), type, filename);
|
|
@@ -43,6 +39,27 @@ class Directories {
|
|
|
43
39
|
.filter(isTemplateFile)
|
|
44
40
|
.map((name) => join(this.templatesDir, name));
|
|
45
41
|
}
|
|
42
|
+
resolveImport(imp, currentFile) {
|
|
43
|
+
return this.params.importResolver(typeof imp === "string" ? this.splitResolverPath(imp) : imp, typeof currentFile === "string"
|
|
44
|
+
? this.splitResolverPath(currentFile)
|
|
45
|
+
: currentFile);
|
|
46
|
+
}
|
|
47
|
+
splitResolverPath(path) {
|
|
48
|
+
const parts = path.split("/");
|
|
49
|
+
if (parts.length !== 2)
|
|
50
|
+
throw new Error(`${path} does not fit the pattern {TargetType}/{MetaFileType}`);
|
|
51
|
+
const [_targetType, _fileType] = parts;
|
|
52
|
+
const fileType = guardMetaFileType(_fileType);
|
|
53
|
+
if (!fileType)
|
|
54
|
+
throw new Error(`${path}: fileType ${_fileType} invalid`);
|
|
55
|
+
const targetType = guardTargetType(_targetType);
|
|
56
|
+
if (!targetType)
|
|
57
|
+
throw new Error(`${path}: targetType ${_targetType} invalid`);
|
|
58
|
+
return { targetType, fileType };
|
|
59
|
+
}
|
|
60
|
+
concatResolverPath(params) {
|
|
61
|
+
return `${params.targetType}/${params.fileType}`;
|
|
62
|
+
}
|
|
46
63
|
get params() {
|
|
47
64
|
if (!this._params)
|
|
48
65
|
throw new Error("Directories: setup needed!");
|
|
@@ -27,6 +27,10 @@ export declare abstract class Generator {
|
|
|
27
27
|
constructor(type: MetaFileType, ext: MetaFileExtension, targetType: TargetType, collector: Collector, useAdditionalImports?: boolean);
|
|
28
28
|
run(interfaceData: MetaMainData[]): GeneratorResultFile[];
|
|
29
29
|
static write(files: GeneratorResultFile[]): Promise<void>;
|
|
30
|
+
resolveImport(targetType: TargetType, fileType: MetaFileType): string;
|
|
31
|
+
importCommon(fileType: MetaFileType): string;
|
|
32
|
+
importFrontend(fileType: MetaFileType): string;
|
|
33
|
+
importBackend(fileType: MetaFileType): string;
|
|
30
34
|
protected addCode(res: GeneratorResultFile, code: string[]): void;
|
|
31
35
|
protected addImport(res: GeneratorResultFile, imp: MetaImport): void;
|
|
32
36
|
protected addImports(res: GeneratorResultFile, imports: MetaImport[]): void;
|
|
@@ -86,6 +86,18 @@ export class Generator {
|
|
|
86
86
|
}
|
|
87
87
|
await Promise.all(promises);
|
|
88
88
|
}
|
|
89
|
+
resolveImport(targetType, fileType) {
|
|
90
|
+
return directories.resolveImport({ targetType, fileType }, { targetType: this.targetType, fileType: this.type });
|
|
91
|
+
}
|
|
92
|
+
importCommon(fileType) {
|
|
93
|
+
return this.resolveImport(TargetType.common, fileType);
|
|
94
|
+
}
|
|
95
|
+
importFrontend(fileType) {
|
|
96
|
+
return this.resolveImport(TargetType.frontend, fileType);
|
|
97
|
+
}
|
|
98
|
+
importBackend(fileType) {
|
|
99
|
+
return this.resolveImport(TargetType.backend, fileType);
|
|
100
|
+
}
|
|
89
101
|
addCode(res, code) {
|
|
90
102
|
if (res.code.length > 0)
|
|
91
103
|
res.code.push("");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Collector } from "../common/Collector.js";
|
|
2
2
|
import { TargetType } from "../meta/meta.common.js";
|
|
3
3
|
import { MetaFileType, MetaFileExtension } from "../meta/meta.enum.js";
|
|
4
|
-
import { isMetaNameType, metaBasename } from "../meta/meta.names.js";
|
|
5
4
|
import { Generator } from "./Generator.js";
|
|
6
5
|
export class GeneratorAnnotations extends Generator {
|
|
7
6
|
constructor() {
|
|
@@ -13,10 +12,11 @@ export class GeneratorAnnotations extends Generator {
|
|
|
13
12
|
imports: [],
|
|
14
13
|
name: mainData.templateName,
|
|
15
14
|
};
|
|
16
|
-
res.code.push(`export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
res.code.push(
|
|
15
|
+
res.code.push(`export const ${names.annotations} = {`);
|
|
16
|
+
res.code.push(` title: "${mainData.title}",`);
|
|
17
|
+
res.code.push(` routes: [],`); // todo
|
|
18
|
+
res.code.push(` properties: ${JSON.stringify(mainData.properties)},`);
|
|
19
|
+
res.code.push("};");
|
|
20
20
|
return res;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -46,12 +46,12 @@ export class GeneratorBackend extends Generator {
|
|
|
46
46
|
isType: true,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
path:
|
|
49
|
+
path: this.importCommon(MetaFileType.routes),
|
|
50
50
|
props: [names.routes],
|
|
51
51
|
isType: true,
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
|
-
path:
|
|
54
|
+
path: this.importCommon(MetaFileType.doc),
|
|
55
55
|
props: [names.doc],
|
|
56
56
|
isType: true,
|
|
57
57
|
},
|
|
@@ -61,12 +61,12 @@ export class GeneratorBackend extends Generator {
|
|
|
61
61
|
isType: false,
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
path:
|
|
64
|
+
path: this.importCommon(MetaFileType.routes),
|
|
65
65
|
props: [`${names.routes}Name`],
|
|
66
66
|
isType: false,
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
path:
|
|
69
|
+
path: this.importBackend(MetaFileType.zod),
|
|
70
70
|
props: [names.shape],
|
|
71
71
|
isType: false,
|
|
72
72
|
},
|
|
@@ -24,7 +24,7 @@ export class GeneratorFrontend extends Generator {
|
|
|
24
24
|
isType: false,
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
path:
|
|
27
|
+
path: this.importCommon(MetaFileType.routes),
|
|
28
28
|
props: [`${names.routes}Name`],
|
|
29
29
|
isType: false,
|
|
30
30
|
},
|
|
@@ -39,12 +39,12 @@ export class GeneratorFrontend extends Generator {
|
|
|
39
39
|
isType: true,
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
|
-
path:
|
|
42
|
+
path: this.importCommon(MetaFileType.routes),
|
|
43
43
|
props: [names.routes],
|
|
44
44
|
isType: true,
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
|
-
path:
|
|
47
|
+
path: this.importCommon(MetaFileType.doc),
|
|
48
48
|
props: [names.doc],
|
|
49
49
|
isType: true,
|
|
50
50
|
},
|
package/dist/meta/meta.common.js
CHANGED
|
@@ -8,6 +8,9 @@ export var TargetType;
|
|
|
8
8
|
TargetType["frontend"] = "frontend";
|
|
9
9
|
TargetType["backend"] = "backend";
|
|
10
10
|
})(TargetType || (TargetType = {}));
|
|
11
|
+
export const guardTargetType = (type) => type && Object.values(TargetType).filter((t) => t === type)
|
|
12
|
+
? type
|
|
13
|
+
: undefined;
|
|
11
14
|
export const isTemplateFile = (filename) => isTsFile(filename, MetaFileType.template);
|
|
12
15
|
export const isTsFile = (filename, type) => isAnyFile(filename, type, MetaFileExtension.ts);
|
|
13
16
|
export const isAnyFile = (filename, type, ext) => {
|
package/dist/meta/meta.names.js
CHANGED
|
@@ -20,6 +20,7 @@ export const metaNames = (basename) => ({
|
|
|
20
20
|
store: metaRename(basename, "store"),
|
|
21
21
|
shape: lowerFirstLetter(metaRename(basename, "shape")),
|
|
22
22
|
schema: lowerFirstLetter(metaRename(basename, "schema")),
|
|
23
|
+
annotations: lowerFirstLetter(metaRename(basename, "annotations")),
|
|
23
24
|
});
|
|
24
25
|
export const metaFrontendNames = (basename) => ({
|
|
25
26
|
...metaNames(basename),
|
package/dist/meta/meta.types.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
import type { DocumentAdmin, DocumentKey } from "@mxpicture/gcp-functions-common/types";
|
|
14
|
+
export declare class MedicationPlanTimesTemplate {
|
|
15
|
+
morning: number;
|
|
16
|
+
noon: number;
|
|
17
|
+
evening: number;
|
|
18
|
+
night: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class MedicationPlanTemplate {
|
|
21
|
+
lastPickDate?: Date;
|
|
22
|
+
times: MedicationPlanTimesTemplate;
|
|
23
|
+
}
|
|
24
|
+
export declare class MedicationTemplate implements DocumentKey, DocumentAdmin {
|
|
25
|
+
id: string;
|
|
26
|
+
createTime?: Date;
|
|
27
|
+
updateTime?: Date;
|
|
28
|
+
ingredient: string;
|
|
29
|
+
dosageMg: number;
|
|
30
|
+
tradeNames: string[];
|
|
31
|
+
size?: number;
|
|
32
|
+
stock: number;
|
|
33
|
+
orderMail?: string;
|
|
34
|
+
plan?: MedicationPlanTemplate;
|
|
35
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
|
+
};
|
|
22
|
+
import { MetaArray, MetaCreateTime, MetaDate, MetaInterface, MetaKey, MetaMainInterface, MetaNumber, MetaObject, MetaString, MetaUpdateTime, } from "../meta/meta.decorators.js";
|
|
23
|
+
import { MetaPropertyType } from "../meta/meta.enum.js";
|
|
24
|
+
let MedicationPlanTimesTemplate = class MedicationPlanTimesTemplate {
|
|
25
|
+
morning;
|
|
26
|
+
noon;
|
|
27
|
+
evening;
|
|
28
|
+
night;
|
|
29
|
+
};
|
|
30
|
+
__decorate([
|
|
31
|
+
MetaNumber({ title: "Morning", min: 0, minInclusive: false }),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], MedicationPlanTimesTemplate.prototype, "morning", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
MetaNumber({ title: "Noon", min: 0, minInclusive: false }),
|
|
36
|
+
__metadata("design:type", Number)
|
|
37
|
+
], MedicationPlanTimesTemplate.prototype, "noon", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
MetaNumber({ title: "Evening", min: 0, minInclusive: false }),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], MedicationPlanTimesTemplate.prototype, "evening", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
MetaNumber({ title: "Night", min: 0, minInclusive: false }),
|
|
44
|
+
__metadata("design:type", Number)
|
|
45
|
+
], MedicationPlanTimesTemplate.prototype, "night", void 0);
|
|
46
|
+
MedicationPlanTimesTemplate = __decorate([
|
|
47
|
+
MetaInterface({ title: "Medication Plan Times" })
|
|
48
|
+
], MedicationPlanTimesTemplate);
|
|
49
|
+
export { MedicationPlanTimesTemplate };
|
|
50
|
+
let MedicationPlanTemplate = class MedicationPlanTemplate {
|
|
51
|
+
lastPickDate;
|
|
52
|
+
times;
|
|
53
|
+
};
|
|
54
|
+
__decorate([
|
|
55
|
+
MetaDate({ title: "Last Pick Date", optional: true }),
|
|
56
|
+
__metadata("design:type", Date)
|
|
57
|
+
], MedicationPlanTemplate.prototype, "lastPickDate", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
MetaObject({ title: "Times" }),
|
|
60
|
+
__metadata("design:type", MedicationPlanTimesTemplate)
|
|
61
|
+
], MedicationPlanTemplate.prototype, "times", void 0);
|
|
62
|
+
MedicationPlanTemplate = __decorate([
|
|
63
|
+
MetaInterface({ title: "Medication Plan" })
|
|
64
|
+
], MedicationPlanTemplate);
|
|
65
|
+
export { MedicationPlanTemplate };
|
|
66
|
+
let MedicationTemplate = class MedicationTemplate {
|
|
67
|
+
id;
|
|
68
|
+
createTime;
|
|
69
|
+
updateTime;
|
|
70
|
+
ingredient;
|
|
71
|
+
dosageMg;
|
|
72
|
+
tradeNames;
|
|
73
|
+
size;
|
|
74
|
+
stock;
|
|
75
|
+
orderMail;
|
|
76
|
+
plan;
|
|
77
|
+
};
|
|
78
|
+
__decorate([
|
|
79
|
+
MetaKey({}),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], MedicationTemplate.prototype, "id", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
MetaCreateTime({ optional: true }),
|
|
84
|
+
__metadata("design:type", Date)
|
|
85
|
+
], MedicationTemplate.prototype, "createTime", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
MetaUpdateTime({ optional: true }),
|
|
88
|
+
__metadata("design:type", Date)
|
|
89
|
+
], MedicationTemplate.prototype, "updateTime", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
MetaString({ title: "Ingredient" }),
|
|
92
|
+
__metadata("design:type", String)
|
|
93
|
+
], MedicationTemplate.prototype, "ingredient", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
MetaNumber({ title: "Dosage mg", min: 0 }),
|
|
96
|
+
__metadata("design:type", Number)
|
|
97
|
+
], MedicationTemplate.prototype, "dosageMg", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
MetaArray({ title: "Trade Names", itemType: MetaPropertyType.string }),
|
|
100
|
+
__metadata("design:type", Array)
|
|
101
|
+
], MedicationTemplate.prototype, "tradeNames", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
MetaNumber({ title: "Size", min: 1, optional: true }),
|
|
104
|
+
__metadata("design:type", Number)
|
|
105
|
+
], MedicationTemplate.prototype, "size", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
MetaNumber({ title: "Stock", min: 0 }),
|
|
108
|
+
__metadata("design:type", Number)
|
|
109
|
+
], MedicationTemplate.prototype, "stock", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
MetaString({ title: "Order Mail", optional: true }),
|
|
112
|
+
__metadata("design:type", String)
|
|
113
|
+
], MedicationTemplate.prototype, "orderMail", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
MetaObject({ title: "Plan", optional: true }),
|
|
116
|
+
__metadata("design:type", MedicationPlanTemplate)
|
|
117
|
+
], MedicationTemplate.prototype, "plan", void 0);
|
|
118
|
+
MedicationTemplate = __decorate([
|
|
119
|
+
MetaMainInterface({
|
|
120
|
+
title: "Medication",
|
|
121
|
+
routes: {
|
|
122
|
+
crud: true,
|
|
123
|
+
testRoute: { requestType: "DocumentKey", responseType: "{test:boolean}" },
|
|
124
|
+
},
|
|
125
|
+
additionalImports: [
|
|
126
|
+
{
|
|
127
|
+
path: "@mxpicture/gcp-functions-common/types",
|
|
128
|
+
props: ["DocumentKey"],
|
|
129
|
+
isType: true,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
})
|
|
133
|
+
], MedicationTemplate);
|
|
134
|
+
export { MedicationTemplate };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
import type { DocumentAdmin, DocumentKey } from "@mxpicture/gcp-functions-common/types";
|
|
14
|
+
export declare class SettingsTemplate implements DocumentKey, DocumentAdmin {
|
|
15
|
+
id: string;
|
|
16
|
+
createTime?: Date;
|
|
17
|
+
updateTime?: Date;
|
|
18
|
+
active: boolean;
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
valueNumber?: number;
|
|
22
|
+
valueString?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
|
+
};
|
|
22
|
+
import { MetaBoolean, MetaCreateTime, MetaKey, MetaMainInterface, MetaNumber, MetaString, MetaUpdateTime, } from "../meta/meta.decorators.js";
|
|
23
|
+
let SettingsTemplate = class SettingsTemplate {
|
|
24
|
+
id;
|
|
25
|
+
createTime;
|
|
26
|
+
updateTime;
|
|
27
|
+
active;
|
|
28
|
+
name;
|
|
29
|
+
type; // todo enum
|
|
30
|
+
valueNumber;
|
|
31
|
+
valueString;
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
MetaKey({}),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], SettingsTemplate.prototype, "id", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
MetaCreateTime({ optional: true }),
|
|
39
|
+
__metadata("design:type", Date)
|
|
40
|
+
], SettingsTemplate.prototype, "createTime", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
MetaUpdateTime({ optional: true }),
|
|
43
|
+
__metadata("design:type", Date)
|
|
44
|
+
], SettingsTemplate.prototype, "updateTime", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
MetaBoolean({ title: "Active" }),
|
|
47
|
+
__metadata("design:type", Boolean)
|
|
48
|
+
], SettingsTemplate.prototype, "active", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
MetaString({ title: "Name" }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], SettingsTemplate.prototype, "name", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
MetaString({ title: "Type" }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], SettingsTemplate.prototype, "type", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
MetaNumber({ title: "Number", optional: true }),
|
|
59
|
+
__metadata("design:type", Number)
|
|
60
|
+
], SettingsTemplate.prototype, "valueNumber", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
MetaString({ title: "String", optional: true }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], SettingsTemplate.prototype, "valueString", void 0);
|
|
65
|
+
SettingsTemplate = __decorate([
|
|
66
|
+
MetaMainInterface({
|
|
67
|
+
title: "Settings",
|
|
68
|
+
routes: {
|
|
69
|
+
crud: true,
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
], SettingsTemplate);
|
|
73
|
+
export { SettingsTemplate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/gcp-functions-tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.67",
|
|
4
4
|
"description": "Tools for google cloud functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"clean": "rm -rf dist .tsbuildinfo tsconfig.tsbuildinfo node_modules",
|
|
28
28
|
"lint": "eslint \"src/**/*.{ts,tsx}\" --ext .ts,.tsx",
|
|
29
|
-
"build": "tsc -b ."
|
|
29
|
+
"build": "tsc -b .",
|
|
30
|
+
"test": "vitest run"
|
|
30
31
|
},
|
|
31
32
|
"publishConfig": {
|
|
32
33
|
"access": "public"
|
|
@@ -41,9 +42,15 @@
|
|
|
41
42
|
"zod": "^4.3.6"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
45
|
+
"@eslint/js": "^9.39.2",
|
|
44
46
|
"@types/micromatch": "^4.0.10",
|
|
45
47
|
"@types/node": "^25.2.0",
|
|
46
48
|
"@types/prettier": "^2.7.3",
|
|
47
|
-
"typescript": "^
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
50
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
51
|
+
"eslint": "^9.39.2",
|
|
52
|
+
"execa": "^9.6.1",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vitest": "^4.0.18"
|
|
48
55
|
}
|
|
49
56
|
}
|