@nmtjs/contract 0.12.4 → 0.12.6
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/constants.d.ts +1 -0
- package/dist/constants.js +1 -3
- package/dist/index.d.ts +47 -0
- package/dist/index.js +10 -10
- package/dist/schemas/api.d.ts +19 -0
- package/dist/schemas/api.js +39 -41
- package/dist/schemas/event.d.ts +19 -0
- package/dist/schemas/event.js +13 -15
- package/dist/schemas/namespace.d.ts +26 -0
- package/dist/schemas/namespace.js +31 -33
- package/dist/schemas/procedure.d.ts +25 -0
- package/dist/schemas/procedure.js +16 -18
- package/dist/schemas/subscription.d.ts +27 -0
- package/dist/schemas/subscription.js +26 -26
- package/dist/types/blob.d.ts +7 -0
- package/dist/types/blob.js +14 -15
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +1 -7
- package/package.json +6 -5
- package/src/index.ts +3 -0
- package/src/types/blob.ts +3 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/schemas/api.js.map +0 -1
- package/dist/schemas/event.js.map +0 -1
- package/dist/schemas/namespace.js.map +0 -1
- package/dist/schemas/procedure.js.map +0 -1
- package/dist/schemas/subscription.js.map +0 -1
- package/dist/types/blob.js.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Kind: unique symbol;
|
package/dist/constants.js
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import t from '@nmtjs/type';
|
|
2
|
+
export * from './schemas/api.ts';
|
|
3
|
+
export * from './schemas/event.ts';
|
|
4
|
+
export * from './schemas/namespace.ts';
|
|
5
|
+
export * from './schemas/procedure.ts';
|
|
6
|
+
export * from './schemas/subscription.ts';
|
|
7
|
+
export declare namespace contract {
|
|
8
|
+
const procedure: <const Options extends {
|
|
9
|
+
input?: import("@nmtjs/type").BaseType;
|
|
10
|
+
output?: import("@nmtjs/type").BaseType;
|
|
11
|
+
stream?: import("@nmtjs/type").BaseType | undefined;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
14
|
+
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?: {
|
|
17
|
+
payload?: Payload;
|
|
18
|
+
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
19
|
+
name?: Name;
|
|
20
|
+
}) => import("./schemas/event.ts").TEventContract<Payload, Name, undefined, undefined>;
|
|
21
|
+
const subscription: (<const Options extends {
|
|
22
|
+
events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
|
|
23
|
+
name?: string;
|
|
24
|
+
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>) & {
|
|
26
|
+
withOptions: <Options extends import("./schemas/subscription.ts").SubcriptionOptions>() => <T extends {
|
|
27
|
+
events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
|
|
28
|
+
name?: string;
|
|
29
|
+
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
30
|
+
}>(options: T) => import("./schemas/subscription.ts").TSubscriptionContract<Options, T["events"], T["name"] extends string ? T["name"] : undefined>;
|
|
31
|
+
};
|
|
32
|
+
const namespace: <const Options extends {
|
|
33
|
+
procedures: Record<string, import("./schemas/procedure.ts").TAnyProcedureContract>;
|
|
34
|
+
events: Record<string, import("./schemas/event.ts").TAnyEventContract>;
|
|
35
|
+
name?: string;
|
|
36
|
+
timeout?: number;
|
|
37
|
+
schemaOptions?: import("./utils.ts").ContractSchemaOptions;
|
|
38
|
+
}>(options: Options) => import("./schemas/namespace.ts").TNamespaceContract<Options["procedures"], Options["events"], Options["name"] extends string ? Options["name"] : undefined>;
|
|
39
|
+
const api: <const Options extends {
|
|
40
|
+
namespaces: Record<string, import("./schemas/namespace.ts").TAnyNamespaceContract>;
|
|
41
|
+
timeout?: number;
|
|
42
|
+
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>;
|
|
45
|
+
}
|
|
46
|
+
export { contract as c };
|
|
47
|
+
export default contract;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// biome-ignore lint/correctness/noUnusedImports: TSC wants it
|
|
2
|
+
import t from '@nmtjs/type';
|
|
1
3
|
import { APIContract } from "./schemas/api.js";
|
|
2
4
|
import { EventContract } from "./schemas/event.js";
|
|
3
5
|
import { NamespaceContract } from "./schemas/namespace.js";
|
|
@@ -9,16 +11,14 @@ export * from "./schemas/event.js";
|
|
|
9
11
|
export * from "./schemas/namespace.js";
|
|
10
12
|
export * from "./schemas/procedure.js";
|
|
11
13
|
export * from "./schemas/subscription.js";
|
|
12
|
-
export
|
|
13
|
-
(function(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export var contract;
|
|
15
|
+
(function (contract) {
|
|
16
|
+
contract.procedure = ProcedureContract;
|
|
17
|
+
contract.event = EventContract;
|
|
18
|
+
contract.subscription = SubscriptionContract;
|
|
19
|
+
contract.namespace = NamespaceContract;
|
|
20
|
+
contract.api = APIContract;
|
|
21
|
+
contract.blob = BlobType;
|
|
20
22
|
})(contract || (contract = {}));
|
|
21
23
|
export { contract as c };
|
|
22
24
|
export default contract;
|
|
23
|
-
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Kind } from '../constants.ts';
|
|
2
|
+
import { type ContractSchemaOptions } from '../utils.ts';
|
|
3
|
+
import type { TAnyNamespaceContract, TNamespaceContract } from './namespace.ts';
|
|
4
|
+
export declare const APIKind: unique symbol;
|
|
5
|
+
export type TAnyAPIContract = TAPIContract<Record<string, TAnyNamespaceContract>>;
|
|
6
|
+
export interface TAPIContract<Namespaces extends Record<string, TAnyNamespaceContract> = {}> {
|
|
7
|
+
readonly [Kind]: typeof APIKind;
|
|
8
|
+
readonly type: 'neemata:api';
|
|
9
|
+
readonly namespaces: {
|
|
10
|
+
[K in keyof Namespaces]: TNamespaceContract<Namespaces[K]['procedures'], Namespaces[K]['events'], Extract<K, string>>;
|
|
11
|
+
};
|
|
12
|
+
readonly timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const APIContract: <const Options extends {
|
|
15
|
+
namespaces: Record<string, TAnyNamespaceContract>;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
schemaOptions?: ContractSchemaOptions;
|
|
18
|
+
}>(options: Options) => TAPIContract<Options["namespaces"]>;
|
|
19
|
+
export declare function IsAPIContract(value: any): value is TAnyAPIContract;
|
package/dist/schemas/api.js
CHANGED
|
@@ -1,47 +1,45 @@
|
|
|
1
1
|
import { Kind } from "../constants.js";
|
|
2
2
|
import { createSchema } from "../utils.js";
|
|
3
|
-
export const APIKind = Symbol(
|
|
3
|
+
export const APIKind = Symbol('NeemataAPI');
|
|
4
4
|
export const APIContract = (options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}
|
|
35
|
+
return createSchema({
|
|
36
|
+
...schemaOptions,
|
|
37
|
+
[Kind]: APIKind,
|
|
38
|
+
type: 'neemata:api',
|
|
39
|
+
namespaces: _namespaces,
|
|
40
|
+
timeout,
|
|
41
|
+
});
|
|
42
42
|
};
|
|
43
43
|
export function IsAPIContract(value) {
|
|
44
|
-
|
|
44
|
+
return Kind in value && value[Kind] === APIKind;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type BaseType, t } from '@nmtjs/type';
|
|
2
|
+
import { Kind } from '../constants.ts';
|
|
3
|
+
import { type ContractSchemaOptions } from '../utils.ts';
|
|
4
|
+
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
|
+
readonly [Kind]: typeof EventKind;
|
|
8
|
+
readonly type: 'neemata:event';
|
|
9
|
+
readonly name: Name;
|
|
10
|
+
readonly subscription: Subscription;
|
|
11
|
+
readonly namespace: Namespace;
|
|
12
|
+
readonly payload: Payload;
|
|
13
|
+
}
|
|
14
|
+
export declare const EventContract: <Payload extends BaseType, Name extends string | undefined = undefined>(options?: {
|
|
15
|
+
payload?: Payload;
|
|
16
|
+
schemaOptions?: ContractSchemaOptions;
|
|
17
|
+
name?: Name;
|
|
18
|
+
}) => TEventContract<Payload, Name, undefined, undefined>;
|
|
19
|
+
export declare function IsEventContract(value: any): value is TAnyEventContract;
|
package/dist/schemas/event.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { t } from
|
|
1
|
+
import { t } from '@nmtjs/type';
|
|
2
2
|
import { Kind } from "../constants.js";
|
|
3
3
|
import { createSchema } from "../utils.js";
|
|
4
|
-
export const EventKind = Symbol(
|
|
4
|
+
export const EventKind = Symbol('NeemataEvent');
|
|
5
5
|
export const EventContract = (options) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const { payload = t.never(), schemaOptions = {}, name, } = options ?? {};
|
|
7
|
+
return createSchema({
|
|
8
|
+
...schemaOptions,
|
|
9
|
+
[Kind]: EventKind,
|
|
10
|
+
type: 'neemata:event',
|
|
11
|
+
payload,
|
|
12
|
+
name: name,
|
|
13
|
+
subscription: undefined,
|
|
14
|
+
namespace: undefined,
|
|
15
|
+
});
|
|
16
16
|
};
|
|
17
17
|
export function IsEventContract(value) {
|
|
18
|
-
|
|
18
|
+
return Kind in value && value[Kind] === EventKind;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
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,39 +1,37 @@
|
|
|
1
1
|
import { Kind } from "../constants.js";
|
|
2
2
|
import { createSchema } from "../utils.js";
|
|
3
|
-
export const NamespaceKind = Symbol(
|
|
3
|
+
export const NamespaceKind = Symbol('NeemataNamespace');
|
|
4
4
|
export const NamespaceContract = (options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
34
|
};
|
|
35
35
|
export function IsNamespaceContract(value) {
|
|
36
|
-
|
|
36
|
+
return Kind in value && value[Kind] === NamespaceKind;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=namespace.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type BaseType, t } from '@nmtjs/type';
|
|
2
|
+
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 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
|
+
readonly [Kind]: typeof ProcedureKind;
|
|
8
|
+
readonly type: 'neemata:procedure';
|
|
9
|
+
readonly name: Name;
|
|
10
|
+
readonly namespace: Namespace;
|
|
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<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>;
|
|
24
|
+
export declare function IsProcedureContract(contract: any): contract is TAnyProcedureContract;
|
|
25
|
+
export declare function IsStreamProcedureContract(contract: any): contract is TAnyProcedureContract;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import { t } from
|
|
1
|
+
import { t } from '@nmtjs/type';
|
|
2
2
|
import { Kind } from "../constants.js";
|
|
3
3
|
import { createSchema } from "../utils.js";
|
|
4
|
-
export const ProcedureKind = Symbol(
|
|
4
|
+
export const ProcedureKind = Symbol('NeemataProcedure');
|
|
5
5
|
export const ProcedureContract = (options) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const { input = t.never(), output = t.never(), stream = undefined, name = undefined, timeout, schemaOptions = {}, } = options;
|
|
7
|
+
return createSchema({
|
|
8
|
+
...schemaOptions,
|
|
9
|
+
[Kind]: ProcedureKind,
|
|
10
|
+
type: 'neemata:procedure',
|
|
11
|
+
input,
|
|
12
|
+
output,
|
|
13
|
+
stream,
|
|
14
|
+
name,
|
|
15
|
+
timeout,
|
|
16
|
+
namespace: undefined,
|
|
17
|
+
});
|
|
18
18
|
};
|
|
19
19
|
export function IsProcedureContract(contract) {
|
|
20
|
-
|
|
20
|
+
return Kind in contract && contract[Kind] === ProcedureKind;
|
|
21
21
|
}
|
|
22
22
|
export function IsStreamProcedureContract(contract) {
|
|
23
|
-
|
|
23
|
+
return IsProcedureContract(contract) && typeof contract.stream !== 'undefined';
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=procedure.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Kind } from '../constants.ts';
|
|
2
|
+
import { type ContractSchemaOptions } from '../utils.ts';
|
|
3
|
+
import type { TAnyEventContract, TEventContract } from './event.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'], Extract<K, string>, Name> : 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"] extends string ? Options["name"] : undefined>) & {
|
|
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"] extends string ? T["name"] : undefined>;
|
|
26
|
+
};
|
|
27
|
+
export declare function IsSubscriptionContract(contract: any): contract is TAnySubscriptionContract;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { Kind } from "../constants.js";
|
|
2
2
|
import { createSchema } from "../utils.js";
|
|
3
|
-
export const SubscriptionKind = Symbol(
|
|
3
|
+
export const SubscriptionKind = Symbol('NeemataSubscription');
|
|
4
4
|
const _SubscriptionContract = (options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
const { schemaOptions = {}, name } = options;
|
|
6
|
+
const _events = {};
|
|
7
|
+
for (const key in options.events) {
|
|
8
|
+
const event = options.events[key];
|
|
9
|
+
_events[key] = createSchema({
|
|
10
|
+
...event,
|
|
11
|
+
name: key,
|
|
12
|
+
namespace: undefined,
|
|
13
|
+
subscription: name,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return createSchema({
|
|
17
|
+
...schemaOptions,
|
|
18
|
+
[Kind]: SubscriptionKind,
|
|
19
|
+
type: 'neemata:subscription',
|
|
20
|
+
events: _events,
|
|
21
|
+
name: name,
|
|
22
|
+
options: undefined,
|
|
23
|
+
});
|
|
24
24
|
};
|
|
25
|
-
export const SubscriptionContract = Object.assign(_SubscriptionContract, {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
export const SubscriptionContract = Object.assign(_SubscriptionContract, {
|
|
26
|
+
withOptions: () => {
|
|
27
|
+
return (options) => _SubscriptionContract(options);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
28
30
|
export function IsSubscriptionContract(contract) {
|
|
29
|
-
|
|
31
|
+
return Kind in contract && contract[Kind] === SubscriptionKind;
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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/types/blob.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { t } from
|
|
1
|
+
import { t } from '@nmtjs/type';
|
|
2
2
|
export const BlobType = (options = {}) => t.custom({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
decode: (value) => {
|
|
4
|
+
// TODO: here should be some validation logic to check if the value is an actual blob
|
|
5
|
+
if ('metadata' in value) {
|
|
6
|
+
if (options.maxSize) {
|
|
7
|
+
const size = value.metadata.size;
|
|
8
|
+
if (typeof size !== 'undefined' && size > options.maxSize) {
|
|
9
|
+
throw new Error('Blob size unknown or exceeds maximum allowed size');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
},
|
|
15
|
+
encode: (value) => value,
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=blob.js.map
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
package/dist/utils.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
export const applyNames = (params, opts) => {
|
|
2
|
-
|
|
3
|
-
...v,
|
|
4
|
-
name: k,
|
|
5
|
-
...opts
|
|
6
|
-
}]));
|
|
2
|
+
return Object.fromEntries(Object.entries(params).map(([k, v]) => [k, { ...v, name: k, ...opts }]));
|
|
7
3
|
};
|
|
8
4
|
export const createSchema = (schema) => Object.freeze(schema);
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
6
7
|
"import": "./dist/index.js",
|
|
7
|
-
"
|
|
8
|
+
"module-sync": "./dist/index.js"
|
|
8
9
|
}
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
|
-
"@nmtjs/
|
|
12
|
-
"@nmtjs/
|
|
12
|
+
"@nmtjs/protocol": "0.12.6",
|
|
13
|
+
"@nmtjs/type": "0.12.6"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"src",
|
|
@@ -17,9 +18,9 @@
|
|
|
17
18
|
"LICENSE.md",
|
|
18
19
|
"README.md"
|
|
19
20
|
],
|
|
20
|
-
"version": "0.12.
|
|
21
|
+
"version": "0.12.6",
|
|
21
22
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
+
"build": "tsc",
|
|
23
24
|
"type-check": "tsc --noEmit"
|
|
24
25
|
}
|
|
25
26
|
}
|
package/src/index.ts
CHANGED
package/src/types/blob.ts
CHANGED
|
@@ -6,7 +6,9 @@ export interface BlobOptions {
|
|
|
6
6
|
contentType?: string
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const BlobType = (
|
|
9
|
+
export const BlobType = (
|
|
10
|
+
options: BlobOptions = {},
|
|
11
|
+
): t.CustomType<ProtocolBlobInterface> =>
|
|
10
12
|
t.custom<ProtocolBlobInterface>({
|
|
11
13
|
decode: (value) => {
|
|
12
14
|
// TODO: here should be some validation logic to check if the value is an actual blob
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,MAAM,OAAO,OAAO,IAAI,eAAe","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const Kind = Symbol.for('neemata:kind')\n"],"version":3,"file":"constants.js"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,mBAAmB,kBAAkB;AAC9C,SAAS,qBAAqB,oBAAoB;AAClD,SAAS,yBAAyB,wBAAwB;AAC1D,SAAS,yBAAyB,wBAAwB;AAC1D,SAAS,4BAA4B,2BAA2B;AAChE,SAAS,gBAAgB,iBAAiB;AAE1C,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;;AAEP;CACE,MAAM,kCAAY;CAClB,MAAM,0BAAQ;CACd,MAAM,wCAAe;CACrB,MAAM,kCAAY;CAClB,MAAM,sBAAM;CACZ,MAAM,wBAAO;;AAGtB,SAAS,YAAY;AAErB,eAAe","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { APIContract } from './schemas/api.ts'\nimport { EventContract } from './schemas/event.ts'\nimport { NamespaceContract } from './schemas/namespace.ts'\nimport { ProcedureContract } from './schemas/procedure.ts'\nimport { SubscriptionContract } from './schemas/subscription.ts'\nimport { BlobType } from './types/blob.ts'\n\nexport * from './schemas/api.ts'\nexport * from './schemas/event.ts'\nexport * from './schemas/namespace.ts'\nexport * from './schemas/procedure.ts'\nexport * from './schemas/subscription.ts'\n\nexport namespace contract {\n export const procedure = ProcedureContract\n export const event = EventContract\n export const subscription = SubscriptionContract\n export const namespace = NamespaceContract\n export const api = APIContract\n export const blob = BlobType\n}\n\nexport { contract as c }\n\nexport default contract\n"],"version":3,"file":"index.js"}
|
package/dist/schemas/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAKtE,OAAO,MAAM,UAAU,OAAO,aAAa;AAqB3C,OAAO,MAAM,cAAc,CAOzBA,YACG;CACH,MAAM,EAAE,SAAS,eAAe,GAAG;CAEnC,MAAM,cAAc,CAAE;AAEtB,MAAK,MAAM,gBAAgB,QAAQ,YAAY;EAC7C,MAAM,YAAY,QAAQ,WAAW;EACrC,MAAM,cAAc,CAAE;AACtB,OAAK,MAAM,gBAAgB,UAAU,YAAY;GAC/C,MAAM,YAAY,UAAU,WAAW;AACvC,eAAY,gBAAgB,aAQ1B;IACA,GAAG;IACH,MAAM;IACN,WAAW;GACZ,EAAC;EACH;EAED,MAAM,UAAU,CAAE;AAClB,OAAK,MAAM,YAAY,UAAU,QAAQ;GACvC,MAAM,QAAQ,UAAU,OAAO;AAC/B,WAAQ,YAAY,aAOlB;IACA,GAAG;IACH,cAAc;IACd,MAAM;IACN,WAAW;GACZ,EAAC;EACH;AAED,cAAY,gBAAgB,aAM1B;GACA,GAAG;GACH,YAAY;GACZ,QAAQ;GACR,MAAM;EACP,EAAC;CACH;AAED,QAAO,aAAkD;EACvD,GAAG;GACF,OAAO;EACR,MAAM;EACN,YAAY;EACZ;CACD,EAAC;AACH;AAED,OAAO,SAAS,cAAcC,OAAsC;AAClE,QAAO,QAAQ,SAAS,MAAM,UAAU;AACzC","names":["options: Options","value: any"],"sources":["../../src/schemas/api.ts"],"sourcesContent":["import { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TEventContract } from './event.ts'\nimport type { TAnyNamespaceContract, TNamespaceContract } from './namespace.ts'\nimport type { TProcedureContract } from './procedure.ts'\n\nexport const APIKind = Symbol('NeemataAPI')\n\nexport type TAnyAPIContract = TAPIContract<\n Record<string, TAnyNamespaceContract>\n>\n\nexport interface TAPIContract<\n Namespaces extends Record<string, TAnyNamespaceContract> = {},\n> {\n readonly [Kind]: typeof APIKind\n readonly type: 'neemata:api'\n readonly namespaces: {\n [K in keyof Namespaces]: TNamespaceContract<\n Namespaces[K]['procedures'],\n Namespaces[K]['events'],\n Extract<K, string>\n >\n }\n readonly timeout?: number\n}\n\nexport const APIContract = <\n const Options extends {\n namespaces: Record<string, TAnyNamespaceContract>\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n },\n>(\n options: Options,\n) => {\n const { timeout, schemaOptions } = options\n\n const _namespaces = {} as any\n\n for (const namespaceKey in options.namespaces) {\n const namespace = options.namespaces[namespaceKey]\n const _procedures = {} as any\n for (const procedureKey in namespace.procedures) {\n const procedure = namespace.procedures[procedureKey]\n _procedures[procedureKey] = createSchema<\n TProcedureContract<\n (typeof procedure)['input'],\n (typeof procedure)['output'],\n (typeof procedure)['stream'],\n Extract<typeof procedureKey, string>,\n Extract<typeof namespaceKey, string>\n >\n >({\n ...procedure,\n name: procedureKey,\n namespace: namespaceKey,\n })\n }\n\n const _events = {} as any\n for (const eventKey in namespace.events) {\n const event = namespace.events[eventKey]\n _events[eventKey] = createSchema<\n TEventContract<\n (typeof event)['payload'],\n Extract<typeof eventKey, string>,\n undefined,\n Extract<typeof namespaceKey, string>\n >\n >({\n ...event,\n subscription: undefined,\n name: eventKey,\n namespace: namespaceKey,\n })\n }\n\n _namespaces[namespaceKey] = createSchema<\n TNamespaceContract<\n typeof _procedures,\n typeof _events,\n Extract<typeof namespaceKey, string>\n >\n >({\n ...namespace,\n procedures: _procedures,\n events: _events,\n name: namespaceKey,\n })\n }\n\n return createSchema<TAPIContract<Options['namespaces']>>({\n ...schemaOptions,\n [Kind]: APIKind,\n type: 'neemata:api',\n namespaces: _namespaces,\n timeout,\n })\n}\n\nexport function IsAPIContract(value: any): value is TAnyAPIContract {\n return Kind in value && value[Kind] === APIKind\n}\n"],"version":3,"file":"api.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAwB,SAAS,aAAa;AAC9C,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAEtE,OAAO,MAAM,YAAY,OAAO,eAAe;AAuB/C,OAAO,MAAM,gBAAgB,CAG3BA,YAII;CACJ,MAAM,EACJ,UAAU,EAAE,OAAO,EACnB,gBAAgB,CAAE,GAClB,MACD,GAAG,WAAW,CAAE;AACjB,QAAO,aAA4C;EACjD,GAAG;GACF,OAAO;EACR,MAAM;EACN;EACM;EACN,cAAc;EACd,WAAW;CACZ,EAAC;AACH;AAED,OAAO,SAAS,gBAAgBC,OAAwC;AACtE,QAAO,QAAQ,SAAS,MAAM,UAAU;AACzC","names":["options?: {\n payload?: Payload\n schemaOptions?: ContractSchemaOptions\n name?: Name\n}","value: any"],"sources":["../../src/schemas/event.ts"],"sourcesContent":["import { type BaseType, t } from '@nmtjs/type'\nimport { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport const EventKind = Symbol('NeemataEvent')\n\nexport type TAnyEventContract = TEventContract<\n BaseType,\n string | undefined,\n string | undefined,\n string | undefined\n>\n\nexport interface TEventContract<\n Payload extends BaseType = t.NeverType,\n Name extends string | undefined = undefined,\n Subscription extends string | undefined = undefined,\n Namespace extends string | undefined = undefined,\n> {\n readonly [Kind]: typeof EventKind\n readonly type: 'neemata:event'\n readonly name: Name\n readonly subscription: Subscription\n readonly namespace: Namespace\n readonly payload: Payload\n}\n\nexport const EventContract = <\n Payload extends BaseType,\n Name extends string | undefined = undefined,\n>(options?: {\n payload?: Payload\n schemaOptions?: ContractSchemaOptions\n name?: Name\n}) => {\n const {\n payload = t.never() as unknown as Payload,\n schemaOptions = {},\n name,\n } = options ?? {}\n return createSchema<TEventContract<Payload, Name>>({\n ...schemaOptions,\n [Kind]: EventKind,\n type: 'neemata:event',\n payload,\n name: name as Name,\n subscription: undefined,\n namespace: undefined,\n })\n}\n\nexport function IsEventContract(value: any): value is TAnyEventContract {\n return Kind in value && value[Kind] === EventKind\n}\n"],"version":3,"file":"event.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAItE,OAAO,MAAM,gBAAgB,OAAO,mBAAmB;AAyCvD,OAAO,MAAM,oBAAoB,CAS/BA,YACG;CACH,MAAM,EAAE,MAAM,SAAS,gBAAgB,CAAE,GAA2B,GAAG;CACvE,MAAMC,SAA8B,CAAE;AAEtC,MAAK,MAAM,QAAQ,QAAQ,QAAQ;EACjC,MAAM,QAAQ,QAAQ,OAAO;AAC7B,SAAO,QAAQ,aAOb;GACA,GAAG;GACH,cAAc;GACR;GACN,WAAW,SAAS;EACrB,EAAC;CACH;CAED,MAAMC,aAAkC,CAAE;AAE1C,MAAK,MAAM,QAAQ,QAAQ,YAAY;EACrC,MAAMC,YAAiB,QAAQ,WAAW;AAC1C,aAAW,QAAQ,aAQjB;GACA,GAAG;GACG;GACN,WAAW,SAAS;EACrB,EAAC;CACH;AAED,QAAO,aAML;EACA,GAAG;GACF,OAAO;EACR,MAAM;EACA;EACM;EACJ;EACR;CACD,EAAC;AACH;AAED,OAAO,SAAS,oBACdC,OACgC;AAChC,QAAO,QAAQ,SAAS,MAAM,UAAU;AACzC","names":["options: Options","events: Record<string, any>","procedures: Record<string, any>","procedure: any","value: any"],"sources":["../../src/schemas/namespace.ts"],"sourcesContent":["import { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TAnyEventContract, TEventContract } from './event.ts'\nimport type { TAnyProcedureContract, TProcedureContract } from './procedure.ts'\n\nexport const NamespaceKind = Symbol('NeemataNamespace')\n\nexport type TAnyNamespaceContract<\n Procedures extends Record<string, TAnyProcedureContract> = Record<\n string,\n TAnyProcedureContract\n >,\n> = TNamespaceContract<\n Procedures,\n Record<string, TAnyEventContract>,\n string | undefined\n>\n\nexport interface TNamespaceContract<\n Procedures extends Record<string, TAnyProcedureContract> = {},\n Events extends Record<string, TAnyEventContract> = {},\n Name extends string | undefined = undefined,\n> {\n readonly [Kind]: typeof NamespaceKind\n readonly type: 'neemata:namespace'\n readonly name: Name\n readonly procedures: {\n [K in keyof Procedures]: TProcedureContract<\n Procedures[K]['input'],\n Procedures[K]['output'],\n Procedures[K]['stream'],\n Extract<K, string>,\n Name\n >\n }\n readonly events: {\n [K in keyof Events]: TEventContract<\n Events[K]['payload'],\n Extract<K, string>,\n undefined,\n Name\n >\n }\n readonly timeout?: number\n}\n\nexport const NamespaceContract = <\n const Options extends {\n procedures: Record<string, TAnyProcedureContract>\n events: Record<string, TAnyEventContract>\n name?: string\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n },\n>(\n options: Options,\n) => {\n const { name, timeout, schemaOptions = {} as ContractSchemaOptions } = options\n const events: Record<string, any> = {}\n\n for (const name in options.events) {\n const event = options.events[name]\n events[name] = createSchema<\n TEventContract<\n (typeof event)['payload'],\n Extract<typeof name, string>,\n undefined,\n Options['name'] extends string ? Options['name'] : undefined\n >\n >({\n ...event,\n subscription: undefined,\n name: name as any,\n namespace: options?.name as any,\n })\n }\n\n const procedures: Record<string, any> = {}\n\n for (const name in options.procedures) {\n const procedure: any = options.procedures[name]\n procedures[name] = createSchema<\n TProcedureContract<\n (typeof procedure)['input'],\n (typeof procedure)['output'],\n (typeof procedure)['stream'],\n Extract<typeof name, string>,\n Options['name'] extends string ? Options['name'] : undefined\n >\n >({\n ...procedure,\n name: name as any,\n namespace: options?.name as any,\n })\n }\n\n return createSchema<\n TNamespaceContract<\n Options['procedures'],\n Options['events'],\n Options['name'] extends string ? Options['name'] : undefined\n >\n >({\n ...schemaOptions,\n [Kind]: NamespaceKind,\n type: 'neemata:namespace',\n name: name as any,\n procedures: procedures as any,\n events: events as any,\n timeout,\n })\n}\n\nexport function IsNamespaceContract(\n value: any,\n): value is TAnyNamespaceContract {\n return Kind in value && value[Kind] === NamespaceKind\n}\n"],"version":3,"file":"namespace.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAwB,SAAS,aAAa;AAC9C,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAUtE,OAAO,MAAM,gBAAgB,OAAO,mBAAmB;AAmBvD,OAAO,MAAM,oBAAoB,CAU/BA,YACG;CACH,MAAM,EACJ,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,OAAO,EAClB,SAAS,WACT,OAAO,WACP,SACA,gBAAgB,CAAE,GACnB,GAAG;AACJ,QAAO,aAOL;EACA,GAAG;GACF,OAAO;EACR,MAAM;EACN;EACA;EACA;EACA;EACA;EACA,WAAW;CACZ,EAAC;AACH;AAED,OAAO,SAAS,oBACdC,UACmC;AACnC,QAAO,QAAQ,YAAY,SAAS,UAAU;AAC/C;AAED,OAAO,SAAS,0BACdA,UACmC;AACnC,QAAO,oBAAoB,SAAS,WAAW,SAAS,WAAW;AACpE","names":["options: Options","contract: any"],"sources":["../../src/schemas/procedure.ts"],"sourcesContent":["import { type BaseType, t } from '@nmtjs/type'\nimport { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport type TAnyProcedureContract = TProcedureContract<\n BaseType,\n BaseType,\n BaseType | undefined,\n string | undefined,\n string | undefined\n>\n\nexport const ProcedureKind = Symbol('NeemataProcedure')\n\nexport interface TProcedureContract<\n Input extends BaseType,\n Output extends BaseType,\n Stream extends BaseType | undefined,\n Name extends string | undefined = undefined,\n Namespace extends string | undefined = undefined,\n> {\n readonly [Kind]: typeof ProcedureKind\n readonly type: 'neemata:procedure'\n readonly name: Name\n readonly namespace: Namespace\n readonly input: Input\n readonly output: Output\n readonly stream: Stream\n readonly timeout?: number\n}\n\nexport const ProcedureContract = <\n const Options extends {\n input?: BaseType\n output?: BaseType\n stream?: BaseType | undefined\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n name?: string\n },\n>(\n options: Options,\n) => {\n const {\n input = t.never() as any,\n output = t.never() as any,\n stream = undefined as any,\n name = undefined as any,\n timeout,\n schemaOptions = {},\n } = options\n return createSchema<\n TProcedureContract<\n Options['input'] extends BaseType ? Options['input'] : t.NeverType,\n Options['output'] extends BaseType ? Options['output'] : t.NeverType,\n Options['stream'] extends BaseType ? Options['stream'] : undefined,\n Options['name'] extends string ? Options['name'] : undefined\n >\n >({\n ...schemaOptions,\n [Kind]: ProcedureKind,\n type: 'neemata:procedure',\n input,\n output,\n stream,\n name,\n timeout,\n namespace: undefined,\n })\n}\n\nexport function IsProcedureContract(\n contract: any,\n): contract is TAnyProcedureContract {\n return Kind in contract && contract[Kind] === ProcedureKind\n}\n\nexport function IsStreamProcedureContract(\n contract: any,\n): contract is TAnyProcedureContract {\n return IsProcedureContract(contract) && typeof contract.stream !== 'undefined'\n}\n"],"version":3,"file":"procedure.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAGtE,OAAO,MAAM,mBAAmB,OAAO,sBAAsB;AA6B7D,MAAM,wBAAwB,CAQ5BA,YACG;CACH,MAAM,EAAE,gBAAgB,CAAE,GAAE,MAAM,GAAG;CACrC,MAAM,UAAU,CAAE;AAClB,MAAK,MAAM,OAAO,QAAQ,QAAQ;EAChC,MAAM,QAAQ,QAAQ,OAAO;AAC7B,UAAQ,OAAO,aAOb;GACA,GAAG;GACH,MAAM;GACN,WAAW;GACX,cAAc;EACf,EAAC;CACH;AACD,QAAO,aAML;EACA,GAAG;GACF,OAAO;EACR,MAAM;EACN,QAAQ;EACF;EACN,SAAS;CACV,EAAC;AACH;AAED,OAAO,MAAM,uBAAuB,OAAO,OAAO,uBAAuB,EACvE,aAAa,MAA0C;AACrD,QAAO,CAOLC,YACG,sBAAkC,QAAQ;AAChD,EACF,EAAC;AAEF,OAAO,SAAS,uBACdC,UACsC;AACtC,QAAO,QAAQ,YAAY,SAAS,UAAU;AAC/C","names":["options: Options","options: T","contract: any"],"sources":["../../src/schemas/subscription.ts"],"sourcesContent":["import { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TAnyEventContract, TEventContract } from './event.ts'\n\nexport const SubscriptionKind = Symbol('NeemataSubscription')\n\nexport type SubcriptionOptions = Record<\n string,\n string | number | boolean\n> | null\n\nexport type TAnySubscriptionContract = TSubscriptionContract<\n SubcriptionOptions,\n Record<string, TAnyEventContract>,\n string | undefined\n>\n\nexport interface TSubscriptionContract<\n Options extends SubcriptionOptions = null,\n Events extends Record<string, unknown> = {},\n Name extends string | undefined = undefined,\n> {\n readonly [Kind]: typeof SubscriptionKind\n readonly type: 'neemata:subscription'\n readonly name: Name\n readonly options: Options\n readonly events: {\n [K in keyof Events]: Events[K] extends TAnyEventContract\n ? TEventContract<Events[K]['payload'], Extract<K, string>, Name>\n : never\n }\n}\n\nconst _SubscriptionContract = <\n const Options extends {\n events: Record<string, TAnyEventContract>\n name?: string\n schemaOptions?: ContractSchemaOptions\n },\n SubOpt extends SubcriptionOptions = null,\n>(\n options: Options,\n) => {\n const { schemaOptions = {}, name } = options\n const _events = {} as any\n for (const key in options.events) {\n const event = options.events[key]\n _events[key] = createSchema<\n TEventContract<\n (typeof event)['payload'],\n Extract<typeof key, string>,\n undefined,\n Options['name'] extends string ? Options['name'] : undefined\n >\n >({\n ...event,\n name: key,\n namespace: undefined,\n subscription: name as any,\n })\n }\n return createSchema<\n TSubscriptionContract<\n SubOpt,\n Options['events'],\n Options['name'] extends string ? Options['name'] : undefined\n >\n >({\n ...schemaOptions,\n [Kind]: SubscriptionKind,\n type: 'neemata:subscription',\n events: _events,\n name: name as any,\n options: undefined as unknown as SubOpt,\n })\n}\n\nexport const SubscriptionContract = Object.assign(_SubscriptionContract, {\n withOptions: <Options extends SubcriptionOptions>() => {\n return <\n T extends {\n events: Record<string, TAnyEventContract>\n name?: string\n schemaOptions?: ContractSchemaOptions\n },\n >(\n options: T,\n ) => _SubscriptionContract<T, Options>(options)\n },\n})\n\nexport function IsSubscriptionContract(\n contract: any,\n): contract is TAnySubscriptionContract {\n return Kind in contract && contract[Kind] === SubscriptionKind\n}\n"],"version":3,"file":"subscription.js"}
|
package/dist/types/blob.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AACA,SAAS,SAAS,aAAa;AAO/B,OAAO,MAAM,WAAW,CAACA,UAAuB,CAAE,MAChD,EAAE,OAA8B;CAC9B,QAAQ,CAAC,UAAU;AAEjB,MAAI,cAAc,OAAO;AACvB,OAAI,QAAQ,SAAS;IACnB,MAAM,OAAQ,MAAgC,SAAS;AACvD,eAAW,SAAS,eAAe,OAAO,QAAQ,SAAS;AACzD,WAAM,IAAI,MAAM;IACjB;GACF;EACF;AACD,SAAO;CACR;CACD,QAAQ,CAAC,UAAU;AACpB,EAAC","names":["options: BlobOptions"],"sources":["../../src/types/blob.ts"],"sourcesContent":["import type { ProtocolBlobInterface } from '@nmtjs/protocol'\nimport { t } from '@nmtjs/type'\n\nexport interface BlobOptions {\n maxSize?: number\n contentType?: string\n}\n\nexport const BlobType = (options: BlobOptions = {}) =>\n t.custom<ProtocolBlobInterface>({\n decode: (value) => {\n // TODO: here should be some validation logic to check if the value is an actual blob\n if ('metadata' in value) {\n if (options.maxSize) {\n const size = (value as ProtocolBlobInterface).metadata.size\n if (typeof size !== 'undefined' && size > options.maxSize) {\n throw new Error('Blob size unknown or exceeds maximum allowed size')\n }\n }\n }\n return value\n },\n encode: (value) => value,\n })\n"],"version":3,"file":"blob.js"}
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAKA,OAAO,MAAM,aAAa,CACxBA,QACAC,SACG;AACH,QAAO,OAAO,YACZ,OAAO,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG;EAAE,GAAG;EAAG,MAAM;EAAG,GAAG;CAAM,CAAC,EAAC,CACxE;AACF;AAED,OAAO,MAAM,eAAe,CAAIC,WAAc,OAAO,OAAO,OAAO","names":["params: T","opts: { serviceName?: string; subscriptionName?: string }","schema: T"],"sources":["../src/utils.ts"],"sourcesContent":["export type ContractSchemaOptions = {\n title?: string\n description?: string\n}\n\nexport const applyNames = <T extends Record<string, { serviceName?: string }>>(\n params: T,\n opts: { serviceName?: string; subscriptionName?: string },\n) => {\n return Object.fromEntries(\n Object.entries(params).map(([k, v]) => [k, { ...v, name: k, ...opts }]),\n )\n}\n\nexport const createSchema = <T>(schema: T) => Object.freeze(schema) as T\n"],"version":3,"file":"utils.js"}
|