@treatwell/moleculer-essentials 2.0.0-beta.3 → 2.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/index.cjs +54 -32
- package/dist/index.d.cts +18 -13
- package/dist/index.d.mts +18 -13
- package/dist/index.mjs +54 -32
- package/dist/mixins/database.mixin.d.cts +3 -3
- package/dist/mixins/database.mixin.d.mts +3 -3
- package/dist/mixins/encryptor.mixin.d.cts +1 -1
- package/dist/mixins/encryptor.mixin.d.mts +1 -1
- package/dist/mixins/global-store.mixin.d.cts +1 -1
- package/dist/mixins/global-store.mixin.d.mts +1 -1
- package/dist/mixins/jwt.mixin.d.cts +1 -1
- package/dist/mixins/jwt.mixin.d.mts +1 -1
- package/dist/mixins/queue.mixin.cjs +8 -2
- package/dist/mixins/queue.mixin.d.cts +1 -1
- package/dist/mixins/queue.mixin.d.mts +1 -1
- package/dist/mixins/queue.mixin.mjs +8 -2
- package/dist/mixins/redis.mixin.cjs +2 -2
- package/dist/mixins/redis.mixin.d.cts +1 -1
- package/dist/mixins/redis.mixin.d.mts +1 -1
- package/dist/mixins/redis.mixin.mjs +2 -2
- package/dist/mixins/redlock.mixin.d.cts +1 -1
- package/dist/mixins/redlock.mixin.d.mts +1 -1
- package/dist/{types-CSx6iC1f.d.cts → types-DLBNHgt4.d.cts} +39 -31
- package/dist/{types-CSx6iC1f.d.mts → types-DLBNHgt4.d.mts} +39 -31
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
- [License](#license)
|
|
17
17
|
<!-- TOC -->
|
|
18
18
|
|
|
19
|
+
> [!WARNING]
|
|
20
|
+
> Starting v2.0.0-beta.4, this package is only compatible with moleculer v0.15+
|
|
21
|
+
|
|
19
22
|
## Purpose
|
|
20
23
|
|
|
21
24
|
`@treatwell/moleculer-essentials` is a collection of essential utilities and helpers for building
|
|
@@ -47,21 +50,20 @@ To complete the TS support and improve the developer experience, we also provide
|
|
|
47
50
|
|
|
48
51
|
## Usage
|
|
49
52
|
|
|
53
|
+
A working example is available in the [`example`](./example) folder, with a simple calculator service and an OpenAPI.
|
|
54
|
+
It's a great way to start a project.
|
|
55
|
+
|
|
50
56
|
### Basic Example
|
|
51
57
|
|
|
52
58
|
```ts
|
|
53
59
|
// src/index.ts
|
|
60
|
+
import { join } from 'node:path';
|
|
54
61
|
import fg from 'fast-glob';
|
|
55
62
|
import {
|
|
56
|
-
HealthCheckMiddleware,
|
|
57
63
|
createLoggerConfig,
|
|
58
64
|
createServiceBroker,
|
|
59
|
-
defaultLogger,
|
|
60
65
|
ZodValidator,
|
|
61
66
|
} from '@treatwell/moleculer-essentials';
|
|
62
|
-
import { fileURLToPath } from 'url';
|
|
63
|
-
import { dirname, join } from 'path';
|
|
64
|
-
import { config } from 'dotenv';
|
|
65
67
|
|
|
66
68
|
async function run() {
|
|
67
69
|
// Create Service Broker
|
|
@@ -92,7 +94,7 @@ async function run() {
|
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
run().catch(err => {
|
|
95
|
-
|
|
97
|
+
console.error('Error while starting server', { err });
|
|
96
98
|
process.exit(1);
|
|
97
99
|
});
|
|
98
100
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,16 @@ function getSchemaFromMoleculer(schema) {
|
|
|
30
30
|
}
|
|
31
31
|
return void 0;
|
|
32
32
|
}
|
|
33
|
+
function getContextSchemaField(ctx, prop) {
|
|
34
|
+
if (!ctx) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const schema = ctx.action ?? ctx.event;
|
|
38
|
+
if (!schema) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return schema[prop];
|
|
42
|
+
}
|
|
33
43
|
|
|
34
44
|
class RefExtractor {
|
|
35
45
|
refs = /* @__PURE__ */ new Map();
|
|
@@ -730,8 +740,6 @@ class AjvExtractor extends RefExtractor {
|
|
|
730
740
|
class AjvValidator extends moleculer.Validators.Base {
|
|
731
741
|
modes;
|
|
732
742
|
defaultMode;
|
|
733
|
-
// broker is a property of the base class
|
|
734
|
-
broker;
|
|
735
743
|
zodValidator;
|
|
736
744
|
/**
|
|
737
745
|
* Cache of compiled validation functions.
|
|
@@ -739,7 +747,7 @@ class AjvValidator extends moleculer.Validators.Base {
|
|
|
739
747
|
*/
|
|
740
748
|
compiledFns = /* @__PURE__ */ new WeakMap();
|
|
741
749
|
constructor(opts, defaultMode, zodValidator) {
|
|
742
|
-
super();
|
|
750
|
+
super({});
|
|
743
751
|
this.defaultMode = defaultMode;
|
|
744
752
|
this.zodValidator = zodValidator;
|
|
745
753
|
this.modes = /* @__PURE__ */ new Map();
|
|
@@ -795,8 +803,10 @@ class AjvValidator extends moleculer.Validators.Base {
|
|
|
795
803
|
}
|
|
796
804
|
const { validator, extractor } = validatorMode;
|
|
797
805
|
const refSchema = extractor.extract(schema);
|
|
798
|
-
const fn = (params,
|
|
799
|
-
|
|
806
|
+
const fn = (params, opts) => {
|
|
807
|
+
const ctx = opts?.meta.ctx;
|
|
808
|
+
const disableTransforms = getContextSchemaField(ctx, "disableTransforms");
|
|
809
|
+
if (!disableTransforms) {
|
|
800
810
|
applyBeforeTransforms(schema, params);
|
|
801
811
|
}
|
|
802
812
|
const validate = validator.compile(refSchema);
|
|
@@ -812,7 +822,7 @@ class AjvValidator extends moleculer.Validators.Base {
|
|
|
812
822
|
validate.errors || []
|
|
813
823
|
);
|
|
814
824
|
}
|
|
815
|
-
if (!
|
|
825
|
+
if (!disableTransforms) {
|
|
816
826
|
applyAfterTransforms(schema, params);
|
|
817
827
|
}
|
|
818
828
|
return true;
|
|
@@ -868,7 +878,7 @@ ${(errors || []).map(
|
|
|
868
878
|
}
|
|
869
879
|
const validate = this.compile(schema, action.validatorMode);
|
|
870
880
|
return async (ctx) => {
|
|
871
|
-
validate(ctx.params != null ? ctx.params : {}, ctx);
|
|
881
|
+
validate(ctx.params != null ? ctx.params : {}, { meta: { ctx } });
|
|
872
882
|
return handler(ctx);
|
|
873
883
|
};
|
|
874
884
|
},
|
|
@@ -885,15 +895,21 @@ ${(errors || []).map(
|
|
|
885
895
|
}
|
|
886
896
|
const validate = this.compile(schema, event.validatorMode);
|
|
887
897
|
return async (ctx) => {
|
|
888
|
-
validate(ctx.params != null ? ctx.params : {}, ctx);
|
|
898
|
+
validate(ctx.params != null ? ctx.params : {}, { meta: { ctx } });
|
|
889
899
|
return handler(ctx);
|
|
890
900
|
};
|
|
891
901
|
}
|
|
892
902
|
};
|
|
893
903
|
}
|
|
904
|
+
convertSchemaToMoleculer() {
|
|
905
|
+
throw new Error("Not implemented");
|
|
906
|
+
}
|
|
894
907
|
}
|
|
895
908
|
|
|
896
909
|
class ZodValidator extends moleculer.Validators.Base {
|
|
910
|
+
constructor() {
|
|
911
|
+
super({});
|
|
912
|
+
}
|
|
897
913
|
compile() {
|
|
898
914
|
throw new Error("compile should not be used, use validate instead");
|
|
899
915
|
}
|
|
@@ -916,6 +932,7 @@ ${v4.z.prettifyError(res.error)}`,
|
|
|
916
932
|
middleware() {
|
|
917
933
|
return {
|
|
918
934
|
name: "Validator",
|
|
935
|
+
// @ts-expect-error Moleculer wants action.params to be an object
|
|
919
936
|
localAction: (handler, action) => {
|
|
920
937
|
const schema = getSchemaFromMoleculer(action.params);
|
|
921
938
|
if (!schema) {
|
|
@@ -926,6 +943,7 @@ ${v4.z.prettifyError(res.error)}`,
|
|
|
926
943
|
return handler(ctx);
|
|
927
944
|
};
|
|
928
945
|
},
|
|
946
|
+
// @ts-expect-error Moleculer wants action.params to be an object
|
|
929
947
|
localEvent: (handler, event) => {
|
|
930
948
|
const schema = getSchemaFromMoleculer(event.params);
|
|
931
949
|
if (!schema) {
|
|
@@ -938,6 +956,9 @@ ${v4.z.prettifyError(res.error)}`,
|
|
|
938
956
|
}
|
|
939
957
|
};
|
|
940
958
|
}
|
|
959
|
+
convertSchemaToMoleculer() {
|
|
960
|
+
throw new Error("Not implemented");
|
|
961
|
+
}
|
|
941
962
|
}
|
|
942
963
|
|
|
943
964
|
class ContextFactory extends moleculer.Context {
|
|
@@ -1316,18 +1337,18 @@ function HealthCheckMiddleware(_opts) {
|
|
|
1316
1337
|
});
|
|
1317
1338
|
},
|
|
1318
1339
|
// After broker started
|
|
1319
|
-
started() {
|
|
1340
|
+
async started() {
|
|
1320
1341
|
const timeout = setTimeout(() => {
|
|
1321
1342
|
state = "up";
|
|
1322
1343
|
}, opts.startDebounce);
|
|
1323
1344
|
timeout.unref();
|
|
1324
1345
|
},
|
|
1325
1346
|
// Before broker stopping
|
|
1326
|
-
stopping() {
|
|
1347
|
+
async stopping() {
|
|
1327
1348
|
state = "stopping";
|
|
1328
1349
|
},
|
|
1329
1350
|
// After broker stopped
|
|
1330
|
-
stopped() {
|
|
1351
|
+
async stopped() {
|
|
1331
1352
|
state = "down";
|
|
1332
1353
|
server.close();
|
|
1333
1354
|
}
|
|
@@ -1336,23 +1357,27 @@ function HealthCheckMiddleware(_opts) {
|
|
|
1336
1357
|
|
|
1337
1358
|
function flattenTags(obj, convertToString = false, path = "") {
|
|
1338
1359
|
if (!obj) return null;
|
|
1339
|
-
return Object.keys(obj).reduce(
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
if (
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1360
|
+
return Object.keys(obj).reduce(
|
|
1361
|
+
(res, k) => {
|
|
1362
|
+
const o = obj[k];
|
|
1363
|
+
const pp = (path ? `${path}.` : "") + k;
|
|
1364
|
+
if (compat.isObject(o)) {
|
|
1365
|
+
if ("toHexString" in o) {
|
|
1366
|
+
res[pp] = o.toString();
|
|
1367
|
+
} else {
|
|
1368
|
+
Object.assign(res, flattenTags(o, convertToString, pp));
|
|
1369
|
+
}
|
|
1370
|
+
} else if (o !== void 0 && o !== null) {
|
|
1371
|
+
res[pp] = convertToString ? String(o) : o;
|
|
1347
1372
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
}, {});
|
|
1373
|
+
return res;
|
|
1374
|
+
},
|
|
1375
|
+
{}
|
|
1376
|
+
);
|
|
1353
1377
|
}
|
|
1354
1378
|
|
|
1355
1379
|
class NewrelicTraceExporter extends moleculer.TracerExporters.Base {
|
|
1380
|
+
opts = {};
|
|
1356
1381
|
queue;
|
|
1357
1382
|
timer = null;
|
|
1358
1383
|
defaultTags = {};
|
|
@@ -1372,11 +1397,11 @@ class NewrelicTraceExporter extends moleculer.TracerExporters.Base {
|
|
|
1372
1397
|
*/
|
|
1373
1398
|
init(tracer) {
|
|
1374
1399
|
super.init(tracer);
|
|
1375
|
-
if (this.opts.interval > 0) {
|
|
1400
|
+
if (this.opts.interval && this.opts.interval > 0) {
|
|
1376
1401
|
this.timer = setInterval(() => this.flush(), this.opts.interval * 1e3);
|
|
1377
1402
|
this.timer.unref();
|
|
1378
1403
|
}
|
|
1379
|
-
this.defaultTags = typeof this.opts.defaultTags === "function" ? this.opts.defaultTags.call(this, tracer) : this.opts.defaultTags;
|
|
1404
|
+
this.defaultTags = (typeof this.opts.defaultTags === "function" ? this.opts.defaultTags.call(this, tracer) : this.opts.defaultTags) || null;
|
|
1380
1405
|
if (this.defaultTags) {
|
|
1381
1406
|
this.defaultTags = flattenTags(this.defaultTags, true);
|
|
1382
1407
|
}
|
|
@@ -1459,7 +1484,6 @@ class NewrelicTraceExporter extends moleculer.TracerExporters.Base {
|
|
|
1459
1484
|
"duration.ms": span.duration,
|
|
1460
1485
|
name: span.name,
|
|
1461
1486
|
"parent.id": span.parentID,
|
|
1462
|
-
// @ts-expect-error fullName isn't declared on span yet
|
|
1463
1487
|
"service.name": span.service?.fullName || null,
|
|
1464
1488
|
...flattenTags(span.tags, true),
|
|
1465
1489
|
...flattenTags(this.errorToObject(span.error), true, "error") || {}
|
|
@@ -1469,9 +1493,7 @@ class NewrelicTraceExporter extends moleculer.TracerExporters.Base {
|
|
|
1469
1493
|
}
|
|
1470
1494
|
|
|
1471
1495
|
class NewrelicMetricsReporter extends moleculer.MetricReporters.Base {
|
|
1472
|
-
|
|
1473
|
-
registry;
|
|
1474
|
-
logger;
|
|
1496
|
+
opts = {};
|
|
1475
1497
|
timer = null;
|
|
1476
1498
|
defaultTags = {};
|
|
1477
1499
|
constructor(opts) {
|
|
@@ -1487,7 +1509,7 @@ class NewrelicMetricsReporter extends moleculer.MetricReporters.Base {
|
|
|
1487
1509
|
*/
|
|
1488
1510
|
init(registry) {
|
|
1489
1511
|
super.init(registry);
|
|
1490
|
-
if (this.opts.interval > 0) {
|
|
1512
|
+
if (this.opts.interval && this.opts.interval > 0) {
|
|
1491
1513
|
this.timer = setInterval(() => this.flush(), this.opts.interval * 1e3);
|
|
1492
1514
|
this.timer.unref();
|
|
1493
1515
|
}
|
|
@@ -1589,7 +1611,7 @@ class NewrelicMetricsReporter extends moleculer.MetricReporters.Base {
|
|
|
1589
1611
|
attributes: labels,
|
|
1590
1612
|
timestamp,
|
|
1591
1613
|
value: { count, sum, min: min || 0, max: max || 0 },
|
|
1592
|
-
"interval.ms": this.opts.interval * 1e3
|
|
1614
|
+
"interval.ms": (this.opts.interval || 0) * 1e3
|
|
1593
1615
|
});
|
|
1594
1616
|
if (buckets) {
|
|
1595
1617
|
Object.entries(buckets).forEach(([key, val]) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { S as SomeJSONSchema, J as JSONSchemaType, C as CustomActionSchema, A as Alias, a as CustomServiceSchema, D as Document, b as SchemaObject, O as OperationObject, R as ReferenceObject, c as CreateLoggerOptions, M as MoleculerLoggerConfigOptions } from './types-
|
|
2
|
-
export { d as AjvValidator, e as ApiKeySecurityScheme, f as CallbackObject, g as ComponentsObject, h as ContactObject, i as ContextFactory, E as EncodingObject, j as ExampleObject, k as ExternalDocumentationObject, H as HeaderObject, l as HttpSecurityScheme, I as InfoObject, m as InternalCallbackServiceThis, n as InternalObjectServiceThis, L as LicenseObject, o as LinkObject, p as MediaTypeObject, q as OAuth2SecurityScheme, r as OpenIdSecurityScheme, P as ParameterBaseObject, s as ParameterObject, t as PathItemObject, u as PathsObject, v as PropertiesSchema, w as RequestBodyObject, x as RequiredMembers, y as ResponseObject, z as ResponsesObject, B as SecurityRequirementObject, F as SecuritySchemeObject, G as ServerObject, K as ServerVariableObject, T as TagObject, N as Transform, Q as TransformField, U as TransformLevel, V as TransformMap, W as Transformer, X as ValidationSchema, Z as ZodValidator } from './types-
|
|
1
|
+
import { S as SomeJSONSchema, J as JSONSchemaType, C as CustomActionSchema, A as Alias, a as CustomServiceSchema, D as Document, b as SchemaObject, O as OperationObject, R as ReferenceObject, c as CreateLoggerOptions, M as MoleculerLoggerConfigOptions } from './types-DLBNHgt4.cjs';
|
|
2
|
+
export { d as AjvValidator, e as ApiKeySecurityScheme, f as CallbackObject, g as ComponentsObject, h as ContactObject, i as ContextFactory, E as EncodingObject, j as ExampleObject, k as ExternalDocumentationObject, H as HeaderObject, l as HttpSecurityScheme, I as InfoObject, m as InternalCallbackServiceThis, n as InternalObjectServiceThis, L as LicenseObject, o as LinkObject, p as MediaTypeObject, q as OAuth2SecurityScheme, r as OpenIdSecurityScheme, P as ParameterBaseObject, s as ParameterObject, t as PathItemObject, u as PathsObject, v as PropertiesSchema, w as RequestBodyObject, x as RequiredMembers, y as ResponseObject, z as ResponsesObject, B as SecurityRequirementObject, F as SecuritySchemeObject, G as ServerObject, K as ServerVariableObject, T as TagObject, N as Transform, Q as TransformField, U as TransformLevel, V as TransformMap, W as Transformer, X as ValidationSchema, Z as ZodValidator } from './types-DLBNHgt4.cjs';
|
|
3
3
|
import { ObjectId } from 'bson';
|
|
4
4
|
import { z, ZodType } from 'zod/v4';
|
|
5
5
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
6
|
-
import
|
|
7
|
-
import { Context, ServiceSchema, ServiceSettingSchema, Service, ServiceBroker, BrokerOptions, Middleware, LoggerConfig, TracerExporters, LoggerInstance, Tracer, Span, MetricReporters, MetricRegistry, MetricReporterOptions } from 'moleculer';
|
|
6
|
+
import { Errors, Context, ServiceSchema, ServiceSettingSchema, Service, ServiceBroker, BrokerOptions, Middleware, LoggerConfig, TracerExporters, Logger as Logger$1, Tracer, Span, MetricReporters, MetricRegistry } from 'moleculer';
|
|
8
7
|
import { Logger } from 'pino';
|
|
9
8
|
import 'pino-pretty';
|
|
10
9
|
|
|
@@ -60,7 +59,7 @@ declare function OpenAPIMixin(options: OpenAPIMixinOptions): Partial<CustomServi
|
|
|
60
59
|
description: string;
|
|
61
60
|
content: {
|
|
62
61
|
'application/json': {
|
|
63
|
-
schema: JSONSchemaType<Omit<
|
|
62
|
+
schema: JSONSchemaType<Omit<Errors.MoleculerServerError, "cause">>;
|
|
64
63
|
};
|
|
65
64
|
};
|
|
66
65
|
};
|
|
@@ -92,7 +91,7 @@ declare function OpenAPIMixin(options: OpenAPIMixinOptions): Partial<CustomServi
|
|
|
92
91
|
description: string;
|
|
93
92
|
content: {
|
|
94
93
|
'application/json': {
|
|
95
|
-
schema: JSONSchemaType<Omit<
|
|
94
|
+
schema: JSONSchemaType<Omit<Errors.ValidationError, "cause">>;
|
|
96
95
|
};
|
|
97
96
|
};
|
|
98
97
|
};
|
|
@@ -201,6 +200,12 @@ declare class AjvExtractor extends RefExtractor {
|
|
|
201
200
|
* For now, only methods are typed.
|
|
202
201
|
*/
|
|
203
202
|
declare function wrapMixin<Settings, Methods, Mixins>(svc: Partial<CustomServiceSchema<Settings, Methods, Mixins>>): typeof svc;
|
|
203
|
+
/**
|
|
204
|
+
* In order to let TS emit types for inferred services, we return our own
|
|
205
|
+
* type that extend the original one.
|
|
206
|
+
* More on why: https://github.com/microsoft/TypeScript/pull/58176#issuecomment-2052698294
|
|
207
|
+
*/
|
|
208
|
+
type _InferredServiceSchema = ServiceSchema;
|
|
204
209
|
/**
|
|
205
210
|
* This function is a NO-OP and is only useful for Typescript types.
|
|
206
211
|
* Using Generic arguments allows TS to infer types directly from the object
|
|
@@ -209,7 +214,7 @@ declare function wrapMixin<Settings, Methods, Mixins>(svc: Partial<CustomService
|
|
|
209
214
|
* For the wrapService fn, it will return a moleculer ServiceSchema that will stripe
|
|
210
215
|
* out every smart typing of methods. This should never be used inside a mixin.
|
|
211
216
|
*/
|
|
212
|
-
declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>):
|
|
217
|
+
declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>): _InferredServiceSchema;
|
|
213
218
|
|
|
214
219
|
/**
|
|
215
220
|
* This class replace the default Service class in Moleculer to:
|
|
@@ -271,7 +276,7 @@ declare function createLogger(opts?: CreateLoggerOptions): Logger;
|
|
|
271
276
|
declare function createLoggerConfig(opts?: MoleculerLoggerConfigOptions): LoggerConfig;
|
|
272
277
|
|
|
273
278
|
type NewrelicTraceExporterOptions = {
|
|
274
|
-
logger?:
|
|
279
|
+
logger?: Logger$1;
|
|
275
280
|
safetyTags?: boolean;
|
|
276
281
|
/**
|
|
277
282
|
* Base URL for NewRelic server.
|
|
@@ -292,7 +297,7 @@ type NewrelicTraceExporterOptions = {
|
|
|
292
297
|
/**
|
|
293
298
|
* Default span tags.
|
|
294
299
|
*/
|
|
295
|
-
defaultTags?: Record<string, unknown> | (() => Record<string, unknown>);
|
|
300
|
+
defaultTags?: Record<string, unknown> | ((tracer?: unknown) => Record<string, unknown>);
|
|
296
301
|
};
|
|
297
302
|
/**
|
|
298
303
|
* >>> Hard copy of the moleculer NewRelic provider. It didn't handle errors correctly
|
|
@@ -303,6 +308,7 @@ type NewrelicTraceExporterOptions = {
|
|
|
303
308
|
* API v2: https://zipkin.io/zipkin-api/#/
|
|
304
309
|
*/
|
|
305
310
|
declare class NewrelicTraceExporter extends TracerExporters.Base {
|
|
311
|
+
private readonly opts;
|
|
306
312
|
private queue;
|
|
307
313
|
private timer;
|
|
308
314
|
private defaultTags;
|
|
@@ -334,7 +340,7 @@ declare class NewrelicTraceExporter extends TracerExporters.Base {
|
|
|
334
340
|
}
|
|
335
341
|
|
|
336
342
|
type DefaultTags = Record<string, unknown> | ((registry: MetricRegistry) => Record<string, unknown>);
|
|
337
|
-
type NewrelicMetricsOptions = MetricReporterOptions & {
|
|
343
|
+
type NewrelicMetricsOptions = MetricReporters.Base.MetricReporterOptions & {
|
|
338
344
|
/**
|
|
339
345
|
* Base URL for NewRelic server.
|
|
340
346
|
*/
|
|
@@ -358,8 +364,7 @@ type NewrelicMetricsOptions = MetricReporterOptions & {
|
|
|
358
364
|
* NewRelic API: https://docs.newrelic.com/docs/data-apis/understand-data/metric-data/metric-data-type/
|
|
359
365
|
*/
|
|
360
366
|
declare class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
361
|
-
|
|
362
|
-
logger: LoggerInstance;
|
|
367
|
+
private readonly opts;
|
|
363
368
|
private timer;
|
|
364
369
|
private defaultTags;
|
|
365
370
|
constructor(opts: NewrelicMetricsOptions);
|
|
@@ -382,4 +387,4 @@ declare class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
|
382
387
|
}
|
|
383
388
|
|
|
384
389
|
export { AjvExtractor, Alias, COERCE_ARRAY_ATTRIBUTE, CustomActionSchema, CustomServiceSchema, DATE_TYPE, Document, EMPTY_OBJECT_SCHEMA, HealthCheckMiddleware, JSONSchemaType, NewrelicMetricsReporter, NewrelicTraceExporter, OBJECTID_TYPE, OpenAPIExtractor, OpenAPIMixin, OperationObject, RefExtractor, ReferenceObject, SCHEMA_REF_NAME, SchemaObject, ServiceFactory, SomeJSONSchema, addFieldsToSchema, composeSchemas, createLogger, createLoggerConfig, createOpenAPIResponses, createServiceBroker, getMetadataFromService, isServiceSelected, isZodSchema, omitFields, optionalExceptFields, optionalFields, pickFields, toPartialSchema, wrapMixin, wrapService, zodCoerceArray, zodDate, zodObjectId, zodToOpenAPISchema };
|
|
385
|
-
export type { OpenAPIMixinOptions, OpenAPIResponses, Selector };
|
|
390
|
+
export type { OpenAPIMixinOptions, OpenAPIResponses, Selector, _InferredServiceSchema };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { S as SomeJSONSchema, J as JSONSchemaType, C as CustomActionSchema, A as Alias, a as CustomServiceSchema, D as Document, b as SchemaObject, O as OperationObject, R as ReferenceObject, c as CreateLoggerOptions, M as MoleculerLoggerConfigOptions } from './types-
|
|
2
|
-
export { d as AjvValidator, e as ApiKeySecurityScheme, f as CallbackObject, g as ComponentsObject, h as ContactObject, i as ContextFactory, E as EncodingObject, j as ExampleObject, k as ExternalDocumentationObject, H as HeaderObject, l as HttpSecurityScheme, I as InfoObject, m as InternalCallbackServiceThis, n as InternalObjectServiceThis, L as LicenseObject, o as LinkObject, p as MediaTypeObject, q as OAuth2SecurityScheme, r as OpenIdSecurityScheme, P as ParameterBaseObject, s as ParameterObject, t as PathItemObject, u as PathsObject, v as PropertiesSchema, w as RequestBodyObject, x as RequiredMembers, y as ResponseObject, z as ResponsesObject, B as SecurityRequirementObject, F as SecuritySchemeObject, G as ServerObject, K as ServerVariableObject, T as TagObject, N as Transform, Q as TransformField, U as TransformLevel, V as TransformMap, W as Transformer, X as ValidationSchema, Z as ZodValidator } from './types-
|
|
1
|
+
import { S as SomeJSONSchema, J as JSONSchemaType, C as CustomActionSchema, A as Alias, a as CustomServiceSchema, D as Document, b as SchemaObject, O as OperationObject, R as ReferenceObject, c as CreateLoggerOptions, M as MoleculerLoggerConfigOptions } from './types-DLBNHgt4.mjs';
|
|
2
|
+
export { d as AjvValidator, e as ApiKeySecurityScheme, f as CallbackObject, g as ComponentsObject, h as ContactObject, i as ContextFactory, E as EncodingObject, j as ExampleObject, k as ExternalDocumentationObject, H as HeaderObject, l as HttpSecurityScheme, I as InfoObject, m as InternalCallbackServiceThis, n as InternalObjectServiceThis, L as LicenseObject, o as LinkObject, p as MediaTypeObject, q as OAuth2SecurityScheme, r as OpenIdSecurityScheme, P as ParameterBaseObject, s as ParameterObject, t as PathItemObject, u as PathsObject, v as PropertiesSchema, w as RequestBodyObject, x as RequiredMembers, y as ResponseObject, z as ResponsesObject, B as SecurityRequirementObject, F as SecuritySchemeObject, G as ServerObject, K as ServerVariableObject, T as TagObject, N as Transform, Q as TransformField, U as TransformLevel, V as TransformMap, W as Transformer, X as ValidationSchema, Z as ZodValidator } from './types-DLBNHgt4.mjs';
|
|
3
3
|
import { ObjectId } from 'bson';
|
|
4
4
|
import { z, ZodType } from 'zod/v4';
|
|
5
5
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
6
|
-
import
|
|
7
|
-
import { Context, ServiceSchema, ServiceSettingSchema, Service, ServiceBroker, BrokerOptions, Middleware, LoggerConfig, TracerExporters, LoggerInstance, Tracer, Span, MetricReporters, MetricRegistry, MetricReporterOptions } from 'moleculer';
|
|
6
|
+
import { Errors, Context, ServiceSchema, ServiceSettingSchema, Service, ServiceBroker, BrokerOptions, Middleware, LoggerConfig, TracerExporters, Logger as Logger$1, Tracer, Span, MetricReporters, MetricRegistry } from 'moleculer';
|
|
8
7
|
import { Logger } from 'pino';
|
|
9
8
|
import 'pino-pretty';
|
|
10
9
|
|
|
@@ -60,7 +59,7 @@ declare function OpenAPIMixin(options: OpenAPIMixinOptions): Partial<CustomServi
|
|
|
60
59
|
description: string;
|
|
61
60
|
content: {
|
|
62
61
|
'application/json': {
|
|
63
|
-
schema: JSONSchemaType<Omit<
|
|
62
|
+
schema: JSONSchemaType<Omit<Errors.MoleculerServerError, "cause">>;
|
|
64
63
|
};
|
|
65
64
|
};
|
|
66
65
|
};
|
|
@@ -92,7 +91,7 @@ declare function OpenAPIMixin(options: OpenAPIMixinOptions): Partial<CustomServi
|
|
|
92
91
|
description: string;
|
|
93
92
|
content: {
|
|
94
93
|
'application/json': {
|
|
95
|
-
schema: JSONSchemaType<Omit<
|
|
94
|
+
schema: JSONSchemaType<Omit<Errors.ValidationError, "cause">>;
|
|
96
95
|
};
|
|
97
96
|
};
|
|
98
97
|
};
|
|
@@ -201,6 +200,12 @@ declare class AjvExtractor extends RefExtractor {
|
|
|
201
200
|
* For now, only methods are typed.
|
|
202
201
|
*/
|
|
203
202
|
declare function wrapMixin<Settings, Methods, Mixins>(svc: Partial<CustomServiceSchema<Settings, Methods, Mixins>>): typeof svc;
|
|
203
|
+
/**
|
|
204
|
+
* In order to let TS emit types for inferred services, we return our own
|
|
205
|
+
* type that extend the original one.
|
|
206
|
+
* More on why: https://github.com/microsoft/TypeScript/pull/58176#issuecomment-2052698294
|
|
207
|
+
*/
|
|
208
|
+
type _InferredServiceSchema = ServiceSchema;
|
|
204
209
|
/**
|
|
205
210
|
* This function is a NO-OP and is only useful for Typescript types.
|
|
206
211
|
* Using Generic arguments allows TS to infer types directly from the object
|
|
@@ -209,7 +214,7 @@ declare function wrapMixin<Settings, Methods, Mixins>(svc: Partial<CustomService
|
|
|
209
214
|
* For the wrapService fn, it will return a moleculer ServiceSchema that will stripe
|
|
210
215
|
* out every smart typing of methods. This should never be used inside a mixin.
|
|
211
216
|
*/
|
|
212
|
-
declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>):
|
|
217
|
+
declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>): _InferredServiceSchema;
|
|
213
218
|
|
|
214
219
|
/**
|
|
215
220
|
* This class replace the default Service class in Moleculer to:
|
|
@@ -271,7 +276,7 @@ declare function createLogger(opts?: CreateLoggerOptions): Logger;
|
|
|
271
276
|
declare function createLoggerConfig(opts?: MoleculerLoggerConfigOptions): LoggerConfig;
|
|
272
277
|
|
|
273
278
|
type NewrelicTraceExporterOptions = {
|
|
274
|
-
logger?:
|
|
279
|
+
logger?: Logger$1;
|
|
275
280
|
safetyTags?: boolean;
|
|
276
281
|
/**
|
|
277
282
|
* Base URL for NewRelic server.
|
|
@@ -292,7 +297,7 @@ type NewrelicTraceExporterOptions = {
|
|
|
292
297
|
/**
|
|
293
298
|
* Default span tags.
|
|
294
299
|
*/
|
|
295
|
-
defaultTags?: Record<string, unknown> | (() => Record<string, unknown>);
|
|
300
|
+
defaultTags?: Record<string, unknown> | ((tracer?: unknown) => Record<string, unknown>);
|
|
296
301
|
};
|
|
297
302
|
/**
|
|
298
303
|
* >>> Hard copy of the moleculer NewRelic provider. It didn't handle errors correctly
|
|
@@ -303,6 +308,7 @@ type NewrelicTraceExporterOptions = {
|
|
|
303
308
|
* API v2: https://zipkin.io/zipkin-api/#/
|
|
304
309
|
*/
|
|
305
310
|
declare class NewrelicTraceExporter extends TracerExporters.Base {
|
|
311
|
+
private readonly opts;
|
|
306
312
|
private queue;
|
|
307
313
|
private timer;
|
|
308
314
|
private defaultTags;
|
|
@@ -334,7 +340,7 @@ declare class NewrelicTraceExporter extends TracerExporters.Base {
|
|
|
334
340
|
}
|
|
335
341
|
|
|
336
342
|
type DefaultTags = Record<string, unknown> | ((registry: MetricRegistry) => Record<string, unknown>);
|
|
337
|
-
type NewrelicMetricsOptions = MetricReporterOptions & {
|
|
343
|
+
type NewrelicMetricsOptions = MetricReporters.Base.MetricReporterOptions & {
|
|
338
344
|
/**
|
|
339
345
|
* Base URL for NewRelic server.
|
|
340
346
|
*/
|
|
@@ -358,8 +364,7 @@ type NewrelicMetricsOptions = MetricReporterOptions & {
|
|
|
358
364
|
* NewRelic API: https://docs.newrelic.com/docs/data-apis/understand-data/metric-data/metric-data-type/
|
|
359
365
|
*/
|
|
360
366
|
declare class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
361
|
-
|
|
362
|
-
logger: LoggerInstance;
|
|
367
|
+
private readonly opts;
|
|
363
368
|
private timer;
|
|
364
369
|
private defaultTags;
|
|
365
370
|
constructor(opts: NewrelicMetricsOptions);
|
|
@@ -382,4 +387,4 @@ declare class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
|
382
387
|
}
|
|
383
388
|
|
|
384
389
|
export { AjvExtractor, Alias, COERCE_ARRAY_ATTRIBUTE, CustomActionSchema, CustomServiceSchema, DATE_TYPE, Document, EMPTY_OBJECT_SCHEMA, HealthCheckMiddleware, JSONSchemaType, NewrelicMetricsReporter, NewrelicTraceExporter, OBJECTID_TYPE, OpenAPIExtractor, OpenAPIMixin, OperationObject, RefExtractor, ReferenceObject, SCHEMA_REF_NAME, SchemaObject, ServiceFactory, SomeJSONSchema, addFieldsToSchema, composeSchemas, createLogger, createLoggerConfig, createOpenAPIResponses, createServiceBroker, getMetadataFromService, isServiceSelected, isZodSchema, omitFields, optionalExceptFields, optionalFields, pickFields, toPartialSchema, wrapMixin, wrapService, zodCoerceArray, zodDate, zodObjectId, zodToOpenAPISchema };
|
|
385
|
-
export type { OpenAPIMixinOptions, OpenAPIResponses, Selector };
|
|
390
|
+
export type { OpenAPIMixinOptions, OpenAPIResponses, Selector, _InferredServiceSchema };
|