@cratis/chronicle 6.61.0 → 6.63.0
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/ChronicleClient.ts +86 -3
- package/connection/ChronicleConnection.ts +7 -1
- package/connection/ChronicleServices.ts +2 -0
- package/connection/ConnectionLifecycle.ts +42 -1
- package/dist/ChronicleClient.d.ts +28 -1
- package/dist/ChronicleClient.d.ts.map +1 -1
- package/dist/ChronicleClient.js +71 -3
- package/dist/ChronicleClient.js.map +1 -1
- package/dist/connection/ChronicleConnection.d.ts +1 -0
- package/dist/connection/ChronicleConnection.d.ts.map +1 -1
- package/dist/connection/ChronicleConnection.js +6 -2
- package/dist/connection/ChronicleConnection.js.map +1 -1
- package/dist/connection/ChronicleServices.d.ts +2 -1
- package/dist/connection/ChronicleServices.d.ts.map +1 -1
- package/dist/connection/ConnectionLifecycle.d.ts +24 -0
- package/dist/connection/ConnectionLifecycle.d.ts.map +1 -1
- package/dist/connection/ConnectionLifecycle.js +40 -1
- package/dist/connection/ConnectionLifecycle.js.map +1 -1
- package/dist/eventSequences/EventForEventSourceId.d.ts +21 -1
- package/dist/eventSequences/EventForEventSourceId.d.ts.map +1 -1
- package/dist/eventSequences/EventSequence.d.ts +9 -0
- package/dist/eventSequences/EventSequence.d.ts.map +1 -1
- package/dist/eventSequences/EventSequence.js +18 -0
- package/dist/eventSequences/EventSequence.js.map +1 -1
- package/dist/eventSequences/IEventSequence.d.ts +30 -0
- package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
- package/dist/imports/EventImport.d.ts +29 -0
- package/dist/imports/EventImport.d.ts.map +1 -0
- package/dist/imports/EventImport.js +248 -0
- package/dist/imports/EventImport.js.map +1 -0
- package/dist/imports/EventImportSettings.d.ts +32 -0
- package/dist/imports/EventImportSettings.d.ts.map +1 -0
- package/dist/imports/EventImportSettings.js +4 -0
- package/dist/imports/EventImportSettings.js.map +1 -0
- package/dist/imports/IEventImport.d.ts +50 -0
- package/dist/imports/IEventImport.d.ts.map +1 -0
- package/dist/imports/IEventImport.js +4 -0
- package/dist/imports/IEventImport.js.map +1 -0
- package/dist/imports/ImportChunkRefused.d.ts +12 -0
- package/dist/imports/ImportChunkRefused.d.ts.map +1 -0
- package/dist/imports/ImportChunkRefused.js +19 -0
- package/dist/imports/ImportChunkRefused.js.map +1 -0
- package/dist/imports/ImportCouldNotBegin.d.ts +10 -0
- package/dist/imports/ImportCouldNotBegin.d.ts.map +1 -0
- package/dist/imports/ImportCouldNotBegin.js +16 -0
- package/dist/imports/ImportCouldNotBegin.js.map +1 -0
- package/dist/imports/ImportOptions.d.ts +26 -0
- package/dist/imports/ImportOptions.d.ts.map +1 -0
- package/dist/imports/ImportOptions.js +4 -0
- package/dist/imports/ImportOptions.js.map +1 -0
- package/dist/imports/ImportProgress.d.ts +20 -0
- package/dist/imports/ImportProgress.d.ts.map +1 -0
- package/dist/imports/ImportProgress.js +4 -0
- package/dist/imports/ImportProgress.js.map +1 -0
- package/dist/imports/ImportRejection.d.ts +10 -0
- package/dist/imports/ImportRejection.d.ts.map +1 -0
- package/dist/imports/ImportRejection.js +4 -0
- package/dist/imports/ImportRejection.js.map +1 -0
- package/dist/imports/ImportResult.d.ts +30 -0
- package/dist/imports/ImportResult.d.ts.map +1 -0
- package/dist/imports/ImportResult.js +4 -0
- package/dist/imports/ImportResult.js.map +1 -0
- package/dist/imports/ImportState.d.ts +18 -0
- package/dist/imports/ImportState.d.ts.map +1 -0
- package/dist/imports/ImportState.js +21 -0
- package/dist/imports/ImportState.js.map +1 -0
- package/dist/imports/ImportTarget.d.ts +16 -0
- package/dist/imports/ImportTarget.d.ts.map +1 -0
- package/dist/imports/ImportTarget.js +4 -0
- package/dist/imports/ImportTarget.js.map +1 -0
- package/dist/imports/ImportWasAbandoned.d.ts +11 -0
- package/dist/imports/ImportWasAbandoned.d.ts.map +1 -0
- package/dist/imports/ImportWasAbandoned.js +16 -0
- package/dist/imports/ImportWasAbandoned.js.map +1 -0
- package/dist/imports/ImportsNotSupported.d.ts +5 -0
- package/dist/imports/ImportsNotSupported.d.ts.map +1 -0
- package/dist/imports/ImportsNotSupported.js +10 -0
- package/dist/imports/ImportsNotSupported.js.map +1 -0
- package/dist/imports/OnInvalidEvent.d.ts +8 -0
- package/dist/imports/OnInvalidEvent.d.ts.map +1 -0
- package/dist/imports/OnInvalidEvent.js +11 -0
- package/dist/imports/OnInvalidEvent.js.map +1 -0
- package/dist/imports/abortable.d.ts +23 -0
- package/dist/imports/abortable.d.ts.map +1 -0
- package/dist/imports/abortable.js +60 -0
- package/dist/imports/abortable.js.map +1 -0
- package/dist/imports/beginEventImport.d.ts +16 -0
- package/dist/imports/beginEventImport.d.ts.map +1 -0
- package/dist/imports/beginEventImport.js +74 -0
- package/dist/imports/beginEventImport.js.map +1 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.d.ts +144 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.d.ts.map +1 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.js +132 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.js.map +1 -0
- package/dist/imports/importEvents.d.ts +13 -0
- package/dist/imports/importEvents.d.ts.map +1 -0
- package/dist/imports/importEvents.js +35 -0
- package/dist/imports/importEvents.js.map +1 -0
- package/dist/imports/index.d.ts +12 -0
- package/dist/imports/index.d.ts.map +1 -0
- package/dist/imports/index.js +9 -0
- package/dist/imports/index.js.map +1 -0
- package/dist/imports/isTransientImportFailure.d.ts +7 -0
- package/dist/imports/isTransientImportFailure.d.ts.map +1 -0
- package/dist/imports/isTransientImportFailure.js +13 -0
- package/dist/imports/isTransientImportFailure.js.map +1 -0
- package/dist/imports/sizeOfImportEvent.d.ts +9 -0
- package/dist/imports/sizeOfImportEvent.d.ts.map +1 -0
- package/dist/imports/sizeOfImportEvent.js +25 -0
- package/dist/imports/sizeOfImportEvent.js.map +1 -0
- package/dist/imports/toImportEvent.d.ts +14 -0
- package/dist/imports/toImportEvent.d.ts.map +1 -0
- package/dist/imports/toImportEvent.js +54 -0
- package/dist/imports/toImportEvent.js.map +1 -0
- package/dist/imports/toImportProgress.d.ts +9 -0
- package/dist/imports/toImportProgress.d.ts.map +1 -0
- package/dist/imports/toImportProgress.js +20 -0
- package/dist/imports/toImportProgress.js.map +1 -0
- package/dist/imports/toImportResult.d.ts +9 -0
- package/dist/imports/toImportResult.d.ts.map +1 -0
- package/dist/imports/toImportResult.js +33 -0
- package/dist/imports/toImportResult.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/observation/ObservationReconnectBackoff.d.ts +64 -0
- package/dist/observation/ObservationReconnectBackoff.d.ts.map +1 -0
- package/dist/observation/ObservationReconnectBackoff.js +75 -0
- package/dist/observation/ObservationReconnectBackoff.js.map +1 -0
- package/dist/observation/ObservationStreamOutcome.d.ts +10 -0
- package/dist/observation/ObservationStreamOutcome.d.ts.map +1 -0
- package/dist/observation/ObservationStreamOutcome.js +4 -0
- package/dist/observation/ObservationStreamOutcome.js.map +1 -0
- package/dist/observation/classifyStreamError.d.ts +25 -0
- package/dist/observation/classifyStreamError.d.ts.map +1 -0
- package/dist/observation/classifyStreamError.js +55 -0
- package/dist/observation/classifyStreamError.js.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.d.ts +13 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.d.ts.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.js +25 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.js.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.d.ts +27 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.d.ts.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js +36 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js.map +1 -0
- package/dist/observation/index.d.ts +2 -0
- package/dist/observation/index.d.ts.map +1 -1
- package/dist/observation/index.js +1 -0
- package/dist/observation/index.js.map +1 -1
- package/dist/reactors/Reactors.d.ts +15 -5
- package/dist/reactors/Reactors.d.ts.map +1 -1
- package/dist/reactors/Reactors.js +95 -18
- package/dist/reactors/Reactors.js.map +1 -1
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.d.ts +26 -0
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.d.ts.map +1 -0
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.js +64 -0
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.js.map +1 -0
- package/dist/reducers/Reducers.d.ts +11 -5
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +93 -19
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.d.ts +25 -0
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.d.ts.map +1 -0
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.js +70 -0
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.js.map +1 -0
- package/dist/testing/BatchPartitionOutcome.d.ts +7 -0
- package/dist/testing/BatchPartitionOutcome.d.ts.map +1 -0
- package/dist/testing/BatchPartitionOutcome.js +4 -0
- package/dist/testing/BatchPartitionOutcome.js.map +1 -0
- package/dist/testing/InProcessEventSequence.d.ts +4 -0
- package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
- package/dist/testing/InProcessEventSequence.js +2 -0
- package/dist/testing/InProcessEventSequence.js.map +1 -1
- package/dist/testing/ReactorDeliveryResult.d.ts +2 -0
- package/dist/testing/ReactorDeliveryResult.d.ts.map +1 -1
- package/dist/testing/ReactorScenario.d.ts +46 -10
- package/dist/testing/ReactorScenario.d.ts.map +1 -1
- package/dist/testing/ReactorScenario.js +120 -29
- package/dist/testing/ReactorScenario.js.map +1 -1
- package/dist/testing/deliverToBatchMethods.d.ts +35 -0
- package/dist/testing/deliverToBatchMethods.d.ts.map +1 -0
- package/dist/testing/deliverToBatchMethods.js +55 -0
- package/dist/testing/deliverToBatchMethods.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eventSequences/EventForEventSourceId.ts +25 -1
- package/eventSequences/EventSequence.ts +28 -0
- package/eventSequences/IEventSequence.ts +33 -0
- package/for_ChronicleClient/when_reconnecting/and_an_observation_stream_lost_its_session.spec.ts +212 -0
- package/imports/EventImport.ts +263 -0
- package/imports/EventImportSettings.ts +46 -0
- package/imports/IEventImport.ts +58 -0
- package/imports/ImportChunkRefused.ts +15 -0
- package/imports/ImportCouldNotBegin.ts +14 -0
- package/imports/ImportOptions.ts +36 -0
- package/imports/ImportProgress.ts +29 -0
- package/imports/ImportRejection.ts +14 -0
- package/imports/ImportResult.ts +43 -0
- package/imports/ImportState.ts +26 -0
- package/imports/ImportTarget.ts +23 -0
- package/imports/ImportWasAbandoned.ts +16 -0
- package/imports/ImportsNotSupported.ts +10 -0
- package/imports/OnInvalidEvent.ts +11 -0
- package/imports/abortable.ts +57 -0
- package/imports/beginEventImport.ts +85 -0
- package/imports/for_EventImport/given/a_kernel_import_session.ts +160 -0
- package/imports/for_EventImport/when_a_chunk_fails.spec.ts +65 -0
- package/imports/for_EventImport/when_abandoning.spec.ts +52 -0
- package/imports/for_EventImport/when_cancelling_with_an_abort_signal.spec.ts +59 -0
- package/imports/for_EventImport/when_completing.spec.ts +71 -0
- package/imports/for_EventImport/when_cutting_events_into_chunks.spec.ts +70 -0
- package/imports/for_EventImport/when_keeping_chunks_in_flight.spec.ts +49 -0
- package/imports/for_beginEventImport/when_reattaching.spec.ts +82 -0
- package/imports/for_beginEventImport/when_the_kernel_does_not_serve_imports.spec.ts +55 -0
- package/imports/for_importEvents/when_importing_in_one_call.spec.ts +99 -0
- package/imports/for_toImportEvent/when_converting_an_event.spec.ts +74 -0
- package/imports/importEvents.ts +44 -0
- package/imports/index.ts +14 -0
- package/imports/isTransientImportFailure.ts +15 -0
- package/imports/sizeOfImportEvent.ts +25 -0
- package/imports/toImportEvent.ts +60 -0
- package/imports/toImportProgress.ts +24 -0
- package/imports/toImportResult.ts +36 -0
- package/index.ts +3 -0
- package/observation/ObservationReconnectBackoff.ts +109 -0
- package/observation/ObservationStreamOutcome.ts +12 -0
- package/observation/classifyStreamError.ts +67 -0
- package/observation/for_ObservationReconnectBackoff/given/a_backoff.ts +29 -0
- package/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.ts +52 -0
- package/observation/for_ObservationReconnectBackoff/when_a_stream_delivered_before_it_ended.spec.ts +23 -0
- package/observation/for_ObservationReconnectBackoff/when_a_stream_stayed_open_before_it_ended.spec.ts +25 -0
- package/observation/for_ObservationReconnectBackoff/when_jittering_the_delay.spec.ts +24 -0
- package/observation/for_ObservationReconnectBackoff/when_streams_keep_ending_without_working.spec.ts +24 -0
- package/observation/for_ObservationReconnectBackoff/when_the_base_delay_is_not_positive.spec.ts +18 -0
- package/observation/for_ObservationReconnectBackoff/when_the_settings_are_not_finite.spec.ts +32 -0
- package/observation/for_ObservationReconnectBackoff/when_using_the_defaults.spec.ts +29 -0
- package/observation/for_classifyStreamError/when_classifying_a_stream_error.spec.ts +36 -0
- package/observation/index.ts +2 -0
- package/package.json +7 -2
- package/projections/for_childrenOrderingSupport/when_detecting_support_in_the_pinned_contracts.spec.ts +1 -1
- package/reactors/Reactors.ts +101 -18
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_handler_failed_with_a_lost_session.spec.ts +32 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_replaced_stream_fails_late.spec.ts +28 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_stream_delivered_before_it_ended.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_stream_stayed_open_before_it_ended.spec.ts +23 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_it_is_disposed_while_waiting_to_reopen.spec.ts +27 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_streams_keep_ending_without_working.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_client_reconnected_after_streams_kept_ending.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_client_reconnected_while_waiting_to_reopen.spec.ts +25 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_kernel_lost_the_session.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.ts +69 -0
- package/reducers/Reducers.ts +99 -19
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_reducer_failed_with_a_lost_session.spec.ts +33 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_replaced_stream_fails_late.spec.ts +28 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_stream_delivered_before_it_ended.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_stream_stayed_open_before_it_ended.spec.ts +23 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_it_is_disposed_while_waiting_to_reopen.spec.ts +27 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_streams_keep_ending_without_working.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_client_reconnected_after_streams_kept_ending.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_client_reconnected_while_waiting_to_reopen.spec.ts +25 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_kernel_lost_the_session.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.ts +69 -0
- package/testing/BatchPartitionOutcome.ts +10 -0
- package/testing/InProcessEventSequence.ts +4 -0
- package/testing/ReactorDeliveryResult.ts +2 -0
- package/testing/ReactorScenario.ts +147 -39
- package/testing/deliverToBatchMethods.ts +90 -0
- package/testing/for_ReactorScenario/when_the_reactor_has_a_batch_method.spec.ts +143 -9
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/** The state of an import session. */
|
|
4
|
+
export var ImportState;
|
|
5
|
+
(function (ImportState) {
|
|
6
|
+
/** The import is open and has not received any chunk yet. */
|
|
7
|
+
ImportState[ImportState["Open"] = 0] = "Open";
|
|
8
|
+
/** The import has received chunks and accepts more. */
|
|
9
|
+
ImportState[ImportState["Staging"] = 1] = "Staging";
|
|
10
|
+
/** Staging is closed and the whole import is being validated. */
|
|
11
|
+
ImportState[ImportState["Validating"] = 2] = "Validating";
|
|
12
|
+
/** The staged events are being committed to the event sequence. */
|
|
13
|
+
ImportState[ImportState["Committing"] = 3] = "Committing";
|
|
14
|
+
/** Every staged event was committed or reported. */
|
|
15
|
+
ImportState[ImportState["Completed"] = 4] = "Completed";
|
|
16
|
+
/** The import failed; when it failed before committing, nothing was committed. */
|
|
17
|
+
ImportState[ImportState["Failed"] = 5] = "Failed";
|
|
18
|
+
/** The import was abandoned before its commit started. */
|
|
19
|
+
ImportState[ImportState["Abandoned"] = 6] = "Abandoned";
|
|
20
|
+
})(ImportState || (ImportState = {}));
|
|
21
|
+
//# sourceMappingURL=ImportState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportState.js","sourceRoot":"","sources":["../../imports/ImportState.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,sCAAsC;AACtC,MAAM,CAAN,IAAY,WAqBX;AArBD,WAAY,WAAW;IACnB,6DAA6D;IAC7D,6CAAQ,CAAA;IAER,uDAAuD;IACvD,mDAAW,CAAA;IAEX,iEAAiE;IACjE,yDAAc,CAAA;IAEd,mEAAmE;IACnE,yDAAc,CAAA;IAEd,oDAAoD;IACpD,uDAAa,CAAA;IAEb,kFAAkF;IAClF,iDAAU,CAAA;IAEV,0DAA0D;IAC1D,uDAAa,CAAA;AACjB,CAAC,EArBW,WAAW,KAAX,WAAW,QAqBtB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ImportsClient } from '@cratis/chronicle.contracts';
|
|
2
|
+
import type { IEventSources } from '../eventSources/IEventSources.js';
|
|
3
|
+
/** The event sequence an import targets, and how to reach the kernel's Imports service. */
|
|
4
|
+
export interface ImportTarget {
|
|
5
|
+
/** The Imports service. */
|
|
6
|
+
readonly imports: ImportsClient;
|
|
7
|
+
/** The name of the event store. */
|
|
8
|
+
readonly eventStore: string;
|
|
9
|
+
/** The namespace. */
|
|
10
|
+
readonly namespace: string;
|
|
11
|
+
/** The identifier of the event sequence the events are imported into. */
|
|
12
|
+
readonly eventSequenceId: string;
|
|
13
|
+
/** The registered event sources, for events routed through a definition. */
|
|
14
|
+
readonly eventSources?: IEventSources;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ImportTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportTarget.d.ts","sourceRoot":"","sources":["../../imports/ImportTarget.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE,2FAA2F;AAC3F,MAAM,WAAW,YAAY;IACzB,2BAA2B;IAC3B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAEhC,mCAAmC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,qBAAqB;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,yEAAyE;IACzE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportTarget.js","sourceRoot":"","sources":["../../imports/ImportTarget.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Guid } from '@cratis/fundamentals';
|
|
2
|
+
/** The exception that is thrown when events are added to, or completed on, an import that was abandoned. */
|
|
3
|
+
export declare class ImportWasAbandoned extends Error {
|
|
4
|
+
readonly importId: Guid;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new {@link ImportWasAbandoned}.
|
|
7
|
+
* @param importId - The identifier of the import.
|
|
8
|
+
*/
|
|
9
|
+
constructor(importId: Guid);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ImportWasAbandoned.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportWasAbandoned.d.ts","sourceRoot":"","sources":["../../imports/ImportWasAbandoned.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,4GAA4G;AAC5G,qBAAa,kBAAmB,SAAQ,KAAK;IAK7B,QAAQ,CAAC,QAAQ,EAAE,IAAI;IAJnC;;;OAGG;IACH,YAAqB,QAAQ,EAAE,IAAI,EAGlC;CACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/** The exception that is thrown when events are added to, or completed on, an import that was abandoned. */
|
|
4
|
+
export class ImportWasAbandoned extends Error {
|
|
5
|
+
importId;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new {@link ImportWasAbandoned}.
|
|
8
|
+
* @param importId - The identifier of the import.
|
|
9
|
+
*/
|
|
10
|
+
constructor(importId) {
|
|
11
|
+
super(`Import '${importId.toString()}' was abandoned.`);
|
|
12
|
+
this.importId = importId;
|
|
13
|
+
this.name = 'ImportWasAbandoned';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ImportWasAbandoned.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportWasAbandoned.js","sourceRoot":"","sources":["../../imports/ImportWasAbandoned.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAIrG,4GAA4G;AAC5G,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAKpB,QAAQ;IAJ7B;;;OAGG;IACH,YAAqB,QAAc;QAC/B,KAAK,CAAC,WAAW,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;wBADvC,QAAQ;QAEzB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACrC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportsNotSupported.d.ts","sourceRoot":"","sources":["../../imports/ImportsNotSupported.ts"],"names":[],"mappings":"AAGA,uFAAuF;AACvF,qBAAa,mBAAoB,SAAQ,KAAK;IAC1C,cAGC;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/** The exception that is thrown when the Chronicle kernel does not support imports. */
|
|
4
|
+
export class ImportsNotSupported extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super('The Chronicle kernel does not support importing events. Upgrade the kernel to a version that serves the Imports service.');
|
|
7
|
+
this.name = 'ImportsNotSupported';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ImportsNotSupported.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImportsNotSupported.js","sourceRoot":"","sources":["../../imports/ImportsNotSupported.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,uFAAuF;AACvF,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC1C;QACI,KAAK,CAAC,0HAA0H,CAAC,CAAC;QAClI,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** What an import does when one of its events is invalid. */
|
|
2
|
+
export declare enum OnInvalidEvent {
|
|
3
|
+
/** Fail the whole import and commit nothing. The default. */
|
|
4
|
+
Reject = 0,
|
|
5
|
+
/** Leave the invalid events out, report them, and commit the rest. */
|
|
6
|
+
Skip = 1
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=OnInvalidEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnInvalidEvent.d.ts","sourceRoot":"","sources":["../../imports/OnInvalidEvent.ts"],"names":[],"mappings":"AAGA,6DAA6D;AAC7D,oBAAY,cAAc;IACtB,6DAA6D;IAC7D,MAAM,IAAI;IAEV,sEAAsE;IACtE,IAAI,IAAI;CACX"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/** What an import does when one of its events is invalid. */
|
|
4
|
+
export var OnInvalidEvent;
|
|
5
|
+
(function (OnInvalidEvent) {
|
|
6
|
+
/** Fail the whole import and commit nothing. The default. */
|
|
7
|
+
OnInvalidEvent[OnInvalidEvent["Reject"] = 0] = "Reject";
|
|
8
|
+
/** Leave the invalid events out, report them, and commit the rest. */
|
|
9
|
+
OnInvalidEvent[OnInvalidEvent["Skip"] = 1] = "Skip";
|
|
10
|
+
})(OnInvalidEvent || (OnInvalidEvent = {}));
|
|
11
|
+
//# sourceMappingURL=OnInvalidEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnInvalidEvent.js","sourceRoot":"","sources":["../../imports/OnInvalidEvent.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,6DAA6D;AAC7D,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACtB,6DAA6D;IAC7D,uDAAU,CAAA;IAEV,sEAAsE;IACtE,mDAAQ,CAAA;AACZ,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits for a while, unless aborted first.
|
|
3
|
+
* @param milliseconds - How long to wait.
|
|
4
|
+
* @param signal - Rejects the wait with its reason when aborted.
|
|
5
|
+
* @returns A promise that resolves after the wait.
|
|
6
|
+
*/
|
|
7
|
+
export declare function delay(milliseconds: number, signal?: AbortSignal): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Waits for a promise, unless aborted first. Aborting does not stop the work the promise stands for.
|
|
10
|
+
* @param promise - The promise to wait for.
|
|
11
|
+
* @param signal - Rejects the wait with its reason when aborted.
|
|
12
|
+
* @returns The value of the promise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function untilAborted<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Reads a sync or async iterable lazily, stopping as soon as a signal aborts, even while the source is waiting for
|
|
17
|
+
* its next value.
|
|
18
|
+
* @param source - The iterable to read.
|
|
19
|
+
* @param signal - Stops reading when aborted.
|
|
20
|
+
* @returns The values of the source.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readUntilAborted<T>(source: AsyncIterable<T> | Iterable<T>, signal: AbortSignal): AsyncGenerator<T>;
|
|
23
|
+
//# sourceMappingURL=abortable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../../imports/abortable.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAK/E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAUrF;AAED;;;;;;GAMG;AACH,wBAAuB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,cAAc,CAAC,CAAC,CAAC,CAezH"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/**
|
|
4
|
+
* Waits for a while, unless aborted first.
|
|
5
|
+
* @param milliseconds - How long to wait.
|
|
6
|
+
* @param signal - Rejects the wait with its reason when aborted.
|
|
7
|
+
* @returns A promise that resolves after the wait.
|
|
8
|
+
*/
|
|
9
|
+
export function delay(milliseconds, signal) {
|
|
10
|
+
return untilAborted(new Promise(resolve => {
|
|
11
|
+
const timer = setTimeout(resolve, milliseconds);
|
|
12
|
+
signal?.addEventListener('abort', () => clearTimeout(timer), { once: true });
|
|
13
|
+
}), signal);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Waits for a promise, unless aborted first. Aborting does not stop the work the promise stands for.
|
|
17
|
+
* @param promise - The promise to wait for.
|
|
18
|
+
* @param signal - Rejects the wait with its reason when aborted.
|
|
19
|
+
* @returns The value of the promise.
|
|
20
|
+
*/
|
|
21
|
+
export function untilAborted(promise, signal) {
|
|
22
|
+
if (!signal)
|
|
23
|
+
return promise;
|
|
24
|
+
if (signal.aborted)
|
|
25
|
+
return Promise.reject(signal.reason);
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const onAbort = () => reject(signal.reason);
|
|
28
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
29
|
+
promise.then(value => { signal.removeEventListener('abort', onAbort); resolve(value); }, error => { signal.removeEventListener('abort', onAbort); reject(error); });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reads a sync or async iterable lazily, stopping as soon as a signal aborts, even while the source is waiting for
|
|
34
|
+
* its next value.
|
|
35
|
+
* @param source - The iterable to read.
|
|
36
|
+
* @param signal - Stops reading when aborted.
|
|
37
|
+
* @returns The values of the source.
|
|
38
|
+
*/
|
|
39
|
+
export async function* readUntilAborted(source, signal) {
|
|
40
|
+
const iterator = Symbol.asyncIterator in source
|
|
41
|
+
? source[Symbol.asyncIterator]()
|
|
42
|
+
: source[Symbol.iterator]();
|
|
43
|
+
let done = false;
|
|
44
|
+
try {
|
|
45
|
+
while (true) {
|
|
46
|
+
const next = await untilAborted(Promise.resolve(iterator.next()), signal);
|
|
47
|
+
if (next.done) {
|
|
48
|
+
done = true;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
yield next.value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
// Let the source release what it holds; a source still waiting for its next value is not waited for.
|
|
56
|
+
if (!done)
|
|
57
|
+
void Promise.resolve(iterator.return?.()).catch(() => undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=abortable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abortable.js","sourceRoot":"","sources":["../../imports/abortable.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,YAAoB,EAAE,MAA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Q,GAAmC,MAAM,CAAC,aAAa,IAAI,MAAM;QAC3E,CAAC,CAAE,MAA2B,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;QACtD,CAAC,CAAE,MAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACjD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,CAAC;QACD,OAAO,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;YAC1E,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBAAC,IAAI,GAAG,IAAI,CAAC;gBAAC,OAAO;YAAC,CAAC;YACvC,MAAM,IAAI,CAAC,KAAK,CAAC;QACrB,CAAC;IACL,CAAC;YAAS,CAAC;QACP,qGAAqG;QACrG,IAAI,CAAC,IAAI;YAAE,KAAK,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChF,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Guid } from '@cratis/fundamentals';
|
|
2
|
+
import type { IEventImport } from './IEventImport.js';
|
|
3
|
+
import type { ImportOptions } from './ImportOptions.js';
|
|
4
|
+
import type { ImportTarget } from './ImportTarget.js';
|
|
5
|
+
/**
|
|
6
|
+
* Begins a new import session, or reattaches to an existing one by its identifier.
|
|
7
|
+
* @param target - The {@link ImportTarget}.
|
|
8
|
+
* @param importIdOrOptions - The identifier of an import to reattach to, or the options for a new one.
|
|
9
|
+
* @param options - The options, when reattaching.
|
|
10
|
+
* @returns The {@link IEventImport}.
|
|
11
|
+
* @throws {@link ImportsNotSupported} when the kernel does not serve imports.
|
|
12
|
+
* @throws {@link ImportCouldNotBegin} when the kernel refuses the import, or the import to reattach to does not exist
|
|
13
|
+
* or targets another event sequence.
|
|
14
|
+
*/
|
|
15
|
+
export declare function beginEventImport(target: ImportTarget, importIdOrOptions?: string | Guid | ImportOptions, options?: ImportOptions): Promise<IEventImport>;
|
|
16
|
+
//# sourceMappingURL=beginEventImport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beginEventImport.d.ts","sourceRoot":"","sources":["../../imports/beginEventImport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAM5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAClC,MAAM,EAAE,YAAY,EACpB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,aAAa,EACjD,OAAO,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,YAAY,CAAC,CAUvB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
import { Guid } from '@cratis/fundamentals';
|
|
4
|
+
import { ClientError, Status } from 'nice-grpc-common';
|
|
5
|
+
import { fromContractsGuid, toContractsGuid } from '../connection/Guid.js';
|
|
6
|
+
import { ensureCommandResponse, ensureQuerySuccess } from '../connection/callResults.js';
|
|
7
|
+
import { EventImport } from './EventImport.js';
|
|
8
|
+
import { ImportCouldNotBegin } from './ImportCouldNotBegin.js';
|
|
9
|
+
import { ImportsNotSupported } from './ImportsNotSupported.js';
|
|
10
|
+
import { OnInvalidEvent } from './OnInvalidEvent.js';
|
|
11
|
+
import { toImportEvent } from './toImportEvent.js';
|
|
12
|
+
/**
|
|
13
|
+
* Begins a new import session, or reattaches to an existing one by its identifier.
|
|
14
|
+
* @param target - The {@link ImportTarget}.
|
|
15
|
+
* @param importIdOrOptions - The identifier of an import to reattach to, or the options for a new one.
|
|
16
|
+
* @param options - The options, when reattaching.
|
|
17
|
+
* @returns The {@link IEventImport}.
|
|
18
|
+
* @throws {@link ImportsNotSupported} when the kernel does not serve imports.
|
|
19
|
+
* @throws {@link ImportCouldNotBegin} when the kernel refuses the import, or the import to reattach to does not exist
|
|
20
|
+
* or targets another event sequence.
|
|
21
|
+
*/
|
|
22
|
+
export async function beginEventImport(target, importIdOrOptions, options) {
|
|
23
|
+
const reattachTo = typeof importIdOrOptions === 'string' || importIdOrOptions instanceof Guid ? Guid.as(importIdOrOptions) : undefined;
|
|
24
|
+
const selected = (reattachTo ? options : importIdOrOptions) ?? {};
|
|
25
|
+
selected.signal?.throwIfAborted();
|
|
26
|
+
try {
|
|
27
|
+
return reattachTo ? await reattach(target, reattachTo, selected) : await begin(target, selected);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof ClientError && error.code === Status.UNIMPLEMENTED)
|
|
31
|
+
throw new ImportsNotSupported();
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function begin(target, options) {
|
|
36
|
+
const response = ensureCommandResponse('begin import', await target.imports.beginImport({
|
|
37
|
+
EventStore: target.eventStore,
|
|
38
|
+
Namespace: target.namespace,
|
|
39
|
+
EventSequenceId: target.eventSequenceId,
|
|
40
|
+
OnInvalid: (options.onInvalid ?? OnInvalidEvent.Reject),
|
|
41
|
+
ImportId: options.importId === undefined ? undefined : toContractsGuid(Guid.as(options.importId))
|
|
42
|
+
}, { signal: options.signal }));
|
|
43
|
+
if (response.Error)
|
|
44
|
+
throw new ImportCouldNotBegin(response.Error);
|
|
45
|
+
return create(target, options, fromContractsGuid(response.ImportId), response.MaxChunkEvents, response.MaxChunkBytes, 0, 0);
|
|
46
|
+
}
|
|
47
|
+
async function reattach(target, importId, options) {
|
|
48
|
+
const progress = ensureQuerySuccess('get import', await target.imports.getImport({
|
|
49
|
+
EventStore: target.eventStore,
|
|
50
|
+
Namespace: target.namespace,
|
|
51
|
+
ImportId: toContractsGuid(importId)
|
|
52
|
+
}, { signal: options.signal }));
|
|
53
|
+
if (!progress)
|
|
54
|
+
throw new ImportCouldNotBegin(`Import '${importId.toString()}' does not exist.`);
|
|
55
|
+
if (progress.EventSequenceId !== target.eventSequenceId) {
|
|
56
|
+
throw new ImportCouldNotBegin(`Import '${importId.toString()}' imports into event sequence '${progress.EventSequenceId}', not '${target.eventSequenceId}'.`);
|
|
57
|
+
}
|
|
58
|
+
return create(target, { ...options, onInvalid: progress.OnInvalid, importId }, importId, progress.MaxChunkEvents, progress.MaxChunkBytes, progress.AcknowledgedChunks, Number(progress.AcknowledgedEvents));
|
|
59
|
+
}
|
|
60
|
+
function create(target, options, importId, maxChunkEvents, maxChunkBytes, acknowledgedChunks, acknowledgedEvents) {
|
|
61
|
+
return new EventImport({
|
|
62
|
+
imports: target.imports,
|
|
63
|
+
eventStore: target.eventStore,
|
|
64
|
+
namespace: target.namespace,
|
|
65
|
+
importId,
|
|
66
|
+
options,
|
|
67
|
+
maxChunkEvents,
|
|
68
|
+
maxChunkBytes,
|
|
69
|
+
convert: event => toImportEvent(event, target.eventSources),
|
|
70
|
+
acknowledgedChunks,
|
|
71
|
+
acknowledgedEvents
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=beginEventImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beginEventImport.js","sourceRoot":"","sources":["../../imports/beginEventImport.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,eAAe,E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AAC;IAChG,IAAI,QAAQ,CAAC,eAAe,KAAK,MAAM,CAAC,eAAe,EAAE,CAAC;QACtD,MAAM,IAAI,mBAAmB,CACzB,WAAW,QAAQ,CAAC,QAAQ,EAAE,kCAAkC,QAAQ,CAAC,eAAe,WAAW,MAAM,CAAC,eAAe,IAAI,CAAC,CAAC;IACvI,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAqC,EAAE,QAAQ,EAAE,EACrG,QAAQ,EAAE,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC;AACrI,CAAC;AAED,SAAS,MAAM,CAAC,MAAoB,EAAE,OAAsB,EAAE,QAAc,EAAE,cAAsB,EAAE,aAAqB,EACvH,kBAA0B,EAAE,kBAA0B;IACtD,OAAO,IAAI,WAAW,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ;QACR,OAAO;QACP,cAAc;QACd,aAAa;QACb,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC;QAC3D,kBAAkB;QAClB,kBAAkB;KACrB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Guid } from '@cratis/fundamentals';
|
|
2
|
+
import { ImportState as ContractsImportState, type AddImportChunkRequest, type ImportEvent, type ImportProgressResponse, type ImportsClient } from '@cratis/chronicle.contracts';
|
|
3
|
+
import type { EventForEventSourceId } from '../../../eventSequences/EventForEventSourceId.js';
|
|
4
|
+
import { EventImport } from '../../EventImport.js';
|
|
5
|
+
import type { EventImportSettings } from '../../EventImportSettings.js';
|
|
6
|
+
/** A chunk the fake kernel received. */
|
|
7
|
+
export interface ReceivedChunk {
|
|
8
|
+
readonly chunkIndex: number;
|
|
9
|
+
readonly firstEventIndex: bigint;
|
|
10
|
+
readonly contents: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
/** A fake of the kernel's Imports service that records the calls an import session makes. */
|
|
13
|
+
export declare class a_kernel_import_session {
|
|
14
|
+
readonly importId: Guid;
|
|
15
|
+
readonly chunks: ReceivedChunk[];
|
|
16
|
+
readonly completions: {
|
|
17
|
+
ExpectedChunks: number;
|
|
18
|
+
ExpectedEvents: bigint;
|
|
19
|
+
}[];
|
|
20
|
+
readonly abandons: number[];
|
|
21
|
+
inFlight: number;
|
|
22
|
+
maxInFlight: number;
|
|
23
|
+
/** Answers each chunk; replace it to fail, refuse or hold chunks. */
|
|
24
|
+
answerChunk: (request: AddImportChunkRequest) => Promise<{
|
|
25
|
+
Error: string;
|
|
26
|
+
}>;
|
|
27
|
+
/** The progress the kernel reports on each read, the last one repeating. */
|
|
28
|
+
reads: Partial<ImportProgressResponse>[];
|
|
29
|
+
readCount: number;
|
|
30
|
+
/** The progress the kernel streams to an observer. */
|
|
31
|
+
observed: Partial<ImportProgressResponse>[];
|
|
32
|
+
/** The chunk limits the kernel gives when an import begins. */
|
|
33
|
+
limits: {
|
|
34
|
+
MaxChunkEvents: number;
|
|
35
|
+
MaxChunkBytes: number;
|
|
36
|
+
};
|
|
37
|
+
readonly imports: {
|
|
38
|
+
beginImport: () => Promise<{
|
|
39
|
+
IsAuthorized: boolean;
|
|
40
|
+
ValidationResults: never[];
|
|
41
|
+
ExceptionMessages: never[];
|
|
42
|
+
ExceptionStackTrace: string;
|
|
43
|
+
AuthorizationFailureReason: string;
|
|
44
|
+
CorrelationId: undefined;
|
|
45
|
+
Response: {
|
|
46
|
+
MaxChunkEvents: number;
|
|
47
|
+
MaxChunkBytes: number;
|
|
48
|
+
ImportId: import("@cratis/chronicle.contracts").Guid;
|
|
49
|
+
State: ContractsImportState;
|
|
50
|
+
Error: string;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
addImportChunk: (request: AddImportChunkRequest) => Promise<{
|
|
54
|
+
IsAuthorized: boolean;
|
|
55
|
+
ValidationResults: never[];
|
|
56
|
+
ExceptionMessages: never[];
|
|
57
|
+
ExceptionStackTrace: string;
|
|
58
|
+
AuthorizationFailureReason: string;
|
|
59
|
+
CorrelationId: undefined;
|
|
60
|
+
Response: {
|
|
61
|
+
ChunkIndex: number;
|
|
62
|
+
AlreadyStaged: boolean;
|
|
63
|
+
EventsReceived: number;
|
|
64
|
+
EventsStaged: number;
|
|
65
|
+
Rejections: never[];
|
|
66
|
+
Error: string;
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
completeImport: (request: {
|
|
70
|
+
ExpectedChunks: number;
|
|
71
|
+
ExpectedEvents: bigint;
|
|
72
|
+
}) => Promise<{
|
|
73
|
+
IsAuthorized: boolean;
|
|
74
|
+
ValidationResults: never[];
|
|
75
|
+
ExceptionMessages: never[];
|
|
76
|
+
ExceptionStackTrace: string;
|
|
77
|
+
AuthorizationFailureReason: string;
|
|
78
|
+
CorrelationId: undefined;
|
|
79
|
+
Response: {
|
|
80
|
+
ImportId: import("@cratis/chronicle.contracts").Guid;
|
|
81
|
+
State: ContractsImportState;
|
|
82
|
+
Error: string;
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
85
|
+
abandonImport: () => Promise<{
|
|
86
|
+
IsAuthorized: boolean;
|
|
87
|
+
ValidationResults: never[];
|
|
88
|
+
ExceptionMessages: never[];
|
|
89
|
+
ExceptionStackTrace: string;
|
|
90
|
+
AuthorizationFailureReason: string;
|
|
91
|
+
CorrelationId: undefined;
|
|
92
|
+
Response: {
|
|
93
|
+
ImportId: import("@cratis/chronicle.contracts").Guid;
|
|
94
|
+
State: ContractsImportState;
|
|
95
|
+
Error: string;
|
|
96
|
+
};
|
|
97
|
+
}>;
|
|
98
|
+
getImport: () => Promise<{
|
|
99
|
+
IsAuthorized: boolean;
|
|
100
|
+
ValidationResults: never[];
|
|
101
|
+
ExceptionMessages: never[];
|
|
102
|
+
ExceptionStackTrace: string;
|
|
103
|
+
CorrelationId: undefined;
|
|
104
|
+
Data: ImportProgressResponse;
|
|
105
|
+
}>;
|
|
106
|
+
observeImport: () => AsyncGenerator<{
|
|
107
|
+
IsAuthorized: boolean;
|
|
108
|
+
ValidationResults: never[];
|
|
109
|
+
ExceptionMessages: never[];
|
|
110
|
+
ExceptionStackTrace: string;
|
|
111
|
+
CorrelationId: undefined;
|
|
112
|
+
Data: ImportProgressResponse;
|
|
113
|
+
}, void, unknown>;
|
|
114
|
+
};
|
|
115
|
+
get client(): ImportsClient;
|
|
116
|
+
/** Creates a session against this fake, converting each event to a wire event carrying its JSON. */
|
|
117
|
+
session(settings?: Partial<EventImportSettings>): EventImport;
|
|
118
|
+
/** The contents of every received chunk, in chunk order. */
|
|
119
|
+
get receivedContents(): string[];
|
|
120
|
+
observe(): AsyncGenerator<{
|
|
121
|
+
IsAuthorized: boolean;
|
|
122
|
+
ValidationResults: never[];
|
|
123
|
+
ExceptionMessages: never[];
|
|
124
|
+
ExceptionStackTrace: string;
|
|
125
|
+
CorrelationId: undefined;
|
|
126
|
+
Data: ImportProgressResponse;
|
|
127
|
+
}, void, unknown>;
|
|
128
|
+
progress(values: Partial<ImportProgressResponse>): ImportProgressResponse;
|
|
129
|
+
private commandResult;
|
|
130
|
+
}
|
|
131
|
+
/** An event for the fake, identified by its number. */
|
|
132
|
+
export declare function numbered(number: number): EventForEventSourceId;
|
|
133
|
+
/** The numbered events from zero up to a count. */
|
|
134
|
+
export declare function numberedEvents(count: number): EventForEventSourceId[];
|
|
135
|
+
/** The wire contents numbered events produce. */
|
|
136
|
+
export declare function contentsOf(count: number): string[];
|
|
137
|
+
/** A wire event carrying the event's JSON as its content. */
|
|
138
|
+
export declare function wireEventFor(event: EventForEventSourceId): ImportEvent;
|
|
139
|
+
/** A promise with its resolver, for holding a fake call until a spec lets it go. */
|
|
140
|
+
export declare function gate(): {
|
|
141
|
+
promise: Promise<void>;
|
|
142
|
+
open: () => void;
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=a_kernel_import_session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a_kernel_import_session.d.ts","sourceRoot":"","sources":["../../../../imports/for_EventImport/given/a_kernel_import_session.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EACH,WAAW,IAAI,oBAAoB,EACnC,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EACrB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kDAAkD,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,6FAA6F;AAC7F,qBAAa,uBAAuB;IAChC,QAAQ,CAAC,QAAQ,OAAiB;IAClC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAM;IACtC,QAAQ,CAAC,WAAW,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,EAAE,CAAM;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAM;IACjC,QAAQ,SAAK;IACb,WAAW,SAAK;IAChB,qEAAqE;IACrE,WAAW,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC;QAAE,KAAK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OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,IAAI,CAAA;CAAE,CAInE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
import { Guid } from '@cratis/fundamentals';
|
|
4
|
+
import { ImportState as ContractsImportState } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { toContractsGuid } from '../../../connection/Guid.js';
|
|
6
|
+
import { EventImport } from '../../EventImport.js';
|
|
7
|
+
/** A fake of the kernel's Imports service that records the calls an import session makes. */
|
|
8
|
+
export class a_kernel_import_session {
|
|
9
|
+
importId = Guid.create();
|
|
10
|
+
chunks = [];
|
|
11
|
+
completions = [];
|
|
12
|
+
abandons = [];
|
|
13
|
+
inFlight = 0;
|
|
14
|
+
maxInFlight = 0;
|
|
15
|
+
/** Answers each chunk; replace it to fail, refuse or hold chunks. */
|
|
16
|
+
answerChunk = async () => ({ Error: '' });
|
|
17
|
+
/** The progress the kernel reports on each read, the last one repeating. */
|
|
18
|
+
reads = [{ State: ContractsImportState.Completed }];
|
|
19
|
+
readCount = 0;
|
|
20
|
+
/** The progress the kernel streams to an observer. */
|
|
21
|
+
observed = [];
|
|
22
|
+
/** The chunk limits the kernel gives when an import begins. */
|
|
23
|
+
limits = { MaxChunkEvents: 0, MaxChunkBytes: 0 };
|
|
24
|
+
imports = {
|
|
25
|
+
beginImport: async () => this.commandResult({ ImportId: toContractsGuid(this.importId), State: ContractsImportState.Open,
|
|
26
|
+
...this.limits, Error: '' }),
|
|
27
|
+
addImportChunk: async (request) => {
|
|
28
|
+
this.inFlight++;
|
|
29
|
+
this.maxInFlight = Math.max(this.maxInFlight, this.inFlight);
|
|
30
|
+
try {
|
|
31
|
+
const answer = await this.answerChunk(request);
|
|
32
|
+
if (!answer.Error) {
|
|
33
|
+
this.chunks.push({
|
|
34
|
+
chunkIndex: request.ChunkIndex,
|
|
35
|
+
firstEventIndex: request.FirstEventIndex,
|
|
36
|
+
contents: request.Events.map(event => event.Content)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return this.commandResult({ ChunkIndex: request.ChunkIndex, AlreadyStaged: false, EventsReceived: request.Events.length,
|
|
40
|
+
EventsStaged: request.Events.length, Rejections: [], Error: answer.Error });
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
this.inFlight--;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
completeImport: async (request) => {
|
|
47
|
+
this.completions.push({ ExpectedChunks: request.ExpectedChunks, ExpectedEvents: request.ExpectedEvents });
|
|
48
|
+
return this.commandResult({ ImportId: toContractsGuid(this.importId), State: ContractsImportState.Validating, Error: '' });
|
|
49
|
+
},
|
|
50
|
+
abandonImport: async () => {
|
|
51
|
+
this.abandons.push(this.chunks.length);
|
|
52
|
+
this.reads = [{ State: ContractsImportState.Abandoned }];
|
|
53
|
+
return this.commandResult({ ImportId: toContractsGuid(this.importId), State: ContractsImportState.Abandoned, Error: '' });
|
|
54
|
+
},
|
|
55
|
+
getImport: async () => {
|
|
56
|
+
const read = this.reads[Math.min(this.readCount++, this.reads.length - 1)];
|
|
57
|
+
return { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [], ExceptionStackTrace: '', CorrelationId: undefined,
|
|
58
|
+
Data: this.progress(read) };
|
|
59
|
+
},
|
|
60
|
+
observeImport: () => this.observe()
|
|
61
|
+
};
|
|
62
|
+
get client() {
|
|
63
|
+
return this.imports;
|
|
64
|
+
}
|
|
65
|
+
/** Creates a session against this fake, converting each event to a wire event carrying its JSON. */
|
|
66
|
+
session(settings = {}) {
|
|
67
|
+
return new EventImport({
|
|
68
|
+
imports: this.client,
|
|
69
|
+
eventStore: 'store',
|
|
70
|
+
namespace: 'default',
|
|
71
|
+
importId: this.importId,
|
|
72
|
+
options: {},
|
|
73
|
+
maxChunkEvents: 0,
|
|
74
|
+
maxChunkBytes: 0,
|
|
75
|
+
convert: wireEventFor,
|
|
76
|
+
retryDelay: () => 0,
|
|
77
|
+
pollInterval: 0,
|
|
78
|
+
...settings
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** The contents of every received chunk, in chunk order. */
|
|
82
|
+
get receivedContents() {
|
|
83
|
+
return [...this.chunks].sort((left, right) => left.chunkIndex - right.chunkIndex).flatMap(chunk => [...chunk.contents]);
|
|
84
|
+
}
|
|
85
|
+
async *observe() {
|
|
86
|
+
for (const progress of this.observed) {
|
|
87
|
+
yield { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [], ExceptionStackTrace: '', CorrelationId: undefined,
|
|
88
|
+
Data: this.progress(progress) };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
progress(values) {
|
|
92
|
+
return {
|
|
93
|
+
ImportId: toContractsGuid(this.importId), EventSequenceId: 'event-log', State: ContractsImportState.Staging, OnInvalid: 0,
|
|
94
|
+
Created: undefined, LastActivity: undefined, StagedChunks: [], EventsReceived: 0n, EventsStaged: 0n, EventsCommitted: 0n,
|
|
95
|
+
AlreadyAppended: 0n, RejectedCount: 0n, Rejections: [], CommittedRanges: [], FirstSequenceNumber: 0n, LastSequenceNumber: 0n,
|
|
96
|
+
FailureReason: '', MaxChunkEvents: 0, MaxChunkBytes: 0, AcknowledgedChunks: 0, AcknowledgedEvents: 0n,
|
|
97
|
+
...values
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
commandResult(response) {
|
|
101
|
+
return { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [], ExceptionStackTrace: '', AuthorizationFailureReason: '',
|
|
102
|
+
CorrelationId: undefined, Response: response };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** An event for the fake, identified by its number. */
|
|
106
|
+
export function numbered(number) {
|
|
107
|
+
return { eventSourceId: 'source', event: { number } };
|
|
108
|
+
}
|
|
109
|
+
/** The numbered events from zero up to a count. */
|
|
110
|
+
export function numberedEvents(count) {
|
|
111
|
+
return Array.from({ length: count }, (_, index) => numbered(index));
|
|
112
|
+
}
|
|
113
|
+
/** The wire contents numbered events produce. */
|
|
114
|
+
export function contentsOf(count) {
|
|
115
|
+
return numberedEvents(count).map(event => JSON.stringify(event.event));
|
|
116
|
+
}
|
|
117
|
+
/** A wire event carrying the event's JSON as its content. */
|
|
118
|
+
export function wireEventFor(event) {
|
|
119
|
+
return {
|
|
120
|
+
EventSourceId: event.eventSourceId, EventSourceType: '', EventStreamType: '', EventStreamId: '',
|
|
121
|
+
EventType: { Id: 'numbered', Generation: 1, Tombstone: false }, Content: JSON.stringify(event.event), Tags: [], NamedTags: [],
|
|
122
|
+
Occurred: undefined, Subject: '', CorrelationId: undefined, Causation: [], CausedBy: undefined, IdempotencyKey: '', EventSource: '',
|
|
123
|
+
SourceSequenceNumber: 0n
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** A promise with its resolver, for holding a fake call until a spec lets it go. */
|
|
127
|
+
export function gate() {
|
|
128
|
+
let open;
|
|
129
|
+
const promise = new Promise(resolve => { open = resolve; });
|
|
130
|
+
return { promise, open };
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=a_kernel_import_session.js.map
|