Skip to content

Commit

Permalink
ran prettier for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
dsoskey committed Jan 21, 2023
1 parent 1058f8a commit 0ce7829
Show file tree
Hide file tree
Showing 37 changed files with 1,746 additions and 1,383 deletions.
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"jsxSingleQuote": true
"jsxSingleQuote": true,
"semi": false
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ git clone git+https://github.com/dsoskey/cogwork-librarian.git
cd cogwork-librarian
npm install
npm run dev-server
```
```
6 changes: 3 additions & 3 deletions config/development.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReefClientConfig, Stage } from '.';
import { ReefClientConfig, Stage } from '.'

const config: ReefClientConfig = {
stage: Stage.Dev,
apiUrl: 'http://127.0.0.1:1337',
};
}

export default config;
export default config
4 changes: 2 additions & 2 deletions config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export enum Stage {
Prod = 'Prod',
}
export interface ReefClientConfig {
stage: Stage;
apiUrl: string;
stage: Stage
apiUrl: string
}
6 changes: 3 additions & 3 deletions config/production.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReefClientConfig, Stage } from '.';
import { ReefClientConfig, Stage } from '.'

const config: ReefClientConfig = {
stage: Stage.Prod,
apiUrl: 'http://api.reef.sosk.watch',
};
}

export default config;
export default config
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ module.exports = {
transform: {
'tsx?$': ['@swc/jest'],
},
};
}
141 changes: 78 additions & 63 deletions src/api/card.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,92 @@
import {Card} from "scryfall-sdk";
import {ObjectValues} from "../types";
import { Card } from 'scryfall-sdk'
import { ObjectValues } from '../types'

export const DOUBLE_FACED_LAYOUTS = ['transform', 'modal_dfc', 'meld', 'double_sided', 'double_faced_token']
export const DOUBLE_FACED_LAYOUTS = [
'transform',
'modal_dfc',
'meld',
'double_sided',
'double_faced_token',
]

export const BASIC_LAND_TYPES = ['plains', 'island', 'swamp', 'mountain', 'forest']
export const BASIC_LAND_TYPES = [
'plains',
'island',
'swamp',
'mountain',
'forest',
]

export const SHOCKLAND_REGEX = /As .* enters the battlefield, you may pay 2 life. If you don't, it enters the battlefield tapped\./
export const SHOCKLAND_REGEX =
/As .* enters the battlefield, you may pay 2 life. If you don't, it enters the battlefield tapped\./

export const isValues = {
gold: "gold" ,
hybrid: "hybrid" ,
phyrexian: "phyrexian" ,
promo: "promo" ,
reprint: "reprint" ,
firstprint: "firstprint" ,
firstprinting: "firstprinting" ,
digital: "digital" ,
dfc: "dfc" ,
mdfc: "mdfc" ,
tdfc: "tdfc" ,
meld: "meld",
transform: "transform" ,
split: "split" ,
flip: "flip" ,
leveler: "leveler" ,
commander: "commander" ,
spell: "spell" ,
permanent: "permanent" ,
historic: "historic" ,
vanilla: "vanilla" ,
modal: "modal" ,
fullart: "fullart" ,
foil: "foil" ,
nonfoil: "nonfoil" ,
etched: "etched" ,
bikeland: "bikeland" ,
cycleland: "cycleland" ,
bicycleland: "bicycleland" ,
bounceland: "bounceland" ,
karoo: "karoo" ,
canopyland: "canopyland" ,
canland: "canland" ,
fetchland: "fetchland" ,
checkland: "checkland" ,
dual: "dual" ,
fastland: "fastland" ,
filterland: "filterland" ,
gainland: "gainland" ,
painland: "painland" ,
scryland: "scryland" ,
shadowland: "shadowland" ,
snarl: "snarl" ,
slowland: "slowland" ,
shockland: "shockland" ,
storageland: "storageland" ,
creatureland: "creatureland" ,
manland: "manland" ,
triland: "triland" ,
triome: "triome" ,
tangoland: "tangoland" ,
battleland: "battleland"
gold: 'gold',
hybrid: 'hybrid',
phyrexian: 'phyrexian',
promo: 'promo',
reprint: 'reprint',
firstprint: 'firstprint',
firstprinting: 'firstprinting',
digital: 'digital',
dfc: 'dfc',
mdfc: 'mdfc',
tdfc: 'tdfc',
meld: 'meld',
transform: 'transform',
split: 'split',
flip: 'flip',
leveler: 'leveler',
commander: 'commander',
spell: 'spell',
permanent: 'permanent',
historic: 'historic',
vanilla: 'vanilla',
modal: 'modal',
fullart: 'fullart',
foil: 'foil',
nonfoil: 'nonfoil',
etched: 'etched',
bikeland: 'bikeland',
cycleland: 'cycleland',
bicycleland: 'bicycleland',
bounceland: 'bounceland',
karoo: 'karoo',
canopyland: 'canopyland',
canland: 'canland',
fetchland: 'fetchland',
checkland: 'checkland',
dual: 'dual',
fastland: 'fastland',
filterland: 'filterland',
gainland: 'gainland',
painland: 'painland',
scryland: 'scryland',
shadowland: 'shadowland',
snarl: 'snarl',
slowland: 'slowland',
shockland: 'shockland',
storageland: 'storageland',
creatureland: 'creatureland',
manland: 'manland',
triland: 'triland',
triome: 'triome',
tangoland: 'tangoland',
battleland: 'battleland',
} as const
export type IsValue = ObjectValues<typeof isValues>

