@mxpicture/gcp-functions-common 0.1.80 → 0.1.82

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.
@@ -1,2 +1,3 @@
1
1
  export * from "./meta.enum.js";
2
+ export * from "./meta.main.js";
2
3
  export * from "./meta.properties.js";
@@ -1,3 +1,4 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
2
  export * from "./meta.enum.js";
3
+ export * from "./meta.main.js";
3
4
  export * from "./meta.properties.js";
@@ -30,7 +30,7 @@ export declare enum MetaPropertyType {
30
30
  createTime = "createTime",
31
31
  updateTime = "updateTime"
32
32
  }
33
- export declare enum MetaMainType {
33
+ export declare enum MetaHeadType {
34
34
  interface = "interface",
35
35
  mainInterface = "mainInterface"
36
36
  }
@@ -40,11 +40,11 @@ export var MetaPropertyType;
40
40
  MetaPropertyType["createTime"] = "createTime";
41
41
  MetaPropertyType["updateTime"] = "updateTime";
42
42
  })(MetaPropertyType || (MetaPropertyType = {}));
43
- export var MetaMainType;
44
- (function (MetaMainType) {
45
- MetaMainType["interface"] = "interface";
46
- MetaMainType["mainInterface"] = "mainInterface";
47
- })(MetaMainType || (MetaMainType = {}));
43
+ export var MetaHeadType;
44
+ (function (MetaHeadType) {
45
+ MetaHeadType["interface"] = "interface";
46
+ MetaHeadType["mainInterface"] = "mainInterface";
47
+ })(MetaHeadType || (MetaHeadType = {}));
48
48
  export var MetaPropertyArrayType;
