@nudojs/service 3.0.0 → 4.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.
Files changed (2) hide show
  1. package/dist/index.js +12 -10
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1902,7 +1902,8 @@ function validateMockDirectives(directives, diagnostics) {
1902
1902
  for (const d of directives) {
1903
1903
  if (d.kind !== "mock" || !d.expression) continue;
1904
1904
  const expr = d.expression.trim();
1905
- if (expr.includes("(") && expr.includes(")") && !expr.startsWith("T.")) {
1905
+ const isTypeExpr = /^(number|string|boolean|any|array|shape|lit|union|fn|partial|pick|omit|record|required|readonly|nonNullable|and)\s*\(/.test(expr) || expr === "unknown" || expr === "any" || expr === "never" || expr === "true" || expr === "false" || expr === "null" || expr === "undefined" || /^-?\d+(\.\d+)?$/.test(expr) || (expr.startsWith('"') && expr.endsWith('"') || expr.startsWith("'") && expr.endsWith("'")) || expr.startsWith("{") || expr.startsWith("[");
1906
+ if (expr.includes("(") && expr.includes(")") && !isTypeExpr && !expr.includes("=>")) {
1906
1907
  diagnostics.push({
1907
1908
  range: { start: { line: 0, column: 0 }, end: { line: 0, column: 0 } },
1908
1909
  severity: "warning",
@@ -1910,7 +1911,8 @@ function validateMockDirectives(directives, diagnostics) {
1910
1911
  code: "nudo:mock-invalid",
1911
1912
  suggestions: [
1912
1913
  "Supported formats: stub(), stub().returns(value), spy(), mock()",
1913
- "Arrow functions: (args) => expression or (args) => { statements; return value; }"
1914
+ "Arrow functions: (args) => expression or (args) => { statements; return value; }",
1915
+ "Type expressions: number(), string(), shape({...}), union(...), or concrete literals"
1914
1916
  ]
1915
1917
  });
1916
1918
  }
@@ -2891,7 +2893,7 @@ function analyzeFileUncachedInner(filePath, source, activeCases, externalCallRec
2891
2893
  diagnostics.push({
2892
2894
  range: { start: { line: directive.commentLine, column: 0 }, end: { line: directive.commentLine, column: 999 } },
2893
2895
  severity: "error",
2894
- message: `Case "${directive.name}": expected ${formatShape2(directive.expected)}, got ${formatShape2(caseAbs)}. The inferred return type does not match the expected type declared in the @nudo:case directive`,
2896
+ message: `debug "${directive.name}": expected ${formatShape2(directive.expected)}, got ${formatShape2(caseAbs)}. The inferred return type does not match the expected type declared in the @nudo:case witness`,
2895
2897
  code: "nudo:case-expected"
2896
2898
  });
2897
2899
  }
@@ -5293,15 +5295,15 @@ function serializeCaseArg(a) {
5293
5295
  }
5294
5296
  switch (s.k) {
5295
5297
  case "prim":
5296
- if (s.type === "number" || s.type === "string" || s.type === "boolean") {
5297
- return `T.${s.type}`;
5298
- }
5298
+ if (s.type === "number") return "number()";
5299
+ if (s.type === "string") return "string()";
5300
+ if (s.type === "boolean") return "boolean()";
5299
5301
  return null;
5300
5302
  case "unknown":
5301
5303
  case "any":
5302
- return "T.unknown";
5304
+ return "any()";
5303
5305
  case "never":
5304
- return "T.never";
5306
+ return "never";
5305
5307
  case "sum": {
5306
5308
  const parts = [];
5307
5309
  for (const member of s.members) {
@@ -5309,11 +5311,11 @@ function serializeCaseArg(a) {
5309
5311
  if (ser === null) return null;
5310
5312
  parts.push(ser);
5311
5313
  }
5312
- return `T.union(${parts.join(", ")})`;
5314
+ return `union(${parts.join(", ")})`;
5313
5315
  }
5314
5316
  case "arr": {
5315
5317
  const el = serializeCaseArg(s.element);
5316
- return el === null ? null : `T.array(${el})`;
5318
+ return el === null ? null : `array(${el})`;
5317
5319
  }
5318
5320
  case "tuple": {
5319
5321
  const parts = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nudojs/service",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -45,10 +45,10 @@
45
45
  "dependencies": {
46
46
  "@babel/traverse": "^7.29.0",
47
47
  "@babel/types": "^7.29.0",
48
- "@nudojs/core": "2.0.1",
49
- "@nudojs/parser": "0.5.1",
50
- "@nudojs/env": "0.4.0",
51
- "@nudojs/harvester": "0.2.6"
48
+ "@nudojs/core": "2.1.0",
49
+ "@nudojs/parser": "1.0.0",
50
+ "@nudojs/env": "0.4.1",
51
+ "@nudojs/harvester": "0.2.7"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tsup src/index.ts src/evaluator/evaluator-api.ts --format esm --dts"