@ariestools/cli 0.1.8 → 0.1.10

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,220 @@
1
+ /** Programmatic datalake client API shipped with @ariestools/cli (bundled). */
2
+
3
+ export type AuthTokenSource = string | (() => string | Promise<string>)
4
+ export type PayloadsAuthTokenSource = AuthTokenSource
5
+
6
+ export type DatalakeRole = 'viewer' | 'runner'
7
+ export type DatalakePrincipal = string
8
+ export type DatalakeTier = 'small' | 'medium' | 'large' | 'archive'
9
+ export type DatalakeRegion = 'us-west-2' | 'us-east-1' | 'eu-west-1'
10
+ export type DatalakeStatus =
11
+ | 'pending'
12
+ | 'provisioning'
13
+ | 'ready'
14
+ | 'resizing'
15
+ | 'deprovisioning'
16
+ | 'deleted'
17
+ | 'error'
18
+
19
+ export interface RateLimitOverrides {
20
+ anonymousPerMinute?: number
21
+ authenticatedPerMinute?: number
22
+ burstFactor?: number
23
+ }
24
+
25
+ export interface DatalakeConfig {
26
+ allowedSchemas?: string[]
27
+ disallowedSchemas?: string[]
28
+ iops?: number
29
+ rateLimits?: RateLimitOverrides
30
+ region?: DatalakeRegion
31
+ retentionDays?: number | null
32
+ sizeBytes?: number
33
+ tier: DatalakeTier
34
+ /** @deprecated No-op; archivist recomputes hashes trustlessly. */
35
+ verifyHashes?: boolean
36
+ }
37
+
38
+ export interface AclEntry {
39
+ grantedAt: string
40
+ grantedBy?: string
41
+ principal: DatalakePrincipal
42
+ role: DatalakeRole
43
+ }
44
+
45
+ export interface DatalakeUsage {
46
+ bytesStored: number
47
+ bytesStoredLimit: number
48
+ payloadCount: number
49
+ readsLast24h: number
50
+ writesLast24h: number
51
+ }
52
+
53
+ export interface DatalakeDescriptor {
54
+ acl: AclEntry[]
55
+ config: DatalakeConfig
56
+ createdAt: string
57
+ errorMessage?: string
58
+ id: string
59
+ name: string
60
+ ownerId: string
61
+ status: DatalakeStatus
62
+ updatedAt: string
63
+ url?: string
64
+ usage?: DatalakeUsage
65
+ }
66
+
67
+ export interface DatalakeToken {
68
+ datalakeId: string
69
+ expiresAt: string
70
+ role: DatalakeRole
71
+ token: string
72
+ url: string
73
+ }
74
+
75
+ export interface CreateDatalakeRequest {
76
+ config: DatalakeConfig
77
+ name: string
78
+ }
79
+
80
+ export interface GrantRequest {
81
+ datalakeId: string
82
+ principal: DatalakePrincipal
83
+ role: DatalakeRole
84
+ }
85
+
86
+ export interface RevokeRequest {
87
+ datalakeId: string
88
+ principal: DatalakePrincipal
89
+ }
90
+
91
+ export interface TokenRequest {
92
+ datalakeId: string
93
+ role: DatalakeRole
94
+ ttlSeconds?: number
95
+ }
96
+
97
+ export interface StoredCredentials {
98
+ authToken: string
99
+ baseUrl: string
100
+ userId?: string
101
+ }
102
+
103
+ export interface WalletJwtCredentials {
104
+ baseUrl: string
105
+ walletJwt: true
106
+ userId?: string
107
+ }
108
+
109
+ export interface CreateDatalakeClientOptions {
110
+ authToken?: AuthTokenSource
111
+ baseUrl?: string
112
+ driver?: 'local' | 'rest'
113
+ }
114
+
115
+ export interface RestDatalakeClientOptions {
116
+ authToken: AuthTokenSource
117
+ baseUrl: string
118
+ fetchImpl?: typeof fetch
119
+ }
120
+
121
+ export interface RestPayloadsClientOptions {
122
+ authToken: PayloadsAuthTokenSource
123
+ baseUrl: string
124
+ datalakeId: string
125
+ fetchImpl?: typeof fetch
126
+ }
127
+
128
+ export interface DatalakeInsertSummary {
129
+ duplicates: number
130
+ rejected: string[]
131
+ }
132
+
133
+ /** Result of PayloadsClient.insert — matches RestPayloadsClient runtime. */
134
+ export interface InsertPayloadsResult {
135
+ inserted: unknown[]
136
+ summary: DatalakeInsertSummary
137
+ }
138
+
139
+ export interface NextPayloadsResult {
140
+ nextCursor?: string
141
+ payloads: unknown[]
142
+ }
143
+
144
+ export interface DatalakeUsageReport {
145
+ datalakeId: string
146
+ payloadCount: number
147
+ rateLimits?: {
148
+ anonymous?: { limit: number; remaining: number }
149
+ authenticated?: { limit: number; remaining: number }
150
+ }
151
+ }
152
+
153
+ export interface PayloadsClient {
154
+ clear(): Promise<{ removed: number }>
155
+ delete(hash: string): Promise<void>
156
+ get(hash: string): Promise<unknown>
157
+ getMany(hashes: string[]): Promise<unknown[]>
158
+ insert(payloads: unknown[]): Promise<InsertPayloadsResult>
159
+ next(options?: {
160
+ cursor?: string
161
+ limit?: number
162
+ order?: 'asc' | 'desc'
163
+ schemas?: string[]
164
+ }): Promise<NextPayloadsResult>
165
+ usage(): Promise<DatalakeUsageReport>
166
+ }
167
+
168
+ export interface DatalakeClient {
169
+ create(request: CreateDatalakeRequest): Promise<DatalakeDescriptor>
170
+ describe(idOrName: string): Promise<DatalakeDescriptor>
171
+ destroy(idOrName: string): Promise<void>
172
+ grant(request: GrantRequest): Promise<DatalakeDescriptor>
173
+ list(): Promise<DatalakeDescriptor[]>
174
+ mintToken(request: TokenRequest): Promise<DatalakeToken>
175
+ revoke(request: RevokeRequest): Promise<DatalakeDescriptor>
176
+ }
177
+
178
+ export declare function createDatalakeClient(options?: CreateDatalakeClientOptions): DatalakeClient
179
+ export declare class LocalDatalakeClient implements DatalakeClient {
180
+ create(request: CreateDatalakeRequest): Promise<DatalakeDescriptor>
181
+ describe(idOrName: string): Promise<DatalakeDescriptor>
182
+ destroy(idOrName: string): Promise<void>
183
+ grant(request: GrantRequest): Promise<DatalakeDescriptor>
184
+ list(): Promise<DatalakeDescriptor[]>
185
+ mintToken(request: TokenRequest): Promise<DatalakeToken>
186
+ revoke(request: RevokeRequest): Promise<DatalakeDescriptor>
187
+ }
188
+ export declare class RestDatalakeClient implements DatalakeClient {
189
+ constructor(options: RestDatalakeClientOptions)
190
+ create(request: CreateDatalakeRequest): Promise<DatalakeDescriptor>
191
+ describe(idOrName: string): Promise<DatalakeDescriptor>
192
+ destroy(idOrName: string): Promise<void>
193
+ grant(request: GrantRequest): Promise<DatalakeDescriptor>
194
+ list(): Promise<DatalakeDescriptor[]>
195
+ mintToken(request: TokenRequest): Promise<DatalakeToken>
196
+ revoke(request: RevokeRequest): Promise<DatalakeDescriptor>
197
+ }
198
+ export declare class RestPayloadsClient implements PayloadsClient {
199
+ constructor(options: RestPayloadsClientOptions)
200
+ clear(): Promise<{ removed: number }>
201
+ delete(hash: string): Promise<void>
202
+ get(hash: string): Promise<unknown>
203
+ getMany(hashes: string[]): Promise<unknown[]>
204
+ insert(payloads: unknown[]): Promise<InsertPayloadsResult>
205
+ next(options?: {
206
+ cursor?: string
207
+ limit?: number
208
+ order?: 'asc' | 'desc'
209
+ schemas?: string[]
210
+ }): Promise<NextPayloadsResult>
211
+ usage(): Promise<DatalakeUsageReport>
212
+ }
213
+
214
+ export declare function loadCredentials(): StoredCredentials | WalletJwtCredentials | undefined
215
+ export declare function saveCredentials(credentials: StoredCredentials | WalletJwtCredentials): void
216
+ export declare function clearCredentials(): void
217
+ export declare function getCredentialsLocation(): string
218
+ export declare function getDefaultDatalake(): string | undefined
219
+ export declare function setDefaultDatalake(id: string): void
220
+ export declare function clearDefaultDatalake(): void
@@ -0,0 +1,475 @@
1
+ import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { homedir } from "node:os";
4
+ //#region ../datalake-core/dist/node/index.mjs
5
+ var DatalakeApiError = class extends Error {
6
+ code;
7
+ requestId;
8
+ status;
9
+ constructor(status, body) {
10
+ super(body.message);
11
+ this.name = "DatalakeApiError";
12
+ this.code = body.code;
13
+ this.status = status;
14
+ this.requestId = body.requestId;
15
+ }
16
+ };
17
+ function datalakeCollectionPath() {
18
+ return `/v1/datalakes`;
19
+ }
20
+ function datalakeResourcePath(idOrName) {
21
+ return `${datalakeCollectionPath()}/${encodeURIComponent(idOrName)}`;
22
+ }
23
+ function datalakeGrantsPath(idOrName) {
24
+ return `${datalakeResourcePath(idOrName)}/grants`;
25
+ }
26
+ function datalakeGrantPath(idOrName, principal) {
27
+ return `${datalakeGrantsPath(idOrName)}/${encodeURIComponent(principal)}`;
28
+ }
29
+ function datalakeTokensPath(idOrName) {
30
+ return `${datalakeResourcePath(idOrName)}/tokens`;
31
+ }
32
+ var DATALAKE_HEADER_DUPLICATES = "x-datalake-duplicates";
33
+ var DATALAKE_HEADER_REJECTED = "x-datalake-rejected";
34
+ function datalakePlaneResourcePath(id) {
35
+ return `/v1/datalakes/${encodeURIComponent(id)}`;
36
+ }
37
+ function datalakePlaneInsertPath(id) {
38
+ return `${datalakePlaneResourcePath(id)}/insert`;
39
+ }
40
+ function datalakePlaneGetPath(id, hash) {
41
+ return `${datalakePlaneResourcePath(id)}/get/${encodeURIComponent(hash)}`;
42
+ }
43
+ function datalakePlaneGetManyPath(id) {
44
+ return `${datalakePlaneResourcePath(id)}/get`;
45
+ }
46
+ function datalakePlaneNextPath(id) {
47
+ return `${datalakePlaneResourcePath(id)}/next`;
48
+ }
49
+ function datalakePlaneDeletePath(id, hash) {
50
+ return `${datalakePlaneResourcePath(id)}/delete/${encodeURIComponent(hash)}`;
51
+ }
52
+ function datalakePlaneClearPath(id) {
53
+ return `${datalakePlaneResourcePath(id)}/clear`;
54
+ }
55
+ function datalakePlaneUsagePath(id) {
56
+ return `${datalakePlaneResourcePath(id)}/usage`;
57
+ }
58
+ //#endregion
59
+ //#region ../datalake-client/dist/node/index.mjs
60
+ function getAriesHome() {
61
+ return process.env.ARIES_HOME ?? path.join(homedir(), ".aries");
62
+ }
63
+ function getDatalakeStoreDir() {
64
+ return path.join(getAriesHome(), "datalakes");
65
+ }
66
+ function getLocalDatalakeStorePath() {
67
+ return path.join(getDatalakeStoreDir(), "local-store.json");
68
+ }
69
+ function getCredentialsPath() {
70
+ return path.join(getAriesHome(), "credentials.json");
71
+ }
72
+ function getDefaultDatalakePath() {
73
+ return path.join(getAriesHome(), "datalake-default.json");
74
+ }
75
+ function saveCredentials(credentials) {
76
+ const home = getAriesHome();
77
+ if (!existsSync(home)) mkdirSync(home, { recursive: true });
78
+ const filePath = getCredentialsPath();
79
+ writeFileSync(filePath, JSON.stringify(credentials, void 0, 2), "utf8");
80
+ try {
81
+ chmodSync(filePath, 384);
82
+ } catch {}
83
+ }
84
+ function loadCredentials() {
85
+ const filePath = getCredentialsPath();
86
+ if (!existsSync(filePath)) return void 0;
87
+ try {
88
+ const raw = readFileSync(filePath, "utf8");
89
+ return JSON.parse(raw);
90
+ } catch {
91
+ return;
92
+ }
93
+ }
94
+ function clearCredentials() {
95
+ const filePath = getCredentialsPath();
96
+ if (existsSync(filePath)) unlinkSync(filePath);
97
+ }
98
+ function getCredentialsLocation() {
99
+ return path.resolve(getCredentialsPath());
100
+ }
101
+ var LOCAL_OWNER_ID = "local-user";
102
+ var TIER_SIZE_DEFAULTS = {
103
+ small: 10 * 1024 * 1024 * 1024,
104
+ medium: 100 * 1024 * 1024 * 1024,
105
+ large: 1024 * 1024 * 1024 * 1024,
106
+ archive: 10 * 1024 * 1024 * 1024 * 1024
107
+ };
108
+ var TIER_IOPS_DEFAULTS = {
109
+ small: 500,
110
+ medium: 2e3,
111
+ large: 1e4,
112
+ archive: 0
113
+ };
114
+ function readStore() {
115
+ const filePath = getLocalDatalakeStorePath();
116
+ if (!existsSync(filePath)) return { datalakes: [] };
117
+ try {
118
+ const raw = readFileSync(filePath, "utf8");
119
+ return JSON.parse(raw);
120
+ } catch {
121
+ return { datalakes: [] };
122
+ }
123
+ }
124
+ function writeStore(store) {
125
+ const dir = getDatalakeStoreDir();
126
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
127
+ writeFileSync(getLocalDatalakeStorePath(), JSON.stringify(store, void 0, 2), "utf8");
128
+ }
129
+ function generateId() {
130
+ return `dl_${Math.random().toString(36).slice(2, 10)}${Date.now().toString(36)}`;
131
+ }
132
+ function findDatalake(store, idOrName) {
133
+ return store.datalakes.find((dl) => dl.id === idOrName || dl.name === idOrName);
134
+ }
135
+ function requireDatalake(store, idOrName) {
136
+ const found = findDatalake(store, idOrName);
137
+ if (!found) throw new Error(`Datalake not found: ${idOrName}`);
138
+ return found;
139
+ }
140
+ var LocalDatalakeClient = class {
141
+ async create(request) {
142
+ const store = readStore();
143
+ if (store.datalakes.some((dl) => dl.name === request.name)) throw new Error(`Datalake already exists: ${request.name}`);
144
+ const now = (/* @__PURE__ */ new Date()).toISOString();
145
+ const tier = request.config.tier;
146
+ const descriptor = {
147
+ id: generateId(),
148
+ name: request.name,
149
+ ownerId: LOCAL_OWNER_ID,
150
+ config: {
151
+ tier,
152
+ sizeBytes: request.config.sizeBytes ?? TIER_SIZE_DEFAULTS[tier],
153
+ iops: request.config.iops ?? TIER_IOPS_DEFAULTS[tier],
154
+ retentionDays: request.config.retentionDays ?? 30,
155
+ region: request.config.region ?? "us-west-2",
156
+ allowedSchemas: request.config.allowedSchemas ?? [],
157
+ disallowedSchemas: request.config.disallowedSchemas ?? []
158
+ },
159
+ status: "ready",
160
+ url: `http://localhost:8080/datalakes/${request.name}`,
161
+ acl: [],
162
+ usage: {
163
+ payloadCount: 0,
164
+ bytesStored: 0,
165
+ bytesStoredLimit: request.config.sizeBytes ?? TIER_SIZE_DEFAULTS[tier],
166
+ readsLast24h: 0,
167
+ writesLast24h: 0
168
+ },
169
+ createdAt: now,
170
+ updatedAt: now
171
+ };
172
+ store.datalakes.push(descriptor);
173
+ writeStore(store);
174
+ return descriptor;
175
+ }
176
+ async describe(idOrName) {
177
+ return requireDatalake(readStore(), idOrName);
178
+ }
179
+ async destroy(idOrName) {
180
+ const store = readStore();
181
+ const found = findDatalake(store, idOrName);
182
+ if (!found) throw new Error(`Datalake not found: ${idOrName}`);
183
+ store.datalakes = store.datalakes.filter((dl) => dl.id !== found.id);
184
+ writeStore(store);
185
+ }
186
+ async grant(request) {
187
+ const store = readStore();
188
+ const datalake = requireDatalake(store, request.datalakeId);
189
+ const existing = datalake.acl.findIndex((entry2) => entry2.principal === request.principal);
190
+ const entry = {
191
+ principal: request.principal,
192
+ role: request.role,
193
+ grantedAt: (/* @__PURE__ */ new Date()).toISOString(),
194
+ grantedBy: LOCAL_OWNER_ID
195
+ };
196
+ if (existing === -1) datalake.acl.push(entry);
197
+ else datalake.acl[existing] = entry;
198
+ datalake.updatedAt = entry.grantedAt;
199
+ writeStore(store);
200
+ return datalake;
201
+ }
202
+ async list() {
203
+ return readStore().datalakes;
204
+ }
205
+ async mintToken(request) {
206
+ const datalake = requireDatalake(readStore(), request.datalakeId);
207
+ const ttl = request.ttlSeconds ?? 3600;
208
+ return {
209
+ token: `local.${Buffer.from(JSON.stringify({
210
+ dl: datalake.id,
211
+ role: request.role,
212
+ exp: Math.floor(Date.now() / 1e3) + ttl
213
+ })).toString("base64url")}`,
214
+ datalakeId: datalake.id,
215
+ role: request.role,
216
+ expiresAt: new Date(Date.now() + ttl * 1e3).toISOString(),
217
+ url: datalake.url ?? `http://localhost:8080/datalakes/${datalake.name}`
218
+ };
219
+ }
220
+ async revoke(request) {
221
+ const store = readStore();
222
+ const datalake = requireDatalake(store, request.datalakeId);
223
+ datalake.acl = datalake.acl.filter((entry) => entry.principal !== request.principal);
224
+ datalake.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
225
+ writeStore(store);
226
+ return datalake;
227
+ }
228
+ };
229
+ var RestDatalakeClient = class {
230
+ authToken;
231
+ baseUrl;
232
+ fetchImpl;
233
+ constructor(options) {
234
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
235
+ this.authToken = options.authToken;
236
+ this.fetchImpl = options.fetchImpl ?? fetch;
237
+ }
238
+ async create(request) {
239
+ const body = {
240
+ name: request.name,
241
+ config: request.config
242
+ };
243
+ return this.request(datalakeCollectionPath(), {
244
+ method: "POST",
245
+ body
246
+ });
247
+ }
248
+ async describe(idOrName) {
249
+ return this.request(datalakeResourcePath(idOrName));
250
+ }
251
+ async destroy(idOrName) {
252
+ await this.request(datalakeResourcePath(idOrName), { method: "DELETE" });
253
+ }
254
+ async grant(request) {
255
+ const body = {
256
+ principal: request.principal,
257
+ role: request.role
258
+ };
259
+ return this.request(datalakeGrantsPath(request.datalakeId), {
260
+ method: "POST",
261
+ body
262
+ });
263
+ }
264
+ async list() {
265
+ return this.request(datalakeCollectionPath());
266
+ }
267
+ async mintToken(request) {
268
+ const body = {
269
+ role: request.role,
270
+ ttlSeconds: request.ttlSeconds
271
+ };
272
+ return this.request(datalakeTokensPath(request.datalakeId), {
273
+ method: "POST",
274
+ body
275
+ });
276
+ }
277
+ async revoke(request) {
278
+ return this.request(datalakeGrantPath(request.datalakeId, request.principal), { method: "DELETE" });
279
+ }
280
+ async request(path4, options = {}) {
281
+ const url = `${this.baseUrl}${path4}`;
282
+ const method = options.method ?? "GET";
283
+ const headers = {
284
+ accept: "application/json",
285
+ authorization: `Bearer ${await this.resolveAuthToken()}`
286
+ };
287
+ const init = {
288
+ method,
289
+ headers
290
+ };
291
+ if (options.body !== void 0) {
292
+ headers["content-type"] = "application/json";
293
+ init.body = JSON.stringify(options.body);
294
+ }
295
+ const response = await this.fetchImpl(url, init);
296
+ if (response.status === 204) return;
297
+ const text = await response.text();
298
+ const payload = text.length > 0 ? JSON.parse(text) : void 0;
299
+ if (!response.ok) {
300
+ const errorBody = isApiErrorBody(payload) ? payload : {
301
+ code: "internal",
302
+ message: `Unexpected ${response.status} response from ${method} ${path4}`
303
+ };
304
+ throw new DatalakeApiError(response.status, errorBody);
305
+ }
306
+ return payload;
307
+ }
308
+ async resolveAuthToken() {
309
+ return typeof this.authToken === "function" ? await this.authToken() : this.authToken;
310
+ }
311
+ };
312
+ function isApiErrorBody(value) {
313
+ if (typeof value !== "object" || value === null) return false;
314
+ const maybe = value;
315
+ return typeof maybe.code === "string" && typeof maybe.message === "string";
316
+ }
317
+ function createDatalakeClient(options = {}) {
318
+ const envBaseUrl = process.env.ARIES_DATALAKE_API;
319
+ const credentials = loadCredentials();
320
+ const baseUrl = options.baseUrl ?? envBaseUrl ?? credentials?.baseUrl;
321
+ const authToken = options.authToken ?? credentials?.authToken;
322
+ if ((options.driver ?? (baseUrl && authToken ? "rest" : "local")) === "rest") {
323
+ if (!baseUrl || !authToken) throw new Error("REST driver requires a baseUrl and authToken. Run `aries datalake login` or set ARIES_DATALAKE_API and sign in.");
324
+ return new RestDatalakeClient({
325
+ baseUrl,
326
+ authToken
327
+ });
328
+ }
329
+ return new LocalDatalakeClient();
330
+ }
331
+ function setDefaultDatalake(name, id) {
332
+ const home = getAriesHome();
333
+ if (!existsSync(home)) mkdirSync(home, { recursive: true });
334
+ const payload = {
335
+ name,
336
+ id,
337
+ setAt: (/* @__PURE__ */ new Date()).toISOString()
338
+ };
339
+ writeFileSync(getDefaultDatalakePath(), JSON.stringify(payload, void 0, 2), "utf8");
340
+ }
341
+ function getDefaultDatalake() {
342
+ const filePath = getDefaultDatalakePath();
343
+ if (!existsSync(filePath)) return void 0;
344
+ try {
345
+ const raw = readFileSync(filePath, "utf8");
346
+ return JSON.parse(raw).name;
347
+ } catch {
348
+ return;
349
+ }
350
+ }
351
+ function clearDefaultDatalake() {
352
+ const filePath = getDefaultDatalakePath();
353
+ if (existsSync(filePath)) unlinkSync(filePath);
354
+ }
355
+ function extractOrigin(urlWithPossiblePath) {
356
+ try {
357
+ const parsed = new URL(urlWithPossiblePath);
358
+ return `${parsed.protocol}//${parsed.host}`;
359
+ } catch {
360
+ return urlWithPossiblePath.replace(/\/$/, "");
361
+ }
362
+ }
363
+ var RestPayloadsClient = class {
364
+ authToken;
365
+ datalakeId;
366
+ fetchImpl;
367
+ origin;
368
+ constructor(options) {
369
+ this.origin = extractOrigin(options.baseUrl);
370
+ this.datalakeId = options.datalakeId;
371
+ this.authToken = options.authToken;
372
+ this.fetchImpl = options.fetchImpl ?? fetch;
373
+ }
374
+ async clear() {
375
+ return this.request(datalakePlaneClearPath(this.datalakeId), { method: "POST" });
376
+ }
377
+ async delete(hash) {
378
+ await this.request(datalakePlaneDeletePath(this.datalakeId, hash), { method: "DELETE" });
379
+ }
380
+ async get(hash) {
381
+ return this.request(datalakePlaneGetPath(this.datalakeId, hash));
382
+ }
383
+ async getMany(hashes) {
384
+ if (hashes.length === 0) return [];
385
+ return this.request(datalakePlaneGetManyPath(this.datalakeId), {
386
+ method: "POST",
387
+ body: hashes
388
+ });
389
+ }
390
+ async insert(payloads) {
391
+ const body = payloads;
392
+ const { data, headers } = await this.requestWithHeaders(datalakePlaneInsertPath(this.datalakeId), {
393
+ method: "POST",
394
+ body
395
+ });
396
+ return {
397
+ inserted: data,
398
+ summary: readInsertSummary(headers)
399
+ };
400
+ }
401
+ async next(options = {}) {
402
+ const params = new URLSearchParams();
403
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
404
+ if (options.cursor) params.set("cursor", options.cursor);
405
+ if (options.schemas && options.schemas.length > 0) params.set("schemas", options.schemas.join(","));
406
+ if (options.order) params.set("order", options.order);
407
+ const suffix = params.toString();
408
+ const path4 = suffix ? `${datalakePlaneNextPath(this.datalakeId)}?${suffix}` : datalakePlaneNextPath(this.datalakeId);
409
+ const { data, headers } = await this.requestWithHeaders(path4);
410
+ return {
411
+ payloads: data,
412
+ nextCursor: headers.get("x-datalake-next-cursor") ?? void 0
413
+ };
414
+ }
415
+ async usage() {
416
+ return this.request(datalakePlaneUsagePath(this.datalakeId));
417
+ }
418
+ async request(path4, options = {}) {
419
+ const { data } = await this.requestWithHeaders(path4, options);
420
+ return data;
421
+ }
422
+ async requestWithHeaders(path4, options = {}) {
423
+ const method = options.method ?? "GET";
424
+ const headers = {
425
+ accept: "application/json",
426
+ authorization: `Bearer ${await this.resolveAuthToken()}`
427
+ };
428
+ const init = {
429
+ method,
430
+ headers
431
+ };
432
+ if (options.body !== void 0) {
433
+ headers["content-type"] = "application/json";
434
+ init.body = JSON.stringify(options.body);
435
+ }
436
+ const response = await this.fetchImpl(`${this.origin}${path4}`, init);
437
+ if (response.status === 204) return {
438
+ data: void 0,
439
+ headers: response.headers
440
+ };
441
+ const text = await response.text();
442
+ const payload = text.length > 0 ? JSON.parse(text) : void 0;
443
+ if (!response.ok) {
444
+ const errorBody = isApiErrorBody2(payload) ? payload : {
445
+ code: "internal",
446
+ message: `Unexpected ${response.status} response from ${method} ${path4}`
447
+ };
448
+ throw new DatalakeApiError(response.status, errorBody);
449
+ }
450
+ return {
451
+ data: payload,
452
+ headers: response.headers
453
+ };
454
+ }
455
+ async resolveAuthToken() {
456
+ return typeof this.authToken === "function" ? await this.authToken() : this.authToken;
457
+ }
458
+ };
459
+ function readInsertSummary(headers) {
460
+ const duplicatesRaw = headers.get(DATALAKE_HEADER_DUPLICATES);
461
+ const duplicates = duplicatesRaw === null ? 0 : Number.parseInt(duplicatesRaw, 10);
462
+ const rejectedRaw = headers.get(DATALAKE_HEADER_REJECTED);
463
+ const rejected = rejectedRaw === null || rejectedRaw.length === 0 ? [] : rejectedRaw.split(",").map((value) => value.trim()).filter((value) => value.length > 0);
464
+ return {
465
+ duplicates: Number.isFinite(duplicates) ? duplicates : 0,
466
+ rejected
467
+ };
468
+ }
469
+ function isApiErrorBody2(value) {
470
+ if (typeof value !== "object" || value === null) return false;
471
+ const maybe = value;
472
+ return typeof maybe.code === "string" && typeof maybe.message === "string";
473
+ }
474
+ //#endregion
475
+ export { LocalDatalakeClient, RestDatalakeClient, RestPayloadsClient, clearCredentials, clearDefaultDatalake, createDatalakeClient, getCredentialsLocation, getDefaultDatalake, loadCredentials, saveCredentials, setDefaultDatalake };