Skip to content

Commit 1cf5261

Browse files
committed
some review changes
Signed-off-by: flakey5 <[email protected]>
1 parent 826cdfc commit 1cf5261

File tree

11 files changed

+367
-106
lines changed

11 files changed

+367
-106
lines changed

.c8rc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"src/generators/legacy-html/assets",
77
"src/generators/web/ui",
88
"**/*.d.ts",
9-
"tools/"
9+
"scripts/"
1010
]
1111
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@
55
*/
66

77
import { readFile, writeFile } from 'node:fs/promises';
8+
import { join } from 'node:path';
89

910
import { compile } from 'json-schema-to-typescript';
1011
import { parse } from 'jsonc-parser';
1112

12-
const SCHEMA_PATH = import.meta.resolve('../src/generators/json/schema.jsonc');
13-
const TYPES_PATH = import.meta.resolve('../src/generators/json/generated.d.ts');
13+
const GENERATOR_DIR = join(
14+
import.meta.dirname,
15+
'..',
16+
'src',
17+
'generators',
18+
'json'
19+
);
20+
21+
const SCHEMA_PATH = join(GENERATOR_DIR, 'schema.jsonc');
22+
const TYPES_PATH = join(GENERATOR_DIR, 'generated.d.ts');
1423

1524
// Read the contents of the JSON schema
1625
const schemaString = await readFile(SCHEMA_PATH, 'utf8');

