feat: enable strictNullChecks

feat: enable `noImplicitAny`

chore: remove sync data access

fix loading package data for affected dependencies

chore: properly get alt marketplace data

update patchdb client to allow for emit on undefined values
This commit is contained in:
waterplea
2022-05-26 18:20:31 +03:00
committed by Lucy C
parent 948fb795f2
commit 0390954a85
99 changed files with 674 additions and 535 deletions

View File

@@ -86,7 +86,7 @@ export class FormService {
validators: ValidatorFn[] = [],
current: { [key: string]: any } = {},
): FormGroup {
let group = {}
let group: Record<string, FormGroup | FormArray | FormControl> = {}
Object.entries(config).map(([key, spec]) => {
if (spec.type === 'pointer') return
group[key] = this.getFormEntry(spec, current ? current[key] : undefined)
@@ -137,6 +137,8 @@ export class FormService {
case 'enum':
value = currentValue === undefined ? spec.default : currentValue
return this.formBuilder.control(value)
default:
return this.formBuilder.control(null)
}
}
}
@@ -298,25 +300,20 @@ export function listUnique(spec: ValueSpecList): ValidatorFn {
}
function listItemEquals(spec: ValueSpecList, val1: any, val2: any): boolean {
// TODO: fix types
switch (spec.subtype) {
case 'string':
case 'number':
case 'enum':
return val1 == val2
case 'object':
return listObjEquals(
spec.spec['unique-by'],
spec.spec as ListValueSpecObject,
val1,
val2,
)
const obj: ListValueSpecObject = spec.spec as any
return listObjEquals(obj['unique-by'], obj, val1, val2)
case 'union':
return unionEquals(
spec.spec['unique-by'],
spec.spec as ListValueSpecUnion,
val1,
val2,
)
const union: ListValueSpecUnion = spec.spec as any
return unionEquals(union['unique-by'], union, val1, val2)
default:
return false
}
@@ -330,9 +327,21 @@ function itemEquals(spec: ValueSpec, val1: any, val2: any): boolean {
case 'enum':
return val1 == val2
case 'object':
return objEquals(spec['unique-by'], spec as ValueSpecObject, val1, val2)
// TODO: 'unique-by' does not exist on ValueSpecObject, fix types
return objEquals(
(spec as any)['unique-by'],
spec as ValueSpecObject,
val1,
val2,
)
case 'union':
return unionEquals(spec['unique-by'], spec as ValueSpecUnion, val1, val2)
// TODO: 'unique-by' does not exist on ValueSpecUnion, fix types
return unionEquals(
(spec as any)['unique-by'],
spec as ValueSpecUnion,
val1,
val2,
)
case 'list':
if (val1.length !== val2.length) {
return false
@@ -373,6 +382,7 @@ function listObjEquals(
}
return true
}
return false
}
function objEquals(
@@ -384,7 +394,8 @@ function objEquals(
if (uniqueBy === null) {
return false
} else if (typeof uniqueBy === 'string') {
return itemEquals(spec[uniqueBy], val1[uniqueBy], val2[uniqueBy])
// TODO: fix types
return itemEquals((spec as any)[uniqueBy], val1[uniqueBy], val2[uniqueBy])
} else if ('any' in uniqueBy) {
for (let subSpec of uniqueBy.any) {
if (objEquals(subSpec, spec, val1, val2)) {
@@ -400,6 +411,7 @@ function objEquals(
}
return true
}
return false
}
function unionEquals(
@@ -433,12 +445,13 @@ function unionEquals(
}
return true
}
return false
}
function uniqueByMessageWrapper(
uniqueBy: UniqueBy,
spec: ListValueSpecObject | ListValueSpecUnion,
obj: object,
obj: Record<string, string>,
) {
let configSpec: ConfigSpec
if (isUnion(spec)) {
@@ -460,9 +473,9 @@ function uniqueByMessage(
outermost = true,
): string {
let joinFunc
const subSpecs = []
const subSpecs: string[] = []
if (uniqueBy === null) {
return null
return ''
} else if (typeof uniqueBy === 'string') {
return configSpec[uniqueBy] ? configSpec[uniqueBy].name : uniqueBy
} else if ('any' in uniqueBy) {
@@ -476,7 +489,7 @@ function uniqueByMessage(
subSpecs.push(uniqueByMessage(subSpec, configSpec, false))
}
}
const ret = subSpecs.filter(ss => ss).join(joinFunc)
const ret = subSpecs.filter(Boolean).join(joinFunc)
return outermost || subSpecs.filter(ss => ss).length === 1
? ret
: '(' + ret + ')'
@@ -486,7 +499,7 @@ function isObjectOrUnion(
spec: ListValueSpecOf<any>,
): spec is ListValueSpecObject | ListValueSpecUnion {
// only lists of objects and unions have unique-by
return spec['unique-by'] !== undefined
return 'unique-by' in spec
}
function isUnion(spec: any): spec is ListValueSpecUnion {
@@ -499,18 +512,20 @@ export function convertValuesRecursive(
group: FormGroup,
) {
Object.entries(configSpec).forEach(([key, valueSpec]) => {
const control = group.get(key)
if (!control) return
if (valueSpec.type === 'number') {
const control = group.get(key)
control.setValue(control.value ? Number(control.value) : null)
} else if (valueSpec.type === 'string') {
const control = group.get(key)
if (!control.value) control.setValue(null)
} else if (valueSpec.type === 'object') {
convertValuesRecursive(valueSpec.spec, group.get(key) as FormGroup)
} else if (valueSpec.type === 'union') {
const control = group.get(key) as FormGroup
const spec = valueSpec.variants[control.controls[valueSpec.tag.id].value]
convertValuesRecursive(spec, control)
const formGr = group.get(key) as FormGroup
const spec = valueSpec.variants[formGr.controls[valueSpec.tag.id].value]
convertValuesRecursive(spec, formGr)
} else if (valueSpec.type === 'list') {
const formArr = group.get(key) as FormArray
const { controls } = formArr