alchemymvc 1.3.22 → 1.4.0-alpha.2
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/LICENSE +1 -1
- package/README.md +3 -3
- package/lib/app/behaviour/publishable_behaviour.js +5 -5
- package/lib/app/behaviour/revision_behaviour.js +96 -59
- package/lib/app/behaviour/sluggable_behaviour.js +14 -14
- package/lib/app/conduit/electron_conduit.js +9 -9
- package/lib/app/conduit/http_conduit.js +13 -13
- package/lib/app/conduit/loopback_conduit.js +15 -15
- package/lib/app/conduit/socket_conduit.js +43 -43
- package/lib/app/config/routes.js +26 -0
- package/lib/app/controller/00-default_app_controller.js +21 -0
- package/lib/app/controller/alchemy_info_controller.js +12 -12
- package/lib/app/datasource/mongo_datasource.js +27 -18
- package/lib/app/element/00-default_app_element.js +19 -0
- package/lib/app/element/time_ago.js +5 -5
- package/lib/app/helper/00-default_app_helper.js +11 -0
- package/lib/app/helper/alchemy_helper.js +22 -22
- package/lib/app/helper/backed_map.js +1 -1
- package/lib/app/helper/breadcrumb.js +10 -10
- package/lib/app/helper/client_collection.js +3 -3
- package/lib/app/helper/cron.js +29 -29
- package/lib/app/helper/enum_values.js +6 -6
- package/lib/app/helper/pagination_helper.js +36 -36
- package/lib/app/helper/router_helper.js +35 -35
- package/lib/app/helper/socket_helper.js +57 -57
- package/lib/app/helper/syncable.js +62 -62
- package/lib/app/helper_component/paginate_component.js +9 -9
- package/lib/app/helper_controller/component.js +1 -1
- package/lib/app/helper_controller/conduit.js +31 -31
- package/lib/app/helper_controller/controller.js +54 -39
- package/lib/app/helper_datasource/00-nosql_datasource.js +624 -70
- package/lib/app/helper_datasource/05-fallback_datasource.js +10 -10
- package/lib/app/helper_datasource/idb_datasource.js +6 -6
- package/lib/app/helper_datasource/indexed_db.js +22 -22
- package/lib/app/helper_datasource/remote_datasource.js +5 -5
- package/lib/app/helper_error/http_error.js +4 -4
- package/lib/app/helper_error/model_error.js +2 -2
- package/lib/app/helper_error/validation_error.js +12 -12
- package/lib/app/helper_field/00-objectid_field.js +7 -7
- package/lib/app/helper_field/05-string_field.js +16 -12
- package/lib/app/helper_field/06-text_field.js +2 -4
- package/lib/app/helper_field/10-number_field.js +9 -12
- package/lib/app/helper_field/11-date_field.js +15 -15
- package/lib/app/helper_field/15-local_temporal_field.js +10 -10
- package/lib/app/helper_field/20-decimal_field.js +8 -9
- package/lib/app/helper_field/belongsto_field.js +1 -1
- package/lib/app/helper_field/big_int_field.js +8 -8
- package/lib/app/helper_field/boolean_field.js +9 -11
- package/lib/app/helper_field/datetime_field.js +3 -3
- package/lib/app/helper_field/enum_field.js +13 -8
- package/lib/app/helper_field/fixed_decimal_field.js +6 -7
- package/lib/app/helper_field/geopoint_field.js +9 -10
- package/lib/app/helper_field/habtm_field.js +3 -3
- package/lib/app/helper_field/hasoneparent_field.js +1 -1
- package/lib/app/helper_field/html_field.js +2 -4
- package/lib/app/helper_field/integer_field.js +8 -11
- package/lib/app/helper_field/local_date_field.js +5 -5
- package/lib/app/helper_field/local_date_time_field.js +5 -5
- package/lib/app/helper_field/local_time_field.js +5 -5
- package/lib/app/helper_field/mixed_field.js +5 -5
- package/lib/app/helper_field/object_field.js +6 -6
- package/lib/app/helper_field/password_field.js +3 -3
- package/lib/app/helper_field/regexp_field.js +7 -9
- package/lib/app/helper_field/schema_field.js +91 -88
- package/lib/app/helper_field/settings_field.js +92 -0
- package/lib/app/helper_field/time_field.js +6 -6
- package/lib/app/helper_field/url_field.js +2 -4
- package/lib/app/helper_model/00-base_criteria.js +662 -0
- package/lib/app/helper_model/05-criteria_expressions.js +605 -0
- package/lib/app/helper_model/10-model_criteria.js +1182 -0
- package/lib/app/helper_model/data_provider.js +2 -2
- package/lib/app/helper_model/document.js +103 -92
- package/lib/app/helper_model/document_list.js +14 -14
- package/lib/app/helper_model/field_config.js +11 -11
- package/lib/app/helper_model/field_set.js +17 -17
- package/lib/app/helper_model/model.js +201 -123
- package/lib/app/helper_model/remote_data_provider.js +2 -2
- package/lib/app/helper_validator/00_validator.js +16 -16
- package/lib/app/helper_validator/not_empty_validator.js +9 -9
- package/lib/app/model/00-default_app_model.js +18 -0
- package/lib/app/model/05-system_model.js +27 -0
- package/lib/app/model/{alchemy_migration_model.js → system_migration_model.js} +4 -4
- package/lib/app/model/system_setting_model.js +154 -0
- package/lib/app/model/{alchemy_task_history_model.js → system_task_history_model.js} +7 -7
- package/lib/app/model/{alchemy_task_model.js → system_task_model.js} +11 -11
- package/lib/bootstrap.js +22 -312
- package/lib/class/accumulator.js +5 -5
- package/lib/class/behaviour.js +5 -5
- package/lib/class/component.js +3 -3
- package/lib/class/conduit.js +152 -150
- package/lib/class/controller.js +42 -42
- package/lib/class/datasource.js +74 -79
- package/lib/class/document.js +74 -95
- package/lib/class/document_list.js +5 -5
- package/lib/class/element.js +17 -17
- package/lib/class/error.js +3 -3
- package/lib/class/field.js +169 -91
- package/lib/class/field_value.js +6 -6
- package/lib/class/helper.js +3 -3
- package/lib/class/inode.js +17 -17
- package/lib/class/inode_dir.js +12 -12
- package/lib/class/inode_file.js +26 -26
- package/lib/class/inode_list.js +4 -4
- package/lib/class/migration.js +4 -4
- package/lib/class/model.js +146 -165
- package/lib/class/path_definition.js +22 -22
- package/lib/class/path_evaluator.js +5 -5
- package/lib/class/path_param_definition.js +7 -7
- package/lib/class/plugin.js +312 -0
- package/lib/class/postponement.js +29 -29
- package/lib/class/reciprocal.js +8 -8
- package/lib/class/route.js +33 -33
- package/lib/class/router.js +73 -73
- package/lib/class/schema.js +21 -21
- package/lib/class/schema_client.js +105 -82
- package/lib/class/session.js +63 -29
- package/lib/class/session_scene.js +4 -4
- package/lib/class/sitemap.js +16 -16
- package/lib/class/task.js +39 -39
- package/lib/class/task_service.js +43 -47
- package/lib/{init → core}/alchemy.js +411 -373
- package/lib/{init/functions.js → core/alchemy_functions.js} +113 -91
- package/lib/core/alchemy_load_functions.js +715 -0
- package/lib/core/base.js +50 -62
- package/lib/core/client_alchemy.js +144 -152
- package/lib/core/client_base.js +27 -50
- package/lib/core/discovery.js +16 -18
- package/lib/core/middleware.js +54 -43
- package/lib/core/{routing.js → prefix.js} +14 -16
- package/lib/core/setting.js +1684 -0
- package/lib/core/stage.js +758 -0
- package/lib/scripts/create_constants.js +119 -0
- package/lib/{init/languages.js → scripts/create_languages.js} +5 -5
- package/lib/scripts/create_settings.js +449 -0
- package/lib/scripts/create_shared_constants.js +95 -0
- package/lib/scripts/create_stages.js +55 -0
- package/lib/scripts/init_alchemy.js +51 -0
- package/lib/{init/requirements.js → scripts/preload_modules.js} +15 -2
- package/lib/scripts/setup_devwatch.js +238 -0
- package/lib/stages/00-load_core.js +342 -0
- package/lib/stages/05-load_app.js +57 -0
- package/lib/stages/10-datasource.js +61 -0
- package/lib/stages/15-tasks.js +27 -0
- package/lib/stages/20-settings.js +68 -0
- package/lib/stages/50-routes.js +218 -0
- package/lib/stages/90-server.js +347 -0
- package/package.json +5 -7
- package/lib/app/helper_model/criteria.js +0 -2294
- package/lib/app/helper_model/db_query.js +0 -1488
- package/lib/app/routes.js +0 -11
- package/lib/core/socket.js +0 -171
- package/lib/init/constants.js +0 -158
- package/lib/init/devwatch.js +0 -238
- package/lib/init/load_functions.js +0 -979
- package/lib/stages.js +0 -515
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @constructor
|
|
6
6
|
*
|
|
7
|
-
* @author Jelle De Loecker
|
|
7
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
8
8
|
* @since 1.1.0
|
|
9
9
|
* @version 1.1.0
|
|
10
10
|
*
|
|
@@ -21,11 +21,11 @@ const Schema = Function.inherits(['Deck', 'Alchemy.Client.Base'], 'Alchemy.Clien
|
|
|
21
21
|
/**
|
|
22
22
|
* Add a relation creator method
|
|
23
23
|
*
|
|
24
|
-
* @author Jelle De Loecker
|
|
24
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
25
25
|
* @since 1.3.4
|
|
26
26
|
* @version 1.3.4
|
|
27
27
|
*
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {string} relation_type
|
|
29
29
|
*/
|
|
30
30
|
Schema.setStatic(function addRelationCreator(relation_type, relation_config) {
|
|
31
31
|
|
|
@@ -39,13 +39,13 @@ Schema.setStatic(function addRelationCreator(relation_type, relation_config) {
|
|
|
39
39
|
/**
|
|
40
40
|
* Is the given variable a schema?
|
|
41
41
|
*
|
|
42
|
-
* @author Jelle De Loecker
|
|
42
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
43
43
|
* @since 1.1.0
|
|
44
44
|
* @version 1.1.0
|
|
45
45
|
*
|
|
46
46
|
* @param {Mixed} value
|
|
47
47
|
*
|
|
48
|
-
* @return {
|
|
48
|
+
* @return {boolean}
|
|
49
49
|
*/
|
|
50
50
|
Schema.setStatic(function isSchema(value) {
|
|
51
51
|
|
|
@@ -65,7 +65,7 @@ Schema.setStatic(function isSchema(value) {
|
|
|
65
65
|
*
|
|
66
66
|
* @TODO: Make Client.Schema & Schema use the same implementation
|
|
67
67
|
*
|
|
68
|
-
* @author Jelle De Loecker
|
|
68
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
69
69
|
* @since 1.1.0
|
|
70
70
|
* @version 1.1.3
|
|
71
71
|
*
|
|
@@ -107,7 +107,7 @@ Schema.setDeprecatedProperty('hasBehaviours', 'has_behaviours');
|
|
|
107
107
|
/**
|
|
108
108
|
* Set a reference to itself
|
|
109
109
|
*
|
|
110
|
-
* @author Jelle De Loecker
|
|
110
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
111
111
|
* @since 0.2.0
|
|
112
112
|
* @version 0.2.0
|
|
113
113
|
*
|
|
@@ -121,7 +121,7 @@ Schema.setProperty(function schema() {
|
|
|
121
121
|
* Set a reference to the root schema
|
|
122
122
|
* (For nested schemas)
|
|
123
123
|
*
|
|
124
|
-
* @author Jelle De Loecker
|
|
124
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
125
125
|
* @since 1.1.0
|
|
126
126
|
* @version 1.1.0
|
|
127
127
|
*
|
|
@@ -139,11 +139,11 @@ Schema.setProperty(function root_schema() {
|
|
|
139
139
|
/**
|
|
140
140
|
* Amount of fields in this schema
|
|
141
141
|
*
|
|
142
|
-
* @author Jelle De Loecker
|
|
142
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
143
143
|
* @since 1.1.3
|
|
144
144
|
* @version 1.1.3
|
|
145
145
|
*
|
|
146
|
-
* @type {
|
|
146
|
+
* @type {number}
|
|
147
147
|
*/
|
|
148
148
|
Schema.setProperty(function field_count() {
|
|
149
149
|
|
|
@@ -159,7 +159,7 @@ Schema.setProperty(function field_count() {
|
|
|
159
159
|
* @since 1.3.0
|
|
160
160
|
* @version 1.3.0
|
|
161
161
|
*
|
|
162
|
-
* @type {
|
|
162
|
+
* @type {boolean}
|
|
163
163
|
*/
|
|
164
164
|
Schema.setProperty(function has_translatable_fields() {
|
|
165
165
|
return this.has_translations;
|
|
@@ -168,7 +168,7 @@ Schema.setProperty(function has_translatable_fields() {
|
|
|
168
168
|
/**
|
|
169
169
|
* Add the relationships
|
|
170
170
|
*
|
|
171
|
-
* @author Jelle De Loecker
|
|
171
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
172
172
|
* @since 0.2.0
|
|
173
173
|
* @version 1.3.4
|
|
174
174
|
*/
|
|
@@ -181,12 +181,12 @@ Schema.addRelationCreator('HasOneChild', {internal: false, singular: tru
|
|
|
181
181
|
/**
|
|
182
182
|
* Browser-side association adder
|
|
183
183
|
*
|
|
184
|
-
* @author Jelle De Loecker
|
|
184
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
185
185
|
* @since 1.3.4
|
|
186
186
|
* @version 1.3.21
|
|
187
187
|
*
|
|
188
|
-
* @param {
|
|
189
|
-
* @param {
|
|
188
|
+
* @param {string} alias
|
|
189
|
+
* @param {string} modelname
|
|
190
190
|
* @param {Object} options
|
|
191
191
|
*
|
|
192
192
|
* @return {Object}
|
|
@@ -237,13 +237,13 @@ Schema.setMethod(function addAssociation(relation_type, relation_config, alias,
|
|
|
237
237
|
/**
|
|
238
238
|
* Conform association arguments
|
|
239
239
|
*
|
|
240
|
-
* @author Jelle De Loecker
|
|
240
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
241
241
|
* @since 0.2.0
|
|
242
|
-
* @version 1.
|
|
242
|
+
* @version 1.4.0
|
|
243
243
|
*
|
|
244
|
-
* @param {
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
244
|
+
* @param {boolean} is_internal Is this internal (A remote record's id is stored inside this record)
|
|
245
|
+
* @param {string} alias
|
|
246
|
+
* @param {string} model_name
|
|
247
247
|
* @param {Object} options
|
|
248
248
|
*/
|
|
249
249
|
Schema.setMethod(function getAssociationArguments(is_internal, alias, model_name, options) {
|
|
@@ -257,6 +257,7 @@ Schema.setMethod(function getAssociationArguments(is_internal, alias, model_name
|
|
|
257
257
|
|
|
258
258
|
if (typeof model_name === 'undefined') {
|
|
259
259
|
model_name = alias;
|
|
260
|
+
alias = null;
|
|
260
261
|
}
|
|
261
262
|
|
|
262
263
|
let local_key = options.local_key || options.localKey || false,
|
|
@@ -270,6 +271,16 @@ Schema.setMethod(function getAssociationArguments(is_internal, alias, model_name
|
|
|
270
271
|
throw new Error('Foreign key for ' + alias + ' association can not be an object');
|
|
271
272
|
}
|
|
272
273
|
|
|
274
|
+
// Get the actual model
|
|
275
|
+
let model = this.getModel(model_name);
|
|
276
|
+
|
|
277
|
+
// And get the correct model_name
|
|
278
|
+
model_name = model.model_name;
|
|
279
|
+
|
|
280
|
+
if (!alias) {
|
|
281
|
+
alias = model_name;
|
|
282
|
+
}
|
|
283
|
+
|
|
273
284
|
if (is_internal) {
|
|
274
285
|
|
|
275
286
|
if (!local_key) {
|
|
@@ -277,13 +288,11 @@ Schema.setMethod(function getAssociationArguments(is_internal, alias, model_name
|
|
|
277
288
|
}
|
|
278
289
|
|
|
279
290
|
if (!foreign_key) {
|
|
280
|
-
let model = this.getModel(model_name);
|
|
281
291
|
foreign_key = model.primary_key || '_id';
|
|
282
292
|
}
|
|
283
293
|
} else {
|
|
284
294
|
|
|
285
295
|
if (!local_key) {
|
|
286
|
-
let model = this.getModel(model_name);
|
|
287
296
|
local_key = model.primary_key || '_id';
|
|
288
297
|
}
|
|
289
298
|
|
|
@@ -350,7 +359,7 @@ Schema.setMethod(function clone() {
|
|
|
350
359
|
/**
|
|
351
360
|
* Dry the object
|
|
352
361
|
*
|
|
353
|
-
* @author Jelle De Loecker <jelle@
|
|
362
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
354
363
|
* @since 1.1.0
|
|
355
364
|
* @version 1.3.1
|
|
356
365
|
*
|
|
@@ -413,7 +422,7 @@ Schema.setMethod(function toDry() {
|
|
|
413
422
|
/**
|
|
414
423
|
* Initialize some values
|
|
415
424
|
*
|
|
416
|
-
* @author Jelle De Loecker <jelle@
|
|
425
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
417
426
|
* @since 1.1.0
|
|
418
427
|
* @version 1.3.21
|
|
419
428
|
*/
|
|
@@ -463,11 +472,11 @@ Schema.setMethod(function init() {
|
|
|
463
472
|
/**
|
|
464
473
|
* Set the name of this schema
|
|
465
474
|
*
|
|
466
|
-
* @author Jelle De Loecker
|
|
475
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
467
476
|
* @since 0.2.0
|
|
468
477
|
* @version 0.2.0
|
|
469
478
|
*
|
|
470
|
-
* @param {
|
|
479
|
+
* @param {string} name
|
|
471
480
|
*/
|
|
472
481
|
Schema.setMethod(function setName(name) {
|
|
473
482
|
this.name = name;
|
|
@@ -476,7 +485,7 @@ Schema.setMethod(function setName(name) {
|
|
|
476
485
|
/**
|
|
477
486
|
* Set the parent schema
|
|
478
487
|
*
|
|
479
|
-
* @author Jelle De Loecker
|
|
488
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
480
489
|
* @since 0.2.0
|
|
481
490
|
* @version 1.3.21
|
|
482
491
|
*
|
|
@@ -495,11 +504,11 @@ Schema.setMethod(function setParent(schema) {
|
|
|
495
504
|
/**
|
|
496
505
|
* Set the model this schema can use
|
|
497
506
|
*
|
|
498
|
-
* @author Jelle De Loecker
|
|
507
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
499
508
|
* @since 0.2.0
|
|
500
509
|
* @version 1.1.3
|
|
501
510
|
*
|
|
502
|
-
* @param {
|
|
511
|
+
* @param {string|Function|Object} model
|
|
503
512
|
*/
|
|
504
513
|
Schema.setMethod(function setModel(model) {
|
|
505
514
|
|
|
@@ -516,7 +525,7 @@ Schema.setMethod(function setModel(model) {
|
|
|
516
525
|
if (typeof model == 'string') {
|
|
517
526
|
path = model;
|
|
518
527
|
} else {
|
|
519
|
-
path = model.
|
|
528
|
+
path = model.model_name;
|
|
520
529
|
|
|
521
530
|
// See if this passed model is a constructor
|
|
522
531
|
if (model.staticChain) {
|
|
@@ -541,9 +550,10 @@ Schema.setMethod(function setModel(model) {
|
|
|
541
550
|
}
|
|
542
551
|
}
|
|
543
552
|
|
|
544
|
-
model_name = constructor.
|
|
553
|
+
model_name = constructor.model_name;
|
|
545
554
|
namespace = constructor.namespace;
|
|
546
555
|
|
|
556
|
+
this.model_class_name = constructor.name;
|
|
547
557
|
this.model_name = model_name;
|
|
548
558
|
this.model_class = constructor;
|
|
549
559
|
this.namespace = namespace;
|
|
@@ -560,7 +570,7 @@ Schema.setMethod(function setModel(model) {
|
|
|
560
570
|
/**
|
|
561
571
|
* Simplify the object for Hawkejs
|
|
562
572
|
*
|
|
563
|
-
* @author Jelle De Loecker <jelle@
|
|
573
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
564
574
|
* @since 1.1.0
|
|
565
575
|
* @version 1.1.0
|
|
566
576
|
*
|
|
@@ -664,12 +674,12 @@ Schema.setMethod(function getPrivateFields() {
|
|
|
664
674
|
* The value of these fields will be computed
|
|
665
675
|
* when the document is saved or loaded.
|
|
666
676
|
*
|
|
667
|
-
* @author Jelle De Loecker
|
|
677
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
668
678
|
* @since 1.3.21
|
|
669
679
|
* @version 1.3.21
|
|
670
680
|
*
|
|
671
|
-
* @param {
|
|
672
|
-
* @param {
|
|
681
|
+
* @param {string} name
|
|
682
|
+
* @param {string} type
|
|
673
683
|
* @param {Object} options
|
|
674
684
|
*
|
|
675
685
|
* @return {Alchemy.Field.Field}
|
|
@@ -713,12 +723,12 @@ Schema.setMethod(function addComputedField(name, type, options) {
|
|
|
713
723
|
/**
|
|
714
724
|
* Add a field to this schema
|
|
715
725
|
*
|
|
716
|
-
* @author Jelle De Loecker
|
|
726
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
717
727
|
* @since 0.2.0
|
|
718
728
|
* @version 1.3.21
|
|
719
729
|
*
|
|
720
|
-
* @param {
|
|
721
|
-
* @param {
|
|
730
|
+
* @param {string} name
|
|
731
|
+
* @param {string} type
|
|
722
732
|
* @param {Object} options
|
|
723
733
|
*
|
|
724
734
|
* @return {Alchemy.Field.Field}
|
|
@@ -775,8 +785,8 @@ Schema.setMethod(function addField(name, type, options) {
|
|
|
775
785
|
if (options.constraints) {
|
|
776
786
|
let required_fields = options.required_fields,
|
|
777
787
|
optional_fields = options.optional_fields,
|
|
778
|
-
|
|
779
|
-
|
|
788
|
+
constraints = options.constraints = Classes.Alchemy.Criteria.Criteria.cast(options.constraints),
|
|
789
|
+
target_path;
|
|
780
790
|
|
|
781
791
|
if (!required_fields) {
|
|
782
792
|
required_fields = [];
|
|
@@ -790,13 +800,9 @@ Schema.setMethod(function addField(name, type, options) {
|
|
|
790
800
|
optional_fields = optional_fields.slice(0);
|
|
791
801
|
}
|
|
792
802
|
|
|
793
|
-
for (
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (value && typeof value == 'object') {
|
|
797
|
-
if (value instanceof Classes.Alchemy.PathEvaluator) {
|
|
798
|
-
required_fields.push(value);
|
|
799
|
-
}
|
|
803
|
+
for (target_path of constraints.getAllExpressionTargetPaths()) {
|
|
804
|
+
if (!required_fields.includes(target_path)) {
|
|
805
|
+
required_fields.push(target_path);
|
|
800
806
|
}
|
|
801
807
|
}
|
|
802
808
|
|
|
@@ -837,11 +843,11 @@ Schema.setMethod(function addField(name, type, options) {
|
|
|
837
843
|
/**
|
|
838
844
|
* Add a rule to this schema
|
|
839
845
|
*
|
|
840
|
-
* @author Jelle De Loecker
|
|
846
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
841
847
|
* @since 0.2.0
|
|
842
848
|
* @version 1.3.21
|
|
843
849
|
*
|
|
844
|
-
* @param {
|
|
850
|
+
* @param {string} rule_name
|
|
845
851
|
* @param {Object} options
|
|
846
852
|
*/
|
|
847
853
|
Schema.setMethod(function addRule(rule_name, options) {
|
|
@@ -868,12 +874,12 @@ Schema.setMethod(function addRule(rule_name, options) {
|
|
|
868
874
|
/**
|
|
869
875
|
* Get the path to this schema
|
|
870
876
|
*
|
|
871
|
-
* @author Jelle De Loecker
|
|
877
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
872
878
|
* @since 0.2.0
|
|
873
879
|
* @version 0.4.0
|
|
874
880
|
*
|
|
875
|
-
* @param {
|
|
876
|
-
* @param {
|
|
881
|
+
* @param {string} extra Extra to append to the path (like field name)
|
|
882
|
+
* @param {boolean} with_top_schema Add top schema name, defaults to true
|
|
877
883
|
*/
|
|
878
884
|
Schema.setMethod(function getPath(extra, with_top_schema) {
|
|
879
885
|
|
|
@@ -913,11 +919,11 @@ Schema.setMethod(function getPath(extra, with_top_schema) {
|
|
|
913
919
|
/**
|
|
914
920
|
* Get a field
|
|
915
921
|
*
|
|
916
|
-
* @author Jelle De Loecker
|
|
922
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
917
923
|
* @since 0.2.0
|
|
918
924
|
* @version 1.1.0
|
|
919
925
|
*
|
|
920
|
-
* @param {
|
|
926
|
+
* @param {string} name
|
|
921
927
|
*
|
|
922
928
|
* @return {FieldType}
|
|
923
929
|
*/
|
|
@@ -933,11 +939,11 @@ Schema.setMethod(function getField(name) {
|
|
|
933
939
|
/**
|
|
934
940
|
* Get an association by name
|
|
935
941
|
*
|
|
936
|
-
* @author Jelle De Loecker
|
|
942
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
937
943
|
* @since 1.3.21
|
|
938
944
|
* @version 1.3.21
|
|
939
945
|
*
|
|
940
|
-
* @param {
|
|
946
|
+
* @param {string} name
|
|
941
947
|
*
|
|
942
948
|
* @return {Object}
|
|
943
949
|
*/
|
|
@@ -948,11 +954,11 @@ Schema.setMethod(function getAssociation(name) {
|
|
|
948
954
|
/**
|
|
949
955
|
* Get a field
|
|
950
956
|
*
|
|
951
|
-
* @author Jelle De Loecker
|
|
957
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
952
958
|
* @since 0.2.0
|
|
953
959
|
* @version 1.2.21
|
|
954
960
|
*
|
|
955
|
-
* @param {
|
|
961
|
+
* @param {string|PathEvaluator} name
|
|
956
962
|
*
|
|
957
963
|
* @return {FieldType[]}
|
|
958
964
|
*/
|
|
@@ -1020,11 +1026,11 @@ Schema.setMethod(function getFieldChain(name) {
|
|
|
1020
1026
|
/**
|
|
1021
1027
|
* Get all field names
|
|
1022
1028
|
*
|
|
1023
|
-
* @author Jelle De Loecker
|
|
1029
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1024
1030
|
* @since 0.2.0
|
|
1025
1031
|
* @version 0.2.0
|
|
1026
1032
|
*
|
|
1027
|
-
* @return {
|
|
1033
|
+
* @return {string}
|
|
1028
1034
|
*/
|
|
1029
1035
|
Schema.setMethod(function getFieldNames() {
|
|
1030
1036
|
return Object.keys(this.dict);
|
|
@@ -1033,11 +1039,11 @@ Schema.setMethod(function getFieldNames() {
|
|
|
1033
1039
|
/**
|
|
1034
1040
|
* Add an index
|
|
1035
1041
|
*
|
|
1036
|
-
* @author Jelle De Loecker
|
|
1042
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1037
1043
|
* @since 0.2.0
|
|
1038
|
-
* @version 1.
|
|
1044
|
+
* @version 1.4.0
|
|
1039
1045
|
*
|
|
1040
|
-
* @param {
|
|
1046
|
+
* @param {string|FieldType} _field
|
|
1041
1047
|
* @param {Object} options
|
|
1042
1048
|
*
|
|
1043
1049
|
* @return {FieldType}
|
|
@@ -1067,13 +1073,33 @@ Schema.setMethod(function addIndex(_field, _options) {
|
|
|
1067
1073
|
// Set the default options
|
|
1068
1074
|
options = Object.assign({}, this.indexOptions, options);
|
|
1069
1075
|
|
|
1070
|
-
|
|
1071
|
-
options.name = field.name;
|
|
1076
|
+
const setIndexName = () => {
|
|
1072
1077
|
|
|
1073
|
-
if (options.
|
|
1074
|
-
|
|
1078
|
+
if (options.name) {
|
|
1079
|
+
return;
|
|
1075
1080
|
}
|
|
1076
|
-
|
|
1081
|
+
|
|
1082
|
+
if (!this.model_name) {
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
if (options.name == null) {
|
|
1087
|
+
options.name = field.path;
|
|
1088
|
+
|
|
1089
|
+
if (options.unique) {
|
|
1090
|
+
options.name += '_uq';
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
if (this.indexes[options.name] == null) {
|
|
1095
|
+
// Create the index group if it doesn't exist yet.
|
|
1096
|
+
// The first time it's called will define the group options.
|
|
1097
|
+
this.indexes[options.name] = {
|
|
1098
|
+
fields: {},
|
|
1099
|
+
options: options
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1077
1103
|
|
|
1078
1104
|
if (typeof options.order == 'number') {
|
|
1079
1105
|
if (options.order == 'asc') {
|
|
@@ -1083,15 +1109,6 @@ Schema.setMethod(function addIndex(_field, _options) {
|
|
|
1083
1109
|
}
|
|
1084
1110
|
}
|
|
1085
1111
|
|
|
1086
|
-
if (this.indexes[options.name] == null) {
|
|
1087
|
-
// Create the index group if it doesn't exist yet.
|
|
1088
|
-
// The first time it's called will define the group options.
|
|
1089
|
-
this.indexes[options.name] = {
|
|
1090
|
-
fields: {},
|
|
1091
|
-
options: options
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
1112
|
// Even if an index is unique,
|
|
1096
1113
|
// it needs the 'alternate' property in order to be used
|
|
1097
1114
|
// as an alternate method of updating without _id
|
|
@@ -1099,6 +1116,9 @@ Schema.setMethod(function addIndex(_field, _options) {
|
|
|
1099
1116
|
this.has_alternates++;
|
|
1100
1117
|
}
|
|
1101
1118
|
|
|
1119
|
+
// Try to set the index name now, if possible
|
|
1120
|
+
setIndexName();
|
|
1121
|
+
|
|
1102
1122
|
const that = this;
|
|
1103
1123
|
|
|
1104
1124
|
that.getDatasource().done(function gotDs(err, datasource) {
|
|
@@ -1117,6 +1137,9 @@ Schema.setMethod(function addIndex(_field, _options) {
|
|
|
1117
1137
|
return alchemy.printLog('error', ['Unable to ensure index on this datasource', options.name], {err: new Error()});
|
|
1118
1138
|
}
|
|
1119
1139
|
|
|
1140
|
+
// Try to set the index name again, if it hasn't been done yet
|
|
1141
|
+
setIndexName();
|
|
1142
|
+
|
|
1120
1143
|
let path = field.path;
|
|
1121
1144
|
|
|
1122
1145
|
if (options.db_property) {
|
|
@@ -1139,7 +1162,7 @@ Schema.setMethod(function addIndex(_field, _options) {
|
|
|
1139
1162
|
/**
|
|
1140
1163
|
* Process the given object
|
|
1141
1164
|
*
|
|
1142
|
-
* @author Jelle De Loecker
|
|
1165
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1143
1166
|
* @since 0.2.0
|
|
1144
1167
|
* @version 1.1.0
|
|
1145
1168
|
*
|
|
@@ -1209,7 +1232,7 @@ Schema.setMethod(function process(data, options) {
|
|
|
1209
1232
|
/**
|
|
1210
1233
|
* Get the datasource for this schema
|
|
1211
1234
|
*
|
|
1212
|
-
* @author Jelle De Loecker
|
|
1235
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1213
1236
|
* @since 1.1.0
|
|
1214
1237
|
* @version 1.1.3
|
|
1215
1238
|
*
|
|
@@ -1241,14 +1264,14 @@ Schema.setMethod(function getDatasource() {
|
|
|
1241
1264
|
/**
|
|
1242
1265
|
* Get violations
|
|
1243
1266
|
*
|
|
1244
|
-
* @author Jelle De Loecker
|
|
1267
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1245
1268
|
* @since 0.2.0
|
|
1246
1269
|
* @version 1.1.4
|
|
1247
1270
|
*
|
|
1248
1271
|
* @param {Document} document The main document
|
|
1249
1272
|
* @param {Object} context The parent object being handled
|
|
1250
1273
|
*
|
|
1251
|
-
* @return {
|
|
1274
|
+
* @return {boolean|Violations}
|
|
1252
1275
|
*/
|
|
1253
1276
|
Schema.setMethod(async function getViolations(document, context) {
|
|
1254
1277
|
|
|
@@ -1289,7 +1312,7 @@ Schema.setMethod(async function getViolations(document, context) {
|
|
|
1289
1312
|
/**
|
|
1290
1313
|
* Validate the given document, throws an error if it fails
|
|
1291
1314
|
*
|
|
1292
|
-
* @author Jelle De Loecker
|
|
1315
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1293
1316
|
* @since 1.0.5
|
|
1294
1317
|
* @version 1.1.0
|
|
1295
1318
|
*
|