@enkaku/client 0.17.1 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.d.ts +5 -5
- package/lib/client.js +20 -16
- package/lib/error.d.ts +0 -1
- package/lib/error.js +0 -1
- package/lib/events.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/safe-write.js +1 -1
- package/package.json +13 -12
package/lib/client.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Disposer } from '@enkaku/async';
|
|
2
|
-
import { type Logger } from '@enkaku/log';
|
|
3
|
-
import { type Tracer } from '@enkaku/otel';
|
|
4
1
|
import type { AnyProcedureDefinition, AnyRequestProcedureDefinition, ChannelProcedureDefinition, ClientTransportOf, DataOf, EventProcedureDefinition, ProtocolDefinition, RequestProcedureDefinition, RequestType, ReturnOf, StreamProcedureDefinition } from '@enkaku/protocol';
|
|
5
|
-
import { type
|
|
6
|
-
import {
|
|
2
|
+
import { type Identity } from '@kokuin/token';
|
|
3
|
+
import { Disposer } from '@sozai/async';
|
|
4
|
+
import { type Logger } from '@sozai/log';
|
|
5
|
+
import { type Tracer } from '@sozai/otel';
|
|
6
|
+
import { type Runtime } from '@sozai/runtime';
|
|
7
7
|
import type { ClientEmitter } from './events.js';
|
|
8
8
|
type FilterNever<T> = {
|
|
9
9
|
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
package/lib/client.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { createTracer, EnkakuAttributeKeys, EnkakuSpanNames } from '@enkaku/otel';
|
|
2
|
+
import { createUnsignedToken, isSigningIdentity } from '@kokuin/token';
|
|
3
|
+
import { Disposer, defer } from '@sozai/async';
|
|
4
|
+
import { EventEmitter } from '@sozai/event';
|
|
5
|
+
import { getLogger } from '@sozai/log';
|
|
6
|
+
import { AttributeKeys, injectTraceContext as otelInjectTraceContext, SpanStatusCode, setSpanOnContext, withActiveContext, withSpan } from '@sozai/otel';
|
|
7
|
+
import { createRuntime } from '@sozai/runtime';
|
|
8
|
+
import { createPipe, writeTo } from '@sozai/stream';
|
|
8
9
|
import { RequestError } from './error.js';
|
|
9
10
|
import { safeWrite } from './safe-write.js';
|
|
10
11
|
const defaultTracer = createTracer('client');
|
|
@@ -109,7 +110,10 @@ export class Client extends Disposer {
|
|
|
109
110
|
});
|
|
110
111
|
this.#handleTransportDisposed = params.handleTransportDisposed;
|
|
111
112
|
this.#handleTransportError = params.handleTransportError;
|
|
112
|
-
this.#logger = params.logger ??
|
|
113
|
+
this.#logger = params.logger ?? getLogger([
|
|
114
|
+
'enkaku',
|
|
115
|
+
'client'
|
|
116
|
+
], {
|
|
113
117
|
clientID: this.#runtime.getRandomID()
|
|
114
118
|
});
|
|
115
119
|
this.#tracer = params.tracer ?? defaultTracer;
|
|
@@ -162,8 +166,8 @@ export class Client extends Disposer {
|
|
|
162
166
|
delete this.#spans[meta.rid];
|
|
163
167
|
}, (error)=>{
|
|
164
168
|
if (error instanceof RequestError) {
|
|
165
|
-
span.setAttribute(
|
|
166
|
-
span.setAttribute(
|
|
169
|
+
span.setAttribute(EnkakuAttributeKeys.ERROR_CODE, error.code);
|
|
170
|
+
span.setAttribute(EnkakuAttributeKeys.ERROR_MESSAGE, error.message);
|
|
167
171
|
}
|
|
168
172
|
span.setStatus({
|
|
169
173
|
code: SpanStatusCode.ERROR,
|
|
@@ -248,7 +252,7 @@ export class Client extends Disposer {
|
|
|
248
252
|
const receiveSpan = this.#spans[msg.payload.rid];
|
|
249
253
|
if (receiveSpan != null) {
|
|
250
254
|
receiveSpan.addEvent('stream.message.received', {
|
|
251
|
-
[
|
|
255
|
+
[EnkakuAttributeKeys.MESSAGE_DIRECTION]: 'receive'
|
|
252
256
|
});
|
|
253
257
|
}
|
|
254
258
|
void controller.receive?.write(msg.payload.val).catch(()=>{});
|
|
@@ -344,7 +348,7 @@ export class Client extends Disposer {
|
|
|
344
348
|
}
|
|
345
349
|
async sendEvent(procedure, ...args) {
|
|
346
350
|
const config = args[0] ?? {};
|
|
347
|
-
return withSpan(this.#tracer,
|
|
351
|
+
return withSpan(this.#tracer, EnkakuSpanNames.CLIENT_CALL, {
|
|
348
352
|
attributes: {
|
|
349
353
|
[AttributeKeys.RPC_SYSTEM]: 'enkaku',
|
|
350
354
|
[AttributeKeys.RPC_PROCEDURE]: procedure,
|
|
@@ -376,7 +380,7 @@ export class Client extends Disposer {
|
|
|
376
380
|
request(procedure, ...args) {
|
|
377
381
|
const config = args[0] ?? {};
|
|
378
382
|
const rid = config.id ?? this.#runtime.getRandomID();
|
|
379
|
-
const span = this.#tracer.startSpan(
|
|
383
|
+
const span = this.#tracer.startSpan(EnkakuSpanNames.CLIENT_CALL, {
|
|
380
384
|
attributes: {
|
|
381
385
|
[AttributeKeys.RPC_SYSTEM]: 'enkaku',
|
|
382
386
|
[AttributeKeys.RPC_PROCEDURE]: procedure,
|
|
@@ -453,7 +457,7 @@ export class Client extends Disposer {
|
|
|
453
457
|
createStream(procedure, ...args) {
|
|
454
458
|
const config = args[0] ?? {};
|
|
455
459
|
const rid = config.id ?? this.#runtime.getRandomID();
|
|
456
|
-
const span = this.#tracer.startSpan(
|
|
460
|
+
const span = this.#tracer.startSpan(EnkakuSpanNames.CLIENT_CALL, {
|
|
457
461
|
attributes: {
|
|
458
462
|
[AttributeKeys.RPC_SYSTEM]: 'enkaku',
|
|
459
463
|
[AttributeKeys.RPC_PROCEDURE]: procedure,
|
|
@@ -537,7 +541,7 @@ export class Client extends Disposer {
|
|
|
537
541
|
createChannel(procedure, ...args) {
|
|
538
542
|
const config = args[0] ?? {};
|
|
539
543
|
const rid = config.id ?? this.#runtime.getRandomID();
|
|
540
|
-
const span = this.#tracer.startSpan(
|
|
544
|
+
const span = this.#tracer.startSpan(EnkakuSpanNames.CLIENT_CALL, {
|
|
541
545
|
attributes: {
|
|
542
546
|
[AttributeKeys.RPC_SYSTEM]: 'enkaku',
|
|
543
547
|
[AttributeKeys.RPC_PROCEDURE]: procedure,
|
|
@@ -619,7 +623,7 @@ export class Client extends Disposer {
|
|
|
619
623
|
const channelSpan = this.#spans[rid];
|
|
620
624
|
if (channelSpan != null) {
|
|
621
625
|
channelSpan.addEvent('channel.message.sent', {
|
|
622
|
-
[
|
|
626
|
+
[EnkakuAttributeKeys.MESSAGE_DIRECTION]: 'send'
|
|
623
627
|
});
|
|
624
628
|
}
|
|
625
629
|
this.#logger.trace('send value to channel {procedure} with ID {rid}: {value}', {
|
package/lib/error.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ErrorReplyPayload } from '@enkaku/protocol';
|
|
2
|
-
export { type ErrorCode, ErrorCodes } from '@enkaku/protocol';
|
|
3
2
|
export type ErrorObjectType<Code extends string = string, Data extends Record<string, unknown> = Record<string, unknown>> = {
|
|
4
3
|
code: Code;
|
|
5
4
|
message: string;
|
package/lib/error.js
CHANGED
package/lib/events.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export type { ChannelCall, ChannelDefinitionsType, ClientDefinitionsType, ClientParams, EventDefinitionsType, RequestCall, RequestDefinitionsType, StreamCall, StreamDefinitionsType, } from './client.js';
|
|
13
13
|
export { Client } from './client.js';
|
|
14
|
-
export { type
|
|
14
|
+
export { type ErrorObjectType, RequestError, type RequestErrorParams, } from './error.js';
|
|
15
15
|
export type { ClientEmitter, ClientEvents, ClientRequestStatus } from './events.js';
|
package/lib/index.js
CHANGED
package/lib/safe-write.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enkaku/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://enkaku.dev",
|
|
6
6
|
"description": "Enkaku RPC client",
|
|
@@ -26,22 +26,23 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
29
|
+
"@kokuin/token": "^0.1.1",
|
|
30
|
+
"@sozai/async": "^0.1.0",
|
|
31
|
+
"@sozai/event": "^0.1.0",
|
|
32
|
+
"@sozai/execution": "^0.1.0",
|
|
33
|
+
"@sozai/log": "^0.1.0",
|
|
34
|
+
"@sozai/otel": "^0.2.0",
|
|
35
|
+
"@sozai/runtime": "^0.1.0",
|
|
36
|
+
"@sozai/stream": "^0.1.0",
|
|
37
|
+
"@enkaku/otel": "^0.18.1"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@enkaku/
|
|
40
|
-
"@enkaku/
|
|
40
|
+
"@enkaku/protocol": "^0.18.1",
|
|
41
|
+
"@enkaku/transport": "^0.18.1"
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build:clean": "del lib",
|
|
44
|
-
"build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
|
|
45
|
+
"build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
45
46
|
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
46
47
|
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
47
48
|
"test:types": "tsc --noEmit --skipLibCheck -p tsconfig.test.json",
|