|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const { |
4 | | - ArrayPrototypeMap, |
5 | | - ArrayPrototypeSort, |
6 | | - ObjectEntries, |
7 | | - ObjectFromEntries, |
8 | | - ObjectKeys, |
9 | | - StringPrototypeReplace, |
| 4 | + JSONParse, |
10 | 5 | } = primordials; |
11 | 6 |
|
12 | 7 | const { |
13 | 8 | getCLIOptionsValues, |
14 | 9 | getCLIOptionsInfo, |
15 | 10 | getOptionsAsFlags, |
16 | 11 | getEmbedderOptions: getEmbedderOptionsFromBinding, |
17 | | - getEnvOptionsInputType, |
18 | | - getNamespaceOptionsInputType, |
| 12 | + getConfigJsonSchema, |
19 | 13 | } = internalBinding('options'); |
20 | 14 |
|
21 | 15 | let warnOnAllowUnauthorized = true; |
@@ -46,101 +40,7 @@ function getEmbedderOptions() { |
46 | 40 | } |
47 | 41 |
|
48 | 42 | function generateConfigJsonSchema() { |
49 | | - const envOptionsMap = getEnvOptionsInputType(); |
50 | | - const namespaceOptionsMap = getNamespaceOptionsInputType(); |
51 | | - |
52 | | - function createPropertyForOptionDetail(detail) { |
53 | | - const { type, description } = detail; |
54 | | - if (type === 'array') { |
55 | | - return { |
56 | | - __proto__: null, |
57 | | - oneOf: [ |
58 | | - { __proto__: null, type: 'string' }, |
59 | | - { __proto__: null, type: 'array', minItems: 1, items: { __proto__: null, type: 'string' } }, |
60 | | - ], |
61 | | - description, |
62 | | - }; |
63 | | - } |
64 | | - |
65 | | - return { __proto__: null, type, description }; |
66 | | - } |
67 | | - |
68 | | - const schema = { |
69 | | - __proto__: null, |
70 | | - $schema: 'https://json-schema.org/draft/2020-12/schema', |
71 | | - additionalProperties: false, |
72 | | - required: [], |
73 | | - properties: { |
74 | | - $schema: { |
75 | | - __proto__: null, |
76 | | - type: 'string', |
77 | | - }, |
78 | | - nodeOptions: { |
79 | | - __proto__: null, |
80 | | - additionalProperties: false, |
81 | | - required: [], |
82 | | - properties: { __proto__: null }, |
83 | | - type: 'object', |
84 | | - }, |
85 | | - __proto__: null, |
86 | | - }, |
87 | | - type: 'object', |
88 | | - }; |
89 | | - |
90 | | - // Get the root properties object for adding namespaces |
91 | | - const rootProperties = schema.properties; |
92 | | - const nodeOptions = rootProperties.nodeOptions.properties; |
93 | | - |
94 | | - // Add env options to nodeOptions (backward compatibility) |
95 | | - for (const { 0: key, 1: type } of ObjectEntries(envOptionsMap)) { |
96 | | - const keyWithoutPrefix = StringPrototypeReplace(key, '--', ''); |
97 | | - nodeOptions[keyWithoutPrefix] = createPropertyForOptionDetail(type); |
98 | | - } |
99 | | - |
100 | | - // Add namespace properties at the root level |
101 | | - for (const { 0: namespace, 1: optionsMap } of namespaceOptionsMap) { |
102 | | - // Create namespace object at the root level |
103 | | - rootProperties[namespace] = { |
104 | | - __proto__: null, |
105 | | - type: 'object', |
106 | | - additionalProperties: false, |
107 | | - required: [], |
108 | | - properties: { __proto__: null }, |
109 | | - }; |
110 | | - |
111 | | - const namespaceProperties = rootProperties[namespace].properties; |
112 | | - |
113 | | - // Add all options for this namespace |
114 | | - for (const { 0: optionName, 1: optionType } of ObjectEntries(optionsMap)) { |
115 | | - const keyWithoutPrefix = StringPrototypeReplace(optionName, '--', ''); |
116 | | - namespaceProperties[keyWithoutPrefix] = createPropertyForOptionDetail(optionType); |
117 | | - } |
118 | | - |
119 | | - // Sort the namespace properties alphabetically |
120 | | - const sortedNamespaceKeys = ArrayPrototypeSort(ObjectKeys(namespaceProperties)); |
121 | | - const sortedNamespaceProperties = ObjectFromEntries( |
122 | | - ArrayPrototypeMap(sortedNamespaceKeys, (key) => [key, namespaceProperties[key]]), |
123 | | - ); |
124 | | - rootProperties[namespace].properties = sortedNamespaceProperties; |
125 | | - } |
126 | | - |
127 | | - // Sort the top-level properties by key alphabetically |
128 | | - const sortedKeys = ArrayPrototypeSort(ObjectKeys(nodeOptions)); |
129 | | - const sortedProperties = ObjectFromEntries( |
130 | | - ArrayPrototypeMap(sortedKeys, (key) => [key, nodeOptions[key]]), |
131 | | - ); |
132 | | - |
133 | | - schema.properties.nodeOptions.properties = sortedProperties; |
134 | | - |
135 | | - // Also sort the root level properties |
136 | | - const sortedRootKeys = ArrayPrototypeSort(ObjectKeys(rootProperties)); |
137 | | - const sortedRootProperties = ObjectFromEntries( |
138 | | - ArrayPrototypeMap(sortedRootKeys, (key) => [key, rootProperties[key]]), |
139 | | - ); |
140 | | - |
141 | | - schema.properties = sortedRootProperties; |
142 | | - |
143 | | - return schema; |
| 43 | + return JSONParse(getConfigJsonSchema()); |
144 | 44 | } |
145 | 45 |
|
146 | 46 | function refreshOptions() { |
|
0 commit comments