@simetrajs/designer 0.2.0 → 0.3.0-next.10

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.
@@ -37,8 +37,9 @@ Only commands write a table of a kind: write a change of its rows as a
37
37
  command of the object or its TypeScript hook. No application SQL, in any
38
38
  file and in debt too, writes one: an `INSERT`, `UPDATE`, `DELETE` or `MERGE`
39
39
  in a function or procedure body whose target is a table of a kind, a tabular
40
- section, a view of the model over one, or the provider's account table
41
- (`auth.users`) is `sql.kind-table-verbatim` with the form `functionBody`, also
40
+ section, a view of the model over one, the provider's account table
41
+ (`auth.users`) or any relation of the platform schema `simetra` is
42
+ `sql.kind-table-verbatim` with the form `functionBody`, also
42
43
  inside a literal `EXECUTE`, a `DO` block or a function the body creates.
43
44
  Reading the table (`SELECT`, `FOR UPDATE`, `UPDATE … FROM`, `MERGE … USING`)
44
45
  and `LOCK` are fine. An unqualified table name counts in every schema,
@@ -52,8 +53,11 @@ the statements the hint of `sql.function-body-statement` lists; the field
52
53
  `statement` names the one refused. A body never changes the schema: move DDL
53
54
  into metadata or a migration.
54
55
 
55
- - `nonLiteralExecute`, `dynamicText` (a call of a builtin or provider
56
- function that executes SQL text, such as `query_to_xml` or `dblink`) and
56
+ - `nonLiteralExecute`, `dynamicText` (a call of a builtin that executes SQL
57
+ text, such as `query_to_xml`, or of any function of a provider schema that
58
+ is not on the provider's reviewed list, such as `dblink` or `cron.schedule`;
59
+ in a body without an empty `search_path`, also an unqualified call that is
60
+ neither a builtin nor a function of the model) and
57
61
  `language` (a language other than `sql` and `plpgsql`) cannot be judged:
58
62
  rewrite the function with static SQL or remove it. Partition maintenance or
59
63
  statistics through `EXECUTE format(…)` is refused on adoption for the same
@@ -62,6 +66,16 @@ into metadata or a migration.
62
66
  - A temporary table of the body is `CREATE TEMP TABLE … ON COMMIT DROP`, and
63
67
  every later reference to it (`DROP`, DML, a read) is `pg_temp.<name>`: an
64
68
  unqualified name could hit a table of the same name in your schema.
69
+ - A body leaves no session state behind its transaction: a pooled connection
70
+ serves the next command of another user. A setting is `SET LOCAL` or
71
+ `set_config(…, true)` with the literal `true`; `SET` without `LOCAL`,
72
+ `RESET` and any other `set_config` are `sql.function-body-session-setting`.
73
+ A temporary table named after a type of `pg_catalog` (`name`, `uuid`,
74
+ `text`…) is `sql.function-body-temp-type`: rename it. A session-level
75
+ advisory lock, `setseed`, `currval` or `lastval` is
76
+ `sql.function-body-session-builtin`: take `pg_advisory_xact_lock` instead of
77
+ the lock, and read the generated value from `INSERT … RETURNING` instead of
78
+ `currval` or `lastval`, which depend on the state of the session.
65
79
 
66
80
  Application SQL anywhere (a body, a view, a policy, a domain `CHECK`, a
67
81
  default) calls only the platform and generated functions that read, such as
@@ -91,17 +105,33 @@ model they call, by an allowlist (`sql.head-not-allowed`):
91
105
 
92
106
  - **A handler only checks.** It reads with `SELECT … INTO`, assigns fields of
93
107
  `NEW`, raises errors and returns `NEW` or `NULL`. It writes no table and runs
94
- no `EXECUTE`, `CALL`, `SET` or cursor. A `beforeWrite` handler on a provider
108
+ no `EXECUTE`, `CALL`, `SET`, cursor or `ASSERT` (a session setting can
109
+ switch `ASSERT` off: check with `IF … THEN RAISE`). A `beforeWrite` handler on a provider
95
110
  table (`auth.users`) does not assign `NEW` either. A write the handler did
96
111
  belongs to a command or a TypeScript hook.
97
112
  - **Everything else is a query function.** `LANGUAGE sql`, a string body of
