diff --git a/lib/src/api_client/access/sql_read.dart b/lib/src/api_client/access/sql_read.dart index 30bdad2..d6843cf 100644 --- a/lib/src/api_client/access/sql_read.dart +++ b/lib/src/api_client/access/sql_read.dart @@ -1,5 +1,4 @@ import 'package:ext_rw/ext_rw.dart'; -import 'package:ext_rw/src/api_client/access/sql_builder.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_log.dart'; import 'package:hmi_core/hmi_core_result_new.dart'; @@ -46,14 +45,15 @@ class SqlRead implements SchemaRead { Future, Failure>> _fetch(Sql sql) { final request = ApiRequest( address: _address, + authToken: _authToken, + debug: _debug, query: SqlQuery( - authToken: _authToken, database: _database, sql: sql.build(), keepAlive: _keepAlive, - debug: _debug, ), ); + _log.debug("._fetch | request: $request"); return request.fetch().then((result) { return switch (result) { Ok(value :final reply) => () { diff --git a/lib/src/api_client/access/sql_write.dart b/lib/src/api_client/access/sql_write.dart index 4893852..aa78eae 100644 --- a/lib/src/api_client/access/sql_write.dart +++ b/lib/src/api_client/access/sql_write.dart @@ -1,5 +1,4 @@ import 'package:ext_rw/ext_rw.dart'; -import 'package:ext_rw/src/api_client/access/sql_builder.dart'; import 'package:hmi_core/hmi_core_failure.dart'; import 'package:hmi_core/hmi_core_log.dart'; import 'package:hmi_core/hmi_core_result_new.dart'; @@ -131,14 +130,15 @@ class SqlWrite implements SchemaWrite { Future, Failure>> _fetchWith(Sql sql) { final request = ApiRequest( address: _address, + authToken: _authToken, + debug: _debug, query: SqlQuery( - authToken: _authToken, database: _database, sql: sql.build(), keepAlive: _keepAlive, - debug: _debug, ), ); + _log.debug("._fetchWith | request: $request"); return request.fetch().then((result) { return switch (result) { Ok(:final value) => () { diff --git a/lib/src/api_client/query/api_query_type.dart b/lib/src/api_client/query/api_query_type.dart index 6471687..2148ff4 100644 --- a/lib/src/api_client/query/api_query_type.dart +++ b/lib/src/api_client/query/api_query_type.dart @@ -1,9 +1,7 @@ abstract class ApiQueryType { bool valid(); /// - String buildJson(); - /// - String get authToken; + String buildJson({String authToken = '', bool debug = false}); /// String get id; } \ No newline at end of file diff --git a/lib/src/api_client/query/executable_query.dart b/lib/src/api_client/query/executable_query.dart index be1c403..17497ef 100644 --- a/lib/src/api_client/query/executable_query.dart +++ b/lib/src/api_client/query/executable_query.dart @@ -4,26 +4,20 @@ import 'package:ext_rw/src/api_client/query/api_query_type.dart'; import 'package:uuid/uuid.dart'; class ExecutableQuery implements ApiQueryType { - final String _authToken; late String _id; final String _script; final Map _params; final bool _keepAlive; - final bool _debug; /// /// Prapares query for some executable ExecutableQuery({ - required String authToken, required String script, required Map params, bool keepAlive = false, - bool debug = false, }) : - _authToken = authToken, _script = script, _params = params, - _keepAlive = keepAlive, - _debug = debug; + _keepAlive = keepAlive; /// @override bool valid() { @@ -32,13 +26,13 @@ class ExecutableQuery implements ApiQueryType { } /// @override - String buildJson() { + String buildJson({String authToken = '', bool debug = false}) { _id = const Uuid().v1(); final jsonString = json.encode({ - 'authToken': _authToken, + 'authToken': authToken, 'id': _id, 'keepAlive': _keepAlive, - 'debug': _debug, + 'debug': debug, 'executable': { 'script': _script, 'params': _params, @@ -48,9 +42,6 @@ class ExecutableQuery implements ApiQueryType { } /// @override - String get authToken => _authToken; - /// - @override String get id => _id; /// String get script => _script; diff --git a/lib/src/api_client/query/python_query.dart b/lib/src/api_client/query/python_query.dart index 83864eb..a7fc584 100644 --- a/lib/src/api_client/query/python_query.dart +++ b/lib/src/api_client/query/python_query.dart @@ -4,26 +4,20 @@ import 'package:ext_rw/src/api_client/query/api_query_type.dart'; import 'package:uuid/uuid.dart'; class PythonQuery implements ApiQueryType { - final String _authToken; late String _id; final String _script; final bool _keepAlive; - final bool _debug; final Map _params; /// /// Prapares query for some python script PythonQuery({ - required String authToken, required String script, required Map params, bool keepAlive = false, - bool debug = false, }) : - _authToken = authToken, _script = script, _params = params, - _keepAlive = keepAlive, - _debug = debug; + _keepAlive = keepAlive; /// @override bool valid() { @@ -32,13 +26,13 @@ class PythonQuery implements ApiQueryType { } /// @override - String buildJson() { + String buildJson({String authToken = '', bool debug = false}) { _id = const Uuid().v1(); final jsonString = json.encode({ - 'authToken': _authToken, + 'authToken': authToken, 'id': _id, 'keepAlive': _keepAlive, - 'debug': _debug, + 'debug': debug, 'python': { 'script': _script, 'params': _params, @@ -48,9 +42,6 @@ class PythonQuery implements ApiQueryType { } /// @override - String get authToken => _authToken; - /// - @override String get id => _id; /// String get script => _script; diff --git a/lib/src/api_client/query/sql_query.dart b/lib/src/api_client/query/sql_query.dart index 4e844c2..c94ace8 100644 --- a/lib/src/api_client/query/sql_query.dart +++ b/lib/src/api_client/query/sql_query.dart @@ -4,26 +4,20 @@ import 'package:ext_rw/src/api_client/query/api_query_type.dart'; import 'package:uuid/uuid.dart'; class SqlQuery implements ApiQueryType { - final String _authToken; late String _id; final String _database; final String _sql; final bool _keepAlive; - final bool _debug; /// /// Prapares sql for some database SqlQuery({ - required String authToken, required String database, required String sql, bool keepAlive = false, - bool debug = false, }) : - _authToken = authToken, _database = database, _sql = sql, - _keepAlive = keepAlive, - _debug = debug; + _keepAlive = keepAlive; /// @override bool valid() { @@ -32,13 +26,13 @@ class SqlQuery implements ApiQueryType { } /// @override - String buildJson() { + String buildJson({String authToken = '', bool debug = false}) { _id = const Uuid().v1(); final jsonString = json.encode({ - 'authToken': _authToken, + 'authToken': authToken, 'id': _id, 'keepAlive': _keepAlive, - 'debug': _debug, + 'debug': debug, 'sql': { 'database': _database, 'sql': _sql, @@ -48,9 +42,6 @@ class SqlQuery implements ApiQueryType { } /// @override - String get authToken => _authToken; - /// - @override String get id => _id; /// String get database => _database; diff --git a/lib/src/api_client/request/api_request.dart b/lib/src/api_client/request/api_request.dart index ea85872..ad75162 100644 --- a/lib/src/api_client/request/api_request.dart +++ b/lib/src/api_client/request/api_request.dart @@ -16,19 +16,27 @@ import 'package:hmi_core/hmi_core_result_new.dart'; class ApiRequest { static final _log = const Log('ApiRequest')..level = LogLevel.info; final ApiAddress _address; + final String _authToken; final ApiQueryType _query; + final bool _debug; /// ApiRequest({ + required String authToken, required ApiAddress address, required ApiQueryType query, + bool debug = false, }) : + _authToken = authToken, _address = address, - _query = query; + _query = query, + _debug = debug; + /// + String get authToken => _authToken; /// /// sends created request to the remote /// returns reply if exists Future> fetch() async { - final query = _query.buildJson(); + final query = _query.buildJson(authToken: _authToken, debug: _debug); final bytes = utf8.encode(query); if (kIsWeb) { return _fetchWebSocket(bytes); diff --git a/lib/src/table_schema/table_schema.dart b/lib/src/table_schema/table_schema.dart index 02c0754..45dbab7 100644 --- a/lib/src/table_schema/table_schema.dart +++ b/lib/src/table_schema/table_schema.dart @@ -45,6 +45,7 @@ class TableSchema implements TableSchemaAbstract Future, Failure>> fetch(P params) async { final read = _read; return read.fetch(params).then((result) { + _log.debug('.fetch | result: $result'); return switch(result) { Ok, Failure>(:final value) => () { _entries.clear();