@functional-systems/lambdadb 0.4.3 → 0.5.0-rc.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 (209) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/FUNCTIONS.md +7 -2
  3. package/README.md +60 -2
  4. package/RUNTIMES.md +7 -0
  5. package/USAGE.md +20 -0
  6. package/dist/commonjs/client.d.ts +25 -10
  7. package/dist/commonjs/client.d.ts.map +1 -1
  8. package/dist/commonjs/client.js +182 -56
  9. package/dist/commonjs/client.js.map +1 -1
  10. package/dist/commonjs/compat/qdrant/client.d.ts +3 -6
  11. package/dist/commonjs/compat/qdrant/client.d.ts.map +1 -1
  12. package/dist/commonjs/compat/qdrant/client.js +17 -11
  13. package/dist/commonjs/compat/qdrant/client.js.map +1 -1
  14. package/dist/commonjs/funcs/collectionsCreate.js +1 -1
  15. package/dist/commonjs/funcs/collectionsDelete.js +1 -1
  16. package/dist/commonjs/funcs/collectionsDocsGetBulkUpsert.js +4 -0
  17. package/dist/commonjs/funcs/collectionsDocsGetBulkUpsert.js.map +1 -1
  18. package/dist/commonjs/funcs/collectionsDocsListDocs.js +2 -0
  19. package/dist/commonjs/funcs/collectionsDocsListDocs.js.map +1 -1
  20. package/dist/commonjs/index.d.ts +4 -1
  21. package/dist/commonjs/index.d.ts.map +1 -1
  22. package/dist/commonjs/index.js +15 -1
  23. package/dist/commonjs/index.js.map +1 -1
  24. package/dist/commonjs/lib/config.d.ts +2 -2
  25. package/dist/commonjs/lib/config.js +2 -2
  26. package/dist/commonjs/lib/config.js.map +1 -1
  27. package/dist/commonjs/lib/queryInput.d.ts +3 -11
  28. package/dist/commonjs/lib/queryInput.d.ts.map +1 -1
  29. package/dist/commonjs/lib/queryInput.js.map +1 -1
  30. package/dist/commonjs/models/collectionresponse.d.ts +12 -21
  31. package/dist/commonjs/models/collectionresponse.d.ts.map +1 -1
  32. package/dist/commonjs/models/collectionresponse.js +5 -6
  33. package/dist/commonjs/models/collectionresponse.js.map +1 -1
  34. package/dist/commonjs/models/index.d.ts +1 -0
  35. package/dist/commonjs/models/index.d.ts.map +1 -1
  36. package/dist/commonjs/models/index.js +1 -0
  37. package/dist/commonjs/models/index.js.map +1 -1
  38. package/dist/commonjs/models/operations/bulkupsertdocs.d.ts +6 -0
  39. package/dist/commonjs/models/operations/bulkupsertdocs.d.ts.map +1 -1
  40. package/dist/commonjs/models/operations/bulkupsertdocs.js +2 -0
  41. package/dist/commonjs/models/operations/bulkupsertdocs.js.map +1 -1
  42. package/dist/commonjs/models/operations/createcollection.d.ts +20 -13
  43. package/dist/commonjs/models/operations/createcollection.d.ts.map +1 -1
  44. package/dist/commonjs/models/operations/createcollection.js +15 -7
  45. package/dist/commonjs/models/operations/createcollection.js.map +1 -1
  46. package/dist/commonjs/models/operations/deletedocs.d.ts +3 -0
  47. package/dist/commonjs/models/operations/deletedocs.d.ts.map +1 -1
  48. package/dist/commonjs/models/operations/deletedocs.js +1 -0
  49. package/dist/commonjs/models/operations/deletedocs.js.map +1 -1
  50. package/dist/commonjs/models/operations/fetchdocs.d.ts +3 -0
  51. package/dist/commonjs/models/operations/fetchdocs.d.ts.map +1 -1
  52. package/dist/commonjs/models/operations/fetchdocs.js +9 -0
  53. package/dist/commonjs/models/operations/fetchdocs.js.map +1 -1
  54. package/dist/commonjs/models/operations/getbulkupsertdocs.d.ts +5 -0
  55. package/dist/commonjs/models/operations/getbulkupsertdocs.d.ts.map +1 -1
  56. package/dist/commonjs/models/operations/getbulkupsertdocs.js +5 -3
  57. package/dist/commonjs/models/operations/getbulkupsertdocs.js.map +1 -1
  58. package/dist/commonjs/models/operations/listdocs.d.ts +9 -0
  59. package/dist/commonjs/models/operations/listdocs.d.ts.map +1 -1
  60. package/dist/commonjs/models/operations/listdocs.js +11 -0
  61. package/dist/commonjs/models/operations/listdocs.js.map +1 -1
  62. package/dist/commonjs/models/operations/querycollection.d.ts +3 -0
  63. package/dist/commonjs/models/operations/querycollection.d.ts.map +1 -1
  64. package/dist/commonjs/models/operations/querycollection.js +9 -0
  65. package/dist/commonjs/models/operations/querycollection.js.map +1 -1
  66. package/dist/commonjs/models/operations/updatecollection.d.ts +10 -4
  67. package/dist/commonjs/models/operations/updatecollection.d.ts.map +1 -1
  68. package/dist/commonjs/models/operations/updatecollection.js +8 -1
  69. package/dist/commonjs/models/operations/updatecollection.js.map +1 -1
  70. package/dist/commonjs/models/operations/updatedocs.d.ts +3 -0
  71. package/dist/commonjs/models/operations/updatedocs.d.ts.map +1 -1
  72. package/dist/commonjs/models/operations/updatedocs.js +1 -0
  73. package/dist/commonjs/models/operations/updatedocs.js.map +1 -1
  74. package/dist/commonjs/models/operations/upsertdocs.d.ts +3 -0
  75. package/dist/commonjs/models/operations/upsertdocs.d.ts.map +1 -1
  76. package/dist/commonjs/models/operations/upsertdocs.js +1 -0
  77. package/dist/commonjs/models/operations/upsertdocs.js.map +1 -1
  78. package/dist/commonjs/models/versioning.d.ts +100 -0
  79. package/dist/commonjs/models/versioning.d.ts.map +1 -0
  80. package/dist/commonjs/models/versioning.js +93 -0
  81. package/dist/commonjs/models/versioning.js.map +1 -0
  82. package/dist/commonjs/types/public.d.ts +80 -6
  83. package/dist/commonjs/types/public.d.ts.map +1 -1
  84. package/dist/commonjs/types/public.js +30 -7
  85. package/dist/commonjs/types/public.js.map +1 -1
  86. package/dist/commonjs/versioning.d.ts +63 -0
  87. package/dist/commonjs/versioning.d.ts.map +1 -0
  88. package/dist/commonjs/versioning.js +390 -0
  89. package/dist/commonjs/versioning.js.map +1 -0
  90. package/dist/esm/client.d.ts +25 -10
  91. package/dist/esm/client.d.ts.map +1 -1
  92. package/dist/esm/client.js +183 -58
  93. package/dist/esm/client.js.map +1 -1
  94. package/dist/esm/compat/qdrant/client.d.ts +3 -6
  95. package/dist/esm/compat/qdrant/client.d.ts.map +1 -1
  96. package/dist/esm/compat/qdrant/client.js +17 -11
  97. package/dist/esm/compat/qdrant/client.js.map +1 -1
  98. package/dist/esm/funcs/collectionsCreate.js +1 -1
  99. package/dist/esm/funcs/collectionsDelete.js +1 -1
  100. package/dist/esm/funcs/collectionsDocsGetBulkUpsert.js +5 -1
  101. package/dist/esm/funcs/collectionsDocsGetBulkUpsert.js.map +1 -1
  102. package/dist/esm/funcs/collectionsDocsListDocs.js +2 -0
  103. package/dist/esm/funcs/collectionsDocsListDocs.js.map +1 -1
  104. package/dist/esm/index.d.ts +4 -1
  105. package/dist/esm/index.d.ts.map +1 -1
  106. package/dist/esm/index.js +3 -1
  107. package/dist/esm/index.js.map +1 -1
  108. package/dist/esm/lib/config.d.ts +2 -2
  109. package/dist/esm/lib/config.js +2 -2
  110. package/dist/esm/lib/config.js.map +1 -1
  111. package/dist/esm/lib/queryInput.d.ts +3 -11
  112. package/dist/esm/lib/queryInput.d.ts.map +1 -1
  113. package/dist/esm/lib/queryInput.js.map +1 -1
  114. package/dist/esm/models/collectionresponse.d.ts +12 -21
  115. package/dist/esm/models/collectionresponse.d.ts.map +1 -1
  116. package/dist/esm/models/collectionresponse.js +5 -6
  117. package/dist/esm/models/collectionresponse.js.map +1 -1
  118. package/dist/esm/models/index.d.ts +1 -0
  119. package/dist/esm/models/index.d.ts.map +1 -1
  120. package/dist/esm/models/index.js +1 -0
  121. package/dist/esm/models/index.js.map +1 -1
  122. package/dist/esm/models/operations/bulkupsertdocs.d.ts +6 -0
  123. package/dist/esm/models/operations/bulkupsertdocs.d.ts.map +1 -1
  124. package/dist/esm/models/operations/bulkupsertdocs.js +2 -0
  125. package/dist/esm/models/operations/bulkupsertdocs.js.map +1 -1
  126. package/dist/esm/models/operations/createcollection.d.ts +20 -13
  127. package/dist/esm/models/operations/createcollection.d.ts.map +1 -1
  128. package/dist/esm/models/operations/createcollection.js +15 -7
  129. package/dist/esm/models/operations/createcollection.js.map +1 -1
  130. package/dist/esm/models/operations/deletedocs.d.ts +3 -0
  131. package/dist/esm/models/operations/deletedocs.d.ts.map +1 -1
  132. package/dist/esm/models/operations/deletedocs.js +1 -0
  133. package/dist/esm/models/operations/deletedocs.js.map +1 -1
  134. package/dist/esm/models/operations/fetchdocs.d.ts +3 -0
  135. package/dist/esm/models/operations/fetchdocs.d.ts.map +1 -1
  136. package/dist/esm/models/operations/fetchdocs.js +9 -0
  137. package/dist/esm/models/operations/fetchdocs.js.map +1 -1
  138. package/dist/esm/models/operations/getbulkupsertdocs.d.ts +5 -0
  139. package/dist/esm/models/operations/getbulkupsertdocs.d.ts.map +1 -1
  140. package/dist/esm/models/operations/getbulkupsertdocs.js +6 -4
  141. package/dist/esm/models/operations/getbulkupsertdocs.js.map +1 -1
  142. package/dist/esm/models/operations/listdocs.d.ts +9 -0
  143. package/dist/esm/models/operations/listdocs.d.ts.map +1 -1
  144. package/dist/esm/models/operations/listdocs.js +11 -0
  145. package/dist/esm/models/operations/listdocs.js.map +1 -1
  146. package/dist/esm/models/operations/querycollection.d.ts +3 -0
  147. package/dist/esm/models/operations/querycollection.d.ts.map +1 -1
  148. package/dist/esm/models/operations/querycollection.js +9 -0
  149. package/dist/esm/models/operations/querycollection.js.map +1 -1
  150. package/dist/esm/models/operations/updatecollection.d.ts +10 -4
  151. package/dist/esm/models/operations/updatecollection.d.ts.map +1 -1
  152. package/dist/esm/models/operations/updatecollection.js +8 -1
  153. package/dist/esm/models/operations/updatecollection.js.map +1 -1
  154. package/dist/esm/models/operations/updatedocs.d.ts +3 -0
  155. package/dist/esm/models/operations/updatedocs.d.ts.map +1 -1
  156. package/dist/esm/models/operations/updatedocs.js +1 -0
  157. package/dist/esm/models/operations/updatedocs.js.map +1 -1
  158. package/dist/esm/models/operations/upsertdocs.d.ts +3 -0
  159. package/dist/esm/models/operations/upsertdocs.d.ts.map +1 -1
  160. package/dist/esm/models/operations/upsertdocs.js +1 -0
  161. package/dist/esm/models/operations/upsertdocs.js.map +1 -1
  162. package/dist/esm/models/versioning.d.ts +100 -0
  163. package/dist/esm/models/versioning.d.ts.map +1 -0
  164. package/dist/esm/models/versioning.js +57 -0
  165. package/dist/esm/models/versioning.js.map +1 -0
  166. package/dist/esm/types/public.d.ts +80 -6
  167. package/dist/esm/types/public.d.ts.map +1 -1
  168. package/dist/esm/types/public.js +26 -7
  169. package/dist/esm/types/public.js.map +1 -1
  170. package/dist/esm/versioning.d.ts +63 -0
  171. package/dist/esm/versioning.d.ts.map +1 -0
  172. package/dist/esm/versioning.js +344 -0
  173. package/dist/esm/versioning.js.map +1 -0
  174. package/jsr.json +3 -1
  175. package/package.json +14 -2
  176. package/src/client.ts +300 -61
  177. package/src/compat/qdrant/client.ts +28 -16
  178. package/src/funcs/collectionsCreate.ts +1 -1
  179. package/src/funcs/collectionsDelete.ts +1 -1
  180. package/src/funcs/collectionsDocsGetBulkUpsert.ts +6 -1
  181. package/src/funcs/collectionsDocsListDocs.ts +2 -0
  182. package/src/index.ts +17 -0
  183. package/src/lib/config.ts +2 -2
  184. package/src/lib/queryInput.ts +3 -10
  185. package/src/models/collectionresponse.ts +17 -26
  186. package/src/models/index.ts +1 -0
  187. package/src/models/operations/bulkupsertdocs.ts +8 -0
  188. package/src/models/operations/createcollection.ts +39 -18
  189. package/src/models/operations/deletedocs.ts +4 -0
  190. package/src/models/operations/fetchdocs.ts +12 -0
  191. package/src/models/operations/getbulkupsertdocs.ts +11 -4
  192. package/src/models/operations/listdocs.ts +20 -0
  193. package/src/models/operations/querycollection.ts +12 -0
  194. package/src/models/operations/updatecollection.ts +21 -3
  195. package/src/models/operations/updatedocs.ts +4 -0
  196. package/src/models/operations/upsertdocs.ts +4 -0
  197. package/src/models/versioning.ts +118 -0
  198. package/src/types/public.ts +127 -14
  199. package/src/versioning.ts +490 -0
  200. package/examples/collectionScoped.example.ts +0 -38
  201. package/examples/collectionsList.example.ts +0 -25
  202. package/examples/package-lock.json +0 -612
  203. package/examples/package.json +0 -18
  204. package/test/integration/qdrant-compat-external.test.mjs +0 -351
  205. package/test/integration/qdrant-compat-live.test.mjs +0 -122
  206. package/test/null-response.test.mjs +0 -73
  207. package/test/public-api.test.mjs +0 -540
  208. package/test/qdrant-compat.test.mjs +0 -547
  209. package/tsconfig.json +0 -39
