@trufnetwork/sdk-js 0.3.5 → 0.3.7
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 +11 -36
- package/dist/cjs/client/browserClient.cjs +1 -0
- package/dist/cjs/client/browserClient.cjs.map +2 -2
- package/dist/cjs/client/client.cjs +71 -11
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/client/nodeClient.cjs +1 -0
- package/dist/cjs/client/nodeClient.cjs.map +2 -2
- package/dist/cjs/contracts-api/action.cjs +4 -2
- package/dist/cjs/contracts-api/action.cjs.map +2 -2
- package/dist/cjs/contracts-api/composedAction.cjs +3 -53
- package/dist/cjs/contracts-api/composedAction.cjs.map +3 -3
- package/dist/cjs/contracts-api/deployStream.cjs +0 -14
- package/dist/cjs/contracts-api/deployStream.cjs.map +2 -2
- package/dist/cjs/contracts-api/roleManagement.cjs +133 -0
- package/dist/cjs/contracts-api/roleManagement.cjs.map +7 -0
- package/dist/cjs/index.common.cjs +2 -0
- package/dist/cjs/index.common.cjs.map +2 -2
- package/dist/cjs/types/role.cjs +19 -0
- package/dist/cjs/types/role.cjs.map +7 -0
- package/dist/esm/client/browserClient.mjs +1 -0
- package/dist/esm/client/browserClient.mjs.map +2 -2
- package/dist/esm/client/client.mjs +71 -11
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/client/nodeClient.mjs +1 -0
- package/dist/esm/client/nodeClient.mjs.map +2 -2
- package/dist/esm/contracts-api/action.mjs +4 -2
- package/dist/esm/contracts-api/action.mjs.map +2 -2
- package/dist/esm/contracts-api/composedAction.mjs +3 -47
- package/dist/esm/contracts-api/composedAction.mjs.map +2 -2
- package/dist/esm/contracts-api/deployStream.mjs +0 -14
- package/dist/esm/contracts-api/deployStream.mjs.map +2 -2
- package/dist/esm/contracts-api/roleManagement.mjs +112 -0
- package/dist/esm/contracts-api/roleManagement.mjs.map +7 -0
- package/dist/esm/index.common.mjs +2 -0
- package/dist/esm/index.common.mjs.map +2 -2
- package/dist/esm/types/role.mjs +1 -0
- package/dist/esm/types/role.mjs.map +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/browserClient.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +39 -6
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/nodeClient.d.ts.map +1 -1
- package/dist/types/contracts-api/action.d.ts +1 -0
- package/dist/types/contracts-api/action.d.ts.map +1 -1
- package/dist/types/contracts-api/composedAction.d.ts +2 -4
- package/dist/types/contracts-api/composedAction.d.ts.map +1 -1
- package/dist/types/contracts-api/deployStream.d.ts +0 -1
- package/dist/types/contracts-api/deployStream.d.ts.map +1 -1
- package/dist/types/contracts-api/roleManagement.d.ts +41 -0
- package/dist/types/contracts-api/roleManagement.d.ts.map +1 -0
- package/dist/types/index.common.d.ts +2 -0
- package/dist/types/index.common.d.ts.map +1 -1
- package/dist/types/types/role.d.ts +33 -0
- package/dist/types/types/role.d.ts.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -118,10 +118,7 @@ A primitive stream is a direct data source that allows you to insert individual
|
|
|
118
118
|
const streamId = await StreamId.generate("my_first_stream");
|
|
119
119
|
|
|
120
120
|
// Deploy the primitive stream
|
|
121
|
-
const deployResult = await client.deployStream(
|
|
122
|
-
streamId,
|
|
123
|
-
StreamType.Primitive
|
|
124
|
-
);
|
|
121
|
+
const deployResult = await client.deployStream(streamId, StreamType.Primitive);
|
|
125
122
|
|
|
126
123
|
// Load the primitive action to insert records
|
|
127
124
|
const primitiveAction = client.loadPrimitiveAction();
|
|
@@ -129,8 +126,8 @@ const primitiveAction = client.loadPrimitiveAction();
|
|
|
129
126
|
// Insert a record
|
|
130
127
|
await primitiveAction.insertRecord({
|
|
131
128
|
stream: client.ownStreamLocator(streamId),
|
|
132
|
-
eventTime: Date.now(), // Unix timestamp
|
|
133
|
-
value: "100.50" // Value as a string for precision
|
|
129
|
+
eventTime: Math.floor(Date.now() / 1000), // Unix timestamp in seconds
|
|
130
|
+
value: "100.50", // Value as a string for precision
|
|
134
131
|
});
|
|
135
132
|
```
|
|
136
133
|
|
|
@@ -145,10 +142,7 @@ const childStream1Id = await StreamId.generate("child_stream_1");
|
|
|
145
142
|
const childStream2Id = await StreamId.generate("child_stream_2");
|
|
146
143
|
|
|
147
144
|
// Deploy the parent composed stream
|
|
148
|
-
await client.deployStream(
|
|
149
|
-
parentStreamId,
|
|
150
|
-
StreamType.Composed
|
|
151
|
-
);
|
|
145
|
+
await client.deployStream(parentStreamId, StreamType.Composed);
|
|
152
146
|
|
|
153
147
|
// Load the composed action to set taxonomy
|
|
154
148
|
const composedAction = client.loadComposedAction();
|
|
@@ -159,14 +153,14 @@ await composedAction.setTaxonomy({
|
|
|
159
153
|
taxonomyItems: [
|
|
160
154
|
{
|
|
161
155
|
childStream: client.ownStreamLocator(childStream1Id),
|
|
162
|
-
weight: "0.6" // 60% weight
|
|
156
|
+
weight: "0.6", // 60% weight
|
|
163
157
|
},
|
|
164
158
|
{
|
|
165
159
|
childStream: client.ownStreamLocator(childStream2Id),
|
|
166
|
-
weight: "0.4" // 40% weight
|
|
167
|
-
}
|
|
160
|
+
weight: "0.4", // 40% weight
|
|
161
|
+
},
|
|
168
162
|
],
|
|
169
|
-
startDate: Date.now() // When this taxonomy becomes effective
|
|
163
|
+
startDate: Math.floor(Date.now() / 1000), // When this taxonomy becomes effective
|
|
170
164
|
});
|
|
171
165
|
```
|
|
172
166
|
|
|
@@ -177,7 +171,7 @@ You can control stream visibility and access permissions:
|
|
|
177
171
|
```typescript
|
|
178
172
|
// Set read visibility (public or private)
|
|
179
173
|
await streamAction.setReadVisibility(
|
|
180
|
-
client.ownStreamLocator(streamId),
|
|
174
|
+
client.ownStreamLocator(streamId),
|
|
181
175
|
visibility.public // or visibility.private
|
|
182
176
|
);
|
|
183
177
|
|
|
@@ -189,32 +183,12 @@ await streamAction.allowReadWallet(
|
|
|
189
183
|
```
|
|
190
184
|
|
|
191
185
|
**Notes:**
|
|
186
|
+
|
|
192
187
|
- Stream IDs are generated deterministically from a descriptive string.
|
|
193
188
|
- Always use string values for numeric data to maintain precision.
|
|
194
189
|
- Weights in composed streams must sum to 1.0.
|
|
195
190
|
- Streams can be made public or private, with fine-grained access control.
|
|
196
191
|
|
|
197
|
-
### Explorer Interaction
|
|
198
|
-
|
|
199
|
-
To enable Explorer-related features, you need to set the `neonConnectionString` in the `NodeTNClient` constructor.
|
|
200
|
-
You can request the explorer write-only connection string by contacting us.
|
|
201
|
-
|
|
202
|
-
```ts
|
|
203
|
-
const wallet = new Wallet("YOUR_PRIVATE_KEY");
|
|
204
|
-
|
|
205
|
-
const client = new NodeTNClient({
|
|
206
|
-
endpoint: "https://gateway.mainnet.truf.network",
|
|
207
|
-
signerInfo: {
|
|
208
|
-
address: wallet.address,
|
|
209
|
-
signer: wallet,
|
|
210
|
-
},
|
|
211
|
-
chainId: "tn-v2",
|
|
212
|
-
neonConnectionString: yourNeonConnectionString, // Add your connection string here
|
|
213
|
-
});
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
For more details on specific methods related to Explorer interactions, consult the [API Reference](./docs/api-reference.md).
|
|
217
|
-
|
|
218
192
|
### Using the SDK with Your Local Node
|
|
219
193
|
|
|
220
194
|
If you are running your own TRUF.NETWORK node, you can configure the SDK to interact with your local instance by changing the `endpoint` in the client configuration, as shown in the [Basic Client Initialization](#basic-client-initialization) section. This is useful for development, testing, or when operating within a private network.
|
|
@@ -235,6 +209,7 @@ import { ... } from "npm:@trufnetwork/sdk-js"
|
|
|
235
209
|
By default, some dependencies require environment permissions. If you need to run without environment permissions, please see [this GitHub issue](https://github.com/denoland/deno/issues/20898#issuecomment-2500396620) for potential workarounds.
|
|
236
210
|
|
|
237
211
|
**Need Immediate Deno Support?**
|
|
212
|
+
|
|
238
213
|
- Open an issue on our GitHub repository
|
|
239
214
|
- Reach out to our support team
|
|
240
215
|
- Provide details of your specific use case
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/browserClient.ts"],
|
|
4
|
-
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { WebKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\n\nexport class BrowserTNClient extends BaseTNClient<EnvironmentType.BROWSER> {\n constructor(options: TNClientOptions) {\n super(options);\n this.kwilClient = new WebKwil({\n ...options,\n kwilProvider: options.endpoint,\n });\n }\n}\n\nexport default BrowserTNClient;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAwB;AACxB,oBAA8C;AAEvC,IAAM,kBAAN,cAA8B,2BAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,uBAAQ;AAAA,MAC5B,GAAG;AAAA,MACH,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,wBAAQ;",
|
|
4
|
+
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { WebKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\n\nexport class BrowserTNClient extends BaseTNClient<EnvironmentType.BROWSER> {\n constructor(options: TNClientOptions) {\n super(options);\n this.kwilClient = new WebKwil({\n ...options,\n timeout: options.timeout ?? 30000,\n kwilProvider: options.endpoint,\n });\n }\n}\n\nexport default BrowserTNClient;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAwB;AACxB,oBAA8C;AAEvC,IAAM,kBAAN,cAA8B,2BAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,uBAAQ;AAAA,MAC5B,GAAG;AAAA,MACH,SAAS,QAAQ,WAAW;AAAA,MAC5B,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,wBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -32,13 +32,12 @@ var import_action = require("../contracts-api/action.cjs");
|
|
|
32
32
|
var import_EthereumAddress = require("../util/EthereumAddress.cjs");
|
|
33
33
|
var import_listStreams = require("./listStreams.cjs");
|
|
34
34
|
var import_getLastTransactions = require("./getLastTransactions.cjs");
|
|
35
|
+
var import_roleManagement = require("../contracts-api/roleManagement.cjs");
|
|
35
36
|
var BaseTNClient = class {
|
|
36
37
|
kwilClient;
|
|
37
38
|
signerInfo;
|
|
38
|
-
neonConnectionString;
|
|
39
39
|
constructor(options) {
|
|
40
40
|
this.signerInfo = options.signerInfo;
|
|
41
|
-
this.neonConnectionString = options.neonConnectionString;
|
|
42
41
|
}
|
|
43
42
|
/**
|
|
44
43
|
* Waits for a transaction to be mined by TN.
|
|
@@ -99,12 +98,6 @@ var BaseTNClient = class {
|
|
|
99
98
|
}
|
|
100
99
|
return this.kwilClient;
|
|
101
100
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns the Neon connection string used by the client.
|
|
104
|
-
*/
|
|
105
|
-
getNeonConnectionString() {
|
|
106
|
-
return this.neonConnectionString;
|
|
107
|
-
}
|
|
108
101
|
/**
|
|
109
102
|
* Deploys a new stream.
|
|
110
103
|
* @param streamId - The ID of the stream to deploy.
|
|
@@ -119,8 +112,7 @@ var BaseTNClient = class {
|
|
|
119
112
|
streamType,
|
|
120
113
|
synchronous,
|
|
121
114
|
kwilClient: this.getKwilClient(),
|
|
122
|
-
kwilSigner: this.getKwilSigner()
|
|
123
|
-
neonConnectionString: this.getNeonConnectionString()
|
|
115
|
+
kwilSigner: this.getKwilSigner()
|
|
124
116
|
});
|
|
125
117
|
}
|
|
126
118
|
/**
|
|
@@ -159,7 +151,16 @@ var BaseTNClient = class {
|
|
|
159
151
|
* @returns An instance of IComposedStream.
|
|
160
152
|
*/
|
|
161
153
|
loadComposedAction() {
|
|
162
|
-
return import_composedAction.ComposedAction.fromStream(this.loadAction()
|
|
154
|
+
return import_composedAction.ComposedAction.fromStream(this.loadAction());
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Loads the role management contract API, permitting its RBAC usage.
|
|
158
|
+
*/
|
|
159
|
+
loadRoleManagementAction() {
|
|
160
|
+
return import_roleManagement.RoleManagement.fromClient(
|
|
161
|
+
this.getKwilClient(),
|
|
162
|
+
this.getKwilSigner()
|
|
163
|
+
);
|
|
163
164
|
}
|
|
164
165
|
/**
|
|
165
166
|
* Creates a new stream locator.
|
|
@@ -207,5 +208,64 @@ var BaseTNClient = class {
|
|
|
207
208
|
const chainInfo = await kwilClient["chainInfoClient"]();
|
|
208
209
|
return chainInfo.data?.chain_id;
|
|
209
210
|
}
|
|
211
|
+
/*
|
|
212
|
+
* High-level role-management helpers. These wrap the lower-level
|
|
213
|
+
* RoleManagement contract calls and expose a simpler API on the
|
|
214
|
+
* TN client.
|
|
215
|
+
*/
|
|
216
|
+
/** Grants a role to one or more wallets. */
|
|
217
|
+
async grantRole(input) {
|
|
218
|
+
const rm = this.loadRoleManagementAction();
|
|
219
|
+
const walletsArr = Array.isArray(input.wallets) ? input.wallets : [input.wallets];
|
|
220
|
+
const tx = await rm.grantRole(
|
|
221
|
+
{
|
|
222
|
+
owner: input.owner,
|
|
223
|
+
roleName: input.roleName,
|
|
224
|
+
wallets: walletsArr
|
|
225
|
+
},
|
|
226
|
+
input.synchronous
|
|
227
|
+
);
|
|
228
|
+
return tx.data?.tx_hash;
|
|
229
|
+
}
|
|
230
|
+
/** Revokes a role from one or more wallets. */
|
|
231
|
+
async revokeRole(input) {
|
|
232
|
+
const rm = this.loadRoleManagementAction();
|
|
233
|
+
const walletsArr = Array.isArray(input.wallets) ? input.wallets : [input.wallets];
|
|
234
|
+
const tx = await rm.revokeRole(
|
|
235
|
+
{
|
|
236
|
+
owner: input.owner,
|
|
237
|
+
roleName: input.roleName,
|
|
238
|
+
wallets: walletsArr
|
|
239
|
+
},
|
|
240
|
+
input.synchronous
|
|
241
|
+
);
|
|
242
|
+
return tx.data?.tx_hash;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Checks if a wallet is member of a role.
|
|
246
|
+
* Returns true if the wallet is a member.
|
|
247
|
+
*/
|
|
248
|
+
async isMemberOf(input) {
|
|
249
|
+
const rm = this.loadRoleManagementAction();
|
|
250
|
+
const res = await rm.areMembersOf({
|
|
251
|
+
owner: input.owner,
|
|
252
|
+
roleName: input.roleName,
|
|
253
|
+
wallets: [input.wallet]
|
|
254
|
+
});
|
|
255
|
+
return res.length > 0 && res[0].isMember;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Lists role members – currently unsupported in the
|
|
259
|
+
* smart-contract layer.
|
|
260
|
+
*/
|
|
261
|
+
async listRoleMembers(input) {
|
|
262
|
+
const rm = this.loadRoleManagementAction();
|
|
263
|
+
return rm.listRoleMembers({
|
|
264
|
+
owner: input.owner,
|
|
265
|
+
roleName: input.roleName,
|
|
266
|
+
limit: input.limit,
|
|
267
|
+
offset: input.offset
|
|
268
|
+
});
|
|
269
|
+
}
|
|
210
270
|
};
|
|
211
271
|
//# sourceMappingURL=client.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/client.ts"],
|
|
4
|
-
"sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { KwilConfig } from \"@kwilteam/kwil-js/dist/api_client/config\";\nimport { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { EthSigner } from \"@kwilteam/kwil-js/dist/core/signature\";\nimport { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { TxInfoReceipt } from \"@kwilteam/kwil-js/dist/core/txQuery\";\nimport { ComposedAction } from \"../contracts-api/composedAction\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { deleteStream } from \"../contracts-api/deleteStream\";\nimport { PrimitiveAction } from \"../contracts-api/primitiveAction\";\nimport { Action } from \"../contracts-api/action\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator, TNStream } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listStreams } from \"./listStreams\";\nimport { getLastTransactions } from \"./getLastTransactions\";\n\nexport interface SignerInfo {\n // we need to have the address upfront to create the KwilSigner, instead of relying on the signer to return it asynchronously\n address: string;\n signer: EthSigner;\n}\n\nexport type TNClientOptions = {\n endpoint: string;\n signerInfo: SignerInfo;\n neonConnectionString?: string;\n} & Omit<KwilConfig, \"kwilProvider\">;\n\nexport interface ListStreamsInput {\n dataProvider?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n blockHeight?: number;\n}\n\n/**\n * @param dataProvider optional address; when omitted or null, returns for all providers\n * @param limitSize max rows to return (default 6, max 100)\n */\nexport interface GetLastTransactionsInput {\n dataProvider?: string;\n limitSize?: number;\n}\n\nexport abstract class BaseTNClient<T extends EnvironmentType> {\n protected kwilClient: Kwil<T> | undefined;\n protected signerInfo: SignerInfo;\n protected neonConnectionString: string | undefined;\n\n protected constructor(options: TNClientOptions) {\n this.signerInfo = options.signerInfo;\n this.neonConnectionString = options.neonConnectionString;\n }\n\n /**\n * Waits for a transaction to be mined by TN.\n * @param txHash - The transaction hash to wait for.\n * @param timeout - The timeout in milliseconds.\n * @returns A promise that resolves to the transaction info receipt.\n */\n async waitForTx(txHash: string, timeout = 12000): Promise<TxInfoReceipt> {\n return new Promise<TxInfoReceipt>(async (resolve, reject) => {\n const interval = setInterval(async () => {\n const receipt = await this.getKwilClient()\n [\"txInfoClient\"](txHash)\n .catch(() => ({ data: undefined, status: undefined }));\n switch (receipt.status) {\n case 200:\n if (receipt.data?.tx_result?.log !== undefined && receipt.data?.tx_result?.log.includes(\"ERROR\")) {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ))\n } else {\n resolve(receipt.data!);\n }\n break;\n case undefined:\n break;\n default:\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n }, 1000);\n setTimeout(() => {\n clearInterval(interval);\n reject(new Error(\"Transaction failed: Timeout\"));\n }, timeout);\n });\n }\n\n /**\n * Returns the Kwil signer used by the client.\n * @returns An instance of KwilSigner.\n */\n getKwilSigner(): KwilSigner {\n return new KwilSigner(\n this.signerInfo.signer,\n this.address().getAddress(),\n );\n }\n\n /**\n * Returns the Kwil client used by the client.\n * @returns An instance of Kwil.\n * @throws If the Kwil client is not initialized.\n */\n getKwilClient(): Kwil<EnvironmentType> {\n if (!this.kwilClient) {\n throw new Error(\"Kwil client not initialized\");\n }\n return this.kwilClient;\n }\n\n /**\n * Returns the Neon connection string used by the client.\n */\n getNeonConnectionString(): string | undefined {\n return this.neonConnectionString;\n }\n\n /**\n * Deploys a new stream.\n * @param streamId - The ID of the stream to deploy.\n * @param streamType - The type of the stream.\n * @param synchronous - Whether the deployment should be synchronous.\n * @param contractVersion\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async deployStream(\n streamId: StreamId,\n streamType: StreamType,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n neonConnectionString: this.getNeonConnectionString(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param stream - The StreamLocator of the stream to destroy.\n * @param synchronous - Whether the destruction should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async destroyStream(\n stream: StreamLocator,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deleteStream({\n stream,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Loads an already deployed stream, permitting its API usage.\n * @returns An instance of IStream.\n */\n loadAction(): Action {\n return new Action(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads a primitive stream.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveAction(): PrimitiveAction {\n return PrimitiveAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads a composed stream.\n * @returns An instance of IComposedStream.\n */\n loadComposedAction(): ComposedAction {\n return ComposedAction.fromStream(this.loadAction(), this.getNeonConnectionString());\n }\n\n /**\n * Creates a new stream locator.\n * @param streamId - The ID of the stream.\n * @returns A StreamLocator object.\n */\n ownStreamLocator(streamId: StreamId): StreamLocator {\n return {\n streamId,\n dataProvider: this.address(),\n };\n }\n\n /**\n * Returns the address of the signer used by the client.\n * @returns An instance of EthereumAddress.\n */\n address(): EthereumAddress {\n return new EthereumAddress(this.signerInfo.address);\n }\n\n /**\n * Returns all streams from the TN network.\n * @param input - The input parameters for listing streams.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getListStreams(input: ListStreamsInput): Promise<TNStream[]> {\n return listStreams(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Returns the last write activity across streams.\n * @param input - The input parameters for getting last transactions.\n * @returns A promise that resolves to a list of last transactions.\n */\n async getLastTransactions(input: GetLastTransactionsInput): Promise<any[]> {\n return getLastTransactions(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.\n * @param provider - The provider URL.\n * @returns A promise that resolves to the chain ID.\n */\n public static async getDefaultChainId(provider: string) {\n const kwilClient = new Client({\n kwilProvider: provider,\n });\n const chainInfo = await kwilClient[\"chainInfoClient\"]();\n return chainInfo.data?.chain_id;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAQtD,4BAA+B;AAC/B,0BAA6B;AAC7B,0BAA6B;AAC7B,6BAAgC;AAChC,oBAAuB;AAGvB,6BAAgC;AAEhC,yBAA4B;AAC5B,iCAAoC;AA+
|
|
4
|
+
"sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { KwilConfig } from \"@kwilteam/kwil-js/dist/api_client/config\";\nimport { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { EthSigner } from \"@kwilteam/kwil-js/dist/core/signature\";\nimport { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { TxInfoReceipt } from \"@kwilteam/kwil-js/dist/core/txQuery\";\nimport { ComposedAction } from \"../contracts-api/composedAction\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { deleteStream } from \"../contracts-api/deleteStream\";\nimport { PrimitiveAction } from \"../contracts-api/primitiveAction\";\nimport { Action } from \"../contracts-api/action\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator, TNStream } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listStreams } from \"./listStreams\";\nimport { getLastTransactions } from \"./getLastTransactions\";\nimport { RoleManagement } from \"../contracts-api/roleManagement\";\nimport { OwnerIdentifier } from \"../types/role\";\n\nexport interface SignerInfo {\n // we need to have the address upfront to create the KwilSigner, instead of relying on the signer to return it asynchronously\n address: string;\n signer: EthSigner;\n}\n\nexport type TNClientOptions = {\n endpoint: string;\n signerInfo: SignerInfo;\n} & Omit<KwilConfig, \"kwilProvider\">;\n\nexport interface ListStreamsInput {\n dataProvider?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n blockHeight?: number;\n}\n\n/**\n * @param dataProvider optional address; when omitted or null, returns for all providers\n * @param limitSize max rows to return (default 6, max 100)\n */\nexport interface GetLastTransactionsInput {\n dataProvider?: string;\n limitSize?: number;\n}\n\nexport abstract class BaseTNClient<T extends EnvironmentType> {\n protected kwilClient: Kwil<T> | undefined;\n protected signerInfo: SignerInfo;\n\n protected constructor(options: TNClientOptions) {\n this.signerInfo = options.signerInfo;\n }\n\n /**\n * Waits for a transaction to be mined by TN.\n * @param txHash - The transaction hash to wait for.\n * @param timeout - The timeout in milliseconds.\n * @returns A promise that resolves to the transaction info receipt.\n */\n async waitForTx(txHash: string, timeout = 12000): Promise<TxInfoReceipt> {\n return new Promise<TxInfoReceipt>(async (resolve, reject) => {\n const interval = setInterval(async () => {\n const receipt = await this.getKwilClient()\n [\"txInfoClient\"](txHash)\n .catch(() => ({ data: undefined, status: undefined }));\n switch (receipt.status) {\n case 200:\n if (receipt.data?.tx_result?.log !== undefined && receipt.data?.tx_result?.log.includes(\"ERROR\")) {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ))\n } else {\n resolve(receipt.data!);\n }\n break;\n case undefined:\n break;\n default:\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n }, 1000);\n setTimeout(() => {\n clearInterval(interval);\n reject(new Error(\"Transaction failed: Timeout\"));\n }, timeout);\n });\n }\n\n /**\n * Returns the Kwil signer used by the client.\n * @returns An instance of KwilSigner.\n */\n getKwilSigner(): KwilSigner {\n return new KwilSigner(\n this.signerInfo.signer,\n this.address().getAddress(),\n );\n }\n\n /**\n * Returns the Kwil client used by the client.\n * @returns An instance of Kwil.\n * @throws If the Kwil client is not initialized.\n */\n getKwilClient(): Kwil<EnvironmentType> {\n if (!this.kwilClient) {\n throw new Error(\"Kwil client not initialized\");\n }\n return this.kwilClient;\n }\n\n /**\n * Deploys a new stream.\n * @param streamId - The ID of the stream to deploy.\n * @param streamType - The type of the stream.\n * @param synchronous - Whether the deployment should be synchronous.\n * @param contractVersion\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async deployStream(\n streamId: StreamId,\n streamType: StreamType,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param stream - The StreamLocator of the stream to destroy.\n * @param synchronous - Whether the destruction should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async destroyStream(\n stream: StreamLocator,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deleteStream({\n stream,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Loads an already deployed stream, permitting its API usage.\n * @returns An instance of IStream.\n */\n loadAction(): Action {\n return new Action(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads a primitive stream.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveAction(): PrimitiveAction {\n return PrimitiveAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads a composed stream.\n * @returns An instance of IComposedStream.\n */\n loadComposedAction(): ComposedAction {\n return ComposedAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads the role management contract API, permitting its RBAC usage.\n */\n loadRoleManagementAction(): RoleManagement {\n return RoleManagement.fromClient(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Creates a new stream locator.\n * @param streamId - The ID of the stream.\n * @returns A StreamLocator object.\n */\n ownStreamLocator(streamId: StreamId): StreamLocator {\n return {\n streamId,\n dataProvider: this.address(),\n };\n }\n\n /**\n * Returns the address of the signer used by the client.\n * @returns An instance of EthereumAddress.\n */\n address(): EthereumAddress {\n return new EthereumAddress(this.signerInfo.address);\n }\n\n /**\n * Returns all streams from the TN network.\n * @param input - The input parameters for listing streams.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getListStreams(input: ListStreamsInput): Promise<TNStream[]> {\n return listStreams(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Returns the last write activity across streams.\n * @param input - The input parameters for getting last transactions.\n * @returns A promise that resolves to a list of last transactions.\n */\n async getLastTransactions(input: GetLastTransactionsInput): Promise<any[]> {\n return getLastTransactions(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.\n * @param provider - The provider URL.\n * @returns A promise that resolves to the chain ID.\n */\n public static async getDefaultChainId(provider: string) {\n const kwilClient = new Client({\n kwilProvider: provider,\n });\n const chainInfo = await kwilClient[\"chainInfoClient\"]();\n return chainInfo.data?.chain_id;\n }\n\n /*\n * High-level role-management helpers. These wrap the lower-level\n * RoleManagement contract calls and expose a simpler API on the\n * TN client.\n */\n\n /** Grants a role to one or more wallets. */\n async grantRole(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress | EthereumAddress[];\n synchronous?: boolean;\n }): Promise<string> {\n const rm = this.loadRoleManagementAction();\n const walletsArr: EthereumAddress[] = Array.isArray(input.wallets)\n ? input.wallets\n : [input.wallets];\n const tx = await rm.grantRole(\n {\n owner: input.owner,\n roleName: input.roleName,\n wallets: walletsArr,\n },\n input.synchronous,\n );\n return tx.data?.tx_hash as unknown as string;\n }\n\n /** Revokes a role from one or more wallets. */\n async revokeRole(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress | EthereumAddress[];\n synchronous?: boolean;\n }): Promise<string> {\n const rm = this.loadRoleManagementAction();\n const walletsArr: EthereumAddress[] = Array.isArray(input.wallets)\n ? input.wallets\n : [input.wallets];\n const tx = await rm.revokeRole(\n {\n owner: input.owner,\n roleName: input.roleName,\n wallets: walletsArr,\n },\n input.synchronous,\n );\n return tx.data?.tx_hash as unknown as string;\n }\n\n /**\n * Checks if a wallet is member of a role.\n * Returns true if the wallet is a member.\n */\n async isMemberOf(input: {\n owner: OwnerIdentifier;\n roleName: string;\n wallet: EthereumAddress;\n }): Promise<boolean> {\n const rm = this.loadRoleManagementAction();\n const res = await rm.areMembersOf({\n owner: input.owner,\n roleName: input.roleName,\n wallets: [input.wallet],\n });\n return res.length > 0 && res[0].isMember;\n }\n\n /**\n * Lists role members \u2013 currently unsupported in the\n * smart-contract layer.\n */\n async listRoleMembers(input: {\n owner: OwnerIdentifier;\n roleName: string;\n limit?: number;\n offset?: number;\n }): Promise<import(\"../types/role\").RoleMember[]> {\n const rm = this.loadRoleManagementAction();\n return rm.listRoleMembers({\n owner: input.owner,\n roleName: input.roleName,\n limit: input.limit,\n offset: input.offset,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAQtD,4BAA+B;AAC/B,0BAA6B;AAC7B,0BAA6B;AAC7B,6BAAgC;AAChC,oBAAuB;AAGvB,6BAAgC;AAEhC,yBAA4B;AAC5B,iCAAoC;AACpC,4BAA+B;AA+BxB,IAAe,eAAf,MAAuD;AAAA,EAClD;AAAA,EACA;AAAA,EAEA,YAAY,SAA0B;AAC9C,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,UAAU,QAAgB,UAAU,MAA+B;AACvE,WAAO,IAAI,QAAuB,OAAO,SAAS,WAAW;AAC3D,YAAM,WAAW,YAAY,YAAY;AACvC,cAAM,UAAU,MAAM,KAAK,cAAc,EACtC,cAAc,EAAE,MAAM,EACtB,MAAM,OAAO,EAAE,MAAM,QAAW,QAAQ,OAAU,EAAE;AACvD,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MAAM;AAAA,MACb,QAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/nodeClient.ts"],
|
|
4
|
-
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { NodeKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\n\nexport class NodeTNClient extends BaseTNClient<EnvironmentType.NODE> {\n constructor(options: TNClientOptions) {\n super(options);\n this.kwilClient = new NodeKwil({\n ...options,\n kwilProvider: options.endpoint,\n });\n }\n}\n\nexport default NodeTNClient;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAyB;AACzB,oBAA8C;AAEvC,IAAM,eAAN,cAA2B,2BAAmC;AAAA,EACnE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,wBAAS;AAAA,MAC7B,GAAG;AAAA,MACH,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,qBAAQ;",
|
|
4
|
+
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { NodeKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\n\nexport class NodeTNClient extends BaseTNClient<EnvironmentType.NODE> {\n constructor(options: TNClientOptions) {\n super(options);\n this.kwilClient = new NodeKwil({\n ...options,\n timeout: options.timeout ?? 30000,\n kwilProvider: options.endpoint,\n });\n }\n}\n\nexport default NodeTNClient;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAyB;AACzB,oBAA8C;AAEvC,IAAM,eAAN,cAA2B,2BAAmC;AAAA,EACnE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,wBAAS;AAAA,MAC7B,GAAG;AAAA,MACH,SAAS,QAAQ,WAAW;AAAA,MAC5B,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -77,8 +77,9 @@ var Action = class {
|
|
|
77
77
|
* Returns the records of the stream within the given date range
|
|
78
78
|
*/
|
|
79
79
|
async getRecord(input) {
|
|
80
|
+
const prefix = input.prefix ? input.prefix : "";
|
|
80
81
|
const result = await this.call(
|
|
81
|
-
"get_record",
|
|
82
|
+
prefix + "get_record",
|
|
82
83
|
{
|
|
83
84
|
$data_provider: input.stream.dataProvider.getAddress(),
|
|
84
85
|
$stream_id: input.stream.streamId.getId(),
|
|
@@ -98,8 +99,9 @@ var Action = class {
|
|
|
98
99
|
* Returns the index of the stream within the given date range
|
|
99
100
|
*/
|
|
100
101
|
async getIndex(input) {
|
|
102
|
+
const prefix = input.prefix ? input.prefix : "";
|
|
101
103
|
const result = await this.call(
|
|
102
|
-
"get_index",
|
|
104
|
+
prefix + "get_index",
|
|
103
105
|
{
|
|
104
106
|
$data_provider: input.stream.dataProvider.getAddress(),
|
|
105
107
|
$stream_id: input.stream.streamId.getId(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/action.ts"],
|
|
4
|
-
"sourcesContent": ["import {KwilSigner, NodeKwil, WebKwil} from \"@kwilteam/kwil-js\";\nimport { ActionBody } from '@kwilteam/kwil-js/dist/core/action';\nimport {NamedParams} from \"@kwilteam/kwil-js/dist/core/action\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { Either } from \"monads-io\";\nimport { DateString } from \"../types/other\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { head } from \"../util/head\";\nimport { StreamId } from \"../util/StreamId\";\nimport { toVisibilityEnum, VisibilityEnum } from \"../util/visibility\";\nimport {\n MetadataKey,\n MetadataKeyValueMap,\n MetadataTableKey,\n MetadataValueTypeForKey,\n StreamType,\n} from \"./contractValues\";\nimport {ValueType} from \"@kwilteam/kwil-js/dist/utils/types\";\n\nexport interface GetRecordInput {\n stream: StreamLocator;\n from?: number;\n to?: number;\n frozenAt?: number;\n baseTime?: DateString | number;\n}\n\nexport interface GetFirstRecordInput {\n stream: StreamLocator;\n after?: number;\n frozenAt?: number;\n}\n\nexport interface StreamRecord {\n eventTime: number;\n value: string;\n}\n\nexport interface GetIndexChangeInput extends GetRecordInput {\n timeInterval: number;\n}\n\nexport class Action {\n protected kwilClient: WebKwil | NodeKwil;\n protected kwilSigner: KwilSigner;\n constructor(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n ) {\n this.kwilClient = kwilClient;\n this.kwilSigner = kwilSigner;\n }\n\n /**\n * Executes a method on the stream\n */\n protected async executeWithNamedParams(\n method: string,\n inputs: NamedParams[],\n ): Promise<GenericResponse<TxReceipt>> {\n return this.kwilClient.execute({\n namespace: \"main\",\n name: method,\n inputs,\n description: `TN SDK - Executing method on stream: ${method}`,\n },\n this.kwilSigner,\n );\n }\n\n /**\n * Executes a method on the stream\n */\n protected async executeWithActionBody(\n inputs: ActionBody,\n synchronous: boolean = false,\n ): Promise<GenericResponse<TxReceipt>> {\n return this.kwilClient.execute(inputs, this.kwilSigner, synchronous);\n }\n\n /**\n * Calls a method on the stream\n */\n protected async call<T>(\n method: string,\n inputs: NamedParams,\n ): Promise<Either<number, T>> {\n const result = await this.kwilClient.call(\n {\n namespace: \"main\",\n name: method,\n inputs: inputs,\n },\n this.kwilSigner,\n );\n\n if (result.status !== 200) {\n return Either.left(result.status);\n }\n\n return Either.right(result.data?.result as T);\n }\n\n /**\n * Returns the records of the stream within the given date range\n */\n public async getRecord(input: GetRecordInput): Promise<StreamRecord[]> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n \"get_record\",\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt,\n }\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * Returns the index of the stream within the given date range\n */\n public async getIndex(input: GetRecordInput): Promise<StreamRecord[]> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n \"get_index\",\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt,\n $base_time: input.baseTime,\n }\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * Returns the type of the stream\n */\n public async getType(\n stream: StreamLocator,\n ): Promise<StreamType> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.TypeKey);\n\n if (!result) {\n throw new Error(\"Failed to get stream type\");\n }\n\n const type = head(result).unwrapOrElse(() => {\n throw new Error(\n \"Failed to get stream type. Check if the stream is initialized.\",\n );\n });\n\n const validTypes = [StreamType.Primitive, StreamType.Composed];\n\n if (!validTypes.includes(type.value as StreamType)) {\n throw new Error(`Invalid stream type: ${type.value}`);\n }\n\n return type.value as StreamType;\n }\n\n /**\n * Returns the first record of the stream\n */\n public async getFirstRecord(\n input: GetFirstRecordInput,\n ): Promise<StreamRecord | null> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n \"get_first_record\",\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $after: input.after,\n $frozen_at: input.frozenAt,\n }\n );\n\n return result\n .mapRight(head)\n .mapRight((result) =>\n result\n .map((result) => ({\n eventTime: result.event_time,\n value: result.value,\n }))\n .unwrapOr(null),\n )\n .throw();\n }\n\n protected async setMetadata<K extends MetadataKey>(\n stream: StreamLocator,\n key: K,\n value: MetadataValueTypeForKey<K>,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.executeWithNamedParams(\"insert_metadata\", [{\n $data_provider: stream.dataProvider.getAddress(),\n $stream_id: stream.streamId.getId(),\n $key: key,\n $value: value,\n $val_type: MetadataKeyValueMap[key],\n },\n ]);\n }\n\n protected async getMetadata<K extends MetadataKey>(\n stream: StreamLocator,\n key: K,\n // onlyLatest: boolean = true,\n filteredRef?: string,\n limit?: number,\n offset?: number,\n orderBy?: string,\n ): Promise<\n { rowId: string; value: MetadataValueTypeForKey<K>; createdAt: number }[]\n > {\n const result = await this.call<\n {\n row_id: string;\n value_i: number;\n value_f: string;\n value_b: boolean;\n value_s: string;\n value_ref: string;\n created_at: number;\n }[]\n >(\"get_metadata\", {\n $data_provider: stream.dataProvider.getAddress(),\n $stream_id: stream.streamId.getId(),\n $key: key,\n $ref: filteredRef,\n $limit: limit,\n $offset: offset,\n $order_by: orderBy,\n },\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n rowId: row.row_id,\n value: row[\n MetadataTableKey[MetadataKeyValueMap[key as MetadataKey]]\n ] as MetadataValueTypeForKey<K>,\n createdAt: row.created_at,\n })),\n )\n .throw();\n }\n\n /**\n * Sets the read visibility of the stream\n */\n public async setReadVisibility(\n stream: StreamLocator,\n visibility: VisibilityEnum,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.ReadVisibilityKey,\n visibility.toString(),\n );\n }\n\n /**\n * Returns the read visibility of the stream\n */\n public async getReadVisibility(\n stream: StreamLocator,\n ): Promise<VisibilityEnum | null> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.ReadVisibilityKey);\n\n return head(result)\n .map((row) => toVisibilityEnum(row.value))\n .unwrapOr(null);\n }\n\n /**\n * Sets the compose visibility of the stream\n */\n public async setComposeVisibility(\n stream: StreamLocator,\n visibility: VisibilityEnum,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.ComposeVisibilityKey,\n visibility.toString(),\n );\n }\n\n /**\n * Returns the compose visibility of the stream\n */\n public async getComposeVisibility(\n stream: StreamLocator,\n ): Promise<VisibilityEnum | null> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.ComposeVisibilityKey);\n\n return head(result)\n .map((row) => toVisibilityEnum(row.value))\n .unwrapOr(null);\n }\n\n /**\n * Allows a wallet to read the stream\n */\n public async allowReadWallet(\n stream: StreamLocator,\n wallet: EthereumAddress,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.AllowReadWalletKey,\n wallet.getAddress(),\n );\n }\n\n /**\n * Disables a wallet from reading the stream\n */\n public async disableReadWallet(\n stream: StreamLocator,\n wallet: EthereumAddress,\n ): Promise<GenericResponse<TxReceipt>> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowReadWalletKey,\n wallet.getAddress(),\n );\n\n const row_id = head(result)\n .map((row) => row.rowId)\n .unwrapOr(null);\n\n if (!row_id) {\n throw new Error(\"Wallet not found in allowed list\");\n }\n\n return await this.disableMetadata(stream, row_id);\n }\n\n /**\n * Allows a stream to use this stream as child\n */\n public async allowComposeStream(\n stream: StreamLocator,\n wallet: StreamLocator,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.AllowComposeStreamKey,\n wallet.streamId.getId(),\n );\n }\n\n /**\n * Disables a stream from using this stream as child\n */\n public async disableComposeStream(\n stream: StreamLocator,\n wallet: StreamLocator,\n ): Promise<GenericResponse<TxReceipt>> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowComposeStreamKey,\n wallet.toString(),\n );\n\n const row_id = head(result)\n .map((row) => row.rowId)\n .unwrapOr(null);\n\n if (!row_id) {\n throw new Error(\"Stream not found in allowed list\");\n }\n\n return await this.disableMetadata(stream, row_id);\n }\n\n protected async disableMetadata(\n stream: StreamLocator,\n rowId: string,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.executeWithNamedParams(\"disable_metadata\", [{\n $data_provider: stream.dataProvider.getAddress(),\n $stream_id: stream.streamId.getId(),\n $row_id: rowId,\n }]);\n }\n\n /**\n * Returns the wallets allowed to read the stream\n */\n public async getAllowedReadWallets(\n stream: StreamLocator,\n ): Promise<EthereumAddress[]> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowReadWalletKey);\n\n return result\n .filter((row) => row.value)\n .map((row) => new EthereumAddress(row.value));\n }\n\n /**\n * Returns the streams allowed to compose the stream\n */\n public async getAllowedComposeStreams(\n stream: StreamLocator,\n ): Promise<StreamLocator[]> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowComposeStreamKey);\n\n return result\n .filter((row) => row.value)\n .map((row) => {\n const [streamId, dataProvider] = row.value.split(\":\");\n return {\n streamId: StreamId.fromString(streamId).throw(),\n dataProvider: new EthereumAddress(dataProvider),\n };\n });\n }\n\n /**\n * Returns the index change of the stream within the given date range\n */\n public async getIndexChange(\n input: GetIndexChangeInput,\n ): Promise<StreamRecord[]> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n \"get_index_change\", \n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt,\n $base_time: input.baseTime,\n $time_interval: input.timeInterval,\n }\n );\n\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * A custom method that accepts the procedure name and the input of GetRecordInput\n * Returns the result of the procedure in the same format as StreamRecord\n * I.e. a custom procedure named \"get_price\" that returns a list of date_value and value\n * can be called with customGetProcedure(\"get_price\", { dateFrom: \"2021-01-01\", dateTo: \"2021-01-31\" })\n */\n public async customGetProcedure(\n procedure: string,\n input: GetRecordInput,\n ): Promise<StreamRecord[]> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n procedure,\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt\n }\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n\n /**\n * A custom method that accepts the procedure name and custom input of type Record<string, any>\n * Returns the result of the procedure in the same format as StreamRecord\n * I.e. a custom procedure named \"get_custom_index\" that returns a list of date_value and value\n * can be called with customProcedureWithArgs(\"get_custom_index\", { $customArg1: \"value1\", $customArg2: \"value2\" })\n * where $customArg1 and $customArg2 are the arguments of the procedure\n * @param procedure\n * @param args\n */\n public async customProcedureWithArgs(\n procedure: string,\n args: Record<string, ValueType | ValueType[]>,\n ){\n const result = await this.call<{ event_time: number; value: string }[]>(\n procedure,\n args\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * Returns the size of database\n */\n public async getDatabaseSize(): Promise<BigInt> {\n const result = await this.call<{ database_size: BigInt }[]>(\"get_database_size\", {})\n return result\n .map((rows) => {\n const raw = rows[0].database_size;\n const asBigInt = BigInt(raw.toString());\n return asBigInt;\n }).throw();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAuB;AAGvB,6BAAgC;AAChC,kBAAqB;AACrB,sBAAyB;AACzB,wBAAiD;AACjD,4BAMO;
|
|
4
|
+
"sourcesContent": ["import {KwilSigner, NodeKwil, WebKwil} from \"@kwilteam/kwil-js\";\nimport { ActionBody } from '@kwilteam/kwil-js/dist/core/action';\nimport {NamedParams} from \"@kwilteam/kwil-js/dist/core/action\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { Either } from \"monads-io\";\nimport { DateString } from \"../types/other\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { head } from \"../util/head\";\nimport { StreamId } from \"../util/StreamId\";\nimport { toVisibilityEnum, VisibilityEnum } from \"../util/visibility\";\nimport {\n MetadataKey,\n MetadataKeyValueMap,\n MetadataTableKey,\n MetadataValueTypeForKey,\n StreamType,\n} from \"./contractValues\";\nimport {ValueType} from \"@kwilteam/kwil-js/dist/utils/types\";\n\nexport interface GetRecordInput {\n stream: StreamLocator;\n from?: number;\n to?: number;\n frozenAt?: number;\n baseTime?: DateString | number;\n prefix?: string;\n}\n\nexport interface GetFirstRecordInput {\n stream: StreamLocator;\n after?: number;\n frozenAt?: number;\n}\n\nexport interface StreamRecord {\n eventTime: number;\n value: string;\n}\n\nexport interface GetIndexChangeInput extends GetRecordInput {\n timeInterval: number;\n}\n\nexport class Action {\n protected kwilClient: WebKwil | NodeKwil;\n protected kwilSigner: KwilSigner;\n constructor(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n ) {\n this.kwilClient = kwilClient;\n this.kwilSigner = kwilSigner;\n }\n\n /**\n * Executes a method on the stream\n */\n protected async executeWithNamedParams(\n method: string,\n inputs: NamedParams[],\n ): Promise<GenericResponse<TxReceipt>> {\n return this.kwilClient.execute({\n namespace: \"main\",\n name: method,\n inputs,\n description: `TN SDK - Executing method on stream: ${method}`,\n },\n this.kwilSigner,\n );\n }\n\n /**\n * Executes a method on the stream\n */\n protected async executeWithActionBody(\n inputs: ActionBody,\n synchronous: boolean = false,\n ): Promise<GenericResponse<TxReceipt>> {\n return this.kwilClient.execute(inputs, this.kwilSigner, synchronous);\n }\n\n /**\n * Calls a method on the stream\n */\n protected async call<T>(\n method: string,\n inputs: NamedParams,\n ): Promise<Either<number, T>> {\n const result = await this.kwilClient.call(\n {\n namespace: \"main\",\n name: method,\n inputs: inputs,\n },\n this.kwilSigner,\n );\n\n if (result.status !== 200) {\n return Either.left(result.status);\n }\n\n return Either.right(result.data?.result as T);\n }\n\n /**\n * Returns the records of the stream within the given date range\n */\n public async getRecord(input: GetRecordInput): Promise<StreamRecord[]> {\n const prefix = input.prefix ? input.prefix : \"\"\n const result = await this.call<{ event_time: number; value: string }[]>(\n prefix + \"get_record\",\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt,\n }\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * Returns the index of the stream within the given date range\n */\n public async getIndex(input: GetRecordInput): Promise<StreamRecord[]> {\n const prefix = input.prefix ? input.prefix : \"\"\n const result = await this.call<{ event_time: number; value: string }[]>(\n prefix + \"get_index\",\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt,\n $base_time: input.baseTime,\n }\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * Returns the type of the stream\n */\n public async getType(\n stream: StreamLocator,\n ): Promise<StreamType> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.TypeKey);\n\n if (!result) {\n throw new Error(\"Failed to get stream type\");\n }\n\n const type = head(result).unwrapOrElse(() => {\n throw new Error(\n \"Failed to get stream type. Check if the stream is initialized.\",\n );\n });\n\n const validTypes = [StreamType.Primitive, StreamType.Composed];\n\n if (!validTypes.includes(type.value as StreamType)) {\n throw new Error(`Invalid stream type: ${type.value}`);\n }\n\n return type.value as StreamType;\n }\n\n /**\n * Returns the first record of the stream\n */\n public async getFirstRecord(\n input: GetFirstRecordInput,\n ): Promise<StreamRecord | null> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n \"get_first_record\",\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $after: input.after,\n $frozen_at: input.frozenAt,\n }\n );\n\n return result\n .mapRight(head)\n .mapRight((result) =>\n result\n .map((result) => ({\n eventTime: result.event_time,\n value: result.value,\n }))\n .unwrapOr(null),\n )\n .throw();\n }\n\n protected async setMetadata<K extends MetadataKey>(\n stream: StreamLocator,\n key: K,\n value: MetadataValueTypeForKey<K>,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.executeWithNamedParams(\"insert_metadata\", [{\n $data_provider: stream.dataProvider.getAddress(),\n $stream_id: stream.streamId.getId(),\n $key: key,\n $value: value,\n $val_type: MetadataKeyValueMap[key],\n },\n ]);\n }\n\n protected async getMetadata<K extends MetadataKey>(\n stream: StreamLocator,\n key: K,\n // onlyLatest: boolean = true,\n filteredRef?: string,\n limit?: number,\n offset?: number,\n orderBy?: string,\n ): Promise<\n { rowId: string; value: MetadataValueTypeForKey<K>; createdAt: number }[]\n > {\n const result = await this.call<\n {\n row_id: string;\n value_i: number;\n value_f: string;\n value_b: boolean;\n value_s: string;\n value_ref: string;\n created_at: number;\n }[]\n >(\"get_metadata\", {\n $data_provider: stream.dataProvider.getAddress(),\n $stream_id: stream.streamId.getId(),\n $key: key,\n $ref: filteredRef,\n $limit: limit,\n $offset: offset,\n $order_by: orderBy,\n },\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n rowId: row.row_id,\n value: row[\n MetadataTableKey[MetadataKeyValueMap[key as MetadataKey]]\n ] as MetadataValueTypeForKey<K>,\n createdAt: row.created_at,\n })),\n )\n .throw();\n }\n\n /**\n * Sets the read visibility of the stream\n */\n public async setReadVisibility(\n stream: StreamLocator,\n visibility: VisibilityEnum,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.ReadVisibilityKey,\n visibility.toString(),\n );\n }\n\n /**\n * Returns the read visibility of the stream\n */\n public async getReadVisibility(\n stream: StreamLocator,\n ): Promise<VisibilityEnum | null> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.ReadVisibilityKey);\n\n return head(result)\n .map((row) => toVisibilityEnum(row.value))\n .unwrapOr(null);\n }\n\n /**\n * Sets the compose visibility of the stream\n */\n public async setComposeVisibility(\n stream: StreamLocator,\n visibility: VisibilityEnum,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.ComposeVisibilityKey,\n visibility.toString(),\n );\n }\n\n /**\n * Returns the compose visibility of the stream\n */\n public async getComposeVisibility(\n stream: StreamLocator,\n ): Promise<VisibilityEnum | null> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.ComposeVisibilityKey);\n\n return head(result)\n .map((row) => toVisibilityEnum(row.value))\n .unwrapOr(null);\n }\n\n /**\n * Allows a wallet to read the stream\n */\n public async allowReadWallet(\n stream: StreamLocator,\n wallet: EthereumAddress,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.AllowReadWalletKey,\n wallet.getAddress(),\n );\n }\n\n /**\n * Disables a wallet from reading the stream\n */\n public async disableReadWallet(\n stream: StreamLocator,\n wallet: EthereumAddress,\n ): Promise<GenericResponse<TxReceipt>> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowReadWalletKey,\n wallet.getAddress(),\n );\n\n const row_id = head(result)\n .map((row) => row.rowId)\n .unwrapOr(null);\n\n if (!row_id) {\n throw new Error(\"Wallet not found in allowed list\");\n }\n\n return await this.disableMetadata(stream, row_id);\n }\n\n /**\n * Allows a stream to use this stream as child\n */\n public async allowComposeStream(\n stream: StreamLocator,\n wallet: StreamLocator,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.setMetadata(\n stream,\n MetadataKey.AllowComposeStreamKey,\n wallet.streamId.getId(),\n );\n }\n\n /**\n * Disables a stream from using this stream as child\n */\n public async disableComposeStream(\n stream: StreamLocator,\n wallet: StreamLocator,\n ): Promise<GenericResponse<TxReceipt>> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowComposeStreamKey,\n wallet.toString(),\n );\n\n const row_id = head(result)\n .map((row) => row.rowId)\n .unwrapOr(null);\n\n if (!row_id) {\n throw new Error(\"Stream not found in allowed list\");\n }\n\n return await this.disableMetadata(stream, row_id);\n }\n\n protected async disableMetadata(\n stream: StreamLocator,\n rowId: string,\n ): Promise<GenericResponse<TxReceipt>> {\n return await this.executeWithNamedParams(\"disable_metadata\", [{\n $data_provider: stream.dataProvider.getAddress(),\n $stream_id: stream.streamId.getId(),\n $row_id: rowId,\n }]);\n }\n\n /**\n * Returns the wallets allowed to read the stream\n */\n public async getAllowedReadWallets(\n stream: StreamLocator,\n ): Promise<EthereumAddress[]> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowReadWalletKey);\n\n return result\n .filter((row) => row.value)\n .map((row) => new EthereumAddress(row.value));\n }\n\n /**\n * Returns the streams allowed to compose the stream\n */\n public async getAllowedComposeStreams(\n stream: StreamLocator,\n ): Promise<StreamLocator[]> {\n const result = await this.getMetadata(\n stream,\n MetadataKey.AllowComposeStreamKey);\n\n return result\n .filter((row) => row.value)\n .map((row) => {\n const [streamId, dataProvider] = row.value.split(\":\");\n return {\n streamId: StreamId.fromString(streamId).throw(),\n dataProvider: new EthereumAddress(dataProvider),\n };\n });\n }\n\n /**\n * Returns the index change of the stream within the given date range\n */\n public async getIndexChange(\n input: GetIndexChangeInput,\n ): Promise<StreamRecord[]> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n \"get_index_change\", \n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt,\n $base_time: input.baseTime,\n $time_interval: input.timeInterval,\n }\n );\n\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * A custom method that accepts the procedure name and the input of GetRecordInput\n * Returns the result of the procedure in the same format as StreamRecord\n * I.e. a custom procedure named \"get_price\" that returns a list of date_value and value\n * can be called with customGetProcedure(\"get_price\", { dateFrom: \"2021-01-01\", dateTo: \"2021-01-31\" })\n */\n public async customGetProcedure(\n procedure: string,\n input: GetRecordInput,\n ): Promise<StreamRecord[]> {\n const result = await this.call<{ event_time: number; value: string }[]>(\n procedure,\n {\n $data_provider: input.stream.dataProvider.getAddress(),\n $stream_id: input.stream.streamId.getId(),\n $from: input.from,\n $to: input.to,\n $frozen_at: input.frozenAt\n }\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n\n /**\n * A custom method that accepts the procedure name and custom input of type Record<string, any>\n * Returns the result of the procedure in the same format as StreamRecord\n * I.e. a custom procedure named \"get_custom_index\" that returns a list of date_value and value\n * can be called with customProcedureWithArgs(\"get_custom_index\", { $customArg1: \"value1\", $customArg2: \"value2\" })\n * where $customArg1 and $customArg2 are the arguments of the procedure\n * @param procedure\n * @param args\n */\n public async customProcedureWithArgs(\n procedure: string,\n args: Record<string, ValueType | ValueType[]>,\n ){\n const result = await this.call<{ event_time: number; value: string }[]>(\n procedure,\n args\n );\n return result\n .mapRight((result) =>\n result.map((row) => ({\n eventTime: row.event_time,\n value: row.value,\n })),\n )\n .throw();\n }\n\n /**\n * Returns the size of database\n */\n public async getDatabaseSize(): Promise<BigInt> {\n const result = await this.call<{ database_size: BigInt }[]>(\"get_database_size\", {})\n return result\n .map((rows) => {\n const raw = rows[0].database_size;\n const asBigInt = BigInt(raw.toString());\n return asBigInt;\n }).throw();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAuB;AAGvB,6BAAgC;AAChC,kBAAqB;AACrB,sBAAyB;AACzB,wBAAiD;AACjD,4BAMO;AA2BA,IAAM,SAAN,MAAa;AAAA,EACR;AAAA,EACA;AAAA,EACV,YACE,YACA,YACA;AAC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AM;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,kBAAmC;AAC9C,UAAM,SAAS,MAAM,KAAK,KAAkC,qBAAqB,CAAC,CAAC;AACnF,WAAO,OACJ,IAAI,CAAC,SAAS;AACb,YAAM,MAAM,KAAK,CAAC,EAAE;AACpB,YAAM,WAAW,OAAO,IAAI,SAAS,CAAC;AACtC,aAAO;AAAA,IACT,CAAC,EAAE,MAAM;AAAA,EACb;AACF;",
|
|
6
6
|
"names": ["result"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/contracts-api/composedAction.ts
|
|
@@ -38,15 +28,11 @@ var import_kwil_js = require("@kwilteam/kwil-js");
|
|
|
38
28
|
var import_EthereumAddress = require("../util/EthereumAddress.cjs");
|
|
39
29
|
var import_StreamId = require("../util/StreamId.cjs");
|
|
40
30
|
var import_action = require("./action.cjs");
|
|
41
|
-
var import_pg = __toESM(require("pg"), 1);
|
|
42
31
|
var DataType = import_kwil_js.Utils.DataType;
|
|
43
|
-
var { Pool } = import_pg.default;
|
|
44
32
|
var ErrorStreamNotComposed = "stream is not a composed stream";
|
|
45
33
|
var ComposedAction = class _ComposedAction extends import_action.Action {
|
|
46
|
-
|
|
47
|
-
constructor(kwilClient, kwilSigner, neonConnectionString) {
|
|
34
|
+
constructor(kwilClient, kwilSigner) {
|
|
48
35
|
super(kwilClient, kwilSigner);
|
|
49
|
-
this.neonConnectionString = neonConnectionString;
|
|
50
36
|
}
|
|
51
37
|
/**
|
|
52
38
|
* Returns the taxonomy of the stream
|
|
@@ -130,53 +116,17 @@ var ComposedAction = class _ComposedAction extends import_action.Action {
|
|
|
130
116
|
$start_date: DataType.Int
|
|
131
117
|
}
|
|
132
118
|
});
|
|
133
|
-
if (this.neonConnectionString) {
|
|
134
|
-
const pool = new Pool({ connectionString: this.neonConnectionString });
|
|
135
|
-
const parentProvider = taxonomy.stream.dataProvider.getAddress().toLowerCase();
|
|
136
|
-
const parentStreamId = taxonomy.stream.streamId.getId();
|
|
137
|
-
const startDateText = String(taxonomy.startDate);
|
|
138
|
-
for (const item of taxonomy.taxonomyItems) {
|
|
139
|
-
const childProvider = item.childStream.dataProvider.getAddress().toLowerCase();
|
|
140
|
-
const childStreamId = item.childStream.streamId.getId();
|
|
141
|
-
const weight = item.weight;
|
|
142
|
-
await pool.query(
|
|
143
|
-
`INSERT INTO taxonomies
|
|
144
|
-
(parent_data_provider, parent_stream_id,
|
|
145
|
-
child_data_provider, child_stream_id,
|
|
146
|
-
weight, start_date)
|
|
147
|
-
VALUES ($1, $2, $3, $4, $5, $6)
|
|
148
|
-
ON CONFLICT ON CONSTRAINT unique_parent_child DO NOTHING`,
|
|
149
|
-
[
|
|
150
|
-
parentProvider,
|
|
151
|
-
parentStreamId,
|
|
152
|
-
childProvider,
|
|
153
|
-
childStreamId,
|
|
154
|
-
weight,
|
|
155
|
-
startDateText
|
|
156
|
-
]
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
await pool.end();
|
|
160
|
-
console.log("Successfully inserted taxonomy into Explorer DB", {
|
|
161
|
-
parentStreamId,
|
|
162
|
-
childStreamId: childStreamIds,
|
|
163
|
-
weight: weights,
|
|
164
|
-
startDate: startDateText
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
119
|
return txHash;
|
|
168
120
|
}
|
|
169
121
|
/**
|
|
170
122
|
* Creates a ComposedStream from a base Stream
|
|
171
123
|
* @param stream The base stream to convert
|
|
172
|
-
* @param neonConnectionString The Neon connection string
|
|
173
124
|
* @returns A ComposedStream instance
|
|
174
125
|
*/
|
|
175
|
-
static fromStream(stream
|
|
126
|
+
static fromStream(stream) {
|
|
176
127
|
return new _ComposedAction(
|
|
177
128
|
stream["kwilClient"],
|
|
178
|
-
stream["kwilSigner"]
|
|
179
|
-
neonConnectionString
|
|
129
|
+
stream["kwilSigner"]
|
|
180
130
|
);
|
|
181
131
|
}
|
|
182
132
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/composedAction.ts"],
|
|
4
|
-
"sourcesContent": ["import {KwilSigner, NodeKwil, Utils, WebKwil} from \"@kwilteam/kwil-js\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { DateString } from \"../types/other\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { Action } from \"./action\";\nimport DataType = Utils.DataType;\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import {KwilSigner, NodeKwil, Utils, WebKwil} from \"@kwilteam/kwil-js\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { DateString } from \"../types/other\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { Action } from \"./action\";\nimport DataType = Utils.DataType;\n\nexport const ErrorStreamNotComposed = \"stream is not a composed stream\";\n\nexport interface TaxonomySet {\n stream: StreamLocator;\n taxonomyItems: TaxonomyItem[];\n startDate: number;\n}\n\nexport interface TaxonomyItem {\n childStream: StreamLocator;\n weight: string;\n}\n\nexport interface DescribeTaxonomiesParams {\n stream: StreamLocator;\n /**\n * if true, will return the latest version of the taxonomy only\n */\n latestGroupSequence: boolean;\n}\n\nexport class ComposedAction extends Action {\n constructor(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n ) {\n super(kwilClient, kwilSigner);\n }\n\n /**\n * Returns the taxonomy of the stream\n * @param params Parameters for describing taxonomies\n * @returns A promise that resolves to the taxonomy\n */\n public async describeTaxonomies(\n params: DescribeTaxonomiesParams,\n ): Promise<TaxonomySet[]> {\n type TaxonomyResult = {\n data_provider: string;\n stream_id: string;\n child_data_provider: string;\n child_stream_id: string;\n weight: string;\n created_at: number;\n group_sequence: number;\n start_date: number;\n }[];\n\n const result = await this.call<TaxonomyResult>(\n \"describe_taxonomies\",\n {\n $data_provider: params.stream.dataProvider.getAddress(),\n $stream_id: params.stream.streamId.getId(),\n $latest_group_sequence: params.latestGroupSequence,\n },\n );\n\n\n\n return result\n .mapRight((records) => {\n const taxonomyItems: Map<DateString, TaxonomyItem[]> = records.reduce(\n (acc, record) => {\n const currentArray = acc.get(record.start_date.toString()) || [];\n currentArray.push({\n childStream: {\n streamId: StreamId.fromString(record.child_stream_id).throw(),\n dataProvider: EthereumAddress.fromString(\n record.child_data_provider,\n ).throw(),\n },\n weight: record.weight,\n });\n acc.set(record.start_date.toString(), currentArray);\n return acc;\n },\n new Map<DateString, TaxonomyItem[]>(),\n );\n\n return Array.from(taxonomyItems.entries()).map(\n ([startDate, taxonomyItems]) => ({\n stream: {\n streamId: StreamId.fromString(records[0].stream_id).throw(),\n dataProvider: EthereumAddress.fromString(\n records[0].data_provider,\n ).throw(),\n },\n taxonomyItems,\n startDate: Number(startDate)\n }),\n );\n })\n .throw();\n }\n\n /**\n * Sets the taxonomy of the stream\n * @param taxonomy The taxonomy to set\n * @returns A promise that resolves to the transaction receipt\n */\n public async setTaxonomy(\n taxonomy: TaxonomySet,\n ): Promise<GenericResponse<TxReceipt>> {\n const childDataProviders: string[] = [];\n const childStreamIds: string[] = [];\n const weights: string[] = [];\n\n for (const item of taxonomy.taxonomyItems) {\n childDataProviders.push(item.childStream.dataProvider\n .getAddress());\n childStreamIds.push(item.childStream.streamId.getId());\n weights.push(item.weight.toString());\n }\n\n const txHash = await this.executeWithActionBody({\n namespace: \"main\",\n name: \"insert_taxonomy\",\n inputs: [\n {\n $data_provider: taxonomy.stream.dataProvider.getAddress(),\n $stream_id: taxonomy.stream.streamId.getId(),\n $child_data_providers: childDataProviders,\n $child_stream_ids: childStreamIds,\n $weights: weights,\n $start_date: taxonomy.startDate\n },\n ],\n types: {\n $data_provider: DataType.Text,\n $stream_id: DataType.Text,\n $child_data_providers: DataType.TextArray,\n $child_stream_ids: DataType.TextArray,\n $weights: DataType.NumericArray(36,18),\n $start_date: DataType.Int\n }});\n\n return txHash;\n }\n\n /**\n * Creates a ComposedStream from a base Stream\n * @param stream The base stream to convert\n * @returns A ComposedStream instance\n */\n public static fromStream(stream: Action): ComposedAction {\n return new ComposedAction(\n stream[\"kwilClient\"],\n stream[\"kwilSigner\"],\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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