typenative 0.4.1 → 0.6.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/.github/workflows/ci.yml +2 -2
- package/.github/workflows/npm-publish-github-packages.yml +2 -2
- package/CHANGELOG.md +442 -1
- package/CONTRIBUTION.md +2 -1
- package/README.md +73 -25
- package/bin/cli.js +2 -0
- package/bin/index.js +75 -5
- package/bin/main.js +2 -0
- package/bin/node/assert.js +2 -2
- package/bin/node/async_hooks.js +1 -1
- package/bin/node/buffer.js +16 -5
- package/bin/node/child_process.js +7 -7
- package/bin/node/cluster.js +3 -3
- package/bin/node/core.js +41 -0
- package/bin/node/crypto_keys.js +21 -21
- package/bin/node/dgram.js +1 -1
- package/bin/node/diagnostics_channel.js +3 -3
- package/bin/node/dns.js +2 -2
- package/bin/node/events.js +18 -13
- package/bin/node/fetch.js +2 -2
- package/bin/node/fs.js +3 -3
- package/bin/node/fs_watch.js +5 -5
- package/bin/node/http.js +3 -3
- package/bin/node/http2.js +3 -3
- package/bin/node/net.js +8 -8
- package/bin/node/path.js +17 -3
- package/bin/node/process.js +47 -11
- package/bin/node/punycode.js +2 -2
- package/bin/node/readline.js +1 -1
- package/bin/node/registry.js +4 -1
- package/bin/node/sqlite.js +6 -6
- package/bin/node/stream.js +81 -15
- package/bin/node/stream_web.js +10 -10
- package/bin/node/system_extra.js +3 -3
- package/bin/node/test.js +674 -366
- package/bin/node/test_coverage.js +187 -0
- package/bin/node/test_report.js +1392 -0
- package/bin/node/test_run.js +575 -0
- package/bin/node/timers.js +8 -6
- package/bin/node/tls.js +5 -5
- package/bin/node/url.js +1 -1
- package/bin/node/util.js +31 -7
- package/bin/node/util_extra.js +7 -7
- package/bin/node/webview.js +654 -0
- package/bin/node/worker_threads.js +1 -1
- package/bin/node/zlib.js +3 -3
- package/bin/parse-node.js +6 -2
- package/bin/regex_vm.js +2057 -0
- package/bin/transpiler.js +32872 -11265
- package/bin/typecheck-node.js +2 -1
- package/bin/version.js +1 -1
- package/conformance.md +515 -345
- package/examples/README.md +71 -11
- package/examples/angular-templates/README.md +139 -0
- package/examples/angular-templates/bench.mjs +173 -0
- package/examples/angular-templates/dom-type-globals.d.ts +21 -0
- package/examples/angular-templates/dom-type-stubs.ts +21 -0
- package/examples/angular-templates/main.ts +135 -0
- package/examples/angular-templates/parity.mjs +157 -0
- package/examples/angular-templates/run-node.mjs +69 -0
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
- package/examples/desktop-notes/README.md +106 -0
- package/examples/desktop-notes/bench.mjs +125 -0
- package/examples/desktop-notes/main.ts +131 -0
- package/examples/desktop-notes/package-lock.json +726 -0
- package/examples/desktop-notes/package.json +9 -0
- package/examples/desktop-notes/ui.ts +176 -0
- package/examples/dupe-finder/README.md +78 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/fibonacci/README.md +7 -7
- package/examples/hello-world/README.md +6 -6
- package/examples/json-server/README.md +19 -18
- package/examples/mandelbrot-png/README.md +63 -0
- package/examples/mandelbrot-png/bench.mjs +95 -0
- package/examples/mandelbrot-png/main.ts +98 -0
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +160 -0
- package/examples/marked-cli/bench.mjs +178 -0
- package/examples/marked-cli/main.ts +292 -0
- package/examples/marked-cli/parity.mjs +185 -0
- package/examples/marked-cli/vendor/marked/LICENSE +44 -0
- package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
- package/examples/openai-chat/README.md +148 -0
- package/examples/openai-chat/bench.mjs +175 -0
- package/examples/openai-chat/main.ts +488 -0
- package/examples/react-compiler/README.md +170 -0
- package/examples/react-compiler/bench.mjs +181 -0
- package/examples/react-compiler/main.ts +158 -0
- package/examples/react-compiler/parity.mjs +362 -0
- package/examples/react-compiler/run-node.mjs +88 -0
- package/examples/react-compiler/vendor/babel/LICENSE +22 -0
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
- package/examples/react-compiler/vendor/charcodes/package.json +25 -0
- package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
- package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
- package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
- package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
- package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
- package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
- package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
- package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
- package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
- package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
- package/examples/react-compiler/vendor/zod/LICENSE +21 -0
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
- package/examples/react-compiler/vendor.mjs +688 -0
- package/examples/todo-cli/README.md +69 -0
- package/examples/todo-cli/bench.mjs +89 -0
- package/examples/todo-cli/main.ts +92 -0
- package/examples/yaml-cli/README.md +146 -0
- package/examples/yaml-cli/bench.mjs +265 -0
- package/examples/yaml-cli/main.ts +29 -0
- package/examples/yaml-cli/parity.mjs +156 -0
- package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
- package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
- package/govendor/github.com/jchv/go-webview2/README.md +21 -0
- package/govendor/github.com/jchv/go-webview2/common.go +84 -0
- package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
- package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
- package/govendor/github.com/jchv/go-winloader/README.md +124 -0
- package/govendor/github.com/jchv/go-winloader/common.go +11 -0
- package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
- package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +8 -5
- package/performance/README.md +195 -0
- package/performance/any-dynamic.ts +21 -0
- package/performance/any-record-view.ts +20 -0
- package/performance/arr-hof.ts +21 -0
- package/performance/arr-push-index.ts +15 -0
- package/performance/arr-sort.ts +21 -0
- package/performance/async-await.ts +24 -0
- package/performance/class-dispatch.ts +52 -0
- package/performance/events-emit.ts +27 -0
- package/performance/exc-throw-rare.ts +25 -0
- package/performance/exc-try-catch.ts +26 -0
- package/performance/fn-closures.ts +29 -0
- package/performance/fn-recursion-tree.ts +31 -0
- package/performance/gen-for-of.ts +46 -0
- package/performance/json-roundtrip.ts +27 -0
- package/performance/map-delete.ts +24 -0
- package/performance/map-string-keys.ts +22 -0
- package/performance/num-arith-loop.ts +14 -0
- package/performance/num-bitwise.ts +21 -0
- package/performance/num-mod-int.ts +16 -0
- package/performance/num-to-string.ts +16 -0
- package/performance/obj-alloc.ts +32 -0
- package/performance/regex-exec.ts +29 -0
- package/performance/regex-site.ts +28 -0
- package/performance/set-ops.ts +20 -0
- package/performance/str-char-scan.ts +35 -0
- package/performance/str-concat-plus.ts +18 -0
- package/performance/str-concat.ts +24 -0
- package/performance/str-short-scan.ts +26 -0
- package/performance/str-split-join.ts +23 -0
- package/performance/str-template.ts +16 -0
- package/performance/union-switch.ts +57 -0
- package/tsparser/check.go +2 -1
- package/tsparser/main.go +5 -0
- package/types/typenative-npm.d.ts +193 -4
- package/types/typenative.d.ts +138 -41
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { joinValues } from '../../utils/joinValues.ts';
|
|
2
|
+
import { stringify } from '../../utils/stringify.ts';
|
|
3
|
+
import type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';
|
|
4
|
+
import type * as zod from '../../../../zod/src/v4/core/index.ts';
|
|
5
|
+
|
|
6
|
+
export function parseInvalidValueIssue(
|
|
7
|
+
issue: zod.$ZodRawIssue<zod.$ZodIssueInvalidValue>,
|
|
8
|
+
options: Pick<
|
|
9
|
+
ErrorMapOptions,
|
|
10
|
+
| 'allowedValuesSeparator'
|
|
11
|
+
| 'maxAllowedValuesToDisplay'
|
|
12
|
+
| 'wrapAllowedValuesInQuote'
|
|
13
|
+
| 'allowedValuesLastSeparator'
|
|
14
|
+
>
|
|
15
|
+
): AbstractSyntaxTree {
|
|
16
|
+
let message: string;
|
|
17
|
+
|
|
18
|
+
if (issue.values.length === 0) {
|
|
19
|
+
message = 'invalid value';
|
|
20
|
+
} else if (issue.values.length === 1) {
|
|
21
|
+
const valueStr = stringify(issue.values[0], {
|
|
22
|
+
wrapStringValueInQuote: true,
|
|
23
|
+
});
|
|
24
|
+
message = `expected value to be ${valueStr}`;
|
|
25
|
+
} else {
|
|
26
|
+
const valuesStr = joinValues(issue.values, {
|
|
27
|
+
separator: options.allowedValuesSeparator,
|
|
28
|
+
lastSeparator: options.allowedValuesLastSeparator,
|
|
29
|
+
wrapStringValuesInQuote: options.wrapAllowedValuesInQuote,
|
|
30
|
+
maxValuesToDisplay: options.maxAllowedValuesToDisplay,
|
|
31
|
+
});
|
|
32
|
+
message = `expected value to be one of ${valuesStr}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
type: issue.code,
|
|
37
|
+
path: issue.path,
|
|
38
|
+
message,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as zod from '../../../../zod/src/v4/core/index.ts';
|
|
2
|
+
import type { AbstractSyntaxTree } from './types.ts';
|
|
3
|
+
|
|
4
|
+
export function parseNotMultipleOfIssue(
|
|
5
|
+
issue: zod.$ZodRawIssue<zod.$ZodIssueNotMultipleOf>
|
|
6
|
+
): AbstractSyntaxTree {
|
|
7
|
+
return {
|
|
8
|
+
type: issue.code,
|
|
9
|
+
path: issue.path,
|
|
10
|
+
message: `expected multiple of ${issue.divisor}`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { stringify } from '../../utils/stringify.ts';
|
|
2
|
+
import type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';
|
|
3
|
+
import type * as zod from '../../../../zod/src/v4/core/index.ts';
|
|
4
|
+
|
|
5
|
+
export function parseTooBigIssue(
|
|
6
|
+
issue: zod.$ZodRawIssue<zod.$ZodIssueTooBig>,
|
|
7
|
+
options: Pick<ErrorMapOptions, 'dateLocalization' | 'numberLocalization'>
|
|
8
|
+
): AbstractSyntaxTree {
|
|
9
|
+
const maxValueStr =
|
|
10
|
+
issue.origin === 'date'
|
|
11
|
+
? stringify(new Date(issue.maximum as number), {
|
|
12
|
+
localization: options.dateLocalization,
|
|
13
|
+
})
|
|
14
|
+
: stringify(issue.maximum, {
|
|
15
|
+
localization: options.numberLocalization,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
switch (issue.origin) {
|
|
19
|
+
case 'number':
|
|
20
|
+
case 'int':
|
|
21
|
+
case 'bigint': {
|
|
22
|
+
return {
|
|
23
|
+
type: issue.code,
|
|
24
|
+
path: issue.path,
|
|
25
|
+
message: `number must be less than${
|
|
26
|
+
issue.inclusive ? ' or equal to' : ''
|
|
27
|
+
} ${maxValueStr}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case 'string': {
|
|
31
|
+
return {
|
|
32
|
+
type: issue.code,
|
|
33
|
+
path: issue.path,
|
|
34
|
+
message: `string must contain at most ${maxValueStr} character(s)`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
case 'date': {
|
|
38
|
+
return {
|
|
39
|
+
type: issue.code,
|
|
40
|
+
path: issue.path,
|
|
41
|
+
message: `date must be ${
|
|
42
|
+
issue.inclusive ? 'prior or equal to' : 'prior to'
|
|
43
|
+
} "${maxValueStr}"`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
case 'array': {
|
|
47
|
+
return {
|
|
48
|
+
type: issue.code,
|
|
49
|
+
path: issue.path,
|
|
50
|
+
message: `array must contain at most ${maxValueStr} item(s)`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case 'set': {
|
|
54
|
+
return {
|
|
55
|
+
type: issue.code,
|
|
56
|
+
path: issue.path,
|
|
57
|
+
message: `set must contain at most ${maxValueStr} item(s)`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
case 'file': {
|
|
61
|
+
return {
|
|
62
|
+
type: issue.code,
|
|
63
|
+
path: issue.path,
|
|
64
|
+
message: `file must not exceed ${maxValueStr} byte(s) in size`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
return {
|
|
69
|
+
type: issue.code,
|
|
70
|
+
path: issue.path,
|
|
71
|
+
message: `value must be less than${
|
|
72
|
+
issue.inclusive ? ' or equal to' : ''
|
|
73
|
+
} ${maxValueStr}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { stringify } from '../../utils/stringify.ts';
|
|
2
|
+
import type * as zod from '../../../../zod/src/v4/core/index.ts';
|
|
3
|
+
import type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';
|
|
4
|
+
|
|
5
|
+
export function parseTooSmallIssue(
|
|
6
|
+
issue: zod.$ZodRawIssue<zod.$ZodIssueTooSmall>,
|
|
7
|
+
options: Pick<ErrorMapOptions, 'dateLocalization' | 'numberLocalization'>
|
|
8
|
+
): AbstractSyntaxTree {
|
|
9
|
+
const minValueStr =
|
|
10
|
+
issue.origin === 'date'
|
|
11
|
+
? stringify(new Date(issue.minimum as number), {
|
|
12
|
+
localization: options.dateLocalization,
|
|
13
|
+
})
|
|
14
|
+
: stringify(issue.minimum, {
|
|
15
|
+
localization: options.numberLocalization,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
switch (issue.origin) {
|
|
19
|
+
case 'number':
|
|
20
|
+
case 'int':
|
|
21
|
+
case 'bigint': {
|
|
22
|
+
return {
|
|
23
|
+
type: issue.code,
|
|
24
|
+
path: issue.path,
|
|
25
|
+
message: `number must be greater than${
|
|
26
|
+
issue.inclusive ? ' or equal to' : ''
|
|
27
|
+
} ${minValueStr}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case 'date': {
|
|
31
|
+
return {
|
|
32
|
+
type: issue.code,
|
|
33
|
+
path: issue.path,
|
|
34
|
+
message: `date must be ${
|
|
35
|
+
issue.inclusive ? 'later or equal to' : 'later to'
|
|
36
|
+
} "${minValueStr}"`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case 'string': {
|
|
40
|
+
return {
|
|
41
|
+
type: issue.code,
|
|
42
|
+
path: issue.path,
|
|
43
|
+
message: `string must contain at least ${minValueStr} character(s)`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
case 'array': {
|
|
47
|
+
return {
|
|
48
|
+
type: issue.code,
|
|
49
|
+
path: issue.path,
|
|
50
|
+
message: `array must contain at least ${minValueStr} item(s)`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case 'set': {
|
|
54
|
+
return {
|
|
55
|
+
type: issue.code,
|
|
56
|
+
path: issue.path,
|
|
57
|
+
message: `set must contain at least ${minValueStr} item(s)`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
case 'file': {
|
|
61
|
+
return {
|
|
62
|
+
type: issue.code,
|
|
63
|
+
path: issue.path,
|
|
64
|
+
message: `file must be at least ${minValueStr} byte(s) in size`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
return {
|
|
69
|
+
type: issue.code,
|
|
70
|
+
path: issue.path,
|
|
71
|
+
message: `value must be greater than${
|
|
72
|
+
issue.inclusive ? ' or equal to' : ''
|
|
73
|
+
} ${minValueStr}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as zod from '../../../../zod/src/v4/core/index.ts';
|
|
2
|
+
|
|
3
|
+
export type IssueType = NonNullable<zod.$ZodIssue['code']>;
|
|
4
|
+
|
|
5
|
+
export type AbstractSyntaxTree = {
|
|
6
|
+
type: IssueType;
|
|
7
|
+
path?: zod.$ZodIssue['path'];
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ErrorMapOptions = {
|
|
12
|
+
// Stringify values
|
|
13
|
+
dateLocalization: boolean | Intl.LocalesArgument;
|
|
14
|
+
numberLocalization: boolean | Intl.LocalesArgument;
|
|
15
|
+
// Invalid format options
|
|
16
|
+
displayInvalidFormatDetails: boolean;
|
|
17
|
+
// Allowed values options
|
|
18
|
+
allowedValuesSeparator: string;
|
|
19
|
+
allowedValuesLastSeparator: string | undefined;
|
|
20
|
+
wrapAllowedValuesInQuote: boolean;
|
|
21
|
+
maxAllowedValuesToDisplay: number;
|
|
22
|
+
// Unrecognized keys options
|
|
23
|
+
unrecognizedKeysSeparator: string;
|
|
24
|
+
unrecognizedKeysLastSeparator: string | undefined;
|
|
25
|
+
wrapUnrecognizedKeysInQuote: boolean;
|
|
26
|
+
maxUnrecognizedKeysToDisplay: number;
|
|
27
|
+
};
|
package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { joinValues } from '../../utils/joinValues.ts';
|
|
2
|
+
import type * as zod from '../../../../zod/src/v4/core/index.ts';
|
|
3
|
+
import type { AbstractSyntaxTree, ErrorMapOptions } from './types.ts';
|
|
4
|
+
|
|
5
|
+
export function parseUnrecognizedKeysIssue(
|
|
6
|
+
issue: zod.$ZodRawIssue<zod.$ZodIssueUnrecognizedKeys>,
|
|
7
|
+
options: Pick<
|
|
8
|
+
ErrorMapOptions,
|
|
9
|
+
| 'unrecognizedKeysSeparator'
|
|
10
|
+
| 'unrecognizedKeysLastSeparator'
|
|
11
|
+
| 'wrapUnrecognizedKeysInQuote'
|
|
12
|
+
| 'maxUnrecognizedKeysToDisplay'
|
|
13
|
+
>
|
|
14
|
+
): AbstractSyntaxTree {
|
|
15
|
+
const keysStr = joinValues(issue.keys, {
|
|
16
|
+
separator: options.unrecognizedKeysSeparator,
|
|
17
|
+
lastSeparator: options.unrecognizedKeysLastSeparator,
|
|
18
|
+
wrapStringValuesInQuote: options.wrapUnrecognizedKeysInQuote,
|
|
19
|
+
maxValuesToDisplay: options.maxUnrecognizedKeysToDisplay,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
type: issue.code,
|
|
24
|
+
path: issue.path,
|
|
25
|
+
message: `unrecognized key(s) ${keysStr} in object`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { toValidationError } from './toValidationError.ts';
|
|
2
|
+
import type { FromZodErrorOptions } from './fromZodError.ts';
|
|
3
|
+
import type { ValidationError } from './ValidationError.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This function is a non-curried version of `toValidationError`
|
|
7
|
+
*/
|
|
8
|
+
export function fromError(
|
|
9
|
+
err: unknown,
|
|
10
|
+
options: FromZodErrorOptions = {}
|
|
11
|
+
): ValidationError {
|
|
12
|
+
return toValidationError(options)(err);
|
|
13
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isNonEmptyArray } from '../utils/NonEmptyArray.ts';
|
|
2
|
+
import { fromError } from './fromError.ts';
|
|
3
|
+
import { isZodErrorLike } from './isZodErrorLike.ts';
|
|
4
|
+
import {
|
|
5
|
+
createMessageBuilder,
|
|
6
|
+
type MessageBuilderOptions,
|
|
7
|
+
type MessageBuilder,
|
|
8
|
+
} from './MessageBuilder.ts';
|
|
9
|
+
import { ValidationError } from './ValidationError.ts';
|
|
10
|
+
import type * as zod from '../../../zod/src/v4/core/index.ts';
|
|
11
|
+
|
|
12
|
+
export type ZodError = zod.$ZodError;
|
|
13
|
+
|
|
14
|
+
export type FromZodErrorOptions =
|
|
15
|
+
| {
|
|
16
|
+
messageBuilder: MessageBuilder;
|
|
17
|
+
}
|
|
18
|
+
// maintain backwards compatibility
|
|
19
|
+
| Partial<MessageBuilderOptions>;
|
|
20
|
+
|
|
21
|
+
export function fromZodError(
|
|
22
|
+
zodError: ZodError,
|
|
23
|
+
options: FromZodErrorOptions = {}
|
|
24
|
+
): ValidationError {
|
|
25
|
+
// perform runtime check to ensure the input is a ZodError
|
|
26
|
+
// why? because people have been historically using this function incorrectly
|
|
27
|
+
if (!isZodErrorLike(zodError)) {
|
|
28
|
+
throw new TypeError(
|
|
29
|
+
`Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return fromZodErrorWithoutRuntimeCheck(zodError, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function fromZodErrorWithoutRuntimeCheck(
|
|
37
|
+
zodError: ZodError,
|
|
38
|
+
options: FromZodErrorOptions = {}
|
|
39
|
+
): ValidationError {
|
|
40
|
+
const zodIssues = zodError.issues;
|
|
41
|
+
|
|
42
|
+
let message: string;
|
|
43
|
+
if (isNonEmptyArray(zodIssues)) {
|
|
44
|
+
const messageBuilder = createMessageBuilderFromOptions(options);
|
|
45
|
+
message = messageBuilder(zodIssues);
|
|
46
|
+
} else {
|
|
47
|
+
message = zodError.message;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return new ValidationError(message, { cause: zodError });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createMessageBuilderFromOptions(
|
|
54
|
+
options: FromZodErrorOptions
|
|
55
|
+
): MessageBuilder {
|
|
56
|
+
if ('messageBuilder' in options) {
|
|
57
|
+
return options.messageBuilder;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return createMessageBuilder(options);
|
|
61
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as zod from '../../../zod/src/v4/core/index.ts';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type MessageBuilder,
|
|
5
|
+
type MessageBuilderOptions,
|
|
6
|
+
type ZodIssue,
|
|
7
|
+
createMessageBuilder,
|
|
8
|
+
} from './MessageBuilder.ts';
|
|
9
|
+
import { ValidationError } from './ValidationError.ts';
|
|
10
|
+
|
|
11
|
+
export type FromZodIssueOptions =
|
|
12
|
+
| {
|
|
13
|
+
messageBuilder: MessageBuilder;
|
|
14
|
+
}
|
|
15
|
+
// maintain backwards compatibility
|
|
16
|
+
| Partial<Omit<MessageBuilderOptions, 'maxIssuesInMessage'>>;
|
|
17
|
+
|
|
18
|
+
export function fromZodIssue(
|
|
19
|
+
issue: ZodIssue,
|
|
20
|
+
options: FromZodIssueOptions = {}
|
|
21
|
+
): ValidationError {
|
|
22
|
+
const messageBuilder = createMessageBuilderFromOptions(options);
|
|
23
|
+
const message = messageBuilder([issue]);
|
|
24
|
+
|
|
25
|
+
return new ValidationError(message, {
|
|
26
|
+
cause: new zod.$ZodRealError([issue]),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createMessageBuilderFromOptions(
|
|
31
|
+
options: FromZodIssueOptions
|
|
32
|
+
): MessageBuilder {
|
|
33
|
+
if ('messageBuilder' in options) {
|
|
34
|
+
return options.messageBuilder;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return createMessageBuilder(options);
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { ValidationError, type ErrorOptions } from './ValidationError.ts';
|
|
2
|
+
export { isValidationError } from './isValidationError.ts';
|
|
3
|
+
export { isValidationErrorLike } from './isValidationErrorLike.ts';
|
|
4
|
+
export { isZodErrorLike } from './isZodErrorLike.ts';
|
|
5
|
+
export { createErrorMap, type ErrorMapOptions } from './errorMap/index.ts';
|
|
6
|
+
export { fromError } from './fromError.ts';
|
|
7
|
+
export { fromZodIssue, type FromZodIssueOptions } from './fromZodIssue.ts';
|
|
8
|
+
export {
|
|
9
|
+
fromZodError,
|
|
10
|
+
type FromZodErrorOptions,
|
|
11
|
+
type ZodError,
|
|
12
|
+
} from './fromZodError.ts';
|
|
13
|
+
export { toValidationError } from './toValidationError.ts';
|
|
14
|
+
export {
|
|
15
|
+
type MessageBuilder,
|
|
16
|
+
type ZodIssue,
|
|
17
|
+
createMessageBuilder,
|
|
18
|
+
type MessageBuilderOptions,
|
|
19
|
+
} from './MessageBuilder.ts';
|
|
20
|
+
export { type NonEmptyArray } from '../utils/NonEmptyArray.ts';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as zod from '../../../zod/src/v4/core/index.ts';
|
|
2
|
+
|
|
3
|
+
export function isZodErrorLike(err: unknown): err is zod.$ZodError {
|
|
4
|
+
return (
|
|
5
|
+
err instanceof Object &&
|
|
6
|
+
'name' in err &&
|
|
7
|
+
(err.name === 'ZodError' || err.name === '$ZodError') &&
|
|
8
|
+
'issues' in err &&
|
|
9
|
+
Array.isArray(err.issues)
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ValidationError } from './ValidationError.ts';
|
|
2
|
+
import { isZodErrorLike } from './isZodErrorLike.ts';
|
|
3
|
+
import {
|
|
4
|
+
fromZodErrorWithoutRuntimeCheck,
|
|
5
|
+
type FromZodErrorOptions,
|
|
6
|
+
} from './fromZodError.ts';
|
|
7
|
+
|
|
8
|
+
export const toValidationError =
|
|
9
|
+
(options: FromZodErrorOptions = {}) =>
|
|
10
|
+
(err: unknown): ValidationError => {
|
|
11
|
+
if (isZodErrorLike(err)) {
|
|
12
|
+
return fromZodErrorWithoutRuntimeCheck(err, options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (err instanceof Error) {
|
|
16
|
+
return new ValidationError(err.message, { cause: err });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return new ValidationError('Unknown error');
|
|
20
|
+
};
|