@trufnetwork/sdk-js 0.3.4 → 0.3.6
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 +85 -16
- 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/listStreams.cjs +3 -1
- package/dist/cjs/client/listStreams.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 -41
- package/dist/cjs/contracts-api/composedAction.cjs.map +2 -2
- 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/cjs/types/stream.cjs.map +1 -1
- 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/listStreams.mjs +3 -1
- package/dist/esm/client/listStreams.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 -45
- 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 +41 -8
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/listStreams.d.ts +2 -2
- package/dist/types/client/listStreams.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/dist/types/types/stream.d.ts +6 -0
- package/dist/types/types/stream.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -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;\nimport pg from \"pg\";\nconst { Pool } = pg;\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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAmD;AAKnD,6BAAgC;AAChC,sBAAyB;AACzB,oBAAuB;AAEvB,gBAAe;AADf,IAAO,WAAW,qBAAM;AAExB,IAAM,EAAE,KAAK,IAAI,UAAAA;AAEV,IAAM,yBAAyB;AAqB/B,IAAM,iBAAN,MAAM,wBAAuB,qBAAO;AAAA,
|
|
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;\nimport pg from \"pg\";\nconst { Pool } = pg;\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;AAAA,qBAAmD;AAKnD,6BAAgC;AAChC,sBAAyB;AACzB,oBAAuB;AAEvB,gBAAe;AADf,IAAO,WAAW,qBAAM;AAExB,IAAM,EAAE,KAAK,IAAI,UAAAA;AAEV,IAAM,yBAAyB;AAqB/B,IAAM,iBAAN,MAAM,wBAAuB,qBAAO;AAAA,EACzC,YACE,YACA,YACA;AACA,UAAM,YAAY,UAAU;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,mBACX,QACwB;AAYxB,UAAM,SAAS,MAAM,KAAK;AAAA,MACtB;AAAA,MACA;AAAA,QACI,gBAAgB,OAAO,OAAO,aAAa,WAAW;AAAA,QACtD,YAAY,OAAO,OAAO,SAAS,MAAM;AAAA,QACzC,wBAAwB,O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AM,SAAS,MAAM,KAAK,sBAAsB;AAAA,MAC5C,WAAW;AAAA,MACX,MAAM;AAAA,MACN,QAAQ;AAAA,QACN;AAAA,UACE,gBAAgB,SAAS,OAAO,aAAa,WAAW;AAAA,UACxD,YAAY,SAAS,OAAO,SAAS,MAAM;AAAA,UAC3C,uBAAuB;AAAA,UACvB,mBAAmB;AAAA,UACnB,UAAU;AAAA,UACV,aAAa,SAAS;AAAA,QACxB;AAAA,MACF;AAAA,MACA,OAAO;AAAA,QACL,gBAAgB,SAAS;AAAA,QACzB,YAAY,SAAS;AAAA,QACrB,uBAAuB,SAAS;AAAA,QAChC,mBAAmB,SAAS;AAAA,QAC5B,UAAU,SAAS,aAAa,IAAG,EAAE;AAAA,QACrC,aAAa,SAAS;AAAA,MACxB;AAAA,IAAC,CAAC;AAEN,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAc,WAAW,QAAgC;AACvD,WAAO,IAAI;AAAA,MACT,OAAO,YAAY;AAAA,MACnB,OAAO,YAAY;AAAA,IACrB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["pg", "taxonomyItems"]
|
|
7
7
|
}
|
|
@@ -50,20 +50,6 @@ async function deployStream(input) {
|
|
|
50
50
|
input.kwilSigner,
|
|
51
51
|
input.synchronous
|
|
52
52
|
);
|
|
53
|
-
if (input.neonConnectionString) {
|
|
54
|
-
console.log("Neon connection detected, attempting to insert into DB...");
|
|
55
|
-
const signer = input.kwilSigner.signer;
|
|
56
|
-
const dataProvider = signer.address.toLowerCase();
|
|
57
|
-
const pool = new Pool({ connectionString: input.neonConnectionString });
|
|
58
|
-
await pool.query(
|
|
59
|
-
`INSERT INTO streams (data_provider, stream_id, type, stream_name, display_name, categories, owner_wallet, geography, tags)
|
|
60
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
61
|
-
ON CONFLICT (data_provider, stream_id) DO NOTHING`,
|
|
62
|
-
[dataProvider, input.streamId.getId(), input.streamType, input.streamId.getName(), input.streamId.getName(), "{External}", dataProvider, "Global", "{External}"]
|
|
63
|
-
);
|
|
64
|
-
await pool.end();
|
|
65
|
-
console.log("successfully inserted into Explorer DB", input.streamId.getName());
|
|
66
|
-
}
|
|
67
53
|
return txHash;
|
|
68
54
|
} catch (error) {
|
|
69
55
|
throw new Error(`Failed to deploy stream: ${error}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/deployStream.ts"],
|
|
4
|
-
"sourcesContent": ["import {StreamType} from \"./contractValues\";\nimport {TxReceipt} from \"@kwilteam/kwil-js/dist/core/tx\";\nimport {Kwil} from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport {KwilSigner} from \"@kwilteam/kwil-js\";\nimport {GenericResponse} from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport {StreamId} from \"../util/StreamId\";\nimport pg from \"pg\";\nconst { Pool } = pg;\n\nexport interface DeployStreamInput {\n streamId: StreamId;\n streamType: StreamType;\n kwilClient: Kwil<any>;\n kwilSigner: KwilSigner;\n synchronous?: boolean;\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gBAAe;AACf,IAAM,EAAE,KAAK,IAAI,UAAAA;
|
|
4
|
+
"sourcesContent": ["import {StreamType} from \"./contractValues\";\nimport {TxReceipt} from \"@kwilteam/kwil-js/dist/core/tx\";\nimport {Kwil} from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport {KwilSigner} from \"@kwilteam/kwil-js\";\nimport {GenericResponse} from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport {StreamId} from \"../util/StreamId\";\nimport pg from \"pg\";\nconst { Pool } = pg;\n\nexport interface DeployStreamInput {\n streamId: StreamId;\n streamType: StreamType;\n kwilClient: Kwil<any>;\n kwilSigner: KwilSigner;\n synchronous?: boolean;\n}\n\nexport interface DeployStreamOutput {\n receipt: TxReceipt;\n}\n\n/**\n * Deploys a stream to TN.\n * @param input - The input parameters for deploying the stream.\n * @returns The transaction hash of the deployment.\n */\nexport async function deployStream(\n input: DeployStreamInput,\n): Promise<GenericResponse<TxReceipt>> {\n try {\n const txHash = await input.kwilClient.execute(\n {\n namespace: \"main\",\n inputs: [{\n $stream_id: input.streamId.getId(),\n $stream_type: input.streamType,\n }],\n name: \"create_stream\",\n description: `TN SDK - Deploying ${input.streamType} stream: ${input.streamId.getId()}`\n },\n input.kwilSigner,\n input.synchronous,\n );\n\n return txHash;\n } catch (error) {\n throw new Error(`Failed to deploy stream: ${error}`);\n }\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,gBAAe;AACf,IAAM,EAAE,KAAK,IAAI,UAAAA;AAmBjB,eAAsB,aACpB,OACqC;AACrC,MAAI;AACA,UAAM,SAAS,MAAM,MAAM,WAAW;AAAA,MACpC;AAAA,QACI,WAAW;AAAA,QACX,QAAQ,CAAC;AAAA,UACL,YAAY,MAAM,SAAS,MAAM;AAAA,UACjC,cAAc,MAAM;AAAA,QACxB,CAAC;AAAA,QACD,MAAM;AAAA,QACN,aAAa,sBAAsB,MAAM,UAAU,YAAY,MAAM,SAAS,MAAM,CAAC;AAAA,MACzF;AAAA,MACA,MAAM;AAAA,MACN,MAAM;AAAA,IACV;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,4BAA4B,KAAK,EAAE;AAAA,EACrD;AACF;",
|
|
6
6
|
"names": ["pg"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/contracts-api/roleManagement.ts
|
|
21
|
+
var roleManagement_exports = {};
|
|
22
|
+
__export(roleManagement_exports, {
|
|
23
|
+
RoleManagement: () => RoleManagement
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(roleManagement_exports);
|
|
26
|
+
var import_kwil_js = require("@kwilteam/kwil-js");
|
|
27
|
+
var import_action = require("./action.cjs");
|
|
28
|
+
var DataType = import_kwil_js.Utils.DataType;
|
|
29
|
+
var RoleManagement = class _RoleManagement extends import_action.Action {
|
|
30
|
+
constructor(kwilClient, kwilSigner) {
|
|
31
|
+
super(kwilClient, kwilSigner);
|
|
32
|
+
}
|
|
33
|
+
static normalizeOwner(owner) {
|
|
34
|
+
return owner === "system" ? "system" : owner.getAddress().toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
static normalizeWallets(wallets) {
|
|
37
|
+
return wallets.map((w) => w.getAddress().toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Grants a role to the provided wallets.
|
|
41
|
+
* This calls the `grant_roles` action.
|
|
42
|
+
*/
|
|
43
|
+
async grantRole(input, synchronous = false) {
|
|
44
|
+
return this.executeWithActionBody(
|
|
45
|
+
{
|
|
46
|
+
namespace: "main",
|
|
47
|
+
name: "grant_roles",
|
|
48
|
+
inputs: [
|
|
49
|
+
{
|
|
50
|
+
$owner: _RoleManagement.normalizeOwner(input.owner),
|
|
51
|
+
$role_name: input.roleName.toLowerCase(),
|
|
52
|
+
$wallets: _RoleManagement.normalizeWallets(input.wallets)
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
types: {
|
|
56
|
+
$owner: DataType.Text,
|
|
57
|
+
$role_name: DataType.Text,
|
|
58
|
+
$wallets: DataType.TextArray
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
synchronous
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Revokes a role from the provided wallets.
|
|
66
|
+
* This calls the `revoke_roles` action.
|
|
67
|
+
*/
|
|
68
|
+
async revokeRole(input, synchronous = false) {
|
|
69
|
+
return this.executeWithActionBody(
|
|
70
|
+
{
|
|
71
|
+
namespace: "main",
|
|
72
|
+
name: "revoke_roles",
|
|
73
|
+
inputs: [
|
|
74
|
+
{
|
|
75
|
+
$owner: _RoleManagement.normalizeOwner(input.owner),
|
|
76
|
+
$role_name: input.roleName.toLowerCase(),
|
|
77
|
+
$wallets: _RoleManagement.normalizeWallets(input.wallets)
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
types: {
|
|
81
|
+
$owner: DataType.Text,
|
|
82
|
+
$role_name: DataType.Text,
|
|
83
|
+
$wallets: DataType.TextArray
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
synchronous
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the provided wallets are members of a role.
|
|
91
|
+
* This calls the `are_members_of` VIEW action.
|
|
92
|
+
*
|
|
93
|
+
* @returns an array matching the provided wallets order with membership flags.
|
|
94
|
+
*/
|
|
95
|
+
async areMembersOf(input) {
|
|
96
|
+
const result = await this.call(
|
|
97
|
+
"are_members_of",
|
|
98
|
+
{
|
|
99
|
+
$owner: _RoleManagement.normalizeOwner(input.owner),
|
|
100
|
+
$role_name: input.roleName.toLowerCase(),
|
|
101
|
+
$wallets: _RoleManagement.normalizeWallets(input.wallets)
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
return result.throw().map((row) => ({
|
|
105
|
+
wallet: row.wallet,
|
|
106
|
+
isMember: row.is_member
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Lists the members of a role with optional pagination.
|
|
111
|
+
* This calls the `list_role_members` VIEW action.
|
|
112
|
+
*/
|
|
113
|
+
async listRoleMembers(input) {
|
|
114
|
+
const result = await this.call("list_role_members", {
|
|
115
|
+
$owner: _RoleManagement.normalizeOwner(input.owner),
|
|
116
|
+
$role_name: input.roleName.toLowerCase(),
|
|
117
|
+
...input.limit !== void 0 ? { $limit: input.limit } : {},
|
|
118
|
+
...input.offset !== void 0 ? { $offset: input.offset } : {}
|
|
119
|
+
});
|
|
120
|
+
return result.throw().map((row) => ({
|
|
121
|
+
wallet: row.wallet,
|
|
122
|
+
grantedAt: Number(row.granted_at),
|
|
123
|
+
grantedBy: row.granted_by
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Helper factory mirroring the pattern used by the other action wrappers.
|
|
128
|
+
*/
|
|
129
|
+
static fromClient(kwilClient, kwilSigner) {
|
|
130
|
+
return new _RoleManagement(kwilClient, kwilSigner);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=roleManagement.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contracts-api/roleManagement.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 { Action } from \"./action\";\nimport { AreMembersOfInput, GrantRoleInput, RevokeRoleInput, WalletMembership } from \"../types/role\";\nimport DataType = Utils.DataType;\nimport { OwnerIdentifier } from \"../types/role\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\n\n/**\n * RoleManagement provides convenient wrappers around the on-chain SQL actions\n * that implement the RBAC system (grant_roles, revoke_roles, are_members_of).\n */\nexport class RoleManagement extends Action {\n constructor(kwilClient: WebKwil | NodeKwil, kwilSigner: KwilSigner) {\n super(kwilClient, kwilSigner);\n }\n\n private static normalizeOwner(owner: OwnerIdentifier): string {\n return owner === \"system\"\n ? \"system\"\n : owner.getAddress().toLowerCase();\n }\n\n private static normalizeWallets(wallets: EthereumAddress[]): string[] {\n return wallets.map((w) => w.getAddress().toLowerCase());\n }\n\n /**\n * Grants a role to the provided wallets.\n * This calls the `grant_roles` action.\n */\n public async grantRole(\n input: GrantRoleInput,\n synchronous = false,\n ): Promise<GenericResponse<TxReceipt>> {\n return this.executeWithActionBody(\n {\n namespace: \"main\",\n name: \"grant_roles\",\n inputs: [\n {\n $owner: RoleManagement.normalizeOwner(input.owner),\n $role_name: input.roleName.toLowerCase(),\n $wallets: RoleManagement.normalizeWallets(input.wallets),\n },\n ],\n types: {\n $owner: DataType.Text,\n $role_name: DataType.Text,\n $wallets: DataType.TextArray,\n },\n },\n synchronous,\n );\n }\n\n /**\n * Revokes a role from the provided wallets.\n * This calls the `revoke_roles` action.\n */\n public async revokeRole(\n input: RevokeRoleInput,\n synchronous = false,\n ): Promise<GenericResponse<TxReceipt>> {\n return this.executeWithActionBody(\n {\n namespace: \"main\",\n name: \"revoke_roles\",\n inputs: [\n {\n $owner: RoleManagement.normalizeOwner(input.owner),\n $role_name: input.roleName.toLowerCase(),\n $wallets: RoleManagement.normalizeWallets(input.wallets),\n },\n ],\n types: {\n $owner: DataType.Text,\n $role_name: DataType.Text,\n $wallets: DataType.TextArray,\n },\n },\n synchronous,\n );\n }\n\n /**\n * Checks if the provided wallets are members of a role.\n * This calls the `are_members_of` VIEW action.\n *\n * @returns an array matching the provided wallets order with membership flags.\n */\n public async areMembersOf(\n input: AreMembersOfInput,\n ): Promise<WalletMembership[]> {\n const result = await this.call<{ wallet: string; is_member: boolean }[]>(\n \"are_members_of\",\n {\n $owner: RoleManagement.normalizeOwner(input.owner),\n $role_name: input.roleName.toLowerCase(),\n $wallets: RoleManagement.normalizeWallets(input.wallets),\n },\n );\n\n // Either.throw() will return the right value or throw with the left value (status code)\n return result.throw().map((row) => ({\n wallet: row.wallet,\n isMember: row.is_member,\n }));\n }\n\n /**\n * Lists the members of a role with optional pagination.\n * This calls the `list_role_members` VIEW action.\n */\n public async listRoleMembers(\n input: import(\"../types/role\").ListRoleMembersInput,\n ): Promise<import(\"../types/role\").RoleMember[]> {\n const result = await this.call<{\n wallet: string;\n granted_at: number;\n granted_by: string;\n }[]>(\"list_role_members\", {\n $owner: RoleManagement.normalizeOwner(input.owner),\n $role_name: input.roleName.toLowerCase(),\n ...(input.limit !== undefined ? { $limit: input.limit } : {}),\n ...(input.offset !== undefined ? { $offset: input.offset } : {}),\n });\n\n return result.throw().map((row) => ({\n wallet: row.wallet,\n grantedAt: Number(row.granted_at),\n grantedBy: row.granted_by,\n }));\n }\n\n /**\n * Helper factory mirroring the pattern used by the other action wrappers.\n */\n public static fromClient(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n ): RoleManagement {\n return new RoleManagement(kwilClient, kwilSigner);\n }\n} "],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAqD;AAGrD,oBAAuB;AAEvB,IAAO,WAAW,qBAAM;AAQjB,IAAM,iBAAN,MAAM,wBAAuB,qBAAO;AAAA,EACzC,YAAY,YAAgC,YAAwB;AAClE,UAAM,YAAY,UAAU;AAAA,EAC9B;AAAA,EAEA,OAAe,eAAe,OAAgC;AAC5D,WAAO,UAAU,WACb,WACA,MAAM,WAAW,E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AAA,QACvC,UAAU,gBAAe,iBAAiB,MAAM,OAAO;AAAA,MACzD;AAAA,IACF;AAGA,WAAO,OAAO,MAAM,EAAE,IAAI,CAAC,SAAS;AAAA,MAClC,QAAQ,IAAI;AAAA,MACZ,UAAU,IAAI;AAAA,IAChB,EAAE;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,gBACX,OAC+C;AAC/C,UAAM,SAAS,MAAM,KAAK,KAIrB,qBAAqB;AAAA,MACxB,QAAQ,gBAAe,eAAe,MAAM,KAAK;AAAA,MACjD,YAAY,MAAM,SAAS,YAAY;AAAA,MACvC,GAAI,MAAM,UAAU,SAAY,EAAE,QAAQ,MAAM,MAAM,IAAI,CAAC;AAAA,MAC3D,GAAI,MAAM,WAAW,SAAY,EAAE,SAAS,MAAM,OAAO,IAAI,CAAC;AAAA,IAChE,CAAC;AAED,WAAO,OAAO,MAAM,EAAE,IAAI,CAAC,SAAS;AAAA,MAClC,QAAQ,IAAI;AAAA,MACZ,WAAW,OAAO,IAAI,UAAU;AAAA,MAChC,WAAW,IAAI;AAAA,IACjB,EAAE;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,WACZ,YACA,YACgB;AAChB,WAAO,IAAI,gBAAe,YAAY,UAAU;AAAA,EAClD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -24,6 +24,7 @@ __export(index_common_exports, {
|
|
|
24
24
|
ComposedAction: () => import_composedAction.ComposedAction,
|
|
25
25
|
EthereumAddress: () => import_EthereumAddress.EthereumAddress,
|
|
26
26
|
PrimitiveAction: () => import_primitiveAction.PrimitiveAction,
|
|
27
|
+
RoleManagement: () => import_roleManagement.RoleManagement,
|
|
27
28
|
StreamId: () => import_StreamId.StreamId,
|
|
28
29
|
StreamType: () => import_contractValues.StreamType,
|
|
29
30
|
visibility: () => import_visibility.visibility
|
|
@@ -36,4 +37,5 @@ var import_contractValues = require("./contracts-api/contractValues.cjs");
|
|
|
36
37
|
var import_action = require("./contracts-api/action.cjs");
|
|
37
38
|
var import_primitiveAction = require("./contracts-api/primitiveAction.cjs");
|
|
38
39
|
var import_composedAction = require("./contracts-api/composedAction.cjs");
|
|
40
|
+
var import_roleManagement = require("./contracts-api/roleManagement.cjs");
|
|
39
41
|
//# sourceMappingURL=index.common.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.common.ts"],
|
|
4
|
-
"sourcesContent": ["// Core client types\nexport type { TNClientOptions } from \"./client/client\";\nexport type { SignerInfo as EthProvider } from \"./client/client\";\n\n// Stream types and interfaces\nexport type { StreamLocator } from \"./types/stream\";\nexport type { StreamRecord } from \"./contracts-api/action\";\nexport type { GetRecordInput, GetFirstRecordInput } from \"./contracts-api/action\";\nexport type { InsertRecordInput } from \"./contracts-api/primitiveAction\";\nexport type { TaxonomySet, TaxonomyItem } from \"./contracts-api/composedAction\";\n\n// Utility types and classes\nexport { StreamId } from \"./util/StreamId\";\nexport { EthereumAddress } from \"./util/EthereumAddress\";\nexport { visibility } from \"./util/visibility\";\nexport type { VisibilityEnum } from \"./util/visibility\";\n\n// Stream type constants\nexport { StreamType } from \"./contracts-api/contractValues\";\n\n// Base classes\nexport { Action } from \"./contracts-api/action\";\nexport { PrimitiveAction } from \"./contracts-api/primitiveAction\";\nexport { ComposedAction } from \"./contracts-api/composedAction\";\n\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAyB;AACzB,6BAAgC;AAChC,wBAA2B;AAI3B,4BAA2B;AAG3B,oBAAuB;AACvB,6BAAgC;AAChC,4BAA+B;",
|
|
4
|
+
"sourcesContent": ["// Core client types\nexport type { TNClientOptions } from \"./client/client\";\nexport type { SignerInfo as EthProvider } from \"./client/client\";\n\n// Stream types and interfaces\nexport type { StreamLocator } from \"./types/stream\";\nexport type { StreamRecord } from \"./contracts-api/action\";\nexport type { GetRecordInput, GetFirstRecordInput } from \"./contracts-api/action\";\nexport type { InsertRecordInput } from \"./contracts-api/primitiveAction\";\nexport type { TaxonomySet, TaxonomyItem } from \"./contracts-api/composedAction\";\n\n// Utility types and classes\nexport { StreamId } from \"./util/StreamId\";\nexport { EthereumAddress } from \"./util/EthereumAddress\";\nexport { visibility } from \"./util/visibility\";\nexport type { VisibilityEnum } from \"./util/visibility\";\n\n// Stream type constants\nexport { StreamType } from \"./contracts-api/contractValues\";\n\n// Base classes\nexport { Action } from \"./contracts-api/action\";\nexport { PrimitiveAction } from \"./contracts-api/primitiveAction\";\nexport { ComposedAction } from \"./contracts-api/composedAction\";\n\n// Role management exports\nexport { RoleManagement } from \"./contracts-api/roleManagement\";\nexport type { GrantRoleInput, RevokeRoleInput, AreMembersOfInput, WalletMembership } from \"./types/role\";\n\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAyB;AACzB,6BAAgC;AAChC,wBAA2B;AAI3B,4BAA2B;AAG3B,oBAAuB;AACvB,6BAAgC;AAChC,4BAA+B;AAG/B,4BAA+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/role.ts
|
|
17
|
+
var role_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(role_exports);
|
|
19
|
+
//# sourceMappingURL=role.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/role.ts"],
|
|
4
|
+
"sourcesContent": ["import { EthereumAddress } from \"../util/EthereumAddress\";\n\n// Represents the owner of a role: either the literal network owner \"system\" or an Ethereum address\nexport type OwnerIdentifier = \"system\" | EthereumAddress;\n\nexport interface GrantRoleInput {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress[];\n}\n\nexport interface RevokeRoleInput {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress[];\n}\n\nexport interface AreMembersOfInput {\n owner: OwnerIdentifier;\n roleName: string;\n wallets: EthereumAddress[];\n}\n\nexport interface WalletMembership {\n wallet: string; // lower-cased wallet address\n isMember: boolean;\n}\n\n// Input parameters for listing role members with pagination\nexport interface ListRoleMembersInput {\n owner: OwnerIdentifier;\n roleName: string;\n limit?: number; // max records to return (defaults enforced in SQL)\n offset?: number; // offset for pagination (defaults enforced in SQL)\n}\n\n// The shape of a role member record as returned by list_role_members.\nexport interface RoleMember {\n wallet: string; // Wallet address in lowercase\n grantedAt: number; // Block height when granted\n grantedBy: string; // Wallet address that performed the grant\n} "],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/types/stream.ts"],
|
|
4
|
-
"sourcesContent": ["import { StreamId } from \"../util/StreamId\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\n\nexport interface StreamLocator {\n /**\n * the unique identifier of the stream, used as name of the deployed contract\n */\n streamId: StreamId;\n /**\n * the address of the data provider, it's the deployer of the stream\n */\n dataProvider: EthereumAddress;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import { StreamId } from \"../util/StreamId\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\n\nexport interface StreamLocator {\n /**\n * the unique identifier of the stream, used as name of the deployed contract\n */\n streamId: StreamId;\n /**\n * the address of the data provider, it's the deployer of the stream\n */\n dataProvider: EthereumAddress;\n}\n\nexport interface TNStream {\n streamId: StreamId;\n dataProvider: EthereumAddress;\n streamType: string;\n createdAt: number;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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": ";AACA,SAAS,eAAe;AACxB,SAAS,oBAAqC;AAEvC,IAAM,kBAAN,cAA8B,aAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,QAAQ;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": ";AACA,SAAS,eAAe;AACxB,SAAS,oBAAqC;AAEvC,IAAM,kBAAN,cAA8B,aAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,QAAQ;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
|
}
|
|
@@ -12,13 +12,12 @@ import { Action } from "../contracts-api/action.mjs";
|
|
|
12
12
|
import { EthereumAddress } from "../util/EthereumAddress.mjs";
|
|
13
13
|
import { listStreams } from "./listStreams.mjs";
|
|
14
14
|
import { getLastTransactions } from "./getLastTransactions.mjs";
|
|
15
|
+
import { RoleManagement } from "../contracts-api/roleManagement.mjs";
|
|
15
16
|
var BaseTNClient = class {
|
|
16
17
|
constructor(options) {
|
|
17
18
|
__publicField(this, "kwilClient");
|
|
18
19
|
__publicField(this, "signerInfo");
|
|
19
|
-
__publicField(this, "neonConnectionString");
|
|
20
20
|
this.signerInfo = options.signerInfo;
|
|
21
|
-
this.neonConnectionString = options.neonConnectionString;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* Waits for a transaction to be mined by TN.
|
|
@@ -79,12 +78,6 @@ var BaseTNClient = class {
|
|
|
79
78
|
}
|
|
80
79
|
return this.kwilClient;
|
|
81
80
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Returns the Neon connection string used by the client.
|
|
84
|
-
*/
|
|
85
|
-
getNeonConnectionString() {
|
|
86
|
-
return this.neonConnectionString;
|
|
87
|
-
}
|
|
88
81
|
/**
|
|
89
82
|
* Deploys a new stream.
|
|
90
83
|
* @param streamId - The ID of the stream to deploy.
|
|
@@ -99,8 +92,7 @@ var BaseTNClient = class {
|
|
|
99
92
|
streamType,
|
|
100
93
|
synchronous,
|
|
101
94
|
kwilClient: this.getKwilClient(),
|
|
102
|
-
kwilSigner: this.getKwilSigner()
|
|
103
|
-
neonConnectionString: this.getNeonConnectionString()
|
|
95
|
+
kwilSigner: this.getKwilSigner()
|
|
104
96
|
});
|
|
105
97
|
}
|
|
106
98
|
/**
|
|
@@ -139,7 +131,16 @@ var BaseTNClient = class {
|
|
|
139
131
|
* @returns An instance of IComposedStream.
|
|
140
132
|
*/
|
|
141
133
|
loadComposedAction() {
|
|
142
|
-
return ComposedAction.fromStream(this.loadAction()
|
|
134
|
+
return ComposedAction.fromStream(this.loadAction());
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Loads the role management contract API, permitting its RBAC usage.
|
|
138
|
+
*/
|
|
139
|
+
loadRoleManagementAction() {
|
|
140
|
+
return RoleManagement.fromClient(
|
|
141
|
+
this.getKwilClient(),
|
|
142
|
+
this.getKwilSigner()
|
|
143
|
+
);
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
145
146
|
* Creates a new stream locator.
|
|
@@ -187,6 +188,65 @@ var BaseTNClient = class {
|
|
|
187
188
|
const chainInfo = await kwilClient["chainInfoClient"]();
|
|
188
189
|
return chainInfo.data?.chain_id;
|
|
189
190
|
}
|
|
191
|
+
/*
|
|
192
|
+
* High-level role-management helpers. These wrap the lower-level
|
|
193
|
+
* RoleManagement contract calls and expose a simpler API on the
|
|
194
|
+
* TN client.
|
|
195
|
+
*/
|
|
196
|
+
/** Grants a role to one or more wallets. */
|
|
197
|
+
async grantRole(input) {
|
|
198
|
+
const rm = this.loadRoleManagementAction();
|
|
199
|
+
const walletsArr = Array.isArray(input.wallets) ? input.wallets : [input.wallets];
|
|
200
|
+
const tx = await rm.grantRole(
|
|
201
|
+
{
|
|
202
|
+
owner: input.owner,
|
|
203
|
+
roleName: input.roleName,
|
|
204
|
+
wallets: walletsArr
|
|
205
|
+
},
|
|
206
|
+
input.synchronous
|
|
207
|
+
);
|
|
208
|
+
return tx.data?.tx_hash;
|
|
209
|
+
}
|
|
210
|
+
/** Revokes a role from one or more wallets. */
|
|
211
|
+
async revokeRole(input) {
|
|
212
|
+
const rm = this.loadRoleManagementAction();
|
|
213
|
+
const walletsArr = Array.isArray(input.wallets) ? input.wallets : [input.wallets];
|
|
214
|
+
const tx = await rm.revokeRole(
|
|
215
|
+
{
|
|
216
|
+
owner: input.owner,
|
|
217
|
+
roleName: input.roleName,
|
|
218
|
+
wallets: walletsArr
|
|
219
|
+
},
|
|
220
|
+
input.synchronous
|
|
221
|
+
);
|
|
222
|
+
return tx.data?.tx_hash;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Checks if a wallet is member of a role.
|
|
226
|
+
* Returns true if the wallet is a member.
|
|
227
|
+
*/
|
|
228
|
+
async isMemberOf(input) {
|
|
229
|
+
const rm = this.loadRoleManagementAction();
|
|
230
|
+
const res = await rm.areMembersOf({
|
|
231
|
+
owner: input.owner,
|
|
232
|
+
roleName: input.roleName,
|
|
233
|
+
wallets: [input.wallet]
|
|
234
|
+
});
|
|
235
|
+
return res.length > 0 && res[0].isMember;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Lists role members – currently unsupported in the
|
|
239
|
+
* smart-contract layer.
|
|
240
|
+
*/
|
|
241
|
+
async listRoleMembers(input) {
|
|
242
|
+
const rm = this.loadRoleManagementAction();
|
|
243
|
+
return rm.listRoleMembers({
|
|
244
|
+
owner: input.owner,
|
|
245
|
+
roleName: input.roleName,
|
|
246
|
+
limit: input.limit,
|
|
247
|
+
offset: input.offset
|
|
248
|
+
});
|
|
249
|
+
}
|
|
190
250
|
};
|
|
191
251
|
export {
|
|
192
252
|
BaseTNClient
|
|
@@ -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 } 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<StreamLocator[]> {\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,SAAS,QAAQ,kBAAqC;AAQtD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,SAAS,cAAc;AAGvB,SAAS,uBAAuB;AAEhC,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B;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,SAAS,QAAQ,kBAAqC;AAQtD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAA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AAA,MACA,MAAM;AAAA,IACR;AACA,WAAO,GAAG,MAAM;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAW,OAII;AACnB,UAAM,KAAK,KAAK,yBAAyB;AACzC,UAAM,MAAM,MAAM,GAAG,aAAa;AAAA,MAChC,OAAO,MAAM;AAAA,MACb,UAAU,MAAM;AAAA,MAChB,SAAS,CAAC,MAAM,MAAM;AAAA,IACxB,CAAC;AACD,WAAO,IAAI,SAAS,KAAK,IAAI,CAAC,EAAE;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,gBAAgB,OAK4B;AAChD,UAAM,KAAK,KAAK,yBAAyB;AACzC,WAAO,GAAG,gBAAgB;AAAA,MACxB,OAAO,MAAM;AAAA,MACb,UAAU,MAAM;AAAA,MAChB,OAAO,MAAM;AAAA,MACb,QAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,7 +16,9 @@ async function listStreams(kwilClient, kwilSigner, input) {
|
|
|
16
16
|
return await Promise.all(
|
|
17
17
|
(result.data?.result).map(async (database) => ({
|
|
18
18
|
streamId: await StreamId.generate(database.stream_id),
|
|
19
|
-
dataProvider: new EthereumAddress(database.data_provider)
|
|
19
|
+
dataProvider: new EthereumAddress(database.data_provider),
|
|
20
|
+
streamType: database.stream_type,
|
|
21
|
+
createdAt: database.created_at
|
|
20
22
|
}))
|
|
21
23
|
);
|
|
22
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/listStreams.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";AACA,SAAQ,uBAAsB;AAC9B,SAAQ,gBAAe;AAYvB,eAAsB,YACpB,YACA,YACA,
|
|
4
|
+
"sourcesContent": ["import {TNStream} from \"../types/stream\";\nimport {EthereumAddress} from \"../util/EthereumAddress\";\nimport {StreamId} from \"../util/StreamId\";\nimport {Database} from \"@kwilteam/kwil-js/dist/core/database\";\nimport {ListStreamsInput} from \"./client\";\nimport {KwilSigner, NodeKwil, WebKwil} from \"@kwilteam/kwil-js\";\n\n/**\n * List all streams from the TN network.\n * @param kwilClient - The Kwil client.\n * @param kwilSigner - The Kwil signer.\n * @param input - The input parameters for listing streams.\n * @returns A list of stream locators.\n */\nexport async function listStreams(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n input: ListStreamsInput\n): Promise<TNStream[]> {\n const result = await kwilClient.call({\n inputs: {\n $data_provider: input.dataProvider,\n $limit: input.limit,\n $offset: input.offset,\n $order_by: input.orderBy,\n $block_height: input.blockHeight,\n },\n name: \"list_streams\",\n namespace: \"main\",\n }, kwilSigner);\n\n return await Promise.all(\n (result.data?.result as {\n data_provider: string;\n stream_id: string;\n stream_type: string;\n created_at: number;\n }[]).map(async (database) => ({\n streamId: await StreamId.generate(database.stream_id),\n dataProvider: new EthereumAddress(database.data_provider),\n streamType: database.stream_type,\n createdAt: database.created_at\n }))\n );\n}"],
|
|
5
|
+
"mappings": ";AACA,SAAQ,uBAAsB;AAC9B,SAAQ,gBAAe;AAYvB,eAAsB,YACpB,YACA,YACA,OACqB;AACnB,QAAM,SAAS,MAAM,WAAW,KAAK;AAAA,IACjC,QAAQ;AAAA,MACJ,gBAAgB,MAAM;AAAA,MACtB,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,WAAW,MAAM;AAAA,MACjB,eAAe,MAAM;AAAA,IACzB;AAAA,IACA,MAAM;AAAA,IACN,WAAW;AAAA,EACf,GAAG,UAAU;AAEb,SAAO,MAAM,QAAQ;AAAA,KAChB,OAAO,MAAM,QAKT,IAAI,OAAO,cAAc;AAAA,MAC1B,UAAU,MAAM,SAAS,SAAS,SAAS,SAAS;AAAA,MACpD,cAAc,IAAI,gBAAgB,SAAS,aAAa;AAAA,MACxD,YAAY,SAAS;AAAA,MACrB,WAAW,SAAS;AAAA,IACxB,EAAE;AAAA,EACN;AACJ;",
|
|
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": ";AACA,SAAS,gBAAgB;AACzB,SAAS,oBAAqC;AAEvC,IAAM,eAAN,cAA2B,aAAmC;AAAA,EACnE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,SAAS;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": ";AACA,SAAS,gBAAgB;AACzB,SAAS,oBAAqC;AAEvC,IAAM,eAAN,cAA2B,aAAmC;AAAA,EACnE,YAAY,SAA0B;AACpC,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,SAAS;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
|
}
|
|
@@ -62,8 +62,9 @@ var Action = class {
|
|
|
62
62
|
* Returns the records of the stream within the given date range
|
|
63
63
|
*/
|
|
64
64
|
async getRecord(input) {
|
|
65
|
+
const prefix = input.prefix ? input.prefix : "";
|
|
65
66
|
const result = await this.call(
|
|
66
|
-
"get_record",
|
|
67
|
+
prefix + "get_record",
|
|
67
68
|
{
|
|
68
69
|
$data_provider: input.stream.dataProvider.getAddress(),
|
|
69
70
|
$stream_id: input.stream.streamId.getId(),
|
|
@@ -83,8 +84,9 @@ var Action = class {
|
|
|
83
84
|
* Returns the index of the stream within the given date range
|
|
84
85
|
*/
|
|
85
86
|
async getIndex(input) {
|
|
87
|
+
const prefix = input.prefix ? input.prefix : "";
|
|
86
88
|
const result = await this.call(
|
|
87
|
-
"get_index",
|
|
89
|
+
prefix + "get_index",
|
|
88
90
|
{
|
|
89
91
|
$data_provider: input.stream.dataProvider.getAddress(),
|
|
90
92
|
$stream_id: input.stream.streamId.getId(),
|