shutro 0.0.0-stage → 0.1.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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/dist/audit/index.d.ts +57 -0
  4. package/dist/audit/index.js +94 -0
  5. package/dist/cli/bin.d.ts +2 -0
  6. package/dist/cli/bin.js +11 -0
  7. package/dist/cli/cli.d.ts +10 -0
  8. package/dist/cli/cli.js +149 -0
  9. package/dist/cli/config.d.ts +18 -0
  10. package/dist/cli/config.js +47 -0
  11. package/dist/cli/errors.d.ts +16 -0
  12. package/dist/cli/errors.js +23 -0
  13. package/dist/cli/generate/generate.d.ts +33 -0
  14. package/dist/cli/generate/generate.js +82 -0
  15. package/dist/cli/generate/render.d.ts +23 -0
  16. package/dist/cli/generate/render.js +200 -0
  17. package/dist/cli/index.d.ts +12 -0
  18. package/dist/cli/index.js +12 -0
  19. package/dist/cli/init.d.ts +2 -0
  20. package/dist/cli/init.js +65 -0
  21. package/dist/cli/inspect.d.ts +10 -0
  22. package/dist/cli/inspect.js +82 -0
  23. package/dist/cli/packages.d.ts +6 -0
  24. package/dist/cli/packages.js +6 -0
  25. package/dist/cli/project.d.ts +18 -0
  26. package/dist/cli/project.js +39 -0
  27. package/dist/core/compute/graph.d.ts +52 -0
  28. package/dist/core/compute/graph.js +162 -0
  29. package/dist/core/env/env.d.ts +295 -0
  30. package/dist/core/env/env.js +631 -0
  31. package/dist/core/env/identity.d.ts +33 -0
  32. package/dist/core/env/identity.js +49 -0
  33. package/dist/core/env/inspector.d.ts +55 -0
  34. package/dist/core/env/inspector.js +85 -0
  35. package/dist/core/env/time.d.ts +12 -0
  36. package/dist/core/env/time.js +38 -0
  37. package/dist/core/errors.d.ts +242 -0
  38. package/dist/core/errors.js +339 -0
  39. package/dist/core/index.d.ts +43 -0
  40. package/dist/core/index.js +34 -0
  41. package/dist/core/model/company.d.ts +6 -0
  42. package/dist/core/model/company.js +31 -0
  43. package/dist/core/model/faces.d.ts +42 -0
  44. package/dist/core/model/faces.js +1 -0
  45. package/dist/core/model/field.d.ts +446 -0
  46. package/dist/core/model/field.js +398 -0
  47. package/dist/core/model/generated.d.ts +75 -0
  48. package/dist/core/model/generated.js +1 -0
  49. package/dist/core/model/id.d.ts +33 -0
  50. package/dist/core/model/id.js +4 -0
  51. package/dist/core/model/model.d.ts +347 -0
  52. package/dist/core/model/model.js +538 -0
  53. package/dist/core/model/partition.d.ts +31 -0
  54. package/dist/core/model/partition.js +71 -0
  55. package/dist/core/money/currency.d.ts +39 -0
  56. package/dist/core/money/currency.js +37 -0
  57. package/dist/core/money/decimal.d.ts +26 -0
  58. package/dist/core/money/decimal.js +51 -0
  59. package/dist/core/money/fx.d.ts +60 -0
  60. package/dist/core/money/fx.js +109 -0
  61. package/dist/core/money/money.d.ts +84 -0
  62. package/dist/core/money/money.js +173 -0
  63. package/dist/core/money/quantity.d.ts +67 -0
  64. package/dist/core/money/quantity.js +108 -0
  65. package/dist/core/money/rounding.d.ts +11 -0
  66. package/dist/core/money/rounding.js +12 -0
  67. package/dist/core/recordset/audit.d.ts +25 -0
  68. package/dist/core/recordset/audit.js +205 -0
  69. package/dist/core/recordset/compute.d.ts +34 -0
  70. package/dist/core/recordset/compute.js +405 -0
  71. package/dist/core/recordset/constraints.d.ts +9 -0
  72. package/dist/core/recordset/constraints.js +61 -0
  73. package/dist/core/recordset/domain.d.ts +27 -0
  74. package/dist/core/recordset/domain.js +228 -0
  75. package/dist/core/recordset/onchange.d.ts +43 -0
  76. package/dist/core/recordset/onchange.js +207 -0
  77. package/dist/core/recordset/recordset.d.ts +101 -0
  78. package/dist/core/recordset/recordset.js +723 -0
  79. package/dist/core/recordset/relations.d.ts +15 -0
  80. package/dist/core/recordset/relations.js +13 -0
  81. package/dist/core/recordset/rls.d.ts +15 -0
  82. package/dist/core/recordset/rls.js +108 -0
  83. package/dist/core/recordset/security.d.ts +42 -0
  84. package/dist/core/recordset/security.js +184 -0
  85. package/dist/core/recordset/sequences.d.ts +31 -0
  86. package/dist/core/recordset/sequences.js +154 -0
  87. package/dist/core/recordset/sqlErrors.d.ts +6 -0
  88. package/dist/core/recordset/sqlErrors.js +39 -0
  89. package/dist/core/recordset/transitions.d.ts +10 -0
  90. package/dist/core/recordset/transitions.js +77 -0
  91. package/dist/core/recordset/types.d.ts +296 -0
  92. package/dist/core/recordset/types.js +8 -0
  93. package/dist/core/recordset/values.d.ts +27 -0
  94. package/dist/core/recordset/values.js +147 -0
  95. package/dist/core/recordset/writes.d.ts +37 -0
  96. package/dist/core/recordset/writes.js +581 -0
  97. package/dist/core/registry/ddl.d.ts +22 -0
  98. package/dist/core/registry/ddl.js +127 -0
  99. package/dist/core/registry/extension.d.ts +94 -0
  100. package/dist/core/registry/extension.js +90 -0
  101. package/dist/core/registry/module.d.ts +80 -0
  102. package/dist/core/registry/module.js +96 -0
  103. package/dist/core/registry/registry.d.ts +105 -0
  104. package/dist/core/registry/registry.js +496 -0
  105. package/dist/driver-pg/driver.d.ts +86 -0
  106. package/dist/driver-pg/driver.js +176 -0
  107. package/dist/driver-pg/errors.d.ts +72 -0
  108. package/dist/driver-pg/errors.js +182 -0
  109. package/dist/driver-pg/index.d.ts +7 -0
  110. package/dist/driver-pg/index.js +7 -0
  111. package/dist/i18n/index.d.ts +25 -0
  112. package/dist/i18n/index.js +51 -0
  113. package/dist/migrate/apply.d.ts +78 -0
  114. package/dist/migrate/apply.js +167 -0
  115. package/dist/migrate/catalog.d.ts +10 -0
  116. package/dist/migrate/catalog.js +122 -0
  117. package/dist/migrate/diff.d.ts +98 -0
  118. package/dist/migrate/diff.js +160 -0
  119. package/dist/migrate/errors.d.ts +21 -0
  120. package/dist/migrate/errors.js +31 -0
  121. package/dist/migrate/index.d.ts +18 -0
  122. package/dist/migrate/index.js +18 -0
  123. package/dist/migrate/render.d.ts +5 -0
  124. package/dist/migrate/render.js +101 -0
  125. package/dist/migrate/schema.d.ts +61 -0
  126. package/dist/migrate/schema.js +195 -0
  127. package/dist/security/index.d.ts +123 -0
  128. package/dist/security/index.js +262 -0
  129. package/dist/sequence/index.d.ts +63 -0
  130. package/dist/sequence/index.js +106 -0
  131. package/dist/sql/ast.d.ts +49 -0
  132. package/dist/sql/ast.js +47 -0
  133. package/dist/sql/builder/builder.d.ts +215 -0
  134. package/dist/sql/builder/builder.js +308 -0
  135. package/dist/sql/builder/expression.d.ts +80 -0
  136. package/dist/sql/builder/expression.js +126 -0
  137. package/dist/sql/compile.d.ts +18 -0
  138. package/dist/sql/compile.js +41 -0
  139. package/dist/sql/errors.d.ts +13 -0
  140. package/dist/sql/errors.js +16 -0
  141. package/dist/sql/index.d.ts +19 -0
  142. package/dist/sql/index.js +19 -0
  143. package/dist/sql/tag.d.ts +42 -0
  144. package/dist/sql/tag.js +95 -0
  145. package/package.json +82 -4
