@shrkcrft/structural-search 0.1.0-alpha.10
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/dist/engine/apply-rewrite.d.ts +29 -0
- package/dist/engine/apply-rewrite.d.ts.map +1 -0
- package/dist/engine/apply-rewrite.js +68 -0
- package/dist/engine/match-pattern.d.ts +12 -0
- package/dist/engine/match-pattern.d.ts.map +1 -0
- package/dist/engine/match-pattern.js +150 -0
- package/dist/engine/plan-rewrite.d.ts +21 -0
- package/dist/engine/plan-rewrite.d.ts.map +1 -0
- package/dist/engine/plan-rewrite.js +187 -0
- package/dist/engine/run-search.d.ts +17 -0
- package/dist/engine/run-search.d.ts.map +1 -0
- package/dist/engine/run-search.js +157 -0
- package/dist/engine/sign-rewrite.d.ts +39 -0
- package/dist/engine/sign-rewrite.d.ts.map +1 -0
- package/dist/engine/sign-rewrite.js +87 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/registry/pattern-registry-store.d.ts +46 -0
- package/dist/registry/pattern-registry-store.d.ts.map +1 -0
- package/dist/registry/pattern-registry-store.js +120 -0
- package/dist/registry/starter-patterns.d.ts +12 -0
- package/dist/registry/starter-patterns.d.ts.map +1 -0
- package/dist/registry/starter-patterns.js +84 -0
- package/dist/schema/match.d.ts +25 -0
- package/dist/schema/match.d.ts.map +1 -0
- package/dist/schema/match.js +1 -0
- package/dist/schema/pattern-registry.d.ts +52 -0
- package/dist/schema/pattern-registry.d.ts.map +1 -0
- package/dist/schema/pattern-registry.js +60 -0
- package/dist/schema/pattern.d.ts +85 -0
- package/dist/schema/pattern.d.ts.map +1 -0
- package/dist/schema/pattern.js +22 -0
- package/dist/schema/rewrite.d.ts +58 -0
- package/dist/schema/rewrite.d.ts.map +1 -0
- package/dist/schema/rewrite.js +1 -0
- package/dist/schema/signed-rewrite.d.ts +20 -0
- package/dist/schema/signed-rewrite.d.ts.map +1 -0
- package/dist/schema/signed-rewrite.js +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative AST pattern DSL. Patterns describe an AST *shape*; the
|
|
3
|
+
* matcher walks the tree and emits a match per matching node. There are
|
|
4
|
+
* deliberately no executable predicates — patterns serialise as plain
|
|
5
|
+
* JSON, sign cleanly, and never run user JS in the matcher.
|
|
6
|
+
*
|
|
7
|
+
* Schema: sharkcraft.structural-pattern/v1.
|
|
8
|
+
*
|
|
9
|
+
* Supported kinds in Wave 4 (foundation):
|
|
10
|
+
* - CallExpression
|
|
11
|
+
* - NewExpression
|
|
12
|
+
* - ImportDeclaration
|
|
13
|
+
* - ClassDeclaration
|
|
14
|
+
* - Decorator
|
|
15
|
+
* - Identifier
|
|
16
|
+
* - StringLiteral
|
|
17
|
+
*
|
|
18
|
+
* Additional kinds (function/method declarations, JSX, conditional types,
|
|
19
|
+
* etc.) slot in by adding a new variant to `StructuralPattern` plus a
|
|
20
|
+
* branch in `matchPattern`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const STRUCTURAL_PATTERN_SCHEMA: "sharkcraft.structural-pattern/v1";
|
|
23
|
+
export type StructuralPattern = ICallExpressionPattern | INewExpressionPattern | IImportDeclarationPattern | IClassDeclarationPattern | IDecoratorPattern | IIdentifierPattern | IStringLiteralPattern;
|
|
24
|
+
export interface IPatternEnvelope {
|
|
25
|
+
schema: typeof STRUCTURAL_PATTERN_SCHEMA;
|
|
26
|
+
id?: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
pattern: StructuralPattern;
|
|
30
|
+
}
|
|
31
|
+
export interface IIdentifierPattern {
|
|
32
|
+
kind: 'Identifier';
|
|
33
|
+
/** Exact-match name. `*` matches any identifier. */
|
|
34
|
+
name?: string;
|
|
35
|
+
/** ECMAScript regex source (without flags). Matched against the identifier text. */
|
|
36
|
+
nameRegex?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface IStringLiteralPattern {
|
|
39
|
+
kind: 'StringLiteral';
|
|
40
|
+
/** Exact match. */
|
|
41
|
+
text?: string;
|
|
42
|
+
textRegex?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ICallExpressionPattern {
|
|
45
|
+
kind: 'CallExpression';
|
|
46
|
+
/** Match against the callee identifier name. */
|
|
47
|
+
callee?: IIdentifierPattern;
|
|
48
|
+
/** Optional minimum argument count. */
|
|
49
|
+
minArgs?: number;
|
|
50
|
+
/** Optional exact argument count. */
|
|
51
|
+
argCount?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface INewExpressionPattern {
|
|
54
|
+
kind: 'NewExpression';
|
|
55
|
+
callee?: IIdentifierPattern;
|
|
56
|
+
}
|
|
57
|
+
export interface IImportDeclarationPattern {
|
|
58
|
+
kind: 'ImportDeclaration';
|
|
59
|
+
/** Exact specifier match. */
|
|
60
|
+
from?: string;
|
|
61
|
+
fromRegex?: string;
|
|
62
|
+
/** True → match only side-effect imports `import "x";`. */
|
|
63
|
+
sideEffectOnly?: boolean;
|
|
64
|
+
/** Match only when this named import exists. */
|
|
65
|
+
importedName?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface IClassDeclarationPattern {
|
|
68
|
+
kind: 'ClassDeclaration';
|
|
69
|
+
name?: string;
|
|
70
|
+
nameRegex?: string;
|
|
71
|
+
/** Require a decorator with this identifier name. */
|
|
72
|
+
hasDecoratorNamed?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface IDecoratorPattern {
|
|
75
|
+
kind: 'Decorator';
|
|
76
|
+
/** Decorator identifier name (e.g. `Controller`). */
|
|
77
|
+
name?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Match only when the decorator is invoked as a call expression
|
|
80
|
+
* `@Foo(...)` (true) vs a bare identifier `@Foo` (false). Omit to
|
|
81
|
+
* accept either.
|
|
82
|
+
*/
|
|
83
|
+
isCall?: boolean;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=pattern.d.ts.map
|
|
@@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C7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative AST pattern DSL. Patterns describe an AST *shape*; the
|
|
3
|
+
* matcher walks the tree and emits a match per matching node. There are
|
|
4
|
+
* deliberately no executable predicates — patterns serialise as plain
|
|
5
|
+
* JSON, sign cleanly, and never run user JS in the matcher.
|
|
6
|
+
*
|
|
7
|
+
* Schema: sharkcraft.structural-pattern/v1.
|
|
8
|
+
*
|
|
9
|
+
* Supported kinds in Wave 4 (foundation):
|
|
10
|
+
* - CallExpression
|
|
11
|
+
* - NewExpression
|
|
12
|
+
* - ImportDeclaration
|
|
13
|
+
* - ClassDeclaration
|
|
14
|
+
* - Decorator
|
|
15
|
+
* - Identifier
|
|
16
|
+
* - StringLiteral
|
|
17
|
+
*
|
|
18
|
+
* Additional kinds (function/method declarations, JSX, conditional types,
|
|
19
|
+
* etc.) slot in by adding a new variant to `StructuralPattern` plus a
|
|
20
|
+
* branch in `matchPattern`.
|
|
21
|
+
*/
|
|
22
|
+
export const STRUCTURAL_PATTERN_SCHEMA = 'sharkcraft.structural-pattern/v1';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { StructuralPattern } from './pattern.js';
|
|
2
|
+
export declare const STRUCTURAL_REWRITE_SCHEMA: "sharkcraft.structural-rewrite-plan/v1";
|
|
3
|
+
/**
|
|
4
|
+
* A rewrite recipe describes what to do at each pattern match.
|
|
5
|
+
*
|
|
6
|
+
* Recipes are intentionally narrow — each one targets one shape of
|
|
7
|
+
* match. Mixing kinds in a single rewrite is not supported; run two
|
|
8
|
+
* passes instead.
|
|
9
|
+
*
|
|
10
|
+
* Supported recipes (Wave 8 foundation):
|
|
11
|
+
*
|
|
12
|
+
* - `replace-identifier-name` — given an `Identifier` pattern,
|
|
13
|
+
* replace the matched identifier's text with `to`.
|
|
14
|
+
* - `replace-call-callee` — given a `CallExpression` pattern,
|
|
15
|
+
* replace the callee identifier text with `to`. Useful for
|
|
16
|
+
* `console.log(...)` → `logger.info(...)`.
|
|
17
|
+
* - `replace-import-from` — given an `ImportDeclaration` pattern,
|
|
18
|
+
* replace the module specifier string with `to`. Useful for
|
|
19
|
+
* `from 'lodash'` → `from 'lodash-es'`.
|
|
20
|
+
*/
|
|
21
|
+
export type RewriteRecipe = {
|
|
22
|
+
kind: 'replace-identifier-name';
|
|
23
|
+
to: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'replace-call-callee';
|
|
26
|
+
to: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'replace-import-from';
|
|
29
|
+
to: string;
|
|
30
|
+
};
|
|
31
|
+
export interface IEdit {
|
|
32
|
+
/** Character offset (inclusive) where the edit starts. */
|
|
33
|
+
start: number;
|
|
34
|
+
/** Character offset (exclusive) where the edit ends. */
|
|
35
|
+
end: number;
|
|
36
|
+
/** New text. */
|
|
37
|
+
replacement: string;
|
|
38
|
+
/** Old text. Provided for human review. */
|
|
39
|
+
before: string;
|
|
40
|
+
/** 1-based line number for display. */
|
|
41
|
+
line: number;
|
|
42
|
+
}
|
|
43
|
+
export interface IFileEdits {
|
|
44
|
+
/** Project-relative POSIX path. */
|
|
45
|
+
path: string;
|
|
46
|
+
/** Edits sorted by `start` ascending. */
|
|
47
|
+
edits: readonly IEdit[];
|
|
48
|
+
}
|
|
49
|
+
export interface IRewritePlan {
|
|
50
|
+
schema: typeof STRUCTURAL_REWRITE_SCHEMA;
|
|
51
|
+
pattern: StructuralPattern;
|
|
52
|
+
recipe: RewriteRecipe;
|
|
53
|
+
filesScanned: number;
|
|
54
|
+
totalEdits: number;
|
|
55
|
+
files: readonly IFileEdits[];
|
|
56
|
+
diagnostics: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=rewrite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../src/schema/rewrite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,eAAO,MAAM,yBAAyB,EAAG,uCAAgD,CAAC;AAE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,yBAAyB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,MAAM,WAAW,KAAK;IACpB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,KAAK,EAAE,SAAS,KAAK,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,yBAAyB,CAAC;IACzC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,MAAM,EAAE,aAAa,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STRUCTURAL_REWRITE_SCHEMA = 'sharkcraft.structural-rewrite-plan/v1';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IRewritePlan } from './rewrite.js';
|
|
2
|
+
export declare const SIGNED_REWRITE_SCHEMA: "sharkcraft.structural-rewrite-plan-signed/v1";
|
|
3
|
+
export interface ISignedRewriteProvenance {
|
|
4
|
+
/** ISO timestamp of the signing event. */
|
|
5
|
+
signedAt: string;
|
|
6
|
+
/** Tool that signed the plan (`shrk search-structural` by default). */
|
|
7
|
+
signedBy: string;
|
|
8
|
+
/** SharkCraft / structural-search schema version of the inner plan. */
|
|
9
|
+
planSchema: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ISignedRewritePlan {
|
|
12
|
+
schema: typeof SIGNED_REWRITE_SCHEMA;
|
|
13
|
+
/** HMAC-SHA256 of the canonical-JSON inner plan + provenance, hex. */
|
|
14
|
+
hmac: string;
|
|
15
|
+
/** Algorithm identifier; always `sha256` for v1. */
|
|
16
|
+
algo: 'sha256';
|
|
17
|
+
provenance: ISignedRewriteProvenance;
|
|
18
|
+
plan: IRewritePlan;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=signed-rewrite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signed-rewrite.d.ts","sourceRoot":"","sources":["../../src/schema/signed-rewrite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,eAAO,MAAM,qBAAqB,EAAG,8CAAuD,CAAC;AAE7F,MAAM,WAAW,wBAAwB;IACvC,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,qBAAqB,CAAC;IACrC,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,wBAAwB,CAAC;IACrC,IAAI,EAAE,YAAY,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SIGNED_REWRITE_SCHEMA = 'sharkcraft.structural-rewrite-plan-signed/v1';
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shrkcrft/structural-search",
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
|
+
"description": "SharkCraft structural search: declarative AST patterns for TypeScript codebases. Find call sites, decorators, classes, imports — preview-only by default; rewrite mode lands in Wave 8.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "SharkCraft contributors",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/sharkcraft/sharkcraft.git",
|
|
25
|
+
"directory": "packages/structural-search"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/sharkcraft/sharkcraft",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/sharkcraft/sharkcraft/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"sharkcraft",
|
|
33
|
+
"structural-search",
|
|
34
|
+
"ast",
|
|
35
|
+
"typescript",
|
|
36
|
+
"codemod"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"bun": ">=1.1.0",
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@shrkcrft/core": "^0.1.0-alpha.10",
|
|
47
|
+
"typescript": "^5.5.0"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|