@webpieces/api-doc-model 0.4.830 → 0.4.832

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/api-doc-model",
3
- "version": "0.4.830",
3
+ "version": "0.4.832",
4
4
  "description": "TypeScript-compiler-API extractor producing one in-memory ApiDocModel from a webpieces API contract. No renderer, no runtime, no app-specific import.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -23,7 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@webpieces/core-util": "0.4.830",
26
+ "@webpieces/core-util": "0.4.832",
27
27
  "typescript": "5.9.3"
28
28
  }
29
29
  }
@@ -36,6 +36,8 @@ export declare class PackageOfFile {
36
36
  of(fileName: string): DeclaringPackage | undefined;
37
37
  private ofDirectory;
38
38
  private parentOf;
39
+ /** A `package.json`, or the ONE error type of this package naming it when it is not JSON. */
40
+ private static parse;
39
41
  /** The package whose `package.json` sits in `directory`, when it is one with a name. */
40
42
  private read;
41
43
  }
@@ -4,6 +4,7 @@ exports.PackageOfFile = exports.DeclaringPackage = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("node:fs"));
6
6
  const path = tslib_1.__importStar(require("node:path"));
7
+ const ApiDocExtractionError_1 = require("./ApiDocExtractionError");
7
8
  /** The npm package a source file belongs to: the nearest `package.json` above it. Data-only. */
