@cratis/arc 24.6.0 → 24.8.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/availability/Availability.ts +94 -19
- package/availability/AvailabilityReason.ts +7 -0
- package/availability/AvailableParts.ts +4 -0
- package/availability/ObserveAvailableParts.ts +22 -2
- package/availability/PartAvailability.ts +43 -0
- package/availability/UnavailablePart.ts +3 -0
- package/availability/askAvailability.ts +66 -0
- package/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_proxy_carries_its_identity.ts +24 -0
- package/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_server_lists_it_as_suspended.ts +20 -0
- package/availability/for_askAvailability/when_answering_for_a_part.ts +15 -0
- package/availability/index.ts +3 -0
- package/availability/isSuspended.ts +14 -0
- package/commands/CommandResult.ts +21 -0
- package/dist/cjs/availability/Availability.d.ts +18 -11
- package/dist/cjs/availability/Availability.d.ts.map +1 -1
- package/dist/cjs/availability/Availability.js +64 -12
- package/dist/cjs/availability/Availability.js.map +1 -1
- package/dist/cjs/availability/AvailabilityReason.d.ts +1 -0
- package/dist/cjs/availability/AvailabilityReason.d.ts.map +1 -1
- package/dist/cjs/availability/AvailabilityReason.js +6 -0
- package/dist/cjs/availability/AvailabilityReason.js.map +1 -1
- package/dist/cjs/availability/AvailableParts.d.ts +1 -0
- package/dist/cjs/availability/AvailableParts.d.ts.map +1 -1
- package/dist/cjs/availability/AvailableParts.js +5 -0
- package/dist/cjs/availability/AvailableParts.js.map +1 -1
- package/dist/cjs/availability/ObserveAvailableParts.d.ts +7 -1
- package/dist/cjs/availability/ObserveAvailableParts.d.ts.map +1 -1
- package/dist/cjs/availability/ObserveAvailableParts.js +10 -1
- package/dist/cjs/availability/ObserveAvailableParts.js.map +1 -1
- package/dist/cjs/availability/PartAvailability.d.ts +12 -0
- package/dist/cjs/availability/PartAvailability.d.ts.map +1 -0
- package/dist/cjs/availability/PartAvailability.js +41 -0
- package/dist/cjs/availability/PartAvailability.js.map +1 -0
- package/dist/cjs/availability/UnavailablePart.d.ts +1 -0
- package/dist/cjs/availability/UnavailablePart.d.ts.map +1 -1
- package/dist/cjs/availability/askAvailability.d.ts +6 -0
- package/dist/cjs/availability/askAvailability.d.ts.map +1 -0
- package/dist/cjs/availability/askAvailability.js +65 -0
- package/dist/cjs/availability/askAvailability.js.map +1 -0
- package/dist/cjs/availability/index.d.ts +3 -0
- package/dist/cjs/availability/index.d.ts.map +1 -1
- package/dist/cjs/availability/index.js +9 -0
- package/dist/cjs/availability/index.js.map +1 -1
- package/dist/cjs/availability/isSuspended.d.ts +5 -0
- package/dist/cjs/availability/isSuspended.d.ts.map +1 -0
- package/dist/cjs/availability/isSuspended.js +17 -0
- package/dist/cjs/availability/isSuspended.js.map +1 -0
- package/dist/cjs/commands/CommandResult.d.ts +2 -0
- package/dist/cjs/commands/CommandResult.d.ts.map +1 -1
- package/dist/cjs/commands/CommandResult.js +17 -0
- package/dist/cjs/commands/CommandResult.js.map +1 -1
- package/dist/cjs/reflection/PartIdentity.d.ts +8 -0
- package/dist/cjs/reflection/PartIdentity.d.ts.map +1 -0
- package/dist/cjs/reflection/PartIdentity.js +31 -0
- package/dist/cjs/reflection/PartIdentity.js.map +1 -0
- package/dist/cjs/reflection/index.d.ts +1 -0
- package/dist/cjs/reflection/index.d.ts.map +1 -1
- package/dist/cjs/reflection/index.js +2 -0
- package/dist/cjs/reflection/index.js.map +1 -1
- package/dist/esm/availability/Availability.d.ts +18 -11
- package/dist/esm/availability/Availability.d.ts.map +1 -1
- package/dist/esm/availability/Availability.js +64 -13
- package/dist/esm/availability/Availability.js.map +1 -1
- package/dist/esm/availability/AvailabilityReason.d.ts +1 -0
- package/dist/esm/availability/AvailabilityReason.d.ts.map +1 -1
- package/dist/esm/availability/AvailabilityReason.js +6 -1
- package/dist/esm/availability/AvailabilityReason.js.map +1 -1
- package/dist/esm/availability/AvailableParts.d.ts +1 -0
- package/dist/esm/availability/AvailableParts.d.ts.map +1 -1
- package/dist/esm/availability/AvailableParts.js +5 -0
- package/dist/esm/availability/AvailableParts.js.map +1 -1
- package/dist/esm/availability/ObserveAvailableParts.d.ts +7 -1
- package/dist/esm/availability/ObserveAvailableParts.d.ts.map +1 -1
- package/dist/esm/availability/ObserveAvailableParts.js +10 -1
- package/dist/esm/availability/ObserveAvailableParts.js.map +1 -1
- package/dist/esm/availability/PartAvailability.d.ts +12 -0
- package/dist/esm/availability/PartAvailability.d.ts.map +1 -0
- package/dist/esm/availability/PartAvailability.js +39 -0
- package/dist/esm/availability/PartAvailability.js.map +1 -0
- package/dist/esm/availability/UnavailablePart.d.ts +1 -0
- package/dist/esm/availability/UnavailablePart.d.ts.map +1 -1
- package/dist/esm/availability/askAvailability.d.ts +6 -0
- package/dist/esm/availability/askAvailability.d.ts.map +1 -0
- package/dist/esm/availability/askAvailability.js +62 -0
- package/dist/esm/availability/askAvailability.js.map +1 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_proxy_carries_its_identity.d.ts +2 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_proxy_carries_its_identity.d.ts.map +1 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_proxy_carries_its_identity.js +20 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_proxy_carries_its_identity.js.map +1 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_server_lists_it_as_suspended.d.ts +2 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_server_lists_it_as_suspended.d.ts.map +1 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_server_lists_it_as_suspended.js +16 -0
- package/dist/esm/availability/for_Availability/when_asking_whether_a_part_is_available/and_the_server_lists_it_as_suspended.js.map +1 -0
- package/dist/esm/availability/for_askAvailability/when_answering_for_a_part.d.ts +2 -0
- package/dist/esm/availability/for_askAvailability/when_answering_for_a_part.d.ts.map +1 -0
- package/dist/esm/availability/for_askAvailability/when_answering_for_a_part.js +11 -0
- package/dist/esm/availability/for_askAvailability/when_answering_for_a_part.js.map +1 -0
- package/dist/esm/availability/index.d.ts +3 -0
- package/dist/esm/availability/index.d.ts.map +1 -1
- package/dist/esm/availability/index.js +5 -2
- package/dist/esm/availability/index.js.map +1 -1
- package/dist/esm/availability/isSuspended.d.ts +5 -0
- package/dist/esm/availability/isSuspended.d.ts.map +1 -0
- package/dist/esm/availability/isSuspended.js +15 -0
- package/dist/esm/availability/isSuspended.js.map +1 -0
- package/dist/esm/commands/CommandResult.d.ts +2 -0
- package/dist/esm/commands/CommandResult.d.ts.map +1 -1
- package/dist/esm/commands/CommandResult.js +17 -0
- package/dist/esm/commands/CommandResult.js.map +1 -1
- package/dist/esm/reflection/PartIdentity.d.ts +8 -0
- package/dist/esm/reflection/PartIdentity.d.ts.map +1 -0
- package/dist/esm/reflection/PartIdentity.js +29 -0
- package/dist/esm/reflection/PartIdentity.js.map +1 -0
- package/dist/esm/reflection/index.d.ts +1 -0
- package/dist/esm/reflection/index.d.ts.map +1 -1
- package/dist/esm/reflection/index.js +1 -0
- package/dist/esm/reflection/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/reflection/PartIdentity.ts +21 -0
- package/reflection/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Availability.js","sources":["../../../availability/Availability.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { UnavailablePart } from './UnavailablePart.js';\n\n/**\n * Something a client can ask about: the full name of a command or read model on the server, or a generated proxy\n * (class or instance) that carries the slice it belongs to.\n */\nexport type AvailabilityPart =\n | string\n | { readonly sliceLocation?: { readonly
|
|
1
|
+
{"version":3,"file":"Availability.js","sources":["../../../availability/Availability.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { UnavailablePart } from './UnavailablePart.js';\nimport { PartAvailability } from './PartAvailability.js';\n\ninterface Location {\n readonly module: string;\n readonly feature: string;\n readonly slice: string;\n}\n\ninterface Identity extends Location {\n readonly name: string;\n}\n\n/**\n * Something a client can ask about: the full name of a command or read model on the server, or a generated proxy\n * (class or instance) that carries the part it is and the slice it belongs to.\n */\nexport type AvailabilityPart =\n | string\n | Identity\n | { readonly part?: Identity; readonly sliceLocation?: Location }\n | { readonly constructor: { readonly part?: Identity; readonly sliceLocation?: Location } };\n\n/**\n * Gets the full name of a part, when it is known.\n * @param part The full name, or a generated proxy or part identity.\n * @returns The name the server knows the part by; undefined when the proxy does not carry one.\n */\nexport function partNameOf(part: AvailabilityPart): string | undefined {\n if (typeof part === 'string') {\n return part;\n }\n\n return identityOf(part)?.name;\n}\n\n/**\n * Represents what is available to the current context, from the last decision the server reported.\n *\n * Everything the server does not list is available. Until the first decision has arrived nothing is known, and\n * nothing is reported as available, so a client never shows a part it has not been told it may show.\n *\n * This answers for the context alone, such as the tenant and the user. A gate that depends on the data a command or\n * query is about, such as one vessel, is asked with `askAvailability` (or `useIsAvailable` in React), which sends the data.\n */\nexport class Availability {\n /** An availability that has not heard from the server yet. */\n static readonly unknown: Availability = new Availability([], false);\n\n /** An availability that treats every part as available, for hosts that do not use availability. */\n static readonly everything: Availability = new Availability([], true);\n\n /**\n * Initializes a new instance of {@link Availability}.\n * @param unavailable The parts the server reported as not available.\n * @param isKnown Whether a decision has arrived.\n */\n constructor(readonly unavailable: readonly UnavailablePart[], readonly isKnown: boolean = true) {\n }\n\n /**\n * Determines whether a part is available.\n * @param part The full name of a command or read model, or a generated proxy. A proxy is matched by the part it is\n * and by the slice it belongs to, so every part of a slice is hidden together, which is how navigation and screens are decided.\n * @returns True when the part is available; false when it is not, or when nothing is known yet.\n */\n isAvailable(part: AvailabilityPart): boolean {\n return this.availabilityOf(part).isAvailable;\n }\n\n /**\n * Gets whether, and if not why, a part is available.\n * @param part The full name of a command or read model, or a generated proxy.\n * @returns The {@link PartAvailability}; `NotAvailable` is told apart from `Suspended` by its reason.\n */\n availabilityOf(part: AvailabilityPart): PartAvailability {\n if (!this.isKnown) {\n return PartAvailability.unknown;\n }\n\n const listed = this.find(part);\n return listed === undefined ? PartAvailability.available : PartAvailability.refused(listed.reason);\n }\n\n /**\n * Keeps the items whose part is available.\n * @param items The items, for example navigation entries.\n * @param partOf Gets the part an item belongs to; an item without one is always kept.\n * @returns The items that are available.\n */\n filter<TItem>(items: readonly TItem[], partOf: (item: TItem) => AvailabilityPart | undefined): TItem[] {\n return items.filter(item => {\n const part = partOf(item);\n return part === undefined || this.isAvailable(part);\n });\n }\n\n private find(part: AvailabilityPart): UnavailablePart | undefined {\n if (typeof part === 'string') {\n return this.unavailable.find(_ => _.name === part);\n }\n\n const identity = identityOf(part);\n if (identity !== undefined) {\n const byName = this.unavailable.find(_ => _.name === identity.name);\n if (byName !== undefined) {\n return byName;\n }\n }\n\n const location = locationOf(part, identity);\n if (location === undefined || (location.module === '' && location.feature === '' && location.slice === '')) {\n return undefined;\n }\n\n return this.unavailable.find(_ => _.module === location.module && _.feature === location.feature && _.slice === location.slice);\n }\n}\n\nfunction identityOf(part: Exclude<AvailabilityPart, string>): Identity | undefined {\n // A proxy class declares its identity as the static `part`. An instance is read through its class only, because a\n // command or query may itself have a property named `part`.\n if (typeof part === 'function') {\n return asIdentity((part as { part?: unknown }).part);\n }\n\n return asIdentity(part) ?? asIdentity((part as { constructor?: { part?: unknown } }).constructor?.part);\n}\n\nfunction asIdentity(value: unknown): Identity | undefined {\n if (typeof value !== 'object' || value === null) {\n return undefined;\n }\n\n const candidate = value as Record<string, unknown>;\n return typeof candidate.name === 'string' && typeof candidate.module === 'string' && typeof candidate.feature === 'string' && typeof candidate.slice === 'string'\n ? value as Identity\n : undefined;\n}\n\nfunction locationOf(part: Exclude<AvailabilityPart, string>, identity: Identity | undefined): Location | undefined {\n if (identity !== undefined) {\n return identity;\n }\n\n const own = (part as { sliceLocation?: Location }).sliceLocation;\n if (own !== undefined) {\n return own;\n }\n\n return (part as { constructor?: { sliceLocation?: Location } }).constructor?.sliceLocation;\n}\n"],"names":["partNameOf","part","identityOf","name","Availability","unknown","everything","isKnown","unavailable","isAvailable","availabilityOf","PartAvailability","listed","find","undefined","available","refused","reason","filter","items","partOf","item","_","identity","byName","location","locationOf","module","feature","slice","asIdentity","value","candidate","own","sliceLocation"],"mappings":";;;;AAAA;AACA;AAyBA;;;;IAKO,SAASA,UAAAA,CAAWC,IAAsB,EAAA;IAC7C,IAAI,OAAOA,SAAS,QAAA,EAAU;QAC1B,OAAOA,IAAAA;AACX,IAAA;AAEA,IAAA,OAAOC,WAAWD,IAAAA,CAAAA,EAAOE,IAAAA;AAC7B;AAEA;;;;;;;;AAQC,IACM,MAAMC,YAAAA,CAAAA;;;AACT,mEACA,OAAgBC,OAAAA,GAAwB,IAAID,YAAAA,CAAa,EAAE,EAAE,KAAA,CAAA;AAE7D,wGACA,OAAgBE,UAAAA,GAA2B,IAAIF,YAAAA,CAAa,EAAE,EAAE,IAAA,CAAA;AAEhE;;;;AAIC,QACD,YAAY,WAAgD,EAAE,OAASG,GAAmB,IAAI,CAAE;aAA3EC,WAAAA,GAAAA,WAAAA;aAAkDD,OAAAA,GAAAA,OAAAA;AACvE,IAAA;AAEA;;;;;QAMAE,WAAAA,CAAYR,IAAsB,EAAW;AACzC,QAAA,OAAO,IAAI,CAACS,cAAc,CAACT,MAAMQ,WAAW;AAChD,IAAA;AAEA;;;;QAKAC,cAAAA,CAAeT,IAAsB,EAAoB;AACrD,QAAA,IAAI,CAAC,IAAI,CAACM,OAAO,EAAE;AACf,YAAA,OAAOI,kCAAiBN,OAAO;AACnC,QAAA;AAEA,QAAA,MAAMO,MAAAA,GAAS,IAAI,CAACC,IAAI,CAACZ,IAAAA,CAAAA;QACzB,OAAOW,MAAAA,KAAWE,YAAYH,iCAAAA,CAAiBI,SAAS,GAAG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availability/AvailabilityReason.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"AvailabilityReason.d.ts","sourceRoot":"","sources":["../../../availability/AvailabilityReason.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAO3C,eAAO,MAAM,SAAS,cAAc,CAAC"}
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* to the caller. It is distinct from being forbidden: availability decides whether a part exists for the caller at
|
|
8
8
|
* all, authorization decides what the caller may do in it.
|
|
9
9
|
*/ const NotAvailable = 'NotAvailable';
|
|
10
|
+
/**
|
|
11
|
+
* The authorization failure reason of a command or query result, and the reason of a part the server lists, when an
|
|
12
|
+
* operator has suspended the part. It is distinct from {@link NotAvailable}: a suspended part comes back when the
|
|
13
|
+
* suspension is lifted, so a client can say so instead of treating the part as gone.
|
|
14
|
+
*/ const Suspended = 'Suspended';
|
|
10
15
|
|
|
11
16
|
exports.NotAvailable = NotAvailable;
|
|
17
|
+
exports.Suspended = Suspended;
|
|
12
18
|
//# sourceMappingURL=AvailabilityReason.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvailabilityReason.js","sources":["../../../availability/AvailabilityReason.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * The authorization failure reason of a command or query result when its part of the application is not available\n * to the caller. It is distinct from being forbidden: availability decides whether a part exists for the caller at\n * all, authorization decides what the caller may do in it.\n */\nexport const NotAvailable = 'NotAvailable';\n"],"names":["NotAvailable"],"mappings":";;AAAA;AACA;AAEA;;;;IAKO,MAAMA,YAAAA,GAAe
|
|
1
|
+
{"version":3,"file":"AvailabilityReason.js","sources":["../../../availability/AvailabilityReason.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * The authorization failure reason of a command or query result when its part of the application is not available\n * to the caller. It is distinct from being forbidden: availability decides whether a part exists for the caller at\n * all, authorization decides what the caller may do in it.\n */\nexport const NotAvailable = 'NotAvailable';\n\n/**\n * The authorization failure reason of a command or query result, and the reason of a part the server lists, when an\n * operator has suspended the part. It is distinct from {@link NotAvailable}: a suspended part comes back when the\n * suspension is lifted, so a client can say so instead of treating the part as gone.\n */\nexport const Suspended = 'Suspended';\n"],"names":["NotAvailable","Suspended"],"mappings":";;AAAA;AACA;AAEA;;;;IAKO,MAAMA,YAAAA,GAAe;AAE5B;;;;IAKO,MAAMC,SAAAA,GAAY;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvailableParts.d.ts","sourceRoot":"","sources":["../../../availability/AvailableParts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AvailableParts.d.ts","sourceRoot":"","sources":["../../../availability/AvailableParts.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKvD,qBAAa,oBAAqB,YAAW,eAAe;IAExD,IAAI,SAAM;IAGV,MAAM,SAAM;IAGZ,OAAO,SAAM;IAGb,KAAK,SAAM;IAGX,MAAM,SAAgB;CACzB;AAKD,qBAAa,cAAc;IAEvB,WAAW,EAAE,oBAAoB,EAAE,CAAM;CAC5C"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var fundamentals = require('@cratis/fundamentals');
|
|
4
|
+
var AvailabilityReason = require('./AvailabilityReason.js');
|
|
4
5
|
|
|
5
6
|
function _ts_decorate(decorators, target, key, desc) {
|
|
6
7
|
var c = arguments.length, r = c < 3 ? target : desc, d;
|
|
@@ -27,6 +28,7 @@ function _ts_metadata(metadataKey, metadataValue) {
|
|
|
27
28
|
module = '';
|
|
28
29
|
feature = '';
|
|
29
30
|
slice = '';
|
|
31
|
+
reason = AvailabilityReason.NotAvailable;
|
|
30
32
|
}
|
|
31
33
|
_ts_decorate([
|
|
32
34
|
fundamentals.field(String)
|
|
@@ -40,6 +42,9 @@ _ts_decorate([
|
|
|
40
42
|
_ts_decorate([
|
|
41
43
|
fundamentals.field(String)
|
|
42
44
|
], UnavailablePartModel.prototype, "slice", void 0);
|
|
45
|
+
_ts_decorate([
|
|
46
|
+
fundamentals.field(String)
|
|
47
|
+
], UnavailablePartModel.prototype, "reason", void 0);
|
|
43
48
|
/**
|
|
44
49
|
* What is not available to the current context, as the server reports it. Everything not listed is available.
|
|
45
50
|
*/ class AvailableParts {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvailableParts.js","sources":["../../../availability/AvailableParts.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { field } from '@cratis/fundamentals';\nimport { UnavailablePart } from './UnavailablePart.js';\n\n/**\n * The part of an unavailable-parts message that names one part. Matches {@link UnavailablePart}.\n */\nexport class UnavailablePartModel implements UnavailablePart {\n @field(String)\n name = '';\n\n @field(String)\n module = '';\n\n @field(String)\n feature = '';\n\n @field(String)\n slice = '';\n}\n\n/**\n * What is not available to the current context, as the server reports it. Everything not listed is available.\n */\nexport class AvailableParts {\n @field(UnavailablePartModel, true)\n unavailable: UnavailablePartModel[] = [];\n}\n"],"names":["UnavailablePartModel","name","module","feature","slice","AvailableParts","unavailable"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AvailableParts.js","sources":["../../../availability/AvailableParts.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { field } from '@cratis/fundamentals';\nimport { NotAvailable } from './AvailabilityReason.js';\nimport { UnavailablePart } from './UnavailablePart.js';\n\n/**\n * The part of an unavailable-parts message that names one part. Matches {@link UnavailablePart}.\n */\nexport class UnavailablePartModel implements UnavailablePart {\n @field(String)\n name = '';\n\n @field(String)\n module = '';\n\n @field(String)\n feature = '';\n\n @field(String)\n slice = '';\n\n @field(String)\n reason = NotAvailable;\n}\n\n/**\n * What is not available to the current context, as the server reports it. Everything not listed is available.\n */\nexport class AvailableParts {\n @field(UnavailablePartModel, true)\n unavailable: UnavailablePartModel[] = [];\n}\n"],"names":["UnavailablePartModel","name","module","feature","slice","reason","NotAvailable","AvailableParts","unavailable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA;;AAEC,IACM,MAAMA,oBAAAA,CAAAA;AAETC,IAAAA,IAAAA,GAAO,EAAA;AAGPC,IAAAA,MAAAA,GAAS,EAAA;AAGTC,IAAAA,OAAAA,GAAU,EAAA;AAGVC,IAAAA,KAAAA,GAAQ,EAAA;AAGRC,IAAAA,MAAAA,GAASC,+BAAAA;AACb;;;;;;;;;;;;;;;;AAEA;;AAEC,IACM,MAAMC,cAAAA,CAAAA;AAETC,IAAAA,WAAAA,GAAsC,EAAE;AAC5C;;;;;;;"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { ObservableQueryFor } from '../queries/ObservableQueryFor.js';
|
|
2
2
|
import { ParameterDescriptor } from '../reflection/ParameterDescriptor.js';
|
|
3
3
|
import { AvailableParts } from './AvailableParts.js';
|
|
4
|
-
export
|
|
4
|
+
export interface ObserveAvailablePartsParameters {
|
|
5
|
+
part?: string;
|
|
6
|
+
arguments?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class ObserveAvailableParts extends ObservableQueryFor<AvailableParts, ObserveAvailablePartsParameters> {
|
|
5
9
|
readonly route = "/.cratis/availability";
|
|
6
10
|
readonly defaultValue: AvailableParts;
|
|
7
11
|
readonly parameterDescriptors: ParameterDescriptor[];
|
|
12
|
+
part?: string;
|
|
13
|
+
arguments?: string;
|
|
8
14
|
get requiredRequestParameters(): string[];
|
|
9
15
|
constructor();
|
|
10
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObserveAvailableParts.d.ts","sourceRoot":"","sources":["../../../availability/ObserveAvailableParts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObserveAvailableParts.d.ts","sourceRoot":"","sources":["../../../availability/ObserveAvailableParts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,MAAM,WAAW,+BAA+B;IAE5C,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AASD,qBAAa,qBAAsB,SAAQ,kBAAkB,CAAC,cAAc,EAAE,+BAA+B,CAAC;IAC1G,QAAQ,CAAC,KAAK,2BAA2B;IACzC,QAAQ,CAAC,YAAY,iBAAwB;IAC7C,QAAQ,CAAC,oBAAoB,EAAE,mBAAmB,EAAE,CAGlD;IAEF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,IAAI,yBAAyB,IAAI,MAAM,EAAE,CAExC;IAED,cAEC;CACJ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ObservableQueryFor = require('../queries/ObservableQueryFor.js');
|
|
4
|
+
var ParameterDescriptor = require('../reflection/ParameterDescriptor.js');
|
|
4
5
|
var AvailableParts = require('./AvailableParts.js');
|
|
5
6
|
|
|
6
7
|
// Copyright (c) Cratis. All rights reserved.
|
|
@@ -8,10 +9,18 @@ var AvailableParts = require('./AvailableParts.js');
|
|
|
8
9
|
/**
|
|
9
10
|
* Observes what is not available to the current context. It reports the current decision first and again every time
|
|
10
11
|
* it changes, so an open session updates without a reload.
|
|
12
|
+
*
|
|
13
|
+
* With `part` (and `arguments`) it answers for that one part and the data it is about: the part is listed when it is
|
|
14
|
+
* not available for those arguments, and the answer is empty when it is available.
|
|
11
15
|
*/ class ObserveAvailableParts extends ObservableQueryFor.ObservableQueryFor {
|
|
12
16
|
route = '/.cratis/availability';
|
|
13
17
|
defaultValue = new AvailableParts.AvailableParts();
|
|
14
|
-
parameterDescriptors = [
|
|
18
|
+
parameterDescriptors = [
|
|
19
|
+
new ParameterDescriptor.ParameterDescriptor('arguments', String, false),
|
|
20
|
+
new ParameterDescriptor.ParameterDescriptor('part', String, false)
|
|
21
|
+
];
|
|
22
|
+
part;
|
|
23
|
+
arguments;
|
|
15
24
|
get requiredRequestParameters() {
|
|
16
25
|
return [];
|
|
17
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObserveAvailableParts.js","sources":["../../../availability/ObserveAvailableParts.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ObservableQueryFor } from '../queries/ObservableQueryFor.js';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor.js';\nimport { AvailableParts } from './AvailableParts.js';\n\n/**\n * Observes what is not available to the current context. It reports the current decision first and again every time\n * it changes, so an open session updates without a reload.\n */\nexport class ObserveAvailableParts extends ObservableQueryFor<AvailableParts> {\n readonly route = '/.cratis/availability';\n readonly defaultValue = new AvailableParts();\n readonly parameterDescriptors: ParameterDescriptor[] = [];\n\n get requiredRequestParameters(): string[] {\n return [];\n }\n\n constructor() {\n super(AvailableParts, false);\n }\n}\n"],"names":["ObserveAvailableParts","ObservableQueryFor","route","defaultValue","AvailableParts","parameterDescriptors","requiredRequestParameters"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ObserveAvailableParts.js","sources":["../../../availability/ObserveAvailableParts.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ObservableQueryFor } from '../queries/ObservableQueryFor.js';\nimport { ParameterDescriptor } from '../reflection/ParameterDescriptor.js';\nimport { AvailableParts } from './AvailableParts.js';\n\n/**\n * The parameters of {@link ObserveAvailableParts}.\n */\nexport interface ObserveAvailablePartsParameters {\n /** The full name of one part to ask about. Every part is decided when it is not given. */\n part?: string;\n\n /** The arguments of that part as a JSON object, for a gate that reads `arguments.name`. */\n arguments?: string;\n}\n\n/**\n * Observes what is not available to the current context. It reports the current decision first and again every time\n * it changes, so an open session updates without a reload.\n *\n * With `part` (and `arguments`) it answers for that one part and the data it is about: the part is listed when it is\n * not available for those arguments, and the answer is empty when it is available.\n */\nexport class ObserveAvailableParts extends ObservableQueryFor<AvailableParts, ObserveAvailablePartsParameters> {\n readonly route = '/.cratis/availability';\n readonly defaultValue = new AvailableParts();\n readonly parameterDescriptors: ParameterDescriptor[] = [\n new ParameterDescriptor('arguments', String, false),\n new ParameterDescriptor('part', String, false),\n ];\n\n part?: string;\n arguments?: string;\n\n get requiredRequestParameters(): string[] {\n return [];\n }\n\n constructor() {\n super(AvailableParts, false);\n }\n}\n"],"names":["ObserveAvailableParts","ObservableQueryFor","route","defaultValue","AvailableParts","parameterDescriptors","ParameterDescriptor","String","part","arguments","requiredRequestParameters"],"mappings":";;;;;;AAAA;AACA;AAiBA;;;;;;IAOO,MAAMA,qBAAAA,SAA8BC,qCAAAA,CAAAA;AAC9BC,IAAAA,KAAAA,GAAQ,uBAAA;AACRC,IAAAA,YAAAA,GAAe,IAAIC,6BAAAA,EAAAA;IACnBC,oBAAAA,GAA8C;QACnD,IAAIC,uCAAAA,CAAoB,aAAaC,MAAAA,EAAQ,KAAA,CAAA;QAC7C,IAAID,uCAAAA,CAAoB,QAAQC,MAAAA,EAAQ,KAAA;KAC3C;IAEDC,IAAAA;IACAC,SAAAA;AAEA,IAAA,IAAIC,yBAAAA,GAAsC;AACtC,QAAA,OAAO,EAAE;AACb,IAAA;IAEA,WAAA,EAAc;AACV,QAAA,KAAK,CAACN,6BAAAA,EAAgB,KAAA,CAAA;AAC1B,IAAA;AACJ;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class PartAvailability {
|
|
2
|
+
readonly isAvailable: boolean;
|
|
3
|
+
readonly reason?: string | undefined;
|
|
4
|
+
readonly isKnown: boolean;
|
|
5
|
+
static readonly available: PartAvailability;
|
|
6
|
+
static readonly unknown: PartAvailability;
|
|
7
|
+
constructor(isAvailable: boolean, reason?: string | undefined, isKnown?: boolean);
|
|
8
|
+
get isNotAvailable(): boolean;
|
|
9
|
+
get isSuspended(): boolean;
|
|
10
|
+
static refused(reason?: string): PartAvailability;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=PartAvailability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PartAvailability.d.ts","sourceRoot":"","sources":["../../../availability/PartAvailability.ts"],"names":[],"mappings":"AAQA,qBAAa,gBAAgB;IAab,QAAQ,CAAC,WAAW,EAAE,OAAO;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO;IAX9F,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAA8B;IAGzE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAiD;IAQ1F,YAAqB,WAAW,EAAE,OAAO,EAAW,MAAM,CAAC,EAAE,MAAM,YAAA,EAAW,OAAO,GAAE,OAAc,EACpG;IAGD,IAAI,cAAc,IAAI,OAAO,CAE5B;IAGD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAOD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAEhD;CACJ"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AvailabilityReason = require('./AvailabilityReason.js');
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
6
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
7
|
+
/**
|
|
8
|
+
* The answer to whether one part is available, optionally for the data it is about.
|
|
9
|
+
*/ class PartAvailability {
|
|
10
|
+
isAvailable;
|
|
11
|
+
reason;
|
|
12
|
+
isKnown;
|
|
13
|
+
/** The answer for a part that is available. */ static available = new PartAvailability(true);
|
|
14
|
+
/** The answer when the server has not told yet, or could not decide. Nothing is reported as available. */ static unknown = new PartAvailability(false, undefined, false);
|
|
15
|
+
/**
|
|
16
|
+
* Initializes a new instance of {@link PartAvailability}.
|
|
17
|
+
* @param isAvailable Whether the part is available.
|
|
18
|
+
* @param reason Why it is not: `NotAvailable` or `Suspended`; undefined when it is available or not known.
|
|
19
|
+
* @param isKnown Whether the server has decided.
|
|
20
|
+
*/ constructor(isAvailable, reason, isKnown = true){
|
|
21
|
+
this.isAvailable = isAvailable;
|
|
22
|
+
this.reason = reason;
|
|
23
|
+
this.isKnown = isKnown;
|
|
24
|
+
}
|
|
25
|
+
/** Gets whether the part is not available for a reason other than a suspension. */ get isNotAvailable() {
|
|
26
|
+
return this.isKnown && !this.isAvailable && this.reason !== AvailabilityReason.Suspended;
|
|
27
|
+
}
|
|
28
|
+
/** Gets whether an operator has suspended the part. It comes back when the suspension is lifted. */ get isSuspended() {
|
|
29
|
+
return this.isKnown && !this.isAvailable && this.reason === AvailabilityReason.Suspended;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates the answer for a reason the server gave.
|
|
33
|
+
* @param reason The reason; a missing reason is `NotAvailable`.
|
|
34
|
+
* @returns The answer.
|
|
35
|
+
*/ static refused(reason) {
|
|
36
|
+
return new PartAvailability(false, reason ?? AvailabilityReason.NotAvailable);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.PartAvailability = PartAvailability;
|
|
41
|
+
//# sourceMappingURL=PartAvailability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PartAvailability.js","sources":["../../../availability/PartAvailability.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { NotAvailable, Suspended } from './AvailabilityReason.js';\n\n/**\n * The answer to whether one part is available, optionally for the data it is about.\n */\nexport class PartAvailability {\n /** The answer for a part that is available. */\n static readonly available: PartAvailability = new PartAvailability(true);\n\n /** The answer when the server has not told yet, or could not decide. Nothing is reported as available. */\n static readonly unknown: PartAvailability = new PartAvailability(false, undefined, false);\n\n /**\n * Initializes a new instance of {@link PartAvailability}.\n * @param isAvailable Whether the part is available.\n * @param reason Why it is not: `NotAvailable` or `Suspended`; undefined when it is available or not known.\n * @param isKnown Whether the server has decided.\n */\n constructor(readonly isAvailable: boolean, readonly reason?: string, readonly isKnown: boolean = true) {\n }\n\n /** Gets whether the part is not available for a reason other than a suspension. */\n get isNotAvailable(): boolean {\n return this.isKnown && !this.isAvailable && this.reason !== Suspended;\n }\n\n /** Gets whether an operator has suspended the part. It comes back when the suspension is lifted. */\n get isSuspended(): boolean {\n return this.isKnown && !this.isAvailable && this.reason === Suspended;\n }\n\n /**\n * Creates the answer for a reason the server gave.\n * @param reason The reason; a missing reason is `NotAvailable`.\n * @returns The answer.\n */\n static refused(reason?: string): PartAvailability {\n return new PartAvailability(false, reason ?? NotAvailable);\n }\n}\n"],"names":["PartAvailability","available","unknown","undefined","reason","isKnown","isAvailable","isNotAvailable","Suspended","isSuspended","refused","NotAvailable"],"mappings":";;;;AAAA;AACA;AAIA;;AAEC,IACM,MAAMA,gBAAAA,CAAAA;;;;AACT,oDACA,OAAgBC,SAAAA,GAA8B,IAAID,iBAAiB,IAAA,CAAA;AAEnE,+GACA,OAAgBE,OAAAA,GAA4B,IAAIF,gBAAAA,CAAiB,KAAA,EAAOG,WAAW,KAAA,CAAA;AAEnF;;;;;QAMA,WAAA,CAAY,WAA6B,EAAWC,MAAe,EAAWC,OAAAA,GAAmB,IAAI,CAAE;aAAlFC,WAAAA,GAAAA,WAAAA;aAA+BF,MAAAA,GAAAA,MAAAA;aAA0BC,OAAAA,GAAAA,OAAAA;AAC9E,IAAA;wFAGA,IAAIE,cAAAA,GAA0B;AAC1B,QAAA,OAAO,IAAI,CAACF,OAAO,IAAI,CAAC,IAAI,CAACC,WAAW,IAAI,IAAI,CAACF,MAAM,KAAKI,4BAAAA;AAChE,IAAA;yGAGA,IAAIC,WAAAA,GAAuB;AACvB,QAAA,OAAO,IAAI,CAACJ,OAAO,IAAI,CAAC,IAAI,CAACC,WAAW,IAAI,IAAI,CAACF,MAAM,KAAKI,4BAAAA;AAChE,IAAA;AAEA;;;;QAKA,OAAOE,OAAAA,CAAQN,MAAe,EAAoB;QAC9C,OAAO,IAAIJ,gBAAAA,CAAiB,KAAA,EAAOI,MAAAA,IAAUO,+BAAAA,CAAAA;AACjD,IAAA;AACJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnavailablePart.d.ts","sourceRoot":"","sources":["../../../availability/UnavailablePart.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAE5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAGxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAGzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"UnavailablePart.d.ts","sourceRoot":"","sources":["../../../availability/UnavailablePart.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAE5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAGxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAGzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAGvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC5B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AvailabilityPart } from './Availability.js';
|
|
2
|
+
import { AvailableParts } from './AvailableParts.js';
|
|
3
|
+
import { PartAvailability } from './PartAvailability.js';
|
|
4
|
+
export declare function answerFor(name: string, parts: AvailableParts): PartAvailability;
|
|
5
|
+
export declare function askAvailability(part: AvailabilityPart, args?: Record<string, unknown>): Promise<PartAvailability>;
|
|
6
|
+
//# sourceMappingURL=askAvailability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"askAvailability.d.ts","sourceRoot":"","sources":["../../../availability/askAvailability.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAc,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQzD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,gBAAgB,CAG/E;AAeD,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgCjH"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Availability = require('./Availability.js');
|
|
4
|
+
var ObserveAvailableParts = require('./ObserveAvailableParts.js');
|
|
5
|
+
var PartAvailability = require('./PartAvailability.js');
|
|
6
|
+
|
|
7
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
8
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
9
|
+
/**
|
|
10
|
+
* Describes the answer to a question about one part from the server's list of what is not available.
|
|
11
|
+
* @param name The full name of the part that was asked about.
|
|
12
|
+
* @param parts What the server listed.
|
|
13
|
+
* @returns The {@link PartAvailability}.
|
|
14
|
+
*/ function answerFor(name, parts) {
|
|
15
|
+
const listed = parts.unavailable.find((_)=>_.name === name);
|
|
16
|
+
return listed === undefined ? PartAvailability.PartAvailability.available : PartAvailability.PartAvailability.refused(listed.reason);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Asks the server whether a part is available for the data it is about, for example one vessel.
|
|
20
|
+
*
|
|
21
|
+
* The server decides with the same gate it uses when the command or query runs, reading `arguments.name` from the
|
|
22
|
+
* arguments given here, so the client never holds a rule of its own. It answers once; use `useIsAvailable` in React
|
|
23
|
+
* to keep the answer current.
|
|
24
|
+
* @param part The full name of a command or read model, or a generated proxy.
|
|
25
|
+
* @param args The arguments of the command or query, by property name. Arguments are for deciding availability only;
|
|
26
|
+
* they never grant anything.
|
|
27
|
+
* @returns The {@link PartAvailability}. When the server could not decide, the answer is {@link PartAvailability.unknown},
|
|
28
|
+
* which is not a denial and not a grant: ask again.
|
|
29
|
+
* @throws When the proxy does not carry the part it is. Generate the proxies again.
|
|
30
|
+
*/ function askAvailability(part, args) {
|
|
31
|
+
const name = Availability.partNameOf(part);
|
|
32
|
+
if (name === undefined) {
|
|
33
|
+
return Promise.reject(new Error('The proxy does not carry the part it is. Generate the proxies again with the current ProxyGenerator.'));
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve)=>{
|
|
36
|
+
const held = {};
|
|
37
|
+
let finished = false;
|
|
38
|
+
const finish = (answer)=>{
|
|
39
|
+
if (finished) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
finished = true;
|
|
43
|
+
held.subscription?.unsubscribe();
|
|
44
|
+
resolve(answer);
|
|
45
|
+
};
|
|
46
|
+
const query = new ObserveAvailableParts.ObserveAvailableParts();
|
|
47
|
+
held.subscription = query.subscribe((result)=>{
|
|
48
|
+
if (result.isSuccess && result.isAuthorized && result.data?.unavailable !== undefined) {
|
|
49
|
+
finish(answerFor(name, result.data));
|
|
50
|
+
} else if (!result.isSuccess) {
|
|
51
|
+
finish(PartAvailability.PartAvailability.unknown);
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
part: name,
|
|
55
|
+
arguments: JSON.stringify(args ?? {})
|
|
56
|
+
});
|
|
57
|
+
if (finished) {
|
|
58
|
+
held.subscription.unsubscribe();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.answerFor = answerFor;
|
|
64
|
+
exports.askAvailability = askAvailability;
|
|
65
|
+
//# sourceMappingURL=askAvailability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"askAvailability.js","sources":["../../../availability/askAvailability.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ObservableQuerySubscription } from '../queries/ObservableQuerySubscription.js';\nimport { AvailabilityPart, partNameOf } from './Availability.js';\nimport { AvailableParts } from './AvailableParts.js';\nimport { ObserveAvailableParts } from './ObserveAvailableParts.js';\nimport { PartAvailability } from './PartAvailability.js';\n\n/**\n * Describes the answer to a question about one part from the server's list of what is not available.\n * @param name The full name of the part that was asked about.\n * @param parts What the server listed.\n * @returns The {@link PartAvailability}.\n */\nexport function answerFor(name: string, parts: AvailableParts): PartAvailability {\n const listed = parts.unavailable.find(_ => _.name === name);\n return listed === undefined ? PartAvailability.available : PartAvailability.refused(listed.reason);\n}\n\n/**\n * Asks the server whether a part is available for the data it is about, for example one vessel.\n *\n * The server decides with the same gate it uses when the command or query runs, reading `arguments.name` from the\n * arguments given here, so the client never holds a rule of its own. It answers once; use `useIsAvailable` in React\n * to keep the answer current.\n * @param part The full name of a command or read model, or a generated proxy.\n * @param args The arguments of the command or query, by property name. Arguments are for deciding availability only;\n * they never grant anything.\n * @returns The {@link PartAvailability}. When the server could not decide, the answer is {@link PartAvailability.unknown},\n * which is not a denial and not a grant: ask again.\n * @throws When the proxy does not carry the part it is. Generate the proxies again.\n */\nexport function askAvailability(part: AvailabilityPart, args?: Record<string, unknown>): Promise<PartAvailability> {\n const name = partNameOf(part);\n if (name === undefined) {\n return Promise.reject(new Error('The proxy does not carry the part it is. Generate the proxies again with the current ProxyGenerator.'));\n }\n\n return new Promise<PartAvailability>(resolve => {\n const held: { subscription?: ObservableQuerySubscription<AvailableParts> } = {};\n let finished = false;\n const finish = (answer: PartAvailability) => {\n if (finished) {\n return;\n }\n\n finished = true;\n held.subscription?.unsubscribe();\n resolve(answer);\n };\n\n const query = new ObserveAvailableParts();\n held.subscription = query.subscribe(result => {\n if (result.isSuccess && result.isAuthorized && result.data?.unavailable !== undefined) {\n finish(answerFor(name, result.data));\n } else if (!result.isSuccess) {\n finish(PartAvailability.unknown);\n }\n }, { part: name, arguments: JSON.stringify(args ?? {}) });\n\n if (finished) {\n held.subscription.unsubscribe();\n }\n });\n}\n"],"names":["answerFor","name","parts","listed","unavailable","find","_","undefined","PartAvailability","available","refused","reason","askAvailability","part","args","partNameOf","Promise","reject","Error","resolve","held","finished","finish","answer","subscription","unsubscribe","query","ObserveAvailableParts","subscribe","result","isSuccess","isAuthorized","data","unknown","arguments","JSON","stringify"],"mappings":";;;;;;AAAA;AACA;AAQA;;;;;AAKC,IACM,SAASA,SAAAA,CAAUC,IAAY,EAAEC,KAAqB,EAAA;IACzD,MAAMC,MAAAA,GAASD,KAAAA,CAAME,WAAW,CAACC,IAAI,CAACC,CAAAA,CAAAA,GAAKA,CAAAA,CAAEL,IAAI,KAAKA,IAAAA,CAAAA;IACtD,OAAOE,MAAAA,KAAWI,YAAYC,iCAAAA,CAAiBC,SAAS,GAAGD,iCAAAA,CAAiBE,OAAO,CAACP,MAAAA,CAAOQ,MAAM,CAAA;AACrG;AAEA;;;;;;;;;;;;AAYC,IACM,SAASC,eAAAA,CAAgBC,IAAsB,EAAEC,IAA8B,EAAA;AAClF,IAAA,MAAMb,OAAOc,uBAAAA,CAAWF,IAAAA,CAAAA;AACxB,IAAA,IAAIZ,SAASM,SAAAA,EAAW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
|
|
1
1
|
export * from './AvailabilityReason.js';
|
|
2
2
|
export * from './isNotAvailable.js';
|
|
3
|
+
export * from './isSuspended.js';
|
|
3
4
|
export * from './UnavailablePart.js';
|
|
4
5
|
export * from './AvailableParts.js';
|
|
5
6
|
export * from './ObserveAvailableParts.js';
|
|
7
|
+
export * from './PartAvailability.js';
|
|
6
8
|
export * from './Availability.js';
|
|
9
|
+
export * from './askAvailability.js';
|
|
7
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../availability/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../availability/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -2,17 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
var AvailabilityReason = require('./AvailabilityReason.js');
|
|
4
4
|
var isNotAvailable = require('./isNotAvailable.js');
|
|
5
|
+
var isSuspended = require('./isSuspended.js');
|
|
5
6
|
var AvailableParts = require('./AvailableParts.js');
|
|
6
7
|
var ObserveAvailableParts = require('./ObserveAvailableParts.js');
|
|
8
|
+
var PartAvailability = require('./PartAvailability.js');
|
|
7
9
|
var Availability = require('./Availability.js');
|
|
10
|
+
var askAvailability = require('./askAvailability.js');
|
|
8
11
|
|
|
9
12
|
// Copyright (c) Cratis. All rights reserved.
|
|
10
13
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
11
14
|
|
|
12
15
|
exports.NotAvailable = AvailabilityReason.NotAvailable;
|
|
16
|
+
exports.Suspended = AvailabilityReason.Suspended;
|
|
13
17
|
exports.isNotAvailable = isNotAvailable.isNotAvailable;
|
|
18
|
+
exports.isSuspended = isSuspended.isSuspended;
|
|
14
19
|
exports.AvailableParts = AvailableParts.AvailableParts;
|
|
15
20
|
exports.UnavailablePartModel = AvailableParts.UnavailablePartModel;
|
|
16
21
|
exports.ObserveAvailableParts = ObserveAvailableParts.ObserveAvailableParts;
|
|
22
|
+
exports.PartAvailability = PartAvailability.PartAvailability;
|
|
17
23
|
exports.Availability = Availability.Availability;
|
|
24
|
+
exports.partNameOf = Availability.partNameOf;
|
|
25
|
+
exports.answerFor = askAvailability.answerFor;
|
|
26
|
+
exports.askAvailability = askAvailability.askAvailability;
|
|
18
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../availability/index.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport * from './AvailabilityReason.js';\nexport * from './isNotAvailable.js';\nexport * from './UnavailablePart.js';\nexport * from './AvailableParts.js';\nexport * from './ObserveAvailableParts.js';\nexport * from './Availability.js';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../availability/index.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport * from './AvailabilityReason.js';\nexport * from './isNotAvailable.js';\nexport * from './isSuspended.js';\nexport * from './UnavailablePart.js';\nexport * from './AvailableParts.js';\nexport * from './ObserveAvailableParts.js';\nexport * from './PartAvailability.js';\nexport * from './Availability.js';\nexport * from './askAvailability.js';\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSuspended.d.ts","sourceRoot":"","sources":["../../../availability/isSuspended.ts"],"names":[],"mappings":"AAWA,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,0BAA0B,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAE7H"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var AvailabilityReason = require('./AvailabilityReason.js');
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
6
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
7
|
+
/**
|
|
8
|
+
* Determines whether a command or query result was refused because an operator has suspended its part of the
|
|
9
|
+
* application. It is not the same as {@link isNotAvailable}: a suspended part comes back when the suspension is lifted.
|
|
10
|
+
* @param result The result of a command or a query.
|
|
11
|
+
* @returns True when the part is suspended.
|
|
12
|
+
*/ function isSuspended(result) {
|
|
13
|
+
return !result.isAuthorized && result.authorizationFailureReason === AvailabilityReason.Suspended;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.isSuspended = isSuspended;
|
|
17
|
+
//# sourceMappingURL=isSuspended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSuspended.js","sources":["../../../availability/isSuspended.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Suspended } from './AvailabilityReason.js';\n\n/**\n * Determines whether a command or query result was refused because an operator has suspended its part of the\n * application. It is not the same as {@link isNotAvailable}: a suspended part comes back when the suspension is lifted.\n * @param result The result of a command or a query.\n * @returns True when the part is suspended.\n */\nexport function isSuspended(result: { readonly isAuthorized: boolean; readonly authorizationFailureReason?: string }): boolean {\n return !result.isAuthorized && result.authorizationFailureReason === Suspended;\n}\n"],"names":["isSuspended","result","isAuthorized","authorizationFailureReason","Suspended"],"mappings":";;;;AAAA;AACA;AAIA;;;;;IAMO,SAASA,WAAAA,CAAYC,MAAwF,EAAA;AAChH,IAAA,OAAO,CAACA,MAAAA,CAAOC,YAAY,IAAID,MAAAA,CAAOE,0BAA0B,KAAKC,4BAAAA;AACzE;;"}
|
|
@@ -54,6 +54,8 @@ export declare class CommandResult<TResponse = object> implements ICommandResult
|
|
|
54
54
|
onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse>;
|
|
55
55
|
get isNotAvailable(): boolean;
|
|
56
56
|
onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse>;
|
|
57
|
+
get isSuspended(): boolean;
|
|
58
|
+
onSuspended(callback: OnNotAvailable): CommandResult<TResponse>;
|
|
57
59
|
onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse>;
|
|
58
60
|
private deserializeResponse;
|
|
59
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../../commands/CommandResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../../commands/CommandResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAGrE,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAKnE,KAAK,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,QAA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,IAAI,OAAO,CAE5B;IAOD,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAKjE;IAMD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAOD,WAAW,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAK9D;IAOD,mBAAmB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,aAAa,CAAC,SAAS,CAAC,CAK3E;IAED,OAAO,CAAC,mBAAmB;CAgB9B"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var fundamentals = require('@cratis/fundamentals');
|
|
4
4
|
var ValidationResult = require('../validation/ValidationResult.js');
|
|
5
5
|
var isNotAvailable = require('../availability/isNotAvailable.js');
|
|
6
|
+
var isSuspended = require('../availability/isSuspended.js');
|
|
6
7
|
|
|
7
8
|
// Copyright (c) Cratis. All rights reserved.
|
|
8
9
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -147,6 +148,22 @@ var isNotAvailable = require('../availability/isNotAvailable.js');
|
|
|
147
148
|
}
|
|
148
149
|
return this;
|
|
149
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Gets whether the command was refused because an operator has suspended its part of the application.
|
|
153
|
+
* It is not the same as {@link isNotAvailable}: a suspended part comes back when the suspension is lifted.
|
|
154
|
+
*/ get isSuspended() {
|
|
155
|
+
return isSuspended.isSuspended(this);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Set up a callback for when the command was refused because its part of the application is suspended.
|
|
159
|
+
* @param {OnNotAvailable} callback The callback to call when the part was suspended.
|
|
160
|
+
* @returns {CommandResult} The instance of the command result.
|
|
161
|
+
*/ onSuspended(callback) {
|
|
162
|
+
if (this.isSuspended) {
|
|
163
|
+
callback();
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
150
167
|
/**
|
|
151
168
|
* Set up a callback for when the command had validation errors.
|
|
152
169
|
* @param {OnSuccess} callback The callback to call when the command was invalid.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { isNotAvailable } from '../availability/isNotAvailable.js';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onNotAvailable callback.\n */\ntype OnNotAvailable = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n reason?: string;\n reasonDetail?: string;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n isRetryable?: boolean;\n errorCode?: string;\n isMissingHandler?: boolean;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state,\n reason: _.reason,\n reasonDetail: _.reasonDetail\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly isRetryable: boolean;\n\n /** @inheritdoc */\n readonly errorCode?: string;\n\n /** Whether no server handler was registered, so execution or validation did not run. */\n readonly isMissingHandler: boolean;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n // Older servers do not report retryable failures; none of their results are.\n this.isRetryable = result.isRetryable ?? false;\n this.errorCode = result.errorCode;\n\n // Older servers do not identify missing handlers.\n this.isMissingHandler = result.isMissingHandler ?? false;\n this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Gets whether the command was refused because its part of the application is not available to the caller.\n * This is not the same as being forbidden: the caller is not told whether it would have been allowed.\n */\n get isNotAvailable(): boolean {\n return isNotAvailable(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is not available.\n * @param {OnNotAvailable} callback The callback to call when the command was not available.\n * @returns {CommandResult} The instance of the command result.\n */\n onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isNotAvailable) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n\n private deserializeResponse(result: ServerCommandResult, responseInstanceType: Constructor, isResponseTypeEnumerable: boolean): TResponse | undefined {\n if (result.response === undefined || result.response === null) {\n return undefined;\n }\n const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;\n if (isResponseTypeEnumerable) {\n return (Array.isArray(result.response)\n ? (isPrimitive\n ? Array.from(result.response)\n : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))\n : []) as TResponse;\n }\n return (isPrimitive\n ? result.response\n : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;\n }\n}\n"],"names":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","reason","reasonDetail","isRetryable","errorCode","isMissingHandler","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","deserializeResponse","onSuccess","callback","onFailed","onException","onUnauthorized","isNotAvailable","onNotAvailable","onValidationFailure","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;AAAA;AACA;AAgEA;;AAEC,IACM,MAAMA,aAAAA,CAAAA;IAET,OAAOC,KAAA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"version":3,"file":"CommandResult.js","sources":["../../../commands/CommandResult.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Guid } from '@cratis/fundamentals';\nimport { ICommandResult } from './ICommandResult.js';\nimport { ValidationResult } from '../validation/ValidationResult.js';\nimport { isNotAvailable } from '../availability/isNotAvailable.js';\nimport { isSuspended } from '../availability/isSuspended.js';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\n\n/**\n * Delegate type for the onSuccess callback.\n */\ntype OnSuccess = (<TResponse>(response: TResponse) => void) | (() => void);\n\n/**\n * Delegate type for the onFailed callback.\n */\ntype OnFailed<TResponse> = ((commandResult: CommandResult<TResponse>) => void) | (() => void);\n\n/**\n * Delegate type for the onException callback.\n */\ntype OnException = (messages: string[], stackTrace: string) => void;\n\n/**\n * Delegate type for the onUnauthorized callback.\n */\ntype OnUnauthorized = () => void;\n\n/**\n * Delegate type for the onNotAvailable callback.\n */\ntype OnNotAvailable = () => void;\n\n/**\n * Delegate type for the onValidationFailure callback.\n */\ntype OnValidationFailure = (validationResults: ValidationResult[]) => void;\n\ntype ServerCommandResult = {\n correlationId: string;\n isSuccess: boolean;\n isAuthorized: boolean;\n isValid: boolean;\n hasExceptions: boolean;\n validationResults: {\n severity: number;\n message: string;\n members: string[];\n state: object;\n reason?: string;\n reasonDetail?: string;\n }[];\n exceptionMessages: string[];\n exceptionStackTrace: string;\n authorizationFailureReason: string;\n isRetryable?: boolean;\n errorCode?: string;\n isMissingHandler?: boolean;\n\n /* eslint-disable @typescript-eslint/no-explicit-any */\n response: any;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n/**\n * Represents the result from executing a {@link ICommand}.\n */\nexport class CommandResult<TResponse = object> implements ICommandResult<TResponse> {\n\n static empty: CommandResult = new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: true,\n isAuthorized: true,\n isValid: true,\n hasExceptions: false,\n validationResults: [],\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n\n static failed = (exceptionMessages: string[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: true,\n hasExceptions: true,\n validationResults: [],\n exceptionMessages: exceptionMessages,\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n static validationFailed = (validationResults: ValidationResult[]): CommandResult => {\n return new CommandResult({\n correlationId: Guid.empty.toString(),\n isSuccess: false,\n isAuthorized: true,\n isValid: false,\n hasExceptions: false,\n validationResults: validationResults.map(_ => ({\n severity: _.severity,\n message: _.message,\n members: _.members,\n state: _.state,\n reason: _.reason,\n reasonDetail: _.reasonDetail\n })),\n exceptionMessages: [],\n exceptionStackTrace: '',\n authorizationFailureReason: '',\n response: null\n }, Object, false);\n };\n\n /** @inheritdoc */\n readonly correlationId: Guid;\n\n /** @inheritdoc */\n readonly isSuccess: boolean;\n\n /** @inheritdoc */\n readonly isAuthorized: boolean;\n\n /** @inheritdoc */\n readonly isValid: boolean;\n\n /** @inheritdoc */\n readonly hasExceptions: boolean;\n\n /** @inheritdoc */\n readonly validationResults: ValidationResult[];\n\n /** @inheritdoc */\n readonly exceptionMessages: string[];\n\n /** @inheritdoc */\n readonly exceptionStackTrace: string;\n\n /** @inheritdoc */\n readonly authorizationFailureReason: string;\n\n /** @inheritdoc */\n readonly isRetryable: boolean;\n\n /** @inheritdoc */\n readonly errorCode?: string;\n\n /** Whether no server handler was registered, so execution or validation did not run. */\n readonly isMissingHandler: boolean;\n\n /** @inheritdoc */\n readonly response?: TResponse;\n\n /**\n * Creates an instance of command result.\n * @param {*} result The JSON/any representation of the command result;\n * @param {Constructor} responseInstanceType The {@see Constructor} that represents the type of response, if any. Defaults to {@see Object}.\n * @param {boolean} isResponseTypeEnumerable Whether or not the response type is an enumerable or not.\n */\n constructor(result: ServerCommandResult, responseInstanceType: Constructor = Object, isResponseTypeEnumerable: boolean) {\n this.correlationId = Guid.parse(result.correlationId);\n this.isSuccess = result.isSuccess;\n this.isAuthorized = result.isAuthorized;\n this.isValid = result.isValid;\n this.hasExceptions = result.hasExceptions;\n this.validationResults = result.validationResults.map(_ => new ValidationResult(_.severity, _.message, _.members, _.state, _.reason, _.reasonDetail));\n this.exceptionMessages = result.exceptionMessages;\n this.exceptionStackTrace = result.exceptionStackTrace;\n this.authorizationFailureReason = result.authorizationFailureReason;\n // Older servers do not report retryable failures; none of their results are.\n this.isRetryable = result.isRetryable ?? false;\n this.errorCode = result.errorCode;\n\n // Older servers do not identify missing handlers.\n this.isMissingHandler = result.isMissingHandler ?? false;\n this.response = this.deserializeResponse(result, responseInstanceType, isResponseTypeEnumerable);\n }\n\n /**\n * Set up a callback for when the command was successful.\n * @param {OnSuccess} callback The callback to call when the command was successful.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuccess(callback: OnSuccess): CommandResult<TResponse> {\n if (this.isSuccess) {\n callback(this.response as TResponse);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed.\n * @param {OnFailed} callback The callback to call when the command failed.\n * @returns {CommandResult} The instance of the command result.\n */\n onFailed(callback: OnFailed<TResponse>): CommandResult<TResponse> {\n if (!this.isSuccess) {\n callback(this);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command failed with an exception.\n * @param {OnException} callback The callback to call when the command had an exception.\n * @returns {CommandResult} The instance of the command result.\n */\n onException(callback: OnException): CommandResult<TResponse> {\n if (this.hasExceptions) {\n callback(this.exceptionMessages, this.exceptionStackTrace);\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command was unauthorized.\n * @param {OnUnauthorized} callback The callback to call when the command was unauthorized.\n * @returns {CommandResult} The instance of the command result.\n */\n onUnauthorized(callback: OnUnauthorized): CommandResult<TResponse> {\n if (!this.isAuthorized) {\n callback();\n }\n return this;\n }\n\n /**\n * Gets whether the command was refused because its part of the application is not available to the caller.\n * This is not the same as being forbidden: the caller is not told whether it would have been allowed.\n */\n get isNotAvailable(): boolean {\n return isNotAvailable(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is not available.\n * @param {OnNotAvailable} callback The callback to call when the command was not available.\n * @returns {CommandResult} The instance of the command result.\n */\n onNotAvailable(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isNotAvailable) {\n callback();\n }\n return this;\n }\n\n /**\n * Gets whether the command was refused because an operator has suspended its part of the application.\n * It is not the same as {@link isNotAvailable}: a suspended part comes back when the suspension is lifted.\n */\n get isSuspended(): boolean {\n return isSuspended(this);\n }\n\n /**\n * Set up a callback for when the command was refused because its part of the application is suspended.\n * @param {OnNotAvailable} callback The callback to call when the part was suspended.\n * @returns {CommandResult} The instance of the command result.\n */\n onSuspended(callback: OnNotAvailable): CommandResult<TResponse> {\n if (this.isSuspended) {\n callback();\n }\n return this;\n }\n\n /**\n * Set up a callback for when the command had validation errors.\n * @param {OnSuccess} callback The callback to call when the command was invalid.\n * @returns {CommandResult} The instance of the command result.\n */\n onValidationFailure(callback: OnValidationFailure): CommandResult<TResponse> {\n if (!this.isValid) {\n callback(this.validationResults);\n }\n return this;\n }\n\n private deserializeResponse(result: ServerCommandResult, responseInstanceType: Constructor, isResponseTypeEnumerable: boolean): TResponse | undefined {\n if (result.response === undefined || result.response === null) {\n return undefined;\n }\n const isPrimitive = responseInstanceType === String || responseInstanceType === Number || responseInstanceType === Boolean;\n if (isResponseTypeEnumerable) {\n return (Array.isArray(result.response)\n ? (isPrimitive\n ? Array.from(result.response)\n : JsonSerializer.deserializeArrayFromInstance(responseInstanceType, result.response))\n : []) as TResponse;\n }\n return (isPrimitive\n ? result.response\n : JsonSerializer.deserializeFromInstance(responseInstanceType, result.response)) as TResponse;\n }\n}\n"],"names":["CommandResult","empty","correlationId","Guid","toString","isSuccess","isAuthorized","isValid","hasExceptions","validationResults","exceptionMessages","exceptionStackTrace","authorizationFailureReason","response","Object","failed","validationFailed","map","_","severity","message","members","state","reason","reasonDetail","isRetryable","errorCode","isMissingHandler","result","responseInstanceType","isResponseTypeEnumerable","parse","ValidationResult","deserializeResponse","onSuccess","callback","onFailed","onException","onUnauthorized","isNotAvailable","onNotAvailable","isSuspended","onSuspended","onValidationFailure","undefined","isPrimitive","String","Number","Boolean","Array","isArray","from","JsonSerializer","deserializeArrayFromInstance","deserializeFromInstance"],"mappings":";;;;;;;AAAA;AACA;AAiEA;;AAEC,IACM,MAAMA,aAAAA,CAAAA;IAET,OAAOC,KAAAA,GAAuB,IAAID,aAAAA,CAAc;QAC5CE,aAAAA,EAAeC,iBAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;QAClCC,SAAAA,EAAW,IAAA;QACXC,YAAAA,EAAc,IAAA;QACdC,OAAAA,EAAS,IAAA;QACTC,aAAAA,EAAe,KAAA;AACfC,QAAAA,iBAAAA,EAAmB,EAAE;AACrBC,QAAAA,iBAAAA,EAAmB,EAAE;QACrBC,mBAAAA,EAAqB,EAAA;QACrBC,0BAAAA,EAA4B,EAAA;QAC5BC,QAAAA,EAAU;AACd,KAAA,EAAGC,QAAQ,KAAA,CAAA;AAEX,IAAA,OAAOC,SAAS,CAACL,iBAAAA,GAAAA;AACb,QAAA,OAAO,IAAIV,aAAAA,CAAc;YACrBE,aAAAA,EAAeC,iBAAAA,CAAKF,KAAK,CAACG,QAAQ,EAAA;YAClCC,SAAAA,EAAW,KAAA;YACXC,YAAAA,EAAc,IAAA;YACdC,OAAAA,EAAS,IAAA;YACTC,aAAAA,EAAe,IAAA;AACfC,YAAAA,iBAAAA,EAAmB,EAAE;YACrBC,iBAAAA,EAAmBA,iBAAAA;YACnBC,mBAAAA,EAAqB,EAAA;YACrBC,0BAAAA,EAA4B,EAAA;YAC5BC,QAAAA,EAAU;AACd,SAAA,EAAGC,MAAAA,EAAQ,KAAA,CAAA;IACf,CAAA;AAEA,IAAA,OAAOE,mBAAmB,CAACP,iBAAAA,GAAAA;AACvB,QAAA,OAAO,IAAIT,aAAAA,CAAc;YACrBE,aAAAA,EA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