@astram/core 1.6.0 → 1.8.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,161 @@
1
+ /**
2
+ * Framework database names (configurable-framework-db, spec §5.A, §10, §13; ADR-0037).
3
+ *
4
+ * The single source of the four framework database names. `SHIELD_DB_NAMESPACE` renames all
5
+ * four together (`beta` ⇒ `beta_app`, `beta_identity`, `beta_authz`, `beta_audit`); unset keeps
6
+ * today's `shield_*` names. Pure and zero-dep (ADR-0003): the caller passes an env-like record,
7
+ * nothing here reads `process.env`.
8
+ *
9
+ * SECURITY: fail closed (Shield #1) — a set-but-empty or non-matching namespace throws; a
10
+ * failure never returns a partial set. Names reach SQL only after this validation, and the
11
+ * pattern admits no quote, backtick, dot or whitespace.
12
+ */
13
+ /** The env variable that selects the namespace. */
14
+ export declare const FRAMEWORK_DB_NAMESPACE_ENV = "SHIELD_DB_NAMESPACE";
15
+ /** The namespace used when `SHIELD_DB_NAMESPACE` is unset (today's names). */
16
+ export declare const DEFAULT_FRAMEWORK_DB_NAMESPACE = "shield";
17
+ /**
18
+ * Allowed namespace. `<ns>_identity`, the longest name, stays within MariaDB's 64-character
19
+ * identifier limit (55 + 9).
20
+ */
21
+ export declare const FRAMEWORK_DB_NAMESPACE_PATTERN: RegExp;
22
+ /** The fixed database suffixes, one per framework module. */
23
+ export declare const FRAMEWORK_SCHEMA_SUFFIXES: Readonly<{
24
+ readonly app: "_app";
25
+ readonly identity: "_identity";
26
+ readonly authz: "_authz";
27
+ readonly audit: "_audit";
28
+ }>;
29
+ /** Selects the layout: `four` (default, unset) or `single` (single-database-layout spec §5.A, ADR-0041). */
30
+ export declare const FRAMEWORK_DB_LAYOUT_ENV = "SHIELD_DB_LAYOUT";
31
+ /** The single database name when `SHIELD_DB_LAYOUT=single`. Validated by {@link SCHEMA_NAME_PATTERN}. */
32
+ export declare const FRAMEWORK_DB_NAME_ENV = "SHIELD_DB_NAME";
33
+ /** Must be exactly `1` for the single layout: the operator accepts the reduced isolation. */
34
+ export declare const FRAMEWORK_DB_LAYOUT_ACK_ENV = "SHIELD_DB_LAYOUT_ACK_REDUCED_ISOLATION";
35
+ /** The resolved framework database names. Always frozen. */
36
+ export interface FrameworkSchemas {
37
+ readonly namespace: string;
38
+ readonly app: string;
39
+ readonly identity: string;
40
+ readonly authz: string;
41
+ readonly audit: string;
42
+ /**
43
+ * True on the `shield` default: `SHIELD_DB_NAMESPACE` unset, or set to `shield` explicitly
44
+ * (which behaves exactly like unset).
45
+ */
46
+ readonly isDefault: boolean;
47
+ /**
48
+ * `'single'` when all four modules share one database (`SHIELD_DB_LAYOUT=single`; then
49
+ * `namespace` and the four names all equal `SHIELD_DB_NAME`). Absent in the four-database
50
+ * layout, so today's output is unchanged (single-database-layout spec §5.A, ADR-0041).
51
+ */
52
+ readonly layout?: 'single';
53
+ }
54
+ /** Thrown for an invalid framework database configuration. Never carries a secret. */
55
+ export declare class FrameworkSchemaConfigError extends Error {
56
+ constructor(message: string);
57
+ }
58
+ /**
59
+ * Resolve the four framework database names from an env-like record.
60
+ * @throws FrameworkSchemaConfigError when `SHIELD_DB_NAMESPACE` is set but empty or invalid.
61
+ */
62
+ export declare function resolveFrameworkSchemas(env: Readonly<Record<string, string | undefined>>): FrameworkSchemas;
63
+ /**
64
+ * The DB account name for a matrix account role under a namespace: `<ns>_<role>`
65
+ * (`frameworkAccountName('beta', 'core')` ⇒ `beta_core`). Roles are the matrix account names
66
+ * without the `shield_` prefix (`core`, `migrate`, `audit_ops`, ...).
67
+ */
68
+ export declare function frameworkAccountName(namespace: string, role: string): string;
69
+ /**
70
+ * A database name a caller may hand to framework SQL (`opts.schema`, `forRoot({ schemas })`):
71
+ * lower-case letters, digits and `_`, 1..64 characters (MariaDB's identifier limit). Names come
72
+ * from the resolver or from operator config, both lower-case (MariaDB database names are
73
+ * case-sensitive on Linux, so a mixed-case name is refused rather than guessed). It admits no
74
+ * backtick, quote, dot, whitespace or `;`, so a name that passes can be backtick-quoted safely.
75
+ */
76
+ export declare const SCHEMA_NAME_PATTERN: RegExp;
77
+ /**
78
+ * Check a caller-supplied database name before it reaches SQL (configurable-framework-db,
79
+ * spec §11). Returns the name unchanged.
80
+ * @param label names the setting in the error (e.g. `opts.schema`); the value is never echoed.
81
+ * @throws FrameworkSchemaConfigError when the name is not a string matching
82
+ * {@link SCHEMA_NAME_PATTERN}.
83
+ */
84
+ export declare function assertSchemaName(name: unknown, label: string): string;
85
+ /** The four framework database names, as `FrameworkSchemas` or any object carrying them. */
86
+ export type FrameworkSchemaNameSet = Pick<FrameworkSchemas, 'app' | 'identity' | 'authz' | 'audit'>;
87
+ /**
88
+ * Check all four names of a caller-supplied set (`forRoot({ schemas })`, a store's `schemas`
89
+ * argument, `ctx.schemas`) with {@link assertSchemaName}. Returns the same object.
90
+ * @throws FrameworkSchemaConfigError naming `<label>.<field>` for the first bad name.
91
+ */
92
+ export declare function assertFrameworkSchemaNames<T extends FrameworkSchemaNameSet>(schemas: T, label: string): T;
93
+ /** The context shape {@link frameworkSchemasForMigration} reads (any `@astram/migrate` version). */
94
+ export interface MigrationSchemasContext {
95
+ readonly schemas?: FrameworkSchemas | undefined;
96
+ }
97
+ /**
98
+ * The framework database names for a framework migration's `up`/`down` (spec v2 §5.H, decided
99
+ * Q2). `@astram/guard` and `@astram/identity` do not depend on `@astram/migrate`, so their
100
+ * migrations may run under an older CLI that passes no `ctx.schemas`:
101
+ * - `ctx.schemas` present (current `@astram/migrate`) ⇒ those names, validated;
102
+ * - absent and `SHIELD_DB_NAMESPACE` unset (or `shield`) ⇒ the default `shield_*` names (today's
103
+ * behaviour);
104
+ * - absent and `SHIELD_DB_NAMESPACE` set to any other value ⇒ throws before any DDL, telling the
105
+ * operator to upgrade `@astram/migrate`.
106
+ *
107
+ * Usage in a migration file: `const s = frameworkSchemasForMigration(ctx, process.env);`.
108
+ * Pure: the caller passes the env.
109
+ * @throws FrameworkSchemaConfigError as above, or for an invalid name in `ctx.schemas`.
110
+ */
111
+ export declare function frameworkSchemasForMigration(ctx: MigrationSchemasContext | undefined, env: Readonly<Record<string, string | undefined>>): FrameworkSchemas;
112
+ /** The `@astram/migrate` ledger table when `APP_MIGRATION_TABLE` is unset. */
113
+ export declare const DEFAULT_MIGRATION_LEDGER_TABLE = "schema_migrations";
114
+ /** A ledger table name: a plain identifier, safe to backtick-quote. */
115
+ export declare const MIGRATION_LEDGER_TABLE_PATTERN: RegExp;
116
+ /** Where the `@astram/migrate` ledger (tracking table) lives. */
117
+ export interface MigrationLedgerLocation {
118
+ readonly database: string;
119
+ readonly table: string;
120
+ }
121
+ /**
122
+ * An operator-supplied ledger database name (`DDL_DB_NAME`, or a migrate job's `APP_DB_NAME` in
123
+ * default mode): any plain MariaDB identifier, mixed case included, so a name that worked with
124
+ * earlier `@astram/migrate` releases keeps working. Letters, digits and `_` only, 1..64: no
125
+ * backtick, quote, dot, whitespace or `;`, so it is safe to backtick-quote or single-quote.
126
+ * Resolver-produced names stay on the stricter {@link SCHEMA_NAME_PATTERN}.
127
+ */
128
+ export declare const LEDGER_DATABASE_NAME_PATTERN: RegExp;
129
+ /**
130
+ * Check an operator-supplied ledger database name before it reaches SQL. Returns it unchanged.
131
+ * @param label names the setting in the error (e.g. `DDL_DB_NAME`); the value is never echoed.
132
+ * @throws FrameworkSchemaConfigError when the name does not match
133
+ * {@link LEDGER_DATABASE_NAME_PATTERN}.
134
+ */
135
+ export declare function assertLedgerDatabaseName(name: unknown, label: string): string;
136
+ /**
137
+ * The ledger-location rule of the migrate CLI (configurable-framework-db spec 5.G):
138
+ * - namespace set ⇒ always `<ns>_app`; a `DDL_DB_NAME` other than `<ns>_app` throws;
139
+ * - namespace unset (or `shield`) ⇒ `DDL_DB_NAME`, else the default app database. (The CLI adds
140
+ * its released fallback to the job's `APP_DB_NAME` before `shield_app`.)
141
+ * Table: `APP_MIGRATION_TABLE`, else `schema_migrations`. The runtime boot check does not use this
142
+ * single location: it tries {@link migrationLedgerCandidates}. Pure: the caller passes the env.
143
+ * @throws FrameworkSchemaConfigError naming the variable on a conflicting or invalid name.
144
+ */
145
+ export declare function resolveMigrationLedgerLocation(schemas: FrameworkSchemas, env: Readonly<Record<string, string | undefined>>): MigrationLedgerLocation;
146
+ /**
147
+ * Where the runtime boot check looks for the ledger, in order (G-007 QA P1). A standard scaffold
148
+ * runs `astram-migrate` with the server's env, so in default mode migrate writes the ledger to
149
+ * `DDL_DB_NAME`, else the job's `APP_DB_NAME`, else `shield_app`; the boot check cannot know
150
+ * which env the migrate job had, so it tries each:
151
+ * - namespace set ⇒ only `<ns>_app` (as {@link resolveMigrationLedgerLocation}; `APP_DB_NAME`
152
+ * is ignored, a conflicting `DDL_DB_NAME` throws);
153
+ * - namespace unset (or `shield`) ⇒ `DDL_DB_NAME`, the runtime `APP_DB_NAME`, then the default
154
+ * app database; unset or blank values skipped, duplicates dropped.
155
+ * The caller uses the first location whose ledger table exists and must still find every shipped
156
+ * id there; when none exists it fails closed naming every location. Pure: the caller passes the
157
+ * env. Returns a frozen, non-empty list.
158
+ * @throws FrameworkSchemaConfigError naming the variable on a conflicting or invalid name.
159
+ */
160
+ export declare function migrationLedgerCandidates(schemas: FrameworkSchemas, env: Readonly<Record<string, string | undefined>>): readonly MigrationLedgerLocation[];
161
+ //# sourceMappingURL=framework-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-schemas.d.ts","sourceRoot":"","sources":["../../src/database/framework-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mDAAmD;AACnD,eAAO,MAAM,0BAA0B,wBAAwB,CAAC;AAEhE,8EAA8E;AAC9E,eAAO,MAAM,8BAA8B,WAAW,CAAC;AAEvD;;;GAGG;AAIH,eAAO,MAAM,8BAA8B,QAA0B,CAAC;AAEtE,6DAA6D;AAC7D,eAAO,MAAM,yBAAyB;;;;;EAK3B,CAAC;AAEZ,4GAA4G;AAC5G,eAAO,MAAM,uBAAuB,qBAA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,KAAK,EAAE,MAAM,GACZ,CAAC,CAqBH;AAED,oGAAoG;AACpG,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACjD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,uBAAuB,GAAG,SAAS,EACxC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAChD,gBAAgB,CAwBlB;AAED,8EAA8E;AAC9E,eAAO,MAAM,8BAA8B,sBAAsB,CAAC;AAElE,uEAAuE;AACvE,eAAO,MAAM,8BAA8B,QAA0B,CAAC;AAEtE,iEAAiE;AACjE,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,QAAyB,CAAC;AAEnE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAO7E;AAYD;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAChD,uBAAuB,CA4BzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAChD,SAAS,uBAAuB,EAAE,CAepC"}
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Framework database names (configurable-framework-db, spec §5.A, §10, §13; ADR-0037).
3
+ *
4
+ * The single source of the four framework database names. `SHIELD_DB_NAMESPACE` renames all
5
+ * four together (`beta` ⇒ `beta_app`, `beta_identity`, `beta_authz`, `beta_audit`); unset keeps
6
+ * today's `shield_*` names. Pure and zero-dep (ADR-0003): the caller passes an env-like record,
7
+ * nothing here reads `process.env`.
8
+ *
9
+ * SECURITY: fail closed (Shield #1) — a set-but-empty or non-matching namespace throws; a
10
+ * failure never returns a partial set. Names reach SQL only after this validation, and the
11
+ * pattern admits no quote, backtick, dot or whitespace.
12
+ */
13
+ /** The env variable that selects the namespace. */
14
+ export const FRAMEWORK_DB_NAMESPACE_ENV = 'SHIELD_DB_NAMESPACE';
15
+ /** The namespace used when `SHIELD_DB_NAMESPACE` is unset (today's names). */
16
+ export const DEFAULT_FRAMEWORK_DB_NAMESPACE = 'shield';
17
+ /**
18
+ * Allowed namespace. `<ns>_identity`, the longest name, stays within MariaDB's 64-character
19
+ * identifier limit (55 + 9).
20
+ */
21
+ // Letters and digits only (spec v3): `_` is a one-character wildcard in MariaDB database-level
22
+ // grants, so a namespace containing `_` could make one environment's grants match another's
23
+ // databases (`team_a_app` also matches `team1a_app`).
24
+ export const FRAMEWORK_DB_NAMESPACE_PATTERN = /^[a-z][a-z0-9]{0,54}$/;
25
+ /** The fixed database suffixes, one per framework module. */
26
+ export const FRAMEWORK_SCHEMA_SUFFIXES = Object.freeze({
27
+ app: '_app',
28
+ identity: '_identity',
29
+ authz: '_authz',
30
+ audit: '_audit',
31
+ });
32
+ /** Selects the layout: `four` (default, unset) or `single` (single-database-layout spec §5.A, ADR-0041). */
33
+ export const FRAMEWORK_DB_LAYOUT_ENV = 'SHIELD_DB_LAYOUT';
34
+ /** The single database name when `SHIELD_DB_LAYOUT=single`. Validated by {@link SCHEMA_NAME_PATTERN}. */
35
+ export const FRAMEWORK_DB_NAME_ENV = 'SHIELD_DB_NAME';
36
+ /** Must be exactly `1` for the single layout: the operator accepts the reduced isolation. */
37
+ export const FRAMEWORK_DB_LAYOUT_ACK_ENV = 'SHIELD_DB_LAYOUT_ACK_REDUCED_ISOLATION';
38
+ /** Thrown for an invalid framework database configuration. Never carries a secret. */
39
+ export class FrameworkSchemaConfigError extends Error {
40
+ constructor(message) {
41
+ super(message);
42
+ this.name = 'FrameworkSchemaConfigError';
43
+ }
44
+ }
45
+ function namesFor(namespace, isDefault) {
46
+ return Object.freeze({
47
+ namespace,
48
+ app: `${namespace}${FRAMEWORK_SCHEMA_SUFFIXES.app}`,
49
+ identity: `${namespace}${FRAMEWORK_SCHEMA_SUFFIXES.identity}`,
50
+ authz: `${namespace}${FRAMEWORK_SCHEMA_SUFFIXES.authz}`,
51
+ audit: `${namespace}${FRAMEWORK_SCHEMA_SUFFIXES.audit}`,
52
+ isDefault,
53
+ });
54
+ }
55
+ // Single layout (single-database-layout spec §5.A): fail closed; values are never echoed.
56
+ function resolveSingle(env) {
57
+ const name = env[FRAMEWORK_DB_NAME_ENV];
58
+ if (typeof name !== 'string' || !SCHEMA_NAME_PATTERN.test(name)) {
59
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_NAME_ENV} is required and must be a valid database name when ` +
60
+ `${FRAMEWORK_DB_LAYOUT_ENV}=single; expected ${SCHEMA_NAME_PATTERN.source}`);
61
+ }
62
+ if (env[FRAMEWORK_DB_LAYOUT_ACK_ENV] !== '1') {
63
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_LAYOUT_ACK_ENV}=1 is required when ${FRAMEWORK_DB_LAYOUT_ENV}=single ` +
64
+ '(the single database layout reduces isolation; ADR-0041)');
65
+ }
66
+ if (env[FRAMEWORK_DB_NAMESPACE_ENV] !== undefined) {
67
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_NAMESPACE_ENV} must not be set when ${FRAMEWORK_DB_LAYOUT_ENV}=single; ` +
68
+ `use ${FRAMEWORK_DB_NAME_ENV}`);
69
+ }
70
+ return Object.freeze({
71
+ namespace: name,
72
+ app: name,
73
+ identity: name,
74
+ authz: name,
75
+ audit: name,
76
+ isDefault: false,
77
+ layout: 'single',
78
+ });
79
+ }
80
+ /**
81
+ * Resolve the four framework database names from an env-like record.
82
+ * @throws FrameworkSchemaConfigError when `SHIELD_DB_NAMESPACE` is set but empty or invalid.
83
+ */
84
+ export function resolveFrameworkSchemas(env) {
85
+ const layout = env[FRAMEWORK_DB_LAYOUT_ENV];
86
+ if (layout !== undefined && layout !== 'four' && layout !== 'single') {
87
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_LAYOUT_ENV} must be "four" or "single" (unset for the default "four")`);
88
+ }
89
+ if (layout === 'single')
90
+ return resolveSingle(env);
91
+ const raw = env[FRAMEWORK_DB_NAMESPACE_ENV];
92
+ if (raw === undefined)
93
+ return namesFor(DEFAULT_FRAMEWORK_DB_NAMESPACE, true);
94
+ if (!FRAMEWORK_DB_NAMESPACE_PATTERN.test(raw)) {
95
+ // The value is not echoed: it is config, not a secret, but the message stays a fixed shape.
96
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_NAMESPACE_ENV} is set but ${raw === '' ? 'empty' : 'invalid'}; ` +
97
+ `expected ${FRAMEWORK_DB_NAMESPACE_PATTERN.source} (unset it for the default "${DEFAULT_FRAMEWORK_DB_NAMESPACE}")`);
98
+ }
99
+ // An explicit default namespace is the default: same names AND the same rules (ledger, old
100
+ // migrate fallback), so `SHIELD_DB_NAMESPACE=shield` never behaves differently from unset.
101
+ return namesFor(raw, raw === DEFAULT_FRAMEWORK_DB_NAMESPACE);
102
+ }
103
+ /**
104
+ * The DB account name for a matrix account role under a namespace: `<ns>_<role>`
105
+ * (`frameworkAccountName('beta', 'core')` ⇒ `beta_core`). Roles are the matrix account names
106
+ * without the `shield_` prefix (`core`, `migrate`, `audit_ops`, ...).
107
+ */
108
+ export function frameworkAccountName(namespace, role) {
109
+ return `${namespace}_${role}`;
110
+ }
111
+ /**
112
+ * A database name a caller may hand to framework SQL (`opts.schema`, `forRoot({ schemas })`):
113
+ * lower-case letters, digits and `_`, 1..64 characters (MariaDB's identifier limit). Names come
114
+ * from the resolver or from operator config, both lower-case (MariaDB database names are
115
+ * case-sensitive on Linux, so a mixed-case name is refused rather than guessed). It admits no
116
+ * backtick, quote, dot, whitespace or `;`, so a name that passes can be backtick-quoted safely.
117
+ */
118
+ export const SCHEMA_NAME_PATTERN = /^[a-z0-9_]{1,64}$/;
119
+ /**
120
+ * Check a caller-supplied database name before it reaches SQL (configurable-framework-db,
121
+ * spec §11). Returns the name unchanged.
122
+ * @param label names the setting in the error (e.g. `opts.schema`); the value is never echoed.
123
+ * @throws FrameworkSchemaConfigError when the name is not a string matching
124
+ * {@link SCHEMA_NAME_PATTERN}.
125
+ */
126
+ export function assertSchemaName(name, label) {
127
+ if (typeof name !== 'string' || !SCHEMA_NAME_PATTERN.test(name)) {
128
+ throw new FrameworkSchemaConfigError(`${label} is not a valid database name; expected ${SCHEMA_NAME_PATTERN.source}`);
129
+ }
130
+ return name;
131
+ }
132
+ /**
133
+ * Check all four names of a caller-supplied set (`forRoot({ schemas })`, a store's `schemas`
134
+ * argument, `ctx.schemas`) with {@link assertSchemaName}. Returns the same object.
135
+ * @throws FrameworkSchemaConfigError naming `<label>.<field>` for the first bad name.
136
+ */
137
+ export function assertFrameworkSchemaNames(schemas, label) {
138
+ if (typeof schemas !== 'object' || schemas === null) {
139
+ throw new FrameworkSchemaConfigError(`${label} must be an object with app, identity, authz and audit database names`);
140
+ }
141
+ for (const key of ['app', 'identity', 'authz', 'audit']) {
142
+ assertSchemaName(schemas[key], `${label}.${key}`);
143
+ }
144
+ // Four equal names are one database: only the single layout may say so (spec §5.A, ADR-0041).
145
+ const single = schemas.layout === 'single';
146
+ const allEqual = schemas.app === schemas.identity &&
147
+ schemas.app === schemas.authz &&
148
+ schemas.app === schemas.audit;
149
+ if (single !== allEqual) {
150
+ throw new FrameworkSchemaConfigError(`${label} names must be four distinct databases, or one database with layout "single"`);
151
+ }
152
+ return schemas;
153
+ }
154
+ /**
155
+ * The framework database names for a framework migration's `up`/`down` (spec v2 §5.H, decided
156
+ * Q2). `@astram/guard` and `@astram/identity` do not depend on `@astram/migrate`, so their
157
+ * migrations may run under an older CLI that passes no `ctx.schemas`:
158
+ * - `ctx.schemas` present (current `@astram/migrate`) ⇒ those names, validated;
159
+ * - absent and `SHIELD_DB_NAMESPACE` unset (or `shield`) ⇒ the default `shield_*` names (today's
160
+ * behaviour);
161
+ * - absent and `SHIELD_DB_NAMESPACE` set to any other value ⇒ throws before any DDL, telling the
162
+ * operator to upgrade `@astram/migrate`.
163
+ *
164
+ * Usage in a migration file: `const s = frameworkSchemasForMigration(ctx, process.env);`.
165
+ * Pure: the caller passes the env.
166
+ * @throws FrameworkSchemaConfigError as above, or for an invalid name in `ctx.schemas`.
167
+ */
168
+ export function frameworkSchemasForMigration(ctx, env) {
169
+ const given = ctx?.schemas;
170
+ // An older migrate (pinned core ignores the layout) may pass four-layout names while the env
171
+ // asks for the single layout: refuse before any DDL (AC-11).
172
+ if (given !== undefined &&
173
+ !(env[FRAMEWORK_DB_LAYOUT_ENV] === 'single' && given.layout !== 'single')) {
174
+ return assertFrameworkSchemaNames(given, 'ctx.schemas');
175
+ }
176
+ if (env[FRAMEWORK_DB_LAYOUT_ENV] === 'single') {
177
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_LAYOUT_ENV}=single but this @astram/migrate does not pass ctx.schemas; ` +
178
+ 'upgrade @astram/migrate');
179
+ }
180
+ const ns = env[FRAMEWORK_DB_NAMESPACE_ENV];
181
+ if (ns !== undefined && ns !== DEFAULT_FRAMEWORK_DB_NAMESPACE) {
182
+ throw new FrameworkSchemaConfigError(`${FRAMEWORK_DB_NAMESPACE_ENV} is set but this @astram/migrate does not pass ctx.schemas; ` +
183
+ 'upgrade @astram/migrate');
184
+ }
185
+ return namesFor(DEFAULT_FRAMEWORK_DB_NAMESPACE, true);
186
+ }
187
+ /** The `@astram/migrate` ledger table when `APP_MIGRATION_TABLE` is unset. */
188
+ export const DEFAULT_MIGRATION_LEDGER_TABLE = 'schema_migrations';
189
+ /** A ledger table name: a plain identifier, safe to backtick-quote. */
190
+ export const MIGRATION_LEDGER_TABLE_PATTERN = /^[A-Za-z0-9_$]{1,64}$/;
191
+ /**
192
+ * An operator-supplied ledger database name (`DDL_DB_NAME`, or a migrate job's `APP_DB_NAME` in
193
+ * default mode): any plain MariaDB identifier, mixed case included, so a name that worked with
194
+ * earlier `@astram/migrate` releases keeps working. Letters, digits and `_` only, 1..64: no
195
+ * backtick, quote, dot, whitespace or `;`, so it is safe to backtick-quote or single-quote.
196
+ * Resolver-produced names stay on the stricter {@link SCHEMA_NAME_PATTERN}.
197
+ */
198
+ export const LEDGER_DATABASE_NAME_PATTERN = /^[A-Za-z0-9_]{1,64}$/;
199
+ /**
200
+ * Check an operator-supplied ledger database name before it reaches SQL. Returns it unchanged.
201
+ * @param label names the setting in the error (e.g. `DDL_DB_NAME`); the value is never echoed.
202
+ * @throws FrameworkSchemaConfigError when the name does not match
203
+ * {@link LEDGER_DATABASE_NAME_PATTERN}.
204
+ */
205
+ export function assertLedgerDatabaseName(name, label) {
206
+ if (typeof name !== 'string' || !LEDGER_DATABASE_NAME_PATTERN.test(name)) {
207
+ throw new FrameworkSchemaConfigError(`${label} is not a valid database name; expected ${LEDGER_DATABASE_NAME_PATTERN.source}`);
208
+ }
209
+ return name;
210
+ }
211
+ function ledgerTable(env) {
212
+ const table = env.APP_MIGRATION_TABLE ?? DEFAULT_MIGRATION_LEDGER_TABLE;
213
+ if (!MIGRATION_LEDGER_TABLE_PATTERN.test(table)) {
214
+ throw new FrameworkSchemaConfigError(`APP_MIGRATION_TABLE is not a valid table name; expected ${MIGRATION_LEDGER_TABLE_PATTERN.source}`);
215
+ }
216
+ return table;
217
+ }
218
+ /**
219
+ * The ledger-location rule of the migrate CLI (configurable-framework-db spec 5.G):
220
+ * - namespace set ⇒ always `<ns>_app`; a `DDL_DB_NAME` other than `<ns>_app` throws;
221
+ * - namespace unset (or `shield`) ⇒ `DDL_DB_NAME`, else the default app database. (The CLI adds
222
+ * its released fallback to the job's `APP_DB_NAME` before `shield_app`.)
223
+ * Table: `APP_MIGRATION_TABLE`, else `schema_migrations`. The runtime boot check does not use this
224
+ * single location: it tries {@link migrationLedgerCandidates}. Pure: the caller passes the env.
225
+ * @throws FrameworkSchemaConfigError naming the variable on a conflicting or invalid name.
226
+ */
227
+ export function resolveMigrationLedgerLocation(schemas, env) {
228
+ const ddl = env.DDL_DB_NAME;
229
+ let database;
230
+ if (schemas.layout === 'single') {
231
+ if (ddl !== undefined && ddl !== schemas.app) {
232
+ throw new FrameworkSchemaConfigError(`DDL_DB_NAME must be ${schemas.app} or unset when ${FRAMEWORK_DB_LAYOUT_ENV}=single ` +
233
+ `(${FRAMEWORK_DB_NAME_ENV}): the migration ledger lives in ${schemas.app} ` +
234
+ '(single-database-layout spec §5.A).');
235
+ }
236
+ database = schemas.app;
237
+ }
238
+ else if (schemas.isDefault) {
239
+ database =
240
+ ddl === undefined
241
+ ? assertSchemaName(schemas.app, 'ledger')
242
+ : assertLedgerDatabaseName(ddl, 'DDL_DB_NAME');
243
+ }
244
+ else {
245
+ if (ddl !== undefined && ddl !== schemas.app) {
246
+ throw new FrameworkSchemaConfigError(`DDL_DB_NAME must be ${schemas.app} or unset when ` +
247
+ `${FRAMEWORK_DB_NAMESPACE_ENV}=${schemas.namespace}: the migration ledger lives in ` +
248
+ `${schemas.app} (spec 5.G).`);
249
+ }
250
+ database = schemas.app;
251
+ }
252
+ return { database, table: ledgerTable(env) };
253
+ }
254
+ /**
255
+ * Where the runtime boot check looks for the ledger, in order (G-007 QA P1). A standard scaffold
256
+ * runs `astram-migrate` with the server's env, so in default mode migrate writes the ledger to
257
+ * `DDL_DB_NAME`, else the job's `APP_DB_NAME`, else `shield_app`; the boot check cannot know
258
+ * which env the migrate job had, so it tries each:
259
+ * - namespace set ⇒ only `<ns>_app` (as {@link resolveMigrationLedgerLocation}; `APP_DB_NAME`
260
+ * is ignored, a conflicting `DDL_DB_NAME` throws);
261
+ * - namespace unset (or `shield`) ⇒ `DDL_DB_NAME`, the runtime `APP_DB_NAME`, then the default
262
+ * app database; unset or blank values skipped, duplicates dropped.
263
+ * The caller uses the first location whose ledger table exists and must still find every shipped
264
+ * id there; when none exists it fails closed naming every location. Pure: the caller passes the
265
+ * env. Returns a frozen, non-empty list.
266
+ * @throws FrameworkSchemaConfigError naming the variable on a conflicting or invalid name.
267
+ */
268
+ export function migrationLedgerCandidates(schemas, env) {
269
+ if (!schemas.isDefault) {
270
+ return Object.freeze([Object.freeze(resolveMigrationLedgerLocation(schemas, env))]);
271
+ }
272
+ const table = ledgerTable(env);
273
+ const databases = [];
274
+ for (const key of ['DDL_DB_NAME', 'APP_DB_NAME']) {
275
+ const raw = env[key];
276
+ if (raw === undefined || raw.trim() === '')
277
+ continue;
278
+ databases.push(assertLedgerDatabaseName(raw.trim(), key));
279
+ }
280
+ databases.push(assertSchemaName(schemas.app, 'ledger'));
281
+ return Object.freeze([...new Set(databases)].map((database) => Object.freeze({ database, table })));
282
+ }
283
+ //# sourceMappingURL=framework-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-schemas.js","sourceRoot":"","sources":["../../src/database/framework-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mDAAmD;AACnD,MAAM,CAAC,MAAM,0BAA0B,GAAG,qBAAqB,CAAC;AAEhE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,8BAA8B,GAAG,QAAQ,CAAC;AAEvD;;;GAGG;AACH,+FAA+F;AAC/F,4FAA4F;AAC5F,sDAAsD;AACtD,MAAM,CAAC,MAAM,8BAA8B,GAAG,uBAAuB,CAAC;AAEtE,6DAA6D;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM;IACX,QAAQ,EAAE,WAAW;IACrB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,QAAQ;CACP,CAAC,CAAC;AAEZ,4GAA4G;AAC5G,MAAM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O,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAC9E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** Framework tables, keyed by the module whose database holds them in the four layout. Deeply frozen. */
2
+ export declare const FRAMEWORK_TABLES: Readonly<{
3
+ app: readonly string[];
4
+ identity: readonly string[];
5
+ authz: readonly string[];
6
+ audit: readonly string[];
7
+ }>;
8
+ /** Framework stored routines. */
9
+ export declare const FRAMEWORK_ROUTINES: readonly string[];
10
+ /**
11
+ * True when `name` is a framework table or the migration ledger table (case-insensitive: MariaDB
12
+ * table-name case rules vary by platform). `ledgerTable` defaults to `schema_migrations`; a custom
13
+ * ledger name replaces the default.
14
+ */
15
+ export declare function isReservedFrameworkTable(name: string, ledgerTable?: string): boolean;
16
+ //# sourceMappingURL=framework-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-tables.d.ts","sourceRoot":"","sources":["../../src/database/framework-tables.ts"],"names":[],"mappings":"AASA,yGAAyG;AACzG,eAAO,MAAM,gBAAgB;;;;;EAqC3B,CAAC;AAEH,iCAAiC;AACjC,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAAmC,CAAC;AAIpF;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,MAAuC,GACnD,OAAO,CAGT"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Framework-owned tables and routines per module (single-database-layout spec §5.A, ADR-0041).
3
+ *
4
+ * In the single layout all four modules share one database, so a table name must not collide
5
+ * with a framework table (or the migration ledger). This list is the one published source.
6
+ * Pure and zero-dep (ADR-0003).
7
+ */
8
+ import { DEFAULT_MIGRATION_LEDGER_TABLE } from './framework-schemas.js';
9
+ /** Framework tables, keyed by the module whose database holds them in the four layout. Deeply frozen. */
10
+ export const FRAMEWORK_TABLES = Object.freeze({
11
+ app: Object.freeze([
12
+ 'companies',
13
+ 'users',
14
+ 'roles',
15
+ 'departments',
16
+ 'branches',
17
+ 'company_membership',
18
+ 'membership_posting',
19
+ 'company_departments',
20
+ 'company_branches',
21
+ 'shared_resource',
22
+ 'service_account',
23
+ 'stored_file',
24
+ ]),
25
+ identity: Object.freeze([
26
+ 'identity_credential',
27
+ 'session',
28
+ 'refresh_token',
29
+ 'mfa_device',
30
+ 'password_reset_token',
31
+ 'mfa_recovery_code',
32
+ 'email_change_token',
33
+ ]),
34
+ authz: Object.freeze([
35
+ 'permission',
36
+ 'role_permission',
37
+ 'authz_permission_version',
38
+ 'access_bundle',
39
+ 'access_bundle_permission',
40
+ 'record_permission_rule',
41
+ 'record_share',
42
+ 'scope_closure',
43
+ 'service_account_key',
44
+ 'cross_tenant_grant',
45
+ ]),
46
+ audit: Object.freeze(['audit_log']),
47
+ });
48
+ /** Framework stored routines. */
49
+ export const FRAMEWORK_ROUTINES = Object.freeze(['prune_audit']);
50
+ const RESERVED = new Set(Object.values(FRAMEWORK_TABLES).flat());
51
+ /**
52
+ * True when `name` is a framework table or the migration ledger table (case-insensitive: MariaDB
53
+ * table-name case rules vary by platform). `ledgerTable` defaults to `schema_migrations`; a custom
54
+ * ledger name replaces the default.
55
+ */
56
+ export function isReservedFrameworkTable(name, ledgerTable = DEFAULT_MIGRATION_LEDGER_TABLE) {
57
+ const n = name.toLowerCase();
58
+ return RESERVED.has(n) || n === ledgerTable.toLowerCase();
59
+ }
60
+ //# sourceMappingURL=framework-tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-tables.js","sourceRoot":"","sources":["../../src/database/framework-tables.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,8BAA8B,EAAE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able-framework-db, ADR-0037): the single source of the
3
+ * four `<namespace>_{app,identity,authz,audit}` names and the namespaced account defaults.
4
+ * Pure + zero-dep (ADR-0003).
5
+ */
6
+ export type { FrameworkSchemas, FrameworkSchemaNameSet, MigrationSchemasContext, } from './framework-schemas.js';
7
+ export { DEFAULT_FRAMEWORK_DB_NAMESPACE, FRAMEWORK_DB_NAMESPACE_ENV, FRAMEWORK_DB_NAMESPACE_PATTERN, FRAMEWORK_SCHEMA_SUFFIXES, FrameworkSchemaConfigError, frameworkAccountName, resolveFrameworkSchemas, SCHEMA_NAME_PATTERN, assertSchemaName, assertFrameworkSchemaNames, frameworkSchemasForMigration, DEFAULT_MIGRATION_LEDGER_TABLE, MIGRATION_LEDGER_TABLE_PATTERN, resolveMigrationLedgerLocation, LEDGER_DATABASE_NAME_PATTERN, assertLedgerDatabaseName, migrationLedgerCandidates, } from './framework-schemas.js';
8
+ export type { MigrationLedgerLocation } from './framework-schemas.js';
9
+ export { FRAMEWORK_DB_LAYOUT_ENV, FRAMEWORK_DB_NAME_ENV, FRAMEWORK_DB_LAYOUT_ACK_ENV, } from './framework-schemas.js';
10
+ export { FRAMEWORK_TABLES, FRAMEWORK_ROUTINES, isReservedFrameworkTable, } from './framework-tables.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,8BAA8B,EAC9B,yBAAyB,EACzB,0BAA0B,EAC1B,oBAAoB,EACpB,uBAAuB,EAEvB,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,EAC1B,4BAA4B,EAE5B,8BAA8B,EAC9B,8BAA8B,EAC9B,8BAA8B,EAG9B,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Framework database names (configurable-framework-db, ADR-0037): the single source of the
3
+ * four `<namespace>_{app,identity,authz,audit}` names and the namespaced account defaults.
4
+ * Pure + zero-dep (ADR-0003).
5
+ */
6
+ export { DEFAULT_FRAMEWORK_DB_NAMESPACE, FRAMEWORK_DB_NAMESPACE_ENV, FRAMEWORK_DB_NAMESPACE_PATTERN, FRAMEWORK_SCHEMA_SUFFIXES, FrameworkSchemaConfigError, frameworkAccountName, resolveFrameworkSchemas,
7
+ // Phase 4: caller-supplied name checks + the migration fallback helper (append-only).
8
+ SCHEMA_NAME_PATTERN, assertSchemaName, assertFrameworkSchemaNames, frameworkSchemasForMigration,
9
+ // Phase 6: the one migration-ledger location rule (migrate CLI + runtime boot check).
10
+ DEFAULT_MIGRATION_LEDGER_TABLE, MIGRATION_LEDGER_TABLE_PATTERN, resolveMigrationLedgerLocation,
11
+ // G-007 QA P1/P2-3: the boot check's candidate ledger locations and the operator ledger-name
12
+ // check (append-only).
13
+ LEDGER_DATABASE_NAME_PATTERN, assertLedgerDatabaseName, migrationLedgerCandidates, } from './framework-schemas.js';
14
+ export {
15
+ // G-008 single-database layout (spec §5.A, ADR-0041; append-only).
16
+ FRAMEWORK_DB_LAYOUT_ENV, FRAMEWORK_DB_NAME_ENV, FRAMEWORK_DB_LAYOUT_ACK_ENV, } from './framework-schemas.js';
17
+ export { FRAMEWORK_TABLES, FRAMEWORK_ROUTINES, isReservedFrameworkTable, } from './framework-tables.js';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,8BAA8B,EAC9B,yBAAyB,EACzB,0BAA0B,EAC1B,oBAAoB,EACpB,uBAAuB;AACvB,sFAAsF;AACtF,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,EAC1B,4BAA4B;AAC5B,sFAAsF;AACtF,8BAA8B,EAC9B,8BAA8B,EAC9B,8BAA8B;AAC9B,6FAA6F;AAC7F,uBAAuB;AACvB,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO;AACL,mEAAmE;AACnE,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -43,4 +43,5 @@ export * from './secrets/index.js';
43
43
  export * from './metadata/index.js';
