@rise-maritime/keelson-js 0.4.6-pre.2

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.
Files changed (157) hide show
  1. package/README.md +141 -0
  2. package/dist/Envelope.d.ts +37 -0
  3. package/dist/Envelope.js +212 -0
  4. package/dist/google/protobuf/timestamp.d.ts +128 -0
  5. package/dist/google/protobuf/timestamp.js +92 -0
  6. package/dist/index.d.ts +16 -0
  7. package/dist/index.js +102 -0
  8. package/dist/index.test.d.ts +1 -0
  9. package/dist/index.test.js +70 -0
  10. package/dist/interfaces/Configurable.d.ts +46 -0
  11. package/dist/interfaces/Configurable.js +106 -0
  12. package/dist/interfaces/ErrorResponse.d.ts +25 -0
  13. package/dist/interfaces/ErrorResponse.js +65 -0
  14. package/dist/interfaces/NetworkPingPong.d.ts +47 -0
  15. package/dist/interfaces/NetworkPingPong.js +228 -0
  16. package/dist/interfaces/Subscriber.d.ts +54 -0
  17. package/dist/interfaces/Subscriber.js +215 -0
  18. package/dist/interfaces/WHEPProxy.d.ts +45 -0
  19. package/dist/interfaces/WHEPProxy.js +147 -0
  20. package/dist/interfaces/google/protobuf/empty.d.ts +33 -0
  21. package/dist/interfaces/google/protobuf/empty.js +48 -0
  22. package/dist/interfaces/google/protobuf/timestamp.d.ts +128 -0
  23. package/dist/interfaces/google/protobuf/timestamp.js +92 -0
  24. package/dist/payloads/Alarm.d.ts +118 -0
  25. package/dist/payloads/Alarm.js +711 -0
  26. package/dist/payloads/Audio.d.ts +37 -0
  27. package/dist/payloads/Audio.js +195 -0
  28. package/dist/payloads/Decomposed3DVector.d.ts +31 -0
  29. package/dist/payloads/Decomposed3DVector.js +125 -0
  30. package/dist/payloads/FlagCode.d.ts +534 -0
  31. package/dist/payloads/FlagCode.js +1885 -0
  32. package/dist/payloads/Geojson.d.ts +28 -0
  33. package/dist/payloads/Geojson.js +110 -0
  34. package/dist/payloads/LocationFixQuality.d.ts +59 -0
  35. package/dist/payloads/LocationFixQuality.js +205 -0
  36. package/dist/payloads/NetworkStatus.d.ts +36 -0
  37. package/dist/payloads/NetworkStatus.js +207 -0
  38. package/dist/payloads/Primitives.d.ts +84 -0
  39. package/dist/payloads/Primitives.js +787 -0
  40. package/dist/payloads/ROCStatus.d.ts +42 -0
  41. package/dist/payloads/ROCStatus.js +225 -0
  42. package/dist/payloads/RadarReading.d.ts +46 -0
  43. package/dist/payloads/RadarReading.js +276 -0
  44. package/dist/payloads/SensorStatus.d.ts +39 -0
  45. package/dist/payloads/SensorStatus.js +164 -0
  46. package/dist/payloads/SimulationStatus.d.ts +45 -0
  47. package/dist/payloads/SimulationStatus.js +212 -0
  48. package/dist/payloads/TargetType.d.ts +38 -0
  49. package/dist/payloads/TargetType.js +153 -0
  50. package/dist/payloads/VesselNavStatus.d.ts +55 -0
  51. package/dist/payloads/VesselNavStatus.js +238 -0
  52. package/dist/payloads/VesselType.d.ts +133 -0
  53. package/dist/payloads/VesselType.js +729 -0
  54. package/dist/payloads/foxglove/ArrowPrimitive.d.ts +40 -0
  55. package/dist/payloads/foxglove/ArrowPrimitive.js +155 -0
  56. package/dist/payloads/foxglove/CameraCalibration.d.ts +90 -0
  57. package/dist/payloads/foxglove/CameraCalibration.js +259 -0
  58. package/dist/payloads/foxglove/CircleAnnotation.d.ts +43 -0
  59. package/dist/payloads/foxglove/CircleAnnotation.js +183 -0
  60. package/dist/payloads/foxglove/Color.d.ts +34 -0
  61. package/dist/payloads/foxglove/Color.js +115 -0
  62. package/dist/payloads/foxglove/CompressedImage.d.ts +38 -0
  63. package/dist/payloads/foxglove/CompressedImage.js +162 -0
  64. package/dist/payloads/foxglove/CompressedVideo.d.ts +68 -0
  65. package/dist/payloads/foxglove/CompressedVideo.js +162 -0
  66. package/dist/payloads/foxglove/CubePrimitive.d.ts +35 -0
  67. package/dist/payloads/foxglove/CubePrimitive.js +103 -0
  68. package/dist/payloads/foxglove/CylinderPrimitive.d.ts +39 -0
  69. package/dist/payloads/foxglove/CylinderPrimitive.js +140 -0
  70. package/dist/payloads/foxglove/FrameTransform.d.ts +38 -0
  71. package/dist/payloads/foxglove/FrameTransform.js +165 -0
  72. package/dist/payloads/foxglove/FrameTransforms.d.ts +29 -0
  73. package/dist/payloads/foxglove/FrameTransforms.js +70 -0
  74. package/dist/payloads/foxglove/GeoJSON.d.ts +28 -0
  75. package/dist/payloads/foxglove/GeoJSON.js +67 -0
  76. package/dist/payloads/foxglove/Grid.d.ts +47 -0
  77. package/dist/payloads/foxglove/Grid.js +255 -0
  78. package/dist/payloads/foxglove/ImageAnnotations.d.ts +35 -0
  79. package/dist/payloads/foxglove/ImageAnnotations.js +104 -0
  80. package/dist/payloads/foxglove/KeyValuePair.d.ts +30 -0
  81. package/dist/payloads/foxglove/KeyValuePair.js +85 -0
  82. package/dist/payloads/foxglove/LaserScan.d.ts +41 -0
  83. package/dist/payloads/foxglove/LaserScan.js +212 -0
  84. package/dist/payloads/foxglove/LinePrimitive.d.ts +61 -0
  85. package/dist/payloads/foxglove/LinePrimitive.js +240 -0
  86. package/dist/payloads/foxglove/LocationFix.d.ts +50 -0
  87. package/dist/payloads/foxglove/LocationFix.js +250 -0
  88. package/dist/payloads/foxglove/Log.d.ts +50 -0
  89. package/dist/payloads/foxglove/Log.js +225 -0
  90. package/dist/payloads/foxglove/ModelPrimitive.d.ts +43 -0
  91. package/dist/payloads/foxglove/ModelPrimitive.js +199 -0
  92. package/dist/payloads/foxglove/PackedElementField.d.ts +47 -0
  93. package/dist/payloads/foxglove/PackedElementField.js +176 -0
  94. package/dist/payloads/foxglove/Point2.d.ts +30 -0
  95. package/dist/payloads/foxglove/Point2.js +85 -0
  96. package/dist/payloads/foxglove/Point3.d.ts +32 -0
  97. package/dist/payloads/foxglove/Point3.js +100 -0
  98. package/dist/payloads/foxglove/PointCloud.d.ts +40 -0
  99. package/dist/payloads/foxglove/PointCloud.js +204 -0
  100. package/dist/payloads/foxglove/PointsAnnotation.d.ts +60 -0
  101. package/dist/payloads/foxglove/PointsAnnotation.js +255 -0
  102. package/dist/payloads/foxglove/Pose.d.ts +32 -0
  103. package/dist/payloads/foxglove/Pose.js +91 -0
  104. package/dist/payloads/foxglove/PoseInFrame.d.ts +33 -0
  105. package/dist/payloads/foxglove/PoseInFrame.js +123 -0
  106. package/dist/payloads/foxglove/PosesInFrame.d.ts +33 -0
  107. package/dist/payloads/foxglove/PosesInFrame.js +123 -0
  108. package/dist/payloads/foxglove/Quaternion.d.ts +34 -0
  109. package/dist/payloads/foxglove/Quaternion.js +115 -0
  110. package/dist/payloads/foxglove/RawImage.d.ts +44 -0
  111. package/dist/payloads/foxglove/RawImage.js +216 -0
  112. package/dist/payloads/foxglove/SceneEntity.d.ts +64 -0
  113. package/dist/payloads/foxglove/SceneEntity.js +323 -0
  114. package/dist/payloads/foxglove/SceneEntityDeletion.d.ts +42 -0
  115. package/dist/payloads/foxglove/SceneEntityDeletion.js +158 -0
  116. package/dist/payloads/foxglove/SceneUpdate.d.ts +32 -0
  117. package/dist/payloads/foxglove/SceneUpdate.js +88 -0
  118. package/dist/payloads/foxglove/SpherePrimitive.d.ts +35 -0
  119. package/dist/payloads/foxglove/SpherePrimitive.js +103 -0
  120. package/dist/payloads/foxglove/TextAnnotation.d.ts +43 -0
  121. package/dist/payloads/foxglove/TextAnnotation.js +183 -0
  122. package/dist/payloads/foxglove/TextPrimitive.d.ts +40 -0
  123. package/dist/payloads/foxglove/TextPrimitive.js +155 -0
  124. package/dist/payloads/foxglove/TriangleListPrimitive.d.ts +43 -0
  125. package/dist/payloads/foxglove/TriangleListPrimitive.js +149 -0
  126. package/dist/payloads/foxglove/Vector2.d.ts +30 -0
  127. package/dist/payloads/foxglove/Vector2.js +85 -0
  128. package/dist/payloads/foxglove/Vector3.d.ts +32 -0
  129. package/dist/payloads/foxglove/Vector3.js +100 -0
  130. package/dist/payloads/google/protobuf/duration.d.ts +100 -0
  131. package/dist/payloads/google/protobuf/duration.js +95 -0
  132. package/dist/payloads/google/protobuf/timestamp.d.ts +129 -0
  133. package/dist/payloads/google/protobuf/timestamp.js +95 -0
  134. package/dist/payloads/index.d.ts +3 -0
  135. package/dist/payloads/index.foxglove.d.ts +38 -0
  136. package/dist/payloads/index.foxglove.js +59 -0
  137. package/dist/payloads/index.google.d.ts +1 -0
  138. package/dist/payloads/index.google.js +32 -0
  139. package/dist/payloads/index.google.protobuf.d.ts +2 -0
  140. package/dist/payloads/index.google.protobuf.js +23 -0
  141. package/dist/payloads/index.js +34 -0
  142. package/dist/payloads/index.keelson.d.ts +15 -0
  143. package/dist/payloads/index.keelson.js +36 -0
  144. package/dist/payloads/typeRegistry.d.ts +18 -0
  145. package/dist/payloads/typeRegistry.js +8 -0
  146. package/dist/subjects.json +146 -0
  147. package/nodes/README.md +242 -0
  148. package/nodes/keelson-decode-payload.html +79 -0
  149. package/nodes/keelson-decode-payload.js +92 -0
  150. package/nodes/keelson-enclose.html +58 -0
  151. package/nodes/keelson-enclose.js +57 -0
  152. package/nodes/keelson-encode-payload.html +79 -0
  153. package/nodes/keelson-encode-payload.js +88 -0
  154. package/nodes/keelson-uncover.html +62 -0
  155. package/nodes/keelson-uncover.js +54 -0
  156. package/nodes/nodes.test.js +542 -0
  157. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Keelson JavaScript SDK
2
+
3
+ JavaScript SDK for [Keelson](https://github.com/RISE-Maritime/keelson): a modern, open protocol for maritime and sensor data. This package provides all the tools needed to encode, decode, and manage Keelson messages and envelopes in JavaScript/TypeScript environments.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install keelson-js
11
+ ```
12
+
13
+ ---
14
+
15
+ ## SDK Usage
16
+
17
+ ### Envelope Management
18
+
19
+ ```js
20
+ import { enclose, uncover } from 'keelson-js';
21
+
22
+ // Wrap payload in envelope
23
+ const envelope = enclose(payloadBytes, Date.now());
24
+
25
+ // Unwrap envelope
26
+ const [uncoveredAt, enclosedAt, payload] = uncover(envelope);
27
+ ```
28
+
29
+ ### Payload Encoding/Decoding
30
+
31
+ ```js
32
+ import { encodePayloadFromTypeName, decodePayloadFromTypeName } from 'keelson-js';
33
+
34
+ // Encode JS object to protobuf
35
+ const bytes = encodePayloadFromTypeName('location_fix', jsObject);
36
+
37
+ // Decode protobuf to JS object
38
+ const obj = decodePayloadFromTypeName('location_fix', bytes);
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Well-Known Subjects
44
+
45
+ Keelson includes 180+ well-known subjects for maritime data types, e.g.:
46
+
47
+ - `location_fix`, `heading_true_north_deg`, `roll_deg`, `engine_throttle_pct`, `image_raw`, `video_compressed`, ...
48
+
49
+ See [`messages/subjects.yaml`](https://github.com/RISE-Maritime/keelson/blob/main/messages/subjects.yaml) for the full list.
50
+
51
+ ---
52
+
53
+ ## Naming Conventions
54
+
55
+ - Functions: `snake_case`
56
+ - Subjects: `snake_case`
57
+ - Arguments/returns match SDK:
58
+ - `enclose(payload, enclosed_at?)` → `Envelope`
59
+ - `uncover(encodedEnvelope)` → `[uncovered_at, enclosed_at, payload]`
60
+ - `encodePayloadFromTypeName(typeName, payload)` → `Uint8Array`
61
+ - `decodePayloadFromTypeName(typeName, bytes)` → `object`
62
+
63
+ ---
64
+
65
+ ## Development Setup
66
+
67
+ 1. Generate protobuf messages:
68
+ ```bash
69
+ chmod +x generate_javascript.sh
70
+ ./generate_javascript.sh
71
+ ```
72
+ 2. Run tests:
73
+ ```bash
74
+ npm install --save-dev jest @types/jest ts-jest
75
+ npx jest
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Node-RED Nodes
81
+
82
+ This package also provides Node-RED nodes for seamless integration with MQTT and Zenoh. To use in Node-RED:
83
+
84
+ ```bash
85
+ cd ~/.node-red
86
+ npm install keelson-js
87
+ ```
88
+ Restart Node-RED. The Keelson nodes will appear in the palette under the "keelson" category.
89
+
90
+ ### Available Nodes
91
+
92
+ - **keelson-enclose**: Wraps payload bytes in a Keelson Envelope protobuf message with a timestamp.
93
+ - **keelson-uncover**: Extracts payload bytes and timestamps from a Keelson Envelope protobuf message.
94
+ - **keelson-encode-payload**: Encodes a JavaScript object to protobuf bytes using a Keelson subject.
95
+ - **keelson-decode-payload**: Decodes protobuf bytes to a JavaScript object using a Keelson subject.
96
+
97
+ #### Node-RED Example Flows
98
+
99
+ **Publishing a Keelson Message:**
100
+ ```
101
+ [Inject] --> [Function: Create Data] --> [keelson-encode-payload] --> [keelson-enclose] --> [MQTT Out or zenoh-put]
102
+ ```
103
+ Function node example:
104
+ ```js
105
+ msg.payload = {
106
+ latitude: 57.7089,
107
+ longitude: 11.9746,
108
+ altitude: 10.5
109
+ };
110
+ msg.topic = "vessel/@v0/123/pubsub/location_fix/gps";
111
+ return msg;
112
+ ```
113
+
114
+ **Subscribing to a Keelson Message:**
115
+ ```
116
+ [MQTT In or zenoh-subscribe] --> [keelson-uncover] --> [keelson-decode-payload] --> [Debug]
117
+ ```
118
+
119
+
120
+ #### Connectivity: Zenoh (Recommended) & MQTT
121
+
122
+ - **Zenoh (Recommended):** Use [`@freol35241/nodered-contrib-zenoh`](https://github.com/freol35241/nodered-contrib-zenoh) for direct, native Zenoh protocol support. Buffers are handled natively by Zenoh nodes, and you get access to Zenoh features like queries and attachments without needing a bridge.
123
+ - **MQTT (Alternative):** You can also use Node-RED MQTT nodes with [zenoh-plugin-mqtt](https://github.com/eclipse-zenoh/zenoh-plugin-mqtt) as a bridge to Zenoh networks. Buffers are handled natively by MQTT nodes.
124
+
125
+ #### Subject Extraction from Topics
126
+
127
+ `keelson-encode-payload` and `keelson-decode-payload` can extract the subject from `msg.topic` if it matches:
128
+ ```
129
+ {base_path}/@v0/{entity_id}/pubsub/{subject}/{source_id}
130
+ ```
131
+ E.g., from `vessel/@v0/123/pubsub/location_fix/gps`, the subject is `location_fix`.
132
+
133
+ #### Passthrough Behavior
134
+
135
+ All Keelson nodes pass through unused message properties, preserving metadata like timestamps, entity IDs, and custom fields.
136
+
137
+ ---
138
+
139
+ ## License
140
+
141
+ Apache-2.0
@@ -0,0 +1,37 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ export declare const protobufPackage = "core";
3
+ export interface Envelope {
4
+ /** Timestamp when this envelope was enclosed */
5
+ enclosedAt: Date | undefined;
6
+ /** The payload should be a protobuf message specified in the payload folder */
7
+ payload: Uint8Array;
8
+ }
9
+ export interface KeyEnvelopePair {
10
+ /** Timestamp when this KeyEnvelopePair was created */
11
+ timestamp: Date | undefined;
12
+ /** The key associated with this KeyEnvelopePair */
13
+ key: string;
14
+ /** The key associated with this KeyEnvelopePair */
15
+ envelope: Uint8Array;
16
+ }
17
+ export declare const Envelope: MessageFns<Envelope>;
18
+ export declare const KeyEnvelopePair: MessageFns<KeyEnvelopePair>;
19
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
20
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
21
+ [K in keyof T]?: DeepPartial<T[K]>;
22
+ } : Partial<T>;
23
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
24
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
25
+ [K in keyof P]: Exact<P[K], I[K]>;
26
+ } & {
27
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
28
+ };
29
+ export interface MessageFns<T> {
30
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
31
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
32
+ fromJSON(object: any): T;
33
+ toJSON(message: T): unknown;
34
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
35
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
36
+ }
37
+ export {};
@@ -0,0 +1,212 @@
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 v6.30.2
6
+ // source: Envelope.proto
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.KeyEnvelopePair = exports.Envelope = exports.protobufPackage = void 0;
9
+ /* eslint-disable */
10
+ const wire_1 = require("@bufbuild/protobuf/wire");
11
+ const timestamp_1 = require("./google/protobuf/timestamp");
12
+ exports.protobufPackage = "core";
13
+ function createBaseEnvelope() {
14
+ return { enclosedAt: undefined, payload: new Uint8Array(0) };
15
+ }
16
+ exports.Envelope = {
17
+ encode(message, writer = new wire_1.BinaryWriter()) {
18
+ if (message.enclosedAt !== undefined) {
19
+ timestamp_1.Timestamp.encode(toTimestamp(message.enclosedAt), writer.uint32(10).fork()).join();
20
+ }
21
+ if (message.payload.length !== 0) {
22
+ writer.uint32(18).bytes(message.payload);
23
+ }
24
+ return writer;
25
+ },
26
+ decode(input, length) {
27
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
28
+ let end = length === undefined ? reader.len : reader.pos + length;
29
+ const message = createBaseEnvelope();
30
+ while (reader.pos < end) {
31
+ const tag = reader.uint32();
32
+ switch (tag >>> 3) {
33
+ case 1: {
34
+ if (tag !== 10) {
35
+ break;
36
+ }
37
+ message.enclosedAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
38
+ continue;
39
+ }
40
+ case 2: {
41
+ if (tag !== 18) {
42
+ break;
43
+ }
44
+ message.payload = reader.bytes();
45
+ continue;
46
+ }
47
+ }
48
+ if ((tag & 7) === 4 || tag === 0) {
49
+ break;
50
+ }
51
+ reader.skip(tag & 7);
52
+ }
53
+ return message;
54
+ },
55
+ fromJSON(object) {
56
+ return {
57
+ enclosedAt: isSet(object.enclosedAt) ? fromJsonTimestamp(object.enclosedAt) : undefined,
58
+ payload: isSet(object.payload) ? bytesFromBase64(object.payload) : new Uint8Array(0),
59
+ };
60
+ },
61
+ toJSON(message) {
62
+ const obj = {};
63
+ if (message.enclosedAt !== undefined) {
64
+ obj.enclosedAt = message.enclosedAt.toISOString();
65
+ }
66
+ if (message.payload.length !== 0) {
67
+ obj.payload = base64FromBytes(message.payload);
68
+ }
69
+ return obj;
70
+ },
71
+ create(base) {
72
+ return exports.Envelope.fromPartial(base ?? {});
73
+ },
74
+ fromPartial(object) {
75
+ const message = createBaseEnvelope();
76
+ message.enclosedAt = object.enclosedAt ?? undefined;
77
+ message.payload = object.payload ?? new Uint8Array(0);
78
+ return message;
79
+ },
80
+ };
81
+ function createBaseKeyEnvelopePair() {
82
+ return { timestamp: undefined, key: "", envelope: new Uint8Array(0) };
83
+ }
84
+ exports.KeyEnvelopePair = {
85
+ encode(message, writer = new wire_1.BinaryWriter()) {
86
+ if (message.timestamp !== undefined) {
87
+ timestamp_1.Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join();
88
+ }
89
+ if (message.key !== "") {
90
+ writer.uint32(18).string(message.key);
91
+ }
92
+ if (message.envelope.length !== 0) {
93
+ writer.uint32(26).bytes(message.envelope);
94
+ }
95
+ return writer;
96
+ },
97
+ decode(input, length) {
98
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
99
+ let end = length === undefined ? reader.len : reader.pos + length;
100
+ const message = createBaseKeyEnvelopePair();
101
+ while (reader.pos < end) {
102
+ const tag = reader.uint32();
103
+ switch (tag >>> 3) {
104
+ case 1: {
105
+ if (tag !== 10) {
106
+ break;
107
+ }
108
+ message.timestamp = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
109
+ continue;
110
+ }
111
+ case 2: {
112
+ if (tag !== 18) {
113
+ break;
114
+ }
115
+ message.key = reader.string();
116
+ continue;
117
+ }
118
+ case 3: {
119
+ if (tag !== 26) {
120
+ break;
121
+ }
122
+ message.envelope = reader.bytes();
123
+ continue;
124
+ }
125
+ }
126
+ if ((tag & 7) === 4 || tag === 0) {
127
+ break;
128
+ }
129
+ reader.skip(tag & 7);
130
+ }
131
+ return message;
132
+ },
133
+ fromJSON(object) {
134
+ return {
135
+ timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined,
136
+ key: isSet(object.key) ? globalThis.String(object.key) : "",
137
+ envelope: isSet(object.envelope) ? bytesFromBase64(object.envelope) : new Uint8Array(0),
138
+ };
139
+ },
140
+ toJSON(message) {
141
+ const obj = {};
142
+ if (message.timestamp !== undefined) {
143
+ obj.timestamp = message.timestamp.toISOString();
144
+ }
145
+ if (message.key !== "") {
146
+ obj.key = message.key;
147
+ }
148
+ if (message.envelope.length !== 0) {
149
+ obj.envelope = base64FromBytes(message.envelope);
150
+ }
151
+ return obj;
152
+ },
153
+ create(base) {
154
+ return exports.KeyEnvelopePair.fromPartial(base ?? {});
155
+ },
156
+ fromPartial(object) {
157
+ const message = createBaseKeyEnvelopePair();
158
+ message.timestamp = object.timestamp ?? undefined;
159
+ message.key = object.key ?? "";
160
+ message.envelope = object.envelope ?? new Uint8Array(0);
161
+ return message;
162
+ },
163
+ };
164
+ function bytesFromBase64(b64) {
165
+ if (globalThis.Buffer) {
166
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
167
+ }
168
+ else {
169
+ const bin = globalThis.atob(b64);
170
+ const arr = new Uint8Array(bin.length);
171
+ for (let i = 0; i < bin.length; ++i) {
172
+ arr[i] = bin.charCodeAt(i);
173
+ }
174
+ return arr;
175
+ }
176
+ }
177
+ function base64FromBytes(arr) {
178
+ if (globalThis.Buffer) {
179
+ return globalThis.Buffer.from(arr).toString("base64");
180
+ }
181
+ else {
182
+ const bin = [];
183
+ arr.forEach((byte) => {
184
+ bin.push(globalThis.String.fromCharCode(byte));
185
+ });
186
+ return globalThis.btoa(bin.join(""));
187
+ }
188
+ }
189
+ function toTimestamp(date) {
190
+ const seconds = Math.trunc(date.getTime() / 1000);
191
+ const nanos = (date.getTime() % 1000) * 1000000;
192
+ return { seconds, nanos };
193
+ }
194
+ function fromTimestamp(t) {
195
+ let millis = (t.seconds || 0) * 1000;
196
+ millis += (t.nanos || 0) / 1000000;
197
+ return new globalThis.Date(millis);
198
+ }
199
+ function fromJsonTimestamp(o) {
200
+ if (o instanceof globalThis.Date) {
201
+ return o;
202
+ }
203
+ else if (typeof o === "string") {
204
+ return new globalThis.Date(o);
205
+ }
206
+ else {
207
+ return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
208
+ }
209
+ }
210
+ function isSet(value) {
211
+ return value !== null && value !== undefined;
212
+ }
@@ -0,0 +1,128 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ export declare const protobufPackage = "google.protobuf";
3
+ /**
4
+ * A Timestamp represents a point in time independent of any time zone or local
5
+ * calendar, encoded as a count of seconds and fractions of seconds at
6
+ * nanosecond resolution. The count is relative to an epoch at UTC midnight on
7
+ * January 1, 1970, in the proleptic Gregorian calendar which extends the
8
+ * Gregorian calendar backwards to year one.
9
+ *
10
+ * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
11
+ * second table is needed for interpretation, using a [24-hour linear
12
+ * smear](https://developers.google.com/time/smear).
13
+ *
14
+ * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
15
+ * restricting to that range, we ensure that we can convert to and from [RFC
16
+ * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
17
+ *
18
+ * # Examples
19
+ *
20
+ * Example 1: Compute Timestamp from POSIX `time()`.
21
+ *
22
+ * Timestamp timestamp;
23
+ * timestamp.set_seconds(time(NULL));
24
+ * timestamp.set_nanos(0);
25
+ *
26
+ * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
27
+ *
28
+ * struct timeval tv;
29
+ * gettimeofday(&tv, NULL);
30
+ *
31
+ * Timestamp timestamp;
32
+ * timestamp.set_seconds(tv.tv_sec);
33
+ * timestamp.set_nanos(tv.tv_usec * 1000);
34
+ *
35
+ * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
36
+ *
37
+ * FILETIME ft;
38
+ * GetSystemTimeAsFileTime(&ft);
39
+ * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
40
+ *
41
+ * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
42
+ * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
43
+ * Timestamp timestamp;
44
+ * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
45
+ * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
46
+ *
47
+ * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
48
+ *
49
+ * long millis = System.currentTimeMillis();
50
+ *
51
+ * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
52
+ * .setNanos((int) ((millis % 1000) * 1000000)).build();
53
+ *
54
+ * Example 5: Compute Timestamp from Java `Instant.now()`.
55
+ *
56
+ * Instant now = Instant.now();
57
+ *
58
+ * Timestamp timestamp =
59
+ * Timestamp.newBuilder().setSeconds(now.getEpochSecond())
60
+ * .setNanos(now.getNano()).build();
61
+ *
62
+ * Example 6: Compute Timestamp from current time in Python.
63
+ *
64
+ * timestamp = Timestamp()
65
+ * timestamp.GetCurrentTime()
66
+ *
67
+ * # JSON Mapping
68
+ *
69
+ * In JSON format, the Timestamp type is encoded as a string in the
70
+ * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
71
+ * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
72
+ * where {year} is always expressed using four digits while {month}, {day},
73
+ * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
74
+ * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
75
+ * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
76
+ * is required. A proto3 JSON serializer should always use UTC (as indicated by
77
+ * "Z") when printing the Timestamp type and a proto3 JSON parser should be
78
+ * able to accept both UTC and other timezones (as indicated by an offset).
79
+ *
80
+ * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
81
+ * 01:30 UTC on January 15, 2017.
82
+ *
83
+ * In JavaScript, one can convert a Date object to this format using the
84
+ * standard
85
+ * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
86
+ * method. In Python, a standard `datetime.datetime` object can be converted
87
+ * to this format using
88
+ * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
89
+ * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
90
+ * the Joda Time's [`ISODateTimeFormat.dateTime()`](
91
+ * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
92
+ * ) to obtain a formatter capable of generating timestamps in this format.
93
+ */
94
+ export interface Timestamp {
95
+ /**
96
+ * Represents seconds of UTC time since Unix epoch
97
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
98
+ * 9999-12-31T23:59:59Z inclusive.
99
+ */
100
+ seconds: number;
101
+ /**
102
+ * Non-negative fractions of a second at nanosecond resolution. Negative
103
+ * second values with fractions must still have non-negative nanos values
104
+ * that count forward in time. Must be from 0 to 999,999,999
105
+ * inclusive.
106
+ */
107
+ nanos: number;
108
+ }
109
+ export declare const Timestamp: MessageFns<Timestamp>;
110
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
111
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
112
+ [K in keyof T]?: DeepPartial<T[K]>;
113
+ } : Partial<T>;
114
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
115
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
116
+ [K in keyof P]: Exact<P[K], I[K]>;
117
+ } & {
118
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
119
+ };
120
+ export interface MessageFns<T> {
121
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
122
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
123
+ fromJSON(object: any): T;
124
+ toJSON(message: T): unknown;
125
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
126
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
127
+ }
128
+ export {};
@@ -0,0 +1,92 @@
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 v6.30.2
6
+ // source: google/protobuf/timestamp.proto
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Timestamp = exports.protobufPackage = void 0;
9
+ /* eslint-disable */
10
+ const wire_1 = require("@bufbuild/protobuf/wire");
11
+ exports.protobufPackage = "google.protobuf";
12
+ function createBaseTimestamp() {
13
+ return { seconds: 0, nanos: 0 };
14
+ }
15
+ exports.Timestamp = {
16
+ encode(message, writer = new wire_1.BinaryWriter()) {
17
+ if (message.seconds !== 0) {
18
+ writer.uint32(8).int64(message.seconds);
19
+ }
20
+ if (message.nanos !== 0) {
21
+ writer.uint32(16).int32(message.nanos);
22
+ }
23
+ return writer;
24
+ },
25
+ decode(input, length) {
26
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
27
+ let end = length === undefined ? reader.len : reader.pos + length;
28
+ const message = createBaseTimestamp();
29
+ while (reader.pos < end) {
30
+ const tag = reader.uint32();
31
+ switch (tag >>> 3) {
32
+ case 1: {
33
+ if (tag !== 8) {
34
+ break;
35
+ }
36
+ message.seconds = longToNumber(reader.int64());
37
+ continue;
38
+ }
39
+ case 2: {
40
+ if (tag !== 16) {
41
+ break;
42
+ }
43
+ message.nanos = reader.int32();
44
+ continue;
45
+ }
46
+ }
47
+ if ((tag & 7) === 4 || tag === 0) {
48
+ break;
49
+ }
50
+ reader.skip(tag & 7);
51
+ }
52
+ return message;
53
+ },
54
+ fromJSON(object) {
55
+ return {
56
+ seconds: isSet(object.seconds) ? globalThis.Number(object.seconds) : 0,
57
+ nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0,
58
+ };
59
+ },
60
+ toJSON(message) {
61
+ const obj = {};
62
+ if (message.seconds !== 0) {
63
+ obj.seconds = Math.round(message.seconds);
64
+ }
65
+ if (message.nanos !== 0) {
66
+ obj.nanos = Math.round(message.nanos);
67
+ }
68
+ return obj;
69
+ },
70
+ create(base) {
71
+ return exports.Timestamp.fromPartial(base ?? {});
72
+ },
73
+ fromPartial(object) {
74
+ const message = createBaseTimestamp();
75
+ message.seconds = object.seconds ?? 0;
76
+ message.nanos = object.nanos ?? 0;
77
+ return message;
78
+ },
79
+ };
80
+ function longToNumber(int64) {
81
+ const num = globalThis.Number(int64.toString());
82
+ if (num > globalThis.Number.MAX_SAFE_INTEGER) {
83
+ throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
84
+ }
85
+ if (num < globalThis.Number.MIN_SAFE_INTEGER) {
86
+ throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
87
+ }
88
+ return num;
89
+ }
90
+ function isSet(value) {
91
+ return value !== null && value !== undefined;
92
+ }
@@ -0,0 +1,16 @@
1
+ import { Envelope } from './Envelope';
2
+ import { MessageType } from './payloads/typeRegistry';
3
+ import './payloads';
4
+ export declare function construct_pubSub_key(base_path: string, entityId: string, subject: string, sourceId: string): string;
5
+ export declare function construct_rpc_key(base_path: string, entityId: string, procedure: string, sourceId: string): string;
6
+ export declare function parse_pubsub_key(key: string): Record<string, string>;
7
+ export declare function parse_rpc_key(key: string): Record<string, string>;
8
+ export declare function get_subject_from_pubsub_key(key: string): string;
9
+ export declare function enclose(payload: Uint8Array, enclosed_at?: Date): Envelope;
10
+ export declare function uncover(encodedEnvelope: Uint8Array): [Date, Date | undefined, Uint8Array] | undefined;
11
+ export declare function isSubjectWellKnown(subject: string): boolean;
12
+ export declare function getSubjectSchema(subject: string): string | undefined;
13
+ export declare function getProtobufClassFromTypeName(typeName: string): MessageType<import("./payloads/typeRegistry").UnknownMessage> | undefined;
14
+ export declare function decodePayloadFromTypeName(typeName: string, payload: Uint8Array): import("./payloads/typeRegistry").UnknownMessage | undefined;
15
+ export declare function encodePayloadFromTypeName(typeName: string, payload: any): Uint8Array | undefined;
16
+ export declare function encloseFromTypeName(typeName: string, payloadValue: any): Envelope | undefined;