@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.
Files changed (32) hide show
  1. package/externals/nats.js/core/src/authenticator.ts +159 -0
  2. package/externals/nats.js/core/src/bench.ts +426 -0
  3. package/externals/nats.js/core/src/codec.ts +28 -0
  4. package/externals/nats.js/core/src/core.ts +1219 -0
  5. package/externals/nats.js/core/src/databuffer.ts +129 -0
  6. package/externals/nats.js/core/src/denobuffer.ts +248 -0
  7. package/externals/nats.js/core/src/encoders.ts +53 -0
  8. package/externals/nats.js/core/src/errors.ts +300 -0
  9. package/externals/nats.js/core/src/headers.ts +315 -0
  10. package/externals/nats.js/core/src/heartbeats.ts +114 -0
  11. package/externals/nats.js/core/src/idleheartbeat_monitor.ts +140 -0
  12. package/externals/nats.js/core/src/internal_mod.ts +167 -0
  13. package/externals/nats.js/core/src/ipparser.ts +215 -0
  14. package/externals/nats.js/core/src/mod.ts +113 -0
  15. package/externals/nats.js/core/src/msg.ts +120 -0
  16. package/externals/nats.js/core/src/muxsubscription.ts +111 -0
  17. package/externals/nats.js/core/src/nats.ts +650 -0
  18. package/externals/nats.js/core/src/nkeys.ts +1 -0
  19. package/externals/nats.js/core/src/nuid.ts +16 -0
  20. package/externals/nats.js/core/src/options.ts +202 -0
  21. package/externals/nats.js/core/src/parser.ts +756 -0
  22. package/externals/nats.js/core/src/protocol.ts +1304 -0
  23. package/externals/nats.js/core/src/queued_iterator.ts +171 -0
  24. package/externals/nats.js/core/src/request.ts +177 -0
  25. package/externals/nats.js/core/src/semver.ts +165 -0
  26. package/externals/nats.js/core/src/servers.ts +424 -0
  27. package/externals/nats.js/core/src/transport.ts +117 -0
  28. package/externals/nats.js/core/src/types.ts +17 -0
  29. package/externals/nats.js/core/src/util.ts +367 -0
  30. package/externals/nats.js/core/src/version.ts +2 -0
  31. package/externals/nats.js/core/src/ws_transport.ts +391 -0
  32. package/package.json +2 -1
