forked from elastic/kibana
-
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.
Add create method to types (elastic#621)
* feat: add serialize/deserialize capabilities * fix: send types to serialize provider * feat: add create method to types and pass types in cast and interpret * fix: re-add type validation * fix: no need to import datatable in pointseries
- Loading branch information
1 parent
4cea78b
commit 7fcaaa6
Showing
15 changed files
with
94 additions
and
58 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 |
---|---|---|
@@ -1,27 +1,21 @@ | ||
/* | ||
WARNING: This is imported into the public and server function registries separately because | ||
it needs access to types and the registry of types is, obviously, different between the environments | ||
*/ | ||
|
||
import { castProvider } from '../interpreter/cast'; | ||
|
||
export function toProvider(types) { | ||
return () => ({ | ||
name: 'to', | ||
aliases: [], | ||
help: 'Explicitly cast from one type to another.', | ||
context: {}, | ||
args: { | ||
_: { | ||
types: ['string'], | ||
help: 'A known type', | ||
aliases: ['type'], | ||
multi: true, | ||
}, | ||
}, | ||
fn: (context, args) => { | ||
if (!args._) throw new Error('Must specify a casting type'); | ||
return castProvider(types.toJS())(context, args._); | ||
export const to = () => ({ | ||
name: 'to', | ||
aliases: [], | ||
help: 'Explicitly cast from one type to another.', | ||
context: {}, | ||
args: { | ||
_: { | ||
types: ['string'], | ||
help: 'A known type', | ||
aliases: ['type'], | ||
multi: true, | ||
}, | ||
}); | ||
} | ||
}, | ||
fn: (context, args, { types }) => { | ||
if (!args._) throw new Error('Must specify a casting type'); | ||
|
||
return castProvider(types)(context, args._); | ||
}, | ||
}); |
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 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,18 @@ | ||
import { get, identity } from 'lodash'; | ||
import { getType } from '../lib/get_type'; | ||
|
||
export function serializeProvider(types) { | ||
return { | ||
serialize: provider('serialize'), | ||
deserialize: provider('deserialize'), | ||
}; | ||
|
||
function provider(key) { | ||
return context => { | ||
const type = getType(context); | ||
const typeDef = types[type]; | ||
const fn = get(typeDef, key) || identity; | ||
return fn(context); | ||
}; | ||
} | ||
} |
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 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 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 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