@arkiv-network/sdk 0.3.2-dev.0 → 0.3.2-dev.2
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 +1 -0
- 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/{entity-o4fwHXKf.d.ts → entity-0JJeFAgO.d.cts} +7 -5
- package/dist/entity-0JJeFAgO.d.cts.map +1 -0
- package/dist/{entity-OY78HYxA.d.cts → entity-BG8YycYJ.d.ts} +7 -5
- package/dist/entity-BG8YycYJ.d.ts.map +1 -0
- package/dist/index.cjs +11 -34
- package/dist/index.d.cts +40 -38
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +40 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -24
- package/dist/index.js.map +1 -1
- package/dist/query/index.cjs +3 -1
- package/dist/query/index.d.cts +3 -3
- package/dist/query/index.d.ts +3 -3
- package/dist/query/index.js +2 -2
- package/dist/{queryBuilder-CboWSREN.d.ts → queryBuilder-BNhnpewa.d.ts} +56 -3
- package/dist/queryBuilder-BNhnpewa.d.ts.map +1 -0
- package/dist/{queryBuilder-BueP5de6.js → queryBuilder-CAQ7TDMZ.js} +60 -4
- package/dist/queryBuilder-CAQ7TDMZ.js.map +1 -0
- package/dist/{queryBuilder-n9ocnT4P.cjs → queryBuilder-DEkfSiCF.cjs} +70 -2
- package/dist/{queryBuilder-Bm1zGqKA.d.cts → queryBuilder-Dc_ii8LH.d.cts} +56 -3
- package/dist/queryBuilder-Dc_ii8LH.d.cts.map +1 -0
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types-CBTc19th.cjs +0 -0
- package/dist/types-Cv8NMtbo.js +0 -0
- package/dist/utils/index.d.cts.map +1 -1
- package/package.json +1 -1
- package/src/clients/createPublicClient.ts +2 -2
- package/src/clients/createWalletClient.ts +2 -2
- package/src/clients/decorators/arkivPublic.ts +2 -2
- package/src/clients/decorators/arkivWallet.ts +12 -11
- package/src/index.ts +3 -34
- package/src/query/engine.test.ts +69 -0
- package/src/query/engine.ts +8 -3
- package/src/query/queryBuilder.test.ts +76 -1
- package/src/query/queryBuilder.ts +103 -0
- package/src/types/rpcSchema.ts +7 -5
- package/dist/entity-OY78HYxA.d.cts.map +0 -1
- package/dist/entity-o4fwHXKf.d.ts.map +0 -1
- package/dist/queryBuilder-Bm1zGqKA.d.cts.map +0 -1
- package/dist/queryBuilder-BueP5de6.js.map +0 -1
- package/dist/queryBuilder-CboWSREN.d.ts.map +0 -1
|
@@ -82,8 +82,8 @@ function processPredicates(predicates) {
|
|
|
82
82
|
}).join(" && ");
|
|
83
83
|
}
|
|
84
84
|
async function processQuery(client, queryParams) {
|
|
85
|
-
const { predicates, limit, cursor, ownedBy, validAtBlock, withAttributes, withMetadata, withPayload } = queryParams;
|
|
86
|
-
console.debug(`Processing query with params: predicates: ${predicates}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`);
|
|
85
|
+
const { predicates, limit, cursor, ownedBy, orderBy, validAtBlock, withAttributes, withMetadata, withPayload } = queryParams;
|
|
86
|
+
console.debug(`Processing query with params: predicates: ${JSON.stringify(predicates)}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, orderBy: ${JSON.stringify(orderBy)}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`);
|
|
87
87
|
let query = processPredicates(predicates);
|
|
88
88
|
if (ownedBy) query += ` && $owner=${ownedBy}`;
|
|
89
89
|
query = query.trim();
|
|
@@ -99,9 +99,11 @@ async function processQuery(client, queryParams) {
|
|
|
99
99
|
if (validAtBlock !== void 0) queryOptions.atBlock = Number(validAtBlock);
|
|
100
100
|
if (limit !== void 0) queryOptions.resultsPerPage = limit;
|
|
101
101
|
if (cursor !== void 0) queryOptions.cursor = cursor;
|
|
102
|
+
if (orderBy !== void 0) queryOptions.orderBy = orderBy;
|
|
102
103
|
console.debug(`Built query to send: ${query}, queryOptions: ${JSON.stringify({
|
|
103
104
|
includeData: queryOptions.includeData,
|
|
104
105
|
atBlock: queryOptions.atBlock?.toString(),
|
|
106
|
+
orderBy: queryOptions.orderBy,
|
|
105
107
|
resultsPerPage: queryOptions.resultsPerPage,
|
|
106
108
|
cursor: queryOptions.cursor
|
|
107
109
|
})}`);
|
|
@@ -155,6 +157,38 @@ var QueryResult = class {
|
|
|
155
157
|
//#endregion
|
|
156
158
|
//#region src/query/queryBuilder.ts
|
|
157
159
|
/**
|
|
160
|
+
* Helper function to create an ascending order by attribute
|
|
161
|
+
* @param attributeName - The name of the attribute to order by
|
|
162
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
163
|
+
* @returns The OrderByAttribute instance
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* const ascAttribute = asc("name", "string")
|
|
167
|
+
*/
|
|
168
|
+
function asc(attributeName, attributeType) {
|
|
169
|
+
return {
|
|
170
|
+
name: attributeName,
|
|
171
|
+
type: attributeType,
|
|
172
|
+
order: "asc"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Helper function to create a descending order by attribute
|
|
177
|
+
* @param attributeName - The name of the attribute to order by
|
|
178
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
179
|
+
* @returns The OrderByAttribute instance
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const descAttribute = desc("name", "string")
|
|
183
|
+
*/
|
|
184
|
+
function desc(attributeName, attributeType) {
|
|
185
|
+
return {
|
|
186
|
+
name: attributeName,
|
|
187
|
+
type: attributeType,
|
|
188
|
+
order: "desc"
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
158
192
|
* QueryBuilder is a helper class to build queries to the Arkiv DBChains.
|
|
159
193
|
* It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
|
|
160
194
|
* @param client - The Arkiv client
|
|
@@ -163,6 +197,7 @@ var QueryResult = class {
|
|
|
163
197
|
var QueryBuilder = class {
|
|
164
198
|
_client;
|
|
165
199
|
_ownedBy;
|
|
200
|
+
_orderBy;
|
|
166
201
|
_validAtBlock;
|
|
167
202
|
_withAttributes;
|
|
168
203
|
_withMetadata;
|
|
@@ -187,6 +222,25 @@ var QueryBuilder = class {
|
|
|
187
222
|
this._ownedBy = ownedBy;
|
|
188
223
|
return this;
|
|
189
224
|
}
|
|
225
|
+
orderBy(attributeNameOrOrderByAttribute, attributeType, order = "asc") {
|
|
226
|
+
if (!this._orderBy) this._orderBy = [];
|
|
227
|
+
const pushOrderByAttribute = ({ name, type, order: order$1 }) => {
|
|
228
|
+
this._orderBy?.push({
|
|
229
|
+
name,
|
|
230
|
+
type: type === "number" ? "numeric" : type,
|
|
231
|
+
desc: order$1 === "desc"
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
if (typeof attributeNameOrOrderByAttribute === "string") {
|
|
235
|
+
if (!attributeType) throw new Error("attributeType is required when using positional orderBy arguments");
|
|
236
|
+
pushOrderByAttribute({
|
|
237
|
+
name: attributeNameOrOrderByAttribute,
|
|
238
|
+
type: attributeType,
|
|
239
|
+
order
|
|
240
|
+
});
|
|
241
|
+
} else pushOrderByAttribute(attributeNameOrOrderByAttribute);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
190
244
|
/**
|
|
191
245
|
* Sets the withAttributes flag which will return the attributes for the entities if true
|
|
192
246
|
* @param withAttributes - The boolean value to set
|
|
@@ -303,6 +357,7 @@ var QueryBuilder = class {
|
|
|
303
357
|
limit: this._limit,
|
|
304
358
|
cursor: this._cursor,
|
|
305
359
|
ownedBy: this._ownedBy,
|
|
360
|
+
orderBy: this._orderBy,
|
|
306
361
|
validAtBlock: this._validAtBlock,
|
|
307
362
|
withAttributes: this._withAttributes,
|
|
308
363
|
withMetadata: this._withMetadata,
|
|
@@ -328,6 +383,7 @@ var QueryBuilder = class {
|
|
|
328
383
|
limit: this._limit,
|
|
329
384
|
cursor: this._cursor,
|
|
330
385
|
ownedBy: this._ownedBy,
|
|
386
|
+
orderBy: void 0,
|
|
331
387
|
validAtBlock: this._validAtBlock,
|
|
332
388
|
withAttributes: false,
|
|
333
389
|
withMetadata: false,
|
|
@@ -373,6 +429,18 @@ Object.defineProperty(exports, 'QueryResult', {
|
|
|
373
429
|
return QueryResult;
|
|
374
430
|
}
|
|
375
431
|
});
|
|
432
|
+
Object.defineProperty(exports, 'asc', {
|
|
433
|
+
enumerable: true,
|
|
434
|
+
get: function () {
|
|
435
|
+
return asc;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
Object.defineProperty(exports, 'desc', {
|
|
439
|
+
enumerable: true,
|
|
440
|
+
get: function () {
|
|
441
|
+
return desc;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
376
444
|
Object.defineProperty(exports, 'entityFromRpcResult', {
|
|
377
445
|
enumerable: true,
|
|
378
446
|
get: function () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as ArkivClient, t as Entity } from "./entity-
|
|
1
|
+
import { g as ArkivClient, t as Entity } from "./entity-0JJeFAgO.cjs";
|
|
2
2
|
import { Hex } from "viem";
|
|
3
3
|
|
|
4
4
|
//#region src/query/predicate.d.ts
|
|
@@ -129,6 +129,31 @@ declare class QueryResult {
|
|
|
129
129
|
}
|
|
130
130
|
//#endregion
|
|
131
131
|
//#region src/query/queryBuilder.d.ts
|
|
132
|
+
type OrderByAttribute = {
|
|
133
|
+
name: string;
|
|
134
|
+
type: "string" | "number";
|
|
135
|
+
order: "asc" | "desc";
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Helper function to create an ascending order by attribute
|
|
139
|
+
* @param attributeName - The name of the attribute to order by
|
|
140
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
141
|
+
* @returns The OrderByAttribute instance
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const ascAttribute = asc("name", "string")
|
|
145
|
+
*/
|
|
146
|
+
declare function asc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute;
|
|
147
|
+
/**
|
|
148
|
+
* Helper function to create a descending order by attribute
|
|
149
|
+
* @param attributeName - The name of the attribute to order by
|
|
150
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
151
|
+
* @returns The OrderByAttribute instance
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const descAttribute = desc("name", "string")
|
|
155
|
+
*/
|
|
156
|
+
declare function desc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute;
|
|
132
157
|
/**
|
|
133
158
|
* QueryBuilder is a helper class to build queries to the Arkiv DBChains.
|
|
134
159
|
* It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
|
|
@@ -138,6 +163,7 @@ declare class QueryResult {
|
|
|
138
163
|
declare class QueryBuilder {
|
|
139
164
|
private _client;
|
|
140
165
|
private _ownedBy;
|
|
166
|
+
private _orderBy;
|
|
141
167
|
private _validAtBlock;
|
|
142
168
|
private _withAttributes;
|
|
143
169
|
private _withMetadata;
|
|
@@ -156,6 +182,33 @@ declare class QueryBuilder {
|
|
|
156
182
|
* builder.ownedBy("0x1234567890123456789012345678901234567890")
|
|
157
183
|
*/
|
|
158
184
|
ownedBy(ownedBy: Hex): this;
|
|
185
|
+
/**
|
|
186
|
+
* Sets the orderBy for the query.
|
|
187
|
+
* It can be called multiple times to order by multiple attributes.
|
|
188
|
+
* The order of the attributes is important. The first attribute is the primary order by attribute.
|
|
189
|
+
* @param attributeName - The name of the attribute to order by
|
|
190
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
191
|
+
* @param order - The order to set the order by (asc or desc)
|
|
192
|
+
* @returns The QueryBuilder instance
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* const builder = new QueryBuilder(client)
|
|
196
|
+
* builder.orderBy("name", "string", "desc")
|
|
197
|
+
*/
|
|
198
|
+
orderBy(attributeName: string, attributeType: "string" | "number", order?: "asc" | "desc"): this;
|
|
199
|
+
/**
|
|
200
|
+
* Sets the orderBy for the query.
|
|
201
|
+
* This method takes the OrderByAttribute object as an argument and is mainly
|
|
202
|
+
* used to use the helper functions asc() and desc() to create the OrderByAttribute instances.
|
|
203
|
+
* @param orderByAttribute - The OrderByAttribute instance to set
|
|
204
|
+
* @returns The QueryBuilder instance
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const builder = new QueryBuilder(client)
|
|
208
|
+
* builder.orderBy(asc("name", "string"))
|
|
209
|
+
* builder.orderBy(desc("name", "string"))
|
|
210
|
+
*/
|
|
211
|
+
orderBy(orderByAttribute: OrderByAttribute): this;
|
|
159
212
|
/**
|
|
160
213
|
* Sets the withAttributes flag which will return the attributes for the entities if true
|
|
161
214
|
* @param withAttributes - The boolean value to set
|
|
@@ -257,5 +310,5 @@ declare class QueryBuilder {
|
|
|
257
310
|
count(): Promise<1>;
|
|
258
311
|
}
|
|
259
312
|
//#endregion
|
|
260
|
-
export {
|
|
261
|
-
//# sourceMappingURL=queryBuilder-
|
|
313
|
+
export { Predicate as a, and as c, gte as d, lt as f, or as g, not as h, QueryResult as i, eq as l, neq as m, asc as n, PredicateContainerType as o, lte as p, desc as r, PredicateType as s, QueryBuilder as t, gt as u };
|
|
314
|
+
//# sourceMappingURL=queryBuilder-Dc_ii8LH.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryBuilder-Dc_ii8LH.d.cts","names":[],"sources":["../src/query/predicate.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":[],"mappings":";;;;KAAY,aAAA;KACA,sBAAA;KAEA,SAAA;QAEA;EALA,GAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA,GAAA,MAAA;AAEZ,CAAA,GAAY;EAEA,IAAA,EAKA,sBALA;EAKA,UAAA,EACM,SADN,EAAA;CACM;;AAclB;AAeA;AAcA;AAcA;AAcA;AAcA;AAcA;AAcA;AAaA;;iBAhHgB,EAAA,aAAe,cAAc;;ACrB7C;;;;;;;;;;ACIK,iBFgCW,GAAA,CEhCK,UAAA,EFgCW,SEhCX,EAAA,CAAA,EFgCyB,SEhCzB;AAerB;AAiBA;AAaA;;;;;;;;AAmPa,iBFlPG,EAAA,CEkPH,GAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,GAAA,MAAA,CAAA,EFlP4C,SEkP5C;;;;;;;;;;;iBFpOG,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;;iBAc1C,EAAA,uCAAyC;;;;;;;;;;;iBAczC,GAAA,uCAA0C;;;;;;;;;;iBAa1C,GAAA,eAAkB;;;cCrIrB,WAAA;YACD;EDLA,QAAA,eAAa;EACb,QAAA,OAAA;EAEA,QAAA,MAAS;EAET,QAAA,aAAA;EAKA,QAAA,aAAA;EACM,IAAA,YAAA,CAAA,CAAA,ECEI,YDFJ;EAAS,IAAA,MAAA,CAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EAcX,WAAE,CAAA,QAAa,ECHjB,MDG+B,EAAA,EAAA,YAAS,ECFpC,YDEoC,EAAA,MAAA,EAAA,MAAA,GAAA,SAAA,EAAA,KAAA,EAAA,MAAA,GAAA,SAAA,EAAA,YAAA,EAAA,MAAA,GAAA,SAAA;EAetC,IAAA,CAAA,CAAG,ECJP,ODIO,CAAA,IAAa,CAAA;EAchB,WAAE,CAAA,CAAA,EAAA,OAAuC;AAczD;;;AApEA,KEQK,gBAAA,GFRoB;EACb,IAAA,EAAA,MAAA;EAEA,IAAA,EAAA,QAAS,GAAA,QAAA;EAET,KAAA,EAAA,KAAA,GAAA,MAAA;CAKA;;;AAeZ;AAeA;AAcA;AAcA;AAcA;AAcA;AAcA;AAcgB,iBErGA,GAAA,CFqG0C,aAAS,EAAA,MAAA,EAAA,aAAA,EAAA,QAAA,GAAA,QAAA,CAAA,EErGa,gBFqGb;AAanE;;;;ACrIA;;;;;AAgCY,iBCII,IAAA,CDJJ,aAAA,EAAA,MAAA,EAAA,aAAA,EAAA,QAAA,GAAA,QAAA,CAAA,ECIqE,gBDJrE;;;;;AC9B+B;AAiB3C;AAiBgB,cAaH,YAAA,CAboE;EAapE,QAAA,OAAY;EAYH,QAAA,QAAA;EAcH,QAAA,QAAA;EA+BS,QAAA,aAAA;EAuIR,QAAA,eAAA;EAAc,QAAA,aAAA;EAmBrB,QAAA,YAAA;EAAA,QAAA,MAAA;EAgCA,QAAA,OAAA;EAAA,QAAA,WAAA;sBAvOS;;;;;;;;;;mBAcH;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA+BS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAuIR,cAAc;;;;;;;;;;;WAmBrB,QAAA;;;;;;;;;;WAgCA"}
|
package/dist/types/index.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('../types-CBTc19th.cjs');
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-
|
|
1
|
+
import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-0JJeFAgO.cjs";
|
|
2
2
|
export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, RpcEntity, RpcIncludeData, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-
|
|
1
|
+
import { _ as ArkivRpcSchema, a as MutateEntitiesReturnType, b as RpcQueryOptions, c as ExtendEntityParameters, d as DeleteEntityReturnType, f as CreateEntityParameters, h as ChangeOwnershipReturnType, i as MutateEntitiesParameters, l as ExtendEntityReturnType, m as ChangeOwnershipParameters, n as TxParams, o as UpdateEntityParameters, p as CreateEntityReturnType, r as Attribute, s as UpdateEntityReturnType, t as Entity, u as DeleteEntityParameters, v as RpcEntity, x as MimeType, y as RpcIncludeData } from "../entity-BG8YycYJ.js";
|
|
2
2
|
export { ArkivRpcSchema, Attribute, ChangeOwnershipParameters, ChangeOwnershipReturnType, CreateEntityParameters, CreateEntityReturnType, DeleteEntityParameters, DeleteEntityReturnType, Entity, ExtendEntityParameters, ExtendEntityReturnType, MimeType, MutateEntitiesParameters, MutateEntitiesReturnType, RpcEntity, RpcIncludeData, RpcQueryOptions, TxParams, UpdateEntityParameters, UpdateEntityReturnType };
|
package/dist/types/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types-Cv8NMtbo.js";
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/expirationTime.ts","../../src/utils/payload.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;EAAA,SAAA,EAAA,CAAA,KAUZ,EAAA,MAAA,EAAA,GADkB,MAAI;;;;ECTP,SAAA,EAAA,CAAA,KAAa,EAAA,MAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/expirationTime.ts","../../src/utils/payload.ts"],"sourcesContent":[],"mappings":";;;cAEa;;;EAAA,SAAA,EAAA,CAAA,KAUZ,EAAA,MAAA,EAAA,GADkB,MAAI;;;;ECTP,SAAA,EAAA,CAAA,KAAa,EAAA,MAAA,EAAA,GAAgB,MAAA;EAI7B,UAAA,EAAA,CAAA,MAAe,EAAA,MAAA,EAAA,GAAgB,MAAA;mBDK5B;;;;iBCTH,aAAA,gBAA6B;iBAI7B,eAAA,gBAA+B"}
|
package/package.json
CHANGED
|
@@ -25,9 +25,9 @@ export type PublicArkivClient<
|
|
|
25
25
|
/**
|
|
26
26
|
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
|
27
27
|
*
|
|
28
|
-
* - Docs: https://docs.
|
|
28
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/clients/public
|
|
29
29
|
*
|
|
30
|
-
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.
|
|
30
|
+
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.arkiv.network/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
|
|
31
31
|
*
|
|
32
32
|
* @param config - {@link PublicClientConfig}
|
|
33
33
|
* @returns A Arkiv Public Client. {@link PublicArkivClient}
|
|
@@ -25,9 +25,9 @@ export type WalletArkivClient<
|
|
|
25
25
|
/**
|
|
26
26
|
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
|
27
27
|
*
|
|
28
|
-
* - Docs: https://docs.
|
|
28
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/clients/public
|
|
29
29
|
*
|
|
30
|
-
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.
|
|
30
|
+
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Kaolin JSON-RPC API](https://kaolin.holesky.arkiv.network/rpc) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
|
|
31
31
|
*
|
|
32
32
|
* @param config - {@link PublicClientConfig}
|
|
33
33
|
* @returns A Arkiv Public Client. {@link PublicArkivClient}
|
|
@@ -34,7 +34,7 @@ export type PublicArkivActions<
|
|
|
34
34
|
/**
|
|
35
35
|
* Returns the entity with the given key.
|
|
36
36
|
*
|
|
37
|
-
* - Docs: https://docs.
|
|
37
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
|
|
38
38
|
*
|
|
39
39
|
* @param args - {entityKey}
|
|
40
40
|
* @returns The entity with the given key. {@link Entity}
|
|
@@ -59,7 +59,7 @@ export type PublicArkivActions<
|
|
|
59
59
|
* Returns a QueryBuilder instance for building and executing queries.
|
|
60
60
|
* The QueryBuilder object follows the Builder pattern, allowing you to chain methods to build a query and then execute it.
|
|
61
61
|
*
|
|
62
|
-
* - Docs: https://docs.
|
|
62
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/public/query
|
|
63
63
|
*
|
|
64
64
|
* @returns A QueryBuilder instance for building and executing queries. {@link QueryBuilder}
|
|
65
65
|
*
|
|
@@ -49,7 +49,8 @@ export type WalletArkivActions<
|
|
|
49
49
|
/**
|
|
50
50
|
* Returns the entity with the given key.
|
|
51
51
|
*
|
|
52
|
-
* - Docs: https://docs.
|
|
52
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/public/getEntity
|
|
53
|
+
* - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
|
|
53
54
|
*
|
|
54
55
|
* @param args - {entityKey}
|
|
55
56
|
* @returns The entity with the given key. {@link Entity}
|
|
@@ -82,8 +83,8 @@ export type WalletArkivActions<
|
|
|
82
83
|
/**
|
|
83
84
|
* Updates the entity with the given key.
|
|
84
85
|
*
|
|
85
|
-
* - Docs: https://docs.
|
|
86
|
-
* - JSON-RPC Methods: [`
|
|
86
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/updateEntity
|
|
87
|
+
* - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
|
|
87
88
|
*
|
|
88
89
|
* @param args - {entityKey, data}
|
|
89
90
|
* @returns The entity with the given key. {@link Entity}
|
|
@@ -105,8 +106,8 @@ export type WalletArkivActions<
|
|
|
105
106
|
/**
|
|
106
107
|
* Deletes the entity with the given key.
|
|
107
108
|
*
|
|
108
|
-
* - Docs: https://docs.
|
|
109
|
-
* - JSON-RPC Methods: [`
|
|
109
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/deleteEntity
|
|
110
|
+
* - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
|
|
110
111
|
*
|
|
111
112
|
* @param args - {entityKey}
|
|
112
113
|
* @returns The entity with the given key. {@link Entity}
|
|
@@ -135,8 +136,8 @@ export type WalletArkivActions<
|
|
|
135
136
|
/**
|
|
136
137
|
* Extends the entity with the given key.
|
|
137
138
|
*
|
|
138
|
-
* - Docs: https://docs.
|
|
139
|
-
* - JSON-RPC Methods: [`
|
|
139
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/extendEntity
|
|
140
|
+
* - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
|
|
140
141
|
*
|
|
141
142
|
* @param args - {entityKey, data}
|
|
142
143
|
* @returns The entity with the given key. {@link Entity}
|
|
@@ -167,8 +168,8 @@ export type WalletArkivActions<
|
|
|
167
168
|
/**
|
|
168
169
|
* Changes the ownership of the entity with the given address.
|
|
169
170
|
*
|
|
170
|
-
* - Docs: https://docs.
|
|
171
|
-
* - JSON-RPC Methods: [`
|
|
171
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/changeOwnership
|
|
172
|
+
* - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
|
|
172
173
|
*
|
|
173
174
|
* @param args - {entityKey, newOwner}
|
|
174
175
|
* @returns The entity with the given address. {@link Entity}
|
|
@@ -181,8 +182,8 @@ export type WalletArkivActions<
|
|
|
181
182
|
/**
|
|
182
183
|
* Mutates the entities with the given keys.
|
|
183
184
|
*
|
|
184
|
-
* - Docs: https://docs.
|
|
185
|
-
* - JSON-RPC Methods: [`golembase_mutateEntities`](https://docs.
|
|
185
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/mutateEntities
|
|
186
|
+
* - JSON-RPC Methods: [`golembase_mutateEntities`](https://docs.arkiv.network/dev/json-rpc-api/#golembase_mutateEntities)
|
|
186
187
|
*
|
|
187
188
|
* @param args - {data}
|
|
188
189
|
* @returns The entity with the given key. {@link Entity}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
// Re-export
|
|
2
|
-
export
|
|
3
|
-
Account,
|
|
4
|
-
Address,
|
|
5
|
-
Chain,
|
|
6
|
-
Hex,
|
|
7
|
-
PublicClientConfig,
|
|
8
|
-
RpcSchema,
|
|
9
|
-
Transport,
|
|
10
|
-
} from "viem"
|
|
11
|
-
|
|
12
|
-
export { http, toBytes, toHex, toRlp, webSocket } from "viem"
|
|
1
|
+
// Re-export all viem stuff
|
|
2
|
+
export * from "viem"
|
|
13
3
|
|
|
14
4
|
// export main arkiv stuff
|
|
15
5
|
export type { ArkivClient } from "./clients/baseClient"
|
|
@@ -19,25 +9,4 @@ export type { WalletArkivClient } from "./clients/createWalletClient"
|
|
|
19
9
|
export { createWalletClient } from "./clients/createWalletClient"
|
|
20
10
|
|
|
21
11
|
// re-export arkiv types in main index file
|
|
22
|
-
export
|
|
23
|
-
ArkivRpcSchema,
|
|
24
|
-
Attribute,
|
|
25
|
-
ChangeOwnershipParameters,
|
|
26
|
-
ChangeOwnershipReturnType,
|
|
27
|
-
CreateEntityParameters,
|
|
28
|
-
CreateEntityReturnType,
|
|
29
|
-
DeleteEntityParameters,
|
|
30
|
-
DeleteEntityReturnType,
|
|
31
|
-
Entity,
|
|
32
|
-
ExtendEntityParameters,
|
|
33
|
-
ExtendEntityReturnType,
|
|
34
|
-
MimeType,
|
|
35
|
-
MutateEntitiesParameters,
|
|
36
|
-
MutateEntitiesReturnType,
|
|
37
|
-
RpcEntity,
|
|
38
|
-
RpcIncludeData,
|
|
39
|
-
RpcQueryOptions,
|
|
40
|
-
TxParams,
|
|
41
|
-
UpdateEntityParameters,
|
|
42
|
-
UpdateEntityReturnType,
|
|
43
|
-
} from "./types"
|
|
12
|
+
export * from "./types"
|
package/src/query/engine.test.ts
CHANGED
|
@@ -15,6 +15,7 @@ describe("processQuery tests", () => {
|
|
|
15
15
|
limit: undefined,
|
|
16
16
|
cursor: undefined,
|
|
17
17
|
ownedBy: undefined,
|
|
18
|
+
orderBy: undefined,
|
|
18
19
|
validAtBlock: undefined,
|
|
19
20
|
withAttributes: undefined,
|
|
20
21
|
withMetadata: undefined,
|
|
@@ -53,6 +54,7 @@ describe("processQuery tests", () => {
|
|
|
53
54
|
limit: undefined,
|
|
54
55
|
cursor: undefined,
|
|
55
56
|
ownedBy: undefined,
|
|
57
|
+
orderBy: undefined,
|
|
56
58
|
validAtBlock: undefined,
|
|
57
59
|
withAttributes: undefined,
|
|
58
60
|
withMetadata: undefined,
|
|
@@ -92,6 +94,7 @@ describe("processQuery tests", () => {
|
|
|
92
94
|
limit: undefined,
|
|
93
95
|
cursor: undefined,
|
|
94
96
|
ownedBy: undefined,
|
|
97
|
+
orderBy: undefined,
|
|
95
98
|
validAtBlock: undefined,
|
|
96
99
|
withAttributes: undefined,
|
|
97
100
|
withMetadata: undefined,
|
|
@@ -131,6 +134,7 @@ describe("processQuery tests", () => {
|
|
|
131
134
|
limit: undefined,
|
|
132
135
|
cursor: undefined,
|
|
133
136
|
ownedBy: undefined,
|
|
137
|
+
orderBy: undefined,
|
|
134
138
|
validAtBlock: undefined,
|
|
135
139
|
withAttributes: undefined,
|
|
136
140
|
withMetadata: undefined,
|
|
@@ -176,6 +180,7 @@ describe("processQuery tests", () => {
|
|
|
176
180
|
limit: undefined,
|
|
177
181
|
cursor: undefined,
|
|
178
182
|
ownedBy: undefined,
|
|
183
|
+
orderBy: undefined,
|
|
179
184
|
validAtBlock: undefined,
|
|
180
185
|
withAttributes: undefined,
|
|
181
186
|
withMetadata: undefined,
|
|
@@ -203,6 +208,7 @@ describe("processQuery tests", () => {
|
|
|
203
208
|
const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
|
|
204
209
|
await processQuery(client, {
|
|
205
210
|
predicates,
|
|
211
|
+
orderBy: undefined,
|
|
206
212
|
limit: undefined,
|
|
207
213
|
cursor: undefined,
|
|
208
214
|
ownedBy: "0x123",
|
|
@@ -232,6 +238,7 @@ describe("processQuery tests", () => {
|
|
|
232
238
|
predicates,
|
|
233
239
|
limit: undefined,
|
|
234
240
|
cursor: undefined,
|
|
241
|
+
orderBy: undefined,
|
|
235
242
|
validAtBlock: undefined,
|
|
236
243
|
withAttributes: undefined,
|
|
237
244
|
withMetadata: undefined,
|
|
@@ -256,12 +263,74 @@ describe("processQuery tests", () => {
|
|
|
256
263
|
})
|
|
257
264
|
})
|
|
258
265
|
|
|
266
|
+
it("should process simple predicates with orderBy", async () => {
|
|
267
|
+
const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
|
|
268
|
+
await processQuery(client, {
|
|
269
|
+
predicates,
|
|
270
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
271
|
+
limit: undefined,
|
|
272
|
+
cursor: undefined,
|
|
273
|
+
ownedBy: undefined,
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
expect(client.request).lastCalledWith({
|
|
277
|
+
method: "arkiv_query",
|
|
278
|
+
params: [
|
|
279
|
+
`key = "value"`,
|
|
280
|
+
{
|
|
281
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
282
|
+
includeData: {
|
|
283
|
+
key: true,
|
|
284
|
+
attributes: false,
|
|
285
|
+
contentType: false,
|
|
286
|
+
payload: false,
|
|
287
|
+
expiration: false,
|
|
288
|
+
owner: false,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
it("should process only orderBy", async () => {
|
|
296
|
+
const predicates = [] as Predicate[]
|
|
297
|
+
await processQuery(client, {
|
|
298
|
+
predicates,
|
|
299
|
+
limit: undefined,
|
|
300
|
+
cursor: undefined,
|
|
301
|
+
ownedBy: undefined,
|
|
302
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
303
|
+
validAtBlock: undefined,
|
|
304
|
+
withAttributes: undefined,
|
|
305
|
+
withMetadata: undefined,
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
expect(client.request).lastCalledWith({
|
|
309
|
+
method: "arkiv_query",
|
|
310
|
+
params: [
|
|
311
|
+
"",
|
|
312
|
+
{
|
|
313
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
314
|
+
includeData: {
|
|
315
|
+
key: true,
|
|
316
|
+
attributes: false,
|
|
317
|
+
contentType: false,
|
|
318
|
+
payload: false,
|
|
319
|
+
expiration: false,
|
|
320
|
+
owner: false,
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
|
|
259
327
|
it("should process simple predicate with validAtBlock and paging", async () => {
|
|
260
328
|
const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
|
|
261
329
|
await processQuery(client, {
|
|
262
330
|
predicates,
|
|
263
331
|
limit: 10,
|
|
264
332
|
cursor: undefined,
|
|
333
|
+
orderBy: undefined,
|
|
265
334
|
validAtBlock: 123n,
|
|
266
335
|
ownedBy: "0x123",
|
|
267
336
|
})
|
package/src/query/engine.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hex } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../clients/baseClient"
|
|
3
|
-
import type { RpcQueryOptions } from "../types/rpcSchema"
|
|
3
|
+
import type { RpcOrderByAttribute, RpcQueryOptions } from "../types/rpcSchema"
|
|
4
4
|
import type { Predicate } from "./predicate"
|
|
5
5
|
|
|
6
6
|
function processPredicates(predicates: Predicate[]): string {
|
|
@@ -45,6 +45,7 @@ export async function processQuery(
|
|
|
45
45
|
limit: number | undefined
|
|
46
46
|
cursor: string | undefined
|
|
47
47
|
ownedBy: Hex | undefined
|
|
48
|
+
orderBy: RpcOrderByAttribute[] | undefined
|
|
48
49
|
validAtBlock?: bigint | undefined
|
|
49
50
|
withAttributes?: boolean | undefined
|
|
50
51
|
withMetadata?: boolean | undefined
|
|
@@ -56,6 +57,7 @@ export async function processQuery(
|
|
|
56
57
|
limit,
|
|
57
58
|
cursor,
|
|
58
59
|
ownedBy,
|
|
60
|
+
orderBy,
|
|
59
61
|
validAtBlock,
|
|
60
62
|
withAttributes,
|
|
61
63
|
withMetadata,
|
|
@@ -63,7 +65,7 @@ export async function processQuery(
|
|
|
63
65
|
} = queryParams
|
|
64
66
|
|
|
65
67
|
console.debug(
|
|
66
|
-
`Processing query with params: predicates: ${predicates}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`,
|
|
68
|
+
`Processing query with params: predicates: ${JSON.stringify(predicates)}, cursor: ${cursor}, limit: ${limit}, ownedBy: ${ownedBy}, orderBy: ${JSON.stringify(orderBy)}, validAtBlock: ${validAtBlock}, withAttributes: ${withAttributes}, withMetadata: ${withMetadata}, withPayload: ${withPayload}`,
|
|
67
69
|
)
|
|
68
70
|
|
|
69
71
|
let query = processPredicates(predicates)
|
|
@@ -97,9 +99,12 @@ export async function processQuery(
|
|
|
97
99
|
if (cursor !== undefined) {
|
|
98
100
|
queryOptions.cursor = cursor
|
|
99
101
|
}
|
|
102
|
+
if (orderBy !== undefined) {
|
|
103
|
+
queryOptions.orderBy = orderBy
|
|
104
|
+
}
|
|
100
105
|
|
|
101
106
|
console.debug(
|
|
102
|
-
`Built query to send: ${query}, queryOptions: ${JSON.stringify({ includeData: queryOptions.includeData, atBlock: queryOptions.atBlock?.toString(), resultsPerPage: queryOptions.resultsPerPage, cursor: queryOptions.cursor })}`,
|
|
107
|
+
`Built query to send: ${query}, queryOptions: ${JSON.stringify({ includeData: queryOptions.includeData, atBlock: queryOptions.atBlock?.toString(), orderBy: queryOptions.orderBy, resultsPerPage: queryOptions.resultsPerPage, cursor: queryOptions.cursor })}`,
|
|
103
108
|
)
|
|
104
109
|
|
|
105
110
|
const result = await client.request({
|