@treatwell/moleculer-essentials 1.0.0 → 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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var lodash = require('lodash');
3
+ var lodashEs = require('lodash-es');
4
4
  var v4 = require('zod/v4');
5
5
  var bson = require('bson');
6
6
  var dateFns = require('date-fns');
@@ -45,7 +45,7 @@ function omitFields(schema, fields, refName) {
45
45
  ...schema,
46
46
  [SCHEMA_REF_NAME]: refName,
47
47
  required: schema.required.filter((f) => !fields.includes(f)),
48
- properties: lodash.omit(schema.properties, fields)
48
+ properties: lodashEs.omit(schema.properties, fields)
49
49
  };
50
50
  }
51
51
  function pickFields(schema, fields, refName) {
@@ -68,7 +68,7 @@ function pickFields(schema, fields, refName) {
68
68
  ...schema,
69
69
  [SCHEMA_REF_NAME]: refName,
70
70
  required: schema.required.filter((f) => fields.includes(f)),
71
- properties: lodash.pick(schema.properties, fields)
71
+ properties: lodashEs.pick(schema.properties, fields)
72
72
  };
73
73
  }
74
74
  function optionalExceptFields(schema, fields, refName) {
@@ -1,4 +1,4 @@
1
- import { omit, pick } from 'lodash';
1
+ import { omit, pick } from 'lodash-es';
2
2
  import { z as z$1 } from 'zod/v4';
3
3
  import { ObjectId } from 'bson';
4
4
  import { parseISO } from 'date-fns';
package/dist/index.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-rZl77S1z.cjs');
3
+ var index = require('./index-CXpoxJ9R.cjs');
4
4
  var v4 = require('zod/v4');
5
5
  var _2019_js = require('ajv/dist/2019.js');
6
6
  var moleculer = require('moleculer');
7
7
  var addFormats = require('ajv-formats');
8
8
  var addKeywords = require('ajv-keywords');
9
- var lodash = require('lodash');
9
+ var lodashEs = require('lodash-es');
10
10
  var dateFns = require('date-fns');
11
11
  var bson = require('bson');
12
12
  var index$1 = require('./index-82e1CXJX.cjs');
@@ -63,12 +63,12 @@ class RefExtractor {
63
63
  if (!this.refs.has(schemaRefName)) {
64
64
  this.refs.set(schemaRefName, null);
65
65
  }
66
- const newSchema2 = walk(lodash.omit(curr, [index.SCHEMA_REF_NAME, "nullable"]), ref);
66
+ const newSchema2 = walk(lodashEs.omit(curr, [index.SCHEMA_REF_NAME, "nullable"]), ref);
67
67
  const registeredSchema = this.refs.get(schemaRefName);
68
68
  if (registeredSchema === null) {
69
69
  this.refs.set(schemaRefName, newSchema2);
70
70
  this.onNewRef(schemaRefName, newSchema2);
71
- } else if (!lodash.isEqual(newSchema2, registeredSchema)) {
71
+ } else if (!lodashEs.isEqual(newSchema2, registeredSchema)) {
72
72
  this.onError(
73
73
  `Schema ${schemaRefName} is already defined with different content`,
74
74
  { registeredSchema, newSchema: newSchema2 }
@@ -145,7 +145,7 @@ function generateOpenAPISpec({
145
145
  services,
146
146
  getSecuritySchemes
147
147
  }) {
148
- services.forEach((svc) => lodash.merge(doc, svc.settings?.openapi));
148
+ services.forEach((svc) => lodashEs.merge(doc, svc.settings?.openapi));
149
149
  const extractor = new OpenAPIExtractor(doc);
150
150
  if (doc.components?.schemas) {
151
151
  const { schemas } = doc.components;
@@ -555,7 +555,7 @@ class LeafTransformerBase {
555
555
 
556
556
  class CoerceArrayTransformer extends LeafTransformerBase {
557
557
  beforeTransformer = (val) => {
558
- if (lodash.isArray(val) || val === null) {
558
+ if (lodashEs.isArray(val) || val === null) {
559
559
  return val;
560
560
  }
561
561
  return [val];
@@ -573,11 +573,11 @@ class DateTransformer extends LeafTransformerBase {
573
573
  return val;
574
574
  };
575
575
  afterTransformer = (val) => {
576
- if (!lodash.isString(val)) {
576
+ if (!lodashEs.isString(val)) {
577
577
  return val;
578
578
  }
579
579
  const date = dateFns.parseISO(val);
580
- if (lodash.isNaN(date.getTime())) {
580
+ if (lodashEs.isNaN(date.getTime())) {
581
581
  return val;
582
582
  }
583
583
  return date;
@@ -595,7 +595,7 @@ class ObjectIdTransformer extends LeafTransformerBase {
595
595
  return val;
596
596
  };
597
597
  afterTransformer = (val) => {
598
- if (lodash.isString(val) && /^[a-f\d]{24}$/i.test(val)) {
598
+ if (lodashEs.isString(val) && /^[a-f\d]{24}$/i.test(val)) {
599
599
  return new bson.ObjectId(val);
600
600
  }
601
601
  return val;
@@ -612,7 +612,7 @@ function applyTransform(parent, dataKey, transformer, transformField, index) {
612
612
  const transformLevel = transformField[index];
613
613
  switch (transformLevel.type) {
614
614
  case "this": {
615
- if (!lodash.isPlainObject(parent) && !lodash.isArray(parent)) {
615
+ if (!lodashEs.isPlainObject(parent) && !lodashEs.isArray(parent)) {
616
616
  return;
617
617
  }
618
618
  if (parent.hasOwnProperty(dataKey)) {
@@ -621,7 +621,7 @@ function applyTransform(parent, dataKey, transformer, transformField, index) {
621
621
  break;
622
622
  }
623
623
  case "access":
624
- if (!lodash.isPlainObject(parent[dataKey])) {
624
+ if (!lodashEs.isPlainObject(parent[dataKey])) {
625
625
  return;
626
626
  }
627
627
  applyTransform(
@@ -638,7 +638,7 @@ function applyTransform(parent, dataKey, transformer, transformField, index) {
638
638
  }
639
639
  break;
640
640
  case "loop": {
641
- if (!lodash.isArray(parent[dataKey])) {
641
+ if (!lodashEs.isArray(parent[dataKey])) {
642
642
  return;
643
643
  }
644
644
  const cast = parent[dataKey];
@@ -744,7 +744,7 @@ class AjvValidator extends moleculer.Validators.Base {
744
744
  });
745
745
  validator.addFormat("object-id", {
746
746
  type: "string",
747
- validate: lodash.constant(true)
747
+ validate: lodashEs.constant(true)
748
748
  });
749
749
  }
750
750
  }
@@ -1062,11 +1062,11 @@ function getMetadataFromService(svc) {
1062
1062
  const res = {
1063
1063
  name: svc.name || "unknown"
1064
1064
  };
1065
- lodash.defaultsDeep(res, svc.metadata);
1065
+ lodashEs.defaultsDeep(res, svc.metadata);
1066
1066
  svc.mixins?.forEach((mixin) => {
1067
- lodash.defaultsDeep(res, mixin.metadata);
1067
+ lodashEs.defaultsDeep(res, mixin.metadata);
1068
1068
  mixin.mixins?.forEach((m) => {
1069
- lodash.defaultsDeep(res, getMetadataFromService(m));
1069
+ lodashEs.defaultsDeep(res, getMetadataFromService(m));
1070
1070
  });
1071
1071
  });
1072
1072
  return res;
@@ -1079,7 +1079,7 @@ const DEFAULT_OPTIONS = {
1079
1079
  liveness: { path: "/live" }
1080
1080
  };
1081
1081
  function HealthCheckMiddleware(_opts) {
1082
- const opts = lodash.defaultsDeep(_opts, DEFAULT_OPTIONS);
1082
+ const opts = lodashEs.defaultsDeep(_opts, DEFAULT_OPTIONS);
1083
1083
  let state = "down";
1084
1084
  let server;
1085
1085
  function handler(req, res) {
@@ -1245,7 +1245,7 @@ function flattenTags(obj, convertToString = false, path = "") {
1245
1245
  return Object.keys(obj).reduce((res, k) => {
1246
1246
  const o = obj[k];
1247
1247
  const pp = (path ? `${path}.` : "") + k;
1248
- if (lodash.isObject(o)) {
1248
+ if (lodashEs.isObject(o)) {
1249
1249
  if ("toHexString" in o) {
1250
1250
  res[pp] = o.toString();
1251
1251
  } else {
@@ -1264,7 +1264,7 @@ class NewrelicTraceExporter extends moleculer.TracerExporters.Base {
1264
1264
  defaultTags = {};
1265
1265
  constructor(opts) {
1266
1266
  super(opts);
1267
- this.opts = lodash.defaultsDeep(this.opts, {
1267
+ this.opts = lodashEs.defaultsDeep(this.opts, {
1268
1268
  baseURL: process.env.NEW_RELIC_TRACE_API_URL || "https://trace-api.newrelic.com",
1269
1269
  batchSize: 1e3,
1270
1270
  insertKey: "",
@@ -1282,7 +1282,7 @@ class NewrelicTraceExporter extends moleculer.TracerExporters.Base {
1282
1282
  this.timer = setInterval(() => this.flush(), this.opts.interval * 1e3);
1283
1283
  this.timer.unref();
1284
1284
  }
1285
- this.defaultTags = lodash.isFunction(this.opts.defaultTags) ? this.opts.defaultTags.call(this, tracer) : this.opts.defaultTags;
1285
+ this.defaultTags = lodashEs.isFunction(this.opts.defaultTags) ? this.opts.defaultTags.call(this, tracer) : this.opts.defaultTags;
1286
1286
  if (this.defaultTags) {
1287
1287
  this.defaultTags = flattenTags(this.defaultTags, true);
1288
1288
  }
@@ -1382,7 +1382,7 @@ class NewrelicMetricsReporter extends moleculer.MetricReporters.Base {
1382
1382
  defaultTags = {};
1383
1383
  constructor(opts) {
1384
1384
  super(opts);
1385
- this.opts = lodash.defaultsDeep(this.opts, {
1385
+ this.opts = lodashEs.defaultsDeep(this.opts, {
1386
1386
  baseURL: process.env.NEW_RELIC_METRICS_API_URL || "https://metric-api.newrelic.com",
1387
1387
  insertKey: "",
1388
1388
  interval: 10
@@ -1397,7 +1397,7 @@ class NewrelicMetricsReporter extends moleculer.MetricReporters.Base {
1397
1397
  this.timer = setInterval(() => this.flush(), this.opts.interval * 1e3);
1398
1398
  this.timer.unref();
1399
1399
  }
1400
- const defaultTags = lodash.isFunction(this.opts.defaultTags) ? this.opts.defaultTags.call(this, registry) : this.opts.defaultTags;
1400
+ const defaultTags = lodashEs.isFunction(this.opts.defaultTags) ? this.opts.defaultTags.call(this, registry) : this.opts.defaultTags;
1401
1401
  if (defaultTags) {
1402
1402
  this.defaultTags = flattenTags(defaultTags, true);
1403
1403
  }
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import { S as SCHEMA_REF_NAME, z as zodToOpenAPISchema, o as omitFields, G as GetOpenApiParamsSchema, V as ValidationErrorSchema, F as FileTooBigSchema, a as FileNotExistSchema, U as UnauthorizedErrorSchema, b as ServerErrorSchema, C as COERCE_ARRAY_ATTRIBUTE } from './index-BV1ZqQrU.mjs';
2
- export { D as DATE_TYPE, E as EMPTY_OBJECT_SCHEMA, O as OBJECTID_TYPE, c as addFieldsToSchema, f as composeSchemas, j as createOpenAPIResponses, e as optionalExceptFields, d as optionalFields, p as pickFields, t as toPartialSchema, i as zodCoerceArray, g as zodDate, h as zodObjectId } from './index-BV1ZqQrU.mjs';
1
+ import { S as SCHEMA_REF_NAME, z as zodToOpenAPISchema, o as omitFields, G as GetOpenApiParamsSchema, V as ValidationErrorSchema, F as FileTooBigSchema, a as FileNotExistSchema, U as UnauthorizedErrorSchema, b as ServerErrorSchema, C as COERCE_ARRAY_ATTRIBUTE } from './index-Lfmmf1DE.mjs';
2
+ export { D as DATE_TYPE, E as EMPTY_OBJECT_SCHEMA, O as OBJECTID_TYPE, c as addFieldsToSchema, f as composeSchemas, j as createOpenAPIResponses, e as optionalExceptFields, d as optionalFields, p as pickFields, t as toPartialSchema, i as zodCoerceArray, g as zodDate, h as zodObjectId } from './index-Lfmmf1DE.mjs';
3
3
  import { ZodType, ZodObject, ZodOptional, z } from 'zod/v4';
4
4
  import { Ajv2019 } from 'ajv/dist/2019.js';
5
5
  import { Validators, Errors, Context, ServiceBroker, Service, TracerExporters, MetricReporters } from 'moleculer';
6
6
  import addFormats from 'ajv-formats';
7
7
  import addKeywords from 'ajv-keywords';
8
- import { omit, isEqual, merge, isArray, isString, isNaN, isPlainObject, constant, defaultsDeep, isObject, isFunction } from 'lodash';
8
+ import { omit, isEqual, merge, isArray, isString, isNaN, isPlainObject, constant, defaultsDeep, isObject, isFunction } from 'lodash-es';
9
9
  import { parseISO } from 'date-fns';
10
10
  import { ObjectId } from 'bson';
11
11
  import { w as wrapMixin } from './index-DNJWwcZu.mjs';
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var v4 = require('zod/v4');
4
- var index = require('../index-rZl77S1z.cjs');
4
+ var index = require('../index-CXpoxJ9R.cjs');
5
5
  var moleculer = require('moleculer');
6
- var lodash = require('lodash');
6
+ var lodashEs = require('lodash-es');
7
7
  var mongodb = require('mongodb');
8
8
  var index$1 = require('../index-82e1CXJX.cjs');
9
9
  var mixins_globalStore_mixin = require('./global-store.mixin.cjs');
@@ -835,14 +835,14 @@ function isIndexEqual(dbIdx, idx) {
835
835
  if (!dbIdx.collation || !opts?.collation) {
836
836
  return false;
837
837
  }
838
- if (!lodash.isMatch(dbIdx.collation, opts.collation)) {
838
+ if (!lodashEs.isMatch(dbIdx.collation, opts.collation)) {
839
839
  return false;
840
840
  }
841
841
  }
842
842
  if (Boolean(dbIdx.sparse) !== Boolean(opts?.sparse)) {
843
843
  return false;
844
844
  }
845
- return dbIdx.expireAfterSeconds === opts?.expireAfterSeconds && dbIdx.unique === opts?.unique && lodash.isEqual(dbIdx.partialFilterExpression, opts?.partialFilterExpression);
845
+ return dbIdx.expireAfterSeconds === opts?.expireAfterSeconds && dbIdx.unique === opts?.unique && lodashEs.isEqual(dbIdx.partialFilterExpression, opts?.partialFilterExpression);
846
846
  }
847
847
  function isOnAtlas() {
848
848
  return (MONGO_URL || MONGODB_URL).includes(".mongodb.net");
@@ -945,7 +945,7 @@ async function getIndexesDifference(collection, declaredIndexes = [], declaredSe
945
945
  });
946
946
  } else {
947
947
  const [dbIdx] = searchIndexes.splice(dbIdxPos, 1);
948
- if (!lodash.isEqual(dbIdx.latestDefinition, idx)) {
948
+ if (!lodashEs.isEqual(dbIdx.latestDefinition, idx)) {
949
949
  states.push({
950
950
  type: "searchIndex",
951
951
  name,
@@ -1115,18 +1115,18 @@ function filterObjectFields(obj, fields) {
1115
1115
  return obj;
1116
1116
  }
1117
1117
  let res = obj;
1118
- const [fieldsRemove, fieldsAdd] = lodash.partition(
1118
+ const [fieldsRemove, fieldsAdd] = lodashEs.partition(
1119
1119
  fields || [],
1120
1120
  (f) => f.startsWith("-")
1121
1121
  );
1122
1122
  if (fieldsRemove.length) {
1123
- res = lodash.omit(
1123
+ res = lodashEs.omit(
1124
1124
  res,
1125
1125
  fieldsRemove.map((f) => f.substring(1))
1126
1126
  );
1127
1127
  }
1128
1128
  if (fieldsAdd.length) {
1129
- res = lodash.pick(res, fieldsAdd);
1129
+ res = lodashEs.pick(res, fieldsAdd);
1130
1130
  }
1131
1131
  return res;
1132
1132
  }
@@ -1,7 +1,7 @@
1
1
  import { ZodType, z, ZodObject } from 'zod/v4';
2
- import { o as omitFields, d as optionalFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, h as zodObjectId, i as zodCoerceArray, j as createOpenAPIResponses } from '../index-BV1ZqQrU.mjs';
2
+ import { o as omitFields, d as optionalFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, h as zodObjectId, i as zodCoerceArray, j as createOpenAPIResponses } from '../index-Lfmmf1DE.mjs';
3
3
  import { Errors } from 'moleculer';
4
- import { isMatch, isEqual, partition, omit, pick } from 'lodash';
4
+ import { isMatch, isEqual, partition, omit, pick } from 'lodash-es';
5
5
  import { MongoClient } from 'mongodb';
6
6
  import { w as wrapMixin } from '../index-DNJWwcZu.mjs';
7
7
  import { GlobalStoreMixin } from './global-store.mixin.mjs';
@@ -2,7 +2,7 @@
2
2
 
3
3
  var moleculer = require('moleculer');
4
4
  var bullmq = require('bullmq');
5
- var lodash = require('lodash');
5
+ var lodashEs = require('lodash-es');
6
6
  var index = require('../index-82e1CXJX.cjs');
7
7
  var mixins_globalStore_mixin = require('./global-store.mixin.cjs');
8
8
  var ioredis = require('ioredis');
@@ -81,7 +81,7 @@ function QueueClient(queueName, opts) {
81
81
  `Queue client '${queueName}' already exists on service '${this.name}'`
82
82
  );
83
83
  }
84
- const key = lodash.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
84
+ const key = lodashEs.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
85
85
  this[kKey] = key;
86
86
  let connection = this.getFromStore("redis", key);
87
87
  if (!connection) {
@@ -163,7 +163,7 @@ function QueueEventsClient(queueName, opts) {
163
163
  `Queue client '${queueName}' already exists on service '${this.name}'`
164
164
  );
165
165
  }
166
- const key = lodash.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
166
+ const key = lodashEs.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
167
167
  this[kKey] = key;
168
168
  let connection = this.getFromStore("redis", key);
169
169
  if (!connection) {
@@ -214,7 +214,7 @@ function QueueFlowProducerMixin(opts) {
214
214
  `Queue Flow producer already exists on service '${this.name}'`
215
215
  );
216
216
  }
217
- const url = lodash.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
217
+ const url = lodashEs.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
218
218
  const connection = createRedisConnection(url);
219
219
  this.$flowProducer = new bullmq.FlowProducer({ connection, ...opts });
220
220
  this[kConnection$1] = connection;
@@ -259,7 +259,7 @@ function QueueStaticRepeatableJobs(queueName, jobs, opts) {
259
259
  mixins: [mixins_globalStore_mixin.GlobalStoreMixin()],
260
260
  methods: {
261
261
  async registerRepeatableJobs() {
262
- const key = lodash.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
262
+ const key = lodashEs.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
263
263
  this[kKey] = key;
264
264
  let connection = this.getFromStore("redis", key);
265
265
  if (!connection) {
@@ -384,7 +384,7 @@ function QueueWorker(queueName, opts, processorOptions = {}) {
384
384
  `A QueueWorker mixin was already on service '${this.name}'`
385
385
  );
386
386
  }
387
- const url = lodash.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
387
+ const url = lodashEs.isFunction(opts.brokerURL) ? await opts.brokerURL(this) : opts.brokerURL;
388
388
  const connection = createRedisConnection(url);
389
389
  const worker = new bullmq.Worker(queueName, this.processJob.bind(this), {
390
390
  connection,
@@ -1,6 +1,6 @@
1
1
  import { Errors } from 'moleculer';
2
2
  import { Queue, QueueEvents, FlowProducer, Worker } from 'bullmq';
3
- import { isFunction } from 'lodash';
3
+ import { isFunction } from 'lodash-es';
4
4
  import { w as wrapMixin } from '../index-DNJWwcZu.mjs';
5
5
  import { GlobalStoreMixin } from './global-store.mixin.mjs';
6
6
  import { Redis } from 'ioredis';
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "type": "git",
7
7
  "url": "https://github.com/treatwell/moleculer-essentials"
8
8
  },
9
- "version": "1.0.0",
9
+ "version": "1.0.1",
10
10
  "main": "./dist/index.cjs",
11
11
  "module": "./dist/index.mjs",
12
12
  "types": "./dist/index.d.cts",
@@ -97,7 +97,7 @@
97
97
  "prepack": "run build",
98
98
  "test": "vitest",
99
99
  "test:types": "tsc --noEmit",
100
- "test:lint": "eslint . --max-warnings=0 && prettier -c ."
100
+ "test:lint": "prettier -c . && eslint . --max-warnings=0"
101
101
  },
102
102
  "dependencies": {
103
103
  "ajv": "^8.12.0",
@@ -105,7 +105,7 @@
105
105
  "ajv-keywords": "^5.1.0",
106
106
  "bson": "^6.2.0",
107
107
  "date-fns": "^2.21.3",
108
- "lodash": "^4.17.20",
108
+ "lodash-es": "^4.17.21",
109
109
  "moleculer": "^0.14.33",
110
110
  "pino": "^8.20.0",
111
111
  "pino-pretty": "^11.0.0"
@@ -149,7 +149,7 @@
149
149
  "@treatwell/eslint-plugin-moleculer": "^1.1.0",
150
150
  "@tsconfig/node-lts": "^22.0.2",
151
151
  "@types/jsonwebtoken": "^9.0.10",
152
- "@types/lodash": "^4.17.20",
152
+ "@types/lodash-es": "^4.17.12",
153
153
  "@types/node": "^24.3.0",
154
154
  "@types/redlock": "^4.0.2",
155
155
  "bullmq": "^5.12.10",