export const isDual = (card: Card) =>
card.type_line.includes("Land") &&
/Add \{.} or \{.}\./.test(card.oracle_text)
card.type_line.includes('Land') && /Add \{.} or \{.}\./.test(card.oracle_text)
export const hasNumLandTypes = (card: Card, num: number) =>
BASIC_LAND_TYPES.filter(type => card.type_line.toLowerCase().includes(type)).length === num
BASIC_LAND_TYPES.filter((type) => card.type_line.toLowerCase().includes(type))
.length === num

export const oracleTextContains = (card: Card, value: string): boolean =>
card.oracle_text.toLowerCase().includes(value) ||
card.card_faces.filter((face) => face.oracle_text.toLowerCase().includes(value)).length > 0
card.oracle_text.toLowerCase().includes(value) ||
card.card_faces.filter((face) =>
face.oracle_text.toLowerCase().includes(value)
).length > 0

export const noReminderText = (text: string): string =>
text.replace(/\(.*\)/, "")
text.replace(/\(.*\)/, '')
45 changes: 22 additions & 23 deletions src/api/local/db.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import Dexie, {Table} from 'dexie'
import Dexie, { Table } from 'dexie'
import { Card } from 'scryfall-sdk'
import { BulkDataDefinition } from 'scryfall-sdk/out/api/BulkData'

type ManifestKeys = 'id' | 'uri' | 'type' | 'updated_at'
export type Manifest = Pick<BulkDataDefinition, ManifestKeys>

export type CardKeys =
'id' |
'oracle_id' |
'cmc' |
'color_identity' |
'colors' |
'name' |
'oracle_text' |
'power' |
'toughness'
| 'id'
| 'oracle_id'
| 'cmc'
| 'color_identity'
| 'colors'
| 'name'
| 'oracle_text'
| 'power'
| 'toughness'
export type CardTable = Pick<Card, CardKeys>

export class TypedDexie extends Dexie {
manifest!: Table<Manifest>
manifest!: Table<Manifest>

card!: Table<CardTable>
card!: Table<CardTable>

constructor() {
super('cogwork-librarian')
constructor() {
super('cogwork-librarian')

this.version(1).stores({
/*
this.version(1).stores({
/*
source: https://scryfall.com/docs/api/bulk-data
√ id UUID A unique ID for this bulk item.
√ uri URI The Scryfall API URI for this file.
Expand All @@ -39,9 +39,9 @@ export class TypedDexie extends Dexie {
content_type MIME Type The MIME type of this file.
content_encoding Encoding The Content-Encoding encoding that will be used to transmit this file when you download it.
*/
manifest: 'id, uri, type, updated_at',
/*
manifest: 'id, uri, type, updated_at',

/*
## Core
arena_id Integer Nullable This card’s Arena ID, if any. A large percentage of cards are not available on Arena and do not have this ID.
√ id UUID A unique ID for this card in Scryfall’s database.
Expand Down Expand Up @@ -84,9 +84,8 @@ export class TypedDexie extends Dexie {
toughness String Nullable This card’s toughness, if any. Note that some cards have toughnesses that are not numeric, such as *.
type_line String The type line of this card.
*/
card: 'id, oracle_id, cmc, color_identity, colors, name, oracle_text, power, toughness',
})
}
card: 'id, oracle_id, cmc, color_identity, colors, name, oracle_text, power, toughness',
})
}
}
export const cogDB = new TypedDexie()

28 changes: 15 additions & 13 deletions src/api/local/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ import { BulkDataType } from 'scryfall-sdk/out/api/BulkData'
import { cogDB, Manifest } from './db'

export const putManifest = async (type: BulkDataType) => {
const result = await Scry.BulkData.definitionByType(type)
await cogDB.manifest.put(result)
return result
const result = await Scry.BulkData.definitionByType(type)
await cogDB.manifest.put(result)
return result
}

export const putCards = async (manifest: Manifest) => {
const download = await Scry.BulkData
.downloadByType(manifest.type, manifest.updated_at)
const results: Array<Card> = (download as any).map(Scry.Card.construct)
await cogDB.card.bulkPut(results)
const download = await Scry.BulkData.downloadByType(
manifest.type,
manifest.updated_at
)
const results: Array<Card> = (download as any).map(Scry.Card.construct)
await cogDB.card.bulkPut(results)
}

export const populateDB = async (maybeManifest: Manifest | null) => {
let manifest = maybeManifest
if (manifest === null) {
manifest = await putManifest('oracle_cards')
await putCards(manifest)
}
}
let manifest = maybeManifest
if (manifest === null) {
manifest = await putManifest('oracle_cards')
await putCards(manifest)
}
}
Loading

0 comments on commit 0ce7829

Please sign in to comment.