@dudko.dev/baton-format 0.1.2 → 0.1.3

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.
@@ -1,4 +1,5 @@
1
1
  export * from "./types.js";
2
2
  export { FormatError, type FormatErrorCode } from "./errors.js";
3
- export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, } from "./parse.js";
4
- export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, } from "./serialize.js";
3
+ export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, parseExamplesFile, parseMockFile, } from "./parse.js";
4
+ export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, serializeExamplesFile, serializeMockFile, } from "./serialize.js";
5
+ export { parseVaultRef, formatVaultRef, type VaultRef } from "./vault.js";
package/dist/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./types.js";
2
2
  export { FormatError } from "./errors.js";
3
- export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, } from "./parse.js";
4
- export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, } from "./serialize.js";
3
+ export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, parseExamplesFile, parseMockFile, } from "./parse.js";
4
+ export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, serializeExamplesFile, serializeMockFile, } from "./serialize.js";
5
+ export { parseVaultRef, formatVaultRef } from "./vault.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest } from "./types.js";
1
+ import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest, ExamplesFile, MockFile } from "./types.js";
2
2
  /** Parse and validate a `*.req.yaml` file into its normalized form. */
3
3
  export declare function parseRequestFile(text: string): RequestFile;
4
4
  /** Parse and validate a `collection.yaml` / `folder.yaml` file. */
@@ -9,3 +9,7 @@ export declare function parseEnvironmentFile(text: string): EnvironmentFile;
9
9
  export declare function parseWorkspaceManifest(text: string): WorkspaceManifest;
10
10
  /** Parse and validate a `schedules.yaml` file. */
11
11
  export declare function parseSchedulesFile(text: string): SchedulesFile;
12
+ /** Parse and validate a `<slug>.examples.yaml` file. */
13
+ export declare function parseExamplesFile(text: string): ExamplesFile;
14
+ /** Parse and validate a `mocks/<name>.yaml` file. */
15
+ export declare function parseMockFile(text: string): MockFile;
package/dist/src/parse.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { parse as parseYaml } from "yaml";
2
2
  import { FormatError } from "./errors.js";
3
+ import { parseVaultRef } from "./vault.js";
3
4
  import { DEFAULT_SETTINGS, FORMAT_VERSION, METHODS, } from "./types.js";
4
5
  const ULID_RE = /^[0-9A-HJKMNP-TV-Z]{26}$/;
5
6
  // MARK: - Primitive readers
@@ -52,6 +53,17 @@ function reqString(obj, key, path) {
52
53
  }
53
54
  return value;
54
55
  }
56
+ /** A required string that may be empty. */
57
+ function reqText(obj, key, path) {
58
+ if (!(key in obj)) {
59
+ throw new FormatError("missing-field", join(path, key), "required field is missing");
60
+ }
61
+ const value = obj[key];
62
+ if (typeof value !== "string") {
63
+ throw new FormatError("invalid-field", join(path, key), "must be a string");
64
+ }
65
+ return value;
66
+ }
55
67
  function optString(obj, key, path) {
56
68
  const value = obj[key];
57
69
  if (value === undefined)
@@ -70,6 +82,16 @@ function optBool(obj, key, path, dflt) {
70
82
  }
71
83
  return value;
72
84
  }
85
+ function reqInt(obj, key, path) {
86
+ const value = obj[key];
87
+ if (value === undefined) {
88
+ throw new FormatError("missing-field", join(path, key), "is required");
89
+ }
90
+ if (typeof value !== "number" || !Number.isInteger(value)) {
91
+ throw new FormatError("invalid-field", join(path, key), "must be an integer");
92
+ }
93
+ return value;
94
+ }
73
95
  function optInt(obj, key, path, dflt) {
74
96
  const value = obj[key];
75
97
  if (value === undefined)
@@ -118,7 +140,9 @@ function parseKvRows(obj, key, path) {
118
140
  checkKeys(row, ["name", "value", "enabled"], itemPath);
119
141
  return {
120
142
  name: reqString(row, "name", itemPath),
121
- value: reqString(row, "value", itemPath),
143
+ // Empty is a value here: `curl -H 'Name;'` sends an empty header, and
144
+ // a documented parameter may have no sample yet.
145
+ value: reqText(row, "value", itemPath),
122
146
  enabled: optBool(row, "enabled", itemPath, true),
123
147
  };
124
148
  });
@@ -400,11 +424,13 @@ export function parseRequestFile(text) {
400
424
  /** Parse and validate a `collection.yaml` / `folder.yaml` file. */
401
425
  export function parseCollectionFile(text) {
402
426
  const obj = root(text);
403
- checkKeys(obj, ["format", "id", "name", "auth", "variables", "order"], "");
427
+ checkKeys(obj, ["format", "id", "name", "spec", "auth", "variables", "order"], "");
428
+ const spec = optString(obj, "spec", "");
404
429
  return {
405
430
  format: checkFormat(obj, ""),
406
431
  id: ulid(obj, "id", ""),
407
432
  name: reqString(obj, "name", ""),
433
+ ...(spec !== undefined ? { spec } : {}),
408
434
  auth: parseAuth(obj, ""),
409
435
  variables: parseVariables(obj, "variables", ""),
410
436
  order: parseStringList(obj, "order", ""),
@@ -413,14 +439,45 @@ export function parseCollectionFile(text) {
413
439
  /** Parse and validate a `*.env.yaml` file. */
414
440
  export function parseEnvironmentFile(text) {
415
441
  const obj = root(text);
416
- checkKeys(obj, ["format", "name", "variables", "secrets"], "");
442
+ checkKeys(obj, ["format", "name", "production", "variables", "secrets"], "");
443
+ const { secrets, vault } = parseSecrets(obj, "");
444
+ const production = optBool(obj, "production", "", false);
417
445
  return {
418
446
  format: checkFormat(obj, ""),
419
447
  name: reqString(obj, "name", ""),
420
448
  variables: parseVariables(obj, "variables", ""),
421
- secrets: parseStringList(obj, "secrets", ""),
449
+ secrets,
450
+ ...(Object.keys(vault).length > 0 ? { vault } : {}),
451
+ ...(production ? { production: true } : {}),
422
452
  };
423
453
  }
454
+ /**
455
+ * `secrets:` entries: a bare name (device store), or `{name, vault}` for a
456
+ * value read from Vault. Order is the list's; the Vault map is by name.
457
+ */
458
+ function parseSecrets(obj, path) {
459
+ const secrets = [];
460
+ const vault = {};
461
+ optArray(obj, "secrets", path).forEach((item, i) => {
462
+ const itemPath = `${join(path, "secrets")}[${i}]`;
463
+ if (typeof item === "string") {
464
+ if (item === "")
465
+ throw new FormatError("invalid-field", itemPath, "must be a non-empty string");
466
+ secrets.push(item);
467
+ return;
468
+ }
469
+ const entry = itemRecord(item, itemPath);
470
+ checkKeys(entry, ["name", "vault"], itemPath);
471
+ const name = reqString(entry, "name", itemPath);
472
+ const ref = reqString(entry, "vault", itemPath);
473
+ // Validated here so a bad reference is a format error at its field, not
474
+ // a send-time failure in whichever engine reads it first.
475
+ parseVaultRef(ref, `${itemPath}.vault`);
476
+ secrets.push(name);
477
+ vault[name] = ref;
478
+ });
479
+ return { secrets, vault };
480
+ }
424
481
  /** Parse and validate the `baton.yaml` workspace manifest. */
425
482
  export function parseWorkspaceManifest(text) {
426
483
  const obj = root(text);
@@ -428,7 +485,7 @@ export function parseWorkspaceManifest(text) {
428
485
  const settingsObj = optRecord(obj, "settings", "");
429
486
  let settings = { ...DEFAULT_SETTINGS };
430
487
  if (settingsObj !== undefined) {
431
- checkKeys(settingsObj, ["followRedirects", "timeoutMs", "validateTls", "tls", "proxy"], "settings");
488
+ checkKeys(settingsObj, ["followRedirects", "timeoutMs", "validateTls", "tls", "proxy", "vault"], "settings");
432
489
  let tls = { clientCertificates: [] };
433
490
  const tlsObj = optRecord(settingsObj, "tls", "settings");
434
491
  if (tlsObj !== undefined) {
@@ -463,12 +520,24 @@ export function parseWorkspaceManifest(text) {
463
520
  ...(passwordSecret !== undefined ? { passwordSecret } : {}),
464
521
  };
465
522
  }
523
+ let vault;
524
+ const vaultObj = optRecord(settingsObj, "vault", "settings");
525
+ if (vaultObj !== undefined) {
526
+ checkKeys(vaultObj, ["address", "namespace"], "settings.vault");
527
+ const address = reqString(vaultObj, "address", "settings.vault");
528
+ if (!address.startsWith("http://") && !address.startsWith("https://")) {
529
+ throw new FormatError("invalid-field", "settings.vault.address", "must start with http:// or https://");
530
+ }
531
+ const namespace = optString(vaultObj, "namespace", "settings.vault");
532
+ vault = { address, ...(namespace !== undefined ? { namespace } : {}) };
533
+ }
466
534
  settings = {
467
535
  followRedirects: optBool(settingsObj, "followRedirects", "settings", DEFAULT_SETTINGS.followRedirects),
468
536
  timeoutMs: optInt(settingsObj, "timeoutMs", "settings", DEFAULT_SETTINGS.timeoutMs),
469
537
  validateTls: optBool(settingsObj, "validateTls", "settings", DEFAULT_SETTINGS.validateTls),
470
538
  ...(tls.caFile !== undefined || tls.clientCertificates.length > 0 ? { tls } : {}),
471
539
  ...(proxy !== undefined ? { proxy } : {}),
540
+ ...(vault !== undefined ? { vault } : {}),
472
541
  };
473
542
  }
474
543
  const description = optString(obj, "description", "");
@@ -528,4 +597,54 @@ export function parseSchedulesFile(text) {
528
597
  });
529
598
  return { format: checkFormat(obj, ""), schedules };
530
599
  }
600
+ /** Parse and validate a `<slug>.examples.yaml` file. */
601
+ export function parseExamplesFile(text) {
602
+ const obj = root(text);
603
+ checkKeys(obj, ["format", "examples"], "");
604
+ const seen = new Set();
605
+ const examples = optArray(obj, "examples", "").map((item, i) => {
606
+ const itemPath = `examples[${i}]`;
607
+ const entry = itemRecord(item, itemPath);
608
+ checkKeys(entry, ["name", "status", "headers", "body"], itemPath);
609
+ const name = reqString(entry, "name", itemPath);
610
+ if (seen.has(name)) {
611
+ throw new FormatError("invalid-field", `${itemPath}.name`, `duplicate example name "${name}"`);
612
+ }
613
+ seen.add(name);
614
+ const status = reqInt(entry, "status", itemPath);
615
+ if (status < 100 || status > 599) {
616
+ throw new FormatError("invalid-field", `${itemPath}.status`, "must be an HTTP status (100–599)");
617
+ }
618
+ return {
619
+ name,
620
+ status,
621
+ headers: parseKvRows(entry, "headers", itemPath),
622
+ body: optString(entry, "body", itemPath) ?? "",
623
+ };
624
+ });
625
+ return { format: checkFormat(obj, ""), examples };
626
+ }
627
+ /** Parse and validate a `mocks/<name>.yaml` file. */
628
+ export function parseMockFile(text) {
629
+ const obj = root(text);
630
+ checkKeys(obj, ["format", "name", "port", "collections", "example"], "");
631
+ const port = reqInt(obj, "port", "");
632
+ if (port < 1 || port > 65535) {
633
+ throw new FormatError("invalid-field", "port", "must be 1–65535");
634
+ }
635
+ const collections = parseStringList(obj, "collections", "");
636
+ collections.forEach((path, i) => {
637
+ if (!path.startsWith("collections/") || path.includes("..")) {
638
+ throw new FormatError("invalid-field", `collections[${i}]`, "must be a workspace-relative collection path (collections/<name>)");
639
+ }
640
+ });
641
+ const example = optString(obj, "example", "");
642
+ return {
643
+ format: checkFormat(obj, ""),
644
+ name: reqString(obj, "name", ""),
645
+ port,
646
+ collections,
647
+ ...(example === undefined ? {} : { example }),
648
+ };
649
+ }
531
650
  //# sourceMappingURL=parse.js.map
@@ -1,4 +1,4 @@
1
- import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest } from "./types.js";
1
+ import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest, ExamplesFile, MockFile } from "./types.js";
2
2
  /** Serialize a normalized request to canonical `*.req.yaml` bytes. */
3
3
  export declare function serializeRequestFile(req: RequestFile): string;
4
4
  /** Serialize a normalized collection/folder to canonical bytes. */
@@ -9,3 +9,7 @@ export declare function serializeEnvironmentFile(env: EnvironmentFile): string;
9
9
  export declare function serializeWorkspaceManifest(ws: WorkspaceManifest): string;
10
10
  /** Serialize normalized schedules to canonical bytes. */
11
11
  export declare function serializeSchedulesFile(file: SchedulesFile): string;
12
+ /** Serialize a request's examples to canonical bytes. */
13
+ export declare function serializeExamplesFile(file: ExamplesFile): string;
14
+ /** Serialize a mock definition to canonical bytes. */
15
+ export declare function serializeMockFile(mock: MockFile): string;
@@ -90,7 +90,10 @@ class Out {
90
90
  * or nothing but newlines, which reads back as the empty string.
91
91
  */
92
92
  block(indent, key, text) {
93
- if (text.includes("\r") || text.replace(/\n+$/, "") === "") {
93
+ // A carriage return or any other control character (a response body is
94
+ // whatever the API sent — ANSI colors, NUL bytes) cannot live in a block
95
+ // scalar; quoted, it round-trips byte for byte.
96
+ if (/[\x00-\x08\x0b-\x1f\x7f]/.test(text) || text.replace(/\n+$/, "") === "") {
94
97
  this.line(indent, `${key}: ${JSON.stringify(text)}`);
95
98
  return;
96
99
  }
@@ -279,6 +282,8 @@ export function serializeCollectionFile(col) {
279
282
  out.kv(0, "format", col.format);
280
283
  out.kv(0, "id", col.id);
281
284
  out.kv(0, "name", col.name);
285
+ if (col.spec !== undefined)
286
+ out.kv(0, "spec", col.spec);
282
287
  emitAuth(out, 0, col.auth);
283
288
  emitVariables(out, 0, "variables", col.variables);
284
289
  if (col.order.length > 0)
@@ -290,9 +295,22 @@ export function serializeEnvironmentFile(env) {
290
295
  const out = new Out();
291
296
  out.kv(0, "format", env.format);
292
297
  out.kv(0, "name", env.name);
298
+ if (env.production === true)
299
+ out.kv(0, "production", true);
293
300
  emitVariables(out, 0, "variables", env.variables);
294
- if (env.secrets.length > 0)
295
- out.list(0, "secrets", env.secrets);
301
+ if (env.secrets.length > 0) {
302
+ out.line(0, "secrets:");
303
+ for (const name of env.secrets) {
304
+ const ref = env.vault?.[name];
305
+ if (ref === undefined) {
306
+ out.line(2, `- ${scalar(name)}`);
307
+ }
308
+ else {
309
+ out.line(2, `- name: ${scalar(name)}`);
310
+ out.kv(4, "vault", ref);
311
+ }
312
+ }
313
+ }
296
314
  return out.toString();
297
315
  }
298
316
  /** Serialize a normalized workspace manifest to canonical bytes. */
@@ -314,7 +332,8 @@ export function serializeWorkspaceManifest(ws) {
314
332
  const tls = s.tls ?? { clientCertificates: [] };
315
333
  const tlsEmpty = tls.caFile === undefined && tls.clientCertificates.length === 0;
316
334
  const proxy = s.proxy;
317
- if (nonDefault.length > 0 || !tlsEmpty || proxy !== undefined) {
335
+ const vault = s.vault;
336
+ if (nonDefault.length > 0 || !tlsEmpty || proxy !== undefined || vault !== undefined) {
318
337
  out.line(0, "settings:");
319
338
  for (const [key, value] of nonDefault)
320
339
  out.kv(2, key, value);
@@ -349,6 +368,12 @@ export function serializeWorkspaceManifest(ws) {
349
368
  out.kv(4, "passwordSecret", proxy.passwordSecret);
350
369
  }
351
370
  }
371
+ if (vault !== undefined) {
372
+ out.line(2, "vault:");
373
+ out.kv(4, "address", vault.address);
374
+ if (vault.namespace !== undefined)
375
+ out.kv(4, "namespace", vault.namespace);
376
+ }
352
377
  }
353
378
  return out.toString();
354
379
  }
@@ -380,4 +405,32 @@ export function serializeSchedulesFile(file) {
380
405
  }
381
406
  return out.toString();
382
407
  }
408
+ /** Serialize a request's examples to canonical bytes. */
409
+ export function serializeExamplesFile(file) {
410
+ const out = new Out();
411
+ out.kv(0, "format", file.format);
412
+ if (file.examples.length > 0) {
413
+ out.line(0, "examples:");
414
+ for (const example of file.examples) {
415
+ out.line(2, `- name: ${scalar(example.name)}`);
416
+ out.kv(4, "status", example.status);
417
+ emitKvRows(out, 4, "headers", example.headers);
418
+ if (example.body.length > 0)
419
+ out.block(4, "body", example.body);
420
+ }
421
+ }
422
+ return out.toString();
423
+ }
424
+ /** Serialize a mock definition to canonical bytes. */
425
+ export function serializeMockFile(mock) {
426
+ const out = new Out();
427
+ out.kv(0, "format", mock.format);
428
+ out.kv(0, "name", mock.name);
429
+ out.kv(0, "port", mock.port);
430
+ if (mock.collections.length > 0)
431
+ out.list(0, "collections", mock.collections);
432
+ if (mock.example !== undefined)
433
+ out.kv(0, "example", mock.example);
434
+ return out.toString();
435
+ }
383
436
  //# sourceMappingURL=serialize.js.map
@@ -129,6 +129,12 @@ export interface CollectionFile {
129
129
  format: number;
130
130
  id: string;
131
131
  name: string;
132
+ /**
133
+ * An OpenAPI document this collection follows: a workspace-relative path
134
+ * or an http(s) URL. The app lists the drift between the two; nothing here
135
+ * writes to it. Absent when the collection is hand-made.
136
+ */
137
+ spec?: string;
132
138
  auth: AuthConfig;
133
139
  variables: Variable[];
134
140
  order: string[];
@@ -140,6 +146,28 @@ export interface EnvironmentFile {
140
146
  variables: Variable[];
141
147
  /** Secret names only — values never live in the workspace. */
142
148
  secrets: string[];
149
+ /**
150
+ * Marks an environment whose targets are real: a send into it from an
151
+ * agent is confirmed in the app first. Absent means false.
152
+ */
153
+ production?: boolean;
154
+ /**
155
+ * Secrets read from Vault rather than the device store, by name:
156
+ * `apiToken` → `kv/billing/prod#password`. A location, not a value. Every
157
+ * key also appears in `secrets`, which keeps the order. Absent when empty.
158
+ */
159
+ vault?: Record<string, string>;
160
+ }
161
+ /**
162
+ * Where the workspace's Vault is — `settings.vault`. Infrastructure, so it is
163
+ * committed like the proxy; the token is a secret of its own
164
+ * (`BATON_VAULT_TOKEN` on the worker, the OS store in the app).
165
+ */
166
+ export interface VaultSettings {
167
+ /** `https://vault.example:8200` — scheme and host, no trailing path. */
168
+ address: string;
169
+ /** Vault Enterprise / HCP namespace, sent as `X-Vault-Namespace`. */
170
+ namespace?: string;
143
171
  }
144
172
  export interface ClientCertificateConfig {
145
173
  /** `api.corp.example` exact, `*.corp.example` for subdomains, `*` for all. */
@@ -171,6 +199,8 @@ export interface WorkspaceSettings {
171
199
  tls?: TlsSettings;
172
200
  /** Outbound proxy; absent means direct (or the platform environment). */
173
201
  proxy?: ProxyConfig;
202
+ /** The workspace's Vault; absent means no secret may name a Vault path. */
203
+ vault?: VaultSettings;
174
204
  }
175
205
  export declare const DEFAULT_SETTINGS: WorkspaceSettings;
176
206
  /** `baton.yaml` — the workspace manifest. */
@@ -203,3 +233,28 @@ export interface SchedulesFile {
203
233
  format: number;
204
234
  schedules: Schedule[];
205
235
  }
236
+ /**
237
+ * One saved response for a request: what a real call answered, or what the
238
+ * API is meant to answer. Lives beside the request in `<slug>.examples.yaml`.
239
+ */
240
+ export interface ResponseExample {
241
+ name: string;
242
+ status: number;
243
+ headers: KeyValueRow[];
244
+ body: string;
245
+ }
246
+ /** `<slug>.examples.yaml`: the examples a request carries, in order. */
247
+ export interface ExamplesFile {
248
+ format: number;
249
+ examples: ResponseExample[];
250
+ }
251
+ /** `mocks/<name>.yaml`: a mock server stood up from examples. */
252
+ export interface MockFile {
253
+ format: number;
254
+ name: string;
255
+ port: number;
256
+ /** Workspace-relative collection paths whose requests the mock answers. */
257
+ collections: string[];
258
+ /** The example to answer with, by name; the first one when absent. */
259
+ example?: string;
260
+ }
@@ -0,0 +1,15 @@
1
+ /** A reference into KV v2: `<mount>/<path>#<key>` — a location, never a value. */
2
+ export interface VaultRef {
3
+ mount: string;
4
+ path: string;
5
+ key: string;
6
+ }
7
+ /**
8
+ * Parses `<mount>/<path>#<key>`; throws a FormatError at `fieldPath` on
9
+ * anything else. Mount and path parts may not be empty, contain whitespace,
10
+ * or walk upward (`..`), so a reference cannot escape the mount it names.
11
+ * Mirrors `VaultRef.parse` in baton_core (invariant 6).
12
+ */
13
+ export declare function parseVaultRef(text: string, fieldPath: string): VaultRef;
14
+ /** The canonical text form — what the writer emits. */
15
+ export declare function formatVaultRef(ref: VaultRef): string;
@@ -0,0 +1,32 @@
1
+ import { FormatError } from "./errors.js";
2
+ /**
3
+ * Parses `<mount>/<path>#<key>`; throws a FormatError at `fieldPath` on
4
+ * anything else. Mount and path parts may not be empty, contain whitespace,
5
+ * or walk upward (`..`), so a reference cannot escape the mount it names.
6
+ * Mirrors `VaultRef.parse` in baton_core (invariant 6).
7
+ */
8
+ export function parseVaultRef(text, fieldPath) {
9
+ const bad = (reason) => new FormatError("invalid-field", fieldPath, reason);
10
+ const hash = text.indexOf("#");
11
+ if (hash < 0 || text.indexOf("#", hash + 1) >= 0)
12
+ throw bad("must be <mount>/<path>#<key>");
13
+ const location = text.slice(0, hash);
14
+ const key = text.slice(hash + 1);
15
+ if (key === "" || /\s/.test(key))
16
+ throw bad("key after # must be a non-empty word");
17
+ const slash = location.indexOf("/");
18
+ if (slash <= 0 || slash === location.length - 1)
19
+ throw bad("must be <mount>/<path>#<key>");
20
+ const segments = location.split("/");
21
+ for (const segment of segments) {
22
+ if (segment === "" || segment === "." || segment === ".." || /\s/.test(segment)) {
23
+ throw bad("mount and path segments must be non-empty words");
24
+ }
25
+ }
26
+ return { mount: segments[0], path: segments.slice(1).join("/"), key };
27
+ }
28
+ /** The canonical text form — what the writer emits. */
29
+ export function formatVaultRef(ref) {
30
+ return `${ref.mount}/${ref.path}#${ref.key}`;
31
+ }
32
+ //# sourceMappingURL=vault.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudko.dev/baton-format",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Baton workspace file format: parsing, validation, and deterministic serialization.",
5
5
  "keywords": ["baton", "api-client", "yaml", "workspace", "format"],
6
6
  "homepage": "https://baton.dudko.dev",