diff --git a/package-lock.json b/package-lock.json index 57e9d53..76ed765 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "dyomedea-solid", "version": "0.0.0", "hasInstallScript": true, - "license": "MIT", + "license": "GPL-3.0-only", "dependencies": { "@awesome-cordova-plugins/android-full-screen": "^6.3.0", "@awesome-cordova-plugins/geolocation": "^6.3.0", @@ -47,7 +47,7 @@ "@types/memoizee": "^0.4.8", "@types/pouchdb": "^6.4.0", "@types/proj4": "^2.5.2", - "jsdom": ">=21.1.0", + "jsdom": "^21.1.0", "license-checker": "^25.0.1", "license-compatibility-checker": "^0.3.5", "license-report": "^6.3.0", @@ -55,7 +55,7 @@ "typescript": "^4.9.5", "vite": ">=4.1.1", "vite-plugin-solid": "^2.5.0", - "vitest": ">=0.28.4" + "vitest": "^0.28.4" } }, "node_modules/@adobe/css-tools": { diff --git a/package.json b/package.json index 14329ef..cbebb37 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@types/memoizee": "^0.4.8", "@types/pouchdb": "^6.4.0", "@types/proj4": "^2.5.2", - "jsdom": ">=21.1.0", + "jsdom": "^21.1.0", "license-checker": "^25.0.1", "license-compatibility-checker": "^0.3.5", "license-report": "^6.3.0", @@ -27,7 +27,7 @@ "typescript": "^4.9.5", "vite": ">=4.1.1", "vite-plugin-solid": "^2.5.0", - "vitest": ">=0.28.4" + "vitest": "^0.28.4" }, "dependencies": { "@awesome-cordova-plugins/android-full-screen": "^6.3.0", diff --git a/src/db/rte.ts b/src/db/rte.ts index 49284cb..3e16bb8 100644 --- a/src/db/rte.ts +++ b/src/db/rte.ts @@ -56,8 +56,8 @@ const compactRteOrTrkseg = (params: any) => { return { ...row.doc, doc: undefined, _deleted: true }; }); db.bulkDocs(compactedDocs); + console.log({ caller: 'compactRteOrTrkseg', params, compactedDocs }); } - console.log({ caller: 'compactRteOrTrkseg', params, compactedDocs }); }); }; @@ -67,10 +67,14 @@ export const compactRteOrTrksegDebounced = debounceByParam( 3600000 * (1 + Math.random()) ); -const getRteDocs = async (params: any) => { +export const getRteDocs: ({ + id, +}: { + id: string; +}) => Promise<{ docs: any; rte: Rte }> = async (params) => { const { id } = params; const docs = await getFamily(id, { include_docs: true }); - // console.log({ caller: 'getRte', id, docs }); + console.log({ caller: 'getRteDocs', id, docs }); let target: any[]; let rte: Rte | undefined = undefined; docs.rows.every((row: any) => { @@ -112,7 +116,6 @@ export const getRte = async (params: any) => { export const putRte = async (params: any) => { const { id, rte } = params; - rte.rtept = undefined; await put(id, 'rte', (doc) => rte, rte); return rte; }; diff --git a/src/db/rtept.ts b/src/db/rtept.ts index 1e7c26d..3fcfba7 100644 --- a/src/db/rtept.ts +++ b/src/db/rtept.ts @@ -1,3 +1,6 @@ +import { getRteDocs, putRte } from './rte'; +import getUri from '../lib/ids'; +import { put } from './lib'; export const emptyRtept: Wpt = { $: { lat: 0, lon: 0 }, @@ -21,3 +24,22 @@ export const emptyRtept: Wpt = { dgpsid: undefined, extensions: undefined, }; + +export const putRtept = async (params: any) => { + const { idRte, index, rtept } = params; + const { docs, rte } = await getRteDocs({ id: idRte }); + const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0; + const nbRteptOutRte = docs.rows.length - 1; + const nbRtept = nbRteptInRte + nbRteptOutRte; + const positiveIndex = index >= 0 ? index : nbRtept - index; + if (positiveIndex < nbRteptInRte) { + rte.rtept[positiveIndex] = rtept; + await putRte({ id: idRte, rte }); + } else { + let rteptIdObj = getUri('rtept', docs.rows[1].id); + rteptIdObj.rtept = rteptIdObj.rtept + positiveIndex - nbRteptInRte; + const rteptUri = getUri('rtept', rteptIdObj); + await put(rteptUri, 'rtept', () => rtept, emptyRtept); + } + return rte; +}; diff --git a/vite.config.ts b/vite.config.ts index ca1e91f..60d6453 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -42,6 +42,10 @@ export default defineConfig(({ command, mode, ssrBuild }) => ({ // or both out to improve performance: threads: false, isolate: false, + // plugins: [solidPlugin()], + // resolve: { + // conditions: ['development', 'browser'], + // }, }, build: { target: 'esnext',