@typespec/tspd 0.47.0-dev.0 → 0.69.0-dev.1

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 (55) hide show
  1. package/README.md +18 -0
  2. package/dist/src/cli.js +24 -5
  3. package/dist/src/cli.js.map +1 -1
  4. package/dist/src/gen-extern-signatures/decorators-signatures.d.ts +5 -0
  5. package/dist/src/gen-extern-signatures/decorators-signatures.d.ts.map +1 -0
  6. package/dist/src/gen-extern-signatures/decorators-signatures.js +338 -0
  7. package/dist/src/gen-extern-signatures/decorators-signatures.js.map +1 -0
  8. package/dist/src/gen-extern-signatures/doc-builder.d.ts +3 -0
  9. package/dist/src/gen-extern-signatures/doc-builder.d.ts.map +1 -0
  10. package/dist/src/gen-extern-signatures/doc-builder.js +14 -0
  11. package/dist/src/gen-extern-signatures/doc-builder.js.map +1 -0
  12. package/dist/src/gen-extern-signatures/gen-extern-signatures.d.ts +11 -0
  13. package/dist/src/gen-extern-signatures/gen-extern-signatures.d.ts.map +1 -0
  14. package/dist/src/gen-extern-signatures/gen-extern-signatures.js +122 -0
  15. package/dist/src/gen-extern-signatures/gen-extern-signatures.js.map +1 -0
  16. package/dist/src/gen-extern-signatures/types.d.ts +11 -0
  17. package/dist/src/gen-extern-signatures/types.d.ts.map +1 -0
  18. package/dist/src/gen-extern-signatures/types.js +2 -0
  19. package/dist/src/gen-extern-signatures/types.js.map +1 -0
  20. package/dist/src/ref-doc/api-docs.d.ts.map +1 -1
  21. package/dist/src/ref-doc/api-docs.js +3 -3
  22. package/dist/src/ref-doc/api-docs.js.map +1 -1
  23. package/dist/src/ref-doc/emitters/docusaurus.d.ts +4 -4
  24. package/dist/src/ref-doc/emitters/docusaurus.d.ts.map +1 -1
  25. package/dist/src/ref-doc/emitters/docusaurus.js +72 -72
  26. package/dist/src/ref-doc/emitters/docusaurus.js.map +1 -1
  27. package/dist/src/ref-doc/emitters/markdown.d.ts +22 -7
  28. package/dist/src/ref-doc/emitters/markdown.d.ts.map +1 -1
  29. package/dist/src/ref-doc/emitters/markdown.js +125 -24
  30. package/dist/src/ref-doc/emitters/markdown.js.map +1 -1
  31. package/dist/src/ref-doc/emitters/starlight.d.ts +24 -0
  32. package/dist/src/ref-doc/emitters/starlight.d.ts.map +1 -0
  33. package/dist/src/ref-doc/emitters/starlight.js +213 -0
  34. package/dist/src/ref-doc/emitters/starlight.js.map +1 -0
  35. package/dist/src/ref-doc/experimental.d.ts +4 -1
  36. package/dist/src/ref-doc/experimental.d.ts.map +1 -1
  37. package/dist/src/ref-doc/experimental.js +7 -8
  38. package/dist/src/ref-doc/experimental.js.map +1 -1
  39. package/dist/src/ref-doc/extractor.d.ts.map +1 -1
  40. package/dist/src/ref-doc/extractor.js +112 -80
  41. package/dist/src/ref-doc/extractor.js.map +1 -1
  42. package/dist/src/ref-doc/lib.d.ts +55 -2
  43. package/dist/src/ref-doc/lib.d.ts.map +1 -1
  44. package/dist/src/ref-doc/lib.js +8 -1
  45. package/dist/src/ref-doc/lib.js.map +1 -1
  46. package/dist/src/ref-doc/types.d.ts +79 -53
  47. package/dist/src/ref-doc/types.d.ts.map +1 -1
  48. package/dist/src/ref-doc/utils/markdown.d.ts +0 -6
  49. package/dist/src/ref-doc/utils/markdown.d.ts.map +1 -1
  50. package/dist/src/ref-doc/utils/markdown.js +1 -9
  51. package/dist/src/ref-doc/utils/markdown.js.map +1 -1
  52. package/dist/src/ref-doc/utils/type-signature.d.ts.map +1 -1
  53. package/dist/src/ref-doc/utils/type-signature.js +8 -22
  54. package/dist/src/ref-doc/utils/type-signature.js.map +1 -1
  55. package/package.json +29 -30
