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