Skip to content

Commit

Permalink
feat: add Store schema
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Nov 25, 2021
1 parent 1d0a8ae commit e059305
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"check-api": "api-extractor run --typescript-compiler-folder ./node_modules/typescript",
"refresh-api": "api-extractor run --local --verbose --diagnostics --typescript-compiler-folder ./node_modules/typescript"
"refresh-api": "npm run build && api-extractor run --local --verbose --diagnostics --typescript-compiler-folder ./node_modules/typescript"
},
"devDependencies": {
"@dcl/eslint-config": "^1.0.0",
Expand Down
27 changes: 27 additions & 0 deletions report/schemas.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,33 @@ export namespace SpawnPoint {
validate: ValidateFunction<SpawnPoint>;
}

// Warning: (ae-missing-release-tag) "Store" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
// Warning: (ae-missing-release-tag) "Store" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type Store = {
id: string;
owner: string;
description: string;
links: {
name: string;
url: string;
}[];
images: {
name: string;
file: string;
}[];
version: number;
};

// @public (undocumented)
export namespace Store {
const // (undocumented)
schema: JSONSchema<Store>;
const // (undocumented)
validate: ValidateFunction<Store>;
}

// Warning: (tsdoc-missing-deprecation-message) The @deprecated block must include a deprecation message, e.g. describing the recommended alternative
//
// @internal @deprecated (undocumented)
Expand Down
69 changes: 69 additions & 0 deletions src/dapps/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { generateValidator, JSONSchema, ValidateFunction } from '../validation'

export type Store = {
id: string // urn
owner: string
description: string
links: {
name: string
url: string
}[]
images: {
name: string
file: string
}[]
version: number
}

export namespace Store {
export const schema: JSONSchema<Store> = {
type: 'object',
properties: {
id: {
type: 'string',
},
version: {
type: 'number',
},
owner: {
type: 'string',
},
description: {
type: 'string',
},
links: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
url: {
type: 'string',
},
},
required: ['name', 'url'],
},
},
images: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
file: {
type: 'string',
},
},
required: ['name', 'file'],
},
},
},
required: ['id', 'version', 'owner', 'description', 'links', 'images'],
}

export const validate: ValidateFunction<Store> = generateValidator(schema)
}
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export { ChainName, getChainId } from './dapps/chain-name'
export {
Collection,
CollectionFilters,
CollectionSortBy
CollectionSortBy,
} from './dapps/collection'
export { Contract, ContractFilters, ContractSortBy } from './dapps/contract'
export { Item, ItemFilters, ItemSortBy } from './dapps/item'
Expand All @@ -25,13 +25,14 @@ export { Order, OrderFilters, OrderSortBy } from './dapps/order'
export { Rarity } from './dapps/rarity'
export { SaleType } from './dapps/sale-type'
export { Sale, SaleFilters, SaleSortBy } from './dapps/sale'
export { Store } from './dapps/store'
export { WearableCategory } from './dapps/wearable-category'
export { WearableGender } from './dapps/wearable-gender'
export {
World,
ValidWorldRange,
getWorld,
isInsideWorldLimits
isInsideWorldLimits,
} from './dapps/world'

export * from './platform'
Expand Down
32 changes: 32 additions & 0 deletions test/store.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import expect from 'expect'
import { Store } from '../src'
import { testTypeSignature } from './test-utils'

describe('Contract tests', () => {
const store: Store = {
id: 'urn:decentraland:marketplace:store:0xe592427a0aece92de3edee1f18e0157c05861564',
description: 'Some store',
owner: '0xe592427a0aece92de3edee1f18e0157c05861564',
links: [
{
name: 'Discord',
url: 'discord.com/some-store',
},
],
images: [
{
name: 'banner',
file: 'banner.png',
},
],
version: 1,
}

testTypeSignature(Store, store)

it('static tests must pass', () => {
expect(Store.validate(store)).toEqual(true)
expect(Store.validate(null)).toEqual(false)
expect(Store.validate({})).toEqual(false)
})
})

0 comments on commit e059305

Please sign in to comment.