@samet-it/be-couchbase-common 1.0.10 → 1.0.11

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.
@@ -8,6 +8,7 @@ export declare abstract class CbRepo<E extends CbEntity, ID> implements CbRepoLi
8
8
  private _scopeName?;
9
9
  private _bucketName?;
10
10
  private _tryCount;
11
+ private _pkIndexed;
11
12
  protected logger: Logger;
12
13
  /** @inheritDoc */
13
14
  readonly fullPath: string;
@@ -45,7 +46,7 @@ export declare abstract class CbRepo<E extends CbEntity, ID> implements CbRepoLi
45
46
  /**
46
47
  * Execute the creation of indexes with keys
47
48
  * */
48
- protected _createMoreIndices(...keys: Array<keyof CbEntity>): Promise<void>;
49
+ protected _createMoreIndices(...keys: Array<keyof E>): Promise<void>;
49
50
  /**
50
51
  * Execute the creation of primary key
51
52
  * */
@@ -127,9 +127,22 @@ class CbRepo {
127
127
  * */
128
128
  _createMoreIndices(...keys) {
129
129
  return __awaiter(this, void 0, void 0, function* () {
130
- const promises = keys.map(k => this._createIndex(k));
131
- promises.push(this._createPk());
132
- yield Promise.all(promises);
130
+ const already = [];
131
+ const promises = keys
132
+ .filter(k => {
133
+ if (already.includes(k)) {
134
+ return false;
135
+ }
136
+ already.push(k);
137
+ return true;
138
+ })
139
+ .map(k => this._createIndex(k));
140
+ if (!this._pkIndexed) {
141
+ promises.push(this._createPk());
142
+ }
143
+ if (promises.length > 0) {
144
+ yield Promise.all(promises);
145
+ }
133
146
  });
134
147
  }
135
148
  /**
@@ -137,8 +150,11 @@ class CbRepo {
137
150
  * */
138
151
  _createPk() {
139
152
  return __awaiter(this, void 0, void 0, function* () {
140
- const sql = `CREATE PRIMARY INDEX \`pk\` ON ${this.fullPath}`;
141
- yield this.cb.one(this.def, sql, { name: `${this.path}.pk`, ignoredErrors: [couchbase_1.IndexExistsError] });
153
+ if (!this._pkIndexed) {
154
+ const sql = `CREATE PRIMARY INDEX \`pk\` ON ${this.fullPath}`;
155
+ yield this.cb.one(this.def, sql, { name: `${this.path}.pk`, ignoredErrors: [couchbase_1.IndexExistsError] });
156
+ this._pkIndexed = true;
157
+ }
142
158
  });
143
159
  }
144
160
  /** @inheritDoc */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-couchbase-common",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Couchbase common component",
5
5
  "keywords": [
6
6
  "Couchbase"