@nmtjs/contract 0.12.5 → 0.12.7

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.
@@ -0,0 +1 @@
1
+ export declare const Kind: unique symbol;
package/dist/constants.js CHANGED
@@ -1,3 +1 @@
1
- export const Kind = Symbol.for("neemata:kind");
2
-
3
- //# sourceMappingURL=constants.js.map
1
+ export const Kind = Symbol.for('neemata:kind');
@@ -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 let contract;
13
- (function(_contract) {
14
- const procedure = _contract.procedure = ProcedureContract;
15
- const event = _contract.event = EventContract;
16
- const subscription = _contract.subscription = SubscriptionContract;
17
- const namespace = _contract.namespace = NamespaceContract;
18
- const api = _contract.api = APIContract;
19
- const blob = _contract.blob = BlobType;
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;
@@ -1,47 +1,45 @@
1
1
  import { Kind } from "../constants.js";
2
2
  import { createSchema } from "../utils.js";
3
- export const APIKind = Symbol("NeemataAPI");
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
- }
35
- return createSchema({
36
- ...schemaOptions,
37
- [Kind]: APIKind,
38
- type: "neemata:api",
39
- namespaces: _namespaces,
40
- timeout
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
- return Kind in value && value[Kind] === APIKind;
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;
@@ -1,21 +1,19 @@
1
- import { t } from "@nmtjs/type";
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("NeemataEvent");
4
+ export const EventKind = Symbol('NeemataEvent');
5
5
  export const EventContract = (options) => {
6
- const { payload = t.never(), schemaOptions = {}, name } = options ?? {};
7
- return createSchema({
8
- ...schemaOptions,
9
- [Kind]: EventKind,
10
- type: "neemata:event",
11
- payload,
12
- name,
13
- subscription: undefined,
14
- namespace: undefined
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
- return Kind in value && value[Kind] === EventKind;
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("NeemataNamespace");
3
+ export const NamespaceKind = Symbol('NeemataNamespace');
4
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,
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,
22
- namespace: options?.name
23
- });
24
- }
25
- return createSchema({
26
- ...schemaOptions,
27
- [Kind]: NamespaceKind,
28
- type: "neemata:namespace",
29
- name,
30
- procedures,
31
- events,
32
- timeout
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
- return Kind in value && value[Kind] === NamespaceKind;
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 "@nmtjs/type";
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("NeemataProcedure");
4
+ export const ProcedureKind = Symbol('NeemataProcedure');
5
5
  export const ProcedureContract = (options) => {
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
- });
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
- return Kind in contract && contract[Kind] === ProcedureKind;
20
+ return Kind in contract && contract[Kind] === ProcedureKind;
21
21
  }
22
22
  export function IsStreamProcedureContract(contract) {
23
- return IsProcedureContract(contract) && typeof contract.stream !== "undefined";
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("NeemataSubscription");
3
+ export const SubscriptionKind = Symbol('NeemataSubscription');
4
4
  const _SubscriptionContract = (options) => {
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,
22
- options: undefined
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, { withOptions: () => {
26
- return (options) => _SubscriptionContract(options);
27
- } });
25
+ export const SubscriptionContract = Object.assign(_SubscriptionContract, {
26
+ withOptions: () => {
27
+ return (options) => _SubscriptionContract(options);
28
+ },
29
+ });
28
30
  export function IsSubscriptionContract(contract) {
29
- return Kind in contract && contract[Kind] === SubscriptionKind;
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>;
@@ -1,17 +1,16 @@
1
- import { t } from "@nmtjs/type";
1
+ import { t } from '@nmtjs/type';
2
2
  export const BlobType = (options = {}) => t.custom({
3
- decode: (value) => {
4
- if ("metadata" in value) {
5
- if (options.maxSize) {
6
- const size = value.metadata.size;
7
- if (typeof size !== "undefined" && size > options.maxSize) {
8
- throw new Error("Blob size unknown or exceeds maximum allowed size");
9
- }
10
- }
11
- }
12
- return value;
13
- },
14
- encode: (value) => value
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
@@ -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
- return Object.fromEntries(Object.entries(params).map(([k, v]) => [k, {
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,23 +3,23 @@
3
3
  "type": "module",
4
4
  "exports": {
5
5
  ".": {
6
+ "types": "./dist/index.d.ts",
6
7
  "import": "./dist/index.js",
7
- "types": "./src/index.ts"
8
+ "module-sync": "./dist/index.js"
8
9
  }
9
10
  },
10
11
  "dependencies": {
11
- "@nmtjs/protocol": "0.12.5",
12
- "@nmtjs/type": "0.12.5"
12
+ "@nmtjs/protocol": "0.12.7",
13
+ "@nmtjs/type": "0.12.7"
13
14
  },
14
15
  "files": [
15
- "src",
16
16
  "dist",
17
17
  "LICENSE.md",
18
18
  "README.md"
19
19
  ],
20
- "version": "0.12.5",
20
+ "version": "0.12.7",
21
21
  "scripts": {
22
- "build": "neemata-build --root=./src './**/*.ts'",
22
+ "build": "tsc",
23
23
  "type-check": "tsc --noEmit"
24
24
  }
25
25
  }
@@ -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"}
@@ -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"}
@@ -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"}
package/src/constants.ts DELETED
@@ -1 +0,0 @@
1
- export const Kind = Symbol.for('neemata:kind')
package/src/index.ts DELETED
@@ -1,25 +0,0 @@
1
- import { APIContract } from './schemas/api.ts'
2
- import { EventContract } from './schemas/event.ts'
3
- import { NamespaceContract } from './schemas/namespace.ts'
4
- import { ProcedureContract } from './schemas/procedure.ts'
5
- import { SubscriptionContract } from './schemas/subscription.ts'
6
- import { BlobType } from './types/blob.ts'
7
-
8
- export * from './schemas/api.ts'
9
- export * from './schemas/event.ts'
10
- export * from './schemas/namespace.ts'
11
- export * from './schemas/procedure.ts'
12
- export * from './schemas/subscription.ts'
13
-
14
- export namespace contract {
15
- export const procedure = ProcedureContract
16
- export const event = EventContract
17
- export const subscription = SubscriptionContract
18
- export const namespace = NamespaceContract
19
- export const api = APIContract
20
- export const blob = BlobType
21
- }
22
-
23
- export { contract as c }
24
-
25
- export default contract
@@ -1,104 +0,0 @@
1
- import { Kind } from '../constants.ts'
2
- import { type ContractSchemaOptions, createSchema } from '../utils.ts'
3
- import type { TEventContract } from './event.ts'
4
- import type { TAnyNamespaceContract, TNamespaceContract } from './namespace.ts'
5
- import type { TProcedureContract } from './procedure.ts'
6
-
7
- export const APIKind = Symbol('NeemataAPI')
8
-
9
- export type TAnyAPIContract = TAPIContract<
10
- Record<string, TAnyNamespaceContract>
11
- >
12
-
13
- export interface TAPIContract<
14
- Namespaces extends Record<string, TAnyNamespaceContract> = {},
15
- > {
16
- readonly [Kind]: typeof APIKind
17
- readonly type: 'neemata:api'
18
- readonly namespaces: {
19
- [K in keyof Namespaces]: TNamespaceContract<
20
- Namespaces[K]['procedures'],
21
- Namespaces[K]['events'],
22
- Extract<K, string>
23
- >
24
- }
25
- readonly timeout?: number
26
- }
27
-
28
- export const APIContract = <
29
- const Options extends {
30
- namespaces: Record<string, TAnyNamespaceContract>
31
- timeout?: number
32
- schemaOptions?: ContractSchemaOptions
33
- },
34
- >(
35
- options: Options,
36
- ) => {
37
- const { timeout, schemaOptions } = options
38
-
39
- const _namespaces = {} as any
40
-
41
- for (const namespaceKey in options.namespaces) {
42
- const namespace = options.namespaces[namespaceKey]
43
- const _procedures = {} as any
44
- for (const procedureKey in namespace.procedures) {
45
- const procedure = namespace.procedures[procedureKey]
46
- _procedures[procedureKey] = createSchema<
47
- TProcedureContract<
48
- (typeof procedure)['input'],
49
- (typeof procedure)['output'],
50
- (typeof procedure)['stream'],
51
- Extract<typeof procedureKey, string>,
52
- Extract<typeof namespaceKey, string>
53
- >
54
- >({
55
- ...procedure,
56
- name: procedureKey,
57
- namespace: namespaceKey,
58
- })
59
- }
60
-
61
- const _events = {} as any
62
- for (const eventKey in namespace.events) {
63
- const event = namespace.events[eventKey]
64
- _events[eventKey] = createSchema<
65
- TEventContract<
66
- (typeof event)['payload'],
67
- Extract<typeof eventKey, string>,
68
- undefined,
69
- Extract<typeof namespaceKey, string>
70
- >
71
- >({
72
- ...event,
73
- subscription: undefined,
74
- name: eventKey,
75
- namespace: namespaceKey,
76
- })
77
- }
78
-
79
- _namespaces[namespaceKey] = createSchema<
80
- TNamespaceContract<
81
- typeof _procedures,
82
- typeof _events,
83
- Extract<typeof namespaceKey, string>
84
- >
85
- >({
86
- ...namespace,
87
- procedures: _procedures,
88
- events: _events,
89
- name: namespaceKey,
90
- })
91
- }
92
-
93
- return createSchema<TAPIContract<Options['namespaces']>>({
94
- ...schemaOptions,
95
- [Kind]: APIKind,
96
- type: 'neemata:api',
97
- namespaces: _namespaces,
98
- timeout,
99
- })
100
- }
101
-
102
- export function IsAPIContract(value: any): value is TAnyAPIContract {
103
- return Kind in value && value[Kind] === APIKind
104
- }
@@ -1,54 +0,0 @@
1
- import { type BaseType, t } from '@nmtjs/type'
2
- import { Kind } from '../constants.ts'
3
- import { type ContractSchemaOptions, createSchema } from '../utils.ts'
4
-
5
- export const EventKind = Symbol('NeemataEvent')
6
-
7
- export type TAnyEventContract = TEventContract<
8
- BaseType,
9
- string | undefined,
10
- string | undefined,
11
- string | undefined
12
- >
13
-
14
- export interface TEventContract<
15
- Payload extends BaseType = t.NeverType,
16
- Name extends string | undefined = undefined,
17
- Subscription extends string | undefined = undefined,
18
- Namespace extends string | undefined = undefined,
19
- > {
20
- readonly [Kind]: typeof EventKind
21
- readonly type: 'neemata:event'
22
- readonly name: Name
23
- readonly subscription: Subscription
24
- readonly namespace: Namespace
25
- readonly payload: Payload
26
- }
27
-
28
- export const EventContract = <
29
- Payload extends BaseType,
30
- Name extends string | undefined = undefined,
31
- >(options?: {
32
- payload?: Payload
33
- schemaOptions?: ContractSchemaOptions
34
- name?: Name
35
- }) => {
36
- const {
37
- payload = t.never() as unknown as Payload,
38
- schemaOptions = {},
39
- name,
40
- } = options ?? {}
41
- return createSchema<TEventContract<Payload, Name>>({
42
- ...schemaOptions,
43
- [Kind]: EventKind,
44
- type: 'neemata:event',
45
- payload,
46
- name: name as Name,
47
- subscription: undefined,
48
- namespace: undefined,
49
- })
50
- }
51
-
52
- export function IsEventContract(value: any): value is TAnyEventContract {
53
- return Kind in value && value[Kind] === EventKind
54
- }
@@ -1,118 +0,0 @@
1
- import { Kind } from '../constants.ts'
2
- import { type ContractSchemaOptions, createSchema } from '../utils.ts'
3
- import type { TAnyEventContract, TEventContract } from './event.ts'
4
- import type { TAnyProcedureContract, TProcedureContract } from './procedure.ts'
5
-
6
- export const NamespaceKind = Symbol('NeemataNamespace')
7
-
8
- export type TAnyNamespaceContract<
9
- Procedures extends Record<string, TAnyProcedureContract> = Record<
10
- string,
11
- TAnyProcedureContract
12
- >,
13
- > = TNamespaceContract<
14
- Procedures,
15
- Record<string, TAnyEventContract>,
16
- string | undefined
17
- >
18
-
19
- export interface TNamespaceContract<
20
- Procedures extends Record<string, TAnyProcedureContract> = {},
21
- Events extends Record<string, TAnyEventContract> = {},
22
- Name extends string | undefined = undefined,
23
- > {
24
- readonly [Kind]: typeof NamespaceKind
25
- readonly type: 'neemata:namespace'
26
- readonly name: Name
27
- readonly procedures: {
28
- [K in keyof Procedures]: TProcedureContract<
29
- Procedures[K]['input'],
30
- Procedures[K]['output'],
31
- Procedures[K]['stream'],
32
- Extract<K, string>,
33
- Name
34
- >
35
- }
36
- readonly events: {
37
- [K in keyof Events]: TEventContract<
38
- Events[K]['payload'],
39
- Extract<K, string>,
40
- undefined,
41
- Name
42
- >
43
- }
44
- readonly timeout?: number
45
- }
46
-
47
- export const NamespaceContract = <
48
- const Options extends {
49
- procedures: Record<string, TAnyProcedureContract>
50
- events: Record<string, TAnyEventContract>
51
- name?: string
52
- timeout?: number
53
- schemaOptions?: ContractSchemaOptions
54
- },
55
- >(
56
- options: Options,
57
- ) => {
58
- const { name, timeout, schemaOptions = {} as ContractSchemaOptions } = options
59
- const events: Record<string, any> = {}
60
-
61
- for (const name in options.events) {
62
- const event = options.events[name]
63
- events[name] = createSchema<
64
- TEventContract<
65
- (typeof event)['payload'],
66
- Extract<typeof name, string>,
67
- undefined,
68
- Options['name'] extends string ? Options['name'] : undefined
69
- >
70
- >({
71
- ...event,
72
- subscription: undefined,
73
- name: name as any,
74
- namespace: options?.name as any,
75
- })
76
- }
77
-
78
- const procedures: Record<string, any> = {}
79
-
80
- for (const name in options.procedures) {
81
- const procedure: any = options.procedures[name]
82
- procedures[name] = createSchema<
83
- TProcedureContract<
84
- (typeof procedure)['input'],
85
- (typeof procedure)['output'],
86
- (typeof procedure)['stream'],
87
- Extract<typeof name, string>,
88
- Options['name'] extends string ? Options['name'] : undefined
89
- >
90
- >({
91
- ...procedure,
92
- name: name as any,
93
- namespace: options?.name as any,
94
- })
95
- }
96
-
97
- return createSchema<
98
- TNamespaceContract<
99
- Options['procedures'],
100
- Options['events'],
101
- Options['name'] extends string ? Options['name'] : undefined
102
- >
103
- >({
104
- ...schemaOptions,
105
- [Kind]: NamespaceKind,
106
- type: 'neemata:namespace',
107
- name: name as any,
108
- procedures: procedures as any,
109
- events: events as any,
110
- timeout,
111
- })
112
- }
113
-
114
- export function IsNamespaceContract(
115
- value: any,
116
- ): value is TAnyNamespaceContract {
117
- return Kind in value && value[Kind] === NamespaceKind
118
- }
@@ -1,82 +0,0 @@
1
- import { type BaseType, t } from '@nmtjs/type'
2
- import { Kind } from '../constants.ts'
3
- import { type ContractSchemaOptions, createSchema } from '../utils.ts'
4
-
5
- export type TAnyProcedureContract = TProcedureContract<
6
- BaseType,
7
- BaseType,
8
- BaseType | undefined,
9
- string | undefined,
10
- string | undefined
11
- >
12
-
13
- export const ProcedureKind = Symbol('NeemataProcedure')
14
-
15
- export interface TProcedureContract<
16
- Input extends BaseType,
17
- Output extends BaseType,
18
- Stream extends BaseType | undefined,
19
- Name extends string | undefined = undefined,
20
- Namespace extends string | undefined = undefined,
21
- > {
22
- readonly [Kind]: typeof ProcedureKind
23
- readonly type: 'neemata:procedure'
24
- readonly name: Name
25
- readonly namespace: Namespace
26
- readonly input: Input
27
- readonly output: Output
28
- readonly stream: Stream
29
- readonly timeout?: number
30
- }
31
-
32
- export const ProcedureContract = <
33
- const Options extends {
34
- input?: BaseType
35
- output?: BaseType
36
- stream?: BaseType | undefined
37
- timeout?: number
38
- schemaOptions?: ContractSchemaOptions
39
- name?: string
40
- },
41
- >(
42
- options: Options,
43
- ) => {
44
- const {
45
- input = t.never() as any,
46
- output = t.never() as any,
47
- stream = undefined as any,
48
- name = undefined as any,
49
- timeout,
50
- schemaOptions = {},
51
- } = options
52
- return createSchema<
53
- TProcedureContract<
54
- Options['input'] extends BaseType ? Options['input'] : t.NeverType,
55
- Options['output'] extends BaseType ? Options['output'] : t.NeverType,
56
- Options['stream'] extends BaseType ? Options['stream'] : undefined,
57
- Options['name'] extends string ? Options['name'] : undefined
58
- >
59
- >({
60
- ...schemaOptions,
61
- [Kind]: ProcedureKind,
62
- type: 'neemata:procedure',
63
- input,
64
- output,
65
- stream,
66
- name,
67
- timeout,
68
- namespace: undefined,
69
- })
70
- }
71
-
72
- export function IsProcedureContract(
73
- contract: any,
74
- ): contract is TAnyProcedureContract {
75
- return Kind in contract && contract[Kind] === ProcedureKind
76
- }
77
-
78
- export function IsStreamProcedureContract(
79
- contract: any,
80
- ): contract is TAnyProcedureContract {
81
- return IsProcedureContract(contract) && typeof contract.stream !== 'undefined'
82
- }
@@ -1,96 +0,0 @@
1
- import { Kind } from '../constants.ts'
2
- import { type ContractSchemaOptions, createSchema } from '../utils.ts'
3
- import type { TAnyEventContract, TEventContract } from './event.ts'
4
-
5
- export const SubscriptionKind = Symbol('NeemataSubscription')
6
-
7
- export type SubcriptionOptions = Record<
8
- string,
9
- string | number | boolean
10
- > | null
11
-
12
- export type TAnySubscriptionContract = TSubscriptionContract<
13
- SubcriptionOptions,
14
- Record<string, TAnyEventContract>,
15
- string | undefined
16
- >
17
-
18
- export interface TSubscriptionContract<
19
- Options extends SubcriptionOptions = null,
20
- Events extends Record<string, unknown> = {},
21
- Name extends string | undefined = undefined,
22
- > {
23
- readonly [Kind]: typeof SubscriptionKind
24
- readonly type: 'neemata:subscription'
25
- readonly name: Name
26
- readonly options: Options
27
- readonly events: {
28
- [K in keyof Events]: Events[K] extends TAnyEventContract
29
- ? TEventContract<Events[K]['payload'], Extract<K, string>, Name>
30
- : never
31
- }
32
- }
33
-
34
- const _SubscriptionContract = <
35
- const Options extends {
36
- events: Record<string, TAnyEventContract>
37
- name?: string
38
- schemaOptions?: ContractSchemaOptions
39
- },
40
- SubOpt extends SubcriptionOptions = null,
41
- >(
42
- options: Options,
43
- ) => {
44
- const { schemaOptions = {}, name } = options
45
- const _events = {} as any
46
- for (const key in options.events) {
47
- const event = options.events[key]
48
- _events[key] = createSchema<
49
- TEventContract<
50
- (typeof event)['payload'],
51
- Extract<typeof key, string>,
52
- undefined,
53
- Options['name'] extends string ? Options['name'] : undefined
54
- >
55
- >({
56
- ...event,
57
- name: key,
58
- namespace: undefined,
59
- subscription: name as any,
60
- })
61
- }
62
- return createSchema<
63
- TSubscriptionContract<
64
- SubOpt,
65
- Options['events'],
66
- Options['name'] extends string ? Options['name'] : undefined
67
- >
68
- >({
69
- ...schemaOptions,
70
- [Kind]: SubscriptionKind,
71
- type: 'neemata:subscription',
72
- events: _events,
73
- name: name as any,
74
- options: undefined as unknown as SubOpt,
75
- })
76
- }
77
-
78
- export const SubscriptionContract = Object.assign(_SubscriptionContract, {
79
- withOptions: <Options extends SubcriptionOptions>() => {
80
- return <
81
- T extends {
82
- events: Record<string, TAnyEventContract>
83
- name?: string
84
- schemaOptions?: ContractSchemaOptions
85
- },
86
- >(
87
- options: T,
88
- ) => _SubscriptionContract<T, Options>(options)
89
- },
90
- })
91
-
92
- export function IsSubscriptionContract(
93
- contract: any,
94
- ): contract is TAnySubscriptionContract {
95
- return Kind in contract && contract[Kind] === SubscriptionKind
96
- }
package/src/types/blob.ts DELETED
@@ -1,24 +0,0 @@
1
- import type { ProtocolBlobInterface } from '@nmtjs/protocol'
2
- import { t } from '@nmtjs/type'
3
-
4
- export interface BlobOptions {
5
- maxSize?: number
6
- contentType?: string
7
- }
8
-
9
- export const BlobType = (options: BlobOptions = {}) =>
10
- t.custom<ProtocolBlobInterface>({
11
- decode: (value) => {
12
- // TODO: here should be some validation logic to check if the value is an actual blob
13
- if ('metadata' in value) {
14
- if (options.maxSize) {
15
- const size = (value as ProtocolBlobInterface).metadata.size
16
- if (typeof size !== 'undefined' && size > options.maxSize) {
17
- throw new Error('Blob size unknown or exceeds maximum allowed size')
18
- }
19
- }
20
- }
21
- return value
22
- },
23
- encode: (value) => value,
24
- })
package/src/utils.ts DELETED
@@ -1,15 +0,0 @@
1
- export type ContractSchemaOptions = {
2
- title?: string
3
- description?: string
4
- }
5
-
6
- export const applyNames = <T extends Record<string, { serviceName?: string }>>(
7
- params: T,
8
- opts: { serviceName?: string; subscriptionName?: string },
9
- ) => {
10
- return Object.fromEntries(
11
- Object.entries(params).map(([k, v]) => [k, { ...v, name: k, ...opts }]),
12
- )
13
- }
14
-
15
- export const createSchema = <T>(schema: T) => Object.freeze(schema) as T