@decaf-ts/for-http 0.3.3 → 0.3.5
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 +6 -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/HttpPaginator.cjs +69 -0
- package/lib/HttpPaginator.d.ts +10 -0
- package/lib/HttpPaginator.js.map +1 -0
- package/lib/HttpStatement.cjs +111 -0
- package/lib/HttpStatement.d.ts +9 -0
- package/lib/HttpStatement.js.map +1 -0
- package/lib/RestRepository.cjs +38 -4
- package/lib/RestRepository.d.ts +10 -4
- package/lib/RestRepository.js.map +1 -1
- package/lib/RestService.d.ts +1 -1
- package/lib/adapter.cjs +50 -9
- package/lib/adapter.d.ts +33 -10
- package/lib/adapter.js.map +1 -1
- package/lib/axios/axios.cjs +57 -15
- package/lib/axios/axios.d.ts +10 -7
- package/lib/axios/axios.js.map +1 -1
- package/lib/esm/HttpPaginator.d.ts +10 -0
- package/lib/esm/HttpPaginator.js +65 -0
- package/lib/esm/HttpPaginator.js.map +1 -0
- package/lib/esm/HttpStatement.d.ts +9 -0
- package/lib/esm/HttpStatement.js +107 -0
- package/lib/esm/HttpStatement.js.map +1 -0
- package/lib/esm/RestRepository.d.ts +10 -4
- package/lib/esm/RestRepository.js +39 -5
- package/lib/esm/RestRepository.js.map +1 -1
- package/lib/esm/RestService.d.ts +1 -1
- package/lib/esm/adapter.d.ts +33 -10
- package/lib/esm/adapter.js +51 -10
- package/lib/esm/adapter.js.map +1 -1
- package/lib/esm/axios/axios.d.ts +10 -7
- package/lib/esm/axios/axios.js +57 -15
- 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/esm/types.d.ts +7 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/types.d.ts +7 -0
- package/package.json +1 -1
package/lib/adapter.cjs
CHANGED
|
@@ -4,7 +4,11 @@ exports.HttpAdapter = void 0;
|
|
|
4
4
|
const core_1 = require("@decaf-ts/core");
|
|
5
5
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
6
6
|
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
7
|
+
const decoration_1 = require("@decaf-ts/decoration");
|
|
7
8
|
const RestService_1 = require("./RestService.cjs");
|
|
9
|
+
const core_2 = require("@decaf-ts/core");
|
|
10
|
+
const logging_1 = require("@decaf-ts/logging");
|
|
11
|
+
const HttpStatement_1 = require("./HttpStatement.cjs");
|
|
8
12
|
/**
|
|
9
13
|
* @description Abstract HTTP adapter for REST API interactions
|
|
10
14
|
* @summary Provides a base implementation for HTTP adapters with methods for CRUD operations,
|
|
@@ -52,8 +56,8 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
52
56
|
* @param {Partial<F>} overrides - Optional flag overrides
|
|
53
57
|
* @return {F} The flags object with headers
|
|
54
58
|
*/
|
|
55
|
-
flags(operation, model, overrides) {
|
|
56
|
-
return Object.assign(super.flags(operation, model, overrides), {
|
|
59
|
+
async flags(operation, model, overrides) {
|
|
60
|
+
return Object.assign(await super.flags(operation, model, overrides), {
|
|
57
61
|
headers: {},
|
|
58
62
|
});
|
|
59
63
|
}
|
|
@@ -127,19 +131,26 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
127
131
|
return result;
|
|
128
132
|
}
|
|
129
133
|
toTableName(t) {
|
|
130
|
-
return typeof t === "string" ? t : decorator_validation_1.Model.tableName(t);
|
|
134
|
+
return typeof t === "string" ? t : (0, logging_1.toKebabCase)(decorator_validation_1.Model.tableName(t));
|
|
131
135
|
}
|
|
132
136
|
/**
|
|
133
137
|
* @description Constructs a URL for API requests
|
|
134
138
|
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
135
139
|
* the specified table name, and optional query parameters. The method handles URL encoding.
|
|
136
|
-
* @param {string} tableName - The name of the table or endpoint
|
|
140
|
+
* @param {string | Constructor} tableName - The name of the table or endpoint
|
|
141
|
+
* @param {string[]} [pathParams] - Optional query parameters
|
|
137
142
|
* @param {Record<string, string | number>} [queryParams] - Optional query parameters
|
|
138
143
|
* @return {string} The encoded URL string
|
|
139
144
|
*/
|
|
140
|
-
url(tableName, queryParams) {
|
|
145
|
+
url(tableName, pathParams, queryParams) {
|
|
146
|
+
if (!queryParams) {
|
|
147
|
+
if (pathParams && !Array.isArray(pathParams)) {
|
|
148
|
+
queryParams = pathParams;
|
|
149
|
+
pathParams = [];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
141
152
|
tableName = this.toTableName(tableName);
|
|
142
|
-
const url = new URL(`${this.config.protocol}://${this.config.host}/${tableName}`);
|
|
153
|
+
const url = new URL(`${this.config.protocol}://${this.config.host}/${tableName}${pathParams && pathParams.length ? `/${pathParams.join("/")}` : ""}`);
|
|
143
154
|
if (queryParams)
|
|
144
155
|
Object.entries(queryParams).forEach(([key, value]) => url.searchParams.append(key, value.toString()));
|
|
145
156
|
// ensure spaces are encoded as %20 (not '+') to match expectations
|
|
@@ -157,9 +168,10 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
157
168
|
* @return {Promise<R>} A promise that resolves with the query result
|
|
158
169
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
159
170
|
*/
|
|
160
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
161
171
|
raw(rawInput, ...args) {
|
|
162
|
-
|
|
172
|
+
const { ctxArgs, ctx } = this.logCtx(args, this.raw);
|
|
173
|
+
const req = this.toRequest(rawInput, ctx);
|
|
174
|
+
return this.request(req, ...ctxArgs);
|
|
163
175
|
}
|
|
164
176
|
/**
|
|
165
177
|
* @description Creates a sequence
|
|
@@ -185,7 +197,7 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
185
197
|
* @throws {UnsupportedError} Always throws as this method is not supported by default
|
|
186
198
|
*/
|
|
187
199
|
Statement() {
|
|
188
|
-
|
|
200
|
+
return new HttpStatement_1.HttpStatement(this);
|
|
189
201
|
}
|
|
190
202
|
/**
|
|
191
203
|
* @description Parses a condition into a query
|
|
@@ -230,6 +242,35 @@ class HttpAdapter extends core_1.Adapter {
|
|
|
230
242
|
return new db_decorators_1.SerializationError(err);
|
|
231
243
|
return new db_decorators_1.InternalError(err);
|
|
232
244
|
}
|
|
245
|
+
static decoration() {
|
|
246
|
+
super.decoration();
|
|
247
|
+
function query(options) {
|
|
248
|
+
return function query(obj, prop, descriptor) {
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
250
|
+
function innerQuery(options) {
|
|
251
|
+
return function innerQuery(obj, propertyKey, descriptor) {
|
|
252
|
+
descriptor.value = new Proxy(descriptor.value, {
|
|
253
|
+
async apply(target, thisArg, args) {
|
|
254
|
+
const repo = thisArg;
|
|
255
|
+
const contextArgs = await db_decorators_1.Context.args(propertyKey, repo.class, args, repo["adapter"], repo["_overrides"] || {});
|
|
256
|
+
const { log, ctxArgs } = repo["logCtx"](contextArgs.args, target);
|
|
257
|
+
log.verbose(`Running prepared statement ${target.name}`);
|
|
258
|
+
log.debug(`With args: ${JSON.stringify(args, null, 2)}`);
|
|
259
|
+
return thisArg.statement(target.name, ...ctxArgs);
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return (0, decoration_1.apply)((0, decoration_1.methodMetadata)(decoration_1.Metadata.key(core_1.PersistenceKeys.QUERY, prop), options), (0, core_2.prepared)(), innerQuery(options))(obj, prop, descriptor);
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
decoration_1.Decoration.for(core_1.PersistenceKeys.QUERY)
|
|
268
|
+
.define({
|
|
269
|
+
decorator: query,
|
|
270
|
+
})
|
|
271
|
+
.apply();
|
|
272
|
+
}
|
|
233
273
|
}
|
|
234
274
|
exports.HttpAdapter = HttpAdapter;
|
|
275
|
+
HttpAdapter.decoration();
|
|
235
276
|
//# sourceMappingURL=adapter.js.map
|
package/lib/adapter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Adapter, Condition, ContextualArgs, PreparedModel, Repository, Sequence, SequenceOptions } from "@decaf-ts/core";
|
|
1
|
+
import { Adapter, Condition, ContextualArgs, MaybeContextualArg, PreparedModel, Repository, Sequence, SequenceOptions } from "@decaf-ts/core";
|
|
2
2
|
import { BaseError, Context, FlagsOf, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
3
|
-
import { HttpConfig, HttpFlags } from "./types";
|
|
3
|
+
import { HttpConfig, HttpFlags, HttpQuery } from "./types";
|
|
4
4
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
5
|
import { Constructor } from "@decaf-ts/decoration";
|
|
6
6
|
import { Statement } from "@decaf-ts/core";
|
|
@@ -36,7 +36,7 @@ import { Statement } from "@decaf-ts/core";
|
|
|
36
36
|
* }
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare abstract class HttpAdapter<CONF extends HttpConfig, CON, Q, C extends Context<HttpFlags> = Context<HttpFlags>> extends Adapter<CONF, CON, Q, C> {
|
|
39
|
+
export declare abstract class HttpAdapter<CONF extends HttpConfig, CON, REQ, Q extends HttpQuery = HttpQuery, C extends Context<HttpFlags> = Context<HttpFlags>> extends Adapter<CONF, CON, Q, C> {
|
|
40
40
|
protected constructor(config: CONF, flavour: string, alias?: string);
|
|
41
41
|
/**
|
|
42
42
|
* @description Generates operation flags with HTTP headers
|
|
@@ -49,9 +49,9 @@ export declare abstract class HttpAdapter<CONF extends HttpConfig, CON, Q, C ext
|
|
|
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<FlagsOf<C>>): Promise<import("@decaf-ts/core").FlagsOf<C
|
|
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.
|
|
@@ -88,20 +88,42 @@ export declare abstract class HttpAdapter<CONF extends HttpConfig, CON, Q, C ext
|
|
|
88
88
|
* @description Constructs a URL for API requests
|
|
89
89
|
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
90
90
|
* the specified table name, and optional query parameters. The method handles URL encoding.
|
|
91
|
-
* @param {string} tableName - The name of the table or endpoint
|
|
92
|
-
* @
|
|
91
|
+
* @param {string | Constructor} tableName - The name of the table or endpoint
|
|
92
|
+
* @return {string} The encoded URL string
|
|
93
|
+
*/
|
|
94
|
+
url<M extends Model>(tableName: string | Constructor<M>): string;
|
|
95
|
+
/**
|
|
96
|
+
* @description Constructs a URL for API requests
|
|
97
|
+
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
98
|
+
* the specified table name, and optional query parameters. The method handles URL encoding.
|
|
99
|
+
* @param {string | Constructor} tableName - The name of the table or endpoint
|
|
100
|
+
* @param {string[]} pathParams - Optional query parameters
|
|
101
|
+
* @return {string} The encoded URL string
|
|
102
|
+
*/
|
|
103
|
+
url<M extends Model>(tableName: string | Constructor<M>, pathParams: string[]): string;
|
|
104
|
+
/**
|
|
105
|
+
* @description Constructs a URL for API requests
|
|
106
|
+
* @summary Builds a complete URL for API requests using the configured protocol and host,
|
|
107
|
+
* the specified table name, and optional query parameters. The method handles URL encoding.
|
|
108
|
+
* @param {string | Constructor} tableName - The name of the table or endpoint
|
|
109
|
+
* @param {Record<string, string | number>} queryParams - Optional query parameters
|
|
93
110
|
* @return {string} The encoded URL string
|
|
94
111
|
*/
|
|
95
|
-
url<M extends Model>(tableName: string | Constructor<M>, queryParams
|
|
112
|
+
url<M extends Model>(tableName: string | Constructor<M>, queryParams: Record<string, string | number>): string;
|
|
113
|
+
url<M extends Model>(tableName: string | Constructor<M>, pathParams: string[], queryParams: Record<string, string | number>): string;
|
|
114
|
+
abstract toRequest(query: Q): REQ;
|
|
115
|
+
abstract toRequest(ctx: C): REQ;
|
|
116
|
+
abstract toRequest(query: Q, ctx: C): REQ;
|
|
117
|
+
abstract toRequest(ctxOrQuery: C | Q, ctx?: C): REQ;
|
|
96
118
|
/**
|
|
97
119
|
* @description Sends an HTTP request
|
|
98
120
|
* @summary Abstract method that must be implemented by subclasses to send HTTP requests
|
|
99
121
|
* using the native HTTP client. This is the core method for making API calls.
|
|
100
122
|
* @template V - The response value type
|
|
101
|
-
* @param {
|
|
123
|
+
* @param {REQ} details - The request details specific to the HTTP client
|
|
102
124
|
* @return {Promise<V>} A promise that resolves with the response data
|
|
103
125
|
*/
|
|
104
|
-
abstract request<V>(details:
|
|
126
|
+
abstract request<V>(details: REQ, ...args: MaybeContextualArg<C>): Promise<V>;
|
|
105
127
|
/**
|
|
106
128
|
* @description Creates a new resource
|
|
107
129
|
* @summary Abstract method that must be implemented by subclasses to create a new resource
|
|
@@ -189,4 +211,5 @@ export declare abstract class HttpAdapter<CONF extends HttpConfig, CON, Q, C ext
|
|
|
189
211
|
*/
|
|
190
212
|
parseCondition(condition: Condition<any>): Q;
|
|
191
213
|
static parseError<E extends BaseError>(err: Error | string, ...args: any[]): E;
|
|
214
|
+
static decoration(): void;
|
|
192
215
|
}
|
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,yCAkBwB;A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CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;YAC3B,CAAC,CAAC;QACJ,CAAC;QAED,uBAAU,CAAC,GAAG,CAAC,sBAAe,CAAC,KAAK,CAAC;aAClC,MAAM,CAAC;YACN,SAAS,EAAE,KAAK;SACV,CAAC;aACR,KAAK,EAAE,CAAC;IACb,CAAC;CACF;AAnbD,kCAmbC;AAED,WAAW,CAAC,UAAU,EAAE,CAAC"}
|
package/lib/axios/axios.cjs
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AxiosHttpAdapter = void 0;
|
|
4
4
|
const adapter_1 = require("./../adapter.cjs");
|
|
5
5
|
const axios_1 = require("axios");
|
|
6
|
+
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
7
|
+
const core_1 = require("@decaf-ts/core");
|
|
6
8
|
const constants_1 = require("./constants.cjs");
|
|
7
9
|
/**
|
|
8
10
|
* @description Axios implementation of the HTTP adapter
|
|
@@ -60,6 +62,33 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
60
62
|
baseURL: `${this.config.protocol}://${this.config.host}`,
|
|
61
63
|
});
|
|
62
64
|
}
|
|
65
|
+
toRequest(ctxOrQuery, ctx) {
|
|
66
|
+
let query;
|
|
67
|
+
let context;
|
|
68
|
+
if (ctxOrQuery instanceof db_decorators_1.Context) {
|
|
69
|
+
context = ctxOrQuery;
|
|
70
|
+
query = undefined; // In this overload, ctx is actually the query
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
query = ctxOrQuery;
|
|
74
|
+
context = ctx;
|
|
75
|
+
}
|
|
76
|
+
const req = {};
|
|
77
|
+
if (context) {
|
|
78
|
+
try {
|
|
79
|
+
req.headers = context.get("headers") || {};
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
// do nothing
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (query) {
|
|
87
|
+
req.method = "GET";
|
|
88
|
+
req.url = this.url(query.class, [core_1.PersistenceKeys.STATEMENT, query.method, ...query.args], query.params);
|
|
89
|
+
}
|
|
90
|
+
return req;
|
|
91
|
+
}
|
|
63
92
|
/**
|
|
64
93
|
* @description Sends an HTTP request using Axios
|
|
65
94
|
* @summary Implementation of the abstract request method from HttpAdapter.
|
|
@@ -68,8 +97,17 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
68
97
|
* @param {AxiosRequestConfig} details - The Axios request configuration
|
|
69
98
|
* @return {Promise<V>} A promise that resolves with the response data
|
|
70
99
|
*/
|
|
71
|
-
async request(details) {
|
|
72
|
-
|
|
100
|
+
async request(details, ...args) {
|
|
101
|
+
let overrides = {};
|
|
102
|
+
try {
|
|
103
|
+
const { ctx } = this.logCtx(args, this.request);
|
|
104
|
+
overrides = this.toRequest(ctx);
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
// do nothing
|
|
109
|
+
}
|
|
110
|
+
return this.client.request(Object.assign({}, details, overrides));
|
|
73
111
|
}
|
|
74
112
|
/**
|
|
75
113
|
* @description Creates a new resource via HTTP POST
|
|
@@ -80,12 +118,13 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
80
118
|
* @param {Record<string, any>} model - The data model to create
|
|
81
119
|
* @return {Promise<Record<string, any>>} A promise that resolves with the created resource
|
|
82
120
|
*/
|
|
83
|
-
async create(tableName, id, model,
|
|
84
|
-
|
|
85
|
-
..._args) {
|
|
121
|
+
async create(tableName, id, model, ...args) {
|
|
122
|
+
const { log, ctx } = this.logCtx(args, this.create);
|
|
86
123
|
try {
|
|
87
124
|
const url = this.url(tableName);
|
|
88
|
-
|
|
125
|
+
const cfg = this.toRequest(ctx);
|
|
126
|
+
log.debug(`POSTing to ${url} with ${JSON.stringify(model)} and cfg ${JSON.stringify(cfg)}`);
|
|
127
|
+
return this.client.post(url, model, cfg);
|
|
89
128
|
}
|
|
90
129
|
catch (e) {
|
|
91
130
|
throw this.parseError(e);
|
|
@@ -99,13 +138,14 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
99
138
|
* @param {string|number|bigint} id - The identifier for the resource to retrieve
|
|
100
139
|
* @return {Promise<Record<string, any>>} A promise that resolves with the retrieved resource
|
|
101
140
|
*/
|
|
102
|
-
async read(tableName, id,
|
|
103
|
-
|
|
104
|
-
...args) {
|
|
141
|
+
async read(tableName, id, ...args) {
|
|
142
|
+
const { log, ctx } = this.logCtx(args, this.read);
|
|
105
143
|
try {
|
|
106
144
|
const url = this.url(tableName, {
|
|
107
145
|
id: id,
|
|
108
146
|
});
|
|
147
|
+
const cfg = this.toRequest(ctx);
|
|
148
|
+
log.debug(`GETing from ${url} and cfg ${JSON.stringify(cfg)}`);
|
|
109
149
|
return this.client.get(url);
|
|
110
150
|
}
|
|
111
151
|
catch (e) {
|
|
@@ -121,11 +161,12 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
121
161
|
* @param {Record<string, any>} model - The updated data model
|
|
122
162
|
* @return {Promise<Record<string, any>>} A promise that resolves with the updated resource
|
|
123
163
|
*/
|
|
124
|
-
async update(tableName, id, model,
|
|
125
|
-
|
|
126
|
-
..._args) {
|
|
164
|
+
async update(tableName, id, model, ...args) {
|
|
165
|
+
const { log, ctx } = this.logCtx(args, this.update);
|
|
127
166
|
try {
|
|
128
167
|
const url = this.url(tableName);
|
|
168
|
+
const cfg = this.toRequest(ctx);
|
|
169
|
+
log.debug(`PUTing to ${url} with ${JSON.stringify(model)} and cfg ${JSON.stringify(cfg)}`);
|
|
129
170
|
return this.client.put(url, model);
|
|
130
171
|
}
|
|
131
172
|
catch (e) {
|
|
@@ -140,13 +181,14 @@ class AxiosHttpAdapter extends adapter_1.HttpAdapter {
|
|
|
140
181
|
* @param {string|number|bigint} id - The identifier for the resource to delete
|
|
141
182
|
* @return {Promise<Record<string, any>>} A promise that resolves with the deletion result
|
|
142
183
|
*/
|
|
143
|
-
async delete(tableName, id,
|
|
144
|
-
|
|
145
|
-
..._args) {
|
|
184
|
+
async delete(tableName, id, ...args) {
|
|
185
|
+
const { log, ctx } = this.logCtx(args, this.delete);
|
|
146
186
|
try {
|
|
147
187
|
const url = this.url(tableName, {
|
|
148
188
|
id: id,
|
|
149
189
|
});
|
|
190
|
+
const cfg = this.toRequest(ctx);
|
|
191
|
+
log.debug(`DELETEing from ${url} and cfg ${JSON.stringify(cfg)}`);
|
|
150
192
|
return this.client.delete(url);
|
|
151
193
|
}
|
|
152
194
|
catch (e) {
|
package/lib/axios/axios.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { HttpAdapter } from "../adapter";
|
|
2
2
|
import { Axios, AxiosRequestConfig } from "axios";
|
|
3
|
-
import { HttpConfig } from "../types";
|
|
3
|
+
import { HttpConfig, HttpQuery } from "../types";
|
|
4
4
|
import { AxiosFlags } from "./types";
|
|
5
5
|
import { BaseError, Context, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
6
|
-
import { ContextualArgs } from "@decaf-ts/core";
|
|
6
|
+
import { ContextualArgs, MaybeContextualArg } from "@decaf-ts/core";
|
|
7
7
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
8
8
|
import { Constructor } from "@decaf-ts/decoration";
|
|
9
9
|
/**
|
|
@@ -53,9 +53,12 @@ import { Constructor } from "@decaf-ts/decoration";
|
|
|
53
53
|
* Axios-->>AxiosHttpAdapter: Response Data
|
|
54
54
|
* AxiosHttpAdapter-->>Client: Resource Data
|
|
55
55
|
*/
|
|
56
|
-
export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, AxiosRequestConfig, Context<AxiosFlags>> {
|
|
56
|
+
export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, AxiosRequestConfig, HttpQuery, Context<AxiosFlags>> {
|
|
57
57
|
constructor(config: HttpConfig, alias?: string);
|
|
58
58
|
protected getClient(): Axios;
|
|
59
|
+
toRequest(query: HttpQuery): AxiosRequestConfig;
|
|
60
|
+
toRequest(ctx: Context<AxiosFlags>): AxiosRequestConfig;
|
|
61
|
+
toRequest(query: HttpQuery, ctx: Context<AxiosFlags>): AxiosRequestConfig;
|
|
59
62
|
/**
|
|
60
63
|
* @description Sends an HTTP request using Axios
|
|
61
64
|
* @summary Implementation of the abstract request method from HttpAdapter.
|
|
@@ -64,7 +67,7 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
64
67
|
* @param {AxiosRequestConfig} details - The Axios request configuration
|
|
65
68
|
* @return {Promise<V>} A promise that resolves with the response data
|
|
66
69
|
*/
|
|
67
|
-
request<V>(details: AxiosRequestConfig): Promise<V>;
|
|
70
|
+
request<V>(details: AxiosRequestConfig, ...args: MaybeContextualArg<Context<AxiosFlags>>): Promise<V>;
|
|
68
71
|
/**
|
|
69
72
|
* @description Creates a new resource via HTTP POST
|
|
70
73
|
* @summary Implementation of the abstract create method from HttpAdapter.
|
|
@@ -74,7 +77,7 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
74
77
|
* @param {Record<string, any>} model - The data model to create
|
|
75
78
|
* @return {Promise<Record<string, any>>} A promise that resolves with the created resource
|
|
76
79
|
*/
|
|
77
|
-
create<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, model: Record<string, any>, ...
|
|
80
|
+
create<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
78
81
|
/**
|
|
79
82
|
* @description Retrieves a resource by ID via HTTP GET
|
|
80
83
|
* @summary Implementation of the abstract read method from HttpAdapter.
|
|
@@ -93,7 +96,7 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
93
96
|
* @param {Record<string, any>} model - The updated data model
|
|
94
97
|
* @return {Promise<Record<string, any>>} A promise that resolves with the updated resource
|
|
95
98
|
*/
|
|
96
|
-
update<M extends Model>(tableName: Constructor<M> | string, id:
|
|
99
|
+
update<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
97
100
|
/**
|
|
98
101
|
* @description Deletes a resource by ID via HTTP DELETE
|
|
99
102
|
* @summary Implementation of the abstract delete method from HttpAdapter.
|
|
@@ -102,6 +105,6 @@ export declare class AxiosHttpAdapter extends HttpAdapter<HttpConfig, Axios, Axi
|
|
|
102
105
|
* @param {string|number|bigint} id - The identifier for the resource to delete
|
|
103
106
|
* @return {Promise<Record<string, any>>} A promise that resolves with the deletion result
|
|
104
107
|
*/
|
|
105
|
-
delete<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, ...
|
|
108
|
+
delete<M extends Model>(tableName: Constructor<M> | string, id: PrimaryKeyType, ...args: ContextualArgs<Context<AxiosFlags>>): Promise<Record<string, any>>;
|
|
106
109
|
parseError<E extends BaseError>(err: Error, ...args: any[]): E;
|
|
107
110
|
}
|
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;AAGlD,2DAA6E;AAC7E,yCAIwB;AACxB,+CAA2C;AAI3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAa,gBAAiB,SAAQ,qBAMrC;IACC,YAAY,MAAkB,EAAE,KAAc;QAC5C,KAAK,CAAC,MAAM,EAAE,wBAAY,EAAE,KAAK,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ED;;;;;;;OAOG;IACM,KAAK,CAAC,MAAM,CACnB,SAAkC,EAClC,EAAkB,EAClB,GAAG,IAAyC;QAE5C,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACpD,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;gBAC9B,EAAE,EAAE,EAAqB;aAC1B,CAAC,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAChC,GAAG,CAAC,KAAK,CAAC,kBAAkB,GAAG,YAAY,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAEQ,UAAU,CAAsB,GAAU,EAAE,GAAG,IAAW;QACjE,OAAO,qBAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC;CACF;AA/LD,4CA+LC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Paginator } from "@decaf-ts/core";
|
|
2
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
+
import { HttpQuery } from "./types";
|
|
4
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
5
|
+
import { HttpAdapter } from "./adapter";
|
|
6
|
+
export declare class HttpPaginator<M extends Model, A extends HttpAdapter<any, any, any, HttpQuery, any>> extends Paginator<M, M, HttpQuery> {
|
|
7
|
+
constructor(adapter: A, query: HttpQuery, size: number, clazz: Constructor<M>);
|
|
8
|
+
page(page?: number, ...args: any[]): Promise<M[]>;
|
|
9
|
+
protected prepare(rawStatement: HttpQuery): HttpQuery;
|
|
10
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OrderDirection, Paginator, QueryClause } from "@decaf-ts/core";
|
|
2
|
+
import { Context, OperationKeys } from "@decaf-ts/db-decorators";
|
|
3
|
+
import { toCamelCase, toPascalCase } from "@decaf-ts/logging";
|
|
4
|
+
export class HttpPaginator extends Paginator {
|
|
5
|
+
constructor(adapter, query, size, clazz) {
|
|
6
|
+
super(adapter, query, size, clazz);
|
|
7
|
+
}
|
|
8
|
+
async page(page = 1, ...args) {
|
|
9
|
+
const contextArgs = await Context.args(OperationKeys.READ, this.clazz, args, this.adapter);
|
|
10
|
+
let statement = Object.assign({}, this.statement, {
|
|
11
|
+
args: [...this.statement.args],
|
|
12
|
+
params: { ...this.statement.params },
|
|
13
|
+
});
|
|
14
|
+
if (!this.statement.method.includes("pageBy"))
|
|
15
|
+
statement = this.prepare(statement);
|
|
16
|
+
statement.args.push(page);
|
|
17
|
+
page = this.validatePage(page);
|
|
18
|
+
const results = await this.adapter.raw(statement, ...contextArgs.args);
|
|
19
|
+
this._currentPage = page;
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
prepare(rawStatement) {
|
|
23
|
+
// only support main attr for now before implementing pageBy
|
|
24
|
+
let attrs = rawStatement.method.split(new RegExp(`(${[QueryClause.FIND_BY, QueryClause.SELECT, QueryClause.ORDER_BY, QueryClause.GROUP_BY, QueryClause.AND, QueryClause.OR].join("|")})`, "i"));
|
|
25
|
+
attrs = attrs
|
|
26
|
+
.map((s) => s.trim())
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.filter((s) => ![
|
|
29
|
+
QueryClause.FIND_BY,
|
|
30
|
+
QueryClause.SELECT,
|
|
31
|
+
QueryClause.ORDER_BY,
|
|
32
|
+
QueryClause.GROUP_BY,
|
|
33
|
+
toPascalCase(OrderDirection.ASC),
|
|
34
|
+
toPascalCase(OrderDirection.DSC),
|
|
35
|
+
].find((c) => s.includes(c)));
|
|
36
|
+
const fullOrderBy = rawStatement.method.split(QueryClause.ORDER_BY);
|
|
37
|
+
let orderBy;
|
|
38
|
+
if (fullOrderBy.length) {
|
|
39
|
+
orderBy = fullOrderBy[1]
|
|
40
|
+
.split(new RegExp(`${[toPascalCase(OrderDirection.ASC), toPascalCase(OrderDirection.DSC), QueryClause.GROUP_BY + ".*", QueryClause.THEN_BY].join("|")}`, "i"))
|
|
41
|
+
.map((s) => s.trim())
|
|
42
|
+
.filter(Boolean);
|
|
43
|
+
orderBy = [
|
|
44
|
+
orderBy[0],
|
|
45
|
+
fullOrderBy[1].includes(toPascalCase(OrderDirection.ASC))
|
|
46
|
+
? OrderDirection.ASC
|
|
47
|
+
: OrderDirection.DSC,
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
if (attrs.length === 1 && attrs[0] === orderBy[0]) {
|
|
51
|
+
const attr = attrs[0];
|
|
52
|
+
return Object.assign({}, rawStatement, {
|
|
53
|
+
method: "pageBy",
|
|
54
|
+
args: [toCamelCase(attr), orderBy[1], this.size],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return Object.assign({}, rawStatement, {
|
|
59
|
+
method: rawStatement.method.replace(QueryClause.FIND_BY, "pageBy"),
|
|
60
|
+
args: [...rawStatement.args, this.size],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=HttpPaginator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpPaginator.js","sourceRoot":"","sources":["../../src/HttpPaginator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKxE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAm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;YACnB,OAAO,GAAG;gBACR,OAAO,CAAC,CAAC,CAAQ;gBACjB,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;oBACvD,CAAC,CAAC,cAAc,CAAC,GAAG;oBACpB,CAAC,CAAC,cAAc,CAAC,GAAG;aACvB,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,YAAY,EAAE;gBACrC,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;aACjD,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,YAAY,EAAE;gBACrC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC;gBAClE,IAAI,EAAE,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;aACxC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Condition, ContextOf, MaybeContextualArg, Paginator, Statement } from "@decaf-ts/core";
|
|
2
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
+
import { HttpAdapter } from "./adapter";
|
|
4
|
+
export declare class HttpStatement<M extends Model, A extends HttpAdapter<any, any, any, any, any>, R> extends Statement<M, A, R, A extends HttpAdapter<any, any, any, infer Q, any> ? Q : never> {
|
|
5
|
+
constructor(adapter: A);
|
|
6
|
+
protected build(): A extends HttpAdapter<any, any, any, infer Q, any> ? Q : never;
|
|
7
|
+
paginate(size?: number, ...args: MaybeContextualArg<ContextOf<A>>): Promise<Paginator<M, R, A extends HttpAdapter<any, any, any, infer Q, any> ? Q : never>>;
|
|
8
|
+
protected parseCondition(condition: Condition<M>): A extends HttpAdapter<any, any, any, infer Q, any> ? Q : never;
|
|
9
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Condition, GroupOperator, Operator, QueryClause, QueryError, Statement, } from "@decaf-ts/core";
|
|
2
|
+
import { toCamelCase } from "@decaf-ts/logging";
|
|
3
|
+
import { HttpPaginator } from "./HttpPaginator.js";
|
|
4
|
+
import { InternalError } from "@decaf-ts/db-decorators";
|
|
5
|
+
export class HttpStatement extends Statement {
|
|
6
|
+
constructor(adapter) {
|
|
7
|
+
super(adapter);
|
|
8
|
+
}
|
|
9
|
+
build() {
|
|
10
|
+
const method = [QueryClause.FIND_BY];
|
|
11
|
+
const args = [];
|
|
12
|
+
const params = {};
|
|
13
|
+
if (this.whereCondition) {
|
|
14
|
+
const parsed = this.parseCondition(this.whereCondition);
|
|
15
|
+
method.push(parsed.method);
|
|
16
|
+
if (parsed.args && parsed.args.length)
|
|
17
|
+
args.push(...parsed.args);
|
|
18
|
+
}
|
|
19
|
+
if (this.selectSelector)
|
|
20
|
+
method.push(QueryClause.SELECT, this.selectSelector.join(` ${QueryClause.AND.toLowerCase()} `));
|
|
21
|
+
if (this.orderBySelector)
|
|
22
|
+
method.push(QueryClause.ORDER_BY, ...this.orderBySelector);
|
|
23
|
+
if (this.groupBySelector)
|
|
24
|
+
method.push(QueryClause.GROUP_BY, this.groupBySelector);
|
|
25
|
+
if (this.limitSelector)
|
|
26
|
+
params.limit = this.limitSelector;
|
|
27
|
+
if (this.offsetSelector) {
|
|
28
|
+
params.skip = this.offsetSelector;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
class: this.fromSelector,
|
|
32
|
+
method: toCamelCase(method.join(" ")),
|
|
33
|
+
args: args,
|
|
34
|
+
params: Object.keys(params).length ? params : undefined,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async paginate(size = 10,
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
...args) {
|
|
40
|
+
try {
|
|
41
|
+
const query = this.build();
|
|
42
|
+
return new HttpPaginator(this.adapter, query, size, this.fromSelector);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new InternalError(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
parseCondition(condition) {
|
|
49
|
+
// @ts-expect-error accessing protected properties
|
|
50
|
+
// eslint-disable-next-line prefer-const
|
|
51
|
+
let { attr1, operator, comparison } = condition;
|
|
52
|
+
const result = {};
|
|
53
|
+
switch (operator) {
|
|
54
|
+
case GroupOperator.AND:
|
|
55
|
+
case GroupOperator.OR: {
|
|
56
|
+
let side1 = attr1, side2 = comparison;
|
|
57
|
+
if (typeof attr1 !== "string") {
|
|
58
|
+
const condition1 = this.parseCondition(attr1);
|
|
59
|
+
side1 = condition1.method;
|
|
60
|
+
result.args = [...(result.args || []), ...(condition1.args || [])];
|
|
61
|
+
}
|
|
62
|
+
if (comparison instanceof Condition) {
|
|
63
|
+
const condition2 = this.parseCondition(comparison);
|
|
64
|
+
side2 = condition2.method;
|
|
65
|
+
result.args = [...(result.args || []), ...(condition2.args || [])];
|
|
66
|
+
}
|
|
67
|
+
result.method = `${side1} ${operator.toLowerCase()} ${side2}`;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case Operator.EQUAL:
|
|
71
|
+
result.method = attr1;
|
|
72
|
+
result.args = [...(result.args || []), comparison];
|
|
73
|
+
break;
|
|
74
|
+
case Operator.DIFFERENT:
|
|
75
|
+
result.method = `${attr1} diff`;
|
|
76
|
+
result.args = [...(result.args || []), comparison];
|
|
77
|
+
break;
|
|
78
|
+
case Operator.REGEXP:
|
|
79
|
+
result.method = `${attr1} matches`;
|
|
80
|
+
result.args = [...(result.args || []), comparison];
|
|
81
|
+
break;
|
|
82
|
+
case Operator.BIGGER:
|
|
83
|
+
result.method = `${attr1} bigger`;
|
|
84
|
+
result.args = [...(result.args || []), comparison];
|
|
85
|
+
break;
|
|
86
|
+
case Operator.BIGGER_EQ:
|
|
87
|
+
result.method = `${attr1} bigger than equal`;
|
|
88
|
+
break;
|
|
89
|
+
case Operator.SMALLER:
|
|
90
|
+
result.method = `${attr1} less`;
|
|
91
|
+
result.args = [...(result.args || []), comparison];
|
|
92
|
+
break;
|
|
93
|
+
case Operator.SMALLER_EQ:
|
|
94
|
+
result.method = `${attr1} less than equal`;
|
|
95
|
+
result.args = [...(result.args || []), comparison];
|
|
96
|
+
break;
|
|
97
|
+
case Operator.IN:
|
|
98
|
+
result.method = `${attr1} in`;
|
|
99
|
+
result.args = [...(result.args || []), comparison];
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw new QueryError(`Unsupported operator ${operator}`);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=HttpStatement.js.map
|