@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.
@@ -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"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,EACpB,cAAc,EAAE,MAAM;IAGzC;;OAEG;IACG,IAAI,CACR,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,EAC9C,OAAO,CAAC,EAAE,cAAc;IAW1B;;OAEG;IACG,MAAM,CACV,IAAI,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;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,158 @@
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 { collectionsCreate } from "./funcs/collectionsCreate.js";
14
+ import { collectionsDelete } from "./funcs/collectionsDelete.js";
15
+ import { collectionsGet } from "./funcs/collectionsGet.js";
16
+ import { collectionsList } from "./funcs/collectionsList.js";
17
+ import { collectionsQuery } from "./funcs/collectionsQuery.js";
18
+ import { collectionsUpdate } from "./funcs/collectionsUpdate.js";
19
+ import { collectionsDocsBulkUpsert } from "./funcs/collectionsDocsBulkUpsert.js";
20
+ import { collectionsDocsDelete } from "./funcs/collectionsDocsDelete.js";
21
+ import { collectionsDocsFetch } from "./funcs/collectionsDocsFetch.js";
22
+ import { collectionsDocsGetBulkUpsert } from "./funcs/collectionsDocsGetBulkUpsert.js";
23
+ import { collectionsDocsListDocs } from "./funcs/collectionsDocsListDocs.js";
24
+ import { collectionsDocsUpdate } from "./funcs/collectionsDocsUpdate.js";
25
+ import { collectionsDocsUpsert } from "./funcs/collectionsDocsUpsert.js";
26
+ import { unwrapAsync } from "./types/fp.js";
27
+ /**
28
+ * Client with collection-scoped API. Prefer this over the legacy
29
+ * `LambdaDB` when you want to avoid passing collectionName on every call.
30
+ */
31
+ export class LambdaDBClient extends LambdaDBCore {
32
+ /**
33
+ * Get a handle for a specific collection. All methods on the handle
34
+ * use this collection name; you do not pass it again.
35
+ */
36
+ collection(collectionName) {
37
+ return new CollectionHandle(this, collectionName);
38
+ }
39
+ /**
40
+ * List all collections in the project.
41
+ */
42
+ async listCollections(options) {
43
+ return unwrapAsync(collectionsList(this, options));
44
+ }
45
+ /**
46
+ * Create a new collection.
47
+ */
48
+ async createCollection(request, options) {
49
+ return unwrapAsync(collectionsCreate(this, request, options));
50
+ }
51
+ }
52
+ /**
53
+ * Handle for a single collection. All methods operate on this collection.
54
+ */
55
+ export class CollectionHandle {
56
+ constructor(client, collectionName) {
57
+ this.client = client;
58
+ this.collectionName = collectionName;
59
+ this.docs = new CollectionDocs(this.client, this.collectionName);
60
+ }
61
+ /**
62
+ * Get metadata of this collection.
63
+ */
64
+ async get(options) {
65
+ return unwrapAsync(collectionsGet(this.client, { collectionName: this.collectionName }, options));
66
+ }
67
+ /**
68
+ * Configure (update) this collection.
69
+ */
70
+ async update(requestBody, options) {
71
+ return unwrapAsync(collectionsUpdate(this.client, {
72
+ collectionName: this.collectionName,
73
+ requestBody,
74
+ }, options));
75
+ }
76
+ /**
77
+ * Delete this collection.
78
+ */
79
+ async delete(options) {
80
+ return unwrapAsync(collectionsDelete(this.client, { collectionName: this.collectionName }, options));
81
+ }
82
+ /**
83
+ * Search this collection with a query.
84
+ */
85
+ async query(requestBody, options) {
86
+ return unwrapAsync(collectionsQuery(this.client, {
87
+ collectionName: this.collectionName,
88
+ requestBody,
89
+ }, options));
90
+ }
91
+ }
92
+ /**
93
+ * Document operations scoped to a collection.
94
+ */
95
+ class CollectionDocs {
96
+ constructor(client, collectionName) {
97
+ this.client = client;
98
+ this.collectionName = collectionName;
99
+ }
100
+ /**
101
+ * List documents in the collection.
102
+ */
103
+ async list(params, options) {
104
+ return unwrapAsync(collectionsDocsListDocs(this.client, { collectionName: this.collectionName, ...params }, options));
105
+ }
106
+ /**
107
+ * Upsert documents. Max payload 6MB.
108
+ */
109
+ async upsert(body, options) {
110
+ return unwrapAsync(collectionsDocsUpsert(this.client, {
111
+ collectionName: this.collectionName,
112
+ requestBody: body,
113
+ }, options));
114
+ }
115
+ /**
116
+ * Update documents (each doc must have id). Max payload 6MB.
117
+ */
118
+ async update(body, options) {
119
+ return unwrapAsync(collectionsDocsUpdate(this.client, {
120
+ collectionName: this.collectionName,
121
+ requestBody: body,
122
+ }, options));
123
+ }
124
+ /**
125
+ * Delete documents by ids and/or filter.
126
+ */
127
+ async delete(body, options) {
128
+ return unwrapAsync(collectionsDocsDelete(this.client, {
129
+ collectionName: this.collectionName,
130
+ requestBody: body,
131
+ }, options));
132
+ }
133
+ /**
134
+ * Fetch documents by IDs (max 100).
135
+ */
136
+ async fetch(body, options) {
137
+ return unwrapAsync(collectionsDocsFetch(this.client, {
138
+ collectionName: this.collectionName,
139
+ requestBody: body,
140
+ }, options));
141
+ }
142
+ /**
143
+ * Get presigned URL and metadata for bulk upload (up to 200MB).
144
+ */
145
+ async getBulkUpsert(options) {
146
+ return unwrapAsync(collectionsDocsGetBulkUpsert(this.client, { collectionName: this.collectionName }, options));
147
+ }
148
+ /**
149
+ * Trigger bulk upsert with an object key from getBulkUpsert().
150
+ */
151
+ async bulkUpsert(body, options) {
152
+ return unwrapAsync(collectionsDocsBulkUpsert(this.client, {
153
+ collectionName: this.collectionName,
154
+ requestBody: body,
155
+ }, options));
156
+ }
157
+ }
158
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EA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AC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,IAAsC,EACtC,OAAwB;QAExB,OAAO,WAAW,CAChB,qBAAqB,CACnB,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,KAAK,CACT,IAAqC,EACrC,OAAwB;QAExB,OAAO,WAAW,CAChB,oBAAoB,CAClB,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,WAAW,CAChB,4BAA4B,CAC1B,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,WAAW,CAChB,yBAAyB,CACvB,IAAI,CAAC,MAAM,EACX;YACE,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW,EAAE,IAAI;SAClB,EACD,OAAO,CACR,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -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/esm/index.js CHANGED
@@ -5,4 +5,6 @@ export * from "./lib/config.js";
5
5
  export * as files from "./lib/files.js";
