Skip to content

Commit

Permalink
Removed Enumerations in favor of Union Types
Browse files Browse the repository at this point in the history
  • Loading branch information
KirianCaumes committed Feb 11, 2023
1 parent 1824414 commit da49c36
Show file tree
Hide file tree
Showing 50 changed files with 2,461 additions and 3,125 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
rules: {
'@typescript-eslint/indent': ['warn', 4],
'@typescript-eslint/semi': ['warn', 'never'],
'@typescript-eslint/consistent-type-definitions': ['warn', 'type'],
'@typescript-eslint/member-delimiter-style': ['error', { multiline: { delimiter: 'none' }, singleline: { delimiter: 'comma' } }],
'@typescript-eslint/naming-convention': [
'error',
Expand Down
208 changes: 111 additions & 97 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,69 @@ const DiscogsMarketplace = require('discogs-marketplace-api-nodejs').default
- Get top 250 items, of the 2nd page, filtered by Rock, listed by newest, for a given artist

```js
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'

// https://www.discogs.com/sell/list?sort=listed,desc&limit=250&artist_id=244819&page=2&genre=Rock
const result = await DiscogsMarketplace.search({
limit: 250,
page: 2,
genre: EGenre.ROCK,
sort: ESort.LISTED_NEWEST,
searchType: EType.ARTIST,
genre: 'Rock',
sort: 'Listed Newest',
searchType: 'artist_id',
searchValue: 244819,
})
```

- Get top 50 items, of the 1st page, listed by price lowest, on a user wantlist

```js
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'

// https://www.discogs.com/sell/mywants?limit=50&user=Kirian_&sort=price,asc
const result = await DiscogsMarketplace.search({
limit: 50,
sort: ESort.PRICE_LOWEST,
searchType: EType.USER,
sort: 'Price Lowest',
searchType: 'user',
searchValue: 'Kirian_',
})
```

- Get top 25 items, of the 1st page, listed by seller A-Z, on a release

```js
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'

// https://www.discogs.com/sell/release/767931?sort=seller,asc&limit=25&page=1
const result = await DiscogsMarketplace.search({
sort: ESort.SELLER_AZ,
searchType: EType.RELEASE,
sort: 'Seller A-Z',
searchType: 'release_id',
searchValue: '767931',
})
```

- Get top 100 items, of the 1st page, listed by newest, on a string search

```js
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'

// https://www.discogs.com/sell/list?sort=listed,desc&limit=100&q=in+flames&page=1
const result = await DiscogsMarketplace.search({
limit: 100,
sort: ESort.LISTED_NEWEST,
searchType: EType.STRING,
sort: 'Listed Newest',
searchType: 'q',
searchValue: 'in flames',
})
```

- Get top 25 items, of the 1st page, listed by newest, on a seller inventory

```js
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'

// https://www.discogs.com/seller/Kirian_/profile?sort=listed,desc&limit=25&page=1
const result = await DiscogsMarketplace.search({
sort: ESort.LISTED_NEWEST,
searchType: EType.STRING,
sort: 'Listed Newest',
searchType: 'q',
searchValue: '',
seller: 'Kirian_',
})
Expand All @@ -98,103 +98,166 @@ const result = await DiscogsMarketplace.search({
- Get top 25 items, of the 1st page, listed by newest, on a user wantlist, on a seller inventory

```js
import DiscogsMarketplace, { EType } from 'discogs-marketplace-api-nodejs'
import DiscogsMarketplace from 'discogs-marketplace-api-nodejs'

// https://www.discogs.com/seller/Kirian_/mywants?sort=listed,desc&limit=25&user=Kirian_&page=1
const result = await DiscogsMarketplace.search({
sort: ESort.LISTED_NEWEST,
searchType: EType.USER,
sort: 'Listed Newest',
searchType: 'user',
searchValue: 'Kirian_',
seller: 'Kirian_',
})
```

## Data format

You can provide parameters to `DiscogsMarketplace.search` function according to this interface:
You can provide parameters to `DiscogsMarketplace.search` function according to this type:

```ts
interface IInput {
type InputCommonType = {
/**
* Type of elements to search
* Type of elements to search.
* Default to `q`.
* | Name | Description |
* |:---------: |:--------------------------:|
* | q | Basic query search |
* | master_id | Search in a master release |
* | release_id | Search in a release |
* | label_id | Search in a label |
* | artist_id | Search in a artist |
* | user | Search in user wantlist |
*/
searchType: EType,
searchType: SearchTypeType
/**
* Value to search corresponding to searchType
*/
searchValue: string | number | undefined,
searchValue: string | number | undefined
/**
* Currency
*/
currency?: ECurrency,
currency?: CurrencyType
/**
* Genre
*/
genre?: EGenre,
genre?: GenreType
/**
* Styles
*/
style?: EStyle[]
style?: StyleType[]
/**
* Formats
*/
format?: EFormat[]
format?: FormatType[]
/**
* Format descriptions
*/
formatDescription?: EFormatDescription[]
formatDescription?: FormatDescriptionType[]
/**
* Media conditions
*/
mediaCondition?: EMediaCondition[]
condition?: ConditionType[]
/**
* Year (Do not use it with years)
* Year (Do not use it with `years`)
*/
year?: number,
year?: number
/**
* Interval of years (Do not use it with year)
* Interval of years (Do not use it with `year`)
*/
years?: IYears,
years?: {
/** Min */
min: number
/** Max */
max: number
}
/**
* Is audio sample ?
*/
isAudioSample?: boolean,
isAudioSample?: boolean
/**
* Is make an offer only ?
*/
isMakeAnOfferOnly?: boolean,
isMakeAnOfferOnly?: boolean
/**
* Expedition country
*/
from?: EFrom,
from?: FromType
/**
* Seller name
*/
seller?: string,
seller?: string
/**
* Sort elements by
*/
sort?: ESort,
sort?: SortType
/**
* Limit of elements to search (25 | 50 | 100 | 250)
*/
limit?: LimitType,
limit?: LimitType
/**
* Page (Must be < 401 or discogs will return an error 404)
* Page (Must be < 401 or discogs will return an error 404).
* Default to `25`.
*/
page?: number,
page?: number
/**
* Lang to use for Discogs
* Lang to use for Discogs.
* Default to `en`.
*/
lang?: ELang
lang?: LangType
}
```
If success, it will return:
```ts
interface IOutputSuccess {
items: IItem[]
type OutputSuccessType = {
items: {
id: number
title: {
original: string
artist: string
item: string
formats: string[]
}
url: string
labels: string[]
catnos: string[]
imageUrl: string
description: string
isAcceptingOffer: boolean
isAvailable: boolean
condition: {
media: {
full: string
short: string
}
sleeve: {
full: string
short: string
}
}
seller: {
name: string
url: string
score: string
notes: number
}
price: {
base: string
shipping: string
}
country: {
name: string
code: ECountryCode
}
community: {
have: number
want: number
}
release: {
id: number
url: string
}
}[]
page: {
current: number
total: number
Expand All @@ -205,65 +268,16 @@ interface IOutputSuccess {
}
search: {
value: string | number
type: EType
type: SearchTypeType
}
urlGenerated: string
}

interface IItem {
id: number
title: {
original: string
artist: string
item: string
formats: string[]
}
url: string
labels: string[]
catnos: string[]
imageUrl: string
description: string
isAcceptingOffer: boolean
isAvailable: boolean
condition: {
media: {
full: string
short: string
}
sleeve: {
full: string
short: string
}
}
seller: {
name: string
url: string
score: string
notes: number
}
price: {
base: string
shipping: string
}
country: {
name: string
code: ECountryCode
}
community: {
have: number
want: number
}
release: {
id: number
url: string
}
}
```
If error, it will throw:
```ts
interface IOutputError {
type OutputErrorType = {
message: string
code: number
}
Expand Down
Loading

0 comments on commit da49c36

Please sign in to comment.