@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,68 @@
|
|
|
1
|
+
"""AST-only SQLAlchemy table discovery for Gateforge (GPP/3 detector).
|
|
2
|
+
|
|
3
|
+
Parses Python source with the stdlib ``ast`` module and reports
|
|
4
|
+
SQLAlchemy declarative tables, abstract bases, and raw ``Table()``
|
|
5
|
+
declarations WITHOUT importing or executing any application code
|
|
6
|
+
(plan §4.1). Stdlib only (Python >= 3.11); the GPP/3 serve loop lives in
|
|
7
|
+
``__main__.py`` and uses the reference client from
|
|
8
|
+
``@gate-forge/plugin-protocol``.
|
|
9
|
+
|
|
10
|
+
Detector vocabulary (frozen with the pack):
|
|
11
|
+
- Business resources: ``kind`` ``sqlalchemy.table``; the identity
|
|
12
|
+
attribute ``resourceName`` carries the literal table name. Class
|
|
13
|
+
declarations additionally carry ``classQname`` (dotted scope-qualified
|
|
14
|
+
name), ``scope``, ``tableName``, ``tablenameProvenance``,
|
|
15
|
+
``hasTableArgs``/``tableArgsSchema``, ``tableKeywordTrue``,
|
|
16
|
+
``abstract`` (always ``false`` for tables), and ``baseNames``.
|
|
17
|
+
- Class-symbol resources: ``kind`` ``gateforge.class`` with the graph's
|
|
18
|
+
canonical attributes ``qname``, ``resourceKind``, ``baseNames``,
|
|
19
|
+
``tableName``, ``abstract``, ``tablenameUnresolved`` (GF-01/02 ID
|
|
20
|
+
rules; cross-module inheritance is resolved by the graph's symbol
|
|
21
|
+
table, never by this detector).
|
|
22
|
+
- Table-candidate recognition (phase 2, detector precision): ONLY
|
|
23
|
+
classes with explicit table facts or a base that conservatively
|
|
24
|
+
resolves to a declarative base are candidates — the exact
|
|
25
|
+
conventional name ``Base``, literal ``DeclarativeBase``, a locally
|
|
26
|
+
registered declarative alias (``declarative_base()``,
|
|
27
|
+
``registry().generate_base()``, ``class X(DeclarativeBase)``), or the
|
|
28
|
+
simple name of an already-detected model class (inheritance closure
|
|
29
|
+
to a fixpoint). Base names bound (possibly via import aliasing) from
|
|
30
|
+
known non-ORM families — ``pydantic``, ``abc``, ``enum``,
|
|
31
|
+
``argparse``, ``dataclasses``, ``marshmallow``, ``fastapi`` — can
|
|
32
|
+
never qualify. A non-candidate class is emitted NOWHERE: no symbol,
|
|
33
|
+
no table, no unresolved entry.
|
|
34
|
+
- ``unresolved`` entries: typed reasons (``computed_tablename``,
|
|
35
|
+
``table_name_derived_runtime``, ``no_tablename_source``) located at
|
|
36
|
+
the class statement; the graph retires them when it resolves the name
|
|
37
|
+
and synthesizes ``inherited_tablename_unresolved`` when it cannot
|
|
38
|
+
(GF-21: computed identity is typed, never absent).
|
|
39
|
+
- ``classificationSignals`` (plan phase 3, ADR 0003 D1): code-derived
|
|
40
|
+
FACTS for the core classifier — ordered ``identity`` (primary-key)
|
|
41
|
+
signals; ``delete-semantics``/``archive-state``/``lifecycle.*``
|
|
42
|
+
declaration signals from the machine-readable declarations
|
|
43
|
+
``__gateforge_delete_semantics__``, ``__gateforge_archive_state__``,
|
|
44
|
+
``__gateforge_read_only__``; never an exposure claim (a table
|
|
45
|
+
declaration proves nothing about external reachability).
|
|
46
|
+
- additional table attributes: ``primaryKeyColumns``,
|
|
47
|
+
``foreignKeyReferences`` (literal ``ForeignKey`` targets),
|
|
48
|
+
``softDeleteCandidateFields`` (bookkeeping-resembling column names —
|
|
49
|
+
facts for reviewers, never semantics), ``readOnly``.
|
|
50
|
+
- additional unresolved entries: ``PRIMARY_KEY_UNRESOLVED`` (computed
|
|
51
|
+
or invisible primary key — the key is never defaulted to ``id``) and
|
|
52
|
+
``ARCHIVE_STATE_UNRESOLVED`` (non-literal archive declaration).
|
|
53
|
+
- ``findings``: ``DUPLICATE_TABLE_NAME`` (GF-20: 2-file and 1-file
|
|
54
|
+
variants), ``CLASS_NAME_REPEATED_IN_FILE`` (GF-01 non-collapse), and
|
|
55
|
+
``PARSE_ERROR`` (GF-19: malformed files never crash the scan and
|
|
56
|
+
contribute no resources).
|
|
57
|
+
|
|
58
|
+
Determinism contract (plan invariant 7): identical input paths and file
|
|
59
|
+
bytes produce byte-identical output. No clocks, no network, no
|
|
60
|
+
randomness; every emitted array is sorted; every name is a literal from
|
|
61
|
+
the AST; ``json.dumps(..., sort_keys=True)`` in the client frame is the
|
|
62
|
+
canonical serializer.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
from __future__ import annotations
|
|
66
|
+
|
|
67
|
+
PLUGIN_ID = "gateforge.pack-sqlalchemy"
|
|
68
|
+
VERSION = "0.1.0"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""GPP/3 serve entry for the Gateforge SQLAlchemy detector.
|
|
3
|
+
|
|
4
|
+
Runnable as a module so the CLI's subprocess transport can invoke it with
|
|
5
|
+
``python3 -m gateforge_sqlalchemy_detector`` (G4 surface): handshake,
|
|
6
|
+
one lock-step ``discover`` per request, shutdown handshake — all through
|
|
7
|
+
the reference client in @gate-forge/plugin-protocol (stdlib only).
|
|
8
|
+
|
|
9
|
+
The module locates the ``gateforge_plugin`` client itself: when it is not
|
|
10
|
+
importable from the environment (e.g. only this pack's ``python/`` dir is
|
|
11
|
+
on ``PYTHONPATH`` in the monorepo layout), the sibling copy shipped by
|
|
12
|
+
``packages/plugin-protocol/python`` is bootstrapped onto ``sys.path``.
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
python3 -m gateforge_sqlalchemy_detector [root]
|
|
16
|
+
# root: scan root (default: process cwd, which the CLI sets to the
|
|
17
|
+
# repo root); every discover path resolves under it.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import sys
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
try: # installed / environment-provided client
|
|
26
|
+
from gateforge_plugin import ProtocolError, serve
|
|
27
|
+
except ImportError: # monorepo bootstrap: ../plugin-protocol/python
|
|
28
|
+
_protocol_py = Path(__file__).resolve().parents[3] / "plugin-protocol" / "python"
|
|
29
|
+
sys.path.insert(0, str(_protocol_py))
|
|
30
|
+
from gateforge_plugin import ProtocolError, serve # noqa: E402
|
|
31
|
+
|
|
32
|
+
from gateforge_sqlalchemy_detector import PLUGIN_ID, VERSION
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_scan_root = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _discover(paths: list[str]) -> dict:
|
|
39
|
+
"""GPP/3 discover handler: scans each repo-relative path in order."""
|
|
40
|
+
from gateforge_sqlalchemy_detector import scan
|
|
41
|
+
|
|
42
|
+
return scan.scan(paths, _scan_root)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
try:
|
|
47
|
+
raise SystemExit(serve(PLUGIN_ID, VERSION, _discover))
|
|
48
|
+
except ProtocolError as error:
|
|
49
|
+
print(f"gateforge_sqlalchemy_detector: {error}", file=sys.stderr)
|
|
50
|
+
raise SystemExit(4) from None
|