@nmtjs/client
Advanced tools
Comparing version 0.3.10 to 0.3.11
@@ -6,2 +6,3 @@ import { NeverType } from '@nmtjs/type'; | ||
contracts; | ||
$types; | ||
#callers; | ||
@@ -20,3 +21,3 @@ constructor(contracts, options){ | ||
const compiled = service.compiled.get(output); | ||
const result = compiled.decode(data); | ||
const result = compiled.decodeSafe(data); | ||
if (result.success) { | ||
@@ -36,3 +37,3 @@ return result.value; | ||
const compiled = service.compiled.get(input); | ||
const result = compiled.encode(data); | ||
const result = compiled.encodeSafe(data); | ||
if (result.success) { | ||
@@ -39,0 +40,0 @@ return result.value; |
import { Client } from "./client.js"; | ||
export class StaticClient extends Client { | ||
$types; | ||
#callers; | ||
@@ -4,0 +5,0 @@ constructor(services, options){ |
@@ -19,51 +19,54 @@ import type { | ||
type ClientServicesResolved<Services extends ClientServices> = { | ||
[K in keyof Services]: { | ||
[P in keyof Services[K]['contract']['procedures']]: { | ||
contract: Services[K]['contract']['procedures'][P] | ||
input: InputType< | ||
t.infer.decoded<Services[K]['contract']['procedures'][P]['input']> | ||
> | ||
output: OutputType< | ||
t.infer.decoded<Services[K]['contract']['procedures'][P]['output']> | ||
> | ||
events: Services[K]['contract']['procedures'][P] extends TSubscriptionContract | ||
? { | ||
[KE in keyof Services[K]['contract']['procedures'][P]['events']]: { | ||
payload: OutputType< | ||
t.infer.decoded< | ||
Services[K]['contract']['procedures'][P]['events'][KE]['payload'] | ||
> | ||
> | ||
} | ||
} | ||
: {} | ||
} | ||
} | ||
} | ||
type ClientServices = Record<string, CompiledContract> | ||
type ClientCallers<Services extends ClientServices> = { | ||
type ClientCallers<Services extends ClientServicesResolved<ClientServices>> = { | ||
[K in keyof Services]: { | ||
[P in keyof Services[K]['contract']['procedures']]: ( | ||
...args: Services[K]['contract']['procedures'][P]['input'] extends NeverType | ||
[P in keyof Services[K]]: ( | ||
...args: Services[K][P]['input'] extends NeverType | ||
? [options?: ClientCallOptions] | ||
: t.infer.staticType< | ||
Services[K]['contract']['procedures'][P]['input'] | ||
Services[K][P]['contract']['input'] | ||
>['isOptional'] extends true | ||
? [ | ||
data?: InputType< | ||
t.infer.decoded< | ||
Services[K]['contract']['procedures'][P]['input'] | ||
> | ||
>, | ||
options?: ClientCallOptions, | ||
] | ||
: [ | ||
data: InputType< | ||
t.infer.decoded< | ||
Services[K]['contract']['procedures'][P]['input'] | ||
> | ||
>, | ||
options?: ClientCallOptions, | ||
] | ||
? [data?: Services[K][P]['input'], options?: ClientCallOptions] | ||
: [data: Services[K][P]['input'], options?: ClientCallOptions] | ||
) => Promise< | ||
Services[K]['contract']['procedures'][P] extends TSubscriptionContract | ||
Services[K][P] extends TSubscriptionContract | ||
? { | ||
payload: Services[K]['contract']['procedures'][P]['output'] extends NeverType | ||
payload: Services[K][P]['output'] extends never | ||
? undefined | ||
: t.infer.decoded< | ||
Services[K]['contract']['procedures'][P]['output'] | ||
> | ||
: Services[K][P]['output'] | ||
subscription: Subscription<{ | ||
[KE in keyof Services[K]['contract']['procedures'][P]['events']]: [ | ||
t.infer.decoded< | ||
Services[K]['contract']['procedures'][P]['events'][KE]['payload'] | ||
>, | ||
[KE in keyof Services[K][P]['events']]: [ | ||
t.infer.decoded<Services[K][P]['events'][KE]['payload']>, | ||
] | ||
}> | ||
} | ||
: Services[K]['contract']['procedures'][P]['output'] extends NeverType | ||
: Services[K][P]['output'] extends never | ||
? void | ||
: OutputType< | ||
t.infer.decoded< | ||
Services[K]['contract']['procedures'][P]['output'] | ||
> | ||
> | ||
: Services[K][P]['output'] | ||
> | ||
@@ -74,3 +77,4 @@ } | ||
export class RuntimeClient<Services extends ClientServices> extends Client { | ||
#callers: ClientCallers<Services> | ||
$types!: ClientServicesResolved<Services> | ||
#callers: ClientCallers<this['$types']> | ||
@@ -98,3 +102,3 @@ constructor( | ||
const compiled = service.compiled.get(output)! | ||
const result = compiled.decode(data) | ||
const result = compiled.decodeSafe(data) | ||
if (result.success) { | ||
@@ -118,3 +122,3 @@ return result.value | ||
const compiled = service.compiled.get(input)! | ||
const result = compiled.encode(data) | ||
const result = compiled.encodeSafe(data) | ||
if (result.success) { | ||
@@ -121,0 +125,0 @@ return result.value |
@@ -9,39 +9,50 @@ import type { TServiceContract, TSubscriptionContract } from '@nmtjs/contract' | ||
type ClientCallers<Services extends ClientServices> = { | ||
type ClientServicesResolved<Services extends ClientServices> = { | ||
[K in keyof Services]: { | ||
[P in keyof Services[K]['procedures']]: ( | ||
...args: Services[K]['procedures'][P]['input'] extends NeverType | ||
[P in keyof Services[K]['procedures']]: { | ||
contract: Services[K]['procedures'][P] | ||
input: InputType<t.infer.encoded<Services[K]['procedures'][P]['input']>> | ||
output: OutputType< | ||
t.infer.encoded<Services[K]['procedures'][P]['output']> | ||
> | ||
events: Services[K]['procedures'][P] extends TSubscriptionContract | ||
? { | ||
[KE in keyof Services[K]['procedures'][P]['events']]: { | ||
payload: OutputType< | ||
t.infer.encoded< | ||
Services[K]['procedures'][P]['events'][KE]['payload'] | ||
> | ||
> | ||
} | ||
} | ||
: {} | ||
} | ||
} | ||
} | ||
type ClientCallers< | ||
Services extends ClientServicesResolved<Record<string, TServiceContract>>, | ||
> = { | ||
[K in keyof Services]: { | ||
[P in keyof Services[K]]: ( | ||
...args: Services[K][P]['input'] extends never | ||
? [options?: ClientCallOptions] | ||
: t.infer.staticType< | ||
Services[K]['procedures'][P]['input'] | ||
>['isOptional'] extends true | ||
? [ | ||
data?: InputType< | ||
t.infer.encoded<Services[K]['procedures'][P]['input']> | ||
>, | ||
options?: ClientCallOptions, | ||
] | ||
: [ | ||
data: InputType< | ||
t.infer.encoded<Services[K]['procedures'][P]['input']> | ||
>, | ||
options?: ClientCallOptions, | ||
] | ||
: Services[K][P]['input'] extends undefined | ||
? [data?: Services[K][P]['input'], options?: ClientCallOptions] | ||
: [data: Services[K][P]['input'], options?: ClientCallOptions] | ||
) => Promise< | ||
Services[K]['procedures'][P] extends TSubscriptionContract | ||
Services[K][P]['contract'] extends TSubscriptionContract | ||
? { | ||
payload: Services[K]['procedures'][P]['output'] extends NeverType | ||
payload: Services[K][P]['output'] extends never | ||
? undefined | ||
: t.infer.encoded<Services[K]['procedures'][P]['output']> | ||
: Services[K][P]['output'] | ||
subscription: Subscription<{ | ||
[KE in keyof Services[K]['procedures'][P]['events']]: [ | ||
t.infer.encoded< | ||
Services[K]['procedures'][P]['events'][KE]['payload'] | ||
>, | ||
[KE in keyof Services[K][P]['events']]: [ | ||
Services[K][P]['events'][KE], | ||
] | ||
}> | ||
} | ||
: Services[K]['procedures'][P]['output'] extends NeverType | ||
: Services[K][P]['output'] extends never | ||
? void | ||
: OutputType<t.infer.encoded<Services[K]['procedures'][P]['output']>> | ||
: Services[K][P]['output'] | ||
> | ||
@@ -52,3 +63,4 @@ } | ||
export class StaticClient<Services extends ClientServices> extends Client { | ||
#callers: ClientCallers<Services> | ||
$types!: ClientServicesResolved<Services> | ||
#callers: ClientCallers<this['$types']> | ||
@@ -55,0 +67,0 @@ constructor( |
import { type BaseClientFormat, ErrorCode } from '@nmtjs/common' | ||
import type { TServiceContract } from '@nmtjs/contract' | ||
import { ClientError } from './common.ts' | ||
@@ -13,2 +14,4 @@ import type { ClientTransport } from './transport.ts' | ||
export type ClientServices = Record<string, TServiceContract> | ||
export abstract class Client extends utils.EventEmitter { | ||
@@ -15,0 +18,0 @@ protected transport!: ClientTransport |
@@ -22,10 +22,10 @@ { | ||
"peerDependencies": { | ||
"@nmtjs/common": "0.3.10", | ||
"@nmtjs/contract": "0.3.10", | ||
"@nmtjs/type": "0.3.10" | ||
"@nmtjs/type": "0.3.11", | ||
"@nmtjs/contract": "0.3.11", | ||
"@nmtjs/common": "0.3.11" | ||
}, | ||
"devDependencies": { | ||
"@nmtjs/contract": "0.3.10", | ||
"@nmtjs/type": "0.3.10", | ||
"@nmtjs/common": "0.3.10" | ||
"@nmtjs/contract": "0.3.11", | ||
"@nmtjs/common": "0.3.11", | ||
"@nmtjs/type": "0.3.11" | ||
}, | ||
@@ -40,3 +40,3 @@ "files": [ | ||
], | ||
"version": "0.3.10", | ||
"version": "0.3.11", | ||
"scripts": { | ||
@@ -43,0 +43,0 @@ "build": "neemata-build -p neutral ./index.ts './lib/**/*.ts'", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60929
887