brackets-memory-db 1.0.0 → 1.0.3
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 +13 -13
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryDatabase = void 0;
|
|
4
|
+
const rfdc = require("rfdc");
|
|
5
|
+
const clone = rfdc();
|
|
4
6
|
class InMemoryDatabase {
|
|
5
7
|
data = {
|
|
6
8
|
participant: [],
|
|
@@ -51,7 +53,6 @@ class InMemoryDatabase {
|
|
|
51
53
|
id = this.data[table].length;
|
|
52
54
|
if (!Array.isArray(values)) {
|
|
53
55
|
try {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
55
56
|
// @ts-ignore
|
|
56
57
|
this.data[table].push({ id, ...values });
|
|
57
58
|
}
|
|
@@ -66,7 +67,6 @@ class InMemoryDatabase {
|
|
|
66
67
|
}
|
|
67
68
|
try {
|
|
68
69
|
values.map((object) => {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
70
|
// @ts-ignore
|
|
71
71
|
this.data[table].push({ id: id++, ...object });
|
|
72
72
|
});
|
|
@@ -88,22 +88,19 @@ class InMemoryDatabase {
|
|
|
88
88
|
try {
|
|
89
89
|
if (arg === undefined) {
|
|
90
90
|
return new Promise((resolve) => {
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
92
91
|
// @ts-ignore
|
|
93
|
-
resolve(this.data[table]);
|
|
92
|
+
resolve(this.data[table].map(clone));
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
95
|
if (typeof arg === 'number') {
|
|
97
96
|
return new Promise((resolve) => {
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
99
97
|
// @ts-ignore
|
|
100
|
-
resolve(this.data[table][arg]);
|
|
98
|
+
resolve(clone(this.data[table][arg]));
|
|
101
99
|
});
|
|
102
100
|
}
|
|
103
101
|
return new Promise((resolve) => {
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
105
102
|
// @ts-ignore
|
|
106
|
-
resolve(this.data[table].filter(this.makeFilter(arg))
|
|
103
|
+
resolve(this.data[table].filter(this.makeFilter(arg))).map(clone);
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
106
|
catch (error) {
|
|
@@ -122,7 +119,6 @@ class InMemoryDatabase {
|
|
|
122
119
|
update(table, arg, value) {
|
|
123
120
|
if (typeof arg === 'number') {
|
|
124
121
|
try {
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
126
122
|
// @ts-ignore
|
|
127
123
|
this.data[table][arg] = value;
|
|
128
124
|
return new Promise((resolve) => {
|
|
@@ -135,7 +131,6 @@ class InMemoryDatabase {
|
|
|
135
131
|
});
|
|
136
132
|
}
|
|
137
133
|
}
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
139
134
|
// @ts-ignore
|
|
140
135
|
const values = this.data[table].filter(this.makeFilter(arg));
|
|
141
136
|
if (!values) {
|
|
@@ -146,9 +141,15 @@ class InMemoryDatabase {
|
|
|
146
141
|
values.forEach((v) => {
|
|
147
142
|
const existing = this.data[table][v.id];
|
|
148
143
|
for (const key in value) {
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
150
144
|
// @ts-ignore
|
|
151
|
-
existing[key]
|
|
145
|
+
if (existing[key] && typeof existing[key] === 'object' && typeof value[key] === 'object') {
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
Object.assign(existing[key], value[key]); // For opponent objects, this does a deep merge of level 2.
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
existing[key] = value[key]; // Otherwise, do a simple value assignment.
|
|
152
|
+
}
|
|
152
153
|
}
|
|
153
154
|
this.data[table][v.id] = existing;
|
|
154
155
|
});
|
|
@@ -177,7 +178,6 @@ class InMemoryDatabase {
|
|
|
177
178
|
}
|
|
178
179
|
const predicate = this.makeFilter(filter);
|
|
179
180
|
const negativeFilter = (value) => !predicate(value);
|
|
180
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
181
181
|
// @ts-ignore
|
|
182
182
|
this.data[table] = values.filter(negativeFilter);
|
|
183
183
|
return new Promise((resolve) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brackets-memory-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "An in-memory database for brackets-manager.js",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,5 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"brackets-manager": "^1.3.9"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"rfdc": "^1.3.0"
|
|
39
42
|
}
|
|
40
43
|
}
|