@magek/common 0.0.1 → 0.0.3

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.
@@ -49,7 +49,7 @@ export declare class Register {
49
49
  *
50
50
  * @param {UUID} requestID - The ID of the current request
51
51
  * @param {Record<string, string>} responseHeaders - The response headers object. It can be changed by the user.
52
- * @param {FlusherFunction} flusher - The provider-dependent function used to flush the events to the event store.
52
+ * @param {FlusherFunction} flusher - The runtime-dependent function used to flush the events to the event store.
53
53
  * @param {UserEnvelope} [currentUser] - The current user envelope, if available
54
54
  * @param {ContextEnvelope} [context] - The current context envelope, if available
55
55
  */
@@ -80,7 +80,7 @@ export declare class Register {
80
80
  */
81
81
  events(...events: Array<EventInterface | NotificationInterface>): Register;
82
82
  /**
83
- * Flushes the accumulated events and commands to the event store using the provider-depdent flusher function.
83
+ * Flushes the accumulated events and commands to the event store using the runtime-dependent flusher function.
84
84
  * This method can be called from a command or event handler to force the persistion of the events
85
85
  * to the event store. After the events have been flushed, the eventList is cleared, so the same
86
86
  * register instance can be used to register more events.
@@ -28,7 +28,7 @@ class Register {
28
28
  *
29
29
  * @param {UUID} requestID - The ID of the current request
30
30
  * @param {Record<string, string>} responseHeaders - The response headers object. It can be changed by the user.
31
- * @param {FlusherFunction} flusher - The provider-dependent function used to flush the events to the event store.
31
+ * @param {FlusherFunction} flusher - The runtime-dependent function used to flush the events to the event store.
32
32
  * @param {UserEnvelope} [currentUser] - The current user envelope, if available
33
33
  * @param {ContextEnvelope} [context] - The current context envelope, if available
34
34
  */
@@ -69,7 +69,7 @@ class Register {
69
69
  return this;
70
70
  }
71
71
  /**
72
- * Flushes the accumulated events and commands to the event store using the provider-depdent flusher function.
72
+ * Flushes the accumulated events and commands to the event store using the runtime-dependent flusher function.
73
73
  * This method can be called from a command or event handler to force the persistion of the events
74
74
  * to the event store. After the events have been flushed, the eventList is cleared, so the same
75
75
  * register instance can be used to register more events.
@@ -1,5 +1,5 @@
1
- import { TimeKey } from './uuid';
1
+ import { UUID } from './uuid';
2
2
  export interface SequenceKey {
3
3
  name: string;
4
- value: TimeKey;
4
+ value: UUID;
5
5
  }
@@ -3,16 +3,10 @@
3
3
  * Commands, Events or any other magek artifact.
4
4
  * New unique identifiers can be created using the
5
5
  * `UUID.generate` method.
6
+ *
7
+ * Uses UUIDv7 (RFC 9562) which provides time-ordering and
8
+ * lexicographic sortability with sub-millisecond precision.
6
9
  */
7
10
  export declare class UUID extends String {
8
11
  static generate(): UUID;
9
12
  }
10
- /** Time-based unique identifier. It's a string in the form <timestamp>-<random UUID>. */
11
- export declare class TimeKey extends String {
12
- /**
13
- * Time-based unique identifier generator
14
- * @param moment Number of milliseconds since epoch for the moment in which the identifier should be generated. It defaults to the current time.
15
- * @returns A unique identifier in the form "<moment>-<random UUID>"
16
- */
17
- static generate(moment?: number): TimeKey;
18
- }
@@ -1,28 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeKey = exports.UUID = void 0;
3
+ exports.UUID = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  /**
6
6
  * `UUID` type to work globally as a identifier for Entities,
7
7
  * Commands, Events or any other magek artifact.
8
8
  * New unique identifiers can be created using the
9
9
  * `UUID.generate` method.
10
+ *
11
+ * Uses UUIDv7 (RFC 9562) which provides time-ordering and
12
+ * lexicographic sortability with sub-millisecond precision.
10
13
  */
11
14
  class UUID extends String {
12
15
  static generate() {
13
- return (0, uuid_1.v4)();
16
+ return (0, uuid_1.v7)();
14
17
  }
15
18
  }
16
19
  exports.UUID = UUID;
17
- /** Time-based unique identifier. It's a string in the form <timestamp>-<random UUID>. */
18
- class TimeKey extends String {
19
- /**
20
- * Time-based unique identifier generator
21
- * @param moment Number of milliseconds since epoch for the moment in which the identifier should be generated. It defaults to the current time.
22
- * @returns A unique identifier in the form "<moment>-<random UUID>"
23
- */
24
- static generate(moment = Date.now()) {
25
- return `${moment}-${(0, uuid_1.v4)()}`;
26
- }
27
- }
28
- exports.TimeKey = TimeKey;
package/dist/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CommandMetadata, DataMigrationMetadata, EntityInterface, EntityMetadata, EventHandlerInterface, EventMetadata, EventStreamConfiguration, GlobalErrorHandlerMetadata, NotificationMetadata, ProjectionMetadata, QueryMetadata, ReadModelInterface, ReadModelMetadata, ReducerMetadata, RoleMetadata, ScheduledCommandMetadata, SchemaMigrationMetadata, TokenVerifier } from './concepts';
2
- import { ProviderLibrary } from './provider';
2
+ import { Runtime } from './runtime';
3
3
  import { EventStoreAdapter } from './event-store-adapter';
4
4
  import { ReadModelStoreAdapter } from './read-model-store-adapter';
5
5
  import { SessionStoreAdapter } from './session-store-adapter';
@@ -8,21 +8,20 @@ import { HealthIndicatorMetadata, Logger, SensorConfiguration } from '.';
8
8
  import { TraceConfiguration } from './instrumentation/trace-types';
9
9
  /**
10
10
  * Class used by external packages that needs to get a representation of
11
- * the Magek config. Used mainly for vendor-specific deployment packages
11
+ * the Magek config.
12
12
  */
13
13
  export declare class MagekConfig {
14
14
  readonly environmentName: string;
15
15
  logLevel: Level;
16
16
  logPrefix?: string;
17
17
  logger?: Logger;
18
- private _provider?;
18
+ private _runtime?;
19
19
  eventStoreAdapter?: EventStoreAdapter;
20
20
  readModelStoreAdapter?: ReadModelStoreAdapter;
21
21
  sessionStoreAdapter?: SessionStoreAdapter;
22
22
  appName: string;
23
23
  assets?: Array<string>;
24
24
  defaultResponseHeaders: Record<string, string>;
25
- injectable?: unknown;
26
25
  readonly subscriptions: {
27
26
  maxConnectionDurationInSeconds: number;
28
27
  maxDurationInSeconds: number;
@@ -88,8 +87,8 @@ export declare class MagekConfig {
88
87
  get thereAreRoles(): boolean;
89
88
  currentVersionFor(className: string): number;
90
89
  validate(): void;
91
- get provider(): ProviderLibrary;
92
- set provider(provider: ProviderLibrary);
90
+ get runtime(): Runtime;
91
+ set runtime(runtime: Runtime);
93
92
  get userProjectRootPath(): string;
94
93
  set userProjectRootPath(path: string);
95
94
  get eventStore(): EventStoreAdapter;
package/dist/config.js CHANGED
@@ -6,7 +6,7 @@ const path = require("path");
6
6
  const _1 = require(".");
7
7
  /**
8
8
  * Class used by external packages that needs to get a representation of
9
- * the Magek config. Used mainly for vendor-specific deployment packages
9
+ * the Magek config.
10
10
  */
11
11
  class MagekConfig {
12
12
  constructor(environmentName) {
@@ -120,13 +120,13 @@ class MagekConfig {
120
120
  validate() {
121
121
  this.validateAllMigrations();
122
122
  }
123
- get provider() {
124
- if (!this._provider)
125
- throw new Error('It is required to set a valid provider runtime in your configuration files');
126
- return this._provider;
123
+ get runtime() {
124
+ if (!this._runtime)
125
+ throw new Error('It is required to set a runtime implementation (graphQL, api, messaging, scheduled, sensor) in your configuration files');
126
+ return this._runtime;
127
127
  }
128
- set provider(provider) {
129
- this._provider = provider;
128
+ set runtime(runtime) {
129
+ this._runtime = runtime;
130
130
  }
131
131
  get userProjectRootPath() {
132
132
  if (!this._userProjectRootPath)
@@ -5,7 +5,7 @@ import { Class } from './typelevel';
5
5
  /**
6
6
  * An `Envelope` carries a command/event body together with the name
7
7
  * of its class. This is important information for the `Distributor` to
8
- * work. Each provider has to implement their own `Envelope`.
8
+ * work. Each runtime has to implement their own `Envelope`.
9
9
  */
10
10
  export interface Envelope {
11
11
  currentUser?: UserEnvelope;
@@ -167,7 +167,7 @@ export interface ContextEnvelope {
167
167
  headers: unknown;
168
168
  body: unknown;
169
169
  };
170
- /** Provider-dependent raw request context object */
170
+ /** Runtime-dependent raw request context object */
171
171
  rawContext: unknown;
172
172
  }
173
173
  export type EventEnvelopeFromDatabase = EventEnvelope & {
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ export * from './instrumentation/trace-types';
22
22
  export * from './sensor/health-indicator-configuration';
23
23
  export * from './internal-info';
24
24
  export * from './stream-types';
25
- export * from './provider';
25
+ export * from './runtime';
26
26
  export * from './event-store-adapter';
27
27
  export * from './read-model-store-adapter';
28
28
  export * from './session-store-adapter';
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ tslib_1.__exportStar(require("./instrumentation/trace-types"), exports);
25
25
  tslib_1.__exportStar(require("./sensor/health-indicator-configuration"), exports);
26
26
  tslib_1.__exportStar(require("./internal-info"), exports);
27
27
  tslib_1.__exportStar(require("./stream-types"), exports);
28
- tslib_1.__exportStar(require("./provider"), exports);
28
+ tslib_1.__exportStar(require("./runtime"), exports);
29
29
  tslib_1.__exportStar(require("./event-store-adapter"), exports);
30
30
  tslib_1.__exportStar(require("./read-model-store-adapter"), exports);
31
31
  tslib_1.__exportStar(require("./session-store-adapter"), exports);
@@ -25,7 +25,7 @@ export interface ReadModelStoreAdapter {
25
25
  fetch<TReadModel extends ReadModelInterface>(config: MagekConfig, readModelName: string, readModelID: UUID, sequenceKey?: SequenceKey): Promise<ReadOnlyNonEmptyArray<TReadModel> | undefined>;
26
26
  /**
27
27
  * Searches for read models based on specific parameters
28
- * This method signature matches the original provider library interface
28
+ * This method signature matches the original runtime interface
29
29
  *
30
30
  * @param config - The Magek configuration object
31
31
  * @param readModelName - The name of the read model type
@@ -1,13 +1,16 @@
1
1
  import { MagekConfig } from './config';
2
2
  import { GraphQLRequestEnvelope, GraphQLRequestEnvelopeError, HealthEnvelope, ScheduledCommandEnvelope } from './envelope';
3
- export interface ProviderLibrary {
4
- graphQL: ProviderGraphQLLibrary;
5
- api: ProviderAPIHandling;
6
- messaging: ProviderMessagingLibrary;
7
- scheduled: ScheduledCommandsLibrary;
8
- sensor: ProviderSensorLibrary;
3
+ export interface Runtime {
4
+ graphQL: GraphQLRuntime;
5
+ api: APIRuntime;
6
+ messaging: MessagingRuntime;
7
+ scheduled: ScheduledRuntime;
8
+ sensor: SensorRuntime;
9
9
  }
10
- export interface ProviderMessagingLibrary {
10
+ /**
11
+ * Runtime messaging adapter for pushing data to client connections.
12
+ */
13
+ export interface MessagingRuntime {
11
14
  /**
12
15
  * Sends a message to a specific connection.
13
16
  *
@@ -18,7 +21,7 @@ export interface ProviderMessagingLibrary {
18
21
  */
19
22
  sendMessage(config: MagekConfig, connectionID: string, data: unknown): Promise<void>;
20
23
  }
21
- export interface ProviderSensorLibrary {
24
+ export interface SensorRuntime {
22
25
  databaseEventsHealthDetails(config: MagekConfig): Promise<unknown>;
23
26
  databaseReadModelsHealthDetails(config: MagekConfig): Promise<unknown>;
24
27
  isDatabaseEventUp(config: MagekConfig): Promise<boolean>;
@@ -28,7 +31,7 @@ export interface ProviderSensorLibrary {
28
31
  graphQLFunctionUrl(config: MagekConfig): Promise<string>;
29
32
  rawRequestToHealthEnvelope(rawRequest: unknown): HealthEnvelope;
30
33
  }
31
- export interface ProviderGraphQLLibrary {
34
+ export interface GraphQLRuntime {
32
35
  /**
33
36
  * Converts a raw GraphQL request to a `GraphQLRequestEnvelope` or a `GraphQLRequestEnvelopeError`.
34
37
  *
@@ -46,7 +49,7 @@ export interface ProviderGraphQLLibrary {
46
49
  */
47
50
  handleResult(result?: unknown, headers?: Record<string, string>): Promise<unknown>;
48
51
  }
49
- export interface ProviderAPIHandling {
52
+ export interface APIRuntime {
50
53
  /**
51
54
  * Handles a successful API request by returning the response body.
52
55
  *
@@ -71,7 +74,7 @@ export interface ProviderAPIHandling {
71
74
  */
72
75
  healthRequestResult(body: unknown, isHealthy: boolean): Promise<unknown>;
73
76
  }
74
- export interface ScheduledCommandsLibrary {
77
+ export interface ScheduledRuntime {
75
78
  /**
76
79
  * Converts a raw message into a `ScheduledCommandEnvelope`.
77
80
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magek/common",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Contains Magek common helpers used by the core and provider packages",
5
5
  "keywords": [
6
6
  "framework-common-helpers"
@@ -33,11 +33,11 @@
33
33
  "uuid": "^13.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@magek/eslint-config": "^0.0.1",
36
+ "@magek/eslint-config": "^0.0.3",
37
37
  "@types/chai": "5.2.3",
38
38
  "@types/chai-as-promised": "8.0.2",
39
39
  "@types/mocha": "10.0.10",
40
- "@types/node": "22.19.3",
40
+ "@types/node": "22.19.7",
41
41
  "@types/sinon": "21.0.0",
42
42
  "@types/sinon-chai": "4.0.0",
43
43
  "@types/uuid": "11.0.0",
@@ -1,12 +0,0 @@
1
- export declare const DEFAULT_CHUNK_SIZE = 100;
2
- export interface AzureConfiguration {
3
- enableEventBatching: boolean;
4
- cosmos: {
5
- batchSize: number;
6
- requestOptions?: {
7
- consistencyLevel?: 'Strong' | 'BoundedStaleness' | 'Session' | 'Eventual' | 'ConsistentPrefix';
8
- disableRUPerMinuteUsage?: boolean;
9
- indexingDirective?: 'Include' | 'Exclude';
10
- };
11
- };
12
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CHUNK_SIZE = void 0;
4
- exports.DEFAULT_CHUNK_SIZE = 100;
@@ -1,7 +0,0 @@
1
- import { RocketDescriptor } from './rockets';
2
- export declare class RocketLoader {
3
- private static requireRocket;
4
- static loadRocket(rocketDescriptor: RocketDescriptor): {
5
- mountStack: Function;
6
- };
7
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RocketLoader = void 0;
4
- class RocketLoader {
5
- // Separate function to make it easier to mock in tests
6
- static requireRocket(rocketPackageName) {
7
- return require(rocketPackageName).default;
8
- }
9
- static loadRocket(rocketDescriptor) {
10
- const rocketBuilder = RocketLoader.requireRocket(rocketDescriptor.packageName);
11
- if (!rocketBuilder)
12
- throw new Error(`Could not load the rocket infrastructure package ${rocketDescriptor.packageName}. Make sure you installed it in your project devDependencies.`);
13
- if (typeof rocketBuilder !== 'function')
14
- throw new Error(`Could not initialize rocket infrastructure package ${rocketDescriptor.packageName}. It doesn't seem to implement a rocket builder method as default export.`);
15
- const rocket = rocketBuilder(rocketDescriptor.parameters);
16
- if (!(rocket === null || rocket === void 0 ? void 0 : rocket.mountStack))
17
- throw new Error(`The package ${rocketDescriptor.packageName} doesn't seem to be a rocket.`);
18
- return rocket;
19
- }
20
- }
21
- exports.RocketLoader = RocketLoader;
package/dist/rockets.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { MagekConfig } from './config';
2
- export declare const rocketFunctionIDEnvVar = "ROCKET_FUNCTION_ID";
3
- export type RocketFunction = (config: MagekConfig, request: unknown) => Promise<unknown>;
4
- export interface RocketDescriptor {
5
- packageName: string;
6
- parameters: unknown;
7
- }
8
- export interface RocketEnvelope {
9
- rocketId: string | undefined;
10
- }
package/dist/rockets.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rocketFunctionIDEnvVar = void 0;
4
- exports.rocketFunctionIDEnvVar = 'ROCKET_FUNCTION_ID';
File without changes