@arkiv-network/sdk 0.3.2-dev.2 → 0.3.2-dev.4
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 +12 -8
- package/dist/chains/index.cjs +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-BG8YycYJ.d.ts → entity-Bsvmepwv.d.cts} +25 -13
- package/dist/entity-Bsvmepwv.d.cts.map +1 -0
- package/dist/{entity-0JJeFAgO.d.cts → entity-ChTOBhd6.d.ts} +25 -13
- package/dist/entity-ChTOBhd6.d.ts.map +1 -0
- package/dist/index.cjs +40 -23
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +41 -24
- package/dist/index.js.map +1 -1
- package/dist/query/index.cjs +1 -1
- package/dist/query/index.d.cts +2 -2
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +1 -1
- package/dist/{queryBuilder-Dc_ii8LH.d.cts → queryBuilder-CNRqyot6.d.cts} +2 -2
- package/dist/{queryBuilder-Dc_ii8LH.d.cts.map → queryBuilder-CNRqyot6.d.cts.map} +1 -1
- package/dist/{queryBuilder-DEkfSiCF.cjs → queryBuilder-Cn5JJRMM.cjs} +79 -11
- package/dist/{queryBuilder-BNhnpewa.d.ts → queryBuilder-DI251Jjp.d.ts} +2 -2
- package/dist/{queryBuilder-BNhnpewa.d.ts.map → queryBuilder-DI251Jjp.d.ts.map} +1 -1
- package/dist/{queryBuilder-CAQ7TDMZ.js → queryBuilder-DVs4ZIyZ.js} +45 -13
- package/dist/queryBuilder-DVs4ZIyZ.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 +1 -0
- package/package.json +4 -2
- package/src/actions/public/getBlockTiming.ts +4 -1
- package/src/actions/public/getEntity.ts +18 -3
- package/src/actions/public/subscribeEntityEvents.ts +6 -3
- package/src/actions/wallet/changeOwnership.ts +5 -2
- package/src/actions/wallet/createEntity.ts +8 -5
- package/src/actions/wallet/deleteEntity.ts +8 -5
- package/src/actions/wallet/extendEntity.ts +8 -5
- package/src/actions/wallet/mutateEntities.ts +8 -4
- package/src/actions/wallet/updateEntity.ts +8 -5
- package/src/clients/decorators/arkivWallet.ts +1 -1
- package/src/query/engine.test.ts +75 -0
- package/src/query/engine.ts +28 -9
- package/src/query/queryBuilder.test.ts +8 -0
- package/src/query/queryResult.ts +4 -1
- package/src/types/entity.ts +22 -10
- package/src/types/rpcSchema.ts +9 -1
- package/src/utils/arkivTransactions.ts +6 -3
- package/src/utils/compression.ts +7 -4
- package/src/utils/entities.ts +15 -2
- package/src/utils/logger.ts +13 -0
- package/dist/entity-0JJeFAgO.d.cts.map +0 -1
- package/dist/entity-BG8YycYJ.d.ts.map +0 -1
- package/dist/queryBuilder-CAQ7TDMZ.js.map +0 -1
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { bytesToString, toBytes } from "viem";
|
|
2
|
+
import createDebug from "debug";
|
|
2
3
|
|
|
4
|
+
//#region src/utils/logger.ts
|
|
5
|
+
const ROOT_NAMESPACE = "arkiv";
|
|
6
|
+
const getLogger = (scope) => createDebug(`${ROOT_NAMESPACE}:${scope}`);
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
3
9
|
//#region src/query/errors.ts
|
|
4
10
|
var NoMoreResultsError = class extends Error {
|
|
5
11
|
constructor() {
|
|
@@ -26,31 +32,41 @@ var NoEntityFoundError = class extends Error {
|
|
|
26
32
|
//#region src/types/entity.ts
|
|
27
33
|
var Entity = class {
|
|
28
34
|
key;
|
|
35
|
+
contentType;
|
|
29
36
|
owner;
|
|
30
37
|
expiresAtBlock;
|
|
38
|
+
createdAtBlock;
|
|
39
|
+
lastModifiedAtBlock;
|
|
40
|
+
transactionIndexInBlock;
|
|
41
|
+
operationIndexInTransaction;
|
|
31
42
|
payload;
|
|
32
43
|
attributes;
|
|
33
|
-
contentType
|
|
34
|
-
constructor(key, contentType, owner, expiresAtBlock, payload, attributes) {
|
|
44
|
+
constructor(key, contentType = void 0, owner = void 0, expiresAtBlock = void 0, createdAtBlock = void 0, lastModifiedAtBlock = void 0, transactionIndexInBlock = void 0, operationIndexInTransaction = void 0, payload = void 0, attributes) {
|
|
35
45
|
this.key = key;
|
|
36
46
|
this.owner = owner;
|
|
37
47
|
this.expiresAtBlock = expiresAtBlock;
|
|
48
|
+
this.createdAtBlock = createdAtBlock;
|
|
49
|
+
this.lastModifiedAtBlock = lastModifiedAtBlock;
|
|
50
|
+
this.transactionIndexInBlock = transactionIndexInBlock;
|
|
51
|
+
this.operationIndexInTransaction = operationIndexInTransaction;
|
|
38
52
|
this.payload = payload;
|
|
39
53
|
this.attributes = attributes;
|
|
40
54
|
this.contentType = contentType;
|
|
41
55
|
}
|
|
42
56
|
toText() {
|
|
43
|
-
return bytesToString(this.payload);
|
|
57
|
+
return this.payload ? bytesToString(this.payload) : "";
|
|
44
58
|
}
|
|
45
59
|
toJson() {
|
|
46
|
-
return JSON.parse(bytesToString(this.payload));
|
|
60
|
+
return this.payload ? JSON.parse(bytesToString(this.payload)) : {};
|
|
47
61
|
}
|
|
48
62
|
};
|
|
49
63
|
|
|
50
64
|
//#endregion
|
|
51
65
|
//#region src/utils/entities.ts
|
|
66
|
+
const logger$2 = getLogger("utils:entities");
|
|
52
67
|
async function entityFromRpcResult(rpcEntity) {
|
|
53
|
-
|
|
68
|
+
logger$2("entityFromRpcResult %o", rpcEntity);
|
|
69
|
+
return new Entity(rpcEntity.key, rpcEntity.contentType, rpcEntity.owner, rpcEntity.expiresAt !== void 0 ? BigInt(rpcEntity.expiresAt) : void 0, rpcEntity.createdAtBlock !== void 0 ? BigInt(rpcEntity.createdAtBlock) : void 0, rpcEntity.lastModifiedAtBlock !== void 0 ? BigInt(rpcEntity.lastModifiedAtBlock) : void 0, rpcEntity.transactionIndexInBlock !== void 0 ? BigInt(rpcEntity.transactionIndexInBlock) : void 0, rpcEntity.operationIndexInTransaction !== void 0 ? BigInt(rpcEntity.operationIndexInTransaction) : void 0, rpcEntity.value !== void 0 ? toBytes(rpcEntity.value) : void 0, [...(rpcEntity.stringAttributes ?? []).map(({ key, value }) => ({
|
|
54
70
|
key,
|
|
55
71
|
value
|
|
56
72
|
})), ...(rpcEntity.numericAttributes ?? []).map(({ key, value }) => ({
|
|
@@ -61,6 +77,7 @@ async function entityFromRpcResult(rpcEntity) {
|
|
|
61
77
|
|
|
62
78
|
//#endregion
|
|
63
79
|
//#region src/query/engine.ts
|
|
80
|
+
const logger$1 = getLogger("query:engine");
|
|
64
81
|
function processPredicates(predicates) {
|
|
65
82
|
const processValue = (value) => {
|
|
66
83
|
if (typeof value === "string") return `"${value}"`;
|
|
@@ -83,7 +100,17 @@ function processPredicates(predicates) {
|
|
|
83
100
|
}
|
|
84
101
|
async function processQuery(client, queryParams) {
|
|
85
102
|
const { predicates, limit, cursor, ownedBy, orderBy, validAtBlock, withAttributes, withMetadata, withPayload } = queryParams;
|
|
86
|
-
|
|
103
|
+
logger$1("Processing query with params %o", {
|
|
104
|
+
predicates,
|
|
105
|
+
cursor,
|
|
106
|
+
limit,
|
|
107
|
+
ownedBy,
|
|
108
|
+
orderBy,
|
|
109
|
+
validAtBlock,
|
|
110
|
+
withAttributes,
|
|
111
|
+
withMetadata,
|
|
112
|
+
withPayload
|
|
113
|
+
});
|
|
87
114
|
let query = processPredicates(predicates);
|
|
88
115
|
if (ownedBy) query += ` && $owner=${ownedBy}`;
|
|
89
116
|
query = query.trim();
|
|
@@ -94,29 +121,34 @@ async function processQuery(client, queryParams) {
|
|
|
94
121
|
payload: withPayload ?? false,
|
|
95
122
|
contentType: withMetadata ?? false,
|
|
96
123
|
expiration: withMetadata ?? false,
|
|
97
|
-
owner: withMetadata ?? false
|
|
124
|
+
owner: withMetadata ?? false,
|
|
125
|
+
createdAtBlock: withMetadata ?? false,
|
|
126
|
+
lastModifiedAtBlock: withMetadata ?? false,
|
|
127
|
+
transactionIndexInBlock: withMetadata ?? false,
|
|
128
|
+
operationIndexInTransaction: withMetadata ?? false
|
|
98
129
|
} };
|
|
99
130
|
if (validAtBlock !== void 0) queryOptions.atBlock = Number(validAtBlock);
|
|
100
131
|
if (limit !== void 0) queryOptions.resultsPerPage = limit;
|
|
101
132
|
if (cursor !== void 0) queryOptions.cursor = cursor;
|
|
102
133
|
if (orderBy !== void 0) queryOptions.orderBy = orderBy;
|
|
103
|
-
|
|
134
|
+
logger$1("Built query to send %s %o", query, {
|
|
104
135
|
includeData: queryOptions.includeData,
|
|
105
136
|
atBlock: queryOptions.atBlock?.toString(),
|
|
106
137
|
orderBy: queryOptions.orderBy,
|
|
107
138
|
resultsPerPage: queryOptions.resultsPerPage,
|
|
108
139
|
cursor: queryOptions.cursor
|
|
109
|
-
})
|
|
140
|
+
});
|
|
110
141
|
const result = await client.request({
|
|
111
142
|
method: "arkiv_query",
|
|
112
143
|
params: [query, queryOptions]
|
|
113
144
|
});
|
|
114
|
-
|
|
145
|
+
logger$1("Raw result from query %o", result);
|
|
115
146
|
return result;
|
|
116
147
|
}
|
|
117
148
|
|
|
118
149
|
//#endregion
|
|
119
150
|
//#region src/query/queryResult.ts
|
|
151
|
+
const logger = getLogger("query:result");
|
|
120
152
|
var QueryResult = class {
|
|
121
153
|
entities;
|
|
122
154
|
_endOfIteration;
|
|
@@ -147,7 +179,7 @@ var QueryResult = class {
|
|
|
147
179
|
this._queryBuilder = result.queryBuilder;
|
|
148
180
|
this._endOfIteration = !result.cursor || result.entities.length < this._limit;
|
|
149
181
|
this._cursor = result.cursor;
|
|
150
|
-
|
|
182
|
+
logger("Current block height for next page %s", this._validAtBlock?.toString() ?? "unknown");
|
|
151
183
|
}
|
|
152
184
|
hasNextPage() {
|
|
153
185
|
return !this._endOfIteration;
|
|
@@ -393,5 +425,5 @@ var QueryBuilder = class {
|
|
|
393
425
|
};
|
|
394
426
|
|
|
395
427
|
//#endregion
|
|
396
|
-
export { entityFromRpcResult as a, NoMoreResultsError as c, QueryResult as i, OffsetCannotBeLessThanZeroError as l, asc as n, NoCursorOrLimitError as o, desc as r, NoEntityFoundError as s, QueryBuilder as t };
|
|
397
|
-
//# sourceMappingURL=queryBuilder-
|
|
428
|
+
export { entityFromRpcResult as a, NoMoreResultsError as c, QueryResult as i, OffsetCannotBeLessThanZeroError as l, asc as n, NoCursorOrLimitError as o, desc as r, NoEntityFoundError as s, QueryBuilder as t, getLogger as u };
|
|
429
|
+
//# sourceMappingURL=queryBuilder-DVs4ZIyZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryBuilder-DVs4ZIyZ.js","names":["logger","logger","predicate","queryOptions: RpcQueryOptions","order"],"sources":["../src/utils/logger.ts","../src/query/errors.ts","../src/types/entity.ts","../src/utils/entities.ts","../src/query/engine.ts","../src/query/queryResult.ts","../src/query/queryBuilder.ts"],"sourcesContent":["import createDebug from \"debug\"\n\nconst ROOT_NAMESPACE = \"arkiv\"\n\nexport const getLogger = (scope: string) => createDebug(`${ROOT_NAMESPACE}:${scope}`)\n\nexport const enableDebug = (namespaces: string): void => {\n createDebug.enable(namespaces)\n}\n\nexport const disableDebug = (): void => {\n createDebug.disable()\n}\n","export class NoMoreResultsError extends Error {\n constructor() {\n super(\"No more results\")\n }\n}\n\nexport class NoCursorOrLimitError extends Error {\n constructor() {\n super(\"Cursor and limit must be defined to fetch next\")\n }\n}\n\nexport class OffsetCannotBeLessThanZeroError extends Error {\n constructor() {\n super(\"Offset cannot be less than 0\")\n }\n}\n\nexport class NoEntityFoundError extends Error {\n constructor() {\n super(\"No entity found\")\n }\n}\n","import { bytesToString, type Hex } from \"viem\"\nimport type { MimeType } from \"../types\"\nimport type { Attribute } from \"./attributes\"\n\nexport class Entity {\n key: Hex\n contentType: MimeType | undefined\n owner: Hex | undefined\n expiresAtBlock: bigint | undefined\n createdAtBlock: bigint | undefined\n lastModifiedAtBlock: bigint | undefined\n transactionIndexInBlock: bigint | undefined\n operationIndexInTransaction: bigint | undefined\n payload: Uint8Array | undefined\n attributes: Attribute[]\n\n constructor(\n key: Hex,\n contentType: MimeType | undefined = undefined,\n owner: Hex | undefined = undefined,\n expiresAtBlock: bigint | undefined = undefined,\n createdAtBlock: bigint | undefined = undefined,\n lastModifiedAtBlock: bigint | undefined = undefined,\n transactionIndexInBlock: bigint | undefined = undefined,\n operationIndexInTransaction: bigint | undefined = undefined,\n payload: Uint8Array | undefined = undefined,\n attributes: Attribute[],\n ) {\n this.key = key\n this.owner = owner\n this.expiresAtBlock = expiresAtBlock\n this.createdAtBlock = createdAtBlock\n this.lastModifiedAtBlock = lastModifiedAtBlock\n this.transactionIndexInBlock = transactionIndexInBlock\n this.operationIndexInTransaction = operationIndexInTransaction\n this.payload = payload\n this.attributes = attributes\n this.contentType = contentType\n }\n\n toText(): string {\n return this.payload ? bytesToString(this.payload) : \"\"\n }\n\n toJson(): any {\n return this.payload ? JSON.parse(bytesToString(this.payload)) : {}\n }\n}\n","import { toBytes } from \"viem\"\nimport { Entity } from \"../types/entity\"\nimport type { RpcEntity } from \"../types/rpcSchema\"\nimport { getLogger } from \"./logger\"\n\nconst logger = getLogger(\"utils:entities\")\n\nexport async function entityFromRpcResult(rpcEntity: RpcEntity) {\n logger(\"entityFromRpcResult %o\", rpcEntity)\n\n return new Entity(\n rpcEntity.key,\n rpcEntity.contentType,\n rpcEntity.owner,\n rpcEntity.expiresAt !== undefined ? BigInt(rpcEntity.expiresAt) : undefined,\n rpcEntity.createdAtBlock !== undefined ? BigInt(rpcEntity.createdAtBlock) : undefined,\n rpcEntity.lastModifiedAtBlock !== undefined ? BigInt(rpcEntity.lastModifiedAtBlock) : undefined,\n rpcEntity.transactionIndexInBlock !== undefined\n ? BigInt(rpcEntity.transactionIndexInBlock)\n : undefined,\n rpcEntity.operationIndexInTransaction !== undefined\n ? BigInt(rpcEntity.operationIndexInTransaction)\n : undefined,\n rpcEntity.value !== undefined ? toBytes(rpcEntity.value) : undefined,\n [\n ...(rpcEntity.stringAttributes ?? []).map(({ key, value }) => ({\n key,\n value,\n })),\n ...(rpcEntity.numericAttributes ?? []).map(({ key, value }) => ({\n key,\n value: Number(value),\n })),\n ],\n )\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcIncludeData, RpcOrderByAttribute, RpcQueryOptions } from \"../types/rpcSchema\"\nimport { getLogger } from \"../utils/logger\"\nimport type { Predicate } from \"./predicate\"\n\nconst logger = getLogger(\"query:engine\")\n\nfunction processPredicates(predicates: Predicate[]): string {\n const processValue = (value: string | number) => {\n if (typeof value === \"string\") {\n return `\"${value}\"`\n }\n return value\n }\n return predicates\n .map((predicate) => {\n switch (predicate.type) {\n case \"eq\":\n return `${predicate.key} = ${processValue(predicate.value)}`\n case \"neq\":\n return `${predicate.key} != ${processValue(predicate.value)}`\n case \"gt\":\n return `${predicate.key} > ${processValue(predicate.value)}`\n case \"gte\":\n return `${predicate.key} >= ${processValue(predicate.value)}`\n case \"lt\":\n return `${predicate.key} < ${processValue(predicate.value)}`\n case \"lte\":\n return `${predicate.key} <= ${processValue(predicate.value)}`\n case \"not\":\n return `!${predicate.key}`\n case \"or\":\n return `(${predicate.predicates.map((predicate) => processPredicates([predicate])).join(\" || \")})`\n case \"and\":\n return `(${predicate.predicates.map((predicate) => processPredicates([predicate])).join(\" && \")})`\n default:\n return \"\"\n }\n })\n .join(\" && \")\n}\n\nexport async function processQuery(\n client: ArkivClient,\n queryParams: {\n predicates: Predicate[]\n limit: number | undefined\n cursor: string | undefined\n ownedBy: Hex | undefined\n orderBy: RpcOrderByAttribute[] | undefined\n validAtBlock?: bigint | undefined\n withAttributes?: boolean | undefined\n withMetadata?: boolean | undefined\n withPayload?: boolean | undefined\n },\n) {\n const {\n predicates,\n limit,\n cursor,\n ownedBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n } = queryParams\n\n logger(\"Processing query with params %o\", {\n predicates,\n cursor,\n limit,\n ownedBy,\n orderBy,\n validAtBlock,\n withAttributes,\n withMetadata,\n withPayload,\n })\n\n let query = processPredicates(predicates)\n if (ownedBy) {\n query += ` && $owner=${ownedBy}`\n }\n\n // remove leading and trailing spaces and leading &&\n query = query.trim()\n if (query.startsWith(\"&& \")) {\n query = query.slice(3)\n }\n\n const queryOptions: RpcQueryOptions = {\n includeData: {\n key: true,\n attributes: withAttributes ?? false,\n payload: withPayload ?? false,\n contentType: withMetadata ?? false,\n expiration: withMetadata ?? false,\n owner: withMetadata ?? false,\n createdAtBlock: withMetadata ?? false,\n lastModifiedAtBlock: withMetadata ?? false,\n transactionIndexInBlock: withMetadata ?? false,\n operationIndexInTransaction: withMetadata ?? false,\n } as RpcIncludeData,\n }\n\n if (validAtBlock !== undefined) {\n queryOptions.atBlock = Number(validAtBlock)\n }\n if (limit !== undefined) {\n queryOptions.resultsPerPage = limit\n }\n if (cursor !== undefined) {\n queryOptions.cursor = cursor\n }\n if (orderBy !== undefined) {\n queryOptions.orderBy = orderBy\n }\n\n logger(\"Built query to send %s %o\", query, {\n includeData: queryOptions.includeData,\n atBlock: queryOptions.atBlock?.toString(),\n orderBy: queryOptions.orderBy,\n resultsPerPage: queryOptions.resultsPerPage,\n cursor: queryOptions.cursor,\n })\n\n const result = await client.request({\n method: \"arkiv_query\",\n params: [query, queryOptions],\n })\n logger(\"Raw result from query %o\", result)\n\n return result\n}\n","import type { Entity } from \"../types/entity\"\nimport { getLogger } from \"../utils/logger\"\nimport { NoCursorOrLimitError, NoMoreResultsError } from \"./errors\"\nimport type { QueryBuilder } from \"./queryBuilder\"\n\nconst logger = getLogger(\"query:result\")\n\nexport class QueryResult {\n entities: Entity[]\n private _endOfIteration: boolean\n private _cursor: string | undefined\n private _limit: number | undefined\n private _validAtBlock: bigint | undefined\n private _queryBuilder: QueryBuilder\n\n // Public getters for internal state\n get queryBuilder(): QueryBuilder {\n return this._queryBuilder\n }\n\n get cursor(): string | undefined {\n return this._cursor\n }\n\n constructor(\n entities: Entity[],\n queryBuilder: QueryBuilder,\n cursor: string | undefined,\n limit: number | undefined,\n validAtBlock: bigint | undefined,\n ) {\n this.entities = entities\n this._queryBuilder = queryBuilder\n this._endOfIteration = !limit || entities.length < limit\n this._cursor = cursor\n this._limit = limit\n this._validAtBlock = validAtBlock\n }\n\n async next() {\n if (this._cursor === undefined || this._limit === undefined) {\n throw new NoCursorOrLimitError()\n }\n if (this._endOfIteration) {\n throw new NoMoreResultsError()\n }\n this._queryBuilder.cursor(this._cursor)\n const result = await this._queryBuilder.fetch()\n this.entities = result.entities\n // Update the query builder reference\n this._queryBuilder = result.queryBuilder\n // Check if we've reached the end (no more cursor or we got fewer entities than limit)\n this._endOfIteration = !result.cursor || result.entities.length < this._limit\n // Update the cursor\n this._cursor = result.cursor\n\n // TODO check current block height and if it is not too old\n logger(\"Current block height for next page %s\", this._validAtBlock?.toString() ?? \"unknown\")\n }\n\n hasNextPage() {\n return !this._endOfIteration\n }\n}\n","import type { Hex } from \"viem\"\nimport type { ArkivClient } from \"../clients/baseClient\"\nimport type { RpcOrderByAttribute } from \"../types/rpcSchema\"\nimport { entityFromRpcResult } from \"../utils/entities\"\nimport { processQuery } from \"./engine\"\nimport type { Predicate } from \"./predicate\"\nimport { QueryResult } from \"./queryResult\"\n\ntype OrderByAttribute = {\n name: string\n type: \"string\" | \"number\"\n order: \"asc\" | \"desc\"\n}\n\n/**\n * Helper function to create an ascending order by attribute\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @returns The OrderByAttribute instance\n *\n * @example\n * const ascAttribute = asc(\"name\", \"string\")\n */\nexport function asc(attributeName: string, attributeType: \"string\" | \"number\"): OrderByAttribute {\n return {\n name: attributeName,\n type: attributeType,\n order: \"asc\",\n }\n}\n\n/**\n * Helper function to create a descending order by attribute\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @returns The OrderByAttribute instance\n *\n * @example\n * const descAttribute = desc(\"name\", \"string\")\n */\nexport function desc(attributeName: string, attributeType: \"string\" | \"number\"): OrderByAttribute {\n return {\n name: attributeName,\n type: attributeType,\n order: \"desc\",\n }\n}\n/**\n * QueryBuilder is a helper class to build queries to the Arkiv DBChains.\n * It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.\n * @param client - The Arkiv client\n * @returns The QueryBuilder instance {@link QueryBuilder}\n */\nexport class QueryBuilder {\n private _client: ArkivClient\n private _ownedBy: Hex | undefined\n private _orderBy: RpcOrderByAttribute[] | undefined\n private _validAtBlock: bigint | undefined\n private _withAttributes: boolean | undefined\n private _withMetadata: boolean | undefined\n private _withPayload: boolean | undefined\n private _limit: number | undefined\n private _cursor: string | undefined\n private _predicates: Predicate[]\n\n constructor(client: ArkivClient) {\n this._client = client\n this._predicates = []\n }\n\n /**\n * Sets the ownedBy filter\n * @param ownedBy - The address of the owner\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.ownedBy(\"0x1234567890123456789012345678901234567890\")\n */\n ownedBy(ownedBy: Hex) {\n this._ownedBy = ownedBy\n return this\n }\n\n /**\n * Sets the orderBy for the query.\n * It can be called multiple times to order by multiple attributes.\n * The order of the attributes is important. The first attribute is the primary order by attribute.\n * @param attributeName - The name of the attribute to order by\n * @param attributeType - The type of the attribute to order by (string or number)\n * @param order - The order to set the order by (asc or desc)\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(\"name\", \"string\", \"desc\")\n */\n orderBy(attributeName: string, attributeType: \"string\" | \"number\", order?: \"asc\" | \"desc\"): this\n /**\n * Sets the orderBy for the query.\n * This method takes the OrderByAttribute object as an argument and is mainly\n * used to use the helper functions asc() and desc() to create the OrderByAttribute instances.\n * @param orderByAttribute - The OrderByAttribute instance to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.orderBy(asc(\"name\", \"string\"))\n * builder.orderBy(desc(\"name\", \"string\"))\n */\n orderBy(orderByAttribute: OrderByAttribute): this\n orderBy(\n attributeNameOrOrderByAttribute: string | OrderByAttribute,\n attributeType?: \"string\" | \"number\",\n order: \"asc\" | \"desc\" = \"asc\",\n ) {\n if (!this._orderBy) {\n this._orderBy = []\n }\n\n const pushOrderByAttribute = ({ name, type, order }: OrderByAttribute) => {\n this._orderBy?.push({\n name,\n type: type === \"number\" ? \"numeric\" : type,\n desc: order === \"desc\",\n })\n }\n\n if (typeof attributeNameOrOrderByAttribute === \"string\") {\n if (!attributeType) {\n throw new Error(\"attributeType is required when using positional orderBy arguments\")\n }\n pushOrderByAttribute({\n name: attributeNameOrOrderByAttribute,\n type: attributeType,\n order,\n })\n } else {\n pushOrderByAttribute(attributeNameOrOrderByAttribute)\n }\n\n return this\n }\n\n /**\n * Sets the withAttributes flag which will return the attributes for the entities if true\n * @param withAttributes - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withAttributes(true)\n */\n withAttributes(withAttributes: boolean = true) {\n this._withAttributes = withAttributes\n return this\n }\n\n /**\n * Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true\n * @param withMetadata - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withMetadata(true)\n */\n withMetadata(withMetadata: boolean = true) {\n this._withMetadata = withMetadata\n return this\n }\n\n /**\n * Sets the withPayload flag which will return the payload for the entities if true\n * @param withPayload - The boolean value to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.withPayload(true)\n */\n withPayload(withPayload: boolean = true) {\n this._withPayload = withPayload\n return this\n }\n\n /**\n * Sets the limit for the query\n * @param limit - The number of entities to return\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.limit(10)\n */\n limit(limit: number) {\n this._limit = limit\n return this\n }\n\n /**\n * 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).\n * @param cursor - The cursor to set which tells to RPC Query server where to start or continue the query.\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.offset(10)\n */\n cursor(cursor: string) {\n this._cursor = cursor\n return this\n }\n\n /**\n * Sets the validAtBlock for the query which tells at which block height the state we are intested.\n * If not set, the latest block is used.\n * @param validAtBlock - The block number to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.validAtBlock(10000)\n */\n validAtBlock(validAtBlock: bigint) {\n this._validAtBlock = validAtBlock\n return this\n }\n\n /**\n * Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with 'and'.\n * Predicates can be nested using 'or' and 'and' predicates.\n * @param predicates - The predicates to set\n * @returns The QueryBuilder instance\n *\n * @example\n * const builder = new QueryBuilder(client)\n * builder.where(eq(\"name\", \"John\"))\n * builder.where([eq(\"name\", \"John\"), eq(\"age\", 30)])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), eq(\"age\", 31)])])\n * builder.where([eq(\"name\", \"John\"), or([eq(\"age\", 30), and([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), eq(\"age\", 32)])])])\n * builder.where([eq(\"name\", \"John\"), and([eq(\"age\", 30), or([eq(\"age\", 31), and([eq(\"age\", 32), eq(\"age\", 33)])])])])\n */\n where(predicates: Predicate[] | Predicate) {\n if (Array.isArray(predicates)) {\n this._predicates.push(...predicates)\n } else {\n this._predicates.push(predicates)\n }\n return this\n }\n\n /**\n * Fetches the entities from the query. Re\n * It will return a QueryResult instance which can be used to fetch the next and previous pages.\n * @returns The QueryResult instance {@link QueryResult}\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).fetch()\n * // result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }\n */\n async fetch() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: this._orderBy,\n validAtBlock: this._validAtBlock,\n withAttributes: this._withAttributes,\n withMetadata: this._withMetadata,\n withPayload: this._withPayload,\n })\n\n const entities = await Promise.all(\n queryResult.data.map((entity) => entityFromRpcResult(entity)),\n )\n\n this.cursor(queryResult.cursor)\n this.validAtBlock(queryResult.blockNumber)\n\n return new QueryResult(entities, this, this._cursor, this._limit, this._validAtBlock)\n }\n\n /**\n * Counts the entities from the query.\n * @returns The number of entities\n *\n * @example\n * const builder = new QueryBuilder(client)\n * const result = await builder.where(eq(\"name\", \"John\")).count()\n * // result = 10\n */\n async count() {\n const queryResult = await processQuery(this._client, {\n predicates: this._predicates,\n limit: this._limit,\n cursor: this._cursor,\n ownedBy: this._ownedBy,\n orderBy: undefined,\n validAtBlock: this._validAtBlock,\n withAttributes: false,\n withMetadata: false,\n withPayload: false,\n })\n\n return queryResult.data.length ?? 0\n }\n}\n"],"mappings":";;;;AAEA,MAAM,iBAAiB;AAEvB,MAAa,aAAa,UAAkB,YAAY,GAAG,eAAe,GAAG,QAAQ;;;;ACJrF,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;AACZ,QAAM,kBAAkB;;;AAI5B,IAAa,uBAAb,cAA0C,MAAM;CAC9C,cAAc;AACZ,QAAM,iDAAiD;;;AAI3D,IAAa,kCAAb,cAAqD,MAAM;CACzD,cAAc;AACZ,QAAM,+BAA+B;;;AAIzC,IAAa,qBAAb,cAAwC,MAAM;CAC5C,cAAc;AACZ,QAAM,kBAAkB;;;;;;AChB5B,IAAa,SAAb,MAAoB;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACE,KACA,cAAoC,QACpC,QAAyB,QACzB,iBAAqC,QACrC,iBAAqC,QACrC,sBAA0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AK,SAAS;AACd,SAAO;;;;;;;;;;;CAYT,OAAO,QAAgB;AACrB,OAAK,UAAU;AACf,SAAO;;;;;;;;;;;;CAaT,aAAa,cAAsB;AACjC,OAAK,gBAAgB;AACrB,SAAO;;;;;;;;;;;;;;;;;;CAmBT,MAAM,YAAqC;AACzC,MAAI,MAAM,QAAQ,WAAW,CAC3B,MAAK,YAAY,KAAK,GAAG,WAAW;MAEpC,MAAK,YAAY,KAAK,WAAW;AAEnC,SAAO;;;;;;;;;;;;CAaT,MAAM,QAAQ;EACZ,MAAM,cAAc,MAAM,aAAa,KAAK,SAAS;GACnD,YAAY,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,SAAS,KAAK;GACd,cAAc,KAAK;GACnB,gBAAgB,KAAK;GACrB,cAAc,KAAK;GACnB,aAAa,KAAK;GACnB,CAAC;EAEF,MAAM,WAAW,MAAM,QAAQ,IAC7B,YAAY,KAAK,KAAK,WAAW,oBAAoB,OAAO,CAAC,CAC9D;AAED,OAAK,OAAO,YAAY,OAAO;AAC/B,OAAK,aAAa,YAAY,YAAY;AAE1C,SAAO,IAAI,YAAY,UAAU,MAAM,KAAK,SAAS,KAAK,QAAQ,KAAK,cAAc;;;;;;;;;;;CAYvF,MAAM,QAAQ;AAaZ,UAZoB,MAAM,aAAa,KAAK,SAAS;GACnD,YAAY,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,SAAS;GACT,cAAc,KAAK;GACnB,gBAAgB;GAChB,cAAc;GACd,aAAa;GACd,CAAC,EAEiB,KAAK,UAAU"}
|
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-Bsvmepwv.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-ChTOBhd6.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/utils/index.cjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkiv-network/sdk",
|
|
3
|
-
"version": "0.3.2-dev.
|
|
3
|
+
"version": "0.3.2-dev.4",
|
|
4
4
|
"description": "TypeScript client library for Arkiv's blockchains interactions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"target": "esnext",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"publish-dev:dry": "npm publish ./arkiv-network-sdk-latest.tgz --access public --tag dev --dry-run"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
+
"@types/debug": "^4.1.12",
|
|
87
88
|
"@biomejs/biome": "2.2.4",
|
|
88
89
|
"@types/bun": "latest",
|
|
89
90
|
"rimraf": "^6.0.1",
|
|
@@ -116,6 +117,7 @@
|
|
|
116
117
|
"homepage": "https://arkiv.network",
|
|
117
118
|
"dependencies": {
|
|
118
119
|
"brotli-wasm": "^3.0.1",
|
|
119
|
-
"viem": "^2.38.2"
|
|
120
|
+
"viem": "^2.38.2",
|
|
121
|
+
"debug": "^4.3.7"
|
|
120
122
|
}
|
|
121
123
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
2
|
+
import { getLogger } from "../../utils/logger"
|
|
3
|
+
|
|
4
|
+
const logger = getLogger("actions:public:get-block-timing")
|
|
2
5
|
|
|
3
6
|
export type GetBlockTimingReturnType = {
|
|
4
7
|
currentBlock: bigint
|
|
@@ -11,7 +14,7 @@ export async function getBlockTiming(client: ArkivClient) {
|
|
|
11
14
|
method: "arkiv_getBlockTiming",
|
|
12
15
|
params: [],
|
|
13
16
|
})
|
|
14
|
-
|
|
17
|
+
logger("Block timing %o", blockTiming)
|
|
15
18
|
return {
|
|
16
19
|
currentBlock: blockTiming.current_block,
|
|
17
20
|
currentBlockTime: blockTiming.current_block_time,
|
|
@@ -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()
|
|
@@ -9,6 +9,9 @@ import type {
|
|
|
9
9
|
OnEntityOwnerChangedEvent,
|
|
10
10
|
OnEntityUpdatedEvent,
|
|
11
11
|
} from "../../types/events"
|
|
12
|
+
import { getLogger } from "../../utils/logger"
|
|
13
|
+
|
|
14
|
+
const logger = getLogger("actions:public:subscribe-entity-events")
|
|
12
15
|
|
|
13
16
|
export const arkivABI = parseAbi([
|
|
14
17
|
"event ArkivEntityCreated(uint256 indexed entityKey, address indexed ownerAddress, uint256 expirationBlock, uint256 cost)",
|
|
@@ -46,14 +49,14 @@ export async function subscribeEntityEvents(
|
|
|
46
49
|
fromBlock: fromBlock ?? 0n,
|
|
47
50
|
events: arkivABI,
|
|
48
51
|
onLogs: (logs) => {
|
|
49
|
-
|
|
52
|
+
logger("logs from subscribeEntityEvents %o", logs)
|
|
50
53
|
for (const log of logs) {
|
|
51
54
|
const event = decodeEventLog({
|
|
52
55
|
abi: arkivABI,
|
|
53
|
-
topics: log.topics,
|
|
56
|
+
topics: log.topics as [string, string, string] | [string, string, string, string],
|
|
54
57
|
data: log.data,
|
|
55
58
|
})
|
|
56
|
-
|
|
59
|
+
logger("event from subscribeEntityEvents %o", event)
|
|
57
60
|
switch (event.eventName) {
|
|
58
61
|
case "ArkivEntityCreated":
|
|
59
62
|
onEntityCreated?.({
|
|
@@ -2,6 +2,9 @@ import type { Hex } from "viem"
|
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import type { TxParams } from "../../types"
|
|
4
4
|
import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
|
|
5
|
+
import { getLogger } from "../../utils/logger"
|
|
6
|
+
|
|
7
|
+
const logger = getLogger("actions:wallet:change-ownership")
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Parameters for the deleteEntity function.
|
|
@@ -27,11 +30,11 @@ export async function changeOwnership(
|
|
|
27
30
|
data: ChangeOwnershipParameters,
|
|
28
31
|
txParams?: TxParams,
|
|
29
32
|
): Promise<ChangeOwnershipReturnType> {
|
|
30
|
-
|
|
33
|
+
logger("changeOwnership %o", data)
|
|
31
34
|
const txData = opsToTxData({ ownershipChanges: [data] })
|
|
32
35
|
const receipt = await sendArkivTransaction(client, txData, txParams)
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
logger("Receipt from changeOwnership %o", receipt)
|
|
35
38
|
|
|
36
39
|
return {
|
|
37
40
|
txHash: receipt.transactionHash,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { Hex } from "viem"
|
|
1
|
+
import type { Hash, Hex } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import type { Attribute, MimeType, TxParams } from "../../types"
|
|
4
4
|
import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
|
|
5
|
+
import { getLogger } from "../../utils/logger"
|
|
6
|
+
|
|
7
|
+
const logger = getLogger("actions:wallet:create-entity")
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Parameters for the createEntity function.
|
|
@@ -24,7 +27,7 @@ export type CreateEntityParameters = {
|
|
|
24
27
|
*/
|
|
25
28
|
export type CreateEntityReturnType = {
|
|
26
29
|
entityKey: Hex
|
|
27
|
-
txHash:
|
|
30
|
+
txHash: Hash
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export async function createEntity(
|
|
@@ -32,14 +35,14 @@ export async function createEntity(
|
|
|
32
35
|
data: CreateEntityParameters,
|
|
33
36
|
txParams?: TxParams,
|
|
34
37
|
): Promise<CreateEntityReturnType> {
|
|
35
|
-
|
|
38
|
+
logger("createEntity %o", data)
|
|
36
39
|
const txData = opsToTxData({ creates: [data] })
|
|
37
40
|
const receipt = await sendArkivTransaction(client, txData, txParams)
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
logger("Receipt from createEntity %o", receipt)
|
|
40
43
|
|
|
41
44
|
return {
|
|
42
|
-
txHash: receipt.transactionHash,
|
|
45
|
+
txHash: receipt.transactionHash as Hash,
|
|
43
46
|
entityKey: receipt.logs[0].topics[1] as Hex,
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { Hex } from "viem"
|
|
1
|
+
import type { Hash, Hex } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import type { TxParams } from "../../types"
|
|
4
4
|
import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
|
|
5
|
+
import { getLogger } from "../../utils/logger"
|
|
6
|
+
|
|
7
|
+
const logger = getLogger("actions:wallet:delete-entity")
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Parameters for the deleteEntity function.
|
|
@@ -18,7 +21,7 @@ export type DeleteEntityParameters = {
|
|
|
18
21
|
*/
|
|
19
22
|
export type DeleteEntityReturnType = {
|
|
20
23
|
entityKey: Hex
|
|
21
|
-
txHash:
|
|
24
|
+
txHash: Hash
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
export async function deleteEntity(
|
|
@@ -26,14 +29,14 @@ export async function deleteEntity(
|
|
|
26
29
|
data: DeleteEntityParameters,
|
|
27
30
|
txParams?: TxParams,
|
|
28
31
|
): Promise<DeleteEntityReturnType> {
|
|
29
|
-
|
|
32
|
+
logger("deleteEntity %o", data)
|
|
30
33
|
const txData = opsToTxData({ deletes: [data] })
|
|
31
34
|
const receipt = await sendArkivTransaction(client, txData, txParams)
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
logger("Receipt from deleteEntity %o", receipt)
|
|
34
37
|
|
|
35
38
|
return {
|
|
36
|
-
txHash: receipt.transactionHash,
|
|
39
|
+
txHash: receipt.transactionHash as Hash,
|
|
37
40
|
entityKey: data.entityKey,
|
|
38
41
|
}
|
|
39
42
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { Hex } from "viem"
|
|
1
|
+
import type { Hash, Hex } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import type { TxParams } from "../../types"
|
|
4
4
|
import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
|
|
5
|
+
import { getLogger } from "../../utils/logger"
|
|
6
|
+
|
|
7
|
+
const logger = getLogger("actions:wallet:extend-entity")
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Parameters for the extendEntity function.
|
|
@@ -20,7 +23,7 @@ export type ExtendEntityParameters = {
|
|
|
20
23
|
*/
|
|
21
24
|
export type ExtendEntityReturnType = {
|
|
22
25
|
entityKey: Hex
|
|
23
|
-
txHash:
|
|
26
|
+
txHash: Hash
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export async function extendEntity(
|
|
@@ -28,14 +31,14 @@ export async function extendEntity(
|
|
|
28
31
|
data: ExtendEntityParameters,
|
|
29
32
|
txParams?: TxParams,
|
|
30
33
|
): Promise<ExtendEntityReturnType> {
|
|
31
|
-
|
|
34
|
+
logger("extendEntity %o", data)
|
|
32
35
|
const txData = opsToTxData({ extensions: [data] })
|
|
33
36
|
const receipt = await sendArkivTransaction(client, txData, txParams)
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
logger("Receipt from extendEntity %o", receipt)
|
|
36
39
|
|
|
37
40
|
return {
|
|
38
|
-
txHash: receipt.transactionHash,
|
|
41
|
+
txHash: receipt.transactionHash as Hash,
|
|
39
42
|
entityKey: receipt.logs[0].topics[1] as Hex,
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { Hex, TransactionReceipt } from "viem"
|
|
1
|
+
import type { Hash, Hex, TransactionReceipt } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import type { TxParams } from "../../types"
|
|
4
4
|
import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
|
|
5
|
+
import { getLogger } from "../../utils/logger"
|
|
5
6
|
import type { ChangeOwnershipParameters } from "./changeOwnership"
|
|
7
|
+
|
|
8
|
+
const logger = getLogger("actions:wallet:mutate-entities")
|
|
9
|
+
|
|
6
10
|
import type { CreateEntityParameters } from "./createEntity"
|
|
7
11
|
import type { DeleteEntityParameters } from "./deleteEntity"
|
|
8
12
|
import type { ExtendEntityParameters } from "./extendEntity"
|
|
@@ -68,7 +72,7 @@ function parseReceipt(receipt: TransactionReceipt, params: MutateEntitiesParamet
|
|
|
68
72
|
* - ownershipChanges: The keys of the ownership changes.
|
|
69
73
|
*/
|
|
70
74
|
export type MutateEntitiesReturnType = {
|
|
71
|
-
txHash:
|
|
75
|
+
txHash: Hash
|
|
72
76
|
createdEntities: Hex[]
|
|
73
77
|
updatedEntities: Hex[]
|
|
74
78
|
deletedEntities: Hex[]
|
|
@@ -94,12 +98,12 @@ export async function mutateEntities(
|
|
|
94
98
|
|
|
95
99
|
const receipt = await sendArkivTransaction(client, txData, txParams)
|
|
96
100
|
|
|
97
|
-
|
|
101
|
+
logger("Receipt from mutateEntities %o", receipt)
|
|
98
102
|
|
|
99
103
|
const { createdEntities, updatedEntities, deletedEntities, extendedEntities, ownershipChanges } =
|
|
100
104
|
parseReceipt(receipt, data)
|
|
101
105
|
return {
|
|
102
|
-
txHash: receipt.transactionHash,
|
|
106
|
+
txHash: receipt.transactionHash as Hash,
|
|
103
107
|
createdEntities,
|
|
104
108
|
updatedEntities,
|
|
105
109
|
deletedEntities,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { Hex } from "viem"
|
|
1
|
+
import type { Hash, Hex } from "viem"
|
|
2
2
|
import type { ArkivClient } from "../../clients/baseClient"
|
|
3
3
|
import type { Attribute, MimeType, TxParams } from "../../types"
|
|
4
4
|
import { opsToTxData, sendArkivTransaction } from "../../utils/arkivTransactions"
|
|
5
|
+
import { getLogger } from "../../utils/logger"
|
|
6
|
+
|
|
7
|
+
const logger = getLogger("actions:wallet:update-entity")
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Parameters for the updateEntity function.
|
|
@@ -26,7 +29,7 @@ export type UpdateEntityParameters = {
|
|
|
26
29
|
*/
|
|
27
30
|
export type UpdateEntityReturnType = {
|
|
28
31
|
entityKey: Hex
|
|
29
|
-
txHash:
|
|
32
|
+
txHash: Hash
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export async function updateEntity(
|
|
@@ -34,14 +37,14 @@ export async function updateEntity(
|
|
|
34
37
|
data: UpdateEntityParameters,
|
|
35
38
|
txParams?: TxParams,
|
|
36
39
|
): Promise<UpdateEntityReturnType> {
|
|
37
|
-
|
|
40
|
+
logger("updateEntity %o", data)
|
|
38
41
|
const txData = opsToTxData({ updates: [data] })
|
|
39
42
|
const receipt = await sendArkivTransaction(client, txData, txParams)
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
logger("Receipt from updateEntity %o", receipt)
|
|
42
45
|
|
|
43
46
|
return {
|
|
44
|
-
txHash: receipt.transactionHash,
|
|
47
|
+
txHash: receipt.transactionHash as Hash,
|
|
45
48
|
entityKey: receipt.logs[0].topics[1] as Hex,
|
|
46
49
|
}
|
|
47
50
|
}
|
|
@@ -183,7 +183,7 @@ export type WalletArkivActions<
|
|
|
183
183
|
* Mutates the entities with the given keys.
|
|
184
184
|
*
|
|
185
185
|
* - Docs: https://docs.arkiv.network/ts-sdk/actions/wallet/mutateEntities
|
|
186
|
-
* - JSON-RPC Methods: [`
|
|
186
|
+
* - JSON-RPC Methods: [`eth_sendRawTransaction`](https://docs.arkiv.network/dev/json-rpc-api/#mutateEntities)
|
|
187
187
|
*
|
|
188
188
|
* @param args - {data}
|
|
189
189
|
* @returns The entity with the given key. {@link Entity}
|