@@ -2,32 +2,31 @@ import { compile, createDiagnosticCollector, joinPaths, NodeHost, } from "@types
2
2
  import { mkdir, readFile, writeFile } from "fs/promises";
3
3
  import prettier from "prettier";
4
4
  import { generateJsApiDocs } from "./api-docs.js";
5
- import { renderToDocusaurusMarkdown } from "./emitters/docusaurus.js";
6
5
  import { renderReadme } from "./emitters/markdown.js";
6
+ import { renderToAstroStarlightMarkdown } from "./emitters/starlight.js";
7
7
  import { extractLibraryRefDocs, extractRefDocs } from "./extractor.js";
8
8
  /**
9
9
  * @experimental this is for experimental and is for internal use only. Breaking change to this API can happen at anytime.
10
10
  */
11
- export async function generateLibraryDocs(libraryPath, outputDir, skipJSApi = false) {
11
+ export async function generateLibraryDocs(libraryPath, outputDir, options = {}) {
12
12
  const diagnostics = createDiagnosticCollector();
13
13
  const pkgJson = await readPackageJson(libraryPath);
14
14
  const refDoc = diagnostics.pipe(await extractLibraryRefDocs(libraryPath));
15
- const files = renderToDocusaurusMarkdown(refDoc);
15
+ const files = renderToAstroStarlightMarkdown(refDoc);
16
16
  await mkdir(outputDir, { recursive: true });
17
17
  const config = await prettier.resolveConfig(libraryPath);
18
18
  for (const [name, content] of Object.entries(files)) {
19
19
  const formatted = await formatMarkdown(name, content, config);
20
20
  await writeFile(joinPaths(outputDir, name), formatted);
21
21
  }
22
- const readme = await formatMarkdown(joinPaths(libraryPath, "README.md"), await renderReadme(refDoc, libraryPath), config !== null && config !== void 0 ? config : {});
22
+ const readme = await formatMarkdown(joinPaths(libraryPath, "README.md"), await renderReadme(refDoc, libraryPath), config ?? {});
23
23
  await writeFile(joinPaths(libraryPath, "README.md"), readme);
24
- if (pkgJson.main && !skipJSApi) {
24
+ if (pkgJson.main && !options.skipJSApi) {
25
25
  await generateJsApiDocs(libraryPath, joinPaths(outputDir, "js-api"));
26
26
  }
27
27
  return diagnostics.diagnostics;
28
28
  }
29
29
  export async function resolveLibraryRefDocsBase(libraryPath, options = {}) {
30
- var _a;
31
30
  const diagnostics = createDiagnosticCollector();
32
31
  const pkgJson = await readPackageJson(libraryPath);
33
32
  if (pkgJson.tspMain) {
@@ -36,7 +35,7 @@ export async function resolveLibraryRefDocsBase(libraryPath, options = {}) {
36
35
  parseOptions: { comments: true, docs: true },
37
36
  });
38
37
  const refDoc = diagnostics.pipe(extractRefDocs(program, options));
39
- for (const diag of (_a = program.diagnostics) !== null && _a !== void 0 ? _a : []) {
38
+ for (const diag of program.diagnostics ?? []) {
40
39
  diagnostics.add(diag);
41
40
  }
42
41
  return diagnostics.wrap(refDoc);
@@ -50,7 +49,7 @@ async function readPackageJson(libraryPath) {
50
49
  async function formatMarkdown(filename, content, options) {
51
50
  try {
52
51
  return await prettier.format(content, {
53
- ...(options !== null && options !== void 0 ? options : {}),
52
+ ...(options ?? {}),
54
53
  parser: "markdown",
55
54
  });
56
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"experimental.js","sourceRoot":"","sources":["../../../src/ref-doc/experimental.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,yBAAyB,EAEzB,SAAS,EACT,QAAQ,GAET,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAwB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG7F;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,WAAmB,EACnB,SAAiB,EACjB,YAAqB,KAAK;IAE1B,MAAM,WAAW,GAAG,yBAAyB,EAAE,CAAC;IAChD,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,qBAAqB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CA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;IACtE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvC,CAAC;AACD,KAAK,UAAU,cAAc,CAC3B,QAAgB,EAChB,OAAe,EACf,OAAgC;IAEhC,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;YACpC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;YAClB,MAAM,EAAE,UAAU;SACnB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,+BAA+B,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5D,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/ref-doc/extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EAwBV,OAAO,EAQR,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAcL,qBAAqB,EACrB,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAGpB,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,CAAC,qBAAqB,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAoCzD;AAOD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE;QACX,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH;AAkCD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,oBAAyB,GACjC,CAAC,kBAAkB,EAAE,SAAS,UAAU,EAAE,CAAC,CAwF7C"}
1
+ {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/ref-doc/extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EAyBV,OAAO,EASR,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAmBL,qBAAqB,EACrB,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAmBpB,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,CAAC,qBAAqB,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAuCzD;AAOD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE;QACX,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH;AAmCD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,oBAAyB,GACjC,CAAC,kBAAkB,EAAE,SAAS,UAAU,EAAE,CAAC,CAqG7C"}
@@ -1,10 +1,13 @@
1
- import { compile, compilerAssert, createDiagnosticCollector, getDoc, getLocationContext, getSourceLocation, getTypeName, isDeclaredType, isTemplateDeclaration, joinPaths, navigateProgram, navigateTypesInNamespace, NodeHost, NoTarget, resolvePath, SyntaxKind, } from "@typespec/compiler";
1
+ import { compile, compilerAssert, createDiagnosticCollector, getDeprecated, getDoc, getLocationContext, getSourceLocation, getTypeName, isDeclaredType, isTemplateDeclaration, joinPaths, navigateProgram, navigateTypesInNamespace, NodeHost, NoTarget, resolveLinterDefinition, resolvePath, } from "@typespec/compiler";
2
+ import { SyntaxKind } from "@typespec/compiler/ast";
2
3
  import { readFile } from "fs/promises";
3
4
  import { pathToFileURL } from "url";
4
5
  import { reportDiagnostic } from "./lib.js";
5
6
  import { getQualifier, getTypeSignature } from "./utils/type-signature.js";
7
+ function getExport(pkgJson, path, condition) {
8
+ return pkgJson.exports?.[path]?.[condition];
9
+ }
6
10
  export async function extractLibraryRefDocs(libraryPath) {
7
- var _a, _b, _c;
8
11
  const diagnostics = createDiagnosticCollector();
9
12
  const pkgJson = await readPackageJson(libraryPath);
10
13
  const refDoc = {
@@ -12,29 +15,32 @@ export async function extractLibraryRefDocs(libraryPath) {
12
15
  description: pkgJson.description,
13
16
  packageJson: pkgJson,
14
17
  namespaces: [],
18
+ getNamedTypeRefDoc: (type) => undefined,
15
19
  };
16
- if (pkgJson.tspMain) {
17
- const main = resolvePath(libraryPath, pkgJson.tspMain);
20
+ const tspMain = getExport(pkgJson, ".", "typespec");
21
+ if (tspMain) {
22
+ const main = resolvePath(libraryPath, tspMain);
18
23
  const program = await compile(NodeHost, main, {
19
24
  parseOptions: { comments: true, docs: true },
20
25
  });
21
- refDoc.namespaces = diagnostics.pipe(extractRefDocs(program)).namespaces;
22
- for (const diag of (_a = program.diagnostics) !== null && _a !== void 0 ? _a : []) {
26
+ const tspEmitter = diagnostics.pipe(extractRefDocs(program));
27
+ Object.assign(refDoc, tspEmitter);
28
+ for (const diag of program.diagnostics ?? []) {
23
29
  diagnostics.add(diag);
24
30
  }
25
31
  }
26
- if (pkgJson.main) {
27
- const entrypoint = await import(pathToFileURL(resolvePath(libraryPath, pkgJson.main)).href);
32
+ const main = getExport(pkgJson, ".", "import") ?? getExport(pkgJson, ".", "default");
33
+ if (main) {
34
+ const entrypoint = await import(pathToFileURL(resolvePath(libraryPath, main)).href);
28
35
  const lib = entrypoint.$lib;
29
- if ((_b = lib === null || lib === void 0 ? void 0 : lib.emitter) === null || _b === void 0 ? void 0 : _b.options) {
36
+ if (lib?.emitter?.options) {
30
37
  refDoc.emitter = {
31
38
  options: extractEmitterOptionsRefDoc(lib.emitter.options),
32
39
  };
33
40
  }
34
- // eslint-disable-next-line deprecation/deprecation
35
- const linter = (_c = entrypoint.$linter) !== null && _c !== void 0 ? _c : lib === null || lib === void 0 ? void 0 : lib.linter;
41
+ const linter = entrypoint.$linter;
36
42
  if (lib && linter) {
37
- refDoc.linter = extractLinterRefDoc(lib.name, linter);
43
+ refDoc.linter = extractLinterRefDoc(lib.name, resolveLinterDefinition(lib.name, linter));
38
44
  }
39
45
  }
40
46
  return diagnostics.wrap(refDoc);
@@ -44,10 +50,9 @@ async function readPackageJson(libraryPath) {
44
50
  return JSON.parse(buffer.toString());
45
51
  }
46
52
  function resolveNamespaces(program, options) {
47
- var _a;
48
53
  const diagnostics = createDiagnosticCollector();
49
54
  let namespaceTypes = [];
50
- const { include, exclude } = (_a = options === null || options === void 0 ? void 0 : options.namespaces) !== null && _a !== void 0 ? _a : {};
55
+ const { include, exclude } = options?.namespaces ?? {};
51
56
  if (include) {
52
57
  namespaceTypes = include
53
58
  .map((x) => diagnostics.pipe(program.resolveTypeReference(x)))
@@ -74,12 +79,14 @@ function resolveNamespaces(program, options) {
74
79
  export function extractRefDocs(program, options = {}) {
75
80
  const diagnostics = createDiagnosticCollector();
76
81
  const namespaceTypes = diagnostics.pipe(resolveNamespaces(program, options));
77
- const refDoc = {
78
- namespaces: [],
79
- };
82
+ const typeMapping = new Map();
83
+ const namespaces = [];
80
84
  for (const namespace of namespaceTypes) {
85
+ const name = getTypeName(namespace);
81
86
  const namespaceDoc = {
82
- id: getTypeName(namespace),
87
+ kind: "namespace",
88
+ id: name,
89
+ name,
83
90
  decorators: [],
84
91
  operations: [],
85
92
  interfaces: [],
@@ -88,24 +95,28 @@ export function extractRefDocs(program, options = {}) {
88
95
  unions: [],
89
96
  scalars: [],
90
97
  };
91
- refDoc.namespaces.push(namespaceDoc);
98
+ namespaces.push(namespaceDoc);
99
+ function collectType(type, refDoc, array) {
100
+ typeMapping.set(type, refDoc);
101
+ array.push(refDoc);
102
+ }
92
103
  navigateTypesInNamespace(namespace, {
93
104
  decorator(dec) {
94
- namespaceDoc.decorators.push(extractDecoratorRefDoc(program, dec));
105
+ collectType(dec, extractDecoratorRefDoc(program, dec), namespaceDoc.decorators);
95
106
  },
96
107
  operation(operation) {
97
108
  if (!isDeclaredType(operation)) {
98
109
  return;
99
110
  }
100
111
  if (operation.interface === undefined) {
101
- namespaceDoc.operations.push(extractOperationRefDoc(program, operation, undefined));
112
+ collectType(operation, extractOperationRefDoc(program, operation, undefined), namespaceDoc.operations);
102
113
  }
103
114
  },
104
115
  interface(iface) {
105
116
  if (!isDeclaredType(iface)) {
106
117
  return;
107
118
  }
108
- namespaceDoc.interfaces.push(extractInterfaceRefDocs(program, iface));
119
+ collectType(iface, extractInterfaceRefDocs(program, iface), namespaceDoc.interfaces);
109
120
  },
110
121
  model(model) {
111
122
  if (!isDeclaredType(model)) {
@@ -114,29 +125,29 @@ export function extractRefDocs(program, options = {}) {
114
125
  if (model.name === "") {
115
126
  return;
116
127
  }
117
- namespaceDoc.models.push(extractModelRefDocs(program, model));
128
+ collectType(model, extractModelRefDocs(program, model), namespaceDoc.models);
118
129
  },
119
130
  enum(e) {
120
131
  if (!isDeclaredType(e)) {
121
132
  return;
122
133
  }
123
- namespaceDoc.enums.push(extractEnumRefDoc(program, e));
134
+ collectType(e, extractEnumRefDoc(program, e), namespaceDoc.enums);
124
135
  },
125
136
  union(union) {
126
137
  if (!isDeclaredType(union)) {
127
138
  return;
128
139
  }
129
140
  if (union.name !== undefined) {
130
- namespaceDoc.unions.push(extractUnionRefDocs(program, union));
141
+ collectType(union, extractUnionRefDocs(program, union), namespaceDoc.unions);
131
142
  }
132
143
  },
133
144
  scalar(scalar) {
134
- namespaceDoc.scalars.push(extractScalarRefDocs(program, scalar));
145
+ collectType(scalar, extractScalarRefDocs(program, scalar), namespaceDoc.scalars);
135
146
  },
136
147
  }, { includeTemplateDeclaration: true, skipSubNamespaces: true });
137
148
  }
138
- sort(refDoc.namespaces);
139
- for (const namespace of refDoc.namespaces) {
149
+ sort(namespaces);
150
+ for (const namespace of namespaces) {
140
151
  sort(namespace.decorators);
141
152
  sort(namespace.enums);
142
153
  sort(namespace.interfaces);
@@ -148,25 +159,27 @@ export function extractRefDocs(program, options = {}) {
148
159
  function sort(arr) {
149
160
  arr.sort((a, b) => a.id.localeCompare(b.id, "en"));
150
161
  }
151
- return diagnostics.wrap(refDoc);
162
+ return diagnostics.wrap({
163
+ namespaces,
164
+ getNamedTypeRefDoc: (type) => typeMapping.get(type),
165
+ });
152
166
  }
153
167
  function extractTemplateParameterDocs(program, type) {
154
168
  if (isTemplateDeclaration(type)) {
155
169
  const templateParamsDocs = getTemplateParameterDocs(type);
156
170
  return type.node.templateParameters.map((x) => {
157
- var _a, _b;
158
171
  const doc = templateParamsDocs.get(x.id.sv);
159
172
  if (doc === undefined || doc === "") {
160
173
  reportDiagnostic(program, {
161
174
  code: "documentation-missing",
162
175
  messageId: "templateParam",
163
- format: { name: (_a = type.name) !== null && _a !== void 0 ? _a : "", param: x.id.sv },
176
+ format: { name: type.name ?? "", param: x.id.sv },
164
177
  target: NoTarget,
165
178
  });
166
179
  }
167
180
  return {
168
181
  name: x.id.sv,
169
- doc: (_b = templateParamsDocs.get(x.id.sv)) !== null && _b !== void 0 ? _b : "",
182
+ doc: templateParamsDocs.get(x.id.sv) ?? "",
170
183
  };
171
184
  });
172
185
  }
@@ -175,19 +188,18 @@ function extractTemplateParameterDocs(program, type) {
175
188
  }
176
189
  }
177
190
  function extractInterfaceRefDocs(program, iface) {
178
- var _a;
179
191
  const doc = extractMainDoc(program, iface);
180
192
  if (doc === undefined || doc === "") {
181
193
  reportDiagnostic(program, {
182
194
  code: "documentation-missing",
183
195
  messageId: "interface",
184
- format: { name: (_a = iface.name) !== null && _a !== void 0 ? _a : "" },
196
+ format: { name: iface.name ?? "" },
185
197
  target: NoTarget,
186
198
  });
187
199
  }
188
200
  return {
189
- id: getNamedTypeId(iface),
190
- name: iface.name,
201
+ kind: "interface",
202
+ ...extractBase(program, iface),
191
203
  signature: getTypeSignature(iface),
192
204
  type: iface,
193
205
  templateParameters: extractTemplateParameterDocs(program, iface),
@@ -196,15 +208,22 @@ function extractInterfaceRefDocs(program, iface) {
196
208
  examples: extractExamples(iface),
197
209
  };
198
210
  }
211
+ function extractBase(program, type) {
212
+ const deprecated = getDeprecated(program, type);
213
+ return {
214
+ id: getNamedTypeId(type),
215
+ name: type.name,
216
+ deprecated: deprecated ? { message: deprecated } : undefined,
217
+ };
218
+ }
199
219
  function extractOperationRefDoc(program, operation, interfaceName) {
200
- var _a, _b;
201
220
  const doc = extractMainDoc(program, operation);
202
221
  if (doc === undefined || doc === "") {
203
222
  if (operation.interface !== undefined) {
204
223
  reportDiagnostic(program, {
205
224
  code: "documentation-missing",
206
225
  messageId: "interfaceOperation",
207
- format: { name: (_a = `${operation.interface.name}.${operation.name}`) !== null && _a !== void 0 ? _a : "" },
226
+ format: { name: `${operation.interface.name}.${operation.name}` },
208
227
  target: NoTarget,
209
228
  });
210
229
  }
@@ -212,13 +231,14 @@ function extractOperationRefDoc(program, operation, interfaceName) {
212
231
  reportDiagnostic(program, {
213
232
  code: "documentation-missing",
214
233
  messageId: "operation",
215
- format: { name: (_b = operation.name) !== null && _b !== void 0 ? _b : "" },
234
+ format: { name: operation.name ?? "" },
216
235
  target: NoTarget,
217
236
  });
218
237
  }
219
238
  }
220
239
  return {
221
- id: getNamedTypeId(operation),
240
+ kind: "operation",
241
+ ...extractBase(program, operation),
222
242
  name: interfaceName ? `${interfaceName}.${operation.name}` : operation.name,
223
243
  signature: getTypeSignature(operation),
224
244
  type: operation,
@@ -228,10 +248,8 @@ function extractOperationRefDoc(program, operation, interfaceName) {
228
248
  };
229
249
  }
230
250
  function extractDecoratorRefDoc(program, decorator) {
231
- var _a;
232
251
  const paramDoc = getParmeterDocs(decorator);
233
252
  const parameters = decorator.parameters.map((x) => {
234
- var _a;
235
253
  const docVal = paramDoc.get(x.name);
236
254
  if (docVal === undefined || docVal === "") {
237
255
  reportDiagnostic(program, {
@@ -242,8 +260,9 @@ function extractDecoratorRefDoc(program, decorator) {
242
260
  });
243
261
  }
244
262
  return {
263
+ kind: "decorator",
245
264
  type: x,
246
- doc: (_a = paramDoc.get(x.name)) !== null && _a !== void 0 ? _a : "",
265
+ doc: paramDoc.get(x.name) ?? "",
247
266
  name: x.name,
248
267
  optional: x.optional,
249
268
  rest: x.rest,
@@ -260,8 +279,8 @@ function extractDecoratorRefDoc(program, decorator) {
260
279
  });
261
280
  }
262
281
  return {
263
- id: getNamedTypeId(decorator),
264
- name: decorator.name,
282
+ kind: "decorator",
283
+ ...extractBase(program, decorator),
265
284
  type: decorator,
266
285
  signature: getTypeSignature(decorator),
267
286
  doc: mainDoc,
@@ -270,7 +289,7 @@ function extractDecoratorRefDoc(program, decorator) {
270
289
  otherTags: [],
271
290
  target: {
272
291
  type: decorator.target,
273
- doc: (_a = paramDoc.get(decorator.target.name)) !== null && _a !== void 0 ? _a : "",
292
+ doc: paramDoc.get(decorator.target.name) ?? "",
274
293
  name: decorator.target.name,
275
294
  optional: decorator.target.optional,
276
295
  rest: decorator.target.rest,
@@ -278,40 +297,60 @@ function extractDecoratorRefDoc(program, decorator) {
278
297
  };
279
298
  }
280
299
  function extractModelRefDocs(program, type) {
281
- var _a;
282
300
  const doc = extractMainDoc(program, type);
283
301
  if (doc === undefined || doc === "") {
284
302
  reportDiagnostic(program, {
285
303
  code: "documentation-missing",
286
304
  messageId: "model",
287
- format: { name: (_a = type.name) !== null && _a !== void 0 ? _a : "" },
305
+ format: { name: type.name ?? "" },
288
306
  target: NoTarget,
289
307
  });
290
308
  }
291
309
  return {
292
- id: getNamedTypeId(type),
293
- name: type.name,
310
+ kind: "model",
311
+ ...extractBase(program, type),
294
312
  signature: getTypeSignature(type),
295
313
  type,
296
314
  templateParameters: extractTemplateParameterDocs(program, type),
297
315
  doc: doc,
298
316
  examples: extractExamples(type),
317
+ properties: new Map([...type.properties.values()].map((x) => [x.name, extractModelPropertyRefDocs(program, x)])),
318
+ };
319
+ }
320
+ function extractModelPropertyRefDocs(program, type) {
321
+ const doc = extractMainDoc(program, type);
322
+ return {
323
+ ...extractBase(program, type),
324
+ signature: getTypeSignature(type),
325
+ type,
326
+ doc: doc,
327
+ examples: extractExamples(type),
299
328
  };
300
329
  }
301
330
  function extractEnumRefDoc(program, type) {
302
- var _a;
303
331
  const doc = extractMainDoc(program, type);
304
332
  if (doc === undefined || doc === "") {
305
333
  reportDiagnostic(program, {
306
334
  code: "documentation-missing",
307
335
  messageId: "enum",
308
- format: { name: (_a = type.name) !== null && _a !== void 0 ? _a : "" },
336
+ format: { name: type.name ?? "" },
309
337
  target: NoTarget,
310
338
  });
311
339
  }
312
340
  return {
313
- id: getNamedTypeId(type),
314
- name: type.name,
341
+ kind: "enum",
342
+ ...extractBase(program, type),
343
+ signature: getTypeSignature(type),
344
+ type,
345
+ doc: doc,
346
+ examples: extractExamples(type),
347
+ members: new Map([...type.members.values()].map((x) => [x.name, extractEnumMemberRefDocs(program, x)])),
348
+ };
349
+ }
350
+ function extractEnumMemberRefDocs(program, type) {
351
+ const doc = extractMainDoc(program, type);
352
+ return {
353
+ ...extractBase(program, type),
315
354
  signature: getTypeSignature(type),
316
355
  type,
317
356
  doc: doc,
@@ -319,19 +358,18 @@ function extractEnumRefDoc(program, type) {
319
358
  };
320
359
  }
321
360
  function extractUnionRefDocs(program, type) {
322
- var _a;
323
361
  const doc = extractMainDoc(program, type);
324
362
  if (doc === undefined || doc === "") {
325
363
  reportDiagnostic(program, {
326
364
  code: "documentation-missing",
327
365
  messageId: "union",
328
- format: { name: (_a = type.name) !== null && _a !== void 0 ? _a : "" },
366
+ format: { name: type.name ?? "" },
329
367
  target: NoTarget,
330
368
  });
331
369
  }
332
370
  return {
333
- id: getNamedTypeId(type),
334
- name: type.name,
371
+ kind: "union",
372
+ ...extractBase(program, type),
335
373
  signature: getTypeSignature(type),
336
374
  type,
337
375
  templateParameters: extractTemplateParameterDocs(program, type),
@@ -340,19 +378,18 @@ function extractUnionRefDocs(program, type) {
340
378
  };
341
379
  }
342
380
  function extractScalarRefDocs(program, type) {
343
- var _a;
344
381
  const doc = extractMainDoc(program, type);
345
382
  if (doc === undefined || doc === "") {
346
383
  reportDiagnostic(program, {
347
384
  code: "documentation-missing",
348
385
  messageId: "scalar",
349
- format: { name: (_a = type.name) !== null && _a !== void 0 ? _a : "" },
386
+ format: { name: type.name ?? "" },
350
387
  target: NoTarget,
351
388
  });
352
389
  }
353
390
  return {
354
- id: getNamedTypeId(type),
355
- name: type.name,
391
+ kind: "scalar",
392
+ ...extractBase(program, type),
356
393
  signature: getTypeSignature(type),
357
394
  type,
358
395
  doc: doc,
@@ -360,19 +397,17 @@ function extractScalarRefDocs(program, type) {
360
397
  };
361
398
  }
362
399
  function extractMainDoc(program, type) {
363
- var _a, _b, _c;
364
- let mainDoc = "";
365
- for (const doc of (_b = (_a = type.node) === null || _a === void 0 ? void 0 : _a.docs) !== null && _b !== void 0 ? _b : []) {
400
+ const mainDocs = [];
401
+ for (const doc of type.node?.docs ?? []) {
366
402
  for (const dContent of doc.content) {
367
- mainDoc += dContent.text + "\n";
403
+ mainDocs.push(dContent.text);
368
404
  }
369
405
  }
370
- return mainDoc !== "" ? mainDoc : (_c = getDoc(program, type)) !== null && _c !== void 0 ? _c : "";
406
+ return mainDocs.length > 0 ? mainDocs.join("\n") : (getDoc(program, type) ?? "");
371
407
  }
372
408
  function extractExamples(type) {
373
- var _a, _b;
374
409
  const examples = [];
375
- for (const doc of (_b = (_a = type.node) === null || _a === void 0 ? void 0 : _a.docs) !== null && _b !== void 0 ? _b : []) {
410
+ for (const doc of type.node?.docs ?? []) {
376
411
  for (const dTag of doc.tags) {
377
412
  if (dTag.kind === SyntaxKind.DocUnknownTag) {
378
413
  if (dTag.tagName.sv === "example") {
@@ -384,12 +419,11 @@ function extractExamples(type) {
384
419
  return examples;
385
420
  }
386
421
  function getNamedTypeId(type) {
387
- var _a;
388
422
  switch (type.kind) {
389
423
  case "Decorator":
390
424
  return getDecoratorId(type);
391
425
  case "Operation":
392
- return getQualifier((_a = type.interface) !== null && _a !== void 0 ? _a : type.namespace) + type.name;
426
+ return getQualifier(type.interface ?? type.namespace) + type.name;
393
427
  default:
394
428
  return "namespace" in type ? getQualifier(type.namespace) + type.name : type.name;
395
429
  }
@@ -398,9 +432,8 @@ function getDecoratorId(decorator) {
398
432
  return "@" + getQualifier(decorator.namespace) + decorator.name.slice(1);
399
433
  }
400
434
  function checkIfTagHasDocOnSameLine(tag) {
401
- var _a, _b;
402
- const start = (_a = tag.content[0]) === null || _a === void 0 ? void 0 : _a.pos;
403
- const end = (_b = tag.content[0]) === null || _b === void 0 ? void 0 : _b.end;
435
+ const start = tag.content[0]?.pos;
436
+ const end = tag.content[0]?.end;
404
437
  const file = getSourceLocation(tag.content[0]).file;
405
438
  let hasFirstLine = false;
406
439
  for (let i = start; i < end; i++) {
@@ -427,9 +460,8 @@ function extractExample(tag) {
427
460
  }
428
461
  }
429
462
  function getParmeterDocs(type) {
430
- var _a, _b;
431
463
  const map = new Map();
432
- for (const d of (_b = (_a = type === null || type === void 0 ? void 0 : type.node) === null || _a === void 0 ? void 0 : _a.docs) !== null && _b !== void 0 ? _b : []) {
464
+ for (const d of type?.node?.docs ?? []) {
433
465
  for (const tag of d.tags) {
434
466
  if (tag.kind === SyntaxKind.DocParamTag) {
435
467
  map.set(tag.paramName.sv, getDocContent(tag.content));
@@ -439,9 +471,8 @@ function getParmeterDocs(type) {
439
471
  return map;
440
472
  }
441
473
  function getTemplateParameterDocs(type) {
442
- var _a, _b;
443
474
  const map = new Map();
444
- for (const d of (_b = (_a = type === null || type === void 0 ? void 0 : type.node) === null || _a === void 0 ? void 0 : _a.docs) !== null && _b !== void 0 ? _b : []) {
475
+ for (const d of type?.node?.docs ?? []) {
445
476
  for (const tag of d.tags) {
446
477
  if (tag.kind === SyntaxKind.DocTemplateTag) {
447
478
  map.set(tag.paramName.sv, getDocContent(tag.content));
@@ -460,13 +491,12 @@ function getDocContent(content) {
460
491
  }
461
492
  function extractEmitterOptionsRefDoc(options) {
462
493
  return Object.entries(options.properties).map(([name, value]) => {
463
- var _a;
464
494
  return {
465
495
  name,
466
496
  type: value.enum
467
497
  ? value.enum.map((x) => (typeof x === "string" ? `"${x}"` : x)).join(" | ")
468
498
  : value.type,
469
- doc: (_a = value.description) !== null && _a !== void 0 ? _a : "",
499
+ doc: value.description ?? "",
470
500
  };
471
501
  });
472
502
  }
@@ -480,6 +510,7 @@ function extractLinterRuleSetsRefDoc(libName, ruleSets) {
480
510
  return Object.entries(ruleSets).map(([name, ruleSet]) => {
481
511
  const fullName = `${libName}/${name}`;
482
512
  return {
513
+ kind: "ruleset",
483
514
  id: fullName,
484
515
  name: fullName,
485
516
  ruleSet,
@@ -489,6 +520,7 @@ function extractLinterRuleSetsRefDoc(libName, ruleSets) {
489
520
  function extractLinterRuleRefDoc(libName, rule) {
490
521
  const fullName = `${libName}/${rule.name}`;
491
522
  return {
523
+ kind: "rule",
492
524
  id: fullName,
493
525
  name: fullName,
494
526
  rule,