@@ -0,0 +1,490 @@
1
+ import * as z from "zod/v3";
2
+
3
+ import type { LambdaDBCore } from "./core.js";
4
+ import * as M from "./lib/matchers.js";
5
+ import { compactMap } from "./lib/primitives.js";
6
+ import { safeParse } from "./lib/schemas.js";
7
+ import type { RequestOptions } from "./lib/sdks.js";
8
+ import { extractSecurity, resolveGlobalSecurity } from "./lib/security.js";
9
+ import * as errors from "./models/errors/index.js";
10
+ import type { LambdaDBError } from "./models/errors/lambdadberror.js";
11
+ import type { ResponseValidationError } from "./models/errors/responsevalidationerror.js";
12
+ import type { SDKValidationError } from "./models/errors/sdkvalidationerror.js";
13
+ import {
14
+ AliasDetails$inboundSchema,
15
+ AliasTarget$schema,
16
+ RefDetails$inboundSchema,
17
+ RefSource$schema,
18
+ type AliasRef,
19
+ type BranchRef,
20
+ type BranchSource,
21
+ type TagRef,
22
+ type TagSource,
23
+ } from "./models/versioning.js";
24
+ import type {
25
+ ConnectionError,
26
+ InvalidRequestError,
27
+ RequestAbortedError,
28
+ RequestTimeoutError,
29
+ UnexpectedClientError,
30
+ } from "./models/errors/httpclienterrors.js";
31
+ import {
32
+ aliasDetailsWithDate,
33
+ refDetailsWithDate,
34
+ type AliasResponse,
35
+ type CreateAliasInput,
36
+ type CreateBranchInput,
37
+ type CreateBranchResponse,
38
+ type CreateTagInput,
39
+ type CreateTagResponse,
40
+ type ListAliasesResponse,
41
+ type ListBranchesResponse,
42
+ type ListTagsResponse,
43
+ type MessageResponse,
44
+ type RetargetAliasInput,
45
+ } from "./types/public.js";
46
+ import type { Result } from "./types/fp.js";
47
+
48
+ /** Exact public contract revision implemented by this SDK. */
49
+ export const DATA_VERSIONING_CONTRACT_REVISION =
50
+ "a52ce19f5a1ce5ad3a30a55a5560e4591f0be9fa" as const;
51
+
52
+ const refNamePattern = /^[a-zA-Z0-9_-]{3,52}$/;
53
+ const refNameSchema = z.string().regex(refNamePattern);
54
+
55
+ function checkedRefName(name: string): string {
56
+ if (!refNamePattern.test(name)) {
57
+ throw new TypeError(
58
+ "Ref names must contain 3 to 52 letters, numbers, underscores, or hyphens",
59
+ );
60
+ }
61
+ return name;
62
+ }
63
+
64
+ /** Creates a validated Branch read ref. */
65
+ export function branchRef(name: string): BranchRef {
66
+ return { kind: "branch", name: checkedRefName(name) };
67
+ }
68
+
69
+ /** Creates a validated Tag read ref. */
70
+ export function tagRef(name: string): TagRef {
71
+ return { kind: "tag", name: checkedRefName(name) };
72
+ }
73
+
74
+ /** Creates a validated Alias read ref. */
75
+ export function aliasRef(name: string): AliasRef {
76
+ return { kind: "alias", name: checkedRefName(name) };
77
+ }
78
+
79
+ /** Creates a validated Branch source, optionally at a Unix-millisecond cutoff. */
80
+ export function branchSource(
81
+ name: string,
82
+ asOf?: Date | number,
83
+ ): BranchSource {
84
+ const source: BranchSource = { kind: "branch", name: checkedRefName(name) };
85
+ if (asOf !== undefined) {
86
+ const milliseconds = asOf instanceof Date ? asOf.getTime() : asOf;
87
+ if (!Number.isInteger(milliseconds)) {
88
+ throw new TypeError("Branch source asOf must be a valid Date or integer Unix milliseconds");
89
+ }
90
+ source.asOf = milliseconds;
91
+ }
92
+ return source;
93
+ }
94
+
95
+ /** Creates a validated Tag source. `asOf` is intentionally unavailable. */
96
+ export function tagSource(name: string): TagSource {
97
+ return tagRef(name);
98
+ }
99
+
100
+ /** Creates a validated Branch Alias target. */
101
+ export function branchTarget(name: string): BranchRef {
102
+ return branchRef(name);
103
+ }
104
+
105
+ /** Creates a validated Tag Alias target. */
106
+ export function tagTarget(name: string): TagRef {
107
+ return tagRef(name);
108
+ }
109
+
110
+ export type VersioningError =
111
+ | errors.BadRequestError
112
+ | errors.UnauthenticatedError
113
+ | errors.ResourceNotFoundError
114
+ | errors.ResourceAlreadyExistsError
115
+ | errors.TooManyRequestsError
116
+ | errors.InternalServerError
117
+ | LambdaDBError
118
+ | ResponseValidationError
119
+ | ConnectionError
120
+ | RequestAbortedError
121
+ | RequestTimeoutError
122
+ | InvalidRequestError
123
+ | UnexpectedClientError
124
+ | SDKValidationError;
125
+
126
+ type VersioningRequest<TInput, TOutput> = {
127
+ body?: TInput | undefined;
128
+ bodySchema?: z.ZodType<TInput> | undefined;
129
+ method: "GET" | "POST" | "PATCH" | "DELETE";
130
+ path: string;
131
+ responseSchema: z.ZodType<TOutput>;
132
+ successStatus: 200 | 201;
133
+ };
134
+
135
+ async function requestVersioning<TInput, TOutput>(
136
+ client: LambdaDBCore,
137
+ request: VersioningRequest<TInput, TOutput>,
138
+ options?: RequestOptions,
139
+ ): Promise<Result<TOutput, VersioningError>> {
140
+ let body: string | null = null;
141
+ if (request.bodySchema !== undefined) {
142
+ const parsed = safeParse(
143
+ request.body,
144
+ (value) => request.bodySchema?.parse(value) as TInput,
145
+ "Input validation failed",
146
+ );
147
+ if (!parsed.ok) return parsed;
148
+ body = JSON.stringify(parsed.value);
149
+ }
150
+
151
+ const headers = new Headers(compactMap({
152
+ Accept: "application/json",
153
+ "Content-Type": body == null ? undefined : "application/json",
154
+ }));
155
+ const secConfig = await extractSecurity(client._options.projectApiKey);
156
+ const securityInput = secConfig == null ? {} : { projectApiKey: secConfig };
157
+ const requestSecurity = resolveGlobalSecurity(securityInput);
158
+ const retryConfig = options?.retries
159
+ || client._options.retryConfig
160
+ || {
161
+ strategy: "backoff" as const,
162
+ backoff: {
163
+ initialInterval: 500,
164
+ maxInterval: 60000,
165
+ exponent: 1.5,
166
+ maxElapsedTime: 3600000,
167
+ },
168
+ retryConnectionErrors: true,
169
+ };
170
+ const retryCodes = options?.retryCodes || ["429", "5XX"];
171
+ const context = {
172
+ options: client._options,
173
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
174
+ operationID: `${request.method} ${request.path}`,
175
+ oAuth2Scopes: null,
176
+ resolvedSecurity: requestSecurity,
177
+ securitySource: client._options.projectApiKey,
178
+ retryConfig,
179
+ retryCodes,
180
+ };
181
+
182
+ const requestResult = client._createRequest(context, {
183
+ security: requestSecurity,
184
+ method: request.method,
185
+ baseURL: options?.serverURL,
186
+ path: request.path,
187
+ headers,
188
+ body,
189
+ userAgent: client._options.userAgent,
190
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
191
+ }, options);
192
+ if (!requestResult.ok) return requestResult;
193
+
194
+ const httpRequest = requestResult.value;
195
+ const responseResult = await client._do(httpRequest, {
196
+ context,
197
+ errorCodes: ["400", "401", "404", "409", "429", "4XX", "500", "5XX"],
198
+ retryConfig,
199
+ retryCodes,
200
+ });
201
+ if (!responseResult.ok) return responseResult;
202
+
203
+ const response = responseResult.value;
204
+ const [result] = await M.match<TOutput, VersioningError>(
205
+ M.json(request.successStatus, request.responseSchema),
206
+ M.jsonErr(400, errors.BadRequestError$inboundSchema),
207
+ M.jsonErr(401, errors.UnauthenticatedError$inboundSchema),
208
+ M.jsonErr(404, errors.ResourceNotFoundError$inboundSchema),
209
+ M.jsonErr(409, errors.ResourceAlreadyExistsError$inboundSchema),
210
+ M.jsonErr(429, errors.TooManyRequestsError$inboundSchema),
211
+ M.jsonErr(500, errors.InternalServerError$inboundSchema),
212
+ M.fail("4XX"),
213
+ M.fail("5XX"),
214
+ )(response, httpRequest, {
215
+ extraFields: { HttpMeta: { Response: response, Request: httpRequest } },
216
+ });
217
+ return result;
218
+ }
219
+
220
+ function pathFor(collectionName: string, suffix: string): string {
221
+ return `/collections/${encodeURIComponent(collectionName)}${suffix}`;
222
+ }
223
+
224
+ const createBranchSchema: z.ZodType<CreateBranchInput> = z.object({
225
+ branchName: z.string().regex(refNamePattern),
226
+ source: RefSource$schema.optional(),
227
+ }).strict();
228
+ const createBranchResponseSchema = z.object({ branch: RefDetails$inboundSchema });
229
+ const listBranchesResponseSchema = z.object({ branches: z.array(RefDetails$inboundSchema) });
230
+
231
+ const createTagSchema: z.ZodType<CreateTagInput> = z.object({
232
+ tagName: z.string().regex(refNamePattern),
233
+ source: RefSource$schema.optional(),
234
+ }).strict();
235
+ const createTagResponseSchema = z.object({ tag: RefDetails$inboundSchema });
236
+ const listTagsResponseSchema = z.object({ tags: z.array(RefDetails$inboundSchema) });
237
+
238
+ const createAliasSchema: z.ZodType<CreateAliasInput> = z.object({
239
+ aliasName: z.string().regex(refNamePattern),
240
+ target: AliasTarget$schema,
241
+ }).strict();
242
+ const retargetAliasSchema: z.ZodType<RetargetAliasInput> = z.object({
243
+ target: AliasTarget$schema,
244
+ }).strict();
245
+ const aliasResponseSchema = z.object({ alias: AliasDetails$inboundSchema });
246
+ const listAliasesResponseSchema = z.object({ aliases: z.array(AliasDetails$inboundSchema) });
247
+ const messageResponseSchema = z.object({ message: z.string() });
248
+
249
+ export class CollectionBranches {
250
+ constructor(
251
+ private readonly client: LambdaDBCore,
252
+ private readonly collectionName: string,
253
+ ) {}
254
+
255
+ async create(input: CreateBranchInput, options?: RequestOptions): Promise<CreateBranchResponse> {
256
+ const result = await this.createSafe(input, options);
257
+ if (!result.ok) throw result.error;
258
+ return result.value;
259
+ }
260
+
261
+ async createSafe(
262
+ input: CreateBranchInput,
263
+ options?: RequestOptions,
264
+ ): Promise<Result<CreateBranchResponse, VersioningError>> {
265
+ const result = await requestVersioning(this.client, {
266
+ body: input,
267
+ bodySchema: createBranchSchema,
268
+ method: "POST",
269
+ path: pathFor(this.collectionName, "/branches"),
270
+ responseSchema: createBranchResponseSchema,
271
+ successStatus: 201,
272
+ }, options);
273
+ if (!result.ok) return result;
274
+ return { ok: true, value: { branch: refDetailsWithDate(result.value.branch) } };
275
+ }
276
+
277
+ async list(options?: RequestOptions): Promise<ListBranchesResponse> {
278
+ const result = await this.listSafe(options);
279
+ if (!result.ok) throw result.error;
280
+ return result.value;
281
+ }
282
+
283
+ async listSafe(options?: RequestOptions): Promise<Result<ListBranchesResponse, VersioningError>> {
284
+ const result = await requestVersioning(this.client, {
285
+ method: "GET",
286
+ path: pathFor(this.collectionName, "/branches"),
287
+ responseSchema: listBranchesResponseSchema,
288
+ successStatus: 200,
289
+ }, options);
290
+ if (!result.ok) return result;
291
+ return { ok: true, value: { branches: result.value.branches.map(refDetailsWithDate) } };
292
+ }
293
+
294
+ async delete(branchName: string, options?: RequestOptions): Promise<MessageResponse> {
295
+ const result = await this.deleteSafe(branchName, options);
296
+ if (!result.ok) throw result.error;
297
+ return result.value;
298
+ }
299
+
300
+ async deleteSafe(
301
+ branchName: string,
302
+ options?: RequestOptions,
303
+ ): Promise<Result<MessageResponse, VersioningError>> {
304
+ const parsedName = safeParse(
305
+ branchName,
306
+ (value) => refNameSchema.parse(value),
307
+ "Input validation failed",
308
+ );
309
+ if (!parsedName.ok) return parsedName;
310
+ return requestVersioning(this.client, {
311
+ method: "DELETE",
312
+ path: pathFor(this.collectionName, `/branches/${encodeURIComponent(parsedName.value)}`),
313
+ responseSchema: messageResponseSchema,
314
+ successStatus: 200,
315
+ }, options);
316
+ }
317
+ }
318
+
319
+ export class CollectionTags {
320
+ constructor(
321
+ private readonly client: LambdaDBCore,
322
+ private readonly collectionName: string,
323
+ ) {}
324
+
325
+ async create(input: CreateTagInput, options?: RequestOptions): Promise<CreateTagResponse> {
326
+ const result = await this.createSafe(input, options);
327
+ if (!result.ok) throw result.error;
328
+ return result.value;
329
+ }
330
+
331
+ async createSafe(
332
+ input: CreateTagInput,
333
+ options?: RequestOptions,
334
+ ): Promise<Result<CreateTagResponse, VersioningError>> {
335
+ const result = await requestVersioning(this.client, {
336
+ body: input,
337
+ bodySchema: createTagSchema,
338
+ method: "POST",
339
+ path: pathFor(this.collectionName, "/tags"),
340
+ responseSchema: createTagResponseSchema,
341
+ successStatus: 201,
342
+ }, options);
343
+ if (!result.ok) return result;
344
+ return { ok: true, value: { tag: refDetailsWithDate(result.value.tag) } };
345
+ }
346
+
347
+ async list(options?: RequestOptions): Promise<ListTagsResponse> {
348
+ const result = await this.listSafe(options);
349
+ if (!result.ok) throw result.error;
350
+ return result.value;
351
+ }
352
+
353
+ async listSafe(options?: RequestOptions): Promise<Result<ListTagsResponse, VersioningError>> {
354
+ const result = await requestVersioning(this.client, {
355
+ method: "GET",
356
+ path: pathFor(this.collectionName, "/tags"),
357
+ responseSchema: listTagsResponseSchema,
358
+ successStatus: 200,
359
+ }, options);
360
+ if (!result.ok) return result;
361
+ return { ok: true, value: { tags: result.value.tags.map(refDetailsWithDate) } };
362
+ }
363
+
364
+ async delete(tagName: string, options?: RequestOptions): Promise<MessageResponse> {
365
+ const result = await this.deleteSafe(tagName, options);
366
+ if (!result.ok) throw result.error;
367
+ return result.value;
368
+ }
369
+
370
+ async deleteSafe(
371
+ tagName: string,
372
+ options?: RequestOptions,
373
+ ): Promise<Result<MessageResponse, VersioningError>> {
374
+ const parsedName = safeParse(
375
+ tagName,
376
+ (value) => refNameSchema.parse(value),
377
+ "Input validation failed",
378
+ );
379
+ if (!parsedName.ok) return parsedName;
380
+ return requestVersioning(this.client, {
381
+ method: "DELETE",
382
+ path: pathFor(this.collectionName, `/tags/${encodeURIComponent(parsedName.value)}`),
383
+ responseSchema: messageResponseSchema,
384
+ successStatus: 200,
385
+ }, options);
386
+ }
387
+ }
388
+
389
+ export class CollectionAliases {
390
+ constructor(
391
+ private readonly client: LambdaDBCore,
392
+ private readonly collectionName: string,
393
+ ) {}
394
+
395
+ async create(input: CreateAliasInput, options?: RequestOptions): Promise<AliasResponse> {
396
+ const result = await this.createSafe(input, options);
397
+ if (!result.ok) throw result.error;
398
+ return result.value;
399
+ }
400
+
401
+ async createSafe(
402
+ input: CreateAliasInput,
403
+ options?: RequestOptions,
404
+ ): Promise<Result<AliasResponse, VersioningError>> {
405
+ const result = await requestVersioning(this.client, {
406
+ body: input,
407
+ bodySchema: createAliasSchema,
408
+ method: "POST",
409
+ path: pathFor(this.collectionName, "/aliases"),
410
+ responseSchema: aliasResponseSchema,
411
+ successStatus: 201,
412
+ }, options);
413
+ if (!result.ok) return result;
414
+ return { ok: true, value: { alias: aliasDetailsWithDate(result.value.alias) } };
415
+ }
416
+
417
+ async list(options?: RequestOptions): Promise<ListAliasesResponse> {
418
+ const result = await this.listSafe(options);
419
+ if (!result.ok) throw result.error;
420
+ return result.value;
421
+ }
422
+
423
+ async listSafe(options?: RequestOptions): Promise<Result<ListAliasesResponse, VersioningError>> {
424
+ const result = await requestVersioning(this.client, {
425
+ method: "GET",
426
+ path: pathFor(this.collectionName, "/aliases"),
427
+ responseSchema: listAliasesResponseSchema,
428
+ successStatus: 200,
429
+ }, options);
430
+ if (!result.ok) return result;
431
+ return { ok: true, value: { aliases: result.value.aliases.map(aliasDetailsWithDate) } };
432
+ }
433
+
434
+ async retarget(
435
+ aliasName: string,
436
+ input: RetargetAliasInput,
437
+ options?: RequestOptions,
438
+ ): Promise<AliasResponse> {
439
+ const result = await this.retargetSafe(aliasName, input, options);
440
+ if (!result.ok) throw result.error;
441
+ return result.value;
442
+ }
443
+
444
+ async retargetSafe(
445
+ aliasName: string,
446
+ input: RetargetAliasInput,
447
+ options?: RequestOptions,
448
+ ): Promise<Result<AliasResponse, VersioningError>> {
449
+ const parsedName = safeParse(
450
+ aliasName,
451
+ (value) => refNameSchema.parse(value),
452
+ "Input validation failed",
453
+ );
454
+ if (!parsedName.ok) return parsedName;
455
+ const result = await requestVersioning(this.client, {
456
+ body: input,
457
+ bodySchema: retargetAliasSchema,
458
+ method: "PATCH",
459
+ path: pathFor(this.collectionName, `/aliases/${encodeURIComponent(parsedName.value)}`),
460
+ responseSchema: aliasResponseSchema,
461
+ successStatus: 200,
462
+ }, options);
463
+ if (!result.ok) return result;
464
+ return { ok: true, value: { alias: aliasDetailsWithDate(result.value.alias) } };
465
+ }
466
+
467
+ async delete(aliasName: string, options?: RequestOptions): Promise<MessageResponse> {
468
+ const result = await this.deleteSafe(aliasName, options);
469
+ if (!result.ok) throw result.error;
470
+ return result.value;
471
+ }
472
+
473
+ async deleteSafe(
474
+ aliasName: string,
475
+ options?: RequestOptions,
476
+ ): Promise<Result<MessageResponse, VersioningError>> {
477
+ const parsedName = safeParse(
478
+ aliasName,
479
+ (value) => refNameSchema.parse(value),
480
+ "Input validation failed",
481
+ );
482
+ if (!parsedName.ok) return parsedName;
483
+ return requestVersioning(this.client, {
484
+ method: "DELETE",
485
+ path: pathFor(this.collectionName, `/aliases/${encodeURIComponent(parsedName.value)}`),
486
+ responseSchema: messageResponseSchema,
487
+ successStatus: 200,
488
+ }, options);
489
+ }
490
+ }
@@ -1,38 +0,0 @@
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 {
13
- LambdaDBClient,
14
- type ListDocsInput,
15
- type ListDocsResponse,
16
- } from "@functional-systems/lambdadb";
17
-
18
- const client = new LambdaDBClient({
19
- projectApiKey: process.env.LAMBDADB_PROJECT_API_KEY ?? "<YOUR_PROJECT_API_KEY>",
20
- });
21
-
22
- const COLLECTION_NAME = "my-collection";
23
-
24
- async function main() {
25
- const collection = client.collection(COLLECTION_NAME);
26
-
27
- // Collection metadata
28
- const meta = await collection.get();
29
- console.log("Collection:", meta);
30
-
31
- // List documents (no collectionName in the call); use public types for params and result
32
- const listParams: ListDocsInput = { size: 10 };
33
- const listResult: ListDocsResponse = await collection.docs.list(listParams);
34
- const { docs, total, nextPageToken } = listResult;
35
- console.log(`Documents: ${docs.length} of ${total}`, nextPageToken ? "(has more)" : "");
36
- }
37
-
38
- main().catch(console.error);
@@ -1,25 +0,0 @@
1
- import dotenv from "dotenv";
2
- dotenv.config();
3
-
4
- /**
5
- * Example: list collections using the recommended LambdaDBClient.
6
- *
7
- * Run from the examples directory:
8
- * npm run build && npx tsx collectionsList.example.ts
9
- */
10
-
11
- import {
12
- LambdaDBClient,
13
- type ListCollectionsResponse,
14
- } from "@functional-systems/lambdadb";
15
-
16
- const client = new LambdaDBClient({
17
- projectApiKey: process.env.LAMBDADB_PROJECT_API_KEY ?? "<YOUR_PROJECT_API_KEY>",
18
- });
19
-
20
- async function main() {
21
- const result: ListCollectionsResponse = await client.listCollections();
22
- console.log(result);
23
- }
24
-
25
- main().catch(console.error);