@samet-it/be-couchbase-common 1.0.11 → 1.0.13
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.
|
@@ -119,7 +119,29 @@ let CbAdapterService = class CbAdapterService {
|
|
|
119
119
|
return this.value(value);
|
|
120
120
|
}
|
|
121
121
|
value(value) {
|
|
122
|
-
|
|
122
|
+
var _a;
|
|
123
|
+
switch (typeof value) {
|
|
124
|
+
case "string":
|
|
125
|
+
return `"${value}"`;
|
|
126
|
+
case "number":
|
|
127
|
+
return `${value}`;
|
|
128
|
+
case "boolean":
|
|
129
|
+
return value ? `true` : 'false';
|
|
130
|
+
case "object":
|
|
131
|
+
if (value) {
|
|
132
|
+
return common_2.$dev.secureJson(value);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return 'null';
|
|
136
|
+
}
|
|
137
|
+
case "bigint":
|
|
138
|
+
return `"${value.toString(10)}"`;
|
|
139
|
+
case "symbol":
|
|
140
|
+
return `"${value.description}"`;
|
|
141
|
+
case "function":
|
|
142
|
+
return `"${(_a = value.name) !== null && _a !== void 0 ? _a : '~fn~'}[${value.length}]()"`;
|
|
143
|
+
}
|
|
144
|
+
return 'null';
|
|
123
145
|
}
|
|
124
146
|
/** {@inheritDoc} */
|
|
125
147
|
flatten(result) {
|
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,34 @@ 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
|
+
if (name.length > 30) {
|
|
62
|
+
name = name.substring(0, 30);
|
|
63
|
+
}
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
38
66
|
/**
|
|
39
67
|
* Fetch urn from doc as doc._urn
|
|
40
68
|
* */
|
|
@@ -107,17 +135,17 @@ class CbRepo {
|
|
|
107
135
|
let sql;
|
|
108
136
|
const fields = [];
|
|
109
137
|
if (Array.isArray(p1)) {
|
|
110
|
-
|
|
111
|
-
if (common_1.$is.text(name)) {
|
|
112
|
-
name =
|
|
138
|
+
const given = p1;
|
|
139
|
+
if (!common_1.$is.text(name)) {
|
|
140
|
+
name = given.map(item => item.split('.').pop()).join('.');
|
|
113
141
|
}
|
|
142
|
+
fields.push(...given.map(f => this.cb.f(f)));
|
|
114
143
|
}
|
|
115
144
|
else {
|
|
116
145
|
fields.push(p1);
|
|
146
|
+
name = p1;
|
|
117
147
|
}
|
|
118
|
-
|
|
119
|
-
name = 'idx_' + name;
|
|
120
|
-
}
|
|
148
|
+
name = this._indexName(name);
|
|
121
149
|
sql = `CREATE INDEX ${this.cb.f(name)} ON ${this.fullPath} (${fields.join(', ')})`;
|
|
122
150
|
yield this.cb.one(this.def, sql, { name: `${this.path}.index`, ignoredErrors: [couchbase_1.IndexExistsError] });
|
|
123
151
|
});
|