@nmtjs/contract 0.13.1 → 0.14.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/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import t from '@nmtjs/type';
2
1
  export * from './schemas/api.ts';
3
2
  export * from './schemas/event.ts';
4
- export * from './schemas/namespace.ts';
5
3
  export * from './schemas/procedure.ts';
4
+ export * from './schemas/router.ts';
6
5
  export * from './schemas/subscription.ts';
7
6
  export declare namespace contract {
8
7
  const procedure: <const Options extends {
@@ -12,36 +11,35 @@ export declare namespace contract {
12
11
  timeout?: number;
13
12
  schemaOptions?: import("./utils.ts").ContractSchemaOptions;
14
13
  name?: string;
15
- }>(options: Options) => import("./schemas/procedure.ts").TProcedureContract<Options["input"] extends import("@nmtjs/type").BaseType<import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").TypeProps> ? Options["input"] : t.NeverType, Options["output"] extends import("@nmtjs/type").BaseType<import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").TypeProps> ? Options["output"] : t.NeverType, Options["stream"] extends import("@nmtjs/type").BaseType<import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").TypeProps> ? Options["stream"] : undefined, Options["name"] extends string ? Options["name"] : undefined, undefined>;
16
- const event: <Payload extends import("@nmtjs/type").BaseType, Name extends string | undefined = undefined>(options?: {
14
+ }>(options: Options) => import("./schemas/procedure.ts").TProcedureContract<Options["input"] extends import("@nmtjs/type").BaseType ? Options["input"] : import("@nmtjs/type/never").NeverType, Options["output"] extends import("@nmtjs/type").BaseType ? Options["output"] : import("@nmtjs/type/never").NeverType, Options["stream"] extends import("@nmtjs/type").BaseType ? Options["stream"] : undefined, Options["name"] extends string ? Options["name"] : undefined>;
15
+ const event: <Payload extends import("@nmtjs/type").BaseType, Name extends string | undefined = undefined, Options extends import("./schemas/subscription.ts").SubcriptionOptions | undefined = undefined>(options?: {
17
16
  payload?: Payload;
18
17
  schemaOptions?: import("./utils.ts").ContractSchemaOptions;
19
18
  name?: Name;
20
- }) => import("./schemas/event.ts").TEventContract<Payload, Name, undefined, undefined>;
19
+ }) => import("./schemas/event.ts").TEventContract<Payload, Name, Options>;
21
20
  const subscription: (<const Options extends {
22
21
  events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
23
22
  name?: string;
24
23
  schemaOptions?: import("./utils.ts").ContractSchemaOptions;
25
- }, SubOpt extends import("./schemas/subscription.ts").SubcriptionOptions = null>(options: Options) => import("./schemas/subscription.ts").TSubscriptionContract<SubOpt, Options["events"], Options["name"] extends string ? Options["name"] : undefined>) & {
24
+ }, SubOpt extends import("./schemas/subscription.ts").SubcriptionOptions = null>(options: Options) => import("./schemas/subscription.ts").TSubscriptionContract<SubOpt, Options["events"], Options["name"]>) & {
26
25
  withOptions: <Options extends import("./schemas/subscription.ts").SubcriptionOptions>() => <T extends {
27
26
  events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
28
27
  name?: string;
29
28
  schemaOptions?: import("./utils.ts").ContractSchemaOptions;
30
- }>(options: T) => import("./schemas/subscription.ts").TSubscriptionContract<Options, T["events"], T["name"] extends string ? T["name"] : undefined>;
29
+ }>(options: T) => import("./schemas/subscription.ts").TSubscriptionContract<Options, T["events"], T["name"]>;
31
30
  };
32
- const namespace: <const Options extends {
33
- procedures: Record<string, import("./schemas/procedure.ts").TAnyProcedureContract>;
34
- events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
31
+ const router: <const Options extends {
32
+ routes: Record<string, import("./schemas/router.ts").TRouteContract>;
35
33
  name?: string;
36
34
  timeout?: number;
37
35
  schemaOptions?: import("./utils.ts").ContractSchemaOptions;
38
- }>(options: Options) => import("./schemas/namespace.ts").TNamespaceContract<Options["procedures"], Options["events"], Options["name"] extends string ? Options["name"] : undefined>;
36
+ }>(options: Options) => import("./schemas/router.ts").TRouterContract<Options["routes"], Options["name"] extends string ? Options["name"] : undefined>;
39
37
  const api: <const Options extends {
40
- namespaces: Record<string, import("./schemas/namespace.ts").TAnyNamespaceContract>;
38
+ router: import("./schemas/router.ts").TAnyRouterContract;
41
39
  timeout?: number;
42
40
  schemaOptions?: import("./utils.ts").ContractSchemaOptions;
43
- }>(options: Options) => import("./schemas/api.ts").TAPIContract<Options["namespaces"]>;
44
- const blob: (options?: import("./types/blob.ts").BlobOptions) => t.CustomType<import("@nmtjs/protocol").ProtocolBlobInterface>;
41
+ }>(options: Options) => import("./schemas/api.ts").TAPIContract<Options["router"]>;
42
+ const blob: (options?: import("./types/blob.ts").BlobOptions) => import("@nmtjs/type/custom").CustomType<import("@nmtjs/protocol").ProtocolBlobInterface>;
45
43
  }
