alchemymvc 1.2.0 → 1.2.1

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.
@@ -0,0 +1,257 @@
1
+ const OBJECT = Symbol('Object'),
2
+ BACKING = Symbol('Backing'),
3
+ MAP = Symbol('Map');
4
+
5
+ /**
6
+ * The Backed map class
7
+ *
8
+ * @constructor
9
+ *
10
+ * @author Jelle De Loecker <jelle@elevenways.be>
11
+ * @since 1.2.1
12
+ * @version 1.2.1
13
+ */
14
+ const Backed = Function.inherits('Alchemy.Base', 'Alchemy.Map', function Backed(backing) {
15
+ this.local = new Map();
16
+ this.type = null;
17
+ this.backing = backing;
18
+ });
19
+
20
+ /**
21
+ * Undry the given value
22
+ *
23
+ * @author Jelle De Loecker <jelle@elevenways.be>
24
+ * @since 1.2.1
25
+ * @version 1.2.1
26
+ *
27
+ * @param {Object} value
28
+ *
29
+ * @return {EnumValues}
30
+ */
31
+ Backed.setStatic(function unDry(value, custom_method, whenDone) {
32
+ let result = new this(value.backing);
33
+ return result;
34
+ });
35
+
36
+ /**
37
+ * Get the size
38
+ *
39
+ * @author Jelle De Loecker <jelle@elevenways.be>
40
+ * @since 1.2.1
41
+ * @version 1.2.1
42
+ */
43
+ Backed.setProperty(function size() {
44
+ return this.keys().length;
45
+ });
46
+
47
+ /**
48
+ * Set the backing value
49
+ *
50
+ * @author Jelle De Loecker <jelle@elevenways.be>
51
+ * @since 1.2.1
52
+ * @version 1.2.1
53
+ */
54
+ Backed.enforceProperty(function backing(new_value, old_value) {
55
+
56
+ this.backing = null;
57
+ this.type = null;
58
+
59
+ if (!new_value) {
60
+ return;
61
+ }
62
+
63
+ if (new_value instanceof Backed) {
64
+ this.type = BACKING;
65
+ } else if (new_value instanceof Map) {
66
+ this.type = MAP;
67
+ } else if (typeof new_value == 'object') {
68
+ this.type = OBJECT;
69
+ }
70
+
71
+ return new_value;
72
+ });
73
+
74
+ /**
75
+ * Create a (shallow) clone of this backed map.
76
+ * Since we don't ever touch the backing itself, we don't have to clone that.
77
+ *
78
+ * @author Jelle De Loecker <jelle@elevenways.be>
79
+ * @since 1.2.1
80
+ * @version 1.2.1
81
+ *
82
+ * @return {Backed}
83
+ */
84
+ Backed.setMethod(function clone() {
85
+ let result = new Backed(this.backing);
86
+ result.local = new Map(this.local);
87
+ return result;
88
+ });
89
+
90
+ /**
91
+ * Create a (shallow) clone of this backed map.
92
+ * Since we don't ever touch the backing itself, we don't have to clone that.
93
+ *
94
+ * @author Jelle De Loecker <jelle@elevenways.be>
95
+ * @since 1.2.1
96
+ * @version 1.2.1
97
+ *
98
+ * @return {Backed}
99
+ */
100
+ Backed.setMethod(function dryClone(wm, custom_method) {
101
+ return this.clone();
102
+ });
103
+
104
+ /**
105
+ * Simplify the object for Hawkejs
106
+ *
107
+ * @author Jelle De Loecker <jelle@elevenways.be>
108
+ * @since 1.2.1
109
+ * @version 1.2.1
110
+ *
111
+ * @param {WeakMap} wm
112
+ *
113
+ * @return {Backed}
114
+ */
115
+ Backed.setMethod(function toHawkejs(wm) {
116
+
117
+ let values = new Map(),
118
+ value,
119
+ keys = this.keys(),
120
+ key;
121
+
122
+ for (key of keys) {
123
+ value = this.get(key);
124
+ values.set(key, JSON.clone(value, 'toHawkejs', wm));
125
+ }
126
+
127
+ return new this.constructor(values);
128
+ });
129
+
130
+ /**
131
+ * Get all the keys
132
+ *
133
+ * @author Jelle De Loecker <jelle@elevenways.be>
134
+ * @since 1.2.1
135
+ * @version 1.2.1
136
+ *
137
+ * @return {String[]}
138
+ */
139
+ Backed.setMethod(function keys() {
140
+
141
+ let result;
142
+
143
+ if (this.type == BACKING) {
144
+ result = this.backing.keys();
145
+ } else if (this.type == MAP) {
146
+ result = [...this.backing.keys()];
147
+ } else if (this.type == OBJECT) {
148
+ result = Object.keys(this.backing);
149
+ } else {
150
+ result = [];
151
+ }
152
+
153
+ if (this.local.size) {
154
+ for (let key of this.local.keys()) {
155
+ if (result.indexOf(key) == -1) {
156
+ result.push(key);
157
+ }
158
+ }
159
+ }
160
+
161
+ return result;
162
+ });
163
+
164
+ /**
165
+ * Get a value by it's name
166
+ *
167
+ * @author Jelle De Loecker <jelle@elevenways.be>
168
+ * @since 1.2.1
169
+ * @version 1.2.1
170
+ *
171
+ * @param {String} name
172
+ *
173
+ * @return {Mixed}
174
+ */
175
+ Backed.setMethod(function get(name) {
176
+
177
+ if (this.local.has(name)) {
178
+ return this.local.get(name);
179
+ }
180
+
181
+ if (!this.type) {
182
+ return;
183
+ }
184
+
185
+ let value;
186
+
187
+ if (this.type == BACKING || this.type == MAP) {
188
+ value = this.backing.get(name);
189
+ } else if (this.type == OBJECT) {
190
+ value = this.backing[name];
191
+ }
192
+
193
+ return value;
194
+ });
195
+
196
+ /**
197
+ * Set a value
198
+ *
199
+ * @author Jelle De Loecker <jelle@elevenways.be>
200
+ * @since 1.2.1
201
+ * @version 1.2.1
202
+ *
203
+ * @param {String} name
204
+ * @param {*} value
205
+ *
206
+ * @return {*}
207
+ */
208
+ Backed.setMethod(function set(name, value) {
209
+ this.local.set(name, value);
210
+ return value;
211
+ });
212
+
213
+ /**
214
+ * Dry the object
215
+ *
216
+ * @author Jelle De Loecker <jelle@elevenways.be>
217
+ * @since 1.2.1
218
+ * @version 1.2.1
219
+ *
220
+ * @return {Object}
221
+ */
222
+ Backed.setMethod(function toDry() {
223
+
224
+ let result = {
225
+ backing : {}
226
+ };
227
+
228
+ let value,
229
+ key;
230
+
231
+ for (key of this.keys()) {
232
+ value = this.get(key);
233
+ result.backing[key] = value;
234
+ }
235
+
236
+ return {value: result};
237
+ });
238
+
239
+ /**
240
+ * Iterate over the object
241
+ *
242
+ * @author Jelle De Loecker <jelle@elevenways.be>
243
+ * @since 1.2.1
244
+ * @version 1.2.1
245
+ *
246
+ * @return {Object}
247
+ */
248
+ Backed.setMethod(Symbol.iterator, function* iterate() {
249
+
250
+ let value,
251
+ key;
252
+
253
+ for (key of this.keys()) {
254
+ value = this.get(key);
255
+ yield value;
256
+ }
257
+ });
@@ -0,0 +1,125 @@
1
+ /**
2
+ * The EnumValues class
3
+ *
4
+ * @constructor
5
+ *
6
+ * @author Jelle De Loecker <jelle@elevenways.be>
7
+ * @since 1.2.1
8
+ * @version 1.2.1
9
+ */
10
+ const EnumMap = Function.inherits('Alchemy.Map.Backed', 'Enum');
11
+
12
+ /**
13
+ * Get a value by it's name
14
+ *
15
+ * @author Jelle De Loecker <jelle@elevenways.be>
16
+ * @since 1.2.1
17
+ * @version 1.2.1
18
+ *
19
+ * @param {String} name
20
+ *
21
+ * @return {Mixed}
22
+ */
23
+ EnumMap.setMethod(function get(name) {
24
+
25
+ if (this.local.has(name)) {
26
+ return this.local.get(name);
27
+ }
28
+
29
+ let value = get.super.call(this, name);
30
+
31
+ if (value) {
32
+ value = this.set(name, value);
33
+ }
34
+
35
+ return value;
36
+ });
37
+
38
+ /**
39
+ * Set a value
40
+ *
41
+ * @author Jelle De Loecker <jelle@elevenways.be>
42
+ * @since 1.2.1
43
+ * @version 1.2.1
44
+ *
45
+ * @param {String} name
46
+ * @param {*} value
47
+ *
48
+ * @return {*}
49
+ */
50
+ EnumMap.setMethod(function set(name, value) {
51
+
52
+ if (value == null) {
53
+ return;
54
+ }
55
+
56
+ if (value.is_enumified) {
57
+ this.local.set(name, value);
58
+ return value;
59
+ }
60
+
61
+ let result;
62
+
63
+ if (typeof value == 'string') {
64
+ result = {
65
+ name : value,
66
+ title : value,
67
+ };
68
+ } else if (typeof value == 'function') {
69
+ result = {
70
+ name : value.name,
71
+ title : value.title,
72
+ };
73
+ } else {
74
+ result = {
75
+ name : value.name,
76
+ title : value.title || value.name,
77
+ };
78
+ }
79
+
80
+ result.value = value;
81
+ result.is_enumified = true;
82
+
83
+ this.local.set(name, result);
84
+
85
+ return result;
86
+ });
87
+
88
+
89
+ /**
90
+ * Simplify the object for Hawkejs
91
+ *
92
+ * @author Jelle De Loecker <jelle@elevenways.be>
93
+ * @since 1.2.1
94
+ * @version 1.2.1
95
+ *
96
+ * @param {WeakMap} wm
97
+ *
98
+ * @return {Enum}
99
+ */
100
+ EnumMap.setMethod(function toHawkejs(wm) {
101
+
102
+ let result = toHawkejs.super.call(this, wm),
103
+ original_value,
104
+ cloned_value,
105
+ keys = this.keys(),
106
+ key;
107
+
108
+ for (key of keys) {
109
+ original_value = this.get(key);
110
+ cloned_value = result.get(key);
111
+
112
+ if (original_value.value) {
113
+
114
+ if (typeof original_value.value == 'function') {
115
+ cloned_value.type = 'function';
116
+ }
117
+
118
+ if (original_value.value.schema) {
119
+ cloned_value.schema = JSON.clone(original_value.value.schema, 'toHawkejs', wm);
120
+ }
121
+ }
122
+ }
123
+
124
+ return result;
125
+ });
@@ -266,7 +266,7 @@ Router.setMethod(function routeConfig(name, socket_route) {
266
266
  *
267
267
  * @author Jelle De Loecker <jelle@develry.be>
268
268
  * @since 0.2.0
269
- * @version 1.1.5
269
+ * @version 1.2.1
270
270
  *
271
271
  * @param {String} name
272
272
  * @param {Object} parameters
@@ -331,6 +331,12 @@ Router.setMethod(function routeUrl(name, _parameters, options) {
331
331
  // Remove [brackets]
332
332
  url = url.replace(/\[.*?\]/g, '');
333
333
  url = url.assign(parameters, true, RURL.encodeUriQuery);
334
+
335
+ // Remove capturing regexes
336
+ if (url.indexOf('(') > -1) {
337
+ // @TODO: should exclude escaped colons like "\\("
338
+ url = url.replace(/\(.*?\)/g, '');
339
+ }
334
340
  }
335
341
 
336
342
  url = this.parseURL(url);
@@ -5,9 +5,14 @@
5
5
  *
6
6
  * @author Jelle De Loecker <jelle@develry.be>
7
7
  * @since 0.2.0
8
- * @version 1.1.0
8
+ * @version 1.2.1
9
9
  */
10
10
  var Enum = Function.inherits('Alchemy.Field', function Enum(schema, name, options) {
11
+
12
+ if (options.values) {
13
+ options.values = new Classes.Alchemy.Map.Enum(options.values);
14
+ }
15
+
11
16
  Enum.super.call(this, schema, name, options);
12
17
  });
13
18
 
@@ -40,9 +45,9 @@ Enum.setMethod(function cast(value) {
40
45
  *
41
46
  * @author Jelle De Loecker <jelle@develry.be>
42
47
  * @since 0.2.0
43
- * @version 0.2.0
48
+ * @version 1.2.1
44
49
  *
45
- * @return {Object}
50
+ * @return {EnumValues}
46
51
  */
47
52
  Enum.setMethod(function getValues() {
48
53
 
@@ -62,7 +67,7 @@ Enum.setMethod(function getValues() {
62
67
  *
63
68
  * @author Jelle De Loecker <jelle@develry.be>
64
69
  * @since 1.1.0
65
- * @version 1.1.0
70
+ * @version 1.2.1
66
71
  *
67
72
  * @param {WeakMap} wm
68
73
  *
@@ -72,37 +77,5 @@ Enum.setMethod(function getClientConfigOptions(wm) {
72
77
 
73
78
  let options = JSON.clone(this.options, 'toHawkejs', wm);
74
79
 
75
- if (this.options.values) {
76
- let value,
77
- entry,
78
- key;
79
-
80
- if (!options.values) {
81
- options.values = {};
82
- }
83
-
84
- for (key in this.options.values) {
85
-
86
- if (options.values[key]) {
87
- continue;
88
- }
89
-
90
- value = this.options.values[key];
91
-
92
- if (typeof value == 'function') {
93
- entry = {
94
- name : value.name,
95
- title : value.title,
96
- };
97
-
98
- if (value.schema) {
99
- entry.schema = JSON.clone(value.schema, 'toHawkejs', wm);
100
- }
101
-
102
- options.values[key] = entry;
103
- }
104
- }
105
- }
106
-
107
80
  return options;
108
81
  });
@@ -91,7 +91,7 @@ SchemaField.setProperty(function requires_translating() {
91
91
  *
92
92
  * @author Jelle De Loecker <jelle@develry.be>
93
93
  * @since 0.2.0
94
- * @version 0.4.0
94
+ * @version 1.2.1
95
95
  *
96
96
  * @param {Object} record
97
97
  * @param {String} some_path Some path to a field in the wanted schema
@@ -106,8 +106,7 @@ SchemaField.setMethod(function getSubschema(record, some_path) {
106
106
  record_value,
107
107
  pieces,
108
108
  field,
109
- name,
110
- temp;
109
+ name;
111
110
 
112
111
  // If schema is a string,
113
112
  // it needs to be extracted from another field's value
@@ -131,9 +130,9 @@ SchemaField.setMethod(function getSubschema(record, some_path) {
131
130
  }
132
131
 
133
132
  // Get the values that field can have (probably an enum)
134
- temp = field.getValues();
133
+ let values = field.getValues();
135
134
 
136
- if (temp == null) {
135
+ if (values == null) {
137
136
  return null;
138
137
  }
139
138
 
@@ -146,23 +145,14 @@ SchemaField.setMethod(function getSubschema(record, some_path) {
146
145
  }
147
146
 
148
147
  // Get the correct field value
149
- temp = temp[record_value];
150
-
151
- if (temp != null) {
152
- schema = temp[property_name];
148
+ let enum_value = values.get(record_value);
153
149
 
154
- if (schema == null && typeof temp == 'function') {
155
- temp = new temp();
156
- schema = temp[property_name] || temp.schema || temp.blueprint;
157
-
158
- if (schema != null) {
159
- schema.setModel(this.schema.model_name);
160
- schema.setName(this.name);
161
- schema.setParent(this.schema);
162
- }
163
- }
164
- } else {
150
+ if (!enum_value) {
165
151
  schema = null;
152
+ } else if (enum_value.schema) {
153
+ schema = enum_value.schema;
154
+ } else if (enum_value.value) {
155
+ schema = enum_value.value[property_name] || enum_value.value.schema;
166
156
  }
167
157
  }
168
158
 
@@ -243,7 +233,7 @@ SchemaField.setMethod(function _toDatasource(value, data, datasource, callback)
243
233
  }
244
234
  }
245
235
 
246
- log.warning('Model and subschema were not found for', that.name);
236
+ log.warning('Model and subschema were not found for', that.path);
247
237
  return datasource.toDatasource(null, value, callback);
248
238
  });
249
239
 
@@ -23,12 +23,17 @@ Function.getNamespace('Alchemy.Element').setStatic('default_element_prefix', 'al
23
23
  *
24
24
  * @author Jelle De Loecker <jelle@elevenways.be>
25
25
  * @since 1.1.3
26
- * @version 1.1.3
26
+ * @version 1.2.1
27
27
  *
28
28
  * @return {RURL}
29
29
  */
30
30
  Element.setMethod(function getCurrentUrl() {
31
31
  if (Blast.isBrowser) {
32
+
33
+ if (hawkejs.scene.opening_url && hawkejs.scene.opening_url.url) {
34
+ return Blast.Classes.RURL.parse(hawkejs.scene.opening_url.url);
35
+ }
36
+
32
37
  return Blast.Classes.RURL.parse(window.location);
33
38
  } else if (this.hawkejs_renderer && this.hawkejs_renderer.variables && this.hawkejs_renderer.variables.__url) {
34
39
  return this.hawkejs_renderer.variables.__url.clone();
@@ -1066,4 +1066,18 @@ Alchemy.setMethod(function syncDataWithServer() {
1066
1066
  });
1067
1067
 
1068
1068
  return Function.parallel(tasks);
1069
+ });
1070
+
1071
+ /**
1072
+ * Create a new schema on the client
1073
+ *
1074
+ * @author Jelle De Loecker <jelle@elevenways.be>
1075
+ * @since 1.2.1
1076
+ * @version 1.2.1
1077
+ *
1078
+ * @param {*} parent
1079
+ */
1080
+ Alchemy.setMethod(function createSchema(parent) {
1081
+ let schema = new Classes.Alchemy.Client.Schema(parent);
1082
+ return schema;
1069
1083
  });
@@ -1721,6 +1721,20 @@ Alchemy.setMethod(function importFromStream(input, options) {
1721
1721
  return pledge;
1722
1722
  });
1723
1723
 
1724
+ /**
1725
+ * Create a new schema
1726
+ *
1727
+ * @author Jelle De Loecker <jelle@elevenways.be>
1728
+ * @since 1.2.1
1729
+ * @version 1.2.1
1730
+ *
1731
+ * @param {*} parent
1732
+ */
1733
+ Alchemy.setMethod(function createSchema(parent) {
1734
+ let schema = new Classes.Alchemy.Schema(parent);
1735
+ return schema;
1736
+ });
1737
+
1724
1738
  /**
1725
1739
  * The alchemy global, where everything will be stored
1726
1740
  *
@@ -1325,7 +1325,7 @@ Alchemy.setMethod(function exposeStatic(name, value) {
1325
1325
  *
1326
1326
  * @author Jelle De Loecker <jelle@develry.be>
1327
1327
  * @since 1.1.0
1328
- * @version 1.1.0
1328
+ * @version 1.2.1
1329
1329
  */
1330
1330
  Alchemy.setMethod(function exposeDefaultStaticVariables() {
1331
1331
 
@@ -1372,6 +1372,9 @@ Alchemy.setMethod(function exposeDefaultStaticVariables() {
1372
1372
 
1373
1373
  hawkejs.exposeStatic('app_version', app_version);
1374
1374
  hawkejs.app_version = app_version;
1375
+
1376
+ // Emit as a global event so plugins can also expose their data
1377
+ this.emit('generate_static_variables', hawkejs);
1375
1378
  });
1376
1379
 
1377
1380
  /**
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.2.0",
4
+ "version": "1.2.1",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",
@@ -22,7 +22,7 @@
22
22
  "chokidar" : "~3.5.3",
23
23
  "formidable" : "~1.2.2",
24
24
  "graceful-fs" : "~4.2.9",
25
- "hawkejs" : "~2.2.0",
25
+ "hawkejs" : "~2.2.3",
26
26
  "jsondiffpatch" : "~0.4.1",
27
27
  "mime" : "~3.0.0",
28
28
  "minimist" : "~1.2.5",
@@ -31,7 +31,7 @@
31
31
  "mongodb" : "~3.6.6",
32
32
  "ncp" : "~2.0.0",
33
33
  "postcss" : "~8.4.6",
34
- "protoblast" : "~0.7.10",
34
+ "protoblast" : "~0.7.16",
35
35
  "semver" : "~7.3.5",
36
36
  "socket.io" : "~2.4.0",
37
37
  "@11ways/socket.io-stream" : "~0.9.2",