Skip to content

Commit c703ff2

Browse files
committed
Fixed async operations in schema.
1 parent 2257162 commit c703ff2

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

builders.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
const REQUIRED = 'The field "@" is required.';
3030
const DEFAULT_SCHEMA = 'default';
31-
const SKIP = { $$schema: true, $$result: true, $$callback: true, $$async: true, $$index: true, $$repository: true };
31+
const SKIP = { $$schema: true, $$result: true, $$callback: true, $$async: true, $$index: true, $$repository: true, $$can: true };
3232
const REGEXP_CLEAN_EMAIL = /\s/g;
3333
const REGEXP_CLEAN_PHONE = /\s|\.|\-|\(|\)/g;
3434
const hasOwnProperty = Object.prototype.hasOwnProperty;
@@ -1953,8 +1953,10 @@ SchemaInstance.prototype.$async = function(callback, index) {
19531953
self.$$result = [];
19541954
self.$$index = index;
19551955
self.$$callback = callback;
1956+
self.$$can = true;
19561957

19571958
setImmediate(function() {
1959+
self.$$can = false;
19581960
async_queue(self.$$async, function() {
19591961
self.$$callback(null, self.$$index !== undefined ? self.$$result[self.$$index] : self.$$result);
19601962
self.$$callback = null;
@@ -2064,7 +2066,7 @@ SchemaInstance.prototype.$next = function(type, name, helper) {
20642066
SchemaInstance.prototype.$save = function(helper, callback) {
20652067
var self = this;
20662068

2067-
if (self.$$async)
2069+
if (self.$$can && self.$$async)
20682070
return self.$push('save', helper);
20692071

20702072
self.$$schema.save(self, helper, callback);
@@ -2074,7 +2076,7 @@ SchemaInstance.prototype.$save = function(helper, callback) {
20742076
SchemaInstance.prototype.$query = function(helper, callback) {
20752077
var self = this;
20762078

2077-
if (self.$$async)
2079+
if (self.$$can && self.$$async)
20782080
return self.$push('query', helper);
20792081

20802082
self.$$schema.query(self, helper, callback);
@@ -2084,7 +2086,7 @@ SchemaInstance.prototype.$query = function(helper, callback) {
20842086
SchemaInstance.prototype.$read = SchemaInstance.prototype.$get = function(helper, callback) {
20852087
var self = this;
20862088

2087-
if (self.$$async)
2089+
if (self.$$can && self.$$async)
20882090
return self.$push('get', helper);
20892091

20902092
self.$$schema.get(self, helper, callback);
@@ -2094,7 +2096,7 @@ SchemaInstance.prototype.$read = SchemaInstance.prototype.$get = function(helper
20942096
SchemaInstance.prototype.$remove = function(helper, callback) {
20952097
var self = this;
20962098

2097-
if (self.$$async)
2099+
if (self.$$can && self.$$async)
20982100
return self.$push('remove', helper);
20992101

21002102
self.$$schema.remove(helper, callback);
@@ -2112,7 +2114,7 @@ SchemaInstance.prototype.$destroy = function() {
21122114
SchemaInstance.prototype.$transform = function(name, helper, callback) {
21132115
var self = this;
21142116

2115-
if (self.$$async)
2117+
if (self.$$can && self.$$async)
21162118
return self.$push('transform', name, helper);
21172119

21182120
self.$$schema.transform(name, self, helper, callback);
@@ -2122,7 +2124,7 @@ SchemaInstance.prototype.$transform = function(name, helper, callback) {
21222124
SchemaInstance.prototype.$workflow = function(name, helper, callback) {
21232125
var self = this;
21242126

2125-
if (self.$$async)
2127+
if (self.$$can && self.$$async)
21262128
return self.$push('workflow', name, helper);
21272129

21282130
self.$$schema.workflow(name, self, helper, callback);
@@ -2132,7 +2134,7 @@ SchemaInstance.prototype.$workflow = function(name, helper, callback) {
21322134
SchemaInstance.prototype.$operation = function(name, helper, callback) {
21332135
var self = this;
21342136

2135-
if (!self.$$async)
2137+
if (self.$$can && self.$$async)
21362138
return self.$push('operation', name, helper);
21372139

21382140
self.$$schema.operation(name, self, helper, callback);

0 commit comments

Comments
 (0)