forked from plouc/nivo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): migrate API to TypeScript and fix stale mappings and examples
- Loading branch information
Showing
124 changed files
with
2,667 additions
and
2,484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"restartable": "rs", | ||
"ignore": ["node_modules/", "dist/", "coverage/"], | ||
"watch": ["src/"], | ||
"execMap": { | ||
"ts": "node -r ts-node/register" | ||
}, | ||
"env": { | ||
"NODE_ENV": "development" | ||
}, | ||
"ext": "js,json,ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { pick } from 'lodash' | ||
import React, { FunctionComponent } from 'react' | ||
import { renderToStaticMarkup } from 'react-dom/server' | ||
import { ChartProps, chartsMapping, ChartType } from '../mapping' | ||
|
||
const staticProps = { | ||
animate: false, | ||
isInteractive: false, | ||
renderWrapper: false, | ||
theme: {}, | ||
} | ||
|
||
export const renderChart = <T extends ChartType>( | ||
{ | ||
type, | ||
props, | ||
}: { | ||
type: T | ||
props: ChartProps<T> | ||
}, | ||
override | ||
) => { | ||
const chart = chartsMapping[type] | ||
const component = chart.component as FunctionComponent<ChartProps<T>> | ||
const mergedProps = { | ||
...staticProps, | ||
...chart.defaults, | ||
...props, | ||
...pick(override, chart.runtimeProps || []), | ||
} | ||
const rendered = renderToStaticMarkup( | ||
React.createElement<ChartProps<T>>(component, mergedProps) | ||
) | ||
|
||
return `<?xml version="1.0" ?>${rendered}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ChartProps, ChartType } from '../mapping' | ||
|
||
export interface StorageEntry<T extends ChartType> { | ||
type: T | ||
props: ChartProps<T> | ||
url: string | ||
} | ||
|
||
const store: Record<string, StorageEntry<ChartType>> = {} | ||
|
||
export const set = (key: string, value: StorageEntry<ChartType>) => { | ||
store[key] = value | ||
} | ||
|
||
export const get = (key: string): StorageEntry<ChartType> | undefined => { | ||
return store[key] | ||
} | ||
|
||
export const dump = () => store |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type OmitStrict<T, K extends keyof T> = T extends any ? Pick<T, Exclude<keyof T, K>> : never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { omit } from 'lodash' | ||
import joi from 'joi' | ||
|
||
export const validate = ( | ||
schema: joi.Schema, | ||
options: { | ||
omit?: string[] | ||
} = {} | ||
) => { | ||
const { omit: omitProps } = options | ||
|
||
return (req, res, next) => { | ||
let data = req.body | ||
if (omit) { | ||
data = omit(data, omitProps) | ||
} | ||
|
||
try { | ||
req.payload = joi.attempt(data, schema, null, { | ||
abortEarly: true, | ||
convert: true, | ||
}) | ||
next() | ||
} catch (err) { | ||
console.log('ERROR', err) | ||
return res.status(400).json({ | ||
errors: err.details.map(({ message, path }) => { | ||
return `${message}${path ? ` (${path})` : ''}` | ||
}), | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.