@mxpicture/gcp-functions-frontend 0.1.49 → 0.1.51

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,8 +1,8 @@
1
1
  import { IFrontendFunction } from "../function/IFrontendFunction.js";
2
- export declare class IFrontendApi<FUNC extends IFrontendFunction> {
2
+ export declare abstract class IFrontendApi<FUNC extends IFrontendFunction> {
3
3
  readonly name: string;
4
4
  protected _func?: FUNC;
5
- protected constructor(name: string);
5
+ constructor(name: string);
6
6
  useFunc(func: FUNC): void;
7
7
  protected func(): FUNC;
8
8
  }
@@ -1,10 +1,13 @@
1
1
  import type { DocumentData, FunctionRequest, FunctionResponse } from "@mxpicture/gcp-functions-common/types";
2
2
  import { HttpsCallable } from "firebase/functions";
3
- export declare class IFrontendFunction {
3
+ export declare abstract class IFrontendFunction {
4
4
  readonly name: string;
5
- protected readonly routes: string[];
5
+ protected _routes?: string[];
6
6
  protected _func?: HttpsCallable<FunctionRequest<any>, Promise<FunctionResponse<any>>, unknown>;
7
- protected constructor(name: string, routes: string[]);
7
+ constructor(name: string);
8
+ useRoutes(routes: string[]): void;
9
+ protected routes(): string[];
10
+ protected hasRoute(name: string): boolean;
8
11
  outgress<REQ, RES extends DocumentData>(request: FunctionRequest<REQ>): Promise<FunctionResponse<RES>>;
9
12
  protected func(): HttpsCallable<FunctionRequest<any>, Promise<FunctionResponse<any>>, unknown>;
10
13
  }
@@ -2,14 +2,24 @@ import { httpsCallable } from "firebase/functions";
2
2
  import { configFirebase } from "../config/firebase.config.js";
3
3
  export class IFrontendFunction {
4
4
  name;
5
- routes;
5
+ _routes;
6
6
  _func;
7
- constructor(name, routes) {
7
+ constructor(name) {
8
8
  this.name = name;
9
- this.routes = routes;
9
+ }
10
+ useRoutes(routes) {
11
+ this._routes = routes;
12
+ }
13
+ routes() {
14
+ if (!this._routes)
15
+ throw new Error(`${this.name}: routes not provided. Use "useRoutes" method`);
16
+ return this._routes;
17
+ }
18
+ hasRoute(name) {
19
+ return !!this.routes().find((m) => m === name);
10
20
  }
11
21
  async outgress(request) {
12
- if (!this.routes.find((m) => m === request.route))
22
+ if (!this.hasRoute(request.route))
13
23
  throw new Error(`Route ${request.route} not available`);
14
24
  return (await this.func()(request)).data;
15
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/gcp-functions-frontend",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
5
5
  "type": "module",
6
6
  "author": "MXPicture",