@suss/adapter-ruby 0.22.4 → 0.23.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/README.md +16 -0
- package/dist/index.cjs +476 -213
- package/dist/index.d.cts +41 -4
- package/dist/index.d.ts +41 -4
- package/dist/index.js +478 -214
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { Tree, Node } from 'web-tree-sitter';
|
|
|
2
2
|
export { Node as RbNode, Tree as RbTree } from 'web-tree-sitter';
|
|
3
3
|
import { Database } from '@suss/datalog';
|
|
4
4
|
import { TypeShape, BehavioralSummary } from '@suss/behavioral-ir';
|
|
5
|
-
import { RawCodeStructure, TimingReport, ExtractionReport, CacheDiagnostic } from '@suss/extractor';
|
|
5
|
+
import { RawCodeStructure, TimingReport, ExtractionReport, CacheDiagnostic, ExtractorOptions } from '@suss/extractor';
|
|
6
6
|
import { WhyExplained } from '@suss/resolution';
|
|
7
7
|
import { Value } from '@suss/values';
|
|
8
8
|
|
|
@@ -63,14 +63,20 @@ declare function readCallArgs(argumentList: Node | null): CallArgs;
|
|
|
63
63
|
*
|
|
64
64
|
* A Ruby codebase locates that file by a naming convention rather than through a
|
|
65
65
|
* load graph a static reader could follow, so we build one path from the
|
|
66
|
-
* constant's own name and
|
|
67
|
-
*
|
|
66
|
+
* constant's own name and look for it under the configured root and the
|
|
67
|
+
* directories Rails autoloads from. No other spelling is tried.
|
|
68
68
|
*/
|
|
69
69
|
/** A pack picks a convention by name, and the code for each one lives here. */
|
|
70
70
|
type ConstantPathConvention = "railsUnderscore";
|
|
71
71
|
/** Ported from ActiveSupport's own `String#underscore`, which is what Rails autoloading runs a constant path through. */
|
|
72
72
|
declare function underscoreConstantPath(qualifiedName: string): string;
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Null when there is no file at that path. Rails autoloads from every
|
|
75
|
+
* directory directly under `app`, so `ApplicationController` is
|
|
76
|
+
* `app/controllers/application_controller.rb` and not
|
|
77
|
+
* `app/application_controller.rb`; those directories are tried after
|
|
78
|
+
* the root itself, in name order, and no other spelling is tried.
|
|
79
|
+
*/
|
|
74
80
|
declare function resolveConstantFile(root: string, qualifiedName: string, convention: ConstantPathConvention): string | null;
|
|
75
81
|
|
|
76
82
|
/**
|
|
@@ -284,6 +290,33 @@ interface ControllerActions {
|
|
|
284
290
|
} | null;
|
|
285
291
|
/** One message per routing declaration kind this pattern's reading left uncovered. A pure read: calling it again gives the same list. */
|
|
286
292
|
routingGaps?: () => readonly string[];
|
|
293
|
+
/** The class-level calls the library gives a controller for running one of its own methods around every action, Rails' `before_action` and `rescue_from`. */
|
|
294
|
+
filters?: RbControllerFilter[];
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* A call in a controller's class body naming a method the library runs
|
|
298
|
+
* around the action, and which actions that reaches. A class inherits
|
|
299
|
+
* what its ancestors declared, so a filter on `ApplicationController`
|
|
300
|
+
* reaches every action in the project.
|
|
301
|
+
*/
|
|
302
|
+
interface RbControllerFilter {
|
|
303
|
+
/** The call as a controller writes it, `before_action`. */
|
|
304
|
+
name: string;
|
|
305
|
+
/**
|
|
306
|
+
* Where the call names the method: `argument` for the leading symbol
|
|
307
|
+
* of `before_action :require_login`, `withKeyword` for the `with:` of
|
|
308
|
+
* `rescue_from ActiveRecord::RecordNotFound, with: :not_found`.
|
|
309
|
+
*/
|
|
310
|
+
methodFrom: "argument" | "withKeyword";
|
|
311
|
+
/** Set when the library runs the method only for an action that raised, which is what `rescue_from` does. */
|
|
312
|
+
onThrow?: boolean;
|
|
313
|
+
/** The name of the call that takes a filter back off, `skip_before_action` for `before_action`. */
|
|
314
|
+
skippedBy?: string;
|
|
315
|
+
/** The keywords that narrow a filter to some of the actions, Rails' `only` and `except`. */
|
|
316
|
+
actionKeywords?: {
|
|
317
|
+
include: string;
|
|
318
|
+
exclude: string;
|
|
319
|
+
};
|
|
287
320
|
}
|
|
288
321
|
/**
|
|
289
322
|
* One call an action writes to send a response, and where that call takes
|
|
@@ -385,6 +418,8 @@ interface DiscoveryOptions extends BodyReadOptions {
|
|
|
385
418
|
filePath: string;
|
|
386
419
|
/** Absolute path of the file being read, for a block's own `ReachedBody.file`. Falls back to `filePath` when nothing was written to disk. */
|
|
387
420
|
absoluteFile?: string;
|
|
421
|
+
/** What a summary's `location.file` says for a file other than the one being read, which a controller's filters need when an ancestor defines them. */
|
|
422
|
+
displayPathOf?: (absolute: string) => string;
|
|
388
423
|
cache: FileCache;
|
|
389
424
|
/** Called once per discovered unit whose own body is a method this run can follow calls out of, so the reach walk has a place to start. */
|
|
390
425
|
onReachSeed?: (raw: RawCodeStructure, seed: ReachSeed) => void;
|
|
@@ -547,6 +582,8 @@ interface ExtractRubyOptions {
|
|
|
547
582
|
onCacheDiagnostic?: (diagnostic: CacheDiagnostic) => void;
|
|
548
583
|
/** Absolute. `<projectRoot>/.suss/cache` by default; `null` turns it off. */
|
|
549
584
|
cacheDir?: string | null;
|
|
585
|
+
/** What to do with gaps, which composing a controller's filters can add one of. */
|
|
586
|
+
gapHandling?: ExtractorOptions["gapHandling"];
|
|
550
587
|
}
|
|
551
588
|
interface ExtractRubyResult {
|
|
552
589
|
summaries: BehavioralSummary[];
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Tree, Node } from 'web-tree-sitter';
|
|
|
2
2
|
export { Node as RbNode, Tree as RbTree } from 'web-tree-sitter';
|
|
3
3
|
import { Database } from '@suss/datalog';
|
|
4
4
|
import { TypeShape, BehavioralSummary } from '@suss/behavioral-ir';
|
|
5
|
-
import { RawCodeStructure, TimingReport, ExtractionReport, CacheDiagnostic } from '@suss/extractor';
|
|
5
|
+
import { RawCodeStructure, TimingReport, ExtractionReport, CacheDiagnostic, ExtractorOptions } from '@suss/extractor';
|
|
6
6
|
import { WhyExplained } from '@suss/resolution';
|
|
7
7
|
import { Value } from '@suss/values';
|
|
8
8
|
|
|
@@ -63,14 +63,20 @@ declare function readCallArgs(argumentList: Node | null): CallArgs;
|
|
|
63
63
|
*
|
|
64
64
|
* A Ruby codebase locates that file by a naming convention rather than through a
|
|
65
65
|
* load graph a static reader could follow, so we build one path from the
|
|
66
|
-
* constant's own name and
|
|
67
|
-
*
|
|
66
|
+
* constant's own name and look for it under the configured root and the
|
|
67
|
+
* directories Rails autoloads from. No other spelling is tried.
|
|
68
68
|
*/
|
|
69
69
|
/** A pack picks a convention by name, and the code for each one lives here. */
|
|
70
70
|
type ConstantPathConvention = "railsUnderscore";
|
|
71
71
|
/** Ported from ActiveSupport's own `String#underscore`, which is what Rails autoloading runs a constant path through. */
|
|
72
72
|
declare function underscoreConstantPath(qualifiedName: string): string;
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Null when there is no file at that path. Rails autoloads from every
|
|
75
|
+
* directory directly under `app`, so `ApplicationController` is
|
|
76
|
+
* `app/controllers/application_controller.rb` and not
|
|
77
|
+
* `app/application_controller.rb`; those directories are tried after
|
|
78
|
+
* the root itself, in name order, and no other spelling is tried.
|
|
79
|
+
*/
|
|
74
80
|
declare function resolveConstantFile(root: string, qualifiedName: string, convention: ConstantPathConvention): string | null;
|
|
75
81
|
|
|
76
82
|
/**
|
|
@@ -284,6 +290,33 @@ interface ControllerActions {
|
|
|
284
290
|
} | null;
|
|
285
291
|
/** One message per routing declaration kind this pattern's reading left uncovered. A pure read: calling it again gives the same list. */
|
|
286
292
|
routingGaps?: () => readonly string[];
|
|
293
|
+
/** The class-level calls the library gives a controller for running one of its own methods around every action, Rails' `before_action` and `rescue_from`. */
|
|
294
|
+
filters?: RbControllerFilter[];
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* A call in a controller's class body naming a method the library runs
|
|
298
|
+
* around the action, and which actions that reaches. A class inherits
|
|
299
|
+
* what its ancestors declared, so a filter on `ApplicationController`
|
|
300
|
+
* reaches every action in the project.
|
|
301
|
+
*/
|
|
302
|
+
interface RbControllerFilter {
|
|
303
|
+
/** The call as a controller writes it, `before_action`. */
|
|
304
|
+
name: string;
|
|
305
|
+
/**
|
|
306
|
+
* Where the call names the method: `argument` for the leading symbol
|
|
307
|
+
* of `before_action :require_login`, `withKeyword` for the `with:` of
|
|
308
|
+
* `rescue_from ActiveRecord::RecordNotFound, with: :not_found`.
|
|
309
|
+
*/
|
|
310
|
+
methodFrom: "argument" | "withKeyword";
|
|
311
|
+
/** Set when the library runs the method only for an action that raised, which is what `rescue_from` does. */
|
|
312
|
+
onThrow?: boolean;
|
|
313
|
+
/** The name of the call that takes a filter back off, `skip_before_action` for `before_action`. */
|
|
314
|
+
skippedBy?: string;
|
|
315
|
+
/** The keywords that narrow a filter to some of the actions, Rails' `only` and `except`. */
|
|
316
|
+
actionKeywords?: {
|
|
317
|
+
include: string;
|
|
318
|
+
exclude: string;
|
|
319
|
+
};
|
|
287
320
|
}
|
|
288
321
|
/**
|
|
289
322
|
* One call an action writes to send a response, and where that call takes
|
|
@@ -385,6 +418,8 @@ interface DiscoveryOptions extends BodyReadOptions {
|
|
|
385
418
|
filePath: string;
|
|
386
419
|
/** Absolute path of the file being read, for a block's own `ReachedBody.file`. Falls back to `filePath` when nothing was written to disk. */
|
|
387
420
|
absoluteFile?: string;
|
|
421
|
+
/** What a summary's `location.file` says for a file other than the one being read, which a controller's filters need when an ancestor defines them. */
|
|
422
|
+
displayPathOf?: (absolute: string) => string;
|
|
388
423
|
cache: FileCache;
|
|
389
424
|
/** Called once per discovered unit whose own body is a method this run can follow calls out of, so the reach walk has a place to start. */
|
|
390
425
|
onReachSeed?: (raw: RawCodeStructure, seed: ReachSeed) => void;
|
|
@@ -547,6 +582,8 @@ interface ExtractRubyOptions {
|
|
|
547
582
|
onCacheDiagnostic?: (diagnostic: CacheDiagnostic) => void;
|
|
548
583
|
/** Absolute. `<projectRoot>/.suss/cache` by default; `null` turns it off. */
|
|
549
584
|
cacheDir?: string | null;
|
|
585
|
+
/** What to do with gaps, which composing a controller's filters can add one of. */
|
|
586
|
+
gapHandling?: ExtractorOptions["gapHandling"];
|
|
550
587
|
}
|
|
551
588
|
interface ExtractRubyResult {
|
|
552
589
|
summaries: BehavioralSummary[];
|