@x-tech-laboratories/x-app 0.112.0 → 0.113.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/app/server.js +4 -1
- package/dist/caller.d.ts +5 -0
- package/dist/caller.js +11 -5
- package/dist/node_caller_scope.d.ts +2 -0
- package/dist/node_caller_scope.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
|
|
|
42
42
|
| `i18n` | Words in the reader's language: `create_translator` looks each key up in catalogs in turn, so a missing translation falls back to the next, with `{name}` placeholders filled; `merge_messages`; `best_locale`, the available locale that best fits the reader's preferred ones, an exact tag before the same language; `text_direction` for the `dir` attribute. |
|
|
43
43
|
| `sql` | `SqlDatabase`, the part of a synchronous SQLite connection the apps use, met by node:sqlite and by `web/sqlite_wasm`; `in_transaction`, and `migrate`, each step once in its own transaction, through `user_version` or, with an `owner` such as a feature or plugin, its own row in `schema_versions`. |
|
|
44
44
|
| `settings` | An app's settings feature: one synced `settings (key, value)` table of JSON values, the same table and first step (`settings_migration` under the owner `"settings"`) every app already ran. Each feature declares a `SettingSpec` per key (`default`, `user_only`, `local` for this device alone, `secret` for another service's key, or its own `hide` and `keep`), `settings_of` giving every key of a defaults table the same spec; `create_settings_store(tables, { app })` merges them, refusing a key declared twice, and gives the migration, the synced table entry with its `local_keys`, `defaults`, the `user_only` set, `is_user_only_call` for `page_only_calls` (a user-only write, an import holding one, an export with secrets), `is_device_only` for `register_sync_routes`, `value_of`, and `get_settings`, `set_setting`, `export_settings` and `import_settings` with their api specs. Secrets read as `hidden_secret` and are kept when it comes back; the settings file is the standard's `{ app, kind: "settings", version, exported_at, settings }`, an import ignoring unknown keys and those of one device. `read_setting`, `write_setting` and `read_stored_settings` reach rows directly. No `node:` or DOM imports. |
|
|
45
|
-
| `caller`
|
|
45
|
+
| `caller`, `node_caller_scope` | Who is making the call in hand: `as_caller("page" \| "program" \| "engine", work)` around a call, `current_caller()` read by a store, and `caller_of(request)` (a token is a program). With a `CallerScope` in use (`use_caller_scope`), the caller holds across the call's awaits; the base app's server and daemon use `node_caller_scope()`, Node's `AsyncLocalStorage`, and without one, as on a phone, it holds for the call's synchronous part. |
|
|
46
46
|
| `api_spec` | An app's calls described once for other programs: `ApiSpec` gives each method its words and a JSON Schema per argument, so a method without one fails to compile; `input_schema` takes the arguments as one object, `positional_args` puts named arguments back in the method's order from a spec or any `NamedParams`, `openapi_document` writes an OpenAPI 3.1 document with one POST per call, and `route_openapi_document` one for REST routes such as `server/mcp`'s `route_tools` serves, each under its own path and verb with its path, query and body arguments; `check_known_ids` refuses a call naming an id that does not exist, such as "no such track a1", before it acts, `unknown_ids` lists them, and `keep_known_ids` cuts a remembered list, such as picked columns, down to the ids that still exist. A spec marked `page_only: true` is a call only the user may make at the app's own page (a signed-in browser, or a desktop window through its daemon's socket), such as approving what an assistant proposed: `page_only_calls(api, { rule?, refusal? })` gives the `PageOnlyCalls` the other modules take (`is_page_only(method)` for the marks, `is_page_only_call(method, args)` adding the app's `rule(method, args)` such as a write to some settings, `is_page_only_request(method, body)` for arguments as a list or by name, unchecked so a call with wrong names is left to refuse them itself, and the `refusal` text, `default_page_only_refusal` unless set), and both OpenAPI documents mark such a call with `x-page-only: true` and a 403. |
|
|
47
47
|
| `filter`, `filter_sql` | Filters as one JSON tree of conditions under and, or and not, over fields the app lists in a catalogue (`define_catalogue`): a column, an SQL expression over the row, a related table matched when any of its rows matches, a set of values in a link table, kept as they are or once in a table of their own, or a `custom` field; tables and columns named as text or as the Drizzle schema's own objects. `compile_filter` makes one parameterised query for any `SqlDatabase` (`query_rows`), missing values last whichever way it sorts and ties broken by id so pages never shift, and a `random` sort key's whole-number `seed` giving the same shuffle each time, in SQL and in memory (`shuffle_position`); `compile_group_by` counts and sums each value of a field for panes; `evaluate` and `select_ids` check records in memory and `sort_records` sorts them, with exactly the same answers and order, which a property test holds them to; text, number, set and date operators, `top` and `bottom`, `in_last` in milliseconds, seconds or ISO dates, `in_filter` for a saved filter with `find_cycle`, the app's own `operators` such as full-text search, `regexp_matches` for the REGEXP a `regex` calls, and `FilterStack`, the removable chips a view shows. |
|
|
48
48
|
| `filter_query` | `parse_filter_query`: search text such as `artist:beatles rating:>3 year:1965..1970 -live played:<30d` read into one filter over the fields the app lists (text, set, number or date, each with the names users type), so one search box serves every field. A text field takes `:` for contains, `=` for exact, `a,b` for either and `/pattern/` (matched with case, as `regex` is); a set field finds its listed values whatever their case; numbers take `>`, `>=`, `<`, `<=` and `a..b` through the field's own `parse_number`, such as stars into a rating; dates take `<30d` and `>6m` (h, d, w, m, y) and whole years, months or days such as `2024-03`, in the field's clock. A leading `-` leaves a term out. Each term comes back with where it is, its filter and a label for a chip, and `without_term` takes one out of the text; anything not readable as a field's condition is searched as words through the app's own text filter, never an error. |
|
package/dist/app/server.js
CHANGED
|
@@ -12,7 +12,8 @@ import { openapi_document, positional_args } from "../api_spec.js";
|
|
|
12
12
|
import { keep_backing_up } from "../backups.js";
|
|
13
13
|
import { backup_method_names } from "../backups.js";
|
|
14
14
|
import { calls_under, register_accounts } from "../server/account_sign_in.js";
|
|
15
|
-
import { caller_of } from "../caller.js";
|
|
15
|
+
import { caller_of, use_caller_scope } from "../caller.js";
|
|
16
|
+
import { node_caller_scope } from "../node_caller_scope.js";
|
|
16
17
|
import { AccountStore, holds_accounts, move_accounts } from "../server/account_store.js";
|
|
17
18
|
import { register_call_table } from "../server/call_table.js";
|
|
18
19
|
import { read_server_config } from "../server/config.js";
|
|
@@ -26,6 +27,8 @@ import { register_web_folder } from "../server/web_folder.js";
|
|
|
26
27
|
import { file_sync_storage } from "../sync_file_storage.js";
|
|
27
28
|
import { create_sync_peer, sync_device_methods } from "../sync_peer.js";
|
|
28
29
|
import { declared_file_of, no_services, side_databases } from "./services.js";
|
|
30
|
+
// The server and the daemon run on Node, so a call's caller holds across its awaits.
|
|
31
|
+
use_caller_scope(node_caller_scope());
|
|
29
32
|
// The app's database as the server and the desktop daemon keep it: a file opened and brought up to date, backed up
|
|
30
33
|
// before its schema is upgraded, before another copy replaces it, and daily, and restored from a backup.
|
|
31
34
|
export function open_app_database(app, path, backups_folder) {
|
package/dist/caller.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export type Caller = "page" | "program" | "engine";
|
|
2
|
+
export interface CallerScope {
|
|
3
|
+
run<Result>(caller: Caller, work: () => Result): Result;
|
|
4
|
+
get(): Caller | undefined;
|
|
5
|
+
}
|
|
6
|
+
export declare function use_caller_scope(next: CallerScope | null): void;
|
|
2
7
|
export declare function as_caller<Result>(caller: Caller, work: () => Result): Result;
|
|
3
8
|
export declare function current_caller(): Caller;
|
|
4
9
|
export declare function caller_of(request: object): Caller;
|
package/dist/caller.js
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
// Who is making the call in hand: the user at the app's own page (a signed-in browser or the desktop window), the
|
|
2
|
-
// app's own assistant or background work acting on its own, or another program through a token or MCP.
|
|
3
|
-
//
|
|
2
|
+
// app's own assistant or background work acting on its own, or another program through a token or MCP. Where a caller
|
|
3
|
+
// scope is in use, as on a server or desktop daemon, it holds for the whole call, awaits included; elsewhere, such as a
|
|
4
|
+
// phone's page, for the call's synchronous part, which is where a store should read it.
|
|
4
5
|
let current = "page";
|
|
5
|
-
|
|
6
|
+
let scope = null;
|
|
7
|
+
// Uses the scope given from now on, or none again for null.
|
|
8
|
+
export function use_caller_scope(next) {
|
|
9
|
+
scope = next;
|
|
10
|
+
}
|
|
11
|
+
// Runs the work as the caller given; without a scope, the caller before comes back once its synchronous part ends.
|
|
6
12
|
export function as_caller(caller, work) {
|
|
7
13
|
const before = current;
|
|
8
14
|
current = caller;
|
|
9
15
|
try {
|
|
10
|
-
return work();
|
|
16
|
+
return scope ? scope.run(caller, work) : work();
|
|
11
17
|
}
|
|
12
18
|
finally {
|
|
13
19
|
current = before;
|
|
14
20
|
}
|
|
15
21
|
}
|
|
16
22
|
export function current_caller() {
|
|
17
|
-
return current;
|
|
23
|
+
return scope?.get() ?? current;
|
|
18
24
|
}
|
|
19
25
|
// The caller a server request is: a token is a program, a browser signed in itself or through a proxy is the user.
|
|
20
26
|
export function caller_of(request) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The caller scope on Node, so a call's caller holds across its awaits on a server or a desktop daemon.
|
|
2
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
// ── Scope ────────────────────────────────────────────────────────────────────
|
|
5
|
+
export function node_caller_scope() {
|
|
6
|
+
const storage = new AsyncLocalStorage();
|
|
7
|
+
return { run: (caller, work) => storage.run(caller, work), get: () => storage.getStore() };
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.113.0",
|
|
4
4
|
"description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|