@ahoo-wang/wow-view-store 10.0.0-alpha.6 → 10.0.0-beta.1

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/index.es.js CHANGED
@@ -1,12 +1,10 @@
1
- import { asc as e, filter as t, listQuery as n, singleQuery as r } from "@ahoo-wang/wow-client/dsl";
2
- import { CommandGateway as i, FrameworkErrorCodes as a, LifecycleCommands as o, SnapshotQueryClient as s, StateClient as c, toWowProblemError as l, wait as u } from "@ahoo-wang/wow-client";
3
- import { ViewStoreError as d, emptyPreferences as f, isSystemInstanceId as p, isViewStoreError as m } from "@ahoo-wang/wow-view-engine";
4
- //#region \0rolldown/runtime.js
5
- var h = Object.defineProperty, __name = (e, t) => h(e, "name", {
6
- value: t,
7
- configurable: !0
8
- }), g = "(shared)", _ = "(system)", v = "(platform)", y = 256, Remembered = class {
9
- constructor(e = y) {
1
+ import { asc as e, cursorQuery as t, filter as n, listQuery as r, singleQuery as i } from "@ahoo-wang/wow-client/dsl";
2
+ import { CommandClient as a, CommandRejectedError as o, FrameworkErrorCodes as s, LifecycleCommands as c, MANIFEST_FORMAT as l, SnapshotQueryClient as u, StateClient as d, WaitPlan as f, WowProblemError as p, toWowProblemError as m, wait as h } from "@ahoo-wang/wow-client";
3
+ import { ViewStoreError as g, emptyPreferences as _, isSystemInstanceId as v, isViewStoreError as y } from "@ahoo-wang/wow-view-engine";
4
+ import { ServiceRoutes as b } from "@ahoo-wang/wow-client/routes";
5
+ // \0rolldown/runtime.js
6
+ var x = "(shared)", S = "(system)", C = "(platform)", w = 256, Remembered = class {
7
+ constructor(e = w) {
10
8
  this.limit = e, this.entries = /* @__PURE__ */ new Map();
11
9
  }
12
10
  get(e) {
@@ -19,20 +17,19 @@ var h = Object.defineProperty, __name = (e, t) => h(e, "name", {
19
17
  this.entries.delete(e), this.entries.set(e, t), this.entries.size > this.limit && this.entries.delete(this.entries.keys().next().value);
20
18
  }
21
19
  };
22
- //#endregion
23
- //#region src/views.ts
20
+ // src/views.ts
24
21
  function isStored(e) {
25
22
  return e.source === "stored" && typeof e.version == "number";
26
23
  }
27
24
  function revisionOf(e) {
28
25
  return String(e);
29
26
  }
30
- function systemInstance(e) {
27
+ function viewInstance(e) {
31
28
  return {
32
29
  id: e.id,
33
30
  definitionId: e.definitionId,
34
31
  title: e.title,
35
- scope: "system",
32
+ scope: e.scope,
36
33
  revision: e.revision,
37
34
  config: e.config,
38
35
  ...isStored(e) ? { stored: !0 } : {}
@@ -51,7 +48,7 @@ function systemSummary(e) {
51
48
  }
52
49
  function toPreferences(e) {
53
50
  return preferencesAt({
54
- order: e.order ?? [],
51
+ order: e.order,
55
52
  defaultInstanceId: e.defaultInstanceId ?? null,
56
53
  autoRun: e.autoRun ?? void 0,
57
54
  lastTabs: e.lastTabs ?? void 0
@@ -72,161 +69,334 @@ function preferencesAt(e, t) {
72
69
  revision: revisionOf(t)
73
70
  };
74
71
  }
75
- //#endregion
76
- //#region src/generated/view-store/boundedContext.ts
77
- var b = "view-store", x = {
78
- APP_REQUIRED: "view-store.app-required",
79
- INVALID: "view-store.invalid",
80
- NOT_FOUND: "view-store.not-found",
81
- OWNER_REQUIRED: "view-store.owner-required",
82
- REFERENCED_BY_SHARED_DASHBOARD: "view-store.referenced-by-shared-dashboard",
83
- SYSTEM_VIEW_READ_ONLY: "view-store.system-view-read-only"
84
- }, S = {
85
- accepted: () => u.accepted(b),
86
- committed: () => u.committed(b),
87
- snapshot: () => u.snapshot(b),
88
- handled: (e) => u.handled(e, b)
89
- }, C = {
72
+ // src/generated/view-store/dataset_wording/aggregate.ts
73
+ var T = {
74
+ context: "view-store",
75
+ name: "dataset_wording",
76
+ path: "/view-store/dataset_wording",
77
+ ownership: "tenant",
78
+ snapshot: !0
79
+ }, E = {
90
80
  context: "view-store",
91
81
  name: "view",
92
82
  path: "/view-store/view",
93
- ownership: "OWNER",
83
+ ownership: "owner",
94
84
  snapshot: !0
95
- }, w = {
96
- CLAIM_VIEW: "/view-store/view/{id}/claim-view",
97
- CREATE_VIEW: "/view-store/view/{id}/create-view",
98
- CREATE_VIEW_WITHOUT_ID: "/view-store/view/create-view",
99
- RENAME_VIEW: "/view-store/view/{id}/rename-view",
100
- SAVE_VIEW: "/view-store/view/{id}/save-view",
101
- SHARE_VIEW: "/view-store/view/{id}/share-view"
85
+ }, D = {
86
+ context: "view-store",
87
+ name: "view_preferences",
88
+ path: "/view-store/view_preferences",
89
+ ownership: "owner",
90
+ snapshot: !0
91
+ }, O = {
92
+ NAME: "view-store",
93
+ Errors: {
94
+ APP_REQUIRED: "view-store.app-required",
95
+ INVALID: "view-store.invalid",
96
+ NOT_FOUND: "view-store.not-found",
97
+ OWNER_REQUIRED: "view-store.owner-required",
98
+ REFERENCED_BY_SHARED_DASHBOARD: "view-store.referenced-by-shared-dashboard",
99
+ SYSTEM_VIEW_READ_ONLY: "view-store.system-view-read-only"
100
+ },
101
+ DatasetWording: T,
102
+ View: E,
103
+ ViewPreferences: D
104
+ }, k = {
105
+ accepted: () => h.accepted(O.NAME),
106
+ committed: () => h.committed(O.NAME),
107
+ snapshot: () => h.snapshot(O.NAME),
108
+ handled: (e) => h.handled(e, O.NAME)
109
+ }, A = {
110
+ format: l,
111
+ contexts: [{
112
+ name: "view-store",
113
+ aggregates: [
114
+ {
115
+ name: "dataset_wording",
116
+ commands: [{
117
+ name: "ClearDatasetWording",
118
+ routes: [{
119
+ method: "POST",
120
+ path: "/view-store/dataset_wording/{id}/clear-dataset-wording"
121
+ }, {
122
+ method: "POST",
123
+ path: "/view-store/dataset_wording/clear-dataset-wording"
124
+ }]
125
+ }, {
126
+ name: "SetDatasetWording",
127
+ routes: [{
128
+ method: "POST",
129
+ path: "/view-store/dataset_wording/{id}/set-dataset-wording"
130
+ }, {
131
+ method: "POST",
132
+ path: "/view-store/dataset_wording/set-dataset-wording"
133
+ }]
134
+ }]
135
+ },
136
+ {
137
+ name: "view",
138
+ commands: [
139
+ {
140
+ name: "ClaimView",
141
+ routes: [{
142
+ method: "POST",
143
+ path: "/view-store/view/{id}/claim-view"
144
+ }]
145
+ },
146
+ {
147
+ name: "CreateView",
148
+ routes: [{
149
+ method: "POST",
150
+ path: "/view-store/view/{id}/create-view"
151
+ }, {
152
+ method: "POST",
153
+ path: "/view-store/view/create-view"
154
+ }]
155
+ },
156
+ {
157
+ name: "RenameView",
158
+ routes: [{
159
+ method: "POST",
160
+ path: "/view-store/view/{id}/rename-view"
161
+ }]
162
+ },
163
+ {
164
+ name: "SaveView",
165
+ routes: [{
166
+ method: "POST",
167
+ path: "/view-store/view/{id}/save-view"
168
+ }]
169
+ },
170
+ {
171
+ name: "ShareView",
172
+ routes: [{
173
+ method: "POST",
174
+ path: "/view-store/view/{id}/share-view"
175
+ }]
176
+ },
177
+ {
178
+ name: "wow.lifecycle.DeleteAggregate",
179
+ routes: [{
180
+ method: "DELETE",
181
+ path: "/view-store/view/{id}"
182
+ }]
183
+ },
184
+ {
185
+ name: "wow.lifecycle.TransferOwner",
186
+ routes: [{
187
+ method: "POST",
188
+ path: "/view-store/view/{id}/wow.lifecycle.transfer-owner"
189
+ }]
190
+ }
191
+ ]
192
+ },
193
+ {
194
+ name: "view_preferences",
195
+ commands: [{
196
+ name: "SetViewPreferences",
197
+ routes: [{
198
+ method: "POST",
199
+ path: "/view-store/view_preferences/{id}/set-view-preferences"
200
+ }, {
201
+ method: "POST",
202
+ path: "/view-store/view_preferences/set-view-preferences"
203
+ }]
204
+ }]
205
+ }
206
+ ],
207
+ routes: [{
208
+ name: "systemViews",
209
+ route: {
210
+ method: "GET",
211
+ path: "/view-store/system-views"
212
+ }
213
+ }, {
214
+ name: "view",
215
+ route: {
216
+ method: "GET",
217
+ path: "/view-store/views/{id}"
218
+ }
219
+ }]
220
+ }]
102
221
  }, ViewCommandClient = class {
103
222
  constructor(e) {
104
- this.gateway = new i(e);
223
+ this.client = new a(e, { manifest: A });
105
224
  }
106
225
  claimView(e, t = {}, n) {
107
- return this.gateway.send(w.CLAIM_VIEW, t, {
226
+ return this.client.wait({
108
227
  ...n,
228
+ command: "view-store.view.ClaimView",
229
+ body: t,
109
230
  id: e
110
231
  });
111
232
  }
112
233
  claimViewStream(e, t = {}, n) {
113
- return this.gateway.stream(w.CLAIM_VIEW, t, {
234
+ return this.client.stream({
114
235
  ...n,
236
+ command: "view-store.view.ClaimView",
237
+ body: t,
115
238
  id: e
116
239
  });
117
240
  }
118
241
  createView(e, t) {
119
- return this.gateway.send(t?.id === void 0 ? w.CREATE_VIEW_WITHOUT_ID : w.CREATE_VIEW, e, t);
242
+ return this.client.wait({
243
+ ...t,
244
+ command: "view-store.view.CreateView",
245
+ body: e
246
+ });
120
247
  }
121
248
  createViewStream(e, t) {
122
- return this.gateway.stream(t?.id === void 0 ? w.CREATE_VIEW_WITHOUT_ID : w.CREATE_VIEW, e, t);
249
+ return this.client.stream({
250
+ ...t,
251
+ command: "view-store.view.CreateView",
252
+ body: e
253
+ });
123
254
  }
124
255
  renameView(e, t, n) {
125
- return this.gateway.send(w.RENAME_VIEW, t, {
256
+ return this.client.wait({
126
257
  ...n,
258
+ command: "view-store.view.RenameView",
259
+ body: t,
127
260
  id: e
128
261
  });
129
262
  }
130
263
  renameViewStream(e, t, n) {
131
- return this.gateway.stream(w.RENAME_VIEW, t, {
264
+ return this.client.stream({
132
265
  ...n,
266
+ command: "view-store.view.RenameView",
267
+ body: t,
133
268
  id: e
134
269
  });
135
270
  }
136
271
  saveView(e, t, n) {
137
- return this.gateway.send(w.SAVE_VIEW, t, {
272
+ return this.client.wait({
138
273
  ...n,
274
+ command: "view-store.view.SaveView",
275
+ body: t,
139
276
  id: e
140
277
  });
141
278
  }
142
279
  saveViewStream(e, t, n) {
143
- return this.gateway.stream(w.SAVE_VIEW, t, {
280
+ return this.client.stream({
144
281
  ...n,
282
+ command: "view-store.view.SaveView",
283
+ body: t,
145
284
  id: e
146
285
  });
147
286
  }
148
287
  shareView(e, t = {}, n) {
149
- return this.gateway.send(w.SHARE_VIEW, t, {
288
+ return this.client.wait({
150
289
  ...n,
290
+ command: "view-store.view.ShareView",
291
+ body: t,
151
292
  id: e
152
293
  });
153
294
  }
154
295
  shareViewStream(e, t = {}, n) {
155
- return this.gateway.stream(w.SHARE_VIEW, t, {
296
+ return this.client.stream({
156
297
  ...n,
298
+ command: "view-store.view.ShareView",
299
+ body: t,
157
300
  id: e
158
301
  });
159
302
  }
160
303
  deleteAggregate(e, t) {
161
- return this.gateway.lifecycle(C.path, e, o.DELETE_AGGREGATE, void 0, t);
304
+ return this.client.wait({
305
+ ...t,
306
+ command: c.DELETE_AGGREGATE,
307
+ type: {
308
+ context: "view-store",
309
+ name: "view"
310
+ },
311
+ id: e
312
+ });
162
313
  }
163
314
  transferOwner(e, t, n) {
164
- return this.gateway.lifecycle(C.path, e, o.TRANSFER_OWNER, t, n);
315
+ return this.client.wait({
316
+ ...n,
317
+ command: c.TRANSFER_OWNER,
318
+ type: {
319
+ context: "view-store",
320
+ name: "view"
321
+ },
322
+ id: e,
323
+ body: t
324
+ });
165
325
  }
166
- }, ViewSnapshotQueryClient = class extends s {
326
+ }, ViewSnapshotQueryClient = class extends u {
167
327
  constructor(e) {
168
- super(C, e);
328
+ super(E, e);
169
329
  }
170
- }, ViewStateClient = class extends c {
330
+ }, ViewStateClient = class extends d {
171
331
  constructor(e) {
172
- super(C, e);
332
+ super(E, e);
173
333
  }
174
- }, T = {
175
- SET_VIEW_PREFERENCES: "/view-store/view_preferences/{id}/set-view-preferences",
176
- SET_VIEW_PREFERENCES_WITHOUT_ID: "/view-store/view_preferences/set-view-preferences"
177
334
  }, ViewPreferencesCommandClient = class {
178
335
  constructor(e) {
179
- this.gateway = new i(e);
336
+ this.client = new a(e, { manifest: A });
180
337
  }
181
338
  setViewPreferences(e, t) {
182
- return this.gateway.send(t?.id === void 0 ? T.SET_VIEW_PREFERENCES_WITHOUT_ID : T.SET_VIEW_PREFERENCES, e, t);
339
+ return this.client.wait({
340
+ ...t,
341
+ command: "view-store.view_preferences.SetViewPreferences",
342
+ body: e
343
+ });
183
344
  }
184
345
  setViewPreferencesStream(e, t) {
185
- return this.gateway.stream(t?.id === void 0 ? T.SET_VIEW_PREFERENCES_WITHOUT_ID : T.SET_VIEW_PREFERENCES, e, t);
346
+ return this.client.stream({
347
+ ...t,
348
+ command: "view-store.view_preferences.SetViewPreferences",
349
+ body: e
350
+ });
186
351
  }
187
- }, E = {
188
- context: "view-store",
189
- name: "view_preferences",
190
- path: "/view-store/view_preferences",
191
- ownership: "OWNER",
192
- snapshot: !0
193
- }, ViewPreferencesSnapshotQueryClient = class extends s {
352
+ }, ViewPreferencesSnapshotQueryClient = class extends u {
194
353
  constructor(e) {
195
- super(E, e);
354
+ super(D, e);
196
355
  }
197
- }, D = x, O = {
198
- [a.AGGREGATE_VERSION_MISMATCH]: "CONFLICT",
199
- [a.COMMAND_REQUEST_ID_REUSED]: "CONFLICT",
200
- [a.AGGREGATE_NOT_FOUND]: "NOT_FOUND",
201
- [a.QUERY_NOT_FOUND]: "NOT_FOUND",
202
- [a.AGGREGATE_DELETED]: "NOT_FOUND",
203
- [x.NOT_FOUND]: "NOT_FOUND",
204
- [a.AUTH_UNAUTHENTICATED]: "FORBIDDEN",
205
- [a.AUTH_FORBIDDEN]: "FORBIDDEN",
206
- [a.AGGREGATE_FORBIDDEN]: "FORBIDDEN",
207
- [x.SYSTEM_VIEW_READ_ONLY]: "FORBIDDEN",
208
- [x.INVALID]: "INVALID",
209
- [x.APP_REQUIRED]: "INVALID",
210
- [x.OWNER_REQUIRED]: "INVALID",
211
- [x.REFERENCED_BY_SHARED_DASHBOARD]: "INVALID",
212
- [a.AGGREGATE_EXISTS]: "INVALID",
213
- [a.COMMAND_MALFORMED]: "INVALID",
214
- [a.COMMAND_INVALID]: "INVALID",
215
- [a.COMMAND_UNHANDLED]: "INVALID",
216
- [a.WAIT_INVALID]: "INVALID",
217
- [a.QUERY_MALFORMED]: "INVALID",
218
- [a.QUERY_INVALID]: "INVALID"
356
+ }, ViewStoreRoutes = class {
357
+ constructor(e) {
358
+ this.routes = new b(e, { manifest: A });
359
+ }
360
+ systemViews(e, t) {
361
+ return this.routes.call("view-store", "systemViews", { query: e }, t);
362
+ }
363
+ view(e, t) {
364
+ return this.routes.call("view-store", "view", { path: { id: e } }, t);
365
+ }
366
+ }, j = O.Errors, M = {
367
+ [s.AGGREGATE_VERSION_MISMATCH]: "CONFLICT",
368
+ [s.COMMAND_REQUEST_ID_REUSED]: "CONFLICT",
369
+ [s.AGGREGATE_NOT_FOUND]: "NOT_FOUND",
370
+ [s.QUERY_NOT_FOUND]: "NOT_FOUND",
371
+ [s.AGGREGATE_DELETED]: "NOT_FOUND",
372
+ [O.Errors.NOT_FOUND]: "NOT_FOUND",
373
+ [s.AUTH_UNAUTHENTICATED]: "FORBIDDEN",
374
+ [s.AUTH_FORBIDDEN]: "FORBIDDEN",
375
+ [s.AGGREGATE_FORBIDDEN]: "FORBIDDEN",
376
+ [O.Errors.SYSTEM_VIEW_READ_ONLY]: "FORBIDDEN",
377
+ [O.Errors.INVALID]: "INVALID",
378
+ [O.Errors.APP_REQUIRED]: "INVALID",
379
+ [O.Errors.OWNER_REQUIRED]: "INVALID",
380
+ [O.Errors.REFERENCED_BY_SHARED_DASHBOARD]: "INVALID",
381
+ [s.AGGREGATE_EXISTS]: "INVALID",
382
+ [s.COMMAND_MALFORMED]: "INVALID",
383
+ [s.COMMAND_INVALID]: "INVALID",
384
+ [s.COMMAND_UNHANDLED]: "INVALID",
385
+ [s.WAIT_INVALID]: "INVALID",
386
+ [s.QUERY_MALFORMED]: "INVALID",
387
+ [s.QUERY_INVALID]: "INVALID"
219
388
  }, Failure = class {
220
- constructor(e, t) {
221
- this.cause = e, this.problem = t;
389
+ constructor(e, t, n) {
390
+ this.cause = e, this.problem = t, this.rejection = n;
222
391
  }
223
392
  get problemCode() {
224
- return this.problem?.code;
393
+ return this.problem?.code ?? this.rejection?.code;
225
394
  }
226
395
  get code() {
227
- let e = this.problemCode, t = e === void 0 ? void 0 : O[e];
396
+ let e = this.problemCode, t = e === void 0 ? void 0 : M[e];
228
397
  if (t) return t;
229
- if (this.problem?.retry.retryable) return "UNAVAILABLE";
398
+ if (this.problem !== void 0 && this.problem.retry !== "none") return "UNAVAILABLE";
399
+ if (this.problem === void 0 && this.rejection) return "CONFLICT";
230
400
  switch (this.problem?.status) {
231
401
  case 400:
232
402
  case 422: return "INVALID";
@@ -240,13 +410,13 @@ var b = "view-store", x = {
240
410
  }
241
411
  }
242
412
  get reached() {
243
- return this.problem !== void 0;
413
+ return this.problem !== void 0 || this.rejection !== void 0;
244
414
  }
245
415
  get message() {
246
- return this.problem ? this.problem.message : `The view store could not be reached: ${reasonOf(this.cause)}`;
416
+ return this.problem ? this.problem.message : this.rejection ? this.rejection.message : `The view store could not be reached: ${reasonOf(this.cause)}`;
247
417
  }
248
418
  toStoreError() {
249
- return new d(this.code, this.message, this.held());
419
+ return new g(this.code, this.message, this.held());
250
420
  }
251
421
  held() {
252
422
  let e = this.problemCode;
@@ -258,7 +428,7 @@ var b = "view-store", x = {
258
428
  }
259
429
  };
260
430
  async function failureOf(e) {
261
- return e instanceof Failure ? e : new Failure(e, await l(e));
431
+ return e instanceof Failure ? e : e instanceof o ? e.cause instanceof p ? new Failure(e, e.cause) : new Failure(e, void 0, e) : new Failure(e, await m(e));
262
432
  }
263
433
  function boardTitles(e) {
264
434
  let t = e?.boards;
@@ -272,7 +442,7 @@ async function guard(e) {
272
442
  try {
273
443
  return await e();
274
444
  } catch (e) {
275
- throw e instanceof Failure ? e.toStoreError() : m(e) ? e : new d("UNAVAILABLE", e instanceof Error ? e.message : String(e), {
445
+ throw e instanceof Failure ? e.toStoreError() : y(e) ? e : new g("UNAVAILABLE", e instanceof Error ? e.message : String(e), {
276
446
  cause: e,
277
447
  ...e instanceof SyntaxError ? { reachable: !0 } : {}
278
448
  });
@@ -292,36 +462,19 @@ function reasonOf(e) {
292
462
  }
293
463
  return String(e);
294
464
  }
295
- //#endregion
296
- //#region src/systemViews.ts
297
- var k = "/view-store/system-views", SystemViewsClient = class {
298
- constructor(e) {
299
- this.fetcher = e;
300
- }
301
- list(e, t) {
302
- return this.get(`${k}?definitionId=${encodeURIComponent(e)}`, t);
303
- }
304
- one(e, t) {
305
- return this.get(`${k}/${encodeURIComponent(e)}`, t);
306
- }
307
- get(e, t) {
308
- return request(async () => await (await this.fetcher.fetch(e, {
309
- method: "GET",
310
- ...t === void 0 ? {} : { signal: t }
311
- })).json());
312
- }
313
- }, A = Object.freeze({ ownerId: g }), j = Object.freeze({
314
- tenantId: v,
315
- ownerId: _
465
+ // src/wire.ts
466
+ var N = Object.freeze({ ownerId: x }), P = Object.freeze({
467
+ tenantId: C,
468
+ ownerId: S
316
469
  });
317
470
  function scopeAt(e) {
318
471
  switch (e) {
319
- case "shared": return A;
320
- case "system": return j;
472
+ case "shared": return N;
473
+ case "system": return P;
321
474
  default: return;
322
475
  }
323
476
  }
324
- var M = [
477
+ var F = [
325
478
  "aggregateId",
326
479
  "version",
327
480
  "state.definitionId",
@@ -356,41 +509,81 @@ function wordingOf(e) {
356
509
  ...e.fields == null ? {} : { fields: e.fields }
357
510
  };
358
511
  }
359
- //#endregion
360
- //#region src/wowViewStore.ts
361
- var N = 1e3, P = 1024, F = [S.handled("ViewAudienceSaga.onAudienceChanged"), S.snapshot()], WowViewStore = class {
512
+ // src/wowViewStore.ts
513
+ var I = 100;
514
+ function listCursor(e) {
515
+ return btoa(JSON.stringify(e)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
516
+ }
517
+ function readListCursor(e) {
518
+ if (!e) return {
519
+ audience: "system",
520
+ cursor: null
521
+ };
522
+ try {
523
+ let t = JSON.parse(atob(e.replace(/-/g, "+").replace(/_/g, "/")));
524
+ if ([
525
+ "system",
526
+ "shared",
527
+ "personal"
528
+ ].includes(t.audience)) return t;
529
+ } catch {}
530
+ throw new g("INVALID", `Not a view list cursor: ${e}`);
531
+ }
532
+ var L = 1024, R = f.of(k.handled("ViewAudienceSaga.onAudienceChanged"), k.snapshot()), WowViewStore = class {
362
533
  constructor(e) {
363
- this.listLimit = N, this.places = /* @__PURE__ */ new Map(), this.systemVersions = new Remembered(P);
534
+ this.places = /* @__PURE__ */ new Map(), this.systemVersions = new Remembered(L), this.pageSize = e.pageSize ?? I;
364
535
  let t = { fetcher: e.fetcher };
365
- this.commands = new ViewCommandClient(t), this.snapshots = new ViewSnapshotQueryClient(t), this.states = new ViewStateClient(t), this.preferenceCommands = new ViewPreferencesCommandClient(t), this.preferenceSnapshots = new ViewPreferencesSnapshotQueryClient(t), this.systemViews = new SystemViewsClient(e.fetcher), e.permissions && (this.permissions = e.permissions);
536
+ this.commands = new ViewCommandClient(t), this.snapshots = new ViewSnapshotQueryClient(t), this.states = new ViewStateClient(t), this.preferenceCommands = new ViewPreferencesCommandClient(t), this.preferenceSnapshots = new ViewPreferencesSnapshotQueryClient(t), this.routes = new ViewStoreRoutes(t), e.permissions && (this.permissions = e.permissions);
366
537
  }
367
- list(r, i) {
538
+ list(e, t = {}) {
368
539
  return guard(async () => {
369
- let a = n({
370
- filter: t.eq("state.definitionId", r),
371
- projection: { include: [...M] },
372
- sort: [e("firstEventTime"), e("aggregateId")],
373
- limit: N
374
- }), [o, s, c] = await Promise.all([
375
- request(() => this.snapshots.list(a, { signal: i })),
376
- request(() => this.snapshots.list(a, {
377
- scope: scopeAt("shared"),
378
- signal: i
379
- })),
380
- this.systemViews.list(r, i)
381
- ]);
382
- for (let e of c) this.rememberSystem(e);
383
- let l = /* @__PURE__ */ new Map();
384
- for (let e of [
385
- ...o.map((e) => toSummary(recordOf(e))),
386
- ...s.map((e) => toSummary(recordOf(e))),
387
- ...c.map(systemSummary)
388
- ]) l.has(e.id) || (l.set(e.id, e), this.places.set(e.id, e.scope));
389
- return [...l.values()].sort((e, t) => I[e.scope] - I[t.scope]);
540
+ let { signal: n } = t, r = [], i = readListCursor(t.cursor);
541
+ for (; i !== null && r.length < this.pageSize;) {
542
+ let t = this.pageSize - r.length, a = await this.listAudience(e, i, t, n);
543
+ r.push(...a.items), i = a.next;
544
+ }
545
+ for (let e of r) this.places.set(e.id, e.scope);
546
+ return {
547
+ items: r,
548
+ nextCursor: i === null ? null : listCursor(i)
549
+ };
390
550
  });
391
551
  }
392
- get(e, t) {
393
- return guard(async () => (await this.find(e, t)).instance);
552
+ async listAudience(r, i, a, o) {
553
+ if (i.audience === "system") {
554
+ let e = await request(() => this.routes.systemViews({ definitionId: r }, { signal: o }));
555
+ for (let t of e) this.rememberSystem(t);
556
+ return {
557
+ items: e.map(systemSummary),
558
+ next: {
559
+ audience: "shared",
560
+ cursor: null
561
+ }
562
+ };
563
+ }
564
+ let s = await request(() => this.snapshots.cursor(t({
565
+ filter: n.eq("state.definitionId", r),
566
+ projection: { include: [...F] },
567
+ sort: [e("firstEventTime")],
568
+ size: a,
569
+ cursor: i.cursor
570
+ }), i.audience === "shared" ? {
571
+ scope: scopeAt("shared"),
572
+ signal: o
573
+ } : { signal: o }));
574
+ return {
575
+ items: s.list.map((e) => toSummary(recordOf(e))),
576
+ next: s.nextCursor === null ? i.audience === "shared" ? {
577
+ audience: "personal",
578
+ cursor: null
579
+ } : null : {
580
+ audience: i.audience,
581
+ cursor: s.nextCursor
582
+ }
583
+ };
584
+ }
585
+ get(e, t = {}) {
586
+ return guard(async () => (await this.read(e, t.signal)).instance);
394
587
  }
395
588
  create(e, t) {
396
589
  return guard(async () => {
@@ -440,18 +633,14 @@ var N = 1e3, P = 1024, F = [S.handled("ViewAudienceSaga.onAudienceChanged"), S.s
440
633
  landsAt: null
441
634
  }));
442
635
  }
443
- getPreferences(e, n) {
636
+ getPreferences(e, t = {}) {
637
+ let { signal: r } = t;
444
638
  return guard(async () => {
445
- try {
446
- let i = await request(() => this.preferenceSnapshots.single(r({ filter: t.eq("state.definitionId", e) }), { signal: n }));
447
- return toPreferences({
448
- ...i.state,
449
- version: i.version
450
- });
451
- } catch (e) {
452
- if (e instanceof Failure && e.problemCode === a.QUERY_NOT_FOUND) return f();
453
- throw e;
454
- }
639
+ let t = await request(() => this.preferenceSnapshots.single(i({ filter: n.eq("state.definitionId", e) }), { signal: r }));
640
+ return t === void 0 ? _() : toPreferences({
641
+ ...t.state,
642
+ version: t.version
643
+ });
455
644
  });
456
645
  }
457
646
  setPreferences(e, t, n) {
@@ -466,22 +655,22 @@ var N = 1e3, P = 1024, F = [S.handled("ViewAudienceSaga.onAudienceChanged"), S.s
466
655
  expectedVersion: versionOf(t.revision),
467
656
  ...i === void 0 ? {} : { signal: i }
468
657
  }));
469
- return typeof n.version == "number" ? preferencesAt(t, n.version) : await this.getPreferences(e, i);
658
+ return typeof n.version == "number" ? preferencesAt(t, n.version) : await this.getPreferences(e, { signal: i });
470
659
  } catch (t) {
471
- throw !(t instanceof Failure) || t.code !== "CONFLICT" ? t : new d("CONFLICT", t.message, {
660
+ throw !(t instanceof Failure) || t.code !== "CONFLICT" ? t : new g("CONFLICT", t.message, {
472
661
  ...t.held(),
473
- preferences: await this.getPreferences(e, i)
662
+ preferences: await this.getPreferences(e, { signal: i })
474
663
  });
475
664
  }
476
665
  });
477
666
  }
478
667
  write(e, t, n, r) {
479
668
  return guard(async () => {
480
- let { signal: i } = n, a = this.places.get(e), o = a ?? (await this.find(e, i)).place, s = a === void 0;
669
+ let { signal: i } = n, a = this.places.get(e), o = a ?? (await this.read(e, i)).place, s = a === void 0;
481
670
  for (;;) {
482
671
  let a = r(o), c = this.commandOptions(a.sentFrom, n, {
483
672
  expectedVersion: o === "system" ? await this.systemVersion(e, t, i) : versionOf(t),
484
- ...a.moves ? { wait: { plan: F } } : {}
673
+ ...a.moves ? { wait: R } : {}
485
674
  }), l;
486
675
  try {
487
676
  l = await request(() => a.send(c));
@@ -490,7 +679,7 @@ var N = 1e3, P = 1024, F = [S.handled("ViewAudienceSaga.onAudienceChanged"), S.s
490
679
  if (a.moves && o === a.landsAt && n.code === "FORBIDDEN") return this.unchanged(e, t, o, i);
491
680
  if (!s && (n.code === "NOT_FOUND" || n.code === "FORBIDDEN")) {
492
681
  s = !0;
493
- let t = (await this.find(e, i, null)).place;
682
+ let t = (await this.read(e, i)).place;
494
683
  if (t !== o) {
495
684
  o = t;
496
685
  continue;
@@ -513,77 +702,60 @@ var N = 1e3, P = 1024, F = [S.handled("ViewAudienceSaga.onAudienceChanged"), S.s
513
702
  ...optionsAt(i),
514
703
  ...a === void 0 ? {} : { signal: a }
515
704
  }));
516
- if (!t.moves || ownedAt(s.scope.ownerId) === i) return toInstance({
705
+ if (!t.moves || ownedAt(s.ownerId) === i) return toInstance({
517
706
  id: e,
518
707
  version: s.version,
519
708
  state: s.state
520
709
  });
521
710
  } catch {}
522
- return (await this.find(e, a, i)).instance;
711
+ return (await this.read(e, a)).instance;
523
712
  }
524
713
  async unchanged(e, t, n, r) {
525
- let { instance: i } = await this.find(e, r, n);
526
- if (i.revision !== t) throw new d("CONFLICT", `View ${e} has moved on from revision ${t}`, { instance: i });
714
+ let { instance: i } = await this.read(e, r);
715
+ if (i.scope !== n || i.revision !== t) throw new g("CONFLICT", `View ${e} has moved on from revision ${t}`, { instance: i });
527
716
  return i;
528
717
  }
529
718
  async conflict(e, t, n) {
530
- let { instance: r } = await this.find(e, n, null);
531
- return new d("CONFLICT", t.message, {
719
+ let { instance: r } = await this.read(e, n);
720
+ return new g("CONFLICT", t.message, {
532
721
  ...t.held(),
533
722
  instance: r
534
723
  });
535
724
  }
536
- async find(e, t, n = this.places.get(e)) {
537
- if (!p(e)) {
538
- let r = [
539
- "personal",
540
- "shared",
541
- "system"
542
- ];
543
- n && r.sort((e, t) => Number(t === n) - Number(e === n));
544
- for (let n of r) try {
545
- let r = await this.readAt(n, e, t);
546
- return this.places.set(e, n), {
547
- place: n,
548
- instance: r
549
- };
550
- } catch (e) {
551
- if (e instanceof Failure && e.code === "NOT_FOUND") continue;
552
- throw e;
553
- }
554
- }
555
- throw new d("NOT_FOUND", `No such view: ${e}`);
556
- }
557
- async readAt(e, n, i) {
558
- return e === "system" ? systemInstance(this.rememberSystem(await this.systemViews.one(n, i))) : toInstance(recordOf(await request(() => this.snapshots.single(r({ filter: t.id(n) }), {
559
- ...optionsAt(e),
560
- ...i === void 0 ? {} : { signal: i }
561
- }))));
725
+ async read(e, t) {
726
+ if (v(e)) throw new g("NOT_FOUND", `No such view: ${e}`);
727
+ let n = await request(() => this.routes.view(e, { signal: t })), r = n.scope;
728
+ return this.places.set(e, r), r === "system" && this.rememberSystem(n), {
729
+ place: r,
730
+ instance: viewInstance(n)
731
+ };
562
732
  }
563
733
  rememberSystem(e) {
564
- return this.systemVersions.set(revisionKey(e.id, e.revision), isStored(e) ? e.version : null), e;
734
+ this.systemVersions.set(revisionKey(e.id, e.revision), isStored(e) ? e.version : null);
565
735
  }
566
736
  async systemVersion(e, t, n) {
567
737
  let r = revisionKey(e, t);
568
738
  if (!this.systemVersions.has(r)) {
569
- let r = await this.readAt("system", e, n);
570
- if (r.revision !== t && r.stored) throw new d("CONFLICT", `System view ${e} has moved on from revision ${t}`, { instance: r });
739
+ let { instance: r } = await this.read(e, n);
740
+ if (r.scope !== "system") throw new g("CONFLICT", `View ${e} is no longer a system view`, { instance: r });
741
+ if (r.revision !== t && r.stored) throw new g("CONFLICT", `System view ${e} has moved on from revision ${t}`, { instance: r });
571
742
  }
572
743
  let i = this.systemVersions.get(r);
573
744
  return typeof i != "number" && readOnly("Configured system views are read-only"), i;
574
745
  }
575
746
  commandOptions(e, { requestId: t, signal: n }, r = {}) {
747
+ let i = scopeAt(e);
576
748
  return {
577
- ...optionsAt(e),
749
+ ...i?.tenantId === void 0 ? {} : { targetTenant: i.tenantId },
750
+ ...i === void 0 ? {} : { targetScope: {
751
+ ownerId: i.ownerId,
752
+ spaceId: i.spaceId
753
+ } },
578
754
  requestId: t,
579
755
  ...n === void 0 ? {} : { signal: n },
580
756
  ...r
581
757
  };
582
758
  }
583
- }, I = {
584
- system: 0,
585
- shared: 1,
586
- personal: 2
587
759
  };
588
760
  function optionsAt(e) {
589
761
  let t = scopeAt(e);
@@ -604,66 +776,70 @@ function bodyOf(e) {
604
776
  }
605
777
  function versionOf(e) {
606
778
  let t = Number(e);
607
- if (!Number.isInteger(t) || t < 0) throw new d("CONFLICT", `Not a revision of this store: ${e}`);
779
+ if (!Number.isInteger(t) || t < 0) throw new g("CONFLICT", `Not a revision of this store: ${e}`);
608
780
  return t;
609
781
  }
610
782
  function revisionKey(e, t) {
611
783
  return `${e}\u0000${t}`;
612
784
  }
613
785
  function readOnly(e) {
614
- throw new d("FORBIDDEN", e);
786
+ throw new g("FORBIDDEN", e);
615
787
  }
616
788
  function refusal(e) {
617
- return e.problemCode === x.REFERENCED_BY_SHARED_DASHBOARD ? new d("INVALID", e.message, {
789
+ return e.problemCode === O.Errors.REFERENCED_BY_SHARED_DASHBOARD ? new g("INVALID", e.message, {
618
790
  ...e.held(),
619
791
  boards: boardTitles(e.problem?.problem.extensions)
620
792
  }) : e.toStoreError();
621
793
  }
622
- //#endregion
623
- //#region src/generated/view-store/dataset_wording/commandClient.ts
624
- var L = {
625
- CLEAR_DATASET_WORDING: "/view-store/dataset_wording/{id}/clear-dataset-wording",
626
- CLEAR_DATASET_WORDING_WITHOUT_ID: "/view-store/dataset_wording/clear-dataset-wording",
627
- SET_DATASET_WORDING: "/view-store/dataset_wording/{id}/set-dataset-wording",
628
- SET_DATASET_WORDING_WITHOUT_ID: "/view-store/dataset_wording/set-dataset-wording"
629
- }, DatasetWordingCommandClient = class {
794
+ // src/generated/view-store/dataset_wording/commandClient.ts
795
+ var DatasetWordingCommandClient = class {
630
796
  constructor(e) {
631
- this.gateway = new i(e);
797
+ this.client = new a(e, { manifest: A });
632
798
  }
633
799
  clearDatasetWording(e, t) {
634
- return this.gateway.send(t?.id === void 0 ? L.CLEAR_DATASET_WORDING_WITHOUT_ID : L.CLEAR_DATASET_WORDING, e, t);
800
+ return this.client.wait({
801
+ ...t,
802
+ command: "view-store.dataset_wording.ClearDatasetWording",
803
+ body: e
804
+ });
635
805
  }
636
806
  clearDatasetWordingStream(e, t) {
637
- return this.gateway.stream(t?.id === void 0 ? L.CLEAR_DATASET_WORDING_WITHOUT_ID : L.CLEAR_DATASET_WORDING, e, t);
807
+ return this.client.stream({
808
+ ...t,
809
+ command: "view-store.dataset_wording.ClearDatasetWording",
810
+ body: e
811
+ });
638
812
  }
639
813
  setDatasetWording(e, t) {
640
- return this.gateway.send(t?.id === void 0 ? L.SET_DATASET_WORDING_WITHOUT_ID : L.SET_DATASET_WORDING, e, t);
814
+ return this.client.wait({
815
+ ...t,
816
+ command: "view-store.dataset_wording.SetDatasetWording",
817
+ body: e
818
+ });
641
819
  }
642
820
  setDatasetWordingStream(e, t) {
643
- return this.gateway.stream(t?.id === void 0 ? L.SET_DATASET_WORDING_WITHOUT_ID : L.SET_DATASET_WORDING, e, t);
821
+ return this.client.stream({
822
+ ...t,
823
+ command: "view-store.dataset_wording.SetDatasetWording",
824
+ body: e
825
+ });
644
826
  }
645
- }, R = {
646
- context: "view-store",
647
- name: "dataset_wording",
648
- path: "/view-store/dataset_wording",
649
- ownership: "TENANT",
650
- snapshot: !0
651
- }, DatasetWordingSnapshotQueryClient = class extends s {
827
+ }, DatasetWordingSnapshotQueryClient = class extends u {
652
828
  constructor(e) {
653
- super(R, e);
829
+ super(T, e);
654
830
  }
655
831
  }, z = 1e3, WowDatasetWordings = class {
656
832
  constructor(e) {
657
833
  let t = { fetcher: e.fetcher };
658
834
  this.commands = new DatasetWordingCommandClient(t), this.snapshots = new DatasetWordingSnapshotQueryClient(t);
659
835
  }
660
- list(e) {
836
+ list({ signal: e } = {}) {
661
837
  return guard(async () => {
662
- let r = await request(() => this.snapshots.list(n({
663
- filter: t.matchAll(),
838
+ let t = await request(() => this.snapshots.list(r({
839
+ filter: n.matchAll(),
664
840
  limit: z
665
841
  }), e === void 0 ? {} : { signal: e }));
666
- return new Map(r.map(({ version: e, state: t }) => [t.dataset, {
842
+ return new Map(t.map(({ version: e, state: t }) => [t.dataset, {
667
843
  wording: wordingOf(t),
668
844
  revision: revisionOf(e)
669
845
  }]));
@@ -675,72 +851,35 @@ var L = {
675
851
  ...t.title === void 0 ? {} : { title: t.title },
676
852
  ...t.recordNoun === void 0 ? {} : { recordNoun: t.recordNoun },
677
853
  ...t.fields === void 0 ? {} : { fields: t.fields }
678
- }, optionsOf$1(n, r))), n));
854
+ }, optionsOf(n, r))), n));
679
855
  }
680
856
  clear(e, t, n) {
681
- return guard(async () => versionAfter(await request(() => this.commands.clearDatasetWording({ dataset: e }, optionsOf$1(t, n))), t));
857
+ return guard(async () => versionAfter(await request(() => this.commands.clearDatasetWording({ dataset: e }, optionsOf(t, n))), t));
682
858
  }
683
859
  };
684
- function optionsOf$1(e, { requestId: t, signal: n }) {
860
+ function optionsOf(e, { requestId: t, signal: n }) {
685
861
  return {
686
862
  requestId: t,
687
863
  expectedVersion: Number(e),
688
864
  ...n === void 0 ? {} : { signal: n }
689
865
  };
690
866
  }
691
- __name(optionsOf$1, "optionsOf");
692
867
  function versionAfter(e, t) {
693
868
  return revisionOf(e.version ?? Number(t) + 1);
694
869
  }
695
- //#endregion
696
- //#region src/source.ts
697
- function viewSourceOf(e) {
698
- return {
699
- async paged(t, n, r) {
700
- let i = await e.paged(t, optionsOf(r));
701
- return {
702
- total: i.total ?? i.list.length,
703
- list: [...i.list]
704
- };
705
- },
706
- async cursor(t, n, r) {
707
- let i = await e.cursor(t, optionsOf(r));
708
- return {
709
- list: i.list,
710
- nextCursor: i.nextCursor
711
- };
712
- },
713
- aggregate(t, n, r) {
714
- return e.aggregate(t, optionsOf(r));
715
- },
716
- async describe(t, n, r) {
717
- let i = await e.describe(t, optionsOf(r));
718
- return i.notModified ? i : {
719
- notModified: !1,
720
- descriptor: i.descriptor,
721
- version: i.version ?? i.descriptor.version
722
- };
723
- }
724
- };
725
- }
870
+ // src/source.ts
726
871
  function datasetCatalogOf(e) {
727
872
  return {
728
- async list() {
729
- return (await e.list()).map((e) => ({
730
- contextName: e.context,
731
- name: e.dataset,
732
- title: e.title ?? null,
733
- version: B
873
+ async list(t) {
874
+ return (await e.list(t)).map((e) => ({
875
+ context: e.context,
876
+ dataset: e.dataset,
877
+ ...e.title ? { title: e.title } : {}
734
878
  }));
735
879
  },
736
- source: (t) => viewSourceOf(e.dataset(t.contextName, t.name))
880
+ source: (t) => e.dataset(t.context, t.dataset)
737
881
  };
738
882
  }
739
- var B = "listed";
740
- function optionsOf(e) {
741
- return e === void 0 ? {} : { signal: e.signal };
742
- }
743
- //#endregion
744
- export { g as SHARED_OWNER_ID, A as SHARED_SCOPE, _ as SYSTEM_OWNER_ID, j as SYSTEM_SCOPE, v as SYSTEM_TENANT_ID, WowDatasetWordings, WowViewStore, D as WowViewStoreErrorCodes, datasetCatalogOf, viewSourceOf };
883
+ export { N as SHARED_SCOPE, P as SYSTEM_SCOPE, WowDatasetWordings, WowViewStore, j as WowViewStoreErrorCodes, datasetCatalogOf };
745
884
 
746
885
  //# sourceMappingURL=index.es.js.map