@magek/common 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.
Files changed (129) hide show
  1. package/dist/app.d.ts +17 -0
  2. package/dist/app.js +2 -0
  3. package/dist/concepts/authorizers.d.ts +7 -0
  4. package/dist/concepts/authorizers.js +2 -0
  5. package/dist/concepts/command.d.ts +14 -0
  6. package/dist/concepts/command.js +2 -0
  7. package/dist/concepts/data-migration.d.ts +19 -0
  8. package/dist/concepts/data-migration.js +8 -0
  9. package/dist/concepts/entity.d.ts +12 -0
  10. package/dist/concepts/entity.js +2 -0
  11. package/dist/concepts/event-handler.d.ts +6 -0
  12. package/dist/concepts/event-handler.js +2 -0
  13. package/dist/concepts/event-stream-configuration.d.ts +14 -0
  14. package/dist/concepts/event-stream-configuration.js +2 -0
  15. package/dist/concepts/event.d.ts +12 -0
  16. package/dist/concepts/event.js +2 -0
  17. package/dist/concepts/filter-hooks.d.ts +15 -0
  18. package/dist/concepts/filter-hooks.js +2 -0
  19. package/dist/concepts/global-error-handler-metadata.d.ts +24 -0
  20. package/dist/concepts/global-error-handler-metadata.js +2 -0
  21. package/dist/concepts/index.d.ts +21 -0
  22. package/dist/concepts/index.js +24 -0
  23. package/dist/concepts/migration.d.ts +8 -0
  24. package/dist/concepts/migration.js +2 -0
  25. package/dist/concepts/notification.d.ts +12 -0
  26. package/dist/concepts/notification.js +2 -0
  27. package/dist/concepts/projection-metadata.d.ts +15 -0
  28. package/dist/concepts/projection-metadata.js +8 -0
  29. package/dist/concepts/query.d.ts +21 -0
  30. package/dist/concepts/query.js +2 -0
  31. package/dist/concepts/read-model.d.ts +33 -0
  32. package/dist/concepts/read-model.js +8 -0
  33. package/dist/concepts/reducer-metadata.d.ts +5 -0
  34. package/dist/concepts/reducer-metadata.js +2 -0
  35. package/dist/concepts/register.d.ts +91 -0
  36. package/dist/concepts/register.js +84 -0
  37. package/dist/concepts/role.d.ts +27 -0
  38. package/dist/concepts/role.js +2 -0
  39. package/dist/concepts/scheduled-command.d.ts +10 -0
  40. package/dist/concepts/scheduled-command.js +2 -0
  41. package/dist/concepts/sequence-metadata.d.ts +5 -0
  42. package/dist/concepts/sequence-metadata.js +2 -0
  43. package/dist/concepts/token-verifier.d.ts +25 -0
  44. package/dist/concepts/token-verifier.js +2 -0
  45. package/dist/concepts/uuid.d.ts +18 -0
  46. package/dist/concepts/uuid.js +28 -0
  47. package/dist/config.d.ts +122 -0
  48. package/dist/config.js +180 -0
  49. package/dist/data-migration-parameters.d.ts +3 -0
  50. package/dist/data-migration-parameters.js +2 -0
  51. package/dist/envelope.d.ts +188 -0
  52. package/dist/envelope.js +2 -0
  53. package/dist/errors/command-handler-global-error.d.ts +8 -0
  54. package/dist/errors/command-handler-global-error.js +12 -0
  55. package/dist/errors/event-global-error.d.ts +6 -0
  56. package/dist/errors/event-global-error.js +11 -0
  57. package/dist/errors/event-handler-global-error.d.ts +9 -0
  58. package/dist/errors/event-handler-global-error.js +13 -0
  59. package/dist/errors/global-error-container.d.ts +4 -0
  60. package/dist/errors/global-error-container.js +9 -0
  61. package/dist/errors/index.d.ts +9 -0
  62. package/dist/errors/index.js +12 -0
  63. package/dist/errors/projection-global-error.d.ts +10 -0
  64. package/dist/errors/projection-global-error.js +14 -0
  65. package/dist/errors/query-handler-global-error.d.ts +6 -0
  66. package/dist/errors/query-handler-global-error.js +11 -0
  67. package/dist/errors/reducer-global-error.d.ts +10 -0
  68. package/dist/errors/reducer-global-error.js +14 -0
  69. package/dist/errors/schedule-command-global-error.d.ts +8 -0
  70. package/dist/errors/schedule-command-global-error.js +12 -0
  71. package/dist/errors/snapshot-persist-handler-global-error.d.ts +16 -0
  72. package/dist/errors/snapshot-persist-handler-global-error.js +21 -0
  73. package/dist/errors.d.ts +30 -0
  74. package/dist/errors.js +60 -0
  75. package/dist/event-store-adapter.d.ts +123 -0
  76. package/dist/event-store-adapter.js +2 -0
  77. package/dist/field-decorator.d.ts +63 -0
  78. package/dist/field-decorator.js +122 -0
  79. package/dist/graphql-websocket-messages.d.ts +65 -0
  80. package/dist/graphql-websocket-messages.js +55 -0
  81. package/dist/groups.d.ts +4 -0
  82. package/dist/groups.js +9 -0
  83. package/dist/http-service.d.ts +10 -0
  84. package/dist/http-service.js +50 -0
  85. package/dist/index.d.ts +30 -0
  86. package/dist/index.js +33 -0
  87. package/dist/instances.d.ts +47 -0
  88. package/dist/instances.js +136 -0
  89. package/dist/instrumentation/trace-types.d.ts +52 -0
  90. package/dist/instrumentation/trace-types.js +34 -0
  91. package/dist/internal-info.d.ts +2 -0
  92. package/dist/internal-info.js +6 -0
  93. package/dist/logger.d.ts +14 -0
  94. package/dist/logger.js +33 -0
  95. package/dist/metadata-types.d.ts +28 -0
  96. package/dist/metadata-types.js +12 -0
  97. package/dist/promises.d.ts +25 -0
  98. package/dist/promises.js +42 -0
  99. package/dist/provider/azure-configuration.d.ts +12 -0
  100. package/dist/provider/azure-configuration.js +4 -0
  101. package/dist/provider.d.ts +83 -0
  102. package/dist/provider.js +2 -0
  103. package/dist/read-model-store-adapter.d.ts +84 -0
  104. package/dist/read-model-store-adapter.js +2 -0
  105. package/dist/retrier.d.ts +12 -0
  106. package/dist/retrier.js +36 -0
  107. package/dist/rocket-loader.d.ts +7 -0
  108. package/dist/rocket-loader.js +21 -0
  109. package/dist/rockets.d.ts +10 -0
  110. package/dist/rockets.js +4 -0
  111. package/dist/run-command.d.ts +5 -0
  112. package/dist/run-command.js +48 -0
  113. package/dist/schedule.d.ts +8 -0
  114. package/dist/schedule.js +2 -0
  115. package/dist/searcher.d.ts +98 -0
  116. package/dist/searcher.js +79 -0
  117. package/dist/sensor/health-indicator-configuration.d.ts +60 -0
  118. package/dist/sensor/health-indicator-configuration.js +31 -0
  119. package/dist/session-store-adapter.d.ts +103 -0
  120. package/dist/session-store-adapter.js +2 -0
  121. package/dist/stream-types.d.ts +1 -0
  122. package/dist/stream-types.js +2 -0
  123. package/dist/super-kind.d.ts +2 -0
  124. package/dist/super-kind.js +5 -0
  125. package/dist/typelevel.d.ts +28 -0
  126. package/dist/typelevel.js +9 -0
  127. package/dist/user-app.d.ts +18 -0
  128. package/dist/user-app.js +2 -0
  129. package/package.json +66 -0
