@belopash/typeorm-store 0.0.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.
- package/.github/workflows/bump.yml +36 -0
- package/.github/workflows/publish.yml +49 -0
- package/CHANGELOG.md +18 -0
- package/lib/cacheMap.d.ts +23 -0
- package/lib/cacheMap.d.ts.map +1 -0
- package/lib/cacheMap.js +115 -0
- package/lib/cacheMap.js.map +1 -0
- package/lib/database.d.ts +10 -0
- package/lib/database.d.ts.map +1 -0
- package/lib/database.js +35 -0
- package/lib/database.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/store.d.ts +60 -0
- package/lib/store.d.ts.map +1 -0
- package/lib/store.js +383 -0
- package/lib/store.js.map +1 -0
- package/lib/updateMap.d.ts +19 -0
- package/lib/updateMap.d.ts.map +1 -0
- package/lib/updateMap.js +67 -0
- package/lib/updateMap.js.map +1 -0
- package/lib/utils.d.ts +3 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +58 -0
- package/lib/utils.js.map +1 -0
- package/package.json +24 -0
- package/src/cacheMap.ts +135 -0
- package/src/database.ts +40 -0
- package/src/index.ts +2 -0
- package/src/store.ts +474 -0
- package/src/updateMap.ts +74 -0
- package/src/utils.ts +49 -0
- package/tsconfig.json +21 -0
package/lib/store.js
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DeferredEntity = exports.StoreWithCache = void 0;
|
|
16
|
+
const typeorm_store_1 = require("@subsquid/typeorm-store");
|
|
17
|
+
const util_internal_1 = require("@subsquid/util-internal");
|
|
18
|
+
const assert_1 = __importDefault(require("assert"));
|
|
19
|
+
const graph_data_structure_1 = require("graph-data-structure");
|
|
20
|
+
const typeorm_1 = require("typeorm");
|
|
21
|
+
const utils_1 = require("./utils");
|
|
22
|
+
const cacheMap_1 = require("./cacheMap");
|
|
23
|
+
const updateMap_1 = require("./updateMap");
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
class StoreWithCache extends typeorm_store_1.Store {
|
|
26
|
+
constructor(em, changes) {
|
|
27
|
+
super(em, changes);
|
|
28
|
+
this.em = em;
|
|
29
|
+
this.deferMap = new Map();
|
|
30
|
+
this.updates = new Map();
|
|
31
|
+
this.knownSelfRelations = {};
|
|
32
|
+
this.cache = new cacheMap_1.CacheMap(em);
|
|
33
|
+
}
|
|
34
|
+
async insert(e) {
|
|
35
|
+
const em = this.em();
|
|
36
|
+
const entities = Array.isArray(e) ? e : [e];
|
|
37
|
+
if (entities.length == 0)
|
|
38
|
+
return;
|
|
39
|
+
const entityClass = entities[0].constructor;
|
|
40
|
+
const metadata = em.connection.getMetadata(entityClass);
|
|
41
|
+
const relationMask = {};
|
|
42
|
+
for (const relation of metadata.relations) {
|
|
43
|
+
if (relation.isOwning) {
|
|
44
|
+
relationMask[relation.propertyName] = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const updateMap = this.getUpdateMap(entityClass);
|
|
48
|
+
for (const entity of entities) {
|
|
49
|
+
updateMap.insert(entity.id);
|
|
50
|
+
this.cache.add(entity, relationMask);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async upsert(e) {
|
|
54
|
+
const em = this.em();
|
|
55
|
+
let entities = Array.isArray(e) ? e : [e];
|
|
56
|
+
if (entities.length == 0)
|
|
57
|
+
return;
|
|
58
|
+
const entityClass = entities[0].constructor;
|
|
59
|
+
const metadata = em.connection.getMetadata(entityClass);
|
|
60
|
+
const updateMap = this.getUpdateMap(entityClass);
|
|
61
|
+
for (const entity of entities) {
|
|
62
|
+
const relationMask = {};
|
|
63
|
+
for (const relation of metadata.relations) {
|
|
64
|
+
const relatedEntity = relation.getEntityValue(entity);
|
|
65
|
+
if (relation.isOwning && relatedEntity !== undefined) {
|
|
66
|
+
relationMask[relation.propertyName] = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
updateMap.upsert(entity.id);
|
|
70
|
+
this.cache.add(entity, relationMask);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async save(e) {
|
|
74
|
+
return await this.upsert(e);
|
|
75
|
+
}
|
|
76
|
+
async remove(e, id) {
|
|
77
|
+
const em = this.em();
|
|
78
|
+
if (id == null) {
|
|
79
|
+
const entities = Array.isArray(e) ? e : [e];
|
|
80
|
+
if (entities.length == 0)
|
|
81
|
+
return;
|
|
82
|
+
const entityClass = entities[0].constructor;
|
|
83
|
+
const updateMap = this.getUpdateMap(entityClass);
|
|
84
|
+
for (const entity of entities) {
|
|
85
|
+
updateMap.remove(entity.id);
|
|
86
|
+
this.cache.delete(entityClass, entity.id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const ids = Array.isArray(id) ? id : [id];
|
|
91
|
+
if (ids.length == 0)
|
|
92
|
+
return;
|
|
93
|
+
const entityClass = e;
|
|
94
|
+
const updateMap = this.getUpdateMap(entityClass);
|
|
95
|
+
for (const i of ids) {
|
|
96
|
+
updateMap.remove(i);
|
|
97
|
+
this.cache.delete(entityClass, i);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async count(entityClass, options) {
|
|
102
|
+
await this.persist();
|
|
103
|
+
return await super.count(entityClass, options);
|
|
104
|
+
}
|
|
105
|
+
async countBy(entityClass, where) {
|
|
106
|
+
await this.persist();
|
|
107
|
+
return await super.countBy(entityClass, where);
|
|
108
|
+
}
|
|
109
|
+
async find(entityClass, options) {
|
|
110
|
+
await this.persist();
|
|
111
|
+
const res = await super.find(entityClass, options);
|
|
112
|
+
if (res != null)
|
|
113
|
+
this.cache.add(res, options.relations);
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
116
|
+
async findBy(entityClass, where) {
|
|
117
|
+
await this.persist();
|
|
118
|
+
const res = await super.findBy(entityClass, where);
|
|
119
|
+
if (res != null)
|
|
120
|
+
this.cache.add(res);
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
async findOne(entityClass, options) {
|
|
124
|
+
await this.persist();
|
|
125
|
+
const res = await super.findOne(entityClass, options);
|
|
126
|
+
if (res != null)
|
|
127
|
+
this.cache.add(res, options.relations);
|
|
128
|
+
return res;
|
|
129
|
+
}
|
|
130
|
+
async findOneOrFail(entityClass, options) {
|
|
131
|
+
await this.persist();
|
|
132
|
+
const res = await super.findOneOrFail(entityClass, options);
|
|
133
|
+
if (res != null)
|
|
134
|
+
this.cache.add(res, options.relations);
|
|
135
|
+
return res;
|
|
136
|
+
}
|
|
137
|
+
async findOneBy(entityClass, where) {
|
|
138
|
+
await this.persist();
|
|
139
|
+
const res = await super.findOneBy(entityClass, where);
|
|
140
|
+
if (res != null)
|
|
141
|
+
this.cache.add(res);
|
|
142
|
+
return res;
|
|
143
|
+
}
|
|
144
|
+
async findOneByOrFail(entityClass, where) {
|
|
145
|
+
await this.persist();
|
|
146
|
+
const res = await super.findOneByOrFail(entityClass, where);
|
|
147
|
+
if (res != null)
|
|
148
|
+
this.cache.add(res);
|
|
149
|
+
return res;
|
|
150
|
+
}
|
|
151
|
+
async get(entityClass, id, relations) {
|
|
152
|
+
await this.load();
|
|
153
|
+
const entity = this.getCached(entityClass, id, relations);
|
|
154
|
+
if (entity !== undefined) {
|
|
155
|
+
return entity == null ? undefined : entity;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return await this.findOne(entityClass, { where: { id }, relations });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async getOrFail(entityClass, id, relations) {
|
|
162
|
+
let e = await this.get(entityClass, id, relations);
|
|
163
|
+
if (e == null) {
|
|
164
|
+
const metadata = this.em().connection.getMetadata(entityClass);
|
|
165
|
+
throw new Error(`Missing entity ${metadata.name} with id "${id}"`);
|
|
166
|
+
}
|
|
167
|
+
return e;
|
|
168
|
+
}
|
|
169
|
+
getCached(entityClass, id, mask = {}) {
|
|
170
|
+
const em = this.em();
|
|
171
|
+
const metadata = em.connection.getMetadata(entityClass);
|
|
172
|
+
const cachedEntity = this.cache.get(entityClass, id);
|
|
173
|
+
if (cachedEntity == null) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
else if (cachedEntity.value == null) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const clonedEntity = em.create(entityClass);
|
|
181
|
+
for (const column of metadata.nonVirtualColumns) {
|
|
182
|
+
const objectColumnValue = column.getEntityValue(cachedEntity.value);
|
|
183
|
+
if (objectColumnValue !== undefined) {
|
|
184
|
+
column.setEntityValue(clonedEntity, (0, utils_1.copy)(objectColumnValue));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const relation of metadata.relations) {
|
|
188
|
+
let relatedMask = mask[relation.propertyName];
|
|
189
|
+
if (!relatedMask)
|
|
190
|
+
continue;
|
|
191
|
+
const relatedEntity = relation.getEntityValue(cachedEntity.value);
|
|
192
|
+
if (relatedEntity === undefined) {
|
|
193
|
+
return undefined; // relation is missing, but required
|
|
194
|
+
}
|
|
195
|
+
else if (relatedEntity == null) {
|
|
196
|
+
relation.setEntityValue(clonedEntity, null);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
const cachedRelatedEntity = this.getCached(relation.inverseEntityMetadata.target, relatedEntity.id, typeof relatedMask === 'boolean' ? {} : relatedMask);
|
|
200
|
+
(0, assert_1.default)(cachedRelatedEntity != null);
|
|
201
|
+
relation.setEntityValue(clonedEntity, cachedRelatedEntity);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return clonedEntity;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
defer(entityClass, id, relations) {
|
|
208
|
+
const _deferredList = this.getDeferData(entityClass);
|
|
209
|
+
_deferredList.ids.add(id);
|
|
210
|
+
if (relations != null) {
|
|
211
|
+
_deferredList.relations = mergeRelataions(_deferredList.relations, relations);
|
|
212
|
+
}
|
|
213
|
+
return new DeferredEntity({
|
|
214
|
+
get: async () => this.get(entityClass, id, relations),
|
|
215
|
+
getOrFail: async () => this.getOrFail(entityClass, id, relations),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async persist() {
|
|
219
|
+
const em = this.em();
|
|
220
|
+
const entityOrder = this.getTopologicalOrder();
|
|
221
|
+
const entityOrderReversed = [...entityOrder].reverse();
|
|
222
|
+
const changeSets = new Map();
|
|
223
|
+
for (const name of entityOrder) {
|
|
224
|
+
const updateMap = this.getUpdateMap(name);
|
|
225
|
+
const inserts = [];
|
|
226
|
+
const upserts = [];
|
|
227
|
+
const delayedUpserts = [];
|
|
228
|
+
const removes = [];
|
|
229
|
+
for (const { id, type } of updateMap) {
|
|
230
|
+
const cached = this.cache.get(name, id);
|
|
231
|
+
switch (type) {
|
|
232
|
+
case updateMap_1.UpdateType.Insert: {
|
|
233
|
+
(0, assert_1.default)(cached != null && cached.value != null);
|
|
234
|
+
inserts.push(cached.value);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case updateMap_1.UpdateType.Upsert: {
|
|
238
|
+
(0, assert_1.default)(cached != null && cached.value != null);
|
|
239
|
+
let isDelayed = false;
|
|
240
|
+
for (const relation of this.getSelfRelations(name)) {
|
|
241
|
+
const relatedEntity = relation.getEntityValue(cached.value);
|
|
242
|
+
const relatedUpdateType = updateMap.get(relatedEntity.id);
|
|
243
|
+
if (relatedUpdateType === updateMap_1.UpdateType.Insert) {
|
|
244
|
+
isDelayed = true;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (isDelayed) {
|
|
249
|
+
delayedUpserts.push(cached.value);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
upserts.push(cached.value);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
case updateMap_1.UpdateType.Remove: {
|
|
257
|
+
const e = em.create(name, { id });
|
|
258
|
+
removes.push(e);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
changeSets.set(name, {
|
|
264
|
+
inserts,
|
|
265
|
+
upserts,
|
|
266
|
+
delayedUpserts,
|
|
267
|
+
removes,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
for (const name of entityOrder) {
|
|
271
|
+
const changeSet = changeSets.get(name);
|
|
272
|
+
if (changeSet == null)
|
|
273
|
+
continue;
|
|
274
|
+
await super.upsert(changeSet.upserts);
|
|
275
|
+
await super.insert(changeSet.inserts);
|
|
276
|
+
await super.upsert(changeSet.delayedUpserts);
|
|
277
|
+
}
|
|
278
|
+
for (const name of entityOrderReversed) {
|
|
279
|
+
const changeSet = changeSets.get(name);
|
|
280
|
+
if (changeSet == null)
|
|
281
|
+
continue;
|
|
282
|
+
await super.remove(changeSet.removes);
|
|
283
|
+
}
|
|
284
|
+
this.updates.clear();
|
|
285
|
+
}
|
|
286
|
+
async flush() {
|
|
287
|
+
await this.persist();
|
|
288
|
+
this.cache.clear();
|
|
289
|
+
}
|
|
290
|
+
async load() {
|
|
291
|
+
const em = this.em();
|
|
292
|
+
for (const [name, deferData] of this.deferMap) {
|
|
293
|
+
const metadata = em.connection.getMetadata(name);
|
|
294
|
+
for (const id of deferData.ids) {
|
|
295
|
+
this.cache.ensure(metadata.target, id);
|
|
296
|
+
}
|
|
297
|
+
for (let batch of (0, utils_1.splitIntoBatches)([...deferData.ids], 30000)) {
|
|
298
|
+
if (batch.length == 0)
|
|
299
|
+
continue;
|
|
300
|
+
await this.find(metadata.target, { where: { id: (0, typeorm_1.In)(batch) }, relations: deferData.relations });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
this.deferMap.clear();
|
|
304
|
+
}
|
|
305
|
+
getSelfRelations(entityClass) {
|
|
306
|
+
const em = this.em();
|
|
307
|
+
const metadata = em.connection.getMetadata(entityClass);
|
|
308
|
+
if (this.knownSelfRelations[metadata.name] == null) {
|
|
309
|
+
this.knownSelfRelations[metadata.name] = metadata.relations.filter((r) => r.inverseEntityMetadata.name === metadata.name);
|
|
310
|
+
}
|
|
311
|
+
return this.knownSelfRelations[metadata.name];
|
|
312
|
+
}
|
|
313
|
+
getTopologicalOrder() {
|
|
314
|
+
const em = this.em();
|
|
315
|
+
const graph = (0, graph_data_structure_1.Graph)();
|
|
316
|
+
for (const metadata of em.connection.entityMetadatas) {
|
|
317
|
+
graph.addNode(metadata.name);
|
|
318
|
+
for (const foreignKey of metadata.foreignKeys) {
|
|
319
|
+
if (foreignKey.referencedEntityMetadata === metadata)
|
|
320
|
+
continue; // don't add self-relations
|
|
321
|
+
graph.addEdge(metadata.name, foreignKey.referencedEntityMetadata.name);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return graph.topologicalSort().reverse();
|
|
325
|
+
}
|
|
326
|
+
getDeferData(entityClass) {
|
|
327
|
+
const em = this.em();
|
|
328
|
+
const metadata = em.connection.getMetadata(entityClass);
|
|
329
|
+
let list = this.deferMap.get(metadata.name);
|
|
330
|
+
if (list == null) {
|
|
331
|
+
list = { ids: new Set(), relations: {} };
|
|
332
|
+
this.deferMap.set(metadata.name, list);
|
|
333
|
+
}
|
|
334
|
+
return list;
|
|
335
|
+
}
|
|
336
|
+
getUpdateMap(entityClass) {
|
|
337
|
+
const em = this.em();
|
|
338
|
+
const metadata = em.connection.getMetadata(entityClass);
|
|
339
|
+
let list = this.updates.get(metadata.name);
|
|
340
|
+
if (list == null) {
|
|
341
|
+
list = new updateMap_1.UpdateMap();
|
|
342
|
+
this.updates.set(metadata.name, list);
|
|
343
|
+
}
|
|
344
|
+
return list;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
__decorate([
|
|
348
|
+
util_internal_1.def,
|
|
349
|
+
__metadata("design:type", Function),
|
|
350
|
+
__metadata("design:paramtypes", []),
|
|
351
|
+
__metadata("design:returntype", void 0)
|
|
352
|
+
], StoreWithCache.prototype, "getTopologicalOrder", null);
|
|
353
|
+
exports.StoreWithCache = StoreWithCache;
|
|
354
|
+
function mergeRelataions(a, b) {
|
|
355
|
+
const mergedObject = {};
|
|
356
|
+
for (const key in a) {
|
|
357
|
+
mergedObject[key] = a[key];
|
|
358
|
+
}
|
|
359
|
+
for (const key in b) {
|
|
360
|
+
const bValue = b[key];
|
|
361
|
+
const value = mergedObject[key];
|
|
362
|
+
if (typeof bValue === 'object') {
|
|
363
|
+
mergedObject[key] = (typeof value === 'object' ? mergeRelataions(value, bValue) : bValue);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
mergedObject[key] = value || bValue;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return mergedObject;
|
|
370
|
+
}
|
|
371
|
+
class DeferredEntity {
|
|
372
|
+
constructor(opts) {
|
|
373
|
+
this.opts = opts;
|
|
374
|
+
}
|
|
375
|
+
async get() {
|
|
376
|
+
return await this.opts.get();
|
|
377
|
+
}
|
|
378
|
+
async getOrFail() {
|
|
379
|
+
return await this.opts.getOrFail();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
exports.DeferredEntity = DeferredEntity;
|
|
383
|
+
//# sourceMappingURL=store.js.map
|
package/lib/store.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAsH;AAEtH,2DAA2C;AAC3C,oDAA2B;AAC3B,+DAA0C;AAC1C,qCAA+F;AAC/F,mCAA8C;AAC9C,yCAAmC;AACnC,2CAAiD;AAajD,aAAa;AACb,MAAa,cAAe,SAAQ,qBAAK;IAKrC,YAAoB,EAAuB,EAAE,OAAuB;QAChE,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QADF,OAAE,GAAF,EAAE,CAAqB;QAJnC,aAAQ,GAAa,IAAI,GAAG,EAAE,CAAA;QAC9B,YAAO,GAA2B,IAAI,GAAG,EAAE,CAAA;QAwW3C,uBAAkB,GAAuC,EAAE,CAAA;QAnW/D,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAQ,CAAC,EAAE,CAAC,CAAA;IACjC,CAAC;IAID,KAAK,CAAC,MAAM,CAAoB,CAAU;QACtC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;QAEpB,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3C,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC;YAAE,OAAM;QAEhC,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;QAC3C,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;QAEvD,MAAM,YAAY,GAA8B,EAAE,CAAA;QAClD,KAAK,MAAM,QAAQ,IAAI,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dateType;
|
|
9
|
+
}
|
|
10
|
+
export declare class UpdateMap {
|
|
11
|
+
private map;
|
|
12
|
+
get(id: string): UpdateType | undefined;
|
|
13
|
+
insert(id: string): void;
|
|
14
|
+
upsert(id: string): void;
|
|
15
|
+
remove(id: string): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
[Symbol.iterator](): IterableIterator<Update>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=updateMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateMap.d.ts","sourceRoot":"","sources":["../src/updateMap.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IAClB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,MAAM,IAAA;CACT;AAED,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,UAAU,CAAA;CACnB;AAED,qBAAa,SAAS;IAClB,OAAO,CAAC,GAAG,CAAqC;IAEhD,GAAG,CAAC,EAAE,EAAE,MAAM;IAId,MAAM,CAAC,EAAE,EAAE,MAAM;IAgBjB,MAAM,CAAC,EAAE,EAAE,MAAM;IAcjB,MAAM,CAAC,EAAE,EAAE,MAAM;IAajB,KAAK;IAIJ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC;CAQjD"}
|
package/lib/updateMap.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateMap = exports.UpdateType = void 0;
|
|
4
|
+
var UpdateType;
|
|
5
|
+
(function (UpdateType) {
|
|
6
|
+
UpdateType[UpdateType["Insert"] = 0] = "Insert";
|
|
7
|
+
UpdateType[UpdateType["Upsert"] = 1] = "Upsert";
|
|
8
|
+
UpdateType[UpdateType["Remove"] = 2] = "Remove";
|
|
9
|
+
})(UpdateType = exports.UpdateType || (exports.UpdateType = {}));
|
|
10
|
+
class UpdateMap {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.map = new Map();
|
|
13
|
+
}
|
|
14
|
+
get(id) {
|
|
15
|
+
return this.map.get(id);
|
|
16
|
+
}
|
|
17
|
+
insert(id) {
|
|
18
|
+
const prevType = this.map.get(id);
|
|
19
|
+
switch (prevType) {
|
|
20
|
+
case UpdateType.Insert:
|
|
21
|
+
case UpdateType.Upsert:
|
|
22
|
+
throw new Error(`Can not add id ${id} because it is already marked as insert or upsert`);
|
|
23
|
+
case UpdateType.Remove:
|
|
24
|
+
this.map.set(id, UpdateType.Upsert);
|
|
25
|
+
break;
|
|
26
|
+
case undefined:
|
|
27
|
+
this.map.set(id, UpdateType.Insert);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
upsert(id) {
|
|
32
|
+
const prevType = this.map.get(id);
|
|
33
|
+
switch (prevType) {
|
|
34
|
+
case UpdateType.Insert:
|
|
35
|
+
break;
|
|
36
|
+
case UpdateType.Upsert:
|
|
37
|
+
case UpdateType.Remove:
|
|
38
|
+
case undefined:
|
|
39
|
+
this.map.set(id, UpdateType.Upsert);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
remove(id) {
|
|
44
|
+
const prevType = this.map.get(id);
|
|
45
|
+
switch (prevType) {
|
|
46
|
+
case UpdateType.Insert:
|
|
47
|
+
case UpdateType.Upsert:
|
|
48
|
+
case UpdateType.Remove:
|
|
49
|
+
case undefined:
|
|
50
|
+
this.map.set(id, UpdateType.Remove);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
clear() {
|
|
55
|
+
this.map.clear();
|
|
56
|
+
}
|
|
57
|
+
*[Symbol.iterator]() {
|
|
58
|
+
for (const [id, type] of this.map) {
|
|
59
|
+
yield {
|
|
60
|
+
id,
|
|
61
|
+
type,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.UpdateMap = UpdateMap;
|
|
67
|
+
//# sourceMappingURL=updateMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateMap.js","sourceRoot":"","sources":["../src/updateMap.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,+CAAM,CAAA;IACN,+CAAM,CAAA;IACN,+CAAM,CAAA;AACV,CAAC,EAJW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAIrB;AAOD,MAAa,SAAS;IAAtB;QACY,QAAG,GAA4B,IAAI,GAAG,EAAE,CAAA;IA6DpD,CAAC;IA3DG,GAAG,CAAC,EAAU;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,CAAC,EAAU;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAEjC,QAAQ,QAAQ,EAAE;YACd,KAAK,UAAU,CAAC,MAAM,CAAC;YACvB,KAAK,UAAU,CAAC,MAAM;gBAClB,MAAM,IAAI,KAAK,CAAC,kBAAkB,EAAE,mDAAmD,CAAC,CAAA;YAC5F,KAAK,UAAU,CAAC,MAAM;gBAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;gBACnC,MAAK;YACT,KAAK,SAAS;gBACV,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;gBACnC,MAAK;SACZ;IACL,CAAC;IAED,MAAM,CAAC,EAAU;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAEjC,QAAQ,QAAQ,EAAE;YACd,KAAK,UAAU,CAAC,MAAM;gBAClB,MAAK;YACT,KAAK,UAAU,CAAC,MAAM,CAAC;YACvB,KAAK,UAAU,CAAC,MAAM,CAAC;YACvB,KAAK,SAAS;gBACV,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;gBACnC,MAAK;SACZ;IACL,CAAC;IAED,MAAM,CAAC,EAAU;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAEjC,QAAQ,QAAQ,EAAE;YACd,KAAK,UAAU,CAAC,MAAM,CAAC;YACvB,KAAK,UAAU,CAAC,MAAM,CAAC;YACvB,KAAK,UAAU,CAAC,MAAM,CAAC;YACvB,KAAK,SAAS;gBACV,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;gBACnC,MAAK;SACZ;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QACd,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE;YAC/B,MAAM;gBACF,EAAE;gBACF,IAAI;aACP,CAAA;SACJ;IACL,CAAC;CACJ;AA9DD,8BA8DC"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAiB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAWpF;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAmBjC"}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copy = exports.splitIntoBatches = void 0;
|
|
4
|
+
function* splitIntoBatches(list, maxBatchSize) {
|
|
5
|
+
if (list.length <= maxBatchSize) {
|
|
6
|
+
yield list;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
let offset = 0;
|
|
10
|
+
while (list.length - offset > maxBatchSize) {
|
|
11
|
+
yield list.slice(offset, offset + maxBatchSize);
|
|
12
|
+
offset += maxBatchSize;
|
|
13
|
+
}
|
|
14
|
+
yield list.slice(offset);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.splitIntoBatches = splitIntoBatches;
|
|
18
|
+
function copy(obj) {
|
|
19
|
+
if (typeof obj !== 'object' || obj == null)
|
|
20
|
+
return obj;
|
|
21
|
+
else if (obj instanceof Date) {
|
|
22
|
+
return new Date(obj);
|
|
23
|
+
}
|
|
24
|
+
else if (Array.isArray(obj)) {
|
|
25
|
+
return copyArray(obj);
|
|
26
|
+
}
|
|
27
|
+
else if (obj instanceof Map) {
|
|
28
|
+
return new Map(copyArray(Array.from(obj)));
|
|
29
|
+
}
|
|
30
|
+
else if (obj instanceof Set) {
|
|
31
|
+
return new Set(copyArray(Array.from(obj)));
|
|
32
|
+
}
|
|
33
|
+
else if (ArrayBuffer.isView(obj)) {
|
|
34
|
+
return copyBuffer(obj);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const clone = Object.create(Object.getPrototypeOf(obj));
|
|
38
|
+
for (var k in obj) {
|
|
39
|
+
clone[k] = copy(obj[k]);
|
|
40
|
+
}
|
|
41
|
+
return clone;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.copy = copy;
|
|
45
|
+
function copyBuffer(buf) {
|
|
46
|
+
if (buf instanceof Buffer) {
|
|
47
|
+
return Buffer.from(buf);
|
|
48
|
+
}
|
|
49
|
+
return new buf.constructor(buf.buffer.slice(), buf.byteOffset, buf.length);
|
|
50
|
+
}
|
|
51
|
+
function copyArray(arr) {
|
|
52
|
+
const clone = new Array(arr.length);
|
|
53
|
+
for (let i = 0; i < arr.length; i++) {
|
|
54
|
+
clone[i] = copy(clone[i]);
|
|
55
|
+
}
|
|
56
|
+
return clone;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,QAAe,CAAC,CAAC,gBAAgB,CAAI,IAAS,EAAE,YAAoB;IAChE,IAAI,IAAI,CAAC,MAAM,IAAI,YAAY,EAAE;QAC7B,MAAM,IAAI,CAAA;KACb;SAAM;QACH,IAAI,MAAM,GAAG,CAAC,CAAA;QACd,OAAO,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,YAAY,EAAE;YACxC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC,CAAA;YAC/C,MAAM,IAAI,YAAY,CAAA;SACzB;QACD,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;KAC3B;AACL,CAAC;AAXD,4CAWC;AAED,SAAgB,IAAI,CAAI,GAAM;IAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,GAAG,CAAA;SACjD,IAAI,GAAG,YAAY,IAAI,EAAE;QAC1B,OAAO,IAAI,IAAI,CAAC,GAAG,CAAQ,CAAA;KAC9B;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC3B,OAAO,SAAS,CAAC,GAAG,CAAQ,CAAA;KAC/B;SAAM,IAAI,GAAG,YAAY,GAAG,EAAE;QAC3B,OAAO,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAQ,CAAA;KACpD;SAAM,IAAI,GAAG,YAAY,GAAG,EAAE;Q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
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/belopash/squid-typeorm-store"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rm -rf lib && tsc"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@subsquid/util-internal": "^2.3.0",
|
|
14
|
+
"graph-data-structure": "^3.3.0"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@subsquid/typeorm-store": "^1.2.1",
|
|
18
|
+
"typeorm": "^0.3.16"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.3.1",
|
|
22
|
+
"typescript": "~5.0.2"
|
|
23
|
+
}
|
|
24
|
+
}
|