@functional-systems/lambdadb 0.3.0-dev.4 → 0.3.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.
Files changed (57) hide show
  1. package/FUNCTIONS.md +1 -1
  2. package/README.md +22 -7
  3. package/dist/commonjs/client.d.ts +25 -9
  4. package/dist/commonjs/client.d.ts.map +1 -1
  5. package/dist/commonjs/client.js +49 -10
  6. package/dist/commonjs/client.js.map +1 -1
  7. package/dist/commonjs/funcs/collectionsList.d.ts +1 -1
  8. package/dist/commonjs/funcs/collectionsList.d.ts.map +1 -1
  9. package/dist/commonjs/funcs/collectionsList.js +9 -3
  10. package/dist/commonjs/funcs/collectionsList.js.map +1 -1
  11. package/dist/commonjs/models/collectionresponse.d.ts +12 -0
  12. package/dist/commonjs/models/collectionresponse.d.ts.map +1 -1
  13. package/dist/commonjs/models/collectionresponse.js +3 -0
  14. package/dist/commonjs/models/collectionresponse.js.map +1 -1
  15. package/dist/commonjs/models/operations/listcollections.d.ts +19 -0
  16. package/dist/commonjs/models/operations/listcollections.d.ts.map +1 -1
  17. package/dist/commonjs/models/operations/listcollections.js +7 -1
  18. package/dist/commonjs/models/operations/listcollections.js.map +1 -1
  19. package/dist/commonjs/sdk/collections.d.ts +1 -1
  20. package/dist/commonjs/sdk/collections.d.ts.map +1 -1
  21. package/dist/commonjs/sdk/collections.js +2 -2
  22. package/dist/commonjs/sdk/collections.js.map +1 -1
  23. package/dist/commonjs/types/public.d.ts +37 -0
  24. package/dist/commonjs/types/public.d.ts.map +1 -1
  25. package/dist/commonjs/types/public.js +30 -0
  26. package/dist/commonjs/types/public.js.map +1 -1
  27. package/dist/esm/client.d.ts +25 -9
  28. package/dist/esm/client.d.ts.map +1 -1
  29. package/dist/esm/client.js +49 -10
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/funcs/collectionsList.d.ts +1 -1
  32. package/dist/esm/funcs/collectionsList.d.ts.map +1 -1
  33. package/dist/esm/funcs/collectionsList.js +9 -3
  34. package/dist/esm/funcs/collectionsList.js.map +1 -1
  35. package/dist/esm/models/collectionresponse.d.ts +12 -0
  36. package/dist/esm/models/collectionresponse.d.ts.map +1 -1
  37. package/dist/esm/models/collectionresponse.js +3 -0
  38. package/dist/esm/models/collectionresponse.js.map +1 -1
  39. package/dist/esm/models/operations/listcollections.d.ts +19 -0
  40. package/dist/esm/models/operations/listcollections.d.ts.map +1 -1
  41. package/dist/esm/models/operations/listcollections.js +6 -0
  42. package/dist/esm/models/operations/listcollections.js.map +1 -1
  43. package/dist/esm/sdk/collections.d.ts +1 -1
  44. package/dist/esm/sdk/collections.d.ts.map +1 -1
  45. package/dist/esm/sdk/collections.js +2 -2
  46. package/dist/esm/sdk/collections.js.map +1 -1
  47. package/dist/esm/types/public.d.ts +37 -0
  48. package/dist/esm/types/public.d.ts.map +1 -1
  49. package/dist/esm/types/public.js +27 -1
  50. package/dist/esm/types/public.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/client.ts +79 -22
  53. package/src/funcs/collectionsList.ts +10 -0
  54. package/src/models/collectionresponse.ts +15 -0
  55. package/src/models/operations/listcollections.ts +29 -0
  56. package/src/sdk/collections.ts +2 -0
  57. package/src/types/public.ts +70 -0
package/src/client.ts CHANGED
@@ -30,14 +30,19 @@ import { unwrapAsync, OK, ERR } from "./types/fp.js";
30
30
  import type { Result } from "./types/fp.js";
31
31
  import type * as operations from "./models/operations/index.js";
32
32
  import type * as models from "./models/index.js";
