Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(obj): changed Svc to Svcm to align with Kvm, Objm, etc #169

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)`
2 changes: 1 addition & 1 deletion services/deno.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 6 additions & 8 deletions services/examples/01_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
* limitations under the License.
*/

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

import type { QueuedIterator } from "jsr:@nats-io/[email protected]";
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";
Expand All @@ -42,7 +40,7 @@ const statsHandler = (): Promise<unknown> => {
};

// 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",
Expand Down Expand Up @@ -139,13 +137,13 @@ function decoder(r: ServiceMsg): Promise<number[]> {
// 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);
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions services/examples/02_multiple_endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*/

import { connect } from "jsr:@nats-io/[email protected]";
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",
Expand Down
4 changes: 2 additions & 2 deletions services/examples/03_bigdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/

import { connect } from "jsr:@nats-io/[email protected]";
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",
Expand Down
2 changes: 1 addition & 1 deletion services/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/services",
"version": "3.0.0-21",
"version": "3.0.0-22",
"files": [
"lib/",
"LICENSE",
Expand Down
2 changes: 1 addition & 1 deletion services/src/internal_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export {
ServiceVerb,
} from "./types.ts";

export class Svc {
export class Svcm {
nc: NatsConnection;

constructor(nc: NatsConnection) {
Expand Down
2 changes: 1 addition & 1 deletion services/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export {
ServiceErrorHeader,
ServiceResponseType,
ServiceVerb,
Svc,
Svcm,
} from "./internal_mod.ts";
10 changes: 5 additions & 5 deletions services/tests/service-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* limitations under the License.
*/

import { cli } from "https://deno.land/x/[email protected]/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";
Expand All @@ -24,7 +24,7 @@ import {
ServiceError,
ServiceResponseType,
ServiceVerb,
Svc,
Svcm,
} from "../src/mod.ts";

import type { ServiceClientImpl } from "../src/serviceclient.ts";
Expand Down Expand Up @@ -136,7 +136,7 @@ async function checkPing(nc: NatsConnection, name: string) {
}

async function invoke(nc: NatsConnection, name: string): Promise<void> {
const svc = new Svc(nc);
const svc = new Svcm(nc);
const sc = svc.client();
const infos = await collect(await sc.info(name));

Expand Down Expand Up @@ -199,7 +199,7 @@ async function check<T extends ServiceIdentity>(
}
};

const svc = new Svc(nc);
const svc = new Svcm(nc);
const sc = svc.client() as ServiceClientImpl;
// all
let responses = filter(
Expand Down
Loading