Skip to content

Commit b1bc733

Browse files
committed
v3: several breaking changes for changeset APIs to be consistent with...
...the OSM API's new json endpoints.
1 parent 6ea7ad0 commit b1bc733

File tree

7 files changed

+52
-88
lines changed

7 files changed

+52
-88
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## 3.0.0 (----------)
11+
12+
- 💥 BREAKING CHANGE: `uploadChangeset` now returns an array of changeset IDs. This is because the function supports chunking uploads into multiple changesets if it exceeds the limit of 10,000 features per changeset.
13+
- 💥 BREAKING CHANGE: The type defintions for `Changeset` have been changed to mark several properties as optional. (see #14)
14+
- 💥 BREAKING CHANGE: `Changeset.created_at`, `Changeset.closed_at`, and `ChangesetComment.date` are now a `string`, not a `Date`. This makes it more consistent with the XML format, and easier to serialise to JSON.
15+
- 💥 BREAKING CHANGE: `ChangesetComment.uid` is now a `number`, not a `string`. This matches the behaviour of OSM's new json API.
16+
- 💥 BREAKING CHANGE: `Changeset.discussion` has been renamed to `Changeset.comments`. This matches the behaviour of OSM's new json API.
17+
1018
## 2.4.0 (2025-01-16)
1119

1220
- Added a method to easily switch users (logout & log back in)

src/__tests__/__snapshots__/e2e.test.ts.snap

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ exports[`end to end tests > getCapabilities 1`] = `
105105
exports[`end to end tests > getChangeset (no discussion) 1`] = `
106106
{
107107
"changes_count": 10,
108-
"closed_at": 2021-12-16T09:29:15.000Z,
108+
"closed_at": "2021-12-16T09:29:15Z",
109109
"comments_count": 2,
110-
"created_at": 2021-12-16T09:29:14.000Z,
111-
"discussion": undefined,
110+
"created_at": "2021-12-16T09:29:14Z",
112111
"id": 227200,
113112
"max_lat": -36.8801278,
114113
"max_lon": 174.7400986,
@@ -132,27 +131,27 @@ exports[`end to end tests > getChangeset (no discussion) 1`] = `
132131
exports[`end to end tests > getChangeset (with discussion) 1`] = `
133132
{
134133
"changes_count": 10,
135-
"closed_at": 2021-12-16T09:29:15.000Z,
136-
"comments_count": 2,
137-
"created_at": 2021-12-16T09:29:14.000Z,
138-
"discussion": [
134+
"closed_at": "2021-12-16T09:29:15Z",
135+
"comments": [
139136
{
140-
"date": 2024-06-30T08:59:15.000Z,
137+
"date": "2024-06-30T08:59:15Z",
141138
"id": 736,
142139
"text": "­",
143-
"uid": "12248",
140+
"uid": 12248,
144141
"user": "kylenz_testing",
145142
"visible": true,
146143
},
147144
{
148-
"date": 2024-06-30T08:59:55.000Z,
145+
"date": "2024-06-30T08:59:55Z",
149146
"id": 737,
150147
"text": "sup bro",
151-
"uid": "12248",
148+
"uid": 12248,
152149
"user": "kylenz_testing",
153150
"visible": true,
154151
},
155152
],
153+
"comments_count": 2,
154+
"created_at": "2021-12-16T09:29:14Z",
156155
"id": 227200,
157156
"max_lat": -36.8801278,
158157
"max_lon": 174.7400986,
@@ -487,7 +486,7 @@ exports[`end to end tests > getUser 1`] = `
487486
},
488487
},
489488
"changesets": {
490-
"count": 15,
489+
"count": 27,
491490
},
492491
"contributor_terms": {
493492
"agreed": true,
@@ -506,10 +505,9 @@ exports[`end to end tests > listChangesets 1`] = `
506505
[
507506
{
508507
"changes_count": 2,
509-
"closed_at": 2022-09-10T11:47:14.000Z,
508+
"closed_at": "2022-09-10T11:47:14Z",
510509
"comments_count": 0,
511-
"created_at": 2022-09-10T11:47:13.000Z,
512-
"discussion": undefined,
510+
"created_at": "2022-09-10T11:47:13Z",
513511
"id": 243638,
514512
"max_lat": -36.8804862,
515513
"max_lon": 174.739748,
@@ -526,10 +524,9 @@ exports[`end to end tests > listChangesets 1`] = `
526524
},
527525
{
528526
"changes_count": 10,
529-
"closed_at": 2022-09-10T11:30:13.000Z,
527+
"closed_at": "2022-09-10T11:30:13Z",
530528
"comments_count": 0,
531-
"created_at": 2022-09-10T11:30:12.000Z,
532-
"discussion": undefined,
529+
"created_at": "2022-09-10T11:30:12Z",
533530
"id": 243637,
534531
"max_lat": -36.8804809,
535532
"max_lon": 174.7397571,
@@ -549,10 +546,9 @@ exports[`end to end tests > listChangesets 1`] = `
549546
},
550547
{
551548
"changes_count": 10,
552-
"closed_at": 2021-12-16T09:29:15.000Z,
549+
"closed_at": "2021-12-16T09:29:15Z",
553550
"comments_count": 2,
554-
"created_at": 2021-12-16T09:29:14.000Z,
555-
"discussion": undefined,
551+
"created_at": "2021-12-16T09:29:14Z",
556552
"id": 227200,
557553
"max_lat": -36.8801278,
558554
"max_lon": 174.7400986,
@@ -573,10 +569,9 @@ exports[`end to end tests > listChangesets 1`] = `
573569
},
574570
{
575571
"changes_count": 5,
576-
"closed_at": 2021-12-16T08:43:07.000Z,
572+
"closed_at": "2021-12-16T08:43:07Z",
577573
"comments_count": 0,
578-
"created_at": 2021-12-16T08:43:06.000Z,
579-
"discussion": undefined,
574+
"created_at": "2021-12-16T08:43:06Z",
580575
"id": 227184,
581576
"max_lat": -36.8804809,
582577
"max_lon": 174.7397571,

src/api/_rawResponse.d.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
import type { FeatureCollection, Point } from "geojson";
2-
import type {
3-
Changeset,
4-
ChangesetComment,
5-
OsmFeatureType,
6-
OsmNote,
7-
} from "../types";
8-
9-
/** @internal */
10-
export type RawChangeset = Omit<
11-
Changeset,
12-
"discussion" | "created_at" | "closed_at"
13-
> & {
14-
created_at: string;
15-
closed_at?: string;
16-
comments?: (Omit<ChangesetComment, "date" | "uid"> & {
17-
/** ISO Date */
18-
date: string;
19-
uid: number;
20-
})[];
21-
};
2+
import type { OsmFeatureType, OsmNote } from "../types";
223

234
/** @internal */
245
export type RawNotesSearch = FeatureCollection<

src/api/changesets/__tests__/uploadChangeset.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe("uploadChangeset", () => {
6969
);
7070
}
7171

72-
expect(output).toBe(1);
72+
expect(output).toStrictEqual([1, 4, 7, 10]);
7373
});
7474

7575
it("splits changesets into chunks and suports a custom tag function", async () => {
@@ -101,6 +101,6 @@ describe("uploadChangeset", () => {
101101
);
102102
}
103103

104-
expect(output).toBe(1);
104+
expect(output).toStrictEqual([1, 4, 7, 10]);
105105
});
106106
});

src/api/changesets/getChangesets.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
import type { BBox, Changeset } from "../../types";
22
import { osmFetch } from "../_osmFetch";
3-
import type { RawChangeset } from "../_rawResponse";
4-
5-
const mapRawChangeset = ({ comments, ...raw }: RawChangeset): Changeset => ({
6-
...raw,
7-
created_at: new Date(raw.created_at),
8-
closed_at: raw.closed_at ? new Date(raw.closed_at) : undefined!,
9-
10-
discussion: comments?.map((comment) => ({
11-
...comment,
12-
date: new Date(comment.date),
13-
uid: `${comment.uid}`,
14-
})),
15-
});
163

174
export type ListChangesetOptions = {
185
/** Find changesets within the given bounding box */
@@ -51,26 +38,26 @@ export async function listChangesets(
5138
): Promise<Changeset[]> {
5239
const { only, ...otherOptions } = options;
5340

54-
const raw = await osmFetch<{ changesets: RawChangeset[] }>(
41+
const raw = await osmFetch<{ changesets: Changeset[] }>(
5542
"/0.6/changesets.json",
5643
{
5744
...(only && { [only]: true }),
5845
...otherOptions,
5946
}
6047
);
6148

62-
return raw.changesets.map(mapRawChangeset);
49+
return raw.changesets;
6350
}
6451

6552
/** get a single changeset */
6653
export async function getChangeset(
6754
id: number,
6855
includeDiscussion = true
6956
): Promise<Changeset> {
70-
const raw = await osmFetch<{ changeset: RawChangeset }>(
57+
const raw = await osmFetch<{ changeset: Changeset }>(
7158
`/0.6/changeset/${id}.json`,
7259
includeDiscussion ? { include_discussion: 1 } : {}
7360
);
7461

75-
return mapRawChangeset(raw.changeset);
62+
return raw.changeset;
7663
}

src/api/changesets/uploadChangeset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function uploadChangeset(
3232
*/
3333
onChunk?(info: UploadChunkInfo): Tags;
3434
}
35-
): Promise<number> {
35+
): Promise<number[]> {
3636
const chunks = chunkOsmChange(diff);
3737
const csIds: number[] = [];
3838

@@ -82,5 +82,5 @@ export async function uploadChangeset(
8282
csIds.push(csId);
8383
}
8484

85-
return csIds[0]; // TODO:(semver breaking) return an array of IDs
85+
return csIds;
8686
}

src/types/changesets.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,35 @@ export type ChangesetComment = {
44
id: number;
55
visible: boolean;
66
user: string;
7-
// TODO:(semver breaking) change to number
8-
uid: string;
9-
// TODO:(semver breaking) change to string
10-
date: Date;
7+
uid: number;
8+
date: string;
119
text: string;
1210
};
1311

1412
export type Changeset = {
1513
id: number;
16-
// TODO:(semver breaking) change to string
17-
created_at: Date;
14+
created_at: string;
1815
open: boolean;
1916
comments_count: number;
2017
changes_count: number;
21-
/** property only exists if `open=false` */
22-
// TODO:(semver breaking) mark as optional
23-
closed_at: Date;
24-
/** property only exists if `open=false` */
25-
// TODO:(semver breaking) mark as optional
26-
min_lat: number;
27-
/** property only exists if `open=false` */
28-
// TODO:(semver breaking) mark as optional
29-
min_lon: number;
30-
/** property only exists if `open=false` */
31-
// TODO:(semver breaking) mark as optional
32-
max_lat: number;
33-
/** property only exists if `open=false` */
34-
// TODO:(semver breaking) mark as optional
35-
max_lon: number;
18+
/** This property is missing if `open=true` */
19+
closed_at?: string;
20+
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
21+
min_lat?: number;
22+
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
23+
min_lon?: number;
24+
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
25+
max_lat?: number;
26+
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
27+
max_lon?: number;
3628
uid: number;
3729
user: string;
3830
tags: {
3931
[key: string]: string;
4032
};
41-
/** the `discussion` attribute is only included in the `getChangeset` API */
42-
discussion?: ChangesetComment[];
33+
34+
/** the `comments` attribute is only included in the `getChangeset` API */
35+
comments?: ChangesetComment[];
4336
};
4437

4538
export type OsmChange = {

0 commit comments

Comments
 (0)