@treatwell/moleculer-essentials 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-DAz9xV2z.mjs → index-B6AujuxZ.mjs} +18 -8
- package/dist/{index-BuNrZnJ4.cjs → index-CjPjJvVl.cjs} +23 -12
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +6 -6
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +10 -11
- package/dist/mixins/database.mixin.cjs +8 -9
- package/dist/mixins/database.mixin.mjs +8 -9
- package/package.json +16 -16
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { omit, pick } from 'es-toolkit';
|
|
2
|
-
import { z as z$1 } from 'zod/v4';
|
|
3
|
-
import 'es-toolkit/compat';
|
|
4
2
|
import { ObjectId } from 'bson';
|
|
5
3
|
import { parseISO } from 'date-fns';
|
|
6
|
-
import { z } from 'zod';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
|
+
import 'es-toolkit/compat';
|
|
7
6
|
|
|
8
7
|
const COERCE_ARRAY_ATTRIBUTE = "x-coerce-array";
|
|
9
8
|
const SCHEMA_REF_NAME = "$id";
|
|
@@ -239,6 +238,18 @@ const zodObjectId = z.transform((val) => {
|
|
|
239
238
|
function zodCoerceArray(element, params) {
|
|
240
239
|
return z.transform((val) => !Array.isArray(val) && val !== void 0 ? [val] : val).pipe(z.array(element, params));
|
|
241
240
|
}
|
|
241
|
+
function _isZodType(schema) {
|
|
242
|
+
if (!schema || typeof schema !== "object") {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
return "_zod" in schema;
|
|
246
|
+
}
|
|
247
|
+
function isZodSchema(schema, type) {
|
|
248
|
+
if (!_isZodType(schema)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return type ? schema.type === type : true;
|
|
252
|
+
}
|
|
242
253
|
|
|
243
254
|
const ServerErrorSchema = {
|
|
244
255
|
type: "object",
|
|
@@ -322,10 +333,9 @@ const ValidationErrorSchema = {
|
|
|
322
333
|
]
|
|
323
334
|
}
|
|
324
335
|
};
|
|
325
|
-
const GetOpenApiParamsSchema = z
|
|
336
|
+
const GetOpenApiParamsSchema = z.object({ kind: z.string().optional() });
|
|
326
337
|
|
|
327
338
|
function createOpenAPIResponses(model, description = "") {
|
|
328
|
-
const isZodType = model instanceof z$1.ZodType;
|
|
329
339
|
return {
|
|
330
340
|
responses: {
|
|
331
341
|
"200": {
|
|
@@ -335,8 +345,8 @@ function createOpenAPIResponses(model, description = "") {
|
|
|
335
345
|
// @ts-expect-error Moleculer will clone this object using lodash,
|
|
336
346
|
// losing the zod class instance. By using a function, we ensure
|
|
337
347
|
// that clone doesn't break the zod instance
|
|
338
|
-
zodInstance:
|
|
339
|
-
schema:
|
|
348
|
+
zodInstance: isZodSchema(model) ? () => model : void 0,
|
|
349
|
+
schema: isZodSchema(model) ? void 0 : model
|
|
340
350
|
}
|
|
341
351
|
}
|
|
342
352
|
}
|
|
@@ -344,4 +354,4 @@ function createOpenAPIResponses(model, description = "") {
|
|
|
344
354
|
};
|
|
345
355
|
}
|
|
346
356
|
|
|
347
|
-
export { COERCE_ARRAY_ATTRIBUTE as C, DATE_TYPE as D, EMPTY_OBJECT_SCHEMA as E, FileTooBigSchema as F, GetOpenApiParamsSchema as G, OBJECTID_TYPE as O, SCHEMA_REF_NAME as S, UnauthorizedErrorSchema as U, ValidationErrorSchema as V, FileNotExistSchema as a, ServerErrorSchema as b, addFieldsToSchema as c, optionalFields as d, optionalExceptFields as e, composeSchemas as f, zodDate as g, zodObjectId as h,
|
|
357
|
+
export { COERCE_ARRAY_ATTRIBUTE as C, DATE_TYPE as D, EMPTY_OBJECT_SCHEMA as E, FileTooBigSchema as F, GetOpenApiParamsSchema as G, OBJECTID_TYPE as O, SCHEMA_REF_NAME as S, UnauthorizedErrorSchema as U, ValidationErrorSchema as V, FileNotExistSchema as a, ServerErrorSchema as b, addFieldsToSchema as c, optionalFields as d, optionalExceptFields as e, composeSchemas as f, zodDate as g, zodObjectId as h, isZodSchema as i, zodCoerceArray as j, createOpenAPIResponses as k, omitFields as o, pickFields as p, toPartialSchema as t, zodToOpenAPISchema as z };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var esToolkit = require('es-toolkit');
|
|
4
|
-
var v4 = require('zod/v4');
|
|
5
|
-
require('es-toolkit/compat');
|
|
6
4
|
var bson = require('bson');
|
|
7
5
|
var dateFns = require('date-fns');
|
|
8
|
-
var
|
|
6
|
+
var v4 = require('zod/v4');
|
|
7
|
+
require('es-toolkit/compat');
|
|
9
8
|
|
|
10
9
|
const COERCE_ARRAY_ATTRIBUTE = "x-coerce-array";
|
|
11
10
|
const SCHEMA_REF_NAME = "$id";
|
|
@@ -179,7 +178,7 @@ function deepRefReplacer(obj, extractor, currentId = "") {
|
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
function zodToOpenAPISchema(schema, extractor) {
|
|
182
|
-
const res =
|
|
181
|
+
const res = v4.z.toJSONSchema(schema, {
|
|
183
182
|
io: "input",
|
|
184
183
|
unrepresentable: "any",
|
|
185
184
|
override: ({ zodSchema, jsonSchema }) => {
|
|
@@ -219,7 +218,7 @@ function zodToOpenAPISchema(schema, extractor) {
|
|
|
219
218
|
}
|
|
220
219
|
return res;
|
|
221
220
|
}
|
|
222
|
-
const zodDate =
|
|
221
|
+
const zodDate = v4.z.transform((val) => {
|
|
223
222
|
if (typeof val === "string") {
|
|
224
223
|
const date = dateFns.parseISO(val);
|
|
225
224
|
if (!Number.isNaN(date.getTime())) {
|
|
@@ -227,19 +226,31 @@ const zodDate = zod.z.transform((val) => {
|
|
|
227
226
|
}
|
|
228
227
|
}
|
|
229
228
|
return val;
|
|
230
|
-
}).pipe(
|
|
229
|
+
}).pipe(v4.z.date());
|
|
231
230
|
const OBJECT_ID_PATTERN = /^[a-f\d]{24}$/i;
|
|
232
231
|
function isObjectId(val) {
|
|
233
232
|
return val instanceof bson.ObjectId;
|
|
234
233
|
}
|
|
235
|
-
const zodObjectId =
|
|
234
|
+
const zodObjectId = v4.z.transform((val) => {
|
|
236
235
|
if (typeof val === "string" && OBJECT_ID_PATTERN.test(val)) {
|
|
237
236
|
return new bson.ObjectId(val);
|
|
238
237
|
}
|
|
239
238
|
return val;
|
|
240
|
-
}).pipe(
|
|
239
|
+
}).pipe(v4.z.custom(isObjectId, { abort: true })).meta({ id: "ObjectId" });
|
|
241
240
|
function zodCoerceArray(element, params) {
|
|
242
|
-
return
|
|
241
|
+
return v4.z.transform((val) => !Array.isArray(val) && val !== void 0 ? [val] : val).pipe(v4.z.array(element, params));
|
|
242
|
+
}
|
|
243
|
+
function _isZodType(schema) {
|
|
244
|
+
if (!schema || typeof schema !== "object") {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return "_zod" in schema;
|
|
248
|
+
}
|
|
249
|
+
function isZodSchema(schema, type) {
|
|
250
|
+
if (!_isZodType(schema)) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
return type ? schema.type === type : true;
|
|
243
254
|
}
|
|
244
255
|
|
|
245
256
|
const ServerErrorSchema = {
|
|
@@ -327,7 +338,6 @@ const ValidationErrorSchema = {
|
|
|
327
338
|
const GetOpenApiParamsSchema = v4.z.object({ kind: v4.z.string().optional() });
|
|
328
339
|
|
|
329
340
|
function createOpenAPIResponses(model, description = "") {
|
|
330
|
-
const isZodType = model instanceof v4.z.ZodType;
|
|
331
341
|
return {
|
|
332
342
|
responses: {
|
|
333
343
|
"200": {
|
|
@@ -337,8 +347,8 @@ function createOpenAPIResponses(model, description = "") {
|
|
|
337
347
|
// @ts-expect-error Moleculer will clone this object using lodash,
|
|
338
348
|
// losing the zod class instance. By using a function, we ensure
|
|
339
349
|
// that clone doesn't break the zod instance
|
|
340
|
-
zodInstance:
|
|
341
|
-
schema:
|
|
350
|
+
zodInstance: isZodSchema(model) ? () => model : void 0,
|
|
351
|
+
schema: isZodSchema(model) ? void 0 : model
|
|
342
352
|
}
|
|
343
353
|
}
|
|
344
354
|
}
|
|
@@ -360,6 +370,7 @@ exports.ValidationErrorSchema = ValidationErrorSchema;
|
|
|
360
370
|
exports.addFieldsToSchema = addFieldsToSchema;
|
|
361
371
|
exports.composeSchemas = composeSchemas;
|
|
362
372
|
exports.createOpenAPIResponses = createOpenAPIResponses;
|
|
373
|
+
exports.isZodSchema = isZodSchema;
|
|
363
374
|
exports.omitFields = omitFields;
|
|
364
375
|
exports.optionalExceptFields = optionalExceptFields;
|
|
365
376
|
exports.optionalFields = optionalFields;
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
4
|
-
var v4 = require('zod/v4');
|
|
3
|
+
var index = require('./index-CjPjJvVl.cjs');
|
|
5
4
|
var _2019_js = require('ajv/dist/2019.js');
|
|
6
5
|
var moleculer = require('moleculer');
|
|
7
6
|
var addFormats = require('ajv-formats');
|
|
@@ -9,12 +8,12 @@ var addKeywords = require('ajv-keywords');
|
|
|
9
8
|
var esToolkit = require('es-toolkit');
|
|
10
9
|
var dateFns = require('date-fns');
|
|
11
10
|
var bson = require('bson');
|
|
11
|
+
var v4 = require('zod/v4');
|
|
12
12
|
var index$1 = require('./index-82e1CXJX.cjs');
|
|
13
13
|
var compat = require('es-toolkit/compat');
|
|
14
14
|
var http = require('http');
|
|
15
15
|
var pino = require('pino');
|
|
16
16
|
var node_os = require('node:os');
|
|
17
|
-
require('zod');
|
|
18
17
|
|
|
19
18
|
function getSchemaFromMoleculer(schema) {
|
|
20
19
|
if (!schema) {
|
|
@@ -191,7 +190,7 @@ function createOperationFromAlias(alias, extractor, url) {
|
|
|
191
190
|
extractor.setMeta({ url, alias });
|
|
192
191
|
const pathParams = url.match(/{(\w+)}/g) || [];
|
|
193
192
|
const params = getSchemaFromMoleculer(alias.action.params);
|
|
194
|
-
if (params
|
|
193
|
+
if (index.isZodSchema(params)) {
|
|
195
194
|
({ parameters, requestBody } = createOperationFromZodParams(
|
|
196
195
|
params,
|
|
197
196
|
pathParams,
|
|
@@ -306,7 +305,7 @@ function createOperationFromAjvParams(params, pathParams, alias, extractor) {
|
|
|
306
305
|
function createOperationFromZodParams(params, pathParams, alias, extractor) {
|
|
307
306
|
const parameters = [];
|
|
308
307
|
let requestBody;
|
|
309
|
-
if (!(params
|
|
308
|
+
if (!index.isZodSchema(params, "object")) {
|
|
310
309
|
throw new Error(
|
|
311
310
|
`Expected params to be an ZodObject in ${alias.actionName}`
|
|
312
311
|
);
|
|
@@ -330,7 +329,7 @@ function createOperationFromZodParams(params, pathParams, alias, extractor) {
|
|
|
330
329
|
in: "query",
|
|
331
330
|
name: key,
|
|
332
331
|
schema: index.zodToOpenAPISchema(val, extractor),
|
|
333
|
-
required: !(val
|
|
332
|
+
required: !index.isZodSchema(val, "optional")
|
|
334
333
|
}))
|
|
335
334
|
);
|
|
336
335
|
} else if (params) {
|
|
@@ -763,7 +762,7 @@ class AjvValidator extends moleculer.Validators.Base {
|
|
|
763
762
|
}
|
|
764
763
|
}
|
|
765
764
|
validate(params, schema) {
|
|
766
|
-
if (schema
|
|
765
|
+
if (index.isZodSchema(schema)) {
|
|
767
766
|
if (!this.zodValidator) {
|
|
768
767
|
throw new Error("No validator to handle zod schemas");
|
|
769
768
|
}
|
|
@@ -861,7 +860,7 @@ ${(errors || []).map(
|
|
|
861
860
|
if (!schema) {
|
|
862
861
|
return handler;
|
|
863
862
|
}
|
|
864
|
-
if (schema
|
|
863
|
+
if (index.isZodSchema(schema)) {
|
|
865
864
|
return zodMiddleware.localAction(
|
|
866
865
|
handler,
|
|
867
866
|
action
|
|
@@ -878,7 +877,7 @@ ${(errors || []).map(
|
|
|
878
877
|
if (!schema) {
|
|
879
878
|
return handler;
|
|
880
879
|
}
|
|
881
|
-
if (schema
|
|
880
|
+
if (index.isZodSchema(schema)) {
|
|
882
881
|
return zodMiddleware.localEvent(
|
|
883
882
|
handler,
|
|
884
883
|
event
|
|
@@ -1602,6 +1601,7 @@ exports.SCHEMA_REF_NAME = index.SCHEMA_REF_NAME;
|
|
|
1602
1601
|
exports.addFieldsToSchema = index.addFieldsToSchema;
|
|
1603
1602
|
exports.composeSchemas = index.composeSchemas;
|
|
1604
1603
|
exports.createOpenAPIResponses = index.createOpenAPIResponses;
|
|
1604
|
+
exports.isZodSchema = index.isZodSchema;
|
|
1605
1605
|
exports.omitFields = index.omitFields;
|
|
1606
1606
|
exports.optionalExceptFields = index.optionalExceptFields;
|
|
1607
1607
|
exports.optionalFields = index.optionalFields;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { J as JSONSchemaType, S as SomeJSONSchema, C as CustomActionSchema, A as Alias, a as CustomServiceSchema, D as Document, b as SchemaObject, O as OperationObject, R as ReferenceObject } from './index-IHCgtNKZ.cjs';
|
|
2
2
|
export { d as AjvValidator, x as ApiKeySecurityScheme, F as CallbackObject, G as ComponentsObject, j as ContactObject, i as ContextFactory, q as EncodingObject, p as ExampleObject, E as ExternalDocumentationObject, H as HeaderObject, w as HttpSecurityScheme, I as InfoObject, L as LicenseObject, s as LinkObject, M as MediaTypeObject, y as OAuth2SecurityScheme, z as OpenIdSecurityScheme, o as ParameterBaseObject, n as ParameterObject, N as PathItemObject, m as PathsObject, P as PropertiesSchema, r as RequestBodyObject, c as RequiredMembers, t as ResponseObject, u as ResponsesObject, v as SecurityRequirementObject, B as SecuritySchemeObject, l as ServerObject, k as ServerVariableObject, K as TagObject, e as Transform, h as TransformField, f as TransformLevel, g as TransformMap, T as Transformer, V as ValidationSchema, Z as ZodValidator, Q as createLogger, U as createLoggerConfig, W as defaultLogger } from './index-IHCgtNKZ.cjs';
|
|
3
3
|
import { ObjectId } from 'bson';
|
|
4
|
-
import {
|
|
5
|
-
import { z } from 'zod/v4';
|
|
4
|
+
import { z, ZodType } from 'zod/v4';
|
|
6
5
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
7
6
|
import * as Moleculer from 'moleculer';
|
|
8
7
|
import { Context, ServiceSchema, ServiceSettingSchema, Service, ServiceBroker, BrokerOptions, Middleware, TracerExporters, LoggerInstance, Tracer, Span, MetricReporters, MetricRegistry, MetricReporterOptions } from 'moleculer';
|
|
@@ -174,9 +173,10 @@ declare function createOpenAPIResponses(model: OpenAPIResponses, description?: s
|
|
|
174
173
|
* For this, you should use helpers provided by this package.
|
|
175
174
|
*/
|
|
176
175
|
declare function zodToOpenAPISchema(schema: ZodType, extractor: OpenAPIExtractor): SchemaObject | ReferenceObject;
|
|
177
|
-
declare const zodDate: z
|
|
178
|
-
declare const zodObjectId: z
|
|
179
|
-
declare function zodCoerceArray<T extends ZodType>(element: T, params?: Parameters<typeof z
|
|
176
|
+
declare const zodDate: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDate>;
|
|
177
|
+
declare const zodObjectId: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodCustom<ObjectId, ObjectId>>;
|
|
178
|
+
declare function zodCoerceArray<T extends ZodType>(element: T, params?: Parameters<typeof z.array>[1]): z.ZodPipe<z.ZodTransform<any[] | undefined, unknown>, z.ZodArray<T>>;
|
|
179
|
+
declare function isZodSchema<S extends z.ZodType>(schema: unknown, type?: S['type']): schema is S;
|
|
180
180
|
|
|
181
181
|
declare class AjvExtractor extends RefExtractor {
|
|
182
182
|
private readonly ajv;
|
|
@@ -365,5 +365,5 @@ declare class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
|
365
365
|
generateMetricsPayload(): unknown[];
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
-
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, createOpenAPIResponses, createServiceBroker, getMetadataFromService, isServiceSelected, omitFields, optionalExceptFields, optionalFields, pickFields, toPartialSchema, wrapMixin, wrapService, zodCoerceArray, zodDate, zodObjectId, zodToOpenAPISchema };
|
|
368
|
+
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, createOpenAPIResponses, createServiceBroker, getMetadataFromService, isServiceSelected, isZodSchema, omitFields, optionalExceptFields, optionalFields, pickFields, toPartialSchema, wrapMixin, wrapService, zodCoerceArray, zodDate, zodObjectId, zodToOpenAPISchema };
|
|
369
369
|
export type { OpenAPIMixinOptions, OpenAPIResponses, Selector };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { J as JSONSchemaType, S as SomeJSONSchema, C as CustomActionSchema, A as Alias, a as CustomServiceSchema, D as Document, b as SchemaObject, O as OperationObject, R as ReferenceObject } from './index-IHCgtNKZ.mjs';
|
|
2
2
|
export { d as AjvValidator, x as ApiKeySecurityScheme, F as CallbackObject, G as ComponentsObject, j as ContactObject, i as ContextFactory, q as EncodingObject, p as ExampleObject, E as ExternalDocumentationObject, H as HeaderObject, w as HttpSecurityScheme, I as InfoObject, L as LicenseObject, s as LinkObject, M as MediaTypeObject, y as OAuth2SecurityScheme, z as OpenIdSecurityScheme, o as ParameterBaseObject, n as ParameterObject, N as PathItemObject, m as PathsObject, P as PropertiesSchema, r as RequestBodyObject, c as RequiredMembers, t as ResponseObject, u as ResponsesObject, v as SecurityRequirementObject, B as SecuritySchemeObject, l as ServerObject, k as ServerVariableObject, K as TagObject, e as Transform, h as TransformField, f as TransformLevel, g as TransformMap, T as Transformer, V as ValidationSchema, Z as ZodValidator, Q as createLogger, U as createLoggerConfig, W as defaultLogger } from './index-IHCgtNKZ.mjs';
|
|
3
3
|
import { ObjectId } from 'bson';
|
|
4
|
-
import {
|
|
5
|
-
import { z } from 'zod/v4';
|
|
4
|
+
import { z, ZodType } from 'zod/v4';
|
|
6
5
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
7
6
|
import * as Moleculer from 'moleculer';
|
|
8
7
|
import { Context, ServiceSchema, ServiceSettingSchema, Service, ServiceBroker, BrokerOptions, Middleware, TracerExporters, LoggerInstance, Tracer, Span, MetricReporters, MetricRegistry, MetricReporterOptions } from 'moleculer';
|
|
@@ -174,9 +173,10 @@ declare function createOpenAPIResponses(model: OpenAPIResponses, description?: s
|
|
|
174
173
|
* For this, you should use helpers provided by this package.
|
|
175
174
|
*/
|
|
176
175
|
declare function zodToOpenAPISchema(schema: ZodType, extractor: OpenAPIExtractor): SchemaObject | ReferenceObject;
|
|
177
|
-
declare const zodDate: z
|
|
178
|
-
declare const zodObjectId: z
|
|
179
|
-
declare function zodCoerceArray<T extends ZodType>(element: T, params?: Parameters<typeof z
|
|
176
|
+
declare const zodDate: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDate>;
|
|
177
|
+
declare const zodObjectId: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodCustom<ObjectId, ObjectId>>;
|
|
178
|
+
declare function zodCoerceArray<T extends ZodType>(element: T, params?: Parameters<typeof z.array>[1]): z.ZodPipe<z.ZodTransform<any[] | undefined, unknown>, z.ZodArray<T>>;
|
|
179
|
+
declare function isZodSchema<S extends z.ZodType>(schema: unknown, type?: S['type']): schema is S;
|
|
180
180
|
|
|
181
181
|
declare class AjvExtractor extends RefExtractor {
|
|
182
182
|
private readonly ajv;
|
|
@@ -365,5 +365,5 @@ declare class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
|
365
365
|
generateMetricsPayload(): unknown[];
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
-
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, createOpenAPIResponses, createServiceBroker, getMetadataFromService, isServiceSelected, omitFields, optionalExceptFields, optionalFields, pickFields, toPartialSchema, wrapMixin, wrapService, zodCoerceArray, zodDate, zodObjectId, zodToOpenAPISchema };
|
|
368
|
+
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, createOpenAPIResponses, createServiceBroker, getMetadataFromService, isServiceSelected, isZodSchema, omitFields, optionalExceptFields, optionalFields, pickFields, toPartialSchema, wrapMixin, wrapService, zodCoerceArray, zodDate, zodObjectId, zodToOpenAPISchema };
|
|
369
369
|
export type { OpenAPIMixinOptions, OpenAPIResponses, Selector };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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-
|
|
2
|
-
export { D as DATE_TYPE, E as EMPTY_OBJECT_SCHEMA, O as OBJECTID_TYPE, c as addFieldsToSchema, f as composeSchemas,
|
|
3
|
-
import { ZodType, ZodObject, ZodOptional, z } from 'zod/v4';
|
|
1
|
+
import { S as SCHEMA_REF_NAME, i as isZodSchema, 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-B6AujuxZ.mjs';
|
|
2
|
+
export { D as DATE_TYPE, E as EMPTY_OBJECT_SCHEMA, O as OBJECTID_TYPE, c as addFieldsToSchema, f as composeSchemas, k as createOpenAPIResponses, e as optionalExceptFields, d as optionalFields, p as pickFields, t as toPartialSchema, j as zodCoerceArray, g as zodDate, h as zodObjectId } from './index-B6AujuxZ.mjs';
|
|
4
3
|
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
5
4
|
import { Validators, Errors, Context, ServiceBroker, Service, TracerExporters, MetricReporters } from 'moleculer';
|
|
6
5
|
import addFormats from 'ajv-formats';
|
|
@@ -8,13 +7,13 @@ import addKeywords from 'ajv-keywords';
|
|
|
8
7
|
import { omit, isEqual, isPlainObject } from 'es-toolkit';
|
|
9
8
|
import { parseISO } from 'date-fns';
|
|
10
9
|
import { ObjectId } from 'bson';
|
|
10
|
+
import { z } from 'zod/v4';
|
|
11
11
|
import { w as wrapMixin } from './index-DNJWwcZu.mjs';
|
|
12
12
|
export { a as wrapService } from './index-DNJWwcZu.mjs';
|
|
13
13
|
import { merge, defaultsDeep, isObject } from 'es-toolkit/compat';
|
|
14
14
|
import http, { STATUS_CODES } from 'http';
|
|
15
15
|
import { pino } from 'pino';
|
|
16
16
|
import { hostname } from 'node:os';
|
|
17
|
-
import 'zod';
|
|
18
17
|
|
|
19
18
|
function getSchemaFromMoleculer(schema) {
|
|
20
19
|
if (!schema) {
|
|
@@ -191,7 +190,7 @@ function createOperationFromAlias(alias, extractor, url) {
|
|
|
191
190
|
extractor.setMeta({ url, alias });
|
|
192
191
|
const pathParams = url.match(/{(\w+)}/g) || [];
|
|
193
192
|
const params = getSchemaFromMoleculer(alias.action.params);
|
|
194
|
-
if (params
|
|
193
|
+
if (isZodSchema(params)) {
|
|
195
194
|
({ parameters, requestBody } = createOperationFromZodParams(
|
|
196
195
|
params,
|
|
197
196
|
pathParams,
|
|
@@ -306,7 +305,7 @@ function createOperationFromAjvParams(params, pathParams, alias, extractor) {
|
|
|
306
305
|
function createOperationFromZodParams(params, pathParams, alias, extractor) {
|
|
307
306
|
const parameters = [];
|
|
308
307
|
let requestBody;
|
|
309
|
-
if (!(params
|
|
308
|
+
if (!isZodSchema(params, "object")) {
|
|
310
309
|
throw new Error(
|
|
311
310
|
`Expected params to be an ZodObject in ${alias.actionName}`
|
|
312
311
|
);
|
|
@@ -330,7 +329,7 @@ function createOperationFromZodParams(params, pathParams, alias, extractor) {
|
|
|
330
329
|
in: "query",
|
|
331
330
|
name: key,
|
|
332
331
|
schema: zodToOpenAPISchema(val, extractor),
|
|
333
|
-
required: !(val
|
|
332
|
+
required: !isZodSchema(val, "optional")
|
|
334
333
|
}))
|
|
335
334
|
);
|
|
336
335
|
} else if (params) {
|
|
@@ -763,7 +762,7 @@ class AjvValidator extends Validators.Base {
|
|
|
763
762
|
}
|
|
764
763
|
}
|
|
765
764
|
validate(params, schema) {
|
|
766
|
-
if (schema
|
|
765
|
+
if (isZodSchema(schema)) {
|
|
767
766
|
if (!this.zodValidator) {
|
|
768
767
|
throw new Error("No validator to handle zod schemas");
|
|
769
768
|
}
|
|
@@ -861,7 +860,7 @@ ${(errors || []).map(
|
|
|
861
860
|
if (!schema) {
|
|
862
861
|
return handler;
|
|
863
862
|
}
|
|
864
|
-
if (schema
|
|
863
|
+
if (isZodSchema(schema)) {
|
|
865
864
|
return zodMiddleware.localAction(
|
|
866
865
|
handler,
|
|
867
866
|
action
|
|
@@ -878,7 +877,7 @@ ${(errors || []).map(
|
|
|
878
877
|
if (!schema) {
|
|
879
878
|
return handler;
|
|
880
879
|
}
|
|
881
|
-
if (schema
|
|
880
|
+
if (isZodSchema(schema)) {
|
|
882
881
|
return zodMiddleware.localEvent(
|
|
883
882
|
handler,
|
|
884
883
|
event
|
|
@@ -1594,4 +1593,4 @@ class NewrelicMetricsReporter extends MetricReporters.Base {
|
|
|
1594
1593
|
}
|
|
1595
1594
|
}
|
|
1596
1595
|
|
|
1597
|
-
export { AjvExtractor, AjvValidator, COERCE_ARRAY_ATTRIBUTE, ContextFactory, HealthCheckMiddleware, NewrelicMetricsReporter, NewrelicTraceExporter, OpenAPIExtractor, OpenAPIMixin, RefExtractor, SCHEMA_REF_NAME, ServiceFactory, ZodValidator, createLogger, createLoggerConfig, createServiceBroker, defaultLogger, getMetadataFromService, isServiceSelected, omitFields, wrapMixin, zodToOpenAPISchema };
|
|
1596
|
+
export { AjvExtractor, AjvValidator, COERCE_ARRAY_ATTRIBUTE, ContextFactory, HealthCheckMiddleware, NewrelicMetricsReporter, NewrelicTraceExporter, OpenAPIExtractor, OpenAPIMixin, RefExtractor, SCHEMA_REF_NAME, ServiceFactory, ZodValidator, createLogger, createLoggerConfig, createServiceBroker, defaultLogger, getMetadataFromService, isServiceSelected, isZodSchema, omitFields, wrapMixin, zodToOpenAPISchema };
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var index = require('../index-BuNrZnJ4.cjs');
|
|
3
|
+
var index = require('../index-CjPjJvVl.cjs');
|
|
5
4
|
var moleculer = require('moleculer');
|
|
6
5
|
var esToolkit = require('es-toolkit');
|
|
6
|
+
var v4 = require('zod/v4');
|
|
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');
|
|
10
10
|
var compat = require('es-toolkit/compat');
|
|
11
11
|
require('bson');
|
|
12
12
|
require('date-fns');
|
|
13
|
-
require('zod');
|
|
14
13
|
|
|
15
14
|
const { MoleculerClientError } = moleculer.Errors;
|
|
16
15
|
class EntityNotFoundError extends MoleculerClientError {
|
|
@@ -324,7 +323,7 @@ function parseAndValidateQuery(validator, schema, sQuery) {
|
|
|
324
323
|
return {};
|
|
325
324
|
}
|
|
326
325
|
let query = parseStringifiedQuery(sQuery);
|
|
327
|
-
if (schema
|
|
326
|
+
if (index.isZodSchema(schema)) {
|
|
328
327
|
query = validator.validate(query, schema);
|
|
329
328
|
} else {
|
|
330
329
|
validator.validate(query, schema);
|
|
@@ -338,7 +337,7 @@ class ZodActionSchemaFactory {
|
|
|
338
337
|
this.opts = opts;
|
|
339
338
|
const { schema, tenantField } = opts;
|
|
340
339
|
if (schema) {
|
|
341
|
-
if (!(schema
|
|
340
|
+
if (!index.isZodSchema(schema, "object")) {
|
|
342
341
|
throw new Error("Schema must be a ZodObject");
|
|
343
342
|
}
|
|
344
343
|
if (tenantField) {
|
|
@@ -361,7 +360,7 @@ class ZodActionSchemaFactory {
|
|
|
361
360
|
return this.schemaWithDbFields;
|
|
362
361
|
}
|
|
363
362
|
const { timestamps, schema, schemaName } = this.opts;
|
|
364
|
-
if (!
|
|
363
|
+
if (!index.isZodSchema(schema, "object")) {
|
|
365
364
|
throw new Error("Schema is not a ZodObject");
|
|
366
365
|
}
|
|
367
366
|
let res = schema.required({ _id: true });
|
|
@@ -463,7 +462,7 @@ class ZodActionSchemaFactory {
|
|
|
463
462
|
createCreateParams(params) {
|
|
464
463
|
const { schema } = this.opts;
|
|
465
464
|
const { allowClientId } = params;
|
|
466
|
-
if (!
|
|
465
|
+
if (!index.isZodSchema(schema, "object")) {
|
|
467
466
|
throw new Error("Schema is not a ZodObject");
|
|
468
467
|
}
|
|
469
468
|
if (allowClientId) {
|
|
@@ -473,7 +472,7 @@ class ZodActionSchemaFactory {
|
|
|
473
472
|
}
|
|
474
473
|
createUpdateParams() {
|
|
475
474
|
const { tenantField, schema } = this.opts;
|
|
476
|
-
if (!
|
|
475
|
+
if (!index.isZodSchema(schema, "object")) {
|
|
477
476
|
throw new Error("Schema is not a ZodObject");
|
|
478
477
|
}
|
|
479
478
|
const mask = { _id: true };
|
|
@@ -516,7 +515,7 @@ const PUBLISHABLE_ACTIONS = [
|
|
|
516
515
|
];
|
|
517
516
|
function createActions(opts) {
|
|
518
517
|
const actions = {};
|
|
519
|
-
const factory = opts.actions?.schemaFactory || (opts.actions?.schema
|
|
518
|
+
const factory = opts.actions?.schemaFactory || (index.isZodSchema(opts.actions?.schema) ? new ZodActionSchemaFactory({
|
|
520
519
|
schemaName: opts.actions.schemaName,
|
|
521
520
|
schema: opts.actions.schema,
|
|
522
521
|
timestamps: opts.timestamps,
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
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-DAz9xV2z.mjs';
|
|
1
|
+
import { o as omitFields, d as optionalFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, i as isZodSchema, h as zodObjectId, j as zodCoerceArray, k as createOpenAPIResponses } from '../index-B6AujuxZ.mjs';
|
|
3
2
|
import { Errors } from 'moleculer';
|
|
4
3
|
import { isEqual as isEqual$1 } from 'es-toolkit';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
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';
|
|
8
8
|
import { isMatch, isEqual } from 'es-toolkit/compat';
|
|
9
9
|
import 'bson';
|
|
10
10
|
import 'date-fns';
|
|
11
|
-
import 'zod';
|
|
12
11
|
|
|
13
12
|
const { MoleculerClientError } = Errors;
|
|
14
13
|
class EntityNotFoundError extends MoleculerClientError {
|
|
@@ -322,7 +321,7 @@ function parseAndValidateQuery(validator, schema, sQuery) {
|
|
|
322
321
|
return {};
|
|
323
322
|
}
|
|
324
323
|
let query = parseStringifiedQuery(sQuery);
|
|
325
|
-
if (schema
|
|
324
|
+
if (isZodSchema(schema)) {
|
|
326
325
|
query = validator.validate(query, schema);
|
|
327
326
|
} else {
|
|
328
327
|
validator.validate(query, schema);
|
|
@@ -336,7 +335,7 @@ class ZodActionSchemaFactory {
|
|
|
336
335
|
this.opts = opts;
|
|
337
336
|
const { schema, tenantField } = opts;
|
|
338
337
|
if (schema) {
|
|
339
|
-
if (!(schema
|
|
338
|
+
if (!isZodSchema(schema, "object")) {
|
|
340
339
|
throw new Error("Schema must be a ZodObject");
|
|
341
340
|
}
|
|
342
341
|
if (tenantField) {
|
|
@@ -359,7 +358,7 @@ class ZodActionSchemaFactory {
|
|
|
359
358
|
return this.schemaWithDbFields;
|
|
360
359
|
}
|
|
361
360
|
const { timestamps, schema, schemaName } = this.opts;
|
|
362
|
-
if (!
|
|
361
|
+
if (!isZodSchema(schema, "object")) {
|
|
363
362
|
throw new Error("Schema is not a ZodObject");
|
|
364
363
|
}
|
|
365
364
|
let res = schema.required({ _id: true });
|
|
@@ -461,7 +460,7 @@ class ZodActionSchemaFactory {
|
|
|
461
460
|
createCreateParams(params) {
|
|
462
461
|
const { schema } = this.opts;
|
|
463
462
|
const { allowClientId } = params;
|
|
464
|
-
if (!
|
|
463
|
+
if (!isZodSchema(schema, "object")) {
|
|
465
464
|
throw new Error("Schema is not a ZodObject");
|
|
466
465
|
}
|
|
467
466
|
if (allowClientId) {
|
|
@@ -471,7 +470,7 @@ class ZodActionSchemaFactory {
|
|
|
471
470
|
}
|
|
472
471
|
createUpdateParams() {
|
|
473
472
|
const { tenantField, schema } = this.opts;
|
|
474
|
-
if (!
|
|
473
|
+
if (!isZodSchema(schema, "object")) {
|
|
475
474
|
throw new Error("Schema is not a ZodObject");
|
|
476
475
|
}
|
|
477
476
|
const mask = { _id: true };
|
|
@@ -514,7 +513,7 @@ const PUBLISHABLE_ACTIONS = [
|
|
|
514
513
|
];
|
|
515
514
|
function createActions(opts) {
|
|
516
515
|
const actions = {};
|
|
517
|
-
const factory = opts.actions?.schemaFactory || (opts.actions?.schema
|
|
516
|
+
const factory = opts.actions?.schemaFactory || (isZodSchema(opts.actions?.schema) ? new ZodActionSchemaFactory({
|
|
518
517
|
schemaName: opts.actions.schemaName,
|
|
519
518
|
schema: opts.actions.schema,
|
|
520
519
|
timestamps: opts.timestamps,
|
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.2.
|
|
9
|
+
"version": "1.2.4",
|
|
10
10
|
"main": "./dist/index.cjs",
|
|
11
11
|
"module": "./dist/index.mjs",
|
|
12
12
|
"types": "./dist/index.d.cts",
|
|
@@ -148,33 +148,33 @@
|
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"@aws-crypto/client-node": "^4.2.1",
|
|
151
|
-
"@eslint/js": "^9.
|
|
151
|
+
"@eslint/js": "^9.36.0",
|
|
152
152
|
"@treatwell/eslint-plugin-moleculer": "^1.1.0",
|
|
153
153
|
"@tsconfig/node-lts": "^22.0.2",
|
|
154
154
|
"@types/jsonwebtoken": "^9.0.10",
|
|
155
|
-
"@types/node": "^24.
|
|
155
|
+
"@types/node": "^24.6.1",
|
|
156
156
|
"@types/redlock": "^4.0.7",
|
|
157
|
-
"bullmq": "^5.
|
|
158
|
-
"eslint": "^9.
|
|
157
|
+
"bullmq": "^5.59.0",
|
|
158
|
+
"eslint": "^9.36.0",
|
|
159
159
|
"eslint-config-prettier": "^10.1.8",
|
|
160
160
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
161
161
|
"eslint-plugin-import": "^2.32.0",
|
|
162
162
|
"eslint-plugin-prettier": "^5.5.4",
|
|
163
|
-
"ioredis": "^5.
|
|
164
|
-
"jiti": "^2.
|
|
163
|
+
"ioredis": "^5.8.0",
|
|
164
|
+
"jiti": "^2.6.1",
|
|
165
165
|
"jsonwebtoken": "^9.0.2",
|
|
166
|
-
"jwks-rsa": "^3.0
|
|
167
|
-
"moleculer": "^0.14.
|
|
168
|
-
"mongodb": "^6.
|
|
169
|
-
"mongodb-memory-server": "^10.2.
|
|
170
|
-
"pkgroll": "^2.15.
|
|
166
|
+
"jwks-rsa": "^3.2.0",
|
|
167
|
+
"moleculer": "^0.14.35",
|
|
168
|
+
"mongodb": "^6.20.0",
|
|
169
|
+
"mongodb-memory-server": "^10.2.1",
|
|
170
|
+
"pkgroll": "^2.15.4",
|
|
171
171
|
"prettier": "^3.6.2",
|
|
172
172
|
"redlock": "^4.2.0",
|
|
173
|
-
"semantic-release": "^24.2.
|
|
174
|
-
"typescript": "~5.9.
|
|
175
|
-
"typescript-eslint": "^8.
|
|
173
|
+
"semantic-release": "^24.2.9",
|
|
174
|
+
"typescript": "~5.9.3",
|
|
175
|
+
"typescript-eslint": "^8.45.0",
|
|
176
176
|
"vitest": "^3.2.4",
|
|
177
|
-
"zod": "^4.1.
|
|
177
|
+
"zod": "^4.1.11"
|
|
178
178
|
},
|
|
179
179
|
"files": [
|
|
180
180
|
"dist"
|