46
44
  export { contract as c };
47
45
  export default contract;
package/dist/index.js CHANGED
@@ -1,22 +1,20 @@
1
- // biome-ignore lint/correctness/noUnusedImports: TSC wants it
2
- import t from '@nmtjs/type';
3
1
  import { APIContract } from "./schemas/api.js";
4
2
  import { EventContract } from "./schemas/event.js";
5
- import { NamespaceContract } from "./schemas/namespace.js";
6
3
  import { ProcedureContract } from "./schemas/procedure.js";
4
+ import { RouterContract } from "./schemas/router.js";
7
5
  import { SubscriptionContract } from "./schemas/subscription.js";
8
6
  import { BlobType } from "./types/blob.js";
9
7
  export * from "./schemas/api.js";
10
8
  export * from "./schemas/event.js";
11
- export * from "./schemas/namespace.js";
12
9
  export * from "./schemas/procedure.js";
10
+ export * from "./schemas/router.js";
13
11
  export * from "./schemas/subscription.js";
14
12
  export var contract;
15
13
  (function (contract) {
16
14
  contract.procedure = ProcedureContract;
17
15
  contract.event = EventContract;
18
16
  contract.subscription = SubscriptionContract;
19
- contract.namespace = NamespaceContract;
17
+ contract.router = RouterContract;
20
18
  contract.api = APIContract;
21
19
  contract.blob = BlobType;
22
20
  })(contract || (contract = {}));
@@ -1,19 +1,17 @@
1
+ import type { ContractSchemaOptions } from '../utils.ts';
2
+ import type { TAnyRouterContract } from './router.ts';
1
3
  import { Kind } from '../constants.ts';
2
- import { type ContractSchemaOptions } from '../utils.ts';
3
- import type { TAnyNamespaceContract, TNamespaceContract } from './namespace.ts';
4
4
  export declare const APIKind: unique symbol;
5
- export type TAnyAPIContract = TAPIContract<Record<string, TAnyNamespaceContract>>;
6
- export interface TAPIContract<Namespaces extends Record<string, TAnyNamespaceContract> = {}> {
5
+ export type TAnyAPIContract = TAPIContract<TAnyRouterContract>;
6
+ export interface TAPIContract<Router extends TAnyRouterContract = TAnyRouterContract> {
7
7
  readonly [Kind]: typeof APIKind;
8
8
  readonly type: 'neemata:api';
9
- readonly namespaces: {
10
- [K in keyof Namespaces]: TNamespaceContract<Namespaces[K]['procedures'], Namespaces[K]['events'], Extract<K, string>>;
11
- };
9
+ readonly router: Router;
12
10
  readonly timeout?: number;
13
11
  }
14
12
  export declare const APIContract: <const Options extends {
15
- namespaces: Record<string, TAnyNamespaceContract>;
13
+ router: TAnyRouterContract;
16
14
  timeout?: number;
17
15
  schemaOptions?: ContractSchemaOptions;
18
- }>(options: Options) => TAPIContract<Options["namespaces"]>;
16
+ }>(options: Options) => TAPIContract<Options["router"]>;
19
17
  export declare function IsAPIContract(value: any): value is TAnyAPIContract;
@@ -2,41 +2,12 @@ import { Kind } from "../constants.js";
2
2
  import { createSchema } from "../utils.js";
3
3
  export const APIKind = Symbol('NeemataAPI');
