@systemfsoftware/effect-schema-vite 1.5.1 → 1.5.3
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/CHANGELOG.md +69 -0
- package/LICENSE +203 -21
- package/README.md +23 -0
- package/dist/effect-schema-vite.d.ts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +216 -6
- package/package.json +19 -18
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @systemfsoftware/effect-schema-vite
|
|
2
|
+
|
|
3
|
+
## 1.5.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Array types are spelled one way. `Array<T>` and `ReadonlyArray<T>` in emitted
|
|
8
|
+
declarations become `T[]` and `readonly T[]`, which the type checker cannot tell
|
|
9
|
+
apart: no exported type changes, only how it is written.
|
|
10
|
+
|
|
11
|
+
- New version is published through npm trusted publishing, so it carries a provenance attestation you can verify.
|
|
12
|
+
|
|
13
|
+
- Declare the effect-schema-law peer dependency as a workspace range so recursive versioning resolves it.
|
|
14
|
+
|
|
15
|
+
- Each of these packages now has a README, so its registry page says what the package is, how
|
|
16
|
+
to install it, and what to import or register — previously the page was blank. The lint
|
|
17
|
+
plugins show the configuration line that enables what they recommend.
|
|
18
|
+
|
|
19
|
+
`@systemfsoftware/stryker-js-mutation-report` also carries its licence text
|
|
20
|
+
|
|
21
|
+
- Generated schema law suites no longer fail to load when a module exports a value derived from a schema rather than a schema itself — a type guard from `Schema.is`, a decoder, an encoder, or an arbitrary. Such an export is skipped instead of being handed to the round-trip laws.
|
|
22
|
+
|
|
23
|
+
- Generated schema laws no longer break when a package exports a value read off a
|
|
24
|
+
codec or JSON-Schema document, such as `Schema.toJsonSchemaDocument(x).schema`.
|
|
25
|
+
Those exports are uses of a schema rather than schemas, and generating
|
|
26
|
+
round-trip laws for one made the whole generated suite fail to load, reporting
|
|
27
|
+
no tests at all. They are now skipped, so the suite runs the laws for the real
|
|
28
|
+
schemas beside them.
|
|
29
|
+
|
|
30
|
+
The set of members recognised as uses is also complete now: the encode side was
|
|
31
|
+
missing its `Exit`, `Option`, `Result` and `Promise` variants, so a schema whose
|
|
32
|
+
declaration used one of those was skipped when it should have been law-tested.
|
|
33
|
+
|
|
34
|
+
- Updated dependencies:
|
|
35
|
+
- @systemfsoftware/effect-schema-law@0.8.0
|
|
36
|
+
|
|
37
|
+
## 1.5.2
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Array types are spelled one way. `Array<T>` and `ReadonlyArray<T>` in emitted
|
|
42
|
+
declarations become `T[]` and `readonly T[]`, which the type checker cannot tell
|
|
43
|
+
apart: no exported type changes, only how it is written.
|
|
44
|
+
|
|
45
|
+
- New version is published through npm trusted publishing, so it carries a provenance attestation you can verify.
|
|
46
|
+
|
|
47
|
+
- Declare the effect-schema-law peer dependency as a workspace range so recursive versioning resolves it.
|
|
48
|
+
|
|
49
|
+
- Each of these packages now has a README, so its registry page says what the package is, how
|
|
50
|
+
to install it, and what to import or register — previously the page was blank. The lint
|
|
51
|
+
plugins show the configuration line that enables what they recommend.
|
|
52
|
+
|
|
53
|
+
`@systemfsoftware/stryker-js-mutation-report` also carries its licence text
|
|
54
|
+
|
|
55
|
+
- Generated schema law suites no longer fail to load when a module exports a value derived from a schema rather than a schema itself — a type guard from `Schema.is`, a decoder, an encoder, or an arbitrary. Such an export is skipped instead of being handed to the round-trip laws.
|
|
56
|
+
|
|
57
|
+
- Generated schema laws no longer break when a package exports a value read off a
|
|
58
|
+
codec or JSON-Schema document, such as `Schema.toJsonSchemaDocument(x).schema`.
|
|
59
|
+
Those exports are uses of a schema rather than schemas, and generating
|
|
60
|
+
round-trip laws for one made the whole generated suite fail to load, reporting
|
|
61
|
+
no tests at all. They are now skipped, so the suite runs the laws for the real
|
|
62
|
+
schemas beside them.
|
|
63
|
+
|
|
64
|
+
The set of members recognised as uses is also complete now: the encode side was
|
|
65
|
+
missing its `Exit`, `Option`, `Result` and `Promise` variants, so a schema whose
|
|
66
|
+
declaration used one of those was skipped when it should have been law-tested.
|
|
67
|
+
|
|
68
|
+
- Updated dependencies:
|
|
69
|
+
- @systemfsoftware/effect-schema-law@0.7.0
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,203 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Copyright (c) 2026 Ryan Lee (systemfsoftware)
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright 2026 Ryan Lee (systemfsoftware)
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @systemfsoftware/effect-schema-vite
|
|
2
|
+
|
|
3
|
+
Vite plugin that auto-discovers Effect Schema exports and injects round-trip property tests via @systemfsoftware/effect-schema-law.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @systemfsoftware/effect-schema-vite '@systemfsoftware/effect-schema-law@0.6.1' 'effect@4.0.0-rc.108' 'vite@>5.0.0' 'vitest@*'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Those are peer dependencies: this package declares them but does not install them, so one copy is shared with the rest of your project.
|
|
12
|
+
|
|
13
|
+
## Entry points
|
|
14
|
+
|
|
15
|
+
- `@systemfsoftware/effect-schema-vite`
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
The public surface is generated from the source and versioned with the package: [`etc/effect-schema-vite.api.md`](./etc/effect-schema-vite.api.md).
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
Apache-2.0. Part of [systemfsoftware](https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/effect-schema-vite#readme).
|
|
@@ -7,6 +7,12 @@ import { Plugin as Plugin_2 } from 'vite';
|
|
|
7
7
|
* file being rewritten lives in `src/`, so a root-relative specifier resolves
|
|
8
8
|
* to `src/src/…` and yields a suite that silently imports nothing.
|
|
9
9
|
*
|
|
10
|
+
* Every schema is imported under a generated local alias. Two modules may
|
|
11
|
+
* export the same name, and a bare `import { X }` pair for them is invalid
|
|
12
|
+
* ESM — one binding wins, so a schema silently loses its laws to its
|
|
13
|
+
* namesake while the suite still reports a passing pair for it. An alias also
|
|
14
|
+
* keeps a schema named `it` or `ruleOfSchemas` from shadowing the harness.
|
|
15
|
+
*
|
|
10
16
|
* @since 1.4.0
|
|
11
17
|
*/
|
|
12
18
|
export declare const generateSchemaLaws: (lawFilePath: string, srcDir: string) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ declare const LAW_FILE_BASENAME: 'schema-laws.test.ts';
|
|
|
19
19
|
* file being rewritten lives in `src/`, so a root-relative specifier resolves
|
|
20
20
|
* to `src/src/…` and yields a suite that silently imports nothing.
|
|
21
21
|
*
|
|
22
|
+
* Every schema is imported under a generated local alias. Two modules may
|
|
23
|
+
* export the same name, and a bare `import { X }` pair for them is invalid
|
|
24
|
+
* ESM — one binding wins, so a schema silently loses its laws to its
|
|
25
|
+
* namesake while the suite still reports a passing pair for it. An alias also
|
|
26
|
+
* keeps a schema named `it` or `ruleOfSchemas` from shadowing the harness.
|
|
27
|
+
*
|
|
22
28
|
* @since 1.4.0
|
|
23
29
|
*/
|
|
24
30
|
declare const generateSchemaLaws: (lawFilePath: string, srcDir: string) => string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
2
|
import { dirname, extname, join, relative, resolve } from "node:path";
|
|
3
3
|
import { parseSync } from "oxc-parser";
|
|
4
4
|
//#region src/mod.ts
|
|
@@ -10,6 +10,24 @@ import { parseSync } from "oxc-parser";
|
|
|
10
10
|
*/
|
|
11
11
|
const LAW_FILE_BASENAME = "schema-laws.test.ts";
|
|
12
12
|
/**
|
|
13
|
+
* A schema is identified by the module that declares it *and* its exported
|
|
14
|
+
* name — never the name alone. Two files may export the same name, and every
|
|
15
|
+
* name-keyed decision (import binding, law title, refutation coverage) then
|
|
16
|
+
* conflates them.
|
|
17
|
+
*
|
|
18
|
+
* The path is resolved because the two sides reach it differently: a walk
|
|
19
|
+
* joins the caller's `srcDir`, which may be relative, while an import is
|
|
20
|
+
* resolved against the importing file and is always absolute.
|
|
21
|
+
*/
|
|
22
|
+
const identityOf = (filePath, name) => `${resolve(filePath)}#${name}`;
|
|
23
|
+
/**
|
|
24
|
+
* A single-quoted TypeScript literal. Every quoted value the suite emits is
|
|
25
|
+
* built from a filesystem path, and a path may legally hold a quote or a
|
|
26
|
+
* backslash — unescaped, either ends the literal early and leaves the whole
|
|
27
|
+
* generated file unparseable, so no law in the package runs at all.
|
|
28
|
+
*/
|
|
29
|
+
const quote = (value) => `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
30
|
+
/**
|
|
13
31
|
* Walk a directory and return every exported const whose type annotation
|
|
14
32
|
* or initialiser references Effect Schema APIs.
|
|
15
33
|
*/
|
|
@@ -75,18 +93,177 @@ function findExportedSchemaNames(source) {
|
|
|
75
93
|
return [];
|
|
76
94
|
}
|
|
77
95
|
}
|
|
96
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
97
|
+
const identifierName = (value) => {
|
|
98
|
+
if (!isRecord(value)) return void 0;
|
|
99
|
+
return value["type"] === "Identifier" && typeof value["name"] === "string" ? value["name"] : void 0;
|
|
100
|
+
};
|
|
101
|
+
function findRefutesCallSites(source) {
|
|
102
|
+
try {
|
|
103
|
+
const names = [];
|
|
104
|
+
const visit = (node) => {
|
|
105
|
+
if (Array.isArray(node)) {
|
|
106
|
+
for (const child of node) visit(child);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!isRecord(node)) return;
|
|
110
|
+
if (node["type"] === "CallExpression" && identifierName(node["callee"]) === "refutes") {
|
|
111
|
+
const args = node["arguments"];
|
|
112
|
+
const first = Array.isArray(args) ? identifierName(args[0]) : void 0;
|
|
113
|
+
if (first !== void 0) names.push(first);
|
|
114
|
+
}
|
|
115
|
+
for (const value of Object.values(node)) visit(value);
|
|
116
|
+
};
|
|
117
|
+
visit(parseSync("temp.ts", source).program.body);
|
|
118
|
+
return names;
|
|
119
|
+
} catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const MODULE_EXTENSION = /\.(?:m|c)?[jt]sx?$/;
|
|
124
|
+
const resolveLocalModule = (fromFile, specifier) => {
|
|
125
|
+
if (!specifier.startsWith(".")) return void 0;
|
|
126
|
+
const base = resolve(dirname(fromFile), specifier.replace(MODULE_EXTENSION, ""));
|
|
127
|
+
return [`${base}.ts`, join(base, "index.ts")].find((candidate) => existsSync(candidate));
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Every name a `refutes` call site could be holding, mapped to the identity
|
|
131
|
+
* of the schema it denotes — or to `undefined` when the name is imported but
|
|
132
|
+
* the declaring module could not be pinned. Presence therefore means "came
|
|
133
|
+
* from an import", which is what licenses the by-name fallback below; a name
|
|
134
|
+
* absent from this map was declared in the file itself.
|
|
135
|
+
*/
|
|
136
|
+
const importedBindings = (filePath, source) => {
|
|
137
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
138
|
+
try {
|
|
139
|
+
for (const node of parseSync("temp.ts", source).program.body) {
|
|
140
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
141
|
+
const declaring = resolveLocalModule(filePath, node.source.value);
|
|
142
|
+
for (const spec of node.specifiers ?? []) {
|
|
143
|
+
if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") {
|
|
144
|
+
bindings.set(spec.local.name, void 0);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (spec.type !== "ImportSpecifier") continue;
|
|
148
|
+
if (spec.imported.type !== "Identifier") continue;
|
|
149
|
+
bindings.set(spec.local.name, declaring === void 0 ? void 0 : identityOf(declaring, spec.imported.name));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
return bindings;
|
|
154
|
+
}
|
|
155
|
+
return bindings;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Identities of the schemas some `refutes` call discharges.
|
|
159
|
+
*
|
|
160
|
+
* A call site resolves exactly when its import pins a module that declares
|
|
161
|
+
* one of `schemas`. When it does not — a barrel re-export, a default import,
|
|
162
|
+
* an unresolvable specifier — the name is matched against `schemas` instead,
|
|
163
|
+
* but only while exactly one schema bears it. An ambiguous name is left
|
|
164
|
+
* undischarged rather than guessed, which is the whole point: guessing is
|
|
165
|
+
* how a refusal stated against one module came to cover its namesake.
|
|
166
|
+
*/
|
|
167
|
+
function findRefutedIdentities(dir, schemas) {
|
|
168
|
+
const declared = new Set(schemas.map((s) => identityOf(s.filePath, s.name)));
|
|
169
|
+
const byName = /* @__PURE__ */ new Map();
|
|
170
|
+
for (const s of schemas) {
|
|
171
|
+
const identity = identityOf(s.filePath, s.name);
|
|
172
|
+
byName.set(s.name, byName.has(s.name) ? void 0 : identity);
|
|
173
|
+
}
|
|
174
|
+
const refuted = /* @__PURE__ */ new Set();
|
|
175
|
+
const walk = (current) => {
|
|
176
|
+
let entries;
|
|
177
|
+
try {
|
|
178
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
179
|
+
} catch {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
for (const dirent of entries) {
|
|
183
|
+
const full = join(current, dirent.name);
|
|
184
|
+
if (dirent.isDirectory()) {
|
|
185
|
+
if (dirent.name === "node_modules" || dirent.name === ".git") continue;
|
|
186
|
+
walk(full);
|
|
187
|
+
} else if (dirent.isFile() && extname(dirent.name) === ".ts") {
|
|
188
|
+
const source = readFileSync(full, "utf-8");
|
|
189
|
+
const sites = findRefutesCallSites(source);
|
|
190
|
+
if (sites.length === 0) continue;
|
|
191
|
+
const bindings = importedBindings(full, source);
|
|
192
|
+
for (const name of sites) {
|
|
193
|
+
const bound = bindings.get(name);
|
|
194
|
+
if (bound !== void 0 && declared.has(bound)) refuted.add(bound);
|
|
195
|
+
else if (!bindings.has(name)) refuted.add(identityOf(full, name));
|
|
196
|
+
else {
|
|
197
|
+
const sole = byName.get(name);
|
|
198
|
+
if (sole !== void 0) refuted.add(sole);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
walk(dir);
|
|
205
|
+
return refuted;
|
|
206
|
+
}
|
|
78
207
|
function typeRefContainsSchema(t) {
|
|
79
208
|
if (!t) return false;
|
|
80
209
|
if (t.type === "TSTypeReference" && t.typeName.type === "Identifier") return t.typeName.name.includes("Schema");
|
|
81
210
|
if (t.type === "TSUnionType" || t.type === "TSIntersectionType") return t.types.some((member) => typeRefContainsSchema(member));
|
|
82
211
|
return false;
|
|
83
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Schema members whose return value is NOT a schema: a type guard, a decoder, an encoder,
|
|
215
|
+
* an arbitrary, or a JSON-schema document. A const bound to one of these is a *use* of the
|
|
216
|
+
* schema it names, so generating round-trip laws for it hands `encodeUnknownEffect` a
|
|
217
|
+
* predicate and the generated suite dies at import with `Cannot read properties of
|
|
218
|
+
* undefined (reading 'encoding')`. Measured 2026-08-17 on `S.is` in `stryker-plugins`.
|
|
219
|
+
*
|
|
220
|
+
* Enumerated, never prefix-matched: `Schema.decodeTo` starts with `decode` and *does*
|
|
221
|
+
* produce a schema, so a `/^decode/` test would silently drop a real codec's laws.
|
|
222
|
+
*/
|
|
223
|
+
const SCHEMA_USE_MEMBERS = {
|
|
224
|
+
decode: true,
|
|
225
|
+
decodeEffect: true,
|
|
226
|
+
decodeExit: true,
|
|
227
|
+
decodeOption: true,
|
|
228
|
+
decodePromise: true,
|
|
229
|
+
decodeResult: true,
|
|
230
|
+
decodeSync: true,
|
|
231
|
+
decodeUnknownEffect: true,
|
|
232
|
+
decodeUnknownExit: true,
|
|
233
|
+
decodeUnknownOption: true,
|
|
234
|
+
decodeUnknownPromise: true,
|
|
235
|
+
decodeUnknownResult: true,
|
|
236
|
+
decodeUnknownSync: true,
|
|
237
|
+
encode: true,
|
|
238
|
+
encodeEffect: true,
|
|
239
|
+
encodeExit: true,
|
|
240
|
+
encodeOption: true,
|
|
241
|
+
encodePromise: true,
|
|
242
|
+
encodeResult: true,
|
|
243
|
+
encodeSync: true,
|
|
244
|
+
encodeUnknownEffect: true,
|
|
245
|
+
encodeUnknownExit: true,
|
|
246
|
+
encodeUnknownOption: true,
|
|
247
|
+
encodeUnknownPromise: true,
|
|
248
|
+
encodeUnknownResult: true,
|
|
249
|
+
encodeUnknownSync: true,
|
|
250
|
+
toArbitrary: true,
|
|
251
|
+
toJsonSchemaDocument: true,
|
|
252
|
+
is: true,
|
|
253
|
+
isSchema: true,
|
|
254
|
+
isSchemaError: true,
|
|
255
|
+
isSchemaAST: true
|
|
256
|
+
};
|
|
257
|
+
/** True when the member call produces a non-schema value, e.g. `S.is(X)` or `S.encodeSync(X)`. */
|
|
258
|
+
function isSchemaUseCall(callee) {
|
|
259
|
+
return callee.property.type === "Identifier" && SCHEMA_USE_MEMBERS[callee.property.name] === true;
|
|
260
|
+
}
|
|
84
261
|
function initRefersToSchema(expr) {
|
|
85
262
|
if (!expr) return false;
|
|
86
263
|
if (expr.type === "CallExpression") {
|
|
87
264
|
const callee = expr.callee;
|
|
88
265
|
if (callee.type === "Identifier" && callee.name === "pipe") return expr.arguments.some((arg) => arg.type !== "SpreadElement" && initRefersToSchema(arg));
|
|
89
|
-
if (callee.type === "MemberExpression") return memberChainStartsWithS(callee);
|
|
266
|
+
if (callee.type === "MemberExpression") return memberChainStartsWithS(callee) && !isSchemaUseCall(callee);
|
|
90
267
|
if (callee.type === "Identifier") return callee.name.includes("Schema");
|
|
91
268
|
return false;
|
|
92
269
|
}
|
|
@@ -99,7 +276,7 @@ function memberChainStartsWithS(node) {
|
|
|
99
276
|
if (obj.type === "MemberExpression") return memberChainStartsWithS(obj);
|
|
100
277
|
if (obj.type === "CallExpression") {
|
|
101
278
|
const callee = obj.callee;
|
|
102
|
-
if (callee.type === "MemberExpression") return memberChainStartsWithS(callee);
|
|
279
|
+
if (callee.type === "MemberExpression") return memberChainStartsWithS(callee) && !isSchemaUseCall(callee);
|
|
103
280
|
if (callee.type === "Identifier") return callee.name === "S" || callee.name.includes("Schema");
|
|
104
281
|
}
|
|
105
282
|
return false;
|
|
@@ -131,6 +308,12 @@ function extendsSchemaClass(superClass) {
|
|
|
131
308
|
* file being rewritten lives in `src/`, so a root-relative specifier resolves
|
|
132
309
|
* to `src/src/…` and yields a suite that silently imports nothing.
|
|
133
310
|
*
|
|
311
|
+
* Every schema is imported under a generated local alias. Two modules may
|
|
312
|
+
* export the same name, and a bare `import { X }` pair for them is invalid
|
|
313
|
+
* ESM — one binding wins, so a schema silently loses its laws to its
|
|
314
|
+
* namesake while the suite still reports a passing pair for it. An alias also
|
|
315
|
+
* keeps a schema named `it` or `ruleOfSchemas` from shadowing the harness.
|
|
316
|
+
*
|
|
134
317
|
* @since 1.4.0
|
|
135
318
|
*/
|
|
136
319
|
const generateSchemaLaws = (lawFilePath, srcDir) => {
|
|
@@ -140,11 +323,38 @@ const generateSchemaLaws = (lawFilePath, srcDir) => {
|
|
|
140
323
|
const rel = relative(dirname(lawFilePath), filePath).replace(/\.ts$/, "");
|
|
141
324
|
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
142
325
|
};
|
|
326
|
+
const nameCount = /* @__PURE__ */ new Map();
|
|
327
|
+
for (const s of schemas) nameCount.set(s.name, (nameCount.get(s.name) ?? 0) + 1);
|
|
328
|
+
const labelOf = (s) => (nameCount.get(s.name) ?? 0) > 1 ? `${s.name} (${specifierOf(s.filePath)})` : s.name;
|
|
329
|
+
const refuted = findRefutedIdentities(srcDir, schemas);
|
|
330
|
+
const quoted = schemas.filter((s) => refuted.has(identityOf(s.filePath, s.name))).map((s) => quote(labelOf(s))).sort().join(", ");
|
|
143
331
|
return [
|
|
144
|
-
`import {
|
|
145
|
-
|
|
332
|
+
`import type { AST } from 'effect/SchemaAST'`,
|
|
333
|
+
`import { it } from 'vitest'`,
|
|
334
|
+
`import { obligationsOf, ruleOfSchemas } from '@systemfsoftware/effect-schema-law'`,
|
|
335
|
+
schemas.map((s, i) => `import { ${s.name} as schema_${i} } from ${quote(specifierOf(s.filePath))}`).join("\n"),
|
|
336
|
+
"",
|
|
337
|
+
schemas.map((s, i) => `ruleOfSchemas(${quote(labelOf(s))}, schema_${i})`).join("\n"),
|
|
338
|
+
"",
|
|
339
|
+
`const REFUTED: ReadonlySet<string> = new Set([${quoted}])`,
|
|
340
|
+
"",
|
|
341
|
+
`const EXPORTED: ReadonlyArray<readonly [string, Parameters<typeof obligationsOf>[0]]> = [`,
|
|
342
|
+
schemas.map((s, i) => ` [${quote(labelOf(s))}, schema_${i}],`).join("\n"),
|
|
343
|
+
`]`,
|
|
146
344
|
"",
|
|
147
|
-
|
|
345
|
+
`it('every obligation reachable from an exported schema is refuted somewhere', () => {`,
|
|
346
|
+
` const covered = new Set<AST>()`,
|
|
347
|
+
` for (const [name, schema] of EXPORTED) {`,
|
|
348
|
+
` if (!REFUTED.has(name)) continue`,
|
|
349
|
+
` for (const node of obligationsOf(schema).keys()) covered.add(node)`,
|
|
350
|
+
` }`,
|
|
351
|
+
` const naked = EXPORTED`,
|
|
352
|
+
` .filter(([, schema]) => [...obligationsOf(schema).keys()].some((n) => !covered.has(n)))`,
|
|
353
|
+
` .map(([name]) => name)`,
|
|
354
|
+
` if (naked.length > 0) {`,
|
|
355
|
+
" throw new Error(`schema(s) reaching an obligation no refutes call discharges: ${naked.join(', ')}`)",
|
|
356
|
+
` }`,
|
|
357
|
+
`})`
|
|
148
358
|
].join("\n");
|
|
149
359
|
};
|
|
150
360
|
/**
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-schema-vite",
|
|
3
|
-
"license": "
|
|
4
|
-
"version": "1.5.
|
|
3
|
+
"license": "Apache-2.0",
|
|
4
|
+
"version": "1.5.3",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/systemfsoftware/systemfsoftware.git",
|
|
9
|
-
"directory": "packages/effect
|
|
9
|
+
"directory": "packages/core/effect/schema/vite"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/effect
|
|
11
|
+
"homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/core/effect/schema/vite#readme",
|
|
12
12
|
"bugs": "https://github.com/systemfsoftware/systemfsoftware/issues",
|
|
13
13
|
"description": "Vite plugin that auto-discovers Effect Schema exports and injects round-trip property tests via @systemfsoftware/effect-schema-law.",
|
|
14
14
|
"keywords": [
|
|
@@ -39,24 +39,25 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@microsoft/api-extractor": "^7.58.7",
|
|
42
|
+
"@systemfsoftware/arethetypeswrong-cli": "^1.1.1",
|
|
42
43
|
"@types/node": "^24",
|
|
43
|
-
"effect": "
|
|
44
|
+
"effect": "4.0.0-rc.108",
|
|
45
|
+
"oxlint": "^1.77.0",
|
|
44
46
|
"rimraf": "^6.1.3",
|
|
45
|
-
"tsdown": "^0.22.
|
|
46
|
-
"vite": "^
|
|
47
|
-
"vitest": "^4",
|
|
48
|
-
"@systemfsoftware/
|
|
49
|
-
"@systemfsoftware/
|
|
50
|
-
"@systemfsoftware/
|
|
51
|
-
"@systemfsoftware/
|
|
52
|
-
"@systemfsoftware/
|
|
53
|
-
"@systemfsoftware/vitest-config": "^0.1.0"
|
|
47
|
+
"tsdown": "^0.22.14",
|
|
48
|
+
"vite": "^8",
|
|
49
|
+
"vitest": "^4.1.10",
|
|
50
|
+
"@systemfsoftware/effect-gherkin-spec": "^2.0.0",
|
|
51
|
+
"@systemfsoftware/vitest-config": "^0.1.0",
|
|
52
|
+
"@systemfsoftware/tsconfig": "^1.3.3",
|
|
53
|
+
"@systemfsoftware/effect-schema-law": "^0.8.0",
|
|
54
|
+
"@systemfsoftware/oxlint-config": "^0.1.0"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"effect": "^3.22.0",
|
|
57
|
+
"effect": "4.0.0-rc.108",
|
|
58
58
|
"vite": ">5.0.0",
|
|
59
|
-
"vitest": "*"
|
|
59
|
+
"vitest": "*",
|
|
60
|
+
"@systemfsoftware/effect-schema-law": "0.8.0"
|
|
60
61
|
},
|
|
61
62
|
"publishConfig": {
|
|
62
63
|
"provenance": true
|
|
@@ -69,7 +70,7 @@
|
|
|
69
70
|
"test:run": "vitest run",
|
|
70
71
|
"api:check": "api-extractor run",
|
|
71
72
|
"api:update": "api-extractor run --local",
|
|
72
|
-
"lint": "oxlint .
|
|
73
|
+
"lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
|
|
73
74
|
"attw": "attw --pack ."
|
|
74
75
|
}
|
|
75
76
|
}
|