@aegis-framework/artemis 0.3.28 → 0.4.0

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 (59) hide show
  1. package/LICENSE +1 -1
  2. package/dist/artemis.browser.js +4 -0
  3. package/dist/artemis.browser.js.map +24 -0
  4. package/dist/artemis.js +3 -1
  5. package/dist/artemis.js.map +23 -1
  6. package/dist/types/DOM.d.ts +383 -0
  7. package/dist/types/DOM.d.ts.map +1 -0
  8. package/dist/types/Debug.d.ts +118 -0
  9. package/dist/types/Debug.d.ts.map +1 -0
  10. package/dist/types/FileSystem.d.ts +69 -0
  11. package/dist/types/FileSystem.d.ts.map +1 -0
  12. package/dist/types/Form.d.ts +32 -0
  13. package/dist/types/Form.d.ts.map +1 -0
  14. package/dist/types/Platform.d.ts +93 -0
  15. package/dist/types/Platform.d.ts.map +1 -0
  16. package/dist/types/Preload.d.ts +26 -0
  17. package/dist/types/Preload.d.ts.map +1 -0
  18. package/dist/types/Request.d.ts +86 -0
  19. package/dist/types/Request.d.ts.map +1 -0
  20. package/dist/types/Space.d.ts +205 -0
  21. package/dist/types/Space.d.ts.map +1 -0
  22. package/dist/types/SpaceAdapter/IndexedDB.d.ts +130 -0
  23. package/dist/types/SpaceAdapter/IndexedDB.d.ts.map +1 -0
  24. package/dist/types/SpaceAdapter/LocalStorage.d.ts +125 -0
  25. package/dist/types/SpaceAdapter/LocalStorage.d.ts.map +1 -0
  26. package/dist/types/SpaceAdapter/RemoteStorage.d.ts +122 -0
  27. package/dist/types/SpaceAdapter/RemoteStorage.d.ts.map +1 -0
  28. package/dist/types/SpaceAdapter/SessionStorage.d.ts +30 -0
  29. package/dist/types/SpaceAdapter/SessionStorage.d.ts.map +1 -0
  30. package/dist/types/SpaceAdapter/types.d.ts +76 -0
  31. package/dist/types/SpaceAdapter/types.d.ts.map +1 -0
  32. package/dist/types/Text.d.ts +47 -0
  33. package/dist/types/Text.d.ts.map +1 -0
  34. package/dist/types/Util.d.ts +31 -0
  35. package/dist/types/Util.d.ts.map +1 -0
  36. package/dist/types/browser.d.ts +7 -0
  37. package/dist/types/browser.d.ts.map +1 -0
  38. package/dist/types/index.d.ts +11 -0
  39. package/dist/types/index.d.ts.map +1 -0
  40. package/package.json +42 -53
  41. package/dist/artemis.min.js +0 -2
  42. package/dist/artemis.min.js.map +0 -1
  43. package/dist/index.js +0 -2
  44. package/dist/index.js.map +0 -1
  45. package/index.js +0 -10
  46. package/src/DOM.js +0 -993
  47. package/src/Debug.js +0 -233
  48. package/src/FileSystem.js +0 -109
  49. package/src/Form.js +0 -73
  50. package/src/Platform.js +0 -166
  51. package/src/Preload.js +0 -48
  52. package/src/Request.js +0 -163
  53. package/src/Space.js +0 -334
  54. package/src/SpaceAdapter/IndexedDB.js +0 -345
  55. package/src/SpaceAdapter/LocalStorage.js +0 -395
  56. package/src/SpaceAdapter/RemoteStorage.js +0 -219
  57. package/src/SpaceAdapter/SessionStorage.js +0 -46
  58. package/src/Text.js +0 -133
  59. package/src/Util.js +0 -55
