imean-service-engine 1.2.0 → 1.2.2

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.
Files changed (3) hide show
  1. package/dist/mod.cjs +28 -32
  2. package/dist/mod.js +28 -32
  3. package/package.json +4 -6
package/dist/mod.cjs CHANGED
@@ -284,6 +284,9 @@ function getZodTypeString(schema, defaultOptional = false) {
284
284
  case "ZodObject": {
285
285
  const shape = def.shape();
286
286
  const props = Object.entries(shape).map(([key, value]) => {
287
+ if (key.includes("-")) {
288
+ key = `'${key}'`;
289
+ }
287
290
  const fieldDef = value._def;
288
291
  const isOptional = fieldDef.typeName === "ZodOptional";
289
292
  const isDefault = defaultOptional && fieldDef.typeName === "ZodDefault";
@@ -310,10 +313,14 @@ function getZodTypeString(schema, defaultOptional = false) {
310
313
  return "void";
311
314
  }
312
315
  case "ZodRecord": {
313
- return `Record<${processType(def.keyType)}, ${processType(def.valueType)}>`;
316
+ return `Record<${processType(def.keyType)}, ${processType(
317
+ def.valueType
318
+ )}>`;
314
319
  }
315
320
  case "ZodMap": {
316
- return `Map<${processType(def.keyType)}, ${processType(def.valueType)}>`;
321
+ return `Map<${processType(def.keyType)}, ${processType(
322
+ def.valueType
323
+ )}>`;
317
324
  }
318
325
  case "ZodAny": {
319
326
  return "any";
@@ -354,7 +361,10 @@ async function generateClientCode(modules) {
354
361
  }
355
362
  const params = action.params.map((param, index) => {
356
363
  const name2 = param.description || `arg${index}`;
357
- return `${name2}${param.isOptional() ? "?" : ""}: ${getZodTypeString(param, true)}`;
364
+ return `${name2}${param.isOptional() ? "?" : ""}: ${getZodTypeString(
365
+ param,
366
+ true
367
+ )}`;
358
368
  }).join(", ");
359
369
  const returnType = action.returns ? getZodTypeString(action.returns) : "void";
360
370
  return `
@@ -378,11 +388,7 @@ async function generateClientCode(modules) {
378
388
  });`;
379
389
  }).join("\n\n ")}
380
390
  }`;
381
- return await formatCode([
382
- imports,
383
- interfaces,
384
- clientClass
385
- ].join("\n\n"));
391
+ return await formatCode([imports, interfaces, clientClass].join("\n\n"));
386
392
  }
387
393
  function hashText(text) {
388
394
  const hash = crypto2__default.default.createHash("sha256");
@@ -430,6 +436,13 @@ var ActionHandler = class {
430
436
  span.setAttribute("action", this.actionName);
431
437
  try {
432
438
  return await this._handle(req);
439
+ } catch (error) {
440
+ span.recordException(error);
441
+ span.setStatus({
442
+ code: api.SpanStatusCode.ERROR,
443
+ message: error.message
444
+ });
445
+ throw error;
433
446
  } finally {
434
447
  span.end();
435
448
  }
@@ -495,26 +508,14 @@ var ActionHandler = class {
495
508
  const iterator = result[Symbol.asyncIterator]();
496
509
  return {
497
510
  async next() {
498
- try {
499
- const { value, done } = await iterator.next();
500
- span?.addEvent("stream.next");
501
- if (!done) count++;
502
- if (done) {
503
- span?.setAttribute("streamCount", count);
504
- span?.addEvent("stream.end");
505
- span?.end();
506
- }
507
- return { value, done };
508
- } catch (error) {
509
- span?.addEvent("stream.error", { error: error.message });
510
- span?.recordException(error);
511
- span?.setStatus({
512
- code: api.SpanStatusCode.ERROR,
513
- message: error.message
514
- });
515
- span?.end();
516
- throw error;
511
+ const { value, done } = await iterator.next();
512
+ span?.addEvent("stream.next");
513
+ if (!done) count++;
514
+ if (done) {
515
+ span?.setAttribute("streamCount", count);
516
+ span?.addEvent("stream.end");
517
517
  }
518
+ return { value, done };
518
519
  }
519
520
  };
520
521
  }
@@ -540,16 +541,11 @@ var ActionHandler = class {
540
541
  { ttl: this.metadata.ttl }
541
542
  );
542
543
  }
543
- span?.setStatus({ code: api.SpanStatusCode.OK, message: "success" });
544
- span?.end();
545
544
  return parsedResult;
546
545
  } catch (error) {
547
546
  if (this.metadata.printError !== false && this.microservice.options.printError !== false) {
548
547
  console.error(`Error in ${this.moduleName}.${this.actionName}:`, error);
549
548
  }
550
- span?.recordException(error);
551
- span?.setStatus({ code: api.SpanStatusCode.ERROR, message: error.message });
552
- span?.end();
553
549
  throw error;
554
550
  }
555
551
  }
package/dist/mod.js CHANGED
@@ -275,6 +275,9 @@ function getZodTypeString(schema, defaultOptional = false) {
275
275
  case "ZodObject": {
276
276
  const shape = def.shape();
277
277
  const props = Object.entries(shape).map(([key, value]) => {
278
+ if (key.includes("-")) {
279
+ key = `'${key}'`;
280
+ }
278
281
  const fieldDef = value._def;
279
282
  const isOptional = fieldDef.typeName === "ZodOptional";
280
283
  const isDefault = defaultOptional && fieldDef.typeName === "ZodDefault";
@@ -301,10 +304,14 @@ function getZodTypeString(schema, defaultOptional = false) {
301
304
  return "void";
302
305
  }
303
306
  case "ZodRecord": {
304
- return `Record<${processType(def.keyType)}, ${processType(def.valueType)}>`;
307
+ return `Record<${processType(def.keyType)}, ${processType(
308
+ def.valueType
309
+ )}>`;
305
310
  }
306
311
  case "ZodMap": {
307
- return `Map<${processType(def.keyType)}, ${processType(def.valueType)}>`;
312
+ return `Map<${processType(def.keyType)}, ${processType(
313
+ def.valueType
314
+ )}>`;
308
315
  }
309
316
  case "ZodAny": {
310
317
  return "any";
@@ -345,7 +352,10 @@ async function generateClientCode(modules) {
345
352
  }
346
353
  const params = action.params.map((param, index) => {
347
354
  const name2 = param.description || `arg${index}`;
348
- return `${name2}${param.isOptional() ? "?" : ""}: ${getZodTypeString(param, true)}`;
355
+ return `${name2}${param.isOptional() ? "?" : ""}: ${getZodTypeString(
356
+ param,
357
+ true
358
+ )}`;
349
359
  }).join(", ");
350
360
  const returnType = action.returns ? getZodTypeString(action.returns) : "void";
351
361
  return `
@@ -369,11 +379,7 @@ async function generateClientCode(modules) {
369
379
  });`;
370
380
  }).join("\n\n ")}
371
381
  }`;
