@foxify/odin
Advanced tools
Comparing version 0.1.0-beta.5 to 0.1.0-beta.6
@@ -15,2 +15,7 @@ # Changelog | ||
## [v0.1.0-beta.6](https://github.com/foxifyjs/odin/releases/tag/v0.1.0-beta.5) - *(2018-08-21)* | ||
- :boom: `GraphQL` change insert single to create single (eq. `insert_user` => `create_user`) | ||
- :boom: `GraphQL` change `data` argument to `query` | ||
## [v0.1.0-beta.5](https://github.com/foxifyjs/odin/releases/tag/v0.1.0-beta.5) - *(2018-08-16)* | ||
@@ -17,0 +22,0 @@ |
@@ -34,3 +34,7 @@ /* | ||
declare class GraphQL { | ||
private static schema; | ||
private static _schema; | ||
private static _table; | ||
private static timestamps; | ||
private static softDelete; | ||
static toGraphQL(): any; | ||
@@ -37,0 +41,0 @@ } |
@@ -28,3 +28,3 @@ /* | ||
var e = this && this.__awaiter || function(e, t, r, n) { | ||
return new (r || (r = Promise))(function(i, s) { | ||
return new (r || (r = Promise))(function(s, i) { | ||
function fulfilled(e) { | ||
@@ -34,3 +34,3 @@ try { | ||
} catch (e) { | ||
s(e); | ||
i(e); | ||
} | ||
@@ -42,7 +42,7 @@ } | ||
} catch (e) { | ||
s(e); | ||
i(e); | ||
} | ||
} | ||
function step(e) { | ||
e.done ? i(e.value) : new r(function(t) { | ||
e.done ? s(e.value) : new r(function(t) { | ||
t(e.value); | ||
@@ -59,4 +59,4 @@ }).then(fulfilled, rejected); | ||
const t = require("graphql"), r = require("../types/Any"), n = require("../utils"), i = (e, n) => { | ||
const s = {}, a = {}; | ||
const t = require("graphql"), r = require("../types/Any"), n = require("../utils"), s = (e, n) => { | ||
const i = {}, a = {}; | ||
for (const o in n) { | ||
@@ -66,3 +66,3 @@ const l = n[o]; | ||
const t = l.toGraphQL(e, o); | ||
s[o] = { | ||
i[o] = { | ||
type: t.field | ||
@@ -72,30 +72,52 @@ }, a[o] = { | ||
}; | ||
} else { | ||
const r = i(e, l); | ||
s[o] = { | ||
type: new t.GraphQLObjectType({ | ||
name: `${e}_${o}`, | ||
fields: r.fields | ||
}) | ||
}, a[o] = { | ||
type: new t.GraphQLInputObjectType({ | ||
name: `${e}_${o}_input`, | ||
fields: r.args | ||
}) | ||
}; | ||
continue; | ||
} | ||
const p = s(e, l); | ||
i[o] = { | ||
type: new t.GraphQLObjectType({ | ||
name: `${e}_${o}`, | ||
fields: p.fields | ||
}) | ||
}, a[o] = { | ||
type: new t.GraphQLInputObjectType({ | ||
name: `${e}_${o}_input`, | ||
fields: p.args | ||
}) | ||
}; | ||
} | ||
return { | ||
fields: s, | ||
fields: i, | ||
args: a | ||
}; | ||
}, s = e => e.selectionSet.selections.reduce((e, t) => (e[t.name.value] = 1, e), {}), a = e => e.toJSON(); | ||
}, i = e => e.selectionSet.selections.reduce((e, t) => (e[t.name.value] = 1, e), {}), a = (e, s) => { | ||
const i = e => `${e}_ASC`, a = e => `${e}_DESC`, o = (e, t) => { | ||
const s = {}; | ||
for (const l in e) { | ||
const p = e[l], c = n.array.compact([ t, l ]).join("."); | ||
if (p instanceof r.default) { | ||
const e = i(c); | ||
s[e] = { | ||
value: e | ||
}; | ||
const t = a(c); | ||
s[t] = { | ||
value: t | ||
}; | ||
} else n.object.forEach(o(e, c), (e, t) => s[t] = e); | ||
} | ||
return s; | ||
}; | ||
return new t.GraphQLEnumType({ | ||
name: `${e}OrderByInput`, | ||
values: o(s) | ||
}); | ||
}, o = e => e.toJSON(); | ||
exports.default = class GraphQL { | ||
static toGraphQL() { | ||
const r = this.name, o = this._table, l = n.string.singularize(o), p = i(r, this.schema), d = p.fields, u = Object.assign({ | ||
const r = this.name, l = this._table, p = n.string.pluralize(l, 1), c = s(r, this.schema), u = c.fields, d = Object.assign({ | ||
id: { | ||
type: t.GraphQLID | ||
} | ||
}, p.args), c = new t.GraphQLObjectType({ | ||
}, c.args), h = new t.GraphQLObjectType({ | ||
name: r, | ||
@@ -106,24 +128,49 @@ fields: Object.assign({ | ||
} | ||
}, d) | ||
}), h = { | ||
[l]: { | ||
type: c, | ||
args: u, | ||
resolve: (t, r, i, o) => e(this, void 0, void 0, function*() { | ||
const e = s(o.fieldNodes[0]); | ||
}, u) | ||
}), y = { | ||
[p]: { | ||
type: h, | ||
args: d, | ||
resolve: (t, r, s, a) => e(this, void 0, void 0, function*() { | ||
const e = i(a.fieldNodes[0]); | ||
let t = this; | ||
return n.object.forEach(r, (e, r) => { | ||
t = t.where(r, e); | ||
}), a(yield t.first(e)); | ||
}), o(yield t.first(e)); | ||
}) | ||
}, | ||
[o]: { | ||
type: new t.GraphQLList(c), | ||
args: u, | ||
resolve: (t, r, i, o) => e(this, void 0, void 0, function*() { | ||
const e = s(o.fieldNodes[0]); | ||
[l]: { | ||
type: new t.GraphQLList(h), | ||
args: Object.assign({}, d, { | ||
skip: { | ||
type: t.GraphQLInt | ||
}, | ||
limit: { | ||
type: t.GraphQLInt | ||
}, | ||
orderBy: { | ||
type: a(r, this._schema) | ||
} | ||
}), | ||
resolve: (t, r, s, a) => e(this, void 0, void 0, function*() { | ||
const e = i(a.fieldNodes[0]); | ||
let t = this; | ||
return n.object.forEach(r, (e, r) => { | ||
t = t.where(r, e); | ||
}), (yield t.get(e)).map(a); | ||
return this.timestamps && (t = t.orderBy("created_at", "desc")), n.object.forEach(r, (e, r) => { | ||
switch (r) { | ||
case "skip": | ||
t = t.skip(e); | ||
break; | ||
case "limit": | ||
t = t.limit(e); | ||
break; | ||
case "orderBy": | ||
e = e.split("_"), t = t.orderBy(e.shift(), e[0].toLowerCase()); | ||
break; | ||
default: | ||
t = t.where(r, e); | ||
} | ||
}), (yield t.get(e)).map(o); | ||
}) | ||
@@ -133,63 +180,78 @@ } | ||
name: `${r}Input`, | ||
fields: p.args | ||
}); | ||
return { | ||
queries: h, | ||
mutations: { | ||
[`insert_${l}`]: { | ||
type: c, | ||
args: { | ||
data: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
}, | ||
resolve: (t, r, n, i) => e(this, void 0, void 0, function*() { | ||
return a(yield this.create(r.data)); | ||
}) | ||
fields: c.args | ||
}), v = { | ||
[`create_${p}`]: { | ||
type: h, | ||
args: { | ||
data: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
}, | ||
[`insert_${o}`]: { | ||
type: t.GraphQLInt, | ||
args: { | ||
data: { | ||
type: new t.GraphQLList(new t.GraphQLNonNull(f)) | ||
} | ||
}, | ||
resolve: (t, r, n, i) => e(this, void 0, void 0, function*() { | ||
return yield this.insert(r.data); | ||
}) | ||
resolve: (t, r, n, s) => e(this, void 0, void 0, function*() { | ||
return o(yield this.create(r.data)); | ||
}) | ||
}, | ||
[`insert_${l}`]: { | ||
type: t.GraphQLInt, | ||
args: { | ||
data: { | ||
type: new t.GraphQLList(new t.GraphQLNonNull(f)) | ||
} | ||
}, | ||
[`update_${o}`]: { | ||
type: t.GraphQLInt, | ||
args: { | ||
query: { | ||
type: new t.GraphQLNonNull(f) | ||
}, | ||
data: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
resolve: (t, r, n, s) => e(this, void 0, void 0, function*() { | ||
return yield this.insert(r.data); | ||
}) | ||
}, | ||
[`update_${l}`]: { | ||
type: t.GraphQLInt, | ||
args: { | ||
query: { | ||
type: new t.GraphQLNonNull(f) | ||
}, | ||
resolve: (t, r, i, s) => e(this, void 0, void 0, function*() { | ||
let e = this; | ||
return n.object.forEach(r.query, (t, r) => { | ||
e = e.where(r, t); | ||
}), yield e.update(r.data); | ||
}) | ||
data: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
}, | ||
[`delete_${o}`]: { | ||
type: t.GraphQLInt, | ||
args: { | ||
data: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
}, | ||
resolve: (t, r, i, s) => e(this, void 0, void 0, function*() { | ||
let e = this; | ||
return n.object.forEach(r.data, (t, r) => { | ||
e = e.where(r, t); | ||
}), yield e.delete(); | ||
}) | ||
} | ||
resolve: (t, r, s, i) => e(this, void 0, void 0, function*() { | ||
let e = this; | ||
return n.object.forEach(r.query, (t, r) => { | ||
e = e.where(r, t); | ||
}), yield e.update(r.data); | ||
}) | ||
}, | ||
[`delete_${l}`]: { | ||
type: t.GraphQLInt, | ||
args: { | ||
query: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
}, | ||
resolve: (t, r, s, i) => e(this, void 0, void 0, function*() { | ||
let e = this; | ||
return n.object.forEach(r.query, (t, r) => { | ||
e = e.where(r, t); | ||
}), yield e.delete(); | ||
}) | ||
} | ||
}; | ||
return this.softDelete && (v[`restore_${l}`] = { | ||
type: t.GraphQLInt, | ||
args: { | ||
query: { | ||
type: new t.GraphQLNonNull(f) | ||
} | ||
}, | ||
resolve: (t, r, s, i) => e(this, void 0, void 0, function*() { | ||
let e = this; | ||
return n.object.forEach(r.query, (t, r) => { | ||
e = e.where(r, t); | ||
}), yield e.update({ | ||
deleted_at: null | ||
}); | ||
}) | ||
}), { | ||
queries: y, | ||
mutations: v | ||
}; | ||
} | ||
}; |
@@ -58,4 +58,4 @@ /* | ||
const t = e.split("_"); | ||
return t.push(exports.string.singularize(t.pop())), t.join("_"); | ||
return t.push(exports.string.pluralize(t.pop(), 1)), t.join("_"); | ||
}), exports.makeTableId = (e => `${exports.makeTableType(e)}_id`), exports.makeMorphType = (e => `${exports.makeTableType(e)}able`), | ||
exports.getCallerFunctionName = (e => t.getData(e).methodName); |
{ | ||
"name": "@foxify/odin", | ||
"version": "0.1.0-beta.5", | ||
"version": "0.1.0-beta.6", | ||
"description": "Active Record Model", | ||
@@ -51,3 +51,3 @@ "author": "Ardalan Amini <ardalanamini22@gmail.com> [https://github.com/ardalanamini]", | ||
"mysql": "^2.16.0", | ||
"prototyped.js": "^0.16.0", | ||
"prototyped.js": "^0.18.1", | ||
"verifications": "^0.3.0" | ||
@@ -67,5 +67,5 @@ }, | ||
"jest": "^23.5.0", | ||
"mongodb-memory-server": "^1.9.3", | ||
"mongodb-memory-server": "^2.0.0", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^23.1.3", | ||
"ts-jest": "^23.1.4", | ||
"tslint": "^5.11.0", | ||
@@ -72,0 +72,0 @@ "typescript": "^3.0.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
187388
4267
0
+ Addedprototyped.js@0.18.1(transitive)
- Removedpluralize@7.0.0(transitive)
- Removedprototyped.js@0.16.0(transitive)
Updatedprototyped.js@^0.18.1