33
- import type {
34
- CreateCollectionInput,
35
- UpdateCollectionInput,
36
- QueryCollectionInput,
37
- QueryCollectionResponse,
38
- QueryCollectionDoc,
39
- ListDocsInput,
40
- ListDocsResponse,
33
+ import {
34
+ listCollectionsResponseWithDates,
35
+ getCollectionResponseWithDates,
36
+ type CreateCollectionInput,
37
+ type UpdateCollectionInput,
38
+ type QueryCollectionInput,
39
+ type QueryCollectionResponse,
40
+ type QueryCollectionDoc,
41
+ type ListDocsInput,
42
+ type ListDocsResponse,
43
+ type ListCollectionsInput,
44
+ type ListCollectionsResponseWithDates,
45
+ type GetCollectionResponseWithDates,
41
46
  UpsertDocsInput,
42
47
  UpdateDocsInput,
43
48
  DeleteDocsInput,
@@ -46,9 +51,7 @@ import type {
46
51
  FetchDocsDoc,
47
52
  BulkUpsertInput,
48
53
  MessageResponse,
49
- ListCollectionsResponse,
50
54
  CreateCollectionResponse,
51
- GetCollectionResponse,
52
55
  UpdateCollectionResponse,
53
56
  GetBulkUpsertDocsResponse,
54
57
  } from "./types/public.js";
@@ -155,19 +158,66 @@ export class LambdaDBClient extends LambdaDBCore {
155
158
  }
156
159
 
157
160
  /**
158
- * List all collections in the project.
161
+ * List collections in the project (with optional pagination). Timestamp fields are returned as Date.
159
162
  */
160
- async listCollections(options?: RequestOptions) {
161
- return unwrapAsync(collectionsList(this, options));
163
+ async listCollections(
164
+ params?: ListCollectionsInput,
165
+ options?: RequestOptions,
166
+ ): Promise<ListCollectionsResponseWithDates> {
167
+ const res = await unwrapAsync(collectionsList(this, params, options));
168
+ return listCollectionsResponseWithDates(res);
162
169
  }
163
170
 
164
171
  /**
165
- * List all collections (Safe: returns Result instead of throwing).
172
+ * List collections (Safe: returns Result instead of throwing). Timestamp fields are Date.
166
173
  */
167
174
  async listCollectionsSafe(
175
+ params?: ListCollectionsInput,
168
176
  options?: RequestOptions,
169
- ): Promise<Result<ListCollectionsResponse, ListCollectionsError>> {
170
- return await collectionsList(this, options);
177
+ ): Promise<Result<ListCollectionsResponseWithDates, ListCollectionsError>> {
178
+ const result = await collectionsList(this, params, options);
179
+ if (!result.ok) return result;
180
+ return OK(listCollectionsResponseWithDates(result.value));
181
+ }
182
+
183
+ /**
184
+ * Iterate over all pages of collections. Yields one page per API response.
185
+ * Use this to process many collections without loading everything into memory.
186
+ *
187
+ * @example
188
+ * for await (const page of client.listCollectionsPages({ size: 20 })) {
189
+ * console.log(page.collections.length, page.nextPageToken ?? "last page");
190
+ * }
191
+ */
192
+ async *listCollectionsPages(
193
+ params?: ListCollectionsInput,
194
+ options?: RequestOptions,
195
+ ): AsyncGenerator<ListCollectionsResponseWithDates> {
196
+ let pageToken: string | undefined = params?.pageToken;
197
+ const baseParams: ListCollectionsInput = { size: params?.size, pageToken };
198
+ while (true) {
199
+ const page = await this.listCollections(
200
+ { ...baseParams, pageToken } as ListCollectionsInput,
201
+ options,
202
+ );
203
+ yield page;
204
+ pageToken = page.nextPageToken;
205
+ if (pageToken == null || pageToken === "") break;
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Fetch all collections across pages and return a single list. Uses listCollectionsPages internally.
211
+ */
212
+ async listAllCollections(
213
+ params?: ListCollectionsInput,
214
+ options?: RequestOptions,
215
+ ): Promise<{ collections: ListCollectionsResponseWithDates["collections"] }> {
216
+ const collections: ListCollectionsResponseWithDates["collections"] = [];
217
+ for await (const page of this.listCollectionsPages(params, options)) {
218
+ collections.push(...page.collections);
219
+ }
220
+ return { collections };
171
221
  }
172
222
 
173
223
  /**
@@ -201,21 +251,28 @@ export class CollectionHandle {
201
251
  ) {}
202
252
 
203
253
  /**
204
- * Get metadata of this collection.
254
+ * Get metadata of this collection. Timestamp fields are returned as Date.
205
255
  */
206
- async get(options?: RequestOptions) {
207
- return unwrapAsync(
256
+ async get(options?: RequestOptions): Promise<GetCollectionResponseWithDates> {
257
+ const res = await unwrapAsync(
208
258
  collectionsGet(this.client, { collectionName: this.collectionName }, options),
209
259
  );
260
+ return getCollectionResponseWithDates(res);
210
261
  }
211
262
 
212
263
  /**
213
- * Get metadata of this collection (Safe: returns Result instead of throwing).
264
+ * Get metadata of this collection (Safe: returns Result instead of throwing). Timestamp fields are Date.
214
265
  */
215
266
  async getSafe(
216
267
  options?: RequestOptions,
217
- ): Promise<Result<GetCollectionResponse, GetCollectionError>> {
218
- return await collectionsGet(this.client, { collectionName: this.collectionName }, options);
268
+ ): Promise<Result<GetCollectionResponseWithDates, GetCollectionError>> {
269
+ const result = await collectionsGet(
270
+ this.client,
271
+ { collectionName: this.collectionName },
272
+ options,
273
+ );
274
+ if (!result.ok) return result;
275
+ return OK(getCollectionResponseWithDates(result.value));
219
276
  }
220
277
 
221
278
  /**
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import { LambdaDBCore } from "../core.js";
6
+ import { encodeFormQuery } from "../lib/encodings.js";
6
7
  import * as M from "../lib/matchers.js";
7
8
  import { compactMap } from "../lib/primitives.js";
8
9
  import { RequestOptions } from "../lib/sdks.js";
@@ -28,6 +29,7 @@ import { Result } from "../types/fp.js";
28
29
  */
29
30
  export function collectionsList(
30
31
  client: LambdaDBCore,
32
+ request?: operations.ListCollectionsRequest,
31
33
  options?: RequestOptions,
32
34
  ): APIPromise<
33
35
  Result<
@@ -48,12 +50,14 @@ export function collectionsList(
48
50
  > {
49
51
  return new APIPromise($do(
50
52
  client,
53
+ request,
51
54
  options,
52
55
  ));
53
56
  }
54
57
 
55
58
  async function $do(
56
59
  client: LambdaDBCore,
60
+ request?: operations.ListCollectionsRequest,
57
61
  options?: RequestOptions,
58
62
  ): Promise<
59
63
  [
@@ -77,6 +81,11 @@ async function $do(
77
81
  > {
78
82
  const path = pathToFunc("/collections")();
79
83
 
84
+ const query = encodeFormQuery({
85
+ "pageToken": request?.pageToken,
86
+ "size": request?.size,
87
+ });
88
+
80
89
  const headers = new Headers(compactMap({
81
90
  Accept: "application/json",
82
91
  }));
@@ -116,6 +125,7 @@ async function $do(
116
125
  baseURL: options?.serverURL,
117
126
  path: path,
118
127
  headers: headers,
128
+ query: query,
119
129
  userAgent: client._options.userAgent,
120
130
  timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
121
131
  }, options);
@@ -51,6 +51,18 @@ export type CollectionResponse = {
51
51
  * Status
52
52
  */
53
53
  collectionStatus: Status;
54
+ /**
55
+ * Collection creation time in seconds since the Unix epoch.
56
+ */
57
+ createdAt: number;
58
+ /**
59
+ * Collection last update time in seconds since the Unix epoch.
60
+ */
61
+ updatedAt: number;
62
+ /**
63
+ * Collection data last update time in seconds since the Unix epoch.
64
+ */
65
+ dataUpdatedAt: number;
54
66
  };
55
67
 
56
68
  /** @internal */
@@ -69,6 +81,9 @@ export const CollectionResponse$inboundSchema: z.ZodType<
69
81
  sourceCollectionName: z.string().optional(),
70
82
  sourceCollectionVersionId: z.string().optional(),
71
83
  collectionStatus: Status$inboundSchema,
84
+ createdAt: z.number().int(),
85
+ updatedAt: z.number().int(),
86
+ dataUpdatedAt: z.number().int(),
72
87
  });
73
88
 
74
89
  export function collectionResponseFromJSON(
@@ -8,11 +8,39 @@ import { Result as SafeParseResult } from "../../types/fp.js";
8
8
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
9
  import * as models from "../index.js";
10
10
 
11
+ /**
12
+ * Request parameters for listing collections (pagination).
13
+ */
14
+ export type ListCollectionsRequest = {
15
+ /**
16
+ * Max number of collections to return at once.
17
+ */
18
+ size?: number | undefined;
19
+ /**
20
+ * Next page token.
21
+ */
22
+ pageToken?: string | undefined;
23
+ };
24
+
25
+ /** @internal */
26
+ export const ListCollectionsRequest$outboundSchema: z.ZodType<
27
+ ListCollectionsRequest,
28
+ z.ZodTypeDef,
29
+ ListCollectionsRequest
30
+ > = z.object({
31
+ size: z.number().int().min(1).max(100).optional(),
32
+ pageToken: z.string().optional(),
33
+ });
34
+
11
35
  /**
12
36
  * A list of collections matched with a projectName.
13
37
  */
14
38
  export type ListCollectionsResponse = {
15
39
  collections: Array<models.CollectionResponse>;
40
+ /**
41
+ * Next page token.
42
+ */
43
+ nextPageToken?: string | undefined;
16
44
  };
17
45
 
18
46
  /** @internal */
@@ -22,6 +50,7 @@ export const ListCollectionsResponse$inboundSchema: z.ZodType<
22
50
  unknown
23
51
  > = z.object({
24
52
  collections: z.array(models.CollectionResponse$inboundSchema),
53
+ nextPageToken: z.string().optional(),
25
54
  });
26
55
 
27
56
  export function listCollectionsResponseFromJSON(
@@ -27,10 +27,12 @@ export class Collections extends ClientSDK {
27
27
  * List all collections in an existing project.
28
28
  */
29
29
  async list(
30
+ request?: operations.ListCollectionsRequest,
30
31
  options?: RequestOptions,
31
32
  ): Promise<operations.ListCollectionsResponse> {
32
33
  return unwrapAsync(collectionsList(
33
34
  this,
35
+ request,
34
36
  options,
35
37
  ));
36
38
  }
@@ -14,10 +14,17 @@ export type { FetchDocsRequestBody as FetchDocsInput } from "../models/operation
14
14
  export type { BulkUpsertDocsRequestBody as BulkUpsertInput } from "../models/operations/bulkupsertdocs.js";
15
15
 
16
16
  import type { ListDocsRequest } from "../models/operations/listdocs.js";
17
+ import type { ListCollectionsRequest } from "../models/operations/listcollections.js";
17
18
 
18
19
  /** Parameters for listing documents (size, pageToken). */
19
20
  export type ListDocsInput = Pick<ListDocsRequest, "size" | "pageToken">;
20
21
 
22
+ /** Parameters for listing collections (size, pageToken). */
23
+ export type ListCollectionsInput = Pick<
24
+ ListCollectionsRequest,
25
+ "size" | "pageToken"
26
+ >;
27
+
21
28
  // ---- Response types ----
22
29
  export type { ListCollectionsResponse } from "../models/operations/listcollections.js";
23
30
  export type { CreateCollectionResponse } from "../models/operations/createcollection.js";
@@ -43,3 +50,66 @@ export type {
43
50
  FieldsSelectorUnion,
44
51
  CollectionResponse,
45
52
  } from "../models/index.js";
53
+
54
+ // ---- Timestamp helpers (Unix seconds → Date) ----
55
+ import type { CollectionResponse as CollectionResponseModel } from "../models/index.js";
56
+
57
+ /**
58
+ * Collection response with timestamp fields as Date (for better DX).
59
+ * Use {@link collectionResponseWithDates} to convert API response.
60
+ */
61
+ export type CollectionResponseWithDates = Omit<
62
+ CollectionResponseModel,
63
+ "createdAt" | "updatedAt" | "dataUpdatedAt"
64
+ > & {
65
+ createdAt?: Date | undefined;
66
+ updatedAt?: Date | undefined;
67
+ dataUpdatedAt?: Date | undefined;
68
+ };
69
+
70
+ /**
71
+ * List collections response with timestamp fields as Date.
72
+ */
73
+ export type ListCollectionsResponseWithDates = {
74
+ collections: CollectionResponseWithDates[];
75
+ nextPageToken?: string | undefined;
76
+ };
77
+
78
+ /**
79
+ * Converts Unix-second timestamp fields to Date. Safe to call on partial responses.
80
+ */
81
+ export function collectionResponseWithDates(
82
+ c: CollectionResponseModel,
83
+ ): CollectionResponseWithDates {
84
+ const { createdAt, updatedAt, dataUpdatedAt, ...rest } = c;
85
+ const out: CollectionResponseWithDates = { ...rest };
86
+ if (createdAt != null) out.createdAt = new Date(createdAt * 1000);
87
+ if (updatedAt != null) out.updatedAt = new Date(updatedAt * 1000);
88
+ if (dataUpdatedAt != null)
89
+ out.dataUpdatedAt = new Date(dataUpdatedAt * 1000);
90
+ return out;
91
+ }
92
+
93
+ /** Converts ListCollectionsResponse to use Date for timestamp fields. */
94
+ export function listCollectionsResponseWithDates(res: {
95
+ collections: CollectionResponseModel[];
96
+ nextPageToken?: string | undefined;
97
+ }): ListCollectionsResponseWithDates {
98
+ const out: ListCollectionsResponseWithDates = {
99
+ collections: res.collections.map(collectionResponseWithDates),
100
+ };
101
+ if (res.nextPageToken !== undefined) out.nextPageToken = res.nextPageToken;
102
+ return out;
103
+ }
104
+
105
+ /** Get collection response with timestamp fields as Date. */
106
+ export type GetCollectionResponseWithDates = {
107
+ collection: CollectionResponseWithDates;
108
+ };
109
+
110
+ /** Converts GetCollectionResponse to use Date for timestamp fields. */
111
+ export function getCollectionResponseWithDates(res: {
112
+ collection: CollectionResponseModel;
113
+ }): GetCollectionResponseWithDates {
114
+ return { collection: collectionResponseWithDates(res.collection) };
115
+ }