context-builder.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ContextBuilder = void 0;
  4. const context_1 = require("./context");
  5. class ContextBuilder {
  6. constructor() {
  7. this.stack = [];
  8. this.fields = [];
  9. this.locations = [];
  10. this.optional = false;
  11. this.requestBail = false;
  12. this.visibility = { type: 'visible' };
  13. }
  14. setFields(fields) {
  15. this.fields = fields;
  16. return this;
  17. }
  18. setLocations(locations) {
  19. this.locations = locations;
  20. return this;
  21. }
  22. setMessage(message) {
  23. this.message = message;
  24. return this;
  25. }
  26. addItem(...items) {
  27. this.stack.push(...items);
  28. return this;
  29. }
  30. setOptional(options) {
  31. this.optional = options;
  32. return this;
  33. }
  34. setRequestBail() {
  35. this.requestBail = true;
  36. return this;
  37. }
  38. setHidden(hidden, hiddenValue) {
  39. if (hidden) {
  40. this.visibility =
  41. hiddenValue !== undefined ? { type: 'redacted', value: hiddenValue } : { type: 'hidden' };
  42. }
  43. else {
  44. this.visibility = { type: 'visible' };
  45. }
  46. return this;
  47. }
  48. build() {
  49. return new context_1.Context(this.fields, this.locations, this.stack, this.optional, this.requestBail, this.visibility, this.message);
  50. }
  51. }
  52. exports.ContextBuilder = ContextBuilder;