Skip to content

Commit

Permalink
fix(Attribute): AttributePatch
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Aug 2, 2021
1 parent 9c6f419 commit 43578a2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/model/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,22 @@ export type Attribute<T extends AttributeType = AttributeType> =
}
: AttributeBase<T>

// TODO Попробовать оптимизировать см. #dhg06qfl

// prettier-ignore

export type AttributePatch<T extends AttributeType = AttributeType> =
| (EntityPatchRef<'attributemetadata'> & {
file: {
T extends AttributeType.File
? EntityPatchRef<'attributemetadata'> & {
file?: {
filename: string
content: string
}
})
| (EntityPatchRef<'attributemetadata'> & Partial<Pick<Attribute<T>, 'value'>>)
}

: T extends AttributeType.CustomEntity
? EntityPatchRef<'attributemetadata'> & {
value: EntityRef<'customentity'>
}

: EntityPatchRef<'attributemetadata'> & Partial<Pick<Attribute<T>, 'value'>>
22 changes: 21 additions & 1 deletion test/model/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Patch, PrefilledDocument } from '../../src'
import type { EntityRef, Patch, PrefilledDocument } from '../../src'
import { testTypeEqual } from '../tools'

const customerorder: Patch<'customerorder'> = {}
Expand All @@ -11,3 +11,23 @@ invoiceOut.positions?.[0].price
invoiceOut.customerOrder
invoiceOut.store
invoiceOut.paymentPlannedMoment

//#region
const t10_1 = {} as EntityRef<'attributemetadata'> & {
value: EntityRef<'customentity'>
}

const t10_2: Patch<'customerorder'> = {
attributes: [
t10_1,
{
meta: {
type: 'attributemetadata',
href: ''
},
value: 123
}
]
}
t10_2
//#endregion
20 changes: 16 additions & 4 deletions test/model/utils/Patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ t1.attributes = [
type: 'attributemetadata',
href: ''
},
value: '',
file: { filename: '', content: '' }
},
{
Expand All @@ -77,8 +76,8 @@ t1.attributes = [
]

t1.attributes = [
// @ts-expect-error
{
// @ts-expect-error
value: ''
}
]
Expand All @@ -90,17 +89,30 @@ t1.attributes = [
}
]

// TODO Нужно оптимизировать проверку типа в attributes #dhg06qfl ..
// .. не понятная ошибка, когда указано лишнее поле

t1.attributes = [
{
meta: {
type: 'attributemetadata',
href: ''
},
// @ts-expect-error
name: '',
// foo: '', // #dhg06qfl
value: ''
}
]

t1.attributes = [
{
meta: {
type: 'attributemetadata',
href: ''
},
// foo: '', // #dhg06qfl
value: { meta: { type: 'customentity', href: '' } }
}
]
//#endregion

//#region Патч коллекции
Expand Down

0 comments on commit 43578a2

Please sign in to comment.