4
4
  export const APIContract = (options) => {
5
- const { timeout, schemaOptions } = options;
6
- const _namespaces = {};
7
- for (const namespaceKey in options.namespaces) {
8
- const namespace = options.namespaces[namespaceKey];
9
- const _procedures = {};
10
- for (const procedureKey in namespace.procedures) {
11
- const procedure = namespace.procedures[procedureKey];
12
- _procedures[procedureKey] = createSchema({
13
- ...procedure,
14
- name: procedureKey,
15
- namespace: namespaceKey,
16
- });
17
- }
18
- const _events = {};
19
- for (const eventKey in namespace.events) {
20
- const event = namespace.events[eventKey];
21
- _events[eventKey] = createSchema({
22
- ...event,
23
- subscription: undefined,
24
- name: eventKey,
25
- namespace: namespaceKey,
26
- });
27
- }
28
- _namespaces[namespaceKey] = createSchema({
29
- ...namespace,
30
- procedures: _procedures,
31
- events: _events,
32
- name: namespaceKey,
33
- });
34
- }
5
+ const { router, timeout, schemaOptions } = options;
35
6
  return createSchema({
36
7
  ...schemaOptions,
37
8
  [Kind]: APIKind,
38
9
  type: 'neemata:api',
39
- namespaces: _namespaces,
10
+ router,
40
11
  timeout,
41
12
  });
42
13
  };
@@ -1,19 +1,20 @@
1
- import { type BaseType, t } from '@nmtjs/type';
1
+ import type { BaseType } from '@nmtjs/type';
2
+ import { t } from '@nmtjs/type';
3
+ import type { ContractSchemaOptions } from '../utils.ts';
4
+ import type { SubcriptionOptions } from './subscription.ts';
2
5
  import { Kind } from '../constants.ts';
3
- import { type ContractSchemaOptions } from '../utils.ts';
4
6
  export declare const EventKind: unique symbol;
5
- export type TAnyEventContract = TEventContract<BaseType, string | undefined, string | undefined, string | undefined>;
6
- export interface TEventContract<Payload extends BaseType = t.NeverType, Name extends string | undefined = undefined, Subscription extends string | undefined = undefined, Namespace extends string | undefined = undefined> {
7
+ export type TAnyEventContract = TEventContract<BaseType, string | undefined, SubcriptionOptions | undefined>;
8
+ export interface TEventContract<Payload extends BaseType = t.NeverType, Name extends string | undefined = undefined, Options extends SubcriptionOptions | undefined = undefined> {
7
9
  readonly [Kind]: typeof EventKind;
8
10
  readonly type: 'neemata:event';
9
11
  readonly name: Name;
10
- readonly subscription: Subscription;
11
- readonly namespace: Namespace;
12
12
  readonly payload: Payload;
13
+ readonly options: Options;
13
14
  }
14
- export declare const EventContract: <Payload extends BaseType, Name extends string | undefined = undefined>(options?: {
15
+ export declare const EventContract: <Payload extends BaseType, Name extends string | undefined = undefined, Options extends SubcriptionOptions | undefined = undefined>(options?: {
15
16
  payload?: Payload;
16
17
  schemaOptions?: ContractSchemaOptions;
17
18
  name?: Name;
18
- }) => TEventContract<Payload, Name, undefined, undefined>;
19
+ }) => TEventContract<Payload, Name, Options>;
19
20
  export declare function IsEventContract(value: any): value is TAnyEventContract;
@@ -3,15 +3,14 @@ import { Kind } from "../constants.js";
3
3
  import { createSchema } from "../utils.js";
4
4
  export const EventKind = Symbol('NeemataEvent');
5
5
  export const EventContract = (options) => {
6
- const { payload = t.never(), schemaOptions = {}, name, } = options ?? {};
6
+ const { payload = t.never(), schemaOptions = {}, name = undefined, } = options ?? {};
7
7
  return createSchema({
8
8
  ...schemaOptions,
9
9
  [Kind]: EventKind,
10
10
  type: 'neemata:event',
11
11
  payload,
12
- name: name,
13
- subscription: undefined,
14
- namespace: undefined,
12
+ name,
13
+ options: undefined,
15
14
  });
16
15
  };
17
16
  export function IsEventContract(value) {
@@ -1,13 +1,13 @@
1
- import { type BaseType, t } from '@nmtjs/type';
1
+ import type { BaseType } from '@nmtjs/type';
2
+ import type { NeverType } from '@nmtjs/type/never';
3
+ import type { ContractSchemaOptions } from '../utils.ts';
2
4
  import { Kind } from '../constants.ts';
3
- import { type ContractSchemaOptions } from '../utils.ts';
4
- export type TAnyProcedureContract = TProcedureContract<BaseType, BaseType, BaseType | undefined, string | undefined, string | undefined>;
5
+ export type TAnyProcedureContract = TProcedureContract<BaseType, BaseType, BaseType | undefined, string | undefined>;
5
6
  export declare const ProcedureKind: unique symbol;
6
- export interface TProcedureContract<Input extends BaseType, Output extends BaseType, Stream extends BaseType | undefined, Name extends string | undefined = undefined, Namespace extends string | undefined = undefined> {
7
+ export interface TProcedureContract<Input extends BaseType, Output extends BaseType, Stream extends BaseType | undefined, Name extends string | undefined = undefined> {
7
8
  readonly [Kind]: typeof ProcedureKind;
8
9
  readonly type: 'neemata:procedure';
9
10
  readonly name: Name;
10
- readonly namespace: Namespace;
11
11
  readonly input: Input;
12
12
  readonly output: Output;
13
13
  readonly stream: Stream;
@@ -20,6 +20,6 @@ export declare const ProcedureContract: <const Options extends {
20
20
  timeout?: number;
21
21
  schemaOptions?: ContractSchemaOptions;
22
22
  name?: string;
23
- }>(options: Options) => TProcedureContract<Options["input"] extends BaseType<import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").TypeProps> ? Options["input"] : t.NeverType, Options["output"] extends BaseType<import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").TypeProps> ? Options["output"] : t.NeverType, Options["stream"] extends BaseType<import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").SimpleZodType, import("@nmtjs/type").TypeProps> ? Options["stream"] : undefined, Options["name"] extends string ? Options["name"] : undefined, undefined>;
23
+ }>(options: Options) => TProcedureContract<Options["input"] extends BaseType ? Options["input"] : NeverType, Options["output"] extends BaseType ? Options["output"] : NeverType, Options["stream"] extends BaseType ? Options["stream"] : undefined, Options["name"] extends string ? Options["name"] : undefined>;
24
24
  export declare function IsProcedureContract(contract: any): contract is TAnyProcedureContract;
25
25
  export declare function IsStreamProcedureContract(contract: any): contract is TAnyProcedureContract;
@@ -13,7 +13,6 @@ export const ProcedureContract = (options) => {
13
13
  stream,
14
14
  name,
15
15
  timeout,
16
- namespace: undefined,
17
16
  });
18
17
  };
