@leyyo/asl 1.0.1
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 +21 -0
- package/README.md +25 -0
- package/dist/asl-type.d.ts +10 -0
- package/dist/asl-type.js +9 -0
- package/dist/asl-type.js.map +1 -0
- package/dist/asl.d.ts +5 -0
- package/dist/asl.js +352 -0
- package/dist/asl.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/index.types.d.ts +423 -0
- package/dist/index.types.js +3 -0
- package/dist/index.types.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +6 -0
- package/dist/internal.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Mustafa Yelmer
|
|
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
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Leyyo ASL
|
|
2
|
+
ASL library for Leyyo framework
|
|
3
|
+
|
|
4
|
+
## Import
|
|
5
|
+
- `npm i @leyyo/asl`
|
|
6
|
+
|
|
7
|
+
## Standards
|
|
8
|
+
- Language: `TS`
|
|
9
|
+
- Eslint: `Yes`
|
|
10
|
+
- Static Code Analysis: `Yes` *IntelliJ Code Inspections*
|
|
11
|
+
- DDD - Document Driven: `Yes`
|
|
12
|
+
- DDD - Domain Driven: `Yes`
|
|
13
|
+
- EDD - Exception Driven: `Yes`
|
|
14
|
+
- TDD - Test Driven: `Yes`
|
|
15
|
+
- LDD - Log Driven: `Yes`
|
|
16
|
+
- 12FA - 12 Factor-App: `50%` *Partially*
|
|
17
|
+
|
|
18
|
+
## Dependencies
|
|
19
|
+
### NO
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
### Prepared by
|
|
23
|
+
- Mustafa Yelmer
|
|
24
|
+
- mustafayelmer(at)gmail.com
|
|
25
|
+
- `2022-01-17`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const literals: readonly ["http", "ws", "job", "broker", "cli", "app", "another"];
|
|
2
|
+
/**
|
|
3
|
+
* ASL (Async Local Storage) Type
|
|
4
|
+
* */
|
|
5
|
+
export type AslType = typeof literals[number];
|
|
6
|
+
/**
|
|
7
|
+
* @type {Array<AslType>}
|
|
8
|
+
* */
|
|
9
|
+
export declare const AslTypeItems: ReadonlyArray<AslType>;
|
|
10
|
+
export {};
|
package/dist/asl-type.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AslTypeItems = void 0;
|
|
4
|
+
const literals = ['http', 'ws', 'job', 'broker', 'cli', 'app', 'another'];
|
|
5
|
+
/**
|
|
6
|
+
* @type {Array<AslType>}
|
|
7
|
+
* */
|
|
8
|
+
exports.AslTypeItems = literals;
|
|
9
|
+
//# sourceMappingURL=asl-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asl-type.js","sourceRoot":"","sources":["../src/asl-type.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAU,CAAC;AAMnF;;KAEK;AACQ,QAAA,YAAY,GAAG,QAAkC,CAAC"}
|
package/dist/asl.d.ts
ADDED
package/dist/asl.js
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.asl = void 0;
|
|
5
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
6
|
+
const asl_type_1 = require("./asl-type");
|
|
7
|
+
/**
|
|
8
|
+
* Safe integer limit
|
|
9
|
+
* */
|
|
10
|
+
const MAX_SAFE = Number.MAX_SAFE_INTEGER - 100;
|
|
11
|
+
/**
|
|
12
|
+
* Instance key
|
|
13
|
+
* */
|
|
14
|
+
const ASL = Symbol.for('asl');
|
|
15
|
+
/**
|
|
16
|
+
* Id key
|
|
17
|
+
* */
|
|
18
|
+
const NUM = Symbol.for('num');
|
|
19
|
+
/**
|
|
20
|
+
* Increment key
|
|
21
|
+
* */
|
|
22
|
+
const INC = Symbol.for('inc');
|
|
23
|
+
/**
|
|
24
|
+
* Build default key
|
|
25
|
+
* */
|
|
26
|
+
const DEF = Symbol.for('set');
|
|
27
|
+
/**
|
|
28
|
+
* Extend context key
|
|
29
|
+
* */
|
|
30
|
+
const EXT = Symbol.for('ext');
|
|
31
|
+
/**
|
|
32
|
+
* Run context key
|
|
33
|
+
* */
|
|
34
|
+
const RUN = Symbol.for('run');
|
|
35
|
+
/**
|
|
36
|
+
* Get context key
|
|
37
|
+
* */
|
|
38
|
+
const GET = Symbol.for('get');
|
|
39
|
+
/**
|
|
40
|
+
* Set context key
|
|
41
|
+
* */
|
|
42
|
+
const SET = Symbol.for('set');
|
|
43
|
+
/**
|
|
44
|
+
* ASL class
|
|
45
|
+
* */
|
|
46
|
+
class Asl {
|
|
47
|
+
constructor() {
|
|
48
|
+
// region private-properties
|
|
49
|
+
/**
|
|
50
|
+
* ASL instance
|
|
51
|
+
* */
|
|
52
|
+
this[_a] = new node_async_hooks_1.AsyncLocalStorage();
|
|
53
|
+
/**
|
|
54
|
+
* Transaction id
|
|
55
|
+
*
|
|
56
|
+
* @type {number}
|
|
57
|
+
* */
|
|
58
|
+
this[_b] = 0;
|
|
59
|
+
// endregion is
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Increments transaction id
|
|
63
|
+
*
|
|
64
|
+
* @return {number}
|
|
65
|
+
* */
|
|
66
|
+
get [(_a = ASL, _b = NUM, INC)]() {
|
|
67
|
+
if (this[NUM] > MAX_SAFE) {
|
|
68
|
+
this[NUM] = 0;
|
|
69
|
+
}
|
|
70
|
+
this[NUM]++;
|
|
71
|
+
return this[NUM];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates default context with given type
|
|
75
|
+
*
|
|
76
|
+
* @param {AslType} type
|
|
77
|
+
* @return {AslContextCore}
|
|
78
|
+
* */
|
|
79
|
+
[DEF](type) {
|
|
80
|
+
const core = {
|
|
81
|
+
id: this[INC],
|
|
82
|
+
time: new Date(),
|
|
83
|
+
type,
|
|
84
|
+
};
|
|
85
|
+
this[ASL].enterWith(core);
|
|
86
|
+
return core;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Creates default context with given type
|
|
90
|
+
*
|
|
91
|
+
* @param {AslType} type
|
|
92
|
+
* @param {AslContextEmpty} data
|
|
93
|
+
* */
|
|
94
|
+
[SET](type, data) {
|
|
95
|
+
this[ASL].enterWith(Object.assign({ id: this[INC], time: new Date(), type }, data));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extends context with getters
|
|
99
|
+
*
|
|
100
|
+
* @param {AslContextCore} core
|
|
101
|
+
* @return {AslContext}
|
|
102
|
+
* */
|
|
103
|
+
[EXT](core) {
|
|
104
|
+
const { type } = core;
|
|
105
|
+
return Object.assign(Object.assign({}, core), {
|
|
106
|
+
// region get data
|
|
107
|
+
get another() {
|
|
108
|
+
return type === 'another' ? core : undefined;
|
|
109
|
+
},
|
|
110
|
+
get application() {
|
|
111
|
+
return type === 'app' ? core : undefined;
|
|
112
|
+
},
|
|
113
|
+
get broker() {
|
|
114
|
+
return type === 'broker' ? core : undefined;
|
|
115
|
+
},
|
|
116
|
+
get cli() {
|
|
117
|
+
return type === 'cli' ? core : undefined;
|
|
118
|
+
},
|
|
119
|
+
get http() {
|
|
120
|
+
return type === 'http' ? core : undefined;
|
|
121
|
+
},
|
|
122
|
+
get job() {
|
|
123
|
+
return type === 'job' ? core : undefined;
|
|
124
|
+
},
|
|
125
|
+
get webSocket() {
|
|
126
|
+
return type === 'ws' ? core : undefined;
|
|
127
|
+
},
|
|
128
|
+
// endregion get data
|
|
129
|
+
// region any
|
|
130
|
+
any(...possibleTypes) {
|
|
131
|
+
return possibleTypes.includes(core.type);
|
|
132
|
+
},
|
|
133
|
+
// endregion any
|
|
134
|
+
// region is
|
|
135
|
+
get isNone() {
|
|
136
|
+
return !type || !asl_type_1.AslTypeItems.includes(type);
|
|
137
|
+
},
|
|
138
|
+
get isAnother() {
|
|
139
|
+
return type === 'another';
|
|
140
|
+
},
|
|
141
|
+
get isApplication() {
|
|
142
|
+
return type === 'app';
|
|
143
|
+
},
|
|
144
|
+
get isBroker() {
|
|
145
|
+
return type === 'broker';
|
|
146
|
+
},
|
|
147
|
+
get isCli() {
|
|
148
|
+
return type === 'cli';
|
|
149
|
+
},
|
|
150
|
+
get isHttp() {
|
|
151
|
+
return type === 'http';
|
|
152
|
+
},
|
|
153
|
+
get isJob() {
|
|
154
|
+
return type === 'job';
|
|
155
|
+
},
|
|
156
|
+
get isWebSocket() {
|
|
157
|
+
return type === 'ws';
|
|
158
|
+
} });
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates new context
|
|
162
|
+
*
|
|
163
|
+
* @param {AslType} type
|
|
164
|
+
* @param {function} next
|
|
165
|
+
* @param {AslContextEmpty} data
|
|
166
|
+
* */
|
|
167
|
+
[RUN](type, next, data) {
|
|
168
|
+
const ctx = Object.assign({ id: this[INC], time: new Date(), type }, (data !== null && data !== void 0 ? data : {}));
|
|
169
|
+
this[ASL].run(ctx, () => {
|
|
170
|
+
try {
|
|
171
|
+
next();
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
console.warn(`${ctx.time.toISOString()} - Asl error [${type}] <${e.name}> ${e.message}`);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Returns new context
|
|
180
|
+
*
|
|
181
|
+
* @param {AslType} type
|
|
182
|
+
* @return {AslContextCore}
|
|
183
|
+
* */
|
|
184
|
+
[GET](type) {
|
|
185
|
+
const value = this[ASL].getStore();
|
|
186
|
+
if (value) {
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
return this[DEF](type);
|
|
190
|
+
}
|
|
191
|
+
// endregion private-properties
|
|
192
|
+
// region from
|
|
193
|
+
/** @inheritDoc */
|
|
194
|
+
$fromAnother(another, next) {
|
|
195
|
+
this[RUN]('another', next, another);
|
|
196
|
+
}
|
|
197
|
+
/** @inheritDoc */
|
|
198
|
+
$setForAnother(another) {
|
|
199
|
+
this[SET]('another', another);
|
|
200
|
+
}
|
|
201
|
+
/** @inheritDoc */
|
|
202
|
+
$fromApplication(app, next) {
|
|
203
|
+
this[RUN]('app', next, app);
|
|
204
|
+
}
|
|
205
|
+
/** @inheritDoc */
|
|
206
|
+
$setForApplication(app) {
|
|
207
|
+
this[SET]('app', app);
|
|
208
|
+
}
|
|
209
|
+
/** @inheritDoc */
|
|
210
|
+
$fromBroker(broker, next) {
|
|
211
|
+
this[RUN]('broker', next, broker);
|
|
212
|
+
}
|
|
213
|
+
/** @inheritDoc */
|
|
214
|
+
$setForBroker(broker) {
|
|
215
|
+
this[SET]('broker', broker);
|
|
216
|
+
}
|
|
217
|
+
/** @inheritDoc */
|
|
218
|
+
$fromCli(cli, next) {
|
|
219
|
+
this[RUN]('cli', next, cli);
|
|
220
|
+
}
|
|
221
|
+
/** @inheritDoc */
|
|
222
|
+
$setForCli(cli) {
|
|
223
|
+
this[SET]('cli', cli);
|
|
224
|
+
}
|
|
225
|
+
/** @inheritDoc */
|
|
226
|
+
$fromHttp(http, next) {
|
|
227
|
+
this[RUN]('http', next, http);
|
|
228
|
+
}
|
|
229
|
+
/** @inheritDoc */
|
|
230
|
+
$setForHttp(http) {
|
|
231
|
+
this[SET]('http', http);
|
|
232
|
+
}
|
|
233
|
+
/** @inheritDoc */
|
|
234
|
+
$fromJob(job, next) {
|
|
235
|
+
this[RUN]('job', next, job);
|
|
236
|
+
}
|
|
237
|
+
/** @inheritDoc */
|
|
238
|
+
$setForJob(job) {
|
|
239
|
+
this[SET]('job', job);
|
|
240
|
+
}
|
|
241
|
+
/** @inheritDoc */
|
|
242
|
+
$fromWs(ws, next) {
|
|
243
|
+
this[RUN]('ws', next, ws);
|
|
244
|
+
}
|
|
245
|
+
/** @inheritDoc */
|
|
246
|
+
$setForWs(ws) {
|
|
247
|
+
this[SET]('ws', ws);
|
|
248
|
+
}
|
|
249
|
+
/** @inheritDoc */
|
|
250
|
+
$httpMiddleware(req, _res, next) {
|
|
251
|
+
this[RUN]('http', next, { req });
|
|
252
|
+
}
|
|
253
|
+
// endregion from
|
|
254
|
+
// region cast
|
|
255
|
+
/** @inheritDoc */
|
|
256
|
+
as() {
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
// endregion cast
|
|
260
|
+
// region context
|
|
261
|
+
/** @inheritDoc */
|
|
262
|
+
get ctx() {
|
|
263
|
+
return this[EXT](this[GET](undefined));
|
|
264
|
+
}
|
|
265
|
+
/** @inheritDoc */
|
|
266
|
+
ctxDef(def) {
|
|
267
|
+
return this[EXT](this[GET](def));
|
|
268
|
+
}
|
|
269
|
+
// endregion context
|
|
270
|
+
// region short-get
|
|
271
|
+
/** @inheritDoc */
|
|
272
|
+
get another() {
|
|
273
|
+
const core = this[GET](undefined);
|
|
274
|
+
return core.type === 'another' ? core : undefined;
|
|
275
|
+
}
|
|
276
|
+
/** @inheritDoc */
|
|
277
|
+
get application() {
|
|
278
|
+
const core = this[GET](undefined);
|
|
279
|
+
return core.type === 'app' ? core : undefined;
|
|
280
|
+
}
|
|
281
|
+
/** @inheritDoc */
|
|
282
|
+
get broker() {
|
|
283
|
+
const core = this[GET](undefined);
|
|
284
|
+
return core.type === 'broker' ? core : undefined;
|
|
285
|
+
}
|
|
286
|
+
/** @inheritDoc */
|
|
287
|
+
get cli() {
|
|
288
|
+
const core = this[GET](undefined);
|
|
289
|
+
return core.type === 'cli' ? core : undefined;
|
|
290
|
+
}
|
|
291
|
+
/** @inheritDoc */
|
|
292
|
+
get http() {
|
|
293
|
+
const core = this[GET](undefined);
|
|
294
|
+
return core.type === 'http' ? core : undefined;
|
|
295
|
+
}
|
|
296
|
+
/** @inheritDoc */
|
|
297
|
+
get job() {
|
|
298
|
+
const core = this[GET](undefined);
|
|
299
|
+
return core.type === 'job' ? core : undefined;
|
|
300
|
+
}
|
|
301
|
+
/** @inheritDoc */
|
|
302
|
+
get webSocket() {
|
|
303
|
+
const core = this[GET](undefined);
|
|
304
|
+
return core.type === 'ws' ? core : undefined;
|
|
305
|
+
}
|
|
306
|
+
// endregion short-get
|
|
307
|
+
// region any
|
|
308
|
+
/** @inheritDoc */
|
|
309
|
+
any(...possibleTypes) {
|
|
310
|
+
return possibleTypes.includes(this[GET](undefined).type);
|
|
311
|
+
}
|
|
312
|
+
// endregion any
|
|
313
|
+
// region is
|
|
314
|
+
/** @inheritDoc */
|
|
315
|
+
get isNone() {
|
|
316
|
+
const type = this[GET](undefined).type;
|
|
317
|
+
return !type || !asl_type_1.AslTypeItems.includes(type);
|
|
318
|
+
}
|
|
319
|
+
/** @inheritDoc */
|
|
320
|
+
get isAnother() {
|
|
321
|
+
return this[GET](undefined).type === 'another';
|
|
322
|
+
}
|
|
323
|
+
/** @inheritDoc */
|
|
324
|
+
get isApplication() {
|
|
325
|
+
return this[GET](undefined).type === 'app';
|
|
326
|
+
}
|
|
327
|
+
/** @inheritDoc */
|
|
328
|
+
get isBroker() {
|
|
329
|
+
return this[GET](undefined).type === 'broker';
|
|
330
|
+
}
|
|
331
|
+
/** @inheritDoc */
|
|
332
|
+
get isCli() {
|
|
333
|
+
return this[GET](undefined).type === 'cli';
|
|
334
|
+
}
|
|
335
|
+
/** @inheritDoc */
|
|
336
|
+
get isHttp() {
|
|
337
|
+
return this[GET](undefined).type === 'http';
|
|
338
|
+
}
|
|
339
|
+
/** @inheritDoc */
|
|
340
|
+
get isJob() {
|
|
341
|
+
return this[GET](undefined).type === 'job';
|
|
342
|
+
}
|
|
343
|
+
/** @inheritDoc */
|
|
344
|
+
get isWebSocket() {
|
|
345
|
+
return this[GET](undefined).type === 'ws';
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* ASL instance
|
|
350
|
+
* */
|
|
351
|
+
exports.asl = new Asl();
|
|
352
|
+
//# sourceMappingURL=asl.js.map
|
package/dist/asl.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asl.js","sourceRoot":"","sources":["../src/asl.ts"],"names":[],"mappings":";;;;AAAA,uDAAmD;AAYnD,yCAAsD;AAEtD;;KAEK;AACL,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,GAAG,G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I,KAAK,SAAS,CAAC;IACnD,CAAC;IAED,kBAAkB;IAClB,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC;IAC/C,CAAC;IAED,kBAAkB;IAClB,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;IAClD,CAAC;IAED,kBAAkB;IAClB,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC;IAC/C,CAAC;IAED,kBAAkB;IAClB,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;IAChD,CAAC;IAED,kBAAkB;IAClB,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC;IAC/C,CAAC;IAED,kBAAkB;IAClB,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;IAC9C,CAAC;CAEJ;AAED;;KAEK;AACQ,QAAA,GAAG,GAAY,IAAI,GAAG,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./asl-type"), exports);
|
|
18
|
+
__exportStar(require("./index.types"), exports);
|
|
19
|
+
__exportStar(require("./asl"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,gDAA8B;AAC9B,wCAAsB"}
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import type { NextFunction, Request } from "express";
|
|
2
|
+
import type { AslType } from "./asl-type";
|
|
3
|
+
/**
|
|
4
|
+
* Core value interface, it's stored in `AsyncLocalStorage`
|
|
5
|
+
* */
|
|
6
|
+
export interface AslContextCore {
|
|
7
|
+
/**
|
|
8
|
+
* Incremental transaction id
|
|
9
|
+
* - It's refreshed when it reaches to limit
|
|
10
|
+
*
|
|
11
|
+
* @type {number} - integer
|
|
12
|
+
* */
|
|
13
|
+
readonly id: number;
|
|
14
|
+
/**
|
|
15
|
+
* Time of transaction
|
|
16
|
+
*
|
|
17
|
+
* @type {Date}
|
|
18
|
+
* */
|
|
19
|
+
readonly time: Date;
|
|
20
|
+
/**
|
|
21
|
+
* Type of transaction
|
|
22
|
+
*
|
|
23
|
+
* @type {AslType}
|
|
24
|
+
* */
|
|
25
|
+
readonly type: AslType;
|
|
26
|
+
/**
|
|
27
|
+
* Other extra parameters by your requirements
|
|
28
|
+
*
|
|
29
|
+
* @type {any}
|
|
30
|
+
* */
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runtime interface, it holds getters
|
|
35
|
+
*
|
|
36
|
+
* Generics:
|
|
37
|
+
* - X: `another` (your custom) context, def: `{}`
|
|
38
|
+
* - H: `http` context, def: `{req}`
|
|
39
|
+
* - W: `web socket` context, def: `{req}`
|
|
40
|
+
* - J: `job` context, def: `{name}`
|
|
41
|
+
* - B: `broker` context, def: `{topic}`
|
|
42
|
+
* - C: `cli` context, def: `{}`
|
|
43
|
+
* - A: `application` context, def: `{}`
|
|
44
|
+
* */
|
|
45
|
+
interface AslContextExtended<X extends AslContextAnother = AslContextAnother, H extends AslContextHttp = AslContextHttp, W extends AslContextWs = AslContextWs, J extends AslContextJob = AslContextJob, B extends AslContextBroker = AslContextBroker, C extends AslContextCli = AslContextCli, A extends AslContextApp = AslContextApp> {
|
|
46
|
+
/**
|
|
47
|
+
* Is type of context in given types
|
|
48
|
+
*
|
|
49
|
+
* @param {...Array<AslType>} possibleTypes - variadic possible types
|
|
50
|
+
* @return {boolean}
|
|
51
|
+
* */
|
|
52
|
+
any(...possibleTypes: Array<AslType>): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Is none?
|
|
55
|
+
* - Means, there is no any valid context
|
|
56
|
+
*
|
|
57
|
+
* @return {boolean}
|
|
58
|
+
* */
|
|
59
|
+
get isNone(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Is http context?
|
|
62
|
+
*
|
|
63
|
+
* @return {boolean}
|
|
64
|
+
* */
|
|
65
|
+
get isHttp(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Get http context
|
|
68
|
+
* - if type === 'http' then return context
|
|
69
|
+
* - else return `undefined`
|
|
70
|
+
*
|
|
71
|
+
* @return {(AslContextCore & Record)}
|
|
72
|
+
* */
|
|
73
|
+
get http(): AslContextCore & H;
|
|
74
|
+
/**
|
|
75
|
+
* Is web socket context?
|
|
76
|
+
*
|
|
77
|
+
* @return {boolean}
|
|
78
|
+
* */
|
|
79
|
+
get isWebSocket(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get web socket context
|
|
82
|
+
* - if type === 'ws' then return context
|
|
83
|
+
* - else return `undefined`
|
|
84
|
+
*
|
|
85
|
+
* @return {(AslContextCore & Record)}
|
|
86
|
+
* */
|
|
87
|
+
get webSocket(): AslContextCore & W;
|
|
88
|
+
/**
|
|
89
|
+
* Is job (scheduler, task, cron) context?
|
|
90
|
+
*
|
|
91
|
+
* @return {boolean}
|
|
92
|
+
* */
|
|
93
|
+
get isJob(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Get job context
|
|
96
|
+
* - if type === 'job' then return context
|
|
97
|
+
* - else return `undefined`
|
|
98
|
+
*
|
|
99
|
+
* @return {(AslContextCore & Record)}
|
|
100
|
+
* */
|
|
101
|
+
get job(): AslContextCore & J;
|
|
102
|
+
/**
|
|
103
|
+
* Is broker (queue, pubsub, event, ...) context?
|
|
104
|
+
*
|
|
105
|
+
* @return {boolean}
|
|
106
|
+
* */
|
|
107
|
+
get isBroker(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Get Http context
|
|
110
|
+
* - if type === 'broker' then return context
|
|
111
|
+
* - else return `undefined`
|
|
112
|
+
*
|
|
113
|
+
* @return {(AslContextCore & Record)}
|
|
114
|
+
* */
|
|
115
|
+
get broker(): AslContextCore & B;
|
|
116
|
+
/**
|
|
117
|
+
* Is CLI (console app) context?
|
|
118
|
+
*
|
|
119
|
+
* @return {boolean}
|
|
120
|
+
* */
|
|
121
|
+
get isCli(): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Get Http context
|
|
124
|
+
* - if type === 'cli' then return context
|
|
125
|
+
* - else return `undefined`
|
|
126
|
+
*
|
|
127
|
+
* @return {(AslContextCore & Record)}
|
|
128
|
+
* */
|
|
129
|
+
get cli(): AslContextCore & C;
|
|
130
|
+
/**
|
|
131
|
+
* Is application context?
|
|
132
|
+
*
|
|
133
|
+
* @return {boolean}
|
|
134
|
+
* */
|
|
135
|
+
get isApplication(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Get Http context
|
|
138
|
+
* - if type === 'app' then return context
|
|
139
|
+
* - else return `undefined`
|
|
140
|
+
*
|
|
141
|
+
* @return {(AslContextCore & Record)}
|
|
142
|
+
* */
|
|
143
|
+
get application(): AslContextCore & A;
|
|
144
|
+
/**
|
|
145
|
+
* Is another context?
|
|
146
|
+
*
|
|
147
|
+
* - Another means: your custom type
|
|
148
|
+
*
|
|
149
|
+
* @return {boolean}
|
|
150
|
+
* */
|
|
151
|
+
get isAnother(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Get Http context
|
|
154
|
+
* - if type === 'another' then return context
|
|
155
|
+
* - else return `undefined`
|
|
156
|
+
*
|
|
157
|
+
* @return {(AslContextCore & Record)}
|
|
158
|
+
* */
|
|
159
|
+
get another(): AslContextCore & X;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Context interface
|
|
163
|
+
* you can override it by using `asl.as()`
|
|
164
|
+
*
|
|
165
|
+
* ```typescript
|
|
166
|
+
* interface X extends AslContextAnother {tenantId: string, correlation: string, region: string}
|
|
167
|
+
* interface H extends AslContextHttp {tenantId: string}
|
|
168
|
+
* interface W extends AslContextWs {tenantId: string}
|
|
169
|
+
* interface J extends AslContextJob {cron: string, tenantId: string}
|
|
170
|
+
* interface B extends AslContextBroker {channel: string, tenantId: string}
|
|
171
|
+
* interface C extends AslContextCli {user: string}
|
|
172
|
+
* interface C extends AslContextApp {ip: string}
|
|
173
|
+
* const myAsl = asl.as<X, H, W, J, B, C, A>();
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* - Then you can use myAsl, it's identical with asl,
|
|
177
|
+
* - but casting is so different according to your usage
|
|
178
|
+
*
|
|
179
|
+
* ```
|
|
180
|
+
* // if http
|
|
181
|
+
* myAsl.http.tenantId
|
|
182
|
+
*
|
|
183
|
+
* // if broker
|
|
184
|
+
* myAsl.broker.channel
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* Generics:
|
|
188
|
+
* - H: `http` context, def: `{req}`
|
|
189
|
+
* - W: `web socket` context, def: `{req}`
|
|
190
|
+
* - J: `job` context, def: `{name}`
|
|
191
|
+
* - B: `broker` context, def: `{topic}`
|
|
192
|
+
* - C: `cli` context, def: `{}`
|
|
193
|
+
* - A: `application` context, def: `{}`
|
|
194
|
+
* */
|
|
195
|
+
export interface AslContext<X extends AslContextAnother = AslContextAnother, H extends AslContextHttp = AslContextHttp, W extends AslContextWs = AslContextWs, J extends AslContextJob = AslContextJob, B extends AslContextBroker = AslContextBroker, C extends AslContextCli = AslContextCli, A extends AslContextApp = AslContextApp> extends AslContextCore, AslContextExtended<X, H, W, J, B, C, A> {
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Context empty interface
|
|
199
|
+
* */
|
|
200
|
+
export interface AslContextEmpty {
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Context base interface
|
|
204
|
+
*
|
|
205
|
+
* Note: request object will be created for all types
|
|
206
|
+
* */
|
|
207
|
+
export interface AslContextBase {
|
|
208
|
+
/**
|
|
209
|
+
* Request object
|
|
210
|
+
*
|
|
211
|
+
* @type {Request}
|
|
212
|
+
* */
|
|
213
|
+
readonly req?: Request;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Context http interface
|
|
217
|
+
* */
|
|
218
|
+
export interface AslContextHttp extends AslContextBase {
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Context web socket interface
|
|
222
|
+
* */
|
|
223
|
+
export interface AslContextWs extends AslContextBase {
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Context job interface
|
|
227
|
+
* */
|
|
228
|
+
export interface AslContextJob extends AslContextBase {
|
|
229
|
+
/**
|
|
230
|
+
* Job name or class name
|
|
231
|
+
*
|
|
232
|
+
* @type {string}
|
|
233
|
+
* */
|
|
234
|
+
readonly name: string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Context broker interface
|
|
238
|
+
* */
|
|
239
|
+
export interface AslContextBroker extends AslContextBase {
|
|
240
|
+
/**
|
|
241
|
+
* Topic or channel name, or concatenated style
|
|
242
|
+
*
|
|
243
|
+
* @type {string}
|
|
244
|
+
* */
|
|
245
|
+
topic: string;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Context cli interface
|
|
249
|
+
* */
|
|
250
|
+
export interface AslContextCli extends AslContextBase {
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Context application interface
|
|
254
|
+
* */
|
|
255
|
+
export interface AslContextApp extends AslContextBase {
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Context another interface
|
|
259
|
+
* */
|
|
260
|
+
export interface AslContextAnother extends AslContextBase {
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Context next function
|
|
264
|
+
* */
|
|
265
|
+
export type AslNextFunction = () => void;
|
|
266
|
+
/**
|
|
267
|
+
* Asl interface
|
|
268
|
+
*
|
|
269
|
+
* Generics:
|
|
270
|
+
* - H: `http` context, def: `{req}`
|
|
271
|
+
* - W: `web socket` context, def: `{req}`
|
|
272
|
+
* - J: `job` context, def: `{name}`
|
|
273
|
+
* - B: `broker` context, def: `{topic}`
|
|
274
|
+
* - C: `cli` context, def: `{}`
|
|
275
|
+
* - A: `application` context, def: `{}`
|
|
276
|
+
* */
|
|
277
|
+
export interface AslLike<X extends AslContextAnother = AslContextAnother, H extends AslContextHttp = AslContextHttp, W extends AslContextWs = AslContextWs, J extends AslContextJob = AslContextJob, B extends AslContextBroker = AslContextBroker, C extends AslContextCli = AslContextCli, A extends AslContextApp = AslContextApp> extends AslContextExtended<X, H, W, J, B, C, A> {
|
|
278
|
+
/**
|
|
279
|
+
* Casts a typed asl with your interfaces
|
|
280
|
+
* */
|
|
281
|
+
as<X2 extends AslContextAnother = X, H2 extends AslContextHttp = H, W2 extends AslContextWs = W, J2 extends AslContextJob = J, B2 extends AslContextBroker = B, C2 extends AslContextCli = C, A2 extends AslContextApp = A>(): AslLike<X2, H2, W2, J2, B2, C2, A2>;
|
|
282
|
+
/**
|
|
283
|
+
* Return current context
|
|
284
|
+
*
|
|
285
|
+
* - It will return any time even if there is no context
|
|
286
|
+
* */
|
|
287
|
+
get ctx(): AslContext<X, H, W, J, B, C, A>;
|
|
288
|
+
/**
|
|
289
|
+
* Return current context with default type when it does not exist
|
|
290
|
+
*
|
|
291
|
+
* - It will return any time even if there is no context
|
|
292
|
+
* */
|
|
293
|
+
ctxDef(def: AslType): AslContext<X, H, W, J, B, C, A>;
|
|
294
|
+
/**
|
|
295
|
+
* Http middleware
|
|
296
|
+
* - When: You need to apply it in your app, ie: `app.use(...)`
|
|
297
|
+
*
|
|
298
|
+
* - It supports only `express`
|
|
299
|
+
* */
|
|
300
|
+
$httpMiddleware(req: Request, _res: unknown, next: NextFunction): void;
|
|
301
|
+
/**
|
|
302
|
+
* You can start `http` asl, with core data and next function
|
|
303
|
+
*
|
|
304
|
+
* - Note: Normally {@link $httpMiddleware} should be enough,
|
|
305
|
+
* and you don't need to use it
|
|
306
|
+
*
|
|
307
|
+
* @param {Record} http - http data, like {req, res}
|
|
308
|
+
* @param {function} next - a basic call back to go on
|
|
309
|
+
* */
|
|
310
|
+
$fromHttp(http: H, next: AslNextFunction): void;
|
|
311
|
+
/**
|
|
312
|
+
* Set custom `http` context
|
|
313
|
+
*
|
|
314
|
+
* @param {Record} http
|
|
315
|
+
*
|
|
316
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
317
|
+
* */
|
|
318
|
+
$setForHttp(http: H): void;
|
|
319
|
+
/**
|
|
320
|
+
* You can start `web socket` asl, with core data and next function
|
|
321
|
+
*
|
|
322
|
+
* - Note: Normally {@link $httpMiddleware} should be enough,
|
|
323
|
+
* and you don't need to use it
|
|
324
|
+
*
|
|
325
|
+
* @param {Record} ws - ws data, like {req}
|
|
326
|
+
* @param {function} next - a basic call back to go on
|
|
327
|
+
* */
|
|
328
|
+
$fromWs(ws: W, next: AslNextFunction): void;
|
|
329
|
+
/**
|
|
330
|
+
* Set custom `ws` context
|
|
331
|
+
*
|
|
332
|
+
* @param {Record} ws
|
|
333
|
+
*
|
|
334
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
335
|
+
* */
|
|
336
|
+
$setForWs(ws: W): void;
|
|
337
|
+
/**
|
|
338
|
+
* You can start `job` asl, with core data and next function
|
|
339
|
+
*
|
|
340
|
+
* - When: cron starts
|
|
341
|
+
*
|
|
342
|
+
* @param {Record} job - job data, like {name}
|
|
343
|
+
* @param {function} next - a basic call back to go on
|
|
344
|
+
* */
|
|
345
|
+
$fromJob(job: J, next: AslNextFunction): void;
|
|
346
|
+
/**
|
|
347
|
+
* Set custom `job` context
|
|
348
|
+
*
|
|
349
|
+
* @param {Record} job
|
|
350
|
+
*
|
|
351
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
352
|
+
* */
|
|
353
|
+
$setForJob(job: J): void;
|
|
354
|
+
/**
|
|
355
|
+
* You can start `broker` asl, with core data and next function
|
|
356
|
+
*
|
|
357
|
+
* - When: broker receives a new event
|
|
358
|
+
*
|
|
359
|
+
* @param {Record} broker - broker data, like {topic, channel}
|
|
360
|
+
* @param {function} next - a basic call back to go on
|
|
361
|
+
* */
|
|
362
|
+
$fromBroker(broker: B, next: AslNextFunction): void;
|
|
363
|
+
/**
|
|
364
|
+
* Set custom `broker` context
|
|
365
|
+
*
|
|
366
|
+
* @param {Record} broker
|
|
367
|
+
*
|
|
368
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
369
|
+
* */
|
|
370
|
+
$setForBroker(broker: B): void;
|
|
371
|
+
/**
|
|
372
|
+
* You can start `cli` asl, with core data and next function
|
|
373
|
+
*
|
|
374
|
+
* - When: use types new command
|
|
375
|
+
*
|
|
376
|
+
* @param {Record} cli - ws data, like {user, command}
|
|
377
|
+
* @param {function} next - a basic call back to go on
|
|
378
|
+
* */
|
|
379
|
+
$fromCli(cli: C, next: AslNextFunction): void;
|
|
380
|
+
/**
|
|
381
|
+
* Set custom `cli` context
|
|
382
|
+
*
|
|
383
|
+
* @param {Record} cli
|
|
384
|
+
*
|
|
385
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
386
|
+
* */
|
|
387
|
+
$setForCli(cli: C): void;
|
|
388
|
+
/**
|
|
389
|
+
* You can start `application` asl, with core data and next function
|
|
390
|
+
*
|
|
391
|
+
* - When: application starts
|
|
392
|
+
*
|
|
393
|
+
* @param {Record} app - ws data, like {name}
|
|
394
|
+
* @param {function} next - a basic call back to go on
|
|
395
|
+
* */
|
|
396
|
+
$fromApplication(app: A, next: AslNextFunction): void;
|
|
397
|
+
/**
|
|
398
|
+
* Set custom `app` context
|
|
399
|
+
*
|
|
400
|
+
* @param {Record} app
|
|
401
|
+
*
|
|
402
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
403
|
+
* */
|
|
404
|
+
$setForApplication(app: A): void;
|
|
405
|
+
/**
|
|
406
|
+
* You can start `another` asl, with core data and next function
|
|
407
|
+
*
|
|
408
|
+
* - When: it based on your choice
|
|
409
|
+
*
|
|
410
|
+
* @param {Record} another - ws data, like {tenantId}
|
|
411
|
+
* @param {function} next - a basic call back to go on
|
|
412
|
+
* */
|
|
413
|
+
$fromAnother(another: X, next: AslNextFunction): void;
|
|
414
|
+
/**
|
|
415
|
+
* Set custom `another` context
|
|
416
|
+
*
|
|
417
|
+
* @param {Record} another
|
|
418
|
+
*
|
|
419
|
+
* It calls {@link AsyncLocalStorage#enterWith}
|
|
420
|
+
* */
|
|
421
|
+
$setForAnother(another: X): void;
|
|
422
|
+
}
|
|
423
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.types.js","sourceRoot":"","sources":["../src/index.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FQN = "leyyo.asl";
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACxB,QAAA,GAAG,GAAG,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leyyo/asl",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "ASL library",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ASL",
|
|
7
|
+
"async local storage",
|
|
8
|
+
"async hooks"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/leyyonet/asl.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/leyyonet/asl.git/issues",
|
|
16
|
+
"email": "mustafayelmer@gmail.com"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/leyyonet/asl.git/#readme",
|
|
19
|
+
"author": "Mustafa Yelmer <mustafayelmer@gmail.com>",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clear": "rimraf dist",
|
|
24
|
+
"lint": "eslint src/**/*.ts",
|
|
25
|
+
"asset": "node -r ts-node/register commands/assets.ts",
|
|
26
|
+
"build": "npm run clear && tsc && npm run asset",
|
|
27
|
+
"test": "jest --config=jest.json --verbose",
|
|
28
|
+
"test:watch": "jest --watch --config=jest.json",
|
|
29
|
+
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
|
|
30
|
+
"~publish": "npm run build && npm publish -access=public"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/*"
|
|
34
|
+
],
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/preset-typescript": "^7.27.0",
|
|
38
|
+
"@types/jest": "^29.5.14",
|
|
39
|
+
"@types/node": "^22.14.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.29.0",
|
|
41
|
+
"@typescript-eslint/parser": "^8.29.0",
|
|
42
|
+
"eslint": "^9.23.0",
|
|
43
|
+
"eslint-config-prettier": "^10.1.1",
|
|
44
|
+
"eslint-plugin-jsdoc": "^50.6.9",
|
|
45
|
+
"eslint-plugin-node": "^11.1.0",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"prettier": "^3.5.3",
|
|
48
|
+
"rimraf": "^6.0.1",
|
|
49
|
+
"ts-jest": "^29.3.1",
|
|
50
|
+
"ts-node": "^10.8.1",
|
|
51
|
+
"typescript": "^5.7.3"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@types/express": "^5.0.6"
|
|
55
|
+
}
|
|
56
|
+
}
|