@gate-forge/pack-sqlalchemy 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -5
- package/dist/detector.d.ts +19 -2
- package/dist/detector.d.ts.map +1 -1
- package/dist/detector.js +42 -9
- package/dist/detector.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/singleton.d.ts +103 -0
- package/dist/singleton.d.ts.map +1 -0
- package/dist/singleton.js +146 -0
- package/dist/singleton.js.map +1 -0
- package/dist/tenancy.d.ts +18 -0
- package/dist/tenancy.d.ts.map +1 -0
- package/dist/tenancy.js +93 -0
- package/dist/tenancy.js.map +1 -0
- package/dist/test-paths.d.ts +40 -0
- package/dist/test-paths.d.ts.map +1 -0
- package/dist/test-paths.js +49 -0
- package/dist/test-paths.js.map +1 -0
- package/package.json +7 -4
- package/python/gateforge_sqlalchemy_detector/__init__.py +12 -2
- package/python/gateforge_sqlalchemy_detector/scan.py +343 -30
- package/python/gateforge_sqlalchemy_detector/__pycache__/__init__.cpython-314.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/__main__.cpython-314.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/scan.cpython-314.pyc +0 -0
package/README.md
CHANGED
|
@@ -22,18 +22,41 @@ with `ast.parse` and reports:
|
|
|
22
22
|
| Source construct | Emitted as |
|
|
23
23
|
| --- | --- |
|
|
24
24
|
| Declarative class with literal `__tablename__` (legacy `declarative_base()` and 2.0 `DeclarativeBase` styles) | `sqlalchemy.table` resource + class symbol |
|
|
25
|
+
| SQLModel class (`class X(SQLModel, table=True)` or a shared `SQLModel` base) with no `__tablename__` | `sqlalchemy.table` resource named by SQLModel's own rule (the lowercased class name, provenance `sqlmodel-class-name`) + class symbol |
|
|
26
|
+
| SQLModel class WITHOUT `table=True` (a plain class, or `table=False`) | nothing — it is not a table |
|
|
25
27
|
| Direct `Table("name", ...)` call | `sqlalchemy.table` resource (provenance `table-call-first-arg`) |
|
|
26
28
|
| Abstract base (`__abstract__ = True`) or `DeclarativeBase` subclass with no table facts | class symbol only (`abstract: true` / base); never a business resource |
|
|
27
|
-
| Class whose tablename is a decorated function, f-string, call, name ref, or
|
|
29
|
+
| Class whose tablename is a decorated function, f-string, call, name ref, or `table=True` on a non-SQLModel base | class symbol with `tablenameUnresolved: true` + typed `unresolved` entry |
|
|
28
30
|
| Class with bases but no literal tablename anywhere | class symbol + `no_tablename_source` unresolved entry (the graph resolves through its repo-wide symbol table when a base carries a literal — same-file AND cross-file) |
|
|
29
31
|
| Plain classes (mixins, no bases, no table facts) | nothing |
|
|
30
32
|
| Malformed Python file | `PARSE_ERROR` finding with a line number; the file contributes no resources (GF-19) |
|
|
33
|
+
| Class declared in a file under a test directory (`test/`, `tests/`) | nothing — fixtures are not business surface (below) |
|
|
34
|
+
|
|
35
|
+
### Test directories are not business surface
|
|
36
|
+
|
|
37
|
+
A path is test fixture surface when any of its **directory** segments is
|
|
38
|
+
exactly `test` or `tests` (case-insensitive; `src/test-paths.ts`, mirrored
|
|
39
|
+
in the python detector). Files there are still parsed and still reported in
|
|
40
|
+
`scannedPaths` — the coverage evidence stays honest — but they contribute no
|
|
41
|
+
resource, no unresolved entry, no signal and no duplicate finding to the
|
|
42
|
+
graph.
|
|
43
|
+
|
|
44
|
+
The why is a real adoption blocker: a pytest module that re-declares a
|
|
45
|
+
table on its own `Base` to build rows without touching the application's
|
|
46
|
+
metadata (`__tablename__ = "accounts"` next to the real
|
|
47
|
+
backend/models/account.py) used to enter the graph as a second business
|
|
48
|
+
resource. The real table then collided with its own fixture, stayed
|
|
49
|
+
plane-unresolved and blocked the gate with no honest answer. Excluding test
|
|
50
|
+
directories is not a special case for any one repository — it is the same
|
|
51
|
+
rule `gateforge init` already applied when it refused to infer a business
|
|
52
|
+
plane for a fixture table, now applied to the graph as well.
|
|
31
53
|
|
|
32
54
|
### Detector vocabulary
|
|
33
55
|
|
|
34
56
|
- **Business table resource** — `kind: "sqlalchemy.table"`, identity in
|
|
35
57
|
`attributes.resourceName`, plus `classQname`, `scope`, `tableName`,
|
|
36
|
-
`tablenameProvenance` (`literal` | `table-call-first-arg`
|
|
58
|
+
`tablenameProvenance` (`literal` | `table-call-first-arg` |
|
|
59
|
+
`sqlmodel-class-name`),
|
|
37
60
|
`hasTableArgs`/`tableArgsSchema` (literal `schema` from
|
|
38
61
|
`__table_args__`), `tableKeywordTrue`, `abstract`, `baseNames`.
|
|
39
62
|
- **Class-symbol resource** — `kind: "gateforge.class"` with the graph's
|
|
@@ -43,9 +66,9 @@ with `ast.parse` and reports:
|
|
|
43
66
|
- **Unresolved entries** — `{code, detail, location}` at the class
|
|
44
67
|
statement; codes: `computed_tablename` (decorator count + return
|
|
45
68
|
expression kind retained in full, GF-02), `table_name_derived_runtime`
|
|
46
|
-
(`table=True`), `no_tablename_source`. The graph
|
|
47
|
-
resolves and synthesizes
|
|
48
|
-
cannot.
|
|
69
|
+
(`table=True` on a non-SQLModel base), `no_tablename_source`. The graph
|
|
70
|
+
retires an entry it resolves and synthesizes
|
|
71
|
+
`inherited_tablename_unresolved` when it cannot.
|
|
49
72
|
- **Findings** — `DUPLICATE_TABLE_NAME` (GF-20, **base-qualified**:
|
|
50
73
|
a same-name group is flagged unless every pair provably sits on a
|
|
51
74
|
different declarative Base root — separate `MetaData` at runtime — so
|
|
@@ -246,6 +269,76 @@ instead of scanning with partial trust). Precedence: the programmatic
|
|
|
246
269
|
explicit `planesConfig` option overrides the document; the default
|
|
247
270
|
document path can be moved with `planesConfigPath`.
|
|
248
271
|
|
|
272
|
+
## Per-tenant singletons
|
|
273
|
+
|
|
274
|
+
A table whose UNIQUE constraint — or whose UNIQUE **index** — is written
|
|
275
|
+
over the tenancy scope and NOTHING ELSE admits at most ONE row per tenant.
|
|
276
|
+
A `create` of such a resource is therefore provable only on a brand-new
|
|
277
|
+
tenant, while the witness's adapter reads use one process-global login: the
|
|
278
|
+
create reads as "the fixed tenant already has that row". The pack reports
|
|
279
|
+
that as an ADDITIVE fact and never as a verdict:
|
|
280
|
+
|
|
281
|
+
- `attributes.uniqueConstraints` — every declared
|
|
282
|
+
`UniqueConstraint("a", "b")`, `Index("ix", "a", "b", unique=True)`, and
|
|
283
|
+
column-level `unique=True`, as `{name, kind, columns}` (`kind` is
|
|
284
|
+
`constraint` | `index` | `column`; `name` is `null` when unnamed). The
|
|
285
|
+
attribute is **absent** when the table declares no unique constraint, and
|
|
286
|
+
a computed column expression or a non-literal `unique` flag is never
|
|
287
|
+
guessed.
|
|
288
|
+
- `attributes.singletonPerTenant` — `{constraint, tenantColumn,
|
|
289
|
+
scopeColumns, columns}`, minted only when BOTH facts are provable: the
|
|
290
|
+
table's plane evidence is `tenant` AND one declared unique constraint
|
|
291
|
+
names tenancy-scope columns ONLY (`TENANT_SCOPE_COLUMNS`: `tenant_id`,
|
|
292
|
+
`tenant`, `tenantId`, `tenant_uuid`, `tenant_key`). `scopeColumns` lists
|
|
293
|
+
the recognized scope columns of that constraint in written order and
|
|
294
|
+
`tenantColumn` is the first of them. The first qualifying constraint in
|
|
295
|
+
written order is the one reported; every one of them says the same.
|
|
296
|
+
|
|
297
|
+
"Scope and nothing else" is the rule. A constraint that merely CONTAINS
|
|
298
|
+
a scope column says something different: `unique (period_id, tenant_id,
|
|
299
|
+
contract_id, recipient_user_id)` admits one row per RECIPIENT per period,
|
|
300
|
+
so many rows per tenant exist and the table is **not** a singleton. Such a
|
|
301
|
+
constraint is left untagged — the `uniqueConstraints` facts stay visible
|
|
302
|
+
so an owner can see exactly why.
|
|
303
|
+
|
|
304
|
+
Both are attributes, not signals: nothing blocks on them. The gate turns
|
|
305
|
+
the tag into one non-blocking `RESOURCE_SINGLETON_PER_TENANT` advisory per
|
|
306
|
+
resource that owes a `persistence:create`, naming the constraint, the
|
|
307
|
+
scope columns and how to prove it (create the tenant in the test, then
|
|
308
|
+
register that tenant's login with the witness for that session only — see
|
|
309
|
+
`packages/cli/guides/TEST-ENVIRONMENT.md`). A table on another plane, an
|
|
310
|
+
unreviewed table, and a unique constraint naming any non-scope column are
|
|
311
|
+
left byte-identical to before.
|
|
312
|
+
|
|
313
|
+
### Declaring the tenant scope columns
|
|
314
|
+
|
|
315
|
+
The default list above recognizes the usual spellings only. When the
|
|
316
|
+
scope column is named differently — the ledger table scoped by
|
|
317
|
+
`contractor_id`, unique `(contractor_id, ledger_id, kind)` — the owner
|
|
318
|
+
declares it in `.gateforge.yml`:
|
|
319
|
+
|
|
320
|
+
```yaml
|
|
321
|
+
# .gateforge.yml
|
|
322
|
+
tenancy:
|
|
323
|
+
scopeColumns: [contractor_id]
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
- The declaration **replaces** `TENANT_SCOPE_COLUMNS`; it never extends
|
|
327
|
+
it. With the block above, `contractor_id` is recognized and `tenant_id`
|
|
328
|
+
is not, so the recognized scope is exactly what the owner said.
|
|
329
|
+
- **Absent** (no file, no `tenancy` block, no `scopeColumns`) means the
|
|
330
|
+
default list, byte-identical to a pack without this channel.
|
|
331
|
+
- The block must be a nonempty list of column names; anything else fails
|
|
332
|
+
closed with `invalid config <path>: …` rather than quietly disabling
|
|
333
|
+
the tag. The pack validates its own block only — the CLI owns the rest
|
|
334
|
+
of the config document.
|
|
335
|
+
- The key lives in `.gateforge.yml`, so it is inside the trusted policy
|
|
336
|
+
digest: widening the recognized tenant scope is an owner-approved
|
|
337
|
+
policy-revision change, never an agent-editable toggle.
|
|
338
|
+
- Programmatically: `createSqlalchemyDetector({ tenancyScopeColumns: [...] })`
|
|
339
|
+
(or `{ configPath }`) overrides the document channel entirely.
|
|
340
|
+
|
|
341
|
+
|
|
249
342
|
## Plane and resource classification
|
|
250
343
|
|
|
251
344
|
The detector emits normalized facts, plane evidence (from
|
package/dist/detector.d.ts
CHANGED
|
@@ -35,6 +35,19 @@ export interface SqlalchemyDetectorOptions {
|
|
|
35
35
|
* byte-identical to `NO_PLANE_MAPPING`; a malformed document throws.
|
|
36
36
|
*/
|
|
37
37
|
planesConfigPath?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Explicit owner-declared tenant scope columns. Overrides the
|
|
40
|
+
* `.gateforge.yml` `tenancy.scopeColumns` document entirely when given.
|
|
41
|
+
*/
|
|
42
|
+
tenancyScopeColumns?: readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* Repo-relative path of the owner config (YAML) the tenant scope
|
|
45
|
+
* declaration is read from, resolved against the working directory at
|
|
46
|
+
* discover time (default `.gateforge.yml`). Absence is normal — the
|
|
47
|
+
* outcome is then byte-identical to the built-in
|
|
48
|
+
* {@link TENANT_SCOPE_COLUMNS}; a malformed document throws.
|
|
49
|
+
*/
|
|
50
|
+
configPath?: string;
|
|
38
51
|
/** Subprocess argv (default: `python3 -m gateforge_sqlalchemy_detector`). */
|
|
39
52
|
command?: readonly string[];
|
|
40
53
|
/** Subprocess environment (default: {@link pythonEnvironment}). */
|
|
@@ -64,11 +77,13 @@ type RawOutcome = DiscoveryOutcome;
|
|
|
64
77
|
* Args:
|
|
65
78
|
* outcome: The python discovery outcome.
|
|
66
79
|
* plane: The plane rule to apply.
|
|
80
|
+
* scopeColumns: The tenant-scope column names to recognize (default:
|
|
81
|
+
* {@link TENANT_SCOPE_COLUMNS}).
|
|
67
82
|
*
|
|
68
83
|
* Returns:
|
|
69
84
|
* RawOutcome: New outcome; tables the rule maps carry `plane`.
|
|
70
85
|
*/
|
|
71
|
-
export declare function applyPlaneMapping(outcome: RawOutcome, plane: PlaneRule): RawOutcome;
|
|
86
|
+
export declare function applyPlaneMapping(outcome: RawOutcome, plane: PlaneRule, scopeColumns?: readonly string[]): RawOutcome;
|
|
72
87
|
/** The code of the blocking declarative-plane conflict finding. */
|
|
73
88
|
export declare const PLANE_RULE_CONTRADICTION = "PLANE_RULE_CONTRADICTION";
|
|
74
89
|
/**
|
|
@@ -89,11 +104,13 @@ export declare const PLANE_RULE_CONTRADICTION = "PLANE_RULE_CONTRADICTION";
|
|
|
89
104
|
* Args:
|
|
90
105
|
* outcome: The python discovery outcome.
|
|
91
106
|
* config: The validated declarative plane config.
|
|
107
|
+
* scopeColumns: The tenant-scope column names to recognize (default:
|
|
108
|
+
* {@link TENANT_SCOPE_COLUMNS}).
|
|
92
109
|
*
|
|
93
110
|
* Returns:
|
|
94
111
|
* RawOutcome: New outcome with agreed planes and any conflict findings.
|
|
95
112
|
*/
|
|
96
|
-
export declare function applyPlanesConfig(outcome: RawOutcome, config: PlanesConfig): RawOutcome;
|
|
113
|
+
export declare function applyPlanesConfig(outcome: RawOutcome, config: PlanesConfig, scopeColumns?: readonly string[]): RawOutcome;
|
|
97
114
|
/**
|
|
98
115
|
* Creates a discover-capable detector module. The default export of the
|
|
99
116
|
* pack is `createSqlalchemyDetector()` — the CLI in-process contract.
|
package/dist/detector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,SAAS,EAGf,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,SAAS,EAGf,MAAM,aAAa,CAAC;AAYrB,2EAA2E;AAC3E,eAAO,MAAM,eAAe,UAAqD,CAAC;AAElF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CAAC,UAAU,CAOlF;AAED,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,KA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,CA0BZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,yBAA8B,GAAG,kBAAkB,CAqDpG"}
|
package/dist/detector.js
CHANGED
|
@@ -23,6 +23,8 @@ import { delimiter, resolve } from 'node:path';
|
|
|
23
23
|
import { PluginSession, } from '@gate-forge/plugin-protocol';
|
|
24
24
|
import { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
25
25
|
import { NO_PLANE_MAPPING, PLANES_CONFIG_PATH, readPlanesConfigOrNull, resolvePlaneByRules, } from './planes.js';
|
|
26
|
+
import { applySingletonTags, TENANT_SCOPE_COLUMNS } from './singleton.js';
|
|
27
|
+
import { readTenancyScopeColumnsOrNull, CONFIG_PATH } from './tenancy.js';
|
|
26
28
|
/** Absolute dir of this pack's `python/` tree (the detector package). */
|
|
27
29
|
const PACK_PYTHON_DIR = fileURLToPath(new URL('../python', import.meta.url));
|
|
28
30
|
/** Absolute dir of the sibling `@gate-forge/plugin-protocol` python client. */
|
|
@@ -42,7 +44,11 @@ export const DEFAULT_COMMAND = ['python3', '-m', 'gateforge_sqlalchemy_detector'
|
|
|
42
44
|
*/
|
|
43
45
|
export function pythonEnvironment(extra = []) {
|
|
44
46
|
const entries = [...extra, PACK_PYTHON_DIR, PROTOCOL_PYTHON_DIR];
|
|
45
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
...process.env,
|
|
49
|
+
PYTHONDONTWRITEBYTECODE: '1',
|
|
50
|
+
PYTHONPATH: entries.join(delimiter),
|
|
51
|
+
};
|
|
46
52
|
}
|
|
47
53
|
/** The table facts of one resource, or null when it is not a named table. */
|
|
48
54
|
function tableFactsOf(resource) {
|
|
@@ -95,16 +101,34 @@ function mapTablePlanes(outcome, decide) {
|
|
|
95
101
|
* Args:
|
|
96
102
|
* outcome: The python discovery outcome.
|
|
97
103
|
* plane: The plane rule to apply.
|
|
104
|
+
* scopeColumns: The tenant-scope column names to recognize (default:
|
|
105
|
+
* {@link TENANT_SCOPE_COLUMNS}).
|
|
98
106
|
*
|
|
99
107
|
* Returns:
|
|
100
108
|
* RawOutcome: New outcome; tables the rule maps carry `plane`.
|
|
101
109
|
*/
|
|
102
|
-
export function applyPlaneMapping(outcome, plane) {
|
|
103
|
-
return mapTablePlanes(outcome, (facts) => plane({
|
|
110
|
+
export function applyPlaneMapping(outcome, plane, scopeColumns = TENANT_SCOPE_COLUMNS) {
|
|
111
|
+
return withSingletonTags(mapTablePlanes(outcome, (facts) => plane({
|
|
104
112
|
tableName: facts.tableName,
|
|
105
113
|
classQname: facts.classQname,
|
|
106
114
|
provenance: facts.provenance,
|
|
107
|
-
}));
|
|
115
|
+
})), scopeColumns);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Rewrites one plane-applied outcome into its per-tenant-singleton form.
|
|
119
|
+
* Every plane channel funnels through here, so the tag is minted exactly
|
|
120
|
+
* once per run and a table without both provable facts is untouched
|
|
121
|
+
* (byte-identical to the pre-tag output).
|
|
122
|
+
*
|
|
123
|
+
* Args:
|
|
124
|
+
* outcome: The outcome with planes already applied.
|
|
125
|
+
* scopeColumns: The tenant-scope column names to recognize.
|
|
126
|
+
*
|
|
127
|
+
* Returns:
|
|
128
|
+
* RawOutcome: The same outcome with `singletonPerTenant` added where earned.
|
|
129
|
+
*/
|
|
130
|
+
function withSingletonTags(outcome, scopeColumns) {
|
|
131
|
+
return { ...outcome, resources: applySingletonTags(outcome.resources, scopeColumns) };
|
|
108
132
|
}
|
|
109
133
|
/** The code of the blocking declarative-plane conflict finding. */
|
|
110
134
|
export const PLANE_RULE_CONTRADICTION = 'PLANE_RULE_CONTRADICTION';
|
|
@@ -165,11 +189,13 @@ function compareFindings(a, b) {
|
|
|
165
189
|
* Args:
|
|
166
190
|
* outcome: The python discovery outcome.
|
|
167
191
|
* config: The validated declarative plane config.
|
|
192
|
+
* scopeColumns: The tenant-scope column names to recognize (default:
|
|
193
|
+
* {@link TENANT_SCOPE_COLUMNS}).
|
|
168
194
|
*
|
|
169
195
|
* Returns:
|
|
170
196
|
* RawOutcome: New outcome with agreed planes and any conflict findings.
|
|
171
197
|
*/
|
|
172
|
-
export function applyPlanesConfig(outcome, config) {
|
|
198
|
+
export function applyPlanesConfig(outcome, config, scopeColumns = TENANT_SCOPE_COLUMNS) {
|
|
173
199
|
const contradictionFindings = [];
|
|
174
200
|
const resources = outcome.resources.map((resource) => {
|
|
175
201
|
const facts = tableFactsOf(resource);
|
|
@@ -188,13 +214,13 @@ export function applyPlanesConfig(outcome, config) {
|
|
|
188
214
|
return { ...resource, attributes: { ...resource.attributes, plane: resolution.plane } };
|
|
189
215
|
});
|
|
190
216
|
contradictionFindings.sort(compareFindings);
|
|
191
|
-
return {
|
|
217
|
+
return withSingletonTags({
|
|
192
218
|
resources,
|
|
193
219
|
unresolved: outcome.unresolved,
|
|
194
220
|
findings: [...outcome.findings, ...contradictionFindings],
|
|
195
221
|
classificationSignals: outcome.classificationSignals,
|
|
196
222
|
...(outcome.scannedPaths !== undefined ? { scannedPaths: outcome.scannedPaths } : {}),
|
|
197
|
-
};
|
|
223
|
+
}, scopeColumns);
|
|
198
224
|
}
|
|
199
225
|
/**
|
|
200
226
|
* Creates a discover-capable detector module. The default export of the
|
|
@@ -219,6 +245,12 @@ export function createSqlalchemyDetector(options = {}) {
|
|
|
219
245
|
const env = options.env ?? pythonEnvironment();
|
|
220
246
|
const pluginId = options.pluginId ?? PACK_PLUGIN_ID;
|
|
221
247
|
const pluginVersion = options.pluginVersion ?? PACK_VERSION;
|
|
248
|
+
// The tenant scope channel, resolved once per discover: the explicit
|
|
249
|
+
// option, else the owner's `.gateforge.yml` declaration, else the
|
|
250
|
+
// pack's default list (absence → byte-identical).
|
|
251
|
+
const resolveScopeColumns = () => options.tenancyScopeColumns ??
|
|
252
|
+
readTenancyScopeColumnsOrNull(resolve(process.cwd(), options.configPath ?? CONFIG_PATH)) ??
|
|
253
|
+
TENANT_SCOPE_COLUMNS;
|
|
222
254
|
return {
|
|
223
255
|
async discover(paths) {
|
|
224
256
|
if (paths.length === 0) {
|
|
@@ -242,15 +274,16 @@ export function createSqlalchemyDetector(options = {}) {
|
|
|
242
274
|
classificationSignals: outcome.classificationSignals,
|
|
243
275
|
...(outcome.scannedPaths !== undefined ? { scannedPaths: outcome.scannedPaths } : {}),
|
|
244
276
|
};
|
|
277
|
+
const scopeColumns = resolveScopeColumns();
|
|
245
278
|
if (plane !== undefined) {
|
|
246
|
-
return planeIsNoop(plane) ? withSignals : applyPlaneMapping(withSignals, plane);
|
|
279
|
+
return planeIsNoop(plane) ? withSignals : applyPlaneMapping(withSignals, plane, scopeColumns);
|
|
247
280
|
}
|
|
248
281
|
const config = options.planesConfig ??
|
|
249
282
|
readPlanesConfigOrNull(resolve(process.cwd(), options.planesConfigPath ?? PLANES_CONFIG_PATH));
|
|
250
283
|
if (config.rules.length === 0) {
|
|
251
284
|
return withSignals; // no rules: byte-identical to NO_PLANE_MAPPING
|
|
252
285
|
}
|
|
253
|
-
return applyPlanesConfig(withSignals, config);
|
|
286
|
+
return applyPlanesConfig(withSignals, config, scopeColumns);
|
|
254
287
|
}
|
|
255
288
|
finally {
|
|
256
289
|
await session.dispose();
|
package/dist/detector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,aAAa,GAGd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GAKpB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"detector.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ACjG,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC9B,OAAO,WAAW,CAAC,CAAC,+CAA+C;gBACrE,CAAC;gBACD,OAAO,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;YAC9D,CAAC;oBAAS,CAAC;gBACT,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,qDAAqD;AACrD,SAAS,WAAW,CAAC,KAAgB;IACnC,OAAO,KAAK,KAAK,gBAAgB,CAAC;AACpC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
2
2
|
export { createSqlalchemyDetector, DEFAULT_COMMAND, pythonEnvironment, applyPlaneMapping, applyPlanesConfig, PLANE_RULE_CONTRADICTION, type SqlalchemyDetector, type SqlalchemyDetectorOptions, } from './detector.js';
|
|
3
3
|
export { DEFAULT_PLANES_CONFIG, NO_PLANE_MAPPING, PLANES_CONFIG_PATH, byTableName, planeRuleMatches, readPlanesConfigOrNull, parsePlanesConfigText, resolvePlaneByRules, type PlaneConfigRule, type PlaneContext, type PlaneMatchInput, type PlaneResolution, type PlaneRule, type PlaneRuleHit, type PlanesConfig, type SqlalchemyPlane, } from './planes.js';
|
|
4
|
+
export { applySingletonTags, singletonTagFor, TENANT_SCOPE_COLUMNS, type SingletonPerTenantFact, } from './singleton.js';
|
|
5
|
+
export { readTenancyScopeColumnsOrNull, CONFIG_PATH as TENANCY_CONFIG_PATH, } from './tenancy.js';
|
|
6
|
+
export { isTestSourcePath, TEST_PATH_SEGMENTS, } from './test-paths.js';
|
|
4
7
|
export { EntityAdapterSchema, validateEntityAdapter, type EntityAdapter, type EntityAdapterContext, type NormalizedEntity, type EntityAdapterValidation, } from './adapter-schema.js';
|
|
5
8
|
/** The default CLI in-process plugin module: `{ discover(paths) }`. */
|
|
6
9
|
declare const _default: import("./detector.js").SqlalchemyDetector;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;;AACvE,wBAA0C"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,mBAAmB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;;AACvE,wBAA0C"}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,9 @@ import { createSqlalchemyDetector } from './detector.js';
|
|
|
25
25
|
export { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
26
26
|
export { createSqlalchemyDetector, DEFAULT_COMMAND, pythonEnvironment, applyPlaneMapping, applyPlanesConfig, PLANE_RULE_CONTRADICTION, } from './detector.js';
|
|
27
27
|
export { DEFAULT_PLANES_CONFIG, NO_PLANE_MAPPING, PLANES_CONFIG_PATH, byTableName, planeRuleMatches, readPlanesConfigOrNull, parsePlanesConfigText, resolvePlaneByRules, } from './planes.js';
|
|
28
|
+
export { applySingletonTags, singletonTagFor, TENANT_SCOPE_COLUMNS, } from './singleton.js';
|
|
29
|
+
export { readTenancyScopeColumnsOrNull, CONFIG_PATH as TENANCY_CONFIG_PATH, } from './tenancy.js';
|
|
30
|
+
export { isTestSourcePath, TEST_PATH_SEGMENTS, } from './test-paths.js';
|
|
28
31
|
export { EntityAdapterSchema, validateEntityAdapter, } from './adapter-schema.js';
|
|
29
32
|
/** The default CLI in-process plugin module: `{ discover(paths) }`. */
|
|
30
33
|
export default createSqlalchemyDetector();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GAGzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GASpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAKtB,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;AACvE,eAAe,wBAAwB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GAGzB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GASpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,6BAA6B,EAC7B,WAAW,IAAI,mBAAmB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAKtB,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;AACvE,eAAe,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-tenant singleton facts (plan 2026-09-25 Phase 4b item 3a).
|
|
3
|
+
*
|
|
4
|
+
* A table whose UNIQUE constraint — or whose UNIQUE INDEX — is declared
|
|
5
|
+
* over EXACTLY the tenancy scope columns admits at most ONE row per
|
|
6
|
+
* tenancy scope. A create of such a resource is therefore provable only
|
|
7
|
+
* on a brand-new tenant, while the witness's adapter reads use one
|
|
8
|
+
* process-global login: the create reads as "the fixed tenant already has
|
|
9
|
+
* that row". This module mints the additive `singletonPerTenant`
|
|
10
|
+
* attribute that lets the gate TELL the owner; it never decides a
|
|
11
|
+
* verdict, never blocks, and never guesses.
|
|
12
|
+
*
|
|
13
|
+
* "Exactly the scope" is the whole rule, and it is deliberately strict:
|
|
14
|
+
* EVERY column of the constraint must be a recognized tenancy-scope
|
|
15
|
+
* column. A constraint that merely CONTAINS a scope column says
|
|
16
|
+
* something else — `unique (period_id, tenant_id, contract_id,
|
|
17
|
+
* recipient_user_id)` says one row per recipient per period, so many
|
|
18
|
+
* rows per tenant exist, and calling that a singleton produced a
|
|
19
|
+
* provably false sentence about a real table (it also mistook a domain
|
|
20
|
+
* `tenant_id` column — the renter — for the tenancy scope). Both facts
|
|
21
|
+
* must therefore be provable statically: the table must carry plane
|
|
22
|
+
* evidence of `tenant` (the reviewed decision, resolved by the plane
|
|
23
|
+
* channel) AND one of its declared `uniqueConstraints` must be written
|
|
24
|
+
* over scope columns only. A table on another plane, an unreviewed
|
|
25
|
+
* table, and a constraint that names any non-scope column are left
|
|
26
|
+
* untouched, so the output stays byte-identical wherever the tag is not
|
|
27
|
+
* earned.
|
|
28
|
+
*
|
|
29
|
+
* WHICH columns carry the tenant scope is the owner's call: the default
|
|
30
|
+
* is {@link TENANT_SCOPE_COLUMNS}, and an application whose scope column
|
|
31
|
+
* is spelled differently (`contractor_id`, ...) passes its own list, read
|
|
32
|
+
* from `.gateforge.yml` (`tenancy.scopeColumns`, see `tenancy.ts`). The
|
|
33
|
+
* passed list REPLACES the default — it never extends it, so a table
|
|
34
|
+
* scoped by a column the owner did not declare stays untagged even when
|
|
35
|
+
* its name resembles the default list.
|
|
36
|
+
*/
|
|
37
|
+
/** Column names that RESEMBLE the tenant scope of a tenant-plane table. */
|
|
38
|
+
export declare const TENANT_SCOPE_COLUMNS: readonly string[];
|
|
39
|
+
/** The additive tag one per-tenant-singleton table carries. */
|
|
40
|
+
export interface SingletonPerTenantFact {
|
|
41
|
+
/** Declared constraint/index name, or null when it is unnamed. */
|
|
42
|
+
constraint: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* The first tenancy-scope column of the constraint in written order.
|
|
45
|
+
* Kept for the additive contract; {@link scopeColumns} names them all.
|
|
46
|
+
*/
|
|
47
|
+
tenantColumn: string;
|
|
48
|
+
/**
|
|
49
|
+
* Every recognized tenancy-scope column of the constraint, written
|
|
50
|
+
* order. Under the default list the spellings are ALTERNATIVES, so this
|
|
51
|
+
* is normally one name; a composite declared scope lists them all.
|
|
52
|
+
*/
|
|
53
|
+
scopeColumns: readonly string[];
|
|
54
|
+
/** Every column of the unique constraint/index, written order. */
|
|
55
|
+
columns: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/** The discovered-resource attribute bag the tag is computed from. */
|
|
58
|
+
type Attributes = Readonly<Record<string, unknown>>;
|
|
59
|
+
/**
|
|
60
|
+
* The unique constraint that makes this table a singleton per tenant,
|
|
61
|
+
* or null when no declared constraint is written over the tenancy scope
|
|
62
|
+
* ALONE.
|
|
63
|
+
*
|
|
64
|
+
* A constraint qualifies only when EVERY column it names is a recognized
|
|
65
|
+
* scope column — it is written over the tenancy scope and nothing else. A
|
|
66
|
+
* constraint that merely CONTAINS a scope column says something else
|
|
67
|
+
* entirely: `unique (period_id, tenant_id, contract_id,
|
|
68
|
+
* recipient_user_id)` allows one row per recipient per period, so many
|
|
69
|
+
* rows per tenant exist and the table is not a singleton. Naming PART of
|
|
70
|
+
* a composite declared scope (`unique (org_id)` under
|
|
71
|
+
* `tenancy.scopeColumns: [org_id, tenant_id]`) still qualifies, and
|
|
72
|
+
* soundly so: at most one row per organization is at most one row per
|
|
73
|
+
* (organization, tenant).
|
|
74
|
+
*
|
|
75
|
+
* Args:
|
|
76
|
+
* attributes: One `sqlalchemy.table` resource's attributes.
|
|
77
|
+
* scopeColumns: The tenancy-scope column names to recognize (default:
|
|
78
|
+
* {@link TENANT_SCOPE_COLUMNS}; an owner-declared list REPLACES it).
|
|
79
|
+
*
|
|
80
|
+
* Returns:
|
|
81
|
+
* SingletonPerTenantFact | null: the deciding constraint's fact, or null.
|
|
82
|
+
*/
|
|
83
|
+
export declare function singletonTagFor(attributes: Attributes, scopeColumns?: readonly string[]): SingletonPerTenantFact | null;
|
|
84
|
+
/** The discovered-resource shape the tag pass rewrites. */
|
|
85
|
+
interface DiscoverableResource {
|
|
86
|
+
readonly kind: string;
|
|
87
|
+
readonly attributes: Attributes;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Adds `singletonPerTenant` to every table that earns it and changes
|
|
91
|
+
* nothing else. Pure over its inputs — deterministic.
|
|
92
|
+
*
|
|
93
|
+
* Args:
|
|
94
|
+
* resources: The discovery outcome's resource list.
|
|
95
|
+
* scopeColumns: The tenant-scope column names to recognize (default:
|
|
96
|
+
* {@link TENANT_SCOPE_COLUMNS}; an owner-declared list REPLACES it).
|
|
97
|
+
*
|
|
98
|
+
* Returns:
|
|
99
|
+
* DiscoverableResource[]: the same resources, tagged where provable.
|
|
100
|
+
*/
|
|
101
|
+
export declare function applySingletonTags<T extends DiscoverableResource>(resources: readonly T[], scopeColumns?: readonly string[]): T[];
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=singleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEH,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,kEAAkE;IAClE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AASD,sEAAsE;AACtE,KAAK,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAuBpD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,EACtB,YAAY,GAAE,SAAS,MAAM,EAAyB,GACrD,sBAAsB,GAAG,IAAI,CA2B/B;AAED,2DAA2D;AAC3D,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CACjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,oBAAoB,EAC/D,SAAS,EAAE,SAAS,CAAC,EAAE,EACvB,YAAY,GAAE,SAAS,MAAM,EAAyB,GACrD,CAAC,EAAE,CAOL"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-tenant singleton facts (plan 2026-09-25 Phase 4b item 3a).
|
|
3
|
+
*
|
|
4
|
+
* A table whose UNIQUE constraint — or whose UNIQUE INDEX — is declared
|
|
5
|
+
* over EXACTLY the tenancy scope columns admits at most ONE row per
|
|
6
|
+
* tenancy scope. A create of such a resource is therefore provable only
|
|
7
|
+
* on a brand-new tenant, while the witness's adapter reads use one
|
|
8
|
+
* process-global login: the create reads as "the fixed tenant already has
|
|
9
|
+
* that row". This module mints the additive `singletonPerTenant`
|
|
10
|
+
* attribute that lets the gate TELL the owner; it never decides a
|
|
11
|
+
* verdict, never blocks, and never guesses.
|
|
12
|
+
*
|
|
13
|
+
* "Exactly the scope" is the whole rule, and it is deliberately strict:
|
|
14
|
+
* EVERY column of the constraint must be a recognized tenancy-scope
|
|
15
|
+
* column. A constraint that merely CONTAINS a scope column says
|
|
16
|
+
* something else — `unique (period_id, tenant_id, contract_id,
|
|
17
|
+
* recipient_user_id)` says one row per recipient per period, so many
|
|
18
|
+
* rows per tenant exist, and calling that a singleton produced a
|
|
19
|
+
* provably false sentence about a real table (it also mistook a domain
|
|
20
|
+
* `tenant_id` column — the renter — for the tenancy scope). Both facts
|
|
21
|
+
* must therefore be provable statically: the table must carry plane
|
|
22
|
+
* evidence of `tenant` (the reviewed decision, resolved by the plane
|
|
23
|
+
* channel) AND one of its declared `uniqueConstraints` must be written
|
|
24
|
+
* over scope columns only. A table on another plane, an unreviewed
|
|
25
|
+
* table, and a constraint that names any non-scope column are left
|
|
26
|
+
* untouched, so the output stays byte-identical wherever the tag is not
|
|
27
|
+
* earned.
|
|
28
|
+
*
|
|
29
|
+
* WHICH columns carry the tenant scope is the owner's call: the default
|
|
30
|
+
* is {@link TENANT_SCOPE_COLUMNS}, and an application whose scope column
|
|
31
|
+
* is spelled differently (`contractor_id`, ...) passes its own list, read
|
|
32
|
+
* from `.gateforge.yml` (`tenancy.scopeColumns`, see `tenancy.ts`). The
|
|
33
|
+
* passed list REPLACES the default — it never extends it, so a table
|
|
34
|
+
* scoped by a column the owner did not declare stays untagged even when
|
|
35
|
+
* its name resembles the default list.
|
|
36
|
+
*/
|
|
37
|
+
/** Column names that RESEMBLE the tenant scope of a tenant-plane table. */
|
|
38
|
+
export const TENANT_SCOPE_COLUMNS = Object.freeze([
|
|
39
|
+
'tenant_id',
|
|
40
|
+
'tenant',
|
|
41
|
+
'tenantId',
|
|
42
|
+
'tenant_uuid',
|
|
43
|
+
'tenant_key',
|
|
44
|
+
]);
|
|
45
|
+
/**
|
|
46
|
+
* Reads one `uniqueConstraints` entry, or null when the attribute is
|
|
47
|
+
* absent or malformed (never a partial guess).
|
|
48
|
+
*/
|
|
49
|
+
function uniqueConstraintOf(value) {
|
|
50
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
51
|
+
return null;
|
|
52
|
+
const entry = value;
|
|
53
|
+
if (typeof entry.kind !== 'string' || entry.kind.length === 0)
|
|
54
|
+
return null;
|
|
55
|
+
if (!Array.isArray(entry.columns) || entry.columns.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
const columns = [];
|
|
58
|
+
for (const column of entry.columns) {
|
|
59
|
+
if (typeof column !== 'string' || column.length === 0)
|
|
60
|
+
return null;
|
|
61
|
+
columns.push(column);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name: typeof entry.name === 'string' && entry.name.length > 0 ? entry.name : null,
|
|
65
|
+
kind: entry.kind,
|
|
66
|
+
columns,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The unique constraint that makes this table a singleton per tenant,
|
|
71
|
+
* or null when no declared constraint is written over the tenancy scope
|
|
72
|
+
* ALONE.
|
|
73
|
+
*
|
|
74
|
+
* A constraint qualifies only when EVERY column it names is a recognized
|
|
75
|
+
* scope column — it is written over the tenancy scope and nothing else. A
|
|
76
|
+
* constraint that merely CONTAINS a scope column says something else
|
|
77
|
+
* entirely: `unique (period_id, tenant_id, contract_id,
|
|
78
|
+
* recipient_user_id)` allows one row per recipient per period, so many
|
|
79
|
+
* rows per tenant exist and the table is not a singleton. Naming PART of
|
|
80
|
+
* a composite declared scope (`unique (org_id)` under
|
|
81
|
+
* `tenancy.scopeColumns: [org_id, tenant_id]`) still qualifies, and
|
|
82
|
+
* soundly so: at most one row per organization is at most one row per
|
|
83
|
+
* (organization, tenant).
|
|
84
|
+
*
|
|
85
|
+
* Args:
|
|
86
|
+
* attributes: One `sqlalchemy.table` resource's attributes.
|
|
87
|
+
* scopeColumns: The tenancy-scope column names to recognize (default:
|
|
88
|
+
* {@link TENANT_SCOPE_COLUMNS}; an owner-declared list REPLACES it).
|
|
89
|
+
*
|
|
90
|
+
* Returns:
|
|
91
|
+
* SingletonPerTenantFact | null: the deciding constraint's fact, or null.
|
|
92
|
+
*/
|
|
93
|
+
export function singletonTagFor(attributes, scopeColumns = TENANT_SCOPE_COLUMNS) {
|
|
94
|
+
// Plane evidence first: an unreviewed table is never a tenant table.
|
|
95
|
+
if (attributes['plane'] !== 'tenant')
|
|
96
|
+
return null;
|
|
97
|
+
const declared = attributes['uniqueConstraints'];
|
|
98
|
+
if (!Array.isArray(declared))
|
|
99
|
+
return null;
|
|
100
|
+
for (const raw of declared) {
|
|
101
|
+
const constraint = uniqueConstraintOf(raw);
|
|
102
|
+
if (constraint === null)
|
|
103
|
+
continue;
|
|
104
|
+
// Every column must be the scope; a single non-scope column means the
|
|
105
|
+
// constraint distinguishes more than the tenancy and admits repeated
|
|
106
|
+
// creates per tenant.
|
|
107
|
+
const scopeInConstraint = constraint.columns.filter((column) => scopeColumns.includes(column));
|
|
108
|
+
if (scopeInConstraint.length !== constraint.columns.length)
|
|
109
|
+
continue;
|
|
110
|
+
// Written order decides which constraint is reported when several
|
|
111
|
+
// qualify — deterministic, and every one of them still says the same.
|
|
112
|
+
const first = scopeInConstraint[0];
|
|
113
|
+
if (first === undefined)
|
|
114
|
+
continue;
|
|
115
|
+
return {
|
|
116
|
+
constraint: constraint.name,
|
|
117
|
+
tenantColumn: first,
|
|
118
|
+
scopeColumns: [...scopeInConstraint],
|
|
119
|
+
columns: [...constraint.columns],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Adds `singletonPerTenant` to every table that earns it and changes
|
|
126
|
+
* nothing else. Pure over its inputs — deterministic.
|
|
127
|
+
*
|
|
128
|
+
* Args:
|
|
129
|
+
* resources: The discovery outcome's resource list.
|
|
130
|
+
* scopeColumns: The tenant-scope column names to recognize (default:
|
|
131
|
+
* {@link TENANT_SCOPE_COLUMNS}; an owner-declared list REPLACES it).
|
|
132
|
+
*
|
|
133
|
+
* Returns:
|
|
134
|
+
* DiscoverableResource[]: the same resources, tagged where provable.
|
|
135
|
+
*/
|
|
136
|
+
export function applySingletonTags(resources, scopeColumns = TENANT_SCOPE_COLUMNS) {
|
|
137
|
+
return resources.map((resource) => {
|
|
138
|
+
if (resource.kind !== 'sqlalchemy.table')
|
|
139
|
+
return resource;
|
|
140
|
+
const fact = singletonTagFor(resource.attributes, scopeColumns);
|
|
141
|
+
if (fact === null)
|
|
142
|
+
return resource;
|
|
143
|
+
return { ...resource, attributes: { ...resource.attributes, singletonPerTenant: fact } };
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=singleton.js.map
|