tardis-machine 18.0.0 → 18.1.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/benchmark.js +35 -14
- package/bin/tardis-machine.js +0 -1
- package/dist/tardismachine.d.ts.map +1 -1
- package/dist/tardismachine.js +20 -55
- package/dist/tardismachine.js.map +1 -1
- package/dist/ws/replay.d.ts +2 -2
- package/dist/ws/replay.d.ts.map +1 -1
- package/dist/ws/replay.js +11 -5
- package/dist/ws/replay.js.map +1 -1
- package/dist/ws/replaynormalized.d.ts +2 -2
- package/dist/ws/replaynormalized.d.ts.map +1 -1
- package/dist/ws/replaynormalized.js +7 -5
- package/dist/ws/replaynormalized.js.map +1 -1
- package/dist/ws/server.d.ts +20 -0
- package/dist/ws/server.d.ts.map +1 -0
- package/dist/ws/server.js +154 -0
- package/dist/ws/server.js.map +1 -0
- package/dist/ws/streamnormalized.d.ts +2 -2
- package/dist/ws/streamnormalized.d.ts.map +1 -1
- package/dist/ws/streamnormalized.js +7 -5
- package/dist/ws/streamnormalized.js.map +1 -1
- package/dist/ws/subscriptionsmappers.d.ts +1 -1
- package/dist/ws/subscriptionsmappers.d.ts.map +1 -1
- package/node_modules/tardis-dev/README.md +1 -1
- package/node_modules/tardis-dev/dist/debug.d.ts +12 -2
- package/node_modules/tardis-dev/dist/debug.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/debug.js +2 -1
- package/node_modules/tardis-dev/dist/debug.js.map +1 -1
- package/node_modules/tardis-dev/dist/downloaddatasets.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/downloaddatasets.js +3 -1
- package/node_modules/tardis-dev/dist/downloaddatasets.js.map +1 -1
- package/node_modules/tardis-dev/dist/handy.d.ts +5 -2
- package/node_modules/tardis-dev/dist/handy.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/handy.js +77 -90
- package/node_modules/tardis-dev/dist/handy.js.map +1 -1
- package/node_modules/tardis-dev/dist/mappers/hyperliquid.d.ts +1 -1
- package/node_modules/tardis-dev/dist/mappers/hyperliquid.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/mappers/hyperliquid.js +15 -4
- package/node_modules/tardis-dev/dist/mappers/hyperliquid.js.map +1 -1
- package/node_modules/tardis-dev/dist/mappers/index.d.ts +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.d.ts +0 -7
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.js +2 -70
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.js.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.d.ts +43 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.d.ts.map +1 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.js +294 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.js.map +1 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.d.ts +3 -3
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.js +3 -3
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.js.map +1 -1
- package/node_modules/tardis-dev/dist/replay.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/replay.js +6 -4
- package/node_modules/tardis-dev/dist/replay.js.map +1 -1
- package/node_modules/tardis-dev/dist/worker.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/worker.js +7 -4
- package/node_modules/tardis-dev/dist/worker.js.map +1 -1
- package/node_modules/tardis-dev/dist/zstd.d.ts +3 -0
- package/node_modules/tardis-dev/dist/zstd.d.ts.map +1 -0
- package/node_modules/tardis-dev/dist/zstd.js +122 -0
- package/node_modules/tardis-dev/dist/zstd.js.map +1 -0
- package/node_modules/tardis-dev/package.json +3 -7
- package/node_modules/tardis-dev/src/debug.ts +16 -1
- package/node_modules/tardis-dev/src/downloaddatasets.ts +3 -1
- package/node_modules/tardis-dev/src/external-modules.d.ts +5 -0
- package/node_modules/tardis-dev/src/handy.ts +100 -93
- package/node_modules/tardis-dev/src/mappers/hyperliquid.ts +19 -5
- package/node_modules/tardis-dev/src/realtimefeeds/mexc.ts +2 -72
- package/node_modules/tardis-dev/src/realtimefeeds/mexcprotobuf.ts +364 -0
- package/node_modules/tardis-dev/src/realtimefeeds/realtimefeed.ts +5 -5
- package/node_modules/tardis-dev/src/replay.ts +6 -4
- package/node_modules/tardis-dev/src/worker.ts +7 -4
- package/node_modules/tardis-dev/src/zstd.ts +139 -0
- package/package.json +9 -35
- package/src/tardismachine.ts +25 -66
- package/src/ws/replay.ts +13 -8
- package/src/ws/replaynormalized.ts +8 -6
- package/src/ws/server.ts +173 -0
- package/src/ws/streamnormalized.ts +8 -6
- package/src/ws/subscriptionsmappers.ts +1 -1
- package/node_modules/follow-redirects/LICENSE +0 -18
- package/node_modules/follow-redirects/README.md +0 -157
- package/node_modules/follow-redirects/debug.js +0 -15
- package/node_modules/follow-redirects/http.js +0 -1
- package/node_modules/follow-redirects/https.js +0 -1
- package/node_modules/follow-redirects/index.js +0 -709
- package/node_modules/follow-redirects/package.json +0 -58
- package/node_modules/long/LICENSE +0 -202
- package/node_modules/long/README.md +0 -286
- package/node_modules/long/index.d.ts +0 -2
- package/node_modules/long/index.js +0 -1581
- package/node_modules/long/package.json +0 -58
- package/node_modules/long/types.d.ts +0 -474
- package/node_modules/long/umd/index.d.ts +0 -3
- package/node_modules/long/umd/index.js +0 -1622
- package/node_modules/long/umd/package.json +0 -3
- package/node_modules/long/umd/types.d.ts +0 -474
- package/node_modules/protobufjs/LICENSE +0 -39
- package/node_modules/protobufjs/README.md +0 -440
- package/node_modules/protobufjs/dist/light/protobuf.js +0 -9276
- package/node_modules/protobufjs/dist/light/protobuf.js.map +0 -1
- package/node_modules/protobufjs/dist/light/protobuf.min.js +0 -8
- package/node_modules/protobufjs/dist/light/protobuf.min.js.map +0 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.js +0 -3556
- package/node_modules/protobufjs/dist/minimal/protobuf.js.map +0 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +0 -8
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +0 -1
- package/node_modules/protobufjs/dist/protobuf.js +0 -11233
- package/node_modules/protobufjs/dist/protobuf.js.map +0 -1
- package/node_modules/protobufjs/dist/protobuf.min.js +0 -8
- package/node_modules/protobufjs/dist/protobuf.min.js.map +0 -1
- package/node_modules/protobufjs/ext/README.md +0 -70
- package/node_modules/protobufjs/ext/debug/README.md +0 -4
- package/node_modules/protobufjs/ext/debug/index.js +0 -71
- package/node_modules/protobufjs/ext/descriptor/README.md +0 -5
- package/node_modules/protobufjs/ext/descriptor/index.d.ts +0 -2
- package/node_modules/protobufjs/ext/descriptor/index.js +0 -2
- package/node_modules/protobufjs/ext/descriptor.d.ts +0 -87
- package/node_modules/protobufjs/ext/descriptor.generated.d.ts +0 -417
- package/node_modules/protobufjs/ext/descriptor.js +0 -1356
- package/node_modules/protobufjs/ext/protojson.LICENSE +0 -201
- package/node_modules/protobufjs/ext/protojson.d.ts +0 -20
- package/node_modules/protobufjs/ext/protojson.generated.d.ts +0 -49
- package/node_modules/protobufjs/ext/protojson.js +0 -951
- package/node_modules/protobufjs/ext/textformat.d.ts +0 -19
- package/node_modules/protobufjs/ext/textformat.generated.d.ts +0 -33
- package/node_modules/protobufjs/ext/textformat.js +0 -1276
- package/node_modules/protobufjs/google/LICENSE +0 -27
- package/node_modules/protobufjs/google/README.md +0 -1
- package/node_modules/protobufjs/google/api/annotations.json +0 -85
- package/node_modules/protobufjs/google/api/annotations.proto +0 -11
- package/node_modules/protobufjs/google/api/http.json +0 -87
- package/node_modules/protobufjs/google/api/http.proto +0 -31
- package/node_modules/protobufjs/google/protobuf/api.json +0 -124
- package/node_modules/protobufjs/google/protobuf/api.proto +0 -34
- package/node_modules/protobufjs/google/protobuf/compiler/plugin.json +0 -126
- package/node_modules/protobufjs/google/protobuf/compiler/plugin.proto +0 -47
- package/node_modules/protobufjs/google/protobuf/descriptor.json +0 -1465
- package/node_modules/protobufjs/google/protobuf/descriptor.proto +0 -527
- package/node_modules/protobufjs/google/protobuf/source_context.json +0 -21
- package/node_modules/protobufjs/google/protobuf/source_context.proto +0 -7
- package/node_modules/protobufjs/google/protobuf/type.json +0 -209
- package/node_modules/protobufjs/google/protobuf/type.proto +0 -89
- package/node_modules/protobufjs/index.d.ts +0 -3203
- package/node_modules/protobufjs/index.js +0 -4
- package/node_modules/protobufjs/light.d.ts +0 -2
- package/node_modules/protobufjs/light.js +0 -4
- package/node_modules/protobufjs/minimal.d.ts +0 -2
- package/node_modules/protobufjs/minimal.js +0 -4
- package/node_modules/protobufjs/package.json +0 -93
- package/node_modules/protobufjs/src/common.js +0 -405
- package/node_modules/protobufjs/src/converter.js +0 -352
- package/node_modules/protobufjs/src/decoder.js +0 -279
- package/node_modules/protobufjs/src/encoder.js +0 -123
- package/node_modules/protobufjs/src/enum.js +0 -239
- package/node_modules/protobufjs/src/field.js +0 -505
- package/node_modules/protobufjs/src/index-light.js +0 -104
- package/node_modules/protobufjs/src/index-minimal.js +0 -35
- package/node_modules/protobufjs/src/index.js +0 -12
- package/node_modules/protobufjs/src/mapfield.js +0 -144
- package/node_modules/protobufjs/src/message.js +0 -137
- package/node_modules/protobufjs/src/method.js +0 -183
- package/node_modules/protobufjs/src/namespace.js +0 -574
- package/node_modules/protobufjs/src/object.js +0 -392
- package/node_modules/protobufjs/src/oneof.js +0 -233
- package/node_modules/protobufjs/src/parse.js +0 -1111
- package/node_modules/protobufjs/src/reader.js +0 -788
- package/node_modules/protobufjs/src/reader_buffer.js +0 -77
- package/node_modules/protobufjs/src/root.js +0 -424
- package/node_modules/protobufjs/src/roots.js +0 -18
- package/node_modules/protobufjs/src/rpc/service.js +0 -155
- package/node_modules/protobufjs/src/rpc.js +0 -36
- package/node_modules/protobufjs/src/service.js +0 -206
- package/node_modules/protobufjs/src/tokenize.js +0 -421
- package/node_modules/protobufjs/src/type.js +0 -676
- package/node_modules/protobufjs/src/types.js +0 -196
- package/node_modules/protobufjs/src/typescript.js +0 -25
- package/node_modules/protobufjs/src/util/aspromise.d.ts +0 -13
- package/node_modules/protobufjs/src/util/aspromise.js +0 -52
- package/node_modules/protobufjs/src/util/base64.d.ts +0 -32
- package/node_modules/protobufjs/src/util/base64.js +0 -146
- package/node_modules/protobufjs/src/util/codegen.d.ts +0 -31
- package/node_modules/protobufjs/src/util/codegen.js +0 -118
- package/node_modules/protobufjs/src/util/eventemitter.d.ts +0 -45
- package/node_modules/protobufjs/src/util/eventemitter.js +0 -86
- package/node_modules/protobufjs/src/util/fetch.d.ts +0 -56
- package/node_modules/protobufjs/src/util/fetch.js +0 -112
- package/node_modules/protobufjs/src/util/float.d.ts +0 -83
- package/node_modules/protobufjs/src/util/float.js +0 -335
- package/node_modules/protobufjs/src/util/fs.js +0 -11
- package/node_modules/protobufjs/src/util/longbits.js +0 -204
- package/node_modules/protobufjs/src/util/minimal.js +0 -511
- package/node_modules/protobufjs/src/util/path.d.ts +0 -22
- package/node_modules/protobufjs/src/util/path.js +0 -100
- package/node_modules/protobufjs/src/util/patterns.js +0 -7
- package/node_modules/protobufjs/src/util/pool.d.ts +0 -32
- package/node_modules/protobufjs/src/util/pool.js +0 -48
- package/node_modules/protobufjs/src/util/utf8.d.ts +0 -24
- package/node_modules/protobufjs/src/util/utf8.js +0 -190
- package/node_modules/protobufjs/src/util.js +0 -264
- package/node_modules/protobufjs/src/verifier.js +0 -185
- package/node_modules/protobufjs/src/wrappers.js +0 -106
- package/node_modules/protobufjs/src/writer.js +0 -700
- package/node_modules/protobufjs/src/writer_buffer.js +0 -100
- package/node_modules/protobufjs/tsconfig.json +0 -6
- package/node_modules/uWebSockets.js/ESM_wrapper.mjs +0 -53
- package/node_modules/uWebSockets.js/LICENSE +0 -201
- package/node_modules/uWebSockets.js/README.md +0 -6
- package/node_modules/uWebSockets.js/index.d.ts +0 -468
- package/node_modules/uWebSockets.js/package.json +0 -12
- package/node_modules/uWebSockets.js/source_commit +0 -1
- package/node_modules/uWebSockets.js/uws.js +0 -76
- package/node_modules/uWebSockets.js/uws_darwin_arm64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_arm64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_arm64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_x64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_x64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_x64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_arm64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_arm64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_arm64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_x64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_x64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_x64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_win32_x64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_win32_x64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_win32_x64_147.node +0 -0
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests if the specified path is absolute.
|
|
3
|
-
* @param {string} path Path to test
|
|
4
|
-
* @returns {boolean} `true` if path is absolute
|
|
5
|
-
*/
|
|
6
|
-
export function isAbsolute(path: string): boolean;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Normalizes the specified path.
|
|
10
|
-
* @param {string} path Path to normalize
|
|
11
|
-
* @returns {string} Normalized path
|
|
12
|
-
*/
|
|
13
|
-
export function normalize(path: string): string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Resolves the specified include path against the specified origin path.
|
|
17
|
-
* @param {string} originPath Path to the origin file
|
|
18
|
-
* @param {string} includePath Include path relative to origin path
|
|
19
|
-
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
|
|
20
|
-
* @returns {string} Path to the include file
|
|
21
|
-
*/
|
|
22
|
-
export function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A minimal path module to resolve Unix, Windows and URL paths alike.
|
|
5
|
-
* @memberof util
|
|
6
|
-
* @namespace
|
|
7
|
-
*/
|
|
8
|
-
var path = exports;
|
|
9
|
-
|
|
10
|
-
var urlRe = /^[a-zA-Z][a-zA-Z0-9+.-]+:\/\//;
|
|
11
|
-
|
|
12
|
-
function normalizeUrl(path) {
|
|
13
|
-
if (typeof URL === "undefined" || !urlRe.test(path))
|
|
14
|
-
return null;
|
|
15
|
-
try {
|
|
16
|
-
return new URL(path).href;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function resolveUrl(originPath, includePath) {
|
|
23
|
-
if (typeof URL === "undefined" || !urlRe.test(originPath) || urlRe.test(includePath))
|
|
24
|
-
return null;
|
|
25
|
-
try {
|
|
26
|
-
return new URL(includePath, originPath).href;
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var isAbsolute =
|
|
33
|
-
/**
|
|
34
|
-
* Tests if the specified path is absolute.
|
|
35
|
-
* @param {string} path Path to test
|
|
36
|
-
* @returns {boolean} `true` if path is absolute
|
|
37
|
-
*/
|
|
38
|
-
path.isAbsolute = function isAbsolute(path) {
|
|
39
|
-
return /^(?:\/|\w+:|\\\\\w+)/.test(path);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
var normalize =
|
|
43
|
-
/**
|
|
44
|
-
* Normalizes the specified path.
|
|
45
|
-
* @param {string} path Path to normalize
|
|
46
|
-
* @returns {string} Normalized path
|
|
47
|
-
*/
|
|
48
|
-
path.normalize = function normalize(path) {
|
|
49
|
-
var normalizedUrl = normalizeUrl(path);
|
|
50
|
-
if (normalizedUrl)
|
|
51
|
-
return normalizedUrl;
|
|
52
|
-
var firstTwoCharacters = path.substring(0,2);
|
|
53
|
-
var uncPrefix = "";
|
|
54
|
-
if (firstTwoCharacters === "\\\\") {
|
|
55
|
-
uncPrefix = firstTwoCharacters;
|
|
56
|
-
path = path.substring(2);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
path = path.replace(/\\/g, "/")
|
|
60
|
-
.replace(/\/{2,}/g, "/");
|
|
61
|
-
var parts = path.split("/"),
|
|
62
|
-
absolute = isAbsolute(path),
|
|
63
|
-
prefix = "";
|
|
64
|
-
if (absolute)
|
|
65
|
-
prefix = parts.shift() + "/";
|
|
66
|
-
for (var i = 0; i < parts.length;) {
|
|
67
|
-
if (parts[i] === "..") {
|
|
68
|
-
if (i > 0 && parts[i - 1] !== "..")
|
|
69
|
-
parts.splice(--i, 2);
|
|
70
|
-
else if (absolute)
|
|
71
|
-
parts.splice(i, 1);
|
|
72
|
-
else
|
|
73
|
-
++i;
|
|
74
|
-
} else if (parts[i] === ".")
|
|
75
|
-
parts.splice(i, 1);
|
|
76
|
-
else
|
|
77
|
-
++i;
|
|
78
|
-
}
|
|
79
|
-
return uncPrefix + prefix + parts.join("/");
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Resolves the specified include path against the specified origin path.
|
|
84
|
-
* @param {string} originPath Path to the origin file
|
|
85
|
-
* @param {string} includePath Include path relative to origin path
|
|
86
|
-
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
|
|
87
|
-
* @returns {string} Path to the include file
|
|
88
|
-
*/
|
|
89
|
-
path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
|
|
90
|
-
var resolvedUrl = resolveUrl(originPath, includePath);
|
|
91
|
-
if (resolvedUrl)
|
|
92
|
-
return resolvedUrl;
|
|
93
|
-
if (!alreadyNormalized)
|
|
94
|
-
includePath = normalize(includePath); // path or absolute url
|
|
95
|
-
if (isAbsolute(includePath))
|
|
96
|
-
return includePath;
|
|
97
|
-
if (!alreadyNormalized)
|
|
98
|
-
originPath = normalize(originPath);
|
|
99
|
-
return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
|
|
100
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var patterns = exports;
|
|
4
|
-
|
|
5
|
-
patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
|
|
6
|
-
patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
|
|
7
|
-
patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export = pool;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* An allocator as used by {@link util.pool}.
|
|
5
|
-
* @typedef PoolAllocator
|
|
6
|
-
* @type {function}
|
|
7
|
-
* @param {number} size Buffer size
|
|
8
|
-
* @returns {Uint8Array} Buffer
|
|
9
|
-
*/
|
|
10
|
-
type PoolAllocator = (size: number) => Uint8Array;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A slicer as used by {@link util.pool}.
|
|
14
|
-
* @typedef PoolSlicer
|
|
15
|
-
* @type {function}
|
|
16
|
-
* @param {number} start Start offset
|
|
17
|
-
* @param {number} end End offset
|
|
18
|
-
* @returns {Uint8Array} Buffer slice
|
|
19
|
-
* @this {Uint8Array}
|
|
20
|
-
*/
|
|
21
|
-
type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A general purpose buffer pool.
|
|
25
|
-
* @memberof util
|
|
26
|
-
* @function
|
|
27
|
-
* @param {PoolAllocator} alloc Allocator
|
|
28
|
-
* @param {PoolSlicer} slice Slicer
|
|
29
|
-
* @param {number} [size=8192] Slab size
|
|
30
|
-
* @returns {PoolAllocator} Pooled allocator
|
|
31
|
-
*/
|
|
32
|
-
declare function pool(alloc: PoolAllocator, slice: PoolSlicer, size?: number): PoolAllocator;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = pool;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An allocator as used by {@link util.pool}.
|
|
6
|
-
* @typedef PoolAllocator
|
|
7
|
-
* @type {function}
|
|
8
|
-
* @param {number} size Buffer size
|
|
9
|
-
* @returns {Uint8Array} Buffer
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A slicer as used by {@link util.pool}.
|
|
14
|
-
* @typedef PoolSlicer
|
|
15
|
-
* @type {function}
|
|
16
|
-
* @param {number} start Start offset
|
|
17
|
-
* @param {number} end End offset
|
|
18
|
-
* @returns {Uint8Array} Buffer slice
|
|
19
|
-
* @this Uint8Array
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A general purpose buffer pool.
|
|
24
|
-
* @memberof util
|
|
25
|
-
* @function
|
|
26
|
-
* @param {PoolAllocator} alloc Allocator
|
|
27
|
-
* @param {PoolSlicer} slice Slicer
|
|
28
|
-
* @param {number} [size=8192] Slab size
|
|
29
|
-
* @returns {PoolAllocator} Pooled allocator
|
|
30
|
-
*/
|
|
31
|
-
function pool(alloc, slice, size) {
|
|
32
|
-
var SIZE = size || 8192;
|
|
33
|
-
var MAX = SIZE >>> 1;
|
|
34
|
-
var slab = null;
|
|
35
|
-
var offset = SIZE;
|
|
36
|
-
return function pool_alloc(size) {
|
|
37
|
-
if (size < 1 || size > MAX)
|
|
38
|
-
return alloc(size);
|
|
39
|
-
if (offset + size > SIZE) {
|
|
40
|
-
slab = alloc(SIZE);
|
|
41
|
-
offset = 0;
|
|
42
|
-
}
|
|
43
|
-
var buf = slice.call(slab, offset, offset += size);
|
|
44
|
-
if (offset & 7) // align to 32 bit
|
|
45
|
-
offset = (offset | 7) + 1;
|
|
46
|
-
return buf;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the UTF8 byte length of a string.
|
|
3
|
-
* @param {string} string String
|
|
4
|
-
* @returns {number} Byte length
|
|
5
|
-
*/
|
|
6
|
-
export function length(string: string): number;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reads UTF8 bytes as a string.
|
|
10
|
-
* @param {Uint8Array} buffer Source buffer
|
|
11
|
-
* @param {number} start Source start
|
|
12
|
-
* @param {number} end Source end
|
|
13
|
-
* @returns {string} String read
|
|
14
|
-
*/
|
|
15
|
-
export function read(buffer: Uint8Array, start: number, end: number): string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Writes a string as UTF8 bytes.
|
|
19
|
-
* @param {string} string Source string
|
|
20
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
21
|
-
* @param {number} offset Destination offset
|
|
22
|
-
* @returns {number} Bytes written
|
|
23
|
-
*/
|
|
24
|
-
export function write(string: string, buffer: Uint8Array, offset: number): number;
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A minimal UTF8 implementation.
|
|
5
|
-
* @memberof util
|
|
6
|
-
* @namespace
|
|
7
|
-
*/
|
|
8
|
-
var utf8 = exports,
|
|
9
|
-
replacementChar = "\ufffd",
|
|
10
|
-
looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
|
11
|
-
strictDecoder;
|
|
12
|
-
var TEXT_DECODER_MIN_LENGTH = 64;
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
16
|
-
} catch (err) {
|
|
17
|
-
// "fatal" option is not supported on Node.js compiled without ICU
|
|
18
|
-
strictDecoder = looseDecoder;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Calculates the UTF8 byte length of a string.
|
|
23
|
-
* @param {string} string String
|
|
24
|
-
* @returns {number} Byte length
|
|
25
|
-
*/
|
|
26
|
-
utf8.length = function utf8_length(string) {
|
|
27
|
-
var len = 0,
|
|
28
|
-
c = 0;
|
|
29
|
-
for (var i = 0; i < string.length; ++i) {
|
|
30
|
-
c = string.charCodeAt(i);
|
|
31
|
-
if (c < 128)
|
|
32
|
-
len += 1;
|
|
33
|
-
else if (c < 2048)
|
|
34
|
-
len += 2;
|
|
35
|
-
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
36
|
-
++i;
|
|
37
|
-
len += 4;
|
|
38
|
-
} else
|
|
39
|
-
len += 3;
|
|
40
|
-
}
|
|
41
|
-
return len;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
function utf8_read_js(buffer, start, end, str) {
|
|
45
|
-
for (var i = start; i < end;) {
|
|
46
|
-
var t = buffer[i++];
|
|
47
|
-
if (t <= 0x7F) {
|
|
48
|
-
str += String.fromCharCode(t);
|
|
49
|
-
} else if (t >= 0xC0 && t < 0xE0) {
|
|
50
|
-
var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
|
|
51
|
-
str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
|
|
52
|
-
} else if (t >= 0xE0 && t < 0xF0) {
|
|
53
|
-
var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
|
|
54
|
-
str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
|
|
55
|
-
} else if (t >= 0xF0) {
|
|
56
|
-
var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
|
|
57
|
-
if (t2 < 0x10000 || t2 > 0x10FFFF)
|
|
58
|
-
str += replacementChar;
|
|
59
|
-
else {
|
|
60
|
-
t2 -= 0x10000;
|
|
61
|
-
str += String.fromCharCode(0xD800 + (t2 >> 10));
|
|
62
|
-
str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return str;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function utf8_read_decoder(decoder, buffer, start, end) {
|
|
70
|
-
var source = start === 0 && end === buffer.length
|
|
71
|
-
? buffer
|
|
72
|
-
: buffer.subarray(start, end);
|
|
73
|
-
return decoder.decode(source);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Reads UTF8 bytes as a string.
|
|
78
|
-
* @param {Uint8Array} buffer Source buffer
|
|
79
|
-
* @param {number} start Source start
|
|
80
|
-
* @param {number} end Source end
|
|
81
|
-
* @returns {string} String read
|
|
82
|
-
*/
|
|
83
|
-
utf8.read = function utf8_read_loose(buffer, start, end) {
|
|
84
|
-
if (end - start < 1)
|
|
85
|
-
return "";
|
|
86
|
-
if (end - start >= TEXT_DECODER_MIN_LENGTH)
|
|
87
|
-
return utf8_read_decoder(looseDecoder, buffer, start, end);
|
|
88
|
-
|
|
89
|
-
var str = "",
|
|
90
|
-
i = start,
|
|
91
|
-
c1, c2, c3, c4, c5, c6, c7, c8;
|
|
92
|
-
|
|
93
|
-
for (; i + 7 < end; i += 8) {
|
|
94
|
-
c1 = buffer[i];
|
|
95
|
-
c2 = buffer[i + 1];
|
|
96
|
-
c3 = buffer[i + 2];
|
|
97
|
-
c4 = buffer[i + 3];
|
|
98
|
-
c5 = buffer[i + 4];
|
|
99
|
-
c6 = buffer[i + 5];
|
|
100
|
-
c7 = buffer[i + 6];
|
|
101
|
-
c8 = buffer[i + 7];
|
|
102
|
-
if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
|
|
103
|
-
return utf8_read_js(buffer, i, end, str);
|
|
104
|
-
str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
for (; i < end; ++i) {
|
|
108
|
-
c1 = buffer[i];
|
|
109
|
-
if (c1 & 0x80)
|
|
110
|
-
return utf8_read_js(buffer, i, end, str);
|
|
111
|
-
str += String.fromCharCode(c1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return str;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Reads UTF8 bytes as a string, rejecting invalid UTF8.
|
|
119
|
-
* @param {Uint8Array} buffer Source buffer
|
|
120
|
-
* @param {number} start Source start
|
|
121
|
-
* @param {number} end Source end
|
|
122
|
-
* @returns {string} String read
|
|
123
|
-
*/
|
|
124
|
-
utf8.readStrict = function utf8_read_strict(buffer, start, end) {
|
|
125
|
-
if (end - start < 1)
|
|
126
|
-
return "";
|
|
127
|
-
if (end - start >= TEXT_DECODER_MIN_LENGTH)
|
|
128
|
-
return utf8_read_decoder(strictDecoder, buffer, start, end);
|
|
129
|
-
|
|
130
|
-
var str = "",
|
|
131
|
-
i = start,
|
|
132
|
-
c1, c2, c3, c4, c5, c6, c7, c8;
|
|
133
|
-
|
|
134
|
-
for (; i + 7 < end; i += 8) {
|
|
135
|
-
c1 = buffer[i];
|
|
136
|
-
c2 = buffer[i + 1];
|
|
137
|
-
c3 = buffer[i + 2];
|
|
138
|
-
c4 = buffer[i + 3];
|
|
139
|
-
c5 = buffer[i + 4];
|
|
140
|
-
c6 = buffer[i + 5];
|
|
141
|
-
c7 = buffer[i + 6];
|
|
142
|
-
c8 = buffer[i + 7];
|
|
143
|
-
if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
|
|
144
|
-
return str + utf8_read_decoder(strictDecoder, buffer, i, end);
|
|
145
|
-
str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
for (; i < end; ++i) {
|
|
149
|
-
c1 = buffer[i];
|
|
150
|
-
if (c1 & 0x80)
|
|
151
|
-
return str + utf8_read_decoder(strictDecoder, buffer, i, end);
|
|
152
|
-
str += String.fromCharCode(c1);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return str;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Writes a string as UTF8 bytes.
|
|
160
|
-
* @param {string} string Source string
|
|
161
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
162
|
-
* @param {number} offset Destination offset
|
|
163
|
-
* @returns {number} Bytes written
|
|
164
|
-
*/
|
|
165
|
-
utf8.write = function utf8_write(string, buffer, offset) {
|
|
166
|
-
var start = offset,
|
|
167
|
-
c1, // character 1
|
|
168
|
-
c2; // character 2
|
|
169
|
-
for (var i = 0; i < string.length; ++i) {
|
|
170
|
-
c1 = string.charCodeAt(i);
|
|
171
|
-
if (c1 < 128) {
|
|
172
|
-
buffer[offset++] = c1;
|
|
173
|
-
} else if (c1 < 2048) {
|
|
174
|
-
buffer[offset++] = c1 >> 6 | 192;
|
|
175
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
176
|
-
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
177
|
-
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
178
|
-
++i;
|
|
179
|
-
buffer[offset++] = c1 >> 18 | 240;
|
|
180
|
-
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
181
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
182
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
183
|
-
} else {
|
|
184
|
-
buffer[offset++] = c1 >> 12 | 224;
|
|
185
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
186
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return offset - start;
|
|
190
|
-
};
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Various utility functions.
|
|
5
|
-
* @namespace
|
|
6
|
-
*/
|
|
7
|
-
var util = module.exports = require("./util/minimal");
|
|
8
|
-
|
|
9
|
-
var roots = require("./roots");
|
|
10
|
-
|
|
11
|
-
var Type, // cyclic
|
|
12
|
-
Enum;
|
|
13
|
-
|
|
14
|
-
util.codegen = require("./util/codegen");
|
|
15
|
-
util.fetch = require("./util/fetch");
|
|
16
|
-
util.path = require("./util/path");
|
|
17
|
-
util.patterns = require("./util/patterns");
|
|
18
|
-
|
|
19
|
-
var reservedRe = util.patterns.reservedRe;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Node's fs module if available.
|
|
23
|
-
* @type {Object.<string,*>}
|
|
24
|
-
*/
|
|
25
|
-
util.fs = require("./util/fs");
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Converts an object's values to an array.
|
|
29
|
-
* @param {Object.<string,*>} object Object to convert
|
|
30
|
-
* @returns {Array.<*>} Converted array
|
|
31
|
-
*/
|
|
32
|
-
util.toArray = function toArray(object) {
|
|
33
|
-
if (object) {
|
|
34
|
-
var keys = Object.keys(object),
|
|
35
|
-
array = new Array(keys.length),
|
|
36
|
-
index = 0;
|
|
37
|
-
while (index < keys.length)
|
|
38
|
-
array[index] = object[keys[index++]];
|
|
39
|
-
return array;
|
|
40
|
-
}
|
|
41
|
-
return [];
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
|
|
46
|
-
* @param {Array.<*>} array Array to convert
|
|
47
|
-
* @returns {Object.<string,*>} Converted object
|
|
48
|
-
*/
|
|
49
|
-
util.toObject = function toObject(array) {
|
|
50
|
-
var object = {},
|
|
51
|
-
index = 0;
|
|
52
|
-
while (index < array.length) {
|
|
53
|
-
var key = array[index++],
|
|
54
|
-
val = array[index++];
|
|
55
|
-
if (val !== undefined)
|
|
56
|
-
object[key] = val;
|
|
57
|
-
}
|
|
58
|
-
return object;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Removes the first matching value from an object.
|
|
63
|
-
* @param {Object.<string,*>|undefined} object Object to remove from
|
|
64
|
-
* @param {*} value Value to remove
|
|
65
|
-
* @param {string} [key] Optional key for fast path removal
|
|
66
|
-
* @returns {boolean} `true` if removed, otherwise `false`
|
|
67
|
-
*/
|
|
68
|
-
util.remove = function remove(object, value, key) {
|
|
69
|
-
if (!object)
|
|
70
|
-
return false;
|
|
71
|
-
if (key !== undefined && Object.prototype.hasOwnProperty.call(object, key) && object[key] === value) {
|
|
72
|
-
delete object[key];
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
for (var names = Object.keys(object), i = 0; i < names.length; ++i)
|
|
76
|
-
if (object[names[i]] === value) {
|
|
77
|
-
delete object[names[i]];
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
return false;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Tests whether the specified name is a reserved word in JS.
|
|
85
|
-
* @param {string} name Name to test
|
|
86
|
-
* @returns {boolean} `true` if reserved, otherwise `false`
|
|
87
|
-
*/
|
|
88
|
-
util.isReserved = function isReserved(name) {
|
|
89
|
-
return reservedRe.test(name);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Returns a safe property accessor for the specified property name.
|
|
94
|
-
* @param {string} prop Property name
|
|
95
|
-
* @returns {string} Safe accessor
|
|
96
|
-
*/
|
|
97
|
-
util.safeProp = function safeProp(prop) {
|
|
98
|
-
if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
|
|
99
|
-
return "[" + JSON.stringify(prop) + "]";
|
|
100
|
-
return "." + prop;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Converts the first character of a string to upper case.
|
|
105
|
-
* @param {string} str String to convert
|
|
106
|
-
* @returns {string} Converted string
|
|
107
|
-
*/
|
|
108
|
-
util.ucFirst = function ucFirst(str) {
|
|
109
|
-
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
var camelCaseRe = /_([a-z])/g;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Converts a string to camel case.
|
|
116
|
-
* @param {string} str String to convert
|
|
117
|
-
* @returns {string} Converted string
|
|
118
|
-
* @deprecated Use {@link util.jsonName} for protobuf field JSON names.
|
|
119
|
-
*/
|
|
120
|
-
util.camelCase = function camelCase(str) {
|
|
121
|
-
return str.substring(0, 1)
|
|
122
|
-
+ str.substring(1)
|
|
123
|
-
.replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Converts a proto field name to its protoc-compatible JSON name.
|
|
128
|
-
* @param {string} str Proto field name
|
|
129
|
-
* @returns {string} JSON name
|
|
130
|
-
*/
|
|
131
|
-
util.jsonName = function jsonName(str) {
|
|
132
|
-
var result = "",
|
|
133
|
-
upperNext = false,
|
|
134
|
-
i = 0;
|
|
135
|
-
for (; i < str.length; ++i) {
|
|
136
|
-
var ch = str.charAt(i);
|
|
137
|
-
if (ch === "_")
|
|
138
|
-
upperNext = true;
|
|
139
|
-
else if (upperNext) {
|
|
140
|
-
result += ch.toUpperCase();
|
|
141
|
-
upperNext = false;
|
|
142
|
-
} else
|
|
143
|
-
result += ch;
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Compares reflected fields by id.
|
|
150
|
-
* @param {Field} a First field
|
|
151
|
-
* @param {Field} b Second field
|
|
152
|
-
* @returns {number} Comparison value
|
|
153
|
-
*/
|
|
154
|
-
util.compareFieldsById = function compareFieldsById(a, b) {
|
|
155
|
-
return a.id - b.id;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Decorator helper for types (TypeScript).
|
|
160
|
-
* @param {Constructor<T>} ctor Constructor function
|
|
161
|
-
* @param {string} [typeName] Type name, defaults to the constructor's name
|
|
162
|
-
* @returns {Type} Reflected type
|
|
163
|
-
* @template T extends Message<T>
|
|
164
|
-
* @property {Root} root Decorators root
|
|
165
|
-
* @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
|
|
166
|
-
*/
|
|
167
|
-
util.decorateType = function decorateType(ctor, typeName) {
|
|
168
|
-
|
|
169
|
-
/* istanbul ignore if */
|
|
170
|
-
if (ctor.$type) {
|
|
171
|
-
if (typeName && ctor.$type.name !== typeName) {
|
|
172
|
-
util.decorateRoot.remove(ctor.$type);
|
|
173
|
-
ctor.$type.name = typeName;
|
|
174
|
-
util.decorateRoot.add(ctor.$type);
|
|
175
|
-
}
|
|
176
|
-
return ctor.$type;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/* istanbul ignore next */
|
|
180
|
-
if (!Type)
|
|
181
|
-
Type = require("./type");
|
|
182
|
-
|
|
183
|
-
var type = new Type(typeName || ctor.name);
|
|
184
|
-
util.decorateRoot.add(type);
|
|
185
|
-
type.ctor = ctor; // sets up .encode, .decode etc.
|
|
186
|
-
Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
|
|
187
|
-
Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
|
|
188
|
-
return type;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
var decorateEnumIndex = 0;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Decorator helper for enums (TypeScript).
|
|
195
|
-
* @param {Object} object Enum object
|
|
196
|
-
* @returns {Enum} Reflected enum
|
|
197
|
-
* @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
|
|
198
|
-
*/
|
|
199
|
-
util.decorateEnum = function decorateEnum(object) {
|
|
200
|
-
|
|
201
|
-
/* istanbul ignore if */
|
|
202
|
-
if (object.$type)
|
|
203
|
-
return object.$type;
|
|
204
|
-
|
|
205
|
-
/* istanbul ignore next */
|
|
206
|
-
if (!Enum)
|
|
207
|
-
Enum = require("./enum");
|
|
208
|
-
|
|
209
|
-
var enm = new Enum("Enum" + decorateEnumIndex++, object);
|
|
210
|
-
util.decorateRoot.add(enm);
|
|
211
|
-
Object.defineProperty(object, "$type", { value: enm, enumerable: false });
|
|
212
|
-
return enm;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Sets the value of a property by property path. If a value already exists, it is turned to an array
|
|
218
|
-
* @param {Object.<string,*>} dst Destination object
|
|
219
|
-
* @param {string} path dot '.' delimited path of the property to set
|
|
220
|
-
* @param {Object} value the value to set
|
|
221
|
-
* @param {boolean|undefined} [ifNotSet] Sets the option only if it isn't currently set
|
|
222
|
-
* @returns {Object.<string,*>} Destination object
|
|
223
|
-
*/
|
|
224
|
-
util.setProperty = function setProperty(dst, path, value, ifNotSet) {
|
|
225
|
-
function setProp(dst, path, value) {
|
|
226
|
-
var part = path.shift();
|
|
227
|
-
if (util.isUnsafeProperty(part))
|
|
228
|
-
return dst;
|
|
229
|
-
if (path.length > 0) {
|
|
230
|
-
dst[part] = setProp(dst[part] || {}, path, value);
|
|
231
|
-
} else {
|
|
232
|
-
var prevValue = dst[part];
|
|
233
|
-
if (prevValue && ifNotSet)
|
|
234
|
-
return dst;
|
|
235
|
-
if (prevValue)
|
|
236
|
-
value = [].concat(prevValue).concat(value);
|
|
237
|
-
dst[part] = value;
|
|
238
|
-
}
|
|
239
|
-
return dst;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (typeof dst !== "object")
|
|
243
|
-
throw TypeError("dst must be an object");
|
|
244
|
-
if (!path)
|
|
245
|
-
throw TypeError("path must be specified");
|
|
246
|
-
|
|
247
|
-
path = path.split(".");
|
|
248
|
-
if (path.length > util.recursionLimit)
|
|
249
|
-
throw Error("max depth exceeded");
|
|
250
|
-
return setProp(dst, path, value);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Decorator root (TypeScript).
|
|
255
|
-
* @name util.decorateRoot
|
|
256
|
-
* @type {Root}
|
|
257
|
-
* @readonly
|
|
258
|
-
* @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
|
|
259
|
-
*/
|
|
260
|
-
Object.defineProperty(util, "decorateRoot", {
|
|
261
|
-
get: function() {
|
|
262
|
-
return roots["decorated"] || (roots["decorated"] = new (require("./root"))());
|
|
263
|
-
}
|
|
264
|
-
});
|