44
44
  export * from './admin/index.js';
45
45
  export * from './storage/index.js';
46
+ export * from './database/index.js';
46
47
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -48,4 +48,6 @@ export * from './metadata/index.js';
48
48
  // signatures + the query/command service factories + command-pipeline order.
49
49
  export * from './admin/index.js';
50
50
  export * from './storage/index.js';
51
+ // Framework database names (configurable-framework-db, ADR-0037) — append-only.
52
+ export * from './database/index.js';
51
53
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAEnC,gFAAgF;AAChF,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ /**
3
+ * Framework database names (configurable-framework-db, spec §5.A, §10, §13; ADR-0037).
4
+ *
5
+ * The single source of the four framework database names. `SHIELD_DB_NAMESPACE` renames all
6
+ * four together (`beta` ⇒ `beta_app`, `beta_identity`, `beta_authz`, `beta_audit`); unset keeps
7
+ * today's `shield_*` names. Pure and zero-dep (ADR-0003): the caller passes an env-like record,
8
+ * nothing here reads `process.env`.
9
+ *
10
+ * SECURITY: fail closed (Shield #1) — a set-but-empty or non-matching namespace throws; a
11
+ * failure never returns a partial set. Names reach SQL only after this validation, and the
12
+ * pattern admits no quote, backtick, dot or whitespace.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LEDGER_DATABASE_NAME_PATTERN = exports.MIGRATION_LEDGER_TABLE_PATTERN = exports.DEFAULT_MIGRATION_LEDGER_TABLE = exports.SCHEMA_NAME_PATTERN = exports.FrameworkSchemaConfigError = exports.FRAMEWORK_DB_LAYOUT_ACK_ENV = exports.FRAMEWORK_DB_NAME_ENV = exports.FRAMEWORK_DB_LAYOUT_ENV = exports.FRAMEWORK_SCHEMA_SUFFIXES = exports.FRAMEWORK_DB_NAMESPACE_PATTERN = exports.DEFAULT_FRAMEWORK_DB_NAMESPACE = exports.FRAMEWORK_DB_NAMESPACE_ENV = void 0;
16
+ exports.resolveFrameworkSchemas = resolveFrameworkSchemas;
17
+ exports.frameworkAccountName = frameworkAccountName;
18
+ exports.assertSchemaName = assertSchemaName;
19
+ exports.assertFrameworkSchemaNames = assertFrameworkSchemaNames;
20
+ exports.frameworkSchemasForMigration = frameworkSchemasForMigration;
21
+ exports.assertLedgerDatabaseName = assertLedgerDatabaseName;
22
+ exports.resolveMigrationLedgerLocation = resolveMigrationLedgerLocation;
23
+ exports.migrationLedgerCandidates = migrationLedgerCandidates;
24
+ /** The env variable that selects the namespace. */
25
+ exports.FRAMEWORK_DB_NAMESPACE_ENV = 'SHIELD_DB_NAMESPACE';
26
+ /** The namespace used when `SHIELD_DB_NAMESPACE` is unset (today's names). */
27
+ exports.DEFAULT_FRAMEWORK_DB_NAMESPACE = 'shield';
28
+ /**
29
+ * Allowed namespace. `<ns>_identity`, the longest name, stays within MariaDB's 64-character
30
+ * identifier limit (55 + 9).
31
+ */
32
+ // Letters and digits only (spec v3): `_` is a one-character wildcard in MariaDB database-level
33
+ // grants, so a namespace containing `_` could make one environment's grants match another's
34
+ // databases (`team_a_app` also matches `team1a_app`).
35
+ exports.FRAMEWORK_DB_NAMESPACE_PATTERN = /^[a-z][a-z0-9]{0,54}$/;
36
+ /** The fixed database suffixes, one per framework module. */
37
+ exports.FRAMEWORK_SCHEMA_SUFFIXES = Object.freeze({
38
+ app: '_app',
39
+ identity: '_identity',
40
+ authz: '_authz',
41
+ audit: '_audit',
42
+ });
43
+ /** Selects the layout: `four` (default, unset) or `single` (single-database-layout spec §5.A, ADR-0041). */
44
+ exports.FRAMEWORK_DB_LAYOUT_ENV = 'SHIELD_DB_LAYOUT';
45
+ /** The single database name when `SHIELD_DB_LAYOUT=single`. Validated by {@link SCHEMA_NAME_PATTERN}. */
46
+ exports.FRAMEWORK_DB_NAME_ENV = 'SHIELD_DB_NAME';
47
+ /** Must be exactly `1` for the single layout: the operator accepts the reduced isolation. */
48
+ exports.FRAMEWORK_DB_LAYOUT_ACK_ENV = 'SHIELD_DB_LAYOUT_ACK_REDUCED_ISOLATION';
49
+ /** Thrown for an invalid framework database configuration. Never carries a secret. */
50
+ class FrameworkSchemaConfigError extends Error {
51
+ constructor(message) {
52
+ super(message);
53
+ this.name = 'FrameworkSchemaConfigError';
54
+ }
55
+ }
56
+ exports.FrameworkSchemaConfigError = FrameworkSchemaConfigError;
57
+ function namesFor(namespace, isDefault) {
58
+ return Object.freeze({
59
+ namespace,
60
+ app: `${namespace}${exports.FRAMEWORK_SCHEMA_SUFFIXES.app}`,
61
+ identity: `${namespace}${exports.FRAMEWORK_SCHEMA_SUFFIXES.identity}`,
62
+ authz: `${namespace}${exports.FRAMEWORK_SCHEMA_SUFFIXES.authz}`,
63
+ audit: `${namespace}${exports.FRAMEWORK_SCHEMA_SUFFIXES.audit}`,
64
+ isDefault,
65
+ });
66
+ }
67
+ // Single layout (single-database-layout spec §5.A): fail closed; values are never echoed.
68
+ function resolveSingle(env) {
69
+ const name = env[exports.FRAMEWORK_DB_NAME_ENV];
70
+ if (typeof name !== 'string' || !exports.SCHEMA_NAME_PATTERN.test(name)) {
71
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_NAME_ENV} is required and must be a valid database name when ` +
72
+ `${exports.FRAMEWORK_DB_LAYOUT_ENV}=single; expected ${exports.SCHEMA_NAME_PATTERN.source}`);
73
+ }
74
+ if (env[exports.FRAMEWORK_DB_LAYOUT_ACK_ENV] !== '1') {
75
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_LAYOUT_ACK_ENV}=1 is required when ${exports.FRAMEWORK_DB_LAYOUT_ENV}=single ` +
76
+ '(the single database layout reduces isolation; ADR-0041)');
77
+ }
78
+ if (env[exports.FRAMEWORK_DB_NAMESPACE_ENV] !== undefined) {
79
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_NAMESPACE_ENV} must not be set when ${exports.FRAMEWORK_DB_LAYOUT_ENV}=single; ` +
80
+ `use ${exports.FRAMEWORK_DB_NAME_ENV}`);
81
+ }
82
+ return Object.freeze({
83
+ namespace: name,
84
+ app: name,
85
+ identity: name,
86
+ authz: name,
87
+ audit: name,
88
+ isDefault: false,
89
+ layout: 'single',
90
+ });
91
+ }
92
+ /**
93
+ * Resolve the four framework database names from an env-like record.
94
+ * @throws FrameworkSchemaConfigError when `SHIELD_DB_NAMESPACE` is set but empty or invalid.
95
+ */
96
+ function resolveFrameworkSchemas(env) {
97
+ const layout = env[exports.FRAMEWORK_DB_LAYOUT_ENV];
98
+ if (layout !== undefined && layout !== 'four' && layout !== 'single') {
99
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_LAYOUT_ENV} must be "four" or "single" (unset for the default "four")`);
100
+ }
101
+ if (layout === 'single')
102
+ return resolveSingle(env);
103
+ const raw = env[exports.FRAMEWORK_DB_NAMESPACE_ENV];
104
+ if (raw === undefined)
105
+ return namesFor(exports.DEFAULT_FRAMEWORK_DB_NAMESPACE, true);
106
+ if (!exports.FRAMEWORK_DB_NAMESPACE_PATTERN.test(raw)) {
107
+ // The value is not echoed: it is config, not a secret, but the message stays a fixed shape.
108
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_NAMESPACE_ENV} is set but ${raw === '' ? 'empty' : 'invalid'}; ` +
109
+ `expected ${exports.FRAMEWORK_DB_NAMESPACE_PATTERN.source} (unset it for the default "${exports.DEFAULT_FRAMEWORK_DB_NAMESPACE}")`);
110
+ }
111
+ // An explicit default namespace is the default: same names AND the same rules (ledger, old
112
+ // migrate fallback), so `SHIELD_DB_NAMESPACE=shield` never behaves differently from unset.
113
+ return namesFor(raw, raw === exports.DEFAULT_FRAMEWORK_DB_NAMESPACE);
114
+ }
115
+ /**
116
+ * The DB account name for a matrix account role under a namespace: `<ns>_<role>`
117
+ * (`frameworkAccountName('beta', 'core')` ⇒ `beta_core`). Roles are the matrix account names
118
+ * without the `shield_` prefix (`core`, `migrate`, `audit_ops`, ...).
119
+ */
120
+ function frameworkAccountName(namespace, role) {
121
+ return `${namespace}_${role}`;
122
+ }
123
+ /**
124
+ * A database name a caller may hand to framework SQL (`opts.schema`, `forRoot({ schemas })`):
125
+ * lower-case letters, digits and `_`, 1..64 characters (MariaDB's identifier limit). Names come
126
+ * from the resolver or from operator config, both lower-case (MariaDB database names are
127
+ * case-sensitive on Linux, so a mixed-case name is refused rather than guessed). It admits no
128
+ * backtick, quote, dot, whitespace or `;`, so a name that passes can be backtick-quoted safely.
129
+ */
130
+ exports.SCHEMA_NAME_PATTERN = /^[a-z0-9_]{1,64}$/;
131
+ /**
132
+ * Check a caller-supplied database name before it reaches SQL (configurable-framework-db,
133
+ * spec §11). Returns the name unchanged.
134
+ * @param label names the setting in the error (e.g. `opts.schema`); the value is never echoed.
135
+ * @throws FrameworkSchemaConfigError when the name is not a string matching
136
+ * {@link SCHEMA_NAME_PATTERN}.
137
+ */
138
+ function assertSchemaName(name, label) {
139
+ if (typeof name !== 'string' || !exports.SCHEMA_NAME_PATTERN.test(name)) {
140
+ throw new FrameworkSchemaConfigError(`${label} is not a valid database name; expected ${exports.SCHEMA_NAME_PATTERN.source}`);
141
+ }
142
+ return name;
143
+ }
144
+ /**
145
+ * Check all four names of a caller-supplied set (`forRoot({ schemas })`, a store's `schemas`
146
+ * argument, `ctx.schemas`) with {@link assertSchemaName}. Returns the same object.
147
+ * @throws FrameworkSchemaConfigError naming `<label>.<field>` for the first bad name.
148
+ */
149
+ function assertFrameworkSchemaNames(schemas, label) {
150
+ if (typeof schemas !== 'object' || schemas === null) {
151
+ throw new FrameworkSchemaConfigError(`${label} must be an object with app, identity, authz and audit database names`);
152
+ }
153
+ for (const key of ['app', 'identity', 'authz', 'audit']) {
154
+ assertSchemaName(schemas[key], `${label}.${key}`);
155
+ }
156
+ // Four equal names are one database: only the single layout may say so (spec §5.A, ADR-0041).
157
+ const single = schemas.layout === 'single';
158
+ const allEqual = schemas.app === schemas.identity &&
159
+ schemas.app === schemas.authz &&
160
+ schemas.app === schemas.audit;
161
+ if (single !== allEqual) {
162
+ throw new FrameworkSchemaConfigError(`${label} names must be four distinct databases, or one database with layout "single"`);
163
+ }
164
+ return schemas;
165
+ }
166
+ /**
167
+ * The framework database names for a framework migration's `up`/`down` (spec v2 §5.H, decided
168
+ * Q2). `@astram/guard` and `@astram/identity` do not depend on `@astram/migrate`, so their
169
+ * migrations may run under an older CLI that passes no `ctx.schemas`:
170
+ * - `ctx.schemas` present (current `@astram/migrate`) ⇒ those names, validated;
171
+ * - absent and `SHIELD_DB_NAMESPACE` unset (or `shield`) ⇒ the default `shield_*` names (today's
172
+ * behaviour);
173
+ * - absent and `SHIELD_DB_NAMESPACE` set to any other value ⇒ throws before any DDL, telling the
174
+ * operator to upgrade `@astram/migrate`.
175
+ *
176
+ * Usage in a migration file: `const s = frameworkSchemasForMigration(ctx, process.env);`.
177
+ * Pure: the caller passes the env.
178
+ * @throws FrameworkSchemaConfigError as above, or for an invalid name in `ctx.schemas`.
179
+ */
180
+ function frameworkSchemasForMigration(ctx, env) {
181
+ const given = ctx?.schemas;
182
+ // An older migrate (pinned core ignores the layout) may pass four-layout names while the env
183
+ // asks for the single layout: refuse before any DDL (AC-11).
184
+ if (given !== undefined &&
185
+ !(env[exports.FRAMEWORK_DB_LAYOUT_ENV] === 'single' && given.layout !== 'single')) {
186
+ return assertFrameworkSchemaNames(given, 'ctx.schemas');
187
+ }
188
+ if (env[exports.FRAMEWORK_DB_LAYOUT_ENV] === 'single') {
189
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_LAYOUT_ENV}=single but this @astram/migrate does not pass ctx.schemas; ` +
190
+ 'upgrade @astram/migrate');
191
+ }
192
+ const ns = env[exports.FRAMEWORK_DB_NAMESPACE_ENV];
193
+ if (ns !== undefined && ns !== exports.DEFAULT_FRAMEWORK_DB_NAMESPACE) {
194
+ throw new FrameworkSchemaConfigError(`${exports.FRAMEWORK_DB_NAMESPACE_ENV} is set but this @astram/migrate does not pass ctx.schemas; ` +
195
+ 'upgrade @astram/migrate');
196
+ }
197
+ return namesFor(exports.DEFAULT_FRAMEWORK_DB_NAMESPACE, true);
198
+ }
199
+ /** The `@astram/migrate` ledger table when `APP_MIGRATION_TABLE` is unset. */
200
+ exports.DEFAULT_MIGRATION_LEDGER_TABLE = 'schema_migrations';
201
+ /** A ledger table name: a plain identifier, safe to backtick-quote. */
202
+ exports.MIGRATION_LEDGER_TABLE_PATTERN = /^[A-Za-z0-9_$]{1,64}$/;
203
+ /**
204
+ * An operator-supplied ledger database name (`DDL_DB_NAME`, or a migrate job's `APP_DB_NAME` in
205
+ * default mode): any plain MariaDB identifier, mixed case included, so a name that worked with
206
+ * earlier `@astram/migrate` releases keeps working. Letters, digits and `_` only, 1..64: no
207
+ * backtick, quote, dot, whitespace or `;`, so it is safe to backtick-quote or single-quote.
208
+ * Resolver-produced names stay on the stricter {@link SCHEMA_NAME_PATTERN}.
209
+ */
210
+ exports.LEDGER_DATABASE_NAME_PATTERN = /^[A-Za-z0-9_]{1,64}$/;
211
+ /**
212
+ * Check an operator-supplied ledger database name before it reaches SQL. Returns it unchanged.
213
+ * @param label names the setting in the error (e.g. `DDL_DB_NAME`); the value is never echoed.
214
+ * @throws FrameworkSchemaConfigError when the name does not match
215
+ * {@link LEDGER_DATABASE_NAME_PATTERN}.
216
+ */
217
+ function assertLedgerDatabaseName(name, label) {
218
+ if (typeof name !== 'string' || !exports.LEDGER_DATABASE_NAME_PATTERN.test(name)) {
219
+ throw new FrameworkSchemaConfigError(`${label} is not a valid database name; expected ${exports.LEDGER_DATABASE_NAME_PATTERN.source}`);
220
+ }
221
+ return name;
222
+ }
223
+ function ledgerTable(env) {
224
+ const table = env.APP_MIGRATION_TABLE ?? exports.DEFAULT_MIGRATION_LEDGER_TABLE;
225
+ if (!exports.MIGRATION_LEDGER_TABLE_PATTERN.test(table)) {
226
+ throw new FrameworkSchemaConfigError(`APP_MIGRATION_TABLE is not a valid table name; expected ${exports.MIGRATION_LEDGER_TABLE_PATTERN.source}`);
227
+ }
228
+ return table;
229
+ }
230
+ /**
231
+ * The ledger-location rule of the migrate CLI (configurable-framework-db spec 5.G):
232
+ * - namespace set ⇒ always `<ns>_app`; a `DDL_DB_NAME` other than `<ns>_app` throws;
233
+ * - namespace unset (or `shield`) ⇒ `DDL_DB_NAME`, else the default app database. (The CLI adds
234
+ * its released fallback to the job's `APP_DB_NAME` before `shield_app`.)
235
+ * Table: `APP_MIGRATION_TABLE`, else `schema_migrations`. The runtime boot check does not use this
236
+ * single location: it tries {@link migrationLedgerCandidates}. Pure: the caller passes the env.
237
+ * @throws FrameworkSchemaConfigError naming the variable on a conflicting or invalid name.
238
+ */
239
+ function resolveMigrationLedgerLocation(schemas, env) {
240
+ const ddl = env.DDL_DB_NAME;
241
+ let database;
242
+ if (schemas.layout === 'single') {
243
+ if (ddl !== undefined && ddl !== schemas.app) {
244
+ throw new FrameworkSchemaConfigError(`DDL_DB_NAME must be ${schemas.app} or unset when ${exports.FRAMEWORK_DB_LAYOUT_ENV}=single ` +
245
+ `(${exports.FRAMEWORK_DB_NAME_ENV}): the migration ledger lives in ${schemas.app} ` +
246
+ '(single-database-layout spec §5.A).');
247
+ }
248
+ database = schemas.app;
249
+ }
250
+ else if (schemas.isDefault) {
251
+ database =
252
+ ddl === undefined
253
+ ? assertSchemaName(schemas.app, 'ledger')
254
+ : assertLedgerDatabaseName(ddl, 'DDL_DB_NAME');
255
+ }
256
+ else {
257
+ if (ddl !== undefined && ddl !== schemas.app) {
258
+ throw new FrameworkSchemaConfigError(`DDL_DB_NAME must be ${schemas.app} or unset when ` +
259
+ `${exports.FRAMEWORK_DB_NAMESPACE_ENV}=${schemas.namespace}: the migration ledger lives in ` +
260
+ `${schemas.app} (spec 5.G).`);
261
+ }
262
+ database = schemas.app;
263
+ }
264
+ return { database, table: ledgerTable(env) };
265
+ }
266
+ /**
267
+ * Where the runtime boot check looks for the ledger, in order (G-007 QA P1). A standard scaffold
268
+ * runs `astram-migrate` with the server's env, so in default mode migrate writes the ledger to
269
+ * `DDL_DB_NAME`, else the job's `APP_DB_NAME`, else `shield_app`; the boot check cannot know
270
+ * which env the migrate job had, so it tries each:
271
+ * - namespace set ⇒ only `<ns>_app` (as {@link resolveMigrationLedgerLocation}; `APP_DB_NAME`
272
+ * is ignored, a conflicting `DDL_DB_NAME` throws);
273
+ * - namespace unset (or `shield`) ⇒ `DDL_DB_NAME`, the runtime `APP_DB_NAME`, then the default
274
+ * app database; unset or blank values skipped, duplicates dropped.
275
+ * The caller uses the first location whose ledger table exists and must still find every shipped
276
+ * id there; when none exists it fails closed naming every location. Pure: the caller passes the
277
+ * env. Returns a frozen, non-empty list.
278
+ * @throws FrameworkSchemaConfigError naming the variable on a conflicting or invalid name.
279
+ */
280
+ function migrationLedgerCandidates(schemas, env) {
281
+ if (!schemas.isDefault) {
282
+ return Object.freeze([Object.freeze(resolveMigrationLedgerLocation(schemas, env))]);
283
+ }
284
+ const table = ledgerTable(env);
285
+ const databases = [];
286
+ for (const key of ['DDL_DB_NAME', 'APP_DB_NAME']) {
287
+ const raw = env[key];
288
+ if (raw === undefined || raw.trim() === '')
289
+ continue;
290
+ databases.push(assertLedgerDatabaseName(raw.trim(), key));
291
+ }
292
+ databases.push(assertSchemaName(schemas.app, 'ledger'));
293
+ return Object.freeze([...new Set(databases)].map((database) => Object.freeze({ database, table })));
294
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FRAMEWORK_ROUTINES = exports.FRAMEWORK_TABLES = void 0;
4
+ exports.isReservedFrameworkTable = isReservedFrameworkTable;
5
+ /**
6
+ * Framework-owned tables and routines per module (single-database-layout spec §5.A, ADR-0041).
7
+ *
8
+ * In the single layout all four modules share one database, so a table name must not collide
9
+ * with a framework table (or the migration ledger). This list is the one published source.
10
+ * Pure and zero-dep (ADR-0003).
11
+ */
12
+ const framework_schemas_js_1 = require("./framework-schemas.js");
13
+ /** Framework tables, keyed by the module whose database holds them in the four layout. Deeply frozen. */
14
+ exports.FRAMEWORK_TABLES = Object.freeze({
15
+ app: Object.freeze([
16
+ 'companies',
17
+ 'users',
18
+ 'roles',
19
+ 'departments',
20
+ 'branches',
21
+ 'company_membership',
22
+ 'membership_posting',
23
+ 'company_departments',
24
+ 'company_branches',
25
+ 'shared_resource',
26
+ 'service_account',
27
+ 'stored_file',
28
+ ]),
29
+ identity: Object.freeze([
30
+ 'identity_credential',
31
+ 'session',
32
+ 'refresh_token',
33
+ 'mfa_device',
34
+ 'password_reset_token',
35
+ 'mfa_recovery_code',
36
+ 'email_change_token',
37
+ ]),
38
+ authz: Object.freeze([
39
+ 'permission',
40
+ 'role_permission',
41
+ 'authz_permission_version',
42
+ 'access_bundle',
43
+ 'access_bundle_permission',
44
+ 'record_permission_rule',
45
+ 'record_share',
46
+ 'scope_closure',
47
+ 'service_account_key',
48
+ 'cross_tenant_grant',
49
+ ]),
50
+ audit: Object.freeze(['audit_log']),
51
+ });
52
+ /** Framework stored routines. */
53
+ exports.FRAMEWORK_ROUTINES = Object.freeze(['prune_audit']);
54
+ const RESERVED = new Set(Object.values(exports.FRAMEWORK_TABLES).flat());
55
+ /**
56
+ * True when `name` is a framework table or the migration ledger table (case-insensitive: MariaDB
57
+ * table-name case rules vary by platform). `ledgerTable` defaults to `schema_migrations`; a custom
58
+ * ledger name replaces the default.
59
+ */
60
+ function isReservedFrameworkTable(name, ledgerTable = framework_schemas_js_1.DEFAULT_MIGRATION_LEDGER_TABLE) {
61
+ const n = name.toLowerCase();
62
+ return RESERVED.has(n) || n === ledgerTable.toLowerCase();
63
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Framework database names (configurable-framework-db, ADR-0037): the single source of the
4
+ * four `<namespace>_{app,identity,authz,audit}` names and the namespaced account defaults.
5
+ * Pure + zero-dep (ADR-0003).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.isReservedFrameworkTable = exports.FRAMEWORK_ROUTINES = exports.FRAMEWORK_TABLES = exports.FRAMEWORK_DB_LAYOUT_ACK_ENV = exports.FRAMEWORK_DB_NAME_ENV = exports.FRAMEWORK_DB_LAYOUT_ENV = exports.migrationLedgerCandidates = exports.assertLedgerDatabaseName = exports.LEDGER_DATABASE_NAME_PATTERN = exports.resolveMigrationLedgerLocation = exports.MIGRATION_LEDGER_TABLE_PATTERN = exports.DEFAULT_MIGRATION_LEDGER_TABLE = exports.frameworkSchemasForMigration = exports.assertFrameworkSchemaNames = exports.assertSchemaName = exports.SCHEMA_NAME_PATTERN = exports.resolveFrameworkSchemas = exports.frameworkAccountName = exports.FrameworkSchemaConfigError = exports.FRAMEWORK_SCHEMA_SUFFIXES = exports.FRAMEWORK_DB_NAMESPACE_PATTERN = exports.FRAMEWORK_DB_NAMESPACE_ENV = exports.DEFAULT_FRAMEWORK_DB_NAMESPACE = void 0;
9
+ var framework_schemas_js_1 = require("./framework-schemas.js");
10
+ Object.defineProperty(exports, "DEFAULT_FRAMEWORK_DB_NAMESPACE", { enumerable: true, get: function () { return framework_schemas_js_1.DEFAULT_FRAMEWORK_DB_NAMESPACE; } });
11
+ Object.defineProperty(exports, "FRAMEWORK_DB_NAMESPACE_ENV", { enumerable: true, get: function () { return framework_schemas_js_1.FRAMEWORK_DB_NAMESPACE_ENV; } });
12
+ Object.defineProperty(exports, "FRAMEWORK_DB_NAMESPACE_PATTERN", { enumerable: true, get: function () { return framework_schemas_js_1.FRAMEWORK_DB_NAMESPACE_PATTERN; } });
13
+ Object.defineProperty(exports, "FRAMEWORK_SCHEMA_SUFFIXES", { enumerable: true, get: function () { return framework_schemas_js_1.FRAMEWORK_SCHEMA_SUFFIXES; } });
14
+ Object.defineProperty(exports, "FrameworkSchemaConfigError", { enumerable: true, get: function () { return framework_schemas_js_1.FrameworkSchemaConfigError; } });
15
+ Object.defineProperty(exports, "frameworkAccountName", { enumerable: true, get: function () { return framework_schemas_js_1.frameworkAccountName; } });
16
+ Object.defineProperty(exports, "resolveFrameworkSchemas", { enumerable: true, get: function () { return framework_schemas_js_1.resolveFrameworkSchemas; } });
17
+ // Phase 4: caller-supplied name checks + the migration fallback helper (append-only).
18
+ Object.defineProperty(exports, "SCHEMA_NAME_PATTERN", { enumerable: true, get: function () { return framework_schemas_js_1.SCHEMA_NAME_PATTERN; } });
19
+ Object.defineProperty(exports, "assertSchemaName", { enumerable: true, get: function () { return framework_schemas_js_1.assertSchemaName; } });
20
+ Object.defineProperty(exports, "assertFrameworkSchemaNames", { enumerable: true, get: function () { return framework_schemas_js_1.assertFrameworkSchemaNames; } });
21
+ Object.defineProperty(exports, "frameworkSchemasForMigration", { enumerable: true, get: function () { return framework_schemas_js_1.frameworkSchemasForMigration; } });
22
+ // Phase 6: the one migration-ledger location rule (migrate CLI + runtime boot check).
23
+ Object.defineProperty(exports, "DEFAULT_MIGRATION_LEDGER_TABLE", { enumerable: true, get: function () { return framework_schemas_js_1.DEFAULT_MIGRATION_LEDGER_TABLE; } });
24
+ Object.defineProperty(exports, "MIGRATION_LEDGER_TABLE_PATTERN", { enumerable: true, get: function () { return framework_schemas_js_1.MIGRATION_LEDGER_TABLE_PATTERN; } });
25
+ Object.defineProperty(exports, "resolveMigrationLedgerLocation", { enumerable: true, get: function () { return framework_schemas_js_1.resolveMigrationLedgerLocation; } });
26
+ // G-007 QA P1/P2-3: the boot check's candidate ledger locations and the operator ledger-name
27
+ // check (append-only).
28
+ Object.defineProperty(exports, "LEDGER_DATABASE_NAME_PATTERN", { enumerable: true, get: function () { return framework_schemas_js_1.LEDGER_DATABASE_NAME_PATTERN; } });
29
+ Object.defineProperty(exports, "assertLedgerDatabaseName", { enumerable: true, get: function () { return framework_schemas_js_1.assertLedgerDatabaseName; } });
30
+ Object.defineProperty(exports, "migrationLedgerCandidates", { enumerable: true, get: function () { return framework_schemas_js_1.migrationLedgerCandidates; } });
31
+ var framework_schemas_js_2 = require("./framework-schemas.js");
32
+ // G-008 single-database layout (spec §5.A, ADR-0041; append-only).
33
+ Object.defineProperty(exports, "FRAMEWORK_DB_LAYOUT_ENV", { enumerable: true, get: function () { return framework_schemas_js_2.FRAMEWORK_DB_LAYOUT_ENV; } });
34
+ Object.defineProperty(exports, "FRAMEWORK_DB_NAME_ENV", { enumerable: true, get: function () { return framework_schemas_js_2.FRAMEWORK_DB_NAME_ENV; } });
35
+ Object.defineProperty(exports, "FRAMEWORK_DB_LAYOUT_ACK_ENV", { enumerable: true, get: function () { return framework_schemas_js_2.FRAMEWORK_DB_LAYOUT_ACK_ENV; } });
36
+ var framework_tables_js_1 = require("./framework-tables.js");
37
+ Object.defineProperty(exports, "FRAMEWORK_TABLES", { enumerable: true, get: function () { return framework_tables_js_1.FRAMEWORK_TABLES; } });
38
+ Object.defineProperty(exports, "FRAMEWORK_ROUTINES", { enumerable: true, get: function () { return framework_tables_js_1.FRAMEWORK_ROUTINES; } });
39
+ Object.defineProperty(exports, "isReservedFrameworkTable", { enumerable: true, get: function () { return framework_tables_js_1.isReservedFrameworkTable; } });
package/dist-cjs/index.js CHANGED
@@ -64,3 +64,5 @@ __exportStar(require("./metadata/index.js"), exports);
64
64
  // signatures + the query/command service factories + command-pipeline order.
65
65
  __exportStar(require("./admin/index.js"), exports);
66
66
  __exportStar(require("./storage/index.js"), exports);
67
+ // Framework database names (configurable-framework-db, ADR-0037) — append-only.
68
+ __exportStar(require("./database/index.js"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astram/core",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "description": "Astram framework — sealed security core (Identity, Authentication, Session, Risk, Authorization, Audit). ZERO framework deps — the portable decision brain (ADR-0003). The frozen public contract consumers build against; installed, not edited (ADR-0023).",
6
6
  "type": "module",