Skip to content

Commit 1a32e8f

Browse files
Merge pull request #27 from xanthous-tech/facet-bugs
Facet bugs
2 parents 295830d + cdc3aaa commit 1a32e8f

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xanthous/dgraph-orm",
3-
"version": "0.2.0-alpha5",
3+
"version": "0.2.0-alpha9",
44
"description": "dgraph ORM in TypeScript",
55
"main": "dist/index.js",
66
"author": "Xanthous Tech Developers <hi@x-tech.io>",
@@ -21,6 +21,7 @@
2121
"build": "tsc -p tsconfig.build.json",
2222
"postinstall": "npm run clean && npm run build",
2323
"prestart": "npm run postinstall",
24+
"prepublish": "npm run test && npm run postinstall",
2425
"lint": "eslint ./src --ext .ts",
2526
"lint:fix": "eslint --fix",
2627
"format": "prettier --write",

src/transaction/transaction.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,13 @@ export class Transaction<T extends Object, V> implements ITransaction<T> {
256256
facetDataIndices.forEach(idx => {
257257
const plain = facets.reduce<IObjectLiteral>((acc, f) => {
258258
const facetPropertyName = `${name}|${f.args.propertyName}`;
259-
const facetValue = Private.accessUnsafe(value._owner, facetPropertyName)[idx];
259+
const facetDataMap = Private.accessUnsafe(value._owner, facetPropertyName);
260+
261+
if (!facetDataMap) {
262+
return acc;
263+
}
264+
265+
const facetValue = facetDataMap[idx];
260266

261267
if (facetValue) {
262268
acc[f.args.propertyName] = facetValue;

tests/mutation.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ describe('Mutation handling', () => {
101101
class PersonKnows {
102102
@Facet()
103103
familiarity: number;
104+
105+
@Facet()
106+
years: number;
104107
}
105108

106109
@Node()
@@ -120,6 +123,7 @@ describe('Mutation handling', () => {
120123
uid: '0x1',
121124
'Person.name': 'John',
122125
'Person.friends|familiarity': { '0': 999 },
126+
'Person.friends|years': { '0': 3 },
123127
'Person.friends': [
124128
{
125129
uid: '0x2',
@@ -152,7 +156,7 @@ describe('Mutation handling', () => {
152156
`<0x3> <Person.name> "New Kamil"^^<xs:string> .
153157
<0x2> <Person.name> "New Jane"^^<xs:string> .
154158
<0x1> <Person.name> "New John"^^<xs:string> .
155-
<0x1> <Person.friends> <0x2> (familiarity=666) .
159+
<0x1> <Person.friends> <0x2> (familiarity=666,years=3) .
156160
`
157161
);
158162
});

0 commit comments

Comments
 (0)