@nmtjs/contract 0.14.5 → 0.15.0-beta.2
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/LICENSE.md +1 -1
- package/README.md +1 -1
- package/dist/index.js +0 -3
- package/dist/types/blob.js +31 -12
- package/package.json +9 -8
- package/dist/constants.d.ts +0 -1
- package/dist/index.d.ts +0 -45
- package/dist/schemas/api.d.ts +0 -17
- package/dist/schemas/api.js +0 -16
- package/dist/schemas/event.d.ts +0 -20
- package/dist/schemas/procedure.d.ts +0 -25
- package/dist/schemas/router.d.ts +0 -22
- package/dist/schemas/subscription.d.ts +0 -27
- package/dist/types/blob.d.ts +0 -7
- package/dist/utils.d.ts +0 -18
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c)
|
|
1
|
+
Copyright (c) 2025 Denys Ilchyshyn
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { APIContract } from "./schemas/api.js";
|
|
2
1
|
import { EventContract } from "./schemas/event.js";
|
|
3
2
|
import { ProcedureContract } from "./schemas/procedure.js";
|
|
4
3
|
import { RouterContract } from "./schemas/router.js";
|
|
5
4
|
import { SubscriptionContract } from "./schemas/subscription.js";
|
|
6
5
|
import { BlobType } from "./types/blob.js";
|
|
7
|
-
export * from "./schemas/api.js";
|
|
8
6
|
export * from "./schemas/event.js";
|
|
9
7
|
export * from "./schemas/procedure.js";
|
|
10
8
|
export * from "./schemas/router.js";
|
|
@@ -15,7 +13,6 @@ export var contract;
|
|
|
15
13
|
contract.event = EventContract;
|
|
16
14
|
contract.subscription = SubscriptionContract;
|
|
17
15
|
contract.router = RouterContract;
|
|
18
|
-
contract.api = APIContract;
|
|
19
16
|
contract.blob = BlobType;
|
|
20
17
|
})(contract || (contract = {}));
|
|
21
18
|
export { contract as c };
|
package/dist/types/blob.js
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { isBlobInterface } from '@nmtjs/protocol';
|
|
2
|
+
import { CustomType } from '@nmtjs/type/custom';
|
|
3
|
+
export const BlobType = (options = {}) => CustomType.factory({
|
|
4
|
+
decode: (value) => value,
|
|
5
|
+
encode: (value) => value,
|
|
6
|
+
validation: {
|
|
7
|
+
decode(value, { addIssue }) {
|
|
8
|
+
if (isBlobInterface(value)) {
|
|
9
|
+
if (options.maxSize) {
|
|
10
|
+
const size = value.metadata.size;
|
|
11
|
+
if (typeof size !== 'undefined' && size > options.maxSize) {
|
|
12
|
+
addIssue({
|
|
13
|
+
code: 'custom',
|
|
14
|
+
message: `Blob size unknown or exceeds maximum allowed size of ${options.maxSize} bytes`,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
10
17
|
}
|
|
11
18
|
}
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
else {
|
|
20
|
+
addIssue({
|
|
21
|
+
code: 'custom',
|
|
22
|
+
message: 'Value is not a Neemata Blob. Make sure to use transport that supports encoded streams.',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
encode(value, { addIssue }) {
|
|
27
|
+
if (!isBlobInterface(value)) {
|
|
28
|
+
addIssue({
|
|
29
|
+
code: 'custom',
|
|
30
|
+
message: 'Value is not a Neemata Blob. Make sure to use transport that supports encoded streams.',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
},
|
|
14
34
|
},
|
|
15
|
-
encode: (value) => value,
|
|
16
35
|
});
|
package/package.json
CHANGED
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
"name": "@nmtjs/contract",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"exports": {
|
|
5
|
-
".":
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"import": "./dist/index.js",
|
|
8
|
-
"module-sync": "./dist/index.js"
|
|
9
|
-
}
|
|
5
|
+
".": "./dist/index.js"
|
|
10
6
|
},
|
|
11
7
|
"dependencies": {
|
|
12
|
-
"@nmtjs/protocol": "0.
|
|
13
|
-
"@nmtjs/type": "0.
|
|
8
|
+
"@nmtjs/protocol": "0.15.0-beta.2",
|
|
9
|
+
"@nmtjs/type": "0.15.0-beta.2"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"zod": "^4.1.0"
|
|
14
13
|
},
|
|
15
14
|
"files": [
|
|
16
15
|
"dist",
|
|
17
16
|
"LICENSE.md",
|
|
18
17
|
"README.md"
|
|
19
18
|
],
|
|
20
|
-
"version": "0.
|
|
19
|
+
"version": "0.15.0-beta.2",
|
|
21
20
|
"scripts": {
|
|
21
|
+
"clean-build": "rm -rf ./dist",
|
|
22
22
|
"build": "tsc",
|
|
23
|
+
"dev": "tsc --watch",
|
|
23
24
|
"type-check": "tsc --noEmit"
|
|
24
25
|
}
|
|
25
26
|
}
|
package/dist/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const Kind: unique symbol;
|
package/dist/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export * from './schemas/api.ts';
|
|
2
|
-
export * from './schemas/event.ts';
|
|
3
|
-
export * from './schemas/procedure.ts';
|
|
4
|
-
export * from './schemas/router.ts';
|
|
5
|
-
export * from './schemas/subscription.ts';
|
|
6
|
-
export declare namespace contract {
|
|
7
|
-
const procedure: <const Options extends {
|
|
8
|
-
input?: import("@nmtjs/type").BaseType;
|
|
9
|
-
output?: import("@nmtjs/type").BaseType;
|
|
10
|
-
stream?: import("@nmtjs/type").BaseType | undefined;
|
|
11
|
-
timeout?: number;
|
|
12
|
-
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
13
|
-
name?: string;
|
|
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?: {
|
|
16
|
-
payload?: Payload;
|
|
17
|
-
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
18
|
-
name?: Name;
|
|
19
|
-
}) => import("./schemas/event.ts").TEventContract<Payload, Name, Options>;
|
|
20
|
-
const subscription: (<const Options extends {
|
|
21
|
-
events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
|
|
22
|
-
name?: string;
|
|
23
|
-
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
24
|
-
}, SubOpt extends import("./schemas/subscription.ts").SubcriptionOptions = null>(options: Options) => import("./schemas/subscription.ts").TSubscriptionContract<SubOpt, Options["events"], Options["name"]>) & {
|
|
25
|
-
withOptions: <Options extends import("./schemas/subscription.ts").SubcriptionOptions>() => <T extends {
|
|
26
|
-
events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
|
|
27
|
-
name?: string;
|
|
28
|
-
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
29
|
-
}>(options: T) => import("./schemas/subscription.ts").TSubscriptionContract<Options, T["events"], T["name"]>;
|
|
30
|
-
};
|
|
31
|
-
const router: <const Options extends {
|
|
32
|
-
routes: Record<string, import("./schemas/router.ts").TRouteContract>;
|
|
33
|
-
name?: string;
|
|
34
|
-
timeout?: number;
|
|
35
|
-
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
36
|
-
}>(options: Options) => import("./schemas/router.ts").TRouterContract<Options["routes"], Options["name"] extends string ? Options["name"] : undefined>;
|
|
37
|
-
const api: <const Options extends {
|
|
38
|
-
router: import("./schemas/router.ts").TAnyRouterContract;
|
|
39
|
-
timeout?: number;
|
|
40
|
-
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
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>;
|
|
43
|
-
}
|
|
44
|
-
export { contract as c };
|
|
45
|
-
export default contract;
|
package/dist/schemas/api.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ContractSchemaOptions } from '../utils.ts';
|
|
2
|
-
import type { TAnyRouterContract } from './router.ts';
|
|
3
|
-
import { Kind } from '../constants.ts';
|
|
4
|
-
export declare const APIKind: unique symbol;
|
|
5
|
-
export type TAnyAPIContract = TAPIContract<TAnyRouterContract>;
|
|
6
|
-
export interface TAPIContract<Router extends TAnyRouterContract = TAnyRouterContract> {
|
|
7
|
-
readonly [Kind]: typeof APIKind;
|
|
8
|
-
readonly type: 'neemata:api';
|
|
9
|
-
readonly router: Router;
|
|
10
|
-
readonly timeout?: number;
|
|
11
|
-
}
|
|
12
|
-
export declare const APIContract: <const Options extends {
|
|
13
|
-
router: TAnyRouterContract;
|
|
14
|
-
timeout?: number;
|
|
15
|
-
schemaOptions?: ContractSchemaOptions;
|
|
16
|
-
}>(options: Options) => TAPIContract<Options["router"]>;
|
|
17
|
-
export declare function IsAPIContract(value: any): value is TAnyAPIContract;
|
package/dist/schemas/api.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Kind } from "../constants.js";
|
|
2
|
-
import { createSchema } from "../utils.js";
|
|
3
|
-
export const APIKind = Symbol('NeemataAPI');
|
|
4
|
-
export const APIContract = (options) => {
|
|
5
|
-
const { router, timeout, schemaOptions } = options;
|
|
6
|
-
return createSchema({
|
|
7
|
-
...schemaOptions,
|
|
8
|
-
[Kind]: APIKind,
|
|
9
|
-
type: 'neemata:api',
|
|
10
|
-
router,
|
|
11
|
-
timeout,
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
export function IsAPIContract(value) {
|
|
15
|
-
return Kind in value && value[Kind] === APIKind;
|
|
16
|
-
}
|
package/dist/schemas/event.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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';
|
|
5
|
-
import { Kind } from '../constants.ts';
|
|
6
|
-
export declare const EventKind: unique symbol;
|
|
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> {
|
|
9
|
-
readonly [Kind]: typeof EventKind;
|
|
10
|
-
readonly type: 'neemata:event';
|
|
11
|
-
readonly name: Name;
|
|
12
|
-
readonly payload: Payload;
|
|
13
|
-
readonly options: Options;
|
|
14
|
-
}
|
|
15
|
-
export declare const EventContract: <Payload extends BaseType, Name extends string | undefined = undefined, Options extends SubcriptionOptions | undefined = undefined>(options?: {
|
|
16
|
-
payload?: Payload;
|
|
17
|
-
schemaOptions?: ContractSchemaOptions;
|
|
18
|
-
name?: Name;
|
|
19
|
-
}) => TEventContract<Payload, Name, Options>;
|
|
20
|
-
export declare function IsEventContract(value: any): value is TAnyEventContract;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { BaseType } from '@nmtjs/type';
|
|
2
|
-
import type { NeverType } from '@nmtjs/type/never';
|
|
3
|
-
import type { ContractSchemaOptions } from '../utils.ts';
|
|
4
|
-
import { Kind } from '../constants.ts';
|
|
5
|
-
export type TAnyProcedureContract = TProcedureContract<BaseType, BaseType, BaseType | undefined, string | undefined>;
|
|
6
|
-
export declare const ProcedureKind: unique symbol;
|
|
7
|
-
export interface TProcedureContract<Input extends BaseType, Output extends BaseType, Stream extends BaseType | undefined, Name extends string | undefined = undefined> {
|
|
8
|
-
readonly [Kind]: typeof ProcedureKind;
|
|
9
|
-
readonly type: 'neemata:procedure';
|
|
10
|
-
readonly name: Name;
|
|
11
|
-
readonly input: Input;
|
|
12
|
-
readonly output: Output;
|
|
13
|
-
readonly stream: Stream;
|
|
14
|
-
readonly timeout?: number;
|
|
15
|
-
}
|
|
16
|
-
export declare const ProcedureContract: <const Options extends {
|
|
17
|
-
input?: BaseType;
|
|
18
|
-
output?: BaseType;
|
|
19
|
-
stream?: BaseType | undefined;
|
|
20
|
-
timeout?: number;
|
|
21
|
-
schemaOptions?: ContractSchemaOptions;
|
|
22
|
-
name?: string;
|
|
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
|
-
export declare function IsProcedureContract(contract: any): contract is TAnyProcedureContract;
|
|
25
|
-
export declare function IsStreamProcedureContract(contract: any): contract is TAnyProcedureContract;
|
package/dist/schemas/router.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ContractSchemaOptions } from '../utils.ts';
|
|
2
|
-
import type { TAnyEventContract, TEventContract } from './event.ts';
|
|
3
|
-
import { Kind } from '../constants.ts';
|
|
4
|
-
export declare const SubscriptionKind: unique symbol;
|
|
5
|
-
export type SubcriptionOptions = Record<string, string | number | boolean> | null;
|
|
6
|
-
export type TAnySubscriptionContract = TSubscriptionContract<SubcriptionOptions, Record<string, TAnyEventContract>, string | undefined>;
|
|
7
|
-
export interface TSubscriptionContract<Options extends SubcriptionOptions = null, Events extends Record<string, unknown> = {}, Name extends string | undefined = undefined> {
|
|
8
|
-
readonly [Kind]: typeof SubscriptionKind;
|
|
9
|
-
readonly type: 'neemata:subscription';
|
|
10
|
-
readonly name: Name;
|
|
11
|
-
readonly options: Options;
|
|
12
|
-
readonly events: {
|
|
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
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export declare const SubscriptionContract: (<const Options extends {
|
|
17
|
-
events: Record<string, TAnyEventContract>;
|
|
18
|
-
name?: string;
|
|
19
|
-
schemaOptions?: ContractSchemaOptions;
|
|
20
|
-
}, SubOpt extends SubcriptionOptions = null>(options: Options) => TSubscriptionContract<SubOpt, Options["events"], Options["name"]>) & {
|
|
21
|
-
withOptions: <Options extends SubcriptionOptions>() => <T extends {
|
|
22
|
-
events: Record<string, TAnyEventContract>;
|
|
23
|
-
name?: string;
|
|
24
|
-
schemaOptions?: ContractSchemaOptions;
|
|
25
|
-
}>(options: T) => TSubscriptionContract<Options, T["events"], T["name"]>;
|
|
26
|
-
};
|
|
27
|
-
export declare function IsSubscriptionContract(contract: any): contract is TAnySubscriptionContract;
|
package/dist/types/blob.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { ProtocolBlobInterface } from '@nmtjs/protocol';
|
|
2
|
-
import { t } from '@nmtjs/type';
|
|
3
|
-
export interface BlobOptions {
|
|
4
|
-
maxSize?: number;
|
|
5
|
-
contentType?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const BlobType: (options?: BlobOptions) => t.CustomType<ProtocolBlobInterface>;
|
package/dist/utils.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type ContractSchemaOptions = {
|
|
2
|
-
title?: string;
|
|
3
|
-
description?: string;
|
|
4
|
-
};
|
|
5
|
-
export declare const applyNames: <T extends Record<string, {
|
|
6
|
-
serviceName?: string;
|
|
7
|
-
}>>(params: T, opts: {
|
|
8
|
-
serviceName?: string;
|
|
9
|
-
subscriptionName?: string;
|
|
10
|
-
}) => {
|
|
11
|
-
[k: string]: {
|
|
12
|
-
serviceName?: string;
|
|
13
|
-
subscriptionName?: string;
|
|
14
|
-
name: string;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export declare const createSchema: <T>(schema: T) => T;
|
|
18
|
-
export declare const concatFullName: (parent: string | undefined, name: string) => string;
|