Upgrade mcschema core

This commit is contained in:
Misode
2021-01-16 15:59:32 +01:00
parent 8e7668b3b9
commit f543c4465c
8 changed files with 9 additions and 47 deletions

View File

@@ -3,12 +3,6 @@ import { getFilterKey } from './getFilterKey'
export const canFlatten: Hook<[], boolean> = {
base: () => false,
boolean: () => false,
choice: () => false,
list: () => false,
map: () => false,
number: () => false,
string: () => false,
object({ node, getActiveFields }, path) {
const filterKey = path.modelArr.length === 0 ? null : node.hook(getFilterKey, path, path)
const visibleEntries = Object.entries(getActiveFields(path))

View File

@@ -6,12 +6,6 @@ import { walk } from './walk'
export const customValidation: Hook<[any, Errors], void> = walk<[Errors]>({
base() {},
boolean() {},
choice() {},
list() {},
map({ config }, path, value) {
if (config.validation?.validator === 'block_state_map') {
const block = relativePath(path, config.validation.params.id).get()
@@ -31,8 +25,6 @@ export const customValidation: Hook<[any, Errors], void> = walk<[Errors]>({
}
},
number() {},
object({ node, getActiveFields }, path, value) {
let activeFields = getActiveFields(path)
const filterKey = path.modelArr.length === 0 ? null : node.hook(getFilterKey, path, path)
@@ -44,7 +36,5 @@ export const customValidation: Hook<[any, Errors], void> = walk<[Errors]>({
path.push(visibleKeys[0]).set(undefined)
}
}
},
string() {}
}
})

View File

@@ -2,12 +2,6 @@ import { Hook, ModelPath, relativePath } from '@mcschema/core'
export const getFilterKey: Hook<[ModelPath, number?], string | null> = {
base: () => null,
boolean: () => null,
choice: () => null,
list: () => null,
map: () => null,
number: () => null,
string: () => null,
object({ filter, getActiveFields }, path, origin, depth = 0) {
if (depth > 2) return null
if (filter) {

View File

@@ -9,10 +9,6 @@ import { Tracker } from '../Tracker'
export const suffixInjector: Hook<[Mounter], string | void> = {
base() {},
boolean() {},
list() {},
map() {},
number() {},
choice({ switchNode }, path, mounter) {
return switchNode.hook(this, path, mounter)

View File

@@ -5,10 +5,6 @@ export const transformOutput: Hook<[any], any> = {
return value
},
boolean({}, _, value) {
return value
},
choice({ switchNode }, path, value) {
return switchNode.hook(this, path, value)
},
@@ -29,10 +25,6 @@ export const transformOutput: Hook<[any], any> = {
return res;
},
number({}, _, value) {
return value
},
object({ getActiveFields }, path, value) {
if (value === undefined || value === null || typeof value !== 'object') {
return value
@@ -45,9 +37,5 @@ export const transformOutput: Hook<[any], any> = {
res[f] = activeFields[f].hook(this, path.push(f), value[f])
})
return res
},
string({}, _, value) {
return value
}
}

View File

@@ -6,12 +6,12 @@ export const walk = <U extends Args> (hook: Hook<[any, ...U], void>): Hook<[any,
...hook,
choice(params, path, value, ...args) {
hook.choice(params, path, value, ...args)
(hook.choice ?? hook.base)(params, path, value, ...args)
params.switchNode.hook(this, path, value, ...args)
},
list(params, path, value, ...args) {
hook.list(params, path, value, ...args)
(hook.list ?? hook.base)(params, path, value, ...args)
if (!Array.isArray(value)) return
value.forEach((e, i) =>
params.children.hook(this, path.push(i), e, ...args)
@@ -19,7 +19,7 @@ export const walk = <U extends Args> (hook: Hook<[any, ...U], void>): Hook<[any,
},
map(params, path, value, ...args) {
hook.map(params, path, value, ...args)
(hook.map ?? hook.base)(params, path, value, ...args)
if (typeof value !== 'object') return
Object.keys(value).forEach(f =>
params.children.hook(this, path.push(f), value[f], ...args)
@@ -27,7 +27,7 @@ export const walk = <U extends Args> (hook: Hook<[any, ...U], void>): Hook<[any,
},
object(params, path, value, ...args) {
hook.object(params, path, value, ...args)
(hook.object ?? hook.base)(params, path, value, ...args)
if (value === null || typeof value !== 'object') return
const activeFields = params.getActiveFields(path)
Object.keys(activeFields)