@dbx-tools/shared 0.1.24 → 0.1.25
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 +17 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,11 +21,11 @@ import {
|
|
|
21
21
|
} from "@dbx-tools/shared";
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
> `apiUtils` and `projectUtils` import Node-only modules
|
|
25
|
-
> `node:fs`) and are intentionally **not** re-exported
|
|
26
|
-
> entry. Vite / Webpack / esbuild builds that honor the
|
|
27
|
-
> condition will resolve `@dbx-tools/shared` to a barrel that
|
|
28
|
-
> omits
|
|
24
|
+
> `apiUtils`, `appkitUtils`, and `projectUtils` import Node-only modules
|
|
25
|
+
> (`@databricks/appkit`, `node:fs`) and are intentionally **not** re-exported
|
|
26
|
+
> from the browser entry. Vite / Webpack / esbuild builds that honor the
|
|
27
|
+
> `browser` condition will resolve `@dbx-tools/shared` to a barrel that
|
|
28
|
+
> omits all three - import them only from server-side code.
|
|
29
29
|
|
|
30
30
|
## `appkitUtils` - typed sibling-plugin lookup
|
|
31
31
|
|
|
@@ -106,8 +106,8 @@ const port = await netUtils.getRandomPort();
|
|
|
106
106
|
|
|
107
107
|
Wraps `fetch` against `https://<workspace-host>/api/2.0/<path>` with the
|
|
108
108
|
auth header your AppKit execution context already carries, plus an
|
|
109
|
-
optional `
|
|
110
|
-
single
|
|
109
|
+
optional `cache` field on the init object so per-user TTL'd reads are a
|
|
110
|
+
single property:
|
|
111
111
|
|
|
112
112
|
```ts
|
|
113
113
|
import { apiUtils } from "@dbx-tools/shared";
|
|
@@ -121,8 +121,7 @@ const data = await apiUtils.fetchApi<{ endpoints?: unknown[] }>(
|
|
|
121
121
|
// With a per-user cache (useful for "list everything" calls):
|
|
122
122
|
const cached = await apiUtils.fetchApi<{ endpoints?: unknown[] }>(
|
|
123
123
|
"serving-endpoints",
|
|
124
|
-
|
|
125
|
-
{ userKey: req.userId, options: { ttl: 300 } },
|
|
124
|
+
{ cache: { options: { ttl: 300 } } },
|
|
126
125
|
);
|
|
127
126
|
|
|
128
127
|
// POST + custom client (e.g. service-account script outside a request).
|
|
@@ -131,9 +130,8 @@ await apiUtils.fetchApi<{ id: string }>(
|
|
|
131
130
|
{
|
|
132
131
|
body: JSON.stringify({ inputs }),
|
|
133
132
|
headers: { "Content-Type": "application/json" },
|
|
133
|
+
workspaceClient: serviceClient,
|
|
134
134
|
},
|
|
135
|
-
undefined,
|
|
136
|
-
serviceClient,
|
|
137
135
|
);
|
|
138
136
|
```
|
|
139
137
|
|
|
@@ -191,8 +189,14 @@ commonUtils.shortId(); // e.g. "a3f1c92b"
|
|
|
191
189
|
commonUtils.fnvHash("databricks-claude-sonnet-4-6"); // e.g. "k3p9q7"
|
|
192
190
|
commonUtils.fnvHashWithOptions({ length: 4 }, "user@example.com");
|
|
193
191
|
|
|
194
|
-
//
|
|
195
|
-
|
|
192
|
+
// Async generator that polls a producer on an interval. Yields each
|
|
193
|
+
// value; stops when `predicate` returns false or the signal aborts.
|
|
194
|
+
for await (const status of commonUtils.poll(
|
|
195
|
+
async ({ signal }) => fetchStatus(signal),
|
|
196
|
+
{ intervalMs: 250, predicate: (s) => s !== "ready" },
|
|
197
|
+
)) {
|
|
198
|
+
render(status);
|
|
199
|
+
}
|
|
196
200
|
|
|
197
201
|
// Pull a printable message out of any thrown value. Folds the
|
|
198
202
|
// `err instanceof Error ? err.message : String(err)` dance into
|