Skip to content

Commit

Permalink
feat(model)
Browse files Browse the repository at this point in the history
- State expand
- рефакторинг
  • Loading branch information
wmakeev committed Jul 2, 2021
1 parent a599fdc commit df9ab8c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 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.1.3",
"version": "0.1.4",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
29 changes: 17 additions & 12 deletions src/model/MetaType.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { Account } from './Account'
import type { AgentNote } from './AgentNote'
import type { ContactPerson } from './ContactPerson'
import type { Counterparty } from './Counterparty'
import type { CustomerOrder } from './CustomerOrder'
import type { Employee } from './Employee'
import type { Entity } from './Entity'
import type { Group } from './Group'
import type { Organization } from './Organization'
import type {
Account,
AgentNote,
ContactPerson,
Counterparty,
CustomerOrder,
Demand,
Employee,
Entity,
Group,
Organization,
RetailDemand,
State
} from '.'

export enum MetaType {
Account = 'account',
Expand Down Expand Up @@ -126,7 +131,7 @@ export type EntityByMetaType = {
[MetaType.CustomerOrder]: CustomerOrder
[MetaType.CustomerOrderPosition]: Entity<MetaType.CustomerOrderPosition>
[MetaType.CustomTemplate]: Entity<MetaType.CustomTemplate>
[MetaType.Demand]: Entity<MetaType.Demand>
[MetaType.Demand]: Demand
[MetaType.DemandPosition]: Entity<MetaType.DemandPosition>
[MetaType.Discount]: Entity<MetaType.Discount>
[MetaType.EmbeddedTemplate]: Entity<MetaType.EmbeddedTemplate>
Expand Down Expand Up @@ -173,7 +178,7 @@ export type EntityByMetaType = {
[MetaType.PurchaseReturn]: Entity<MetaType.PurchaseReturn>
[MetaType.PurchaseReturnPosition]: Entity<MetaType.PurchaseReturnPosition>
[MetaType.Region]: Entity<MetaType.Region>
[MetaType.RetailDemand]: Entity<MetaType.RetailDemand>
[MetaType.RetailDemand]: RetailDemand
[MetaType.RetailDrawerCashIn]: Entity<MetaType.RetailDrawerCashIn>
[MetaType.RetailDrawerCashOut]: Entity<MetaType.RetailDrawerCashOut>
[MetaType.RetailSalesReturn]: Entity<MetaType.RetailSalesReturn>
Expand All @@ -183,7 +188,7 @@ export type EntityByMetaType = {
[MetaType.SalesReturnPosition]: Entity<MetaType.SalesReturnPosition>
[MetaType.Service]: Entity<MetaType.Service>
[MetaType.SpecialPriceDiscount]: Entity<MetaType.SpecialPriceDiscount>
[MetaType.State]: Entity<MetaType.State>
[MetaType.State]: State
[MetaType.Store]: Entity<MetaType.Store>
[MetaType.Supply]: Entity<MetaType.Supply>
[MetaType.SupplyPosition]: Entity<MetaType.SupplyPosition>
Expand Down
2 changes: 2 additions & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Добавить новые сущности аналогично в MetaType.ts

export * from './Account'
export * from './Address'
export * from './Agent'
Expand Down
4 changes: 2 additions & 2 deletions test/model/CustomerOrder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CustomerOrder, CustomerOrderExpand } from '../..'
import { AttributeType, MediaType, MetaType, TaxSystem } from '../..'
import type { CustomerOrder, CustomerOrderExpand } from '../../src'
import { AttributeType, MediaType, MetaType, TaxSystem } from '../../src'

const customerOrderFull1: CustomerOrder = {
meta: {
Expand Down
6 changes: 4 additions & 2 deletions test/model/Expand.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CustomerOrder, Expand } from '../..'
import type { CustomerOrder, Expand } from '../../src'

// Expand EntityRef
const test1 = {} as Expand<CustomerOrder, 'agent'>
const test1 = {} as Expand<Expand<CustomerOrder, 'agent'>, 'state'>

test1.owner.meta
test1.agent.name // expand
Expand All @@ -10,6 +10,8 @@ test1.agent.group.name // ERROR: no 2-nd level expanded
// @ts-expect-error
test1.project?.id

test1.state?.name

const test2 = {} as Expand<CustomerOrder, 'agent.group'>

test2.agent.group.name // OK: 2-nd level expanded
2 changes: 1 addition & 1 deletion test/model/isType.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CustomerOrder, Demand, MetaType, RetailDemand } from '../../build/src'
import { CustomerOrder, Demand, MetaType, RetailDemand } from '../../src'
import { isType } from '../../src/tools'
import { getTypedVar } from '../tools'

Expand Down

0 comments on commit df9ab8c

Please sign in to comment.