Skip to content

Commit 623f036

Browse files
committed
more nats -> conat renaming
1 parent e0eeb09 commit 623f036

File tree

14 files changed

+73
-75
lines changed

14 files changed

+73
-75
lines changed

src/packages/backend/conat/test/service.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pnpm test ./service.test.ts
66
77
*/
88

9-
import { callNatsService, createNatsService } from "@cocalc/conat/service";
9+
import { callConatService, createConatService } from "@cocalc/conat/service";
1010
import { once } from "@cocalc/util/async-utils";
1111
import { before, after } from "@cocalc/backend/conat/test/setup";
1212
import { wait } from "@cocalc/backend/conat/test/util";
@@ -16,22 +16,20 @@ beforeAll(before);
1616
describe("create a service and test it out", () => {
1717
let s;
1818
it("creates a service", async () => {
19-
s = createNatsService({
19+
s = createConatService({
2020
service: "echo",
2121
handler: (mesg) => mesg.repeat(2),
2222
});
2323
await once(s, "running");
24-
expect(await callNatsService({ service: "echo", mesg: "hello" })).toBe(
24+
expect(await callConatService({ service: "echo", mesg: "hello" })).toBe(
2525
"hellohello",
2626
);
2727
});
2828

2929
it("closes the services and observes it doesn't work anymore", async () => {
3030
s.close();
31-
32-
let t = "";
3331
await expect(async () => {
34-
await callNatsService({ service: "echo", mesg: "hi", timeout: 1000 });
32+
await callConatService({ service: "echo", mesg: "hi", timeout: 1000 });
3533
}).rejects.toThrowError("timeout");
3634
});
3735
});
@@ -40,12 +38,12 @@ describe("verify that you can create a service AFTER calling it and things to st
4038
let result = "";
4139
it("call a service that does not exist yet", () => {
4240
(async () => {
43-
result = await callNatsService({ service: "echo3", mesg: "hello " });
41+
result = await callConatService({ service: "echo3", mesg: "hello " });
4442
})();
4543
});
4644

4745
it("create the echo3 service and observe that it answer the request we made before the service was created", async () => {
48-
const s = createNatsService({
46+
const s = createConatService({
4947
service: "echo3",
5048
handler: (mesg) => mesg.repeat(3),
5149
});

src/packages/conat/service/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export type {
22
ServiceDescription,
3-
CallNatsServiceFunction,
3+
CallConatServiceFunction,
44
ServiceCall,
5-
CreateNatsServiceFunction,
6-
NatsService,
5+
CreateConatServiceFunction,
6+
ConatService,
77
} from "./service";
8-
export { callNatsService, createNatsService } from "./service";
8+
export { callConatService, createConatService } from "./service";

src/packages/conat/service/service.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
Simple to use UI to connect anything in cocalc via request/reply services.
33
4-
- callNatsService
5-
- createNatsService
4+
- callConatService
5+
- createConatService
66
77
The input is basically where the service is (account, project, public),
88
and either what message to send or how to handle messages.
@@ -46,8 +46,8 @@ export interface ServiceCall extends ServiceDescription {
4646
noRetry?: boolean;
4747
}
4848

49-
export async function callNatsService(opts: ServiceCall): Promise<any> {
50-
// console.log("callNatsService", opts);
49+
export async function callConatService(opts: ServiceCall): Promise<any> {
50+
// console.log("callConatService", opts);
5151
const env = await getEnv();
5252
const { cn } = env;
5353
const subject = serviceSubject(opts);
@@ -79,7 +79,7 @@ export async function callNatsService(opts: ServiceCall): Promise<any> {
7979
if (err.code == 503) {
8080
// it's actually just not ready, so
8181
// wait for the service to be ready, then try again
82-
await waitForNatsService({ options: opts, maxWait: timeout });
82+
await waitForConatService({ options: opts, maxWait: timeout });
8383
try {
8484
return await doRequest();
8585
} catch (err) {
@@ -98,19 +98,19 @@ export async function callNatsService(opts: ServiceCall): Promise<any> {
9898
}
9999
}
100100

101-
export type CallNatsServiceFunction = typeof callNatsService;
101+
export type CallConatServiceFunction = typeof callConatService;
102102

103103
export interface Options extends ServiceDescription {
104104
description?: string;
105105
version?: string;
106106
handler: (mesg) => Promise<any>;
107107
}
108108

109-
export function createNatsService(options: Options) {
110-
return new NatsService(options);
109+
export function createConatService(options: Options) {
110+
return new ConatService(options);
111111
}
112112

113-
export type CreateNatsServiceFunction = typeof createNatsService;
113+
export type CreateConatServiceFunction = typeof createConatService;
114114

115115
export function serviceSubject({
116116
service,
@@ -180,7 +180,7 @@ export function serviceDescription({
180180
return [description, path ? `\nPath: ${path}` : ""].join("");
181181
}
182182

183-
export class NatsService extends EventEmitter {
183+
export class ConatService extends EventEmitter {
184184
private options: Options;
185185
private subject: string;
186186
private sub?;
@@ -264,11 +264,11 @@ interface ServiceClientOpts {
264264
id?: string;
265265
}
266266

267-
export async function pingNatsService({
267+
export async function pingConatService({
268268
options,
269269
maxWait = 3000,
270270
}: ServiceClientOpts): Promise<string[]> {
271-
const pong = await callNatsService({
271+
const pong = await callConatService({
272272
...options,
273273
mesg: "ping",
274274
timeout: Math.max(3000, maxWait),
@@ -278,7 +278,7 @@ export async function pingNatsService({
278278
return [pong];
279279
}
280280

281-
export async function waitForNatsService({
281+
export async function waitForConatService({
282282
options,
283283
maxWait = 60000,
284284
}: {
@@ -290,7 +290,7 @@ export async function waitForNatsService({
290290
const start = Date.now();
291291
const getPing = async (m: number) => {
292292
try {
293-
return await pingNatsService({ options, maxWait: m });
293+
return await pingConatService({ options, maxWait: m });
294294
} catch {
295295
// ping can fail, e.g, if not connected to nats at all or the ping
296296
// service isn't up yet.

src/packages/conat/service/typed.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
callNatsService,
3-
createNatsService,
4-
pingNatsService,
5-
waitForNatsService,
2+
callConatService,
3+
createConatService,
4+
pingConatService,
5+
waitForConatService,
66
} from "./service";
77
import type { Options, ServiceCall } from "./service";
88

99
export interface Extra {
10-
ping: typeof pingNatsService;
10+
ping: typeof pingConatService;
1111
waitFor: (opts?: { maxWait?: number }) => Promise<void>;
1212
}
1313

@@ -26,14 +26,14 @@ export function createServiceClient<Api>(options: Omit<ServiceCall, "mesg">) {
2626
if (prop == "nats") {
2727
return {
2828
ping: async (opts: { id?: string; maxWait?: number } = {}) =>
29-
await pingNatsService({ options, ...opts }),
29+
await pingConatService({ options, ...opts }),
3030
waitFor: async (opts: { maxWait?: number } = {}) =>
31-
await waitForNatsService({ options, ...opts }),
31+
await waitForConatService({ options, ...opts }),
3232
};
3333
}
3434
return async (...args) => {
3535
try {
36-
return await callNatsService({
36+
return await callConatService({
3737
...options,
3838
mesg: { name: prop, args },
3939
});
@@ -51,7 +51,7 @@ export async function createServiceHandler<Api>({
5151
impl,
5252
...options
5353
}: Omit<Options, "handler"> & { impl: Api }) {
54-
return await createNatsService({
54+
return await createConatService({
5555
...options,
5656
handler: async (mesg) => await impl[mesg.name](...mesg.args),
5757
});

src/packages/frontend/client/client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import { ACCOUNT_ID_COOKIE_NAME } from "@cocalc/util/db-schema/accounts";
3434
import { appBasePath } from "@cocalc/frontend/customize/app-base-path";
3535
import type { NatsSyncTableFunction } from "@cocalc/conat/sync/synctable";
3636
import type {
37-
CallNatsServiceFunction,
38-
CreateNatsServiceFunction,
37+
CallConatServiceFunction,
38+
CreateConatServiceFunction,
3939
} from "@cocalc/conat/service";
4040
import type { NatsEnvFunction } from "@cocalc/conat/types";
4141
import { randomId } from "@cocalc/conat/names";
@@ -92,8 +92,8 @@ export interface WebappClient extends EventEmitter {
9292
is_signed_in: () => boolean;
9393
synctable_project: Function;
9494
synctable_nats: NatsSyncTableFunction;
95-
callNatsService: CallNatsServiceFunction;
96-
createNatsService: CreateNatsServiceFunction;
95+
callConatService: CallConatServiceFunction;
96+
createConatService: CreateConatServiceFunction;
9797
getNatsEnv: NatsEnvFunction;
9898
pubsub_nats: Function;
9999
prettier: Function;
@@ -176,8 +176,8 @@ class Client extends EventEmitter implements WebappClient {
176176
is_signed_in: () => boolean;
177177
synctable_project: Function;
178178
synctable_nats: NatsSyncTableFunction;
179-
callNatsService: CallNatsServiceFunction;
180-
createNatsService: CreateNatsServiceFunction;
179+
callConatService: CallConatServiceFunction;
180+
createConatService: CreateConatServiceFunction;
181181
getNatsEnv: NatsEnvFunction;
182182
pubsub_nats: Function;
183183
prettier: Function;
@@ -271,8 +271,8 @@ class Client extends EventEmitter implements WebappClient {
271271
);
272272
this.synctable_nats = this.nats_client.synctable;
273273
this.pubsub_nats = this.nats_client.pubsub;
274-
this.callNatsService = this.nats_client.callNatsService;
275-
this.createNatsService = this.nats_client.createNatsService;
274+
this.callConatService = this.nats_client.callConatService;
275+
this.createConatService = this.nats_client.createConatService;
276276
this.getNatsEnv = this.nats_client.getEnv;
277277

278278
this.query = this.query_client.query.bind(this.query_client);

src/packages/frontend/conat/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import {
3131
} from "@cocalc/conat/sync/stream";
3232
import { dstream } from "@cocalc/conat/sync/dstream";
3333
import { delay } from "awaiting";
34-
import { callNatsService, createNatsService } from "@cocalc/conat/service";
34+
import { callConatService, createConatService } from "@cocalc/conat/service";
3535
import type {
36-
CallNatsServiceFunction,
37-
CreateNatsServiceFunction,
36+
CallConatServiceFunction,
37+
CreateConatServiceFunction,
3838
} from "@cocalc/conat/service";
3939
import { listingsClient } from "@cocalc/conat/service/listings";
4040
import {
@@ -216,12 +216,12 @@ export class NatsClient extends EventEmitter {
216216
}
217217
};
218218

219-
callNatsService: CallNatsServiceFunction = async (options) => {
220-
return await callNatsService(options);
219+
callConatService: CallConatServiceFunction = async (options) => {
220+
return await callConatService(options);
221221
};
222222

223-
createNatsService: CreateNatsServiceFunction = (options) => {
224-
return createNatsService(options);
223+
createConatService: CreateConatServiceFunction = (options) => {
224+
return createConatService(options);
225225
};
226226

227227
// TODO: plan to deprecated...?

src/packages/jupyter/kernel/nats-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { createNatsJupyterService } from "@cocalc/conat/service/jupyter";
1313
import { get_existing_kernel as getKernel } from "@cocalc/jupyter/kernel";
1414
import { bufferToBase64 } from "@cocalc/util/base64";
1515

16-
export async function initNatsService({
16+
export async function initConatService({
1717
path,
1818
project_id,
1919
}: {

src/packages/jupyter/redux/project-actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import nbconvertChange from "./handle-nbconvert-change";
3030
import type { ClientFs } from "@cocalc/sync/client/types";
3131
import { kernel as createJupyterKernel } from "@cocalc/jupyter/kernel";
3232
import { removeJupyterRedux } from "@cocalc/jupyter/kernel";
33-
import { initNatsService } from "@cocalc/jupyter/kernel/nats-service";
33+
import { initConatService } from "@cocalc/jupyter/kernel/nats-service";
3434
import { type DKV, dkv } from "@cocalc/conat/sync/dkv";
3535
import { computeServerManager } from "@cocalc/conat/compute/manager";
3636
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
@@ -223,7 +223,7 @@ export class JupyterActions extends JupyterActions0 {
223223
this.natsService.close();
224224
this.natsService = null;
225225
}
226-
const service = (this.natsService = await initNatsService({
226+
const service = (this.natsService = await initConatService({
227227
project_id: this.project_id,
228228
path: this.path,
229229
}));

src/packages/project/client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ import pubsub from "@cocalc/project/conat/pubsub";
5353
import type { NatsSyncTableFunction } from "@cocalc/conat/sync/synctable";
5454
import { getEnv as getNatsEnv } from "@cocalc/project/conat/env";
5555
import {
56-
callNatsService,
57-
createNatsService,
58-
type CallNatsServiceFunction,
59-
type CreateNatsServiceFunction,
56+
callConatService,
57+
createConatService,
58+
type CallConatServiceFunction,
59+
type CreateConatServiceFunction,
6060
} from "@cocalc/conat/service";
6161
import type { NatsEnvFunction } from "@cocalc/conat/types";
6262

@@ -528,12 +528,12 @@ export class Client extends EventEmitter implements ProjectClientInterface {
528528
return await pubsub({ path, name });
529529
};
530530

531-
callNatsService: CallNatsServiceFunction = async (options) => {
532-
return await callNatsService(options);
531+
callConatService: CallConatServiceFunction = async (options) => {
532+
return await callConatService(options);
533533
};
534534

535-
createNatsService: CreateNatsServiceFunction = (options) => {
536-
return createNatsService({
535+
createConatService: CreateConatServiceFunction = (options) => {
536+
return createConatService({
537537
...options,
538538
project_id: this.project_id,
539539
});

src/packages/project/conat/listings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ import { compute_server_id, project_id } from "@cocalc/project/data";
4343
import { init as initClient } from "@cocalc/project/client";
4444
import { delay } from "awaiting";
4545
import { type DKV } from "./sync";
46-
import { type NatsService } from "@cocalc/conat/service";
46+
import { type ConatService } from "@cocalc/conat/service";
4747
import { MultipathWatcher } from "@cocalc/backend/path-watcher";
4848
import getLogger from "@cocalc/backend/logger";
4949

5050
const logger = getLogger("project:nats:listings");
5151

52-
let service: NatsService | null;
52+
let service: ConatService | null;
5353
export async function init() {
5454
logger.debug("init: initializing");
5555
initClient();

0 commit comments

Comments
 (0)