src/generators/json/generated.d.ts

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export type NodeJsAPIDocumentationSchema = DocumentRoot & (Module | Text);
1010
* A JavaScript module.
1111
*/
1212
export type Module = SectionBase & {
13-
type: 'module';
13+
type: "module";
1414
/**
1515
* https://jsdoc.app/tags-module
1616
*/
17-
'@module': string;
17+
"@module": string;
1818
/**
1919
* Classes exported from this module.
2020
*/
@@ -29,52 +29,47 @@ export type Module = SectionBase & {
2929
globals?: (Class | Method)[];
3030
properties?: Property[];
3131
events?: Event[];
32-
[k: string]: unknown;
3332
};
3433
export type Text = SectionBase;
3534
/**
3635
* Node.js version number
3736
*/
3837
export type NodeCoreVersion = string;
3938
export type Class = SectionBase & {
40-
type: 'class';
41-
'@constructor': MethodSignature[];
42-
methods: Method[];
43-
staticMethods: Method[];
44-
properties: Property[];
39+
type: "class";
40+
"@constructor"?: MethodSignature[];
41+
methods?: Method[];
42+
staticMethods?: Method[];
43+
properties?: Property[];
4544
events?: Event[];
46-
[k: string]: unknown;
4745
};
4846
/**
4947
* A JavaScript function.
5048
*/
5149
export type Method = SectionBase & {
52-
type: 'method';
50+
type: "method";
5351
signatures: MethodSignature[];
54-
[k: string]: unknown;
5552
};
5653
/**
5754
* A property on a JavaScript object or class.
5855
*/
5956
export type Property = SectionBase & {
60-
type: 'property';
57+
type: "property";
6158
/**
6259
* JavaScript type of the property.
6360
*/
64-
'@type'?: string | [string, ...string[]];
61+
"@type"?: string | [string, ...string[]];
6562
/**
6663
* Is this property modifiable by user code?
6764
*/
6865
mutable?: boolean;
69-
[k: string]: unknown;
7066
};
7167
/**
7268
* An event that can be emitted by the parent object or class.
7369
*/
7470
export type Event = SectionBase & {
75-
type: 'event';
71+
type: "event";
7672
parameters: MethodParameter[];
77-
[k: string]: unknown;
7873
};
7974

8075
/**
@@ -85,7 +80,6 @@ export interface DocumentRoot {
8580
* The path to the Markdown source used to generate this document. It is relative to the Node.js repository root.
8681
*/
8782
source: string;
88-
[k: string]: unknown;
8983
}
9084
/**
9185
* Common properties found in each section of a document.
@@ -94,31 +88,31 @@ export interface SectionBase {
9488
/**
9589
* Type of the section
9690
*/
97-
type: 'module' | 'class' | 'method' | 'property' | 'event' | 'text';
91+
type: "module" | "class" | "method" | "property" | "event" | "text";
9892
/**
9993
* https://jsdoc.app/tags-name
10094
*/
101-
'@name': string;
95+
"@name": string;
10296
/**
10397
* Description of the section.
10498
*/
10599
description?: string;
106100
/**
107101
* https://jsdoc.app/tags-see
108102
*/
109-
'@see'?: string;
103+
"@see"?: string;
110104
/**
111105
* Sections that just hold further text on this section.
112106
*/
113107
text?: Text[];
114108
/**
115109
* https://jsdoc.app/tags-example
116110
*/
117-
'@example'?: string | string[];
111+
"@example"?: string | string[];
118112
/**
119113
* https://jsdoc.app/tags-deprecated
120114
*/
121-
'@deprecated'?: NodeCoreVersion[];
115+
"@deprecated"?: NodeCoreVersion[];
122116
stability?: Stability;
123117
/**
124118
* The changes this API has underwent.
@@ -127,13 +121,12 @@ export interface SectionBase {
127121
/**
128122
* https://jsdoc.app/tags-since
129123
*/
130-
'@since'?: NodeCoreVersion[];
124+
"@since"?: NodeCoreVersion[];
131125
napiVersion?: number[];
132126
/**
133127
* Versions that this was removed in.
134128
*/
135129
removedIn?: NodeCoreVersion[];
136-
[k: string]: unknown;
137130
}
138131
/**
139132
* Describes the stability of an object.
@@ -147,7 +140,6 @@ export interface Stability {
147140
* Textual representation of the stability.
148141
*/
149142
text: string;
150-
[k: string]: unknown;
151143
}
152144
export interface Change {
153145
version: NodeCoreVersion[];
@@ -159,28 +151,25 @@ export interface Change {
159151
* Description of the change.
160152
*/
161153
description: string;
162-
[k: string]: unknown;
163154
}
164155
export interface MethodSignature {
165-
parameters?: MethodParameter[];
166-
'@returns'?: MethodReturnType;
167-
[k: string]: unknown;
156+
parameters: MethodParameter[];
157+
"@returns": MethodReturnType;
168158
}
169159
export interface MethodParameter {
170160
/**
171161
* Name of the parameter.
172162
*/
173-
'@name': string;
163+
"@name": string;
174164
/**
175165
* Type of the parameter
176166
*/
177-
'@type': string | [string, ...string[]];
167+
"@type": string | [string, ...string[]];
178168
description?: string;
179169
/**
180170
* The parameter's default value
181171
*/
182-
'@default'?: string;
183-
[k: string]: unknown;
172+
"@default"?: string;
184173
}
185174
/**
186175
* A method signature's return type.
@@ -190,6 +179,5 @@ export interface MethodReturnType {
190179
/**
191180
* The method signature's return type.
192181
*/
193-
'@type': string | [string, ...string[]];
194-
[k: string]: unknown;
182+
"@type": string | [string, ...string[]];
195183
}

src/generators/json/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default {
7676
if (output) {
7777
writeFilePromises[i] = writeFile(
7878
join(output, `${node.api}.json`),
79-
JSON.stringify(section, null, 2)
79+
JSON.stringify(section)
8080
);
8181
}
8282
}

src/generators/json/schema.jsonc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* NOTE: if you modify this, please:
44
* - Bump the version in the $id property
55
* - Bump the version of the `json` and `json-all` generator.
6-
* - Run `tools/generate-json-types.mjs` and ensure there aren't type errors
6+
* - Run `scripts/generate-json-types.mjs` and ensure there aren't type errors
77
*/
88

99
"$schema": "http://json-schema.org/draft-07/schema#",
@@ -153,6 +153,7 @@
153153
},
154154
},
155155
"required": ["type", "@module", "@see"],
156+
"additionalProperties": false
156157
},
157158
],
158159
},
@@ -191,6 +192,7 @@
191192
"required": [
192193
"type",
193194
],
195+
"additionalProperties": false
194196
},
195197
],
196198
},
@@ -212,6 +214,7 @@
212214
},
213215
},
214216
"required": ["type", "signatures"],
217+
"additionalProperties": false
215218
},
216219
],
217220
},
@@ -227,7 +230,8 @@
227230
"$ref": "#/definitions/MethodReturnType",
228231
},
229232
},
230-
"required": ["parameters", "@returns"]
233+
"required": ["parameters", "@returns"],
234+
"additionalProperties": false
231235
},
232236

