@arkiv-network/sdk 0.1.1-dev.0 → 0.1.3-dev.0

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.
Files changed (58) hide show
  1. package/README.md +22 -10
  2. package/dist/chains/index.d.ts +25 -25
  3. package/dist/chains/index.d.ts.map +1 -1
  4. package/dist/index.cjs +30 -9
  5. package/dist/index.js +30 -16
  6. package/dist/index.js.map +1 -1
  7. package/dist/utils/index.d.ts.map +1 -1
  8. package/package.json +22 -8
  9. package/src/accounts/index.ts +1 -0
  10. package/src/actions/public/buildQuery.ts +6 -0
  11. package/src/actions/public/getBlockTiming.ts +20 -0
  12. package/src/actions/public/getEntity.ts +18 -0
  13. package/src/actions/public/getEntityCount.ts +10 -0
  14. package/src/actions/public/query.ts +13 -0
  15. package/src/actions/public/subscribeEntityEvents.ts +105 -0
  16. package/src/actions/wallet/changeOwnership.ts +40 -0
  17. package/src/actions/wallet/createEntity.ts +45 -0
  18. package/src/actions/wallet/deleteEntity.ts +39 -0
  19. package/src/actions/wallet/extendEntity.ts +41 -0
  20. package/src/actions/wallet/mutateEntities.ts +100 -0
  21. package/src/actions/wallet/updateEntity.ts +47 -0
  22. package/src/chains/index.ts +3 -0
  23. package/src/chains/kaolin.ts +26 -0
  24. package/src/chains/localhost.ts +14 -0
  25. package/src/chains/marketplace.ts +26 -0
  26. package/src/clients/baseClient.ts +9 -0
  27. package/src/clients/createPublicClient.test.ts +22 -0
  28. package/src/clients/createPublicClient.ts +65 -0
  29. package/src/clients/createWalletClient.test.ts +23 -0
  30. package/src/clients/createWalletClient.ts +70 -0
  31. package/src/clients/decorators/arkivPublic.ts +203 -0
  32. package/src/clients/decorators/arkivWallet.ts +250 -0
  33. package/src/consts.ts +2 -0
  34. package/src/index.ts +21 -0
  35. package/src/query/engine.test.ts +288 -0
  36. package/src/query/engine.ts +112 -0
  37. package/src/query/errors.ts +23 -0
  38. package/src/query/index.ts +4 -0
  39. package/src/query/predicate.test.ts +418 -0
  40. package/src/query/predicate.ts +140 -0
  41. package/src/query/queryBuilder.test.ts +537 -0
  42. package/src/query/queryBuilder.ts +209 -0
  43. package/src/query/queryResult.test.ts +270 -0
  44. package/src/query/queryResult.ts +61 -0
  45. package/src/types/attributes.ts +4 -0
  46. package/src/types/entity.ts +36 -0
  47. package/src/types/events.ts +34 -0
  48. package/src/types/index.ts +4 -0
  49. package/src/types/mimeTypes.ts +27 -0
  50. package/src/types/rpcSchema.ts +61 -0
  51. package/src/types/txParams.ts +15 -0
  52. package/src/utils/arkivTransactions.ts +100 -0
  53. package/src/utils/compression.test.ts +32 -0
  54. package/src/utils/compression.ts +99 -0
  55. package/src/utils/entities.ts +23 -0
  56. package/src/utils/expirationTime.ts +13 -0
  57. package/src/utils/index.ts +3 -0
  58. package/src/utils/payload.ts +9 -0
@@ -0,0 +1,418 @@
1
+ import { describe, expect, test } from "bun:test"
2
+ import { and, eq, gt, gte, lt, lte, neq, not, or, type Predicate } from "./predicate"
3
+
4
+ describe("Predicate Factory Functions", () => {
5
+ describe("eq()", () => {
6
+ test("creates equality predicate with string value", () => {
7
+ const result = eq("name", "john")
8
+
9
+ expect(result).toEqual({
10
+ type: "eq",
11
+ key: "name",
12
+ value: "john",
13
+ })
14
+ })
15
+
16
+ test("creates equality predicate with numeric value", () => {
17
+ const result = eq("age", 25)
18
+
19
+ expect(result).toEqual({
20
+ type: "eq",
21
+ key: "age",
22
+ value: 25,
23
+ })
24
+ })
25
+
26
+ test("creates equality predicate with zero", () => {
27
+ const result = eq("count", 0)
28
+
29
+ expect(result).toEqual({
30
+ type: "eq",
31
+ key: "count",
32
+ value: 0,
33
+ })
34
+ })
35
+
36
+ test("creates equality predicate with empty string", () => {
37
+ const result = eq("name", "")
38
+
39
+ expect(result).toEqual({
40
+ type: "eq",
41
+ key: "name",
42
+ value: "",
43
+ })
44
+ })
45
+ })
46
+
47
+ describe("neq()", () => {
48
+ test("creates not equal predicate with string value", () => {
49
+ const result = neq("status", "inactive")
50
+
51
+ expect(result).toEqual({
52
+ type: "neq",
53
+ key: "status",
54
+ value: "inactive",
55
+ })
56
+ })
57
+
58
+ test("creates not equal predicate with numeric value", () => {
59
+ const result = neq("count", 0)
60
+
61
+ expect(result).toEqual({
62
+ type: "neq",
63
+ key: "count",
64
+ value: 0,
65
+ })
66
+ })
67
+ })
68
+
69
+ describe("gt()", () => {
70
+ test("creates greater than predicate with numeric value", () => {
71
+ const result = gt("age", 18)
72
+
73
+ expect(result).toEqual({
74
+ type: "gt",
75
+ key: "age",
76
+ value: 18,
77
+ })
78
+ })
79
+
80
+ test("creates greater than predicate with negative number", () => {
81
+ const result = gt("balance", -100)
82
+
83
+ expect(result).toEqual({
84
+ type: "gt",
85
+ key: "balance",
86
+ value: -100,
87
+ })
88
+ })
89
+
90
+ test("creates greater than predicate with string value", () => {
91
+ const result = gt("name", "abc")
92
+
93
+ expect(result).toEqual({
94
+ type: "gt",
95
+ key: "name",
96
+ value: "abc",
97
+ })
98
+ })
99
+ })
100
+
101
+ describe("gte()", () => {
102
+ test("creates greater than or equal predicate with numeric value", () => {
103
+ const result = gte("age", 18)
104
+
105
+ expect(result).toEqual({
106
+ type: "gte",
107
+ key: "age",
108
+ value: 18,
109
+ })
110
+ })
111
+
112
+ test("creates greater than or equal predicate with negative number", () => {
113
+ const result = gte("temperature", -10)
114
+
115
+ expect(result).toEqual({
116
+ type: "gte",
117
+ key: "temperature",
118
+ value: -10,
119
+ })
120
+ })
121
+
122
+ test("creates greater than or equal predicate with string value", () => {
123
+ const result = gte("version", "1.0.0")
124
+
125
+ expect(result).toEqual({
126
+ type: "gte",
127
+ key: "version",
128
+ value: "1.0.0",
129
+ })
130
+ })
131
+ })
132
+
133
+ describe("lt()", () => {
134
+ test("creates less than predicate with numeric value", () => {
135
+ const result = lt("age", 65)
136
+
137
+ expect(result).toEqual({
138
+ type: "lt",
139
+ key: "age",
140
+ value: 65,
141
+ })
142
+ })
143
+
144
+ test("creates less than predicate with string value", () => {
145
+ const result = lt("priority", "high")
146
+
147
+ expect(result).toEqual({
148
+ type: "lt",
149
+ key: "priority",
150
+ value: "high",
151
+ })
152
+ })
153
+ })
154
+
155
+ describe("lte()", () => {
156
+ test("creates less than or equal predicate with numeric value", () => {
157
+ const result = lte("score", 100)
158
+
159
+ expect(result).toEqual({
160
+ type: "lte",
161
+ key: "score",
162
+ value: 100,
163
+ })
164
+ })
165
+
166
+ test("creates less than or equal predicate with string value", () => {
167
+ const result = lte("date", "2023-12-31")
168
+
169
+ expect(result).toEqual({
170
+ type: "lte",
171
+ key: "date",
172
+ value: "2023-12-31",
173
+ })
174
+ })
175
+ })
176
+
177
+ describe("not()", () => {
178
+ test("creates not predicate", () => {
179
+ const result = not("deleted")
180
+
181
+ expect(result).toEqual({
182
+ type: "not",
183
+ key: "deleted",
184
+ value: "",
185
+ })
186
+ })
187
+
188
+ test("creates not predicate with different key", () => {
189
+ const result = not("archived")
190
+
191
+ expect(result).toEqual({
192
+ type: "not",
193
+ key: "archived",
194
+ value: "",
195
+ })
196
+ })
197
+ })
198
+
199
+ describe("or()", () => {
200
+ test("creates or predicate with two simple predicates", () => {
201
+ const predicates = [eq("type", "admin"), eq("type", "moderator")]
202
+ const result = or(predicates)
203
+
204
+ expect(result).toEqual({
205
+ type: "or",
206
+ predicates: [
207
+ { type: "eq", key: "type", value: "admin" },
208
+ { type: "eq", key: "type", value: "moderator" },
209
+ ],
210
+ })
211
+ })
212
+
213
+ test("creates or predicate with mixed predicate types", () => {
214
+ const predicates = [eq("status", "active"), gte("score", 100), neq("role", "guest")]
215
+ const result = or(predicates)
216
+
217
+ expect(result).toEqual({
218
+ type: "or",
219
+ predicates: [
220
+ { type: "eq", key: "status", value: "active" },
221
+ { type: "gte", key: "score", value: 100 },
222
+ { type: "neq", key: "role", value: "guest" },
223
+ ],
224
+ })
225
+ })
226
+
227
+ test("creates or predicate with single predicate", () => {
228
+ const predicates = [eq("enabled", 1)]
229
+ const result = or(predicates)
230
+
231
+ expect(result).toEqual({
232
+ type: "or",
233
+ predicates: [{ type: "eq", key: "enabled", value: 1 }],
234
+ })
235
+ })
236
+
237
+ test("creates or predicate with empty array", () => {
238
+ const predicates: Predicate[] = []
239
+ const result = or(predicates)
240
+
241
+ expect(result).toEqual({
242
+ type: "or",
243
+ predicates: [],
244
+ })
245
+ })
246
+
247
+ test("creates or predicate with nested and", () => {
248
+ const nestedAnd = and([eq("verified", 1), gte("age", 18)])
249
+ const predicates = [eq("status", "premium"), nestedAnd]
250
+ const result = or(predicates)
251
+
252
+ expect(result).toEqual({
253
+ type: "or",
254
+ predicates: [
255
+ { type: "eq", key: "status", value: "premium" },
256
+ {
257
+ type: "and",
258
+ predicates: [
259
+ { type: "eq", key: "verified", value: 1 },
260
+ { type: "gte", key: "age", value: 18 },
261
+ ],
262
+ },
263
+ ],
264
+ })
265
+ })
266
+ })
267
+
268
+ describe("and()", () => {
269
+ test("creates and predicate with two simple predicates", () => {
270
+ const predicates = [eq("status", "active"), eq("verified", 1)]
271
+ const result = and(predicates)
272
+
273
+ expect(result).toEqual({
274
+ type: "and",
275
+ predicates: [
276
+ { type: "eq", key: "status", value: "active" },
277
+ { type: "eq", key: "verified", value: 1 },
278
+ ],
279
+ })
280
+ })
281
+
282
+ test("creates and predicate with mixed predicate types", () => {
283
+ const predicates = [eq("active", 1), gte("age", 18), lt("age", 65), neq("role", "guest")]
284
+ const result = and(predicates)
285
+
286
+ expect(result).toEqual({
287
+ type: "and",
288
+ predicates: [
289
+ { type: "eq", key: "active", value: 1 },
290
+ { type: "gte", key: "age", value: 18 },
291
+ { type: "lt", key: "age", value: 65 },
292
+ { type: "neq", key: "role", value: "guest" },
293
+ ],
294
+ })
295
+ })
296
+
297
+ test("creates and predicate with single predicate", () => {
298
+ const predicates = [eq("enabled", 1)]
299
+ const result = and(predicates)
300
+
301
+ expect(result).toEqual({
302
+ type: "and",
303
+ predicates: [{ type: "eq", key: "enabled", value: 1 }],
304
+ })
305
+ })
306
+
307
+ test("creates and predicate with empty array", () => {
308
+ const predicates: Predicate[] = []
309
+ const result = and(predicates)
310
+
311
+ expect(result).toEqual({
312
+ type: "and",
313
+ predicates: [],
314
+ })
315
+ })
316
+
317
+ test("creates and predicate with nested or", () => {
318
+ const nestedOr = or([eq("type", "admin"), eq("type", "moderator")])
319
+ const predicates = [eq("active", 1), nestedOr]
320
+ const result = and(predicates)
321
+
322
+ expect(result).toEqual({
323
+ type: "and",
324
+ predicates: [
325
+ { type: "eq", key: "active", value: 1 },
326
+ {
327
+ type: "or",
328
+ predicates: [
329
+ { type: "eq", key: "type", value: "admin" },
330
+ { type: "eq", key: "type", value: "moderator" },
331
+ ],
332
+ },
333
+ ],
334
+ })
335
+ })
336
+ })
337
+
338
+ describe("Complex Nested Predicates", () => {
339
+ test("creates deeply nested predicate structure", () => {
340
+ const innerOr = or([eq("role", "admin"), eq("role", "moderator")])
341
+ const innerAnd = and([eq("verified", 1), gte("reputation", 1000)])
342
+ const outerOr = or([innerAnd, innerOr])
343
+ const result = and([eq("active", 1), outerOr, neq("banned", 1)])
344
+
345
+ expect(result).toEqual({
346
+ type: "and",
347
+ predicates: [
348
+ { type: "eq", key: "active", value: 1 },
349
+ {
350
+ type: "or",
351
+ predicates: [
352
+ {
353
+ type: "and",
354
+ predicates: [
355
+ { type: "eq", key: "verified", value: 1 },
356
+ { type: "gte", key: "reputation", value: 1000 },
357
+ ],
358
+ },
359
+ {
360
+ type: "or",
361
+ predicates: [
362
+ { type: "eq", key: "role", value: "admin" },
363
+ { type: "eq", key: "role", value: "moderator" },
364
+ ],
365
+ },
366
+ ],
367
+ },
368
+ { type: "neq", key: "banned", value: 1 },
369
+ ],
370
+ })
371
+ })
372
+
373
+ test("creates predicate with multiple comparison types", () => {
374
+ const result = and([
375
+ gte("age", 18),
376
+ lt("age", 65),
377
+ lte("score", 100),
378
+ neq("status", "suspended"),
379
+ not("deleted"),
380
+ ])
381
+
382
+ expect(result).toEqual({
383
+ type: "and",
384
+ predicates: [
385
+ { type: "gte", key: "age", value: 18 },
386
+ { type: "lt", key: "age", value: 65 },
387
+ { type: "lte", key: "score", value: 100 },
388
+ { type: "neq", key: "status", value: "suspended" },
389
+ { type: "not", key: "deleted", value: "" },
390
+ ],
391
+ })
392
+ })
393
+ })
394
+
395
+ describe("Type Safety", () => {
396
+ test("predicates maintain correct type information", () => {
397
+ const stringPred = eq("name", "test")
398
+ const numPred = eq("count", 42)
399
+ const orPred = or([stringPred, numPred])
400
+ const andPred = and([stringPred, numPred])
401
+
402
+ // Type assertions to ensure TypeScript types are correct
403
+ expect(stringPred.type).toBe("eq")
404
+ expect(numPred.type).toBe("eq")
405
+ expect(orPred.type).toBe("or")
406
+ expect(andPred.type).toBe("and")
407
+
408
+ // Verify container predicates have predicates array
409
+ if (orPred.type === "or" || orPred.type === "and") {
410
+ expect(Array.isArray(orPred.predicates)).toBe(true)
411
+ }
412
+
413
+ if (andPred.type === "or" || andPred.type === "and") {
414
+ expect(Array.isArray(andPred.predicates)).toBe(true)
415
+ }
416
+ })
417
+ })
418
+ })
@@ -0,0 +1,140 @@
1
+ export type PredicateType = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "not"
2
+ export type PredicateContainerType = "or" | "and"
3
+
4
+ export type Predicate =
5
+ | {
6
+ type: PredicateType
7
+ key: string
8
+ value: string | number
9
+ }
10
+ | {
11
+ type: PredicateContainerType
12
+ predicates: Predicate[]
13
+ }
14
+
15
+ /**
16
+ * Creates an OR predicate
17
+ * @param predicates - The predicates to combine
18
+ * @returns The OR predicate
19
+ *
20
+ * @example
21
+ * const predicates = [eq("name", "John"), eq("age", 30)]
22
+ * const result = or(predicates)
23
+ * // result = { type: "or", predicates: [eq("name", "John"), eq("age", 30)] }
24
+ *
25
+ */
26
+ export function or(predicates: Predicate[]): Predicate {
27
+ return { type: "or", predicates }
28
+ }
29
+
30
+ /**
31
+ * Creates an AND predicate
32
+ * @param predicates - The predicates to combine
33
+ * @returns The AND predicate
34
+ *
35
+ * @example
36
+ * const predicates = [eq("name", "John"), eq("age", 30)]
37
+ * const result = and(predicates)
38
+ * // result = { type: "and", predicates: [eq("name", "John"), eq("age", 30)] }
39
+ *
40
+ */
41
+ export function and(predicates: Predicate[]): Predicate {
42
+ return { type: "and", predicates }
43
+ }
44
+
45
+ /**
46
+ * Creates an equality predicate
47
+ * @param key - The key to compare
48
+ * @param value - The value to compare
49
+ * @returns The equality predicate
50
+ *
51
+ * @example
52
+ * const predicate = eq("name", "John")
53
+ * // result = { type: "eq", key: "name", value: "John" }
54
+ */
55
+ export function eq(key: string, value: string | number): Predicate {
56
+ return { type: "eq", key, value }
57
+ }
58
+
59
+ /**
60
+ * Creates a not equal predicate
61
+ * @param key - The key to compare
62
+ * @param value - The value to compare
63
+ * @returns The not equal predicate
64
+ *
65
+ * @example
66
+ * const predicate = neq("name", "John")
67
+ * // result = { type: "neq", key: "name", value: "John" }
68
+ */
69
+ export function neq(key: string, value: string | number): Predicate {
70
+ return { type: "neq", key, value }
71
+ }
72
+
73
+ /**
74
+ * Creates a greater than predicate
75
+ * @param key - The key to compare
76
+ * @param value - The value to compare
77
+ * @returns The greater than predicate
78
+ *
79
+ * @example
80
+ * const predicate = gt("name", "John")
81
+ * // result = { type: "gt", key: "name", value: "John" }
82
+ */
83
+ export function gt(key: string, value: string | number): Predicate {
84
+ return { type: "gt", key, value }
85
+ }
86
+
87
+ /**
88
+ * Creates a greater than or equal predicate
89
+ * @param key - The key to compare
90
+ * @param value - The value to compare
91
+ * @returns The greater than or equal predicate
92
+ *
93
+ * @example
94
+ * const predicate = gte("name", "John")
95
+ * // result = { type: "gte", key: "name", value: "John" }
96
+ */
97
+ export function gte(key: string, value: string | number): Predicate {
98
+ return { type: "gte", key, value }
99
+ }
100
+
101
+ /**
102
+ * Creates a less than predicate
103
+ * @param key - The key to compare
104
+ * @param value - The value to compare
105
+ * @returns The less than predicate
106
+ *
107
+ * @example
108
+ * const predicate = lt("name", "John")
109
+ * // result = { type: "lt", key: "name", value: "John" }
110
+ */
111
+ export function lt(key: string, value: string | number): Predicate {
112
+ return { type: "lt", key, value }
113
+ }
114
+
115
+ /**
116
+ * Creates a less than or equal predicate
117
+ * @param key - The key to compare
118
+ * @param value - The value to compare
119
+ * @returns The less than or equal predicate
120
+ *
121
+ * @example
122
+ * const predicate = lte("name", "John")
123
+ * // result = { type: "lte", key: "name", value: "John" }
124
+ */
125
+ export function lte(key: string, value: string | number): Predicate {
126
+ return { type: "lte", key, value }
127
+ }
128
+
129
+ /**
130
+ * Creates a not predicate
131
+ * @param key - The key to compare
132
+ * @returns The not predicate
133
+ *
134
+ * @example
135
+ * const predicate = not("name")
136
+ * // result = { type: "not", key: "name", value: "" }
137
+ */
138
+ export function not(key: string): Predicate {
139
+ return { type: "not", key, value: "" }
140
+ }