Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nmtjs/client

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nmtjs/client - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

38

dist/lib/client-runtime.js

@@ -1,3 +0,3 @@

import { compile } from '@nmtjs/contract/compiler';
import { ContractGuard } from '@nmtjs/contract/guards';
import { NeverType } from '@nmtjs/type';
import { compile } from '@nmtjs/type/compiler';
import { Client } from "./client.js";

@@ -9,12 +9,13 @@ export class RuntimeClient extends Client {

const callers = {};
for (const [serviceKey, serviceContract] of Object.entries(services)){
if (!serviceContract.contract.transports[this.transport.type]) throw new Error(`Transport [${this.transport.type}] not supported for service [${serviceContract.contract.name}]`);
for (const [serviceKey, service] of Object.entries(services)){
service.contract.procedures;
if (!service.contract.transports[this.transport.type]) throw new Error(`Transport [${this.transport.type}] not supported for service [${service.contract.name}]`);
callers[serviceKey] = {};
for(const procedureName in serviceContract.contract.procedures){
const { input, output } = serviceContract.contract.procedures[procedureName];
callers[serviceKey][procedureName] = this.createCaller(serviceContract.contract.name, procedureName, {
timeout: serviceContract.contract.timeout,
for(const procedureName in service.contract.procedures){
const { input, output } = service.contract.procedures[procedureName];
callers[serviceKey][procedureName] = this.createCaller(service.contract.name, procedureName, {
timeout: service.contract.timeout,
transformInput: (data)=>{
if (ContractGuard.IsNever(data)) return undefined;
const compiled = serviceContract.compiled.get(input);
if (input instanceof NeverType) return undefined;
const compiled = service.compiled.get(input);
const result = compiled.encode(data);

@@ -31,4 +32,4 @@ if (result.success) {

transformOutput: (data)=>{
if (ContractGuard.IsNever(data)) return undefined;
const compiled = serviceContract.compiled.get(output);
if (output instanceof NeverType) return undefined;
const compiled = service.compiled.get(output);
const result = compiled.decode(data);

@@ -55,7 +56,8 @@ if (result.success) {

const compiled = new Map();
for (const procedureContract of Object.values(contract.procedures)){
const { input, output, events } = procedureContract;
if (ContractGuard.IsSubscription(procedureContract)) {
for (const procedure of Object.values(contract.procedures)){
const { input, output } = procedure;
if (procedure.type === 'neemata:subscription') {
const { events } = procedure;
for (const event of Object.values(events)){
compiled.set(event, compile(event));
compiled.set(event.payload, compile(event.payload));
}

@@ -66,4 +68,4 @@ }

}
for (const eventContract of Object.values(contract.events)){
compiled.set(eventContract, compile(eventContract));
for (const event of Object.values(contract.events)){
compiled.set(event.payload, compile(event.payload));
}

@@ -70,0 +72,0 @@ return {

import type {
Decoded,
TEventContract,
TSchema,
TProcedureContract,
TServiceContract,
TSubscriptionContract,
} from '@nmtjs/contract'
import { type Compiled, compile } from '@nmtjs/contract/compiler'
import { ContractGuard } from '@nmtjs/contract/guards'
import { type BaseType, NeverType, type t } from '@nmtjs/type'
import { type Compiled, compile } from '@nmtjs/type/compiler'
import { Client, type ClientOptions } from './client.ts'

@@ -15,3 +15,3 @@ import type { Subscription } from './subscription.ts'

type CompiledContract<T extends TServiceContract = TServiceContract> = {
compiled: Map<TSchema, Compiled>
compiled: Map<BaseType, Compiled>
contract: T

@@ -25,9 +25,7 @@ }

[P in keyof Services[K]['contract']['procedures']]: (
...args: Decoded<
Services[K]['contract']['procedures'][P]['input']
> extends never
...args: Services[K]['contract']['procedures'][P]['input'] extends NeverType
? [options?: ClientCallOptions]
: [
data: InputType<
Decoded<Services[K]['contract']['procedures'][P]['input']>
t.infer.decoded<Services[K]['contract']['procedures'][P]['input']>
>,

@@ -39,15 +37,21 @@ options?: ClientCallOptions,

? {
payload: Decoded<
Services[K]['contract']['procedures'][P]['output']
> extends never
payload: Services[K]['contract']['procedures'][P]['output'] extends NeverType
? undefined
: Decoded<Services[K]['contract']['procedures'][P]['output']>
subscription: Subscription<Services[K]['contract']['procedures'][P]>
: t.infer.decoded<
Services[K]['contract']['procedures'][P]['output']
>
subscription: Subscription<{
[KE in keyof Services[K]['contract']['procedures'][P]['events']]: [
t.infer.decoded<
Services[K]['contract']['procedures'][P]['events'][KE]['payload']
>,
]
}>
}
: Decoded<
Services[K]['contract']['procedures'][P]['static']
> extends never
: Services[K]['contract']['procedures'][P]['output'] extends NeverType
? void
: OutputType<
Decoded<Services[K]['contract']['procedures'][P]['output']>
t.infer.decoded<
Services[K]['contract']['procedures'][P]['output']
>
>

@@ -68,6 +72,7 @@ >

const callers = {} as any
for (const [serviceKey, serviceContract] of Object.entries(services)) {
if (!serviceContract.contract.transports[this.transport.type])
for (const [serviceKey, service] of Object.entries(services)) {
service.contract.procedures
if (!service.contract.transports[this.transport.type])
throw new Error(
`Transport [${this.transport.type}] not supported for service [${serviceContract.contract.name}]`,
`Transport [${this.transport.type}] not supported for service [${service.contract.name}]`,
)

@@ -77,14 +82,13 @@

for (const procedureName in serviceContract.contract.procedures) {
const { input, output } =
serviceContract.contract.procedures[procedureName]
for (const procedureName in service.contract.procedures) {
const { input, output } = service.contract.procedures[procedureName]
callers[serviceKey][procedureName] = this.createCaller(
serviceContract.contract.name,
service.contract.name,
procedureName,
{
timeout: serviceContract.contract.timeout,
timeout: service.contract.timeout,
transformInput: (data: any) => {
if (ContractGuard.IsNever(data)) return undefined
const compiled = serviceContract.compiled.get(input)!
if (input instanceof NeverType) return undefined
const compiled = service.compiled.get(input)!
const result = compiled.encode(data)

@@ -101,4 +105,4 @@ if (result.success) {

transformOutput: (data: any) => {
if (ContractGuard.IsNever(data)) return undefined
const compiled = serviceContract.compiled.get(output)!
if (output instanceof NeverType) return undefined
const compiled = service.compiled.get(output)!
const result = compiled.decode(data)

@@ -129,8 +133,10 @@ if (result.success) {

): CompiledContract<T> => {
const compiled = new Map<TSchema, Compiled>()
for (const procedureContract of Object.values(contract.procedures)) {
const { input, output, events } = procedureContract
if (ContractGuard.IsSubscription(procedureContract)) {
const compiled = new Map<BaseType, Compiled>()
for (const procedure of Object.values(contract.procedures)) {
const { input, output } = procedure
if (procedure.type === 'neemata:subscription') {
const { events } = procedure
for (const event of Object.values(events) as TEventContract[]) {
compiled.set(event, compile(event))
compiled.set(event.payload, compile(event.payload))
}

@@ -141,4 +147,4 @@ }

}
for (const eventContract of Object.values(contract.events)) {
compiled.set(eventContract, compile(eventContract))
for (const event of Object.values(contract.events)) {
compiled.set(event.payload, compile(event.payload))
}

@@ -145,0 +151,0 @@

@@ -1,6 +0,3 @@

import type {
Encoded,
TServiceContract,
TSubscriptionContract,
} from '@nmtjs/contract'
import type { TServiceContract, TSubscriptionContract } from '@nmtjs/contract'
import type { NeverType, t } from '@nmtjs/type'
import { Client, type ClientOptions } from './client.ts'

@@ -15,6 +12,8 @@ import type { Subscription } from './subscription.ts'

[P in keyof Services[K]['procedures']]: (
...args: Encoded<Services[K]['procedures'][P]['input']> extends never
...args: Services[K]['procedures'][P]['input'] extends NeverType
? [options?: ClientCallOptions]
: [
data: InputType<Encoded<Services[K]['procedures'][P]['input']>>,
data: InputType<
t.infer.encoded<Services[K]['procedures'][P]['input']>
>,
options?: ClientCallOptions,

@@ -25,12 +24,16 @@ ]

? {
payload: Encoded<
Services[K]['procedures'][P]['output']
> extends never
payload: Services[K]['procedures'][P]['output'] extends NeverType
? undefined
: Encoded<Services[K]['procedures'][P]['output']>
subscription: Subscription<Services[K]['procedures'][P]>
: t.infer.encoded<Services[K]['procedures'][P]['output']>
subscription: Subscription<{
[KE in keyof Services[K]['procedures'][P]['events']]: [
t.infer.encoded<
Services[K]['procedures'][P]['events'][KE]['payload']
>,
]
}>
}
: Encoded<Services[K]['procedures'][P]['static']> extends never
: Services[K]['procedures'][P]['output'] extends NeverType
? void
: OutputType<Encoded<Services[K]['procedures'][P]['output']>>
: OutputType<t.infer.encoded<Services[K]['procedures'][P]['output']>>
>

@@ -37,0 +40,0 @@ }

@@ -1,9 +0,6 @@

import type { TSubscriptionContract } from '@nmtjs/contract'
import { EventEmitter } from './utils.ts'
import { EventEmitter, type EventMap } from './utils.ts'
export class Subscription<
Contact extends TSubscriptionContract = TSubscriptionContract,
> extends EventEmitter<{
[K in keyof Contact['events']]: [Contact['events'][K]['static']['payload']]
}> {
Events extends EventMap = EventMap,
> extends EventEmitter<Events> {
constructor(

@@ -10,0 +7,0 @@ readonly key: string,

@@ -22,8 +22,10 @@ {

"peerDependencies": {
"@nmtjs/contract": "0.0.4",
"@nmtjs/common": "0.0.4"
"@nmtjs/type": "0.1.0",
"@nmtjs/common": "0.1.0",
"@nmtjs/contract": "0.1.0"
},
"devDependencies": {
"@nmtjs/contract": "0.0.4",
"@nmtjs/common": "0.0.4"
"@nmtjs/type": "0.1.0",
"@nmtjs/contract": "0.1.0",
"@nmtjs/common": "0.1.0"
},

@@ -38,3 +40,3 @@ "files": [

],
"version": "0.0.4",
"version": "0.1.0",
"scripts": {

@@ -41,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc