alchemymvc 1.3.12 → 1.3.13

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 (121) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/lib/app/assets/scripts/.gitkeep +0 -0
  4. package/lib/app/assets/stylesheets/alchemy-info.less +0 -0
  5. package/lib/app/behaviour/publishable_behaviour.js +0 -0
  6. package/lib/app/behaviour/revision_behaviour.js +0 -0
  7. package/lib/app/behaviour/sluggable_behaviour.js +0 -0
  8. package/lib/app/component/.gitkeep +0 -0
  9. package/lib/app/conduit/electron_conduit.js +0 -0
  10. package/lib/app/conduit/http_conduit.js +0 -0
  11. package/lib/app/conduit/loopback_conduit.js +0 -0
  12. package/lib/app/conduit/socket_conduit.js +0 -0
  13. package/lib/app/controller/alchemy_info_controller.js +0 -0
  14. package/lib/app/datasource/mongo_datasource.js +0 -0
  15. package/lib/app/element/time_ago.js +0 -0
  16. package/lib/app/helper/alchemy_helper.js +0 -0
  17. package/lib/app/helper/backed_map.js +0 -0
  18. package/lib/app/helper/breadcrumb.js +0 -0
  19. package/lib/app/helper/client_collection.js +0 -0
  20. package/lib/app/helper/enum_values.js +0 -0
  21. package/lib/app/helper/pagination_helper.js +0 -0
  22. package/lib/app/helper/router_helper.js +0 -0
  23. package/lib/app/helper/socket_helper.js +0 -0
  24. package/lib/app/helper/syncable.js +0 -0
  25. package/lib/app/helper_component/paginate_component.js +0 -0
  26. package/lib/app/helper_controller/component.js +0 -0
  27. package/lib/app/helper_controller/conduit.js +0 -0
  28. package/lib/app/helper_controller/controller.js +0 -0
  29. package/lib/app/helper_datasource/00-nosql_datasource.js +0 -0
  30. package/lib/app/helper_datasource/05-fallback_datasource.js +0 -0
  31. package/lib/app/helper_datasource/idb_datasource.js +0 -0
  32. package/lib/app/helper_datasource/indexed_db.js +0 -0
  33. package/lib/app/helper_datasource/remote_datasource.js +0 -0
  34. package/lib/app/helper_error/http_error.js +0 -0
  35. package/lib/app/helper_error/model_error.js +0 -0
  36. package/lib/app/helper_error/validation_error.js +0 -0
  37. package/lib/app/helper_field/00-objectid_field.js +0 -0
  38. package/lib/app/helper_field/05-string_field.js +0 -0
  39. package/lib/app/helper_field/06-text_field.js +0 -0
  40. package/lib/app/helper_field/10-number_field.js +0 -0
  41. package/lib/app/helper_field/belongsto_field.js +0 -0
  42. package/lib/app/helper_field/big_int_field.js +0 -0
  43. package/lib/app/helper_field/boolean_field.js +0 -0
  44. package/lib/app/helper_field/date_field.js +0 -0
  45. package/lib/app/helper_field/datetime_field.js +0 -0
  46. package/lib/app/helper_field/enum_field.js +0 -0
  47. package/lib/app/helper_field/geopoint_field.js +0 -0
  48. package/lib/app/helper_field/habtm_field.js +0 -0
  49. package/lib/app/helper_field/hasoneparent_field.js +0 -0
  50. package/lib/app/helper_field/html_field.js +0 -0
  51. package/lib/app/helper_field/integer_field.js +0 -0
  52. package/lib/app/helper_field/object_field.js +0 -0
  53. package/lib/app/helper_field/password_field.js +0 -0
  54. package/lib/app/helper_field/regexp_field.js +0 -0
  55. package/lib/app/helper_field/schema_field.js +0 -0
  56. package/lib/app/helper_field/time_field.js +0 -0
  57. package/lib/app/helper_field/url_field.js +0 -0
  58. package/lib/app/helper_model/criteria.js +0 -0
  59. package/lib/app/helper_model/data_provider.js +9 -0
  60. package/lib/app/helper_model/db_query.js +0 -0
  61. package/lib/app/helper_model/document.js +36 -0
  62. package/lib/app/helper_model/document_list.js +0 -0
  63. package/lib/app/helper_model/field_config.js +0 -0
  64. package/lib/app/helper_model/field_set.js +0 -0
  65. package/lib/app/helper_model/model.js +35 -5
  66. package/lib/app/helper_model/remote_data_provider.js +60 -10
  67. package/lib/app/helper_validator/00_validator.js +0 -0
  68. package/lib/app/helper_validator/not_empty_validator.js +0 -0
  69. package/lib/app/model/alchemy_migration_model.js +0 -0
  70. package/lib/app/model/alchemy_task_model.js +0 -0
  71. package/lib/app/routes.js +0 -0
  72. package/lib/app/view/alchemy/info.hwk +0 -0
  73. package/lib/app/view/error/unknown.ejs +0 -0
  74. package/lib/app/view/paginate/navlist.ejs +0 -0
  75. package/lib/bootstrap.js +0 -0
  76. package/lib/class/behaviour.js +0 -0
  77. package/lib/class/component.js +0 -0
  78. package/lib/class/conduit.js +14 -4
  79. package/lib/class/controller.js +0 -0
  80. package/lib/class/datasource.js +0 -0
  81. package/lib/class/document.js +0 -0
  82. package/lib/class/document_list.js +0 -0
  83. package/lib/class/element.js +0 -0
  84. package/lib/class/error.js +0 -0
  85. package/lib/class/field.js +0 -0
  86. package/lib/class/field_value.js +0 -0
  87. package/lib/class/helper.js +0 -0
  88. package/lib/class/inode.js +0 -0
  89. package/lib/class/inode_dir.js +0 -0
  90. package/lib/class/inode_file.js +0 -0
  91. package/lib/class/inode_list.js +0 -0
  92. package/lib/class/migration.js +0 -0
  93. package/lib/class/model.js +0 -0
  94. package/lib/class/path_definition.js +0 -0
  95. package/lib/class/path_evaluator.js +0 -0
  96. package/lib/class/path_param_definition.js +0 -0
  97. package/lib/class/postponement.js +0 -0
  98. package/lib/class/reciprocal.js +0 -0
  99. package/lib/class/route.js +0 -0
  100. package/lib/class/router.js +0 -0
  101. package/lib/class/schema.js +0 -0
  102. package/lib/class/schema_client.js +0 -0
  103. package/lib/class/session.js +0 -0
  104. package/lib/class/session_scene.js +0 -0
  105. package/lib/class/sitemap.js +0 -0
  106. package/lib/class/task.js +0 -0
  107. package/lib/core/base.js +0 -0
  108. package/lib/core/client_alchemy.js +57 -0
  109. package/lib/core/client_base.js +0 -0
  110. package/lib/core/discovery.js +0 -0
  111. package/lib/core/middleware.js +0 -0
  112. package/lib/core/routing.js +0 -0
  113. package/lib/core/socket.js +0 -0
  114. package/lib/init/alchemy.js +0 -0
  115. package/lib/init/constants.js +0 -0
  116. package/lib/init/devwatch.js +0 -0
  117. package/lib/init/functions.js +0 -0
  118. package/lib/init/load_functions.js +0 -0
  119. package/lib/init/requirements.js +0 -0
  120. package/lib/stages.js +0 -0
  121. package/package.json +1 -1
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -82,6 +82,15 @@ DataProvider.setAbstractMethod('getAll');
82
82
  */
