@arkiv-network/sdk 0.8.1-dev.1 → 0.9.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -61
- package/dist/chains/index.d.ts +17 -17
- package/dist/changeOwnership-Cy9gfyjN.d.cts +1160 -0
- package/dist/changeOwnership-Cy9gfyjN.d.cts.map +1 -0
- package/dist/changeOwnership-gXf-lBqI.d.ts +1160 -0
- package/dist/changeOwnership-gXf-lBqI.d.ts.map +1 -0
- package/dist/entity/index.cjs +4 -10
- package/dist/entity/index.d.cts +3 -3
- package/dist/entity/index.d.ts +3 -3
- package/dist/entity/index.js +3 -4
- package/dist/entity-BM1unrQf.cjs +41 -0
- package/dist/{entity-DJ0Gml9c.cjs → entity-BgaFJSaV.cjs} +4 -4
- package/dist/entity-CFAI1KyG.js +36 -0
- package/dist/entity-CFAI1KyG.js.map +1 -0
- package/dist/{entity-CniBgBSd.js → entity-CGqx_AU0.js} +4 -4
- package/dist/entity-CGqx_AU0.js.map +1 -0
- package/dist/{payload-AfUfSctb.d.ts → expirationTime-C7PZK49K.d.ts} +8 -37
- package/dist/expirationTime-C7PZK49K.d.ts.map +1 -0
- package/dist/expirationTime-CkIGNAg8.cjs +140 -0
- package/dist/{payload-D167BlJR.d.cts → expirationTime-DOB8V4B8.d.cts} +8 -37
- package/dist/expirationTime-DOB8V4B8.d.cts.map +1 -0
- package/dist/{expiry-Cgdb_dbq.js → expirationTime-UKPuA-LM.js} +62 -27
- package/dist/expirationTime-UKPuA-LM.js.map +1 -0
- package/dist/expiry-B48I-yTA.d.cts +40 -0
- package/dist/expiry-B48I-yTA.d.cts.map +1 -0
- package/dist/expiry-S2PUL8Hg.d.ts +40 -0
- package/dist/expiry-S2PUL8Hg.d.ts.map +1 -0
- package/dist/index-C-mMF5WZ.d.cts +735 -0
- package/dist/index-C-mMF5WZ.d.cts.map +1 -0
- package/dist/{index-BkqSnGJH.d.ts → index-C4zZqJ9S.d.ts} +5 -27
- package/dist/index-C4zZqJ9S.d.ts.map +1 -0
- package/dist/{index-CLhsFyVH.d.cts → index-CcVWYB6v.d.cts} +5 -27
- package/dist/index-CcVWYB6v.d.cts.map +1 -0
- package/dist/index-DCx2XC6S.d.ts +489 -0
- package/dist/index-DCx2XC6S.d.ts.map +1 -0
- package/dist/index-DLb7BfIw.d.ts +735 -0
- package/dist/index-DLb7BfIw.d.ts.map +1 -0
- package/dist/index-DzriOUm8.d.cts +489 -0
- package/dist/index-DzriOUm8.d.cts.map +1 -0
- package/dist/index.cjs +162 -146
- package/dist/index.d.cts +180 -133
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +180 -133
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -83
- package/dist/index.js.map +1 -1
- package/dist/params-BuIrJA9a.cjs +45 -0
- package/dist/params-DDJOnsNi.js +22 -0
- package/dist/params-DDJOnsNi.js.map +1 -0
- package/dist/query/index.cjs +9 -4
- package/dist/query/index.d.cts +6 -6
- package/dist/query/index.d.ts +6 -6
- package/dist/query/index.js +4 -5
- package/dist/query-D0KtuFh2.cjs +1625 -0
- package/dist/query-DpRDozmj.js +1417 -0
- package/dist/query-DpRDozmj.js.map +1 -0
- package/dist/schema/index.cjs +46 -0
- package/dist/schema/index.d.cts +2 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +3 -0
- package/dist/{attr-BXTkpnoc.cjs → schema-B9AyXcgU.cjs} +513 -246
- package/dist/{attr-tmyREHtw.js → schema-DY4sqehl.js} +427 -244
- package/dist/schema-DY4sqehl.js.map +1 -0
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.d.cts +5 -5
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.js +1 -1
- package/dist/utils/index.cjs +3 -5
- package/dist/utils/index.d.cts +3 -3
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/package.json +9 -12
- package/src/actions/public/getEntity.test.ts +69 -0
- package/src/actions/public/getEntity.ts +34 -20
- package/src/actions/public/predictEntityKeys.ts +8 -7
- package/src/actions/public/query.test.ts +58 -0
- package/src/actions/public/query.ts +41 -13
- package/src/actions/wallet/createEntity.ts +34 -63
- package/src/actions/wallet/executeBatch.test.ts +38 -0
- package/src/actions/wallet/executeBatch.ts +26 -9
- package/src/actions/wallet/extendEntity.ts +9 -8
- package/src/actions/wallet/patchEntity.ts +43 -52
- package/src/clients/createPublicClient.test.ts +10 -2
- package/src/clients/createWalletClient.ts +4 -1
- package/src/clients/decorators/arkivPublic.ts +123 -80
- package/src/clients/decorators/arkivWallet.ts +113 -65
- package/src/entity/create.test.ts +25 -21
- package/src/entity/expiry.ts +8 -6
- package/src/entity/flags.ts +1 -1
- package/src/entity/index.ts +2 -4
- package/src/entity/key.ts +3 -3
- package/src/entity/operations.ts +1 -1
- package/src/errors.ts +2 -11
- package/src/index.ts +18 -6
- package/src/query/builderBase.ts +166 -0
- package/src/query/countBuilder.test.ts +91 -0
- package/src/query/countBuilder.ts +67 -0
- package/src/query/engine.ts +9 -3
- package/src/query/errors.ts +24 -14
- package/src/query/expression.test.ts +129 -21
- package/src/query/expression.ts +323 -94
- package/src/query/index.ts +26 -4
- package/src/query/injection.test.ts +5 -11
- package/src/query/queryBuilder.test.ts +467 -58
- package/src/query/queryBuilder.ts +191 -98
- package/src/query/queryResult.ts +35 -9
- package/src/query/selection.test.ts +278 -24
- package/src/query/selection.ts +427 -86
- package/src/schema/attributes.test.ts +266 -0
- package/src/schema/attributes.ts +212 -0
- package/src/{attr → schema}/codec.test.ts +37 -5
- package/src/{attr → schema}/codec.ts +40 -11
- package/src/schema/column.ts +193 -0
- package/src/{attr → schema}/errors.ts +67 -10
- package/src/schema/index.ts +76 -0
- package/src/{attr → schema}/names.ts +4 -2
- package/src/schema/schema.test.ts +171 -0
- package/src/schema/schema.ts +250 -0
- package/src/{attr → schema}/types.ts +36 -30
- package/src/{attr → schema}/values.test.ts +62 -3
- package/src/{attr → schema}/values.ts +246 -65
- package/src/types/entity.test.ts +1 -44
- package/src/types/entity.ts +9 -55
- package/src/types/events.ts +1 -1
- package/src/types/index.ts +11 -4
- package/src/types/rpcSchema.ts +22 -16
- package/src/utils/arkivTransactions.test.ts +356 -116
- package/src/utils/arkivTransactions.ts +30 -38
- package/src/utils/entities.ts +10 -9
- package/src/utils/expirationTime.ts +5 -5
- package/src/utils/index.ts +0 -1
- package/src/utils/logger.test.ts +45 -0
- package/src/utils/logger.ts +5 -39
- package/src/utils/revert.test.ts +25 -0
- package/src/utils/revert.ts +28 -3
- package/dist/attr/index.cjs +0 -34
- package/dist/attr/index.d.cts +0 -2
- package/dist/attr/index.d.ts +0 -2
- package/dist/attr/index.js +0 -3
- package/dist/attr-tmyREHtw.js.map +0 -1
- package/dist/entity-B0t6sN7F.cjs +0 -71
- package/dist/entity-BIp_df9u.js +0 -67
- package/dist/entity-BIp_df9u.js.map +0 -1
- package/dist/entity-CniBgBSd.js.map +0 -1
- package/dist/expiry-BxOlvVWC.d.ts +0 -79
- package/dist/expiry-BxOlvVWC.d.ts.map +0 -1
- package/dist/expiry-CG9GhVXv.cjs +0 -135
- package/dist/expiry-Cgdb_dbq.js.map +0 -1
- package/dist/expiry-DRV29F1r.d.cts +0 -79
- package/dist/expiry-DRV29F1r.d.cts.map +0 -1
- package/dist/flags-DCD26uhe.cjs +0 -43
- package/dist/flags-DUT2gHEU.js +0 -33
- package/dist/flags-DUT2gHEU.js.map +0 -1
- package/dist/index-BkqSnGJH.d.ts.map +0 -1
- package/dist/index-C7fbakoI.d.cts +0 -278
- package/dist/index-C7fbakoI.d.cts.map +0 -1
- package/dist/index-CIcHPx2j.d.cts +0 -424
- package/dist/index-CIcHPx2j.d.cts.map +0 -1
- package/dist/index-CLhsFyVH.d.cts.map +0 -1
- package/dist/index-Cd2aaWme.d.ts +0 -424
- package/dist/index-Cd2aaWme.d.ts.map +0 -1
- package/dist/index-Cq6fa8AI.d.ts +0 -278
- package/dist/index-Cq6fa8AI.d.ts.map +0 -1
- package/dist/index-DaNeJUw8.d.ts +0 -955
- package/dist/index-DaNeJUw8.d.ts.map +0 -1
- package/dist/index-Dv16LO2s.d.cts +0 -955
- package/dist/index-Dv16LO2s.d.cts.map +0 -1
- package/dist/payload-AfUfSctb.d.ts.map +0 -1
- package/dist/payload-D167BlJR.d.cts.map +0 -1
- package/dist/payload-DE7wMztL.js +0 -92
- package/dist/payload-DE7wMztL.js.map +0 -1
- package/dist/payload-DqFweqiO.cjs +0 -108
- package/dist/query-9oojUdM7.cjs +0 -1128
- package/dist/query-Ber-lOJQ.js +0 -968
- package/dist/query-Ber-lOJQ.js.map +0 -1
- package/src/actions/public/getEntityCount.ts +0 -10
- package/src/attr/attributes.test.ts +0 -120
- package/src/attr/attributes.ts +0 -196
- package/src/attr/index.ts +0 -50
- package/src/types/mimeTypes.ts +0 -27
- package/src/utils/compression.test.ts +0 -32
- package/src/utils/compression.ts +0 -102
- package/src/utils/payload.ts +0 -36
- /package/src/{attr → schema}/decimal.ts +0 -0
|
@@ -0,0 +1,1160 @@
|
|
|
1
|
+
import { c as ResolvedCreationFlags, i as SaltInput, s as CreationFlags } from "./index-C4zZqJ9S.js";
|
|
2
|
+
import { t as Expiry } from "./expiry-S2PUL8Hg.js";
|
|
3
|
+
import { C as IndexedColumnName, E as PatchEntityValues, O as Schema, R as TagOf, S as CreateEntityValues, T as OptionalColumnName, _ as Attributes, _t as TypeTag, bt as ValueOf, g as AttributeSchema, gt as StrValue, mt as IndexableValue, ot as ArkivValue, pt as IndexableTypeTag, tt as AnyColumn, x as ColumnsOf } from "./index-DLb7BfIw.js";
|
|
4
|
+
import { Account, Address, Chain, Client, Hash, Hex, RpcSchema, Transport } from "viem";
|
|
5
|
+
|
|
6
|
+
//#region src/types/rpcSchema.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An attribute as the node renders it: the name, the type **tag** (not the wire typeId), and the
|
|
10
|
+
* value in the JSON encoding that type prescribes — a JSON number for `i32`, a `0x` QUANTITY for
|
|
11
|
+
* `u64` and `u256`, a decimal string for `dec`, `0x` DATA for the byte-shaped types (`bytes`
|
|
12
|
+
* included), and a string for `str`.
|
|
13
|
+
*
|
|
14
|
+
* The encoding follows the *declared type*, never the magnitude, so a decoder dispatches on `type`
|
|
15
|
+
* and never has to guess from the shape of the value.
|
|
16
|
+
*/
|
|
17
|
+
type RpcAttribute = {
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
value: unknown;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* An entry of the `attributeSchema` projection — a name, its type, and whether the node indexes
|
|
24
|
+
* it, with no value.
|
|
25
|
+
*/
|
|
26
|
+
type RpcAttributeSchemaEntry = {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
indexed?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The `creationFlags` projection.
|
|
33
|
+
*/
|
|
34
|
+
type RpcCreationFlags = {
|
|
35
|
+
readonly?: boolean;
|
|
36
|
+
permissionlessExtension?: boolean;
|
|
37
|
+
raw: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* An entity as `arkiv_query` returns it. Every field is present only if it was selected, so all of
|
|
41
|
+
* them are optional here — {@link RpcSelect} is what decides which arrive.
|
|
42
|
+
*/
|
|
43
|
+
type RpcEntity = {
|
|
44
|
+
key?: Hex;
|
|
45
|
+
owner?: Hex;
|
|
46
|
+
creator?: Hex;
|
|
47
|
+
createdAt?: Hex;
|
|
48
|
+
updatedAt?: Hex;
|
|
49
|
+
expiresAt?: Hex;
|
|
50
|
+
creationFlags?: RpcCreationFlags | number;
|
|
51
|
+
attributeSchema?: RpcAttributeSchemaEntry[];
|
|
52
|
+
attributes?: RpcAttribute[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The `select` projection: flat, per-field booleans. Everything except `key` defaults to **off**,
|
|
56
|
+
* so a query asks for exactly what it needs and nothing more.
|
|
57
|
+
*
|
|
58
|
+
* `attributes` is the one field with a third form: `true` for every attribute, or a map of names
|
|
59
|
+
* for a subset.
|
|
60
|
+
*/
|
|
61
|
+
type RpcSelect = {
|
|
62
|
+
key?: boolean;
|
|
63
|
+
owner?: boolean;
|
|
64
|
+
creator?: boolean;
|
|
65
|
+
createdAt?: boolean;
|
|
66
|
+
updatedAt?: boolean;
|
|
67
|
+
expiresAt?: boolean;
|
|
68
|
+
creationFlags?: boolean;
|
|
69
|
+
attributeSchema?: boolean;
|
|
70
|
+
attributes?: boolean | Record<string, boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Not a field of each entity but of the page: the number of entities the query matches at the
|
|
73
|
+
* block, regardless of `limit` and `cursor`, returned as the response's `count`.
|
|
74
|
+
*/
|
|
75
|
+
count?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/** The second parameter of `arkiv_query` — what to return, and where in the results to start. */
|
|
78
|
+
type RpcQueryOptions = {
|
|
79
|
+
/** Block height to read at, as a hex quantity. Defaults to the head, and must be within the node's retained range. */
|
|
80
|
+
atBlock?: Hex;
|
|
81
|
+
/** What to return. Defaults to `{ key: true }`. */
|
|
82
|
+
select?: RpcSelect;
|
|
83
|
+
/** Page size, as a hex quantity. Node maximum is 100. */
|
|
84
|
+
limit?: Hex;
|
|
85
|
+
/** Opaque cursor from a previous response; bound to that query, block and selection. */
|
|
86
|
+
cursor?: string;
|
|
87
|
+
};
|
|
88
|
+
type ArkivRpcSchema = [{
|
|
89
|
+
Method: "arkiv_query";
|
|
90
|
+
Parameters?: [query: string, queryOptions?: RpcQueryOptions];
|
|
91
|
+
ReturnType: {
|
|
92
|
+
data: RpcEntity[];
|
|
93
|
+
blockNumber: Hex;
|
|
94
|
+
/** Omitted when no pages remain. */
|
|
95
|
+
cursor?: string;
|
|
96
|
+
/** How many entities the query matches, as a hex quantity. Present only when selected. */
|
|
97
|
+
count?: Hex;
|
|
98
|
+
};
|
|
99
|
+
}, {
|
|
100
|
+
Method: "arkiv_getEntity";
|
|
101
|
+
Parameters: [entityKey: Hex];
|
|
102
|
+
/** Every field except `attributeSchema`, or `null` if no live entity has the key. */
|
|
103
|
+
ReturnType: RpcEntity | null;
|
|
104
|
+
}, {
|
|
105
|
+
Method: "arkiv_getBlockTiming";
|
|
106
|
+
Parameters?: [];
|
|
107
|
+
ReturnType: {
|
|
108
|
+
current_block: bigint;
|
|
109
|
+
current_block_time: number;
|
|
110
|
+
duration: number;
|
|
111
|
+
};
|
|
112
|
+
}];
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/clients/baseClient.d.ts
|
|
115
|
+
type ArkivClient<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, accountOrAddress extends Account | undefined = Account | undefined, rpcSchema extends RpcSchema | undefined = ArkivRpcSchema> = Client<transport, chain, accountOrAddress, rpcSchema>;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/actions/public/getBlockTiming.d.ts
|
|
118
|
+
type GetBlockTimingReturnType = {
|
|
119
|
+
currentBlock: bigint;
|
|
120
|
+
currentBlockTime: number;
|
|
121
|
+
blockDuration: number;
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/actions/public/predictEntityKeys.d.ts
|
|
125
|
+
/**
|
|
126
|
+
* A key a create will be given, together with the salt that mints it.
|
|
127
|
+
*
|
|
128
|
+
* The two travel as a pair because neither is any use alone: a create defaults to a *random* salt,
|
|
129
|
+
* so the key only comes out as predicted if that same create carries this salt.
|
|
130
|
+
*/
|
|
131
|
+
type PredictedEntityKey = {
|
|
132
|
+
/** The key the create will be given. */
|
|
133
|
+
key: Hex;
|
|
134
|
+
/**
|
|
135
|
+
* The salt the create must carry for its key to come out as {@link PredictedEntityKey.key}.
|
|
136
|
+
* Always a plain `uint128` — a requested {@link NO_SALT} comes back as the `0n` it resolves to,
|
|
137
|
+
* which a create accepts just the same.
|
|
138
|
+
*/
|
|
139
|
+
salt: bigint;
|
|
140
|
+
};
|
|
141
|
+
/** Parameters for `client.predictEntityKeys`. */
|
|
142
|
+
type PredictEntityKeysParameters<TCount extends number = number, TSalts extends readonly SaltInput[] | undefined = readonly SaltInput[] | undefined> = {
|
|
143
|
+
/** The account that will sign the creates. Its nonce is what the keys are derived from. */
|
|
144
|
+
owner: Address;
|
|
145
|
+
/**
|
|
146
|
+
* How many creates the batch will carry. Ignored when `salts` is given, which already says how
|
|
147
|
+
* many there are.
|
|
148
|
+
*
|
|
149
|
+
* A literal count comes back as a fixed-length tuple, so `count: 2` destructures into two named
|
|
150
|
+
* pairs without a cast.
|
|
151
|
+
*/
|
|
152
|
+
count?: TCount | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* The salt each create will carry, in batch order. Defaults to `count` fresh random salts —
|
|
155
|
+
* either way each key comes back paired with the salt that mints it. Pass {@link NO_SALT} in a
|
|
156
|
+
* slot whose create opts out of salting.
|
|
157
|
+
*/
|
|
158
|
+
salts?: TSalts;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* The keys a batch would mint, in batch order, each paired with its salt.
|
|
162
|
+
*
|
|
163
|
+
* The length follows the request whenever it is known statically: a literal `count`, or a `salts`
|
|
164
|
+
* tuple, gives a fixed-length tuple; a count computed at runtime gives a plain array.
|
|
165
|
+
*
|
|
166
|
+
* `TSalts` is wrapped in a tuple to stop the conditional distributing over it. Left naked, the
|
|
167
|
+
* `readonly SaltInput[] | undefined` default would take both branches and union a tuple with an
|
|
168
|
+
* array, which widens the length straight back to `number`.
|
|
169
|
+
*/
|
|
170
|
+
type PredictEntityKeysReturnType<TCount extends number = number, TSalts extends readonly SaltInput[] | undefined = readonly SaltInput[] | undefined> = [TSalts] extends [readonly SaltInput[]] ? { -readonly [Index in keyof TSalts]: PredictedEntityKey } : Repeat<PredictedEntityKey, TCount>;
|
|
171
|
+
/**
|
|
172
|
+
* A tuple of `TLength` × `T`, or a plain array when the length is only known at runtime.
|
|
173
|
+
*
|
|
174
|
+
* Written tail-recursively so TypeScript can build the batch sizes anyone would actually send.
|
|
175
|
+
*/
|
|
176
|
+
type Repeat<T$1, TLength extends number, TAcc extends T$1[] = []> = number extends TLength ? T$1[] : TAcc["length"] extends TLength ? TAcc : Repeat<T$1, TLength, [...TAcc, T$1]>;
|
|
177
|
+
/**
|
|
178
|
+
* Works out the keys an account's next creates will be given, before sending them.
|
|
179
|
+
*
|
|
180
|
+
* A key is `keccak256(chainId ++ registry ++ owner ++ nonce ++ salt)`. Everything but the nonce is
|
|
181
|
+
* known to the caller, and the nonce is read here — so a batch can reference a key it is about to
|
|
182
|
+
* mint, storing it as a `key` attribute on a sibling entity created in the same transaction.
|
|
183
|
+
*
|
|
184
|
+
* Each key arrives paired with its salt, and the create must be given that salt: a create left to
|
|
185
|
+
* pick its own salt picks a random one, which mints a different key.
|
|
186
|
+
*
|
|
187
|
+
* The prediction is valid only while nothing else from this owner is in flight. Every create that
|
|
188
|
+
* lands first takes the nonce with it and moves these keys. For a key you can rely on
|
|
189
|
+
* unconditionally, read it back from the create instead — `createEntity` and `executeBatch`
|
|
190
|
+
* report the keys the engine actually minted.
|
|
191
|
+
*
|
|
192
|
+
* @param parameters - Owner, and either a count or the salts. {@link PredictEntityKeysParameters}
|
|
193
|
+
* @returns One `{ key, salt }` pair per create, in batch order. {@link PredictEntityKeysReturnType}
|
|
194
|
+
*
|
|
195
|
+
* @example A batch whose second entity points at its first.
|
|
196
|
+
* import { defineSchema, key, str } from "@arkiv-network/sdk/schema"
|
|
197
|
+
*
|
|
198
|
+
* const Nodes = defineSchema("nodes", { name: str(), parent: key().indexed().optional() })
|
|
199
|
+
*
|
|
200
|
+
* const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
|
|
201
|
+
* await wallet.executeBatch({
|
|
202
|
+
* creates: [
|
|
203
|
+
* { schema: Nodes, values: { name: "root" }, expiration, salt: parent.salt },
|
|
204
|
+
* {
|
|
205
|
+
* schema: Nodes,
|
|
206
|
+
* values: { name: "leaf", parent: key(parent.key) },
|
|
207
|
+
* expiration,
|
|
208
|
+
* salt: child.salt,
|
|
209
|
+
* },
|
|
210
|
+
* ],
|
|
211
|
+
* })
|
|
212
|
+
*/
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/query/expression.d.ts
|
|
215
|
+
/**
|
|
216
|
+
* The comparison operators the query language defines. Every indexable type accepts all of them;
|
|
217
|
+
* `<` `<=` `>` `>=` compare in index order — numerically for `i32`, `u64`, `u256` and `dec`,
|
|
218
|
+
* `false < true` for `bool`, and by unsigned bytes for `str`, `bytes32`, `addr` and `key`.
|
|
219
|
+
*/
|
|
220
|
+
type ComparisonOperator = "=" | "!=" | "<" | "<=" | ">" | ">=";
|
|
221
|
+
/**
|
|
222
|
+
* A value a predicate can compare against: a value of any indexable type, or a bare boolean,
|
|
223
|
+
* number, bigint or string. `bytes` is excluded — it is never indexed, so never filterable.
|
|
224
|
+
*/
|
|
225
|
+
type PredicateValue = IndexableValue | boolean | number | bigint | string;
|
|
226
|
+
/**
|
|
227
|
+
* `between`'s check that both bounds have one type — `unknown` when they do, and otherwise an
|
|
228
|
+
* object whose one property is named after the problem. No value has that property, so the
|
|
229
|
+
* compiler reports the sentence as the property it is missing.
|
|
230
|
+
*/
|
|
231
|
+
type SameTypeCheck<L, H> = [TagOf<L>, TagOf<H>] extends [TagOf<H>, TagOf<L>] ? unknown : { [K in `BETWEEN bounds must have one type, got ${TagOf<L>} and ${TagOf<H>}`]: never };
|
|
232
|
+
/**
|
|
233
|
+
* The attribute a predicate names, and the type it asserts — `never` when it asserts none, as
|
|
234
|
+
* `EXISTS` does. Carried by an {@link Expression} at the type level only, so a query against a
|
|
235
|
+
* schema can be checked at compile time: every name must be an indexed column, and every type the
|
|
236
|
+
* column's.
|
|
237
|
+
*/
|
|
238
|
+
type AttributeRef = {
|
|
239
|
+
readonly name: string;
|
|
240
|
+
readonly type: IndexableTypeTag;
|
|
241
|
+
};
|
|
242
|
+
declare const refs: unique symbol;
|
|
243
|
+
/** The type-level record of the attributes an expression names. Never present at runtime. */
|
|
244
|
+
type Refs<R$1 extends AttributeRef> = {
|
|
245
|
+
readonly [refs]?: R$1;
|
|
246
|
+
};
|
|
247
|
+
/** A comparison between an attribute and a typed literal. */
|
|
248
|
+
interface ComparisonNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
249
|
+
readonly kind: "comparison";
|
|
250
|
+
readonly name: string;
|
|
251
|
+
readonly operator: ComparisonOperator;
|
|
252
|
+
readonly value: IndexableValue;
|
|
253
|
+
}
|
|
254
|
+
/** An inclusive range test, `name BETWEEN low AND high`. Both bounds have one type. */
|
|
255
|
+
interface BetweenNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
256
|
+
readonly kind: "between";
|
|
257
|
+
readonly name: string;
|
|
258
|
+
readonly low: IndexableValue;
|
|
259
|
+
readonly high: IndexableValue;
|
|
260
|
+
}
|
|
261
|
+
/** A `STARTSWITH` prefix test, the language's only pattern operator. */
|
|
262
|
+
interface StartsWithNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
263
|
+
readonly kind: "startsWith";
|
|
264
|
+
readonly name: string;
|
|
265
|
+
readonly value: StrValue;
|
|
266
|
+
}
|
|
267
|
+
/** An `EXISTS(name)` test — true when the attribute is set with any type. */
|
|
268
|
+
interface ExistsNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
269
|
+
readonly kind: "exists";
|
|
270
|
+
readonly name: string;
|
|
271
|
+
}
|
|
272
|
+
/** A `TYPEOF(name) = tag` test. */
|
|
273
|
+
interface TypeOfNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
274
|
+
readonly kind: "typeOf";
|
|
275
|
+
readonly name: string;
|
|
276
|
+
readonly tag: IndexableTypeTag;
|
|
277
|
+
}
|
|
278
|
+
/** The complement of an expression, evaluated against the active-entity set. */
|
|
279
|
+
interface NotNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
280
|
+
readonly kind: "not";
|
|
281
|
+
readonly expression: Expression;
|
|
282
|
+
}
|
|
283
|
+
/** A conjunction. */
|
|
284
|
+
interface AndNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
285
|
+
readonly kind: "and";
|
|
286
|
+
readonly expressions: readonly Expression[];
|
|
287
|
+
}
|
|
288
|
+
/** A disjunction. */
|
|
289
|
+
interface OrNode<R$1 extends AttributeRef = AttributeRef> extends Refs<R$1> {
|
|
290
|
+
readonly kind: "or";
|
|
291
|
+
readonly expressions: readonly Expression[];
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* A query expression: an immutable tree built by the combinators below, whose `toString()` is the
|
|
295
|
+
* exact query string sent over the wire.
|
|
296
|
+
*
|
|
297
|
+
* @typeParam R - The attributes the expression names, as {@link AttributeRef}s — inferred by the
|
|
298
|
+
* combinators, and checked against the schema by `select(...).from(schema).where(...)`.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* const q = and(gte("level", i32(10)), or(eq("status", str("open")), not(exists("closedAt"))))
|
|
302
|
+
* String(q) // level >= i32(10) AND (status = str('open') OR NOT EXISTS(closedAt))
|
|
303
|
+
*/
|
|
304
|
+
type Expression<R$1 extends AttributeRef = AttributeRef> = ComparisonNode<R$1> | BetweenNode<R$1> | StartsWithNode<R$1> | ExistsNode<R$1> | TypeOfNode<R$1> | NotNode<R$1> | AndNode<R$1> | OrNode<R$1>;
|
|
305
|
+
/** The attributes an expression names — the `R` of an {@link Expression}. */
|
|
306
|
+
type RefsOf<E> = E extends Refs<infer R> ? Exclude<R, undefined> : never;
|
|
307
|
+
/** The reference a comparison against `V` makes to `N`. */
|
|
308
|
+
type ValueRef<N$1 extends string, V> = {
|
|
309
|
+
readonly name: N$1;
|
|
310
|
+
readonly type: TagOf<V> & IndexableTypeTag;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* The system attributes a query may filter on, and the type each one carries.
|
|
314
|
+
*
|
|
315
|
+
* Every other system attribute (`$createdAt`, `$updatedAt`, `$creationFlags`) is returned in
|
|
316
|
+
* query results — selected and read back as `createdAt`, `updatedAt` and `creationFlags` — but is
|
|
317
|
+
* not indexed, so it cannot appear in a predicate.
|
|
318
|
+
*/
|
|
319
|
+
declare const QUERYABLE_SYSTEM_ATTRIBUTES: {
|
|
320
|
+
readonly $key: "key";
|
|
321
|
+
readonly $owner: "addr";
|
|
322
|
+
readonly $creator: "addr";
|
|
323
|
+
readonly $expiresAt: "u64";
|
|
324
|
+
};
|
|
325
|
+
type SystemAttributeName = keyof typeof QUERYABLE_SYSTEM_ATTRIBUTES;
|
|
326
|
+
/** The references a filter on a system attribute makes — each with its fixed type. */
|
|
327
|
+
type SystemAttributeRef = { [N in SystemAttributeName]: {
|
|
328
|
+
readonly name: N;
|
|
329
|
+
readonly type: (typeof QUERYABLE_SYSTEM_ATTRIBUTES)[N];
|
|
330
|
+
} }[SystemAttributeName];
|
|
331
|
+
/**
|
|
332
|
+
* The references a filter through schema `S` may make: each indexed column with its declared
|
|
333
|
+
* type, and the queryable system attributes with theirs. An {@link Expression} naming anything else
|
|
334
|
+
* is a compile error in `select(...).from(S).where(...)`.
|
|
335
|
+
*/
|
|
336
|
+
type SchemaRef<S extends Schema> = { [K in IndexedColumnName<S>]: {
|
|
337
|
+
readonly name: K;
|
|
338
|
+
readonly type: ColumnsOf<S>[K]["type"] & IndexableTypeTag;
|
|
339
|
+
} }[IndexedColumnName<S>] | SystemAttributeRef;
|
|
340
|
+
/**
|
|
341
|
+
* Attribute equals value — set with this exact type, and holding this value.
|
|
342
|
+
*
|
|
343
|
+
* Bare booleans, numbers, bigints and strings take the same default types they take when written
|
|
344
|
+
* (`number` is an `i32`, `bigint` a `u256`, `string` a `str`); anything else names its type.
|
|
345
|
+
*
|
|
346
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
347
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
348
|
+
* attribute, a system attribute is compared against the wrong type, or the value is `bytes`.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* eq("status", str("open")) // status = str('open')
|
|
352
|
+
* eq("flagged", true) // flagged = true
|
|
353
|
+
* eq("$owner", addr(account)) // $owner = addr(0xd8dA…)
|
|
354
|
+
*/
|
|
355
|
+
declare function eq<N$1 extends string, V extends PredicateValue>(name: N$1, value: V): ComparisonNode<ValueRef<N$1, V>>;
|
|
356
|
+
/**
|
|
357
|
+
* Attribute is set with this type and holds a **different** value.
|
|
358
|
+
*
|
|
359
|
+
* This is typed value-negation, not the complement: an entity that never set the attribute, or set
|
|
360
|
+
* it with another type, does not match. Use `not(eq(...))` for the full complement.
|
|
361
|
+
*
|
|
362
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
363
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
364
|
+
* attribute, a system attribute is compared against the wrong type, or the value is `bytes`.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ne("status", str("closed")) // status != str('closed')
|
|
368
|
+
* not(eq("status", str("closed"))) // NOT status = str('closed') — also matches entities with no status
|
|
369
|
+
*/
|
|
370
|
+
declare function ne<N$1 extends string, V extends PredicateValue>(name: N$1, value: V): ComparisonNode<ValueRef<N$1, V>>;
|
|
371
|
+
/**
|
|
372
|
+
* Attribute is greater than value, in index order — see {@link ComparisonOperator}.
|
|
373
|
+
*
|
|
374
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
375
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
376
|
+
* attribute, a system attribute is compared against the wrong type, or the value is `bytes`.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* gt("level", i32(10)) // level > i32(10)
|
|
380
|
+
* gt("$expiresAt", u64(1_200_000n)) // $expiresAt > u64(1200000)
|
|
381
|
+
*/
|
|
382
|
+
declare function gt<N$1 extends string, V extends PredicateValue>(name: N$1, value: V): ComparisonNode<ValueRef<N$1, V>>;
|
|
383
|
+
/**
|
|
384
|
+
* Attribute is greater than or equal to value, in index order — see {@link ComparisonOperator}.
|
|
385
|
+
*
|
|
386
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
387
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
388
|
+
* attribute, a system attribute is compared against the wrong type, or the value is `bytes`.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* gte("score", dec("3.5")) // score >= dec(3.5)
|
|
392
|
+
*/
|
|
393
|
+
declare function gte<N$1 extends string, V extends PredicateValue>(name: N$1, value: V): ComparisonNode<ValueRef<N$1, V>>;
|
|
394
|
+
/**
|
|
395
|
+
* Attribute is less than value, in index order — see {@link ComparisonOperator}.
|
|
396
|
+
*
|
|
397
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
398
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
399
|
+
* attribute, a system attribute is compared against the wrong type, or the value is `bytes`.
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* lt("level", i32(10)) // level < i32(10)
|
|
403
|
+
*/
|
|
404
|
+
declare function lt<N$1 extends string, V extends PredicateValue>(name: N$1, value: V): ComparisonNode<ValueRef<N$1, V>>;
|
|
405
|
+
/**
|
|
406
|
+
* Attribute is less than or equal to value, in index order — see {@link ComparisonOperator}.
|
|
407
|
+
*
|
|
408
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
409
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
410
|
+
* attribute, a system attribute is compared against the wrong type, or the value is `bytes`.
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* lte("score", dec("5")) // score <= dec(5)
|
|
414
|
+
*/
|
|
415
|
+
declare function lte<N$1 extends string, V extends PredicateValue>(name: N$1, value: V): ComparisonNode<ValueRef<N$1, V>>;
|
|
416
|
+
/**
|
|
417
|
+
* Attribute lies between two values, **inclusive** at both ends: it matches exactly what
|
|
418
|
+
* `and(gte(name, low), lte(name, high))` matches, in one predicate. Both bounds must have one type,
|
|
419
|
+
* and a `low` above `high` matches nothing.
|
|
420
|
+
*
|
|
421
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
422
|
+
* @throws {InvalidPredicateError} If the bounds have different types, the name starts with `$` but
|
|
423
|
+
* is not a queryable system attribute, a system attribute is compared against the wrong type, or a
|
|
424
|
+
* bound is `bytes`.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* between("score", dec("3.5"), dec("5")) // score BETWEEN dec(3.5) AND dec(5)
|
|
428
|
+
* between("$expiresAt", u64(100n), u64(200n))
|
|
429
|
+
*/
|
|
430
|
+
declare function between<N$1 extends string, L extends PredicateValue, H extends PredicateValue>(name: N$1, low: L, high: H & SameTypeCheck<L, H>): BetweenNode<ValueRef<N$1, L>>;
|
|
431
|
+
/**
|
|
432
|
+
* Attribute is a `str` beginning with this prefix.
|
|
433
|
+
*
|
|
434
|
+
* The match is on **raw UTF-8 bytes** with no normalization — it is the index encoding, so
|
|
435
|
+
* `startsWith("name", "é")` matches only the same byte sequence, not another normal form of it.
|
|
436
|
+
*
|
|
437
|
+
* @param prefix - The prefix, as a bare string or a `str` value.
|
|
438
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
439
|
+
* @throws {InvalidPredicateError} If the name starts with `$` but is not a queryable system
|
|
440
|
+
* attribute.
|
|
441
|
+
* @throws {UnsupportedOperatorError} If given a value that is not a `str`, or a system attribute
|
|
442
|
+
* (none of which is a `str`).
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* startsWith("desc", "ab") // desc STARTSWITH str('ab')
|
|
446
|
+
*/
|
|
447
|
+
declare function startsWith<N$1 extends string>(name: N$1, prefix: string | StrValue): StartsWithNode<{
|
|
448
|
+
readonly name: N$1;
|
|
449
|
+
readonly type: "str";
|
|
450
|
+
}>;
|
|
451
|
+
/**
|
|
452
|
+
* The attribute is set, with any type.
|
|
453
|
+
*
|
|
454
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
455
|
+
* @throws {InvalidPredicateError} If given a system attribute — every entity has all of them, so
|
|
456
|
+
* the test would be a constant — or a `$` name that is not one.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* exists("reviewedBy") // EXISTS(reviewedBy)
|
|
460
|
+
* not(exists("closedAt")) // NOT EXISTS(closedAt)
|
|
461
|
+
*/
|
|
462
|
+
declare function exists<N$1 extends string>(name: N$1): ExistsNode<{
|
|
463
|
+
readonly name: N$1;
|
|
464
|
+
readonly type: never;
|
|
465
|
+
}>;
|
|
466
|
+
/**
|
|
467
|
+
* The attribute is set with exactly this type, whatever its value.
|
|
468
|
+
*
|
|
469
|
+
* Useful when the same name is written with different types across entities — a comparison already
|
|
470
|
+
* asserts the type, so this is for asking about the type alone.
|
|
471
|
+
*
|
|
472
|
+
* @param tag - The type tag: `bool`, `i32`, `u64`, `u256`, `dec`, `bytes32`, `str`, `addr` or
|
|
473
|
+
* `key` — any type but `bytes`, which is never indexed.
|
|
474
|
+
* @throws {InvalidAttributeNameError} If the name is outside the attribute name grammar.
|
|
475
|
+
* @throws {InvalidPredicateError} If the tag is not an indexable type, the name is a system
|
|
476
|
+
* attribute (whose type is fixed), or the name starts with `$` but is not a system attribute.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* hasType("age", "i32") // TYPEOF(age) = i32
|
|
480
|
+
*/
|
|
481
|
+
declare function hasType<N$1 extends string, T$1 extends IndexableTypeTag>(name: N$1, tag: T$1): TypeOfNode<{
|
|
482
|
+
readonly name: N$1;
|
|
483
|
+
readonly type: T$1;
|
|
484
|
+
}>;
|
|
485
|
+
/**
|
|
486
|
+
* The complement of an expression, evaluated against the set of live entities — unlike `!=`, it
|
|
487
|
+
* matches entities that never set the attribute at all.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* not(exists("closedAt")) // NOT EXISTS(closedAt)
|
|
491
|
+
* not(and(eq("a", 1), eq("b", 2))) // NOT (a = i32(1) AND b = i32(2))
|
|
492
|
+
*/
|
|
493
|
+
declare function not<R$1 extends AttributeRef>(expression: Expression<R$1>): NotNode<R$1>;
|
|
494
|
+
/**
|
|
495
|
+
* All of these must hold.
|
|
496
|
+
*
|
|
497
|
+
* A single expression is returned unwrapped, so building a conjunction from a filtered list does
|
|
498
|
+
* not litter the query with redundant nesting.
|
|
499
|
+
*
|
|
500
|
+
* @param expressions - The expressions, as separate arguments or one array.
|
|
501
|
+
* @throws {InvalidPredicateError} If given nothing to combine.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* and(gte("level", i32(10)), eq("status", "open"))
|
|
505
|
+
* and(filters) // an array works too
|
|
506
|
+
*/
|
|
507
|
+
declare function and<const E extends readonly Expression[]>(expressions: E): Expression<RefsOf<E[number]>>;
|
|
508
|
+
declare function and<const E extends readonly Expression[]>(...expressions: E): Expression<RefsOf<E[number]>>;
|
|
509
|
+
/**
|
|
510
|
+
* At least one of these must hold.
|
|
511
|
+
*
|
|
512
|
+
* A single expression is returned unwrapped.
|
|
513
|
+
*
|
|
514
|
+
* @param expressions - The expressions, as separate arguments or one array.
|
|
515
|
+
* @throws {InvalidPredicateError} If given nothing to combine.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* or(eq("status", "open"), not(exists("closedAt")))
|
|
519
|
+
*/
|
|
520
|
+
declare function or<const E extends readonly Expression[]>(expressions: E): Expression<RefsOf<E[number]>>;
|
|
521
|
+
declare function or<const E extends readonly Expression[]>(...expressions: E): Expression<RefsOf<E[number]>>;
|
|
522
|
+
/**
|
|
523
|
+
* Checks every attribute an expression names against a schema — the runtime half of the check
|
|
524
|
+
* {@link SchemaRef} makes at compile time, for the callers the type system does not reach.
|
|
525
|
+
*
|
|
526
|
+
* @throws {InvalidPredicateError} If a predicate names something that is not a column of the
|
|
527
|
+
* schema, a column that is not indexed, or compares a column against a value of another type.
|
|
528
|
+
*/
|
|
529
|
+
declare function checkAgainstSchema(expression: Expression, schema: Schema): void;
|
|
530
|
+
/**
|
|
531
|
+
* Renders an expression as the query string the node parses. Equivalent to `String(expression)`.
|
|
532
|
+
*
|
|
533
|
+
* Literals are always written tagged, even where the language would infer them: an untagged number
|
|
534
|
+
* defaults to `i32`, but spelling it `i32(10)` keeps the exact-type assertion visible in the query
|
|
535
|
+
* that actually went over the wire.
|
|
536
|
+
*/
|
|
537
|
+
declare function render(expression: Expression): string;
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region src/types/entity.d.ts
|
|
540
|
+
/**
|
|
541
|
+
* The fields an {@link Entity} can carry. Every one is optional: a query returns exactly the parts
|
|
542
|
+
* it selected, and `undefined` means "not asked for" rather than "empty".
|
|
543
|
+
*/
|
|
544
|
+
type EntityFields = {
|
|
545
|
+
key?: Hex | undefined;
|
|
546
|
+
owner?: Hex | undefined;
|
|
547
|
+
creator?: Hex | undefined;
|
|
548
|
+
/** Block the entity was created at. */
|
|
549
|
+
createdAt?: bigint | undefined;
|
|
550
|
+
/** Block the entity was last patched at. */
|
|
551
|
+
updatedAt?: bigint | undefined;
|
|
552
|
+
/** Block the entity expires at. */
|
|
553
|
+
expiresAt?: bigint | undefined;
|
|
554
|
+
/** The immutable properties the entity was created with. */
|
|
555
|
+
creationFlags?: ResolvedCreationFlags | undefined;
|
|
556
|
+
/** Attribute names, types and indexing, with no values. */
|
|
557
|
+
attributeSchema?: AttributeSchema | undefined;
|
|
558
|
+
/** Attribute names, types and values. */
|
|
559
|
+
attributes?: Attributes | undefined;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* An entity as the node returns it, decoded: the fields a query selected, with its attributes as a
|
|
563
|
+
* map keyed by name. Which fields are populated is decided by the selection, so each may be
|
|
564
|
+
* `undefined`.
|
|
565
|
+
*
|
|
566
|
+
* Queries do not return these: `select()`, `query()` and `getEntity()` lay each one out as a flat
|
|
567
|
+
* row — the selected entity fields and attributes side by side, typed by the selection and, through
|
|
568
|
+
* a schema, by its columns.
|
|
569
|
+
*/
|
|
570
|
+
declare class Entity implements EntityFields {
|
|
571
|
+
key: Hex | undefined;
|
|
572
|
+
owner: Hex | undefined;
|
|
573
|
+
creator: Hex | undefined;
|
|
574
|
+
createdAt: bigint | undefined;
|
|
575
|
+
updatedAt: bigint | undefined;
|
|
576
|
+
expiresAt: bigint | undefined;
|
|
577
|
+
creationFlags: ResolvedCreationFlags | undefined;
|
|
578
|
+
attributeSchema: AttributeSchema | undefined;
|
|
579
|
+
attributes: Attributes | undefined;
|
|
580
|
+
constructor(fields?: EntityFields);
|
|
581
|
+
}
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region src/query/selection.d.ts
|
|
584
|
+
/**
|
|
585
|
+
* The entity fields a row can carry. Each is `$`-prefixed, like the system attributes `where`
|
|
586
|
+
* filters on: an attribute name cannot start with `$`, so no attribute can collide with one.
|
|
587
|
+
*/
|
|
588
|
+
declare const SYSTEM_FIELDS: readonly ["$key", "$owner", "$creator", "$createdAt", "$updatedAt", "$expiresAt", "$creationFlags"];
|
|
589
|
+
/** The name of an entity field a row carries alongside its attributes. */
|
|
590
|
+
type SystemField = (typeof SYSTEM_FIELDS)[number];
|
|
591
|
+
/** The {@link Entity} property a system field reads. */
|
|
592
|
+
type EntityField<F extends SystemField> = F extends `$${infer N extends keyof EntityFields}` ? N : never;
|
|
593
|
+
/**
|
|
594
|
+
* The keys a selection gives a fixed meaning: the entity fields, plus `$attributes` and
|
|
595
|
+
* `$attributeSchema`, which read an entity's attributes as a whole. Any key without a `$` names an
|
|
596
|
+
* attribute.
|
|
597
|
+
*/
|
|
598
|
+
type SelectionFields = { [K in SystemField]?: boolean } & {
|
|
599
|
+
/**
|
|
600
|
+
* Attribute names, types and indexing, without their values — a cheap way to find out what
|
|
601
|
+
* entities hold before fetching values that may be large. See {@link AttributeSchema}.
|
|
602
|
+
*/
|
|
603
|
+
$attributeSchema?: boolean;
|
|
604
|
+
/** Every attribute, as a map keyed by name. */
|
|
605
|
+
$attributes?: boolean;
|
|
606
|
+
};
|
|
607
|
+
/** The selection keys with a fixed meaning, in the order they are written into the RPC `select`. */
|
|
608
|
+
declare const SELECTION_KEYS: readonly ["$key", "$owner", "$creator", "$createdAt", "$updatedAt", "$expiresAt", "$creationFlags", "$attributeSchema", "$attributes"];
|
|
609
|
+
/** A selection key with a fixed meaning. */
|
|
610
|
+
type SelectionKey = (typeof SELECTION_KEYS)[number];
|
|
611
|
+
/**
|
|
612
|
+
* A selection: entity fields, `$attributes` / `$attributeSchema`, and attributes by name, each set
|
|
613
|
+
* to `true` to ask for it. The same selection means the same thing with or without a schema —
|
|
614
|
+
* naming one with `.from(...)` only types and checks the selected attributes, and the filter. A
|
|
615
|
+
* named schema also restricts the query to entities tagged with its name, and leaves the tag out of
|
|
616
|
+
* every row.
|
|
617
|
+
*/
|
|
618
|
+
type Selection = Readonly<Record<string, boolean | undefined>>;
|
|
619
|
+
/** Argument accepted by `select()` — a {@link Selection}, or `"*"` for everything. */
|
|
620
|
+
type SelectArg = Selection | "*";
|
|
621
|
+
/** Whether a selection value asks for the field: `true` does, `false` and `undefined` do not. */
|
|
622
|
+
type Selected<V> = V extends false | undefined ? false : true;
|
|
623
|
+
/**
|
|
624
|
+
* What a column reads back as: a value of its type, or `undefined` too if the column is optional.
|
|
625
|
+
*/
|
|
626
|
+
type ColumnValue<C> = C extends {
|
|
627
|
+
readonly type: infer T extends TypeTag;
|
|
628
|
+
readonly isOptional: infer O;
|
|
629
|
+
} ? ValueOf<T> | (true extends O ? undefined : never) : never;
|
|
630
|
+
/**
|
|
631
|
+
* What a selected key reads back as: an entity field as the entity has it, the attributes as a
|
|
632
|
+
* whole, or one attribute — typed by its column through a schema, and any value or none without.
|
|
633
|
+
*/
|
|
634
|
+
type FieldValue<K$1, TSchema extends Schema | undefined> = K$1 extends SystemField ? NonNullable<Entity[EntityField<K$1>]> : K$1 extends "$attributes" ? Attributes : K$1 extends "$attributeSchema" ? AttributeSchema : K$1 extends `$${string}` ? never : TSchema extends Schema ? K$1 extends keyof ColumnsOf<TSchema> ? ColumnValue<ColumnsOf<TSchema>[K$1]> : never : ArkivValue | undefined;
|
|
635
|
+
/**
|
|
636
|
+
* One result of selection `S`, through schema `TSchema` or without one: the selected entity fields
|
|
637
|
+
* and attributes side by side, flat. Through a schema each attribute is typed as its column
|
|
638
|
+
* declares; without one it is whatever value the entity holds, or `undefined`. Accessing an
|
|
639
|
+
* unselected field is a compile error.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* // select({ $key: true, title: true }) → { $key: Hex; title: ArkivValue | undefined }
|
|
643
|
+
* // select({ $key: true, title: true }).from(Posts) → { $key: Hex; title: StrValue }
|
|
644
|
+
*/
|
|
645
|
+
type Row<S, TSchema extends Schema | undefined = undefined> = { readonly [K in keyof S as Selected<S[K]> extends true ? K : never]: FieldValue<K, TSchema> };
|
|
646
|
+
/**
|
|
647
|
+
* What `select()` / `select("*")` selects without a schema: every entity field and every
|
|
648
|
+
* attribute. Not the `$attributeSchema`: its point is learning an entity's shape without fetching
|
|
649
|
+
* its values, so returning it next to every value would only add to the response. It is only
|
|
650
|
+
* returned when asked for by name.
|
|
651
|
+
*/
|
|
652
|
+
type AllSelected = { [K in SystemField | "$attributes"]: true };
|
|
653
|
+
/**
|
|
654
|
+
* The result when everything is selected without a schema — every entity field, and every
|
|
655
|
+
* attribute as the `$attributes` map. Also what `getEntity(key)` returns.
|
|
656
|
+
*/
|
|
657
|
+
type FullEntity = Row<AllSelected>;
|
|
658
|
+
/** The row type when everything is selected through a schema — every entity field and column. */
|
|
659
|
+
type FullRow<TSchema extends Schema> = Row<{ [K in SystemField | keyof ColumnsOf<TSchema>]: true }, TSchema>;
|
|
660
|
+
declare const dynamic: unique symbol;
|
|
661
|
+
/**
|
|
662
|
+
* The selection type of a builder whose selection is only known at runtime — `select(sel)` with
|
|
663
|
+
* `sel` typed {@link SelectArg} rather than written inline. Nothing about which fields will be
|
|
664
|
+
* present can be known statically, so results are typed with every field optional.
|
|
665
|
+
*/
|
|
666
|
+
type DynamicSelection = {
|
|
667
|
+
readonly [dynamic]: true;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* A result whose selection is only known at runtime: any entity field and any attribute may be
|
|
671
|
+
* absent, because nothing says statically which were selected.
|
|
672
|
+
*/
|
|
673
|
+
type PartialRow<TSchema extends Schema | undefined = undefined> = { readonly [K in SystemField]?: NonNullable<Entity[EntityField<K>]> } & {
|
|
674
|
+
readonly $attributes?: Attributes;
|
|
675
|
+
readonly $attributeSchema?: AttributeSchema;
|
|
676
|
+
} & (TSchema extends Schema ? { readonly [K in keyof ColumnsOf<TSchema>]?: ValueOf<ColumnsOf<TSchema>[K]["type"]> } : {
|
|
677
|
+
readonly [name: string]: ArkivValue | undefined;
|
|
678
|
+
});
|
|
679
|
+
/**
|
|
680
|
+
* Whether which fields `S` selects is only known at runtime: a selection typed {@link SelectArg} or
|
|
681
|
+
* {@link Selection}, or one with a field typed `boolean` rather than `true` or `false`.
|
|
682
|
+
*/
|
|
683
|
+
type IsDynamic<S> = string extends keyof Exclude<S, "*"> ? true : S extends "*" ? false : true extends { [K in keyof S]: [S[K]] extends [boolean] ? (boolean extends S[K] ? true : false) : false }[keyof S] ? true : false;
|
|
684
|
+
/**
|
|
685
|
+
* The selection type a query carries for the selection `select()` or `query()` was given: `"*"`
|
|
686
|
+
* for everything, {@link DynamicSelection} when the fields are only known at runtime, and the
|
|
687
|
+
* selection itself otherwise.
|
|
688
|
+
*/
|
|
689
|
+
type SelectionOf<S> = [S] extends ["*"] ? "*" : IsDynamic<S> extends true ? DynamicSelection : S;
|
|
690
|
+
/**
|
|
691
|
+
* Rejects a selection that asks for nothing at compile time — `{}`, or every field `false`:
|
|
692
|
+
* `unknown` when `S` asks for something, or when that is only known at runtime, and an object no
|
|
693
|
+
* selection satisfies otherwise.
|
|
694
|
+
*/
|
|
695
|
+
type NonEmptySelection<S> = SelectionOf<S> extends "*" | DynamicSelection ? unknown : [keyof { [K in keyof S as Selected<S[K]> extends true ? K : never]: true }] extends [never] ? {
|
|
696
|
+
"select() needs at least one field set to true": true;
|
|
697
|
+
} : unknown;
|
|
698
|
+
/**
|
|
699
|
+
* Rejects a `$` key that is not an entity field, `$attributes` or `$attributeSchema` at compile
|
|
700
|
+
* time. An attribute name cannot start with `$`, so such a key can only be a typo: `unknown` when
|
|
701
|
+
* there is none, and an object naming the offenders, which no selection satisfies, otherwise.
|
|
702
|
+
*/
|
|
703
|
+
type KnownSystemFields<S> = SelectionOf<S> extends "*" | DynamicSelection ? unknown : [Extract<Exclude<keyof S, SelectionKey>, `$${string}`>] extends [never] ? unknown : {
|
|
704
|
+
"selected names that are not entity fields": Extract<Exclude<keyof S, SelectionKey>, `$${string}`>;
|
|
705
|
+
};
|
|
706
|
+
/** What a query returns per result — a flat row, typed by the schema when there is one. */
|
|
707
|
+
type ResultOf<TSelection, TSchema extends Schema | undefined> = TSelection extends DynamicSelection ? PartialRow<TSchema> : TSelection extends "*" ? TSchema extends Schema ? FullRow<TSchema> : FullEntity : Row<TSelection, TSchema>;
|
|
708
|
+
/**
|
|
709
|
+
* The keys of a selection that mean nothing through `TSchema` — neither an entity field,
|
|
710
|
+
* `$attributes` / `$attributeSchema`, nor a column. None for a star or a selection only known at
|
|
711
|
+
* runtime, which `from()` checks when it runs instead.
|
|
712
|
+
*/
|
|
713
|
+
type UnknownSelection<TSelection, TSchema extends Schema> = TSelection extends "*" | DynamicSelection ? never : Exclude<keyof TSelection, SelectionKey | keyof ColumnsOf<TSchema>>;
|
|
714
|
+
/**
|
|
715
|
+
* Converts a selection into the RPC `select` object — the same request {@link projectSelection}
|
|
716
|
+
* makes without a schema.
|
|
717
|
+
*
|
|
718
|
+
* Every field is opt-in — anything not explicitly selected is sent as `false`, including the key.
|
|
719
|
+
* Sending the full object rather than omitting the `false`s keeps what the SDK asked for legible in
|
|
720
|
+
* a request log, and pins the answer even if a node's defaults change.
|
|
721
|
+
*
|
|
722
|
+
* `undefined` or `"*"` selects everything.
|
|
723
|
+
*
|
|
724
|
+
* @throws If the selection asks for nothing, or names an attribute outside the name grammar.
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* toRpcSelect() // everything
|
|
728
|
+
* toRpcSelect({ $key: true }) // only the key
|
|
729
|
+
* toRpcSelect({ $key: true, projectId: true }) // the key and one attribute
|
|
730
|
+
*/
|
|
731
|
+
declare function toRpcSelect(selection?: SelectArg): RpcSelect;
|
|
732
|
+
/**
|
|
733
|
+
* A selection resolved, through a schema or without one: what to ask the node for, and how to lay
|
|
734
|
+
* the answer out.
|
|
735
|
+
*/
|
|
736
|
+
type Projection = {
|
|
737
|
+
readonly select: RpcSelect;
|
|
738
|
+
/** The entity fields each row carries. */
|
|
739
|
+
readonly fields: readonly SystemField[];
|
|
740
|
+
/**
|
|
741
|
+
* The attributes each row carries as fields of their own, by name — each with its column
|
|
742
|
+
* through a schema, which the value is checked against, and `undefined` without one.
|
|
743
|
+
*/
|
|
744
|
+
readonly columns: readonly (readonly [name: string, column: AnyColumn | undefined])[];
|
|
745
|
+
/** Whether each row carries the `$attributes` map. */
|
|
746
|
+
readonly attributes: boolean;
|
|
747
|
+
/** Whether each row carries the `$attributeSchema`. */
|
|
748
|
+
readonly attributeSchema: boolean;
|
|
749
|
+
/** The tag each entity must carry, for a named schema. Checked, never part of the row. */
|
|
750
|
+
readonly tag: StrValue | undefined;
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* Resolves a selection, through a schema or without one. A key that does not start with `$` names
|
|
754
|
+
* an attribute — through a schema, it must be a column.
|
|
755
|
+
*
|
|
756
|
+
* `undefined` or `"*"` selects every entity field and, through a schema, every column; without one,
|
|
757
|
+
* every attribute as the `$attributes` map. The `$attributeSchema` is only selected by name.
|
|
758
|
+
*
|
|
759
|
+
* Attributes are fetched by name where possible, so the ones a row does not carry stay on the node.
|
|
760
|
+
* A named schema's tag is fetched too, so each entity can be checked against it.
|
|
761
|
+
*
|
|
762
|
+
* @throws If the selection asks for nothing, names a `$` key that is not an entity field, names an
|
|
763
|
+
* attribute outside the name grammar, or — through a schema — names an attribute that is not a
|
|
764
|
+
* column.
|
|
765
|
+
*/
|
|
766
|
+
declare function projectSelection(selection?: SelectArg, schema?: Schema): Projection;
|
|
767
|
+
/**
|
|
768
|
+
* Lays an entity out as a row of `projection` — checking it against the schema, when there is one.
|
|
769
|
+
*
|
|
770
|
+
* @throws {SchemaMismatchError} If a named schema's entity is not tagged with its name, or the
|
|
771
|
+
* entity lacks a selected required column or holds one with a type other than the schema's — it
|
|
772
|
+
* was not written through this schema, or was patched since.
|
|
773
|
+
*/
|
|
774
|
+
declare function toRow(entity: Entity, projection: Projection): Record<string, unknown>;
|
|
775
|
+
//#endregion
|
|
776
|
+
//#region src/actions/public/query.d.ts
|
|
777
|
+
type QueryOptions<TSelection extends SelectArg = SelectArg> = {
|
|
778
|
+
/** What to return — the same selection `select()` takes. Defaults to everything. */
|
|
779
|
+
select?: TSelection | undefined;
|
|
780
|
+
/** Block height to read at. Defaults to the head. */
|
|
781
|
+
atBlock?: bigint | undefined;
|
|
782
|
+
/** Page size, up to the node maximum of 100. */
|
|
783
|
+
limit?: number | undefined;
|
|
784
|
+
/** Cursor from a previous page. */
|
|
785
|
+
cursor?: string | undefined;
|
|
786
|
+
/** Whether to also count every entity the query matches, returned as `count`. */
|
|
787
|
+
count?: boolean | undefined;
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* What one result of a `query()` reads as for selection `S`: the same row `select(S)` returns
|
|
791
|
+
* without a schema — every field when everything is selected, and every field optional when the
|
|
792
|
+
* selection is only known at runtime.
|
|
793
|
+
*/
|
|
794
|
+
type QueryRow<S> = ResultOf<SelectionOf<S>, undefined>;
|
|
795
|
+
type QueryReturnType<TResult = FullEntity> = {
|
|
796
|
+
entities: TResult[];
|
|
797
|
+
/** The cursor for the next page, or `undefined` when no pages remain. */
|
|
798
|
+
cursor: string | undefined;
|
|
799
|
+
/** The block the page was read at. */
|
|
800
|
+
blockNumber: bigint;
|
|
801
|
+
/** How many entities the query matches, if `count` was set. */
|
|
802
|
+
count: bigint | undefined;
|
|
803
|
+
};
|
|
804
|
+
//#endregion
|
|
805
|
+
//#region src/types/events.d.ts
|
|
806
|
+
/**
|
|
807
|
+
* Where an event sits in the chain — carried by every on-chain entity event.
|
|
808
|
+
*
|
|
809
|
+
* Operations apply in batch order and emit one event each, so `blockNumber` and `logIndex` together
|
|
810
|
+
* are the order the operations were applied in. A replica that replays them in that order sees
|
|
811
|
+
* exactly what the engine did.
|
|
812
|
+
*/
|
|
813
|
+
type EntityEventContext = {
|
|
814
|
+
/** The block the operation was applied in. */
|
|
815
|
+
blockNumber: bigint;
|
|
816
|
+
/** The transaction the operation was part of. */
|
|
817
|
+
transactionHash: Hex;
|
|
818
|
+
/** The event's position within its block. */
|
|
819
|
+
logIndex: number;
|
|
820
|
+
};
|
|
821
|
+
/** An entity was created. */
|
|
822
|
+
type EntityCreatedEvent = EntityEventContext & {
|
|
823
|
+
type: "EntityCreated";
|
|
824
|
+
entityKey: Hex;
|
|
825
|
+
owner: Address;
|
|
826
|
+
/** The block the entity is set to expire at. */
|
|
827
|
+
expiresAt: bigint;
|
|
828
|
+
/**
|
|
829
|
+
* The immutable properties the entity was created with, decoded from its `creationFlags` byte.
|
|
830
|
+
*/
|
|
831
|
+
creationFlags: ResolvedCreationFlags;
|
|
832
|
+
};
|
|
833
|
+
/**
|
|
834
|
+
* An entity's attributes changed.
|
|
835
|
+
*
|
|
836
|
+
* The event says *that* it changed, not what to — read the entity to see the new state.
|
|
837
|
+
*/
|
|
838
|
+
type EntityPatchedEvent = EntityEventContext & {
|
|
839
|
+
type: "EntityPatched";
|
|
840
|
+
entityKey: Hex;
|
|
841
|
+
owner: Address;
|
|
842
|
+
};
|
|
843
|
+
/** An entity's expiry moved further out. */
|
|
844
|
+
type ExpiryExtendedEvent = EntityEventContext & {
|
|
845
|
+
type: "ExpiryExtended";
|
|
846
|
+
entityKey: Hex;
|
|
847
|
+
/**
|
|
848
|
+
* The entity's owner — **not** whoever extended it. An entity created with
|
|
849
|
+
* `permissionlessExtension` can be extended by anyone, and the event does not say by whom; read
|
|
850
|
+
* the transaction's sender if you need that.
|
|
851
|
+
*/
|
|
852
|
+
owner: Address;
|
|
853
|
+
/** The block the entity is now set to expire at. */
|
|
854
|
+
expiresAt: bigint;
|
|
855
|
+
};
|
|
856
|
+
/** An entity changed hands. */
|
|
857
|
+
type OwnershipTransferredEvent = EntityEventContext & {
|
|
858
|
+
type: "OwnershipTransferred";
|
|
859
|
+
entityKey: Hex;
|
|
860
|
+
previousOwner: Address;
|
|
861
|
+
newOwner: Address;
|
|
862
|
+
};
|
|
863
|
+
/** An entity was deleted by its owner, before its expiry. */
|
|
864
|
+
type EntityDeletedEvent = EntityEventContext & {
|
|
865
|
+
type: "EntityDeleted";
|
|
866
|
+
entityKey: Hex;
|
|
867
|
+
owner: Address;
|
|
868
|
+
};
|
|
869
|
+
/**
|
|
870
|
+
* Every event the engine emits, discriminated by `type`.
|
|
871
|
+
*/
|
|
872
|
+
type EntityEvent = EntityCreatedEvent | EntityPatchedEvent | ExpiryExtendedEvent | OwnershipTransferredEvent | EntityDeletedEvent;
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region src/actions/public/watchEntityEvents.d.ts
|
|
875
|
+
/**
|
|
876
|
+
* Handlers and options for `client.watchEntityEvents`. Every handler is optional; the watcher does
|
|
877
|
+
* the work for the ones you pass.
|
|
878
|
+
*/
|
|
879
|
+
type WatchEntityEventsParameters = {
|
|
880
|
+
onEntityCreated?: ((event: EntityCreatedEvent) => void) | undefined;
|
|
881
|
+
onEntityPatched?: ((event: EntityPatchedEvent) => void) | undefined;
|
|
882
|
+
onExpiryExtended?: ((event: ExpiryExtendedEvent) => void) | undefined;
|
|
883
|
+
onOwnershipTransferred?: ((event: OwnershipTransferredEvent) => void) | undefined;
|
|
884
|
+
onEntityDeleted?: ((event: EntityDeletedEvent) => void) | undefined;
|
|
885
|
+
/**
|
|
886
|
+
* Every event, in application order, whatever its type. Runs *before* the per-event handler for
|
|
887
|
+
* the same event.
|
|
888
|
+
*
|
|
889
|
+
* This is the replay seam: operations apply in batch order and emit one event each, so an
|
|
890
|
+
* off-chain replica that consumes this in order sees exactly what the engine did.
|
|
891
|
+
*/
|
|
892
|
+
onEvent?: ((event: EntityEvent) => void) | undefined;
|
|
893
|
+
/**
|
|
894
|
+
* Transport failures, logs that will not decode, and anything one of your own handlers throws.
|
|
895
|
+
*
|
|
896
|
+
* Defaults to `console.error`. A watcher whose filter the node dropped otherwise just goes quiet,
|
|
897
|
+
* and a quiet watcher is indistinguishable from a quiet chain.
|
|
898
|
+
*/
|
|
899
|
+
onError?: ((error: Error) => void) | undefined;
|
|
900
|
+
/** Replay from this block before following the head. Defaults to the head. */
|
|
901
|
+
fromBlock?: bigint | undefined;
|
|
902
|
+
/** How often to poll, in milliseconds. Defaults to half a block. */
|
|
903
|
+
pollingInterval?: number | undefined;
|
|
904
|
+
};
|
|
905
|
+
//#endregion
|
|
906
|
+
//#region src/actions/wallet/createEntity.d.ts
|
|
907
|
+
/**
|
|
908
|
+
* How an created entity lives: its lifetime, plus the flags and salt it is created with.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* { expiration: ExpirationTime.fromDays(30) }
|
|
912
|
+
*
|
|
913
|
+
* @example Pin an absolute deadline, but never let it leave the entity with less than a day:
|
|
914
|
+
* {
|
|
915
|
+
* expiration: ExpirationTime.atDate(someDeadline, {
|
|
916
|
+
* atLeast: ExpirationTime.fromDays(1), // ...but live at least a day regardless
|
|
917
|
+
* }),
|
|
918
|
+
* flags: { readonly: true },
|
|
919
|
+
* }
|
|
920
|
+
*/
|
|
921
|
+
type CreateEntityOptions = {
|
|
922
|
+
/**
|
|
923
|
+
* How long the entity should live, built with {@link ExpirationTime}.
|
|
924
|
+
*
|
|
925
|
+
* `ExpirationTime.fromDays(30)` is the everyday form. `atBlock` / `atDate` pin an absolute
|
|
926
|
+
* deadline instead, and either can carry `{ atLeast }` to guarantee a minimum life on top of it.
|
|
927
|
+
*/
|
|
928
|
+
expiration: Expiry;
|
|
929
|
+
/**
|
|
930
|
+
* Properties fixed at creation: `readonly` and `permissionlessExtension`. No operation changes
|
|
931
|
+
* them afterwards, so an entity is whatever it was created as for life. Both default to `false`.
|
|
932
|
+
*/
|
|
933
|
+
flags?: CreationFlags | undefined;
|
|
934
|
+
/**
|
|
935
|
+
* The salt mixed into the entity key. Defaults to 128 random bits, which makes the key
|
|
936
|
+
* unpredictable to everyone but the creator.
|
|
937
|
+
*
|
|
938
|
+
* Pass {@link NO_SALT} for a key derived from the owner and nonce alone — predictable by anyone,
|
|
939
|
+
* which is what you want only when a third party must be able to compute the key in advance.
|
|
940
|
+
*/
|
|
941
|
+
salt?: SaltInput | undefined;
|
|
942
|
+
};
|
|
943
|
+
/**
|
|
944
|
+
* One entity to create, as a batch carries it: the schema, the values, and the {@link CreateEntityOptions}.
|
|
945
|
+
*
|
|
946
|
+
* @typeParam S - The schema the values are typed by.
|
|
947
|
+
*/
|
|
948
|
+
type CreateEntityParameters<S extends Schema = Schema> = CreateEntityOptions & {
|
|
949
|
+
/** The schema the entity is written through. */
|
|
950
|
+
schema: S;
|
|
951
|
+
/**
|
|
952
|
+
* The entity's values, keyed by column. Every required column must be given; an optional one may
|
|
953
|
+
* be left out, and a defaulted one left out is written with its default.
|
|
954
|
+
*/
|
|
955
|
+
values: CreateEntityValues<S>;
|
|
956
|
+
};
|
|
957
|
+
/**
|
|
958
|
+
* The result of creating an entity.
|
|
959
|
+
*/
|
|
960
|
+
type CreateEntityReturnType = {
|
|
961
|
+
/** The new entity's key. */
|
|
962
|
+
entityKey: Hex;
|
|
963
|
+
txHash: Hash;
|
|
964
|
+
/**
|
|
965
|
+
* The block the entity expires at, as the engine recorded it — read from the `EntityCreated`
|
|
966
|
+
* event, so a duration is already resolved against the block the transaction landed in.
|
|
967
|
+
*/
|
|
968
|
+
expiresAt: bigint;
|
|
969
|
+
};
|
|
970
|
+
//#endregion
|
|
971
|
+
//#region src/actions/wallet/deleteEntity.d.ts
|
|
972
|
+
/**
|
|
973
|
+
* Parameters for the deleteEntity function.
|
|
974
|
+
* - entityKey: The key of the entity to delete.
|
|
975
|
+
*/
|
|
976
|
+
type DeleteEntityParameters = {
|
|
977
|
+
entityKey: Hex;
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Return type for the deleteEntity function.
|
|
981
|
+
* - entityKey: The key of the entity.
|
|
982
|
+
* - txHash: The transaction hash.
|
|
983
|
+
*/
|
|
984
|
+
type DeleteEntityReturnType = {
|
|
985
|
+
entityKey: Hex;
|
|
986
|
+
txHash: Hash;
|
|
987
|
+
};
|
|
988
|
+
//#endregion
|
|
989
|
+
//#region src/actions/wallet/extendEntity.d.ts
|
|
990
|
+
/**
|
|
991
|
+
* Parameters for extending an entity's life.
|
|
992
|
+
*
|
|
993
|
+
* An extension **sets a new expiry**; it does not add to the existing one. It is resolved exactly
|
|
994
|
+
* as a create's is — a duration counts from now, not from the entity's current expiry — so
|
|
995
|
+
* `ExpirationTime.fromDays(30)` means "alive for thirty more days from now" whatever the entity's
|
|
996
|
+
* remaining life happened to be.
|
|
997
|
+
*
|
|
998
|
+
* The engine rejects an extension that would move the expiry earlier, so extending an entity by
|
|
999
|
+
* less than it already has left is an error rather than a silent shortening. One that resolves to
|
|
1000
|
+
* the current expiry changes nothing.
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* await client.extendEntity({ entityKey, expiration: ExpirationTime.fromDays(30) })
|
|
1004
|
+
* await client.extendEntity({ entityKey, expiration: ExpirationTime.atBlock(1_200_000n) })
|
|
1005
|
+
*/
|
|
1006
|
+
type ExtendEntityParameters = {
|
|
1007
|
+
entityKey: Hex;
|
|
1008
|
+
/** The entity's new lifetime, built with {@link ExpirationTime}. */
|
|
1009
|
+
expiration: Expiry;
|
|
1010
|
+
};
|
|
1011
|
+
/**
|
|
1012
|
+
* The result of extending an entity.
|
|
1013
|
+
*/
|
|
1014
|
+
type ExtendEntityReturnType = {
|
|
1015
|
+
entityKey: Hex;
|
|
1016
|
+
txHash: Hash;
|
|
1017
|
+
/**
|
|
1018
|
+
* The block the entity now expires at, as the engine recorded it — read from the
|
|
1019
|
+
* `ExpiryExtended` event, so a duration is already resolved against the block the transaction
|
|
1020
|
+
* landed in.
|
|
1021
|
+
*/
|
|
1022
|
+
expiresAt: bigint;
|
|
1023
|
+
};
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region src/actions/wallet/patchEntity.d.ts
|
|
1026
|
+
/**
|
|
1027
|
+
* What a patch changes.
|
|
1028
|
+
*
|
|
1029
|
+
* A patch names only what changes. Columns it does not mention keep whatever value they have — so
|
|
1030
|
+
* a caller can change one column without first reading the entity to learn what the others are,
|
|
1031
|
+
* and without racing anyone else who is changing a different one.
|
|
1032
|
+
*
|
|
1033
|
+
* @typeParam S - The schema the changes are typed by.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* { set: { title: "Cells, not entities", score: dec("4.2") }, unset: ["thumbnail"] }
|
|
1037
|
+
*/
|
|
1038
|
+
type PatchEntityChanges<S extends Schema = Schema> = {
|
|
1039
|
+
/**
|
|
1040
|
+
* Columns to write, keyed by name. Each is written with the indexed flag its column declares,
|
|
1041
|
+
* so writing a column whose indexing the schema has since changed changes it on the entity too.
|
|
1042
|
+
* Defaults do not apply: a patch writes only what it names.
|
|
1043
|
+
*
|
|
1044
|
+
* @throws {SchemaMismatchError} If a name is not a column, or a value is not of its column's type.
|
|
1045
|
+
*/
|
|
1046
|
+
set?: PatchEntityValues<S> | undefined;
|
|
1047
|
+
/**
|
|
1048
|
+
* Optional columns to remove. Naming one the entity does not carry is not an error — the outcome
|
|
1049
|
+
* is the same either way, and a caller clearing a column should not have to know whether it was
|
|
1050
|
+
* ever set.
|
|
1051
|
+
*
|
|
1052
|
+
* @throws {ConflictingMutationError} If a name also appears in `set`.
|
|
1053
|
+
*/
|
|
1054
|
+
unset?: readonly OptionalColumnName<S>[] | undefined;
|
|
1055
|
+
};
|
|
1056
|
+
/**
|
|
1057
|
+
* One patch, as a batch carries it: the schema, the entity, and the {@link PatchEntityChanges}.
|
|
1058
|
+
*
|
|
1059
|
+
* The entity's identity is fixed: a patch never moves the key, the owner, the creation flags or the
|
|
1060
|
+
* expiry. Use `extendEntity` for the expiry and `changeOwnership` for the owner.
|
|
1061
|
+
*/
|
|
1062
|
+
type PatchEntityParameters<S extends Schema = Schema> = PatchEntityChanges<S> & {
|
|
1063
|
+
/** The schema the changes are typed by. */
|
|
1064
|
+
schema: S;
|
|
1065
|
+
/** The entity to patch. */
|
|
1066
|
+
entityKey: Hex;
|
|
1067
|
+
};
|
|
1068
|
+
/** The result of a patch. */
|
|
1069
|
+
type PatchEntityReturnType = {
|
|
1070
|
+
/** The patched entity's key — unchanged, since a patch never moves it. */
|
|
1071
|
+
entityKey: Hex;
|
|
1072
|
+
txHash: Hash;
|
|
1073
|
+
};
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/actions/wallet/executeBatch.d.ts
|
|
1076
|
+
/**
|
|
1077
|
+
* Parameters for the executeBatch function.
|
|
1078
|
+
*
|
|
1079
|
+
* At least one operation is required; a batch with nothing in it throws rather than spending gas on
|
|
1080
|
+
* an empty transaction.
|
|
1081
|
+
*
|
|
1082
|
+
* Each create and patch names its own schema, and is typed by it — a batch can write entities of
|
|
1083
|
+
* several schemas at once.
|
|
1084
|
+
*
|
|
1085
|
+
* @typeParam TCreates - The schema of each create, in order. Inferred.
|
|
1086
|
+
* @typeParam TPatches - The schema of each patch, in order. Inferred.
|
|
1087
|
+
*/
|
|
1088
|
+
type ExecuteBatchParameters<TCreates extends readonly Schema[] = readonly Schema[], TPatches extends readonly Schema[] = readonly Schema[]> = {
|
|
1089
|
+
/** The entities to create. */
|
|
1090
|
+
creates?: { readonly [I in keyof TCreates]: CreateEntityParameters<TCreates[I]> } | undefined;
|
|
1091
|
+
/** The patches to apply. */
|
|
1092
|
+
patches?: { readonly [I in keyof TPatches]: PatchEntityParameters<TPatches[I]> } | undefined;
|
|
1093
|
+
/** The entities to delete. */
|
|
1094
|
+
deletes?: readonly DeleteEntityParameters[] | undefined;
|
|
1095
|
+
/** The expiries to set. */
|
|
1096
|
+
extensions?: readonly ExtendEntityParameters[] | undefined;
|
|
1097
|
+
/** The ownership transfers to perform. */
|
|
1098
|
+
ownershipChanges?: readonly ChangeOwnershipParameters[] | undefined;
|
|
1099
|
+
};
|
|
1100
|
+
/** Return type for the executeBatch function. */
|
|
1101
|
+
type ExecuteBatchReturnType = {
|
|
1102
|
+
/** The transaction hash. */
|
|
1103
|
+
txHash: Hash;
|
|
1104
|
+
/** The keys of the created entities, in batch order. */
|
|
1105
|
+
createdEntities: Hex[];
|
|
1106
|
+
/** The keys of the patched entities. */
|
|
1107
|
+
patchedEntities: Hex[];
|
|
1108
|
+
/** The keys of the deleted entities. */
|
|
1109
|
+
deletedEntities: Hex[];
|
|
1110
|
+
/** The keys of the extended entities. */
|
|
1111
|
+
extendedEntities: Hex[];
|
|
1112
|
+
/** The keys of the entities handed to a new owner. */
|
|
1113
|
+
ownershipChanges: Hex[];
|
|
1114
|
+
};
|
|
1115
|
+
//#endregion
|
|
1116
|
+
//#region src/types/txParams.d.ts
|
|
1117
|
+
/**
|
|
1118
|
+
* Transaction fields a write action passes through to the wallet, for the cases where the defaults
|
|
1119
|
+
* are not what you want.
|
|
1120
|
+
*
|
|
1121
|
+
* Fee style is either/or: give `gasPrice` for a legacy transaction, or `maxFeePerGas` /
|
|
1122
|
+
* `maxPriorityFeePerGas` for an EIP-1559 one. Mixing the two does not typecheck. Anything left out
|
|
1123
|
+
* is estimated.
|
|
1124
|
+
*/
|
|
1125
|
+
type TxParams = {
|
|
1126
|
+
gas?: bigint;
|
|
1127
|
+
nonce?: number;
|
|
1128
|
+
gasPrice?: bigint;
|
|
1129
|
+
maxFeePerGas?: never;
|
|
1130
|
+
maxPriorityFeePerGas?: never;
|
|
1131
|
+
} | {
|
|
1132
|
+
gas?: bigint;
|
|
1133
|
+
nonce?: number;
|
|
1134
|
+
maxFeePerGas?: bigint;
|
|
1135
|
+
maxPriorityFeePerGas?: bigint;
|
|
1136
|
+
gasPrice?: never;
|
|
1137
|
+
};
|
|
1138
|
+
//#endregion
|
|
1139
|
+
//#region src/actions/wallet/changeOwnership.d.ts
|
|
1140
|
+
/**
|
|
1141
|
+
* Parameters for the changeOwnership function.
|
|
1142
|
+
* - entityKey: The key of the entity.
|
|
1143
|
+
* - newOwner: The address of the new owner.
|
|
1144
|
+
*/
|
|
1145
|
+
type ChangeOwnershipParameters = {
|
|
1146
|
+
entityKey: Hex;
|
|
1147
|
+
newOwner: Hex;
|
|
1148
|
+
};
|
|
1149
|
+
/**
|
|
1150
|
+
* Return type for the changeOwnership function.
|
|
1151
|
+
* - entityKey: The key of the entity.
|
|
1152
|
+
* - txHash: The transaction hash.
|
|
1153
|
+
*/
|
|
1154
|
+
type ChangeOwnershipReturnType = {
|
|
1155
|
+
entityKey: Hex;
|
|
1156
|
+
txHash: Hash;
|
|
1157
|
+
};
|
|
1158
|
+
//#endregion
|
|
1159
|
+
export { ComparisonNode as $, FullRow as A, ArkivClient as At, Selection as B, OwnershipTransferredEvent as C, or as Ct, ColumnValue as D, PredictEntityKeysReturnType as Dt, QueryRow as E, PredictEntityKeysParameters as Et, ResultOf as F, RpcEntity as Ft, projectSelection as G, SelectionOf as H, Row as I, RpcQueryOptions as It, Entity as J, toRow as K, SYSTEM_FIELDS as L, RpcSelect as Lt, NonEmptySelection as M, RpcAttribute as Mt, PartialRow as N, RpcAttributeSchemaEntry as Nt, DynamicSelection as O, PredictedEntityKey as Ot, Projection as P, RpcCreationFlags as Pt, BetweenNode as Q, SelectArg as R, ExpiryExtendedEvent as S, not as St, QueryReturnType as T, startsWith as Tt, SystemField as U, SelectionFields as V, UnknownSelection as W, AndNode as X, EntityFields as Y, AttributeRef as Z, EntityCreatedEvent as _, gte as _t, ExecuteBatchReturnType as a, PredicateValue as at, EntityEventContext as b, lte as bt, PatchEntityReturnType as c, StartsWithNode as ct, DeleteEntityParameters as d, and as dt, ComparisonOperator as et, DeleteEntityReturnType as f, between as ft, WatchEntityEventsParameters as g, gt, CreateEntityReturnType as h, exists as ht, ExecuteBatchParameters as i, OrNode as it, KnownSystemFields as j, ArkivRpcSchema as jt, FullEntity as k, GetBlockTimingReturnType as kt, ExtendEntityParameters as l, SystemAttributeRef as lt, CreateEntityParameters as m, eq as mt, ChangeOwnershipReturnType as n, Expression as nt, PatchEntityChanges as o, RefsOf as ot, CreateEntityOptions as p, checkAgainstSchema as pt, toRpcSelect as q, TxParams as r, NotNode as rt, PatchEntityParameters as s, SchemaRef as st, ChangeOwnershipParameters as t, ExistsNode as tt, ExtendEntityReturnType as u, TypeOfNode as ut, EntityDeletedEvent as v, hasType as vt, QueryOptions as w, render as wt, EntityPatchedEvent as x, ne as xt, EntityEvent as y, lt as yt, Selected as z };
|
|
1160
|
+
//# sourceMappingURL=changeOwnership-gXf-lBqI.d.ts.map
|