alchemymvc 1.3.12 → 1.3.14

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 (111) 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/datasource/mongo_datasource.js +0 -0
  12. package/lib/app/element/time_ago.js +0 -0
  13. package/lib/app/helper/alchemy_helper.js +0 -0
  14. package/lib/app/helper/backed_map.js +0 -0
  15. package/lib/app/helper/breadcrumb.js +0 -0
  16. package/lib/app/helper/client_collection.js +0 -0
  17. package/lib/app/helper/enum_values.js +0 -0
  18. package/lib/app/helper/pagination_helper.js +0 -0
  19. package/lib/app/helper_component/paginate_component.js +0 -0
  20. package/lib/app/helper_controller/component.js +0 -0
  21. package/lib/app/helper_controller/conduit.js +0 -0
  22. package/lib/app/helper_controller/controller.js +0 -0
  23. package/lib/app/helper_datasource/00-nosql_datasource.js +0 -0
  24. package/lib/app/helper_datasource/05-fallback_datasource.js +0 -0
  25. package/lib/app/helper_datasource/idb_datasource.js +0 -0
  26. package/lib/app/helper_datasource/indexed_db.js +0 -0
  27. package/lib/app/helper_datasource/remote_datasource.js +0 -0
  28. package/lib/app/helper_error/http_error.js +0 -0
  29. package/lib/app/helper_error/model_error.js +0 -0
  30. package/lib/app/helper_error/validation_error.js +0 -0
  31. package/lib/app/helper_field/00-objectid_field.js +0 -0
  32. package/lib/app/helper_field/05-string_field.js +0 -0
  33. package/lib/app/helper_field/06-text_field.js +0 -0
  34. package/lib/app/helper_field/10-number_field.js +0 -0
  35. package/lib/app/helper_field/belongsto_field.js +0 -0
  36. package/lib/app/helper_field/big_int_field.js +0 -0
  37. package/lib/app/helper_field/boolean_field.js +0 -0
  38. package/lib/app/helper_field/date_field.js +0 -0
  39. package/lib/app/helper_field/datetime_field.js +0 -0
  40. package/lib/app/helper_field/enum_field.js +0 -0
  41. package/lib/app/helper_field/geopoint_field.js +0 -0
  42. package/lib/app/helper_field/habtm_field.js +0 -0
  43. package/lib/app/helper_field/hasoneparent_field.js +0 -0
  44. package/lib/app/helper_field/html_field.js +0 -0
  45. package/lib/app/helper_field/integer_field.js +0 -0
  46. package/lib/app/helper_field/object_field.js +0 -0
  47. package/lib/app/helper_field/password_field.js +0 -0
  48. package/lib/app/helper_field/regexp_field.js +0 -0
  49. package/lib/app/helper_field/schema_field.js +0 -0
  50. package/lib/app/helper_field/time_field.js +0 -0
  51. package/lib/app/helper_field/url_field.js +0 -0
  52. package/lib/app/helper_model/criteria.js +0 -0
  53. package/lib/app/helper_model/data_provider.js +9 -0
  54. package/lib/app/helper_model/db_query.js +0 -0
  55. package/lib/app/helper_model/document.js +36 -0
  56. package/lib/app/helper_model/document_list.js +0 -0
  57. package/lib/app/helper_model/field_config.js +0 -0
  58. package/lib/app/helper_model/field_set.js +0 -0
  59. package/lib/app/helper_model/model.js +35 -5
  60. package/lib/app/helper_model/remote_data_provider.js +60 -10
  61. package/lib/app/helper_validator/00_validator.js +0 -0
  62. package/lib/app/helper_validator/not_empty_validator.js +0 -0
  63. package/lib/app/model/alchemy_migration_model.js +0 -0
  64. package/lib/app/model/alchemy_task_model.js +0 -0
  65. package/lib/app/view/alchemy/info.hwk +0 -0
  66. package/lib/app/view/error/unknown.ejs +0 -0
  67. package/lib/app/view/paginate/navlist.ejs +0 -0
  68. package/lib/bootstrap.js +0 -0
  69. package/lib/class/behaviour.js +0 -0
  70. package/lib/class/component.js +0 -0
  71. package/lib/class/conduit.js +26 -6
  72. package/lib/class/controller.js +0 -0
  73. package/lib/class/datasource.js +0 -0
  74. package/lib/class/document.js +0 -0
  75. package/lib/class/document_list.js +0 -0
  76. package/lib/class/element.js +0 -0
  77. package/lib/class/error.js +0 -0
  78. package/lib/class/field.js +0 -0
  79. package/lib/class/field_value.js +0 -0
  80. package/lib/class/helper.js +0 -0
  81. package/lib/class/inode.js +0 -0
  82. package/lib/class/inode_dir.js +0 -0
  83. package/lib/class/inode_file.js +0 -0
  84. package/lib/class/inode_list.js +0 -0
  85. package/lib/class/migration.js +0 -0
  86. package/lib/class/model.js +0 -0
  87. package/lib/class/path_definition.js +0 -0
  88. package/lib/class/path_evaluator.js +0 -0
  89. package/lib/class/postponement.js +0 -0
  90. package/lib/class/reciprocal.js +0 -0
  91. package/lib/class/router.js +0 -0
  92. package/lib/class/schema.js +0 -0
  93. package/lib/class/schema_client.js +0 -0
  94. package/lib/class/session.js +0 -0
  95. package/lib/class/session_scene.js +0 -0
  96. package/lib/class/sitemap.js +0 -0
  97. package/lib/class/task.js +0 -0
  98. package/lib/core/base.js +0 -0
  99. package/lib/core/client_alchemy.js +57 -0
  100. package/lib/core/client_base.js +0 -0
  101. package/lib/core/discovery.js +0 -0
  102. package/lib/core/middleware.js +3 -2
  103. package/lib/core/routing.js +0 -0
  104. package/lib/core/socket.js +0 -0
  105. package/lib/init/constants.js +0 -0
  106. package/lib/init/devwatch.js +0 -0
  107. package/lib/init/functions.js +0 -0
  108. package/lib/init/load_functions.js +0 -0
  109. package/lib/init/requirements.js +0 -0
  110. package/lib/stages.js +0 -0
  111. package/package.json +2 -2
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
@@ -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
File without changes
File without changes
File without changes
package/lib/bootstrap.js CHANGED
File without changes
File without changes
File without changes
@@ -1824,7 +1824,7 @@ Conduit.setMethod(function end(message) {
1824
1824
  *
1825
1825
  * @author Jelle De Loecker <jelle@elevenways.be>
1826
1826
  * @since 0.2.0
1827
- * @version 1.3.10
1827
+ * @version 1.3.14
1828
1828
  */
1829
1829
  Conduit.setMethod(function _end(message, encoding = 'utf-8') {
1830
1830
 
@@ -1862,6 +1862,11 @@ Conduit.setMethod(function _end(message, encoding = 'utf-8') {
1862
1862
 
1863
1863
  for (key in this.response_headers) {
1864
1864
  value = this.response_headers[key];
1865
+
1866
+ if (value == null) {
1867
+ continue;
1868
+ }
1869
+
1865
1870
  this.response.setHeader(key, value);
1866
1871
  }
1867
1872
 
@@ -2033,7 +2038,7 @@ Conduit.setTypedMethod([Types.String, Types.Object.optional()], function serveFi
2033
2038
  *
2034
2039
  * @author Jelle De Loecker <jelle@elevenways.be>
2035
2040
  * @since 0.2.0
2036
- * @version 1.3.0
2041
+ * @version 1.3.13
2037
2042
  *
2038
2043
  * @param {Alchemy.Inode.File} file The file to serve
2039
2044
  * @param {Object} options Options, including headers
@@ -2043,12 +2048,17 @@ Conduit.setTypedMethod([Types.Alchemy.Inode.File, Types.Object.optional()], asyn
2043
2048
  if (file.path && !FILECACHE.has(file.path)) {
2044
2049
  FILECACHE.set(file.path, file);
2045
2050
  }
2046
-
2051
+
2052
+ let stats = await file.getStats();
2053
+
2047
2054
  if (alchemy.settings.cache && (!options.cache_time && options.cache_time !== false)) {
2048
- let stats = await file.getStats();
2049
2055
  options.cache_time = stats.mtime;
2050
2056
  }
2051
2057
 
2058
+ if (options.content_length == null) {
2059
+ options.content_length = stats.size;
2060
+ }
2061
+
2052
2062
  if (!options.mimetype) {
2053
2063
  options.mimetype = await file.getMimetype();
2054
2064
  }
@@ -2121,7 +2131,7 @@ Conduit.setTypedMethod([Types.Stream, Types.Object.optional()], function serveFi
2121
2131
  *
2122
2132
  * @author Jelle De Loecker <jelle@elevenways.be>
2123
2133
  * @since 1.3.0
2124
- * @version 1.3.0
2134
+ * @version 1.3.14
2125
2135
  *
2126
2136
  * @param {Stream} stream The stream to send
2127
2137
  * @param {Object} options Options, including headers
@@ -2194,9 +2204,13 @@ Conduit.setMethod(function _sendStream(stream, options) {
2194
2204
  // Set the gzip header
2195
2205
  this.setHeader('content-encoding', 'gzip');
2196
2206
  this.setHeader('vary', 'accept-encoding');
2207
+ this.setHeader('transfer-encoding', 'chunked');
2208
+ this.setHeader('content-length', null);
2197
2209
 
2198
2210
  // Create the gzip stream
2199
2211
  out_stream = out_stream.pipe(zlib.createGzip());
2212
+ } else if (options.content_length != null) {
2213
+ this.setHeader('content-length', options.content_length);
2200
2214
  }
2201
2215
 
2202
2216
  if (options.cleanup_stream) {
@@ -2219,7 +2233,13 @@ Conduit.setMethod(function _sendStream(stream, options) {
2219
2233
 
2220
2234
  // Set the response headers
2221
2235
  for (key in this.response_headers) {
2222
- response.setHeader(key, this.response_headers[key]);
2236
+ let value = this.response_headers[key];
2237
+
2238
+ if (value == null) {
2239
+ continue;
2240
+ }
2241
+
2242
+ response.setHeader(key, value);
2223
2243
  }
2224
2244
 
2225
2245
  if (this.new_cookie_header.length) {
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
@@ -444,9 +444,10 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
444
444
  };
445
445
 
446
446
  if (alchemy.settings.debug && alchemy.settings.source_map) {
447
- minify_options.sourceMap = {
447
+ console.warn('Source maps have been disabled because alchemy.settings.minify_js is true');
448
+ /*minify_options.sourceMap = {
448
449
  url: 'inline'
449
- };
450
+ };*/
450
451
  }
451
452
 
452
453
  result = await Terser.minify(data, minify_options);
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.14",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",
@@ -36,7 +36,7 @@
36
36
  "socket.io" : "~4.6.0",
37
37
  "@11ways/socket.io-stream" : "~0.9.2",
38
38
  "sputnik" : "~0.1.0",
39
- "terser" : "~5.16.3",
39
+ "terser" : "~5.18.1",
40
40
  "toobusy-js" : "~0.5.1",
41
41
  "useragent" : "~2.3.0"
42
42
  },