@@ -0,0 +1,9 @@
1
+ export * from './command-handler-global-error';
2
+ export * from './query-handler-global-error';
3
+ export * from './event-handler-global-error';
4
+ export * from './global-error-container';
5
+ export * from './projection-global-error';
6
+ export * from './reducer-global-error';
7
+ export * from './schedule-command-global-error';
8
+ export * from './snapshot-persist-handler-global-error';
9
+ export * from './event-global-error';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./command-handler-global-error"), exports);
5
+ tslib_1.__exportStar(require("./query-handler-global-error"), exports);
6
+ tslib_1.__exportStar(require("./event-handler-global-error"), exports);
7
+ tslib_1.__exportStar(require("./global-error-container"), exports);
8
+ tslib_1.__exportStar(require("./projection-global-error"), exports);
9
+ tslib_1.__exportStar(require("./reducer-global-error"), exports);
10
+ tslib_1.__exportStar(require("./schedule-command-global-error"), exports);
11
+ tslib_1.__exportStar(require("./snapshot-persist-handler-global-error"), exports);
12
+ tslib_1.__exportStar(require("./event-global-error"), exports);
@@ -0,0 +1,10 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { EntityInterface, ProjectionMetadata, ReadModelInterface } from '../concepts';
3
+ import { EntitySnapshotEnvelope } from '../envelope';
4
+ export declare class ProjectionGlobalError extends GlobalErrorContainer {
5
+ readonly entityEnvelope: EntitySnapshotEnvelope;
6
+ readonly entity: EntityInterface;
7
+ readonly readModel: ReadModelInterface | undefined;
8
+ readonly projectionMetadata: ProjectionMetadata<EntityInterface, ReadModelInterface>;
9
+ constructor(entityEnvelope: EntitySnapshotEnvelope, entity: EntityInterface, readModel: ReadModelInterface | undefined, projectionMetadata: ProjectionMetadata<EntityInterface, ReadModelInterface>, originalError: Error);
10
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectionGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class ProjectionGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(entityEnvelope, entity, readModel, projectionMetadata, originalError) {
7
+ super(originalError);
8
+ this.entityEnvelope = entityEnvelope;
9
+ this.entity = entity;
10
+ this.readModel = readModel;
11
+ this.projectionMetadata = projectionMetadata;
12
+ }
13
+ }
14
+ exports.ProjectionGlobalError = ProjectionGlobalError;
@@ -0,0 +1,6 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { QueryEnvelope } from '../envelope';
3
+ export declare class QueryHandlerGlobalError extends GlobalErrorContainer {
4
+ readonly query: QueryEnvelope;
5
+ constructor(query: QueryEnvelope, originalError: Error);
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryHandlerGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class QueryHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(query, originalError) {
7
+ super(originalError);
8
+ this.query = query;
9
+ }
10
+ }
11
+ exports.QueryHandlerGlobalError = QueryHandlerGlobalError;
@@ -0,0 +1,10 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { EntityInterface, EventInterface, ReducerMetadata } from '../concepts';
3
+ import { EventEnvelope } from '../envelope';
4
+ export declare class ReducerGlobalError extends GlobalErrorContainer {
5
+ readonly eventEnvelope: EventEnvelope;
6
+ readonly eventInstance: EventInterface;
7
+ readonly snapshotInstance: EntityInterface | null;
8
+ readonly reducerMetadata: ReducerMetadata;
9
+ constructor(eventEnvelope: EventEnvelope, eventInstance: EventInterface, snapshotInstance: EntityInterface | null, reducerMetadata: ReducerMetadata, originalError: Error);
10
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReducerGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class ReducerGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(eventEnvelope, eventInstance, snapshotInstance, reducerMetadata, originalError) {
7
+ super(originalError);
8
+ this.eventEnvelope = eventEnvelope;
9
+ this.eventInstance = eventInstance;
10
+ this.snapshotInstance = snapshotInstance;
11
+ this.reducerMetadata = reducerMetadata;
12
+ }
13
+ }
14
+ exports.ReducerGlobalError = ReducerGlobalError;
@@ -0,0 +1,8 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { ScheduledCommandMetadata } from '../concepts';
3
+ import { ScheduledCommandEnvelope } from '../envelope';
4
+ export declare class ScheduleCommandGlobalError extends GlobalErrorContainer {
5
+ readonly scheduleCommandEnvelope: ScheduledCommandEnvelope;
6
+ readonly scheduleCommandMetadata: ScheduledCommandMetadata;
7
+ constructor(scheduleCommandEnvelope: ScheduledCommandEnvelope, scheduleCommandMetadata: ScheduledCommandMetadata, originalError: Error);
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScheduleCommandGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ class ScheduleCommandGlobalError extends global_error_container_1.GlobalErrorContainer {
6
+ constructor(scheduleCommandEnvelope, scheduleCommandMetadata, originalError) {
7
+ super(originalError);
8
+ this.scheduleCommandEnvelope = scheduleCommandEnvelope;
9
+ this.scheduleCommandMetadata = scheduleCommandMetadata;
10
+ }
11
+ }
12
+ exports.ScheduleCommandGlobalError = ScheduleCommandGlobalError;
@@ -0,0 +1,16 @@
1
+ import { GlobalErrorContainer } from './global-error-container';
2
+ import { NonPersistedEntitySnapshotEnvelope } from '../envelope';
3
+ /**
4
+ * @deprecated [EOL v3] Errors when persisting snapshots can be safely ignored because
5
+ * this problem is likely caused by a temporary network error, and the events,
6
+ * which are the true source of truth are kept in any case.
7
+ * The next time the entity is fetched, the snapshot will be recalculated and
8
+ * Magek will try to persist it once again.
9
+ * If you define custom error handlers for this error, they will still be called,
10
+ * but errors returned by them will be logged and ignored.
11
+ * This class is kept for backwards compatibility.
12
+ */
13
+ export declare class SnapshotPersistHandlerGlobalError extends GlobalErrorContainer {
14
+ readonly snapshot: NonPersistedEntitySnapshotEnvelope;
15
+ constructor(snapshot: NonPersistedEntitySnapshotEnvelope, originalError: Error);
16
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapshotPersistHandlerGlobalError = void 0;
4
+ const global_error_container_1 = require("./global-error-container");
5
+ /**
6
+ * @deprecated [EOL v3] Errors when persisting snapshots can be safely ignored because
7
+ * this problem is likely caused by a temporary network error, and the events,
8
+ * which are the true source of truth are kept in any case.
9
+ * The next time the entity is fetched, the snapshot will be recalculated and
10
+ * Magek will try to persist it once again.
11
+ * If you define custom error handlers for this error, they will still be called,
12
+ * but errors returned by them will be logged and ignored.
13
+ * This class is kept for backwards compatibility.
14
+ */
15
+ class SnapshotPersistHandlerGlobalError extends global_error_container_1.GlobalErrorContainer {
16
+ constructor(snapshot, originalError) {
17
+ super(originalError);
18
+ this.snapshot = snapshot;
19
+ }
20
+ }
21
+ exports.SnapshotPersistHandlerGlobalError = SnapshotPersistHandlerGlobalError;
@@ -0,0 +1,30 @@
1
+ import { EntityInterface, EventInterface } from './concepts';
2
+ export declare class MagekError extends Error {
3
+ readonly data?: Record<string, unknown> | undefined;
4
+ readonly code: string;
5
+ constructor(message: string, code?: string, data?: Record<string, unknown> | undefined);
6
+ }
7
+ export declare class InvalidParameterError extends MagekError {
8
+ }
9
+ export declare class InvalidProtocolError extends MagekError {
10
+ }
11
+ export declare class NotAuthorizedError extends MagekError {
12
+ }
13
+ export declare class MagekTokenExpiredError extends MagekError {
14
+ }
15
+ export declare class MagekTokenNotBeforeError extends MagekError {
16
+ }
17
+ export declare class NotFoundError extends MagekError {
18
+ }
19
+ export declare class InvalidVersionError extends MagekError {
20
+ }
21
+ export declare class OptimisticConcurrencyUnexpectedVersionError extends MagekError {
22
+ }
23
+ export declare class InvalidEventError extends MagekError {
24
+ }
25
+ export declare class InvalidReducerError extends MagekError {
26
+ readonly eventInstance: EventInterface;
27
+ readonly snapshotInstance: EntityInterface | null;
28
+ constructor(message: string, eventInstance: EventInterface, snapshotInstance: EntityInterface | null);
29
+ }
30
+ export declare function httpStatusCodeFor(error: Error): number;
package/dist/errors.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidReducerError = exports.InvalidEventError = exports.OptimisticConcurrencyUnexpectedVersionError = exports.InvalidVersionError = exports.NotFoundError = exports.MagekTokenNotBeforeError = exports.MagekTokenExpiredError = exports.NotAuthorizedError = exports.InvalidProtocolError = exports.InvalidParameterError = exports.MagekError = void 0;
4
+ exports.httpStatusCodeFor = httpStatusCodeFor;
5
+ class MagekError extends Error {
6
+ constructor(message, code, data) {
7
+ super(message);
8
+ this.data = data;
9
+ this.code = code !== null && code !== void 0 ? code : this.constructor.name;
10
+ }
11
+ }
12
+ exports.MagekError = MagekError;
13
+ class InvalidParameterError extends MagekError {
14
+ }
15
+ exports.InvalidParameterError = InvalidParameterError;
16
+ class InvalidProtocolError extends MagekError {
17
+ }
18
+ exports.InvalidProtocolError = InvalidProtocolError;
19
+ class NotAuthorizedError extends MagekError {
20
+ }
21
+ exports.NotAuthorizedError = NotAuthorizedError;
22
+ class MagekTokenExpiredError extends MagekError {
23
+ }
24
+ exports.MagekTokenExpiredError = MagekTokenExpiredError;
25
+ class MagekTokenNotBeforeError extends MagekError {
26
+ }
27
+ exports.MagekTokenNotBeforeError = MagekTokenNotBeforeError;
28
+ class NotFoundError extends MagekError {
29
+ }
30
+ exports.NotFoundError = NotFoundError;
31
+ class InvalidVersionError extends MagekError {
32
+ }
33
+ exports.InvalidVersionError = InvalidVersionError;
34
+ class OptimisticConcurrencyUnexpectedVersionError extends MagekError {
35
+ }
36
+ exports.OptimisticConcurrencyUnexpectedVersionError = OptimisticConcurrencyUnexpectedVersionError;
37
+ class InvalidEventError extends MagekError {
38
+ }
39
+ exports.InvalidEventError = InvalidEventError;
40
+ class InvalidReducerError extends MagekError {
41
+ constructor(message, eventInstance, snapshotInstance) {
42
+ super(message);
43
+ this.eventInstance = eventInstance;
44
+ this.snapshotInstance = snapshotInstance;
45
+ }
46
+ }
47
+ exports.InvalidReducerError = InvalidReducerError;
48
+ function httpStatusCodeFor(error) {
49
+ var _a;
50
+ const errorToHTTPCode = {
51
+ [InvalidParameterError.name]: 400,
52
+ [InvalidProtocolError.name]: 400,
53
+ [NotAuthorizedError.name]: 401,
54
+ [MagekTokenExpiredError.name]: 401,
55
+ [MagekTokenNotBeforeError.name]: 401,
56
+ [NotFoundError.name]: 404,
57
+ [InvalidVersionError.name]: 422,
58
+ };
59
+ return (_a = errorToHTTPCode[error.constructor.name]) !== null && _a !== void 0 ? _a : 500;
60
+ }
@@ -0,0 +1,123 @@
1
+ import { UUID } from './concepts';
2
+ import { MagekConfig } from './config';
3
+ import { EntitySnapshotEnvelope, EntitySnapshotEnvelopeFromDatabase, EventDeleteParameters, EventEnvelope, EventEnvelopeFromDatabase, EventSearchParameters, EventSearchResponse, NonPersistedEntitySnapshotEnvelope, NonPersistedEventEnvelope, PaginatedEntitiesIdsResult, SnapshotDeleteParameters } from './envelope';
4
+ import { EventStream } from './stream-types';
5
+ export interface EventStoreAdapter {
6
+ /**
7
+ * Converts raw events data into an array of EventEnvelope objects
8
+ *
9
+ * @param rawEvents - The raw events data to be converted
10
+ * @returns An array of EventEnvelope objects
11
+ */
12
+ rawToEnvelopes(rawEvents: unknown): Array<EventEnvelope>;
13
+ rawStreamToEnvelopes(config: MagekConfig, context: unknown, dedupEventStream: EventStream): Array<EventEnvelope>;
14
+ dedupEventStream(config: MagekConfig, rawEvents: unknown): Promise<EventStream>;
15
+ produce(entityName: string, entityID: UUID, eventEnvelopes: Array<EventEnvelope>, config: MagekConfig): Promise<void>;
16
+ /**
17
+ * Retrieves events for a specific entity since a given time
18
+ *
19
+ * @param config - The Magek configuration object
20
+ * @param entityTypeName - The type name of the entity
21
+ * @param entityID - The ID of the entity
22
+ * @param since - The time to retrieve events since (optional)
23
+ * @returns A promise that resolves to an array of EventEnvelope objects
24
+ */
25
+ forEntitySince(config: MagekConfig, entityTypeName: string, entityID: UUID, since?: string): Promise<Array<EventEnvelope>>;
26
+ /**
27
+ * Retrieves the latest snapshot of an entity
28
+ *
29
+ * @param config - The Magek configuration object
30
+ * @param entityTypeName - The type name of the entity
31
+ * @param entityID - The ID of the entity
32
+ * @returns A promise that resolves to the latest EventEnvelope for the entity, or null if none exist
33
+ */
34
+ latestEntitySnapshot(config: MagekConfig, entityTypeName: string, entityID: UUID): Promise<EntitySnapshotEnvelope | undefined>;
35
+ /**
36
+ * Searches for events based on specific parameters
37
+ *
38
+ * @param config - The Magek configuration object
39
+ * @param parameters - The search parameters
40
+ * @returns A promise that resolves to an array of EventSearchResponse objects
41
+ */
42
+ search(config: MagekConfig, parameters: EventSearchParameters): Promise<Array<EventSearchResponse>>;
43
+ /**
44
+ * Searches for entities IDs based on a specific entity type and pagination parameters
45
+ *
46
+ * @param config - The Magek configuration object
47
+ * @param limit - The maximum number of entities IDs to retrieve
48
+ * @param afterCursor - The cursor to retrieve entities IDs after (optional)
49
+ * @param entityTypeName - The type name of the entities to search for
50
+ * @returns A promise that resolves to a PaginatedEntitiesIdsResult object
51
+ */
52
+ searchEntitiesIDs(config: MagekConfig, limit: number, afterCursor: Record<string, string> | undefined, entityTypeName: string): Promise<PaginatedEntitiesIdsResult>;
53
+ /**
54
+ * Streams an event to the corresponding event handler
55
+ *
56
+ * @param eventEnvelopes - The array of `NonPersistedEventEnvelope` objects to store
57
+ * @param config - The Magek configuration object
58
+ * @returns A promise that resolves with the list of `EventEnvelope`s when the events have been stored
59
+ */
60
+ store(eventEnvelopes: Array<NonPersistedEventEnvelope>, config: MagekConfig): Promise<Array<EventEnvelope>>;
61
+ /**
62
+ * Stores a snapshot of an entity
63
+ *
64
+ * @param snapshotEnvelope - The `NonPersistedEntitySnapshotEnvelope` object to store
65
+ * @param config - The Magek configuration object
66
+ * @returns A promise that resolves with the `EntitySnapshotEnvelope` when the snapshot has been stored
67
+ */
68
+ storeSnapshot(snapshotEnvelope: NonPersistedEntitySnapshotEnvelope, config: MagekConfig): Promise<EntitySnapshotEnvelope>;
69
+ /**
70
+ * Stores an event envelope that has been dispatched in the dispatched events table.
71
+ *
72
+ * @param eventEnvelope - The `EventEnvelope` to store.
73
+ * @param config - The Magek configuration object.
74
+ * @returns `true` if the dispatched event was stored, `false` if the event already exists in the dispatched events
75
+ * table, throws an error on any other type of error.
76
+ */
77
+ storeDispatched(eventEnvelope: EventEnvelope, config: MagekConfig): Promise<boolean>;
78
+ /**
79
+ * Find all events to be removed based on the parameters
80
+ *
81
+ * @param config
82
+ * @param parameters
83
+ */
84
+ findDeletableEvent(config: MagekConfig, parameters: EventDeleteParameters): Promise<Array<EventEnvelopeFromDatabase>>;
85
+ /**
86
+ * Find all snapshots to be removed based on the parameters
87
+ *
88
+ * @param config
89
+ * @param parameters
90
+ */
91
+ findDeletableSnapshot(config: MagekConfig, parameters: SnapshotDeleteParameters): Promise<Array<EntitySnapshotEnvelopeFromDatabase>>;
92
+ /**
93
+ * Delete events
94
+ *
95
+ * @param config
96
+ * @param events
97
+ */
98
+ deleteEvent(config: MagekConfig, events: Array<EventEnvelopeFromDatabase>): Promise<void>;
99
+ /**
100
+ * Delete snapshots
101
+ *
102
+ * @param config
103
+ * @param snapshots
104
+ */
105
+ deleteSnapshot(config: MagekConfig, snapshots: Array<EntitySnapshotEnvelopeFromDatabase>): Promise<void>;
106
+ /**
107
+ * Health check methods for the event store
108
+ */
109
+ healthCheck?: {
110
+ /**
111
+ * Check if the event store is up and running
112
+ */
113
+ isUp(config: MagekConfig): Promise<boolean>;
114
+ /**
115
+ * Get detailed health information about the event store
116
+ */
117
+ details(config: MagekConfig): Promise<unknown>;
118
+ /**
119
+ * Get the URLs/endpoints of the event store
120
+ */
121
+ urls(config: MagekConfig): Promise<Array<string>>;
122
+ };
123
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,63 @@
1
+ import 'reflect-metadata';
2
+ /**
3
+ * Type function for specifying field types
4
+ * The parameter is optional and not used - it's just for TypeGraphQL-style ergonomics
5
+ */
6
+ export type TypeFunction = (type?: unknown) => unknown;
7
+ /**
8
+ * Options for the @Field() decorator
9
+ */
10
+ export interface FieldOptions {
11
+ nullable?: boolean;
12
+ readonly?: boolean;
13
+ }
14
+ /**
15
+ * Metadata stored for each field
16
+ */
17
+ export interface FieldMetadata {
18
+ name: string;
19
+ typeFunction?: TypeFunction;
20
+ options: FieldOptions;
21
+ designType?: unknown;
22
+ }
23
+ /**
24
+ * Stage 3 decorator context for class fields (TypeScript 5.0+)
25
+ */
26
+ interface Stage3FieldContext {
27
+ kind: 'field';
28
+ name: string | symbol;
29
+ static: boolean;
30
+ private: boolean;
31
+ metadata: Record<string | symbol, unknown>;
32
+ access?: {
33
+ get: () => unknown;
34
+ set: (value: unknown) => void;
35
+ };
36
+ addInitializer?: (initializer: () => void) => void;
37
+ }
38
+ /**
39
+ * Decorator return type that supports both legacy and Stage 3 formats.
40
+ * This is a function that can be called with either signature.
41
+ */
42
+ type UniversalFieldDecorator = {
43
+ (target: object, propertyKey: string | symbol): void;
44
+ (value: undefined, context: Stage3FieldContext): void;
45
+ };
46
+ /**
47
+ * @Field() decorator for explicit type declaration
48
+ *
49
+ * Supports both legacy decorators (experimentalDecorators) and
50
+ * Stage 3 TC39 decorators.
51
+ *
52
+ * Usage:
53
+ * @Field() - Simple type (inferred from design:type in legacy mode)
54
+ * @Field(type => String) - Explicit type
55
+ * @Field(type => [String]) - Array type
56
+ * @Field({ nullable: true }) - With options
57
+ * @Field(type => String, { nullable: true }) - Type with options
58
+ */
59
+ export declare function Field(): UniversalFieldDecorator;
60
+ export declare function Field(options: FieldOptions): UniversalFieldDecorator;
61
+ export declare function Field(typeFunction: TypeFunction): UniversalFieldDecorator;
62
+ export declare function Field(typeFunction: TypeFunction, options: FieldOptions): UniversalFieldDecorator;
63
+ export {};
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Field = Field;
4
+ require("reflect-metadata");
5
+ // Symbol for storing fields metadata (for Stage 3 decorators)
6
+ const FIELDS_KEY = Symbol.for('magek:fields');
7
+ /**
8
+ * Type guard to detect Stage 3 decorator context
9
+ */
10
+ function isStage3Context(arg) {
11
+ return (arg !== null &&
12
+ typeof arg === 'object' &&
13
+ 'kind' in arg &&
14
+ arg.kind === 'field' &&
15
+ 'name' in arg &&
16
+ 'metadata' in arg);
17
+ }
18
+ /**
19
+ * Store field metadata on a constructor (works for both legacy and Stage 3)
20
+ */
21
+ function storeFieldMetadata(constructor, fieldMetadata) {
22
+ // Get existing fields
23
+ let existingFields = [];
24
+ // Try Reflect.getMetadata first
25
+ try {
26
+ if (typeof Reflect !== 'undefined' && typeof Reflect.getMetadata === 'function') {
27
+ existingFields = Reflect.getMetadata('magek:fields', constructor) || [];
28
+ }
29
+ }
30
+ catch {
31
+ // Ignore
32
+ }
33
+ // Also check fallback property
34
+ const ctorWithFields = constructor;
35
+ if (existingFields.length === 0 && ctorWithFields.__magek_fields__) {
36
+ existingFields = ctorWithFields.__magek_fields__;
37
+ }
38
+ // Add this field (avoid duplicates by name)
39
+ const filteredFields = existingFields.filter((f) => f.name !== fieldMetadata.name);
40
+ filteredFields.push(fieldMetadata);
41
+ // Store using both mechanisms for reliability
42
+ try {
43
+ if (typeof Reflect !== 'undefined' && typeof Reflect.defineMetadata === 'function') {
44
+ Reflect.defineMetadata('magek:fields', filteredFields, constructor);
45
+ }
46
+ }
47
+ catch {
48
+ // Ignore
49
+ }
50
+ // Also store as a fallback property
51
+ ctorWithFields.__magek_fields__ = filteredFields;
52
+ }
53
+ /**
54
+ * Handle legacy decorator format (experimentalDecorators)
55
+ */
56
+ function handleLegacyDecorator(target, propertyKey, typeFunction, fieldOptions) {
57
+ // Get design type from TypeScript decorator metadata
58
+ let designType;
59
+ try {
60
+ if (typeof Reflect !== 'undefined' && typeof Reflect.getMetadata === 'function') {
61
+ designType = Reflect.getMetadata('design:type', target, propertyKey);
62
+ }
63
+ }
64
+ catch {
65
+ // Ignore - Reflect.getMetadata may fail if called before initialization
66
+ }
67
+ const fieldMetadata = {
68
+ name: propertyKey.toString(),
69
+ typeFunction,
70
+ options: fieldOptions,
71
+ designType,
72
+ };
73
+ const constructor = target.constructor;
74
+ if (constructor) {
75
+ storeFieldMetadata(constructor, fieldMetadata);
76
+ }
77
+ }
78
+ /**
79
+ * Handle Stage 3 decorator format (TC39 decorators)
80
+ */
81
+ function handleStage3Decorator(context, typeFunction, fieldOptions) {
82
+ const fieldMetadata = {
83
+ name: context.name.toString(),
84
+ typeFunction,
85
+ options: fieldOptions,
86
+ designType: undefined, // Stage 3 doesn't have design:type
87
+ };
88
+ // Store in context.metadata for later retrieval by class decorators
89
+ // Class decorators (like @Command, @Entity, etc.) will transfer this to the class constructor
90
+ if (!context.metadata[FIELDS_KEY]) {
91
+ context.metadata[FIELDS_KEY] = [];
92
+ }
93
+ const fields = context.metadata[FIELDS_KEY];
94
+ const filteredFields = fields.filter((f) => f.name !== fieldMetadata.name);
95
+ filteredFields.push(fieldMetadata);
96
+ context.metadata[FIELDS_KEY] = filteredFields;
97
+ }
98
+ function Field(typeFunctionOrOptions, options) {
99
+ // Parse arguments
100
+ let typeFunction;
101
+ let fieldOptions = {};
102
+ if (typeof typeFunctionOrOptions === 'function') {
103
+ typeFunction = typeFunctionOrOptions;
104
+ fieldOptions = options || {};
105
+ }
106
+ else if (typeFunctionOrOptions) {
107
+ fieldOptions = typeFunctionOrOptions;
108
+ }
109
+ // Return decorator that handles both formats
110
+ return function fieldDecorator(targetOrValue, propertyKeyOrContext) {
111
+ // Detect Stage 3 vs Legacy based on the second argument
112
+ if (isStage3Context(propertyKeyOrContext)) {
113
+ // Stage 3 decorator
114
+ handleStage3Decorator(propertyKeyOrContext, typeFunction, fieldOptions);
115
+ }
116
+ else if (targetOrValue) {
117
+ // Legacy decorator
118
+ handleLegacyDecorator(targetOrValue, propertyKeyOrContext, typeFunction, fieldOptions);
119
+ }
120
+ // If targetOrValue is undefined and not Stage 3, silently skip
121
+ };
122
+ }
@@ -0,0 +1,65 @@
1
+ import { GraphQLOperation } from './envelope';
2
+ import { ExecutionResult } from 'graphql';
3
+ export declare enum MessageTypes {
4
+ GQL_CONNECTION_INIT = "connection_init",
5
+ GQL_CONNECTION_ACK = "connection_ack",
6
+ GQL_CONNECTION_ERROR = "connection_error",
7
+ GQL_CONNECTION_TERMINATE = "connection_terminate",
8
+ GQL_START = "start",
9
+ GQL_DATA = "data",
10
+ GQL_ERROR = "error",
11
+ GQL_COMPLETE = "complete",
12
+ GQL_STOP = "stop"
13
+ }
14
+ export type GraphQLClientMessage = GraphQLInit | GraphQLStart | GraphQLStop | GraphQLTerminate;
15
+ export interface GraphQLInit {
16
+ type: MessageTypes.GQL_CONNECTION_INIT;
17
+ payload: {
18
+ Authorization?: string;
19
+ };
20
+ }
21
+ export interface GraphQLStart {
22
+ type: MessageTypes.GQL_START;
23
+ id: string;
24
+ payload: Omit<GraphQLOperation, 'id'>;
25
+ }
26
+ export interface GraphQLStop {
27
+ type: MessageTypes.GQL_STOP;
28
+ id: string;
29
+ }
30
+ export interface GraphQLTerminate {
31
+ type: MessageTypes.GQL_CONNECTION_TERMINATE;
32
+ }
33
+ export type GraphQLServerMessage = GraphQLInitError | GraphQLInitAck | GraphQLData | GraphQLError | GraphQLComplete;
34
+ export declare class GraphQLInitError {
35
+ readonly payload: string;
36
+ readonly type = MessageTypes.GQL_CONNECTION_ERROR;
37
+ constructor(payload: string);
38
+ }
39
+ export declare class GraphQLInitAck {
40
+ readonly type = MessageTypes.GQL_CONNECTION_ACK;
41
+ }
42
+ export declare class GraphQLData {
43
+ readonly id: string;
44
+ readonly payload: ExecutionResult;
45
+ readonly type = MessageTypes.GQL_DATA;
46
+ constructor(id: string, payload: ExecutionResult);
47
+ }
48
+ export declare class GraphQLError {
49
+ readonly id: string;
50
+ readonly payload: {
51
+ errors: Array<Error>;
52
+ };
53
+ readonly type = MessageTypes.GQL_ERROR;
54
+ constructor(id: string, payload: {
55
+ errors: Array<Error>;
56
+ });
57
+ }
58
+ export declare class GraphQLComplete {
59
+ readonly id: string;
60
+ readonly type = MessageTypes.GQL_COMPLETE;
61
+ constructor(id: string);
62
+ }
63
+ export declare const graphQLWebsocketSubprotocolHeaders: {
64
+ 'Sec-WebSocket-Protocol': string;
65
+ };