@ahoo-wang/wow-view-store 10.0.0-alpha.6 → 10.0.0-alpha.7
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 +11 -12
- package/README.zh-CN.md +10 -11
- package/dist/datasetWordings.d.ts +5 -5
- package/dist/errors.d.ts +10 -4
- package/dist/generated/view-store/client.d.ts +38 -0
- package/dist/generated/view-store/contract.d.ts +58 -0
- package/dist/generated/view-store/dataset_wording/aggregate.d.ts +3 -3
- package/dist/generated/view-store/dataset_wording/commandClient.d.ts +3 -10
- package/dist/generated/view-store/index.d.ts +4 -1
- package/dist/generated/view-store/manifest.d.ts +3 -0
- package/dist/generated/view-store/routes.d.ts +22 -0
- package/dist/generated/view-store/types.d.ts +29 -3
- package/dist/generated/view-store/view/aggregate.d.ts +3 -3
- package/dist/generated/view-store/view/commandClient.d.ts +3 -12
- package/dist/generated/view-store/view_preferences/aggregate.d.ts +3 -3
- package/dist/generated/view-store/view_preferences/commandClient.d.ts +3 -8
- package/dist/index.d.ts +2 -3
- package/dist/index.es.js +425 -286
- package/dist/index.es.js.map +1 -1
- package/dist/paths.d.ts +11 -19
- package/dist/source.d.ts +12 -36
- package/dist/views.d.ts +19 -34
- package/dist/wire.d.ts +8 -4
- package/dist/wowViewStore.d.ts +40 -33
- package/package.json +8 -8
- package/dist/generated/view-store/boundedContext.d.ts +0 -36
- package/dist/systemViews.d.ts +0 -21
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","names":["LIST_LIMIT","optionsOf","__defProp","target","SHARED_OWNER_ID","SYSTEM_OWNER_ID","SYSTEM_TENANT_ID","REMEMBERED_WRITES","limit","key","value","view","version","body","preferences","order","defaultInstanceId","autoRun","lastTabs","VIEW_STORE_BOUNDED_CONTEXT","ViewStoreErrorCodes","viewStoreWait","wait","subscription","ViewAggregate","ViewCommandPaths","CommandGateway","options","id","LifecycleCommands","SnapshotQueryClient","StateClient","ViewPreferencesCommandPaths","ViewPreferencesAggregate","WowViewStoreErrorCodes","CODES","FrameworkErrorCodes","cause","problem","code","known","ViewStoreError","error","toWowProblemError","boards","extensions","board","title","run","thrown","isViewStoreError","message","name","SYSTEM_VIEWS_PATH","fetcher","definitionId","signal","url","SHARED_SCOPE","SYSTEM_SCOPE","place","SUMMARY_FIELDS","state","LIST_LIMIT$1","REMEMBERED_SYSTEM_REVISIONS","AUDIENCE_WAIT","client","query","listQuery","filter","asc","personal","shared","system","seen","summary","record","AUDIENCE_RANK","a","b","input","write","config","result","context","revision","audience","singleQuery","emptyPreferences","remembered","relocated","plan","found","landsAt","read","instance","failure","isSystemInstanceId","first","more","scope","ownerId","DatasetWordingCommandPaths","DatasetWordingAggregate","LIST_LIMIT","snapshots","wording","page","abort","previous","entry","LISTED"],"sources":["../src/paths.ts","../src/remembered.ts","../src/views.ts","../src/generated/view-store/boundedContext.ts","../src/generated/view-store/view/aggregate.ts","../src/generated/view-store/view/commandClient.ts","../src/generated/view-store/view/queryClient.ts","../src/generated/view-store/view_preferences/commandClient.ts","../src/generated/view-store/view_preferences/aggregate.ts","../src/generated/view-store/view_preferences/queryClient.ts","../src/errors.ts","../src/systemViews.ts","../src/wire.ts","../src/wowViewStore.ts","../src/generated/view-store/dataset_wording/commandClient.ts","../src/generated/view-store/dataset_wording/aggregate.ts","../src/generated/view-store/dataset_wording/queryClient.ts","../src/datasetWordings.ts","../src/source.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The reserved owner of shared views and shared preferences\n * (`ViewStoreService.SHARED_OWNER_ID` on the server). The parentheses keep it\n * apart from every user id, so a path whose owner segment is `(shared)` is the\n * shared audience's.\n *\n * A host nobody signs in to fills `{ownerId}` with it by default (its own\n * request interceptor), and then has shared views and shared preferences\n * only.\n */\nexport const SHARED_OWNER_ID = '(shared)';\n\n/**\n * The reserved owner of stored system views\n * (`ViewStoreService.SYSTEM_OWNER_ID` on the server).\n */\nexport const SYSTEM_OWNER_ID = '(system)';\n\n/**\n * The one tenant stored system views live under\n * (`ViewStoreService.SYSTEM_TENANT_ID`): the value of CoSec's platform\n * tenant, not the default tenant `(0)`. System views are global, so the\n * store writes them on `tenant/(platform)/owner/(system)` whatever the\n * caller's own tenant, and the security gateway decides who may, by that\n * path.\n */\nexport const SYSTEM_TENANT_ID = '(platform)';\n\n/**\n * Where a view lives on the server: the owner segment of its path. `personal`\n * leaves `{ownerId}` to the fetcher's interceptors (fetcher-cosec's resource\n * attribution fills it from the token's `sub`); `shared` names\n * {@link SHARED_OWNER_ID}, which the interceptors never replace; `system`\n * names both the tenant and the owner of stored system views,\n * {@link SYSTEM_TENANT_ID} and {@link SYSTEM_OWNER_ID}.\n */\nexport type Place = 'personal' | 'shared' | 'system';\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** How many writes a store remembers the outcome of, unless told otherwise. */\nconst REMEMBERED_WRITES = 256;\n\n/** A bounded memory by key: the oldest entry goes first. */\nexport class Remembered<T> {\n private readonly entries = new Map<string, T>();\n\n constructor(private readonly limit = REMEMBERED_WRITES) {}\n\n get(key: string): T | undefined {\n return this.entries.get(key);\n }\n\n has(key: string): boolean {\n return this.entries.has(key);\n }\n\n set(key: string, value: T): void {\n this.entries.delete(key);\n this.entries.set(key, value);\n if (this.entries.size > this.limit)\n this.entries.delete(this.entries.keys().next().value!);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * The server's shapes, as far as the store reads them, and their reading as\n * the port's. The server stores the engine's `ViewConfig` whole and never\n * reads its meaning, so a config comes back exactly as it was saved.\n */\n\nimport type {\n ViewConfig,\n ViewInstance,\n ViewInstanceSummary,\n ViewKind,\n ViewPreferences,\n} from '@ahoo-wang/wow-view-engine';\n\n/** A system view the server serves (`SystemView`); `scope` is always `system`. */\nexport interface SystemViewBody {\n id: string;\n definitionId: string;\n title: string;\n kind: ViewKind;\n /** A hash of its content, whatever its source. */\n revision: string;\n config: ViewConfig;\n /**\n * `configured` (read-only) or `stored` (a view of `tenant/(platform)/owner/(system)`,\n * written through the view routes); absent from a server before it,\n * which served configured views only.\n */\n source?: 'configured' | 'stored';\n /** A stored view's aggregate version, which its writes expect. */\n version?: number | null;\n}\n\n/**\n * Whether the server stores `view` (else it configures it). A stored one\n * carries the port's `stored: true` (D81), the views an `editSystem`\n * permission may write; configured and code system views carry none.\n */\nexport function isStored(view: SystemViewBody): boolean {\n return view.source === 'stored' && typeof view.version === 'number';\n}\n\n/** One owner's preferences in one definition (`ViewPreferencesView`). */\nexport interface PreferencesBody {\n definitionId: string;\n order?: string[] | null;\n defaultInstanceId?: string | null;\n autoRun?: boolean | null;\n lastTabs?: Record<string, string> | null;\n /** `0` for preferences never written. */\n version: number;\n}\n\n/** A snapshot's revision: the aggregate's version, compared as a string. */\nexport function revisionOf(version: number): string {\n return String(version);\n}\n\nexport function systemInstance(view: SystemViewBody): ViewInstance {\n return {\n id: view.id,\n definitionId: view.definitionId,\n title: view.title,\n scope: 'system',\n revision: view.revision,\n config: view.config,\n ...(isStored(view) ? { stored: true as const } : {}),\n };\n}\n\nexport function systemSummary(view: SystemViewBody): ViewInstanceSummary {\n return {\n id: view.id,\n definitionId: view.definitionId,\n title: view.title,\n scope: 'system',\n kind: view.kind,\n revision: view.revision,\n ...(isStored(view) ? { stored: true as const } : {}),\n };\n}\n\n/**\n * The port's preferences. A member the server holds as `null` is one never\n * set: `defaultInstanceId` reads as `null`, and `autoRun` and `lastTabs` are\n * left out, as the port's own `emptyPreferences()` leaves them.\n */\nexport function toPreferences(body: PreferencesBody): ViewPreferences {\n return preferencesAt(\n {\n order: body.order ?? [],\n defaultInstanceId: body.defaultInstanceId ?? null,\n autoRun: body.autoRun ?? undefined,\n lastTabs: body.lastTabs ?? undefined,\n },\n body.version,\n );\n}\n\n/** What a preferences write sends: everything but the revision. */\nexport function preferencesInput(\n preferences: Omit<ViewPreferences, 'revision'>,\n): Omit<ViewPreferences, 'revision'> {\n const { order, defaultInstanceId, autoRun, lastTabs } = preferences;\n return {\n order: [...order],\n defaultInstanceId: defaultInstanceId ?? null,\n ...(autoRun === undefined ? {} : { autoRun }),\n ...(lastTabs === undefined ? {} : { lastTabs: { ...lastTabs } }),\n };\n}\n\n/** `preferences` as written at `version`, in the port's shape. */\nexport function preferencesAt(\n preferences: Omit<ViewPreferences, 'revision'>,\n version: number,\n): ViewPreferences {\n return { ...preferencesInput(preferences), revision: revisionOf(version) };\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { type Hop, wait } from '@ahoo-wang/wow-client';\n\n/**\n * The bounded context `view-store`.\n * The view engine's saved views, view preferences and dataset wording\n */\nexport const VIEW_STORE_BOUNDED_CONTEXT = 'view-store';\n\n/** The domain error codes of `view-store`, each a problem's `code` with the status the Manifest gives it. */\nexport const ViewStoreErrorCodes = {\n /** 400: The request carries no CoSec-App-Id. */\n APP_REQUIRED: 'view-store.app-required',\n /** 400: The request is not a valid write: its config, title, preferences or wording. */\n INVALID: 'view-store.invalid',\n /** 404: The aggregate belongs to another application, which reads as none. */\n NOT_FOUND: 'view-store.not-found',\n /** 400: A view is saved by an owner: a user, (shared), or (system) under (platform). */\n OWNER_REQUIRED: 'view-store.owner-required',\n /** 409: A shared dashboard shows the view, which stays shared. */\n REFERENCED_BY_SHARED_DASHBOARD: 'view-store.referenced-by-shared-dashboard',\n /** 403: A system view never moves audience: it is neither shared nor claimed. */\n SYSTEM_VIEW_READ_ONLY: 'view-store.system-view-read-only',\n} as const;\n\n/** A {@link ViewStoreErrorCodes} value. */\nexport type ViewStoreErrorCode = (typeof ViewStoreErrorCodes)[keyof typeof ViewStoreErrorCodes];\n\n/** The subscriptions of `view-store` a `handled` hop names. */\nexport type ViewStoreSubscription = 'ViewAudienceSaga.onAudienceChanged';\n\n/** The hops of a wait chain (`Wow-Wait`) in `view-store`. */\nexport const viewStoreWait = {\n /** Until a command of `view-store` passed admission. */\n accepted: (): Hop => wait.accepted(VIEW_STORE_BOUNDED_CONTEXT),\n /** Until a command's events are appended to the log of `view-store`. */\n committed: (): Hop => wait.committed(VIEW_STORE_BOUNDED_CONTEXT),\n /** Until the snapshot of `view-store` holds the commit. */\n snapshot: (): Hop => wait.snapshot(VIEW_STORE_BOUNDED_CONTEXT),\n /** Until a subscription of `view-store` handled the commit. */\n handled: (subscription: ViewStoreSubscription): Hop => wait.handled(subscription, VIEW_STORE_BOUNDED_CONTEXT),\n} as const;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { EventView, SystemEvent } from '@ahoo-wang/wow-client';\nimport type { ViewAudienceChanged, ViewClaimed, ViewCreated, ViewRenamed, ViewSaved, ViewShared } from '../types.js';\n\n/**\n * The aggregate `view-store.view`.\n * A saved view of the view engine: a record view, an analysis view or a dashboard\n */\nexport const ViewAggregate = {\n context: 'view-store',\n name: 'view',\n path: '/view-store/view',\n ownership: 'OWNER',\n snapshot: true,\n} as const;\n\n/** The `state.*` paths of `view`'s snapshots a query filters, sorts and projects on. */\nexport type ViewStateField = 'state.appId' | 'state.audience' | 'state.config' | 'state.definitionId' | 'state.kind' | 'state.title';\n\n/** The events of `view`, named as the server sends them, `view-store.view.<Event>` at its current revision (the `events` query upgrades older records), and the system events every aggregate has. */\nexport type ViewEvent = EventView<'view-store.view.ViewAudienceChanged', ViewAudienceChanged> | EventView<'view-store.view.ViewClaimed', ViewClaimed> | EventView<'view-store.view.ViewCreated', ViewCreated> | EventView<'view-store.view.ViewRenamed', ViewRenamed> | EventView<'view-store.view.ViewSaved', ViewSaved> | EventView<'view-store.view.ViewShared', ViewShared> | SystemEvent;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { CommandGateway, type CommandOptions, type CommandResult, type CommandResultStream, type CreateCommandOptions, LifecycleCommands, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { ClaimView, CreateView, RenameView, SaveView, ShareView, WowLifecycleTransferOwner } from '../types.js';\nimport { ViewAggregate } from './aggregate.js';\n\n/** The command routes of `view-store.view`. */\nexport const ViewCommandPaths = {\n CLAIM_VIEW: '/view-store/view/{id}/claim-view',\n CREATE_VIEW: '/view-store/view/{id}/create-view',\n CREATE_VIEW_WITHOUT_ID: '/view-store/view/create-view',\n RENAME_VIEW: '/view-store/view/{id}/rename-view',\n SAVE_VIEW: '/view-store/view/{id}/save-view',\n SHARE_VIEW: '/view-store/view/{id}/share-view',\n} as const;\n\n/** Sends the commands of `view-store.view`; a command that did not succeed rejects with a `WowProblemError` holding its result. */\nexport class ViewCommandClient {\n readonly gateway: CommandGateway;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.gateway = new CommandGateway(options);\n }\n\n /**\n * Make a shared view personal\n * `ClaimView`: `POST /view-store/view/{id}/claim-view`.\n * Produces `ViewClaimed`.\n */\n claimView(id: string, body: ClaimView = {}, options?: CommandOptions): Promise<CommandResult> {\n return this.gateway.send(ViewCommandPaths.CLAIM_VIEW, body, { ...options, id });\n }\n\n /** `ClaimView`, answered as one result per hop of its wait (`text/event-stream`). */\n claimViewStream(id: string, body: ClaimView = {}, options?: CommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(ViewCommandPaths.CLAIM_VIEW, body, { ...options, id });\n }\n\n /**\n * Create a view\n * `CreateView`: `POST /view-store/view/{id}/create-view`, `POST /view-store/view/create-view`.\n * Creates the aggregate.\n * Produces `ViewCreated`.\n */\n createView(body: CreateView, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.gateway.send(options?.id === undefined ? ViewCommandPaths.CREATE_VIEW_WITHOUT_ID : ViewCommandPaths.CREATE_VIEW, body, options);\n }\n\n /** `CreateView`, answered as one result per hop of its wait (`text/event-stream`). */\n createViewStream(body: CreateView, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(options?.id === undefined ? ViewCommandPaths.CREATE_VIEW_WITHOUT_ID : ViewCommandPaths.CREATE_VIEW, body, options);\n }\n\n /**\n * Rename a view\n * `RenameView`: `POST /view-store/view/{id}/rename-view`.\n * Produces `ViewRenamed`.\n */\n renameView(id: string, body: RenameView, options?: CommandOptions): Promise<CommandResult> {\n return this.gateway.send(ViewCommandPaths.RENAME_VIEW, body, { ...options, id });\n }\n\n /** `RenameView`, answered as one result per hop of its wait (`text/event-stream`). */\n renameViewStream(id: string, body: RenameView, options?: CommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(ViewCommandPaths.RENAME_VIEW, body, { ...options, id });\n }\n\n /**\n * Save a view's config\n * `SaveView`: `POST /view-store/view/{id}/save-view`.\n * Produces `ViewSaved`.\n */\n saveView(id: string, body: SaveView, options?: CommandOptions): Promise<CommandResult> {\n return this.gateway.send(ViewCommandPaths.SAVE_VIEW, body, { ...options, id });\n }\n\n /** `SaveView`, answered as one result per hop of its wait (`text/event-stream`). */\n saveViewStream(id: string, body: SaveView, options?: CommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(ViewCommandPaths.SAVE_VIEW, body, { ...options, id });\n }\n\n /**\n * Make a view shared\n * `ShareView`: `POST /view-store/view/{id}/share-view`.\n * Produces `ViewShared`.\n */\n shareView(id: string, body: ShareView = {}, options?: CommandOptions): Promise<CommandResult> {\n return this.gateway.send(ViewCommandPaths.SHARE_VIEW, body, { ...options, id });\n }\n\n /** `ShareView`, answered as one result per hop of its wait (`text/event-stream`). */\n shareViewStream(id: string, body: ShareView = {}, options?: CommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(ViewCommandPaths.SHARE_VIEW, body, { ...options, id });\n }\n\n /**\n * Marks the aggregate deleted; its events stay in the log.\n * The lifecycle command `wow.lifecycle.DeleteAggregate`.\n */\n deleteAggregate(id: string, options?: CommandOptions): Promise<CommandResult> {\n return this.gateway.lifecycle(ViewAggregate.path, id, LifecycleCommands.DELETE_AGGREGATE, undefined, options);\n }\n\n /** The lifecycle command `wow.lifecycle.TransferOwner`. */\n transferOwner(id: string, body: WowLifecycleTransferOwner, options?: CommandOptions): Promise<CommandResult> {\n return this.gateway.lifecycle(ViewAggregate.path, id, LifecycleCommands.TRANSFER_OWNER, body, options);\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { EventQueryClient, SnapshotQueryClient, StateClient, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { ViewState } from '../types.js';\nimport { ViewAggregate, type ViewEvent, type ViewStateField } from './aggregate.js';\n\n/** Queries the snapshots of `view-store.view`: `POST /view-store/view/snapshot/query`. */\nexport class ViewSnapshotQueryClient extends SnapshotQueryClient<ViewState, ViewStateField> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewAggregate, options);\n }\n}\n\n\n/** Queries the event streams of `view-store.view`, one record per commit: `POST /view-store/view/events/query`. */\nexport class ViewEventQueryClient extends EventQueryClient<ViewEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewAggregate, options);\n }\n}\n\n\n/** Reads the states of `view-store.view`, at a version or a time, and their traces: `GET /view-store/view/{id}/state`. */\nexport class ViewStateClient extends StateClient<ViewState, ViewEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewAggregate, options);\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { CommandGateway, type CommandResult, type CommandResultStream, type CreateCommandOptions, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { SetViewPreferences } from '../types.js';\n\n/** The command routes of `view-store.view_preferences`. */\nexport const ViewPreferencesCommandPaths = {\n SET_VIEW_PREFERENCES: '/view-store/view_preferences/{id}/set-view-preferences',\n SET_VIEW_PREFERENCES_WITHOUT_ID: '/view-store/view_preferences/set-view-preferences',\n} as const;\n\n/** Sends the commands of `view-store.view_preferences`; a command that did not succeed rejects with a `WowProblemError` holding its result. */\nexport class ViewPreferencesCommandClient {\n readonly gateway: CommandGateway;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.gateway = new CommandGateway(options);\n }\n\n /**\n * Set the view preferences of a definition\n * `SetViewPreferences`: `POST /view-store/view_preferences/{id}/set-view-preferences`, `POST /view-store/view_preferences/set-view-preferences`.\n * Creates the aggregate, or acts on the one that exists.\n * Produces `ViewPreferencesSet`.\n */\n setViewPreferences(body: SetViewPreferences, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.gateway.send(options?.id === undefined ? ViewPreferencesCommandPaths.SET_VIEW_PREFERENCES_WITHOUT_ID : ViewPreferencesCommandPaths.SET_VIEW_PREFERENCES, body, options);\n }\n\n /** `SetViewPreferences`, answered as one result per hop of its wait (`text/event-stream`). */\n setViewPreferencesStream(body: SetViewPreferences, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(options?.id === undefined ? ViewPreferencesCommandPaths.SET_VIEW_PREFERENCES_WITHOUT_ID : ViewPreferencesCommandPaths.SET_VIEW_PREFERENCES, body, options);\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { EventView, SystemEvent } from '@ahoo-wang/wow-client';\nimport type { ViewPreferencesSet } from '../types.js';\n\n/**\n * The aggregate `view-store.view_preferences`.\n * One owner's view preferences for one definition in one application\n */\nexport const ViewPreferencesAggregate = {\n context: 'view-store',\n name: 'view_preferences',\n path: '/view-store/view_preferences',\n ownership: 'OWNER',\n snapshot: true,\n} as const;\n\n/** The `state.*` paths of `view_preferences`'s snapshots a query filters, sorts and projects on. */\nexport type ViewPreferencesStateField = 'state.appId' | 'state.autoRun' | 'state.defaultInstanceId' | 'state.definitionId' | 'state.lastTabs' | 'state.order';\n\n/** The events of `view_preferences`, named as the server sends them, `view-store.view_preferences.<Event>` at its current revision (the `events` query upgrades older records), and the system events every aggregate has. */\nexport type ViewPreferencesEvent = EventView<'view-store.view_preferences.ViewPreferencesSet', ViewPreferencesSet> | SystemEvent;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { EventQueryClient, SnapshotQueryClient, StateClient, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { ViewPreferencesState } from '../types.js';\nimport { ViewPreferencesAggregate, type ViewPreferencesEvent, type ViewPreferencesStateField } from './aggregate.js';\n\n/** Queries the snapshots of `view-store.view_preferences`: `POST /view-store/view_preferences/snapshot/query`. */\nexport class ViewPreferencesSnapshotQueryClient extends SnapshotQueryClient<ViewPreferencesState, ViewPreferencesStateField> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewPreferencesAggregate, options);\n }\n}\n\n\n/** Queries the event streams of `view-store.view_preferences`, one record per commit: `POST /view-store/view_preferences/events/query`. */\nexport class ViewPreferencesEventQueryClient extends EventQueryClient<ViewPreferencesEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewPreferencesAggregate, options);\n }\n}\n\n\n/** Reads the states of `view-store.view_preferences`, at a version or a time, and their traces: `GET /view-store/view_preferences/{id}/state`. */\nexport class ViewPreferencesStateClient extends StateClient<ViewPreferencesState, ViewPreferencesEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewPreferencesAggregate, options);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FrameworkErrorCodes,\n toWowProblemError,\n type WowProblemError,\n} from '@ahoo-wang/wow-client';\nimport {\n isViewStoreError,\n ViewStoreError,\n type ViewStoreErrorCode,\n} from '@ahoo-wang/wow-view-engine';\nimport { ViewStoreErrorCodes } from './generated/view-store/boundedContext.js';\n\n/**\n * The V10 view store's own problem codes (`ViewStoreRejections` of\n * `platform/view-store`), beside the framework's (`FrameworkErrorCodes` of\n * `@ahoo-wang/wow-client`): generated from the service's Manifest.\n *\n * Named apart from the engine's `ViewStoreErrorCode` (the port's codes):\n * these are the `code` of the server's problems, which a `ViewStoreError`\n * carries as `detail.code`.\n */\nexport const WowViewStoreErrorCodes = ViewStoreErrorCodes;\n\n/** The port's code of each problem code the server answers with. */\nconst CODES: Readonly<Record<string, ViewStoreErrorCode>> = {\n [FrameworkErrorCodes.AGGREGATE_VERSION_MISMATCH]: 'CONFLICT',\n // A request id another command already used: the write cannot be told\n // from that one, so it is refused as the stale write it most likely is.\n [FrameworkErrorCodes.COMMAND_REQUEST_ID_REUSED]: 'CONFLICT',\n [FrameworkErrorCodes.AGGREGATE_NOT_FOUND]: 'NOT_FOUND',\n [FrameworkErrorCodes.QUERY_NOT_FOUND]: 'NOT_FOUND',\n [FrameworkErrorCodes.AGGREGATE_DELETED]: 'NOT_FOUND',\n [ViewStoreErrorCodes.NOT_FOUND]: 'NOT_FOUND',\n [FrameworkErrorCodes.AUTH_UNAUTHENTICATED]: 'FORBIDDEN',\n [FrameworkErrorCodes.AUTH_FORBIDDEN]: 'FORBIDDEN',\n [FrameworkErrorCodes.AGGREGATE_FORBIDDEN]: 'FORBIDDEN',\n [ViewStoreErrorCodes.SYSTEM_VIEW_READ_ONLY]: 'FORBIDDEN',\n [ViewStoreErrorCodes.INVALID]: 'INVALID',\n [ViewStoreErrorCodes.APP_REQUIRED]: 'INVALID',\n [ViewStoreErrorCodes.OWNER_REQUIRED]: 'INVALID',\n [ViewStoreErrorCodes.REFERENCED_BY_SHARED_DASHBOARD]: 'INVALID',\n [FrameworkErrorCodes.AGGREGATE_EXISTS]: 'INVALID',\n [FrameworkErrorCodes.COMMAND_MALFORMED]: 'INVALID',\n [FrameworkErrorCodes.COMMAND_INVALID]: 'INVALID',\n [FrameworkErrorCodes.COMMAND_UNHANDLED]: 'INVALID',\n [FrameworkErrorCodes.WAIT_INVALID]: 'INVALID',\n [FrameworkErrorCodes.QUERY_MALFORMED]: 'INVALID',\n [FrameworkErrorCodes.QUERY_INVALID]: 'INVALID',\n};\n\n/**\n * A request that did not succeed, as the store reads it: the server's\n * problem when it answered with one, else what the request threw.\n */\nexport class Failure {\n constructor(\n /** What the request threw. */\n readonly cause: unknown,\n /** The server's problem, when a response came back. */\n readonly problem?: WowProblemError,\n ) {}\n\n /** The problem's code: a framework code (`wow.*`) or the view store's. */\n get problemCode(): string | undefined {\n return this.problem?.code;\n }\n\n /**\n * The port's code, **by the problem's code first**: one HTTP status\n * carries several decisions (a `400` is a bad title and a missing\n * application alike). Only an answer without a code the store knows — a\n * gateway's own page, a proxy, a code a later server adds — falls back to\n * the status; a problem the service says a retry may get past is\n * `UNAVAILABLE` whatever its status. A `404` without a code is a route the server does not serve:\n * no view store there (or, on the memory backend, no snapshot query), so\n * `UNSUPPORTED`. No answer at all is `UNAVAILABLE`: the outcome is\n * unknown, and a retry under the same request id is safe, since the\n * server deduplicates it.\n */\n get code(): ViewStoreErrorCode {\n const code = this.problemCode;\n const known = code === undefined ? undefined : CODES[code];\n if (known) return known;\n // What a retry may get past (a busy or closing node, a store out of\n // reach, contended writers, a wait that ran out): the outcome is unknown.\n if (this.problem?.retry.retryable) return 'UNAVAILABLE';\n switch (this.problem?.status) {\n case 400:\n case 422:\n return 'INVALID';\n case 401:\n case 403:\n return 'FORBIDDEN';\n case 404:\n return code === undefined ? 'UNSUPPORTED' : 'NOT_FOUND';\n case 410:\n return 'NOT_FOUND';\n case 409:\n case 412:\n return 'CONFLICT';\n default:\n return 'UNAVAILABLE';\n }\n }\n\n /** Whether the server (or something in front of it) answered at all. */\n get reached(): boolean {\n return this.problem !== undefined;\n }\n\n get message(): string {\n if (this.problem) return this.problem.message;\n return `The view store could not be reached: ${reasonOf(this.cause)}`;\n }\n\n /** The port's error, holding what it was read from. */\n toStoreError(): ViewStoreError {\n return new ViewStoreError(this.code, this.message, this.held());\n }\n\n /**\n * What {@link toStoreError} holds, for an error of another code: the\n * request's own failure as `cause`, the problem's code as `detail` (a\n * host tells `view-store.app-required` from `view-store.invalid` by it),\n * and for `UNAVAILABLE` whether the server answered (`reachable`).\n */\n held(): {\n cause: unknown;\n detail?: { code: string };\n reachable?: true;\n } {\n const code = this.problemCode;\n return {\n cause: this.cause,\n ...(code === undefined ? {} : { detail: { code } }),\n ...(this.code === 'UNAVAILABLE' && this.reached\n ? { reachable: true as const }\n : {}),\n };\n }\n}\n\n/** What a failed request threw, read as a {@link Failure}. */\nexport async function failureOf(error: unknown): Promise<Failure> {\n if (error instanceof Failure) return error;\n return new Failure(error, await toWowProblemError(error));\n}\n\n/**\n * The titles of the shared dashboards a claim refusal names: the problem's\n * `boards` extension member, a list of `{ id, title }` (decision D211). A\n * board without a title is named by its id; anything else is skipped.\n */\nexport function boardTitles(\n extensions: Readonly<Record<string, unknown>> | undefined,\n): string[] {\n const boards = extensions?.boards;\n if (!Array.isArray(boards)) return [];\n return boards.flatMap((board: unknown) => {\n if (typeof board !== 'object' || board === null) return [];\n const { id, title } = board as { id?: unknown; title?: unknown };\n if (typeof title === 'string' && title.trim() !== '') return [title];\n return typeof id === 'string' ? [id] : [];\n });\n}\n\n/**\n * Runs one of the port's methods, so that everything it rejects with is a\n * `ViewStoreError`: a failed request as its code says, anything else — a\n * body that did not parse — as `UNAVAILABLE`, the outcome unknown.\n */\nexport async function guard<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (thrown) {\n if (thrown instanceof Failure) throw thrown.toStoreError();\n if (isViewStoreError(thrown)) throw thrown;\n // A body that did not parse came back from something — a login wall's\n // page, a proxy's: answered, so not \"could not be reached\".\n throw new ViewStoreError(\n 'UNAVAILABLE',\n thrown instanceof Error ? thrown.message : String(thrown),\n {\n cause: thrown,\n ...(thrown instanceof SyntaxError ? { reachable: true as const } : {}),\n },\n );\n }\n}\n\n/** Runs one request, so that what it throws is a {@link Failure}. */\nexport async function request<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (error) {\n // A body that did not parse is no failed request: `guard` reads it.\n if (error instanceof SyntaxError) throw error;\n throw await failureOf(error);\n }\n}\n\n/** What a refusal said; a `DOMException` is an `Error` only in some realms. */\nfunction reasonOf(error: unknown): string {\n if (typeof error === 'object' && error !== null) {\n const { name, message } = error as { name?: unknown; message?: unknown };\n if (typeof message === 'string')\n return typeof name === 'string' ? `${name}: ${message}` : message;\n }\n return String(error);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Fetcher } from '@ahoo-wang/fetcher';\nimport type { SystemViewBody } from './views.js';\nimport { request } from './errors.js';\n\n/**\n * The system views route, `GET /view-store/system-views[/{id}]`: the\n * service's own route, ordered before Wow's and outside the Manifest, so no\n * client is generated for it. It answers the configured system views of the\n * caller's tenant and application and the stored ones, in the 9.x\n * `SystemView` shape; the tenant is the principal's, the application the\n * request's `CoSec-App-Id`.\n */\nexport const SYSTEM_VIEWS_PATH = '/view-store/system-views';\n\n/** The system views route, through the store's fetcher. */\nexport class SystemViewsClient {\n constructor(private readonly fetcher: Fetcher) {}\n\n /** The definition's system views: the configured ones first, in their order. */\n list(definitionId: string, signal?: AbortSignal): Promise<SystemViewBody[]> {\n return this.get(\n `${SYSTEM_VIEWS_PATH}?definitionId=${encodeURIComponent(definitionId)}`,\n signal,\n );\n }\n\n /** One system view; `404 view-store.not-found` for none. */\n one(id: string, signal?: AbortSignal): Promise<SystemViewBody> {\n return this.get(`${SYSTEM_VIEWS_PATH}/${encodeURIComponent(id)}`, signal);\n }\n\n private get<T>(url: string, signal: AbortSignal | undefined): Promise<T> {\n return request(async () => {\n const response = await this.fetcher.fetch(url, {\n method: 'GET',\n ...(signal === undefined ? {} : { signal }),\n });\n return (await response.json()) as T;\n });\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * The V10 view store's shapes, as far as the store reads them, and their\n * reading as the port's. The server stores the engine's `ViewConfig` whole\n * and never reads its meaning; it keeps the config's `kind` beside it, as\n * `state.kind`, which a list projects and filters on.\n */\n\nimport type { TargetScope } from '@ahoo-wang/wow-client';\nimport type {\n DatasetOverrides,\n ViewConfig,\n ViewInstance,\n ViewInstanceSummary,\n} from '@ahoo-wang/wow-view-engine';\nimport { revisionOf } from './views.js';\nimport {\n SHARED_OWNER_ID,\n SYSTEM_OWNER_ID,\n SYSTEM_TENANT_ID,\n type Place,\n} from './paths.js';\nimport type {\n DatasetWordingState,\n ViewState,\n} from './generated/view-store/types.js';\n\n/** The `Wow-Scope` of the shared views: the reserved owner `(shared)`. */\nexport const SHARED_SCOPE: TargetScope = Object.freeze({\n ownerId: SHARED_OWNER_ID,\n});\n\n/** The `Wow-Scope` of the stored system views: `(system)` of `(platform)`. */\nexport const SYSTEM_SCOPE: TargetScope = Object.freeze({\n tenantId: SYSTEM_TENANT_ID,\n ownerId: SYSTEM_OWNER_ID,\n});\n\n/**\n * The `Wow-Scope` a request at `place` carries: none for the caller's own\n * views, whose owner the server takes from the principal.\n */\nexport function scopeAt(place: Place): TargetScope | undefined {\n switch (place) {\n case 'shared':\n return SHARED_SCOPE;\n case 'system':\n return SYSTEM_SCOPE;\n default:\n return undefined;\n }\n}\n\n/** A view's snapshot or state as the store reads it: its id, version and state. */\nexport interface ViewRecord {\n id: string;\n version: number;\n state: Pick<ViewState, 'definitionId' | 'title' | 'audience'> &\n Partial<Pick<ViewState, 'kind' | 'config'>>;\n}\n\n/** The fields a list reads, and of the config only its `kind`, kept apart. */\nexport const SUMMARY_FIELDS = [\n 'aggregateId',\n 'version',\n 'state.definitionId',\n 'state.title',\n 'state.audience',\n 'state.kind',\n] as const;\n\nexport function toInstance({ id, version, state }: ViewRecord): ViewInstance {\n return {\n id,\n definitionId: state.definitionId,\n title: state.title,\n scope: state.audience,\n revision: revisionOf(version),\n config: state.config as unknown as ViewConfig,\n };\n}\n\nexport function toSummary({\n id,\n version,\n state,\n}: ViewRecord): ViewInstanceSummary {\n return {\n id,\n definitionId: state.definitionId,\n title: state.title,\n scope: state.audience,\n kind: state.kind!,\n revision: revisionOf(version),\n };\n}\n\n/** The engine's overrides from a stored wording: what is stored, nothing more. */\nexport function wordingOf(\n state: Pick<DatasetWordingState, 'title' | 'recordNoun' | 'fields'>,\n): DatasetOverrides {\n return {\n ...(state.title == null ? {} : { title: state.title }),\n ...(state.recordNoun == null ? {} : { recordNoun: state.recordNoun }),\n ...(state.fields == null\n ? {}\n : { fields: state.fields as DatasetOverrides['fields'] }),\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Fetcher } from '@ahoo-wang/fetcher';\nimport { asc, filter, listQuery, singleQuery } from '@ahoo-wang/wow-client/dsl';\nimport {\n FrameworkErrorCodes,\n type CommandOptions,\n type CommandResult,\n type WowClientOptions,\n} from '@ahoo-wang/wow-client';\nimport {\n emptyPreferences,\n isSystemInstanceId,\n ViewStoreError,\n type ViewAudience,\n type ViewConfig,\n type ViewInstance,\n type ViewInstanceSummary,\n type ViewPermissions,\n type ViewPreferences,\n type ViewStore,\n type WriteContext,\n} from '@ahoo-wang/wow-view-engine';\nimport { SHARED_OWNER_ID, SYSTEM_OWNER_ID, type Place } from './paths.js';\nimport { Remembered } from './remembered.js';\nimport {\n isStored,\n preferencesAt,\n preferencesInput,\n systemInstance,\n systemSummary,\n toPreferences,\n type SystemViewBody,\n} from './views.js';\nimport {\n ViewStoreErrorCodes,\n viewStoreWait,\n} from './generated/view-store/boundedContext.js';\nimport { ViewCommandClient } from './generated/view-store/view/commandClient.js';\nimport {\n ViewSnapshotQueryClient,\n ViewStateClient,\n} from './generated/view-store/view/queryClient.js';\nimport { ViewPreferencesCommandClient } from './generated/view-store/view_preferences/commandClient.js';\nimport { ViewPreferencesSnapshotQueryClient } from './generated/view-store/view_preferences/queryClient.js';\nimport type { ViewState } from './generated/view-store/types.js';\nimport { boardTitles, Failure, guard, request } from './errors.js';\nimport { SystemViewsClient } from './systemViews.js';\nimport {\n scopeAt,\n SUMMARY_FIELDS,\n toInstance,\n toSummary,\n type ViewRecord,\n} from './wire.js';\n\n/** How a V10 {@link WowViewStore} reaches the view store service. */\nexport interface WowViewStoreOptions {\n /**\n * The fetcher every request goes through, on the base URL that serves\n * `/view-store/…` (the V10 view store service, or a gateway in front of\n * it).\n *\n * Its interceptors carry who is asking; the store never does. The V10\n * service takes the tenant and the owner from the principal, so no path\n * names them: the interceptors send the authorization (CoSec's token, or\n * the headers the service's own caller resolver reads) and `CoSec-App-Id`,\n * the application every view, preference and wording is kept in. The\n * store adds `Wow-Scope` itself where it acts as a reserved owner: the\n * shared views' `(shared)`, and `(system)` of `(platform)` for stored\n * system views.\n */\n fetcher: Fetcher;\n /**\n * Which buttons are enabled for one definition's views. The service\n * authorizes each write; a host answers this by the roles it holds there —\n * `changeAudience` and the shared views' writes by the role that writes\n * the owner `(shared)` (`view-store.shared-writer` on the service as\n * shipped), `editSystem` by the one that writes `(system)`. Left out,\n * everything is allowed, as the port reads a store without `permissions`.\n */\n permissions?: (definitionId: string) => ViewPermissions;\n}\n\n/**\n * The largest list the server answers (its query budget); a definition with\n * more views of one audience lists the first this many.\n */\nconst LIST_LIMIT = 1000;\n\n/** How many system views' revisions the store remembers the version of. */\nconst REMEMBERED_SYSTEM_REVISIONS = 1024;\n\n/**\n * What a share or a claim waits for: the saga that moves the view to its\n * new owner, then that move's snapshot. The view's own commit changes its\n * audience; the owner, which reads and writes go by, changes one version\n * later (`ViewAudienceSaga`).\n */\nconst AUDIENCE_WAIT = [\n viewStoreWait.handled('ViewAudienceSaga.onAudienceChanged'),\n viewStoreWait.snapshot(),\n];\n\n/** One instance write, as sent from the place the view is at. */\ninterface InstanceWrite {\n /** Sends it with the options the store fills. */\n send(options: CommandOptions): Promise<CommandResult>;\n /** The place whose `Wow-Scope` it is sent with. */\n sentFrom: Place;\n /** Where the view is once it lands; `null` for a delete. */\n landsAt: Place | null;\n /** A share or a claim: it moves the view, waiting for the move. */\n moves?: boolean;\n}\n\n/**\n * The view engine's `ViewStore` over the **V10** view store service\n * (`platform/view-store` in the Wow repository): saved views and preferences\n * as two Wow V10 aggregates, reached through the clients generated from the\n * service's Manifest (`@ahoo-wang/wow-client`), and the system views\n * through the service's own route.\n *\n * **The owner is the audience.** A personal view is the caller's own; a\n * shared one belongs to the reserved owner `(shared)`, which the store acts\n * as with `Wow-Scope: owner=\"(shared)\"`; a stored system view to `(system)`\n * of the tenant `(platform)`. The port names a view by id alone, so the\n * store remembers where it last saw each one and looks an unknown id up as\n * the caller, as `(shared)` and among the system views, in that order.\n * Sharing and claiming move a view to the other owner in place, id kept:\n * the store waits for the service's `ViewAudienceSaga` to move it.\n *\n * **Writes** carry the port's `requestId` as `Wow-Request-Id` and its\n * `revision` as `If-Match`, and wait for the snapshot. The service\n * deduplicates a request id, creates included, so a retry is answered with\n * the first attempt's outcome; the store answers the view read back at the\n * version that write left (`GET …/{id}/state?version=`). A stale revision\n * is `CONFLICT` carrying the view as it is now.\n *\n * **Errors** are read by the problem's code onto the port's codes, by the\n * HTTP status only for an answer without a code the store knows; a `404`\n * without a code is a route the service does not serve (`UNSUPPORTED`), and\n * a request that got no answer is `UNAVAILABLE`.\n */\nexport class WowViewStore implements ViewStore {\n /**\n * The most of one audience a list answers (`LIST_LIMIT`): an audience\n * listed this full was cut there, which the workbench then says (R2-26).\n */\n readonly listLimit = LIST_LIMIT;\n /** The host's {@link WowViewStoreOptions.permissions}, when it gave any. */\n readonly permissions?: (definitionId: string) => ViewPermissions;\n private readonly commands: ViewCommandClient;\n private readonly snapshots: ViewSnapshotQueryClient;\n private readonly states: ViewStateClient;\n private readonly preferenceCommands: ViewPreferencesCommandClient;\n private readonly preferenceSnapshots: ViewPreferencesSnapshotQueryClient;\n private readonly systemViews: SystemViewsClient;\n /** Where each view was last seen, by id. */\n private readonly places = new Map<string, Place>();\n /**\n * The version of each stored system view at each revision the store has\n * seen it at (a hash of its content, while a write expects the version),\n * by `id` and revision; `null` for a configured one, which is read-only.\n * Keeping the old revisions too lets a retry send the version its first\n * attempt expected, which the service then answers as a duplicate.\n */\n private readonly systemVersions = new Remembered<number | null>(\n REMEMBERED_SYSTEM_REVISIONS,\n );\n\n constructor(options: WowViewStoreOptions) {\n const client: WowClientOptions = { fetcher: options.fetcher };\n this.commands = new ViewCommandClient(client);\n this.snapshots = new ViewSnapshotQueryClient(client);\n this.states = new ViewStateClient(client);\n this.preferenceCommands = new ViewPreferencesCommandClient(client);\n this.preferenceSnapshots = new ViewPreferencesSnapshotQueryClient(client);\n this.systemViews = new SystemViewsClient(options.fetcher);\n // Left undefined when the host declared none, which the port reads as\n // \"everything is allowed\".\n if (options.permissions) this.permissions = options.permissions;\n }\n\n /**\n * The caller's personal views, the shared views and the service's system\n * views of the definition: three requests, sent together, answered in the\n * port's order — system, shared, personal, each oldest first (the service\n * sorts each audience by the time its first event was written).\n */\n list(\n definitionId: string,\n signal?: AbortSignal,\n ): Promise<ViewInstanceSummary[]> {\n return guard(async () => {\n const query = listQuery({\n filter: filter.eq('state.definitionId', definitionId),\n projection: { include: [...SUMMARY_FIELDS] },\n sort: [asc('firstEventTime'), asc('aggregateId')],\n limit: LIST_LIMIT,\n });\n const [personal, shared, system] = await Promise.all([\n request(() => this.snapshots.list(query, { signal })),\n request(() =>\n this.snapshots.list(query, { scope: scopeAt('shared'), signal }),\n ),\n this.systemViews.list(definitionId, signal),\n ]);\n for (const view of system) this.rememberSystem(view);\n const seen = new Map<string, ViewInstanceSummary>();\n for (const summary of [\n ...personal.map(record => toSummary(recordOf(record))),\n ...shared.map(record => toSummary(recordOf(record))),\n ...system.map(systemSummary),\n ]) {\n if (seen.has(summary.id)) continue;\n seen.set(summary.id, summary);\n this.places.set(summary.id, summary.scope);\n }\n // Sorted stably: within an audience, the service's order stands.\n return [...seen.values()].sort(\n (a, b) => AUDIENCE_RANK[a.scope] - AUDIENCE_RANK[b.scope],\n );\n });\n }\n\n /** View `id` wherever it is: the caller's, shared, or a system view. */\n get(id: string, signal?: AbortSignal): Promise<ViewInstance> {\n return guard(async () => (await this.find(id, signal)).instance);\n }\n\n /**\n * Creates the view as the owner of its `scope`; the service generates the\n * id. A retry under the same request id is answered with the first\n * attempt's view, whichever store sends it: the service deduplicates it.\n */\n create(\n input: Omit<ViewInstance, 'id' | 'revision'>,\n context: WriteContext,\n ): Promise<ViewInstance> {\n return guard(async () => {\n const place: Place = input.scope;\n const { definitionId, title, config } = input;\n const write: InstanceWrite = {\n send: options =>\n this.commands.createView(\n { definitionId, title, config: bodyOf(config) },\n options,\n ),\n sentFrom: place,\n landsAt: place,\n };\n const result = await request(() =>\n write.send(this.commandOptions(place, context)),\n );\n return (await this.landed(result.ref.id, write, result, context))!;\n });\n }\n\n /** Replaces the view's config, at the expected `revision`. */\n save(\n id: string,\n config: ViewConfig,\n revision: string,\n context: WriteContext,\n ): Promise<ViewInstance> {\n return this.write(id, revision, context, place => ({\n send: options =>\n this.commands.saveView(id, { config: bodyOf(config) }, options),\n sentFrom: place,\n landsAt: place,\n })) as Promise<ViewInstance>;\n }\n\n /** Renames the view (the service trims the title), at the expected `revision`. */\n rename(\n id: string,\n title: string,\n revision: string,\n context: WriteContext,\n ): Promise<ViewInstance> {\n return this.write(id, revision, context, place => ({\n send: options => this.commands.renameView(id, { title }, options),\n sentFrom: place,\n landsAt: place,\n })) as Promise<ViewInstance>;\n }\n\n /**\n * 设为共享 sends `share-view` as the caller, the view's owner; 设为个人\n * sends `claim-view` as `(shared)`, which the service admits only with\n * the role that writes the owner `(shared)`, and which makes the caller\n * the owner. Either waits for the move (`ViewAudienceSaga`). Each is sent\n * from the same owner whether or not the view has moved, so a retry is\n * answered as its first attempt's duplicate even after the move.\n *\n * Asked for the audience the view already has, the service refuses the\n * command as outside that owner's scope; the store then answers the view\n * as it is, revision unmoved, once the revision matches.\n *\n * A shared view a shared dashboard shows stays shared: the service\n * refuses the claim and names the boards, and the refusal carries them by\n * **title** in `boards`, as they are stored.\n */\n changeAudience(\n id: string,\n audience: ViewAudience,\n revision: string,\n context: WriteContext,\n ): Promise<ViewInstance> {\n return this.write(id, revision, context, place => {\n if (place === 'system') readOnly('A system view never moves audience');\n return audience === 'shared'\n ? {\n send: options => this.commands.shareView(id, {}, options),\n sentFrom: 'personal',\n landsAt: 'shared',\n moves: true,\n }\n : {\n send: options => this.commands.claimView(id, {}, options),\n sentFrom: 'shared',\n landsAt: 'personal',\n moves: true,\n };\n }) as Promise<ViewInstance>;\n }\n\n /** Deletes the view, at the expected `revision`; a board showing it keeps a broken panel. */\n async delete(\n id: string,\n revision: string,\n context: WriteContext,\n ): Promise<void> {\n await this.write(id, revision, context, place => ({\n send: options => this.commands.deleteAggregate(id, options),\n sentFrom: place,\n landsAt: null,\n }));\n }\n\n /**\n * The caller's preferences of the definition, in the request's\n * application: the service derives their id from the owner, the\n * application and the definition. None written yet reads as the port's\n * empty preferences, at revision `'0'`.\n */\n getPreferences(\n definitionId: string,\n signal?: AbortSignal,\n ): Promise<ViewPreferences> {\n return guard(async () => {\n try {\n const record = await request(() =>\n this.preferenceSnapshots.single(\n singleQuery({\n filter: filter.eq('state.definitionId', definitionId),\n }),\n { signal },\n ),\n );\n return toPreferences({ ...record.state, version: record.version });\n } catch (thrown) {\n if (\n thrown instanceof Failure &&\n thrown.problemCode === FrameworkErrorCodes.QUERY_NOT_FOUND\n )\n return emptyPreferences();\n throw thrown;\n }\n });\n }\n\n /**\n * Writes the preferences at the expected `revision` (`'0'` for ones never\n * written, which `If-Match: \"0\"` says). A retry under the same request id\n * is answered as the first attempt's duplicate, at its version.\n */\n setPreferences(\n definitionId: string,\n preferences: ViewPreferences,\n context: WriteContext,\n ): Promise<ViewPreferences> {\n return guard(async () => {\n const { requestId, signal } = context;\n try {\n const result = await request(() =>\n this.preferenceCommands.setViewPreferences(\n { definitionId, ...preferencesInput(preferences) },\n {\n requestId,\n expectedVersion: versionOf(preferences.revision),\n ...(signal === undefined ? {} : { signal }),\n },\n ),\n );\n return typeof result.version === 'number'\n ? preferencesAt(preferences, result.version)\n : await this.getPreferences(definitionId, signal);\n } catch (thrown) {\n if (!(thrown instanceof Failure) || thrown.code !== 'CONFLICT')\n throw thrown;\n throw new ViewStoreError('CONFLICT', thrown.message, {\n ...thrown.held(),\n preferences: await this.getPreferences(definitionId, signal),\n });\n }\n });\n }\n\n /**\n * One instance write: to the place the view is at, then the answer read\n * back. A view remembered at a place it has since left (another tab shared\n * it) is looked up again and the write sent once more from where it is.\n * A move refused because the view already has the audience it asks for\n * changes nothing: the view is answered as it is, once its revision\n * matches.\n */\n private write(\n id: string,\n revision: string,\n context: WriteContext,\n plan: (place: Place) => InstanceWrite,\n ): Promise<ViewInstance | undefined> {\n return guard(async () => {\n const { signal } = context;\n const remembered = this.places.get(id);\n let place = remembered ?? (await this.find(id, signal)).place;\n let relocated = remembered === undefined;\n for (;;) {\n const write = plan(place);\n const options = this.commandOptions(write.sentFrom, context, {\n expectedVersion:\n place === 'system'\n ? await this.systemVersion(id, revision, signal)\n : versionOf(revision),\n ...(write.moves ? { wait: { plan: AUDIENCE_WAIT } } : {}),\n });\n let result: CommandResult;\n try {\n result = await request(() => write.send(options));\n } catch (thrown) {\n if (!(thrown instanceof Failure)) throw thrown;\n if (\n write.moves &&\n place === write.landsAt &&\n thrown.code === 'FORBIDDEN'\n )\n return this.unchanged(id, revision, place, signal);\n if (\n !relocated &&\n (thrown.code === 'NOT_FOUND' || thrown.code === 'FORBIDDEN')\n ) {\n relocated = true;\n const found = (await this.find(id, signal, null)).place;\n if (found !== place) {\n place = found;\n continue;\n }\n }\n if (thrown.code === 'CONFLICT')\n throw await this.conflict(id, thrown, signal);\n throw refusal(thrown);\n }\n // Landed: what goes wrong reading it back is never a reason to send\n // it again.\n return this.landed(id, write, result, context);\n }\n });\n }\n\n /**\n * A landed write's answer: the view read back at the version it left\n * (`GET …/{id}/state?version=`). A system view's revision is its content\n * hash, so it is read from its route as it is now.\n *\n * A move is two commits: the view's own (its audience), then the saga's\n * (its owner). Waited for, the result's version is the second; a\n * duplicate answers the first, so the move is read one version later,\n * where the owner it names must be the one it moved to. Anything else\n * (another writer between the two) answers the view as it is now.\n */\n private async landed(\n id: string,\n write: InstanceWrite,\n result: CommandResult,\n context: WriteContext,\n ): Promise<ViewInstance | undefined> {\n const { landsAt } = write;\n if (landsAt === null) return undefined;\n this.places.set(id, landsAt);\n const { signal } = context;\n const read = typeof result.version === 'number' ? result.version : null;\n if (landsAt !== 'system' && read !== null)\n try {\n const version = write.moves && result.duplicate ? read + 1 : read;\n const view = await request(() =>\n this.states.get(id, {\n version,\n ...optionsAt(landsAt),\n ...(signal === undefined ? {} : { signal }),\n }),\n );\n if (!write.moves || ownedAt(view.scope.ownerId) === landsAt)\n return toInstance({ id, version: view.version, state: view.state });\n } catch {\n // Moved on since (another tab moved it): answered as it is.\n }\n return (await this.find(id, signal, landsAt)).instance;\n }\n\n /** A move to where the view already is: the view as it is, at `revision`. */\n private async unchanged(\n id: string,\n revision: string,\n place: Place,\n signal: AbortSignal | undefined,\n ): Promise<ViewInstance> {\n const { instance } = await this.find(id, signal, place);\n if (instance.revision !== revision)\n throw new ViewStoreError(\n 'CONFLICT',\n `View ${id} has moved on from revision ${revision}`,\n { instance },\n );\n return instance;\n }\n\n /** A stale write's refusal, carrying the view as it is now. */\n private async conflict(\n id: string,\n failure: Failure,\n signal: AbortSignal | undefined,\n ): Promise<ViewStoreError> {\n const { instance } = await this.find(id, signal, null);\n return new ViewStoreError('CONFLICT', failure.message, {\n ...failure.held(),\n instance,\n });\n }\n\n /**\n * View `id` and where it is: first where it was last seen (`first`, `null`\n * to ignore that), then as the caller, as `(shared)` and among the system\n * views.\n */\n private async find(\n id: string,\n signal: AbortSignal | undefined,\n first: Place | null | undefined = this.places.get(id),\n ): Promise<{ place: Place; instance: ViewInstance }> {\n // Ids in `system:` are the views a host declares in code; the service\n // never issues or serves one.\n if (!isSystemInstanceId(id)) {\n const order: Place[] = ['personal', 'shared', 'system'];\n if (first)\n order.sort((a, b) => Number(b === first) - Number(a === first));\n for (const place of order) {\n try {\n const instance = await this.readAt(place, id, signal);\n this.places.set(id, place);\n return { place, instance };\n } catch (thrown) {\n if (thrown instanceof Failure && thrown.code === 'NOT_FOUND')\n continue;\n throw thrown;\n }\n }\n }\n throw new ViewStoreError('NOT_FOUND', `No such view: ${id}`);\n }\n\n /** The view as it is now at `place`; a `NOT_FOUND` failure when it is not there. */\n private async readAt(\n place: Place,\n id: string,\n signal: AbortSignal | undefined,\n ): Promise<ViewInstance> {\n if (place === 'system')\n return systemInstance(\n this.rememberSystem(await this.systemViews.one(id, signal)),\n );\n const record = await request(() =>\n this.snapshots.single(singleQuery({ filter: filter.id(id) }), {\n ...optionsAt(place),\n ...(signal === undefined ? {} : { signal }),\n }),\n );\n return toInstance(recordOf(record));\n }\n\n /** Keeps the version of a stored system view at its revision; a configured one as read-only. */\n private rememberSystem(view: SystemViewBody): SystemViewBody {\n this.systemVersions.set(\n revisionKey(view.id, view.revision),\n isStored(view) ? view.version! : null,\n );\n return view;\n }\n\n /**\n * The version a write of stored system view `id` at `revision` (its\n * content hash) expects: as seen at that revision, else as read now. A\n * configured system view is read-only (`FORBIDDEN`; a code one is never\n * found here); a revision other than the view's is `CONFLICT`, carrying\n * the view as it is.\n */\n private async systemVersion(\n id: string,\n revision: string,\n signal: AbortSignal | undefined,\n ): Promise<number> {\n const key = revisionKey(id, revision);\n if (!this.systemVersions.has(key)) {\n const instance = await this.readAt('system', id, signal);\n if (instance.revision !== revision && instance.stored)\n throw new ViewStoreError(\n 'CONFLICT',\n `System view ${id} has moved on from revision ${revision}`,\n { instance },\n );\n }\n const version = this.systemVersions.get(key);\n if (typeof version !== 'number')\n readOnly('Configured system views are read-only');\n return version;\n }\n\n /** The options of a command sent from `place`: its scope, request id and signal. */\n private commandOptions(\n place: Place,\n { requestId, signal }: WriteContext,\n more: Partial<CommandOptions> = {},\n ): CommandOptions {\n return {\n ...optionsAt(place),\n requestId,\n ...(signal === undefined ? {} : { signal }),\n ...more,\n };\n }\n}\n\n/** The port's list order: system views first, then shared, then personal. */\nconst AUDIENCE_RANK: Readonly<Record<ViewInstanceSummary['scope'], number>> = {\n system: 0,\n shared: 1,\n personal: 2,\n};\n\n/** The request options of `place`: its `Wow-Scope`, when it has one. */\nfunction optionsAt(place: Place): { scope?: ReturnType<typeof scopeAt> } {\n const scope = scopeAt(place);\n return scope === undefined ? {} : { scope };\n}\n\n/** The place of a view its owner says: a reserved owner, or a user's own. */\nfunction ownedAt(ownerId: string | null | undefined): Place {\n return ownerId === SHARED_OWNER_ID\n ? 'shared'\n : ownerId === SYSTEM_OWNER_ID\n ? 'system'\n : 'personal';\n}\n\n/** A snapshot record as the store reads it. */\nfunction recordOf(record: {\n aggregateId: string;\n version: number;\n state: unknown;\n}): ViewRecord {\n return {\n id: record.aggregateId,\n version: record.version,\n state: record.state as ViewState,\n };\n}\n\n/** A config as a command body holds it: free-form, the service stores it whole. */\nfunction bodyOf(config: ViewConfig): Record<string, unknown> {\n return config as unknown as Record<string, unknown>;\n}\n\n/** The aggregate version a revision of this store names. */\nfunction versionOf(revision: string): number {\n const version = Number(revision);\n if (!Number.isInteger(version) || version < 0)\n throw new ViewStoreError(\n 'CONFLICT',\n `Not a revision of this store: ${revision}`,\n );\n return version;\n}\n\nfunction revisionKey(id: string, revision: string): string {\n return `${id}\\u0000${revision}`;\n}\n\n/** Refuses a write to a system view the server or the code declares. */\nfunction readOnly(message: string): never {\n throw new ViewStoreError('FORBIDDEN', message);\n}\n\n/**\n * The port's refusal of a write. A claim the service refuses because shared\n * dashboards show the view carries those boards' titles (`boards`), read\n * from the problem's `boards` extension member; the engine says the refusal\n * around them.\n */\nfunction refusal(failure: Failure): ViewStoreError {\n if (\n failure.problemCode !== ViewStoreErrorCodes.REFERENCED_BY_SHARED_DASHBOARD\n )\n return failure.toStoreError();\n return new ViewStoreError('INVALID', failure.message, {\n ...failure.held(),\n boards: boardTitles(failure.problem?.problem.extensions),\n });\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { CommandGateway, type CommandResult, type CommandResultStream, type CreateCommandOptions, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { ClearDatasetWording, SetDatasetWording } from '../types.js';\n\n/** The command routes of `view-store.dataset_wording`. */\nexport const DatasetWordingCommandPaths = {\n CLEAR_DATASET_WORDING: '/view-store/dataset_wording/{id}/clear-dataset-wording',\n CLEAR_DATASET_WORDING_WITHOUT_ID: '/view-store/dataset_wording/clear-dataset-wording',\n SET_DATASET_WORDING: '/view-store/dataset_wording/{id}/set-dataset-wording',\n SET_DATASET_WORDING_WITHOUT_ID: '/view-store/dataset_wording/set-dataset-wording',\n} as const;\n\n/** Sends the commands of `view-store.dataset_wording`; a command that did not succeed rejects with a `WowProblemError` holding its result. */\nexport class DatasetWordingCommandClient {\n readonly gateway: CommandGateway;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.gateway = new CommandGateway(options);\n }\n\n /**\n * Clear the wording of a dataset\n * `ClearDatasetWording`: `POST /view-store/dataset_wording/{id}/clear-dataset-wording`, `POST /view-store/dataset_wording/clear-dataset-wording`.\n * Produces `DatasetWordingCleared`.\n */\n clearDatasetWording(body: ClearDatasetWording, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.gateway.send(options?.id === undefined ? DatasetWordingCommandPaths.CLEAR_DATASET_WORDING_WITHOUT_ID : DatasetWordingCommandPaths.CLEAR_DATASET_WORDING, body, options);\n }\n\n /** `ClearDatasetWording`, answered as one result per hop of its wait (`text/event-stream`). */\n clearDatasetWordingStream(body: ClearDatasetWording, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(options?.id === undefined ? DatasetWordingCommandPaths.CLEAR_DATASET_WORDING_WITHOUT_ID : DatasetWordingCommandPaths.CLEAR_DATASET_WORDING, body, options);\n }\n\n /**\n * Set the wording of a dataset\n * `SetDatasetWording`: `POST /view-store/dataset_wording/{id}/set-dataset-wording`, `POST /view-store/dataset_wording/set-dataset-wording`.\n * Creates the aggregate, or acts on the one that exists.\n * Produces `DatasetWordingSet`.\n */\n setDatasetWording(body: SetDatasetWording, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.gateway.send(options?.id === undefined ? DatasetWordingCommandPaths.SET_DATASET_WORDING_WITHOUT_ID : DatasetWordingCommandPaths.SET_DATASET_WORDING, body, options);\n }\n\n /** `SetDatasetWording`, answered as one result per hop of its wait (`text/event-stream`). */\n setDatasetWordingStream(body: SetDatasetWording, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.gateway.stream(options?.id === undefined ? DatasetWordingCommandPaths.SET_DATASET_WORDING_WITHOUT_ID : DatasetWordingCommandPaths.SET_DATASET_WORDING, body, options);\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { EventView, SystemEvent } from '@ahoo-wang/wow-client';\nimport type { DatasetWordingCleared, DatasetWordingSet } from '../types.js';\n\n/**\n * The aggregate `view-store.dataset_wording`.\n * A tenant's wording over one dataset in one application\n */\nexport const DatasetWordingAggregate = {\n context: 'view-store',\n name: 'dataset_wording',\n path: '/view-store/dataset_wording',\n ownership: 'TENANT',\n snapshot: true,\n} as const;\n\n/** The `state.*` paths of `dataset_wording`'s snapshots a query filters, sorts and projects on. */\nexport type DatasetWordingStateField = 'state.appId' | 'state.dataset' | 'state.fields' | 'state.recordNoun' | 'state.title';\n\n/** The events of `dataset_wording`, named as the server sends them, `view-store.dataset_wording.<Event>` at its current revision (the `events` query upgrades older records), and the system events every aggregate has. */\nexport type DatasetWordingEvent = EventView<'view-store.dataset_wording.DatasetWordingCleared', DatasetWordingCleared> | EventView<'view-store.dataset_wording.DatasetWordingSet', DatasetWordingSet> | SystemEvent;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { EventQueryClient, SnapshotQueryClient, StateClient, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { DatasetWordingState } from '../types.js';\nimport { DatasetWordingAggregate, type DatasetWordingEvent, type DatasetWordingStateField } from './aggregate.js';\n\n/** Queries the snapshots of `view-store.dataset_wording`: `POST /view-store/dataset_wording/snapshot/query`. */\nexport class DatasetWordingSnapshotQueryClient extends SnapshotQueryClient<DatasetWordingState, DatasetWordingStateField> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(DatasetWordingAggregate, options);\n }\n}\n\n\n/** Queries the event streams of `view-store.dataset_wording`, one record per commit: `POST /view-store/dataset_wording/events/query`. */\nexport class DatasetWordingEventQueryClient extends EventQueryClient<DatasetWordingEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(DatasetWordingAggregate, options);\n }\n}\n\n\n/** Reads the states of `view-store.dataset_wording`, at a version or a time, and their traces: `GET /view-store/dataset_wording/{id}/state`. */\nexport class DatasetWordingStateClient extends StateClient<DatasetWordingState, DatasetWordingEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(DatasetWordingAggregate, options);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Fetcher } from '@ahoo-wang/fetcher';\nimport { filter, listQuery } from '@ahoo-wang/wow-client/dsl';\nimport type { CommandOptions, CommandResult } from '@ahoo-wang/wow-client';\nimport type {\n DatasetOverrides,\n DatasetWordingStore,\n StoredDatasetWording,\n WriteContext,\n} from '@ahoo-wang/wow-view-engine';\nimport { revisionOf } from './views.js';\nimport { DatasetWordingCommandClient } from './generated/view-store/dataset_wording/commandClient.js';\nimport { DatasetWordingSnapshotQueryClient } from './generated/view-store/dataset_wording/queryClient.js';\nimport { guard, request } from './errors.js';\nimport { wordingOf } from './wire.js';\n\n/** How a V10 {@link WowDatasetWordings} reaches the view store service: as a V10 `WowViewStore` does. */\nexport interface WowDatasetWordingsOptions {\n /**\n * The fetcher every request goes through, as the V10\n * `WowViewStoreOptions.fetcher`: its interceptors carry the caller and\n * `CoSec-App-Id`. The wording is the tenant's (an aggregate of the tenant,\n * not of an owner), so no request names a scope.\n */\n fetcher: Fetcher;\n}\n\n/** The most datasets one application's wording is read for at once. */\nconst LIST_LIMIT = 1000;\n\n/**\n * The wording a tenant's administrators keep over its datasets in the V10\n * view store (view engine D86): one per dataset of the caller's tenant and\n * application, the id derived by the service from the two. Every reader of\n * the tenant reads it; the service decides who writes it (the role that\n * writes the owner `(shared)`, `view-store.shared-writer` as shipped).\n *\n * A host hands it to the datasets it registers as their store of wording\n * (`DatasetCatalog.wordings`, D91). The key is the dataset's definition id,\n * `{context}.{dataset}`. Every rejection is a `ViewStoreError`, read as a\n * V10 `WowViewStore`'s are.\n */\nexport class WowDatasetWordings implements DatasetWordingStore {\n private readonly commands: DatasetWordingCommandClient;\n private readonly snapshots: DatasetWordingSnapshotQueryClient;\n\n constructor(options: WowDatasetWordingsOptions) {\n const client = { fetcher: options.fetcher };\n this.commands = new DatasetWordingCommandClient(client);\n this.snapshots = new DatasetWordingSnapshotQueryClient(client);\n }\n\n /**\n * Every dataset's wording of the caller's tenant and application, by\n * dataset. A cleared one is listed too, saying nothing: its revision is\n * what the next write expects.\n */\n list(\n signal?: AbortSignal,\n ): Promise<ReadonlyMap<string, StoredDatasetWording>> {\n return guard(async () => {\n const snapshots = await request(() =>\n this.snapshots.list(\n listQuery({ filter: filter.matchAll(), limit: LIST_LIMIT }),\n signal === undefined ? {} : { signal },\n ),\n );\n return new Map(\n snapshots.map(({ version, state }) => [\n state.dataset,\n { wording: wordingOf(state), revision: revisionOf(version) },\n ]),\n );\n });\n }\n\n /**\n * Writes a dataset's wording at the expected `revision` (`'0'` for one never\n * written), whole: what it leaves out is no longer said. Answers the new\n * revision.\n */\n set(\n dataset: string,\n wording: DatasetOverrides,\n revision: string,\n context: WriteContext,\n ): Promise<string> {\n return guard(async () => {\n const result = await request(() =>\n this.commands.setDatasetWording(\n {\n dataset,\n ...(wording.title === undefined ? {} : { title: wording.title }),\n ...(wording.recordNoun === undefined\n ? {}\n : { recordNoun: wording.recordNoun }),\n ...(wording.fields === undefined\n ? {}\n : {\n fields: wording.fields as unknown as Record<string, unknown>,\n }),\n },\n optionsOf(revision, context),\n ),\n );\n return versionAfter(result, revision);\n });\n }\n\n /**\n * Clears a dataset's wording at the expected `revision`: its derived words\n * stand again. Answers the new revision.\n */\n clear(\n dataset: string,\n revision: string,\n context: WriteContext,\n ): Promise<string> {\n return guard(async () => {\n const result = await request(() =>\n this.commands.clearDatasetWording(\n { dataset },\n optionsOf(revision, context),\n ),\n );\n return versionAfter(result, revision);\n });\n }\n}\n\nfunction optionsOf(\n revision: string,\n { requestId, signal }: WriteContext,\n): CommandOptions {\n return {\n requestId,\n expectedVersion: Number(revision),\n ...(signal === undefined ? {} : { signal }),\n };\n}\n\n/** The revision a write left: its version, or the one it expected moved on. */\nfunction versionAfter(result: CommandResult, revision: string): string {\n return revisionOf(result.version ?? Number(revision) + 1);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DatasetClient,\n PagedQuery,\n QueryModelClient,\n RequestOptions,\n} from '@ahoo-wang/wow-client';\nimport type {\n AggregationQuery,\n CursorQuery,\n FilterPagedQuery,\n} from '@ahoo-wang/wow-client/dsl';\nimport type {\n DatasetCatalog,\n DatasetDirectoryEntry,\n RecordData,\n ViewSource,\n} from '@ahoo-wang/wow-view-engine';\n\n/**\n * The view engine's `ViewSource` over one query route of a Wow **V10**\n * service: a generated `…SnapshotQueryClient`, a `QueryModelClient`, or a\n * dataset's (`DatasetClient.dataset(…)`). The engine's port takes an\n * `AbortController` rather than request options, reads the total as a plain\n * count, and wants the descriptor's version with every read. This is the\n * whole adapter.\n *\n * A page counts its total as the service does by default, `BOUNDED`\n * (D150): exact up to the budget's limit, and the limit itself past it. A\n * V10 service refuses an exact total over HTTP, so the engine, which reads\n * the total as the count of matches, shows a count past the limit as the\n * limit (an engine follow-up: say \"at least\"). The engine's `attributes`\n * have no counterpart on a V10 request and are not sent.\n *\n * ```ts\n * const engine = new ViewEngine({\n * store: new WowViewStore({ fetcher }),\n * resources: [\n * { definition: orders, source: viewSourceOf(new OrderSnapshotQueryClient({ fetcher })) },\n * ],\n * });\n * ```\n */\nexport function viewSourceOf<F extends string>(\n client: QueryModelClient<object, F>,\n): ViewSource {\n return {\n async paged(query, _attributes, abort) {\n const page = await client.paged(\n query as FilterPagedQuery<F> as PagedQuery<F>,\n optionsOf(abort),\n );\n return {\n total: page.total ?? page.list.length,\n list: [...page.list] as RecordData[],\n };\n },\n async cursor(query, _attributes, abort) {\n const page = await client.cursor(\n query as CursorQuery<F>,\n optionsOf(abort),\n );\n return { list: page.list as RecordData[], nextCursor: page.nextCursor };\n },\n aggregate(query, _attributes, abort) {\n return client.aggregate<RecordData>(\n query as AggregationQuery<F, string>,\n optionsOf(abort),\n );\n },\n async describe(previous, _attributes, abort) {\n const read = await client.describe(previous, optionsOf(abort));\n if (read.notModified) return read;\n return {\n notModified: false,\n descriptor: read.descriptor,\n version: read.version ?? read.descriptor.version,\n };\n },\n };\n}\n\n/**\n * What a `DatasetCatalog` reads of a Wow **V10** service's datasets: the\n * directory (`GET /wow/dataset`) and each dataset's query route as a\n * `ViewSource` ({@link viewSourceOf}). A host spreads it into the catalog it\n * hands `DatasetResources`, beside its own `overrides` and `wordings`:\n *\n * ```ts\n * const datasets = new DatasetClient({ fetcher });\n * new DatasetResources(engine, {\n * ...datasetCatalogOf(datasets),\n * wordings: new WowDatasetWordings({ fetcher }),\n * });\n * ```\n *\n * A V10 directory entry names no version, and lists only datasets it serves:\n * each is given `LISTED`, so `DatasetResources` (which reads `null` as a\n * dataset not servable) registers it, and a dataset is told changed by its\n * descriptor's version, which the engine checks on its own schedule.\n */\nexport function datasetCatalogOf(\n client: DatasetClient,\n): Pick<DatasetCatalog, 'list' | 'source'> {\n return {\n async list(): Promise<DatasetDirectoryEntry[]> {\n return (await client.list()).map(entry => ({\n contextName: entry.context,\n name: entry.dataset,\n title: entry.title ?? null,\n version: LISTED,\n }));\n },\n source: entry =>\n viewSourceOf(client.dataset(entry.contextName, entry.name)),\n };\n}\n\n/** The version every dataset a V10 directory lists is given (`datasetCatalogOf`). */\nconst LISTED = 'listed';\n\n/** A V10 request's options from the engine's controller. */\nfunction optionsOf(abort: AbortController | undefined): RequestOptions {\n return abort === undefined ? {} : { signal: abort.signal };\n}\n"],"mappings":";;;;;;;IAuBaI,IAAkB,YAMlBC,IAAkB,YAUlBC,IAAmB,cCzB1BC,IAAoB,KAGb,aAAb,MAA2B;CAGzB,YAAY,IAAyBA,GAAmB;EAF7B,AAEE,KAAA,QAAAC,GAFF,KAAA,0BAAA,IAAI,IAAe;CAEW;CAEzD,IAAI,GAA4B;EAC9B,OAAO,KAAK,QAAQ,IAAIC,CAAG;CAC7B;CAEA,IAAI,GAAsB;EACx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OWNER_ID","SYSTEM_TENANT_ID","REMEMBERED_WRITES","limit","key","value","view","version","body","preferences","order","defaultInstanceId","autoRun","lastTabs","DatasetWordingAggregate","ViewAggregate","ViewPreferencesAggregate","ViewStoreContract","viewStoreWait","wait","subscription","ViewStoreManifest","MANIFEST_FORMAT","CommandClient","options","LifecycleCommands","SnapshotQueryClient","StateClient","ServiceRoutes","WowViewStoreErrorCodes","CODES","FrameworkErrorCodes","cause","problem","rejection","code","known","ViewStoreError","error","CommandRejectedError","WowProblemError","toWowProblemError","boards","extensions","board","title","id","run","thrown","isViewStoreError","message","name","SHARED_SCOPE","SYSTEM_SCOPE","place","SUMMARY_FIELDS","state","LIST_PAGE","at","cursor","REMEMBERED_SYSTEM_REVISIONS","AUDIENCE_WAIT","WaitPlan","client","items","room","read","definitionId","signal","summary","system","page","cursorQuery","filter","asc","record","input","write","config","result","context","revision","audience","singleQuery","emptyPreferences","remembered","relocated","plan","found","landsAt","instance","failure","isSystemInstanceId","entry","scope","more","ownerId","LIST_LIMIT","snapshots","listQuery","wording"],"sources":["../src/paths.ts","../src/remembered.ts","../src/views.ts","../src/generated/view-store/dataset_wording/aggregate.ts","../src/generated/view-store/view/aggregate.ts","../src/generated/view-store/view_preferences/aggregate.ts","../src/generated/view-store/contract.ts","../src/generated/view-store/manifest.ts","../src/generated/view-store/view/commandClient.ts","../src/generated/view-store/view/queryClient.ts","../src/generated/view-store/view_preferences/commandClient.ts","../src/generated/view-store/view_preferences/queryClient.ts","../src/generated/view-store/routes.ts","../src/errors.ts","../src/wire.ts","../src/wowViewStore.ts","../src/generated/view-store/dataset_wording/commandClient.ts","../src/generated/view-store/dataset_wording/queryClient.ts","../src/datasetWordings.ts","../src/source.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The reserved owner of shared views and shared preferences\n * (`ViewStoreContext.SHARED_OWNER_ID` on the server). The parentheses keep it\n * apart from every user id. A request acts as it by naming it in `Wow-Scope`\n * (`SHARED_SCOPE`), as far as the service lets the caller.\n */\nexport const SHARED_OWNER_ID = '(shared)';\n\n/**\n * The reserved owner of stored system views\n * (`ViewStoreContext.SYSTEM_OWNER_ID`), under {@link SYSTEM_TENANT_ID} only.\n */\nexport const SYSTEM_OWNER_ID = '(system)';\n\n/**\n * The one tenant stored system views live under\n * (`ViewStoreContext.SYSTEM_TENANT_ID`): CoSec's platform tenant, by value,\n * not the default tenant `(0)`. System views are global, so they are read\n * and written in this tenant whatever the caller's own (`SYSTEM_SCOPE`).\n */\nexport const SYSTEM_TENANT_ID = '(platform)';\n\n/**\n * Which audience a view is read or written as: `personal` names no scope,\n * and the service takes the owner from the caller; `shared` and `system`\n * name the reserved owner (and, for `system`, tenant) in `Wow-Scope`\n * (`scopeAt`).\n */\nexport type Place = 'personal' | 'shared' | 'system';\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** How many writes a store remembers the outcome of, unless told otherwise. */\nconst REMEMBERED_WRITES = 256;\n\n/** A bounded memory by key: the oldest entry goes first. */\nexport class Remembered<T> {\n private readonly entries = new Map<string, T>();\n\n constructor(private readonly limit = REMEMBERED_WRITES) {}\n\n get(key: string): T | undefined {\n return this.entries.get(key);\n }\n\n has(key: string): boolean {\n return this.entries.has(key);\n }\n\n set(key: string, value: T): void {\n this.entries.delete(key);\n this.entries.set(key, value);\n if (this.entries.size > this.limit)\n this.entries.delete(this.entries.keys().next().value!);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * The server's shapes, as far as the store reads them, and their reading as\n * the port's. The server stores the engine's `ViewConfig` whole and never\n * reads its meaning, so a config comes back exactly as it was saved.\n */\n\nimport type {\n SystemView,\n ViewEntry,\n ViewPreferencesState,\n} from './generated/view-store/types.js';\nimport type {\n ViewConfig,\n ViewInstance,\n ViewInstanceSummary,\n ViewPreferences,\n} from '@ahoo-wang/wow-view-engine';\n\n/**\n * Whether the server stores system view `view` (else it configures it; a\n * saved view has no source). A stored one carries the port's\n * `stored: true`, the views an `editSystem` permission may write;\n * configured and code system views carry none.\n */\nexport function isStored(view: SystemView | ViewEntry): boolean {\n return view.source === 'stored' && typeof view.version === 'number';\n}\n\n/**\n * One owner's preferences in one definition: the generated\n * `ViewPreferencesState`, and the aggregate version they were read at.\n */\nexport type PreferencesBody = Pick<\n ViewPreferencesState,\n 'definitionId' | 'order' | 'defaultInstanceId' | 'autoRun' | 'lastTabs'\n> & { version: number };\n\n/** A snapshot's revision: the aggregate's version, compared as a string. */\nexport function revisionOf(version: number): string {\n return String(version);\n}\n\n/**\n * A view read by id as the port's: a saved view's revision is its version as\n * text, a system view's its content hash, either as the server answers it.\n */\nexport function viewInstance(view: ViewEntry): ViewInstance {\n return {\n id: view.id,\n definitionId: view.definitionId,\n title: view.title,\n scope: view.scope,\n revision: view.revision,\n config: view.config as unknown as ViewConfig,\n ...(isStored(view) ? { stored: true as const } : {}),\n };\n}\n\nexport function systemSummary(view: SystemView): ViewInstanceSummary {\n return {\n id: view.id,\n definitionId: view.definitionId,\n title: view.title,\n scope: 'system',\n kind: view.kind,\n revision: view.revision,\n ...(isStored(view) ? { stored: true as const } : {}),\n };\n}\n\n/**\n * The port's preferences. A member the server holds as `null` is one never\n * set: `defaultInstanceId` reads as `null`, and `autoRun` and `lastTabs` are\n * left out, as the port's own `emptyPreferences()` leaves them.\n */\nexport function toPreferences(body: PreferencesBody): ViewPreferences {\n return preferencesAt(\n {\n order: body.order,\n defaultInstanceId: body.defaultInstanceId ?? null,\n autoRun: body.autoRun ?? undefined,\n lastTabs: body.lastTabs ?? undefined,\n },\n body.version,\n );\n}\n\n/** What a preferences write sends: everything but the revision. */\nexport function preferencesInput(\n preferences: Omit<ViewPreferences, 'revision'>,\n): Omit<ViewPreferences, 'revision'> {\n const { order, defaultInstanceId, autoRun, lastTabs } = preferences;\n return {\n order: [...order],\n defaultInstanceId: defaultInstanceId ?? null,\n ...(autoRun === undefined ? {} : { autoRun }),\n ...(lastTabs === undefined ? {} : { lastTabs: { ...lastTabs } }),\n };\n}\n\n/** `preferences` as written at `version`, in the port's shape. */\nexport function preferencesAt(\n preferences: Omit<ViewPreferences, 'revision'>,\n version: number,\n): ViewPreferences {\n return { ...preferencesInput(preferences), revision: revisionOf(version) };\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { CommittedEvent, SystemEvent } from '@ahoo-wang/wow-client';\nimport type { DatasetWordingCleared, DatasetWordingSet } from '../types.js';\n\n/**\n * The aggregate `view-store.dataset_wording`.\n * A tenant's wording over one dataset in one application\n */\nexport const DatasetWordingAggregate = {\n context: 'view-store',\n name: 'dataset_wording',\n path: '/view-store/dataset_wording',\n ownership: 'tenant',\n snapshot: true,\n} as const;\n\n/** The `state.*` paths of `dataset_wording`'s snapshots a query filters, sorts and projects on. */\nexport type DatasetWordingStateField = 'state.appId' | 'state.dataset' | 'state.fields' | 'state.recordNoun' | 'state.title';\n\n/** The events of `dataset_wording`, named as the server sends them, `view-store.dataset_wording.<Event>` at its current revision (the `events` query upgrades older records), and the system events every aggregate has. */\nexport type DatasetWordingEvent = CommittedEvent<'view-store.dataset_wording.DatasetWordingCleared', DatasetWordingCleared> | CommittedEvent<'view-store.dataset_wording.DatasetWordingSet', DatasetWordingSet> | SystemEvent;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { CommittedEvent, SystemEvent } from '@ahoo-wang/wow-client';\nimport type { ViewAudienceChanged, ViewClaimed, ViewCreated, ViewRenamed, ViewSaved, ViewShared } from '../types.js';\n\n/**\n * The aggregate `view-store.view`.\n * A saved view of the view engine: a record view, an analysis view or a dashboard\n */\nexport const ViewAggregate = {\n context: 'view-store',\n name: 'view',\n path: '/view-store/view',\n ownership: 'owner',\n snapshot: true,\n} as const;\n\n/** The `state.*` paths of `view`'s snapshots a query filters, sorts and projects on. */\nexport type ViewStateField = 'state.appId' | 'state.audience' | 'state.config' | 'state.definitionId' | 'state.kind' | 'state.title';\n\n/** The events of `view`, named as the server sends them, `view-store.view.<Event>` at its current revision (the `events` query upgrades older records), and the system events every aggregate has. */\nexport type ViewEvent = CommittedEvent<'view-store.view.ViewAudienceChanged', ViewAudienceChanged> | CommittedEvent<'view-store.view.ViewClaimed', ViewClaimed> | CommittedEvent<'view-store.view.ViewCreated', ViewCreated> | CommittedEvent<'view-store.view.ViewRenamed', ViewRenamed> | CommittedEvent<'view-store.view.ViewSaved', ViewSaved> | CommittedEvent<'view-store.view.ViewShared', ViewShared> | SystemEvent;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { CommittedEvent, SystemEvent } from '@ahoo-wang/wow-client';\nimport type { ViewPreferencesSet } from '../types.js';\n\n/**\n * The aggregate `view-store.view_preferences`.\n * One owner's view preferences for one definition in one application\n */\nexport const ViewPreferencesAggregate = {\n context: 'view-store',\n name: 'view_preferences',\n path: '/view-store/view_preferences',\n ownership: 'owner',\n snapshot: true,\n} as const;\n\n/** The `state.*` paths of `view_preferences`'s snapshots a query filters, sorts and projects on. */\nexport type ViewPreferencesStateField = 'state.appId' | 'state.autoRun' | 'state.defaultInstanceId' | 'state.definitionId' | 'state.lastTabs' | 'state.order';\n\n/** The events of `view_preferences`, named as the server sends them, `view-store.view_preferences.<Event>` at its current revision (the `events` query upgrades older records), and the system events every aggregate has. */\nexport type ViewPreferencesEvent = CommittedEvent<'view-store.view_preferences.ViewPreferencesSet', ViewPreferencesSet> | SystemEvent;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { type Hop, wait } from '@ahoo-wang/wow-client';\nimport { DatasetWordingAggregate } from './dataset_wording/aggregate.js';\nimport { ViewAggregate } from './view/aggregate.js';\nimport { ViewPreferencesAggregate } from './view_preferences/aggregate.js';\n\n/**\n * The bounded context `view-store`: its name, its error codes and its aggregates, as the Kotlin `ViewStoreContract` names them. A problem's `code` is one of its `Errors`, or of an aggregate's.\n * The view engine's saved views, view preferences and dataset wording\n */\nexport const ViewStoreContract = {\n NAME: 'view-store',\n Errors: {\n /** 400: The request's CoSec scope has no application (behind the CoSec gateway, the one it forwarded). */\n APP_REQUIRED: 'view-store.app-required',\n /** 400: The request is not a valid write: its config, title, preferences or wording. */\n INVALID: 'view-store.invalid',\n /** 404: The aggregate belongs to another application, which reads as none. */\n NOT_FOUND: 'view-store.not-found',\n /** 400: A view is saved by an owner: a user, (shared), or (system) under (platform). */\n OWNER_REQUIRED: 'view-store.owner-required',\n /** 409: A shared dashboard shows the view, which stays shared. */\n REFERENCED_BY_SHARED_DASHBOARD: 'view-store.referenced-by-shared-dashboard',\n /** 403: A system view never moves audience: it is neither shared nor claimed. */\n SYSTEM_VIEW_READ_ONLY: 'view-store.system-view-read-only',\n },\n DatasetWording: DatasetWordingAggregate,\n View: ViewAggregate,\n ViewPreferences: ViewPreferencesAggregate,\n} as const;\n\n/** An error code of `view-store`, of the context or of one of its aggregates. */\nexport type ViewStoreErrorCode = 'view-store.app-required' | 'view-store.invalid' | 'view-store.not-found' | 'view-store.owner-required' | 'view-store.referenced-by-shared-dashboard' | 'view-store.system-view-read-only';\n\n/** The subscriptions of `view-store` a `handled` hop names. */\nexport type ViewStoreSubscription = 'ViewAudienceSaga.onAudienceChanged';\n\n/** The hops of a wait chain (`Wow-Wait`) in `view-store`. */\nexport const viewStoreWait = {\n /** Until a command of `view-store` passed admission. */\n accepted: (): Hop => wait.accepted(ViewStoreContract.NAME),\n /** Until a command's events are appended to the log of `view-store`. */\n committed: (): Hop => wait.committed(ViewStoreContract.NAME),\n /** Until the snapshot of `view-store` holds the commit. */\n snapshot: (): Hop => wait.snapshot(ViewStoreContract.NAME),\n /** Until a subscription of `view-store` handled the commit. */\n handled: (subscription: ViewStoreSubscription): Hop => wait.handled(subscription, ViewStoreContract.NAME),\n} as const;\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { MANIFEST_FORMAT, type RoutingManifest } from '@ahoo-wang/wow-client';\n\n/** The routes of `view-store`'s commands and service routes, as its Manifest lists them: what its clients send by, with no Manifest fetched and no schema. */\nexport const ViewStoreManifest: RoutingManifest = {\n format: MANIFEST_FORMAT,\n contexts: [\n {\n name: 'view-store',\n aggregates: [\n {\n name: 'dataset_wording',\n commands: [\n { name: 'ClearDatasetWording', routes: [{ method: 'POST', path: '/view-store/dataset_wording/{id}/clear-dataset-wording' }, { method: 'POST', path: '/view-store/dataset_wording/clear-dataset-wording' }] },\n { name: 'SetDatasetWording', routes: [{ method: 'POST', path: '/view-store/dataset_wording/{id}/set-dataset-wording' }, { method: 'POST', path: '/view-store/dataset_wording/set-dataset-wording' }] },\n ],\n },\n {\n name: 'view',\n commands: [\n { name: 'ClaimView', routes: [{ method: 'POST', path: '/view-store/view/{id}/claim-view' }] },\n { name: 'CreateView', routes: [{ method: 'POST', path: '/view-store/view/{id}/create-view' }, { method: 'POST', path: '/view-store/view/create-view' }] },\n { name: 'RenameView', routes: [{ method: 'POST', path: '/view-store/view/{id}/rename-view' }] },\n { name: 'SaveView', routes: [{ method: 'POST', path: '/view-store/view/{id}/save-view' }] },\n { name: 'ShareView', routes: [{ method: 'POST', path: '/view-store/view/{id}/share-view' }] },\n { name: 'wow.lifecycle.DeleteAggregate', routes: [{ method: 'DELETE', path: '/view-store/view/{id}' }] },\n { name: 'wow.lifecycle.TransferOwner', routes: [{ method: 'POST', path: '/view-store/view/{id}/wow.lifecycle.transfer-owner' }] },\n ],\n },\n {\n name: 'view_preferences',\n commands: [\n { name: 'SetViewPreferences', routes: [{ method: 'POST', path: '/view-store/view_preferences/{id}/set-view-preferences' }, { method: 'POST', path: '/view-store/view_preferences/set-view-preferences' }] },\n ],\n },\n ],\n routes: [\n { name: 'systemViews', route: { method: 'GET', path: '/view-store/system-views' } },\n { name: 'view', route: { method: 'GET', path: '/view-store/views/{id}' } },\n ],\n },\n ],\n};\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { CommandClient, type CommandOptions, type CommandResult, type CommandResultStream, type CreateCommandOptions, LifecycleCommands, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport { ViewStoreManifest } from '../manifest.js';\nimport type { ClaimView, CreateView, RenameView, SaveView, ShareView, WowLifecycleTransferOwner } from '../types.js';\n\n/** Sends the commands of `view-store.view` by its service's routes (`ViewStoreManifest`). Each method answers the result its wait plan ends with, as `CommandClient.wait` does: the server's default plan unless the options give one, `{ wait: WaitPlan.ACCEPTED }` to answer once it is accepted. A rejected command rejects with a `CommandRejectedError`; anything else that did not succeed with a `WowProblemError`. */\nexport class ViewCommandClient {\n readonly client: CommandClient;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.client = new CommandClient(options, { manifest: ViewStoreManifest });\n }\n\n /**\n * Make a shared view personal\n * `ClaimView`: `POST /view-store/view/{id}/claim-view`.\n * Produces `ViewClaimed`.\n */\n claimView(id: string, body: ClaimView = {}, options?: CommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.view.ClaimView', body, id });\n }\n\n /** `ClaimView`, answered as one result per hop of its wait (`text/event-stream`). */\n claimViewStream(id: string, body: ClaimView = {}, options?: CommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.view.ClaimView', body, id });\n }\n\n /**\n * Create a view\n * `CreateView`: `POST /view-store/view/{id}/create-view`, `POST /view-store/view/create-view`.\n * Creates the aggregate.\n * Produces `ViewCreated`.\n */\n createView(body: CreateView, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.view.CreateView', body });\n }\n\n /** `CreateView`, answered as one result per hop of its wait (`text/event-stream`). */\n createViewStream(body: CreateView, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.view.CreateView', body });\n }\n\n /**\n * Rename a view\n * `RenameView`: `POST /view-store/view/{id}/rename-view`.\n * Produces `ViewRenamed`.\n */\n renameView(id: string, body: RenameView, options?: CommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.view.RenameView', body, id });\n }\n\n /** `RenameView`, answered as one result per hop of its wait (`text/event-stream`). */\n renameViewStream(id: string, body: RenameView, options?: CommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.view.RenameView', body, id });\n }\n\n /**\n * Save a view's config\n * `SaveView`: `POST /view-store/view/{id}/save-view`.\n * Produces `ViewSaved`.\n */\n saveView(id: string, body: SaveView, options?: CommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.view.SaveView', body, id });\n }\n\n /** `SaveView`, answered as one result per hop of its wait (`text/event-stream`). */\n saveViewStream(id: string, body: SaveView, options?: CommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.view.SaveView', body, id });\n }\n\n /**\n * Make a view shared\n * `ShareView`: `POST /view-store/view/{id}/share-view`.\n * Produces `ViewShared`.\n */\n shareView(id: string, body: ShareView = {}, options?: CommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.view.ShareView', body, id });\n }\n\n /** `ShareView`, answered as one result per hop of its wait (`text/event-stream`). */\n shareViewStream(id: string, body: ShareView = {}, options?: CommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.view.ShareView', body, id });\n }\n\n /**\n * Marks the aggregate deleted; its events stay in the log.\n * The lifecycle command `wow.lifecycle.DeleteAggregate`.\n */\n deleteAggregate(id: string, options?: CommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: LifecycleCommands.DELETE_AGGREGATE, type: { context: 'view-store', name: 'view' }, id });\n }\n\n /** The lifecycle command `wow.lifecycle.TransferOwner`. */\n transferOwner(id: string, body: WowLifecycleTransferOwner, options?: CommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: LifecycleCommands.TRANSFER_OWNER, type: { context: 'view-store', name: 'view' }, id, body });\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { EventQueryClient, SnapshotQueryClient, StateClient, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { ViewState } from '../types.js';\nimport { ViewAggregate, type ViewEvent, type ViewStateField } from './aggregate.js';\n\n/** Queries the snapshots of `view-store.view`: `POST /view-store/view/snapshot/query`. */\nexport class ViewSnapshotQueryClient extends SnapshotQueryClient<ViewState, ViewStateField> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewAggregate, options);\n }\n}\n\n\n/** Queries the event streams of `view-store.view`, one record per commit: `POST /view-store/view/events/query`. */\nexport class ViewEventQueryClient extends EventQueryClient<ViewEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewAggregate, options);\n }\n}\n\n\n/** Reads the states of `view-store.view`, at a version or a time, and their traces: `GET /view-store/view/{id}/state`. */\nexport class ViewStateClient extends StateClient<ViewState, ViewEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewAggregate, options);\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { CommandClient, type CommandResult, type CommandResultStream, type CreateCommandOptions, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport { ViewStoreManifest } from '../manifest.js';\nimport type { SetViewPreferences } from '../types.js';\n\n/** Sends the commands of `view-store.view_preferences` by its service's routes (`ViewStoreManifest`). Each method answers the result its wait plan ends with, as `CommandClient.wait` does: the server's default plan unless the options give one, `{ wait: WaitPlan.ACCEPTED }` to answer once it is accepted. A rejected command rejects with a `CommandRejectedError`; anything else that did not succeed with a `WowProblemError`. */\nexport class ViewPreferencesCommandClient {\n readonly client: CommandClient;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.client = new CommandClient(options, { manifest: ViewStoreManifest });\n }\n\n /**\n * Set the view preferences of a definition\n * `SetViewPreferences`: `POST /view-store/view_preferences/{id}/set-view-preferences`, `POST /view-store/view_preferences/set-view-preferences`.\n * Creates the aggregate, or acts on the one that exists.\n * Produces `ViewPreferencesSet`.\n */\n setViewPreferences(body: SetViewPreferences, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.view_preferences.SetViewPreferences', body });\n }\n\n /** `SetViewPreferences`, answered as one result per hop of its wait (`text/event-stream`). */\n setViewPreferencesStream(body: SetViewPreferences, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.view_preferences.SetViewPreferences', body });\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { EventQueryClient, SnapshotQueryClient, StateClient, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { ViewPreferencesState } from '../types.js';\nimport { ViewPreferencesAggregate, type ViewPreferencesEvent, type ViewPreferencesStateField } from './aggregate.js';\n\n/** Queries the snapshots of `view-store.view_preferences`: `POST /view-store/view_preferences/snapshot/query`. */\nexport class ViewPreferencesSnapshotQueryClient extends SnapshotQueryClient<ViewPreferencesState, ViewPreferencesStateField> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewPreferencesAggregate, options);\n }\n}\n\n\n/** Queries the event streams of `view-store.view_preferences`, one record per commit: `POST /view-store/view_preferences/events/query`. */\nexport class ViewPreferencesEventQueryClient extends EventQueryClient<ViewPreferencesEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewPreferencesAggregate, options);\n }\n}\n\n\n/** Reads the states of `view-store.view_preferences`, at a version or a time, and their traces: `GET /view-store/view_preferences/{id}/state`. */\nexport class ViewPreferencesStateClient extends StateClient<ViewPreferencesState, ViewPreferencesEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(ViewPreferencesAggregate, options);\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport type { RequestOptions, WowClientOptions } from '@ahoo-wang/wow-client';\nimport { ServiceRoutes } from '@ahoo-wang/wow-client/routes';\nimport { ViewStoreManifest } from './manifest.js';\nimport type { SystemView, ViewEntry } from './types.js';\n\n/** The service routes of `view-store`: routes whose handler is the service's own code, each called by its Manifest's name. */\nexport class ViewStoreRoutes {\n /** Calls any route of the service by its name. */\n readonly routes: ServiceRoutes;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.routes = new ServiceRoutes(options, { manifest: ViewStoreManifest });\n }\n\n /**\n * The system views of the caller's tenant and application, of definitionId when it is given and not blank.\n * `GET /view-store/system-views`\n */\n systemViews(query?: { readonly definitionId?: string; }, options?: RequestOptions): Promise<SystemView[]> {\n return this.routes.call('view-store', 'systemViews', { query }, options) as Promise<SystemView[]>;\n }\n\n /**\n * The view id as the caller reads it: its own personal view, else a shared view of its tenant, else a system view of its tenant and application; `view-store.not-found` when none is.\n * `GET /view-store/views/{id}`\n */\n view(id: string, options?: RequestOptions): Promise<ViewEntry> {\n return this.routes.call('view-store', 'view', { path: { id } }, options) as Promise<ViewEntry>;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FrameworkErrorCodes,\n CommandRejectedError,\n toWowProblemError,\n WowProblemError,\n} from '@ahoo-wang/wow-client';\nimport {\n isViewStoreError,\n ViewStoreError,\n type ViewStoreErrorCode,\n} from '@ahoo-wang/wow-view-engine';\nimport { ViewStoreContract } from './generated/view-store/contract.js';\n\n/**\n * The V10 view store's own problem codes (`ViewStoreRejections` of\n * `platform/view-store`), beside the framework's (`FrameworkErrorCodes` of\n * `@ahoo-wang/wow-client`): generated from the service's Manifest.\n *\n * Named apart from the engine's `ViewStoreErrorCode` (the port's codes):\n * these are the `code` of the server's problems, which a `ViewStoreError`\n * carries as `detail.code`.\n */\nexport const WowViewStoreErrorCodes = ViewStoreContract.Errors;\n\n/** One of {@link WowViewStoreErrorCodes}: a problem code the server answers. */\nexport type WowViewStoreErrorCode =\n (typeof WowViewStoreErrorCodes)[keyof typeof WowViewStoreErrorCodes];\n\n/** The port's code of each problem code the server answers with. */\nconst CODES: Readonly<Record<string, ViewStoreErrorCode>> = {\n [FrameworkErrorCodes.AGGREGATE_VERSION_MISMATCH]: 'CONFLICT',\n // A request id another command already used: the write cannot be told\n // from that one, so it is refused as the stale write it most likely is.\n [FrameworkErrorCodes.COMMAND_REQUEST_ID_REUSED]: 'CONFLICT',\n [FrameworkErrorCodes.AGGREGATE_NOT_FOUND]: 'NOT_FOUND',\n [FrameworkErrorCodes.QUERY_NOT_FOUND]: 'NOT_FOUND',\n [FrameworkErrorCodes.AGGREGATE_DELETED]: 'NOT_FOUND',\n [ViewStoreContract.Errors.NOT_FOUND]: 'NOT_FOUND',\n [FrameworkErrorCodes.AUTH_UNAUTHENTICATED]: 'FORBIDDEN',\n [FrameworkErrorCodes.AUTH_FORBIDDEN]: 'FORBIDDEN',\n [FrameworkErrorCodes.AGGREGATE_FORBIDDEN]: 'FORBIDDEN',\n [ViewStoreContract.Errors.SYSTEM_VIEW_READ_ONLY]: 'FORBIDDEN',\n [ViewStoreContract.Errors.INVALID]: 'INVALID',\n [ViewStoreContract.Errors.APP_REQUIRED]: 'INVALID',\n [ViewStoreContract.Errors.OWNER_REQUIRED]: 'INVALID',\n [ViewStoreContract.Errors.REFERENCED_BY_SHARED_DASHBOARD]: 'INVALID',\n [FrameworkErrorCodes.AGGREGATE_EXISTS]: 'INVALID',\n [FrameworkErrorCodes.COMMAND_MALFORMED]: 'INVALID',\n [FrameworkErrorCodes.COMMAND_INVALID]: 'INVALID',\n [FrameworkErrorCodes.COMMAND_UNHANDLED]: 'INVALID',\n [FrameworkErrorCodes.WAIT_INVALID]: 'INVALID',\n [FrameworkErrorCodes.QUERY_MALFORMED]: 'INVALID',\n [FrameworkErrorCodes.QUERY_INVALID]: 'INVALID',\n};\n\n/**\n * A request that did not succeed, as the store reads it: the server's\n * problem when it answered with one, else what the request threw.\n */\nexport class Failure {\n constructor(\n /** What the request threw. */\n readonly cause: unknown,\n /** The server's problem, when a response came back. */\n readonly problem?: WowProblemError,\n /** The command's rejection, when its result came back rejected without a problem. */\n readonly rejection?: CommandRejectedError,\n ) {}\n\n /** The problem's code, or the rejection's: a framework code (`wow.*`) or the view store's. */\n get problemCode(): string | undefined {\n return this.problem?.code ?? this.rejection?.code;\n }\n\n /**\n * The port's code, **by the problem's code first**: one HTTP status\n * carries several decisions (a `400` is a bad title and a missing\n * application alike). Only an answer without a code the store knows — a\n * gateway's own page, a proxy, a code a later server adds — falls back to\n * the status; a problem the service says a retry may get past is\n * `UNAVAILABLE` whatever its status. A `404` without a code is a route the server does not serve:\n * no view store there (or, on the memory backend, no snapshot query), so\n * `UNSUPPORTED`. No answer at all is `UNAVAILABLE`: the outcome is\n * unknown, and a retry under the same request id is safe, since the\n * server deduplicates it.\n */\n get code(): ViewStoreErrorCode {\n const code = this.problemCode;\n const known = code === undefined ? undefined : CODES[code];\n if (known) return known;\n // What a retry may get past (a busy or closing node, a store out of\n // reach, contended writers, a wait that ran out): the outcome is unknown.\n if (this.problem !== undefined && this.problem.retry !== 'none') {\n return 'UNAVAILABLE';\n }\n // The aggregate refused the command in the state it is in.\n if (this.problem === undefined && this.rejection) return 'CONFLICT';\n switch (this.problem?.status) {\n case 400:\n case 422:\n return 'INVALID';\n case 401:\n case 403:\n return 'FORBIDDEN';\n case 404:\n return code === undefined ? 'UNSUPPORTED' : 'NOT_FOUND';\n case 410:\n return 'NOT_FOUND';\n case 409:\n case 412:\n return 'CONFLICT';\n default:\n return 'UNAVAILABLE';\n }\n }\n\n /** Whether the server (or something in front of it) answered at all. */\n get reached(): boolean {\n return this.problem !== undefined || this.rejection !== undefined;\n }\n\n get message(): string {\n if (this.problem) return this.problem.message;\n if (this.rejection) return this.rejection.message;\n return `The view store could not be reached: ${reasonOf(this.cause)}`;\n }\n\n /** The port's error, holding what it was read from. */\n toStoreError(): ViewStoreError {\n return new ViewStoreError(this.code, this.message, this.held());\n }\n\n /**\n * What {@link toStoreError} holds, for an error of another code: the\n * request's own failure as `cause`, the problem's code as `detail` (a\n * host tells `view-store.app-required` from `view-store.invalid` by it),\n * and for `UNAVAILABLE` whether the server answered (`reachable`).\n */\n held(): {\n cause: unknown;\n detail?: { code: string };\n reachable?: true;\n } {\n const code = this.problemCode;\n return {\n cause: this.cause,\n ...(code === undefined ? {} : { detail: { code } }),\n ...(this.code === 'UNAVAILABLE' && this.reached\n ? { reachable: true as const }\n : {}),\n };\n }\n}\n\n/** What a failed request threw, read as a {@link Failure}. */\nexport async function failureOf(error: unknown): Promise<Failure> {\n if (error instanceof Failure) return error;\n // A rejection the service answered with a problem reads as that problem.\n if (error instanceof CommandRejectedError) {\n return error.cause instanceof WowProblemError\n ? new Failure(error, error.cause)\n : new Failure(error, undefined, error);\n }\n return new Failure(error, await toWowProblemError(error));\n}\n\n/**\n * The titles of the shared dashboards a claim refusal names: the problem's\n * `boards` extension member, a list of `{ id, title }`. A\n * board without a title is named by its id; anything else is skipped.\n */\nexport function boardTitles(\n extensions: Readonly<Record<string, unknown>> | undefined,\n): string[] {\n const boards = extensions?.boards;\n if (!Array.isArray(boards)) return [];\n return boards.flatMap((board: unknown) => {\n if (typeof board !== 'object' || board === null) return [];\n const { id, title } = board as { id?: unknown; title?: unknown };\n if (typeof title === 'string' && title.trim() !== '') return [title];\n return typeof id === 'string' ? [id] : [];\n });\n}\n\n/**\n * Runs one of the port's methods, so that everything it rejects with is a\n * `ViewStoreError`: a failed request as its code says, anything else — a\n * body that did not parse — as `UNAVAILABLE`, the outcome unknown.\n */\nexport async function guard<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (thrown) {\n if (thrown instanceof Failure) throw thrown.toStoreError();\n if (isViewStoreError(thrown)) throw thrown;\n // A body that did not parse came back from something — a login wall's\n // page, a proxy's: answered, so not \"could not be reached\".\n throw new ViewStoreError(\n 'UNAVAILABLE',\n thrown instanceof Error ? thrown.message : String(thrown),\n {\n cause: thrown,\n ...(thrown instanceof SyntaxError ? { reachable: true as const } : {}),\n },\n );\n }\n}\n\n/** Runs one request, so that what it throws is a {@link Failure}. */\nexport async function request<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (error) {\n // A body that did not parse is no failed request: `guard` reads it.\n if (error instanceof SyntaxError) throw error;\n throw await failureOf(error);\n }\n}\n\n/** What a refusal said; a `DOMException` is an `Error` only in some realms. */\nfunction reasonOf(error: unknown): string {\n if (typeof error === 'object' && error !== null) {\n const { name, message } = error as { name?: unknown; message?: unknown };\n if (typeof message === 'string')\n return typeof name === 'string' ? `${name}: ${message}` : message;\n }\n return String(error);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * The V10 view store's shapes, as far as the store reads them, and their\n * reading as the port's. The server stores the engine's `ViewConfig` whole\n * and never reads its meaning; it keeps the config's `kind` beside it, as\n * `state.kind`, which a list projects and filters on.\n */\n\nimport type { TargetScope } from '@ahoo-wang/wow-client';\nimport type {\n DatasetOverrides,\n ViewConfig,\n ViewInstance,\n ViewInstanceSummary,\n} from '@ahoo-wang/wow-view-engine';\nimport { revisionOf } from './views.js';\nimport {\n SHARED_OWNER_ID,\n SYSTEM_OWNER_ID,\n SYSTEM_TENANT_ID,\n type Place,\n} from './paths.js';\nimport type {\n DatasetWordingState,\n ViewState,\n} from './generated/view-store/types.js';\n\n/** The `Wow-Scope` of the shared views: the reserved owner `(shared)`. */\nexport const SHARED_SCOPE: TargetScope = Object.freeze({\n ownerId: SHARED_OWNER_ID,\n});\n\n/** The `Wow-Scope` of the stored system views: `(system)` of `(platform)`. */\nexport const SYSTEM_SCOPE: TargetScope = Object.freeze({\n tenantId: SYSTEM_TENANT_ID,\n ownerId: SYSTEM_OWNER_ID,\n});\n\n/**\n * The `Wow-Scope` a request at `place` carries: none for the caller's own\n * views, whose owner the server takes from the principal.\n */\nexport function scopeAt(place: Place): TargetScope | undefined {\n switch (place) {\n case 'shared':\n return SHARED_SCOPE;\n case 'system':\n return SYSTEM_SCOPE;\n default:\n return undefined;\n }\n}\n\n/** A view as a list reads it: its id, version and the fields of a summary. */\nexport interface ViewSummaryRecord {\n id: string;\n version: number;\n state: Pick<ViewState, 'definitionId' | 'title' | 'audience' | 'kind'>;\n}\n\n/** A view read whole: a summary's fields and its config. */\nexport interface ViewRecord extends ViewSummaryRecord {\n state: ViewSummaryRecord['state'] & Pick<ViewState, 'config'>;\n}\n\n/** The fields a list reads, and of the config only its `kind`, kept apart. */\nexport const SUMMARY_FIELDS = [\n 'aggregateId',\n 'version',\n 'state.definitionId',\n 'state.title',\n 'state.audience',\n 'state.kind',\n] as const;\n\nexport function toInstance({ id, version, state }: ViewRecord): ViewInstance {\n return {\n id,\n definitionId: state.definitionId,\n title: state.title,\n scope: state.audience,\n revision: revisionOf(version),\n config: state.config as unknown as ViewConfig,\n };\n}\n\nexport function toSummary({\n id,\n version,\n state,\n}: ViewSummaryRecord): ViewInstanceSummary {\n return {\n id,\n definitionId: state.definitionId,\n title: state.title,\n scope: state.audience,\n kind: state.kind,\n revision: revisionOf(version),\n };\n}\n\n/** The engine's overrides from a stored wording: what is stored, nothing more. */\nexport function wordingOf(\n state: Pick<DatasetWordingState, 'title' | 'recordNoun' | 'fields'>,\n): DatasetOverrides {\n return {\n ...(state.title == null ? {} : { title: state.title }),\n ...(state.recordNoun == null ? {} : { recordNoun: state.recordNoun }),\n ...(state.fields == null\n ? {}\n : { fields: state.fields as DatasetOverrides['fields'] }),\n };\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Fetcher } from '@ahoo-wang/fetcher';\nimport {\n asc,\n cursorQuery,\n filter,\n singleQuery,\n} from '@ahoo-wang/wow-client/dsl';\nimport {\n type CommandOptions,\n type CommandResult,\n WaitPlan,\n type WowClientOptions,\n} from '@ahoo-wang/wow-client';\nimport {\n emptyPreferences,\n isSystemInstanceId,\n ViewStoreError,\n type ViewAudience,\n type ViewConfig,\n type ViewInstance,\n type ViewInstanceSummary,\n type ViewListOptions,\n type ViewListPage,\n type ReadOptions,\n type ViewPermissions,\n type ViewPreferences,\n type ViewStore,\n type WriteOptions,\n} from '@ahoo-wang/wow-view-engine';\nimport { SHARED_OWNER_ID, SYSTEM_OWNER_ID, type Place } from './paths.js';\nimport { Remembered } from './remembered.js';\nimport {\n isStored,\n preferencesAt,\n preferencesInput,\n systemSummary,\n toPreferences,\n viewInstance,\n} from './views.js';\nimport {\n ViewStoreContract,\n viewStoreWait,\n} from './generated/view-store/contract.js';\nimport { ViewCommandClient } from './generated/view-store/view/commandClient.js';\nimport {\n ViewSnapshotQueryClient,\n ViewStateClient,\n} from './generated/view-store/view/queryClient.js';\nimport { ViewPreferencesCommandClient } from './generated/view-store/view_preferences/commandClient.js';\nimport { ViewPreferencesSnapshotQueryClient } from './generated/view-store/view_preferences/queryClient.js';\nimport { ViewStoreRoutes } from './generated/view-store/routes.js';\nimport type {\n SystemView,\n ViewEntry,\n ViewState,\n} from './generated/view-store/types.js';\nimport { boardTitles, Failure, guard, request } from './errors.js';\nimport {\n scopeAt,\n SUMMARY_FIELDS,\n toInstance,\n toSummary,\n type ViewRecord,\n} from './wire.js';\n\n/** How a V10 {@link WowViewStore} reaches the view store service. */\nexport interface WowViewStoreOptions {\n /**\n * The fetcher every request goes through, on the base URL that serves\n * `/view-store/…` (the V10 view store service, or a gateway in front of\n * it).\n *\n * Its interceptors carry who is asking; the store never does. The V10\n * service takes the tenant and the owner from the principal, so no path\n * names them: the interceptors send the authorization (CoSec's token, or\n * the headers the service's own caller resolver reads) and `CoSec-App-Id`,\n * the application every view, preference and wording is kept in. The\n * store adds `Wow-Scope` itself where it acts as a reserved owner: the\n * shared views' `(shared)`, and `(system)` of `(platform)` for stored\n * system views.\n */\n fetcher: Fetcher;\n /**\n * Which buttons are enabled for one definition's views. The service\n * authorizes each write; a host answers this by the roles it holds there —\n * `changeAudience` and the shared views' writes by the role that writes\n * the owner `(shared)` (`view-store.shared-writer` on the service as\n * shipped), `editSystem` by the one that writes `(system)`. Left out,\n * everything is allowed, as the port reads a store without `permissions`.\n */\n permissions?: (definitionId: string) => ViewPermissions;\n /**\n * The most views one page of `list` answers; 100, the service's default\n * cursor page limit over HTTP, when left out. A test sets it low to read\n * a list across pages, and across audiences, with few views.\n */\n pageSize?: number;\n}\n\n/** The views one page of `list` answers when the options say none. */\nconst LIST_PAGE = 100;\n\n/** Where a list page starts: the audience being read, and its own cursor. */\ninterface ListAt {\n audience: 'system' | 'shared' | 'personal';\n cursor: string | null;\n}\n\n/** A list page's cursor: {@link ListAt} as base64url JSON, opaque to the engine. */\nfunction listCursor(at: ListAt): string {\n return btoa(JSON.stringify(at))\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+$/, '');\n}\n\n/** The page a cursor names; the first page without one. */\nfunction readListCursor(cursor: string | null | undefined): ListAt {\n if (!cursor) return { audience: 'system', cursor: null };\n try {\n const at = JSON.parse(\n atob(cursor.replace(/-/g, '+').replace(/_/g, '/')),\n ) as ListAt;\n if (['system', 'shared', 'personal'].includes(at.audience)) return at;\n } catch {\n // Read as the malformed cursor below.\n }\n throw new ViewStoreError('INVALID', `Not a view list cursor: ${cursor}`);\n}\n\n/** How many system views' revisions the store remembers the version of. */\nconst REMEMBERED_SYSTEM_REVISIONS = 1024;\n\n/**\n * What a share or a claim waits for: the saga that moves the view to its\n * new owner, then that move's snapshot. The view's own commit changes its\n * audience; the owner, which reads and writes go by, changes one version\n * later (`ViewAudienceSaga`).\n */\nconst AUDIENCE_WAIT = WaitPlan.of(\n viewStoreWait.handled('ViewAudienceSaga.onAudienceChanged'),\n viewStoreWait.snapshot(),\n);\n\n/** One instance write, as sent from the place the view is at. */\ninterface InstanceWrite {\n /** Sends it with the options the store fills. */\n send(options: CommandOptions): Promise<CommandResult>;\n /** The place whose `Wow-Scope` it is sent with. */\n sentFrom: Place;\n /** Where the view is once it lands; `null` for a delete. */\n landsAt: Place | null;\n /** A share or a claim: it moves the view, waiting for the move. */\n moves?: boolean;\n}\n\n/**\n * The view engine's `ViewStore` over the **V10** view store service\n * (`platform/view-store` in the Wow repository): saved views and preferences\n * as two Wow V10 aggregates, reached through the clients generated from the\n * service's Manifest (`@ahoo-wang/wow-client`), and the system views and\n * the read by id through the service's own routes.\n *\n * **The owner is the audience.** A personal view is the caller's own; a\n * shared one belongs to the reserved owner `(shared)`, which the store acts\n * as with `Wow-Scope: owner=\"(shared)\"`; a stored system view to `(system)`\n * of the tenant `(platform)`. The port names a view by id alone, so the\n * store remembers where it last saw each one; one read by id answers a\n * view wherever it is, the caller's own first, then a shared one, then a\n * system view (`GET /view-store/views/{id}`).\n * Sharing and claiming move a view to the other owner in place, id kept:\n * the store waits for the service's `ViewAudienceSaga` to move it.\n *\n * **Writes** carry the port's `requestId` as `Wow-Request-Id` and its\n * `revision` as `If-Match`, and wait for the snapshot. The service\n * deduplicates a request id, creates included, so a retry is answered with\n * the first attempt's outcome; the store answers the view read back at the\n * version that write left (`GET …/{id}/state?version=`). A stale revision\n * is `CONFLICT` carrying the view as it is now.\n *\n * **Errors** are read by the problem's code onto the port's codes, by the\n * HTTP status only for an answer without a code the store knows; a `404`\n * without a code is a route the service does not serve (`UNSUPPORTED`), and\n * a request that got no answer is `UNAVAILABLE`.\n */\nexport class WowViewStore implements ViewStore {\n /** The host's {@link WowViewStoreOptions.permissions}, when it gave any. */\n readonly permissions?: (definitionId: string) => ViewPermissions;\n private readonly commands: ViewCommandClient;\n private readonly snapshots: ViewSnapshotQueryClient;\n private readonly states: ViewStateClient;\n private readonly preferenceCommands: ViewPreferencesCommandClient;\n private readonly preferenceSnapshots: ViewPreferencesSnapshotQueryClient;\n private readonly routes: ViewStoreRoutes;\n /** Where each view was last seen, by id. */\n private readonly places = new Map<string, Place>();\n /**\n * The version of each stored system view at each revision the store has\n * seen it at (a hash of its content, while a write expects the version),\n * by `id` and revision; `null` for a configured one, which is read-only.\n * Keeping the old revisions too lets a retry send the version its first\n * attempt expected, which the service then answers as a duplicate.\n */\n private readonly systemVersions = new Remembered<number | null>(\n REMEMBERED_SYSTEM_REVISIONS,\n );\n\n /** See `WowViewStoreOptions.pageSize`. */\n private readonly pageSize: number;\n\n constructor(options: WowViewStoreOptions) {\n this.pageSize = options.pageSize ?? LIST_PAGE;\n const client: WowClientOptions = { fetcher: options.fetcher };\n this.commands = new ViewCommandClient(client);\n this.snapshots = new ViewSnapshotQueryClient(client);\n this.states = new ViewStateClient(client);\n this.preferenceCommands = new ViewPreferencesCommandClient(client);\n this.preferenceSnapshots = new ViewPreferencesSnapshotQueryClient(client);\n this.routes = new ViewStoreRoutes(client);\n // Left undefined when the host declared none, which the port reads as\n // \"everything is allowed\".\n if (options.permissions) this.permissions = options.permissions;\n }\n\n /**\n * The definition's views a page at a time, in the port's order: the\n * service's system views first, whole, then the shared views, then the\n * caller's own, each read with the snapshot model's cursor, oldest first\n * (the service sorts by the time a view's first event was written, then\n * by its id). One call reads on into the next audience while its page has\n * room, so a definition with few views answers one page; the page's cursor\n * names the audience being read and that audience's own cursor.\n */\n list(\n definitionId: string,\n options: ViewListOptions = {},\n ): Promise<ViewListPage> {\n return guard(async () => {\n const { signal } = options;\n const items: ViewInstanceSummary[] = [];\n let at: ListAt | null = readListCursor(options.cursor);\n while (at !== null && items.length < this.pageSize) {\n const room = this.pageSize - items.length;\n const read = await this.listAudience(definitionId, at, room, signal);\n items.push(...read.items);\n at = read.next;\n }\n for (const summary of items) this.places.set(summary.id, summary.scope);\n return { items, nextCursor: at === null ? null : listCursor(at) };\n });\n }\n\n /** One read of one audience, and where the list goes on after it. */\n private async listAudience(\n definitionId: string,\n at: ListAt,\n size: number,\n signal: AbortSignal | undefined,\n ): Promise<{ items: ViewInstanceSummary[]; next: ListAt | null }> {\n if (at.audience === 'system') {\n const system = await request(() =>\n this.routes.systemViews({ definitionId }, { signal }),\n );\n for (const view of system) this.rememberSystem(view);\n return {\n items: system.map(systemSummary),\n next: { audience: 'shared', cursor: null },\n };\n }\n const page = await request(() =>\n this.snapshots.cursor(\n cursorQuery({\n filter: filter.eq('state.definitionId', definitionId),\n projection: { include: [...SUMMARY_FIELDS] },\n sort: [asc('firstEventTime')],\n size,\n cursor: at.cursor,\n }),\n at.audience === 'shared'\n ? { scope: scopeAt('shared'), signal }\n : { signal },\n ),\n );\n const items = page.list.map(record => toSummary(recordOf(record)));\n const next: ListAt | null =\n page.nextCursor !== null\n ? { audience: at.audience, cursor: page.nextCursor }\n : at.audience === 'shared'\n ? { audience: 'personal', cursor: null }\n : null;\n return { items, next };\n }\n\n /** View `id` wherever it is: the caller's, shared, or a system view. */\n get(id: string, options: ReadOptions = {}): Promise<ViewInstance> {\n return guard(async () => (await this.read(id, options.signal)).instance);\n }\n\n /**\n * Creates the view as the owner of its `scope`; the service generates the\n * id. A retry under the same request id is answered with the first\n * attempt's view, whichever store sends it: the service deduplicates it.\n */\n create(\n input: Omit<ViewInstance, 'id' | 'revision'>,\n context: WriteOptions,\n ): Promise<ViewInstance> {\n return guard(async () => {\n const place: Place = input.scope;\n const { definitionId, title, config } = input;\n const write: InstanceWrite = {\n send: options =>\n this.commands.createView(\n { definitionId, title, config: bodyOf(config) },\n options,\n ),\n sentFrom: place,\n landsAt: place,\n };\n const result = await request(() =>\n write.send(this.commandOptions(place, context)),\n );\n return (await this.landed(result.ref.id, write, result, context))!;\n });\n }\n\n /** Replaces the view's config, at the expected `revision`. */\n save(\n id: string,\n config: ViewConfig,\n revision: string,\n context: WriteOptions,\n ): Promise<ViewInstance> {\n return this.write(id, revision, context, place => ({\n send: options =>\n this.commands.saveView(id, { config: bodyOf(config) }, options),\n sentFrom: place,\n landsAt: place,\n })) as Promise<ViewInstance>;\n }\n\n /** Renames the view (the service trims the title), at the expected `revision`. */\n rename(\n id: string,\n title: string,\n revision: string,\n context: WriteOptions,\n ): Promise<ViewInstance> {\n return this.write(id, revision, context, place => ({\n send: options => this.commands.renameView(id, { title }, options),\n sentFrom: place,\n landsAt: place,\n })) as Promise<ViewInstance>;\n }\n\n /**\n * 设为共享 sends `share-view` as the caller, the view's owner; 设为个人\n * sends `claim-view` as `(shared)`, which the service admits only with\n * the role that writes the owner `(shared)`, and which makes the caller\n * the owner. Either waits for the move (`ViewAudienceSaga`). Each is sent\n * from the same owner whether or not the view has moved, so a retry is\n * answered as its first attempt's duplicate even after the move.\n *\n * Asked for the audience the view already has, the service refuses the\n * command as outside that owner's scope; the store then answers the view\n * as it is, revision unmoved, once the revision matches.\n *\n * A shared view a shared dashboard shows stays shared: the service\n * refuses the claim and names the boards, and the refusal carries them by\n * **title** in `boards`, as they are stored.\n */\n changeAudience(\n id: string,\n audience: ViewAudience,\n revision: string,\n context: WriteOptions,\n ): Promise<ViewInstance> {\n return this.write(id, revision, context, place => {\n if (place === 'system') readOnly('A system view never moves audience');\n return audience === 'shared'\n ? {\n send: options => this.commands.shareView(id, {}, options),\n sentFrom: 'personal',\n landsAt: 'shared',\n moves: true,\n }\n : {\n send: options => this.commands.claimView(id, {}, options),\n sentFrom: 'shared',\n landsAt: 'personal',\n moves: true,\n };\n }) as Promise<ViewInstance>;\n }\n\n /** Deletes the view, at the expected `revision`; a board showing it keeps a broken panel. */\n async delete(\n id: string,\n revision: string,\n context: WriteOptions,\n ): Promise<void> {\n await this.write(id, revision, context, place => ({\n send: options => this.commands.deleteAggregate(id, options),\n sentFrom: place,\n landsAt: null,\n }));\n }\n\n /**\n * The caller's preferences of the definition, in the request's\n * application: the service derives their id from the owner, the\n * application and the definition. None written yet reads as the port's\n * empty preferences, at revision `'0'`.\n */\n getPreferences(\n definitionId: string,\n options: ReadOptions = {},\n ): Promise<ViewPreferences> {\n const { signal } = options;\n return guard(async () => {\n const record = await request(() =>\n this.preferenceSnapshots.single(\n singleQuery({\n filter: filter.eq('state.definitionId', definitionId),\n }),\n { signal },\n ),\n );\n // None written yet: the port's empty preferences.\n if (record === undefined) return emptyPreferences();\n return toPreferences({ ...record.state, version: record.version });\n });\n }\n\n /**\n * Writes the preferences at the expected `revision` (`'0'` for ones never\n * written, which `If-Match: \"0\"` says). A retry under the same request id\n * is answered as the first attempt's duplicate, at its version.\n */\n setPreferences(\n definitionId: string,\n preferences: ViewPreferences,\n context: WriteOptions,\n ): Promise<ViewPreferences> {\n return guard(async () => {\n const { requestId, signal } = context;\n try {\n const result = await request(() =>\n this.preferenceCommands.setViewPreferences(\n { definitionId, ...preferencesInput(preferences) },\n {\n requestId,\n expectedVersion: versionOf(preferences.revision),\n ...(signal === undefined ? {} : { signal }),\n },\n ),\n );\n return typeof result.version === 'number'\n ? preferencesAt(preferences, result.version)\n : await this.getPreferences(definitionId, { signal });\n } catch (thrown) {\n if (!(thrown instanceof Failure) || thrown.code !== 'CONFLICT')\n throw thrown;\n throw new ViewStoreError('CONFLICT', thrown.message, {\n ...thrown.held(),\n preferences: await this.getPreferences(definitionId, { signal }),\n });\n }\n });\n }\n\n /**\n * One instance write: to the place the view is at, then the answer read\n * back. A view remembered at a place it has since left (another tab shared\n * it) is looked up again and the write sent once more from where it is.\n * A move refused because the view already has the audience it asks for\n * changes nothing: the view is answered as it is, once its revision\n * matches.\n */\n private write(\n id: string,\n revision: string,\n context: WriteOptions,\n plan: (place: Place) => InstanceWrite,\n ): Promise<ViewInstance | undefined> {\n return guard(async () => {\n const { signal } = context;\n const remembered = this.places.get(id);\n let place = remembered ?? (await this.read(id, signal)).place;\n let relocated = remembered === undefined;\n for (;;) {\n const write = plan(place);\n const options = this.commandOptions(write.sentFrom, context, {\n expectedVersion:\n place === 'system'\n ? await this.systemVersion(id, revision, signal)\n : versionOf(revision),\n ...(write.moves ? { wait: AUDIENCE_WAIT } : {}),\n });\n let result: CommandResult;\n try {\n result = await request(() => write.send(options));\n } catch (thrown) {\n if (!(thrown instanceof Failure)) throw thrown;\n if (\n write.moves &&\n place === write.landsAt &&\n thrown.code === 'FORBIDDEN'\n )\n return this.unchanged(id, revision, place, signal);\n if (\n !relocated &&\n (thrown.code === 'NOT_FOUND' || thrown.code === 'FORBIDDEN')\n ) {\n relocated = true;\n const found = (await this.read(id, signal)).place;\n if (found !== place) {\n place = found;\n continue;\n }\n }\n if (thrown.code === 'CONFLICT')\n throw await this.conflict(id, thrown, signal);\n throw refusal(thrown);\n }\n // Landed: what goes wrong reading it back is never a reason to send\n // it again.\n return this.landed(id, write, result, context);\n }\n });\n }\n\n /**\n * A landed write's answer: the view read back at the version it left\n * (`GET …/{id}/state?version=`). A system view's revision is its content\n * hash, so it is read by id as it is now.\n *\n * A move is two commits: the view's own (its audience), then the saga's\n * (its owner). Waited for, the result's version is the second; a\n * duplicate answers the first, so the move is read one version later,\n * where the owner it names must be the one it moved to. Anything else\n * (another writer between the two) answers the view as it is now.\n */\n private async landed(\n id: string,\n write: InstanceWrite,\n result: CommandResult,\n context: WriteOptions,\n ): Promise<ViewInstance | undefined> {\n const { landsAt } = write;\n if (landsAt === null) return undefined;\n this.places.set(id, landsAt);\n const { signal } = context;\n const read = typeof result.version === 'number' ? result.version : null;\n if (landsAt !== 'system' && read !== null)\n try {\n const version = write.moves && result.duplicate ? read + 1 : read;\n const view = await request(() =>\n this.states.get(id, {\n version,\n ...optionsAt(landsAt),\n ...(signal === undefined ? {} : { signal }),\n }),\n );\n if (!write.moves || ownedAt(view.ownerId) === landsAt)\n return toInstance({ id, version: view.version, state: view.state });\n } catch {\n // Moved on since (another tab moved it): answered as it is.\n }\n return (await this.read(id, signal)).instance;\n }\n\n /** A move to where the view already is: the view as it is, at `revision`. */\n private async unchanged(\n id: string,\n revision: string,\n place: Place,\n signal: AbortSignal | undefined,\n ): Promise<ViewInstance> {\n const { instance } = await this.read(id, signal);\n if (instance.scope !== place || instance.revision !== revision)\n throw new ViewStoreError(\n 'CONFLICT',\n `View ${id} has moved on from revision ${revision}`,\n { instance },\n );\n return instance;\n }\n\n /** A stale write's refusal, carrying the view as it is now. */\n private async conflict(\n id: string,\n failure: Failure,\n signal: AbortSignal | undefined,\n ): Promise<ViewStoreError> {\n const { instance } = await this.read(id, signal);\n return new ViewStoreError('CONFLICT', failure.message, {\n ...failure.held(),\n instance,\n });\n }\n\n /**\n * View `id` as it is now and where it is, in one read: the service answers\n * the caller's own view of that id, else a shared one, else a system view.\n */\n private async read(\n id: string,\n signal: AbortSignal | undefined,\n ): Promise<{ place: Place; instance: ViewInstance }> {\n // Ids in `system:` are the views a host declares in code; the service\n // never issues or serves one.\n if (isSystemInstanceId(id))\n throw new ViewStoreError('NOT_FOUND', `No such view: ${id}`);\n const entry = await request(() => this.routes.view(id, { signal }));\n const place: Place = entry.scope;\n this.places.set(id, place);\n if (place === 'system') this.rememberSystem(entry);\n return { place, instance: viewInstance(entry) };\n }\n\n /** Keeps the version of a stored system view at its revision; a configured one as read-only. */\n private rememberSystem(view: SystemView | ViewEntry): void {\n this.systemVersions.set(\n revisionKey(view.id, view.revision),\n isStored(view) ? view.version! : null,\n );\n }\n\n /**\n * The version a write of stored system view `id` at `revision` (its\n * content hash) expects: as seen at that revision, else as read now. A\n * configured system view is read-only (`FORBIDDEN`; a code one is never\n * found here); a revision other than the view's, or a view of that id\n * that is no longer a system view, is `CONFLICT`, carrying the view as it\n * is.\n */\n private async systemVersion(\n id: string,\n revision: string,\n signal: AbortSignal | undefined,\n ): Promise<number> {\n const key = revisionKey(id, revision);\n if (!this.systemVersions.has(key)) {\n const { instance } = await this.read(id, signal);\n if (instance.scope !== 'system')\n throw new ViewStoreError(\n 'CONFLICT',\n `View ${id} is no longer a system view`,\n { instance },\n );\n if (instance.revision !== revision && instance.stored)\n throw new ViewStoreError(\n 'CONFLICT',\n `System view ${id} has moved on from revision ${revision}`,\n { instance },\n );\n }\n const version = this.systemVersions.get(key);\n if (typeof version !== 'number')\n readOnly('Configured system views are read-only');\n return version;\n }\n\n /** The options of a command sent from `place`: its scope, request id and signal. */\n private commandOptions(\n place: Place,\n { requestId, signal }: WriteOptions,\n more: Partial<CommandOptions> = {},\n ): CommandOptions {\n const scope = scopeAt(place);\n return {\n ...(scope?.tenantId === undefined\n ? {}\n : { targetTenant: scope.tenantId }),\n ...(scope === undefined\n ? {}\n : { targetScope: { ownerId: scope.ownerId, spaceId: scope.spaceId } }),\n requestId,\n ...(signal === undefined ? {} : { signal }),\n ...more,\n };\n }\n}\n\n/** The request options of `place`: its `Wow-Scope`, when it has one. */\nfunction optionsAt(place: Place): { scope?: ReturnType<typeof scopeAt> } {\n const scope = scopeAt(place);\n return scope === undefined ? {} : { scope };\n}\n\n/** The place of a view its owner says: a reserved owner, or a user's own. */\nfunction ownedAt(ownerId: string | null | undefined): Place {\n return ownerId === SHARED_OWNER_ID\n ? 'shared'\n : ownerId === SYSTEM_OWNER_ID\n ? 'system'\n : 'personal';\n}\n\n/** A snapshot record as the store reads it. */\nfunction recordOf(record: {\n aggregateId: string;\n version: number;\n state: unknown;\n}): ViewRecord {\n return {\n id: record.aggregateId,\n version: record.version,\n state: record.state as ViewState,\n };\n}\n\n/** A config as a command body holds it: free-form, the service stores it whole. */\nfunction bodyOf(config: ViewConfig): Record<string, unknown> {\n return config as unknown as Record<string, unknown>;\n}\n\n/** The aggregate version a revision of this store names. */\nfunction versionOf(revision: string): number {\n const version = Number(revision);\n if (!Number.isInteger(version) || version < 0)\n throw new ViewStoreError(\n 'CONFLICT',\n `Not a revision of this store: ${revision}`,\n );\n return version;\n}\n\nfunction revisionKey(id: string, revision: string): string {\n return `${id}\\u0000${revision}`;\n}\n\n/** Refuses a write to a system view the server or the code declares. */\nfunction readOnly(message: string): never {\n throw new ViewStoreError('FORBIDDEN', message);\n}\n\n/**\n * The port's refusal of a write. A claim the service refuses because shared\n * dashboards show the view carries those boards' titles (`boards`), read\n * from the problem's `boards` extension member; the engine says the refusal\n * around them.\n */\nfunction refusal(failure: Failure): ViewStoreError {\n if (\n failure.problemCode !==\n ViewStoreContract.Errors.REFERENCED_BY_SHARED_DASHBOARD\n )\n return failure.toStoreError();\n return new ViewStoreError('INVALID', failure.message, {\n ...failure.held(),\n boards: boardTitles(failure.problem?.problem.extensions),\n });\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { CommandClient, type CommandResult, type CommandResultStream, type CreateCommandOptions, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport { ViewStoreManifest } from '../manifest.js';\nimport type { ClearDatasetWording, SetDatasetWording } from '../types.js';\n\n/** Sends the commands of `view-store.dataset_wording` by its service's routes (`ViewStoreManifest`). Each method answers the result its wait plan ends with, as `CommandClient.wait` does: the server's default plan unless the options give one, `{ wait: WaitPlan.ACCEPTED }` to answer once it is accepted. A rejected command rejects with a `CommandRejectedError`; anything else that did not succeed with a `WowProblemError`. */\nexport class DatasetWordingCommandClient {\n readonly client: CommandClient;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.client = new CommandClient(options, { manifest: ViewStoreManifest });\n }\n\n /**\n * Clear the wording of a dataset\n * `ClearDatasetWording`: `POST /view-store/dataset_wording/{id}/clear-dataset-wording`, `POST /view-store/dataset_wording/clear-dataset-wording`.\n * Produces `DatasetWordingCleared`.\n */\n clearDatasetWording(body: ClearDatasetWording, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.dataset_wording.ClearDatasetWording', body });\n }\n\n /** `ClearDatasetWording`, answered as one result per hop of its wait (`text/event-stream`). */\n clearDatasetWordingStream(body: ClearDatasetWording, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.dataset_wording.ClearDatasetWording', body });\n }\n\n /**\n * Set the wording of a dataset\n * `SetDatasetWording`: `POST /view-store/dataset_wording/{id}/set-dataset-wording`, `POST /view-store/dataset_wording/set-dataset-wording`.\n * Creates the aggregate, or acts on the one that exists.\n * Produces `DatasetWordingSet`.\n */\n setDatasetWording(body: SetDatasetWording, options?: CreateCommandOptions): Promise<CommandResult> {\n return this.client.wait({ ...options, command: 'view-store.dataset_wording.SetDatasetWording', body });\n }\n\n /** `SetDatasetWording`, answered as one result per hop of its wait (`text/event-stream`). */\n setDatasetWordingStream(body: SetDatasetWording, options?: CreateCommandOptions): Promise<CommandResultStream> {\n return this.client.stream({ ...options, command: 'view-store.dataset_wording.SetDatasetWording', body });\n }\n}\n","// Code generated by wow-generator. DO NOT EDIT.\n\nimport { EventQueryClient, SnapshotQueryClient, StateClient, type WowClientOptions } from '@ahoo-wang/wow-client';\nimport type { DatasetWordingState } from '../types.js';\nimport { DatasetWordingAggregate, type DatasetWordingEvent, type DatasetWordingStateField } from './aggregate.js';\n\n/** Queries the snapshots of `view-store.dataset_wording`: `POST /view-store/dataset_wording/snapshot/query`. */\nexport class DatasetWordingSnapshotQueryClient extends SnapshotQueryClient<DatasetWordingState, DatasetWordingStateField> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(DatasetWordingAggregate, options);\n }\n}\n\n\n/** Queries the event streams of `view-store.dataset_wording`, one record per commit: `POST /view-store/dataset_wording/events/query`. */\nexport class DatasetWordingEventQueryClient extends EventQueryClient<DatasetWordingEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(DatasetWordingAggregate, options);\n }\n}\n\n\n/** Reads the states of `view-store.dataset_wording`, at a version or a time, and their traces: `GET /view-store/dataset_wording/{id}/state`. */\nexport class DatasetWordingStateClient extends StateClient<DatasetWordingState, DatasetWordingEvent> {\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(DatasetWordingAggregate, options);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Fetcher } from '@ahoo-wang/fetcher';\nimport { filter, listQuery } from '@ahoo-wang/wow-client/dsl';\nimport type { CommandOptions, CommandResult } from '@ahoo-wang/wow-client';\nimport type {\n DatasetOverrides,\n DatasetWordingStore,\n StoredDatasetWording,\n ReadOptions,\n WriteOptions,\n} from '@ahoo-wang/wow-view-engine';\nimport { revisionOf } from './views.js';\nimport { DatasetWordingCommandClient } from './generated/view-store/dataset_wording/commandClient.js';\nimport { DatasetWordingSnapshotQueryClient } from './generated/view-store/dataset_wording/queryClient.js';\nimport { guard, request } from './errors.js';\nimport { wordingOf } from './wire.js';\n\n/** How a V10 {@link WowDatasetWordings} reaches the view store service: as a V10 `WowViewStore` does. */\nexport interface WowDatasetWordingsOptions {\n /**\n * The fetcher every request goes through, as the V10\n * `WowViewStoreOptions.fetcher`: its interceptors carry the caller and\n * `CoSec-App-Id`. The wording is the tenant's (an aggregate of the tenant,\n * not of an owner), so no request names a scope.\n */\n fetcher: Fetcher;\n}\n\n/** The most datasets one application's wording is read for at once. */\nconst LIST_LIMIT = 1000;\n\n/**\n * The wording a tenant's administrators keep over its datasets in the V10\n * view store: one per dataset of the caller's tenant and\n * application, the id derived by the service from the two. Every reader of\n * the tenant reads it; the service decides who writes it (the role that\n * writes the owner `(shared)`, `view-store.shared-writer` as shipped).\n *\n * A host hands it to the datasets it registers as their store of wording\n * (`DatasetCatalog.wordings`, D91). The key is the dataset's definition id,\n * `{context}.{dataset}`. Every rejection is a `ViewStoreError`, read as a\n * V10 `WowViewStore`'s are.\n */\nexport class WowDatasetWordings implements DatasetWordingStore {\n private readonly commands: DatasetWordingCommandClient;\n private readonly snapshots: DatasetWordingSnapshotQueryClient;\n\n constructor(options: WowDatasetWordingsOptions) {\n const client = { fetcher: options.fetcher };\n this.commands = new DatasetWordingCommandClient(client);\n this.snapshots = new DatasetWordingSnapshotQueryClient(client);\n }\n\n /**\n * Every dataset's wording of the caller's tenant and application, by\n * dataset. A cleared one is listed too, saying nothing: its revision is\n * what the next write expects.\n */\n list({ signal }: ReadOptions = {}): Promise<\n ReadonlyMap<string, StoredDatasetWording>\n > {\n return guard(async () => {\n const snapshots = await request(() =>\n this.snapshots.list(\n listQuery({ filter: filter.matchAll(), limit: LIST_LIMIT }),\n signal === undefined ? {} : { signal },\n ),\n );\n return new Map(\n snapshots.map(({ version, state }) => [\n state.dataset,\n { wording: wordingOf(state), revision: revisionOf(version) },\n ]),\n );\n });\n }\n\n /**\n * Writes a dataset's wording at the expected `revision` (`'0'` for one never\n * written), whole: what it leaves out is no longer said. Answers the new\n * revision.\n */\n set(\n dataset: string,\n wording: DatasetOverrides,\n revision: string,\n context: WriteOptions,\n ): Promise<string> {\n return guard(async () => {\n const result = await request(() =>\n this.commands.setDatasetWording(\n {\n dataset,\n ...(wording.title === undefined ? {} : { title: wording.title }),\n ...(wording.recordNoun === undefined\n ? {}\n : { recordNoun: wording.recordNoun }),\n ...(wording.fields === undefined\n ? {}\n : {\n fields: wording.fields as unknown as Record<string, unknown>,\n }),\n },\n optionsOf(revision, context),\n ),\n );\n return versionAfter(result, revision);\n });\n }\n\n /**\n * Clears a dataset's wording at the expected `revision`: its derived words\n * stand again. Answers the new revision.\n */\n clear(\n dataset: string,\n revision: string,\n context: WriteOptions,\n ): Promise<string> {\n return guard(async () => {\n const result = await request(() =>\n this.commands.clearDatasetWording(\n { dataset },\n optionsOf(revision, context),\n ),\n );\n return versionAfter(result, revision);\n });\n }\n}\n\nfunction optionsOf(\n revision: string,\n { requestId, signal }: WriteOptions,\n): CommandOptions {\n return {\n requestId,\n expectedVersion: Number(revision),\n ...(signal === undefined ? {} : { signal }),\n };\n}\n\n/** The revision a write left: its version, or the one it expected moved on. */\nfunction versionAfter(result: CommandResult, revision: string): string {\n return revisionOf(result.version ?? Number(revision) + 1);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { DatasetClient } from '@ahoo-wang/wow-client';\nimport type {\n DatasetCatalog,\n DatasetDirectoryEntry,\n} from '@ahoo-wang/wow-view-engine';\n\n/**\n * What a `DatasetCatalog` reads of a Wow **V10** service's datasets: the\n * directory (`GET /wow/dataset`) and each dataset's query client, which is a\n * `ViewSource` as it is. A host spreads it into the catalog it hands\n * `DatasetResources`, beside its own `overrides` and `wordings`:\n *\n * ```ts\n * const datasets = new DatasetClient({ fetcher });\n * new DatasetResources(engine, {\n * catalogs: {\n * ...datasetCatalogOf(datasets),\n * wordings: new WowDatasetWordings({ fetcher }),\n * },\n * });\n * ```\n *\n * A V10 directory lists only the datasets it serves and names no version of\n * them, so a changed dataset is told by its descriptor's version, which the\n * engine checks on its own schedule.\n */\nexport function datasetCatalogOf(\n client: DatasetClient,\n): Pick<DatasetCatalog, 'list' | 'source'> {\n return {\n async list(options): Promise<DatasetDirectoryEntry[]> {\n return (await client.list(options)).map(entry => ({\n context: entry.context,\n dataset: entry.dataset,\n ...(entry.title ? { title: entry.title } : {}),\n }));\n },\n source: entry => client.dataset(entry.context, entry.dataset),\n };\n}\n"],"mappings":";;;;;A,IAmBaA,IAAkB,YAMlBC,IAAkB,YAQlBC,IAAmB,cCnB1BC,IAAoB,KAGb,aAAb,MAA2B;CAGzB,YAAY,IAAyBA,GAAmB;EAF7B,AAEE,KAAA,QAAAC,GAFF,KAAA,0BAAA,IAAI,IAAe;CAEW;CAEzD,IAAI,GAA4B;EAC9B,OAAO,KAAK,QAAQ,IAAIC,CAAG;CAC7B;CAEA,IAAI,GAAsB;EACxB,OAAO,KAAK,QAA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A,IACnB,CAAC,IACD,EACE,QAAQA,EAAQ,OAClB;EACN,GACA,UAAUnB,GAAUD,CAAO,CAC7B,CACF,GAC4BC,CAAQ,CACrC;CACH;CAMA,MACE,GACA,GACA,GACiB;EACjB,OAAO,MAAM,YAOJ,aAAa,MANC,cACnB,KAAK,SAAS,oBACZ,EAAE,WAAQ,GACV,UAAUA,GAAUD,CAAO,CAC7B,CACF,GAC4BC,CAAQ,CACrC;CACH;AACF;AAEA,SAAS,UACP,GACA,EAAE,cAAW,aACG;CAChB,OAAO;EACL;EACA,iBAAiB,OAAOA,CAAQ;EAChC,GAAIb,MAAW,KAAA,IAAY,CAAC,IAAI,EAAE,UAAO;CAC3C;AACF;AAGA,SAAS,aAAa,GAAuB,GAA0B;CACrE,OAAO,WAAWW,EAAO,WAAW,OAAOE,CAAQ,IAAI,CAAC;AAC1D;;ACtHA,SAAgB,iBACd,GACyC;CACzC,OAAO;EACL,MAAM,KAAK,GAA2C;GACpD,QAAQ,MAAMlB,EAAO,KAAKvC,CAAO,EAAA,CAAG,KAAI,OAAU;IAChD,SAASqE,EAAM;IACf,SAASA,EAAM;IACf,GAAIA,EAAM,QAAQ,EAAE,OAAOA,EAAM,MAAM,IAAI,CAAC;GAC9C,EAAE;EACJ;EACA,SAAQ,MAAS9B,EAAO,QAAQ8B,EAAM,SAASA,EAAM,OAAO;CAC9D;AACF"}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,34 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The reserved owner of shared views and shared preferences
|
|
3
|
-
* (`
|
|
4
|
-
* apart from every user id
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* A host nobody signs in to fills `{ownerId}` with it by default (its own
|
|
8
|
-
* request interceptor), and then has shared views and shared preferences
|
|
9
|
-
* only.
|
|
3
|
+
* (`ViewStoreContext.SHARED_OWNER_ID` on the server). The parentheses keep it
|
|
4
|
+
* apart from every user id. A request acts as it by naming it in `Wow-Scope`
|
|
5
|
+
* (`SHARED_SCOPE`), as far as the service lets the caller.
|
|
10
6
|
*/
|
|
11
7
|
export declare const SHARED_OWNER_ID = "(shared)";
|
|
12
8
|
/**
|
|
13
9
|
* The reserved owner of stored system views
|
|
14
|
-
* (`
|
|
10
|
+
* (`ViewStoreContext.SYSTEM_OWNER_ID`), under {@link SYSTEM_TENANT_ID} only.
|
|
15
11
|
*/
|
|
16
12
|
export declare const SYSTEM_OWNER_ID = "(system)";
|
|
17
13
|
/**
|
|
18
14
|
* The one tenant stored system views live under
|
|
19
|
-
* (`
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* caller's own tenant, and the security gateway decides who may, by that
|
|
23
|
-
* path.
|
|
15
|
+
* (`ViewStoreContext.SYSTEM_TENANT_ID`): CoSec's platform tenant, by value,
|
|
16
|
+
* not the default tenant `(0)`. System views are global, so they are read
|
|
17
|
+
* and written in this tenant whatever the caller's own (`SYSTEM_SCOPE`).
|
|
24
18
|
*/
|
|
25
19
|
export declare const SYSTEM_TENANT_ID = "(platform)";
|
|
26
20
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* names both the tenant and the owner of stored system views,
|
|
32
|
-
* {@link SYSTEM_TENANT_ID} and {@link SYSTEM_OWNER_ID}.
|
|
21
|
+
* Which audience a view is read or written as: `personal` names no scope,
|
|
22
|
+
* and the service takes the owner from the caller; `shared` and `system`
|
|
23
|
+
* name the reserved owner (and, for `system`, tenant) in `Wow-Scope`
|
|
24
|
+
* (`scopeAt`).
|
|
33
25
|
*/
|
|
34
26
|
export type Place = 'personal' | 'shared' | 'system';
|