From e0593055d70d92a431be7122a84bd208bf232e12 Mon Sep 17 00:00:00 2001 From: Juan Cazala Date: Thu, 25 Nov 2021 13:35:27 -0300 Subject: [PATCH] feat: add Store schema --- package.json | 2 +- report/schemas.api.md | 27 +++++++++++++++++ src/dapps/store.ts | 69 +++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 5 ++-- test/store.spec.ts | 32 ++++++++++++++++++++ 5 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/dapps/store.ts create mode 100644 test/store.spec.ts diff --git a/package.json b/package.json index 85ac40b9..13d3d6c7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/report/schemas.api.md b/report/schemas.api.md index 5ffe1569..f43f2d97 100644 --- a/report/schemas.api.md +++ b/report/schemas.api.md @@ -1067,6 +1067,33 @@ export namespace SpawnPoint { validate: ValidateFunction; } +// 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; + const // (undocumented) + validate: ValidateFunction; +} + // Warning: (tsdoc-missing-deprecation-message) The @deprecated block must include a deprecation message, e.g. describing the recommended alternative // // @internal @deprecated (undocumented) diff --git a/src/dapps/store.ts b/src/dapps/store.ts new file mode 100644 index 00000000..63d22069 --- /dev/null +++ b/src/dapps/store.ts @@ -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 = { + 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 = generateValidator(schema) +} diff --git a/src/index.ts b/src/index.ts index 4d114d8c..201e2da9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' @@ -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' diff --git a/test/store.spec.ts b/test/store.spec.ts new file mode 100644 index 00000000..bbec3d24 --- /dev/null +++ b/test/store.spec.ts @@ -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) + }) +})