Skip to content

v3: several breaking changes for changeset APIs #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 3.0.0 (----------)

- 💥 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.
- 💥 BREAKING CHANGE: The type defintions for `Changeset` have been changed to mark several properties as optional. (see #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.
- 💥 BREAKING CHANGE: `ChangesetComment.uid` is now a `number`, not a `string`. This matches the behaviour of OSM's new json API.
- 💥 BREAKING CHANGE: `Changeset.discussion` has been renamed to `Changeset.comments`. This matches the behaviour of OSM's new json API.

## 2.4.0 (2025-01-16)

- Added a method to easily switch users (logout & log back in)
Expand Down
43 changes: 19 additions & 24 deletions src/__tests__/__snapshots__/e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ exports[`end to end tests > getCapabilities 1`] = `
exports[`end to end tests > getChangeset (no discussion) 1`] = `
{
"changes_count": 10,
"closed_at": 2021-12-16T09:29:15.000Z,
"closed_at": "2021-12-16T09:29:15Z",
"comments_count": 2,
"created_at": 2021-12-16T09:29:14.000Z,
"discussion": undefined,
"created_at": "2021-12-16T09:29:14Z",
"id": 227200,
"max_lat": -36.8801278,
"max_lon": 174.7400986,
Expand All @@ -132,27 +131,27 @@ exports[`end to end tests > getChangeset (no discussion) 1`] = `
exports[`end to end tests > getChangeset (with discussion) 1`] = `
{
"changes_count": 10,
"closed_at": 2021-12-16T09:29:15.000Z,
"comments_count": 2,
"created_at": 2021-12-16T09:29:14.000Z,
"discussion": [
"closed_at": "2021-12-16T09:29:15Z",
"comments": [
{
"date": 2024-06-30T08:59:15.000Z,
"date": "2024-06-30T08:59:15Z",
"id": 736,
"text": "­",
"uid": "12248",
"uid": 12248,
"user": "kylenz_testing",
"visible": true,
},
{
"date": 2024-06-30T08:59:55.000Z,
"date": "2024-06-30T08:59:55Z",
"id": 737,
"text": "sup bro",
"uid": "12248",
"uid": 12248,
"user": "kylenz_testing",
"visible": true,
},
],
"comments_count": 2,
"created_at": "2021-12-16T09:29:14Z",
"id": 227200,
"max_lat": -36.8801278,
"max_lon": 174.7400986,
Expand Down Expand Up @@ -487,7 +486,7 @@ exports[`end to end tests > getUser 1`] = `
},
},
"changesets": {
"count": 15,
"count": 27,
},
"contributor_terms": {
"agreed": true,
Expand All @@ -506,10 +505,9 @@ exports[`end to end tests > listChangesets 1`] = `
[
{
"changes_count": 2,
"closed_at": 2022-09-10T11:47:14.000Z,
"closed_at": "2022-09-10T11:47:14Z",
"comments_count": 0,
"created_at": 2022-09-10T11:47:13.000Z,
"discussion": undefined,
"created_at": "2022-09-10T11:47:13Z",
"id": 243638,
"max_lat": -36.8804862,
"max_lon": 174.739748,
Expand All @@ -526,10 +524,9 @@ exports[`end to end tests > listChangesets 1`] = `
},
{
"changes_count": 10,
"closed_at": 2022-09-10T11:30:13.000Z,
"closed_at": "2022-09-10T11:30:13Z",
"comments_count": 0,
"created_at": 2022-09-10T11:30:12.000Z,
"discussion": undefined,
"created_at": "2022-09-10T11:30:12Z",
"id": 243637,
"max_lat": -36.8804809,
"max_lon": 174.7397571,
Expand All @@ -549,10 +546,9 @@ exports[`end to end tests > listChangesets 1`] = `
},
{
"changes_count": 10,
"closed_at": 2021-12-16T09:29:15.000Z,
"closed_at": "2021-12-16T09:29:15Z",
"comments_count": 2,
"created_at": 2021-12-16T09:29:14.000Z,
"discussion": undefined,
"created_at": "2021-12-16T09:29:14Z",
"id": 227200,
"max_lat": -36.8801278,
"max_lon": 174.7400986,
Expand All @@ -573,10 +569,9 @@ exports[`end to end tests > listChangesets 1`] = `
},
{
"changes_count": 5,
"closed_at": 2021-12-16T08:43:07.000Z,
"closed_at": "2021-12-16T08:43:07Z",
"comments_count": 0,
"created_at": 2021-12-16T08:43:06.000Z,
"discussion": undefined,
"created_at": "2021-12-16T08:43:06Z",
"id": 227184,
"max_lat": -36.8804809,
"max_lon": 174.7397571,
Expand Down
21 changes: 1 addition & 20 deletions src/api/_rawResponse.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
import type { FeatureCollection, Point } from "geojson";
import type {
Changeset,
ChangesetComment,
OsmFeatureType,
OsmNote,
} from "../types";

/** @internal */
export type RawChangeset = Omit<
Changeset,
"discussion" | "created_at" | "closed_at"
> & {
created_at: string;
closed_at?: string;
comments?: (Omit<ChangesetComment, "date" | "uid"> & {
/** ISO Date */
date: string;
uid: number;
})[];
};
import type { OsmFeatureType, OsmNote } from "../types";

/** @internal */
export type RawNotesSearch = FeatureCollection<
Expand Down
4 changes: 2 additions & 2 deletions src/api/changesets/__tests__/uploadChangeset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("uploadChangeset", () => {
);
}

expect(output).toBe(1);
expect(output).toStrictEqual([1, 4, 7, 10]);
});

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

expect(output).toBe(1);
expect(output).toStrictEqual([1, 4, 7, 10]);
});
});
21 changes: 4 additions & 17 deletions src/api/changesets/getChangesets.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import type { BBox, Changeset } from "../../types";
import { osmFetch } from "../_osmFetch";
import type { RawChangeset } from "../_rawResponse";

const mapRawChangeset = ({ comments, ...raw }: RawChangeset): Changeset => ({
...raw,
created_at: new Date(raw.created_at),
closed_at: raw.closed_at ? new Date(raw.closed_at) : undefined!,

discussion: comments?.map((comment) => ({
...comment,
date: new Date(comment.date),
uid: `${comment.uid}`,
})),
});

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

const raw = await osmFetch<{ changesets: RawChangeset[] }>(
const raw = await osmFetch<{ changesets: Changeset[] }>(
"/0.6/changesets.json",
{
...(only && { [only]: true }),
...otherOptions,
}
);

return raw.changesets.map(mapRawChangeset);
return raw.changesets;
}

/** get a single changeset */
export async function getChangeset(
id: number,
includeDiscussion = true
): Promise<Changeset> {
const raw = await osmFetch<{ changeset: RawChangeset }>(
const raw = await osmFetch<{ changeset: Changeset }>(
`/0.6/changeset/${id}.json`,
includeDiscussion ? { include_discussion: 1 } : {}
);

return mapRawChangeset(raw.changeset);
return raw.changeset;
}
4 changes: 2 additions & 2 deletions src/api/changesets/uploadChangeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function uploadChangeset(
*/
onChunk?(info: UploadChunkInfo): Tags;
}
): Promise<number> {
): Promise<number[]> {
const chunks = chunkOsmChange(diff);
const csIds: number[] = [];

Expand Down Expand Up @@ -82,5 +82,5 @@ export async function uploadChangeset(
csIds.push(csId);
}

return csIds[0]; // TODO:(semver breaking) return an array of IDs
return csIds;
}
39 changes: 16 additions & 23 deletions src/types/changesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,35 @@ export type ChangesetComment = {
id: number;
visible: boolean;
user: string;
// TODO:(semver breaking) change to number
uid: string;
// TODO:(semver breaking) change to string
date: Date;
uid: number;
date: string;
text: string;
};

export type Changeset = {
id: number;
// TODO:(semver breaking) change to string
created_at: Date;
created_at: string;
open: boolean;
comments_count: number;
changes_count: number;
/** property only exists if `open=false` */
// TODO:(semver breaking) mark as optional
closed_at: Date;
/** property only exists if `open=false` */
// TODO:(semver breaking) mark as optional
min_lat: number;
/** property only exists if `open=false` */
// TODO:(semver breaking) mark as optional
min_lon: number;
/** property only exists if `open=false` */
// TODO:(semver breaking) mark as optional
max_lat: number;
/** property only exists if `open=false` */
// TODO:(semver breaking) mark as optional
max_lon: number;
/** This property is missing if `open=true` */
closed_at?: string;
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
min_lat?: number;
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
min_lon?: number;
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
max_lat?: number;
/** This property is missing if `open=true`, or if none of the edited features have geometry data (see #14) */
max_lon?: number;
uid: number;
user: string;
tags: {
[key: string]: string;
};
/** the `discussion` attribute is only included in the `getChangeset` API */
discussion?: ChangesetComment[];

/** the `comments` attribute is only included in the `getChangeset` API */
comments?: ChangesetComment[];
};

export type OsmChange = {
Expand Down