alchemymvc 1.2.4 → 1.2.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.
Files changed (86) 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 +173 -173
  11. package/lib/app/conduit/socket_conduit.js +620 -620
  12. package/lib/app/controller/alchemy_info_controller.js +0 -0
  13. package/lib/app/datasource/mongo_datasource.js +0 -0
  14. package/lib/app/helper/client_collection.js +0 -0
  15. package/lib/app/helper/pagination_helper.js +0 -0
  16. package/lib/app/helper/router_helper.js +135 -3
  17. package/lib/app/helper/socket_helper.js +613 -613
  18. package/lib/app/helper_component/paginate_component.js +3 -1
  19. package/lib/app/helper_controller/component.js +0 -0
  20. package/lib/app/helper_controller/conduit.js +20 -0
  21. package/lib/app/helper_controller/controller.js +0 -0
  22. package/lib/app/helper_datasource/00-nosql_datasource.js +0 -0
  23. package/lib/app/helper_datasource/05-fallback_datasource.js +0 -0
  24. package/lib/app/helper_datasource/idb_datasource.js +0 -0
  25. package/lib/app/helper_datasource/indexed_db.js +0 -0
  26. package/lib/app/helper_field/00-objectid_field.js +0 -0
  27. package/lib/app/helper_field/06-text_field.js +0 -0
  28. package/lib/app/helper_field/10-number_field.js +0 -0
  29. package/lib/app/helper_field/boolean_field.js +0 -0
  30. package/lib/app/helper_field/date_field.js +0 -0
  31. package/lib/app/helper_field/datetime_field.js +0 -0
  32. package/lib/app/helper_field/enum_field.js +0 -0
  33. package/lib/app/helper_field/geopoint_field.js +0 -0
  34. package/lib/app/helper_field/habtm_field.js +0 -0
  35. package/lib/app/helper_field/hasoneparent_field.js +0 -0
  36. package/lib/app/helper_field/html_field.js +0 -0
  37. package/lib/app/helper_field/integer_field.js +0 -0
  38. package/lib/app/helper_field/object_field.js +0 -0
  39. package/lib/app/helper_field/regexp_field.js +0 -0
  40. package/lib/app/helper_field/schema_field.js +23 -2
  41. package/lib/app/helper_field/time_field.js +0 -0
  42. package/lib/app/helper_field/url_field.js +0 -0
  43. package/lib/app/helper_model/criteria.js +26 -1
  44. package/lib/app/helper_model/db_query.js +0 -0
  45. package/lib/app/helper_model/document.js +20 -12
  46. package/lib/app/helper_model/document_list.js +0 -0
  47. package/lib/app/helper_model/field_config.js +25 -12
  48. package/lib/app/helper_model/field_set.js +22 -1
  49. package/lib/app/helper_model/model.js +22 -10
  50. package/lib/app/model/alchemy_task_model.js +0 -0
  51. package/lib/app/routes.js +0 -0
  52. package/lib/app/view/alchemy/info.ejs +0 -0
  53. package/lib/app/view/error/unknown.ejs +0 -0
  54. package/lib/app/view/paginate/navlist.ejs +0 -0
  55. package/lib/bootstrap.js +0 -0
  56. package/lib/class/behaviour.js +0 -0
  57. package/lib/class/component.js +0 -0
  58. package/lib/class/conduit.js +2555 -2474
  59. package/lib/class/controller.js +4 -1
  60. package/lib/class/document_list.js +0 -0
  61. package/lib/class/element.js +2 -11
  62. package/lib/class/field.js +7 -1
  63. package/lib/class/helper.js +0 -0
  64. package/lib/class/inode.js +0 -0
  65. package/lib/class/inode_dir.js +0 -0
  66. package/lib/class/inode_file.js +112 -112
  67. package/lib/class/inode_list.js +0 -0
  68. package/lib/class/model.js +1772 -1761
  69. package/lib/class/path_definition.js +0 -0
  70. package/lib/class/route.js +92 -61
  71. package/lib/class/router.js +80 -3
  72. package/lib/class/schema_client.js +7 -2
  73. package/lib/class/session.js +0 -0
  74. package/lib/class/task.js +0 -0
  75. package/lib/core/base.js +50 -9
  76. package/lib/core/client_alchemy.js +48 -43
  77. package/lib/core/discovery.js +0 -0
  78. package/lib/core/middleware.js +72 -7
  79. package/lib/core/routing.js +0 -0
  80. package/lib/core/socket.js +159 -159
  81. package/lib/init/alchemy.js +1823 -1823
  82. package/lib/init/constants.js +0 -0
  83. package/lib/init/functions.js +8 -4
  84. package/lib/init/load_functions.js +0 -0
  85. package/lib/init/requirements.js +101 -101
  86. package/package.json +74 -73
