alchemymvc 1.3.5 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app/datasource/mongo_datasource.js +21 -1
- package/lib/app/helper/backed_map.js +2 -249
- package/lib/app/helper/enum_values.js +32 -10
- package/lib/app/helper/router_helper.js +13 -12
- package/lib/app/helper_field/big_int_field.js +116 -0
- package/lib/class/conduit.js +18 -24
- package/lib/class/field.js +10 -7
- package/lib/class/path_param_definition.js +16 -3
- package/lib/class/sitemap.js +12 -5
- package/package.json +2 -2
|
@@ -369,7 +369,7 @@ Mongo.setMethod(function _read(model, criteria, callback) {
|
|
|
369
369
|
*
|
|
370
370
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
371
371
|
* @since 0.2.0
|
|
372
|
-
* @version 1.
|
|
372
|
+
* @version 1.3.6
|
|
373
373
|
*/
|
|
374
374
|
Mongo.setMethod(function _create(model, data, options, callback) {
|
|
375
375
|
|
|
@@ -394,6 +394,26 @@ Mongo.setMethod(function _create(model, data, options, callback) {
|
|
|
394
394
|
return callback(err, result);
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
+
let write_errors = result.message?.documents?.[0]?.writeErrors;
|
|
398
|
+
|
|
399
|
+
if (write_errors) {
|
|
400
|
+
let violations = new Classes.Alchemy.Error.Validation.Violations();
|
|
401
|
+
|
|
402
|
+
if (write_errors.length) {
|
|
403
|
+
let entry;
|
|
404
|
+
|
|
405
|
+
for (entry of write_errors) {
|
|
406
|
+
let violation = new Classes.Alchemy.Error.Validation.Violation();
|
|
407
|
+
violation.message = entry.errmsg || entry.message || entry.code;
|
|
408
|
+
violations.add(violation);
|
|
409
|
+
}
|
|
410
|
+
} else {
|
|
411
|
+
violations.add(new Error('Unknown database error'));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return callback(violations);
|
|
415
|
+
}
|
|
416
|
+
|
|
397
417
|
callback(null, Object.assign({}, data));
|
|
398
418
|
});
|
|
399
419
|
});
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
const OBJECT = Symbol('Object'),
|
|
2
|
-
BACKING = Symbol('Backing'),
|
|
3
|
-
MAP = Symbol('Map');
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* The Backed map class
|
|
7
3
|
*
|
|
@@ -9,249 +5,6 @@ const OBJECT = Symbol('Object'),
|
|
|
9
5
|
*
|
|
10
6
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
11
7
|
* @since 1.2.1
|
|
12
|
-
* @version 1.
|
|
8
|
+
* @version 1.3.5
|
|
13
9
|
*/
|
|
14
|
-
const Backed = Function.inherits('
|
|
15
|
-
this.local = new Map();
|
|
16
|
-
this.type = null;
|
|
17
|
-
this.backing = backing;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Undry the given value
|
|
22
|
-
*
|
|
23
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
-
* @since 1.2.1
|
|
25
|
-
* @version 1.2.1
|
|
26
|
-
*
|
|
27
|
-
* @param {Object} value
|
|
28
|
-
*
|
|
29
|
-
* @return {EnumValues}
|
|
30
|
-
*/
|
|
31
|
-
Backed.setStatic(function unDry(value, custom_method, whenDone) {
|
|
32
|
-
let result = new this(value.backing);
|
|
33
|
-
return result;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get the size
|
|
38
|
-
*
|
|
39
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
40
|
-
* @since 1.2.1
|
|
41
|
-
* @version 1.2.1
|
|
42
|
-
*/
|
|
43
|
-
Backed.setProperty(function size() {
|
|
44
|
-
return this.keys().length;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Set the backing value
|
|
49
|
-
*
|
|
50
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
51
|
-
* @since 1.2.1
|
|
52
|
-
* @version 1.2.1
|
|
53
|
-
*/
|
|
54
|
-
Backed.enforceProperty(function backing(new_value, old_value) {
|
|
55
|
-
|
|
56
|
-
this.backing = null;
|
|
57
|
-
this.type = null;
|
|
58
|
-
|
|
59
|
-
if (!new_value) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (new_value instanceof Backed) {
|
|
64
|
-
this.type = BACKING;
|
|
65
|
-
} else if (new_value instanceof Map) {
|
|
66
|
-
this.type = MAP;
|
|
67
|
-
} else if (typeof new_value == 'object') {
|
|
68
|
-
this.type = OBJECT;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return new_value;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Create a (shallow) clone of this backed map.
|
|
76
|
-
* Since we don't ever touch the backing itself, we don't have to clone that.
|
|
77
|
-
*
|
|
78
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
79
|
-
* @since 1.2.1
|
|
80
|
-
* @version 1.3.1
|
|
81
|
-
*
|
|
82
|
-
* @return {Backed}
|
|
83
|
-
*/
|
|
84
|
-
Backed.setMethod(function clone() {
|
|
85
|
-
let result = new this.constructor(this.backing);
|
|
86
|
-
result.local = new Map(this.local);
|
|
87
|
-
return result;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Create a (shallow) clone of this backed map.
|
|
92
|
-
* Since we don't ever touch the backing itself, we don't have to clone that.
|
|
93
|
-
*
|
|
94
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
95
|
-
* @since 1.2.1
|
|
96
|
-
* @version 1.2.1
|
|
97
|
-
*
|
|
98
|
-
* @return {Backed}
|
|
99
|
-
*/
|
|
100
|
-
Backed.setMethod(function dryClone(wm, custom_method) {
|
|
101
|
-
return this.clone();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Simplify the object for Hawkejs
|
|
106
|
-
*
|
|
107
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
108
|
-
* @since 1.2.1
|
|
109
|
-
* @version 1.2.1
|
|
110
|
-
*
|
|
111
|
-
* @param {WeakMap} wm
|
|
112
|
-
*
|
|
113
|
-
* @return {Backed}
|
|
114
|
-
*/
|
|
115
|
-
Backed.setMethod(function toHawkejs(wm) {
|
|
116
|
-
|
|
117
|
-
let values = new Map(),
|
|
118
|
-
value,
|
|
119
|
-
keys = this.keys(),
|
|
120
|
-
key;
|
|
121
|
-
|
|
122
|
-
for (key of keys) {
|
|
123
|
-
value = this.get(key);
|
|
124
|
-
values.set(key, JSON.clone(value, 'toHawkejs', wm));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return new this.constructor(values);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Get all the keys
|
|
132
|
-
*
|
|
133
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
134
|
-
* @since 1.2.1
|
|
135
|
-
* @version 1.2.1
|
|
136
|
-
*
|
|
137
|
-
* @return {String[]}
|
|
138
|
-
*/
|
|
139
|
-
Backed.setMethod(function keys() {
|
|
140
|
-
|
|
141
|
-
let result;
|
|
142
|
-
|
|
143
|
-
if (this.type == BACKING) {
|
|
144
|
-
result = this.backing.keys();
|
|
145
|
-
} else if (this.type == MAP) {
|
|
146
|
-
result = [...this.backing.keys()];
|
|
147
|
-
} else if (this.type == OBJECT) {
|
|
148
|
-
result = Object.keys(this.backing);
|
|
149
|
-
} else {
|
|
150
|
-
result = [];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (this.local.size) {
|
|
154
|
-
for (let key of this.local.keys()) {
|
|
155
|
-
if (result.indexOf(key) == -1) {
|
|
156
|
-
result.push(key);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return result;
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Get a value by it's name
|
|
166
|
-
*
|
|
167
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
168
|
-
* @since 1.2.1
|
|
169
|
-
* @version 1.2.1
|
|
170
|
-
*
|
|
171
|
-
* @param {String} name
|
|
172
|
-
*
|
|
173
|
-
* @return {Mixed}
|
|
174
|
-
*/
|
|
175
|
-
Backed.setMethod(function get(name) {
|
|
176
|
-
|
|
177
|
-
if (this.local.has(name)) {
|
|
178
|
-
return this.local.get(name);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (!this.type) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
let value;
|
|
186
|
-
|
|
187
|
-
if (this.type == BACKING || this.type == MAP) {
|
|
188
|
-
value = this.backing.get(name);
|
|
189
|
-
} else if (this.type == OBJECT) {
|
|
190
|
-
value = this.backing[name];
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return value;
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Set a value
|
|
198
|
-
*
|
|
199
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
200
|
-
* @since 1.2.1
|
|
201
|
-
* @version 1.2.1
|
|
202
|
-
*
|
|
203
|
-
* @param {String} name
|
|
204
|
-
* @param {*} value
|
|
205
|
-
*
|
|
206
|
-
* @return {*}
|
|
207
|
-
*/
|
|
208
|
-
Backed.setMethod(function set(name, value) {
|
|
209
|
-
this.local.set(name, value);
|
|
210
|
-
return value;
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Dry the object
|
|
215
|
-
*
|
|
216
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
217
|
-
* @since 1.2.1
|
|
218
|
-
* @version 1.2.1
|
|
219
|
-
*
|
|
220
|
-
* @return {Object}
|
|
221
|
-
*/
|
|
222
|
-
Backed.setMethod(function toDry() {
|
|
223
|
-
|
|
224
|
-
let result = {
|
|
225
|
-
backing : {}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
let value,
|
|
229
|
-
key;
|
|
230
|
-
|
|
231
|
-
for (key of this.keys()) {
|
|
232
|
-
value = this.get(key);
|
|
233
|
-
result.backing[key] = value;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return {value: result};
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Iterate over the object
|
|
241
|
-
*
|
|
242
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
243
|
-
* @since 1.2.1
|
|
244
|
-
* @version 1.2.1
|
|
245
|
-
*
|
|
246
|
-
* @return {Object}
|
|
247
|
-
*/
|
|
248
|
-
Backed.setMethod(Symbol.iterator, function* iterate() {
|
|
249
|
-
|
|
250
|
-
let value,
|
|
251
|
-
key;
|
|
252
|
-
|
|
253
|
-
for (key of this.keys()) {
|
|
254
|
-
value = this.get(key);
|
|
255
|
-
yield value;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
10
|
+
const Backed = Function.inherits('Develry.BackedMap', 'Alchemy.Map', 'Backed');
|
|
@@ -91,7 +91,7 @@ EnumMap.setMethod(function set(name, value) {
|
|
|
91
91
|
*
|
|
92
92
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
93
93
|
* @since 1.2.1
|
|
94
|
-
* @version 1.
|
|
94
|
+
* @version 1.3.6
|
|
95
95
|
*
|
|
96
96
|
* @param {WeakMap} wm
|
|
97
97
|
*
|
|
@@ -100,23 +100,45 @@ EnumMap.setMethod(function set(name, value) {
|
|
|
100
100
|
EnumMap.setMethod(function toHawkejs(wm) {
|
|
101
101
|
|
|
102
102
|
let result = toHawkejs.super.call(this, wm),
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
original_entry,
|
|
104
|
+
cloned_entry,
|
|
105
105
|
keys = this.keys(),
|
|
106
106
|
key;
|
|
107
107
|
|
|
108
108
|
for (key of keys) {
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
original_entry = this.get(key);
|
|
110
|
+
cloned_entry = result.get(key);
|
|
111
|
+
|
|
112
|
+
if (original_entry.value) {
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
let val = original_entry.value;
|
|
113
115
|
|
|
114
|
-
if (typeof
|
|
115
|
-
|
|
116
|
+
if (typeof val == 'function') {
|
|
117
|
+
cloned_entry.type = 'function';
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
+
if (val.schema) {
|
|
121
|
+
cloned_entry.schema = JSON.clone(val.schema, 'toHawkejs', wm);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let key,
|
|
125
|
+
field_val;
|
|
126
|
+
|
|
127
|
+
for (key in val) {
|
|
128
|
+
|
|
129
|
+
if (key == 'schema') {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
field_val = val[key];
|
|
134
|
+
|
|
135
|
+
if (field_val) {
|
|
136
|
+
const SchemaClass = Blast.isBrowser ? Classes.Alchemy.Client.Schema : Classes.Alchemy.Schema;
|
|
137
|
+
|
|
138
|
+
if (field_val instanceof SchemaClass) {
|
|
139
|
+
cloned_entry[key] = JSON.clone(field_val, 'toHawkejs', wm);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
120
142
|
}
|
|
121
143
|
}
|
|
122
144
|
}
|
|
@@ -221,9 +221,9 @@ Router.setMethod(function applyDirective(element, name, options) {
|
|
|
221
221
|
/**
|
|
222
222
|
* Return route name info
|
|
223
223
|
*
|
|
224
|
-
* @author Jelle De Loecker <jelle@
|
|
224
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
225
225
|
* @since 0.2.0
|
|
226
|
-
* @version 1.
|
|
226
|
+
* @version 1.3.6
|
|
227
227
|
*
|
|
228
228
|
* @param {String} name
|
|
229
229
|
* @param {Boolean} socket_route Look in the socket routes
|
|
@@ -232,13 +232,12 @@ Router.setMethod(function applyDirective(element, name, options) {
|
|
|
232
232
|
*/
|
|
233
233
|
Router.setMethod(function routeConfig(name, socket_route) {
|
|
234
234
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
key;
|
|
235
|
+
if (!name) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let section,
|
|
240
|
+
routes;
|
|
242
241
|
|
|
243
242
|
if (socket_route) {
|
|
244
243
|
|
|
@@ -264,7 +263,7 @@ Router.setMethod(function routeConfig(name, socket_route) {
|
|
|
264
263
|
return null;
|
|
265
264
|
}
|
|
266
265
|
|
|
267
|
-
pieces = name.split('@');
|
|
266
|
+
let pieces = name.split('@');
|
|
268
267
|
|
|
269
268
|
if (pieces.length == 1) {
|
|
270
269
|
name = pieces[0];
|
|
@@ -273,6 +272,8 @@ Router.setMethod(function routeConfig(name, socket_route) {
|
|
|
273
272
|
if (routes.default[name] != null) {
|
|
274
273
|
section = 'default';
|
|
275
274
|
} else {
|
|
275
|
+
let key;
|
|
276
|
+
|
|
276
277
|
for (key in routes) {
|
|
277
278
|
if (routes[key][name] != null) {
|
|
278
279
|
section = key
|
|
@@ -285,9 +286,9 @@ Router.setMethod(function routeConfig(name, socket_route) {
|
|
|
285
286
|
}
|
|
286
287
|
|
|
287
288
|
if (routes[section] != null && routes[section][name] != null) {
|
|
288
|
-
route = routes[section][name];
|
|
289
|
+
let route = routes[section][name];
|
|
289
290
|
|
|
290
|
-
result = {
|
|
291
|
+
let result = {
|
|
291
292
|
section : section,
|
|
292
293
|
name : name
|
|
293
294
|
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
let mongo;
|
|
2
|
+
|
|
3
|
+
if (Blast.isNode) {
|
|
4
|
+
mongo = alchemy.use('mongodb');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The BigInt Field class
|
|
9
|
+
*
|
|
10
|
+
* @constructor
|
|
11
|
+
*
|
|
12
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
13
|
+
* @since 1.3.6
|
|
14
|
+
* @version 1.3.6
|
|
15
|
+
*/
|
|
16
|
+
const BigIntField = Function.inherits('Alchemy.Field.Number', 'BigInt');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Set the datatype name
|
|
20
|
+
*
|
|
21
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
22
|
+
* @since 1.3.6
|
|
23
|
+
* @version 1.3.6
|
|
24
|
+
*/
|
|
25
|
+
BigIntField.setDatatype('bigint');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Cast the given value to this field's type
|
|
29
|
+
*
|
|
30
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
31
|
+
* @since 1.3.6
|
|
32
|
+
* @version 1.3.6
|
|
33
|
+
*
|
|
34
|
+
* @param {Mixed} value
|
|
35
|
+
*
|
|
36
|
+
* @return {BigInt}
|
|
37
|
+
*/
|
|
38
|
+
BigIntField.setMethod(function cast(value) {
|
|
39
|
+
|
|
40
|
+
// Allow null
|
|
41
|
+
if (value == null) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return BigInt(value);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Cast the given value to this field's type for search in a db
|
|
50
|
+
*
|
|
51
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
52
|
+
* @since 1.3.6
|
|
53
|
+
* @version 1.3.6
|
|
54
|
+
*
|
|
55
|
+
* @param {Mixed} value
|
|
56
|
+
* @param {Array} field_paths The path to the field
|
|
57
|
+
*
|
|
58
|
+
* @return {Mixed}
|
|
59
|
+
*/
|
|
60
|
+
BigIntField.setMethod(function _castCondition(value, field_paths) {
|
|
61
|
+
|
|
62
|
+
value = this.cast(value);
|
|
63
|
+
|
|
64
|
+
if (mongo) {
|
|
65
|
+
value = mongo.Long.fromBigInt(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return value;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Convert the value for the given datasource
|
|
73
|
+
*
|
|
74
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
75
|
+
* @since 1.3.6
|
|
76
|
+
* @version 1.3.6
|
|
77
|
+
*
|
|
78
|
+
* @param {Mixed} value The field's own value
|
|
79
|
+
* @param {Object} data The main record
|
|
80
|
+
* @param {Datasource} datasource The datasource instance
|
|
81
|
+
*
|
|
82
|
+
* @return {Mixed}
|
|
83
|
+
*/
|
|
84
|
+
BigIntField.setMethod(function _toDatasource(value, data, datasource, callback) {
|
|
85
|
+
|
|
86
|
+
value = this.cast(value);
|
|
87
|
+
|
|
88
|
+
if (mongo) {
|
|
89
|
+
value = mongo.Long.fromBigInt(value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
callback(null, value);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Convert from database to app
|
|
97
|
+
*
|
|
98
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
99
|
+
* @since 1.3.6
|
|
100
|
+
* @version 1.3.6
|
|
101
|
+
*
|
|
102
|
+
* @param {Object} query The original query
|
|
103
|
+
* @param {Object} options The original query options
|
|
104
|
+
* @param {Mixed} value The field value, as stored in the DB
|
|
105
|
+
* @param {Function} callback
|
|
106
|
+
*/
|
|
107
|
+
BigIntField.setMethod(function _toApp(query, options, value, callback) {
|
|
108
|
+
|
|
109
|
+
if (mongo && value && value.toBigInt) {
|
|
110
|
+
value = value.toBigInt();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
value = this.cast(value);
|
|
114
|
+
|
|
115
|
+
callback(null, value);
|
|
116
|
+
});
|
package/lib/class/conduit.js
CHANGED
|
@@ -1400,16 +1400,16 @@ Conduit.setMethod(function setResponseUrl(new_url) {
|
|
|
1400
1400
|
/**
|
|
1401
1401
|
* Redirect to another url
|
|
1402
1402
|
*
|
|
1403
|
-
* @author Jelle De Loecker <jelle@
|
|
1403
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1404
1404
|
* @since 0.2.0
|
|
1405
|
-
* @version 1.
|
|
1405
|
+
* @version 1.3.6
|
|
1406
1406
|
*
|
|
1407
1407
|
* @param {Number} status 3xx redirection codes. 302 (temporary redirect) by default
|
|
1408
1408
|
* @param {String|Object} options Options or url
|
|
1409
1409
|
*/
|
|
1410
1410
|
Conduit.setMethod(function redirect(status, options) {
|
|
1411
1411
|
|
|
1412
|
-
|
|
1412
|
+
let hard_refresh = false,
|
|
1413
1413
|
url;
|
|
1414
1414
|
|
|
1415
1415
|
if (typeof status != 'number') {
|
|
@@ -1486,6 +1486,20 @@ Conduit.setMethod(function redirect(status, options) {
|
|
|
1486
1486
|
|
|
1487
1487
|
this.status = status;
|
|
1488
1488
|
|
|
1489
|
+
// Make sure the url is an internal one if no hard refresh is requested
|
|
1490
|
+
if (!hard_refresh && alchemy.settings.url) {
|
|
1491
|
+
let rurl = RURL.parse(url);
|
|
1492
|
+
|
|
1493
|
+
// If an explicit hostname is set, this might be an external url
|
|
1494
|
+
if (rurl.hostname) {
|
|
1495
|
+
let base_url = RURL.parse(alchemy.settings.url);
|
|
1496
|
+
|
|
1497
|
+
if (base_url.hostname != rurl.hostname) {
|
|
1498
|
+
hard_refresh = true;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1489
1503
|
if (hard_refresh && this.headers['x-hawkejs-request']) {
|
|
1490
1504
|
this.setHeader('x-hawkejs-navigate', url);
|
|
1491
1505
|
|
|
@@ -2217,7 +2231,7 @@ Conduit.setMethod(function _sendStream(stream, options) {
|
|
|
2217
2231
|
*
|
|
2218
2232
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
2219
2233
|
* @since 0.2.0
|
|
2220
|
-
* @version 1.3.
|
|
2234
|
+
* @version 1.3.6
|
|
2221
2235
|
*
|
|
2222
2236
|
* @param {Boolean} create Create a session if none exist
|
|
2223
2237
|
*
|
|
@@ -2231,7 +2245,6 @@ Conduit.setMethod(function getSession(allow_create = true) {
|
|
|
2231
2245
|
}
|
|
2232
2246
|
|
|
2233
2247
|
let cookie_name,
|
|
2234
|
-
fingerprint,
|
|
2235
2248
|
session_id,
|
|
2236
2249
|
session;
|
|
2237
2250
|
|
|
@@ -2246,30 +2259,11 @@ Conduit.setMethod(function getSession(allow_create = true) {
|
|
|
2246
2259
|
session = alchemy.sessions.get(session_id);
|
|
2247
2260
|
}
|
|
2248
2261
|
|
|
2249
|
-
// If no session is found, see if we can find one
|
|
2250
|
-
// based on the browser fingerprint
|
|
2251
|
-
if (!session && this.ip) {
|
|
2252
|
-
fingerprint = this.fingerprint;
|
|
2253
|
-
|
|
2254
|
-
if (fingerprint) {
|
|
2255
|
-
session = alchemy.fingerprints.get(fingerprint);
|
|
2256
|
-
|
|
2257
|
-
if (session && session.id) {
|
|
2258
|
-
session_id = session.id;
|
|
2259
|
-
this.cookie(cookie_name, session_id, {httpOnly: true});
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
2262
|
// If no valid session exists, create a new one
|
|
2265
2263
|
if (!session && allow_create) {
|
|
2266
2264
|
session = new Classes.Alchemy.ClientSession(this);
|
|
2267
2265
|
session_id = session.id;
|
|
2268
2266
|
|
|
2269
|
-
if (fingerprint) {
|
|
2270
|
-
alchemy.fingerprints.set(fingerprint, session);
|
|
2271
|
-
}
|
|
2272
|
-
|
|
2273
2267
|
this.cookie(cookie_name, session_id, {httpOnly: true});
|
|
2274
2268
|
|
|
2275
2269
|
alchemy.sessions.set(session_id, session);
|
package/lib/class/field.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @constructor
|
|
6
6
|
*
|
|
7
|
-
* @author Jelle De Loecker <jelle@
|
|
7
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
8
8
|
* @since 0.2.0
|
|
9
|
-
* @version 1.
|
|
9
|
+
* @version 1.3.6
|
|
10
10
|
*
|
|
11
11
|
* @param {Schema} schema The schema this field is added to
|
|
12
12
|
* @param {String} name The name of the field
|
|
@@ -22,8 +22,11 @@ Blast.Globals.Field = Function.inherits('Alchemy.Base', 'Alchemy.Field', functio
|
|
|
22
22
|
// Also store under parent
|
|
23
23
|
this.parent_schema = schema;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (schema) {
|
|
26
|
+
// Check the indexes
|
|
27
|
+
// @TODO: move this to the `addField` methods?
|
|
28
|
+
this.checkIndexes();
|
|
29
|
+
}
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
/**
|
|
@@ -974,9 +977,9 @@ Field.setMethod(function _getValue(wrapped, done_translation) {
|
|
|
974
977
|
/**
|
|
975
978
|
* See if we need to apply any indexes
|
|
976
979
|
*
|
|
977
|
-
* @author Jelle De Loecker <jelle@
|
|
980
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
978
981
|
* @since 1.1.0
|
|
979
|
-
* @version 1.
|
|
982
|
+
* @version 1.3.6
|
|
980
983
|
*/
|
|
981
984
|
Field.setMethod(function checkIndexes() {
|
|
982
985
|
|
|
@@ -997,7 +1000,7 @@ Field.setMethod(function checkIndexes() {
|
|
|
997
1000
|
index.sparse = this.options.sparse;
|
|
998
1001
|
}
|
|
999
1002
|
|
|
1000
|
-
if (this.options.unique) {
|
|
1003
|
+
if (this.options.unique && this.schema) {
|
|
1001
1004
|
this.schema.addIndex(this, index);
|
|
1002
1005
|
} else if (!Object.isEmpty(index)) {
|
|
1003
1006
|
console.log('@TODO: handle field index:', this, index);
|
|
@@ -84,7 +84,7 @@ PathParamDefinition.setStatic(function from(input) {
|
|
|
84
84
|
*
|
|
85
85
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
86
86
|
* @since 1.3.0
|
|
87
|
-
* @version 1.3.
|
|
87
|
+
* @version 1.3.6
|
|
88
88
|
*/
|
|
89
89
|
PathParamDefinition.setMethod(function parseTypeDefinition() {
|
|
90
90
|
|
|
@@ -109,8 +109,21 @@ PathParamDefinition.setMethod(function parseTypeDefinition() {
|
|
|
109
109
|
class_name = this.typedef;
|
|
110
110
|
}
|
|
111
111
|
} else {
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
|
|
113
|
+
let class_path = [],
|
|
114
|
+
field_path = [],
|
|
115
|
+
current = class_path;
|
|
116
|
+
|
|
117
|
+
for (let piece of this.typedef) {
|
|
118
|
+
if (piece[0] != piece[0].toUpperCase()) {
|
|
119
|
+
current = field_path;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
current.push(piece);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class_name = class_path.join('.');
|
|
126
|
+
field_name = field_path.join('.');
|
|
114
127
|
}
|
|
115
128
|
|
|
116
129
|
if (class_name) {
|
package/lib/class/sitemap.js
CHANGED
|
@@ -353,11 +353,13 @@ Sitemap.setMethod(function addRouteWithParameters(route, config, parameters, for
|
|
|
353
353
|
*
|
|
354
354
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
355
355
|
* @since 1.3.4
|
|
356
|
-
* @version 1.3.
|
|
356
|
+
* @version 1.3.6
|
|
357
|
+
*
|
|
358
|
+
* @param {String} prefix
|
|
357
359
|
*
|
|
358
360
|
* @return {Hawkejs.Builder}
|
|
359
361
|
*/
|
|
360
|
-
Sitemap.setMethod(function getXmlBuilder() {
|
|
362
|
+
Sitemap.setMethod(function getXmlBuilder(prefix) {
|
|
361
363
|
|
|
362
364
|
let xml = Classes.Hawkejs.Builder.create({xml: true}),
|
|
363
365
|
urlset = xml.ele('urlset');
|
|
@@ -367,13 +369,18 @@ Sitemap.setMethod(function getXmlBuilder() {
|
|
|
367
369
|
.att('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd')
|
|
368
370
|
.att('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
|
|
369
371
|
|
|
370
|
-
let categories = this.getCategories();
|
|
372
|
+
let categories = this.getCategories(prefix);
|
|
371
373
|
|
|
372
374
|
for (let category of categories) {
|
|
373
|
-
|
|
375
|
+
|
|
376
|
+
if (!category.pages) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
for (let info of category.pages) {
|
|
374
381
|
let url = urlset.ele(url);
|
|
375
382
|
|
|
376
|
-
url.ele('loc').txt(info.url);
|
|
383
|
+
url.ele('loc').txt(''+info.url);
|
|
377
384
|
|
|
378
385
|
if (info.lastmod) {
|
|
379
386
|
url.ele('lastmod').txt(info.lastmod);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemymvc",
|
|
3
3
|
"description": "MVC framework for Node.js",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.6",
|
|
5
5
|
"author": "Jelle De Loecker <jelle@elevenways.be>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"alchemy",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"mongodb" : "~3.6.6",
|
|
32
32
|
"ncp" : "~2.0.0",
|
|
33
33
|
"postcss" : "~8.4.6",
|
|
34
|
-
"protoblast" : "~0.8.
|
|
34
|
+
"protoblast" : "~0.8.5",
|
|
35
35
|
"semver" : "~7.3.5",
|
|
36
36
|
"socket.io" : "~4.6.0",
|
|
37
37
|
"@11ways/socket.io-stream" : "~0.9.2",
|