@kar-mi/spirit-vale-tools-logging 0.10.0 → 0.10.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { JsonLinesLogger, activateLogSession, createLogSession, readCurrentLogStream, writeCurrentLogStreamPointer, } from "./logger.ts";
2
2
  export { encodeLogRecord, encodeLogStreamHeader, isLogStreamHeader, parseLogRecord, parseLogStreamHeader, } from "./record-codec.ts";
3
+ export { decoderForText, LogRecordLineDecoder, readTextLines } from "./record-reader.ts";
4
+ export type { DecodedLogLine } from "./record-reader.ts";
3
5
  export type { CreateLogSessionOptions, JsonLinesLoggerOptions, JsonLinesLoggerStats, LoggerTuning, LogWriteFailure, } from "./logger.ts";
4
6
  export { sanitizeCombatData } from "./combat-sanitizer.ts";
5
7
  export { defaultLogDirectory, currentStreamPointerPath, streamCategoryDirectory, streamSessionPath, } from "./paths.ts";
@@ -13,4 +15,5 @@ export type { LiveLogLineConsumer, LiveLogSessionFollowerOptions } from "./sessi
13
15
  export { DEFAULT_STREAM_BATCH_BYTES, DEFAULT_STREAM_DEBOUNCE_MS, DEFAULT_STREAM_FALLBACK_POLL_MS, subscribeToLogStream, } from "./stream-source.ts";
14
16
  export type { LogStreamRead, LogStreamSourceOptions, LogStreamSubscription } from "./stream-source.ts";
15
17
  export type { CurrentLogStream, JsonData, JsonObject, LogRecord, LogSession, ListedLogSession, LogStream, LogStreamHeader, } from "./types.ts";
18
+ export { compact, count, warnings } from "./text-format.ts";
16
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,i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AAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -103,7 +103,7 @@ function isIsoDate(value) {
103
103
  return isNonEmptyString(value) && Number.isFinite(Date.parse(value));
104
104
  }
105
105
  function isLogStream(value) {
106
- return value === "capture" || value === "combat" || value === "rewards" || value === "other";
106
+ return value === "capture" || value === "combat" || value === "market" || value === "rewards" || value === "other";
107
107
  }
108
108
 
109
109
  // src/combat-sanitizer.ts
@@ -422,6 +422,61 @@ function isIsoDate2(value) {
422
422
  function toError(error) {
423
423
  return error instanceof Error ? error : new Error(String(error));
424
424
  }
425
+ // src/record-reader.ts
426
+ class LogRecordLineDecoder {
427
+ header;
428
+ decode(line) {
429
+ if (!line.trim())
430
+ return { kind: "empty" };
431
+ let value;
432
+ try {
433
+ value = JSON.parse(line);
434
+ } catch {
435
+ return { kind: "invalid" };
436
+ }
437
+ if (isRecord(value) && value["schemaVersion"] === 2) {
438
+ const header = parseLogStreamHeader(value);
439
+ if (!header)
440
+ return { kind: "invalid" };
441
+ this.header = header;
442
+ return { kind: "header", header };
443
+ }
444
+ const record = parseLogRecord(value, this.header);
445
+ return record ? { kind: "record", record } : { kind: "invalid" };
446
+ }
447
+ reset() {
448
+ this.header = undefined;
449
+ }
450
+ }
451
+ async function* readTextLines(stream) {
452
+ const reader = stream.getReader();
453
+ let decoder;
454
+ let pending = "";
455
+ try {
456
+ while (true) {
457
+ const { done, value } = await reader.read();
458
+ if (done)
459
+ break;
460
+ decoder ??= decoderForText(value);
461
+ pending += decoder.decode(value, { stream: true });
462
+ const lines = pending.split(/\r?\n/);
463
+ pending = lines.pop() ?? "";
464
+ yield* lines;
465
+ }
466
+ pending += decoder?.decode() ?? "";
467
+ if (pending)
468
+ yield pending;
469
+ } finally {
470
+ reader.releaseLock();
471
+ }
472
+ }
473
+ function decoderForText(firstChunk) {
474
+ if (firstChunk[0] === 255 && firstChunk[1] === 254)
475
+ return new TextDecoder("utf-16le");
476
+ if (firstChunk[0] === 254 && firstChunk[1] === 255)
477
+ return new TextDecoder("utf-16be");
478
+ return new TextDecoder("utf-8");
479
+ }
425
480
  // src/sessions.ts
426
481
  import { lstat, open as open2, readFile as readFile2, readdir } from "fs/promises";
427
482
  import path3 from "path";
@@ -954,6 +1009,16 @@ class LiveLogSessionFollower {
954
1009
  return { ...merged, path: read.current.path, sessionId: read.current.sessionId };
955
1010
  }
956
1011
  }
