diff --git a/migration.md b/migration.md index bf12c61a..d23953e3 100644 --- a/migration.md +++ b/migration.md @@ -222,7 +222,7 @@ instance of Svc, which allows you to `add()` a service and create a ServiceClient `client(nc)`: ```typescript -const svc = new Svc(nc); +const svc = new Svcm(nc); const service = await svc.add({ name: "max", version: "0.0.1", @@ -234,4 +234,4 @@ const service = await svc.add({ ``` - `services` property has been removed. Install and import the `Services` - library, and call `services(nc: NatsConnection)` + library, and call `Svcm(nc: NatsConnection)` diff --git a/services/deno.json b/services/deno.json index 10d7883f..bfc88fd9 100644 --- a/services/deno.json +++ b/services/deno.json @@ -1,6 +1,6 @@ { "name": "@nats-io/services", - "version": "3.0.0-21", + "version": "3.0.0-22", "exports": { ".": "./src/mod.ts", "./internal": "./src/internal_mod.ts" diff --git a/services/examples/01_services.ts b/services/examples/01_services.ts index d2b87bf1..f424486c 100644 --- a/services/examples/01_services.ts +++ b/services/examples/01_services.ts @@ -13,15 +13,13 @@ * limitations under the License. */ -import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; - -import type { QueuedIterator } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; +import { connect, type QueuedIterator } from "jsr:@nats-io/transport-deno"; import { ServiceError, ServiceErrorCodeHeader, ServiceErrorHeader, - Svc, + Svcm, } from "../src/mod.ts"; import type { ServiceMsg, ServiceStats } from "../src/mod.ts"; import { assertEquals } from "jsr:@std/assert"; @@ -42,7 +40,7 @@ const statsHandler = (): Promise => { }; // create a service - using the statsHandler -const svc = new Svc(nc); +const svc = new Svcm(nc); const service = await svc.add({ name: "max", version: "0.0.1", @@ -139,13 +137,13 @@ function decoder(r: ServiceMsg): Promise { // Now we switch gears and look at a client making a request: // we call the service without any payload and expect some errors -await nc.request("max").then((r) => { +await nc.request("max").then((r: ServiceMsg) => { // errors are really these two headers set on the message assertEquals(r.headers?.get(ServiceErrorHeader), "Bad JSON"); assertEquals(r.headers?.get(ServiceErrorCodeHeader), "400"); }); // call it with an empty array also expecting an error response -await nc.request("max", JSON.stringify([])).then((r) => { +await nc.request("max", JSON.stringify([])).then((r: ServiceMsg) => { // Here's an alternative way of checking if the response is an error response assertEquals(ServiceError.isServiceError(r), true); const se = ServiceError.toServiceError(r); @@ -154,7 +152,7 @@ await nc.request("max", JSON.stringify([])).then((r) => { }); // call it with valid arguments -await nc.request("max", JSON.stringify([1, 10, 100])).then((r) => { +await nc.request("max", JSON.stringify([1, 10, 100])).then((r: ServiceMsg) => { // no error headers assertEquals(ServiceError.isServiceError(r), false); // and the response is on the payload, so we process the JSON we diff --git a/services/examples/02_multiple_endpoints.ts b/services/examples/02_multiple_endpoints.ts index 0e11542e..989b6632 100644 --- a/services/examples/02_multiple_endpoints.ts +++ b/services/examples/02_multiple_endpoints.ts @@ -14,14 +14,14 @@ */ import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; -import { ServiceError, Svc } from "../src/mod.ts"; +import { ServiceError, Svcm } from "../src/mod.ts"; import type { ServiceMsg } from "../src/mod.ts"; // connect to NATS on demo.nats.io const nc = await connect({ servers: ["demo.nats.io"] }); // create a service - using the statsHandler and decoder -const svc = new Svc(nc); +const svc = new Svcm(nc); const calc = await svc.add({ name: "calc", version: "0.0.1", diff --git a/services/examples/03_bigdata.ts b/services/examples/03_bigdata.ts index cfc3d62f..226429a1 100644 --- a/services/examples/03_bigdata.ts +++ b/services/examples/03_bigdata.ts @@ -14,12 +14,12 @@ */ import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; -import { Svc } from "../src/mod.ts"; +import { Svcm } from "../src/mod.ts"; import { humanizeBytes } from "./03_util.ts"; import type { DataRequest } from "./03_util.ts"; const nc = await connect({ servers: "demo.nats.io" }); -const svc = new Svc(nc); +const svc = new Svcm(nc); const srv = await svc.add({ name: "big-data", version: "0.0.1", diff --git a/services/package.json b/services/package.json index 34badc12..385df530 100644 --- a/services/package.json +++ b/services/package.json @@ -1,6 +1,6 @@ { "name": "@nats-io/services", - "version": "3.0.0-21", + "version": "3.0.0-22", "files": [ "lib/", "LICENSE", diff --git a/services/src/internal_mod.ts b/services/src/internal_mod.ts index 4b61e120..d1e5ef36 100644 --- a/services/src/internal_mod.ts +++ b/services/src/internal_mod.ts @@ -30,7 +30,7 @@ export { ServiceVerb, } from "./types.ts"; -export class Svc { +export class Svcm { nc: NatsConnection; constructor(nc: NatsConnection) { diff --git a/services/src/mod.ts b/services/src/mod.ts index 6e231d44..a08676f3 100644 --- a/services/src/mod.ts +++ b/services/src/mod.ts @@ -23,5 +23,5 @@ export { ServiceErrorHeader, ServiceResponseType, ServiceVerb, - Svc, + Svcm, } from "./internal_mod.ts"; diff --git a/services/tests/service-check.ts b/services/tests/service-check.ts index 8933a872..9975837f 100644 --- a/services/tests/service-check.ts +++ b/services/tests/service-check.ts @@ -13,8 +13,8 @@ * limitations under the License. */ -import { cli } from "https://deno.land/x/cobra@v0.0.9/mod.ts"; -import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-4"; +import { cli } from "jsr:@aricart/cobra"; +import { connect } from "@nats-io/transport-deno"; import { collect, parseSemVer } from "@nats-io/nats-core/internal"; import type { NatsConnection } from "@nats-io/nats-core/internal"; @@ -24,7 +24,7 @@ import { ServiceError, ServiceResponseType, ServiceVerb, - Svc, + Svcm, } from "../src/mod.ts"; import type { ServiceClientImpl } from "../src/serviceclient.ts"; @@ -136,7 +136,7 @@ async function checkPing(nc: NatsConnection, name: string) { } async function invoke(nc: NatsConnection, name: string): Promise { - const svc = new Svc(nc); + const svc = new Svcm(nc); const sc = svc.client(); const infos = await collect(await sc.info(name)); @@ -199,7 +199,7 @@ async function check( } }; - const svc = new Svc(nc); + const svc = new Svcm(nc); const sc = svc.client() as ServiceClientImpl; // all let responses = filter( diff --git a/services/tests/service_test.ts b/services/tests/service_test.ts index 35f5f958..e3d0f670 100644 --- a/services/tests/service_test.ts +++ b/services/tests/service_test.ts @@ -52,7 +52,7 @@ import { ServiceErrorHeader, ServiceResponseType, ServiceVerb, - Svc, + Svcm, } from "../src/mod.ts"; Deno.test("service - control subject", () => { @@ -76,7 +76,7 @@ Deno.test("service - control subject", () => { Deno.test("service - bad name", async () => { const { ns, nc } = await setup({}, {}); - const svc = new Svc(nc); + const svc = new Svcm(nc); const t = async (name: string, msg: string) => { await assertRejects( async () => { @@ -100,7 +100,7 @@ Deno.test("service - bad name", async () => { Deno.test("service - client", async () => { const { ns, nc } = await setup({}, {}); const subj = createInbox(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "test", @@ -201,7 +201,7 @@ Deno.test("service - client", async () => { Deno.test("service - basics", async () => { const { ns, nc } = await setup({}, {}); - const svc = new Svc(nc); + const svc = new Svcm(nc); const conf: ServiceConfig = { name: "test", version: "0.0.0", @@ -273,7 +273,7 @@ Deno.test("service - stop error", async () => { }, }, { user: "a", pass: "a" }); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -308,7 +308,7 @@ Deno.test("service - start error", async () => { }, }, { user: "a", pass: "a" }); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -326,7 +326,7 @@ Deno.test("service - start error", async () => { Deno.test("service - callback error", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "test", version: "2.0.0", @@ -347,7 +347,7 @@ Deno.test("service - callback error", async () => { Deno.test("service - service error is headers", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "test", version: "2.0.0", @@ -366,7 +366,7 @@ Deno.test("service - service error is headers", async () => { Deno.test("service - sub stop", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -390,7 +390,7 @@ Deno.test("service - sub stop", async () => { Deno.test("service - monitoring sub stop", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -414,7 +414,7 @@ Deno.test("service - monitoring sub stop", async () => { Deno.test("service - custom stats handler", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "test", version: "2.0.0", @@ -447,7 +447,7 @@ Deno.test("service - bad stats handler", async () => { statsHandler: "hello world", }; - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add(config as unknown as ServiceConfig); srv.addEndpoint("q", (_err, m) => { m.respond(); @@ -463,7 +463,7 @@ Deno.test("service - bad stats handler", async () => { Deno.test("service - stats handler error", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "test", version: "2.0.0", @@ -490,7 +490,7 @@ Deno.test("service - stats handler error", async () => { Deno.test("service - reset", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -532,7 +532,7 @@ Deno.test("service - reset", async () => { Deno.test("service - iter", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -568,7 +568,7 @@ Deno.test("service - iter", async () => { Deno.test("service - iter closed", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const service = await svc.add({ name: "test", version: "2.0.0", @@ -591,7 +591,7 @@ Deno.test("service - iter closed", async () => { Deno.test("service - version must be semver", async () => { const { ns, nc } = await setup(); const test = (v?: string): Promise => { - const svc = new Svc(nc); + const svc = new Svcm(nc); return svc.add({ name: "test", version: v!, @@ -628,7 +628,7 @@ Deno.test("service - version must be semver", async () => { Deno.test("service - service errors", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "test", version: "2.0.0", @@ -721,7 +721,7 @@ Deno.test("service - service errors", async () => { Deno.test("service - stats name respects assigned name", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const test = await svc.add({ name: "tEsT", // @ts-ignore: testing @@ -742,7 +742,7 @@ Deno.test("service - stats name respects assigned name", async () => { Deno.test("service - multiple endpoints", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const ms = await svc.add({ name: "multi", version: "0.0.1", @@ -778,7 +778,7 @@ Deno.test("service - multiple endpoints", async () => { Deno.test("service - multi cb/iterator", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -805,7 +805,7 @@ Deno.test("service - multi cb/iterator", async () => { Deno.test("service - group and endpoint names", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -833,7 +833,7 @@ Deno.test("service - group and endpoint names", async () => { Deno.test("service - group subs", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -862,7 +862,7 @@ Deno.test("service - group subs", async () => { Deno.test("service - metadata", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -888,7 +888,7 @@ Deno.test("service - metadata", async () => { Deno.test("service - schema metadata", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -909,7 +909,7 @@ Deno.test("service - schema metadata", async () => { Deno.test("service - json reviver", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -937,7 +937,7 @@ Deno.test("service - json reviver", async () => { }); async function testQueueName(nc: NatsConnection, subj: string, q?: string) { - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -1013,7 +1013,7 @@ function checkQueueGroup(srv: Service, subj: string, queue: string) { Deno.test("service - endpoint default queue group", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -1051,7 +1051,7 @@ Deno.test("service - endpoint default queue group", async () => { Deno.test("service - endpoint no queue group", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1", @@ -1087,7 +1087,7 @@ Deno.test("service - endpoint no queue group", async () => { Deno.test("service - metadata is not editable", async () => { const { ns, nc } = await setup(); - const svc = new Svc(nc); + const svc = new Svcm(nc); const srv = await svc.add({ name: "example", version: "0.0.1",