@mxpicture/gcp-functions-tools 0.1.69 → 0.1.71
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/{testTemplates → 4testing/templates}/template.medication.js +1 -1
- package/dist/{testTemplates → 4testing/templates}/template.settings.js +1 -1
- package/dist/4testing/utils.d.ts +5 -0
- package/dist/4testing/utils.js +14 -0
- package/dist/generator/GeneratorAnnotations.js +13 -11
- package/dist/generator/GeneratorBackend.js +7 -2
- package/dist/meta/meta.main.d.ts +3 -0
- package/dist/meta/meta.main.js +28 -1
- package/package.json +4 -3
- /package/dist/{testTemplates → 4testing/templates}/template.medication.d.ts +0 -0
- /package/dist/{testTemplates → 4testing/templates}/template.settings.d.ts +0 -0
|
@@ -19,7 +19,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
19
19
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
20
20
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
21
|
};
|
|
22
|
-
import { MetaArray, MetaCreateTime, MetaDate, MetaInterface, MetaKey, MetaMainInterface, MetaNumber, MetaObject, MetaString, MetaUpdateTime, } from "
|
|
22
|
+
import { MetaArray, MetaCreateTime, MetaDate, MetaInterface, MetaKey, MetaMainInterface, MetaNumber, MetaObject, MetaString, MetaUpdateTime, } from "../../meta/meta.decorators.js";
|
|
23
23
|
import { MetaPropertyType } from "@mxpicture/gcp-functions-common/meta";
|
|
24
24
|
let MedicationPlanTimesTemplate = class MedicationPlanTimesTemplate {
|
|
25
25
|
morning;
|
|
@@ -19,7 +19,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
19
19
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
20
20
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
21
|
};
|
|
22
|
-
import { MetaBoolean, MetaCreateTime, MetaKey, MetaMainInterface, MetaNumber, MetaString, MetaUpdateTime, } from "
|
|
22
|
+
import { MetaBoolean, MetaCreateTime, MetaKey, MetaMainInterface, MetaNumber, MetaString, MetaUpdateTime, } from "../../meta/meta.decorators.js";
|
|
23
23
|
let SettingsTemplate = class SettingsTemplate {
|
|
24
24
|
id;
|
|
25
25
|
createTime;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const testingDir: string;
|
|
2
|
+
export declare const wsRoot: string;
|
|
3
|
+
export declare const templatesDir: string;
|
|
4
|
+
export declare const createTestWorkspace: () => Promise<string>;
|
|
5
|
+
export declare const removeTestWorkspace: (p: string | null) => Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
export const testingDir = __dirname;
|
|
4
|
+
export const wsRoot = resolve(testingDir, "../..");
|
|
5
|
+
export const templatesDir = resolve(testingDir, "./templates");
|
|
6
|
+
export const createTestWorkspace = async () => mkdtemp(join(testingDir, "generator-test-"));
|
|
7
|
+
export const removeTestWorkspace = async (p) => {
|
|
8
|
+
if (!p)
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
return rm(p, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
catch { }
|
|
14
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MetaFileType, MetaFileExtension, MetaTargetType, } from "@mxpicture/gcp-functions-common/meta";
|
|
2
|
-
import { stripAnnotationsHeader, } from "@mxpicture/gcp-functions-common/types";
|
|
3
2
|
import { Collector } from "../common/Collector.js";
|
|
4
3
|
import { formatJson2Spaces } from "../meta/meta.common.js";
|
|
4
|
+
import { mapAnnotationsHeader } from "../meta/meta.main.js";
|
|
5
5
|
import { Generator } from "./Generator.js";
|
|
6
6
|
const typeRegex = /\"type\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
7
7
|
const itemTypeRegex = /\"itemType\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
8
|
+
const propertyRefRegex = /\"propertyRef\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
8
9
|
export class GeneratorAnnotations extends Generator {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(MetaFileType.annotations, MetaFileExtension.ts, MetaTargetType.common, Collector.instance());
|
|
@@ -20,36 +21,37 @@ export class GeneratorAnnotations extends Generator {
|
|
|
20
21
|
},
|
|
21
22
|
{
|
|
22
23
|
path: "@mxpicture/gcp-functions-common/meta",
|
|
23
|
-
props: ["MetaPropertyType"],
|
|
24
|
+
props: ["MetaPropertyType", "MetaPropertyDataWoType"],
|
|
24
25
|
isType: false,
|
|
25
26
|
},
|
|
26
27
|
],
|
|
27
28
|
name: mainData.templateName,
|
|
28
29
|
};
|
|
29
|
-
const
|
|
30
|
-
...mainData,
|
|
31
|
-
routes: Object.entries(mainData.routes).map(([name, params]) => ({
|
|
32
|
-
...params,
|
|
33
|
-
name,
|
|
34
|
-
})),
|
|
35
|
-
properties: mainData.properties,
|
|
36
|
-
};
|
|
37
|
-
const header = stripAnnotationsHeader(_header);
|
|
30
|
+
const header = mapAnnotationsHeader(mainData);
|
|
38
31
|
const json = formatJson2Spaces(JSON.stringify(header));
|
|
39
32
|
const lines = json.split("\n");
|
|
40
33
|
res.code.push(`export const ${names.annotations}: AnnotationsHeader = `);
|
|
34
|
+
// replace enums and types
|
|
41
35
|
for (let line of lines) {
|
|
36
|
+
// type
|
|
42
37
|
let match = null;
|
|
43
38
|
match = line.match(typeRegex);
|
|
44
39
|
while (match && match.length > 1) {
|
|
45
40
|
line = line.replace(typeRegex, `type: MetaPropertyType.${match[1]}`);
|
|
46
41
|
match = line.match(typeRegex);
|
|
47
42
|
}
|
|
43
|
+
// itemType
|
|
48
44
|
match = line.match(itemTypeRegex);
|
|
49
45
|
while (match && match.length > 1) {
|
|
50
46
|
line = line.replace(itemTypeRegex, `itemType: MetaPropertyType.${match[1]}`);
|
|
51
47
|
match = line.match(itemTypeRegex);
|
|
52
48
|
}
|
|
49
|
+
// propertyRef
|
|
50
|
+
match = line.match(propertyRefRegex);
|
|
51
|
+
while (match && match.length > 1) {
|
|
52
|
+
line = line.replace(propertyRefRegex, `propertyRef: "${match[1]}" as keyof MetaPropertyDataWoType`);
|
|
53
|
+
match = line.match(propertyRefRegex);
|
|
54
|
+
}
|
|
53
55
|
res.code.push(line);
|
|
54
56
|
}
|
|
55
57
|
res.code.push(";");
|
|
@@ -22,7 +22,7 @@ export class GeneratorBackend extends Generator {
|
|
|
22
22
|
imports: [
|
|
23
23
|
{
|
|
24
24
|
path: "@mxpicture/gcp-functions-common/types",
|
|
25
|
-
props: ["ApiFromRoutes"],
|
|
25
|
+
props: ["ApiFromRoutes", "FunctionRequest", "FunctionResponse"],
|
|
26
26
|
isType: true,
|
|
27
27
|
},
|
|
28
28
|
{
|
|
@@ -45,6 +45,11 @@ export class GeneratorBackend extends Generator {
|
|
|
45
45
|
props: ["FirestoreDataConverter"],
|
|
46
46
|
isType: true,
|
|
47
47
|
},
|
|
48
|
+
{
|
|
49
|
+
path: "firebase-functions/v2/https",
|
|
50
|
+
props: ["CallableFunction"],
|
|
51
|
+
isType: true,
|
|
52
|
+
},
|
|
48
53
|
{
|
|
49
54
|
path: this.importCommon(MetaFileType.routes),
|
|
50
55
|
props: [names.routes],
|
|
@@ -110,7 +115,7 @@ export class GeneratorBackend extends Generator {
|
|
|
110
115
|
}
|
|
111
116
|
buildCreate(names) {
|
|
112
117
|
return [
|
|
113
|
-
`export const create${names.basename}Function = (api: I${names.api}) => {`,
|
|
118
|
+
`export const create${names.basename}Function = (api: I${names.api}): CallableFunction<FunctionRequest<unknown>,Promise<FunctionResponse<unknown>>,unknown> => {`,
|
|
114
119
|
` const store = new ${names.store}();`,
|
|
115
120
|
"",
|
|
116
121
|
` const val = new Validation<${names.doc}>("${lowerFirstLetter(names.basename)}");`,
|
package/dist/meta/meta.main.d.ts
CHANGED
|
@@ -30,3 +30,6 @@ export interface MetaMainData {
|
|
|
30
30
|
routes: MetaRoutes;
|
|
31
31
|
additionalImports?: MetaImport[];
|
|
32
32
|
}
|
|
33
|
+
export declare const mapAnnotationsHeader: (data: MetaMainData) => import("@mxpicture/gcp-functions-common/types").AnnotationsHeader;
|
|
34
|
+
export declare const mapAnnotationsRoutes: (routes: MetaRoutes) => import("@mxpicture/gcp-functions-common/types").AnnotationsRoute[];
|
|
35
|
+
export declare const mapAnnotationsProperty: (prop: MetaPropertyData) => import("@mxpicture/gcp-functions-common/types").AnnotationsProperty;
|
package/dist/meta/meta.main.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { MetaMainType, } from "@mxpicture/gcp-functions-common/meta";
|
|
1
|
+
import { MetaMainType, MetaPropertyDecorator, } from "@mxpicture/gcp-functions-common/meta";
|
|
2
|
+
import { stripAnnotationsRoute, stripAnnotationsProperty, stripAnnotationsHeader, } from "@mxpicture/gcp-functions-common/types";
|
|
2
3
|
export var MetaMainDecorator;
|
|
3
4
|
(function (MetaMainDecorator) {
|
|
4
5
|
MetaMainDecorator["MetaInterface"] = "MetaInterface";
|
|
@@ -8,3 +9,29 @@ export const metaMainOptionsMap = {
|
|
|
8
9
|
[MetaMainDecorator.MetaInterface]: MetaMainType.interface,
|
|
9
10
|
[MetaMainDecorator.MetaMainInterface]: MetaMainType.mainInterface,
|
|
10
11
|
};
|
|
12
|
+
export const mapAnnotationsHeader = (data) => stripAnnotationsHeader({
|
|
13
|
+
...data,
|
|
14
|
+
routes: mapAnnotationsRoutes(data.routes),
|
|
15
|
+
properties: data.properties.map(mapAnnotationsProperty),
|
|
16
|
+
});
|
|
17
|
+
export const mapAnnotationsRoutes = (routes) => Object.entries(routes).map(([name, params]) => stripAnnotationsRoute({
|
|
18
|
+
...params,
|
|
19
|
+
name,
|
|
20
|
+
}));
|
|
21
|
+
export const mapAnnotationsProperty = (prop) => {
|
|
22
|
+
const decorators = Object.values(MetaPropertyDecorator);
|
|
23
|
+
let propertyRef = null;
|
|
24
|
+
// find ref/decorator
|
|
25
|
+
for (const decorator of decorators) {
|
|
26
|
+
if (decorator in prop && !!prop[decorator]) {
|
|
27
|
+
propertyRef = decorator;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!propertyRef)
|
|
32
|
+
throw new Error(`No property ref / decorator found in ${prop.propertyKey}`);
|
|
33
|
+
return stripAnnotationsProperty({
|
|
34
|
+
...prop,
|
|
35
|
+
propertyRef,
|
|
36
|
+
});
|
|
37
|
+
};
|
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.71",
|
|
4
4
|
"description": "Tools for google cloud functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
"clean": "rm -rf dist .tsbuildinfo tsconfig.tsbuildinfo node_modules",
|
|
28
28
|
"lint": "eslint \"src/**/*.{ts,tsx}\" --ext .ts,.tsx",
|
|
29
29
|
"build": "tsc -b .",
|
|
30
|
-
"test": "vitest run"
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"test:clean": "rm -rf src/4testing/generator-test-*"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@mxpicture/gcp-functions-common": "
|
|
37
|
+
"@mxpicture/gcp-functions-common": "^0.1.71",
|
|
37
38
|
"json5": "^1.0.2",
|
|
38
39
|
"micromatch": "^4.0.8",
|
|
39
40
|
"prettier": "^2.8.8",
|
|
File without changes
|
|
File without changes
|