@antelopejs/dms 0.20.3 → 0.20.5
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/CHANGELOG.md +33 -0
- package/README.md +1 -1
- package/dist/implementations/dms-builder/engine/compose-page.js +3 -2
- package/dist/implementations/dms-builder/engine/compose-page.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-access.d.ts +1 -16
- package/dist/implementations/dms-builder/engine/database-access.js +13 -44
- package/dist/implementations/dms-builder/engine/database-access.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-check.d.ts +1 -2
- package/dist/implementations/dms-builder/engine/database-check.js +28 -15
- package/dist/implementations/dms-builder/engine/database-check.js.map +1 -1
- package/dist/implementations/dms-builder/engine/driver-packages.d.ts +1 -0
- package/dist/implementations/dms-builder/engine/driver-packages.js +4 -0
- package/dist/implementations/dms-builder/engine/driver-packages.js.map +1 -1
- package/dist/implementations/dms-builder/engine/driver-probe.d.ts +27 -0
- package/dist/implementations/dms-builder/engine/driver-probe.js +53 -0
- package/dist/implementations/dms-builder/engine/driver-probe.js.map +1 -0
- package/dist/implementations/dms-builder/engine/index.d.ts +2 -6
- package/dist/implementations/dms-builder/engine/index.js +2 -6
- package/dist/implementations/dms-builder/engine/index.js.map +1 -1
- package/dist/implementations/dms-builder/engine/probe-answer.d.ts +4 -0
- package/dist/implementations/dms-builder/engine/probe-answer.js +90 -0
- package/dist/implementations/dms-builder/engine/probe-answer.js.map +1 -0
- package/dist/implementations/dms-builder/engine/probe-child.d.ts +1 -0
- package/dist/implementations/dms-builder/engine/probe-child.js +70 -0
- package/dist/implementations/dms-builder/engine/probe-child.js.map +1 -0
- package/dist/implementations/dms-builder/engine/probe-process.d.ts +2 -0
- package/dist/implementations/dms-builder/engine/probe-process.js +132 -0
- package/dist/implementations/dms-builder/engine/probe-process.js.map +1 -0
- package/dist/implementations/dms-builder/engine/probe-protocol.d.ts +46 -0
- package/dist/implementations/dms-builder/engine/probe-protocol.js +18 -0
- package/dist/implementations/dms-builder/engine/probe-protocol.js.map +1 -0
- package/dist/mcp/page-verify/index.d.ts +1 -0
- package/dist/mcp/page-verify/index.js +1 -0
- package/dist/mcp/page-verify/index.js.map +1 -1
- package/dist/mcp/page-verify/redact-report.d.ts +2 -0
- package/dist/mcp/page-verify/redact-report.js +120 -0
- package/dist/mcp/page-verify/redact-report.js.map +1 -0
- package/dist/mcp/page-verify/render.js +4 -1
- package/dist/mcp/page-verify/render.js.map +1 -1
- package/dist/mcp/redact.d.ts +87 -0
- package/dist/mcp/redact.js +139 -0
- package/dist/mcp/redact.js.map +1 -0
- package/dist/mcp/tools/builder-compose.js +11 -2
- package/dist/mcp/tools/builder-compose.js.map +1 -1
- package/dist/mcp/tools/builder-project.js +56 -23
- package/dist/mcp/tools/builder-project.js.map +1 -1
- package/dist/mcp/tools/builder-queries.js +41 -4
- package/dist/mcp/tools/builder-queries.js.map +1 -1
- package/dist/mcp/tools/builder-shared.d.ts +3 -1
- package/dist/mcp/tools/builder-shared.js +5 -0
- package/dist/mcp/tools/builder-shared.js.map +1 -1
- package/dist/mcp/tools/database.js +3 -2
- package/dist/mcp/tools/database.js.map +1 -1
- package/dist/mcp/tools/page-verify.js +3 -2
- package/dist/mcp/tools/page-verify.js.map +1 -1
- package/dist/mockup/fixtures.d.ts +1 -1
- package/dist/routes/system-state.d.ts +1 -1
- package/frontend-vue/eslint-globals.generated.mjs +259 -942
- package/frontend-vue/layers/dms-core/app/build/composables/api-error.ts +46 -23
- package/frontend-vue/layers/dms-core/app/build/composables/auth/usePermissionPreview.ts +34 -23
- package/frontend-vue/layers/dms-core/app/build/composables/user/preferencesCookie.ts +8 -2
- package/frontend-vue/layers/dms-core/app/build/composables/user/tablePreferences.ts +11 -5
- package/frontend-vue/layers/dms-core/app/build/utils/crossTab.ts +4 -2
- package/frontend-vue/layers/dms-core/app/build/utils/json.ts +31 -0
- package/frontend-vue/layers/dms-core/app/build/utils/permission-preview.ts +6 -11
- package/frontend-vue/layers/dms-core/app/build/utils/record.ts +4 -0
- package/frontend-vue/layers/dms-core/app/build/utils/sharedRealtimeConnection.ts +56 -36
- package/frontend-vue/layers/dms-core/app/composables/auth/useApiData.ts +2 -2
- package/frontend-vue/layers/dms-core/app/composables/auth/useAuthFetch.ts +6 -1
- package/frontend-vue/layers/dms-core/app/composables/auth/useCurrentUser.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/auth/useLogout.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/auth/useMultiAccount.ts +15 -14
- package/frontend-vue/layers/dms-core/app/composables/auth/useSessionRecovery.ts +21 -8
- package/frontend-vue/layers/dms-core/app/composables/data-types/useDataType.ts +3 -3
- package/frontend-vue/layers/dms-core/app/composables/page/useSiteLayout.ts +11 -9
- package/frontend-vue/layers/dms-core/app/composables/period/periodLink.ts +3 -2
- package/frontend-vue/layers/dms-core/app/composables/period/usePeriod.ts +2 -2
- package/frontend-vue/layers/dms-core/app/composables/realtime/usePageRealtime.ts +10 -3
- package/frontend-vue/layers/dms-core/app/composables/realtime/useSseStream.ts +22 -16
- package/frontend-vue/layers/dms-core/app/composables/realtime/useUserRealtime.ts +68 -46
- package/frontend-vue/layers/dms-core/app/composables/useApiErrorPresenter.ts +22 -11
- package/frontend-vue/layers/dms-core/app/composables/useEventedAction.ts +4 -1
- package/frontend-vue/layers/dms-core/app/composables/useFieldErrors.ts +14 -6
- package/frontend-vue/layers/dms-core/app/composables/user/usePreferences.ts +8 -3
- package/frontend-vue/layers/dms-core/app/composables/watch/useWatch.ts +17 -8
- package/frontend-vue/layers/dms-core/app/types/module-store.ts +3 -1
- package/frontend-vue/layers/dms-core/app/types/page.ts +3 -1
- package/frontend-vue/layers/dms-core/app/utils/dedupedRefresh.ts +2 -2
- package/frontend-vue/layers/dms-core/app/utils/formatter.ts +5 -5
- package/frontend-vue/layers/dms-core/app/utils/menu.ts +12 -4
- package/frontend-vue/layers/dms-core/app/utils/pageQuery.ts +7 -4
- package/frontend-vue/layers/dms-core/app/utils/row-action-rule-evaluator.ts +7 -3
- package/frontend-vue/layers/dms-core/app/utils/stringTypeParser.ts +8 -10
- package/frontend-vue/layers/dms-core/app/utils/type-check.ts +25 -12
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupEditOverlay.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupIndex.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupInspector.vue +3 -2
- package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupInspectorField.vue +5 -2
- package/frontend-vue/layers/dms-ui/app/build/components/containers/drawer/DynamicDrawer.vue +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/containers/modal/DynamicModal.vue +3 -2
- package/frontend-vue/layers/dms-ui/app/build/components/containers/row/RowHeader.vue +2 -1
- package/frontend-vue/layers/dms-ui/app/build/components/period/PeriodRangeCalendar.vue +10 -7
- package/frontend-vue/layers/dms-ui/app/build/components/sortable/SortableList.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/build/components/table/FiltersRow.vue +20 -18
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuColumns.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuDensity.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuFilter.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuImport.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuPage.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuRoot.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuSort.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/MenuViewMode.vue +21 -19
- package/frontend-vue/layers/dms-ui/app/build/components/table/RowSelection.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/Table.types.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableActions.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableMenu.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TablePagination.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableRoot.vue +3 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableTabs.vue +2 -5
- package/frontend-vue/layers/dms-ui/app/build/components/table/TableViews.vue +3 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentFilters.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentPreferences.ts +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentRows.ts +4 -3
- package/frontend-vue/layers/dms-ui/app/build/components/table/tableComponentTheme.ts +11 -0
- package/frontend-vue/layers/dms-ui/app/build/components/table-view/CardsDisplay.vue +35 -9
- package/frontend-vue/layers/dms-ui/app/build/mockups/MockupCards.vue +1 -1
- package/frontend-vue/layers/dms-ui/app/build/mockups/resync.ts +9 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreview.ts +34 -25
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewMessages.ts +52 -26
- package/frontend-vue/layers/dms-ui/app/build/utils/calendarDay.ts +4 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/characterCount.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/dispatchQuickActionTarget.ts +16 -11
- package/frontend-vue/layers/dms-ui/app/build/utils/fieldOptionsI18n.ts +23 -21
- package/frontend-vue/layers/dms-ui/app/build/utils/json.ts +74 -0
- package/frontend-vue/layers/dms-ui/app/build/utils/link.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/mockup.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupCatalog.ts +59 -50
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupDrop.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupEdit.ts +8 -6
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupSpec.ts +34 -28
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupStamp.ts +11 -3
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupStream.ts +5 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/streamHighlight.ts +8 -6
- package/frontend-vue/layers/dms-ui/app/build/utils/urlVariables.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/components/RecursiveComponent.vue +3 -6
- package/frontend-vue/layers/dms-ui/app/components/block-preview/BlockPreview.vue +5 -4
- package/frontend-vue/layers/dms-ui/app/components/blocks/BannerBlock.vue +1 -2
- package/frontend-vue/layers/dms-ui/app/components/card/NavCard.vue +4 -1
- package/frontend-vue/layers/dms-ui/app/components/chart/ApexChartHost.vue +62 -13
- package/frontend-vue/layers/dms-ui/app/components/chart/ChartBlock.vue +18 -6
- package/frontend-vue/layers/dms-ui/app/components/code-snippet/CodeSnippet.vue +9 -4
- package/frontend-vue/layers/dms-ui/app/components/confirm/ConfirmModal.vue +9 -6
- package/frontend-vue/layers/dms-ui/app/components/flow-canvas/FlowCanvas.vue +16 -18
- package/frontend-vue/layers/dms-ui/app/components/form/FormBlock.vue +4 -9
- package/frontend-vue/layers/dms-ui/app/components/form/LocalizedField.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputAddress.vue +2 -2
- package/frontend-vue/layers/dms-ui/app/components/form/components/InputImage.vue +5 -8
- package/frontend-vue/layers/dms-ui/app/components/form/components/RichText.vue +3 -2
- package/frontend-vue/layers/dms-ui/app/components/master-detail/MasterDetail.vue +3 -1
- package/frontend-vue/layers/dms-ui/app/components/period/usePeriodSelectorInteraction.ts +9 -7
- package/frontend-vue/layers/dms-ui/app/components/table-view/KanbanBoard.vue +11 -6
- package/frontend-vue/layers/dms-ui/app/components/table-view/KanbanDisplay.vue +40 -3
- package/frontend-vue/layers/dms-ui/app/composables/chart/apexDatetimeBuckets.ts +9 -5
- package/frontend-vue/layers/dms-ui/app/composables/chart/events.ts +6 -3
- package/frontend-vue/layers/dms-ui/app/composables/chart/heatmapColors.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/chart/localizeSeries.ts +13 -2
- package/frontend-vue/layers/dms-ui/app/composables/chart/useApexChart.ts +27 -4
- package/frontend-vue/layers/dms-ui/app/composables/chart/useApexChart.types.ts +3 -2
- package/frontend-vue/layers/dms-ui/app/composables/chart/useChartFetch.ts +3 -4
- package/frontend-vue/layers/dms-ui/app/composables/confirm/types.ts +5 -1
- package/frontend-vue/layers/dms-ui/app/composables/containers/openDynamicContainer.ts +6 -6
- package/frontend-vue/layers/dms-ui/app/composables/containers/types.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/containers/useDrawer.ts +8 -5
- package/frontend-vue/layers/dms-ui/app/composables/containers/useModal.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/form/types/props.ts +5 -2
- package/frontend-vue/layers/dms-ui/app/composables/form/useForm.ts +80 -39
- package/frontend-vue/layers/dms-ui/app/composables/live/usePageLiveRefresh.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/resolveDmsComponent.ts +9 -2
- package/frontend-vue/layers/dms-ui/app/composables/tab/useTab.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/shortcuts/tableViewShiftA.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/action-target.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/column.ts +3 -1
- package/frontend-vue/layers/dms-ui/app/composables/table-view/types/display.ts +6 -2
- package/frontend-vue/layers/dms-ui/app/composables/table-view/useTableViewExport.ts +6 -5
- package/frontend-vue/layers/dms-ui/app/composables/unsaved-changes/useUnsavedChanges.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/composables/useExportJob.ts +21 -9
- package/frontend-vue/layers/dms-ui/app/utils/blockRefresh.ts +8 -2
- package/frontend-vue/layers/dms-ui/app/utils/cascader.ts +18 -8
- package/frontend-vue/layers/dms-ui/app/utils/metadataRetry.ts +1 -1
- package/frontend-vue/package.json +2 -1
- package/frontend-vue/scripts/check-api-error-presentation.mjs +257 -117
- package/frontend-vue/scripts/check-autoimport-boundaries.mjs +143 -27
- package/frontend-vue/scripts/check-disable-blocks.mjs +26 -4
- package/frontend-vue/scripts/check-dms-components.mjs +152 -246
- package/frontend-vue/scripts/check-invariants.mjs +100 -42
- package/frontend-vue/scripts/check-page-invariants.mjs +103 -40
- package/frontend-vue/scripts/dms-components-dependencies.mjs +106 -13
- package/frontend-vue/scripts/dms-components-script.mjs +375 -0
- package/frontend-vue/scripts/eslint-test-quality.mjs +126 -0
- package/frontend-vue/scripts/jsconfig.json +10 -0
- package/frontend-vue/scripts/probes/capture-frontend-probe.cjs +4 -2
- package/frontend-vue/scripts/probes/frontend-behavior.cjs +217 -47
- package/frontend-vue/scripts/probes/frontend-legacy.cjs +159 -8
- package/frontend-vue/scripts/probes/frontend-probe-controls.cjs +89 -10
- package/frontend-vue/scripts/prove-comment-emit.mjs +33 -4
- package/frontend-vue/scripts/prove-component-registration.mjs +110 -24
- package/frontend-vue/scripts/test-autoimport-boundaries.mjs +37 -6
- package/frontend-vue/scripts/test-dms-components.mjs +51 -2
- package/package.json +5 -19
- package/dist/implementations/dms-builder/engine/access-mongodb.d.ts +0 -20
- package/dist/implementations/dms-builder/engine/access-mongodb.js +0 -30
- package/dist/implementations/dms-builder/engine/access-mongodb.js.map +0 -1
- package/dist/implementations/dms-builder/engine/access-mysql.d.ts +0 -8
- package/dist/implementations/dms-builder/engine/access-mysql.js +0 -11
- package/dist/implementations/dms-builder/engine/access-mysql.js.map +0 -1
- package/dist/implementations/dms-builder/engine/access-postgres.d.ts +0 -8
- package/dist/implementations/dms-builder/engine/access-postgres.js +0 -11
- package/dist/implementations/dms-builder/engine/access-postgres.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-client.d.ts +0 -19
- package/dist/implementations/dms-builder/engine/probe-client.js +0 -50
- package/dist/implementations/dms-builder/engine/probe-client.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-connections.d.ts +0 -10
- package/dist/implementations/dms-builder/engine/probe-connections.js +0 -43
- package/dist/implementations/dms-builder/engine/probe-connections.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-mongodb.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-mongodb.js +0 -148
- package/dist/implementations/dms-builder/engine/probe-mongodb.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-mysql.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-mysql.js +0 -189
- package/dist/implementations/dms-builder/engine/probe-mysql.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-postgres.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-postgres.js +0 -164
- package/dist/implementations/dms-builder/engine/probe-postgres.js.map +0 -1
- package/dist/implementations/dms-builder/engine/probe-rethinkdb.d.ts +0 -2
- package/dist/implementations/dms-builder/engine/probe-rethinkdb.js +0 -92
- package/dist/implementations/dms-builder/engine/probe-rethinkdb.js.map +0 -1
- package/dist/implementations/dms-builder/engine/rethinkdb-client.d.ts +0 -34
- package/dist/implementations/dms-builder/engine/rethinkdb-client.js +0 -3
- package/dist/implementations/dms-builder/engine/rethinkdb-client.js.map +0 -1
- package/dist/implementations/dms-builder/engine/scram-bound.d.ts +0 -5
- package/dist/implementations/dms-builder/engine/scram-bound.js +0 -60
- package/dist/implementations/dms-builder/engine/scram-bound.js.map +0 -1
- package/frontend-vue/eslint-test-quality.mjs +0 -62
|
@@ -3,20 +3,33 @@ import { runDeduped } from "../../utils/dedupedRefresh";
|
|
|
3
3
|
const AUTH_PATH = "/auth";
|
|
4
4
|
const IN_FLIGHT_REFRESH_KEY = "__dmsAuthInFlightRefresh";
|
|
5
5
|
|
|
6
|
+
type DmsApp = ReturnType<typeof useDmsApp>;
|
|
7
|
+
type RefreshHolder = Parameters<typeof runDeduped<boolean>>[0];
|
|
8
|
+
|
|
9
|
+
/** Per app, the holder `runDeduped` keeps its in-flight session refresh in. */
|
|
10
|
+
const refreshHolders = new WeakMap<DmsApp, RefreshHolder>();
|
|
11
|
+
|
|
12
|
+
function refreshHolderOf(app: DmsApp): RefreshHolder {
|
|
13
|
+
const known = refreshHolders.get(app);
|
|
14
|
+
if (known) return known;
|
|
15
|
+
const holder = {};
|
|
16
|
+
refreshHolders.set(app, holder);
|
|
17
|
+
return holder;
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
export const useSessionRecovery = () => {
|
|
7
21
|
const dmsApp = useDmsApp();
|
|
8
|
-
const
|
|
22
|
+
const userSession = useDmsUserSession();
|
|
23
|
+
const { loggedIn } = userSession;
|
|
9
24
|
|
|
10
25
|
const router = useDmsRouter();
|
|
11
26
|
|
|
12
27
|
function refreshSession(): Promise<boolean> {
|
|
13
|
-
return runDeduped(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.then(() => true)
|
|
19
|
-
.catch(() => false),
|
|
28
|
+
return runDeduped(refreshHolderOf(dmsApp), IN_FLIGHT_REFRESH_KEY, () =>
|
|
29
|
+
userSession
|
|
30
|
+
.fetch()
|
|
31
|
+
.then(() => true)
|
|
32
|
+
.catch(() => false),
|
|
20
33
|
);
|
|
21
34
|
}
|
|
22
35
|
|
|
@@ -76,15 +76,15 @@ export interface DataType {
|
|
|
76
76
|
) => DataTypeSelectSource | undefined;
|
|
77
77
|
displayComponent?: Component;
|
|
78
78
|
}
|
|
79
|
-
const dataTypes
|
|
79
|
+
const dataTypes = new Map<string, DataType>();
|
|
80
80
|
|
|
81
81
|
export const useDataTypes = () => {
|
|
82
82
|
function registerDataType(dataType: DataType) {
|
|
83
|
-
dataTypes
|
|
83
|
+
dataTypes.set(dataType.id, dataType);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function getDataType(id: string) {
|
|
87
|
-
return dataTypes
|
|
87
|
+
return dataTypes.get(id);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
return {
|
|
@@ -55,24 +55,24 @@ const occurrenceKey = (name: string, occurrence: number): string =>
|
|
|
55
55
|
`${name}${OCCURRENCE_KEY_SEPARATOR}${occurrence}`;
|
|
56
56
|
|
|
57
57
|
function countByName(names: string[]) {
|
|
58
|
-
const totals
|
|
58
|
+
const totals = new Map<string, number>();
|
|
59
59
|
for (const name of names) {
|
|
60
|
-
totals
|
|
60
|
+
totals.set(name, (totals.get(name) ?? 0) + 1);
|
|
61
61
|
}
|
|
62
62
|
return totals;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
function buildParamBag(names: string[], values: string[]) {
|
|
66
66
|
const totals = countByName(names);
|
|
67
|
-
const seen
|
|
67
|
+
const seen = new Map<string, number>();
|
|
68
68
|
const params: Record<string, string> = {};
|
|
69
69
|
|
|
70
70
|
names.forEach((name, index) => {
|
|
71
71
|
const value = values[index]!;
|
|
72
|
-
const occurrence = (seen
|
|
73
|
-
seen
|
|
72
|
+
const occurrence = (seen.get(name) ?? 0) + 1;
|
|
73
|
+
seen.set(name, occurrence);
|
|
74
74
|
params[name] = value;
|
|
75
|
-
if (totals
|
|
75
|
+
if (totals.get(name)! > 1) {
|
|
76
76
|
params[occurrenceKey(name, occurrence)] = value;
|
|
77
77
|
}
|
|
78
78
|
});
|
|
@@ -205,11 +205,13 @@ const useSiteLayoutRequests = () => {
|
|
|
205
205
|
const { pageLayoutPromises, loadingPromise } =
|
|
206
206
|
useSiteLayoutRequestsInFlight();
|
|
207
207
|
|
|
208
|
-
const
|
|
208
|
+
const errorPresenter = useApiErrorPresenter();
|
|
209
209
|
const HTTP_INTERNAL_ERROR = 500;
|
|
210
210
|
|
|
211
|
-
const handleSiteLayoutError = (
|
|
212
|
-
|
|
211
|
+
const handleSiteLayoutError = (
|
|
212
|
+
error: Parameters<typeof errorPresenter.resolveError>[0],
|
|
213
|
+
) => {
|
|
214
|
+
const errorMessage = errorPresenter.resolveError(error, {
|
|
213
215
|
fallbackKey: "error.500.description",
|
|
214
216
|
})?.message;
|
|
215
217
|
if (!errorMessage) return;
|
|
@@ -33,7 +33,7 @@ export function periodQueryKeys(id?: string): PeriodQueryKeys {
|
|
|
33
33
|
function firstText(
|
|
34
34
|
value: Parameters<typeof withPeriodQuery>[1][string],
|
|
35
35
|
): string | undefined {
|
|
36
|
-
const text = Array.isArray(value) ? value[0] : value;
|
|
36
|
+
const text: unknown = Array.isArray(value) ? value[0] : value;
|
|
37
37
|
return isString(text) && text ? text : undefined;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -51,7 +51,8 @@ export function withPeriodQuery(
|
|
|
51
51
|
const [beforeFragment = "", ...fragment] = link.split(FRAGMENT_SEPARATOR);
|
|
52
52
|
const [path = "", ...search] = beforeFragment.split(QUERY_SEPARATOR);
|
|
53
53
|
const params = new URLSearchParams(search.join(QUERY_SEPARATOR));
|
|
54
|
-
|
|
54
|
+
const keys: Record<keyof PeriodQueryKeys, string> = periodQueryKeys(id);
|
|
55
|
+
for (const key of Object.values(keys)) {
|
|
55
56
|
const value = firstText(query[key]);
|
|
56
57
|
if (value && !params.has(key)) params.set(key, value);
|
|
57
58
|
}
|
|
@@ -136,12 +136,12 @@ function buildKey(state: Omit<PeriodState, "key">): string {
|
|
|
136
136
|
].join("|");
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
type PeriodRefs = {
|
|
140
140
|
preset: Ref<PeriodPreset>;
|
|
141
141
|
comparison: Ref<PeriodComparison>;
|
|
142
142
|
customRange: Ref<PeriodRange | null>;
|
|
143
143
|
customCompareRange: Ref<PeriodRange | null>;
|
|
144
|
-
}
|
|
144
|
+
};
|
|
145
145
|
|
|
146
146
|
function buildState(refs: PeriodRefs, now: Date): PeriodState {
|
|
147
147
|
const fallback = refs.customRange.value ?? defaultFallbackRange(now);
|
|
@@ -27,8 +27,15 @@ interface PageClaim {
|
|
|
27
27
|
*/
|
|
28
28
|
const pageClaims: PageClaim[] = [];
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Moves the session to the latest claimed page, in the background. A failed
|
|
32
|
+
* page call leaves the page drawn as it is and is logged: the page is not
|
|
33
|
+
* marked applied, so the next reconcile subscribes it again.
|
|
34
|
+
*/
|
|
30
35
|
const applyLatestClaim = (user: UserRealtimeApi): void => {
|
|
31
|
-
|
|
36
|
+
user.setPage(pageClaims.at(-1)?.pageId ?? null).catch((error: unknown) => {
|
|
37
|
+
console.error("[dms] page realtime subscription failed", error);
|
|
38
|
+
});
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
const raiseClaim = (claim: PageClaim): void => {
|
|
@@ -49,7 +56,7 @@ export function usePageRealtime(
|
|
|
49
56
|
const resolvedPageId = computed(() => toValue(pageId) || undefined);
|
|
50
57
|
|
|
51
58
|
if (import.meta.env.SSR) {
|
|
52
|
-
|
|
59
|
+
user.setPage(resolvedPageId.value ?? null).catch(() => {});
|
|
53
60
|
} else {
|
|
54
61
|
const claim: PageClaim = { pageId: undefined };
|
|
55
62
|
watch(
|
|
@@ -68,7 +75,7 @@ export function usePageRealtime(
|
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
return {
|
|
71
|
-
subscribe: user.subscribe,
|
|
78
|
+
subscribe: (topic, handler) => user.subscribe(topic, handler),
|
|
72
79
|
sessionId: user.sessionId,
|
|
73
80
|
pageId: resolvedPageId,
|
|
74
81
|
pageTopics: user.pageTopics,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HTTP_UNAUTHORIZED } from "../../utils/http-status";
|
|
2
2
|
import { isObject } from "../../utils/type-check";
|
|
3
|
+
import { isJsonValue } from "../../build/utils/json";
|
|
3
4
|
|
|
4
5
|
/** Receives decoded data and the frame's id (null if absent, empty if reset). */
|
|
5
6
|
export type SseEventHandler = (
|
|
@@ -17,7 +18,7 @@ export interface SseStreamOptions {
|
|
|
17
18
|
headers?: () => Record<string, string>;
|
|
18
19
|
onEvent: SseEventHandler;
|
|
19
20
|
onOpen?: () => void;
|
|
20
|
-
onError?: (error:
|
|
21
|
+
onError?: (error: Parameters<typeof isUnauthorizedStreamError>[0]) => void;
|
|
21
22
|
/** Called once after cleanup; errors call onError first. Retry on only one callback. */
|
|
22
23
|
onClose?: (reason: SseCloseReason) => void;
|
|
23
24
|
}
|
|
@@ -68,7 +69,8 @@ function parseFrame(frame: string): ParsedFrame | null {
|
|
|
68
69
|
|
|
69
70
|
function decodeData(data: string): Parameters<SseEventHandler>[1] {
|
|
70
71
|
try {
|
|
71
|
-
|
|
72
|
+
const parsed: unknown = JSON.parse(data);
|
|
73
|
+
return isJsonValue(parsed) ? parsed : data;
|
|
72
74
|
} catch {
|
|
73
75
|
return data;
|
|
74
76
|
}
|
|
@@ -146,10 +148,15 @@ async function connect(
|
|
|
146
148
|
await readStream(response.body.getReader(), options, signal);
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
/** A stream error that carries HTTP 401. */
|
|
152
|
+
interface UnauthorizedStreamError {
|
|
153
|
+
status: typeof HTTP_UNAUTHORIZED;
|
|
154
|
+
}
|
|
155
|
+
|
|
149
156
|
/** Whether a stream error carries HTTP 401 and may need session recovery. */
|
|
150
157
|
export function isUnauthorizedStreamError(
|
|
151
|
-
error:
|
|
152
|
-
):
|
|
158
|
+
error: unknown,
|
|
159
|
+
): error is UnauthorizedStreamError {
|
|
153
160
|
return (
|
|
154
161
|
isObject(error) && error !== null && error.status === HTTP_UNAUTHORIZED
|
|
155
162
|
);
|
|
@@ -158,17 +165,16 @@ export function isUnauthorizedStreamError(
|
|
|
158
165
|
/** Opens one SSE request. EOF is not business completion; no retry is implicit. */
|
|
159
166
|
export function openSseStream(options: SseStreamOptions): SseStreamHandle {
|
|
160
167
|
const controller = new AbortController();
|
|
161
|
-
void (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
})();
|
|
168
|
+
void connect(options, controller.signal).then(
|
|
169
|
+
() => options.onClose?.(controller.signal.aborted ? "aborted" : "eof"),
|
|
170
|
+
(error: unknown) => {
|
|
171
|
+
const reason = controller.signal.aborted ? "aborted" : "error";
|
|
172
|
+
try {
|
|
173
|
+
if (reason === "error") options.onError?.(error);
|
|
174
|
+
} finally {
|
|
175
|
+
options.onClose?.(reason);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
);
|
|
173
179
|
return { close: () => controller.abort() };
|
|
174
180
|
}
|
|
@@ -6,7 +6,15 @@ import {
|
|
|
6
6
|
type StreamRecovery,
|
|
7
7
|
} from "../../build/utils/sharedRealtimeConnection";
|
|
8
8
|
import { HTTP_UNAUTHORIZED } from "../../utils/http-status";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
isNumber,
|
|
11
|
+
isObject,
|
|
12
|
+
isString,
|
|
13
|
+
isUndefined,
|
|
14
|
+
} from "../../utils/type-check";
|
|
15
|
+
import { isJsonObject } from "../../build/utils/json";
|
|
16
|
+
import { isRecord } from "../../build/utils/record";
|
|
17
|
+
import type { JsonValue } from "../../types/json";
|
|
10
18
|
|
|
11
19
|
const REALTIME_CONNECTION_PATH = "/api/realtime/connection";
|
|
12
20
|
const REALTIME_SESSION_PATH = "/api/realtime/session";
|
|
@@ -32,7 +40,7 @@ type RealtimeFrameData = Parameters<
|
|
|
32
40
|
export interface RealtimeEvent {
|
|
33
41
|
topic: string;
|
|
34
42
|
type: string;
|
|
35
|
-
payload?:
|
|
43
|
+
payload?: { [key: string]: JsonValue };
|
|
36
44
|
actorId?: string;
|
|
37
45
|
ts: number;
|
|
38
46
|
}
|
|
@@ -132,27 +140,52 @@ const dispatchToHandlers = (
|
|
|
132
140
|
for (const handler of handlers) handler(event);
|
|
133
141
|
};
|
|
134
142
|
|
|
143
|
+
const isOptionalString = (value: unknown): value is string | undefined =>
|
|
144
|
+
isUndefined(value) || isString(value);
|
|
145
|
+
|
|
146
|
+
const isSnapshotEntry = (
|
|
147
|
+
value: unknown,
|
|
148
|
+
): value is RealtimeSnapshotEvent["entries"][number] =>
|
|
149
|
+
isRecord(value) &&
|
|
150
|
+
isString(value.topic) &&
|
|
151
|
+
isString(value.rowId) &&
|
|
152
|
+
isRecord(value.actor) &&
|
|
153
|
+
isString(value.actor.id) &&
|
|
154
|
+
isOptionalString(value.actor.displayName) &&
|
|
155
|
+
isOptionalString(value.actor.avatarUrl) &&
|
|
156
|
+
isString(value.sessionId) &&
|
|
157
|
+
isString(value.instanceId) &&
|
|
158
|
+
isNumber(value.since);
|
|
159
|
+
|
|
135
160
|
const isSnapshotEvent = (
|
|
136
161
|
eventName: string,
|
|
137
162
|
data: RealtimeFrameData,
|
|
138
163
|
): data is RealtimeSnapshotEvent =>
|
|
139
|
-
eventName === SNAPSHOT_EVENT &&
|
|
164
|
+
eventName === SNAPSHOT_EVENT &&
|
|
165
|
+
isRecord(data) &&
|
|
166
|
+
isString(data.topic) &&
|
|
167
|
+
Array.isArray(data.entries) &&
|
|
168
|
+
data.entries.every(isSnapshotEntry);
|
|
140
169
|
|
|
141
170
|
const isRealtimeEvent = (data: RealtimeFrameData): data is RealtimeEvent =>
|
|
142
|
-
!!data &&
|
|
171
|
+
!!data &&
|
|
172
|
+
isObject(data) &&
|
|
173
|
+
isString(data.topic) &&
|
|
174
|
+
isString(data.type) &&
|
|
175
|
+
(isUndefined(data.payload) || isJsonObject(data.payload));
|
|
143
176
|
|
|
144
177
|
/** Takes the session a greeting names, with the menu topics it announces. */
|
|
145
178
|
const handleHello = (
|
|
146
179
|
state: UserRealtimeState,
|
|
147
|
-
|
|
180
|
+
sessionId: string,
|
|
181
|
+
greeting: SessionGreeting,
|
|
148
182
|
): void => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const { menuTopics } = data;
|
|
183
|
+
state.sessionId.value = sessionId;
|
|
184
|
+
const { menuTopics } = greeting;
|
|
152
185
|
state.menuTopics.value = Array.isArray(menuTopics)
|
|
153
186
|
? menuTopics.filter((topic): topic is string => isString(topic))
|
|
154
187
|
: [];
|
|
155
|
-
const { devReloadTopic } =
|
|
188
|
+
const { devReloadTopic } = greeting;
|
|
156
189
|
state.devReloadTopic.value = isString(devReloadTopic)
|
|
157
190
|
? devReloadTopic
|
|
158
191
|
: undefined;
|
|
@@ -180,6 +213,7 @@ interface ConnectionCallbacks extends StreamRecovery {
|
|
|
180
213
|
interface SessionGreeting {
|
|
181
214
|
sessionId?: unknown;
|
|
182
215
|
menuTopics?: unknown;
|
|
216
|
+
devReloadTopic?: unknown;
|
|
183
217
|
}
|
|
184
218
|
|
|
185
219
|
interface BufferedFrame {
|
|
@@ -192,7 +226,8 @@ const readGreeting = async (
|
|
|
192
226
|
response: Response,
|
|
193
227
|
): Promise<SessionGreeting | null> => {
|
|
194
228
|
try {
|
|
195
|
-
|
|
229
|
+
const greeting: unknown = await response.json();
|
|
230
|
+
return isRecord(greeting) ? greeting : null;
|
|
196
231
|
} catch {
|
|
197
232
|
return null;
|
|
198
233
|
}
|
|
@@ -233,24 +268,9 @@ const connectTab = (
|
|
|
233
268
|
const retries = createReconnector();
|
|
234
269
|
const sessionCloseUrl = `${baseUrl}${REALTIME_SESSION_CLOSE_PATH}`;
|
|
235
270
|
let connectionId: string | undefined;
|
|
236
|
-
|
|
237
271
|
let attempt = 0;
|
|
238
|
-
|
|
239
272
|
let buffered: BufferedFrame[] | undefined;
|
|
240
273
|
|
|
241
|
-
const adopt = (forConnection: string, greeting: SessionGreeting) => {
|
|
242
|
-
const sessionId = String(greeting.sessionId);
|
|
243
|
-
handleHello(state, greeting);
|
|
244
|
-
const pending = buffered ?? [];
|
|
245
|
-
buffered = undefined;
|
|
246
|
-
for (const frame of pending) {
|
|
247
|
-
if (frame.sessionId === sessionId) dispatch(frame.eventName, frame.data);
|
|
248
|
-
}
|
|
249
|
-
retries.resetDelay();
|
|
250
|
-
connection.announceSession(forConnection, sessionId);
|
|
251
|
-
callbacks.onConnected();
|
|
252
|
-
};
|
|
253
|
-
|
|
254
274
|
const openSession = async (forConnection: string): Promise<void> => {
|
|
255
275
|
const ownAttempt = ++attempt;
|
|
256
276
|
const isCurrent = () =>
|
|
@@ -258,15 +278,14 @@ const connectTab = (
|
|
|
258
278
|
connectionId === forConnection &&
|
|
259
279
|
attempt === ownAttempt;
|
|
260
280
|
const retry = () =>
|
|
261
|
-
retries.schedule(() => {
|
|
262
|
-
if (isCurrent())
|
|
281
|
+
retries.schedule(async () => {
|
|
282
|
+
if (isCurrent()) await openSession(forConnection);
|
|
263
283
|
});
|
|
264
284
|
buffered = [];
|
|
265
285
|
let response: Response;
|
|
266
286
|
try {
|
|
267
287
|
response = await fetch(`${baseUrl}${REALTIME_SESSION_PATH}`, {
|
|
268
288
|
method: "POST",
|
|
269
|
-
|
|
270
289
|
headers: { [CONNECTION_HEADER]: forConnection },
|
|
271
290
|
credentials: "include",
|
|
272
291
|
});
|
|
@@ -298,17 +317,25 @@ const connectTab = (
|
|
|
298
317
|
});
|
|
299
318
|
return;
|
|
300
319
|
}
|
|
301
|
-
|
|
320
|
+
handleHello(state, sessionId, greeting!);
|
|
321
|
+
const pending = buffered ?? [];
|
|
322
|
+
buffered = undefined;
|
|
323
|
+
for (const frame of pending) {
|
|
324
|
+
if (frame.sessionId === sessionId) dispatch(frame.eventName, frame.data);
|
|
325
|
+
}
|
|
326
|
+
retries.resetDelay();
|
|
327
|
+
connection.announceSession(forConnection, sessionId);
|
|
328
|
+
callbacks.onConnected();
|
|
302
329
|
};
|
|
303
330
|
|
|
304
|
-
const renewSession = () => {
|
|
331
|
+
const renewSession = async () => {
|
|
305
332
|
if (retries.isCancelled() || !connectionId) return;
|
|
306
333
|
const sessionId = state.sessionId.value;
|
|
307
334
|
if (sessionId) {
|
|
308
335
|
closeStraySession(sessionCloseUrl, connectionId, sessionId);
|
|
309
336
|
callbacks.onDisconnected();
|
|
310
337
|
}
|
|
311
|
-
|
|
338
|
+
await openSession(connectionId);
|
|
312
339
|
};
|
|
313
340
|
|
|
314
341
|
const connection = joinSharedRealtimeConnection({
|
|
@@ -316,11 +343,11 @@ const connectTab = (
|
|
|
316
343
|
streamUrl: `${baseUrl}${REALTIME_CONNECTION_PATH}`,
|
|
317
344
|
sessionCloseUrl,
|
|
318
345
|
onConnection: (next) => {
|
|
319
|
-
if (retries.isCancelled()) return;
|
|
346
|
+
if (retries.isCancelled()) return undefined;
|
|
320
347
|
if (state.sessionId.value) callbacks.onDisconnected();
|
|
321
348
|
buffered = undefined;
|
|
322
349
|
connectionId = next;
|
|
323
|
-
|
|
350
|
+
return next ? openSession(next) : undefined;
|
|
324
351
|
},
|
|
325
352
|
onFrame: (sessionId, eventName, data) => {
|
|
326
353
|
if (sessionId === undefined) {
|
|
@@ -328,10 +355,7 @@ const connectTab = (
|
|
|
328
355
|
return;
|
|
329
356
|
}
|
|
330
357
|
if (sessionId === state.sessionId.value) {
|
|
331
|
-
if (eventName === SESSION_ENDED_EVENT)
|
|
332
|
-
renewSession();
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
358
|
+
if (eventName === SESSION_ENDED_EVENT) return renewSession();
|
|
335
359
|
dispatch(eventName, data);
|
|
336
360
|
return;
|
|
337
361
|
}
|
|
@@ -353,19 +377,15 @@ const connectTab = (
|
|
|
353
377
|
};
|
|
354
378
|
};
|
|
355
379
|
|
|
356
|
-
interface PageSubscriptionAnswer {
|
|
357
|
-
topics?: unknown;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
380
|
/** The topics a page subscription answered, none when it answered none. */
|
|
361
381
|
const readPageTopics = async (response: Response): Promise<string[]> => {
|
|
362
|
-
let answer:
|
|
382
|
+
let answer: unknown;
|
|
363
383
|
try {
|
|
364
384
|
answer = await response.json();
|
|
365
385
|
} catch {
|
|
366
386
|
return [];
|
|
367
387
|
}
|
|
368
|
-
const topics = answer
|
|
388
|
+
const topics = isRecord(answer) ? answer.topics : undefined;
|
|
369
389
|
return Array.isArray(topics)
|
|
370
390
|
? topics.filter((topic): topic is string => isString(topic))
|
|
371
391
|
: [];
|
|
@@ -476,8 +496,8 @@ const buildApi = (): UserRealtimeApi => {
|
|
|
476
496
|
state.menuTopics.value = [];
|
|
477
497
|
if (userKey === undefined) return;
|
|
478
498
|
state.connection = connectTab(state, baseUrl, userKey, {
|
|
479
|
-
onConnected: () => {
|
|
480
|
-
|
|
499
|
+
onConnected: async () => {
|
|
500
|
+
await reconcilePage(state, baseUrl);
|
|
481
501
|
},
|
|
482
502
|
onDisconnected: () => resetSession(state),
|
|
483
503
|
refreshSession,
|
|
@@ -489,7 +509,9 @@ const buildApi = (): UserRealtimeApi => {
|
|
|
489
509
|
|
|
490
510
|
watch(
|
|
491
511
|
() => sessionScopeOf(session?.value),
|
|
492
|
-
() =>
|
|
512
|
+
() => {
|
|
513
|
+
state.connection?.renewSession();
|
|
514
|
+
},
|
|
493
515
|
);
|
|
494
516
|
}
|
|
495
517
|
|
|
@@ -35,13 +35,16 @@ export interface PresentApiErrorOptions extends ResolveApiErrorOptions {
|
|
|
35
35
|
readonly replaceToastId?: ApiErrorToastId;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** Anything thrown or rejected, as `decodeApiFailure` reads it. */
|
|
39
|
+
type ApiFailure = Parameters<typeof decodeApiFailure>[0];
|
|
40
|
+
|
|
38
41
|
/** Captured during setup and callable after awaits. */
|
|
39
42
|
export interface ApiErrorPresenter {
|
|
40
43
|
resolveError(
|
|
41
|
-
error:
|
|
44
|
+
error: ApiFailure,
|
|
42
45
|
options: ResolveApiErrorOptions,
|
|
43
46
|
): ApiErrorNotice | null;
|
|
44
|
-
presentError(error:
|
|
47
|
+
presentError(error: ApiFailure, options: PresentApiErrorOptions): void;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
const GENERIC_KEY = "error.500.description";
|
|
@@ -53,7 +56,17 @@ const ICONS: Record<ApiErrorSeverity, string> = {
|
|
|
53
56
|
error: "i-ph-warning-circle",
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
/** A message vue-i18n compiled ahead of time: its AST, typed `0` at the root. */
|
|
60
|
+
type CompiledMessage = { type: 0 } | { t: 0 };
|
|
61
|
+
|
|
62
|
+
/** A message `rt` renders: its source text, a message function or a compiled AST. */
|
|
63
|
+
type RenderableMessage =
|
|
64
|
+
| string
|
|
65
|
+
| ((...args: never[]) => string)
|
|
66
|
+
| CompiledMessage;
|
|
67
|
+
|
|
68
|
+
function isRenderableMessage(value: unknown): value is RenderableMessage {
|
|
69
|
+
if (typeof value === "string" || typeof value === "function") return true;
|
|
57
70
|
return (
|
|
58
71
|
value !== null &&
|
|
59
72
|
typeof value === "object" &&
|
|
@@ -80,12 +93,7 @@ export function useApiErrorPresenter(): ApiErrorPresenter {
|
|
|
80
93
|
if (!key) return null;
|
|
81
94
|
try {
|
|
82
95
|
const message = i18n.tm(key.startsWith("$") ? key.slice(1) : key);
|
|
83
|
-
if (
|
|
84
|
-
typeof message !== "string" &&
|
|
85
|
-
typeof message !== "function" &&
|
|
86
|
-
!isCompiledMessage(message)
|
|
87
|
-
)
|
|
88
|
-
return null;
|
|
96
|
+
if (!isRenderableMessage(message)) return null;
|
|
89
97
|
return i18n.rt(message, params);
|
|
90
98
|
} catch {
|
|
91
99
|
return null;
|
|
@@ -110,13 +118,16 @@ export function useApiErrorPresenter(): ApiErrorPresenter {
|
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
function resolveError(
|
|
113
|
-
error:
|
|
121
|
+
error: ApiFailure,
|
|
114
122
|
options: ResolveApiErrorOptions,
|
|
115
123
|
): ApiErrorNotice | null {
|
|
116
124
|
return noticeOf(decodeApiFailure(error), options);
|
|
117
125
|
}
|
|
118
126
|
|
|
119
|
-
function presentError(
|
|
127
|
+
function presentError(
|
|
128
|
+
error: ApiFailure,
|
|
129
|
+
options: PresentApiErrorOptions,
|
|
130
|
+
): void {
|
|
120
131
|
if (import.meta.env.SSR) return;
|
|
121
132
|
const failure = decodeApiFailure(error);
|
|
122
133
|
const notice = noticeOf(failure, options);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentEventData } from "../types/component";
|
|
2
|
+
import type { ApiErrorPresenter } from "./useApiErrorPresenter";
|
|
2
3
|
|
|
3
4
|
interface EventedActionOptions {
|
|
4
5
|
componentId?: string;
|
|
@@ -12,7 +13,9 @@ interface EventedActionOptions {
|
|
|
12
13
|
interface ExecuteOptions<TResult> {
|
|
13
14
|
startPayload?: ComponentEventData["data"];
|
|
14
15
|
successPayload?: (result: TResult) => ComponentEventData["data"];
|
|
15
|
-
errorPayload?: (
|
|
16
|
+
errorPayload?: (
|
|
17
|
+
error: Parameters<ApiErrorPresenter["resolveError"]>[0],
|
|
18
|
+
) => ComponentEventData["data"];
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
export function useEventedAction<TResult = unknown>(
|
|
@@ -317,7 +317,9 @@ function lookupCode<F extends string>(
|
|
|
317
317
|
): ApiFieldError | undefined {
|
|
318
318
|
if (!code || !codes) return undefined;
|
|
319
319
|
const bare = code.startsWith("$") ? code.slice(1) : code;
|
|
320
|
-
const
|
|
320
|
+
const own = (key: string) =>
|
|
321
|
+
Object.hasOwn(codes, key) ? codes[key] : undefined;
|
|
322
|
+
const entry = own(code) ?? own(bare) ?? own(`$${bare}`);
|
|
321
323
|
if (!entry) return undefined;
|
|
322
324
|
return isString(entry)
|
|
323
325
|
? { field: entry, message: code }
|
|
@@ -484,8 +486,12 @@ export interface HandleApiErrorOptions {
|
|
|
484
486
|
export function useFieldErrors<F extends string>(
|
|
485
487
|
options: UseFieldErrorsOptions<F>,
|
|
486
488
|
) {
|
|
487
|
-
const
|
|
488
|
-
const fieldIds = Object.keys(options.fields)
|
|
489
|
+
const errorPresenter = useApiErrorPresenter();
|
|
490
|
+
const fieldIds = Object.keys(options.fields).filter((key): key is F =>
|
|
491
|
+
Object.hasOwn(options.fields, key),
|
|
492
|
+
);
|
|
493
|
+
const knownFields = new Set<string>(fieldIds);
|
|
494
|
+
const isField = (name: string): name is F => knownFields.has(name);
|
|
489
495
|
const errors: Partial<Record<F, string>> = reactive({});
|
|
490
496
|
|
|
491
497
|
function controlId(field: F): string {
|
|
@@ -547,12 +553,14 @@ export function useFieldErrors<F extends string>(
|
|
|
547
553
|
if (fields.length === 0) return false;
|
|
548
554
|
clear();
|
|
549
555
|
for (const entry of fields) {
|
|
550
|
-
|
|
556
|
+
if (!isField(entry.field)) continue;
|
|
557
|
+
errors[entry.field] = errorPresenter.resolveError(entry.message, {
|
|
551
558
|
fallbackKey: entry.fallbackKey ?? "dms.field_errors.invalid",
|
|
552
559
|
params: entry.params,
|
|
553
560
|
})?.message;
|
|
554
561
|
}
|
|
555
|
-
|
|
562
|
+
const first = fields[0]!.field;
|
|
563
|
+
if (isField(first)) await focus(first);
|
|
556
564
|
return !hasUnmatched;
|
|
557
565
|
}
|
|
558
566
|
|
|
@@ -561,7 +569,7 @@ export function useFieldErrors<F extends string>(
|
|
|
561
569
|
error: Parameters<typeof resolveApiErrorMessage>[0],
|
|
562
570
|
toastOptions: HandleApiErrorOptions,
|
|
563
571
|
) {
|
|
564
|
-
presentError(error, {
|
|
572
|
+
errorPresenter.presentError(error, {
|
|
565
573
|
fallbackKey: toastOptions.toastDescription ?? toastOptions.toastTitle,
|
|
566
574
|
});
|
|
567
575
|
}
|
|
@@ -23,9 +23,14 @@ const COOKIE_MAX_AGE_ONE_YEAR = 60 * 60 * 24 * 365;
|
|
|
23
23
|
*/
|
|
24
24
|
export const MAX_PREFERENCES_COOKIE_BYTES = 3 * 1024;
|
|
25
25
|
|
|
26
|
-
const toPlain =
|
|
26
|
+
const toPlain = (value: PreferencesTree[string]): PreferencesTree[string] =>
|
|
27
27
|
value === undefined ? value : JSON.parse(JSON.stringify(value));
|
|
28
28
|
|
|
29
|
+
const toPlainTree = (tree: PreferencesTree): PreferencesTree => {
|
|
30
|
+
const plain = toPlain(tree);
|
|
31
|
+
return isBranch(plain) ? plain : {};
|
|
32
|
+
};
|
|
33
|
+
|
|
29
34
|
/**
|
|
30
35
|
* The user's preferences, kept in the `dms-preferences` cookie so that a
|
|
31
36
|
* server render reads them too: a tree addressed by dotted paths, stored as
|
|
@@ -70,7 +75,7 @@ export const usePreferences = () => {
|
|
|
70
75
|
value: UserPreferences[string],
|
|
71
76
|
): void => {
|
|
72
77
|
const keys = keyPath.split(".");
|
|
73
|
-
const next =
|
|
78
|
+
const next = toPlainTree(tree.value);
|
|
74
79
|
writeAt(next, keys, toPlain(value));
|
|
75
80
|
markWritten(next, keys);
|
|
76
81
|
commit(next);
|
|
@@ -79,7 +84,7 @@ export const usePreferences = () => {
|
|
|
79
84
|
const removePreference = (keyPath: string): void => {
|
|
80
85
|
const keys = keyPath.split(".");
|
|
81
86
|
const lastKey = keys.pop()!;
|
|
82
|
-
const next =
|
|
87
|
+
const next = toPlainTree(tree.value);
|
|
83
88
|
const parent = keys.length === 0 ? next : readAt(next, keys);
|
|
84
89
|
if (!isBranch(parent) || !(lastKey in parent)) return;
|
|
85
90
|
|