@treatwell/moleculer-essentials 2.0.0-beta.5 → 2.0.0

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 CHANGED
@@ -50,21 +50,20 @@ To complete the TS support and improve the developer experience, we also provide
50
50
 
51
51
  ## Usage
52
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
+
53
56
  ### Basic Example
54
57
 
55
58
  ```ts
56
59
  // src/index.ts
60
+ import { join } from 'node:path';
57
61
  import fg from 'fast-glob';
58
62
  import {
59
- HealthCheckMiddleware,
60
63
  createLoggerConfig,
61
64
  createServiceBroker,
62
- defaultLogger,
63
65
  ZodValidator,
64
66
  } from '@treatwell/moleculer-essentials';
65
- import { fileURLToPath } from 'url';
66
- import { dirname, join } from 'path';
67
- import { config } from 'dotenv';
68
67
 
69
68
  async function run() {
70
69
  // Create Service Broker
@@ -95,7 +94,7 @@ async function run() {
95
94
  }
96
95
 
97
96
  run().catch(err => {
98
- defaultLogger.error('Error while starting server', { err });
97
+ console.error('Error while starting server', { err });
99
98
  process.exit(1);
100
99
  });
101
100
  ```
package/dist/index.d.cts CHANGED
@@ -200,6 +200,12 @@ declare class AjvExtractor extends RefExtractor {
200
200
  * For now, only methods are typed.
201
201
  */
202
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;
203
209
  /**
204
210
  * This function is a NO-OP and is only useful for Typescript types.
205
211
  * Using Generic arguments allows TS to infer types directly from the object
@@ -208,7 +214,7 @@ declare function wrapMixin<Settings, Methods, Mixins>(svc: Partial<CustomService
208
214
  * For the wrapService fn, it will return a moleculer ServiceSchema that will stripe
209
215
  * out every smart typing of methods. This should never be used inside a mixin.
210
216
  */
211
- declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>): ServiceSchema;
217
+ declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>): _InferredServiceSchema;
212
218
 
213
219
  /**
214
220
  * This class replace the default Service class in Moleculer to:
@@ -381,4 +387,4 @@ declare class NewrelicMetricsReporter extends MetricReporters.Base {
381
387
  }
382
388
 
383
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 };
384
- export type { OpenAPIMixinOptions, OpenAPIResponses, Selector };
390
+ export type { OpenAPIMixinOptions, OpenAPIResponses, Selector, _InferredServiceSchema };
package/dist/index.d.mts CHANGED
@@ -200,6 +200,12 @@ declare class AjvExtractor extends RefExtractor {
200
200
  * For now, only methods are typed.
201
201
  */
202
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;
203
209
  /**
204
210
  * This function is a NO-OP and is only useful for Typescript types.
205
211
  * Using Generic arguments allows TS to infer types directly from the object
@@ -208,7 +214,7 @@ declare function wrapMixin<Settings, Methods, Mixins>(svc: Partial<CustomService
208
214
  * For the wrapService fn, it will return a moleculer ServiceSchema that will stripe
209
215
  * out every smart typing of methods. This should never be used inside a mixin.
210
216
  */
211
- declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>): ServiceSchema;
217
+ declare function wrapService<Settings, Methods, Mixins>(svc: CustomServiceSchema<Settings, Methods, Mixins>): _InferredServiceSchema;
212
218
 
213
219
  /**
214
220
  * This class replace the default Service class in Moleculer to:
@@ -381,4 +387,4 @@ declare class NewrelicMetricsReporter extends MetricReporters.Base {
381
387
  }
382
388
 
383
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 };
384
- export type { OpenAPIMixinOptions, OpenAPIResponses, Selector };
390
+ export type { OpenAPIMixinOptions, OpenAPIResponses, Selector, _InferredServiceSchema };
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": "2.0.0-beta.5",
9
+ "version": "2.0.0",
10
10
  "main": "./dist/index.cjs",
11
11
  "module": "./dist/index.mjs",
12
12
  "types": "./dist/index.d.cts",