@nmtjs/contract 0.0.4 → 0.1.1

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.
Files changed (69) hide show
  1. package/dist/index.js +16 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/schemas/event.js +4 -4
  4. package/dist/schemas/event.js.map +1 -1
  5. package/dist/schemas/procedure.js +4 -5
  6. package/dist/schemas/procedure.js.map +1 -1
  7. package/dist/schemas/service.js +1 -6
  8. package/dist/schemas/service.js.map +1 -1
  9. package/dist/schemas/subscription.js +13 -14
  10. package/dist/schemas/subscription.js.map +1 -1
  11. package/dist/types/blob.js +13 -0
  12. package/dist/types/blob.js.map +1 -0
  13. package/dist/utils.js.map +1 -1
  14. package/package.json +8 -18
  15. package/src/index.ts +31 -0
  16. package/src/schemas/event.ts +7 -11
  17. package/src/schemas/procedure.ts +21 -23
  18. package/src/schemas/service.ts +40 -30
  19. package/src/schemas/subscription.ts +27 -49
  20. package/src/types/blob.ts +25 -0
  21. package/src/utils.ts +5 -6
  22. package/dist/compiler.js +0 -50
  23. package/dist/compiler.js.map +0 -1
  24. package/dist/contract.js +0 -24
  25. package/dist/contract.js.map +0 -1
  26. package/dist/formats.js +0 -127
  27. package/dist/formats.js.map +0 -1
  28. package/dist/guards/blob.js +0 -3
  29. package/dist/guards/blob.js.map +0 -1
  30. package/dist/guards/event.js +0 -3
  31. package/dist/guards/event.js.map +0 -1
  32. package/dist/guards/native-enum.js +0 -3
  33. package/dist/guards/native-enum.js.map +0 -1
  34. package/dist/guards/nullable.js +0 -2
  35. package/dist/guards/nullable.js.map +0 -1
  36. package/dist/guards/procedure.js +0 -3
  37. package/dist/guards/procedure.js.map +0 -1
  38. package/dist/guards/service.js +0 -3
  39. package/dist/guards/service.js.map +0 -1
  40. package/dist/guards/subscription.js +0 -3
  41. package/dist/guards/subscription.js.map +0 -1
  42. package/dist/guards/union-enum.js +0 -3
  43. package/dist/guards/union-enum.js.map +0 -1
  44. package/dist/guards.js +0 -20
  45. package/dist/guards.js.map +0 -1
  46. package/dist/schemas/blob.js +0 -26
  47. package/dist/schemas/blob.js.map +0 -1
  48. package/dist/schemas/native-enum.js +0 -14
  49. package/dist/schemas/native-enum.js.map +0 -1
  50. package/dist/schemas/nullable.js +0 -5
  51. package/dist/schemas/nullable.js.map +0 -1
  52. package/dist/schemas/union-enum.js +0 -13
  53. package/dist/schemas/union-enum.js.map +0 -1
  54. package/src/compiler.ts +0 -63
  55. package/src/contract.ts +0 -62
  56. package/src/formats.ts +0 -181
  57. package/src/guards/blob.ts +0 -5
  58. package/src/guards/event.ts +0 -6
  59. package/src/guards/native-enum.ts +0 -7
  60. package/src/guards/nullable.ts +0 -14
  61. package/src/guards/procedure.ts +0 -6
  62. package/src/guards/service.ts +0 -6
  63. package/src/guards/subscription.ts +0 -10
  64. package/src/guards/union-enum.ts +0 -7
  65. package/src/guards.ts +0 -21
  66. package/src/schemas/blob.ts +0 -58
  67. package/src/schemas/native-enum.ts +0 -29
  68. package/src/schemas/nullable.ts +0 -6
  69. package/src/schemas/union-enum.ts +0 -43
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { t as baseT } from '@nmtjs/type';
2
+ import { EventContract } from "./schemas/event.js";
3
+ import { ProcedureContract } from "./schemas/procedure.js";
4
+ import { ServiceContract } from "./schemas/service.js";
5
+ import { SubscriptionContract } from "./schemas/subscription.js";
6
+ import { blob } from "./types/blob.js";
7
+ export var c;
8
+ (function(c) {
9
+ c.procedure = ProcedureContract;
10
+ c.event = EventContract;
11
+ c.subscription = SubscriptionContract;
12
+ c.service = ServiceContract;
13
+ })(c || (c = {}));
14
+ export const t = Object.assign({}, baseT, {
15
+ blob
16
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { t as baseT } from '@nmtjs/type'\nimport { EventContract, type TEventContract } from './schemas/event.ts'\n\nimport {\n ProcedureContract,\n type TBaseProcedureContract,\n type TProcedureContract,\n} from './schemas/procedure.ts'\nimport { ServiceContract, type TServiceContract } from './schemas/service.ts'\nimport {\n SubscriptionContract,\n type TSubscriptionContract,\n} from './schemas/subscription.ts'\nimport { blob } from './types/blob.ts'\n\nexport type {\n TEventContract,\n TProcedureContract,\n TBaseProcedureContract,\n TServiceContract,\n TSubscriptionContract,\n}\n\nexport namespace c {\n export const procedure = ProcedureContract\n export const event = EventContract\n export const subscription = SubscriptionContract\n export const service = ServiceContract\n}\n\nexport const t = Object.assign({}, baseT, { blob })\n"],"names":["t","baseT","EventContract","ProcedureContract","ServiceContract","SubscriptionContract","blob","c","procedure","event","subscription","service","Object","assign"],"mappings":"AAAA,SAASA,KAAKC,KAAK,QAAQ,cAAa;AACxC,SAASC,aAAa,QAA6B,qBAAoB;AAEvE,SACEC,iBAAiB,QAGZ,yBAAwB;AAC/B,SAASC,eAAe,QAA+B,uBAAsB;AAC7E,SACEC,oBAAoB,QAEf,4BAA2B;AAClC,SAASC,IAAI,QAAQ,kBAAiB;;UAUrBC;MACFC,YAAYL;MACZM,QAAQP;MACRQ,eAAeL;MACfM,UAAUP;AACzB,GALiBG,MAAAA;AAOjB,OAAO,MAAMP,IAAIY,OAAOC,MAAM,CAAC,CAAC,GAAGZ,OAAO;IAAEK;AAAK,GAAE"}
@@ -1,12 +1,12 @@
1
- import { Kind, TypeRegistry } from '@sinclair/typebox/type';
2
1
  import { createSchema } from "../utils.js";
3
2
  export const EventKind = 'NeemataEvent';
4
3
  export const EventContract = (payload, schemaOptions = {})=>{
5
- if (!TypeRegistry.Has(EventKind)) TypeRegistry.Set(EventKind, ()=>true);
6
4
  return createSchema({
7
5
  ...schemaOptions,
8
- [Kind]: EventKind,
9
6
  type: 'neemata:event',
10
- payload
7
+ payload,
8
+ name: undefined,
9
+ serviceName: undefined,
10
+ subscriptionName: undefined
11
11
  });
12
12
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/event.ts"],"sourcesContent":["import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport const EventKind = 'NeemataEvent'\n\nexport interface TEventContract<\n Payload extends TSchema = any,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n SubscriptionName extends string | undefined = string | undefined,\n> extends TSchema {\n [Kind]: typeof EventKind\n type: 'neemata:event'\n static: {\n payload: Payload['static']\n }\n name: Name\n serviceName: ServiceName\n subscriptionName: SubscriptionName\n payload: Payload\n}\n\nexport const EventContract = <Payload extends TSchema>(\n payload: Payload,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n if (!TypeRegistry.Has(EventKind)) TypeRegistry.Set(EventKind, () => true)\n\n return createSchema<TEventContract<Payload>>({\n ...schemaOptions,\n [Kind]: EventKind,\n type: 'neemata:event',\n payload,\n })\n}\n"],"names":["Kind","TypeRegistry","createSchema","EventKind","EventContract","payload","schemaOptions","Has","Set","type"],"mappings":"AAAA,SAASA,IAAI,EAAgBC,YAAY,QAAQ,yBAAwB;AACzE,SAAqCC,YAAY,QAAQ,cAAa;AAEtE,OAAO,MAAMC,YAAY,eAAc;AAmBvC,OAAO,MAAMC,gBAAgB,CAC3BC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,IAAI,CAACL,aAAaM,GAAG,CAACJ,YAAYF,aAAaO,GAAG,CAACL,WAAW,IAAM;IAEpE,OAAOD,aAAsC;QAC3C,GAAGI,aAAa;QAChB,CAACN,KAAK,EAAEG;QACRM,MAAM;QACNJ;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/schemas/event.ts"],"sourcesContent":["import { type BaseType, type TSchema, getTypeSchema } from '@nmtjs/type'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport const EventKind = 'NeemataEvent'\n\nexport interface TEventContract<\n Payload extends BaseType = BaseType,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n SubscriptionName extends string | undefined = string | undefined,\n> {\n type: 'neemata:event'\n name: Name\n serviceName: ServiceName\n subscriptionName: SubscriptionName\n payload: Payload\n}\n\nexport const EventContract = <Payload extends BaseType>(\n payload: Payload,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n return createSchema<TEventContract<Payload>>({\n ...schemaOptions,\n type: 'neemata:event',\n payload,\n name: undefined,\n serviceName: undefined,\n subscriptionName: undefined,\n })\n}\n"],"names":["createSchema","EventKind","EventContract","payload","schemaOptions","type","name","undefined","serviceName","subscriptionName"],"mappings":"AACA,SAAqCA,YAAY,QAAQ,cAAa;AAEtE,OAAO,MAAMC,YAAY,eAAc;AAevC,OAAO,MAAMC,gBAAgB,CAC3BC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,OAAOJ,aAAsC;QAC3C,GAAGI,aAAa;QAChBC,MAAM;QACNF;QACAG,MAAMC;QACNC,aAAaD;QACbE,kBAAkBF;IACpB;AACF,EAAC"}
@@ -1,14 +1,13 @@
1
- import { Kind, TypeRegistry } from '@sinclair/typebox/type';
2
1
  import { createSchema } from "../utils.js";
3
- export const ProcedureKind = 'NeemataProcedure';
4
2
  export const ProcedureContract = (input, output, timeout, schemaOptions = {})=>{
5
- if (!TypeRegistry.Has(ProcedureKind)) TypeRegistry.Set(ProcedureKind, ()=>true);
6
3
  return createSchema({
7
4
  ...schemaOptions,
8
- [Kind]: ProcedureKind,
9
5
  type: 'neemata:procedure',
10
6
  input,
11
7
  output,
12
- timeout
8
+ timeout,
9
+ name: undefined,
10
+ serviceName: undefined,
11
+ transports: undefined
13
12
  });
14
13
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/procedure.ts"],"sourcesContent":["import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'\n\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport const ProcedureKind = 'NeemataProcedure'\n\nexport interface TBaseProcedureContract<\n Input extends TSchema = TSchema,\n Output extends TSchema = TSchema,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n> extends TSchema {\n name: Name\n serviceName: ServiceName\n transports: Transports\n input: Input\n output: Output\n timeout?: number\n}\n\nexport interface TProcedureContract<\n Input extends TSchema = TSchema,\n Output extends TSchema = TSchema,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n> extends TBaseProcedureContract<Input, Output, Name, ServiceName, Transports> {\n [Kind]: typeof ProcedureKind\n type: 'neemata:procedure'\n static: {\n input: Input['static']\n output: Output['static']\n }\n}\n\nexport const ProcedureContract = <\n Input extends TSchema,\n Output extends TSchema,\n>(\n input: Input,\n output: Output,\n timeout?: number,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n if (!TypeRegistry.Has(ProcedureKind))\n TypeRegistry.Set(ProcedureKind, () => true)\n\n return createSchema<TProcedureContract<Input, Output>>({\n ...schemaOptions,\n [Kind]: ProcedureKind,\n type: 'neemata:procedure',\n input,\n output,\n timeout,\n })\n}\n"],"names":["Kind","TypeRegistry","createSchema","ProcedureKind","ProcedureContract","input","output","timeout","schemaOptions","Has","Set","type"],"mappings":"AAAA,SAASA,IAAI,EAAgBC,YAAY,QAAQ,yBAAwB;AAEzE,SAAqCC,YAAY,QAAQ,cAAa;AAEtE,OAAO,MAAMC,gBAAgB,mBAAkB;AAoC/C,OAAO,MAAMC,oBAAoB,CAI/BC,OACAC,QACAC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,IAAI,CAACP,aAAaQ,GAAG,CAACN,gBACpBF,aAAaS,GAAG,CAACP,eAAe,IAAM;IAExC,OAAOD,aAAgD;QACrD,GAAGM,aAAa;QAChB,CAACR,KAAK,EAAEG;QACRQ,MAAM;QACNN;QACAC;QACAC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/schemas/procedure.ts"],"sourcesContent":["import type { BaseType } from '@nmtjs/type'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport interface TBaseProcedureContract<\n Type extends string = string,\n Input extends BaseType = BaseType,\n Output extends BaseType = BaseType,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n> {\n type: Type\n name: Name\n serviceName: ServiceName\n transports: Transports\n input: Input\n output: Output\n timeout?: number\n}\n\nexport interface TProcedureContract<\n Input extends BaseType = BaseType,\n Output extends BaseType = BaseType,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n> extends TBaseProcedureContract<\n 'neemata:procedure',\n Input,\n Output,\n Name,\n ServiceName,\n Transports\n > {}\n\nexport const ProcedureContract = <\n Input extends BaseType,\n Output extends BaseType,\n>(\n input: Input,\n output: Output,\n timeout?: number,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n return createSchema<TProcedureContract<Input, Output>>({\n ...schemaOptions,\n type: 'neemata:procedure',\n input,\n output,\n timeout,\n name: undefined,\n serviceName: undefined,\n transports: undefined,\n })\n}\n"],"names":["createSchema","ProcedureContract","input","output","timeout","schemaOptions","type","name","undefined","serviceName","transports"],"mappings":"AACA,SAAqCA,YAAY,QAAQ,cAAa;AAsCtE,OAAO,MAAMC,oBAAoB,CAI/BC,OACAC,QACAC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,OAAOL,aAAgD;QACrD,GAAGK,aAAa;QAChBC,MAAM;QACNJ;QACAC;QACAC;QACAG,MAAMC;QACNC,aAAaD;QACbE,YAAYF;IACd;AACF,EAAC"}
@@ -1,12 +1,8 @@
1
- import { Kind, TypeRegistry } from '@sinclair/typebox/type';
2
1
  import { applyNames, createSchema } from "../utils.js";
3
- import { SubscriptionKind } from "./subscription.js";
4
- export const ServiceKind = 'NeemataService';
5
2
  export const ServiceContract = (name, transports, procedures = {}, events = {}, timeout, schemaOptions = {})=>{
6
- if (!TypeRegistry.Has(ServiceKind)) TypeRegistry.Set(ServiceKind, ()=>true);
7
3
  const serviceProcedures = {};
8
4
  for (const [procedureName, procedure] of Object.entries(procedures)){
9
- if (procedure[Kind] === SubscriptionKind) {
5
+ if (procedure.type === 'neemata:subscription') {
10
6
  serviceProcedures[procedureName] = {
11
7
  ...procedure,
12
8
  events: applyNames(procedure.events, {
@@ -20,7 +16,6 @@ export const ServiceContract = (name, transports, procedures = {}, events = {},
20
16
  }
21
17
  return createSchema({
22
18
  ...schemaOptions,
23
- [Kind]: ServiceKind,
24
19
  name: name,
25
20
  type: 'neemata:service',
26
21
  procedures: applyNames(procedures, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/service.ts"],"sourcesContent":["import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'\nimport {\n type ContractSchemaOptions,\n applyNames,\n createSchema,\n} from '../utils.ts'\nimport type { TEventContract } from './event.ts'\nimport type { TProcedureContract } from './procedure.ts'\nimport { SubscriptionKind, type TSubscriptionContract } from './subscription.ts'\n\nexport const ServiceKind = 'NeemataService'\n\nexport interface TServiceContract<\n Name extends string = string,\n Transports extends { [K in string]?: true } = { [K in string]?: true },\n Procedures extends Record<\n string,\n TProcedureContract | TSubscriptionContract\n > = Record<string, TProcedureContract | TSubscriptionContract>,\n Events extends Record<string, TEventContract> = Record<\n string,\n TEventContract\n >,\n> extends TSchema {\n [Kind]: typeof ServiceKind\n static: {\n procedures: {\n [K in keyof Procedures]: Procedures[K]['static']\n }\n subscriptions: {\n [K in keyof Procedures]: Procedures[K]['static']\n }\n events: {\n [K in keyof Events]: Events[K]['static']\n }\n transports: Transports\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 >\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 >\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 : never\n }\n events: {\n [K in Extract<keyof Events, string>]: Events[K] extends TEventContract<\n infer Payload\n >\n ? TEventContract<Payload, K, Name>\n : never\n }\n timeout?: number\n}\n\nexport const ServiceContract = <\n Name extends string,\n Transports extends { [key: string]: true },\n Procedures extends Record<string, TProcedureContract | TSubscriptionContract>,\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 if (!TypeRegistry.Has(ServiceKind)) TypeRegistry.Set(ServiceKind, () => true)\n\n const serviceProcedures = {}\n\n for (const [procedureName, procedure] of Object.entries(procedures)) {\n if (procedure[Kind] === SubscriptionKind) {\n serviceProcedures[procedureName] = {\n ...procedure,\n events: applyNames(procedure.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 [Kind]: ServiceKind,\n name: name,\n type: 'neemata:service',\n procedures: applyNames(procedures, { serviceName: name }),\n events: applyNames(events, { serviceName: name }),\n transports,\n timeout,\n })\n}\n"],"names":["Kind","TypeRegistry","applyNames","createSchema","SubscriptionKind","ServiceKind","ServiceContract","name","transports","procedures","events","timeout","schemaOptions","Has","Set","serviceProcedures","procedureName","procedure","Object","entries","serviceName","subscriptionName","type"],"mappings":"AAAA,SAASA,IAAI,EAAgBC,YAAY,QAAQ,yBAAwB;AACzE,SAEEC,UAAU,EACVC,YAAY,QACP,cAAa;AAGpB,SAASC,gBAAgB,QAAoC,oBAAmB;AAEhF,OAAO,MAAMC,cAAc,iBAAgB;AA0E3C,OAAO,MAAMC,kBAAkB,CAM7BC,MACAC,YACAC,aAAyB,CAAC,CAAe,EACzCC,SAAiB,CAAC,CAAW,EAC7BC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,IAAI,CAACX,aAAaY,GAAG,CAACR,cAAcJ,aAAaa,GAAG,CAACT,aAAa,IAAM;IAExE,MAAMU,oBAAoB,CAAC;IAE3B,KAAK,MAAM,CAACC,eAAeC,UAAU,IAAIC,OAAOC,OAAO,CAACV,YAAa;QACnE,IAAIQ,SAAS,CAACjB,KAAK,KAAKI,kBAAkB;YACxCW,iBAAiB,CAACC,cAAc,GAAG;gBACjC,GAAGC,SAAS;gBACZP,QAAQR,WAAWe,UAAUP,MAAM,EAAE;oBACnCU,aAAab;oBACbc,kBAAkBL;gBACpB;YACF;QACF,OAAO;YACLD,iBAAiB,CAACC,cAAc,GAAGC;QACrC;IACF;IAEA,OAAOd,aAAqE;QAC1E,GAAGS,aAAa;QAChB,CAACZ,KAAK,EAAEK;QACRE,MAAMA;QACNe,MAAM;QACNb,YAAYP,WAAWO,YAAY;YAAEW,aAAab;QAAK;QACvDG,QAAQR,WAAWQ,QAAQ;YAAEU,aAAab;QAAK;QAC/CC;QACAG;IACF;AACF,EAAC"}
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 TProcedureContract | TSubscriptionContract\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<string, TProcedureContract | TSubscriptionContract>,\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.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\ntype A<T extends boolean> = {\n // type: 'boolean'\n a: T\n}\ntype B<T extends number> = {\n // type: 'number'\n b: T\n}\ntype T = Record<string, A<boolean> | B<number>>\n\ntype TT<TTT extends T> = {\n [K in keyof TTT]: TTT[K] extends A<infer T>\n ? T\n : TTT[K] extends B<infer T>\n ? T\n : never\n}\n\ntype TTT = TT<{ r: A<false> }>\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,CAM7BC,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,WAAWW,UAAUL,MAAM,EAAE;oBACnCS,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"}
@@ -1,16 +1,15 @@
1
- import { Kind, TypeRegistry } from '@sinclair/typebox/type';
2
1
  import { createSchema } from "../utils.js";
3
- export const SubscriptionKind = 'NeemataSubscription';
4
- export const SubscriptionContract = (input, output, options, events, timeout, schemaOptions = {})=>{
5
- if (!TypeRegistry.Has(SubscriptionKind)) TypeRegistry.Set(SubscriptionKind, ()=>true);
6
- return createSchema({
7
- ...schemaOptions,
8
- [Kind]: SubscriptionKind,
9
- type: 'neemata:subscription',
10
- input,
11
- output,
12
- events,
13
- options,
14
- timeout
15
- });
2
+ export const SubscriptionContract = (input, output, events, timeout, schemaOptions = {})=>{
3
+ return ()=>createSchema({
4
+ ...schemaOptions,
5
+ type: 'neemata:subscription',
6
+ input,
7
+ output,
8
+ events,
9
+ timeout,
10
+ options: undefined,
11
+ name: undefined,
12
+ serviceName: undefined,
13
+ transports: undefined
14
+ });
16
15
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/schemas/subscription.ts"],"sourcesContent":["import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TEventContract } from './event.ts'\nimport type { TBaseProcedureContract } from './procedure.ts'\n\nexport const SubscriptionKind = 'NeemataSubscription'\n\nexport type TSubcriptionOptions = { static: Record<string, string | number> }\n\nexport interface TSubscriptionContract<\n Input extends TSchema = TSchema,\n Output extends TSchema = TSchema,\n Options extends TSubcriptionOptions = TSubcriptionOptions,\n Events extends Record<string, TEventContract> = Record<\n string,\n TEventContract\n >,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n> extends TBaseProcedureContract<Input, Output, Name, ServiceName, Transports> {\n [Kind]: typeof SubscriptionKind\n type: 'neemata:subscription'\n static: {\n input: Input['static']\n output: Output['static']\n options: Options['static']\n events: {\n [K in keyof Events]: Events[K]['static']\n }\n }\n options: Options\n events: Events\n}\n\nexport const SubscriptionContract = <\n Input extends TSchema = TSchema,\n Output extends TSchema = TSchema,\n Options extends TSubcriptionOptions = TSubcriptionOptions,\n Events extends Record<string, TEventContract> = Record<\n string,\n TEventContract\n >,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n>(\n input: Input,\n output: Output,\n options: Options,\n events: Events,\n timeout?: number,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n if (!TypeRegistry.Has(SubscriptionKind))\n TypeRegistry.Set(SubscriptionKind, () => true)\n\n return createSchema<\n TSubscriptionContract<\n Input,\n Output,\n Options,\n Events,\n Name,\n ServiceName,\n Transports\n >\n >({\n ...schemaOptions,\n [Kind]: SubscriptionKind,\n type: 'neemata:subscription',\n input,\n output,\n events,\n options,\n timeout,\n })\n}\n"],"names":["Kind","TypeRegistry","createSchema","SubscriptionKind","SubscriptionContract","input","output","options","events","timeout","schemaOptions","Has","Set","type"],"mappings":"AAAA,SAASA,IAAI,EAAgBC,YAAY,QAAQ,yBAAwB;AACzE,SAAqCC,YAAY,QAAQ,cAAa;AAItE,OAAO,MAAMC,mBAAmB,sBAAqB;AAgCrD,OAAO,MAAMC,uBAAuB,CAclCC,OACAC,QACAC,SACAC,QACAC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,IAAI,CAACT,aAAaU,GAAG,CAACR,mBACpBF,aAAaW,GAAG,CAACT,kBAAkB,IAAM;IAE3C,OAAOD,aAUL;QACA,GAAGQ,aAAa;QAChB,CAACV,KAAK,EAAEG;QACRU,MAAM;QACNR;QACAC;QACAE;QACAD;QACAE;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/schemas/subscription.ts"],"sourcesContent":["import type { BaseType } from '@nmtjs/type'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\nimport type { TEventContract } from './event.ts'\nimport type { TBaseProcedureContract } from './procedure.ts'\n\nexport type TSubcriptionOptions = Record<string, string | number>\n\nexport interface TSubscriptionContract<\n Input extends BaseType = BaseType,\n Output extends BaseType = BaseType,\n Options extends TSubcriptionOptions = TSubcriptionOptions,\n Events extends Record<string, TEventContract> = Record<\n string,\n TEventContract\n >,\n Name extends string | undefined = string | undefined,\n ServiceName extends string | undefined = string | undefined,\n Transports extends { [K in string]?: true } | undefined =\n | { [K in string]?: true }\n | undefined,\n> extends TBaseProcedureContract<\n 'neemata:subscription',\n Input,\n Output,\n Name,\n ServiceName,\n Transports\n > {\n options: Options\n events: Events\n}\n\nexport const SubscriptionContract = <\n Input extends BaseType = BaseType,\n Output extends BaseType = BaseType,\n Events extends Record<string, TEventContract> = Record<\n string,\n TEventContract\n >,\n>(\n input: Input,\n output: Output,\n events: Events,\n timeout?: number,\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n return <Options extends TSubcriptionOptions>() =>\n createSchema<TSubscriptionContract<Input, Output, Options, Events>>({\n ...schemaOptions,\n type: 'neemata:subscription',\n input,\n output,\n events,\n timeout,\n options: undefined as unknown as Options,\n name: undefined,\n serviceName: undefined,\n transports: undefined,\n })\n}\n"],"names":["createSchema","SubscriptionContract","input","output","events","timeout","schemaOptions","type","options","undefined","name","serviceName","transports"],"mappings":"AACA,SAAqCA,YAAY,QAAQ,cAAa;AA+BtE,OAAO,MAAMC,uBAAuB,CAQlCC,OACAC,QACAC,QACAC,SACAC,gBAAuC,CAAC,CAA0B;IAElE,OAAO,IACLN,aAAoE;YAClE,GAAGM,aAAa;YAChBC,MAAM;YACNL;YACAC;YACAC;YACAC;YACAG,SAASC;YACTC,MAAMD;YACNE,aAAaF;YACbG,YAAYH;QACd;AACJ,EAAC"}
@@ -0,0 +1,13 @@
1
+ import { t } from '@nmtjs/type';
2
+ export const BlobKind = 'ApiBlob';
3
+ export const blob = (options = {})=>t.custom((value)=>{
4
+ if ('metadata' in value) {
5
+ if (options.maxSize) {
6
+ const size = value.metadata.size;
7
+ if (size === -1 || size > options.maxSize) {
8
+ throw new Error('Blob size unknown or exceeds maximum allowed size');
9
+ }
10
+ }
11
+ }
12
+ return value;
13
+ }, (value)=>value);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/blob.ts"],"sourcesContent":["import type { ApiBlobInterface } from '@nmtjs/common'\nimport { t } from '@nmtjs/type'\n\nexport const BlobKind = 'ApiBlob'\n\nexport interface BlobOptions {\n maxSize?: number\n contentType?: string\n}\n\nexport const blob = (options: BlobOptions = {}) =>\n t.custom<ApiBlobInterface>(\n (value) => {\n if ('metadata' in value) {\n if (options.maxSize) {\n const size = (value as ApiBlobInterface).metadata.size\n if (size === -1 || size > options.maxSize) {\n throw new Error('Blob size unknown or exceeds maximum allowed size')\n }\n }\n }\n return value\n },\n (value) => value,\n )\n"],"names":["t","BlobKind","blob","options","custom","value","maxSize","size","metadata","Error"],"mappings":"AACA,SAASA,CAAC,QAAQ,cAAa;AAE/B,OAAO,MAAMC,WAAW,UAAS;AAOjC,OAAO,MAAMC,OAAO,CAACC,UAAuB,CAAC,CAAC,GAC5CH,EAAEI,MAAM,CACN,CAACC;QACC,IAAI,cAAcA,OAAO;YACvB,IAAIF,QAAQG,OAAO,EAAE;gBACnB,MAAMC,OAAO,AAACF,MAA2BG,QAAQ,CAACD,IAAI;gBACtD,IAAIA,SAAS,CAAC,KAAKA,OAAOJ,QAAQG,OAAO,EAAE;oBACzC,MAAM,IAAIG,MAAM;gBAClB;YACF;QACF;QACA,OAAOJ;IACT,GACA,CAACA,QAAUA,OACZ"}
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { SchemaOptions, TSchema } from '@sinclair/typebox'\n\nexport type ContractSchemaOptions = Pick<SchemaOptions, 'title' | 'description'>\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 extends TSchema>(\n schema: Omit<T, 'static' | 'params'>,\n) => schema as T\n"],"names":["applyNames","params","opts","Object","fromEntries","entries","map","k","v","name","createSchema","schema"],"mappings":"AAIA,OAAO,MAAMA,aAAa,CACxBC,QACAC;IAEA,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACJ,QAAQK,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK;YAACD;YAAG;gBAAE,GAAGC,CAAC;gBAAEC,MAAMF;gBAAG,GAAGL,IAAI;YAAC;SAAE;AAE1E,EAAC;AAED,OAAO,MAAMQ,eAAe,CAC1BC,SACGA,OAAW"}
1
+ {"version":3,"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) => schema as T\n"],"names":["applyNames","params","opts","Object","fromEntries","entries","map","k","v","name","createSchema","schema"],"mappings":"AAKA,OAAO,MAAMA,aAAa,CACxBC,QACAC;IAEA,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACJ,QAAQK,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK;YAACD;YAAG;gBAAE,GAAGC,CAAC;gBAAEC,MAAMF;gBAAG,GAAGL,IAAI;YAAC;SAAE;AAE1E,EAAC;AAED,OAAO,MAAMQ,eAAe,CAAIC,SAAcA,OAAW"}
package/package.json CHANGED
@@ -3,28 +3,18 @@
3
3
  "type": "module",
4
4
  "exports": {
5
5
  ".": {
6
- "bun": "./src/contract.ts",
7
- "default": "./dist/contract.js",
8
- "types": "./src/contract.ts"
9
- },
10
- "./compiler": {
11
- "bun": "./src/compiler.ts",
12
- "default": "./dist/compiler.js",
13
- "types": "./src/compiler.ts"
14
- },
15
- "./guards": {
16
- "bun": "./src/guards.ts",
17
- "default": "./dist/guards.js",
18
- "types": "./src/guards.ts"
6
+ "bun": "./src/index.ts",
7
+ "default": "./dist/index.js",
8
+ "types": "./src/index.ts"
19
9
  }
20
10
  },
21
11
  "peerDependencies": {
22
- "@sinclair/typebox": "^0.32.34",
23
- "@nmtjs/common": "0.0.4"
12
+ "@nmtjs/common": "0.1.1",
13
+ "@nmtjs/type": "0.1.1"
24
14
  },
25
15
  "devDependencies": {
26
- "@sinclair/typebox": "^0.32.34",
27
- "@nmtjs/common": "0.0.4"
16
+ "@nmtjs/common": "0.1.1",
17
+ "@nmtjs/type": "0.1.1"
28
18
  },
29
19
  "files": [
30
20
  "src",
@@ -33,7 +23,7 @@
33
23
  "LICENSE.md",
34
24
  "README.md"
35
25
  ],
36
- "version": "0.0.4",
26
+ "version": "0.1.1",
37
27
  "scripts": {
38
28
  "build": "neemata-build -p neutral --root=./src './**/*.ts'",
39
29
  "type-check": "tsc --noEmit"
package/src/index.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { t as baseT } from '@nmtjs/type'
2
+ import { EventContract, type TEventContract } from './schemas/event.ts'
3
+
4
+ import {
5
+ ProcedureContract,
6
+ type TBaseProcedureContract,
7
+ type TProcedureContract,
8
+ } from './schemas/procedure.ts'
9
+ import { ServiceContract, type TServiceContract } from './schemas/service.ts'
10
+ import {
11
+ SubscriptionContract,
12
+ type TSubscriptionContract,
13
+ } from './schemas/subscription.ts'
14
+ import { blob } from './types/blob.ts'
15
+
16
+ export type {
17
+ TEventContract,
18
+ TProcedureContract,
19
+ TBaseProcedureContract,
20
+ TServiceContract,
21
+ TSubscriptionContract,
22
+ }
23
+
24
+ export namespace c {
25
+ export const procedure = ProcedureContract
26
+ export const event = EventContract
27
+ export const subscription = SubscriptionContract
28
+ export const service = ServiceContract
29
+ }
30
+
31
+ export const t = Object.assign({}, baseT, { blob })
@@ -1,35 +1,31 @@
1
- import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'
1
+ import { type BaseType, type TSchema, getTypeSchema } from '@nmtjs/type'
2
2
  import { type ContractSchemaOptions, createSchema } from '../utils.ts'
3
3
 
4
4
  export const EventKind = 'NeemataEvent'
5
5
 
6
6
  export interface TEventContract<
7
- Payload extends TSchema = any,
7
+ Payload extends BaseType = BaseType,
8
8
  Name extends string | undefined = string | undefined,
9
9
  ServiceName extends string | undefined = string | undefined,
10
10
  SubscriptionName extends string | undefined = string | undefined,
11
- > extends TSchema {
12
- [Kind]: typeof EventKind
11
+ > {
13
12
  type: 'neemata:event'
14
- static: {
15
- payload: Payload['static']
16
- }
17
13
  name: Name
18
14
  serviceName: ServiceName
19
15
  subscriptionName: SubscriptionName
20
16
  payload: Payload
21
17
  }
22
18
 
23
- export const EventContract = <Payload extends TSchema>(
19
+ export const EventContract = <Payload extends BaseType>(
24
20
  payload: Payload,
25
21
  schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,
26
22
  ) => {
27
- if (!TypeRegistry.Has(EventKind)) TypeRegistry.Set(EventKind, () => true)
28
-
29
23
  return createSchema<TEventContract<Payload>>({
30
24
  ...schemaOptions,
31
- [Kind]: EventKind,
32
25
  type: 'neemata:event',
33
26
  payload,
27
+ name: undefined,
28
+ serviceName: undefined,
29
+ subscriptionName: undefined,
34
30
  })
35
31
  }
@@ -1,18 +1,17 @@
1
- import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'
2
-
1
+ import type { BaseType } from '@nmtjs/type'
3
2
  import { type ContractSchemaOptions, createSchema } from '../utils.ts'
4
3
 
5
- export const ProcedureKind = 'NeemataProcedure'
6
-
7
4
  export interface TBaseProcedureContract<
8
- Input extends TSchema = TSchema,
9
- Output extends TSchema = TSchema,
5
+ Type extends string = string,
6
+ Input extends BaseType = BaseType,
7
+ Output extends BaseType = BaseType,
10
8
  Name extends string | undefined = string | undefined,
11
9
  ServiceName extends string | undefined = string | undefined,
12
10
  Transports extends { [K in string]?: true } | undefined =
13
11
  | { [K in string]?: true }
14
12
  | undefined,
15
- > extends TSchema {
13
+ > {
14
+ type: Type
16
15
  name: Name
17
16
  serviceName: ServiceName
18
17
  transports: Transports
@@ -22,40 +21,39 @@ export interface TBaseProcedureContract<
22
21
  }
23
22
 
24
23
  export interface TProcedureContract<
25
- Input extends TSchema = TSchema,
26
- Output extends TSchema = TSchema,
24
+ Input extends BaseType = BaseType,
25
+ Output extends BaseType = BaseType,
27
26
  Name extends string | undefined = string | undefined,
28
27
  ServiceName extends string | undefined = string | undefined,
29
28
  Transports extends { [K in string]?: true } | undefined =
30
29
  | { [K in string]?: true }
31
30
  | undefined,
32
- > extends TBaseProcedureContract<Input, Output, Name, ServiceName, Transports> {
33
- [Kind]: typeof ProcedureKind
34
- type: 'neemata:procedure'
35
- static: {
36
- input: Input['static']
37
- output: Output['static']
38
- }
39
- }
31
+ > extends TBaseProcedureContract<
32
+ 'neemata:procedure',
33
+ Input,
34
+ Output,
35
+ Name,
36
+ ServiceName,
37
+ Transports
38
+ > {}
40
39
 
41
40
  export const ProcedureContract = <
42
- Input extends TSchema,
43
- Output extends TSchema,
41
+ Input extends BaseType,
42
+ Output extends BaseType,
44
43
  >(
45
44
  input: Input,
46
45
  output: Output,
47
46
  timeout?: number,
48
47
  schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,
49
48
  ) => {
50
- if (!TypeRegistry.Has(ProcedureKind))
51
- TypeRegistry.Set(ProcedureKind, () => true)
52
-
53
49
  return createSchema<TProcedureContract<Input, Output>>({
54
50
  ...schemaOptions,
55
- [Kind]: ProcedureKind,
56
51
  type: 'neemata:procedure',
57
52
  input,
58
53
  output,
59
54
  timeout,
55
+ name: undefined,
56
+ serviceName: undefined,
57
+ transports: undefined,
60
58
  })
61
59
  }
@@ -1,54 +1,45 @@
1
- import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'
2
1
  import {
3
2
  type ContractSchemaOptions,
4
3
  applyNames,
5
4
  createSchema,
6
5
  } from '../utils.ts'
7
6
  import type { TEventContract } from './event.ts'
8
- import type { TProcedureContract } from './procedure.ts'
9
- import { SubscriptionKind, type TSubscriptionContract } from './subscription.ts'
10
-
11
- export const ServiceKind = 'NeemataService'
7
+ import type { TBaseProcedureContract, TProcedureContract } from './procedure.ts'
8
+ import type { TSubscriptionContract } from './subscription.ts'
12
9
 
13
10
  export interface TServiceContract<
14
11
  Name extends string = string,
15
12
  Transports extends { [K in string]?: true } = { [K in string]?: true },
16
- Procedures extends Record<
13
+ Procedures extends Record<string, TBaseProcedureContract> = Record<
17
14
  string,
18
15
  TProcedureContract | TSubscriptionContract
19
- > = Record<string, TProcedureContract | TSubscriptionContract>,
16
+ >,
20
17
  Events extends Record<string, TEventContract> = Record<
21
18
  string,
22
19
  TEventContract
23
20
  >,
24
- > extends TSchema {
25
- [Kind]: typeof ServiceKind
26
- static: {
27
- procedures: {
28
- [K in keyof Procedures]: Procedures[K]['static']
29
- }
30
- subscriptions: {
31
- [K in keyof Procedures]: Procedures[K]['static']
32
- }
33
- events: {
34
- [K in keyof Events]: Events[K]['static']
35
- }
36
- transports: Transports
37
- }
21
+ > {
38
22
  type: 'neemata:service'
39
23
  name: Name
40
24
  transports: Transports
41
25
  procedures: {
42
26
  [K in keyof Procedures]: Procedures[K] extends TProcedureContract<
43
27
  infer Input,
44
- infer Output
28
+ infer Output,
29
+ any,
30
+ any,
31
+ any
45
32
  >
46
- ? TProcedureContract<Input, Output, Extract<K, string>, Name, Transports>
33
+ ? // ? true
34
+ TProcedureContract<Input, Output, Extract<K, string>, Name, Transports>
47
35
  : Procedures[K] extends TSubscriptionContract<
48
36
  infer Input,
49
37
  infer Output,
50
38
  infer Options,
51
- infer Events
39
+ infer Events,
40
+ any,
41
+ any,
42
+ any
52
43
  >
53
44
  ? TSubscriptionContract<
54
45
  Input,
@@ -70,14 +61,14 @@ export interface TServiceContract<
70
61
  Name,
71
62
  Transports
72
63
  >
73
- : never
64
+ : Procedures[K]
74
65
  }
75
66
  events: {
76
67
  [K in Extract<keyof Events, string>]: Events[K] extends TEventContract<
77
68
  infer Payload
78
69
  >
79
70
  ? TEventContract<Payload, K, Name>
80
- : never
71
+ : Events[K]
81
72
  }
82
73
  timeout?: number
83
74
  }
@@ -95,12 +86,10 @@ export const ServiceContract = <
95
86
  timeout?: number,
96
87
  schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,
97
88
  ) => {
98
- if (!TypeRegistry.Has(ServiceKind)) TypeRegistry.Set(ServiceKind, () => true)
99
-
100
89
  const serviceProcedures = {}
101
90
 
102
91
  for (const [procedureName, procedure] of Object.entries(procedures)) {
103
- if (procedure[Kind] === SubscriptionKind) {
92
+ if (procedure.type === 'neemata:subscription') {
104
93
  serviceProcedures[procedureName] = {
105
94
  ...procedure,
106
95
  events: applyNames(procedure.events, {
@@ -115,12 +104,33 @@ export const ServiceContract = <
115
104
 
116
105
  return createSchema<TServiceContract<Name, Transports, Procedures, Events>>({
117
106
  ...schemaOptions,
118
- [Kind]: ServiceKind,
119
107
  name: name,
120
108
  type: 'neemata:service',
109
+ // @ts-expect-error
121
110
  procedures: applyNames(procedures, { serviceName: name }),
111
+ // @ts-expect-error
122
112
  events: applyNames(events, { serviceName: name }),
123
113
  transports,
124
114
  timeout,
125
115
  })
126
116
  }
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> }>