19
18
  export function IsProcedureContract(contract) {
@@ -0,0 +1,22 @@
1
+ import type { ContractSchemaOptions } from '../utils.ts';
2
+ import type { TAnyProcedureContract, TProcedureContract } from './procedure.ts';
3
+ import { Kind } from '../constants.ts';
4
+ export declare const RouterKind: unique symbol;
5
+ export type TAnyRouterContract<RouteContracts extends Record<string, TRouteContract> = Record<string, TRouteContract>> = TRouterContract<RouteContracts, string | undefined>;
6
+ export type TRouteContract = TAnyProcedureContract | TRouterContract<Record<string, TRouteContract>, string | undefined>;
7
+ export interface TRouterContract<Routes extends Record<string, TRouteContract> = {}, Name extends string | undefined = undefined> {
8
+ readonly [Kind]: typeof RouterKind;
9
+ readonly type: 'neemata:router';
10
+ readonly name: Name;
11
+ readonly routes: {
12
+ [K in keyof Routes]: Routes[K] extends TAnyRouterContract ? TRouterContract<Routes[K]['routes'], Name extends string ? `${Name}/${Extract<K, string>}` : Extract<K, string>> : Routes[K] extends TAnyProcedureContract ? TProcedureContract<Routes[K]['input'], Routes[K]['output'], Routes[K]['stream'], Name extends string ? `${Name}/${Extract<K, string>}` : Extract<K, string>> : never;
13
+ };
14
+ readonly timeout?: number;
15
+ }
16
+ export declare const RouterContract: <const Options extends {
17
+ routes: Record<string, TRouteContract>;
18
+ name?: string;
19
+ timeout?: number;
20
+ schemaOptions?: ContractSchemaOptions;
21
+ }>(options: Options) => TRouterContract<Options["routes"], Options["name"] extends string ? Options["name"] : undefined>;
22
+ export declare function IsRouterContract(value: any): value is TAnyRouterContract;
@@ -0,0 +1,41 @@
1
+ import { Kind } from "../constants.js";
2
+ import { concatFullName, createSchema } from "../utils.js";
3
+ import { IsProcedureContract } from "./procedure.js";
4
+ export const RouterKind = Symbol('NeemataRouter');
5
+ export const RouterContract = (options) => {
6
+ const { name = undefined, timeout, schemaOptions = {}, } = options;
7
+ const routes = processNestedRoutes(options.routes, name);
8
+ return createSchema({
9
+ ...schemaOptions,
10
+ [Kind]: RouterKind,
11
+ type: 'neemata:router',
12
+ name,
13
+ routes,
14
+ timeout,
15
+ });
16
+ };
17
+ function processNestedRoutes(routes, parentName) {
18
+ const processed = {};
19
+ for (const routeName in routes) {
20
+ const route = routes[routeName];
21
+ if (IsRouterContract(route)) {
22
+ const nestedName = concatFullName(parentName, routeName);
23
+ processed[routeName] = createSchema({
24
+ ...route,
25
+ name: nestedName,
26
+ routes: processNestedRoutes(route.routes, nestedName),
27
+ });
28
+ }
29
+ else if (IsProcedureContract(route)) {
30
+ const fullName = concatFullName(parentName, routeName);
31
+ processed[routeName] = createSchema({ ...route, name: fullName });
32
+ }
33
+ else {
34
+ throw new Error(`Invalid route type for ${routeName}`);
35
+ }
36
+ }
37
+ return processed;
38
+ }
39
+ export function IsRouterContract(value) {
40
+ return Kind in value && value[Kind] === RouterKind;
41
+ }
@@ -1,6 +1,6 @@
1
- import { Kind } from '../constants.ts';
2
- import { type ContractSchemaOptions } from '../utils.ts';
1
+ import type { ContractSchemaOptions } from '../utils.ts';
3
2
  import type { TAnyEventContract, TEventContract } from './event.ts';
3
+ import { Kind } from '../constants.ts';
4
4
  export declare const SubscriptionKind: unique symbol;
5
5
  export type SubcriptionOptions = Record<string, string | number | boolean> | null;
6
6
  export type TAnySubscriptionContract = TSubscriptionContract<SubcriptionOptions, Record<string, TAnyEventContract>, string | undefined>;
@@ -10,18 +10,18 @@ export interface TSubscriptionContract<Options extends SubcriptionOptions = null
10
10
  readonly name: Name;
11
11
  readonly options: Options;
12
12
  readonly events: {
13
- [K in keyof Events]: Events[K] extends TAnyEventContract ? TEventContract<Events[K]['payload'], Extract<K, string>, Name> : never;
13
+ [K in keyof Events]: Events[K] extends TAnyEventContract ? TEventContract<Events[K]['payload'], Name extends string ? `${Name}/${Extract<K, string>}` : Extract<K, string>, Options> : never;
14
14
  };
15
15
  }
