@declaw/sdk 1.1.1 → 1.1.2
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/CHANGELOG.md +14 -0
- package/dist/index.cjs +16 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -55,6 +55,8 @@ declare class ApiClient {
|
|
|
55
55
|
});
|
|
56
56
|
/** Send a GET request and return parsed JSON. */
|
|
57
57
|
get(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
58
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
59
|
+
getBytes(path: string, opts?: RequestOpts): Promise<Uint8Array>;
|
|
58
60
|
/** Send a POST request and return parsed JSON. */
|
|
59
61
|
post(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
60
62
|
/** Send a PATCH request and return parsed JSON. */
|
|
@@ -697,16 +699,27 @@ declare class Filesystem {
|
|
|
697
699
|
private readonly client;
|
|
698
700
|
constructor(sandboxId: string, client: ApiClient);
|
|
699
701
|
/**
|
|
700
|
-
* Read a file's contents
|
|
702
|
+
* Read a file's contents.
|
|
703
|
+
*
|
|
704
|
+
* Default returns the content as a string. Pass `{ format: "bytes" }`
|
|
705
|
+
* to get a `Uint8Array` for binary-safe reads — the SDK negotiates
|
|
706
|
+
* `application/octet-stream` end-to-end so high-bit bytes survive the
|
|
707
|
+
* round trip.
|
|
701
708
|
*
|
|
702
709
|
* @param path - Absolute path to the file.
|
|
703
|
-
* @param opts - Optional user and request timeout.
|
|
704
|
-
* @returns The file contents as a string.
|
|
710
|
+
* @param opts - Optional format, user, and request timeout.
|
|
711
|
+
* @returns The file contents as a string, or Uint8Array when format="bytes".
|
|
705
712
|
*/
|
|
706
713
|
read(path: string, opts?: {
|
|
714
|
+
format?: 'text';
|
|
707
715
|
user?: string;
|
|
708
716
|
requestTimeout?: number;
|
|
709
717
|
}): Promise<string>;
|
|
718
|
+
read(path: string, opts: {
|
|
719
|
+
format: 'bytes';
|
|
720
|
+
user?: string;
|
|
721
|
+
requestTimeout?: number;
|
|
722
|
+
}): Promise<Uint8Array>;
|
|
710
723
|
/**
|
|
711
724
|
* Write data to a file.
|
|
712
725
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ declare class ApiClient {
|
|
|
55
55
|
});
|
|
56
56
|
/** Send a GET request and return parsed JSON. */
|
|
57
57
|
get(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
58
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
59
|
+
getBytes(path: string, opts?: RequestOpts): Promise<Uint8Array>;
|
|
58
60
|
/** Send a POST request and return parsed JSON. */
|
|
59
61
|
post(path: string, opts?: RequestOpts): Promise<unknown>;
|
|
60
62
|
/** Send a PATCH request and return parsed JSON. */
|
|
@@ -697,16 +699,27 @@ declare class Filesystem {
|
|
|
697
699
|
private readonly client;
|
|
698
700
|
constructor(sandboxId: string, client: ApiClient);
|
|
699
701
|
/**
|
|
700
|
-
* Read a file's contents
|
|
702
|
+
* Read a file's contents.
|
|
703
|
+
*
|
|
704
|
+
* Default returns the content as a string. Pass `{ format: "bytes" }`
|
|
705
|
+
* to get a `Uint8Array` for binary-safe reads — the SDK negotiates
|
|
706
|
+
* `application/octet-stream` end-to-end so high-bit bytes survive the
|
|
707
|
+
* round trip.
|
|
701
708
|
*
|
|
702
709
|
* @param path - Absolute path to the file.
|
|
703
|
-
* @param opts - Optional user and request timeout.
|
|
704
|
-
* @returns The file contents as a string.
|
|
710
|
+
* @param opts - Optional format, user, and request timeout.
|
|
711
|
+
* @returns The file contents as a string, or Uint8Array when format="bytes".
|
|
705
712
|
*/
|
|
706
713
|
read(path: string, opts?: {
|
|
714
|
+
format?: 'text';
|
|
707
715
|
user?: string;
|
|
708
716
|
requestTimeout?: number;
|
|
709
717
|
}): Promise<string>;
|
|
718
|
+
read(path: string, opts: {
|
|
719
|
+
format: 'bytes';
|
|
720
|
+
user?: string;
|
|
721
|
+
requestTimeout?: number;
|
|
722
|
+
}): Promise<Uint8Array>;
|
|
710
723
|
/**
|
|
711
724
|
* Write data to a file.
|
|
712
725
|
*
|
package/dist/index.js
CHANGED
|
@@ -139,6 +139,12 @@ var ApiClient = class {
|
|
|
139
139
|
async get(path, opts) {
|
|
140
140
|
return this.requestWithRetry("GET", path, opts);
|
|
141
141
|
}
|
|
142
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
143
|
+
async getBytes(path, opts) {
|
|
144
|
+
const response = await this.requestWithRetry("GET", path, opts, true);
|
|
145
|
+
const buf = await response.arrayBuffer();
|
|
146
|
+
return new Uint8Array(buf);
|
|
147
|
+
}
|
|
142
148
|
/** Send a POST request and return parsed JSON. */
|
|
143
149
|
async post(path, opts) {
|
|
144
150
|
return this.requestWithRetry("POST", path, opts);
|
|
@@ -1263,15 +1269,18 @@ var Filesystem = class {
|
|
|
1263
1269
|
this.sandboxId = sandboxId;
|
|
1264
1270
|
this.client = client;
|
|
1265
1271
|
}
|
|
1266
|
-
/**
|
|
1267
|
-
* Read a file's contents as a string.
|
|
1268
|
-
*
|
|
1269
|
-
* @param path - Absolute path to the file.
|
|
1270
|
-
* @param opts - Optional user and request timeout.
|
|
1271
|
-
* @returns The file contents as a string.
|
|
1272
|
-
*/
|
|
1273
1272
|
async read(path, opts) {
|
|
1274
1273
|
const user = opts?.user ?? DEFAULT_USER;
|
|
1274
|
+
if (opts?.format === "bytes") {
|
|
1275
|
+
return this.client.getBytes(
|
|
1276
|
+
`/sandboxes/${this.sandboxId}/files`,
|
|
1277
|
+
{
|
|
1278
|
+
params: { path, username: user },
|
|
1279
|
+
headers: { "Accept": "application/octet-stream" },
|
|
1280
|
+
timeout: opts?.requestTimeout
|
|
1281
|
+
}
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1275
1284
|
const result = await this.client.get(
|
|
1276
1285
|
`/sandboxes/${this.sandboxId}/files`,
|
|
1277
1286
|
{
|