@ohos-ports/core 1.0.113-beta.0 → 1.16.33-beta.0
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 +13 -0
- package/README.md +3 -0
- package/lib/api/node.js +176 -0
- package/lib/api/team.js +1889 -0
- package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
- package/lib/blocklet/downloader/bundle-downloader.js +316 -0
- package/lib/blocklet/downloader/constants.js +3 -0
- package/lib/blocklet/downloader/resolve-download.js +187 -0
- package/lib/blocklet/extras.js +177 -0
- package/lib/blocklet/hooks.js +89 -0
- package/lib/blocklet/manager/base.js +49 -0
- package/lib/blocklet/manager/config-synchronizer.js +128 -0
- package/lib/blocklet/manager/disk.js +5170 -0
- package/lib/blocklet/manager/engine.js +124 -0
- package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
- package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
- package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
- package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
- package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
- package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
- package/lib/blocklet/manager/pm2-events.js +50 -0
- package/lib/blocklet/migration-dist/migration.cjs +38605 -0
- package/lib/blocklet/migration-dist/run-script.cjs +29 -0
- package/lib/blocklet/migration.js +145 -0
- package/lib/blocklet/project/connect-by-studio.js +91 -0
- package/lib/blocklet/project/connect-to-store.js +64 -0
- package/lib/blocklet/project/create-pack-release.js +293 -0
- package/lib/blocklet/project/disconnect-from-store.js +13 -0
- package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
- package/lib/blocklet/project/index.js +545 -0
- package/lib/blocklet/project/logo.png +0 -0
- package/lib/blocklet/project/publish-to-store.js +108 -0
- package/lib/blocklet/project/util.js +194 -0
- package/lib/blocklet/security/access-policy.js +131 -0
- package/lib/blocklet/security/index.js +309 -0
- package/lib/blocklet/security/response-header-policy.js +178 -0
- package/lib/blocklet/security/security-rule.js +127 -0
- package/lib/blocklet/security/utils.js +35 -0
- package/lib/blocklet/security/validator.js +40 -0
- package/lib/blocklet/storage/backup/base.js +149 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
- package/lib/blocklet/storage/backup/blocklet.js +159 -0
- package/lib/blocklet/storage/backup/blocklets.js +109 -0
- package/lib/blocklet/storage/backup/data.js +35 -0
- package/lib/blocklet/storage/backup/disk.js +131 -0
- package/lib/blocklet/storage/backup/logs.js +24 -0
- package/lib/blocklet/storage/backup/routing-rule.js +47 -0
- package/lib/blocklet/storage/backup/spaces.js +345 -0
- package/lib/blocklet/storage/restore/base.js +74 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
- package/lib/blocklet/storage/restore/blocklet.js +56 -0
- package/lib/blocklet/storage/restore/blocklets.js +43 -0
- package/lib/blocklet/storage/restore/disk.js +104 -0
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +174 -0
- package/lib/blocklet/storage/utils/disk.js +178 -0
- package/lib/blocklet/storage/utils/hash.js +53 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/cert.js +221 -0
- package/lib/crons/check-new-version.js +68 -0
- package/lib/crons/monitor-disk-usage.js +46 -0
- package/lib/crons/rotate-pm2-logs/index.js +41 -0
- package/lib/crons/rotate-pm2-logs/script.js +56 -0
- package/lib/event/auto-backup-handler.js +48 -0
- package/lib/event/index.js +520 -0
- package/lib/index.js +768 -364
- package/lib/locales/ar.js +18 -0
- package/lib/locales/de.js +21 -0
- package/lib/locales/en.js +19 -0
- package/lib/locales/es.js +21 -0
- package/lib/locales/fr.js +21 -0
- package/lib/locales/hi.js +18 -0
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +20 -0
- package/lib/locales/index.js +54 -0
- package/lib/locales/ja.js +19 -0
- package/lib/locales/ko.js +18 -0
- package/lib/locales/pt.js +20 -0
- package/lib/locales/ru.js +21 -0
- package/lib/locales/th.js +18 -0
- package/lib/locales/vi.js +18 -0
- package/lib/locales/zh-tw.js +17 -0
- package/lib/locales/zh.js +17 -0
- package/lib/migrations/1.0.21-update-config.js +34 -0
- package/lib/migrations/1.0.22-max-memory.js +40 -0
- package/lib/migrations/1.0.25.js +36 -0
- package/lib/migrations/1.0.32-update-config.js +30 -0
- package/lib/migrations/1.0.33-blocklets.js +33 -0
- package/lib/migrations/1.0.36-snapshot.js +10 -0
- package/lib/migrations/1.1.10-team.js +26 -0
- package/lib/migrations/1.1.9-snapshot.js +7 -0
- package/lib/migrations/1.16.11-component-status.js +22 -0
- package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
- package/lib/migrations/1.16.6-chain-info.js +78 -0
- package/lib/migrations/1.16.8-component-title.js +66 -0
- package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
- package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
- package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
- package/lib/migrations/1.4.5-access-key.js +18 -0
- package/lib/migrations/1.5.0-site.js +34 -0
- package/lib/migrations/1.5.15-site.js +184 -0
- package/lib/migrations/1.5.20-registry.js +15 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
- package/lib/migrations/1.6.4-security.js +59 -0
- package/lib/migrations/1.6.5-security.js +60 -0
- package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
- package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
- package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
- package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
- package/lib/migrations/1.7.20-blocklet-component.js +41 -0
- package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
- package/lib/migrations/README.md +71 -0
- package/lib/migrations/index.js +215 -0
- package/lib/monitor/blocklet-runtime-monitor.js +204 -0
- package/lib/monitor/get-history-list.js +37 -0
- package/lib/monitor/node-monit-sender.js +99 -0
- package/lib/monitor/node-runtime-monitor.js +205 -0
- package/lib/processes/updater.js +186 -0
- package/lib/router/helper.js +1653 -0
- package/lib/router/index.js +341 -0
- package/lib/router/manager.js +806 -0
- package/lib/states/README.md +38 -0
- package/lib/states/access-key.js +124 -0
- package/lib/states/access-policy.js +29 -0
- package/lib/states/audit-log.js +734 -0
- package/lib/states/backup.js +165 -0
- package/lib/states/base.js +25 -0
- package/lib/states/blocklet-extras.js +257 -0
- package/lib/states/blocklet.js +755 -0
- package/lib/states/cache.js +23 -0
- package/lib/states/connect-account.js +8 -0
- package/lib/states/index.js +76 -0
- package/lib/states/job.js +8 -0
- package/lib/states/migration.js +34 -0
- package/lib/states/node.js +324 -0
- package/lib/states/notification.js +81 -0
- package/lib/states/passport.js +8 -0
- package/lib/states/project.js +119 -0
- package/lib/states/release.js +50 -0
- package/lib/states/response-header-policy.js +30 -0
- package/lib/states/routing-snapshot.js +146 -0
- package/lib/states/runtime-insight.js +25 -0
- package/lib/states/security-rule.js +30 -0
- package/lib/states/session.js +53 -0
- package/lib/states/site.js +102 -0
- package/lib/states/tag.js +8 -0
- package/lib/states/traffic-insight.js +25 -0
- package/lib/states/user-session.js +8 -0
- package/lib/states/user.js +717 -0
- package/lib/states/verify-code.js +152 -0
- package/lib/states/webhook.js +66 -0
- package/lib/team/manager.js +508 -0
- package/lib/util/blocklet.js +2182 -0
- package/lib/util/cache.js +63 -0
- package/lib/util/chain.js +29 -0
- package/lib/util/default-node-config.js +46 -0
- package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
- package/lib/util/docker/check-docker-has-image.js +23 -0
- package/lib/util/docker/check-docker-installed.js +32 -0
- package/lib/util/docker/check-docker-run-history.js +18 -0
- package/lib/util/docker/check-need-run-docker.js +32 -0
- package/lib/util/docker/create-docker-image.js +65 -0
- package/lib/util/docker/debian-dockerfile.js +50 -0
- package/lib/util/docker/docker-container-prune.js +75 -0
- package/lib/util/docker/docker-exec-chown.js +39 -0
- package/lib/util/docker/docker-exec.js +68 -0
- package/lib/util/docker/docker-remove-by-name.js +20 -0
- package/lib/util/docker/get-docker-runtime-info.js +39 -0
- package/lib/util/docker/parse-docker-name.js +10 -0
- package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
- package/lib/util/docker/shard-network.js +10 -0
- package/lib/util/domain-status.js +118 -0
- package/lib/util/get-accessible-external-node-ip.js +92 -0
- package/lib/util/get-dynamic-components.js +47 -0
- package/lib/util/get-meta-from-url.js +30 -0
- package/lib/util/get-migration-scripts.js +36 -0
- package/lib/util/get-safe-env.js +12 -0
- package/lib/util/index.js +522 -0
- package/lib/util/install-external-dependencies.js +67 -0
- package/lib/util/ip.js +53 -0
- package/lib/util/launcher.js +475 -0
- package/lib/util/log.js +431 -0
- package/lib/util/maintain.js +178 -0
- package/lib/util/promise-debounce.js +29 -0
- package/lib/util/promise-once.js +14 -0
- package/lib/util/promise-spawn.js +93 -0
- package/lib/util/queue.js +44 -0
- package/lib/util/ready.js +89 -0
- package/lib/util/request.js +10 -0
- package/lib/util/requirement.js +61 -0
- package/lib/util/reset-node.js +166 -0
- package/lib/util/rotator.js +194 -0
- package/lib/util/router.js +122 -0
- package/lib/util/rpc.js +78 -0
- package/lib/util/spaces.js +102 -0
- package/lib/util/store.js +184 -0
- package/lib/util/sysinfo.js +46 -0
- package/lib/util/ua.js +54 -0
- package/lib/validators/backup.js +34 -0
- package/lib/validators/blocklet-extra.js +18 -0
- package/lib/validators/node.js +73 -0
- package/lib/validators/permission.js +38 -0
- package/lib/validators/project.js +39 -0
- package/lib/validators/role.js +64 -0
- package/lib/validators/router.js +192 -0
- package/lib/validators/space-gateway.js +33 -0
- package/lib/validators/trusted-factory.js +28 -0
- package/lib/validators/trusted-passport.js +32 -0
- package/lib/validators/user.js +62 -0
- package/lib/validators/util.js +92 -0
- package/lib/validators/webhook.js +42 -0
- package/lib/webhook/index.js +216 -0
- package/lib/webhook/reduce-queue.js +12 -0
- package/lib/webhook/sender/api/index.js +67 -0
- package/lib/webhook/sender/base.js +11 -0
- package/lib/webhook/sender/index.js +44 -0
- package/lib/webhook/sender/slack/index.js +167 -0
- package/lib/webhook/sender/wallet/index.js +62 -0
- package/package.json +107 -34
- package/examples/BatchClient.js +0 -61
- package/examples/compressor/example.js +0 -7
- package/examples/jsonrpcserver/rpcmethod.js +0 -21
- package/examples/jsonrpcserver/rpcrequest.js +0 -20
- package/examples/jsonrpcserver/rpctest.js +0 -6
- package/examples/loader-pipes/test-mc.js +0 -52
- package/examples/loader-pipes/test.js +0 -51
- package/examples/mc-test.js +0 -44
- package/examples/redisdebug.js +0 -80
- package/lib/cache/CFMemcache.js +0 -57
- package/lib/cache/CacheLoader.js +0 -217
- package/lib/cache/Memcache.js +0 -406
- package/lib/class/Class.js +0 -54
- package/lib/client/MemcacheAdapter.js +0 -139
- package/lib/client/Memcached.js +0 -142
- package/lib/client/MemcachedSocket.js +0 -570
- package/lib/client/MySQLPool.js +0 -153
- package/lib/client/PGPool.js +0 -296
- package/lib/client/Redis.js +0 -787
- package/lib/client/S3.js +0 -103
- package/lib/client/S3Client.js +0 -392
- package/lib/client/pg/CursorQueryWorker.js +0 -160
- package/lib/client/rabbitmq/RbmqChannel.js +0 -61
- package/lib/client/rabbitmq/RbmqConfig.js +0 -144
- package/lib/client/rabbitmq/RbmqConnection.js +0 -259
- package/lib/client/rabbitmq/RbmqExchange.js +0 -112
- package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
- package/lib/client/rabbitmq/RbmqMessage.js +0 -120
- package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
- package/lib/client/rabbitmq/RbmqQueue.js +0 -87
- package/lib/client/rabbitmq/index.js +0 -8
- package/lib/common/Assertions.js +0 -184
- package/lib/common/Merge.js +0 -32
- package/lib/common/Net.js +0 -56
- package/lib/common/Process.js +0 -20
- package/lib/common/Random.js +0 -53
- package/lib/common/Sort.js +0 -19
- package/lib/common/Types.js +0 -163
- package/lib/credentials/CredentialsProvider.js +0 -45
- package/lib/credentials/Manager.js +0 -101
- package/lib/crypto/Crypto.js +0 -66
- package/lib/data/BinaryData.js +0 -363
- package/lib/data/Compressor.js +0 -83
- package/lib/data/FormData.js +0 -144
- package/lib/data/Mime.js +0 -45
- package/lib/event/ErrorEvent.js +0 -71
- package/lib/event/Event.js +0 -20
- package/lib/event/EventDispatcher.js +0 -157
- package/lib/http/ConnectionPool.js +0 -82
- package/lib/http/ExpressServer.js +0 -19
- package/lib/http/Headers.js +0 -165
- package/lib/http/Loader.js +0 -584
- package/lib/http/Message.js +0 -189
- package/lib/http/Request.js +0 -848
- package/lib/http/RequestProcessor.js +0 -150
- package/lib/http/Response.js +0 -850
- package/lib/http/Server.js +0 -267
- package/lib/http/Socket.js +0 -157
- package/lib/http/Url.js +0 -2
- package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
- package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
- package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
- package/lib/jsonrpc/JsonRpcError.js +0 -191
- package/lib/jsonrpc/JsonRpcMethod.js +0 -67
- package/lib/jsonrpc/JsonRpcRequest.js +0 -224
- package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
- package/lib/jsonrpc/JsonRpcResponse.js +0 -175
- package/lib/jsonrpc/JsonRpcServer.js +0 -81
- package/lib/logger/EmptyLogger.js +0 -15
- package/lib/logger/LoggerFactory.js +0 -20
- package/lib/logger/WildFireLogger.js +0 -267
- package/lib/pattern/Pool.js +0 -187
- package/lib/pattern/decorator/AbstractDecorator.js +0 -49
- package/lib/pattern/decorator/DecoratorChain.js +0 -285
- package/lib/util/DeviceDetector.js +0 -153
- package/lib/yaml/YAML.js +0 -46
- package/patterns.conf +0 -6
- package/tests/cache/CacheLoaderSpec.js +0 -7
- package/tests/class/ClassSpec.js +0 -106
- package/tests/client/MemcachedSocketSpec.js +0 -1228
- package/tests/client/MemcachedSpec.js +0 -77
- package/tests/client/MySQLPoolSpec.js +0 -231
- package/tests/client/PGPoolSpec.js +0 -479
- package/tests/client/RedisSpec.js +0 -471
- package/tests/client/S3ClientSpec.js +0 -26
- package/tests/client/S3Spec.js +0 -129
- package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
- package/tests/common/AssertionsSpec.js +0 -278
- package/tests/common/NetSpec.js +0 -6
- package/tests/common/RandomSpec.js +0 -35
- package/tests/common/TypesSpec.js +0 -7
- package/tests/credentials/CredentialsProviderSpec.js +0 -46
- package/tests/crypto/CryptoSpec.js +0 -33
- package/tests/data/BinaryDataSpec.js +0 -50
- package/tests/data/CompressorSpec.js +0 -7
- package/tests/data/FormDataSpec.js +0 -7
- package/tests/data/MimeSpec.js +0 -7
- package/tests/event/ErrorEventSpec.js +0 -20
- package/tests/event/EventDispatcherSpec.js +0 -319
- package/tests/event/EventSpec.js +0 -17
- package/tests/http/ConnectionPoolSpec.js +0 -7
- package/tests/http/HeadersSpec.js +0 -79
- package/tests/http/LoaderSpec.js +0 -43
- package/tests/http/MessageSpec.js +0 -251
- package/tests/http/RequestProcessorSpec.js +0 -124
- package/tests/http/RequestSpec.js +0 -651
- package/tests/http/ResponseSpec.js +0 -491
- package/tests/http/ServerSpec.js +0 -7
- package/tests/http/SocketSpec.js +0 -7
- package/tests/http/UrlSpec.js +0 -14
- package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
- package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
- package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
- package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
- package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
- package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
- package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
- package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
- package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
- package/tests/pattern/PoolSpec.js +0 -180
- package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
- package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
- package/tests/yaml/YAMLSpec.js +0 -132
package/lib/client/S3.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @overview MySQLPool
|
|
3
|
-
* @copyright Dreamlab Onet.pl sp. z. o o 2012
|
|
4
|
-
*/
|
|
5
|
-
var Event = require('../event/Event.js').Event;
|
|
6
|
-
var ErrorEvent = require('../event/ErrorEvent.js').ErrorEvent;
|
|
7
|
-
var EventDispatcher = require('../event/EventDispatcher.js').EventDispatcher;
|
|
8
|
-
var Crypto = require('../crypto/Crypto.js').Crypto;
|
|
9
|
-
var BinaryData = require("../data/BinaryData.js").BinaryData;
|
|
10
|
-
var Response = require("../http/Response.js").Response;
|
|
11
|
-
var knox = require('knox');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @class S3
|
|
15
|
-
* @classdesc S3 client
|
|
16
|
-
* @param {Object} configuration
|
|
17
|
-
* @extends EventDispatcher
|
|
18
|
-
*/
|
|
19
|
-
var S3 = function(configuration){
|
|
20
|
-
this._client = knox.createClient(configuration);
|
|
21
|
-
EventDispatcher.call(this);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
S3.prototype = Object.create(EventDispatcher.prototype);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Fetch file from S3
|
|
28
|
-
* @method
|
|
29
|
-
* @param {String} file
|
|
30
|
-
* @param {Function} cb
|
|
31
|
-
*/
|
|
32
|
-
S3.prototype.get = function (file, cb) {
|
|
33
|
-
var request = this._client.get(file).on('response', function(res){
|
|
34
|
-
var dataLength = 0, buffers = [];
|
|
35
|
-
res.on('data', function (buffer) {
|
|
36
|
-
buffers.push(buffer);
|
|
37
|
-
dataLength += buffer.length;
|
|
38
|
-
});
|
|
39
|
-
res.on('end', function () {
|
|
40
|
-
var resultBuffer = new Buffer(dataLength);
|
|
41
|
-
var bufferPosition = 0;
|
|
42
|
-
for(var i = 0, l = buffers.length; i < l; i++){
|
|
43
|
-
buffers[i].copy(resultBuffer, bufferPosition);
|
|
44
|
-
bufferPosition += buffers[i].length;
|
|
45
|
-
}
|
|
46
|
-
var response = new Response();
|
|
47
|
-
response.setStatusCode(res.statusCode);
|
|
48
|
-
response.setHeaders(res.headers);
|
|
49
|
-
response._setBody(resultBuffer);
|
|
50
|
-
// response.setBody(new BinaryData(resultBuffer, BinaryData.Encoding.BINARY));
|
|
51
|
-
cb(false, response);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
request.on('error', function(err){
|
|
55
|
-
cb(err);
|
|
56
|
-
});
|
|
57
|
-
request.end();
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Put file to S3
|
|
62
|
-
* @method
|
|
63
|
-
* @param {String|Buffer} data
|
|
64
|
-
*/
|
|
65
|
-
S3.prototype.set = function (data) {
|
|
66
|
-
var that = this;
|
|
67
|
-
var req = this._client.put(Crypto.md5(data), {
|
|
68
|
-
'Content-Length': data.length,
|
|
69
|
-
'Content-Type': 'application/octet-stream'
|
|
70
|
-
});
|
|
71
|
-
req.on('response', function (res) {
|
|
72
|
-
if (200 == res.statusCode) {
|
|
73
|
-
that.dispatchEvent(new Event(S3.Event.LOADED, null));
|
|
74
|
-
} else {
|
|
75
|
-
that.dispatchEvent(new ErrorEvent(S3.Event.ERROR, {res: res, req:req}, -5, 'S3 Error'));
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
req.end(data);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @static
|
|
83
|
-
* @constant
|
|
84
|
-
* @namespace
|
|
85
|
-
*/
|
|
86
|
-
S3.Event = {};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @static
|
|
90
|
-
* @constant
|
|
91
|
-
* @type {String}
|
|
92
|
-
* @default
|
|
93
|
-
*/
|
|
94
|
-
S3.Event.LOADED = 'S3.Event.LOADED';
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @static
|
|
98
|
-
* @constant
|
|
99
|
-
* @type {String}
|
|
100
|
-
* @default
|
|
101
|
-
*/
|
|
102
|
-
S3.Event.ERROR = 'S3.Event.ERROR';
|
|
103
|
-
exports.S3 = S3;
|
package/lib/client/S3Client.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
var Response = require("../http/Response.js").Response;
|
|
2
|
-
var knox = require('knox');
|
|
3
|
-
var xml2js = require('xml2js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @class S3Client
|
|
7
|
-
* @classdesc S3 client
|
|
8
|
-
* @param {Object} configuration S3 connection configuration
|
|
9
|
-
* @param {Object} configuration.key access key ID
|
|
10
|
-
* @param {Object} configuration.secret secret access key
|
|
11
|
-
* @param {Object} configuration.bucket bucket
|
|
12
|
-
* @param {Object} options connection options
|
|
13
|
-
* @param {Object} options.timeout timeout before aborting request
|
|
14
|
-
* @param {Object} options.retry number of retries when connection problem occurs
|
|
15
|
-
*/
|
|
16
|
-
var S3Client = function (configuration, options) {
|
|
17
|
-
this.retry = options.retry || 0;
|
|
18
|
-
this.timeout = options.timeout || 10000;
|
|
19
|
-
|
|
20
|
-
/* odwolanie przez bucket */
|
|
21
|
-
configuration.style = 'path';
|
|
22
|
-
|
|
23
|
-
this._client = knox.createClient(configuration);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Callback fired after receiving response from server.
|
|
28
|
-
*
|
|
29
|
-
* When connection error occured {error} object will be passed as first parameter.
|
|
30
|
-
*
|
|
31
|
-
* @callback S3Client~callback
|
|
32
|
-
* @param {error} error
|
|
33
|
-
* @param {response} response Response object
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Callback fired after receiving response from server.
|
|
38
|
-
*
|
|
39
|
-
* When connection error occured {error} object will be passed as first parameter.
|
|
40
|
-
*
|
|
41
|
-
* @callback S3Client~callbackAcl
|
|
42
|
-
* @param {error} error
|
|
43
|
-
* @param {object} acl requested object's ACLs
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Adds object to S3
|
|
48
|
-
*
|
|
49
|
-
* @param {string} key key name of the object
|
|
50
|
-
* @param {object} params object properties
|
|
51
|
-
* @param {buffer|string} params.body object content
|
|
52
|
-
* @param {object} params.headers headers
|
|
53
|
-
* @param {string} params.acl ACL applied to object
|
|
54
|
-
* @param {S3Client~callback} callback Called when response from the server is returned.
|
|
55
|
-
*/
|
|
56
|
-
S3Client.prototype.set = function (key, params, callback) {
|
|
57
|
-
var headers = params.headers;
|
|
58
|
-
var body = params.body;
|
|
59
|
-
|
|
60
|
-
if (!body) {
|
|
61
|
-
return callback(this._getError(S3Client.Error.ENOBODY), null);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!key) {
|
|
65
|
-
return callback(this._getError(S3Client.Error.ENOKEY), null);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!headers) {
|
|
69
|
-
return callback(this._getError(S3Client.Error.ENOHEADERS), null);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (params.acl) {
|
|
73
|
-
headers['x-amz-acl'] = params.acl;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this._spawnFunction(this._set.bind(this, key, headers, body), callback);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Retrieves object from S3.
|
|
81
|
-
*
|
|
82
|
-
* When retry count specified, callback is called once after all tries.
|
|
83
|
-
*
|
|
84
|
-
* @param {string} key
|
|
85
|
-
* @param {S3Client~callback} callback Called when response from the server is returned.
|
|
86
|
-
*/
|
|
87
|
-
S3Client.prototype.get = function (key, params, callback) {
|
|
88
|
-
params = params || {};
|
|
89
|
-
|
|
90
|
-
var headers = {};
|
|
91
|
-
|
|
92
|
-
if (params.range) {
|
|
93
|
-
headers.range = params.range;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
this._spawnFunction(this._get.bind(this, key, headers), callback);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Retrieves headers of object from S3.
|
|
102
|
-
*
|
|
103
|
-
* When retry count specified, callback is called once after all tries.
|
|
104
|
-
*
|
|
105
|
-
* @param {string} key
|
|
106
|
-
* @param {S3Client~callback} callback Called when response from the server is returned.
|
|
107
|
-
*/
|
|
108
|
-
S3Client.prototype.head = function (key, headers, callback) {
|
|
109
|
-
this._spawnFunction(this._head.bind(this, key, headers), callback);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Removes object from S3.
|
|
115
|
-
*
|
|
116
|
-
* When retry count specified, callback is called once after all tries.
|
|
117
|
-
*
|
|
118
|
-
* @param {string} key
|
|
119
|
-
* @param {S3Client~callback} callback Called when response from the server is returned.
|
|
120
|
-
*/
|
|
121
|
-
S3Client.prototype.del = function (key, callback) {
|
|
122
|
-
this._spawnFunction(this._del.bind(this, key), callback);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Copy object in S3 around the same bucket.
|
|
127
|
-
*
|
|
128
|
-
* When retry count specified, callback is called once after all tries.
|
|
129
|
-
*
|
|
130
|
-
* @param {string} keySrc
|
|
131
|
-
* @param {string} keyDst
|
|
132
|
-
* @param {string} headers
|
|
133
|
-
* @param {S3Client~callback} callback Called when response from the server is returned.
|
|
134
|
-
*/
|
|
135
|
-
S3Client.prototype.copy = function (keySrc, keyDst, headers, callback) {
|
|
136
|
-
this._spawnFunction(this._copy.bind(this, keySrc, keyDst, headers), callback);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* List object in S3 bucket.
|
|
141
|
-
*
|
|
142
|
-
* When retry count specified, callback is called once after all tries.
|
|
143
|
-
*
|
|
144
|
-
* @param {string} params
|
|
145
|
-
* @param {string} headers
|
|
146
|
-
* @param {S3Client~callback} callback Called when response from the server is returned.
|
|
147
|
-
*/
|
|
148
|
-
S3Client.prototype.list = function (params, headers, callback) {
|
|
149
|
-
this._client.list(params, headers, callback);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Retrieves object's ACL.
|
|
155
|
-
*
|
|
156
|
-
* When retry count specified, callback is called once after all tries.
|
|
157
|
-
*
|
|
158
|
-
* @param {type} key
|
|
159
|
-
* @param {S3Client~callbackAcl} callback Called when response from the server is returned.
|
|
160
|
-
*/
|
|
161
|
-
S3Client.prototype.getAcl = function (key, callback) {
|
|
162
|
-
key = key + '?acl';
|
|
163
|
-
this._spawnFunction(this._get.bind(this, key, null), function (err, response) {
|
|
164
|
-
if (err) {
|
|
165
|
-
return callback(err, response);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (response.getStatusCode() != 200) {
|
|
169
|
-
var error = new Error('Error fetching ACLs - status code: ' + response.getStatusCode());
|
|
170
|
-
return callback(error, null);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
var xml = response.getBody().toBuffer().toString();
|
|
174
|
-
xml2js.parseString(xml, {explicitArray: false}, function (err, acl) {
|
|
175
|
-
if (err) {
|
|
176
|
-
var error = new Error('Error parsing XML response');
|
|
177
|
-
return callback(error, null);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
callback(null, acl.AccessControlPolicy);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Wraps knox request and manages request events
|
|
187
|
-
*
|
|
188
|
-
* @private
|
|
189
|
-
* @param {string} key
|
|
190
|
-
* @param {Object} headers
|
|
191
|
-
* @param {Buffer} body
|
|
192
|
-
* @param {function} callback
|
|
193
|
-
*/
|
|
194
|
-
S3Client.prototype._set = function (key, headers, body, callback) {
|
|
195
|
-
var request = this._client.put(key, headers, body);
|
|
196
|
-
if (this.timeout) {
|
|
197
|
-
request.setTimeout(this.timeout);
|
|
198
|
-
}
|
|
199
|
-
request.on('response', this._handleResponse.bind(this, callback));
|
|
200
|
-
request.on('error', function (error) {
|
|
201
|
-
callback(error, null);
|
|
202
|
-
});
|
|
203
|
-
request.once('timeout', function () {
|
|
204
|
-
request.abort();
|
|
205
|
-
});
|
|
206
|
-
request.end(body);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Wraps knox request and manages request events
|
|
212
|
-
*
|
|
213
|
-
* @private
|
|
214
|
-
* @param {string} keySrc
|
|
215
|
-
* @param {Object} keyDst
|
|
216
|
-
* @param {Buffer} headers
|
|
217
|
-
* @param {function} callback
|
|
218
|
-
*/
|
|
219
|
-
S3Client.prototype._copy = function (keySrc, keyDst, headers, callback) {
|
|
220
|
-
var request = this._client.copy(keySrc, keyDst, headers);
|
|
221
|
-
if (this.timeout) {
|
|
222
|
-
request.setTimeout(this.timeout);
|
|
223
|
-
}
|
|
224
|
-
request.on('response', this._handleResponse.bind(this, callback));
|
|
225
|
-
request.on('error', function (error) {
|
|
226
|
-
callback(error, null);
|
|
227
|
-
});
|
|
228
|
-
request.once('timeout', function () {
|
|
229
|
-
request.abort();
|
|
230
|
-
});
|
|
231
|
-
request.end();
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Wraps knox request and manages request events
|
|
237
|
-
*
|
|
238
|
-
* @private
|
|
239
|
-
* @param {string} key
|
|
240
|
-
* @param {function} callback
|
|
241
|
-
*/
|
|
242
|
-
S3Client.prototype._get = function (key, headers, callback) {
|
|
243
|
-
var request = this._client.get(key, headers);
|
|
244
|
-
if (this.timeout) {
|
|
245
|
-
request.setTimeout(this.timeout);
|
|
246
|
-
}
|
|
247
|
-
request.on('response', this._handleResponse.bind(this, callback));
|
|
248
|
-
request.on('error', function (error) {
|
|
249
|
-
callback(error, null);
|
|
250
|
-
});
|
|
251
|
-
request.once('timeout', function () {
|
|
252
|
-
request.abort();
|
|
253
|
-
});
|
|
254
|
-
request.end();
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Wraps knox request and manages request events
|
|
260
|
-
*
|
|
261
|
-
* @private
|
|
262
|
-
* @param {string} key
|
|
263
|
-
* @param {function} callback
|
|
264
|
-
*/
|
|
265
|
-
S3Client.prototype._head = function (key, headers, callback) {
|
|
266
|
-
var request = this._client.head(key, headers);
|
|
267
|
-
if (this.timeout) {
|
|
268
|
-
request.setTimeout(this.timeout);
|
|
269
|
-
}
|
|
270
|
-
request.on('response', this._handleResponse.bind(this, callback));
|
|
271
|
-
request.on('error', function (error) {
|
|
272
|
-
callback(error, null);
|
|
273
|
-
});
|
|
274
|
-
request.once('timeout', function () {
|
|
275
|
-
request.abort();
|
|
276
|
-
});
|
|
277
|
-
request.end();
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Wraps knox request and manages request events
|
|
283
|
-
*
|
|
284
|
-
* @private
|
|
285
|
-
* @param {string} key
|
|
286
|
-
* @param {function} callback
|
|
287
|
-
*/
|
|
288
|
-
S3Client.prototype._del = function (key, callback) {
|
|
289
|
-
var request = this._client.del(key);
|
|
290
|
-
if (this.timeout) {
|
|
291
|
-
request.setTimeout(this.timeout);
|
|
292
|
-
}
|
|
293
|
-
request.on('response', this._handleResponse.bind(this, callback));
|
|
294
|
-
request.on('error', function (error) {
|
|
295
|
-
callback(error, null);
|
|
296
|
-
});
|
|
297
|
-
request.once('timeout', function () {
|
|
298
|
-
request.abort();
|
|
299
|
-
});
|
|
300
|
-
request.end();
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @private
|
|
305
|
-
* @param {function} callback
|
|
306
|
-
* @param {http.response} res
|
|
307
|
-
*/
|
|
308
|
-
S3Client.prototype._handleResponse = function (callback, res) {
|
|
309
|
-
var dataLength = 0;
|
|
310
|
-
var buffers = [];
|
|
311
|
-
|
|
312
|
-
res.on('data', function (data) {
|
|
313
|
-
buffers.push(data);
|
|
314
|
-
dataLength += data.length;
|
|
315
|
-
});
|
|
316
|
-
res.on('end', function () {
|
|
317
|
-
var resultBuffer = new Buffer(dataLength);
|
|
318
|
-
var bufferPosition = 0;
|
|
319
|
-
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
320
|
-
buffers[i].copy(resultBuffer, bufferPosition);
|
|
321
|
-
bufferPosition += buffers[i].length;
|
|
322
|
-
}
|
|
323
|
-
var response = new Response();
|
|
324
|
-
response.setStatusCode(res.statusCode);
|
|
325
|
-
response.setHeaders(res.headers);
|
|
326
|
-
response._setBody(resultBuffer);
|
|
327
|
-
|
|
328
|
-
callback(null, response);
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Function for handling retries
|
|
334
|
-
*
|
|
335
|
-
* @private
|
|
336
|
-
* @param {function} fnc function to call
|
|
337
|
-
* @param {function} callback callback fired when specified number
|
|
338
|
-
* of retries reached or response recieved
|
|
339
|
-
*/
|
|
340
|
-
S3Client.prototype._spawnFunction = function (fnc, callback) {
|
|
341
|
-
var maxRetry = this.retry;
|
|
342
|
-
|
|
343
|
-
fnc(function (err, data) {
|
|
344
|
-
if (err && maxRetry--) {
|
|
345
|
-
console.log('S3Client retrying operation...', maxRetry);
|
|
346
|
-
fnc(arguments.callee);
|
|
347
|
-
} else {
|
|
348
|
-
callback(err, data);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
S3Client.prototype._getError = function (err) {
|
|
354
|
-
var error = new Error(err.msg);
|
|
355
|
-
error.code = err.code;
|
|
356
|
-
|
|
357
|
-
return error;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Checks if passed ACL allows for public read.
|
|
362
|
-
*
|
|
363
|
-
* @param {Object} acl ACL
|
|
364
|
-
* @returns {Boolean} True or false depending on ACL configuration
|
|
365
|
-
*/
|
|
366
|
-
S3Client.isPublicRead = function (acl) {
|
|
367
|
-
try {
|
|
368
|
-
var grants = acl.AccessControlList.Grant;
|
|
369
|
-
var grant;
|
|
370
|
-
for (var i = 0, len = grants.length; i < len; i++) {
|
|
371
|
-
grant = grants[i];
|
|
372
|
-
|
|
373
|
-
if (grant.Grantee.URI == 'http://acs.amazonaws.com/groups/global/AllUsers') {
|
|
374
|
-
if (['READ', 'FULL_CONTROL'].indexOf(grant.Permission) != -1) {
|
|
375
|
-
return true;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return false;
|
|
380
|
-
} catch (ex) {
|
|
381
|
-
console.warn('S3Client error processing ACLs', ex);
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
S3Client.Error = {};
|
|
388
|
-
S3Client.Error.ENOBODY = {code: 'ENOBODY', msg: 'No body given'};
|
|
389
|
-
S3Client.Error.ENOKEY = {code: 'ENOKEY', msg: 'No key give'};
|
|
390
|
-
S3Client.Error.ENOHEADERS = {code: 'ENOHEADERS', msg: 'No headers given'};
|
|
391
|
-
|
|
392
|
-
exports.S3Client = S3Client;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
var Event = require('../../event/Event.js').Event;
|
|
2
|
-
var ErrorEvent = require('../../event/ErrorEvent.js').ErrorEvent;
|
|
3
|
-
var EventDispatcher = require('../../event/EventDispatcher.js').EventDispatcher;
|
|
4
|
-
|
|
5
|
-
var CursorQueryWorker = function (client) {
|
|
6
|
-
EventDispatcher.call(this);
|
|
7
|
-
this._client = client;
|
|
8
|
-
this._transactionOpened = false;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
CursorQueryWorker.prototype = Object.create(EventDispatcher.prototype);
|
|
12
|
-
|
|
13
|
-
CursorQueryWorker.prototype.query = function (sql, params, cursors) {
|
|
14
|
-
var that = this;
|
|
15
|
-
|
|
16
|
-
this.beginTransaction(function (data) {
|
|
17
|
-
that._execute(sql, params, function (result) {
|
|
18
|
-
if (result.rowCount == 0) {
|
|
19
|
-
that.endTransaction(function () {
|
|
20
|
-
/* zwracam do klienta dane, który otrzymałem z procedury */
|
|
21
|
-
that._dispatchLoaded(result);
|
|
22
|
-
});
|
|
23
|
-
} else {
|
|
24
|
-
var resultRow = result.rows[0];
|
|
25
|
-
that._fetchCursors(resultRow, cursors, function () {
|
|
26
|
-
that.endTransaction(function () {
|
|
27
|
-
that._dispatchLoaded(result);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
CursorQueryWorker.prototype._handleError = function (error) {
|
|
36
|
-
var that = this;
|
|
37
|
-
|
|
38
|
-
if (this._isFatalError.call(this, error)) { /* fatal - padło połączenie */
|
|
39
|
-
this._dispatchError(error);
|
|
40
|
-
} else if (this._transactionOpened) { /* error ale mam otwartą transakcję */
|
|
41
|
-
this.endTransaction(function (err, data) {
|
|
42
|
-
return that._dispatchError(error); /* oddaje wejściowy błąd */
|
|
43
|
-
});
|
|
44
|
-
} else { /* nie fatal i zamknięta transakcja */
|
|
45
|
-
this._dispatchError(error);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
CursorQueryWorker.prototype._dispatchError = function (err) {
|
|
50
|
-
console.log('CursorQueryWorker:', 'dispatchError');
|
|
51
|
-
this.dispatchEvent(new ErrorEvent(CursorQueryWorker.Event.ERROR, err));
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
CursorQueryWorker.prototype._dispatchLoaded = function (data) {
|
|
55
|
-
console.log('CursorQueryWorker:', 'dispatchLoaded');
|
|
56
|
-
this.dispatchEvent(new Event(CursorQueryWorker.Event.LOADED, data));
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
CursorQueryWorker.prototype.beginTransaction = function (callback) {
|
|
60
|
-
var that = this;
|
|
61
|
-
|
|
62
|
-
this._client.query('BEGIN', [], function (err, data) {
|
|
63
|
-
that._transactionOpened = true;
|
|
64
|
-
if (err) {
|
|
65
|
-
return that._handleError(err);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return callback(data);
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
CursorQueryWorker.prototype.endTransaction = function (callback) {
|
|
73
|
-
var that = this;
|
|
74
|
-
this._client.query("COMMIT", [], function (err, data) {
|
|
75
|
-
that._transactionOpened = false;
|
|
76
|
-
if (err) {
|
|
77
|
-
return that._handleError(err);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return callback(data);
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
CursorQueryWorker.prototype._execute = function (sql, params, callback) {
|
|
85
|
-
var that = this;
|
|
86
|
-
this._client.query(sql, params, function (err, data) {
|
|
87
|
-
if (err) {
|
|
88
|
-
return that._handleError(err);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return callback(data);
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
CursorQueryWorker.prototype._getCursorMap = function (result, cursors) {
|
|
95
|
-
var cursorsMap = [];
|
|
96
|
-
|
|
97
|
-
for (var i = 0, len = cursors.length; i < len; i++) {
|
|
98
|
-
var cursorField = cursors[i];
|
|
99
|
-
cursorsMap.push({
|
|
100
|
-
field: cursorField,
|
|
101
|
-
cursor: result[cursorField]
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return cursorsMap;
|
|
106
|
-
};
|
|
107
|
-
CursorQueryWorker.prototype._fetchCursors = function (result, cursors, callback) {
|
|
108
|
-
var that = this;
|
|
109
|
-
|
|
110
|
-
/* no cursors to fetch */
|
|
111
|
-
if (!cursors.length) {
|
|
112
|
-
return callback(null);
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
var cursorsMap = this._getCursorMap(result, cursors);
|
|
116
|
-
var counter = cursorsMap.length;
|
|
117
|
-
|
|
118
|
-
var spawnFetchCursor = function (err) {
|
|
119
|
-
if (err) {
|
|
120
|
-
return that._handleError(err);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (!counter) {
|
|
124
|
-
/* w error musi być null */
|
|
125
|
-
return callback(err);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/* decrementing counter */
|
|
129
|
-
counter -= 1;
|
|
130
|
-
return that._fetchCursor(cursorsMap[counter], result, spawnFetchCursor);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
return spawnFetchCursor(null);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
CursorQueryWorker.prototype._fetchCursor = function (map, result, callback) {
|
|
137
|
-
console.log('PGPool:', 'fetching cursor', map);
|
|
138
|
-
var that = this;
|
|
139
|
-
var query = 'FETCH ALL FROM "' + map.cursor + '"';
|
|
140
|
-
this._client.query(query, [], function (err, data) {
|
|
141
|
-
if (err) {
|
|
142
|
-
return callback(err);
|
|
143
|
-
}
|
|
144
|
-
/* replacing result field with data from cursor */
|
|
145
|
-
result[map.field] = data.rows;
|
|
146
|
-
return callback(err, data);
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
CursorQueryWorker.prototype._isFatalError = function (err) {
|
|
151
|
-
var PGPool = require('../PGPool.js').PGPool;
|
|
152
|
-
return PGPool.prototype._isFatalError.call(this, err);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
CursorQueryWorker.Event = {};
|
|
156
|
-
CursorQueryWorker.Event.LOADED = 'CursorQueryWorker_LOADED';
|
|
157
|
-
CursorQueryWorker.Event.ERROR = 'CursorQueryWorker_ERROR';
|
|
158
|
-
CursorQueryWorker.Event.FATAL_ERROR = 'CursorQueryWorker_FATAL_ERROR';
|
|
159
|
-
|
|
160
|
-
exports.CursorQueryWorker = CursorQueryWorker;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var Event = require('../../event/Event').Event;
|
|
2
|
-
var EventDispatcher = require('../../event/EventDispatcher').EventDispatcher;
|
|
3
|
-
var RbmqConnection = require('./RbmqConnection').RbmqConnection;
|
|
4
|
-
|
|
5
|
-
var RbmqChannel = function(rbmqConnection, config) {
|
|
6
|
-
EventDispatcher.call(this);
|
|
7
|
-
|
|
8
|
-
this._config = null;
|
|
9
|
-
this._opened = false;
|
|
10
|
-
this._rbmqConnection = rbmqConnection;
|
|
11
|
-
this._rbmqChannel = null;
|
|
12
|
-
|
|
13
|
-
this.setConfig(config);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
RbmqChannel.prototype = Object.create(EventDispatcher.prototype);
|
|
17
|
-
|
|
18
|
-
RbmqChannel.prototype.setConfig = function(config) {
|
|
19
|
-
this._config = config;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
RbmqChannel.prototype.isOpened = function() {
|
|
23
|
-
return this._opened;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
RbmqChannel.prototype.open = function() {
|
|
27
|
-
var that = this;
|
|
28
|
-
|
|
29
|
-
this._rbmqChannel.on('open', function() {
|
|
30
|
-
that._onChannelOpened();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
this._rbmqChannel.on('close', function() {
|
|
34
|
-
that._onChannelClosed();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
this._rbmqConnection.addEventListener(RbmqConnection.Event.DISCONNECTED, this._onChannelClosed, this);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
RbmqChannel.prototype._onChannelOpened = function() {
|
|
41
|
-
console.log('RbmqChannel/_onChannelOpened');
|
|
42
|
-
this._opened = true;
|
|
43
|
-
this.dispatchEvent(new Event(RbmqChannel.Event.OPENED));
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
RbmqChannel.prototype._onChannelClosed = function() {
|
|
47
|
-
console.log('RbmqChannel/_onChannelClosed');
|
|
48
|
-
this._opened = false;
|
|
49
|
-
if (this._rbmqChannel) {
|
|
50
|
-
this._rbmqConnection.removeEventListener(RbmqConnection.Event.DISCONNECTED, this._onChannelClosed);
|
|
51
|
-
this._rbmqChannel.removeAllListeners();
|
|
52
|
-
this._rbmqChannel = null;
|
|
53
|
-
}
|
|
54
|
-
this.dispatchEvent(new Event(RbmqChannel.Event.CLOSED));
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
RbmqChannel.Event = {};
|
|
58
|
-
RbmqChannel.Event.OPENED = 'RbmqChannel.Event.OPENED';
|
|
59
|
-
RbmqChannel.Event.CLOSED = 'RbmqChannel.Event.CLOSED';
|
|
60
|
-
|
|
61
|
-
exports.RbmqChannel = RbmqChannel;
|