Skip to content

Commit

Permalink
bump bundles, fix bundle names for transport, fix imports for process…
Browse files Browse the repository at this point in the history
… in node

Signed-off-by: Alberto Ricart <[email protected]>
  • Loading branch information
aricart committed Oct 28, 2024
1 parent bc229c9 commit 29c0d5c
Show file tree
Hide file tree
Showing 32 changed files with 248 additions and 109 deletions.
56 changes: 30 additions & 26 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ is working.

```typescript
// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]4";
import { connect } from "jsr:@nats-io/[email protected]7";

const servers = [
{},
Expand Down Expand Up @@ -179,7 +179,7 @@ the server.

```typescript
// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]4";
import { connect } from "jsr:@nats-io/[email protected]7";

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand Down Expand Up @@ -241,8 +241,8 @@ All subscriptions are independent. If two different subscriptions match a
subject, both will get to process the message:

```typescript
import { connect } from "jsr:@nats-io/nats-[email protected]4";
import type { Subscription } from "jsr:@nats-io/nats-[email protected]4";
import { connect } from "jsr:@nats-io/[email protected]7";
import type { Subscription } from "jsr:@nats-io/[email protected]7";
const nc = await connect({ servers: "demo.nats.io:4222" });

// subscriptions can have wildcard subjects
Expand Down Expand Up @@ -418,11 +418,11 @@ independent unit. Note that non-queue subscriptions are also independent of
subscriptions in a queue group.

```typescript
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";
import type {
NatsConnection,
Subscription,
} from "jsr:@nats-io/nats-[email protected]4";
} from "jsr:@nats-io/[email protected]7";

