arvo-core 1.1.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +3 -2
- package/dist/types.d.ts +74 -0
- package/dist/types.js +2 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -6,7 +6,7 @@ import { exceptionToSpan, logToSpan, OTelNull, currentOpenTelemetryHeaders } fro
|
|
6
6
|
import { OpenTelemetryHeaders, TelemetryLogLevel } from './OpenTelemetry/types';
|
7
7
|
import { validateURI, cleanString } from './utils';
|
8
8
|
import ArvoContract from './ArvoContract';
|
9
|
-
import { createArvoContract, InferArvoContract } from './ArvoContract/helpers';
|
9
|
+
import { createArvoContract, InferArvoContract as InferArvoContractType } from './ArvoContract/helpers';
|
10
10
|
import { ArvoContractValidators } from './ArvoContract/validators';
|
11
11
|
import { ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractJSONSchema } from './ArvoContract/types';
|
12
12
|
import ArvoContractLibrary from './ArvoContractLibrary';
|
@@ -23,6 +23,7 @@ import { ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema } f
|
|
23
23
|
import { ArvoOrchestrationSubjectContent, ArvoOchestratorVersion } from './ArvoOrchestrationSubject/type';
|
24
24
|
import ArvoEventHttp from './ArvoEventHttp';
|
25
25
|
import { ArvoEventHttpConfig } from './ArvoEventHttp/types';
|
26
|
+
import { InferArvoContract, InferArvoEvent } from './types';
|
26
27
|
/**
|
27
28
|
* Collection of Zod schemas for validating various aspects of Arvo events.
|
28
29
|
* @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
|
@@ -89,4 +90,4 @@ declare const ArvoEventSchemas: {
|
|
89
90
|
tracestate: string | null;
|
90
91
|
}>;
|
91
92
|
};
|
92
|
-
export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord,
|
93
|
+
export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, };
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import ArvoContract from './ArvoContract';
|
3
|
+
import ArvoEvent from './ArvoEvent';
|
4
|
+
import { ArvoExtension, OpenTelemetryExtension } from './ArvoEvent/types';
|
5
|
+
/**
|
6
|
+
* A type utility that infers the structure of an ArvoEvent.
|
7
|
+
*
|
8
|
+
* @template T - The type to infer from, expected to be an ArvoEvent.
|
9
|
+
*
|
10
|
+
* @returns An object type that includes all properties of an ArvoEvent,
|
11
|
+
* including its data, extensions, and standard CloudEvents properties.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* type MyEvent = InferArvoEvent<ArvoEvent<{ message: string }, { customField: number }, 'my.event.type'>>;
|
15
|
+
* // MyEvent will have properties like id, source, data.message, customField, etc.
|
16
|
+
*/
|
17
|
+
export type InferArvoEvent<T> = T extends ArvoEvent<infer TData, infer TExtension, infer TType> ? {
|
18
|
+
/** Unique identifier of the event */
|
19
|
+
id: string;
|
20
|
+
/** Identifies the context in which an event happened */
|
21
|
+
source: string;
|
22
|
+
/** The version of the CloudEvents specification */
|
23
|
+
specversion: string;
|
24
|
+
/** Describes the type of event related to the originating occurrence */
|
25
|
+
type: TType;
|
26
|
+
/** Describes the subject of the event in the context of the event producer */
|
27
|
+
subject: string;
|
28
|
+
/** Content type of the data value */
|
29
|
+
datacontenttype: string;
|
30
|
+
/** A link to the schema that the data adheres to */
|
31
|
+
dataschema: string | null;
|
32
|
+
/** Event payload */
|
33
|
+
data: TData;
|
34
|
+
/** Timestamp of when the occurrence happened */
|
35
|
+
time: string;
|
36
|
+
} & ArvoExtension & OpenTelemetryExtension & TExtension : never;
|
37
|
+
/**
|
38
|
+
* Helper type to infer the TypeScript type from a Zod schema.
|
39
|
+
*
|
40
|
+
* @template T - The Zod schema type to infer from.
|
41
|
+
*
|
42
|
+
* @returns The TypeScript type that corresponds to the Zod schema.
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
* const mySchema = z.object({ name: z.string(), age: z.number() });
|
46
|
+
* type MyType = InferZodSchema<typeof mySchema>;
|
47
|
+
* // MyType will be { name: string; age: number; }
|
48
|
+
*/
|
49
|
+
type InferZodSchema<T> = T extends z.ZodTypeAny ? z.infer<T> : never;
|
50
|
+
/**
|
51
|
+
* A type utility that infers the structure of an ArvoContract.
|
52
|
+
*
|
53
|
+
* @template T - The type to infer from, expected to be an ArvoContract.
|
54
|
+
*
|
55
|
+
* @returns An object type that includes the URI, accepted event type, and emitted event types of the contract.
|
56
|
+
*
|
57
|
+
* @example
|
58
|
+
* const myContract = new ArvoContract('my-uri', 'my-type', z.object({ input: z.string() }), {
|
59
|
+
* 'output.event': z.object({ result: z.number() })
|
60
|
+
* });
|
61
|
+
* type MyContractType = InferArvoContract<typeof myContract>;
|
62
|
+
* // MyContractType will have properties uri, accepts, and emits
|
63
|
+
*/
|
64
|
+
export type InferArvoContract<T extends ArvoContract<string, string, z.ZodTypeAny, Record<string, z.ZodTypeAny>>> = T extends ArvoContract<infer TUri, infer TType, infer TAcceptSchema, infer TEmits> ? {
|
65
|
+
uri: TUri;
|
66
|
+
accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TAcceptSchema>, {}, TType>>;
|
67
|
+
emits: {
|
68
|
+
[K in keyof TEmits]: InferArvoEvent<ArvoEvent<InferZodSchema<TEmits[K]>, {}, K & string>>;
|
69
|
+
} & {
|
70
|
+
[K in `sys.${TType}.error`]: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
|
71
|
+
};
|
72
|
+
systemError: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
|
73
|
+
} : never;
|
74
|
+
export {};
|
package/dist/types.js
ADDED