@nmtjs/contract 0.11.6 → 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.
|
@@ -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: {},
|
|
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"}
|
|
@@ -6,7 +6,10 @@ export const SubscriptionContract = (options) => {
|
|
|
6
6
|
const _events = {};
|
|
7
7
|
for (const key in events) {
|
|
8
8
|
const event = events[key];
|
|
9
|
-
_events[key] = Object.assign({}, event, {
|
|
9
|
+
_events[key] = Object.assign({}, event, {
|
|
10
|
+
name: key,
|
|
11
|
+
subscription: name
|
|
12
|
+
});
|
|
10
13
|
}
|
|
11
14
|
return { $withOptions: () => createSchema({
|
|
12
15
|
...schemaOptions,
|
|
@@ -14,7 +17,6 @@ export const SubscriptionContract = (options) => {
|
|
|
14
17
|
type: "neemata:subscription",
|
|
15
18
|
events: _events,
|
|
16
19
|
name,
|
|
17
|
-
namespace: undefined,
|
|
18
20
|
options: undefined
|
|
19
21
|
}) };
|
|
20
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAqC,oBAAoB,aAAa;AAGtE,OAAO,MAAM,mBAAmB;
|
|
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/namespace.ts
CHANGED
|
@@ -2,23 +2,17 @@ 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
9
|
Record<string, any>,
|
|
14
|
-
// Record<string, any>,
|
|
15
10
|
Record<string, any>,
|
|
16
11
|
string | undefined
|
|
17
12
|
>
|
|
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,42 +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<
|
|
136
|
-
Procedures,
|
|
137
|
-
// Subscriptions,
|
|
138
|
-
Events,
|
|
139
|
-
Name
|
|
140
|
-
>
|
|
141
|
-
>({
|
|
83
|
+
return createSchema<TNamespaceContract<Procedures, Events, Name>>({
|
|
142
84
|
...schemaOptions,
|
|
143
85
|
[Kind]: NamespaceKind,
|
|
144
86
|
type: 'neemata:namespace',
|
|
145
87
|
name: name as Name,
|
|
146
88
|
procedures: _procedures,
|
|
147
|
-
// subscriptions: _subscriptions,
|
|
148
|
-
subscriptions: {},
|
|
149
89
|
events: _events,
|
|
150
90
|
timeout,
|
|
151
91
|
})
|
|
@@ -8,8 +8,7 @@ export type SubcriptionOptions = Record<string, string | number | boolean>
|
|
|
8
8
|
|
|
9
9
|
export type TAnySubscriptionContract = TSubscriptionContract<
|
|
10
10
|
SubcriptionOptions,
|
|
11
|
-
Record<string,
|
|
12
|
-
string | undefined,
|
|
11
|
+
Record<string, TAnyEventContract>,
|
|
13
12
|
string | undefined
|
|
14
13
|
>
|
|
15
14
|
|
|
@@ -17,21 +16,14 @@ export interface TSubscriptionContract<
|
|
|
17
16
|
Options extends SubcriptionOptions = {},
|
|
18
17
|
Events extends Record<string, unknown> = {},
|
|
19
18
|
Name extends string | undefined = undefined,
|
|
20
|
-
Namespace extends string | undefined = undefined,
|
|
21
19
|
> {
|
|
22
20
|
[Kind]: typeof SubscriptionKind
|
|
23
21
|
type: 'neemata:subscription'
|
|
24
22
|
name: Name
|
|
25
|
-
namespace: Namespace
|
|
26
23
|
options: Options
|
|
27
24
|
events: {
|
|
28
25
|
[K in keyof Events]: Events[K] extends TAnyEventContract
|
|
29
|
-
? TEventContract<
|
|
30
|
-
Events[K]['payload'],
|
|
31
|
-
Extract<K, string>,
|
|
32
|
-
Name,
|
|
33
|
-
Namespace
|
|
34
|
-
>
|
|
26
|
+
? TEventContract<Events[K]['payload'], Extract<K, string>, Name>
|
|
35
27
|
: never
|
|
36
28
|
}
|
|
37
29
|
}
|
|
@@ -45,11 +37,10 @@ export const SubscriptionContract = <
|
|
|
45
37
|
name?: Name
|
|
46
38
|
}) => {
|
|
47
39
|
const { events = {} as Events, schemaOptions = {}, name } = options ?? {}
|
|
48
|
-
|
|
49
40
|
const _events = {} as any
|
|
50
41
|
for (const key in events) {
|
|
51
42
|
const event = events[key]
|
|
52
|
-
_events[key] = Object.assign({}, event, { subscription: name })
|
|
43
|
+
_events[key] = Object.assign({}, event, { name: key, subscription: name })
|
|
53
44
|
}
|
|
54
45
|
return {
|
|
55
46
|
$withOptions: <Options extends SubcriptionOptions>() =>
|
|
@@ -59,7 +50,6 @@ export const SubscriptionContract = <
|
|
|
59
50
|
type: 'neemata:subscription',
|
|
60
51
|
events: _events,
|
|
61
52
|
name: name as Name,
|
|
62
|
-
namespace: undefined,
|
|
63
53
|
options: undefined as unknown as Options,
|
|
64
54
|
}),
|
|
65
55
|
}
|