6
6
  export { HTTPClient } from "./lib/http.js";
7
7
  export * from "./sdk/sdk.js";
8
+ /** Collection-scoped client (recommended). See docs/REFACTORING_PROPOSAL.md */
9
+ export { LambdaDBClient, CollectionHandle, } from "./client.js";
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,cAAc,cAAc,CAAC;AAE7B,+EAA+E;AAC/E,OAAO,EACL,cAAc,EACd,gBAAgB,GAEjB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,32 @@
1
+ import dotenv from "dotenv";
2
+ dotenv.config();
3
+
4
+ /**
5
+ * Example: collection-scoped API — get a collection handle once, then call
6
+ * methods without passing collectionName every time.
7
+ *
8
+ * Run from the examples directory:
9
+ * npm run build && npx tsx collectionScoped.example.ts
10
+ */
11
+
12
+ import { LambdaDBClient } from "@functional-systems/lambdadb";
13
+
14
+ const client = new LambdaDBClient({
15
+ projectApiKey: process.env.LAMBDADB_PROJECT_API_KEY ?? "<YOUR_PROJECT_API_KEY>",
16
+ });
17
+
18
+ const COLLECTION_NAME = "my-collection";
19
+
20
+ async function main() {
21
+ const collection = client.collection(COLLECTION_NAME);
22
+
23
+ // Collection metadata
24
+ const meta = await collection.get();
25
+ console.log("Collection:", meta);
26
+
27
+ // List documents (no collectionName in the call)
28
+ const { docs, total, nextPageToken } = await collection.docs.list({ size: 10 });
29
+ console.log(`Documents: ${docs.length} of ${total}`, nextPageToken ? "(has more)" : "");
30
+ }
31
+
32
+ main().catch(console.error);
@@ -1,25 +1,21 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
-
5
1
  import dotenv from "dotenv";
