@nmtjs/contract 0.11.5 → 0.11.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.
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/namespace.js +1 -20
- package/dist/schemas/namespace.js.map +1 -1
- package/dist/schemas/procedure.js.map +1 -1
- package/dist/schemas/subscription.js +5 -7
- package/dist/schemas/subscription.js.map +1 -1
- package/package.json +3 -3
- package/src/schemas/api.ts +1 -1
- package/src/schemas/namespace.ts +1 -55
- package/src/schemas/procedure.ts +9 -33
- package/src/schemas/subscription.ts +15 -51
package/dist/schemas/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAGtE,OAAO,MAAM,UAAU;AAoBvB,OAAO,MAAM,cAAc,CAEzBA,YAII;CACJ,MAAM,EAAE,aAAa,CAAE,GAAE,UAAU,KAAM,gBAAgB,CAAE,GAAE,GAAG,WAAW,CAAE;CAE7E,MAAM,cAAc,CAAE;AAEtB,MAAK,MAAM,gBAAgB,YAAY;EACrC,MAAM,YAAY,WAAW;EAC7B,MAAM,cAAc,CAAE;AACtB,OAAK,MAAM,gBAAgB,UAAU,YAAY;GAC/C,MAAM,YAAY,UAAU,WAAW;AACvC,eAAY,gBAAgB,OAAO,OAAO,CAAE,GAAE,WAAW;IACvD,MAAM;IACN,WAAW;GACZ,EAAC;EACH;EAED,MAAM,iBAAiB,CAAE;AACzB,OAAK,MAAM,mBAAmB,UAAU,eAAe;GACrD,MAAM,eAAe,UAAU,cAAc;GAC7C,MAAM,UAAU,CAAE;AAClB,QAAK,MAAM,YAAY,aAAa,QAAQ;IAC1C,MAAM,QAAQ,aAAa,OAAO;AAClC,YAAQ,YAAY,OAAO,OAAO,CAAE,GAAE,OAAO;KAC3C,MAAM;KACN,WAAW;KACX,cAAc;IACf,EAAC;GACH;AACD,kBAAe,mBAAmB,OAAO,OAAO,CAAE,GAAE,cAAc;IAChE,MAAM;IACN,WAAW;IACX,QAAQ;GACT,EAAC;EACH;EAED,MAAM,UAAU,CAAE;AAClB,OAAK,MAAM,YAAY,UAAU,QAAQ;GACvC,MAAM,QAAQ,UAAU,OAAO;AAC/B,WAAQ,YAAY,OAAO,OAAO,CAAE,GAAE,OAAO;IAC3C,MAAM;IACN,WAAW;GACZ,EAAC;EACH;AAED,cAAY,gBAAgB,OAAO,OAAO,CAAE,GAAE,WAAW;GACvD,MAAM;GACN,YAAY;GACZ,eAAe;GACf,QAAQ;EACT,EAAC;CACH;AAED,QAAO,aAAuC;EAC5C,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?: {\n namespaces?: Namespaces\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n}","value: any"],"sources":["../../src/schemas/api.ts"],"sourcesContent":["import { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TAnyNamespaceContract, TNamespaceContract } from './namespace.ts'\n\nexport const APIKind = 'NeemataAPI'\n\nexport type TAnyAPIContract = TAPIContract<Record<string, any>>\n\nexport interface TAPIContract<Namespaces extends Record<string, unknown> = {}> {\n [Kind]: typeof APIKind\n type: 'neemata:api'\n namespaces: {\n [K in keyof Namespaces]: Namespaces[K] extends TAnyNamespaceContract\n ? TNamespaceContract<\n Namespaces[K]['procedures'],\n Namespaces[K]['subscriptions'],\n Namespaces[K]['events'],\n Extract<K, string>\n >\n : never\n }\n timeout?: number\n}\n\nexport const APIContract = <\n Namespaces extends Record<string, unknown> = {},\n>(options?: {\n namespaces?: Namespaces\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n}) => {\n const { namespaces = {}, timeout = 1000, schemaOptions = {} } = options || {}\n\n const _namespaces = {} as any\n\n for (const namespaceKey in namespaces) {\n const namespace = namespaces[namespaceKey]\n const _procedures = {} as any\n for (const procedureKey in namespace.procedures) {\n const procedure = namespace.procedures[procedureKey]\n _procedures[procedureKey] = Object.assign({}, procedure, {\n name: procedureKey,\n namespace: namespaceKey,\n })\n }\n\n const _subscriptions = {} as any\n for (const subscriptionKey in namespace.subscriptions) {\n const subscription = namespace.subscriptions[subscriptionKey]\n const _events = {} as any\n for (const eventKey in subscription.events) {\n const event = subscription.events[eventKey]\n _events[eventKey] = Object.assign({}, event, {\n name: eventKey,\n namespace: namespaceKey,\n subscription: subscriptionKey,\n })\n }\n _subscriptions[subscriptionKey] = Object.assign({}, subscription, {\n name: subscriptionKey,\n namespace: namespaceKey,\n events: _events,\n })\n }\n\n const _events = {} as any\n for (const eventKey in namespace.events) {\n const event = namespace.events[eventKey]\n _events[eventKey] = Object.assign({}, event, {\n name: eventKey,\n namespace: namespaceKey,\n })\n }\n\n _namespaces[namespaceKey] = Object.assign({}, namespace, {\n name: namespaceKey,\n procedures: _procedures,\n subscriptions: _subscriptions,\n events: _events,\n })\n }\n\n return createSchema<TAPIContract<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
|
+
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAGtE,OAAO,MAAM,UAAU;AAoBvB,OAAO,MAAM,cAAc,CAEzBA,YAII;CACJ,MAAM,EAAE,aAAa,CAAE,GAAE,UAAU,KAAM,gBAAgB,CAAE,GAAE,GAAG,WAAW,CAAE;CAE7E,MAAM,cAAc,CAAE;AAEtB,MAAK,MAAM,gBAAgB,YAAY;EACrC,MAAM,YAAY,WAAW;EAC7B,MAAM,cAAc,CAAE;AACtB,OAAK,MAAM,gBAAgB,UAAU,YAAY;GAC/C,MAAM,YAAY,UAAU,WAAW;AACvC,eAAY,gBAAgB,OAAO,OAAO,CAAE,GAAE,WAAW;IACvD,MAAM;IACN,WAAW;GACZ,EAAC;EACH;EAED,MAAM,iBAAiB,CAAE;AACzB,OAAK,MAAM,mBAAmB,UAAU,eAAe;GACrD,MAAM,eAAe,UAAU,cAAc;GAC7C,MAAM,UAAU,CAAE;AAClB,QAAK,MAAM,YAAY,aAAa,QAAQ;IAC1C,MAAM,QAAQ,aAAa,OAAO;AAClC,YAAQ,YAAY,OAAO,OAAO,CAAE,GAAE,OAAO;KAC3C,MAAM;KACN,WAAW;KACX,cAAc;IACf,EAAC;GACH;AACD,kBAAe,mBAAmB,OAAO,OAAO,CAAE,GAAE,cAAc;IAChE,MAAM;IACN,WAAW;IACX,QAAQ;GACT,EAAC;EACH;EAED,MAAM,UAAU,CAAE;AAClB,OAAK,MAAM,YAAY,UAAU,QAAQ;GACvC,MAAM,QAAQ,UAAU,OAAO;AAC/B,WAAQ,YAAY,OAAO,OAAO,CAAE,GAAE,OAAO;IAC3C,MAAM;IACN,WAAW;GACZ,EAAC;EACH;AAED,cAAY,gBAAgB,OAAO,OAAO,CAAE,GAAE,WAAW;GACvD,MAAM;GACN,YAAY;GACZ,eAAe;GACf,QAAQ;EACT,EAAC;CACH;AAED,QAAO,aAAuC;EAC5C,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?: {\n namespaces?: Namespaces\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n}","value: any"],"sources":["../../src/schemas/api.ts"],"sourcesContent":["import { Kind } from '../constants.ts'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TAnyNamespaceContract, TNamespaceContract } from './namespace.ts'\n\nexport const APIKind = 'NeemataAPI'\n\nexport type TAnyAPIContract = TAPIContract<Record<string, any>>\n\nexport interface TAPIContract<Namespaces extends Record<string, unknown> = {}> {\n [Kind]: typeof APIKind\n type: 'neemata:api'\n namespaces: {\n [K in keyof Namespaces]: Namespaces[K] extends TAnyNamespaceContract\n ? TNamespaceContract<\n Namespaces[K]['procedures'],\n // Namespaces[K]['subscriptions'],\n Namespaces[K]['events'],\n Extract<K, string>\n >\n : never\n }\n timeout?: number\n}\n\nexport const APIContract = <\n Namespaces extends Record<string, unknown> = {},\n>(options?: {\n namespaces?: Namespaces\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n}) => {\n const { namespaces = {}, timeout = 1000, schemaOptions = {} } = options || {}\n\n const _namespaces = {} as any\n\n for (const namespaceKey in namespaces) {\n const namespace = namespaces[namespaceKey]\n const _procedures = {} as any\n for (const procedureKey in namespace.procedures) {\n const procedure = namespace.procedures[procedureKey]\n _procedures[procedureKey] = Object.assign({}, procedure, {\n name: procedureKey,\n namespace: namespaceKey,\n })\n }\n\n const _subscriptions = {} as any\n for (const subscriptionKey in namespace.subscriptions) {\n const subscription = namespace.subscriptions[subscriptionKey]\n const _events = {} as any\n for (const eventKey in subscription.events) {\n const event = subscription.events[eventKey]\n _events[eventKey] = Object.assign({}, event, {\n name: eventKey,\n namespace: namespaceKey,\n subscription: subscriptionKey,\n })\n }\n _subscriptions[subscriptionKey] = Object.assign({}, subscription, {\n name: subscriptionKey,\n namespace: namespaceKey,\n events: _events,\n })\n }\n\n const _events = {} as any\n for (const eventKey in namespace.events) {\n const event = namespace.events[eventKey]\n _events[eventKey] = Object.assign({}, event, {\n name: eventKey,\n namespace: namespaceKey,\n })\n }\n\n _namespaces[namespaceKey] = Object.assign({}, namespace, {\n name: namespaceKey,\n procedures: _procedures,\n subscriptions: _subscriptions,\n events: _events,\n })\n }\n\n return createSchema<TAPIContract<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"}
|
|
@@ -2,7 +2,7 @@ import { Kind } from "../constants.js";
|
|
|
2
2
|
import { createSchema } from "../utils.js";
|
|
3
3
|
export const NamespaceKind = "NeemataNamespace";
|
|
4
4
|
export const NamespaceContract = (options) => {
|
|
5
|
-
const { procedures = {},
|
|
5
|
+
const { procedures = {}, events = {}, name, timeout, schemaOptions = {} } = options ?? {};
|
|
6
6
|
const _events = {};
|
|
7
7
|
for (const eventKey in events) {
|
|
8
8
|
const event = events[eventKey];
|
|
@@ -19,31 +19,12 @@ export const NamespaceContract = (options) => {
|
|
|
19
19
|
namespace: options?.name
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
const _subscriptions = {};
|
|
23
|
-
for (const subscriptionKey in subscriptions) {
|
|
24
|
-
const subscription = subscriptions[subscriptionKey];
|
|
25
|
-
const _events = {};
|
|
26
|
-
for (const eventKey in subscription.events) {
|
|
27
|
-
const event = subscription.events[eventKey];
|
|
28
|
-
_events[eventKey] = Object.assign({}, event, {
|
|
29
|
-
name: eventKey,
|
|
30
|
-
subscription: subscriptionKey,
|
|
31
|
-
namespace: options?.name
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
_subscriptions[subscriptionKey] = Object.assign({}, subscription, {
|
|
35
|
-
name: subscriptionKey,
|
|
36
|
-
namespace: options?.name,
|
|
37
|
-
events: _events
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
22
|
return createSchema({
|
|
41
23
|
...schemaOptions,
|
|
42
24
|
[Kind]: NamespaceKind,
|
|
43
25
|
type: "neemata:namespace",
|
|
44
26
|
name,
|
|
45
27
|
procedures: _procedures,
|
|
46
|
-
subscriptions: _subscriptions,
|
|
47
28
|
events: _events,
|
|
48
29
|
timeout
|
|
49
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;
|
|
1
|
+
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAItE,OAAO,MAAM,gBAAgB;AAwC7B,OAAO,MAAM,oBAAoB,CAI/BA,YAMI;CACJ,MAAM,EACJ,aAAa,CAAE,GACf,SAAS,CAAE,GACX,MACA,SACA,gBAAgB,CAAE,GACnB,GAAG,WAAW,CAAE;CACjB,MAAM,UAAU,CAAE;AAElB,MAAK,MAAM,YAAY,QAAQ;EAC7B,MAAM,QAAQ,OAAO;AACrB,UAAQ,YAAY,OAAO,OAAO,CAAE,GAAE,OAAO;GAC3C,MAAM;GACN,WAAW,SAAS;EACrB,EAAC;CACH;CAED,MAAM,cAAc,CAAE;AACtB,MAAK,MAAM,gBAAgB,YAAY;EACrC,MAAMC,YAAiB,WAAW;AAClC,cAAY,gBAAgB,OAAO,OAAO,CAAE,GAAE,WAAW;GACvD,MAAM;GACN,WAAW,SAAS;EACrB,EAAC;CACH;AAED,QAAO,aAA2D;EAChE,GAAG;GACF,OAAO;EACR,MAAM;EACA;EACN,YAAY;EACZ,QAAQ;EACR;CACD,EAAC;AACH;AAED,OAAO,SAAS,oBACdC,OACgC;AAChC,QAAO,QAAQ,SAAS,MAAM,UAAU;AACzC","names":["options?: {\n procedures?: Procedures\n events?: Events\n name?: Name\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n}","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 = 'NeemataNamespace'\n\nexport type TAnyNamespaceContract = TNamespaceContract<\n Record<string, any>,\n Record<string, any>,\n string | undefined\n>\n\nexport interface TNamespaceContract<\n Procedures extends Record<string, unknown> = {},\n Events extends Record<string, unknown> = {},\n Name extends string | undefined = undefined,\n> {\n [Kind]: typeof NamespaceKind\n type: 'neemata:namespace'\n name: Name\n procedures: {\n [K in keyof Procedures]: Procedures[K] extends TAnyProcedureContract\n ? TProcedureContract<\n Procedures[K]['input'],\n Procedures[K]['output'],\n Procedures[K]['stream'],\n Extract<K, string>,\n Name\n >\n : never\n }\n events: {\n [K in keyof Events]: Events[K] extends TAnyEventContract\n ? TEventContract<\n Events[K]['payload'],\n Extract<K, string>,\n undefined,\n Name\n >\n : never\n }\n timeout?: number\n}\n\nexport const NamespaceContract = <\n Procedures extends Record<string, unknown> = {},\n Events extends Record<string, unknown> = {},\n Name extends string | undefined = undefined,\n>(options?: {\n procedures?: Procedures\n events?: Events\n name?: Name\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n}) => {\n const {\n procedures = {} as Procedures,\n events = {} as Events,\n name,\n timeout,\n schemaOptions = {} as ContractSchemaOptions,\n } = options ?? {}\n const _events = {} as any\n\n for (const eventKey in events) {\n const event = events[eventKey]\n _events[eventKey] = Object.assign({}, event, {\n name: eventKey,\n namespace: options?.name,\n })\n }\n\n const _procedures = {} as any\n for (const procedureKey in procedures) {\n const procedure: any = procedures[procedureKey]\n _procedures[procedureKey] = Object.assign({}, procedure, {\n name: procedureKey,\n namespace: options?.name,\n })\n }\n\n return createSchema<TNamespaceContract<Procedures, Events, Name>>({\n ...schemaOptions,\n [Kind]: NamespaceKind,\n type: 'neemata:namespace',\n name: name as Name,\n procedures: _procedures,\n events: _events,\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 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAwB,SAAS,aAAa;AAC9C,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;
|
|
1
|
+
{"mappings":"AAAA,SAAwB,SAAS,aAAa;AAC9C,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAUtE,OAAO,MAAM,gBAAgB;AAmB7B,OAAO,MAAM,oBAAoB,CAK/BA,YAOI;CACJ,MAAM,EACJ,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,OAAO,EAClB,SACA,gBAAgB,CAAE,GAClB,MACD,GAAG;AACJ,QAAO,aAA8D;EACnE,GAAG;GACF,OAAO;EACR,MAAM;EACN;EACA;EACA;EACA;EACM;EACN,WAAW;CACZ,EAAC;AACH;AAED,OAAO,SAAS,oBACdC,UACmC;AACnC,QAAO,QAAQ,YAAY,SAAS,UAAU;AAC/C","names":["options: {\n input?: Input\n output?: Output\n stream?: Stream\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n name?: Name\n}","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,\n string | undefined,\n string | undefined\n>\n\nexport const ProcedureKind = 'NeemataProcedure'\n\nexport interface TProcedureContract<\n Input extends BaseType = t.NeverType,\n Output extends BaseType = t.NeverType,\n Stream extends BaseType = t.NeverType,\n Name extends string | undefined = undefined,\n Namespace extends string | undefined = undefined,\n> {\n [Kind]: typeof ProcedureKind\n type: 'neemata:procedure'\n name: Name\n namespace: Namespace\n input: Input\n output: Output\n timeout?: number\n stream: Stream\n}\n\nexport const ProcedureContract = <\n Input extends BaseType = t.NeverType,\n Output extends BaseType = t.NeverType,\n Stream extends BaseType = t.NeverType,\n Name extends string | undefined = undefined,\n>(options: {\n input?: Input\n output?: Output\n stream?: Stream\n timeout?: number\n schemaOptions?: ContractSchemaOptions\n name?: Name\n}) => {\n const {\n input = t.never() as unknown as Input,\n output = t.never() as unknown as Output,\n stream = t.never() as unknown as Stream,\n timeout,\n schemaOptions = {},\n name,\n } = options\n return createSchema<TProcedureContract<Input, Output, Stream, Name>>({\n ...schemaOptions,\n [Kind]: ProcedureKind,\n type: 'neemata:procedure',\n input,\n output,\n stream,\n timeout,\n name: name as Name,\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"],"version":3,"file":"procedure.js"}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { t } from "@nmtjs/type";
|
|
2
1
|
import { Kind } from "../constants.js";
|
|
3
2
|
import { createSchema } from "../utils.js";
|
|
4
3
|
export const SubscriptionKind = "NeemataSubscription";
|
|
5
4
|
export const SubscriptionContract = (options) => {
|
|
6
|
-
const {
|
|
5
|
+
const { events = {}, schemaOptions = {}, name } = options ?? {};
|
|
7
6
|
const _events = {};
|
|
8
7
|
for (const key in events) {
|
|
9
8
|
const event = events[key];
|
|
10
|
-
_events[key] = Object.assign({}, event, {
|
|
9
|
+
_events[key] = Object.assign({}, event, {
|
|
10
|
+
name: key,
|
|
11
|
+
subscription: name
|
|
12
|
+
});
|
|
11
13
|
}
|
|
12
14
|
return { $withOptions: () => createSchema({
|
|
13
15
|
...schemaOptions,
|
|
14
16
|
[Kind]: SubscriptionKind,
|
|
15
17
|
type: "neemata:subscription",
|
|
16
|
-
input,
|
|
17
|
-
output,
|
|
18
18
|
events: _events,
|
|
19
|
-
timeout,
|
|
20
19
|
name,
|
|
21
|
-
namespace: undefined,
|
|
22
20
|
options: undefined
|
|
23
21
|
}) };
|
|
24
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAGtE,OAAO,MAAM,mBAAmB;AA0BhC,OAAO,MAAM,uBAAuB,CAGlCA,YAII;CACJ,MAAM,EAAE,SAAS,CAAE,GAAY,gBAAgB,CAAE,GAAE,MAAM,GAAG,WAAW,CAAE;CACzE,MAAM,UAAU,CAAE;AAClB,MAAK,MAAM,OAAO,QAAQ;EACxB,MAAM,QAAQ,OAAO;AACrB,UAAQ,OAAO,OAAO,OAAO,CAAE,GAAE,OAAO;GAAE,MAAM;GAAK,cAAc;EAAM,EAAC;CAC3E;AACD,QAAO,EACL,cAAc,MACZ,aAA2D;EACzD,GAAG;GACF,OAAO;EACR,MAAM;EACN,QAAQ;EACF;EACN,SAAS;CACV,EAAC,CACL;AACF;AAED,OAAO,SAAS,uBACdC,UACsC;AACtC,QAAO,QAAQ,YAAY,SAAS,UAAU;AAC/C","names":["options?: {\n events?: Events\n schemaOptions?: ContractSchemaOptions\n name?: Name\n}","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 = 'NeemataSubscription'\n\nexport type SubcriptionOptions = Record<string, string | number | boolean>\n\nexport type TAnySubscriptionContract = TSubscriptionContract<\n SubcriptionOptions,\n Record<string, TAnyEventContract>,\n string | undefined\n>\n\nexport interface TSubscriptionContract<\n Options extends SubcriptionOptions = {},\n Events extends Record<string, unknown> = {},\n Name extends string | undefined = undefined,\n> {\n [Kind]: typeof SubscriptionKind\n type: 'neemata:subscription'\n name: Name\n options: Options\n events: {\n [K in keyof Events]: Events[K] extends TAnyEventContract\n ? TEventContract<Events[K]['payload'], Extract<K, string>, Name>\n : never\n }\n}\n\nexport const SubscriptionContract = <\n Events extends Record<string, unknown> = {},\n Name extends string | undefined = undefined,\n>(options?: {\n events?: Events\n schemaOptions?: ContractSchemaOptions\n name?: Name\n}) => {\n const { events = {} as Events, schemaOptions = {}, name } = options ?? {}\n const _events = {} as any\n for (const key in events) {\n const event = events[key]\n _events[key] = Object.assign({}, event, { name: key, subscription: name })\n }\n return {\n $withOptions: <Options extends SubcriptionOptions>() =>\n createSchema<TSubscriptionContract<Options, Events, Name>>({\n ...schemaOptions,\n [Kind]: SubscriptionKind,\n type: 'neemata:subscription',\n events: _events,\n name: name as Name,\n options: undefined as unknown as Options,\n }),\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/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nmtjs/protocol": "0.11.
|
|
12
|
-
"@nmtjs/type": "0.11.
|
|
11
|
+
"@nmtjs/protocol": "0.11.7",
|
|
12
|
+
"@nmtjs/type": "0.11.7"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"src",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"LICENSE.md",
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
|
-
"version": "0.11.
|
|
20
|
+
"version": "0.11.7",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "neemata-build --root=./src './**/*.ts'",
|
|
23
23
|
"type-check": "tsc --noEmit"
|
package/src/schemas/api.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface TAPIContract<Namespaces extends Record<string, unknown> = {}> {
|
|
|
13
13
|
[K in keyof Namespaces]: Namespaces[K] extends TAnyNamespaceContract
|
|
14
14
|
? TNamespaceContract<
|
|
15
15
|
Namespaces[K]['procedures'],
|
|
16
|
-
Namespaces[K]['subscriptions'],
|
|
16
|
+
// Namespaces[K]['subscriptions'],
|
|
17
17
|
Namespaces[K]['events'],
|
|
18
18
|
Extract<K, string>
|
|
19
19
|
>
|
package/src/schemas/namespace.ts
CHANGED
|
@@ -2,15 +2,10 @@ import { Kind } from '../constants.ts'
|
|
|
2
2
|
import { type ContractSchemaOptions, createSchema } from '../utils.ts'
|
|
3
3
|
import type { TAnyEventContract, TEventContract } from './event.ts'
|
|
4
4
|
import type { TAnyProcedureContract, TProcedureContract } from './procedure.ts'
|
|
5
|
-
import type {
|
|
6
|
-
TAnySubscriptionContract,
|
|
7
|
-
TSubscriptionContract,
|
|
8
|
-
} from './subscription.ts'
|
|
9
5
|
|
|
10
6
|
export const NamespaceKind = 'NeemataNamespace'
|
|
11
7
|
|
|
12
8
|
export type TAnyNamespaceContract = TNamespaceContract<
|
|
13
|
-
Record<string, any>,
|
|
14
9
|
Record<string, any>,
|
|
15
10
|
Record<string, any>,
|
|
16
11
|
string | undefined
|
|
@@ -18,7 +13,6 @@ export type TAnyNamespaceContract = TNamespaceContract<
|
|
|
18
13
|
|
|
19
14
|
export interface TNamespaceContract<
|
|
20
15
|
Procedures extends Record<string, unknown> = {},
|
|
21
|
-
Subscriptions extends Record<string, unknown> = {},
|
|
22
16
|
Events extends Record<string, unknown> = {},
|
|
23
17
|
Name extends string | undefined = undefined,
|
|
24
18
|
> {
|
|
@@ -36,27 +30,6 @@ export interface TNamespaceContract<
|
|
|
36
30
|
>
|
|
37
31
|
: never
|
|
38
32
|
}
|
|
39
|
-
subscriptions: {
|
|
40
|
-
[K in keyof Subscriptions]: Subscriptions[K] extends TAnySubscriptionContract
|
|
41
|
-
? TSubscriptionContract<
|
|
42
|
-
Subscriptions[K]['input'],
|
|
43
|
-
Subscriptions[K]['output'],
|
|
44
|
-
Subscriptions[K]['options'],
|
|
45
|
-
{
|
|
46
|
-
[E in keyof Subscriptions[K]['events']]: Subscriptions[K]['events'][E] extends TAnyEventContract
|
|
47
|
-
? TEventContract<
|
|
48
|
-
Subscriptions[K]['events'][E]['payload'],
|
|
49
|
-
Extract<E, string>,
|
|
50
|
-
Extract<K, string>,
|
|
51
|
-
Name
|
|
52
|
-
>
|
|
53
|
-
: never
|
|
54
|
-
},
|
|
55
|
-
Extract<K, string>,
|
|
56
|
-
Name
|
|
57
|
-
>
|
|
58
|
-
: never
|
|
59
|
-
}
|
|
60
33
|
events: {
|
|
61
34
|
[K in keyof Events]: Events[K] extends TAnyEventContract
|
|
62
35
|
? TEventContract<
|
|
@@ -72,12 +45,10 @@ export interface TNamespaceContract<
|
|
|
72
45
|
|
|
73
46
|
export const NamespaceContract = <
|
|
74
47
|
Procedures extends Record<string, unknown> = {},
|
|
75
|
-
Subscriptions extends Record<string, unknown> = {},
|
|
76
48
|
Events extends Record<string, unknown> = {},
|
|
77
49
|
Name extends string | undefined = undefined,
|
|
78
50
|
>(options?: {
|
|
79
51
|
procedures?: Procedures
|
|
80
|
-
subscriptions?: Subscriptions
|
|
81
52
|
events?: Events
|
|
82
53
|
name?: Name
|
|
83
54
|
timeout?: number
|
|
@@ -85,7 +56,6 @@ export const NamespaceContract = <
|
|
|
85
56
|
}) => {
|
|
86
57
|
const {
|
|
87
58
|
procedures = {} as Procedures,
|
|
88
|
-
subscriptions = {} as Subscriptions,
|
|
89
59
|
events = {} as Events,
|
|
90
60
|
name,
|
|
91
61
|
timeout,
|
|
@@ -110,36 +80,12 @@ export const NamespaceContract = <
|
|
|
110
80
|
})
|
|
111
81
|
}
|
|
112
82
|
|
|
113
|
-
|
|
114
|
-
for (const subscriptionKey in subscriptions) {
|
|
115
|
-
const subscription: any = subscriptions[subscriptionKey]
|
|
116
|
-
const _events = {} as any
|
|
117
|
-
|
|
118
|
-
for (const eventKey in subscription.events) {
|
|
119
|
-
const event = subscription.events[eventKey]
|
|
120
|
-
_events[eventKey] = Object.assign({}, event, {
|
|
121
|
-
name: eventKey,
|
|
122
|
-
subscription: subscriptionKey,
|
|
123
|
-
namespace: options?.name,
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
_subscriptions[subscriptionKey] = Object.assign({}, subscription, {
|
|
128
|
-
name: subscriptionKey,
|
|
129
|
-
namespace: options?.name,
|
|
130
|
-
events: _events,
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return createSchema<
|
|
135
|
-
TNamespaceContract<Procedures, Subscriptions, Events, Name>
|
|
136
|
-
>({
|
|
83
|
+
return createSchema<TNamespaceContract<Procedures, Events, Name>>({
|
|
137
84
|
...schemaOptions,
|
|
138
85
|
[Kind]: NamespaceKind,
|
|
139
86
|
type: 'neemata:namespace',
|
|
140
87
|
name: name as Name,
|
|
141
88
|
procedures: _procedures,
|
|
142
|
-
subscriptions: _subscriptions,
|
|
143
89
|
events: _events,
|
|
144
90
|
timeout,
|
|
145
91
|
})
|
package/src/schemas/procedure.ts
CHANGED
|
@@ -2,32 +2,6 @@ import { type BaseType, t } from '@nmtjs/type'
|
|
|
2
2
|
import { Kind } from '../constants.ts'
|
|
3
3
|
import { type ContractSchemaOptions, createSchema } from '../utils.ts'
|
|
4
4
|
|
|
5
|
-
export type TAnyBaseProcedureContract = TBaseProcedureContract<
|
|
6
|
-
string,
|
|
7
|
-
BaseType,
|
|
8
|
-
BaseType,
|
|
9
|
-
string | undefined,
|
|
10
|
-
string | undefined
|
|
11
|
-
>
|
|
12
|
-
|
|
13
|
-
export interface TBaseProcedureContract<
|
|
14
|
-
Type extends string,
|
|
15
|
-
Input extends BaseType,
|
|
16
|
-
Output extends BaseType,
|
|
17
|
-
Name extends string | undefined = undefined,
|
|
18
|
-
Namespace extends string | undefined = undefined,
|
|
19
|
-
> {
|
|
20
|
-
[Kind]: string
|
|
21
|
-
type: Type
|
|
22
|
-
name: Name
|
|
23
|
-
namespace: Namespace
|
|
24
|
-
input: Input
|
|
25
|
-
output: Output
|
|
26
|
-
timeout?: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const ProcedureKind = 'NeemataProcedure'
|
|
30
|
-
|
|
31
5
|
export type TAnyProcedureContract = TProcedureContract<
|
|
32
6
|
BaseType,
|
|
33
7
|
BaseType,
|
|
@@ -36,20 +10,22 @@ export type TAnyProcedureContract = TProcedureContract<
|
|
|
36
10
|
string | undefined
|
|
37
11
|
>
|
|
38
12
|
|
|
13
|
+
export const ProcedureKind = 'NeemataProcedure'
|
|
14
|
+
|
|
39
15
|
export interface TProcedureContract<
|
|
40
16
|
Input extends BaseType = t.NeverType,
|
|
41
17
|
Output extends BaseType = t.NeverType,
|
|
42
18
|
Stream extends BaseType = t.NeverType,
|
|
43
19
|
Name extends string | undefined = undefined,
|
|
44
20
|
Namespace extends string | undefined = undefined,
|
|
45
|
-
>
|
|
46
|
-
'neemata:procedure',
|
|
47
|
-
Input,
|
|
48
|
-
Output,
|
|
49
|
-
Name,
|
|
50
|
-
Namespace
|
|
51
|
-
> {
|
|
21
|
+
> {
|
|
52
22
|
[Kind]: typeof ProcedureKind
|
|
23
|
+
type: 'neemata:procedure'
|
|
24
|
+
name: Name
|
|
25
|
+
namespace: Namespace
|
|
26
|
+
input: Input
|
|
27
|
+
output: Output
|
|
28
|
+
timeout?: number
|
|
53
29
|
stream: Stream
|
|
54
30
|
}
|
|
55
31
|
|
|
@@ -1,93 +1,57 @@
|
|
|
1
|
-
import { type BaseType, t } from '@nmtjs/type'
|
|
2
1
|
import { Kind } from '../constants.ts'
|
|
3
2
|
import { type ContractSchemaOptions, createSchema } from '../utils.ts'
|
|
4
3
|
import type { TAnyEventContract, TEventContract } from './event.ts'
|
|
5
|
-
import type { TBaseProcedureContract } from './procedure.ts'
|
|
6
4
|
|
|
7
5
|
export const SubscriptionKind = 'NeemataSubscription'
|
|
8
6
|
|
|
9
7
|
export type SubcriptionOptions = Record<string, string | number | boolean>
|
|
10
8
|
|
|
11
9
|
export type TAnySubscriptionContract = TSubscriptionContract<
|
|
12
|
-
BaseType,
|
|
13
|
-
BaseType,
|
|
14
10
|
SubcriptionOptions,
|
|
15
|
-
Record<string,
|
|
16
|
-
string | undefined,
|
|
11
|
+
Record<string, TAnyEventContract>,
|
|
17
12
|
string | undefined
|
|
18
13
|
>
|
|
19
14
|
|
|
20
15
|
export interface TSubscriptionContract<
|
|
21
|
-
Input extends BaseType = t.NeverType,
|
|
22
|
-
Output extends BaseType = t.NeverType,
|
|
23
16
|
Options extends SubcriptionOptions = {},
|
|
24
17
|
Events extends Record<string, unknown> = {},
|
|
25
18
|
Name extends string | undefined = undefined,
|
|
26
|
-
|
|
27
|
-
> extends TBaseProcedureContract<
|
|
28
|
-
'neemata:subscription',
|
|
29
|
-
Input,
|
|
30
|
-
Output,
|
|
31
|
-
Name,
|
|
32
|
-
Namespace
|
|
33
|
-
> {
|
|
19
|
+
> {
|
|
34
20
|
[Kind]: typeof SubscriptionKind
|
|
21
|
+
type: 'neemata:subscription'
|
|
22
|
+
name: Name
|
|
35
23
|
options: Options
|
|
36
24
|
events: {
|
|
37
25
|
[K in keyof Events]: Events[K] extends TAnyEventContract
|
|
38
|
-
? TEventContract<
|
|
39
|
-
Events[K]['payload'],
|
|
40
|
-
Extract<K, string>,
|
|
41
|
-
Name,
|
|
42
|
-
Namespace
|
|
43
|
-
>
|
|
26
|
+
? TEventContract<Events[K]['payload'], Extract<K, string>, Name>
|
|
44
27
|
: never
|
|
45
28
|
}
|
|
46
29
|
}
|
|
47
30
|
|
|
48
31
|
export const SubscriptionContract = <
|
|
49
|
-
Input extends BaseType = t.NeverType,
|
|
50
|
-
Output extends BaseType = t.NeverType,
|
|
51
32
|
Events extends Record<string, unknown> = {},
|
|
52
33
|
Name extends string | undefined = undefined,
|
|
53
34
|
>(options?: {
|
|
54
|
-
input?: Input
|
|
55
|
-
output?: Output
|
|
56
35
|
events?: Events
|
|
57
|
-
timeout?: number
|
|
58
36
|
schemaOptions?: ContractSchemaOptions
|
|
59
37
|
name?: Name
|
|
60
38
|
}) => {
|
|
61
|
-
const {
|
|
62
|
-
input = t.never() as unknown as Input,
|
|
63
|
-
output = t.never() as unknown as Output,
|
|
64
|
-
events = {} as Events,
|
|
65
|
-
timeout,
|
|
66
|
-
schemaOptions = {},
|
|
67
|
-
name,
|
|
68
|
-
} = options ?? {}
|
|
69
|
-
|
|
39
|
+
const { events = {} as Events, schemaOptions = {}, name } = options ?? {}
|
|
70
40
|
const _events = {} as any
|
|
71
41
|
for (const key in events) {
|
|
72
42
|
const event = events[key]
|
|
73
|
-
_events[key] = Object.assign({}, event, { subscription: name })
|
|
43
|
+
_events[key] = Object.assign({}, event, { name: key, subscription: name })
|
|
74
44
|
}
|
|
75
45
|
return {
|
|
76
46
|
$withOptions: <Options extends SubcriptionOptions>() =>
|
|
77
|
-
createSchema<TSubscriptionContract<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
timeout,
|
|
86
|
-
name: name as Name,
|
|
87
|
-
namespace: undefined,
|
|
88
|
-
options: undefined as unknown as Options,
|
|
89
|
-
},
|
|
90
|
-
),
|
|
47
|
+
createSchema<TSubscriptionContract<Options, Events, Name>>({
|
|
48
|
+
...schemaOptions,
|
|
49
|
+
[Kind]: SubscriptionKind,
|
|
50
|
+
type: 'neemata:subscription',
|
|
51
|
+
events: _events,
|
|
52
|
+
name: name as Name,
|
|
53
|
+
options: undefined as unknown as Options,
|
|
54
|
+
}),
|
|
91
55
|
}
|
|
92
56
|
}
|
|
93
57
|
|