@nmtjs/contract 0.3.1 → 0.3.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schemas/service.ts"],"sourcesContent":["import {\n type ContractSchemaOptions,\n applyNames,\n createSchema,\n} from '../utils.ts'\nimport type { TEventContract } from './event.ts'\nimport type { TBaseProcedureContract, TProcedureContract } from './procedure.ts'\nimport type { TSubscriptionContract } from './subscription.ts'\n\nexport interface TServiceContract<\n Name extends string = string,\n Transports extends { [K in string]?: true } = { [K in string]?: true },\n Procedures extends Record<string, TBaseProcedureContract> = Record<\n string,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/service.ts"],"sourcesContent":["import {\n type ContractSchemaOptions,\n applyNames,\n createSchema,\n} from '../utils.ts'\nimport type { TEventContract } from './event.ts'\nimport type { TBaseProcedureContract, TProcedureContract } from './procedure.ts'\nimport type { TSubscriptionContract } from './subscription.ts'\n\nexport interface TServiceContract<\n Name extends string = string,\n Transports extends { [K in string]?: true } = { [K in string]?: true },\n Procedures extends Record<string, TBaseProcedureContract> = Record<\n string,\n TBaseProcedureContract\n >,\n Events extends Record<string, TEventContract> = Record<\n string,\n TEventContract\n >,\n> {\n type: 'neemata:service'\n name: Name\n transports: Transports\n procedures: {\n [K in keyof Procedures]: Procedures[K] extends TProcedureContract<\n infer Input,\n infer Output,\n any,\n any,\n any\n >\n ? // ? true\n TProcedureContract<Input, Output, Extract<K, string>, Name, Transports>\n : Procedures[K] extends TSubscriptionContract<\n infer Input,\n infer Output,\n infer Options,\n infer Events,\n any,\n any,\n any\n >\n ? TSubscriptionContract<\n Input,\n Output,\n Options,\n {\n [EK in keyof Events]: Events[EK] extends TEventContract<\n infer Payload\n >\n ? TEventContract<\n Payload,\n Extract<EK, string>,\n Name,\n Extract<K, string>\n >\n : never\n },\n Extract<K, string>,\n Name,\n Transports\n >\n : Procedures[K]\n }\n events: {\n [K in Extract<keyof Events, string>]: Events[K] extends TEventContract<\n infer Payload\n >\n ? TEventContract<Payload, K, Name>\n : Events[K]\n }\n timeout?: number\n}\n\nexport const ServiceContract = <\n Name extends string,\n Transports extends { [key: string]: true },\n Procedures extends Record<\n string,\n TBaseProcedureContract | TProcedureContract | TSubscriptionContract\n >,\n Events extends Record<string, TEventContract>,\n>(\n name: Name,\n transports: Transports,\n procedures: Procedures = {} as Procedures,\n events: Events = {} as Events,\n timeout?: number,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n const serviceProcedures = {}\n\n for (const [procedureName, procedure] of Object.entries(procedures)) {\n if (procedure.type === 'neemata:subscription') {\n serviceProcedures[procedureName] = {\n ...procedure,\n events: applyNames((procedure as TSubscriptionContract).events, {\n serviceName: name,\n subscriptionName: procedureName,\n }),\n }\n } else {\n serviceProcedures[procedureName] = procedure\n }\n }\n\n return createSchema<TServiceContract<Name, Transports, Procedures, Events>>({\n ...schemaOptions,\n name: name,\n type: 'neemata:service',\n // @ts-expect-error\n procedures: applyNames(procedures, { serviceName: name }),\n // @ts-expect-error\n events: applyNames(events, { serviceName: name }),\n transports,\n timeout,\n })\n}\n"],"names":["applyNames","createSchema","ServiceContract","name","transports","procedures","events","timeout","schemaOptions","serviceProcedures","procedureName","procedure","Object","entries","type","serviceName","subscriptionName"],"mappings":"AAAA,SAEEA,UAAU,EACVC,YAAY,QACP,cAAa;AAuEpB,OAAO,MAAMC,kBAAkB,CAS7BC,MACAC,YACAC,aAAyB,CAAC,CAAe,EACzCC,SAAiB,CAAC,CAAW,EAC7BC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,MAAMC,oBAAoB,CAAC;IAE3B,KAAK,MAAM,CAACC,eAAeC,UAAU,IAAIC,OAAOC,OAAO,CAACR,YAAa;QACnE,IAAIM,UAAUG,IAAI,KAAK,wBAAwB;YAC7CL,iBAAiB,CAACC,cAAc,GAAG;gBACjC,GAAGC,SAAS;gBACZL,QAAQN,WAAW,AAACW,UAAoCL,MAAM,EAAE;oBAC9DS,aAAaZ;oBACba,kBAAkBN;gBACpB;YACF;QACF,OAAO;YACLD,iBAAiB,CAACC,cAAc,GAAGC;QACrC;IACF;IAEA,OAAOV,aAAqE;QAC1E,GAAGO,aAAa;QAChBL,MAAMA;QACNW,MAAM;QAENT,YAAYL,WAAWK,YAAY;YAAEU,aAAaZ;QAAK;QAEvDG,QAAQN,WAAWM,QAAQ;YAAES,aAAaZ;QAAK;QAC/CC;QACAG;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@nmtjs/type": "0.3.
|
|
13
|
-
"@nmtjs/common": "0.3.
|
|
12
|
+
"@nmtjs/type": "0.3.3",
|
|
13
|
+
"@nmtjs/common": "0.3.3"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@nmtjs/type": "0.3.
|
|
17
|
-
"@nmtjs/common": "0.3.
|
|
16
|
+
"@nmtjs/type": "0.3.3",
|
|
17
|
+
"@nmtjs/common": "0.3.3"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"src",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"LICENSE.md",
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
|
-
"version": "0.3.
|
|
26
|
+
"version": "0.3.3",
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "neemata-build -p neutral --root=./src './**/*.ts'",
|
|
29
29
|
"type-check": "tsc --noEmit"
|
package/src/schemas/service.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface TServiceContract<
|
|
|
12
12
|
Transports extends { [K in string]?: true } = { [K in string]?: true },
|
|
13
13
|
Procedures extends Record<string, TBaseProcedureContract> = Record<
|
|
14
14
|
string,
|
|
15
|
-
|
|
15
|
+
TBaseProcedureContract
|
|
16
16
|
>,
|
|
17
17
|
Events extends Record<string, TEventContract> = Record<
|
|
18
18
|
string,
|
|
@@ -76,7 +76,10 @@ export interface TServiceContract<
|
|
|
76
76
|
export const ServiceContract = <
|
|
77
77
|
Name extends string,
|
|
78
78
|
Transports extends { [key: string]: true },
|
|
79
|
-
Procedures extends Record<
|
|
79
|
+
Procedures extends Record<
|
|
80
|
+
string,
|
|
81
|
+
TBaseProcedureContract | TProcedureContract | TSubscriptionContract
|
|
82
|
+
>,
|
|
80
83
|
Events extends Record<string, TEventContract>,
|
|
81
84
|
>(
|
|
82
85
|
name: Name,
|
|
@@ -92,7 +95,7 @@ export const ServiceContract = <
|
|
|
92
95
|
if (procedure.type === 'neemata:subscription') {
|
|
93
96
|
serviceProcedures[procedureName] = {
|
|
94
97
|
...procedure,
|
|
95
|
-
events: applyNames(procedure.events, {
|
|
98
|
+
events: applyNames((procedure as TSubscriptionContract).events, {
|
|
96
99
|
serviceName: name,
|
|
97
100
|
subscriptionName: procedureName,
|
|
98
101
|
}),
|
|
@@ -114,23 +117,3 @@ export const ServiceContract = <
|
|
|
114
117
|
timeout,
|
|
115
118
|
})
|
|
116
119
|
}
|
|
117
|
-
|
|
118
|
-
type A<T extends boolean> = {
|
|
119
|
-
// type: 'boolean'
|
|
120
|
-
a: T
|
|
121
|
-
}
|
|
122
|
-
type B<T extends number> = {
|
|
123
|
-
// type: 'number'
|
|
124
|
-
b: T
|
|
125
|
-
}
|
|
126
|
-
type T = Record<string, A<boolean> | B<number>>
|
|
127
|
-
|
|
128
|
-
type TT<TTT extends T> = {
|
|
129
|
-
[K in keyof TTT]: TTT[K] extends A<infer T>
|
|
130
|
-
? T
|
|
131
|
-
: TTT[K] extends B<infer T>
|
|
132
|
-
? T
|
|
133
|
-
: never
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
type TTT = TT<{ r: A<false> }>
|