-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simple example of conversion functions #2
Comments
I'd like to see something more along the lines of this: Source: {
"name": {
"type": "pandat/name-last-name-first",
"label": "NAME"
},
"city": {
"type": "pandat/us-street-address",
"label": "ADDR"
}
} Output: {
"name": {
"type": "pandat/name",
"label": "NAME",
"source": "NAME"
},
"addr": {
"type": "pandat/us-city",
"label": "CITY",
"source": "ADDR"
}
} Converter: /**
* Module dependencies
*/
var object1 = require('./object1.json')
var fooSchema = require('./foo.json');
var barSchema = require('./bar.json');
var pandat = require('pandat');
/**
* Initialize converter.
*
* @param {Object} sourceSchema
* @param {Object} targetSchema
* @return {Function}
*/
var converter = pandat.Conversion(fooSchema, barSchema, {invertible: false});
/**
* Execute conversion
*/
var resultObject = converter(object1); I think that if you design your relations beforehand, there'll be no need for further declarations. Such an implementation would allow for more flexibility, and result in a cleaner API. Also: I didn't quite catch the difference between a codec and conversion, could you explain what you mean by that? |
Hello!
Yeah! What i meant above by "pandat might be able to generate the function, with some hints about how the names map to each other".
I like this relational mapping, though it won't quite happen on the output type, as the output type may be an input type elsewhere. Relevant to mention here is that users will be reusing types published by others. Totally possible to just have to specify:
Given I published
Yeah. A A Lmk if that makes sense? Will put this all on the Readme. |
Your explanation of A conversion has a:
An input schema has:
An output schema has:
Or |
Output schema == input schema. They're the same thing. They define Other than that, right on! |
I really dislike the And couldn't this: /**
* Module dependencies
*/
var outputSchema = require('./bar');
var inputSchema = require('./foo');
var linkSchema = require('baz');
var pandat = require('pandat');
/**
* Initialize converter.
*/
var Foo2Bar = pandat.Conversion({'invertible': 'false'}, [inputSchema], [outputSchema]);
Foo2Bar.convert = function(linkSchema) {
return {
'name': pandat(inputSchema.name['@type'], outputSchema .name['@type'], linkSchema.name),
'city': pandat(inputSchema.addr['@type'], outputSchema .city['@type'], linkSchema.addr)
}
} be rewritten to this: /**
* Module dependencies
*/
var outputSchema = require('./bar');
var inputSchema = require('./foo');
var linkSchema = require('baz');
var pandat = require('pandat');
/**
* Export converter.
*/
module.exports = var converter = pandat({'invertible': 'false'});
converter.schema = {
'name': [inputSchema.name, outputSchema.name, linkSchema.name],
'city': [inputSchema.addr, outputSchema.city, linkSchema.city],
} You could use an internal function to execute The less friction the API causes, the more developers will love using it. Imo things like |
Take that up with json-ld.org :)
They are, the goal is for all transformer objects to have a definition in JSON-LD. (sorry, haven't made it clear in the REAMDE.) They'll have their own ( t = pandat.Type({
'name': {
'@type': 'pandat/name',
'label': 'NAME',
'codec': 'pandat/name-last-name-first'
},
'addr': {
'@type': 'pandat/us-street-address',
'label': 'ADDR',
}
}) fill's in:
See https://github.com/jbenet/pandat/blob/master/js/type.js Though none if this is final. Will try to have working code by end of this weekend. |
just for the sake of argument, how about this for a minimum viable JSON type:
e.g. default |
As for the example, the goal is that most users won't have to write their own conversion functions at all, simply use published ones. Some people will, and in those cases, both doing it in code directly or with a relational schema (expressing the mapping of one type to the other) that allows transformer to generate the code. Precisely like you suggest! :)
👍 |
Yeah! lgtm! both filling in the |
👍 |
not final, food for thought.
Want output
Input Type FOO
Output Type BAR
You can write a conversion function, use it and/or publish it to pandat:
(excuse this interface, might be simplified some)
Or, pandat might be able to generate the function, with some hints about how the names map to each other. (not quite sure what the right interface is here, but will think about it.)
The text was updated successfully, but these errors were encountered: