web_lib

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

commit 7a3cbf6e5272d8a97a2112528df0291bbd7f6ae2
parent cce98b74d5ca219d8109e024099316b8579655ed
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Sun,  1 Sep 2024 14:55:32 +0000

client: remove tab spacing

Diffstat:
Mclient/src/capacitor/sql.ts | 102++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/client/src/capacitor/sql.ts b/client/src/capacitor/sql.ts @@ -1,7 +1,7 @@ -import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection, type DBSQLiteValues, type capSQLiteChanges, type capSQLiteUpgradeOptions, type capSQLiteVersionUpgrade } from '@radroots/capacitor-sqlite'; 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, parse_nostr_note_form_field_types, nostr_note_sort, type INostrNoteGetList, type INostrNoteGet, type INostrNoteUpdate, type INostrNoteQueryBindValues, type INostrNoteQueryBindValuesKey, type INostrNoteQueryBindValuesTuple, parse_nostr_note, parse_nostr_notes, type NostrNote, type NostrNoteFields, type NostrNoteFormFields, NostrNoteSchema} from "@radroots/models"; +import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection, type DBSQLiteValues, type capSQLiteChanges, type capSQLiteUpgradeOptions, type capSQLiteVersionUpgrade } from '@radroots/capacitor-sqlite'; +import { LocationGcsSchema, NostrNoteSchema, 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_product_form_field_types, parse_trade_products, 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 ITradeProductGet, type ITradeProductGetList, type ITradeProductQueryBindValues, type ITradeProductQueryBindValuesTuple, type ITradeProductUpdate, type LocationGcs, type LocationGcsFields, type LocationGcsFormFields, type NostrNote, type NostrNoteFields, type NostrNoteFormFields, type TradeProduct, type TradeProductFields, type TradeProductFormFields } from "@radroots/models"; +import { err_msg, time_created_on, uuidv4 } from '@radroots/utils'; const models_upgrades = [ { @@ -20,13 +20,13 @@ export type IISQLiteServiceOpenDatabase = { version: number; }; -export type IISQLiteServiceMessage = - | "*-location-gcs-geohash-unique" - | "*-trade-product-key-unique" - | "*-trade-product-lot-unique" - | "*-trade-product-varietal-unique" - | "*-nostr-note-ev-id-unique" - | "*-validate" +export type IISQLiteServiceMessage = + | "*-location-gcs-geohash-unique" + | "*-trade-product-key-unique" + | "*-trade-product-lot-unique" + | "*-trade-product-varietal-unique" + | "*-nostr-note-ev-id-unique" + | "*-validate" | "*-result" | "*-fields" | "*-open" @@ -187,10 +187,10 @@ 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: nostr_note.ev_id")) return "*-nostr-note-ev-id-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: nostr_note.ev_id")) return "*-nostr-note-ev-id-unique"; return this.append_logs("*-exe", bv_o, query, error); }; }; @@ -245,7 +245,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)) { @@ -262,7 +262,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, }; }; @@ -271,9 +271,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); @@ -281,7 +281,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) { @@ -289,12 +289,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; @@ -308,7 +308,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); @@ -319,7 +319,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); @@ -334,7 +334,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;`; @@ -348,7 +348,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)); @@ -366,7 +366,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)) { @@ -383,7 +383,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, }; }; @@ -392,9 +392,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); @@ -402,7 +402,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) { @@ -410,12 +410,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; @@ -429,7 +429,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); @@ -440,7 +440,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); @@ -455,7 +455,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;`; @@ -469,7 +469,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)); @@ -487,7 +487,7 @@ export class CapacitorClientSQLite { }; }; - private nostr_note_add_validate(opts: NostrNoteFormFields): NostrNoteFields | string[] { + 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)) { @@ -504,7 +504,7 @@ export class CapacitorClientSQLite { 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, + ...nostr_note_v.data, }; }; @@ -513,9 +513,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); @@ -523,7 +523,7 @@ export class CapacitorClientSQLite { 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 }; + 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) { @@ -531,11 +531,11 @@ export class CapacitorClientSQLite { }; }; - private nostr_note_query_bind_values = (opts: INostrNoteQueryBindValues): INostrNoteQueryBindValuesTuple => { + private nostr_note_query_bind_values = (opts: INostrNoteQueryBindValues): INostrNoteQueryBindValuesTuple => { return ["id", opts.id]; }; - private nostr_note_get_query_list = (opts: INostrNoteGetList): IModelsQueryParam => { + private nostr_note_get_query_list = (opts: INostrNoteGetList): IModelsQueryParam => { const sort = nostr_note_sort[opts.sort || "newest"]; let query = ""; let bind_values = null; @@ -549,7 +549,7 @@ export class CapacitorClientSQLite { }; }; - private nostr_note_get_parse_opts = (opts: INostrNoteGet): IModelsQueryParam => { + 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); @@ -560,7 +560,7 @@ export class CapacitorClientSQLite { }; }; - public async nostr_note_get(opts: INostrNoteGet): Promise<NostrNote[] | IISQLiteServiceMessage> { + 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); @@ -575,7 +575,7 @@ export class CapacitorClientSQLite { }; }; - public async nostr_note_delete(opts: INostrNoteQueryBindValues): Promise<true | IISQLiteServiceMessage> { + 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;`; @@ -589,7 +589,7 @@ export class CapacitorClientSQLite { }; }; - public async nostr_note_update(opts: INostrNoteUpdate): Promise<true | string[] | IISQLiteServiceMessage> { + 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)); @@ -607,7 +607,7 @@ export class CapacitorClientSQLite { }; }; - 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 { @@ -639,7 +639,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];