simetra 0.0.0-stage → 0.2.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.
@@ -0,0 +1,103 @@
1
+ import { CommandError, CommandResult, DatabaseProvider, ObjectModule, Operation, ProviderApiRoles, ReadQuery, RequestRolePurpose, RuntimeCatalog, SessionClaims } from "simetra/model";
2
+ /**
3
+ * One connection taken from a pool: bound text parameters only, unnamed
4
+ * statements (P4 spec Рт19).
5
+ */
6
+ interface DatabaseClient {
7
+ /** Column values are the Postgres text form (or `null`), whatever the pool parses. */
8
+ query(text: string, params?: readonly (string | null)[]): Promise<{
9
+ rows: Record<string, unknown>[];
10
+ command: string;
11
+ }>;
12
+ /** Returns the connection; `true` destroys it instead. */
13
+ release(destroy?: boolean): void;
14
+ }
15
+ /** The database port of the command runtime (P4 spec §6.4). */
16
+ interface CommandDatabase {
17
+ connect(): Promise<DatabaseClient>;
18
+ }
19
+ /**
20
+ * The shape of `pg.Pool` the runtime uses. Структурний тип замість імпорту
21
+ * `pg`: серверний ярус не тягне драйвер у свій бандл (Рт17), host передає
22
+ * будь-який пул з такою формою.
23
+ */
24
+ interface PgPoolLike {
25
+ connect(): Promise<{
26
+ query(config: {
27
+ text: string;
28
+ values: readonly (string | null)[];
29
+ types: typeof RAW_TYPES;
30
+ }): Promise<{
31
+ rows: Record<string, unknown>[];
32
+ command: string;
33
+ }>;
34
+ release(destroy?: boolean): void;
35
+ }>;
36
+ }
37
+ /**
38
+ * Парсери типів на рівні запиту: текст Postgres без перетворень. Інакше
39
+ * парсери, які host поставив на пул (`types` у `pg.Pool`), змінили б рядок
40
+ * ядра ще до `decodeRow` — і значення залежали б від налаштувань host-а.
41
+ */
42
+ declare const RAW_TYPES: {
43
+ getTypeParser: () => (value: string) => string;
44
+ };
45
+ /** Adapts a `pg` pool to the runtime port. */
46
+ export declare function fromPgPool(pool: PgPoolLike): CommandDatabase;
47
+ /**
48
+ * The rejection of `run` and `read`: `message` is the error code, no
49
+ * `cause` — текст Postgres не має виходити назовні навіть через ланцюжок
50
+ * причин (Р-A3-8).
51
+ */
52
+ export declare class CommandFailure extends Error {
53
+ readonly error: CommandError;
54
+ constructor(error: CommandError);
55
+ }
56
+ /** A runtime log entry: the full error stays inside the process. */
57
+ type LogEntry = {
58
+ kind: "afterCommit" | "hook" | "defer" | "database";
59
+ error: unknown;
60
+ };
61
+ /** Options of {@link createCommandRuntime}. */
62
+ interface CommandRuntimeOptions {
63
+ database: CommandDatabase;
64
+ /** The runtime catalog object (`runtime-catalog.json`); validated here. */
65
+ catalog: unknown;
66
+ /** Object modules keyed `"<kind>.<name>"`, e.g. `"Catalog.Client"`. */
67
+ objectModules?: Readonly<Record<string, ObjectModule<object>>>;
68
+ /** Hands `afterCommit` work to the platform (`waitUntil`); without it `run` awaits that work. */
69
+ defer?: (work: Promise<unknown>) => void;
70
+ /** Reads through the fallback path when the login role lacks the request role. */
71
+ readFallback?: boolean;
72
+ /** Attempts in total on serialization failure or deadlock; default 3. */
73
+ maxAttempts?: number;
74
+ /** Depth limit of phases started by hooks; default 8. */
75
+ maxDepth?: number;
76
+ /** Receives errors that never leave the runtime; default `console.error`. */
77
+ log?: (entry: LogEntry) => void;
78
+ }
79
+ /** The command runtime of one catalog and database. */
80
+ interface CommandRuntime {
81
+ /** Runs an operation or a batch in one transaction; rejects with `CommandFailure`. */
82
+ run(session: SessionClaims, input: Operation | readonly Operation[]): Promise<CommandResult>;
83
+ /**
84
+ * Reads rows under the request role of the profile, or through the
85
+ * fallback path (P4 spec §6.11); rejects with `CommandFailure`.
86
+ */
87
+ read(session: SessionClaims, query: ReadQuery): Promise<Record<string, unknown>[]>;
88
+ }
89
+ /**
90
+ * The request role the server reads under for a provider profile;
91
+ * `undefined` — the profile names none (P4 spec Рт18). Таблиці — параметри,
92
+ * щоб правило перевірялося на підставлених профілях.
93
+ */
94
+ export declare function readRoleOf(provider: DatabaseProvider, purposes?: Readonly<Record<DatabaseProvider, readonly RequestRolePurpose[]>>, roles?: Readonly<Record<DatabaseProvider, ProviderApiRoles>>): string | undefined;
95
+ /**
96
+ * Creates the command runtime (P4 spec §6.5): validates the catalog and the
97
+ * object modules, checks the applied snapshot hash and the request-role
98
+ * membership in one read-only transaction. Rejects with `CommandFailure`
99
+ * (`command.model-mismatch`, `command.read-role-missing`, …); an invalid
100
+ * catalog or module map throws before any database call.
101
+ */
102
+ export declare function createCommandRuntime(options: CommandRuntimeOptions): Promise<CommandRuntime>;
103
+ export type { CommandDatabase, CommandRuntime, CommandRuntimeOptions, DatabaseClient, LogEntry, PgPoolLike };