@@ -15,7 +15,7 @@ const Paginate = Function.inherits('Alchemy.Client.Component', 'Paginate');
15
15
  *
16
16
  * @author Jelle De Loecker <jelle@elevenways.be>
17
17
  * @since 0.0.1
18
- * @version 1.2.2
18
+ * @version 1.2.5
19
19
  *
20
20
  * @param {Model} model
21
21
  * @param {Criteria} criteria
@@ -26,6 +26,8 @@ Paginate.setMethod(function find(model, criteria) {
26
26
 
27
27
  const conduit = this.controller.conduit;
28
28
 
29
+ criteria = Blast.Classes.Alchemy.Criteria.Criteria.cast(criteria);
30
+
29
31
  // Get the model if a name has been given
30
32
  if (typeof model == 'string') {
31
33
  model = this.getModel(model);
File without changes
@@ -405,6 +405,26 @@ Conduit.setMethod(function chooseBestLocale(locales) {
405
405
  return 'en';
406
406
  });
407
407
 
408
+ /**
409
+ * Check if this request has a permission
410
+ *
411
+ * @author Jelle De Loecker <jelle@elevenways.be>
412
+ * @since 1.2.5
413
+ * @version 1.2.5
414
+ *
415
+ * @param {String} permission
416
+ *
417
+ * @return {Boolean} True if the user has the permission, false otherwise
418
+ */
419
+ Conduit.setMethod(function hasPermission(permission) {
420
+
421
+ if (alchemy.permission_checker != null) {
422
+ return alchemy.permission_checker.conduitHasPermission(this, permission);
423
+ }
424
+
425
+ return false;
426
+ });
427
+
408
428
  if (Blast.isNode) {
409
429
  return;
410
430
  }
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
@@ -364,7 +364,7 @@ SchemaField.setMethod(function _toApp(query, options, value, callback) {
364
364
  *
365
365
  * @author Jelle De Loecker <jelle@elevenways.be>
366
366
  * @since 1.1.4
367
- * @version 1.1.4
367
+ * @version 1.2.6
368
368
  */
369
369
  SchemaField.setMethod(function translateRecord(prefixes, record, allow_empty) {
370
370
 
@@ -373,11 +373,18 @@ SchemaField.setMethod(function translateRecord(prefixes, record, allow_empty) {
373
373
  translateRecord.super.call(this, prefixes, record, allow_empty);
374
374
  }
375
375
 
376
+ if (!record.$translated_fields) {
377
+ record.$translated_fields = {};
378
+ }
379
+
376
380
  // Turn it into an array, some already are (is_array fields)
377
381
  let subject = Array.cast(record[this.name]),
378
- schema_record;
382
+ schema_record,
383
+ count = -1;
379
384
 
380
385
  for (schema_record of subject) {
386
+ count++;
387
+
381
388
  if (this.field_schema.hasTranslations && schema_record) {
382
389
 
383
390
  let field_name,
@@ -386,6 +393,20 @@ SchemaField.setMethod(function translateRecord(prefixes, record, allow_empty) {
386
393
  for (field_name in this.field_schema.translatableFields) {
387
394
  field = this.field_schema.translatableFields[field_name];
388
395
  field.translateRecord(prefixes, schema_record, allow_empty);
396
+
397
+ if (schema_record.$translated_fields) {
398
+ for (let key in schema_record.$translated_fields) {
399
+ let path = this.name;
400
+
401
+ if (this.is_array) {
402
+ path += '.' + count;
403
+ }
404
+
405
+ path += '.' + key;
406
+
407
+ record.$translated_fields[path] = schema_record.$translated_fields[key];
408
+ }
409
+ }
389
410
  }
390
411
  }
391
412
  }
File without changes
File without changes
@@ -53,6 +53,31 @@ Criteria.setStatic(function isCriteria(instance) {
53
53
  return false;
54
54
  });
55
55
 
56
+ /**
57
+ * Make sure to get a criteria
58
+ *
59
+ * @author Jelle De Loecker <jelle@elevenways.be>
60
+ * @since 1.2.5
61
+ * @version 1.2.5
62
+ *
63
+ * @param {Object} obj
64
+ *
65
+ * @return {Criteria}
66
+ */
67
+ Criteria.setStatic(function cast(obj) {
68
+
69
+ if (Criteria.isCriteria(obj)) {
70
+ return obj;
71
+ }
72
+
73
+ let instance = new Criteria();
74
+
75
+ if (obj) {
76
+ instance.applyOldOptions(obj);
77
+ }
78
+
79
+ return instance;
80
+ });
56
81
 
57
82
  /**
58
83
  * Undry the given object
@@ -81,7 +106,7 @@ Criteria.setStatic(function unDry(data) {
81
106
  // Revive the group instance
82
107
  criteria.group = Group.revive(data.group, criteria);
83
108
 
84
- if(!data.options) {
109
+ if (!data.options) {
85
110
  data.options = {};
86
111
  }
87
112
 
File without changes
@@ -305,7 +305,7 @@ Document.setStatic(function getDocumentClass(model) {
305
305
  *
306
306
  * @author Jelle De Loecker <jelle@develry.be>
307
307
  * @since 1.0.0
308
- * @version 1.2.4
308
+ * @version 1.2.5
309
309
  *
310
310
  * @param {Object} obj
311
311
  * @param {Boolean|String} cloned
@@ -365,6 +365,7 @@ Document.setStatic(function unDry(obj, cloned) {
365
365
  }
366
366
 
367
367
  model.schema.addField(field.name, field.constructor.type_name, field.options);
368
+ model.constructor.Document.setFieldGetter(field.name);
368
369
  }
369
370
  }
370
371
 
@@ -638,9 +639,9 @@ Document.setMethod(function toDry() {
638
639
  /**
639
640
  * Actually initialize this instance
640
641
  *
641
- * @author Jelle De Loecker <jelle@develry.be>
642
+ * @author Jelle De Loecker <jelle@elevenways.be>
642
643
  * @since 1.0.4
643
- * @version 1.2.4
644
+ * @version 1.2.5
644
645
  *
645
646
  * @param {Object} record
646
647
  * @param {Object} options
@@ -680,9 +681,13 @@ Document.setMethod(function setDataRecord(record, options) {
680
681
  // The original record
681
682
  this.$record = record;
682
683
 
684
+ // @TODO: Find a cleaner way of setting these values
685
+ if (record[name].$translated_fields) {
686
+ this.$hold.translated_fields = record[name].$translated_fields;
687
+ }
688
+
683
689
  if (Blast.isNode && this.constructor.namespace.indexOf('Alchemy.Document') == -1) {
684
- let delete_field = false,
685
- added_private_field_info = false,
690
+ let delete_field,
686
691
  field,
687
692
  key;
688
693
 
@@ -696,20 +701,23 @@ Document.setMethod(function setDataRecord(record, options) {
696
701
 
697
702
  if (options.keep_private_fields) {
698
703
  delete_field = false;
699
-
700
- if (!added_private_field_info) {
701
- added_private_field_info = true;
702
-
703
- let fields = this.$model.schema.getPrivateFields();
704
- options.private_fields = JSON.clone(fields, 'toHawkejs');
705
- }
706
704
  }
705
+ } else {
706
+ delete_field = false;
707
707
  }
708
708
 
709
709
  if (delete_field) {
710
710
  delete this.$main[key];
711
711
  }
712
712
  }
713
+
714
+ if (options?.keep_private_fields) {
715
+ let fields = this.$model.schema.getPrivateFields();
716
+
717
+ if (fields?.length) {
718
+ options.private_fields = JSON.clone(fields, 'toHawkejs');
719
+ }
720
+ }
713
721
  }
714
722
 
715
723
  // If this has object fields we need to clone the document already
File without changes
@@ -131,7 +131,7 @@ FieldConfig.setMethod(function getContextModel() {
131
131
  *
132
132
  * @author Jelle De Loecker <jelle@elevenways.be>
133
133
  * @since 1.2.2
134
- * @version 1.2.2
134
+ * @version 1.2.5
135
135
  */
136
136
  FieldConfig.setMethod(function getModel() {
137
137
 
@@ -142,13 +142,15 @@ FieldConfig.setMethod(function getModel() {
142
142
  }
143
143
 
144
144
  if (this.association) {
145
- let config = model.getAssociation(this.association);
145
+ try {
146
+ let config = model.getAssociation(this.association);
146
147
 
147
- if (config) {
148
- model = alchemy.getModel(config.modelName);
149
- } else {
150
- model = null;
151
- }
148
+ if (config) {
149
+ model = alchemy.getModel(config.modelName);
150
+ } else {
151
+ model = null;
152
+ }
153
+ } catch (ignored_error) {}
152
154
  }
153
155
 
154
156
  return model;
@@ -159,17 +161,28 @@ FieldConfig.setMethod(function getModel() {
159
161
  *
160
162
  * @author Jelle De Loecker <jelle@elevenways.be>
161
163
  * @since 1.2.2
162
- * @version 1.2.2
164
+ * @version 1.2.5
165
+ *
166
+ * @return {Field}
163
167
  */
164
168
  FieldConfig.setMethod(function getFieldDefinition() {
165
169
 
166
- let model = this.getModel();
170
+ let model = this.getModel(),
171
+ result;
167
172
 
168
- if (!model) {
169
- return;
173
+ if (model) {
174
+ result = model.getField(this.local_path);
170
175
  }
171
176
 
172
- return model.getField(this.local_path);
177
+ if (!result && this.options?.type) {
178
+ let constructor = Classes.Alchemy.Field.Field.getMember(this.options.type);
179
+
180
+ if (constructor) {
181
+ result = new constructor(null, this.name);
182
+ }
183
+ }
184
+
185
+ return result;
173
186
  });
174
187
 
175
188
  /**
@@ -65,7 +65,7 @@ FieldSet.setStatic(function fromArray(fields) {
65
65
  *
66
66
  * @author Jelle De Loecker <jelle@elevenways.be>
67
67
  * @since 1.1.3
68
- * @version 1.1.3
68
+ * @version 1.2.5
69
69
  *
70
70
  * @type {Deck}
71
71
  */
@@ -88,6 +88,14 @@ FieldSet.enforceProperty(function fields(new_value, old_value) {
88
88
  };
89
89
  }
90
90
 
91
+ if (!entry.options) {
92
+ entry.options = {};
93
+ }
94
+
95
+ if (entry.type) {
96
+ entry.options.type = entry.type;
97
+ }
98
+
91
99
  field = new Classes.Alchemy.Criteria.FieldConfig(entry.name, entry.options);
92
100
  deck.set(entry.name, field);
93
101
  }
@@ -205,4 +213,17 @@ FieldSet.setMethod(function addField(name, options) {
205
213
  this.fields.set(name, config);
206
214
 
207
215
  return config;
216
+ });
217
+
218
+ /**
219
+ * Get a fieldconfig by its field name
220
+ *
221
+ * @author Jelle De Loecker <jelle@elevenways.be>
222
+ * @since 1.2.5
223
+ * @version 1.2.5
224
+ *
225
+ * @return {Alchemy.Form.FieldConfig}
226
+ */
227
+ FieldSet.setMethod(function get(name) {
228
+ return this.fields.get(name);
208
229
  });
@@ -32,7 +32,7 @@ if (Blast.isBrowser) {
32
32
  *
33
33
  * @param {Object} options
34
34
  */
35
- var Model = Function.inherits('Alchemy.Client.Base', 'Alchemy.Client.Model', function Model(options) {
35
+ const Model = Function.inherits('Alchemy.Client.Base', 'Alchemy.Client.Model', function Model(options) {
36
36
  this.init(options);
37
37
  });
38
38
 
@@ -49,6 +49,22 @@ Model.constitute(function setModelName() {
49
49
  this.table = this.model_name.tableize();
50
50
  });
51
51
 
52
+ /**
53
+ * Map these events to methods
54
+ *
55
+ * @author Jelle De Loecker <jelle@elevenways.be>
56
+ * @since 1.2.5
57
+ * @version 1.2.5
58
+ */
59
+ Model.mapEventToMethod({
60
+ saved : 'afterSave',
61
+ finding : 'beforeFind',
62
+ queried : 'afterQuery',
63
+ associated : 'afterAssociated',
64
+ found : 'afterData',
65
+ foundDocuments : 'afterFind',
66
+ });
67
+
52
68
  /**
53
69
  * Is the given action enabled on the server?
54
70
  *
@@ -485,7 +501,7 @@ Model.setMethod(function getAliasModel(alias) {
485
501
  *
486
502
  * @author Jelle De Loecker <jelle@develry.be>
487
503
  * @since 0.0.1
488
- * @version 1.1.3
504
+ * @version 1.2.5
489
505
  *
490
506
  * @param {String} type The type of find (first, all)
491
507
  * @param {Criteria} criteria The criteria object
@@ -530,14 +546,10 @@ Model.setMethod(function find(type, criteria, callback) {
530
546
  error = new TypeError('Find type should be a string');
531
547
  }
532
548
 
533
- if (!Blast.Classes.Alchemy.Criteria.Criteria.isCriteria(criteria)) {
534
- try {
535
- let options = criteria;
536
- criteria = new Blast.Classes.Alchemy.Criteria();
537
- criteria.applyOldOptions(options);
538
- } catch (err) {
539
- error = err;
540
- }
549
+ try {
550
+ criteria = Blast.Classes.Alchemy.Criteria.Criteria.cast(criteria);
551
+ } catch (err) {
552
+ error = err;
541
553
  }
542
554
 
543
555
  if (error != null) {
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