@databricks/zerobus-ingest-sdk 1.0.1 → 1.0.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.
package/Cargo.lock CHANGED
@@ -2889,7 +2889,7 @@ dependencies = [
2889
2889
 
2890
2890
  [[package]]
2891
2891
  name = "zerobus-sdk-ts"
2892
- version = "1.0.1"
2892
+ version = "1.0.2"
2893
2893
  dependencies = [
2894
2894
  "arrow-array",
2895
2895
  "arrow-ipc",
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "zerobus-sdk-ts"
3
- version = "1.0.1"
3
+ version = "1.0.2"
4
4
  authors = ["Databricks"]
5
5
  edition = "2021"
6
6
  license = "Apache-2.0"
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,40 @@
1
+ Copyright (2025) Databricks, Inc.
2
+
3
+ This Software includes software developed at Databricks (https://www.databricks.com/) and its use is subject to the included LICENSE file.
4
+
5
+ ---
6
+
7
+ This Software includes the following open source components:
8
+
9
+ ## Rust Dependencies
10
+
11
+ ### MIT License
12
+
13
+ - **napi**: Copyright (c) 2020 LongYinan (https://github.com/napi-rs/napi-rs)
14
+ - **napi-derive**: Copyright (c) 2020 LongYinan (https://github.com/napi-rs/napi-rs)
15
+ - **tokio**: Copyright (c) 2019 Tokio Contributors (https://github.com/tokio-rs/tokio)
16
+ - **serde**: Copyright (c) 2014 David Tolnay (https://github.com/serde-rs/serde)
17
+ - **serde_json**: Copyright (c) 2014 David Tolnay (https://github.com/serde-rs/json)
18
+ - **thiserror**: Copyright (c) 2019 David Tolnay (https://github.com/dtolnay/thiserror)
19
+ - **async-trait**: Copyright (c) 2019 David Tolnay (https://github.com/dtolnay/async-trait)
20
+
21
+ ### Apache License 2.0
22
+
23
+ - **prost**: Copyright (c) 2017 Dan Burkert (https://github.com/tokio-rs/prost)
24
+ - **prost-types**: Copyright (c) 2017 Dan Burkert (https://github.com/tokio-rs/prost)
25
+ - **base64**: Copyright (c) 2015 Alice Maz and Marshall Pierce (https://github.com/marshallpierce/rust-base64)
26
+
27
+ ### Optional: Arrow Flight support (Apache License 2.0)
28
+
29
+ These components are only included when the `arrow-flight` feature is enabled:
30
+
31
+ - **arrow-array**: Copyright (c) 2020 Apache Arrow contributors (https://github.com/apache/arrow-rs)
32
+ - **arrow-schema**: Copyright (c) 2020 Apache Arrow contributors (https://github.com/apache/arrow-rs)
33
+ - **arrow-ipc**: Copyright (c) 2020 Apache Arrow contributors (https://github.com/apache/arrow-rs)
34
+
35
+ ## JavaScript Peer Dependencies (optional, user-supplied)
36
+
37
+ - **protobufjs**: Copyright (c) 2016 Daniel Wirtz (https://github.com/protobufjs/protobuf.js) — BSD 3-Clause
38
+ - **apache-arrow**: Copyright (c) 2020 Apache Arrow contributors (https://github.com/apache/arrow-js) — Apache License 2.0
39
+
40
+ For a complete list of dependencies and their licenses, see `Cargo.toml` and `package.json`.
package/README.md CHANGED
@@ -1177,4 +1177,4 @@ This is an open source project. We welcome contributions, feedback, and bug repo
1177
1177
 
1178
1178
  ## License
1179
1179
 
1180
- This SDK is licensed under the Apache License 2.0. See the [LICENSE](https://github.com/databricks/zerobus-sdk/blob/main/LICENSE) file for the full license text.
1180
+ This SDK is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for the full text.
package/index.d.ts CHANGED
@@ -1 +1,485 @@
1
- export { }
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ /**
7
+ * Record serialization format.
8
+ *
9
+ * Specifies how records should be encoded when ingested into the stream.
10
+ */
11
+ export const enum RecordType {
12
+ /** JSON encoding - records are JSON-encoded strings */
13
+ Json = 0,
14
+ /** Protocol Buffers encoding - records are binary protobuf messages */
15
+ Proto = 1
16
+ }
17
+ /**
18
+ * Configuration options for the Zerobus stream.
19
+ *
20
+ * These options control stream behavior including recovery, timeouts, and inflight limits.
21
+ */
22
+ export interface StreamConfigurationOptions {
23
+ /**
24
+ * Maximum number of unacknowledged requests that can be in flight.
25
+ * Default: 10,000
26
+ */
27
+ maxInflightRequests?: number
28
+ /**
29
+ * Enable automatic stream recovery on transient failures.
30
+ * Default: true
31
+ */
32
+ recovery?: boolean
33
+ /**
34
+ * Timeout for recovery operations in milliseconds.
35
+ * Default: 15,000 (15 seconds)
36
+ */
37
+ recoveryTimeoutMs?: number
38
+ /**
39
+ * Delay between recovery retry attempts in milliseconds.
40
+ * Default: 2,000 (2 seconds)
41
+ */
42
+ recoveryBackoffMs?: number
43
+ /**
44
+ * Maximum number of recovery attempts before giving up.
45
+ * Default: 4
46
+ */
47
+ recoveryRetries?: number
48
+ /**
49
+ * Timeout for flush operations in milliseconds.
50
+ * Default: 300,000 (5 minutes)
51
+ */
52
+ flushTimeoutMs?: number
53
+ /**
54
+ * Timeout waiting for server acknowledgments in milliseconds.
55
+ * Default: 60,000 (1 minute)
56
+ */
57
+ serverLackOfAckTimeoutMs?: number
58
+ /**
59
+ * Record serialization format.
60
+ * Use RecordType.Json for JSON encoding or RecordType.Proto for Protocol Buffers.
61
+ * Default: RecordType.Proto (Protocol Buffers)
62
+ */
63
+ recordType?: number
64
+ /**
65
+ * Maximum wait time during graceful stream close in milliseconds.
66
+ * When the server signals stream closure, this controls how long to wait
67
+ * for in-flight records to be acknowledged.
68
+ * - None (undefined): Wait for full server-specified duration
69
+ * - Some(0): Immediately trigger recovery without waiting
70
+ * - Some(x): Wait up to min(x, server_duration) milliseconds
71
+ * Default: None (wait for full server duration)
72
+ */
73
+ streamPausedMaxWaitTimeMs?: number
74
+ }
75
+ /**
76
+ * Properties of the target Delta table for ingestion.
77
+ *
78
+ * Specifies which Unity Catalog table to write to and optionally the schema descriptor
79
+ * for Protocol Buffers encoding.
80
+ */
81
+ export interface TableProperties {
82
+ /** Full table name in Unity Catalog (e.g., "catalog.schema.table") */
83
+ tableName: string
84
+ /**
85
+ * Optional Protocol Buffer descriptor as a base64-encoded string.
86
+ * If not provided, JSON encoding will be used.
87
+ */
88
+ descriptorProto?: string
89
+ }
90
+ /**
91
+ * JavaScript headers provider callback wrapper.
92
+ *
93
+ * Allows TypeScript code to provide custom authentication headers
94
+ * by implementing a getHeaders() function.
95
+ */
96
+ export interface JsHeadersProvider {
97
+ /** JavaScript function: () => Promise<Array<[string, string]>> */
98
+ getHeadersCallback: (...args: any[]) => any
99
+ }
100
+ /**
101
+ * Custom error type for Zerobus operations.
102
+ *
103
+ * This error type includes information about whether the error is retryable,
104
+ * which helps determine if automatic recovery can resolve the issue.
105
+ */
106
+ export declare class ZerobusError {
107
+ /** Returns true if this error can be automatically retried by the SDK. */
108
+ get isRetryable(): boolean
109
+ /** Get the error message. */
110
+ get message(): string
111
+ }
112
+ /**
113
+ * A stream for ingesting data into a Databricks Delta table.
114
+ *
115
+ * The stream manages a bidirectional gRPC connection, handles acknowledgments,
116
+ * and provides automatic recovery on transient failures.
117
+ *
118
+ * # Example
119
+ *
120
+ * ```typescript
121
+ * const stream = await sdk.createStream(tableProps, clientId, clientSecret, options);
122
+ * const ackPromise = await stream.ingestRecord(Buffer.from([1, 2, 3]));
123
+ * const offset = await ackPromise;
124
+ * await stream.close();
125
+ * ```
126
+ */
127
+ export declare class ZerobusStream {
128
+ /**
129
+ * Ingests a single record into the stream.
130
+ *
131
+ * **@deprecated** Use `ingestRecordOffset()` instead, which returns the offset directly
132
+ * after queuing. Then use `waitForOffset()` to wait for acknowledgment when needed.
133
+ *
134
+ * This method accepts either:
135
+ * - A Protocol Buffer encoded record as a Buffer (Vec<u8>)
136
+ * - A JSON string
137
+ *
138
+ * This method BLOCKS until the record is sent to the SDK's internal landing zone,
139
+ * then returns a Promise for the server acknowledgment. This allows you to send
140
+ * many records immediately without waiting for acknowledgments:
141
+ *
142
+ * ```typescript
143
+ * let lastAckPromise;
144
+ * for (let i = 0; i < 1000; i++) {
145
+ * // This call blocks until record is sent (in SDK)
146
+ * lastAckPromise = stream.ingestRecord(record);
147
+ * }
148
+ * // All 1000 records are now in the SDK's internal queue
149
+ * // Wait for the last acknowledgment
150
+ * await lastAckPromise;
151
+ * // Flush to ensure all records are acknowledged
152
+ * await stream.flush();
153
+ * ```
154
+ *
155
+ * # Arguments
156
+ *
157
+ * * `payload` - The record data. Accepts:
158
+ * - Buffer (low-level proto bytes)
159
+ * - string (low-level JSON string)
160
+ * - Protobuf message object with .encode() method (high-level, auto-serializes)
161
+ * - Plain JavaScript object (high-level, auto-stringifies to JSON)
162
+ *
163
+ * # Returns
164
+ *
165
+ * A Promise that resolves to the offset ID when the server acknowledges the record.
166
+ */
167
+ ingestRecord(payload: unknown): Promise<bigint>
168
+ /**
169
+ * Ingests multiple records as a single atomic batch.
170
+ *
171
+ * **@deprecated** Use `ingestRecordsOffset()` instead, which returns the offset directly
172
+ * after queuing. Then use `waitForOffset()` to wait for acknowledgment when needed.
173
+ *
174
+ * This method accepts an array of records (Protocol Buffer buffers or JSON strings)
175
+ * and ingests them as a batch. The batch receives a single acknowledgment from
176
+ * the server with all-or-nothing semantics.
177
+ *
178
+ * Similar to ingestRecord(), this BLOCKS until the batch is sent to the SDK's
179
+ * internal landing zone, then returns a Promise for the server acknowledgment.
180
+ *
181
+ * # Arguments
182
+ *
183
+ * * `records` - Array of record data (Buffer for protobuf, string for JSON)
184
+ *
185
+ * # Returns
186
+ *
187
+ * Promise resolving to:
188
+ * - `bigint`: offset ID for non-empty batches
189
+ * - `null`: for empty batches
190
+ *
191
+ * # Example
192
+ *
193
+ * ```typescript
194
+ * const buffers = records.map(r => Buffer.from(encode(r)));
195
+ * const offsetId = await stream.ingestRecords(buffers);
196
+ *
197
+ * if (offsetId !== null) {
198
+ * console.log('Batch acknowledged at offset:', offsetId);
199
+ * }
200
+ * ```
201
+ */
202
+ ingestRecords(records: Array<unknown>): Promise<bigint | null>
203
+ /**
204
+ * Ingests a single record and returns a future that resolves to the offset ID after queuing.
205
+ *
206
+ * Unlike `ingestRecord()`, this method's Promise resolves immediately after
207
+ * the record is queued, without waiting for server acknowledgment. Use
208
+ * `waitForOffset()` to wait for acknowledgment when needed.
209
+ *
210
+ * This is the recommended API for high-throughput scenarios where you want to
211
+ * decouple record ingestion from acknowledgment tracking.
212
+ *
213
+ * # Arguments
214
+ *
215
+ * * `payload` - The record data (Buffer, string, protobuf message, or plain object)
216
+ *
217
+ * # Returns
218
+ *
219
+ * `Promise<bigint>` - Resolves to the offset ID immediately after the record is queued
220
+ * (does not wait for server acknowledgment).
221
+ *
222
+ * # Example
223
+ *
224
+ * ```typescript
225
+ * // Promise resolves immediately with offset (before server ack)
226
+ * const offset1 = await stream.ingestRecordOffset(record1);
227
+ * const offset2 = await stream.ingestRecordOffset(record2);
228
+ * // Wait for both to be acknowledged
229
+ * await stream.waitForOffset(offset2);
230
+ * ```
231
+ */
232
+ ingestRecordOffset(payload: unknown): Promise<bigint>
233
+ /**
234
+ * Ingests multiple records as a batch and returns a future that resolves to the offset ID after queuing.
235
+ *
236
+ * Unlike `ingestRecords()`, this method's Promise resolves immediately after
237
+ * the batch is queued, without waiting for server acknowledgment. Use
238
+ * `waitForOffset()` to wait for acknowledgment when needed.
239
+ *
240
+ * # Arguments
241
+ *
242
+ * * `records` - Array of record data
243
+ *
244
+ * # Returns
245
+ *
246
+ * `Promise<bigint | null>` - Resolves to the offset ID immediately after the batch
247
+ * is queued (does not wait for server acknowledgment). Returns null for empty batches.
248
+ *
249
+ * # Example
250
+ *
251
+ * ```typescript
252
+ * // Promise resolves immediately with offset (before server ack)
253
+ * const offset = await stream.ingestRecordsOffset(batch);
254
+ * if (offset !== null) {
255
+ * await stream.waitForOffset(offset);
256
+ * }
257
+ * ```
258
+ */
259
+ ingestRecordsOffset(records: Array<unknown>): Promise<bigint | null>
260
+ /**
261
+ * Waits for a specific offset to be acknowledged by the server.
262
+ *
263
+ * Use this method with `ingestRecordOffset()` and `ingestRecordsOffset()` to
264
+ * selectively wait for acknowledgments. This allows you to ingest many records
265
+ * quickly and then wait only for specific offsets when needed.
266
+ *
267
+ * # Arguments
268
+ *
269
+ * * `offset_id` - The offset ID to wait for (returned by ingestRecordOffset/ingestRecordsOffset)
270
+ *
271
+ * # Errors
272
+ *
273
+ * - Timeout if acknowledgment takes too long
274
+ * - Server errors propagated immediately (no waiting for timeout)
275
+ *
276
+ * # Example
277
+ *
278
+ * ```typescript
279
+ * const offsets = [];
280
+ * for (const record of records) {
281
+ * offsets.push(await stream.ingestRecordOffset(record));
282
+ * }
283
+ * // Wait for the last offset (implies all previous are also acknowledged)
284
+ * await stream.waitForOffset(offsets[offsets.length - 1]);
285
+ * ```
286
+ */
287
+ waitForOffset(offsetId: bigint): Promise<void>
288
+ /**
289
+ * Flushes all pending records and waits for acknowledgments.
290
+ *
291
+ * This method ensures all previously ingested records have been sent to the server
292
+ * and acknowledged. It's useful for checkpointing or ensuring data durability.
293
+ *
294
+ * # Errors
295
+ *
296
+ * - Timeout errors if flush takes longer than configured timeout
297
+ * - Network errors if the connection fails during flush
298
+ */
299
+ flush(): Promise<void>
300
+ /**
301
+ * Closes the stream gracefully.
302
+ *
303
+ * This method flushes all pending records, waits for acknowledgments, and then
304
+ * closes the underlying gRPC connection. Always call this method when done with
305
+ * the stream to ensure data integrity.
306
+ *
307
+ * # Errors
308
+ *
309
+ * - Returns an error if some records could not be acknowledged
310
+ * - Network errors during the close operation
311
+ */
312
+ close(): Promise<void>
313
+ /**
314
+ * Gets the list of unacknowledged records.
315
+ *
316
+ * This method should only be called after a stream failure to retrieve records
317
+ * that were sent but not acknowledged by the server. These records can be
318
+ * re-ingested into a new stream.
319
+ *
320
+ * # Returns
321
+ *
322
+ * An array of Buffers containing the unacknowledged record payloads.
323
+ */
324
+ getUnackedRecords(): Promise<Array<Buffer>>
325
+ /**
326
+ * Gets unacknowledged records grouped by their original batches.
327
+ *
328
+ * This preserves the batch structure from ingestion:
329
+ * - Each ingestRecord() call → 1-element batch
330
+ * - Each ingestRecords() call → N-element batch
331
+ *
332
+ * Should only be called after stream failure. All records returned as Buffers
333
+ * (JSON strings are converted to UTF-8 bytes).
334
+ *
335
+ * # Returns
336
+ *
337
+ * Array of batches, where each batch is an array of Buffers
338
+ *
339
+ * # Example
340
+ *
341
+ * ```typescript
342
+ * try {
343
+ * await stream.ingestRecords(batch1);
344
+ * await stream.ingestRecords(batch2);
345
+ * } catch (error) {
346
+ * const unackedBatches = await stream.getUnackedBatches();
347
+ *
348
+ * // Re-ingest with new stream
349
+ * for (const batch of unackedBatches) {
350
+ * await newStream.ingestRecords(batch);
351
+ * }
352
+ * }
353
+ * ```
354
+ */
355
+ getUnackedBatches(): Promise<Array<Array<Buffer>>>
356
+ }
357
+ /**
358
+ * The main SDK for interacting with the Databricks Zerobus service.
359
+ *
360
+ * This is the entry point for creating ingestion streams to Delta tables.
361
+ *
362
+ * # Example
363
+ *
364
+ * ```typescript
365
+ * const sdk = new ZerobusSdk(
366
+ * "https://workspace-id.zerobus.region.cloud.databricks.com",
367
+ * "https://workspace.cloud.databricks.com"
368
+ * );
369
+ *
370
+ * const stream = await sdk.createStream(
371
+ * { tableName: "catalog.schema.table" },
372
+ * "client-id",
373
+ * "client-secret"
374
+ * );
375
+ * ```
376
+ */
377
+ export declare class ZerobusSdk {
378
+ /**
379
+ * Creates a new Zerobus SDK instance.
380
+ *
381
+ * # Arguments
382
+ *
383
+ * * `zerobus_endpoint` - The Zerobus API endpoint URL
384
+ * (e.g., "https://workspace-id.zerobus.region.cloud.databricks.com")
385
+ * * `unity_catalog_url` - The Unity Catalog endpoint URL
386
+ * (e.g., "https://workspace.cloud.databricks.com")
387
+ *
388
+ * # Errors
389
+ *
390
+ * - Invalid endpoint URLs
391
+ * - Failed to extract workspace ID from the endpoint
392
+ */
393
+ constructor(zerobusEndpoint: string, unityCatalogUrl: string)
394
+ /**
395
+ * Creates a new ingestion stream to a Delta table.
396
+ *
397
+ * This method establishes a bidirectional gRPC connection to the Zerobus service
398
+ * and prepares it for data ingestion. By default, it uses OAuth 2.0 Client Credentials
399
+ * authentication. For custom authentication (e.g., Personal Access Tokens), provide
400
+ * a custom headers_provider.
401
+ *
402
+ * # Arguments
403
+ *
404
+ * * `table_properties` - Properties of the target table including name and optional schema
405
+ * * `client_id` - OAuth 2.0 client ID (ignored if headers_provider is provided)
406
+ * * `client_secret` - OAuth 2.0 client secret (ignored if headers_provider is provided)
407
+ * * `options` - Optional stream configuration (timeouts, recovery settings, etc.)
408
+ * * `headers_provider` - Optional custom headers provider for authentication.
409
+ * If not provided, uses OAuth with client_id and client_secret.
410
+ *
411
+ * # Returns
412
+ *
413
+ * A Promise that resolves to a ZerobusStream ready for data ingestion.
414
+ *
415
+ * # Errors
416
+ *
417
+ * - Authentication failures (invalid credentials)
418
+ * - Invalid table name or insufficient permissions
419
+ * - Network connectivity issues
420
+ * - Schema validation errors
421
+ *
422
+ * # Example
423
+ *
424
+ * ```typescript
425
+ * // OAuth authentication (default)
426
+ * const stream = await sdk.createStream(
427
+ * { tableName: "catalog.schema.table" },
428
+ * "client-id",
429
+ * "client-secret"
430
+ * );
431
+ *
432
+ * // Custom authentication with headers provider
433
+ * const stream = await sdk.createStream(
434
+ * { tableName: "catalog.schema.table" },
435
+ * "", // ignored
436
+ * "", // ignored
437
+ * undefined,
438
+ * {
439
+ * getHeadersCallback: async () => [
440
+ * ["authorization", `Bearer ${myToken}`],
441
+ * ["x-databricks-zerobus-table-name", tableName]
442
+ * ]
443
+ * }
444
+ * );
445
+ * ```
446
+ */
447
+ createStream(tableProperties: TableProperties, clientId: string, clientSecret: string, options?: StreamConfigurationOptions | undefined | null, headersProvider?: JsHeadersProvider | undefined | null): Promise<ZerobusStream>
448
+ /**
449
+ * Recreates a stream with the same configuration and re-ingests unacknowledged batches.
450
+ *
451
+ * This method is the recommended approach for recovering from stream failures. It:
452
+ * 1. Retrieves all unacknowledged batches from the failed stream
453
+ * 2. Creates a new stream with identical configuration
454
+ * 3. Re-ingests all unacknowledged batches in order
455
+ * 4. Returns the new stream ready for continued ingestion
456
+ *
457
+ * # Arguments
458
+ *
459
+ * * `stream` - The failed or closed stream to recreate
460
+ *
461
+ * # Returns
462
+ *
463
+ * A Promise that resolves to a new ZerobusStream with all unacknowledged batches re-ingested.
464
+ *
465
+ * # Errors
466
+ *
467
+ * - Failed to retrieve unacknowledged batches from the original stream
468
+ * - Authentication failures when creating the new stream
469
+ * - Network connectivity issues during re-ingestion
470
+ *
471
+ * # Examples
472
+ *
473
+ * ```typescript
474
+ * try {
475
+ * await stream.ingestRecords(batch);
476
+ * } catch (error) {
477
+ * await stream.close();
478
+ * // Recreate stream with all unacked batches re-ingested
479
+ * const newStream = await sdk.recreateStream(stream);
480
+ * // Continue ingesting with newStream
481
+ * }
482
+ * ```
483
+ */
484
+ recreateStream(stream: ZerobusStream): Promise<ZerobusStream>
485
+ }
package/index.js CHANGED
@@ -1,21 +1,318 @@
1
- if (process.platform === "linux" && process.arch === "x64") {
2
- try { module.exports = require("@databricks/zerobus-ingest-sdk-linux-x64-gnu"); } catch(e) {
3
- module.exports = require("./zerobus-ingest-sdk.linux-x64-gnu.node"); }
4
- } else
5
- if (process.platform === "linux" && process.arch === "arm64") {
6
- try { module.exports = require("@databricks/zerobus-ingest-sdk-linux-arm64-gnu"); } catch(e) {
7
- module.exports = require("./zerobus-ingest-sdk.linux-arm64-gnu.node"); }
8
- } else
9
- if (process.platform === "win32" && process.arch === "x64") {
10
- try { module.exports = require("@databricks/zerobus-ingest-sdk-win32-x64-msvc"); } catch(e) {
11
- module.exports = require("./zerobus-ingest-sdk.win32-x64-msvc.node"); }
12
- } else
13
- if (process.platform === "darwin" && process.arch === "x64") {
14
- try { module.exports = require("@databricks/zerobus-ingest-sdk-darwin-x64"); } catch(e) {
15
- module.exports = require("./zerobus-ingest-sdk.darwin-x64.node"); }
16
- } else
17
- if (process.platform === "darwin" && process.arch === "arm64") {
18
- try { module.exports = require("@databricks/zerobus-ingest-sdk-darwin-arm64"); } catch(e) {
19
- module.exports = require("./zerobus-ingest-sdk.darwin-arm64.node"); }
20
- } else
21
- { throw new Error("Unsupported platform: " + process.platform + "-" + process.arch); }
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'zerobus-ingest-sdk.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./zerobus-ingest-sdk.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'zerobus-ingest-sdk.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./zerobus-ingest-sdk.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
58
+ default:
59
+ throw new Error(`Unsupported architecture on Android ${arch}`)
60
+ }
61
+ break
62
+ case 'win32':
63
+ switch (arch) {
64
+ case 'x64':
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'zerobus-ingest-sdk.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./zerobus-ingest-sdk.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'zerobus-ingest-sdk.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./zerobus-ingest-sdk.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'zerobus-ingest-sdk.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./zerobus-ingest-sdk.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-win32-arm64-msvc')
101
+ }
102
+ } catch (e) {
103
+ loadError = e
104
+ }
105
+ break
106
+ default:
107
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
+ }
109
+ break
110
+ case 'darwin':
111
+ localFileExisted = existsSync(join(__dirname, 'zerobus-ingest-sdk.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./zerobus-ingest-sdk.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'zerobus-ingest-sdk.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./zerobus-ingest-sdk.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'zerobus-ingest-sdk.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./zerobus-ingest-sdk.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-darwin-arm64')
142
+ }
143
+ } catch (e) {
144
+ loadError = e
145
+ }
146
+ break
147
+ default:
148
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
+ }
150
+ break
151
+ case 'freebsd':
152
+ if (arch !== 'x64') {
153
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
+ }
155
+ localFileExisted = existsSync(join(__dirname, 'zerobus-ingest-sdk.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./zerobus-ingest-sdk.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-freebsd-x64')
161
+ }
162
+ } catch (e) {
163
+ loadError = e
164
+ }
165
+ break
166
+ case 'linux':
167
+ switch (arch) {
168
+ case 'x64':
169
+ if (isMusl()) {
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'zerobus-ingest-sdk.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./zerobus-ingest-sdk.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'zerobus-ingest-sdk.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./zerobus-ingest-sdk.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-x64-gnu')
191
+ }
192
+ } catch (e) {
193
+ loadError = e
194
+ }
195
+ }
196
+ break
197
+ case 'arm64':
198
+ if (isMusl()) {
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'zerobus-ingest-sdk.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./zerobus-ingest-sdk.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'zerobus-ingest-sdk.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./zerobus-ingest-sdk.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-arm64-gnu')
220
+ }
221
+ } catch (e) {
222
+ loadError = e
223
+ }
224
+ }
225
+ break
226
+ case 'arm':
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'zerobus-ingest-sdk.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./zerobus-ingest-sdk.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'zerobus-ingest-sdk.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./zerobus-ingest-sdk.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
252
+ }
253
+ }
254
+ break
255
+ case 'riscv64':
256
+ if (isMusl()) {
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'zerobus-ingest-sdk.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./zerobus-ingest-sdk.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'zerobus-ingest-sdk.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./zerobus-ingest-sdk.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'zerobus-ingest-sdk.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./zerobus-ingest-sdk.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('@databricks/zerobus-ingest-sdk-linux-s390x-gnu')
293
+ }
294
+ } catch (e) {
295
+ loadError = e
296
+ }
297
+ break
298
+ default:
299
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
300
+ }
301
+ break
302
+ default:
303
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
304
+ }
305
+
306
+ if (!nativeBinding) {
307
+ if (loadError) {
308
+ throw loadError
309
+ }
310
+ throw new Error(`Failed to load native binding`)
311
+ }
312
+
313
+ const { RecordType, ZerobusError, ZerobusStream, ZerobusSdk } = nativeBinding
314
+
315
+ module.exports.RecordType = RecordType
316
+ module.exports.ZerobusError = ZerobusError
317
+ module.exports.ZerobusStream = ZerobusStream
318
+ module.exports.ZerobusSdk = ZerobusSdk
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databricks/zerobus-ingest-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "TypeScript/Node.js SDK for streaming data ingestion into Databricks Delta tables using Zerobus",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -23,13 +23,13 @@
23
23
  "index.d.ts",
24
24
  "README.md",
25
25
  "LICENSE",
26
+ "NOTICE",
26
27
  "src/",
27
28
  "utils/",
28
29
  "schemas/",
29
30
  "Cargo.toml",
30
31
  "Cargo.lock",
31
- "build.rs",
32
- "*.node"
32
+ "build.rs"
33
33
  ],
34
34
  "napi": {
35
35
  "name": "zerobus-ingest-sdk",
@@ -66,6 +66,11 @@
66
66
  "example:arrow:single": "tsx examples/arrow/single.ts",
67
67
  "example:arrow:batch": "tsx examples/arrow/batch.ts"
68
68
  },
69
+ "optionalDependencies": {
70
+ "@databricks/zerobus-ingest-sdk-linux-x64-gnu": "1.0.2",
71
+ "@databricks/zerobus-ingest-sdk-linux-arm64-gnu": "1.0.2",
72
+ "@databricks/zerobus-ingest-sdk-win32-x64-msvc": "1.0.2"
73
+ },
69
74
  "peerDependencies": {
70
75
  "protobufjs": "^7.0.0",
71
76
  "apache-arrow": "^56.0.0"