@ariestools/cli 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/bin/aries.mjs +608 -185
- package/dist/bin/daemons/chain-server.mjs +152 -0
- package/dist/bin/daemons/dapp-server.mjs +970 -0
- package/dist/bin/daemons/datalake-dev.mjs +111520 -0
- package/dist/node/datalake.d.ts +100 -0
- package/dist/node/datalake.mjs +475 -0
- package/package.json +19 -11
|
@@ -0,0 +1,100 @@
|
|
|
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 interface StoredCredentials {
|
|
7
|
+
authToken: string
|
|
8
|
+
baseUrl: string
|
|
9
|
+
userId?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface WalletJwtCredentials {
|
|
13
|
+
baseUrl: string
|
|
14
|
+
walletJwt: true
|
|
15
|
+
userId?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CreateDatalakeClientOptions {
|
|
19
|
+
authToken?: AuthTokenSource
|
|
20
|
+
baseUrl?: string
|
|
21
|
+
driver?: 'local' | 'rest'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RestDatalakeClientOptions {
|
|
25
|
+
authToken: AuthTokenSource
|
|
26
|
+
baseUrl: string
|
|
27
|
+
fetchImpl?: typeof fetch
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RestPayloadsClientOptions {
|
|
31
|
+
authToken: PayloadsAuthTokenSource
|
|
32
|
+
baseUrl: string
|
|
33
|
+
datalakeId: string
|
|
34
|
+
fetchImpl?: typeof fetch
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface InsertPayloadsResult {
|
|
38
|
+
duplicates?: number
|
|
39
|
+
payloads: unknown[]
|
|
40
|
+
rejected?: string[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PayloadsClient {
|
|
44
|
+
clear(): Promise<{ removed: number }>
|
|
45
|
+
delete(hash: string): Promise<void>
|
|
46
|
+
get(hash: string): Promise<unknown>
|
|
47
|
+
getMany(hashes: string[]): Promise<unknown[]>
|
|
48
|
+
insert(payloads: unknown[]): Promise<InsertPayloadsResult>
|
|
49
|
+
next(options?: { cursor?: string; limit?: number }): Promise<{ nextCursor?: string; payloads: unknown[] }>
|
|
50
|
+
usage(): Promise<{ datalakeId: string; payloadCount: number }>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DatalakeClient {
|
|
54
|
+
create(body: unknown): Promise<unknown>
|
|
55
|
+
destroy(id: string): Promise<void>
|
|
56
|
+
get(id: string): Promise<unknown>
|
|
57
|
+
grant(id: string, body: unknown): Promise<unknown>
|
|
58
|
+
list(): Promise<unknown[]>
|
|
59
|
+
mintToken(id: string, body?: unknown): Promise<unknown>
|
|
60
|
+
revoke(id: string, body: unknown): Promise<void>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export declare function createDatalakeClient(options?: CreateDatalakeClientOptions): DatalakeClient
|
|
64
|
+
export declare class LocalDatalakeClient implements DatalakeClient {
|
|
65
|
+
create(body: unknown): Promise<unknown>
|
|
66
|
+
destroy(id: string): Promise<void>
|
|
67
|
+
get(id: string): Promise<unknown>
|
|
68
|
+
grant(id: string, body: unknown): Promise<unknown>
|
|
69
|
+
list(): Promise<unknown[]>
|
|
70
|
+
mintToken(id: string, body?: unknown): Promise<unknown>
|
|
71
|
+
revoke(id: string, body: unknown): Promise<void>
|
|
72
|
+
}
|
|
73
|
+
export declare class RestDatalakeClient implements DatalakeClient {
|
|
74
|
+
constructor(options: RestDatalakeClientOptions)
|
|
75
|
+
create(body: unknown): Promise<unknown>
|
|
76
|
+
destroy(id: string): Promise<void>
|
|
77
|
+
get(id: string): Promise<unknown>
|
|
78
|
+
grant(id: string, body: unknown): Promise<unknown>
|
|
79
|
+
list(): Promise<unknown[]>
|
|
80
|
+
mintToken(id: string, body?: unknown): Promise<unknown>
|
|
81
|
+
revoke(id: string, body: unknown): Promise<void>
|
|
82
|
+
}
|
|
83
|
+
export declare class RestPayloadsClient implements PayloadsClient {
|
|
84
|
+
constructor(options: RestPayloadsClientOptions)
|
|
85
|
+
clear(): Promise<{ removed: number }>
|
|
86
|
+
delete(hash: string): Promise<void>
|
|
87
|
+
get(hash: string): Promise<unknown>
|
|
88
|
+
getMany(hashes: string[]): Promise<unknown[]>
|
|
89
|
+
insert(payloads: unknown[]): Promise<InsertPayloadsResult>
|
|
90
|
+
next(options?: { cursor?: string; limit?: number }): Promise<{ nextCursor?: string; payloads: unknown[] }>
|
|
91
|
+
usage(): Promise<{ datalakeId: string; payloadCount: number }>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare function loadCredentials(): StoredCredentials | WalletJwtCredentials | undefined
|
|
95
|
+
export declare function saveCredentials(credentials: StoredCredentials | WalletJwtCredentials): void
|
|
96
|
+
export declare function clearCredentials(): void
|
|
97
|
+
export declare function getCredentialsLocation(): string
|
|
98
|
+
export declare function getDefaultDatalake(): string | undefined
|
|
99
|
+
export declare function setDefaultDatalake(id: string): void
|
|
100
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ariestools/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Aries Tools CLI - A suite of tools by Arie Trouw",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ariestools",
|
|
@@ -16,17 +16,25 @@
|
|
|
16
16
|
},
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
"./datalake": {
|
|
21
|
+
"types": "./dist/node/datalake.d.ts",
|
|
22
|
+
"default": "./dist/node/datalake.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
19
26
|
"bin": {
|
|
20
27
|
"aries": "dist/bin/aries.mjs"
|
|
21
28
|
},
|
|
22
29
|
"files": [
|
|
23
30
|
"dist/bin",
|
|
31
|
+
"dist/node",
|
|
24
32
|
"dist/plugins",
|
|
25
33
|
"README.md"
|
|
26
34
|
],
|
|
27
35
|
"dependencies": {
|
|
28
36
|
"@opentelemetry/api": "~1.9.1",
|
|
29
|
-
"@xyo-network/sdk-protocol": "~7.2.
|
|
37
|
+
"@xyo-network/sdk-protocol": "~7.2.2",
|
|
30
38
|
"async-mutex": "~0.5.0",
|
|
31
39
|
"ethers": "~6.17.0",
|
|
32
40
|
"imghash": "~1.1.4",
|
|
@@ -35,15 +43,14 @@
|
|
|
35
43
|
"sharp": "~0.35.3",
|
|
36
44
|
"sharp-phash": "~2.2.0",
|
|
37
45
|
"zod": "~4.4.3",
|
|
38
|
-
"@ariestools/aries-
|
|
39
|
-
"@xyo-network/wallet-xl1-cli": "~0.1.
|
|
40
|
-
"@ariestools/aries-dapp-serve": "~0.1.
|
|
41
|
-
"@ariestools/aries-dapp-core": "~0.1.8"
|
|
46
|
+
"@ariestools/aries-dapp-core": "~0.1.9",
|
|
47
|
+
"@xyo-network/wallet-xl1-cli": "~0.1.9",
|
|
48
|
+
"@ariestools/aries-dapp-serve": "~0.1.9"
|
|
42
49
|
},
|
|
43
50
|
"devDependencies": {
|
|
44
|
-
"@ariestools/sdk": "~8.1.
|
|
45
|
-
"@ariestools/toolchain": "~8.7.
|
|
46
|
-
"@ariestools/tsconfig": "~8.7.
|
|
51
|
+
"@ariestools/sdk": "~8.1.2",
|
|
52
|
+
"@ariestools/toolchain": "~8.7.20",
|
|
53
|
+
"@ariestools/tsconfig": "~8.7.20",
|
|
47
54
|
"@metamask/json-rpc-engine": "~10.5.0",
|
|
48
55
|
"@types/node": "~26.1.1",
|
|
49
56
|
"@xyo-network/sdk": "~7.2.1",
|
|
@@ -54,7 +61,8 @@
|
|
|
54
61
|
"typescript": "~6.0.3",
|
|
55
62
|
"vite": "~8.1.5",
|
|
56
63
|
"vitest": "~4.1.10",
|
|
57
|
-
"@ariestools/cli-lib": "~0.1.
|
|
64
|
+
"@ariestools/cli-lib": "~0.1.9",
|
|
65
|
+
"@ariestools/aries-datalake-client": "~0.1.9"
|
|
58
66
|
},
|
|
59
67
|
"engines": {
|
|
60
68
|
"node": ">=18.17.1"
|
|
@@ -65,6 +73,6 @@
|
|
|
65
73
|
},
|
|
66
74
|
"scripts": {
|
|
67
75
|
"package-clean": "rm -rf dist bundle",
|
|
68
|
-
"package-compile": "tsc -p tsconfig.build.json --noEmit && rolldown -c rolldown.config.ts && tsx scripts/buildBundle.ts"
|
|
76
|
+
"package-compile": "tsc -p tsconfig.build.json --noEmit && rolldown -c rolldown.config.ts && tsx scripts/buildBundle.ts && tsx scripts/emitDatalakeTypes.ts"
|
|
69
77
|
}
|
|
70
78
|
}
|