@workbench-kit/workbench-config 0.0.2-prototype.0.2.10 → 0.0.2-prototype.0.2.11

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,14 +1,14 @@
1
1
  {
2
2
  "name": "@workbench-kit/workbench-config",
3
- "version": "0.0.2-prototype.0.2.10",
3
+ "version": "0.0.2-prototype.0.2.11",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./src/index.ts"
8
8
  },
9
9
  "dependencies": {
10
- "@workbench-kit/base": "0.0.2-prototype.0.2.10",
11
- "@workbench-kit/platform": "0.0.2-prototype.0.2.10"
10
+ "@workbench-kit/base": "0.0.2-prototype.0.2.11",
11
+ "@workbench-kit/platform": "0.0.2-prototype.0.2.11"
12
12
  },
13
13
  "files": [
14
14
  "src",
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;
@@ -242,14 +243,6 @@ export {
242
243
  type WorkbenchUserCommandsConfig,
243
244
  } from './user-commands-config.js';
244
245
 
245
- function assertRecord(value: unknown, label: string): Record<string, unknown> {
246
- if (typeof value !== 'object' || value === null || Array.isArray(value)) {
247
- throw new WorkbenchConfigValidationError(`Expected ${label} to be an object.`);
248
- }
249
-
250
- return value as Record<string, unknown>;
251
- }
252
-
253
246
  function readOptionalRecord(record: Record<string, unknown>, key: string): Record<string, unknown> {
254
247
  const value = record[key];
255
248
  if (value === undefined) {
@@ -351,11 +344,3 @@ function readOptionalSizePercent(
351
344
  function clampLayoutSizePercent(value: number): number {
352
345
  return Math.min(90, Math.max(10, value));
353
346
  }
354
-
355
- function assertKnownKeys(record: Record<string, unknown>, keys: readonly string[], label: string) {
356
- const knownKeys = new Set(keys);
357
- const unknownKeys = Object.keys(record).filter((key) => !knownKeys.has(key));
358
- if (unknownKeys.length > 0) {
359
- throw new WorkbenchConfigValidationError(`Unexpected ${label} field "${unknownKeys[0]}".`);
360
- }
361
- }
@@ -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
- }