proto.io 0.0.208 → 0.0.210
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/adapters/file/aliyun-oss.d.ts +6 -6
- package/dist/adapters/file/aliyun-oss.js +14 -13
- package/dist/adapters/file/aliyun-oss.js.map +1 -1
- package/dist/adapters/file/aliyun-oss.mjs +14 -13
- package/dist/adapters/file/aliyun-oss.mjs.map +1 -1
- package/dist/adapters/file/database.d.ts +3 -3
- package/dist/adapters/file/database.js +2 -2
- package/dist/adapters/file/database.js.map +1 -1
- package/dist/adapters/file/database.mjs +2 -2
- package/dist/adapters/file/database.mjs.map +1 -1
- package/dist/adapters/file/filesystem.d.ts +5 -5
- package/dist/adapters/file/filesystem.js +11 -7
- package/dist/adapters/file/filesystem.js.map +1 -1
- package/dist/adapters/file/filesystem.mjs +11 -7
- package/dist/adapters/file/filesystem.mjs.map +1 -1
- package/dist/adapters/file/google-cloud-storage.d.ts +6 -6
- package/dist/adapters/file/google-cloud-storage.js +23 -13
- package/dist/adapters/file/google-cloud-storage.js.map +1 -1
- package/dist/adapters/file/google-cloud-storage.mjs +23 -13
- package/dist/adapters/file/google-cloud-storage.mjs.map +1 -1
- package/dist/adapters/storage/progres.d.ts +1 -1
- package/dist/adapters/storage/progres.js +22 -28
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +22 -28
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +3 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +159 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -24
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{base-wSknxBv7.d.ts → base-C1ndp06_.d.ts} +2 -2
- package/dist/internals/base-C1ndp06_.d.ts.map +1 -0
- package/dist/internals/{base-CfQi0T0I.mjs → base-DYc1_peK.mjs} +3 -3
- package/dist/internals/{base-CfQi0T0I.mjs.map → base-DYc1_peK.mjs.map} +1 -1
- package/dist/internals/{base-BFKQpiws.js → base-NsJYo2MG.js} +3 -3
- package/dist/internals/{base-BFKQpiws.js.map → base-NsJYo2MG.js.map} +1 -1
- package/dist/internals/{chunk-BuMQw4dz.js → chunk-BuKmyceG.js} +5 -3
- package/dist/internals/chunk-BuKmyceG.js.map +1 -0
- package/dist/internals/{chunk-C_BXf1Er.d.ts → chunk-DF4KyvgB.d.ts} +6 -6
- package/dist/internals/chunk-DF4KyvgB.d.ts.map +1 -0
- package/dist/internals/{chunk-DxYhYVky.mjs → chunk-bpt1C6W4.mjs} +5 -3
- package/dist/internals/chunk-bpt1C6W4.mjs.map +1 -0
- package/dist/internals/const-C3I6cfav.js +42 -0
- package/dist/internals/const-C3I6cfav.js.map +1 -0
- package/dist/internals/const-Dkp7Nsv5.mjs +34 -0
- package/dist/internals/const-Dkp7Nsv5.mjs.map +1 -0
- package/dist/internals/index-B8TESzd9.js.map +1 -1
- package/dist/internals/{index-BvwYz4Yp.mjs → index-BgSBzm-K.mjs} +95 -20
- package/dist/internals/index-BgSBzm-K.mjs.map +1 -0
- package/dist/internals/{index-DVUiXLfI.js → index-Clo9hepf.js} +101 -29
- package/dist/internals/index-Clo9hepf.js.map +1 -0
- package/dist/internals/{index-CkAvNaAe.js → index-D8O7SinR.js} +50 -3
- package/dist/internals/index-D8O7SinR.js.map +1 -0
- package/dist/internals/{index-A-hoMfDO.d.ts → index-DIRjiWPh.d.ts} +32 -1
- package/dist/internals/index-DIRjiWPh.d.ts.map +1 -0
- package/dist/internals/{index-DlY33lfO.mjs → index-DPPLcZx8.mjs} +51 -4
- package/dist/internals/index-DPPLcZx8.mjs.map +1 -0
- package/dist/internals/index-al1N-qi7.mjs.map +1 -1
- package/dist/internals/{index-iqOd-Wdg.d.ts → index-l-Mk0lCc.d.ts} +2 -2
- package/dist/internals/index-l-Mk0lCc.d.ts.map +1 -0
- package/dist/internals/{random-B0V0EnjP.js → random-CyU_Y2Ay.js} +2 -2
- package/dist/internals/{random-B0V0EnjP.js.map → random-CyU_Y2Ay.js.map} +1 -1
- package/dist/internals/{random-ZgzzM5v_.mjs → random-ycCeBd0S.mjs} +2 -2
- package/dist/internals/{random-ZgzzM5v_.mjs.map → random-ycCeBd0S.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/internals/base-wSknxBv7.d.ts.map +0 -1
- package/dist/internals/chunk-BuMQw4dz.js.map +0 -1
- package/dist/internals/chunk-C_BXf1Er.d.ts.map +0 -1
- package/dist/internals/chunk-DxYhYVky.mjs.map +0 -1
- package/dist/internals/index-A-hoMfDO.d.ts.map +0 -1
- package/dist/internals/index-BvwYz4Yp.mjs.map +0 -1
- package/dist/internals/index-CkAvNaAe.js.map +0 -1
- package/dist/internals/index-DVUiXLfI.js.map +0 -1
- package/dist/internals/index-DlY33lfO.mjs.map +0 -1
- package/dist/internals/index-iqOd-Wdg.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { F as FileChunkStorageBase } from '../../internals/chunk-
|
|
3
|
-
import '../../internals/base-
|
|
2
|
+
import { F as FileChunkStorageBase } from '../../internals/chunk-bpt1C6W4.mjs';
|
|
3
|
+
import '../../internals/base-DYc1_peK.mjs';
|
|
4
4
|
import 'util';
|
|
5
5
|
import 'zlib';
|
|
6
6
|
import '@o2ter/utils-js';
|
|
@@ -44,19 +44,29 @@ class GoogleCloudStorage extends FileChunkStorageBase {
|
|
|
44
44
|
async createChunk(proto, token, start, end, compressed) {
|
|
45
45
|
await this.bucket.file(`${token}/${start}.chunk`).save(compressed);
|
|
46
46
|
}
|
|
47
|
-
async listChunks(proto, token) {
|
|
48
|
-
|
|
47
|
+
async *listChunks(proto, token, start, end) {
|
|
48
|
+
let query = {
|
|
49
|
+
autoPaginate: false,
|
|
49
50
|
prefix: `${token}/`,
|
|
50
51
|
delimiter: '/',
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
};
|
|
53
|
+
do {
|
|
54
|
+
const [response, nextPage] = await this.bucket.getFiles(query);
|
|
55
|
+
if (_.isEmpty(response))
|
|
56
|
+
break;
|
|
57
|
+
for (const item of response) {
|
|
58
|
+
const name = _.last(_.split(item.name, '/'));
|
|
59
|
+
if (!name?.match(/^\d+\.chunk$/))
|
|
60
|
+
continue;
|
|
61
|
+
const pos = parseInt(name.slice(0, -6));
|
|
62
|
+
if (start && pos < start)
|
|
63
|
+
continue;
|
|
64
|
+
if (end && pos >= end)
|
|
65
|
+
continue;
|
|
66
|
+
yield { start: pos, file: item };
|
|
67
|
+
}
|
|
68
|
+
query = nextPage;
|
|
69
|
+
} while (query);
|
|
60
70
|
}
|
|
61
71
|
async readChunk(proto, file) {
|
|
62
72
|
const [buffer] = await file.download() ?? [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-cloud-storage.mjs","sources":["../../../../src/adapters/file/google-cloud-storage/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { Storage, File } from '@google-cloud/storage';\nimport { FileStorageOptions } from '../base';\nimport { FileChunkStorageBase } from '../base/chunk';\n\nexport class GoogleCloudStorage extends FileChunkStorageBase<File> {\n\n private _storage: Storage;\n private _bucket: string;\n\n constructor(storage: Storage, bucket: string, options: FileStorageOptions = {}) {\n super(options);\n this._storage = storage;\n this._bucket = bucket;\n }\n\n get bucket() {\n return this._storage.bucket(this._bucket);\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n await this.bucket.file(`${token}/${start}.chunk`).save(compressed);\n }\n\n async listChunks<E>(proto: ProtoService<E>, token: string) {\n
|
|
1
|
+
{"version":3,"file":"google-cloud-storage.mjs","sources":["../../../../src/adapters/file/google-cloud-storage/index.ts"],"sourcesContent":["//\n// index.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { ProtoService } from '../../../server/proto';\nimport { Storage, File, GetFilesOptions } from '@google-cloud/storage';\nimport { FileStorageOptions } from '../base';\nimport { FileChunkStorageBase } from '../base/chunk';\n\nexport class GoogleCloudStorage extends FileChunkStorageBase<File> {\n\n private _storage: Storage;\n private _bucket: string;\n\n constructor(storage: Storage, bucket: string, options: FileStorageOptions = {}) {\n super(options);\n this._storage = storage;\n this._bucket = bucket;\n }\n\n get bucket() {\n return this._storage.bucket(this._bucket);\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n await this.bucket.file(`${token}/${start}.chunk`).save(compressed);\n }\n\n async* listChunks<E>(proto: ProtoService<E>, token: string, start?: number, end?: number) {\n let query: any = {\n autoPaginate: false,\n prefix: `${token}/`,\n delimiter: '/',\n };\n do {\n const [response, nextPage] = await this.bucket.getFiles(query);\n if (_.isEmpty(response)) break;\n for (const item of response) {\n const name = _.last(_.split(item.name, '/'));\n if (!name?.match(/^\\d+\\.chunk$/)) continue;\n const pos = parseInt(name.slice(0, -6));\n if (start && pos < start) continue;\n if (end && pos >= end) continue;\n yield { start: pos, file: item };\n }\n query = nextPage;\n } while (query);\n }\n\n async readChunk<E>(proto: ProtoService<E>, file: File) {\n const [buffer] = await file.download() ?? [];\n if (!buffer) throw Error('Unable to connect cloud storage');\n return buffer;\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n await this.bucket.deleteFiles({ prefix: `${token}/` });\n }\n};\n\nexport default GoogleCloudStorage;"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQM,MAAO,kBAAmB,SAAQ,oBAA0B,CAAA;AAExD,IAAA,QAAQ;AACR,IAAA,OAAO;AAEf,IAAA,WAAA,CAAY,OAAgB,EAAE,MAAc,EAAE,UAA8B,EAAE,EAAA;QAC5E,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;;AAGvB,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;;IAG3C,MAAM,WAAW,CAAI,KAAsB,EAAE,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,UAAkB,EAAA;AACxG,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAG,EAAA,KAAK,CAAI,CAAA,EAAA,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;;IAGpE,OAAO,UAAU,CAAI,KAAsB,EAAE,KAAa,EAAE,KAAc,EAAE,GAAY,EAAA;AACtF,QAAA,IAAI,KAAK,GAAQ;AACf,YAAA,YAAY,EAAE,KAAK;YACnB,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA;AACnB,YAAA,SAAS,EAAE,GAAG;SACf;AACD,QAAA,GAAG;AACD,YAAA,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC9D,YAAA,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAAE;AACzB,YAAA,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE;AAC3B,gBAAA,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5C,gBAAA,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC;oBAAE;AAClC,gBAAA,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACvC,gBAAA,IAAI,KAAK,IAAI,GAAG,GAAG,KAAK;oBAAE;AAC1B,gBAAA,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;oBAAE;gBACvB,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE;;YAElC,KAAK,GAAG,QAAQ;SACjB,QAAQ,KAAK;;AAGhB,IAAA,MAAM,SAAS,CAAI,KAAsB,EAAE,IAAU,EAAA;QACnD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE;AAC5C,QAAA,IAAI,CAAC,MAAM;AAAE,YAAA,MAAM,KAAK,CAAC,iCAAiC,CAAC;AAC3D,QAAA,OAAO,MAAM;;AAGf,IAAA,MAAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAG,EAAA,KAAK,CAAG,CAAA,CAAA,EAAE,CAAC;;AAEzD;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
-
import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QuerySelector, y as DecodedSortOption, z as DecodedQuery, A as FindOptions, I as InsertOptions, B as TStorage, C as TransactionOptions, j as TObject, G as TQueryRandomOptions, H as TPubSub } from '../../internals/index-
|
|
2
|
+
import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QuerySelector, y as DecodedSortOption, z as DecodedQuery, A as FindOptions, I as InsertOptions, B as TStorage, C as TransactionOptions, j as TObject, G as TQueryRandomOptions, H as TPubSub } from '../../internals/index-DIRjiWPh.js';
|
|
3
3
|
import * as _o2ter_utils_js from '@o2ter/utils-js';
|
|
4
4
|
import { asyncStream } from '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
@@ -9,9 +9,10 @@ var QueryStream = require('pg-query-stream');
|
|
|
9
9
|
var utilsJs = require('@o2ter/utils-js');
|
|
10
10
|
var Decimal = require('decimal.js');
|
|
11
11
|
var utils = require('pg/lib/utils');
|
|
12
|
-
var index$1 = require('../../internals/index-
|
|
12
|
+
var index$1 = require('../../internals/index-D8O7SinR.js');
|
|
13
13
|
require('@o2ter/crypto-js');
|
|
14
|
-
var random$1 = require('../../internals/random-
|
|
14
|
+
var random$1 = require('../../internals/random-CyU_Y2Ay.js');
|
|
15
|
+
var _const = require('../../internals/const-C3I6cfav.js');
|
|
15
16
|
var _private = require('../../internals/private-Ciddhure.js');
|
|
16
17
|
|
|
17
18
|
//
|
|
@@ -1063,24 +1064,24 @@ class PostgresClientDriver {
|
|
|
1063
1064
|
}
|
|
1064
1065
|
async publish(channel, payload) {
|
|
1065
1066
|
await this.withClient(async (db) => {
|
|
1066
|
-
await db.query(`NOTIFY ${
|
|
1067
|
+
await db.query(`NOTIFY ${_const.PROTO_EVENT}, ${quote(JSON.stringify(index._encodeValue({ channel, payload })))}`);
|
|
1067
1068
|
});
|
|
1068
1069
|
}
|
|
1069
1070
|
}
|
|
1070
1071
|
class PostgresPubSub {
|
|
1071
1072
|
client;
|
|
1072
|
-
subscribers =
|
|
1073
|
-
channels = [];
|
|
1073
|
+
subscribers = [];
|
|
1074
1074
|
constructor(client) {
|
|
1075
1075
|
this.client = client;
|
|
1076
1076
|
(async () => {
|
|
1077
1077
|
try {
|
|
1078
|
-
|
|
1079
|
-
|
|
1078
|
+
client = await client;
|
|
1079
|
+
client.on('notification', ({ channel, payload }) => {
|
|
1080
|
+
if (_.toUpper(channel) !== _const.PROTO_EVENT || !payload)
|
|
1080
1081
|
return;
|
|
1081
1082
|
try {
|
|
1082
1083
|
const _payload = index._decodeValue(JSON.parse(payload));
|
|
1083
|
-
for (const subscriber of this.subscribers
|
|
1084
|
+
for (const subscriber of this.subscribers) {
|
|
1084
1085
|
subscriber(_payload);
|
|
1085
1086
|
}
|
|
1086
1087
|
}
|
|
@@ -1088,6 +1089,7 @@ class PostgresPubSub {
|
|
|
1088
1089
|
console.error(`Unknown payload: ${e}`);
|
|
1089
1090
|
}
|
|
1090
1091
|
});
|
|
1092
|
+
await client.query(`LISTEN ${_const.PROTO_EVENT}`);
|
|
1091
1093
|
}
|
|
1092
1094
|
catch (e) {
|
|
1093
1095
|
console.error(e);
|
|
@@ -1097,20 +1099,14 @@ class PostgresPubSub {
|
|
|
1097
1099
|
async shutdown() {
|
|
1098
1100
|
(await this.client).release();
|
|
1099
1101
|
}
|
|
1100
|
-
|
|
1101
|
-
this.
|
|
1102
|
-
await (await this.client).query(`LISTEN ${channel}`);
|
|
1103
|
-
}
|
|
1104
|
-
subscribe(channel, callback) {
|
|
1105
|
-
if (_.isNil(this.subscribers[channel]))
|
|
1106
|
-
this.subscribers[channel] = [];
|
|
1107
|
-
this.subscribers[channel].push(callback);
|
|
1102
|
+
subscribe(callback) {
|
|
1103
|
+
this.subscribers.push(callback);
|
|
1108
1104
|
return () => {
|
|
1109
|
-
this.subscribers
|
|
1105
|
+
this.subscribers = this.subscribers.filter(x => x !== callback);
|
|
1110
1106
|
};
|
|
1111
1107
|
}
|
|
1112
1108
|
isEmpty() {
|
|
1113
|
-
return _.
|
|
1109
|
+
return _.isEmpty(this.subscribers);
|
|
1114
1110
|
}
|
|
1115
1111
|
}
|
|
1116
1112
|
class PostgresDriver extends PostgresClientDriver {
|
|
@@ -1129,14 +1125,9 @@ class PostgresDriver extends PostgresClientDriver {
|
|
|
1129
1125
|
await this.database.end();
|
|
1130
1126
|
}
|
|
1131
1127
|
_init_pubsub() {
|
|
1132
|
-
if (this.pubsub)
|
|
1128
|
+
if (this.pubsub || this.database.ending || this.database.ended)
|
|
1133
1129
|
return;
|
|
1134
|
-
|
|
1135
|
-
this.pubsub = new PostgresPubSub(this.database.connect());
|
|
1136
|
-
}
|
|
1137
|
-
catch (e) {
|
|
1138
|
-
console.error(e);
|
|
1139
|
-
}
|
|
1130
|
+
this.pubsub = new PostgresPubSub(this.database.connect());
|
|
1140
1131
|
}
|
|
1141
1132
|
async _release_pubsub() {
|
|
1142
1133
|
const pubsub = this.pubsub;
|
|
@@ -1145,9 +1136,12 @@ class PostgresDriver extends PostgresClientDriver {
|
|
|
1145
1136
|
}
|
|
1146
1137
|
subscribe(channel, callback) {
|
|
1147
1138
|
this._init_pubsub();
|
|
1148
|
-
if (!
|
|
1149
|
-
|
|
1150
|
-
const release = this.pubsub.subscribe(channel,
|
|
1139
|
+
if (!this.pubsub)
|
|
1140
|
+
return () => void 0;
|
|
1141
|
+
const release = this.pubsub.subscribe(({ channel: _channel, payload }) => {
|
|
1142
|
+
if (_channel === channel)
|
|
1143
|
+
callback(payload);
|
|
1144
|
+
});
|
|
1151
1145
|
return () => {
|
|
1152
1146
|
release();
|
|
1153
1147
|
if (this.pubsub?.isEmpty())
|