@arkiv-network/sdk 0.6.8-dev.1 → 0.6.8-dev.3
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 +52 -16
- package/dist/chains/index.d.cts +25 -25
- package/dist/chains/index.d.cts.map +1 -1
- package/dist/chains/index.d.ts +25 -25
- package/dist/consts-AUoL-v42.cjs +18 -0
- package/dist/consts-BV4PR-de.js +7 -0
- package/dist/consts-BV4PR-de.js.map +1 -0
- package/dist/{query-CO6f35AE.d.cts → entity-BSU5-vyY.d.cts} +68 -31
- package/dist/entity-BSU5-vyY.d.cts.map +1 -0
- package/dist/{query-BhdmAzYg.d.ts → entity-CHiZ2Qu1.d.ts} +68 -31
- package/dist/entity-CHiZ2Qu1.d.ts.map +1 -0
- package/dist/{queryBuilder-BvoQXa_u.d.ts → index-CzqHiUAo.d.ts} +202 -74
- package/dist/index-CzqHiUAo.d.ts.map +1 -0
- package/dist/{queryBuilder-zTsKXctT.d.cts → index-gj33r3rd.d.cts} +202 -74
- package/dist/index-gj33r3rd.d.cts.map +1 -0
- package/dist/index.cjs +63 -28
- package/dist/index.d.cts +90 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +91 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -21
- package/dist/index.js.map +1 -1
- package/dist/{payload-Da9gJMG5.d.ts → payload-B2kFJyah.d.ts} +1 -1
- package/dist/{payload-Da9gJMG5.d.ts.map → payload-B2kFJyah.d.ts.map} +1 -1
- package/dist/payload-Claf2jUO.js +13 -0
- package/dist/payload-Claf2jUO.js.map +1 -0
- package/dist/{payload-vwU3Rc6P.cjs → payload-DpA5PA-w.cjs} +0 -17
- package/dist/query/index.cjs +6 -2
- package/dist/query/index.d.cts +3 -3
- package/dist/query/index.d.ts +3 -3
- package/dist/query/index.js +3 -2
- package/dist/query/index.js.map +1 -1
- package/dist/{queryBuilder-DM-YO1Y7.cjs → queryBuilder-CTPwve9u.cjs} +229 -70
- package/dist/{queryBuilder-DonAg1aq.js → queryBuilder-D-ACo-g_.js} +201 -72
- package/dist/queryBuilder-D-ACo-g_.js.map +1 -0
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/index.cjs +4 -10
- package/dist/utils/index.d.cts +0 -1
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -3
- package/dist/utils/index.js.map +1 -1
- package/package.json +11 -15
- package/src/actions/public/buildQuery.ts +4 -0
- package/src/actions/wallet/createEntity.ts +12 -2
- package/src/actions/wallet/extendEntity.ts +6 -1
- package/src/actions/wallet/updateEntity.ts +12 -2
- package/src/clients/createPublicClient.test.ts +2 -0
- package/src/clients/decorators/arkivPublic.ts +67 -1
- package/src/clients/decorators/arkivWallet.ts +18 -0
- package/src/errors.ts +18 -0
- package/src/index.ts +0 -3
- package/src/query/engine.ts +22 -13
- package/src/query/index.ts +1 -0
- package/src/query/queryBuilder.ts +189 -94
- package/src/query/queryResult.ts +13 -7
- package/src/query/selectQueryBuilder.test.ts +210 -0
- package/src/query/selection.test.ts +120 -0
- package/src/query/selection.ts +116 -0
- package/src/types/attributes.ts +12 -0
- package/src/utils/arkivTransactions.test.ts +62 -0
- package/src/utils/arkivTransactions.ts +36 -27
- package/src/utils/index.ts +0 -1
- package/src/utils/validation.test.ts +60 -0
- package/src/utils/validation.ts +32 -0
- package/dist/accounts/index.cjs +0 -9
- package/dist/accounts/index.d.cts +0 -1
- package/dist/accounts/index.d.ts +0 -1
- package/dist/accounts/index.js +0 -1
- package/dist/payload-DKBYYjeA.js +0 -18
- package/dist/payload-DKBYYjeA.js.map +0 -1
- package/dist/query-BhdmAzYg.d.ts.map +0 -1
- package/dist/query-CO6f35AE.d.cts.map +0 -1
- package/dist/queryBuilder-BvoQXa_u.d.ts.map +0 -1
- package/dist/queryBuilder-DonAg1aq.js.map +0 -1
- package/dist/queryBuilder-zTsKXctT.d.cts.map +0 -1
- package/src/accounts/index.ts +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_consts = require('./consts-AUoL-v42.cjs');
|
|
1
2
|
let viem = require("viem");
|
|
2
3
|
|
|
3
4
|
//#region src/utils/logger.ts
|
|
@@ -120,6 +121,18 @@ var EntityMutationError = class extends Error {
|
|
|
120
121
|
this.name = "EntityMutationError";
|
|
121
122
|
}
|
|
122
123
|
};
|
|
124
|
+
var InvalidExpirationError = class extends Error {
|
|
125
|
+
constructor(expiresIn) {
|
|
126
|
+
super(`Invalid expiresIn: ${String(expiresIn)}. expiresIn must be a positive integer and a multiple of the Arkiv block time (${require_consts.BLOCK_TIME} seconds), because expiration is measured in whole blocks (1 block = ${require_consts.BLOCK_TIME} seconds).`);
|
|
127
|
+
this.name = "InvalidExpirationError";
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var InvalidAttributeError = class extends Error {
|
|
131
|
+
constructor(key, value) {
|
|
132
|
+
super(`Invalid numeric value for attribute "${key}": ${String(value)}. Numeric attribute values must be integers. To keep numeric ordering/range queries, scale it to an integer (e.g. Math.round(${String(value)} * 1000), dividing by 1000 on read); otherwise store it as a string (e.g. "${String(value)}").`);
|
|
133
|
+
this.name = "InvalidAttributeError";
|
|
134
|
+
}
|
|
135
|
+
};
|
|
123
136
|
var NoMoreResultsError = class extends Error {
|
|
124
137
|
constructor() {
|
|
125
138
|
super("No more results");
|
|
@@ -235,7 +248,7 @@ function processPredicates(predicates) {
|
|
|
235
248
|
}).join(" && ");
|
|
236
249
|
}
|
|
237
250
|
async function processQuery(client, queryParams) {
|
|
238
|
-
const { predicates, limit, cursor, ownedBy, createdBy, orderBy, validAtBlock, withAttributes, withMetadata, withPayload } = queryParams;
|
|
251
|
+
const { predicates, limit, cursor, ownedBy, createdBy, orderBy, validAtBlock, withAttributes, withMetadata, withPayload, includeData } = queryParams;
|
|
239
252
|
logger$1("Processing query with params %o", {
|
|
240
253
|
predicates,
|
|
241
254
|
cursor,
|
|
@@ -246,14 +259,15 @@ async function processQuery(client, queryParams) {
|
|
|
246
259
|
validAtBlock,
|
|
247
260
|
withAttributes,
|
|
248
261
|
withMetadata,
|
|
249
|
-
withPayload
|
|
262
|
+
withPayload,
|
|
263
|
+
includeData
|
|
250
264
|
});
|
|
251
265
|
let query = processPredicates(predicates);
|
|
252
266
|
if (ownedBy) query += ` && $owner=${ownedBy}`;
|
|
253
267
|
if (createdBy) query += ` && $creator=${createdBy}`;
|
|
254
268
|
query = query.trim();
|
|
255
269
|
if (query.startsWith("&& ")) query = query.slice(3);
|
|
256
|
-
const queryOptions = { includeData: {
|
|
270
|
+
const queryOptions = { includeData: includeData ?? {
|
|
257
271
|
key: true,
|
|
258
272
|
attributes: withAttributes ?? false,
|
|
259
273
|
payload: withPayload ?? false,
|
|
@@ -288,6 +302,12 @@ async function processQuery(client, queryParams) {
|
|
|
288
302
|
//#endregion
|
|
289
303
|
//#region src/query/queryResult.ts
|
|
290
304
|
const logger = getLogger("query:result");
|
|
305
|
+
/**
|
|
306
|
+
* The result of a query. Holds the fetched entities and supports cursor-based pagination.
|
|
307
|
+
*
|
|
308
|
+
* @typeParam TEntity - The shape of each entity, inferred from the query builder
|
|
309
|
+
* (a full {@link Entity}, or a projected object inferred from a `select()` selection).
|
|
310
|
+
*/
|
|
291
311
|
var QueryResult = class {
|
|
292
312
|
entities;
|
|
293
313
|
_endOfIteration;
|
|
@@ -325,6 +345,53 @@ var QueryResult = class {
|
|
|
325
345
|
}
|
|
326
346
|
};
|
|
327
347
|
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/query/selection.ts
|
|
350
|
+
/**
|
|
351
|
+
* Converts a {@link SelectArg} into the {@link RpcIncludeData} understood by the query engine.
|
|
352
|
+
* Every field is opt-in — anything not explicitly selected defaults to `false`, including the key.
|
|
353
|
+
* `undefined` or `"*"` selects everything.
|
|
354
|
+
*
|
|
355
|
+
* @param selection - The selection to convert
|
|
356
|
+
* @returns The fully-resolved include-data object for the RPC query
|
|
357
|
+
* @throws If an empty selection object is provided
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* selectionToIncludeData() // everything
|
|
361
|
+
* selectionToIncludeData("*") // everything
|
|
362
|
+
* selectionToIncludeData({ key: true }) // only the key
|
|
363
|
+
* selectionToIncludeData({ owner: true }) // only the owner
|
|
364
|
+
*/
|
|
365
|
+
function selectionToIncludeData(selection) {
|
|
366
|
+
if (selection === void 0 || selection === "*") return {
|
|
367
|
+
key: true,
|
|
368
|
+
attributes: true,
|
|
369
|
+
payload: true,
|
|
370
|
+
contentType: true,
|
|
371
|
+
expiration: true,
|
|
372
|
+
owner: true,
|
|
373
|
+
creator: true,
|
|
374
|
+
createdAtBlock: true,
|
|
375
|
+
lastModifiedAtBlock: true,
|
|
376
|
+
transactionIndexInBlock: true,
|
|
377
|
+
operationIndexInTransaction: true
|
|
378
|
+
};
|
|
379
|
+
if (!Object.values(selection).some((selected) => selected === true)) throw new Error("select() requires at least one field to be selected. Pass select() or select(\"*\") to select everything.");
|
|
380
|
+
return {
|
|
381
|
+
key: selection.key ?? false,
|
|
382
|
+
attributes: selection.attributes ?? false,
|
|
383
|
+
payload: selection.payload ?? false,
|
|
384
|
+
contentType: selection.contentType ?? false,
|
|
385
|
+
expiration: selection.expiresAtBlock ?? false,
|
|
386
|
+
owner: selection.owner ?? false,
|
|
387
|
+
creator: selection.creator ?? false,
|
|
388
|
+
createdAtBlock: selection.createdAtBlock ?? false,
|
|
389
|
+
lastModifiedAtBlock: selection.lastModifiedAtBlock ?? false,
|
|
390
|
+
transactionIndexInBlock: selection.transactionIndexInBlock ?? false,
|
|
391
|
+
operationIndexInTransaction: selection.operationIndexInTransaction ?? false
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
328
395
|
//#endregion
|
|
329
396
|
//#region src/query/queryBuilder.ts
|
|
330
397
|
/**
|
|
@@ -360,20 +427,21 @@ function desc(attributeName, attributeType) {
|
|
|
360
427
|
};
|
|
361
428
|
}
|
|
362
429
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
430
|
+
* BaseQueryBuilder holds the query-building logic shared by every query builder
|
|
431
|
+
* (filtering, ordering, pagination, execution). It follows the Builder pattern,
|
|
432
|
+
* allowing methods to be chained. Subclasses decide how data selection is expressed
|
|
433
|
+
* by implementing the protected `selectionParams` method.
|
|
434
|
+
*
|
|
435
|
+
* Use {@link SelectQueryBuilder} via `client.select()` to build and execute queries.
|
|
436
|
+
*
|
|
437
|
+
* @typeParam TEntity - The shape of each entity produced by {@link BaseQueryBuilder.fetch}.
|
|
367
438
|
*/
|
|
368
|
-
var
|
|
439
|
+
var BaseQueryBuilder = class {
|
|
369
440
|
_client;
|
|
370
441
|
_ownedBy;
|
|
371
442
|
_createdBy;
|
|
372
443
|
_orderBy;
|
|
373
444
|
_validAtBlock;
|
|
374
|
-
_withAttributes;
|
|
375
|
-
_withMetadata;
|
|
376
|
-
_withPayload;
|
|
377
445
|
_limit;
|
|
378
446
|
_cursor;
|
|
379
447
|
_predicates;
|
|
@@ -384,10 +452,10 @@ var QueryBuilder = class {
|
|
|
384
452
|
/**
|
|
385
453
|
* Sets the ownedBy filter
|
|
386
454
|
* @param ownedBy - The address of the owner
|
|
387
|
-
* @returns The
|
|
455
|
+
* @returns The query builder instance
|
|
388
456
|
*
|
|
389
457
|
* @example
|
|
390
|
-
* const builder =
|
|
458
|
+
* const builder = client.select()
|
|
391
459
|
* builder.ownedBy("0x1234567890123456789012345678901234567890")
|
|
392
460
|
*/
|
|
393
461
|
ownedBy(ownedBy) {
|
|
@@ -397,10 +465,10 @@ var QueryBuilder = class {
|
|
|
397
465
|
/**
|
|
398
466
|
* Sets the createdBy filter
|
|
399
467
|
* @param createdBy - The address of the creator
|
|
400
|
-
* @returns The
|
|
468
|
+
* @returns The query builder instance
|
|
401
469
|
*
|
|
402
470
|
* @example
|
|
403
|
-
* const builder =
|
|
471
|
+
* const builder = client.select()
|
|
404
472
|
* builder.createdBy("0x1234567890123456789012345678901234567890")
|
|
405
473
|
*/
|
|
406
474
|
createdBy(createdBy) {
|
|
@@ -427,51 +495,12 @@ var QueryBuilder = class {
|
|
|
427
495
|
return this;
|
|
428
496
|
}
|
|
429
497
|
/**
|
|
430
|
-
* Sets the withAttributes flag which will return the attributes for the entities if true
|
|
431
|
-
* @param withAttributes - The boolean value to set
|
|
432
|
-
* @returns The QueryBuilder instance
|
|
433
|
-
*
|
|
434
|
-
* @example
|
|
435
|
-
* const builder = new QueryBuilder(client)
|
|
436
|
-
* builder.withAttributes(true)
|
|
437
|
-
*/
|
|
438
|
-
withAttributes(withAttributes = true) {
|
|
439
|
-
this._withAttributes = withAttributes;
|
|
440
|
-
return this;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true
|
|
444
|
-
* @param withMetadata - The boolean value to set
|
|
445
|
-
* @returns The QueryBuilder instance
|
|
446
|
-
*
|
|
447
|
-
* @example
|
|
448
|
-
* const builder = new QueryBuilder(client)
|
|
449
|
-
* builder.withMetadata(true)
|
|
450
|
-
*/
|
|
451
|
-
withMetadata(withMetadata = true) {
|
|
452
|
-
this._withMetadata = withMetadata;
|
|
453
|
-
return this;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Sets the withPayload flag which will return the payload for the entities if true
|
|
457
|
-
* @param withPayload - The boolean value to set
|
|
458
|
-
* @returns The QueryBuilder instance
|
|
459
|
-
*
|
|
460
|
-
* @example
|
|
461
|
-
* const builder = new QueryBuilder(client)
|
|
462
|
-
* builder.withPayload(true)
|
|
463
|
-
*/
|
|
464
|
-
withPayload(withPayload = true) {
|
|
465
|
-
this._withPayload = withPayload;
|
|
466
|
-
return this;
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
498
|
* Sets the limit for the query
|
|
470
499
|
* @param limit - The number of entities to return
|
|
471
|
-
* @returns The
|
|
500
|
+
* @returns The query builder instance
|
|
472
501
|
*
|
|
473
502
|
* @example
|
|
474
|
-
* const builder =
|
|
503
|
+
* const builder = client.select()
|
|
475
504
|
* builder.limit(10)
|
|
476
505
|
*/
|
|
477
506
|
limit(limit) {
|
|
@@ -481,11 +510,11 @@ var QueryBuilder = class {
|
|
|
481
510
|
/**
|
|
482
511
|
* Sets the cursor for the query - it is advances setting which rather shouldn't be used manually but it is provided from query result if limit is used (pagination).
|
|
483
512
|
* @param cursor - The cursor to set which tells to RPC Query server where to start or continue the query.
|
|
484
|
-
* @returns The
|
|
513
|
+
* @returns The query builder instance
|
|
485
514
|
*
|
|
486
515
|
* @example
|
|
487
|
-
* const builder =
|
|
488
|
-
* builder.
|
|
516
|
+
* const builder = client.select()
|
|
517
|
+
* builder.cursor("0xABC123")
|
|
489
518
|
*/
|
|
490
519
|
cursor(cursor) {
|
|
491
520
|
this._cursor = cursor;
|
|
@@ -495,10 +524,10 @@ var QueryBuilder = class {
|
|
|
495
524
|
* Sets the validAtBlock for the query which tells at which block height the state we are intested.
|
|
496
525
|
* If not set, the latest block is used.
|
|
497
526
|
* @param validAtBlock - The block number to set
|
|
498
|
-
* @returns The
|
|
527
|
+
* @returns The query builder instance
|
|
499
528
|
*
|
|
500
529
|
* @example
|
|
501
|
-
* const builder =
|
|
530
|
+
* const builder = client.select()
|
|
502
531
|
* builder.validAtBlock(10000)
|
|
503
532
|
*/
|
|
504
533
|
validAtBlock(validAtBlock) {
|
|
@@ -509,10 +538,10 @@ var QueryBuilder = class {
|
|
|
509
538
|
* Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.
|
|
510
539
|
* Predicates can be nested using 'or' and 'and' predicates.
|
|
511
540
|
* @param predicates - The predicates to set
|
|
512
|
-
* @returns The
|
|
541
|
+
* @returns The query builder instance
|
|
513
542
|
*
|
|
514
543
|
* @example
|
|
515
|
-
* const builder =
|
|
544
|
+
* const builder = client.select()
|
|
516
545
|
* builder.where(eq("name", "John"))
|
|
517
546
|
* builder.where([eq("name", "John"), eq("age", 30)])
|
|
518
547
|
* builder.where([eq("name", "John"), or([eq("age", 30), eq("age", 31)])])
|
|
@@ -527,12 +556,12 @@ var QueryBuilder = class {
|
|
|
527
556
|
return this;
|
|
528
557
|
}
|
|
529
558
|
/**
|
|
530
|
-
* Fetches the entities from the query.
|
|
559
|
+
* Fetches the entities from the query.
|
|
531
560
|
* It will return a QueryResult instance which can be used to fetch the next and previous pages.
|
|
532
561
|
* @returns The QueryResult instance {@link QueryResult}
|
|
533
562
|
*
|
|
534
563
|
* @example
|
|
535
|
-
* const builder =
|
|
564
|
+
* const builder = client.select()
|
|
536
565
|
* const result = await builder.where(eq("name", "John")).fetch()
|
|
537
566
|
* // result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }
|
|
538
567
|
*/
|
|
@@ -545,11 +574,9 @@ var QueryBuilder = class {
|
|
|
545
574
|
createdBy: this._createdBy,
|
|
546
575
|
orderBy: this._orderBy,
|
|
547
576
|
validAtBlock: this._validAtBlock,
|
|
548
|
-
|
|
549
|
-
withMetadata: this._withMetadata,
|
|
550
|
-
withPayload: this._withPayload
|
|
577
|
+
...this.selectionParams()
|
|
551
578
|
});
|
|
552
|
-
const entities = await Promise.all(queryResult.data.map((entity) =>
|
|
579
|
+
const entities = await Promise.all(queryResult.data.map((entity) => this.projectEntity(entity)));
|
|
553
580
|
this.cursor(queryResult.cursor);
|
|
554
581
|
this.validAtBlock(BigInt(queryResult.blockNumber ?? 0));
|
|
555
582
|
return new QueryResult(entities, this, this._cursor, this._limit, this._validAtBlock);
|
|
@@ -559,7 +586,7 @@ var QueryBuilder = class {
|
|
|
559
586
|
* @returns The number of entities
|
|
560
587
|
*
|
|
561
588
|
* @example
|
|
562
|
-
* const builder =
|
|
589
|
+
* const builder = client.select()
|
|
563
590
|
* const result = await builder.where(eq("name", "John")).count()
|
|
564
591
|
* // result = 10
|
|
565
592
|
*/
|
|
@@ -578,14 +605,134 @@ var QueryBuilder = class {
|
|
|
578
605
|
})).data.length ?? 0;
|
|
579
606
|
}
|
|
580
607
|
};
|
|
608
|
+
/**
|
|
609
|
+
* QueryBuilder is a helper class to build queries to the Arkiv DBChains.
|
|
610
|
+
* It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
|
|
611
|
+
*
|
|
612
|
+
* By default the result includes only the entity `key`. Additional data is opt-in through
|
|
613
|
+
* `withAttributes()`, `withMetadata()` and `withPayload()`.
|
|
614
|
+
*
|
|
615
|
+
* @deprecated Use {@link SelectQueryBuilder} via `client.select()` instead. Declaring the
|
|
616
|
+
* selection up front avoids the common mistake of forgetting to opt in to data and getting back
|
|
617
|
+
* entities with only their `key` populated. This class remains for backwards compatibility and
|
|
618
|
+
* will be removed in a future release.
|
|
619
|
+
*
|
|
620
|
+
* @param client - The Arkiv client
|
|
621
|
+
* @returns The QueryBuilder instance {@link QueryBuilder}
|
|
622
|
+
*/
|
|
623
|
+
var QueryBuilder = class extends BaseQueryBuilder {
|
|
624
|
+
_withAttributes;
|
|
625
|
+
_withMetadata;
|
|
626
|
+
_withPayload;
|
|
627
|
+
/**
|
|
628
|
+
* Sets the withAttributes flag which will return the attributes for the entities if true
|
|
629
|
+
* @param withAttributes - The boolean value to set
|
|
630
|
+
* @returns The QueryBuilder instance
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* const builder = client.buildQuery()
|
|
634
|
+
* builder.withAttributes(true)
|
|
635
|
+
*/
|
|
636
|
+
withAttributes(withAttributes = true) {
|
|
637
|
+
this._withAttributes = withAttributes;
|
|
638
|
+
return this;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true
|
|
642
|
+
* @param withMetadata - The boolean value to set
|
|
643
|
+
* @returns The QueryBuilder instance
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* const builder = client.buildQuery()
|
|
647
|
+
* builder.withMetadata(true)
|
|
648
|
+
*/
|
|
649
|
+
withMetadata(withMetadata = true) {
|
|
650
|
+
this._withMetadata = withMetadata;
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Sets the withPayload flag which will return the payload for the entities if true
|
|
655
|
+
* @param withPayload - The boolean value to set
|
|
656
|
+
* @returns The QueryBuilder instance
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* const builder = client.buildQuery()
|
|
660
|
+
* builder.withPayload(true)
|
|
661
|
+
*/
|
|
662
|
+
withPayload(withPayload = true) {
|
|
663
|
+
this._withPayload = withPayload;
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
selectionParams() {
|
|
667
|
+
return {
|
|
668
|
+
withAttributes: this._withAttributes,
|
|
669
|
+
withMetadata: this._withMetadata,
|
|
670
|
+
withPayload: this._withPayload
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
projectEntity(rpcEntity) {
|
|
674
|
+
return entityFromRpcResult(rpcEntity);
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* SelectQueryBuilder is the recommended query builder. It requires the selection to be declared
|
|
679
|
+
* up front, so results always contain exactly the data you asked for — and the type of each
|
|
680
|
+
* returned entity is narrowed to exactly the selected fields.
|
|
681
|
+
*
|
|
682
|
+
* The selection is fixed at construction time and is flat — each field maps to an entity field.
|
|
683
|
+
* Create one via `client.select(...)` rather than constructing it directly, so the result type is
|
|
684
|
+
* inferred from the selection.
|
|
685
|
+
*
|
|
686
|
+
* @typeParam TEntity - The projected entity shape, inferred from the selection by `client.select()`.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* // everything
|
|
690
|
+
* await client.select().where(eq("name", "John")).fetch()
|
|
691
|
+
* await client.select("*").where(eq("name", "John")).fetch()
|
|
692
|
+
* // specific fields
|
|
693
|
+
* await client.select({ owner: true, attributes: true }).fetch()
|
|
694
|
+
* // a single field — result is typed (flat) { owner: Hex }
|
|
695
|
+
* await client.select({ owner: true }).fetch()
|
|
696
|
+
*/
|
|
697
|
+
var SelectQueryBuilder = class extends BaseQueryBuilder {
|
|
698
|
+
_includeData;
|
|
699
|
+
constructor(client, selection) {
|
|
700
|
+
super(client);
|
|
701
|
+
this._includeData = selectionToIncludeData(selection);
|
|
702
|
+
}
|
|
703
|
+
selectionParams() {
|
|
704
|
+
return { includeData: this._includeData };
|
|
705
|
+
}
|
|
706
|
+
async projectEntity(rpcEntity) {
|
|
707
|
+
return await entityFromRpcResult(rpcEntity);
|
|
708
|
+
}
|
|
709
|
+
};
|
|
581
710
|
|
|
582
711
|
//#endregion
|
|
712
|
+
Object.defineProperty(exports, 'BaseQueryBuilder', {
|
|
713
|
+
enumerable: true,
|
|
714
|
+
get: function () {
|
|
715
|
+
return BaseQueryBuilder;
|
|
716
|
+
}
|
|
717
|
+
});
|
|
583
718
|
Object.defineProperty(exports, 'EntityMutationError', {
|
|
584
719
|
enumerable: true,
|
|
585
720
|
get: function () {
|
|
586
721
|
return EntityMutationError;
|
|
587
722
|
}
|
|
588
723
|
});
|
|
724
|
+
Object.defineProperty(exports, 'InvalidAttributeError', {
|
|
725
|
+
enumerable: true,
|
|
726
|
+
get: function () {
|
|
727
|
+
return InvalidAttributeError;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
Object.defineProperty(exports, 'InvalidExpirationError', {
|
|
731
|
+
enumerable: true,
|
|
732
|
+
get: function () {
|
|
733
|
+
return InvalidExpirationError;
|
|
734
|
+
}
|
|
735
|
+
});
|
|
589
736
|
Object.defineProperty(exports, 'NoCursorOrLimitError', {
|
|
590
737
|
enumerable: true,
|
|
591
738
|
get: function () {
|
|
@@ -616,6 +763,12 @@ Object.defineProperty(exports, 'QueryResult', {
|
|
|
616
763
|
return QueryResult;
|
|
617
764
|
}
|
|
618
765
|
});
|
|
766
|
+
Object.defineProperty(exports, 'SelectQueryBuilder', {
|
|
767
|
+
enumerable: true,
|
|
768
|
+
get: function () {
|
|
769
|
+
return SelectQueryBuilder;
|
|
770
|
+
}
|
|
771
|
+
});
|
|
619
772
|
Object.defineProperty(exports, 'asc', {
|
|
620
773
|
enumerable: true,
|
|
621
774
|
get: function () {
|
|
@@ -639,4 +792,10 @@ Object.defineProperty(exports, 'getLogger', {
|
|
|
639
792
|
get: function () {
|
|
640
793
|
return getLogger;
|
|
641
794
|
}
|
|
795
|
+
});
|
|
796
|
+
Object.defineProperty(exports, 'selectionToIncludeData', {
|
|
797
|
+
enumerable: true,
|
|
798
|
+
get: function () {
|
|
799
|
+
return selectionToIncludeData;
|
|
800
|
+
}
|
|
642
801
|
});
|