Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 2, 2021
0 parents commit 22a1224
Show file tree
Hide file tree
Showing 57 changed files with 1,437 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Logs
logs
*.log
npm-debug.log*

# Bootstrap scripts folder
.bootstrap

# npm
node_modules
package-lock.json

# env
.env*
!.env.example

# temp
/__temp*

# build
/build


15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"parser": "typescript",
"printWidth": 80,
"proseWrap": "preserve",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
}
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch TS",
"program": "${file}",
"preLaunchTask": "tsc: build - tsconfig.json",
"envFile": "${workspaceFolder}/.env",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Launch JS",
"program": "${file}",
"envFile": "${workspaceFolder}/.env",
"internalConsoleOptions": "openOnSessionStart"
},
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Makeev Vitaliy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# moysklad-api-model

> Объектная модель сервиса МойСклад для TypeScript проектов
Экспериментальная версия
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "moysklad-api-model",
"version": "0.1.0",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "tsc --build tsconfig.prod.json",
"build": "rm -rf build/ && npm run compile"
},
"keywords": [
"moysklad",
"model",
"api",
"typescript"
],
"author": {
"name": "Vitaliy V. Makeev",
"email": "w.makeev@gmail.com"
},
"license": "MIT",
"devDependencies": {
"moysklad": "^0.9.2",
"moysklad-extension-queue": "^0.2.1",
"prettier": "^2.2.1",
"typescript": "^4.1.3"
}
}
31 changes: 31 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @ts-nocheck

import type { EntityByMetaType, MetaType } from './model/MetaType'
import type { PositionTypeByDocument } from './model/Position'

type EntityCollectionEndpoint<T extends MetaType> = `entity/${T}`
// type EntityCollectionEndpoint2 = `entity/${MetaType}`

type EntityEndpoint = `entity/${MetaType}/${string}`

type PositionsEndpoint = `entity/${keyof PositionTypeByDocument}/${string}/positions`
type CounterpartyContactPersonsEndpoint = `entity/${MetaType.Counterparty}/${string}/contactpersons`

export type EntityByEndpoint<T extends string> = string extends T
? 'unknown1'
: T extends `entity/${infer M}`
? M extends keyof EntityByMetaType
? EntityByMetaType[M]
: M
: 'never3'

type Test1 = EntityByEndpoint<'entity/account'>
type Test2 = EntityByMetaType['bonusprogram']

type Keys = keyof EntityByMetaType // MetaType
type Keys2 = `${MetaType}`
type Keys3 = keyof typeof MetaType

type Test3 = 'account' extends keyof EntityByMetaType ? true : false
type Test4 = 'account' extends Keys2 ? true : false
type Test5 = 'account' extends keyof typeof MetaType ? true : false
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model'
23 changes: 23 additions & 0 deletions src/model/Account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Entity } from './Entity'
import type { HasUpdated } from './HasUpdated'
import type { MetaType } from './MetaType'

export interface Account extends Entity<MetaType.Account>, HasUpdated {
/** Является ли счет основным счетом Контрагента */
isDefault: boolean

/** Номер счета */
accountNumber: string

/** Наименование банка */
bankName?: string

/** Адрес банка */
bankLocation?: string

/** Кор. счет */
correspondentAccount?: string

/** БИК */
bic?: string
}
22 changes: 22 additions & 0 deletions src/model/Address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { EntityRef } from './EntityRef'
import type { MetaType } from './MetaType'

export interface Address {
postalCode?: string

country?: EntityRef<MetaType.Country>

region?: EntityRef<MetaType.Region>

city?: string

street?: string

house?: string

apartment?: string

addInfo?: string

comment?: string
}
39 changes: 39 additions & 0 deletions src/model/Agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { Entity } from './Entity'
import type { HasAttributes } from './HasAttributes'
import type { HasCreated } from './HasCreated'
import type { HasUpdated } from './HasUpdated'
import type { MetaType } from './MetaType'
import type { Owned } from './Owned'

export type AgentMetaType =
| MetaType.Employee
| MetaType.Counterparty
| MetaType.Organization

export interface Agent<T extends AgentMetaType>
extends Entity<T>,
Owned,
HasCreated,
HasUpdated,
HasAttributes {
/** Наименование */
name: string

/** Комментарий */
description?: string

/** Внешний код */
externalCode: string

/** Архивирован */
archived: boolean

/** ИНН */
inn?: string

/** Email */
email?: string

/** Номер телефона */
phone?: string
}
12 changes: 12 additions & 0 deletions src/model/AgentNote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { HasCreated } from './HasCreated'
import type { MetaType } from './MetaType'

export interface AgentNote extends Entity<MetaType.Note>, HasCreated {
description?: string

agent: EntityRef<MetaType.Counterparty>

author: EntityRef<MetaType.Employee>
}
76 changes: 76 additions & 0 deletions src/model/Attribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { MediaType } from './MediaType'
import type { MetaType } from './MetaType'

export enum AttributeType {
// Base type
String = 'string',
Long = 'long',
Time = 'time',
File = 'file',
Double = 'double',
Boolean = 'boolean',
Text = 'text',
Link = 'link',

// Embedded entity
Organization = 'organization',
Counterparty = 'counterparty',
Employee = 'employee',
Contract = 'contract',
Product = 'product',
Project = 'project',
Store = 'store',

// Custom entity
CustomEntity = 'customentity'
}

export type AttributeJsTypeMap = {
// Base type
[AttributeType.String]: string
[AttributeType.Long]: number
[AttributeType.Time]: string
[AttributeType.File]: object // TODO AttributeType.File
[AttributeType.Double]: number
[AttributeType.Boolean]: boolean
[AttributeType.Text]: string
[AttributeType.Link]: string

// Embedded entity
[AttributeType.Organization]: EntityRef<MetaType.Organization>
[AttributeType.Counterparty]: EntityRef<MetaType.Counterparty>
[AttributeType.Employee]: EntityRef<MetaType.Employee>
[AttributeType.Contract]: EntityRef<MetaType.Contract>
[AttributeType.Product]: EntityRef<MetaType.Product>
[AttributeType.Project]: EntityRef<MetaType.Project>
[AttributeType.Store]: EntityRef<MetaType.Store>

// Custom entity
[AttributeType.CustomEntity]: EntityRef<MetaType.CustomEntity> & {
name: string
}
}

interface AttributeBase<T extends AttributeType = AttributeType>
extends Entity<MetaType.AttributeMetadata> {
/** Наименование пользовательского поля */
name: string

/** Тип значения пользовательского поля */
type: T

value: AttributeJsTypeMap[T]
}

export type Attribute<
T extends AttributeType = AttributeType
> = T extends AttributeType.File
? AttributeBase<T> & {
download: {
href: string
mediaType: MediaType
}
}
: AttributeBase<T>
7 changes: 7 additions & 0 deletions src/model/Collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { CollectionRef } from './CollectionRef'
import type { EntityByMetaType, MetaType } from './MetaType'

export interface Collection<T extends MetaType = MetaType>
extends CollectionRef<T> {
rows: EntityByMetaType[T][]
}
11 changes: 11 additions & 0 deletions src/model/CollectionRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { EntityRef } from './EntityRef'
import type { MetaType } from './MetaType'

export interface CollectionRef<T extends MetaType = MetaType>
extends EntityRef<T> {
meta: EntityRef<T>['meta'] & {
size: number
limit: number
offset: number
}
}
Loading

0 comments on commit 22a1224

Please sign in to comment.