Skip to content

Commit

Permalink
added metadata schema for amulet-20210221, first pass (#18)
Browse files Browse the repository at this point in the history
* added metadata schema for amulet-20210221, first pass

* fixing typo in amulet rarities

* fixes to amulet schema, added 20280228 version

* a few fixes to the tests for amulet schema

* removed amulet 20210228 version

* cleaning up removal of amulet-20210228, oops

* added string type to carbonOffsetURL in amulet schema

Co-authored-by: Robin Sloan <robin@robinsloan.com>
  • Loading branch information
robinsloan and robinsloan authored Jun 4, 2021
1 parent 45f5a47 commit a4dbda5
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 3 deletions.
75 changes: 75 additions & 0 deletions schemas/amulet/20210221.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"description": "This schema describes version 20210221 of the metadata standard for the amulet poem format, designed for the Zora protocol.",
"title": "Amulet20210221",
"$id": "http://text.bargains/schema.json",
"type": "object",
"properties": {
"carbonOffsetURL": {
"description": "An HTTPS link to the carbon offset purchased in this poem's name. This is not required in this metadata version, but if it is not specified in this field, it should be included in the `description` field.",
"examples": [
"https://dashboard.cloverly.com/receipt/20210223-9e38b918ecfd9bfb051287bf71556736"
],
"type": "string"
},
"description": {
"description": "The description of the amulet. You can feel free to have fun & be evocative with this; including a link to the current formal definition is probably wise, but not required.",
"examples": [
"This is an amulet, a short poem with a lucky SHA-256 hash, explained here: https://text.bargains/ This poem's rarity is COMMON. Here is this poem's carbon offset: https://dashboard.cloverly.com/receipt/20210223-9e38b918ecfd9bfb051287bf71556736"
],
"type": "string"
},
"mimeType": {
"description": "The mimeType of the amulet. This will always be text/plain.",
"examples": [
"text/plain"
],
"type": "string",
"enum": ["text/plain"]
},
"name": {
"description": "The title of the amulet.",
"examples": [
"morning amulet"
],
"type": "string"
},
"poemText": {
"description": "The text of the amulet. You should include this if possible, but, in this metadata version, it's not formally required. The text at the contentURI in the Zora NFT is considered the canonical version.",
"examples": [
"DON'T WORRY."
],
"type": "string"
},
"rarity": {
"description": "The rarity level of the amulet.",
"examples": [
"common"
],
"type": "string",
"enum": ["common", "uncommon", "rare", "epic", "legendary", "mythic", "beyond mythic"]
},
"version": {
"description": "The calendar version of the schema.",
"const": "amulet-20210221",
"type": "string"
}
},
"additionalProperties": true,
"examples": [
{
"description": "This is an amulet, a short poem with a lucky SHA-256 hash, explained here: https://text.bargains/ This poem's rarity is COMMON. Here is this poem's carbon offset: https://dashboard.cloverly.com/receipt/20210223-9e38b918ecfd9bfb051287bf71556736",
"mimeType": "text/plain",
"name": "morning amulet",
"poemText": "DON'T WORRY.",
"rarity": "common",
"version": "amulet-20210221"
}
],
"required": [
"description",
"mimeType",
"name",
"rarity",
"version"
]
}
6 changes: 5 additions & 1 deletion src/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*/
export const supportedVersions: { [key: string]: Array<string> } = {
zora: ['20210101'],
catalog: ['20210202']
catalog: ['20210202'],
amulet: ['20210221']
}

/**
Expand All @@ -17,6 +18,9 @@ export const supportedVersionsTypeMapping: {
},
catalog: {
'20210202': 'Catalog20210202'
},
amulet: {
'20210221': 'Amulet20210221'
}
}

Expand Down
48 changes: 47 additions & 1 deletion tests/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('schemas', () => {
const result = validator.validate(json)
expect(result).toBe(false)
})

it('requires the correct Catalog schema version', () => {
const validator = new Validator('catalog-20210202')
const json = {
Expand Down Expand Up @@ -436,4 +436,50 @@ describe('schemas', () => {
})
})
})

describe('amulet', () => {
describe('20210221', () => {
it('requires all keys', () => {
const validator = new Validator('amulet-20210221')
const json = {
description: 'it is an amulet, what do you want from me!',
mimeType: 'text/plain',
name: 'a fine amulet',
}

const result = validator.validate(json)
expect(result).toBe(false)
})

it('cannot be assigned a random rarity', () => {
const validator = new Validator('amulet-20210221')
const json = {
version: 'amulet-20210221',
description: 'it is an amulet, what do you want from me!',
mimeType: 'text/plain',
name: 'a fine amulet',
rarity: 'hyperrare'
}

const result = validator.validate(json)
expect(result).toBe(false)
})

it('must be of mimeType text/plain', () => {
const validator = new Validator('amulet-20210221')
const json = {
version: 'amulet-20210101',
carbonOffsetURL: 'https://dashboard.cloverly.com/receipt/20210223-9e38b918ecfd9bfb051287bf71556736',
description: 'it is a picture of an amulet',
mimeType: 'image/jpeg',
name: 'pic of my amulet',
poemText: 'DON\'T WORRY.',
rarity: 'common'
}

const result = validator.validate(json)
expect(result).toBe(false)
})
})
})
})
41 changes: 41 additions & 0 deletions types/amulet/20210221.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

/**
* This schema describes version 20210221 of the metadata standard for the amulet poem format, designed for the Zora protocol.
*/
export interface Amulet20210221 {
/**
* An HTTPS link to the carbon offset purchased in this poem's name. This is not required in this metadata version, but if it is not specified in this field, it should be included in the `description` field.
*/
carbonOffsetURL?: string;
/**
* The description of the amulet. You can feel free to have fun & be evocative with this; including a link to the current formal definition is probably wise, but not required.
*/
description: string;
/**
* The mimeType of the amulet. This will always be text/plain.
*/
mimeType: "text/plain";
/**
* The title of the amulet.
*/
name: string;
/**
* The text of the amulet. You should include this if possible, but, in this metadata version, it's not formally required. The text at the contentURI in the Zora NFT is considered the canonical version.
*/
poemText?: string;
/**
* The rarity level of the amulet.
*/
rarity: "common" | "uncommon" | "rare" | "epic" | "legendary" | "mythic" | "beyond mythic";
/**
* The calendar version of the schema.
*/
version: "amulet-20210221";
[k: string]: unknown;
}
4 changes: 3 additions & 1 deletion types/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Zora20210101 } from './zora/20210101';
import { Catalog20210202 } from './catalog/20210202';
import { Amulet20210221 } from './amulet/20210221';

export { Zora20210101 }
export { Catalog20210202 }
export type MetadataLike = Zora20210101 | Catalog20210202;
export { Amulet20210221 }
export type MetadataLike = Zora20210101 | Catalog20210202 | Amulet20210221 ;

0 comments on commit a4dbda5

Please sign in to comment.