@decaf-ts/for-http 0.3.0 → 0.3.2
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/README.md +1 -1
- package/dist/for-http.cjs +1 -1
- package/dist/for-http.cjs.map +1 -1
- package/dist/for-http.js +1 -1
- package/dist/for-http.js.map +1 -1
- package/lib/RestRepository.d.ts +3 -5
- package/lib/RestRepository.js.map +1 -1
- package/lib/RestService.cjs +8 -229
- package/lib/RestService.d.ts +4 -156
- package/lib/RestService.js.map +1 -1
- package/lib/adapter.cjs +43 -8
- package/lib/adapter.d.ts +20 -21
- package/lib/adapter.js.map +1 -1
- package/lib/axios/axios.cjs +20 -21
- package/lib/axios/axios.d.ts +10 -7
- package/lib/axios/axios.js.map +1 -1
- package/lib/esm/RestRepository.d.ts +3 -5
- package/lib/esm/RestRepository.js.map +1 -1
- package/lib/esm/RestService.d.ts +4 -156
- package/lib/esm/RestService.js +8 -229
- package/lib/esm/RestService.js.map +1 -1
- package/lib/esm/adapter.d.ts +20 -21
- package/lib/esm/adapter.js +45 -10
- package/lib/esm/adapter.js.map +1 -1
- package/lib/esm/axios/axios.d.ts +10 -7
- package/lib/esm/axios/axios.js +20 -21
- package/lib/esm/axios/axios.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/package.json +1 -1
package/lib/RestService.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { BulkCrudOperator, Context, CrudOperator } from "@decaf-ts/db-decorators";
|
|
2
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
2
|
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
-
import {
|
|
3
|
+
import { FlagsOf } from "@decaf-ts/core";
|
|
5
4
|
import { HttpAdapter } from "./adapter";
|
|
6
|
-
import {
|
|
7
|
-
import { LoggedClass, Logger } from "@decaf-ts/logging";
|
|
5
|
+
import { RestRepository } from "./RestRepository";
|
|
8
6
|
/**
|
|
9
7
|
* @description Service class for REST API operations
|
|
10
8
|
* @summary Provides a comprehensive implementation for interacting with REST APIs.
|
|
@@ -53,44 +51,8 @@ import { LoggedClass, Logger } from "@decaf-ts/logging";
|
|
|
53
51
|
* Adapter-->>Service: record
|
|
54
52
|
* Service-->>Client: revert(record)
|
|
55
53
|
*/
|
|
56
|
-
export declare class RestService<M extends Model,
|
|
57
|
-
|
|
58
|
-
private _pk;
|
|
59
|
-
private logger?;
|
|
60
|
-
/**
|
|
61
|
-
* @description Gets the model class constructor
|
|
62
|
-
* @summary Retrieves the model class constructor associated with this service.
|
|
63
|
-
* Throws an error if no class definition is found.
|
|
64
|
-
* @return {Constructor<M>} The model class constructor
|
|
65
|
-
* @throws {InternalError} If no class definition is found
|
|
66
|
-
*/
|
|
67
|
-
get class(): Constructor<M>;
|
|
68
|
-
protected get log(): Logger;
|
|
69
|
-
/**
|
|
70
|
-
* @description Gets the primary key property name
|
|
71
|
-
* @summary Retrieves the name of the primary key property for the model.
|
|
72
|
-
* If not already determined, it finds the primary key using the model class.
|
|
73
|
-
* @return The primary key property name
|
|
74
|
-
*/
|
|
75
|
-
get pk(): keyof M;
|
|
76
|
-
protected observers: Observer[];
|
|
77
|
-
private readonly _adapter;
|
|
78
|
-
private _tableName;
|
|
79
|
-
/**
|
|
80
|
-
* @description Gets the HTTP adapter
|
|
81
|
-
* @summary Retrieves the HTTP adapter associated with this service.
|
|
82
|
-
* Throws an error if no adapter is found.
|
|
83
|
-
* @return {A} The HTTP adapter instance
|
|
84
|
-
* @throws {InternalError} If no adapter is found
|
|
85
|
-
*/
|
|
86
|
-
protected get adapter(): A;
|
|
87
|
-
/**
|
|
88
|
-
* @description Gets the table name for the model
|
|
89
|
-
* @summary Retrieves the table name associated with the model class.
|
|
90
|
-
* If not already determined, it gets the table name from the Repository utility.
|
|
91
|
-
* @return {string} The table name
|
|
92
|
-
*/
|
|
93
|
-
protected get tableName(): string;
|
|
54
|
+
export declare class RestService<M extends Model, A extends HttpAdapter<any, any, any, any>, Q = A extends HttpAdapter<any, any, infer Q, any> ? Q : never> extends RestRepository<M, A, Q> {
|
|
55
|
+
protected _overrides: Partial<FlagsOf<A>>;
|
|
94
56
|
/**
|
|
95
57
|
* @description Initializes a new RestService instance
|
|
96
58
|
* @summary Creates a new service instance with the specified adapter and optional model class.
|
|
@@ -99,119 +61,5 @@ export declare class RestService<M extends Model, Q, A extends HttpAdapter<any,
|
|
|
99
61
|
* @param {Constructor<M>} [clazz] - Optional constructor for the model class
|
|
100
62
|
*/
|
|
101
63
|
constructor(adapter: A, clazz?: Constructor<M>);
|
|
102
|
-
url(path: string, queryParams?: Record<string, string | number>): string;
|
|
103
|
-
/**
|
|
104
|
-
* @description Creates a new resource
|
|
105
|
-
* @summary Creates a new resource in the REST API using the provided model.
|
|
106
|
-
* The method prepares the model for the adapter, sends the create request,
|
|
107
|
-
* and then converts the response back to a model instance.
|
|
108
|
-
* @param {M} model - The model instance to create
|
|
109
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
110
|
-
* @return {Promise<M>} A promise that resolves with the created model instance
|
|
111
|
-
*/
|
|
112
|
-
create(model: M, ...args: any[]): Promise<M>;
|
|
113
|
-
/**
|
|
114
|
-
* @description Retrieves a resource by ID
|
|
115
|
-
* @summary Fetches a resource from the REST API using the provided ID.
|
|
116
|
-
* The method sends the read request and converts the response to a model instance.
|
|
117
|
-
* @param {string|number} id - The identifier of the resource to retrieve
|
|
118
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
119
|
-
* @return {Promise<M>} A promise that resolves with the retrieved model instance
|
|
120
|
-
*/
|
|
121
|
-
read(id: string | number, ...args: any[]): Promise<M>;
|
|
122
|
-
/**
|
|
123
|
-
* @description Updates an existing resource
|
|
124
|
-
* @summary Updates an existing resource in the REST API using the provided model.
|
|
125
|
-
* The method prepares the model for the adapter, sends the update request,
|
|
126
|
-
* and then converts the response back to a model instance.
|
|
127
|
-
* @param {M} model - The model instance with updated data
|
|
128
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
129
|
-
* @return {Promise<M>} A promise that resolves with the updated model instance
|
|
130
|
-
*/
|
|
131
|
-
update(model: M, ...args: any[]): Promise<M>;
|
|
132
|
-
/**
|
|
133
|
-
* @description Deletes a resource by ID
|
|
134
|
-
* @summary Removes a resource from the REST API using the provided ID.
|
|
135
|
-
* The method sends the delete request and converts the response to a model instance.
|
|
136
|
-
* @param {string|number} id - The identifier of the resource to delete
|
|
137
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
138
|
-
* @return {Promise<M>} A promise that resolves with the deleted model instance
|
|
139
|
-
*/
|
|
140
|
-
delete(id: string | number, ...args: any[]): Promise<M>;
|
|
141
|
-
request<V>(details: Q): Promise<V>;
|
|
142
|
-
/**
|
|
143
|
-
* @description Creates multiple resources
|
|
144
|
-
* @summary Creates multiple resources in the REST API using the provided models.
|
|
145
|
-
* The method prepares each model for the adapter, sends a bulk create request,
|
|
146
|
-
* and then converts the responses back to model instances.
|
|
147
|
-
* @param {M[]} models - The model instances to create
|
|
148
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
149
|
-
* @return {Promise<M[]>} A promise that resolves with an array of created model instances
|
|
150
|
-
* @mermaid
|
|
151
|
-
* sequenceDiagram
|
|
152
|
-
* participant Client
|
|
153
|
-
* participant Service as RestService
|
|
154
|
-
* participant Adapter as HttpAdapter
|
|
155
|
-
* Client->>Service: createAll(models)
|
|
156
|
-
* Service->>Adapter: prepare(model, pk) x N
|
|
157
|
-
* Service->>Adapter: createAll(table, ids[], records[])
|
|
158
|
-
* Adapter-->>Service: records[]
|
|
159
|
-
* Service-->>Client: revert(records[])
|
|
160
|
-
*/
|
|
161
|
-
createAll(models: M[], ...args: any[]): Promise<M[]>;
|
|
162
|
-
/**
|
|
163
|
-
* @description Deletes multiple resources by IDs
|
|
164
|
-
* @summary Removes multiple resources from the REST API using the provided IDs.
|
|
165
|
-
* The method sends a bulk delete request and converts the responses to model instances.
|
|
166
|
-
* @param {string[]|number[]} keys - The identifiers of the resources to delete
|
|
167
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
168
|
-
* @return {Promise<M[]>} A promise that resolves with an array of deleted model instances
|
|
169
|
-
*/
|
|
170
|
-
deleteAll(keys: string[] | number[], ...args: any[]): Promise<M[]>;
|
|
171
|
-
/**
|
|
172
|
-
* @description Retrieves multiple resources by IDs
|
|
173
|
-
* @summary Fetches multiple resources from the REST API using the provided IDs.
|
|
174
|
-
* The method sends a bulk read request and converts the responses to model instances.
|
|
175
|
-
* @param {string[]|number[]} keys - The identifiers of the resources to retrieve
|
|
176
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
177
|
-
* @return {Promise<M[]>} A promise that resolves with an array of retrieved model instances
|
|
178
|
-
*/
|
|
179
|
-
readAll(keys: string[] | number[], ...args: any[]): Promise<M[]>;
|
|
180
|
-
/**
|
|
181
|
-
* @description Updates multiple resources
|
|
182
|
-
* @summary Updates multiple resources in the REST API using the provided models.
|
|
183
|
-
* The method prepares each model for the adapter, sends a bulk update request,
|
|
184
|
-
* and then converts the responses back to model instances.
|
|
185
|
-
* @param {M[]} models - The model instances with updated data
|
|
186
|
-
* @param {...any[]} args - Additional arguments to pass to the adapter
|
|
187
|
-
* @return {Promise<M[]>} A promise that resolves with an array of updated model instances
|
|
188
|
-
*/
|
|
189
|
-
updateAll(models: M[], ...args: any[]): Promise<M[]>;
|
|
190
|
-
/**
|
|
191
|
-
* @description Registers an observer
|
|
192
|
-
* @summary Adds an observer to the list of observers that will be notified of changes.
|
|
193
|
-
* Throws an error if the observer is already registered.
|
|
194
|
-
* @param {Observer} observer - The observer to register
|
|
195
|
-
* @return {void}
|
|
196
|
-
* @throws {InternalError} If the observer is already registered
|
|
197
|
-
*/
|
|
198
|
-
observe(observer: Observer): void;
|
|
199
|
-
/**
|
|
200
|
-
* @description Unregisters an observer
|
|
201
|
-
* @summary Removes an observer from the list of observers.
|
|
202
|
-
* Throws an error if the observer is not found.
|
|
203
|
-
* @param {Observer} observer - The observer to unregister
|
|
204
|
-
* @return {void}
|
|
205
|
-
* @throws {InternalError} If the observer is not found
|
|
206
|
-
*/
|
|
207
|
-
unObserve(observer: Observer): void;
|
|
208
|
-
/**
|
|
209
|
-
* @description Notifies all registered observers
|
|
210
|
-
* @summary Calls the refresh method on all registered observers to update themselves.
|
|
211
|
-
* Any errors during observer refresh are logged as warnings but don't stop the process.
|
|
212
|
-
* @param {...any[]} [args] - Optional arguments to pass to the observer refresh method
|
|
213
|
-
* @return {Promise<void>} A promise that resolves when all observers have been updated
|
|
214
|
-
*/
|
|
215
|
-
updateObservers(...args: any[]): Promise<void>;
|
|
216
64
|
toString(): string;
|
|
217
65
|
}
|
package/lib/RestService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RestService.js","sourceRoot":"","sources":["../src/RestService.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"RestService.js","sourceRoot":"","sources":["../src/RestService.ts"],"names":[],"mappings":";;;AAAA,yEAAuD;AAIvD,yDAAkD;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAa,WAIX,SAAQ,+BAAuB;IAM/B;;;;;;OAMG;IACH,YAAY,OAAU,EAAE,KAAsB;QAC5C,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAbL,eAAU,GAAwB;YACnD,gBAAgB,EAAE,IAAI;YACtB,cAAc,EAAE,IAAI;SACE,CAAC;IAWzB,CAAC;IAEQ,QAAQ;QACf,OAAO,GAAG,4BAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC;IACvD,CAAC;CACF;AAxBD,kCAwBC"}
|
package/lib/adapter.cjs
CHANGED
|
@@ -61,8 +61,8 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
61
61
|
* @description Returns the repository constructor for this adapter
|
|
62
62
|
* @summary Provides the RestService class as the repository implementation for this HTTP adapter.
|
|
63
63
|
* This method is used to create repository instances that work with this adapter type.
|
|
64
|
-
* @template
|
|
65
|
-
* @return {Constructor<
|
|
64
|
+
* @template R - Repository subtype working with this adapter
|
|
65
|
+
* @return {Constructor<R>} The repository constructor
|
|
66
66
|
*/
|
|
67
67
|
repository() {
|
|
68
68
|
return RestService_1.RestService;
|
|
@@ -74,10 +74,11 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
74
74
|
* @template M - The model type
|
|
75
75
|
* @param {M} model - The model instance to prepare
|
|
76
76
|
* @param pk - The primary key property name
|
|
77
|
+
* @param args
|
|
77
78
|
* @return The prepared data
|
|
78
79
|
*/
|
|
79
|
-
prepare(model,
|
|
80
|
-
const log = this.
|
|
80
|
+
prepare(model, ...args) {
|
|
81
|
+
const { log } = this.logCtx(args, this.prepare);
|
|
81
82
|
const result = Object.assign({}, model);
|
|
82
83
|
if (model[core_1.PersistenceKeys.METADATA]) {
|
|
83
84
|
log.silly(`Passing along persistence metadata for ${model[core_1.PersistenceKeys.METADATA]}`);
|
|
@@ -90,7 +91,7 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
90
91
|
}
|
|
91
92
|
return {
|
|
92
93
|
record: model,
|
|
93
|
-
id: model[pk],
|
|
94
|
+
id: model[decorator_validation_1.Model.pk(model.constructor)],
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
@@ -104,8 +105,8 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
104
105
|
* @param {string|number|bigint} id - The primary key value
|
|
105
106
|
* @return {M} The reconstructed model instance
|
|
106
107
|
*/
|
|
107
|
-
revert(obj, clazz,
|
|
108
|
-
const log = this.
|
|
108
|
+
revert(obj, clazz, id, ...args) {
|
|
109
|
+
const { log } = this.logCtx(args, this.revert);
|
|
109
110
|
const ob = {};
|
|
110
111
|
const m = (typeof clazz === "string" ? decorator_validation_1.Model.build(ob, clazz) : new clazz(ob));
|
|
111
112
|
log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
|
|
@@ -125,6 +126,9 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
125
126
|
}
|
|
126
127
|
return result;
|
|
127
128
|
}
|
|
129
|
+
toTableName(t) {
|
|
130
|
+
return typeof t === "string" ? t : decorator_validation_1.Model.tableName(t);
|
|
131
|
+
}
|
|
128
132
|
/**
|
|
129
133
|
* @description Constructs a URL for API requests
|
|
130
134
|
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
@@ -134,6 +138,7 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
134
138
|
* @return {string} The encoded URL string
|
|
135
139
|
*/
|
|
136
140
|
url(tableName, queryParams) {
|
|
141
|
+
tableName = this.toTableName(tableName);
|
|
137
142
|
const url = new URL(`${this.config.protocol}://${this.config.host}/${tableName}`);
|
|
138
143
|
if (queryParams)
|
|
139
144
|
Object.entries(queryParams).forEach(([key, value]) => url.searchParams.append(key, value.toString()));
|
|
@@ -153,7 +158,7 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
153
158
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
154
159
|
*/
|
|
155
160
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
156
|
-
raw(rawInput,
|
|
161
|
+
raw(rawInput, ...args) {
|
|
157
162
|
return Promise.reject(new core_1.UnsupportedError("Api is not natively available for HttpAdapters. If required, please extends this class"));
|
|
158
163
|
}
|
|
159
164
|
/**
|
|
@@ -195,6 +200,36 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
195
200
|
parseCondition(condition) {
|
|
196
201
|
throw new core_1.UnsupportedError("Api is not natively available for HttpAdapters. If required, please extends this class");
|
|
197
202
|
}
|
|
203
|
+
static parseError(err,
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
205
|
+
...args) {
|
|
206
|
+
const msg = typeof err === "string" ? err : err.message;
|
|
207
|
+
if (msg.includes(db_decorators_1.NotFoundError.name))
|
|
208
|
+
return new db_decorators_1.NotFoundError(err);
|
|
209
|
+
if (msg.includes(db_decorators_1.ConflictError.name))
|
|
210
|
+
return new db_decorators_1.ConflictError(err);
|
|
211
|
+
if (msg.includes(db_decorators_1.BadRequestError.name))
|
|
212
|
+
return new db_decorators_1.BadRequestError(err);
|
|
213
|
+
if (msg.includes(core_1.QueryError.name))
|
|
214
|
+
return new core_1.QueryError(err);
|
|
215
|
+
if (msg.includes(core_1.PagingError.name))
|
|
216
|
+
return new core_1.PagingError(err);
|
|
217
|
+
if (msg.includes(core_1.UnsupportedError.name))
|
|
218
|
+
return new core_1.UnsupportedError(err);
|
|
219
|
+
if (msg.includes(core_1.MigrationError.name))
|
|
220
|
+
return new core_1.MigrationError(err);
|
|
221
|
+
if (msg.includes(core_1.ObserverError.name))
|
|
222
|
+
return new core_1.ObserverError(err);
|
|
223
|
+
if (msg.includes(core_1.AuthorizationError.name))
|
|
224
|
+
return new core_1.AuthorizationError(err);
|
|
225
|
+
if (msg.includes(core_1.ForbiddenError.name))
|
|
226
|
+
return new core_1.ForbiddenError(err);
|
|
227
|
+
if (msg.includes(core_1.ConnectionError.name))
|
|
228
|
+
return new core_1.ConnectionError(err);
|
|
229
|
+
if (msg.includes(db_decorators_1.SerializationError.name))
|
|
230
|
+
return new db_decorators_1.SerializationError(err);
|
|
231
|
+
return new db_decorators_1.InternalError(err);
|
|
232
|
+
}
|
|
198
233
|
}
|
|
199
234
|
exports.HttpAdapter = HttpAdapter;
|
|
200
235
|
//# sourceMappingURL=adapter.js.map
|
package/lib/adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Adapter, Condition, Repository, Sequence, SequenceOptions } from "@decaf-ts/core";
|
|
2
|
-
import { Context, OperationKeys } from "@decaf-ts/db-decorators";
|
|
1
|
+
import { Adapter, Condition, ContextualArgs, PreparedModel, Repository, Sequence, SequenceOptions } from "@decaf-ts/core";
|
|
2
|
+
import { BaseError, Context, FlagsOf, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
3
3
|
import { HttpConfig, HttpFlags } from "./types";
|
|
4
4
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
5
|
import { Constructor } from "@decaf-ts/decoration";
|
|
@@ -36,8 +36,8 @@ import { Statement } from "@decaf-ts/core";
|
|
|
36
36
|
* }
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare abstract class HttpAdapter<
|
|
40
|
-
protected constructor(config:
|
|
39
|
+
export declare abstract class HttpAdapter<CONF extends HttpConfig, CON, Q, C extends Context<HttpFlags> = Context<HttpFlags>> extends Adapter<CONF, CON, Q, C> {
|
|
40
|
+
protected constructor(config: CONF, flavour: string, alias?: string);
|
|
41
41
|
/**
|
|
42
42
|
* @description Generates operation flags with HTTP headers
|
|
43
43
|
* @summary Extends the base flags method to include HTTP-specific headers for operations.
|
|
@@ -49,17 +49,17 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
49
49
|
* @param {Partial<F>} overrides - Optional flag overrides
|
|
50
50
|
* @return {F} The flags object with headers
|
|
51
51
|
*/
|
|
52
|
-
flags<M extends Model>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, model: Constructor<M>, overrides: Partial<
|
|
52
|
+
flags<M extends Model>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE, model: Constructor<M>, overrides: Partial<FlagsOf<C>>): Promise<import("@decaf-ts/core").FlagsOf<C>> & {
|
|
53
53
|
headers: {};
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
56
|
* @description Returns the repository constructor for this adapter
|
|
57
57
|
* @summary Provides the RestService class as the repository implementation for this HTTP adapter.
|
|
58
58
|
* This method is used to create repository instances that work with this adapter type.
|
|
59
|
-
* @template
|
|
60
|
-
* @return {Constructor<
|
|
59
|
+
* @template R - Repository subtype working with this adapter
|
|
60
|
+
* @return {Constructor<R>} The repository constructor
|
|
61
61
|
*/
|
|
62
|
-
repository<
|
|
62
|
+
repository<R extends Repository<any, Adapter<CONF, CON, Q, C>>>(): Constructor<R>;
|
|
63
63
|
/**
|
|
64
64
|
* @description Prepares a model for persistence
|
|
65
65
|
* @summary Converts a model instance into a format suitable for database storage,
|
|
@@ -67,13 +67,10 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
67
67
|
* @template M - The model type
|
|
68
68
|
* @param {M} model - The model instance to prepare
|
|
69
69
|
* @param pk - The primary key property name
|
|
70
|
+
* @param args
|
|
70
71
|
* @return The prepared data
|
|
71
72
|
*/
|
|
72
|
-
prepare<M extends Model>(model: M,
|
|
73
|
-
record: Record<string, any>;
|
|
74
|
-
id: string;
|
|
75
|
-
transient?: Record<string, any>;
|
|
76
|
-
};
|
|
73
|
+
prepare<M extends Model>(model: M, ...args: ContextualArgs<C>): PreparedModel;
|
|
77
74
|
/**
|
|
78
75
|
* @description Converts database data back into a model instance
|
|
79
76
|
* @summary Reconstructs a model instance from database data, handling column mapping
|
|
@@ -85,7 +82,8 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
85
82
|
* @param {string|number|bigint} id - The primary key value
|
|
86
83
|
* @return {M} The reconstructed model instance
|
|
87
84
|
*/
|
|
88
|
-
revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>,
|
|
85
|
+
revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<C>): M;
|
|
86
|
+
protected toTableName<M extends Model>(t: string | Constructor<M>): string;
|
|
89
87
|
/**
|
|
90
88
|
* @description Constructs a URL for API requests
|
|
91
89
|
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
@@ -94,7 +92,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
94
92
|
* @param {Record<string, string | number>} [queryParams] - Optional query parameters
|
|
95
93
|
* @return {string} The encoded URL string
|
|
96
94
|
*/
|
|
97
|
-
url(tableName: string
|
|
95
|
+
url<M extends Model>(tableName: string | Constructor<M>, queryParams?: Record<string, string | number>): string;
|
|
98
96
|
/**
|
|
99
97
|
* @description Sends an HTTP request
|
|
100
98
|
* @summary Abstract method that must be implemented by subclasses to send HTTP requests
|
|
@@ -114,7 +112,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
114
112
|
* @param {...any[]} args - Additional arguments
|
|
115
113
|
* @return {Promise<Record<string, any>>} A promise that resolves with the created resource
|
|
116
114
|
*/
|
|
117
|
-
abstract create(tableName: string, id:
|
|
115
|
+
abstract create<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
|
|
118
116
|
/**
|
|
119
117
|
* @description Retrieves a resource by ID
|
|
120
118
|
* @summary Abstract method that must be implemented by subclasses to retrieve a resource
|
|
@@ -124,7 +122,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
124
122
|
* @param {...any[]} args - Additional arguments
|
|
125
123
|
* @return {Promise<Record<string, any>>} A promise that resolves with the retrieved resource
|
|
126
124
|
*/
|
|
127
|
-
abstract read(tableName: string, id:
|
|
125
|
+
abstract read<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
|
|
128
126
|
/**
|
|
129
127
|
* @description Updates an existing resource
|
|
130
128
|
* @summary Abstract method that must be implemented by subclasses to update a resource
|
|
@@ -135,7 +133,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
135
133
|
* @param {...any[]} args - Additional arguments
|
|
136
134
|
* @return {Promise<Record<string, any>>} A promise that resolves with the updated resource
|
|
137
135
|
*/
|
|
138
|
-
abstract update(tableName: string, id: string | number, model: Record<string, any>, ...args:
|
|
136
|
+
abstract update<M extends Model>(tableName: Constructor<M> | string, id: string | number, model: Record<string, any>, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
|
|
139
137
|
/**
|
|
140
138
|
* @description Deletes a resource by ID
|
|
141
139
|
* @summary Abstract method that must be implemented by subclasses to delete a resource
|
|
@@ -145,7 +143,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
145
143
|
* @param {...any[]} args - Additional arguments
|
|
146
144
|
* @return {Promise<Record<string, any>>} A promise that resolves with the deletion result
|
|
147
145
|
*/
|
|
148
|
-
abstract delete(tableName: string, id:
|
|
146
|
+
abstract delete<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, ...args: ContextualArgs<C>): Promise<Record<string, any>>;
|
|
149
147
|
/**
|
|
150
148
|
* @description Executes a raw query
|
|
151
149
|
* @summary Method for executing raw queries directly with the HTTP client.
|
|
@@ -158,7 +156,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
158
156
|
* @return {Promise<R>} A promise that resolves with the query result
|
|
159
157
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
160
158
|
*/
|
|
161
|
-
raw<R>(rawInput: Q,
|
|
159
|
+
raw<R>(rawInput: Q, ...args: ContextualArgs<C>): Promise<R>;
|
|
162
160
|
/**
|
|
163
161
|
* @description Creates a sequence
|
|
164
162
|
* @summary Method for creating a sequence for generating unique identifiers.
|
|
@@ -179,7 +177,7 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
179
177
|
* @return {Statement<Q, M, any>} A statement object for building queries
|
|
180
178
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
181
179
|
*/
|
|
182
|
-
Statement<M extends Model>(): Statement<
|
|
180
|
+
Statement<M extends Model>(): Statement<M, Adapter<CONF, CON, Q, C>, any>;
|
|
183
181
|
/**
|
|
184
182
|
* @description Parses a condition into a query
|
|
185
183
|
* @summary Method for parsing a condition object into a query format understood by the HTTP client.
|
|
@@ -190,4 +188,5 @@ export declare abstract class HttpAdapter<Y extends HttpConfig, CON, Q, F extend
|
|
|
190
188
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
191
189
|
*/
|
|
192
190
|
parseCondition(condition: Condition<any>): Q;
|
|
191
|
+
static parseError<E extends BaseError>(err: Error | string, ...args: any[]): E;
|
|
193
192
|
}
|
package/lib/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;;AAAA,yCAiBwB;AACxB,2DAWiC;AAEjC,yEAAuD;AAEvD,mDAA4C;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAsB,WAKpB,SAAQ,cAAwB;IAChC,YAAsB,MAAY,EAAE,OAAe,EAAE,KAAc;QACjE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;;;;;OAUG;IACM,KAAK,CACZ,SAIwB,EACxB,KAAqB,EACrB,SAA8B;QAE9B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAI,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE;YAChE,OAAO,EAAE,EAAE;SACZ,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACM,UAAU;QAGjB,OAAO,yBAAwC,CAAC;IAClD,CAAC;IAED;;;;;;;;;OASG;IACM,OAAO,CACd,KAAQ,EACR,GAAG,IAAuB;QAE1B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,CA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
const axios_1 = require("axios");
|
|
6
|
-
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
7
6
|
const constants_1 = require("./constants.cjs");
|
|
8
|
-
const core_1 = require("@decaf-ts/core");
|
|
9
7
|
/**
|
|
10
8
|
* @description Axios implementation of the HTTP adapter
|
|
11
9
|
* @summary Concrete implementation of HttpAdapter using Axios as the HTTP client.
|
|
@@ -82,7 +80,9 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
82
80
|
* @param {Record<string, any>} model - The data model to create
|
|
83
81
|
* @return {Promise<Record<string, any>>} A promise that resolves with the created resource
|
|
84
82
|
*/
|
|
85
|
-
async create(tableName, id, model
|
|
83
|
+
async create(tableName, id, model,
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
|
+
..._args) {
|
|
86
86
|
try {
|
|
87
87
|
const url = this.url(tableName);
|
|
88
88
|
return this.client.post(url, model);
|
|
@@ -99,9 +99,13 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
99
99
|
* @param {string|number|bigint} id - The identifier for the resource to retrieve
|
|
100
100
|
* @return {Promise<Record<string, any>>} A promise that resolves with the retrieved resource
|
|
101
101
|
*/
|
|
102
|
-
async read(tableName, id
|
|
102
|
+
async read(tableName, id,
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
104
|
+
...args) {
|
|
103
105
|
try {
|
|
104
|
-
const url = this.url(tableName, {
|
|
106
|
+
const url = this.url(tableName, {
|
|
107
|
+
id: id,
|
|
108
|
+
});
|
|
105
109
|
return this.client.get(url);
|
|
106
110
|
}
|
|
107
111
|
catch (e) {
|
|
@@ -117,7 +121,9 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
117
121
|
* @param {Record<string, any>} model - The updated data model
|
|
118
122
|
* @return {Promise<Record<string, any>>} A promise that resolves with the updated resource
|
|
119
123
|
*/
|
|
120
|
-
async update(tableName, id, model
|
|
124
|
+
async update(tableName, id, model,
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
126
|
+
..._args) {
|
|
121
127
|
try {
|
|
122
128
|
const url = this.url(tableName);
|
|
123
129
|
return this.client.put(url, model);
|
|
@@ -134,28 +140,21 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
134
140
|
* @param {string|number|bigint} id - The identifier for the resource to delete
|
|
135
141
|
* @return {Promise<Record<string, any>>} A promise that resolves with the deletion result
|
|
136
142
|
*/
|
|
137
|
-
async delete(tableName, id
|
|
143
|
+
async delete(tableName, id,
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
|
+
..._args) {
|
|
138
146
|
try {
|
|
139
|
-
const url = this.url(tableName, {
|
|
147
|
+
const url = this.url(tableName, {
|
|
148
|
+
id: id,
|
|
149
|
+
});
|
|
140
150
|
return this.client.delete(url);
|
|
141
151
|
}
|
|
142
152
|
catch (e) {
|
|
143
153
|
throw this.parseError(e);
|
|
144
154
|
}
|
|
145
155
|
}
|
|
146
|
-
parseError(err) {
|
|
147
|
-
|
|
148
|
-
db_decorators_1.InternalError,
|
|
149
|
-
core_1.AuthorizationError,
|
|
150
|
-
db_decorators_1.ConflictError,
|
|
151
|
-
db_decorators_1.NotFoundError,
|
|
152
|
-
core_1.UnsupportedError,
|
|
153
|
-
];
|
|
154
|
-
for (const error of errs) {
|
|
155
|
-
if (err.message.includes(error.name))
|
|
156
|
-
return new error(err.message);
|
|
157
|
-
}
|
|
158
|
-
return new db_decorators_1.InternalError(err.message);
|
|
156
|
+
parseError(err, ...args) {
|
|
157
|
+
return adapter_1.HttpAdapter.parseError(err, ...args);
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
exports.AxiosHttpAdapter = AxiosHttpAdapter;
|
package/lib/axios/axios.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { HttpAdapter } from "../adapter";
|
|
|
2
2
|
import { Axios, AxiosRequestConfig } from "axios";
|
|
3
3
|
import { HttpConfig } from "../types";
|
|
4
4
|
import { AxiosFlags } from "./types";
|
|
5
|
-
import { BaseError, Context } from "@decaf-ts/db-decorators";
|
|
5
|
+
import { BaseError, Context, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
6
|
+
import { ContextualArgs } from "@decaf-ts/core";
|
|
7
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
8
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
6
9
|
/**
|
|
7
10
|
* @description Axios implementation of the HTTP adapter
|
|
8
11
|
* @summary Concrete implementation of HttpAdapter using Axios as the HTTP client.
|
|
@@ -50,7 +53,7 @@ import { BaseError, Context } from "@decaf-ts/db-decorators";
|
|
|
50
53
|
* Axios-->>AxiosHttpAdapter: Response Data
|
|
51
54
|
* AxiosHttpAdapter-->>Client: Resource Data
|
|
52
55
|
*/
|
|
53
|
-
export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, AxiosRequestConfig,
|
|
56
|
+
export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, AxiosRequestConfig, Context<AxiosFlags>> {
|
|
54
57
|
constructor(config: HttpConfig, alias?: string);
|
|
55
58
|
protected getClient(): Axios;
|
|
56
59
|
/**
|
|
@@ -71,7 +74,7 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
71
74
|
* @param {Record<string, any>} model - The data model to create
|
|
72
75
|
* @return {Promise<Record<string, any>>} A promise that resolves with the created resource
|
|
73
76
|
*/
|
|
74
|
-
create(tableName: string, id:
|
|
77
|
+
create<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, model: Record<string, any>, ..._args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
75
78
|
/**
|
|
76
79
|
* @description Retrieves a resource by ID via HTTP GET
|
|
77
80
|
* @summary Implementation of the abstract read method from HttpAdapter.
|
|
@@ -80,7 +83,7 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
80
83
|
* @param {string|number|bigint} id - The identifier for the resource to retrieve
|
|
81
84
|
* @return {Promise<Record<string, any>>} A promise that resolves with the retrieved resource
|
|
82
85
|
*/
|
|
83
|
-
read(tableName: string, id:
|
|
86
|
+
read<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, ...args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
84
87
|
/**
|
|
85
88
|
* @description Updates an existing resource via HTTP PUT
|
|
86
89
|
* @summary Implementation of the abstract update method from HttpAdapter.
|
|
@@ -90,7 +93,7 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
90
93
|
* @param {Record<string, any>} model - The updated data model
|
|
91
94
|
* @return {Promise<Record<string, any>>} A promise that resolves with the updated resource
|
|
92
95
|
*/
|
|
93
|
-
update(tableName: string, id: string | number, model: Record<string, any
|
|
96
|
+
update<M extends Model>(tableName: Constructor<M> | string, id: string | number, model: Record<string, any>, ..._args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
94
97
|
/**
|
|
95
98
|
* @description Deletes a resource by ID via HTTP DELETE
|
|
96
99
|
* @summary Implementation of the abstract delete method from HttpAdapter.
|
|
@@ -99,6 +102,6 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
99
102
|
* @param {string|number|bigint} id - The identifier for the resource to delete
|
|
100
103
|
* @return {Promise<Record<string, any>>} A promise that resolves with the deletion result
|
|
101
104
|
*/
|
|
102
|
-
delete(tableName: string, id:
|
|
103
|
-
parseError(err: Error):
|
|
105
|
+
delete<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, ..._args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
106
|
+
parseError<E extends BaseError>(err: Error, ...args: any[]): E;
|
|
104
107
|
}
|
package/lib/axios/axios.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../src/axios/axios.ts"],"names":[],"mappings":";;;AAAA,8CAAyC;AACzC,iCAAkD;
|
|
1
|
+
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../src/axios/axios.ts"],"names":[],"mappings":";;;AAAA,8CAAyC;AACzC,iCAAkD;AAKlD,+CAA2C;AAI3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAa,gBAAiB,SAAQ,qBAKrC;IACC,YAAY,MAAkB,EAAE,KAAc;QAC5C,KAAK,CAAC,MAAM,EAAE,wBAAY,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAEkB,SAAS;QAC1B,OAAO,IAAI,aAAK,CAAC;YACf,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;SACnC,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACM,KAAK,CAAC,OAAO,CAAI,OAA2B;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACM,KAAK,CAAC,MAAM,CACnB,SAAkC,EAClC,EAAkB,EAClB,KAA0B;IAC1B,6DAA6D;IAC7D,GAAG,KAA0C;QAE7C,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IACD;;;;;;;OAOG;IACM,KAAK,CAAC,IAAI,CACjB,SAAkC,EAClC,EAAkB;IAClB,6DAA6D;IAC7D,GAAG,IAAyC;QAE5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CAAC;IAC9C,CAAC;CACF;AA9HD,4CA8HC"}
|
|
@@ -2,8 +2,6 @@ import { Repository } from "@decaf-ts/core";
|
|
|
2
2
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { Constructor } from "@decaf-ts/decoration";
|
|
4
4
|
import { HttpAdapter } from "./adapter";
|
|
5
|
-
import { Context } from "@decaf-ts/db-decorators";
|
|
6
|
-
import { HttpFlags } from "./types";
|
|
7
5
|
/**
|
|
8
6
|
* @description Repository for REST API interactions
|
|
9
7
|
* @summary A specialized repository implementation for interacting with REST APIs.
|
|
@@ -33,8 +31,8 @@ import { HttpFlags } from "./types";
|
|
|
33
31
|
* ```
|
|
34
32
|
* @see {@link RestService}
|
|
35
33
|
*/
|
|
36
|
-
export declare class RestRepository<M extends Model,
|
|
34
|
+
export declare class RestRepository<M extends Model, A extends HttpAdapter<any, any, any, any>, Q = A extends HttpAdapter<any, any, infer Q, any> ? Q : never> extends Repository<M, A> {
|
|
37
35
|
constructor(adapter: A, clazz?: Constructor<M>);
|
|
38
|
-
url(path: string
|
|
39
|
-
request<
|
|
36
|
+
url(path: string | Constructor<M>, queryParams?: Record<string, string | number>): string;
|
|
37
|
+
request<R>(details: Q): Promise<R>;
|
|
40
38
|
}
|