@mxpicture/gcp-functions-backend 0.1.44 → 0.1.45

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.
@@ -5,7 +5,7 @@ import type { Validation } from "../validation/Validation.js";
5
5
  import type { ZodRawShape } from "zod";
6
6
  import { IBackendApi } from "./IBackendApi.js";
7
7
  export declare class BackendApi<DTO extends DocumentData, STORE extends Store<DTO> = Store<DTO>, VAL extends Validation<DTO> = Validation<DTO>> extends IBackendApi<DTO, STORE, VAL> implements ApiFromRoutes<CrudRoutes<DTO>> {
8
- constructor(storeC: CallbackAble<STORE>, validationC: CallbackAble<VAL>, shapeC: CallbackAble<ZodRawShape>);
8
+ constructor(name: string, storeC: CallbackAble<STORE>, validationC: CallbackAble<VAL>, shapeC: CallbackAble<ZodRawShape>);
9
9
  delete(request: DocumentKey): Promise<{
10
10
  deleted: true;
11
11
  }>;
@@ -1,8 +1,8 @@
1
1
  import { Meta } from "@mxpicture/zod-meta";
2
2
  import { IBackendApi } from "./IBackendApi.js";
3
3
  export class BackendApi extends IBackendApi {
4
- constructor(storeC, validationC, shapeC) {
5
- super(storeC, validationC, shapeC);
4
+ constructor(name, storeC, validationC, shapeC) {
5
+ super(name, storeC, validationC, shapeC);
6
6
  }
7
7
  async delete(request) {
8
8
  await (await this.store()).delete(request.id);
@@ -3,13 +3,14 @@ import { Store } from "../store/Store.js";
3
3
  import type { Validation } from "../validation/Validation.js";
4
4
  import type { ZodRawShape } from "zod";
5
5
  export declare class IBackendApi<DTO extends DocumentData, STORE extends Store<DTO> = Store<DTO>, VAL extends Validation<DTO> = Validation<DTO>> {
6
+ readonly name: string;
6
7
  protected readonly storeC: CallbackAble<STORE>;
7
8
  protected readonly validationC: CallbackAble<VAL>;
8
9
  protected readonly shapeC: CallbackAble<ZodRawShape>;
9
10
  protected _store?: STORE;
10
11
  protected _validation?: VAL;
11
12
  protected _shape?: ZodRawShape;
12
- protected constructor(storeC: CallbackAble<STORE>, validationC: CallbackAble<VAL>, shapeC: CallbackAble<ZodRawShape>);
13
+ protected constructor(name: string, storeC: CallbackAble<STORE>, validationC: CallbackAble<VAL>, shapeC: CallbackAble<ZodRawShape>);
13
14
  protected store(): Promise<STORE>;
14
15
  protected validation(): Promise<VAL>;
15
16
  protected shape(): Promise<ZodRawShape>;
@@ -1,12 +1,14 @@
1
1
  import { callableUnwrap } from "@mxpicture/gcp-functions-common/helper";
2
2
  export class IBackendApi {
3
+ name;
3
4
  storeC;
4
5
  validationC;
5
6
  shapeC;
6
7
  _store;
7
8
  _validation;
8
9
  _shape;
9
- constructor(storeC, validationC, shapeC) {
10
+ constructor(name, storeC, validationC, shapeC) {
11
+ this.name = name;
10
12
  this.storeC = storeC;
11
13
  this.validationC = validationC;
12
14
  this.shapeC = shapeC;
@@ -1,22 +1 @@
1
- import type { DocumentData, CallbackAble, CrudRoutes, ApiFilter, DocumentKey, WithKey, WithoutKey } from "@mxpicture/gcp-functions-common/types";
2
- import { BackendApi } from "../api/BackendApi.js";
3
- import { FunctionFromRoutes, FunctionResponse } from "../../../common/src/types/types.function.js";
4
- import { MetaItem } from "@mxpicture/zod-meta";
5
- import { IBackendFunction } from "./IBackendFunction.js";
6
- export declare class BackendFunction<DTO extends DocumentData, API extends BackendApi<DTO>> extends IBackendFunction<DTO, API> implements FunctionFromRoutes<CrudRoutes<DTO>> {
7
- constructor(name: string, apiC: CallbackAble<API>, additionalRoutes?: string[]);
8
- create(request: WithoutKey<DTO>): Promise<FunctionResponse<WithKey<DTO>>>;
9
- update(request: WithKey<Partial<DTO>>): Promise<FunctionResponse<WithKey<DTO>>>;
10
- delete(request: DocumentKey): Promise<FunctionResponse<{
11
- deleted: true;
12
- }>>;
13
- get(request: DocumentKey): Promise<FunctionResponse<WithKey<DTO>>>;
14
- query(request: ApiFilter | null | undefined): Promise<FunctionResponse<WithKey<DTO>[]>>;
15
- count(request: ApiFilter | null | undefined): Promise<FunctionResponse<{
16
- count: number;
17
- }>>;
18
- exists(request: DocumentKey): Promise<FunctionResponse<{
19
- exists: boolean;
20
- }>>;
21
- meta(): Promise<FunctionResponse<MetaItem[]>>;
22
- }
1
+ export {};
@@ -1,31 +1,72 @@
1
- import { IBackendFunction } from "./IBackendFunction.js";
2
- import { CRUD_ROUTES } from "@mxpicture/gcp-functions-common/config";
3
- export class BackendFunction extends IBackendFunction {
4
- constructor(name, apiC, additionalRoutes) {
5
- super(name, apiC, [...CRUD_ROUTES, ...(additionalRoutes ?? [])]);
6
- }
7
- async create(request) {
8
- return this.ingress({ data: request, route: "create" });
9
- }
10
- async update(request) {
11
- return this.ingress({ data: request, route: "update" });
12
- }
13
- async delete(request) {
14
- return this.ingress({ data: request, route: "delete" });
15
- }
16
- async get(request) {
17
- return this.ingress({ data: request, route: "get" });
18
- }
19
- async query(request) {
20
- return this.ingress({ data: request, route: "query" });
21
- }
22
- async count(request) {
23
- return this.ingress({ data: request, route: "count" });
24
- }
25
- async exists(request) {
26
- return this.ingress({ data: request, route: "exists" });
27
- }
28
- async meta() {
29
- return this.ingress({ route: "meta", data: null });
30
- }
31
- }
1
+ // todo not needed anymore?
2
+ // import type {
3
+ // DocumentData,
4
+ // CallbackAble,
5
+ // CrudRoutes,
6
+ // ApiFilter,
7
+ // DocumentKey,
8
+ // WithKey,
9
+ // WithoutKey,
10
+ // } from "@mxpicture/gcp-functions-common/types";
11
+ // import { BackendApi } from "../api/BackendApi.js";
12
+ // import {
13
+ // FunctionFromRoutes,
14
+ // FunctionResponse,
15
+ // } from "../../../common/src/types/types.function.js";
16
+ // import { MetaItem } from "@mxpicture/zod-meta";
17
+ // import { IBackendFunction } from "./IBackendFunction.js";
18
+ // import { CRUD_ROUTES } from "@mxpicture/gcp-functions-common/config";
19
+ export {};
20
+ // export class BackendFunction<
21
+ // DTO extends DocumentData,
22
+ // API extends BackendApi<DTO>,
23
+ // >
24
+ // extends IBackendFunction<DTO, API>
25
+ // implements FunctionFromRoutes<CrudRoutes<DTO>>
26
+ // {
27
+ // public constructor(
28
+ // name: string,
29
+ // apiC: CallbackAble<API>,
30
+ // additionalRoutes?: string[],
31
+ // ) {
32
+ // super(name, apiC, [...CRUD_ROUTES, ...(additionalRoutes ?? [])]);
33
+ // }
34
+ // public async create(
35
+ // request: WithoutKey<DTO>,
36
+ // ): Promise<FunctionResponse<WithKey<DTO>>> {
37
+ // return this.ingress({ data: request, route: "create" });
38
+ // }
39
+ // public async update(
40
+ // request: WithKey<Partial<DTO>>,
41
+ // ): Promise<FunctionResponse<WithKey<DTO>>> {
42
+ // return this.ingress({ data: request, route: "update" });
43
+ // }
44
+ // public async delete(
45
+ // request: DocumentKey,
46
+ // ): Promise<FunctionResponse<{ deleted: true }>> {
47
+ // return this.ingress({ data: request, route: "delete" });
48
+ // }
49
+ // public async get(
50
+ // request: DocumentKey,
51
+ // ): Promise<FunctionResponse<WithKey<DTO>>> {
52
+ // return this.ingress({ data: request, route: "get" });
53
+ // }
54
+ // public async query(
55
+ // request: ApiFilter | null | undefined,
56
+ // ): Promise<FunctionResponse<WithKey<DTO>[]>> {
57
+ // return this.ingress({ data: request, route: "query" });
58
+ // }
59
+ // public async count(
60
+ // request: ApiFilter | null | undefined,
61
+ // ): Promise<FunctionResponse<{ count: number }>> {
62
+ // return this.ingress({ data: request, route: "count" });
63
+ // }
64
+ // public async exists(
65
+ // request: DocumentKey,
66
+ // ): Promise<FunctionResponse<{ exists: boolean }>> {
67
+ // return this.ingress({ data: request, route: "exists" });
68
+ // }
69
+ // public async meta(): Promise<FunctionResponse<MetaItem[]>> {
70
+ // return this.ingress({ route: "meta", data: null });
71
+ // }
72
+ // }
@@ -3,12 +3,14 @@ import { BackendApi } from "../api/BackendApi.js";
3
3
  import { CallableFunction } from "firebase-functions/v2/https";
4
4
  import { FunctionRequest, FunctionResponse } from "../../../common/src/types/types.function.js";
5
5
  export declare class IBackendFunction<DTO extends DocumentData, API extends BackendApi<DTO>> {
6
- readonly name: string;
7
6
  protected apiC: CallbackAble<API>;
8
- protected readonly routes: string[];
7
+ protected readonly routesC: CallbackAble<string[]>;
9
8
  protected _api?: API;
10
- protected constructor(name: string, apiC: CallbackAble<API>, routes: string[]);
9
+ protected _routes?: string[];
10
+ protected constructor(apiC: CallbackAble<API>, routesC: CallbackAble<string[]>);
11
+ name(): Promise<string>;
11
12
  protected api(): Promise<API>;
13
+ protected routes(): Promise<string[]>;
12
14
  ingress<REQ, RES extends DocumentData>(request: FunctionRequest<REQ>): Promise<FunctionResponse<RES>>;
13
15
  buildFunction(): CallableFunction<FunctionRequest<any>, Promise<FunctionResponse<any>>>;
14
16
  }
@@ -1,22 +1,30 @@
1
1
  import { onCall, HttpsError, } from "firebase-functions/v2/https";
2
2
  import { callableUnwrap } from "@mxpicture/gcp-functions-common/helper";
3
3
  export class IBackendFunction {
4
- name;
5
4
  apiC;
6
- routes;
5
+ routesC;
7
6
  _api;
8
- constructor(name, apiC, routes) {
9
- this.name = name;
7
+ _routes;
8
+ constructor(apiC, routesC) {
10
9
  this.apiC = apiC;
11
- this.routes = routes;
10
+ this.routesC = routesC;
11
+ }
12
+ async name() {
13
+ return (await this.api()).name;
12
14
  }
13
15
  async api() {
14
16
  if (!this._api)
15
17
  this._api = await callableUnwrap(this.apiC);
16
18
  return this._api;
17
19
  }
20
+ async routes() {
21
+ if (!this._routes)
22
+ this._routes = await callableUnwrap(this.routesC);
23
+ return this._routes;
24
+ }
18
25
  async ingress(request) {
19
- if (!this.routes.find((m) => m === request.route))
26
+ const routes = await this.routes();
27
+ if (!routes.find((m) => m === request.route))
20
28
  throw new HttpsError("invalid-argument", `Route ${request.route} not available`);
21
29
  try {
22
30
  return {
@@ -1,2 +1 @@
1
- export { BackendFunction } from "./BackendFunction.js";
2
1
  export { IBackendFunction } from "./IBackendFunction.js";
@@ -1,2 +1 @@
1
- export { BackendFunction } from "./BackendFunction.js";
2
1
  export { IBackendFunction } from "./IBackendFunction.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/gcp-functions-backend",
3
- "version": "0.1.44",
3
+ "version": "0.1.45",
4
4
  "description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
5
5
  "type": "module",
6
6
  "author": "MXPicture",