@mxpicture/gcp-functions-backend 0.1.16 → 0.1.17

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.
Files changed (120) hide show
  1. package/dist/{esm/base → api}/BackendApi.d.ts +4 -5
  2. package/dist/{esm/base → api}/BackendApi.js +7 -8
  3. package/dist/api/index.d.ts +1 -0
  4. package/dist/api/index.js +1 -0
  5. package/dist/{cjs/common → firebase}/firebase.backend.d.ts +0 -1
  6. package/dist/firebase/firebase.backend.js +4 -0
  7. package/dist/firebase/index.d.ts +1 -0
  8. package/dist/firebase/index.js +1 -0
  9. package/dist/{types/base → function}/BackendFunction.d.ts +1 -2
  10. package/dist/function/BackendFunction.js +22 -0
  11. package/dist/{cjs → function}/FunctionCollection.d.ts +3 -4
  12. package/dist/function/FunctionCollection.js +12 -0
  13. package/dist/function/index.d.ts +2 -0
  14. package/dist/function/index.js +2 -0
  15. package/dist/{types/base → http}/BackendHttp.d.ts +6 -7
  16. package/dist/http/BackendHttp.js +103 -0
  17. package/dist/http/index.d.ts +1 -0
  18. package/dist/http/index.js +1 -0
  19. package/dist/{cjs/loader → loader}/zod.loader.d.ts +0 -1
  20. package/dist/loader/zod.loader.js +6 -0
  21. package/dist/{cjs/store → store}/Store.d.ts +1 -2
  22. package/dist/{esm/store → store}/Store.js +9 -42
  23. package/dist/store/index.d.ts +1 -0
  24. package/dist/store/index.js +1 -0
  25. package/dist/types/index.d.ts +1 -4
  26. package/dist/types/index.js +1 -0
  27. package/dist/types/types.validation.d.ts +1 -0
  28. package/dist/types/types.validation.js +1 -0
  29. package/dist/{cjs/validation → validation}/Validation.d.ts +3 -4
  30. package/dist/{cjs/validation → validation}/Validation.js +12 -13
  31. package/dist/validation/index.d.ts +1 -0
  32. package/dist/validation/index.js +1 -0
  33. package/package.json +12 -17
  34. package/dist/cjs/FunctionCollection.d.ts.map +0 -1
  35. package/dist/cjs/FunctionCollection.js +0 -17
  36. package/dist/cjs/base/BackendApi.d.ts +0 -27
  37. package/dist/cjs/base/BackendApi.d.ts.map +0 -1
  38. package/dist/cjs/base/BackendApi.js +0 -40
  39. package/dist/cjs/base/BackendFunction.d.ts +0 -10
  40. package/dist/cjs/base/BackendFunction.d.ts.map +0 -1
  41. package/dist/cjs/base/BackendFunction.js +0 -23
  42. package/dist/cjs/base/BackendHttp.d.ts +0 -19
  43. package/dist/cjs/base/BackendHttp.d.ts.map +0 -1
  44. package/dist/cjs/base/BackendHttp.js +0 -106
  45. package/dist/cjs/common/firebase.backend.d.ts.map +0 -1
  46. package/dist/cjs/common/firebase.backend.js +0 -7
  47. package/dist/cjs/demo/User.d.ts +0 -25
  48. package/dist/cjs/demo/User.d.ts.map +0 -1
  49. package/dist/cjs/demo/User.js +0 -33
  50. package/dist/cjs/index.d.ts +0 -4
  51. package/dist/cjs/index.d.ts.map +0 -1
  52. package/dist/cjs/index.js +0 -42
  53. package/dist/cjs/lib.d.ts +0 -10
  54. package/dist/cjs/lib.d.ts.map +0 -1
  55. package/dist/cjs/lib.js +0 -23
  56. package/dist/cjs/loader/zod.loader.d.ts.map +0 -1
  57. package/dist/cjs/loader/zod.loader.js +0 -43
  58. package/dist/cjs/package.d.ts +0 -2
  59. package/dist/cjs/package.d.ts.map +0 -1
  60. package/dist/cjs/package.js +0 -20
  61. package/dist/cjs/store/Store.d.ts.map +0 -1
  62. package/dist/cjs/store/Store.js +0 -128
  63. package/dist/cjs/validation/Validation.d.ts.map +0 -1
  64. package/dist/esm/FunctionCollection.d.ts +0 -13
  65. package/dist/esm/FunctionCollection.d.ts.map +0 -1
  66. package/dist/esm/FunctionCollection.js +0 -17
  67. package/dist/esm/base/BackendApi.d.ts.map +0 -1
  68. package/dist/esm/base/BackendFunction.d.ts +0 -10
  69. package/dist/esm/base/BackendFunction.d.ts.map +0 -1
  70. package/dist/esm/base/BackendFunction.js +0 -23
  71. package/dist/esm/base/BackendHttp.d.ts +0 -19
  72. package/dist/esm/base/BackendHttp.d.ts.map +0 -1
  73. package/dist/esm/base/BackendHttp.js +0 -106
  74. package/dist/esm/common/firebase.backend.d.ts +0 -3
  75. package/dist/esm/common/firebase.backend.d.ts.map +0 -1
  76. package/dist/esm/common/firebase.backend.js +0 -7
  77. package/dist/esm/demo/User.d.ts +0 -25
  78. package/dist/esm/demo/User.d.ts.map +0 -1
  79. package/dist/esm/demo/User.js +0 -33
  80. package/dist/esm/index.d.ts +0 -4
  81. package/dist/esm/index.d.ts.map +0 -1
  82. package/dist/esm/index.js +0 -42
  83. package/dist/esm/lib.d.ts +0 -10
  84. package/dist/esm/lib.d.ts.map +0 -1
  85. package/dist/esm/lib.js +0 -23
  86. package/dist/esm/loader/zod.loader.d.ts +0 -2
  87. package/dist/esm/loader/zod.loader.d.ts.map +0 -1
  88. package/dist/esm/loader/zod.loader.js +0 -10
  89. package/dist/esm/package.d.ts +0 -2
  90. package/dist/esm/package.d.ts.map +0 -1
  91. package/dist/esm/package.js +0 -20
  92. package/dist/esm/store/Store.d.ts +0 -24
  93. package/dist/esm/store/Store.d.ts.map +0 -1
  94. package/dist/esm/validation/Validation.d.ts +0 -16
  95. package/dist/esm/validation/Validation.d.ts.map +0 -1
  96. package/dist/esm/validation/Validation.js +0 -43
  97. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  98. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  99. package/dist/tsconfig.types.tsbuildinfo +0 -1
  100. package/dist/types/FunctionCollection.d.ts +0 -13
  101. package/dist/types/FunctionCollection.d.ts.map +0 -1
  102. package/dist/types/base/BackendApi.d.ts +0 -27
  103. package/dist/types/base/BackendApi.d.ts.map +0 -1
  104. package/dist/types/base/BackendFunction.d.ts.map +0 -1
  105. package/dist/types/base/BackendHttp.d.ts.map +0 -1
  106. package/dist/types/common/firebase.backend.d.ts +0 -3
  107. package/dist/types/common/firebase.backend.d.ts.map +0 -1
  108. package/dist/types/demo/User.d.ts +0 -25
  109. package/dist/types/demo/User.d.ts.map +0 -1
  110. package/dist/types/index.d.ts.map +0 -1
  111. package/dist/types/lib.d.ts +0 -10
  112. package/dist/types/lib.d.ts.map +0 -1
  113. package/dist/types/loader/zod.loader.d.ts +0 -2
  114. package/dist/types/loader/zod.loader.d.ts.map +0 -1
  115. package/dist/types/package.d.ts +0 -2
  116. package/dist/types/package.d.ts.map +0 -1
  117. package/dist/types/store/Store.d.ts +0 -24
  118. package/dist/types/store/Store.d.ts.map +0 -1
  119. package/dist/types/validation/Validation.d.ts +0 -16
  120. package/dist/types/validation/Validation.d.ts.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import type { MetaItem } from "@mxpicture/zod-meta";
