@spine-event-engine/core 2.0.0-snapshot.16 → 2.0.0-snapshot.18

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.js CHANGED
@@ -181,13 +181,30 @@ export class ValidationException extends Error {
181
181
  return this.#messageData;
182
182
  }
183
183
  }
184
+ /**
185
+ * Constructs a rejection after its generated message has been validated.
186
+ *
187
+ * @typeParam Schema Generated rejection message schema.
188
+ * @param schema Schema used to snapshot the message.
189
+ * @param messageData Validated rejection message.
190
+ * @returns Nominal rejection throwable.
191
+ */
184
192
  let instantiateRejection;
185
193
  /**
186
194
  * A nominal domain rejection carrying its generated Protobuf message.
195
+ *
196
+ * @typeParam Schema Generated schema of the rejection message.
187
197
  */
188
198
  export class RejectionThrowable extends Error {
189
199
  #schema;
190
200
  #messageData;
201
+ /**
202
+ * Captures a validated rejection through the private factory token.
203
+ *
204
+ * @param schema Generated rejection message schema.
205
+ * @param messageData Validated rejection message to snapshot.
206
+ * @param token Token restricting construction to the factory.
207
+ */
191
208
  constructor(schema, messageData, token) {
192
209
  super(`Rejected: ${schema.typeName}`);
193
210
  if (token !== REJECTION_CONSTRUCTOR) {
@@ -201,7 +218,18 @@ export class RejectionThrowable extends Error {
201
218
  Object.preventExtensions(this);
202
219
  }
203
220
  static {
204
- instantiateRejection = (schema, messageData) => new RejectionThrowable(schema, messageData, REJECTION_CONSTRUCTOR);
221
+ instantiateRejection = (schema, messageData) => RejectionThrowable.instantiate(schema, messageData);
222
+ }
223
+ /**
224
+ * Creates a typed rejection through the private constructor.
225
+ *
226
+ * @typeParam CreatedSchema Generated rejection message schema.
227
+ * @param schema Schema used to snapshot the message.
228
+ * @param messageData Validated rejection message.
229
+ * @returns Nominal rejection throwable.
230
+ */
231
+ static instantiate(schema, messageData) {
232
+ return new RejectionThrowable(schema, messageData, REJECTION_CONSTRUCTOR);
205
233
  }
206
234
  /**
207
235
  * Returns the generated Protobuf-ES schema for the rejected domain signal.
@@ -226,6 +254,7 @@ export class RejectionThrowable extends Error {
226
254
  }
227
255
  /**
228
256
  * Creates a nominal throwable from a validated generated rejection message.
257
+ * @typeParam Schema Generated rejection message schema.
229
258
  * @param schema The generated rejection schema.
230
259
  * @param input The rejection message fields.
231
260
  * @returns The validated nominal rejection throwable.
@@ -242,6 +271,11 @@ export class RejectionThrowable extends Error {
242
271
  static is(value) {
243
272
  return typeof value === "object" && value !== null && REJECTION_THROWABLES.has(value);
244
273
  }
274
+ /**
275
+ * Validates that a schema is a top-level message from a rejection schema file.
276
+ *
277
+ * @param schema Candidate generated rejection schema.
278
+ */
245
279
  static assertSchema(schema) {
246
280
  const basename = schema.file.proto.name.split("/").at(-1);
247
281
  const rejectionSource = basename === "rejections.proto" || basename?.endsWith("_rejections.proto") === true;
@@ -249,6 +283,14 @@ export class RejectionThrowable extends Error {
249
283
  throw new TypeError(`Rejection schema "${schema.typeName}" must be a top-level message declared in a rejections.proto file.`);
250
284
  }
251
285
  }
286
+ /**
287
+ * Copies a rejection message through its binary representation.
288
+ *
289
+ * @typeParam Schema Generated rejection message schema.
290
+ * @param schema Schema used to encode and decode the message.
291
+ * @param message Rejection message to copy.
292
+ * @returns Independent message snapshot.
293
+ */
252
294
  static snapshot(schema, message) {
253
295
  return fromBinary(schema, toBinary(schema, message));
254
296
  }
@@ -268,6 +310,7 @@ export const Validate = {
268
310
  },
269
311
  /**
270
312
  * Validates one Protobuf message through the Spine TS validation facade.
313
+ * @typeParam Schema Generated schema of the message being validated.
271
314
  * @param schema The message schema.
272
315
  * @param message The message to validate.
273
316
  * @returns The sanitized validation result.
@@ -284,6 +327,7 @@ export const Validate = {
284
327
  },
285
328
  /**
286
329
  * Validates one Protobuf message and throws for constraint violations.
330
+ * @typeParam Schema Generated schema of the message being validated.
287
331
  * @param schema The message schema.
288
332
  * @param message The message to validate.
289
333
  * @returns The validated message.
@@ -296,6 +340,7 @@ export const Validate = {
296
340
  },
297
341
  /**
298
342
  * Validates a previous/next state pair with framework-owned transition rules.
343
+ * @typeParam Schema Generated schema shared by both states.
299
344
  * @param request The state transition.
300
345
  * @param rules The rules to apply.
301
346
  * @returns The sanitized transition result.
@@ -378,6 +423,7 @@ export const AnyMessages = {
378
423
  // prettier-ignore
379
424
  /**
380
425
  * Packs a message into `Any`, omitting unknown fields from binary output.
426
+ * @typeParam Schema Generated schema of the enclosed message.
381
427
  * @param schema The message schema.
382
428
  * @param message The message to pack.
383
429
  * @param options The packing options.
@@ -393,6 +439,7 @@ export const AnyMessages = {
393
439
  },
394
440
  /**
395
441
  * Unpacks an `Any` when its type URL exactly matches the requested schema.
442
+ * @typeParam Schema Generated schema expected in the envelope.
396
443
  * @param packed The packed message.
397
444
  * @param schema The expected schema.
398
445
  * @returns The unpacked message, when valid.
@@ -429,8 +476,23 @@ Object.freeze(AnyMessages);
429
476
  function isProtobufRegistry(types) {
430
477
  return "kind" in types;
431
478
  }
479
+ /**
480
+ * Creates reversible compact Proto JSON conversion for a generated message.
481
+ *
482
+ * @typeParam Schema Generated schema used for conversion.
483
+ * @param schema Message schema used for Proto JSON.
484
+ * @param registry Optional registry for expanding packed Any messages.
485
+ * @param typeUrls Canonical URLs restored on parsed Any messages.
486
+ * @returns Schema-bound stringifier.
487
+ */
432
488
  function defaultMessageStringifier(schema, registry, typeUrls) {
433
489
  return Object.freeze({
490
+ /**
491
+ * Parses compact Proto JSON and restores canonical Any type URLs.
492
+ *
493
+ * @param value Compact Proto JSON text.
494
+ * @returns Parsed generated message.
495
+ */
434
496
  fromString(value) {
435
497
  const message = registry === undefined
436
498
  ? fromJsonString(schema, value)
@@ -438,6 +500,12 @@ function defaultMessageStringifier(schema, registry, typeUrls) {
438
500
  restoreAnyTypeUrls(message, typeUrls);
439
501
  return message;
440
502
  },
503
+ /**
504
+ * Serializes a generated message as compact Proto JSON.
505
+ *
506
+ * @param value Generated message to serialize.
507
+ * @returns Compact Proto JSON text.
508
+ */
441
509
  toString(value) {
442
510
  return registry === undefined
443
511
  ? toJsonString(schema, value)
@@ -466,6 +534,13 @@ function restoreAnyTypeUrls(value, typeUrls) {
466
534
  restoreAnyTypeUrls(item, typeUrls);
467
535
  }
468
536
  const FieldStringifiers = Object.freeze({
537
+ /**
538
+ * Returns reversible conversion for one singular message, enum, or scalar field.
539
+ *
540
+ * @param field Generated descriptor of the field.
541
+ * @param messageStringifier Resolves conversion for message-valued fields.
542
+ * @returns Stringifier for the field's runtime value.
543
+ */
469
544
  create(field, messageStringifier) {
470
545
  switch (field.fieldKind) {
471
546
  case "message":
@@ -479,13 +554,31 @@ const FieldStringifiers = Object.freeze({
479
554
  throw new Error("Stringifiers support only singular Protobuf fields.");
480
555
  }
481
556
  },
557
+ /**
558
+ * Creates enum conversion using declared names and valid numeric values.
559
+ *
560
+ * @param field Generated enum field descriptor.
561
+ * @returns Reversible enum stringifier.
562
+ */
482
563
  enum(field) {
483
564
  return Object.freeze({
565
+ /**
566
+ * Parses a declared enum name or valid integer text.
567
+ *
568
+ * @param value Enum name or canonical numeric text.
569
+ * @returns Enum numeric value.
570
+ */
484
571
  fromString(value) {
485
572
  const named = field.enum.values.find((candidate) => candidate.name === value);
486
573
  return (named?.number ??
487
574
  Number(FieldStringifiers.integerText(value, -(2n ** 31n), 2n ** 31n - 1n)));
488
575
  },
576
+ /**
577
+ * Formats an enum number as its declared name or integer text.
578
+ *
579
+ * @param value Valid enum numeric value.
580
+ * @returns Declared name when available, otherwise numeric text.
581
+ */
489
582
  toString(value) {
490
583
  if (typeof value !== "number" || !Number.isInteger(value)) {
491
584
  throw new TypeError("Enum field value must be an integer number.");
@@ -495,6 +588,12 @@ const FieldStringifiers = Object.freeze({
495
588
  },
496
589
  });
497
590
  },
591
+ /**
592
+ * Returns conversion and range rules for a Protobuf scalar field.
593
+ *
594
+ * @param field Generated scalar field descriptor.
595
+ * @returns Reversible scalar stringifier.
596
+ */
498
597
  scalar(field) {
499
598
  switch (field.scalar) {
500
599
  case ScalarType.STRING:
@@ -524,9 +623,21 @@ const FieldStringifiers = Object.freeze({
524
623
  }
525
624
  },
526
625
  string: Object.freeze({
626
+ /**
627
+ * Accepts a string field without changing its text.
628
+ *
629
+ * @param value Stored string text.
630
+ * @returns The same string value.
631
+ */
527
632
  fromString(value) {
528
633
  return value;
529
634
  },
635
+ /**
636
+ * Checks and returns a string field value.
637
+ *
638
+ * @param value Runtime string field value.
639
+ * @returns The same string text.
640
+ */
530
641
  toString(value) {
531
642
  if (typeof value !== "string")
532
643
  throw new TypeError("Field value must be a string.");
@@ -534,6 +645,12 @@ const FieldStringifiers = Object.freeze({
534
645
  },
535
646
  }),
536
647
  boolean: Object.freeze({
648
+ /**
649
+ * Parses canonical boolean text.
650
+ *
651
+ * @param value Text required to be `true` or `false`.
652
+ * @returns Decoded boolean value.
653
+ */
537
654
  fromString(value) {
538
655
  if (value === "true")
539
656
  return true;
@@ -541,6 +658,12 @@ const FieldStringifiers = Object.freeze({
541
658
  return false;
542
659
  throw new Error("Field value must be a canonical boolean.");
543
660
  },
661
+ /**
662
+ * Formats a boolean as canonical text.
663
+ *
664
+ * @param value Runtime boolean field value.
665
+ * @returns `true` or `false`.
666
+ */
544
667
  toString(value) {
545
668
  if (typeof value !== "boolean")
546
669
  throw new TypeError("Field value must be a boolean.");
@@ -548,6 +671,12 @@ const FieldStringifiers = Object.freeze({
548
671
  },
549
672
  }),
550
673
  bytes: Object.freeze({
674
+ /**
675
+ * Decodes a canonical standard-base64 byte field.
676
+ *
677
+ * @param value Canonical base64 text.
678
+ * @returns Decoded bytes.
679
+ */
551
680
  fromString(value) {
552
681
  let decoded;
553
682
  try {
@@ -561,6 +690,12 @@ const FieldStringifiers = Object.freeze({
561
690
  }
562
691
  return decoded;
563
692
  },
693
+ /**
694
+ * Encodes a byte field as standard base64.
695
+ *
696
+ * @param value Runtime byte array.
697
+ * @returns Canonical base64 text.
698
+ */
564
699
  toString(value) {
565
700
  if (!(value instanceof Uint8Array)) {
566
701
  throw new TypeError("Field value must be a byte array.");
@@ -569,6 +704,12 @@ const FieldStringifiers = Object.freeze({
569
704
  },
570
705
  }),
571
706
  number: Object.freeze({
707
+ /**
708
+ * Parses canonical finite numeric text, preserving negative zero.
709
+ *
710
+ * @param value Canonical finite number text.
711
+ * @returns Parsed finite number.
712
+ */
572
713
  fromString(value) {
573
714
  const parsed = Number(value);
574
715
  if (!Number.isFinite(parsed))
@@ -578,6 +719,12 @@ const FieldStringifiers = Object.freeze({
578
719
  throw new Error("Field value must be a canonical number.");
579
720
  return parsed;
580
721
  },
722
+ /**
723
+ * Formats a finite number canonically, preserving negative zero.
724
+ *
725
+ * @param value Runtime finite number.
726
+ * @returns Canonical numeric text.
727
+ */
581
728
  toString(value) {
582
729
  if (typeof value !== "number" || !Number.isFinite(value)) {
583
730
  throw new TypeError("Field value must be a finite number.");
@@ -586,6 +733,12 @@ const FieldStringifiers = Object.freeze({
586
733
  },
587
734
  }),
588
735
  float: Object.freeze({
736
+ /**
737
+ * Parses canonical binary32 text and rejects values outside its range.
738
+ *
739
+ * @param value Canonical binary32 number text.
740
+ * @returns Rounded binary32 number.
741
+ */
589
742
  fromString(value) {
590
743
  const parsed = Number(value);
591
744
  if (!Number.isFinite(parsed))
@@ -599,6 +752,12 @@ const FieldStringifiers = Object.freeze({
599
752
  }
600
753
  return restored;
601
754
  },
755
+ /**
756
+ * Converts a finite number to canonical binary32 text.
757
+ *
758
+ * @param value Runtime finite number.
759
+ * @returns Canonical binary32 number text.
760
+ */
602
761
  toString(value) {
603
762
  if (typeof value !== "number" || !Number.isFinite(value)) {
604
763
  throw new TypeError("Field value must be a finite number.");
@@ -610,6 +769,12 @@ const FieldStringifiers = Object.freeze({
610
769
  return FieldStringifiers.floatText(normalized);
611
770
  },
612
771
  }),
772
+ /**
773
+ * Finds the shortest decimal text that round-trips to a binary32 value.
774
+ *
775
+ * @param value Finite binary32 number to format.
776
+ * @returns Canonical short decimal text.
777
+ */
613
778
  floatText(value) {
614
779
  if (Object.is(value, -0))
615
780
  return "-0";
@@ -622,8 +787,22 @@ const FieldStringifiers = Object.freeze({
622
787
  }
623
788
  throw new Error("Unable to format the float32 field value.");
624
789
  },
790
+ /**
791
+ * Creates range-checked integer conversion for a declared runtime representation.
792
+ *
793
+ * @param min Smallest integer accepted by the field.
794
+ * @param max Largest integer accepted by the field.
795
+ * @param representation Runtime number, bigint, or string representation.
796
+ * @returns Reversible bounded integer stringifier.
797
+ */
625
798
  integer(min, max, representation) {
626
799
  return Object.freeze({
800
+ /**
801
+ * Parses bounded canonical integer text into the declared runtime form.
802
+ *
803
+ * @param value Canonical integer text.
804
+ * @returns Number, bigint, or string required by the field.
805
+ */
627
806
  fromString(value) {
628
807
  const restored = FieldStringifiers.integerText(value, min, max);
629
808
  switch (representation) {
@@ -635,12 +814,26 @@ const FieldStringifiers = Object.freeze({
635
814
  return restored.toString();
636
815
  }
637
816
  },
817
+ /**
818
+ * Checks a runtime integer and formats it as canonical decimal text.
819
+ *
820
+ * @param value Integer in the field's runtime representation.
821
+ * @returns Canonical decimal text.
822
+ */
638
823
  toString(value) {
639
824
  const restored = FieldStringifiers.integerValue(value, min, max, representation);
640
825
  return restored.toString();
641
826
  },
642
827
  });
643
828
  },
829
+ /**
830
+ * Parses canonical decimal integer text within the field's bounds.
831
+ *
832
+ * @param value Canonical integer text.
833
+ * @param min Smallest allowed integer.
834
+ * @param max Largest allowed integer.
835
+ * @returns Parsed bounded integer.
836
+ */
644
837
  integerText(value, min, max) {
645
838
  if (!/^(?:0|-?[1-9]\d*)$/u.test(value)) {
646
839
  throw new Error("Field value must be a canonical integer.");
@@ -652,6 +845,15 @@ const FieldStringifiers = Object.freeze({
652
845
  }
653
846
  return restored;
654
847
  },
848
+ /**
849
+ * Converts a runtime integer to bigint after representation and range checks.
850
+ *
851
+ * @param value Integer value to validate.
852
+ * @param min Smallest allowed integer.
853
+ * @param max Largest allowed integer.
854
+ * @param representation Required runtime representation.
855
+ * @returns Bounded bigint value.
856
+ */
655
857
  integerValue(value, min, max, representation) {
656
858
  let converted;
657
859
  if (representation === "string") {
@@ -684,6 +886,7 @@ export const Stringifiers = {
684
886
  // prettier-ignore
685
887
  /**
686
888
  * Creates the default compact Proto JSON stringifier for a message schema.
889
+ * @typeParam Schema Generated schema used for Proto JSON conversion.
687
890
  * @param schema The generated message schema.
688
891
  * @param types The optional generated-type registry used to expand `Any` values.
689
892
  * @returns A reversible schema-bound stringifier.
@@ -738,6 +941,7 @@ export class StringifierRegistry {
738
941
  }
739
942
  /**
740
943
  * Registers or replaces the stringifier for one generated message type.
944
+ * @typeParam Schema Generated schema of the custom stringifier's message.
741
945
  * @param schema The generated message schema.
742
946
  * @param stringifier The reversible stringifier.
743
947
  */
@@ -756,6 +960,7 @@ export class StringifierRegistry {
756
960
  }
757
961
  /**
758
962
  * Returns the custom stringifier or the default compact Proto JSON mapping.
963
+ * @typeParam Schema Generated schema of the requested stringifier.
759
964
  * @param schema The generated message schema.
760
965
  * @returns The schema-bound stringifier.
761
966
  */
@@ -796,6 +1001,12 @@ export const Identifiers = {
796
1001
  };
797
1002
  Object.freeze(Identifiers);
798
1003
  const IdentifierValues = Object.freeze({
1004
+ /**
1005
+ * Validates a signed 32-bit numeric identifier.
1006
+ *
1007
+ * @param value Candidate numeric identifier.
1008
+ * @returns Integer within the signed 32-bit range.
1009
+ */
799
1010
  int32(value) {
800
1011
  if (typeof value !== "number" ||
801
1012
  !Number.isInteger(value) ||
@@ -805,6 +1016,12 @@ const IdentifierValues = Object.freeze({
805
1016
  }
806
1017
  return value;
807
1018
  },
1019
+ /**
1020
+ * Validates a signed 64-bit bigint identifier.
1021
+ *
1022
+ * @param value Candidate bigint identifier.
1023
+ * @returns Bigint within the signed 64-bit range.
1024
+ */
808
1025
  int64(value) {
809
1026
  if (typeof value !== "bigint" || value < -(1n << 63n) || value >= 1n << 63n) {
810
1027
  throw new RangeError("Identifier is outside the int64 range.");
@@ -867,6 +1084,7 @@ export const SignalEnvelopes = {
867
1084
  // prettier-ignore
868
1085
  /**
869
1086
  * Packs a generated Spine command envelope with a fresh secure ID.
1087
+ * @typeParam Schema Generated schema of the domain command.
870
1088
  * @param input The command envelope input.
871
1089
  * @returns The packed command.
872
1090
  */
@@ -879,6 +1097,7 @@ export const SignalEnvelopes = {
879
1097
  },
880
1098
  /**
881
1099
  * Packs a generated Spine event envelope with a fresh secure ID.
1100
+ * @typeParam Schema Generated schema of the domain event.
882
1101
  * @param input The event envelope input.
883
1102
  * @returns The packed event.
884
1103
  */
@@ -962,6 +1181,7 @@ export class TypeRegistry {
962
1181
  }
963
1182
  /**
964
1183
  * Registers one schema and returns its immutable metadata.
1184
+ * @typeParam Schema Generated schema to register.
965
1185
  * @param schema The generated message schema.
966
1186
  * @param options Optional explicit type URL.
967
1187
  * @returns The registered schema metadata.
@@ -1013,6 +1233,7 @@ export class TypeRegistry {
1013
1233
  }
1014
1234
  /**
1015
1235
  * Finds metadata by generated schema identity.
1236
+ * @typeParam Schema Generated schema used as the lookup key.
1016
1237
  * @param schema The generated message schema.
1017
1238
  * @returns Matching metadata, if registered.
1018
1239
  */
@@ -1045,6 +1266,7 @@ export class TypeRegistry {
1045
1266
  }
1046
1267
  /**
1047
1268
  * Gets metadata by generated schema identity or throws a descriptive error.
1269
+ * @typeParam Schema Generated schema used as the lookup key.
1048
1270
  * @param schema The generated message schema.
1049
1271
  * @returns The registered metadata.
1050
1272
  */
@@ -1067,6 +1289,12 @@ const RegistryLookups = {
1067
1289
  // prettier-ignore
1068
1290
  /**
1069
1291
  * Composes modules in deterministic dependency-first order.
1292
+ *
1293
+ * @param root Module whose dependency graph is traversed.
1294
+ * @param definitions Seen module definitions keyed by name.
1295
+ * @param visiting Names on the current dependency path for cycle detection.
1296
+ * @param verified Module objects already checked and appended.
1297
+ * @param schemas Output list of schemas in dependency-first order.
1070
1298
  */
1071
1299
  compose(root, definitions, visiting, verified, schemas) {
1072
1300
  const frames = [{ module: root, appendSchemas: false }];
@@ -1109,6 +1337,10 @@ const RegistryLookups = {
1109
1337
  },
1110
1338
  /**
1111
1339
  * Compares two module definitions for same-name conflicts.
1340
+ *
1341
+ * @param left Previously seen module definition.
1342
+ * @param right Candidate definition with the same name.
1343
+ * @returns True when names, schemas, and dependency names agree.
1112
1344
  */
1113
1345
  sameModule(left, right) {
1114
1346
  if (left === right) {
@@ -1124,6 +1356,11 @@ const RegistryLookups = {
1124
1356
  },
1125
1357
  /**
1126
1358
  * Creates immutable descriptor-backed schema metadata.
1359
+ *
1360
+ * @typeParam Schema Generated schema represented by the metadata.
1361
+ * @param schema Generated message schema being registered.
1362
+ * @param typeUrl Canonical URL assigned to the schema.
1363
+ * @returns Frozen descriptor-backed metadata.
1127
1364
  */
1128
1365
  metadata(schema, typeUrl) {
1129
1366
  const firstField = schema.fields[0];
@@ -1137,9 +1374,23 @@ const RegistryLookups = {
1137
1374
  typeUrlPrefix: typeUrl.slice(0, typeUrl.length - schema.typeName.length - 1),
1138
1375
  firstField,
1139
1376
  firstFieldName: firstField?.name,
1377
+ /**
1378
+ * Checks whether the schema file declares a given option.
1379
+ *
1380
+ * @typeParam Value Value type declared by the extension.
1381
+ * @param option File-option extension to test.
1382
+ * @returns True when the option is present.
1383
+ */
1140
1384
  hasFileOption(option) {
1141
1385
  return hasOption(schema.file, option);
1142
1386
  },
1387
+ /**
1388
+ * Reads a declared option from the schema file.
1389
+ *
1390
+ * @typeParam Value Value type declared by the extension.
1391
+ * @param option File-option extension to read.
1392
+ * @returns Decoded option value.
1393
+ */
1143
1394
  getFileOption(option) {
1144
1395
  return getOption(schema.file, option);
1145
1396
  },
@@ -1147,15 +1398,36 @@ const RegistryLookups = {
1147
1398
  },
1148
1399
  /**
1149
1400
  * Creates an immutable registry lookup view.
1401
+ *
1402
+ * @param registry Mutable registry exposed through read-only operations.
1403
+ * @returns Frozen lookup facade.
1150
1404
  */
1151
1405
  lookup(registry) {
1152
1406
  return Object.freeze({
1153
1407
  findByFullName: (fullTypeName) => registry.findByFullName(fullTypeName),
1154
1408
  findByTypeUrl: (typeUrl) => registry.findByTypeUrl(typeUrl),
1155
- findBySchema: (schema) => registry.findBySchema(schema),
1409
+ /**
1410
+ * Finds registered metadata by generated schema identity.
1411
+ *
1412
+ * @typeParam Schema Generated schema used as the lookup key.
1413
+ * @param schema Generated schema to find.
1414
+ * @returns Matching metadata, if registered.
1415
+ */
1416
+ findBySchema(schema) {
1417
+ return registry.findBySchema(schema);
1418
+ },
1156
1419
  getByFullName: (fullTypeName) => registry.getByFullName(fullTypeName),
1157
1420
  getByTypeUrl: (typeUrl) => registry.getByTypeUrl(typeUrl),
1158
- getBySchema: (schema) => registry.getBySchema(schema),
1421
+ /**
1422
+ * Gets registered metadata by generated schema identity.
1423
+ *
1424
+ * @typeParam Schema Generated schema used as the lookup key.
1425
+ * @param schema Generated schema to require.
1426
+ * @returns Registered metadata.
1427
+ */
1428
+ getBySchema(schema) {
1429
+ return registry.getBySchema(schema);
1430
+ },
1159
1431
  list: () => registry.list(),
1160
1432
  });
1161
1433
  },
@@ -1168,21 +1440,46 @@ export const spineCoreRegistry = RegistryLookups.lookup(TypeRegistry.spineCore()
1168
1440
  * Constructs and sanitizes internal message-validation results.
1169
1441
  */
1170
1442
  const ValidationResults = {
1443
+ /**
1444
+ * Builds a structured validation result from sanitized violations.
1445
+ *
1446
+ * @param violations Sanitized constraint violations.
1447
+ * @returns Valid result when empty, otherwise an error with violations.
1448
+ */
1171
1449
  from(violations) {
1172
1450
  if (violations.length === 0)
1173
1451
  return { valid: true, violations: EMPTY_VIOLATIONS, error: undefined };
1174
1452
  const nonEmpty = violations;
1175
1453
  return { valid: false, violations: nonEmpty, error: ValidationResults.error(nonEmpty) };
1176
1454
  },
1455
+ /**
1456
+ * Packs constraint violations into a generated validation error.
1457
+ *
1458
+ * @param violations Violations to include in the error.
1459
+ * @returns Generated validation error message.
1460
+ */
1177
1461
  error(violations) {
1178
1462
  return create(ValidationErrorSchema, { constraintViolation: [...violations] });
1179
1463
  },
1464
+ /**
1465
+ * Creates a runtime-failure violation without exposing the caught error.
1466
+ *
1467
+ * @param typeName Protobuf type being validated.
1468
+ * @param message Stable public failure text.
1469
+ * @returns Generated constraint violation.
1470
+ */
1180
1471
  failure(typeName, message) {
1181
1472
  return create(ConstraintViolationSchema, {
1182
1473
  typeName,
1183
1474
  message: create(TemplateStringSchema, { withPlaceholders: message }),
1184
1475
  });
1185
1476
  },
1477
+ /**
1478
+ * Copies a violation while redacting placeholder values.
1479
+ *
1480
+ * @param violation Violation supplied by a validation rule.
1481
+ * @returns Sanitized generated constraint violation.
1482
+ */
1186
1483
  violation(violation) {
1187
1484
  return create(ConstraintViolationSchema, {
1188
1485
  message: violation.message === undefined
@@ -1197,6 +1494,12 @@ const ValidationResults = {
1197
1494
  : create(FieldPathSchema, { fieldName: [...violation.fieldPath.fieldName] }),
1198
1495
  });
1199
1496
  },
1497
+ /**
1498
+ * Replaces every template placeholder value with stable redaction text.
1499
+ *
1500
+ * @param values Placeholder values to suppress.
1501
+ * @returns Placeholder keys mapped to redaction text.
1502
+ */
1200
1503
  redact(values) {
1201
1504
  return Object.fromEntries(Object.keys(values ?? {}).map((key) => [key, REDACTED_VALIDATION_DETAIL]));
1202
1505
  },