@mxpicture/gcp-functions-frontend 0.1.32 → 0.1.42
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/FrontendApi.d.ts +14 -18
- package/dist/api/FrontendApi.js +26 -51
- package/dist/api/IFrontendApi.d.ts +8 -0
- package/dist/api/IFrontendApi.js +13 -0
- package/dist/api/index.d.ts +2 -1
- package/dist/api/index.js +2 -1
- package/dist/config/firebase.config.d.ts +4 -4
- package/dist/config/firebase.config.js +2 -2
- package/dist/function/FrontendFunction.d.ts +20 -0
- package/dist/function/FrontendFunction.js +31 -0
- package/dist/function/IFrontendFunction.d.ts +10 -0
- package/dist/function/IFrontendFunction.js +21 -0
- package/dist/function/index.d.ts +2 -0
- package/dist/function/index.js +2 -0
- package/package.json +4 -3
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import type { MetaItem } from "@mxpicture/zod-meta";
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
query(): Promise<WithKey<DTO>[]>;
|
|
14
|
-
count(): Promise<{
|
|
2
|
+
import type { DocumentData, WithKey, CallbackAble, ApiFromRoutes, CrudRoutes, WithoutKey, DocumentKey, ApiFilter } from "@mxpicture/gcp-functions-common/types";
|
|
3
|
+
import { IFrontendApi } from "./IFrontendApi.js";
|
|
4
|
+
import { FrontendFunction } from "../function/FrontendFunction.js";
|
|
5
|
+
export declare class FrontendApi<DTO extends DocumentData, FUNC extends FrontendFunction<DTO>> extends IFrontendApi<DTO, FUNC> implements ApiFromRoutes<CrudRoutes<DTO>> {
|
|
6
|
+
constructor(funcC: CallbackAble<FUNC>);
|
|
7
|
+
delete(request: DocumentKey): Promise<{
|
|
8
|
+
deleted: true;
|
|
9
|
+
}>;
|
|
10
|
+
get(request: DocumentKey): Promise<WithKey<DTO>>;
|
|
11
|
+
query(request?: ApiFilter | null): Promise<WithKey<DTO>[]>;
|
|
12
|
+
count(request?: ApiFilter | null): Promise<{
|
|
15
13
|
count: number;
|
|
16
14
|
}>;
|
|
17
|
-
exists(
|
|
15
|
+
exists(request: DocumentKey): Promise<{
|
|
18
16
|
exists: boolean;
|
|
19
17
|
}>;
|
|
20
18
|
meta(): Promise<MetaItem[]>;
|
|
21
|
-
create(
|
|
22
|
-
update(
|
|
23
|
-
id: string;
|
|
24
|
-
}, data: Partial<DTO>): Promise<WithKey<DTO>>;
|
|
19
|
+
create(request: WithoutKey<DTO>): Promise<WithKey<DTO>>;
|
|
20
|
+
update(request: WithKey<Partial<DTO>>): Promise<WithKey<DTO>>;
|
|
25
21
|
}
|
package/dist/api/FrontendApi.js
CHANGED
|
@@ -1,55 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
await (await this.service())({ route: "delete", keys });
|
|
21
|
-
}
|
|
22
|
-
async get(keys) {
|
|
23
|
-
return (await (await this.service())({ route: "get", keys })).data
|
|
24
|
-
.doc;
|
|
25
|
-
}
|
|
26
|
-
// todo add filter
|
|
27
|
-
async query() {
|
|
28
|
-
return (await (await this.service())({ route: "query" })).data
|
|
29
|
-
.doc;
|
|
30
|
-
}
|
|
31
|
-
async count() {
|
|
32
|
-
return (await (await this.service())({ route: "count" })).data
|
|
33
|
-
.doc;
|
|
34
|
-
}
|
|
35
|
-
async exists(keys) {
|
|
36
|
-
return (await (await this.service())({ route: "exists", keys })).data
|
|
37
|
-
.doc;
|
|
1
|
+
import { IFrontendApi } from "./IFrontendApi.js";
|
|
2
|
+
export class FrontendApi extends IFrontendApi {
|
|
3
|
+
constructor(funcC) {
|
|
4
|
+
super(funcC);
|
|
5
|
+
}
|
|
6
|
+
async delete(request) {
|
|
7
|
+
return (await (await this.func()).delete(request)).data;
|
|
8
|
+
}
|
|
9
|
+
async get(request) {
|
|
10
|
+
return (await (await this.func()).get(request)).data;
|
|
11
|
+
}
|
|
12
|
+
async query(request) {
|
|
13
|
+
return (await (await this.func()).query(request)).data;
|
|
14
|
+
}
|
|
15
|
+
async count(request) {
|
|
16
|
+
return (await (await this.func()).count(request)).data;
|
|
17
|
+
}
|
|
18
|
+
async exists(request) {
|
|
19
|
+
return (await (await this.func()).exists(request)).data;
|
|
38
20
|
}
|
|
39
21
|
async meta() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
async update(keys, data) {
|
|
49
|
-
return (await (await this.service())({
|
|
50
|
-
route: "update",
|
|
51
|
-
keys,
|
|
52
|
-
content: data,
|
|
53
|
-
})).data.doc;
|
|
22
|
+
return (await (await this.func()).meta()).data;
|
|
23
|
+
}
|
|
24
|
+
async create(request) {
|
|
25
|
+
return (await (await this.func()).create(request)).data;
|
|
26
|
+
}
|
|
27
|
+
async update(request) {
|
|
28
|
+
return (await (await this.func()).update(request)).data;
|
|
54
29
|
}
|
|
55
30
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DocumentData, CallbackAble } from "@mxpicture/gcp-functions-common/types";
|
|
2
|
+
import { FrontendFunction } from "../function/FrontendFunction.js";
|
|
3
|
+
export declare class IFrontendApi<DTO extends DocumentData, FUNC extends FrontendFunction<DTO>> {
|
|
4
|
+
protected funcC: CallbackAble<FUNC>;
|
|
5
|
+
protected _func?: FUNC;
|
|
6
|
+
protected constructor(funcC: CallbackAble<FUNC>);
|
|
7
|
+
protected func(): Promise<FUNC>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { callableUnwrap } from "@mxpicture/gcp-functions-common/helper";
|
|
2
|
+
export class IFrontendApi {
|
|
3
|
+
funcC;
|
|
4
|
+
_func;
|
|
5
|
+
constructor(funcC) {
|
|
6
|
+
this.funcC = funcC;
|
|
7
|
+
}
|
|
8
|
+
async func() {
|
|
9
|
+
if (!this._func)
|
|
10
|
+
this._func = await callableUnwrap(this.funcC);
|
|
11
|
+
return this._func;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { FrontendApi
|
|
1
|
+
export { FrontendApi } from "./FrontendApi.js";
|
|
2
|
+
export { IFrontendApi } from "./IFrontendApi.js";
|
package/dist/api/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { FrontendApi
|
|
1
|
+
export { FrontendApi } from "./FrontendApi.js";
|
|
2
|
+
export { IFrontendApi } from "./IFrontendApi.js";
|
|
@@ -2,15 +2,15 @@ import { GoogleAuthProvider, type Auth } from "firebase/auth";
|
|
|
2
2
|
import { type FirebaseApp } from "firebase/app";
|
|
3
3
|
import { type Functions } from "firebase/functions";
|
|
4
4
|
import type { FirebaseConfig, FirebaseEmulatorConfig } from "../types/firebase.types.js";
|
|
5
|
-
export declare const initializeFirebase: (config: FirebaseConfig, emu?: FirebaseEmulatorConfig) =>
|
|
5
|
+
export declare const initializeFirebase: (config: FirebaseConfig, emu?: FirebaseEmulatorConfig) => {
|
|
6
6
|
app: FirebaseApp;
|
|
7
7
|
auth: Auth;
|
|
8
8
|
functions: Functions;
|
|
9
9
|
googleProvider: GoogleAuthProvider;
|
|
10
|
-
}
|
|
11
|
-
export declare const configFirebase: () =>
|
|
10
|
+
};
|
|
11
|
+
export declare const configFirebase: () => {
|
|
12
12
|
app: FirebaseApp;
|
|
13
13
|
auth: Auth;
|
|
14
14
|
functions: Functions;
|
|
15
15
|
googleProvider: GoogleAuthProvider;
|
|
16
|
-
}
|
|
16
|
+
};
|
|
@@ -4,7 +4,7 @@ import { connectFunctionsEmulator, getFunctions, } from "firebase/functions";
|
|
|
4
4
|
let _inst = null;
|
|
5
5
|
let _config = null;
|
|
6
6
|
let _emu = null;
|
|
7
|
-
export const initializeFirebase =
|
|
7
|
+
export const initializeFirebase = (config, emu) => {
|
|
8
8
|
if (_config)
|
|
9
9
|
throw new Error("Firebase config already present");
|
|
10
10
|
_config = { ...config };
|
|
@@ -12,7 +12,7 @@ export const initializeFirebase = async (config, emu) => {
|
|
|
12
12
|
_emu = { ...emu };
|
|
13
13
|
return configFirebase();
|
|
14
14
|
};
|
|
15
|
-
export const configFirebase =
|
|
15
|
+
export const configFirebase = () => {
|
|
16
16
|
if (!_inst) {
|
|
17
17
|
if (!_config)
|
|
18
18
|
throw new Error("Firebase config not provided. Use initializeFirebase at first");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DocumentData, CrudRoutes, FunctionFromRoutes, ApiFilter, DocumentKey, FunctionResponse, WithKey, WithoutKey } from "@mxpicture/gcp-functions-common/types";
|
|
2
|
+
import { IFrontendFunction } from "./IFrontendFunction.js";
|
|
3
|
+
import { MetaItem } from "@mxpicture/zod-meta";
|
|
4
|
+
export declare class FrontendFunction<DTO extends DocumentData> extends IFrontendFunction implements FunctionFromRoutes<CrudRoutes<DTO>> {
|
|
5
|
+
constructor(name: string);
|
|
6
|
+
create(request: WithoutKey<DTO>): Promise<FunctionResponse<WithKey<DTO>>>;
|
|
7
|
+
update(request: WithKey<Partial<DTO>>): Promise<FunctionResponse<WithKey<DTO>>>;
|
|
8
|
+
delete(request: DocumentKey): Promise<FunctionResponse<{
|
|
9
|
+
deleted: true;
|
|
10
|
+
}>>;
|
|
11
|
+
get(request: DocumentKey): Promise<FunctionResponse<WithKey<DTO>>>;
|
|
12
|
+
query(request: ApiFilter | null | undefined): Promise<FunctionResponse<WithKey<DTO>[]>>;
|
|
13
|
+
count(request: ApiFilter | null | undefined): Promise<FunctionResponse<{
|
|
14
|
+
count: number;
|
|
15
|
+
}>>;
|
|
16
|
+
exists(request: DocumentKey): Promise<FunctionResponse<{
|
|
17
|
+
exists: boolean;
|
|
18
|
+
}>>;
|
|
19
|
+
meta(): Promise<FunctionResponse<MetaItem[]>>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IFrontendFunction } from "./IFrontendFunction.js";
|
|
2
|
+
import { CRUD_ROUTES } from "@mxpicture/gcp-functions-common/config";
|
|
3
|
+
export class FrontendFunction extends IFrontendFunction {
|
|
4
|
+
constructor(name) {
|
|
5
|
+
super(name, CRUD_ROUTES);
|
|
6
|
+
}
|
|
7
|
+
async create(request) {
|
|
8
|
+
return this.outgress({ data: request, route: "create" });
|
|
9
|
+
}
|
|
10
|
+
async update(request) {
|
|
11
|
+
return this.outgress({ data: request, route: "update" });
|
|
12
|
+
}
|
|
13
|
+
async delete(request) {
|
|
14
|
+
return this.outgress({ data: request, route: "delete" });
|
|
15
|
+
}
|
|
16
|
+
async get(request) {
|
|
17
|
+
return this.outgress({ data: request, route: "get" });
|
|
18
|
+
}
|
|
19
|
+
async query(request) {
|
|
20
|
+
return this.outgress({ data: request, route: "query" });
|
|
21
|
+
}
|
|
22
|
+
async count(request) {
|
|
23
|
+
return this.outgress({ data: request, route: "count" });
|
|
24
|
+
}
|
|
25
|
+
async exists(request) {
|
|
26
|
+
return this.outgress({ data: request, route: "exists" });
|
|
27
|
+
}
|
|
28
|
+
async meta() {
|
|
29
|
+
return this.outgress({ data: null, route: "meta" });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DocumentData, FunctionRequest, FunctionResponse } from "@mxpicture/gcp-functions-common/types";
|
|
2
|
+
import { HttpsCallable } from "firebase/functions";
|
|
3
|
+
export declare class IFrontendFunction {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
protected readonly routes: string[];
|
|
6
|
+
protected _func?: HttpsCallable<FunctionRequest<any>, Promise<FunctionResponse<any>>, unknown>;
|
|
7
|
+
protected constructor(name: string, routes: string[]);
|
|
8
|
+
outgress<REQ, RES extends DocumentData>(request: FunctionRequest<REQ>): Promise<FunctionResponse<RES>>;
|
|
9
|
+
protected func(): HttpsCallable<FunctionRequest<any>, Promise<FunctionResponse<any>>, unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { httpsCallable } from "firebase/functions";
|
|
2
|
+
import { configFirebase } from "../config/firebase.config.js";
|
|
3
|
+
export class IFrontendFunction {
|
|
4
|
+
name;
|
|
5
|
+
routes;
|
|
6
|
+
_func;
|
|
7
|
+
constructor(name, routes) {
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.routes = routes;
|
|
10
|
+
}
|
|
11
|
+
async outgress(request) {
|
|
12
|
+
if (!this.routes.find((m) => m === request.route))
|
|
13
|
+
throw new Error(`Route ${request.route} not available`);
|
|
14
|
+
return (await this.func()(request)).data;
|
|
15
|
+
}
|
|
16
|
+
func() {
|
|
17
|
+
if (!this._func)
|
|
18
|
+
this._func = httpsCallable(configFirebase().functions, this.name);
|
|
19
|
+
return this._func;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/gcp-functions-frontend",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.42",
|
|
4
4
|
"description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
"./types": "./dist/types/index.js",
|
|
16
16
|
"./api": "./dist/api/index.js",
|
|
17
17
|
"./helper": "./dist/helper/index.js",
|
|
18
|
+
"./function": "./dist/function/index.js",
|
|
18
19
|
"./package.json": "./package.json"
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
22
|
"dist"
|
|
22
23
|
],
|
|
23
24
|
"engines": {
|
|
24
|
-
"node": "
|
|
25
|
+
"node": ">=22"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"clean": "rm -rf dist .tsbuildinfo tsconfig.tsbuildinfo node_modules",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@mxpicture/gcp-functions-common": "*",
|
|
38
|
-
"@mxpicture/zod-meta": "^0.1.
|
|
39
|
+
"@mxpicture/zod-meta": "^0.1.12",
|
|
39
40
|
"firebase": "^12.8.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|