@workbench-kit/workbench-config 0.0.2-prototype.0.2.2 → 0.0.2-prototype.0.2.21
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 +1 -5
- package/src/index.ts +67 -17
- package/src/keybindings-config.ts +6 -38
- package/src/parse-helpers.ts +46 -0
- package/src/user-commands-config.ts +6 -38
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workbench-kit/workbench-config",
|
|
3
|
-
"version": "0.0.2-prototype.0.2.
|
|
3
|
+
"version": "0.0.2-prototype.0.2.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./src/index.ts"
|
|
8
8
|
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"@workbench-kit/base": "0.0.2-prototype.0.2.2",
|
|
11
|
-
"@workbench-kit/platform": "0.0.2-prototype.0.2.2"
|
|
12
|
-
},
|
|
13
9
|
"files": [
|
|
14
10
|
"src",
|
|
15
11
|
"!src/**/*.test.ts",
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertKnownKeys, assertRecord } from './parse-helpers.js';
|
|
1
2
|
import { WorkbenchConfigValidationError } from './validation-error.js';
|
|
2
3
|
|
|
3
4
|
export const WORKBENCH_KIT_WORKBENCH_CONFIG_VERSION = '0.0.0' as const;
|
|
@@ -19,6 +20,16 @@ export interface WorkbenchExtensionsConfig {
|
|
|
19
20
|
recommendations: readonly string[];
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
export interface WorkbenchExtensionsLockEntry {
|
|
24
|
+
readonly integrity?: string | undefined;
|
|
25
|
+
readonly version: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface WorkbenchExtensionsLock {
|
|
29
|
+
readonly extensions: Readonly<Record<string, WorkbenchExtensionsLockEntry>>;
|
|
30
|
+
readonly lockfileVersion: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
export interface WorkbenchLayoutConfig {
|
|
23
34
|
readonly activityBar: {
|
|
24
35
|
readonly hiddenItemIds?: readonly string[];
|
|
@@ -29,6 +40,8 @@ export interface WorkbenchLayoutConfig {
|
|
|
29
40
|
readonly visible: boolean;
|
|
30
41
|
};
|
|
31
42
|
readonly panel: {
|
|
43
|
+
readonly activeViewContainer?: string;
|
|
44
|
+
readonly sizePercent?: number;
|
|
32
45
|
readonly visible: boolean;
|
|
33
46
|
};
|
|
34
47
|
readonly sideBar: {
|
|
@@ -83,6 +96,57 @@ export function parseWorkbenchExtensionsConfigJson(jsonText: string): WorkbenchE
|
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
98
|
|
|
99
|
+
export function parseWorkbenchExtensionsLock(input: unknown): WorkbenchExtensionsLock {
|
|
100
|
+
const record = assertRecord(input, 'extensions lock');
|
|
101
|
+
const lockfileVersion = record.lockfileVersion;
|
|
102
|
+
if (
|
|
103
|
+
typeof lockfileVersion !== 'number' ||
|
|
104
|
+
!Number.isInteger(lockfileVersion) ||
|
|
105
|
+
lockfileVersion < 1
|
|
106
|
+
) {
|
|
107
|
+
throw new WorkbenchConfigValidationError(
|
|
108
|
+
'Expected extensions lock "lockfileVersion" to be a positive integer.',
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const extensionsRecord = assertRecord(record.extensions ?? {}, 'extensions lock extensions');
|
|
113
|
+
const extensions: Record<string, WorkbenchExtensionsLockEntry> = {};
|
|
114
|
+
for (const [extensionId, rawEntry] of Object.entries(extensionsRecord)) {
|
|
115
|
+
const entry = assertRecord(rawEntry, `extensions lock entry "${extensionId}"`);
|
|
116
|
+
if (typeof entry.version !== 'string' || entry.version.trim().length === 0) {
|
|
117
|
+
throw new WorkbenchConfigValidationError(
|
|
118
|
+
`Expected extensions lock entry "${extensionId}" to include a non-empty version.`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (entry.integrity !== undefined && typeof entry.integrity !== 'string') {
|
|
122
|
+
throw new WorkbenchConfigValidationError(
|
|
123
|
+
`Expected extensions lock entry "${extensionId}" integrity to be a string.`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
extensions[extensionId] = {
|
|
127
|
+
integrity: typeof entry.integrity === 'string' ? entry.integrity : undefined,
|
|
128
|
+
version: entry.version.trim(),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
extensions,
|
|
134
|
+
lockfileVersion,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function parseWorkbenchExtensionsLockJson(jsonText: string): WorkbenchExtensionsLock {
|
|
139
|
+
try {
|
|
140
|
+
return parseWorkbenchExtensionsLock(JSON.parse(jsonText) as unknown);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error instanceof WorkbenchConfigValidationError) {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
throw new WorkbenchConfigValidationError('Expected extensions lock to be valid JSON.');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
86
150
|
export function parseWorkbenchLayoutConfig(input: unknown): WorkbenchLayoutConfig {
|
|
87
151
|
const record = assertRecord(input, 'layout config');
|
|
88
152
|
assertKnownKeys(record, ['activityBar', 'auxiliaryBar', 'panel', 'sideBar'], 'layout config');
|
|
@@ -98,7 +162,7 @@ export function parseWorkbenchLayoutConfig(input: unknown): WorkbenchLayoutConfi
|
|
|
98
162
|
'layout config activityBar',
|
|
99
163
|
);
|
|
100
164
|
assertKnownKeys(auxiliaryBar, ['visible'], 'layout config auxiliaryBar');
|
|
101
|
-
assertKnownKeys(panel, ['visible'], 'layout config panel');
|
|
165
|
+
assertKnownKeys(panel, ['activeViewContainer', 'sizePercent', 'visible'], 'layout config panel');
|
|
102
166
|
assertKnownKeys(
|
|
103
167
|
sideBar,
|
|
104
168
|
['activeViewContainer', 'sizePercent', 'visible'],
|
|
@@ -123,6 +187,8 @@ export function parseWorkbenchLayoutConfig(input: unknown): WorkbenchLayoutConfi
|
|
|
123
187
|
),
|
|
124
188
|
},
|
|
125
189
|
panel: {
|
|
190
|
+
...readOptionalLayoutId(panel, 'activeViewContainer'),
|
|
191
|
+
...readOptionalSizePercent(panel, 'sizePercent'),
|
|
126
192
|
visible: readOptionalBoolean(panel, 'visible', DEFAULT_WORKBENCH_LAYOUT_CONFIG.panel.visible),
|
|
127
193
|
},
|
|
128
194
|
sideBar: {
|
|
@@ -181,14 +247,6 @@ export {
|
|
|
181
247
|
type WorkbenchUserCommandsConfig,
|
|
182
248
|
} from './user-commands-config.js';
|
|
183
249
|
|
|
184
|
-
function assertRecord(value: unknown, label: string): Record<string, unknown> {
|
|
185
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
186
|
-
throw new WorkbenchConfigValidationError(`Expected ${label} to be an object.`);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return value as Record<string, unknown>;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
250
|
function readOptionalRecord(record: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
193
251
|
const value = record[key];
|
|
194
252
|
if (value === undefined) {
|
|
@@ -290,11 +348,3 @@ function readOptionalSizePercent(
|
|
|
290
348
|
function clampLayoutSizePercent(value: number): number {
|
|
291
349
|
return Math.min(90, Math.max(10, value));
|
|
292
350
|
}
|
|
293
|
-
|
|
294
|
-
function assertKnownKeys(record: Record<string, unknown>, keys: readonly string[], label: string) {
|
|
295
|
-
const knownKeys = new Set(keys);
|
|
296
|
-
const unknownKeys = Object.keys(record).filter((key) => !knownKeys.has(key));
|
|
297
|
-
if (unknownKeys.length > 0) {
|
|
298
|
-
throw new WorkbenchConfigValidationError(`Unexpected ${label} field "${unknownKeys[0]}".`);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertKnownKeys,
|
|
3
|
+
assertRecord,
|
|
4
|
+
readOptionalString,
|
|
5
|
+
readRequiredString,
|
|
6
|
+
} from './parse-helpers.js';
|
|
1
7
|
import { WorkbenchConfigValidationError } from './validation-error.js';
|
|
2
8
|
|
|
3
9
|
export interface WorkbenchKeybindingDefinition {
|
|
@@ -48,36 +54,6 @@ function parseWorkbenchKeybindingDefinition(
|
|
|
48
54
|
};
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
function assertRecord(value: unknown, label: string): Record<string, unknown> {
|
|
52
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
53
|
-
throw new WorkbenchConfigValidationError(`Expected ${label} to be an object.`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return value as Record<string, unknown>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function readRequiredString(record: Record<string, unknown>, key: string): string {
|
|
60
|
-
const value = record[key];
|
|
61
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
62
|
-
throw new WorkbenchConfigValidationError(`Expected "${key}" to be a non-empty string.`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return value.trim();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function readOptionalString(record: Record<string, unknown>, key: string): string | undefined {
|
|
69
|
-
const value = record[key];
|
|
70
|
-
if (value === undefined) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
75
|
-
throw new WorkbenchConfigValidationError(`Expected "${key}" to be a non-empty string.`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return value.trim();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
57
|
function readOptionalArgs(record: Record<string, unknown>): readonly unknown[] | undefined {
|
|
82
58
|
const value = record.args;
|
|
83
59
|
if (value === undefined) {
|
|
@@ -90,11 +66,3 @@ function readOptionalArgs(record: Record<string, unknown>): readonly unknown[] |
|
|
|
90
66
|
|
|
91
67
|
return [...value];
|
|
92
68
|
}
|
|
93
|
-
|
|
94
|
-
function assertKnownKeys(record: Record<string, unknown>, keys: readonly string[], label: string) {
|
|
95
|
-
const knownKeys = new Set(keys);
|
|
96
|
-
const unknownKeys = Object.keys(record).filter((key) => !knownKeys.has(key));
|
|
97
|
-
if (unknownKeys.length > 0) {
|
|
98
|
-
throw new WorkbenchConfigValidationError(`Unexpected ${label} field "${unknownKeys[0]}".`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { WorkbenchConfigValidationError } from './validation-error.js';
|
|
2
|
+
|
|
3
|
+
export function assertRecord(value: unknown, label: string): Record<string, unknown> {
|
|
4
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
5
|
+
throw new WorkbenchConfigValidationError(`Expected ${label} to be an object.`);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return value as Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function readRequiredString(record: Record<string, unknown>, key: string): string {
|
|
12
|
+
const value = record[key];
|
|
13
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
14
|
+
throw new WorkbenchConfigValidationError(`Expected "${key}" to be a non-empty string.`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return value.trim();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function readOptionalString(
|
|
21
|
+
record: Record<string, unknown>,
|
|
22
|
+
key: string,
|
|
23
|
+
): string | undefined {
|
|
24
|
+
const value = record[key];
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
30
|
+
throw new WorkbenchConfigValidationError(`Expected "${key}" to be a non-empty string.`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return value.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function assertKnownKeys(
|
|
37
|
+
record: Record<string, unknown>,
|
|
38
|
+
keys: readonly string[],
|
|
39
|
+
label: string,
|
|
40
|
+
) {
|
|
41
|
+
const knownKeys = new Set(keys);
|
|
42
|
+
const unknownKeys = Object.keys(record).filter((key) => !knownKeys.has(key));
|
|
43
|
+
if (unknownKeys.length > 0) {
|
|
44
|
+
throw new WorkbenchConfigValidationError(`Unexpected ${label} field "${unknownKeys[0]}".`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertKnownKeys,
|
|
3
|
+
assertRecord,
|
|
4
|
+
readOptionalString,
|
|
5
|
+
readRequiredString,
|
|
6
|
+
} from './parse-helpers.js';
|
|
1
7
|
import { WorkbenchConfigValidationError } from './validation-error.js';
|
|
2
8
|
|
|
3
9
|
export interface WorkbenchUserCommandExecuteAction {
|
|
@@ -102,36 +108,6 @@ function parseUserCommandAction(input: unknown, label: string): WorkbenchUserCom
|
|
|
102
108
|
throw new WorkbenchConfigValidationError(`Unexpected ${label} type "${type}".`);
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
function assertRecord(value: unknown, label: string): Record<string, unknown> {
|
|
106
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
107
|
-
throw new WorkbenchConfigValidationError(`Expected ${label} to be an object.`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return value as Record<string, unknown>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function readRequiredString(record: Record<string, unknown>, key: string): string {
|
|
114
|
-
const value = record[key];
|
|
115
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
116
|
-
throw new WorkbenchConfigValidationError(`Expected "${key}" to be a non-empty string.`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return value.trim();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function readOptionalString(record: Record<string, unknown>, key: string): string | undefined {
|
|
123
|
-
const value = record[key];
|
|
124
|
-
if (value === undefined) {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
129
|
-
throw new WorkbenchConfigValidationError(`Expected "${key}" to be a non-empty string.`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return value.trim();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
111
|
function readOptionalNumber(record: Record<string, unknown>, key: string): number | undefined {
|
|
136
112
|
const value = record[key];
|
|
137
113
|
if (value === undefined) {
|
|
@@ -144,11 +120,3 @@ function readOptionalNumber(record: Record<string, unknown>, key: string): numbe
|
|
|
144
120
|
|
|
145
121
|
return value;
|
|
146
122
|
}
|
|
147
|
-
|
|
148
|
-
function assertKnownKeys(record: Record<string, unknown>, keys: readonly string[], label: string) {
|
|
149
|
-
const knownKeys = new Set(keys);
|
|
150
|
-
const unknownKeys = Object.keys(record).filter((key) => !knownKeys.has(key));
|
|
151
|
-
if (unknownKeys.length > 0) {
|
|
152
|
-
throw new WorkbenchConfigValidationError(`Unexpected ${label} field "${unknownKeys[0]}".`);
|
|
153
|
-
}
|
|
154
|
-
}
|