2
- import type { ApiKey, ApiFilter, DocumentData, WithKey } from "@mxpicture/gcp-functions-common";
3
- import { IApi } from "@mxpicture/gcp-functions-common";
4
- import { Store } from "../store/Store";
5
- import type { Validation } from "../validation/Validation";
2
+ import type { ApiKey, ApiFilter, DocumentData, WithKey } from "@mxpicture/gcp-functions-common/types";
3
+ import { IApi } from "@mxpicture/gcp-functions-common/api";
4
+ import { Store } from "../store/Store.js";
5
+ import type { Validation } from "../validation/Validation.js";
6
6
  import type { ZodRawShape } from "zod";
7
7
  export declare class BackendApi<DTO extends DocumentData, STORE extends Store<DTO> = Store<DTO>, VAL extends Validation<DTO> = Validation<DTO>> extends IApi<DTO> {
8
8
  readonly store: STORE;
@@ -24,4 +24,3 @@ export declare class BackendApi<DTO extends DocumentData, STORE extends Store<DT
24
24
  id: string;
25
25
  }, data: Partial<DTO>): Promise<WithKey<DTO>>;
26
26
  }
27
- //# sourceMappingURL=BackendApi.d.ts.map
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BackendApi = void 0;
4
- const zod_meta_1 = require("@mxpicture/zod-meta");
5
- const gcp_functions_common_1 = require("@mxpicture/gcp-functions-common");
6
- class BackendApi extends gcp_functions_common_1.IApi {
1
+ import { Meta } from "@mxpicture/zod-meta";
2
+ import { IApi } from "@mxpicture/gcp-functions-common/api";
3
+ export class BackendApi extends IApi {
4
+ store;
5
+ validation;
6
+ shape;
7
7
  constructor(store, validation, shape) {
8
8
  super();
9
9
  this.store = store;
@@ -26,7 +26,7 @@ class BackendApi extends gcp_functions_common_1.IApi {
26
26
  return { exists: await this.store.exists(p.id) };
27
27
  }
28
28
  async meta() {
29
- return new zod_meta_1.Meta(this.shape).items();
29
+ return new Meta(this.shape).items();
30
30
  }
31
31
  async create(data) {
32
32
  const result = await this.validation.validate(data);
@@ -37,4 +37,3 @@ class BackendApi extends gcp_functions_common_1.IApi {
37
37
  return this.store.update(p.id, result);
38
38
  }
39
39
  }
40
- exports.BackendApi = BackendApi;
@@ -0,0 +1 @@
1
+ export { BackendApi } from "./BackendApi.js";
@@ -0,0 +1 @@
1
+ export { BackendApi } from "./BackendApi.js";
@@ -1,3 +1,2 @@
1
1
  export declare const app: import("firebase-admin/app").App;
2
2
  export declare const db: FirebaseFirestore.Firestore;
3
- //# sourceMappingURL=firebase.backend.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { getFirestore } from "firebase-admin/firestore";
2
+ import { initializeApp } from "firebase-admin/app";
3
+ export const app = initializeApp();
4
+ export const db = getFirestore();
@@ -0,0 +1 @@
1
+ export { app, db } from "./firebase.backend.js";
@@ -0,0 +1 @@
1
+ export { app, db } from "./firebase.backend.js";
@@ -1,5 +1,5 @@
1
1
  import { HttpsFunction } from "firebase-functions/https";
2
- import type { HttpHandlers, DocumentData, ApiRoutes } from "@mxpicture/gcp-functions-common";
2
+ import type { HttpHandlers, DocumentData, ApiRoutes } from "@mxpicture/gcp-functions-common/types";
3
3
  export declare class BackendFunction<DTO extends DocumentData, HANDLER extends HttpHandlers<ApiRoutes<DTO>> = HttpHandlers<ApiRoutes<DTO>>> {
4
4
  readonly name: string;
5
5
  protected http: HANDLER;
@@ -7,4 +7,3 @@ export declare class BackendFunction<DTO extends DocumentData, HANDLER extends H
7
7
  constructor(name: string, http: HANDLER);
8
8
  createFunction(): HttpsFunction;
9
9
  }
10
- //# sourceMappingURL=BackendFunction.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { HttpsError, onCall } from "firebase-functions/https";
2
+ import { API_ROUTES_METHODS } from "@mxpicture/gcp-functions-common/config";
3
+ export class BackendFunction {
4
+ name;
5
+ http;
6
+ httpMethods;
7
+ constructor(name, http) {
8
+ this.name = name;
9
+ this.http = http;
10
+ this.httpMethods = API_ROUTES_METHODS;
11
+ }
12
+ createFunction() {
13
+ return onCall({ cors: [/firebase\.com$/, /web\.app$/] }, async (req) => {
14
+ if (!this.httpMethods.find((m) => m === req.data.route))
15
+ throw new HttpsError("invalid-argument", `Route ${req.data.route} not available`);
16
+ return {
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ doc: await this.http[req.data.route](req.data),
19
+ };
20
+ });
21
+ }
22
+ }
@@ -1,5 +1,5 @@
1
- import { BackendFunction } from "./base/BackendFunction";
2
- import type { DocumentData } from "@mxpicture/gcp-functions-common";
1
+ import { BackendFunction } from "./BackendFunction.js";
2
+ import type { DocumentData } from "@mxpicture/gcp-functions-common/types";
3
3
  export declare class FunctionCollection {
4
4
  protected funcs: {
5
5
  [key: string]: BackendFunction<any>;
@@ -7,7 +7,6 @@ export declare class FunctionCollection {
7
7
  constructor();
8
8
  add<DTO extends DocumentData>(func: BackendFunction<DTO>, name?: string): FunctionCollection;
9
9
  build(): {
10
- [key: string]: BackendFunction<any, import("@mxpicture/gcp-functions-common").HttpHandlers<import("@mxpicture/gcp-functions-common").ApiRoutes<any>>>;
10
+ [key: string]: BackendFunction<any, import("@mxpicture/gcp-functions-common/types").HttpHandlers<import("@mxpicture/gcp-functions-common/types").ApiRoutes<any>>>;
11
11
  };
12
12
  }
13
- //# sourceMappingURL=FunctionCollection.d.ts.map
@@ -0,0 +1,12 @@
1
+ export class FunctionCollection {
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ funcs = {};
4
+ constructor() { }
5
+ add(func, name) {
6
+ this.funcs[name ?? func.name] = func;
7
+ return this;
8
+ }
9
+ build() {
10
+ return this.funcs;
11
+ }
12
+ }
@@ -0,0 +1,2 @@
1
+ export { BackendFunction } from "./BackendFunction.js";
2
+ export { FunctionCollection } from "./FunctionCollection.js";
@@ -0,0 +1,2 @@
1
+ export { BackendFunction } from "./BackendFunction.js";
2
+ export { FunctionCollection } from "./FunctionCollection.js";
@@ -1,11 +1,11 @@
1
- import type { HttpHandlers, FunctionPayload, ApiFilter, ApiKey, ApiRoutes, DocumentData } from "@mxpicture/gcp-functions-common";
2
- import { BackendApi } from "./BackendApi";
1
+ import type { HttpHandlers, FunctionPayload, ApiFilter, ApiKey, ApiRoutes, DocumentData } from "@mxpicture/gcp-functions-common/types";
2
+ import { BackendApi } from "../api/BackendApi.js";
3
3
  export declare class BackendHttp<DTO extends DocumentData, API extends BackendApi<DTO> = BackendApi<DTO>> implements HttpHandlers<ApiRoutes<DTO>> {
4
4
  protected api: API;
5
5
  constructor(api: API);
6
6
  delete(req: FunctionPayload<never, ApiKey>): Promise<void>;
7
- get(req: FunctionPayload<never, ApiKey>): Promise<import("@mxpicture/gcp-functions-common").WithKey<DTO>>;
8
- query(req: FunctionPayload<ApiFilter>): Promise<import("@mxpicture/gcp-functions-common").WithKey<DTO>[]>;
7
+ get(req: FunctionPayload<never, ApiKey>): Promise<import("@mxpicture/gcp-functions-common/types").WithKey<DTO>>;
8
+ query(req: FunctionPayload<ApiFilter>): Promise<import("@mxpicture/gcp-functions-common/types").WithKey<DTO>[]>;
9
9
  count(req: FunctionPayload<ApiFilter>): Promise<{
10
10
  count: number;
11
11
  }>;
@@ -13,7 +13,6 @@ export declare class BackendHttp<DTO extends DocumentData, API extends BackendAp
13
13
  exists: boolean;
14
14
  }>;
15
15
  meta(): Promise<import("@mxpicture/zod-meta").MetaItem[]>;
16
- create(req: FunctionPayload<DTO>): Promise<import("@mxpicture/gcp-functions-common").WithKey<DTO>>;
17
- update(req: FunctionPayload<Partial<DTO>, ApiKey>): Promise<import("@mxpicture/gcp-functions-common").WithKey<DTO>>;
16
+ create(req: FunctionPayload<DTO>): Promise<import("@mxpicture/gcp-functions-common/types").WithKey<DTO>>;
17
+ update(req: FunctionPayload<Partial<DTO>, ApiKey>): Promise<import("@mxpicture/gcp-functions-common/types").WithKey<DTO>>;
18
18
  }
19
- //# sourceMappingURL=BackendHttp.d.ts.map
@@ -0,0 +1,103 @@
1
+ import { HttpsError } from "firebase-functions/https";
2
+ export class BackendHttp {
3
+ api;
4
+ constructor(api) {
5
+ this.api = api;
6
+ }
7
+ async delete(req) {
8
+ try {
9
+ const id = req.keys?.id;
10
+ if (!id)
11
+ throw new HttpsError("invalid-argument", "Id invalid");
12
+ await this.api.delete({ id });
13
+ }
14
+ catch (error) {
15
+ if (error instanceof HttpsError)
16
+ throw error;
17
+ throw new HttpsError("not-found", `Id ${req.keys?.id} not found`);
18
+ }
19
+ }
20
+ async get(req) {
21
+ try {
22
+ const id = req.keys?.id;
23
+ if (!id)
24
+ throw new HttpsError("invalid-argument", "Id invalid");
25
+ return this.api.get({ id });
26
+ }
27
+ catch (error) {
28
+ if (error instanceof HttpsError)
29
+ throw error;
30
+ throw new HttpsError("not-found", `Id ${req.keys?.id} not found`);
31
+ }
32
+ }
33
+ async query(req) {
34
+ try {
35
+ return this.api.query(req.content);
36
+ }
37
+ catch (error) {
38
+ if (error instanceof HttpsError)
39
+ throw error;
40
+ throw new HttpsError("unknown", "Unknown error");
41
+ }
42
+ }
43
+ async count(req) {
44
+ try {
45
+ return this.api.count(req.content);
46
+ }
47
+ catch (error) {
48
+ if (error instanceof HttpsError)
49
+ throw error;
50
+ throw new HttpsError("unknown", "Unknown error");
51
+ }
52
+ }
53
+ async exists(req) {
54
+ try {
55
+ const id = req.keys?.id;
56
+ if (!id)
57
+ throw new HttpsError("invalid-argument", "Id invalid");
58
+ return await this.api.exists({ id });
59
+ }
60
+ catch (error) {
61
+ if (error instanceof HttpsError)
62
+ throw error;
63
+ throw new HttpsError("unknown", "Unknown error");
64
+ }
65
+ }
66
+ async meta() {
67
+ try {
68
+ return this.api.meta();
69
+ }
70
+ catch (error) {
71
+ if (error instanceof HttpsError)
72
+ throw error;
73
+ throw new HttpsError("unknown", "Unknown error");
74
+ }
75
+ }
76
+ async create(req) {
77
+ try {
78
+ if (!req.content)
79
+ throw new HttpsError("invalid-argument", "Content is invalid");
80
+ return this.api.create(req.content);
81
+ }
82
+ catch (error) {
83
+ if (error instanceof HttpsError)
84
+ throw error;
85
+ throw new HttpsError("unknown", "Unknown error");
86
+ }
87
+ }
88
+ async update(req) {
89
+ try {
90
+ const id = req.keys?.id;
91
+ if (!id)
92
+ throw new HttpsError("invalid-argument", "Id invalid");
93
+ if (!req.content)
94
+ throw new HttpsError("invalid-argument", "Content is invalid");
95
+ return this.api.update({ id }, req.content);
96
+ }
97
+ catch (error) {
98
+ if (error instanceof HttpsError)
99
+ throw error;
100
+ throw new HttpsError("unknown", "Unknown error");
101
+ }
102
+ }
103
+ }
@@ -0,0 +1 @@
1
+ export { BackendHttp } from "./BackendHttp.js";
@@ -0,0 +1 @@
1
+ export { BackendHttp } from "./BackendHttp.js";
@@ -1,2 +1 @@
1
1
  export declare const loadZod: () => Promise<typeof import("zod")>;
2
- //# sourceMappingURL=zod.loader.d.ts.map
@@ -0,0 +1,6 @@
1
+ let zodPromise = null;
2
+ export const loadZod = () => {
3
+ if (!zodPromise)
4
+ zodPromise = import("zod");
5
+ return zodPromise;
6
+ };
@@ -1,5 +1,5 @@
1
1
  import type { CollectionReference, DocumentReference, FirestoreDataConverter, Query, QuerySnapshot } from "firebase-admin/firestore";
2
- import type { DocumentData, WithKey, ApiFilterItems } from "@mxpicture/gcp-functions-common";
2
+ import type { DocumentData, WithKey, ApiFilterItems } from "@mxpicture/gcp-functions-common/types";
3
3
  export declare class Store<DTO extends DocumentData> {
4
4
  readonly collectionName: string;
5
5
  protected readonly converter?: FirestoreDataConverter<DTO> | undefined;
@@ -21,4 +21,3 @@ export declare class Store<DTO extends DocumentData> {
21
21
  deleteByParent(parentId: string): Promise<void>;
22
22
  refByParent(parentId: string): Query<DTO, FirebaseFirestore.DocumentData>;
23
23
  }
24
- //# sourceMappingURL=Store.d.ts.map
@@ -1,42 +1,10 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Store = void 0;
37
- const firebase_backend_js_1 = require("../common/firebase.backend.js");
38
- const uuid = __importStar(require("short-uuid"));
39
- class Store {
1
+ import { db as firestore } from "../firebase/firebase.backend.js";
2
+ import * as uuid from "short-uuid";
3
+ export class Store {
4
+ collectionName;
5
+ converter;
6
+ namespace;
7
+ _db;
40
8
  constructor(collectionName, converter, namespace = "picpad") {
41
9
  this.collectionName = collectionName;
42
10
  this.converter = converter;
@@ -45,11 +13,11 @@ class Store {
45
13
  db() {
46
14
  if (!this._db)
47
15
  if (this.converter)
48
- this._db = firebase_backend_js_1.db
16
+ this._db = firestore
49
17
  .collection(`${this.namespace}.${this.collectionName}`)
50
18
  .withConverter(this.converter);
51
19
  else
52
- this._db = firebase_backend_js_1.db.collection(`${this.namespace}.${this.collectionName}`);
20
+ this._db = firestore.collection(`${this.namespace}.${this.collectionName}`);
53
21
  return this._db;
54
22
  }
55
23
  async query(p) {
@@ -125,4 +93,3 @@ class Store {
125
93
  return this.db().where("parentId", "==", parentId);
126
94
  }
127
95
  }
128
- exports.Store = Store;
@@ -0,0 +1 @@
1
+ export { Store } from "./Store.js";
@@ -0,0 +1 @@
1
+ export { Store } from "./Store.js";
@@ -1,4 +1 @@
1
- export * from "./lib";
2
- import * as _all from "./lib";
3
- export default _all;
4
- //# sourceMappingURL=index.d.ts.map
1
+ export type * from "./types.validation.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type ValidationFieldErrors = Record<string, string[]>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
- import { Store } from "../store/Store";
1
+ import { Store } from "../store/Store.js";
2
2
  import type { ZodError, ZodObject, ZodRawShape } from "zod";
3
- import type { DocumentData, WithKey } from "@mxpicture/gcp-functions-common";
4
- export type ValidationFieldErrors = Record<string, string[]>;
3
+ import type { DocumentData, WithKey } from "@mxpicture/gcp-functions-common/types";
4
+ import { ValidationFieldErrors } from "../types/types.validation.js";
5
5
  export declare const createValidation: <DTO extends DocumentData>(store: Store<DTO>, shape: ZodRawShape) => Promise<Validation<DTO>>;
6
6
  export declare class Validation<DTO extends DocumentData> {
7
7
  readonly store: Store<DTO>;
@@ -13,4 +13,3 @@ export declare class Validation<DTO extends DocumentData> {
13
13
  validatePartial(doc: Partial<WithKey<DTO>>): Promise<Partial<WithKey<DTO>>>;
14
14
  protected issuesToFieldErrors(issues: ZodError["issues"]): ValidationFieldErrors;
15
15
  }
16
- //# sourceMappingURL=Validation.d.ts.map
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Validation = exports.createValidation = void 0;
4
- const https_1 = require("firebase-functions/https");
5
- const zod_loader_1 = require("../loader/zod.loader");
6
- const createValidation = async (store, shape) => {
7
- const createSchema = (await (0, zod_loader_1.loadZod)()).object(shape);
1
+ import { HttpsError } from "firebase-functions/https";
2
+ import { loadZod } from "../loader/zod.loader.js";
3
+ export const createValidation = async (store, shape) => {
4
+ const createSchema = (await loadZod()).object(shape);
8
5
  return new Validation(store, shape, createSchema, createSchema.partial());
9
6
  };
10
- exports.createValidation = createValidation;
11
- class Validation {
7
+ export class Validation {
8
+ store;
9
+ shape;
10
+ createSchema;
11
+ updateSchema;
12
12
  constructor(store, shape, createSchema, updateSchema) {
13
13
  this.store = store;
14
14
  this.shape = shape;
@@ -18,7 +18,7 @@ class Validation {
18
18
  async validate(doc) {
19
19
  const result = this.createSchema.safeParse(doc);
20
20
  if (!result.success)
21
- throw new https_1.HttpsError("invalid-argument", "Invalid request data", {
21
+ throw new HttpsError("invalid-argument", "Invalid request data", {
22
22
  fields: this.issuesToFieldErrors(result.error.issues),
23
23
  });
24
24
  return result.data;
@@ -26,7 +26,7 @@ class Validation {
26
26
  async validatePartial(doc) {
27
27
  const result = this.updateSchema.safeParse(doc);
28
28
  if (!result.success)
29
- throw new https_1.HttpsError("invalid-argument", "Invalid request data", {
29
+ throw new HttpsError("invalid-argument", "Invalid request data", {
30
30
  fields: this.issuesToFieldErrors(result.error.issues),
31
31
  });
32
32
  return result.data;
@@ -35,9 +35,8 @@ class Validation {
35
35
  const fields = {};
36
36
  for (const issue of issues) {
37
37
  const path = issue.path.length ? issue.path.join(".") : "_form";
38
- (fields[path] ?? (fields[path] = [])).push(issue.message);
38
+ (fields[path] ??= []).push(issue.message);
39
39
  }
40
40
  return fields;
41
41
  }
42
42
  }
43
- exports.Validation = Validation;
@@ -0,0 +1 @@
1
+ export { Validation, createValidation } from "./Validation.js";
@@ -0,0 +1 @@
1
+ export { Validation, createValidation } from "./Validation.js";
package/package.json CHANGED
@@ -1,40 +1,35 @@
1
1
  {
2
2
  "name": "@mxpicture/gcp-functions-backend",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
5
+ "type": "module",
5
6
  "author": "MXPicture",
6
7
  "license": "MIT",
7
8
  "repository": {
8
9
  "type": "git",
9
10
  "url": "git+https://github.com/MXPicture/npm-gcp-functions.git"
10
11
  },
11
- "main": "dist/cjs/index.js",
12
- "module": "dist/esm/index.js",
13
- "types": "dist/types/package.d.ts",
14
12
  "exports": {
15
- ".": {
16
- "types": "./dist/types/package.d.ts",
17
- "import": "./dist/esm/index.js",
18
- "require": "./dist/cjs/index.js"
19
- },
20
- "./*": {
21
- "types": "./dist/types/*",
22
- "import": "./dist/esm/*",
23
- "require": "./dist/cjs/*"
24
- },
13
+ "./store": "./dist/store/index.js",
14
+ "./firebase": "./dist/firebase/index.js",
15
+ "./validation": "./dist/validation/index.js",
16
+ "./api": "./dist/api/index.js",
17
+ "./http": "./dist/http/index.js",
18
+ "./function": "./dist/function/index.js",
19
+ "./types": "./dist/types/index.js",
25
20
  "./package.json": "./package.json"
26
21
  },
27
22
  "files": [
28
- "dist/"
23
+ "dist"
29
24
  ],
30
25
  "engines": {
31
26
  "node": "24"
32
27
  },
33
28
  "scripts": {
34
- "clean": "rm -rf dist .tsbuildinfo",
29
+ "clean": "rm -rf dist .tsbuildinfo node_modules",
35
30
  "lint": "eslint \"src/**/*.{ts,tsx}\" --ext .ts,.tsx",
36
31
  "update": "ncu -u && npm install",
37
- "build": "tsc",
32
+ "build": "tsc -p tsconfig.json",
38
33
  "update-own": "npm update --save @mxpicture/zod-meta"
39
34
  },
40
35
  "publishConfig": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"FunctionCollection.d.ts","sourceRoot":"","sources":["../../src/FunctionCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,qBAAa,kBAAkB;IAE7B,SAAS,CAAC,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;KAAE,CAAM;;IAIvD,GAAG,CAAC,GAAG,SAAS,YAAY,EACjC,IAAI,EAAE,eAAe,CAAC,GAAG,CAAC,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,kBAAkB;IAKd,KAAK;;;CAGb"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionCollection = void 0;
4
- class FunctionCollection {
5
- constructor() {
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- this.funcs = {};
8
- }
9
- add(func, name) {
10
- this.funcs[name ?? func.name] = func;
11
- return this;
12
- }
13
- build() {
14
- return this.funcs;
15
- }
16
- }
17
- exports.FunctionCollection = FunctionCollection;
@@ -1,27 +0,0 @@
1
- import type { MetaItem } from "@mxpicture/zod-meta";
2
- import type { ApiKey, ApiFilter, DocumentData, WithKey } from "@mxpicture/gcp-functions-common";
3
- import { IApi } from "@mxpicture/gcp-functions-common";
4
- import { Store } from "../store/Store";
5
- import type { Validation } from "../validation/Validation";
6
- import type { ZodRawShape } from "zod";
7
- export declare class BackendApi<DTO extends DocumentData, STORE extends Store<DTO> = Store<DTO>, VAL extends Validation<DTO> = Validation<DTO>> extends IApi<DTO> {
8
- readonly store: STORE;
9
- readonly validation: VAL;
10
- protected shape: ZodRawShape;
11
- constructor(store: STORE, validation: VAL, shape: ZodRawShape);
12
- delete(p: ApiKey): Promise<void>;
13
- get(p: ApiKey): Promise<WithKey<DTO>>;
14
- query(payload?: ApiFilter): Promise<WithKey<DTO>[]>;
15
- count(payload?: ApiFilter): Promise<{
16
- count: number;
17
- }>;
18
- exists(p: ApiKey): Promise<{
19
- exists: boolean;
20
- }>;
21
- meta(): Promise<MetaItem[]>;
22
- create(data: DTO): Promise<WithKey<DTO>>;
23
- update(p: {
24
- id: string;
25
- }, data: Partial<DTO>): Promise<WithKey<DTO>>;
26
- }
27
- //# sourceMappingURL=BackendApi.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BackendApi.d.ts","sourceRoot":"","sources":["../../../src/base/BackendApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,YAAY,EACZ,OAAO,EACR,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAEvC,qBAAa,UAAU,CACrB,GAAG,SAAS,YAAY,EACxB,KAAK,SAAS,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,EACrC,GAAG,SAAS,UAAU,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAC7C,SAAQ,IAAI,CAAC,GAAG,CAAC;aAEC,KAAK,EAAE,KAAK;aACZ,UAAU,EAAE,GAAG;IAC/B,SAAS,CAAC,KAAK,EAAE,WAAW;gBAFZ,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,GAAG,EACrB,KAAK,EAAE,WAAW;IAKR,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAIrC,KAAK,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;IAInD,KAAK,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAItD,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IAI/C,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAI3B,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAKxC,MAAM,CAAC,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;CAInE"}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BackendApi = void 0;
4
- const zod_meta_1 = require("@mxpicture/zod-meta");
5
- const gcp_functions_common_1 = require("@mxpicture/gcp-functions-common");
6
- class BackendApi extends gcp_functions_common_1.IApi {
7
- constructor(store, validation, shape) {
8
- super();
9
- this.store = store;
10
- this.validation = validation;
11
- this.shape = shape;
12
- }
13
- async delete(p) {
14
- return this.store.delete(p.id);
15
- }
16
- async get(p) {
17
- return this.store.get(p.id);
18
- }
19
- async query(payload) {
20
- return this.store.query(payload?.filters);
21
- }
22
- async count(payload) {
23
- return { count: await this.store.count(payload?.filters) };
24
- }
25
- async exists(p) {
26
- return { exists: await this.store.exists(p.id) };
27
- }
28
- async meta() {
29
- return new zod_meta_1.Meta(this.shape).items();
30
- }
31
- async create(data) {
32
- const result = await this.validation.validate(data);
33
- return this.store.create(result);
34
- }
35
- async update(p, data) {
36
- const result = await this.validation.validatePartial(data);
37
- return this.store.update(p.id, result);
38
- }
39
- }
40
- exports.BackendApi = BackendApi;
@@ -1,10 +0,0 @@
1
- import { HttpsFunction } from "firebase-functions/https";
2
- import type { HttpHandlers, DocumentData, ApiRoutes } from "@mxpicture/gcp-functions-common";
3
- export declare class BackendFunction<DTO extends DocumentData, HANDLER extends HttpHandlers<ApiRoutes<DTO>> = HttpHandlers<ApiRoutes<DTO>>> {
4
- readonly name: string;
5
- protected http: HANDLER;
6
- protected readonly httpMethods: string[];
7
- constructor(name: string, http: HANDLER);
8
- createFunction(): HttpsFunction;
9
- }
10
- //# sourceMappingURL=BackendFunction.d.ts.map