argsbarg 6.1.7 → 6.1.9

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.
@@ -195,7 +195,7 @@ MCP server and bundle tools.
195
195
  | Option | Type | Required | Format / default | Description |
196
196
  | --- | --- | --- | --- | --- |
197
197
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
198
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
198
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
199
199
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
200
200
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
201
201
 
@@ -231,7 +231,7 @@ HTTP API server for tools.
231
231
  | `--port` | number | optional | — | Listen port. |
232
232
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
233
233
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
234
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
234
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
235
235
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
236
236
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
237
237
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -408,7 +408,7 @@ MCP server and bundle tools.
408
408
  | Option | Type | Required | Format / default | Description |
409
409
  | --- | --- | --- | --- | --- |
410
410
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
411
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
411
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
412
412
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
413
413
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
414
414
 
@@ -444,7 +444,7 @@ HTTP API server for tools.
444
444
  | `--port` | number | optional | — | Listen port. |
445
445
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
446
446
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
447
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
447
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
448
448
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
449
449
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
450
450
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -649,7 +649,7 @@ MCP server and bundle tools.
649
649
  | Option | Type | Required | Format / default | Description |
650
650
  | --- | --- | --- | --- | --- |
651
651
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
652
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
652
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
653
653
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
654
654
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
655
655
 
@@ -685,7 +685,7 @@ HTTP API server for tools.
685
685
  | `--port` | number | optional | — | Listen port. |
686
686
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
687
687
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
688
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
688
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
689
689
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
690
690
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
691
691
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -872,7 +872,7 @@ MCP server and bundle tools.
872
872
  | Option | Type | Required | Format / default | Description |
873
873
  | --- | --- | --- | --- | --- |
874
874
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
875
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
875
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
876
876
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
877
877
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
878
878
 
@@ -908,7 +908,7 @@ HTTP API server for tools.
908
908
  | `--port` | number | optional | — | Listen port. |
909
909
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
910
910
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
911
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
911
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
912
912
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
913
913
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
914
914
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -1085,7 +1085,7 @@ MCP server and bundle tools.
1085
1085
  | Option | Type | Required | Format / default | Description |
1086
1086
  | --- | --- | --- | --- | --- |
1087
1087
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1088
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1088
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1089
1089
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1090
1090
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
1091
1091
 
@@ -1121,7 +1121,7 @@ HTTP API server for tools.
1121
1121
  | `--port` | number | optional | — | Listen port. |
1122
1122
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
1123
1123
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1124
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1124
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1125
1125
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1126
1126
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
1127
1127
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -1309,7 +1309,7 @@ MCP server and bundle tools.
1309
1309
  | Option | Type | Required | Format / default | Description |
1310
1310
  | --- | --- | --- | --- | --- |
1311
1311
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1312
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1312
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1313
1313
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1314
1314
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
1315
1315
 
@@ -1345,7 +1345,7 @@ HTTP API server for tools.
1345
1345
  | `--port` | number | optional | — | Listen port. |
1346
1346
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
1347
1347
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1348
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1348
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1349
1349
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1350
1350
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
1351
1351
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -1522,7 +1522,7 @@ MCP server and bundle tools.
1522
1522
  | Option | Type | Required | Format / default | Description |
1523
1523
  | --- | --- | --- | --- | --- |
1524
1524
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1525
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1525
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1526
1526
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1527
1527
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
1528
1528
 
@@ -1558,7 +1558,7 @@ HTTP API server for tools.
1558
1558
  | `--port` | number | optional | — | Listen port. |
1559
1559
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
1560
1560
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1561
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1561
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1562
1562
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1563
1563
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
1564
1564
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -1735,7 +1735,7 @@ MCP server and bundle tools.
1735
1735
  | Option | Type | Required | Format / default | Description |
1736
1736
  | --- | --- | --- | --- | --- |
1737
1737
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1738
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1738
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1739
1739
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1740
1740
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
1741
1741
 
@@ -1771,7 +1771,7 @@ HTTP API server for tools.
1771
1771
  | `--port` | number | optional | — | Listen port. |
1772
1772
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
1773
1773
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1774
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1774
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1775
1775
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1776
1776
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
1777
1777
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -1948,7 +1948,7 @@ MCP server and bundle tools.
1948
1948
  | Option | Type | Required | Format / default | Description |
1949
1949
  | --- | --- | --- | --- | --- |
1950
1950
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1951
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1951
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1952
1952
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1953
1953
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
1954
1954
 
@@ -1984,7 +1984,7 @@ HTTP API server for tools.
1984
1984
  | `--port` | number | optional | — | Listen port. |
