arvo-core 0.0.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.
- package/CHANGELOG.md +5 -0
- package/LICENSE.md +7 -0
- package/README.md +46 -0
- package/dist/ArvoContract/helpers.d.ts +15 -0
- package/dist/ArvoContract/helpers.js +19 -0
- package/dist/ArvoContract/index.d.ts +80 -0
- package/dist/ArvoContract/index.js +122 -0
- package/dist/ArvoContract/types.d.ts +31 -0
- package/dist/ArvoContract/types.js +2 -0
- package/dist/ArvoContract/validators.d.ts +9 -0
- package/dist/ArvoContract/validators.js +21 -0
- package/dist/ArvoEvent/helpers.d.ts +40 -0
- package/dist/ArvoEvent/helpers.js +76 -0
- package/dist/ArvoEvent/index.d.ts +88 -0
- package/dist/ArvoEvent/index.js +126 -0
- package/dist/ArvoEvent/schema.d.ts +86 -0
- package/dist/ArvoEvent/schema.js +130 -0
- package/dist/ArvoEvent/types.d.ts +61 -0
- package/dist/ArvoEvent/types.js +2 -0
- package/dist/ArvoEvent/utils.d.ts +8 -0
- package/dist/ArvoEvent/utils.js +24 -0
- package/dist/OpenTelemetry/index.d.ts +93 -0
- package/dist/OpenTelemetry/index.js +179 -0
- package/dist/OpenTelemetry/types.d.ts +40 -0
- package/dist/OpenTelemetry/types.js +2 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +38 -0
- package/dist/utils.d.ts +50 -0
- package/dist/utils.js +79 -0
- package/generate-changelog.sh +29 -0
- package/package.json +53 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
15
|
+
if (ar || !(i in from)) {
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
17
|
+
ar[i] = from[i];
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
21
|
+
};
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
23
|
+
exports.OTelNull = exports.createOtelSpan = exports.exceptionToSpan = exports.logToSpan = exports.getTelemetryCarrier = exports.getTelemetryContext = void 0;
|
24
|
+
var api_1 = require("@opentelemetry/api");
|
25
|
+
/**
|
26
|
+
* Retrieves the active context based on the provided trace header.
|
27
|
+
* @param traceparent - The trace header string.
|
28
|
+
* @returns The active context.
|
29
|
+
*/
|
30
|
+
var getTelemetryContext = function (traceparent) {
|
31
|
+
if (traceparent) {
|
32
|
+
return api_1.propagation.extract(api_1.context.active(), { traceparent: traceparent });
|
33
|
+
}
|
34
|
+
return api_1.context.active();
|
35
|
+
};
|
36
|
+
exports.getTelemetryContext = getTelemetryContext;
|
37
|
+
/**
|
38
|
+
* Parses the context from a span and active context.
|
39
|
+
* @param span - The span to parse the context from.
|
40
|
+
* @param activeContext - The active context (optional, defaults to the current active context).
|
41
|
+
* @returns The parsed telemetry context.
|
42
|
+
*/
|
43
|
+
var getTelemetryCarrier = function (span, activeContext) {
|
44
|
+
if (activeContext === void 0) { activeContext = api_1.context.active(); }
|
45
|
+
var carrier = {
|
46
|
+
traceparent: null,
|
47
|
+
tracestate: null,
|
48
|
+
};
|
49
|
+
api_1.propagation.inject(activeContext, carrier);
|
50
|
+
if (!carrier.traceparent) {
|
51
|
+
carrier.traceparent = "00-".concat(span.spanContext().traceId, "-").concat(span.spanContext().spanId, "-0").concat(span.spanContext().traceFlags);
|
52
|
+
}
|
53
|
+
return carrier;
|
54
|
+
};
|
55
|
+
exports.getTelemetryCarrier = getTelemetryCarrier;
|
56
|
+
/**
|
57
|
+
* Logs a message to a span with additional parameters.
|
58
|
+
* @param span - The span to log the message to.
|
59
|
+
* @param params - The parameters for the log message.
|
60
|
+
* @param params.level - The log level.
|
61
|
+
* @param params.message - The log message.
|
62
|
+
*/
|
63
|
+
var logToSpan = function (span, params) {
|
64
|
+
span.addEvent('log_message', __assign(__assign({}, params), { timestamp: performance.now() }));
|
65
|
+
};
|
66
|
+
exports.logToSpan = logToSpan;
|
67
|
+
/**
|
68
|
+
* Logs an exception to a span and sets exception-related attributes.
|
69
|
+
* @param span - The span to log the exception to.
|
70
|
+
* @param level - The log level for the exception.
|
71
|
+
* @param error - The error object to be logged.
|
72
|
+
*/
|
73
|
+
var exceptionToSpan = function (span, level, error) {
|
74
|
+
(0, exports.logToSpan)(span, {
|
75
|
+
level: level,
|
76
|
+
message: error.message,
|
77
|
+
});
|
78
|
+
span.setAttributes({
|
79
|
+
'exception.type': "[".concat(level, "] ").concat(error.name),
|
80
|
+
'exception.message': error.message,
|
81
|
+
'exception.stacktrace': error.stack || exports.OTelNull,
|
82
|
+
});
|
83
|
+
};
|
84
|
+
exports.exceptionToSpan = exceptionToSpan;
|
85
|
+
/**
|
86
|
+
* Creates a new OpenTelemetry span and executes the provided function within its context.
|
87
|
+
*
|
88
|
+
* This function enhances tracing by creating a new span, executing the given function within
|
89
|
+
* that span's context, and properly handling any errors that may occur. It also ensures that
|
90
|
+
* the wrapped function has access to the current span.
|
91
|
+
*
|
92
|
+
* @template TArgs - The type of the arguments array for the wrapped function.
|
93
|
+
* @template TReturn - The return type of the wrapped function.
|
94
|
+
*
|
95
|
+
* @param {TelemetryContext | string} telemetryContext - The OpenTelemetry context object or a tracer name.
|
96
|
+
* @param {string} spanName - The name of the span to be created.
|
97
|
+
* @param {SpanOptions} [spanOptions] - Optional configuration for the span.
|
98
|
+
* @param {(currentSpan: Span, ...args: TArgs) => TReturn} wrappedFunction - The function to be executed within the new span.
|
99
|
+
* This function will receive the current span as its first argument.
|
100
|
+
* @param {ThisParameterType<TFunction>} [thisArg] - The 'this' context to be used when calling the wrapped function.
|
101
|
+
* @param {...TArgs} args - The arguments to be passed to the wrapped function.
|
102
|
+
*
|
103
|
+
* @returns {TReturn} The result of the wrapped function execution.
|
104
|
+
*
|
105
|
+
* @throws {Error} Rethrows any error that occurs during the execution of the wrapped function.
|
106
|
+
*
|
107
|
+
* @example
|
108
|
+
* // Using with TelemetryContext
|
109
|
+
* const telemetryContext: TelemetryContext = {
|
110
|
+
* span: currentSpan,
|
111
|
+
* tracer: currentTracer,
|
112
|
+
* context: { traceparent: 'traceparent-value', tracestate: 'tracestate-value' }
|
113
|
+
* };
|
114
|
+
* const result = createOtelSpan(
|
115
|
+
* telemetryContext,
|
116
|
+
* 'ProcessOrder',
|
117
|
+
* { attributes: { orderId: '12345' } },
|
118
|
+
* (span, orderId) => {
|
119
|
+
* span.addEvent('Processing order');
|
120
|
+
* return processOrder(orderId);
|
121
|
+
* },
|
122
|
+
* null,
|
123
|
+
* '12345'
|
124
|
+
* );
|
125
|
+
*
|
126
|
+
* @example
|
127
|
+
* // Using with tracer name
|
128
|
+
* const result = createOtelSpan(
|
129
|
+
* 'OrderService',
|
130
|
+
* 'FetchOrderDetails',
|
131
|
+
* undefined,
|
132
|
+
* (span, orderId) => {
|
133
|
+
* span.setAttribute('orderId', orderId);
|
134
|
+
* return fetchOrderDetails(orderId);
|
135
|
+
* },
|
136
|
+
* null,
|
137
|
+
* '12345'
|
138
|
+
* );
|
139
|
+
*/
|
140
|
+
var createOtelSpan = function (telemetryContext, spanName, spanOptions, wrappedFunction, thisArg) {
|
141
|
+
var args = [];
|
142
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
143
|
+
args[_i - 5] = arguments[_i];
|
144
|
+
}
|
145
|
+
var activeContext = api_1.context.active();
|
146
|
+
var activeTracer;
|
147
|
+
if (typeof telemetryContext === 'string') {
|
148
|
+
activeTracer = api_1.trace.getTracer(telemetryContext);
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
activeContext = (0, exports.getTelemetryContext)(telemetryContext.context.traceparent);
|
152
|
+
activeTracer = telemetryContext.tracer;
|
153
|
+
}
|
154
|
+
var newSpan = activeTracer.startSpan(spanName, spanOptions, activeContext);
|
155
|
+
try {
|
156
|
+
var result = api_1.context.with(api_1.trace.setSpan(activeContext, newSpan), function () {
|
157
|
+
return wrappedFunction.call.apply(wrappedFunction, __spreadArray([thisArg, newSpan], args, false));
|
158
|
+
});
|
159
|
+
newSpan.setStatus({
|
160
|
+
code: api_1.SpanStatusCode.OK,
|
161
|
+
});
|
162
|
+
newSpan.end();
|
163
|
+
return result;
|
164
|
+
}
|
165
|
+
catch (error) {
|
166
|
+
(0, exports.exceptionToSpan)(newSpan, 'ERROR', error);
|
167
|
+
newSpan.setStatus({
|
168
|
+
code: api_1.SpanStatusCode.ERROR,
|
169
|
+
message: error.message,
|
170
|
+
});
|
171
|
+
newSpan.end();
|
172
|
+
throw error;
|
173
|
+
}
|
174
|
+
};
|
175
|
+
exports.createOtelSpan = createOtelSpan;
|
176
|
+
/**
|
177
|
+
* A constant representing a null or not applicable value in OpenTelemetry context.
|
178
|
+
*/
|
179
|
+
exports.OTelNull = 'N/A';
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { Span, Tracer } from '@opentelemetry/api';
|
2
|
+
/**
|
3
|
+
* Represents the available log levels for telemetry.
|
4
|
+
* - DEBUG: Used for detailed information, typically of interest only when diagnosing problems.
|
5
|
+
* - INFO: Used for general information about program execution.
|
6
|
+
* - WARNING: Indicates an unexpected event or a potential problem that doesn't prevent the program from working.
|
7
|
+
* - ERROR: Used for more serious problems that prevent a specific function or feature from working correctly.
|
8
|
+
* - CRITICAL: Used for very serious errors that might prevent the entire program from running.
|
9
|
+
*/
|
10
|
+
export type TelemetryLogLevel = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR' | 'CRITICAL';
|
11
|
+
/**
|
12
|
+
* Represents the context for telemetry.
|
13
|
+
* See reference standard documentation [here](https://www.w3.org/TR/trace-context/#design-overview)
|
14
|
+
*/
|
15
|
+
export type TelemetryCarrier = {
|
16
|
+
/** The traceparent header value */
|
17
|
+
traceparent: string | null;
|
18
|
+
/** The tracestate header value */
|
19
|
+
tracestate: string | null;
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* Represents the OpenTelemetry context for a handler.
|
23
|
+
* See reference documentation [here](https://opentelemetry.io/docs/languages/js/instrumentation/#traces)
|
24
|
+
*/
|
25
|
+
export type TelemetryContext = {
|
26
|
+
/**
|
27
|
+
* The current OpenTelemetry Span. If passed to a function,
|
28
|
+
* then for that function, this is the parent span object
|
29
|
+
*/
|
30
|
+
span: Span;
|
31
|
+
/**
|
32
|
+
* The current OpenTelemetry tracer object being
|
33
|
+
* used.
|
34
|
+
*/
|
35
|
+
tracer: Tracer;
|
36
|
+
/**
|
37
|
+
* The telemetry headers
|
38
|
+
*/
|
39
|
+
context: TelemetryCarrier;
|
40
|
+
};
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
import ArvoEvent from './ArvoEvent';
|
2
|
+
import { ArvoDataContentType } from './ArvoEvent/schema';
|
3
|
+
import { createArvoEvent } from './ArvoEvent/helpers';
|
4
|
+
import { CloudEventContext, CloudEventExtension, ArvoEventData, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent } from './ArvoEvent/types';
|
5
|
+
import { exceptionToSpan, logToSpan, getTelemetryContext, getTelemetryCarrier, createOtelSpan, OTelNull } from './OpenTelemetry';
|
6
|
+
import { TelemetryCarrier, TelemetryContext, TelemetryLogLevel } from './OpenTelemetry/types';
|
7
|
+
import { validateURI, cleanString } from './utils';
|
8
|
+
/**
|
9
|
+
* Collection of Zod schemas for validating various aspects of Arvo events.
|
10
|
+
* @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
|
11
|
+
* @property {z.ZodRecord} CloudEventExtensionSchema - Schema for custom CloudEvent extensions.
|
12
|
+
* @property {z.ZodRecord} ArvoDataSchema - Schema for Arvo event data payload.
|
13
|
+
* @property {z.ZodObject} ArvoExtensionSchema - Schema for Arvo-specific CloudEvent extensions.
|
14
|
+
* @property {z.ZodObject} OpenTelemetryExtensionSchema - Schema for OpenTelemetry extensions.
|
15
|
+
*/
|
16
|
+
declare const ArvoEventSchemas: {
|
17
|
+
CloudEventContextSchema: import("zod").ZodObject<{
|
18
|
+
id: import("zod").ZodString;
|
19
|
+
time: import("zod").ZodString;
|
20
|
+
source: import("zod").ZodEffects<import("zod").ZodString, string, string>;
|
21
|
+
specversion: import("zod").ZodEffects<import("zod").ZodString, "1.0", string>;
|
22
|
+
type: import("zod").ZodString;
|
23
|
+
subject: import("zod").ZodEffects<import("zod").ZodString, string, string>;
|
24
|
+
datacontenttype: import("zod").ZodDefault<import("zod").ZodEffects<import("zod").ZodString, string, string>>;
|
25
|
+
dataschema: import("zod").ZodNullable<import("zod").ZodEffects<import("zod").ZodString, string, string>>;
|
26
|
+
}, "strip", import("zod").ZodTypeAny, {
|
27
|
+
id: string;
|
28
|
+
time: string;
|
29
|
+
source: string;
|
30
|
+
specversion: "1.0";
|
31
|
+
type: string;
|
32
|
+
subject: string;
|
33
|
+
datacontenttype: string;
|
34
|
+
dataschema: string | null;
|
35
|
+
}, {
|
36
|
+
id: string;
|
37
|
+
time: string;
|
38
|
+
source: string;
|
39
|
+
specversion: string;
|
40
|
+
type: string;
|
41
|
+
subject: string;
|
42
|
+
dataschema: string | null;
|
43
|
+
datacontenttype?: string | undefined;
|
44
|
+
}>;
|
45
|
+
CloudEventExtensionSchema: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodBoolean, import("zod").ZodNumber, import("zod").ZodNull]>>;
|
46
|
+
ArvoDataSchema: import("zod").ZodEffects<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>, Record<string, any>, Record<string, any>>;
|
47
|
+
ArvoExtensionSchema: import("zod").ZodObject<{
|
48
|
+
to: import("zod").ZodNullable<import("zod").ZodEffects<import("zod").ZodString, string, string>>;
|
49
|
+
accesscontrol: import("zod").ZodNullable<import("zod").ZodString>;
|
50
|
+
redirectto: import("zod").ZodNullable<import("zod").ZodEffects<import("zod").ZodString, string, string>>;
|
51
|
+
executionunits: import("zod").ZodNullable<import("zod").ZodNumber>;
|
52
|
+
}, "strip", import("zod").ZodTypeAny, {
|
53
|
+
to: string | null;
|
54
|
+
accesscontrol: string | null;
|
55
|
+
redirectto: string | null;
|
56
|
+
executionunits: number | null;
|
57
|
+
}, {
|
58
|
+
to: string | null;
|
59
|
+
accesscontrol: string | null;
|
60
|
+
redirectto: string | null;
|
61
|
+
executionunits: number | null;
|
62
|
+
}>;
|
63
|
+
OpenTelemetryExtensionSchema: import("zod").ZodObject<{
|
64
|
+
traceparent: import("zod").ZodNullable<import("zod").ZodString>;
|
65
|
+
tracestate: import("zod").ZodNullable<import("zod").ZodString>;
|
66
|
+
}, "strip", import("zod").ZodTypeAny, {
|
67
|
+
traceparent: string | null;
|
68
|
+
tracestate: string | null;
|
69
|
+
}, {
|
70
|
+
traceparent: string | null;
|
71
|
+
tracestate: string | null;
|
72
|
+
}>;
|
73
|
+
};
|
74
|
+
export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, getTelemetryCarrier, getTelemetryContext, createOtelSpan, TelemetryCarrier, TelemetryContext, TelemetryLogLevel, OTelNull, validateURI, cleanString, };
|
package/dist/index.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.cleanString = exports.validateURI = exports.OTelNull = exports.createOtelSpan = exports.getTelemetryContext = exports.getTelemetryCarrier = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
|
7
|
+
var ArvoEvent_1 = __importDefault(require("./ArvoEvent"));
|
8
|
+
exports.ArvoEvent = ArvoEvent_1.default;
|
9
|
+
var schema_1 = require("./ArvoEvent/schema");
|
10
|
+
Object.defineProperty(exports, "ArvoDataContentType", { enumerable: true, get: function () { return schema_1.ArvoDataContentType; } });
|
11
|
+
var helpers_1 = require("./ArvoEvent/helpers");
|
12
|
+
Object.defineProperty(exports, "createArvoEvent", { enumerable: true, get: function () { return helpers_1.createArvoEvent; } });
|
13
|
+
var OpenTelemetry_1 = require("./OpenTelemetry");
|
14
|
+
Object.defineProperty(exports, "exceptionToSpan", { enumerable: true, get: function () { return OpenTelemetry_1.exceptionToSpan; } });
|
15
|
+
Object.defineProperty(exports, "logToSpan", { enumerable: true, get: function () { return OpenTelemetry_1.logToSpan; } });
|
16
|
+
Object.defineProperty(exports, "getTelemetryContext", { enumerable: true, get: function () { return OpenTelemetry_1.getTelemetryContext; } });
|
17
|
+
Object.defineProperty(exports, "getTelemetryCarrier", { enumerable: true, get: function () { return OpenTelemetry_1.getTelemetryCarrier; } });
|
18
|
+
Object.defineProperty(exports, "createOtelSpan", { enumerable: true, get: function () { return OpenTelemetry_1.createOtelSpan; } });
|
19
|
+
Object.defineProperty(exports, "OTelNull", { enumerable: true, get: function () { return OpenTelemetry_1.OTelNull; } });
|
20
|
+
var utils_1 = require("./utils");
|
21
|
+
Object.defineProperty(exports, "validateURI", { enumerable: true, get: function () { return utils_1.validateURI; } });
|
22
|
+
Object.defineProperty(exports, "cleanString", { enumerable: true, get: function () { return utils_1.cleanString; } });
|
23
|
+
/**
|
24
|
+
* Collection of Zod schemas for validating various aspects of Arvo events.
|
25
|
+
* @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
|
26
|
+
* @property {z.ZodRecord} CloudEventExtensionSchema - Schema for custom CloudEvent extensions.
|
27
|
+
* @property {z.ZodRecord} ArvoDataSchema - Schema for Arvo event data payload.
|
28
|
+
* @property {z.ZodObject} ArvoExtensionSchema - Schema for Arvo-specific CloudEvent extensions.
|
29
|
+
* @property {z.ZodObject} OpenTelemetryExtensionSchema - Schema for OpenTelemetry extensions.
|
30
|
+
*/
|
31
|
+
var ArvoEventSchemas = {
|
32
|
+
CloudEventContextSchema: schema_1.CloudEventContextSchema,
|
33
|
+
CloudEventExtensionSchema: schema_1.CloudEventExtensionSchema,
|
34
|
+
ArvoDataSchema: schema_1.ArvoDataSchema,
|
35
|
+
ArvoExtensionSchema: schema_1.ArvoExtensionSchema,
|
36
|
+
OpenTelemetryExtensionSchema: schema_1.OpenTelemetryExtensionSchema,
|
37
|
+
};
|
38
|
+
exports.ArvoEventSchemas = ArvoEventSchemas;
|
package/dist/utils.d.ts
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
/**
|
2
|
+
* Cleans a string by removing leading/trailing whitespace from each line,
|
3
|
+
* removing empty lines, and joining the remaining lines with newline characters.
|
4
|
+
*
|
5
|
+
* @param s - The input string to be cleaned.
|
6
|
+
* @returns A new string with cleaned content.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* const input = " Hello \n World \n\n ";
|
10
|
+
* const cleaned = cleanString(input);
|
11
|
+
* console.log(cleaned); // Output: "Hello\nWorld"
|
12
|
+
*/
|
13
|
+
export declare function cleanString(s: string): string;
|
14
|
+
/**
|
15
|
+
* Validates if a given string is a properly encoded URI.
|
16
|
+
*
|
17
|
+
* This function checks if the input string remains unchanged after being
|
18
|
+
* decoded and then re-encoded, which indicates that it's a valid URI.
|
19
|
+
*
|
20
|
+
* @param value - The string to be validated as a URI.
|
21
|
+
* @returns A boolean indicating whether the input is a valid URI (true) or not (false).
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* validateURI("https://example.com"); // Returns true
|
25
|
+
* validateURI("https://example.com/path with spaces"); // Returns false
|
26
|
+
* validateURI("https://example.com/path%20with%20spaces"); // Returns true
|
27
|
+
*/
|
28
|
+
export declare const validateURI: (value: string) => boolean;
|
29
|
+
/**
|
30
|
+
* Creates an RFC 3339 compliant timestamp string with an optional UTC offset.
|
31
|
+
*
|
32
|
+
* @param offsetHours - The number of hours to offset from UTC. Positive values
|
33
|
+
* represent hours ahead of UTC, negative values represent
|
34
|
+
* hours behind UTC. Defaults to 0 (UTC).
|
35
|
+
* @returns A string representing the current date and time in RFC 3339 format
|
36
|
+
* with the specified UTC offset.
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
* // Returns current time in UTC
|
40
|
+
* createTimestamp();
|
41
|
+
*
|
42
|
+
* @example
|
43
|
+
* // Returns current time with +2 hours offset
|
44
|
+
* createTimestamp(2);
|
45
|
+
*
|
46
|
+
* @example
|
47
|
+
* // Returns current time with -5 hours offset
|
48
|
+
* createTimestamp(-5);
|
49
|
+
*/
|
50
|
+
export declare const createTimestamp: (offsetHours?: number) => string;
|
package/dist/utils.js
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createTimestamp = exports.validateURI = void 0;
|
4
|
+
exports.cleanString = cleanString;
|
5
|
+
/**
|
6
|
+
* Cleans a string by removing leading/trailing whitespace from each line,
|
7
|
+
* removing empty lines, and joining the remaining lines with newline characters.
|
8
|
+
*
|
9
|
+
* @param s - The input string to be cleaned.
|
10
|
+
* @returns A new string with cleaned content.
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* const input = " Hello \n World \n\n ";
|
14
|
+
* const cleaned = cleanString(input);
|
15
|
+
* console.log(cleaned); // Output: "Hello\nWorld"
|
16
|
+
*/
|
17
|
+
function cleanString(s) {
|
18
|
+
return s
|
19
|
+
.split('\n')
|
20
|
+
.map(function (item) { return item.trim(); })
|
21
|
+
.filter(function (item) { return Boolean(item); })
|
22
|
+
.join('\n');
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* Validates if a given string is a properly encoded URI.
|
26
|
+
*
|
27
|
+
* This function checks if the input string remains unchanged after being
|
28
|
+
* decoded and then re-encoded, which indicates that it's a valid URI.
|
29
|
+
*
|
30
|
+
* @param value - The string to be validated as a URI.
|
31
|
+
* @returns A boolean indicating whether the input is a valid URI (true) or not (false).
|
32
|
+
*
|
33
|
+
* @example
|
34
|
+
* validateURI("https://example.com"); // Returns true
|
35
|
+
* validateURI("https://example.com/path with spaces"); // Returns false
|
36
|
+
* validateURI("https://example.com/path%20with%20spaces"); // Returns true
|
37
|
+
*/
|
38
|
+
var validateURI = function (value) {
|
39
|
+
try {
|
40
|
+
return value === encodeURI(decodeURI(value));
|
41
|
+
}
|
42
|
+
catch (_a) {
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
};
|
46
|
+
exports.validateURI = validateURI;
|
47
|
+
/**
|
48
|
+
* Creates an RFC 3339 compliant timestamp string with an optional UTC offset.
|
49
|
+
*
|
50
|
+
* @param offsetHours - The number of hours to offset from UTC. Positive values
|
51
|
+
* represent hours ahead of UTC, negative values represent
|
52
|
+
* hours behind UTC. Defaults to 0 (UTC).
|
53
|
+
* @returns A string representing the current date and time in RFC 3339 format
|
54
|
+
* with the specified UTC offset.
|
55
|
+
*
|
56
|
+
* @example
|
57
|
+
* // Returns current time in UTC
|
58
|
+
* createTimestamp();
|
59
|
+
*
|
60
|
+
* @example
|
61
|
+
* // Returns current time with +2 hours offset
|
62
|
+
* createTimestamp(2);
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
* // Returns current time with -5 hours offset
|
66
|
+
* createTimestamp(-5);
|
67
|
+
*/
|
68
|
+
var createTimestamp = function (offsetHours) {
|
69
|
+
if (offsetHours === void 0) { offsetHours = 0; }
|
70
|
+
var now = new Date();
|
71
|
+
var offsetMinutes = offsetHours * 60;
|
72
|
+
now.setMinutes(now.getMinutes() - now.getTimezoneOffset() + offsetMinutes);
|
73
|
+
return now
|
74
|
+
.toISOString()
|
75
|
+
.replace('Z', offsetHours >= 0
|
76
|
+
? "+".concat(String(offsetHours).padStart(2, '0'), ":00")
|
77
|
+
: "-".concat(String(Math.abs(offsetHours)).padStart(2, '0'), ":00"));
|
78
|
+
};
|
79
|
+
exports.createTimestamp = createTimestamp;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# File name
|
4
|
+
CHANGELOG_FILE="CHANGELOG.md"
|
5
|
+
|
6
|
+
# Get current date
|
7
|
+
CURRENT_DATE=$(date +"%Y-%m-%d")
|
8
|
+
|
9
|
+
# Prompt for version
|
10
|
+
read -p "Enter version number: " VERSION
|
11
|
+
|
12
|
+
# Prompt for description
|
13
|
+
read -p "Enter change description: " DESCRIPTION
|
14
|
+
|
15
|
+
# Create or append to CHANGELOG.md
|
16
|
+
if [ ! -f "$CHANGELOG_FILE" ]; then
|
17
|
+
echo "# Changelog" > "$CHANGELOG_FILE"
|
18
|
+
echo "" >> "$CHANGELOG_FILE"
|
19
|
+
fi
|
20
|
+
|
21
|
+
# Add new entry
|
22
|
+
{
|
23
|
+
echo "## [$VERSION] - $CURRENT_DATE"
|
24
|
+
echo ""
|
25
|
+
echo "- $DESCRIPTION"
|
26
|
+
echo ""
|
27
|
+
} >> "$CHANGELOG_FILE"
|
28
|
+
|
29
|
+
echo "Changelog updated successfully!"
|
package/package.json
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
{
|
2
|
+
"name": "arvo-core",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "This core package contains all the core classes and components of the Arvo Event Driven System",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"scripts": {
|
7
|
+
"build": "tsc",
|
8
|
+
"start": "node ./dist/index.js",
|
9
|
+
"dev": "ts-node ./src/index.ts",
|
10
|
+
"test": "jest --passWithNoTests --runInBand --detectOpenHandles --forceExit",
|
11
|
+
"format": "npx prettier --write .",
|
12
|
+
"doc": "npx typedoc"
|
13
|
+
},
|
14
|
+
"keywords": [
|
15
|
+
"arvo",
|
16
|
+
"event-driven architecture",
|
17
|
+
"xorca",
|
18
|
+
"core",
|
19
|
+
"cloudevent",
|
20
|
+
"opentelemetry",
|
21
|
+
"orchestrator"
|
22
|
+
],
|
23
|
+
"author": "Saad Ahmad <saadkwi12@hotmail.com>",
|
24
|
+
"license": "MIT",
|
25
|
+
"devDependencies": {
|
26
|
+
"@jest/globals": "^29.7.0",
|
27
|
+
"@opentelemetry/auto-instrumentations-node": "^0.49.1",
|
28
|
+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.52.1",
|
29
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.52.1",
|
30
|
+
"@opentelemetry/resources": "^1.25.1",
|
31
|
+
"@opentelemetry/sdk-metrics": "^1.25.1",
|
32
|
+
"@opentelemetry/sdk-node": "^0.52.1",
|
33
|
+
"@opentelemetry/sdk-trace-node": "^1.25.1",
|
34
|
+
"@opentelemetry/semantic-conventions": "^1.25.1",
|
35
|
+
"@types/jest": "^29.5.12",
|
36
|
+
"@types/node": "^22.5.0",
|
37
|
+
"@types/uuid": "^10.0.0",
|
38
|
+
"dotenv": "^16.4.5",
|
39
|
+
"jest": "^29.7.0",
|
40
|
+
"prettier": "^3.3.3",
|
41
|
+
"ts-jest": "^29.2.5",
|
42
|
+
"ts-node": "^10.9.2",
|
43
|
+
"typedoc": "^0.26.6",
|
44
|
+
"typedoc-plugin-zod": "^1.2.1",
|
45
|
+
"typescript": "^5.5.4"
|
46
|
+
},
|
47
|
+
"dependencies": {
|
48
|
+
"@opentelemetry/api": "^1.9.0",
|
49
|
+
"uuid": "^10.0.0",
|
50
|
+
"zod": "^3.23.8",
|
51
|
+
"zod-to-json-schema": "^3.23.2"
|
52
|
+
}
|
53
|
+
}
|