async function createService(
name: string,
Expand Down Expand Up @@ -541,29 +541,33 @@ If you send a request for which there's no interest, the request will be
immediately rejected:

```typescript
import { connect, ErrorCode } from "jsr:@nats-io/[email protected]";
import type { NatsError } from "jsr:@nats-io/[email protected]";

const nc = await connect(
{
servers: `demo.nats.io`,
},
);
import { connect } from "jsr:@nats-io/[email protected]";
import {
NoRespondersError,
RequestError,
TimeoutError,
} from "jsr:@nats-io/[email protected]";

const nc = await connect({
servers: `demo.nats.io`,
});

try {
const m = await nc.request("hello.world");
console.log(m.data);
} catch (err) {
const nerr = err as NatsError;
switch (nerr.code) {
case ErrorCode.NoResponders:
console.log("no one is listening to 'hello.world'");
break;
case ErrorCode.Timeout:
if (err instanceof RequestError) {
if (err.cause instanceof TimeoutError) {
console.log("someone is listening but didn't respond");
break;
default:
console.log("request failed", err);
} else if (err.cause instanceof NoRespondersError) {
console.log("no one is listening to 'hello.world'");
} else {
console.log(
`failed due to unknown error: ${(err.cause as Error)?.message}`,
);
}
} else {
console.log(`request failed: ${(err as Error).message}`);
}
}

Expand Down Expand Up @@ -591,7 +595,7 @@ Setting the `user`/`pass` or `token` options, simply initializes an
```typescript
// if the connection requires authentication, provide `user` and `pass` or
// `token` options in the NatsConnectionOptions
import { connect } from "jsr:@nats-io/nats-[email protected]";
import { connect } from "jsr:@nats-io/[email protected]";

const nc1 = await connect({
servers: "127.0.0.1:4222",
Expand Down Expand Up @@ -680,8 +684,8 @@ You can specify several options when creating a subscription:
- `timeout`: how long to wait for the first message
- `queue`: the [queue group](#queue-groups) name the subscriber belongs to
- `callback`: a function with the signature
`(err: NatsError|null, msg: Msg) => void;` that should be used for handling
the message. Subscriptions with callbacks are NOT iterators.
`(err: Error|null, msg: Msg) => void;` that should be used for handling the
message. Subscriptions with callbacks are NOT iterators.

#### Auto Unsubscribe

Expand Down
4 changes: 2 additions & 2 deletions core/examples/snippets/autounsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import type { Subscription } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";
import type { Subscription } from "jsr:@nats-io/[email protected]7";

// create a connection
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand Down
2 changes: 1 addition & 1 deletion core/examples/snippets/basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand Down
2 changes: 1 addition & 1 deletion core/examples/snippets/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";

const servers = [
{},
Expand Down
2 changes: 1 addition & 1 deletion core/examples/snippets/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Empty,
headers,
nuid,
} from "jsr:@nats-io/nats-[email protected]5";
} from "jsr:@nats-io/[email protected]7";

const nc = await connect(
{
Expand Down
4 changes: 2 additions & 2 deletions core/examples/snippets/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand All @@ -30,7 +30,7 @@ const sub = nc.subscribe("people");
for await (const m of sub) {
// typescript will see this as a Person
const p = m.json<Person>();
console.log(`[${sub.getProcessed()}]: ${p.name}`);
console.log(p);
}
})();

Expand Down
43 changes: 32 additions & 11 deletions core/examples/snippets/no_responders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { connect, ErrorCode } from "jsr:@nats-io/[email protected]";
import type { NatsError } from "jsr:@nats-io/[email protected]";
/*
* Copyright 2024 Synadia Communications, Inc
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/[email protected]";
import {
NoRespondersError,
RequestError,
TimeoutError,
} from "jsr:@nats-io/[email protected]";

const nc = await connect(
{
Expand All @@ -11,16 +30,18 @@ try {
const m = await nc.request("hello.world");
console.log(m.data);
} catch (err) {
const nerr = err as NatsError;
switch (nerr.code) {
case ErrorCode.NoResponders:
console.log("no one is listening to 'hello.world'");
break;
case ErrorCode.Timeout:
if (err instanceof RequestError) {
if (err.cause instanceof TimeoutError) {
console.log("someone is listening but didn't respond");
break;
default:
console.log("request failed", err);
} else if (err.cause instanceof NoRespondersError) {
console.log("no one is listening to 'hello.world'");
} else {
console.log(
`failed due to unknown error: ${(err.cause as Error)?.message}`,
);
}
} else {
console.log(`request failed: ${(err as Error).message}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/examples/snippets/queuegroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";
import type {
NatsConnection,
Subscription,
} from "jsr:@nats-io/nats-[email protected]4";
} from "jsr:@nats-io/[email protected]7";

async function createService(
name: string,
Expand Down
4 changes: 2 additions & 2 deletions core/examples/snippets/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import type { Subscription } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";
import type { Subscription } from "jsr:@nats-io/[email protected]7";

// create a connection
const nc = await connect({ servers: "demo.nats.io" });
Expand Down
2 changes: 1 addition & 1 deletion core/examples/snippets/service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect, Empty } from "jsr:@nats-io/nats-[email protected]5";
import { connect, Empty } from "jsr:@nats-io/[email protected]7";

// create a connection
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand Down
2 changes: 1 addition & 1 deletion core/examples/snippets/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io" });
Expand Down
4 changes: 2 additions & 2 deletions core/examples/snippets/sub_timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect, ErrorCode } from "jsr:@nats-io/nats-[email protected]5";
import { connect, TimeoutError } from "jsr:@nats-io/[email protected]7";

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand All @@ -27,7 +27,7 @@ const sub = nc.subscribe("hello", { timeout: 1000 });
// handle the messages
}
})().catch((err) => {
if (err.code === ErrorCode.Timeout) {
if (err instanceof TimeoutError) {
console.log(`sub timed out!`);
} else {
console.log(`sub iterator got an error!`);
Expand Down
8 changes: 4 additions & 4 deletions core/examples/snippets/unsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

// import the connect function from a transport
import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";

// to create a connection to a nats-server:
const nc = await connect({ servers: "demo.nats.io:4222" });
Expand All @@ -38,9 +38,9 @@ const manual = nc.subscribe("hello");
const done = (async () => {
console.log("waiting for a message on `hello` with a payload of `stop`");
for await (const m of manual) {
const d = sc.decode(m.data);
console.log("manual", manual.getProcessed(), d);
if (d === "stop") {
const payload = m.string();
console.log("manual", manual.getProcessed(), payload);
if (payload === "stop") {
manual.unsubscribe();
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/examples/snippets/wildcard_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import type { Subscription } from "jsr:@nats-io/nats-[email protected]5";
import { connect } from "jsr:@nats-io/[email protected]7";
import type { Subscription } from "jsr:@nats-io/[email protected]7";

const nc = await connect({ servers: "demo.nats.io:4222" });

Expand Down
4 changes: 2 additions & 2 deletions jetstream/examples/01_consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { jetstream } from "../src/mod.ts";
import { connect } from "jsr:@nats-io/[email protected]7";
import { jetstream } from "jsr:@nats-io/[email protected]";
import { setupStreamAndConsumer } from "./util.ts";

// create a connection
Expand Down
4 changes: 2 additions & 2 deletions jetstream/examples/02_next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { jetstream } from "../src/mod.ts";
import { connect } from "jsr:@nats-io/[email protected]7";
import { jetstream } from "jsr:@nats-io/[email protected]";
import { setupStreamAndConsumer } from "./util.ts";

// create a connection
Expand Down
4 changes: 2 additions & 2 deletions jetstream/examples/03_batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { jetstream } from "../src/mod.ts";
import { connect } from "jsr:@nats-io/[email protected]7";
import { jetstream } from "jsr:@nats-io/[email protected]";
import { setupStreamAndConsumer } from "./util.ts";

// create a connection
Expand Down
6 changes: 3 additions & 3 deletions jetstream/examples/04_consume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { jetstream } from "../src/mod.ts";
import { connect } from "jsr:@nats-io/[email protected]7";
import { jetstream } from "jsr:@nats-io/[email protected]";
import { setupStreamAndConsumer } from "./util.ts";

// create a connection
Expand All @@ -39,6 +39,6 @@ while (true) {
m.ack();
}
} catch (err) {
console.log(`consume failed: ${err.message}`);
console.log(`consume failed: ${(err as Error).message}`);
}
}
4 changes: 2 additions & 2 deletions jetstream/examples/05_consume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { jetstream } from "../src/mod.ts";
import { connect } from "jsr:@nats-io/[email protected]7";
import { jetstream } from "jsr:@nats-io/[email protected]";
import { setupStreamAndConsumer } from "./util.ts";

// create a connection
Expand Down
4 changes: 2 additions & 2 deletions jetstream/examples/06_heartbeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { connect } from "jsr:@nats-io/nats-[email protected]5";
import { ConsumerEvents, jetstream } from "../src/mod.ts";
import { connect } from "jsr:@nats-io/[email protected]7";
import { ConsumerEvents, jetstream } from "jsr:@nats-io/[email protected]";
import { setupStreamAndConsumer } from "./util.ts";

// create a connection
Expand Down
Loading

0 comments on commit 29c0d5c

Please sign in to comment.