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.
Files changed (39) hide show
  1. package/lib/app/behaviour/sluggable_behaviour.js +2 -4
  2. package/lib/app/conduit/http_conduit.js +173 -192
  3. package/lib/app/conduit/loopback_conduit.js +0 -0
  4. package/lib/app/conduit/socket_conduit.js +620 -620
  5. package/lib/app/datasource/mongo_datasource.js +75 -10
  6. package/lib/app/element/time_ago.js +0 -0
  7. package/lib/app/helper/socket_helper.js +613 -613
  8. package/lib/app/helper_datasource/00-nosql_datasource.js +73 -19
  9. package/lib/app/helper_datasource/remote_datasource.js +0 -0
  10. package/lib/app/helper_field/05-string_field.js +0 -0
  11. package/lib/app/helper_field/schema_field.js +7 -2
  12. package/lib/app/helper_model/criteria.js +76 -18
  13. package/lib/app/helper_model/field_config.js +24 -5
  14. package/lib/app/helper_model/model.js +65 -7
  15. package/lib/app/model/alchemy_migration_model.js +33 -0
  16. package/lib/bootstrap.js +9 -0
  17. package/lib/class/conduit.js +2474 -2412
  18. package/lib/class/datasource.js +8 -8
  19. package/lib/class/field.js +7 -1
  20. package/lib/class/inode.js +62 -0
  21. package/lib/class/inode_dir.js +115 -0
  22. package/lib/class/inode_file.js +112 -111
  23. package/lib/class/migration.js +138 -0
  24. package/lib/class/model.js +1765 -1772
  25. package/lib/class/reciprocal.js +8 -2
  26. package/lib/class/router.js +0 -0
  27. package/lib/class/schema.js +14 -12
  28. package/lib/core/base.js +37 -10
  29. package/lib/core/client_base.js +1 -9
  30. package/lib/core/middleware.js +4 -8
  31. package/lib/core/socket.js +159 -159
  32. package/lib/init/alchemy.js +1779 -1779
  33. package/lib/init/devwatch.js +1 -1
  34. package/lib/init/functions.js +2 -56
  35. package/lib/init/load_functions.js +8 -2
  36. package/lib/init/requirements.js +101 -96
  37. package/lib/stages.js +12 -0
  38. package/package.json +74 -76
  39. 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.1.0
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
- collection.aggregate(compiled.pipeline, {}, function gotAggregate(err, cursor) {
253
+ // Sorting should happen in the pipeline
254
+ if (options.sort && options.sort.length) {
255
+ let sort_object = {};
254
256
 
255
- if (err) {
256
- return callback(err);
257
+ for (let entry of options.sort) {
258
+ sort_object[entry[0]] = entry[1];
257
259
  }
258
260
 
259
- cursor.toArray(function gotArray(err, items) {
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
- if (err) {
262
- return callback(err);
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
- items = that.organizeResultItems(model, items);
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
- callback(null, items);
268
- });
333
+ callback(err, data.items, data.available);
269
334
  });
270
335
 
271
336
  return;
File without changes