@contractspec/lib.source-extractors 0.0.0-canary-20260119222405

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.
Files changed (78) hide show
  1. package/README.md +86 -0
  2. package/dist/_virtual/rolldown_runtime.js +18 -0
  3. package/dist/codegen/index.d.ts +12 -0
  4. package/dist/codegen/index.d.ts.map +1 -0
  5. package/dist/codegen/index.js +17 -0
  6. package/dist/codegen/index.js.map +1 -0
  7. package/dist/codegen/operation-gen.d.ts +16 -0
  8. package/dist/codegen/operation-gen.d.ts.map +1 -0
  9. package/dist/codegen/operation-gen.js +91 -0
  10. package/dist/codegen/operation-gen.js.map +1 -0
  11. package/dist/codegen/registry-gen.d.ts +11 -0
  12. package/dist/codegen/registry-gen.d.ts.map +1 -0
  13. package/dist/codegen/registry-gen.js +47 -0
  14. package/dist/codegen/registry-gen.js.map +1 -0
  15. package/dist/codegen/schema-gen.d.ts +16 -0
  16. package/dist/codegen/schema-gen.d.ts.map +1 -0
  17. package/dist/codegen/schema-gen.js +93 -0
  18. package/dist/codegen/schema-gen.js.map +1 -0
  19. package/dist/codegen/types.d.ts +48 -0
  20. package/dist/codegen/types.d.ts.map +1 -0
  21. package/dist/detect.d.ts +47 -0
  22. package/dist/detect.d.ts.map +1 -0
  23. package/dist/detect.js +177 -0
  24. package/dist/detect.js.map +1 -0
  25. package/dist/extract.d.ts +24 -0
  26. package/dist/extract.d.ts.map +1 -0
  27. package/dist/extract.js +125 -0
  28. package/dist/extract.js.map +1 -0
  29. package/dist/extractors/base.d.ts +90 -0
  30. package/dist/extractors/base.d.ts.map +1 -0
  31. package/dist/extractors/base.js +152 -0
  32. package/dist/extractors/base.js.map +1 -0
  33. package/dist/extractors/elysia/extractor.d.ts +15 -0
  34. package/dist/extractors/elysia/extractor.d.ts.map +1 -0
  35. package/dist/extractors/elysia/extractor.js +58 -0
  36. package/dist/extractors/elysia/extractor.js.map +1 -0
  37. package/dist/extractors/express/extractor.d.ts +15 -0
  38. package/dist/extractors/express/extractor.d.ts.map +1 -0
  39. package/dist/extractors/express/extractor.js +61 -0
  40. package/dist/extractors/express/extractor.js.map +1 -0
  41. package/dist/extractors/fastify/extractor.d.ts +15 -0
  42. package/dist/extractors/fastify/extractor.d.ts.map +1 -0
  43. package/dist/extractors/fastify/extractor.js +61 -0
  44. package/dist/extractors/fastify/extractor.js.map +1 -0
  45. package/dist/extractors/hono/extractor.d.ts +15 -0
  46. package/dist/extractors/hono/extractor.d.ts.map +1 -0
  47. package/dist/extractors/hono/extractor.js +57 -0
  48. package/dist/extractors/hono/extractor.js.map +1 -0
  49. package/dist/extractors/index.d.ts +21 -0
  50. package/dist/extractors/index.d.ts.map +1 -0
  51. package/dist/extractors/index.js +42 -0
  52. package/dist/extractors/index.js.map +1 -0
  53. package/dist/extractors/nestjs/extractor.d.ts +29 -0
  54. package/dist/extractors/nestjs/extractor.d.ts.map +1 -0
  55. package/dist/extractors/nestjs/extractor.js +118 -0
  56. package/dist/extractors/nestjs/extractor.js.map +1 -0
  57. package/dist/extractors/next-api/extractor.d.ts +16 -0
  58. package/dist/extractors/next-api/extractor.d.ts.map +1 -0
  59. package/dist/extractors/next-api/extractor.js +80 -0
  60. package/dist/extractors/next-api/extractor.js.map +1 -0
  61. package/dist/extractors/trpc/extractor.d.ts +15 -0
  62. package/dist/extractors/trpc/extractor.d.ts.map +1 -0
  63. package/dist/extractors/trpc/extractor.js +71 -0
  64. package/dist/extractors/trpc/extractor.js.map +1 -0
  65. package/dist/extractors/zod/extractor.d.ts +16 -0
  66. package/dist/extractors/zod/extractor.d.ts.map +1 -0
  67. package/dist/extractors/zod/extractor.js +69 -0
  68. package/dist/extractors/zod/extractor.js.map +1 -0
  69. package/dist/index.d.ts +7 -0
  70. package/dist/index.js +7 -0
  71. package/dist/registry.d.ts +85 -0
  72. package/dist/registry.d.ts.map +1 -0
  73. package/dist/registry.js +87 -0
  74. package/dist/registry.js.map +1 -0
  75. package/dist/types.d.ts +272 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +0 -0
  78. package/package.json +71 -0
