From 12f0a8a10dc7a7dd6dd9ac7d3523fe0afdc21df3 Mon Sep 17 00:00:00 2001 From: evlist Date: Wed, 9 Nov 2022 10:32:06 +0100 Subject: [PATCH] Using full ISO dates as Gpx ids to support a wider range of dates. --- src/db/gpx.test.ts | 2 +- src/db/gpx.ts | 4 +- src/db/lib.test.ts | 130 +++++++++++++++++++++--------------------- src/db/rte.test.ts | 2 +- src/db/rtept.test.ts | 2 +- src/db/trk.test.ts | 2 +- src/db/trkpt.test.ts | 2 +- src/db/trkseg.test.ts | 2 +- src/db/wpt.test.ts | 2 +- 9 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/db/gpx.test.ts b/src/db/gpx.test.ts index e99afc7..f8eb97f 100644 --- a/src/db/gpx.test.ts +++ b/src/db/gpx.test.ts @@ -57,6 +57,6 @@ describe('The gpx module', () => { }); test('db.put() generates an id if needed', async () => { const id = await putNewGpx(); - expect(id).toEqual({ gpx: '0' }); + expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z' }); }); }); diff --git a/src/db/gpx.ts b/src/db/gpx.ts index 4b1af95..49b49c2 100644 --- a/src/db/gpx.ts +++ b/src/db/gpx.ts @@ -31,7 +31,9 @@ const emptyGpx: Gpx = { extensions: undefined, }; -export const putNewGpx = async (id: IdGpx = { gpx: Date.now().toString() }) => { +export const putNewGpx = async ( + id: IdGpx = { gpx: new Date(Date.now()).toISOString() } +) => { const uri = getUri('gpx', id); await put( uri, diff --git a/src/db/lib.test.ts b/src/db/lib.test.ts index be629ab..efb09f3 100644 --- a/src/db/lib.test.ts +++ b/src/db/lib.test.ts @@ -26,23 +26,23 @@ describe('getFamily', () => { }); test('returns two rows after a gpx and a track have been inserted.', async () => { await putNewTrk(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' })); + const allDocs: any = await getFamily(uri('gpx', { gpx: '' })); expect(allDocs).toMatchInlineSnapshot(` Object { "offset": 0, "rows": Array [ Object { - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { - "id": "gpx/0/2trk/00000", - "key": "gpx/0/2trk/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", "value": Object { - "rev": "1-1e197ef8965a436730f80cabaaaa6f70", + "rev": "1-e1e6888ad978a5fcc405a75296604bee", }, }, ], @@ -52,7 +52,7 @@ Object { }); test('also returns the docs if required.', async () => { await putNewTrk(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }), { + const allDocs: any = await getFamily(uri('gpx', { gpx: '' }), { include_docs: true, }); expect(allDocs).toMatchInlineSnapshot(` @@ -61,8 +61,8 @@ Object { "rows": Array [ Object { "doc": Object { - "_id": "gpx/0", - "_rev": "1-98d42c99fcf471a500b0506a60e77559", + "_id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "_rev": "1-649694b1e46839ec63d2a93f483dd023", "doc": Object { "$": Object { "creator": "dyomedea version 0.000002", @@ -81,25 +81,25 @@ Object { }, "type": "gpx", }, - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { "doc": Object { - "_id": "gpx/0/2trk/00000", - "_rev": "1-1e197ef8965a436730f80cabaaaa6f70", + "_id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", + "_rev": "1-e1e6888ad978a5fcc405a75296604bee", "doc": Object { "number": 0, }, "type": "trk", }, - "id": "gpx/0/2trk/00000", - "key": "gpx/0/2trk/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", "value": Object { - "rev": "1-1e197ef8965a436730f80cabaaaa6f70", + "rev": "1-e1e6888ad978a5fcc405a75296604bee", }, }, ], @@ -109,30 +109,30 @@ Object { }); test('returns three rows after a gpx and a track segment have been inserted.', async () => { await putNewTrkseg(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' })); + const allDocs: any = await getFamily(uri('gpx', { gpx: '' })); expect(allDocs).toMatchInlineSnapshot(` Object { "offset": 0, "rows": Array [ Object { - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { - "id": "gpx/0/2trk/00000", - "key": "gpx/0/2trk/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", "value": Object { - "rev": "1-1e197ef8965a436730f80cabaaaa6f70", + "rev": "1-e1e6888ad978a5fcc405a75296604bee", }, }, Object { - "id": "gpx/0/2trk/00000/00000", - "key": "gpx/0/2trk/00000/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000", "value": Object { - "rev": "1-33cb714b4d5553cc20fc7a753c63cf51", + "rev": "1-9d8fbcd9cb7d2a45d6caf57a2cbee7ca", }, }, ], @@ -142,37 +142,37 @@ Object { }); test('returns four rows after a gpx and a track point have been inserted.', async () => { await putNewTrkpt(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' })); + const allDocs: any = await getFamily(uri('gpx', { gpx: '' })); expect(allDocs).toMatchInlineSnapshot(` Object { "offset": 0, "rows": Array [ Object { - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { - "id": "gpx/0/2trk/00000", - "key": "gpx/0/2trk/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000", "value": Object { - "rev": "1-1e197ef8965a436730f80cabaaaa6f70", + "rev": "1-e1e6888ad978a5fcc405a75296604bee", }, }, Object { - "id": "gpx/0/2trk/00000/00000", - "key": "gpx/0/2trk/00000/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000", "value": Object { - "rev": "1-33cb714b4d5553cc20fc7a753c63cf51", + "rev": "1-9d8fbcd9cb7d2a45d6caf57a2cbee7ca", }, }, Object { - "id": "gpx/0/2trk/00000/00000/00000", - "key": "gpx/0/2trk/00000/00000/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000/00000", "value": Object { - "rev": "1-c88eea2fc5a5637322a3f3357b49618f", + "rev": "1-42b858110cde8bec09e5d34b9e480936", }, }, ], @@ -183,23 +183,23 @@ Object { test('returns two rows after a gpx and a waypoint have been inserted.', async () => { await putNewWpt(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' })); + const allDocs: any = await getFamily(uri('gpx', { gpx: '' })); expect(allDocs).toMatchInlineSnapshot(` Object { "offset": 0, "rows": Array [ Object { - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { - "id": "gpx/0/0wpt/00000", - "key": "gpx/0/0wpt/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/0wpt/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/0wpt/00000", "value": Object { - "rev": "1-dcdc55abd413b401dba4278510d9c51b", + "rev": "1-f98b9048879fc7b97771bf2bafc77e42", }, }, ], @@ -210,23 +210,23 @@ Object { test('returns two rows after a gpx and a route have been inserted.', async () => { await putNewRte(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' })); + const allDocs: any = await getFamily(uri('gpx', { gpx: '' })); expect(allDocs).toMatchInlineSnapshot(` Object { "offset": 0, "rows": Array [ Object { - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { - "id": "gpx/0/1rte/00000", - "key": "gpx/0/1rte/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000", "value": Object { - "rev": "1-bce69fd9ada837c19cf8c1c296f82f92", + "rev": "1-f17cd2939d1e63764478613f54835884", }, }, ], @@ -237,30 +237,30 @@ Object { test('returns three rows after a gpx and a route point have been inserted.', async () => { await putNewRtept(); - const allDocs: any = await getFamily(uri('gpx', { gpx: '0' })); + const allDocs: any = await getFamily(uri('gpx', { gpx: '' })); expect(allDocs).toMatchInlineSnapshot(` Object { "offset": 0, "rows": Array [ Object { - "id": "gpx/0", - "key": "gpx/0", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z", "value": Object { - "rev": "1-98d42c99fcf471a500b0506a60e77559", + "rev": "1-649694b1e46839ec63d2a93f483dd023", }, }, Object { - "id": "gpx/0/1rte/00000", - "key": "gpx/0/1rte/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000", "value": Object { - "rev": "1-bce69fd9ada837c19cf8c1c296f82f92", + "rev": "1-f17cd2939d1e63764478613f54835884", }, }, Object { - "id": "gpx/0/1rte/00000/00000", - "key": "gpx/0/1rte/00000/00000", + "id": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000/00000", + "key": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000/00000", "value": Object { - "rev": "1-1045e2dc6d2f7927514b02f79d14daa8", + "rev": "1-ba3f25be70b620dd06b453ec29853bae", }, }, ], diff --git a/src/db/rte.test.ts b/src/db/rte.test.ts index f8a7a70..97d30cb 100644 --- a/src/db/rte.test.ts +++ b/src/db/rte.test.ts @@ -43,6 +43,6 @@ describe('The rte module', () => { }); test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewRte(); - expect(id).toEqual({ gpx: '0', rte: '00000' }); + expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', rte: '00000' }); }); }); diff --git a/src/db/rtept.test.ts b/src/db/rtept.test.ts index 68c8e03..6ce9a04 100644 --- a/src/db/rtept.test.ts +++ b/src/db/rtept.test.ts @@ -53,6 +53,6 @@ describe('The rtept module', () => { }); test('db.put() generates ids for both gpx and rte if needed', async () => { const id = await putNewRtept(); - expect(id).toEqual({ gpx: '0', rte: '00000', rtept: '00000' }); + expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', rte: '00000', rtept: '00000' }); }); }); diff --git a/src/db/trk.test.ts b/src/db/trk.test.ts index 917eb39..f29fdb6 100644 --- a/src/db/trk.test.ts +++ b/src/db/trk.test.ts @@ -42,6 +42,6 @@ describe('The trk module', () => { }); test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewTrk(); - expect(id).toEqual({ gpx: '0', trk: '00000' }); + expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', trk: '00000' }); }); }); diff --git a/src/db/trkpt.test.ts b/src/db/trkpt.test.ts index ab7db77..f2097ce 100644 --- a/src/db/trkpt.test.ts +++ b/src/db/trkpt.test.ts @@ -70,7 +70,7 @@ describe('The trkpt module', () => { test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewTrkpt(); expect(id).toEqual({ - gpx: '0', + gpx: '1970-01-01T00:00:00.000Z', trk: '00000', trkseg: '00000', trkpt: '00000', diff --git a/src/db/trkseg.test.ts b/src/db/trkseg.test.ts index 715a3a3..da26cb2 100644 --- a/src/db/trkseg.test.ts +++ b/src/db/trkseg.test.ts @@ -35,6 +35,6 @@ describe('The trkseg module', () => { }); test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewTrkseg(); - expect(id).toEqual({ gpx: '0', trk: '00000', trkseg: '00000' }); + expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', trk: '00000', trkseg: '00000' }); }); }); diff --git a/src/db/wpt.test.ts b/src/db/wpt.test.ts index 6b8dc0a..812a0c2 100644 --- a/src/db/wpt.test.ts +++ b/src/db/wpt.test.ts @@ -53,6 +53,6 @@ describe('The wpt module', () => { }); test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewWpt(); - expect(id).toEqual({ gpx: '0', wpt: '00000' }); + expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', wpt: '00000' }); }); });