web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit d5dc493074e49af891806088e54cef8c97c4b924
parent e625c0526fbbf71dbe7c9ea999017a1fb5e03f4f
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Fri, 13 Sep 2024 07:21:20 +0000

client: update iclient db `trade_product` model, edit iclientdialog

Diffstat:
Mclient/src/capacitor/dialog.ts | 17+++++++++++++----
Mclient/src/capacitor/sql.ts | 323++++++++-----------------------------------------------------------------------
Mclient/src/types.ts | 4+++-
3 files changed, 48 insertions(+), 296 deletions(-)

diff --git a/client/src/capacitor/dialog.ts b/client/src/capacitor/dialog.ts @@ -1,5 +1,5 @@ -import { Dialog } from "@capacitor/dialog"; -import type { IClientDialog, IClientDialogPrompt } from "../types"; +import { type ConfirmOptions, Dialog } from "@capacitor/dialog"; +import type { IClientDialog, IClientDialogConfirmOpts, IClientDialogPrompt } from "../types"; export class CapacitorClientDialog implements IClientDialog { public async alert(message: string): Promise<boolean> { @@ -11,9 +11,18 @@ export class CapacitorClientDialog implements IClientDialog { }; } - public async confirm(message: string): Promise<boolean> { + public async confirm(opts: IClientDialogConfirmOpts): Promise<boolean> { try { - const res = await Dialog.confirm({ message }); + const message = typeof opts === `string` ? opts : opts.message; + const options: ConfirmOptions = { + message + }; + + if (typeof opts !== `string`) { + if (opts.cancel_label) options.cancelButtonTitle = opts.cancel_label; + if (opts.ok_label) options.okButtonTitle = opts.ok_label; + } + const res = await Dialog.confirm(options); if (res && typeof res.value === `boolean`) return res.value; return false; } catch (e) { diff --git a/client/src/capacitor/sql.ts b/client/src/capacitor/sql.ts @@ -1,7 +1,7 @@ -import { Capacitor } from '@capacitor/core'; import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection, type DBSQLiteValues, type capSQLiteChanges, type capSQLiteUpgradeOptions, type capSQLiteVersionUpgrade } from '@radroots/capacitor-sqlite'; -import { LocationGcsSchema, NostrNoteSchema, TradeOfferSchema, TradeProductSchema, location_gcs_sort, models_initial_upgrade, nostr_note_sort, parse_location_gcs_form_field_types, parse_location_gcss, parse_nostr_note_form_field_types, parse_nostr_notes, parse_trade_offer_form_field_types, parse_trade_offers, parse_trade_product_form_field_types, parse_trade_products, trade_offer_sort, trade_product_sort, type ILocationGcsGet, type ILocationGcsGetList, type ILocationGcsQueryBindValues, type ILocationGcsQueryBindValuesTuple, type ILocationGcsUpdate, type IModelsQueryBindValueOpt, type IModelsQueryBindValueTuple, type IModelsQueryParam, type INostrNoteGet, type INostrNoteGetList, type INostrNoteQueryBindValues, type INostrNoteQueryBindValuesTuple, type INostrNoteUpdate, type ITradeOfferGet, type ITradeOfferGetList, type ITradeOfferQueryBindValues, type ITradeOfferQueryBindValuesTuple, type ITradeOfferUpdate, type ITradeProductGet, type ITradeProductGetList, type ITradeProductQueryBindValues, type ITradeProductQueryBindValuesTuple, type ITradeProductUpdate, type LocationGcs, type LocationGcsFields, type LocationGcsFormFields, type NostrNote, type NostrNoteFields, type NostrNoteFormFields, type TradeOffer, type TradeOfferFields, type TradeOfferFormFields, type TradeProduct, type TradeProductFields, type TradeProductFormFields } from "@radroots/models"; -import { err_msg, time_created_on, uuidv4 } from '@radroots/utils'; +import { Capacitor } from '@capacitor/core'; +import { time_created_on, uuidv4, err_msg } from '@radroots/utils'; +import { type IModelsQueryParam, type IModelsQueryBindValue, type IModelsQueryBindValueTuple, type IModelsQueryBindValueOpt, models_initial_upgrade, parse_location_gcs_form_field_types, location_gcs_sort, type ILocationGcsGetList, type ILocationGcsGet, type ILocationGcsUpdate, type ILocationGcsQueryBindValues, type ILocationGcsQueryBindValuesKey, type ILocationGcsQueryBindValuesTuple, parse_location_gcs, parse_location_gcss, type LocationGcs, type LocationGcsFields, type LocationGcsFormFields, LocationGcsSchema, parse_trade_product_form_field_types, trade_product_sort, type ITradeProductGetList, type ITradeProductGet, type ITradeProductUpdate, type ITradeProductQueryBindValues, type ITradeProductQueryBindValuesKey, type ITradeProductQueryBindValuesTuple, parse_trade_product, parse_trade_products, type TradeProduct, type TradeProductFields, type TradeProductFormFields, TradeProductSchema} from "@radroots/models"; const models_upgrades = [ { @@ -20,17 +20,9 @@ export type IISQLiteServiceOpenDatabase = { version: number; }; -export type IISQLiteServiceMessage = - | "*-location-gcs-geohash-unique" - | "*-trade-product-key-unique" - | "*-trade-product-lot-unique" - | "*-trade-product-varietal-unique" - | "*-trade-offer-quantity-amt-unique" - | "*-trade-offer-quantity-unit-unique" - | "*-trade-offer-price-amt-unique" - | "*-trade-offer-price-currency-unique" - | "*-nostr-note-ev-id-unique" - | "*-validate" +export type IISQLiteServiceMessage = + | "*-location-gcs-geohash-unique" + | "*-validate" | "*-result" | "*-fields" | "*-open" @@ -191,14 +183,6 @@ export class CapacitorClientSQLite { } catch (e) { const { error } = err_msg(e, "execute"); if (String(e).includes("UNIQUE constraint failed: location_gcs.geohash")) return "*-location-gcs-geohash-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_product.key")) return "*-trade-product-key-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_product.lot")) return "*-trade-product-lot-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_product.varietal")) return "*-trade-product-varietal-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_offer.quantity_amt")) return "*-trade-offer-quantity-amt-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_offer.quantity_unit")) return "*-trade-offer-quantity-unit-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_offer.price_amt")) return "*-trade-offer-price-amt-unique"; - else if (String(e).includes("UNIQUE constraint failed: trade_offer.price_currency")) return "*-trade-offer-price-currency-unique"; - else if (String(e).includes("UNIQUE constraint failed: nostr_note.ev_id")) return "*-nostr-note-ev-id-unique"; return this.append_logs("*-exe", bv_o, query, error); }; }; @@ -253,7 +237,7 @@ export class CapacitorClientSQLite { }; } - private location_gcs_add_validate(opts: LocationGcsFormFields): LocationGcsFields | string[] { + private location_gcs_add_validate(opts: LocationGcsFormFields): LocationGcsFields | string[] { const opts_filtered = Object.entries(opts).reduce((acc: Record<string, (string | number)>, [key, value]) => { if (!!value) { switch (parse_location_gcs_form_field_types(key)) { @@ -270,7 +254,7 @@ export class CapacitorClientSQLite { const location_gcs_v = LocationGcsSchema.safeParse(opts_filtered); if (!location_gcs_v.success) return location_gcs_v.error.issues.map(i => i.message); else return { - ...location_gcs_v.data, + ...location_gcs_v.data, }; }; @@ -279,9 +263,9 @@ export class CapacitorClientSQLite { if (Array.isArray(optsv)) return optsv; const fields = Object.entries(optsv); if (!fields.length) return "*-fields"; - const id = uuidv4(); + const id = uuidv4(); const bind_values_tup: IModelsQueryBindValueTuple[] = [ - ["id", id], + ["id", id], ["created_at", time_created_on()] ]; for (const field of this.filter_bind_value_fields(fields)) bind_values_tup.push(field); @@ -289,7 +273,7 @@ export class CapacitorClientSQLite { const query = `INSERT INTO location_gcs (${bind_values_tup.map(([k]) => k).join(", ")}) VALUES (${bind_values_tup.map((_, num) => `$${1 + num}`).join(", ")});`; try { const result = await this.execute(query, bind_values); - if (typeof result !== "string" && typeof result.changes?.changes === "number" && result.changes.changes > 0) return { id }; + if (typeof result !== "string" && typeof result.changes?.changes === "number" && result.changes.changes > 0) return { id }; else if (typeof result === "string") return result; return "*-result"; } catch (e) { @@ -297,12 +281,12 @@ export class CapacitorClientSQLite { }; }; - private location_gcs_query_bind_values = (opts: ILocationGcsQueryBindValues): ILocationGcsQueryBindValuesTuple => { + private location_gcs_query_bind_values = (opts: ILocationGcsQueryBindValues): ILocationGcsQueryBindValuesTuple => { if ("id" in opts) return ["id", opts.id]; - else return ["geohash", opts.geohash]; + else return ["geohash", opts.geohash]; }; - private location_gcs_get_query_list = (opts: ILocationGcsGetList): IModelsQueryParam => { + private location_gcs_get_query_list = (opts: ILocationGcsGetList): IModelsQueryParam => { const sort = location_gcs_sort[opts.sort || "newest"]; let query = ""; let bind_values = null; @@ -316,7 +300,7 @@ export class CapacitorClientSQLite { }; }; - private location_gcs_get_parse_opts = (opts: ILocationGcsGet): IModelsQueryParam => { + private location_gcs_get_parse_opts = (opts: ILocationGcsGet): IModelsQueryParam => { if ("list" in opts) return this.location_gcs_get_query_list(opts); else { const bv_tup = this.location_gcs_query_bind_values(opts); @@ -327,7 +311,7 @@ export class CapacitorClientSQLite { }; }; - public async location_gcs_get(opts: ILocationGcsGet): Promise<LocationGcs[] | IISQLiteServiceMessage> { + public async location_gcs_get(opts: ILocationGcsGet): Promise<LocationGcs[] | IISQLiteServiceMessage> { const { query, bind_values } = this.location_gcs_get_parse_opts(opts); try { const response = await this.select(query, bind_values); @@ -342,7 +326,7 @@ export class CapacitorClientSQLite { }; }; - public async location_gcs_delete(opts: ILocationGcsQueryBindValues): Promise<true | IISQLiteServiceMessage> { + public async location_gcs_delete(opts: ILocationGcsQueryBindValues): Promise<true | IISQLiteServiceMessage> { const bv_tup = this.location_gcs_query_bind_values(opts); const bind_values = [bv_tup[1]]; const query = `DELETE FROM location_gcs WHERE ${bv_tup[0]} = $1;`; @@ -356,7 +340,7 @@ export class CapacitorClientSQLite { }; }; - public async location_gcs_update(opts: ILocationGcsUpdate): Promise<true | string[] | IISQLiteServiceMessage> { + public async location_gcs_update(opts: ILocationGcsUpdate): Promise<true | string[] | IISQLiteServiceMessage> { const optsv = this.location_gcs_add_validate(opts.fields); if (Array.isArray(optsv)) return optsv; const fields = this.filter_bind_value_fields(Object.entries(optsv)); @@ -374,7 +358,7 @@ export class CapacitorClientSQLite { }; }; - private trade_product_add_validate(opts: TradeProductFormFields): TradeProductFields | string[] { + private trade_product_add_validate(opts: TradeProductFormFields): TradeProductFields | string[] { const opts_filtered = Object.entries(opts).reduce((acc: Record<string, (string | number)>, [key, value]) => { if (!!value) { switch (parse_trade_product_form_field_types(key)) { @@ -391,7 +375,7 @@ export class CapacitorClientSQLite { const trade_product_v = TradeProductSchema.safeParse(opts_filtered); if (!trade_product_v.success) return trade_product_v.error.issues.map(i => i.message); else return { - ...trade_product_v.data, + ...trade_product_v.data, }; }; @@ -400,9 +384,9 @@ export class CapacitorClientSQLite { if (Array.isArray(optsv)) return optsv; const fields = Object.entries(optsv); if (!fields.length) return "*-fields"; - const id = uuidv4(); + const id = uuidv4(); const bind_values_tup: IModelsQueryBindValueTuple[] = [ - ["id", id], + ["id", id], ["created_at", time_created_on()] ]; for (const field of this.filter_bind_value_fields(fields)) bind_values_tup.push(field); @@ -410,7 +394,7 @@ export class CapacitorClientSQLite { const query = `INSERT INTO trade_product (${bind_values_tup.map(([k]) => k).join(", ")}) VALUES (${bind_values_tup.map((_, num) => `$${1 + num}`).join(", ")});`; try { const result = await this.execute(query, bind_values); - if (typeof result !== "string" && typeof result.changes?.changes === "number" && result.changes.changes > 0) return { id }; + if (typeof result !== "string" && typeof result.changes?.changes === "number" && result.changes.changes > 0) return { id }; else if (typeof result === "string") return result; return "*-result"; } catch (e) { @@ -418,12 +402,12 @@ export class CapacitorClientSQLite { }; }; - private trade_product_query_bind_values = (opts: ITradeProductQueryBindValues): ITradeProductQueryBindValuesTuple => { + private trade_product_query_bind_values = (opts: ITradeProductQueryBindValues): ITradeProductQueryBindValuesTuple => { if ("id" in opts) return ["id", opts.id]; - else return ["url", opts.url]; + else return ["url", opts.url]; }; - private trade_product_get_query_list = (opts: ITradeProductGetList): IModelsQueryParam => { + private trade_product_get_query_list = (opts: ITradeProductGetList): IModelsQueryParam => { const sort = trade_product_sort[opts.sort || "newest"]; let query = ""; let bind_values = null; @@ -437,7 +421,7 @@ export class CapacitorClientSQLite { }; }; - private trade_product_get_parse_opts = (opts: ITradeProductGet): IModelsQueryParam => { + private trade_product_get_parse_opts = (opts: ITradeProductGet): IModelsQueryParam => { if ("list" in opts) return this.trade_product_get_query_list(opts); else { const bv_tup = this.trade_product_query_bind_values(opts); @@ -448,7 +432,7 @@ export class CapacitorClientSQLite { }; }; - public async trade_product_get(opts: ITradeProductGet): Promise<TradeProduct[] | IISQLiteServiceMessage> { + public async trade_product_get(opts: ITradeProductGet): Promise<TradeProduct[] | IISQLiteServiceMessage> { const { query, bind_values } = this.trade_product_get_parse_opts(opts); try { const response = await this.select(query, bind_values); @@ -463,7 +447,7 @@ export class CapacitorClientSQLite { }; }; - public async trade_product_delete(opts: ITradeProductQueryBindValues): Promise<true | IISQLiteServiceMessage> { + public async trade_product_delete(opts: ITradeProductQueryBindValues): Promise<true | IISQLiteServiceMessage> { const bv_tup = this.trade_product_query_bind_values(opts); const bind_values = [bv_tup[1]]; const query = `DELETE FROM trade_product WHERE ${bv_tup[0]} = $1;`; @@ -477,7 +461,7 @@ export class CapacitorClientSQLite { }; }; - public async trade_product_update(opts: ITradeProductUpdate): Promise<true | string[] | IISQLiteServiceMessage> { + public async trade_product_update(opts: ITradeProductUpdate): Promise<true | string[] | IISQLiteServiceMessage> { const optsv = this.trade_product_add_validate(opts.fields); if (Array.isArray(optsv)) return optsv; const fields = this.filter_bind_value_fields(Object.entries(optsv)); @@ -495,250 +479,7 @@ export class CapacitorClientSQLite { }; }; - private trade_offer_add_validate(opts: TradeOfferFormFields): TradeOfferFields | string[] { - const opts_filtered = Object.entries(opts).reduce((acc: Record<string, (string | number)>, [key, value]) => { - if (!!value) { - switch (parse_trade_offer_form_field_types(key)) { - case "string": - acc[key] = value; - break; - case "number": - acc[key] = Number(value); - break; - } - }; - return acc; - }, {}); - const trade_offer_v = TradeOfferSchema.safeParse(opts_filtered); - if (!trade_offer_v.success) return trade_offer_v.error.issues.map(i => i.message); - else return { - ...trade_offer_v.data, - }; - }; - - public async trade_offer_add(opts: TradeOfferFormFields): Promise<{ id: string; } | string[] | IISQLiteServiceMessage> { - const optsv = this.trade_offer_add_validate(opts); - if (Array.isArray(optsv)) return optsv; - const fields = Object.entries(optsv); - if (!fields.length) return "*-fields"; - const id = uuidv4(); - const bind_values_tup: IModelsQueryBindValueTuple[] = [ - ["id", id], - ["created_at", time_created_on()] - ]; - for (const field of this.filter_bind_value_fields(fields)) bind_values_tup.push(field); - const bind_values = bind_values_tup.map(([_, v]) => v); - const query = `INSERT INTO trade_offer (${bind_values_tup.map(([k]) => k).join(", ")}) VALUES (${bind_values_tup.map((_, num) => `$${1 + num}`).join(", ")});`; - try { - const result = await this.execute(query, bind_values); - if (typeof result !== "string" && typeof result.changes?.changes === "number" && result.changes.changes > 0) return { id }; - else if (typeof result === "string") return result; - return "*-result"; - } catch (e) { - return this.append_logs("*", bind_values, query, ["trade_offer_add", e]); - }; - }; - - private trade_offer_query_bind_values = (opts: ITradeOfferQueryBindValues): ITradeOfferQueryBindValuesTuple => { - return ["id", opts.id]; - }; - - private trade_offer_get_query_list = (opts: ITradeOfferGetList): IModelsQueryParam => { - const sort = trade_offer_sort[opts.sort || "newest"]; - let query = ""; - let bind_values = null; - if (opts.list[0] === "all") { - query = `SELECT * FROM trade_offer ORDER BY ${sort};`; - } else if (opts.list[0] === "unique") { - query = `SELECT * FROM trade_offer WHERE quantity_amt = $1 AND quantity_unit = $2 AND price_amt = $3 AND price_currency = $4;`; - bind_values = [opts.list[1].quantity_amt, opts.list[1].quantity_unit, opts.list[1].price_amt, opts.list[1].price_currency]; - } - if (!query) throw new Error("Error: Missing query (trade_offer_get_query_list)") - return { - query, - bind_values - }; - }; - - private trade_offer_get_parse_opts = (opts: ITradeOfferGet): IModelsQueryParam => { - if ("list" in opts) return this.trade_offer_get_query_list(opts); - else { - const bv_tup = this.trade_offer_query_bind_values(opts); - return { - query: `SELECT * FROM trade_offer WHERE ${bv_tup[0]} = $1;`, - bind_values: [bv_tup[1]] - }; - }; - }; - - public async trade_offer_get(opts: ITradeOfferGet): Promise<TradeOffer[] | IISQLiteServiceMessage> { - const { query, bind_values } = this.trade_offer_get_parse_opts(opts); - try { - const response = await this.select(query, bind_values); - if (typeof response === "string") return response; - else { - const result = parse_trade_offers(response); - if (result) return result; - } - return "*-result"; - } catch (e) { - return this.append_logs("*", opts, query, ["trade_offer_get", e]); - }; - }; - - public async trade_offer_delete(opts: ITradeOfferQueryBindValues): Promise<true | IISQLiteServiceMessage> { - const bv_tup = this.trade_offer_query_bind_values(opts); - const bind_values = [bv_tup[1]]; - const query = `DELETE FROM trade_offer WHERE ${bv_tup[0]} = $1;`; - try { - const response = await this.execute(query, bind_values); - if (typeof response === "string") return response; - else if (typeof response.changes?.changes === "number" && response.changes.changes > 0) return true; - return "*-result"; - } catch (e) { - return this.append_logs("*", [], query, ["trade_offer_delete", e]); - }; - }; - - public async trade_offer_update(opts: ITradeOfferUpdate): Promise<true | string[] | IISQLiteServiceMessage> { - const optsv = this.trade_offer_add_validate(opts.fields); - if (Array.isArray(optsv)) return optsv; - const fields = this.filter_bind_value_fields(Object.entries(optsv)); - if (!fields.length) return "*-fields"; - const bv_tup = this.trade_offer_query_bind_values(opts.on); - const bind_values = [bv_tup[1], ...fields.map(([_, v]) => v)]; - const query = `UPDATE trade_offer SET ${fields.map(([k], num) => `${k} = $${1 + num}`).join(", ")} WHERE ${bv_tup[0]} = $1;`; - try { - const response = await this.execute(query, bind_values); - if (typeof response === "string") return response; - else if (typeof response.changes?.changes === "number" && response.changes.changes > 0) return true; - return "*-result"; - } catch (e) { - return this.append_logs("*", [], query, ["trade_offer_update", e]); - }; - }; - - private nostr_note_add_validate(opts: NostrNoteFormFields): NostrNoteFields | string[] { - const opts_filtered = Object.entries(opts).reduce((acc: Record<string, (string | number)>, [key, value]) => { - if (!!value) { - switch (parse_nostr_note_form_field_types(key)) { - case "string": - acc[key] = value; - break; - case "number": - acc[key] = Number(value); - break; - } - }; - return acc; - }, {}); - const nostr_note_v = NostrNoteSchema.safeParse(opts_filtered); - if (!nostr_note_v.success) return nostr_note_v.error.issues.map(i => i.message); - else return { - ...nostr_note_v.data, - }; - }; - - public async nostr_note_add(opts: NostrNoteFormFields): Promise<{ id: string; } | string[] | IISQLiteServiceMessage> { - const optsv = this.nostr_note_add_validate(opts); - if (Array.isArray(optsv)) return optsv; - const fields = Object.entries(optsv); - if (!fields.length) return "*-fields"; - const id = uuidv4(); - const bind_values_tup: IModelsQueryBindValueTuple[] = [ - ["id", id], - ["created_at", time_created_on()] - ]; - for (const field of this.filter_bind_value_fields(fields)) bind_values_tup.push(field); - const bind_values = bind_values_tup.map(([_, v]) => v); - const query = `INSERT INTO nostr_note (${bind_values_tup.map(([k]) => k).join(", ")}) VALUES (${bind_values_tup.map((_, num) => `$${1 + num}`).join(", ")});`; - try { - const result = await this.execute(query, bind_values); - if (typeof result !== "string" && typeof result.changes?.changes === "number" && result.changes.changes > 0) return { id }; - else if (typeof result === "string") return result; - return "*-result"; - } catch (e) { - return this.append_logs("*", bind_values, query, ["nostr_note_add", e]); - }; - }; - - private nostr_note_query_bind_values = (opts: INostrNoteQueryBindValues): INostrNoteQueryBindValuesTuple => { - return ["id", opts.id]; - }; - - private nostr_note_get_query_list = (opts: INostrNoteGetList): IModelsQueryParam => { - const sort = nostr_note_sort[opts.sort || "newest"]; - let query = ""; - let bind_values = null; - if (opts.list[0] === "all") { - query = `SELECT * FROM nostr_note ORDER BY ${sort};`; - } - if (!query) throw new Error("Error: Missing query (nostr_note_get_query_list)") - return { - query, - bind_values - }; - }; - - private nostr_note_get_parse_opts = (opts: INostrNoteGet): IModelsQueryParam => { - if ("list" in opts) return this.nostr_note_get_query_list(opts); - else { - const bv_tup = this.nostr_note_query_bind_values(opts); - return { - query: `SELECT * FROM nostr_note WHERE ${bv_tup[0]} = $1;`, - bind_values: [bv_tup[1]] - }; - }; - }; - - public async nostr_note_get(opts: INostrNoteGet): Promise<NostrNote[] | IISQLiteServiceMessage> { - const { query, bind_values } = this.nostr_note_get_parse_opts(opts); - try { - const response = await this.select(query, bind_values); - if (typeof response === "string") return response; - else { - const result = parse_nostr_notes(response); - if (result) return result; - } - return "*-result"; - } catch (e) { - return this.append_logs("*", opts, query, ["nostr_note_get", e]); - }; - }; - - public async nostr_note_delete(opts: INostrNoteQueryBindValues): Promise<true | IISQLiteServiceMessage> { - const bv_tup = this.nostr_note_query_bind_values(opts); - const bind_values = [bv_tup[1]]; - const query = `DELETE FROM nostr_note WHERE ${bv_tup[0]} = $1;`; - try { - const response = await this.execute(query, bind_values); - if (typeof response === "string") return response; - else if (typeof response.changes?.changes === "number" && response.changes.changes > 0) return true; - return "*-result"; - } catch (e) { - return this.append_logs("*", [], query, ["nostr_note_delete", e]); - }; - }; - - public async nostr_note_update(opts: INostrNoteUpdate): Promise<true | string[] | IISQLiteServiceMessage> { - const optsv = this.nostr_note_add_validate(opts.fields); - if (Array.isArray(optsv)) return optsv; - const fields = this.filter_bind_value_fields(Object.entries(optsv)); - if (!fields.length) return "*-fields"; - const bv_tup = this.nostr_note_query_bind_values(opts.on); - const bind_values = [bv_tup[1], ...fields.map(([_, v]) => v)]; - const query = `UPDATE nostr_note SET ${fields.map(([k], num) => `${k} = $${1 + num}`).join(", ")} WHERE ${bv_tup[0]} = $1;`; - try { - const response = await this.execute(query, bind_values); - if (typeof response === "string") return response; - else if (typeof response.changes?.changes === "number" && response.changes.changes > 0) return true; - return "*-result"; - } catch (e) { - return this.append_logs("*", [], query, ["nostr_note_update", e]); - }; - }; - - public async get_trade_product_location(): Promise<any[] | IISQLiteServiceMessage> { + public async get_trade_product_location(): Promise<any[] | IISQLiteServiceMessage> { const bind_values = undefined; const query = "SELECT * FROM trade_product_location;"; try { @@ -770,7 +511,7 @@ export class CapacitorClientSQLite { const { error } = err_msg(e, "connect"); return this.append_logs("*", bind_values, query, ["set_trade_product_location", error]); }; - }; + }; public async unset_trade_product_location(opts: { trade_product_id: string; location_gcs_id: string; }): Promise<true | IISQLiteServiceMessage> { const bind_values = [opts.trade_product_id, opts.location_gcs_id]; diff --git a/client/src/types.ts b/client/src/types.ts @@ -115,9 +115,11 @@ export type IClientDialogPrompt = { input_text?: string; }; +export type IClientDialogConfirmOpts = string | { message: string; cancel_label?: string; ok_label?: string; }; + export type IClientDialog = { alert(message: string): Promise<boolean>; - confirm(message: string): Promise<boolean>; + confirm(opts: IClientDialogConfirmOpts): Promise<boolean>; prompt(opts: IClientDialogPrompt): Promise<string | false>; };