@konitif/workbench 0.285.7 → 0.285.8
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/dist/application/experience/experienceLifecycle.d.ts +1 -0
- package/dist/application/experience/experienceLifecycle.js +5 -1
- package/dist/application/experience/experienceRepository.d.ts +1 -0
- package/dist/infrastructure/persistence/BrowserExperienceRepository.d.ts +5 -2
- package/dist/infrastructure/persistence/BrowserExperienceRepository.js +21 -1
- package/package.json +1 -1
|
@@ -60,4 +60,5 @@ export declare function transitionWorkbenchExperienceLifecycle<TMetadata>(input:
|
|
|
60
60
|
experience: WorkbenchExperience<TMetadata>;
|
|
61
61
|
expected: Exclude<ExperienceLifecycleStatus, 'tombstoned'>;
|
|
62
62
|
next: ExperienceLifecycleStatus;
|
|
63
|
+
metadata?: TMetadata;
|
|
63
64
|
}): ExperienceLifecycleResult<WorkbenchExperience<TMetadata>>;
|
|
@@ -83,7 +83,11 @@ export function transitionWorkbenchExperienceLifecycle(input) {
|
|
|
83
83
|
if (!isAllowedTransition(input.experience.lifecycle, input.next)) {
|
|
84
84
|
return refused('experience.lifecycle.status-conflict', '$.next', `Experience lifecycle cannot transition from ${input.experience.lifecycle} to ${input.next}.`, undefined, input.next);
|
|
85
85
|
}
|
|
86
|
-
return accepted({
|
|
86
|
+
return accepted({
|
|
87
|
+
...input.experience,
|
|
88
|
+
lifecycle: input.next,
|
|
89
|
+
metadata: input.metadata ?? input.experience.metadata,
|
|
90
|
+
});
|
|
87
91
|
}
|
|
88
92
|
function isAllowedTransition(current, next) {
|
|
89
93
|
return next === 'tombstoned'
|
|
@@ -38,5 +38,6 @@ export interface WorkbenchExperienceRepository<TMetadata = unknown, TSpecializat
|
|
|
38
38
|
experienceId: ExperienceIdentity;
|
|
39
39
|
expected: Exclude<ExperienceLifecycleStatus, 'tombstoned'>;
|
|
40
40
|
next: ExperienceLifecycleStatus;
|
|
41
|
+
metadata?: TMetadata;
|
|
41
42
|
}): Promise<WorkbenchExperienceRepositoryResult<WorkbenchExperience<TMetadata>>>;
|
|
42
43
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { WorkbenchExperienceRepository } from "../../application/experience/experienceRepository.js";
|
|
1
|
+
import type { WorkbenchExperienceRepository, WorkbenchExperienceRepositoryResult, WorkbenchExperienceRepositorySnapshot } from "../../application/experience/experienceRepository.js";
|
|
2
2
|
export interface BrowserExperienceRepositoryStorage {
|
|
3
3
|
getItem(key: string): string | null;
|
|
4
4
|
setItem(key: string, value: string): void;
|
|
5
5
|
}
|
|
6
|
+
export interface BrowserWorkbenchExperienceRepository<TMetadata = unknown, TSpecialization = unknown> extends WorkbenchExperienceRepository<TMetadata, TSpecialization> {
|
|
7
|
+
initialize(snapshot: WorkbenchExperienceRepositorySnapshot<TMetadata, TSpecialization>): Promise<WorkbenchExperienceRepositoryResult<WorkbenchExperienceRepositorySnapshot<TMetadata, TSpecialization>>>;
|
|
8
|
+
}
|
|
6
9
|
/**
|
|
7
10
|
* Browser persistence adapter for the generic Workbench Experience authority.
|
|
8
11
|
* Products choose the storage key and keep migration and specialization policy
|
|
@@ -11,4 +14,4 @@ export interface BrowserExperienceRepositoryStorage {
|
|
|
11
14
|
export declare function createBrowserWorkbenchExperienceRepository<TMetadata = unknown, TSpecialization = unknown>(input: {
|
|
12
15
|
storageKey: string;
|
|
13
16
|
storage?: BrowserExperienceRepositoryStorage | null;
|
|
14
|
-
}):
|
|
17
|
+
}): BrowserWorkbenchExperienceRepository<TMetadata, TSpecialization>;
|
|
@@ -10,6 +10,18 @@ export function createBrowserWorkbenchExperienceRepository(input) {
|
|
|
10
10
|
const storageKey = requireStorageKey(input.storageKey);
|
|
11
11
|
return {
|
|
12
12
|
hydrate: () => hydrate(storage, storageKey),
|
|
13
|
+
async initialize(snapshot) {
|
|
14
|
+
const current = await hydrate(storage, storageKey);
|
|
15
|
+
if (!current.ok)
|
|
16
|
+
return current;
|
|
17
|
+
if (current.value.experiences.length > 0 || current.value.revisions.length > 0) {
|
|
18
|
+
return refused('experience.repository.already-exists', 'Browser Experience repository is already initialized.');
|
|
19
|
+
}
|
|
20
|
+
if (!isRepositorySnapshot(snapshot)) {
|
|
21
|
+
return refused('experience.repository.invalid-artifact', 'Initial Experience snapshot does not match the Workbench contract.');
|
|
22
|
+
}
|
|
23
|
+
return persist(storage, storageKey, snapshot);
|
|
24
|
+
},
|
|
13
25
|
async list() {
|
|
14
26
|
const snapshot = await hydrate(storage, storageKey);
|
|
15
27
|
return snapshot.ok ? accepted(snapshot.value.experiences) : snapshot;
|
|
@@ -78,6 +90,7 @@ export function createBrowserWorkbenchExperienceRepository(input) {
|
|
|
78
90
|
experience,
|
|
79
91
|
expected: value.expected,
|
|
80
92
|
next: value.next,
|
|
93
|
+
metadata: value.metadata,
|
|
81
94
|
});
|
|
82
95
|
if (!transitioned.ok)
|
|
83
96
|
return lifecycleRefused(transitioned.diagnostics[0]);
|
|
@@ -141,6 +154,11 @@ function isStoredRepository(value) {
|
|
|
141
154
|
|| !Array.isArray(value.experiences)
|
|
142
155
|
|| !Array.isArray(value.revisions))
|
|
143
156
|
return false;
|
|
157
|
+
return isRepositorySnapshot(value);
|
|
158
|
+
}
|
|
159
|
+
function isRepositorySnapshot(value) {
|
|
160
|
+
if (!isRecord(value) || !Array.isArray(value.experiences) || !Array.isArray(value.revisions))
|
|
161
|
+
return false;
|
|
144
162
|
const experiences = value.experiences;
|
|
145
163
|
const revisions = value.revisions;
|
|
146
164
|
if (!experiences.every(isWorkbenchExperience) || !revisions.every(isWorkbenchExperienceRevision))
|
|
@@ -149,7 +167,9 @@ function isStoredRepository(value) {
|
|
|
149
167
|
&& isIdentity(revision.experienceId, 'experience')
|
|
150
168
|
&& isIdentity(revision.id, 'experience-revision')
|
|
151
169
|
&& revision.experienceId.value === experience.id.value
|
|
152
|
-
&& revision.id.value === experience.headRevisionId.value))
|
|
170
|
+
&& revision.id.value === experience.headRevisionId.value)) && revisions.every(revision => experiences.some(experience => isRecord(revision)
|
|
171
|
+
&& isIdentity(revision.experienceId, 'experience')
|
|
172
|
+
&& revision.experienceId.value === experience.id.value));
|
|
153
173
|
}
|
|
154
174
|
function isWorkbenchExperience(value) {
|
|
155
175
|
return isRecord(value)
|
package/package.json
CHANGED