@@ -0,0 +1,49 @@
1
+ import { InvalidIdentityError } from '../errors.js';
2
+ import { assertTimeZone } from './time.js';
3
+ const LANG = /^[a-z]{2,3}_[A-Z]{2}$/;
4
+ function assertId(value, what) {
5
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {
6
+ throw new InvalidIdentityError(`${what} must be a positive integer id, got ${JSON.stringify(value)}.`, 'Pass the database id of the record (a positive integer).');
7
+ }
8
+ return value;
9
+ }
10
+ /** Validates a language code (`'en_US'`, `'bn_BD'`). @throws {InvalidIdentityError} */
11
+ export function assertLang(lang) {
12
+ if (!LANG.test(lang)) {
13
+ throw new InvalidIdentityError(`${JSON.stringify(lang)} is not a language code.`, "Use the form 'll_CC', e.g. 'en_US' or 'bn_BD'.");
14
+ }
15
+ return lang;
16
+ }
17
+ /** Validates `reason` for superuser scopes and jobs. @throws {InvalidIdentityError} */
18
+ export function assertReason(reason) {
19
+ if (typeof reason !== 'string' || reason.trim() === '') {
20
+ throw new InvalidIdentityError('A reason is required.', "Say why elevated access or this job runs, e.g. { reason: 'payment-webhook: register payment' }; it is recorded in the audit trail.");
21
+ }
22
+ return reason;
23
+ }
24
+ /** Applies defaults and validates. @throws {InvalidIdentityError} */
25
+ export function resolveIdentity(identity) {
26
+ const uid = assertId(identity.user, 'user');
27
+ const companyId = assertId(identity.company, 'company');
28
+ const companyIds = identity.companies === undefined
29
+ ? [companyId]
30
+ : identity.companies.map((c) => assertId(c, 'companies[]'));
31
+ if (!companyIds.includes(companyId)) {
32
+ throw new InvalidIdentityError(`The current company ${companyId} is not in the allowed companies [${companyIds.join(', ')}].`, 'Include the current company in `companies`, or omit `companies` to allow only the current one.');
33
+ }
34
+ const tz = identity.tz ?? 'UTC';
35
+ assertTimeZone(tz);
36
+ return {
37
+ uid,
38
+ companyId,
39
+ companyIds: Object.freeze([...companyIds]),
40
+ lang: assertLang(identity.lang ?? 'en_US'),
41
+ tz,
42
+ reason: identity.reason === undefined ? undefined : assertReason(identity.reason),
43
+ groups: Object.freeze([...(identity.groups ?? [])].map((g) => {
44
+ if (typeof g !== 'string' || g === '')
45
+ throw new InvalidIdentityError(`${JSON.stringify(g)} is not a group code.`, "Pass group codes such as 'sale.user'.");
46
+ return g;
47
+ })),
48
+ };
49
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The dev-mode query inspector: records every statement a Shutro instance runs (SQL text, parameters, duration,
3
+ * transaction), flags slow statements, and warns about N+1 patterns — the same SQL text run many times inside one
4
+ * transaction attempt, which batched loads never do.
5
+ */
6
+ /** One statement the inspector saw. */
7
+ export interface InspectedQuery {
8
+ readonly sql: string;
9
+ readonly params: readonly unknown[];
10
+ readonly ms: number;
11
+ /** Groups the statements of one transaction attempt. */
12
+ readonly tx: string;
13
+ readonly uid: number;
14
+ /** Set when the statement failed. */
15
+ readonly error?: string;
16
+ }
17
+ /** A pattern the inspector warns about. */
18
+ export interface InspectorWarning {
19
+ readonly kind: 'n+1' | 'slow';
20
+ readonly sql: string;
21
+ readonly tx: string;
22
+ /** How many times the statement ran in the transaction (n+1), or its duration (slow). */
23
+ readonly count: number;
24
+ readonly message: string;
25
+ }
26
+ /** Options of {@link createInspector}. */
27
+ export interface InspectorOptions {
28
+ /** Same SQL text this many times in one transaction is an N+1 warning (default 10). */
29
+ readonly n1Threshold?: number;
30
+ /** Statements slower than this many milliseconds are reported (default 200). */
31
+ readonly slowMs?: number;
32
+ /** Keep at most this many statements (oldest dropped; default 5,000). */
33
+ readonly limit?: number;
34
+ /** Called once per warning as it happens (default: `process.emitWarning`). Pass `() => {}` to silence. */
35
+ readonly onWarning?: (warning: InspectorWarning) => void;
36
+ }
37
+ /** The inspector: pass it to `createShutro({ inspector })` in development. */
38
+ export interface Inspector {
39
+ readonly queries: readonly InspectedQuery[];
40
+ readonly warnings: readonly InspectorWarning[];
41
+ /** @internal Called by the environment around every statement. */
42
+ record(query: InspectedQuery): void;
43
+ /** Statements grouped by SQL text, most frequent first, with total and max duration. */
44
+ summary(): readonly {
45
+ readonly sql: string;
46
+ readonly count: number;
47
+ readonly totalMs: number;
48
+ readonly maxMs: number;
49
+ }[];
50
+ /** A plain-text report (`shutro inspect --queries` prints it). */
51
+ report(): string;
52
+ clear(): void;
53
+ }
54
+ /** Creates an inspector. Not for production: it keeps parameters in memory. */
55
+ export declare function createInspector(options?: InspectorOptions): Inspector;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The dev-mode query inspector: records every statement a Shutro instance runs (SQL text, parameters, duration,
3
+ * transaction), flags slow statements, and warns about N+1 patterns — the same SQL text run many times inside one
4
+ * transaction attempt, which batched loads never do.
5
+ */
6
+ /** Creates an inspector. Not for production: it keeps parameters in memory. */
7
+ export function createInspector(options = {}) {
8
+ const n1 = options.n1Threshold ?? 10;
9
+ const slow = options.slowMs ?? 200;
10
+ const limit = options.limit ?? 5_000;
11
+ const warn = options.onWarning ??
12
+ ((w) => process.emitWarning(w.message, { code: 'SHUTRO_INSPECTOR' }));
13
+ const queries = [];
14
+ const warnings = [];
15
+ const perTx = new Map();
16
+ const flagged = new Set();
17
+ const add = (w) => {
18
+ warnings.push(w);
19
+ warn(w);
20
+ };
21
+ return {
22
+ queries,
23
+ warnings,
24
+ record(query) {
25
+ queries.push(query);
26
+ if (queries.length > limit)
27
+ queries.splice(0, queries.length - limit);
28
+ let counts = perTx.get(query.tx);
29
+ if (counts === undefined) {
30
+ counts = new Map();
31
+ perTx.set(query.tx, counts);
32
+ if (perTx.size > 1_000)
33
+ perTx.delete(perTx.keys().next().value);
34
+ }
35
+ const count = (counts.get(query.sql) ?? 0) + 1;
36
+ counts.set(query.sql, count);
37
+ const key = `${query.tx}|${query.sql}`;
38
+ if (count >= n1 && !flagged.has(key)) {
39
+ flagged.add(key);
40
+ add({
41
+ kind: 'n+1',
42
+ sql: query.sql,
43
+ tx: query.tx,
44
+ count,
45
+ message: `Possible N+1: the same statement ran ${count} times in one transaction. Load the relation for the whole recordset (records.load({ ... })) instead of per record. SQL: ${query.sql.slice(0, 160)}`,
46
+ });
47
+ }
48
+ if (query.ms >= slow) {
49
+ add({
50
+ kind: 'slow',
51
+ sql: query.sql,
52
+ tx: query.tx,
53
+ count: Math.round(query.ms),
54
+ message: `Slow statement (${Math.round(query.ms)} ms ≥ ${slow} ms): ${query.sql.slice(0, 160)}`,
55
+ });
56
+ }
57
+ },
58
+ summary() {
59
+ const groups = new Map();
60
+ for (const q of queries) {
61
+ const g = groups.get(q.sql) ?? { sql: q.sql, count: 0, totalMs: 0, maxMs: 0 };
62
+ g.count++;
63
+ g.totalMs += q.ms;
64
+ g.maxMs = Math.max(g.maxMs, q.ms);
65
+ groups.set(q.sql, g);
66
+ }
67
+ return [...groups.values()].sort((a, b) => b.count - a.count || b.totalMs - a.totalMs);
68
+ },
69
+ report() {
70
+ const lines = [`${queries.length} statement(s), ${warnings.length} warning(s)`];
71
+ for (const g of this.summary().slice(0, 20)) {
72
+ lines.push(`${String(g.count).padStart(5)}× ${g.totalMs.toFixed(1).padStart(8)} ms max ${g.maxMs.toFixed(1)} ms ${g.sql.replace(/\s+/g, ' ').slice(0, 120)}`);
73
+ }
74
+ for (const w of warnings)
75
+ lines.push(`! ${w.kind}: ${w.message}`);
76
+ return lines.join('\n');
77
+ },
78
+ clear() {
79
+ queries.length = 0;
80
+ warnings.length = 0;
81
+ perTx.clear();
82
+ flagged.clear();
83
+ },
84
+ };
85
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Validates an IANA time zone name (`'Asia/Dhaka'`, `'UTC'`).
3
+ * @throws {InvalidIdentityError} when the runtime doesn't know the zone.
4
+ */
5
+ export declare function assertTimeZone(tz: string): void;
6
+ /**
7
+ * The calendar date (`'YYYY-MM-DD'`) of an instant in a time zone. Business dates always need an explicit zone
8
+ * (RFC 0003 §7.8): `2026-10-14T20:30Z` is already the 15th in Dhaka.
9
+ *
10
+ * @throws {InvalidIdentityError} for an unknown time zone.
11
+ */
12
+ export declare function calendarDateIn(instant: Date, tz: string): string;
@@ -0,0 +1,38 @@
1
+ import { InvalidIdentityError } from '../errors.js';
2
+ const formatters = new Map();
3
+ /**
4
+ * Validates an IANA time zone name (`'Asia/Dhaka'`, `'UTC'`).
5
+ * @throws {InvalidIdentityError} when the runtime doesn't know the zone.
6
+ */
7
+ export function assertTimeZone(tz) {
8
+ formatterFor(tz);
9
+ }
10
+ function formatterFor(tz) {
11
+ const cached = formatters.get(tz);
12
+ if (cached !== undefined)
13
+ return cached;
14
+ try {
15
+ const formatter = new Intl.DateTimeFormat('en-US', {
16
+ timeZone: tz,
17
+ year: 'numeric',
18
+ month: '2-digit',
19
+ day: '2-digit',
20
+ });
21
+ formatters.set(tz, formatter);
22
+ return formatter;
23
+ }
24
+ catch {
25
+ throw new InvalidIdentityError(`${JSON.stringify(tz)} is not a known IANA time zone.`, "Use a name such as 'Asia/Dhaka', 'Europe/Berlin' or 'UTC' (see the tz database).");
26
+ }
27
+ }
28
+ /**
29
+ * The calendar date (`'YYYY-MM-DD'`) of an instant in a time zone. Business dates always need an explicit zone
30
+ * (RFC 0003 §7.8): `2026-10-14T20:30Z` is already the 15th in Dhaka.
31
+ *
32
+ * @throws {InvalidIdentityError} for an unknown time zone.
33
+ */
34
+ export function calendarDateIn(instant, tz) {
35
+ const parts = formatterFor(tz).formatToParts(instant);
36
+ const get = (type) => parts.find((p) => p.type === type)?.value ?? '';
37
+ return `${get('year')}-${get('month')}-${get('day')}`;
38
+ }
@@ -0,0 +1,242 @@
1
+ /** Machine-readable reason for a {@link ShutroError}. */
2
+ export type ShutroErrorCode = 'NON_INTEGER_NUMBER' | 'INVALID_DECIMAL' | 'DIVISION_BY_ZERO' | 'INVALID_CURRENCY' | 'CURRENCY_MISMATCH' | 'INVALID_ALLOCATION' | 'MONEY_EMPTY_SUM' | 'INVALID_UOM' | 'UOM_MISMATCH' | 'UOM_CATEGORY_MISMATCH' | 'NO_ENVIRONMENT' | 'TRANSACTION_SCOPE' | 'CONCURRENT_UPDATE' | 'INVALID_IDENTITY' | 'COMPANY_NOT_ALLOWED' | 'FLAG_NOT_ALLOWED' | 'INVALID_FIELD' | 'INVALID_MODEL' | 'INVALID_MODULE' | 'DUPLICATE_MODULE' | 'DUPLICATE_MODEL' | 'UNDECLARED_DEPENDENCY' | 'UNKNOWN_MODEL' | 'INVALID_RELATION' | 'INVALID_DEPENDS_PATH' | 'FIELD_NOT_LOADED' | 'SINGLETON' | 'MISSING_RECORD' | 'INVALID_DOMAIN' | 'NO_REGISTRY' | 'VALIDATION' | 'INVALID_EXTENSION' | 'EXTENSION_CONFLICT' | 'COMPUTE_CYCLE' | 'COMPUTE_ASSIGNMENT' | 'RECOMPUTE_LIMIT' | 'CONSTRAINT' | 'CONSTRAINT_VIOLATION' | 'INVALID_TRANSITION' | 'TRANSITION_GUARD' | 'CROSS_COMPANY' | 'MISSING_RATE' | 'UNKNOWN_SEQUENCE' | 'ACCESS';
3
+ /**
4
+ * Base class of every error raised by `@shutro/core`. The message says what went wrong and ends with
5
+ * {@link ShutroError.hint}, which says how to fix it (`CLAUDE.md` coding rules).
6
+ */
7
+ export declare class ShutroError extends Error {
8
+ /** Machine-readable reason. */
9
+ readonly code: ShutroErrorCode;
10
+ /** How to fix the problem. Also included at the end of `message`. */
11
+ readonly hint: string;
12
+ constructor(code: ShutroErrorCode, problem: string, hint: string, options?: {
13
+ readonly cause?: unknown;
14
+ });
15
+ }
16
+ /** A JavaScript `number` that isn't a safe integer was used where an exact decimal is required. */
17
+ export declare class NonIntegerNumberError extends ShutroError {
18
+ constructor(problem: string, hint: string);
19
+ }
20
+ /** A string or Decimal that isn't a finite decimal number. */
21
+ export declare class InvalidDecimalError extends ShutroError {
22
+ constructor(problem: string, hint: string);
23
+ }
24
+ /** Division of a money amount or quantity by zero. */
25
+ export declare class DivisionByZeroError extends ShutroError {
26
+ constructor(problem: string, hint: string);
27
+ }
28
+ /** Invalid currency definition. */
29
+ export declare class InvalidCurrencyError extends ShutroError {
30
+ constructor(problem: string, hint: string);
31
+ }
32
+ /** Arithmetic or comparison between amounts in different currencies (RFC 0006 R4). */
33
+ export declare class CurrencyMismatchError extends ShutroError {
34
+ constructor(problem: string, hint: string);
35
+ }
36
+ /** Invalid ratios passed to `Money.allocate()`. */
37
+ export declare class InvalidAllocationError extends ShutroError {
38
+ constructor(problem: string, hint: string);
39
+ }
40
+ /** `Money.sum([])` without a currency. */
41
+ export declare class EmptyMoneySumError extends ShutroError {
42
+ constructor(problem: string, hint: string);
43
+ }
44
+ /** Invalid unit-of-measure definition. */
45
+ export declare class InvalidUomError extends ShutroError {
46
+ constructor(problem: string, hint: string);
47
+ }
48
+ /** Arithmetic or comparison between quantities in different units. */
49
+ export declare class UomMismatchError extends ShutroError {
50
+ constructor(problem: string, hint: string);
51
+ }
52
+ /** Conversion between units of different categories (e.g. units to kilograms). */
53
+ export declare class IncompatibleUomCategoryError extends ShutroError {
54
+ constructor(problem: string, hint: string);
55
+ }
56
+ /** No environment is active (code ran outside `shutro.run()`), RFC 0003 §7.7. */
57
+ export declare class NoEnvironmentError extends ShutroError {
58
+ constructor();
59
+ }
60
+ /** An environment was used outside its transaction scope (RFC 0003 §7.7). */
61
+ export declare class TransactionScopeError extends ShutroError {
62
+ constructor(problem: string, hint: string);
63
+ }
64
+ /** Every retry of a transaction hit a serialization failure or deadlock (RFC 0003 §7.5). */
65
+ export declare class ConcurrentUpdateError extends ShutroError {
66
+ constructor(attempts: number, cause: unknown);
67
+ }
68
+ /** Invalid user, company, language, time zone or reason passed to `shutro.run()` or a derived environment. */
69
+ export declare class InvalidIdentityError extends ShutroError {
70
+ constructor(problem: string, hint: string);
71
+ }
72
+ /** `withCompany()` outside the user's allowed companies (RFC 0003 §7.2). */
73
+ export declare class CompanyNotAllowedError extends ShutroError {
74
+ constructor(company: number, allowed: readonly number[]);
75
+ }
76
+ /** A field definition that can't be right (RFC 0001): bad size, scale, selection, transition, relation option, ... */
77
+ export declare class InvalidFieldError extends ShutroError {
78
+ constructor(problem: string, hint: string);
79
+ }
80
+ /** A model definition that can't be right (RFC 0001): reserved keys, column collisions, bad sibling references, ... */
81
+ export declare class InvalidModelError extends ShutroError {
82
+ constructor(model: string, problem: string, hint: string);
83
+ }
84
+ /** A module definition that can't be right (RFC 0002 §7.1). */
85
+ export declare class InvalidModuleError extends ShutroError {
86
+ constructor(problem: string, hint: string);
87
+ }
88
+ /** Two different module objects share a name (e.g. two copies of `base` from different package versions). */
89
+ export declare class DuplicateModuleError extends ShutroError {
90
+ constructor(name: string);
91
+ }
92
+ /** The same model name is defined twice (in one module or in two). */
93
+ export declare class DuplicateModelError extends ShutroError {
94
+ constructor(model: string, modules: readonly string[]);
95
+ }
96
+ /** A module references a model owned by a module it doesn't depend on (RFC 0002 W2). */
97
+ export declare class UndeclaredDependencyError extends ShutroError {
98
+ constructor(module: string, model: string, owner: string, via: string);
99
+ }
100
+ /** A model name that no loaded module defines. */
101
+ export declare class UnknownModelError extends ShutroError {
102
+ constructor(model: string, via: string | undefined);
103
+ }
104
+ /** A one2many whose inverse field doesn't point back, or another broken relation. */
105
+ export declare class InvalidRelationError extends ShutroError {
106
+ constructor(problem: string, hint: string);
107
+ }
108
+ /** A `depends` path that doesn't resolve through real fields. */
109
+ export declare class InvalidDependsPathError extends ShutroError {
110
+ constructor(problem: string, hint: string);
111
+ }
112
+ /** A field was read before it was loaded (RFC 0004 §7.1). */
113
+ export declare class FieldNotLoadedError extends ShutroError {
114
+ constructor(model: string, field: string, hint: string);
115
+ }
116
+ /** `first()` on an empty recordset, or `ensureOne()` on a recordset that isn't exactly one record. */
117
+ export declare class SingletonError extends ShutroError {
118
+ constructor(model: string, count: number, what: 'first' | 'ensureOne');
119
+ }
120
+ /** A browsed id that doesn't exist (or isn't visible). */
121
+ export declare class MissingRecordError extends ShutroError {
122
+ constructor(model: string, ids: readonly number[]);
123
+ }
124
+ /** A search domain that can't be compiled (RFC 0005 §7.1). */
125
+ export declare class InvalidDomainError extends ShutroError {
126
+ constructor(problem: string, hint: string);
127
+ }
128
+ /** `env.model()` on a Shutro instance created without a registry. */
129
+ export declare class NoRegistryError extends ShutroError {
130
+ constructor();
131
+ }
132
+ /** Values rejected by `create()` / `write()`: missing required fields, unknown or readonly fields, wrong types (RFC 0001 §7.7). */
133
+ export declare class ValidationError extends ShutroError {
134
+ readonly model: string;
135
+ /** The offending field keys. */
136
+ readonly fields: readonly string[];
137
+ constructor(model: string, fields: readonly string[], problem: string, hint: string);
138
+ }
139
+ /** An extension that breaks a view-safety rule (RFC 0002 §7.5) or is malformed. */
140
+ export declare class InvalidExtensionError extends ShutroError {
141
+ constructor(problem: string, hint: string);
142
+ }
143
+ /** Two modules contribute the same field, method or constraint key (RFC 0002 §7.6). Never resolved silently. */
144
+ export declare class ExtensionConflictError extends ShutroError {
145
+ constructor(problem: string, hint: string);
146
+ }
147
+ /** A flag that only a superuser environment may change (RFC 0003 §7.4). */
148
+ export declare class FlagNotAllowedError extends ShutroError {
149
+ constructor(flag: string);
150
+ }
151
+ /** Computed fields depend on each other in a cycle (RFC 0008 §7.1). */
152
+ export declare class ComputeCycleError extends ShutroError {
153
+ constructor(chain: readonly string[]);
154
+ }
155
+ /** A computed field was assigned outside its compute (RFC 0008 §7.5). */
156
+ export declare class ComputeAssignmentError extends ShutroError {
157
+ constructor(model: string, key: string);
158
+ }
159
+ /** The recompute loop did not converge (RFC 0008 §7.3). */
160
+ export declare class RecomputeLimitError extends ShutroError {
161
+ constructor(rounds: number, pending: readonly string[]);
162
+ }
163
+ /** A business constraint found failing records at a flush point (RFC 0009 §7.1). */
164
+ export declare class ConstraintError extends ShutroError {
165
+ readonly model: string;
166
+ readonly constraint: string;
167
+ /** The constraint's `depends`. */
168
+ readonly fields: readonly string[];
169
+ /** Ids of the failing records. */
170
+ readonly records: readonly number[];
171
+ constructor(model: string, constraint: string, fields: readonly string[], records: readonly number[], message: string);
172
+ }
173
+ /** Which kind of SQL constraint PostgreSQL reported. */
174
+ export type SqlConstraintKind = 'unique' | 'check' | 'exclusion' | 'foreign_key';
175
+ /** PostgreSQL rejected a statement because of a declared `sqlConstraints` entry or a foreign key (RFC 0009 §7.2). */
176
+ export declare class ConstraintViolationError extends ShutroError {
177
+ readonly model: string;
178
+ /** The `sqlConstraints` key, or the many2one field for a foreign key. */
179
+ readonly constraint: string;
180
+ readonly kind: SqlConstraintKind;
181
+ readonly fields: readonly string[];
182
+ constructor(model: string, constraint: string, kind: SqlConstraintKind, fields: readonly string[], message: string, hint: string, options?: {
183
+ cause?: unknown;
184
+ });
185
+ }
186
+ /** A transition was requested from a state it does not start from (RFC 0010 §7.2). Nothing changed. */
187
+ export declare class InvalidTransitionError extends ShutroError {
188
+ readonly model: string;
189
+ readonly transition: string;
190
+ /** The offending records with their current state. */
191
+ readonly records: readonly {
192
+ readonly id: number;
193
+ readonly state: string;
194
+ }[];
195
+ /** The states the transition starts from. */
196
+ readonly from: readonly string[];
197
+ constructor(model: string, transition: string, records: readonly {
198
+ readonly id: number;
199
+ readonly state: string;
200
+ }[], from: readonly string[]);
201
+ }
202
+ /** A transition guard returned records that may not transition (RFC 0010 §7.2). Nothing changed. */
203
+ export declare class TransitionGuardError extends ShutroError {
204
+ readonly model: string;
205
+ readonly transition: string;
206
+ readonly records: readonly number[];
207
+ constructor(model: string, transition: string, records: readonly number[], message: string);
208
+ }
209
+ /** A record references a record of another company through a `checkCompany` many2one (RFC 0003 §7.4). */
210
+ export declare class CrossCompanyError extends ShutroError {
211
+ readonly model: string;
212
+ readonly records: readonly {
213
+ readonly id: number;
214
+ readonly field: string;
215
+ readonly company: number | null;
216
+ readonly targetCompany: number;
217
+ }[];
218
+ constructor(model: string, records: CrossCompanyError['records']);
219
+ }
220
+ /** No exchange rate on or before the date (RFC 0006 §7.6), or the rate model is unusable. */
221
+ export declare class MissingRateError extends ShutroError {
222
+ constructor(problem: string, hint: string);
223
+ }
224
+ /** A field references a sequence code no module declares (RFC 0012 §7.1). */
225
+ export declare class UnknownSequenceError extends ShutroError {
226
+ constructor(code: string, where: string);
227
+ }
228
+ /** An operation the environment may not perform (RFC 0014): model ACL, record rules or field groups. */
229
+ export declare class AccessError extends ShutroError {
230
+ readonly model: string;
231
+ readonly perm: string;
232
+ /** The records out of scope, when the rules denied them. */
233
+ readonly records: readonly number[];
234
+ /** The restricted field, when field groups denied it. */
235
+ readonly field: string | undefined;
236
+ constructor(model: string, perm: string, details: {
237
+ readonly records?: readonly number[];
238
+ readonly field?: string;
239
+ readonly problem: string;
240
+ readonly hint: string;
241
+ });
242
+ }