@mxpicture/gcp-functions-backend 2.1.34 → 2.1.36
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/BackendBaseApi.d.ts +35 -13
- package/dist/api/BackendBaseApi.d.ts.map +1 -1
- package/dist/api/BackendBaseApi.js +36 -13
- package/dist/api/BackendBaseApi.js.map +1 -1
- package/dist/api/BackendCrudApi.d.ts +5 -5
- package/dist/api/BackendCrudApi.d.ts.map +1 -1
- package/dist/api/BackendCrudApi.js +6 -2
- package/dist/api/BackendCrudApi.js.map +1 -1
- package/dist/api/BackendDefaultApi.d.ts +17 -8
- package/dist/api/BackendDefaultApi.d.ts.map +1 -1
- package/dist/api/BackendDefaultApi.js +19 -6
- package/dist/api/BackendDefaultApi.js.map +1 -1
- package/dist/api/BackendStoreApi.d.ts +1 -1
- package/dist/api/BackendStoreApi.d.ts.map +1 -1
- package/dist/api/BackendStoreApi.js.map +1 -1
- package/dist/api/IBackendApi.d.ts +22 -0
- package/dist/api/IBackendApi.d.ts.map +1 -1
- package/dist/factory/IBackendFactory.d.ts +39 -1
- package/dist/factory/IBackendFactory.d.ts.map +1 -1
- package/dist/factory/IBackendFactory.js +35 -0
- package/dist/factory/IBackendFactory.js.map +1 -1
- package/dist/factory/IBackendStoreFactory.d.ts +37 -1
- package/dist/factory/IBackendStoreFactory.d.ts.map +1 -1
- package/dist/factory/IBackendStoreFactory.js +34 -0
- package/dist/factory/IBackendStoreFactory.js.map +1 -1
- package/dist/firebase/FirebaseTaskHandler.d.ts +13 -6
- package/dist/firebase/FirebaseTaskHandler.d.ts.map +1 -1
- package/dist/firebase/FirebaseTaskHandler.js +13 -6
- package/dist/firebase/FirebaseTaskHandler.js.map +1 -1
- package/dist/firebase/FirebaseTaskQueueHandler.d.ts +23 -20
- package/dist/firebase/FirebaseTaskQueueHandler.d.ts.map +1 -1
- package/dist/firebase/FirebaseTaskQueueHandler.js +23 -20
- package/dist/firebase/FirebaseTaskQueueHandler.js.map +1 -1
- package/dist/firebase/firebase.express.d.ts +16 -8
- package/dist/firebase/firebase.express.d.ts.map +1 -1
- package/dist/firebase/firebase.express.js +16 -8
- package/dist/firebase/firebase.express.js.map +1 -1
- package/dist/firebase/firebase.tasks.d.ts +31 -0
- package/dist/firebase/firebase.tasks.d.ts.map +1 -1
- package/dist/firebase/firebase.tasks.js +31 -0
- package/dist/firebase/firebase.tasks.js.map +1 -1
- package/dist/function/CompositeBackendFunction.d.ts +33 -2
- package/dist/function/CompositeBackendFunction.d.ts.map +1 -1
- package/dist/function/CompositeBackendFunction.js +31 -1
- package/dist/function/CompositeBackendFunction.js.map +1 -1
- package/dist/function/IBackendFunction.d.ts +48 -23
- package/dist/function/IBackendFunction.d.ts.map +1 -1
- package/dist/function/IBackendFunction.js +39 -22
- package/dist/function/IBackendFunction.js.map +1 -1
- package/dist/store/Store.d.ts +21 -2
- package/dist/store/Store.d.ts.map +1 -1
- package/dist/store/Store.js +22 -3
- package/dist/store/Store.js.map +1 -1
- package/dist/types/types.env.d.ts +2 -1
- package/dist/types/types.env.d.ts.map +1 -1
- package/dist/types/types.tasks.d.ts +30 -1
- package/dist/types/types.tasks.d.ts.map +1 -1
- package/package.json +5 -3
|
@@ -5,17 +5,21 @@ import type { IBackendApi } from "./IBackendApi.js";
|
|
|
5
5
|
* Abstract base class for backend API implementations.
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* Provides dependency-injection
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Provides the dependency-injection seams for a {@link Validation} instance,
|
|
9
|
+
* the deployed function URL, and the set of route names this API answers to.
|
|
10
|
+
* Subclasses implement the concrete API methods while relying on the injected
|
|
11
|
+
* validation via {@link BackendBaseApi.useValidation}.
|
|
11
12
|
*
|
|
12
|
-
* @typeParam DTO - The document data transfer object type.
|
|
13
|
+
* @typeParam DTO - The document data transfer object type returned by this API.
|
|
14
|
+
* @typeParam INPUT_DTO - The shape accepted on write operations (defaults to `DTO`).
|
|
15
|
+
* @typeParam SIDE_EFFECTS - Type of side-effect payloads forwarded to subclasses.
|
|
13
16
|
* @typeParam VAL - The validation implementation used for input validation.
|
|
14
17
|
*/
|
|
15
|
-
export declare abstract class BackendBaseApi<DTO extends DocumentData, SIDE_EFFECTS extends DocumentData = DocumentData, VAL extends Validation<
|
|
18
|
+
export declare abstract class BackendBaseApi<DTO extends DocumentData, INPUT_DTO extends DocumentData = DTO, SIDE_EFFECTS extends DocumentData = DocumentData, VAL extends Validation<INPUT_DTO> = Validation<INPUT_DTO>> implements IBackendApi {
|
|
16
19
|
readonly name: string;
|
|
17
20
|
protected readonly datePaths: string[];
|
|
18
|
-
protected readonly
|
|
21
|
+
protected readonly outputVirtuals: DecoPropertyVirtual[];
|
|
22
|
+
protected readonly inputVirtuals: DecoPropertyVirtual[];
|
|
19
23
|
protected readonly sideEffects: string[];
|
|
20
24
|
protected _validation?: VAL;
|
|
21
25
|
protected _functionUrl?: string;
|
|
@@ -25,9 +29,24 @@ export declare abstract class BackendBaseApi<DTO extends DocumentData, SIDE_EFFE
|
|
|
25
29
|
*
|
|
26
30
|
* @param name - A descriptive name for this API, used in error messages.
|
|
27
31
|
* @param datePaths - JSON paths within the response payload that contain date values to convert to Firestore Timestamps.
|
|
32
|
+
* @param outputVirtuals - Virtual fields populated on read (consumed by `loadVirtualFields`).
|
|
33
|
+
* @param inputVirtuals - Virtual fields accepted on input (validated, stripped before storage).
|
|
34
|
+
* @param sideEffects - Keys whose changes trigger `processSideEffects`.
|
|
35
|
+
*/
|
|
36
|
+
constructor(name: string, datePaths: string[], outputVirtuals: DecoPropertyVirtual[], inputVirtuals: DecoPropertyVirtual[], sideEffects: string[]);
|
|
37
|
+
/**
|
|
38
|
+
* Inject the deployed function URL used by clients that talk to this API.
|
|
39
|
+
*
|
|
40
|
+
* @param url - The HTTPS URL of the deployed Cloud Function.
|
|
41
|
+
* @returns This instance for chaining.
|
|
28
42
|
*/
|
|
29
|
-
constructor(name: string, datePaths: string[], virtuals: DecoPropertyVirtual[], sideEffects: string[]);
|
|
30
43
|
useFunctionUrl(url: string): this;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve the configured function URL.
|
|
46
|
+
*
|
|
47
|
+
* @returns The HTTPS URL previously set via {@link useFunctionUrl}.
|
|
48
|
+
* @throws Error when no URL has been provided.
|
|
49
|
+
*/
|
|
31
50
|
get functionUrl(): string;
|
|
32
51
|
/**
|
|
33
52
|
* Inject the validation instance used for input validation.
|
|
@@ -56,17 +75,20 @@ export declare abstract class BackendBaseApi<DTO extends DocumentData, SIDE_EFFE
|
|
|
56
75
|
*/
|
|
57
76
|
validation(): VAL;
|
|
58
77
|
/**
|
|
59
|
-
*
|
|
78
|
+
* Routes an incoming request to the API method matching `route`.
|
|
60
79
|
*
|
|
61
80
|
* @remarks
|
|
62
|
-
* Validates that
|
|
63
|
-
*
|
|
81
|
+
* Validates that `route` is registered, converts date fields in the request
|
|
82
|
+
* to JavaScript `Date` objects, dispatches to the same-named method on the
|
|
83
|
+
* subclass, then converts date fields in the response back to Firestore
|
|
84
|
+
* timestamps before returning.
|
|
64
85
|
*
|
|
65
86
|
* @typeParam REQ - The request payload type.
|
|
66
87
|
* @typeParam RES - The response document data type.
|
|
67
|
-
* @param
|
|
68
|
-
* @
|
|
69
|
-
* @
|
|
88
|
+
* @param route - The name of the API method to invoke.
|
|
89
|
+
* @param data - The request payload to forward.
|
|
90
|
+
* @returns The transformed result of the dispatched method.
|
|
91
|
+
* @throws Error when `route` is not present in {@link routes}.
|
|
70
92
|
*/
|
|
71
93
|
ingress<REQ, RES extends DocumentData>(route: string, data: REQ): Promise<RES>;
|
|
72
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendBaseApi.d.ts","sourceRoot":"","sources":["../../src/api/BackendBaseApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACV,MAAM,uCAAuC,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G1C;;;;;OAKG;IACI,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKxC;;;;;OAKG;IACH,IAAW,WAAW,IAAI,MAAM,CAG/B;IAED;;;;OAIG;IACI,aAAa,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAK3C;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAKzC;;;;;OAKG;IACH,IAAW,MAAM,IAAI,MAAM,EAAE,CAM5B;IAED;;;;;OAKG;IACI,UAAU,IAAI,GAAG;IAQxB;;;;;;;;;;;;;;;OAeG;IACU,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,YAAY,EAChD,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,GAAG,CAAC;CAWhB"}
|
|
@@ -3,17 +3,21 @@ import { toDatesDeep, toTimestampsDeep, } from "@mxpicture/gcp-functions-common/
|
|
|
3
3
|
* Abstract base class for backend API implementations.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
* Provides dependency-injection
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Provides the dependency-injection seams for a {@link Validation} instance,
|
|
7
|
+
* the deployed function URL, and the set of route names this API answers to.
|
|
8
|
+
* Subclasses implement the concrete API methods while relying on the injected
|
|
9
|
+
* validation via {@link BackendBaseApi.useValidation}.
|
|
9
10
|
*
|
|
10
|
-
* @typeParam DTO - The document data transfer object type.
|
|
11
|
+
* @typeParam DTO - The document data transfer object type returned by this API.
|
|
12
|
+
* @typeParam INPUT_DTO - The shape accepted on write operations (defaults to `DTO`).
|
|
13
|
+
* @typeParam SIDE_EFFECTS - Type of side-effect payloads forwarded to subclasses.
|
|
11
14
|
* @typeParam VAL - The validation implementation used for input validation.
|
|
12
15
|
*/
|
|
13
16
|
export class BackendBaseApi {
|
|
14
17
|
name;
|
|
15
18
|
datePaths;
|
|
16
|
-
|
|
19
|
+
outputVirtuals;
|
|
20
|
+
inputVirtuals;
|
|
17
21
|
sideEffects;
|
|
18
22
|
_validation;
|
|
19
23
|
_functionUrl;
|
|
@@ -23,17 +27,33 @@ export class BackendBaseApi {
|
|
|
23
27
|
*
|
|
24
28
|
* @param name - A descriptive name for this API, used in error messages.
|
|
25
29
|
* @param datePaths - JSON paths within the response payload that contain date values to convert to Firestore Timestamps.
|
|
30
|
+
* @param outputVirtuals - Virtual fields populated on read (consumed by `loadVirtualFields`).
|
|
31
|
+
* @param inputVirtuals - Virtual fields accepted on input (validated, stripped before storage).
|
|
32
|
+
* @param sideEffects - Keys whose changes trigger `processSideEffects`.
|
|
26
33
|
*/
|
|
27
|
-
constructor(name, datePaths,
|
|
34
|
+
constructor(name, datePaths, outputVirtuals, inputVirtuals, sideEffects) {
|
|
28
35
|
this.name = name;
|
|
29
36
|
this.datePaths = datePaths;
|
|
30
|
-
this.
|
|
37
|
+
this.outputVirtuals = outputVirtuals;
|
|
38
|
+
this.inputVirtuals = inputVirtuals;
|
|
31
39
|
this.sideEffects = sideEffects;
|
|
32
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Inject the deployed function URL used by clients that talk to this API.
|
|
43
|
+
*
|
|
44
|
+
* @param url - The HTTPS URL of the deployed Cloud Function.
|
|
45
|
+
* @returns This instance for chaining.
|
|
46
|
+
*/
|
|
33
47
|
useFunctionUrl(url) {
|
|
34
48
|
this._functionUrl = url;
|
|
35
49
|
return this;
|
|
36
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve the configured function URL.
|
|
53
|
+
*
|
|
54
|
+
* @returns The HTTPS URL previously set via {@link useFunctionUrl}.
|
|
55
|
+
* @throws Error when no URL has been provided.
|
|
56
|
+
*/
|
|
37
57
|
get functionUrl() {
|
|
38
58
|
if (!this._functionUrl)
|
|
39
59
|
throw new Error(`No Url provided. ${this.name}`);
|
|
@@ -80,17 +100,20 @@ export class BackendBaseApi {
|
|
|
80
100
|
return this._validation;
|
|
81
101
|
}
|
|
82
102
|
/**
|
|
83
|
-
*
|
|
103
|
+
* Routes an incoming request to the API method matching `route`.
|
|
84
104
|
*
|
|
85
105
|
* @remarks
|
|
86
|
-
* Validates that
|
|
87
|
-
*
|
|
106
|
+
* Validates that `route` is registered, converts date fields in the request
|
|
107
|
+
* to JavaScript `Date` objects, dispatches to the same-named method on the
|
|
108
|
+
* subclass, then converts date fields in the response back to Firestore
|
|
109
|
+
* timestamps before returning.
|
|
88
110
|
*
|
|
89
111
|
* @typeParam REQ - The request payload type.
|
|
90
112
|
* @typeParam RES - The response document data type.
|
|
91
|
-
* @param
|
|
92
|
-
* @
|
|
93
|
-
* @
|
|
113
|
+
* @param route - The name of the API method to invoke.
|
|
114
|
+
* @param data - The request payload to forward.
|
|
115
|
+
* @returns The transformed result of the dispatched method.
|
|
116
|
+
* @throws Error when `route` is not present in {@link routes}.
|
|
94
117
|
*/
|
|
95
118
|
async ingress(route, data) {
|
|
96
119
|
const routes = this.routes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendBaseApi.js","sourceRoot":"","sources":["../../src/api/BackendBaseApi.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,WAAW,EACX,gBAAgB,GACjB,MAAM,wCAAwC,CAAC;AAGhD
|
|
1
|
+
{"version":3,"file":"BackendBaseApi.js","sourceRoot":"","sources":["../../src/api/BackendBaseApi.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,WAAW,EACX,gBAAgB,GACjB,MAAM,wCAAwC,CAAC;AAGhD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAgB,cAAc;IAqBhB;IACG;IACA;IACA;IACA;IAlBX,WAAW,CAAO;IAClB,YAAY,CAAU;IACtB,OAAO,CAAY;IAE7B;;;;;;;;OAQG;IACH,YACkB,IAAY,EACT,SAAmB,EACnB,cAAqC,EACrC,aAAoC,EACpC,WAAqB;QAJxB,SAAI,GAAJ,IAAI,CAAQ;QACT,cAAS,GAAT,SAAS,CAAU;QACnB,mBAAc,GAAd,cAAc,CAAuB;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,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,SAAS,KAAK,gBAAgB,CAAC,CAAC;QAElD,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAEtD,8DAA8D;QAC9D,MAAM,OAAO,GAAG,MAAO,IAAY,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC;QACxD,OAAO,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -13,7 +13,7 @@ import { BackendStoreApi } from "./BackendStoreApi.js";
|
|
|
13
13
|
* @typeParam STORE - The store implementation used for persistence.
|
|
14
14
|
* @typeParam VAL - The validation implementation used for input validation.
|
|
15
15
|
*/
|
|
16
|
-
export declare abstract class BackendCrudApi<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, SIDE_EFFECTS extends DocumentData = DocumentData, STORE extends Store<STORE_DOC> = Store<STORE_DOC>, VAL extends Validation<
|
|
16
|
+
export declare abstract class BackendCrudApi<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, INPUT_DTO extends DocumentData = DTO, SIDE_EFFECTS extends DocumentData = DocumentData, STORE extends Store<STORE_DOC> = Store<STORE_DOC>, VAL extends Validation<INPUT_DTO> = Validation<INPUT_DTO>> extends BackendStoreApi<STORE_DOC, DTO, INPUT_DTO, SIDE_EFFECTS, STORE, VAL> implements ApiFromRoutes<CrudRoutes<DTO, INPUT_DTO>> {
|
|
17
17
|
protected abstract loadVirtualFields(doc: STORE_DOC): Promise<DTO>;
|
|
18
18
|
protected processVirtualFields(doc: DTO): Promise<STORE_DOC>;
|
|
19
19
|
protected abstract processSideEffects(current: DTO, prev: DTO | null, sideEffects: Partial<SIDE_EFFECTS>): Promise<DTO>;
|
|
@@ -65,7 +65,7 @@ export declare abstract class BackendCrudApi<STORE_DOC extends DocumentKeyAdmin,
|
|
|
65
65
|
* @returns The newly created document including its generated key.
|
|
66
66
|
* @throws {@link HttpsError} if validation fails.
|
|
67
67
|
*/
|
|
68
|
-
abstract create(request: CreateInput<
|
|
68
|
+
abstract create(request: CreateInput<INPUT_DTO>): Promise<DTO>;
|
|
69
69
|
/**
|
|
70
70
|
* Update an existing document after validating the partial input.
|
|
71
71
|
*
|
|
@@ -73,12 +73,12 @@ export declare abstract class BackendCrudApi<STORE_DOC extends DocumentKeyAdmin,
|
|
|
73
73
|
* @returns The updated document including its key metadata.
|
|
74
74
|
* @throws {@link HttpsError} if validation fails.
|
|
75
75
|
*/
|
|
76
|
-
abstract update(request: UpdateInput<
|
|
76
|
+
abstract update(request: UpdateInput<INPUT_DTO>): Promise<DTO>;
|
|
77
77
|
protected toDto(doc: STORE_DOC): Promise<DTO>;
|
|
78
78
|
protected toDtos(docs: STORE_DOC[]): Promise<DTO[]>;
|
|
79
79
|
protected fromDto(dto: DTO, prevDto: DTO | null, changedProps?: string[]): Promise<STORE_DOC>;
|
|
80
|
-
protected fromDtoUpdate(dto: UpdateInput<
|
|
81
|
-
protected fromDtoCreate(dto: CreateInput<
|
|
80
|
+
protected fromDtoUpdate(dto: UpdateInput<INPUT_DTO>): Promise<STORE_DOC>;
|
|
81
|
+
protected fromDtoCreate(dto: CreateInput<INPUT_DTO>): Promise<STORE_DOC>;
|
|
82
82
|
protected createId(id?: string): string;
|
|
83
83
|
}
|
|
84
84
|
//# sourceMappingURL=BackendCrudApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendCrudApi.d.ts","sourceRoot":"","sources":["../../src/api/BackendCrudApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC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EAAE,GAAG,EACR,OAAO,EAAE,GAAG,GAAG,IAAI,EACnB,YAAY,GAAE,MAAM,EAAO,GAC1B,OAAO,CAAC,SAAS,CAAC;cA+BL,aAAa,CAC3B,GAAG,EAAE,WAAW,CAAC,SAAS,CAAC,GAC1B,OAAO,CAAC,SAAS,CAAC;cAYL,aAAa,CAC3B,GAAG,EAAE,WAAW,CAAC,SAAS,CAAC,GAC1B,OAAO,CAAC,SAAS,CAAC;IAKrB,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;CAOxC"}
|
|
@@ -15,8 +15,12 @@ import { toDatesDeep, toTimestampsDeep, } from "@mxpicture/gcp-functions-common/
|
|
|
15
15
|
export class BackendCrudApi extends BackendStoreApi {
|
|
16
16
|
// to be redefined
|
|
17
17
|
async processVirtualFields(doc) {
|
|
18
|
-
//
|
|
19
|
-
for (const { key } of this.
|
|
18
|
+
// strip any virtual key (input or output) — non-stored fields
|
|
19
|
+
for (const { key } of this.outputVirtuals)
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
if (doc[key])
|
|
22
|
+
delete doc[key];
|
|
23
|
+
for (const { key } of this.inputVirtuals)
|
|
20
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
25
|
if (doc[key])
|
|
22
26
|
delete doc[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendCrudApi.js","sourceRoot":"","sources":["../../src/api/BackendCrudApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAanC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,WAAW,EACX,gBAAgB,GACjB,MAAM,wCAAwC,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"BackendCrudApi.js","sourceRoot":"","sources":["../../src/api/BackendCrudApi.ts"],"names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,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,GAAG,EAAS,CAAC;QAE9C,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YACjD,8DAA8D;YAC9D,IAAK,MAAc,CAAC,GAAG,CAAC,KAAK,KAAK;gBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAExD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAES,KAAK,CAAC,aAAa,CAC3B,GAA2B;QAE3B,MAAM,QAAQ,GAAqB,EAAE,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,QAAQ,EAAoB,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,CAAC;IAES,QAAQ,CAAC,EAAW;QAC5B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -3,17 +3,26 @@ import type { Store } from "../store/Store.js";
|
|
|
3
3
|
import type { Validation } from "../validation/Validation.js";
|
|
4
4
|
import { BackendCrudApi } from "./BackendCrudApi.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Concrete default implementation of {@link BackendCrudApi}.
|
|
7
7
|
*
|
|
8
8
|
* @remarks
|
|
9
|
-
*
|
|
10
|
-
* Delegates persistence to a {@link Store} and input validation to a {@link Validation} instance.
|
|
9
|
+
* Wires every CRUD route through the injected {@link Store} and {@link Validation}:
|
|
11
10
|
*
|
|
12
|
-
*
|
|
11
|
+
* - `create` / `update` validate via {@link Validation} before persisting.
|
|
12
|
+
* - `get`, `query`, `count`, `exists`, `delete` forward directly to the store.
|
|
13
|
+
*
|
|
14
|
+
* The default `processVirtualFields` strips both input and output virtual
|
|
15
|
+
* fields before persistence so they never reach storage. Subclasses can
|
|
16
|
+
* override it to compute or persist virtual fields explicitly.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam STORE_DOC - The shape stored in the underlying {@link Store}.
|
|
19
|
+
* @typeParam DTO - The shape returned to callers (extends `STORE_DOC`).
|
|
20
|
+
* @typeParam INPUT_DTO - The shape accepted on write operations (defaults to `DTO`).
|
|
21
|
+
* @typeParam SIDE_EFFECTS - Type of side-effect payloads forwarded to subclasses.
|
|
13
22
|
* @typeParam STORE - The store implementation used for persistence.
|
|
14
23
|
* @typeParam VAL - The validation implementation used for input validation.
|
|
15
24
|
*/
|
|
16
|
-
export declare abstract class BackendDefaultApi<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, SIDE_EFFECTS extends DocumentData = DocumentData, STORE extends Store<STORE_DOC> = Store<STORE_DOC>, VAL extends Validation<
|
|
25
|
+
export declare abstract class BackendDefaultApi<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, INPUT_DTO extends DocumentData = DTO, SIDE_EFFECTS extends DocumentData = DocumentData, STORE extends Store<STORE_DOC> = Store<STORE_DOC>, VAL extends Validation<INPUT_DTO> = Validation<INPUT_DTO>> extends BackendCrudApi<STORE_DOC, DTO, INPUT_DTO, SIDE_EFFECTS, STORE, VAL> {
|
|
17
26
|
protected processVirtualFields(doc: DTO): Promise<STORE_DOC>;
|
|
18
27
|
/**
|
|
19
28
|
* Delete a document by its key.
|
|
@@ -63,7 +72,7 @@ export declare abstract class BackendDefaultApi<STORE_DOC extends DocumentKeyAdm
|
|
|
63
72
|
* @returns The newly created document including its generated key.
|
|
64
73
|
* @throws {@link HttpsError} if validation fails.
|
|
65
74
|
*/
|
|
66
|
-
create(request: CreateInput<
|
|
75
|
+
create(request: CreateInput<INPUT_DTO>): Promise<DTO>;
|
|
67
76
|
/**
|
|
68
77
|
* Update an existing document after validating the partial input.
|
|
69
78
|
*
|
|
@@ -71,8 +80,8 @@ export declare abstract class BackendDefaultApi<STORE_DOC extends DocumentKeyAdm
|
|
|
71
80
|
* @returns The updated document including its key metadata.
|
|
72
81
|
* @throws {@link HttpsError} if validation fails.
|
|
73
82
|
*/
|
|
74
|
-
update(request: UpdateInput<
|
|
75
|
-
protected prepareUpdate(request: UpdateInput<
|
|
83
|
+
update(request: UpdateInput<INPUT_DTO>): Promise<DTO>;
|
|
84
|
+
protected prepareUpdate(request: UpdateInput<INPUT_DTO>): Promise<{
|
|
76
85
|
id: string;
|
|
77
86
|
patch: Partial<STORE_DOC>;
|
|
78
87
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendDefaultApi.d.ts","sourceRoot":"","sources":["../../src/api/BackendDefaultApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD
|
|
1
|
+
{"version":3,"file":"BackendDefaultApi.d.ts","sourceRoot":"","sources":["../../src/api/BackendDefaultApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAA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AC,GAAG,CAAC;IAO3E;;;;;;OAMG;IACmB,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;cAM3D,aAAa,CAC3B,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,GAC9B,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;KAAE,CAAC;cAOrC,aAAa,CAC3B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,GACxB,OAAO,CAAC,MAAM,EAAE,CAAC;cAIJ,QAAQ,CACtB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,EACzB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;QAAE,OAAO,EAAE,GAAG,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAQrD"}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { BackendCrudApi } from "./BackendCrudApi.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Concrete default implementation of {@link BackendCrudApi}.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
* Delegates persistence to a {@link Store} and input validation to a {@link Validation} instance.
|
|
6
|
+
* Wires every CRUD route through the injected {@link Store} and {@link Validation}:
|
|
8
7
|
*
|
|
9
|
-
*
|
|
8
|
+
* - `create` / `update` validate via {@link Validation} before persisting.
|
|
9
|
+
* - `get`, `query`, `count`, `exists`, `delete` forward directly to the store.
|
|
10
|
+
*
|
|
11
|
+
* The default `processVirtualFields` strips both input and output virtual
|
|
12
|
+
* fields before persistence so they never reach storage. Subclasses can
|
|
13
|
+
* override it to compute or persist virtual fields explicitly.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam STORE_DOC - The shape stored in the underlying {@link Store}.
|
|
16
|
+
* @typeParam DTO - The shape returned to callers (extends `STORE_DOC`).
|
|
17
|
+
* @typeParam INPUT_DTO - The shape accepted on write operations (defaults to `DTO`).
|
|
18
|
+
* @typeParam SIDE_EFFECTS - Type of side-effect payloads forwarded to subclasses.
|
|
10
19
|
* @typeParam STORE - The store implementation used for persistence.
|
|
11
20
|
* @typeParam VAL - The validation implementation used for input validation.
|
|
12
21
|
*/
|
|
13
22
|
export class BackendDefaultApi extends BackendCrudApi {
|
|
14
23
|
// to be redefined
|
|
15
24
|
async processVirtualFields(doc) {
|
|
16
|
-
//
|
|
17
|
-
for (const { key } of this.
|
|
25
|
+
// strip any virtual key (input or output) — non-stored fields
|
|
26
|
+
for (const { key } of this.outputVirtuals)
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
if (doc[key])
|
|
29
|
+
delete doc[key];
|
|
30
|
+
for (const { key } of this.inputVirtuals)
|
|
18
31
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
32
|
if (doc[key])
|
|
20
33
|
delete doc[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendDefaultApi.js","sourceRoot":"","sources":["../../src/api/BackendDefaultApi.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD
|
|
1
|
+
{"version":3,"file":"BackendDefaultApi.js","sourceRoot":"","sources":["../../src/api/BackendDefaultApi.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAgB,iBAOpB,SAAQ,cAAmE;IAC3E,kBAAkB;IACC,KAAK,CAAC,oBAAoB,CAAC,GAAQ;QACpD,8DAA8D;QAC9D,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,cAAc;YACvC,8DAA8D;YAC9D,IAAK,GAAW,CAAC,GAAG,CAAC;gBAAE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,EAAE,EACF,KAAK,EACL,cAAc,CACf,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -15,7 +15,7 @@ import { BackendBaseApi } from "./BackendBaseApi.js";
|
|
|
15
15
|
* @typeParam STORE - The store implementation used for persistence.
|
|
16
16
|
* @typeParam VAL - The validation implementation used for input validation.
|
|
17
17
|
*/
|
|
18
|
-
export declare abstract class BackendStoreApi<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, SIDE_EFFECTS extends DocumentData = DocumentData, STORE extends Store<STORE_DOC> = Store<STORE_DOC>, VAL extends Validation<
|
|
18
|
+
export declare abstract class BackendStoreApi<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, INPUT_DTO extends DocumentData = DTO, SIDE_EFFECTS extends DocumentData = DocumentData, STORE extends Store<STORE_DOC> = Store<STORE_DOC>, VAL extends Validation<INPUT_DTO> = Validation<INPUT_DTO>> extends BackendBaseApi<DTO, INPUT_DTO, SIDE_EFFECTS, VAL> {
|
|
19
19
|
protected _store?: STORE;
|
|
20
20
|
/**
|
|
21
21
|
* Inject the store instance used for data persistence.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendStoreApi.d.ts","sourceRoot":"","sources":["../../src/api/BackendStoreApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,8BAAsB,eAAe,CACnC,SAAS,SAAS,gBAAgB,EAClC,GAAG,SAAS,SAAS,EACrB,YAAY,SAAS,YAAY,GAAG,YAAY,EAChD,KAAK,SAAS,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,EACjD,GAAG,SAAS,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"BackendStoreApi.d.ts","sourceRoot":"","sources":["../../src/api/BackendStoreApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,8BAAsB,eAAe,CACnC,SAAS,SAAS,gBAAgB,EAClC,GAAG,SAAS,SAAS,EACrB,SAAS,SAAS,YAAY,GAAG,GAAG,EACpC,YAAY,SAAS,YAAY,GAAG,YAAY,EAChD,KAAK,SAAS,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,EACjD,GAAG,SAAS,UAAU,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CACzD,SAAQ,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,CAAC;IACzD,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;IAEzB;;;;OAIG;IACI,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAKnC;;;;;OAKG;IACI,KAAK,IAAI,KAAK;CAOtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendStoreApi.js","sourceRoot":"","sources":["../../src/api/BackendStoreApi.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"BackendStoreApi.js","sourceRoot":"","sources":["../../src/api/BackendStoreApi.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,eAOpB,SAAQ,cAAiD;IAC/C,MAAM,CAAS;IAEzB;;;;OAIG;IACI,QAAQ,CAAC,KAAY;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,MAAM;YACd,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,IAAI,6CAA6C,CAC1D,CAAC;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import type { DocumentData, RoutesRaw } from "@mxpicture/gcp-functions-common/types";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal contract every backend API must satisfy.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Used by {@link CompositeBackendFunction} and the per-topic factory wiring to
|
|
7
|
+
* dispatch incoming requests without depending on the concrete API class.
|
|
8
|
+
*/
|
|
2
9
|
export interface IBackendApi {
|
|
10
|
+
/** Inject the deployed function URL used to derive callback paths. */
|
|
3
11
|
useFunctionUrl(url: string): void;
|
|
12
|
+
/** The previously injected function URL. Throws if not set. */
|
|
4
13
|
get functionUrl(): string;
|
|
14
|
+
/** Register the route names this API answers to. */
|
|
5
15
|
useRoutes(routes: RoutesRaw): void;
|
|
16
|
+
/** The registered route names. Throws if not set. */
|
|
6
17
|
get routes(): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Dispatch a request to the named route, returning its typed response.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam REQ - The request payload type.
|
|
22
|
+
* @typeParam RES - The response document data type.
|
|
23
|
+
* @param route - The route name to invoke.
|
|
24
|
+
* @param data - The request payload.
|
|
25
|
+
*/
|
|
7
26
|
ingress<REQ, RES extends DocumentData>(route: string, data: REQ): Promise<RES>;
|
|
8
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Map of named {@link IBackendApi} instances keyed by topic / namespace.
|
|
30
|
+
*/
|
|
9
31
|
export type IBackendApis = Record<string, IBackendApi>;
|
|
10
32
|
//# sourceMappingURL=IBackendApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IBackendApi.d.ts","sourceRoot":"","sources":["../../src/api/IBackendApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACV,MAAM,uCAAuC,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,IAAI,WAAW,IAAI,MAAM,CAAC;IAE1B,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;IAEvB,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,YAAY,EACnC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"IBackendApi.d.ts","sourceRoot":"","sources":["../../src/api/IBackendApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACV,MAAM,uCAAuC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,+DAA+D;IAC/D,IAAI,WAAW,IAAI,MAAM,CAAC;IAE1B,oDAAoD;IACpD,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,qDAAqD;IACrD,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;IAEvB;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,YAAY,EACnC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import type { DocumentData, RoutesRaw } from "@mxpicture/gcp-functions-common/types";
|
|
2
2
|
import type { Validation } from "../validation/Validation.js";
|
|
3
3
|
import type { BackendBaseApi } from "../api/BackendBaseApi.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Lazy factory that constructs and memoises a backend API, its validation, and its routes.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Subclasses implement the three abstract `_create*` hooks; the public
|
|
9
|
+
* accessors cache the result of the first call so successive invocations are
|
|
10
|
+
* cheap. Generated code uses this base to wire backend topics into the
|
|
11
|
+
* Cloud Functions runtime without leaking construction details into call sites.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam DTO - The document data transfer object type.
|
|
14
|
+
* @typeParam INPUT_DTO - The shape accepted on write operations.
|
|
15
|
+
* @typeParam API - The concrete API class produced by the factory.
|
|
16
|
+
* @typeParam SIDE_EFFECTS - Type of side-effect payloads supported by the API.
|
|
17
|
+
* @typeParam VAL - The validation implementation used by the API.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class IBackendFactory<DTO extends DocumentData, INPUT_DTO extends DocumentData, API extends BackendBaseApi<DTO, INPUT_DTO, SIDE_EFFECTS, VAL>, SIDE_EFFECTS extends DocumentData = DocumentData, VAL extends Validation<INPUT_DTO> = Validation<INPUT_DTO>> {
|
|
5
20
|
protected readonly params: {
|
|
6
21
|
name: string;
|
|
7
22
|
projectId: string;
|
|
@@ -12,21 +27,44 @@ export declare abstract class IBackendFactory<DTO extends DocumentData, API exte
|
|
|
12
27
|
protected _validation: VAL | null;
|
|
13
28
|
protected _routesRaw: RoutesRaw | null;
|
|
14
29
|
protected _functionUrl: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new factory.
|
|
32
|
+
*
|
|
33
|
+
* @param params - Deployment parameters: function name, GCP project, region, and service account.
|
|
34
|
+
*/
|
|
15
35
|
constructor(params: {
|
|
16
36
|
name: string;
|
|
17
37
|
projectId: string;
|
|
18
38
|
region: string;
|
|
19
39
|
serviceAccount: string;
|
|
20
40
|
});
|
|
41
|
+
/** Deployed function name. */
|
|
21
42
|
get name(): string;
|
|
43
|
+
/** GCP project ID. */
|
|
22
44
|
get projectId(): string;
|
|
45
|
+
/** Cloud Functions deployment region. */
|
|
23
46
|
get region(): string;
|
|
47
|
+
/** Service account email used by the deployed function. */
|
|
24
48
|
get serviceAccount(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the API instance, constructing it on first call and caching afterwards.
|
|
51
|
+
*
|
|
52
|
+
* @returns The configured {@link API} with routes and validation injected.
|
|
53
|
+
*/
|
|
25
54
|
api(): API;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the validation instance, constructing it on first call and caching afterwards.
|
|
57
|
+
*/
|
|
26
58
|
validation(): VAL;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the raw routes definition, constructing it on first call and caching afterwards.
|
|
61
|
+
*/
|
|
27
62
|
routes(): RoutesRaw;
|
|
63
|
+
/** Subclass hook: build a fresh API instance. Called at most once per factory. */
|
|
28
64
|
protected abstract _createApi(): API;
|
|
65
|
+
/** Subclass hook: build a fresh validation instance. Called at most once per factory. */
|
|
29
66
|
protected abstract _createValidation(): VAL;
|
|
67
|
+
/** Subclass hook: build the raw routes definition. Called at most once per factory. */
|
|
30
68
|
protected abstract _createRoutes(): RoutesRaw;
|
|
31
69
|
}
|
|
32
70
|
//# sourceMappingURL=IBackendFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IBackendFactory.d.ts","sourceRoot":"","sources":["../../src/factory/IBackendFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACV,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,8BAAsB,eAAe,CACnC,GAAG,SAAS,YAAY,EACxB,GAAG,SAAS,cAAc,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"IBackendFactory.d.ts","sourceRoot":"","sources":["../../src/factory/IBackendFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACV,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,eAAe,CACnC,GAAG,SAAS,YAAY,EACxB,SAAS,SAAS,YAAY,EAC9B,GAAG,SAAS,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,CAAC,EAC7D,YAAY,SAAS,YAAY,GAAG,YAAY,EAChD,GAAG,SAAS,UAAU,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC;IAavD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,MAAM,CAAC;KACxB;IAhBH,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAAQ;IAClC,SAAS,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,CAAQ;IACzC,SAAS,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI,CAAQ;IAC9C,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE7C;;;;OAIG;gBAEkB,MAAM,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,MAAM,CAAC;KACxB;IAGH,8BAA8B;IAC9B,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,sBAAsB;IACtB,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,yCAAyC;IACzC,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,2DAA2D;IAC3D,IAAW,cAAc,IAAI,MAAM,CAElC;IAED;;;;OAIG;IACI,GAAG,IAAI,GAAG;IAMjB;;OAEG;IACI,UAAU,IAAI,GAAG;IAIxB;;OAEG;IACI,MAAM,IAAI,SAAS;IAI1B,kFAAkF;IAClF,SAAS,CAAC,QAAQ,CAAC,UAAU,IAAI,GAAG;IACpC,yFAAyF;IACzF,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,GAAG;IAC3C,uFAAuF;IACvF,SAAS,CAAC,QAAQ,CAAC,aAAa,IAAI,SAAS;CAC9C"}
|
|
@@ -1,32 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy factory that constructs and memoises a backend API, its validation, and its routes.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Subclasses implement the three abstract `_create*` hooks; the public
|
|
6
|
+
* accessors cache the result of the first call so successive invocations are
|
|
7
|
+
* cheap. Generated code uses this base to wire backend topics into the
|
|
8
|
+
* Cloud Functions runtime without leaking construction details into call sites.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam DTO - The document data transfer object type.
|
|
11
|
+
* @typeParam INPUT_DTO - The shape accepted on write operations.
|
|
12
|
+
* @typeParam API - The concrete API class produced by the factory.
|
|
13
|
+
* @typeParam SIDE_EFFECTS - Type of side-effect payloads supported by the API.
|
|
14
|
+
* @typeParam VAL - The validation implementation used by the API.
|
|
15
|
+
*/
|
|
1
16
|
export class IBackendFactory {
|
|
2
17
|
params;
|
|
3
18
|
_api = null;
|
|
4
19
|
_validation = null;
|
|
5
20
|
_routesRaw = null;
|
|
6
21
|
_functionUrl = null;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new factory.
|
|
24
|
+
*
|
|
25
|
+
* @param params - Deployment parameters: function name, GCP project, region, and service account.
|
|
26
|
+
*/
|
|
7
27
|
constructor(params) {
|
|
8
28
|
this.params = params;
|
|
9
29
|
}
|
|
30
|
+
/** Deployed function name. */
|
|
10
31
|
get name() {
|
|
11
32
|
return this.params.name;
|
|
12
33
|
}
|
|
34
|
+
/** GCP project ID. */
|
|
13
35
|
get projectId() {
|
|
14
36
|
return this.params.projectId;
|
|
15
37
|
}
|
|
38
|
+
/** Cloud Functions deployment region. */
|
|
16
39
|
get region() {
|
|
17
40
|
return this.params.region;
|
|
18
41
|
}
|
|
42
|
+
/** Service account email used by the deployed function. */
|
|
19
43
|
get serviceAccount() {
|
|
20
44
|
return this.params.serviceAccount;
|
|
21
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the API instance, constructing it on first call and caching afterwards.
|
|
48
|
+
*
|
|
49
|
+
* @returns The configured {@link API} with routes and validation injected.
|
|
50
|
+
*/
|
|
22
51
|
api() {
|
|
23
52
|
return (this._api ??= this._createApi()
|
|
24
53
|
.useRoutes(this.routes())
|
|
25
54
|
.useValidation(this.validation()));
|
|
26
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the validation instance, constructing it on first call and caching afterwards.
|
|
58
|
+
*/
|
|
27
59
|
validation() {
|
|
28
60
|
return (this._validation ??= this._createValidation());
|
|
29
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the raw routes definition, constructing it on first call and caching afterwards.
|
|
64
|
+
*/
|
|
30
65
|
routes() {
|
|
31
66
|
return (this._routesRaw ??= this._createRoutes());
|
|
32
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IBackendFactory.js","sourceRoot":"","sources":["../../src/factory/IBackendFactory.ts"],"names":[],"mappings":"AAOA,MAAM,OAAgB,eAAe;
|
|
1
|
+
{"version":3,"file":"IBackendFactory.js","sourceRoot":"","sources":["../../src/factory/IBackendFactory.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAgB,eAAe;IAkBd;IAXX,IAAI,GAAe,IAAI,CAAC;IACxB,WAAW,GAAe,IAAI,CAAC;IAC/B,UAAU,GAAqB,IAAI,CAAC;IACpC,YAAY,GAAkB,IAAI,CAAC;IAE7C;;;;OAIG;IACH,YACqB,MAKlB;QALkB,WAAM,GAAN,MAAM,CAKxB;IACA,CAAC;IAEJ,8BAA8B;IAC9B,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,sBAAsB;IACtB,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED,yCAAyC;IACzC,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,2DAA2D;IAC3D,IAAW,cAAc;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,GAAG;QACR,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,UAAU,EAAE;aACpC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;aACxB,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACI,MAAM;QACX,OAAO,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IACpD,CAAC;CAQF"}
|