package/src/Request.js DELETED
@@ -1,163 +0,0 @@
1
- /**
2
- * ==============================
3
- * Request
4
- * ==============================
5
- */
6
-
7
- /**
8
- * Simple Wrapper for the fetch API, providing simple functions to handle requests
9
- *
10
- * @class
11
- */
12
- export class Request {
13
-
14
- /**
15
- * @static serialize - Serialize an object of data into a URI encoded format
16
- *
17
- * @param {Object} data - Key-value object of data to serialize
18
- * @return {string} - Serialized Data
19
- */
20
- static serialize (data) {
21
- return Object.keys (data).map ((key) => {
22
- return encodeURIComponent (key) + '=' + encodeURIComponent (data[key]);
23
- }).join ('&');
24
- }
25
-
26
- /**
27
- * @static get - Make a GET request to a given URL with the provided data
28
- * parameters and an optional configuration object for the request.
29
- *
30
- * @param {string} url - URL to make the request to
31
- * @param {Object} [data = {}] - Parameters to send in the URL, represented
32
- * as a JSON object. These parameters will be sent as a query in the URL
33
- * @param {Object} [options = {}] - Options object for configurations you want
34
- * to use in the fetch () request made.
35
- * @return {Promise<Response>} - Resolves to the response of the request
36
- */
37
- static get (url, data = {}, options = {}) {
38
- const query = Request.serialize (data);
39
-
40
- // Check if there is actually any data parameters and join them to the
41
- // url as query parameters
42
- if (query !== '') {
43
- url = `${url}?${query}`;
44
- }
45
-
46
- return fetch (url, options);
47
- }
48
-
49
- /**
50
- * @static post - Make a POST request to a given URL with the provided data
51
- * and an optional configuration object for the request.
52
- *
53
- * @param {string} url - URL to make the request
54
- * @param {Object} [data = {}] - Set of data to send in the URL, represented
55
- * as a JSON object
56
- * @param {Object} [options = {}] - Options object for configurations you want
57
- * to use in the fetch () request made. The Content-Type header is used to
58
- * serialize data in the correct format and defaults to application/x-www-form-urlencoded
59
- * @return {Promise<Response>} - Resolves to the response of the request
60
- */
61
- static post (url, data, options = {}) {
62
- let formData;
63
-
64
- if (typeof options.headers !== 'undefined') {
65
- const contentType = options.headers['Content-Type'];
66
- if (typeof contentType !== 'undefined') {
67
- if (contentType == 'multipart/form-data') {
68
- formData = new FormData ();
69
- for (const value in data) {
70
- formData.append (value, data[value]);
71
- }
72
- } else if (contentType == 'application/json') {
73
- formData = JSON.stringify (data);
74
- } else {
75
- formData = Request.serialize (data);
76
- }
77
- }
78
- } else {
79
- formData = Request.serialize (data);
80
- }
81
-
82
- const props = Object.assign ({}, {
83
- method: 'POST',
84
- headers: {
85
- 'Content-Type': 'application/x-www-form-urlencoded'
86
- },
87
- body: formData
88
- }, options);
89
-
90
- // Delete the explicit multipart/form-data header to allow boundary automatic filling
91
- if (typeof props.headers !== 'undefined') {
92
- if (props.headers['Content-Type'] === 'multipart/form-data') {
93
- delete props.headers['Content-Type'];
94
- }
95
- }
96
-
97
- return fetch (url, props);
98
- }
99
-
100
- /**
101
- * @static put - Make a PUT request to a given URL with the provided data
102
- * and an optional configuration object for the request.
103
- *
104
- * @param {string} url - URL to make the request
105
- * @param {Object} [data = {}] - Set of data to send in the URL, represented
106
- * as a JSON object
107
- * @param {Object} [options = {}] - Options object for configurations you want
108
- * to use in the fetch () request made. The Content-Type header is used to
109
- * serialize data in the correct format and defaults to application/x-www-form-urlencoded
110
- * @return {Promise<Response>} - Resolves to the response of the request
111
- */
112
- static put (url, data, options = {}) {
113
- return Request.post (url, data, Object.assign ({}, {method: 'PUT'}, options));
114
- }
115
-
116
- /**
117
- * @static delete - Make a DELETE request to a given URL with the provided data
118
- * and an optional configuration object for the request.
119
- *
120
- * @param {string} url - URL to make the request
121
- * @param {Object} [data = {}] - Parameters to send in the URL, represented
122
- * as a JSON object. These parameters will be sent as a query in the URL
123
- * @param {Object} [options = {}] - Options object for configurations you want
124
- * to use in the fetch () request made. The Content-Type header is used to
125
- * serialize data in the correct format and defaults to application/x-www-form-urlencoded
126
- * @return {Promise<Response>} - Resolves to the response of the request
127
- */
128
- static delete (url, data, options = {}) {
129
- return Request.get (url, data, Object.assign ({}, {method: 'DELETE'}, options));
130
- }
131
-
132
- /**
133
- * @static json - Request a JSON object from a given URL through a GET request
134
- *
135
- * @param {string} url - URL to make the request to
136
- * @param {Object} [data = {}] - Parameters to send in the URL, represented
137
- * as a JSON object. These parameters will be sent as a query in the URL
138
- * @param {Object} [options = {}] - Options object for configurations you want
139
- * to use in the fetch () request made.
140
- * @return {Promise<Object>} - Resolves to the json object obtained from the request response
141
- */
142
- static json (url, data = {}, options = {}) {
143
- return Request.get (url, data, options).then ((response) => {
144
- return response.json ();
145
- });
146
- }
147
-
148
- /**
149
- * @static blob - Request a Blob from a given URL through a GET request
150
- *
151
- * @param {string} url - URL to make the request to
152
- * @param {Object} [data = {}] - Parameters to send in the URL, represented
153
- * as a JSON object. These parameters will be sent as a query in the URL
154
- * @param {Object} [options = {}] - Options object for configurations you want
155
- * to use in the fetch () request made.
156
- * @return {Promise<Blob>} - Resolves to the blob obtained from the request response
157
- */
158
- static blob (url, data = {}, options = {}) {
159
- return Request.get (url, data, options).then ((response) => {
160
- return response.blob ();
161
- });
162
- }
163
- }
package/src/Space.js DELETED
@@ -1,334 +0,0 @@
1
- /**
2
- * ==============================
3
- * Space
4
- * ==============================
5
- */
6
-
7
- import { LocalStorage } from './SpaceAdapter/LocalStorage';
8
- import { SessionStorage } from './SpaceAdapter/SessionStorage';
9
- import { IndexedDB } from './SpaceAdapter/IndexedDB';
10
- import { RemoteStorage } from './SpaceAdapter/RemoteStorage';
11
-
12
- /**
13
- * List of Adapters Available
14
- */
15
- export const SpaceAdapter = {
16
- LocalStorage,
17
- SessionStorage,
18
- IndexedDB,
19
- RemoteStorage
20
- };
21
-
22
- /**
23
- * Space provides a simple wrapper for different Storage APIs. It aims to
24
- * provide data independence through storage namespaces and versioning, allowing
25
- * transparent data formatting and content modifications through versions.
26
- *
27
- * While this class documentation provides some information, specific details may
28
- * be addressed on the documentation of each adapter.
29
- *
30
- * @class
31
- */
32
- export class Space {
33
-
34
- /**
35
- * Create a new Space Object. If no name and version is defined, the global LocalSpace space is used.
36
- *
37
- * @constructor
38
- * @param {SpaceAdapter} [adapter = SpaceAdapter.LocalStorage] - Space Adapter
39
- * to use. Currently LocalStorage, SessionStorage, IndexedDB and Server are
40
- * available
41
- * @param {Object} [configuration = {}] - Configuration object for the space.
42
- * This configuration may change depending on the adapter used, however all
43
- * adapters have support for a name, version and store properties.
44
- * @param {string} configuration.name - Name of the Space
45
- * @param {string} configuration.version - Version of the Space in Semantic versioning syntax
46
- * @param {string} configuration.store - Name of the Object Store to use
47
- */
48
- constructor (adapter = SpaceAdapter.LocalStorage, configuration = {}) {
49
- // Assign the provided configuration to the default one
50
- this._configuration = Object.assign ({}, {name: '', version: '', store: ''}, configuration);
51
-
52
- // Set up the adapter instance to use
53
- this.adapter = new adapter (this._configuration);
54
-
55
- // This object stores all the callbacks the user can define for the
56
- // space operations
57
- this.callbacks = {
58
- 'create': [],
59
- 'update': [],
60
- 'delete': []
61
- };
62
-
63
- // A transformation is an object that can contain a set and get functions
64
- // every transformation will be applied to the retrieved value or to the
65
- // value before storing it.
66
- this.transformations = {
67
-
68
- };
69
- }
70
-
71
- /**
72
- * Modify the space configuration, it will also be passed down to the adapter
73
- * using its configuration () function.
74
- *
75
- * @param {object} - Configuration object to set up
76
- * @return {object} - Configuration object if no param was passed
77
- */
78
- configuration (object = null) {
79
- if (object !== null) {
80
- this._configuration = Object.assign ({}, this._configuration, object);
81
- this.adapter.configuration (object);
82
- } else {
83
- return this._configuration;
84
- }
85
- }
86
-
87
- /**
88
- * Open the Storage Object to be used depending on the SpaceAdapter
89
- *
90
- * @return {Promise}
91
- */
92
- open () {
93
- return this.adapter.open ().then (() => {
94
- return Promise.resolve (this);
95
- });
96
- }
97
-
98
- /**
99
- * Store a key-value pair
100
- *
101
- * @param {string} key - Key with which this value will be saved
102
- * @param {Object|string|Number} - Value to save
103
- * @return {Promise<{key, value}>}
104
- */
105
- set (key, value) {
106
- // Apply all set transformations to the value
107
- for (const id of Object.keys (this.transformations)) {
108
- if (typeof this.transformations[id].set === 'function') {
109
- value = this.transformations[id].set.call (null, key, value);
110
- }
111
- }
112
-
113
- return this.adapter.set (key, value).then (({key, value}) => {
114
- for (const callback of this.callbacks.create) {
115
- callback.call (null, key, value);
116
- }
117
- return Promise.resolve ({key, value});
118
- });
119
- }
120
-
121
- /**
122
- * Update a key-value pair. In difference with the set () method, the update
123
- * method will use an Object.assign () in the case of objects so no value is
124
- * lost.
125
- *
126
- * @param {string} key - Key with which this value will be saved
127
- * @param {Object|string|Number} - Value to save
128
- * @return {Promise<{key, value}>}
129
- */
130
- update (key, value) {
131
- // Apply all set transformations to the value
132
- for (const id of Object.keys (this.transformations)) {
133
- if (typeof this.transformations[id].set === 'function') {
134
- value = this.transformations[id].set.call (null, key, value);
135
- }
136
- }
137
-
138
- return this.adapter.update (key, value).then (({key, value}) => {
139
- for (const callback of this.callbacks.update) {
140
- callback.call (null, key, value);
141
- }
142
- return Promise.resolve ({key, value});
143
- });
144
- }
145
-
146
- /**
147
- * Retrieves a value from storage given it's key
148
- *
149
- * @param {string} - Key with which the value was saved
150
- * @return {Promise<Object>|Promise<string>|Promise<Number>} - Resolves to the retreived value
151
- * or its rejected if it doesn't exist.
152
- */
153
- get (key) {
154
- return this.adapter.get (key).then ((value) => {
155
- // Apply all get transformations to the value
156
- for (const id of Object.keys (this.transformations)) {
157
- if (typeof this.transformations[id].get === 'function') {
158
- value = this.transformations[id].get.call (null, key, value);
159
- }
160
- }
161
- return value;
162
- });
163
- }
164
-
165
- /**
166
- * Retrieves all the values in the space in a key-value JSON object
167
- *
168
- * @return {Promise<Object>} - Resolves to the retreived values
169
- */
170
- getAll () {
171
- return this.adapter.getAll ().then ((values) => {
172
- // Apply all get transformations to the value
173
- for (const key of Object.keys (values)) {
174
- for (const id of Object.keys (this.transformations)) {
175
- if (typeof this.transformations[id].get === 'function') {
176
- values[key] = this.transformations[id].get.call (null, key, values[key]);
177
- }
178
- }
179
- }
180
- return values;
181
- });
182
- }
183
-
184
- /**
185
- * Iterate over every value in the space
186
- *
187
- * @param {function (key, value)} callback - A callback function receiving the
188
- * key and value of a value. Must return a callback
189
- * @return {Promise} - Resolves when all callbacks have been resolved.
190
- */
191
- each (callback) {
192
- return this.getAll ().then ((values) => {
193
- const promises = [];
194
- for (const i of Object.keys (values)) {
195
- promises.push (callback.call (this, i, values[i]));
196
- }
197
- return Promise.all (promises);
198
- });
199
- }
200
-
201
- /**
202
- * Check if a space contains a given key. Not all adapters may give this information
203
- *
204
- * @param {string} key - Key to look for.
205
- * @return {Promise} - Promise gets resolved if it exists and rejected if
206
- * doesn't
207
- */
208
- contains (key) {
209
- return this.adapter.contains (key);
210
- }
211
-
212
- /**
213
- * Upgrade a Space Version. Not all adapters may provide this functionality
214
- *
215
- * @param oldVersion {string} - The version of the storage to be upgraded
216
- * @param newVersion {string} - The version to be upgraded to
217
- * @param callback {function} - Function to transform the old stored values to the new version's format
218
- *
219
- * @returns {Promise} - Result of the upgrade operation
220
- */
221
- upgrade (oldVersion, newVersion, callback) {
222
- return this.adapter.upgrade (oldVersion, newVersion, callback).then (() => {
223
- return Promise.resolve (this);
224
- });
225
- }
226
-
227
- /**
228
- * Rename a Space. Not all adapters may provide this functionality
229
- *
230
- * @param {string} name - New name to be used.
231
- * @returns {Promise} Result of the rename operation
232
- */
233
- rename (name) {
234
- return this.adapter.rename (name);
235
- }
236
-
237
- /**
238
- * Add a callback function to be run every time a value is created.
239
- *
240
- * @param {function (key, value)} callback - Callback Function. Key and Value pair will be sent as parameters when run.
241
- */
242
- onCreate (callback) {
243
- this.callbacks.create.push (callback);
244
- }
245
-
246
- /**
247
- * Add a callback function to be run every time a value is updated.
248
- *
249
- * @param {function (key, value)} callback - Callback Function. Key and Value pair will be sent as parameters when run.
250
- */
251
- onUpdate (callback) {
252
- this.callbacks.update.push (callback);
253
- }
254
-
255
- /**
256
- * Add a callback function to be run every time a value is deleted.
257
- *
258
- * @param {function (key, value)} callback - Callback Function. Key and Value pair will be sent as parameters when run.
259
- */
260
- onDelete (callback) {
261
- this.callbacks.delete.push (callback);
262
- }
263
-
264
- /**
265
- * Add a transformation function to the space.
266
- *
267
- * @param {string} id - Unique transformation name or identifier
268
- * @param {function (key, value)|null} get - Transformation function to apply to the content before
269
- * returning the value when using the get () function .
270
- * @param {function (key, value)|null} set - Transformation function to apply to the content before
271
- * saving it when using the set () function befo.
272
- */
273
- addTransformation ({id, get, set}) {
274
- this.transformations[id] = {
275
- id,
276
- get,
277
- set
278
- };
279
- }
280
-
281
- /**
282
- * Remove a transformation function given its id
283
- *
284
- * @param {string} id - Name or identifier of the transformation to remove
285
- */
286
- removeTransformation (id) {
287
- delete this.transformations[id];
288
- }
289
-
290
- /**
291
- * Get the key that corresponds to a given index in the storage. Not all adapters may provide this functionality
292
- *
293
- * @param {Number} index - Index to get the key from
294
- * @param {boolean} [full = false] - Whether to return the full key name including space id or just the key name
295
- * @return {Promise<string>} - Resolves to the key's name
296
- */
297
- key (index, full = false) {
298
- return this.adapter.key (index, full);
299
- }
300
-
301
- /**
302
- * Return all keys stored in the space. Not all adapters may provide this functionality
303
- *
304
- * @param {boolean} [full = false] - Whether to return the full key name including space id or just the key name
305
- * @return {Promise<string[]>} - Array of keys
306
- */
307
- keys (full = false) {
308
- return this.adapter.keys (full);
309
- }
310
-
311
- /**
312
- * Delete a value from the space given it's key
313
- *
314
- * @param {string} key - Key of the item to delete
315
- * @return {Promise<key, value>} - Resolves to the key and value of the deleted object
316
- */
317
- remove (key) {
318
- return this.adapter.remove (key).then ((value) => {
319
- // Run the callback for deletions
320
- for (const callback of this.callbacks.delete) {
321
- callback.call (null, key, value);
322
- }
323
- });
324
- }
325
-
326
- /**
327
- * Clear the entire space
328
- *
329
- * @return {Promise} - Result of the clear operation
330
- */
331
- clear () {
332
- return this.adapter.clear ();
333
- }
334
- }