6
2
  dotenv.config();
3
+
7
4
  /**
8
- * Example usage of the @functional-systems/lambdadb SDK
5
+ * Example: list collections using the recommended LambdaDBClient.
9
6
  *
10
- * To run this example from the examples directory:
11
- * npm run build && npx tsx collectionsList.example.ts
7
+ * Run from the examples directory:
8
+ * npm run build && npx tsx collectionsList.example.ts
12
9
  */
13
10
 
14
- import { LambdaDB } from "@functional-systems/lambdadb";
11
+ import { LambdaDBClient } from "@functional-systems/lambdadb";
15
12
 
16
- const lambdaDB = new LambdaDB({
17
- projectApiKey: "<YOUR_PROJECT_API_KEY>",
13
+ const client = new LambdaDBClient({
14
+ projectApiKey: process.env.LAMBDADB_PROJECT_API_KEY ?? "<YOUR_PROJECT_API_KEY>",
18
15
  });
19
16
 
20
17
  async function main() {
21
- const result = await lambdaDB.collections.list();
22
-
18
+ const result = await client.listCollections();
23
19
  console.log(result);
24
20
  }
25
21
 
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@functional-systems/lambdadb",
3
- "version": "0.2.1",
3
+ "version": "0.3.0-dev",
4
4
  "author": "Functional Systems, Inc.",
5
5
  "homepage": "https://github.com/lambdadb/lambdadb-typescript-client#readme",
6
6
  "license": "Apache-2.0",
7
- "repository": "https://github.com/lambdadb/lambdadb-typescript-client.git",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/lambdadb/lambdadb-typescript-client.git"
10
+ },
8
11
  "type": "module",
9
12
  "tshy": {
10
13
  "sourceDialects": [
@@ -27,7 +30,6 @@
27
30
  "build": "tshy",
28
31
  "prepublishOnly": "npm run build"
29
32
  },
30
- "peerDependencies": {},
31
33
  "devDependencies": {
32
34
  "@eslint/js": "^9.19.0",
33
35
  "eslint": "^9.19.0",
package/src/client.ts ADDED
@@ -0,0 +1,272 @@
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
+
13
+ import { LambdaDBCore } from "./core.js";
14
+ import { collectionsCreate } from "./funcs/collectionsCreate.js";
15
+ import { collectionsDelete } from "./funcs/collectionsDelete.js";
16
+ import { collectionsGet } from "./funcs/collectionsGet.js";
17
+ import { collectionsList } from "./funcs/collectionsList.js";
18
+ import { collectionsQuery } from "./funcs/collectionsQuery.js";
19
+ import { collectionsUpdate } from "./funcs/collectionsUpdate.js";
20
+ import { collectionsDocsBulkUpsert } from "./funcs/collectionsDocsBulkUpsert.js";
21
+ import { collectionsDocsDelete } from "./funcs/collectionsDocsDelete.js";
22
+ import { collectionsDocsFetch } from "./funcs/collectionsDocsFetch.js";
23
+ import { collectionsDocsGetBulkUpsert } from "./funcs/collectionsDocsGetBulkUpsert.js";
24
+ import { collectionsDocsListDocs } from "./funcs/collectionsDocsListDocs.js";
25
+ import { collectionsDocsUpdate } from "./funcs/collectionsDocsUpdate.js";
26
+ import { collectionsDocsUpsert } from "./funcs/collectionsDocsUpsert.js";
27
+ import type { RequestOptions } from "./lib/sdks.js";
28
+ import type * as operations from "./models/operations/index.js";
29
+ import type * as models from "./models/index.js";
30
+ import { unwrapAsync } from "./types/fp.js";
31
+
32
+ export type { RequestOptions };
33
+
34
+ // Re-export common types for facade users
35
+ export type { operations, models };
36
+
37
+ /**
38
+ * Client with collection-scoped API. Prefer this over the legacy
39
+ * `LambdaDB` when you want to avoid passing collectionName on every call.
40
+ */
41
+ export class LambdaDBClient extends LambdaDBCore {
42
+ /**
43
+ * Get a handle for a specific collection. All methods on the handle
44
+ * use this collection name; you do not pass it again.
45
+ */
46
+ collection(collectionName: string): CollectionHandle {
47
+ return new CollectionHandle(this, collectionName);
48
+ }
49
+
50
+ /**
51
+ * List all collections in the project.
52
+ */
53
+ async listCollections(options?: RequestOptions) {
54
+ return unwrapAsync(collectionsList(this, options));
55
+ }
56
+
57
+ /**
58
+ * Create a new collection.
59
+ */
60
+ async createCollection(
61
+ request: operations.CreateCollectionRequest,
62
+ options?: RequestOptions,
63
+ ) {
64
+ return unwrapAsync(collectionsCreate(this, request, options));
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Handle for a single collection. All methods operate on this collection.
70
+ */
71
+ export class CollectionHandle {
72
+ constructor(
73
+ private readonly client: LambdaDBCore,
74
+ readonly collectionName: string,
75
+ ) {}
76
+
77
+ /**
78
+ * Get metadata of this collection.
79
+ */
80
+ async get(options?: RequestOptions) {
81
+ return unwrapAsync(
82
+ collectionsGet(this.client, { collectionName: this.collectionName }, options),
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Configure (update) this collection.
88
+ */
89
+ async update(
90
+ requestBody: operations.UpdateCollectionRequestBody,
91
+ options?: RequestOptions,
92
+ ) {
93
+ return unwrapAsync(
94
+ collectionsUpdate(
95
+ this.client,
96
+ {
97
+ collectionName: this.collectionName,
98
+ requestBody,
99
+ },
100
+ options,
101
+ ),
102
+ );
103
+ }
104
+
105
+ /**
106
+ * Delete this collection.
107
+ */
108
+ async delete(options?: RequestOptions) {
109
+ return unwrapAsync(
110
+ collectionsDelete(
111
+ this.client,
112
+ { collectionName: this.collectionName },
113
+ options,
114
+ ),
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Search this collection with a query.
120
+ */
121
+ async query(
122
+ requestBody: operations.QueryCollectionRequestBody,
123
+ options?: RequestOptions,
124
+ ) {
125
+ return unwrapAsync(
126
+ collectionsQuery(
127
+ this.client,
128
+ {
129
+ collectionName: this.collectionName,
130
+ requestBody,
131
+ },
132
+ options,
133
+ ),
134
+ );
135
+ }
136
+
137
+ readonly docs: CollectionDocs = new CollectionDocs(this.client, this.collectionName);
138
+ }
139
+
140
+ /**
141
+ * Document operations scoped to a collection.
142
+ */
143
+ class CollectionDocs {
144
+ constructor(
145
+ private readonly client: LambdaDBCore,
146
+ private readonly collectionName: string,
147
+ ) {}
148
+
149
+ /**
150
+ * List documents in the collection.
151
+ */
152
+ async list(
153
+ params?: { size?: number; pageToken?: string },
154
+ options?: RequestOptions,
155
+ ) {
156
+ return unwrapAsync(
157
+ collectionsDocsListDocs(
158
+ this.client,
159
+ { collectionName: this.collectionName, ...params },
160
+ options,
161
+ ),
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Upsert documents. Max payload 6MB.
167
+ */
168
+ async upsert(
169
+ body: { docs: Array<Record<string, unknown>> },
170
+ options?: RequestOptions,
171
+ ): Promise<models.MessageResponse> {
172
+ return unwrapAsync(
173
+ collectionsDocsUpsert(
174
+ this.client,
175
+ {
176
+ collectionName: this.collectionName,
177
+ requestBody: body,
178
+ },
179
+ options,
180
+ ),
181
+ );
182
+ }
183
+
184
+ /**
185
+ * Update documents (each doc must have id). Max payload 6MB.
186
+ */
187
+ async update(
188
+ body: { docs: Array<Record<string, unknown>> },
189
+ options?: RequestOptions,
190
+ ): Promise<models.MessageResponse> {
191
+ return unwrapAsync(
192
+ collectionsDocsUpdate(
193
+ this.client,
194
+ {
195
+ collectionName: this.collectionName,
196
+ requestBody: body,
197
+ },
198
+ options,
199
+ ),
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Delete documents by ids and/or filter.
205
+ */
206
+ async delete(
207
+ body: operations.DeleteDocsRequestBody,
208
+ options?: RequestOptions,
209
+ ): Promise<models.MessageResponse> {
210
+ return unwrapAsync(
211
+ collectionsDocsDelete(
212
+ this.client,
213
+ {
214
+ collectionName: this.collectionName,
215
+ requestBody: body,
216
+ },
217
+ options,
218
+ ),
219
+ );
220
+ }
221
+
222
+ /**
223
+ * Fetch documents by IDs (max 100).
224
+ */
225
+ async fetch(
226
+ body: operations.FetchDocsRequestBody,
227
+ options?: RequestOptions,
228
+ ) {
229
+ return unwrapAsync(
230
+ collectionsDocsFetch(
231
+ this.client,
232
+ {
233
+ collectionName: this.collectionName,
234
+ requestBody: body,
235
+ },
236
+ options,
237
+ ),
238
+ );
239
+ }
240
+
241
+ /**
242
+ * Get presigned URL and metadata for bulk upload (up to 200MB).
243
+ */
244
+ async getBulkUpsert(options?: RequestOptions) {
245
+ return unwrapAsync(
246
+ collectionsDocsGetBulkUpsert(
247
+ this.client,
248
+ { collectionName: this.collectionName },
249
+ options,
250
+ ),
251
+ );
252
+ }
253
+
254
+ /**
255
+ * Trigger bulk upsert with an object key from getBulkUpsert().
256
+ */
257
+ async bulkUpsert(
258
+ body: { objectKey: string },
259
+ options?: RequestOptions,
260
+ ): Promise<models.MessageResponse> {
261
+ return unwrapAsync(
262
+ collectionsDocsBulkUpsert(
263
+ this.client,
264
+ {
265
+ collectionName: this.collectionName,
266
+ requestBody: body,
267
+ },
268
+ options,
269
+ ),
270
+ );
271
+ }
272
+ }
package/src/index.ts CHANGED
@@ -7,3 +7,10 @@ export * as files from "./lib/files.js";
7
7
  export { HTTPClient } from "./lib/http.js";
8
8
  export type { Fetcher, HTTPClientOptions } from "./lib/http.js";
9
9
  export * from "./sdk/sdk.js";
10
+
11
+ /** Collection-scoped client (recommended). See docs/REFACTORING_PROPOSAL.md */
12
+ export {
13
+ LambdaDBClient,
14
+ CollectionHandle,
15
+ type RequestOptions as ClientRequestOptions,
16
+ } from "./client.js";