1012
+ // src/text-format.ts
1013
+ function count(value, label) {
1014
+ return `${value} ${label}${value === 1 ? "" : "s"}`;
1015
+ }
1016
+ function compact(value) {
1017
+ return new Intl.NumberFormat(undefined, { notation: "compact", maximumFractionDigits: 1 }).format(value);
1018
+ }
1019
+ function warnings(value) {
1020
+ return value === 0 ? "" : ` \xB7 ${value} skipped`;
1021
+ }
957
1022
  export {
958
1023
  DEFAULT_STREAM_BATCH_BYTES,
959
1024
  DEFAULT_STREAM_DEBOUNCE_MS,
@@ -961,10 +1026,14 @@ export {
961
1026
  JsonLinesLogger,
962
1027
  JsonlTailReader,
963
1028
  LiveLogSessionFollower,
1029
+ LogRecordLineDecoder,
964
1030
  activateLogSession,
1031
+ compact,
1032
+ count,
965
1033
  createLogSession,
966
1034
  currentStreamPointerPath,
967
1035
  decimal,
1036
+ decoderForText,
968
1037
  defaultLogDirectory,
969
1038
  encodeLogRecord,
970
1039
  encodeLogStreamHeader,
@@ -976,9 +1045,11 @@ export {
976
1045
  parseLogRecord,
977
1046
  parseLogStreamHeader,
978
1047
  readCurrentLogStream,
1048
+ readTextLines,
979
1049
  sanitizeCombatData,
980
1050
  streamCategoryDirectory,
981
1051
  streamSessionPath,
982
1052
  subscribeToLogStream,
1053
+ warnings,
983
1054
  writeCurrentLogStreamPointer
984
1055
  };
@@ -0,0 +1,23 @@
1
+ import type { LogRecord, LogStreamHeader } from "./types.ts";
2
+ export type DecodedLogLine = {
3
+ kind: "empty";
4
+ } | {
5
+ kind: "header";
6
+ header: LogStreamHeader;
7
+ } | {
8
+ kind: "record";
9
+ record: LogRecord;
10
+ } | {
11
+ kind: "invalid";
12
+ };
13
+ /** Stateful JSONL decoder that keeps v2 stream metadata while accepting legacy v1 records. */
14
+ export declare class LogRecordLineDecoder {
15
+ private header?;
16
+ decode(line: string): DecodedLogLine;
17
+ reset(): void;
18
+ }
19
+ /** Splits a byte stream into lines, recognizing the Unicode BOMs supported by live combat logs. */
20
+ export declare function readTextLines(stream: ReadableStream<Uint8Array>): AsyncGenerator<string>;
21
+ /** Decoder selection shared by incremental readers that need the same BOM behavior. */
22
+ export declare function decoderForText(firstChunk: Uint8Array): TextDecoder;
23
+ //# sourceMappingURL=record-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-reader.d.ts","sourceRoot":"","sources":["../src/record-reader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAExB,8FAA8F;AAC9F,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,CAAkB;IAEjC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAoBnC;IAED,KAAK,IAAI,IAAI,CAEZ;CACF;AAED,mGAAmG;AACnG,wBAAuB,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAmB/F;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAIlE"}
@@ -0,0 +1,4 @@
1
+ export declare function count(value: number, label: string): string;
2
+ export declare function compact(value: number | bigint): string;
3
+ export declare function warnings(value: number): string;
4
+ //# sourceMappingURL=text-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-format.d.ts","sourceRoot":"","sources":["../src/text-format.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kar-mi/spirit-vale-tools-logging",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Session-oriented logging utilities for Spirit Vale tools.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {