@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.
- package/dist/api/BackendApi.d.ts +1 -1
- package/dist/api/BackendApi.js +2 -2
- package/dist/api/IBackendApi.d.ts +2 -1
- package/dist/api/IBackendApi.js +3 -1
- package/dist/function/BackendFunction.d.ts +1 -22
- package/dist/function/BackendFunction.js +72 -31
- package/dist/function/IBackendFunction.d.ts +5 -3
- package/dist/function/IBackendFunction.js +14 -6
- package/dist/function/index.d.ts +0 -1
- package/dist/function/index.js +0 -1
- package/package.json +1 -1
package/dist/api/BackendApi.d.ts
CHANGED
|
@@ -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
|
}>;
|
package/dist/api/BackendApi.js
CHANGED
|
@@ -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>;
|
package/dist/api/IBackendApi.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
7
|
+
protected readonly routesC: CallbackAble<string[]>;
|
|
9
8
|
protected _api?: API;
|
|
10
|
-
protected
|
|
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
|
-
|
|
5
|
+
routesC;
|
|
7
6
|
_api;
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
_routes;
|
|
8
|
+
constructor(apiC, routesC) {
|
|
10
9
|
this.apiC = apiC;
|
|
11
|
-
this.
|
|
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
|
-
|
|
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 {
|
package/dist/function/index.d.ts
CHANGED
package/dist/function/index.js
CHANGED