@sayknow-cli/utils 0.3.16 → 0.4.0

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.
@@ -1,93 +0,0 @@
1
- /**
2
- * A fixed-capacity circular buffer that supports efficient push/pop/shift/unshift operations.
3
- * When the buffer is full, adding new items overwrites the oldest items (FIFO behavior).
4
- *
5
- * @template T The type of elements stored in the buffer.
6
- */
7
- export declare class RingBuffer<T> {
8
- #private;
9
- readonly capacity: number;
10
- /**
11
- * Creates a new ring buffer with the specified capacity.
12
- *
13
- * @param capacity - The maximum number of elements the buffer can hold. Must be positive.
14
- */
15
- constructor(capacity: number);
16
- /**
17
- * The number of elements currently in the buffer.
18
- */
19
- get length(): number;
20
- /**
21
- * Whether the buffer is at full capacity.
22
- */
23
- get isFull(): boolean;
24
- /**
25
- * Whether the buffer is empty (contains no elements).
26
- */
27
- get isEmpty(): boolean;
28
- /**
29
- * Adds an item to the end of the buffer.
30
- * If the buffer is full, the oldest item is overwritten and returned.
31
- *
32
- * @param item - The item to add.
33
- * @returns The overwritten item if the buffer was full, otherwise `undefined`.
34
- */
35
- push(item: T): T | undefined;
36
- /**
37
- * Removes and returns the first (oldest) item from the buffer.
38
- *
39
- * @returns The removed item, or `undefined` if the buffer is empty.
40
- */
41
- shift(): T | undefined;
42
- /**
43
- * Removes and returns the last (newest) item from the buffer.
44
- *
45
- * @returns The removed item, or `undefined` if the buffer is empty.
46
- */
47
- pop(): T | undefined;
48
- /**
49
- * Adds an item to the beginning of the buffer.
50
- * If the buffer is full, the newest item is overwritten and returned.
51
- *
52
- * @param item - The item to add.
53
- * @returns The overwritten item if the buffer was full, otherwise `undefined`.
54
- */
55
- unshift(item: T): T | undefined;
56
- /**
57
- * Returns the element at the specified index without removing it.
58
- * Supports negative indices (e.g., `-1` for the last element).
59
- *
60
- * @param index - The zero-based index, or negative index from the end.
61
- * @returns The element at the index, or `undefined` if the index is out of bounds.
62
- */
63
- at(index: number): T | undefined;
64
- /**
65
- * Returns the first (oldest) element without removing it.
66
- *
67
- * @returns The first element, or `undefined` if the buffer is empty.
68
- */
69
- peek(): T | undefined;
70
- /**
71
- * Returns the last (newest) element without removing it.
72
- *
73
- * @returns The last element, or `undefined` if the buffer is empty.
74
- */
75
- peekBack(): T | undefined;
76
- /**
77
- * Removes all elements from the buffer, resetting it to an empty state.
78
- */
79
- clear(): void;
80
- /**
81
- * Returns an iterator that yields elements in logical order (oldest to newest).
82
- * Allows the buffer to be used with `for...of` loops and spread syntax.
83
- *
84
- * @yields Elements in FIFO order.
85
- */
86
- [Symbol.iterator](): Iterator<T>;
87
- /**
88
- * Creates a new array containing all elements in logical order (oldest to newest).
89
- *
90
- * @returns A new array with all buffer elements.
91
- */
92
- toArray(): T[];
93
- }
@@ -1 +0,0 @@
1
- export declare function safeStderrWrite(message: string): void;
@@ -1,14 +0,0 @@
1
- /**
2
- * Strip ANSI escape sequences, remove control characters / lone surrogates,
3
- * and normalize line endings.
4
- *
5
- * Bun-native implementation of the former native `sanitizeText` (see
6
- * `crates/pi-natives/src/text.rs::sanitize_text`). JavaScript strings are
7
- * already UTF-16 code-unit arrays. `toWellFormed()` handles the uncommon
8
- * malformed path; when it changes the input, replacement characters are
9
- * dropped and the normalized result goes through the well-formed sanitizer.
10
- *
11
- * Fast path: well-formed input with no controls or ANSI returns the original
12
- * string after the control probe.
13
- */
14
- export declare function sanitizeText(text: string): string;
@@ -1,25 +0,0 @@
1
- type Snowflake = string & {
2
- readonly __brand: unique symbol;
3
- };
4
- declare namespace Snowflake {
5
- const PATTERN: RegExp;
6
- const EPOCH_TIMESTAMP = 1420070400000;
7
- const MAX_SEQUENCE = 4194303;
8
- function formatParts(dt: number, seq: number): Snowflake;
9
- class Source {
10
- #private;
11
- constructor(sequence?: number);
12
- get sequence(): number;
13
- set sequence(v: number);
14
- reset(): void;
15
- generate(timestamp: number): Snowflake;
16
- }
17
- function next(timestamp?: number): Snowflake;
18
- function valid(value: string): value is Snowflake;
19
- function lowerbound(timelike: Date | number | Snowflake): Snowflake;
20
- function upperbound(timelike: Date | number | Snowflake): Snowflake;
21
- function getSequence(value: Snowflake): number;
22
- function getTimestamp(value: Snowflake): number;
23
- function getDate(value: Snowflake): Date;
24
- }
25
- export { Snowflake };
@@ -1,4 +0,0 @@
1
- export declare function isSafeEnvName(name: string): boolean;
2
- export declare function isSafeEnvValue(value: string): boolean;
3
- export declare function shouldForwardSpawnEnvName(name: string): boolean;
4
- export declare function filterProcessEnv(env: Record<string, string | undefined>): Record<string, string>;
@@ -1,68 +0,0 @@
1
- export declare function readLines(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<Uint8Array>;
2
- export declare function readJsonl<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<T>;
3
- /**
4
- * Stream parsed JSON objects from SSE `data:` lines.
5
- *
6
- * Thin wrapper over {@link readSseEvents}: yields one parsed JSON value per
7
- * dispatched SSE event, skipping events with empty `data` and stopping at the
8
- * OpenAI-style `[DONE]` sentinel. If your consumer doesn't care about `event:`
9
- * names or doesn't need a custom parse step, use this; otherwise call
10
- * `readSseEvents` directly.
11
- *
12
- * @example
13
- * ```ts
14
- * for await (const obj of readSseJson(response.body!)) {
15
- * console.log(obj);
16
- * }
17
- * ```
18
- */
19
- export type SseEventObserver = (event: ServerSentEvent) => void;
20
- export declare function readSseJson<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal, onEvent?: SseEventObserver): AsyncGenerator<T>;
21
- /**
22
- * A single Server-Sent Event dispatched on a blank-line boundary.
23
- *
24
- * - `event` is the value of the most recent `event:` field, or `null` if none.
25
- * - `data` is the concatenation (joined by `\n`) of every `data:` field in the
26
- * event, exactly as required by the SSE spec.
27
- * - `raw` is the list of decoded non-empty lines that made up the event,
28
- * preserved for diagnostic context (error reporting, debugging). The
29
- * dispatching blank line is not included.
30
- */
31
- export interface ServerSentEvent {
32
- event: string | null;
33
- data: string;
34
- raw: string[];
35
- }
36
- /**
37
- * Stream raw Server-Sent Events from an HTTP response body.
38
- *
39
- * Yields one `ServerSentEvent` per blank-line dispatch. The consumer is
40
- * responsible for parsing `data` (e.g. JSON, plain text, error envelope).
41
- * Use `readSseJson` instead when every event is a single `data:` JSON object
42
- * and you don't need access to the `event:` field.
43
- *
44
- * Internally backed by a Buffer-based line reader (`ConcatSink`) so chunk
45
- * concatenation is O(n) and never triggers per-line string slicing of the
46
- * accumulated buffer.
47
- *
48
- * @example
49
- * ```ts
50
- * for await (const sse of readSseEvents(response.body!)) {
51
- * if (sse.event === "ping") continue;
52
- * const obj = JSON.parse(sse.data);
53
- * }
54
- * ```
55
- */
56
- export declare function readSseEvents(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<ServerSentEvent>;
57
- /**
58
- * Parse a complete JSONL string, skipping malformed lines instead of throwing.
59
- *
60
- * Uses `Bun.JSONL.parseChunk` internally. On parse errors, the malformed
61
- * region is skipped up to the next newline and parsing continues.
62
- *
63
- * @example
64
- * ```ts
65
- * const entries = parseJsonlLenient<MyType>(fileContents);
66
- * ```
67
- */
68
- export declare function parseJsonlLenient<T>(buffer: string): T[];
@@ -1,12 +0,0 @@
1
- export declare const MIN_TAB_WIDTH = 1;
2
- export declare const MAX_TAB_WIDTH = 16;
3
- export declare const DEFAULT_TAB_WIDTH = 3;
4
- type TabWidthChangeListener = (width: number) => void;
5
- export declare function onDefaultTabWidthChange(listener: TabWidthChangeListener): () => void;
6
- export declare function getDefaultTabWidth(): number;
7
- export declare function setDefaultTabWidth(width: number): void;
8
- /**
9
- * Visible tab width in columns for `file` (from `.editorconfig` + default), or the default when `file` is omitted.
10
- */
11
- export declare function getIndentation(file?: string | null, projectDir?: string | null): number;
12
- export {};
@@ -1,14 +0,0 @@
1
- export declare class TempDir {
2
- #private;
3
- private constructor();
4
- static createSync(prefix?: string): TempDir;
5
- static create(prefix?: string): Promise<TempDir>;
6
- path(): string;
7
- absolute(): string;
8
- remove(): Promise<void>;
9
- removeSync(): void;
10
- toString(): string;
11
- join(...paths: string[]): string;
12
- [Symbol.asyncDispose](): Promise<void>;
13
- [Symbol.dispose](): void;
14
- }
@@ -1,3 +0,0 @@
1
- export declare function isRecord(value: unknown): value is Record<string, unknown>;
2
- export declare function asRecord(value: unknown): Record<string, unknown> | null;
3
- export declare function toError(value: unknown): Error;
@@ -1,39 +0,0 @@
1
- /**
2
- * Cache policy for which lookups.
3
- */
4
- export declare const enum WhichCachePolicy {
5
- /**
6
- * Use cached result if available.
7
- */
8
- Cached = 0,
9
- /**
10
- * Bypass cache and perform a new lookup.
11
- */
12
- Bypass = 1,
13
- /**
14
- * Always update cache.
15
- */
16
- Fresh = 2,
17
- /**
18
- * Read-only, serves from cache if present, but doesn't write.
19
- */
20
- ReadOnly = 3
21
- }
22
- export interface WhichOptions extends Bun.WhichOptions {
23
- /**
24
- * Cache policy for the lookup.
25
- * Defaults to `WhichCachePolicy.Fresh`.
26
- */
27
- cache?: WhichCachePolicy;
28
- }
29
- declare function darwinWhich(command: string, _options?: Bun.WhichOptions): string | null;
30
- export declare const whichFresh: typeof darwinWhich;
31
- /**
32
- * Locate binary on PATH (with flexible caching).
33
- *
34
- * @param command - Binary name to resolve
35
- * @param options - Bun.WhichOptions plus `cache` control
36
- * @returns Filesystem path if found, else null
37
- */
38
- export declare function $which(command: string, options?: WhichOptions): string | null;
39
- export {};