@glubean/scanner 0.4.0 → 0.5.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.
@@ -1,27 +1,19 @@
1
1
  /**
2
- * Static analysis extractor for Glubean test files.
3
- *
4
- * Uses regex patterns to extract test metadata WITHOUT importing files.
5
- * This is useful for:
6
- * - Build systems that scan code without execution
7
- * - CI/CD pipelines
8
- * - IDE extensions (VSCode)
9
- *
10
- * Note: Static analysis may miss dynamically computed metadata.
11
- *
12
- * **Limitations:**
13
- * - Template variables (`$id`, `$_pick`) in IDs are preserved as-is, not resolved.
14
- * - Dynamically computed IDs or tags are not detected.
15
- * - `test.each()` / `test.pick()` produce one ExportMeta with the template ID,
16
- * not one per data row (row count is unknown statically).
17
- * - Deeply nested or multi-line object literals with complex expressions may
18
- * not be fully parsed.
2
+ * Static guards + shared static-metadata types for Glubean scanning.
3
+ *
4
+ * The test/contract/pick EXTRACTORS that used to live here are gone they are
5
+ * now AST-based (@babel/parser) in `extractor-ast.ts`. What remains are the two
6
+ * cheap regex GUARDS that run over every candidate file in phase 1 (no TS
7
+ * expression parsing, so a parser would only add cost):
8
+ * - `isGlubeanFile` does this file import the SDK / a test-like function?
9
+ * - `extractAliasesFromSource` — `const x = test.extend(...)` alias names.
10
+ * Plus the result types consumed across packages (`ExportMeta` lives in
11
+ * `types.ts`; `PickMeta` / `Contract*StaticMeta` live here).
19
12
  */
20
- import type { ExportMeta } from "./types.js";
21
13
  /**
22
14
  * Check if a file's content looks like a Glubean test/task file.
23
15
  *
24
- * Useful as a fast guard before running the more expensive `extractFromSource`.
16
+ * A fast, parse-free guard run before the (AST) extractors.
25
17
  *
26
18
  * Detection layers (any match → true):
27
19
  * 1. Direct SDK module import (`jsr:@glubean/sdk`, `@glubean/sdk`)
@@ -49,39 +41,6 @@ export declare function isGlubeanFile(content: string, customFns?: string[]): bo
49
41
  * @returns Array of discovered alias names
50
42
  */
51
43
  export declare function extractAliasesFromSource(content: string): string[];
52
- /**
53
- * Extract test metadata from TypeScript source using static analysis (regex).
54
- *
55
- * Recognizes the following patterns:
56
- * - `export const x = test("id", fn)` — simple test with string ID
57
- * - `export const x = test({ id, name, tags }, fn)` — simple test with meta
58
- * - `export const x = test("id").step(...)` — builder with steps
59
- * - `export const x = test.each(data)("id-$key", fn)` — data-driven
60
- * - `export const x = test.pick(examples)("id-$_pick", fn)` — example selection
61
- *
62
- * This is a pure function — no file system or runtime access needed.
63
- *
64
- * @param content - TypeScript source code
65
- * @param customFns - Additional function names discovered via `extractAliasesFromSource`.
66
- * When provided, these names are matched alongside `test` and `task`.
67
- * When omitted, falls back to `*Test` / `*Task` convention matching.
68
- * @returns Array of extracted export metadata
69
- */
70
- export declare function extractFromSource(content: string, customFns?: string[]): ExportMeta[];
71
- /**
72
- * Create a static metadata extractor that uses file system to read content.
73
- *
74
- * Aliases can be supplied at two levels:
75
- * - `customFns` (construction-time): baked-in aliases known upfront.
76
- * - `runtimeFns` (call-time): aliases discovered during a Scanner two-phase
77
- * scan. These are merged with `customFns` so the extractor benefits from
78
- * aliases discovered after construction.
79
- *
80
- * @param readFile - Function to read file content as string
81
- * @param customFns - Additional function names (from alias discovery)
82
- * @returns MetadataExtractor function
83
- */
84
- export declare function createStaticExtractor(readFile: (path: string) => Promise<string>, customFns?: string[]): (filePath: string, runtimeFns?: string[]) => Promise<ExportMeta[]>;
85
44
  /** Metadata for a discovered test.pick() call. */
