@samet-it/be-couchbase-common 1.1.8 → 1.1.9

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.
@@ -16,7 +16,7 @@ class CbDirectConnection extends cb_connection_1.CbConnection {
16
16
  * */
17
17
  constructor(opt) {
18
18
  super(opt);
19
- this.logger = be_base_common_1.logger.of(`CbConnection${(opt === null || opt === void 0 ? void 0 : opt.name) ? '#' + (opt === null || opt === void 0 ? void 0 : opt.name) : ''}`);
19
+ this.logger = be_base_common_1.logger.create(`CbConnection${(opt === null || opt === void 0 ? void 0 : opt.name) ? '#' + (opt === null || opt === void 0 ? void 0 : opt.name) : ''}`);
20
20
  }
21
21
  /** @inheritDoc */
22
22
  newRepo(opt) {
@@ -1,12 +1,46 @@
1
- import type { QueryResult, QueryMetaData } from 'couchbase';
2
- import { type IgnoreFieldsByType, type ReplaceType } from "@leyyo/common";
3
- import { DbConnection, type DbLines } from "@samet-it/be-db-common";
4
- import type { CbConnectionLike, CbConnOpt, CbExecOpt, CbConnProps, CbRepoLink } from "./index.types";
5
- import type { DbQueryResultMore, DbQueryResultOne } from "@samet-it/be-db-common";
1
+ import type { Cluster } from 'couchbase';
2
+ import { DbConnection } from "@samet-it/be-db-common";
3
+ import type { CbConnectionLike, CbConnOpt, CbConnProps } from "./index.types";
6
4
  /**
7
5
  * Couchbase connection abstract class
8
6
  * */
9
- export declare abstract class CbConnection extends DbConnection<CbRepoLink, QueryMetaData, CbExecOpt> implements CbConnectionLike {
7
+ export declare abstract class CbConnection extends DbConnection implements CbConnectionLike {
8
+ /**
9
+ * Base/starting/min delay for connection
10
+ *
11
+ * @type {number} - as seconds
12
+ * */
13
+ private static readonly CONN_BASE_DELAY;
14
+ /**
15
+ * Last/max delay for connection
16
+ *
17
+ * @type {number} - as seconds
18
+ * */
19
+ private static readonly CONN_MAX_DELAY;
20
+ /**
21
+ * Try count
22
+ *
23
+ * @type {number} - times
24
+ * */
25
+ private static readonly CONN_TRY_COUNT;
26
+ /**
27
+ * Base/starting/min delay for ping
28
+ *
29
+ * @type {number} - as seconds
30
+ * */
31
+ private static readonly PING_BASE_DELAY;
32
+ /**
33
+ * Last/max delay ping
34
+ *
35
+ * @type {number} - as seconds
36
+ * */
37
+ private static readonly PING_MAX_DELAY;
38
+ /**
39
+ * Try count
40
+ *
41
+ * @type {number} - times
42
+ * */
43
+ private static readonly PING_TRY_COUNT;
10
44
  /** {@inheritDoc} */
11
45
  protected _props: CbConnProps;
12
46
  /**
@@ -19,22 +53,16 @@ export declare abstract class CbConnection extends DbConnection<CbRepoLink, Quer
19
53
  * Read configuration by variant
20
54
  * */
21
55
  protected _readEnv(): void;
56
+ protected get _connectionDelay(): number;
57
+ protected get _pingDelay(): number;
22
58
  /** {@inheritDoc} */
23
59
  get props(): Readonly<CbConnProps>;
24
60
  /** {@inheritDoc} */
25
- field(field: string): string;
26
- /** {@inheritDoc} */
27
- value(value: unknown): string;
28
- /** {@inheritDoc} */
29
- flatten<T>(result: QueryResult<T>): Array<T>;
30
- /** {@inheritDoc} */
31
- castDates<T>(given: ReplaceType<T, Date, string> | T, ...fields: Array<IgnoreFieldsByType<T, Date>>): void;
32
- /** {@inheritDoc} */
33
- castDatesForList<T>(given: Array<ReplaceType<T, Date, string> | T>, ...fields: Array<IgnoreFieldsByType<T, Date>>): void;
61
+ get bucketName(): string;
34
62
  /** {@inheritDoc} */
35
- more<T>(link: CbRepoLink, lines: string | DbLines, p1?: string | CbExecOpt): Promise<DbQueryResultMore<T, QueryMetaData>>;
63
+ get scopeName(): string;
36
64
  /** {@inheritDoc} */
37
- one<T>(link: CbRepoLink, lines: string | DbLines, p1?: string | CbExecOpt): Promise<DbQueryResultOne<T, QueryMetaData>>;
65
+ get cluster(): Cluster;
38
66
  /** {@inheritDoc} */
39
67
  connect(): Promise<boolean>;
40
68
  /** {@inheritDoc} */
@@ -45,10 +45,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.CbConnection = void 0;
46
46
  const couchbase = __importStar(require("couchbase"));
47
47
  const config_1 = require("../config");
48
- const common_1 = require("@leyyo/common");
49
- const filter_1 = require("../filter");
50
48
  const be_db_common_1 = require("@samet-it/be-db-common");
51
- const type_1 = require("@leyyo/type");
49
+ const be_base_common_1 = require("@samet-it/be-base-common");
52
50
  /**
53
51
  * Couchbase connection abstract class
54
52
  * */
@@ -61,7 +59,6 @@ class CbConnection extends be_db_common_1.DbConnection {
61
59
  * */
62
60
  constructor(opt) {
63
61
  super(opt);
64
- filter_1.cbFilterUtil.$set(this);
65
62
  this._readEnv();
66
63
  }
67
64
  // region protected-method
@@ -71,10 +68,11 @@ class CbConnection extends be_db_common_1.DbConnection {
71
68
  _readEnv() {
72
69
  var _a, _b, _c, _d, _e, _f, _g, _h;
73
70
  const { _props: props } = this;
74
- let env = config_1.couchbaseCommonConfig.valueShort;
71
+ let env = config_1.couchbaseCommonConfig.value;
75
72
  if (props.envVariant) {
76
- env = config_1.couchbaseCommonConfig.configure.getVariation(props.envVariant).valueShort;
73
+ env = config_1.couchbaseCommonConfig.configure.getVariation(props.envVariant).value;
77
74
  }
75
+ props.isEnabled = props.isEnabled == env.ENABLED;
78
76
  props.protocol = (_a = props.protocol) !== null && _a !== void 0 ? _a : env.PROTOCOL;
79
77
  props.host = (_b = props.host) !== null && _b !== void 0 ? _b : env.HOST;
80
78
  props.port = (_c = props.port) !== null && _c !== void 0 ? _c : env.PORT;
@@ -84,182 +82,77 @@ class CbConnection extends be_db_common_1.DbConnection {
84
82
  props.scopeName = (_g = props.scopeName) !== null && _g !== void 0 ? _g : env.SCOPE;
85
83
  props.createIndices = (_h = props.createIndices) !== null && _h !== void 0 ? _h : env.CREATE_INDICES;
86
84
  }
85
+ get _connectionDelay() {
86
+ return this._delayWithJitter(this._props.connectTryCount, CbConnection.CONN_BASE_DELAY, CbConnection.CONN_MAX_DELAY);
87
+ }
88
+ get _pingDelay() {
89
+ return this._delayWithJitter(this._props.pingTryCount, CbConnection.PING_BASE_DELAY, CbConnection.PING_MAX_DELAY);
90
+ }
87
91
  // endregion protected-method
88
92
  // region getter
89
93
  /** {@inheritDoc} */
90
94
  get props() {
91
95
  return this._props;
92
96
  }
93
- // endregion getter
94
- // region field-value
95
97
  /** {@inheritDoc} */
96
- field(field) {
97
- field = field.trim();
98
- if (field.includes('.')) {
99
- return field.split('.').map(part => this.field(part)).join('.');
100
- }
101
- return field.startsWith('`') ? field : `\`${field}\``;
98
+ get bucketName() {
99
+ return this._props.bucketName;
102
100
  }
103
101
  /** {@inheritDoc} */
104
- value(value) {
105
- var _a;
106
- switch (typeof value) {
107
- case "string":
108
- return JSON.stringify(value);
109
- case "number":
110
- return `${value}`;
111
- case "boolean":
112
- return value ? `true` : 'false';
113
- case "object":
114
- if (value) {
115
- return (0, common_1.secureJson)(value);
116
- }
117
- else {
118
- return 'null';
119
- }
120
- case "bigint":
121
- return `"${value.toString(10)}"`;
122
- case "symbol":
123
- return JSON.stringify(value.description);
124
- case "function":
125
- return JSON.stringify(`${(_a = value.name) !== null && _a !== void 0 ? _a : '~fn~'}[${value.length}]()`);
126
- }
127
- return 'null';
102
+ get scopeName() {
103
+ return this._props.scopeName;
128
104
  }
129
105
  /** {@inheritDoc} */
130
- flatten(result) {
131
- if (result && Array.isArray(result.rows) && (result.rows.length > 0)) {
132
- return result.rows;
133
- }
134
- return [];
135
- }
136
- // endregion field-value
137
- // region transcoders
138
- /** {@inheritDoc} */
139
- castDates(given, ...fields) {
140
- if (fields.length < 1) {
141
- return;
142
- }
143
- if (!given || typeof given !== 'object' && Array.isArray(given)) {
144
- return;
145
- }
146
- const doc = given;
147
- fields.forEach(field => {
148
- const val = doc[field];
149
- if (typeof val === 'string' || (typeof val === 'number' && val > 0 && Number.isInteger(val))) {
150
- doc[field] = new Date(val);
151
- }
152
- });
153
- }
154
- /** {@inheritDoc} */
155
- castDatesForList(given, ...fields) {
156
- if (fields.length < 1) {
157
- return;
158
- }
159
- if (!given || !Array.isArray(given) || given.length < 1) {
160
- return;
161
- }
162
- const arr = given;
163
- arr.forEach(item => this.castDates(item, ...fields));
164
- }
165
- // endregion transcoders
166
- // region query
167
- /** {@inheritDoc} */
168
- more(link, lines, p1) {
169
- return __awaiter(this, void 0, void 0, function* () {
170
- if (!this._props.enabled) {
171
- return { success: true, rows: [] };
172
- }
173
- const opt = this.buildOpt(p1);
174
- const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
175
- if (opt.printSql) {
176
- this.logger.log(`${link.path} > SQL${opt.name}`, sql);
177
- }
178
- try {
179
- const result = yield link.scope.query(sql, opt);
180
- return {
181
- success: true,
182
- rows: result.rows,
183
- meta: result.meta,
184
- };
185
- }
186
- catch (err) {
187
- this.checkError(err, Object.assign(Object.assign({}, opt), { sql }));
188
- return {
189
- success: false,
190
- rows: [],
191
- error: err,
192
- };
193
- }
194
- });
195
- }
196
- /** {@inheritDoc} */
197
- one(link, lines, p1) {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- if (!this._props.enabled) {
200
- return { success: true, row: undefined };
201
- }
202
- const opt = this.buildOpt(p1);
203
- const sql = (0, type_1.isObjectValid)(lines) ? lines.end() : lines;
204
- if (opt.printSql) {
205
- this.logger.log(`${link.path} > SQL${opt.name}`, sql);
206
- }
207
- try {
208
- const result = yield link.scope.query(sql, opt);
209
- return {
210
- success: true,
211
- row: (Array.isArray(result.rows) && result.rows.length > 0) ? result.rows[0] : undefined,
212
- meta: result.meta,
213
- };
214
- }
215
- catch (err) {
216
- this.checkError(err, Object.assign(Object.assign({}, opt), { sql }));
217
- return {
218
- success: false,
219
- row: undefined,
220
- error: err,
221
- };
222
- }
223
- });
106
+ get cluster() {
107
+ return this._props.cluster;
224
108
  }
225
- // endregion query
109
+ // endregion getter
226
110
  // region connect
227
111
  /** {@inheritDoc} */
228
112
  connect() {
229
113
  return __awaiter(this, void 0, void 0, function* () {
230
- if (!this._props.enabled) {
114
+ const { _props: props } = this;
115
+ if (!this.isEnabled) {
231
116
  return false;
232
117
  }
233
- const { _props: props } = this;
234
- if (props.isConnected) {
118
+ if (this.isConnected) {
235
119
  return true;
236
120
  }
121
+ if (this._props.connectTryCount > CbConnection.CONN_TRY_COUNT) {
122
+ const err = new be_db_common_1.DbError('Maximum try county', { tryCount: this._props.connectTryCount });
123
+ this.logger.error(be_base_common_1.errorHandler.common.logText(err, 'connect'));
124
+ return false;
125
+ }
237
126
  try {
238
127
  props.cluster = yield couchbase.connect(`${props.protocol}://${props.host}`, {
239
128
  username: props.username,
240
129
  password: props.password,
241
130
  });
242
131
  props.isConnected = true;
243
- this.logger.log('Connected');
132
+ props.connectTryCount = 0;
133
+ this._triggerOnCase('connected', this._onConnected, false);
134
+ if (props.isFirst === undefined) {
135
+ this._triggerOnCase('first-connected', this._onFirstConnected, true);
136
+ props.isFirst = false;
137
+ }
138
+ // clear stopped ping
139
+ if (this._props.pingTryCount > CbConnection.PING_TRY_COUNT) {
140
+ this._props.pingTryCount = 0;
141
+ setTimeout(() => this.ping(true).then(), 30000);
142
+ }
143
+ props.isConnected = true;
144
+ this.logger.info('Connected');
244
145
  setTimeout(() => this.ping(true).then(), 30000);
245
146
  }
246
147
  catch (e) {
247
- this.checkError(e, { name: 'connection' });
248
- throw e;
249
- }
250
- if (props.isFirst === undefined) {
251
- if (this._onFirstConnected.length > 0) {
252
- yield Promise.all(this._onFirstConnected);
253
- this._onFirstConnected = [];
148
+ this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'connection', this._props.connectTryCount));
149
+ props.connectTryCount++;
150
+ const old = this.isConnected;
151
+ props.isConnected = false;
152
+ if (old) {
153
+ this._triggerOnCase('disconnected', this._onDisconnected, false);
254
154
  }
255
- props.isFirst = false;
256
- }
257
- if (this._onConnected.length > 0) {
258
- this._onConnected.forEach(fn => {
259
- fn().then().catch(e => {
260
- this.logger.error(`OnConnected <${e.name}> ${e.message}`);
261
- });
262
- });
155
+ setTimeout(() => this.connect().then(), this._connectionDelay);
263
156
  }
264
157
  return true;
265
158
  });
@@ -267,17 +160,27 @@ class CbConnection extends be_db_common_1.DbConnection {
267
160
  /** {@inheritDoc} */
268
161
  ping(next) {
269
162
  return __awaiter(this, void 0, void 0, function* () {
270
- if (!this._props.enabled) {
163
+ if (!this.isEnabled) {
271
164
  return false;
272
165
  }
273
- const { _props: props } = this;
274
- let result = false;
275
- try {
276
- yield this.exec(props.cluster.ping(), { name: 'ping' });
277
- result = true;
166
+ if (this._props.pingTryCount > CbConnection.PING_TRY_COUNT) {
167
+ const err = new be_db_common_1.DbError('Maximum try county', { tryCount: this._props.pingTryCount });
168
+ this.logger.error(be_base_common_1.errorHandler.common.logText(err, 'connect'));
169
+ return false;
278
170
  }
279
- catch (err) {
280
- this.checkError(err, { name: 'ping', silent: true });
171
+ let result = false;
172
+ if (this.isConnected) {
173
+ try {
174
+ yield this.cluster.ping();
175
+ this._props.pingTryCount = 0;
176
+ result = true;
177
+ }
178
+ catch (err) {
179
+ this._props.pingTryCount++;
180
+ this.logger.warn(be_base_common_1.errorHandler.common.logText(err, 'ping', this._props.pingTryCount));
181
+ setTimeout(() => this.ping(true).then(), this._pingDelay);
182
+ next = false;
183
+ }
281
184
  }
282
185
  if (next) {
283
186
  setTimeout(() => this.ping(true).then(), 30000);
@@ -287,3 +190,40 @@ class CbConnection extends be_db_common_1.DbConnection {
287
190
  }
288
191
  }
289
192
  exports.CbConnection = CbConnection;
193
+ // region protected-property
194
+ /**
195
+ * Base/starting/min delay for connection
196
+ *
197
+ * @type {number} - as seconds
198
+ * */
199
+ CbConnection.CONN_BASE_DELAY = 500; // 0.5 sec
200
+ /**
201
+ * Last/max delay for connection
202
+ *
203
+ * @type {number} - as seconds
204
+ * */
205
+ CbConnection.CONN_MAX_DELAY = 1000 * 60 * 60; // 60 minutes
206
+ /**
207
+ * Try count
208
+ *
209
+ * @type {number} - times
210
+ * */
211
+ CbConnection.CONN_TRY_COUNT = 100; // 100 times
212
+ /**
213
+ * Base/starting/min delay for ping
214
+ *
215
+ * @type {number} - as seconds
216
+ * */
217
+ CbConnection.PING_BASE_DELAY = 200; // 0.2 sec
218
+ /**
219
+ * Last/max delay ping
220
+ *
221
+ * @type {number} - as seconds
222
+ * */
223
+ CbConnection.PING_MAX_DELAY = 1000 * 60 * 10; // 10 minutes
224
+ /**
225
+ * Try count
226
+ *
227
+ * @type {number} - times
228
+ * */
229
+ CbConnection.PING_TRY_COUNT = 100; // 100 times
@@ -1,26 +1,26 @@
1
- import type { Cluster, QueryMetaData, QueryOptions, QueryResult, Scope } from "couchbase";
1
+ import type { Cluster } from "couchbase";
2
2
  import type { IgnoreFieldsByType, KeyValue, ReplaceType, StrKey } from "@leyyo/common";
3
3
  import type { CbRepoDirectOpt, CbRepoLike } from "../repo";
4
- import type { DbConnectionLike, DbConnOpt, DbConnProps, DbExecOpt, DbRepoLink } from "@samet-it/be-db-common";
4
+ import type { DbConnDirectOpt, DbConnectionLike, DbConnOpt, DbConnProps } from "@samet-it/be-db-common";
5
5
  import type { DefDims, Entity, UrnDocLike, Pair, Portion, View, UrnDef } from "@samet-it/be-base-common";
6
6
  /**
7
7
  * Couchbase connection interface
8
8
  * */
9
- export interface CbConnectionLike extends DbConnectionLike<CbRepoLink, QueryMetaData, CbExecOpt> {
9
+ export interface CbConnectionLike extends DbConnectionLike {
10
10
  /** @inheritDoc */
11
11
  get props(): Readonly<CbConnProps>;
12
12
  /**
13
- * Flatten query result to rows
13
+ * Shortcut to {@link CbConnOpt#bucketName}
14
14
  * */
15
- flatten<T>(result: QueryResult<T>): Array<T>;
15
+ get bucketName(): string;
16
16
  /**
17
- * Cast dates
17
+ * Shortcut to {@link CbConnOpt#scopeName}
18
18
  * */
19
- castDates<T>(given: ReplaceType<T, Date, string> | T, ...fields: Array<IgnoreFieldsByType<T, Date>>): void;
19
+ get scopeName(): string;
20
20
  /**
21
- * Cast dates for an array
21
+ * Shortcut to {@link CbConnProps#cluster}
22
22
  * */
23
- castDatesForList<T>(given: Array<ReplaceType<T, Date, string> | T>, ...fields: Array<IgnoreFieldsByType<T, Date>>): void;
23
+ get cluster(): Cluster;
24
24
  }
25
25
  /**
26
26
  * Couchbase connection option interface
@@ -45,17 +45,6 @@ export interface CbConnOpt extends DbConnOpt {
45
45
  * */
46
46
  createIndices?: boolean;
47
47
  }
48
- /**
49
- * Couchbase direct connection option interface
50
- * */
51
- export interface CbDirectConnOpt extends CbConnOpt {
52
- /**
53
- * Logger name
54
- *
55
- * @type {string}
56
- * */
57
- name?: string;
58
- }
59
48
  /**
60
49
  * Couchbase connection props interface
61
50
  * */
@@ -68,9 +57,10 @@ export interface CbConnProps extends CbConnOpt, DbConnProps {
68
57
  cluster: Cluster;
69
58
  }
70
59
  /**
71
- * Couchbase query option
60
+ * Couchbase direct connection option interface
72
61
  * */
73
- export type CbExecOpt = DbExecOpt & QueryOptions;
62
+ export interface CbDirectConnOpt extends CbConnOpt, DbConnDirectOpt {
63
+ }
74
64
  /**
75
65
  * Direct connection to use outside dependency injection
76
66
  * */
@@ -94,15 +84,5 @@ export interface CbDirectConnectionLike extends CbConnectionLike {
94
84
  * */
95
85
  newRepo<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef, VIEW extends View<ID> = ENT, PAIR extends Pair<ID> = Pair<ID>, PORTION extends Portion<ID> = Portion<ID>, KEYS extends string = StrKey<ENT>, DIMS extends DefDims = DefDims, R = unknown>(opt: CbRepoDirectOpt<ENT, ID, URN, DIMS, R>): CbRepoLike<ENT, ID, URN, VIEW, PAIR, PORTION, KEYS, DIMS>;
96
86
  }
97
- export type CbIgnoreDate<T> = CbReplaceType<T, Date, string>;
98
- export type CbIgnoreDateKeys<T> = CbIgnoreFields<T, Date>;
99
- type CbIgnoreFields<T, I> = {
100
- [K in keyof T]: T[K] extends I ? K : never;
101
- }[keyof T];
102
- type CbReplaceType<T, O, N> = {
103
- [P in keyof T]: T[P] extends O ? N : T[P];
104
- };
105
- export interface CbRepoLink extends DbRepoLink {
106
- scope: Scope;
107
- }
108
- export {};
87
+ export type CbIgnoreDate<T> = ReplaceType<T, Date, string>;
88
+ export type CbIgnoreDateKeys<T> = IgnoreFieldsByType<T, Date>;
@@ -53,10 +53,10 @@ class CbFilterUtilImpl {
53
53
  if (Array.isArray(items) && items.length > 0) {
54
54
  items = items.map(v => (v instanceof Date) ? v.toISOString() : v);
55
55
  if (items.length === 1) {
56
- return `${this._where(opt)} ${this.cb.f(field)} = ${this.cb.v(items[0])}`;
56
+ return `${this._where(opt)} ${this.repo.f(field)} = ${this.repo.v(items[0])}`;
57
57
  }
58
58
  else {
59
- return `${this._where(opt)} ${this.cb.f(field)} IN ${this.cb.v(items[0])}`;
59
+ return `${this._where(opt)} ${this.repo.f(field)} IN ${this.repo.v(items[0])}`;
60
60
  }
61
61
  }
62
62
  return undefined;
@@ -64,7 +64,7 @@ class CbFilterUtilImpl {
64
64
  /** @inheritDoc */
65
65
  sqlBool(opt, field, value) {
66
66
  if (typeof value === 'boolean') {
67
- return `${this._where(opt)} ${this.cb.f(field)} = ${value ? 'true' : 'false'}`;
67
+ return `${this._where(opt)} ${this.repo.f(field)} = ${value ? 'true' : 'false'}`;
68
68
  }
69
69
  return undefined;
70
70
  }
@@ -73,20 +73,20 @@ class CbFilterUtilImpl {
73
73
  if (Array.isArray(value) && value.length > 0) {
74
74
  const [first, last] = value.map(v => (v instanceof Date) ? v.toISOString() : v);
75
75
  if (first !== undefined && last !== undefined) {
76
- return `${this._where(opt)} ${this.cb.f(field)} BETWEEN ${this.cb.v(first)} AND ${this.cb.v(last)}`;
76
+ return `${this._where(opt)} ${this.repo.f(field)} BETWEEN ${this.repo.v(first)} AND ${this.repo.v(last)}`;
77
77
  }
78
78
  else if (first !== undefined && last === undefined) {
79
- return `${this._where(opt)} ${this.cb.f(field)} >= ${this.cb.v(first)}`;
79
+ return `${this._where(opt)} ${this.repo.f(field)} >= ${this.repo.v(first)}`;
80
80
  }
81
81
  else if (first === undefined && last !== undefined) {
82
- return `${this._where(opt)} ${this.cb.f(field)} <= ${this.cb.v(last)}`;
82
+ return `${this._where(opt)} ${this.repo.f(field)} <= ${this.repo.v(last)}`;
83
83
  }
84
84
  }
85
85
  return undefined;
86
86
  }
87
- $set(cb) {
88
- if (!this.cb) {
89
- this.cb = cb;
87
+ $set(repo) {
88
+ if (!this.repo) {
89
+ this.repo = repo;
90
90
  }
91
91
  }
92
92
  }
@@ -1,5 +1,6 @@
1
- import type { CbConnectionLike } from "../connection";
2
1
  import type { DbLines } from "@samet-it/be-db-common";
2
+ import { CbRepoLike } from "../repo";
3
+ import { Entity } from "@samet-it/be-base-common";
3
4
  export type FilterCastLambda<T> = (v: unknown) => T;
4
5
  export interface CbFilterUtil {
5
6
  /**
@@ -26,7 +27,7 @@ export interface CbFilterUtil {
26
27
  * Builds a sql for between
27
28
  * */
28
29
  sqlBetween(opt: CbFilterUtilWhereOpt, field: string, value: [unknown, unknown]): string | undefined;
29
- $set(cb: CbConnectionLike): void;
30
+ $set(repo: CbRepoLike<Entity>): void;
30
31
  }
31
32
  export interface CbFilterUtilWhereOpt {
32
33
  lines: DbLines;
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CbDirectRepo = void 0;
13
4
  const cb_repo_1 = require("./cb.repo");
@@ -33,21 +24,10 @@ class CbDirectRepo extends cb_repo_1.CbRepo {
33
24
  * @param {CbRepoDirectOpt} opt - options
34
25
  * */
35
26
  constructor(conn, opt) {
27
+ var _a;
36
28
  super(conn, opt);
37
- if (opt) {
38
- if (!opt.name) {
39
- opt.name = this._props.urnPrefix;
40
- }
41
- if (typeof opt.toUrnTuple === 'function') {
42
- this.$toUrnTuple = opt.toUrnTuple;
43
- }
44
- if (typeof opt.toDim === 'function') {
45
- this.$toDim = (doc, dim) => __awaiter(this, void 0, void 0, function* () {
46
- return (yield opt.toDim(doc, dim));
47
- });
48
- }
49
- }
50
- this.logger = be_base_common_1.logger.of(`CbRepo${(opt === null || opt === void 0 ? void 0 : opt.name) ? '#' + (opt === null || opt === void 0 ? void 0 : opt.name) : ''}`);
29
+ const logName = (_a = opt === null || opt === void 0 ? void 0 : opt.name) !== null && _a !== void 0 ? _a : this._props.urnPrefix;
30
+ this.logger = be_base_common_1.logger.create(`CbRepo${logName ? '#' + logName : ''}`);
51
31
  }
52
32
  }
53
33
  exports.CbDirectRepo = CbDirectRepo;