@cuecue/store-mysql 0.0.27 → 0.0.28
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/dist/index.js +36 -24
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mysql = require('mysql');
|
|
4
|
+
var StateMachine = require('javascript-state-machine');
|
|
5
|
+
var EventEmitter = require('wolfy87-eventemitter');
|
|
6
|
+
var createDebug = require('debug');
|
|
7
|
+
var isObject = require('lodash/isObject');
|
|
8
|
+
var core = require('@cuecue/core');
|
|
9
|
+
var isString = require('lodash/isString');
|
|
10
|
+
var isArray = require('lodash/isArray');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var mysql__default = /*#__PURE__*/_interopDefaultLegacy(mysql);
|
|
15
|
+
var StateMachine__default = /*#__PURE__*/_interopDefaultLegacy(StateMachine);
|
|
16
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
17
|
+
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
18
|
+
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
19
|
+
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
|
|
20
|
+
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
|
|
9
21
|
|
|
10
22
|
const now = () => new Date().toISOString().slice(0, 19).replace('T', ' ');
|
|
11
23
|
const getIdFromParams = params => Object.keys(params).reduce((acc, key) => {
|
|
@@ -30,13 +42,13 @@ const getParams = params => {
|
|
|
30
42
|
values
|
|
31
43
|
};
|
|
32
44
|
};
|
|
33
|
-
const setUpdateData = data => Object.keys(data).map(key => (
|
|
45
|
+
const setUpdateData = data => Object.keys(data).map(key => (isObject__default["default"](data[key]) || isArray__default["default"](data[key])) && key === 'data' ? JSON.stringify(data[key]) : data[key]);
|
|
34
46
|
const getUpdateFields = data => ({
|
|
35
47
|
fields: Object.keys(data).reduce((items, key) => [...items, `${key} = ?`], []).join(', '),
|
|
36
48
|
values: setUpdateData(data)
|
|
37
49
|
});
|
|
38
|
-
const setInsertData = data =>
|
|
39
|
-
if (key === 'data' && (
|
|
50
|
+
const setInsertData = data => isObject__default["default"](data) ? Object.keys(data).reduce((acc, key) => {
|
|
51
|
+
if (key === 'data' && (isObject__default["default"](data[key]) || isArray__default["default"](data[key]))) {
|
|
40
52
|
acc[key] = JSON.stringify(data[key]);
|
|
41
53
|
} else {
|
|
42
54
|
acc[key] = data[key];
|
|
@@ -45,7 +57,7 @@ const setInsertData = data => isObject(data) ? Object.keys(data).reduce((acc, ke
|
|
|
45
57
|
return acc;
|
|
46
58
|
}, {}) : null;
|
|
47
59
|
const getInsertFields = data => {
|
|
48
|
-
if (!
|
|
60
|
+
if (!isObject__default["default"](data)) {
|
|
49
61
|
return null;
|
|
50
62
|
}
|
|
51
63
|
|
|
@@ -55,8 +67,8 @@ const getInsertFields = data => {
|
|
|
55
67
|
values: Object.values(setInsertData(data))
|
|
56
68
|
};
|
|
57
69
|
};
|
|
58
|
-
const getResult = result =>
|
|
59
|
-
if (key === 'data' &&
|
|
70
|
+
const getResult = result => isObject__default["default"](result) ? Object.keys(result).reduce((acc, key) => {
|
|
71
|
+
if (key === 'data' && isString__default["default"](result[key])) {
|
|
60
72
|
acc[key] = JSON.parse(result[key]);
|
|
61
73
|
} else {
|
|
62
74
|
acc[key] = result[key];
|
|
@@ -66,9 +78,9 @@ const getResult = result => isObject(result) ? Object.keys(result).reduce((acc,
|
|
|
66
78
|
}, {}) : null;
|
|
67
79
|
const getResults = results => results.map(res => getResult(res));
|
|
68
80
|
|
|
69
|
-
const debug =
|
|
81
|
+
const debug = createDebug__default["default"]('cuecue:store:mysql');
|
|
70
82
|
|
|
71
|
-
class MysqlStore extends
|
|
83
|
+
class MysqlStore extends EventEmitter__default["default"] {
|
|
72
84
|
constructor(opts = {}) {
|
|
73
85
|
super();
|
|
74
86
|
this.options = {
|
|
@@ -91,7 +103,7 @@ class MysqlStore extends EventEmitter {
|
|
|
91
103
|
this.onDisconnected = this.onDisconnected.bind(this);
|
|
92
104
|
this.onInvalidTransition = this.onInvalidTransition.bind(this);
|
|
93
105
|
this.client = null;
|
|
94
|
-
this.state = new
|
|
106
|
+
this.state = new StateMachine__default["default"]({
|
|
95
107
|
transitions: [{
|
|
96
108
|
name: 'init',
|
|
97
109
|
from: 'none',
|
|
@@ -153,7 +165,7 @@ class MysqlStore extends EventEmitter {
|
|
|
153
165
|
|
|
154
166
|
findItem(type, externalId = null, internalId = null, withDeleted = false) {
|
|
155
167
|
return new Promise((resolve, reject) => {
|
|
156
|
-
const idParams =
|
|
168
|
+
const idParams = isObject__default["default"](externalId) ? externalId : { ...(externalId !== null ? {
|
|
157
169
|
externalId
|
|
158
170
|
} : null),
|
|
159
171
|
...(internalId !== null ? {
|
|
@@ -171,13 +183,13 @@ class MysqlStore extends EventEmitter {
|
|
|
171
183
|
}
|
|
172
184
|
|
|
173
185
|
const result = results !== null && results.length === 1 ? getResult(results[0]) : null;
|
|
174
|
-
resolve(parseStoreOutputId(result));
|
|
186
|
+
resolve(core.parseStoreOutputId(result));
|
|
175
187
|
});
|
|
176
188
|
});
|
|
177
189
|
}
|
|
178
190
|
|
|
179
191
|
addItem(type, data) {
|
|
180
|
-
const parsedData = parseStoreInputId(data);
|
|
192
|
+
const parsedData = core.parseStoreInputId(data);
|
|
181
193
|
const withCreated = parsedData !== null && !parsedData.created_at ? { ...parsedData,
|
|
182
194
|
created_at: now()
|
|
183
195
|
} : parsedData;
|
|
@@ -205,7 +217,7 @@ class MysqlStore extends EventEmitter {
|
|
|
205
217
|
}
|
|
206
218
|
|
|
207
219
|
updateItem(type, externalId, data) {
|
|
208
|
-
const parsedData = parseStoreInputId(data);
|
|
220
|
+
const parsedData = core.parseStoreInputId(data);
|
|
209
221
|
const withUpdated = { ...parsedData,
|
|
210
222
|
updated_at: now()
|
|
211
223
|
};
|
|
@@ -263,7 +275,7 @@ class MysqlStore extends EventEmitter {
|
|
|
263
275
|
}
|
|
264
276
|
|
|
265
277
|
const allResults = getResults(results);
|
|
266
|
-
resolve(parseStoreOutputId(allResults));
|
|
278
|
+
resolve(core.parseStoreOutputId(allResults));
|
|
267
279
|
});
|
|
268
280
|
});
|
|
269
281
|
}
|
|
@@ -277,7 +289,7 @@ class MysqlStore extends EventEmitter {
|
|
|
277
289
|
port,
|
|
278
290
|
autoConnect
|
|
279
291
|
} = this.options;
|
|
280
|
-
this.client =
|
|
292
|
+
this.client = mysql__default["default"].createConnection({
|
|
281
293
|
host,
|
|
282
294
|
user,
|
|
283
295
|
password,
|
|
@@ -371,4 +383,4 @@ class MysqlStore extends EventEmitter {
|
|
|
371
383
|
|
|
372
384
|
}
|
|
373
385
|
|
|
374
|
-
|
|
386
|
+
module.exports = MysqlStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuecue/store-mysql",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@babel/runtime": "^7.12.5",
|
|
46
|
-
"@cuecue/core": "^0.0.
|
|
46
|
+
"@cuecue/core": "^0.0.28",
|
|
47
47
|
"db-migrate": "^0.11.12",
|
|
48
48
|
"db-migrate-mysql": "^2.1.2",
|
|
49
49
|
"debug": "^4.3.1",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f6865a82708bf09de192b9a6367729e9faeb1250"
|
|
60
60
|
}
|