83
83
  DataProvider.setAbstractMethod('getPage');
84
84
 
85
+ /**
86
+ * Get a single data by id (or other unique identifier)
87
+ *
88
+ * @author Jelle De Loecker <jelle@elevenways.be>
89
+ * @since 1.2.2
90
+ * @version 1.2.2
91
+ */
92
+ DataProvider.setAbstractMethod('getById');
93
+
85
94
  /**
86
95
  * Return an object for json-drying this document
87
96
  *
File without changes
@@ -636,6 +636,42 @@ Document.setMethod(function toDry() {
636
636
  };
637
637
  }, false);
638
638
 
639
+ /**
640
+ * Get the displaytitle of this document, or null
641
+ *
642
+ * @author Jelle De Loecker <jelle@elevenways.be>
643
+ * @since 1.3.13
644
+ * @version 1.3.14
645
+ *
646
+ * @return {String}
647
+ */
648
+ Document.setMethod(function getDisplayTitleOrNull() {
649
+
650
+ if (this.$model) {
651
+ return this.$model.getDisplayTitleOrNull(this);
652
+ }
653
+
654
+ return null;
655
+ });
656
+
657
+ /**
658
+ * Get the displaytitle of this document
659
+ *
660
+ * @author Jelle De Loecker <jelle@elevenways.be>
661
+ * @since 1.3.13
662
+ * @version 1.3.14
663
+ *
664
+ * @return {String}
665
+ */
666
+ Document.setMethod(function getDisplayTitle() {
667
+
668
+ if (this.$model) {
669
+ return this.$model.getDisplayTitle(this);
670
+ }
671
+
672
+ return '';
673
+ });
674
+
639
675
  /**
640
676
  * Actually initialize this instance
641
677
  *
File without changes
File without changes
File without changes
@@ -452,23 +452,22 @@ Model.setMethod(function getFindOptions(options) {
452
452
  return Object.assign({}, def_options, options);
453
453
  });
454
454
 
455
-
456
455
  /**
457
456
  * Get the title to display for this record
458
457
  *
459
458
  * @author Jelle De Loecker <jelle@elevenways.be>
460
459
  * @since 0.0.1
461
- * @version 1.2.7
460
+ * @version 1.3.14
462
461
  *
463
462
  * @param {Object} item The record item of this model
464
463
  * @param {String|Array} fallbacks Extra fallbacks to use
465
464
  *
466
465
  * @return {String} The display title to use
467
466
  */
