arvo-core 1.1.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,7 @@ import { ArvoEventData, CloudEventExtension, CreateArvoEvent } from './types';
22
22
  * - If no `datacontenttype` is provided, it defaults to `application/cloudevents+json;charset=UTF-8;profile=arvo`.
23
23
  * - If a non-compatible `datacontenttype` is provided, a warning will be logged to the span.
24
24
  * - The `source`, `subject`, `to`, `redirectto`, and `dataschema` fields are URI-encoded.
25
+ * - If no `to` (null, undefined or empty string) is provided, then the `type` value is used by default
25
26
  *
26
27
  * @example
27
28
  * const event = createArvoEvent(
@@ -31,7 +32,7 @@ import { ArvoEventData, CloudEventExtension, CreateArvoEvent } from './types';
31
32
  * subject: 'example-subject',
32
33
  * data: { key: 'value' }
33
34
  * },
34
- * { customExtension: 'value' },
35
+ * { customextension: 'value' },
35
36
  * );
36
37
  */
37
38
  export declare const createArvoEvent: <TData extends ArvoEventData, TExtension extends CloudEventExtension, TType extends string>(event: CreateArvoEvent<TData, TType>, extensions?: TExtension) => ArvoEvent<TData, TExtension, TType>;
@@ -32,6 +32,7 @@ var uuid_1 = require("uuid");
32
32
  * - If no `datacontenttype` is provided, it defaults to `application/cloudevents+json;charset=UTF-8;profile=arvo`.
33
33
  * - If a non-compatible `datacontenttype` is provided, a warning will be logged to the span.
34
34
  * - The `source`, `subject`, `to`, `redirectto`, and `dataschema` fields are URI-encoded.
35
+ * - If no `to` (null, undefined or empty string) is provided, then the `type` value is used by default
35
36
  *
36
37
  * @example
37
38
  * const event = createArvoEvent(
@@ -41,7 +42,7 @@ var uuid_1 = require("uuid");
41
42
  * subject: 'example-subject',
42
43
  * data: { key: 'value' }
43
44
  * },
44
- * { customExtension: 'value' },
45
+ * { customextension: 'value' },
45
46
  * );
46
47
  */
47
48
  var createArvoEvent = function (event, extensions) {
@@ -70,7 +71,7 @@ var createArvoEvent = function (event, extensions) {
70
71
  time: (_h = event.time) !== null && _h !== void 0 ? _h : (0, utils_1.createTimestamp)(),
71
72
  source: encodeURI(event.source),
72
73
  subject: encodeURI(event.subject),
73
- to: event.to ? encodeURI(event.to) : null,
74
+ to: event.to ? encodeURI(event.to) : encodeURI(event.type),
74
75
  redirectto: event.redirectto ? encodeURI(event.redirectto) : null,
75
76
  dataschema: event.dataschema ? encodeURI(event.dataschema) : null,
76
77
  }, event.data, extensions);
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, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOchestratorVersion, };
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, };
@@ -0,0 +1,71 @@
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
+ } : never;
71
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "This core package contains all the core classes and components of the Arvo Event Driven System",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {