@orkestrel/capture 0.0.9 → 0.0.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.
@@ -1,4 +1,4 @@
1
- import { INTRINSICS, arrayOf, holds, isError, isFiniteNumber, isFunction, isObject, isRecord, isString, preview } from "@orkestrel/contract";
1
+ import { INTRINSICS, arrayOf, holds, isError, isFiniteNumber, isFunction, isObject, isRecord, isSafeInteger, isString, preview } from "@orkestrel/contract";
2
2
  // src/core/constants.ts
3
3
  /**
4
4
  * Lists the condition axes a capture failure carries, in the order the executable reports them.
@@ -7,7 +7,9 @@ import { INTRINSICS, arrayOf, holds, isError, isFiniteNumber, isFunction, isObje
7
7
  * `USAGE` is a refused command line and exits 64; every other condition exits 1. `SELECTION`
8
8
  * names a selector, variant, case, state, or portfolio the host does not declare. `HOST` names a
9
9
  * wrapper, configuration, or declaration fault. `STAGE` names a runner stage that did not
10
- * complete. `EVIDENCE` names a record, report, registry, or manifest that fails its protocol.
10
+ * complete. `EVIDENCE` names a record, report, journal, or manifest that fails its protocol, and a
11
+ * document of another version. `REGISTRY` names an accepted registry that is absent, fails
12
+ * authentication, or lags the declarations. `LOOKUP` names a state lookup that is absent or stale.
11
13
  * `CONTAINMENT` names a path that leaves the authorized roots.
12
14
  *
13
15
  * @example
@@ -21,6 +23,8 @@ var CAPTURE_ERROR_CODES = Object.freeze([
21
23
  "HOST",
22
24
  "STAGE",
23
25
  "EVIDENCE",
26
+ "REGISTRY",
27
+ "LOOKUP",
24
28
  "CONTAINMENT"
25
29
  ]);
26
30
  /**
@@ -70,10 +74,10 @@ var CAPTURE_REQUEST_PREFIX = "journey-selection";
70
74
  *
71
75
  * @example
72
76
  * ```ts
73
- * CAPTURE_VERSION // 1
77
+ * CAPTURE_VERSION // 2
74
78
  * ```
75
79
  */
76
- var CAPTURE_VERSION = 1;
80
+ var CAPTURE_VERSION = 2;
77
81
  /**
78
82
  * Holds the eight bytes every PNG file opens with.
79
83
  *
@@ -327,7 +331,7 @@ function isCaptureSources(value) {
327
331
  * ```
328
332
  */
329
333
  function isCaptureIdentity(value) {
330
- return holds(() => isRecord(value) && isCaptureSegment(value.id) && isCaptureSegment(value.stage) && typeof value.pid === "number" && Number.isSafeInteger(value.pid) && value.pid > 0 && isCapturePath(value.config));
334
+ return holds(() => isRecord(value) && isCaptureSegment(value.id) && isCaptureSegment(value.stage) && typeof value.pid === "number" && isSafeInteger(value.pid) && value.pid > 0 && isCapturePath(value.config));
331
335
  }
332
336
  /**
333
337
  * Checks whether a request has the supported version and complete execution identity.
@@ -338,11 +342,11 @@ function isCaptureIdentity(value) {
338
342
  * @example
339
343
  * ```ts
340
344
  * isCaptureRequest(JSON.parse(text)) // true for a well-formed runner request
341
- * isCaptureRequest({ version: 2 }) // false
345
+ * isCaptureRequest({ version: 1 }) // false
342
346
  * ```
343
347
  */
344
348
  function isCaptureRequest(value) {
345
- return holds(() => isRecord(value) && isCaptureIdentity(value) && value.version === 1 && (value.command === "journey" || value.command === "capture") && (value.mode === void 0 || typeof value.mode === "string" && value.mode.trim() !== "") && isCaptureSelector(value.selector) && arrayOf(isCaptureSegment)(value.variants) && value.variants.length > 0 && arrayOf(isString)(value.args) && (value.case === void 0 || typeof value.case === "string" && value.case.trim() !== "") && (value.state === void 0 || value.command === "capture" && isCaptureSegment(value.state)));
349
+ return holds(() => isRecord(value) && isCaptureIdentity(value) && value.version === 2 && (value.command === "journey" || value.command === "capture") && (value.mode === void 0 || typeof value.mode === "string" && value.mode.trim() !== "") && isCaptureSelector(value.selector) && arrayOf(isCaptureSegment)(value.variants) && value.variants.length > 0 && arrayOf(isString)(value.args) && (value.case === void 0 || typeof value.case === "string" && value.case.trim() !== "") && (value.state === void 0 || value.command === "capture" && isCaptureSegment(value.state)));
346
350
  }
347
351
  /**
348
352
  * Checks whether a collected declaration preserves its full owner and state population.
@@ -422,7 +426,7 @@ function isCaptureArtifact(value) {
422
426
  * ```
423
427
  */
424
428
  function isCaptureRun(value) {
425
- return holds(() => isRecord(value) && value.version === 1 && isCaptureSegment(value.variant) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && typeof value.complete === "boolean" && typeof value.reference === "boolean" && arrayOf(isCaptureDeclaration)(value.declarations) && arrayOf(isCaptureDestination)(value.registry) && arrayOf(isString)(value.passed) && arrayOf(isCaptureSegment)(value.observed) && arrayOf(isCaptureEntry)(value.entries) && (value.artifact === void 0 || isCaptureArtifact(value.artifact)) && (value.identity === void 0 && value.request === void 0 || isCaptureIdentity(value.identity) && isCaptureRequest(value.request)));
429
+ return holds(() => isRecord(value) && value.version === 2 && isCaptureSegment(value.variant) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && typeof value.complete === "boolean" && typeof value.reference === "boolean" && arrayOf(isCaptureDeclaration)(value.declarations) && arrayOf(isCaptureDestination)(value.registry) && arrayOf(isString)(value.passed) && arrayOf(isCaptureSegment)(value.observed) && arrayOf(isCaptureEntry)(value.entries) && (value.artifact === void 0 || isCaptureArtifact(value.artifact)) && (value.identity === void 0 && value.request === void 0 || isCaptureIdentity(value.identity) && isCaptureRequest(value.request)));
426
430
  }
427
431
  /**
428
432
  * Checks whether a shared-source digest retains both patterns and expanded file hashes.
@@ -452,7 +456,7 @@ function isCaptureDigest(value) {
452
456
  * ```
453
457
  */
454
458
  function isCaptureReceipt(value) {
455
- return holds(() => isRecord(value) && value.version === 1 && isCaptureSegment(value.variant) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && isRecord(value.report) && isCapturePath(value.report.file) && isCaptureHash(value.report.digest) && isCaptureHashes(value.inputs) && arrayOf(isCaptureDeclaration)(value.declarations) && arrayOf(isCaptureDestination)(value.registry) && typeof value.complete === "boolean");
459
+ return holds(() => isRecord(value) && value.version === 2 && isCaptureSegment(value.variant) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && isRecord(value.report) && isCapturePath(value.report.file) && isCaptureHash(value.report.digest) && isCaptureHashes(value.inputs) && arrayOf(isCaptureDeclaration)(value.declarations) && arrayOf(isCaptureDestination)(value.registry) && typeof value.complete === "boolean");
456
460
  }
457
461
  /**
458
462
  * Checks whether a registry document retains its receipts and required output pairs.
@@ -467,7 +471,7 @@ function isCaptureReceipt(value) {
467
471
  * ```
468
472
  */
469
473
  function isCaptureRegistry(value) {
470
- return holds(() => isRecord(value) && value.version === 1 && arrayOf(isCaptureReceipt)(value.receipts) && arrayOf(isCaptureDestination)(value.entries) && isCaptureHash(value.digest));
474
+ return holds(() => isRecord(value) && value.version === 2 && arrayOf(isCaptureReceipt)(value.receipts) && arrayOf(isCaptureDestination)(value.entries) && isCaptureHash(value.digest));
471
475
  }
472
476
  /**
473
477
  * Checks whether a lookup binds a passing case to its full run record and input hashes.
@@ -493,12 +497,12 @@ function isCaptureLookup(value) {
493
497
  *
494
498
  * @example
495
499
  * ```ts
496
- * isCaptureLookupJournal({ version: 1, inputs: {}, lookups: [] }) // true
497
- * isCaptureLookupJournal({ version: 2, inputs: {}, lookups: [] }) // false
500
+ * isCaptureLookupJournal({ version: 2, populations: {}, lookups: [] }) // true
501
+ * isCaptureLookupJournal({ version: 1, populations: {}, lookups: [] }) // false
498
502
  * ```
499
503
  */
500
504
  function isCaptureLookupJournal(value) {
501
- return holds(() => isRecord(value) && (value.collections === void 0 || arrayOf(isCaptureCollection)(value.collections)) && value.version === 1 && (value.manifest === void 0 || isCaptureHash(value.manifest)) && isRecord(value.inputs) && Object.entries(value.inputs).every(([digest, inputs]) => isCaptureHash(digest) && isCaptureHashes(inputs)) && arrayOf((entry) => isRecord(entry) && isCaptureHash(entry.inputs) && isCaptureLookup({
505
+ return holds(() => isRecord(value) && (value.collections === void 0 || arrayOf(isCaptureCollection)(value.collections)) && value.version === 2 && (value.manifest === void 0 || isCaptureHash(value.manifest)) && isRecord(value.populations) && Object.entries(value.populations).every(([digest, inputs]) => isCaptureHash(digest) && isCaptureHashes(inputs)) && arrayOf((entry) => isRecord(entry) && isCaptureHash(entry.inputs) && isCaptureLookup({
502
506
  ...entry,
503
507
  inputs: {}
504
508
  }))(value.lookups));
@@ -516,22 +520,22 @@ function isCaptureLookupJournal(value) {
516
520
  * ```
517
521
  */
518
522
  function isCaptureStamp(value) {
519
- return holds(() => isRecord(value) && isCaptureEntry(value) && isCaptureIdentity(value.identity) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && typeof value.commit === "string" && /^[a-f0-9]{40,64}$/u.test(value.commit) && arrayOf(isCapturePath)(value.dirty) && isCaptureHashes(value.own) && isCaptureDigest(value.shared) && isCaptureHashes(value.tests) && isCaptureHash(value.registry) && isRecord(value.image) && isCaptureHash(value.image.digest) && isFiniteNumber(value.image.size) && Number.isSafeInteger(value.image.size) && value.image.size > 0 && isFiniteNumber(value.image.modified) && value.image.modified >= 0);
523
+ return holds(() => isRecord(value) && isCaptureEntry(value) && isCaptureIdentity(value.identity) && typeof value.time === "string" && Number.isFinite(Date.parse(value.time)) && typeof value.commit === "string" && /^[a-f0-9]{40,64}$/u.test(value.commit) && arrayOf(isCapturePath)(value.dirty) && isCaptureHashes(value.own) && isCaptureDigest(value.shared) && isCaptureHashes(value.tests) && isCaptureHash(value.registry) && isRecord(value.image) && isCaptureHash(value.image.digest) && isFiniteNumber(value.image.size) && isSafeInteger(value.image.size) && value.image.size > 0 && isFiniteNumber(value.image.modified) && value.image.modified >= 0);
520
524
  }
521
525
  /**
522
- * Checks whether an inherited manifest has the supported schema without discarding malformed rows.
526
+ * Checks whether an expanded manifest has the supported schema without discarding malformed rows.
523
527
  *
524
528
  * @param value - The manifest
525
529
  * @returns True if every inherited member validates; false otherwise
526
530
  *
527
531
  * @example
528
532
  * ```ts
529
- * isCaptureManifest(JSON.parse(text)) // true for a published manifest.json
533
+ * isCaptureManifest(readCaptureManifest(JSON.parse(text), file)) // true for an expanded manifest.json
530
534
  * isCaptureManifest('manifest') // false
531
535
  * ```
532
536
  */
533
537
  function isCaptureManifest(value) {
534
- return holds(() => isRecord(value) && value.version === 1 && isCaptureRegistry(value.registry) && isRecord(value.entries) && Object.entries(value.entries).every(([key, stamp]) => isCapturePath(key) && isCaptureStamp(stamp)) && arrayOf(isCaptureLookup)(value.lookups));
538
+ return holds(() => isRecord(value) && value.version === 2 && isCaptureRegistry(value.registry) && isRecord(value.entries) && Object.entries(value.entries).every(([key, stamp]) => isCapturePath(key) && isCaptureStamp(stamp)) && arrayOf(isCaptureLookup)(value.lookups));
535
539
  }
536
540
  /**
537
541
  * Checks whether collection evidence pins complete input membership and both external artifacts.
@@ -549,21 +553,68 @@ function isCaptureCollection(value) {
549
553
  return holds(() => isRecord(value) && isCaptureHash(value.registry) && isCaptureSegment(value.variant) && typeof value.project === "string" && value.project.trim() !== "" && isCaptureDigest(value.inputs) && isRecord(value.run) && isCapturePath(value.run.file) && isCaptureHash(value.run.digest) && isRecord(value.report) && isCapturePath(value.report.file) && isCaptureHash(value.report.digest));
550
554
  }
551
555
  /**
552
- * Checks optional collection metadata without upgrading historical image evidence.
556
+ * Checks whether an expanded manifest and its optional collection receipts have the supported schema.
553
557
  *
554
- * @param value - The inherited image transaction
555
- * @returns True if its existing manifest and any collection receipts are valid; false otherwise
558
+ * @param value - The expanded manifest
559
+ * @returns True if the manifest and any collection receipts are valid; false otherwise
556
560
  *
557
561
  * @example
558
562
  * ```ts
559
- * isCaptureStoredManifest(JSON.parse(text)) // true for a manifest with or without collections
560
- * isCaptureStoredManifest(null) // false
563
+ * isCaptureExpandedManifest(readCaptureManifest(JSON.parse(text), file)) // true with or without collections
564
+ * isCaptureExpandedManifest(null) // false
561
565
  * ```
562
566
  */
563
- function isCaptureStoredManifest(value) {
567
+ function isCaptureExpandedManifest(value) {
564
568
  return holds(() => isCaptureManifest(value) && isRecord(value) && (value.collections === void 0 || arrayOf(isCaptureCollection)(value.collections)));
565
569
  }
566
570
  /**
571
+ * Checks whether a digest names its file map by a table key beside its patterns and combined digest.
572
+ *
573
+ * @param value - The stored digest reference
574
+ * @returns True if the patterns are valid and both digests are SHA-256 hexadecimal; false otherwise
575
+ *
576
+ * @example
577
+ * ```ts
578
+ * isCaptureDigestReference({ patterns: ['src/**'], files: 'a'.repeat(64), digest: 'b'.repeat(64) }) // true
579
+ * isCaptureDigestReference({ patterns: ['src/**'], files: {}, digest: 'b'.repeat(64) }) // false
580
+ * ```
581
+ */
582
+ function isCaptureDigestReference(value) {
583
+ return holds(() => isRecord(value) && arrayOf(isCapturePattern)(value.patterns) && isCaptureHash(value.files) && isCaptureHash(value.digest));
584
+ }
585
+ /**
586
+ * Checks whether a stored manifest holds its population table and every member that names a table key.
587
+ *
588
+ * @param value - The decoded manifest file
589
+ * @returns True if the version, table, registry, stamps, lookups, and collections are valid; false otherwise
590
+ * @remarks Table digests and reference existence are verified when the document is read.
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * isCaptureManifestDocument(JSON.parse(text)) // true for a written manifest.json
595
+ * isCaptureManifestDocument({ version: 1, populations: {}, entries: {}, lookups: [] }) // false
596
+ * ```
597
+ */
598
+ function isCaptureManifestDocument(value) {
599
+ return holds(() => isRecord(value) && isCaptureLookupJournal({
600
+ version: value.version,
601
+ populations: value.populations,
602
+ lookups: value.lookups
603
+ }) && isCaptureRegistry(value.registry) && isRecord(value.entries) && Object.entries(value.entries).every(([key, stamp]) => isCapturePath(key) && isRecord(stamp) && isCaptureDigestReference(stamp.shared) && isCaptureStamp({
604
+ ...stamp,
605
+ shared: {
606
+ ...stamp.shared,
607
+ files: {}
608
+ }
609
+ })) && (value.collections === void 0 || arrayOf((entry) => isRecord(entry) && isCaptureDigestReference(entry.inputs) && isCaptureCollection({
610
+ ...entry,
611
+ inputs: {
612
+ ...entry.inputs,
613
+ files: {}
614
+ }
615
+ }))(value.collections)));
616
+ }
617
+ /**
567
618
  * Checks the host's declared viewport without deriving geometry from an output name.
568
619
  *
569
620
  * @param value - The published viewport data
@@ -1289,7 +1340,7 @@ function buildCaptureRun(options) {
1289
1340
  const reference = options.registry.filter((entry) => entry.section === entry.state);
1290
1341
  const request = options.request;
1291
1342
  return {
1292
- version: 1,
1343
+ version: 2,
1293
1344
  ...request === void 0 ? {} : {
1294
1345
  identity: {
1295
1346
  id: request.id,
@@ -1357,6 +1408,6 @@ function readCaptureArtifact(text) {
1357
1408
  cases: lines.filter((line) => line.startsWith(CAPTURE_ARTIFACT_PREFIXES.case)).map((line) => line.slice(CAPTURE_ARTIFACT_PREFIXES.case.length))
1358
1409
  };
1359
1410
  }
1360
- export { CAPTURE_ARTIFACT_PREFIXES, CAPTURE_ERROR_BRAND, CAPTURE_ERROR_CODES, CAPTURE_LOOKUPS_FILE, CAPTURE_MANIFEST_FILE, CAPTURE_OWNER_PREFIX, CAPTURE_PNG_SIGNATURE, CAPTURE_REGISTRY_FILE, CAPTURE_REQUEST_PREFIX, CAPTURE_STATUS_PRECEDENCE, CAPTURE_VERSION, CaptureError, buildCaptureDestinations, buildCaptureRun, buildCaptureTags, buildCaptureTest, collectCaptureAncestors, collectCaptureCases, collectCaptureChanges, collectCaptureDuplicates, describeCaptureDeclaration, describeCaptureDestination, describeCaptureError, describeCaptureIdentity, describeCaptureRequest, isCaptureArtifact, isCaptureBox, isCaptureCollection, isCaptureDeclaration, isCaptureDestination, isCaptureDigest, isCaptureEntry, isCaptureError, isCaptureGeometry, isCaptureHash, isCaptureHashes, isCaptureIdentity, isCaptureLookup, isCaptureLookupJournal, isCaptureManifest, isCapturePath, isCapturePattern, isCaptureReceipt, isCaptureRegistry, isCaptureRequest, isCaptureRun, isCaptureSegment, isCaptureSelector, isCaptureSources, isCaptureStamp, isCaptureStoredManifest, matchesCaptureMembers, matchesCaptureSelector, readCaptureArtifact, readCaptureDirty, readCaptureReport, renderCaptureArtifact, requireCaptureCases, requireCaptureUnique, resolveCaptureKey, resolveCaptureOwner, resolveCaptureStatus, resolveLookupKey, validateCaptureReceipt, validateCaptureRun };
1411
+ export { CAPTURE_ARTIFACT_PREFIXES, CAPTURE_ERROR_BRAND, CAPTURE_ERROR_CODES, CAPTURE_LOOKUPS_FILE, CAPTURE_MANIFEST_FILE, CAPTURE_OWNER_PREFIX, CAPTURE_PNG_SIGNATURE, CAPTURE_REGISTRY_FILE, CAPTURE_REQUEST_PREFIX, CAPTURE_STATUS_PRECEDENCE, CAPTURE_VERSION, CaptureError, buildCaptureDestinations, buildCaptureRun, buildCaptureTags, buildCaptureTest, collectCaptureAncestors, collectCaptureCases, collectCaptureChanges, collectCaptureDuplicates, describeCaptureDeclaration, describeCaptureDestination, describeCaptureError, describeCaptureIdentity, describeCaptureRequest, isCaptureArtifact, isCaptureBox, isCaptureCollection, isCaptureDeclaration, isCaptureDestination, isCaptureDigest, isCaptureDigestReference, isCaptureEntry, isCaptureError, isCaptureExpandedManifest, isCaptureGeometry, isCaptureHash, isCaptureHashes, isCaptureIdentity, isCaptureLookup, isCaptureLookupJournal, isCaptureManifest, isCaptureManifestDocument, isCapturePath, isCapturePattern, isCaptureReceipt, isCaptureRegistry, isCaptureRequest, isCaptureRun, isCaptureSegment, isCaptureSelector, isCaptureSources, isCaptureStamp, matchesCaptureMembers, matchesCaptureSelector, readCaptureArtifact, readCaptureDirty, readCaptureReport, renderCaptureArtifact, requireCaptureCases, requireCaptureUnique, resolveCaptureKey, resolveCaptureOwner, resolveCaptureStatus, resolveLookupKey, validateCaptureReceipt, validateCaptureRun };
1361
1412
 
1362
1413
  //# sourceMappingURL=index.js.map