@syncbridge/sqb 0.4.1

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (c) 2025 Panates (Panates Teknoloji Yatirim A.S.). All rights reserved.
2
+
3
+ This software and associated documentation files (the "Software") are
4
+ the proprietary property of Panates and are protected by copyright laws
5
+ and international copyright treaties.
6
+
7
+ Unauthorized copying, distribution, modification, reverse engineering,
8
+ or use of this software, in whole or in part, is strictly prohibited
9
+ without the express written permission of Panates.
10
+
11
+ This Software is provided solely for use in accordance with the terms
12
+ of a valid license agreement. Any unauthorized use may result in
13
+ civil and/or criminal penalties.
14
+
15
+ For licensing inquiries, please contact: info@panates.com
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # SyncBridge ICU Connectors
@@ -0,0 +1,35 @@
1
+ import '@sqb/oracle';
2
+ import '@sqb/postgres';
3
+ import { SqbClient } from '@sqb/connect';
4
+ import { ComponentBase } from '@syncbridge/common';
5
+ import { SqbClientPoolVariables, SqbClientVariables } from './sqb-client.variables.js';
6
+ /**
7
+ * SqbClient component
8
+ */
9
+ export declare class SqbClientComponent<TEvents extends SqbClientComponent.Events = SqbClientComponent.Events> extends ComponentBase<TEvents> {
10
+ protected _livenessTimer?: NodeJS.Timeout;
11
+ protected client: SqbClient;
12
+ values: SqbClientVariables;
13
+ protected _init(): Promise<void>;
14
+ protected _start(abortSignal: AbortSignal): Promise<void>;
15
+ protected _stop(): Promise<void>;
16
+ protected _terminate(): Promise<void>;
17
+ getClient(): SqbClient;
18
+ /**
19
+ * Test db connection health every 5 secs
20
+ * @protected
21
+ */
22
+ protected _liveness(): void;
23
+ protected _resetLiveness(): void;
24
+ }
25
+ /**
26
+ * @namespace
27
+ */
28
+ export declare namespace SqbClientComponent {
29
+ interface Events extends ComponentBase.Events {
30
+ }
31
+ const Variables: typeof SqbClientVariables;
32
+ type Variables = SqbClientVariables;
33
+ const PoolVariables: typeof SqbClientPoolVariables;
34
+ type PoolVariables = SqbClientPoolVariables;
35
+ }
@@ -0,0 +1,129 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@sqb/oracle';
3
+ import '@sqb/postgres';
4
+ import { clearTimeout } from 'node:timers';
5
+ import { SqbClient, SQBError } from '@sqb/connect';
6
+ import { Component, ComponentBase, ServiceStatus } from '@syncbridge/common';
7
+ import colors from 'ansi-colors';
8
+ import { SqbClientPoolVariables, SqbClientVariables, } from './sqb-client.variables.js';
9
+ /**
10
+ * SqbClient component
11
+ */
12
+ let SqbClientComponent = class SqbClientComponent extends ComponentBase {
13
+ _livenessTimer;
14
+ async _init() {
15
+ await super._init();
16
+ this.client = new SqbClient({
17
+ dialect: this.values.dialect,
18
+ host: this.values.host,
19
+ port: this.values.port,
20
+ user: this.values.username,
21
+ password: this.values.password,
22
+ database: this.values.database,
23
+ schema: this.values.schema,
24
+ name: this.values.applicationName,
25
+ pool: this.values.pool,
26
+ });
27
+ this.client.on('error', (err) => {
28
+ if (err instanceof SQBError && this.logger?.level === 'debug') {
29
+ const query = err.request?.sql || String(err.query);
30
+ this.logger.debug(err.message +
31
+ `\nSQL: ${colors.whiteBright(query)}\n${err.request?.params
32
+ ? 'Params: \n ' +
33
+ Object.entries(err.request.params)
34
+ .map(([key, value]) => `${colors.yellow(key)}: ${colors.yellowBright(String(value))}`)
35
+ .join(`\n `)
36
+ : ''}`, {
37
+ query,
38
+ dialect: err.request?.dialect,
39
+ params: err.request?.params,
40
+ });
41
+ }
42
+ });
43
+ this.client.on('acquire', () => {
44
+ this._resetLiveness();
45
+ });
46
+ }
47
+ async _start(abortSignal) {
48
+ await super._start(abortSignal);
49
+ const testConnection = () => {
50
+ if (!(this.status === ServiceStatus.started ||
51
+ this.status === ServiceStatus.unhealthy))
52
+ return;
53
+ this.logger?.trace(`Testing database connection`);
54
+ return this.client
55
+ .test()
56
+ .then(() => {
57
+ this.logger?.trace(`Database connection success`);
58
+ this.setStatus(ServiceStatus.started);
59
+ })
60
+ .catch(err => {
61
+ const timer = setTimeout(testConnection, 5000).unref();
62
+ abortSignal.addEventListener('abort', () => clearTimeout(timer));
63
+ const msg = `Database connection failed. ${err.message}`;
64
+ this.logger?.error(msg);
65
+ this.setStatus(ServiceStatus.unhealthy, msg);
66
+ });
67
+ };
68
+ await testConnection();
69
+ }
70
+ async _stop() {
71
+ clearTimeout(this._livenessTimer);
72
+ await this.client.close();
73
+ }
74
+ async _terminate() {
75
+ await this.client.close(0);
76
+ }
77
+ getClient() {
78
+ if (!this.client)
79
+ throw new Error('SqbClient component is not initialized');
80
+ return this.client;
81
+ }
82
+ /**
83
+ * Test db connection health every 5 secs
84
+ * @protected
85
+ */
86
+ _liveness() {
87
+ this.client
88
+ .test()
89
+ .then(() => {
90
+ this.setStatus(ServiceStatus.started);
91
+ })
92
+ .catch(err => {
93
+ if (this.status !== ServiceStatus.unhealthy) {
94
+ const msg = `Database connection failed. ${err.message}`;
95
+ this.logger?.error(msg);
96
+ this.setStatus(ServiceStatus.unhealthy, msg);
97
+ }
98
+ })
99
+ .finally(() => {
100
+ this._resetLiveness();
101
+ });
102
+ }
103
+ _resetLiveness() {
104
+ clearTimeout(this._livenessTimer);
105
+ this._livenessTimer = setTimeout(() => {
106
+ this._liveness();
107
+ }, 5000).unref();
108
+ }
109
+ };
110
+ __decorate([
111
+ Component.UseVariables(),
112
+ __metadata("design:type", SqbClientVariables)
113
+ ], SqbClientComponent.prototype, "values", void 0);
114
+ SqbClientComponent = __decorate([
115
+ Component({
116
+ className: 'SqbClient',
117
+ displayName: 'SqbClient',
118
+ description: 'Database Connection Client',
119
+ tags: ['io', 'stream'],
120
+ })
121
+ ], SqbClientComponent);
122
+ export { SqbClientComponent };
123
+ /**
124
+ * @namespace
125
+ */
126
+ (function (SqbClientComponent) {
127
+ SqbClientComponent.Variables = SqbClientVariables;
128
+ SqbClientComponent.PoolVariables = SqbClientPoolVariables;
129
+ })(SqbClientComponent || (SqbClientComponent = {}));
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Pool variables
3
+ */
4
+ export declare class SqbClientPoolVariables {
5
+ acquireMaxRetries: number;
6
+ acquireRetryWait: number;
7
+ acquireTimeoutMillis: number;
8
+ fifo: boolean;
9
+ idleTimeoutMillis: number;
10
+ houseKeepInterval: number;
11
+ min: number;
12
+ minIdle: number;
13
+ max: number;
14
+ maxQueue: number;
15
+ }
16
+ /**
17
+ * Variables
18
+ */
19
+ export declare class SqbClientVariables {
20
+ dialect: string;
21
+ host?: string;
22
+ port?: number;
23
+ username?: string;
24
+ password?: string;
25
+ database?: string;
26
+ schema?: string;
27
+ applicationName: string;
28
+ pool: SqbClientPoolVariables;
29
+ }
@@ -0,0 +1,162 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { AdapterRegistry } from '@sqb/connect';
3
+ import { DefineVariable, VariableType } from '@syncbridge/common';
4
+ /**
5
+ * Pool variables
6
+ */
7
+ export class SqbClientPoolVariables {
8
+ }
9
+ __decorate([
10
+ DefineVariable({
11
+ label: 'Acquire max retries',
12
+ description: 'Maximum number that Pool will try to create a resource before returning the error',
13
+ default: 0,
14
+ }),
15
+ __metadata("design:type", Number)
16
+ ], SqbClientPoolVariables.prototype, "acquireMaxRetries", void 0);
17
+ __decorate([
18
+ DefineVariable({
19
+ label: 'Acquire retry wait',
20
+ description: 'Time in millis that Pool will wait after each tries',
21
+ default: 2000,
22
+ }),
23
+ __metadata("design:type", Number)
24
+ ], SqbClientPoolVariables.prototype, "acquireRetryWait", void 0);
25
+ __decorate([
26
+ DefineVariable({
27
+ label: 'Acquire timeout millis',
28
+ description: 'Time in millis an acquire call will wait for a resource before timing out',
29
+ default: 0,
30
+ }),
31
+ __metadata("design:type", Number)
32
+ ], SqbClientPoolVariables.prototype, "acquireTimeoutMillis", void 0);
33
+ __decorate([
34
+ DefineVariable({
35
+ label: 'Fifo',
36
+ description: 'If true resources will be allocated first-in-first-out order. resources will be allocated last-in-first-out order',
37
+ default: true,
38
+ }),
39
+ __metadata("design:type", Boolean)
40
+ ], SqbClientPoolVariables.prototype, "fifo", void 0);
41
+ __decorate([
42
+ DefineVariable({
43
+ label: 'Idle timeout',
44
+ description: 'The minimum amount of time in millis that an resource may sit idle in the Pool',
45
+ default: 30000,
46
+ }),
47
+ __metadata("design:type", Number)
48
+ ], SqbClientPoolVariables.prototype, "idleTimeoutMillis", void 0);
49
+ __decorate([
50
+ DefineVariable({
51
+ label: 'House keep interval',
52
+ description: 'Time period in millis that Pool will make a cleanup',
53
+ default: 1000,
54
+ }),
55
+ __metadata("design:type", Number)
56
+ ], SqbClientPoolVariables.prototype, "houseKeepInterval", void 0);
57
+ __decorate([
58
+ DefineVariable({
59
+ label: 'Min',
60
+ description: 'Minimum number of resources that Pool will keep',
61
+ default: 0,
62
+ }),
63
+ __metadata("design:type", Number)
64
+ ], SqbClientPoolVariables.prototype, "min", void 0);
65
+ __decorate([
66
+ DefineVariable({
67
+ label: 'Min idle',
68
+ description: 'Minimum number of resources that Pool will keep in idle state',
69
+ default: 0,
70
+ }),
71
+ __metadata("design:type", Number)
72
+ ], SqbClientPoolVariables.prototype, "minIdle", void 0);
73
+ __decorate([
74
+ DefineVariable({
75
+ label: 'Max',
76
+ description: 'Maximum number of resources that Pool will create',
77
+ default: 30,
78
+ }),
79
+ __metadata("design:type", Number)
80
+ ], SqbClientPoolVariables.prototype, "max", void 0);
81
+ __decorate([
82
+ DefineVariable({
83
+ label: 'Max queue',
84
+ description: 'Maximum number of request that Pool will accept',
85
+ default: 1000,
86
+ }),
87
+ __metadata("design:type", Number)
88
+ ], SqbClientPoolVariables.prototype, "maxQueue", void 0);
89
+ /**
90
+ * Variables
91
+ */
92
+ export class SqbClientVariables {
93
+ }
94
+ __decorate([
95
+ DefineVariable({
96
+ type: VariableType.Enum,
97
+ label: 'Dialect',
98
+ description: 'Database dialect',
99
+ enumValues: Array.from(AdapterRegistry.items()).map(x => x.dialect),
100
+ }),
101
+ __metadata("design:type", String)
102
+ ], SqbClientVariables.prototype, "dialect", void 0);
103
+ __decorate([
104
+ DefineVariable({
105
+ label: 'Host',
106
+ description: 'Database server address or url',
107
+ }),
108
+ __metadata("design:type", String)
109
+ ], SqbClientVariables.prototype, "host", void 0);
110
+ __decorate([
111
+ DefineVariable({
112
+ label: 'Port',
113
+ description: 'Database listener port number',
114
+ minValue: 1,
115
+ maxValue: 65535,
116
+ }),
117
+ __metadata("design:type", Number)
118
+ ], SqbClientVariables.prototype, "port", void 0);
119
+ __decorate([
120
+ DefineVariable({
121
+ label: 'Username',
122
+ description: 'Database username',
123
+ }),
124
+ __metadata("design:type", String)
125
+ ], SqbClientVariables.prototype, "username", void 0);
126
+ __decorate([
127
+ DefineVariable({
128
+ label: 'Password',
129
+ description: 'Database password',
130
+ type: VariableType.Secret,
131
+ }),
132
+ __metadata("design:type", String)
133
+ ], SqbClientVariables.prototype, "password", void 0);
134
+ __decorate([
135
+ DefineVariable({
136
+ label: 'Database name',
137
+ description: 'Database name to be connected to',
138
+ }),
139
+ __metadata("design:type", String)
140
+ ], SqbClientVariables.prototype, "database", void 0);
141
+ __decorate([
142
+ DefineVariable({
143
+ label: 'Database schema',
144
+ description: 'Database schema to be connected to',
145
+ }),
146
+ __metadata("design:type", String)
147
+ ], SqbClientVariables.prototype, "schema", void 0);
148
+ __decorate([
149
+ DefineVariable({
150
+ label: 'Application Name',
151
+ description: 'Name of the application to be set to database sessions. This is used for debugging purposes',
152
+ default: 'syncbridge',
153
+ }),
154
+ __metadata("design:type", String)
155
+ ], SqbClientVariables.prototype, "applicationName", void 0);
156
+ __decorate([
157
+ DefineVariable({
158
+ label: 'Pooling',
159
+ description: 'Pooling options',
160
+ }),
161
+ __metadata("design:type", SqbClientPoolVariables)
162
+ ], SqbClientVariables.prototype, "pool", void 0);
@@ -0,0 +1 @@
1
+ export * from './components/sqb-client.component.js';
package/components.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components/sqb-client.component.js';
package/constants.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { AuthorMetadata } from '@syncbridge/common';
2
+ export declare const version = "1";
3
+ export declare const noOp: () => undefined;
4
+ export declare const panatesAuthor: AuthorMetadata;
package/constants.js ADDED
@@ -0,0 +1,7 @@
1
+ export const version = '0.4.1';
2
+ export const noOp = () => undefined;
3
+ export const panatesAuthor = {
4
+ name: 'Panates Technology AS',
5
+ email: 'info@panates.com',
6
+ url: 'https://www.panates.com',
7
+ };
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import * as components from './components.js';
2
+ export { components };
3
+ export * from './components.js';
4
+ declare const cfg: import("@syncbridge/common").IExtensionPackage;
5
+ export default cfg;
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { makeExtensionPackage } from '@syncbridge/common';
2
+ import * as components from './components.js';
3
+ export { components };
4
+ export * from './components.js';
5
+ const cfg = makeExtensionPackage({
6
+ processors: [],
7
+ components: Object.values(components),
8
+ });
9
+ export default cfg;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@syncbridge/sqb",
3
+ "version": "0.4.1",
4
+ "description": "SyncBridge SQB database connection components",
5
+ "author": "Panates Inc",
6
+ "license": "UNLICENSED",
7
+ "dependencies": {
8
+ "@sqb/connect": "^4.19.6",
9
+ "@sqb/oracle": "^4.21.1",
10
+ "@sqb/postgres": "^4.21.1",
11
+ "ansi-colors": "^4.1.3",
12
+ "node-events-async": "^1.5.0",
13
+ "oracledb": "^6.10.0"
14
+ },
15
+ "peerDependencies": {
16
+ "@syncbridge/common": "^0.4.1",
17
+ "@syncbridge/builtins": "^0.4.1",
18
+ "@sqb/builder": ">=4.19.6 <5",
19
+ "@sqb/connect": ">=4.19.6 <5"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./index.d.ts",
24
+ "default": "./index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "type": "module",
29
+ "module": "./index.js",
30
+ "types": "./index.d.ts",
31
+ "engines": {
32
+ "node": ">=20.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }