alchemymvc 1.1.7 → 1.2.0
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/behaviour/sluggable_behaviour.js +2 -4
- package/lib/app/conduit/http_conduit.js +173 -192
- package/lib/app/conduit/loopback_conduit.js +0 -0
- package/lib/app/conduit/socket_conduit.js +620 -620
- package/lib/app/datasource/mongo_datasource.js +75 -10
- package/lib/app/element/time_ago.js +0 -0
- package/lib/app/helper/socket_helper.js +613 -613
- package/lib/app/helper_datasource/00-nosql_datasource.js +73 -19
- package/lib/app/helper_datasource/remote_datasource.js +0 -0
- package/lib/app/helper_field/05-string_field.js +0 -0
- package/lib/app/helper_field/schema_field.js +7 -2
- package/lib/app/helper_model/criteria.js +76 -18
- package/lib/app/helper_model/field_config.js +24 -5
- package/lib/app/helper_model/model.js +65 -7
- package/lib/app/model/alchemy_migration_model.js +33 -0
- package/lib/bootstrap.js +9 -0
- package/lib/class/conduit.js +2474 -2412
- package/lib/class/datasource.js +8 -8
- package/lib/class/field.js +7 -1
- package/lib/class/inode.js +62 -0
- package/lib/class/inode_dir.js +115 -0
- package/lib/class/inode_file.js +112 -111
- package/lib/class/migration.js +138 -0
- package/lib/class/model.js +1765 -1772
- package/lib/class/reciprocal.js +8 -2
- package/lib/class/router.js +0 -0
- package/lib/class/schema.js +14 -12
- package/lib/core/base.js +37 -10
- package/lib/core/client_base.js +1 -9
- package/lib/core/middleware.js +4 -8
- package/lib/core/socket.js +159 -159
- package/lib/init/alchemy.js +1779 -1779
- package/lib/init/devwatch.js +1 -1
- package/lib/init/functions.js +2 -56
- package/lib/init/load_functions.js +8 -2
- package/lib/init/requirements.js +101 -96
- package/lib/stages.js +12 -0
- package/package.json +74 -76
- package/CHANGELOG.md +0 -445
|
@@ -228,7 +228,7 @@ Mongo.setMethod(function collection(name, callback) {
|
|
|
228
228
|
*
|
|
229
229
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
230
230
|
* @since 0.2.0
|
|
231
|
-
* @version 1.
|
|
231
|
+
* @version 1.2.0
|
|
232
232
|
*/
|
|
233
233
|
Mongo.setMethod(function _read(model, criteria, callback) {
|
|
234
234
|
|
|
@@ -250,22 +250,87 @@ Mongo.setMethod(function _read(model, criteria, callback) {
|
|
|
250
250
|
|
|
251
251
|
if (compiled.pipeline) {
|
|
252
252
|
|
|
253
|
-
|
|
253
|
+
// Sorting should happen in the pipeline
|
|
254
|
+
if (options.sort && options.sort.length) {
|
|
255
|
+
let sort_object = {};
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
+
for (let entry of options.sort) {
|
|
258
|
+
sort_object[entry[0]] = entry[1];
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
|
|
261
|
+
compiled.pipeline.unshift({$sort: sort_object});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Skipping also happens in the pipeline
|
|
265
|
+
if (options.skip) {
|
|
266
|
+
compiled.pipeline.push({$skip: options.skip});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let aggregate_options = {};
|
|
260
270
|
|
|
261
|
-
|
|
262
|
-
|
|
271
|
+
// Limits can still be set as an option though
|
|
272
|
+
if (options.limit) {
|
|
273
|
+
aggregate_options.limit = options.limit;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
Function.parallel({
|
|
277
|
+
available: function getAvailable(next) {
|
|
278
|
+
|
|
279
|
+
if (criteria.options.available === false) {
|
|
280
|
+
return next(null, null);
|
|
263
281
|
}
|
|
264
282
|
|
|
265
|
-
|
|
283
|
+
let pipeline = JSON.clone(compiled.pipeline),
|
|
284
|
+
cloned_options = JSON.clone(aggregate_options);
|
|
285
|
+
|
|
286
|
+
pipeline.push({$count: 'available'});
|
|
287
|
+
|
|
288
|
+
// Expensive aggregate just to get the available count...
|
|
289
|
+
collection.aggregate(pipeline, cloned_options, function gotAggregate(err, cursor) {
|
|
290
|
+
|
|
291
|
+
if (err) {
|
|
292
|
+
return next(err);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
cursor.toArray(function gotAvailableArray(err, items) {
|
|
296
|
+
|
|
297
|
+
if (err) {
|
|
298
|
+
return next(err);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (!items || !items.length) {
|
|
302
|
+
return next(null, null);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
let available = items[0].available;
|
|
306
|
+
|
|
307
|
+
if (options.skip) {
|
|
308
|
+
available += options.skip;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return next(null, available);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
items: function getItems(next) {
|
|
316
|
+
collection.aggregate(compiled.pipeline, aggregate_options, function gotAggregate(err, cursor) {
|
|
317
|
+
|
|
318
|
+
if (err) {
|
|
319
|
+
return next(err);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
cursor.toArray(next);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}, function done(err, data) {
|
|
326
|
+
|
|
327
|
+
if (err) {
|
|
328
|
+
return callback(err);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
data.items = that.organizeResultItems(model, data.items);
|
|
266
332
|
|
|
267
|
-
|
|
268
|
-
});
|
|
333
|
+
callback(err, data.items, data.available);
|
|
269
334
|
});
|
|
270
335
|
|
|
271
336
|
return;
|
|
File without changes
|