robonomics-interface-vue 0.2.2 → 0.3.0
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/datalog/useQuery.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/subscription/useQuery.js +4 -0
- package/dist/twin/useQuery.js +1 -0
- package/package.json +10 -10
- package/dist/devices/____isWatch___useDevices copy.d.ts +0 -25
- package/dist/devices/____isWatch___useDevices copy.js +0 -53
- package/dist/twin/_useQuery copy.d.ts +0 -32
- package/dist/twin/_useQuery copy.js +0 -238
package/dist/datalog/useQuery.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -61,7 +61,11 @@ export function useQuery() {
|
|
|
61
61
|
}
|
|
62
62
|
const data = {
|
|
63
63
|
data: raw.toHuman(),
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
65
|
+
// @ts-ignore
|
|
64
66
|
validUntil: subscription.tools.validUntil(raw),
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
68
|
+
// @ts-ignore
|
|
65
69
|
month: subscription.tools.countMonth(raw)
|
|
66
70
|
};
|
|
67
71
|
return {
|
package/dist/twin/useQuery.js
CHANGED
|
@@ -73,6 +73,7 @@ export function useQuery() {
|
|
|
73
73
|
TopicChanged: ["sender", "twinId", "topic", "account"],
|
|
74
74
|
NewDigitalTwin: ["sender", "twinId"]
|
|
75
75
|
};
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
77
|
const values = event.data.toJSON();
|
|
77
78
|
if (!Object.keys(methods).includes(event.method)) {
|
|
78
79
|
return values; // Fallback to default form
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "robonomics-interface-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "vol4tim <sas@robonomics.network>",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"type": "module",
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"pretty": "prettier --write \"./src/**/*.{js,ts,json}\""
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@polkadot/api": "^16.4.6",
|
|
29
|
-
"@polkadot/util-crypto": "^13.5.3",
|
|
30
|
-
"robonomics-interface": "^0.5.1",
|
|
31
28
|
"vue": "^3.0.0"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@eslint/js": "^
|
|
31
|
+
"@eslint/js": "^10.0.1",
|
|
32
|
+
"@polkadot/api": "^16.5.4",
|
|
35
33
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"prettier": "^3.
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
34
|
+
"eslint": "^10.0.2",
|
|
35
|
+
"prettier": "^3.8.1",
|
|
36
|
+
"robonomics-api-augment": "^0.3.0",
|
|
37
|
+
"robonomics-interface": "^0.6.0",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"typescript-eslint": "^8.56.1",
|
|
40
|
+
"vue": "^3.5.29"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Ref } from "vue";
|
|
2
|
-
/**
|
|
3
|
-
* Vue сomposable for working with devices list
|
|
4
|
-
* @description Provides functionality for loading and tracking changes in devices list by address
|
|
5
|
-
* @param addressInit - Address for getting devices list
|
|
6
|
-
* @param options - Composable options
|
|
7
|
-
* @param [options.isWatch] - Whether to track changes in the address
|
|
8
|
-
* @param [options.immediate] - Whether to start loading immediately
|
|
9
|
-
* @returns Object with devices list state and management methods
|
|
10
|
-
* @example
|
|
11
|
-
* const { data, loading, error, load } = useDevices('5F...', { immediate: true })
|
|
12
|
-
*
|
|
13
|
-
* // With reactive address
|
|
14
|
-
* const address = ref('5F...')
|
|
15
|
-
* const { data } = useDevices(address)
|
|
16
|
-
*/
|
|
17
|
-
export declare function useDevices(addressInit: string | Ref<string>, { isWatch, immediate }?: {
|
|
18
|
-
isWatch?: boolean | undefined;
|
|
19
|
-
immediate?: boolean | undefined;
|
|
20
|
-
}): {
|
|
21
|
-
load: () => void;
|
|
22
|
-
loading: Ref<boolean, boolean>;
|
|
23
|
-
error: Ref<Error | null, Error | null>;
|
|
24
|
-
data: Ref<string[] | null | undefined, string[] | null | undefined>;
|
|
25
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { tools } from "robonomics-interface";
|
|
2
|
-
import { isRef, onUnmounted, ref, toRefs, watch } from "vue";
|
|
3
|
-
import { useLoader } from "../tools/useLoader.js";
|
|
4
|
-
import { usePolkadotApi } from "../usePolkadotApi.js";
|
|
5
|
-
import { useQuery } from "./useQuery.js";
|
|
6
|
-
/**
|
|
7
|
-
* Vue сomposable for working with devices list
|
|
8
|
-
* @description Provides functionality for loading and tracking changes in devices list by address
|
|
9
|
-
* @param addressInit - Address for getting devices list
|
|
10
|
-
* @param options - Composable options
|
|
11
|
-
* @param [options.isWatch] - Whether to track changes in the address
|
|
12
|
-
* @param [options.immediate] - Whether to start loading immediately
|
|
13
|
-
* @returns Object with devices list state and management methods
|
|
14
|
-
* @example
|
|
15
|
-
* const { data, loading, error, load } = useDevices('5F...', { immediate: true })
|
|
16
|
-
*
|
|
17
|
-
* // With reactive address
|
|
18
|
-
* const address = ref('5F...')
|
|
19
|
-
* const { data } = useDevices(address)
|
|
20
|
-
*/
|
|
21
|
-
export function useDevices(addressInit, { isWatch = true, immediate = true } = {}) {
|
|
22
|
-
const address = isRef(addressInit) ? addressInit : ref(addressInit);
|
|
23
|
-
const { isConnected, watchConnect } = usePolkadotApi();
|
|
24
|
-
const { loader, setter, state } = useLoader();
|
|
25
|
-
const { getDevices } = useQuery();
|
|
26
|
-
const watcher = tools.createWatcher();
|
|
27
|
-
/**
|
|
28
|
-
* Loads devices list and subscribes to changes
|
|
29
|
-
* @description Stops previous subscription, loads devices list and subscribes to new changes
|
|
30
|
-
*/
|
|
31
|
-
const load = () => {
|
|
32
|
-
loader(async () => {
|
|
33
|
-
watcher.stop();
|
|
34
|
-
const unsubscribe = await getDevices(address.value, setter);
|
|
35
|
-
watcher.set(unsubscribe);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
if (isWatch) {
|
|
39
|
-
const isChangedArgs = ref(immediate);
|
|
40
|
-
watch(address, () => {
|
|
41
|
-
if (isChangedArgs.value || isConnected.value) {
|
|
42
|
-
load();
|
|
43
|
-
}
|
|
44
|
-
isChangedArgs.value = true;
|
|
45
|
-
}, { immediate });
|
|
46
|
-
watchConnect(load, { isCheck: isChangedArgs });
|
|
47
|
-
}
|
|
48
|
-
onUnmounted(watcher.stop);
|
|
49
|
-
return {
|
|
50
|
-
...toRefs(state),
|
|
51
|
-
load
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { UnsubscribePromise } from "@polkadot/api/types";
|
|
2
|
-
import { Callback } from "robonomics-interface";
|
|
3
|
-
import { AnyJson, Filter, FnCallback } from "../types.js";
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} TwinQueryComposable
|
|
6
|
-
* @property {Function} getTwins - Function for getting list of twins
|
|
7
|
-
* @property {Function} getTwin - Function for getting data of specific twin
|
|
8
|
-
* @property {Function} listen - Function for subscribing to digitalTwin events
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Vue сomposable for twin queries
|
|
12
|
-
* @description Provides functions for loading twin data and subscribing to digitalTwin events
|
|
13
|
-
* @returns {TwinQueryComposable} Object with methods for working with twin
|
|
14
|
-
* @example
|
|
15
|
-
* const { getTwins, getTwin, listen } = useQuery()
|
|
16
|
-
*
|
|
17
|
-
* // Getting list of twins
|
|
18
|
-
* const twins = await getTwins('5F...')
|
|
19
|
-
*
|
|
20
|
-
* // Getting specific twin
|
|
21
|
-
* const twinData = await getTwin(123)
|
|
22
|
-
*
|
|
23
|
-
* // Subscribing to events
|
|
24
|
-
* const unsubscribe = await listen({ method: 'NewDigitalTwin' }, (event) => {
|
|
25
|
-
* console.log('New twin created:', event)
|
|
26
|
-
* })
|
|
27
|
-
*/
|
|
28
|
-
export declare function useQuery(): {
|
|
29
|
-
getTwin: (twinId: number, cb: Callback<AnyJson>) => UnsubscribePromise;
|
|
30
|
-
getTwins: (address: string, cb?: Callback<FnCallback> | undefined) => Promise<import("@polkadot/api/types").VoidFn | number[]>;
|
|
31
|
-
listen: (filter: Filter | undefined, cb: Callback<any>, toJSON?: boolean | undefined) => Promise<import("@polkadot/api/types").VoidFn>;
|
|
32
|
-
};
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { addressEq } from "@polkadot/util-crypto";
|
|
2
|
-
import { tools, twin } from "robonomics-interface";
|
|
3
|
-
import { usePolkadotApi } from "../usePolkadotApi.js";
|
|
4
|
-
// interface Api {
|
|
5
|
-
// // Предполагаемый интерфейс для Api, можно уточнить при необходимости
|
|
6
|
-
// [key: string]: any;
|
|
7
|
-
// }
|
|
8
|
-
// // Глобальная переменная isConnected (предполагается boolean)
|
|
9
|
-
// const isConnected: boolean = false;
|
|
10
|
-
// // Типизация для composeWithCheckConnection
|
|
11
|
-
// function composeWithCheckConnections<T extends (...args: any[]) => any>(
|
|
12
|
-
// fn: T
|
|
13
|
-
// ): (...args: Parameters<T>) => ReturnType<T> {
|
|
14
|
-
// return (...args: Parameters<T>): ReturnType<T> => {
|
|
15
|
-
// if (!isConnected) {
|
|
16
|
-
// throw new Error("Not connected");
|
|
17
|
-
// }
|
|
18
|
-
// return fn(api, ...args);
|
|
19
|
-
// };
|
|
20
|
-
// }
|
|
21
|
-
// // Перегрузки для getTwin
|
|
22
|
-
// function getTwinss(api: Api, twinId: number): number;
|
|
23
|
-
// function getTwinss(
|
|
24
|
-
// api: Api,
|
|
25
|
-
// twinId: number,
|
|
26
|
-
// cb: (id: number) => number
|
|
27
|
-
// ): () => number;
|
|
28
|
-
// function getTwinss(
|
|
29
|
-
// api: Api,
|
|
30
|
-
// twinId: number,
|
|
31
|
-
// cb?: (id: number) => number
|
|
32
|
-
// ): number | (() => number) {
|
|
33
|
-
// if (cb) {
|
|
34
|
-
// return () => cb(twinId);
|
|
35
|
-
// }
|
|
36
|
-
// return twinId + 1000;
|
|
37
|
-
// }
|
|
38
|
-
// // Типизация для newGetTwin
|
|
39
|
-
// const newGetTwin = composeWithCheckConnections(getTwinss);
|
|
40
|
-
// const asdasd = newGetTwin(123);
|
|
41
|
-
/**
|
|
42
|
-
* @typedef {Object} TwinQueryComposable
|
|
43
|
-
* @property {Function} getTwins - Function for getting list of twins
|
|
44
|
-
* @property {Function} getTwin - Function for getting data of specific twin
|
|
45
|
-
* @property {Function} listen - Function for subscribing to digitalTwin events
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* Vue сomposable for twin queries
|
|
49
|
-
* @description Provides functions for loading twin data and subscribing to digitalTwin events
|
|
50
|
-
* @returns {TwinQueryComposable} Object with methods for working with twin
|
|
51
|
-
* @example
|
|
52
|
-
* const { getTwins, getTwin, listen } = useQuery()
|
|
53
|
-
*
|
|
54
|
-
* // Getting list of twins
|
|
55
|
-
* const twins = await getTwins('5F...')
|
|
56
|
-
*
|
|
57
|
-
* // Getting specific twin
|
|
58
|
-
* const twinData = await getTwin(123)
|
|
59
|
-
*
|
|
60
|
-
* // Subscribing to events
|
|
61
|
-
* const unsubscribe = await listen({ method: 'NewDigitalTwin' }, (event) => {
|
|
62
|
-
* console.log('New twin created:', event)
|
|
63
|
-
* })
|
|
64
|
-
*/
|
|
65
|
-
export function useQuery() {
|
|
66
|
-
const { composeWithCheckConnection } = usePolkadotApi();
|
|
67
|
-
async function getTwin(api, twinId, cb) {
|
|
68
|
-
if (cb) {
|
|
69
|
-
return await twin.query.getTwin(api, twinId, (data) => cb(data.toJSON()));
|
|
70
|
-
}
|
|
71
|
-
const data = await twin.query.getTwin(api, twinId);
|
|
72
|
-
return data.toJSON();
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Gets list of twins for specified address
|
|
76
|
-
* @description Loads total number of twins and list of twins for address
|
|
77
|
-
* @param {string} address - Address for getting list of twins
|
|
78
|
-
* @param {Function} cb - Callback function for processing data (optional)
|
|
79
|
-
* @returns {Promise<any|Function>} List of twins or unsubscribe function
|
|
80
|
-
* @async
|
|
81
|
-
* @example
|
|
82
|
-
* // Simple loading
|
|
83
|
-
* const twins = await getTwins('5F...')
|
|
84
|
-
*
|
|
85
|
-
* // With subscription to changes
|
|
86
|
-
* const unsubscribe = await getTwins('5F...', (loader) => {
|
|
87
|
-
* // loader - function for loading updated data
|
|
88
|
-
* const newData = await loader()
|
|
89
|
-
* console.log('Twins updated:', newData)
|
|
90
|
-
* })
|
|
91
|
-
*/
|
|
92
|
-
const getTwins = async (api, address, cb) => {
|
|
93
|
-
if (cb) {
|
|
94
|
-
return await twin.query.getTotalTwins(api, (total) => cb(() => twin.query.getTwins(api, address, total)));
|
|
95
|
-
}
|
|
96
|
-
const total = await twin.query.getTotalTwins(api);
|
|
97
|
-
return await twin.query.getTwins(api, address, total);
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Subscribes to digitalTwin events
|
|
101
|
-
* @description Creates subscription to digitalTwin events with filtering capability
|
|
102
|
-
* @param {Object} filter - Filter for events
|
|
103
|
-
* @param {boolean} [filter.success] - Filter by event success
|
|
104
|
-
* @param {string} [filter.method] - Filter by event method
|
|
105
|
-
* @param {string} [filter.sender] - Filter by sender
|
|
106
|
-
* @param {Function} cb - Callback function for processing events
|
|
107
|
-
* @param {boolean} [toJSON] - Whether to convert events to JSON format
|
|
108
|
-
* @returns {Promise<Function>} Function for unsubscribing
|
|
109
|
-
* @async
|
|
110
|
-
* @example
|
|
111
|
-
* // Subscribe to all events
|
|
112
|
-
* const unsubscribe = await listen({}, (event) => {
|
|
113
|
-
* console.log('Digital twin event:', event)
|
|
114
|
-
* })
|
|
115
|
-
*
|
|
116
|
-
* // Subscribe to specific method
|
|
117
|
-
* const unsubscribe = await listen({ method: 'NewDigitalTwin' }, (event) => {
|
|
118
|
-
* console.log('New twin created:', event)
|
|
119
|
-
* })
|
|
120
|
-
*
|
|
121
|
-
* // Unsubscribe
|
|
122
|
-
* unsubscribe()
|
|
123
|
-
*/
|
|
124
|
-
const listen = async (api, filter = {}, cb, toJSON = true) => {
|
|
125
|
-
/**
|
|
126
|
-
* Converts event to human-readable format
|
|
127
|
-
* @param event - Event to convert
|
|
128
|
-
* @returns Converted event
|
|
129
|
-
*/
|
|
130
|
-
const toHuman = (event) => {
|
|
131
|
-
// const met = ["sender", "twinId", "topic", "account"];
|
|
132
|
-
// met.reduce((obj, key, index) => {
|
|
133
|
-
// obj[key] = values[index];
|
|
134
|
-
// return obj;
|
|
135
|
-
// }, {});
|
|
136
|
-
// type MetKeys = "sender" | "twinId" | "topic" | "account";
|
|
137
|
-
// // Определяем тип для значений (например, string | number, но можно уточнить)
|
|
138
|
-
// type MetValues = (string | number)[];
|
|
139
|
-
// type MethodKeys = "TopicChanged" | "NewDigitalTwin";
|
|
140
|
-
// const methods: { [k in MethodKeys]: string[] } = {
|
|
141
|
-
// // Определяем тип для результирующего объекта
|
|
142
|
-
// type ResultObject = { [K in MetKeys]: string | number };
|
|
143
|
-
// const met: MetKeys[] = ["sender", "twinId", "topic", "account"];
|
|
144
|
-
// const valuesa: MetValues = ["user1", 123, "chat", "acc123"]; // Пример значений
|
|
145
|
-
// const result = met.reduce(
|
|
146
|
-
// (obj: ResultObject, key: MetKeys, index: number) => {
|
|
147
|
-
// obj[key] = valuesa[index];
|
|
148
|
-
// return obj;
|
|
149
|
-
// },
|
|
150
|
-
// {} as ResultObject
|
|
151
|
-
// );
|
|
152
|
-
// console.log(result);
|
|
153
|
-
// type MetKeys = "sender" | "twinId" | "topic" | "account";
|
|
154
|
-
// type MetValues = (string | number)[];
|
|
155
|
-
// type ResultObject = { [K in MetKeys]: string | number };
|
|
156
|
-
// const met: MetKeys[] = ["sender", "twinId", "topic", "account"];
|
|
157
|
-
// const valuess: MetValues = ["user1", 123, "chat", "acc123"];
|
|
158
|
-
// // Проверка длины массивов
|
|
159
|
-
// if (met.length !== valuess.length) {
|
|
160
|
-
// throw new Error("Arrays 'met' and 'values' must have the same length");
|
|
161
|
-
// }
|
|
162
|
-
// const result = met.reduce(
|
|
163
|
-
// (obj: ResultObject, key: MetKeys, index: number) => {
|
|
164
|
-
// const value = valuess[index];
|
|
165
|
-
// if (value === undefined) {
|
|
166
|
-
// throw new Error(`Value at index ${index} is undefined`);
|
|
167
|
-
// }
|
|
168
|
-
// obj[key] = value; // Ошибка здесь
|
|
169
|
-
// // obj[key] = valuess[index]; // Теперь TypeScript знает, что values[index] не undefined
|
|
170
|
-
// return obj;
|
|
171
|
-
// },
|
|
172
|
-
// {} as ResultObject
|
|
173
|
-
// );
|
|
174
|
-
// console.log(result);
|
|
175
|
-
// Результат: { sender: "user1", twinId: 123, topic: "chat", account: "acc123" }
|
|
176
|
-
// interface ResultObject {
|
|
177
|
-
// sender: string;
|
|
178
|
-
// twinId: number;
|
|
179
|
-
// topic: string;
|
|
180
|
-
// account: string;
|
|
181
|
-
// }
|
|
182
|
-
// const met: (keyof ResultObject)[] = [
|
|
183
|
-
// "sender",
|
|
184
|
-
// "twinId",
|
|
185
|
-
// "topic",
|
|
186
|
-
// "account"
|
|
187
|
-
// ];
|
|
188
|
-
// const valuess: [string, number, string, string] = [
|
|
189
|
-
// "user1",
|
|
190
|
-
// 123,
|
|
191
|
-
// "chat",
|
|
192
|
-
// "acc123"
|
|
193
|
-
// ];
|
|
194
|
-
// if (met.length !== valuess.length) {
|
|
195
|
-
// throw new Error("Arrays 'met' and 'values' must have the same length");
|
|
196
|
-
// }
|
|
197
|
-
// const result: ResultObject = Object.fromEntries(
|
|
198
|
-
// met.map((key, index) => [key, valuess[index]])
|
|
199
|
-
// ) as ResultObject;
|
|
200
|
-
// console.log(result);
|
|
201
|
-
const methods = {
|
|
202
|
-
TopicChanged: ["sender", "twinId", "topic", "account"],
|
|
203
|
-
NewDigitalTwin: ["sender", "twinId"]
|
|
204
|
-
};
|
|
205
|
-
if (event.method !== "TopicChanged" &&
|
|
206
|
-
event.method !== "NewDigitalTwin") {
|
|
207
|
-
return event.data.toJSON(); // Fallback to default form
|
|
208
|
-
}
|
|
209
|
-
const values = event.data.toJSON();
|
|
210
|
-
return methods[event.method]
|
|
211
|
-
? methods[event.method].reduce((obj, key, index) => {
|
|
212
|
-
const value = values[index];
|
|
213
|
-
if (value === undefined) {
|
|
214
|
-
throw new Error(`Value at index ${index} is undefined`);
|
|
215
|
-
}
|
|
216
|
-
obj[key] = value;
|
|
217
|
-
return obj;
|
|
218
|
-
}, {})
|
|
219
|
-
: values;
|
|
220
|
-
};
|
|
221
|
-
return await tools.events.on(api, {
|
|
222
|
-
section: "digitalTwin",
|
|
223
|
-
success: filter.success || true,
|
|
224
|
-
method: filter.method
|
|
225
|
-
}, (r) => {
|
|
226
|
-
for (const event of r) {
|
|
227
|
-
if (!filter.sender || addressEq(event.data[0], filter.sender)) {
|
|
228
|
-
cb(toJSON ? toHuman(event) : event);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
return {
|
|
234
|
-
getTwin: composeWithCheckConnection(getTwin),
|
|
235
|
-
getTwins: composeWithCheckConnection(getTwins),
|
|
236
|
-
listen: composeWithCheckConnection(listen)
|
|
237
|
-
};
|
|
238
|
-
}
|