@botejs/core 0.5.0 → 0.7.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.
- package/README.md +45 -117
- package/dist/args.d.ts +14 -8
- package/dist/args.js +6 -3
- package/dist/cursor.d.ts +44 -6
- package/dist/cursor.js +41 -41
- package/dist/error.d.ts +47 -0
- package/dist/error.js +113 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +4 -2
- package/dist/open.d.ts +31 -24
- package/dist/open.js +27 -20
- package/dist/path.d.ts +3 -1
- package/dist/path.js +28 -4
- package/dist/source/base.d.ts +70 -0
- package/dist/source/base.js +1 -0
- package/dist/source/forward.d.ts +49 -0
- package/dist/source/forward.js +219 -0
- package/dist/source/seekable.d.ts +8 -0
- package/dist/{sources.js → source/seekable.js} +24 -10
- package/dist/validate.d.ts +2 -16
- package/dist/validate.js +5 -51
- package/package.json +3 -2
- package/dist/decode.d.ts +0 -3
- package/dist/decode.js +0 -20
- package/dist/sources.d.ts +0 -39
package/dist/validate.d.ts
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import type
|
|
3
|
-
export type { StandardSchemaV1
|
|
4
|
-
export type Segment = string | number;
|
|
5
|
-
export type Path = readonly Segment[];
|
|
6
|
-
export declare class ValidationError extends Error {
|
|
7
|
-
readonly issues: readonly StandardSchemaV1.Issue[];
|
|
8
|
-
readonly path: Path;
|
|
9
|
-
constructor(issues: readonly StandardSchemaV1.Issue[], path: Path);
|
|
10
|
-
}
|
|
11
|
-
export declare class PathError extends Error {
|
|
12
|
-
readonly path: Path;
|
|
13
|
-
/** The fault kind; stable across versions, safe to branch on. */
|
|
14
|
-
readonly code: PathFaultCode;
|
|
15
|
-
constructor(path: Path, code: PathFaultCode, segment?: number);
|
|
16
|
-
}
|
|
2
|
+
import { type Path } from './path.ts';
|
|
3
|
+
export type { StandardSchemaV1 };
|
|
17
4
|
export declare function runStandardSchema<O>(schema: StandardSchemaV1<unknown, O>, value: unknown, path: Path): Promise<O>;
|
|
18
5
|
export declare function validateItem<O>(schema: StandardSchemaV1<unknown, O>, value: unknown, path: Path, onInvalid: 'throw' | 'skip'): Promise<{
|
|
19
6
|
skip: true;
|
|
20
7
|
} | {
|
|
21
8
|
value: O;
|
|
22
9
|
}>;
|
|
23
|
-
export declare function formatPath(path: Path): string;
|
package/dist/validate.js
CHANGED
|
@@ -1,64 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
issues;
|
|
3
|
-
path;
|
|
4
|
-
constructor(issues, path) {
|
|
5
|
-
super(`bote: schema validation failed at ${formatPath(path)}: ${issues[0]?.message ?? 'unknown'}`);
|
|
6
|
-
this.name = 'ValidationError';
|
|
7
|
-
this.issues = issues;
|
|
8
|
-
this.path = path;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/** Human message per fault kind. The native layer ships only the code (and the
|
|
12
|
-
* offending `segment` where it matters), so this is the single source of the
|
|
13
|
-
* user-facing prose. Keyed by the Rust-generated [`PathFaultCode`]. */
|
|
14
|
-
const PATH_FAULT_MESSAGE = {
|
|
15
|
-
through_scalar: (segment) => `path traverses a non-container value at segment ${segment}`,
|
|
16
|
-
wrong_kind: (segment) => `path segment ${segment} does not match the container kind`,
|
|
17
|
-
scalar_target: () => 'target value is not a container',
|
|
18
|
-
};
|
|
19
|
-
export class PathError extends Error {
|
|
20
|
-
path;
|
|
21
|
-
/** The fault kind; stable across versions, safe to branch on. */
|
|
22
|
-
code;
|
|
23
|
-
constructor(path, code, segment) {
|
|
24
|
-
const reason = (PATH_FAULT_MESSAGE[code] ?? (() => code))(segment);
|
|
25
|
-
super(`bote: cannot resolve ${formatPath(path)}: ${reason}`);
|
|
26
|
-
this.name = 'PathError';
|
|
27
|
-
this.path = path;
|
|
28
|
-
this.code = code;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { ValidationError } from "./error.js";
|
|
31
2
|
export async function runStandardSchema(schema, value, path) {
|
|
32
3
|
const result = await schema['~standard'].validate(value);
|
|
33
|
-
if (result.issues)
|
|
4
|
+
if (result.issues) {
|
|
34
5
|
throw new ValidationError(result.issues, path);
|
|
6
|
+
}
|
|
35
7
|
return result.value;
|
|
36
8
|
}
|
|
37
9
|
export async function validateItem(schema, value, path, onInvalid) {
|
|
38
10
|
const result = await schema['~standard'].validate(value);
|
|
39
11
|
if (result.issues) {
|
|
40
|
-
if (onInvalid === 'skip')
|
|
12
|
+
if (onInvalid === 'skip') {
|
|
41
13
|
return { skip: true };
|
|
14
|
+
}
|
|
42
15
|
throw new ValidationError(result.issues, path);
|
|
43
16
|
}
|
|
44
17
|
return { value: result.value };
|
|
45
18
|
}
|
|
46
|
-
export function formatPath(path) {
|
|
47
|
-
if (path.length === 0)
|
|
48
|
-
return '(root)';
|
|
49
|
-
let out = '';
|
|
50
|
-
for (let i = 0; i < path.length; i++) {
|
|
51
|
-
const seg = path[i];
|
|
52
|
-
if (typeof seg === 'number') {
|
|
53
|
-
out += `[${seg}]`;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(seg)) {
|
|
57
|
-
out += i === 0 ? seg : `.${seg}`;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
out += `[${JSON.stringify(seg)}]`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return out;
|
|
64
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botejs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"build": "tsc",
|
|
32
32
|
"build:debug": "tsc --sourceMap",
|
|
33
33
|
"test": "node --test __test__/*.spec.ts",
|
|
34
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p __test__/tsconfig.json",
|
|
34
35
|
"lint": "oxlint src",
|
|
35
36
|
"prepublishOnly": "cp ../../README.md ./README.md && tsc"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@botejs/native": "^0.
|
|
39
|
+
"@botejs/native": "^0.7.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/node": "^22.0.0",
|
package/dist/decode.d.ts
DELETED
package/dist/decode.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { PathError, formatPath } from "./validate.js";
|
|
2
|
-
const NATIVE_PATH_ERROR = /^bote:path:([a-z_]+)(?::(\d+))?$/;
|
|
3
|
-
export function deserializeError(err, path) {
|
|
4
|
-
if (err instanceof Error && !(err instanceof PathError)) {
|
|
5
|
-
const match = NATIVE_PATH_ERROR.exec(err.message);
|
|
6
|
-
if (match) {
|
|
7
|
-
const segment = match[2] === undefined ? undefined : Number(match[2]);
|
|
8
|
-
return new PathError(path, match[1], segment);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return err;
|
|
12
|
-
}
|
|
13
|
-
export function parseValue(text, path) {
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(text);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
throw new Error(`bote: malformed JSON value at ${formatPath(path)}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/dist/sources.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A handle on an opened seekable byte stream. The reader owns whatever
|
|
3
|
-
* resources back the stream (a file handle, an `AbortController`, etc.) and
|
|
4
|
-
* surfaces them through `close()`. Constructed by `Source.open()`; never by
|
|
5
|
-
* library callers directly.
|
|
6
|
-
*/
|
|
7
|
-
export interface SourceReader {
|
|
8
|
-
/** Total length of the underlying byte stream. */
|
|
9
|
-
readonly size: number;
|
|
10
|
-
/** Preferred read granularity in bytes. Must be a non-zero multiple of 64. */
|
|
11
|
-
readonly chunkBytes?: number;
|
|
12
|
-
/**
|
|
13
|
-
* Read up to `length` bytes starting at `offset` and resolve with the
|
|
14
|
-
* bytes read. The returned `Uint8Array`'s `.byteLength` is the actual
|
|
15
|
-
* count, which must be `<= length`.
|
|
16
|
-
*/
|
|
17
|
-
read(offset: number, length: number): Promise<Uint8Array>;
|
|
18
|
-
/** Release resources held by the reader. Driven once by the `open()` lifecycle. */
|
|
19
|
-
close?(): Promise<void> | void;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Describes how to obtain a seekable byte stream. Provide your own object implementing
|
|
23
|
-
* this interface to plug in custom backends.
|
|
24
|
-
*/
|
|
25
|
-
export interface Source {
|
|
26
|
-
/** Acquire the stream. Resolves to a `SourceReader` that owns any underlying resources. */
|
|
27
|
-
open(): Promise<SourceReader>;
|
|
28
|
-
}
|
|
29
|
-
export interface FactoryOptions {
|
|
30
|
-
/** Override the factory's default chunk size. Must be a non-zero multiple of 64. */
|
|
31
|
-
chunkBytes?: number;
|
|
32
|
-
}
|
|
33
|
-
export interface HttpRangeOptions extends FactoryOptions {
|
|
34
|
-
/** Merged into every request (headers, credentials, signal, etc.). */
|
|
35
|
-
init?: RequestInit;
|
|
36
|
-
}
|
|
37
|
-
export declare function fromBuffer(buf: Uint8Array | ArrayBuffer, options?: FactoryOptions): Source;
|
|
38
|
-
export declare function fromFile(path: string, options?: FactoryOptions): Source;
|
|
39
|
-
export declare function fromHttpRange(url: string, options?: HttpRangeOptions): Source;
|