8
9
  class DeclaringPackage {
9
10
  name;
@@ -56,13 +57,25 @@ class PackageOfFile {
56
57
  const parent = path.dirname(directory);
57
58
  return parent === directory ? undefined : this.ofDirectory(parent);
58
59
  }
60
+ /** A `package.json`, or the ONE error type of this package naming it when it is not JSON. */
61
+ // webpieces-disable no-function-outside-class -- private static reader of this class
62
+ static parse(file) {
63
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package, naming the file
64
+ try {
65
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
66
+ }
67
+ catch (err) {
68
+ //const error = toError(err);
69
+ throw new ApiDocExtractionError_1.ApiDocExtractionError(`package.json is not valid JSON: ${err instanceof Error ? err.message : String(err)}`, file, 'Fix that package.json — the package a type is declared in is read from it.');
70
+ }
71
+ }
59
72
  /** The package whose `package.json` sits in `directory`, when it is one with a name. */
60
73
  read(directory) {
61
74
  const file = path.join(directory, 'package.json');
62
75
  if (!fs.existsSync(file)) {
63
76
  return undefined;
64
77
  }
65
- const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
78
+ const raw = PackageOfFile.parse(file);
66
79
  if (typeof raw.name !== 'string' || raw.name.trim() === '') {
67
80
  return undefined;
68
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PackageOfFile.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/PackageOfFile.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAElC,gGAAgG;AAChG,MAAa,gBAAgB;IAGZ;IAEA;IAEA;IANb;IACI,oEAAoE;IAC3D,IAAY;IACrB,gFAAgF;IACvE,OAAe;IACxB,0DAA0D;IACjD,SAAiB;QAJjB,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QAEf,cAAS,GAAT,SAAS,CAAQ;IAC3B,CAAC;CACP;AATD,4CASC;AAMD;;;;;;;;;;;;;;;GAeG;AACH,MAAa,aAAa;IACL,WAAW,GAAG,IAAI,GAAG,EAAwC,CAAC;IAE/E,qGAAqG;IACrG,EAAE,CAAC,QAAgB;QACf,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAEO,WAAW,CAAC,SAAiB;QACjC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAClC,OAAO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'node:path';\n\n/** The npm package a source file belongs to: the nearest `package.json` above it. Data-only. */\nexport class DeclaringPackage {\n constructor(\n /** `name` from that `package.json`, e.g. `@myorg/lang-api-dtos`. */\n readonly name: string,\n /** `version` from that `package.json`; the empty string when it states none. */\n readonly version: string,\n /** The absolute directory holding that `package.json`. */\n readonly directory: string,\n ) {}\n}\n\n/** The two fields of a `package.json` this lookup reads — raw JSON, narrowed where they are read. */\n// webpieces-disable no-any-unknown -- a file off disk: each field is narrowed with typeof before use\ntype PackageJsonFields = { readonly name?: unknown; readonly version?: unknown };\n\n/**\n * WHICH PACKAGE declares a type — the owner of its schema (#1058).\n *\n * A schema is defined in exactly one OpenAPI document: the one belonging to the package whose source\n * declares the TypeScript type. That is what lets two different `LocalizedDescriptionsDto`s live in\n * two packages without colliding, and what lets a contract document `$ref` a DTO library's schema\n * instead of copying it. The answer is the nearest `package.json` above the declaring file — which is\n * the same answer whether the compiler reached the file as workspace SOURCE through tsconfig `paths`\n * or as a published `.d.ts` under `node_modules`.\n *\n * A file with no `package.json` above it belongs to no package; `of` returns `undefined` and the\n * caller decides what that means (the OpenAPI generator refuses to reference it, the MCP renderer\n * does not care).\n *\n * Cached per directory, because a contract reaches hundreds of declarations in a handful of files.\n */\nexport class PackageOfFile {\n private readonly byDirectory = new Map<string, DeclaringPackage | undefined>();\n\n /** The package declaring `fileName`, or undefined when no `package.json` with a name is above it. */\n of(fileName: string): DeclaringPackage | undefined {\n return this.ofDirectory(path.dirname(path.resolve(fileName)));\n }\n\n private ofDirectory(directory: string): DeclaringPackage | undefined {\n if (this.byDirectory.has(directory)) {\n return this.byDirectory.get(directory);\n }\n const found = this.read(directory) ?? this.parentOf(directory);\n this.byDirectory.set(directory, found);\n return found;\n }\n\n private parentOf(directory: string): DeclaringPackage | undefined {\n const parent = path.dirname(directory);\n return parent === directory ? undefined : this.ofDirectory(parent);\n }\n\n /** The package whose `package.json` sits in `directory`, when it is one with a name. */\n private read(directory: string): DeclaringPackage | undefined {\n const file = path.join(directory, 'package.json');\n if (!fs.existsSync(file)) {\n return undefined;\n }\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as PackageJsonFields;\n if (typeof raw.name !== 'string' || raw.name.trim() === '') {\n return undefined;\n }\n return new DeclaringPackage(\n raw.name,\n typeof raw.version === 'string' ? raw.version : '',\n directory,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"PackageOfFile.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/extract/PackageOfFile.ts"],"names":[],"mappings":";;;;AAAA,oDAA8B;AAC9B,wDAAkC;AAClC,mEAAgE;AAEhE,gGAAgG;AAChG,MAAa,gBAAgB;IAGZ;IAEA;IAEA;IANb;IACI,oEAAoE;IAC3D,IAAY;IACrB,gFAAgF;IACvE,OAAe;IACxB,0DAA0D;IACjD,SAAiB;QAJjB,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QAEf,cAAS,GAAT,SAAS,CAAQ;IAC3B,CAAC;CACP;AATD,4CASC;AAMD;;;;;;;;;;;;;;;GAeG;AACH,MAAa,aAAa;IACL,WAAW,GAAG,IAAI,GAAG,EAAwC,CAAC;IAE/E,qGAAqG;IACrG,EAAE,CAAC,QAAgB;QACf,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAEO,WAAW,CAAC,SAAiB;QACjC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC/D,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,EAA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O,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAClD,SAAS,CACZ,CAAC;IACN,CAAC;CACJ;AAtDD,sCAsDC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { ApiDocExtractionError } from './ApiDocExtractionError';\n\n/** The npm package a source file belongs to: the nearest `package.json` above it. Data-only. */\nexport class DeclaringPackage {\n constructor(\n /** `name` from that `package.json`, e.g. `@myorg/lang-api-dtos`. */\n readonly name: string,\n /** `version` from that `package.json`; the empty string when it states none. */\n readonly version: string,\n /** The absolute directory holding that `package.json`. */\n readonly directory: string,\n ) {}\n}\n\n/** The two fields of a `package.json` this lookup reads — raw JSON, narrowed where they are read. */\n// webpieces-disable no-any-unknown -- a file off disk: each field is narrowed with typeof before use\ntype PackageJsonFields = { readonly name?: unknown; readonly version?: unknown };\n\n/**\n * WHICH PACKAGE declares a type — the owner of its schema (#1058).\n *\n * A schema is defined in exactly one OpenAPI document: the one belonging to the package whose source\n * declares the TypeScript type. That is what lets two different `LocalizedDescriptionsDto`s live in\n * two packages without colliding, and what lets a contract document `$ref` a DTO library's schema\n * instead of copying it. The answer is the nearest `package.json` above the declaring file — which is\n * the same answer whether the compiler reached the file as workspace SOURCE through tsconfig `paths`\n * or as a published `.d.ts` under `node_modules`.\n *\n * A file with no `package.json` above it belongs to no package; `of` returns `undefined` and the\n * caller decides what that means (the OpenAPI generator refuses to reference it, the MCP renderer\n * does not care).\n *\n * Cached per directory, because a contract reaches hundreds of declarations in a handful of files.\n */\nexport class PackageOfFile {\n private readonly byDirectory = new Map<string, DeclaringPackage | undefined>();\n\n /** The package declaring `fileName`, or undefined when no `package.json` with a name is above it. */\n of(fileName: string): DeclaringPackage | undefined {\n return this.ofDirectory(path.dirname(path.resolve(fileName)));\n }\n\n private ofDirectory(directory: string): DeclaringPackage | undefined {\n if (this.byDirectory.has(directory)) {\n return this.byDirectory.get(directory);\n }\n const found = this.read(directory) ?? this.parentOf(directory);\n this.byDirectory.set(directory, found);\n return found;\n }\n\n private parentOf(directory: string): DeclaringPackage | undefined {\n const parent = path.dirname(directory);\n return parent === directory ? undefined : this.ofDirectory(parent);\n }\n\n /** A `package.json`, or the ONE error type of this package naming it when it is not JSON. */\n // webpieces-disable no-function-outside-class -- private static reader of this class\n private static parse(file: string): PackageJsonFields {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- re-thrown as the ONE error type of this package, naming the file\n try {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as PackageJsonFields;\n } catch (err: unknown) {\n //const error = toError(err);\n throw new ApiDocExtractionError(\n `package.json is not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n file,\n 'Fix that package.json — the package a type is declared in is read from it.',\n );\n }\n }\n\n /** The package whose `package.json` sits in `directory`, when it is one with a name. */\n private read(directory: string): DeclaringPackage | undefined {\n const file = path.join(directory, 'package.json');\n if (!fs.existsSync(file)) {\n return undefined;\n }\n const raw = PackageOfFile.parse(file);\n if (typeof raw.name !== 'string' || raw.name.trim() === '') {\n return undefined;\n }\n return new DeclaringPackage(\n raw.name,\n typeof raw.version === 'string' ? raw.version : '',\n directory,\n );\n }\n}\n"]}