fatsify核心功能示例测试!!!

This commit is contained in:
2025-09-21 14:50:41 +08:00
commit 9145aea047
1958 changed files with 230098 additions and 0 deletions

36
node_modules/@fastify/merge-json-schemas/lib/errors.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
'use strict'
class MergeError extends Error {
constructor (keyword, schemas) {
super()
this.name = 'JsonSchemaMergeError'
this.code = 'JSON_SCHEMA_MERGE_ERROR'
this.message = `Failed to merge "${keyword}" keyword schemas.`
this.schemas = schemas
}
}
class ResolverNotFoundError extends Error {
constructor (keyword, schemas) {
super()
this.name = 'JsonSchemaMergeError'
this.code = 'JSON_SCHEMA_MERGE_ERROR'
this.message = `Resolver for "${keyword}" keyword not found.`
this.schemas = schemas
}
}
class InvalidOnConflictOptionError extends Error {
constructor (onConflict) {
super()
this.name = 'JsonSchemaMergeError'
this.code = 'JSON_SCHEMA_MERGE_ERROR'
this.message = `Invalid "onConflict" option: "${onConflict}".`
}
}
module.exports = {
MergeError,
ResolverNotFoundError,
InvalidOnConflictOptionError
}

View File

@@ -0,0 +1,127 @@
'use strict'
const { dequal: deepEqual } = require('dequal')
const { MergeError } = require('./errors')
function _arraysIntersection (arrays) {
let intersection = arrays[0]
for (let i = 1; i < arrays.length; i++) {
intersection = intersection.filter(
value => arrays[i].includes(value)
)
}
return intersection
}
function arraysIntersection (keyword, values, mergedSchema) {
const intersection = _arraysIntersection(values)
if (intersection.length === 0) {
throw new MergeError(keyword, values)
}
mergedSchema[keyword] = intersection
}
function hybridArraysIntersection (keyword, values, mergedSchema) {
for (let i = 0; i < values.length; i++) {
if (!Array.isArray(values[i])) {
values[i] = [values[i]]
}
}
const intersection = _arraysIntersection(values)
if (intersection.length === 0) {
throw new MergeError(keyword, values)
}
if (intersection.length === 1) {
mergedSchema[keyword] = intersection[0]
} else {
mergedSchema[keyword] = intersection
}
}
function arraysUnion (keyword, values, mergedSchema) {
const union = []
for (const array of values) {
for (const value of array) {
if (!union.includes(value)) {
union.push(value)
}
}
}
mergedSchema[keyword] = union
}
function minNumber (keyword, values, mergedSchema) {
mergedSchema[keyword] = Math.min(...values)
}
function maxNumber (keyword, values, mergedSchema) {
mergedSchema[keyword] = Math.max(...values)
}
function commonMultiple (keyword, values, mergedSchema) {
const gcd = (a, b) => (!b ? a : gcd(b, a % b))
const lcm = (a, b) => (a * b) / gcd(a, b)
let scale = 1
for (const value of values) {
while (value * scale % 1 !== 0) {
scale *= 10
}
}
let multiple = values[0] * scale
for (const value of values) {
multiple = lcm(multiple, value * scale)
}
mergedSchema[keyword] = multiple / scale
}
function allEqual (keyword, values, mergedSchema) {
const firstValue = values[0]
for (let i = 1; i < values.length; i++) {
if (!deepEqual(values[i], firstValue)) {
throw new MergeError(keyword, values)
}
}
mergedSchema[keyword] = firstValue
}
function skip () {}
function booleanAnd (keyword, values, mergedSchema) {
for (const value of values) {
if (value === false) {
mergedSchema[keyword] = false
return
}
}
mergedSchema[keyword] = true
}
function booleanOr (keyword, values, mergedSchema) {
for (const value of values) {
if (value === true) {
mergedSchema[keyword] = true
return
}
}
mergedSchema[keyword] = false
}
module.exports = {
arraysIntersection,
hybridArraysIntersection,
arraysUnion,
minNumber,
maxNumber,
commonMultiple,
allEqual,
booleanAnd,
booleanOr,
skip
}