Skip to content

Commit

Permalink
removed circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Apr 29, 2024
1 parent 71a7b7c commit 6ddb1d4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
29 changes: 28 additions & 1 deletion service/internal_mod.ts
@@ -1,3 +1,11 @@
import {
NatsConnection,
RequestManyOptions,
} from "../nats-base-client/core.ts";
import { ServiceImpl } from "./service.ts";
import { ServiceClientImpl } from "./serviceclient.ts";
import { Service, ServiceClient, ServiceConfig } from "./types.ts";

export type {
Endpoint,
EndpointInfo,
Expand All @@ -24,4 +32,23 @@ export {
ServiceVerb,
} from "./types.ts";

export { Svc } from "./service.ts";
export class Svc {
nc: NatsConnection;

constructor(nc: NatsConnection) {
this.nc = nc;
}

add(config: ServiceConfig): Promise<Service> {
try {
const s = new ServiceImpl(this.nc, config);
return s.start();
} catch (err) {
return Promise.reject(err);
}
}

client(opts?: RequestManyOptions, prefix?: string): ServiceClient {
return new ServiceClientImpl(this.nc, opts, prefix);
}
}
2 changes: 1 addition & 1 deletion service/mod.ts
Expand Up @@ -24,4 +24,4 @@ export {
ServiceVerb,
} from "./internal_mod.ts";

export { Svc } from "./service.ts";
export { Svc } from "./internal_mod.ts";
23 changes: 0 additions & 23 deletions service/service.ts
Expand Up @@ -29,18 +29,15 @@ import {
Payload,
PublishOptions,
QueuedIterator,
RequestManyOptions,
ReviverFn,
Sub,
} from "../nats-base-client/core.ts";
import { ServiceClientImpl } from "./serviceclient.ts";
import {
Endpoint,
EndpointInfo,
EndpointOptions,
NamedEndpointStats,
Service,
ServiceClient,
ServiceConfig,
ServiceError,
ServiceErrorCodeHeader,
Expand All @@ -66,26 +63,6 @@ import {
*/
export const ServiceApiPrefix = "$SRV";

export class Svc {
nc: NatsConnection;
constructor(nc: NatsConnection) {
this.nc = nc;
}

add(config: ServiceConfig): Promise<Service> {
try {
const s = new ServiceImpl(this.nc, config);
return s.start();
} catch (err) {
return Promise.reject(err);
}
}

client(opts?: RequestManyOptions, prefix?: string): ServiceClient {
return new ServiceClientImpl(this.nc, opts, prefix);
}
}

export class ServiceMsgImpl implements ServiceMsg {
msg: Msg;
constructor(msg: Msg) {
Expand Down
2 changes: 1 addition & 1 deletion service/tests/service-check.ts
Expand Up @@ -23,14 +23,14 @@ import {
ServiceResponseType,
ServiceStats,
ServiceVerb,
Svc,
} from "../mod.ts";

import { collect } from "../../nats-base-client/util.ts";
import { ServiceClientImpl } from "../serviceclient.ts";
import Ajv, { JSONSchemaType, ValidateFunction } from "npm:ajv";

import { parseSemVer } from "../../nats-base-client/semver.ts";
import { Svc } from "../service.ts";

const ajv = new Ajv();

Expand Down
3 changes: 2 additions & 1 deletion service/tests/service_test.ts
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/
import { cleanup, setup } from "../../tests/helpers/mod.ts";
import { ServiceImpl, Svc } from "../service.ts";
import { ServiceImpl } from "../service.ts";
import {
assert,
assertArrayIncludes,
Expand All @@ -38,6 +38,7 @@ import {
ServiceResponseType,
ServiceStats,
ServiceVerb,
Svc,
} from "../types.ts";
import {
connect,
Expand Down

0 comments on commit 6ddb1d4

Please sign in to comment.