elseware-nodejs 1.11.6 → 1.11.8
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/LICENSE +20 -20
- package/README.md +49 -49
- package/dist/index.cjs +82 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +82 -38
- package/dist/index.js.map +1 -1
- package/package.json +78 -78
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 elseware Technology
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 elseware Technology
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
# elseware-nodejs
|
|
2
|
-
|
|
3
|
-
A modern Node.js utility and application framework powering the Elseware ecosystem.
|
|
4
|
-
|
|
5
|
-
`elseware-nodejs` provides a collection of reusable components, utilities, middleware, abstractions, and development patterns for building scalable Node.js applications and microservices.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- TypeScript-first development
|
|
10
|
-
- Express.js integration
|
|
11
|
-
- Repository pattern abstractions
|
|
12
|
-
- Service layer architecture
|
|
13
|
-
- Request context management
|
|
14
|
-
- Structured error handling
|
|
15
|
-
- Validation utilities
|
|
16
|
-
- Logging and observability support
|
|
17
|
-
- Microservice-friendly design
|
|
18
|
-
- Reusable application building blocks
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install elseware-nodejs
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
import { AppError } from "elseware-nodejs";
|
|
30
|
-
|
|
31
|
-
throw new AppError("Something went wrong");
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Documentation
|
|
35
|
-
|
|
36
|
-
Documentation, guides, and usage examples are available in the official repository.
|
|
37
|
-
|
|
38
|
-
## About elseware Technology
|
|
39
|
-
|
|
40
|
-
elseware Technology builds tools, frameworks, and solutions for software engineering, cloud computing, game development, and developer productivity.
|
|
41
|
-
|
|
42
|
-
## Contributing
|
|
43
|
-
|
|
44
|
-
Contributions, issues, and feature requests are welcome.
|
|
45
|
-
|
|
46
|
-
## License
|
|
47
|
-
|
|
48
|
-
This project is licensed under the MIT License.
|
|
49
|
-
|
|
1
|
+
# elseware-nodejs
|
|
2
|
+
|
|
3
|
+
A modern Node.js utility and application framework powering the Elseware ecosystem.
|
|
4
|
+
|
|
5
|
+
`elseware-nodejs` provides a collection of reusable components, utilities, middleware, abstractions, and development patterns for building scalable Node.js applications and microservices.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- TypeScript-first development
|
|
10
|
+
- Express.js integration
|
|
11
|
+
- Repository pattern abstractions
|
|
12
|
+
- Service layer architecture
|
|
13
|
+
- Request context management
|
|
14
|
+
- Structured error handling
|
|
15
|
+
- Validation utilities
|
|
16
|
+
- Logging and observability support
|
|
17
|
+
- Microservice-friendly design
|
|
18
|
+
- Reusable application building blocks
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install elseware-nodejs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { AppError } from "elseware-nodejs";
|
|
30
|
+
|
|
31
|
+
throw new AppError("Something went wrong");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
Documentation, guides, and usage examples are available in the official repository.
|
|
37
|
+
|
|
38
|
+
## About elseware Technology
|
|
39
|
+
|
|
40
|
+
elseware Technology builds tools, frameworks, and solutions for software engineering, cloud computing, game development, and developer productivity.
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
Contributions, issues, and feature requests are welcome.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
This project is licensed under the MIT License.
|
|
49
|
+
|
|
50
50
|
Copyright © 2026 elseware Technology.
|
package/dist/index.cjs
CHANGED
|
@@ -1942,6 +1942,7 @@ var CircularQueue = class {
|
|
|
1942
1942
|
}
|
|
1943
1943
|
this.data = new Array(capacity);
|
|
1944
1944
|
}
|
|
1945
|
+
capacity;
|
|
1945
1946
|
data;
|
|
1946
1947
|
head = 0;
|
|
1947
1948
|
tail = 0;
|
|
@@ -4919,6 +4920,8 @@ var DatabaseManager = class {
|
|
|
4919
4920
|
this.provider = provider;
|
|
4920
4921
|
this.options = options;
|
|
4921
4922
|
}
|
|
4923
|
+
provider;
|
|
4924
|
+
options;
|
|
4922
4925
|
async connect() {
|
|
4923
4926
|
try {
|
|
4924
4927
|
await this.provider.connect();
|
|
@@ -4969,6 +4972,7 @@ var MongoDatabaseProvider = class {
|
|
|
4969
4972
|
constructor(config) {
|
|
4970
4973
|
this.config = config;
|
|
4971
4974
|
}
|
|
4975
|
+
config;
|
|
4972
4976
|
async connect() {
|
|
4973
4977
|
mongoose__default.default.set("strictQuery", this.config.strictQuery ?? true);
|
|
4974
4978
|
await mongoose__default.default.connect(this.config.uri);
|
|
@@ -5000,33 +5004,41 @@ var AsyncHandler = (fn) => (req, res, next) => {
|
|
|
5000
5004
|
Promise.resolve(fn(req, res, next)).catch(next);
|
|
5001
5005
|
};
|
|
5002
5006
|
|
|
5003
|
-
// src/infrastructure/http/query/
|
|
5004
|
-
var
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
"fields",
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
"contains",
|
|
5024
|
-
"startsWith",
|
|
5025
|
-
"endsWith"
|
|
5026
|
-
];
|
|
5007
|
+
// src/infrastructure/http/query/ApiFeaturesConfig.ts
|
|
5008
|
+
var DefaultApiFeaturesConfig = {
|
|
5009
|
+
defaultPage: 1,
|
|
5010
|
+
defaultLimit: 100,
|
|
5011
|
+
maxLimit: 1e3,
|
|
5012
|
+
reservedFields: ["page", "limit", "sort", "fields", "populate"],
|
|
5013
|
+
supportedOperators: [
|
|
5014
|
+
"eq",
|
|
5015
|
+
"ne",
|
|
5016
|
+
"gt",
|
|
5017
|
+
"gte",
|
|
5018
|
+
"lt",
|
|
5019
|
+
"lte",
|
|
5020
|
+
"in",
|
|
5021
|
+
"nin",
|
|
5022
|
+
"contains",
|
|
5023
|
+
"startsWith",
|
|
5024
|
+
"endsWith"
|
|
5025
|
+
]
|
|
5026
|
+
};
|
|
5027
5027
|
|
|
5028
5028
|
// src/infrastructure/http/query/ApiFeatures.ts
|
|
5029
5029
|
var ApiFeatures = class {
|
|
5030
|
+
static config = {
|
|
5031
|
+
...DefaultApiFeaturesConfig
|
|
5032
|
+
};
|
|
5033
|
+
static configure(config) {
|
|
5034
|
+
this.config = {
|
|
5035
|
+
...this.config,
|
|
5036
|
+
...config
|
|
5037
|
+
};
|
|
5038
|
+
}
|
|
5039
|
+
static getConfig() {
|
|
5040
|
+
return this.config;
|
|
5041
|
+
}
|
|
5030
5042
|
static parse(query) {
|
|
5031
5043
|
return {
|
|
5032
5044
|
filters: this.parseFilters(query),
|
|
@@ -5039,12 +5051,11 @@ var ApiFeatures = class {
|
|
|
5039
5051
|
static parseFilters(query) {
|
|
5040
5052
|
const filters = [];
|
|
5041
5053
|
Object.entries(query).forEach(([key, value]) => {
|
|
5042
|
-
if (
|
|
5054
|
+
if (this.config.reservedFields.includes(key)) {
|
|
5043
5055
|
return;
|
|
5044
5056
|
}
|
|
5045
|
-
const
|
|
5046
|
-
|
|
5047
|
-
);
|
|
5057
|
+
const operatorsPattern = this.config.supportedOperators.join("|");
|
|
5058
|
+
const match = key.match(new RegExp(`^(.+)\\[(${operatorsPattern})\\]$`));
|
|
5048
5059
|
if (match) {
|
|
5049
5060
|
filters.push({
|
|
5050
5061
|
field: match[1],
|
|
@@ -5094,8 +5105,9 @@ var ApiFeatures = class {
|
|
|
5094
5105
|
return populate.split(",").map((field) => field.trim()).filter(Boolean);
|
|
5095
5106
|
}
|
|
5096
5107
|
static parsePagination(query) {
|
|
5097
|
-
const page = Number(query.page) ||
|
|
5098
|
-
const
|
|
5108
|
+
const page = Math.max(1, Number(query.page) || this.config.defaultPage);
|
|
5109
|
+
const requestedLimit = Number(query.limit) || this.config.defaultLimit;
|
|
5110
|
+
const limit = Math.min(Math.max(1, requestedLimit), this.config.maxLimit);
|
|
5099
5111
|
return {
|
|
5100
5112
|
page,
|
|
5101
5113
|
limit
|
|
@@ -5383,6 +5395,7 @@ var JoiValidator = class {
|
|
|
5383
5395
|
constructor(schema) {
|
|
5384
5396
|
this.schema = schema;
|
|
5385
5397
|
}
|
|
5398
|
+
schema;
|
|
5386
5399
|
validate(data) {
|
|
5387
5400
|
const result = this.schema.validate(data, {
|
|
5388
5401
|
abortEarly: false,
|
|
@@ -5411,6 +5424,7 @@ var ZodValidator = class {
|
|
|
5411
5424
|
constructor(schema) {
|
|
5412
5425
|
this.schema = schema;
|
|
5413
5426
|
}
|
|
5427
|
+
schema;
|
|
5414
5428
|
validate(data) {
|
|
5415
5429
|
const result = this.schema.safeParse(data);
|
|
5416
5430
|
if (!result.success) {
|
|
@@ -5599,6 +5613,7 @@ var BearerTokenStrategy = class {
|
|
|
5599
5613
|
constructor(tokenProvider) {
|
|
5600
5614
|
this.tokenProvider = tokenProvider;
|
|
5601
5615
|
}
|
|
5616
|
+
tokenProvider;
|
|
5602
5617
|
async getHeaders() {
|
|
5603
5618
|
const token = await this.tokenProvider.getToken();
|
|
5604
5619
|
return {
|
|
@@ -5612,6 +5627,7 @@ var StaticTokenProvider = class {
|
|
|
5612
5627
|
constructor(token) {
|
|
5613
5628
|
this.token = token;
|
|
5614
5629
|
}
|
|
5630
|
+
token;
|
|
5615
5631
|
getToken() {
|
|
5616
5632
|
return this.token;
|
|
5617
5633
|
}
|
|
@@ -5655,9 +5671,9 @@ var HttpClient = class {
|
|
|
5655
5671
|
let attempt = 0;
|
|
5656
5672
|
let lastError;
|
|
5657
5673
|
while (true) {
|
|
5674
|
+
const controller = new AbortController();
|
|
5675
|
+
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
5658
5676
|
try {
|
|
5659
|
-
const controller = new AbortController();
|
|
5660
|
-
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
5661
5677
|
const authHeaders = await this.authStrategy?.getHeaders();
|
|
5662
5678
|
const response = await fetch(`${this.baseUrl}${path2}`, {
|
|
5663
5679
|
method,
|
|
@@ -5671,17 +5687,19 @@ var HttpClient = class {
|
|
|
5671
5687
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
5672
5688
|
});
|
|
5673
5689
|
clearTimeout(timeout);
|
|
5674
|
-
const
|
|
5690
|
+
const parsedBody = await this.parseResponseBody(response);
|
|
5675
5691
|
if (!response.ok) {
|
|
5692
|
+
const payload = parsedBody;
|
|
5676
5693
|
throw new AppError(
|
|
5677
|
-
|
|
5694
|
+
payload?.message ?? response.statusText ?? "HTTP request failed",
|
|
5678
5695
|
response.status,
|
|
5679
5696
|
{
|
|
5680
|
-
code:
|
|
5697
|
+
code: payload?.code ?? "HTTP_REQUEST_FAILED",
|
|
5681
5698
|
details: {
|
|
5682
5699
|
service: this.serviceName,
|
|
5683
5700
|
method,
|
|
5684
|
-
path: path2
|
|
5701
|
+
path: path2,
|
|
5702
|
+
status: response.status
|
|
5685
5703
|
}
|
|
5686
5704
|
}
|
|
5687
5705
|
);
|
|
@@ -5690,8 +5708,9 @@ var HttpClient = class {
|
|
|
5690
5708
|
logger.info(
|
|
5691
5709
|
`[${this.serviceName}]` + (correlationId2 ? ` [${correlationId2}]` : "") + ` ${method} ${path2}`
|
|
5692
5710
|
);
|
|
5693
|
-
return
|
|
5711
|
+
return parsedBody;
|
|
5694
5712
|
} catch (error) {
|
|
5713
|
+
clearTimeout(timeout);
|
|
5695
5714
|
lastError = error;
|
|
5696
5715
|
if (this.retryPolicy.shouldRetry(attempt, error)) {
|
|
5697
5716
|
const delay = this.retryPolicy.getDelay(attempt, error);
|
|
@@ -5712,6 +5731,31 @@ var HttpClient = class {
|
|
|
5712
5731
|
);
|
|
5713
5732
|
throw lastError;
|
|
5714
5733
|
}
|
|
5734
|
+
async parseResponseBody(response) {
|
|
5735
|
+
if (response.status === 204) {
|
|
5736
|
+
return null;
|
|
5737
|
+
}
|
|
5738
|
+
const responseLike = response;
|
|
5739
|
+
const contentType = response.headers?.get?.("content-type") ?? "";
|
|
5740
|
+
if (contentType.includes("application/json") && typeof responseLike.json === "function") {
|
|
5741
|
+
return responseLike.json();
|
|
5742
|
+
}
|
|
5743
|
+
if (typeof responseLike.json === "function") {
|
|
5744
|
+
try {
|
|
5745
|
+
return await responseLike.json();
|
|
5746
|
+
} catch {
|
|
5747
|
+
}
|
|
5748
|
+
}
|
|
5749
|
+
if (typeof responseLike.text === "function") {
|
|
5750
|
+
const text = await responseLike.text();
|
|
5751
|
+
return {
|
|
5752
|
+
message: text || response.statusText || "HTTP request failed"
|
|
5753
|
+
};
|
|
5754
|
+
}
|
|
5755
|
+
return {
|
|
5756
|
+
message: response.statusText || "HTTP request failed"
|
|
5757
|
+
};
|
|
5758
|
+
}
|
|
5715
5759
|
sleep(ms) {
|
|
5716
5760
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5717
5761
|
}
|
|
@@ -6368,10 +6412,8 @@ exports.ConsistentHash = ConsistentHash;
|
|
|
6368
6412
|
exports.CorrelationId = CorrelationId;
|
|
6369
6413
|
exports.CountMinSketch = CountMinSketch;
|
|
6370
6414
|
exports.CrudControllerFactory = CrudControllerFactory;
|
|
6371
|
-
exports.DEFAULT_LIMIT = DEFAULT_LIMIT;
|
|
6372
|
-
exports.DEFAULT_PAGE = DEFAULT_PAGE;
|
|
6373
|
-
exports.DEFAULT_SORT_DIRECTION = DEFAULT_SORT_DIRECTION;
|
|
6374
6415
|
exports.DatabaseManager = DatabaseManager;
|
|
6416
|
+
exports.DefaultApiFeaturesConfig = DefaultApiFeaturesConfig;
|
|
6375
6417
|
exports.Deque = Deque;
|
|
6376
6418
|
exports.DirectedGraph = DirectedGraph;
|
|
6377
6419
|
exports.DisjointSetUnion = DisjointSetUnion;
|
|
@@ -6410,14 +6452,12 @@ exports.OrderedSet = OrderedSet;
|
|
|
6410
6452
|
exports.PairingHeap = PairingHeap;
|
|
6411
6453
|
exports.PairingNode = PairingNode;
|
|
6412
6454
|
exports.PriorityQueue = PriorityQueue;
|
|
6413
|
-
exports.QUERY_RESERVED_FIELDS = QUERY_RESERVED_FIELDS;
|
|
6414
6455
|
exports.QuadTree = QuadTree;
|
|
6415
6456
|
exports.Queue = Queue;
|
|
6416
6457
|
exports.RadixTree = RadixTree;
|
|
6417
6458
|
exports.RedBlackTree = RedBlackTree;
|
|
6418
6459
|
exports.RequestContext = RequestContext;
|
|
6419
6460
|
exports.SMTPProvider = SMTPProvider;
|
|
6420
|
-
exports.SUPPORTED_OPERATORS = SUPPORTED_OPERATORS;
|
|
6421
6461
|
exports.SegmentTree = SegmentTree;
|
|
6422
6462
|
exports.ServiceClient = ServiceClient;
|
|
6423
6463
|
exports.Set = Set2;
|