@ahoo-wang/wow-view-store 9.8.0 → 10.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -137
- package/README.zh-CN.md +89 -100
- package/dist/datasetWordings.d.ts +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +188 -257
- package/dist/index.es.js.map +1 -1
- package/dist/paths.d.ts +2 -0
- package/dist/remembered.d.ts +9 -0
- package/dist/remembered.es.js +147 -0
- package/dist/remembered.es.js.map +1 -0
- package/dist/v10/datasetWordings.d.ts +46 -0
- package/dist/v10/errors.d.ts +83 -0
- package/dist/v10/generated/index.d.ts +1 -0
- package/dist/v10/generated/view-store/boundedContext.d.ts +36 -0
- package/dist/v10/generated/view-store/dataset_wording/aggregate.d.ts +17 -0
- package/dist/v10/generated/view-store/dataset_wording/commandClient.d.ts +32 -0
- package/dist/v10/generated/view-store/dataset_wording/index.d.ts +3 -0
- package/dist/v10/generated/view-store/dataset_wording/queryClient.d.ts +18 -0
- package/dist/v10/generated/view-store/index.d.ts +5 -0
- package/dist/v10/generated/view-store/types.d.ts +167 -0
- package/dist/v10/generated/view-store/view/aggregate.d.ts +17 -0
- package/dist/v10/generated/view-store/view/commandClient.d.ts +65 -0
- package/dist/v10/generated/view-store/view/index.d.ts +3 -0
- package/dist/v10/generated/view-store/view/queryClient.d.ts +18 -0
- package/dist/v10/generated/view-store/view_preferences/aggregate.d.ts +17 -0
- package/dist/v10/generated/view-store/view_preferences/commandClient.d.ts +22 -0
- package/dist/v10/generated/view-store/view_preferences/index.d.ts +3 -0
- package/dist/v10/generated/view-store/view_preferences/queryClient.d.ts +18 -0
- package/dist/v10/index.d.ts +6 -0
- package/dist/v10/source.d.ts +46 -0
- package/dist/v10/systemViews.d.ts +21 -0
- package/dist/v10/wire.d.ts +25 -0
- package/dist/v10/wowViewStore.d.ts +179 -0
- package/dist/v10.es.js +673 -0
- package/dist/v10.es.js.map +1 -0
- package/dist/wowViewStore.d.ts +13 -0
- package/package.json +12 -6
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TargetScope } from '@ahoo-wang/wow-client/v10';
|
|
2
|
+
import { DatasetOverrides, ViewInstance, ViewInstanceSummary } from '@ahoo-wang/wow-view-engine';
|
|
3
|
+
import { Place } from '../paths.js';
|
|
4
|
+
import { DatasetWordingState, ViewState } from './generated/view-store/types.js';
|
|
5
|
+
/** The `Wow-Scope` of the shared views: the reserved owner `(shared)`. */
|
|
6
|
+
export declare const SHARED_SCOPE: TargetScope;
|
|
7
|
+
/** The `Wow-Scope` of the stored system views: `(system)` of `(platform)`. */
|
|
8
|
+
export declare const SYSTEM_SCOPE: TargetScope;
|
|
9
|
+
/**
|
|
10
|
+
* The `Wow-Scope` a request at `place` carries: none for the caller's own
|
|
11
|
+
* views, whose owner the server takes from the principal.
|
|
12
|
+
*/
|
|
13
|
+
export declare function scopeAt(place: Place): TargetScope | undefined;
|
|
14
|
+
/** A view's snapshot or state as the store reads it: its id, version and state. */
|
|
15
|
+
export interface ViewRecord {
|
|
16
|
+
id: string;
|
|
17
|
+
version: number;
|
|
18
|
+
state: Pick<ViewState, 'definitionId' | 'title' | 'audience'> & Partial<Pick<ViewState, 'kind' | 'config'>>;
|
|
19
|
+
}
|
|
20
|
+
/** The fields a list reads, and of the config only its `kind`, kept apart. */
|
|
21
|
+
export declare const SUMMARY_FIELDS: readonly ["aggregateId", "version", "state.definitionId", "state.title", "state.audience", "state.kind"];
|
|
22
|
+
export declare function toInstance({ id, version, state }: ViewRecord): ViewInstance;
|
|
23
|
+
export declare function toSummary({ id, version, state, }: ViewRecord): ViewInstanceSummary;
|
|
24
|
+
/** The engine's overrides from a stored wording: what is stored, nothing more. */
|
|
25
|
+
export declare function wordingOf(state: Pick<DatasetWordingState, 'title' | 'recordNoun' | 'fields'>): DatasetOverrides;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
2
|
+
import { ViewAudience, ViewConfig, ViewInstance, ViewInstanceSummary, ViewPermissions, ViewPreferences, ViewStore, WriteContext } from '@ahoo-wang/wow-view-engine';
|
|
3
|
+
/** How a V10 {@link WowViewStore} reaches the view store service. */
|
|
4
|
+
export interface WowViewStoreOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The fetcher every request goes through, on the base URL that serves
|
|
7
|
+
* `/view-store/…` (the V10 view store service, or a gateway in front of
|
|
8
|
+
* it).
|
|
9
|
+
*
|
|
10
|
+
* Its interceptors carry who is asking; the store never does. The V10
|
|
11
|
+
* service takes the tenant and the owner from the principal, so no path
|
|
12
|
+
* names them: the interceptors send the authorization (CoSec's token, or
|
|
13
|
+
* the headers the service's own caller resolver reads) and `CoSec-App-Id`,
|
|
14
|
+
* the application every view, preference and wording is kept in. The
|
|
15
|
+
* store adds `Wow-Scope` itself where it acts as a reserved owner: the
|
|
16
|
+
* shared views' `(shared)`, and `(system)` of `(platform)` for stored
|
|
17
|
+
* system views.
|
|
18
|
+
*/
|
|
19
|
+
fetcher: Fetcher;
|
|
20
|
+
/**
|
|
21
|
+
* Which buttons are enabled for one definition's views. The service
|
|
22
|
+
* authorizes each write; a host answers this by the roles it holds there —
|
|
23
|
+
* `changeAudience` and the shared views' writes by the role that writes
|
|
24
|
+
* the owner `(shared)` (`view-store.shared-writer` on the service as
|
|
25
|
+
* shipped), `editSystem` by the one that writes `(system)`. Left out,
|
|
26
|
+
* everything is allowed, as the port reads a store without `permissions`.
|
|
27
|
+
*/
|
|
28
|
+
permissions?: (definitionId: string) => ViewPermissions;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The view engine's `ViewStore` over the **V10** view store service
|
|
32
|
+
* (`platform/view-store` in the Wow repository): saved views and preferences
|
|
33
|
+
* as two Wow V10 aggregates, reached through the clients generated from the
|
|
34
|
+
* service's Manifest (`@ahoo-wang/wow-client/v10`), and the system views
|
|
35
|
+
* through the service's own route.
|
|
36
|
+
*
|
|
37
|
+
* **The owner is the audience.** A personal view is the caller's own; a
|
|
38
|
+
* shared one belongs to the reserved owner `(shared)`, which the store acts
|
|
39
|
+
* as with `Wow-Scope: owner="(shared)"`; a stored system view to `(system)`
|
|
40
|
+
* of the tenant `(platform)`. The port names a view by id alone, so the
|
|
41
|
+
* store remembers where it last saw each one and looks an unknown id up as
|
|
42
|
+
* the caller, as `(shared)` and among the system views, in that order.
|
|
43
|
+
* Sharing and claiming move a view to the other owner in place, id kept:
|
|
44
|
+
* the store waits for the service's `ViewAudienceSaga` to move it.
|
|
45
|
+
*
|
|
46
|
+
* **Writes** carry the port's `requestId` as `Wow-Request-Id` and its
|
|
47
|
+
* `revision` as `If-Match`, and wait for the snapshot. The service
|
|
48
|
+
* deduplicates a request id, creates included, so a retry is answered with
|
|
49
|
+
* the first attempt's outcome; the store answers the view read back at the
|
|
50
|
+
* version that write left (`GET …/{id}/state?version=`). A stale revision
|
|
51
|
+
* is `CONFLICT` carrying the view as it is now.
|
|
52
|
+
*
|
|
53
|
+
* **Errors** are read by the problem's code onto the port's codes, by the
|
|
54
|
+
* HTTP status only for an answer without a code the store knows; a `404`
|
|
55
|
+
* without a code is a route the service does not serve (`UNSUPPORTED`), and
|
|
56
|
+
* a request that got no answer is `UNAVAILABLE`.
|
|
57
|
+
*/
|
|
58
|
+
export declare class WowViewStore implements ViewStore {
|
|
59
|
+
/**
|
|
60
|
+
* The most of one audience a list answers (`LIST_LIMIT`): an audience
|
|
61
|
+
* listed this full was cut there, which the workbench then says (R2-26).
|
|
62
|
+
*/
|
|
63
|
+
readonly listLimit = 1000;
|
|
64
|
+
/** The host's {@link WowViewStoreOptions.permissions}, when it gave any. */
|
|
65
|
+
readonly permissions?: (definitionId: string) => ViewPermissions;
|
|
66
|
+
private readonly commands;
|
|
67
|
+
private readonly snapshots;
|
|
68
|
+
private readonly states;
|
|
69
|
+
private readonly preferenceCommands;
|
|
70
|
+
private readonly preferenceSnapshots;
|
|
71
|
+
private readonly systemViews;
|
|
72
|
+
/** Where each view was last seen, by id. */
|
|
73
|
+
private readonly places;
|
|
74
|
+
/**
|
|
75
|
+
* The version of each stored system view at each revision the store has
|
|
76
|
+
* seen it at (a hash of its content, while a write expects the version),
|
|
77
|
+
* by `id` and revision; `null` for a configured one, which is read-only.
|
|
78
|
+
* Keeping the old revisions too lets a retry send the version its first
|
|
79
|
+
* attempt expected, which the service then answers as a duplicate.
|
|
80
|
+
*/
|
|
81
|
+
private readonly systemVersions;
|
|
82
|
+
constructor(options: WowViewStoreOptions);
|
|
83
|
+
/**
|
|
84
|
+
* The caller's personal views, the shared views and the service's system
|
|
85
|
+
* views of the definition: three requests, sent together, answered in the
|
|
86
|
+
* port's order — system, shared, personal, each oldest first (the service
|
|
87
|
+
* sorts each audience by the time its first event was written).
|
|
88
|
+
*/
|
|
89
|
+
list(definitionId: string, signal?: AbortSignal): Promise<ViewInstanceSummary[]>;
|
|
90
|
+
/** View `id` wherever it is: the caller's, shared, or a system view. */
|
|
91
|
+
get(id: string, signal?: AbortSignal): Promise<ViewInstance>;
|
|
92
|
+
/**
|
|
93
|
+
* Creates the view as the owner of its `scope`; the service generates the
|
|
94
|
+
* id. A retry under the same request id is answered with the first
|
|
95
|
+
* attempt's view, whichever store sends it: the service deduplicates it.
|
|
96
|
+
*/
|
|
97
|
+
create(input: Omit<ViewInstance, 'id' | 'revision'>, context: WriteContext): Promise<ViewInstance>;
|
|
98
|
+
/** Replaces the view's config, at the expected `revision`. */
|
|
99
|
+
save(id: string, config: ViewConfig, revision: string, context: WriteContext): Promise<ViewInstance>;
|
|
100
|
+
/** Renames the view (the service trims the title), at the expected `revision`. */
|
|
101
|
+
rename(id: string, title: string, revision: string, context: WriteContext): Promise<ViewInstance>;
|
|
102
|
+
/**
|
|
103
|
+
* 设为共享 sends `share-view` as the caller, the view's owner; 设为个人
|
|
104
|
+
* sends `claim-view` as `(shared)`, which the service admits only with
|
|
105
|
+
* the role that writes the owner `(shared)`, and which makes the caller
|
|
106
|
+
* the owner. Either waits for the move (`ViewAudienceSaga`). Each is sent
|
|
107
|
+
* from the same owner whether or not the view has moved, so a retry is
|
|
108
|
+
* answered as its first attempt's duplicate even after the move.
|
|
109
|
+
*
|
|
110
|
+
* Asked for the audience the view already has, the service refuses the
|
|
111
|
+
* command as outside that owner's scope; the store then answers the view
|
|
112
|
+
* as it is, revision unmoved, once the revision matches.
|
|
113
|
+
*
|
|
114
|
+
* A shared view a shared dashboard shows stays shared: the service
|
|
115
|
+
* refuses the claim and names the boards, and the refusal carries them by
|
|
116
|
+
* **title** in `boards`, as they are stored.
|
|
117
|
+
*/
|
|
118
|
+
changeAudience(id: string, audience: ViewAudience, revision: string, context: WriteContext): Promise<ViewInstance>;
|
|
119
|
+
/** Deletes the view, at the expected `revision`; a board showing it keeps a broken panel. */
|
|
120
|
+
delete(id: string, revision: string, context: WriteContext): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* The caller's preferences of the definition, in the request's
|
|
123
|
+
* application: the service derives their id from the owner, the
|
|
124
|
+
* application and the definition. None written yet reads as the port's
|
|
125
|
+
* empty preferences, at revision `'0'`.
|
|
126
|
+
*/
|
|
127
|
+
getPreferences(definitionId: string, signal?: AbortSignal): Promise<ViewPreferences>;
|
|
128
|
+
/**
|
|
129
|
+
* Writes the preferences at the expected `revision` (`'0'` for ones never
|
|
130
|
+
* written, which `If-Match: "0"` says). A retry under the same request id
|
|
131
|
+
* is answered as the first attempt's duplicate, at its version.
|
|
132
|
+
*/
|
|
133
|
+
setPreferences(definitionId: string, preferences: ViewPreferences, context: WriteContext): Promise<ViewPreferences>;
|
|
134
|
+
/**
|
|
135
|
+
* One instance write: to the place the view is at, then the answer read
|
|
136
|
+
* back. A view remembered at a place it has since left (another tab shared
|
|
137
|
+
* it) is looked up again and the write sent once more from where it is.
|
|
138
|
+
* A move refused because the view already has the audience it asks for
|
|
139
|
+
* changes nothing: the view is answered as it is, once its revision
|
|
140
|
+
* matches.
|
|
141
|
+
*/
|
|
142
|
+
private write;
|
|
143
|
+
/**
|
|
144
|
+
* A landed write's answer: the view read back at the version it left
|
|
145
|
+
* (`GET …/{id}/state?version=`). A system view's revision is its content
|
|
146
|
+
* hash, so it is read from its route as it is now.
|
|
147
|
+
*
|
|
148
|
+
* A move is two commits: the view's own (its audience), then the saga's
|
|
149
|
+
* (its owner). Waited for, the result's version is the second; a
|
|
150
|
+
* duplicate answers the first, so the move is read one version later,
|
|
151
|
+
* where the owner it names must be the one it moved to. Anything else
|
|
152
|
+
* (another writer between the two) answers the view as it is now.
|
|
153
|
+
*/
|
|
154
|
+
private landed;
|
|
155
|
+
/** A move to where the view already is: the view as it is, at `revision`. */
|
|
156
|
+
private unchanged;
|
|
157
|
+
/** A stale write's refusal, carrying the view as it is now. */
|
|
158
|
+
private conflict;
|
|
159
|
+
/**
|
|
160
|
+
* View `id` and where it is: first where it was last seen (`first`, `null`
|
|
161
|
+
* to ignore that), then as the caller, as `(shared)` and among the system
|
|
162
|
+
* views.
|
|
163
|
+
*/
|
|
164
|
+
private find;
|
|
165
|
+
/** The view as it is now at `place`; a `NOT_FOUND` failure when it is not there. */
|
|
166
|
+
private readAt;
|
|
167
|
+
/** Keeps the version of a stored system view at its revision; a configured one as read-only. */
|
|
168
|
+
private rememberSystem;
|
|
169
|
+
/**
|
|
170
|
+
* The version a write of stored system view `id` at `revision` (its
|
|
171
|
+
* content hash) expects: as seen at that revision, else as read now. A
|
|
172
|
+
* configured system view is read-only (`FORBIDDEN`; a code one is never
|
|
173
|
+
* found here); a revision other than the view's is `CONFLICT`, carrying
|
|
174
|
+
* the view as it is.
|
|
175
|
+
*/
|
|
176
|
+
private systemVersion;
|
|
177
|
+
/** The options of a command sent from `place`: its scope, request id and signal. */
|
|
178
|
+
private commandOptions;
|
|
179
|
+
}
|