16
16
  export declare const SubscriptionContract: (<const Options extends {
17
17
  events: Record<string, TAnyEventContract>;
18
18
  name?: string;
19
19
  schemaOptions?: ContractSchemaOptions;
20
- }, SubOpt extends SubcriptionOptions = null>(options: Options) => TSubscriptionContract<SubOpt, Options["events"], Options["name"] extends string ? Options["name"] : undefined>) & {
20
+ }, SubOpt extends SubcriptionOptions = null>(options: Options) => TSubscriptionContract<SubOpt, Options["events"], Options["name"]>) & {
21
21
  withOptions: <Options extends SubcriptionOptions>() => <T extends {
22
22
  events: Record<string, TAnyEventContract>;
23
23
  name?: string;
24
24
  schemaOptions?: ContractSchemaOptions;
25
- }>(options: T) => TSubscriptionContract<Options, T["events"], T["name"] extends string ? T["name"] : undefined>;
25
+ }>(options: T) => TSubscriptionContract<Options, T["events"], T["name"]>;
26
26
  };
27
27
  export declare function IsSubscriptionContract(contract: any): contract is TAnySubscriptionContract;
@@ -1,17 +1,13 @@
1
1
  import { Kind } from "../constants.js";
2
- import { createSchema } from "../utils.js";
2
+ import { concatFullName, createSchema } from "../utils.js";
3
3
  export const SubscriptionKind = Symbol('NeemataSubscription');
