@trufnetwork/sdk-js 0.0.0-dev-20241126103246
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/LICENSE.md +13 -0
- package/README.md +95 -0
- package/dist/cjs/client/browserClient.cjs +39 -0
- package/dist/cjs/client/browserClient.cjs.map +7 -0
- package/dist/cjs/client/client.cjs +200 -0
- package/dist/cjs/client/client.cjs.map +7 -0
- package/dist/cjs/client/client.test.cjs +32 -0
- package/dist/cjs/client/client.test.cjs.map +7 -0
- package/dist/cjs/client/listAllStreams.cjs +51 -0
- package/dist/cjs/client/listAllStreams.cjs.map +7 -0
- package/dist/cjs/client/nodeClient.cjs +39 -0
- package/dist/cjs/client/nodeClient.cjs.map +7 -0
- package/dist/cjs/contracts/composed_stream_template.json +1638 -0
- package/dist/cjs/contracts/contractsContent.cjs +53 -0
- package/dist/cjs/contracts/contractsContent.cjs.map +7 -0
- package/dist/cjs/contracts/primitive_stream_template.json +952 -0
- package/dist/cjs/contracts-api/composedStream.cjs +137 -0
- package/dist/cjs/contracts-api/composedStream.cjs.map +7 -0
- package/dist/cjs/contracts-api/contractValues.cjs +66 -0
- package/dist/cjs/contracts-api/contractValues.cjs.map +7 -0
- package/dist/cjs/contracts-api/deployStream.cjs +55 -0
- package/dist/cjs/contracts-api/deployStream.cjs.map +7 -0
- package/dist/cjs/contracts-api/destroyStream.cjs +45 -0
- package/dist/cjs/contracts-api/destroyStream.cjs.map +7 -0
- package/dist/cjs/contracts-api/primitiveStream.cjs +86 -0
- package/dist/cjs/contracts-api/primitiveStream.cjs.map +7 -0
- package/dist/cjs/contracts-api/stream.cjs +379 -0
- package/dist/cjs/contracts-api/stream.cjs.map +7 -0
- package/dist/cjs/index.browser.cjs +29 -0
- package/dist/cjs/index.browser.cjs.map +7 -0
- package/dist/cjs/index.cjs +31 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/index.common.cjs +39 -0
- package/dist/cjs/index.common.cjs.map +7 -0
- package/dist/cjs/index.node.cjs +29 -0
- package/dist/cjs/index.node.cjs.map +7 -0
- package/dist/cjs/types/other.cjs +19 -0
- package/dist/cjs/types/other.cjs.map +7 -0
- package/dist/cjs/types/stream.cjs +19 -0
- package/dist/cjs/types/stream.cjs.map +7 -0
- package/dist/cjs/util/EthereumAddress.cjs +108 -0
- package/dist/cjs/util/EthereumAddress.cjs.map +7 -0
- package/dist/cjs/util/StreamId.cjs +77 -0
- package/dist/cjs/util/StreamId.cjs.map +7 -0
- package/dist/cjs/util/head.cjs +30 -0
- package/dist/cjs/util/head.cjs.map +7 -0
- package/dist/cjs/util/visibility.cjs +42 -0
- package/dist/cjs/util/visibility.cjs.map +7 -0
- package/dist/esm/client/browserClient.mjs +18 -0
- package/dist/esm/client/browserClient.mjs.map +7 -0
- package/dist/esm/client/client.mjs +183 -0
- package/dist/esm/client/client.mjs.map +7 -0
- package/dist/esm/client/client.test.mjs +30 -0
- package/dist/esm/client/client.test.mjs.map +7 -0
- package/dist/esm/client/listAllStreams.mjs +30 -0
- package/dist/esm/client/listAllStreams.mjs.map +7 -0
- package/dist/esm/client/nodeClient.mjs +18 -0
- package/dist/esm/client/nodeClient.mjs.map +7 -0
- package/dist/esm/contracts/composed_stream_template.json +1638 -0
- package/dist/esm/contracts/contractsContent.mjs +21 -0
- package/dist/esm/contracts/contractsContent.mjs.map +7 -0
- package/dist/esm/contracts/primitive_stream_template.json +952 -0
- package/dist/esm/contracts-api/composedStream.mjs +116 -0
- package/dist/esm/contracts-api/composedStream.mjs.map +7 -0
- package/dist/esm/contracts-api/contractValues.mjs +45 -0
- package/dist/esm/contracts-api/contractValues.mjs.map +7 -0
- package/dist/esm/contracts-api/deployStream.mjs +37 -0
- package/dist/esm/contracts-api/deployStream.mjs.map +7 -0
- package/dist/esm/contracts-api/destroyStream.mjs +24 -0
- package/dist/esm/contracts-api/destroyStream.mjs.map +7 -0
- package/dist/esm/contracts-api/primitiveStream.mjs +65 -0
- package/dist/esm/contracts-api/primitiveStream.mjs.map +7 -0
- package/dist/esm/contracts-api/stream.mjs +367 -0
- package/dist/esm/contracts-api/stream.mjs.map +7 -0
- package/dist/esm/index.browser.mjs +7 -0
- package/dist/esm/index.browser.mjs.map +7 -0
- package/dist/esm/index.common.mjs +18 -0
- package/dist/esm/index.common.mjs.map +7 -0
- package/dist/esm/index.mjs +9 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/index.node.mjs +7 -0
- package/dist/esm/index.node.mjs.map +7 -0
- package/dist/esm/types/other.mjs +1 -0
- package/dist/esm/types/other.mjs.map +7 -0
- package/dist/esm/types/stream.mjs +1 -0
- package/dist/esm/types/stream.mjs.map +7 -0
- package/dist/esm/util/EthereumAddress.mjs +90 -0
- package/dist/esm/util/EthereumAddress.mjs.map +7 -0
- package/dist/esm/util/StreamId.mjs +59 -0
- package/dist/esm/util/StreamId.mjs.map +7 -0
- package/dist/esm/util/head.mjs +9 -0
- package/dist/esm/util/head.mjs.map +7 -0
- package/dist/esm/util/visibility.mjs +21 -0
- package/dist/esm/util/visibility.mjs.map +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/client/browserClient.d.ts +7 -0
- package/dist/types/client/browserClient.d.ts.map +1 -0
- package/dist/types/client/client.d.ts +103 -0
- package/dist/types/client/client.d.ts.map +1 -0
- package/dist/types/client/client.test.d.ts +2 -0
- package/dist/types/client/client.test.d.ts.map +1 -0
- package/dist/types/client/listAllStreams.d.ts +14 -0
- package/dist/types/client/listAllStreams.d.ts.map +1 -0
- package/dist/types/client/nodeClient.d.ts +7 -0
- package/dist/types/client/nodeClient.d.ts.map +1 -0
- package/dist/types/contracts/contractsContent.d.ts +4 -0
- package/dist/types/contracts/contractsContent.d.ts.map +1 -0
- package/dist/types/contracts-api/composedStream.d.ts +57 -0
- package/dist/types/contracts-api/composedStream.d.ts.map +1 -0
- package/dist/types/contracts-api/contractValues.d.ts +49 -0
- package/dist/types/contracts-api/contractValues.d.ts.map +1 -0
- package/dist/types/contracts-api/deployStream.d.ts +23 -0
- package/dist/types/contracts-api/deployStream.d.ts.map +1 -0
- package/dist/types/contracts-api/destroyStream.d.ts +27 -0
- package/dist/types/contracts-api/destroyStream.d.ts.map +1 -0
- package/dist/types/contracts-api/primitiveStream.d.ts +39 -0
- package/dist/types/contracts-api/primitiveStream.d.ts.map +1 -0
- package/dist/types/contracts-api/stream.d.ts +135 -0
- package/dist/types/contracts-api/stream.d.ts.map +1 -0
- package/dist/types/index.browser.d.ts +3 -0
- package/dist/types/index.browser.d.ts.map +1 -0
- package/dist/types/index.common.d.ts +16 -0
- package/dist/types/index.common.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.node.d.ts +3 -0
- package/dist/types/index.node.d.ts.map +1 -0
- package/dist/types/types/other.d.ts +2 -0
- package/dist/types/types/other.d.ts.map +1 -0
- package/dist/types/types/stream.d.ts +13 -0
- package/dist/types/types/stream.d.ts.map +1 -0
- package/dist/types/util/EthereumAddress.d.ts +14 -0
- package/dist/types/util/EthereumAddress.d.ts.map +1 -0
- package/dist/types/util/StreamId.d.ts +13 -0
- package/dist/types/util/StreamId.d.ts.map +1 -0
- package/dist/types/util/head.d.ts +3 -0
- package/dist/types/util/head.d.ts.map +1 -0
- package/dist/types/util/visibility.d.ts +10 -0
- package/dist/types/util/visibility.d.ts.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,137 @@
|
|
|
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/composedStream.ts
|
|
21
|
+
var composedStream_exports = {};
|
|
22
|
+
__export(composedStream_exports, {
|
|
23
|
+
ComposedStream: () => ComposedStream,
|
|
24
|
+
ErrorStreamNotComposed: () => ErrorStreamNotComposed
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(composedStream_exports);
|
|
27
|
+
var import_action = require("@kwilteam/kwil-js/dist/core/action.js");
|
|
28
|
+
var import_EthereumAddress = require("../util/EthereumAddress.cjs");
|
|
29
|
+
var import_StreamId = require("../util/StreamId.cjs");
|
|
30
|
+
var import_contractValues = require("./contractValues.cjs");
|
|
31
|
+
var import_stream = require("./stream.cjs");
|
|
32
|
+
var ErrorStreamNotComposed = "stream is not a composed stream";
|
|
33
|
+
var ComposedStream = class _ComposedStream extends import_stream.Stream {
|
|
34
|
+
constructor(kwilClient, kwilSigner, locator) {
|
|
35
|
+
super(kwilClient, kwilSigner, locator);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the stream is a valid composed stream.
|
|
39
|
+
* A valid composed stream must be:
|
|
40
|
+
* - initialized
|
|
41
|
+
* - of type composed
|
|
42
|
+
*/
|
|
43
|
+
async checkValidComposedStream() {
|
|
44
|
+
await this.checkInitialized(import_contractValues.StreamType.Composed);
|
|
45
|
+
const streamType = await this.getType();
|
|
46
|
+
if (streamType !== import_contractValues.StreamType.Composed) {
|
|
47
|
+
throw new Error(ErrorStreamNotComposed);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Executes a method after checking if the stream is a valid composed stream
|
|
52
|
+
* @param method The method name to execute
|
|
53
|
+
* @param inputs The inputs for the action
|
|
54
|
+
* @returns A generic response containing the transaction receipt
|
|
55
|
+
*/
|
|
56
|
+
async checkedComposedExecute(method, inputs) {
|
|
57
|
+
await this.checkValidComposedStream();
|
|
58
|
+
return this.execute(method, inputs);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the taxonomy of the stream
|
|
62
|
+
* @param params Parameters for describing taxonomies
|
|
63
|
+
* @returns A promise that resolves to the taxonomy
|
|
64
|
+
*/
|
|
65
|
+
async describeTaxonomies(params) {
|
|
66
|
+
const result = await this.call("describe_taxonomies", [
|
|
67
|
+
import_action.ActionInput.fromObject({ $latest_version: params.latestVersion })
|
|
68
|
+
]);
|
|
69
|
+
return result.mapRight((records) => {
|
|
70
|
+
const taxonomyItems = records.reduce(
|
|
71
|
+
(acc, record) => {
|
|
72
|
+
const currentArray = acc.get(record.start_date) || [];
|
|
73
|
+
currentArray.push({
|
|
74
|
+
childStream: {
|
|
75
|
+
streamId: import_StreamId.StreamId.fromString(record.child_stream_id).throw(),
|
|
76
|
+
dataProvider: import_EthereumAddress.EthereumAddress.fromString(
|
|
77
|
+
record.child_data_provider
|
|
78
|
+
).throw()
|
|
79
|
+
},
|
|
80
|
+
weight: record.weight
|
|
81
|
+
});
|
|
82
|
+
acc.set(record.start_date, currentArray);
|
|
83
|
+
return acc;
|
|
84
|
+
},
|
|
85
|
+
/* @__PURE__ */ new Map()
|
|
86
|
+
);
|
|
87
|
+
let startDate;
|
|
88
|
+
if (records.length > 0 && records[0].start_date) {
|
|
89
|
+
startDate = records[0].start_date;
|
|
90
|
+
}
|
|
91
|
+
return Array.from(taxonomyItems.entries()).map(
|
|
92
|
+
([startDate2, taxonomyItems2]) => ({
|
|
93
|
+
startDate: startDate2,
|
|
94
|
+
taxonomyItems: taxonomyItems2
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
}).throw();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Sets the taxonomy of the stream
|
|
101
|
+
* @param taxonomy The taxonomy to set
|
|
102
|
+
* @returns A promise that resolves to the transaction receipt
|
|
103
|
+
*/
|
|
104
|
+
async setTaxonomy(taxonomy) {
|
|
105
|
+
const dataProviders = [];
|
|
106
|
+
const streamIds = [];
|
|
107
|
+
const weights = [];
|
|
108
|
+
const startDate = taxonomy.startDate;
|
|
109
|
+
for (const item of taxonomy.taxonomyItems) {
|
|
110
|
+
const dataProviderHex = item.childStream.dataProvider.getAddress().slice(2);
|
|
111
|
+
dataProviders.push(dataProviderHex);
|
|
112
|
+
streamIds.push(item.childStream.streamId.getId());
|
|
113
|
+
weights.push(item.weight.toString());
|
|
114
|
+
}
|
|
115
|
+
return this.checkedComposedExecute("set_taxonomy", [
|
|
116
|
+
import_action.ActionInput.fromObject({
|
|
117
|
+
$data_providers: dataProviders,
|
|
118
|
+
$stream_ids: streamIds,
|
|
119
|
+
$weights: weights,
|
|
120
|
+
$start_date: startDate
|
|
121
|
+
})
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates a ComposedStream from a base Stream
|
|
126
|
+
* @param stream The base stream to convert
|
|
127
|
+
* @returns A ComposedStream instance
|
|
128
|
+
*/
|
|
129
|
+
static fromStream(stream) {
|
|
130
|
+
return new _ComposedStream(
|
|
131
|
+
stream["kwilClient"],
|
|
132
|
+
stream["kwilSigner"],
|
|
133
|
+
stream["locator"]
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=composedStream.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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\";\n\nexport const ErrorStreamNotComposed = \"stream is not a composed stream\";\n\nexport interface TaxonomySet {\n taxonomyItems: TaxonomyItem[];\n startDate?: DateString;\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 constructor(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n locator: StreamLocator,\n ) {\n super(kwilClient, kwilSigner, locator);\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;\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(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(record.start_date, currentArray);\n return acc;\n },\n new Map<DateString, TaxonomyItem[]>(),\n );\n\n let startDate: DateString | undefined;\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 return 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\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": "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",
|
|
6
|
+
"names": ["startDate", "taxonomyItems"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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/contractValues.ts
|
|
21
|
+
var contractValues_exports = {};
|
|
22
|
+
__export(contractValues_exports, {
|
|
23
|
+
MetadataKey: () => MetadataKey,
|
|
24
|
+
MetadataKeyValueMap: () => MetadataKeyValueMap,
|
|
25
|
+
MetadataTableKey: () => MetadataTableKey,
|
|
26
|
+
MetadataType: () => MetadataType,
|
|
27
|
+
StreamType: () => StreamType
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(contractValues_exports);
|
|
30
|
+
var StreamType = {
|
|
31
|
+
Composed: "composed",
|
|
32
|
+
Primitive: "primitive"
|
|
33
|
+
};
|
|
34
|
+
var MetadataKey = {
|
|
35
|
+
ReadonlyKey: "readonly_key",
|
|
36
|
+
StreamOwner: "stream_owner",
|
|
37
|
+
TypeKey: "type",
|
|
38
|
+
ComposeVisibilityKey: "compose_visibility",
|
|
39
|
+
ReadVisibilityKey: "read_visibility",
|
|
40
|
+
AllowReadWalletKey: "allow_read_wallet",
|
|
41
|
+
AllowComposeStreamKey: "allow_compose_stream"
|
|
42
|
+
};
|
|
43
|
+
var MetadataType = {
|
|
44
|
+
Int: "int",
|
|
45
|
+
Bool: "bool",
|
|
46
|
+
Float: "float",
|
|
47
|
+
String: "string",
|
|
48
|
+
Ref: "ref"
|
|
49
|
+
};
|
|
50
|
+
var MetadataTableKey = {
|
|
51
|
+
[MetadataType.Int]: "value_i",
|
|
52
|
+
[MetadataType.Bool]: "value_b",
|
|
53
|
+
[MetadataType.Float]: "value_f",
|
|
54
|
+
[MetadataType.String]: "value_s",
|
|
55
|
+
[MetadataType.Ref]: "value_ref"
|
|
56
|
+
};
|
|
57
|
+
var MetadataKeyValueMap = {
|
|
58
|
+
[MetadataKey.ReadonlyKey]: MetadataType.Bool,
|
|
59
|
+
[MetadataKey.StreamOwner]: MetadataType.Ref,
|
|
60
|
+
[MetadataKey.TypeKey]: MetadataType.String,
|
|
61
|
+
[MetadataKey.ComposeVisibilityKey]: MetadataType.Int,
|
|
62
|
+
[MetadataKey.ReadVisibilityKey]: MetadataType.Int,
|
|
63
|
+
[MetadataKey.AllowReadWalletKey]: MetadataType.Ref,
|
|
64
|
+
[MetadataKey.AllowComposeStreamKey]: MetadataType.Ref
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=contractValues.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contracts-api/contractValues.ts"],
|
|
4
|
+
"sourcesContent": ["export const StreamType = {\n Composed: \"composed\",\n Primitive: \"primitive\",\n} as const;\nexport type StreamType = (typeof StreamType)[keyof typeof StreamType];\n\nexport const MetadataKey = {\n ReadonlyKey: \"readonly_key\",\n StreamOwner: \"stream_owner\",\n TypeKey: \"type\",\n ComposeVisibilityKey: \"compose_visibility\",\n ReadVisibilityKey: \"read_visibility\",\n AllowReadWalletKey: \"allow_read_wallet\",\n AllowComposeStreamKey: \"allow_compose_stream\",\n} as const;\nexport type MetadataKey = (typeof MetadataKey)[keyof typeof MetadataKey];\n\nexport const MetadataType = {\n Int: \"int\",\n Bool: \"bool\",\n Float: \"float\",\n String: \"string\",\n Ref: \"ref\",\n} as const;\nexport type MetadataType = (typeof MetadataType)[keyof typeof MetadataType];\n\nexport const MetadataTableKey = {\n [MetadataType.Int]: \"value_i\",\n [MetadataType.Bool]: \"value_b\",\n [MetadataType.Float]: \"value_f\",\n [MetadataType.String]: \"value_s\",\n [MetadataType.Ref]: \"value_ref\",\n} as const satisfies Record<MetadataType, string>;\n\nexport const MetadataKeyValueMap = {\n [MetadataKey.ReadonlyKey]: MetadataType.Bool,\n [MetadataKey.StreamOwner]: MetadataType.Ref,\n [MetadataKey.TypeKey]: MetadataType.String,\n [MetadataKey.ComposeVisibilityKey]: MetadataType.Int,\n [MetadataKey.ReadVisibilityKey]: MetadataType.Int,\n [MetadataKey.AllowReadWalletKey]: MetadataType.Ref,\n [MetadataKey.AllowComposeStreamKey]: MetadataType.Ref,\n} as const satisfies Record<MetadataKey, MetadataType>;\n\ntype MetadataValueMap = {\n [MetadataType.Int]: string;\n [MetadataType.Bool]: boolean;\n [MetadataType.Float]: string;\n [MetadataType.String]: string;\n [MetadataType.Ref]: string;\n};\n\nexport type MetadataValueTypeForKey<K extends MetadataKey> =\n MetadataValueMap[(typeof MetadataKeyValueMap)[K]];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,aAAa;AAAA,EACxB,UAAU;AAAA,EACV,WAAW;AACb;AAGO,IAAM,cAAc;AAAA,EACzB,aAAa;AAAA,EACb,aAAa;AAAA,EACb,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACpB,uBAAuB;AACzB;AAGO,IAAM,eAAe;AAAA,EAC1B,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AACP;AAGO,IAAM,mBAAmB;AAAA,EAC9B,CAAC,aAAa,GAAG,GAAG;AAAA,EACpB,CAAC,aAAa,IAAI,GAAG;AAAA,EACrB,CAAC,aAAa,KAAK,GAAG;AAAA,EACtB,CAAC,aAAa,MAAM,GAAG;AAAA,EACvB,CAAC,aAAa,GAAG,GAAG;AACtB;AAEO,IAAM,sBAAsB;AAAA,EACjC,CAAC,YAAY,WAAW,GAAG,aAAa;AAAA,EACxC,CAAC,YAAY,WAAW,GAAG,aAAa;AAAA,EACxC,CAAC,YAAY,OAAO,GAAG,aAAa;AAAA,EACpC,CAAC,YAAY,oBAAoB,GAAG,aAAa;AAAA,EACjD,CAAC,YAAY,iBAAiB,GAAG,aAAa;AAAA,EAC9C,CAAC,YAAY,kBAAkB,GAAG,aAAa;AAAA,EAC/C,CAAC,YAAY,qBAAqB,GAAG,aAAa;AACpD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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/deployStream.ts
|
|
21
|
+
var deployStream_exports = {};
|
|
22
|
+
__export(deployStream_exports, {
|
|
23
|
+
deployStream: () => deployStream
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(deployStream_exports);
|
|
26
|
+
var import_contractValues = require("./contractValues.cjs");
|
|
27
|
+
var import_contractsContent = require("../contracts/contractsContent.cjs");
|
|
28
|
+
async function deployStream(input) {
|
|
29
|
+
try {
|
|
30
|
+
const schema = await getContract(input.streamType);
|
|
31
|
+
schema.name = input.streamId.getId();
|
|
32
|
+
const txHash = await input.kwilClient.deploy(
|
|
33
|
+
{
|
|
34
|
+
schema,
|
|
35
|
+
description: `TN SDK - Deploying ${input.streamType} stream: ${input.streamId.getId()}`
|
|
36
|
+
},
|
|
37
|
+
input.kwilSigner,
|
|
38
|
+
input.synchronous
|
|
39
|
+
);
|
|
40
|
+
return txHash;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to deploy stream: ${error}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function getContract(streamType) {
|
|
46
|
+
switch (streamType) {
|
|
47
|
+
case import_contractValues.StreamType.Composed:
|
|
48
|
+
return import_contractsContent.composedStreamTemplate;
|
|
49
|
+
case import_contractValues.StreamType.Primitive:
|
|
50
|
+
return import_contractsContent.primitiveStreamTemplate;
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`Unknown stream type: ${streamType}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=deployStream.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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} from \"../contracts/contractsContent\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { KwilSigner } from \"@kwilteam/kwil-js\";\nimport { StreamId } from \"../util/StreamId\";\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 schema = await getContract(input.streamType);\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 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 * @returns The contract content as a Uint8Array.\n */\nasync function getContract(streamType: StreamType): Promise<CompiledKuneiform> {\n switch (streamType) {\n case StreamType.Composed:\n return composedStreamTemplate;\n case StreamType.Primitive:\n return primitiveStreamTemplate;\n default:\n throw new Error(`Unknown stream type: ${streamType}`);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA2B;AAI3B,8BAGO;AAsBP,eAAsB,aACpB,OACqC;AACrC,MAAI;AACF,UAAM,SAAS,MAAM,YAAY,MAAM,UAAU;AAEjD,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;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,4BAA4B,KAAK,EAAE;AAAA,EACrD;AACF;AAOA,eAAe,YAAY,YAAoD;AAC7E,UAAQ,YAAY;AAAA,IAClB,KAAK,iCAAW;AACd,aAAO;AAAA,IACT,KAAK,iCAAW;AACd,aAAO;AAAA,IACT;AACE,YAAM,IAAI,MAAM,wBAAwB,UAAU,EAAE;AAAA,EACxD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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/destroyStream.ts
|
|
21
|
+
var destroyStream_exports = {};
|
|
22
|
+
__export(destroyStream_exports, {
|
|
23
|
+
destroyStream: () => destroyStream
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(destroyStream_exports);
|
|
26
|
+
var import_dbid = require("@kwilteam/kwil-js/dist/utils/dbid.js");
|
|
27
|
+
async function destroyStream(input) {
|
|
28
|
+
const dbid = (0, import_dbid.generateDBID)(
|
|
29
|
+
input.kwilSigner.identifier,
|
|
30
|
+
input.streamId.getId()
|
|
31
|
+
);
|
|
32
|
+
try {
|
|
33
|
+
const txReceipt = await input.kwilClient.drop(
|
|
34
|
+
{
|
|
35
|
+
dbid
|
|
36
|
+
},
|
|
37
|
+
input.kwilSigner,
|
|
38
|
+
input.synchronous
|
|
39
|
+
);
|
|
40
|
+
return txReceipt;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to destroy stream: ${error}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=destroyStream.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contracts-api/destroyStream.ts"],
|
|
4
|
+
"sourcesContent": ["import { StreamId } from \"../util/StreamId\";\nimport { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { KwilSigner } from \"@kwilteam/kwil-js\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { generateDBID } from \"@kwilteam/kwil-js/dist/utils/dbid\";\n\n/**\n * Input parameters for destroying a stream.\n */\nexport interface DestroyStreamInput {\n streamId: StreamId;\n kwilClient: Kwil<any>;\n kwilSigner: KwilSigner;\n synchronous?: boolean;\n}\n\n/**\n * Output after destroying a stream.\n */\nexport interface DestroyStreamOutput {\n receipt: TxReceipt;\n}\n\n/**\n * Destroys a stream from TN.\n * @param input - The input parameters for destroying the stream.\n * @returns The transaction receipt of the destruction.\n */\nexport async function destroyStream(\n input: DestroyStreamInput,\n): Promise<GenericResponse<TxReceipt>> {\n const dbid = generateDBID(\n input.kwilSigner.identifier,\n input.streamId.getId(),\n );\n try {\n const txReceipt = await input.kwilClient.drop(\n {\n dbid,\n },\n input.kwilSigner,\n input.synchronous,\n );\n\n return txReceipt;\n } catch (error) {\n throw new Error(`Failed to destroy stream: ${error}`);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,kBAA6B;AAwB7B,eAAsB,cACpB,OACqC;AACrC,QAAM,WAAO;AAAA,IACX,MAAM,WAAW;AAAA,IACjB,MAAM,SAAS,MAAM;AAAA,EACvB;AACA,MAAI;AACF,UAAM,YAAY,MAAM,MAAM,WAAW;AAAA,MACvC;AAAA,QACE;AAAA,MACF;AAAA,MACA,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,6BAA6B,KAAK,EAAE;AAAA,EACtD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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/primitiveStream.ts
|
|
21
|
+
var primitiveStream_exports = {};
|
|
22
|
+
__export(primitiveStream_exports, {
|
|
23
|
+
PrimitiveStream: () => PrimitiveStream
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(primitiveStream_exports);
|
|
26
|
+
var import_action = require("@kwilteam/kwil-js/dist/core/action.js");
|
|
27
|
+
var import_contractValues = require("./contractValues.cjs");
|
|
28
|
+
var import_stream = require("./stream.cjs");
|
|
29
|
+
var ErrorStreamNotPrimitive = "stream is not a primitive stream";
|
|
30
|
+
var PrimitiveStream = class _PrimitiveStream extends import_stream.Stream {
|
|
31
|
+
constructor(kwilClient, kwilSigner, locator) {
|
|
32
|
+
super(kwilClient, kwilSigner, locator);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the stream is a valid primitive stream.
|
|
36
|
+
* A valid primitive stream must be:
|
|
37
|
+
* - initialized
|
|
38
|
+
* - of type primitive
|
|
39
|
+
*/
|
|
40
|
+
async checkValidPrimitiveStream() {
|
|
41
|
+
await this.checkInitialized(import_contractValues.StreamType.Primitive);
|
|
42
|
+
const streamType = await this.getType();
|
|
43
|
+
if (streamType !== import_contractValues.StreamType.Primitive) {
|
|
44
|
+
throw new Error(ErrorStreamNotPrimitive);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Executes a method after checking if the stream is a valid primitive stream
|
|
49
|
+
* @param method The method name to execute
|
|
50
|
+
* @param inputs The inputs for the action
|
|
51
|
+
* @returns A generic response containing the transaction receipt
|
|
52
|
+
*/
|
|
53
|
+
async checkedPrimitiveExecute(method, inputs) {
|
|
54
|
+
await this.checkValidPrimitiveStream();
|
|
55
|
+
return this.execute(method, inputs);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Inserts records into the stream
|
|
59
|
+
* @param inputs Array of records to insert
|
|
60
|
+
* @returns Transaction receipt
|
|
61
|
+
*/
|
|
62
|
+
async insertRecords(inputs) {
|
|
63
|
+
await this.checkValidPrimitiveStream();
|
|
64
|
+
const actionInputs = inputs.map(
|
|
65
|
+
(input) => import_action.ActionInput.fromObject({
|
|
66
|
+
$date_value: input.dateValue,
|
|
67
|
+
$value: input.value
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
return await this.checkedPrimitiveExecute("insert_record", actionInputs);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a PrimitiveStream from a base Stream
|
|
74
|
+
* @param stream The base stream to convert
|
|
75
|
+
* @returns A Promise that resolves to a PrimitiveStream instance
|
|
76
|
+
*/
|
|
77
|
+
static fromStream(stream) {
|
|
78
|
+
const primitiveStream = new _PrimitiveStream(
|
|
79
|
+
stream["kwilClient"],
|
|
80
|
+
stream["kwilSigner"],
|
|
81
|
+
stream["locator"]
|
|
82
|
+
);
|
|
83
|
+
return primitiveStream;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=primitiveStream.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contracts-api/primitiveStream.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 { StreamType } from \"./contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { Stream } from \"./stream\";\n\nconst ErrorStreamNotPrimitive = \"stream is not a primitive stream\";\n\nexport class PrimitiveStream extends Stream {\n constructor(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n locator: StreamLocator,\n ) {\n super(kwilClient, kwilSigner, locator);\n }\n\n /**\n * Checks if the stream is a valid primitive stream.\n * A valid primitive stream must be:\n * - initialized\n * - of type primitive\n */\n private async checkValidPrimitiveStream(): Promise<void> {\n // First check if initialized\n await this.checkInitialized(StreamType.Primitive);\n\n // Then check if is primitive\n const streamType = await this.getType();\n if (streamType !== StreamType.Primitive) {\n throw new Error(ErrorStreamNotPrimitive);\n }\n }\n\n /**\n * Executes a method after checking if the stream is a valid primitive 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 checkedPrimitiveExecute(\n method: string,\n inputs: ActionInput[],\n ): Promise<GenericResponse<TxReceipt>> {\n await this.checkValidPrimitiveStream();\n return this.execute(method, inputs);\n }\n\n /**\n * Inserts records into the stream\n * @param inputs Array of records to insert\n * @returns Transaction receipt\n */\n public async insertRecords(\n inputs: InsertRecordInput[],\n ): Promise<GenericResponse<TxReceipt>> {\n await this.checkValidPrimitiveStream();\n\n const actionInputs = inputs.map((input) =>\n ActionInput.fromObject({\n $date_value: input.dateValue,\n $value: input.value,\n }),\n );\n\n return await this.checkedPrimitiveExecute(\"insert_record\", actionInputs);\n }\n\n /**\n * Creates a PrimitiveStream from a base Stream\n * @param stream The base stream to convert\n * @returns A Promise that resolves to a PrimitiveStream instance\n */\n public static fromStream(stream: Stream): PrimitiveStream {\n const primitiveStream = new PrimitiveStream(\n stream[\"kwilClient\"],\n stream[\"kwilSigner\"],\n stream[\"locator\"],\n );\n\n return primitiveStream;\n }\n}\nexport interface InsertRecordInput {\n dateValue: string;\n // value is a string to support arbitrary precision\n value: string;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA4B;AAG5B,4BAA2B;AAE3B,oBAAuB;AAEvB,IAAM,0BAA0B;AAEzB,IAAM,kBAAN,MAAM,yBAAwB,qBAAO;AAAA,EAC1C,YACE,YACA,YACA,SACA;AACA,UAAM,YAAY,YAAY,OAAO;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAc,4BAA2C;AAEvD,UAAM,KAAK,iBAAiB,iCAAW,SAAS;AAGhD,UAAM,aAAa,MAAM,KAAK,QAAQ;AACtC,QAAI,eAAe,iCAAW,WAAW;AACvC,YAAM,IAAI,MAAM,uBAAuB;AAAA,IACzC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAc,wBACZ,QACA,QACqC;AACrC,UAAM,KAAK,0BAA0B;AACrC,WAAO,KAAK,QAAQ,QAAQ,MAAM;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,cACX,QACqC;AACrC,UAAM,KAAK,0BAA0B;AAErC,UAAM,eAAe,OAAO;AAAA,MAAI,CAAC,UAC/B,0BAAY,WAAW;AAAA,QACrB,aAAa,MAAM;AAAA,QACnB,QAAQ,MAAM;AAAA,MAChB,CAAC;AAAA,IACH;AAEA,WAAO,MAAM,KAAK,wBAAwB,iBAAiB,YAAY;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAc,WAAW,QAAiC;AACxD,UAAM,kBAAkB,IAAI;AAAA,MAC1B,OAAO,YAAY;AAAA,MACnB,OAAO,YAAY;AAAA,MACnB,OAAO,SAAS;AAAA,IAClB;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|