233237
"MethodParameter": {
@@ -263,6 +267,7 @@
263267
},
264268
},
265269
"required": ["@name", "@type"],
270+
"additionalProperties": false
266271
},
267272

268273
"MethodReturnType": {
@@ -289,6 +294,7 @@
289294
},
290295
},
291296
"required": ["@type"],
297+
"additionalProperties": false
292298
},
293299

294300
"Global": {
@@ -331,6 +337,7 @@
331337
},
332338
},
333339
"required": ["type"],
340+
"additionalProperties": false
334341
},
335342
],
336343
},
@@ -352,6 +359,7 @@
352359
},
353360
},
354361
"required": ["type", "parameters"],
362+
"additionalProperties": false
355363
},
356364
],
357365
},
@@ -388,6 +396,7 @@
388396
},
389397
},
390398
"required": ["version", "description"],
399+
"additionalProperties": false
391400
},
392401

393402
"Stability": {
@@ -406,6 +415,7 @@
406415
},
407416
},
408417
"required": ["value", "text"],
418+
"additionalProperties": false
409419
},
410420
},
411421
}

src/generators/json/utils/createParameterGroupings.mjs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import { ParameterTree } from './parameter-tree.mjs';
3+
import { ParameterTree } from './parameterTree.mjs';
44

55
/**
66
* Parameters are declared in a section's header. This looks something like
@@ -34,25 +34,21 @@ export function createParameterGroupings(parameterNames) {
3434
* @returns {[ParameterTree, boolean]}
3535
*/
3636
export function createParameterTree(parameterNames) {
37-
/**
38-
* @type {import('./parameter-tree.mjs').Counter}
39-
*/
40-
const counter = { count: 0 };
41-
42-
let tree = new ParameterTree(counter);
37+
let tree = new ParameterTree();
4338
let includeFirstChildren = false;
39+
4440
for (let i = 0; i < parameterNames.length; i++) {
4541
/**
46-
* @example 'length]]' -> add `length` to tree's parameters, close out optional depth
42+
* @example 'length]]' -> add `length` to tree's parameters, close out child tree(s)
4743
* @example 'arrayBuffer[' -> add `arrayBuffer` to tree's parameters, start child tree
48-
* @example '[sources[' -> start child tree for sources and another child tree for that child
49-
* @example '[hello]' -> start child tree, add and end child tree
50-
* @example '[hello' -> start child tree
51-
* @example '[hello]['
52-
* @example ']max['
53-
* @example 'end' -> just add
44+
* @example '[sources[' -> start child tree with parameter `sources`, then start another child tree
45+
* @example '[hello]' -> start child tree, add `hello` to it, then end it
46+
* @example '[hello' -> start child tree, add `hello` to it
47+
* @example '[hello][' -> start child tree, end child tree, start another child tree
48+
* @example ']max[' -> add `max` to parent tree, start another child tree, set includeFirstChildren to true
49+
* @example 'end' -> add to tree's parameters
5450
*/
55-
let parameter = parameterNames[i].trim();
51+
const parameter = parameterNames[i].trim();
5652

5753
let nameStartIndex = 0;
5854
if (parameter.startsWith('[')) {

src/generators/json/utils/parameter-tree.mjs renamed to src/generators/json/utils/parameterTree.mjs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,11 @@ export class ParameterTree {
3535
* @param {Counter} counter
3636
* @param {ParameterTree} [parent=undefined]
3737
*/
38-
constructor(counter, parent = undefined) {
38+
constructor(counter = { count: 0 }, parent = undefined) {
3939
this.#counter = counter;
4040
this.#parent = parent;
4141
}
4242

43-
/**
44-
*
45-
*/
46-
get parameters() {
47-
return this.#parameters;
48-
}
49-
50-
/**
51-
*
52-
*/
53-
get children() {
54-
return this.#children;
55-
}
56-
57-
/**
58-
*
59-
*/
60-
get counter() {
61-
return this.#counter;
62-
}
63-
6443
/**
6544
*
6645
*/

0 commit comments

Comments
 (0)