@gate-forge/pack-sqlalchemy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +353 -0
- package/dist/adapter-schema.d.ts +84 -0
- package/dist/adapter-schema.d.ts.map +1 -0
- package/dist/adapter-schema.js +67 -0
- package/dist/adapter-schema.js.map +1 -0
- package/dist/detector.d.ts +116 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +265 -0
- package/dist/detector.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/planes.d.ts +177 -0
- package/dist/planes.d.ts.map +1 -0
- package/dist/planes.js +280 -0
- package/dist/planes.js.map +1 -0
- package/dist/version.d.ts +12 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +12 -0
- package/dist/version.js.map +1 -0
- package/examples/example.accounts.adapter.mjs +97 -0
- package/package.json +45 -0
- package/python/gateforge_sqlalchemy_detector/__init__.py +68 -0
- package/python/gateforge_sqlalchemy_detector/__main__.py +50 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/__init__.cpython-312.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/__init__.cpython-314.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/__main__.cpython-312.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/__main__.cpython-314.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/scan.cpython-312.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/__pycache__/scan.cpython-314.pyc +0 -0
- package/python/gateforge_sqlalchemy_detector/scan.py +1446 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity-adapter schema (pack deliverable: "entity-adapter schema doc").
|
|
3
|
+
*
|
|
4
|
+
* The evidence-witness contract (interface pin #8, ADR 0002): an
|
|
5
|
+
* adapter is a reviewed, engine-side module whose default export
|
|
6
|
+
* executes GET-only reads against the target resource. The witness
|
|
7
|
+
* service loads `.gateforge/adapters/<resourceId>.mjs` and calls
|
|
8
|
+
* `read(ctx, id)` when a test asks for persistence evidence; the raw
|
|
9
|
+
* adapter response is never returned to the test process — only the
|
|
10
|
+
* `verdictRelevant` projection is.
|
|
11
|
+
*
|
|
12
|
+
* Adapter responsibilities (mirrored by {@link EntityAdapterSchema} and
|
|
13
|
+
* enforced by {@link validateEntityAdapter}):
|
|
14
|
+
* - `resourceId` — the resource this adapter proves; must match the
|
|
15
|
+
* file name (`<resourceId>.mjs`) so the registry binds by filename.
|
|
16
|
+
* - `read(ctx, id)` — GET-only fetch of one entity; returns the raw
|
|
17
|
+
* response body. Implementations MUST NOT mutate anything.
|
|
18
|
+
* - `normalize(body)` — project the raw body onto the evidence shape
|
|
19
|
+
* `{ entityId, fields }` where `fields` carry the classified
|
|
20
|
+
* `primaryKey` columns.
|
|
21
|
+
* - `deletion: 'hard' | 'archive'` — how removal manifests (archive =
|
|
22
|
+
* soft delete: the row keeps existing retrievable).
|
|
23
|
+
* - `environmentFingerprint` — the target-environment marker (e.g. the
|
|
24
|
+
* value of a response header the witness compares on a probe GET);
|
|
25
|
+
* a fingerprint mismatch rejects the record (GF-13).
|
|
26
|
+
*/
|
|
27
|
+
import { z } from 'zod';
|
|
28
|
+
/**
|
|
29
|
+
* Zod schema for the data fields of an adapter module (functions are
|
|
30
|
+
* checked by {@link validateEntityAdapter} for a single-cause diagnostic
|
|
31
|
+
* list; zod function schemas would blur the message).
|
|
32
|
+
*/
|
|
33
|
+
export const EntityAdapterSchema = z
|
|
34
|
+
.object({
|
|
35
|
+
resourceId: z.string().min(1),
|
|
36
|
+
deletion: z.enum(['hard', 'archive']),
|
|
37
|
+
environmentFingerprint: z.string().min(1),
|
|
38
|
+
read: z.unknown(),
|
|
39
|
+
normalize: z.unknown(),
|
|
40
|
+
})
|
|
41
|
+
.strict();
|
|
42
|
+
/**
|
|
43
|
+
* Validates an adapter module against the frozen contract, failing
|
|
44
|
+
* closed with one issue per violated field.
|
|
45
|
+
*
|
|
46
|
+
* Args:
|
|
47
|
+
* value: The default export of an `.mjs` adapter module.
|
|
48
|
+
*
|
|
49
|
+
* Returns:
|
|
50
|
+
* EntityAdapterValidation: The typed adapter, or every issue found.
|
|
51
|
+
*/
|
|
52
|
+
export function validateEntityAdapter(value) {
|
|
53
|
+
const parsed = EntityAdapterSchema.safeParse(value);
|
|
54
|
+
if (!parsed.success) {
|
|
55
|
+
return { ok: false, issues: parsed.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`) };
|
|
56
|
+
}
|
|
57
|
+
const candidate = value;
|
|
58
|
+
const issues = [];
|
|
59
|
+
if (typeof candidate.read !== 'function')
|
|
60
|
+
issues.push('read: must be a function (ctx, id) => Promise<unknown>');
|
|
61
|
+
if (typeof candidate.normalize !== 'function')
|
|
62
|
+
issues.push('normalize: must be a function (body) => { entityId, fields }');
|
|
63
|
+
if (issues.length > 0)
|
|
64
|
+
return { ok: false, issues };
|
|
65
|
+
return { ok: true, adapter: value };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=adapter-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-schema.js","sourceRoot":"","sources":["../src/adapter-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA2BxB;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrC,sBAAsB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;IACjB,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;CACvB,CAAC;KACD,MAAM,EAAE,CAAC;AAOZ;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACpD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IAChH,CAAC;IACD,MAAM,SAAS,GAAG,KAA+B,CAAC;IAClD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU;QAAE,MAAM,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;IAChH,IAAI,OAAO,SAAS,CAAC,SAAS,KAAK,UAAU;QAAE,MAAM,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;IAC3H,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACpD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAsB,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type DiscoveryOutcome } from '@gate-forge/plugin-protocol';
|
|
2
|
+
import { type PlanesConfig, type PlaneRule } from './planes.js';
|
|
3
|
+
/** The subprocess command the in-process transport spawns (G4 surface). */
|
|
4
|
+
export declare const DEFAULT_COMMAND: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Builds the environment the python detector runs under: the host env
|
|
7
|
+
* plus a `PYTHONPATH` that makes both this pack's detector and the
|
|
8
|
+
* GPP/3 client importable.
|
|
9
|
+
*
|
|
10
|
+
* Args:
|
|
11
|
+
* extra: Additional leading `PYTHONPATH` entries (for tests).
|
|
12
|
+
*
|
|
13
|
+
* Returns:
|
|
14
|
+
* NodeJS.ProcessEnv: host env + deterministic PYTHONPATH.
|
|
15
|
+
*/
|
|
16
|
+
export declare function pythonEnvironment(extra?: readonly string[]): NodeJS.ProcessEnv;
|
|
17
|
+
/** Options for {@link createSqlalchemyDetector}. */
|
|
18
|
+
export interface SqlalchemyDetectorOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Optional programmatic plane mapping. Takes precedence over the
|
|
21
|
+
* declarative config channel: when given, `.gateforge/planes.json` is
|
|
22
|
+
* not read at all. The default is `NO_PLANE_MAPPING`.
|
|
23
|
+
*/
|
|
24
|
+
plane?: PlaneRule;
|
|
25
|
+
/**
|
|
26
|
+
* Explicit declarative plane config; overrides the
|
|
27
|
+
* `.gateforge/planes.json` document entirely when given (and is
|
|
28
|
+
* ignored while `plane` is given).
|
|
29
|
+
*/
|
|
30
|
+
planesConfig?: PlanesConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Repo-relative path of the declarative plane config document (JSON),
|
|
33
|
+
* resolved against the working directory at discover time (default:
|
|
34
|
+
* `.gateforge/planes.json`). Absence is normal — the outcome is then
|
|
35
|
+
* byte-identical to `NO_PLANE_MAPPING`; a malformed document throws.
|
|
36
|
+
*/
|
|
37
|
+
planesConfigPath?: string;
|
|
38
|
+
/** Subprocess argv (default: `python3 -m gateforge_sqlalchemy_detector`). */
|
|
39
|
+
command?: readonly string[];
|
|
40
|
+
/** Subprocess environment (default: {@link pythonEnvironment}). */
|
|
41
|
+
env?: NodeJS.ProcessEnv;
|
|
42
|
+
/** Handshake-pinned plugin id (default: the pack id). */
|
|
43
|
+
pluginId?: string;
|
|
44
|
+
/** Handshake-pinned plugin version (default: the pack version). */
|
|
45
|
+
pluginVersion?: string;
|
|
46
|
+
}
|
|
47
|
+
/** The pinned in-process plugin contract: `{ discover(paths) }`. */
|
|
48
|
+
export interface SqlalchemyDetector {
|
|
49
|
+
discover(paths: readonly string[]): Promise<{
|
|
50
|
+
resources: unknown[];
|
|
51
|
+
unresolved: unknown[];
|
|
52
|
+
findings: unknown[];
|
|
53
|
+
classificationSignals: unknown[];
|
|
54
|
+
scannedPaths?: string[];
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
/** One discovery outcome with a typed resource list. */
|
|
58
|
+
type RawOutcome = DiscoveryOutcome;
|
|
59
|
+
/**
|
|
60
|
+
* Attaches `attributes.plane` to each table the rule maps (a mirror of
|
|
61
|
+
* the graph's classification binding; disambiguates same-name
|
|
62
|
+
* multi-plane classification). Pure over its inputs — deterministic.
|
|
63
|
+
*
|
|
64
|
+
* Args:
|
|
65
|
+
* outcome: The python discovery outcome.
|
|
66
|
+
* plane: The plane rule to apply.
|
|
67
|
+
*
|
|
68
|
+
* Returns:
|
|
69
|
+
* RawOutcome: New outcome; tables the rule maps carry `plane`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function applyPlaneMapping(outcome: RawOutcome, plane: PlaneRule): RawOutcome;
|
|
72
|
+
/** The code of the blocking declarative-plane conflict finding. */
|
|
73
|
+
export declare const PLANE_RULE_CONTRADICTION = "PLANE_RULE_CONTRADICTION";
|
|
74
|
+
/**
|
|
75
|
+
* Applies the declarative `.gateforge/planes.json` rules to business
|
|
76
|
+
* `sqlalchemy.table` resources. Deterministic and fail-closed, in two
|
|
77
|
+
* tiers with explicit-beats-general precedence: a table claimed by any
|
|
78
|
+
* `tables` rule resolves only against `tables` rules (glob rules are
|
|
79
|
+
* ignored for it — an enumeration is a more specific human claim, and
|
|
80
|
+
* a glob's `exclude` prunes source files, not table names); glob rules
|
|
81
|
+
* apply only to tables no explicit rule claims. Within the deciding
|
|
82
|
+
* tier: agreement → the plane is applied (the graph then qualifies the
|
|
83
|
+
* id as `plane.name`); conflict → a blocking
|
|
84
|
+
* {@link PLANE_RULE_CONTRADICTION} finding is appended (sorted) and NO
|
|
85
|
+
* plane is applied; no match → nothing (the resource stays
|
|
86
|
+
* plane-unresolved and the core classifier blocks it — the config must
|
|
87
|
+
* cover every table). Pure over its inputs.
|
|
88
|
+
*
|
|
89
|
+
* Args:
|
|
90
|
+
* outcome: The python discovery outcome.
|
|
91
|
+
* config: The validated declarative plane config.
|
|
92
|
+
*
|
|
93
|
+
* Returns:
|
|
94
|
+
* RawOutcome: New outcome with agreed planes and any conflict findings.
|
|
95
|
+
*/
|
|
96
|
+
export declare function applyPlanesConfig(outcome: RawOutcome, config: PlanesConfig): RawOutcome;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a discover-capable detector module. The default export of the
|
|
99
|
+
* pack is `createSqlalchemyDetector()` — the CLI in-process contract.
|
|
100
|
+
*
|
|
101
|
+
* Plane channels, in strict precedence order: the programmatic
|
|
102
|
+
* `options.plane` rule (config channel not read at all), then the
|
|
103
|
+
* explicit `options.planesConfig`, then the `.gateforge/planes.json`
|
|
104
|
+
* document read from the working directory at discover time (absence
|
|
105
|
+
* normal → `NO_PLANE_MAPPING` behavior byte-identical; malformed
|
|
106
|
+
* throws).
|
|
107
|
+
*
|
|
108
|
+
* Args:
|
|
109
|
+
* options: Plane mapping, spawn command/env, and handshake identity.
|
|
110
|
+
*
|
|
111
|
+
* Returns:
|
|
112
|
+
* SqlalchemyDetector: the pinned `{ discover(paths) }` module.
|
|
113
|
+
*/
|
|
114
|
+
export declare function createSqlalchemyDetector(options?: SqlalchemyDetectorOptions): SqlalchemyDetector;
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,gBAAgB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B,CAAC;AA2CnE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CA0BvF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,yBAA8B,GAAG,kBAAkB,CA6CpG"}
|
package/dist/detector.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pack's discover entry: a thin TypeScript GPP/3 client over the
|
|
3
|
+
* Python AST detector, usable from BOTH CLI transports.
|
|
4
|
+
*
|
|
5
|
+
* - **in-process**: `.gateforge.yml` declares
|
|
6
|
+
* `transport: in-process, module: "@gate-forge/pack-sqlalchemy"`; the
|
|
7
|
+
* CLI imports this package's default export and calls
|
|
8
|
+
* `discover(paths)`. The implementation spawns the SAME python
|
|
9
|
+
* detector (GPP/3, hardened host) with a computed `PYTHONPATH`, so
|
|
10
|
+
* one detector implementation serves both transports.
|
|
11
|
+
* - **subprocess**: `.gateforge.yml` declares
|
|
12
|
+
* `transport: subprocess, command: ["python3","-m","gateforge_sqlalchemy_detector"]`
|
|
13
|
+
* (with the pack's `python/` dir on `PYTHONPATH`); the CLI drives the
|
|
14
|
+
* plugin directly — see the README.
|
|
15
|
+
*
|
|
16
|
+
* Determinism: the python scan is pure over (paths, file bytes). Plane
|
|
17
|
+
* attribution is opt-in through detector options or the declarative
|
|
18
|
+
* `.gateforge/planes.json` document (see `planes.ts`); core owns
|
|
19
|
+
* business meaning.
|
|
20
|
+
*/
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { delimiter, resolve } from 'node:path';
|
|
23
|
+
import { PluginSession, } from '@gate-forge/plugin-protocol';
|
|
24
|
+
import { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
25
|
+
import { NO_PLANE_MAPPING, PLANES_CONFIG_PATH, readPlanesConfigOrNull, resolvePlaneByRules, } from './planes.js';
|
|
26
|
+
/** Absolute dir of this pack's `python/` tree (the detector package). */
|
|
27
|
+
const PACK_PYTHON_DIR = fileURLToPath(new URL('../python', import.meta.url));
|
|
28
|
+
/** Absolute dir of the sibling `@gate-forge/plugin-protocol` python client. */
|
|
29
|
+
const PROTOCOL_PYTHON_DIR = fileURLToPath(new URL('../../../plugin-protocol/python', import.meta.url));
|
|
30
|
+
/** The subprocess command the in-process transport spawns (G4 surface). */
|
|
31
|
+
export const DEFAULT_COMMAND = ['python3', '-m', 'gateforge_sqlalchemy_detector'];
|
|
32
|
+
/**
|
|
33
|
+
* Builds the environment the python detector runs under: the host env
|
|
34
|
+
* plus a `PYTHONPATH` that makes both this pack's detector and the
|
|
35
|
+
* GPP/3 client importable.
|
|
36
|
+
*
|
|
37
|
+
* Args:
|
|
38
|
+
* extra: Additional leading `PYTHONPATH` entries (for tests).
|
|
39
|
+
*
|
|
40
|
+
* Returns:
|
|
41
|
+
* NodeJS.ProcessEnv: host env + deterministic PYTHONPATH.
|
|
42
|
+
*/
|
|
43
|
+
export function pythonEnvironment(extra = []) {
|
|
44
|
+
const entries = [...extra, PACK_PYTHON_DIR, PROTOCOL_PYTHON_DIR];
|
|
45
|
+
return { ...process.env, PYTHONPATH: entries.join(delimiter) };
|
|
46
|
+
}
|
|
47
|
+
/** The table facts of one resource, or null when it is not a named table. */
|
|
48
|
+
function tableFactsOf(resource) {
|
|
49
|
+
const name = resource.attributes['resourceName'];
|
|
50
|
+
if (resource.kind !== 'sqlalchemy.table' || typeof name !== 'string') {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const classQname = typeof resource.attributes['classQname'] === 'string'
|
|
54
|
+
? resource.attributes['classQname']
|
|
55
|
+
: null;
|
|
56
|
+
return {
|
|
57
|
+
tableName: name,
|
|
58
|
+
classQname,
|
|
59
|
+
classSimpleName: classQname === null ? null : (classQname.split('.').pop() ?? null),
|
|
60
|
+
provenance: typeof resource.attributes['tablenameProvenance'] === 'string'
|
|
61
|
+
? resource.attributes['tablenameProvenance']
|
|
62
|
+
: 'literal',
|
|
63
|
+
sourcePath: resource.source,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Shared table-mapping pass: rebuilds exactly the resources whose
|
|
68
|
+
* decider returns a plane (`attributes.plane` added; order, ids, and
|
|
69
|
+
* every other field preserved). `gateforge.class` symbols never carry a
|
|
70
|
+
* plane. Pure over its inputs — deterministic.
|
|
71
|
+
*/
|
|
72
|
+
function mapTablePlanes(outcome, decide) {
|
|
73
|
+
const resources = outcome.resources.map((resource) => {
|
|
74
|
+
const facts = tableFactsOf(resource);
|
|
75
|
+
if (facts === null)
|
|
76
|
+
return resource;
|
|
77
|
+
const mapped = decide(facts);
|
|
78
|
+
if (mapped === null)
|
|
79
|
+
return resource;
|
|
80
|
+
return { ...resource, attributes: { ...resource.attributes, plane: mapped } };
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
resources,
|
|
84
|
+
unresolved: outcome.unresolved,
|
|
85
|
+
findings: outcome.findings,
|
|
86
|
+
classificationSignals: outcome.classificationSignals,
|
|
87
|
+
...(outcome.scannedPaths !== undefined ? { scannedPaths: outcome.scannedPaths } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Attaches `attributes.plane` to each table the rule maps (a mirror of
|
|
92
|
+
* the graph's classification binding; disambiguates same-name
|
|
93
|
+
* multi-plane classification). Pure over its inputs — deterministic.
|
|
94
|
+
*
|
|
95
|
+
* Args:
|
|
96
|
+
* outcome: The python discovery outcome.
|
|
97
|
+
* plane: The plane rule to apply.
|
|
98
|
+
*
|
|
99
|
+
* Returns:
|
|
100
|
+
* RawOutcome: New outcome; tables the rule maps carry `plane`.
|
|
101
|
+
*/
|
|
102
|
+
export function applyPlaneMapping(outcome, plane) {
|
|
103
|
+
return mapTablePlanes(outcome, (facts) => plane({
|
|
104
|
+
tableName: facts.tableName,
|
|
105
|
+
classQname: facts.classQname,
|
|
106
|
+
provenance: facts.provenance,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
/** The code of the blocking declarative-plane conflict finding. */
|
|
110
|
+
export const PLANE_RULE_CONTRADICTION = 'PLANE_RULE_CONTRADICTION';
|
|
111
|
+
/**
|
|
112
|
+
* Builds the conflict finding: it names the table, EVERY conflicting
|
|
113
|
+
* plane, EVERY human reason, and EVERY rule index (the review artifact
|
|
114
|
+
* is the config; the diagnostic points straight at its lines).
|
|
115
|
+
*/
|
|
116
|
+
function planeContradictionFinding(facts, location, hits) {
|
|
117
|
+
const described = hits
|
|
118
|
+
.map((hit) => `rule ${hit.index} (${hit.plane}, "${hit.reason}")`)
|
|
119
|
+
.join(' vs ');
|
|
120
|
+
return {
|
|
121
|
+
code: PLANE_RULE_CONTRADICTION,
|
|
122
|
+
detail: `table '${facts.tableName}' matches ${hits.length} declarative plane rules with ` +
|
|
123
|
+
`conflicting planes: ${described}; fix ${PLANES_CONFIG_PATH} so exactly one plane ` +
|
|
124
|
+
'remains — the table stays plane-unresolved and blocks until then',
|
|
125
|
+
locations: [{ file: location.file, line: location.line, col: location.col }],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** Finding order: first location (file, line, col), then code, then detail. */
|
|
129
|
+
function compareFindings(a, b) {
|
|
130
|
+
const locationA = a.locations[0];
|
|
131
|
+
const locationB = b.locations[0];
|
|
132
|
+
const fileA = locationA?.file ?? '';
|
|
133
|
+
const fileB = locationB?.file ?? '';
|
|
134
|
+
if (fileA !== fileB)
|
|
135
|
+
return fileA < fileB ? -1 : 1;
|
|
136
|
+
const lineA = locationA?.line ?? 0;
|
|
137
|
+
const lineB = locationB?.line ?? 0;
|
|
138
|
+
if (lineA !== lineB)
|
|
139
|
+
return lineA - lineB;
|
|
140
|
+
const colA = locationA?.col ?? 0;
|
|
141
|
+
const colB = locationB?.col ?? 0;
|
|
142
|
+
if (colA !== colB)
|
|
143
|
+
return colA - colB;
|
|
144
|
+
if (a.code !== b.code)
|
|
145
|
+
return a.code < b.code ? -1 : 1;
|
|
146
|
+
if (a.detail === b.detail)
|
|
147
|
+
return 0;
|
|
148
|
+
return a.detail < b.detail ? -1 : 1;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Applies the declarative `.gateforge/planes.json` rules to business
|
|
152
|
+
* `sqlalchemy.table` resources. Deterministic and fail-closed, in two
|
|
153
|
+
* tiers with explicit-beats-general precedence: a table claimed by any
|
|
154
|
+
* `tables` rule resolves only against `tables` rules (glob rules are
|
|
155
|
+
* ignored for it — an enumeration is a more specific human claim, and
|
|
156
|
+
* a glob's `exclude` prunes source files, not table names); glob rules
|
|
157
|
+
* apply only to tables no explicit rule claims. Within the deciding
|
|
158
|
+
* tier: agreement → the plane is applied (the graph then qualifies the
|
|
159
|
+
* id as `plane.name`); conflict → a blocking
|
|
160
|
+
* {@link PLANE_RULE_CONTRADICTION} finding is appended (sorted) and NO
|
|
161
|
+
* plane is applied; no match → nothing (the resource stays
|
|
162
|
+
* plane-unresolved and the core classifier blocks it — the config must
|
|
163
|
+
* cover every table). Pure over its inputs.
|
|
164
|
+
*
|
|
165
|
+
* Args:
|
|
166
|
+
* outcome: The python discovery outcome.
|
|
167
|
+
* config: The validated declarative plane config.
|
|
168
|
+
*
|
|
169
|
+
* Returns:
|
|
170
|
+
* RawOutcome: New outcome with agreed planes and any conflict findings.
|
|
171
|
+
*/
|
|
172
|
+
export function applyPlanesConfig(outcome, config) {
|
|
173
|
+
const contradictionFindings = [];
|
|
174
|
+
const resources = outcome.resources.map((resource) => {
|
|
175
|
+
const facts = tableFactsOf(resource);
|
|
176
|
+
if (facts === null)
|
|
177
|
+
return resource;
|
|
178
|
+
const resolution = resolvePlaneByRules(config, {
|
|
179
|
+
sourcePath: facts.sourcePath,
|
|
180
|
+
tableName: facts.tableName,
|
|
181
|
+
classSimpleName: facts.classSimpleName,
|
|
182
|
+
});
|
|
183
|
+
if (resolution.conflict) {
|
|
184
|
+
contradictionFindings.push(planeContradictionFinding(facts, resource.location, resolution.hits));
|
|
185
|
+
}
|
|
186
|
+
if (resolution.plane === null)
|
|
187
|
+
return resource;
|
|
188
|
+
return { ...resource, attributes: { ...resource.attributes, plane: resolution.plane } };
|
|
189
|
+
});
|
|
190
|
+
contradictionFindings.sort(compareFindings);
|
|
191
|
+
return {
|
|
192
|
+
resources,
|
|
193
|
+
unresolved: outcome.unresolved,
|
|
194
|
+
findings: [...outcome.findings, ...contradictionFindings],
|
|
195
|
+
classificationSignals: outcome.classificationSignals,
|
|
196
|
+
...(outcome.scannedPaths !== undefined ? { scannedPaths: outcome.scannedPaths } : {}),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Creates a discover-capable detector module. The default export of the
|
|
201
|
+
* pack is `createSqlalchemyDetector()` — the CLI in-process contract.
|
|
202
|
+
*
|
|
203
|
+
* Plane channels, in strict precedence order: the programmatic
|
|
204
|
+
* `options.plane` rule (config channel not read at all), then the
|
|
205
|
+
* explicit `options.planesConfig`, then the `.gateforge/planes.json`
|
|
206
|
+
* document read from the working directory at discover time (absence
|
|
207
|
+
* normal → `NO_PLANE_MAPPING` behavior byte-identical; malformed
|
|
208
|
+
* throws).
|
|
209
|
+
*
|
|
210
|
+
* Args:
|
|
211
|
+
* options: Plane mapping, spawn command/env, and handshake identity.
|
|
212
|
+
*
|
|
213
|
+
* Returns:
|
|
214
|
+
* SqlalchemyDetector: the pinned `{ discover(paths) }` module.
|
|
215
|
+
*/
|
|
216
|
+
export function createSqlalchemyDetector(options = {}) {
|
|
217
|
+
const plane = options.plane;
|
|
218
|
+
const command = options.command ?? DEFAULT_COMMAND;
|
|
219
|
+
const env = options.env ?? pythonEnvironment();
|
|
220
|
+
const pluginId = options.pluginId ?? PACK_PLUGIN_ID;
|
|
221
|
+
const pluginVersion = options.pluginVersion ?? PACK_VERSION;
|
|
222
|
+
return {
|
|
223
|
+
async discover(paths) {
|
|
224
|
+
if (paths.length === 0) {
|
|
225
|
+
return { resources: [], unresolved: [], findings: [], classificationSignals: [] };
|
|
226
|
+
}
|
|
227
|
+
const session = new PluginSession({
|
|
228
|
+
command: [...command],
|
|
229
|
+
pluginId,
|
|
230
|
+
pluginVersion,
|
|
231
|
+
cwd: process.cwd(),
|
|
232
|
+
env,
|
|
233
|
+
timeouts: { handshakeMs: 10_000, requestMs: 30_000, shutdownMs: 10_000 },
|
|
234
|
+
});
|
|
235
|
+
try {
|
|
236
|
+
await session.start();
|
|
237
|
+
const outcome = await session.discover([...paths]);
|
|
238
|
+
const withSignals = {
|
|
239
|
+
resources: outcome.resources,
|
|
240
|
+
unresolved: outcome.unresolved,
|
|
241
|
+
findings: outcome.findings,
|
|
242
|
+
classificationSignals: outcome.classificationSignals,
|
|
243
|
+
...(outcome.scannedPaths !== undefined ? { scannedPaths: outcome.scannedPaths } : {}),
|
|
244
|
+
};
|
|
245
|
+
if (plane !== undefined) {
|
|
246
|
+
return planeIsNoop(plane) ? withSignals : applyPlaneMapping(withSignals, plane);
|
|
247
|
+
}
|
|
248
|
+
const config = options.planesConfig ??
|
|
249
|
+
readPlanesConfigOrNull(resolve(process.cwd(), options.planesConfigPath ?? PLANES_CONFIG_PATH));
|
|
250
|
+
if (config.rules.length === 0) {
|
|
251
|
+
return withSignals; // no rules: byte-identical to NO_PLANE_MAPPING
|
|
252
|
+
}
|
|
253
|
+
return applyPlanesConfig(withSignals, config);
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
await session.dispose();
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** True when a plane rule can never map anything. */
|
|
262
|
+
function planeIsNoop(plane) {
|
|
263
|
+
return plane === NO_PLANE_MAPPING;
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mapp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AC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACtF,CAAC;gBACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACxB,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;gBAClF,CAAC;gBACD,MAAM,MAAM,GACV,OAAO,CAAC,YAAY;oBACpB,sBAAsB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,gBAAgB,IAAI,kBAAkB,CAAC,CAAC,CAAC;gBACjG,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,CAAC,CAAC;YAChD,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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
2
|
+
export { createSqlalchemyDetector, DEFAULT_COMMAND, pythonEnvironment, applyPlaneMapping, applyPlanesConfig, PLANE_RULE_CONTRADICTION, type SqlalchemyDetector, type SqlalchemyDetectorOptions, } from './detector.js';
|
|
3
|
+
export { DEFAULT_PLANES_CONFIG, NO_PLANE_MAPPING, PLANES_CONFIG_PATH, byTableName, planeRuleMatches, readPlanesConfigOrNull, resolvePlaneByRules, type PlaneConfigRule, type PlaneContext, type PlaneMatchInput, type PlaneResolution, type PlaneRule, type PlaneRuleHit, type PlanesConfig, type SqlalchemyPlane, } from './planes.js';
|
|
4
|
+
export { EntityAdapterSchema, validateEntityAdapter, type EntityAdapter, type EntityAdapterContext, type NormalizedEntity, type EntityAdapterValidation, } from './adapter-schema.js';
|
|
5
|
+
/** The default CLI in-process plugin module: `{ discover(paths) }`. */
|
|
6
|
+
declare const _default: import("./detector.js").SqlalchemyDetector;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gate-forge/pack-sqlalchemy — SQLAlchemy CRUD discovery pack.
|
|
3
|
+
*
|
|
4
|
+
* Detects SQLAlchemy tables from Python source (AST only, stdlib, no
|
|
5
|
+
* imports/execution) and exposes the pinned GPP/3 discovery vocabulary
|
|
6
|
+
* of the resource graph: business `sqlalchemy.table` resources,
|
|
7
|
+
* `gateforge.class` symbol resources for cross-module inheritance
|
|
8
|
+
* resolution, typed `unresolved` entries for computed names (GF-21),
|
|
9
|
+
* and `DUPLICATE_TABLE_NAME` / `CLASS_NAME_REPEATED_IN_FILE` /
|
|
10
|
+
* `PARSE_ERROR` findings (GF-20/GF-01/GF-19).
|
|
11
|
+
*
|
|
12
|
+
* The default export is the CLI in-process plugin contract
|
|
13
|
+
* (`discover(paths)`); the same python detector runs under the CLI's
|
|
14
|
+
* subprocess transport via `python3 -m gateforge_sqlalchemy_detector`.
|
|
15
|
+
* Plane evidence is configured declaratively via `.gateforge/planes.json`
|
|
16
|
+
* (or programmatically via the factory); declarative rules resolve with
|
|
17
|
+
* explicit-beats-general precedence — a table claimed by a `tables`
|
|
18
|
+
* rule ignores `match` globs, and conflicts fail closed within a tier.
|
|
19
|
+
*
|
|
20
|
+
* See README.md for setup, both transports, the plane-config schema and
|
|
21
|
+
* evaluation semantics, the classification workflow, and the
|
|
22
|
+
* entity-adapter schema + example adapter.
|
|
23
|
+
*/
|
|
24
|
+
import { createSqlalchemyDetector } from './detector.js';
|
|
25
|
+
export { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
26
|
+
export { createSqlalchemyDetector, DEFAULT_COMMAND, pythonEnvironment, applyPlaneMapping, applyPlanesConfig, PLANE_RULE_CONTRADICTION, } from './detector.js';
|
|
27
|
+
export { DEFAULT_PLANES_CONFIG, NO_PLANE_MAPPING, PLANES_CONFIG_PATH, byTableName, planeRuleMatches, readPlanesConfigOrNull, resolvePlaneByRules, } from './planes.js';
|
|
28
|
+
export { EntityAdapterSchema, validateEntityAdapter, } from './adapter-schema.js';
|
|
29
|
+
/** The default CLI in-process plugin module: `{ discover(paths) }`. */
|
|
30
|
+
export default createSqlalchemyDetector();
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,mBAAmB,GASpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAKtB,MAAM,qBAAqB,CAAC;AAC7B,uEAAuE;AACvE,eAAe,wBAAwB,EAAE,CAAC"}
|