brackets-memory-db 1.0.1 → 1.0.4

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 (2) hide show
  1. package/dist/index.js +13 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -49,11 +49,11 @@ class InMemoryDatabase {
49
49
  * @param values What to insert.
50
50
  */
51
51
  insert(table, values) {
52
- let id;
53
- id = this.data[table].length;
52
+ let id = this.data[table].length > 0
53
+ ? (Math.max(...this.data[table].map(d => d.id)) + 1)
54
+ : 0;
54
55
  if (!Array.isArray(values)) {
55
56
  try {
56
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
57
  // @ts-ignore
58
58
  this.data[table].push({ id, ...values });
59
59
  }
@@ -68,7 +68,6 @@ class InMemoryDatabase {
68
68
  }
69
69
  try {
70
70
  values.map((object) => {
71
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72
71
  // @ts-ignore
73
72
  this.data[table].push({ id: id++, ...object });
74
73
  });
@@ -90,22 +89,19 @@ class InMemoryDatabase {
90
89
  try {
91
90
  if (arg === undefined) {
92
91
  return new Promise((resolve) => {
93
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
94
92
  // @ts-ignore
95
93
  resolve(this.data[table].map(clone));
96
94
  });
97
95
  }
98
96
  if (typeof arg === 'number') {
99
97
  return new Promise((resolve) => {
100
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
101
98
  // @ts-ignore
102
- resolve(clone(this.data[table][arg]));
99
+ resolve(clone(this.data[table].find(d => d.id === arg)));
103
100
  });
104
101
  }
105
102
  return new Promise((resolve) => {
106
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
107
103
  // @ts-ignore
108
- resolve(this.data[table].filter(this.makeFilter(arg))).map(clone);
104
+ resolve(this.data[table].filter(this.makeFilter(arg)).map(clone));
109
105
  });
110
106
  }
111
107
  catch (error) {
@@ -124,7 +120,6 @@ class InMemoryDatabase {
124
120
  update(table, arg, value) {
125
121
  if (typeof arg === 'number') {
126
122
  try {
127
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
128
123
  // @ts-ignore
129
124
  this.data[table][arg] = value;
130
125
  return new Promise((resolve) => {
@@ -137,7 +132,6 @@ class InMemoryDatabase {
137
132
  });
138
133
  }
139
134
  }
140
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
141
135
  // @ts-ignore
142
136
  const values = this.data[table].filter(this.makeFilter(arg));
143
137
  if (!values) {
@@ -148,9 +142,15 @@ class InMemoryDatabase {
148
142
  values.forEach((v) => {
149
143
  const existing = this.data[table][v.id];
150
144
  for (const key in value) {
151
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
152
145
  // @ts-ignore
153
- Object.assign(existing[key], value[key]);
146
+ if (existing[key] && typeof existing[key] === 'object' && typeof value[key] === 'object') {
147
+ // @ts-ignore
148
+ Object.assign(existing[key], value[key]); // For opponent objects, this does a deep merge of level 2.
149
+ }
150
+ else {
151
+ // @ts-ignore
152
+ existing[key] = value[key]; // Otherwise, do a simple value assignment.
153
+ }
154
154
  }
155
155
  this.data[table][v.id] = existing;
156
156
  });
@@ -179,7 +179,6 @@ class InMemoryDatabase {
179
179
  }
180
180
  const predicate = this.makeFilter(filter);
181
181
  const negativeFilter = (value) => !predicate(value);
182
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
183
182
  // @ts-ignore
184
183
  this.data[table] = values.filter(negativeFilter);
185
184
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brackets-memory-db",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "An in-memory database for brackets-manager.js",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",