@xeno-js/core 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2078 -2251
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +573 -48
- package/dist/index.d.ts +573 -48
- package/dist/index.js +1882 -2057
- package/dist/index.js.map +1 -1
- package/package.json +8 -31
- package/dist/db.cjs +0 -149
- package/dist/db.cjs.map +0 -1
- package/dist/db.d.cts +0 -120
- package/dist/db.d.ts +0 -120
- package/dist/db.js +0 -120
- package/dist/db.js.map +0 -1
- package/dist/itoken-service.contracts-3GrRvKeZ.d.cts +0 -527
- package/dist/itoken-service.contracts-3GrRvKeZ.d.ts +0 -527
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xeno-js/core",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "A Typescript application framework architecture for Node.js with explicit dependency injection, DDD, CQRS and modular application boundaries",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/xeno-js/xeno-js.git"
|
|
@@ -19,11 +19,6 @@
|
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
21
|
"require": "./dist/index.cjs"
|
|
22
|
-
},
|
|
23
|
-
"./db": {
|
|
24
|
-
"types": "./dist/db.d.ts",
|
|
25
|
-
"import": "./dist/db.js",
|
|
26
|
-
"require": "./dist/db.cjs"
|
|
27
22
|
}
|
|
28
23
|
},
|
|
29
24
|
"files": [
|
|
@@ -48,9 +43,6 @@
|
|
|
48
43
|
"verify:commit": "npm run lint-staged && npm run test",
|
|
49
44
|
"verify:push": "npm run check",
|
|
50
45
|
"prepare": "husky",
|
|
51
|
-
"db:generate": "drizzle-kit generate",
|
|
52
|
-
"db:push": "drizzle-kit push",
|
|
53
|
-
"db:migrate": "drizzle-kit migrate",
|
|
54
46
|
"changelog": "npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
55
47
|
"prepublishOnly": "npm run check && npm run build",
|
|
56
48
|
"release:patch": "npm version patch && npm run changelog && npm run prepublishOnly && npm publish --access public",
|
|
@@ -59,7 +51,13 @@
|
|
|
59
51
|
},
|
|
60
52
|
"keywords": [
|
|
61
53
|
"typescript",
|
|
54
|
+
"javascript",
|
|
55
|
+
"xeno",
|
|
56
|
+
"xeno-js",
|
|
57
|
+
"xeno.js",
|
|
62
58
|
"nodejs",
|
|
59
|
+
"node.js",
|
|
60
|
+
"framework",
|
|
63
61
|
"application-framework",
|
|
64
62
|
"application-architecture",
|
|
65
63
|
"dependency-injection",
|
|
@@ -81,7 +79,6 @@
|
|
|
81
79
|
"node": ">=20.0.0"
|
|
82
80
|
},
|
|
83
81
|
"peerDependencies": {
|
|
84
|
-
"@libsql/client": "^0.14.0",
|
|
85
82
|
"@sentry/node": "^11.0.0",
|
|
86
83
|
"@supabase/ssr": "^0.12.7",
|
|
87
84
|
"@supabase/supabase-js": "^2.117.1",
|
|
@@ -89,19 +86,13 @@
|
|
|
89
86
|
"@xeno-js/shared": "^3.0.0",
|
|
90
87
|
"axios": "^1.20.0",
|
|
91
88
|
"cockatiel": "^4.0.0",
|
|
92
|
-
"drizzle-orm": "^0.45.3",
|
|
93
89
|
"fastify": "^5.12.5",
|
|
94
90
|
"ioredis": "^6.0.0",
|
|
95
91
|
"p-limit": "^7.3.3",
|
|
96
|
-
"pg": "^8.23.0",
|
|
97
92
|
"pino": "^10.3.1",
|
|
98
|
-
"postgres": "^3.4.9",
|
|
99
93
|
"zod": "^4.6.5"
|
|
100
94
|
},
|
|
101
95
|
"peerDependenciesMeta": {
|
|
102
|
-
"@libsql/client": {
|
|
103
|
-
"optional": true
|
|
104
|
-
},
|
|
105
96
|
"@sentry/node": {
|
|
106
97
|
"optional": true
|
|
107
98
|
},
|
|
@@ -120,9 +111,6 @@
|
|
|
120
111
|
"cockatiel": {
|
|
121
112
|
"optional": true
|
|
122
113
|
},
|
|
123
|
-
"drizzle-orm": {
|
|
124
|
-
"optional": true
|
|
125
|
-
},
|
|
126
114
|
"fastify": {
|
|
127
115
|
"optional": true
|
|
128
116
|
},
|
|
@@ -132,15 +120,9 @@
|
|
|
132
120
|
"p-limit": {
|
|
133
121
|
"optional": true
|
|
134
122
|
},
|
|
135
|
-
"pg": {
|
|
136
|
-
"optional": true
|
|
137
|
-
},
|
|
138
123
|
"pino": {
|
|
139
124
|
"optional": true
|
|
140
125
|
},
|
|
141
|
-
"postgres": {
|
|
142
|
-
"optional": true
|
|
143
|
-
},
|
|
144
126
|
"zod": {
|
|
145
127
|
"optional": true
|
|
146
128
|
}
|
|
@@ -149,7 +131,6 @@
|
|
|
149
131
|
"@commitlint/cli": "^21.2.3",
|
|
150
132
|
"@commitlint/config-conventional": "^21.2.3",
|
|
151
133
|
"@eslint/js": "^10.0.1",
|
|
152
|
-
"@libsql/client": "^0.18.0",
|
|
153
134
|
"@sentry/node": "^11.0.0",
|
|
154
135
|
"@supabase/ssr": "^0.12.7",
|
|
155
136
|
"@supabase/supabase-js": "^2.117.1",
|
|
@@ -163,8 +144,6 @@
|
|
|
163
144
|
"conventional-changelog-angular": "^9.4.0",
|
|
164
145
|
"conventional-changelog-cli": "^5.0.0",
|
|
165
146
|
"conventional-changelog-writer": "^9.2.1",
|
|
166
|
-
"drizzle-kit": "^0.31.11",
|
|
167
|
-
"drizzle-orm": "^0.45.3",
|
|
168
147
|
"eslint": "^10.11.0",
|
|
169
148
|
"eslint-config-prettier": "^10.1.8",
|
|
170
149
|
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
@@ -173,9 +152,7 @@
|
|
|
173
152
|
"ioredis": "^6.0.0",
|
|
174
153
|
"lint-staged": "^17.5.1",
|
|
175
154
|
"p-limit": "^7.3.3",
|
|
176
|
-
"pg": "^8.23.0",
|
|
177
155
|
"pino": "^10.3.1",
|
|
178
|
-
"postgres": "^3.4.9",
|
|
179
156
|
"prettier": "^3.9.9",
|
|
180
157
|
"tsc-alias": "^1.9.5",
|
|
181
158
|
"tsup": "^8.5.1",
|
package/dist/db.cjs
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/db.ts
|
|
21
|
-
var db_exports = {};
|
|
22
|
-
__export(db_exports, {
|
|
23
|
-
BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
|
|
24
|
-
BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
|
|
25
|
-
RemoteDataSource: () => RemoteDataSource
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(db_exports);
|
|
28
|
-
|
|
29
|
-
// src/infrastructure/datasources/base-postgressql.datasource.ts
|
|
30
|
-
var BasePostgresSqlDataSource = class {
|
|
31
|
-
constructor(_db) {
|
|
32
|
-
this._db = _db;
|
|
33
|
-
}
|
|
34
|
-
_db;
|
|
35
|
-
/**
|
|
36
|
-
* @description Returns the database connection.
|
|
37
|
-
* @returns {NodePgDatabase<TSchema>} The database connection.
|
|
38
|
-
*/
|
|
39
|
-
get db() {
|
|
40
|
-
return this._db;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// src/infrastructure/datasources/base-sqllite.datasource.ts
|
|
45
|
-
var BaseSqliteSqlDataSource = class {
|
|
46
|
-
constructor(_db) {
|
|
47
|
-
this._db = _db;
|
|
48
|
-
}
|
|
49
|
-
_db;
|
|
50
|
-
/**
|
|
51
|
-
* @description Returns the SQLite database connection.
|
|
52
|
-
* @returns {LibSQLDatabase<TSchema>} The database connection.
|
|
53
|
-
*/
|
|
54
|
-
get db() {
|
|
55
|
-
return this._db;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// src/infrastructure/datasources/remote.datasource.ts
|
|
60
|
-
var import_shared = require("@xeno-js/shared");
|
|
61
|
-
var RemoteDataSource = class {
|
|
62
|
-
/** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.
|
|
63
|
-
* These dependencies are injected into the class, allowing for greater flexibility and testability.
|
|
64
|
-
* The HTTP client is used to send requests to remote endpoints, while the resilience service is used to execute these requests with built-in support for retries, timeouts, and circuit breakers, ensuring that the remote calls are more resilient to failures and can recover gracefully from errors.
|
|
65
|
-
* @param _httpClient An instance of an agnostic HTTP client that implements the IHttpClient interface, used for sending HTTP requests to remote endpoints.
|
|
66
|
-
* @param _resilienceService An instance of a resilience service that implements the IServiceResilience interface, used for executing HTTP requests with built-in support for retries, timeouts, and circuit breakers to enhance the reliability of remote calls.
|
|
67
|
-
*
|
|
68
|
-
* @author Xeno
|
|
69
|
-
* @version 1.0.0
|
|
70
|
-
* @since 2025-09-30
|
|
71
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
72
|
-
*/
|
|
73
|
-
constructor(_httpClient, _resilienceService) {
|
|
74
|
-
this._httpClient = _httpClient;
|
|
75
|
-
this._resilienceService = _resilienceService;
|
|
76
|
-
}
|
|
77
|
-
_httpClient;
|
|
78
|
-
_resilienceService;
|
|
79
|
-
/** @description Private method that sends an HTTP request to a specified endpoint using the provided HttpRequest options. The method utilizes the resilience service to execute the request, ensuring that it is performed with built-in support for retries, timeouts, and circuit breakers. The response from the HTTP client is then wrapped in a ResultType, which encapsulates either the successful response data or an error, providing a consistent way to handle both success and failure cases.
|
|
80
|
-
* @param endpoint The URL or endpoint to which the HTTP request is sent.
|
|
81
|
-
* @param options The HttpRequest options that specify the HTTP method, headers, query parameters, body, and other request configurations.
|
|
82
|
-
* @returns A Promise that resolves to a ResultType containing either the successful response data or an error if the request fails.
|
|
83
|
-
*
|
|
84
|
-
* @author Xeno
|
|
85
|
-
* @version 1.0.0
|
|
86
|
-
* @since 2025-09-30
|
|
87
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
88
|
-
*/
|
|
89
|
-
async send(endpoint, options) {
|
|
90
|
-
const response = await this._resilienceService.execute(async () => {
|
|
91
|
-
switch (options.method) {
|
|
92
|
-
case "GET":
|
|
93
|
-
return await this._httpClient.get(endpoint, options);
|
|
94
|
-
case "POST":
|
|
95
|
-
return await this._httpClient.post(endpoint, options.body, options);
|
|
96
|
-
case "PUT":
|
|
97
|
-
return await this._httpClient.put(endpoint, options.body, options);
|
|
98
|
-
case "PATCH":
|
|
99
|
-
return await this._httpClient.patch(endpoint, options.body, options);
|
|
100
|
-
case "DELETE":
|
|
101
|
-
return await this._httpClient.delete(endpoint, options);
|
|
102
|
-
default:
|
|
103
|
-
throw import_shared.AppError.notSupported(
|
|
104
|
-
this.constructor.name,
|
|
105
|
-
`Unsupported HTTP method: ${options.method}`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}, options.signal);
|
|
109
|
-
return import_shared.Result.ok(response.data);
|
|
110
|
-
}
|
|
111
|
-
setOptions(request, method, body = void 0) {
|
|
112
|
-
return {
|
|
113
|
-
query: request?.query,
|
|
114
|
-
signal: request?.signal,
|
|
115
|
-
timeoutMs: request?.timeoutMs,
|
|
116
|
-
headers: request?.headers,
|
|
117
|
-
responseType: request?.responseType,
|
|
118
|
-
method,
|
|
119
|
-
body
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
async get(endpoint, request) {
|
|
123
|
-
const options = this.setOptions(request, "GET");
|
|
124
|
-
return await this.send(endpoint, options);
|
|
125
|
-
}
|
|
126
|
-
async post(endpoint, body, request) {
|
|
127
|
-
const options = this.setOptions(request, "POST", body);
|
|
128
|
-
return await this.send(endpoint, options);
|
|
129
|
-
}
|
|
130
|
-
async put(endpoint, body, request) {
|
|
131
|
-
const options = this.setOptions(request, "PUT", body);
|
|
132
|
-
return await this.send(endpoint, options);
|
|
133
|
-
}
|
|
134
|
-
async patch(endpoint, body, request) {
|
|
135
|
-
const options = this.setOptions(request, "PATCH", body);
|
|
136
|
-
return await this.send(endpoint, options);
|
|
137
|
-
}
|
|
138
|
-
async delete(endpoint, request) {
|
|
139
|
-
const options = this.setOptions(request, "DELETE");
|
|
140
|
-
return await this.send(endpoint, options);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
-
0 && (module.exports = {
|
|
145
|
-
BasePostgresSqlDataSource,
|
|
146
|
-
BaseSqliteSqlDataSource,
|
|
147
|
-
RemoteDataSource
|
|
148
|
-
});
|
|
149
|
-
//# sourceMappingURL=db.cjs.map
|
package/dist/db.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/db.ts","../src/infrastructure/datasources/base-postgressql.datasource.ts","../src/infrastructure/datasources/base-sqllite.datasource.ts","../src/infrastructure/datasources/remote.datasource.ts"],"sourcesContent":["export * from './infrastructure/datasources'\nexport type * from './infrastructure/db'\n","import type { Dictionary } from '@xeno-js/shared'\r\nimport type { NodePgDatabase } from 'drizzle-orm/node-postgres'\r\n\r\nimport type { DbContext } from '../db'\r\n\r\n/**\r\n * @description BasePostgresSqlDataSource is an abstract class that serves as a foundation for creating data sources that interact with a PostgreSQL database. It provides a common interface for accessing the database connection and ensures that the database connection is properly initialized and managed. By extending this class, developers can easily create data sources that are tailored to their specific use cases.\r\n *\r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js\r\n */\r\nexport abstract class BasePostgresSqlDataSource<TSchema extends Dictionary = Dictionary> {\r\n constructor(private readonly _db: DbContext<TSchema>) {}\r\n\r\n /**\r\n * @description Returns the database connection.\r\n * @returns {NodePgDatabase<TSchema>} The database connection.\r\n */\r\n protected get db(): NodePgDatabase<TSchema> {\r\n return this._db as NodePgDatabase<TSchema>\r\n }\r\n}\r\n","import type { Dictionary } from '@xeno-js/shared'\r\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\r\n\r\nimport type { DbContext } from '../db'\r\n\r\n/**\r\n * @description BaseSqliteSqlDataSource is an abstract class that serves as a foundation for creating data sources that interact with a SQLite / libSQL database.\r\n *\r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js\r\n */\r\nexport abstract class BaseSqliteSqlDataSource<TSchema extends Dictionary = Dictionary> {\r\n constructor(private readonly _db: DbContext<TSchema>) {}\r\n\r\n /**\r\n * @description Returns the SQLite database connection.\r\n * @returns {LibSQLDatabase<TSchema>} The database connection.\r\n */\r\n protected get db(): LibSQLDatabase<TSchema> {\r\n return this._db as LibSQLDatabase<TSchema>\r\n }\r\n}\r\n","import type {\r\n HttpBaseRequest,\r\n HttpMethod,\r\n HttpRequest,\r\n IHttpClient,\r\n IRemoteDataSource,\r\n IServiceResilience,\r\n Optional,\r\n ResultType,\r\n} from '@xeno-js/shared'\r\nimport { AppError, Result } from '@xeno-js/shared'\r\n\r\n/**\r\n * @description Concrete implementation of the IRemoteDataSource contract that utilizes an agnostic HTTP client and a resilience service to fetch data from remote endpoints. The RemoteDataSource class is responsible for sending HTTP requests based on the provided HttpClientRequest parameters, while leveraging the resilience features of the IServiceResilience to ensure reliable communication with external services. This implementation abstracts away the details of how HTTP requests are made and how resilience is handled, allowing for flexibility in choosing different HTTP clients and resilience strategies without affecting the consumers of the IRemoteDataSource interface.\r\n *\r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js\r\n */\r\nexport abstract class RemoteDataSource implements IRemoteDataSource {\r\n /** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.\r\n * These dependencies are injected into the class, allowing for greater flexibility and testability.\r\n * The HTTP client is used to send requests to remote endpoints, while the resilience service is used to execute these requests with built-in support for retries, timeouts, and circuit breakers, ensuring that the remote calls are more resilient to failures and can recover gracefully from errors.\r\n * @param _httpClient An instance of an agnostic HTTP client that implements the IHttpClient interface, used for sending HTTP requests to remote endpoints.\r\n * @param _resilienceService An instance of a resilience service that implements the IServiceResilience interface, used for executing HTTP requests with built-in support for retries, timeouts, and circuit breakers to enhance the reliability of remote calls.\r\n *\r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js\r\n */\r\n constructor(\r\n private readonly _httpClient: IHttpClient,\r\n private readonly _resilienceService: IServiceResilience,\r\n ) {}\r\n\r\n /** @description Private method that sends an HTTP request to a specified endpoint using the provided HttpRequest options. The method utilizes the resilience service to execute the request, ensuring that it is performed with built-in support for retries, timeouts, and circuit breakers. The response from the HTTP client is then wrapped in a ResultType, which encapsulates either the successful response data or an error, providing a consistent way to handle both success and failure cases.\r\n * @param endpoint The URL or endpoint to which the HTTP request is sent.\r\n * @param options The HttpRequest options that specify the HTTP method, headers, query parameters, body, and other request configurations.\r\n * @returns A Promise that resolves to a ResultType containing either the successful response data or an error if the request fails.\r\n *\r\n * @author Xeno\r\n * @version 1.0.0\r\n * @since 2025-09-30\r\n * @link https://github.com/xeno-js/xeno-js\r\n */\r\n private async send<TResponse, TBody = unknown>(\r\n endpoint: string,\r\n options: HttpRequest<TBody>,\r\n ): Promise<ResultType<TResponse>> {\r\n const response = await this._resilienceService.execute(async () => {\r\n switch (options.method) {\r\n case 'GET':\r\n return await this._httpClient.get<TResponse>(endpoint, options)\r\n case 'POST':\r\n return await this._httpClient.post<TResponse, TBody>(endpoint, options.body, options)\r\n case 'PUT':\r\n return await this._httpClient.put<TResponse, TBody>(endpoint, options.body, options)\r\n case 'PATCH':\r\n return await this._httpClient.patch<TResponse, TBody>(endpoint, options.body, options)\r\n case 'DELETE':\r\n return await this._httpClient.delete<TResponse>(endpoint, options)\r\n default:\r\n throw AppError.notSupported(\r\n this.constructor.name,\r\n `Unsupported HTTP method: ${options.method}`,\r\n )\r\n }\r\n }, options.signal)\r\n\r\n return Result.ok(response.data)\r\n }\r\n\r\n protected setOptions<T>(\r\n request: Optional<HttpBaseRequest>,\r\n method: HttpMethod,\r\n body: Optional<T> = undefined,\r\n ): HttpRequest<T> {\r\n return {\r\n query: request?.query,\r\n signal: request?.signal,\r\n timeoutMs: request?.timeoutMs,\r\n headers: request?.headers,\r\n responseType: request?.responseType,\r\n method,\r\n body,\r\n }\r\n }\r\n\r\n public async get<TResponse>(\r\n endpoint: string,\r\n request?: HttpBaseRequest,\r\n ): Promise<ResultType<TResponse>> {\r\n const options = this.setOptions(request, 'GET')\r\n\r\n return await this.send<TResponse>(endpoint, options)\r\n }\r\n\r\n public async post<TResponse, TBody = unknown>(\r\n endpoint: string,\r\n body: TBody,\r\n request?: HttpBaseRequest,\r\n ): Promise<ResultType<TResponse>> {\r\n const options = this.setOptions(request, 'POST', body)\r\n\r\n return await this.send<TResponse, TBody>(endpoint, options)\r\n }\r\n\r\n public async put<TResponse, TBody = unknown>(\r\n endpoint: string,\r\n body: TBody,\r\n request?: HttpBaseRequest,\r\n ): Promise<ResultType<TResponse>> {\r\n const options = this.setOptions(request, 'PUT', body)\r\n\r\n return await this.send<TResponse, TBody>(endpoint, options)\r\n }\r\n\r\n public async patch<TResponse, TBody = unknown>(\r\n endpoint: string,\r\n body: TBody,\r\n request?: HttpBaseRequest,\r\n ): Promise<ResultType<TResponse>> {\r\n const options = this.setOptions(request, 'PATCH', body)\r\n\r\n return await this.send<TResponse, TBody>(endpoint, options)\r\n }\r\n\r\n public async delete<TResponse>(\r\n endpoint: string,\r\n request?: HttpBaseRequest,\r\n ): Promise<ResultType<TResponse>> {\r\n const options = this.setOptions(request, 'DELETE')\r\n\r\n return await this.send<TResponse>(endpoint, options)\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,IAAe,4BAAf,MAAkF;AAAA,EACvF,YAA6B,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAA1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7B,IAAc,KAA8B;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;;;ACVO,IAAe,0BAAf,MAAgF;AAAA,EACrF,YAA6B,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAA1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7B,IAAc,KAA8B;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;;;ACbA,oBAAiC;AAU1B,IAAe,mBAAf,MAA6D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYlE,YACmB,aACA,oBACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanB,MAAc,KACZ,UACA,SACgC;AAChC,UAAM,WAAW,MAAM,KAAK,mBAAmB,QAAQ,YAAY;AACjE,cAAQ,QAAQ,QAAQ;AAAA,QACtB,KAAK;AACH,iBAAO,MAAM,KAAK,YAAY,IAAe,UAAU,OAAO;AAAA,QAChE,KAAK;AACH,iBAAO,MAAM,KAAK,YAAY,KAAuB,UAAU,QAAQ,MAAM,OAAO;AAAA,QACtF,KAAK;AACH,iBAAO,MAAM,KAAK,YAAY,IAAsB,UAAU,QAAQ,MAAM,OAAO;AAAA,QACrF,KAAK;AACH,iBAAO,MAAM,KAAK,YAAY,MAAwB,UAAU,QAAQ,MAAM,OAAO;AAAA,QACvF,KAAK;AACH,iBAAO,MAAM,KAAK,YAAY,OAAkB,UAAU,OAAO;AAAA,QACnE;AACE,gBAAM,uBAAS;AAAA,YACb,KAAK,YAAY;AAAA,YACjB,4BAA4B,QAAQ,MAAM;AAAA,UAC5C;AAAA,MACJ;AAAA,IACF,GAAG,QAAQ,MAAM;AAEjB,WAAO,qBAAO,GAAG,SAAS,IAAI;AAAA,EAChC;AAAA,EAEU,WACR,SACA,QACA,OAAoB,QACJ;AAChB,WAAO;AAAA,MACL,OAAO,SAAS;AAAA,MAChB,QAAQ,SAAS;AAAA,MACjB,WAAW,SAAS;AAAA,MACpB,SAAS,SAAS;AAAA,MAClB,cAAc,SAAS;AAAA,MACvB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAa,IACX,UACA,SACgC;AAChC,UAAM,UAAU,KAAK,WAAW,SAAS,KAAK;AAE9C,WAAO,MAAM,KAAK,KAAgB,UAAU,OAAO;AAAA,EACrD;AAAA,EAEA,MAAa,KACX,UACA,MACA,SACgC;AAChC,UAAM,UAAU,KAAK,WAAW,SAAS,QAAQ,IAAI;AAErD,WAAO,MAAM,KAAK,KAAuB,UAAU,OAAO;AAAA,EAC5D;AAAA,EAEA,MAAa,IACX,UACA,MACA,SACgC;AAChC,UAAM,UAAU,KAAK,WAAW,SAAS,OAAO,IAAI;AAEpD,WAAO,MAAM,KAAK,KAAuB,UAAU,OAAO;AAAA,EAC5D;AAAA,EAEA,MAAa,MACX,UACA,MACA,SACgC;AAChC,UAAM,UAAU,KAAK,WAAW,SAAS,SAAS,IAAI;AAEtD,WAAO,MAAM,KAAK,KAAuB,UAAU,OAAO;AAAA,EAC5D;AAAA,EAEA,MAAa,OACX,UACA,SACgC;AAChC,UAAM,UAAU,KAAK,WAAW,SAAS,QAAQ;AAEjD,WAAO,MAAM,KAAK,KAAgB,UAAU,OAAO;AAAA,EACrD;AACF;","names":[]}
|
package/dist/db.d.cts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Dictionary, IRemoteDataSource, IHttpClient, IServiceResilience, Optional, HttpBaseRequest, HttpMethod, HttpRequest, ResultType } from '@xeno-js/shared';
|
|
2
|
-
import * as drizzle_orm_node_postgres from 'drizzle-orm/node-postgres';
|
|
3
|
-
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
-
import * as _libsql_client_web from '@libsql/client/web';
|
|
5
|
-
import * as drizzle_orm_libsql from 'drizzle-orm/libsql';
|
|
6
|
-
import { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
7
|
-
import { A as ApplicationRegistry } from './itoken-service.contracts-3GrRvKeZ.cjs';
|
|
8
|
-
export * from 'drizzle-orm';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @description Type definition for the database context used in the application.
|
|
12
|
-
* Polymorphically handles both PostgreSQL and libSQL (SQLite/Turso) engines.
|
|
13
|
-
*
|
|
14
|
-
* @author Xeno
|
|
15
|
-
* @version 1.0.0
|
|
16
|
-
* @since 2025-09-30
|
|
17
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
18
|
-
*/
|
|
19
|
-
type DbContext<TSchema extends Dictionary = Dictionary> = drizzle_orm_node_postgres.NodePgDatabase<TSchema> | (drizzle_orm_libsql.LibSQLDatabase<TSchema> & {
|
|
20
|
-
$client: _libsql_client_web.Client;
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* @description Type definition for the transaction object used in the database context.
|
|
24
|
-
* Polymorphically handles both PostgreSQL and libSQL (SQLite/Turso) engines.
|
|
25
|
-
*
|
|
26
|
-
* @author Xeno
|
|
27
|
-
* @version 1.0.0
|
|
28
|
-
* @since 2025-09-30
|
|
29
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
30
|
-
*/
|
|
31
|
-
type DbTransaction = Parameters<Parameters<DbContext['transaction']>[0]>[0];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @description The XenoDbRegistry type is an alias for the ApplicationRegistry specialized with DbContext and DbTransaction. It represents the registry of application services and dependencies, specifically tailored for applications that utilize a database context and transactions. This type is used throughout the application to ensure consistent typing and to facilitate dependency injection and service resolution.
|
|
35
|
-
* @author Xeno
|
|
36
|
-
* @version 1.0.0
|
|
37
|
-
* @since 2025-09-30
|
|
38
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
39
|
-
*/
|
|
40
|
-
type XenoDbRegistry<TSchema extends Dictionary = Dictionary, TExtensions = object> = ApplicationRegistry<DbContext<TSchema>, DbTransaction> & Readonly<Omit<TExtensions, keyof ApplicationRegistry<DbContext<TSchema>, DbTransaction>>>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @description BasePostgresSqlDataSource is an abstract class that serves as a foundation for creating data sources that interact with a PostgreSQL database. It provides a common interface for accessing the database connection and ensures that the database connection is properly initialized and managed. By extending this class, developers can easily create data sources that are tailored to their specific use cases.
|
|
44
|
-
*
|
|
45
|
-
* @author Xeno
|
|
46
|
-
* @version 1.0.0
|
|
47
|
-
* @since 2025-09-30
|
|
48
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
49
|
-
*/
|
|
50
|
-
declare abstract class BasePostgresSqlDataSource<TSchema extends Dictionary = Dictionary> {
|
|
51
|
-
private readonly _db;
|
|
52
|
-
constructor(_db: DbContext<TSchema>);
|
|
53
|
-
/**
|
|
54
|
-
* @description Returns the database connection.
|
|
55
|
-
* @returns {NodePgDatabase<TSchema>} The database connection.
|
|
56
|
-
*/
|
|
57
|
-
protected get db(): NodePgDatabase<TSchema>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @description BaseSqliteSqlDataSource is an abstract class that serves as a foundation for creating data sources that interact with a SQLite / libSQL database.
|
|
62
|
-
*
|
|
63
|
-
* @author Xeno
|
|
64
|
-
* @version 1.0.0
|
|
65
|
-
* @since 2025-09-30
|
|
66
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
67
|
-
*/
|
|
68
|
-
declare abstract class BaseSqliteSqlDataSource<TSchema extends Dictionary = Dictionary> {
|
|
69
|
-
private readonly _db;
|
|
70
|
-
constructor(_db: DbContext<TSchema>);
|
|
71
|
-
/**
|
|
72
|
-
* @description Returns the SQLite database connection.
|
|
73
|
-
* @returns {LibSQLDatabase<TSchema>} The database connection.
|
|
74
|
-
*/
|
|
75
|
-
protected get db(): LibSQLDatabase<TSchema>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @description Concrete implementation of the IRemoteDataSource contract that utilizes an agnostic HTTP client and a resilience service to fetch data from remote endpoints. The RemoteDataSource class is responsible for sending HTTP requests based on the provided HttpClientRequest parameters, while leveraging the resilience features of the IServiceResilience to ensure reliable communication with external services. This implementation abstracts away the details of how HTTP requests are made and how resilience is handled, allowing for flexibility in choosing different HTTP clients and resilience strategies without affecting the consumers of the IRemoteDataSource interface.
|
|
80
|
-
*
|
|
81
|
-
* @author Xeno
|
|
82
|
-
* @version 1.0.0
|
|
83
|
-
* @since 2025-09-30
|
|
84
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
85
|
-
*/
|
|
86
|
-
declare abstract class RemoteDataSource implements IRemoteDataSource {
|
|
87
|
-
private readonly _httpClient;
|
|
88
|
-
private readonly _resilienceService;
|
|
89
|
-
/** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.
|
|
90
|
-
* These dependencies are injected into the class, allowing for greater flexibility and testability.
|
|
91
|
-
* The HTTP client is used to send requests to remote endpoints, while the resilience service is used to execute these requests with built-in support for retries, timeouts, and circuit breakers, ensuring that the remote calls are more resilient to failures and can recover gracefully from errors.
|
|
92
|
-
* @param _httpClient An instance of an agnostic HTTP client that implements the IHttpClient interface, used for sending HTTP requests to remote endpoints.
|
|
93
|
-
* @param _resilienceService An instance of a resilience service that implements the IServiceResilience interface, used for executing HTTP requests with built-in support for retries, timeouts, and circuit breakers to enhance the reliability of remote calls.
|
|
94
|
-
*
|
|
95
|
-
* @author Xeno
|
|
96
|
-
* @version 1.0.0
|
|
97
|
-
* @since 2025-09-30
|
|
98
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
99
|
-
*/
|
|
100
|
-
constructor(_httpClient: IHttpClient, _resilienceService: IServiceResilience);
|
|
101
|
-
/** @description Private method that sends an HTTP request to a specified endpoint using the provided HttpRequest options. The method utilizes the resilience service to execute the request, ensuring that it is performed with built-in support for retries, timeouts, and circuit breakers. The response from the HTTP client is then wrapped in a ResultType, which encapsulates either the successful response data or an error, providing a consistent way to handle both success and failure cases.
|
|
102
|
-
* @param endpoint The URL or endpoint to which the HTTP request is sent.
|
|
103
|
-
* @param options The HttpRequest options that specify the HTTP method, headers, query parameters, body, and other request configurations.
|
|
104
|
-
* @returns A Promise that resolves to a ResultType containing either the successful response data or an error if the request fails.
|
|
105
|
-
*
|
|
106
|
-
* @author Xeno
|
|
107
|
-
* @version 1.0.0
|
|
108
|
-
* @since 2025-09-30
|
|
109
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
110
|
-
*/
|
|
111
|
-
private send;
|
|
112
|
-
protected setOptions<T>(request: Optional<HttpBaseRequest>, method: HttpMethod, body?: Optional<T>): HttpRequest<T>;
|
|
113
|
-
get<TResponse>(endpoint: string, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
114
|
-
post<TResponse, TBody = unknown>(endpoint: string, body: TBody, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
115
|
-
put<TResponse, TBody = unknown>(endpoint: string, body: TBody, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
116
|
-
patch<TResponse, TBody = unknown>(endpoint: string, body: TBody, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
117
|
-
delete<TResponse>(endpoint: string, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { BasePostgresSqlDataSource, BaseSqliteSqlDataSource, type DbContext, type DbTransaction, RemoteDataSource, type XenoDbRegistry };
|
package/dist/db.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Dictionary, IRemoteDataSource, IHttpClient, IServiceResilience, Optional, HttpBaseRequest, HttpMethod, HttpRequest, ResultType } from '@xeno-js/shared';
|
|
2
|
-
import * as drizzle_orm_node_postgres from 'drizzle-orm/node-postgres';
|
|
3
|
-
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
-
import * as _libsql_client_web from '@libsql/client/web';
|
|
5
|
-
import * as drizzle_orm_libsql from 'drizzle-orm/libsql';
|
|
6
|
-
import { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
7
|
-
import { A as ApplicationRegistry } from './itoken-service.contracts-3GrRvKeZ.js';
|
|
8
|
-
export * from 'drizzle-orm';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @description Type definition for the database context used in the application.
|
|
12
|
-
* Polymorphically handles both PostgreSQL and libSQL (SQLite/Turso) engines.
|
|
13
|
-
*
|
|
14
|
-
* @author Xeno
|
|
15
|
-
* @version 1.0.0
|
|
16
|
-
* @since 2025-09-30
|
|
17
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
18
|
-
*/
|
|
19
|
-
type DbContext<TSchema extends Dictionary = Dictionary> = drizzle_orm_node_postgres.NodePgDatabase<TSchema> | (drizzle_orm_libsql.LibSQLDatabase<TSchema> & {
|
|
20
|
-
$client: _libsql_client_web.Client;
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* @description Type definition for the transaction object used in the database context.
|
|
24
|
-
* Polymorphically handles both PostgreSQL and libSQL (SQLite/Turso) engines.
|
|
25
|
-
*
|
|
26
|
-
* @author Xeno
|
|
27
|
-
* @version 1.0.0
|
|
28
|
-
* @since 2025-09-30
|
|
29
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
30
|
-
*/
|
|
31
|
-
type DbTransaction = Parameters<Parameters<DbContext['transaction']>[0]>[0];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @description The XenoDbRegistry type is an alias for the ApplicationRegistry specialized with DbContext and DbTransaction. It represents the registry of application services and dependencies, specifically tailored for applications that utilize a database context and transactions. This type is used throughout the application to ensure consistent typing and to facilitate dependency injection and service resolution.
|
|
35
|
-
* @author Xeno
|
|
36
|
-
* @version 1.0.0
|
|
37
|
-
* @since 2025-09-30
|
|
38
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
39
|
-
*/
|
|
40
|
-
type XenoDbRegistry<TSchema extends Dictionary = Dictionary, TExtensions = object> = ApplicationRegistry<DbContext<TSchema>, DbTransaction> & Readonly<Omit<TExtensions, keyof ApplicationRegistry<DbContext<TSchema>, DbTransaction>>>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @description BasePostgresSqlDataSource is an abstract class that serves as a foundation for creating data sources that interact with a PostgreSQL database. It provides a common interface for accessing the database connection and ensures that the database connection is properly initialized and managed. By extending this class, developers can easily create data sources that are tailored to their specific use cases.
|
|
44
|
-
*
|
|
45
|
-
* @author Xeno
|
|
46
|
-
* @version 1.0.0
|
|
47
|
-
* @since 2025-09-30
|
|
48
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
49
|
-
*/
|
|
50
|
-
declare abstract class BasePostgresSqlDataSource<TSchema extends Dictionary = Dictionary> {
|
|
51
|
-
private readonly _db;
|
|
52
|
-
constructor(_db: DbContext<TSchema>);
|
|
53
|
-
/**
|
|
54
|
-
* @description Returns the database connection.
|
|
55
|
-
* @returns {NodePgDatabase<TSchema>} The database connection.
|
|
56
|
-
*/
|
|
57
|
-
protected get db(): NodePgDatabase<TSchema>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @description BaseSqliteSqlDataSource is an abstract class that serves as a foundation for creating data sources that interact with a SQLite / libSQL database.
|
|
62
|
-
*
|
|
63
|
-
* @author Xeno
|
|
64
|
-
* @version 1.0.0
|
|
65
|
-
* @since 2025-09-30
|
|
66
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
67
|
-
*/
|
|
68
|
-
declare abstract class BaseSqliteSqlDataSource<TSchema extends Dictionary = Dictionary> {
|
|
69
|
-
private readonly _db;
|
|
70
|
-
constructor(_db: DbContext<TSchema>);
|
|
71
|
-
/**
|
|
72
|
-
* @description Returns the SQLite database connection.
|
|
73
|
-
* @returns {LibSQLDatabase<TSchema>} The database connection.
|
|
74
|
-
*/
|
|
75
|
-
protected get db(): LibSQLDatabase<TSchema>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @description Concrete implementation of the IRemoteDataSource contract that utilizes an agnostic HTTP client and a resilience service to fetch data from remote endpoints. The RemoteDataSource class is responsible for sending HTTP requests based on the provided HttpClientRequest parameters, while leveraging the resilience features of the IServiceResilience to ensure reliable communication with external services. This implementation abstracts away the details of how HTTP requests are made and how resilience is handled, allowing for flexibility in choosing different HTTP clients and resilience strategies without affecting the consumers of the IRemoteDataSource interface.
|
|
80
|
-
*
|
|
81
|
-
* @author Xeno
|
|
82
|
-
* @version 1.0.0
|
|
83
|
-
* @since 2025-09-30
|
|
84
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
85
|
-
*/
|
|
86
|
-
declare abstract class RemoteDataSource implements IRemoteDataSource {
|
|
87
|
-
private readonly _httpClient;
|
|
88
|
-
private readonly _resilienceService;
|
|
89
|
-
/** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.
|
|
90
|
-
* These dependencies are injected into the class, allowing for greater flexibility and testability.
|
|
91
|
-
* The HTTP client is used to send requests to remote endpoints, while the resilience service is used to execute these requests with built-in support for retries, timeouts, and circuit breakers, ensuring that the remote calls are more resilient to failures and can recover gracefully from errors.
|
|
92
|
-
* @param _httpClient An instance of an agnostic HTTP client that implements the IHttpClient interface, used for sending HTTP requests to remote endpoints.
|
|
93
|
-
* @param _resilienceService An instance of a resilience service that implements the IServiceResilience interface, used for executing HTTP requests with built-in support for retries, timeouts, and circuit breakers to enhance the reliability of remote calls.
|
|
94
|
-
*
|
|
95
|
-
* @author Xeno
|
|
96
|
-
* @version 1.0.0
|
|
97
|
-
* @since 2025-09-30
|
|
98
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
99
|
-
*/
|
|
100
|
-
constructor(_httpClient: IHttpClient, _resilienceService: IServiceResilience);
|
|
101
|
-
/** @description Private method that sends an HTTP request to a specified endpoint using the provided HttpRequest options. The method utilizes the resilience service to execute the request, ensuring that it is performed with built-in support for retries, timeouts, and circuit breakers. The response from the HTTP client is then wrapped in a ResultType, which encapsulates either the successful response data or an error, providing a consistent way to handle both success and failure cases.
|
|
102
|
-
* @param endpoint The URL or endpoint to which the HTTP request is sent.
|
|
103
|
-
* @param options The HttpRequest options that specify the HTTP method, headers, query parameters, body, and other request configurations.
|
|
104
|
-
* @returns A Promise that resolves to a ResultType containing either the successful response data or an error if the request fails.
|
|
105
|
-
*
|
|
106
|
-
* @author Xeno
|
|
107
|
-
* @version 1.0.0
|
|
108
|
-
* @since 2025-09-30
|
|
109
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
110
|
-
*/
|
|
111
|
-
private send;
|
|
112
|
-
protected setOptions<T>(request: Optional<HttpBaseRequest>, method: HttpMethod, body?: Optional<T>): HttpRequest<T>;
|
|
113
|
-
get<TResponse>(endpoint: string, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
114
|
-
post<TResponse, TBody = unknown>(endpoint: string, body: TBody, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
115
|
-
put<TResponse, TBody = unknown>(endpoint: string, body: TBody, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
116
|
-
patch<TResponse, TBody = unknown>(endpoint: string, body: TBody, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
117
|
-
delete<TResponse>(endpoint: string, request?: HttpBaseRequest): Promise<ResultType<TResponse>>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { BasePostgresSqlDataSource, BaseSqliteSqlDataSource, type DbContext, type DbTransaction, RemoteDataSource, type XenoDbRegistry };
|
package/dist/db.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// src/infrastructure/datasources/base-postgressql.datasource.ts
|
|
2
|
-
var BasePostgresSqlDataSource = class {
|
|
3
|
-
constructor(_db) {
|
|
4
|
-
this._db = _db;
|
|
5
|
-
}
|
|
6
|
-
_db;
|
|
7
|
-
/**
|
|
8
|
-
* @description Returns the database connection.
|
|
9
|
-
* @returns {NodePgDatabase<TSchema>} The database connection.
|
|
10
|
-
*/
|
|
11
|
-
get db() {
|
|
12
|
-
return this._db;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/infrastructure/datasources/base-sqllite.datasource.ts
|
|
17
|
-
var BaseSqliteSqlDataSource = class {
|
|
18
|
-
constructor(_db) {
|
|
19
|
-
this._db = _db;
|
|
20
|
-
}
|
|
21
|
-
_db;
|
|
22
|
-
/**
|
|
23
|
-
* @description Returns the SQLite database connection.
|
|
24
|
-
* @returns {LibSQLDatabase<TSchema>} The database connection.
|
|
25
|
-
*/
|
|
26
|
-
get db() {
|
|
27
|
-
return this._db;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/infrastructure/datasources/remote.datasource.ts
|
|
32
|
-
import { AppError, Result } from "@xeno-js/shared";
|
|
33
|
-
var RemoteDataSource = class {
|
|
34
|
-
/** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.
|
|
35
|
-
* These dependencies are injected into the class, allowing for greater flexibility and testability.
|
|
36
|
-
* The HTTP client is used to send requests to remote endpoints, while the resilience service is used to execute these requests with built-in support for retries, timeouts, and circuit breakers, ensuring that the remote calls are more resilient to failures and can recover gracefully from errors.
|
|
37
|
-
* @param _httpClient An instance of an agnostic HTTP client that implements the IHttpClient interface, used for sending HTTP requests to remote endpoints.
|
|
38
|
-
* @param _resilienceService An instance of a resilience service that implements the IServiceResilience interface, used for executing HTTP requests with built-in support for retries, timeouts, and circuit breakers to enhance the reliability of remote calls.
|
|
39
|
-
*
|
|
40
|
-
* @author Xeno
|
|
41
|
-
* @version 1.0.0
|
|
42
|
-
* @since 2025-09-30
|
|
43
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
44
|
-
*/
|
|
45
|
-
constructor(_httpClient, _resilienceService) {
|
|
46
|
-
this._httpClient = _httpClient;
|
|
47
|
-
this._resilienceService = _resilienceService;
|
|
48
|
-
}
|
|
49
|
-
_httpClient;
|
|
50
|
-
_resilienceService;
|
|
51
|
-
/** @description Private method that sends an HTTP request to a specified endpoint using the provided HttpRequest options. The method utilizes the resilience service to execute the request, ensuring that it is performed with built-in support for retries, timeouts, and circuit breakers. The response from the HTTP client is then wrapped in a ResultType, which encapsulates either the successful response data or an error, providing a consistent way to handle both success and failure cases.
|
|
52
|
-
* @param endpoint The URL or endpoint to which the HTTP request is sent.
|
|
53
|
-
* @param options The HttpRequest options that specify the HTTP method, headers, query parameters, body, and other request configurations.
|
|
54
|
-
* @returns A Promise that resolves to a ResultType containing either the successful response data or an error if the request fails.
|
|
55
|
-
*
|
|
56
|
-
* @author Xeno
|
|
57
|
-
* @version 1.0.0
|
|
58
|
-
* @since 2025-09-30
|
|
59
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
60
|
-
*/
|
|
61
|
-
async send(endpoint, options) {
|
|
62
|
-
const response = await this._resilienceService.execute(async () => {
|
|
63
|
-
switch (options.method) {
|
|
64
|
-
case "GET":
|
|
65
|
-
return await this._httpClient.get(endpoint, options);
|
|
66
|
-
case "POST":
|
|
67
|
-
return await this._httpClient.post(endpoint, options.body, options);
|
|
68
|
-
case "PUT":
|
|
69
|
-
return await this._httpClient.put(endpoint, options.body, options);
|
|
70
|
-
case "PATCH":
|
|
71
|
-
return await this._httpClient.patch(endpoint, options.body, options);
|
|
72
|
-
case "DELETE":
|
|
73
|
-
return await this._httpClient.delete(endpoint, options);
|
|
74
|
-
default:
|
|
75
|
-
throw AppError.notSupported(
|
|
76
|
-
this.constructor.name,
|
|
77
|
-
`Unsupported HTTP method: ${options.method}`
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}, options.signal);
|
|
81
|
-
return Result.ok(response.data);
|
|
82
|
-
}
|
|
83
|
-
setOptions(request, method, body = void 0) {
|
|
84
|
-
return {
|
|
85
|
-
query: request?.query,
|
|
86
|
-
signal: request?.signal,
|
|
87
|
-
timeoutMs: request?.timeoutMs,
|
|
88
|
-
headers: request?.headers,
|
|
89
|
-
responseType: request?.responseType,
|
|
90
|
-
method,
|
|
91
|
-
body
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async get(endpoint, request) {
|
|
95
|
-
const options = this.setOptions(request, "GET");
|
|
96
|
-
return await this.send(endpoint, options);
|
|
97
|
-
}
|
|
98
|
-
async post(endpoint, body, request) {
|
|
99
|
-
const options = this.setOptions(request, "POST", body);
|
|
100
|
-
return await this.send(endpoint, options);
|
|
101
|
-
}
|
|
102
|
-
async put(endpoint, body, request) {
|
|
103
|
-
const options = this.setOptions(request, "PUT", body);
|
|
104
|
-
return await this.send(endpoint, options);
|
|
105
|
-
}
|
|
106
|
-
async patch(endpoint, body, request) {
|
|
107
|
-
const options = this.setOptions(request, "PATCH", body);
|
|
108
|
-
return await this.send(endpoint, options);
|
|
109
|
-
}
|
|
110
|
-
async delete(endpoint, request) {
|
|
111
|
-
const options = this.setOptions(request, "DELETE");
|
|
112
|
-
return await this.send(endpoint, options);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
export {
|
|
116
|
-
BasePostgresSqlDataSource,
|
|
117
|
-
BaseSqliteSqlDataSource,
|
|
118
|
-
RemoteDataSource
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=db.js.map
|