@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/esm/adapter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Adapter, PersistenceKeys, UnsupportedError, } from "@decaf-ts/core";
|
|
2
|
-
import { InternalError } from "@decaf-ts/db-decorators";
|
|
1
|
+
import { Adapter, AuthorizationError, ConnectionError, ForbiddenError, MigrationError, ObserverError, PagingError, PersistenceKeys, QueryError, UnsupportedError, } from "@decaf-ts/core";
|
|
2
|
+
import { BadRequestError, ConflictError, InternalError, NotFoundError, SerializationError, } from "@decaf-ts/db-decorators";
|
|
3
3
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
4
|
import { RestService } from "./RestService.js";
|
|
5
5
|
/**
|
|
@@ -58,8 +58,8 @@ export class HttpAdapter extends Adapter {
|
|
|
58
58
|
* @description Returns the repository constructor for this adapter
|
|
59
59
|
* @summary Provides the RestService class as the repository implementation for this HTTP adapter.
|
|
60
60
|
* This method is used to create repository instances that work with this adapter type.
|
|
61
|
-
* @template
|
|
62
|
-
* @return {Constructor<
|
|
61
|
+
* @template R - Repository subtype working with this adapter
|
|
62
|
+
* @return {Constructor<R>} The repository constructor
|
|
63
63
|
*/
|
|
64
64
|
repository() {
|
|
65
65
|
return RestService;
|
|
@@ -71,10 +71,11 @@ export class HttpAdapter extends Adapter {
|
|
|
71
71
|
* @template M - The model type
|
|
72
72
|
* @param {M} model - The model instance to prepare
|
|
73
73
|
* @param pk - The primary key property name
|
|
74
|
+
* @param args
|
|
74
75
|
* @return The prepared data
|
|
75
76
|
*/
|
|
76
|
-
prepare(model,
|
|
77
|
-
const log = this.
|
|
77
|
+
prepare(model, ...args) {
|
|
78
|
+
const { log } = this.logCtx(args, this.prepare);
|
|
78
79
|
const result = Object.assign({}, model);
|
|
79
80
|
if (model[PersistenceKeys.METADATA]) {
|
|
80
81
|
log.silly(`Passing along persistence metadata for ${model[PersistenceKeys.METADATA]}`);
|
|
@@ -87,7 +88,7 @@ export class HttpAdapter extends Adapter {
|
|
|
87
88
|
}
|
|
88
89
|
return {
|
|
89
90
|
record: model,
|
|
90
|
-
id: model[pk],
|
|
91
|
+
id: model[Model.pk(model.constructor)],
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
@@ -101,8 +102,8 @@ export class HttpAdapter extends Adapter {
|
|
|
101
102
|
* @param {string|number|bigint} id - The primary key value
|
|
102
103
|
* @return {M} The reconstructed model instance
|
|
103
104
|
*/
|
|
104
|
-
revert(obj, clazz,
|
|
105
|
-
const log = this.
|
|
105
|
+
revert(obj, clazz, id, ...args) {
|
|
106
|
+
const { log } = this.logCtx(args, this.revert);
|
|
106
107
|
const ob = {};
|
|
107
108
|
const m = (typeof clazz === "string" ? Model.build(ob, clazz) : new clazz(ob));
|
|
108
109
|
log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
|
|
@@ -122,6 +123,9 @@ export class HttpAdapter extends Adapter {
|
|
|
122
123
|
}
|
|
123
124
|
return result;
|
|
124
125
|
}
|
|
126
|
+
toTableName(t) {
|
|
127
|
+
return typeof t === "string" ? t : Model.tableName(t);
|
|
128
|
+
}
|
|
125
129
|
/**
|
|
126
130
|
* @description Constructs a URL for API requests
|
|
127
131
|
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
@@ -131,6 +135,7 @@ export class HttpAdapter extends Adapter {
|
|
|
131
135
|
* @return {string} The encoded URL string
|
|
132
136
|
*/
|
|
133
137
|
url(tableName, queryParams) {
|
|
138
|
+
tableName = this.toTableName(tableName);
|
|
134
139
|
const url = new URL(`${this.config.protocol}://${this.config.host}/${tableName}`);
|
|
135
140
|
if (queryParams)
|
|
136
141
|
Object.entries(queryParams).forEach(([key, value]) => url.searchParams.append(key, value.toString()));
|
|
@@ -150,7 +155,7 @@ export class HttpAdapter extends Adapter {
|
|
|
150
155
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
151
156
|
*/
|
|
152
157
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
-
raw(rawInput,
|
|
158
|
+
raw(rawInput, ...args) {
|
|
154
159
|
return Promise.reject(new UnsupportedError("Api is not natively available for HttpAdapters. If required, please extends this class"));
|
|
155
160
|
}
|
|
156
161
|
/**
|
|
@@ -192,5 +197,35 @@ export class HttpAdapter extends Adapter {
|
|
|
192
197
|
parseCondition(condition) {
|
|
193
198
|
throw new UnsupportedError("Api is not natively available for HttpAdapters. If required, please extends this class");
|
|
194
199
|
}
|
|
200
|
+
static parseError(err,
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
202
|
+
...args) {
|
|
203
|
+
const msg = typeof err === "string" ? err : err.message;
|
|
204
|
+
if (msg.includes(NotFoundError.name))
|
|
205
|
+
return new NotFoundError(err);
|
|
206
|
+
if (msg.includes(ConflictError.name))
|
|
207
|
+
return new ConflictError(err);
|
|
208
|
+
if (msg.includes(BadRequestError.name))
|
|
209
|
+
return new BadRequestError(err);
|
|
210
|
+
if (msg.includes(QueryError.name))
|
|
211
|
+
return new QueryError(err);
|
|
212
|
+
if (msg.includes(PagingError.name))
|
|
213
|
+
return new PagingError(err);
|
|
214
|
+
if (msg.includes(UnsupportedError.name))
|
|
215
|
+
return new UnsupportedError(err);
|
|
216
|
+
if (msg.includes(MigrationError.name))
|
|
217
|
+
return new MigrationError(err);
|
|
218
|
+
if (msg.includes(ObserverError.name))
|
|
219
|
+
return new ObserverError(err);
|
|
220
|
+
if (msg.includes(AuthorizationError.name))
|
|
221
|
+
return new AuthorizationError(err);
|
|
222
|
+
if (msg.includes(ForbiddenError.name))
|
|
223
|
+
return new ForbiddenError(err);
|
|
224
|
+
if (msg.includes(ConnectionError.name))
|
|
225
|
+
return new ConnectionError(err);
|
|
226
|
+
if (msg.includes(SerializationError.name))
|
|
227
|
+
return new SerializationError(err);
|
|
228
|
+
return new InternalError(err);
|
|
229
|
+
}
|
|
195
230
|
}
|
|
196
231
|
//# sourceMappingURL=adapter.js.map
|
package/lib/esm/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,kBAAkB,EAElB,eAAe,EAEf,cAAc,EACd,cAAc,EACd,aAAa,EACb,WAAW,EACX,eAAe,EAEf,UAAU,EAIV,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAA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I,CAAC;YAAE,OAAO,IAAI,cAAc,CAAC,GAAG,CAAM,CAAC;QAC3E,IAAI,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,aAAa,CAAC,GAAG,CAAM,CAAC;QACzE,IAAI,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC;YACvC,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAM,CAAC;QAC1C,IAAI,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,cAAc,CAAC,GAAG,CAAM,CAAC;QAC3E,IAAI,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC;YACpC,OAAO,IAAI,eAAe,CAAC,GAAG,CAAM,CAAC;QACvC,IAAI,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC;YACvC,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAM,CAAC;QAC1C,OAAO,IAAI,aAAa,CAAC,GAAG,CAAM,CAAC;IACrC,CAAC;CACF"}
|
package/lib/esm/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/esm/axios/axios.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { HttpAdapter } from "./../adapter.js";
|
|
2
2
|
import { Axios } from "axios";
|
|
3
|
-
import { ConflictError, InternalError, NotFoundError, } from "@decaf-ts/db-decorators";
|
|
4
3
|
import { AxiosFlavour } from "./constants.js";
|
|
5
|
-
import { AuthorizationError, UnsupportedError } from "@decaf-ts/core";
|
|
6
4
|
/**
|
|
7
5
|
* @description Axios implementation of the HTTP adapter
|
|
8
6
|
* @summary Concrete implementation of HttpAdapter using Axios as the HTTP client.
|
|
@@ -79,7 +77,9 @@ export class AxiosHttpAdapter extends HttpAdapter {
|
|
|
79
77
|
* @param {Record<string, any>} model - The data model to create
|
|
80
78
|
* @return {Promise<Record<string, any>>} A promise that resolves with the created resource
|
|
81
79
|
*/
|
|
82
|
-
async create(tableName, id, model
|
|
80
|
+
async create(tableName, id, model,
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
|
+
..._args) {
|
|
83
83
|
try {
|
|
84
84
|
const url = this.url(tableName);
|
|
85
85
|
return this.client.post(url, model);
|
|
@@ -96,9 +96,13 @@ export class AxiosHttpAdapter extends HttpAdapter {
|
|
|
96
96
|
* @param {string|number|bigint} id - The identifier for the resource to retrieve
|
|
97
97
|
* @return {Promise<Record<string, any>>} A promise that resolves with the retrieved resource
|
|
98
98
|
*/
|
|
99
|
-
async read(tableName, id
|
|
99
|
+
async read(tableName, id,
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
101
|
+
...args) {
|
|
100
102
|
try {
|
|
101
|
-
const url = this.url(tableName, {
|
|
103
|
+
const url = this.url(tableName, {
|
|
104
|
+
id: id,
|
|
105
|
+
});
|
|
102
106
|
return this.client.get(url);
|
|
103
107
|
}
|
|
104
108
|
catch (e) {
|
|
@@ -114,7 +118,9 @@ export class AxiosHttpAdapter extends HttpAdapter {
|
|
|
114
118
|
* @param {Record<string, any>} model - The updated data model
|
|
115
119
|
* @return {Promise<Record<string, any>>} A promise that resolves with the updated resource
|
|
116
120
|
*/
|
|
117
|
-
async update(tableName, id, model
|
|
121
|
+
async update(tableName, id, model,
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
123
|
+
..._args) {
|
|
118
124
|
try {
|
|
119
125
|
const url = this.url(tableName);
|
|
120
126
|
return this.client.put(url, model);
|
|
@@ -131,28 +137,21 @@ export class AxiosHttpAdapter extends HttpAdapter {
|
|
|
131
137
|
* @param {string|number|bigint} id - The identifier for the resource to delete
|
|
132
138
|
* @return {Promise<Record<string, any>>} A promise that resolves with the deletion result
|
|
133
139
|
*/
|
|
134
|
-
async delete(tableName, id
|
|
140
|
+
async delete(tableName, id,
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
142
|
+
..._args) {
|
|
135
143
|
try {
|
|
136
|
-
const url = this.url(tableName, {
|
|
144
|
+
const url = this.url(tableName, {
|
|
145
|
+
id: id,
|
|
146
|
+
});
|
|
137
147
|
return this.client.delete(url);
|
|
138
148
|
}
|
|
139
149
|
catch (e) {
|
|
140
150
|
throw this.parseError(e);
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
|
-
parseError(err) {
|
|
144
|
-
|
|
145
|
-
InternalError,
|
|
146
|
-
AuthorizationError,
|
|
147
|
-
ConflictError,
|
|
148
|
-
NotFoundError,
|
|
149
|
-
UnsupportedError,
|
|
150
|
-
];
|
|
151
|
-
for (const error of errs) {
|
|
152
|
-
if (err.message.includes(error.name))
|
|
153
|
-
return new error(err.message);
|
|
154
|
-
}
|
|
155
|
-
return new InternalError(err.message);
|
|
153
|
+
parseError(err, ...args) {
|
|
154
|
+
return HttpAdapter.parseError(err, ...args);
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
//# sourceMappingURL=axios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/axios/axios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAmB;AACzC,OAAO,EAAE,KAAK,EAAsB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/axios/axios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wBAAmB;AACzC,OAAO,EAAE,KAAK,EAAsB,MAAM,OAAO,CAAC;AAKlD,OAAO,EAAE,YAAY,EAAE,uBAAoB;AAI3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,OAAO,gBAAiB,SAAQ,WAKrC;IACC,YAAY,MAAkB,EAAE,KAAc;QAC5C,KAAK,CAAC,MAAM,EAAE,YAAY,EA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