@trufnetwork/sdk-js 0.2.6 → 0.2.8
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/dist/cjs/client/browserClient.cjs +6 -0
- package/dist/cjs/client/browserClient.cjs.map +2 -2
- package/dist/cjs/client/client.cjs +2 -2
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/client/client.test.cjs +1 -1
- package/dist/cjs/client/nodeClient.cjs +8 -0
- package/dist/cjs/client/nodeClient.cjs.map +2 -2
- package/dist/cjs/contracts-api/composedStream.cjs +6 -19
- package/dist/cjs/contracts-api/composedStream.cjs.map +3 -3
- package/dist/cjs/contracts-api/deployStream.cjs +5 -18
- package/dist/cjs/contracts-api/deployStream.cjs.map +3 -3
- package/dist/cjs/util/EthereumAddress.cjs +1 -1
- package/dist/esm/client/browserClient.mjs +6 -0
- package/dist/esm/client/browserClient.mjs.map +2 -2
- package/dist/esm/client/client.mjs +2 -2
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/client/client.test.mjs +1 -1
- package/dist/esm/client/nodeClient.mjs +15 -0
- package/dist/esm/client/nodeClient.mjs.map +2 -2
- package/dist/esm/contracts-api/composedStream.mjs +6 -9
- package/dist/esm/contracts-api/composedStream.mjs.map +2 -2
- package/dist/esm/contracts-api/deployStream.mjs +5 -8
- package/dist/esm/contracts-api/deployStream.mjs.map +2 -2
- package/dist/esm/util/EthereumAddress.mjs +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/browserClient.d.ts +2 -0
- package/dist/types/client/browserClient.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +2 -0
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/listAllStreams.d.ts.map +1 -1
- package/dist/types/client/nodeClient.d.ts +2 -0
- package/dist/types/client/nodeClient.d.ts.map +1 -1
- package/dist/types/contracts-api/composedStream.d.ts +3 -2
- package/dist/types/contracts-api/composedStream.d.ts.map +1 -1
- package/dist/types/contracts-api/deployStream.d.ts +2 -1
- package/dist/types/contracts-api/deployStream.d.ts.map +1 -1
- package/dist/types/util/visibility.d.ts.map +1 -1
- package/package.json +15 -12
|
@@ -28,12 +28,18 @@ var import_kwil_js = require("@kwilteam/kwil-js");
|
|
|
28
28
|
var import_client = require("./client.cjs");
|
|
29
29
|
var BrowserTNClient = class extends import_client.BaseTNClient {
|
|
30
30
|
constructor(options) {
|
|
31
|
+
if (options.neonConnectionString) {
|
|
32
|
+
console.warn("Neon connection string is not supported in browser environments. Database operations won't be performed.");
|
|
33
|
+
}
|
|
31
34
|
super(options);
|
|
32
35
|
this.kwilClient = new import_kwil_js.WebKwil({
|
|
33
36
|
...options,
|
|
34
37
|
kwilProvider: options.endpoint
|
|
35
38
|
});
|
|
36
39
|
}
|
|
40
|
+
getPool() {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
37
43
|
};
|
|
38
44
|
var browserClient_default = BrowserTNClient;
|
|
39
45
|
//# sourceMappingURL=browserClient.cjs.map
|
|
@@ -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;
|
|
4
|
+
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { WebKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\nimport { type Pool } from \"pg\";\n\nexport class BrowserTNClient extends BaseTNClient<EnvironmentType.BROWSER> {\n constructor(options: TNClientOptions) {\n if (options.neonConnectionString) {\n console.warn(\"Neon connection string is not supported in browser environments. Database operations won't be performed.\");\n }\n\n super(options);\n this.kwilClient = new WebKwil({\n ...options,\n kwilProvider: options.endpoint,\n });\n }\n\n protected getPool(): Pool | undefined {\n return undefined;\n }\n}\n\nexport default BrowserTNClient;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAwB;AACxB,oBAA8C;AAGvC,IAAM,kBAAN,cAA8B,2BAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,QAAI,QAAQ,sBAAsB;AAChC,cAAQ,KAAK,0GAA0G;AAAA,IACzH;AAEA,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,uBAAQ;AAAA,MAC5B,GAAG;AAAA,MACH,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AAAA,EAEU,UAA4B;AACpC,WAAO;AAAA,EACT;AACF;AAEA,IAAO,wBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -120,7 +120,7 @@ var BaseTNClient = class {
|
|
|
120
120
|
kwilClient: this.getKwilClient(),
|
|
121
121
|
kwilSigner: this.getKwilSigner(),
|
|
122
122
|
contractVersion,
|
|
123
|
-
|
|
123
|
+
pool: this.getPool()
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
@@ -167,7 +167,7 @@ var BaseTNClient = class {
|
|
|
167
167
|
this.getKwilClient(),
|
|
168
168
|
this.getKwilSigner(),
|
|
169
169
|
stream,
|
|
170
|
-
this.
|
|
170
|
+
this.getPool()
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
@@ -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/builders\";\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 { ComposedStream } from \"../contracts-api/composedStream\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { destroyStream } from \"../contracts-api/destroyStream\";\nimport { PrimitiveStream } from \"../contracts-api/primitiveStream\";\nimport { Stream } from \"../contracts-api/stream\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listAllStreams } from \"./listAllStreams\";\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 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 === \"success\") {\n resolve(receipt.data);\n } else {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\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 contractVersion?: number\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n contractVersion: contractVersion,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAQtD,4BAA+B;AAC/B,0BAA6B;AAC7B,2BAA8B;AAC9B,6BAAgC;AAChC,oBAAuB;AAGvB,6BAAgC;AAEhC,4BAA+B;
|
|
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/builders\";\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 { ComposedStream } from \"../contracts-api/composedStream\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { destroyStream } from \"../contracts-api/destroyStream\";\nimport { PrimitiveStream } from \"../contracts-api/primitiveStream\";\nimport { Stream } from \"../contracts-api/stream\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listAllStreams } from \"./listAllStreams\";\nimport { type Pool } from \"pg\";\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 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 === \"success\") {\n resolve(receipt.data);\n } else {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\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 contractVersion?: number\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n contractVersion: contractVersion,\n pool: this.getPool(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param streamId - The ID 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 streamId: StreamId,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await destroyStream({\n streamId,\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 * @param stream - The locator of the stream to load.\n * @returns An instance of IStream.\n */\n loadStream(stream: StreamLocator): Stream {\n return new Stream(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n stream,\n );\n }\n\n /**\n * Loads a primitive stream.\n * @param stream - The locator of the primitive stream to load.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveStream(stream: StreamLocator): PrimitiveStream {\n return PrimitiveStream.fromStream(this.loadStream(stream));\n }\n\n /**\n * Loads a composed stream.\n * @param stream - The locator of the composed stream to load.\n * @returns An instance of IComposedStream.\n */\n loadComposedStream(stream: StreamLocator): ComposedStream {\n return new ComposedStream(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n stream,\n this.getPool(),\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 owner - The owner of the streams. If not provided, all streams will be returned.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getAllStreams(owner?: EthereumAddress): Promise<StreamLocator[]> {\n return listAllStreams(this.getKwilClient(), owner);\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 protected abstract getPool(): Pool | undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAQtD,4BAA+B;AAC/B,0BAA6B;AAC7B,2BAA8B;AAC9B,6BAAgC;AAChC,oBAAuB;AAGvB,6BAAgC;AAEhC,4BAA+B;AAexB,IAAe,eAAf,MAAuD;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,SAA0B;AAC9C,SAAK,aAAa,QAAQ;AAC1B,SAAK,uBAAuB,QAAQ;AAAA,EACtC;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,gBAAQ,QAAQ,QAAQ;AAAA,UACtB,KAAK;AACH,gBAAI,QAAQ,MAAM,UAAU,QAAQ,WAAW;AAC7C,sBAAQ,QAAQ,IAAI;AAAA,YACtB,OAAO;AACL;AAAA,gBACE,IAAI;AAAA,kBACF,8BAA8B,QAAQ,MAAM,kBAAkB,QAAQ,MAAM,UAAU,GAAG;AAAA,gBAC3F;AAAA,cACF;AAAA,YACF;AACA;AAAA,UACF,KAAK;AACH;AAAA,UACF;AACE;AAAA,cACE,IAAI;AAAA,gBACF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A,MACnB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,oBAAoB,QAAwC;AAC1D,WAAO,uCAAgB,WAAW,KAAK,WAAW,MAAM,CAAC;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,mBAAmB,QAAuC;AACxD,WAAO,IAAI;AAAA,MACT,KAAK,cAAc;AAAA,MACnB,KAAK,cAAc;AAAA,MACnB;AAAA,MACA,KAAK,QAAQ;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,iBAAiB,UAAmC;AAClD,WAAO;AAAA,MACL;AAAA,MACA,cAAc,KAAK,QAAQ;AAAA,IAC7B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAA2B;AACzB,WAAO,IAAI,uCAAgB,KAAK,WAAW,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAc,OAAmD;AACrE,eAAO,sCAAe,KAAK,cAAc,GAAG,KAAK;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAoB,kBAAkB,UAAkB;AACtD,UAAM,aAAa,IAAI,sBAAO;AAAA,MAC5B,cAAc;AAAA,IAChB,CAAC;AACD,UAAM,YAAY,MAAM,WAAW,iBAAiB,EAAE;AACtD,WAAO,UAAU,MAAM;AAAA,EACzB;AAIF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/client/client.test.ts
|
|
4
4
|
var import_vitest = require("vitest");
|
|
5
|
-
var import_ethers = require("ethers
|
|
5
|
+
var import_ethers = require("ethers");
|
|
6
6
|
var import_nodeClient = require("./nodeClient.cjs");
|
|
7
7
|
import_vitest.describe.sequential("Client", { timeout: 3e4 }, () => {
|
|
8
8
|
import_vitest.it.skipIf(process.env.CI);
|
|
@@ -34,6 +34,14 @@ var NodeTNClient = class extends import_client.BaseTNClient {
|
|
|
34
34
|
kwilProvider: options.endpoint
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
getPool() {
|
|
38
|
+
const pg = require("pg");
|
|
39
|
+
const { Pool } = pg;
|
|
40
|
+
if (this.neonConnectionString) {
|
|
41
|
+
return new Pool({ connectionString: this.neonConnectionString });
|
|
42
|
+
}
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
37
45
|
};
|
|
38
46
|
var nodeClient_default = NodeTNClient;
|
|
39
47
|
//# sourceMappingURL=nodeClient.cjs.map
|
|
@@ -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\";\
|
|
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\";\nimport { type Pool } from \"pg\";\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 protected getPool(): Pool | undefined {\n const pg = require(\"pg\");\n const { Pool } = pg;\n if (this.neonConnectionString) {\n return new Pool({ connectionString: this.neonConnectionString });\n }\n return undefined;\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;AAAA,EAEU,UAA4B;AACpC,UAAM,KAAK,QAAQ,IAAI;AACvB,UAAM,EAAE,KAAK,IAAI;AACjB,QAAI,KAAK,sBAAsB;AAC7B,aAAO,IAAI,KAAK,EAAE,kBAAkB,KAAK,qBAAqB,CAAC;AAAA,IACjE;AACA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
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/composedStream.ts
|
|
@@ -39,14 +29,12 @@ var import_EthereumAddress = require("../util/EthereumAddress.cjs");
|
|
|
39
29
|
var import_StreamId = require("../util/StreamId.cjs");
|
|
40
30
|
var import_contractValues = require("./contractValues.cjs");
|
|
41
31
|
var import_stream = require("./stream.cjs");
|
|
42
|
-
var import_pg = __toESM(require("pg"), 1);
|
|
43
|
-
var { Pool } = import_pg.default;
|
|
44
32
|
var ErrorStreamNotComposed = "stream is not a composed stream";
|
|
45
33
|
var ComposedStream = class _ComposedStream extends import_stream.Stream {
|
|
46
|
-
|
|
47
|
-
constructor(kwilClient, kwilSigner, locator,
|
|
34
|
+
pool;
|
|
35
|
+
constructor(kwilClient, kwilSigner, locator, pool) {
|
|
48
36
|
super(kwilClient, kwilSigner, locator);
|
|
49
|
-
this.
|
|
37
|
+
this.pool = pool;
|
|
50
38
|
}
|
|
51
39
|
/**
|
|
52
40
|
* Checks if the stream is a valid composed stream.
|
|
@@ -134,8 +122,7 @@ var ComposedStream = class _ComposedStream extends import_stream.Stream {
|
|
|
134
122
|
$start_date: startDate
|
|
135
123
|
})
|
|
136
124
|
]);
|
|
137
|
-
if (this.
|
|
138
|
-
const pool = new Pool({ connectionString: this.neonConnectionString });
|
|
125
|
+
if (this.pool) {
|
|
139
126
|
const parentProvider = this.locator.dataProvider.getAddress().slice(2);
|
|
140
127
|
const parentStreamId = this.locator.streamId.getId();
|
|
141
128
|
const startDateText = String(startDate);
|
|
@@ -143,7 +130,7 @@ var ComposedStream = class _ComposedStream extends import_stream.Stream {
|
|
|
143
130
|
const childProvider = item.childStream.dataProvider.getAddress().slice(2);
|
|
144
131
|
const childStreamId = item.childStream.streamId.getId();
|
|
145
132
|
const weight = item.weight;
|
|
146
|
-
await pool.query(
|
|
133
|
+
await this.pool.query(
|
|
147
134
|
`INSERT INTO taxonomies
|
|
148
135
|
(parent_data_provider, parent_stream_id,
|
|
149
136
|
child_data_provider, child_stream_id,
|
|
@@ -160,7 +147,7 @@ var ComposedStream = class _ComposedStream extends import_stream.Stream {
|
|
|
160
147
|
]
|
|
161
148
|
);
|
|
162
149
|
}
|
|
163
|
-
await pool.end();
|
|
150
|
+
await this.pool.end();
|
|
164
151
|
console.log("Successfully inserted taxonomy into Explorer DB", {
|
|
165
152
|
parentStreamId,
|
|
166
153
|
childStreamId: streamIds,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contracts-api/composedStream.ts"],
|
|
4
|
-
"sourcesContent": ["import { KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { ActionInput } 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 { DateString } from \"../types/other\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { StreamType } from \"./contractValues\";\nimport { Stream } from \"./stream\";\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { ActionInput } 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 { DateString } from \"../types/other\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { StreamType } from \"./contractValues\";\nimport { Stream } from \"./stream\";\nimport { type Pool } from \"pg\";\n\nexport const ErrorStreamNotComposed = \"stream is not a composed stream\";\n\nexport interface TaxonomySet {\n taxonomyItems: TaxonomyItem[];\n startDate: DateString | number;\n}\n\nexport interface TaxonomyItem {\n childStream: StreamLocator;\n weight: string;\n}\n\nexport interface DescribeTaxonomiesParams {\n /**\n * if true, will return the latest version of the taxonomy only\n */\n latestVersion: boolean;\n}\n\nexport class ComposedStream extends Stream {\n protected pool: Pool | undefined;\n\n constructor(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n locator: StreamLocator,\n pool?: Pool,\n ) {\n super(kwilClient, kwilSigner, locator);\n this.pool = pool;\n }\n\n /**\n * Checks if the stream is a valid composed stream.\n * A valid composed stream must be:\n * - initialized\n * - of type composed\n */\n private async checkValidComposedStream(): Promise<void> {\n // First check if initialized\n await this.checkInitialized(StreamType.Composed);\n\n // Then check if is composed\n const streamType = await this.getType();\n if (streamType !== StreamType.Composed) {\n throw new Error(ErrorStreamNotComposed);\n }\n }\n\n /**\n * Executes a method after checking if the stream is a valid composed stream\n * @param method The method name to execute\n * @param inputs The inputs for the action\n * @returns A generic response containing the transaction receipt\n */\n private async checkedComposedExecute(\n method: string,\n inputs: ActionInput[],\n ): Promise<GenericResponse<TxReceipt>> {\n await this.checkValidComposedStream();\n return this.execute(method, inputs);\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 child_stream_id: string;\n child_data_provider: string;\n weight: string;\n created_at: number;\n version: number;\n start_date: string | number;\n }[];\n\n const result = await this.call<TaxonomyResult>(\"describe_taxonomies\", [\n ActionInput.fromObject({ $latest_version: params.latestVersion }),\n ]);\n\n return result\n .mapRight((records) => {\n const taxonomyItems: Map<DateString, TaxonomyItem[]> = records.reduce(\n (acc, record) => {\n const currentArray = acc.get(<string>record.start_date) || [];\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(<string>record.start_date, currentArray);\n return acc;\n },\n new Map<DateString, TaxonomyItem[]>(),\n );\n\n let startDate: string | number;\n if (records.length > 0 && records[0].start_date) {\n startDate = records[0].start_date;\n }\n\n return Array.from(taxonomyItems.entries()).map(\n ([startDate, taxonomyItems]) => ({\n startDate,\n taxonomyItems,\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 dataProviders: string[] = [];\n const streamIds: string[] = [];\n const weights: string[] = [];\n const startDate = taxonomy.startDate;\n\n for (const item of taxonomy.taxonomyItems) {\n const dataProviderHex = item.childStream.dataProvider\n .getAddress()\n .slice(2); // Remove 0x prefix\n dataProviders.push(dataProviderHex);\n streamIds.push(item.childStream.streamId.getId());\n weights.push(item.weight.toString());\n }\n\n const res = await this.checkedComposedExecute(\"set_taxonomy\", [\n ActionInput.fromObject({\n $data_providers: dataProviders,\n $stream_ids: streamIds,\n $weights: weights,\n $start_date: startDate,\n }),\n ]);\n\n // Optional: insert into Postgres via neon connection if a connection string is provided\n if (this.pool) {\n // parent info comes from this.locator\n const parentProvider = this.locator.dataProvider.getAddress().slice(2);\n const parentStreamId = this.locator.streamId.getId();\n const startDateText = String(startDate);\n\n for (const item of taxonomy.taxonomyItems) {\n const childProvider = item.childStream.dataProvider.getAddress().slice(2);\n const childStreamId = item.childStream.streamId.getId();\n const weight = item.weight;\n\n await this.pool.query(\n `INSERT INTO taxonomies\n (parent_data_provider, parent_stream_id,\n child_data_provider, child_stream_id,\n weight, start_date)\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT ON CONSTRAINT unique_parent_child DO NOTHING`,\n [\n parentProvider,\n parentStreamId,\n childProvider,\n childStreamId,\n weight,\n startDateText,\n ],\n );\n }\n\n await this.pool.end();\n console.log(\"Successfully inserted taxonomy into Explorer DB\", {\n parentStreamId,\n childStreamId: streamIds,\n weight: weights,\n startDate,\n });\n }\n\n return res;\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: Stream): ComposedStream {\n return new ComposedStream(\n stream[\"kwilClient\"],\n stream[\"kwilSigner\"],\n stream[\"locator\"],\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA4B;AAK5B,6BAAgC;AAChC,sBAAyB;AACzB,4BAA2B;AAC3B,oBAAuB;AAGhB,IAAM,yBAAyB;AAmB/B,IAAM,iBAAN,MAAM,wBAAuB,qBAAO;AAAA,EAC/B;AAAA,EAEV,YACE,YACA,YACA,SACA,MACA;AACA,UAAM,YAAY,YAAY,OAAO;AACrC,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAc,2BAA0C;AAEtD,UAAM,KAAK,iBAAiB,iCAAW,QAAQ;AAG/C,UAAM,aAAa,MAAM,KAAK,QAAQ;AACtC,QAAI,eAAe,iCAAW,UAAU;AACtC,YAAM,IAAI,MAAM,sBAAsB;AAAA,IACxC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAc,uBACZ,QACA,QACqC;AACrC,UAAM,KAAK,yBAAyB;AACpC,WAAO,KAAK,QAAQ,QAAQ,MAAM;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;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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/deployStream.ts
|
|
@@ -35,8 +25,6 @@ __export(deployStream_exports, {
|
|
|
35
25
|
module.exports = __toCommonJS(deployStream_exports);
|
|
36
26
|
var import_contractValues = require("./contractValues.cjs");
|
|
37
27
|
var import_contractsContent = require("../contracts/contractsContent.cjs");
|
|
38
|
-
var import_pg = __toESM(require("pg"), 1);
|
|
39
|
-
var { Pool } = import_pg.default;
|
|
40
28
|
async function deployStream(input) {
|
|
41
29
|
try {
|
|
42
30
|
const schema = await getContract(input.streamType, input.contractVersion);
|
|
@@ -49,18 +37,17 @@ async function deployStream(input) {
|
|
|
49
37
|
input.kwilSigner,
|
|
50
38
|
input.synchronous
|
|
51
39
|
);
|
|
52
|
-
if (input.
|
|
40
|
+
if (input.pool) {
|
|
53
41
|
console.log("Neon connection detected, attempting to insert into DB...");
|
|
54
42
|
const signer = input.kwilSigner.signer;
|
|
55
43
|
const dataProvider = signer.address.toLowerCase().substring(2);
|
|
56
|
-
|
|
57
|
-
await pool.query(
|
|
44
|
+
await input.pool.query(
|
|
58
45
|
`INSERT INTO streams (data_provider, stream_id, type, stream_name, display_name, categories, owner_wallet, geography, tags)
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
47
|
+
ON CONFLICT (data_provider, stream_id) DO NOTHING`,
|
|
61
48
|
[dataProvider, input.streamId.getId(), input.streamType, input.streamId.getName(), input.streamId.getName(), "{External}", dataProvider, "Global", "{External}"]
|
|
62
49
|
);
|
|
63
|
-
await pool.end();
|
|
50
|
+
await input.pool.end();
|
|
64
51
|
console.log("successfully inserted into Explorer DB", input.streamId.getName());
|
|
65
52
|
}
|
|
66
53
|
return txHash;
|
|
@@ -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 { CompiledKuneiform } from \"@kwilteam/kwil-js/dist/core/payload\";\nimport {\n composedStreamTemplate,\n primitiveStreamTemplate,\n composedStreamTemplateUnix,\n primitiveStreamTemplateUnix\n} from \"../contracts/contractsContent\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { KwilSigner } from \"@kwilteam/kwil-js\";\nimport { StreamId } from \"../util/StreamId\";\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
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 { CompiledKuneiform } from \"@kwilteam/kwil-js/dist/core/payload\";\nimport {\n composedStreamTemplate,\n primitiveStreamTemplate,\n composedStreamTemplateUnix,\n primitiveStreamTemplateUnix\n} from \"../contracts/contractsContent\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { KwilSigner } from \"@kwilteam/kwil-js\";\nimport { StreamId } from \"../util/StreamId\";\nimport { type Pool } from \"pg\";\nexport interface DeployStreamInput {\n streamId: StreamId;\n streamType: StreamType;\n kwilClient: Kwil<any>;\n kwilSigner: KwilSigner;\n synchronous?: boolean;\n contractVersion?: number;\n pool?: Pool;\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 schema = await getContract(input.streamType, input.contractVersion);\n\n schema.name = input.streamId.getId();\n\n const txHash = await input.kwilClient.deploy(\n {\n schema,\n description: `TN SDK - Deploying ${input.streamType} stream: ${input.streamId.getId()}`,\n },\n input.kwilSigner,\n input.synchronous,\n );\n\n // Optional: insert into Postgres via neon connection\n if (input.pool) {\n console.log(\"Neon connection detected, attempting to insert into DB...\");\n\n const signer: any = input.kwilSigner.signer;\n const dataProvider = signer.address.toLowerCase().substring(2);\n\n await input.pool.query(\n `INSERT INTO streams (data_provider, stream_id, type, stream_name, display_name, categories, owner_wallet, geography, tags)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)\n ON CONFLICT (data_provider, stream_id) DO NOTHING`,\n [dataProvider, input.streamId.getId(), input.streamType, input.streamId.getName(), input.streamId.getName(), '{External}', dataProvider, 'Global', '{External}'],\n );\n await input.pool.end();\n\n console.log(\"successfully inserted into Explorer DB\", input.streamId.getName());\n }\n\n return txHash;\n } catch (error) {\n throw new Error(`Failed to deploy stream: ${error}`);\n }\n}\n\n/**\n * Returns the contract content based on the stream type.\n * @param streamType - The type of the stream.\n * @param contractVersion\n * @returns The contract content as a Uint8Array.\n */\nasync function getContract(streamType: StreamType, contractVersion?: number): Promise<CompiledKuneiform> {\n switch (streamType) {\n case StreamType.Composed:\n return contractVersion === 2 ? composedStreamTemplateUnix : composedStreamTemplate;\n case StreamType.Primitive:\n return contractVersion === 2 ? primitiveStreamTemplateUnix : primitiveStreamTemplate;\n default:\n throw new Error(`Unknown stream type: ${streamType}`);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA2B;AAI3B,8BAKO;AAwBP,eAAsB,aACpB,OACqC;AACrC,MAAI;AACF,UAAM,SAAS,MAAM,YAAY,MAAM,YAAY,MAAM,eAAe;AAExE,WAAO,OAAO,MAAM,SAAS,MAAM;AAEnC,UAAM,SAAS,MAAM,MAAM,WAAW;AAAA,MACpC;AAAA,QACE;AAAA,QACA,aAAa,sBAAsB,MAAM,UAAU,YAAY,MAAM,SAAS,MAAM,CAAC;AAAA,MACvF;AAAA,MACA,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAGA,QAAI,MAAM,MAAM;AACd,cAAQ,IAAI,2DAA2D;AAEvE,YAAM,SAAc,MAAM,WAAW;AACrC,YAAM,eAAe,OAAO,QAAQ,YAAY,EAAE,UAAU,CAAC;AAE7D,YAAM,MAAM,KAAK;AAAA,QACf;AAAA;AAAA;AAAA,QAGA,CAAC,cAAc,MAAM,SAAS,MAAM,GAAG,MAAM,YAAY,MAAM,SAAS,QAAQ,GAAG,MAAM,SAAS,QAAQ,GAAG,cAAc,cAAc,UAAU,YAAY;AAAA,MACjK;AACA,YAAM,MAAM,KAAK,IAAI;AAErB,cAAQ,IAAI,0CAA0C,MAAM,SAAS,QAAQ,CAAC;AAAA,IAChF;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,4BAA4B,KAAK,EAAE;AAAA,EACrD;AACF;AAQA,eAAe,YAAY,YAAwB,iBAAsD;AACvG,UAAQ,YAAY;AAAA,IAClB,KAAK,iCAAW;AACd,aAAO,oBAAoB,IAAI,qDAA6B;AAAA,IAC9D,KAAK,iCAAW;AACd,aAAO,oBAAoB,IAAI,sDAA8B;AAAA,IAC/D;AACE,YAAM,IAAI,MAAM,wBAAwB,UAAU,EAAE;AAAA,EACxD;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -23,7 +23,7 @@ __export(EthereumAddress_exports, {
|
|
|
23
23
|
EthereumAddress: () => EthereumAddress
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(EthereumAddress_exports);
|
|
26
|
-
var import_ethers = require("ethers
|
|
26
|
+
var import_ethers = require("ethers");
|
|
27
27
|
var import_either = require("monads-io/either");
|
|
28
28
|
var import_meta = {};
|
|
29
29
|
var EthereumAddress = class _EthereumAddress {
|
|
@@ -3,12 +3,18 @@ import { WebKwil } from "@kwilteam/kwil-js";
|
|
|
3
3
|
import { BaseTNClient } from "./client.mjs";
|
|
4
4
|
var BrowserTNClient = class extends BaseTNClient {
|
|
5
5
|
constructor(options) {
|
|
6
|
+
if (options.neonConnectionString) {
|
|
7
|
+
console.warn("Neon connection string is not supported in browser environments. Database operations won't be performed.");
|
|
8
|
+
}
|
|
6
9
|
super(options);
|
|
7
10
|
this.kwilClient = new WebKwil({
|
|
8
11
|
...options,
|
|
9
12
|
kwilProvider: options.endpoint
|
|
10
13
|
});
|
|
11
14
|
}
|
|
15
|
+
getPool() {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
12
18
|
};
|
|
13
19
|
var browserClient_default = BrowserTNClient;
|
|
14
20
|
export {
|
|
@@ -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;
|
|
4
|
+
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { WebKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\nimport { type Pool } from \"pg\";\n\nexport class BrowserTNClient extends BaseTNClient<EnvironmentType.BROWSER> {\n constructor(options: TNClientOptions) {\n if (options.neonConnectionString) {\n console.warn(\"Neon connection string is not supported in browser environments. Database operations won't be performed.\");\n }\n\n super(options);\n this.kwilClient = new WebKwil({\n ...options,\n kwilProvider: options.endpoint,\n });\n }\n\n protected getPool(): Pool | undefined {\n return undefined;\n }\n}\n\nexport default BrowserTNClient;\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,eAAe;AACxB,SAAS,oBAAqC;AAGvC,IAAM,kBAAN,cAA8B,aAAsC;AAAA,EACzE,YAAY,SAA0B;AACpC,QAAI,QAAQ,sBAAsB;AAChC,cAAQ,KAAK,0GAA0G;AAAA,IACzH;AAEA,UAAM,OAAO;AACb,SAAK,aAAa,IAAI,QAAQ;AAAA,MAC5B,GAAG;AAAA,MACH,cAAc,QAAQ;AAAA,IACxB,CAAC;AAAA,EACH;AAAA,EAEU,UAA4B;AACpC,WAAO;AAAA,EACT;AACF;AAEA,IAAO,wBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -100,7 +100,7 @@ var BaseTNClient = class {
|
|
|
100
100
|
kwilClient: this.getKwilClient(),
|
|
101
101
|
kwilSigner: this.getKwilSigner(),
|
|
102
102
|
contractVersion,
|
|
103
|
-
|
|
103
|
+
pool: this.getPool()
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
@@ -147,7 +147,7 @@ var BaseTNClient = class {
|
|
|
147
147
|
this.getKwilClient(),
|
|
148
148
|
this.getKwilSigner(),
|
|
149
149
|
stream,
|
|
150
|
-
this.
|
|
150
|
+
this.getPool()
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
@@ -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/builders\";\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 { ComposedStream } from \"../contracts-api/composedStream\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { destroyStream } from \"../contracts-api/destroyStream\";\nimport { PrimitiveStream } from \"../contracts-api/primitiveStream\";\nimport { Stream } from \"../contracts-api/stream\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listAllStreams } from \"./listAllStreams\";\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 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 === \"success\") {\n resolve(receipt.data);\n } else {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\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 contractVersion?: number\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n contractVersion: contractVersion,\n
|
|
5
|
-
"mappings": ";;;;;AAAA,SAAS,QAAQ,kBAAqC;AAQtD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,cAAc;AAGvB,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;
|
|
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/builders\";\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 { ComposedStream } from \"../contracts-api/composedStream\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { destroyStream } from \"../contracts-api/destroyStream\";\nimport { PrimitiveStream } from \"../contracts-api/primitiveStream\";\nimport { Stream } from \"../contracts-api/stream\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listAllStreams } from \"./listAllStreams\";\nimport { type Pool } from \"pg\";\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 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 === \"success\") {\n resolve(receipt.data);\n } else {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\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 contractVersion?: number\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n contractVersion: contractVersion,\n pool: this.getPool(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param streamId - The ID 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 streamId: StreamId,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await destroyStream({\n streamId,\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 * @param stream - The locator of the stream to load.\n * @returns An instance of IStream.\n */\n loadStream(stream: StreamLocator): Stream {\n return new Stream(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n stream,\n );\n }\n\n /**\n * Loads a primitive stream.\n * @param stream - The locator of the primitive stream to load.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveStream(stream: StreamLocator): PrimitiveStream {\n return PrimitiveStream.fromStream(this.loadStream(stream));\n }\n\n /**\n * Loads a composed stream.\n * @param stream - The locator of the composed stream to load.\n * @returns An instance of IComposedStream.\n */\n loadComposedStream(stream: StreamLocator): ComposedStream {\n return new ComposedStream(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n stream,\n this.getPool(),\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 owner - The owner of the streams. If not provided, all streams will be returned.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getAllStreams(owner?: EthereumAddress): Promise<StreamLocator[]> {\n return listAllStreams(this.getKwilClient(), owner);\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 protected abstract getPool(): Pool | undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,SAAS,QAAQ,kBAAqC;AAQtD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,cAAc;AAGvB,SAAS,uBAAuB;AAEhC,SAAS,sBAAsB;AAexB,IAAe,eAAf,MAAuD;AAAA,EAKlD,YAAY,SAA0B;AAJhD,wBAAU;AACV,wBAAU;AACV,wBAAU;AAGR,SAAK,aAAa,QAAQ;AAC1B,SAAK,uBAAuB,QAAQ;AAAA,EACtC;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,EACt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AiB,EAAE;AACtD,WAAO,UAAU,MAAM;AAAA,EACzB;AAIF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/client/client.test.ts
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { ethers } from "ethers
|
|
3
|
+
import { ethers } from "ethers";
|
|
4
4
|
import { NodeTNClient } from "./nodeClient.mjs";
|
|
5
5
|
describe.sequential("Client", { timeout: 3e4 }, () => {
|
|
6
6
|
it.skipIf(process.env.CI);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/client/nodeClient.ts
|
|
2
9
|
import { NodeKwil } from "@kwilteam/kwil-js";
|
|
3
10
|
import { BaseTNClient } from "./client.mjs";
|
|
@@ -9,6 +16,14 @@ var NodeTNClient = class extends BaseTNClient {
|
|
|
9
16
|
kwilProvider: options.endpoint
|
|
10
17
|
});
|
|
11
18
|
}
|
|
19
|
+
getPool() {
|
|
20
|
+
const pg = __require("pg");
|
|
21
|
+
const { Pool } = pg;
|
|
22
|
+
if (this.neonConnectionString) {
|
|
23
|
+
return new Pool({ connectionString: this.neonConnectionString });
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
12
27
|
};
|
|
13
28
|
var nodeClient_default = NodeTNClient;
|
|
14
29
|
export {
|
|
@@ -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\";\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { NodeKwil } from \"@kwilteam/kwil-js\";\nimport { BaseTNClient, TNClientOptions } from \"./client\";\nimport { type Pool } from \"pg\";\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 protected getPool(): Pool | undefined {\n const pg = require(\"pg\");\n const { Pool } = pg;\n if (this.neonConnectionString) {\n return new Pool({ connectionString: this.neonConnectionString });\n }\n return undefined;\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;AAAA,EAEU,UAA4B;AACpC,UAAM,KAAK,UAAQ,IAAI;AACvB,UAAM,EAAE,KAAK,IAAI;AACjB,QAAI,KAAK,sBAAsB;AAC7B,aAAO,IAAI,KAAK,EAAE,kBAAkB,KAAK,qBAAqB,CAAC;AAAA,IACjE;AACA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,14 +8,12 @@ import { EthereumAddress } from "../util/EthereumAddress.mjs";
|
|
|
8
8
|
import { StreamId } from "../util/StreamId.mjs";
|
|
9
9
|
import { StreamType } from "./contractValues.mjs";
|
|
10
10
|
import { Stream } from "./stream.mjs";
|
|
11
|
-
import pg from "pg";
|
|
12
|
-
var { Pool } = pg;
|
|
13
11
|
var ErrorStreamNotComposed = "stream is not a composed stream";
|
|
14
12
|
var ComposedStream = class _ComposedStream extends Stream {
|
|
15
|
-
constructor(kwilClient, kwilSigner, locator,
|
|
13
|
+
constructor(kwilClient, kwilSigner, locator, pool) {
|
|
16
14
|
super(kwilClient, kwilSigner, locator);
|
|
17
|
-
__publicField(this, "
|
|
18
|
-
this.
|
|
15
|
+
__publicField(this, "pool");
|
|
16
|
+
this.pool = pool;
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* Checks if the stream is a valid composed stream.
|
|
@@ -103,8 +101,7 @@ var ComposedStream = class _ComposedStream extends Stream {
|
|
|
103
101
|
$start_date: startDate
|
|
104
102
|
})
|
|
105
103
|
]);
|
|
106
|
-
if (this.
|
|
107
|
-
const pool = new Pool({ connectionString: this.neonConnectionString });
|
|
104
|
+
if (this.pool) {
|
|
108
105
|
const parentProvider = this.locator.dataProvider.getAddress().slice(2);
|
|
109
106
|
const parentStreamId = this.locator.streamId.getId();
|
|
110
107
|
const startDateText = String(startDate);
|
|
@@ -112,7 +109,7 @@ var ComposedStream = class _ComposedStream extends Stream {
|
|
|
112
109
|
const childProvider = item.childStream.dataProvider.getAddress().slice(2);
|
|
113
110
|
const childStreamId = item.childStream.streamId.getId();
|
|
114
111
|
const weight = item.weight;
|
|
115
|
-
await pool.query(
|
|
112
|
+
await this.pool.query(
|
|
116
113
|
`INSERT INTO taxonomies
|
|
117
114
|
(parent_data_provider, parent_stream_id,
|
|
118
115
|
child_data_provider, child_stream_id,
|
|
@@ -129,7 +126,7 @@ var ComposedStream = class _ComposedStream extends Stream {
|
|
|
129
126
|
]
|
|
130
127
|
);
|
|
131
128
|
}
|
|
132
|
-
await pool.end();
|
|
129
|
+
await this.pool.end();
|
|
133
130
|
console.log("Successfully inserted taxonomy into Explorer DB", {
|
|
134
131
|
parentStreamId,
|
|
135
132
|
childStreamId: streamIds,
|