diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/index.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/index.js index c4e79bfd6..d2bf43c94 100644 --- a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/index.js +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/index.js @@ -2,7 +2,7 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -import * as KeyValueStore from "./keyvaluestore.js"; +import * as Service from "./service.js"; export { - KeyValueStore + Service }; diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/keyvaluestore.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/keyvaluestore.js deleted file mode 100644 index 26d36cbb6..000000000 --- a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/keyvaluestore.js +++ /dev/null @@ -1,47 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore: Unused imports -import {Call as $Call, Create as $Create} from "/wails/runtime.js"; - -/** - * Delete deletes the key from the store. If AutoSave is true, the store is saved to disk. - * @param {string} key - * @returns {Promise & { cancel(): void }} - */ -export function Delete(key) { - let $resultPromise = /** @type {any} */($Call.ByID(1029952841, key)); - return $resultPromise; -} - -/** - * Get returns the value for the given key. If key is empty, the entire store is returned. - * @param {string} key - * @returns {Promise & { cancel(): void }} - */ -export function Get(key) { - let $resultPromise = /** @type {any} */($Call.ByID(3017738442, key)); - return $resultPromise; -} - -/** - * Save saves the store to disk - * @returns {Promise & { cancel(): void }} - */ -export function Save() { - let $resultPromise = /** @type {any} */($Call.ByID(840897339)); - return $resultPromise; -} - -/** - * Set sets the value for the given key. If AutoSave is true, the store is saved to disk. - * @param {string} key - * @param {any} value - * @returns {Promise & { cancel(): void }} - */ -export function Set(key, value) { - let $resultPromise = /** @type {any} */($Call.ByID(2329265830, key, value)); - return $resultPromise; -} diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/service.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/service.js new file mode 100644 index 000000000..b4285097c --- /dev/null +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/kvstore/service.js @@ -0,0 +1,69 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: Unused imports +import {Call as $Call, Create as $Create} from "/wails/runtime.js"; + +/** + * Clear deletes all keys from the store. If AutoSave is true, the store is saved to disk. + * @returns {Promise & { cancel(): void }} + */ +export function Clear() { + let $resultPromise = /** @type {any} */($Call.ByID(816318109)); + return $resultPromise; +} + +/** + * Delete deletes the given key from the store. If AutoSave is true, the store is saved to disk. + * @param {string} key + * @returns {Promise & { cancel(): void }} + */ +export function Delete(key) { + let $resultPromise = /** @type {any} */($Call.ByID(2889946731, key)); + return $resultPromise; +} + +/** + * Get returns the value for the given key. If key is empty, the entire store is returned. + * @param {string} key + * @returns {Promise & { cancel(): void }} + */ +export function Get(key) { + let $resultPromise = /** @type {any} */($Call.ByID(376909388, key)); + return $resultPromise; +} + +/** + * Load loads the store from disk. + * If the store is in-memory, i.e. not associated with a file, Load has no effect. + * If the operation fails, a non-nil error is returned + * and the store's content and state at call time are preserved. + * @returns {Promise & { cancel(): void }} + */ +export function Load() { + let $resultPromise = /** @type {any} */($Call.ByID(1850778156)); + return $resultPromise; +} + +/** + * Save saves the store to disk. + * If the store is in-memory, i.e. not associated with a file, Save has no effect. + * @returns {Promise & { cancel(): void }} + */ +export function Save() { + let $resultPromise = /** @type {any} */($Call.ByID(3572737965)); + return $resultPromise; +} + +/** + * Set sets the value for the given key. If AutoSave is true, the store is saved to disk. + * @param {string} key + * @param {any} value + * @returns {Promise & { cancel(): void }} + */ +export function Set(key, value) { + let $resultPromise = /** @type {any} */($Call.ByID(2491766752, key, value)); + return $resultPromise; +} diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/index.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/index.js index d3c050f93..564a31eeb 100644 --- a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/index.js +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/index.js @@ -2,7 +2,11 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -import * as LoggerService from "./loggerservice.js"; +import * as Service from "./service.js"; export { - LoggerService + Service }; + +export { + Level +} from "./models.js"; diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/loggerservice.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/loggerservice.js deleted file mode 100644 index 0ee366a67..000000000 --- a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/loggerservice.js +++ /dev/null @@ -1,60 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore: Unused imports -import {Call as $Call, Create as $Create} from "/wails/runtime.js"; - -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore: Unused imports -import * as slog$0 from "../../../../../../../log/slog/models.js"; - -/** - * @param {string} message - * @param {any[]} args - * @returns {Promise & { cancel(): void }} - */ -export function Debug(message, ...args) { - let $resultPromise = /** @type {any} */($Call.ByID(1384012895, message, args)); - return $resultPromise; -} - -/** - * @param {string} message - * @param {any[]} args - * @returns {Promise & { cancel(): void }} - */ -export function Error(message, ...args) { - let $resultPromise = /** @type {any} */($Call.ByID(1324251502, message, args)); - return $resultPromise; -} - -/** - * @param {string} message - * @param {any[]} args - * @returns {Promise & { cancel(): void }} - */ -export function Info(message, ...args) { - let $resultPromise = /** @type {any} */($Call.ByID(3712350036, message, args)); - return $resultPromise; -} - -/** - * @param {slog$0.Level} level - * @returns {Promise & { cancel(): void }} - */ -export function SetLogLevel(level) { - let $resultPromise = /** @type {any} */($Call.ByID(2521579448, level)); - return $resultPromise; -} - -/** - * @param {string} message - * @param {any[]} args - * @returns {Promise & { cancel(): void }} - */ -export function Warning(message, ...args) { - let $resultPromise = /** @type {any} */($Call.ByID(2902024404, message, args)); - return $resultPromise; -} diff --git a/v3/examples/services/assets/bindings/log/slog/models.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/models.js similarity index 62% rename from v3/examples/services/assets/bindings/log/slog/models.js rename to v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/models.js index ec976569d..d8579b51a 100644 --- a/v3/examples/services/assets/bindings/log/slog/models.js +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/models.js @@ -9,5 +9,18 @@ import {Create as $Create} from "/wails/runtime.js"; /** * A Level is the importance or severity of a log event. * The higher the level, the more important or severe the event. - * @typedef {any} Level + * + * Values are arbitrary, but there are four predefined ones. + * @typedef {number} Level */ + +/** + * Predefined constants for type Level. + * @namespace + */ +export const Level = { + Debug: -4, + Info: 0, + Warning: 4, + Error: 8, +}; diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/service.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/service.js new file mode 100644 index 000000000..e5128d9bc --- /dev/null +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/log/service.js @@ -0,0 +1,106 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: Unused imports +import {Call as $Call, Create as $Create} from "/wails/runtime.js"; + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: Unused imports +import * as $models from "./models.js"; + +/** + * DebugContext logs at level [Debug]. + * @param {string} message + * @param {any[]} args + * @returns {Promise & { cancel(): void }} + */ +function DebugContext(message, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(1481024990, message, args)); + return $resultPromise; +} + +/** + * ErrorContext logs at level [Error]. + * @param {string} message + * @param {any[]} args + * @returns {Promise & { cancel(): void }} + */ +function ErrorContext(message, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(4028761057, message, args)); + return $resultPromise; +} + +/** + * InfoContext logs at level [Info]. + * @param {string} message + * @param {any[]} args + * @returns {Promise & { cancel(): void }} + */ +function InfoContext(message, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(1400061359, message, args)); + return $resultPromise; +} + +/** + * Log emits a log record with the current time and the given level and message. + * The Record's attributes consist of the Logger's attributes followed by + * the attributes specified by args. + * + * The attribute arguments are processed as follows: + * - If an argument is a string and this is not the last argument, + * the following argument is treated as the value and the two are combined + * into an attribute. + * - Otherwise, the argument is treated as a value with key "!BADKEY". + * + * Log feeds the binding call context into the configured logger, + * so custom handlers may access context values, e.g. the current window. + * @param {$models.Level} level + * @param {string} message + * @param {any[]} args + * @returns {Promise & { cancel(): void }} + */ +export function Log(level, message, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(4156699346, level, message, args)); + return $resultPromise; +} + +/** + * LogLevel returns the currently configured log level, + * that is either the one configured initially + * or the last value passed to [Service.SetLogLevel]. + * @returns {Promise<$models.Level> & { cancel(): void }} + */ +export function LogLevel() { + let $resultPromise = /** @type {any} */($Call.ByID(4058368160)); + return $resultPromise; +} + +/** + * SetLogLevel changes the current log level. + * @param {$models.Level} level + * @returns {Promise & { cancel(): void }} + */ +export function SetLogLevel(level) { + let $resultPromise = /** @type {any} */($Call.ByID(3988219088, level)); + return $resultPromise; +} + +/** + * WarningContext logs at level [Warn]. + * @param {string} message + * @param {any[]} args + * @returns {Promise & { cancel(): void }} + */ +function WarningContext(message, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(52282975, message, args)); + return $resultPromise; +} + +export { + DebugContext as Debug, + InfoContext as Info, + WarningContext as Warning, + ErrorContext as Error, +}; diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/index.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/index.js index d2bf43c94..0918a51f0 100644 --- a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/index.js +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/index.js @@ -6,3 +6,17 @@ import * as Service from "./service.js"; export { Service }; + +import * as $models from "./models.js"; + +/** + * Row holds a single row in the result of a query. + * It is a key-value map where keys are column names. + * @typedef {$models.Row} Row + */ + +/** + * Rows holds the result of a query + * as an array of key-value maps where keys are column names. + * @typedef {$models.Rows} Rows + */ diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/models.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/models.js new file mode 100644 index 000000000..041151c86 --- /dev/null +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/models.js @@ -0,0 +1,25 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: Unused imports +import {Create as $Create} from "/wails/runtime.js"; + +/** + * Row holds a single row in the result of a query. + * It is a key-value map where keys are column names. + * @typedef {{ [_: string]: any }} Row + */ + +/** + * Rows holds the result of a query + * as an array of key-value maps where keys are column names. + * @typedef {Row[]} Rows + */ + +/** + * Stmt wraps a prepared sql statement pointer. + * It provides the same methods as the [sql.Stmt] type. + * @typedef {string} Stmt + */ diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/service.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/service.js index ddbe76eb4..9330c1e4d 100644 --- a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/service.js +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/service.js @@ -6,8 +6,18 @@ // @ts-ignore: Unused imports import {Call as $Call, Create as $Create} from "/wails/runtime.js"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: Unused imports +import * as $models from "./models.js"; + /** - * @returns {Promise & { cancel(): void }} + * Close closes the current database connection if one is open, otherwise has no effect. + * Additionally, Close closes all open prepared statements associated to the connection. + * + * Even when a non-nil error is returned, + * the database service is left in a consistent state, + * ready for a call to [Service.Open]. + * @returns {Promise & { cancel(): void }} */ export function Close() { let $resultPromise = /** @type {any} */($Call.ByID(1888105376)); @@ -15,31 +25,104 @@ export function Close() { } /** + * ClosePrepared closes a prepared statement + * obtained with [Service.Prepare] or [Service.PrepareContext]. + * ClosePrepared is idempotent: + * it has no effect on prepared statements that are already closed. + * @param {$models.Stmt | null} stmt + * @returns {Promise & { cancel(): void }} + */ +function ClosePrepared(stmt) { + let $resultPromise = /** @type {any} */($Call.ByID(2526200629, stmt)); + return $resultPromise; +} + +/** + * ExecContext executes a query without returning any rows. + * It supports early cancellation. * @param {string} query * @param {any[]} args * @returns {Promise & { cancel(): void }} */ -export function Execute(query, ...args) { - let $resultPromise = /** @type {any} */($Call.ByID(3811930203, query, args)); +function ExecContext(query, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(674944556, query, args)); return $resultPromise; } /** - * @param {string} dbPath - * @returns {Promise & { cancel(): void }} + * ExecPrepared executes a prepared statement + * obtained with [Service.Prepare] or [Service.PrepareContext] + * without returning any rows. + * It supports early cancellation. + * @param {$models.Stmt | null} stmt + * @param {any[]} args + * @returns {Promise & { cancel(): void }} */ -export function Open(dbPath) { - let $resultPromise = /** @type {any} */($Call.ByID(2012175612, dbPath)); +function ExecPrepared(stmt, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(2086877656, stmt, args)); return $resultPromise; } /** + * Open validates the current configuration, + * closes the current connection if one is present, + * then opens and validates a new connection. + * + * Even when a non-nil error is returned, + * the database service is left in a consistent state, + * ready for a new call to Open. + * @returns {Promise & { cancel(): void }} + */ +export function Open() { + let $resultPromise = /** @type {any} */($Call.ByID(2012175612)); + return $resultPromise; +} + +/** + * PrepareContext creates a prepared statement for later queries or executions. + * Multiple queries or executions may be run concurrently from the returned statement. + * + * The caller must call the statement's Close method when it is no longer needed. + * Statements are closed automatically + * when the connection they are associated with is closed. + * + * PrepareContext supports early cancellation. + * @param {string} query + * @returns {Promise<$models.Stmt | null> & { cancel(): void }} + */ +function PrepareContext(query) { + let $resultPromise = /** @type {any} */($Call.ByID(570941694, query)); + return $resultPromise; +} + +/** + * QueryContext executes a query and returns a slice of key-value records, + * one per row, with column names as keys. + * It supports early cancellation, returning the slice of results fetched so far. * @param {string} query * @param {any[]} args - * @returns {Promise<{ [_: string]: any }[]> & { cancel(): void }} + * @returns {Promise<$models.Rows> & { cancel(): void }} */ -export function Select(query, ...args) { - let $resultPromise = /** @type {any} */($Call.ByID(2472933124, query, args)); +function QueryContext(query, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(4115542347, query, args)); + let $typingPromise = /** @type {any} */($resultPromise.then(($result) => { + return $$createType1($result); + })); + $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); + return $typingPromise; +} + +/** + * QueryPrepared executes a prepared statement + * obtained with [Service.Prepare] or [Service.PrepareContext] + * and returns a slice of key-value records, one per row, with column names as keys. + * It supports early cancellation, returning the slice of results fetched so far. + * @param {$models.Stmt | null} stmt + * @param {any[]} args + * @returns {Promise<$models.Rows> & { cancel(): void }} + */ +function QueryPrepared(stmt, ...args) { + let $resultPromise = /** @type {any} */($Call.ByID(3885083725, stmt, args)); let $typingPromise = /** @type {any} */($resultPromise.then(($result) => { return $$createType1($result); })); @@ -50,3 +133,35 @@ export function Select(query, ...args) { // Private type creation functions const $$createType0 = $Create.Map($Create.Any, $Create.Any); const $$createType1 = $Create.Array($$createType0); + +export { + ExecContext as Execute, + QueryContext as Query +}; + +import { Stmt } from "./stmt.js"; + +/** + * Prepare creates a prepared statement for later queries or executions. + * Multiple queries or executions may be run concurrently from the returned statement. + * + * The caller must call the statement's Close method when it is no longer needed. + * Statements are closed automatically + * when the connection they are associated with is closed. + * + * Prepare supports early cancellation. + * + * @param {string} query + * @returns {Promise & { cancel(): void }} + */ +export function Prepare(query) { + const promise = PrepareContext(query); + const wrapper = /** @type {any} */(promise.then(function (id) { + return id == null ? null : new Stmt( + ClosePrepared.bind(null, id), + ExecPrepared.bind(null, id), + QueryPrepared.bind(null, id)); + })); + wrapper.cancel = promise.cancel; + return wrapper; +} diff --git a/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/stmt.js b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/stmt.js new file mode 100644 index 000000000..948b0c3dd --- /dev/null +++ b/v3/examples/services/assets/bindings/github.com/wailsapp/wails/v3/pkg/services/sqlite/stmt.js @@ -0,0 +1,79 @@ +//@ts-check + +//@ts-ignore: Unused imports +import * as $models from "./models.js"; + +const execSymbol = Symbol("exec"), + querySymbol = Symbol("query"), + closeSymbol = Symbol("close"); + +/** + * Stmt represents a prepared statement for later queries or executions. + * Multiple queries or executions may be run concurrently on the same statement. + * + * The caller must call the statement's Close method when it is no longer needed. + * Statements are closed automatically + * when the connection they are associated with is closed. + */ +export class Stmt { + /** + * Constructs a new prepared statement instance. + * @param {(...args: any[]) => Promise} close + * @param {(...args: any[]) => Promise & { cancel(): void }} exec + * @param {(...args: any[]) => Promise<$models.Rows> & { cancel(): void }} query + */ + constructor(close, exec, query) { + /** + * @member + * @private + * @type {typeof close} + */ + this[closeSymbol] = close; + + /** + * @member + * @private + * @type {typeof exec} + */ + this[execSymbol] = exec; + + /** + * @member + * @private + * @type {typeof query} + */ + this[querySymbol] = query; + } + + /** + * Closes the prepared statement. + * It has no effect when the statement is already closed. + * @returns {Promise} + */ + Close() { + return this[closeSymbol](); + } + + /** + * Executes the prepared statement without returning any rows. + * It supports early cancellation. + * + * @param {any[]} args + * @returns {Promise & { cancel(): void }} + */ + Exec(...args) { + return this[execSymbol](...args); + } + + /** + * Executes the prepared statement + * and returns a slice of key-value records, one per row, with column names as keys. + * It supports early cancellation, returning the array of results fetched so far. + * + * @param {any[]} args + * @returns {Promise<$models.Rows> & { cancel(): void }} + */ + Query(...args) { + return this[querySymbol](...args); + } +} diff --git a/v3/examples/services/assets/bindings/log/slog/index.js b/v3/examples/services/assets/bindings/log/slog/index.js deleted file mode 100644 index 45070abb0..000000000 --- a/v3/examples/services/assets/bindings/log/slog/index.js +++ /dev/null @@ -1,11 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -import * as $models from "./models.js"; - -/** - * A Level is the importance or severity of a log event. - * The higher the level, the more important or severe the event. - * @typedef {$models.Level} Level - */