typespeed 2.0.21 → 2.0.22
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/core.decorator.js +1 -30
- package/dist/default/default-authentication.class.js +25 -0
- package/dist/default/express-server.class.js +11 -4
- package/dist/default/log-default.class.js +0 -6
- package/dist/factory/authentication-factory.class.js +11 -0
- package/dist/factory/log-factory.class.js +9 -0
- package/dist/route.decorator.js +92 -2
- package/dist/typespeed.d.ts +25 -3
- package/dist/typespeed.js +3 -1
- package/package.json +1 -1
- package/src/core.decorator.ts +1 -29
- package/src/default/default-authentication.class.ts +10 -0
- package/src/default/express-server.class.ts +12 -5
- package/src/default/log-default.class.ts +0 -10
- package/src/factory/authentication-factory.class.ts +9 -0
- package/src/factory/log-factory.class.ts +9 -2
- package/src/route.decorator.ts +91 -3
- package/src/typespeed.d.ts +25 -3
- package/src/typespeed.ts +1 -0
- package/test/node_modules/.package-lock.json +65 -101
- package/test/node_modules/@types/body-parser/LICENSE +21 -0
- package/test/node_modules/@types/body-parser/README.md +16 -0
- package/test/node_modules/@types/body-parser/index.d.ts +107 -0
- package/test/node_modules/@types/body-parser/package.json +58 -0
- package/test/node_modules/@types/connect/LICENSE +21 -0
- package/test/node_modules/@types/connect/README.md +16 -0
- package/test/node_modules/@types/connect/index.d.ts +93 -0
- package/test/node_modules/@types/connect/package.json +32 -0
- package/test/node_modules/@types/express/LICENSE +21 -0
- package/test/node_modules/@types/express/README.md +16 -0
- package/test/node_modules/@types/express/index.d.ts +136 -0
- package/test/node_modules/@types/express/package.json +45 -0
- package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
- package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
- package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
- package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
- package/test/node_modules/@types/mime/LICENSE +21 -0
- package/test/node_modules/@types/mime/Mime.d.ts +10 -0
- package/test/node_modules/@types/mime/README.md +16 -0
- package/test/node_modules/@types/mime/index.d.ts +35 -0
- package/test/node_modules/@types/mime/lite.d.ts +7 -0
- package/test/node_modules/@types/mime/package.json +29 -0
- package/test/node_modules/@types/qs/LICENSE +21 -0
- package/test/node_modules/@types/qs/README.md +16 -0
- package/test/node_modules/@types/qs/index.d.ts +62 -0
- package/test/node_modules/@types/qs/package.json +65 -0
- package/test/node_modules/@types/range-parser/LICENSE +21 -0
- package/test/node_modules/@types/range-parser/README.md +55 -0
- package/test/node_modules/@types/range-parser/index.d.ts +35 -0
- package/test/node_modules/@types/range-parser/package.json +25 -0
- package/test/node_modules/@types/send/LICENSE +21 -0
- package/test/node_modules/@types/send/README.md +16 -0
- package/test/node_modules/@types/send/index.d.ts +231 -0
- package/test/node_modules/@types/send/package.json +33 -0
- package/test/node_modules/@types/serve-static/LICENSE +21 -0
- package/test/node_modules/@types/serve-static/README.md +16 -0
- package/test/node_modules/@types/serve-static/index.d.ts +113 -0
- package/test/node_modules/@types/serve-static/package.json +38 -0
- package/test/src/config.json +5 -0
- package/test/src/custom-log.class.ts +6 -0
- package/test/src/jwt-authentication.class.ts +29 -0
- package/test/src/test-request.class.ts +36 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
- package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
- package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
- package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
- package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
- package/test/node_modules/amqplib/CHANGELOG.md +0 -430
- package/test/node_modules/amqplib/LICENSE +0 -6
- package/test/node_modules/amqplib/LICENSE-MIT +0 -21
- package/test/node_modules/amqplib/Makefile +0 -47
- package/test/node_modules/amqplib/README.md +0 -157
- package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
- package/test/node_modules/amqplib/callback_api.js +0 -22
- package/test/node_modules/amqplib/channel_api.js +0 -16
- package/test/node_modules/amqplib/examples/headers.js +0 -42
- package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
- package/test/node_modules/amqplib/examples/send_generators.js +0 -42
- package/test/node_modules/amqplib/examples/ssl.js +0 -64
- package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
- package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
- package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
- package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
- package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
- package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
- package/test/node_modules/amqplib/lib/api_args.js +0 -314
- package/test/node_modules/amqplib/lib/bitset.js +0 -130
- package/test/node_modules/amqplib/lib/callback_model.js +0 -327
- package/test/node_modules/amqplib/lib/channel.js +0 -499
- package/test/node_modules/amqplib/lib/channel_model.js +0 -302
- package/test/node_modules/amqplib/lib/codec.js +0 -321
- package/test/node_modules/amqplib/lib/connect.js +0 -189
- package/test/node_modules/amqplib/lib/connection.js +0 -663
- package/test/node_modules/amqplib/lib/credentials.js +0 -42
- package/test/node_modules/amqplib/lib/defs.js +0 -4966
- package/test/node_modules/amqplib/lib/error.js +0 -24
- package/test/node_modules/amqplib/lib/format.js +0 -40
- package/test/node_modules/amqplib/lib/frame.js +0 -113
- package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
- package/test/node_modules/amqplib/lib/mux.js +0 -129
- package/test/node_modules/amqplib/package.json +0 -37
- package/test/node_modules/amqplib/test/bitset.js +0 -69
- package/test/node_modules/amqplib/test/callback_api.js +0 -312
- package/test/node_modules/amqplib/test/channel.js +0 -621
- package/test/node_modules/amqplib/test/channel_api.js +0 -596
- package/test/node_modules/amqplib/test/codec.js +0 -237
- package/test/node_modules/amqplib/test/connect.js +0 -197
- package/test/node_modules/amqplib/test/connection.js +0 -390
- package/test/node_modules/amqplib/test/data.js +0 -254
- package/test/node_modules/amqplib/test/frame.js +0 -198
- package/test/node_modules/amqplib/test/mux.js +0 -204
- package/test/node_modules/amqplib/test/util.js +0 -219
- package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
- package/test/node_modules/buffer-more-ints/LICENSE +0 -19
- package/test/node_modules/buffer-more-ints/README.md +0 -69
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
- package/test/node_modules/buffer-more-ints/package.json +0 -19
- package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
- package/test/node_modules/core-util-is/LICENSE +0 -19
- package/test/node_modules/core-util-is/README.md +0 -3
- package/test/node_modules/core-util-is/lib/util.js +0 -107
- package/test/node_modules/core-util-is/package.json +0 -38
- package/test/node_modules/debug/LICENSE +0 -20
- package/test/node_modules/debug/README.md +0 -481
- package/test/node_modules/debug/package.json +0 -59
- package/test/node_modules/debug/src/browser.js +0 -269
- package/test/node_modules/debug/src/common.js +0 -274
- package/test/node_modules/debug/src/index.js +0 -10
- package/test/node_modules/debug/src/node.js +0 -263
- package/test/node_modules/inherits/LICENSE +0 -16
- package/test/node_modules/inherits/README.md +0 -42
- package/test/node_modules/inherits/inherits.js +0 -9
- package/test/node_modules/inherits/inherits_browser.js +0 -27
- package/test/node_modules/inherits/package.json +0 -29
- package/test/node_modules/isarray/README.md +0 -54
- package/test/node_modules/isarray/build/build.js +0 -209
- package/test/node_modules/isarray/component.json +0 -19
- package/test/node_modules/isarray/index.js +0 -3
- package/test/node_modules/isarray/package.json +0 -25
- package/test/node_modules/ms/index.js +0 -162
- package/test/node_modules/ms/license.md +0 -21
- package/test/node_modules/ms/package.json +0 -37
- package/test/node_modules/ms/readme.md +0 -60
- package/test/node_modules/querystringify/LICENSE +0 -22
- package/test/node_modules/querystringify/README.md +0 -61
- package/test/node_modules/querystringify/index.js +0 -118
- package/test/node_modules/querystringify/package.json +0 -38
- package/test/node_modules/readable-stream/LICENSE +0 -18
- package/test/node_modules/readable-stream/README.md +0 -15
- package/test/node_modules/readable-stream/duplex.js +0 -1
- package/test/node_modules/readable-stream/float.patch +0 -923
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
- package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
- package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
- package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
- package/test/node_modules/readable-stream/package.json +0 -32
- package/test/node_modules/readable-stream/passthrough.js +0 -1
- package/test/node_modules/readable-stream/readable.js +0 -10
- package/test/node_modules/readable-stream/transform.js +0 -1
- package/test/node_modules/readable-stream/writable.js +0 -1
- package/test/node_modules/requires-port/.travis.yml +0 -19
- package/test/node_modules/requires-port/LICENSE +0 -22
- package/test/node_modules/requires-port/README.md +0 -47
- package/test/node_modules/requires-port/index.js +0 -38
- package/test/node_modules/requires-port/package.json +0 -47
- package/test/node_modules/requires-port/test.js +0 -98
- package/test/node_modules/safe-buffer/LICENSE +0 -21
- package/test/node_modules/safe-buffer/README.md +0 -584
- package/test/node_modules/safe-buffer/index.d.ts +0 -187
- package/test/node_modules/safe-buffer/index.js +0 -62
- package/test/node_modules/safe-buffer/package.json +0 -37
- package/test/node_modules/string_decoder/LICENSE +0 -20
- package/test/node_modules/string_decoder/README.md +0 -7
- package/test/node_modules/string_decoder/index.js +0 -221
- package/test/node_modules/string_decoder/package.json +0 -25
- package/test/node_modules/url-parse/LICENSE +0 -22
- package/test/node_modules/url-parse/README.md +0 -153
- package/test/node_modules/url-parse/dist/url-parse.js +0 -755
- package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
- package/test/node_modules/url-parse/index.js +0 -589
- package/test/node_modules/url-parse/package.json +0 -49
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var assert = require('assert');
|
|
4
|
-
var succeed = require('./util').succeed;
|
|
5
|
-
var fail = require('./util').fail;
|
|
6
|
-
var connection = require('../lib/connection');
|
|
7
|
-
var Frames = connection.Connection;
|
|
8
|
-
var HEARTBEAT = require('../lib/frame').HEARTBEAT;
|
|
9
|
-
var Stream = require('stream');
|
|
10
|
-
var PassThrough = Stream.PassThrough ||
|
|
11
|
-
require('readable-stream/passthrough');
|
|
12
|
-
|
|
13
|
-
var defs = require('../lib/defs');
|
|
14
|
-
|
|
15
|
-
// We'll need to supply a stream which we manipulate ourselves
|
|
16
|
-
|
|
17
|
-
function inputs() {
|
|
18
|
-
// don't coalesce buffers, since that could mess up properties
|
|
19
|
-
// (e.g., encoded frame size)
|
|
20
|
-
return new PassThrough({objectMode: true});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var HB = Buffer.from([defs.constants.FRAME_HEARTBEAT,
|
|
24
|
-
0, 0, // channel 0
|
|
25
|
-
0, 0, 0, 0, // zero size
|
|
26
|
-
defs.constants.FRAME_END]);
|
|
27
|
-
|
|
28
|
-
suite("Explicit parsing", function() {
|
|
29
|
-
|
|
30
|
-
test('Parse heartbeat', function() {
|
|
31
|
-
var input = inputs();
|
|
32
|
-
var frames = new Frames(input);
|
|
33
|
-
input.write(HB);
|
|
34
|
-
assert(frames.recvFrame() === HEARTBEAT);
|
|
35
|
-
assert(!frames.recvFrame());
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('Parse partitioned', function() {
|
|
39
|
-
var input = inputs();
|
|
40
|
-
var frames = new Frames(input);
|
|
41
|
-
input.write(HB.slice(0, 3));
|
|
42
|
-
assert(!frames.recvFrame());
|
|
43
|
-
input.write(HB.slice(3));
|
|
44
|
-
assert(frames.recvFrame() === HEARTBEAT);
|
|
45
|
-
assert(!frames.recvFrame());
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
function testBogusFrame(name, bytes) {
|
|
49
|
-
test(name, function(done) {
|
|
50
|
-
var input = inputs();
|
|
51
|
-
var frames = new Frames(input);
|
|
52
|
-
frames.frameMax = 5; //for the max frame test
|
|
53
|
-
input.write(Buffer.from(bytes));
|
|
54
|
-
frames.step(function(err, frame) {
|
|
55
|
-
if (err != null) done();
|
|
56
|
-
else done(new Error('Was a bogus frame!'));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
testBogusFrame('Wrong sized frame',
|
|
62
|
-
[defs.constants.FRAME_BODY,
|
|
63
|
-
0,0, 0,0,0,0, // zero length
|
|
64
|
-
65, // but a byte!
|
|
65
|
-
defs.constants.FRAME_END]);
|
|
66
|
-
|
|
67
|
-
testBogusFrame('Unknown method frame',
|
|
68
|
-
[defs.constants.FRAME_METHOD,
|
|
69
|
-
0,0, 0,0,0,4,
|
|
70
|
-
0,0,0,0, // garbage ID
|
|
71
|
-
defs.constants.FRAME_END]);
|
|
72
|
-
|
|
73
|
-
testBogusFrame('> max frame',
|
|
74
|
-
[defs.constants.FRAME_BODY,
|
|
75
|
-
0,0, 0,0,0,6, // too big!
|
|
76
|
-
65,66,67,68,69,70,
|
|
77
|
-
defs.constants.FRAME_END]);
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Now for a bit more fun.
|
|
82
|
-
|
|
83
|
-
var amqp = require('./data');
|
|
84
|
-
var claire = require('claire');
|
|
85
|
-
var choice = claire.choice;
|
|
86
|
-
var forAll = claire.forAll;
|
|
87
|
-
var repeat = claire.repeat;
|
|
88
|
-
var label = claire.label;
|
|
89
|
-
var sequence = claire.sequence;
|
|
90
|
-
var transform = claire.transform;
|
|
91
|
-
var sized = claire.sized;
|
|
92
|
-
|
|
93
|
-
var assertEqualModuloDefaults =
|
|
94
|
-
require('./codec').assertEqualModuloDefaults;
|
|
95
|
-
|
|
96
|
-
var Trace = label('frame trace',
|
|
97
|
-
repeat(choice.apply(choice, amqp.methods)));
|
|
98
|
-
|
|
99
|
-
suite("Parsing", function() {
|
|
100
|
-
|
|
101
|
-
function testPartitioning(partition) {
|
|
102
|
-
return forAll(Trace).satisfy(function(t) {
|
|
103
|
-
var bufs = [];
|
|
104
|
-
var input = inputs();
|
|
105
|
-
var frames = new Frames(input);
|
|
106
|
-
var i = 0, ex;
|
|
107
|
-
frames.accept = function(f) {
|
|
108
|
-
// A minor hack to make sure we get the assertion exception;
|
|
109
|
-
// otherwise, it's just a test that we reached the line
|
|
110
|
-
// incrementing `i` for each frame.
|
|
111
|
-
try {
|
|
112
|
-
assertEqualModuloDefaults(t[i], f.fields);
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
115
|
-
ex = e;
|
|
116
|
-
}
|
|
117
|
-
i++;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
t.forEach(function(f) {
|
|
121
|
-
f.channel = 0;
|
|
122
|
-
bufs.push(defs.encodeMethod(f.id, 0, f.fields));
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
partition(bufs).forEach(function (chunk) { input.write(chunk); });
|
|
126
|
-
frames.acceptLoop();
|
|
127
|
-
if (ex) throw ex;
|
|
128
|
-
return i === t.length;
|
|
129
|
-
}).asTest({times: 20})
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
test("Parse trace of methods",
|
|
133
|
-
testPartitioning(function(bufs) { return bufs; }));
|
|
134
|
-
|
|
135
|
-
test("Parse concat'd methods",
|
|
136
|
-
testPartitioning(function(bufs) {
|
|
137
|
-
return [Buffer.concat(bufs)];
|
|
138
|
-
}));
|
|
139
|
-
|
|
140
|
-
test("Parse partitioned methods",
|
|
141
|
-
testPartitioning(function(bufs) {
|
|
142
|
-
var full = Buffer.concat(bufs);
|
|
143
|
-
var onethird = Math.floor(full.length / 3);
|
|
144
|
-
var twothirds = 2 * onethird;
|
|
145
|
-
return [
|
|
146
|
-
full.slice(0, onethird),
|
|
147
|
-
full.slice(onethird, twothirds),
|
|
148
|
-
full.slice(twothirds)
|
|
149
|
-
];
|
|
150
|
-
}));
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
var FRAME_MAX_MAX = 4096 * 4;
|
|
154
|
-
var FRAME_MAX_MIN = 4096;
|
|
155
|
-
|
|
156
|
-
var FrameMax = amqp.rangeInt('frame max',
|
|
157
|
-
FRAME_MAX_MIN,
|
|
158
|
-
FRAME_MAX_MAX);
|
|
159
|
-
|
|
160
|
-
var Body = sized(function(_n) {
|
|
161
|
-
return Math.floor(Math.random() * FRAME_MAX_MAX);
|
|
162
|
-
}, repeat(amqp.Octet));
|
|
163
|
-
|
|
164
|
-
var Content = transform(function(args) {
|
|
165
|
-
return {
|
|
166
|
-
method: args[0].fields,
|
|
167
|
-
header: args[1].fields,
|
|
168
|
-
body: Buffer.from(args[2])
|
|
169
|
-
}
|
|
170
|
-
}, sequence(amqp.methods['BasicDeliver'],
|
|
171
|
-
amqp.properties['BasicProperties'], Body));
|
|
172
|
-
|
|
173
|
-
suite("Content framing", function() {
|
|
174
|
-
test("Adhere to frame max",
|
|
175
|
-
forAll(Content, FrameMax).satisfy(function(content, max) {
|
|
176
|
-
var input = inputs();
|
|
177
|
-
var frames = new Frames(input);
|
|
178
|
-
frames.frameMax = max;
|
|
179
|
-
frames.sendMessage(
|
|
180
|
-
0,
|
|
181
|
-
defs.BasicDeliver, content.method,
|
|
182
|
-
defs.BasicProperties, content.header,
|
|
183
|
-
content.body);
|
|
184
|
-
var f, i = 0, largest = 0;
|
|
185
|
-
while (f = input.read()) {
|
|
186
|
-
i++;
|
|
187
|
-
if (f.length > largest) largest = f.length;
|
|
188
|
-
if (f.length > max) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// The ratio of frames to 'contents' should always be >= 2
|
|
193
|
-
// (one properties frame and at least one content frame); > 2
|
|
194
|
-
// indicates fragmentation. The largest is always, of course <= frame max
|
|
195
|
-
//console.log('Frames: %d; frames per message: %d; largest frame %d', i, i / t.length, largest);
|
|
196
|
-
return true;
|
|
197
|
-
}).asTest());
|
|
198
|
-
});
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var assert = require('assert');
|
|
4
|
-
var Mux = require('../lib/mux').Mux;
|
|
5
|
-
var PassThrough = require('stream').PassThrough ||
|
|
6
|
-
require('readable-stream/passthrough');
|
|
7
|
-
|
|
8
|
-
var latch = require('./util').latch;
|
|
9
|
-
var schedule = require('./util').schedule;
|
|
10
|
-
|
|
11
|
-
function stream() {
|
|
12
|
-
return new PassThrough({objectMode: true});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function readAllObjects(s, cb) {
|
|
16
|
-
var objs = [];
|
|
17
|
-
|
|
18
|
-
function read() {
|
|
19
|
-
var v = s.read();
|
|
20
|
-
while (v !== null) {
|
|
21
|
-
objs.push(v);
|
|
22
|
-
v = s.read();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
s.on('end', function() { cb(objs); });
|
|
27
|
-
s.on('readable', read);
|
|
28
|
-
|
|
29
|
-
read();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
test("single input", function(done) {
|
|
33
|
-
var input = stream();
|
|
34
|
-
var output = stream();
|
|
35
|
-
input.on('end', function() { output.end() });
|
|
36
|
-
|
|
37
|
-
var mux = new Mux(output);
|
|
38
|
-
mux.pipeFrom(input);
|
|
39
|
-
|
|
40
|
-
var data = [1,2,3,4,5,6,7,8,9];
|
|
41
|
-
// not 0, it's treated specially by PassThrough for some reason. By
|
|
42
|
-
// 'specially' I mean it breaks the stream. See e.g.,
|
|
43
|
-
// https://github.com/isaacs/readable-stream/pull/55
|
|
44
|
-
data.forEach(function (chunk) { input.write(chunk); });
|
|
45
|
-
|
|
46
|
-
readAllObjects(output, function(vals) {
|
|
47
|
-
assert.deepEqual(data, vals);
|
|
48
|
-
done();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
input.end();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("single input, resuming stream", function(done) {
|
|
55
|
-
var input = stream();
|
|
56
|
-
var output = stream();
|
|
57
|
-
input.on('end', function() { output.end() });
|
|
58
|
-
|
|
59
|
-
var mux = new Mux(output);
|
|
60
|
-
mux.pipeFrom(input);
|
|
61
|
-
|
|
62
|
-
// Streams might be blocked and become readable again, simulate this
|
|
63
|
-
// using a special read function and a marker
|
|
64
|
-
var data = [1,2,3,4,'skip',6,7,8,9];
|
|
65
|
-
|
|
66
|
-
var oldRead = input.read;
|
|
67
|
-
input.read = function(size) {
|
|
68
|
-
var val = oldRead.call(input, size)
|
|
69
|
-
|
|
70
|
-
if (val === 'skip') {
|
|
71
|
-
input.emit('readable');
|
|
72
|
-
return null
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return val;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
data.forEach(function (chunk) { input.write(chunk); });
|
|
79
|
-
|
|
80
|
-
readAllObjects(output, function(vals) {
|
|
81
|
-
assert.deepEqual([1,2,3,4,6,7,8,9], vals);
|
|
82
|
-
done();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
input.end();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("two sequential inputs", function(done) {
|
|
89
|
-
var input1 = stream();
|
|
90
|
-
var input2 = stream();
|
|
91
|
-
var output = stream();
|
|
92
|
-
var mux = new Mux(output);
|
|
93
|
-
mux.pipeFrom(input1);
|
|
94
|
-
mux.pipeFrom(input2);
|
|
95
|
-
|
|
96
|
-
var data = [1,2,3,4,5,6,7,8,9];
|
|
97
|
-
data.forEach(function(v) { input1.write(v); });
|
|
98
|
-
|
|
99
|
-
input1.on('end', function() {
|
|
100
|
-
data.forEach(function (v) { input2.write(v); });
|
|
101
|
-
input2.end();
|
|
102
|
-
});
|
|
103
|
-
input2.on('end', function() { output.end(); });
|
|
104
|
-
|
|
105
|
-
input1.end();
|
|
106
|
-
readAllObjects(output, function(vs) {
|
|
107
|
-
assert.equal(2 * data.length, vs.length);
|
|
108
|
-
done();
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("two interleaved inputs", function(done) {
|
|
113
|
-
var input1 = stream();
|
|
114
|
-
var input2 = stream();
|
|
115
|
-
var output = stream();
|
|
116
|
-
var mux = new Mux(output);
|
|
117
|
-
mux.pipeFrom(input1);
|
|
118
|
-
mux.pipeFrom(input2);
|
|
119
|
-
|
|
120
|
-
var endLatch = latch(2, function() { output.end(); });
|
|
121
|
-
input1.on('end', endLatch);
|
|
122
|
-
input2.on('end', endLatch);
|
|
123
|
-
|
|
124
|
-
var data = [1,2,3,4,5,6,7,8,9];
|
|
125
|
-
data.forEach(function(v) { input1.write(v); });
|
|
126
|
-
input1.end();
|
|
127
|
-
|
|
128
|
-
data.forEach(function(v) { input2.write(v); });
|
|
129
|
-
input2.end();
|
|
130
|
-
|
|
131
|
-
readAllObjects(output, function(vs) {
|
|
132
|
-
assert.equal(2 * data.length, vs.length);
|
|
133
|
-
done();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test("unpipe", function(done) {
|
|
138
|
-
var input = stream();
|
|
139
|
-
var output = stream();
|
|
140
|
-
var mux = new Mux(output);
|
|
141
|
-
|
|
142
|
-
var pipedData = [1,2,3,4,5];
|
|
143
|
-
var unpipedData = [6,7,8,9];
|
|
144
|
-
|
|
145
|
-
mux.pipeFrom(input);
|
|
146
|
-
|
|
147
|
-
schedule(function() {
|
|
148
|
-
pipedData.forEach(function (chunk) { input.write(chunk); });
|
|
149
|
-
|
|
150
|
-
schedule(function() {
|
|
151
|
-
mux.unpipeFrom(input);
|
|
152
|
-
|
|
153
|
-
schedule(function() {
|
|
154
|
-
unpipedData.forEach(function(chunk) { input.write(chunk); });
|
|
155
|
-
input.end();
|
|
156
|
-
schedule(function() {
|
|
157
|
-
// exhaust so that 'end' fires
|
|
158
|
-
var v; while (v = input.read());
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
input.on('end', function() {
|
|
166
|
-
output.end();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
readAllObjects(output, function(vals) {
|
|
170
|
-
try {
|
|
171
|
-
assert.deepEqual(pipedData, vals);
|
|
172
|
-
done();
|
|
173
|
-
}
|
|
174
|
-
catch (e) { done(e); }
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test("roundrobin", function(done) {
|
|
179
|
-
var input1 = stream();
|
|
180
|
-
var input2 = stream();
|
|
181
|
-
var output = stream();
|
|
182
|
-
var mux = new Mux(output);
|
|
183
|
-
|
|
184
|
-
mux.pipeFrom(input1);
|
|
185
|
-
mux.pipeFrom(input2);
|
|
186
|
-
|
|
187
|
-
var endLatch = latch(2, function() { output.end(); });
|
|
188
|
-
input1.on('end', endLatch);
|
|
189
|
-
input2.on('end', endLatch);
|
|
190
|
-
|
|
191
|
-
var ones = [1,1,1,1,1];
|
|
192
|
-
ones.forEach(function(v) { input1.write(v); });
|
|
193
|
-
input1.end();
|
|
194
|
-
|
|
195
|
-
var twos = [2,2,2,2,2];
|
|
196
|
-
twos.forEach(function(v) { input2.write(v); });
|
|
197
|
-
input2.end();
|
|
198
|
-
|
|
199
|
-
readAllObjects(output, function(vs) {
|
|
200
|
-
assert.deepEqual([1,2,1,2,1,2,1,2,1,2], vs);
|
|
201
|
-
done();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
});
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
var Connection = require('../lib/connection').Connection;
|
|
5
|
-
var PassThrough =
|
|
6
|
-
require('stream').PassThrough ||
|
|
7
|
-
require('readable-stream/passthrough');
|
|
8
|
-
var defs = require('../lib/defs');
|
|
9
|
-
var assert = require('assert');
|
|
10
|
-
|
|
11
|
-
var schedule = (typeof setImmediate === 'function') ?
|
|
12
|
-
setImmediate : process.nextTick;
|
|
13
|
-
|
|
14
|
-
function randomString() {
|
|
15
|
-
var hash = crypto.createHash('sha1');
|
|
16
|
-
hash.update(crypto.randomBytes(64));
|
|
17
|
-
return hash.digest('base64');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// Set up a socket pair {client, server}, such that writes to the
|
|
22
|
-
// client are readable from the server, and writes to the server are
|
|
23
|
-
// readable at the client.
|
|
24
|
-
//
|
|
25
|
-
// +---+ +---+
|
|
26
|
-
// | C | | S |
|
|
27
|
-
// --write->| l |----->| e |--read-->
|
|
28
|
-
// | i | | r |
|
|
29
|
-
// <--read--| e |<-----| v |<-write--
|
|
30
|
-
// | n | | e |
|
|
31
|
-
// | t | | r |
|
|
32
|
-
// +---+ +---+
|
|
33
|
-
//
|
|
34
|
-
// I also need to make sure that end called on either socket affects
|
|
35
|
-
// the other.
|
|
36
|
-
|
|
37
|
-
function socketPair() {
|
|
38
|
-
var server = new PassThrough();
|
|
39
|
-
var client = new PassThrough();
|
|
40
|
-
server.write = client.push.bind(client);
|
|
41
|
-
client.write = server.push.bind(server);
|
|
42
|
-
function end(chunk, encoding) {
|
|
43
|
-
if (chunk) this.push(chunk, encoding);
|
|
44
|
-
this.push(null);
|
|
45
|
-
}
|
|
46
|
-
server.end = end.bind(client);
|
|
47
|
-
client.end = end.bind(server);
|
|
48
|
-
|
|
49
|
-
return {client: client, server: server};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function runServer(socket, run) {
|
|
53
|
-
var frames = new Connection(socket);
|
|
54
|
-
// We will be closing the socket without doing a closing handshake,
|
|
55
|
-
// so cheat
|
|
56
|
-
frames.expectSocketClose = true;
|
|
57
|
-
// We also need to create some channel buffers, again a cheat
|
|
58
|
-
frames.freshChannel(null);
|
|
59
|
-
frames.freshChannel(null);
|
|
60
|
-
frames.freshChannel(null);
|
|
61
|
-
|
|
62
|
-
function send(id, fields, channel, content) {
|
|
63
|
-
channel = channel || 0;
|
|
64
|
-
if (content) {
|
|
65
|
-
schedule(function() {
|
|
66
|
-
frames.sendMessage(channel, id, fields,
|
|
67
|
-
defs.BasicProperties, fields,
|
|
68
|
-
content);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
schedule(function() {
|
|
73
|
-
frames.sendMethod(channel, id, fields);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function wait(method) {
|
|
79
|
-
return function() {
|
|
80
|
-
return new Promise(function(resolve, reject) {
|
|
81
|
-
if (method) {
|
|
82
|
-
frames.step(function(e, f) {
|
|
83
|
-
if (e !== null) return reject(e);
|
|
84
|
-
if (f.id === method)
|
|
85
|
-
resolve(f);
|
|
86
|
-
else
|
|
87
|
-
reject(new Error("Expected method: " + method +
|
|
88
|
-
", got " + f.id));
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
frames.step(function(e, f) {
|
|
93
|
-
if (e !== null) return reject(e);
|
|
94
|
-
else resolve(f);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
run(send, wait);
|
|
101
|
-
return frames;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Produce a callback that will complete the test successfully
|
|
105
|
-
function succeed(done) {
|
|
106
|
-
return function() { done(); }
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Produce a callback that will complete the test successfully
|
|
110
|
-
// only if the value is an object, it has the specified
|
|
111
|
-
// attribute, and its value is equals to the expected value
|
|
112
|
-
function succeedIfAttributeEquals(attribute, value, done) {
|
|
113
|
-
return function(object) {
|
|
114
|
-
if (object && !(object instanceof Error) && value === object[attribute]) {
|
|
115
|
-
return done();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
done(new Error(attribute + " is not equal to " + value));
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Produce a callback that will fail the test, given either an error
|
|
123
|
-
// (to be used as a failure continuation) or any other value (to be
|
|
124
|
-
// used as a success continuation when failure is expected)
|
|
125
|
-
function fail(done) {
|
|
126
|
-
return function(err) {
|
|
127
|
-
if (err instanceof Error) done(err);
|
|
128
|
-
else done(new Error("Expected to fail, instead got " + err.toString()));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Create a function that will call done once it's been called itself
|
|
133
|
-
// `count` times. If it's called with an error value, it will
|
|
134
|
-
// immediately call done with that error value.
|
|
135
|
-
function latch(count, done) {
|
|
136
|
-
var awaiting = count;
|
|
137
|
-
var alive = true;
|
|
138
|
-
return function(err) {
|
|
139
|
-
if (err instanceof Error && alive) {
|
|
140
|
-
alive = false;
|
|
141
|
-
done(err);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
awaiting--;
|
|
145
|
-
if (awaiting === 0 && alive) {
|
|
146
|
-
alive = false;
|
|
147
|
-
done();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Call a thunk with a continuation that will be called with an error
|
|
154
|
-
// if the thunk throws one, or nothing if it runs to completion.
|
|
155
|
-
function completes(thunk, done) {
|
|
156
|
-
try {
|
|
157
|
-
thunk();
|
|
158
|
-
done();
|
|
159
|
-
}
|
|
160
|
-
catch (e) { done(e); }
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Construct a Node.JS-style callback from a success continuation and
|
|
164
|
-
// an error continuation
|
|
165
|
-
function kCallback(k, ek) {
|
|
166
|
-
return function(err, val) {
|
|
167
|
-
if (err === null) k && k(val);
|
|
168
|
-
else ek && ek(err);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// A noddy way to make tests depend on the node version.
|
|
173
|
-
function versionGreaterThan(actual, spec) {
|
|
174
|
-
|
|
175
|
-
function int(e) { return parseInt(e); }
|
|
176
|
-
|
|
177
|
-
var version = actual.split('.').map(int);
|
|
178
|
-
var desired = spec.split('.').map(int);
|
|
179
|
-
for (var i=0; i < desired.length; i++) {
|
|
180
|
-
var a = version[i], b = desired[i];
|
|
181
|
-
if (a != b) return a > b;
|
|
182
|
-
}
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
suite('versionGreaterThan', function() {
|
|
187
|
-
|
|
188
|
-
test('full spec', function() {
|
|
189
|
-
assert(versionGreaterThan('0.8.26', '0.6.12'));
|
|
190
|
-
assert(versionGreaterThan('0.8.26', '0.8.21'));
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test('partial spec', function() {
|
|
194
|
-
assert(versionGreaterThan('0.9.12', '0.8'));
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('not greater', function() {
|
|
198
|
-
assert(!versionGreaterThan('0.8.12', '0.8.26'));
|
|
199
|
-
assert(!versionGreaterThan('0.6.2', '0.6.12'));
|
|
200
|
-
assert(!versionGreaterThan('0.8.29', '0.8'));
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
test
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
module.exports = {
|
|
208
|
-
socketPair: socketPair,
|
|
209
|
-
runServer: runServer,
|
|
210
|
-
succeed: succeed,
|
|
211
|
-
succeedIfAttributeEquals: succeedIfAttributeEquals,
|
|
212
|
-
fail: fail,
|
|
213
|
-
latch: latch,
|
|
214
|
-
completes: completes,
|
|
215
|
-
kCallback: kCallback,
|
|
216
|
-
schedule: schedule,
|
|
217
|
-
randomString: randomString,
|
|
218
|
-
versionGreaterThan: versionGreaterThan
|
|
219
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2012 David Wragg. All rights reserved.
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to
|
|
5
|
-
deal in the Software without restriction, including without limitation the
|
|
6
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
19
|
-
IN THE SOFTWARE.
|