Skip to content

Commit

Permalink
feat: add Id type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 20, 2021
1 parent 399add4 commit 2d499b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 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.2.8",
"version": "0.2.9",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/model/Id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Id = string
29 changes: 15 additions & 14 deletions src/model/api/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EntityByMetaType, DocumentWithPositionsMetaType } from '..'
import type { EntityByMetaType, DocumentWithPositionsMetaType, Id } from '..'
import type { Collection } from '../Collection'
import type { CompanyMetaType } from '../Company'
import type { Document, DocumentMetaType } from '../Document'
import type { Meta } from '../Meta'
import type { Expand, Patch, PatchCollection, Template } from '../utils'
Expand All @@ -10,28 +11,28 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
export type HttpMethodPath = {
GET:
| `audit`
| `audit/${string}`
| `audit/${string}/events`
| `audit/${Id}`
| `audit/${Id}/events`
| `context/employee`
| `download/${string}`
| `download/${Id}`
| `entity/assortment`
| `entity/customentity/${string}`
| `entity/customentity/${Id}`
| `entity/${CompanyMetaType}/${Id}/accounts`
| `entity/${DomineEntityMetaType}` // +
| `entity/${DomineEntityMetaType}/metadata`
| `entity/${DomineEntityMetaType}/metadata/attributes`
| `entity/${DomineEntityMetaType}/${string}`
| `entity/${DocumentWithPositionsMetaType}/${string}/positions`
| `entity/${DocumentWithPositionsMetaType}/${string}/positions/${string}`
| `entity/${DomineEntityMetaType}/${Id}`
| `entity/${DocumentWithPositionsMetaType}/${Id}/positions`
| `entity/${DocumentWithPositionsMetaType}/${Id}/positions/${Id}`

POST:
| `entity/${DomineEntityMetaType}`
| `entity/${DocumentWithPositionsMetaType}/${string}/positions`
| `entity/${DocumentWithPositionsMetaType}/${Id}/positions`

PUT:
| `entity/${DomineEntityMetaType}/${string}`
| `entity/${DocumentMetaType}/new` // TODO Какие точно типы поддерживают new
// TODO Какие точно типы поддерживают new?
PUT: `entity/${DomineEntityMetaType}/${Id}` | `entity/${DocumentMetaType}/new`

DELETE: `entity/${DomineEntityMetaType}/${string}`
DELETE: `entity/${DomineEntityMetaType}/${Id}`
}

export type EndpointInterfaceInfo<
Expand All @@ -54,7 +55,7 @@ export type EndpointInterface<
? EndpointInterfaceInfo<unknown, unknown, undefined>

// entity/{type}/{..}
: Endpoint extends `entity/${infer EntityType}/${string}`
: Endpoint extends `entity/${infer EntityType}/${Id}`
? EntityType extends DomineEntityMetaType
// GET entity/{type}/{id}
? Method extends 'GET'
Expand Down
1 change: 1 addition & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from './PriceType'
export * from './RetailDemand'
export * from './State'
export * from './TaxSystem'
export * from './Id'

// Utility types
export * from './utils'
Expand Down

0 comments on commit 2d499b4

Please sign in to comment.