@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
package/dist/index.es.js
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _ } from "./remembered.es.js";
|
|
2
|
+
import { ResultExtractors as v } from "@ahoo-wang/fetcher";
|
|
3
|
+
import { CommandHeaders as y, CommandStage as b, ErrorCodes as x, asc as S, filter as C, listQuery as w, singleQuery as T, toWowError as E } from "@ahoo-wang/wow-client";
|
|
4
|
+
import { ViewStoreError as D, isSystemInstanceId as O, isViewStoreError as k } from "@ahoo-wang/wow-view-engine";
|
|
5
|
+
//#region src/errors.ts
|
|
6
|
+
var A = Object.freeze({
|
|
6
7
|
VIEW_INVALID: "ViewInvalid",
|
|
7
8
|
VIEW_APP_REQUIRED: "ViewAppRequired",
|
|
8
9
|
SYSTEM_VIEW_READ_ONLY: "SystemViewReadOnly",
|
|
9
10
|
VIEW_SCOPE_REQUIRED: "ViewScopeRequired",
|
|
10
11
|
VIEW_EVENT_STREAM_CLOSED: "ViewEventStreamClosed"
|
|
11
|
-
}),
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
12
|
+
}), j = "referenced-by-shared-dashboard", M = {
|
|
13
|
+
[x.COMMAND_EXPECT_VERSION_CONFLICT]: "CONFLICT",
|
|
14
|
+
[x.EVENT_VERSION_CONFLICT]: "CONFLICT",
|
|
15
|
+
[x.SOURCING_VERSION_CONFLICT]: "CONFLICT",
|
|
16
|
+
[x.NOT_FOUND]: "NOT_FOUND",
|
|
17
|
+
[x.ILLEGAL_ACCESS_DELETED_AGGREGATE]: "NOT_FOUND",
|
|
18
|
+
[x.ILLEGAL_ACCESS_OWNER_AGGREGATE]: "FORBIDDEN",
|
|
19
|
+
[x.ILLEGAL_ACCESS_SPACE_AGGREGATE]: "FORBIDDEN",
|
|
20
|
+
[x.ILLEGAL_ACCESS_QUERY_SCOPE]: "FORBIDDEN",
|
|
21
|
+
[A.SYSTEM_VIEW_READ_ONLY]: "FORBIDDEN",
|
|
22
|
+
[A.VIEW_EVENT_STREAM_CLOSED]: "FORBIDDEN",
|
|
23
|
+
[A.VIEW_INVALID]: "INVALID",
|
|
24
|
+
[A.VIEW_APP_REQUIRED]: "INVALID",
|
|
25
|
+
[A.VIEW_SCOPE_REQUIRED]: "INVALID",
|
|
26
|
+
[x.BAD_REQUEST]: "INVALID",
|
|
27
|
+
[x.ILLEGAL_ARGUMENT]: "INVALID",
|
|
28
|
+
[x.ILLEGAL_STATE]: "UNAVAILABLE",
|
|
29
|
+
[x.COMMAND_VALIDATION]: "INVALID",
|
|
30
|
+
[x.DUPLICATE_AGGREGATE_ID]: "INVALID",
|
|
31
|
+
[x.QUERY_SCHEMA_VALIDATION]: "INVALID",
|
|
32
|
+
[x.REQUEST_TIMEOUT]: "UNAVAILABLE",
|
|
33
|
+
[x.TOO_MANY_REQUESTS]: "UNAVAILABLE",
|
|
34
|
+
[x.INTERNAL_SERVER_ERROR]: "UNAVAILABLE",
|
|
35
|
+
[x.QUERY_SCHEMA_UNAVAILABLE]: "UNAVAILABLE",
|
|
36
|
+
[x.QUERY_SCHEMA_CONFLICT]: "UNAVAILABLE"
|
|
36
37
|
}, Failure = class {
|
|
37
38
|
constructor(e, t, n) {
|
|
38
39
|
this.cause = e, this.wow = t, this.status = n;
|
|
@@ -45,7 +46,7 @@ var f = Object.freeze({
|
|
|
45
46
|
}
|
|
46
47
|
get unfilled() {
|
|
47
48
|
if (!(this.wow || this.status !== void 0)) for (let e = this.cause, t = 0; e && t < 4; t++) {
|
|
48
|
-
let t = e.message, n = typeof t == "string" ?
|
|
49
|
+
let t = e.message, n = typeof t == "string" ? N.exec(t) : null;
|
|
49
50
|
if (n) return n[1];
|
|
50
51
|
e = e.cause;
|
|
51
52
|
}
|
|
@@ -62,7 +63,7 @@ var f = Object.freeze({
|
|
|
62
63
|
return e === void 0 ? this.status === void 0 ? `The view store could not be reached: ${reasonOf(this.cause)}` : `The view store answered HTTP ${this.status}` : `The fetcher's interceptors did not fill the path variable {${e}}`;
|
|
63
64
|
}
|
|
64
65
|
toStoreError() {
|
|
65
|
-
return new
|
|
66
|
+
return new D(this.code, this.message, this.held());
|
|
66
67
|
}
|
|
67
68
|
held() {
|
|
68
69
|
let e = this.errorCode;
|
|
@@ -72,12 +73,12 @@ var f = Object.freeze({
|
|
|
72
73
|
...this.code === "UNAVAILABLE" && this.reached ? { reachable: !0 } : {}
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
|
-
},
|
|
76
|
+
}, N = /^Missing required path parameter: (\S+)/;
|
|
76
77
|
function isDuplicateRequest(e) {
|
|
77
|
-
return e.errorCode ===
|
|
78
|
+
return e.errorCode === x.DUPLICATE_REQUEST_ID;
|
|
78
79
|
}
|
|
79
80
|
function portCodeOf(e, t) {
|
|
80
|
-
let n = e === void 0 ? void 0 :
|
|
81
|
+
let n = e === void 0 ? void 0 : M[e];
|
|
81
82
|
if (n) return n;
|
|
82
83
|
switch (t) {
|
|
83
84
|
case 400:
|
|
@@ -92,7 +93,7 @@ function portCodeOf(e, t) {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
async function failureOf(e) {
|
|
95
|
-
let t = await
|
|
96
|
+
let t = await E(e);
|
|
96
97
|
return new Failure(e, t, t?.status ?? statusOf(e));
|
|
97
98
|
}
|
|
98
99
|
function statusOf(e) {
|
|
@@ -106,167 +107,42 @@ function reasonOf(e) {
|
|
|
106
107
|
return String(e);
|
|
107
108
|
}
|
|
108
109
|
//#endregion
|
|
109
|
-
//#region src/paths.ts
|
|
110
|
-
var g = "(shared)", _ = "(system)", v = "(platform)", y = "/view-store/tenant/{tenantId}/owner/{ownerId}", b = {
|
|
111
|
-
views: `${y}/view`,
|
|
112
|
-
view: `${y}/view/{id}`,
|
|
113
|
-
save: `${y}/view/{id}/save`,
|
|
114
|
-
rename: `${y}/view/{id}/rename`,
|
|
115
|
-
share: `${y}/view/{id}/share`,
|
|
116
|
-
claim: `${y}/view/{id}/claim`,
|
|
117
|
-
single: `${y}/view/snapshot/single`,
|
|
118
|
-
list: `${y}/view/snapshot/list`,
|
|
119
|
-
replay: `${y}/view/requests/{requestId}`,
|
|
120
|
-
systemViews: `${y}/system-views`,
|
|
121
|
-
systemView: `${y}/system-views/{id}`,
|
|
122
|
-
preferences: `${y}/definitions/{definitionId}/preferences`
|
|
123
|
-
};
|
|
124
|
-
function pathAt(e, t = {}) {
|
|
125
|
-
switch (e) {
|
|
126
|
-
case "shared": return {
|
|
127
|
-
...t,
|
|
128
|
-
ownerId: g
|
|
129
|
-
};
|
|
130
|
-
case "system": return {
|
|
131
|
-
...t,
|
|
132
|
-
tenantId: v,
|
|
133
|
-
ownerId: _
|
|
134
|
-
};
|
|
135
|
-
default: return { ...t };
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/wire.ts
|
|
140
|
-
function isStored(e) {
|
|
141
|
-
return e.source === "stored" && typeof e.version == "number";
|
|
142
|
-
}
|
|
143
|
-
var x = [
|
|
144
|
-
"aggregateId",
|
|
145
|
-
"version",
|
|
146
|
-
"state.definitionId",
|
|
147
|
-
"state.title",
|
|
148
|
-
"state.audience",
|
|
149
|
-
"state.config.kind"
|
|
150
|
-
];
|
|
151
|
-
function revisionOf(e) {
|
|
152
|
-
return String(e);
|
|
153
|
-
}
|
|
154
|
-
function toInstance(e) {
|
|
155
|
-
let { aggregateId: t, version: n, state: r } = e;
|
|
156
|
-
return {
|
|
157
|
-
id: t,
|
|
158
|
-
definitionId: r.definitionId,
|
|
159
|
-
title: r.title,
|
|
160
|
-
scope: r.audience,
|
|
161
|
-
revision: revisionOf(n),
|
|
162
|
-
config: r.config
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function toSummary(e) {
|
|
166
|
-
let { aggregateId: t, version: n, state: r } = e;
|
|
167
|
-
return {
|
|
168
|
-
id: t,
|
|
169
|
-
definitionId: r.definitionId,
|
|
170
|
-
title: r.title,
|
|
171
|
-
scope: r.audience,
|
|
172
|
-
kind: r.config.kind,
|
|
173
|
-
revision: revisionOf(n)
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
function systemInstance(e) {
|
|
177
|
-
return {
|
|
178
|
-
id: e.id,
|
|
179
|
-
definitionId: e.definitionId,
|
|
180
|
-
title: e.title,
|
|
181
|
-
scope: "system",
|
|
182
|
-
revision: e.revision,
|
|
183
|
-
config: e.config,
|
|
184
|
-
...isStored(e) ? { stored: !0 } : {}
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
function systemSummary(e) {
|
|
188
|
-
return {
|
|
189
|
-
id: e.id,
|
|
190
|
-
definitionId: e.definitionId,
|
|
191
|
-
title: e.title,
|
|
192
|
-
scope: "system",
|
|
193
|
-
kind: e.kind,
|
|
194
|
-
revision: e.revision,
|
|
195
|
-
...isStored(e) ? { stored: !0 } : {}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function toPreferences(e) {
|
|
199
|
-
return preferencesAt({
|
|
200
|
-
order: e.order ?? [],
|
|
201
|
-
defaultInstanceId: e.defaultInstanceId ?? null,
|
|
202
|
-
autoRun: e.autoRun ?? void 0,
|
|
203
|
-
lastTabs: e.lastTabs ?? void 0
|
|
204
|
-
}, e.version);
|
|
205
|
-
}
|
|
206
|
-
function preferencesInput(e) {
|
|
207
|
-
let { order: t, defaultInstanceId: n, autoRun: r, lastTabs: i } = e;
|
|
208
|
-
return {
|
|
209
|
-
order: [...t],
|
|
210
|
-
defaultInstanceId: n ?? null,
|
|
211
|
-
...r === void 0 ? {} : { autoRun: r },
|
|
212
|
-
...i === void 0 ? {} : { lastTabs: { ...i } }
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function preferencesAt(e, t) {
|
|
216
|
-
return {
|
|
217
|
-
...preferencesInput(e),
|
|
218
|
-
revision: revisionOf(t)
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function samePreferences(e, t) {
|
|
222
|
-
return canonical(e) === canonical(t);
|
|
223
|
-
}
|
|
224
|
-
function canonical(e) {
|
|
225
|
-
let { order: t, defaultInstanceId: n, autoRun: r, lastTabs: i } = preferencesInput(e), a = i && Object.entries(i).sort(([e], [t]) => e < t ? -1 : +(e > t));
|
|
226
|
-
return JSON.stringify([
|
|
227
|
-
t,
|
|
228
|
-
n,
|
|
229
|
-
r ?? null,
|
|
230
|
-
a ?? null
|
|
231
|
-
]);
|
|
232
|
-
}
|
|
233
|
-
//#endregion
|
|
234
110
|
//#region src/wowViewStore.ts
|
|
235
|
-
var
|
|
111
|
+
var P = 1e3, F = Symbol("not replayed"), WowViewStore = class {
|
|
236
112
|
constructor(e) {
|
|
237
|
-
this.places = /* @__PURE__ */ new Map(), this.preferenceOutcomes = new
|
|
113
|
+
this.listLimit = P, this.places = /* @__PURE__ */ new Map(), this.preferenceOutcomes = new h(), this.preferenceAttempts = new h(), this.createAttempts = new h(), this.storedVersions = new h(z), this.fetcher = e.fetcher, e.permissions && (this.permissions = e.permissions);
|
|
238
114
|
}
|
|
239
115
|
list(e, t) {
|
|
240
116
|
return guard(async () => {
|
|
241
|
-
let n =
|
|
242
|
-
filter:
|
|
243
|
-
projection: { include:
|
|
244
|
-
sort:
|
|
245
|
-
limit:
|
|
246
|
-
}), [r,
|
|
247
|
-
this.json("POST",
|
|
117
|
+
let n = w({
|
|
118
|
+
filter: C.eq("state.definitionId", e),
|
|
119
|
+
projection: { include: u },
|
|
120
|
+
sort: L,
|
|
121
|
+
limit: P
|
|
122
|
+
}), [r, a, o] = await Promise.all([
|
|
123
|
+
this.json("POST", f.list, "personal", {
|
|
248
124
|
body: n,
|
|
249
125
|
signal: t
|
|
250
126
|
}),
|
|
251
|
-
this.json("POST",
|
|
127
|
+
this.json("POST", f.list, "shared", {
|
|
252
128
|
body: n,
|
|
253
129
|
signal: t
|
|
254
130
|
}),
|
|
255
|
-
this.json("GET",
|
|
131
|
+
this.json("GET", f.systemViews, "shared", {
|
|
256
132
|
query: { definitionId: e },
|
|
257
133
|
signal: t
|
|
258
134
|
})
|
|
259
135
|
]).catch((e) => {
|
|
260
136
|
throw e instanceof Failure && e.code === "NOT_FOUND" ? unsupported(e) : e;
|
|
261
137
|
});
|
|
262
|
-
for (let e of
|
|
263
|
-
let
|
|
138
|
+
for (let e of o) this.rememberSystem(e);
|
|
139
|
+
let s = /* @__PURE__ */ new Map();
|
|
264
140
|
for (let e of [
|
|
265
|
-
...r.map(
|
|
266
|
-
...
|
|
267
|
-
...
|
|
268
|
-
])
|
|
269
|
-
return [...
|
|
141
|
+
...r.map(i),
|
|
142
|
+
...a.map(i),
|
|
143
|
+
...o.map(c)
|
|
144
|
+
]) s.has(e.id) || (s.set(e.id, e), this.places.set(e.id, e.scope));
|
|
145
|
+
return [...s.values()].sort((e, t) => R[e.scope] - R[t.scope]);
|
|
270
146
|
});
|
|
271
147
|
}
|
|
272
148
|
get(e, t) {
|
|
@@ -277,12 +153,12 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
277
153
|
let n = e.scope, { requestId: r } = t;
|
|
278
154
|
if (this.createAttempts.has(r)) {
|
|
279
155
|
let e = await this.probe(n, t, !0), r = e?.status === 200 ? await e.json() : null;
|
|
280
|
-
if (r?.aggregateId) return this.places.set(r.aggregateId, n), n === "system" ? this.readAt("system", r.aggregateId, t.signal) :
|
|
156
|
+
if (r?.aggregateId) return this.places.set(r.aggregateId, n), n === "system" ? this.readAt("system", r.aggregateId, t.signal) : g(r);
|
|
281
157
|
}
|
|
282
158
|
this.createAttempts.set(r, !0);
|
|
283
159
|
let { definitionId: i, title: a, config: o } = e, s = {
|
|
284
160
|
method: "POST",
|
|
285
|
-
url:
|
|
161
|
+
url: f.views,
|
|
286
162
|
sentTo: n,
|
|
287
163
|
body: {
|
|
288
164
|
definitionId: i,
|
|
@@ -303,7 +179,7 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
303
179
|
save(e, t, n, r) {
|
|
304
180
|
return this.write(e, n, r, (e) => ({
|
|
305
181
|
method: "PUT",
|
|
306
|
-
url:
|
|
182
|
+
url: f.save,
|
|
307
183
|
sentTo: e,
|
|
308
184
|
body: { config: t },
|
|
309
185
|
landsAt: e
|
|
@@ -312,7 +188,7 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
312
188
|
rename(e, t, n, r) {
|
|
313
189
|
return this.write(e, n, r, (e) => ({
|
|
314
190
|
method: "PUT",
|
|
315
|
-
url:
|
|
191
|
+
url: f.rename,
|
|
316
192
|
sentTo: e,
|
|
317
193
|
body: { title: t },
|
|
318
194
|
landsAt: e
|
|
@@ -321,13 +197,13 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
321
197
|
changeAudience(e, t, n, r) {
|
|
322
198
|
return this.write(e, n, r, (e) => e === "system" ? readOnly("A system view never moves audience") : t === "shared" ? {
|
|
323
199
|
method: "PUT",
|
|
324
|
-
url:
|
|
200
|
+
url: f.share,
|
|
325
201
|
sentTo: e,
|
|
326
202
|
body: {},
|
|
327
203
|
landsAt: "shared"
|
|
328
204
|
} : {
|
|
329
205
|
method: "PUT",
|
|
330
|
-
url:
|
|
206
|
+
url: f.claim,
|
|
331
207
|
sentTo: "personal",
|
|
332
208
|
landsAt: "personal"
|
|
333
209
|
});
|
|
@@ -335,45 +211,45 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
335
211
|
async delete(e, t, n) {
|
|
336
212
|
await this.write(e, t, n, (e) => ({
|
|
337
213
|
method: "DELETE",
|
|
338
|
-
url:
|
|
214
|
+
url: f.view,
|
|
339
215
|
sentTo: e,
|
|
340
216
|
body: {},
|
|
341
217
|
landsAt: null
|
|
342
218
|
}));
|
|
343
219
|
}
|
|
344
220
|
getPreferences(e, t) {
|
|
345
|
-
return guard(async () =>
|
|
221
|
+
return guard(async () => r(await this.json("GET", f.preferences, "personal", {
|
|
346
222
|
path: { definitionId: e },
|
|
347
223
|
signal: t
|
|
348
224
|
}).catch(async (e) => {
|
|
349
225
|
throw await this.unsupportedOr(e, t);
|
|
350
226
|
})));
|
|
351
227
|
}
|
|
352
|
-
setPreferences(e,
|
|
228
|
+
setPreferences(e, n, r) {
|
|
353
229
|
return guard(async () => {
|
|
354
|
-
let { requestId:
|
|
355
|
-
if (
|
|
356
|
-
let
|
|
357
|
-
this.preferenceAttempts.set(
|
|
358
|
-
let
|
|
230
|
+
let { requestId: i, signal: a } = r, o = this.preferenceOutcomes.get(i);
|
|
231
|
+
if (o) return structuredClone(o);
|
|
232
|
+
let c = this.preferenceAttempts.has(i);
|
|
233
|
+
this.preferenceAttempts.set(i, !0);
|
|
234
|
+
let l;
|
|
359
235
|
try {
|
|
360
|
-
let
|
|
236
|
+
let i = await this.json("PUT", f.preferences, "personal", {
|
|
361
237
|
path: { definitionId: e },
|
|
362
|
-
body:
|
|
363
|
-
headers: writeHeaders(
|
|
364
|
-
signal:
|
|
238
|
+
body: t(n),
|
|
239
|
+
headers: writeHeaders(r, n.revision),
|
|
240
|
+
signal: a
|
|
365
241
|
});
|
|
366
|
-
|
|
367
|
-
} catch (
|
|
368
|
-
if (!(
|
|
369
|
-
let r = await this.getPreferences(e,
|
|
370
|
-
if ((
|
|
371
|
-
else throw new
|
|
372
|
-
...
|
|
242
|
+
l = typeof i.aggregateVersion == "number" ? s(n, i.aggregateVersion) : await this.getPreferences(e, a);
|
|
243
|
+
} catch (t) {
|
|
244
|
+
if (!(t instanceof Failure) || t.code !== "CONFLICT" && !isDuplicateRequest(t)) throw await this.unsupportedOr(t, a);
|
|
245
|
+
let r = await this.getPreferences(e, a);
|
|
246
|
+
if ((c || isDuplicateRequest(t)) && m(r, n)) l = r;
|
|
247
|
+
else throw new D("CONFLICT", t.message, {
|
|
248
|
+
...t.held(),
|
|
373
249
|
preferences: r
|
|
374
250
|
});
|
|
375
251
|
}
|
|
376
|
-
return this.preferenceOutcomes.set(
|
|
252
|
+
return this.preferenceOutcomes.set(i, l), structuredClone(l);
|
|
377
253
|
});
|
|
378
254
|
}
|
|
379
255
|
write(e, t, n, r) {
|
|
@@ -397,7 +273,7 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
397
273
|
} catch (t) {
|
|
398
274
|
if (!(t instanceof Failure)) throw t;
|
|
399
275
|
let c = await this.replayed(e, a, n, t);
|
|
400
|
-
if (c !==
|
|
276
|
+
if (c !== F) return c;
|
|
401
277
|
if (!s && (t.code === "NOT_FOUND" || t.code === "FORBIDDEN")) {
|
|
402
278
|
s = !0;
|
|
403
279
|
let t = (await this.find(e, i, null)).place;
|
|
@@ -417,32 +293,32 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
417
293
|
this.places.set(e, t.landsAt);
|
|
418
294
|
let i = n.aggregateVersion, a, o;
|
|
419
295
|
try {
|
|
420
|
-
if (a = await this.readAt(t.landsAt, e, r.signal), typeof i != "number" || a.revision ===
|
|
296
|
+
if (a = await this.readAt(t.landsAt, e, r.signal), typeof i != "number" || a.revision === d(i) || t.landsAt === "system" && this.storedVersions.get(e)?.version === i) return a;
|
|
421
297
|
} catch (e) {
|
|
422
298
|
o = e;
|
|
423
299
|
}
|
|
424
300
|
let s = await this.replay(e, t, r, !1);
|
|
425
|
-
if (s !==
|
|
301
|
+
if (s !== F && s !== void 0) return s;
|
|
426
302
|
if (a) return a;
|
|
427
303
|
throw o;
|
|
428
304
|
}
|
|
429
305
|
async replayed(e, t, n, r) {
|
|
430
|
-
return r.code === "CONFLICT" || r.code === "NOT_FOUND" || isDuplicateRequest(r) ? this.replay(e, t, n, !0) :
|
|
306
|
+
return r.code === "CONFLICT" || r.code === "NOT_FOUND" || isDuplicateRequest(r) ? this.replay(e, t, n, !0) : F;
|
|
431
307
|
}
|
|
432
308
|
async replay(e, t, n, r) {
|
|
433
309
|
let i = t.sentTo === "system" ? ["system"] : t.sentTo === "personal" ? ["personal", "shared"] : ["shared", "personal"];
|
|
434
310
|
for (let [a, o] of i.entries()) {
|
|
435
311
|
let i = await this.probe(o, n, r && a === 0);
|
|
436
312
|
if (!i) continue;
|
|
437
|
-
if (i.status === 204) return t.landsAt === null ? void 0 :
|
|
313
|
+
if (i.status === 204) return t.landsAt === null ? void 0 : F;
|
|
438
314
|
let s = await i.json();
|
|
439
|
-
return t.landsAt === null || s?.aggregateId !== e ?
|
|
315
|
+
return t.landsAt === null || s?.aggregateId !== e ? F : t.landsAt === "system" ? this.readAt("system", e, n.signal) : g(s);
|
|
440
316
|
}
|
|
441
|
-
return
|
|
317
|
+
return F;
|
|
442
318
|
}
|
|
443
319
|
async probe(e, t, n) {
|
|
444
320
|
try {
|
|
445
|
-
return await this.send("GET",
|
|
321
|
+
return await this.send("GET", f.replay, e, {
|
|
446
322
|
path: { requestId: t.requestId },
|
|
447
323
|
signal: t.signal
|
|
448
324
|
});
|
|
@@ -453,16 +329,16 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
453
329
|
}
|
|
454
330
|
async conflict(e, t, n) {
|
|
455
331
|
let { instance: r } = await this.find(e, n, null);
|
|
456
|
-
return new
|
|
332
|
+
return new D("CONFLICT", t.message, {
|
|
457
333
|
...t.held(),
|
|
458
334
|
instance: r
|
|
459
335
|
});
|
|
460
336
|
}
|
|
461
337
|
async refusal(e, t) {
|
|
462
|
-
let n = e.bindingErrors.filter((e) => e.code ===
|
|
338
|
+
let n = e.bindingErrors.filter((e) => e.code === j);
|
|
463
339
|
if (e.code !== "INVALID" || n.length === 0) return e.toStoreError();
|
|
464
340
|
let r = await Promise.all(n.map((e) => this.boardTitle(e, t)));
|
|
465
|
-
return new
|
|
341
|
+
return new D("INVALID", e.message, {
|
|
466
342
|
...e.held(),
|
|
467
343
|
boards: r
|
|
468
344
|
});
|
|
@@ -476,7 +352,7 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
476
352
|
}
|
|
477
353
|
}
|
|
478
354
|
async find(e, t, n = this.places.get(e)) {
|
|
479
|
-
if (!
|
|
355
|
+
if (!O(e)) {
|
|
480
356
|
let r = [
|
|
481
357
|
"personal",
|
|
482
358
|
"shared",
|
|
@@ -493,13 +369,13 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
493
369
|
if (e instanceof Failure && e.code === "NOT_FOUND") continue;
|
|
494
370
|
throw e;
|
|
495
371
|
}
|
|
496
|
-
if (!await this.served(t)) throw new
|
|
372
|
+
if (!await this.served(t)) throw new D("UNSUPPORTED", I);
|
|
497
373
|
}
|
|
498
|
-
throw new
|
|
374
|
+
throw new D("NOT_FOUND", `No such view: ${e}`);
|
|
499
375
|
}
|
|
500
376
|
async served(e) {
|
|
501
377
|
try {
|
|
502
|
-
return await this.send("GET",
|
|
378
|
+
return await this.send("GET", f.systemViews, "shared", { signal: e }), !0;
|
|
503
379
|
} catch (e) {
|
|
504
380
|
return !(e instanceof Failure && e.code === "NOT_FOUND");
|
|
505
381
|
}
|
|
@@ -508,7 +384,7 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
508
384
|
return e instanceof Failure && e.code === "NOT_FOUND" && !await this.served(t) ? unsupported(e) : e;
|
|
509
385
|
}
|
|
510
386
|
rememberSystem(e) {
|
|
511
|
-
return this.storedVersions.set(e.id,
|
|
387
|
+
return this.storedVersions.set(e.id, p(e) ? {
|
|
512
388
|
revision: e.revision,
|
|
513
389
|
version: e.version
|
|
514
390
|
} : null), e;
|
|
@@ -519,86 +395,141 @@ var S = 1e3, C = 256, w = Symbol("not replayed"), WowViewStore = class {
|
|
|
519
395
|
let a = await this.readAt("system", e, r.signal);
|
|
520
396
|
if (i = this.storedVersions.get(e), i && i.revision !== t) {
|
|
521
397
|
let i = await this.replay(e, n, r, !1);
|
|
522
|
-
if (i !==
|
|
523
|
-
throw new
|
|
398
|
+
if (i !== F) return { answer: i };
|
|
399
|
+
throw new D("CONFLICT", `System view ${e} has moved on from revision ${t}`, { instance: a });
|
|
524
400
|
}
|
|
525
401
|
}
|
|
526
402
|
return i || readOnly("Configured system views are read-only"), { version: String(i.version) };
|
|
527
403
|
}
|
|
528
|
-
async readAt(e, t,
|
|
529
|
-
return e === "system" ?
|
|
404
|
+
async readAt(e, t, r) {
|
|
405
|
+
return e === "system" ? n(this.rememberSystem(await this.json("GET", f.systemView, "shared", {
|
|
530
406
|
path: { id: t },
|
|
531
|
-
signal:
|
|
532
|
-
}))) :
|
|
533
|
-
body:
|
|
534
|
-
signal:
|
|
407
|
+
signal: r
|
|
408
|
+
}))) : g(await this.json("POST", f.single, e, {
|
|
409
|
+
body: T({ filter: C.id(t) }),
|
|
410
|
+
signal: r
|
|
535
411
|
}));
|
|
536
412
|
}
|
|
537
413
|
async json(e, t, n, r) {
|
|
538
414
|
return await (await this.send(e, t, n, r)).json();
|
|
539
415
|
}
|
|
540
|
-
async send(t, n,
|
|
416
|
+
async send(e, t, n, { path: r, query: i, body: a, headers: o, signal: s }) {
|
|
541
417
|
try {
|
|
542
418
|
return await this.fetcher.request({
|
|
543
|
-
url:
|
|
544
|
-
method:
|
|
419
|
+
url: t,
|
|
420
|
+
method: e,
|
|
545
421
|
urlParams: {
|
|
546
|
-
path:
|
|
547
|
-
query:
|
|
422
|
+
path: _(n, r),
|
|
423
|
+
query: i
|
|
548
424
|
},
|
|
549
|
-
body:
|
|
550
|
-
headers:
|
|
551
|
-
signal:
|
|
552
|
-
}, { resultExtractor:
|
|
425
|
+
body: a,
|
|
426
|
+
headers: o,
|
|
427
|
+
signal: s
|
|
428
|
+
}, { resultExtractor: v.Response });
|
|
553
429
|
} catch (e) {
|
|
554
430
|
throw await failureOf(e);
|
|
555
431
|
}
|
|
556
432
|
}
|
|
557
433
|
};
|
|
558
|
-
function writeHeaders(e,
|
|
434
|
+
function writeHeaders(e, t) {
|
|
559
435
|
return {
|
|
560
|
-
[
|
|
561
|
-
[
|
|
562
|
-
...
|
|
436
|
+
[y.REQUEST_ID]: e.requestId,
|
|
437
|
+
[y.WAIT_STAGE]: b.SNAPSHOT,
|
|
438
|
+
...t === void 0 ? {} : { [y.AGGREGATE_VERSION]: t }
|
|
563
439
|
};
|
|
564
440
|
}
|
|
565
|
-
var
|
|
441
|
+
var I = "This server has no view store";
|
|
566
442
|
function unsupported(e) {
|
|
567
|
-
return new
|
|
443
|
+
return new D("UNSUPPORTED", I, e.held());
|
|
568
444
|
}
|
|
569
|
-
var
|
|
445
|
+
var L = [S("firstEventTime"), S("aggregateId")], R = {
|
|
570
446
|
system: 0,
|
|
571
447
|
shared: 1,
|
|
572
448
|
personal: 2
|
|
573
449
|
};
|
|
574
450
|
function readOnly(e) {
|
|
575
|
-
throw new
|
|
451
|
+
throw new D("FORBIDDEN", e);
|
|
576
452
|
}
|
|
577
453
|
async function guard(e) {
|
|
578
454
|
try {
|
|
579
455
|
return await e();
|
|
580
456
|
} catch (e) {
|
|
581
|
-
throw e instanceof Failure ? e.toStoreError() :
|
|
457
|
+
throw e instanceof Failure ? e.toStoreError() : k(e) ? e : new D("UNAVAILABLE", e instanceof Error ? e.message : String(e), {
|
|
582
458
|
cause: e,
|
|
583
459
|
...e instanceof SyntaxError ? { reachable: !0 } : {}
|
|
584
460
|
});
|
|
585
461
|
}
|
|
586
462
|
}
|
|
587
|
-
var
|
|
588
|
-
|
|
589
|
-
|
|
463
|
+
var z = 1024, B = 1e3, V = {
|
|
464
|
+
wording: `${l}/datasets/{dataset}/wording`,
|
|
465
|
+
list: `${l}/dataset_wording/snapshot/list`
|
|
466
|
+
}, WowDatasetWordings = class {
|
|
467
|
+
constructor(e) {
|
|
468
|
+
this.fetcher = e.fetcher;
|
|
590
469
|
}
|
|
591
|
-
|
|
592
|
-
return
|
|
470
|
+
list(e) {
|
|
471
|
+
return guard(async () => {
|
|
472
|
+
let t = await (await this.send("POST", V.list, {
|
|
473
|
+
body: w({
|
|
474
|
+
filter: C.matchAll(),
|
|
475
|
+
limit: B
|
|
476
|
+
}),
|
|
477
|
+
signal: e
|
|
478
|
+
})).json();
|
|
479
|
+
return new Map(t.map(({ version: e, state: t }) => [t.dataset, {
|
|
480
|
+
wording: wordingOf(t),
|
|
481
|
+
revision: d(e)
|
|
482
|
+
}]));
|
|
483
|
+
});
|
|
593
484
|
}
|
|
594
|
-
|
|
595
|
-
return
|
|
485
|
+
set(e, t, n, r) {
|
|
486
|
+
return guard(async () => {
|
|
487
|
+
let i = await (await this.send("PUT", V.wording, {
|
|
488
|
+
dataset: e,
|
|
489
|
+
body: {
|
|
490
|
+
...t.title === void 0 ? {} : { title: t.title },
|
|
491
|
+
...t.recordNoun === void 0 ? {} : { recordNoun: t.recordNoun },
|
|
492
|
+
...t.fields === void 0 ? {} : { fields: t.fields }
|
|
493
|
+
},
|
|
494
|
+
headers: writeHeaders(r, n),
|
|
495
|
+
signal: r.signal
|
|
496
|
+
})).json();
|
|
497
|
+
return d(i.aggregateVersion ?? Number(n) + 1);
|
|
498
|
+
});
|
|
596
499
|
}
|
|
597
|
-
|
|
598
|
-
|
|
500
|
+
clear(e, t, n) {
|
|
501
|
+
return guard(async () => {
|
|
502
|
+
await this.send("DELETE", V.wording, {
|
|
503
|
+
dataset: e,
|
|
504
|
+
body: {},
|
|
505
|
+
headers: writeHeaders(n, t),
|
|
506
|
+
signal: n.signal
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async send(e, t, { dataset: n, body: r, headers: i, signal: a }) {
|
|
511
|
+
try {
|
|
512
|
+
return await this.fetcher.request({
|
|
513
|
+
url: t,
|
|
514
|
+
method: e,
|
|
515
|
+
urlParams: { path: _("shared", n === void 0 ? {} : { dataset: n }) },
|
|
516
|
+
body: r,
|
|
517
|
+
headers: i,
|
|
518
|
+
signal: a
|
|
519
|
+
}, { resultExtractor: v.Response });
|
|
520
|
+
} catch (e) {
|
|
521
|
+
throw await failureOf(e);
|
|
522
|
+
}
|
|
599
523
|
}
|
|
600
524
|
};
|
|
525
|
+
function wordingOf(e) {
|
|
526
|
+
return {
|
|
527
|
+
...e.title == null ? {} : { title: e.title },
|
|
528
|
+
...e.recordNoun == null ? {} : { recordNoun: e.recordNoun },
|
|
529
|
+
...e.fields == null ? {} : { fields: e.fields }
|
|
530
|
+
};
|
|
531
|
+
}
|
|
601
532
|
//#endregion
|
|
602
|
-
export {
|
|
533
|
+
export { o as SHARED_OWNER_ID, a as SYSTEM_OWNER_ID, e as SYSTEM_TENANT_ID, WowDatasetWordings, WowViewStore, A as WowViewStoreErrorCodes };
|
|
603
534
|
|
|
604
535
|
//# sourceMappingURL=index.es.js.map
|