4
4
  const _SubscriptionContract = (options) => {
5
5
  const { schemaOptions = {}, name } = options;
6
6
  const _events = {};
7
7
  for (const key in options.events) {
8
8
  const event = options.events[key];
9
- _events[key] = createSchema({
10
- ...event,
11
- name: key,
12
- namespace: undefined,
13
- subscription: name,
14
- });
9
+ const fullName = concatFullName(name, key);
10
+ _events[key] = createSchema({ ...event, name: fullName });
15
11
  }
16
12
  return createSchema({
17
13
  ...schemaOptions,
package/dist/utils.d.ts CHANGED
@@ -15,3 +15,4 @@ export declare const applyNames: <T extends Record<string, {
15
15
  };
16
16
  };
17
17
  export declare const createSchema: <T>(schema: T) => T;
18
+ export declare const concatFullName: (parent: string | undefined, name: string) => string;
package/dist/utils.js CHANGED
@@ -2,3 +2,6 @@ export const applyNames = (params, opts) => {
2
2
  return Object.fromEntries(Object.entries(params).map(([k, v]) => [k, { ...v, name: k, ...opts }]));
3
3
  };
4
4
  export const createSchema = (schema) => Object.freeze(schema);
5
+ export const concatFullName = (parent, name) => {
6
+ return parent ? `${parent}/${name}` : name;
7
+ };
package/package.json CHANGED
@@ -9,15 +9,15 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "@nmtjs/protocol": "0.13.1",
13
- "@nmtjs/type": "0.13.1"
12
+ "@nmtjs/protocol": "0.14.1",
13
+ "@nmtjs/type": "0.14.1"
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
17
  "LICENSE.md",
18
18
  "README.md"
19
19
  ],
20
- "version": "0.13.1",
20
+ "version": "0.14.1",
21
21
  "scripts": {
22
22
  "build": "tsc",
23
23
  "type-check": "tsc --noEmit"
@@ -1,26 +0,0 @@
1
- import { Kind } from '../constants.ts';
2
- import { type ContractSchemaOptions } from '../utils.ts';
3
- import type { TAnyEventContract, TEventContract } from './event.ts';
4
- import type { TAnyProcedureContract, TProcedureContract } from './procedure.ts';
5
- export declare const NamespaceKind: unique symbol;
6
- export type TAnyNamespaceContract<Procedures extends Record<string, TAnyProcedureContract> = Record<string, TAnyProcedureContract>> = TNamespaceContract<Procedures, Record<string, TAnyEventContract>, string | undefined>;
7
- export interface TNamespaceContract<Procedures extends Record<string, TAnyProcedureContract> = {}, Events extends Record<string, TAnyEventContract> = {}, Name extends string | undefined = undefined> {
8
- readonly [Kind]: typeof NamespaceKind;
9
- readonly type: 'neemata:namespace';
10
- readonly name: Name;
11
- readonly procedures: {
12
- [K in keyof Procedures]: TProcedureContract<Procedures[K]['input'], Procedures[K]['output'], Procedures[K]['stream'], Extract<K, string>, Name>;
13
- };
14
- readonly events: {
15
- [K in keyof Events]: TEventContract<Events[K]['payload'], Extract<K, string>, undefined, Name>;
16
- };
17
- readonly timeout?: number;
18
- }
19
- export declare const NamespaceContract: <const Options extends {
20
- procedures: Record<string, TAnyProcedureContract>;
21
- events: Record<string, TAnyEventContract>;
22
- name?: string;
23
- timeout?: number;
24
- schemaOptions?: ContractSchemaOptions;
25
- }>(options: Options) => TNamespaceContract<Options["procedures"], Options["events"], Options["name"] extends string ? Options["name"] : undefined>;
26
- export declare function IsNamespaceContract(value: any): value is TAnyNamespaceContract;
@@ -1,37 +0,0 @@
1
- import { Kind } from "../constants.js";
2
- import { createSchema } from "../utils.js";
3
- export const NamespaceKind = Symbol('NeemataNamespace');
4
- export const NamespaceContract = (options) => {
5
- const { name, timeout, schemaOptions = {} } = options;
6
- const events = {};
7
- for (const name in options.events) {
8
- const event = options.events[name];
9
- events[name] = createSchema({
10
- ...event,
11
- subscription: undefined,
12
- name: name,
13
- namespace: options?.name,
14
- });
15
- }
16
- const procedures = {};
17
- for (const name in options.procedures) {
18
- const procedure = options.procedures[name];
19
- procedures[name] = createSchema({
20
- ...procedure,
21
- name: name,
22
- namespace: options?.name,
23
- });
24
- }
25
- return createSchema({
26
- ...schemaOptions,
27
- [Kind]: NamespaceKind,
28
- type: 'neemata:namespace',
29
- name: name,
30
- procedures: procedures,
31
- events: events,
32
- timeout,
33
- });
34
- };
35
- export function IsNamespaceContract(value) {
36
- return Kind in value && value[Kind] === NamespaceKind;
37
- }