events.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. "use strict";
  2. // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
  3. // versions:
  4. // protoc-gen-ts_proto v2.6.1
  5. // protoc v5.29.4
  6. // source: events.proto
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.CloudEventBatch = exports.CloudEvent_CloudEventAttributeValue = exports.CloudEvent_AttributesEntry = exports.CloudEvent = void 0;
  9. /* eslint-disable */
  10. const any_1 = require("./google/protobuf/any");
  11. const timestamp_1 = require("./google/protobuf/timestamp");
  12. exports.CloudEvent = {
  13. fromJSON(object) {
  14. return {
  15. id: isSet(object.id) ? globalThis.String(object.id) : "",
  16. source: isSet(object.source) ? globalThis.String(object.source) : "",
  17. specVersion: isSet(object.specVersion) ? globalThis.String(object.specVersion) : "",
  18. type: isSet(object.type) ? globalThis.String(object.type) : "",
  19. attributes: isObject(object.attributes)
  20. ? Object.entries(object.attributes).reduce((acc, [key, value]) => {
  21. acc[key] = exports.CloudEvent_CloudEventAttributeValue.fromJSON(value);
  22. return acc;
  23. }, {})
  24. : {},
  25. data: isSet(object.binaryData)
  26. ? { $case: "binaryData", binaryData: Buffer.from(bytesFromBase64(object.binaryData)) }
  27. : isSet(object.textData)
  28. ? { $case: "textData", textData: globalThis.String(object.textData) }
  29. : isSet(object.protoData)
  30. ? { $case: "protoData", protoData: any_1.Any.fromJSON(object.protoData) }
  31. : undefined,
  32. };
  33. },
  34. toJSON(message) {
  35. const obj = {};
  36. if (message.id !== "") {
  37. obj.id = message.id;
  38. }
  39. if (message.source !== "") {
  40. obj.source = message.source;
  41. }
  42. if (message.specVersion !== "") {
  43. obj.specVersion = message.specVersion;
  44. }
  45. if (message.type !== "") {
  46. obj.type = message.type;
  47. }
  48. if (message.attributes) {
  49. const entries = Object.entries(message.attributes);
  50. if (entries.length > 0) {
  51. obj.attributes = {};
  52. entries.forEach(([k, v]) => {
  53. obj.attributes[k] = exports.CloudEvent_CloudEventAttributeValue.toJSON(v);
  54. });
  55. }
  56. }
  57. if (message.data?.$case === "binaryData") {
  58. obj.binaryData = base64FromBytes(message.data.binaryData);
  59. }
  60. else if (message.data?.$case === "textData") {
  61. obj.textData = message.data.textData;
  62. }
  63. else if (message.data?.$case === "protoData") {
  64. obj.protoData = any_1.Any.toJSON(message.data.protoData);
  65. }
  66. return obj;
  67. },
  68. };
  69. exports.CloudEvent_AttributesEntry = {
  70. fromJSON(object) {
  71. return {
  72. key: isSet(object.key) ? globalThis.String(object.key) : "",
  73. value: isSet(object.value) ? exports.CloudEvent_CloudEventAttributeValue.fromJSON(object.value) : undefined,
  74. };
  75. },
  76. toJSON(message) {
  77. const obj = {};
  78. if (message.key !== "") {
  79. obj.key = message.key;
  80. }
  81. if (message.value !== undefined) {
  82. obj.value = exports.CloudEvent_CloudEventAttributeValue.toJSON(message.value);
  83. }
  84. return obj;
  85. },
  86. };
  87. exports.CloudEvent_CloudEventAttributeValue = {
  88. fromJSON(object) {
  89. return {
  90. attr: isSet(object.ceBoolean)
  91. ? { $case: "ceBoolean", ceBoolean: globalThis.Boolean(object.ceBoolean) }
  92. : isSet(object.ceInteger)
  93. ? { $case: "ceInteger", ceInteger: globalThis.Number(object.ceInteger) }
  94. : isSet(object.ceString)
  95. ? { $case: "ceString", ceString: globalThis.String(object.ceString) }
  96. : isSet(object.ceBytes)
  97. ? { $case: "ceBytes", ceBytes: Buffer.from(bytesFromBase64(object.ceBytes)) }
  98. : isSet(object.ceUri)
  99. ? { $case: "ceUri", ceUri: globalThis.String(object.ceUri) }
  100. : isSet(object.ceUriRef)
  101. ? { $case: "ceUriRef", ceUriRef: globalThis.String(object.ceUriRef) }
  102. : isSet(object.ceTimestamp)
  103. ? { $case: "ceTimestamp", ceTimestamp: fromJsonTimestamp(object.ceTimestamp) }
  104. : undefined,
  105. };
  106. },
  107. toJSON(message) {
  108. const obj = {};
  109. if (message.attr?.$case === "ceBoolean") {
  110. obj.ceBoolean = message.attr.ceBoolean;
  111. }
  112. else if (message.attr?.$case === "ceInteger") {
  113. obj.ceInteger = Math.round(message.attr.ceInteger);
  114. }
  115. else if (message.attr?.$case === "ceString") {
  116. obj.ceString = message.attr.ceString;
  117. }
  118. else if (message.attr?.$case === "ceBytes") {
  119. obj.ceBytes = base64FromBytes(message.attr.ceBytes);
  120. }
  121. else if (message.attr?.$case === "ceUri") {
  122. obj.ceUri = message.attr.ceUri;
  123. }
  124. else if (message.attr?.$case === "ceUriRef") {
  125. obj.ceUriRef = message.attr.ceUriRef;
  126. }
  127. else if (message.attr?.$case === "ceTimestamp") {
  128. obj.ceTimestamp = message.attr.ceTimestamp.toISOString();
  129. }
  130. return obj;
  131. },
  132. };
  133. exports.CloudEventBatch = {
  134. fromJSON(object) {
  135. return {
  136. events: globalThis.Array.isArray(object?.events) ? object.events.map((e) => exports.CloudEvent.fromJSON(e)) : [],
  137. };
  138. },
  139. toJSON(message) {
  140. const obj = {};
  141. if (message.events?.length) {
  142. obj.events = message.events.map((e) => exports.CloudEvent.toJSON(e));
  143. }
  144. return obj;
  145. },
  146. };
  147. function bytesFromBase64(b64) {
  148. return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
  149. }
  150. function base64FromBytes(arr) {
  151. return globalThis.Buffer.from(arr).toString("base64");
  152. }
  153. function fromTimestamp(t) {
  154. let millis = (globalThis.Number(t.seconds) || 0) * 1_000;
  155. millis += (t.nanos || 0) / 1_000_000;
  156. return new globalThis.Date(millis);
  157. }
  158. function fromJsonTimestamp(o) {
  159. if (o instanceof globalThis.Date) {
  160. return o;
  161. }
  162. else if (typeof o === "string") {
  163. return new globalThis.Date(o);
  164. }
  165. else {
  166. return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
  167. }
  168. }
  169. function isObject(value) {
  170. return typeof value === "object" && value !== null;
  171. }
  172. function isSet(value) {
  173. return value !== null && value !== undefined;
  174. }