@@ -0,0 +1,272 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Intermediate Representation (IR) types for source extraction.
4
+ *
5
+ * The IR provides a framework-agnostic representation of API endpoints,
6
+ * schemas, errors, and events discovered in source code.
7
+ */
8
+ /**
9
+ * Confidence level for extracted candidates.
10
+ * Indicates how certain we are about the extraction.
11
+ */
12
+ type ConfidenceLevel = 'high' | 'medium' | 'low' | 'ambiguous';
13
+ /**
14
+ * Reason for the assigned confidence level.
15
+ */
16
+ type ConfidenceReason = 'explicit-schema' | 'explicit-decorator' | 'inferred-types' | 'decorator-hints' | 'naming-convention' | 'missing-schema' | 'partial-extraction';
17
+ /**
18
+ * Source location information.
19
+ */
20
+ interface SourceLocation {
21
+ /** File path (relative to project root) */
22
+ file: string;
23
+ /** Start line number (1-indexed) */
24
+ startLine: number;
25
+ /** End line number (1-indexed) */
26
+ endLine: number;
27
+ /** Optional column information */
28
+ startColumn?: number;
29
+ endColumn?: number;
30
+ }
31
+ /**
32
+ * HTTP method types.
33
+ */
34
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
35
+ /**
36
+ * Operation kind derived from HTTP method or explicit annotation.
37
+ */
38
+ type OpKind = 'command' | 'query';
39
+ /**
40
+ * Confidence metadata attached to extracted items.
41
+ */
42
+ interface ConfidenceMeta {
43
+ level: ConfidenceLevel;
44
+ reasons: ConfidenceReason[];
45
+ notes?: string[];
46
+ }
47
+ /**
48
+ * Schema candidate extracted from source code.
49
+ * Can represent Zod schemas, class-validator DTOs, JSON Schema, etc.
50
+ */
51
+ interface SchemaCandidate {
52
+ /** Unique identifier for this schema */
53
+ id: string;
54
+ /** Schema name (e.g., class name, export name) */
55
+ name: string;
56
+ /** Type of schema source */
57
+ schemaType: 'zod' | 'class-validator' | 'json-schema' | 'typebox' | 'typescript' | 'unknown';
58
+ /** Raw schema definition (for Zod, the code; for class-validator, the class def) */
59
+ rawDefinition?: string;
60
+ /** Parsed fields if available */
61
+ fields?: SchemaField[];
62
+ /** Source location */
63
+ source: SourceLocation;
64
+ /** Confidence in this extraction */
65
+ confidence: ConfidenceMeta;
66
+ }
67
+ /**
68
+ * Individual field in a schema.
69
+ */
70
+ interface SchemaField {
71
+ name: string;
72
+ type: string;
73
+ optional: boolean;
74
+ description?: string;
75
+ validation?: string[];
76
+ }
77
+ /**
78
+ * Endpoint candidate extracted from source code.
79
+ * Represents an API route/handler.
80
+ */
81
+ interface EndpointCandidate {
82
+ /** Unique identifier for this endpoint */
83
+ id: string;
84
+ /** HTTP method */
85
+ method: HttpMethod;
86
+ /** Route path (e.g., '/users/:id') */
87
+ path: string;
88
+ /** Operation kind (command/query) */
89
+ kind: OpKind;
90
+ /** Handler function name */
91
+ handlerName: string;
92
+ /** Controller/router name if applicable */
93
+ controllerName?: string;
94
+ /** Input schema reference */
95
+ input?: SchemaRef;
96
+ /** Output schema reference */
97
+ output?: SchemaRef;
98
+ /** Path parameters */
99
+ pathParams?: SchemaRef;
100
+ /** Query parameters */
101
+ queryParams?: SchemaRef;
102
+ /** Associated errors */
103
+ errors?: ErrorRef[];
104
+ /** Framework-specific metadata */
105
+ frameworkMeta?: Record<string, unknown>;
106
+ /** Source location */
107
+ source: SourceLocation;
108
+ /** Confidence in this extraction */
109
+ confidence: ConfidenceMeta;
110
+ }
111
+ /**
112
+ * Reference to a schema (either inline or by ID).
113
+ */
114
+ interface SchemaRef {
115
+ /** Reference to a SchemaCandidate.id */
116
+ ref?: string;
117
+ /** Inline schema definition if not a reference */
118
+ inline?: SchemaCandidate;
119
+ }
120
+ /**
121
+ * Error candidate extracted from source code.
122
+ */
123
+ interface ErrorCandidate {
124
+ /** Unique identifier for this error */
125
+ id: string;
126
+ /** Error name/code */
127
+ name: string;
128
+ /** HTTP status code if applicable */
129
+ httpStatus?: number;
130
+ /** Error description */
131
+ description?: string;
132
+ /** Error payload schema if any */
133
+ payload?: SchemaRef;
134
+ /** Source location */
135
+ source: SourceLocation;
136
+ /** Confidence in this extraction */
137
+ confidence: ConfidenceMeta;
138
+ }
139
+ /**
140
+ * Reference to an error.
141
+ */
142
+ interface ErrorRef {
143
+ /** Reference to an ErrorCandidate.id */
144
+ ref?: string;
145
+ /** Condition when this error is thrown */
146
+ when?: string;
147
+ }
148
+ /**
149
+ * Event candidate extracted from source code.
150
+ */
151
+ interface EventCandidate {
152
+ /** Unique identifier for this event */
153
+ id: string;
154
+ /** Event name/key */
155
+ name: string;
156
+ /** Event payload schema */
157
+ payload?: SchemaRef;
158
+ /** Source location */
159
+ source: SourceLocation;
160
+ /** Confidence in this extraction */
161
+ confidence: ConfidenceMeta;
162
+ }
163
+ /**
164
+ * Ambiguity detected during extraction.
165
+ * Used to flag items that need human review.
166
+ */
167
+ interface Ambiguity {
168
+ /** Type of ambiguous item */
169
+ type: 'endpoint' | 'schema' | 'error' | 'event';
170
+ /** Reference to the item ID */
171
+ itemId: string;
172
+ /** Description of the ambiguity */
173
+ description: string;
174
+ /** Suggested resolution */
175
+ suggestion?: string;
176
+ /** Source location */
177
+ source: SourceLocation;
178
+ }
179
+ /**
180
+ * Framework detection result.
181
+ */
182
+ interface FrameworkInfo {
183
+ /** Framework identifier */
184
+ id: string;
185
+ /** Human-readable name */
186
+ name: string;
187
+ /** Version if detected */
188
+ version?: string;
189
+ /** Detection confidence */
190
+ confidence: ConfidenceLevel;
191
+ }
192
+ /**
193
+ * Project information used for extraction.
194
+ */
195
+ interface ProjectInfo {
196
+ /** Project root path */
197
+ rootPath: string;
198
+ /** Detected frameworks */
199
+ frameworks: FrameworkInfo[];
200
+ /** TypeScript config path if found */
201
+ tsConfigPath?: string;
202
+ /** Package.json path if found */
203
+ packageJsonPath?: string;
204
+ }
205
+ /**
206
+ * Options for extraction.
207
+ */
208
+ interface ExtractOptions {
209
+ /** Force a specific framework */
210
+ framework?: string;
211
+ /** Limit extraction to specific paths (glob patterns) */
212
+ scope?: string[];
213
+ /** Exclude paths (glob patterns) */
214
+ exclude?: string[];
215
+ /** Include node_modules */
216
+ includeNodeModules?: boolean;
217
+ /** Extraction mode */
218
+ mode?: 'full' | 'endpoints-only' | 'schemas-only';
219
+ }
220
+ /**
221
+ * The complete Intermediate Representation of extracted contracts.
222
+ */
223
+ interface ImportIR {
224
+ /** IR schema version */
225
+ version: '1.0';
226
+ /** Extraction timestamp (ISO 8601) */
227
+ extractedAt: string;
228
+ /** Project information */
229
+ project: ProjectInfo;
230
+ /** Extracted endpoints */
231
+ endpoints: EndpointCandidate[];
232
+ /** Extracted schemas */
233
+ schemas: SchemaCandidate[];
234
+ /** Extracted errors */
235
+ errors: ErrorCandidate[];
236
+ /** Extracted events */
237
+ events: EventCandidate[];
238
+ /** Detected ambiguities requiring review */
239
+ ambiguities: Ambiguity[];
240
+ /** Extraction statistics */
241
+ stats: {
242
+ filesScanned: number;
243
+ endpointsFound: number;
244
+ schemasFound: number;
245
+ errorsFound: number;
246
+ eventsFound: number;
247
+ ambiguitiesFound: number;
248
+ highConfidence: number;
249
+ mediumConfidence: number;
250
+ lowConfidence: number;
251
+ };
252
+ }
253
+ /**
254
+ * Result of an extraction operation.
255
+ */
256
+ interface ExtractResult {
257
+ success: boolean;
258
+ ir?: ImportIR;
259
+ errors?: ExtractError[];
260
+ }
261
+ /**
262
+ * Error during extraction.
263
+ */
264
+ interface ExtractError {
265
+ code: string;
266
+ message: string;
267
+ source?: SourceLocation;
268
+ recoverable: boolean;
269
+ }
270
+ //#endregion
271
+ export { Ambiguity, ConfidenceLevel, ConfidenceMeta, ConfidenceReason, EndpointCandidate, ErrorCandidate, ErrorRef, EventCandidate, ExtractError, ExtractOptions, ExtractResult, FrameworkInfo, HttpMethod, ImportIR, OpKind, ProjectInfo, SchemaCandidate, SchemaField, SchemaRef, SourceLocation };
272
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["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;;;;UAgBA,QAAA;;;;;;WAMN;;aAEE;;WAEF;;UAED;;UAEA;;eAEK;;;;;;;;;;;;;;;;;UAkBE,aAAA;;OAEV;WACI;;;;;UAMM,YAAA;;;WAGN"}
package/dist/types.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@contractspec/lib.source-extractors",
3
+ "version": "0.0.0-canary-20260119222405",
4
+ "description": "Extract contract candidates from TypeScript source code across multiple frameworks (NestJS, Express, Fastify, Hono, Elysia, tRPC, Next.js)",
5
+ "keywords": [
6
+ "contractspec",
7
+ "source-extraction",
8
+ "nestjs",
9
+ "express",
10
+ "fastify",
11
+ "hono",
12
+ "elysia",
13
+ "trpc",
14
+ "typescript"
15
+ ],
16
+ "type": "module",
17
+ "scripts": {
18
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
19
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
20
+ "build": "bun build:types && bun build:bundle",
21
+ "build:bundle": "tsdown",
22
+ "build:types": "tsc --noEmit",
23
+ "dev": "bun build:bundle --watch",
24
+ "clean": "rimraf dist .turbo",
25
+ "lint": "bun lint:fix",
26
+ "lint:fix": "eslint src --fix",
27
+ "lint:check": "eslint src",
28
+ "test": "bun test"
29
+ },
30
+ "dependencies": {
31
+ "@contractspec/lib.contracts": "0.0.0-canary-20260119222405",
32
+ "@contractspec/lib.schema": "1.48.0",
33
+ "typescript": "^5.9.3",
34
+ "zod": "^4.3.5"
35
+ },
36
+ "devDependencies": {
37
+ "@contractspec/tool.tsdown": "1.48.0",
38
+ "@contractspec/tool.typescript": "1.48.0",
39
+ "tsdown": "^0.19.0"
40
+ },
41
+ "types": "./dist/index.d.ts",
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ],
46
+ "exports": {
47
+ ".": "./dist/index.js",
48
+ "./codegen": "./dist/codegen/index.js",
49
+ "./extractors": "./dist/extractors/index.js",
50
+ "./types": "./dist/types.js",
51
+ "./*": "./*"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "exports": {
56
+ ".": "./dist/index.js",
57
+ "./types": "./dist/types.js",
58
+ "./extractors": "./dist/extractors/index.js",
59
+ "./codegen": "./dist/codegen/index.js",
60
+ "./*": "./*"
61
+ },
62
+ "registry": "https://registry.npmjs.org/"
63
+ },
64
+ "license": "MIT",
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "https://github.com/lssm-tech/contractspec.git",
68
+ "directory": "packages/libs/source-extractors"
69
+ },
70
+ "homepage": "https://contractspec.io"
71
+ }