@@ -0,0 +1,113 @@
1
+ /*
2
+ * Copyright 2024 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
+ export {
17
+ AuthorizationError,
18
+ backoff,
19
+ Bench,
20
+ buildAuthenticator,
21
+ canonicalMIMEHeaderKey,
22
+ ClosedConnectionError,
23
+ ConnectionError,
24
+ createInbox,
25
+ credsAuthenticator,
26
+ deadline,
27
+ deferred,
28
+ delay,
29
+ DrainingConnectionError,
30
+ Empty,
31
+ errors,
32
+ hasWsProtocol,
33
+ headers,
34
+ InvalidArgumentError,
35
+ InvalidOperationError,
36
+ InvalidSubjectError,
37
+ jwtAuthenticator,
38
+ Match,
39
+ Metric,
40
+ millis,
41
+ MsgHdrsImpl,
42
+ nanos,
43
+ nkeyAuthenticator,
44
+ nkeys,
45
+ NoRespondersError,
46
+ Nuid,
47
+ nuid,
48
+ PermissionViolationError,
49
+ ProtocolError,
50
+ RequestError,
51
+ syncIterator,
52
+ TimeoutError,
53
+ tokenAuthenticator,
54
+ UserAuthenticationExpiredError,
55
+ usernamePasswordAuthenticator,
56
+ wsconnect,
57
+ } from "./internal_mod.ts";
58
+
59
+ export type {
60
+ Auth,
61
+ Authenticator,
62
+ Backoff,
63
+ BenchOpts,
64
+ ClientPingStatus,
65
+ CloseStatus,
66
+ ClusterUpdateStatus,
67
+ Codec,
68
+ ConnectionOptions,
69
+ Deferred,
70
+ Delay,
71
+ DisconnectStatus,
72
+ ForceReconnectStatus,
73
+ JwtAuth,
74
+ LDMStatus,
75
+ Msg,
76
+ MsgCallback,
77
+ MsgHdrs,
78
+ Nanos,
79
+ NatsConnection,
80
+ NKeyAuth,
81
+ NoAuth,
82
+ Payload,
83
+ Perf,
84
+ Publisher,
85
+ PublishOptions,
86
+ QueuedIterator,
87
+ ReconnectingStatus,
88
+ ReconnectStatus,
89
+ ReconnectToServerHandler,
90
+ RequestManyOptions,
91
+ RequestOptions,
92
+ RequestStrategy,
93
+ ReviverFn,
94
+ Server,
95
+ ServerErrorStatus,
96
+ ServerInfo,
97
+ ServersChanged,
98
+ SlowConsumerStatus,
99
+ StaleConnectionStatus,
100
+ Stats,
101
+ Status,
102
+ SubOpts,
103
+ Subscription,
104
+ SubscriptionOptions,
105
+ SyncIterator,
106
+ Timeout,
107
+ TlsOptions,
108
+ TokenAuth,
109
+ UserPass,
110
+ WithRequired,
111
+ WsConnectionOptions,
112
+ WsSocketFactory,
113
+ } from "./internal_mod.ts";
@@ -0,0 +1,120 @@
1
+ /*
2
+ * Copyright 2020-2024 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
+ import { MsgHdrsImpl } from "./headers.ts";
16
+ import type { MsgArg } from "./parser.ts";
17
+ import { Empty, TD } from "./encoders.ts";
18
+ import type {
19
+ Msg,
20
+ MsgHdrs,
21
+ Payload,
22
+ Publisher,
23
+ RequestInfo,
24
+ ReviverFn,
25
+ } from "./core.ts";
26
+
27
+ export class MsgImpl implements Msg {
28
+ _headers?: MsgHdrs;
29
+ _msg: MsgArg;
30
+ _rdata: Uint8Array;
31
+ _reply!: string;
32
+ _subject!: string;
33
+ publisher: Publisher;
34
+
35
+ constructor(msg: MsgArg, data: Uint8Array, publisher: Publisher) {
36
+ this._msg = msg;
37
+ this._rdata = data;
38
+ this.publisher = publisher;
39
+ }
40
+
41
+ get subject(): string {
42
+ if (this._subject) {
43
+ return this._subject;
44
+ }
45
+ this._subject = TD.decode(this._msg.subject);
46
+ return this._subject;
47
+ }
48
+
49
+ get reply(): string {
50
+ if (this._reply) {
51
+ return this._reply;
52
+ }
53
+ this._reply = TD.decode(this._msg.reply);
54
+ return this._reply;
55
+ }
56
+
57
+ get sid(): number {
58
+ return this._msg.sid;
59
+ }
60
+
61
+ get headers(): MsgHdrs | undefined {
62
+ if (this._msg.hdr > -1 && !this._headers) {
63
+ const buf = this._rdata.subarray(0, this._msg.hdr);
64
+ this._headers = MsgHdrsImpl.decode(buf);
65
+ }
66
+ return this._headers;
67
+ }
68
+
69
+ get data(): Uint8Array {
70
+ if (!this._rdata) {
71
+ return new Uint8Array(0);
72
+ }
73
+ return this._msg.hdr > -1
74
+ ? this._rdata.subarray(this._msg.hdr)
75
+ : this._rdata;
76
+ }
77
+
78
+ // eslint-ignore-next-line @typescript-eslint/no-explicit-any
79
+ respond(
80
+ data: Payload = Empty,
81
+ opts?: { headers?: MsgHdrs; reply?: string },
82
+ ): boolean {
83
+ if (this.reply) {
84
+ this.publisher.publish(this.reply, data, opts);
85
+ return true;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ size(): number {
91
+ const subj = this._msg.subject.length;
92
+ const reply = this._msg.reply?.length || 0;
93
+ const payloadAndHeaders = this._msg.size === -1 ? 0 : this._msg.size;
94
+ return subj + reply + payloadAndHeaders;
95
+ }
96
+
97
+ json<T = unknown>(reviver?: ReviverFn): T {
98
+ return JSON.parse(this.string(), reviver);
99
+ }
100
+
101
+ string(): string {
102
+ return TD.decode(this.data);
103
+ }
104
+
105
+ requestInfo(): RequestInfo | null {
106
+ const v = this.headers?.get("Nats-Request-Info");
107
+ if (v) {
108
+ return JSON.parse(
109
+ v,
110
+ function (this: unknown, key: string, value: unknown): unknown {
111
+ if ((key === "start" || key === "stop") && value !== "") {
112
+ return new Date(Date.parse(value as string));
113
+ }
114
+ return value;
115
+ },
116
+ ) as RequestInfo;
117
+ }
118
+ return null;
119
+ }
120
+ }
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright 2020-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
+ import type { Msg, MsgCallback, Request } from "./core.ts";
16
+ import { createInbox } from "./core.ts";
17
+ import { NoRespondersError, RequestError } from "./errors.ts";
18
+
19
+ import type { PermissionViolationError } from "./errors.ts";
20
+
21
+ export class MuxSubscription {
22
+ baseInbox!: string;
23
+ reqs: Map<string, Request>;
24
+
25
+ constructor() {
26
+ this.reqs = new Map<string, Request>();
27
+ }
28
+
29
+ size(): number {
30
+ return this.reqs.size;
31
+ }
32
+
33
+ init(prefix?: string): string {
34
+ this.baseInbox = `${createInbox(prefix)}.`;
35
+ return this.baseInbox;
36
+ }
37
+
38
+ add(r: Request) {
39
+ if (!isNaN(r.received)) {
40
+ r.received = 0;
41
+ }
42
+ this.reqs.set(r.token, r);
43
+ }
44
+
45
+ get(token: string): Request | undefined {
46
+ return this.reqs.get(token);
47
+ }
48
+
49
+ cancel(r: Request): void {
50
+ this.reqs.delete(r.token);
51
+ }
52
+
53
+ getToken(m: Msg): string | null {
54
+ const s = m.subject || "";
55
+ if (s.indexOf(this.baseInbox) === 0) {
56
+ return s.substring(this.baseInbox.length);
57
+ }
58
+ return null;
59
+ }
60
+
61
+ all(): Request[] {
62
+ return Array.from(this.reqs.values());
63
+ }
64
+
65
+ handleError(
66
+ isMuxPermissionError: boolean,
67
+ err: PermissionViolationError,
68
+ ): boolean {
69
+ if (isMuxPermissionError) {
70
+ // one or more requests queued but mux cannot process them
71
+ this.all().forEach((r) => {
72
+ r.resolver(err, {} as Msg);
73
+ });
74
+ return true;
75
+ }
76
+ if (err.operation === "publish") {
77
+ const req = this.all().find((s) => {
78
+ return s.requestSubject === err.subject;
79
+ });
80
+ if (req) {
81
+ req.resolver(err, {} as Msg);
82
+ return true;
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+
88
+ dispatcher(): MsgCallback<Msg> {
89
+ return (err: Error | null, m: Msg) => {
90
+ const token = this.getToken(m);
91
+ if (token) {
92
+ const r = this.get(token);
93
+ if (r) {
94
+ if (err === null) {
95
+ err = (m?.data?.length === 0 && m.headers?.code === 503)
96
+ ? new NoRespondersError(r.requestSubject)
97
+ : null;
98
+ }
99
+ r.resolver(err, m);
100
+ }
101
+ }
102
+ };
103
+ }
104
+
105
+ close() {
106
+ const err = new RequestError("connection closed");
107
+ this.reqs.forEach((req) => {
108
+ req.resolver(err, {} as Msg);
109
+ });
110
+ }
111
+ }