@dbx-tools/shared 0.1.18 → 0.1.19
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 +14 -1
- package/dist/src/api.js +0 -4
- package/dist/src/common.d.ts +15 -0
- package/dist/src/common.js +17 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api.ts +0 -4
- package/src/common.ts +18 -0
package/README.md
CHANGED
|
@@ -172,7 +172,7 @@ const name = await projectUtils.name();
|
|
|
172
172
|
projectUtils.parseGitRemote("git@github.com:org/my-repo.git"); // "my-repo"
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
## `commonUtils` - memoize
|
|
175
|
+
## `commonUtils` - memoize, ids, hashing, polling, error messages
|
|
176
176
|
|
|
177
177
|
```ts
|
|
178
178
|
import { commonUtils } from "@dbx-tools/shared";
|
|
@@ -180,11 +180,24 @@ import { commonUtils } from "@dbx-tools/shared";
|
|
|
180
180
|
// Memoize by all-args; sync results cache forever, async failures bust.
|
|
181
181
|
const fetchUser = commonUtils.memoize(async (id: string) => loadUser(id));
|
|
182
182
|
|
|
183
|
+
// Marker-friendly short id (default 8 hex chars from a v4 UUID).
|
|
184
|
+
// Safe within a single conversation / job / batch. Use a full UUID
|
|
185
|
+
// when global uniqueness is needed.
|
|
186
|
+
commonUtils.shortId(); // e.g. "a3f1c92b"
|
|
187
|
+
|
|
183
188
|
// Short, deterministic hash for cache keys / slug suffixes / etc.
|
|
184
189
|
// Pure-JS FNV-1a in Crockford-style base-32 (digits + lowercase
|
|
185
190
|
// alphabet minus i/l/o/u). Browser-safe.
|
|
186
191
|
commonUtils.fnvHash("databricks-claude-sonnet-4-6"); // e.g. "k3p9q7"
|
|
187
192
|
commonUtils.fnvHashWithOptions({ length: 4 }, "user@example.com");
|
|
193
|
+
|
|
194
|
+
// Poll an async fn until it returns truthy or the timeout fires.
|
|
195
|
+
await commonUtils.poll(() => isReady(), { intervalMs: 250, timeoutMs: 30_000 });
|
|
196
|
+
|
|
197
|
+
// Pull a printable message out of any thrown value. Folds the
|
|
198
|
+
// `err instanceof Error ? err.message : String(err)` dance into
|
|
199
|
+
// one helper for log attributes and similar contexts.
|
|
200
|
+
log.warn("write:error", { error: commonUtils.errorMessage(err) });
|
|
188
201
|
```
|
|
189
202
|
|
|
190
203
|
`@memoized` is a TC39 stage-1 method decorator built on the same
|
package/dist/src/api.js
CHANGED
|
@@ -130,10 +130,6 @@ export function toContext(source, input) {
|
|
|
130
130
|
* `cancellationToken.onCancellationRequested` to it, so this
|
|
131
131
|
* adapter is the one-line bridge from "platform-standard
|
|
132
132
|
* cancellation" to "the SDK aborts the fetch on your behalf".
|
|
133
|
-
*
|
|
134
|
-
* Kept private for now: the genie package is the only consumer in
|
|
135
|
-
* the workspace. Lift to `@dbx-tools/shared` (`apiUtils`) the
|
|
136
|
-
* moment a second package needs SDK-call cancellation.
|
|
137
133
|
*/
|
|
138
134
|
function signalToCancellationToken(signal) {
|
|
139
135
|
return {
|
package/dist/src/common.d.ts
CHANGED
|
@@ -175,6 +175,21 @@ export declare function tieAbortSignal(child: AbortController, parent?: AbortSig
|
|
|
175
175
|
* globally unique, use a full UUID instead.
|
|
176
176
|
*/
|
|
177
177
|
export declare function shortId(length?: number): string;
|
|
178
|
+
/**
|
|
179
|
+
* Extract a human-readable message from any thrown value. Returns
|
|
180
|
+
* `value.message` when `value` is an `Error`, otherwise coerces
|
|
181
|
+
* via `String(value)`. Collapses the ubiquitous
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* err instanceof Error ? err.message : String(err)
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* dance into a single helper, useful for log attributes and any
|
|
188
|
+
* other "give me something printable" context where the caller
|
|
189
|
+
* doesn't want to re-throw or rely on `console.error`'s default
|
|
190
|
+
* formatting.
|
|
191
|
+
*/
|
|
192
|
+
export declare function errorMessage(value: unknown): string;
|
|
178
193
|
export declare function fnvHash(...values: string[]): string;
|
|
179
194
|
export declare function fnvHashWithOptions(options?: {
|
|
180
195
|
length?: number;
|
package/dist/src/common.js
CHANGED
|
@@ -205,6 +205,23 @@ function sleep(ms, signal) {
|
|
|
205
205
|
export function shortId(length = 8) {
|
|
206
206
|
return globalThis.crypto.randomUUID().replace(/-/g, "").slice(0, length);
|
|
207
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Extract a human-readable message from any thrown value. Returns
|
|
210
|
+
* `value.message` when `value` is an `Error`, otherwise coerces
|
|
211
|
+
* via `String(value)`. Collapses the ubiquitous
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* err instanceof Error ? err.message : String(err)
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* dance into a single helper, useful for log attributes and any
|
|
218
|
+
* other "give me something printable" context where the caller
|
|
219
|
+
* doesn't want to re-throw or rely on `console.error`'s default
|
|
220
|
+
* formatting.
|
|
221
|
+
*/
|
|
222
|
+
export function errorMessage(value) {
|
|
223
|
+
return value instanceof Error ? value.message : String(value);
|
|
224
|
+
}
|
|
208
225
|
export function fnvHash(...values) {
|
|
209
226
|
return fnvHashWithOptions({}, ...values);
|
|
210
227
|
}
|