Skip to content

Commit

Permalink
feat: add EntityRefAttributeType union
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 31, 2021
1 parent 886e33a commit 9c6f419
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moysklad-api-model",
"version": "0.4.3",
"version": "0.4.4",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
28 changes: 19 additions & 9 deletions src/model/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ export enum AttributeType {
CustomEntity = 'customentity'
}

/** Типы атрибутов, значение которых является сущностью (ссылкой на сущность) */
export type EntityRefAttributeType =
| AttributeType.Organization
| AttributeType.Counterparty
| AttributeType.Employee
| AttributeType.Contract
| AttributeType.Product
| AttributeType.Project
| AttributeType.Store
| AttributeType.CustomEntity

export type AttributeJsTypeMap = {
// Base type
[AttributeType.String]: string
Expand Down Expand Up @@ -63,16 +74,15 @@ export interface AttributeBase<T extends AttributeType = AttributeType>
value: AttributeJsTypeMap[T]
}

export type Attribute<
T extends AttributeType = AttributeType
> = T extends AttributeType.File
? AttributeBase<T> & {
readonly download: {
readonly href: string
readonly mediaType: MediaType
export type Attribute<T extends AttributeType = AttributeType> =
T extends AttributeType.File
? AttributeBase<T> & {
readonly download: {
readonly href: string
readonly mediaType: MediaType
}
}
}
: AttributeBase<T>
: AttributeBase<T>

export type AttributePatch<T extends AttributeType = AttributeType> =
| (EntityPatchRef<'attributemetadata'> & {
Expand Down

0 comments on commit 9c6f419

Please sign in to comment.