1985
1985
  | `--trust-proxy` | flag | optional | — | Honor X-Forwarded-For for client IP. |
1986
1986
  | `--obscure-errors` | flag | optional | — | Hide unexpected errors from clients. |
1987
- | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS) or text. |
1987
+ | `--log-format` | enum (`json`, `text`) | optional | — | Log format: json (ECS Logging) or text. |
1988
1988
  | `--log-file` | string | optional | — | Append logs to this file (relative → app config dir). |
1989
1989
  | `--no-access-log` | flag | optional | — | Disable HTTP access logs. |
1990
1990
  | `--dev` | flag | optional | — | Print full stacks to stderr on errors. |
@@ -45,6 +45,16 @@ Handlers must use `ctx.respond()` or return a value for API/MCP tool calls.
45
45
 
46
46
  Errors use `{ "error": "..." }` with `400`, `404`, `503`, or `500`.
47
47
 
48
+ ## Logging
49
+
50
+ Server logs go to **stderr** (one JSON object per line by default).
51
+
52
+ - Configure with `program.log` on the program root
53
+ - **`enrich`** — add custom JSON fields on top of the default line
54
+ - **`serialize`** — replace the formatter and emit your own line shape
55
+
56
+ See the argsbarg [logging guide](https://github.com/bdombro/bun-argsbarg/blob/main/docs/logging.md) for examples and the full `LogEnrichContext` shape.
57
+
48
58
  ## REST routes
49
59
 
50
60
  - `POST /echo` (CLI: `full-example echo`) — Echo a message (MCP-friendly leaf).
package/index.d.ts CHANGED
@@ -113,6 +113,59 @@ export declare class CliContext {
113
113
  private _posMap;
114
114
  private _positionalMap;
115
115
  }
116
+ /** ECS version string written to every JSON log line. */
117
+ export declare const ECS_VERSION = "8.11.0";
118
+ /** Severity label for ECS `log.level`. */
119
+ export type EcsLogLevel = "debug" | "info" | "warn" | "error";
120
+ /** Fields merged into every ECS log line. */
121
+ export interface EcsServiceFields {
122
+ name: string;
123
+ version: string;
124
+ }
125
+ /** Context for {@link CliLogConfig.enrich} and {@link CliLogConfig.serialize}. */
126
+ export interface LogEnrichContext {
127
+ level: EcsLogLevel;
128
+ message: string;
129
+ action?: string;
130
+ requestId?: string;
131
+ traceId?: string;
132
+ spanId?: string;
133
+ labels?: Record<string, string | number | boolean>;
134
+ error?: unknown;
135
+ service: EcsServiceFields;
136
+ http?: {
137
+ method: string;
138
+ path: string;
139
+ status: number;
140
+ durationMs: number;
141
+ clientIp?: string;
142
+ };
143
+ }
144
+ /** Input for one ECS log event. */
145
+ export interface EcsLogEvent {
146
+ level: EcsLogLevel;
147
+ message: string;
148
+ action?: string;
149
+ labels?: Record<string, string | number | boolean>;
150
+ error?: unknown;
151
+ fields?: Record<string, unknown>;
152
+ requestId?: string;
153
+ traceId?: string;
154
+ spanId?: string;
155
+ /** Populated on HTTP/MCP access log events for {@link CliLogConfig.enrich}. */
156
+ http?: LogEnrichContext["http"];
157
+ }
158
+ /** Options for {@link formatEcsLine}. */
159
+ export interface FormatEcsLineOpts {
160
+ service: EcsServiceFields;
161
+ event: EcsLogEvent;
162
+ /** Additive fields merged after the ECS baseline (cannot override protected keys). */
163
+ enrich?: (ctx: LogEnrichContext) => Record<string, unknown>;
164
+ }
165
+ /** Formats one ECS Logging–compatible JSON log line (newline omitted). */
166
+ export declare function formatEcsLine(opts: FormatEcsLineOpts): string;
167
+ /** @deprecated Pass {@link FormatEcsLineOpts} instead. */
168
+ export declare function formatEcsLine(service: EcsServiceFields, event: EcsLogEvent): string;
116
169
  /**
117
170
  * How a leaf handler was dispatched.
118
171
  */
@@ -324,6 +377,10 @@ export interface CliHttpWireContext {
324
377
  clientIp: string;
325
378
  path: string;
326
379
  method: string;
380
+ /** W3C trace id when `traceparent` is present on the request. */
381
+ traceId?: string;
382
+ /** Span id for this server hop when `traceparent` is present. */
383
+ spanId?: string;
327
384
  }
328
385
  /** Wire-level MCP hooks on JSON-RPC messages (observe-only). */
329
386
  export interface CliMcpWireHooks {
@@ -672,6 +729,8 @@ export interface InvokeHookContext {
672
729
  request: Request;
673
730
  clientIp: string;
674
731
  requestId: string;
732
+ traceId?: string;
733
+ spanId?: string;
675
734
  };
676
735
  mcp?: {
677
736
  rpcMethod: string;
@@ -717,9 +776,9 @@ export interface ReadinessContext {
717
776
  appConfig: AnyAppConfigSnapshot;
718
777
  runtime: ServerRuntime;
719
778
  }
720
- /** Framework logging defaults (ECS json or human text on stderr). */
779
+ /** Framework logging defaults (ECS Logging json or human text on stderr). */
721
780
  export interface CliLogConfig {
722
- /** `json` = ECS lines; `text` = human stderr lines. Default: `json`. */
781
+ /** `json` = ECS Logging lines; `text` = human stderr lines. Default: `json`. */
723
782
  format?: "json" | "text";
724
783
  /** Tee stderr + append; relative paths resolve under the app config dir. */
725
784
  file?: string;
@@ -727,6 +786,16 @@ export interface CliLogConfig {
727
786
  access?: boolean;
728
787
  /** Emit error events after the hook pipeline. Default: true. */
729
788
  errors?: boolean;
789
+ /**
790
+ * Add non-standard fields to each JSON log line after the ECS baseline.
791
+ * Cannot override `@timestamp`, `log.level`, `message`, `ecs.version`, or service fields.
792
+ */
793
+ enrich?: (ctx: LogEnrichContext) => Record<string, unknown>;
794
+ /**
795
+ * Full control over JSON log line serialization. When set, bypasses the built-in ECS formatter.
796
+ * The consumer owns the entire line (including newline omission).
797
+ */
798
+ serialize?: (ctx: LogEnrichContext) => string;
730
799
  }
731
800
  /**
732
801
  * Program root passed to {@link Cli}.
@@ -870,17 +939,6 @@ export interface CliSchemaRootExport extends CliSchemaExport {
870
939
  /** Program-level error JSON Schema when configured on `httpServer.errors` or `mcpServer.errors`. */
871
940
  errorSchema?: Record<string, unknown>;
872
941
  }
873
- /** Severity label for ECS `log.level`. */
874
- export type EcsLogLevel = "debug" | "info" | "warn" | "error";
875
- /** Input for one ECS log event. */
876
- export interface EcsLogEvent {
877
- level: EcsLogLevel;
878
- message: string;
879
- action?: string;
880
- labels?: Record<string, string | number | boolean>;
881
- error?: unknown;
882
- fields?: Record<string, unknown>;
883
- }
884
942
  /** Resolved logging options for a server or invoke session. */
885
943
  export interface ResolvedLogConfig {
886
944
  format: "json" | "text";
@@ -888,6 +946,8 @@ export interface ResolvedLogConfig {
888
946
  access: boolean;
889
947
  errors: boolean;
890
948
  dev: boolean;
949
+ enrich?: CliLogConfig["enrich"];
950
+ serialize?: CliLogConfig["serialize"];
891
951
  }
892
952
  /** Options for {@link LogEmitter}. */
893
953
  export interface LogEmitterOpts {
@@ -911,10 +971,18 @@ declare class LogEmitter {
911
971
  durationMs: number;
912
972
  requestId?: string;
913
973
  clientIp?: string;
974
+ traceId?: string;
975
+ spanId?: string;
914
976
  }): void;
915
977
  /** Error log after the hook pipeline (real stack always included). */
916
- emitInvokeError(failureKind: string, error: unknown, clientMessage: string, labels?: Record<string, string | number | boolean>): void;
978
+ emitInvokeError(failureKind: string, error: unknown, clientMessage: string, meta?: {
979
+ labels?: Record<string, string | number | boolean>;
980
+ requestId?: string;
981
+ traceId?: string;
982
+ spanId?: string;
983
+ }): void;
917
984
  private formatLine;
985
+ private buildEnrichContext;
918
986
  private formatTextLine;
919
987
  private appendFile;
920
988
  }
@@ -996,6 +1064,8 @@ export declare class Cli {
996
1064
  request: Request;
997
1065
  clientIp: string;
998
1066
  requestId: string;
1067
+ traceId?: string;
1068
+ spanId?: string;
999
1069
  };
1000
1070
  mcp?: {
1001
1071
  rpcMethod: string;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "argsbarg",
3
- "version": "6.1.7",
3
+ "version": "6.1.9",
4
4
  "main": "./src/index.ts",
5
5
  "module": "./src/index.ts",
6
6
  "dependencies": {
7
+ "@cfworker/json-schema": "^4",
7
8
  "ts-json-schema-generator": "^2.3.0"
8
9
  },
9
10
  "devDependencies": {
10
- "@biomejs/biome": "^2.5.0",
11
+ "@biomejs/biome": "^2.5.5",
11
12
  "@types/bun": "^1.3.12",
12
13
  "dts-bundle-generator": "^9.5.1",
13
14
  "typescript": "^5.9.3"
@@ -18,7 +18,7 @@ const HTTP_SERVE_OPTIONS: CliOption[] = [
18
18
  { name: "obscure-errors", description: "Hide unexpected errors from clients.", kind: CliOptionKind.Presence },
19
19
  {
20
20
  name: "log-format",
21
- description: "Log format: json (ECS) or text.",
21
+ description: "Log format: json (ECS Logging) or text.",
22
22
  kind: CliOptionKind.Enum,
23
23
  choices: ["json", "text"],
24
24
  },
@@ -13,7 +13,7 @@ const MCP_SERVE_OPTIONS: CliOption[] = [
13
13
  { name: "obscure-errors", description: "Hide unexpected errors from clients.", kind: CliOptionKind.Presence },
14
14
  {
15
15
  name: "log-format",
16
- description: "Log format: json (ECS) or text.",
16
+ description: "Log format: json (ECS Logging) or text.",
17
17
  kind: CliOptionKind.Enum,
18
18
  choices: ["json", "text"],
19
19
  },
@@ -3,7 +3,7 @@ Tests for config/validate module behavior.
3
3
  */
4
4
 
5
5
  import { describe, expect, test } from "bun:test";
6
- import { parseConfigSetValue, validateConfigDocument } from "./validate.ts";
6
+ import { parseConfigSetValue, resolveSchemaDraft, validateConfigDocument } from "./validate.ts";
7
7
 
8
8
  const rootSchema = {
9
9
  type: "object",
@@ -98,4 +98,48 @@ describe("config/validate", () => {
98
98
  expect(() => parseConfigSetValue("a,b", schema, rootSchema, false)).toThrow(/--json/);
99
99
  expect(parseConfigSetValue('[{"ttl":1}]', schema, rootSchema, false)).toEqual([{ ttl: 1 }]);
100
100
  });
101
+
102
+ test("resolveSchemaDraft maps $schema URIs", () => {
103
+ expect(resolveSchemaDraft({ $schema: "http://json-schema.org/draft-07/schema#" })).toBe("7");
104
+ expect(resolveSchemaDraft({ $schema: "https://json-schema.org/draft/2020-12/schema" })).toBe("2020-12");
105
+ expect(resolveSchemaDraft({ $schema: "https://json-schema.org/draft/2019-09/schema" })).toBe("2019-09");
106
+ expect(resolveSchemaDraft({})).toBe("7");
107
+ });
108
+
109
+ test("validates draft 2020-12 schemas when $schema is set", () => {
110
+ const schema = {
111
+ $schema: "https://json-schema.org/draft/2020-12/schema",
112
+ type: "object",
113
+ additionalProperties: false,
114
+ required: ["name"],
115
+ properties: {
116
+ name: { type: "string", minLength: 1 },
117
+ },
118
+ };
119
+ expect(validateConfigDocument({ name: "ok" }, schema).valid).toBe(true);
120
+ expect(validateConfigDocument({ name: "" }, schema).valid).toBe(false);
121
+ expect(validateConfigDocument({}, schema).valid).toBe(false);
122
+ });
123
+
124
+ test("validates draft 2020-12 $defs refs", () => {
125
+ const schema = {
126
+ $schema: "https://json-schema.org/draft/2020-12/schema",
127
+ type: "object",
128
+ additionalProperties: false,
129
+ required: ["item"],
130
+ properties: {
131
+ item: { $ref: "#/$defs/Item" },
132
+ },
133
+ $defs: {
134
+ Item: {
135
+ type: "object",
136
+ additionalProperties: false,
137
+ required: ["id"],
138
+ properties: { id: { type: "string" } },
139
+ },
140
+ },
141
+ };
142
+ expect(validateConfigDocument({ item: { id: "a" } }, schema).valid).toBe(true);
143
+ expect(validateConfigDocument({ item: { id: 1 } }, schema).valid).toBe(false);
144
+ });
101
145
  });