@gate-forge/pack-validation 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 +43 -0
- package/dist/detector.d.ts +16 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +218 -0
- package/dist/detector.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/obligations.d.ts +21 -0
- package/dist/obligations.d.ts.map +1 -0
- package/dist/obligations.js +26 -0
- package/dist/obligations.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 UKD
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @gate-forge/pack-validation
|
|
2
|
+
|
|
3
|
+
Request-schema validation discovery pack for Gateforge.
|
|
4
|
+
|
|
5
|
+
## What it detects
|
|
6
|
+
|
|
7
|
+
| Library | Detector pattern |
|
|
8
|
+
|-----------------|-------------------------------------------|
|
|
9
|
+
| zod | `z.object({...})` / `zod.object({...})` |
|
|
10
|
+
| joi | `Joi.object({...})` / `joi.object({...})` |
|
|
11
|
+
| yup | `yup.object({...})` |
|
|
12
|
+
| class-validator | class with decorators from `class-validator` |
|
|
13
|
+
|
|
14
|
+
Each detected schema becomes one `validation.schema` resource carrying:
|
|
15
|
+
- `library` — the validation library used
|
|
16
|
+
- `name` — the variable / class name
|
|
17
|
+
- `boundary` — `strict` (zod/joi/class-validator) or `lenient` (yup) by default
|
|
18
|
+
- `fields` — best-effort field map (zod: type + constraints; others: empty)
|
|
19
|
+
|
|
20
|
+
## Obligation vocabulary
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
validation:boundary-accepted
|
|
24
|
+
validation:boundary-rejected
|
|
25
|
+
validation:no-side-effect-on-reject
|
|
26
|
+
validation:error-message-explicit
|
|
27
|
+
validation:envelope-shape-stable
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Limitations
|
|
31
|
+
|
|
32
|
+
- Field extraction is best-effort: zod schemas get a typed field map; joi / yup / class-validator return `fields: {}` for now. A full schema parser is deferred.
|
|
33
|
+
- The detector does not execute user code. Hand-rolled validators without the `validate` / `parse` export convention are NOT recognised.
|
|
34
|
+
- Class-validator requires an `import 'class-validator'` line in the same file.
|
|
35
|
+
- Schema runtime is intentionally NOT bundled — the example server uses an inline zod-like validator to avoid pulling zod into the test environment.
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { default as detector } from '@gate-forge/pack-validation';
|
|
41
|
+
const outcome = detector.discover(['src/']);
|
|
42
|
+
for (const r of outcome.resources) console.log(r.id, r.attributes);
|
|
43
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DiscoveryOutcome } from '@gate-forge/plugin-protocol';
|
|
2
|
+
/** Detector contract: `discover(paths)` is sync (pure over file bytes). */
|
|
3
|
+
export interface ValidationDetector {
|
|
4
|
+
discover(paths: readonly string[]): DiscoveryOutcome;
|
|
5
|
+
}
|
|
6
|
+
/** Options for {@link createValidationDetector}. */
|
|
7
|
+
export interface ValidationDetectorOptions {
|
|
8
|
+
/** Repo root for repo-relative `source` paths (default: `process.cwd()`). */
|
|
9
|
+
root?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Resource kind emitted by this pack. */
|
|
12
|
+
export declare const VALIDATION_SCHEMA_KIND = "validation.schema";
|
|
13
|
+
/** Inferred resource id pattern. */
|
|
14
|
+
export type ValidationResourceId = `validation.${string}.${string}`;
|
|
15
|
+
export declare function createValidationDetector(options?: ValidationDetectorOptions): ValidationDetector;
|
|
16
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAKpE,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAAC;CACtD;AAED,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D,oCAAoC;AACpC,MAAM,MAAM,oBAAoB,GAAG,cAAc,MAAM,IAAI,MAAM,EAAE,CAAC;AAgKpE,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,yBAA8B,GAAG,kBAAkB,CA6BpG"}
|
package/dist/detector.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation pack detector — discovers request-validation schemas in
|
|
3
|
+
* TypeScript / JavaScript source files and emits one `validation.schema`
|
|
4
|
+
* resource per schema definition.
|
|
5
|
+
*
|
|
6
|
+
* Recognised constructs (TS/JS only):
|
|
7
|
+
* - zod: `z.object({...})` / `zod.object({...})` / `schema.parse(...)`
|
|
8
|
+
* - joi: `Joi.object({...})` / `joi.object({...})` / `schema.validate(...)`
|
|
9
|
+
* - yup: `yup.object({...})` / `schema.shape` / `schema.validateSync(...)`
|
|
10
|
+
* - class-validator: classes decorated with `@Validator` and props
|
|
11
|
+
* decorated with `@IsString` / `@MinLength` / `@IsEmail` / etc.
|
|
12
|
+
*
|
|
13
|
+
* Each detected schema becomes a `validation.schema` resource:
|
|
14
|
+
* {
|
|
15
|
+
* id: "validation.<route-or-class-name>.<schemaName>",
|
|
16
|
+
* kind: "validation.schema",
|
|
17
|
+
* attributes: {
|
|
18
|
+
* library: "zod" | "joi" | "yup" | "class-validator",
|
|
19
|
+
* fields: Record<string, { type: string; constraints: string[] }>,
|
|
20
|
+
* boundary: "strict" | "lenient" | "unknown",
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* Discovery is pure (no execution), deterministic (no Date.now /
|
|
25
|
+
* Math.random), and fails closed: malformed schemas surface as
|
|
26
|
+
* `AMBIGUOUS_SCHEMA` findings, never silently emit.
|
|
27
|
+
*/
|
|
28
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
29
|
+
import { readFileSync } from 'node:fs';
|
|
30
|
+
import { GATEFORGE_SCHEMA_VERSION } from '@gate-forge/core';
|
|
31
|
+
import { PACK_VERSION } from './version.js';
|
|
32
|
+
/** Resource kind emitted by this pack. */
|
|
33
|
+
export const VALIDATION_SCHEMA_KIND = 'validation.schema';
|
|
34
|
+
/** Walks a directory non-recursively, returning .ts/.tsx/.js/.mjs paths. */
|
|
35
|
+
function collectFiles(input) {
|
|
36
|
+
const stat = (() => {
|
|
37
|
+
try {
|
|
38
|
+
return require('node:fs').statSync(input);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
if (stat === null)
|
|
45
|
+
return [];
|
|
46
|
+
if (stat.isDirectory()) {
|
|
47
|
+
const { readdirSync } = require('node:fs');
|
|
48
|
+
return readdirSync(input)
|
|
49
|
+
.filter((n) => /\.(ts|tsx|js|mjs)$/.test(n))
|
|
50
|
+
.map((n) => resolve(input, n));
|
|
51
|
+
}
|
|
52
|
+
return [input];
|
|
53
|
+
}
|
|
54
|
+
/** Detects a `z.object({...})` schema declaration. */
|
|
55
|
+
function detectZod(text, file) {
|
|
56
|
+
const out = [];
|
|
57
|
+
// Match `const <name>Schema = z.object({...})` or `zod.object({...})`
|
|
58
|
+
const decl = /(?:export\s+)?const\s+(\w+)\s*=\s*(?:z|zod)\.object\(\s*\{/g;
|
|
59
|
+
let m;
|
|
60
|
+
while ((m = decl.exec(text)) !== null) {
|
|
61
|
+
const name = m[1] ?? 'unknown';
|
|
62
|
+
const line = text.substring(0, m.index).split('\n').length;
|
|
63
|
+
out.push({
|
|
64
|
+
id: `validation.zod.${name.toLowerCase()}`,
|
|
65
|
+
library: 'zod',
|
|
66
|
+
name,
|
|
67
|
+
boundary: 'strict',
|
|
68
|
+
fields: extractZodFields(text, m.index + m[0].length),
|
|
69
|
+
file,
|
|
70
|
+
line,
|
|
71
|
+
col: 0,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/** Best-effort field extraction from a zod object literal start. */
|
|
77
|
+
function extractZodFields(text, openIdx) {
|
|
78
|
+
const out = {};
|
|
79
|
+
let depth = 1;
|
|
80
|
+
let i = openIdx;
|
|
81
|
+
// Walk to the matching closing brace, then regex out field names.
|
|
82
|
+
while (i < text.length && depth > 0) {
|
|
83
|
+
const ch = text[i];
|
|
84
|
+
if (ch === '{')
|
|
85
|
+
depth += 1;
|
|
86
|
+
else if (ch === '}')
|
|
87
|
+
depth -= 1;
|
|
88
|
+
i += 1;
|
|
89
|
+
}
|
|
90
|
+
const body = text.slice(openIdx, i - 1);
|
|
91
|
+
const fieldRe = /(\w+)\s*:\s*z\.(\w+)\s*\(([^)]*)\)/g;
|
|
92
|
+
let fm;
|
|
93
|
+
while ((fm = fieldRe.exec(body)) !== null) {
|
|
94
|
+
out[fm[1] ?? ''] = {
|
|
95
|
+
type: fm[2] ?? 'unknown',
|
|
96
|
+
constraints: (fm[3] ?? '').split(',').map((s) => s.trim()).filter(Boolean),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
/** Detects a `Joi.object({...})` schema declaration. */
|
|
102
|
+
function detectJoi(text, file) {
|
|
103
|
+
const out = [];
|
|
104
|
+
const decl = /(?:export\s+)?const\s+(\w+)\s*=\s*(?:Joi|joi)\.object\(\s*\{/g;
|
|
105
|
+
let m;
|
|
106
|
+
while ((m = decl.exec(text)) !== null) {
|
|
107
|
+
const name = m[1] ?? 'unknown';
|
|
108
|
+
const line = text.substring(0, m.index).split('\n').length;
|
|
109
|
+
out.push({
|
|
110
|
+
id: `validation.joi.${name.toLowerCase()}`,
|
|
111
|
+
library: 'joi',
|
|
112
|
+
name,
|
|
113
|
+
boundary: 'strict',
|
|
114
|
+
fields: {},
|
|
115
|
+
file,
|
|
116
|
+
line,
|
|
117
|
+
col: 0,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** Detects a `yup.object({...})` schema declaration. */
|
|
123
|
+
function detectYup(text, file) {
|
|
124
|
+
const out = [];
|
|
125
|
+
const decl = /(?:export\s+)?const\s+(\w+)\s*=\s*yup\.object\(\s*\{/g;
|
|
126
|
+
let m;
|
|
127
|
+
while ((m = decl.exec(text)) !== null) {
|
|
128
|
+
const name = m[1] ?? 'unknown';
|
|
129
|
+
const line = text.substring(0, m.index).split('\n').length;
|
|
130
|
+
out.push({
|
|
131
|
+
id: `validation.yup.${name.toLowerCase()}`,
|
|
132
|
+
library: 'yup',
|
|
133
|
+
name,
|
|
134
|
+
boundary: 'lenient',
|
|
135
|
+
fields: {},
|
|
136
|
+
file,
|
|
137
|
+
line,
|
|
138
|
+
col: 0,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
/** Detects a class with class-validator decorators. */
|
|
144
|
+
function detectClassValidator(text, file) {
|
|
145
|
+
const out = [];
|
|
146
|
+
if (!/from\s+['"]class-validator['"]/.test(text))
|
|
147
|
+
return out;
|
|
148
|
+
const clsRe = /class\s+(\w+)/g;
|
|
149
|
+
let m;
|
|
150
|
+
while ((m = clsRe.exec(text)) !== null) {
|
|
151
|
+
const name = m[1] ?? 'unknown';
|
|
152
|
+
const line = text.substring(0, m.index).split('\n').length;
|
|
153
|
+
out.push({
|
|
154
|
+
id: `validation.class-validator.${name.toLowerCase()}`,
|
|
155
|
+
library: 'class-validator',
|
|
156
|
+
name,
|
|
157
|
+
boundary: 'strict',
|
|
158
|
+
fields: {},
|
|
159
|
+
file,
|
|
160
|
+
line,
|
|
161
|
+
col: 0,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
function toResource(root, s) {
|
|
167
|
+
const source = resolve(s.file).split('/').slice(-2).join('/');
|
|
168
|
+
return {
|
|
169
|
+
schemaVersion: GATEFORGE_SCHEMA_VERSION,
|
|
170
|
+
id: s.id,
|
|
171
|
+
kind: VALIDATION_SCHEMA_KIND,
|
|
172
|
+
source,
|
|
173
|
+
location: { file: source, line: s.line, col: s.col },
|
|
174
|
+
detectorVersion: PACK_VERSION,
|
|
175
|
+
attributes: {
|
|
176
|
+
library: s.library,
|
|
177
|
+
name: s.name,
|
|
178
|
+
boundary: s.boundary,
|
|
179
|
+
fields: s.fields,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export function createValidationDetector(options = {}) {
|
|
184
|
+
const root = options.root ?? process.cwd();
|
|
185
|
+
return {
|
|
186
|
+
discover(paths) {
|
|
187
|
+
const out = { resources: [], unresolved: [], findings: [], classificationSignals: [] };
|
|
188
|
+
if (paths.length === 0)
|
|
189
|
+
return out;
|
|
190
|
+
const scanned = [];
|
|
191
|
+
for (const rawPath of paths) {
|
|
192
|
+
const abs = isAbsolute(rawPath) ? rawPath : resolve(root, rawPath);
|
|
193
|
+
const files = collectFiles(abs);
|
|
194
|
+
for (const file of files) {
|
|
195
|
+
let text;
|
|
196
|
+
try {
|
|
197
|
+
text = readFileSync(file, 'utf8');
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
scanned.push(relative(root, file).split(sep).join('/'));
|
|
203
|
+
for (const s of [
|
|
204
|
+
...detectZod(text, file),
|
|
205
|
+
...detectJoi(text, file),
|
|
206
|
+
...detectYup(text, file),
|
|
207
|
+
...detectClassValidator(text, file),
|
|
208
|
+
]) {
|
|
209
|
+
out.resources.push(toResource(root, s));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
out.resources.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
214
|
+
return { ...out, scannedPaths: scanned.sort() };
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAa5C,0CAA0C;AAC1C,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAgB1D,4EAA4E;AAC5E,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE;QACjB,IAAI,CAAC;YAAC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAA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AC;wBAAC,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;oBAAC,CAAC;oBAC1C,MAAM,CAAC;wBAAC,SAAS;oBAAC,CAAC;oBACnB,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;oBACxD,KAAK,MAAM,CAAC,IAAI;wBACd,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;wBACxB,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;wBACxB,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;wBACxB,GAAG,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC;qBACpC,EAAE,CAAC;wBACF,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;oBAC1C,CAAC;gBACH,CAAC;YACH,CAAC;YACD,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvE,OAAO,EAAE,GAAG,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gate-forge/pack-validation — request-schema validation discovery pack.
|
|
3
|
+
*
|
|
4
|
+
* Detects zod / joi / yup / class-validator schemas in TypeScript /
|
|
5
|
+
* JavaScript source and emits one `validation.schema` resource per
|
|
6
|
+
* schema declaration. The default export is the CLI in-process plugin
|
|
7
|
+
* contract (`discover(paths)`).
|
|
8
|
+
*
|
|
9
|
+
* See README.md for setup, the obligation vocabulary, and the example
|
|
10
|
+
* server.
|
|
11
|
+
*/
|
|
12
|
+
export { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
13
|
+
export { createValidationDetector, VALIDATION_SCHEMA_KIND, type ValidationDetector, type ValidationDetectorOptions, type ValidationResourceId, } from './detector.js';
|
|
14
|
+
export { VALIDATION_OBLIGATIONS, type ValidationObligation } from './obligations.js';
|
|
15
|
+
/** The default CLI in-process plugin module: `{ discover(paths) }`. */
|
|
16
|
+
declare const _default: import("./detector.js").ValidationDetector;
|
|
17
|
+
export default _default;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAErF,uEAAuE;;AACvE,wBAA0C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gate-forge/pack-validation — request-schema validation discovery pack.
|
|
3
|
+
*
|
|
4
|
+
* Detects zod / joi / yup / class-validator schemas in TypeScript /
|
|
5
|
+
* JavaScript source and emits one `validation.schema` resource per
|
|
6
|
+
* schema declaration. The default export is the CLI in-process plugin
|
|
7
|
+
* contract (`discover(paths)`).
|
|
8
|
+
*
|
|
9
|
+
* See README.md for setup, the obligation vocabulary, and the example
|
|
10
|
+
* server.
|
|
11
|
+
*/
|
|
12
|
+
export { PACK_PLUGIN_ID, PACK_VERSION } from './version.js';
|
|
13
|
+
export { createValidationDetector, VALIDATION_SCHEMA_KIND, } from './detector.js';
|
|
14
|
+
export { VALIDATION_OBLIGATIONS } from './obligations.js';
|
|
15
|
+
import { createValidationDetector } from './detector.js';
|
|
16
|
+
/** The default CLI in-process plugin module: `{ discover(paths) }`. */
|
|
17
|
+
export default createValidationDetector();
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GAIvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAA6B,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,uEAAuE;AACvE,eAAe,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The validation pack's obligation contract vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* - validation:boundary-accepted — a request whose payload sits
|
|
5
|
+
* inside every constraint (min/max/regex/enum) is accepted (2xx).
|
|
6
|
+
* - validation:boundary-rejected — a request whose payload
|
|
7
|
+
* violates at least one constraint is rejected (4xx) with an
|
|
8
|
+
* explicit error message naming the failing field.
|
|
9
|
+
* - validation:no-side-effect-on-reject — a rejected request produces
|
|
10
|
+
* NO persistence side effect (a post-reject GET shows the row
|
|
11
|
+
* count unchanged).
|
|
12
|
+
* - validation:error-message-explicit — the rejection response
|
|
13
|
+
* names the field that violated the contract (not a generic 400).
|
|
14
|
+
*
|
|
15
|
+
* - validation:envelope-shape-stable — the request schema is
|
|
16
|
+
* versioned and a single re-declared schema change does not
|
|
17
|
+
* silently mutate the contract (caller must re-classify).
|
|
18
|
+
*/
|
|
19
|
+
export declare const VALIDATION_OBLIGATIONS: readonly ["validation:boundary-accepted", "validation:boundary-rejected", "validation:no-side-effect-on-reject", "validation:error-message-explicit", "validation:envelope-shape-stable"];
|
|
20
|
+
export type ValidationObligation = (typeof VALIDATION_OBLIGATIONS)[number];
|
|
21
|
+
//# sourceMappingURL=obligations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obligations.d.ts","sourceRoot":"","sources":["../src/obligations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,2LAMzB,CAAC;AACX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The validation pack's obligation contract vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* - validation:boundary-accepted — a request whose payload sits
|
|
5
|
+
* inside every constraint (min/max/regex/enum) is accepted (2xx).
|
|
6
|
+
* - validation:boundary-rejected — a request whose payload
|
|
7
|
+
* violates at least one constraint is rejected (4xx) with an
|
|
8
|
+
* explicit error message naming the failing field.
|
|
9
|
+
* - validation:no-side-effect-on-reject — a rejected request produces
|
|
10
|
+
* NO persistence side effect (a post-reject GET shows the row
|
|
11
|
+
* count unchanged).
|
|
12
|
+
* - validation:error-message-explicit — the rejection response
|
|
13
|
+
* names the field that violated the contract (not a generic 400).
|
|
14
|
+
*
|
|
15
|
+
* - validation:envelope-shape-stable — the request schema is
|
|
16
|
+
* versioned and a single re-declared schema change does not
|
|
17
|
+
* silently mutate the contract (caller must re-classify).
|
|
18
|
+
*/
|
|
19
|
+
export const VALIDATION_OBLIGATIONS = [
|
|
20
|
+
'validation:boundary-accepted',
|
|
21
|
+
'validation:boundary-rejected',
|
|
22
|
+
'validation:no-side-effect-on-reject',
|
|
23
|
+
'validation:error-message-explicit',
|
|
24
|
+
'validation:envelope-shape-stable',
|
|
25
|
+
];
|
|
26
|
+
//# sourceMappingURL=obligations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obligations.js","sourceRoot":"","sources":["../src/obligations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,8BAA8B;IAC9B,8BAA8B;IAC9B,qCAAqC;IACrC,mCAAmC;IACnC,kCAAkC;CAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,eAAO,MAAM,cAAc,gCAAgC,CAAC;AAC5D,eAAO,MAAM,YAAY,UAAU,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gate-forge/pack-validation",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Validation discovery pack: TS-only AST-light detector (GPP/3) for zod / joi / yup / class-validator request schemas; boundary + side-effect contracts.",
|
|
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
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.build.json",
|
|
22
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
23
|
+
"test": "vitest run"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@gate-forge/core": "^0.1.0",
|
|
27
|
+
"@gate-forge/plugin-protocol": "^0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "*",
|
|
31
|
+
"vitest": "*"
|
|
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-validation"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/umiddey/gateforge/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/umiddey/gateforge#readme"
|
|
45
|
+
}
|