@camera.ui/rpc 1.0.3 → 1.0.4
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/externals/nats.js/core/src/authenticator.ts +159 -0
- package/externals/nats.js/core/src/bench.ts +426 -0
- package/externals/nats.js/core/src/codec.ts +28 -0
- package/externals/nats.js/core/src/core.ts +1219 -0
- package/externals/nats.js/core/src/databuffer.ts +129 -0
- package/externals/nats.js/core/src/denobuffer.ts +248 -0
- package/externals/nats.js/core/src/encoders.ts +53 -0
- package/externals/nats.js/core/src/errors.ts +300 -0
- package/externals/nats.js/core/src/headers.ts +315 -0
- package/externals/nats.js/core/src/heartbeats.ts +114 -0
- package/externals/nats.js/core/src/idleheartbeat_monitor.ts +140 -0
- package/externals/nats.js/core/src/internal_mod.ts +167 -0
- package/externals/nats.js/core/src/ipparser.ts +215 -0
- package/externals/nats.js/core/src/mod.ts +113 -0
- package/externals/nats.js/core/src/msg.ts +120 -0
- package/externals/nats.js/core/src/muxsubscription.ts +111 -0
- package/externals/nats.js/core/src/nats.ts +650 -0
- package/externals/nats.js/core/src/nkeys.ts +1 -0
- package/externals/nats.js/core/src/nuid.ts +16 -0
- package/externals/nats.js/core/src/options.ts +202 -0
- package/externals/nats.js/core/src/parser.ts +756 -0
- package/externals/nats.js/core/src/protocol.ts +1304 -0
- package/externals/nats.js/core/src/queued_iterator.ts +171 -0
- package/externals/nats.js/core/src/request.ts +177 -0
- package/externals/nats.js/core/src/semver.ts +165 -0
- package/externals/nats.js/core/src/servers.ts +424 -0
- package/externals/nats.js/core/src/transport.ts +117 -0
- package/externals/nats.js/core/src/types.ts +17 -0
- package/externals/nats.js/core/src/util.ts +367 -0
- package/externals/nats.js/core/src/version.ts +2 -0
- package/externals/nats.js/core/src/ws_transport.ts +391 -0
- package/package.json +2 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2018-2021 The NATS Authors
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { TD, TE } from "./encoders.ts";
|
|
17
|
+
|
|
18
|
+
export class DataBuffer {
|
|
19
|
+
buffers: Uint8Array[];
|
|
20
|
+
byteLength: number;
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.buffers = [];
|
|
24
|
+
this.byteLength = 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static concat(...bufs: Uint8Array[]): Uint8Array {
|
|
28
|
+
let max = 0;
|
|
29
|
+
for (let i = 0; i < bufs.length; i++) {
|
|
30
|
+
max += bufs[i].length;
|
|
31
|
+
}
|
|
32
|
+
const out = new Uint8Array(max);
|
|
33
|
+
let index = 0;
|
|
34
|
+
for (let i = 0; i < bufs.length; i++) {
|
|
35
|
+
out.set(bufs[i], index);
|
|
36
|
+
index += bufs[i].length;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static fromAscii(m: string): Uint8Array {
|
|
42
|
+
if (!m) {
|
|
43
|
+
m = "";
|
|
44
|
+
}
|
|
45
|
+
return TE.encode(m);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static toAscii(a: Uint8Array): string {
|
|
49
|
+
return TD.decode(a);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
reset(): void {
|
|
53
|
+
this.buffers.length = 0;
|
|
54
|
+
this.byteLength = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
pack(): void {
|
|
58
|
+
if (this.buffers.length > 1) {
|
|
59
|
+
const v = new Uint8Array(this.byteLength);
|
|
60
|
+
let index = 0;
|
|
61
|
+
for (let i = 0; i < this.buffers.length; i++) {
|
|
62
|
+
v.set(this.buffers[i], index);
|
|
63
|
+
index += this.buffers[i].length;
|
|
64
|
+
}
|
|
65
|
+
this.buffers.length = 0;
|
|
66
|
+
this.buffers.push(v);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
shift(): Uint8Array {
|
|
71
|
+
if (this.buffers.length) {
|
|
72
|
+
const a = this.buffers.shift();
|
|
73
|
+
if (a) {
|
|
74
|
+
this.byteLength -= a.length;
|
|
75
|
+
return a;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return new Uint8Array(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
drain(n?: number): Uint8Array {
|
|
82
|
+
if (this.buffers.length) {
|
|
83
|
+
this.pack();
|
|
84
|
+
const v = this.buffers.pop();
|
|
85
|
+
if (v) {
|
|
86
|
+
const max = this.byteLength;
|
|
87
|
+
if (n === undefined || n > max) {
|
|
88
|
+
n = max;
|
|
89
|
+
}
|
|
90
|
+
const d = v.subarray(0, n);
|
|
91
|
+
if (max > n) {
|
|
92
|
+
this.buffers.push(v.subarray(n));
|
|
93
|
+
}
|
|
94
|
+
this.byteLength = max - n;
|
|
95
|
+
return d;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return new Uint8Array(0);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fill(a: Uint8Array, ...bufs: Uint8Array[]): void {
|
|
102
|
+
if (a) {
|
|
103
|
+
this.buffers.push(a);
|
|
104
|
+
this.byteLength += a.length;
|
|
105
|
+
}
|
|
106
|
+
for (let i = 0; i < bufs.length; i++) {
|
|
107
|
+
if (bufs[i] && bufs[i].length) {
|
|
108
|
+
this.buffers.push(bufs[i]);
|
|
109
|
+
this.byteLength += bufs[i].length;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
peek(): Uint8Array {
|
|
115
|
+
if (this.buffers.length) {
|
|
116
|
+
this.pack();
|
|
117
|
+
return this.buffers[0];
|
|
118
|
+
}
|
|
119
|
+
return new Uint8Array(0);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
size(): number {
|
|
123
|
+
return this.byteLength;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
length(): number {
|
|
127
|
+
return this.buffers.length;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
// This code has been ported almost directly from Go's src/bytes/buffer.go
|
|
4
|
+
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
|
5
|
+
// https://github.com/golang/go/blob/master/LICENSE
|
|
6
|
+
|
|
7
|
+
// This code removes all Deno specific functionality to enable its use
|
|
8
|
+
// in a browser environment
|
|
9
|
+
|
|
10
|
+
//@internal
|
|
11
|
+
import { TE } from "./encoders.ts";
|
|
12
|
+
|
|
13
|
+
export class AssertionError extends Error {
|
|
14
|
+
constructor(msg?: string) {
|
|
15
|
+
super(msg);
|
|
16
|
+
this.name = "AssertionError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Reader {
|
|
21
|
+
read(p: Uint8Array): number | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Writer {
|
|
25
|
+
write(p: Uint8Array): number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// @internal
|
|
29
|
+
export function assert(cond: unknown, msg = "Assertion failed."): asserts cond {
|
|
30
|
+
if (!cond) {
|
|
31
|
+
throw new AssertionError(msg);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
|
|
36
|
+
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
|
|
37
|
+
// what is required to hold the contents of r, readFrom() will not grow the
|
|
38
|
+
// underlying buffer.
|
|
39
|
+
const MIN_READ = 32 * 1024;
|
|
40
|
+
|
|
41
|
+
export const MAX_SIZE = 2 ** 32 - 2;
|
|
42
|
+
|
|
43
|
+
// `off` is the offset into `dst` where it will at which to begin writing values
|
|
44
|
+
// from `src`.
|
|
45
|
+
// Returns the number of bytes copied.
|
|
46
|
+
function copy(src: Uint8Array, dst: Uint8Array, off = 0): number {
|
|
47
|
+
const r = dst.byteLength - off;
|
|
48
|
+
if (src.byteLength > r) {
|
|
49
|
+
src = src.subarray(0, r);
|
|
50
|
+
}
|
|
51
|
+
dst.set(src, off);
|
|
52
|
+
return src.byteLength;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function concat(origin?: Uint8Array, b?: Uint8Array): Uint8Array {
|
|
56
|
+
if (origin === undefined && b === undefined) {
|
|
57
|
+
return new Uint8Array(0);
|
|
58
|
+
}
|
|
59
|
+
if (origin === undefined) {
|
|
60
|
+
return b!;
|
|
61
|
+
}
|
|
62
|
+
if (b === undefined) {
|
|
63
|
+
return origin;
|
|
64
|
+
}
|
|
65
|
+
const output = new Uint8Array(origin.length + b.length);
|
|
66
|
+
output.set(origin, 0);
|
|
67
|
+
output.set(b, origin.length);
|
|
68
|
+
return output;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function append(origin: Uint8Array, b: number): Uint8Array {
|
|
72
|
+
return concat(origin, Uint8Array.of(b));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class DenoBuffer implements Reader, Writer {
|
|
76
|
+
_buf: Uint8Array; // contents are the bytes _buf[off : len(_buf)]
|
|
77
|
+
_off: number; // read at _buf[off], write at _buf[_buf.byteLength]
|
|
78
|
+
|
|
79
|
+
constructor(ab?: Uint8Array | ArrayBuffer) {
|
|
80
|
+
this._off = 0;
|
|
81
|
+
if (ab == null) {
|
|
82
|
+
this._buf = new Uint8Array(0);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this._buf = new Uint8Array(ab);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
bytes(options: { copy?: boolean } = { copy: true }): Uint8Array {
|
|
90
|
+
if (options.copy === false) return this._buf.subarray(this._off);
|
|
91
|
+
return this._buf.slice(this._off);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
empty(): boolean {
|
|
95
|
+
return this._buf.byteLength <= this._off;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get length(): number {
|
|
99
|
+
return this._buf.byteLength - this._off;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get capacity(): number {
|
|
103
|
+
return this._buf.buffer.byteLength;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
truncate(n: number): void {
|
|
107
|
+
if (n === 0) {
|
|
108
|
+
this.reset();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (n < 0 || n > this.length) {
|
|
112
|
+
throw Error("bytes.Buffer: truncation out of range");
|
|
113
|
+
}
|
|
114
|
+
this._reslice(this._off + n);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
reset(): void {
|
|
118
|
+
this._reslice(0);
|
|
119
|
+
this._off = 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
_tryGrowByReslice(n: number): number {
|
|
123
|
+
const l = this._buf.byteLength;
|
|
124
|
+
if (n <= this.capacity - l) {
|
|
125
|
+
this._reslice(l + n);
|
|
126
|
+
return l;
|
|
127
|
+
}
|
|
128
|
+
return -1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_reslice(len: number): void {
|
|
132
|
+
assert(len <= this._buf.buffer.byteLength);
|
|
133
|
+
this._buf = new Uint8Array(this._buf.buffer, 0, len);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
readByte(): number | null {
|
|
137
|
+
const a = new Uint8Array(1);
|
|
138
|
+
if (this.read(a)) {
|
|
139
|
+
return a[0];
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
read(p: Uint8Array): number | null {
|
|
145
|
+
if (this.empty()) {
|
|
146
|
+
// Buffer is empty, reset to recover space.
|
|
147
|
+
this.reset();
|
|
148
|
+
if (p.byteLength === 0) {
|
|
149
|
+
// this edge case is tested in 'bufferReadEmptyAtEOF' test
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const nread = copy(this._buf.subarray(this._off), p);
|
|
155
|
+
this._off += nread;
|
|
156
|
+
return nread;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
writeByte(n: number): number {
|
|
160
|
+
return this.write(Uint8Array.of(n));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
writeString(s: string): number {
|
|
164
|
+
return this.write(TE.encode(s));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
write(p: Uint8Array): number {
|
|
168
|
+
const m = this._grow(p.byteLength);
|
|
169
|
+
return copy(p, this._buf, m);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
_grow(n: number): number {
|
|
173
|
+
const m = this.length;
|
|
174
|
+
// If buffer is empty, reset to recover space.
|
|
175
|
+
if (m === 0 && this._off !== 0) {
|
|
176
|
+
this.reset();
|
|
177
|
+
}
|
|
178
|
+
// Fast: Try to _grow by means of a _reslice.
|
|
179
|
+
const i = this._tryGrowByReslice(n);
|
|
180
|
+
if (i >= 0) {
|
|
181
|
+
return i;
|
|
182
|
+
}
|
|
183
|
+
const c = this.capacity;
|
|
184
|
+
if (n <= Math.floor(c / 2) - m) {
|
|
185
|
+
// We can slide things down instead of allocating a new
|
|
186
|
+
// ArrayBuffer. We only need m+n <= c to slide, but
|
|
187
|
+
// we instead let capacity get twice as large so we
|
|
188
|
+
// don't spend all our time copying.
|
|
189
|
+
copy(this._buf.subarray(this._off), this._buf);
|
|
190
|
+
} else if (c + n > MAX_SIZE) {
|
|
191
|
+
throw new Error("The buffer cannot be grown beyond the maximum size.");
|
|
192
|
+
} else {
|
|
193
|
+
// Not enough space anywhere, we need to allocate.
|
|
194
|
+
const buf = new Uint8Array(Math.min(2 * c + n, MAX_SIZE));
|
|
195
|
+
copy(this._buf.subarray(this._off), buf);
|
|
196
|
+
this._buf = buf;
|
|
197
|
+
}
|
|
198
|
+
// Restore this.off and len(this._buf).
|
|
199
|
+
this._off = 0;
|
|
200
|
+
this._reslice(Math.min(m + n, MAX_SIZE));
|
|
201
|
+
return m;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
grow(n: number): void {
|
|
205
|
+
if (n < 0) {
|
|
206
|
+
throw Error("Buffer._grow: negative count");
|
|
207
|
+
}
|
|
208
|
+
const m = this._grow(n);
|
|
209
|
+
this._reslice(m);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
readFrom(r: Reader): number {
|
|
213
|
+
let n = 0;
|
|
214
|
+
const tmp = new Uint8Array(MIN_READ);
|
|
215
|
+
while (true) {
|
|
216
|
+
const shouldGrow = this.capacity - this.length < MIN_READ;
|
|
217
|
+
// read into tmp buffer if there's not enough room
|
|
218
|
+
// otherwise read directly into the internal buffer
|
|
219
|
+
const buf = shouldGrow
|
|
220
|
+
? tmp
|
|
221
|
+
: new Uint8Array(this._buf.buffer, this.length);
|
|
222
|
+
|
|
223
|
+
const nread = r.read(buf);
|
|
224
|
+
if (nread === null) {
|
|
225
|
+
return n;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// write will grow if needed
|
|
229
|
+
if (shouldGrow) this.write(buf.subarray(0, nread));
|
|
230
|
+
else this._reslice(this.length + nread);
|
|
231
|
+
|
|
232
|
+
n += nread;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function readAll(r: Reader): Uint8Array {
|
|
238
|
+
const buf = new DenoBuffer();
|
|
239
|
+
buf.readFrom(r);
|
|
240
|
+
return buf.bytes();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function writeAll(w: Writer, arr: Uint8Array): void {
|
|
244
|
+
let nwritten = 0;
|
|
245
|
+
while (nwritten < arr.length) {
|
|
246
|
+
nwritten += w.write(arr.subarray(nwritten));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 The NATS Authors
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
export const Empty: Uint8Array = new Uint8Array(0);
|
|
16
|
+
|
|
17
|
+
export const TE: InstanceType<typeof TextEncoder> = new TextEncoder();
|
|
18
|
+
export const TD: InstanceType<typeof TextDecoder> = new TextDecoder();
|
|
19
|
+
|
|
20
|
+
function concat(...bufs: Uint8Array[]): Uint8Array {
|
|
21
|
+
let max = 0;
|
|
22
|
+
for (let i = 0; i < bufs.length; i++) {
|
|
23
|
+
max += bufs[i].length;
|
|
24
|
+
}
|
|
25
|
+
const out = new Uint8Array(max);
|
|
26
|
+
let index = 0;
|
|
27
|
+
for (let i = 0; i < bufs.length; i++) {
|
|
28
|
+
out.set(bufs[i], index);
|
|
29
|
+
index += bufs[i].length;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function encode(...a: string[]): Uint8Array {
|
|
35
|
+
const bufs = [];
|
|
36
|
+
for (let i = 0; i < a.length; i++) {
|
|
37
|
+
bufs.push(TE.encode(a[i]));
|
|
38
|
+
}
|
|
39
|
+
if (bufs.length === 0) {
|
|
40
|
+
return Empty;
|
|
41
|
+
}
|
|
42
|
+
if (bufs.length === 1) {
|
|
43
|
+
return bufs[0];
|
|
44
|
+
}
|
|
45
|
+
return concat(...bufs);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function decode(a: Uint8Array): string {
|
|
49
|
+
if (!a || a.length === 0) {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
return TD.decode(a);
|
|
53
|
+
}
|