@functional-systems/lambdadb 0.2.1 → 0.3.0-dev
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 +54 -49
- package/dist/commonjs/client.d.ts +107 -0
- package/dist/commonjs/client.d.ts.map +1 -0
- package/dist/commonjs/client.js +163 -0
- package/dist/commonjs/client.js.map +1 -0
- package/dist/commonjs/index.d.ts +2 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +5 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/client.d.ts +107 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +158 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/examples/collectionScoped.example.ts +32 -0
- package/examples/collectionsList.example.ts +8 -12
- package/package.json +5 -3
- package/src/client.ts +272 -0
- package/src/index.ts +7 -0
- package/_speakeasy/.github/action-inputs-config.json +0 -53
- package/_speakeasy/.github/action-security-config.json +0 -88
package/README.md
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *LambdaDB* API.
|
|
4
4
|
|
|
5
5
|
<div align="left">
|
|
6
|
-
<a href="https://
|
|
7
|
-
|
|
8
|
-
<img src="https://img.shields.io/badge/License-MIT-blue.svg" style="width: 100px; height: 28px;" />
|
|
6
|
+
<a href="https://opensource.org/licenses/Apache-2.0">
|
|
7
|
+
<img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg" style="width: 100px; height: 28px;" />
|
|
9
8
|
</a>
|
|
10
9
|
</div>
|
|
11
10
|
|
|
@@ -80,23 +79,30 @@ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
|
|
|
80
79
|
<!-- Start SDK Example Usage [usage] -->
|
|
81
80
|
## SDK Example Usage
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
We recommend the **collection-scoped client** (`LambdaDBClient`): you get a handle for a collection once and then call methods without passing `collectionName` on every request.
|
|
83
|
+
|
|
84
|
+
### Recommended: LambdaDBClient (collection-scoped)
|
|
84
85
|
|
|
85
86
|
```typescript
|
|
86
|
-
import {
|
|
87
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
87
88
|
|
|
88
|
-
const
|
|
89
|
+
const client = new LambdaDBClient({
|
|
89
90
|
projectApiKey: "<YOUR_PROJECT_API_KEY>",
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
async function run() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
console.log(
|
|
94
|
+
// List all collections in the project
|
|
95
|
+
const list = await client.listCollections();
|
|
96
|
+
console.log(list);
|
|
97
|
+
|
|
98
|
+
// Work with a specific collection — no collectionName in every call
|
|
99
|
+
const collection = client.collection("my-collection");
|
|
100
|
+
await collection.get();
|
|
101
|
+
await collection.docs.list({ size: 20 });
|
|
102
|
+
await collection.docs.upsert({ docs: [{ id: "1", text: "hello" }] });
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
run();
|
|
99
|
-
|
|
100
106
|
```
|
|
101
107
|
<!-- End SDK Example Usage [usage] -->
|
|
102
108
|
|
|
@@ -113,20 +119,18 @@ This SDK supports the following security scheme globally:
|
|
|
113
119
|
|
|
114
120
|
To authenticate with the API the `projectApiKey` parameter must be set when initializing the SDK client instance. For example:
|
|
115
121
|
```typescript
|
|
116
|
-
import {
|
|
122
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
117
123
|
|
|
118
|
-
const
|
|
124
|
+
const client = new LambdaDBClient({
|
|
119
125
|
projectApiKey: "<YOUR_PROJECT_API_KEY>",
|
|
120
126
|
});
|
|
121
127
|
|
|
122
128
|
async function run() {
|
|
123
|
-
const result = await
|
|
124
|
-
|
|
129
|
+
const result = await client.listCollections();
|
|
125
130
|
console.log(result);
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
run();
|
|
129
|
-
|
|
130
134
|
```
|
|
131
135
|
<!-- End Authentication [security] -->
|
|
132
136
|
|
|
@@ -158,6 +162,20 @@ run();
|
|
|
158
162
|
</details>
|
|
159
163
|
<!-- End Available Resources and Operations [operations] -->
|
|
160
164
|
|
|
165
|
+
### Legacy API (`LambdaDB`)
|
|
166
|
+
|
|
167
|
+
The classic client `LambdaDB` is still supported for compatibility. New code should prefer `LambdaDBClient` and `client.collection(name)`.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { LambdaDB } from "@functional-systems/lambdadb";
|
|
171
|
+
|
|
172
|
+
const lambdaDB = new LambdaDB({ projectApiKey: "<YOUR_PROJECT_API_KEY>" });
|
|
173
|
+
const result = await lambdaDB.collections.list();
|
|
174
|
+
await lambdaDB.collections.docs.listDocs({ collectionName: "my-collection", size: 20 });
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
See [docs/sdks/collections/README.md](docs/sdks/collections/README.md) and [docs/sdks/docs/README.md](docs/sdks/docs/README.md) for the full legacy API reference.
|
|
178
|
+
|
|
161
179
|
<!-- Start Standalone functions [standalone-funcs] -->
|
|
162
180
|
## Standalone functions
|
|
163
181
|
|
|
@@ -197,14 +215,14 @@ Some of the endpoints in this SDK support retries. If you use the SDK without a
|
|
|
197
215
|
|
|
198
216
|
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
|
|
199
217
|
```typescript
|
|
200
|
-
import {
|
|
218
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
201
219
|
|
|
202
|
-
const
|
|
220
|
+
const client = new LambdaDBClient({
|
|
203
221
|
projectApiKey: "<YOUR_PROJECT_API_KEY>",
|
|
204
222
|
});
|
|
205
223
|
|
|
206
224
|
async function run() {
|
|
207
|
-
const result = await
|
|
225
|
+
const result = await client.listCollections({
|
|
208
226
|
retries: {
|
|
209
227
|
strategy: "backoff",
|
|
210
228
|
backoff: {
|
|
@@ -216,19 +234,17 @@ async function run() {
|
|
|
216
234
|
retryConnectionErrors: false,
|
|
217
235
|
},
|
|
218
236
|
});
|
|
219
|
-
|
|
220
237
|
console.log(result);
|
|
221
238
|
}
|
|
222
239
|
|
|
223
240
|
run();
|
|
224
|
-
|
|
225
241
|
```
|
|
226
242
|
|
|
227
243
|
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
|
|
228
244
|
```typescript
|
|
229
|
-
import {
|
|
245
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
230
246
|
|
|
231
|
-
const
|
|
247
|
+
const client = new LambdaDBClient({
|
|
232
248
|
retryConfig: {
|
|
233
249
|
strategy: "backoff",
|
|
234
250
|
backoff: {
|
|
@@ -243,8 +259,7 @@ const lambdaDB = new LambdaDB({
|
|
|
243
259
|
});
|
|
244
260
|
|
|
245
261
|
async function run() {
|
|
246
|
-
const result = await
|
|
247
|
-
|
|
262
|
+
const result = await client.listCollections();
|
|
248
263
|
console.log(result);
|
|
249
264
|
}
|
|
250
265
|
|
|
@@ -269,17 +284,16 @@ run();
|
|
|
269
284
|
|
|
270
285
|
### Example
|
|
271
286
|
```typescript
|
|
272
|
-
import {
|
|
287
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
273
288
|
import * as errors from "@functional-systems/lambdadb/models/errors";
|
|
274
289
|
|
|
275
|
-
const
|
|
290
|
+
const client = new LambdaDBClient({
|
|
276
291
|
projectApiKey: "<YOUR_PROJECT_API_KEY>",
|
|
277
292
|
});
|
|
278
293
|
|
|
279
294
|
async function run() {
|
|
280
295
|
try {
|
|
281
|
-
const result = await
|
|
282
|
-
|
|
296
|
+
const result = await client.listCollections();
|
|
283
297
|
console.log(result);
|
|
284
298
|
} catch (error) {
|
|
285
299
|
// The base class for HTTP error responses
|
|
@@ -345,43 +359,39 @@ The default server `https://{projectHost}` contains variables and is set to `htt
|
|
|
345
359
|
#### Example
|
|
346
360
|
|
|
347
361
|
```typescript
|
|
348
|
-
import {
|
|
362
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
349
363
|
|
|
350
|
-
const
|
|
364
|
+
const client = new LambdaDBClient({
|
|
351
365
|
serverIdx: 0,
|
|
352
366
|
projectHost: "api.lambdadb.com/projects/default",
|
|
353
367
|
projectApiKey: "<YOUR_PROJECT_API_KEY>",
|
|
354
368
|
});
|
|
355
369
|
|
|
356
370
|
async function run() {
|
|
357
|
-
const result = await
|
|
358
|
-
|
|
371
|
+
const result = await client.listCollections();
|
|
359
372
|
console.log(result);
|
|
360
373
|
}
|
|
361
374
|
|
|
362
375
|
run();
|
|
363
|
-
|
|
364
376
|
```
|
|
365
377
|
|
|
366
378
|
### Override Server URL Per-Client
|
|
367
379
|
|
|
368
380
|
The default server can be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:
|
|
369
381
|
```typescript
|
|
370
|
-
import {
|
|
382
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
371
383
|
|
|
372
|
-
const
|
|
384
|
+
const client = new LambdaDBClient({
|
|
373
385
|
serverURL: "https://api.lambdadb.com/projects/default",
|
|
374
386
|
projectApiKey: "<YOUR_PROJECT_API_KEY>",
|
|
375
387
|
});
|
|
376
388
|
|
|
377
389
|
async function run() {
|
|
378
|
-
const result = await
|
|
379
|
-
|
|
390
|
+
const result = await client.listCollections();
|
|
380
391
|
console.log(result);
|
|
381
392
|
}
|
|
382
393
|
|
|
383
394
|
run();
|
|
384
|
-
|
|
385
395
|
```
|
|
386
396
|
<!-- End Server Selection [server] -->
|
|
387
397
|
|
|
@@ -403,7 +413,7 @@ custom header and a timeout to requests and how to use the `"requestError"` hook
|
|
|
403
413
|
to log errors:
|
|
404
414
|
|
|
405
415
|
```typescript
|
|
406
|
-
import {
|
|
416
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
407
417
|
import { HTTPClient } from "@functional-systems/lambdadb/lib/http";
|
|
408
418
|
|
|
409
419
|
const httpClient = new HTTPClient({
|
|
@@ -430,7 +440,7 @@ httpClient.addHook("requestError", (error, request) => {
|
|
|
430
440
|
console.groupEnd();
|
|
431
441
|
});
|
|
432
442
|
|
|
433
|
-
const
|
|
443
|
+
const client = new LambdaDBClient({ httpClient, projectApiKey: "<YOUR_PROJECT_API_KEY>" });
|
|
434
444
|
```
|
|
435
445
|
<!-- End Custom HTTP Client [http-client] -->
|
|
436
446
|
|
|
@@ -445,25 +455,20 @@ You can pass a logger that matches `console`'s interface as an SDK option.
|
|
|
445
455
|
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
|
|
446
456
|
|
|
447
457
|
```typescript
|
|
448
|
-
import {
|
|
458
|
+
import { LambdaDBClient } from "@functional-systems/lambdadb";
|
|
449
459
|
|
|
450
|
-
const
|
|
460
|
+
const client = new LambdaDBClient({ debugLogger: console, projectApiKey: "<YOUR_PROJECT_API_KEY>" });
|
|
451
461
|
```
|
|
452
462
|
|
|
453
463
|
You can also enable a default debug logger by setting an environment variable `LAMBDADB_DEBUG` to true.
|
|
454
464
|
<!-- End Debugging [debug] -->
|
|
455
465
|
|
|
456
|
-
<!-- Placeholder for Future Speakeasy SDK Sections -->
|
|
457
|
-
|
|
458
466
|
# Development
|
|
459
467
|
|
|
460
468
|
## Maturity
|
|
461
469
|
|
|
462
|
-
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
|
|
463
|
-
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
|
|
464
|
-
looking for the latest version.
|
|
470
|
+
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version unless you are intentionally looking for the latest version.
|
|
465
471
|
|
|
466
472
|
## Contributions
|
|
467
473
|
|
|
468
|
-
|
|
469
|
-
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
|
|
474
|
+
We welcome contributions. The recommended API is implemented in `src/client.ts` (LambdaDBClient, collection-scoped). The rest of `src/` (funcs, models, lib) is maintained manually; see [docs/OPENAPI_UPDATE.md](docs/OPENAPI_UPDATE.md) for how API changes are applied. Feel free to open a PR or an issue.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection-scoped facade for LambdaDB API.
|
|
3
|
+
* Use this client for a better DX: no need to pass collectionName on every call.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const client = new LambdaDBClient({ projectApiKey: "..." });
|
|
7
|
+
* const collection = client.collection("my-collection");
|
|
8
|
+
* await collection.get();
|
|
9
|
+
* await collection.docs.list({ size: 20 });
|
|
10
|
+
* await collection.docs.upsert({ docs: [{ id: "1", text: "hello" }] });
|
|
11
|
+
*/
|
|
12
|
+
import { LambdaDBCore } from "./core.js";
|
|
13
|
+
import type { RequestOptions } from "./lib/sdks.js";
|
|
14
|
+
import type * as operations from "./models/operations/index.js";
|
|
15
|
+
import type * as models from "./models/index.js";
|
|
16
|
+
export type { RequestOptions };
|
|
17
|
+
export type { operations, models };
|
|
18
|
+
/**
|
|
19
|
+
* Client with collection-scoped API. Prefer this over the legacy
|
|
20
|
+
* `LambdaDB` when you want to avoid passing collectionName on every call.
|
|
21
|
+
*/
|
|
22
|
+
export declare class LambdaDBClient extends LambdaDBCore {
|
|
23
|
+
/**
|
|
24
|
+
* Get a handle for a specific collection. All methods on the handle
|
|
25
|
+
* use this collection name; you do not pass it again.
|
|
26
|
+
*/
|
|
27
|
+
collection(collectionName: string): CollectionHandle;
|
|
28
|
+
/**
|
|
29
|
+
* List all collections in the project.
|
|
30
|
+
*/
|
|
31
|
+
listCollections(options?: RequestOptions): Promise<operations.ListCollectionsResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new collection.
|
|
34
|
+
*/
|
|
35
|
+
createCollection(request: operations.CreateCollectionRequest, options?: RequestOptions): Promise<operations.CreateCollectionResponse>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Handle for a single collection. All methods operate on this collection.
|
|
39
|
+
*/
|
|
40
|
+
export declare class CollectionHandle {
|
|
41
|
+
private readonly client;
|
|
42
|
+
readonly collectionName: string;
|
|
43
|
+
constructor(client: LambdaDBCore, collectionName: string);
|
|
44
|
+
/**
|
|
45
|
+
* Get metadata of this collection.
|
|
46
|
+
*/
|
|
47
|
+
get(options?: RequestOptions): Promise<operations.GetCollectionResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Configure (update) this collection.
|
|
50
|
+
*/
|
|
51
|
+
update(requestBody: operations.UpdateCollectionRequestBody, options?: RequestOptions): Promise<operations.UpdateCollectionResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Delete this collection.
|
|
54
|
+
*/
|
|
55
|
+
delete(options?: RequestOptions): Promise<models.MessageResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Search this collection with a query.
|
|
58
|
+
*/
|
|
59
|
+
query(requestBody: operations.QueryCollectionRequestBody, options?: RequestOptions): Promise<operations.QueryCollectionResponse>;
|
|
60
|
+
readonly docs: CollectionDocs;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Document operations scoped to a collection.
|
|
64
|
+
*/
|
|
65
|
+
declare class CollectionDocs {
|
|
66
|
+
private readonly client;
|
|
67
|
+
private readonly collectionName;
|
|
68
|
+
constructor(client: LambdaDBCore, collectionName: string);
|
|
69
|
+
/**
|
|
70
|
+
* List documents in the collection.
|
|
71
|
+
*/
|
|
72
|
+
list(params?: {
|
|
73
|
+
size?: number;
|
|
74
|
+
pageToken?: string;
|
|
75
|
+
}, options?: RequestOptions): Promise<operations.ListDocsResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Upsert documents. Max payload 6MB.
|
|
78
|
+
*/
|
|
79
|
+
upsert(body: {
|
|
80
|
+
docs: Array<Record<string, unknown>>;
|
|
81
|
+
}, options?: RequestOptions): Promise<models.MessageResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Update documents (each doc must have id). Max payload 6MB.
|
|
84
|
+
*/
|
|
85
|
+
update(body: {
|
|
86
|
+
docs: Array<Record<string, unknown>>;
|
|
87
|
+
}, options?: RequestOptions): Promise<models.MessageResponse>;
|
|
88
|
+
/**
|
|
89
|
+
* Delete documents by ids and/or filter.
|
|
90
|
+
*/
|
|
91
|
+
delete(body: operations.DeleteDocsRequestBody, options?: RequestOptions): Promise<models.MessageResponse>;
|
|
92
|
+
/**
|
|
93
|
+
* Fetch documents by IDs (max 100).
|
|
94
|
+
*/
|
|
95
|
+
fetch(body: operations.FetchDocsRequestBody, options?: RequestOptions): Promise<operations.FetchDocsResponse>;
|
|
96
|
+
/**
|
|
97
|
+
* Get presigned URL and metadata for bulk upload (up to 200MB).
|
|
98
|
+
*/
|
|
99
|
+
getBulkUpsert(options?: RequestOptions): Promise<operations.GetBulkUpsertDocsResponse>;
|
|
100
|
+
/**
|
|
101
|
+
* Trigger bulk upsert with an object key from getBulkUpsert().
|
|
102
|
+
*/
|
|
103
|
+
bulkUpsert(body: {
|
|
104
|
+
objectKey: string;
|
|
105
|
+
}, options?: RequestOptions): Promise<models.MessageResponse>;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAczC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAGjD,YAAY,EAAE,cAAc,EAAE,CAAC;AAG/B,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAEnC;;;GAGG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C;;;OAGG;IACH,UAAU,CAAC,cAAc,EAA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,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KAAE,EAC9C,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAalC;;OAEG;IACG,MAAM,CACV,IAAI,EAAE,UAAU,CAAC,qBAAqB,EACtC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAalC;;OAEG;IACG,KAAK,CACT,IAAI,EAAE,UAAU,CAAC,oBAAoB,EACrC,OAAO,CAAC,EAAE,cAAc;IAc1B;;OAEG;IACG,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc;IAU5C;;OAEG;IACG,UAAU,CACd,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;CAYnC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Collection-scoped facade for LambdaDB API.
|
|
4
|
+
* Use this client for a better DX: no need to pass collectionName on every call.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const client = new LambdaDBClient({ projectApiKey: "..." });
|
|
8
|
+
* const collection = client.collection("my-collection");
|
|
9
|
+
* await collection.get();
|
|
10
|
+
* await collection.docs.list({ size: 20 });
|
|
11
|
+
* await collection.docs.upsert({ docs: [{ id: "1", text: "hello" }] });
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.CollectionHandle = exports.LambdaDBClient = void 0;
|
|
15
|
+
const core_js_1 = require("./core.js");
|
|
16
|
+
const collectionsCreate_js_1 = require("./funcs/collectionsCreate.js");
|
|
17
|
+
const collectionsDelete_js_1 = require("./funcs/collectionsDelete.js");
|
|
18
|
+
const collectionsGet_js_1 = require("./funcs/collectionsGet.js");
|
|
19
|
+
const collectionsList_js_1 = require("./funcs/collectionsList.js");
|
|
20
|
+
const collectionsQuery_js_1 = require("./funcs/collectionsQuery.js");
|
|
21
|
+
const collectionsUpdate_js_1 = require("./funcs/collectionsUpdate.js");
|
|
22
|
+
const collectionsDocsBulkUpsert_js_1 = require("./funcs/collectionsDocsBulkUpsert.js");
|
|
23
|
+
const collectionsDocsDelete_js_1 = require("./funcs/collectionsDocsDelete.js");
|
|
24
|
+
const collectionsDocsFetch_js_1 = require("./funcs/collectionsDocsFetch.js");
|
|
25
|
+
const collectionsDocsGetBulkUpsert_js_1 = require("./funcs/collectionsDocsGetBulkUpsert.js");
|
|
26
|
+
const collectionsDocsListDocs_js_1 = require("./funcs/collectionsDocsListDocs.js");
|
|
27
|
+
const collectionsDocsUpdate_js_1 = require("./funcs/collectionsDocsUpdate.js");
|
|
28
|
+
const collectionsDocsUpsert_js_1 = require("./funcs/collectionsDocsUpsert.js");
|
|
29
|
+
const fp_js_1 = require("./types/fp.js");
|
|
30
|
+
/**
|
|
31
|
+
* Client with collection-scoped API. Prefer this over the legacy
|
|
32
|
+
* `LambdaDB` when you want to avoid passing collectionName on every call.
|
|
33
|
+
*/
|
|
34
|
+
class LambdaDBClient extends core_js_1.LambdaDBCore {
|
|
35
|
+
/**
|
|
36
|
+
* Get a handle for a specific collection. All methods on the handle
|
|
37
|
+
* use this collection name; you do not pass it again.
|
|
38
|
+
*/
|
|
39
|
+
collection(collectionName) {
|
|
40
|
+
return new CollectionHandle(this, collectionName);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* List all collections in the project.
|
|
44
|
+
*/
|
|
45
|
+
async listCollections(options) {
|
|
46
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsList_js_1.collectionsList)(this, options));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a new collection.
|
|
50
|
+
*/
|
|
51
|
+
async createCollection(request, options) {
|
|
52
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsCreate_js_1.collectionsCreate)(this, request, options));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.LambdaDBClient = LambdaDBClient;
|
|
56
|
+
/**
|
|
57
|
+
* Handle for a single collection. All methods operate on this collection.
|
|
58
|
+
*/
|
|
59
|
+
class CollectionHandle {
|
|
60
|
+
constructor(client, collectionName) {
|
|
61
|
+
this.client = client;
|
|
62
|
+
this.collectionName = collectionName;
|
|
63
|
+
this.docs = new CollectionDocs(this.client, this.collectionName);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get metadata of this collection.
|
|
67
|
+
*/
|
|
68
|
+
async get(options) {
|
|
69
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsGet_js_1.collectionsGet)(this.client, { collectionName: this.collectionName }, options));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Configure (update) this collection.
|
|
73
|
+
*/
|
|
74
|
+
async update(requestBody, options) {
|
|
75
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsUpdate_js_1.collectionsUpdate)(this.client, {
|
|
76
|
+
collectionName: this.collectionName,
|
|
77
|
+
requestBody,
|
|
78
|
+
}, options));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Delete this collection.
|
|
82
|
+
*/
|
|
83
|
+
async delete(options) {
|
|
84
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDelete_js_1.collectionsDelete)(this.client, { collectionName: this.collectionName }, options));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Search this collection with a query.
|
|
88
|
+
*/
|
|
89
|
+
async query(requestBody, options) {
|
|
90
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsQuery_js_1.collectionsQuery)(this.client, {
|
|
91
|
+
collectionName: this.collectionName,
|
|
92
|
+
requestBody,
|
|
93
|
+
}, options));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.CollectionHandle = CollectionHandle;
|
|
97
|
+
/**
|
|
98
|
+
* Document operations scoped to a collection.
|
|
99
|
+
*/
|
|
100
|
+
class CollectionDocs {
|
|
101
|
+
constructor(client, collectionName) {
|
|
102
|
+
this.client = client;
|
|
103
|
+
this.collectionName = collectionName;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* List documents in the collection.
|
|
107
|
+
*/
|
|
108
|
+
async list(params, options) {
|
|
109
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsListDocs_js_1.collectionsDocsListDocs)(this.client, { collectionName: this.collectionName, ...params }, options));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Upsert documents. Max payload 6MB.
|
|
113
|
+
*/
|
|
114
|
+
async upsert(body, options) {
|
|
115
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsUpsert_js_1.collectionsDocsUpsert)(this.client, {
|
|
116
|
+
collectionName: this.collectionName,
|
|
117
|
+
requestBody: body,
|
|
118
|
+
}, options));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Update documents (each doc must have id). Max payload 6MB.
|
|
122
|
+
*/
|
|
123
|
+
async update(body, options) {
|
|
124
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsUpdate_js_1.collectionsDocsUpdate)(this.client, {
|
|
125
|
+
collectionName: this.collectionName,
|
|
126
|
+
requestBody: body,
|
|
127
|
+
}, options));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Delete documents by ids and/or filter.
|
|
131
|
+
*/
|
|
132
|
+
async delete(body, options) {
|
|
133
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsDelete_js_1.collectionsDocsDelete)(this.client, {
|
|
134
|
+
collectionName: this.collectionName,
|
|
135
|
+
requestBody: body,
|
|
136
|
+
}, options));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Fetch documents by IDs (max 100).
|
|
140
|
+
*/
|
|
141
|
+
async fetch(body, options) {
|
|
142
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsFetch_js_1.collectionsDocsFetch)(this.client, {
|
|
143
|
+
collectionName: this.collectionName,
|
|
144
|
+
requestBody: body,
|
|
145
|
+
}, options));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get presigned URL and metadata for bulk upload (up to 200MB).
|
|
149
|
+
*/
|
|
150
|
+
async getBulkUpsert(options) {
|
|
151
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsGetBulkUpsert_js_1.collectionsDocsGetBulkUpsert)(this.client, { collectionName: this.collectionName }, options));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Trigger bulk upsert with an object key from getBulkUpsert().
|
|
155
|
+
*/
|
|
156
|
+
async bulkUpsert(body, options) {
|
|
157
|
+
return (0, fp_js_1.unwrapAsync)((0, collectionsDocsBulkUpsert_js_1.collectionsDocsBulkUpsert)(this.client, {
|
|
158
|
+
collectionName: this.collectionName,
|
|
159
|
+
requestBody: body,
|
|
160
|
+
}, options));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,uCAAyC;AACzC,uEAAiE;AACjE,uEAAiE;AACjE,iEAA2D;AAC3D,mEAA6D;AAC7D,qEAA+D;AAC/D,uEAAiE;AACjE,uFAAiF;AACjF,+EAAyE;AACzE,6EAAuE;AACvE,6FAAuF;AACvF,mFAA6E;AAC7E,+EAAyE;AACzE,+EAAyE;AAIzE,yCAA4C;AAO5C;;;GAGG;AACH,MAAa,cAAe,SAAQ,sBAAY;IAC9C;;;OAGG;IACH,UAAU,CAAC,cAAsB;QAC/B,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,OAAwB;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;SAClB,EACD,OAAO,CACR,CACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CACT,IAAqC,EACrC,OAAwB;QAExB,OAAO,IAAA,mBAAW,EAChB,IAAA,8CAAoB,EAClB,IAAI,CAAC,MAAM,EACX;YACE,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW,EAAE,IAAI;SAClB,EACD,OAAO,CACR,CACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,OAAwB;QAC1C,OAAO,IAAA,mBAAW,EAChB,IAAA,8DAA4B,EAC1B,IAAI,CAAC,MAAM,EACX,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,EACvC,OAAO,CACR,CACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CACd,IAA2B,EAC3B,OAAwB;QAExB,OAAO,IAAA,mBAAW,EAChB,IAAA,wDAAyB,EACvB,IAAI,CAAC,MAAM,EACX;YACE,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW,EAAE,IAAI;SAClB,EACD,OAAO,CACR,CACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export * as files from "./lib/files.js";
|
|
|
3
3
|
export { HTTPClient } from "./lib/http.js";
|
|
4
4
|
export type { Fetcher, HTTPClientOptions } from "./lib/http.js";
|
|
5
5
|
export * from "./sdk/sdk.js";
|
|
6
|
+
/** Collection-scoped client (recommended). See docs/REFACTORING_PROPOSAL.md */
|
|
7
|
+
export { LambdaDBClient, CollectionHandle, type RequestOptions as ClientRequestOptions, } from "./client.js";
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAChE,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAChE,cAAc,cAAc,CAAC;AAE7B,+EAA+E;AAC/E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,cAAc,IAAI,oBAAoB,GAC5C,MAAM,aAAa,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -39,10 +39,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.HTTPClient = exports.files = void 0;
|
|
42
|
+
exports.CollectionHandle = exports.LambdaDBClient = exports.HTTPClient = exports.files = void 0;
|
|
43
43
|
__exportStar(require("./lib/config.js"), exports);
|
|
44
44
|
exports.files = __importStar(require("./lib/files.js"));
|
|
45
45
|
var http_js_1 = require("./lib/http.js");
|
|
46
46
|
Object.defineProperty(exports, "HTTPClient", { enumerable: true, get: function () { return http_js_1.HTTPClient; } });
|
|
47
47
|
__exportStar(require("./sdk/sdk.js"), exports);
|
|
48
|
+
/** Collection-scoped client (recommended). See docs/REFACTORING_PROPOSAL.md */
|
|
49
|
+
var client_js_1 = require("./client.js");
|
|
50
|
+
Object.defineProperty(exports, "LambdaDBClient", { enumerable: true, get: function () { return client_js_1.LambdaDBClient; } });
|
|
51
|
+
Object.defineProperty(exports, "CollectionHandle", { enumerable: true, get: function () { return client_js_1.CollectionHandle; } });
|
|
48
52
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,wDAAwC;AACxC,yCAA2C;AAAlC,qGAAA,UAAU,OAAA;AAEnB,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAgC;AAChC,wDAAwC;AACxC,yCAA2C;AAAlC,qGAAA,UAAU,OAAA;AAEnB,+CAA6B;AAE7B,+EAA+E;AAC/E,yCAIqB;AAHnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA"}
|