-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type DictionaryMetaType = | ||
| 'counterparty' | ||
| 'product' | ||
| 'productfolder' | ||
| 'variant' | ||
| 'project' | ||
| 'store' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { | ||
DocumentMetaType, | ||
DictionaryMetaType, | ||
AttributeType, | ||
Entity, | ||
CollectionRef, | ||
State | ||
} from '.' | ||
|
||
/** | ||
* Типы сущностей у которых есть метаданные | ||
*/ | ||
export type MetadataMetaType = DocumentMetaType | DictionaryMetaType | ||
|
||
export type MetadataMeta<T extends MetadataMetaType = MetadataMetaType> = { | ||
meta: { | ||
/** `https://online.moysklad.ru/api/remap/1.2/entity/product/metadata` */ | ||
href: `https://${string}/api/remap/1.2/entity/${T}/metadata` | ||
mediaType: 'application/json' | ||
} | ||
} | ||
|
||
export interface MetadataAttribute extends Entity<'attributemetadata'> { | ||
/** Наименование пользовательского поля */ | ||
readonly name: string | ||
|
||
/** Тип значения пользовательского поля */ | ||
readonly type: AttributeType | ||
|
||
readonly required: boolean | ||
|
||
readonly show: true | ||
} | ||
|
||
export type DocumentMetadata<T extends DocumentMetaType = DocumentMetaType> = | ||
MetadataMeta<T> & { | ||
attributes: CollectionRef<'attributemetadata'> | ||
states: State<T>[] | ||
createShared: boolean | ||
} | ||
|
||
// TODO | ||
export type DictionaryMetadata< | ||
T extends DictionaryMetaType = DictionaryMetaType | ||
> = MetadataMeta<T> & { | ||
attributes: CollectionRef<'attributemetadata'> | ||
createShared: boolean | ||
} & (T extends 'counterparty' ? { states: State<T>[] } : {}) | ||
|
||
// prettier-ignore | ||
|
||
export type Metadata<T extends MetadataMetaType> = | ||
// Документы | ||
T extends DocumentMetaType | ||
? DocumentMetadata<T> | ||
|
||
// Справочники | ||
: T extends DictionaryMetaType | ||
? T extends 'project' | 'store' | 'product' | 'counterparty' | ||
? DictionaryMetadata<T> | ||
|
||
// Пустые метаданные | ||
: MetadataMeta<T> | ||
|
||
: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { expectType } from 'tsd' | ||
import type { CollectionRef, Metadata, State } from '../../src' | ||
|
||
// @ts-expect-error account не имеет метаданных | ||
const t0 = {} as Metadata<'account'> | ||
|
||
// Document | ||
|
||
const t1 = {} as Metadata<'demand'> | ||
|
||
expectType<`https://${string}/api/remap/1.2/entity/demand/metadata`>( | ||
t1.meta.href | ||
) | ||
|
||
expectType<CollectionRef<'attributemetadata'>>(t1.attributes) | ||
|
||
expectType<State<'demand'>>(t1.states[0]) | ||
|
||
expectType<boolean>(t1.createShared) | ||
|
||
// Dictionary | ||
|
||
const t3 = {} as Metadata<'product'> | ||
|
||
expectType<CollectionRef<'attributemetadata'>>(t3.attributes) | ||
|
||
// @ts-expect-error | ||
t3.states | ||
|
||
expectType<boolean>(t3.createShared) | ||
|
||
// Counterparty | ||
|
||
const t4 = {} as Metadata<'counterparty'> | ||
|
||
expectType<CollectionRef<'attributemetadata'>>(t4.attributes) | ||
|
||
expectType<State<'counterparty'>>(t4.states[0]) | ||
|
||
expectType<boolean>(t3.createShared) | ||
|
||
// Other | ||
|
||
const t5 = {} as Metadata<'variant'> | ||
|
||
// @ts-expect-error | ||
t5.attributes | ||
|
||
// @ts-expect-error | ||
t5.states | ||
|
||
// @ts-expect-error | ||
t5.createShared | ||
|
||
expectType<`https://${string}/api/remap/1.2/entity/variant/metadata`>( | ||
t5.meta.href | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters