arktype 3.0.0-beta.2 → 3.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -20
- package/out/_internal/regex/quantify.d.ts +17 -1
- package/out/_internal/schema/refinements/range.d.ts +2 -1
- package/out/_internal/schema/roots/domain.d.ts +1 -0
- package/out/_internal/schema/roots/root.d.ts +3 -1
- package/out/_internal/schema/roots/union.d.ts +8 -3
- package/out/_internal/schema/shared/compile.d.ts +2 -0
- package/out/_internal/schema/shared/declare.d.ts +9 -6
- package/out/_internal/schema/shared/errors.d.ts +3 -0
- package/out/_internal/schema/shared/issues.d.ts +5 -1
- package/out/_internal/schema/shared/issuesLean.d.ts +4 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +1 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +1 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +1 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +16 -3
- package/out/_internal/schema/shared/transform.d.ts +1 -0
- package/out/_internal/sets/constraint.d.ts +2 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +3 -1
- package/out/_internal/util/registry.d.ts +1 -1
- package/out/attributes.d.ts +12 -8
- package/out/chunk-2FVJ5JBN.js +161 -0
- package/out/{chunk-QBX4MEQR.js → chunk-3HZC67MT.js} +15 -15
- package/out/{chunk-5TN5JRP7.js → chunk-3KBOPH3J.js} +63 -41
- package/out/{chunk-GPNWBJL3.js → chunk-3WYMLH45.js} +17 -11
- package/out/{chunk-NIZDOWFU.js → chunk-46PLKNON.js} +2 -2
- package/out/{chunk-7JXN4WJX.js → chunk-4FTHWK63.js} +1 -1
- package/out/{chunk-EA2DNEDI.js → chunk-4HREHNIV.js} +12 -12
- package/out/{chunk-ZFB6DQWY.js → chunk-4J7H2ELX.js} +6 -11
- package/out/{chunk-7SVIUP6X.js → chunk-4MUH2MO4.js} +2 -2
- package/out/{chunk-J7CKAEDX.js → chunk-4NZCLVBD.js} +1 -1
- package/out/{chunk-RAM6G3F6.js → chunk-54U3D6OV.js} +26 -25
- package/out/{chunk-HA3POWOU.js → chunk-5FNHK7CC.js} +6 -5
- package/out/{chunk-KVQCLBJR.js → chunk-7SUZFAHZ.js} +241 -66
- package/out/{chunk-YMYPW3L5.js → chunk-AMNHRY72.js} +3 -3
- package/out/{chunk-UH6XKS3C.js → chunk-BQR65UPE.js} +30 -9
- package/out/{chunk-V4TZHFNK.js → chunk-BWKJV74G.js} +1 -1
- package/out/{chunk-7N3JEHA4.js → chunk-CXHXN7DF.js} +1 -1
- package/out/{chunk-FY4M7GE7.js → chunk-E4OQHHFS.js} +4 -4
- package/out/{chunk-CGWRW4JZ.js → chunk-ERGIJZFA.js} +4 -4
- package/out/{chunk-OA5Q2JLI.js → chunk-H44UG6HG.js} +8 -4
- package/out/{chunk-A7A6FDBS.js → chunk-I65VSWGS.js} +50 -44
- package/out/{chunk-C5JGK6GT.js → chunk-J2BFVWVY.js} +20 -3
- package/out/{chunk-W77ROLOT.js → chunk-JIILWIU4.js} +1 -1
- package/out/{chunk-5WRZ25AB.js → chunk-LMUBBBHJ.js} +4 -4
- package/out/{chunk-CQU7WIIR.js → chunk-P3HEEGB5.js} +6 -6
- package/out/{chunk-JZ4KBCMM.js → chunk-RKJNLXEQ.js} +21 -13
- package/out/{chunk-XMEK4I7J.js → chunk-TM22D5DL.js} +887 -266
- package/out/{chunk-PIFOURNM.js → chunk-TQYLOZRT.js} +11 -4
- package/out/{chunk-YN3XRJ7H.js → chunk-UJJGG4VQ.js} +1 -1
- package/out/{chunk-NIYAI7AF.js → chunk-US6BWOGJ.js} +3 -3
- package/out/{chunk-57LF5Y5P.js → chunk-W2XOI5DY.js} +1 -1
- package/out/{chunk-KDMHK4KP.js → chunk-XVLEFUSY.js} +2 -2
- package/out/{chunk-SGFGLENC.js → chunk-YPN67JMD.js} +3 -3
- package/out/cli.d.ts +5 -1
- package/out/cli.js +301 -49
- package/out/codecs.d.ts +4 -3
- package/out/codecs.js +18 -18
- package/out/config.js +8 -8
- package/out/declare.d.ts +2 -4
- package/out/errors.js +8 -8
- package/out/fn.d.ts +2 -2
- package/out/fromJsonSchema.d.ts +1 -1
- package/out/generic.d.ts +7 -4
- package/out/i18n.js +5 -5
- package/out/index.js +19 -19
- package/out/internal.js +32 -32
- package/out/island.js +18 -18
- package/out/islandDependency.js +33 -33
- package/out/jsonSchema/infer.d.ts +16 -6
- package/out/jsonSchema/validate.d.ts +16 -4
- package/out/keywords/functions.d.ts +4 -169
- package/out/keywords/keywords.d.ts +1 -1
- package/out/keywords/phrases.d.ts +3 -168
- package/out/keywords/ts.js +14 -14
- package/out/locales/de.js +6 -6
- package/out/locales/en.js +15 -15
- package/out/match.d.ts +12 -9
- package/out/mutatesInput.js +14 -14
- package/out/nary.d.ts +219 -193
- package/out/parser/definition.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +2 -0
- package/out/precompiled.js +11 -11
- package/out/runtime.d.ts +1 -1
- package/out/runtime.js +5 -5
- package/out/schema.js +11 -11
- package/out/schemaInternal.js +29 -17
- package/out/schemaRuntime.js +4 -4
- package/out/schemaRuntimeLean.js +60 -36
- package/out/schemaRuntimeNone.js +52 -31
- package/out/schemaRuntimeNoneLean.js +52 -31
- package/out/type.d.ts +3 -3
- package/out/util.js +14 -11
- package/out/variants/base.d.ts +9 -8
- package/out/variants/object.d.ts +14 -6
- package/package.json +4 -4
- package/skills/arktype/SKILL.md +17 -17
- package/skills/arktype/references/migrating.md +13 -13
- package/skills/arktype/references/precompile.md +4 -4
- package/out/chunk-CSVAPWDE.js +0 -83
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
registerBuilderCompiler,
|
|
3
3
|
registeredReference
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-I65VSWGS.js";
|
|
5
5
|
import {
|
|
6
6
|
TransformErrors,
|
|
7
7
|
addMorphErrs,
|
|
@@ -16,14 +16,15 @@ import {
|
|
|
16
16
|
transformResolution,
|
|
17
17
|
transformedInApply,
|
|
18
18
|
transformsValid
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-3KBOPH3J.js";
|
|
20
20
|
import {
|
|
21
21
|
CastableBase,
|
|
22
22
|
DynamicFunction,
|
|
23
23
|
hasDomain,
|
|
24
24
|
isDotAccessible,
|
|
25
|
-
serializePrimitive
|
|
26
|
-
|
|
25
|
+
serializePrimitive,
|
|
26
|
+
throwInternalError
|
|
27
|
+
} from "./chunk-3HZC67MT.js";
|
|
27
28
|
|
|
28
29
|
// ../schema/out/shared/compile.js
|
|
29
30
|
var writeErrorBuilder = function (context) {
|
|
@@ -207,6 +208,12 @@ var NodeCompiler = class extends CompiledFunction {
|
|
|
207
208
|
serialize(value) {
|
|
208
209
|
return hasDomain(value, "object") || typeof value === "symbol" ? this.ref(value) : serializePrimitive(value);
|
|
209
210
|
}
|
|
211
|
+
/** validates that a numeric literal interpolated into generated JS is a number */
|
|
212
|
+
num(n) {
|
|
213
|
+
if (typeof n !== "number")
|
|
214
|
+
throwInternalError(`Expected a numeric literal (was ${typeof n})`);
|
|
215
|
+
return `${n}`;
|
|
216
|
+
}
|
|
210
217
|
ref(value) {
|
|
211
218
|
if (!this.refs)
|
|
212
219
|
return registeredReference(value);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isDigitCode
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3HZC67MT.js";
|
|
4
4
|
|
|
5
5
|
// ../util/out/formats.js
|
|
6
6
|
var isHexCode = (code) => code - 48 >>> 0 < 10 || (code | 32) - 97 >>> 0 < 6;
|
|
7
|
-
var uuidMatcher = /^(?:[\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[1-8][\dA-Fa-f]{3}-[89ABab][\dA-Fa-f]{3}-[\dA-Fa-f]{12}|0{8}-(?:0{4}-){3}0{12}|
|
|
7
|
+
var uuidMatcher = /^(?:[\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[1-8][\dA-Fa-f]{3}-[89ABab][\dA-Fa-f]{3}-[\dA-Fa-f]{12}|0{8}-(?:0{4}-){3}0{12}|[Ff]{8}-(?:[Ff]{4}-){3}[Ff]{12})$/;
|
|
8
8
|
var uuidWrittenOut = (
|
|
9
9
|
// eslint-disable-next-line unicorn/better-regex
|
|
10
|
-
/^(?:[\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[1-8][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[89ABab][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]|0{8}-(?:0{4}-){3}0{12}|
|
|
10
|
+
/^(?:[\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[1-8][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[89ABab][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]-[\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f]|0{8}-(?:0{4}-){3}0{12}|[Ff]{8}-(?:[Ff]{4}-){3}[Ff]{12})$/
|
|
11
11
|
);
|
|
12
12
|
var isUuid = (s) => s.length === 36 && uuidWrittenOut.test(s);
|
|
13
13
|
var ipv4Matcher = /^((?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])\.){3}(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])$/;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3WYMLH45.js";
|
|
4
4
|
import {
|
|
5
5
|
parse
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TM22D5DL.js";
|
|
7
7
|
import {
|
|
8
8
|
RootModule
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7SUZFAHZ.js";
|
|
10
10
|
|
|
11
11
|
// out/fromJsonSchema.js
|
|
12
12
|
var fromJsonSchema = (schema) => (
|
package/out/cli.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export declare const bundledSkillPath: () => string;
|
|
|
19
19
|
export declare const detectPackageManager: (startDir: string) => PackageManager;
|
|
20
20
|
export declare const installDevCommand: (pm: PackageManager, pkg: string) => string;
|
|
21
21
|
export declare const detectMigrationSource: (manifest: PackageManifest | undefined) => MigrationSource | undefined;
|
|
22
|
-
export
|
|
22
|
+
export type InstallSkillOptions = {
|
|
23
|
+
allowOutside?: boolean;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const installBundledSkill: (projectRoot: string, targetDir?: string, opts?: InstallSkillOptions) => string;
|
|
23
27
|
export declare const runCli: (argv: string[], ctx?: CliContext) => number;
|
|
24
28
|
export {};
|
package/out/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
|
-
import {
|
|
3
|
+
import { constants, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
-
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
8
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
@@ -15,7 +15,7 @@ const readManifest = (dir) => {
|
|
|
15
15
|
if (!existsSync(path))
|
|
16
16
|
return undefined;
|
|
17
17
|
try {
|
|
18
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
18
|
+
return JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
21
|
return undefined;
|
|
@@ -111,35 +111,188 @@ const defaultSkillTarget = (projectRoot) => {
|
|
|
111
111
|
return join(projectRoot, ".claude", "skills", "arktype");
|
|
112
112
|
return join(projectRoot, ".agents", "skills", "arktype");
|
|
113
113
|
};
|
|
114
|
-
|
|
114
|
+
const lstatIfExists = (path) => {
|
|
115
|
+
try {
|
|
116
|
+
return lstatSync(path);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
if (e.code === "ENOENT")
|
|
120
|
+
return undefined;
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const isWithinDir = (root, target) => {
|
|
125
|
+
const rel = relative(root, target);
|
|
126
|
+
return (rel === "" ||
|
|
127
|
+
(rel !== ".." &&
|
|
128
|
+
!rel.startsWith(`..${sep}`) &&
|
|
129
|
+
!rel.startsWith("../") &&
|
|
130
|
+
!isAbsolute(rel)));
|
|
131
|
+
};
|
|
132
|
+
const resolveSafeSkillDir = (projectRoot, dest, explicitDir, allowOutside) => {
|
|
133
|
+
const realRoot = realpathSync(projectRoot);
|
|
134
|
+
// walk up via lstat so dangling symlinks are detected instead of skipped
|
|
135
|
+
let cur = dest;
|
|
136
|
+
let stat = lstatIfExists(cur);
|
|
137
|
+
while (!stat) {
|
|
138
|
+
const parent = dirname(cur);
|
|
139
|
+
if (parent === cur)
|
|
140
|
+
break;
|
|
141
|
+
cur = parent;
|
|
142
|
+
stat = lstatIfExists(cur);
|
|
143
|
+
}
|
|
144
|
+
let resolvedAncestor;
|
|
145
|
+
if (stat?.isSymbolicLink()) {
|
|
146
|
+
try {
|
|
147
|
+
resolvedAncestor = realpathSync(cur);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw new Error(`Refusing to install skill through dangling symlink ${cur}`);
|
|
151
|
+
}
|
|
152
|
+
if (!statSync(resolvedAncestor).isDirectory()) {
|
|
153
|
+
throw new Error(`Cannot install skill to ${dest}: ${cur} resolves to ${resolvedAncestor}, which is not a directory`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (stat && !stat.isDirectory()) {
|
|
157
|
+
throw new Error(`Cannot install skill to ${dest}: ${cur} is not a directory`);
|
|
158
|
+
}
|
|
159
|
+
else
|
|
160
|
+
resolvedAncestor = realpathSync(cur);
|
|
161
|
+
const resolvedDest = join(resolvedAncestor, relative(cur, dest));
|
|
162
|
+
if (!explicitDir && !allowOutside && !isWithinDir(realRoot, resolvedDest)) {
|
|
163
|
+
throw new Error(`Refusing to install skill to ${dest}: resolves to ${resolvedDest}, outside project root ${realRoot} (pass --allow-outside to allow)`);
|
|
164
|
+
}
|
|
165
|
+
return resolvedDest;
|
|
166
|
+
};
|
|
167
|
+
const validateSkillTree = (srcDir, destDir) => {
|
|
168
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
169
|
+
const srcPath = join(srcDir, entry.name);
|
|
170
|
+
const destPath = join(destDir, entry.name);
|
|
171
|
+
const destStat = lstatIfExists(destPath);
|
|
172
|
+
if (destStat?.isSymbolicLink())
|
|
173
|
+
throw new Error(`Refusing to write through symlink at ${destPath}`);
|
|
174
|
+
if (entry.isDirectory()) {
|
|
175
|
+
if (destStat && !destStat.isDirectory()) {
|
|
176
|
+
throw new Error(`Cannot create directory at ${destPath}: path exists and is not a directory`);
|
|
177
|
+
}
|
|
178
|
+
validateSkillTree(srcPath, destPath);
|
|
179
|
+
}
|
|
180
|
+
else if (entry.isFile() && destStat && !destStat.isFile()) {
|
|
181
|
+
throw new Error(`Cannot write file at ${destPath}: path exists and is not a regular file`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const copySkillTree = (srcDir, destDir) => {
|
|
186
|
+
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
187
|
+
const srcPath = join(srcDir, entry.name);
|
|
188
|
+
const destPath = join(destDir, entry.name);
|
|
189
|
+
const destStat = lstatIfExists(destPath);
|
|
190
|
+
if (destStat?.isSymbolicLink())
|
|
191
|
+
throw new Error(`Refusing to write through symlink at ${destPath}`);
|
|
192
|
+
if (entry.isDirectory()) {
|
|
193
|
+
if (destStat && !destStat.isDirectory()) {
|
|
194
|
+
throw new Error(`Cannot create directory at ${destPath}: path exists and is not a directory`);
|
|
195
|
+
}
|
|
196
|
+
if (!destStat)
|
|
197
|
+
mkdirSync(destPath);
|
|
198
|
+
copySkillTree(srcPath, destPath);
|
|
199
|
+
}
|
|
200
|
+
else if (entry.isFile()) {
|
|
201
|
+
if (destStat) {
|
|
202
|
+
if (!destStat.isFile()) {
|
|
203
|
+
throw new Error(`Cannot write file at ${destPath}: path exists and is not a regular file`);
|
|
204
|
+
}
|
|
205
|
+
unlinkSync(destPath);
|
|
206
|
+
}
|
|
207
|
+
copyFileSync(srcPath, destPath, constants.COPYFILE_EXCL);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const resolveExplicitSkillTarget = (cwd, targetDir) => {
|
|
212
|
+
const resolved = resolve(cwd, targetDir);
|
|
213
|
+
return basename(resolved) === "arktype" ? resolved : join(resolved, "arktype");
|
|
214
|
+
};
|
|
215
|
+
const prepareSkillInstall = (projectRoot, targetDir, opts) => {
|
|
115
216
|
const src = bundledSkillPath();
|
|
116
|
-
const dest = targetDir ?
|
|
117
|
-
|
|
217
|
+
const dest = targetDir !== undefined ?
|
|
218
|
+
resolveExplicitSkillTarget(opts?.cwd ?? process.cwd(), targetDir)
|
|
118
219
|
: defaultSkillTarget(projectRoot);
|
|
119
|
-
|
|
120
|
-
|
|
220
|
+
const resolvedDest = resolveSafeSkillDir(projectRoot, dest, targetDir !== undefined, Boolean(opts?.allowOutside));
|
|
221
|
+
const realSrc = realpathSync(src);
|
|
222
|
+
if (isWithinDir(realSrc, resolvedDest) ||
|
|
223
|
+
isWithinDir(resolvedDest, realSrc)) {
|
|
224
|
+
throw new Error(`Refusing to install skill to ${dest}: destination overlaps bundled skill source ${realSrc}`);
|
|
225
|
+
}
|
|
226
|
+
validateSkillTree(realSrc, resolvedDest);
|
|
227
|
+
return { dest, realSrc, resolvedDest };
|
|
228
|
+
};
|
|
229
|
+
const applySkillInstall = ({ dest, realSrc, resolvedDest }) => {
|
|
230
|
+
mkdirSync(resolvedDest, { recursive: true });
|
|
231
|
+
copySkillTree(realSrc, resolvedDest);
|
|
121
232
|
return dest;
|
|
122
233
|
};
|
|
123
|
-
const
|
|
234
|
+
export const installBundledSkill = (projectRoot, targetDir, opts) => applySkillInstall(prepareSkillInstall(projectRoot, targetDir, opts));
|
|
235
|
+
const findAotManifest = (startDir) => {
|
|
236
|
+
for (let dir = startDir;; dir = dirname(dir)) {
|
|
237
|
+
const manifest = readManifest(dir);
|
|
238
|
+
if (manifest?.name === "@ark/aot")
|
|
239
|
+
return { pkgDir: dir, manifest };
|
|
240
|
+
const parent = dirname(dir);
|
|
241
|
+
if (parent === dir)
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const findAotInNodeModules = (cwd) => {
|
|
246
|
+
for (let dir = resolve(cwd);; dir = dirname(dir)) {
|
|
247
|
+
const pkgDir = join(dir, "node_modules", "@ark", "aot");
|
|
248
|
+
const manifest = readManifest(pkgDir);
|
|
249
|
+
if (manifest?.name === "@ark/aot")
|
|
250
|
+
return { pkgDir, manifest };
|
|
251
|
+
const parent = dirname(dir);
|
|
252
|
+
if (parent === dir)
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const findAotViaRequire = (cwd) => {
|
|
257
|
+
const req = createRequire(join(resolve(cwd), "package.json"));
|
|
258
|
+
try {
|
|
259
|
+
const found = findAotManifest(dirname(req.resolve("@ark/aot")));
|
|
260
|
+
if (found)
|
|
261
|
+
return found;
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// fall back to resolving package.json directly when root entry isn't available
|
|
265
|
+
}
|
|
124
266
|
try {
|
|
125
|
-
const req = createRequire(join(resolve(cwd), "package.json"));
|
|
126
267
|
const pkgPath = req.resolve("@ark/aot/package.json");
|
|
127
268
|
const pkgDir = dirname(pkgPath);
|
|
128
|
-
const manifest =
|
|
129
|
-
|
|
130
|
-
manifest
|
|
131
|
-
: manifest.bin?.["arktype-precompile"];
|
|
132
|
-
if (bin && existsSync(join(pkgDir, bin)))
|
|
133
|
-
return join(pkgDir, bin);
|
|
134
|
-
const srcCli = join(pkgDir, "cli.ts");
|
|
135
|
-
if (existsSync(srcCli))
|
|
136
|
-
return srcCli;
|
|
269
|
+
const manifest = readManifest(pkgDir);
|
|
270
|
+
if (manifest)
|
|
271
|
+
return { pkgDir, manifest };
|
|
137
272
|
}
|
|
138
273
|
catch {
|
|
139
274
|
return undefined;
|
|
140
275
|
}
|
|
141
276
|
return undefined;
|
|
142
277
|
};
|
|
278
|
+
const resolveAotCli = (cwd) => {
|
|
279
|
+
// Yarn PnP has no node_modules on disk; resolve through Node's module hooks
|
|
280
|
+
// (avoiding NODE_PATH leaks from pnpm bin shims in non-PnP environments)
|
|
281
|
+
const found = findAotInNodeModules(cwd) ??
|
|
282
|
+
("pnp" in process.versions ? findAotViaRequire(cwd) : undefined);
|
|
283
|
+
if (!found)
|
|
284
|
+
return undefined;
|
|
285
|
+
const { pkgDir, manifest } = found;
|
|
286
|
+
const bin = typeof manifest.bin === "string" ?
|
|
287
|
+
manifest.bin
|
|
288
|
+
: manifest.bin?.["arktype-precompile"];
|
|
289
|
+
if (bin && existsSync(join(pkgDir, bin)))
|
|
290
|
+
return join(pkgDir, bin);
|
|
291
|
+
const srcCli = join(pkgDir, "cli.ts");
|
|
292
|
+
if (existsSync(srcCli))
|
|
293
|
+
return srcCli;
|
|
294
|
+
return undefined;
|
|
295
|
+
};
|
|
143
296
|
const aotSubcommands = new Set(["check", "emit", "declare"]);
|
|
144
297
|
const runAot = (subcommand, rest, cwd, stderr) => {
|
|
145
298
|
const cliPath = resolveAotCli(cwd);
|
|
@@ -154,6 +307,9 @@ const runAot = (subcommand, rest, cwd, stderr) => {
|
|
|
154
307
|
const result = spawnSync(process.execPath, [cliPath, `--${subcommand}`, ...rest], { cwd, stdio: "inherit" });
|
|
155
308
|
return result.status ?? 1;
|
|
156
309
|
};
|
|
310
|
+
const hasArkPrecompileSetting = (manifest) => typeof manifest?.ark === "object" &&
|
|
311
|
+
manifest.ark !== null &&
|
|
312
|
+
Object.prototype.hasOwnProperty.call(manifest.ark, "precompile");
|
|
157
313
|
const runInit = (args, cwd, stdout, stderr) => {
|
|
158
314
|
let parsed;
|
|
159
315
|
try {
|
|
@@ -162,6 +318,7 @@ const runInit = (args, cwd, stdout, stderr) => {
|
|
|
162
318
|
options: {
|
|
163
319
|
force: { type: "boolean", default: false },
|
|
164
320
|
"no-skill": { type: "boolean", default: false },
|
|
321
|
+
"allow-outside": { type: "boolean", default: false },
|
|
165
322
|
help: { type: "boolean", short: "h", default: false }
|
|
166
323
|
},
|
|
167
324
|
allowPositionals: false
|
|
@@ -172,26 +329,94 @@ const runInit = (args, cwd, stdout, stderr) => {
|
|
|
172
329
|
return 1;
|
|
173
330
|
}
|
|
174
331
|
if (parsed.values.help) {
|
|
175
|
-
stdout("Usage: ark init [--force] [--no-skill]\n\nDetects your bundler/test runner, writes ark.json, and installs the bundled ArkType skill.\n");
|
|
332
|
+
stdout("Usage: ark init [--force] [--no-skill] [--allow-outside]\n\nDetects your bundler/test runner, writes ark.json, and installs the bundled ArkType skill.\n");
|
|
176
333
|
return 0;
|
|
177
334
|
}
|
|
178
335
|
const projectRoot = findProjectRoot(cwd);
|
|
179
336
|
const manifest = readManifest(projectRoot);
|
|
180
337
|
const tools = detectedToolsOf(manifest, projectRoot);
|
|
181
338
|
const settingsPath = join(projectRoot, "ark.json");
|
|
182
|
-
|
|
339
|
+
const settingsContent = `${JSON.stringify({ precompile: {} }, null, "\t")}\n`;
|
|
340
|
+
const hasSettings = hasArkPrecompileSetting(manifest);
|
|
341
|
+
let existingSettings;
|
|
342
|
+
if (!hasSettings && parsed.values.force) {
|
|
343
|
+
existingSettings = lstatIfExists(settingsPath);
|
|
344
|
+
if (existingSettings?.isSymbolicLink()) {
|
|
345
|
+
stderr(`Refusing to overwrite symlink at ${settingsPath}.\n`);
|
|
346
|
+
return 1;
|
|
347
|
+
}
|
|
348
|
+
if (existingSettings && !existingSettings.isFile()) {
|
|
349
|
+
stderr(`Cannot write ${settingsPath}: path is not a regular file.\n`);
|
|
350
|
+
return 1;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
let preparedSkill;
|
|
354
|
+
if (!parsed.values["no-skill"]) {
|
|
355
|
+
try {
|
|
356
|
+
preparedSkill = prepareSkillInstall(projectRoot, undefined, {
|
|
357
|
+
allowOutside: Boolean(parsed.values["allow-outside"])
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
stderr(`${e.message}\n`);
|
|
362
|
+
return 1;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (hasSettings) {
|
|
183
366
|
stdout(`Found existing "ark" settings in ${join(projectRoot, "package.json")}; leaving ark.json untouched.\n`);
|
|
184
367
|
}
|
|
185
|
-
else if (
|
|
186
|
-
|
|
368
|
+
else if (parsed.values.force) {
|
|
369
|
+
try {
|
|
370
|
+
if (existingSettings)
|
|
371
|
+
unlinkSync(settingsPath);
|
|
372
|
+
writeFileSync(settingsPath, settingsContent, { flag: "wx" });
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
stderr(`Failed to write ${settingsPath}: ${e.message}\n`);
|
|
376
|
+
return 1;
|
|
377
|
+
}
|
|
378
|
+
stdout(`Created ${settingsPath}\n`);
|
|
187
379
|
}
|
|
188
380
|
else {
|
|
189
|
-
|
|
190
|
-
|
|
381
|
+
// lstat before writing: on Windows, the "wx" flag follows a dangling
|
|
382
|
+
// symlink and creates its target (possibly outside the project) instead
|
|
383
|
+
// of failing with EEXIST as POSIX does. "wx" stays as the defense
|
|
384
|
+
// against a file appearing between the lstat and the write.
|
|
385
|
+
const reportExisting = (stat) => {
|
|
386
|
+
const detail = stat?.isSymbolicLink() ? "symlink"
|
|
387
|
+
: stat?.isDirectory() ? "directory"
|
|
388
|
+
: stat && !stat.isFile() ? "not a regular file"
|
|
389
|
+
: "pass --force to overwrite";
|
|
390
|
+
stdout(`ark.json already exists at ${settingsPath} (${detail}).\n`);
|
|
391
|
+
};
|
|
392
|
+
const stat = lstatIfExists(settingsPath);
|
|
393
|
+
if (stat)
|
|
394
|
+
reportExisting(stat);
|
|
395
|
+
else {
|
|
396
|
+
try {
|
|
397
|
+
writeFileSync(settingsPath, settingsContent, { flag: "wx" });
|
|
398
|
+
stdout(`Created ${settingsPath}\n`);
|
|
399
|
+
}
|
|
400
|
+
catch (e) {
|
|
401
|
+
const code = e.code;
|
|
402
|
+
if (code === "EEXIST" || code === "EISDIR")
|
|
403
|
+
reportExisting(lstatIfExists(settingsPath));
|
|
404
|
+
else {
|
|
405
|
+
stderr(`Failed to write ${settingsPath}: ${e.message}\n`);
|
|
406
|
+
return 1;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
191
410
|
}
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
411
|
+
if (preparedSkill) {
|
|
412
|
+
try {
|
|
413
|
+
const dest = applySkillInstall(preparedSkill);
|
|
414
|
+
stdout(`Installed ArkType skill to ${dest}\n`);
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
stderr(`${e.message}\n`);
|
|
418
|
+
return 1;
|
|
419
|
+
}
|
|
195
420
|
}
|
|
196
421
|
if (tools.length)
|
|
197
422
|
stdout(`Detected tools: ${tools.join(", ")}\n`);
|
|
@@ -205,10 +430,14 @@ const runInit = (args, cwd, stdout, stderr) => {
|
|
|
205
430
|
return 0;
|
|
206
431
|
};
|
|
207
432
|
const buildMigrationPrompt = (source, skillDir) => {
|
|
208
|
-
const fromLabel = source === "v2" ? "ArkType 2.x"
|
|
209
|
-
: source ? source
|
|
210
|
-
: "the existing validation library";
|
|
211
433
|
const skillFile = join(skillDir, "SKILL.md");
|
|
434
|
+
if (source === "v2") {
|
|
435
|
+
return [
|
|
436
|
+
"Migrate this codebase from ArkType 2.x to ArkType 3.",
|
|
437
|
+
`Read the "Upgrading from ArkType 2" section of ${skillFile} and https://arktype.io/docs/upgrading.md first, then upgrade schemas, types, and error handling incrementally while keeping typecheck and tests green.`
|
|
438
|
+
].join("\n");
|
|
439
|
+
}
|
|
440
|
+
const fromLabel = source ?? "the existing validation library";
|
|
212
441
|
const migratingFile = join(skillDir, "references", "migrating.md");
|
|
213
442
|
return [
|
|
214
443
|
`Migrate this codebase from ${fromLabel} to ArkType 3.`,
|
|
@@ -233,6 +462,7 @@ const runMigrate = (args, cwd, stdout, stderr) => {
|
|
|
233
462
|
run: { type: "boolean", default: false },
|
|
234
463
|
agent: { type: "string" },
|
|
235
464
|
"no-skill": { type: "boolean", default: false },
|
|
465
|
+
"allow-outside": { type: "boolean", default: false },
|
|
236
466
|
help: { type: "boolean", short: "h", default: false }
|
|
237
467
|
},
|
|
238
468
|
allowPositionals: true
|
|
@@ -243,7 +473,7 @@ const runMigrate = (args, cwd, stdout, stderr) => {
|
|
|
243
473
|
return 1;
|
|
244
474
|
}
|
|
245
475
|
if (parsed.values.help) {
|
|
246
|
-
stdout(`Usage: ark migrate [${migrationSources.join("|")}] [--run] [--agent claude|codex] [--no-skill]\n\nDetects your existing validator, installs the bundled ArkType skill, and prints (or launches) a migration prompt.\n`);
|
|
476
|
+
stdout(`Usage: ark migrate [${migrationSources.join("|")}] [--run] [--agent claude|codex] [--no-skill] [--allow-outside]\n\nDetects your existing validator, installs the bundled ArkType skill, and prints (or launches) a migration prompt.\n`);
|
|
247
477
|
return 0;
|
|
248
478
|
}
|
|
249
479
|
const projectRoot = findProjectRoot(cwd);
|
|
@@ -259,11 +489,21 @@ const runMigrate = (args, cwd, stdout, stderr) => {
|
|
|
259
489
|
}
|
|
260
490
|
else
|
|
261
491
|
source = detectMigrationSource(manifest);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
492
|
+
let skillDir;
|
|
493
|
+
if (parsed.values["no-skill"])
|
|
494
|
+
skillDir = bundledSkillPath();
|
|
495
|
+
else {
|
|
496
|
+
try {
|
|
497
|
+
skillDir = installBundledSkill(projectRoot, undefined, {
|
|
498
|
+
allowOutside: Boolean(parsed.values["allow-outside"])
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
catch (e) {
|
|
502
|
+
stderr(`${e.message}\n`);
|
|
503
|
+
return 1;
|
|
504
|
+
}
|
|
266
505
|
stdout(`Installed ArkType skill to ${skillDir}\n`);
|
|
506
|
+
}
|
|
267
507
|
const prompt = buildMigrationPrompt(source, skillDir);
|
|
268
508
|
if (parsed.values.run || parsed.values.agent) {
|
|
269
509
|
const requested = typeof parsed.values.agent === "string" ? parsed.values.agent : undefined;
|
|
@@ -290,6 +530,7 @@ const runSkill = (args, cwd, stdout, stderr) => {
|
|
|
290
530
|
args,
|
|
291
531
|
options: {
|
|
292
532
|
dir: { type: "string" },
|
|
533
|
+
"allow-outside": { type: "boolean", default: false },
|
|
293
534
|
help: { type: "boolean", short: "h", default: false }
|
|
294
535
|
},
|
|
295
536
|
allowPositionals: true
|
|
@@ -300,7 +541,7 @@ const runSkill = (args, cwd, stdout, stderr) => {
|
|
|
300
541
|
return 1;
|
|
301
542
|
}
|
|
302
543
|
if (parsed.values.help) {
|
|
303
|
-
stdout("Usage: ark skill [path|install] [--dir <path>]\n\nPrints the path to the bundled ArkType skill or installs it into your project.\n");
|
|
544
|
+
stdout("Usage: ark skill [path|install] [--dir <path>] [--allow-outside]\n\nPrints the path to the bundled ArkType skill or installs it into your project. With --dir <path> (resolved from cwd), installs to <path>/arktype unless <path> already ends in arktype.\n");
|
|
304
545
|
return 0;
|
|
305
546
|
}
|
|
306
547
|
const action = parsed.positionals[0] ?? "path";
|
|
@@ -311,9 +552,18 @@ const runSkill = (args, cwd, stdout, stderr) => {
|
|
|
311
552
|
if (action === "install") {
|
|
312
553
|
const projectRoot = findProjectRoot(cwd);
|
|
313
554
|
const target = typeof parsed.values.dir === "string" ? parsed.values.dir : undefined;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
555
|
+
try {
|
|
556
|
+
const dest = installBundledSkill(projectRoot, target, {
|
|
557
|
+
allowOutside: Boolean(parsed.values["allow-outside"]),
|
|
558
|
+
cwd
|
|
559
|
+
});
|
|
560
|
+
stdout(`Installed ArkType skill to ${dest}\n`);
|
|
561
|
+
return 0;
|
|
562
|
+
}
|
|
563
|
+
catch (e) {
|
|
564
|
+
stderr(`${e.message}\n`);
|
|
565
|
+
return 1;
|
|
566
|
+
}
|
|
317
567
|
}
|
|
318
568
|
stderr(`Unknown skill action "${action}". Expected "path" or "install".\n`);
|
|
319
569
|
return 1;
|
|
@@ -321,17 +571,19 @@ const runSkill = (args, cwd, stdout, stderr) => {
|
|
|
321
571
|
const usage = `Usage: ark <command> [options]
|
|
322
572
|
|
|
323
573
|
Commands:
|
|
324
|
-
aot <check|emit|declare> [...flags]
|
|
325
|
-
check [...flags]
|
|
326
|
-
emit [...flags]
|
|
327
|
-
declare [...flags]
|
|
328
|
-
init [--force] [--no-skill]
|
|
329
|
-
migrate [source] [--run]
|
|
330
|
-
|
|
574
|
+
aot <check|emit|declare> [...flags] Run @ark/aot precompiler commands
|
|
575
|
+
check [...flags] Shortcut for \`ark aot check\`
|
|
576
|
+
emit [...flags] Shortcut for \`ark aot emit\`
|
|
577
|
+
declare [...flags] Shortcut for \`ark aot declare\`
|
|
578
|
+
init [--force] [--no-skill] [--allow-outside] Detect setup, write ark.json, install skill
|
|
579
|
+
migrate [source] [--run] [--agent <cli>] Generate or launch a migration prompt
|
|
580
|
+
[--no-skill] [--allow-outside]
|
|
581
|
+
skill [path|install] [--dir <path>] Print path to or install the bundled skill
|
|
582
|
+
[--allow-outside]
|
|
331
583
|
|
|
332
584
|
Options:
|
|
333
|
-
-h, --help
|
|
334
|
-
-v, --version
|
|
585
|
+
-h, --help Show help
|
|
586
|
+
-v, --version Show version
|
|
335
587
|
`;
|
|
336
588
|
export const runCli = (argv, ctx = {}) => {
|
|
337
589
|
const cwd = ctx.cwd ?? process.cwd();
|
package/out/codecs.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ArkError, ArkErrors, Morph } from "./_internal/schema/index.js";
|
|
|
2
2
|
import type { noInfer } from "./_internal/util/index.js";
|
|
3
3
|
import type { distill, inferPipe, Out } from "./attributes.ts";
|
|
4
4
|
import { type } from "./keywords/keywords.ts";
|
|
5
|
+
import type { inferDefinition } from "./parser/definition.ts";
|
|
5
6
|
import type { instantiateType } from "./variants/instantiate.ts";
|
|
6
7
|
/**
|
|
7
8
|
* Create a {@link Type} from a morph and its inverse
|
|
@@ -15,7 +16,7 @@ import type { instantiateType } from "./variants/instantiate.ts";
|
|
|
15
16
|
* // 0
|
|
16
17
|
* const ms = EpochMs.encode(date)
|
|
17
18
|
*/
|
|
18
|
-
export declare const codec: <const i, const o, r = instantiateType<inferPipe<(In: distill.In<
|
|
19
|
-
decode: Morph<distill.Out<
|
|
20
|
-
encode: Morph<distill.In<
|
|
19
|
+
export declare const codec: <const i, const o, r = instantiateType<inferPipe<(In: distill.In<inferDefinition<i>>) => Out<distill.In<inferDefinition<o>>>, inferDefinition<o>>, {}>>(i: type.validate<i>, o: type.validate<o>, { decode, encode }: noInfer<{
|
|
20
|
+
decode: Morph<distill.Out<inferDefinition<i>>, distill.In<inferDefinition<o>> | ArkError | ArkErrors>;
|
|
21
|
+
encode: Morph<distill.In<inferDefinition<o>>, distill.Out<inferDefinition<i>> | ArkError | ArkErrors>;
|
|
21
22
|
}, i | o>) => r extends infer _ ? _ : never;
|
package/out/codecs.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export { codec } from "./chunk-
|
|
2
|
-
import "./chunk-
|
|
3
|
-
import "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
1
|
+
export { codec } from "./chunk-E4OQHHFS.js";
|
|
2
|
+
import "./chunk-2FVJ5JBN.js";
|
|
3
|
+
import "./chunk-3WYMLH45.js";
|
|
4
|
+
import "./chunk-TM22D5DL.js";
|
|
5
|
+
import "./chunk-4FTHWK63.js";
|
|
6
6
|
import "./chunk-BDJVONP7.js";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-4MUH2MO4.js";
|
|
8
|
+
import "./chunk-4HREHNIV.js";
|
|
9
|
+
import "./chunk-7SUZFAHZ.js";
|
|
10
10
|
import "./chunk-CWSF57VM.js";
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-UJJGG4VQ.js";
|
|
12
|
+
import "./chunk-US6BWOGJ.js";
|
|
13
|
+
import "./chunk-P3HEEGB5.js";
|
|
14
|
+
import "./chunk-W2XOI5DY.js";
|
|
15
15
|
import "./chunk-TACLEIDM.js";
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-ERGIJZFA.js";
|
|
17
|
+
import "./chunk-TQYLOZRT.js";
|
|
18
|
+
import "./chunk-I65VSWGS.js";
|
|
19
|
+
import "./chunk-3KBOPH3J.js";
|
|
20
|
+
import "./chunk-J2BFVWVY.js";
|
|
21
21
|
import "./chunk-3SH2BQ4T.js";
|
|
22
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-3HZC67MT.js";
|
|
23
23
|
import "./chunk-I2KLQ2HA.js";
|