@nmtjs/contract 0.0.3 → 0.1.0
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/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/event.js +4 -4
- package/dist/schemas/event.js.map +1 -1
- package/dist/schemas/procedure.js +4 -5
- package/dist/schemas/procedure.js.map +1 -1
- package/dist/schemas/service.js +1 -6
- package/dist/schemas/service.js.map +1 -1
- package/dist/schemas/subscription.js +13 -14
- package/dist/schemas/subscription.js.map +1 -1
- package/dist/types/blob.js +13 -0
- package/dist/types/blob.js.map +1 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -18
- package/src/index.ts +31 -0
- package/src/schemas/event.ts +7 -11
- package/src/schemas/procedure.ts +21 -23
- package/src/schemas/service.ts +41 -31
- package/src/schemas/subscription.ts +27 -49
- package/src/types/blob.ts +25 -0
- package/src/utils.ts +5 -6
- package/dist/compiler.js +0 -50
- package/dist/compiler.js.map +0 -1
- package/dist/contract.js +0 -24
- package/dist/contract.js.map +0 -1
- package/dist/formats.js +0 -127
- package/dist/formats.js.map +0 -1
- package/dist/guards/blob.js +0 -3
- package/dist/guards/blob.js.map +0 -1
- package/dist/guards/event.js +0 -3
- package/dist/guards/event.js.map +0 -1
- package/dist/guards/native-enum.js +0 -3
- package/dist/guards/native-enum.js.map +0 -1
- package/dist/guards/nullable.js +0 -2
- package/dist/guards/nullable.js.map +0 -1
- package/dist/guards/procedure.js +0 -3
- package/dist/guards/procedure.js.map +0 -1
- package/dist/guards/service.js +0 -3
- package/dist/guards/service.js.map +0 -1
- package/dist/guards/subscription.js +0 -3
- package/dist/guards/subscription.js.map +0 -1
- package/dist/guards/union-enum.js +0 -3
- package/dist/guards/union-enum.js.map +0 -1
- package/dist/guards.js +0 -20
- package/dist/guards.js.map +0 -1
- package/dist/schemas/blob.js +0 -26
- package/dist/schemas/blob.js.map +0 -1
- package/dist/schemas/native-enum.js +0 -14
- package/dist/schemas/native-enum.js.map +0 -1
- package/dist/schemas/nullable.js +0 -5
- package/dist/schemas/nullable.js.map +0 -1
- package/dist/schemas/union-enum.js +0 -13
- package/dist/schemas/union-enum.js.map +0 -1
- package/src/compiler.ts +0 -63
- package/src/contract.ts +0 -62
- package/src/formats.ts +0 -181
- package/src/guards/blob.ts +0 -5
- package/src/guards/event.ts +0 -6
- package/src/guards/native-enum.ts +0 -7
- package/src/guards/nullable.ts +0 -14
- package/src/guards/procedure.ts +0 -6
- package/src/guards/service.ts +0 -6
- package/src/guards/subscription.ts +0 -10
- package/src/guards/union-enum.ts +0 -7
- package/src/guards.ts +0 -21
- package/src/schemas/blob.ts +0 -58
- package/src/schemas/native-enum.ts +0 -29
- package/src/schemas/nullable.ts +0 -6
- 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"}
|
package/dist/schemas/event.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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"}
|
package/dist/schemas/service.js
CHANGED
|
@@ -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
|
|
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 {
|
|
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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
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":["
|
|
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/
|
|
7
|
-
"default": "./dist/
|
|
8
|
-
"types": "./src/
|
|
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
|
-
"@
|
|
23
|
-
"@nmtjs/common": "0.0
|
|
12
|
+
"@nmtjs/type": "0.1.0",
|
|
13
|
+
"@nmtjs/common": "0.1.0"
|
|
24
14
|
},
|
|
25
15
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@nmtjs/common": "0.0
|
|
16
|
+
"@nmtjs/type": "0.1.0",
|
|
17
|
+
"@nmtjs/common": "0.1.0"
|
|
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
|
|
26
|
+
"version": "0.1.0",
|
|
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 })
|
package/src/schemas/event.ts
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
-
>
|
|
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
|
|
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
|
}
|
package/src/schemas/procedure.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
>
|
|
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
|
|
26
|
-
Output extends
|
|
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<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
43
|
-
Output extends
|
|
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
|
}
|
package/src/schemas/service.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
Transports extends { [K in string]?: true } = {},
|
|
16
|
-
Procedures extends Record<
|
|
12
|
+
Transports extends { [K in string]?: true } = { [K in string]?: true },
|
|
13
|
+
Procedures extends Record<string, TBaseProcedureContract> = Record<
|
|
17
14
|
string,
|
|
18
15
|
TProcedureContract | TSubscriptionContract
|
|
19
|
-
|
|
16
|
+
>,
|
|
20
17
|
Events extends Record<string, TEventContract> = Record<
|
|
21
18
|
string,
|
|
22
19
|
TEventContract
|
|
23
20
|
>,
|
|
24
|
-
>
|
|
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
|
-
?
|
|
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
|
-
:
|
|
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
|
-
:
|
|
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
|
|
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> }>
|