@mountaya/studio 0.0.0-stage → 0.2.0
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 +69 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +917 -2
- package/dist/agent/index.cjs +2600 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +1237 -0
- package/dist/agent/index.d.ts +1237 -0
- package/dist/agent/index.js +2581 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-3Oi_Zrtm.js +9 -0
- package/dist/chunk-3Oi_Zrtm.js.map +1 -0
- package/dist/chunk-B18OPIu_.js +6 -0
- package/dist/chunk-B18OPIu_.js.map +1 -0
- package/dist/chunk-B5Uz3Qct.cjs +15 -0
- package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
- package/dist/chunk-BBEJwkd3.d.cts +839 -0
- package/dist/chunk-BIEc_SkR.cjs +29 -0
- package/dist/chunk-BIEc_SkR.cjs.map +1 -0
- package/dist/chunk-BKMFOe-N.js +171 -0
- package/dist/chunk-BKMFOe-N.js.map +1 -0
- package/dist/chunk-BP4uy7E1.d.ts +11583 -0
- package/dist/chunk-BSHTsFiB.js +1403 -0
- package/dist/chunk-BSHTsFiB.js.map +1 -0
- package/dist/chunk-BTUUABGI.js +17 -0
- package/dist/chunk-BTUUABGI.js.map +1 -0
- package/dist/chunk-BaPiaz5X.cjs +115 -0
- package/dist/chunk-BaPiaz5X.cjs.map +1 -0
- package/dist/chunk-BeCVpkYr.cjs +542 -0
- package/dist/chunk-BeCVpkYr.cjs.map +1 -0
- package/dist/chunk-BgngsvK8.cjs +6202 -0
- package/dist/chunk-BgngsvK8.cjs.map +1 -0
- package/dist/chunk-BhInd7CJ.d.cts +253 -0
- package/dist/chunk-Bn6ZbxkS.cjs +27 -0
- package/dist/chunk-By9ZnkVI.js +60 -0
- package/dist/chunk-By9ZnkVI.js.map +1 -0
- package/dist/chunk-BzqPhxsz.cjs +367 -0
- package/dist/chunk-BzqPhxsz.cjs.map +1 -0
- package/dist/chunk-C2mMX81q.d.ts +443 -0
- package/dist/chunk-C2rr9Q0V.cjs +1402 -0
- package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
- package/dist/chunk-CDJCbwIQ.d.cts +78 -0
- package/dist/chunk-CLGvBOVH.d.cts +1654 -0
- package/dist/chunk-COdw1dc6.d.ts +525 -0
- package/dist/chunk-CQCJnT2i.d.ts +511 -0
- package/dist/chunk-CSyHY67q.cjs +353 -0
- package/dist/chunk-CSyHY67q.cjs.map +1 -0
- package/dist/chunk-CiK1Iqrv.js +950 -0
- package/dist/chunk-CiK1Iqrv.js.map +1 -0
- package/dist/chunk-CmJBgSwZ.cjs +24 -0
- package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
- package/dist/chunk-CnrsRK2u.cjs +83 -0
- package/dist/chunk-CnrsRK2u.cjs.map +1 -0
- package/dist/chunk-Co782_9r.js +326 -0
- package/dist/chunk-Co782_9r.js.map +1 -0
- package/dist/chunk-Csr3KDpZ.cjs +32 -0
- package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
- package/dist/chunk-CwkmccXv.js +89 -0
- package/dist/chunk-CwkmccXv.js.map +1 -0
- package/dist/chunk-D0Q4iL9B.cjs +255 -0
- package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
- package/dist/chunk-DFwiSzUS.cjs +72 -0
- package/dist/chunk-DFwiSzUS.cjs.map +1 -0
- package/dist/chunk-DIFayl2P.d.cts +443 -0
- package/dist/chunk-DIGF58ux.d.cts +525 -0
- package/dist/chunk-DKuuuld5.js +101 -0
- package/dist/chunk-DKuuuld5.js.map +1 -0
- package/dist/chunk-DMePkFEo.js +5054 -0
- package/dist/chunk-DMePkFEo.js.map +1 -0
- package/dist/chunk-DO5SIBgu.js +305 -0
- package/dist/chunk-DO5SIBgu.js.map +1 -0
- package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
- package/dist/chunk-DThaaNeb.d.cts +15 -0
- package/dist/chunk-DThaaNeb.d.ts +15 -0
- package/dist/chunk-DUQzjUJy.d.ts +78 -0
- package/dist/chunk-DX37IPhV.cjs +1903 -0
- package/dist/chunk-DX37IPhV.cjs.map +1 -0
- package/dist/chunk-Damps5Tk.cjs +155 -0
- package/dist/chunk-Damps5Tk.cjs.map +1 -0
- package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
- package/dist/chunk-De0vAASv.d.ts +253 -0
- package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
- package/dist/chunk-DjEvqvPA.cjs +43 -0
- package/dist/chunk-DjEvqvPA.cjs.map +1 -0
- package/dist/chunk-DkwDzwvu.d.cts +121 -0
- package/dist/chunk-DkwDzwvu.d.ts +121 -0
- package/dist/chunk-Dmszv9If.js +71 -0
- package/dist/chunk-Dmszv9If.js.map +1 -0
- package/dist/chunk-Dp_ftNWY.d.cts +511 -0
- package/dist/chunk-DsHQySz0.js +31 -0
- package/dist/chunk-DsHQySz0.js.map +1 -0
- package/dist/chunk-DwoUyHHh.js +281 -0
- package/dist/chunk-DwoUyHHh.js.map +1 -0
- package/dist/chunk-IaIDQflj.d.cts +2315 -0
- package/dist/chunk-IaIDQflj.d.ts +2315 -0
- package/dist/chunk-cVXLsZfL.d.ts +839 -0
- package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
- package/dist/chunk-nJQxbOwQ.cjs +8962 -0
- package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
- package/dist/chunk-o9jaxhCO.js +8852 -0
- package/dist/chunk-o9jaxhCO.js.map +1 -0
- package/dist/chunk-p-Tt_Lwz.js +14 -0
- package/dist/chunk-p-Tt_Lwz.js.map +1 -0
- package/dist/engines/index.cjs +2091 -0
- package/dist/engines/index.cjs.map +1 -0
- package/dist/engines/index.d.cts +2176 -0
- package/dist/engines/index.d.ts +2176 -0
- package/dist/engines/index.js +2075 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/handlers/index.cjs +53 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +403 -0
- package/dist/handlers/index.d.ts +403 -0
- package/dist/handlers/index.js +33 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.cjs +3511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +3033 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +510 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +296 -0
- package/dist/plugins/index.d.ts +296 -0
- package/dist/plugins/index.js +489 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/seams/index.cjs +89 -0
- package/dist/seams/index.cjs.map +1 -0
- package/dist/seams/index.d.cts +452 -0
- package/dist/seams/index.d.ts +452 -0
- package/dist/seams/index.js +49 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/strings/fr/index.cjs +2135 -0
- package/dist/strings/fr/index.cjs.map +1 -0
- package/dist/strings/fr/index.d.cts +17 -0
- package/dist/strings/fr/index.d.ts +17 -0
- package/dist/strings/fr/index.js +2130 -0
- package/dist/strings/fr/index.js.map +1 -0
- package/dist/strings/index.cjs +2384 -0
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +3 -0
- package/dist/strings/index.d.ts +3 -0
- package/dist/strings/index.js +2353 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/testing/index.cjs +230 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +246 -0
- package/dist/testing/index.d.ts +246 -0
- package/dist/testing/index.js +219 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/time/index.cjs +28 -0
- package/dist/time/index.cjs.map +1 -0
- package/dist/time/index.d.cts +41 -0
- package/dist/time/index.d.ts +41 -0
- package/dist/time/index.js +23 -0
- package/dist/time/index.js.map +1 -0
- package/package.json +224 -4
- package/src/agent/engines/agentThreads.ts +1601 -0
- package/src/agent/engines/directorChat.ts +500 -0
- package/src/agent/index.ts +67 -0
- package/src/agent/rules/agentEditLock.ts +115 -0
- package/src/agent/rules/agentErrorCopy.ts +44 -0
- package/src/agent/rules/copilotOrganization.ts +36 -0
- package/src/agent/rules/playbook.gen.ts +444 -0
- package/src/agent/rules/router.ts +518 -0
- package/src/agent/rules/stateDelta.ts +29 -0
- package/src/agent/rules/studioRouter.ts +123 -0
- package/src/agent/rules/surfaces.gen.ts +633 -0
- package/src/agent/rules/threadsUrl.ts +48 -0
- package/src/agent/rules/transcriptObserver.ts +90 -0
- package/src/agent/stores/agentThreads.ts +451 -0
- package/src/bus/contracts/noData.ts +18 -0
- package/src/bus/contracts/shared.ts +172 -0
- package/src/bus/contracts/studioTools.ts +224 -0
- package/src/bus/rules/bus.ts +857 -0
- package/src/bus/rules/confirmation.ts +22 -0
- package/src/bus/rules/defineRegistry.ts +24 -0
- package/src/bus/rules/errors.ts +401 -0
- package/src/bus/rules/handlerErrors.ts +103 -0
- package/src/bus/rules/handlerRegistry.ts +627 -0
- package/src/bus/rules/inputSchema.ts +232 -0
- package/src/bus/rules/invalidInput.ts +441 -0
- package/src/bus/rules/lateBoundTools.ts +100 -0
- package/src/bus/rules/studioRegistry.ts +324 -0
- package/src/bus/rules/studioToolBus.ts +73 -0
- package/src/bus/rules/types.ts +804 -0
- package/src/chrome/contracts/alert.ts +42 -0
- package/src/chrome/contracts/itinerary.ts +26 -0
- package/src/chrome/contracts/map.ts +23 -0
- package/src/chrome/contracts/overlay.ts +46 -0
- package/src/chrome/contracts/panel.ts +29 -0
- package/src/chrome/contracts/question.ts +52 -0
- package/src/chrome/contracts/selection.ts +26 -0
- package/src/chrome/contracts/sidenav.ts +23 -0
- package/src/chrome/contracts/snapshot.ts +319 -0
- package/src/chrome/contracts/state.ts +22 -0
- package/src/chrome/contracts/tabs.ts +56 -0
- package/src/chrome/handlers/alert.ts +91 -0
- package/src/chrome/handlers/introspection.ts +180 -0
- package/src/chrome/handlers/panels.ts +42 -0
- package/src/chrome/handlers/question.ts +24 -0
- package/src/chrome/handlers/sidenav.ts +116 -0
- package/src/chrome/handlers/snapshot.ts +451 -0
- package/src/chrome/handlers/stateDelta.ts +125 -0
- package/src/chrome/handlers/tabs.ts +143 -0
- package/src/chrome/handlers/timestamp.ts +19 -0
- package/src/chrome/rules/agentSelectors.ts +210 -0
- package/src/chrome/rules/mapAlert.ts +13 -0
- package/src/chrome/rules/question.ts +25 -0
- package/src/chrome/rules/tabs.ts +13 -0
- package/src/chrome/stores/activeDraftSession.ts +134 -0
- package/src/chrome/stores/chrome.ts +527 -0
- package/src/chrome/stores/uiStore.ts +575 -0
- package/src/collab/contracts/collab.ts +261 -0
- package/src/collab/handlers/collab.ts +468 -0
- package/src/collab/rules/toolNames.ts +33 -0
- package/src/collab/stores/collab.ts +899 -0
- package/src/collections/contracts/collection.ts +182 -0
- package/src/collections/handlers/collectionAttach.ts +141 -0
- package/src/collections/handlers/collections.ts +499 -0
- package/src/collections/handlers/heldCollection.ts +42 -0
- package/src/collections/handlers/restCollections.ts +386 -0
- package/src/collections/rules/collections.ts +138 -0
- package/src/collections/rules/entityCollections.ts +53 -0
- package/src/collections/stores/collections.ts +133 -0
- package/src/data/contracts/data.ts +233 -0
- package/src/data/contracts/itinerary.ts +71 -0
- package/src/data/handlers/activityResolve.ts +76 -0
- package/src/data/handlers/data.ts +200 -0
- package/src/data/handlers/graphql.ts +26 -0
- package/src/data/handlers/mutationSink.ts +1577 -0
- package/src/data/handlers/profile.ts +83 -0
- package/src/data/handlers/writeThrough.ts +417 -0
- package/src/data/rules/cache.ts +181 -0
- package/src/data/rules/dataTypes.ts +40 -0
- package/src/data/rules/keys.ts +106 -0
- package/src/data/rules/persistence.ts +1058 -0
- package/src/data/rules/requestBody.ts +43 -0
- package/src/data/rules/restErrors.ts +354 -0
- package/src/data/rules/sessionSurface.ts +156 -0
- package/src/data/rules/toolResultData.ts +73 -0
- package/src/data/rules/uuid.ts +24 -0
- package/src/edit/contracts/edit.ts +37 -0
- package/src/edit/contracts/itinerary.ts +57 -0
- package/src/edit/handlers/draftCommit.ts +257 -0
- package/src/edit/handlers/editDiscard.ts +34 -0
- package/src/edit/handlers/editLock.ts +949 -0
- package/src/edit/handlers/editor.ts +203 -0
- package/src/edit/handlers/formUnsaved.ts +24 -0
- package/src/edit/rules/draftMetadata.ts +117 -0
- package/src/edit/rules/editKeyboard.ts +222 -0
- package/src/edit/rules/editShortcuts.ts +102 -0
- package/src/edit/rules/editTooltip.ts +174 -0
- package/src/edit/rules/editorTaken.ts +49 -0
- package/src/edit/rules/history.ts +26 -0
- package/src/edit/rules/unsavedWork.ts +60 -0
- package/src/edit/stores/editorReservation.ts +70 -0
- package/src/edit/stores/formsUnsaved.ts +54 -0
- package/src/embed/contracts/embed.ts +48 -0
- package/src/embed/engines/embedFraming.ts +1329 -0
- package/src/embed/engines/embedReady.ts +353 -0
- package/src/embed/engines/framingPageSession.ts +169 -0
- package/src/embed/handlers/embed.ts +130 -0
- package/src/embed/rules/allowedDomains.ts +71 -0
- package/src/embed/rules/bridgeMessages.ts +224 -0
- package/src/embed/rules/defaults.ts +173 -0
- package/src/embed/rules/displaySeed.ts +115 -0
- package/src/embed/rules/embedAllowlist.ts +146 -0
- package/src/embed/rules/embedConstraints.ts +215 -0
- package/src/embed/rules/embedElements.ts +277 -0
- package/src/embed/rules/embedSectionFields.ts +126 -0
- package/src/embed/rules/embedSecurity.ts +116 -0
- package/src/embed/rules/fieldDependencies.ts +89 -0
- package/src/embed/rules/fieldOptions.ts +138 -0
- package/src/embed/rules/layerOptions.ts +161 -0
- package/src/embed/rules/readyProtocol.ts +66 -0
- package/src/embed/rules/safetyRules.ts +215 -0
- package/src/embed/rules/snippet.ts +531 -0
- package/src/embed/rules/tableCode.ts +270 -0
- package/src/embed/stores/embed.ts +60 -0
- package/src/embed/stores/embedContent.ts +77 -0
- package/src/engines/index.ts +81 -0
- package/src/handlers/index.ts +66 -0
- package/src/index.ts +1065 -0
- package/src/itinerary/contracts/itinerary.ts +705 -0
- package/src/itinerary/engines/itineraryPace.ts +612 -0
- package/src/itinerary/engines/profileMarker.ts +238 -0
- package/src/itinerary/handlers/importStaging.ts +352 -0
- package/src/itinerary/handlers/itinerary.ts +572 -0
- package/src/itinerary/handlers/itineraryDuplicate.ts +177 -0
- package/src/itinerary/handlers/itineraryExport.ts +117 -0
- package/src/itinerary/handlers/itineraryImport.ts +783 -0
- package/src/itinerary/handlers/itineraryPublish.ts +118 -0
- package/src/itinerary/handlers/itinerarySelection.ts +354 -0
- package/src/itinerary/handlers/itinerarySuggest.ts +1186 -0
- package/src/itinerary/handlers/itineraryUnpublish.ts +101 -0
- package/src/itinerary/handlers/publicationScope.ts +118 -0
- package/src/itinerary/handlers/restItineraries.ts +752 -0
- package/src/itinerary/handlers/restItineraryExport.ts +70 -0
- package/src/itinerary/handlers/restItineraryImport.ts +311 -0
- package/src/itinerary/handlers/restItineraryPace.ts +87 -0
- package/src/itinerary/handlers/restItineraryRecord.ts +36 -0
- package/src/itinerary/handlers/suggestParams.ts +379 -0
- package/src/itinerary/handlers/suggestStaging.ts +363 -0
- package/src/itinerary/handlers/surfaceOpen.ts +389 -0
- package/src/itinerary/rules/activity.ts +139 -0
- package/src/itinerary/rules/analysis.ts +42 -0
- package/src/itinerary/rules/ceiling.ts +49 -0
- package/src/itinerary/rules/createFlow.ts +107 -0
- package/src/itinerary/rules/densify.ts +440 -0
- package/src/itinerary/rules/draftSurface.ts +219 -0
- package/src/itinerary/rules/editorView.ts +83 -0
- package/src/itinerary/rules/export.ts +159 -0
- package/src/itinerary/rules/friendlyName.ts +77 -0
- package/src/itinerary/rules/import.ts +1050 -0
- package/src/itinerary/rules/importFiles.ts +140 -0
- package/src/itinerary/rules/importTotals.ts +77 -0
- package/src/itinerary/rules/liveSegment.ts +712 -0
- package/src/itinerary/rules/lngLat.ts +17 -0
- package/src/itinerary/rules/mapSync.ts +100 -0
- package/src/itinerary/rules/previewRender.ts +416 -0
- package/src/itinerary/rules/profileReadout.ts +216 -0
- package/src/itinerary/rules/routing.ts +707 -0
- package/src/itinerary/rules/suggest.ts +522 -0
- package/src/itinerary/rules/suggestionPreview.ts +119 -0
- package/src/itinerary/rules/view.ts +61 -0
- package/src/itinerary/stores/importSession.ts +319 -0
- package/src/itinerary/stores/itinerary.ts +331 -0
- package/src/itinerary/stores/itineraryDuplicate.ts +76 -0
- package/src/itinerary/stores/sessionIdentity.ts +43 -0
- package/src/itinerary/stores/suggestSession.ts +418 -0
- package/src/layers/contracts/itinerary.ts +46 -0
- package/src/layers/contracts/overlay.ts +132 -0
- package/src/layers/handlers/enrichment.ts +36 -0
- package/src/layers/handlers/overlay.ts +406 -0
- package/src/layers/handlers/restLayers.ts +94 -0
- package/src/layers/handlers/tiles.ts +25 -0
- package/src/layers/rules/layers.ts +212 -0
- package/src/layers/rules/overlayInstant.ts +12 -0
- package/src/layers/rules/reachabilityIcon.ts +18 -0
- package/src/layers/rules/readout.ts +102 -0
- package/src/layers/stores/layers.ts +262 -0
- package/src/map/contracts/contextmenu.ts +33 -0
- package/src/map/contracts/geolocate.ts +37 -0
- package/src/map/contracts/map.ts +146 -0
- package/src/map/contracts/streetview.ts +53 -0
- package/src/map/contracts/terrain.ts +152 -0
- package/src/map/handlers/contextMenu.ts +135 -0
- package/src/map/handlers/geolocate.ts +52 -0
- package/src/map/handlers/map.ts +391 -0
- package/src/map/handlers/streetview.ts +94 -0
- package/src/map/handlers/terrain.ts +663 -0
- package/src/map/rules/baseTerrain.ts +75 -0
- package/src/map/rules/clickTargets.ts +464 -0
- package/src/map/rules/constraints.ts +32 -0
- package/src/map/rules/contextMenuReadout.ts +67 -0
- package/src/map/rules/coordinates.ts +71 -0
- package/src/map/rules/itineraryFit.ts +8 -0
- package/src/map/rules/mapEvents.ts +64 -0
- package/src/map/rules/mapProjection.ts +476 -0
- package/src/map/rules/terrainReading.ts +62 -0
- package/src/plugins/contracts/ids.ts +66 -0
- package/src/plugins/contracts/plugin.ts +202 -0
- package/src/plugins/contracts/slots.ts +137 -0
- package/src/plugins/engines/studioPlugin.ts +1365 -0
- package/src/plugins/index.ts +111 -0
- package/src/plugins/rules/contributions.ts +152 -0
- package/src/plugins/rules/errors.ts +60 -0
- package/src/plugins/rules/ids.ts +42 -0
- package/src/plugins/rules/validation.ts +249 -0
- package/src/rules/listeners.ts +57 -0
- package/src/rules/origin.ts +13 -0
- package/src/rules/storeWrite.ts +37 -0
- package/src/rules/types.ts +136 -0
- package/src/seams/index.ts +79 -0
- package/src/seams/rules/clock.ts +28 -0
- package/src/seams/rules/formatters.ts +211 -0
- package/src/seams/rules/ids.ts +102 -0
- package/src/seams/rules/links.ts +66 -0
- package/src/seams/rules/navigation.ts +222 -0
- package/src/seams/rules/notify.ts +49 -0
- package/src/seams/rules/persistenceDrawer.ts +220 -0
- package/src/seams/rules/saveFile.ts +101 -0
- package/src/seams/rules/seams.ts +156 -0
- package/src/seams/rules/storage.ts +116 -0
- package/src/search/contracts/overlay.ts +74 -0
- package/src/search/contracts/search.ts +197 -0
- package/src/search/handlers/pois.ts +57 -0
- package/src/search/handlers/search.ts +280 -0
- package/src/search/rules/params.ts +925 -0
- package/src/search/rules/poiGroups.ts +138 -0
- package/src/search/rules/searchFetch.ts +139 -0
- package/src/search/rules/timeWindow.ts +30 -0
- package/src/search/stores/search.ts +51 -0
- package/src/segments/contracts/itinerary.ts +433 -0
- package/src/segments/contracts/segment.ts +35 -0
- package/src/segments/engines/segmentDraft.ts +926 -0
- package/src/segments/handlers/chainGuards.ts +67 -0
- package/src/segments/handlers/directions.ts +44 -0
- package/src/segments/handlers/itineraryEcho.ts +45 -0
- package/src/segments/handlers/roadAccessDialog.ts +34 -0
- package/src/segments/handlers/segment.ts +111 -0
- package/src/segments/handlers/segmentEdit.ts +1341 -0
- package/src/segments/handlers/segmentGroups.ts +347 -0
- package/src/segments/handlers/segmentStructure.ts +1144 -0
- package/src/segments/rules/chain.ts +196 -0
- package/src/segments/rules/chainModel.ts +217 -0
- package/src/segments/rules/colors.ts +11 -0
- package/src/segments/rules/commit.ts +76 -0
- package/src/segments/rules/draft.ts +90 -0
- package/src/segments/rules/draftDisposition.ts +43 -0
- package/src/segments/rules/draftSegmentEdit.ts +129 -0
- package/src/segments/rules/engine.ts +222 -0
- package/src/segments/rules/groupSave.ts +234 -0
- package/src/segments/rules/hazardPrompt.ts +60 -0
- package/src/segments/rules/itineraryEcho.ts +40 -0
- package/src/segments/rules/liveSegmentProjection.ts +55 -0
- package/src/segments/rules/merge.ts +51 -0
- package/src/segments/rules/metrics.ts +456 -0
- package/src/segments/rules/naming.ts +168 -0
- package/src/segments/rules/segmentArming.ts +144 -0
- package/src/segments/rules/splitPick.ts +84 -0
- package/src/segments/rules/viaSimplify.ts +230 -0
- package/src/segments/stores/directions.ts +77 -0
- package/src/segments/stores/roadAccessDialog.ts +58 -0
- package/src/segments/stores/segmentEdit.ts +922 -0
- package/src/segments/stores/segmentGroupEdit.ts +84 -0
- package/src/segments/stores/segmentSplit.ts +77 -0
- package/src/share/contracts/share.ts +39 -0
- package/src/share/contracts/shareLink.ts +63 -0
- package/src/share/engines/shareLink.ts +1053 -0
- package/src/share/handlers/share.ts +47 -0
- package/src/share/handlers/shareLink.ts +231 -0
- package/src/share/handlers/shareScope.ts +54 -0
- package/src/share/rules/link.ts +89 -0
- package/src/share/rules/shareLink.ts +218 -0
- package/src/share/rules/targets.ts +92 -0
- package/src/share/rules/viewConfig.ts +95 -0
- package/src/share/stores/share.ts +58 -0
- package/src/strings/fr/index.ts +18 -0
- package/src/strings/fr/rules/fr.ts +2368 -0
- package/src/strings/index.ts +98 -0
- package/src/strings/rules/confirmCopy.ts +156 -0
- package/src/strings/rules/draftToolNames.ts +94 -0
- package/src/strings/rules/en.ts +2519 -0
- package/src/strings/rules/failureAlert.ts +115 -0
- package/src/strings/rules/formError.ts +400 -0
- package/src/strings/rules/maneuvers.ts +107 -0
- package/src/strings/rules/outputOptions.ts +126 -0
- package/src/strings/rules/publicationState.ts +100 -0
- package/src/strings/rules/routeHazardCopy.ts +62 -0
- package/src/strings/rules/searchLabels.ts +50 -0
- package/src/strings/rules/segmentChainVerbs.ts +62 -0
- package/src/strings/rules/studioCopy.ts +130 -0
- package/src/strings/rules/unitOptions.ts +119 -0
- package/src/testing/checkedBus.ts +226 -0
- package/src/testing/index.ts +30 -0
- package/src/testing/plugins.ts +106 -0
- package/src/testing/studio.ts +267 -0
- package/src/testing/urlSeam.ts +153 -0
- package/src/time/index.ts +12 -0
- package/src/time/rules/sun.ts +78 -0
- package/src/video/contracts/cameraSchemas.ts +266 -0
- package/src/video/contracts/profileSchemas.ts +37 -0
- package/src/video/contracts/video.ts +601 -0
- package/src/video/handlers/video.ts +1638 -0
- package/src/video/handlers/videoDirector.ts +114 -0
- package/src/video/rules/previewRefresh.ts +76 -0
- package/src/video/rules/profileSource.ts +51 -0
- package/src/video/rules/routeSpans.ts +79 -0
- package/src/video/rules/shotDefaults.ts +28 -0
- package/src/video/rules/stepOrder.ts +17 -0
- package/src/video/rules/videoSnapshot.ts +136 -0
- package/src/video/stores/directorThreads.ts +167 -0
- package/src/video/stores/videoExport.ts +290 -0
- package/src/viewer/contracts/preferences.ts +40 -0
- package/src/viewer/handlers/preferences.ts +91 -0
- package/src/viewer/rules/capabilities.ts +42 -0
- package/src/viewer/rules/config.ts +266 -0
- package/src/viewer/rules/context.ts +375 -0
- package/src/viewer/rules/ownership.ts +134 -0
- package/src/viewer/rules/platformViewer.ts +199 -0
- package/src/viewer/rules/scope.ts +197 -0
- package/src/viewer/rules/url.ts +145 -0
- package/src/viewer/rules/viewer.ts +307 -0
- package/src/viewer/rules/viewerSeam.ts +49 -0
- package/src/viewer/rules/viewerUnits.ts +34 -0
- package/src/waypoints/contracts/itinerary.ts +417 -0
- package/src/waypoints/handlers/poiWaypointStyle.ts +32 -0
- package/src/waypoints/handlers/waypointDetailsDialog.ts +38 -0
- package/src/waypoints/handlers/waypointEdit.ts +1073 -0
- package/src/waypoints/rules/amenities.ts +30 -0
- package/src/waypoints/rules/defaults.ts +31 -0
- package/src/waypoints/rules/details.ts +213 -0
- package/src/waypoints/rules/detailsDraft.ts +312 -0
- package/src/waypoints/rules/detailsPreview.ts +76 -0
- package/src/waypoints/rules/detailsSave.ts +356 -0
- package/src/waypoints/rules/draftDirty.ts +45 -0
- package/src/waypoints/rules/icons.ts +32 -0
- package/src/waypoints/rules/liveWaypoint.ts +63 -0
- package/src/waypoints/rules/naming.ts +185 -0
- package/src/waypoints/rules/sections.ts +77 -0
- package/src/waypoints/rules/waypointDraft.ts +62 -0
- package/src/waypoints/stores/waypointDetails.ts +62 -0
- package/src/waypoints/stores/waypointEdit.ts +566 -0
- package/src/zones/contracts/collection.ts +37 -0
- package/src/zones/contracts/zone.ts +528 -0
- package/src/zones/engines/zoneForm.ts +1773 -0
- package/src/zones/handlers/restZones.ts +287 -0
- package/src/zones/handlers/zonePublish.ts +206 -0
- package/src/zones/handlers/zoneUnpublish.ts +56 -0
- package/src/zones/handlers/zones.ts +2254 -0
- package/src/zones/rules/geometry.ts +946 -0
- package/src/zones/rules/zoneDefaults.ts +34 -0
- package/src/zones/rules/zoneDraft.ts +54 -0
- package/src/zones/rules/zoneForm.ts +563 -0
- package/src/zones/rules/zoneMetadata.ts +29 -0
- package/src/zones/rules/zoneSource.ts +87 -0
- package/src/zones/rules/zoneSourceRefusal.ts +104 -0
- package/src/zones/stores/zoneEdit.ts +998 -0
|
@@ -0,0 +1,1058 @@
|
|
|
1
|
+
import type { Geometry, LineString, Position } from "geojson";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ItineraryCreateParams,
|
|
5
|
+
ItineraryDuplicateParams,
|
|
6
|
+
ItinerarySegment,
|
|
7
|
+
ItineraryUpdateParams,
|
|
8
|
+
ItineraryWaypoint,
|
|
9
|
+
ItineraryWithDetails,
|
|
10
|
+
Mountaya,
|
|
11
|
+
SegmentConvertParams,
|
|
12
|
+
SegmentCreateParams,
|
|
13
|
+
SegmentGroupCreateParams,
|
|
14
|
+
SegmentGroupUpdateParams,
|
|
15
|
+
SegmentSplitParams,
|
|
16
|
+
SegmentUpdateParams,
|
|
17
|
+
ShareLink,
|
|
18
|
+
WaypointCreateParams,
|
|
19
|
+
WaypointUpdateParams,
|
|
20
|
+
} from "@mountaya/client";
|
|
21
|
+
import { MountayaElementsError, MountayaElementsNotFoundError } from "@mountaya/elements/errors";
|
|
22
|
+
import { buildGeometryCollection, extractLines, extractVias } from "@mountaya/elements/geo";
|
|
23
|
+
import { durationForSpeed, resolveSpeedKmh } from "@mountaya/elements/profile";
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
convertSegment,
|
|
27
|
+
createItinerary,
|
|
28
|
+
createSegment,
|
|
29
|
+
createSegmentGroup,
|
|
30
|
+
createWaypoint,
|
|
31
|
+
deleteItinerary,
|
|
32
|
+
deleteSegment,
|
|
33
|
+
deleteSegmentGroup,
|
|
34
|
+
deleteWaypoint,
|
|
35
|
+
disableItineraryShareLink,
|
|
36
|
+
duplicateItinerary,
|
|
37
|
+
fetchItineraryShareLink,
|
|
38
|
+
mergeSegment,
|
|
39
|
+
mintItineraryShareLink,
|
|
40
|
+
publishItinerary,
|
|
41
|
+
rotateItineraryShareLink,
|
|
42
|
+
splitSegment,
|
|
43
|
+
unpublishItinerary,
|
|
44
|
+
updateItinerary,
|
|
45
|
+
updateSegment,
|
|
46
|
+
updateSegmentGroup,
|
|
47
|
+
updateWaypoint,
|
|
48
|
+
} from "../../itinerary/handlers/restItineraries.js";
|
|
49
|
+
import { fetchItineraryRecord } from "../../itinerary/handlers/restItineraryRecord.js";
|
|
50
|
+
import { withItineraryAnalysis, withSegmentAnalysis } from "../../itinerary/rules/analysis.js";
|
|
51
|
+
import type { ItinerarySurface } from "../../itinerary/rules/export.js";
|
|
52
|
+
import type { Activity } from "../../rules/types.js";
|
|
53
|
+
import type { Clock } from "../../seams/rules/clock.js";
|
|
54
|
+
import type { StudioIds } from "../../seams/rules/ids.js";
|
|
55
|
+
import {
|
|
56
|
+
localPersistenceDrawer,
|
|
57
|
+
memoryPersistenceDrawer,
|
|
58
|
+
type StudioPersistenceDrawer,
|
|
59
|
+
} from "../../seams/rules/persistenceDrawer.js";
|
|
60
|
+
import { studioSeamAbsences } from "../../seams/rules/seams.js";
|
|
61
|
+
import { segmentLengthMeters } from "../../segments/rules/metrics.js";
|
|
62
|
+
import { SegmentDeleteNotEdgeError } from "./restErrors.js";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* StudioPersistence is where a committed write goes.
|
|
66
|
+
*
|
|
67
|
+
* A host mounting the studio can hand it preferences with nowhere to put them
|
|
68
|
+
* ({@link createMemoryViewer}), a storage that keeps nothing ({@link memoryStudioStorage}) and a
|
|
69
|
+
* save-file that refuses ({@link inertStudioSaveFile}), and a write has the same seam in front of
|
|
70
|
+
* it. A demo, a docs example, a sandbox inside somebody else's Embedded Studio and a
|
|
71
|
+
* preview of an itinerary the reader may not edit all need the same thing: an editor whose verbs
|
|
72
|
+
* WORK, writing somewhere that is not a customer's itinerary.
|
|
73
|
+
*
|
|
74
|
+
* **Domain level, not wire level.** Every method speaks {@link ItineraryWithDetails},
|
|
75
|
+
* {@link ItinerarySegment} and {@link ItineraryWaypoint}, exactly as the functions in
|
|
76
|
+
* `itinerary/handlers/restItineraries.ts` and `itinerary/handlers/restItineraryRecord.ts` do, and
|
|
77
|
+
* the member names are those functions' names minus their `client` argument. A wire-level seam (a fetch, a transport, a URL matcher)
|
|
78
|
+
* would put every caller's knowledge of the REST surface into the implementation of the null
|
|
79
|
+
* object, so a second implementation would have to reproduce the API rather than the behaviour.
|
|
80
|
+
*
|
|
81
|
+
* **The whole seam is one object and not one method per capability.** A host is choosing where
|
|
82
|
+
* writes go, once, for the mount, and not per verb. A per-verb override would let a studio persist
|
|
83
|
+
* segments to a customer's itinerary and waypoints to a sandbox, which is not a state any product
|
|
84
|
+
* wants and is the kind of half-wiring that is discovered in the data rather than in the code.
|
|
85
|
+
*
|
|
86
|
+
* `restStudioPersistence` is the default and is what an unset seam resolves to.
|
|
87
|
+
*/
|
|
88
|
+
export interface StudioPersistence {
|
|
89
|
+
/**
|
|
90
|
+
* Whether a record this seam persisted can be read back from the itinerary vector tiles.
|
|
91
|
+
*
|
|
92
|
+
* An EXPLICIT fact rather than an inference, because the alternative is a renderer deciding
|
|
93
|
+
* "this client looks local", which is the kind of magic that is wrong once and then impossible
|
|
94
|
+
* to find. It is on the seam rather than on the host config because it is a property OF the
|
|
95
|
+
* seam: whoever wrote the implementation knows whether their writes reach the tile server, and
|
|
96
|
+
* nobody above them does.
|
|
97
|
+
*
|
|
98
|
+
* What reads it: `useStudioPreviewSync` in `@mountaya/studio-react`, and {@link writeThrough},
|
|
99
|
+
* which reads an untiled seam's record back after a write. A persisted itinerary is
|
|
100
|
+
* normally painted by the always-on `itinerary_lines` / `itinerary_points` tiles and repainted
|
|
101
|
+
* by busting that cache, which is a server round trip. False, that round trip answers with the
|
|
102
|
+
* itinerary as the server still has it, so the hook suppresses the tile copy and paints the
|
|
103
|
+
* active itinerary out of the store instead. Without it a locally committed segment is drawn by
|
|
104
|
+
* the edit engine and then vanishes the moment the engine tears down, while still showing in the
|
|
105
|
+
* segment list and the elevation profile.
|
|
106
|
+
*/
|
|
107
|
+
readonly tiled: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Switches which engine defines a segment's geometry, and answers the itinerary as the switch
|
|
110
|
+
* left it: a re-derived geometry moves the boundaries the segment shares with its neighbours.
|
|
111
|
+
*/
|
|
112
|
+
convertSegment: (
|
|
113
|
+
itineraryId: string,
|
|
114
|
+
segmentId: string,
|
|
115
|
+
params: SegmentConvertParams,
|
|
116
|
+
) => Promise<ItineraryWithDetails>;
|
|
117
|
+
/**
|
|
118
|
+
* Creates the itinerary shell and answers it, or null for one that was saved and that this seam
|
|
119
|
+
* cannot name: the API made the create and could not answer it again, with no `Location` to
|
|
120
|
+
* read the itinerary at. The caller then reads its listings again and never sends the create a
|
|
121
|
+
* second time. A seam that always knows what it made never answers null.
|
|
122
|
+
*/
|
|
123
|
+
createItinerary: (params: ItineraryCreateParams) => Promise<ItineraryWithDetails | null>;
|
|
124
|
+
/**
|
|
125
|
+
* Adds a segment and answers it: appended at the tail of the chain, or, where `params` names
|
|
126
|
+
* `before_segment_id`, inserted ahead of that segment, the chain renumbering behind it.
|
|
127
|
+
*/
|
|
128
|
+
createSegment: (itineraryId: string, params: SegmentCreateParams) => Promise<ItinerarySegment>;
|
|
129
|
+
createSegmentGroup: (
|
|
130
|
+
itineraryId: string,
|
|
131
|
+
params: SegmentGroupCreateParams,
|
|
132
|
+
) => Promise<ItineraryWithDetails>;
|
|
133
|
+
createWaypoint: (itineraryId: string, params: WaypointCreateParams) => Promise<ItineraryWaypoint>;
|
|
134
|
+
deleteItinerary: (itineraryId: string) => Promise<void>;
|
|
135
|
+
deleteSegment: (itineraryId: string, segmentId: string) => Promise<void>;
|
|
136
|
+
deleteSegmentGroup: (itineraryId: string, groupId: string) => Promise<ItineraryWithDetails>;
|
|
137
|
+
deleteWaypoint: (itineraryId: string, waypointId: string) => Promise<void>;
|
|
138
|
+
disableItineraryShareLink: (itineraryId: string) => Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Copies an itinerary and answers the copy, or null for a copy that was saved and that this seam
|
|
141
|
+
* cannot name, as {@link StudioPersistence.createItinerary} answers it.
|
|
142
|
+
*/
|
|
143
|
+
duplicateItinerary: (
|
|
144
|
+
itineraryId: string,
|
|
145
|
+
params: ItineraryDuplicateParams,
|
|
146
|
+
) => Promise<ItineraryWithDetails | null>;
|
|
147
|
+
fetchItineraryRecord: (
|
|
148
|
+
itineraryId: string,
|
|
149
|
+
surface?: ItinerarySurface,
|
|
150
|
+
) => Promise<ItineraryWithDetails>;
|
|
151
|
+
/**
|
|
152
|
+
* Reads the itinerary's share link without setting one, and answers it, or `null` where none is
|
|
153
|
+
* set. The share dialog asks it when it opens, so opening the dialog creates nothing.
|
|
154
|
+
*/
|
|
155
|
+
fetchItineraryShareLink: (itineraryId: string) => Promise<ShareLink | null>;
|
|
156
|
+
mergeSegment: (itineraryId: string, segmentId: string) => Promise<ItineraryWithDetails>;
|
|
157
|
+
mintItineraryShareLink: (itineraryId: string) => Promise<ShareLink>;
|
|
158
|
+
publishItinerary: (itineraryId: string) => Promise<ItineraryWithDetails>;
|
|
159
|
+
rotateItineraryShareLink: (itineraryId: string) => Promise<ShareLink>;
|
|
160
|
+
splitSegment: (
|
|
161
|
+
itineraryId: string,
|
|
162
|
+
segmentId: string,
|
|
163
|
+
params: SegmentSplitParams,
|
|
164
|
+
) => Promise<ItineraryWithDetails>;
|
|
165
|
+
unpublishItinerary: (itineraryId: string) => Promise<ItineraryWithDetails>;
|
|
166
|
+
updateItinerary: (
|
|
167
|
+
itineraryId: string,
|
|
168
|
+
params: ItineraryUpdateParams,
|
|
169
|
+
) => Promise<ItineraryWithDetails>;
|
|
170
|
+
updateSegment: (
|
|
171
|
+
itineraryId: string,
|
|
172
|
+
segmentId: string,
|
|
173
|
+
params: SegmentUpdateParams,
|
|
174
|
+
) => Promise<ItinerarySegment>;
|
|
175
|
+
updateSegmentGroup: (
|
|
176
|
+
itineraryId: string,
|
|
177
|
+
groupId: string,
|
|
178
|
+
params: SegmentGroupUpdateParams,
|
|
179
|
+
) => Promise<ItineraryWithDetails>;
|
|
180
|
+
updateWaypoint: (
|
|
181
|
+
itineraryId: string,
|
|
182
|
+
waypointId: string,
|
|
183
|
+
params: WaypointUpdateParams,
|
|
184
|
+
) => Promise<ItineraryWaypoint>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* restStudioPersistence writes through the Mountaya API, which is what every mount that does not
|
|
189
|
+
* set a persistence does.
|
|
190
|
+
*
|
|
191
|
+
* A one-to-one binding and nothing else: each member is the function of the same name with the
|
|
192
|
+
* client already applied. There is deliberately no logic here: a decision made in this wrapper
|
|
193
|
+
* would be a decision the two null objects below could not see, and the point of the seam is that
|
|
194
|
+
* the three are interchangeable from above.
|
|
195
|
+
*/
|
|
196
|
+
export const restStudioPersistence = (client: Mountaya): StudioPersistence => ({
|
|
197
|
+
tiled: true,
|
|
198
|
+
convertSegment: (itineraryId, segmentId, params) =>
|
|
199
|
+
convertSegment(client, itineraryId, segmentId, params),
|
|
200
|
+
createItinerary: (params) => createItinerary(client, params),
|
|
201
|
+
createSegment: (itineraryId, params) => createSegment(client, itineraryId, params),
|
|
202
|
+
createSegmentGroup: (itineraryId, params) => createSegmentGroup(client, itineraryId, params),
|
|
203
|
+
createWaypoint: (itineraryId, params) => createWaypoint(client, itineraryId, params),
|
|
204
|
+
deleteItinerary: (itineraryId) => deleteItinerary(client, itineraryId),
|
|
205
|
+
deleteSegment: (itineraryId, segmentId) => deleteSegment(client, itineraryId, segmentId),
|
|
206
|
+
deleteSegmentGroup: (itineraryId, groupId) => deleteSegmentGroup(client, itineraryId, groupId),
|
|
207
|
+
deleteWaypoint: (itineraryId, waypointId) => deleteWaypoint(client, itineraryId, waypointId),
|
|
208
|
+
disableItineraryShareLink: (itineraryId) => disableItineraryShareLink(client, itineraryId),
|
|
209
|
+
duplicateItinerary: (itineraryId, params) => duplicateItinerary(client, itineraryId, params),
|
|
210
|
+
fetchItineraryRecord: (itineraryId, surface) =>
|
|
211
|
+
fetchItineraryRecord(client, itineraryId, surface),
|
|
212
|
+
fetchItineraryShareLink: (itineraryId) => fetchItineraryShareLink(client, itineraryId),
|
|
213
|
+
mergeSegment: (itineraryId, segmentId) => mergeSegment(client, itineraryId, segmentId),
|
|
214
|
+
mintItineraryShareLink: (itineraryId) => mintItineraryShareLink(client, itineraryId),
|
|
215
|
+
publishItinerary: (itineraryId) => publishItinerary(client, itineraryId),
|
|
216
|
+
rotateItineraryShareLink: (itineraryId) => rotateItineraryShareLink(client, itineraryId),
|
|
217
|
+
splitSegment: (itineraryId, segmentId, params) =>
|
|
218
|
+
splitSegment(client, itineraryId, segmentId, params),
|
|
219
|
+
unpublishItinerary: (itineraryId) => unpublishItinerary(client, itineraryId),
|
|
220
|
+
updateItinerary: (itineraryId, params) => updateItinerary(client, itineraryId, params),
|
|
221
|
+
updateSegment: (itineraryId, segmentId, params) =>
|
|
222
|
+
updateSegment(client, itineraryId, segmentId, params),
|
|
223
|
+
updateSegmentGroup: (itineraryId, groupId, params) =>
|
|
224
|
+
updateSegmentGroup(client, itineraryId, groupId, params),
|
|
225
|
+
updateWaypoint: (itineraryId, waypointId, params) =>
|
|
226
|
+
updateWaypoint(client, itineraryId, waypointId, params),
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The `name` every {@link StudioPersistenceRefusedError} carries, so a log line says which
|
|
231
|
+
* refusal it is.
|
|
232
|
+
*/
|
|
233
|
+
const PERSISTENCE_REFUSED_NAME = "StudioPersistenceRefusedError";
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* StudioPersistenceRefusedError is a verb a local session cannot answer, said out loud.
|
|
237
|
+
*
|
|
238
|
+
* Thrown rather than returned, because that is how the layer above already works: `writeThrough`
|
|
239
|
+
* rolls its optimistic patch back and re-throws anything it does not recognize, and the bus's
|
|
240
|
+
* dispatch boundary classifies the throw into the failing `ToolResult` a surface renders. A
|
|
241
|
+
* silent no-op would instead report success and change nothing, which is the one outcome a reader
|
|
242
|
+
* cannot tell from a bug.
|
|
243
|
+
*
|
|
244
|
+
* The refusals are a decision, not a gap: publishing, sharing and duplicating are the verbs whose
|
|
245
|
+
* whole meaning is an organization's real catalogue, and merge, split, a conversion and the
|
|
246
|
+
* segment groups re-route neighbours server-side against terrain a local seam has never read.
|
|
247
|
+
* Saying so is the same posture {@link createStaticViewer} takes.
|
|
248
|
+
*/
|
|
249
|
+
export class StudioPersistenceRefusedError extends MountayaElementsError {
|
|
250
|
+
override readonly name: string = PERSISTENCE_REFUSED_NAME;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** refusedError names the verb in the sentence a surface will render. */
|
|
254
|
+
const refusedError = (verb: string) =>
|
|
255
|
+
new StudioPersistenceRefusedError(`${verb} is not available in a local studio session`);
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* LocalPersistenceOptions seed a session and name the drawer it is kept in.
|
|
259
|
+
*
|
|
260
|
+
* `seed` is the fixture the session opens on, which is what makes a demo a demo rather than an
|
|
261
|
+
* empty editor: a host hands over the records it wants read back, and every write lands on a copy
|
|
262
|
+
* of them. `namespace` separates one session's drawer from another's under the same origin.
|
|
263
|
+
*
|
|
264
|
+
* `clock` and `ids` are the two determinism seams every rule in this package takes rather than
|
|
265
|
+
* reaching for the platform: a studio rendered into a video frame twice must mint the same ids and
|
|
266
|
+
* stamp the same instants twice. One left out is answered as an absent seam is everywhere in the
|
|
267
|
+
* package: by the system clock and by the platform's UUID.
|
|
268
|
+
*/
|
|
269
|
+
export interface LocalPersistenceOptions {
|
|
270
|
+
/**
|
|
271
|
+
* Where the instant a write is stamped with comes from: a new record's `created_at` and the
|
|
272
|
+
* itinerary's `updated_at`. A write under a clock that reads no instant rejects.
|
|
273
|
+
*
|
|
274
|
+
* @default The system clock.
|
|
275
|
+
*/
|
|
276
|
+
clock?: Clock | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* The default travel speed of an activity, in kilometers per hour, or null for an activity
|
|
279
|
+
* the host holds none for.
|
|
280
|
+
*
|
|
281
|
+
* A segment whose `speed` is null travels at its activity's default, a figure of the activity
|
|
282
|
+
* catalog that no record carries. Supplied, a speed write resolves the speed the segment held
|
|
283
|
+
* and the one it takes through this read, as the API resolves them, so the stored `duration`
|
|
284
|
+
* follows a change to or from the default as it follows a change between two speeds of the
|
|
285
|
+
* segment's own. It is read for a write that carries a `speed`, with the itinerary's activity.
|
|
286
|
+
*
|
|
287
|
+
* A host wires it from the catalog it already holds, as it wires `route` from its client:
|
|
288
|
+
* `defaultSpeedForActivity` over the capabilities of the activity of that id. An answer that
|
|
289
|
+
* is no positive number, and a read that throws, are read as null.
|
|
290
|
+
*
|
|
291
|
+
* @default No read: a change to or from the activity's default leaves the `duration` the
|
|
292
|
+
* segment holds.
|
|
293
|
+
*/
|
|
294
|
+
defaultSpeed?: ((activityId: Activity["id"]) => number | null) | undefined;
|
|
295
|
+
/**
|
|
296
|
+
* Where the id of a new segment or waypoint comes from, behind the `local-` prefix.
|
|
297
|
+
*
|
|
298
|
+
* @default The platform's UUID.
|
|
299
|
+
*/
|
|
300
|
+
ids?: StudioIds | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* The name of the drawer, which separates one session's document from another's under the
|
|
303
|
+
* same origin. A page showing three tenants' studios names three.
|
|
304
|
+
*
|
|
305
|
+
* @default "studio"
|
|
306
|
+
*/
|
|
307
|
+
namespace?: string | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* How to route a directions segment, for a session that wants its lines drawn.
|
|
310
|
+
*
|
|
311
|
+
* The one thing a local seam genuinely cannot do on its own, and the reason it is a seam of its
|
|
312
|
+
* own rather than something this file reaches for. A directions segment's wire geometry is the
|
|
313
|
+
* VIAS, not a line: the backend routes between them on write and echoes the routed LineString
|
|
314
|
+
* back. Persist what the editor hands over and the segment lands with no line at all: it is in
|
|
315
|
+
* the rail, in the count and nowhere on the map.
|
|
316
|
+
*
|
|
317
|
+
* Supplied, a directions write is routed first and the routed line is stored beside the vias,
|
|
318
|
+
* which is the geometry the wire contract carries and the shape `draftSink` already builds for
|
|
319
|
+
* an import draft. Unsupplied, or failing, the vias are persisted as handed over: a local
|
|
320
|
+
* session does not invent a line it did not measure.
|
|
321
|
+
*
|
|
322
|
+
* A host wires this from the client it already holds: routing is a READ, and the whole point of
|
|
323
|
+
* this seam is that only writes are local. It is not on {@link StudioPersistence} because it is
|
|
324
|
+
* not a verb anything above dispatches; it is how this implementation answers one of them.
|
|
325
|
+
*/
|
|
326
|
+
route?:
|
|
327
|
+
| ((input: { activityId: string; vias: Position[] }) => Promise<LineString | null>)
|
|
328
|
+
| undefined;
|
|
329
|
+
/**
|
|
330
|
+
* The itineraries the session opens on.
|
|
331
|
+
*
|
|
332
|
+
* A record is read from the drawer's document when the session wrote to it and from the seed
|
|
333
|
+
* otherwise, the document winning for an id both hold. So a seed that gains an itinerary, or
|
|
334
|
+
* rewords one nobody edited, reaches a visitor whose browser already holds a document, while
|
|
335
|
+
* an itinerary the visitor changed stays theirs. A new `namespace` starts every visitor from
|
|
336
|
+
* the seed again.
|
|
337
|
+
*
|
|
338
|
+
* @default No itinerary: every read rejects with a `MountayaElementsNotFoundError`.
|
|
339
|
+
*/
|
|
340
|
+
seed?: ReadonlyArray<ItineraryWithDetails> | undefined;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The drawer a host that named none writes to. */
|
|
344
|
+
const DEFAULT_NAMESPACE = "studio";
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* instantOf reads the clock as a `Date`, and refuses a reading that is no instant.
|
|
348
|
+
*
|
|
349
|
+
* A clock built on a start it could not parse reads `NaN`. A record stamped with it would hold
|
|
350
|
+
* an Invalid Date, which the drawer stores as `null` and the first formatter downstream throws
|
|
351
|
+
* on, far from the clock that caused it. So the reading is refused here, where the seam builds
|
|
352
|
+
* the date.
|
|
353
|
+
*
|
|
354
|
+
* @throws {MountayaElementsError} When `clock.now()` answers no instant: `NaN`, an infinite
|
|
355
|
+
* number, or one past the range a `Date` holds.
|
|
356
|
+
*/
|
|
357
|
+
const instantOf = (clock: Clock): Date => {
|
|
358
|
+
const reading = clock.now();
|
|
359
|
+
const instant = new Date(reading);
|
|
360
|
+
if (Number.isNaN(instant.getTime())) {
|
|
361
|
+
throw new MountayaElementsError(
|
|
362
|
+
`local studio session: the clock seam reads no instant (${String(reading)}), so the write ` +
|
|
363
|
+
"has no time to carry. Hand the session a clock whose now() answers epoch milliseconds.",
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return instant;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* withLocalMetrics fills in the numbers the backend computes, for the ones that can be computed
|
|
372
|
+
* from the geometry alone.
|
|
373
|
+
*
|
|
374
|
+
* Distance and the four elevation readings, and no more. `gradient_*`, `speed_info` and the five
|
|
375
|
+
* analysis bands are terrain reads: the server samples a DEM along the line to produce them, and
|
|
376
|
+
* a client that invented them would be publishing a number with nothing behind it. They stay
|
|
377
|
+
* null, which is the wire's own spelling for "not computed" and what every reader downstream
|
|
378
|
+
* already renders as a blank.
|
|
379
|
+
*
|
|
380
|
+
* The elevation four are computed only when the geometry carries a z, which a routed line does
|
|
381
|
+
* and a freehand line drawn on a 2D basemap does not. Same rule: measured or absent.
|
|
382
|
+
*
|
|
383
|
+
* Every line the geometry holds is measured, the lines of a `MultiLineString` included
|
|
384
|
+
* ({@link extractLines}), and each by itself: the gap between the end of one line and the start
|
|
385
|
+
* of the next is no distance travelled and no climb. The distance of a line is the great-circle
|
|
386
|
+
* length the segment rail reads ({@link segmentLengthMeters}), and it is null when no line holds
|
|
387
|
+
* two positions.
|
|
388
|
+
*/
|
|
389
|
+
const withLocalMetrics = (segment: ItinerarySegment): ItinerarySegment => {
|
|
390
|
+
// Folded in one pass and never spread into Math.min and Math.max: a recorded track holds more
|
|
391
|
+
// readings than a call takes arguments, and a spread past that throws a RangeError.
|
|
392
|
+
let ascent = 0;
|
|
393
|
+
let descent = 0;
|
|
394
|
+
let lowest = Number.POSITIVE_INFINITY;
|
|
395
|
+
let highest = Number.NEGATIVE_INFINITY;
|
|
396
|
+
let readings = 0;
|
|
397
|
+
let distance: number | null = null;
|
|
398
|
+
|
|
399
|
+
for (const line of extractLines(segment.geojson)) {
|
|
400
|
+
if (line.coordinates.length > 1) {
|
|
401
|
+
distance = (distance ?? 0) + segmentLengthMeters(line);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
let previous: number | null = null;
|
|
405
|
+
for (const position of line.coordinates) {
|
|
406
|
+
const elevation = position[2];
|
|
407
|
+
if (typeof elevation !== "number") continue;
|
|
408
|
+
|
|
409
|
+
if (previous !== null) {
|
|
410
|
+
const step = elevation - previous;
|
|
411
|
+
if (step > 0) ascent += step;
|
|
412
|
+
else descent -= step;
|
|
413
|
+
}
|
|
414
|
+
lowest = Math.min(lowest, elevation);
|
|
415
|
+
highest = Math.max(highest, elevation);
|
|
416
|
+
previous = elevation;
|
|
417
|
+
readings += 1;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const has3d = readings > 1;
|
|
422
|
+
|
|
423
|
+
return withSegmentAnalysis({
|
|
424
|
+
...segment,
|
|
425
|
+
altitude_max: has3d ? highest : null,
|
|
426
|
+
altitude_min: has3d ? lowest : null,
|
|
427
|
+
ascent: has3d ? ascent : null,
|
|
428
|
+
descent: has3d ? descent : null,
|
|
429
|
+
distance,
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* routedGeometry folds a routed line in beside the vias, or hands the geometry back untouched.
|
|
435
|
+
*
|
|
436
|
+
* Only for a directions write that arrived as vias alone, which is what the wire contract sends:
|
|
437
|
+
* a geometry that already carries a line ({@link extractLines}, so a `MultiLineString` counts) has
|
|
438
|
+
* been routed by whoever built it, and a linestring-mode segment IS its line. The result is the
|
|
439
|
+
* single-level GeometryCollection the contract uses (the routed LineString and a MultiPoint of
|
|
440
|
+
* the committed vias), which is the shape `draftSink` builds for the same case and the shape the
|
|
441
|
+
* backend echoes.
|
|
442
|
+
*
|
|
443
|
+
* Best effort in both directions: no router, no vias, or a router that refuses, and the geometry
|
|
444
|
+
* is persisted exactly as it came. The segment then has no line, which is the truth about it.
|
|
445
|
+
*/
|
|
446
|
+
const routedGeometry = async (
|
|
447
|
+
geojson: Geometry | null | undefined,
|
|
448
|
+
mode: string,
|
|
449
|
+
activityId: string,
|
|
450
|
+
route: LocalPersistenceOptions["route"],
|
|
451
|
+
): Promise<Geometry | null | undefined> => {
|
|
452
|
+
if (!route || mode !== "directions" || !geojson) return geojson;
|
|
453
|
+
if (extractLines(geojson).length > 0) return geojson;
|
|
454
|
+
|
|
455
|
+
const vias = extractVias(geojson);
|
|
456
|
+
if (vias.length < 2) return geojson;
|
|
457
|
+
|
|
458
|
+
try {
|
|
459
|
+
const line = await route({ activityId, vias: vias.map((via) => [...via]) });
|
|
460
|
+
|
|
461
|
+
return line
|
|
462
|
+
? buildGeometryCollection([line, { coordinates: vias, type: "MultiPoint" }])
|
|
463
|
+
: geojson;
|
|
464
|
+
} catch {
|
|
465
|
+
// A routing failure is not a reason to refuse the write: the reader drew something and it is
|
|
466
|
+
// theirs, line or no line.
|
|
467
|
+
return geojson;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
/** sum adds the present values and answers null when every one of them was absent. */
|
|
472
|
+
const sum = (values: ReadonlyArray<number | null>): number | null => {
|
|
473
|
+
const present = values.filter((value): value is number => value !== null);
|
|
474
|
+
|
|
475
|
+
return present.length ? present.reduce((total, value) => total + value, 0) : null;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* withRollUp re-derives the itinerary's own totals from its segments and re-numbers the chain.
|
|
480
|
+
*
|
|
481
|
+
* The backend does this on every write and every reader above treats the itinerary's `distance`,
|
|
482
|
+
* `ascent` and `count` as authoritative, so a local seam that only appended a segment would leave
|
|
483
|
+
* the rail's header disagreeing with the rail's rows. `position` is the array order, which is the
|
|
484
|
+
* one thing a local session can say with certainty about a chain it holds entirely.
|
|
485
|
+
*/
|
|
486
|
+
const withRollUp = (itinerary: ItineraryWithDetails): ItineraryWithDetails => {
|
|
487
|
+
const segments = itinerary.segments.map((segment, index) => ({ ...segment, position: index }));
|
|
488
|
+
|
|
489
|
+
return withItineraryAnalysis({
|
|
490
|
+
...itinerary,
|
|
491
|
+
ascent: sum(segments.map((segment) => segment.ascent)),
|
|
492
|
+
count: {
|
|
493
|
+
...itinerary.count,
|
|
494
|
+
groups: itinerary.groups.length,
|
|
495
|
+
segments: segments.length,
|
|
496
|
+
waypoints: itinerary.waypoints.length,
|
|
497
|
+
},
|
|
498
|
+
distance: sum(segments.map((segment) => segment.distance)),
|
|
499
|
+
segments,
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* clearedText reads a description as the API does: absent keeps what is held, and `null` or a
|
|
505
|
+
* value that trims to nothing clears it.
|
|
506
|
+
*/
|
|
507
|
+
const clearedText = (sent: string | null | undefined, held: string | null): string | null => {
|
|
508
|
+
if (sent === undefined) return held;
|
|
509
|
+
|
|
510
|
+
return sent === null || sent.trim() === "" ? null : sent;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* segmentOf answers one segment of a record.
|
|
515
|
+
*
|
|
516
|
+
* @throws {MountayaElementsNotFoundError} When the record holds no segment of that id, which is
|
|
517
|
+
* what the API answers an update or a delete of one.
|
|
518
|
+
*/
|
|
519
|
+
const segmentOf = (record: ItineraryWithDetails, segmentId: string): ItinerarySegment => {
|
|
520
|
+
const segment = record.segments.find((candidate) => candidate.id === segmentId);
|
|
521
|
+
if (!segment) {
|
|
522
|
+
throw new MountayaElementsNotFoundError(`local studio session holds no segment ${segmentId}`);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return segment;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
/** waypointOf is {@link segmentOf}'s twin, with the same miss. */
|
|
529
|
+
const waypointOf = (record: ItineraryWithDetails, waypointId: string): ItineraryWaypoint => {
|
|
530
|
+
const waypoint = record.waypoints.find((candidate) => candidate.id === waypointId);
|
|
531
|
+
if (!waypoint) {
|
|
532
|
+
throw new MountayaElementsNotFoundError(`local studio session holds no waypoint ${waypointId}`);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return waypoint;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* activityDefaultSpeed reads an activity's default speed through the host's read, in kilometers
|
|
540
|
+
* per hour.
|
|
541
|
+
*
|
|
542
|
+
* Null where the session was given no read, where the read answers none or no positive number,
|
|
543
|
+
* and where it throws: a catalog read that fails is no reason to refuse the write it serves.
|
|
544
|
+
*/
|
|
545
|
+
const activityDefaultSpeed = (
|
|
546
|
+
read: LocalPersistenceOptions["defaultSpeed"],
|
|
547
|
+
activityId: Activity["id"],
|
|
548
|
+
): number | null => {
|
|
549
|
+
if (!read) return null;
|
|
550
|
+
|
|
551
|
+
try {
|
|
552
|
+
const speed = read(activityId);
|
|
553
|
+
|
|
554
|
+
return typeof speed === "number" && Number.isFinite(speed) && speed > 0 ? speed : null;
|
|
555
|
+
} catch {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* rescaledDuration answers a segment's duration under a new speed.
|
|
562
|
+
*
|
|
563
|
+
* A duration over a fixed line is in inverse proportion to the speed ({@link durationForSpeed}).
|
|
564
|
+
* Each of the two speeds is resolved as the API resolves it ({@link resolveSpeedKmh}): the
|
|
565
|
+
* segment's own where it is set, and the activity's default otherwise. So with a default to
|
|
566
|
+
* read, a change to or from it rescales as a change between two speeds of the segment's own
|
|
567
|
+
* does. Where either speed resolves to nothing, a null speed with no default read, the duration
|
|
568
|
+
* is left as it is held: a figure derived from a speed nobody read would be invented. A segment
|
|
569
|
+
* that holds a distance and no duration takes the distance over the new speed, the figure the
|
|
570
|
+
* editor's own patch shows.
|
|
571
|
+
*
|
|
572
|
+
* @param segment The segment as it is held, with the speed and the duration it has.
|
|
573
|
+
* @param speed The speed the write sets, in kilometers per hour, or null for the default.
|
|
574
|
+
* @param activityDefault The default speed of the itinerary's activity, or null where none
|
|
575
|
+
* was read.
|
|
576
|
+
*/
|
|
577
|
+
const rescaledDuration = (
|
|
578
|
+
segment: ItinerarySegment,
|
|
579
|
+
speed: number | null,
|
|
580
|
+
activityDefault: number | null,
|
|
581
|
+
): number | null => {
|
|
582
|
+
const held = resolveSpeedKmh(segment.speed, activityDefault);
|
|
583
|
+
const next = resolveSpeedKmh(speed, activityDefault);
|
|
584
|
+
if (held === null || next === null) {
|
|
585
|
+
return segment.duration;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return (
|
|
589
|
+
durationForSpeed({
|
|
590
|
+
baseDurationSeconds: segment.duration,
|
|
591
|
+
baseSpeedKmh: held,
|
|
592
|
+
distanceMeters: segment.distance,
|
|
593
|
+
targetSpeedKmh: next,
|
|
594
|
+
}) ?? segment.duration
|
|
595
|
+
);
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* updatedSegment projects an update over a segment, three-state member by member as the wire
|
|
600
|
+
* reads them: absent keeps, `null` clears where the contract allows a clear.
|
|
601
|
+
*
|
|
602
|
+
* The metrics are measured again only when the update carries a geometry
|
|
603
|
+
* ({@link withLocalMetrics}). A rename, a recolor or a new start leaves the numbers the segment
|
|
604
|
+
* holds, which for a seeded segment are the server's: a second measure of a line with no z would
|
|
605
|
+
* replace an ascent somebody computed with none. A new speed rescales the duration
|
|
606
|
+
* ({@link rescaledDuration}), over `activityDefault` for a speed that is the activity's default.
|
|
607
|
+
*/
|
|
608
|
+
const updatedSegment = (
|
|
609
|
+
segment: ItinerarySegment,
|
|
610
|
+
params: SegmentUpdateParams,
|
|
611
|
+
geojson: Geometry | null | undefined,
|
|
612
|
+
activityDefault: number | null,
|
|
613
|
+
): ItinerarySegment => {
|
|
614
|
+
const next: ItinerarySegment = {
|
|
615
|
+
...segment,
|
|
616
|
+
color: params.color === undefined ? segment.color : params.color,
|
|
617
|
+
description: clearedText(params.description, segment.description),
|
|
618
|
+
duration:
|
|
619
|
+
params.speed === undefined
|
|
620
|
+
? segment.duration
|
|
621
|
+
: rescaledDuration(segment, params.speed, activityDefault),
|
|
622
|
+
geojson: geojson ?? segment.geojson,
|
|
623
|
+
name: params.name ?? segment.name,
|
|
624
|
+
revision: segment.revision + 1,
|
|
625
|
+
speed: params.speed === undefined ? segment.speed : params.speed,
|
|
626
|
+
start_at: params.start_at === undefined ? segment.start_at : params.start_at,
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
return geojson ? withLocalMetrics(next) : next;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* updatedWaypoint projects an update over a waypoint, three-state member by member as the wire
|
|
634
|
+
* reads them. `amenities` clears to an empty list on `null`, and `geojson`, `icon` and
|
|
635
|
+
* `position` have no clear: absent keeps them.
|
|
636
|
+
*/
|
|
637
|
+
const updatedWaypoint = (
|
|
638
|
+
waypoint: ItineraryWaypoint,
|
|
639
|
+
params: WaypointUpdateParams,
|
|
640
|
+
): ItineraryWaypoint => ({
|
|
641
|
+
...waypoint,
|
|
642
|
+
amenities: params.amenities === undefined ? waypoint.amenities : (params.amenities ?? []),
|
|
643
|
+
color: params.color === undefined ? waypoint.color : params.color,
|
|
644
|
+
contact: params.contact === undefined ? waypoint.contact : params.contact,
|
|
645
|
+
description: clearedText(params.description, waypoint.description),
|
|
646
|
+
geojson: params.geojson ?? waypoint.geojson,
|
|
647
|
+
icon: params.icon ?? waypoint.icon,
|
|
648
|
+
media: params.media === undefined ? waypoint.media : params.media,
|
|
649
|
+
name: params.name === undefined ? waypoint.name : params.name,
|
|
650
|
+
position: params.position ?? waypoint.position,
|
|
651
|
+
properties: params.properties === undefined ? waypoint.properties : params.properties,
|
|
652
|
+
revision: waypoint.revision + 1,
|
|
653
|
+
timing: params.timing === undefined ? waypoint.timing : params.timing,
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* LocalRecords is a local session's records over its drawer: what every verb reads, and the one
|
|
658
|
+
* way a verb saves.
|
|
659
|
+
*/
|
|
660
|
+
interface LocalRecords {
|
|
661
|
+
/**
|
|
662
|
+
* Applies `change` to one record, stamps it `updated_at` with the instant `change` is handed,
|
|
663
|
+
* rolls its totals up, saves it and answers the saved copy. Nothing is saved when the clock
|
|
664
|
+
* reads no instant or `change` throws.
|
|
665
|
+
*/
|
|
666
|
+
readonly commit: (
|
|
667
|
+
itineraryId: string,
|
|
668
|
+
change: (record: ItineraryWithDetails, stamp: Date) => ItineraryWithDetails,
|
|
669
|
+
) => ItineraryWithDetails;
|
|
670
|
+
/**
|
|
671
|
+
* The record of that id.
|
|
672
|
+
*
|
|
673
|
+
* @throws {MountayaElementsNotFoundError} When neither the document nor the seed holds it.
|
|
674
|
+
*/
|
|
675
|
+
readonly recordOf: (itineraryId: string) => ItineraryWithDetails;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* sameRecord reports whether the drawer answered the record it was just handed.
|
|
680
|
+
*
|
|
681
|
+
* The memory drawer hands back the object it was given. The local one hands back a parse of what
|
|
682
|
+
* the storage kept, so the two are compared as the documents they serialize to: an instant is its
|
|
683
|
+
* ISO form on both sides, as the drawer writes it.
|
|
684
|
+
*/
|
|
685
|
+
const sameRecord = (kept: ItineraryWithDetails | undefined, written: ItineraryWithDetails) =>
|
|
686
|
+
kept === written || (kept !== undefined && JSON.stringify(kept) === JSON.stringify(written));
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* createLocalRecords reads and saves a session's records over a drawer and a seed.
|
|
690
|
+
*
|
|
691
|
+
* **The document holds what the session wrote, and the seed answers the rest.** A record is read
|
|
692
|
+
* from the document when it holds one of that id and from the seed otherwise, so a seed that
|
|
693
|
+
* gains an itinerary reaches a visitor whose browser already holds a document, and a seeded
|
|
694
|
+
* itinerary nobody wrote to is read as the seed states it today. A read writes nothing.
|
|
695
|
+
*
|
|
696
|
+
* **The drawer is read on every call and never cached,** which is what makes two mounts sharing
|
|
697
|
+
* a namespace agree, and what makes a reload pick up where the reader left off.
|
|
698
|
+
*
|
|
699
|
+
* **A write the drawer did not keep is kept here.** A drawer over a storage that is absent,
|
|
700
|
+
* blocked or full takes a write and holds something else afterwards. Each save is read back, and
|
|
701
|
+
* while the drawer does not answer what it was handed, the session reads the document it last
|
|
702
|
+
* wrote: a write that answered as done is in the next read, for the life of the object. The first
|
|
703
|
+
* save the drawer keeps hands the reads back to it.
|
|
704
|
+
*/
|
|
705
|
+
const createLocalRecords = (
|
|
706
|
+
drawer: StudioPersistenceDrawer,
|
|
707
|
+
clock: Clock,
|
|
708
|
+
seed: ReadonlyArray<ItineraryWithDetails>,
|
|
709
|
+
): LocalRecords => {
|
|
710
|
+
let seeded: Record<string, ItineraryWithDetails> | null = null;
|
|
711
|
+
let unkept: Record<string, ItineraryWithDetails> | null = null;
|
|
712
|
+
|
|
713
|
+
const seedRecords = (): Record<string, ItineraryWithDetails> => {
|
|
714
|
+
seeded ??= Object.fromEntries(
|
|
715
|
+
seed.map((itinerary) => [itinerary.id, withRollUp(itinerary)] as const),
|
|
716
|
+
);
|
|
717
|
+
|
|
718
|
+
return seeded;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
const written = (): Record<string, ItineraryWithDetails> => unkept ?? drawer.read() ?? {};
|
|
722
|
+
|
|
723
|
+
/** The record of that id in a document, or the seed's, or a thrown miss. */
|
|
724
|
+
const recordIn = (
|
|
725
|
+
document: Record<string, ItineraryWithDetails>,
|
|
726
|
+
itineraryId: string,
|
|
727
|
+
): ItineraryWithDetails => {
|
|
728
|
+
const record = document[itineraryId] ?? seedRecords()[itineraryId];
|
|
729
|
+
if (!record) {
|
|
730
|
+
throw new MountayaElementsNotFoundError(
|
|
731
|
+
`local studio session holds no itinerary ${itineraryId}`,
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
return record;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
return {
|
|
739
|
+
commit: (itineraryId, change) => {
|
|
740
|
+
// One read serves the record and the document it is saved into.
|
|
741
|
+
const held = written();
|
|
742
|
+
const current = recordIn(held, itineraryId);
|
|
743
|
+
const stamp = instantOf(clock);
|
|
744
|
+
const next = withRollUp({ ...change(current, stamp), updated_at: stamp });
|
|
745
|
+
const document = { ...held, [next.id]: next };
|
|
746
|
+
|
|
747
|
+
drawer.write(document);
|
|
748
|
+
unkept = sameRecord(drawer.read()?.[next.id], next) ? null : document;
|
|
749
|
+
|
|
750
|
+
return next;
|
|
751
|
+
},
|
|
752
|
+
recordOf: (itineraryId) => recordIn(written(), itineraryId),
|
|
753
|
+
};
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* createLocalPersistence is both null objects: the arithmetic, over a drawer.
|
|
758
|
+
*
|
|
759
|
+
* Every verb it implements is the one the editor dispatches while a reader is drawing:
|
|
760
|
+
* segment create, update and delete, waypoint create, update and delete, and the itinerary's own
|
|
761
|
+
* rename. Every other verb refuses out loud; see {@link StudioPersistenceRefusedError}. The rules
|
|
762
|
+
* a verb shares with the API are stated once, on {@link localStudioPersistence}, and where the
|
|
763
|
+
* records are read and saved on {@link createLocalRecords}.
|
|
764
|
+
*/
|
|
765
|
+
const createLocalPersistence = (
|
|
766
|
+
drawer: StudioPersistenceDrawer,
|
|
767
|
+
options: LocalPersistenceOptions,
|
|
768
|
+
): StudioPersistence => {
|
|
769
|
+
// A seam the options leave out is answered by the absence the seams module states, for this
|
|
770
|
+
// session as for every handler: this module chooses no implementation of its own.
|
|
771
|
+
const { clock = studioSeamAbsences.clock, ids = studioSeamAbsences.ids } = options;
|
|
772
|
+
const { defaultSpeed, route, seed = [] } = options;
|
|
773
|
+
const records = createLocalRecords(drawer, clock, seed);
|
|
774
|
+
const refuse = (verb: string) => Promise.reject(refusedError(verb));
|
|
775
|
+
|
|
776
|
+
return {
|
|
777
|
+
tiled: false,
|
|
778
|
+
convertSegment: () => refuse("Changing a segment's authoring mode"),
|
|
779
|
+
createItinerary: () => refuse("Creating an itinerary"),
|
|
780
|
+
createSegment: async (itineraryId, params) => {
|
|
781
|
+
const { activity_id: activityId } = records.recordOf(itineraryId);
|
|
782
|
+
const geojson = await routedGeometry(params.geojson, params.mode, activityId, route);
|
|
783
|
+
const id = localId(ids);
|
|
784
|
+
const saved = records.commit(itineraryId, (current, stamp) => {
|
|
785
|
+
const segment = withLocalMetrics({
|
|
786
|
+
...blankSegment(current, stamp, id),
|
|
787
|
+
color: params.color ?? null,
|
|
788
|
+
description: params.description ?? null,
|
|
789
|
+
geojson: geojson ?? null,
|
|
790
|
+
mode: params.mode,
|
|
791
|
+
name: params.name,
|
|
792
|
+
speed: params.speed ?? null,
|
|
793
|
+
start_at: params.start_at ?? null,
|
|
794
|
+
});
|
|
795
|
+
// Ahead of the segment `before_segment_id` names, or at the tail without one. A segment
|
|
796
|
+
// the itinerary does not hold is the miss the API answers, and writes nothing.
|
|
797
|
+
const before = params.before_segment_id;
|
|
798
|
+
const at =
|
|
799
|
+
before === undefined
|
|
800
|
+
? current.segments.length
|
|
801
|
+
: current.segments.indexOf(segmentOf(current, before));
|
|
802
|
+
|
|
803
|
+
return {
|
|
804
|
+
...current,
|
|
805
|
+
segments: [...current.segments.slice(0, at), segment, ...current.segments.slice(at)],
|
|
806
|
+
};
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
// The saved copy, whose `position` is the one the roll-up settled on.
|
|
810
|
+
return segmentOf(saved, id);
|
|
811
|
+
},
|
|
812
|
+
createSegmentGroup: () => refuse("Creating a segment group"),
|
|
813
|
+
createWaypoint: async (itineraryId, params) => {
|
|
814
|
+
const id = localId(ids);
|
|
815
|
+
const saved = records.commit(itineraryId, (current, stamp) => ({
|
|
816
|
+
...current,
|
|
817
|
+
waypoints: [
|
|
818
|
+
...current.waypoints,
|
|
819
|
+
{
|
|
820
|
+
...blankWaypoint(current, stamp, id),
|
|
821
|
+
amenities: params.amenities ?? [],
|
|
822
|
+
color: params.color ?? null,
|
|
823
|
+
contact: params.contact ?? null,
|
|
824
|
+
description: params.description ?? null,
|
|
825
|
+
geojson: params.geojson ?? null,
|
|
826
|
+
icon: params.icon ?? null,
|
|
827
|
+
media: params.media ?? null,
|
|
828
|
+
mode: params.mode,
|
|
829
|
+
name: params.name ?? null,
|
|
830
|
+
position: params.position,
|
|
831
|
+
properties: params.properties ?? null,
|
|
832
|
+
timing: params.timing ?? null,
|
|
833
|
+
},
|
|
834
|
+
],
|
|
835
|
+
}));
|
|
836
|
+
|
|
837
|
+
return waypointOf(saved, id);
|
|
838
|
+
},
|
|
839
|
+
deleteItinerary: () => refuse("Deleting an itinerary"),
|
|
840
|
+
deleteSegment: async (itineraryId, segmentId) => {
|
|
841
|
+
records.commit(itineraryId, (current) => {
|
|
842
|
+
// The chain shrinks from its ends only, the rule the API enforces on the same verb.
|
|
843
|
+
const index = current.segments.indexOf(segmentOf(current, segmentId));
|
|
844
|
+
if (index > 0 && index < current.segments.length - 1) {
|
|
845
|
+
throw new SegmentDeleteNotEdgeError(
|
|
846
|
+
`local studio session: segment ${segmentId} is neither the first nor the last of ` +
|
|
847
|
+
"the chain, and a chain shrinks from its ends only",
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
return {
|
|
852
|
+
...current,
|
|
853
|
+
segments: current.segments.filter((segment) => segment.id !== segmentId),
|
|
854
|
+
};
|
|
855
|
+
});
|
|
856
|
+
},
|
|
857
|
+
deleteSegmentGroup: () => refuse("Deleting a segment group"),
|
|
858
|
+
deleteWaypoint: async (itineraryId, waypointId) => {
|
|
859
|
+
records.commit(itineraryId, (current) => {
|
|
860
|
+
const removed = waypointOf(current, waypointId);
|
|
861
|
+
|
|
862
|
+
return {
|
|
863
|
+
...current,
|
|
864
|
+
waypoints: current.waypoints.filter((waypoint) => waypoint !== removed),
|
|
865
|
+
};
|
|
866
|
+
});
|
|
867
|
+
},
|
|
868
|
+
disableItineraryShareLink: () => refuse("Disabling a share link"),
|
|
869
|
+
duplicateItinerary: () => refuse("Duplicating an itinerary"),
|
|
870
|
+
fetchItineraryRecord: async (itineraryId) => records.recordOf(itineraryId),
|
|
871
|
+
fetchItineraryShareLink: () => refuse("Reading a share link"),
|
|
872
|
+
mergeSegment: () => refuse("Merging two segments"),
|
|
873
|
+
mintItineraryShareLink: () => refuse("Minting a share link"),
|
|
874
|
+
publishItinerary: () => refuse("Publishing an itinerary"),
|
|
875
|
+
rotateItineraryShareLink: () => refuse("Rotating a share link"),
|
|
876
|
+
splitSegment: () => refuse("Splitting a segment"),
|
|
877
|
+
unpublishItinerary: () => refuse("Unpublishing an itinerary"),
|
|
878
|
+
updateItinerary: async (itineraryId, params) =>
|
|
879
|
+
records.commit(itineraryId, (current) => ({
|
|
880
|
+
...current,
|
|
881
|
+
description: clearedText(params.description, current.description),
|
|
882
|
+
is_private: params.is_private ?? current.is_private,
|
|
883
|
+
name: params.name ?? current.name,
|
|
884
|
+
revision: current.revision + 1,
|
|
885
|
+
})),
|
|
886
|
+
updateSegment: async (itineraryId, segmentId, params) => {
|
|
887
|
+
const record = records.recordOf(itineraryId);
|
|
888
|
+
const { mode } = segmentOf(record, segmentId);
|
|
889
|
+
const geojson = await routedGeometry(params.geojson, mode, record.activity_id, route);
|
|
890
|
+
const activityDefault =
|
|
891
|
+
params.speed === undefined ? null : activityDefaultSpeed(defaultSpeed, record.activity_id);
|
|
892
|
+
const saved = records.commit(itineraryId, (current) => {
|
|
893
|
+
const held = segmentOf(current, segmentId);
|
|
894
|
+
|
|
895
|
+
return {
|
|
896
|
+
...current,
|
|
897
|
+
segments: current.segments.map((segment) =>
|
|
898
|
+
segment === held ? updatedSegment(segment, params, geojson, activityDefault) : segment,
|
|
899
|
+
),
|
|
900
|
+
};
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
return segmentOf(saved, segmentId);
|
|
904
|
+
},
|
|
905
|
+
updateSegmentGroup: () => refuse("Updating a segment group"),
|
|
906
|
+
updateWaypoint: async (itineraryId, waypointId, params) => {
|
|
907
|
+
const saved = records.commit(itineraryId, (current) => {
|
|
908
|
+
const held = waypointOf(current, waypointId);
|
|
909
|
+
|
|
910
|
+
return {
|
|
911
|
+
...current,
|
|
912
|
+
waypoints: current.waypoints.map((waypoint) =>
|
|
913
|
+
waypoint === held ? updatedWaypoint(waypoint, params) : waypoint,
|
|
914
|
+
),
|
|
915
|
+
};
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
return waypointOf(saved, waypointId);
|
|
919
|
+
},
|
|
920
|
+
};
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* localStudioPersistence keeps a session's writes in `localStorage`, namespaced, and never throws
|
|
925
|
+
* on the storage itself.
|
|
926
|
+
*
|
|
927
|
+
* What it is FOR: a demo whose editor has to work, a docs example a reader can draw in, and a
|
|
928
|
+
* sandbox a platform offers inside its own Embedded Studio. The reads that are not writes still
|
|
929
|
+
* go to the real APIs: search, geocoding, points of interest, directions and tiles are the
|
|
930
|
+
* client's, and this seam has no opinion about them. That split is the whole point: a sandbox
|
|
931
|
+
* should route on real terrain and then keep the result to itself.
|
|
932
|
+
*
|
|
933
|
+
* Its verbs answer as {@link restStudioPersistence}'s do, rule by rule:
|
|
934
|
+
*
|
|
935
|
+
* - A segment created with `before_segment_id` is inserted ahead of that segment, and one created
|
|
936
|
+
* without it is appended; the chain renumbers either way.
|
|
937
|
+
* - Deleting a segment that is neither end of its chain rejects with an error named
|
|
938
|
+
* `SegmentDeleteNotEdgeError` and leaves the chain whole, since a chain only shrinks from an
|
|
939
|
+
* end.
|
|
940
|
+
* - An update or a delete of a segment or a waypoint the itinerary does not hold, and a create
|
|
941
|
+
* ahead of a segment it does not hold, rejects with a `MountayaElementsNotFoundError` and writes
|
|
942
|
+
* nothing.
|
|
943
|
+
* - Every `updateItinerary` raises the itinerary's `revision`, one that changes nothing included.
|
|
944
|
+
* - Every write moves the itinerary's `updated_at` to the clock's instant, a segment's and a
|
|
945
|
+
* waypoint's included.
|
|
946
|
+
* - An update reads each member in the wire's three states: absent keeps what is held, and `null`
|
|
947
|
+
* clears where the contract allows a clear (a description that trims to nothing also clears,
|
|
948
|
+
* and a waypoint's `amenities` clear to an empty list).
|
|
949
|
+
* - A segment is measured when its geometry is written and not otherwise: a rename or a recolor
|
|
950
|
+
* leaves the distance and the elevation readings it holds.
|
|
951
|
+
*
|
|
952
|
+
* A segment's `duration` follows its speed, a change to or from the activity's default (a `null`
|
|
953
|
+
* speed) included, where the session reads that default through `options.defaultSpeed`. One
|
|
954
|
+
* answer differs from the API's: with no such read, a change to or from the default leaves the
|
|
955
|
+
* duration the segment holds.
|
|
956
|
+
*
|
|
957
|
+
* The records the session wrote live in the one document {@link localPersistenceDrawer} keeps
|
|
958
|
+
* under `namespace`, and every other record is read from the `seed`. A stored document in any
|
|
959
|
+
* other shape reads as empty. Where the storage is absent, blocked or full, the session keeps
|
|
960
|
+
* its writes for the life of this object and forgets them on reload.
|
|
961
|
+
*
|
|
962
|
+
* The stated absence: the verbs a local session cannot mean. See
|
|
963
|
+
* {@link StudioPersistenceRefusedError}.
|
|
964
|
+
*
|
|
965
|
+
* Each write rejects with a `MountayaElementsError` when `options.clock` reads no instant, with
|
|
966
|
+
* nothing written.
|
|
967
|
+
*/
|
|
968
|
+
export const localStudioPersistence = (options: LocalPersistenceOptions = {}): StudioPersistence =>
|
|
969
|
+
createLocalPersistence(localPersistenceDrawer(options.namespace ?? DEFAULT_NAMESPACE), options);
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* memoryStudioPersistence keeps a session's writes for the lifetime of the object and no longer.
|
|
973
|
+
*
|
|
974
|
+
* The same distinction {@link memoryStudioStorage} draws against {@link localStudioStorage}: a
|
|
975
|
+
* kiosk, a shared terminal, a server-side render and a test all want an editor whose verbs work
|
|
976
|
+
* and whose writes are gone when the object is. Unlike omitting the seam, it is a decision a
|
|
977
|
+
* reader of the host's code can see.
|
|
978
|
+
*
|
|
979
|
+
* Its verbs answer exactly as {@link localStudioPersistence}'s do, every rule that docblock
|
|
980
|
+
* lists included; only where the records are kept differs.
|
|
981
|
+
*/
|
|
982
|
+
export const memoryStudioPersistence = (options: LocalPersistenceOptions = {}): StudioPersistence =>
|
|
983
|
+
createLocalPersistence(memoryPersistenceDrawer(), options);
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* blankSegment is the fields a new segment inherits from the itinerary it is being added to.
|
|
987
|
+
*
|
|
988
|
+
* Authorship and ownership come from the record rather than being invented: a local session has
|
|
989
|
+
* no user of its own, and the reader drawing in it is, as far as anything rendering is concerned,
|
|
990
|
+
* whoever the seeded itinerary says created it. Every metric opens null and
|
|
991
|
+
* {@link withLocalMetrics} fills in the ones a geometry can answer.
|
|
992
|
+
*/
|
|
993
|
+
const blankSegment = (record: ItineraryWithDetails, stamp: Date, id: string): ItinerarySegment => ({
|
|
994
|
+
altitude_max: null,
|
|
995
|
+
altitude_min: null,
|
|
996
|
+
ascent: null,
|
|
997
|
+
color: null,
|
|
998
|
+
created_at: stamp,
|
|
999
|
+
created_by: record.created_by,
|
|
1000
|
+
descent: null,
|
|
1001
|
+
description: null,
|
|
1002
|
+
distance: null,
|
|
1003
|
+
duration: null,
|
|
1004
|
+
geojson: null,
|
|
1005
|
+
gradient_max: null,
|
|
1006
|
+
gradient_min: null,
|
|
1007
|
+
group_id: null,
|
|
1008
|
+
id,
|
|
1009
|
+
itinerary_id: record.id,
|
|
1010
|
+
mode: "linestring",
|
|
1011
|
+
name: "",
|
|
1012
|
+
position: 0,
|
|
1013
|
+
revision: 1,
|
|
1014
|
+
road_access_info: null,
|
|
1015
|
+
slope_info: [],
|
|
1016
|
+
speed: null,
|
|
1017
|
+
speed_info: null,
|
|
1018
|
+
start_at: null,
|
|
1019
|
+
steps: [],
|
|
1020
|
+
surface_info: [],
|
|
1021
|
+
trail_difficulty_info: [],
|
|
1022
|
+
way_type_info: [],
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
/** blankWaypoint is {@link blankSegment}'s twin, for the other thing a reader drops on the map. */
|
|
1026
|
+
const blankWaypoint = (
|
|
1027
|
+
record: ItineraryWithDetails,
|
|
1028
|
+
stamp: Date,
|
|
1029
|
+
id: string,
|
|
1030
|
+
): ItineraryWaypoint => ({
|
|
1031
|
+
amenities: [],
|
|
1032
|
+
color: null,
|
|
1033
|
+
contact: null,
|
|
1034
|
+
created_at: stamp,
|
|
1035
|
+
created_by: record.created_by,
|
|
1036
|
+
description: null,
|
|
1037
|
+
geojson: null,
|
|
1038
|
+
icon: null,
|
|
1039
|
+
id,
|
|
1040
|
+
itinerary_id: record.id,
|
|
1041
|
+
media: null,
|
|
1042
|
+
mode: "point",
|
|
1043
|
+
name: null,
|
|
1044
|
+
position: 0,
|
|
1045
|
+
properties: null,
|
|
1046
|
+
revision: 1,
|
|
1047
|
+
timing: null,
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* localId mints an id for a record the backend will never see.
|
|
1052
|
+
*
|
|
1053
|
+
* Through {@link StudioIds} rather than the platform, which is the rule every other mint in this
|
|
1054
|
+
* package follows and the reason is determinism: a session replayed with `sequentialStudioIds`
|
|
1055
|
+
* produces the same records twice. The `local-` prefix is the fact worth being able to see in a
|
|
1056
|
+
* bug report: an id carrying it came from a session that wrote nowhere.
|
|
1057
|
+
*/
|
|
1058
|
+
const localId = (ids: StudioIds): string => `local-${ids.next()}`;
|