tapeworm_persistence_store_hybrid 1.0.2 → 1.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # tapeworm_persistence_store_hybrid
2
+
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 855c605: Convert monorepo to TypeScript with full type definitions
8
+
9
+ - Convert all packages from JavaScript to TypeScript with complete type annotations
10
+ - Add shared type system (IBaseEvent, ICommit, ISnapshot, IPersistencePartition)
11
+ - Migrate all test suites to vitest
12
+ - Add CJS backward-compatibility shims to preserve existing require() API
13
+ - Fix \_partitions initialization bug and indexeddb loadSnapshot error handler
14
+
15
+ ### Patch Changes
16
+
17
+ - Upgrade packages to fix vulnerabilities.
package/README CHANGED
@@ -1 +1 @@
1
- #tapeworm_persistence_store_hybrid
1
+ #tapeworm_persistence_store_hybrid
@@ -1,22 +1,22 @@
1
- import BluebirdPromise from 'bluebird';
2
- import { Commit } from 'tapeworm';
3
- import { LoggingOptions, Partition, queryStreamCallback, truncateStreamFromCallback } from './HybridPersistence';
4
- import { Snapshot } from './utils';
5
- declare class HybridPartition implements Partition {
6
- private localPartition;
7
- private remotePartition;
8
- private snapshotLifeTime;
9
- private loggingOptions;
10
- constructor(localPartition: Partition, remotePartition: Partition, autoCleanLocalPartition: boolean, snapshotLifeTime: number, loggingOptions: LoggingOptions);
11
- private cleanPartition;
12
- open(): BluebirdPromise<this>;
13
- append(commit: Commit<Record<string, any>>): BluebirdPromise<import("./utils").Commit<Record<string, any>>[]>;
14
- storeSnapshot(streamId: string, snapshot: Snapshot, version: number): BluebirdPromise<void>;
15
- private checkIsSnapshotToOld;
16
- loadSnapshot(streamId: string, callback?: (err: Error, snapshot: Snapshot) => void): BluebirdPromise<Snapshot>;
17
- queryStream(streamId: string, fromEventSequence?: number | queryStreamCallback, callback?: queryStreamCallback): BluebirdPromise<any[]>;
18
- removeSnapshot(streamId: string): BluebirdPromise<void>;
19
- truncateStreamFrom(streamId: string, commit: Commit<Record<string, any>>, remove: boolean | truncateStreamFromCallback, callback?: truncateStreamFromCallback): BluebirdPromise<void>;
20
- applyCommitHeader(streamId: string, commit: Commit<Record<string, any>>, remove: any, callback: () => void): BluebirdPromise<void>;
21
- }
22
- export default HybridPartition;
1
+ import BluebirdPromise from 'bluebird';
2
+ import type { ICommit, ISnapshot } from 'tapeworm';
3
+ import { LoggingOptions, Partition, queryStreamCallback, truncateStreamFromCallback } from './HybridPersistence';
4
+ declare class HybridPartition implements Partition {
5
+ private localPartition;
6
+ private remotePartition;
7
+ private snapshotLifeTime;
8
+ private loggingOptions;
9
+ constructor(localPartition: Partition, remotePartition: Partition, autoCleanLocalPartition: boolean, snapshotLifeTime: number, loggingOptions: LoggingOptions);
10
+ private cleanPartition;
11
+ open(): BluebirdPromise<this>;
12
+ append(commit: ICommit): BluebirdPromise<ICommit<import("tapeworm").IBaseEvent>[]>;
13
+ storeSnapshot(streamId: string, snapshot: ISnapshot['snapshot'], version: number): BluebirdPromise<void>;
14
+ private checkIsSnapshotToOld;
15
+ loadSnapshot(streamId: string, callback?: (err: Error | null, snapshot: ISnapshot) => void): BluebirdPromise<ISnapshot>;
16
+ queryStream(streamId: string, fromEventSequence?: number | queryStreamCallback, callback?: queryStreamCallback): BluebirdPromise<ICommit<import("tapeworm").IBaseEvent>[]>;
17
+ removeSnapshot(streamId: string): BluebirdPromise<void>;
18
+ truncateStreamFrom(streamId: string, commitSequence: number, remove: boolean | truncateStreamFromCallback, callback?: truncateStreamFromCallback): BluebirdPromise<void>;
19
+ applyCommitHeader(streamId: string, commit: ICommit, remove: any, callback: () => void): BluebirdPromise<void>;
20
+ }
21
+ export default HybridPartition;
22
+ //# sourceMappingURL=HybridPartition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HybridPartition.d.ts","sourceRoot":"","sources":["../src/HybridPartition.ts"],"names":[],"mappings":"AAAA,OAAO,eA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,eAAe,CAAC"}
@@ -1,128 +1,128 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- exports.__esModule = true;
6
- var bluebird_1 = __importDefault(require("bluebird"));
7
- var slf_1 = require("slf");
8
- var log = slf_1.LoggerFactory.getLogger('tapeworm-persistence-hybrid:hybrid-partition');
9
- var DEFAULT_LOAD_SNAPSHOT_MAX_TIME = 10;
10
- var HybridPartition = (function () {
11
- function HybridPartition(localPartition, remotePartition, autoCleanLocalPartition, snapshotLifeTime, loggingOptions) {
12
- var _this = this;
13
- this.localPartition = localPartition;
14
- this.remotePartition = remotePartition;
15
- this.snapshotLifeTime = snapshotLifeTime;
16
- this.loggingOptions = loggingOptions;
17
- if (!this.loggingOptions.loadSnapshotMaxTime) {
18
- this.loggingOptions.loadSnapshotMaxTime = DEFAULT_LOAD_SNAPSHOT_MAX_TIME;
19
- }
20
- if (autoCleanLocalPartition) {
21
- if (!localPartition.querySnapshotsOlderThanMaxDate) {
22
- throw new Error('Unable to start auto clean of local partition since it does not support it.');
23
- }
24
- log.info('Starting auto clean of local partition');
25
- setInterval(function () {
26
- _this.cleanPartition();
27
- }, 1000 * 60 * 30);
28
- }
29
- }
30
- HybridPartition.prototype.cleanPartition = function () {
31
- var _this = this;
32
- log.info('Auto cleaning partition');
33
- var snapshotTTLDate = new Date();
34
- snapshotTTLDate.setMinutes(snapshotTTLDate.getMinutes() - this.snapshotLifeTime);
35
- this.localPartition.querySnapshotsOlderThanMaxDate(snapshotTTLDate.toISOString()).then(function (snapshots) {
36
- log.info('cleaning %s snapshots', snapshots.length);
37
- var snapshotIdsToRemove = snapshots.map(function (snapshot) { return snapshot.id; });
38
- _this.localPartition.removeSnapshots(snapshotIdsToRemove);
39
- snapshotIdsToRemove.forEach(function (snapshotId) { return _this.localPartition.truncateStreamFrom(snapshotId, 0, true); });
40
- });
41
- };
42
- HybridPartition.prototype.open = function () {
43
- return bluebird_1["default"].resolve(this);
44
- };
45
- HybridPartition.prototype.append = function (commit) {
46
- return this.localPartition.append(commit);
47
- };
48
- HybridPartition.prototype.storeSnapshot = function (streamId, snapshot, version) {
49
- return this.localPartition.storeSnapshot(streamId, snapshot, version);
50
- };
51
- HybridPartition.prototype.checkIsSnapshotToOld = function (snapshot) {
52
- if (!snapshot) {
53
- return true;
54
- }
55
- if (snapshot.storedDateTime) {
56
- var storedDateEpoch = new Date(snapshot.storedDateTime).getTime();
57
- var nowEpoch = new Date().getTime();
58
- var elapsedTimeInMilliSeconds = nowEpoch - storedDateEpoch;
59
- var snapshotLifetimeMilliSeconds = this.snapshotLifeTime * 60 * 1000;
60
- return elapsedTimeInMilliSeconds > snapshotLifetimeMilliSeconds;
61
- }
62
- return false;
63
- };
64
- HybridPartition.prototype.loadSnapshot = function (streamId, callback) {
65
- var _this = this;
66
- var startTime = Date.now();
67
- return new bluebird_1["default"](function (resolve) {
68
- _this.localPartition.loadSnapshot(streamId).then(function (localSnapshot) {
69
- var isSnapshotToOld = _this.checkIsSnapshotToOld(localSnapshot);
70
- if (localSnapshot && !isSnapshotToOld) {
71
- log.info('loadSnapshot: Using local snapshot');
72
- callback === null || callback === void 0 ? void 0 : callback(null, localSnapshot);
73
- resolve(localSnapshot);
74
- return;
75
- }
76
- _this.remotePartition
77
- .loadSnapshot(streamId)
78
- .then(function (remoteSnapshot) {
79
- log.info('loadSnapshot: Using remote snapshot');
80
- if (remoteSnapshot) {
81
- _this.localPartition.storeSnapshot(remoteSnapshot.id, remoteSnapshot.snapshot, remoteSnapshot.version);
82
- _this.localPartition.truncateStreamFrom(remoteSnapshot.id, 0, true);
83
- }
84
- callback === null || callback === void 0 ? void 0 : callback(null, remoteSnapshot);
85
- resolve(remoteSnapshot);
86
- })["catch"](function (error) {
87
- log.warn('Failed to load snapshot with stream id %s from remote partition', streamId);
88
- });
89
- });
90
- })["finally"](function () {
91
- var endTime = Date.now();
92
- var queryTime = (endTime - startTime) / 1000;
93
- if (_this.loggingOptions.loggingEnabled && queryTime > _this.loggingOptions.loadSnapshotMaxTime) {
94
- log.warn('Loading snapshot with id %s, took %s seconds. Allowed max time is %s seconds.', streamId, queryTime, _this.loggingOptions.loadSnapshotMaxTime);
95
- }
96
- });
97
- };
98
- HybridPartition.prototype.queryStream = function (streamId, fromEventSequence, callback) {
99
- var _this = this;
100
- log.debug('queryStream, streamId %s ,fromEventSequence %s', streamId, fromEventSequence);
101
- return new bluebird_1["default"](function (resolve) {
102
- _this.localPartition.loadSnapshot(streamId).then(function (localSnapshot) {
103
- var currentPartition = _this.localPartition;
104
- var isSnapshotToOld = _this.checkIsSnapshotToOld(localSnapshot);
105
- if (!localSnapshot || isSnapshotToOld) {
106
- currentPartition = _this.remotePartition;
107
- }
108
- currentPartition.queryStream(streamId, fromEventSequence).then(function (queryStream) {
109
- callback === null || callback === void 0 ? void 0 : callback(null, queryStream);
110
- resolve(queryStream);
111
- return;
112
- });
113
- });
114
- });
115
- };
116
- HybridPartition.prototype.removeSnapshot = function (streamId) {
117
- return this.localPartition.removeSnapshot(streamId);
118
- };
119
- HybridPartition.prototype.truncateStreamFrom = function (streamId, commit, remove, callback) {
120
- return this.localPartition.truncateStreamFrom(streamId, commit, remove, callback);
121
- };
122
- HybridPartition.prototype.applyCommitHeader = function (streamId, commit, remove, callback) {
123
- return this.localPartition.applyCommitHeader(streamId, commit, remove, callback);
124
- };
125
- return HybridPartition;
126
- }());
127
- exports["default"] = HybridPartition;
1
+ "use strict";
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
+ const bluebird_1 = __importDefault(require("bluebird"));
7
+ const slf_1 = require("slf");
8
+ const log = slf_1.LoggerFactory.getLogger('tapeworm-persistence-hybrid:hybrid-partition');
9
+ const DEFAULT_LOAD_SNAPSHOT_MAX_TIME = 10;
10
+ class HybridPartition {
11
+ localPartition;
12
+ remotePartition;
13
+ snapshotLifeTime;
14
+ loggingOptions;
15
+ constructor(localPartition, remotePartition, autoCleanLocalPartition, snapshotLifeTime, loggingOptions) {
16
+ this.localPartition = localPartition;
17
+ this.remotePartition = remotePartition;
18
+ this.snapshotLifeTime = snapshotLifeTime;
19
+ this.loggingOptions = loggingOptions;
20
+ if (!this.loggingOptions.loadSnapshotMaxTime) {
21
+ this.loggingOptions.loadSnapshotMaxTime = DEFAULT_LOAD_SNAPSHOT_MAX_TIME;
22
+ }
23
+ if (autoCleanLocalPartition) {
24
+ if (!localPartition.querySnapshotsOlderThanMaxDate) {
25
+ throw new Error('Unable to start auto clean of local partition since it does not support it.');
26
+ }
27
+ log.info('Starting auto clean of local partition');
28
+ setInterval(() => {
29
+ this.cleanPartition();
30
+ }, 1000 * 60 * 30);
31
+ }
32
+ }
33
+ cleanPartition() {
34
+ log.info('Auto cleaning partition');
35
+ const snapshotTTLDate = new Date();
36
+ snapshotTTLDate.setMinutes(snapshotTTLDate.getMinutes() - this.snapshotLifeTime);
37
+ this.localPartition.querySnapshotsOlderThanMaxDate(snapshotTTLDate.toISOString()).then((snapshots) => {
38
+ log.info('cleaning %s snapshots', snapshots.length);
39
+ const snapshotIdsToRemove = snapshots.map((snapshot) => snapshot.id);
40
+ this.localPartition.removeSnapshots(snapshotIdsToRemove);
41
+ snapshotIdsToRemove.forEach((snapshotId) => this.localPartition.truncateStreamFrom(snapshotId, 0, true));
42
+ });
43
+ }
44
+ open() {
45
+ return bluebird_1.default.resolve(this);
46
+ }
47
+ append(commit) {
48
+ return this.localPartition.append(commit);
49
+ }
50
+ storeSnapshot(streamId, snapshot, version) {
51
+ return this.localPartition.storeSnapshot(streamId, snapshot, version);
52
+ }
53
+ checkIsSnapshotToOld(snapshot) {
54
+ if (!snapshot) {
55
+ return true;
56
+ }
57
+ if (snapshot.storedDateTime) {
58
+ const storedDateEpoch = new Date(snapshot.storedDateTime).getTime();
59
+ const nowEpoch = new Date().getTime();
60
+ const elapsedTimeInMilliSeconds = nowEpoch - storedDateEpoch;
61
+ const snapshotLifetimeMilliSeconds = this.snapshotLifeTime * 60 * 1000;
62
+ return elapsedTimeInMilliSeconds > snapshotLifetimeMilliSeconds;
63
+ }
64
+ return false;
65
+ }
66
+ loadSnapshot(streamId, callback) {
67
+ const startTime = Date.now();
68
+ return new bluebird_1.default((resolve) => {
69
+ this.localPartition.loadSnapshot(streamId).then((localSnapshot) => {
70
+ const isSnapshotToOld = this.checkIsSnapshotToOld(localSnapshot);
71
+ if (localSnapshot && !isSnapshotToOld) {
72
+ log.info('loadSnapshot: Using local snapshot');
73
+ callback?.(null, localSnapshot);
74
+ resolve(localSnapshot);
75
+ return;
76
+ }
77
+ this.remotePartition
78
+ .loadSnapshot(streamId)
79
+ .then((remoteSnapshot) => {
80
+ log.info('loadSnapshot: Using remote snapshot');
81
+ if (remoteSnapshot) {
82
+ this.localPartition.storeSnapshot(remoteSnapshot.id, remoteSnapshot.snapshot, remoteSnapshot.version);
83
+ this.localPartition.truncateStreamFrom(remoteSnapshot.id, 0, true);
84
+ callback?.(null, remoteSnapshot);
85
+ }
86
+ resolve(remoteSnapshot);
87
+ })
88
+ .catch((error) => {
89
+ log.warn('Failed to load snapshot with stream id %s from remote partition', streamId);
90
+ });
91
+ });
92
+ }).finally(() => {
93
+ const endTime = Date.now();
94
+ const queryTime = (endTime - startTime) / 1000;
95
+ if (this.loggingOptions.loggingEnabled && queryTime > this.loggingOptions.loadSnapshotMaxTime) {
96
+ log.warn('Loading snapshot with id %s, took %s seconds. Allowed max time is %s seconds.', streamId, queryTime, this.loggingOptions.loadSnapshotMaxTime);
97
+ }
98
+ });
99
+ }
100
+ queryStream(streamId, fromEventSequence, callback) {
101
+ log.debug('queryStream, streamId %s ,fromEventSequence %s', streamId, fromEventSequence);
102
+ return new bluebird_1.default((resolve) => {
103
+ this.localPartition.loadSnapshot(streamId).then((localSnapshot) => {
104
+ let currentPartition = this.localPartition;
105
+ const isSnapshotToOld = this.checkIsSnapshotToOld(localSnapshot);
106
+ if (!localSnapshot || isSnapshotToOld) {
107
+ currentPartition = this.remotePartition;
108
+ }
109
+ currentPartition.queryStream(streamId, fromEventSequence).then((queryStream) => {
110
+ callback?.(null, queryStream);
111
+ resolve(queryStream);
112
+ return;
113
+ });
114
+ });
115
+ });
116
+ }
117
+ removeSnapshot(streamId) {
118
+ return this.localPartition.removeSnapshot(streamId);
119
+ }
120
+ truncateStreamFrom(streamId, commitSequence, remove, callback) {
121
+ return this.localPartition.truncateStreamFrom(streamId, commitSequence, remove, callback);
122
+ }
123
+ applyCommitHeader(streamId, commit, remove, callback) {
124
+ return this.localPartition.applyCommitHeader(streamId, commit, remove, callback);
125
+ }
126
+ }
127
+ exports.default = HybridPartition;
128
128
  //# sourceMappingURL=HybridPartition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HybridPartition.js","sourceRoot":"","sources":["../src/HybridPartition.ts"],"names":[],"mappings":";;;;;AAAA,sDAAuC;AAIvC,2BAAoC;AAGpC,IAAM,GAAG,GAAG,mBAAa,CAAC,SAAS,CAAC,8CAA8C,CAAC,CAAC;AAEpF,IAAM,8BAA8B,GAAG,EAAE,CAAC;AAE1C;IAUE,yBACU,cAAyB,EACzB,eAA0B,EAClC,uBAAgC,EACxB,gBAAwB,EAChC,cAA8B;QALhC,iBAsBC;QArBS,mBAAc,GAAd,cAAc,CAAW;QACzB,oBAAe,GAAf,eAAe,CAAW;QAE1B,qBAAgB,GAAhB,gBAAgB,CAAQ;QAGhC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,mBAAmB,EAAE;YAC5C,IAAI,CAAC,cAAc,CAAC,mBAAmB,GAAG,8BAA8B,CAAC;SAC1E;QAED,IAAI,uBAAuB,EAAE;YAC3B,IAAI,CAAC,cAAc,CAAC,8BAA8B,EAAE;gBAClD,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;aAChG;YAED,GAAG,CAAC,I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C,CAAC,CAAC;IACL,CAAC;IAED,cAAc,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,kBAAkB,CAAC,QAAgB,EAAE,cAAsB,EAAE,MAA4C,EAAE,QAAqC;QAC9I,OAAO,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC5F,CAAC;IAED,iBAAiB,CAAC,QAAgB,EAAE,MAAe,EAAE,MAAW,EAAE,QAAoB;QACpF,OAAO,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnF,CAAC;CACF;AAED,kBAAe,eAAe,CAAC"}
@@ -1,38 +1,39 @@
1
- import BluebirdPromise from 'bluebird';
2
- import { Commit, Snapshot } from './utils';
3
- export declare type truncateStreamFromCallback = (error: Error, result: Record<string, any>) => void;
4
- declare type TruncateStreamFrom = (streamId: string, commitSequence: number, remove: boolean | truncateStreamFromCallback, callback?: truncateStreamFromCallback) => BluebirdPromise<void>;
5
- export declare type queryStreamCallback = (err: Error, steam: Commit<Record<string, any>>[]) => void;
6
- declare type QueryStream = (streamId: string, fromEventSequence?: number | queryStreamCallback, callback?: queryStreamCallback) => BluebirdPromise<Commit<Record<string, any>>[]>;
7
- export declare type Partition = {
8
- open: () => BluebirdPromise<Partition>;
9
- storeSnapshot: (streamId: string, snapshot: Snapshot['snapshot'], version: number) => BluebirdPromise<void>;
10
- loadSnapshot: (streamId: string, callback?: (err: Error, snapshot: Snapshot | undefined) => void) => BluebirdPromise<Snapshot | undefined>;
11
- queryStream: QueryStream;
12
- append: (commit: Commit<Record<string, any>>) => BluebirdPromise<Commit<Record<string, any>>[]>;
13
- removeSnapshot: (streamId: string) => BluebirdPromise<void>;
14
- removeSnapshots?: (streamIds: string[]) => BluebirdPromise<void>;
15
- truncateStreamFrom: TruncateStreamFrom;
16
- applyCommitHeader: (streamId: string, commit: Commit<Record<string, any>>, remove: any, callback: () => void) => BluebirdPromise<void>;
17
- querySnapshotsOlderThanMaxDate?: (dateTime: string) => BluebirdPromise<Snapshot[]>;
18
- };
19
- export interface LoggingOptions {
20
- loggingEnabled: boolean;
21
- loadSnapshotMaxTime?: number;
22
- }
23
- export declare type Persistence = {
24
- openPartition: (partitionId?: string) => BluebirdPromise<Partition>;
25
- };
26
- declare class HybridPersistence {
27
- private localPersistence;
28
- private remotePersistence;
29
- private autoCleanLocalPartition;
30
- private snapshotLifeTime;
31
- private loggingOptions;
32
- private partitions;
33
- constructor(localPersistence: Persistence, remotePersistence: Persistence, autoCleanLocalPartition: boolean, snapshotLifeTime: number, loggingOptions: LoggingOptions);
34
- openPartition(partitionId?: string): BluebirdPromise<unknown>;
35
- private getPartition;
36
- private setPartition;
37
- }
38
- export default HybridPersistence;
1
+ import BluebirdPromise from 'bluebird';
2
+ import type { ICommit, ISnapshot } from 'tapeworm';
3
+ export type truncateStreamFromCallback = (error: Error | null, result: Record<string, any>) => void;
4
+ type TruncateStreamFrom = (streamId: string, commitSequence: number, remove: boolean | truncateStreamFromCallback, callback?: truncateStreamFromCallback) => BluebirdPromise<void>;
5
+ export type queryStreamCallback = (err: Error | null, steam: ICommit[]) => void;
6
+ type QueryStream = (streamId: string, fromEventSequence?: number | queryStreamCallback, callback?: queryStreamCallback) => BluebirdPromise<ICommit[]>;
7
+ export type Partition = {
8
+ open: () => BluebirdPromise<Partition>;
9
+ storeSnapshot: (streamId: string, snapshot: ISnapshot['snapshot'], version: number) => BluebirdPromise<void>;
10
+ loadSnapshot: (streamId: string, callback?: (err: Error | null, snapshot: ISnapshot | undefined) => void) => BluebirdPromise<ISnapshot | undefined>;
11
+ queryStream: QueryStream;
12
+ append: (commit: ICommit) => BluebirdPromise<ICommit[]>;
13
+ removeSnapshot: (streamId: string) => BluebirdPromise<void>;
14
+ removeSnapshots?: (streamIds: string[]) => BluebirdPromise<void>;
15
+ truncateStreamFrom: TruncateStreamFrom;
16
+ applyCommitHeader: (streamId: string, commit: ICommit, remove: any, callback: () => void) => BluebirdPromise<void>;
17
+ querySnapshotsOlderThanMaxDate?: (dateTime: string) => BluebirdPromise<ISnapshot[]>;
18
+ };
19
+ export interface LoggingOptions {
20
+ loggingEnabled: boolean;
21
+ loadSnapshotMaxTime?: number;
22
+ }
23
+ export type Persistence = {
24
+ openPartition: (partitionId?: string) => BluebirdPromise<Partition>;
25
+ };
26
+ declare class HybridPersistence {
27
+ private localPersistence;
28
+ private remotePersistence;
29
+ private autoCleanLocalPartition;
30
+ private snapshotLifeTime;
31
+ private loggingOptions;
32
+ private partitions;
33
+ constructor(localPersistence: Persistence, remotePersistence: Persistence, autoCleanLocalPartition: boolean, snapshotLifeTime: number, loggingOptions: LoggingOptions);
34
+ openPartition(partitionId?: string): BluebirdPromise<unknown>;
35
+ private getPartition;
36
+ private setPartition;
37
+ }
38
+ export default HybridPersistence;
39
+ //# sourceMappingURL=HybridPersistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HybridPersistence.d.ts","sourceRoot":"","sources":["../src/HybridPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,UAAU,CAAC;AAEvC,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;AACpG,KAAK,kBAAkB,GAAG,CACxB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,OAAO,GAAG,0BAA0B,EAC5C,QAAQ,CAAC,EAAE,0BAA0B,KAClC,eAAe,CAAC,IAAI,CAAC,CAAC;AAE3B,MAAM,MAAM,mBAAmB,GAAG,C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eAAe,CAAC,SAAS,EAAE,CAAC,CAAC;CACrF,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,eAAe,CAAC,SAAS,CAAC,CAAC;CACrE,CAAC;AAIF,cAAM,iBAAiB;IAInB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,iBAAiB;IACzB,OAAO,CAAC,uBAAuB;IAC/B,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,cAAc;IAPxB,OAAO,CAAC,UAAU,CAAiC;gBAGzC,gBAAgB,EAAE,WAAW,EAC7B,iBAAiB,EAAE,WAAW,EAC9B,uBAAuB,EAAE,OAAO,EAChC,gBAAgB,EAAE,MAAM,EACxB,cAAc,EAAE,cAAc;IAGxC,aAAa,CAAC,WAAW,GAAE,MAA0B;IAiBrD,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,YAAY;CAIrB;AAED,eAAe,iBAAiB,CAAC"}
@@ -1,94 +1,49 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- exports.__esModule = true;
42
- var bluebird_1 = __importDefault(require("bluebird"));
43
- var HybridPartition_1 = __importDefault(require("./HybridPartition"));
44
- var DEFAULT_PARTITION = 'master';
45
- var HybridPersistence = (function () {
46
- function HybridPersistence(localPersistence, remotePersistence, autoCleanLocalPartition, snapshotLifeTime, loggingOptions) {
47
- this.localPersistence = localPersistence;
48
- this.remotePersistence = remotePersistence;
49
- this.autoCleanLocalPartition = autoCleanLocalPartition;
50
- this.snapshotLifeTime = snapshotLifeTime;
51
- this.loggingOptions = loggingOptions;
52
- this.partitions = {};
53
- }
54
- HybridPersistence.prototype.openPartition = function (partitionId) {
55
- var _this = this;
56
- if (partitionId === void 0) { partitionId = DEFAULT_PARTITION; }
57
- return new bluebird_1["default"](function (resolve) { return __awaiter(_this, void 0, void 0, function () {
58
- var partition, localPartition, remotePartition, newPartition_1;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0:
62
- partition = this.getPartition(partitionId);
63
- if (!partition) return [3, 1];
64
- resolve(partition);
65
- return [3, 4];
66
- case 1: return [4, this.localPersistence.openPartition(partitionId)];
67
- case 2:
68
- localPartition = _a.sent();
69
- return [4, this.remotePersistence.openPartition(partitionId)];
70
- case 3:
71
- remotePartition = _a.sent();
72
- newPartition_1 = new HybridPartition_1["default"](localPartition, remotePartition, this.autoCleanLocalPartition, this.snapshotLifeTime, this.loggingOptions);
73
- this.setPartition(partitionId, newPartition_1);
74
- newPartition_1.open().then(function () {
75
- resolve(newPartition_1);
76
- });
77
- _a.label = 4;
78
- case 4: return [2];
79
- }
80
- });
81
- }); });
82
- };
83
- HybridPersistence.prototype.getPartition = function (partitionId) {
84
- if (partitionId === void 0) { partitionId = DEFAULT_PARTITION; }
85
- return this.partitions[partitionId];
86
- };
87
- HybridPersistence.prototype.setPartition = function (partitionId, partition) {
88
- this.partitions[partitionId || DEFAULT_PARTITION] = partition;
89
- return partition;
90
- };
91
- return HybridPersistence;
92
- }());
93
- exports["default"] = HybridPersistence;
1
+ "use strict";
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
+ const bluebird_1 = __importDefault(require("bluebird"));
7
+ const HybridPartition_1 = __importDefault(require("./HybridPartition"));
8
+ const DEFAULT_PARTITION = 'master';
9
+ class HybridPersistence {
10
+ localPersistence;
11
+ remotePersistence;
12
+ autoCleanLocalPartition;
13
+ snapshotLifeTime;
14
+ loggingOptions;
15
+ partitions = {};
16
+ constructor(localPersistence, remotePersistence, autoCleanLocalPartition, snapshotLifeTime, loggingOptions) {
17
+ this.localPersistence = localPersistence;
18
+ this.remotePersistence = remotePersistence;
19
+ this.autoCleanLocalPartition = autoCleanLocalPartition;
20
+ this.snapshotLifeTime = snapshotLifeTime;
21
+ this.loggingOptions = loggingOptions;
22
+ }
23
+ openPartition(partitionId = DEFAULT_PARTITION) {
24
+ return new bluebird_1.default(async (resolve) => {
25
+ const partition = this.getPartition(partitionId);
26
+ if (partition) {
27
+ resolve(partition);
28
+ }
29
+ else {
30
+ const localPartition = await this.localPersistence.openPartition(partitionId);
31
+ const remotePartition = await this.remotePersistence.openPartition(partitionId);
32
+ const newPartition = new HybridPartition_1.default(localPartition, remotePartition, this.autoCleanLocalPartition, this.snapshotLifeTime, this.loggingOptions);
33
+ this.setPartition(partitionId, newPartition);
34
+ newPartition.open().then(() => {
35
+ resolve(newPartition);
36
+ });
37
+ }
38
+ });
39
+ }
40
+ getPartition(partitionId = DEFAULT_PARTITION) {
41
+ return this.partitions[partitionId];
42
+ }
43
+ setPartition(partitionId, partition) {
44
+ this.partitions[partitionId] = partition;
45
+ return partition;
46
+ }
47
+ }
48
+ exports.default = HybridPersistence;
94
49
  //# sourceMappingURL=HybridPersistence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HybridPersistence.js","sourceRoot":"","sources":["../src/HybridPersistence.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAuC;AACvC,sEAAgD;AAwChD,IAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC;IAGE,2BACU,gBAA6B,EAC7B,iBAA8B,EAC9B,uBAAgC,EAChC,gBAAwB,EACxB,cAA8B;QAJ9B,qBAAgB,GAAhB,gBAAgB,CAAa;QAC7B,sBAAiB,GAAjB,iBAAiB,CAAa;QAC9B,4BAAuB,GAAvB,uBAAuB,CAAS;QAChC,qBAAgB,GAAhB,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