86
45
  export interface PickMeta {
87
46
  /** The test ID template (e.g. "create-user-$_pick") */
@@ -128,36 +87,6 @@ export interface PickMeta {
128
87
  path: string;
129
88
  };
130
89
  }
131
- /**
132
- * Extract test.pick() metadata from TypeScript source for CodeLens rendering.
133
- *
134
- * Handles data source patterns:
135
- * 1. Inline object literal: `test.pick({ "key1": ..., "key2": ... })`
136
- * 2. JSON import variable: `import X from "./data.json"` then `test.pick(X)`
137
- * 3. fromDir.merge variable: `const X = await fromDir.merge("./dir/")` then `test.pick(X)`
138
- * 4. fromDir variable: `const X = await fromDir("./dir/")` then `test.pick(X)`
139
- * 5. fromDir.concat variable: `const X = await fromDir.concat("./dir/")` then `test.pick(X)`
140
- * 6. fromYaml.map variable: `const X = await fromYaml.map("./file.yaml")` then `test.pick(X)`
141
- * 7. fromJson variable: `const X = await fromJson("./file.json")` then `test.each(X)`
142
- * 8. fromJson.map variable: `const X = await fromJson.map("./file.json")` then `test.pick(X)`
143
- *
144
- * For other patterns (dynamic vars, etc.), returns keys: null.
145
- *
146
- * @param content - TypeScript source code
147
- * @param options - Optional settings
148
- * @param options.customFns - Additional function names discovered via alias scanning.
149
- * @param options.filePath - Source file path. When provided, file-relative
150
- * paths are resolved against this file's directory.
151
- * @param options.projectRoot - Project root. When provided, bare paths are
152
- * resolved against the project root instead of
153
- * the source file directory.
154
- * @returns Array of PickMeta, or empty if no test.pick calls found
155
- */
156
- export declare function extractPickExamples(content: string, options?: {
157
- customFns?: string[];
158
- filePath?: string;
159
- projectRoot?: string;
160
- }): PickMeta[];
161
90
  /** Metadata for a discovered contract case. */
162
91
  export type ContractVerifyRule = string | {
163
92
  id?: string;
@@ -218,17 +147,15 @@ export interface ContractStaticMeta {
218
147
  /** Cases */
219
148
  cases: ContractCaseStaticMeta[];
220
149
  }
221
- /**
222
- * Extract contract.http()/contract.grpc()/etc. metadata from TypeScript source.
223
- *
224
- * Statically extracts:
225
- * - Contract ID, endpoint, export name, line number
226
- * - Each case key with its line number
227
- * - Expected status code (if literal number)
228
- * - Deferred reason (if literal string)
229
- *
230
- * @param content - TypeScript source code
231
- * @returns Array of ContractStaticMeta, or empty if no contract calls found
232
- */
233
- export declare function extractContractCases(content: string): ContractStaticMeta[];
150
+ /** Metadata for a discovered `<fn>.flow("id")` export (structural — no marker). */
151
+ export interface FlowStaticMeta {
152
+ /** Export variable name (e.g. "signupFlow") */
153
+ exportName: string;
154
+ /** Source location (1-based line number) of the export */
155
+ line: number;
156
+ /** Flow ID the literal string arg to `.flow(...)` */
157
+ flowId: string;
158
+ /** Skip-at-declaration reason from `.meta({ skip })`, if present */
159
+ skip?: string;
160
+ }
234
161
  //# sourceMappingURL=extractor-static.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractor-static.d.ts","sourceRoot":"","sources":["../src/extractor-static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAoC7C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAU5E;AAwXD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAUlE;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAkCrF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC3C,SAAS,CAAC,EAAE,MAAM,EAAE,GACnB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAOpE;AAMD,kDAAkD;AAClD,MAAM,WAAW,QAAQ;IACvB,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACtB;;;;;;;OAOG;IACH,UAAU,CAAC,EACP;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,GAClB;QAAE,IAAI,EAA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