@suss/recognize 0.11.0 → 0.13.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,197 +0,0 @@
1
- /**
2
- * The operations a chain performs at one call site, and what a language
3
- * adapter has to be able to work out for it.
4
- *
5
- * A chain is data, so something has to turn "did this module declare
6
- * the method" into a yes or no about a particular program. That is the
7
- * adapter's job, and this interface is the whole of what a chain asks
8
- * for. An adapter implements it once and every declared pack runs
9
- * there, which is what lets one pack drive several languages.
10
- *
11
- * Nothing here mentions a syntax tree. A link that needs the tree goes
12
- * through `@suss/recognize/ast`, a separate import so that reaching for
13
- * it shows up in a diff and in the pack health report.
14
- */
15
- /**
16
- * How a pack pins down the receiver a call is on.
17
- *
18
- * The migration plan for #542 lists four more: `factoryMade` (`app =
19
- * express()`), `imported`, `anchored` (a chain read from its anchor
20
- * call), `inherits` (a Ruby or Python receiver matched by ancestry) and
21
- * `global` (`process.env`, bare `fetch`). Each arrives as a member here
22
- * with an entry in every adapter's dispatch table. The README beside
23
- * this file says which starts are not receiver-shaped at all.
24
- */
25
- type ReceiverOrigin = DeclaredBy | ConstructedFrom;
26
- /**
27
- * A receiver whose method one of these modules declared.
28
- *
29
- * This is the origin for a client the source never spells out. `const
30
- * redis = await this.getClient()` says nothing about ioredis, and the
31
- * declaration behind `redis.get` says everything.
32
- */
33
- interface DeclaredBy {
34
- readonly origin: "declaredBy";
35
- /** The modules whose declarations settle the call. */
36
- readonly importedFrom: readonly string[];
37
- }
38
- /**
39
- * A client made from a module's export, however the program caches it.
40
- * Asked of the receiver itself, so it still works where the method is untyped
41
- * and `declaredBy` finds nothing to read.
42
- */
43
- interface ConstructedFrom {
44
- readonly origin: "constructed";
45
- /** The modules whose export the client was made from. */
46
- readonly importedFrom: readonly string[];
47
- }
48
- /**
49
- * A receiver whose method one of these modules declared. Pass every
50
- * module that ships the same client, the way three packages all speak
51
- * one wire protocol.
52
- */
53
- declare function declaredBy(...importedFrom: readonly string[]): DeclaredBy;
54
- /** A client made from one of these modules' exports. */
55
- declare function constructedFrom(...importedFrom: readonly string[]): ConstructedFrom;
56
- /**
57
- * What a reader gives back for a name nothing in the source settles.
58
- * `"nothing"` gives null, `"reference"` gives the value to go and ask
59
- * about instead.
60
- */
61
- type UnsettledName = "nothing" | "reference";
62
- /**
63
- * One call site, as the questions a chain asks about it.
64
- *
65
- * An adapter builds one of these per call and hands it to the
66
- * recognizer through its context. Every member is about the call in
67
- * hand, so there is no node to pass around and no place for a pack to
68
- * reach past what it declared.
69
- */
70
- interface CallOps {
71
- /** Which method the call reaches for, spelled as the source spells it. */
72
- method(): string | null;
73
- /** Whether the receiver came from where the origin says. */
74
- receiverIsFrom(origin: ReceiverOrigin): boolean;
75
- /** How many arguments the call passes. */
76
- argumentCount(): number;
77
- /** The name the argument in this position gives. */
78
- nameAt(index: number, unsettled: UnsettledName): string | null;
79
- /** The callee, as the source writes it. */
80
- calleeText(): string;
81
- }
82
- /**
83
- * The property an adapter puts its ops on, in the context it hands a
84
- * recognizer. A context without it belongs to an adapter that has not
85
- * implemented the ops, and a declared pack matches nothing there.
86
- */
87
- interface OpsCarrier {
88
- ops?: CallOps;
89
- }
90
- /** The ops in a recognizer context, or null when the adapter has none. */
91
- declare function opsIn(ctx: unknown): CallOps | null;
92
-
93
- /**
94
- * The spine every pack shares, as a chain of links.
95
- *
96
- * A pack does four jobs, and all four start the same way: match the
97
- * receiver, match the method, read the arguments, then yield. What
98
- * differs is the ending. Recognition yields effects, discovery yields a
99
- * unit, a terminal yields a response write, and a claimed callback
100
- * yields a sub-unit. Only the effects ending is built; the others are
101
- * further members of `Ending` with an entry in the compile table.
102
- *
103
- * A link's answer is data wherever it can be. A link given a function
104
- * instead is code, that link alone, and pack health says which ones.
105
- */
106
-
107
- /** A link whose answer a pack wrote as code rather than as data. */
108
- interface LinkFunction<A extends unknown[], R> {
109
- (...args: A): R;
110
- /** Set when the function was built through `@suss/recognize/ast`. */
111
- readonly reachesAst?: boolean;
112
- }
113
- /**
114
- * What a match starts from.
115
- *
116
- * Most of what the shipped packs match starts from a receiver, and none
117
- * of what discovery matches does: an exported name, a file path, a
118
- * decorator, a parameter's type, a template file beside the module and
119
- * a function's return type each start somewhere else. So the start is
120
- * its own axis, and a receiver origin is one value on it.
121
- */
122
- type MatchStart = FromReceiver;
123
- /** A match that starts from the receiver a call is on. */
124
- interface FromReceiver {
125
- readonly starts: "receiver";
126
- readonly origin: ReceiverOrigin;
127
- }
128
- /** Where the match begins. */
129
- interface StartLink {
130
- readonly asks: "start";
131
- readonly at: MatchStart;
132
- }
133
- /** Which methods count, and what each one does. */
134
- interface MethodsLink<TMeaning> {
135
- readonly asks: "methods";
136
- readonly table: Readonly<Record<string, TMeaning>>;
137
- /**
138
- * Whether two spellings of one method name are the same method. One
139
- * client library lower-cases where another camel-cases, and both are
140
- * sending the same command.
141
- */
142
- readonly ignoringCase: boolean;
143
- }
144
- /**
145
- * Which container a call's selector belongs to.
146
- *
147
- * The call in hand comes second so that a rule written over the
148
- * selector alone, which is most of them, ignores it. A rule that has to
149
- * read the syntax tree goes through `astLink`, which is what puts the
150
- * call to use.
151
- */
152
- interface ContainerLink {
153
- readonly asks: "container";
154
- readonly from: LinkFunction<[readonly string[], CallOps], string | null>;
155
- }
156
- /** One question in a chain, and the answer the pack gave for it. */
157
- type Link<TMeaning> = StartLink | MethodsLink<TMeaning> | ContainerLink;
158
- /** Which argument or arguments say what a call reached. */
159
- type ArgumentPick = {
160
- readonly at: number;
161
- } | {
162
- readonly from: number;
163
- };
164
- /** What one method of a storage client does. */
165
- interface StorageMethod {
166
- readonly kind: "read" | "write";
167
- /** Which argument or arguments say what the call reached. */
168
- readonly selector?: ArgumentPick;
169
- /** Which argument says which field inside it, when the method takes one. */
170
- readonly fields?: ArgumentPick;
171
- }
172
- /** What a chain produces when every link matches. */
173
- type Ending = StorageEnding;
174
- /** A storage access: one call, one thing it read or wrote. */
175
- interface StorageEnding {
176
- readonly yields: "storageAccess";
177
- /** The store, in the words OpenTelemetry's semantic conventions use. */
178
- readonly system: string;
179
- /** The wire, when it differs from the store's own name. */
180
- readonly transport?: string;
181
- /** Which of the store's namespaces the call reached. */
182
- readonly scope: string;
183
- /** What a reader gives back for a name nothing in the source settles. */
184
- readonly unsettledName: "nothing" | "reference";
185
- }
186
- /**
187
- * A pack's declaration for one kind of call: the links, the ending, and
188
- * a line of code it matches.
189
- */
190
- interface Chain<TMeaning = StorageMethod> {
191
- readonly links: readonly Link<TMeaning>[];
192
- readonly ending: Ending;
193
- /** A line of code this matches, which the pack's tests run. */
194
- readonly example: string | null;
195
- }
196
-
197
- export { type ArgumentPick as A, type CallOps as C, type DeclaredBy as D, type Ending as E, type FromReceiver as F, type LinkFunction as L, type MatchStart as M, type OpsCarrier as O, type ReceiverOrigin as R, type StorageMethod as S, type UnsettledName as U, type Chain as a, type ConstructedFrom as b, type ContainerLink as c, type Link as d, type MethodsLink as e, type StartLink as f, type StorageEnding as g, constructedFrom as h, declaredBy as i, opsIn as o };
@@ -1,197 +0,0 @@
1
- /**
2
- * The operations a chain performs at one call site, and what a language
3
- * adapter has to be able to work out for it.
4
- *
5
- * A chain is data, so something has to turn "did this module declare
6
- * the method" into a yes or no about a particular program. That is the
7
- * adapter's job, and this interface is the whole of what a chain asks
8
- * for. An adapter implements it once and every declared pack runs
9
- * there, which is what lets one pack drive several languages.
10
- *
11
- * Nothing here mentions a syntax tree. A link that needs the tree goes
12
- * through `@suss/recognize/ast`, a separate import so that reaching for
13
- * it shows up in a diff and in the pack health report.
14
- */
15
- /**
16
- * How a pack pins down the receiver a call is on.
17
- *
18
- * The migration plan for #542 lists four more: `factoryMade` (`app =
19
- * express()`), `imported`, `anchored` (a chain read from its anchor
20
- * call), `inherits` (a Ruby or Python receiver matched by ancestry) and
21
- * `global` (`process.env`, bare `fetch`). Each arrives as a member here
22
- * with an entry in every adapter's dispatch table. The README beside
23
- * this file says which starts are not receiver-shaped at all.
24
- */
25
- type ReceiverOrigin = DeclaredBy | ConstructedFrom;
26
- /**
27
- * A receiver whose method one of these modules declared.
28
- *
29
- * This is the origin for a client the source never spells out. `const
30
- * redis = await this.getClient()` says nothing about ioredis, and the
31
- * declaration behind `redis.get` says everything.
32
- */
33
- interface DeclaredBy {
34
- readonly origin: "declaredBy";
35
- /** The modules whose declarations settle the call. */
36
- readonly importedFrom: readonly string[];
37
- }
38
- /**
39
- * A client made from a module's export, however the program caches it.
40
- * Asked of the receiver itself, so it still works where the method is untyped
41
- * and `declaredBy` finds nothing to read.
42
- */
43
- interface ConstructedFrom {
44
- readonly origin: "constructed";
45
- /** The modules whose export the client was made from. */
46
- readonly importedFrom: readonly string[];
47
- }
48
- /**
49
- * A receiver whose method one of these modules declared. Pass every
50
- * module that ships the same client, the way three packages all speak
51
- * one wire protocol.
52
- */
53
- declare function declaredBy(...importedFrom: readonly string[]): DeclaredBy;
54
- /** A client made from one of these modules' exports. */
55
- declare function constructedFrom(...importedFrom: readonly string[]): ConstructedFrom;
56
- /**
57
- * What a reader gives back for a name nothing in the source settles.
58
- * `"nothing"` gives null, `"reference"` gives the value to go and ask
59
- * about instead.
60
- */
61
- type UnsettledName = "nothing" | "reference";
62
- /**
63
- * One call site, as the questions a chain asks about it.
64
- *
65
- * An adapter builds one of these per call and hands it to the
66
- * recognizer through its context. Every member is about the call in
67
- * hand, so there is no node to pass around and no place for a pack to
68
- * reach past what it declared.
69
- */
70
- interface CallOps {
71
- /** Which method the call reaches for, spelled as the source spells it. */
72
- method(): string | null;
73
- /** Whether the receiver came from where the origin says. */
74
- receiverIsFrom(origin: ReceiverOrigin): boolean;
75
- /** How many arguments the call passes. */
76
- argumentCount(): number;
77
- /** The name the argument in this position gives. */
78
- nameAt(index: number, unsettled: UnsettledName): string | null;
79
- /** The callee, as the source writes it. */
80
- calleeText(): string;
81
- }
82
- /**
83
- * The property an adapter puts its ops on, in the context it hands a
84
- * recognizer. A context without it belongs to an adapter that has not
85
- * implemented the ops, and a declared pack matches nothing there.
86
- */
87
- interface OpsCarrier {
88
- ops?: CallOps;
89
- }
90
- /** The ops in a recognizer context, or null when the adapter has none. */
91
- declare function opsIn(ctx: unknown): CallOps | null;
92
-
93
- /**
94
- * The spine every pack shares, as a chain of links.
95
- *
96
- * A pack does four jobs, and all four start the same way: match the
97
- * receiver, match the method, read the arguments, then yield. What
98
- * differs is the ending. Recognition yields effects, discovery yields a
99
- * unit, a terminal yields a response write, and a claimed callback
100
- * yields a sub-unit. Only the effects ending is built; the others are
101
- * further members of `Ending` with an entry in the compile table.
102
- *
103
- * A link's answer is data wherever it can be. A link given a function
104
- * instead is code, that link alone, and pack health says which ones.
105
- */
106
-
107
- /** A link whose answer a pack wrote as code rather than as data. */
108
- interface LinkFunction<A extends unknown[], R> {
109
- (...args: A): R;
110
- /** Set when the function was built through `@suss/recognize/ast`. */
111
- readonly reachesAst?: boolean;
112
- }
113
- /**
114
- * What a match starts from.
115
- *
116
- * Most of what the shipped packs match starts from a receiver, and none
117
- * of what discovery matches does: an exported name, a file path, a
118
- * decorator, a parameter's type, a template file beside the module and
119
- * a function's return type each start somewhere else. So the start is
120
- * its own axis, and a receiver origin is one value on it.
121
- */
122
- type MatchStart = FromReceiver;
123
- /** A match that starts from the receiver a call is on. */
124
- interface FromReceiver {
125
- readonly starts: "receiver";
126
- readonly origin: ReceiverOrigin;
127
- }
128
- /** Where the match begins. */
129
- interface StartLink {
130
- readonly asks: "start";
131
- readonly at: MatchStart;
132
- }
133
- /** Which methods count, and what each one does. */
134
- interface MethodsLink<TMeaning> {
135
- readonly asks: "methods";
136
- readonly table: Readonly<Record<string, TMeaning>>;
137
- /**
138
- * Whether two spellings of one method name are the same method. One
139
- * client library lower-cases where another camel-cases, and both are
140
- * sending the same command.
141
- */
142
- readonly ignoringCase: boolean;
143
- }
144
- /**
145
- * Which container a call's selector belongs to.
146
- *
147
- * The call in hand comes second so that a rule written over the
148
- * selector alone, which is most of them, ignores it. A rule that has to
149
- * read the syntax tree goes through `astLink`, which is what puts the
150
- * call to use.
151
- */
152
- interface ContainerLink {
153
- readonly asks: "container";
154
- readonly from: LinkFunction<[readonly string[], CallOps], string | null>;
155
- }
156
- /** One question in a chain, and the answer the pack gave for it. */
157
- type Link<TMeaning> = StartLink | MethodsLink<TMeaning> | ContainerLink;
158
- /** Which argument or arguments say what a call reached. */
159
- type ArgumentPick = {
160
- readonly at: number;
161
- } | {
162
- readonly from: number;
163
- };
164
- /** What one method of a storage client does. */
165
- interface StorageMethod {
166
- readonly kind: "read" | "write";
167
- /** Which argument or arguments say what the call reached. */
168
- readonly selector?: ArgumentPick;
169
- /** Which argument says which field inside it, when the method takes one. */
170
- readonly fields?: ArgumentPick;
171
- }
172
- /** What a chain produces when every link matches. */
173
- type Ending = StorageEnding;
174
- /** A storage access: one call, one thing it read or wrote. */
175
- interface StorageEnding {
176
- readonly yields: "storageAccess";
177
- /** The store, in the words OpenTelemetry's semantic conventions use. */
178
- readonly system: string;
179
- /** The wire, when it differs from the store's own name. */
180
- readonly transport?: string;
181
- /** Which of the store's namespaces the call reached. */
182
- readonly scope: string;
183
- /** What a reader gives back for a name nothing in the source settles. */
184
- readonly unsettledName: "nothing" | "reference";
185
- }
186
- /**
187
- * A pack's declaration for one kind of call: the links, the ending, and
188
- * a line of code it matches.
189
- */
190
- interface Chain<TMeaning = StorageMethod> {
191
- readonly links: readonly Link<TMeaning>[];
192
- readonly ending: Ending;
193
- /** A line of code this matches, which the pack's tests run. */
194
- readonly example: string | null;
195
- }
196
-
197
- export { type ArgumentPick as A, type CallOps as C, type DeclaredBy as D, type Ending as E, type FromReceiver as F, type LinkFunction as L, type MatchStart as M, type OpsCarrier as O, type ReceiverOrigin as R, type StorageMethod as S, type UnsettledName as U, type Chain as a, type ConstructedFrom as b, type ContainerLink as c, type Link as d, type MethodsLink as e, type StartLink as f, type StorageEnding as g, constructedFrom as h, declaredBy as i, opsIn as o };