372
- return await formatCode([
373
- imports,
374
- interfaces,
375
- clientClass
376
- ].join("\n\n"));
382
+ return await formatCode([imports, interfaces, clientClass].join("\n\n"));
377
383
  }
378
384
  function hashText(text) {
379
385
  const hash = crypto2.createHash("sha256");
@@ -421,6 +427,13 @@ var ActionHandler = class {
421
427
  span.setAttribute("action", this.actionName);
422
428
  try {
423
429
  return await this._handle(req);
430
+ } catch (error) {
431
+ span.recordException(error);
432
+ span.setStatus({
433
+ code: SpanStatusCode.ERROR,
434
+ message: error.message
435
+ });
436
+ throw error;
424
437
  } finally {
425
438
  span.end();
426
439
  }
@@ -486,26 +499,14 @@ var ActionHandler = class {
486
499
  const iterator = result[Symbol.asyncIterator]();
487
500
  return {
488
501
  async next() {
489
- try {
490
- const { value, done } = await iterator.next();
491
- span?.addEvent("stream.next");
492
- if (!done) count++;
493
- if (done) {
494
- span?.setAttribute("streamCount", count);
495
- span?.addEvent("stream.end");
496
- span?.end();
497
- }
498
- return { value, done };
499
- } catch (error) {
500
- span?.addEvent("stream.error", { error: error.message });
501
- span?.recordException(error);
502
- span?.setStatus({
503
- code: SpanStatusCode.ERROR,
504
- message: error.message
505
- });
506
- span?.end();
507
- throw error;
502
+ const { value, done } = await iterator.next();
503
+ span?.addEvent("stream.next");
504
+ if (!done) count++;
505
+ if (done) {
506
+ span?.setAttribute("streamCount", count);
507
+ span?.addEvent("stream.end");
508
508
  }
509
+ return { value, done };
509
510
  }
510
511
  };
511
512
  }
@@ -531,16 +532,11 @@ var ActionHandler = class {
531
532
  { ttl: this.metadata.ttl }
532
533
  );
533
534
  }
534
- span?.setStatus({ code: SpanStatusCode.OK, message: "success" });
535
- span?.end();
536
535
  return parsedResult;
537
536
  } catch (error) {
538
537
  if (this.metadata.printError !== false && this.microservice.options.printError !== false) {
539
538
  console.error(`Error in ${this.moduleName}.${this.actionName}:`, error);
540
539
  }
541
- span?.recordException(error);
542
- span?.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
543
- span?.end();
544
540
  throw error;
545
541
  }
546
542
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imean-service-engine",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "microservice engine",
5
5
  "keywords": [
6
6
  "microservice",
@@ -31,12 +31,9 @@
31
31
  "LICENSE"
32
32
  ],
33
33
  "scripts": {
34
- "dev": "tsx dev/index.ts",
34
+ "dev": "tsx watch dev/index.ts",
35
35
  "build": "tsup",
36
- "lint": "deno lint",
37
- "fmt": "deno fmt",
38
- "test": "vitest",
39
- "coverage": "vitest --coverage",
36
+ "test": "vitest run",
40
37
  "prepublishOnly": "npm run build && npm run test"
41
38
  },
42
39
  "dependencies": {
@@ -69,6 +66,7 @@
69
66
  "@types/ejson": "^2.2.2",
70
67
  "@types/fs-extra": "^11.0.4",
71
68
  "@types/node": "^20.0.0",
69
+ "@vitest/coverage-v8": "^3.0.4",
72
70
  "imean-service-client": "^1.5.0",
73
71
  "opentelemetry-instrumentation-fetch-node": "^1.2.3",
74
72
  "tslib": "^2.8.1",