@backwrite/sdk 0.1.0 → 0.2.1
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 +59 -0
- package/dist/client.d.ts +155 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +207 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/operations.d.ts +944 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +961 -0
- package/dist/operations.js.map +1 -0
- package/dist/services.d.ts +143 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +389 -0
- package/dist/services.js.map +1 -0
- package/package.json +33 -8
- package/src/client.ts +62 -9
- package/src/index.ts +8 -2
- package/src/services.ts +451 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# `@backwrite/sdk`
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript client SDK for [Backwrite](https://backwrite.dev) — the programmable distributed backend platform.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @backwrite/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Quickstart
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { createClient } from "@backwrite/sdk";
|
|
19
|
+
|
|
20
|
+
// Initialize client with project and branch context
|
|
21
|
+
const bw = createClient({
|
|
22
|
+
url: "https://api.backwrite.dev",
|
|
23
|
+
apiKey: process.env.BACKWRITE_SERVICE_KEY!,
|
|
24
|
+
projectId: "bw_proj_01a0eeb720837282bb8ee7835fb9d669",
|
|
25
|
+
branchId: "br_01a0eeb720d473428f7e4733bd999964",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// 1. Execute type-safe SQL query with 1ms execution
|
|
29
|
+
const { rows } = await bw.query<{ id: string; name: string }>(
|
|
30
|
+
"SELECT id, name FROM users WHERE status = $1 LIMIT 10",
|
|
31
|
+
["active"]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// 2. Query an isolated preview branch
|
|
35
|
+
const preview = bw.branch("preview-feat-payments");
|
|
36
|
+
await preview.query("INSERT INTO orders (user_id, amount) VALUES ($1, $2)", [rows[0].id, 49.99]);
|
|
37
|
+
|
|
38
|
+
// 3. Vector Similarity Search
|
|
39
|
+
const matches = await bw.vector.search("embeddings_table", [0.024, -0.421, 0.812], {
|
|
40
|
+
topK: 5,
|
|
41
|
+
metric: "cosine",
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **Branch-Aware Routing**: Target production, development, or ephemeral branches seamlessly.
|
|
50
|
+
- **Transactional Migrations**: Apply DDL migrations safely with automated rollback guarantees.
|
|
51
|
+
- **NATS JetStream CDC**: Low-latency change data capture streaming directly from Postgres WAL.
|
|
52
|
+
- **Vector Embeddings**: Native pgvector similarity search with cosine and Euclidean distance metrics.
|
|
53
|
+
- **Row Level Security**: Built-in auth tokens and session handling.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
Apache-2.0 © Backwrite
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structured API failure. Every non-2xx response is raised as this class,
|
|
3
|
+
* so `instanceof BackwriteApiError` is the single catch boundary and the
|
|
4
|
+
* platform error code (e.g. `BRANCH_NOT_READY`) is always machine-readable.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BackwriteApiError extends Error {
|
|
7
|
+
/** HTTP status of the failed response. */
|
|
8
|
+
readonly status: number;
|
|
9
|
+
/** Platform error code from the envelope (`RATE_LIMITED`, `NOT_FOUND`, …). */
|
|
10
|
+
readonly code: string;
|
|
11
|
+
/** Structured details object when the server supplied one. */
|
|
12
|
+
readonly details?: unknown;
|
|
13
|
+
/** Seconds to wait before retrying, when the server sent `retry_after`. */
|
|
14
|
+
readonly retryAfter?: number;
|
|
15
|
+
/** Correlation id echoed by the server for this request. */
|
|
16
|
+
readonly requestId?: string;
|
|
17
|
+
constructor(status: number, code: string, message: string, options?: {
|
|
18
|
+
details?: unknown;
|
|
19
|
+
retryAfter?: number;
|
|
20
|
+
requestId?: string;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Query values must survive URL serialization unchanged. */
|
|
24
|
+
export type QueryValue = string | number | boolean;
|
|
25
|
+
/** Options every generated operation accepts beyond its path parameters. */
|
|
26
|
+
export interface RequestOptions {
|
|
27
|
+
/**
|
|
28
|
+
* JSON-serializable request body. Non-JSON payloads (binary uploads such
|
|
29
|
+
* as multipart storage parts) pass bytes and are sent with an
|
|
30
|
+
* octet-stream content type.
|
|
31
|
+
*/
|
|
32
|
+
body?: unknown;
|
|
33
|
+
/** Enables A6 replay semantics on mutating endpoints. */
|
|
34
|
+
idempotencyKey?: string;
|
|
35
|
+
/** Return the full envelope (with `request_id`) instead of `data`. */
|
|
36
|
+
raw?: boolean;
|
|
37
|
+
/** Abort signal forwarded to the underlying fetch. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
import { DbService, AuthService, BranchesService, StorageService, CacheService, QueuesService, VectorService, RealtimeService, SecretsService, AdvisorsService, OrgsService } from "./services.js";
|
|
41
|
+
export interface BackwriteClientOptions {
|
|
42
|
+
/** Base URL of the gateway, e.g. `https://api.backwrite.dev`. */
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
/** API key (`bwk_…`) or session JWT; anonymous calls may omit it. */
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
/** Default project ID for scoped service methods. */
|
|
47
|
+
projectId?: string;
|
|
48
|
+
/** Default branch ID for scoped service methods. */
|
|
49
|
+
branchId?: string;
|
|
50
|
+
/** Custom fetch (testing, proxies). Defaults to globalThis.fetch. */
|
|
51
|
+
fetch?: typeof fetch;
|
|
52
|
+
/** Request timeout in milliseconds. */
|
|
53
|
+
timeoutMs?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The platform client. One instance per credential; the generated operation
|
|
57
|
+
* functions are pure adapters over `request()`.
|
|
58
|
+
*/
|
|
59
|
+
export declare class BackwriteClient {
|
|
60
|
+
private readonly baseUrl;
|
|
61
|
+
private readonly apiKey?;
|
|
62
|
+
private readonly doFetch;
|
|
63
|
+
private readonly timeoutMs?;
|
|
64
|
+
/** Default scoped project & branch IDs. */
|
|
65
|
+
readonly projectId?: string;
|
|
66
|
+
readonly branchId?: string;
|
|
67
|
+
/** Correlation id of the most recent completed request, if the server echoed one. */
|
|
68
|
+
lastRequestId?: string;
|
|
69
|
+
/** High-level ergonomic Backwrite service namespaces. */
|
|
70
|
+
readonly db: DbService;
|
|
71
|
+
readonly auth: AuthService;
|
|
72
|
+
readonly branches: BranchesService;
|
|
73
|
+
readonly storage: StorageService;
|
|
74
|
+
readonly cache: CacheService;
|
|
75
|
+
readonly queues: QueuesService;
|
|
76
|
+
readonly vector: VectorService;
|
|
77
|
+
readonly realtime: RealtimeService;
|
|
78
|
+
readonly secrets: SecretsService;
|
|
79
|
+
readonly advisors: AdvisorsService;
|
|
80
|
+
readonly orgs: OrgsService;
|
|
81
|
+
constructor(options?: BackwriteClientOptions);
|
|
82
|
+
/**
|
|
83
|
+
* Execute one platform call and transparently unwrap the envelope.
|
|
84
|
+
*
|
|
85
|
+
* Success → the `data` payload (or the full envelope with `raw`).
|
|
86
|
+
* Failure → BackwriteApiError carrying the platform error code.
|
|
87
|
+
*/
|
|
88
|
+
request<T = unknown>(method: "GET" | "PUT" | "POST" | "DELETE" | "PATCH", path: string, options?: RequestOptions & {
|
|
89
|
+
query?: Record<string, QueryValue>;
|
|
90
|
+
}): Promise<T>;
|
|
91
|
+
/** Execute arbitrary SQL query or migration on default or target branch. */
|
|
92
|
+
query(projectId: string, sql: string, options?: {
|
|
93
|
+
branchId?: string;
|
|
94
|
+
view?: string;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
success: boolean;
|
|
97
|
+
columns: string[];
|
|
98
|
+
rows: (string | null)[][];
|
|
99
|
+
summary: string;
|
|
100
|
+
execution_time_ms: number;
|
|
101
|
+
error?: string;
|
|
102
|
+
}>;
|
|
103
|
+
/** Introspect entire relational database schema in a single call. */
|
|
104
|
+
getSchema(projectId: string, options?: {
|
|
105
|
+
branchId?: string;
|
|
106
|
+
}): Promise<{
|
|
107
|
+
branch_id: string;
|
|
108
|
+
database: string;
|
|
109
|
+
tables: Array<{
|
|
110
|
+
schema: string;
|
|
111
|
+
name: string;
|
|
112
|
+
type: string;
|
|
113
|
+
columns: Array<{
|
|
114
|
+
name: string;
|
|
115
|
+
data_type: string;
|
|
116
|
+
udt_name: string;
|
|
117
|
+
nullable: boolean;
|
|
118
|
+
default: string | null;
|
|
119
|
+
position: number;
|
|
120
|
+
is_pk: boolean;
|
|
121
|
+
is_unique: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
primary_key: string[];
|
|
124
|
+
foreign_keys: Array<{
|
|
125
|
+
constraint_name: string;
|
|
126
|
+
column: string;
|
|
127
|
+
foreign_schema: string;
|
|
128
|
+
foreign_table: string;
|
|
129
|
+
foreign_column: string;
|
|
130
|
+
on_delete: string | null;
|
|
131
|
+
on_update: string | null;
|
|
132
|
+
}>;
|
|
133
|
+
indexes: Array<{
|
|
134
|
+
name: string;
|
|
135
|
+
definition: string;
|
|
136
|
+
is_primary: boolean;
|
|
137
|
+
is_unique: boolean;
|
|
138
|
+
}>;
|
|
139
|
+
policies: Array<{
|
|
140
|
+
name: string;
|
|
141
|
+
permissive: string;
|
|
142
|
+
roles: string[];
|
|
143
|
+
cmd: string;
|
|
144
|
+
qual: string;
|
|
145
|
+
with_check: string;
|
|
146
|
+
}>;
|
|
147
|
+
}>;
|
|
148
|
+
enums: Array<{
|
|
149
|
+
schema: string;
|
|
150
|
+
name: string;
|
|
151
|
+
values: string[];
|
|
152
|
+
}>;
|
|
153
|
+
}>;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAG1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO;CAU/E;AAED,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnD,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yDAAyD;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,sDAAsD;IACtD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,OAAO,EACL,SAAS,EACT,WAAW,EACX,eAAe,EACf,cAAc,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
|
|
2
|
+
//! unwrapping, and error typing.
|
|
3
|
+
//!
|
|
4
|
+
//! The generated operation layer (`operations.ts`) holds one function per
|
|
5
|
+
//! OpenAPI `operationId`. Everything the contract cannot express — base URL
|
|
6
|
+
//! resolution, credential selection, envelope handling, error classes,
|
|
7
|
+
//! idempotency keys, retry-after observance — lives here and stays identical
|
|
8
|
+
//! for every generated call.
|
|
9
|
+
//!
|
|
10
|
+
//! Envelope transparency (platform API §5/§7): every response body is
|
|
11
|
+
//! `{ "data": ..., "request_id": "..." }` on success and
|
|
12
|
+
//! `{ "error": { "code", "message", "details?", "retry_after?" }, "request_id" }`
|
|
13
|
+
//! on failure. `request()` unwraps `data` by default so callers operate on
|
|
14
|
+
//! the payload itself; `raw: true` returns the full envelope (and the
|
|
15
|
+
//! `request_id` needed to correlate with server logs).
|
|
16
|
+
/**
|
|
17
|
+
* A structured API failure. Every non-2xx response is raised as this class,
|
|
18
|
+
* so `instanceof BackwriteApiError` is the single catch boundary and the
|
|
19
|
+
* platform error code (e.g. `BRANCH_NOT_READY`) is always machine-readable.
|
|
20
|
+
*/
|
|
21
|
+
export class BackwriteApiError extends Error {
|
|
22
|
+
/** HTTP status of the failed response. */
|
|
23
|
+
status;
|
|
24
|
+
/** Platform error code from the envelope (`RATE_LIMITED`, `NOT_FOUND`, …). */
|
|
25
|
+
code;
|
|
26
|
+
/** Structured details object when the server supplied one. */
|
|
27
|
+
details;
|
|
28
|
+
/** Seconds to wait before retrying, when the server sent `retry_after`. */
|
|
29
|
+
retryAfter;
|
|
30
|
+
/** Correlation id echoed by the server for this request. */
|
|
31
|
+
requestId;
|
|
32
|
+
constructor(status, code, message, options = {}) {
|
|
33
|
+
super(`${code} (${status}): ${message}`);
|
|
34
|
+
this.name = "BackwriteApiError";
|
|
35
|
+
this.status = status;
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.details = options.details;
|
|
38
|
+
this.retryAfter = options.retryAfter;
|
|
39
|
+
this.requestId = options.requestId;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
import { DbService, AuthService, BranchesService, StorageService, CacheService, QueuesService, VectorService, RealtimeService, SecretsService, AdvisorsService, OrgsService, } from "./services.js";
|
|
43
|
+
function isBinaryBody(body) {
|
|
44
|
+
return body instanceof ArrayBuffer || body instanceof Uint8Array;
|
|
45
|
+
}
|
|
46
|
+
function buildUrl(baseUrl, path, query) {
|
|
47
|
+
const url = new URL(path, baseUrl);
|
|
48
|
+
for (const [key, value] of Object.entries(query)) {
|
|
49
|
+
url.searchParams.set(key, String(value));
|
|
50
|
+
}
|
|
51
|
+
return url;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The platform client. One instance per credential; the generated operation
|
|
55
|
+
* functions are pure adapters over `request()`.
|
|
56
|
+
*/
|
|
57
|
+
export class BackwriteClient {
|
|
58
|
+
baseUrl;
|
|
59
|
+
apiKey;
|
|
60
|
+
doFetch;
|
|
61
|
+
timeoutMs;
|
|
62
|
+
/** Default scoped project & branch IDs. */
|
|
63
|
+
projectId;
|
|
64
|
+
branchId;
|
|
65
|
+
/** Correlation id of the most recent completed request, if the server echoed one. */
|
|
66
|
+
lastRequestId;
|
|
67
|
+
/** High-level ergonomic Backwrite service namespaces. */
|
|
68
|
+
db;
|
|
69
|
+
auth;
|
|
70
|
+
branches;
|
|
71
|
+
storage;
|
|
72
|
+
cache;
|
|
73
|
+
queues;
|
|
74
|
+
vector;
|
|
75
|
+
realtime;
|
|
76
|
+
secrets;
|
|
77
|
+
advisors;
|
|
78
|
+
orgs;
|
|
79
|
+
constructor(options = {}) {
|
|
80
|
+
const resolvedBase = options.baseUrl ?? "https://api.backwrite.dev";
|
|
81
|
+
this.baseUrl = resolvedBase.replace(/\/+$/, "");
|
|
82
|
+
this.apiKey = options.apiKey;
|
|
83
|
+
this.projectId = options.projectId;
|
|
84
|
+
this.branchId = options.branchId;
|
|
85
|
+
this.doFetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
86
|
+
this.timeoutMs = options.timeoutMs;
|
|
87
|
+
this.db = new DbService(this);
|
|
88
|
+
this.auth = new AuthService(this);
|
|
89
|
+
this.branches = new BranchesService(this);
|
|
90
|
+
this.storage = new StorageService(this);
|
|
91
|
+
this.cache = new CacheService(this);
|
|
92
|
+
this.queues = new QueuesService(this);
|
|
93
|
+
this.vector = new VectorService(this);
|
|
94
|
+
this.realtime = new RealtimeService(this);
|
|
95
|
+
this.secrets = new SecretsService(this);
|
|
96
|
+
this.advisors = new AdvisorsService(this);
|
|
97
|
+
this.orgs = new OrgsService(this);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Execute one platform call and transparently unwrap the envelope.
|
|
101
|
+
*
|
|
102
|
+
* Success → the `data` payload (or the full envelope with `raw`).
|
|
103
|
+
* Failure → BackwriteApiError carrying the platform error code.
|
|
104
|
+
*/
|
|
105
|
+
async request(method, path, options = {}) {
|
|
106
|
+
const url = buildUrl(this.baseUrl, path, options.query ?? {});
|
|
107
|
+
const headers = {};
|
|
108
|
+
if (this.apiKey) {
|
|
109
|
+
headers["authorization"] = `Bearer ${this.apiKey}`;
|
|
110
|
+
if (this.apiKey.startsWith("bwk_") || this.apiKey.startsWith("bw_")) {
|
|
111
|
+
headers["apikey"] = this.apiKey;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (options.idempotencyKey)
|
|
115
|
+
headers["idempotency-key"] = options.idempotencyKey;
|
|
116
|
+
let payload;
|
|
117
|
+
if (options.body !== undefined) {
|
|
118
|
+
if (isBinaryBody(options.body)) {
|
|
119
|
+
headers["content-type"] = "application/octet-stream";
|
|
120
|
+
payload = options.body;
|
|
121
|
+
}
|
|
122
|
+
else if (typeof options.body === "string") {
|
|
123
|
+
headers["content-type"] = "application/json";
|
|
124
|
+
payload = options.body;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
headers["content-type"] = "application/json";
|
|
128
|
+
payload = JSON.stringify(options.body);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const controller = this.timeoutMs !== undefined ? new AbortController() : undefined;
|
|
132
|
+
const timer = controller && this.timeoutMs !== undefined
|
|
133
|
+
? setTimeout(() => controller.abort(), this.timeoutMs)
|
|
134
|
+
: undefined;
|
|
135
|
+
if (controller && options.signal) {
|
|
136
|
+
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const response = await this.doFetch(url, {
|
|
140
|
+
method,
|
|
141
|
+
headers,
|
|
142
|
+
body: payload,
|
|
143
|
+
signal: controller?.signal ?? options.signal,
|
|
144
|
+
});
|
|
145
|
+
const text = await response.text();
|
|
146
|
+
const requestId = response.headers.get("x-request-id") ??
|
|
147
|
+
(text ? (safeParse(text)?.request_id ?? undefined) : undefined);
|
|
148
|
+
if (requestId)
|
|
149
|
+
this.lastRequestId = requestId;
|
|
150
|
+
const parsed = text ? safeParse(text) : null;
|
|
151
|
+
if (!response.ok) {
|
|
152
|
+
const err = parsed?.error;
|
|
153
|
+
throw new BackwriteApiError(response.status, err?.code ?? `HTTP_${response.status}`, err?.message ?? (response.statusText || "request failed"), {
|
|
154
|
+
details: err?.details,
|
|
155
|
+
retryAfter: err?.retry_after,
|
|
156
|
+
requestId,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (options.raw) {
|
|
160
|
+
// The correlation id always reaches the caller in raw mode: from the
|
|
161
|
+
// body when stamped, else from the x-request-id header (parity with
|
|
162
|
+
// the Python runtime).
|
|
163
|
+
const envelope = (parsed ?? {});
|
|
164
|
+
if (envelope &&
|
|
165
|
+
typeof envelope === "object" &&
|
|
166
|
+
envelope.request_id === undefined &&
|
|
167
|
+
requestId !== undefined) {
|
|
168
|
+
return { ...envelope, request_id: requestId };
|
|
169
|
+
}
|
|
170
|
+
return envelope;
|
|
171
|
+
}
|
|
172
|
+
// Non-JSON 2xx (e.g. metrics text) surfaces as-is through data-less envelopes.
|
|
173
|
+
if (parsed === null)
|
|
174
|
+
return text;
|
|
175
|
+
return (parsed.data !== undefined ? parsed.data : parsed);
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
if (timer !== undefined)
|
|
179
|
+
clearTimeout(timer);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Execute arbitrary SQL query or migration on default or target branch. */
|
|
183
|
+
async query(projectId, sql, options = {}) {
|
|
184
|
+
const path = options.branchId
|
|
185
|
+
? `/v1/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(options.branchId)}/query`
|
|
186
|
+
: `/v1/projects/${encodeURIComponent(projectId)}/query`;
|
|
187
|
+
return (await this.request("POST", path, {
|
|
188
|
+
body: { sql, view: options.view ?? "raw" },
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
/** Introspect entire relational database schema in a single call. */
|
|
192
|
+
async getSchema(projectId, options = {}) {
|
|
193
|
+
const path = options.branchId
|
|
194
|
+
? `/v1/projects/${encodeURIComponent(projectId)}/branches/${encodeURIComponent(options.branchId)}/schema`
|
|
195
|
+
: `/v1/projects/${encodeURIComponent(projectId)}/schema`;
|
|
196
|
+
return (await this.request("GET", path));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function safeParse(text) {
|
|
200
|
+
try {
|
|
201
|
+
return JSON.parse(text);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,iCAAiC;AACjC,GAAG;AACH,0EAA0E;AAC1E,4EAA4E;AAC5E,uEAAuE;AACvE,6EAA6E;AAC7E,6BAA6B;AAC7B,GAAG;AACH,sEAAsE;AACtE,yDAAyD;AACzD,kFAAkF;AAClF,2EAA2E;AAC3E,sEAAsE;AACtE,uDAAuD;AAEvD;;;;GAIG;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;IAC7B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAa,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BackwriteClient, BackwriteApiError, RequestOptions, BackwriteClientOptions } from "./client.js";
|
|
2
|
+
import * as operations from "./operations.js";
|
|
3
|
+
import { OPERATION_META } from "./operations.js";
|
|
4
|
+
export { BackwriteClient, BackwriteApiError };
|
|
5
|
+
export type { RequestOptions, BackwriteClientOptions };
|
|
6
|
+
export { operations, OPERATION_META };
|
|
7
|
+
export * from "./services.js";
|
|
8
|
+
type RequestLike = (method: "GET" | "PUT" | "POST" | "DELETE" | "PATCH", path: string, options?: RequestOptions & {
|
|
9
|
+
query?: Record<string, string | number | boolean>;
|
|
10
|
+
}) => Promise<unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Attach every generated operation as a prototype method named in camelCase
|
|
13
|
+
* (e.g. `getBranchCredentials`, `putStorageObject`). The generated module's
|
|
14
|
+
* function signature already takes the client as its first argument, so the
|
|
15
|
+
* binding is a pure partial application — no logic duplication.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bindOperations(client: BackwriteClient): BackwriteClient;
|
|
18
|
+
/**
|
|
19
|
+
* Convenience constructor: returns a client with operations pre-bound.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const bw = createBackwriteClient(process.env.BACKWRITE_URL!, process.env.BACKWRITE_SERVICE_KEY!);
|
|
23
|
+
* const branch = await bw.getBranchCredentials("br_…");
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createBackwriteClient(baseUrl: string, apiKey?: string, options?: Partial<ConstructorParameters<typeof BackwriteClient>[0]>): BackwriteClient;
|
|
27
|
+
/** Ergonomic options-object factory (`createClient({ apiKey, projectId, branchId })`). */
|
|
28
|
+
export declare function createClient(options?: BackwriteClientOptions): BackwriteClient;
|
|
29
|
+
export type { RequestLike };
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;AACtC,cAAc,eAAe,CAAC;AAE9B,KAAK,WAAW,GAAG,CACjB,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,EACnD,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CAAE,KAC7E,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAOvE;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,GAAE,OAAO,CAAC,qBAAqB,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAM,GACtE,eAAe,CAEjB;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAElF;AAED,YAAY,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//! Backwrite TypeScript SDK entrypoint.
|
|
2
|
+
//!
|
|
3
|
+
//! `BackwriteClient` is the hand-written runtime (transport, envelope
|
|
4
|
+
//! unwrapping, typed errors). The generated layer in `operations` adds one
|
|
5
|
+
//! typed function per OpenAPI operation; `bindOperations` attaches them to
|
|
6
|
+
//! the client prototype so `client.listBranches(...)` style calls work
|
|
7
|
+
//! directly while the standalone functions remain available.
|
|
8
|
+
import { BackwriteClient, BackwriteApiError } from "./client.js";
|
|
9
|
+
import * as operations from "./operations.js";
|
|
10
|
+
import { OPERATION_META } from "./operations.js";
|
|
11
|
+
export { BackwriteClient, BackwriteApiError };
|
|
12
|
+
export { operations, OPERATION_META };
|
|
13
|
+
export * from "./services.js";
|
|
14
|
+
/**
|
|
15
|
+
* Attach every generated operation as a prototype method named in camelCase
|
|
16
|
+
* (e.g. `getBranchCredentials`, `putStorageObject`). The generated module's
|
|
17
|
+
* function signature already takes the client as its first argument, so the
|
|
18
|
+
* binding is a pure partial application — no logic duplication.
|
|
19
|
+
*/
|
|
20
|
+
export function bindOperations(client) {
|
|
21
|
+
const target = client;
|
|
22
|
+
for (const [name, fn] of Object.entries(operations)) {
|
|
23
|
+
if (typeof fn !== "function")
|
|
24
|
+
continue;
|
|
25
|
+
target[name] = fn.bind(null, client);
|
|
26
|
+
}
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convenience constructor: returns a client with operations pre-bound.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const bw = createBackwriteClient(process.env.BACKWRITE_URL!, process.env.BACKWRITE_SERVICE_KEY!);
|
|
34
|
+
* const branch = await bw.getBranchCredentials("br_…");
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function createBackwriteClient(baseUrl, apiKey, options = {}) {
|
|
38
|
+
return bindOperations(new BackwriteClient({ baseUrl, apiKey, ...options }));
|
|
39
|
+
}
|
|
40
|
+
/** Ergonomic options-object factory (`createClient({ apiKey, projectId, branchId })`). */
|
|
41
|
+
export function createClient(options = {}) {
|
|
42
|
+
return bindOperations(new BackwriteClient(options));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,GAAG;AACH,sEAAsE;AACtE,2EAA2E;AAC3E,2EAA2E;AAC3E,uEAAuE;AACvE,6DAA6D;AAE7D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAA0C,MAAM,aAAa,CAAC;AACzG,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;AACtC,cAAc,eAAe,CAAC;AAQ9B;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB;IACpD,MAAM,MAAM,GAAG,MAA4C,CAAC;IAC5D,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,IAAI,OAAO,EAAE,KAAK,UAAU;YAAE,SAAS;QACvC,MAAM,CAAC,IAAI,CAAC,GAAI,EAA0D,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,MAAe,EACf,UAAqE,EAAE;IAEvE,OAAO,cAAc,CAAC,IAAI,eAAe,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,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