-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathreql-client-errors.js
185 lines (153 loc) · 4.82 KB
/
reql-client-errors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Generated by CoffeeScript 1.7.0
RqlClientError, RqlCompileError, RqlDriverError, RqlQueryPrinter, RqlRuntimeError, RqlServerError;
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
RqlDriverError = (function(_super) {
__extends(RqlDriverError, _super);
function RqlDriverError(msg) {
this.name = this.constructor.name;
this.msg = msg;
this.message = msg;
if (Error.captureStackTrace != null) {
Error.captureStackTrace(this, this);
}
}
return RqlDriverError;
})(Error);
RqlServerError = (function(_super) {
__extends(RqlServerError, _super);
function RqlServerError(msg, term, frames) {
this.name = this.constructor.name;
this.msg = msg;
this.frames = frames.slice(0);
if (term != null) {
if (msg[msg.length - 1] === '.') {
this.message = "" + (msg.slice(0, msg.length - 1)) + " in:\n" + (RqlQueryPrinter.prototype.printQuery(term)) + "\n" + (RqlQueryPrinter.prototype.printCarrots(term, frames));
} else {
this.message = "" + msg + " in:\n" + (RqlQueryPrinter.prototype.printQuery(term)) + "\n" + (RqlQueryPrinter.prototype.printCarrots(term, frames));
}
} else {
this.message = "" + msg;
}
if (Error.captureStackTrace != null) {
Error.captureStackTrace(this, this);
}
}
return RqlServerError;
})(Error);
RqlRuntimeError = (function(_super) {
__extends(RqlRuntimeError, _super);
function RqlRuntimeError() {
return RqlRuntimeError.__super__.constructor.apply(this, arguments);
}
return RqlRuntimeError;
})(RqlServerError);
RqlCompileError = (function(_super) {
__extends(RqlCompileError, _super);
function RqlCompileError() {
return RqlCompileError.__super__.constructor.apply(this, arguments);
}
return RqlCompileError;
})(RqlServerError);
RqlClientError = (function(_super) {
__extends(RqlClientError, _super);
function RqlClientError() {
return RqlClientError.__super__.constructor.apply(this, arguments);
}
return RqlClientError;
})(RqlServerError);
RqlQueryPrinter = (function() {
var carrotMarker, carrotify, composeCarrots, composeTerm, joinTree;
function RqlQueryPrinter() {}
RqlQueryPrinter.prototype.printQuery = function(term) {
var tree;
tree = composeTerm(term);
return joinTree(tree);
};
composeTerm = function(term) {
var arg, args, key, optargs, _ref;
args = (function() {
var _i, _len, _ref, _results;
_ref = term.args;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
arg = _ref[_i];
_results.push(composeTerm(arg));
}
return _results;
})();
optargs = {};
_ref = term.optargs;
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
arg = _ref[key];
optargs[key] = composeTerm(arg);
}
return term.compose(args, optargs);
};
RqlQueryPrinter.prototype.printCarrots = function(term, frames) {
var tree;
if (frames.length === 0) {
tree = [carrotify(composeTerm(term))];
} else {
tree = composeCarrots(term, frames);
}
return (joinTree(tree)).replace(/[^\^]/g, ' ');
};
composeCarrots = function(term, frames) {
var arg, args, frame, i, key, optargs, _ref;
frame = frames.shift();
args = (function() {
var _i, _len, _ref, _results;
_ref = term.args;
_results = [];
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
arg = _ref[i];
if (frame === i) {
_results.push(composeCarrots(arg, frames));
} else {
_results.push(composeTerm(arg));
}
}
return _results;
})();
optargs = {};
_ref = term.optargs;
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
arg = _ref[key];
if (frame === key) {
optargs[key] = composeCarrots(arg, frames);
} else {
optargs[key] = composeTerm(arg);
}
}
if (frame != null) {
return term.compose(args, optargs);
} else {
return carrotify(term.compose(args, optargs));
}
};
carrotMarker = {};
carrotify = function(tree) {
return [carrotMarker, tree];
};
joinTree = function(tree) {
var str, term, _i, _len;
str = '';
for (_i = 0, _len = tree.length; _i < _len; _i++) {
term = tree[_i];
if (Array.isArray(term)) {
if (term.length === 2 && term[0] === carrotMarker) {
str += (joinTree(term[1])).replace(/./g, '^');
} else {
str += joinTree(term);
}
} else {
str += term;
}
}
return str;
};
return RqlQueryPrinter;
})();