screenreader-speech-capture 0.0.1-preview.0 → 0.0.1-preview.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 (2) hide show
  1. package/dist/cli.mjs +98 -2
  2. package/package.json +8 -8
package/dist/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import { TextDecoder as TextDecoder$1 } from "node:util";
4
4
  import { performance } from "node:perf_hooks";
5
5
  import { monotonicFactory } from "ulid";
6
6
  // package.json
7
- var version = "0.0.1-preview.0";
7
+ var version = "0.0.1-preview.1";
8
8
  // src/adapters/in/tcp/text-to-socket-parser.ts
9
9
  const LF = 10;
10
10
  const CR = 13;
@@ -266,6 +266,13 @@ var AppError = class extends Error {
266
266
  function invalidField(field, message) {
267
267
  return new AppError("INVALID_REQUEST", `${field}: ${message}`, { field });
268
268
  }
269
+ // src/domain/config.ts
270
+ const LOG_LEVELS = [
271
+ "error",
272
+ "warn",
273
+ "info",
274
+ "debug"
275
+ ];
269
276
  const DEFAULT_CONFIG = {
270
277
  tcp: {
271
278
  host: "127.0.0.1",
@@ -295,6 +302,79 @@ const DEFAULT_CONFIG = {
295
302
  file: null
296
303
  }
297
304
  };
305
+ const integer = (min, max) => (value) => typeof value === "number" && Number.isInteger(value) && value >= min && value <= max ? void 0 : `must be an integer from ${min} to ${max}`;
306
+ const port = integer(0, 65535);
307
+ const boolean = (value) => typeof value === "boolean" ? void 0 : "must be true or false";
308
+ const nonEmptyString = (value) => typeof value === "string" && value.trim() !== "" ? void 0 : "must be a non-empty string";
309
+ const nullableString = (value) => value === null ? void 0 : nonEmptyString(value) && "must be a non-empty string or null";
310
+ const oneOf = (values) => (value) => typeof value === "string" && values.includes(value) ? void 0 : `must be one of ${values.join(", ")}`;
311
+ const encoding = (value) => {
312
+ if (typeof value !== "string") return "must be a string";
313
+ try {
314
+ new TextDecoder(value);
315
+ return;
316
+ } catch {
317
+ return `unknown encoding "${value}"`;
318
+ }
319
+ };
320
+ const SCHEMA = {
321
+ tcp: {
322
+ host: nonEmptyString,
323
+ port,
324
+ format: oneOf(["text-to-socket"]),
325
+ encoding,
326
+ maxLineBytes: integer(1024, 16777216)
327
+ },
328
+ http: {
329
+ host: nonEmptyString,
330
+ port
331
+ },
332
+ playwright: {
333
+ enabled: boolean,
334
+ port,
335
+ version: nullableString
336
+ },
337
+ mcp: {
338
+ enabled: boolean,
339
+ port,
340
+ version: nullableString
341
+ },
342
+ input: { enabled: boolean },
343
+ buffer: { maxEntries: integer(1, 1e6) },
344
+ log: {
345
+ level: oneOf(LOG_LEVELS),
346
+ file: nullableString
347
+ }
348
+ };
349
+ function isPlainObject(value) {
350
+ return typeof value === "object" && value !== null && !Array.isArray(value);
351
+ }
352
+ /**
353
+ * Applies a partial configuration to `base` and validates the result.
354
+ * Throws `INVALID_REQUEST` naming the first invalid or unknown field (`details.field`).
355
+ */
356
+ function mergeConfig(base, patch) {
357
+ if (patch === void 0 || patch === null) return base;
358
+ if (!isPlainObject(patch)) throw invalidField("config", "must be an object");
359
+ const result = {};
360
+ for (const section of Object.keys(base)) result[section] = { ...base[section] };
361
+ for (const [section, values] of Object.entries(patch)) {
362
+ const sectionSchema = SCHEMA[section];
363
+ if (sectionSchema === void 0) throw invalidField(section, "unknown setting");
364
+ if (values === void 0) continue;
365
+ if (!isPlainObject(values)) throw invalidField(section, "must be an object");
366
+ for (const [key, value] of Object.entries(values)) {
367
+ const field = `${section}.${key}`;
368
+ const check = sectionSchema[key];
369
+ if (check === void 0) throw invalidField(field, "unknown setting");
370
+ if (value === void 0) continue;
371
+ const problem = check(value);
372
+ if (problem !== void 0) throw invalidField(field, problem);
373
+ result[section][key] = value;
374
+ }
375
+ }
376
+ return result;
377
+ }
298
378
  // src/adapters/out/clock/system-clock.ts
299
379
  var SystemClock = class {
300
380
  now() {
@@ -559,7 +639,23 @@ async function startBridge(options) {
559
639
  };
560
640
  }
561
641
  // src/cli.ts
562
- const config = DEFAULT_CONFIG;
642
+ function configFromEnv(env) {
643
+ const port = env.SR_SPEECH_TCP_PORT;
644
+ return mergeConfig(DEFAULT_CONFIG, {
645
+ tcp: {
646
+ port: port === void 0 ? void 0 : Number(port),
647
+ encoding: env.SR_SPEECH_TCP_ENCODING
648
+ },
649
+ log: { level: env.SR_SPEECH_LOG_LEVEL }
650
+ });
651
+ }
652
+ let config;
653
+ try {
654
+ config = configFromEnv(process.env);
655
+ } catch (error) {
656
+ process.stderr.write(`screenreader-speech-capture: ${error.message}\n`);
657
+ process.exit(2);
658
+ }
563
659
  const log = new BridgeLog(config.log.level, [consoleSink()]);
564
660
  try {
565
661
  const bridge = await startBridge({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screenreader-speech-capture",
3
- "version": "0.0.1-preview.0",
3
+ "version": "0.0.1-preview.1",
4
4
  "description": "Capture what a screen reader says (JAWS / NVDA via a SAPI 5 socket voice) and expose it over HTTP for automated tests.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -13,16 +13,16 @@
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
- "scripts": {
17
- "build": "tsdown",
18
- "dev": "tsx watch src/cli.ts",
19
- "typecheck": "tsc --noEmit"
20
- },
21
16
  "dependencies": {
22
17
  "ulid": "^3.0.2"
23
18
  },
24
19
  "devDependencies": {
25
- "@screenreader-speech-capture/shared": "workspace:*",
20
+ "@screenreader-speech-capture/shared": "0.0.0",
26
21
  "tsdown": "^0.23.7"
22
+ },
23
+ "scripts": {
24
+ "build": "tsdown",
25
+ "dev": "tsx watch src/cli.ts",
26
+ "typecheck": "tsc --noEmit"
27
27
  }
28
- }
28
+ }