vgno / data-shaper Goto Github PK
View Code? Open in Web Editor NEWUtility for building meaningful responses from normalized data using shapes
License: MIT License
Utility for building meaningful responses from normalized data using shapes
License: MIT License
I think there is a bug when multiple reverse references exist in the same hierarchy. It seems that IDs are "leaking" into arrays, somehow.
Right now its possible to express one-to-one and many-to-one relations, but there's no way of expressing one-to-many or many-to-many. The following is a proposal on how *-to-many could be described as a way of looking up incoming connections from coupling tables.
var participantShape = {
collectionName: 'participants',
shape: {
id: 'id',
type: 'name'
}
}
var eventIncidentsShape = {
collectionName: 'eventIncidents',
shape: {
id: 'id',
elapsed: 'elapsed',
participants: {
reference: 'eventIncidentDetails(eventIncidents=id).participantId',
shape: participantShape
}
}
};
Given the following data in the database;
# eventIncidents
+----+---------+---------------------+---------+
| id | eventId | eventIncidentTypeId | elapsed |
+----+---------+---------------------+---------+
| 1 | 48 | 724 | 0 |
| 2 | 39 | 724 | 0 |
| 3 | 48 | 832 | 0 |
+----+---------+---------------------+---------+
# eventIncidentDetails
+-----+-------------+-----------------+---------------+--------------------------+
| id | type | eventIncidentId | participantId | value |
+-----+-------------+-----------------+---------------+--------------------------+
| 115 | team | 39 | 5672 | |
| 123 | statusTime | 39 | 0 | 2015-02-17T19:55:18.000Z |
| 147 | team | 48 | 5672 | |
| 159 | statusTime | 48 | 0 | 2015-02-17T19:57:56.000Z |
| 162 | player1 | 48 | 30529 | |
| 163 | coordinates | 48 | 0 | 20:7 |
+-----+-------------+-----------------+---------------+--------------------------+
If we fetch the eventIncidents and use the eventIncidentsShape, the resolver will
parse the reference eventIncidentDetails(eventIncidents=id).participantId
, look
up all items in the eventIncidentDetails collection where eventIncidents=id (the id
from the referring object) and fetch all non-null participantIds.
Next the participantShape will be used for each of the participantIds ending with the
result looking like this;
{
eventIncidents: {
'39' : {
id: 39,
elapsed: 0,
participants: { participants: [5672] }
},
'48' : {
id: 48,
elapsed: 0,
participants: { participants: [30529] }
}
},
participants: {
'5672': {..},
'30529': {..}
}
}
In another case an incident may have more than one participant and then the participants
array would hold more than one id.
Let's say I have two collection called catBreeds
and translations
. It contains the following:
id | name | description |
---|---|---|
1 | Norwegian Forest Cat | the most awesome of cats |
2 | Scottish fold | the cutest of cats |
id | catBreedId | translatedName |
---|---|---|
11 | 1 | Norsk skogkatt |
12 | 2 | Skotsk kattepus |
I want the shape of my catBreeds
to return the translated name for the cat:
{
collectionName: 'catBreeds',
shape: {
id: 'id',
name: 'name',
translated: {
reference: 'translations(catBreedId=id)',
shape: {
collectionName: 'translations',
shape: {
id: 'id',
translatedName: 'translatedName'
}
}
}
}
}
The problem is that this assumes a multi-reference - that is, it returns an array of IDs instead of a single ID:
translated: {
catBreeds: [
1
]
}
It would be nice if there was a way to specify that this is a single reverse reference, which would return an ID instead of an array in this case.
I'm having a hard time figuring out the flow and how this bug occurs. Basically it has to do with references that can't be resolved (0
, for instance). They are returned from the fetcher as null
and something in the resolve-fragment
code tries to map over the values and extract the IDs from it. That obviously fails when encountering a null
.
I hotfixed it with d566b43, but someone(tm) should add a test to ensure there are no regressions later.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.