@dbx-tools/databricks-zerobus 0.1.9
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/README.md +55 -0
- package/index.ts +5 -0
- package/package.json +44 -0
- package/src/zerobus.ts +59 -0
- package/tsconfig.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @dbx-tools/node-databricks-zerobus
|
|
2
|
+
|
|
3
|
+
Region-aware Zerobus ingest helpers for Databricks workspaces.
|
|
4
|
+
|
|
5
|
+
Import this package when Node code needs to create a Zerobus SDK client and open
|
|
6
|
+
an ingest stream without hand-building the region-specific Zerobus endpoint.
|
|
7
|
+
|
|
8
|
+
Key features:
|
|
9
|
+
|
|
10
|
+
- Databricks workspace URL/id discovery through
|
|
11
|
+
[`@dbx-tools/node-databricks`](../databricks).
|
|
12
|
+
- Cloud/region-aware Zerobus endpoint construction.
|
|
13
|
+
- Credential lookup with Zerobus-prefixed env vars and Databricks client-id
|
|
14
|
+
fallbacks.
|
|
15
|
+
- Thin wrapper around the Zerobus SDK so callers can still use SDK-native stream
|
|
16
|
+
methods after setup.
|
|
17
|
+
|
|
18
|
+
## Create A Zerobus SDK Client
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { zerobus } from "@dbx-tools/node-databricks-zerobus";
|
|
22
|
+
|
|
23
|
+
const sdk = await zerobus.createSdk();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`createSdk()` resolves the current Databricks workspace URL/id, detects its cloud
|
|
27
|
+
region through [`@dbx-tools/node-databricks`](../databricks), and constructs the
|
|
28
|
+
Zerobus endpoint for that region.
|
|
29
|
+
|
|
30
|
+
## Open An Ingest Stream
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const stream = await zerobus.createStream(sdk, "main.default.events");
|
|
34
|
+
|
|
35
|
+
await stream.ingestRecord({
|
|
36
|
+
id: crypto.randomUUID(),
|
|
37
|
+
event_type: "clicked",
|
|
38
|
+
created_at: new Date().toISOString(),
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`createStream()` reads `ZEROBUS_DATABRICKS_CLIENT_ID` /
|
|
43
|
+
`ZEROBUS_DATABRICKS_CLIENT_SECRET`, falling back to unprefixed
|
|
44
|
+
`DATABRICKS_CLIENT_ID` / `DATABRICKS_CLIENT_SECRET`. Use the prefixed variables
|
|
45
|
+
when the app uses separate credentials for Zerobus ingestion.
|
|
46
|
+
|
|
47
|
+
This package does not model records or topics. It only resolves the correct SDK
|
|
48
|
+
client and stream endpoint, then leaves ingestion semantics to Zerobus.
|
|
49
|
+
|
|
50
|
+
## Module
|
|
51
|
+
|
|
52
|
+
- `zerobus` - `createSdk()` and `createStream()`.
|
|
53
|
+
|
|
54
|
+
This package has no AppKit dependency. Workspace and cloud detection are
|
|
55
|
+
delegated to [`@dbx-tools/node-databricks`](../databricks).
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dbx-tools/databricks-zerobus",
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "git+https://github.com/reggie-db/dbx-tools.git",
|
|
6
|
+
"directory": "workspaces/node/databricks-zerobus"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/node": "^24.6.0",
|
|
10
|
+
"tsx": "^4.23.0",
|
|
11
|
+
"typescript": "^5.9.3"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@databricks/zerobus-ingest-sdk": "^1.1.0",
|
|
15
|
+
"@dbx-tools/databricks": "0.1.9",
|
|
16
|
+
"@dbx-tools/shared-core": "0.1.9"
|
|
17
|
+
},
|
|
18
|
+
"main": "index.ts",
|
|
19
|
+
"license": "UNLICENSED",
|
|
20
|
+
"version": "0.1.9",
|
|
21
|
+
"types": "index.ts",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./index.ts",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"dbxToolsConfig": {
|
|
28
|
+
"tags": [
|
|
29
|
+
"node"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"pnpm exec projen\".",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "projen build",
|
|
35
|
+
"compile": "projen compile",
|
|
36
|
+
"default": "projen default",
|
|
37
|
+
"package": "projen package",
|
|
38
|
+
"post-compile": "projen post-compile",
|
|
39
|
+
"pre-compile": "projen pre-compile",
|
|
40
|
+
"test": "projen test",
|
|
41
|
+
"watch": "projen watch",
|
|
42
|
+
"projen": "projen"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/zerobus.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZerobusSdk,
|
|
3
|
+
type RecordType,
|
|
4
|
+
type StreamConfigurationOptions,
|
|
5
|
+
type TableProperties,
|
|
6
|
+
type ZerobusStream,
|
|
7
|
+
} from "@databricks/zerobus-ingest-sdk";
|
|
8
|
+
import { workspace, cloud } from "@dbx-tools/databricks";
|
|
9
|
+
|
|
10
|
+
export async function createSdk(): Promise<ZerobusSdk> {
|
|
11
|
+
const workspaceUrl = await workspace.getWorkspaceUrl();
|
|
12
|
+
if (!workspaceUrl) {
|
|
13
|
+
throw new Error("Workspace URL not found");
|
|
14
|
+
}
|
|
15
|
+
const workspaceId = await workspace.getWorkspaceId();
|
|
16
|
+
if (!workspaceId) {
|
|
17
|
+
throw new Error(`Workspace ID not found: workspaceUrl=${workspaceUrl.toString()}`);
|
|
18
|
+
}
|
|
19
|
+
const location = await cloud.resolveCloudLocation(workspaceUrl.toString());
|
|
20
|
+
if (!location) {
|
|
21
|
+
throw new Error(`Workspace location not found: workspaceUrl=${workspaceUrl.toString()}`);
|
|
22
|
+
}
|
|
23
|
+
const domain =
|
|
24
|
+
location.provider === cloud.CloudProvider.Azure
|
|
25
|
+
? "azuredatabricks.net"
|
|
26
|
+
: "cloud.databricks.com";
|
|
27
|
+
const zerobusEndpoint = `https://${workspaceId}.zerobus.${location.region}.${domain}`;
|
|
28
|
+
return new ZerobusSdk(zerobusEndpoint, workspaceUrl.toString());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function createStream(
|
|
32
|
+
sdk: ZerobusSdk,
|
|
33
|
+
table: TableProperties | string,
|
|
34
|
+
options?: StreamConfigurationOptions,
|
|
35
|
+
): Promise<ZerobusStream> {
|
|
36
|
+
function resolveVariable(name: string): string {
|
|
37
|
+
for (const candidate of [`ZEROBUS_${name}`, name]) {
|
|
38
|
+
const value = process.env[candidate];
|
|
39
|
+
if (value) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Variable ${name} not found`);
|
|
44
|
+
}
|
|
45
|
+
const streamTableProperties = typeof table === "string" ? { tableName: table } : table;
|
|
46
|
+
const streamClientId = resolveVariable("DATABRICKS_CLIENT_ID");
|
|
47
|
+
const streamClientSecret = resolveVariable("DATABRICKS_CLIENT_SECRET");
|
|
48
|
+
const streamOptions = {
|
|
49
|
+
recovery: true,
|
|
50
|
+
recordType: 0 as RecordType, // RecordType.Json (const enum, can't be referenced under verbatimModuleSyntax)
|
|
51
|
+
...options,
|
|
52
|
+
};
|
|
53
|
+
return await sdk.createStream(
|
|
54
|
+
streamTableProperties,
|
|
55
|
+
streamClientId,
|
|
56
|
+
streamClientSecret,
|
|
57
|
+
streamOptions,
|
|
58
|
+
);
|
|
59
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// ~~ Generated by projen. To modify, edit .projenrc.js and run "pnpm exec projen".
|
|
2
|
+
{
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "lib",
|
|
6
|
+
"alwaysStrict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"inlineSourceMap": true,
|
|
11
|
+
"inlineSources": true,
|
|
12
|
+
"lib": [
|
|
13
|
+
"ES2022"
|
|
14
|
+
],
|
|
15
|
+
"module": "ESNext",
|
|
16
|
+
"noEmitOnError": false,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noImplicitAny": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noImplicitThis": true,
|
|
21
|
+
"noUnusedLocals": true,
|
|
22
|
+
"noUnusedParameters": true,
|
|
23
|
+
"resolveJsonModule": true,
|
|
24
|
+
"strict": true,
|
|
25
|
+
"strictNullChecks": true,
|
|
26
|
+
"strictPropertyInitialization": true,
|
|
27
|
+
"stripInternal": true,
|
|
28
|
+
"target": "ES2022",
|
|
29
|
+
"types": [
|
|
30
|
+
"node"
|
|
31
|
+
],
|
|
32
|
+
"moduleResolution": "bundler",
|
|
33
|
+
"skipLibCheck": true
|
|
34
|
+
},
|
|
35
|
+
"include": [
|
|
36
|
+
"src/**/*.ts"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"node_modules"
|
|
40
|
+
]
|
|
41
|
+
}
|