49
49
  (function (MetaPropertyArrayType) {
50
50
  MetaPropertyArrayType["string"] = "string";
@@ -0,0 +1,35 @@
1
+ import { MetaHeadBaseOptions, MetaInterfaceOptions, MetaHeadInterfaceOptions, WithoutBase, MetaRouteParams, MetaImport } from "../types/types.meta.js";
2
+ import { MetaHeadType } from "./meta.enum.js";
3
+ import { MetaPropertyData } from "./meta.properties.js";
4
+ export type MetaHeadDecoratorMap<DEF = any> = Record<MetaHeadDecorator, DEF>;
5
+ export type WithMainDecoratorMap<T, R extends MetaHeadDecoratorMap<T>> = R;
6
+ export declare enum MetaHeadDecorator {
7
+ MetaInterface = "MetaInterface",
8
+ MetaHeadInterface = "MetaHeadInterface"
9
+ }
10
+ export declare const metaMainOptionsMap: MetaHeadOptionsMap;
11
+ export type MetaHeadOptionsMap = WithMainDecoratorMap<MetaHeadType, {
12
+ [MetaHeadDecorator.MetaInterface]: MetaHeadType.interface;
13
+ [MetaHeadDecorator.MetaHeadInterface]: MetaHeadType.mainInterface;
14
+ }>;
15
+ export type MetaHeadOptionsBase = WithMainDecoratorMap<MetaHeadBaseOptions, {
16
+ [MetaHeadDecorator.MetaInterface]: MetaInterfaceOptions;
17
+ [MetaHeadDecorator.MetaHeadInterface]: MetaHeadInterfaceOptions;
18
+ }>;
19
+ export type MetaHeadOptions = Partial<WithMainDecoratorMap<WithoutBase<MetaHeadBaseOptions>, {
20
+ [MetaHeadDecorator.MetaInterface]: WithoutBase<MetaHeadOptionsBase[MetaHeadDecorator.MetaInterface]>;
21
+ [MetaHeadDecorator.MetaHeadInterface]: WithoutBase<MetaHeadOptionsBase[MetaHeadDecorator.MetaHeadInterface]>;
22
+ }>>;
23
+ export type MetaRoutes = Record<string, MetaRouteParams>;
24
+ export interface MetaHeadData {
25
+ templateName: string;
26
+ title: string;
27
+ inputFilePath: string;
28
+ repoInputFilePath: string;
29
+ properties: MetaPropertyData[];
30
+ routes: MetaRoutes;
31
+ additionalImports?: MetaImport[];
32
+ }
33
+ export declare const mapAnnotationsHeader: (data: MetaHeadData) => import("../types/types.annotation.js").AnnotationsHeader;
34
+ export declare const mapAnnotationsRoutes: (routes: MetaRoutes) => import("../types/types.annotation.js").AnnotationsRoute[];
35
+ export declare const mapAnnotationsProperty: (prop: MetaPropertyData) => import("../types/types.annotation.js").AnnotationsProperty;
@@ -0,0 +1,38 @@
1
+ import { stripAnnotationsHeader, stripAnnotationsRoute, stripAnnotationsProperty, } from "../types/types.annotation.js";
2
+ import { MetaHeadType } from "./meta.enum.js";
3
+ import { MetaPropertyDecorator } from "./meta.properties.js";
4
+ export var MetaHeadDecorator;
5
+ (function (MetaHeadDecorator) {
6
+ MetaHeadDecorator["MetaInterface"] = "MetaInterface";
7
+ MetaHeadDecorator["MetaHeadInterface"] = "MetaHeadInterface";
8
+ })(MetaHeadDecorator || (MetaHeadDecorator = {}));
9
+ export const metaMainOptionsMap = {
10
+ [MetaHeadDecorator.MetaInterface]: MetaHeadType.interface,
11
+ [MetaHeadDecorator.MetaHeadInterface]: MetaHeadType.mainInterface,
12
+ };
13
+ export const mapAnnotationsHeader = (data) => stripAnnotationsHeader({
14
+ ...data,
15
+ routes: mapAnnotationsRoutes(data.routes),
16
+ properties: data.properties.map(mapAnnotationsProperty),
17
+ });
18
+ export const mapAnnotationsRoutes = (routes) => Object.entries(routes).map(([name, params]) => stripAnnotationsRoute({
19
+ ...params,
20
+ name,
21
+ }));
22
+ export const mapAnnotationsProperty = (prop) => {
23
+ const decorators = Object.values(MetaPropertyDecorator);
24
+ let propertyRef = null;
25
+ // find ref/decorator
26
+ for (const decorator of decorators) {
27
+ if (decorator in prop && !!prop[decorator]) {
28
+ propertyRef = decorator;
29
+ break;
30
+ }
31
+ }
32
+ if (!propertyRef)
33
+ throw new Error(`No property ref / decorator found in ${prop.propertyKey}`);
34
+ return stripAnnotationsProperty({
35
+ ...prop,
36
+ propertyRef,
37
+ });
38
+ };
@@ -1,8 +1,7 @@
1
1
  import { MetaPropertyDataWoType } from "../meta/meta.properties.js";
2
- export interface AnnotationsRoute {
2
+ import { MetaRouteParams } from "./types.meta.js";
3
+ export interface AnnotationsRoute extends MetaRouteParams {
3
4
  name: string;
4
- requestType: string;
5
- responseType: string;
6
5
  }
7
6
  export declare const stripAnnotationsRoute: (route: AnnotationsRoute) => AnnotationsRoute;
8
7
  export interface AnnotationsProperty extends MetaPropertyDataWoType {
@@ -35,3 +35,27 @@ export const stripAnnotationsHeader = (header, deepStrip = false) => {
35
35
  }
36
36
  return stripObject(header, annotationsHeaderKeys);
37
37
  };
38
+ // AnnotationsFile ----------------------------------------------------
39
+ // export interface AnnotationsFile {
40
+ // templateFilePath: string;
41
+ // templateRepoFilePath: string;
42
+ // headers: AnnotationsHeader[];
43
+ // }
44
+ // const annotationsFile: Required<AnnotationsFile> = {
45
+ // templateFilePath: undefined!,
46
+ // templateRepoFilePath: undefined!,
47
+ // headers: undefined!,
48
+ // };
49
+ // const annotationsFileKeys = Object.keys(
50
+ // annotationsFile,
51
+ // ) as (keyof AnnotationsFile)[];
52
+ // export const stripAnnotationsFile = (
53
+ // file: AnnotationsFile,
54
+ // deepStrip: boolean = false,
55
+ // ): AnnotationsFile => {
56
+ // if (deepStrip)
57
+ // file.headers = file.headers.map((header) =>
58
+ // stripAnnotationsHeader(header, deepStrip),
59
+ // );
60
+ // return stripObject<AnnotationsFile>(file, annotationsFileKeys);
61
+ // };
@@ -12,25 +12,26 @@
12
12
  * tradeNames!: string[];
13
13
  * }
14
14
  */
15
- import { MetaPropertyType, MetaNumberFormat, MetaStringFormat, MetaMainType, MetaTargetType } from "../meta/meta.enum.js";
15
+ import { MetaPropertyType, MetaNumberFormat, MetaStringFormat, MetaHeadType, MetaTargetType } from "../meta/meta.enum.js";
16
+ import { MetaHeadData } from "../meta/meta.main.js";
16
17
  export interface MetaRouteParams {
17
18
  requestType: string;
18
19
  responseType: string;
19
20
  }
20
- export interface MetaMainBaseOptions {
21
- type: MetaMainType;
21
+ export interface MetaHeadBaseOptions {
22
+ type: MetaHeadType;
22
23
  title: string;
23
24
  }
24
- export interface MetaInterfaceOptions extends MetaMainBaseOptions {
25
- type: MetaMainType.interface;
25
+ export interface MetaInterfaceOptions extends MetaHeadBaseOptions {
26
+ type: MetaHeadType.interface;
26
27
  }
27
28
  export interface MetaImport {
28
29
  props: string[];
29
30
  path: string;
30
31
  isType?: boolean;
31
32
  }
32
- export interface MetaMainInterfaceOptions extends MetaMainBaseOptions {
33
- type: MetaMainType.mainInterface;
33
+ export interface MetaHeadInterfaceOptions extends MetaHeadBaseOptions {
34
+ type: MetaHeadType.mainInterface;
34
35
  routes: Record<string, MetaRouteParams> | {
35
36
  crud?: boolean;
36
37
  };
@@ -50,10 +51,10 @@ export interface MetaPropertyBaseOptions {
50
51
  }
51
52
  export declare const withoutBaseIgnoreValues: readonly ["title", "description", "optional"];
52
53
  export type WithoutBaseIgnore = (typeof withoutBaseIgnoreValues)[number];
53
- export type WithoutBase<T extends MetaPropertyBaseOptions | MetaMainBaseOptions> = Omit<T, WithoutBaseIgnore>;
54
+ export type WithoutBase<T extends MetaPropertyBaseOptions | MetaHeadBaseOptions> = Omit<T, WithoutBaseIgnore>;
54
55
  export declare const withoutTypeIgnoreValues: readonly ["type"];
55
56
  export type WithoutTypeIgnore = (typeof withoutTypeIgnoreValues)[number];
56
- export type WithoutType<T extends MetaPropertyBaseOptions | MetaMainBaseOptions> = Omit<T, WithoutTypeIgnore>;
57
+ export type WithoutType<T extends MetaPropertyBaseOptions | MetaHeadBaseOptions> = Omit<T, WithoutTypeIgnore>;
57
58
  export interface MetaNumberOptions extends MetaPropertyBaseOptions {
58
59
  type: MetaPropertyType.number;
59
60
  min?: number;
@@ -117,3 +118,8 @@ export type MetaNamesFromMap<R extends MetaNamesNoTarget> = {
117
118
  [K in keyof R]: R[K];
118
119
  };
119
120
  export declare const metaNameProperties: (keyof MetaNamesNoTarget)[];
121
+ export interface MetaFile {
122
+ templateFilePath: string;
123
+ templateRepoFilePath: string;
124
+ headers: MetaHeadData[];
125
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/gcp-functions-common",
3
- "version": "0.1.80",
3
+ "version": "0.1.82",
4
4
  "description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
5
5
  "type": "module",
6
6
  "author": "MXPicture",