@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
package/dist/planes.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional plane attribution helpers for the SQLAlchemy detector.
|
|
3
|
+
*
|
|
4
|
+
* Core derives business meaning from normalized classification signals.
|
|
5
|
+
* Two channels feed `attributes.plane` on `sqlalchemy.table` resources:
|
|
6
|
+
*
|
|
7
|
+
* - a programmatic {@link PlaneRule} (the detector factory option; for
|
|
8
|
+
* host code and tests); and
|
|
9
|
+
* - the declarative `.gateforge/planes.json` document — an explicit,
|
|
10
|
+
* human-reviewed config file (every rule must carry a non-empty
|
|
11
|
+
* `reason`, the review artifact). A `match` rule may additionally
|
|
12
|
+
* carry `exclude` — repo-root-relative globs pruning whole FILES from
|
|
13
|
+
* the rule's surface (a directory surface mixing planes, e.g.
|
|
14
|
+
* contractor-scoped routers beside global-ingress endpoints under one
|
|
15
|
+
* `backend/api/v1/`, needs those exceptions documented; exclusion is
|
|
16
|
+
* explicit and reviewed here, unlike silent precedence between
|
|
17
|
+
* overlapping rules). Rules resolve in two tiers with
|
|
18
|
+
* EXPLICIT-BEATS-GENERAL precedence: a table claimed by ANY `tables`
|
|
19
|
+
* rule (explicit enumeration) resolves ONLY against `tables` rules —
|
|
20
|
+
* `match` (glob) rules are ignored for it; glob rules apply only to
|
|
21
|
+
* tables no explicit rule claims. WHY: an enumerated name list is a
|
|
22
|
+
* more specific human claim than a directory glob, and a glob's
|
|
23
|
+
* `exclude` prunes source files — it cannot enumerate table-name
|
|
24
|
+
* claims — so cross-tier overlap must not read as contradiction.
|
|
25
|
+
* Within a tier: agreement applies the plane; disagreement emits a
|
|
26
|
+
* blocking `PLANE_RULE_CONTRADICTION` finding and applies nothing;
|
|
27
|
+
* NO matching rule applies nothing either — the resource stays
|
|
28
|
+
* plane-unresolved and the core classifier blocks it, forcing the
|
|
29
|
+
* config author to cover every table (closed-world completeness).
|
|
30
|
+
*
|
|
31
|
+
* Absence of the config file is normal and byte-identical to
|
|
32
|
+
* {@link NO_PLANE_MAPPING}; a malformed document throws (fail closed).
|
|
33
|
+
*/
|
|
34
|
+
/** The plane enum the graph accepts. */
|
|
35
|
+
export type SqlalchemyPlane = 'tenant' | 'master' | 'global';
|
|
36
|
+
/** Facts about one table resource a plane rule can key on. */
|
|
37
|
+
export interface PlaneContext {
|
|
38
|
+
tableName: string;
|
|
39
|
+
classQname: string | null;
|
|
40
|
+
provenance: string;
|
|
41
|
+
}
|
|
42
|
+
/** A plane rule returns a plane, or null to leave binding to core. */
|
|
43
|
+
export type PlaneRule = (context: PlaneContext) => SqlalchemyPlane | null;
|
|
44
|
+
/** The empty rule; core derives plane from normalized signals. */
|
|
45
|
+
export declare const NO_PLANE_MAPPING: PlaneRule;
|
|
46
|
+
/** Rule that maps table names to planes; unmapped tables stay null. */
|
|
47
|
+
export declare function byTableName(mapping: Record<string, SqlalchemyPlane>): PlaneRule;
|
|
48
|
+
/** Repo-root-relative location of the declarative plane config document. */
|
|
49
|
+
export declare const PLANES_CONFIG_PATH = ".gateforge/planes.json";
|
|
50
|
+
/** One reviewed rule of the declarative plane config. */
|
|
51
|
+
export interface PlaneConfigRule {
|
|
52
|
+
/**
|
|
53
|
+
* Repo-root-relative glob matched against the resource's SOURCE FILE
|
|
54
|
+
* path, with core's classifier glob semantics (`*` within one path
|
|
55
|
+
* segment, `**` across segments, `?` one character).
|
|
56
|
+
*/
|
|
57
|
+
readonly match?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Explicit names matched against the resource's table `resourceName`
|
|
60
|
+
* OR its class simple name. Matching either is deliberate: the table
|
|
61
|
+
* name and the declaring class name are both identity evidence for
|
|
62
|
+
* the same resource. Explicit-beats-general: any table claimed here
|
|
63
|
+
* resolves only against `tables` rules — `match` globs are ignored
|
|
64
|
+
* for it (an enumeration is a more specific human claim, and a
|
|
65
|
+
* glob's `exclude` prunes source files, not table names).
|
|
66
|
+
*/
|
|
67
|
+
readonly tables?: readonly string[];
|
|
68
|
+
/**
|
|
69
|
+
* Repo-root-relative globs pruning whole FILES from this rule's
|
|
70
|
+
* surface: when the resource's source path matches ANY of them the
|
|
71
|
+
* rule does not apply at all (checked before tier collection, so an
|
|
72
|
+
* excluded file cannot collide with a narrower per-file rule).
|
|
73
|
+
* Valid only together with `match` — the reader rejects
|
|
74
|
+
* `tables` + `exclude` at read time. WHY: real directory surfaces
|
|
75
|
+
* mix planes (a `backend/api/v1/**` of contractor-scoped routers
|
|
76
|
+
* beside global-ingress files such as `public_payment.py`); without
|
|
77
|
+
* a documented exclusion the narrow per-file rules collide with the
|
|
78
|
+
* directory glob inside one tier and block as
|
|
79
|
+
* `PLANE_RULE_CONTRADICTION`. The exceptions live here, explicit and
|
|
80
|
+
* reviewed (they ride the same `reason` artifact), rather than being
|
|
81
|
+
* resolved by silent rule precedence.
|
|
82
|
+
*/
|
|
83
|
+
readonly exclude?: readonly string[];
|
|
84
|
+
/** The plane this rule asserts (strictly `tenant`|`master`|`global`). */
|
|
85
|
+
readonly plane: SqlalchemyPlane;
|
|
86
|
+
/** Required non-empty human rationale; rides conflict diagnostics. */
|
|
87
|
+
readonly reason: string;
|
|
88
|
+
}
|
|
89
|
+
/** Parsed `.gateforge/planes.json` document (strict schema). */
|
|
90
|
+
export interface PlanesConfig {
|
|
91
|
+
readonly rules: readonly PlaneConfigRule[];
|
|
92
|
+
}
|
|
93
|
+
/** The absent-config default: no rules, no mapping (byte-identical noop). */
|
|
94
|
+
export declare const DEFAULT_PLANES_CONFIG: PlanesConfig;
|
|
95
|
+
/**
|
|
96
|
+
* Reads a declarative plane config document. Returns the default config
|
|
97
|
+
* when the file is absent (normal; byte-identical to
|
|
98
|
+
* {@link NO_PLANE_MAPPING}); malformed documents throw (fail closed —
|
|
99
|
+
* the CLI surfaces the error instead of scanning with partial trust).
|
|
100
|
+
*
|
|
101
|
+
* Accepted shape: `{ rules: [{ match?, exclude?, tables?, plane, reason }] }` — a
|
|
102
|
+
* rule carries EXACTLY ONE of `match` (repo-root-relative source-path
|
|
103
|
+
* glob) or `tables` (explicit tableName / class-simple-name list),
|
|
104
|
+
* always with a strict `plane` and a non-empty human `reason`; a
|
|
105
|
+
* `match` rule may additionally carry `exclude` (a non-empty list of
|
|
106
|
+
* repo-root-relative globs pruning files from its surface — rejected
|
|
107
|
+
* on a `tables` rule).
|
|
108
|
+
*/
|
|
109
|
+
export declare function readPlanesConfigOrNull(path: string | null): PlanesConfig;
|
|
110
|
+
/** The facts one `sqlalchemy.table` resource is matched against. */
|
|
111
|
+
export interface PlaneMatchInput {
|
|
112
|
+
/** Repo-root-relative source file path of the resource. */
|
|
113
|
+
readonly sourcePath: string;
|
|
114
|
+
/** The table name (`attributes.resourceName`). */
|
|
115
|
+
readonly tableName: string;
|
|
116
|
+
/** Simple (last `.`-segment) class name; null for Table()-call resources. */
|
|
117
|
+
readonly classSimpleName: string | null;
|
|
118
|
+
}
|
|
119
|
+
/** One rule that matched a resource (config order preserved). */
|
|
120
|
+
export interface PlaneRuleHit {
|
|
121
|
+
/** The rule's 0-based index in the config document. */
|
|
122
|
+
readonly index: number;
|
|
123
|
+
/** The plane the rule asserts. */
|
|
124
|
+
readonly plane: SqlalchemyPlane;
|
|
125
|
+
/** The rule's human review rationale. */
|
|
126
|
+
readonly reason: string;
|
|
127
|
+
}
|
|
128
|
+
/** The deterministic outcome of rule evaluation for one resource. */
|
|
129
|
+
export interface PlaneResolution {
|
|
130
|
+
/**
|
|
131
|
+
* The agreed plane, or null when NO rule of the resource's deciding
|
|
132
|
+
* tier matched or that tier's rules conflict (fail closed: never
|
|
133
|
+
* guess between planes).
|
|
134
|
+
*/
|
|
135
|
+
readonly plane: SqlalchemyPlane | null;
|
|
136
|
+
/**
|
|
137
|
+
* Every hit of the DECIDING tier, in config order — the `tables`
|
|
138
|
+
* tier when any `tables` rule claimed the resource, else the `match`
|
|
139
|
+
* tier (diagnostics input).
|
|
140
|
+
*/
|
|
141
|
+
readonly hits: readonly PlaneRuleHit[];
|
|
142
|
+
/** True when ≥2 rules of the deciding tier matched and disagree. */
|
|
143
|
+
readonly conflict: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Whether one config rule matches one table resource. A `match` rule
|
|
147
|
+
* globs the resource's repo-root-relative SOURCE FILE path with core's
|
|
148
|
+
* classifier glob semantics (`pathInScope`: `*` within one segment,
|
|
149
|
+
* `**` across segments, `?` one character; whole-path, case-sensitive)
|
|
150
|
+
* — and when the rule carries `exclude`, ANY matching exclusion glob
|
|
151
|
+
* removes the resource's source file from the rule's surface entirely
|
|
152
|
+
* (the documented exception wins over the directory glob; checked
|
|
153
|
+
* first, so an excluded file can never collide with a narrower rule).
|
|
154
|
+
* A `tables` rule matches when ANY listed name equals the table
|
|
155
|
+
* `resourceName` OR the class simple name — deliberately either: table
|
|
156
|
+
* names and class names are both identity evidence. The reader rejects
|
|
157
|
+
* `exclude` on `tables` rules, but the check sits ahead of the branch
|
|
158
|
+
* so hand-built configs cannot resurrect an excluded rule either way.
|
|
159
|
+
*/
|
|
160
|
+
export declare function planeRuleMatches(rule: PlaneConfigRule, input: PlaneMatchInput): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Deterministic, fail-closed rule evaluation in two tiers with
|
|
163
|
+
* explicit-beats-general precedence: a table claimed by ANY `tables`
|
|
164
|
+
* rule resolves ONLY against `tables` rules — `match` (glob) rules are
|
|
165
|
+
* ignored for it; glob rules apply only to tables no explicit rule
|
|
166
|
+
* claims. WHY: an enumerated name list is a more specific human claim
|
|
167
|
+
* than a directory glob, and a glob's `exclude` prunes source files —
|
|
168
|
+
* it cannot enumerate table-name claims — so cross-tier overlap must
|
|
169
|
+
* not read as contradiction. Within the deciding tier: every hit
|
|
170
|
+
* agreeing → that plane; any disagreement → `conflict` with no plane
|
|
171
|
+
* (fail closed: never guess between planes); no hit → no plane. The
|
|
172
|
+
* no-match case is deliberate: the resource stays plane-unresolved and
|
|
173
|
+
* the core classifier blocks it, so a config covers every table or the
|
|
174
|
+
* gate stays red (closed-world completeness).
|
|
175
|
+
*/
|
|
176
|
+
export declare function resolvePlaneByRules(config: PlanesConfig, input: PlaneMatchInput): PlaneResolution;
|
|
177
|
+
//# sourceMappingURL=planes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CA0BxE;AAED,oEAAoE;AACpE,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AAED,iEAAiE;AACjE,MAAM,WAAW,YAAY;IAC3B,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,CAAC;IACvC,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAWvF;AAoCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,GAAG,eAAe,CAQjG"}
|
package/dist/planes.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional plane attribution helpers for the SQLAlchemy detector.
|
|
3
|
+
*
|
|
4
|
+
* Core derives business meaning from normalized classification signals.
|
|
5
|
+
* Two channels feed `attributes.plane` on `sqlalchemy.table` resources:
|
|
6
|
+
*
|
|
7
|
+
* - a programmatic {@link PlaneRule} (the detector factory option; for
|
|
8
|
+
* host code and tests); and
|
|
9
|
+
* - the declarative `.gateforge/planes.json` document — an explicit,
|
|
10
|
+
* human-reviewed config file (every rule must carry a non-empty
|
|
11
|
+
* `reason`, the review artifact). A `match` rule may additionally
|
|
12
|
+
* carry `exclude` — repo-root-relative globs pruning whole FILES from
|
|
13
|
+
* the rule's surface (a directory surface mixing planes, e.g.
|
|
14
|
+
* contractor-scoped routers beside global-ingress endpoints under one
|
|
15
|
+
* `backend/api/v1/`, needs those exceptions documented; exclusion is
|
|
16
|
+
* explicit and reviewed here, unlike silent precedence between
|
|
17
|
+
* overlapping rules). Rules resolve in two tiers with
|
|
18
|
+
* EXPLICIT-BEATS-GENERAL precedence: a table claimed by ANY `tables`
|
|
19
|
+
* rule (explicit enumeration) resolves ONLY against `tables` rules —
|
|
20
|
+
* `match` (glob) rules are ignored for it; glob rules apply only to
|
|
21
|
+
* tables no explicit rule claims. WHY: an enumerated name list is a
|
|
22
|
+
* more specific human claim than a directory glob, and a glob's
|
|
23
|
+
* `exclude` prunes source files — it cannot enumerate table-name
|
|
24
|
+
* claims — so cross-tier overlap must not read as contradiction.
|
|
25
|
+
* Within a tier: agreement applies the plane; disagreement emits a
|
|
26
|
+
* blocking `PLANE_RULE_CONTRADICTION` finding and applies nothing;
|
|
27
|
+
* NO matching rule applies nothing either — the resource stays
|
|
28
|
+
* plane-unresolved and the core classifier blocks it, forcing the
|
|
29
|
+
* config author to cover every table (closed-world completeness).
|
|
30
|
+
*
|
|
31
|
+
* Absence of the config file is normal and byte-identical to
|
|
32
|
+
* {@link NO_PLANE_MAPPING}; a malformed document throws (fail closed).
|
|
33
|
+
*/
|
|
34
|
+
import { readFileSync } from 'node:fs';
|
|
35
|
+
import { globMatch } from '@gate-forge/core';
|
|
36
|
+
/** The empty rule; core derives plane from normalized signals. */
|
|
37
|
+
export const NO_PLANE_MAPPING = () => null;
|
|
38
|
+
/** Rule that maps table names to planes; unmapped tables stay null. */
|
|
39
|
+
export function byTableName(mapping) {
|
|
40
|
+
const table = new Map(Object.entries(mapping));
|
|
41
|
+
return (context) => table.get(context.tableName) ?? null;
|
|
42
|
+
}
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Declarative plane config (`.gateforge/planes.json`)
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
/** Repo-root-relative location of the declarative plane config document. */
|
|
47
|
+
export const PLANES_CONFIG_PATH = '.gateforge/planes.json';
|
|
48
|
+
/** The absent-config default: no rules, no mapping (byte-identical noop). */
|
|
49
|
+
export const DEFAULT_PLANES_CONFIG = { rules: [] };
|
|
50
|
+
/** The plane values a rule may assert, in canonical order. */
|
|
51
|
+
const PLANES = ['tenant', 'master', 'global'];
|
|
52
|
+
/** The only keys a rule object may carry. */
|
|
53
|
+
const RULE_KEYS = ['match', 'tables', 'exclude', 'plane', 'reason'];
|
|
54
|
+
/**
|
|
55
|
+
* Validates one repo-root-relative posix glob pattern. Rejects
|
|
56
|
+
* absolute, drive-qualified, backslash, and `..`-escaping patterns with
|
|
57
|
+
* a single-cause error (same posture as the graph's source-path
|
|
58
|
+
* normalizer — a pattern escaping the repo root would silently match
|
|
59
|
+
* nothing and hide exactly the tables the rule exists to cover).
|
|
60
|
+
* `field` names the error location: `'match'` for the rule's own
|
|
61
|
+
* pattern, `exclude[N]` for one exclusion entry.
|
|
62
|
+
*/
|
|
63
|
+
function validateMatchPattern(raw, path, index, field) {
|
|
64
|
+
const at = `rules[${index}].${field}`;
|
|
65
|
+
if (typeof raw !== 'string' || raw.length === 0) {
|
|
66
|
+
throw new Error(`invalid planes config: ${at} must be a non-empty string at ${path}`);
|
|
67
|
+
}
|
|
68
|
+
if (raw.includes('\\')) {
|
|
69
|
+
throw new Error(`invalid planes config: ${at} must use posix '/' separators ` +
|
|
70
|
+
`(repo-root-relative) at ${path}: ${JSON.stringify(raw)}`);
|
|
71
|
+
}
|
|
72
|
+
if (raw.startsWith('/') || /^[A-Za-z]:/.test(raw)) {
|
|
73
|
+
throw new Error(`invalid planes config: ${at} must be a repo-root-relative glob ` +
|
|
74
|
+
`at ${path}: ${JSON.stringify(raw)}`);
|
|
75
|
+
}
|
|
76
|
+
if (raw.split('/').includes('..')) {
|
|
77
|
+
throw new Error(`invalid planes config: ${at} must not escape the repo root ` +
|
|
78
|
+
`('..') at ${path}: ${JSON.stringify(raw)}`);
|
|
79
|
+
}
|
|
80
|
+
return raw;
|
|
81
|
+
}
|
|
82
|
+
/** Validates one `tables` entry list (fail closed on every wrong shape). */
|
|
83
|
+
function validateTables(raw, path, index) {
|
|
84
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
85
|
+
throw new Error(`invalid planes config: rules[${index}].tables must be a non-empty array of names at ${path}`);
|
|
86
|
+
}
|
|
87
|
+
return raw.map((name) => {
|
|
88
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
89
|
+
throw new Error(`invalid planes config: rules[${index}].tables entries must be non-empty strings ` +
|
|
90
|
+
`at ${path}`);
|
|
91
|
+
}
|
|
92
|
+
return name;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Validates one `exclude` entry list (fail closed on every wrong
|
|
97
|
+
* shape): a non-empty array of repo-root-relative posix globs, each
|
|
98
|
+
* pattern-validated exactly like `match` — a malformed exclusion would
|
|
99
|
+
* otherwise silently match nothing and let the rule keep claiming the
|
|
100
|
+
* very file the author meant to except.
|
|
101
|
+
*/
|
|
102
|
+
function validateExclude(raw, path, index) {
|
|
103
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
104
|
+
throw new Error(`invalid planes config: rules[${index}].exclude must be a non-empty array of globs ` +
|
|
105
|
+
`at ${path}`);
|
|
106
|
+
}
|
|
107
|
+
return raw.map((pattern, entry) => validateMatchPattern(pattern, path, index, `exclude[${entry}]`));
|
|
108
|
+
}
|
|
109
|
+
/** Validates one rule object (fail closed; first cause wins, in order). */
|
|
110
|
+
function parsePlaneConfigRule(value, path, index) {
|
|
111
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
112
|
+
throw new Error(`invalid planes config: rules[${index}] must be an object at ${path}`);
|
|
113
|
+
}
|
|
114
|
+
const record = value;
|
|
115
|
+
const unknownKeys = Object.keys(record).filter((key) => !RULE_KEYS.includes(key));
|
|
116
|
+
if (unknownKeys.length > 0) {
|
|
117
|
+
// Strict on purpose: a typo'd key ('planes', 'matsh') would otherwise
|
|
118
|
+
// silently drop a reviewed rule and un-cover exactly its tables.
|
|
119
|
+
throw new Error(`invalid planes config: rules[${index}] has unknown key(s) ` +
|
|
120
|
+
`${unknownKeys.sort().join(', ')} at ${path}`);
|
|
121
|
+
}
|
|
122
|
+
const hasMatch = record['match'] !== undefined;
|
|
123
|
+
const hasTables = record['tables'] !== undefined;
|
|
124
|
+
if (hasMatch === hasTables) {
|
|
125
|
+
throw new Error(`invalid planes config: rules[${index}] must carry exactly one of 'match' or 'tables' ` +
|
|
126
|
+
`at ${path}`);
|
|
127
|
+
}
|
|
128
|
+
const hasExclude = record['exclude'] !== undefined;
|
|
129
|
+
// Mirror the exactly-one-of posture: `exclude` prunes the surface of
|
|
130
|
+
// a source-path glob, so on a `tables` rule it would be dead config —
|
|
131
|
+
// and dead config in a review artifact reads as a review that never
|
|
132
|
+
// happened. Reject instead of silently ignoring.
|
|
133
|
+
if (hasExclude && !hasMatch) {
|
|
134
|
+
throw new Error(`invalid planes config: rules[${index}].exclude is only valid together with 'match' ` +
|
|
135
|
+
`at ${path}`);
|
|
136
|
+
}
|
|
137
|
+
const plane = record['plane'];
|
|
138
|
+
if (!PLANES.includes(plane)) {
|
|
139
|
+
throw new Error(`invalid planes config: rules[${index}].plane must be one of: ` +
|
|
140
|
+
`${PLANES.map((value) => `'${value}'`).join(', ')} at ${path}`);
|
|
141
|
+
}
|
|
142
|
+
const reason = record['reason'];
|
|
143
|
+
if (typeof reason !== 'string' || reason.trim().length === 0) {
|
|
144
|
+
throw new Error(`invalid planes config: rules[${index}].reason must be a non-empty string ` +
|
|
145
|
+
'(the config is a human review artifact) at ' +
|
|
146
|
+
path);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
...(hasMatch
|
|
150
|
+
? {
|
|
151
|
+
match: validateMatchPattern(record['match'], path, index, 'match'),
|
|
152
|
+
...(hasExclude
|
|
153
|
+
? { exclude: validateExclude(record['exclude'], path, index) }
|
|
154
|
+
: {}),
|
|
155
|
+
}
|
|
156
|
+
: { tables: validateTables(record['tables'], path, index) }),
|
|
157
|
+
plane: plane,
|
|
158
|
+
reason,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Reads a declarative plane config document. Returns the default config
|
|
163
|
+
* when the file is absent (normal; byte-identical to
|
|
164
|
+
* {@link NO_PLANE_MAPPING}); malformed documents throw (fail closed —
|
|
165
|
+
* the CLI surfaces the error instead of scanning with partial trust).
|
|
166
|
+
*
|
|
167
|
+
* Accepted shape: `{ rules: [{ match?, exclude?, tables?, plane, reason }] }` — a
|
|
168
|
+
* rule carries EXACTLY ONE of `match` (repo-root-relative source-path
|
|
169
|
+
* glob) or `tables` (explicit tableName / class-simple-name list),
|
|
170
|
+
* always with a strict `plane` and a non-empty human `reason`; a
|
|
171
|
+
* `match` rule may additionally carry `exclude` (a non-empty list of
|
|
172
|
+
* repo-root-relative globs pruning files from its surface — rejected
|
|
173
|
+
* on a `tables` rule).
|
|
174
|
+
*/
|
|
175
|
+
export function readPlanesConfigOrNull(path) {
|
|
176
|
+
if (path === null)
|
|
177
|
+
return DEFAULT_PLANES_CONFIG;
|
|
178
|
+
let text;
|
|
179
|
+
try {
|
|
180
|
+
text = readFileSync(path, 'utf8');
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return DEFAULT_PLANES_CONFIG; // absence is normal; malformed is not (below)
|
|
184
|
+
}
|
|
185
|
+
const parsed = JSON.parse(text);
|
|
186
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
187
|
+
throw new Error(`invalid planes config: expected an object at ${path}`);
|
|
188
|
+
}
|
|
189
|
+
const document = parsed;
|
|
190
|
+
const unknownKeys = Object.keys(document).filter((key) => key !== 'rules');
|
|
191
|
+
if (unknownKeys.length > 0) {
|
|
192
|
+
throw new Error(`invalid planes config: unknown key(s) ${unknownKeys.sort().join(', ')} at ${path}`);
|
|
193
|
+
}
|
|
194
|
+
const rules = document['rules'];
|
|
195
|
+
if (!Array.isArray(rules)) {
|
|
196
|
+
throw new Error(`invalid planes config: 'rules' must be an array of rule objects at ${path}`);
|
|
197
|
+
}
|
|
198
|
+
return { rules: rules.map((rule, index) => parsePlaneConfigRule(rule, path, index)) };
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether one config rule matches one table resource. A `match` rule
|
|
202
|
+
* globs the resource's repo-root-relative SOURCE FILE path with core's
|
|
203
|
+
* classifier glob semantics (`pathInScope`: `*` within one segment,
|
|
204
|
+
* `**` across segments, `?` one character; whole-path, case-sensitive)
|
|
205
|
+
* — and when the rule carries `exclude`, ANY matching exclusion glob
|
|
206
|
+
* removes the resource's source file from the rule's surface entirely
|
|
207
|
+
* (the documented exception wins over the directory glob; checked
|
|
208
|
+
* first, so an excluded file can never collide with a narrower rule).
|
|
209
|
+
* A `tables` rule matches when ANY listed name equals the table
|
|
210
|
+
* `resourceName` OR the class simple name — deliberately either: table
|
|
211
|
+
* names and class names are both identity evidence. The reader rejects
|
|
212
|
+
* `exclude` on `tables` rules, but the check sits ahead of the branch
|
|
213
|
+
* so hand-built configs cannot resurrect an excluded rule either way.
|
|
214
|
+
*/
|
|
215
|
+
export function planeRuleMatches(rule, input) {
|
|
216
|
+
if (rule.exclude !== undefined &&
|
|
217
|
+
rule.exclude.some((pattern) => globMatch(input.sourcePath, pattern))) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (rule.match !== undefined)
|
|
221
|
+
return globMatch(input.sourcePath, rule.match);
|
|
222
|
+
const names = rule.tables ?? [];
|
|
223
|
+
if (names.includes(input.tableName))
|
|
224
|
+
return true;
|
|
225
|
+
return input.classSimpleName !== null && names.includes(input.classSimpleName);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Whether one config rule belongs to the EXPLICIT tier (enumerated
|
|
229
|
+
* `tables` claim). Tier membership, not matching, is what this decides:
|
|
230
|
+
* a resource claimed here never falls through to the glob tier.
|
|
231
|
+
*/
|
|
232
|
+
function isTablesRule(rule) {
|
|
233
|
+
return rule.tables !== undefined;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Whether one config rule belongs to the GENERAL tier (source-path
|
|
237
|
+
* `match` glob, and only a glob — the reader rejects hybrid rules, but
|
|
238
|
+
* hand-built configs must not let a hybrid claim both tiers).
|
|
239
|
+
*/
|
|
240
|
+
function isMatchRule(rule) {
|
|
241
|
+
return rule.tables === undefined && rule.match !== undefined;
|
|
242
|
+
}
|
|
243
|
+
/** All hits of one tier, in config order (deterministic). */
|
|
244
|
+
function collectTierHits(config, input, inTier) {
|
|
245
|
+
const hits = [];
|
|
246
|
+
for (let index = 0; index < config.rules.length; index += 1) {
|
|
247
|
+
const rule = config.rules[index];
|
|
248
|
+
if (rule === undefined || !inTier(rule))
|
|
249
|
+
continue;
|
|
250
|
+
if (!planeRuleMatches(rule, input))
|
|
251
|
+
continue;
|
|
252
|
+
hits.push({ index, plane: rule.plane, reason: rule.reason });
|
|
253
|
+
}
|
|
254
|
+
return hits;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Deterministic, fail-closed rule evaluation in two tiers with
|
|
258
|
+
* explicit-beats-general precedence: a table claimed by ANY `tables`
|
|
259
|
+
* rule resolves ONLY against `tables` rules — `match` (glob) rules are
|
|
260
|
+
* ignored for it; glob rules apply only to tables no explicit rule
|
|
261
|
+
* claims. WHY: an enumerated name list is a more specific human claim
|
|
262
|
+
* than a directory glob, and a glob's `exclude` prunes source files —
|
|
263
|
+
* it cannot enumerate table-name claims — so cross-tier overlap must
|
|
264
|
+
* not read as contradiction. Within the deciding tier: every hit
|
|
265
|
+
* agreeing → that plane; any disagreement → `conflict` with no plane
|
|
266
|
+
* (fail closed: never guess between planes); no hit → no plane. The
|
|
267
|
+
* no-match case is deliberate: the resource stays plane-unresolved and
|
|
268
|
+
* the core classifier blocks it, so a config covers every table or the
|
|
269
|
+
* gate stays red (closed-world completeness).
|
|
270
|
+
*/
|
|
271
|
+
export function resolvePlaneByRules(config, input) {
|
|
272
|
+
const explicit = collectTierHits(config, input, isTablesRule);
|
|
273
|
+
const hits = explicit.length > 0 ? explicit : collectTierHits(config, input, isMatchRule);
|
|
274
|
+
const first = hits[0];
|
|
275
|
+
if (first !== undefined && hits.every((hit) => hit.plane === first.plane)) {
|
|
276
|
+
return { plane: first.plane, hits, conflict: false };
|
|
277
|
+
}
|
|
278
|
+
return { plane: null, hits, conflict: hits.length > 0 };
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=planes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planes.js","sourceRoot":"","sources":["../src/planes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAc7C,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAc,GAAG,EAAE,CAAC,IAAI,CAAC;AAGtD,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,OAAwC;IAClE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;AAC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AK,SAAS,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,SAAS;QAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC;YAAE,SAAS;QAC7C,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAoB,EAAE,KAAsB;IAC9E,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC1F,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACvD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pack identity constants. The GPP/3 handshake pins these values: the
|
|
3
|
+
* `.gateforge.yml` plugin entry MUST declare the same `id` and
|
|
4
|
+
* `version` (see the pack README). The Python detector carries the same
|
|
5
|
+
* constants in `python/gateforge_sqlalchemy_detector/__init__.py` — the
|
|
6
|
+
* cross-language test asserts they agree.
|
|
7
|
+
*/
|
|
8
|
+
/** Plugin id every SQLAlchemy pack contribution is pinned to. */
|
|
9
|
+
export declare const PACK_PLUGIN_ID = "gateforge.pack-sqlalchemy";
|
|
10
|
+
/** Detector/pack version; must match `python/.../__init__.py::VERSION`. */
|
|
11
|
+
export declare const PACK_VERSION = "0.1.0";
|
|
12
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AACjE,eAAO,MAAM,cAAc,8BAA8B,CAAC;AAE1D,2EAA2E;AAC3E,eAAO,MAAM,YAAY,UAAU,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pack identity constants. The GPP/3 handshake pins these values: the
|
|
3
|
+
* `.gateforge.yml` plugin entry MUST declare the same `id` and
|
|
4
|
+
* `version` (see the pack README). The Python detector carries the same
|
|
5
|
+
* constants in `python/gateforge_sqlalchemy_detector/__init__.py` — the
|
|
6
|
+
* cross-language test asserts they agree.
|
|
7
|
+
*/
|
|
8
|
+
/** Plugin id every SQLAlchemy pack contribution is pinned to. */
|
|
9
|
+
export const PACK_PLUGIN_ID = 'gateforge.pack-sqlalchemy';
|
|
10
|
+
/** Detector/pack version; must match `python/.../__init__.py::VERSION`. */
|
|
11
|
+
export const PACK_VERSION = '0.1.0';
|
|
12
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAE1D,2EAA2E;AAC3E,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample entity adapter for the gateforge example app (`example/`):
|
|
3
|
+
* the `accounts` resource, read via `GET /api/accounts/:id`.
|
|
4
|
+
*
|
|
5
|
+
* DOCUMENTATION + SAMPLE ONLY — actual adapter loading is the engine
|
|
6
|
+
* side (witness registry, ADR 0002): adapters live in the project's
|
|
7
|
+
* `.gateforge/adapters/` directory as `<resourceId>.mjs` and are
|
|
8
|
+
* executed ENGINE-SIDE with GET-only transport. Copy this file to
|
|
9
|
+
* `.gateforge/adapters/example.accounts.mjs` in a project that runs the
|
|
10
|
+
* example app and the witness service can prove `example.accounts`
|
|
11
|
+
* persistence evidence.
|
|
12
|
+
*
|
|
13
|
+
* Adapter contract (interface pin #8; the pack's EntityAdapterSchema):
|
|
14
|
+
* - `read(ctx, id)` — GET-only fetch of one entity; never mutates.
|
|
15
|
+
* - `normalize(body)` — project the raw body onto
|
|
16
|
+
* `{ entityId, fields }` (fields carry the classified primaryKey).
|
|
17
|
+
* - `deletion: 'archive'` — the example app archives; rows stay
|
|
18
|
+
* retrievable (no hard delete).
|
|
19
|
+
* - `environmentFingerprint` — the target-environment marker the
|
|
20
|
+
* witness compares against a probe GET (GF-13): the example app
|
|
21
|
+
* must answer with this value in the `x-gateforge-env` response
|
|
22
|
+
* header for the adapter's reads to be accepted.
|
|
23
|
+
* - `resourceId` — registry identity; must match the file name.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Registry identity of the example accounts resource. */
|
|
27
|
+
const RESOURCE_ID = 'example.accounts';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The marker the witness expects on any probe/read response: the
|
|
31
|
+
* example app serves `x-gateforge-env: example-loopback-v1` on every
|
|
32
|
+
* route once wired for gateforge (see the pack README).
|
|
33
|
+
*/
|
|
34
|
+
const ENVIRONMENT_FINGERPRINT = 'example-loopback-v1';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* GET-only entity read against the example app's read API.
|
|
38
|
+
*
|
|
39
|
+
* Args:
|
|
40
|
+
* ctx: Witness-provided context (loopback base URL; optional headers).
|
|
41
|
+
* id: The entity id (`acc-1`, ...).
|
|
42
|
+
*
|
|
43
|
+
* Returns:
|
|
44
|
+
* Promise<unknown>: The raw account object
|
|
45
|
+
* `{ id, first_name, last_name, status, created_at, updated_at }`.
|
|
46
|
+
*
|
|
47
|
+
* Throws:
|
|
48
|
+
* Error: On a fingerprint mismatch (environment attestation) or a
|
|
49
|
+
* non-200/404 status. 404 surfaces as `null` — the entity is gone.
|
|
50
|
+
*/
|
|
51
|
+
async function read(ctx, id) {
|
|
52
|
+
const response = await fetch(`${ctx.baseUrl}/api/accounts/${encodeURIComponent(id)}`, {
|
|
53
|
+
headers: ctx.headers ?? {},
|
|
54
|
+
});
|
|
55
|
+
if (response.status === 404) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
throw new Error(`example accounts adapter: GET /api/accounts/${id} -> ${response.status}`);
|
|
60
|
+
}
|
|
61
|
+
const marker = response.headers.get('x-gateforge-env');
|
|
62
|
+
if (marker !== ENVIRONMENT_FINGERPRINT) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`example accounts adapter: environment fingerprint mismatch ` +
|
|
65
|
+
`(expected ${ENVIRONMENT_FINGERPRINT}, got ${JSON.stringify(marker)})`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return response.json();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Projects the raw account body onto the evidence shape.
|
|
73
|
+
*
|
|
74
|
+
* Args:
|
|
75
|
+
* body: The raw account object from `read`.
|
|
76
|
+
*
|
|
77
|
+
* Returns:
|
|
78
|
+
* { entityId, fields }: The entity id plus the classified primary-key
|
|
79
|
+
* columns and status (archive evidence keys on the status change).
|
|
80
|
+
*/
|
|
81
|
+
function normalize(body) {
|
|
82
|
+
return {
|
|
83
|
+
entityId: String(body.id),
|
|
84
|
+
fields: {
|
|
85
|
+
id: body.id,
|
|
86
|
+
status: body.status,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default {
|
|
92
|
+
resourceId: RESOURCE_ID,
|
|
93
|
+
read,
|
|
94
|
+
normalize,
|
|
95
|
+
deletion: 'archive',
|
|
96
|
+
environmentFingerprint: ENVIRONMENT_FINGERPRINT,
|
|
97
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gate-forge/pack-sqlalchemy",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "SQLAlchemy CRUD discovery pack: AST-only python detector (GPP/3), in-process TS discover entry, configurable plane mapping, entity-adapter schema.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"README.md",
|
|
18
|
+
"dist",
|
|
19
|
+
"examples",
|
|
20
|
+
"python"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.build.json",
|
|
24
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
25
|
+
"test": "vitest run"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@gate-forge/core": "^0.1.0",
|
|
29
|
+
"@gate-forge/plugin-protocol": "^0.1.0",
|
|
30
|
+
"yaml": "^2.8.1",
|
|
31
|
+
"zod": "^4.1.5"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/umiddey/gateforge.git",
|
|
39
|
+
"directory": "packages/pack-sqlalchemy"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/umiddey/gateforge/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/umiddey/gateforge#readme"
|
|
45
|
+
}
|