@samet-it/be-couchbase-common 1.0.11 → 1.0.12
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/repo/cb.repo.d.ts +2 -0
- package/dist/repo/cb.repo.js +30 -6
- package/package.json +1 -1
package/dist/repo/cb.repo.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare abstract class CbRepo<E extends CbEntity, ID> implements CbRepoLi
|
|
|
23
23
|
/** @inheritDoc */
|
|
24
24
|
readonly collection: Collection;
|
|
25
25
|
protected constructor(colName: string, cb: CbAdapterService, _scopeName?: string, _bucketName?: string);
|
|
26
|
+
private get _randomIndexName();
|
|
27
|
+
protected _indexName(name: string): string;
|
|
26
28
|
/**
|
|
27
29
|
* Fetch urn from doc as doc._urn
|
|
28
30
|
* */
|
package/dist/repo/cb.repo.js
CHANGED
|
@@ -35,6 +35,31 @@ class CbRepo {
|
|
|
35
35
|
F_TRASH_ID = cb.f('_trashId');
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
get _randomIndexName() {
|
|
39
|
+
return 'idx_' + (0, node_crypto_1.randomUUID)().match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
|
40
|
+
.map(s => s.toLowerCase())
|
|
41
|
+
.join('_');
|
|
42
|
+
}
|
|
43
|
+
_indexName(name) {
|
|
44
|
+
if (typeof name !== 'string') {
|
|
45
|
+
return this._randomIndexName;
|
|
46
|
+
}
|
|
47
|
+
name = name.trim();
|
|
48
|
+
if (name === '') {
|
|
49
|
+
return this._randomIndexName;
|
|
50
|
+
}
|
|
51
|
+
name = name.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
|
52
|
+
.map(s => s.toLowerCase())
|
|
53
|
+
.join('_');
|
|
54
|
+
name = name.replace(/^_+|_+$/g, '');
|
|
55
|
+
if (name === '') {
|
|
56
|
+
return this._randomIndexName;
|
|
57
|
+
}
|
|
58
|
+
if (!name.startsWith('idx_')) {
|
|
59
|
+
name = 'idx_' + name;
|
|
60
|
+
}
|
|
61
|
+
return name;
|
|
62
|
+
}
|
|
38
63
|
/**
|
|
39
64
|
* Fetch urn from doc as doc._urn
|
|
40
65
|
* */
|
|
@@ -107,17 +132,16 @@ class CbRepo {
|
|
|
107
132
|
let sql;
|
|
108
133
|
const fields = [];
|
|
109
134
|
if (Array.isArray(p1)) {
|
|
110
|
-
|
|
111
|
-
if (common_1.$is.text(name)) {
|
|
112
|
-
name =
|
|
135
|
+
const given = p1;
|
|
136
|
+
if (!common_1.$is.text(name)) {
|
|
137
|
+
name = given.map(item => item.split('.').pop()).join('.');
|
|
113
138
|
}
|
|
139
|
+
fields.push(...given.map(f => this.cb.f(f)));
|
|
114
140
|
}
|
|
115
141
|
else {
|
|
116
142
|
fields.push(p1);
|
|
117
143
|
}
|
|
118
|
-
|
|
119
|
-
name = 'idx_' + name;
|
|
120
|
-
}
|
|
144
|
+
name = this._indexName(name);
|
|
121
145
|
sql = `CREATE INDEX ${this.cb.f(name)} ON ${this.fullPath} (${fields.join(', ')})`;
|
|
122
146
|
yield this.cb.one(this.def, sql, { name: `${this.path}.index`, ignoredErrors: [couchbase_1.IndexExistsError] });
|
|
123
147
|
});
|