commit 45c1e50213ca858397947fccacf6f6a0133abf92
parent da52aa2079069e07b085850e0a889a2f41acbdcb
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Fri, 6 Dec 2024 05:41:10 +0000
client: edit iclientdatabase add `log_error` methods, edit iclientdialog, edit iclientgeolocationposition, add/edit iclientnostrlib methods
Diffstat:
7 files changed, 88 insertions(+), 12 deletions(-)
diff --git a/client/package.json b/client/package.json
@@ -11,7 +11,7 @@
},
"dependencies": {
"@noble/hashes": "^1.4.0",
- "@nostr-dev-kit/ndk": "^2.10.0",
+ "@nostr-dev-kit/ndk": "^2.10.6",
"@radroots/models": "workspace:*",
"@radroots/tauri-plugin-map-display": "workspace:*",
"@radroots/utils": "workspace:*",
diff --git a/client/src/database/tauri.ts b/client/src/database/tauri.ts
@@ -1,5 +1,5 @@
-import { LocationGcsSchema, LocationGcsUpdateSchema, MediaUploadSchema, MediaUploadUpdateSchema, NostrProfileSchema, NostrProfileUpdateSchema, NostrRelaySchema, NostrRelayUpdateSchema, TradeProductSchema, TradeProductUpdateSchema, parse_location_gcs, parse_location_gcs_form_fields, parse_location_gcs_get_composite_list, parse_location_gcs_list, parse_media_upload, parse_media_upload_form_fields, parse_media_upload_get_composite_list, parse_media_upload_list, parse_nostr_profile, parse_nostr_profile_form_fields, parse_nostr_profile_get_composite_list, parse_nostr_profile_list, parse_nostr_profile_relay_list, parse_nostr_relay, parse_nostr_relay_form_fields, parse_nostr_relay_get_composite_list, parse_nostr_relay_list, parse_trade_product, parse_trade_product_form_fields, parse_trade_product_get_composite_list, parse_trade_product_list, parse_trade_product_location_list, parse_trade_product_media_list, type ILocationGcsAdd, type ILocationGcsAddResolve, type ILocationGcsDelete, type ILocationGcsDeleteResolve, type ILocationGcsGet, type ILocationGcsGetOne, type ILocationGcsGetOneResolve, type ILocationGcsGetResolve, type ILocationGcsUpdate, type ILocationGcsUpdateResolve, type IMediaUploadAdd, type IMediaUploadAddResolve, type IMediaUploadDelete, type IMediaUploadDeleteResolve, type IMediaUploadGet, type IMediaUploadGetOne, type IMediaUploadGetOneResolve, type IMediaUploadGetResolve, type IMediaUploadUpdate, type IMediaUploadUpdateResolve, type IModelsQueryBindValueTuple, type IModelsQueryValue, type INostrProfileAdd, type INostrProfileAddResolve, type INostrProfileDelete, type INostrProfileDeleteResolve, type INostrProfileGet, type INostrProfileGetOne, type INostrProfileGetOneResolve, type INostrProfileGetResolve, type INostrProfileRelayRelation, type INostrProfileRelayRelationResolve, type INostrProfileRelayRelationResolveGetAll, type INostrProfileUpdate, type INostrProfileUpdateResolve, type INostrRelayAdd, type INostrRelayAddResolve, type INostrRelayDelete, type INostrRelayDeleteResolve, type INostrRelayGet, type INostrRelayGetOne, type INostrRelayGetOneResolve, type INostrRelayGetResolve, type INostrRelayUpdate, type INostrRelayUpdateResolve, type ITradeProductAdd, type ITradeProductAddResolve, type ITradeProductDelete, type ITradeProductDeleteResolve, type ITradeProductGet, type ITradeProductGetOne, type ITradeProductGetOneResolve, type ITradeProductGetResolve, type ITradeProductLocationRelation, type ITradeProductLocationRelationResolve, type ITradeProductLocationRelationResolveGetAll, type ITradeProductMediaRelation, type ITradeProductMediaRelationResolve, type ITradeProductMediaRelationResolveGetAll, type ITradeProductUpdate, type ITradeProductUpdateResolve, type LocationGcsFields, type LocationGcsFormFields, type MediaUploadFields, type MediaUploadFormFields, type NostrProfileFields, type NostrProfileFormFields, type NostrRelayFields, type NostrRelayFormFields, type TradeProductFields, type TradeProductFormFields } from "@radroots/models";
+import { LocationGcsSchema, LocationGcsUpdateSchema, LogErrorSchema, MediaUploadSchema, MediaUploadUpdateSchema, NostrProfileSchema, NostrProfileUpdateSchema, NostrRelaySchema, NostrRelayUpdateSchema, TradeProductSchema, TradeProductUpdateSchema, parse_location_gcs, parse_location_gcs_form_fields, parse_location_gcs_get_composite_list, parse_location_gcs_list, parse_log_error, parse_log_error_form_fields, parse_log_error_get_composite_list, parse_log_error_list, parse_media_upload, parse_media_upload_form_fields, parse_media_upload_get_composite_list, parse_media_upload_list, parse_nostr_profile, parse_nostr_profile_form_fields, parse_nostr_profile_get_composite_list, parse_nostr_profile_list, parse_nostr_profile_relay_list, parse_nostr_relay, parse_nostr_relay_form_fields, parse_nostr_relay_get_composite_list, parse_nostr_relay_list, parse_trade_product, parse_trade_product_form_fields, parse_trade_product_get_composite_list, parse_trade_product_list, parse_trade_product_location_list, parse_trade_product_media_list, type ILocationGcsAdd, type ILocationGcsAddResolve, type ILocationGcsDelete, type ILocationGcsDeleteResolve, type ILocationGcsGet, type ILocationGcsGetOne, type ILocationGcsGetOneResolve, type ILocationGcsGetResolve, type ILocationGcsUpdate, type ILocationGcsUpdateResolve, type ILogErrorAdd, type ILogErrorAddResolve, type ILogErrorDelete, type ILogErrorDeleteResolve, type ILogErrorGet, type ILogErrorGetOne, type ILogErrorGetOneResolve, type ILogErrorGetResolve, type IMediaUploadAdd, type IMediaUploadAddResolve, type IMediaUploadDelete, type IMediaUploadDeleteResolve, type IMediaUploadGet, type IMediaUploadGetOne, type IMediaUploadGetOneResolve, type IMediaUploadGetResolve, type IMediaUploadUpdate, type IMediaUploadUpdateResolve, type IModelsQueryBindValueTuple, type IModelsQueryValue, type INostrProfileAdd, type INostrProfileAddResolve, type INostrProfileDelete, type INostrProfileDeleteResolve, type INostrProfileGet, type INostrProfileGetOne, type INostrProfileGetOneResolve, type INostrProfileGetResolve, type INostrProfileRelayRelation, type INostrProfileRelayRelationResolve, type INostrProfileRelayRelationResolveGetAll, type INostrProfileUpdate, type INostrProfileUpdateResolve, type INostrRelayAdd, type INostrRelayAddResolve, type INostrRelayDelete, type INostrRelayDeleteResolve, type INostrRelayGet, type INostrRelayGetOne, type INostrRelayGetOneResolve, type INostrRelayGetResolve, type INostrRelayUpdate, type INostrRelayUpdateResolve, type ITradeProductAdd, type ITradeProductAddResolve, type ITradeProductDelete, type ITradeProductDeleteResolve, type ITradeProductGet, type ITradeProductGetOne, type ITradeProductGetOneResolve, type ITradeProductGetResolve, type ITradeProductLocationRelation, type ITradeProductLocationRelationResolve, type ITradeProductLocationRelationResolveGetAll, type ITradeProductMediaRelation, type ITradeProductMediaRelationResolve, type ITradeProductMediaRelationResolveGetAll, type ITradeProductUpdate, type ITradeProductUpdateResolve, type LocationGcsFields, type LocationGcsFormFields, type LogErrorFields, type LogErrorFormFields, type MediaUploadFields, type MediaUploadFormFields, type NostrProfileFields, type NostrProfileFormFields, type NostrRelayFields, type NostrRelayFormFields, type TradeProductFields, type TradeProductFormFields } from "@radroots/models";
import { err_msg, type ErrorMessage } from "@radroots/utils";
import { invoke } from "@tauri-apps/api/core";
import type { IClientDatabase, IClientDatabaseMessage } from "./types";
@@ -482,6 +482,70 @@ export class TauriClientDatabase implements IClientDatabase {
return this.handle_errors("model_media_upload_update", opts, e);
};
}
+ private log_error_add_validate(fields: LogErrorFormFields): LogErrorFields | string[] {
+ const fields_r = Object.entries(fields).filter(([_, v]) => !!v).reduce((acc: Record<string, IModelsQueryValue>, i) => {
+ const [key, val] = parse_log_error_form_fields(i);
+ acc[key] = val;
+ return acc;
+ }, {});
+ const schema = LogErrorSchema;
+ const parsed_schema = schema.safeParse(fields_r);
+ if (!parsed_schema.success) return parsed_schema.error.issues.map(i => i.message);
+ else return {
+ ...parsed_schema.data
+ };
+ }
+
+ public async log_error_add(opts: ILogErrorAdd): Promise<ILogErrorAddResolve<IClientDatabaseMessage>> {
+ const err_s = this.log_error_add_validate(opts);
+ if (Array.isArray(err_s)) return { err_s };
+ const fields = this.filter_bind_value_fields(Object.entries(err_s));
+ if (!fields.length) return err_msg("*-fields");
+ try {
+ const response = await invoke<any>("model_log_error_add", { opts });
+ if ("id" in response && typeof response.id === "string") return { id: response.id };
+ else if (typeof response === "string") return err_msg(response);
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_log_error_add", opts, e);
+ };
+ }
+
+ public async log_error_get(opts: ILogErrorGet): Promise<ILogErrorGetResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_log_error_get", { opts: "list" in opts ? { list: { of: parse_log_error_get_composite_list(opts.list), sort: opts.sort } } : { on: opts } });
+ if (typeof response === "string") return err_msg(response);
+ else if ("results" in response && Array.isArray(response.results)) return { results: parse_log_error_list(response.results) };
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_log_error_get", opts, e);
+ };
+ }
+
+ public async log_error_get_one(opts: ILogErrorGetOne): Promise<ILogErrorGetOneResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_log_error_get", { opts: { on: opts } });
+ if (typeof response === "string") return err_msg(response);
+ else if ("results" in response && Array.isArray(response.results) && response.results.length === 1) {
+ const result = parse_log_error(response.results[0]);
+ if (result) return { result };
+ }
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_log_error_get", opts, e);
+ };
+ }
+
+ public async log_error_delete(opts: ILogErrorDelete): Promise<ILogErrorDeleteResolve<IClientDatabaseMessage>> {
+ try {
+ const response = await invoke<any>("model_log_error_delete", { opts });
+ if (response === null) return { pass: true };
+ else if (typeof response === "string") return err_msg(response);
+ return err_msg("*-result");
+ } catch (e) {
+ return this.handle_errors("model_log_error_delete", opts, e);
+ };
+ }
public async nostr_profile_relay_set(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolve<IClientDatabaseMessage>> {
try {
diff --git a/client/src/database/types.ts b/client/src/database/types.ts
@@ -1,4 +1,4 @@
-import type { ILocationGcsAdd, ILocationGcsAddResolve, ILocationGcsDelete, ILocationGcsDeleteResolve, ILocationGcsGet, ILocationGcsGetResolve, ILocationGcsUpdate, ILocationGcsUpdateResolve, IMediaUploadAdd, IMediaUploadAddResolve, IMediaUploadDelete, IMediaUploadDeleteResolve, IMediaUploadGet, IMediaUploadGetResolve, IMediaUploadUpdate, IMediaUploadUpdateResolve, INostrProfileAdd, INostrProfileAddResolve, INostrProfileDelete, INostrProfileDeleteResolve, INostrProfileGet, INostrProfileGetResolve, INostrProfileRelayRelation, INostrProfileRelayRelationResolve, INostrProfileRelayRelationResolveGetAll, INostrProfileUpdate, INostrProfileUpdateResolve, INostrRelayAdd, INostrRelayAddResolve, INostrRelayDelete, INostrRelayDeleteResolve, INostrRelayGet, INostrRelayGetResolve, INostrRelayUpdate, INostrRelayUpdateResolve, ITradeProductAdd, ITradeProductAddResolve, ITradeProductDelete, ITradeProductDeleteResolve, ITradeProductGet, ITradeProductGetResolve, ITradeProductLocationRelation, ITradeProductLocationRelationResolve, ITradeProductLocationRelationResolveGetAll, ITradeProductMediaRelation, ITradeProductMediaRelationResolve, ITradeProductMediaRelationResolveGetAll, ITradeProductUpdate, ITradeProductUpdateResolve } from "@radroots/models";
+import type { ILocationGcsAdd, ILocationGcsAddResolve, ILocationGcsDelete, ILocationGcsDeleteResolve, ILocationGcsGet, ILocationGcsGetResolve, ILocationGcsUpdate, ILocationGcsUpdateResolve, ILogErrorAdd, ILogErrorAddResolve, ILogErrorDelete, ILogErrorDeleteResolve, ILogErrorGet, ILogErrorGetResolve, IMediaUploadAdd, IMediaUploadAddResolve, IMediaUploadDelete, IMediaUploadDeleteResolve, IMediaUploadGet, IMediaUploadGetResolve, IMediaUploadUpdate, IMediaUploadUpdateResolve, INostrProfileAdd, INostrProfileAddResolve, INostrProfileDelete, INostrProfileDeleteResolve, INostrProfileGet, INostrProfileGetResolve, INostrProfileRelayRelation, INostrProfileRelayRelationResolve, INostrProfileRelayRelationResolveGetAll, INostrProfileUpdate, INostrProfileUpdateResolve, INostrRelayAdd, INostrRelayAddResolve, INostrRelayDelete, INostrRelayDeleteResolve, INostrRelayGet, INostrRelayGetResolve, INostrRelayUpdate, INostrRelayUpdateResolve, ITradeProductAdd, ITradeProductAddResolve, ITradeProductDelete, ITradeProductDeleteResolve, ITradeProductGet, ITradeProductGetResolve, ITradeProductLocationRelation, ITradeProductLocationRelationResolve, ITradeProductLocationRelationResolveGetAll, ITradeProductMediaRelation, ITradeProductMediaRelationResolve, ITradeProductMediaRelationResolveGetAll, ITradeProductUpdate, ITradeProductUpdateResolve } from "@radroots/models";
export type IClientDatabaseMessage =
| string
@@ -26,6 +26,9 @@ export type IClientDatabase = {
media_upload_get(opts: IMediaUploadGet): Promise<IMediaUploadGetResolve<IClientDatabaseMessage>>;
media_upload_delete(opts: IMediaUploadDelete): Promise<IMediaUploadDeleteResolve<IClientDatabaseMessage>>;
media_upload_update(opts: IMediaUploadUpdate): Promise<IMediaUploadUpdateResolve<IClientDatabaseMessage>>;
+ log_error_add(opts: ILogErrorAdd): Promise<ILogErrorAddResolve<IClientDatabaseMessage>>;
+ log_error_get(opts: ILogErrorGet): Promise<ILogErrorGetResolve<IClientDatabaseMessage>>;
+ log_error_delete(opts: ILogErrorDelete): Promise<ILogErrorDeleteResolve<IClientDatabaseMessage>>;
nostr_profile_relay_set(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolve<IClientDatabaseMessage>>;
nostr_profile_relay_unset(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolve<IClientDatabaseMessage>>;
nostr_profile_relay_get_all(opts: INostrProfileRelayRelation): Promise<INostrProfileRelayRelationResolveGetAll<IClientDatabaseMessage>>;
diff --git a/client/src/dialog/tauri.ts b/client/src/dialog/tauri.ts
@@ -2,9 +2,9 @@ import { confirm, type ConfirmDialogOptions, message, open, type OpenDialogOptio
import type { IClientDialog, IClientDialogConfirmOpts, IClientDialogKind, IClientDialogResolve } from "./types";
export class TauriClientDialog implements IClientDialog {
- public async alert(msg: string, title?: string, kind?: IClientDialogKind): Promise<boolean> {
+ public async alert(opts: string, title?: string, kind?: IClientDialogKind): Promise<boolean> {
try {
- await message(msg, { title: title || ``, kind: kind || `info` });
+ await message(opts, { title: title || ``, kind: kind || `info` });
return true;
} catch (e) {
return false;
diff --git a/client/src/dialog/types.ts b/client/src/dialog/types.ts
@@ -11,12 +11,14 @@ export type IClientDialogPrompt = {
export type IClientDialogKind = "info" | "warning" | "error";
+export type IClientDialogAlertOpts = string;
+
export type IClientDialogConfirmOpts = string | { title?: string, kind?: IClientDialogKind; message: string; cancel_label?: string; ok_label?: string; };
export type IClientDialogResolve = ResultsList<string>;
export type IClientDialog = {
- alert(message: string): Promise<boolean>;
+ alert(opts: IClientDialogAlertOpts): Promise<boolean>;
confirm(opts: IClientDialogConfirmOpts): Promise<boolean>;
open_photos(): Promise<IClientDialogResolve | undefined>;
//prompt(opts: IClientDialogPrompt): Promise<string | false>;
diff --git a/client/src/geolocation/types.ts b/client/src/geolocation/types.ts
@@ -9,9 +9,9 @@ export type IGeolocationErrorMessage = `*-permissions` | `*`;
export type IClientGeolocationPosition = {
lat: number;
lng: number;
- accuracy: number | undefined;
- altitude: number | undefined;
- altitude_accuracy: number | undefined;
+ accuracy?: number;
+ altitude?: number;
+ altitude_accuracy?: number;
};
export type IClientGeolocationWatchOpts = {
diff --git a/client/src/nostr/lib.ts b/client/src/nostr/lib.ts
@@ -119,12 +119,19 @@ export class ClientNostrLib implements IClientNostrLib {
/**
*
+ * @returns
+ */
+ public nevent(event_pointer: nip19.EventPointer, relays: string[]): string {
+ return nip19.neventEncode(event_pointer)
+ }
+
+ /**
+ *
* @returns nostr public key nprofile
*/
public nprofile(public_key_hex: string, relays: string[]): string {
if (!public_key_hex || !relays.length) return ``;
- const nprofile = nip19.nprofileEncode({ pubkey: public_key_hex, relays })
- return nprofile;
+ return nip19.nprofileEncode({ pubkey: public_key_hex, relays })
}
/**
@@ -140,7 +147,7 @@ export class ClientNostrLib implements IClientNostrLib {
/**
*
- * @returns nostr public key nprofile
+ * @returns
*/
public secretkey_to_publickey(nsec_or_hex: string): string | undefined {
if (nsec_or_hex.startsWith(`nsec1`)) {