alchemymvc 1.3.23 → 1.4.0-alpha.10
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/index.js +0 -0
- package/lib/app/assets/scripts/.gitkeep +0 -0
- package/lib/app/assets/stylesheets/{alchemy-info.less → alchemy-info.scss} +2 -0
- package/lib/app/behaviour/publishable_behaviour.js +6 -8
- package/lib/app/behaviour/revision_behaviour.js +127 -75
- package/lib/app/behaviour/sluggable_behaviour.js +22 -22
- package/lib/app/bootstrap.js +0 -0
- package/lib/app/component/.gitkeep +0 -0
- 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 +38 -23
- 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 +376 -304
- 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 +27 -25
- 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 +50 -22
- package/lib/app/helper/pagination_helper.js +36 -36
- package/lib/app/helper/router_helper.js +107 -60
- package/lib/app/helper/socket_helper.js +57 -57
- package/lib/app/helper/syncable.js +65 -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 +69 -43
- package/lib/app/helper_datasource/00-nosql_datasource.js +663 -70
- package/lib/app/helper_datasource/05-fallback_datasource.js +75 -93
- package/lib/app/helper_datasource/10-datasource_operational_context.js +153 -0
- package/lib/app/helper_datasource/idb_datasource.js +80 -63
- package/lib/app/helper_datasource/indexed_db.js +63 -55
- package/lib/app/helper_datasource/read_operational_context.js +179 -0
- package/lib/app/helper_datasource/remote_datasource.js +56 -29
- package/lib/app/helper_datasource/remove_operational_context.js +10 -0
- package/lib/app/helper_datasource/save_operational_context.js +194 -0
- package/lib/app/helper_datasource/schema_operational_context.js +109 -0
- 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 +8 -10
- 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 +25 -28
- package/lib/app/helper_field/15-local_temporal_field.js +20 -23
- package/lib/app/helper_field/20-decimal_field.js +20 -24
- package/lib/app/helper_field/30-meta_field.js +27 -0
- package/lib/app/helper_field/40-foreign_key_field.js +39 -0
- package/lib/app/helper_field/association_alias_field.js +12 -0
- package/lib/app/helper_field/belongsto_field.js +3 -3
- package/lib/app/helper_field/big_int_field.js +21 -24
- package/lib/app/helper_field/boolean_field.js +9 -11
- package/lib/app/helper_field/datetime_field.js +9 -12
- package/lib/app/helper_field/enum_field.js +26 -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 +4 -8
- package/lib/app/helper_field/hasoneparent_field.js +3 -7
- 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 +18 -19
- package/lib/app/helper_field/object_field.js +12 -13
- package/lib/app/helper_field/password_field.js +14 -11
- package/lib/app/helper_field/regexp_field.js +7 -9
- package/lib/app/helper_field/schema_field.js +348 -220
- 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 +723 -0
- package/lib/app/helper_model/05-criteria_expressions.js +624 -0
- package/lib/app/helper_model/10-model_criteria.js +1184 -0
- package/lib/app/helper_model/data_provider.js +2 -2
- package/lib/app/helper_model/document.js +132 -119
- 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 +387 -148
- 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 +162 -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} +24 -15
- package/lib/app/root/alchemy-logo.png +0 -0
- package/lib/app/root/favicon.ico +0 -0
- package/lib/app/view/alchemy/info.hwk +0 -0
- package/lib/app/view/error/403.ejs +0 -0
- package/lib/app/view/error/404.ejs +0 -0
- package/lib/app/view/error/unknown.ejs +0 -0
- package/lib/app/view/paginate/navlist.ejs +0 -0
- package/lib/bootstrap.js +24 -309
- package/lib/class/accumulator.js +5 -5
- package/lib/class/behaviour.js +6 -30
- package/lib/class/component.js +3 -3
- package/lib/class/conduit.js +174 -194
- package/lib/class/controller.js +42 -42
- package/lib/class/datasource.js +181 -339
- package/lib/class/document.js +74 -95
- package/lib/class/document_list.js +5 -5
- package/lib/class/element.js +33 -17
- package/lib/class/error.js +3 -3
- package/lib/class/field.js +258 -179
- 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 +27 -27
- package/lib/class/inode_list.js +4 -4
- package/lib/class/migration.js +4 -4
- package/lib/class/model.js +197 -215
- package/lib/class/operational_context.js +146 -0
- 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 +32 -42
- package/lib/class/reciprocal.js +8 -8
- package/lib/class/route.js +39 -40
- package/lib/class/router.js +75 -75
- package/lib/class/schema.js +24 -42
- package/lib/class/schema_client.js +156 -89
- 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 +46 -50
- package/lib/{init → core}/alchemy.js +547 -416
- package/lib/{init/functions.js → core/alchemy_functions.js} +181 -94
- package/lib/core/alchemy_load_functions.js +747 -0
- package/lib/core/base.js +54 -66
- package/lib/core/client_alchemy.js +162 -156
- package/lib/core/client_base.js +27 -50
- package/lib/core/discovery.js +16 -18
- package/lib/core/middleware.js +503 -105
- package/lib/core/{routing.js → prefix.js} +14 -16
- package/lib/core/setting.js +1794 -0
- package/lib/core/stage.js +764 -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 +473 -0
- package/lib/scripts/create_shared_constants.js +120 -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 -3
- package/lib/scripts/setup_devwatch.js +238 -0
- package/lib/stages/00-load_core.js +355 -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 +220 -0
- package/lib/stages/90-server.js +347 -0
- package/package.json +22 -23
- 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
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2013-
|
|
1
|
+
Copyright (c) 2013-2024 Jelle De Loecker <jelle@elevenways.be>
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
<b>Alchemy</b>
|
|
4
4
|
</h1>
|
|
5
5
|
<div align="center">
|
|
6
|
-
<!-- CI -
|
|
7
|
-
<a href="https://
|
|
8
|
-
<img src="https://
|
|
6
|
+
<!-- CI - Github Actions -->
|
|
7
|
+
<a href="https://github.com/11ways/alchemy/actions/workflows/unit_test.yaml">
|
|
8
|
+
<img src="https://github.com/11ways/alchemy/actions/workflows/unit_test.yaml/badge.svg" alt="Node.js CI (Linux, MacOS, Windows)" />
|
|
9
9
|
</a>
|
|
10
10
|
|
|
11
11
|
<!-- Coverage - Codecov -->
|
package/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -4,18 +4,16 @@
|
|
|
4
4
|
* @constructor
|
|
5
5
|
* @extends Alchemy.Behaviour
|
|
6
6
|
*
|
|
7
|
-
* @author
|
|
8
|
-
* @since
|
|
9
|
-
* @version
|
|
7
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @version 0.3.0
|
|
10
10
|
*/
|
|
11
|
-
var Publish = Function.inherits('Alchemy.Behaviour',
|
|
12
|
-
PublishableBehaviour.super.call(this, model, options);
|
|
13
|
-
});
|
|
11
|
+
var Publish = Function.inherits('Alchemy.Behaviour', 'PublishableBehaviour');
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* Listen to attachments to schema's
|
|
17
15
|
*
|
|
18
|
-
* @author Jelle De Loecker
|
|
16
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
19
17
|
* @since 1.0.3
|
|
20
18
|
* @version 1.0.3
|
|
21
19
|
*
|
|
@@ -37,7 +35,7 @@ Publish.setStatic(function attached(schema, options) {
|
|
|
37
35
|
/**
|
|
38
36
|
* Set publish options
|
|
39
37
|
*
|
|
40
|
-
* @author Jelle De Loecker
|
|
38
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
41
39
|
* @since 0.1.0
|
|
42
40
|
* @version 1.1.0
|
|
43
41
|
*
|
|
@@ -8,30 +8,53 @@ var jsondiffpatch = alchemy.use('jsondiffpatch'),
|
|
|
8
8
|
* @constructor
|
|
9
9
|
* @extends Alchemy.Behaviour
|
|
10
10
|
*
|
|
11
|
-
* @author
|
|
12
|
-
* @since
|
|
13
|
-
* @version
|
|
11
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
12
|
+
* @since 0.0.1
|
|
13
|
+
* @version 0.2.0
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
Behaviour.call(this, model, options);
|
|
17
|
-
});
|
|
15
|
+
const Revision = Function.inherits('Alchemy.Behaviour', 'RevisionBehaviour');
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
|
-
* Get the Revision
|
|
18
|
+
* Get the Revision model class for the given main model
|
|
21
19
|
*
|
|
22
|
-
* @author Jelle De Loecker
|
|
23
|
-
* @since 1.0
|
|
24
|
-
* @version 1.
|
|
20
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
21
|
+
* @since 1.4.0
|
|
22
|
+
* @version 1.4.0
|
|
23
|
+
*
|
|
24
|
+
* @param {Schema} schema
|
|
25
|
+
* @param {Object} options
|
|
25
26
|
*/
|
|
26
|
-
Revision.
|
|
27
|
+
Revision.setStatic(function getRevisionModel(model) {
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
if (typeof model == 'function') {
|
|
30
|
+
model = model.model_name;
|
|
31
|
+
}
|
|
29
32
|
|
|
30
|
-
if (
|
|
31
|
-
|
|
33
|
+
if (typeof model == 'string') {
|
|
34
|
+
model = Model.get(model);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
if (!model) {
|
|
38
|
+
throw new Error('Unable to add Revision behaviour to undefined model');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let revision_model_name = model.model_name + 'DataRevision',
|
|
42
|
+
revision_model;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
revision_model = Model.get(revision_model_name, false);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// Ignore
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (revision_model) {
|
|
51
|
+
return revision_model;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let namespace = model.constructor.namespace,
|
|
55
|
+
class_name = model.name + 'DataRevision';
|
|
56
|
+
|
|
57
|
+
let model_class = Function.inherits('Alchemy.Model', namespace, Function.create(class_name, function DataRevision(options) {
|
|
35
58
|
Model.call(this, options);
|
|
36
59
|
}));
|
|
37
60
|
|
|
@@ -42,12 +65,18 @@ Revision.setProperty(function revision_model_class() {
|
|
|
42
65
|
this.schema.remove('updated');
|
|
43
66
|
|
|
44
67
|
this.addField('record_id', 'ObjectId');
|
|
45
|
-
this.addField('revision', '
|
|
68
|
+
this.addField('revision', 'Integer');
|
|
46
69
|
this.addField('delta', 'Object');
|
|
47
70
|
|
|
48
71
|
if (Classes.Alchemy.Model.User) {
|
|
49
72
|
this.belongsTo('User');
|
|
50
73
|
}
|
|
74
|
+
|
|
75
|
+
// Add an index on the record_id
|
|
76
|
+
this.addIndex('record_id', {
|
|
77
|
+
unique : false,
|
|
78
|
+
sparse : false,
|
|
79
|
+
});
|
|
51
80
|
});
|
|
52
81
|
|
|
53
82
|
// Force the constitutors to load now
|
|
@@ -56,10 +85,43 @@ Revision.setProperty(function revision_model_class() {
|
|
|
56
85
|
return model_class;
|
|
57
86
|
});
|
|
58
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Listen to attachments to schema's
|
|
90
|
+
*
|
|
91
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
92
|
+
* @since 1.0.3
|
|
93
|
+
* @version 1.4.0
|
|
94
|
+
*
|
|
95
|
+
* @param {Schema} schema
|
|
96
|
+
* @param {Object} options
|
|
97
|
+
*/
|
|
98
|
+
Revision.setStatic(function attached(schema, new_options) {
|
|
99
|
+
|
|
100
|
+
const context = schema.model_class;
|
|
101
|
+
|
|
102
|
+
// Add the revision number to the main model
|
|
103
|
+
context.addField('__r', 'Integer', {
|
|
104
|
+
title: 'Revision',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
Revision.getRevisionModel(schema.model_class);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the Revision Model class for the attached model
|
|
112
|
+
*
|
|
113
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
114
|
+
* @since 1.0.3
|
|
115
|
+
* @version 1.4.0
|
|
116
|
+
*/
|
|
117
|
+
Revision.setProperty(function revision_model_class() {
|
|
118
|
+
return Revision.getRevisionModel(this.model);
|
|
119
|
+
});
|
|
120
|
+
|
|
59
121
|
/**
|
|
60
122
|
* Get the revision model for the attached model
|
|
61
123
|
*
|
|
62
|
-
* @author Jelle De Loecker
|
|
124
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
63
125
|
* @since 1.0.3
|
|
64
126
|
* @version 1.0.3
|
|
65
127
|
*/
|
|
@@ -76,7 +138,7 @@ Revision.setProperty(function revision_model() {
|
|
|
76
138
|
/**
|
|
77
139
|
* Get the jsondiffpatch instance
|
|
78
140
|
*
|
|
79
|
-
* @author Jelle De Loecker
|
|
141
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
80
142
|
* @since 1.0.3
|
|
81
143
|
* @version 1.0.3
|
|
82
144
|
*/
|
|
@@ -122,28 +184,10 @@ Revision.setProperty(function diff_patcher() {
|
|
|
122
184
|
return diff_patch_instance;
|
|
123
185
|
});
|
|
124
186
|
|
|
125
|
-
/**
|
|
126
|
-
* Listen to attachments to schema's
|
|
127
|
-
*
|
|
128
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
129
|
-
* @since 1.0.3
|
|
130
|
-
* @version 1.0.3
|
|
131
|
-
*
|
|
132
|
-
* @param {Schema} schema
|
|
133
|
-
* @param {Object} options
|
|
134
|
-
*/
|
|
135
|
-
Revision.setStatic(function attached(schema, new_options) {
|
|
136
|
-
|
|
137
|
-
var context = schema.model_class;
|
|
138
|
-
|
|
139
|
-
// Add the revision
|
|
140
|
-
context.addField('__r', 'Number', {title: 'Revision'});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
187
|
/**
|
|
144
188
|
* Compare 2 objects
|
|
145
189
|
*
|
|
146
|
-
* @author Jelle De Loecker
|
|
190
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
147
191
|
* @since 0.0.1
|
|
148
192
|
* @version 1.0.3
|
|
149
193
|
*/
|
|
@@ -155,16 +199,16 @@ Revision.setMethod(function compare(left, right) {
|
|
|
155
199
|
* Called before the model saves a record,
|
|
156
200
|
* but after it has applied the strictFields
|
|
157
201
|
*
|
|
158
|
-
* @author Jelle De Loecker
|
|
202
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
159
203
|
* @since 0.0.1
|
|
160
|
-
* @version 1.0
|
|
204
|
+
* @version 1.4.0
|
|
161
205
|
*/
|
|
162
206
|
Revision.setMethod(function beforeSave(record, options, creating) {
|
|
163
207
|
|
|
164
|
-
let main = record
|
|
208
|
+
let main = record.$main;
|
|
165
209
|
|
|
166
210
|
if (!main) {
|
|
167
|
-
throw new Error('Unable to find main "' + this.model.
|
|
211
|
+
throw new Error('Unable to find main "' + this.model.model_name + '" data');
|
|
168
212
|
}
|
|
169
213
|
|
|
170
214
|
// No revision to save when creating a record
|
|
@@ -173,50 +217,54 @@ Revision.setMethod(function beforeSave(record, options, creating) {
|
|
|
173
217
|
return;
|
|
174
218
|
}
|
|
175
219
|
|
|
176
|
-
let that = this
|
|
177
|
-
next = this.wait('series');
|
|
178
|
-
|
|
179
|
-
// Find the original record
|
|
180
|
-
Model.get(that.model.name).findById(main._id, async function gotRecord(err, result) {
|
|
220
|
+
let that = this;
|
|
181
221
|
|
|
182
|
-
|
|
222
|
+
let pledge = new Swift();
|
|
183
223
|
|
|
184
|
-
|
|
224
|
+
// Find the original record
|
|
225
|
+
Model.get(this.model.model_name).findById(record.$pk, function gotRecord(err, result) {
|
|
185
226
|
|
|
186
|
-
|
|
187
|
-
|
|
227
|
+
if (err || !result) {
|
|
228
|
+
return pledge.resolve();
|
|
229
|
+
}
|
|
188
230
|
|
|
189
|
-
|
|
190
|
-
revision_before.set(options, ori);
|
|
231
|
+
let conversion;
|
|
191
232
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
main.__r = 1;
|
|
197
|
-
}
|
|
233
|
+
try {
|
|
234
|
+
conversion = that.model.convertRecordToDatasourceFormat(result);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
return pledge.reject(err);
|
|
198
237
|
}
|
|
199
238
|
|
|
200
|
-
|
|
239
|
+
pledge.resolve(Swift.waterfall(
|
|
240
|
+
conversion,
|
|
241
|
+
ori => {
|
|
242
|
+
// Store the original data in a weakmap for later
|
|
243
|
+
revision_before.set(options, ori);
|
|
244
|
+
|
|
245
|
+
// Increase the revision count by 1
|
|
246
|
+
if (ori.__r) {
|
|
247
|
+
main.__r = ori.__r+1;
|
|
248
|
+
} else {
|
|
249
|
+
main.__r = 1;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
));
|
|
201
253
|
});
|
|
254
|
+
|
|
255
|
+
return pledge;
|
|
202
256
|
});
|
|
203
257
|
|
|
204
258
|
/**
|
|
205
259
|
* Called after the model saves a record.
|
|
206
260
|
*
|
|
207
|
-
* @author Jelle De Loecker
|
|
261
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
208
262
|
* @since 0.0.1
|
|
209
|
-
* @version 1.
|
|
263
|
+
* @version 1.4.0
|
|
210
264
|
*/
|
|
211
265
|
Revision.setMethod(function afterSave(record, options, created) {
|
|
212
266
|
|
|
213
|
-
|
|
214
|
-
earlier_data,
|
|
215
|
-
right,
|
|
216
|
-
main,
|
|
217
|
-
that,
|
|
218
|
-
left,
|
|
219
|
-
next;
|
|
267
|
+
let earlier_data;
|
|
220
268
|
|
|
221
269
|
if (created) {
|
|
222
270
|
earlier_data = {};
|
|
@@ -229,11 +277,13 @@ Revision.setMethod(function afterSave(record, options, created) {
|
|
|
229
277
|
return;
|
|
230
278
|
}
|
|
231
279
|
|
|
232
|
-
|
|
233
|
-
|
|
280
|
+
let doc = this.model.createDocument(record);
|
|
281
|
+
const that = this;
|
|
282
|
+
|
|
283
|
+
let pledge = new Swift();
|
|
234
284
|
|
|
235
285
|
// Find the complete saved item
|
|
236
|
-
Model.get(
|
|
286
|
+
Model.get(this.model.model_name).findByPk(doc.$pk, async function gotRecord(err, result) {
|
|
237
287
|
|
|
238
288
|
if (result) {
|
|
239
289
|
|
|
@@ -243,8 +293,8 @@ Revision.setMethod(function afterSave(record, options, created) {
|
|
|
243
293
|
if (new_data) {
|
|
244
294
|
|
|
245
295
|
// Convert the objects so they can be diffed properly
|
|
246
|
-
left = JSON.toDryObject(earlier_data)
|
|
247
|
-
|
|
296
|
+
let left = JSON.toDryObject(earlier_data),
|
|
297
|
+
right = JSON.toDryObject(new_data);
|
|
248
298
|
|
|
249
299
|
// Diff them
|
|
250
300
|
let delta = that.compare(left, right);
|
|
@@ -267,7 +317,7 @@ Revision.setMethod(function afterSave(record, options, created) {
|
|
|
267
317
|
|
|
268
318
|
// Add the delta information
|
|
269
319
|
revision_data = {
|
|
270
|
-
[that.revision_model.
|
|
320
|
+
[that.revision_model.model_name] : revision_data
|
|
271
321
|
};
|
|
272
322
|
|
|
273
323
|
// Save the data
|
|
@@ -275,6 +325,8 @@ Revision.setMethod(function afterSave(record, options, created) {
|
|
|
275
325
|
}
|
|
276
326
|
}
|
|
277
327
|
|
|
278
|
-
|
|
328
|
+
pledge.resolve();
|
|
279
329
|
});
|
|
330
|
+
|
|
331
|
+
return pledge;
|
|
280
332
|
});
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @constructor
|
|
5
5
|
* @extends Alchemy.Behaviour
|
|
6
6
|
*
|
|
7
|
-
* @author
|
|
8
|
-
* @since
|
|
9
|
-
* @version
|
|
7
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @version 1.3.16
|
|
10
10
|
*/
|
|
11
11
|
var Sluggable = Function.inherits('Alchemy.Behaviour', function SluggableBehaviour(model, options) {
|
|
12
12
|
|
|
@@ -37,7 +37,7 @@ var Sluggable = Function.inherits('Alchemy.Behaviour', function SluggableBehavio
|
|
|
37
37
|
/**
|
|
38
38
|
* Default slug options
|
|
39
39
|
*
|
|
40
|
-
* @author Jelle De Loecker
|
|
40
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
41
41
|
* @since 0.2.0
|
|
42
42
|
* @version 0.2.3
|
|
43
43
|
*
|
|
@@ -53,11 +53,11 @@ Sluggable.setProperty('default_options', {
|
|
|
53
53
|
/**
|
|
54
54
|
* Get the source field
|
|
55
55
|
*
|
|
56
|
-
* @author Jelle De Loecker
|
|
56
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
57
57
|
* @since 0.2.0
|
|
58
58
|
* @version 0.2.0
|
|
59
59
|
*
|
|
60
|
-
* @param {
|
|
60
|
+
* @param {string} source
|
|
61
61
|
* @param {Schema} schema
|
|
62
62
|
*/
|
|
63
63
|
Sluggable.setStatic(function getSource(source, schema) {
|
|
@@ -81,7 +81,7 @@ Sluggable.setStatic(function getSource(source, schema) {
|
|
|
81
81
|
/**
|
|
82
82
|
* Listen to attachments to schema's
|
|
83
83
|
*
|
|
84
|
-
* @author Jelle De Loecker
|
|
84
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
85
85
|
* @since 0.2.0
|
|
86
86
|
* @version 1.3.0
|
|
87
87
|
*
|
|
@@ -139,13 +139,13 @@ Sluggable.setStatic(function attached(schema, new_options) {
|
|
|
139
139
|
/**
|
|
140
140
|
* The beforeSave
|
|
141
141
|
*
|
|
142
|
-
* @author Jelle De Loecker
|
|
142
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
143
143
|
* @since 0.1.0
|
|
144
144
|
* @version 1.0.6
|
|
145
145
|
*
|
|
146
146
|
* @param {Object} data The data that is to be saved
|
|
147
147
|
* @param {Object} options Behaviour options
|
|
148
|
-
* @param {
|
|
148
|
+
* @param {boolean} creating Is this record being created?
|
|
149
149
|
*/
|
|
150
150
|
Sluggable.setMethod(async function beforeSave(data, options, creating) {
|
|
151
151
|
|
|
@@ -153,8 +153,7 @@ Sluggable.setMethod(async function beforeSave(data, options, creating) {
|
|
|
153
153
|
has_new_value,
|
|
154
154
|
old_record,
|
|
155
155
|
new_value,
|
|
156
|
-
old_value
|
|
157
|
-
next;
|
|
156
|
+
old_value;
|
|
158
157
|
|
|
159
158
|
// Get the actual record data
|
|
160
159
|
if (data[that.model.name]) {
|
|
@@ -170,9 +169,6 @@ Sluggable.setMethod(async function beforeSave(data, options, creating) {
|
|
|
170
169
|
has_new_value = true;
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
// Let other event callbacks wait for this one
|
|
174
|
-
next = this.wait('series');
|
|
175
|
-
|
|
176
172
|
if (!creating) {
|
|
177
173
|
old_record = await this.model.findById(data._id);
|
|
178
174
|
|
|
@@ -186,7 +182,7 @@ Sluggable.setMethod(async function beforeSave(data, options, creating) {
|
|
|
186
182
|
// and we're not explicitly setting a new slug value,
|
|
187
183
|
// then do nothing
|
|
188
184
|
if (!creating && old_value && !has_new_value) {
|
|
189
|
-
return
|
|
185
|
+
return;
|
|
190
186
|
}
|
|
191
187
|
|
|
192
188
|
let new_data = {};
|
|
@@ -198,30 +194,34 @@ Sluggable.setMethod(async function beforeSave(data, options, creating) {
|
|
|
198
194
|
Object.assign(new_data, data);
|
|
199
195
|
}
|
|
200
196
|
|
|
197
|
+
let pledge = new Swift();
|
|
198
|
+
|
|
201
199
|
// Try creating a new slug
|
|
202
200
|
that.createSlug(new_data, new_value, function createdSlug(err, result) {
|
|
203
201
|
|
|
204
202
|
if (err) {
|
|
205
|
-
return
|
|
203
|
+
return pledge.reject(err);
|
|
206
204
|
}
|
|
207
205
|
|
|
208
206
|
if (!Object.isEmpty(result)) {
|
|
209
207
|
data[that.target_field.name] = result;
|
|
210
208
|
}
|
|
211
209
|
|
|
212
|
-
|
|
210
|
+
pledge.resolve();
|
|
213
211
|
});
|
|
212
|
+
|
|
213
|
+
return pledge;
|
|
214
214
|
});
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
217
|
* Start the slug creating process
|
|
218
218
|
*
|
|
219
|
-
* @author Jelle De Loecker
|
|
219
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
220
220
|
* @since 0.1.0
|
|
221
221
|
* @version 1.1.0
|
|
222
222
|
*
|
|
223
223
|
* @param {Object} record
|
|
224
|
-
* @param {
|
|
224
|
+
* @param {string} new_value
|
|
225
225
|
* @param {Function} callback
|
|
226
226
|
*/
|
|
227
227
|
Sluggable.setMethod(function createSlug(record, new_value, callback) {
|
|
@@ -295,12 +295,12 @@ Sluggable.setMethod(function createSlug(record, new_value, callback) {
|
|
|
295
295
|
* Actually generate the slug from the given string,
|
|
296
296
|
* and look for existing slugs in the path
|
|
297
297
|
*
|
|
298
|
-
* @author Jelle De Loecker
|
|
298
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
299
299
|
* @since 0.1.0
|
|
300
300
|
* @version 1.1.8
|
|
301
301
|
*
|
|
302
|
-
* @param {
|
|
303
|
-
* @param {
|
|
302
|
+
* @param {string} title
|
|
303
|
+
* @param {string} path
|
|
304
304
|
* @param {Document} record
|
|
305
305
|
* @param {Function} callback
|
|
306
306
|
*/
|
package/lib/app/bootstrap.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -6,12 +6,12 @@ var fs = require('fs');
|
|
|
6
6
|
* @constructor
|
|
7
7
|
* @extends Alchemy.Conduit
|
|
8
8
|
*
|
|
9
|
-
* @author
|
|
10
|
-
* @since
|
|
11
|
-
* @version
|
|
9
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
10
|
+
* @since 0.2.0
|
|
11
|
+
* @version 1.1.3
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
13
|
+
* @param {Object} request
|
|
14
|
+
* @param {Function} callback
|
|
15
15
|
*/
|
|
16
16
|
var ElectronConduit = Function.inherits('Alchemy.Conduit', function Electron(request, callback, router) {
|
|
17
17
|
|
|
@@ -32,7 +32,7 @@ var ElectronConduit = Function.inherits('Alchemy.Conduit', function Electron(req
|
|
|
32
32
|
request.conduit = this;
|
|
33
33
|
|
|
34
34
|
// Allow use of the log in the views
|
|
35
|
-
if (alchemy.settings.debug) {
|
|
35
|
+
if (alchemy.settings.debugging.debug) {
|
|
36
36
|
this.internal('debuglog', {_placeholder_: 'debuglog'});
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -62,7 +62,7 @@ var ElectronConduit = Function.inherits('Alchemy.Conduit', function Electron(req
|
|
|
62
62
|
/**
|
|
63
63
|
* Create a new Hawkejs' ViewRender instance
|
|
64
64
|
*
|
|
65
|
-
* @author Jelle De Loecker
|
|
65
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
66
66
|
* @since 0.2.0
|
|
67
67
|
* @version 1.1.0
|
|
68
68
|
*/
|
|
@@ -86,7 +86,7 @@ ElectronConduit.setMethod(function setHeader(name, val) {
|
|
|
86
86
|
/**
|
|
87
87
|
* Call the actual end method
|
|
88
88
|
*
|
|
89
|
-
* @author Jelle De Loecker
|
|
89
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
90
90
|
* @since 0.2.0
|
|
91
91
|
* @version 1.0.0
|
|
92
92
|
*/
|
|
@@ -97,7 +97,7 @@ ElectronConduit.setMethod(function _end(message, encoding) {
|
|
|
97
97
|
/**
|
|
98
98
|
* Serve a file
|
|
99
99
|
*
|
|
100
|
-
* @author Jelle De Loecker
|
|
100
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
101
101
|
* @since 0.2.0
|
|
102
102
|
* @version 0.2.0
|
|
103
103
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Http Conduit Class
|
|
3
3
|
*
|
|
4
|
-
* @author Jelle De Loecker
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
5
|
* @since 0.2.0
|
|
6
6
|
* @version 1.1.3
|
|
7
7
|
*
|
|
@@ -20,11 +20,11 @@ var HttpConduit = Function.inherits('Alchemy.Conduit.Conduit', function Http(req
|
|
|
20
20
|
/**
|
|
21
21
|
* Has the client aborted the request?
|
|
22
22
|
*
|
|
23
|
-
* @author Jelle De Loecker
|
|
23
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
24
|
* @since 1.1.0
|
|
25
25
|
* @version 1.1.0
|
|
26
26
|
*
|
|
27
|
-
* @type {
|
|
27
|
+
* @type {boolean}
|
|
28
28
|
*/
|
|
29
29
|
HttpConduit.setProperty(function aborted() {
|
|
30
30
|
|
|
@@ -38,7 +38,7 @@ HttpConduit.setProperty(function aborted() {
|
|
|
38
38
|
/**
|
|
39
39
|
* Return the IP address
|
|
40
40
|
*
|
|
41
|
-
* @author Jelle De Loecker
|
|
41
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
42
42
|
* @since 0.2.0
|
|
43
43
|
* @version 1.1.0
|
|
44
44
|
*/
|
|
@@ -84,11 +84,11 @@ HttpConduit.setProperty(function ip() {
|
|
|
84
84
|
* Get a simple fingerprint of the client
|
|
85
85
|
* based on ip, accept-language & user-agent
|
|
86
86
|
*
|
|
87
|
-
* @author Jelle De Loecker
|
|
87
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
88
88
|
* @since 1.1.0
|
|
89
89
|
* @version 1.1.0
|
|
90
90
|
*
|
|
91
|
-
* @type {
|
|
91
|
+
* @type {string}
|
|
92
92
|
*/
|
|
93
93
|
HttpConduit.enforceProperty(function fingerprint() {
|
|
94
94
|
|
|
@@ -105,9 +105,9 @@ HttpConduit.enforceProperty(function fingerprint() {
|
|
|
105
105
|
/**
|
|
106
106
|
* Init
|
|
107
107
|
*
|
|
108
|
-
* @author Jelle De Loecker
|
|
108
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
109
109
|
* @since 0.3.3
|
|
110
|
-
* @version 1.
|
|
110
|
+
* @version 1.4.0
|
|
111
111
|
*
|
|
112
112
|
* @param {IncomingMessage} req
|
|
113
113
|
* @param {ServerResponse} res
|
|
@@ -133,7 +133,7 @@ HttpConduit.setMethod(async function initHttp(req, res, router) {
|
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
if (alchemy.settings.debug || alchemy.settings.environment != 'live') {
|
|
136
|
+
if (alchemy.settings.debugging.debug || alchemy.settings.environment != 'live') {
|
|
137
137
|
this.setHeader('X-Robots-Tag', 'none');
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -151,11 +151,11 @@ HttpConduit.setMethod(async function initHttp(req, res, router) {
|
|
|
151
151
|
/**
|
|
152
152
|
* Get the original url path
|
|
153
153
|
*
|
|
154
|
-
* @author Jelle De Loecker
|
|
154
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
155
155
|
* @since 1.1.0
|
|
156
156
|
* @version 1.1.0
|
|
157
157
|
*
|
|
158
|
-
* @type {
|
|
158
|
+
* @type {string}
|
|
159
159
|
*/
|
|
160
160
|
HttpConduit.setProperty(function original_path() {
|
|
161
161
|
return this.original_url.path;
|
|
@@ -166,11 +166,11 @@ HttpConduit.setProperty(function original_path() {
|
|
|
166
166
|
/**
|
|
167
167
|
* Get the original url pathname
|
|
168
168
|
*
|
|
169
|
-
* @author Jelle De Loecker
|
|
169
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
170
170
|
* @since 1.1.0
|
|
171
171
|
* @version 1.1.0
|
|
172
172
|
*
|
|
173
|
-
* @type {
|
|
173
|
+
* @type {string}
|
|
174
174
|
*/
|
|
175
175
|
HttpConduit.setProperty(function original_pathname() {
|
|
176
176
|
return this.original_url.pathname;
|