98
113
  exactly one `SELECT` (no `INTO`, no `FOR UPDATE`, no data-modifying `WITH`),
99
- `SET search_path = ''` and no other `SET` option. It reads only qualified
114
+ `SET search_path = ''` and no other `SET` option except the pinned session
115
+ settings below. It reads only qualified
100
116
  tables of kinds, adopted tables and views of the model, and calls only query
101
117
  functions of the model, generated functions that read,
102
118
  `simetra.current_user_id()`, the listed provider functions and allowlisted
103
119
  builtins. A function of a kind module that is not of this form belongs in
104
120
  a shared `sql/` file, called by nothing inside a command.
121
+ - **A scope set function, an access dimension values function and a policy
122
+ function pin the session settings** the client could choose (time zone,
123
+ date, interval, number, money, `bytea` and XML styles, text search
124
+ configuration) with `SET` options of their `CREATE FUNCTION`; the hint of
125
+ `sql.head-settings` lists the exact options (`fix` does not add them). A
126
+ function they call sets none of these to another value.
127
+ - **A verbatim policy expression runs in the client's settings**, and so does
128
+ what it reads: a view and a function that does not pin the settings itself.
129
+ There `current_date`, `localtime` and a conversion to `date`, `time`,
130
+ `timetz` or `timestamp` without `now() AT TIME ZONE '<zone>'`, or to
131
+ `timestamptz` from a value without a zone, is `sql.head-not-allowed`
132
+ (`setting`, `TimeZone`).
133
+ - **A cast to a `reg*` type** names an object by text; only a string literal
134
+ cast to `regclass` (read as that relation) is allowed in a head.
105
135
 
106
136
  ## Reading `sql.head-not-allowed`
107
137
 
@@ -173,10 +203,11 @@ is closed by its own rule:
173
203
  your SQL, and its cascade would write tables of kinds. Promote the root, or
174
204
  delete tenants through a command.
175
205
  - **Extensions** — `CREATE EXTENSION … SCHEMA extensions` (a schema of the
176
- provider); without `SCHEMA` or with another schema it is the warning
177
- `sql.debt-extension-schema`. Until you fix it, code inside a command calls
178
- no function of the model in that schema, and none at all while an
179
- extension has no `SCHEMA`.
206
+ provider); without `SCHEMA` or with another schema it is the error
207
+ `sql.debt-extension-schema`. Fix it with `ALTER EXTENSION … SET SCHEMA
208
+ extensions` in the database and `SCHEMA extensions` in the statement:
209
+ Postgres picks an overload by argument types, so a name match with a model
210
+ function would not make a call safe.
180
211
 
181
212
  ## Before a promotion
182
213
 
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
- // src/schema-engine/errors.ts
3
- /**
4
- * Помилки адаптера, які межа підключення (`io/database.ts`) розпізнає за
5
- * класом. Окремий модуль без `pg` і pg-delta: межу імпортує кожен виклик
6
- * CLI, а двигун вантажиться лише інструментом бази.
7
- */
8
- /** Тінь на сервері іншої мажорної версії: каталоги двох версій не порівнюються. */
9
- var ShadowServerMismatchError = class extends Error {
10
- name = "ShadowServerMismatchError";
11
- };
12
- /** Роль підключення не має `CREATEDB` на сервері, де мала б з'явитися тінь. */
13
- var ShadowCreateRefusedError = class extends Error {
14
- onShadowBase;
15
- name = "ShadowCreateRefusedError";
16
- constructor(onShadowBase) {
17
- super("the connecting role lacks CREATEDB");
18
- this.onShadowBase = onShadowBase;
19
- }
20
- };
21
- /**
22
- * Збій створення тіні чи підключення до неї з причиною, якої адаптер не
23
- * розпізнав: причина — у `cause`. Межа описує її адресою сервера, де мала
24
- * з'явитися тінь, і називає вимогу тіні до режиму з'єднання (спека designer
25
- * §3.2).
26
- */
27
- var ShadowServerError = class extends Error {
28
- onShadowBase;
29
- name = "ShadowServerError";
30
- constructor(cause, onShadowBase) {
31
- super("the shadow could not be created or reached", { cause });
32
- this.onShadowBase = onShadowBase;
33
- }
34
- };
35
- export { ShadowServerError as n, ShadowServerMismatchError as r, ShadowCreateRefusedError as t };