@suss/resolution 0.1.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/LICENSE +205 -0
- package/README.md +81 -0
- package/dist/index.cjs +201 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +176 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable by
|
|
79
|
+
such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do not
|
|
117
|
+
modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor has
|
|
163
|
+
been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format please. Also add information on
|
|
185
|
+
how to contact you by electronic and paper mail.
|
|
186
|
+
|
|
187
|
+
If the program does not interact with users remotely through a computer
|
|
188
|
+
network, then your name and employer's name (e.g., your institution)
|
|
189
|
+
is sufficient to fill in the "name of copyright owner" field. Feel
|
|
190
|
+
free to omit the "name of employer" line if you are in no way affiliated
|
|
191
|
+
with any institution.
|
|
192
|
+
|
|
193
|
+
Copyright 2026 Nimbus Cloud AI LLC
|
|
194
|
+
|
|
195
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
196
|
+
you may not use this file except in compliance with the License.
|
|
197
|
+
You may obtain a copy of the License at
|
|
198
|
+
|
|
199
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
200
|
+
|
|
201
|
+
Unless required by applicable law or agreed to in writing, software
|
|
202
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
203
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
204
|
+
See the License for the specific language governing permissions and
|
|
205
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @suss/resolution
|
|
2
|
+
|
|
3
|
+
The rules for following a value to the function it comes down to.
|
|
4
|
+
|
|
5
|
+
## What this package is
|
|
6
|
+
|
|
7
|
+
A list of Datalog rules and nothing else. No parser, no language, no
|
|
8
|
+
files. An adapter reads source into facts, concatenates its own rules
|
|
9
|
+
onto these, and evaluates on `@suss/datalog`.
|
|
10
|
+
|
|
11
|
+
The rules are about programming languages rather than about any one of
|
|
12
|
+
them. A name binds to a value. A call puts an argument in a parameter. A
|
|
13
|
+
module exports a name and another module can forward it. A function that
|
|
14
|
+
returns a function calling its parameter hands back the argument it was
|
|
15
|
+
given, which is a decorator in Python, a closure in Go, and a handler
|
|
16
|
+
factory in TypeScript.
|
|
17
|
+
|
|
18
|
+
## The facts an adapter supplies
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
func(f) f is a function
|
|
22
|
+
binds(x, y) the name x is declared as y
|
|
23
|
+
paramOf(f, k, p) p is f's parameter at position k
|
|
24
|
+
returnsValue(f, v) f returns v
|
|
25
|
+
bodyCalls(f, c) f's body calls c
|
|
26
|
+
containsFn(f, g) g is declared inside f
|
|
27
|
+
call(r, c) r is a call whose callee is c
|
|
28
|
+
callArg(r, k, a) r passes a at position k
|
|
29
|
+
imports(x, m, n) x is the name n imported from module m
|
|
30
|
+
exportsAs(m, n, v) module m exports v under the name n
|
|
31
|
+
reExports(m, n, m2, n2) m's n is m2's n2
|
|
32
|
+
reExportsAll(m, m2) m forwards everything m2 exports
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Two more come from a pack rather than from source, for a wrapper whose
|
|
36
|
+
body nobody can read: `unwrapsByName(name, k)` and
|
|
37
|
+
`wrapperModule(name, module)`, checked against `calleeName` and
|
|
38
|
+
`calleeOrigin` so a local function spelled like the library's does not
|
|
39
|
+
match.
|
|
40
|
+
|
|
41
|
+
Node identity is the adapter's business. The rules only join on it.
|
|
42
|
+
|
|
43
|
+
## Why rules and not a walker
|
|
44
|
+
|
|
45
|
+
Each rule describes one hop. The chains people write are longer than
|
|
46
|
+
that, and nobody writes a rule for them: a factory handing off to
|
|
47
|
+
another factory, a closure three levels down calling the argument, a
|
|
48
|
+
barrel re-exporting a wrapper. The engine composes what it has, so those
|
|
49
|
+
work without being named.
|
|
50
|
+
|
|
51
|
+
The corollary is where to look when something comes back empty. Suspect
|
|
52
|
+
the facts before the rules. A production service once declared 91
|
|
53
|
+
handlers and resolved 11; the fix was one condition in fact extraction,
|
|
54
|
+
and the rules found the other 79 unchanged.
|
|
55
|
+
|
|
56
|
+
## What is not modelled
|
|
57
|
+
|
|
58
|
+
**A handler passed as one property of a config.** `make({ body:
|
|
59
|
+
handler })`, where the factory reads `opts.body`, does not resolve. A
|
|
60
|
+
rule for it was tried and taken out: production wrappers read several
|
|
61
|
+
callbacks off the same config (a log extractor, an error builder, the
|
|
62
|
+
handler), the rule made each one a candidate for the whole call, and
|
|
63
|
+
ambiguity nulled out sixty handlers that used to resolve. Saying which
|
|
64
|
+
property is the handler takes something structure does not carry,
|
|
65
|
+
either "the only property called" (which needs negation) or a pack
|
|
66
|
+
naming the property. Until one of those exists, this shape stays
|
|
67
|
+
unresolved on purpose.
|
|
68
|
+
|
|
69
|
+
**An element of an array.** `all[0]` has no fact for what an array
|
|
70
|
+
holds.
|
|
71
|
+
|
|
72
|
+
**Reassignment.** A name assigned twice resolves to the first
|
|
73
|
+
assignment rather than to both or to neither.
|
|
74
|
+
|
|
75
|
+
**Ambiguity is the caller's problem.** When the rules reach two
|
|
76
|
+
different functions the store returns nothing, since picking one would
|
|
77
|
+
make the answer depend on the order facts arrived in.
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
Licensed under Apache 2.0. See [LICENSE](../../LICENSE).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
RESOLUTION_RULES: () => RESOLUTION_RULES
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_datalog = require("@suss/datalog");
|
|
27
|
+
var RESOLUTION_RULES = [
|
|
28
|
+
// A value comes to itself; every chain ends at something written out
|
|
29
|
+
// in source, a function or an object.
|
|
30
|
+
(0, import_datalog.rule)("comesTo", [(0, import_datalog.variable)("x"), (0, import_datalog.variable)("x")], [(0, import_datalog.lit)("func", (0, import_datalog.variable)("x"))]),
|
|
31
|
+
(0, import_datalog.rule)("comesTo", [(0, import_datalog.variable)("x"), (0, import_datalog.variable)("x")], [(0, import_datalog.lit)("objectValue", (0, import_datalog.variable)("x"))]),
|
|
32
|
+
// Aliasing: const x = y, or an identifier referencing a declaration.
|
|
33
|
+
(0, import_datalog.rule)(
|
|
34
|
+
"comesTo",
|
|
35
|
+
[(0, import_datalog.variable)("x"), (0, import_datalog.variable)("z")],
|
|
36
|
+
[(0, import_datalog.lit)("binds", (0, import_datalog.variable)("x"), (0, import_datalog.variable)("y")), (0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("y"), (0, import_datalog.variable)("z"))]
|
|
37
|
+
),
|
|
38
|
+
// An import comes to what the module exports under that name.
|
|
39
|
+
(0, import_datalog.rule)(
|
|
40
|
+
"comesTo",
|
|
41
|
+
[(0, import_datalog.variable)("x"), (0, import_datalog.variable)("z")],
|
|
42
|
+
[
|
|
43
|
+
(0, import_datalog.lit)("imports", (0, import_datalog.variable)("x"), (0, import_datalog.variable)("m"), (0, import_datalog.variable)("n")),
|
|
44
|
+
(0, import_datalog.lit)("moduleExport", (0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("value")),
|
|
45
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("value"), (0, import_datalog.variable)("z"))
|
|
46
|
+
]
|
|
47
|
+
),
|
|
48
|
+
// What a module exports: directly, or through re-export chains.
|
|
49
|
+
(0, import_datalog.rule)(
|
|
50
|
+
"moduleExport",
|
|
51
|
+
[(0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("value")],
|
|
52
|
+
[(0, import_datalog.lit)("exportsAs", (0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("value"))]
|
|
53
|
+
),
|
|
54
|
+
(0, import_datalog.rule)(
|
|
55
|
+
"moduleExport",
|
|
56
|
+
[(0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("value")],
|
|
57
|
+
[
|
|
58
|
+
(0, import_datalog.lit)("reExports", (0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("m2"), (0, import_datalog.variable)("n2")),
|
|
59
|
+
(0, import_datalog.lit)("moduleExport", (0, import_datalog.variable)("m2"), (0, import_datalog.variable)("n2"), (0, import_datalog.variable)("value"))
|
|
60
|
+
]
|
|
61
|
+
),
|
|
62
|
+
(0, import_datalog.rule)(
|
|
63
|
+
"moduleExport",
|
|
64
|
+
[(0, import_datalog.variable)("m"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("value")],
|
|
65
|
+
[
|
|
66
|
+
(0, import_datalog.lit)("reExportsAll", (0, import_datalog.variable)("m"), (0, import_datalog.variable)("m2")),
|
|
67
|
+
(0, import_datalog.lit)("moduleExport", (0, import_datalog.variable)("m2"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("value"))
|
|
68
|
+
]
|
|
69
|
+
),
|
|
70
|
+
// Reading a property comes to what the object holds under that name.
|
|
71
|
+
// `comesTo` in the middle is what lets the object arrive through an
|
|
72
|
+
// alias, an import, or a factory call.
|
|
73
|
+
(0, import_datalog.rule)(
|
|
74
|
+
"comesTo",
|
|
75
|
+
[(0, import_datalog.variable)("x"), (0, import_datalog.variable)("z")],
|
|
76
|
+
[
|
|
77
|
+
(0, import_datalog.lit)("readsProperty", (0, import_datalog.variable)("x"), (0, import_datalog.variable)("o"), (0, import_datalog.variable)("n")),
|
|
78
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("o"), (0, import_datalog.variable)("obj")),
|
|
79
|
+
(0, import_datalog.lit)("holdsProperty", (0, import_datalog.variable)("obj"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("held")),
|
|
80
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("held"), (0, import_datalog.variable)("z"))
|
|
81
|
+
]
|
|
82
|
+
),
|
|
83
|
+
// Wrapper transparency, derived: calling a factory that returns a
|
|
84
|
+
// function which calls its parameter k comes to argument k.
|
|
85
|
+
(0, import_datalog.rule)(
|
|
86
|
+
"returnsFunc",
|
|
87
|
+
[(0, import_datalog.variable)("f"), (0, import_datalog.variable)("g")],
|
|
88
|
+
[
|
|
89
|
+
(0, import_datalog.lit)("returnsValue", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("value")),
|
|
90
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("value"), (0, import_datalog.variable)("g")),
|
|
91
|
+
(0, import_datalog.lit)("func", (0, import_datalog.variable)("g"))
|
|
92
|
+
]
|
|
93
|
+
),
|
|
94
|
+
// A call made by a nested closure counts as made by the function
|
|
95
|
+
// that declares it; the closure runs as part of that function.
|
|
96
|
+
(0, import_datalog.rule)("bodyCallsDeep", [(0, import_datalog.variable)("f"), (0, import_datalog.variable)("c")], [(0, import_datalog.lit)("bodyCalls", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("c"))]),
|
|
97
|
+
(0, import_datalog.rule)(
|
|
98
|
+
"bodyCallsDeep",
|
|
99
|
+
[(0, import_datalog.variable)("f"), (0, import_datalog.variable)("c")],
|
|
100
|
+
[(0, import_datalog.lit)("containsFn", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("g")), (0, import_datalog.lit)("bodyCallsDeep", (0, import_datalog.variable)("g"), (0, import_datalog.variable)("c"))]
|
|
101
|
+
),
|
|
102
|
+
(0, import_datalog.rule)(
|
|
103
|
+
"unwraps",
|
|
104
|
+
[(0, import_datalog.variable)("f"), (0, import_datalog.variable)("k")],
|
|
105
|
+
[
|
|
106
|
+
(0, import_datalog.lit)("returnsFunc", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("g")),
|
|
107
|
+
(0, import_datalog.lit)("bodyCallsDeep", (0, import_datalog.variable)("g"), (0, import_datalog.variable)("c")),
|
|
108
|
+
(0, import_datalog.lit)("binds", (0, import_datalog.variable)("c"), (0, import_datalog.variable)("p")),
|
|
109
|
+
(0, import_datalog.lit)("paramOf", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("k"), (0, import_datalog.variable)("p"))
|
|
110
|
+
]
|
|
111
|
+
),
|
|
112
|
+
// Argument flow: which parameter a value traces back to. Directly
|
|
113
|
+
// (an identifier bound to the parameter), or through a call to
|
|
114
|
+
// another unwrapping factory. This is what lets
|
|
115
|
+
// `createProtected(h) { return service.withAuth(h); }` unwrap:
|
|
116
|
+
// the returned call passes h through withAuth, which unwraps.
|
|
117
|
+
(0, import_datalog.rule)(
|
|
118
|
+
"flowsToParam",
|
|
119
|
+
[(0, import_datalog.variable)("x"), (0, import_datalog.variable)("p")],
|
|
120
|
+
[
|
|
121
|
+
(0, import_datalog.lit)("binds", (0, import_datalog.variable)("x"), (0, import_datalog.variable)("p")),
|
|
122
|
+
(0, import_datalog.lit)("paramOf", (0, import_datalog.variable)("anyF"), (0, import_datalog.variable)("anyK"), (0, import_datalog.variable)("p"))
|
|
123
|
+
]
|
|
124
|
+
),
|
|
125
|
+
(0, import_datalog.rule)(
|
|
126
|
+
"flowsToParam",
|
|
127
|
+
[(0, import_datalog.variable)("r"), (0, import_datalog.variable)("p")],
|
|
128
|
+
[
|
|
129
|
+
(0, import_datalog.lit)("call", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("c")),
|
|
130
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("c"), (0, import_datalog.variable)("f")),
|
|
131
|
+
(0, import_datalog.lit)("unwraps", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("k")),
|
|
132
|
+
(0, import_datalog.lit)("callArg", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("k"), (0, import_datalog.variable)("a")),
|
|
133
|
+
(0, import_datalog.lit)("flowsToParam", (0, import_datalog.variable)("a"), (0, import_datalog.variable)("p"))
|
|
134
|
+
]
|
|
135
|
+
),
|
|
136
|
+
(0, import_datalog.rule)(
|
|
137
|
+
"unwraps",
|
|
138
|
+
[(0, import_datalog.variable)("f"), (0, import_datalog.variable)("k")],
|
|
139
|
+
[
|
|
140
|
+
(0, import_datalog.lit)("returnsValue", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("value")),
|
|
141
|
+
(0, import_datalog.lit)("flowsToParam", (0, import_datalog.variable)("value"), (0, import_datalog.variable)("p")),
|
|
142
|
+
(0, import_datalog.lit)("paramOf", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("k"), (0, import_datalog.variable)("p"))
|
|
143
|
+
]
|
|
144
|
+
),
|
|
145
|
+
(0, import_datalog.rule)(
|
|
146
|
+
"comesTo",
|
|
147
|
+
[(0, import_datalog.variable)("r"), (0, import_datalog.variable)("h")],
|
|
148
|
+
[
|
|
149
|
+
(0, import_datalog.lit)("call", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("c")),
|
|
150
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("c"), (0, import_datalog.variable)("f")),
|
|
151
|
+
(0, import_datalog.lit)("unwraps", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("k")),
|
|
152
|
+
(0, import_datalog.lit)("callArg", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("k"), (0, import_datalog.variable)("a")),
|
|
153
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("a"), (0, import_datalog.variable)("h"))
|
|
154
|
+
]
|
|
155
|
+
),
|
|
156
|
+
// A property read off a call: `make(body).handle`. The call itself is
|
|
157
|
+
// not given a `comesTo`, since a factory call usually IS the wrapper
|
|
158
|
+
// and answering with the raw returned function would fight the
|
|
159
|
+
// unwraps answer. Only the property read narrows enough to be safe.
|
|
160
|
+
(0, import_datalog.rule)(
|
|
161
|
+
"comesTo",
|
|
162
|
+
[(0, import_datalog.variable)("x"), (0, import_datalog.variable)("z")],
|
|
163
|
+
[
|
|
164
|
+
(0, import_datalog.lit)("readsProperty", (0, import_datalog.variable)("x"), (0, import_datalog.variable)("r"), (0, import_datalog.variable)("n")),
|
|
165
|
+
(0, import_datalog.lit)("call", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("c")),
|
|
166
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("c"), (0, import_datalog.variable)("f")),
|
|
167
|
+
(0, import_datalog.lit)("returnsValue", (0, import_datalog.variable)("f"), (0, import_datalog.variable)("ret")),
|
|
168
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("ret"), (0, import_datalog.variable)("obj")),
|
|
169
|
+
(0, import_datalog.lit)("holdsProperty", (0, import_datalog.variable)("obj"), (0, import_datalog.variable)("n"), (0, import_datalog.variable)("held")),
|
|
170
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("held"), (0, import_datalog.variable)("z"))
|
|
171
|
+
]
|
|
172
|
+
),
|
|
173
|
+
// Wrapper transparency, declared: a pack says this callee wraps
|
|
174
|
+
// argument k, whatever its implementation looks like. The callee has
|
|
175
|
+
// to have been imported from the library the pack named, so a local
|
|
176
|
+
// object spelled the same way is not mistaken for it.
|
|
177
|
+
(0, import_datalog.rule)(
|
|
178
|
+
"comesTo",
|
|
179
|
+
[(0, import_datalog.variable)("r"), (0, import_datalog.variable)("h")],
|
|
180
|
+
[
|
|
181
|
+
(0, import_datalog.lit)("calleeName", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("n")),
|
|
182
|
+
(0, import_datalog.lit)("unwrapsByName", (0, import_datalog.variable)("n"), (0, import_datalog.variable)("k")),
|
|
183
|
+
(0, import_datalog.lit)("wrapperModule", (0, import_datalog.variable)("n"), (0, import_datalog.variable)("m")),
|
|
184
|
+
(0, import_datalog.lit)("calleeOrigin", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("m")),
|
|
185
|
+
(0, import_datalog.lit)("callArg", (0, import_datalog.variable)("r"), (0, import_datalog.variable)("k"), (0, import_datalog.variable)("a")),
|
|
186
|
+
(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("a"), (0, import_datalog.variable)("h"))
|
|
187
|
+
]
|
|
188
|
+
),
|
|
189
|
+
// The question callers ask: what a value comes to, narrowed to the
|
|
190
|
+
// functions. Objects appear in the middle of chains and never in an
|
|
191
|
+
// answer.
|
|
192
|
+
(0, import_datalog.rule)(
|
|
193
|
+
"resolves",
|
|
194
|
+
[(0, import_datalog.variable)("x"), (0, import_datalog.variable)("z")],
|
|
195
|
+
[(0, import_datalog.lit)("comesTo", (0, import_datalog.variable)("x"), (0, import_datalog.variable)("z")), (0, import_datalog.lit)("func", (0, import_datalog.variable)("z"))]
|
|
196
|
+
)
|
|
197
|
+
];
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
RESOLUTION_RULES
|
|
201
|
+
});
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { lit, rule, variable as v } from "@suss/datalog";
|
|
3
|
+
var RESOLUTION_RULES = [
|
|
4
|
+
// A value comes to itself; every chain ends at something written out
|
|
5
|
+
// in source, a function or an object.
|
|
6
|
+
rule("comesTo", [v("x"), v("x")], [lit("func", v("x"))]),
|
|
7
|
+
rule("comesTo", [v("x"), v("x")], [lit("objectValue", v("x"))]),
|
|
8
|
+
// Aliasing: const x = y, or an identifier referencing a declaration.
|
|
9
|
+
rule(
|
|
10
|
+
"comesTo",
|
|
11
|
+
[v("x"), v("z")],
|
|
12
|
+
[lit("binds", v("x"), v("y")), lit("comesTo", v("y"), v("z"))]
|
|
13
|
+
),
|
|
14
|
+
// An import comes to what the module exports under that name.
|
|
15
|
+
rule(
|
|
16
|
+
"comesTo",
|
|
17
|
+
[v("x"), v("z")],
|
|
18
|
+
[
|
|
19
|
+
lit("imports", v("x"), v("m"), v("n")),
|
|
20
|
+
lit("moduleExport", v("m"), v("n"), v("value")),
|
|
21
|
+
lit("comesTo", v("value"), v("z"))
|
|
22
|
+
]
|
|
23
|
+
),
|
|
24
|
+
// What a module exports: directly, or through re-export chains.
|
|
25
|
+
rule(
|
|
26
|
+
"moduleExport",
|
|
27
|
+
[v("m"), v("n"), v("value")],
|
|
28
|
+
[lit("exportsAs", v("m"), v("n"), v("value"))]
|
|
29
|
+
),
|
|
30
|
+
rule(
|
|
31
|
+
"moduleExport",
|
|
32
|
+
[v("m"), v("n"), v("value")],
|
|
33
|
+
[
|
|
34
|
+
lit("reExports", v("m"), v("n"), v("m2"), v("n2")),
|
|
35
|
+
lit("moduleExport", v("m2"), v("n2"), v("value"))
|
|
36
|
+
]
|
|
37
|
+
),
|
|
38
|
+
rule(
|
|
39
|
+
"moduleExport",
|
|
40
|
+
[v("m"), v("n"), v("value")],
|
|
41
|
+
[
|
|
42
|
+
lit("reExportsAll", v("m"), v("m2")),
|
|
43
|
+
lit("moduleExport", v("m2"), v("n"), v("value"))
|
|
44
|
+
]
|
|
45
|
+
),
|
|
46
|
+
// Reading a property comes to what the object holds under that name.
|
|
47
|
+
// `comesTo` in the middle is what lets the object arrive through an
|
|
48
|
+
// alias, an import, or a factory call.
|
|
49
|
+
rule(
|
|
50
|
+
"comesTo",
|
|
51
|
+
[v("x"), v("z")],
|
|
52
|
+
[
|
|
53
|
+
lit("readsProperty", v("x"), v("o"), v("n")),
|
|
54
|
+
lit("comesTo", v("o"), v("obj")),
|
|
55
|
+
lit("holdsProperty", v("obj"), v("n"), v("held")),
|
|
56
|
+
lit("comesTo", v("held"), v("z"))
|
|
57
|
+
]
|
|
58
|
+
),
|
|
59
|
+
// Wrapper transparency, derived: calling a factory that returns a
|
|
60
|
+
// function which calls its parameter k comes to argument k.
|
|
61
|
+
rule(
|
|
62
|
+
"returnsFunc",
|
|
63
|
+
[v("f"), v("g")],
|
|
64
|
+
[
|
|
65
|
+
lit("returnsValue", v("f"), v("value")),
|
|
66
|
+
lit("comesTo", v("value"), v("g")),
|
|
67
|
+
lit("func", v("g"))
|
|
68
|
+
]
|
|
69
|
+
),
|
|
70
|
+
// A call made by a nested closure counts as made by the function
|
|
71
|
+
// that declares it; the closure runs as part of that function.
|
|
72
|
+
rule("bodyCallsDeep", [v("f"), v("c")], [lit("bodyCalls", v("f"), v("c"))]),
|
|
73
|
+
rule(
|
|
74
|
+
"bodyCallsDeep",
|
|
75
|
+
[v("f"), v("c")],
|
|
76
|
+
[lit("containsFn", v("f"), v("g")), lit("bodyCallsDeep", v("g"), v("c"))]
|
|
77
|
+
),
|
|
78
|
+
rule(
|
|
79
|
+
"unwraps",
|
|
80
|
+
[v("f"), v("k")],
|
|
81
|
+
[
|
|
82
|
+
lit("returnsFunc", v("f"), v("g")),
|
|
83
|
+
lit("bodyCallsDeep", v("g"), v("c")),
|
|
84
|
+
lit("binds", v("c"), v("p")),
|
|
85
|
+
lit("paramOf", v("f"), v("k"), v("p"))
|
|
86
|
+
]
|
|
87
|
+
),
|
|
88
|
+
// Argument flow: which parameter a value traces back to. Directly
|
|
89
|
+
// (an identifier bound to the parameter), or through a call to
|
|
90
|
+
// another unwrapping factory. This is what lets
|
|
91
|
+
// `createProtected(h) { return service.withAuth(h); }` unwrap:
|
|
92
|
+
// the returned call passes h through withAuth, which unwraps.
|
|
93
|
+
rule(
|
|
94
|
+
"flowsToParam",
|
|
95
|
+
[v("x"), v("p")],
|
|
96
|
+
[
|
|
97
|
+
lit("binds", v("x"), v("p")),
|
|
98
|
+
lit("paramOf", v("anyF"), v("anyK"), v("p"))
|
|
99
|
+
]
|
|
100
|
+
),
|
|
101
|
+
rule(
|
|
102
|
+
"flowsToParam",
|
|
103
|
+
[v("r"), v("p")],
|
|
104
|
+
[
|
|
105
|
+
lit("call", v("r"), v("c")),
|
|
106
|
+
lit("comesTo", v("c"), v("f")),
|
|
107
|
+
lit("unwraps", v("f"), v("k")),
|
|
108
|
+
lit("callArg", v("r"), v("k"), v("a")),
|
|
109
|
+
lit("flowsToParam", v("a"), v("p"))
|
|
110
|
+
]
|
|
111
|
+
),
|
|
112
|
+
rule(
|
|
113
|
+
"unwraps",
|
|
114
|
+
[v("f"), v("k")],
|
|
115
|
+
[
|
|
116
|
+
lit("returnsValue", v("f"), v("value")),
|
|
117
|
+
lit("flowsToParam", v("value"), v("p")),
|
|
118
|
+
lit("paramOf", v("f"), v("k"), v("p"))
|
|
119
|
+
]
|
|
120
|
+
),
|
|
121
|
+
rule(
|
|
122
|
+
"comesTo",
|
|
123
|
+
[v("r"), v("h")],
|
|
124
|
+
[
|
|
125
|
+
lit("call", v("r"), v("c")),
|
|
126
|
+
lit("comesTo", v("c"), v("f")),
|
|
127
|
+
lit("unwraps", v("f"), v("k")),
|
|
128
|
+
lit("callArg", v("r"), v("k"), v("a")),
|
|
129
|
+
lit("comesTo", v("a"), v("h"))
|
|
130
|
+
]
|
|
131
|
+
),
|
|
132
|
+
// A property read off a call: `make(body).handle`. The call itself is
|
|
133
|
+
// not given a `comesTo`, since a factory call usually IS the wrapper
|
|
134
|
+
// and answering with the raw returned function would fight the
|
|
135
|
+
// unwraps answer. Only the property read narrows enough to be safe.
|
|
136
|
+
rule(
|
|
137
|
+
"comesTo",
|
|
138
|
+
[v("x"), v("z")],
|
|
139
|
+
[
|
|
140
|
+
lit("readsProperty", v("x"), v("r"), v("n")),
|
|
141
|
+
lit("call", v("r"), v("c")),
|
|
142
|
+
lit("comesTo", v("c"), v("f")),
|
|
143
|
+
lit("returnsValue", v("f"), v("ret")),
|
|
144
|
+
lit("comesTo", v("ret"), v("obj")),
|
|
145
|
+
lit("holdsProperty", v("obj"), v("n"), v("held")),
|
|
146
|
+
lit("comesTo", v("held"), v("z"))
|
|
147
|
+
]
|
|
148
|
+
),
|
|
149
|
+
// Wrapper transparency, declared: a pack says this callee wraps
|
|
150
|
+
// argument k, whatever its implementation looks like. The callee has
|
|
151
|
+
// to have been imported from the library the pack named, so a local
|
|
152
|
+
// object spelled the same way is not mistaken for it.
|
|
153
|
+
rule(
|
|
154
|
+
"comesTo",
|
|
155
|
+
[v("r"), v("h")],
|
|
156
|
+
[
|
|
157
|
+
lit("calleeName", v("r"), v("n")),
|
|
158
|
+
lit("unwrapsByName", v("n"), v("k")),
|
|
159
|
+
lit("wrapperModule", v("n"), v("m")),
|
|
160
|
+
lit("calleeOrigin", v("r"), v("m")),
|
|
161
|
+
lit("callArg", v("r"), v("k"), v("a")),
|
|
162
|
+
lit("comesTo", v("a"), v("h"))
|
|
163
|
+
]
|
|
164
|
+
),
|
|
165
|
+
// The question callers ask: what a value comes to, narrowed to the
|
|
166
|
+
// functions. Objects appear in the middle of chains and never in an
|
|
167
|
+
// answer.
|
|
168
|
+
rule(
|
|
169
|
+
"resolves",
|
|
170
|
+
[v("x"), v("z")],
|
|
171
|
+
[lit("comesTo", v("x"), v("z")), lit("func", v("z"))]
|
|
172
|
+
)
|
|
173
|
+
];
|
|
174
|
+
export {
|
|
175
|
+
RESOLUTION_RULES
|
|
176
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@suss/resolution",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Language-neutral rules for following a value to the function it comes down to.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"suss",
|
|
8
|
+
"datalog",
|
|
9
|
+
"resolution",
|
|
10
|
+
"static-analysis"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"author": "Nimbus Cloud AI LLC",
|
|
14
|
+
"homepage": "https://github.com/nimbuscloud-ai/suss/tree/main/packages/resolution#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/nimbuscloud-ai/suss.git",
|
|
18
|
+
"directory": "packages/resolution"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/nimbuscloud-ai/suss/issues"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"test:coverage": "vitest run --coverage",
|
|
42
|
+
"lint": "biome check .",
|
|
43
|
+
"lint:fix": "biome check --write .",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"fast-check": "^3.23.1",
|
|
48
|
+
"tsup": "*",
|
|
49
|
+
"typescript": "*",
|
|
50
|
+
"vitest": "*"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@suss/datalog": "0.1.0"
|
|
57
|
+
}
|
|
58
|
+
}
|