@arkiv-network/sdk 0.3.2-dev.1 → 0.3.2-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 +1 -0
- package/dist/chains/index.d.ts +25 -25
- package/dist/{entity-DvQtQL8v.d.ts → entity-0JJeFAgO.d.cts} +1 -5
- package/dist/entity-0JJeFAgO.d.cts.map +1 -0
- package/dist/{entity-jTQZmEAd.d.cts → entity-BG8YycYJ.d.ts} +1 -5
- package/dist/entity-BG8YycYJ.d.ts.map +1 -0
- package/dist/index.cjs +20 -36
- 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 +36 -26
- 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-BBtwhH0G.d.ts → queryBuilder-BNhnpewa.d.ts} +44 -6
- package/dist/queryBuilder-BNhnpewa.d.ts.map +1 -0
- package/dist/{queryBuilder-D22Tamry.js → queryBuilder-CAQ7TDMZ.js} +50 -21
- package/dist/queryBuilder-CAQ7TDMZ.js.map +1 -0
- package/dist/{queryBuilder-D-bqHg3w.cjs → queryBuilder-DEkfSiCF.cjs} +60 -19
- package/dist/{queryBuilder-DkhyyeFr.d.cts → queryBuilder-Dc_ii8LH.d.cts} +44 -6
- 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/actions/public/getEntity.ts +18 -3
- 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 +4 -4
- package/src/query/queryBuilder.test.ts +44 -3
- package/src/query/queryBuilder.ts +80 -10
- package/src/types/rpcSchema.ts +0 -5
- package/dist/entity-DvQtQL8v.d.ts.map +0 -1
- package/dist/entity-jTQZmEAd.d.cts.map +0 -1
- package/dist/queryBuilder-BBtwhH0G.d.ts.map +0 -1
- package/dist/queryBuilder-D22Tamry.js.map +0 -1
- package/dist/queryBuilder-DkhyyeFr.d.cts.map +0 -1
|
@@ -157,6 +157,38 @@ var QueryResult = class {
|
|
|
157
157
|
//#endregion
|
|
158
158
|
//#region src/query/queryBuilder.ts
|
|
159
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
|
+
/**
|
|
160
192
|
* QueryBuilder is a helper class to build queries to the Arkiv DBChains.
|
|
161
193
|
* It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
|
|
162
194
|
* @param client - The Arkiv client
|
|
@@ -190,26 +222,23 @@ var QueryBuilder = class {
|
|
|
190
222
|
this._ownedBy = ownedBy;
|
|
191
223
|
return this;
|
|
192
224
|
}
|
|
193
|
-
|
|
194
|
-
* Sets the orderBy for the query.
|
|
195
|
-
* It can be called multiple times to order by multiple attributes.
|
|
196
|
-
* The order of the attributes is important. The first attribute is the primary order by attribute.
|
|
197
|
-
* @param attributeName - The name of the attribute to order by
|
|
198
|
-
* @param attributeType - The type of the attribute to order by (string or number)
|
|
199
|
-
* @param descending - The boolean value to set the order by descending
|
|
200
|
-
* @returns The QueryBuilder instance
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* const builder = new QueryBuilder(client)
|
|
204
|
-
* builder.orderBy("name", "string", true)
|
|
205
|
-
*/
|
|
206
|
-
orderBy(attributeName, attributeType, descending = void 0) {
|
|
225
|
+
orderBy(attributeNameOrOrderByAttribute, attributeType, order = "asc") {
|
|
207
226
|
if (!this._orderBy) this._orderBy = [];
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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);
|
|
213
242
|
return this;
|
|
214
243
|
}
|
|
215
244
|
/**
|
|
@@ -400,6 +429,18 @@ Object.defineProperty(exports, 'QueryResult', {
|
|
|
400
429
|
return QueryResult;
|
|
401
430
|
}
|
|
402
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
|
+
});
|
|
403
444
|
Object.defineProperty(exports, 'entityFromRpcResult', {
|
|
404
445
|
enumerable: true,
|
|
405
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.
|
|
@@ -163,14 +188,27 @@ declare class QueryBuilder {
|
|
|
163
188
|
* The order of the attributes is important. The first attribute is the primary order by attribute.
|
|
164
189
|
* @param attributeName - The name of the attribute to order by
|
|
165
190
|
* @param attributeType - The type of the attribute to order by (string or number)
|
|
166
|
-
* @param
|
|
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
|
|
167
204
|
* @returns The QueryBuilder instance
|
|
168
205
|
*
|
|
169
206
|
* @example
|
|
170
207
|
* const builder = new QueryBuilder(client)
|
|
171
|
-
* builder.orderBy("name", "string"
|
|
208
|
+
* builder.orderBy(asc("name", "string"))
|
|
209
|
+
* builder.orderBy(desc("name", "string"))
|
|
172
210
|
*/
|
|
173
|
-
orderBy(
|
|
211
|
+
orderBy(orderByAttribute: OrderByAttribute): this;
|
|
174
212
|
/**
|
|
175
213
|
* Sets the withAttributes flag which will return the attributes for the entities if true
|
|
176
214
|
* @param withAttributes - The boolean value to set
|
|
@@ -272,5 +310,5 @@ declare class QueryBuilder {
|
|
|
272
310
|
count(): Promise<1>;
|
|
273
311
|
}
|
|
274
312
|
//#endregion
|
|
275
|
-
export {
|
|
276
|
-
//# 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,EAAgB,GAAA,MAAA;EAI7B,UAAA,EAAA,CAAA,MAAe,EAAA,MAAA,EAAgB,GAAA,MAAA;mBDK5B;;;;iBCTH,aAAA,gBAA6B;iBAI7B,eAAA,gBAA+B"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { bytesToHex, type Hex, hexToBytes } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import { NoEntityFoundError } from "../../query/errors"
|
|
4
4
|
import { entityFromRpcResult } from "../../utils/entities"
|
|
5
5
|
|
|
6
6
|
export async function getEntity(client: ArkivClient, key: Hex) {
|
|
7
|
+
// Normalize the key into bytes
|
|
8
|
+
let bytes: Uint8Array
|
|
9
|
+
try {
|
|
10
|
+
bytes = hexToBytes(key)
|
|
11
|
+
} catch {
|
|
12
|
+
throw new Error(`Invalid key format: ${key}. Key must be a valid hex string.`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (bytes.length !== 32) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Invalid key length: ${bytes.length} bytes. Key must be 32 bytes (64 hex characters) long.`,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const hexKey = bytesToHex(bytes)
|
|
22
|
+
|
|
7
23
|
const result = await client.request({
|
|
8
24
|
method: "arkiv_query",
|
|
9
|
-
params: [`$key = ${
|
|
25
|
+
params: [`$key = ${hexKey}`],
|
|
10
26
|
})
|
|
11
|
-
console.debug("GetEntity result", result)
|
|
12
27
|
|
|
13
28
|
if (!result.data) {
|
|
14
29
|
throw new NoEntityFoundError()
|
|
@@ -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
|
@@ -267,7 +267,7 @@ describe("processQuery tests", () => {
|
|
|
267
267
|
const predicates = [{ type: "eq" as const, key: "key", value: "value" }]
|
|
268
268
|
await processQuery(client, {
|
|
269
269
|
predicates,
|
|
270
|
-
orderBy: [{ name: "key", type: "string",
|
|
270
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
271
271
|
limit: undefined,
|
|
272
272
|
cursor: undefined,
|
|
273
273
|
ownedBy: undefined,
|
|
@@ -278,7 +278,7 @@ describe("processQuery tests", () => {
|
|
|
278
278
|
params: [
|
|
279
279
|
`key = "value"`,
|
|
280
280
|
{
|
|
281
|
-
orderBy: [{ name: "key", type: "string",
|
|
281
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
282
282
|
includeData: {
|
|
283
283
|
key: true,
|
|
284
284
|
attributes: false,
|
|
@@ -299,7 +299,7 @@ describe("processQuery tests", () => {
|
|
|
299
299
|
limit: undefined,
|
|
300
300
|
cursor: undefined,
|
|
301
301
|
ownedBy: undefined,
|
|
302
|
-
orderBy: [{ name: "key", type: "string",
|
|
302
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
303
303
|
validAtBlock: undefined,
|
|
304
304
|
withAttributes: undefined,
|
|
305
305
|
withMetadata: undefined,
|
|
@@ -310,7 +310,7 @@ describe("processQuery tests", () => {
|
|
|
310
310
|
params: [
|
|
311
311
|
"",
|
|
312
312
|
{
|
|
313
|
-
orderBy: [{ name: "key", type: "string",
|
|
313
|
+
orderBy: [{ name: "key", type: "string", desc: true }],
|
|
314
314
|
includeData: {
|
|
315
315
|
key: true,
|
|
316
316
|
attributes: false,
|
|
@@ -4,7 +4,7 @@ import { Entity } from "../types/entity"
|
|
|
4
4
|
import * as entitiesUtils from "../utils/entities"
|
|
5
5
|
import * as engine from "./engine"
|
|
6
6
|
import { and, eq, gt, gte, neq, or } from "./predicate"
|
|
7
|
-
import { QueryBuilder } from "./queryBuilder"
|
|
7
|
+
import { asc, QueryBuilder } from "./queryBuilder"
|
|
8
8
|
|
|
9
9
|
describe("QueryBuilder", () => {
|
|
10
10
|
let mockClient: ArkivClient
|
|
@@ -177,13 +177,34 @@ describe("QueryBuilder", () => {
|
|
|
177
177
|
})
|
|
178
178
|
})
|
|
179
179
|
|
|
180
|
-
test("orderBy() sets orderBy", async () => {
|
|
180
|
+
test("orderBy() sets orderBy ascending", async () => {
|
|
181
181
|
mockProcessQuery.mockResolvedValue({
|
|
182
182
|
data: [],
|
|
183
183
|
})
|
|
184
184
|
|
|
185
185
|
const builder = new QueryBuilder(mockClient)
|
|
186
|
-
await builder.orderBy("name", "string",
|
|
186
|
+
await builder.orderBy("name", "string", "asc").fetch()
|
|
187
|
+
|
|
188
|
+
expect(mockProcessQuery).toHaveBeenCalledWith(mockClient, {
|
|
189
|
+
predicates: [],
|
|
190
|
+
limit: undefined,
|
|
191
|
+
offset: undefined,
|
|
192
|
+
ownedBy: undefined,
|
|
193
|
+
orderBy: [{ name: "name", type: "string", desc: false }],
|
|
194
|
+
validAtBlock: undefined,
|
|
195
|
+
withAttributes: undefined,
|
|
196
|
+
withMetadata: undefined,
|
|
197
|
+
withPayload: undefined,
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test("orderBy() sets orderBy descending", async () => {
|
|
202
|
+
mockProcessQuery.mockResolvedValue({
|
|
203
|
+
data: [],
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
const builder = new QueryBuilder(mockClient)
|
|
207
|
+
await builder.orderBy("name", "string", "desc").fetch()
|
|
187
208
|
|
|
188
209
|
expect(mockProcessQuery).toHaveBeenCalledWith(mockClient, {
|
|
189
210
|
predicates: [],
|
|
@@ -198,6 +219,26 @@ describe("QueryBuilder", () => {
|
|
|
198
219
|
})
|
|
199
220
|
})
|
|
200
221
|
|
|
222
|
+
test("orderBy() with helper function", async () => {
|
|
223
|
+
mockProcessQuery.mockResolvedValue({
|
|
224
|
+
data: [],
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const builder = new QueryBuilder(mockClient)
|
|
228
|
+
await builder.orderBy(asc("name", "string")).fetch()
|
|
229
|
+
|
|
230
|
+
expect(mockProcessQuery).toHaveBeenCalledWith(mockClient, {
|
|
231
|
+
predicates: [],
|
|
232
|
+
limit: undefined,
|
|
233
|
+
offset: undefined,
|
|
234
|
+
ownedBy: undefined,
|
|
235
|
+
orderBy: [{ name: "name", type: "string", desc: false }],
|
|
236
|
+
validAtBlock: undefined,
|
|
237
|
+
withAttributes: undefined,
|
|
238
|
+
withMetadata: undefined,
|
|
239
|
+
withPayload: undefined,
|
|
240
|
+
})
|
|
241
|
+
})
|
|
201
242
|
test("limit() sets limit", async () => {
|
|
202
243
|
mockProcessQuery.mockResolvedValue({
|
|
203
244
|
data: [],
|
|
@@ -6,6 +6,45 @@ import { processQuery } from "./engine"
|
|
|
6
6
|
import type { Predicate } from "./predicate"
|
|
7
7
|
import { QueryResult } from "./queryResult"
|
|
8
8
|
|
|
9
|
+
type OrderByAttribute = {
|
|
10
|
+
name: string
|
|
11
|
+
type: "string" | "number"
|
|
12
|
+
order: "asc" | "desc"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Helper function to create an ascending order by attribute
|
|
17
|
+
* @param attributeName - The name of the attribute to order by
|
|
18
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
19
|
+
* @returns The OrderByAttribute instance
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const ascAttribute = asc("name", "string")
|
|
23
|
+
*/
|
|
24
|
+
export function asc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute {
|
|
25
|
+
return {
|
|
26
|
+
name: attributeName,
|
|
27
|
+
type: attributeType,
|
|
28
|
+
order: "asc",
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Helper function to create a descending order by attribute
|
|
34
|
+
* @param attributeName - The name of the attribute to order by
|
|
35
|
+
* @param attributeType - The type of the attribute to order by (string or number)
|
|
36
|
+
* @returns The OrderByAttribute instance
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const descAttribute = desc("name", "string")
|
|
40
|
+
*/
|
|
41
|
+
export function desc(attributeName: string, attributeType: "string" | "number"): OrderByAttribute {
|
|
42
|
+
return {
|
|
43
|
+
name: attributeName,
|
|
44
|
+
type: attributeType,
|
|
45
|
+
order: "desc",
|
|
46
|
+
}
|
|
47
|
+
}
|
|
9
48
|
/**
|
|
10
49
|
* QueryBuilder is a helper class to build queries to the Arkiv DBChains.
|
|
11
50
|
* It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
|
|
@@ -49,26 +88,57 @@ export class QueryBuilder {
|
|
|
49
88
|
* The order of the attributes is important. The first attribute is the primary order by attribute.
|
|
50
89
|
* @param attributeName - The name of the attribute to order by
|
|
51
90
|
* @param attributeType - The type of the attribute to order by (string or number)
|
|
52
|
-
* @param
|
|
91
|
+
* @param order - The order to set the order by (asc or desc)
|
|
92
|
+
* @returns The QueryBuilder instance
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* const builder = new QueryBuilder(client)
|
|
96
|
+
* builder.orderBy("name", "string", "desc")
|
|
97
|
+
*/
|
|
98
|
+
orderBy(attributeName: string, attributeType: "string" | "number", order?: "asc" | "desc"): this
|
|
99
|
+
/**
|
|
100
|
+
* Sets the orderBy for the query.
|
|
101
|
+
* This method takes the OrderByAttribute object as an argument and is mainly
|
|
102
|
+
* used to use the helper functions asc() and desc() to create the OrderByAttribute instances.
|
|
103
|
+
* @param orderByAttribute - The OrderByAttribute instance to set
|
|
53
104
|
* @returns The QueryBuilder instance
|
|
54
105
|
*
|
|
55
106
|
* @example
|
|
56
107
|
* const builder = new QueryBuilder(client)
|
|
57
|
-
* builder.orderBy("name", "string"
|
|
108
|
+
* builder.orderBy(asc("name", "string"))
|
|
109
|
+
* builder.orderBy(desc("name", "string"))
|
|
58
110
|
*/
|
|
111
|
+
orderBy(orderByAttribute: OrderByAttribute): this
|
|
59
112
|
orderBy(
|
|
60
|
-
|
|
61
|
-
attributeType
|
|
62
|
-
|
|
113
|
+
attributeNameOrOrderByAttribute: string | OrderByAttribute,
|
|
114
|
+
attributeType?: "string" | "number",
|
|
115
|
+
order: "asc" | "desc" = "asc",
|
|
63
116
|
) {
|
|
64
117
|
if (!this._orderBy) {
|
|
65
118
|
this._orderBy = []
|
|
66
119
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
120
|
+
|
|
121
|
+
const pushOrderByAttribute = ({ name, type, order }: OrderByAttribute) => {
|
|
122
|
+
this._orderBy?.push({
|
|
123
|
+
name,
|
|
124
|
+
type: type === "number" ? "numeric" : type,
|
|
125
|
+
desc: order === "desc",
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (typeof attributeNameOrOrderByAttribute === "string") {
|
|
130
|
+
if (!attributeType) {
|
|
131
|
+
throw new Error("attributeType is required when using positional orderBy arguments")
|
|
132
|
+
}
|
|
133
|
+
pushOrderByAttribute({
|
|
134
|
+
name: attributeNameOrOrderByAttribute,
|
|
135
|
+
type: attributeType,
|
|
136
|
+
order,
|
|
137
|
+
})
|
|
138
|
+
} else {
|
|
139
|
+
pushOrderByAttribute(attributeNameOrOrderByAttribute)
|
|
140
|
+
}
|
|
141
|
+
|
|
72
142
|
return this
|
|
73
143
|
}
|
|
74
144
|
|
package/src/types/rpcSchema.ts
CHANGED
|
@@ -35,11 +35,6 @@ export type RpcIncludeData = {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type ArkivRpcSchema = [
|
|
38
|
-
{
|
|
39
|
-
Method: "golembase_getStorageValue"
|
|
40
|
-
Parameters?: [entityId: Hex]
|
|
41
|
-
ReturnType: string
|
|
42
|
-
},
|
|
43
38
|
{
|
|
44
39
|
Method: "arkiv_query"
|
|
45
40
|
Parameters?: [query: string, queryOptions?: RpcQueryOptions]
|