468
- Model.setMethod(function getDisplayTitle(item, fallbacks) {
467
+ Model.setMethod(function getDisplayTitleOrNull(item, fallbacks) {
469
468
 
470
469
  if (!item) {
471
- return 'Undefined item';
470
+ return null;
472
471
  }
473
472
 
474
473
  let main;
@@ -509,7 +508,38 @@ Model.setMethod(function getDisplayTitle(item, fallbacks) {
509
508
  }
510
509
  }
511
510
 
512
- return main[this.primary_key] || '';
511
+ return null;
512
+ });
513
+
514
+ /**
515
+ * Get the title to display for this record
516
+ *
517
+ * @author Jelle De Loecker <jelle@elevenways.be>
518
+ * @since 0.0.1
519
+ * @version 1.3.14
520
+ *
521
+ * @param {Object} item The record item of this model
522
+ * @param {String|Array} fallbacks Extra fallbacks to use
523
+ *
524
+ * @return {String} The display title to use
525
+ */
526
+ Model.setMethod(function getDisplayTitle(item, fallbacks) {
527
+
528
+ if (!item) {
529
+ return 'Undefined item';
530
+ }
531
+
532
+ let result = this.getDisplayTitleOrNull(item, fallbacks);
533
+
534
+ if (result == null) {
535
+ result = main[this.primary_key] || '';
536
+
537
+ if (result && typeof result != 'string') {
538
+ result = '' + result;
539
+ }
540
+ }
541
+
542
+ return result;
513
543
  });
514
544
 
515
545
  /**
@@ -17,27 +17,77 @@ const RemoteDataProvider = Function.inherits('Alchemy.DataProvider', 'Remote');
17
17
  RemoteDataProvider.addConfig('source');
18
18
 
19
19
  /**
20
- * Get all the data
20
+ * Do a fetch
21
21
  *
22
22
  * @author Jelle De Loecker <jelle@elevenways.be>
23
- * @since 1.2.2
24
- * @version 1.3.12
23
+ * @since 1.3.13
24
+ * @version 1.3.13
25
+ *
26
+ * @return {Pledge|Array}
25
27
  */
26
- RemoteDataProvider.setMethod(async function getAll() {
28
+ RemoteDataProvider.setMethod(function performSourceRequest(type, options) {
27
29
 
28
30
  if (!this.source) {
29
31
  return [];
30
32
  }
31
33
 
32
- let options = {};
34
+ if (!options) {
35
+ options = {};
36
+ }
37
+
38
+ if (!options.get) {
39
+ options.get = {};
40
+ }
33
41
 
34
42
  if (this.context) {
35
- options.get = {
36
- context: this.context
37
- };
43
+ options.get.context = this.context;
38
44
  }
39
45
 
40
- let result = await alchemy.fetch(this.source, options);
46
+ options.get.provider_method = type;
47
+
48
+ return alchemy.fetch(this.source, options);
49
+ });
50
+
51
+ /**
52
+ * Get all the data
53
+ *
54
+ * @author Jelle De Loecker <jelle@elevenways.be>
55
+ * @since 1.2.2
56
+ * @version 1.3.13
57
+ */
58
+ RemoteDataProvider.setMethod(function getAll() {
59
+ return this.performSourceRequest('all');
60
+ });
61
+
62
+ /**
63
+ * Get a specific id
64
+ *
65
+ * @author Jelle De Loecker <jelle@elevenways.be>
66
+ * @since 1.2.2
67
+ * @version 1.3.13
68
+ */
69
+ RemoteDataProvider.setMethod(function getById(id) {
70
+ return this.performSourceRequest('by_id', {
71
+ get: {
72
+ id: id,
73
+ }
74
+ });
75
+ });
41
76
 
42
- return result;
77
+ /**
78
+ * Get a specific page
79
+ *
80
+ * @author Jelle De Loecker <jelle@elevenways.be>
81
+ * @since 1.2.2
82
+ * @version 1.3.13
83
+ *
84
+ * @param {Number} page 1-indexed page number
85
+ */
86
+ RemoteDataProvider.setMethod(function getPage(page) {
87
+ return this.performSourceRequest('page', {
88
+ get: {
89
+ page : page,
90
+ page_size: this.page_size,
91
+ }
92
+ });
43
93
  });
File without changes
File without changes
File without changes
File without changes
package/lib/app/routes.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/lib/bootstrap.js CHANGED
File without changes
File without changes
File without changes
@@ -2033,7 +2033,7 @@ Conduit.setTypedMethod([Types.String, Types.Object.optional()], function serveFi
2033
2033
  *
2034
2034
  * @author Jelle De Loecker <jelle@elevenways.be>
2035
2035
  * @since 0.2.0
2036
- * @version 1.3.0
2036
+ * @version 1.3.13
2037
2037
  *
2038
2038
  * @param {Alchemy.Inode.File} file The file to serve
2039
2039
  * @param {Object} options Options, including headers
@@ -2043,12 +2043,17 @@ Conduit.setTypedMethod([Types.Alchemy.Inode.File, Types.Object.optional()], asyn
2043
2043
  if (file.path && !FILECACHE.has(file.path)) {
2044
2044
  FILECACHE.set(file.path, file);
2045
2045
  }
2046
-
2046
+
2047
+ let stats = await file.getStats();
2048
+
2047
2049
  if (alchemy.settings.cache && (!options.cache_time && options.cache_time !== false)) {
2048
- let stats = await file.getStats();
2049
2050
  options.cache_time = stats.mtime;
2050
2051
  }
2051
2052
 
2053
+ if (options.content_length == null) {
2054
+ options.content_length = stats.size;
2055
+ }
2056
+
2052
2057
  if (!options.mimetype) {
2053
2058
  options.mimetype = await file.getMimetype();
2054
2059
  }
@@ -2121,7 +2126,7 @@ Conduit.setTypedMethod([Types.Stream, Types.Object.optional()], function serveFi
2121
2126
  *
2122
2127
  * @author Jelle De Loecker <jelle@elevenways.be>
2123
2128
  * @since 1.3.0
2124
- * @version 1.3.0
2129
+ * @version 1.3.13
2125
2130
  *
2126
2131
  * @param {Stream} stream The stream to send
2127
2132
  * @param {Object} options Options, including headers
@@ -2177,6 +2182,11 @@ Conduit.setMethod(function _sendStream(stream, options) {
2177
2182
  this.setHeader('content-disposition', disposition);
2178
2183
  }
2179
2184
 
2185
+ // Set the content-length response header when not compressing
2186
+ if (!options.compress && options.content_length != null) {
2187
+ this.setHeader('content-length', options.content_length);
2188
+ }
2189
+
2180
2190
  // Set all the headers
2181
2191
  for (key in options.headers) {
2182
2192
  this.setHeader(key, options.headers[key]);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/class/task.js CHANGED
File without changes
package/lib/core/base.js CHANGED
File without changes
@@ -364,6 +364,63 @@ Alchemy.setMethod(function getValidatorClass(name) {
364
364
  }
365
365
  });
366
366
 
367
+ /**
368
+ * Get the display title of something
369
+ *
370
+ * @author Jelle De Loecker <jelle@elevenways.be>
371
+ * @since 1.3.13
372
+ * @version 1.3.14
373
+ *
374
+ * @param {Object} value
375
+ *
376
+ * @return {String}
377
+ */
378
+ Alchemy.setMethod(function getDisplayTitle(value, max_length) {
379
+
380
+ //.title || value.name || value.slug || value.$pk || value._id || value.id
381
+
382
+ if (!value || Object.isPrimitive(value)) {
383
+
384
+ if (max_length == null) {
385
+ max_length = 48;
386
+ }
387
+
388
+ let result = '' + value;
389
+
390
+ if (result.length > max_length) {
391
+ result = result.truncate(max_length - 2);
392
+ }
393
+
394
+ return result;
395
+ }
396
+
397
+ let type = typeof value;
398
+
399
+ if (type == 'symbol') {
400
+ return value.toString();
401
+ }
402
+
403
+ let result;
404
+
405
+ // `getDisplayTitle` might already return the ID as a fallback,
406
+ // so we prefer `getDisplayTitleOrNull`
407
+ if (typeof value.getDisplayTitleOrNull == 'function') {
408
+ result = value.getDisplayTitleOrNull();
409
+ } else if (typeof value.getDisplayTitle == 'function') {
410
+ result = value.getDisplayTitle();
411
+ }
412
+
413
+ if (result == null || result === '') {
414
+ result = value.title || value.name || value.label || value.slug || value.id || value.$pk || value._id;
415
+ }
416
+
417
+ if (max_length != null && typeof result == 'string' && result.length > max_length) {
418
+ result = result.truncate(max_length - 2);
419
+ }
420
+
421
+ return result || '';
422
+ });
423
+
367
424
  /**
368
425
  * Pick a translation
369
426
  *
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/stages.js CHANGED
File without changes
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.12",
4
+ "version": "1.3.13",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",