temba 0.8.2 → 0.9.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.
@@ -1,78 +1,69 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.initConfig = initConfig;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _logging = require("../logging");
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
-
18
- var defaultConfig = {
19
- resourceNames: [],
20
- validateResources: false,
21
- logLevel: _logging.logLevels.DEBUG,
22
- staticFolder: null,
23
- apiPrefix: '',
24
- connectionString: null,
25
- cacheControl: 'no-store',
26
- delay: 0,
27
- requestBodyValidator: {
28
- post: function post() {},
29
- put: function put() {}
30
- }
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initConfig = void 0;
4
+ const logging_1 = require("../logging");
5
+ const defaultConfig = {
6
+ resourceNames: [],
7
+ validateResources: false,
8
+ logLevel: logging_1.logLevels.DEBUG,
9
+ staticFolder: null,
10
+ apiPrefix: '',
11
+ connectionString: null,
12
+ cacheControl: 'no-store',
13
+ delay: 0,
14
+ requestBodyValidator: {
15
+ post: () => {
16
+ // do nothing
17
+ },
18
+ put: () => {
19
+ // do nothing
20
+ },
21
+ },
31
22
  };
32
-
33
23
  function initConfig(userConfig) {
34
- if (!userConfig) return defaultConfig;
35
-
36
- var config = _objectSpread({}, defaultConfig);
37
-
38
- if (userConfig.resourceNames && userConfig.resourceNames.length > 0) {
39
- config.resourceNames = userConfig.resourceNames;
40
- config.validateResources = true;
41
- }
42
-
43
- if (userConfig.logLevel && userConfig.logLevel.length !== 0 && Object.keys(_logging.logLevels).includes(userConfig.logLevel.toUpperCase())) {
44
- config.logLevel = userConfig.logLevel.toUpperCase();
45
- }
46
-
47
- if (userConfig.staticFolder) {
48
- config.staticFolder = userConfig.staticFolder.replace(/[^a-zA-Z0-9]/g, '');
49
- }
50
-
51
- if (userConfig.apiPrefix) {
52
- config.apiPrefix = '/' + userConfig.apiPrefix.replace(/[^a-zA-Z0-9]/g, '') + '/';
53
- }
54
-
55
- if (userConfig.connectionString && userConfig.connectionString.length > 0) {
56
- config.connectionString = userConfig.connectionString;
57
- }
58
-
59
- if (userConfig.cacheControl && userConfig.cacheControl.length > 0) {
60
- config.cacheControl = userConfig.cacheControl;
61
- }
62
-
63
- if (userConfig.delay && userConfig.delay.length !== 0 && typeof Number(userConfig.delay) === 'number' && Number(userConfig.delay) > 0 && Number(userConfig.delay) < 10000) {
64
- config.delay = Number(userConfig.delay);
65
- }
66
-
67
- if (userConfig.requestBodyValidator) {
68
- if (userConfig.requestBodyValidator.post && typeof userConfig.requestBodyValidator.post === 'function') {
69
- config.requestBodyValidator.post = userConfig.requestBodyValidator.post;
24
+ if (!userConfig)
25
+ return defaultConfig;
26
+ const config = Object.assign({}, defaultConfig);
27
+ if (userConfig.resourceNames && userConfig.resourceNames.length > 0) {
28
+ config.resourceNames = userConfig.resourceNames;
29
+ config.validateResources = true;
30
+ }
31
+ if (userConfig.logLevel &&
32
+ userConfig.logLevel.length !== 0 &&
33
+ Object.keys(logging_1.logLevels).includes(userConfig.logLevel.toUpperCase())) {
34
+ config.logLevel = userConfig.logLevel.toUpperCase();
35
+ }
36
+ if (userConfig.staticFolder) {
37
+ config.staticFolder = userConfig.staticFolder.replace(/[^a-zA-Z0-9]/g, '');
38
+ }
39
+ if (userConfig.apiPrefix) {
40
+ config.apiPrefix =
41
+ '/' + userConfig.apiPrefix.replace(/[^a-zA-Z0-9]/g, '') + '/';
70
42
  }
71
-
72
- if (userConfig.requestBodyValidator.put && typeof userConfig.requestBodyValidator.put === 'function') {
73
- config.requestBodyValidator.put = userConfig.requestBodyValidator.put;
43
+ if (userConfig.connectionString && userConfig.connectionString.length > 0) {
44
+ config.connectionString = userConfig.connectionString;
74
45
  }
75
- }
76
-
77
- return config;
78
- }
46
+ if (userConfig.cacheControl && userConfig.cacheControl.length > 0) {
47
+ config.cacheControl = userConfig.cacheControl;
48
+ }
49
+ if (userConfig.delay &&
50
+ userConfig.delay.length !== 0 &&
51
+ typeof Number(userConfig.delay) === 'number' &&
52
+ Number(userConfig.delay) > 0 &&
53
+ Number(userConfig.delay) < 10000) {
54
+ config.delay = Number(userConfig.delay);
55
+ }
56
+ if (userConfig.requestBodyValidator) {
57
+ if (userConfig.requestBodyValidator.post &&
58
+ typeof userConfig.requestBodyValidator.post === 'function') {
59
+ config.requestBodyValidator.post = userConfig.requestBodyValidator.post;
60
+ }
61
+ if (userConfig.requestBodyValidator.put &&
62
+ typeof userConfig.requestBodyValidator.put === 'function') {
63
+ config.requestBodyValidator.put = userConfig.requestBodyValidator.put;
64
+ }
65
+ }
66
+ return config;
67
+ }
68
+ exports.initConfig = initConfig;
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;AAAA,wCAAsC;AAEtC,MAAM,aAAa,GAAG;IACpB,aAAa,EAAE,EAAE;IACjB,iBAAiB,EAAE,KAAK;IACxB,QAAQ,EAAE,mBA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,CAAC,EAAE;QACzE,MAAM,CAAC,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,CAAA;KACtD;IAED,IAAI,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QACjE,MAAM,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAA;KAC9C;IAED,IACE,UAAU,CAAC,KAAK;QAChB,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAC7B,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,QAAQ;QAC5C,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC;QAC5B,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,EAChC;QACA,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;KACxC;IAED,IAAI,UAAU,CAAC,oBAAoB,EAAE;QACnC,IACE,UAAU,CAAC,oBAAoB,CAAC,IAAI;YACpC,OAAO,UAAU,CAAC,oBAAoB,CAAC,IAAI,KAAK,UAAU,EAC1D;YACA,MAAM,CAAC,oBAAoB,CAAC,IAAI,GAAG,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAA;SACxE;QACD,IACE,UAAU,CAAC,oBAAoB,CAAC,GAAG;YACnC,OAAO,UAAU,CAAC,oBAAoB,CAAC,GAAG,KAAK,UAAU,EACzD;YACA,MAAM,CAAC,oBAAoB,CAAC,GAAG,GAAG,UAAU,CAAC,oBAAoB,CAAC,GAAG,CAAA;SACtE;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AA7DD,gCA6DC"}
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createDelayMiddleware = createDelayMiddleware;
7
-
8
- var pause = require('connect-pause');
9
-
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createDelayMiddleware = void 0;
7
+ const connect_pause_1 = __importDefault(require("connect-pause"));
10
8
  function createDelayMiddleware(delay) {
11
- return function (req, res, next) {
12
- console.log('Start delay...');
13
- pause(delay)(req, res, next);
14
- console.log('Delay finished!');
15
- };
16
- }
9
+ return function (req, res, next) {
10
+ console.log('Start delay...');
11
+ (0, connect_pause_1.default)(delay)(req, res, next);
12
+ console.log('Delay finished!');
13
+ };
14
+ }
15
+ exports.createDelayMiddleware = createDelayMiddleware;
16
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/delay/middleware.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAiC;AAEjC,SAAS,qBAAqB,CAAC,KAAK;IAClC,OAAO,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QAC7B,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;QAC7B,IAAA,uBAAK,EAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;QAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAChC,CAAC,CAAA;AACH,CAAC;AAEQ,sDAAqB"}
@@ -1,21 +1,13 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.new400BadRequestError = exports.new404NotFoundError = void 0;
4
+ const types_1 = require("./types");
5
+ function new404NotFoundError(message = 'Not Found') {
6
+ return new types_1.TembaError(message, 404);
7
+ }
6
8
  exports.new404NotFoundError = new404NotFoundError;
7
- exports.new400BadRequestError = new400BadRequestError;
8
-
9
- function new404NotFoundError() {
10
- var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Not Found';
11
- var error = new Error(message);
12
- error.status = 404;
13
- return error;
9
+ function new400BadRequestError(message = 'Bad Request') {
10
+ return new types_1.TembaError(message, 400);
14
11
  }
15
-
16
- function new400BadRequestError() {
17
- var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Bad Request';
18
- var error = new Error(message);
19
- error.status = 400;
20
- return error;
21
- }
12
+ exports.new400BadRequestError = new400BadRequestError;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAEpC,SAAS,mBAAmB,CAAC,OAAO,GAAG,WAAW;IAChD,OAAO,IAAI,kBAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACrC,CAAC;AAMQ,kDAAmB;AAJ5B,SAAS,qBAAqB,CAAC,OAAO,GAAG,aAAa;IACpD,OAAO,IAAI,kBAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACrC,CAAC;AAE6B,sDAAqB"}
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorHandler = void 0;
4
+ function errorHandler(err, _, res) {
5
+ console.log('errorHandler: ' + err.message);
6
+ if (!err.status)
7
+ err.status = 500;
8
+ return res.status(err.status).json({ message: err.message });
9
+ }
6
10
  exports.errorHandler = errorHandler;
7
-
8
- function errorHandler(err, _, res, next) {
9
- console.log('errorHandler: ' + err.message);
10
- if (!err.status) err.status = 500;
11
- return res.status(err.status).json({
12
- message: err.message
13
- });
14
- }
11
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/errors/middleware.ts"],"names":[],"mappings":";;;AAAA,SAAS,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG;IAC/B,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;IAE3C,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAA;IAEjC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;AAC9D,CAAC;AAEQ,oCAAY"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TembaError = void 0;
4
+ class TembaError extends Error {
5
+ constructor(msg, status) {
6
+ super(msg);
7
+ this.status = status;
8
+ Object.setPrototypeOf(this, TembaError.prototype);
9
+ this.status = status;
10
+ }
11
+ }
12
+ exports.TembaError = TembaError;
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/errors/types.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,GAAW,EAAS,MAAc;QAC5C,KAAK,CAAC,GAAG,CAAC,CAAA;QADoB,WAAM,GAAN,MAAM,CAAQ;QAE5C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;QAEjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAPD,gCAOC"}
@@ -1,38 +1,39 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createLogger = createLogger;
7
- exports.logLevels = void 0;
8
- var DEBUG = 'DEBUG';
9
- var INFO = 'INFO'; //TODO Add 'NONE'
10
-
11
- var logLevels = {
12
- DEBUG: DEBUG,
13
- INFO: INFO
14
- };
15
- exports.logLevels = logLevels;
16
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLogger = exports.logLevels = void 0;
4
+ const DEBUG = 'DEBUG';
5
+ const INFO = 'INFO';
6
+ //TODO Add 'NONE'
7
+ exports.logLevels = { DEBUG, INFO };
17
8
  function createLogger(logLevel) {
18
- return {
19
- debug: function debug(message) {
20
- try {
21
- if (logLevel === DEBUG) console.log(new Date(), 'DEBUG -', message);
22
- } catch (_unused) {//swallow exceptions during logging
23
- }
24
- },
25
- info: function info(message) {
26
- try {
27
- if (logLevel === DEBUG || logLevel === INFO) console.info(new Date(), 'INFO -', message);
28
- } catch (_unused2) {//swallow exceptions during logging
29
- }
30
- },
31
- error: function error(message) {
32
- try {
33
- console.error(new Date(), 'ERROR -', message);
34
- } catch (_unused3) {//swallow exceptions during logging
35
- }
36
- }
37
- };
38
- }
9
+ return {
10
+ debug: function (message) {
11
+ try {
12
+ if (logLevel === DEBUG)
13
+ console.log(new Date(), 'DEBUG -', message);
14
+ }
15
+ catch (_a) {
16
+ //swallow exceptions during logging
17
+ }
18
+ },
19
+ info: function (message) {
20
+ try {
21
+ if (logLevel === DEBUG || logLevel === INFO)
22
+ console.info(new Date(), 'INFO -', message);
23
+ }
24
+ catch (_a) {
25
+ //swallow exceptions during logging
26
+ }
27
+ },
28
+ error: function (message) {
29
+ try {
30
+ console.error(new Date(), 'ERROR -', message);
31
+ }
32
+ catch (_a) {
33
+ //swallow exceptions during logging
34
+ }
35
+ },
36
+ };
37
+ }
38
+ exports.createLogger = createLogger;
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logging/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAA;AACrB,MAAM,IAAI,GAAG,MAAM,CAAA;AACnB,iBAAiB;AAEJ,QAAA,SAAS,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AAExC,SAAgB,YAAY,CAAC,QAAQ;IACnC,OAAO;QACL,KAAK,EAAE,UAAU,OAAO;YACtB,IAAI;gBACF,IAAI,QAAQ,KAAK,KAAK;oBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;aACpE;YAAC,WAAM;gBACN,mCAAmC;aACpC;QACH,CAAC;QAED,IAAI,EAAE,UAAU,OAAO;YACrB,IAAI;gBACF,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,IAAI;oBACzC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;aAC/C;YAAC,WAAM;gBACN,mCAAmC;aACpC;QACH,CAAC;QAED,KAAK,EAAE,UAAU,OAAO;YACtB,IAAI;gBACF,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;aAC9C;YAAC,WAAM;gBACN,mCAAmC;aACpC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AA3BD,oCA2BC"}
@@ -1,96 +1,65 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
-
18
- var data = {};
19
-
20
- function connectToDatabase() {// do nothing
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const data = {};
4
+ function connectToDatabase() {
5
+ // do nothing
21
6
  }
22
-
23
7
  function getAll(resourceName) {
24
- createResourceArrayIfNecessary(resourceName);
25
- return new Promise(function (resolve) {
26
- resolve(data[resourceName]);
27
- });
8
+ createResourceArrayIfNecessary(resourceName);
9
+ return new Promise((resolve) => {
10
+ resolve(data[resourceName]);
11
+ });
28
12
  }
29
-
30
13
  function getById(resourceName, id) {
31
- createResourceArrayIfNecessary(resourceName);
32
- return new Promise(function (resolve) {
33
- resolve(data[resourceName].find(function (item) {
34
- return item.id === id;
35
- }));
36
- });
14
+ createResourceArrayIfNecessary(resourceName);
15
+ return new Promise((resolve) => {
16
+ resolve(data[resourceName].find((item) => item.id === id));
17
+ });
37
18
  }
38
-
39
19
  function create(resourceName, item) {
40
- createResourceArrayIfNecessary(resourceName);
41
-
42
- var newItem = _objectSpread(_objectSpread({}, item), {}, {
43
- id: String(new Date().getTime())
44
- });
45
-
46
- data[resourceName] = [].concat((0, _toConsumableArray2["default"])(data[resourceName]), [newItem]);
47
- return new Promise(function (resolve) {
48
- resolve(newItem);
49
- });
20
+ createResourceArrayIfNecessary(resourceName);
21
+ const newItem = Object.assign(Object.assign({}, item), { id: String(new Date().getTime()) });
22
+ data[resourceName] = [...data[resourceName], newItem];
23
+ return new Promise((resolve) => {
24
+ resolve(newItem);
25
+ });
50
26
  }
51
-
52
27
  function update(resourceName, item) {
53
- createResourceArrayIfNecessary(resourceName);
54
-
55
- var updatedItem = _objectSpread({}, item);
56
-
57
- data[resourceName] = [].concat((0, _toConsumableArray2["default"])(data[resourceName].filter(function (r) {
58
- return r.id !== item.id;
59
- })), [updatedItem]);
60
- return new Promise(function (resolve) {
61
- resolve(updatedItem);
62
- });
28
+ createResourceArrayIfNecessary(resourceName);
29
+ const updatedItem = Object.assign({}, item);
30
+ data[resourceName] = [
31
+ ...data[resourceName].filter((r) => r.id !== item.id),
32
+ updatedItem,
33
+ ];
34
+ return new Promise((resolve) => {
35
+ resolve(updatedItem);
36
+ });
63
37
  }
64
-
65
38
  function deleteById(resourceName, id) {
66
- createResourceArrayIfNecessary(resourceName);
67
- data[resourceName] = data[resourceName].filter(function (item) {
68
- return item.id !== id;
69
- });
70
- return new Promise(function (resolve) {
71
- resolve();
72
- });
39
+ createResourceArrayIfNecessary(resourceName);
40
+ data[resourceName] = data[resourceName].filter((item) => item.id !== id);
41
+ return new Promise((resolve) => {
42
+ resolve();
43
+ });
73
44
  }
74
-
75
45
  function deleteAll(resourceName) {
76
- createResourceArrayIfNecessary(resourceName);
77
- data[resourceName] = [];
78
- return new Promise(function (resolve) {
79
- resolve([]);
80
- });
46
+ createResourceArrayIfNecessary(resourceName);
47
+ data[resourceName] = [];
48
+ return new Promise((resolve) => {
49
+ resolve([]);
50
+ });
81
51
  }
82
-
83
52
  function createResourceArrayIfNecessary(resourceName) {
84
- if (!data.hasOwnProperty(resourceName)) data[resourceName] = [];
53
+ if (!data.hasOwnProperty(resourceName))
54
+ data[resourceName] = [];
85
55
  }
86
-
87
- var _default = {
88
- connectToDatabase: connectToDatabase,
89
- getAll: getAll,
90
- getById: getById,
91
- create: create,
92
- update: update,
93
- deleteById: deleteById,
94
- deleteAll: deleteAll
56
+ exports.default = {
57
+ connectToDatabase,
58
+ getAll,
59
+ getById,
60
+ create,
61
+ update,
62
+ deleteById,
63
+ deleteAll,
95
64
  };
96
- exports["default"] = _default;
65
+ //# sourceMappingURL=in-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.js","sourceRoot":"","sources":["../../src/queries/in-memory.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,GAAG,EAAE,CAAA;AAEf,SAAS,iBAAiB;IACxB,aAAa;AACf,CAAC;AAED,SAAS,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AC;QACrD,WAAW;KACZ,CAAA;IACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,OAAO,CAAC,WAAW,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,YAAY,EAAE,EAAE;IAClC,8BAA8B,CAAC,YAAY,CAAC,CAAA;IAE5C,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IACxE,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,YAAY;IAC7B,8BAA8B,CAAC,YAAY,CAAC,CAAA;IAE5C,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,OAAO,CAAC,EAAE,CAAC,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,8BAA8B,CAAC,YAAY;IAClD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC;QAAE,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;AACjE,CAAC;AAED,kBAAe;IACb,iBAAiB;IACjB,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,UAAU;IACV,SAAS;CACV,CAAA"}
@@ -1,21 +1,17 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createQueries = createQueries;
9
-
10
- var _inMemory = _interopRequireDefault(require("./in-memory"));
11
-
12
- var _mongo = _interopRequireDefault(require("./mongo"));
13
-
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createQueries = void 0;
7
+ const in_memory_1 = __importDefault(require("./in-memory"));
8
+ const mongo_1 = __importDefault(require("./mongo"));
14
9
  function createQueries(connectionString) {
15
- if (!connectionString) {
16
- return _inMemory["default"];
17
- }
18
-
19
- var mongoQueries = (0, _mongo["default"])(connectionString);
20
- return mongoQueries;
21
- }
10
+ if (!connectionString) {
11
+ return in_memory_1.default;
12
+ }
13
+ const mongoQueries = (0, mongo_1.default)(connectionString);
14
+ return mongoQueries;
15
+ }
16
+ exports.createQueries = createQueries;
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAyC;AACzC,oDAAwC;AAExC,SAAS,aAAa,CAAC,gBAAgB;IACrC,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,mBAAe,CAAA;KACvB;IAED,MAAM,YAAY,GAAG,IAAA,eAAkB,EAAC,gBAAgB,CAAC,CAAA;IACzD,OAAO,YAAY,CAAA;AACrB,CAAC;AAEQ,sCAAa"}