@eslint-react/shared
Advanced tools
Comparing version 1.5.2 to 1.5.3-beta.0
'use strict'; | ||
var utils = require('@typescript-eslint/utils'); | ||
var valibot = require('valibot'); | ||
@@ -214,42 +213,378 @@ /** | ||
// src/error/flatten/flatten.ts | ||
// src/error/ValiError/ValiError.ts | ||
var ValiError = class extends Error { | ||
issues; | ||
/** | ||
* Creates a Valibot error with useful information. | ||
* | ||
* @param issues The error issues. | ||
*/ | ||
constructor(issues) { | ||
super(issues[0].message); | ||
this.name = "ValiError"; | ||
this.issues = issues; | ||
} | ||
}; | ||
// src/utils/errorMessage/errorMessage.ts | ||
function errorMessage(message) { | ||
return typeof message === "function" ? message() : message; | ||
} | ||
// src/utils/defaultArgs/defaultArgs.ts | ||
function defaultArgs(arg1, arg2) { | ||
return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2]; | ||
} | ||
// src/utils/parseResult/parseResult.ts | ||
function parseResult(typed, output, issues) { | ||
return { typed, output, issues }; | ||
} | ||
// src/utils/restAndDefaultArgs/restAndDefaultArgs.ts | ||
function restAndDefaultArgs(arg1, arg2, arg3) { | ||
if (!arg1 || typeof arg1 === "object" && !Array.isArray(arg1)) { | ||
const [error2, pipe2] = defaultArgs(arg2, arg3); | ||
return [arg1, error2, pipe2]; | ||
} | ||
const [error, pipe] = defaultArgs( | ||
arg1, | ||
arg2 | ||
); | ||
return [void 0, error, pipe]; | ||
} | ||
// src/utils/pipeResult/utils/pipeIssue/pipeIssue.ts | ||
function pipeIssue(info, issue) { | ||
return { | ||
reason: info?.reason, | ||
validation: issue.validation, | ||
origin: info?.origin || "value", | ||
message: issue.message, | ||
input: issue.input, | ||
requirement: issue?.requirement, | ||
path: issue.path, | ||
abortEarly: info?.abortEarly, | ||
abortPipeEarly: info?.abortPipeEarly, | ||
skipPipe: info?.skipPipe | ||
}; | ||
} | ||
// src/utils/pipeResult/utils/pipeInfo/pipeInfo.ts | ||
function pipeInfo(info, reason) { | ||
return { | ||
reason, | ||
origin: info?.origin, | ||
abortEarly: info?.abortEarly, | ||
abortPipeEarly: info?.abortPipeEarly, | ||
skipPipe: info?.skipPipe | ||
}; | ||
} | ||
// src/utils/pipeResult/pipeResult.ts | ||
function pipeResult(input, pipe, parseInfo, reason, issues) { | ||
let info; | ||
let output = input; | ||
if (pipe?.length && !parseInfo?.skipPipe) { | ||
for (const action of pipe) { | ||
const result = action._parse(output); | ||
if (result.issues) { | ||
info = info || pipeInfo(parseInfo, reason); | ||
for (const issueInfo of result.issues) { | ||
const issue = pipeIssue(info, issueInfo); | ||
issues ? issues.push(issue) : issues = [issue]; | ||
} | ||
if (info.abortEarly || info.abortPipeEarly) { | ||
break; | ||
} | ||
} else { | ||
output = result.output; | ||
} | ||
} | ||
} | ||
return parseResult(true, output, issues); | ||
} | ||
// src/utils/schemaIssue/schemaIssue.ts | ||
function schemaIssue(info, reason, validation, message, input, path, issues) { | ||
return { | ||
typed: false, | ||
output: input, | ||
issues: [ | ||
{ | ||
reason, | ||
validation, | ||
origin: info?.origin || "value", | ||
message: errorMessage(message), | ||
input, | ||
path, | ||
issues, | ||
abortEarly: info?.abortEarly, | ||
abortPipeEarly: info?.abortPipeEarly, | ||
skipPipe: info?.skipPipe | ||
} | ||
] | ||
}; | ||
} | ||
// src/methods/getDefault/getDefault.ts | ||
function getDefault(schema) { | ||
return typeof schema.default === "function" ? schema.default() : schema.default; | ||
} | ||
// src/schemas/array/array.ts | ||
function array(item, arg2, arg3) { | ||
const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); | ||
return { | ||
type: "array", | ||
async: false, | ||
item, | ||
message, | ||
pipe, | ||
_parse(input, info) { | ||
if (!Array.isArray(input)) { | ||
return schemaIssue(info, "type", "array", this.message, input); | ||
} | ||
let typed = true; | ||
let issues; | ||
const output = []; | ||
for (let key = 0; key < input.length; key++) { | ||
const value2 = input[key]; | ||
const result = this.item._parse(value2, info); | ||
if (result.issues) { | ||
const pathItem = { | ||
type: "array", | ||
input, | ||
key, | ||
value: value2 | ||
}; | ||
for (const issue of result.issues) { | ||
if (issue.path) { | ||
issue.path.unshift(pathItem); | ||
} else { | ||
issue.path = [pathItem]; | ||
} | ||
issues?.push(issue); | ||
} | ||
if (!issues) { | ||
issues = result.issues; | ||
} | ||
if (info?.abortEarly) { | ||
typed = false; | ||
break; | ||
} | ||
} | ||
if (!result.typed) { | ||
typed = false; | ||
} | ||
output.push(result.output); | ||
} | ||
if (typed) { | ||
return pipeResult( | ||
output, | ||
this.pipe, | ||
info, | ||
"array", | ||
issues | ||
); | ||
} | ||
return parseResult(false, output, issues); | ||
} | ||
}; | ||
} | ||
// src/schemas/object/object.ts | ||
function object(entries, arg2, arg3, arg4) { | ||
const [rest, message = "Invalid type", pipe] = restAndDefaultArgs(arg2, arg3, arg4); | ||
let cachedEntries; | ||
return { | ||
type: "object", | ||
async: false, | ||
entries, | ||
rest, | ||
message, | ||
pipe, | ||
_parse(input, info) { | ||
if (!input || typeof input !== "object") { | ||
return schemaIssue(info, "type", "object", this.message, input); | ||
} | ||
cachedEntries = cachedEntries || Object.entries(this.entries); | ||
let typed = true; | ||
let issues; | ||
const output = {}; | ||
for (const [key, schema] of cachedEntries) { | ||
const value2 = input[key]; | ||
const result = schema._parse(value2, info); | ||
if (result.issues) { | ||
const pathItem = { | ||
type: "object", | ||
input, | ||
key, | ||
value: value2 | ||
}; | ||
for (const issue of result.issues) { | ||
if (issue.path) { | ||
issue.path.unshift(pathItem); | ||
} else { | ||
issue.path = [pathItem]; | ||
} | ||
issues?.push(issue); | ||
} | ||
if (!issues) { | ||
issues = result.issues; | ||
} | ||
if (info?.abortEarly) { | ||
typed = false; | ||
break; | ||
} | ||
} | ||
if (!result.typed) { | ||
typed = false; | ||
} | ||
if (result.output !== void 0 || key in input) { | ||
output[key] = result.output; | ||
} | ||
} | ||
if (this.rest && !(info?.abortEarly && issues)) { | ||
for (const key in input) { | ||
if (!(key in this.entries)) { | ||
const value2 = input[key]; | ||
const result = this.rest._parse(value2, info); | ||
if (result.issues) { | ||
const pathItem = { | ||
type: "object", | ||
input, | ||
key, | ||
value: value2 | ||
}; | ||
for (const issue of result.issues) { | ||
if (issue.path) { | ||
issue.path.unshift(pathItem); | ||
} else { | ||
issue.path = [pathItem]; | ||
} | ||
issues?.push(issue); | ||
} | ||
if (!issues) { | ||
issues = result.issues; | ||
} | ||
if (info?.abortEarly) { | ||
typed = false; | ||
break; | ||
} | ||
} | ||
if (!result.typed) { | ||
typed = false; | ||
} | ||
output[key] = result.output; | ||
} | ||
} | ||
} | ||
if (typed) { | ||
return pipeResult( | ||
output, | ||
this.pipe, | ||
info, | ||
"object", | ||
issues | ||
); | ||
} | ||
return parseResult(false, output, issues); | ||
} | ||
}; | ||
} | ||
// src/schemas/optional/optional.ts | ||
function optional(wrapped, default_) { | ||
return { | ||
type: "optional", | ||
async: false, | ||
wrapped, | ||
default: default_, | ||
_parse(input, info) { | ||
if (input === void 0) { | ||
const override = getDefault(this); | ||
if (override === void 0) { | ||
return parseResult(true, input); | ||
} | ||
input = override; | ||
} | ||
return this.wrapped._parse(input, info); | ||
} | ||
}; | ||
} | ||
// src/schemas/string/string.ts | ||
function string(arg1, arg2) { | ||
const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); | ||
return { | ||
type: "string", | ||
async: false, | ||
message, | ||
pipe, | ||
_parse(input, info) { | ||
if (typeof input !== "string") { | ||
return schemaIssue(info, "type", "string", this.message, input); | ||
} | ||
return pipeResult(input, this.pipe, info, "string"); | ||
} | ||
}; | ||
} | ||
// src/methods/parse/parse.ts | ||
function parse(schema, input, info) { | ||
const result = schema._parse(input, info); | ||
if (result.issues) { | ||
throw new ValiError(result.issues); | ||
} | ||
return result.output; | ||
} | ||
// src/methods/safeParse/safeParse.ts | ||
function safeParse(schema, input, info) { | ||
const result = schema._parse(input, info); | ||
return { | ||
typed: result.typed, | ||
success: !result.issues, | ||
data: result.output, | ||
output: result.output, | ||
error: result.issues && new ValiError(result.issues), | ||
issues: result.issues | ||
}; | ||
} | ||
/** | ||
* @internal | ||
*/ const ESLintReactSettingsSchema = valibot.object({ | ||
additionalHooks: valibot.optional(valibot.object({ | ||
use: valibot.optional(valibot.string()), | ||
useCallback: valibot.optional(valibot.array(valibot.string())), | ||
useContext: valibot.optional(valibot.array(valibot.string())), | ||
useDebugValue: valibot.optional(valibot.array(valibot.string())), | ||
useDeferredValue: valibot.optional(valibot.array(valibot.string())), | ||
useEffect: valibot.optional(valibot.array(valibot.string())), | ||
useId: valibot.optional(valibot.array(valibot.string())), | ||
useImperativeHandle: valibot.optional(valibot.array(valibot.string())), | ||
useInsertionEffect: valibot.optional(valibot.array(valibot.string())), | ||
useLayoutEffect: valibot.optional(valibot.array(valibot.string())), | ||
useMemo: valibot.optional(valibot.array(valibot.string())), | ||
useOptimistic: valibot.optional(valibot.array(valibot.string())), | ||
useReducer: valibot.optional(valibot.array(valibot.string())), | ||
useRef: valibot.optional(valibot.array(valibot.string())), | ||
useState: valibot.optional(valibot.array(valibot.string())), | ||
useSyncExternalStore: valibot.optional(valibot.array(valibot.string())), | ||
useTransition: valibot.optional(valibot.array(valibot.string())) | ||
*/ const ESLintReactSettingsSchema = object({ | ||
additionalHooks: optional(object({ | ||
use: optional(string()), | ||
useCallback: optional(array(string())), | ||
useContext: optional(array(string())), | ||
useDebugValue: optional(array(string())), | ||
useDeferredValue: optional(array(string())), | ||
useEffect: optional(array(string())), | ||
useId: optional(array(string())), | ||
useImperativeHandle: optional(array(string())), | ||
useInsertionEffect: optional(array(string())), | ||
useLayoutEffect: optional(array(string())), | ||
useMemo: optional(array(string())), | ||
useOptimistic: optional(array(string())), | ||
useReducer: optional(array(string())), | ||
useRef: optional(array(string())), | ||
useState: optional(array(string())), | ||
useSyncExternalStore: optional(array(string())), | ||
useTransition: optional(array(string())) | ||
})), | ||
jsxPragma: valibot.optional(valibot.string()), | ||
jsxPragmaFrag: valibot.optional(valibot.string()), | ||
version: valibot.optional(valibot.string()) | ||
jsxPragma: optional(string()), | ||
jsxPragmaFrag: optional(string()), | ||
version: optional(string()) | ||
}); | ||
/** | ||
* @internal | ||
*/ const ESLintSettingsSchema = valibot.object({ | ||
reactOptions: valibot.optional(ESLintReactSettingsSchema) | ||
*/ const ESLintSettingsSchema = object({ | ||
reactOptions: optional(ESLintReactSettingsSchema) | ||
}); | ||
Object.defineProperty(exports, "parseSchema", { | ||
enumerable: true, | ||
get: function () { return valibot.parse; } | ||
}); | ||
Object.defineProperty(exports, "safeParseSchema", { | ||
enumerable: true, | ||
get: function () { return valibot.safeParse; } | ||
}); | ||
exports.ESLintReactSettingsSchema = ESLintReactSettingsSchema; | ||
@@ -269,1 +604,3 @@ exports.ESLintSettingsSchema = ESLintSettingsSchema; | ||
exports.createRuleForPlugin = createRuleForPlugin; | ||
exports.parseSchema = parse; | ||
exports.safeParseSchema = safeParse; |
{ | ||
"name": "@eslint-react/shared", | ||
"version": "1.5.2", | ||
"version": "1.5.3-beta.0", | ||
"description": "ESLint React's Shared constants and functions.", | ||
@@ -38,8 +38,8 @@ "homepage": "https://github.com/rel1cx/eslint-react", | ||
"dependencies": { | ||
"@typescript-eslint/utils": ">=6.20.0", | ||
"deepmerge-ts": "5.1.0", | ||
"valibot": "0.27.0" | ||
"@typescript-eslint/utils": ">=6.21.0", | ||
"deepmerge-ts": "5.1.0" | ||
}, | ||
"devDependencies": { | ||
"type-fest": "4.10.2" | ||
"type-fest": "4.10.2", | ||
"valibot": "0.27.0" | ||
}, | ||
@@ -46,0 +46,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80368
2
2005
2
1
- Removedvalibot@0.27.0
- Removedvalibot@0.27.0(transitive)