@osm-editor-kit/osm-data 0.1.0-alpha.1 → 1.0.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/README.md CHANGED
@@ -1,23 +1,62 @@
1
1
  # `@osm-editor-kit/osm-data`
2
2
 
3
+ Download OSM JSON from Overpass or the OSM API, parse it into an indexed in-memory store, and merge several downloads into one. For apps that show or check OSM data.
4
+
3
5
  > [!NOTE]
4
- > This package is an **alpha** release and still under active development. APIs may change; install with the npm `alpha` dist-tag.
6
+ > Claude Opus 5.5 wrote and reviewed the code of this package. [@tordans](https://github.com/tordans) specified what it should do and tested and verified its user-facing behavior.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @osm-editor-kit/osm-data
12
+ ```
5
13
 
6
14
  ## What it does
7
15
 
8
- - Fetch OSM JSON from Overpass or the OSM API
9
- - Parse responses into in-memory indexes (ways, relations, tagged nodes, coordinates)
10
- - Look up which ways belong to a relation
11
- - Merge several downloads into one graph, preferring newer element versions
12
- - Shared TypeScript types for parsed OSM session data
16
+ - Fetches OSM JSON from a URL (Overpass or OSM API).
17
+ - Parses `elements` into indexes by id: ways, relations, tagged nodes, and node coordinates (`[lat, lon]`).
18
+ - Marks which ways are members of a relation (`waysInRelation`).
19
+ - Merges two parsed stores. Ways and relations keep the higher `version`; nodes and coordinates from the newer store replace existing ones.
20
+ - Exports TypeScript types for OSM elements and the parsed store.
21
+
22
+ It only fetches, parses, and indexes. It does not edit OSM data or write tags.
13
23
 
14
24
  ## Usage
15
25
 
16
26
  ```ts
17
- import { downloadOsmData, parseOsmResp, mergeParsedOsm } from '@osm-editor-kit/osm-data'
27
+ import {
28
+ downloadOsmData,
29
+ emptyParsedOsmData,
30
+ mergeParsedOsm,
31
+ parseOsmResp,
32
+ type ParsedOsmData,
33
+ type RawOsmData,
34
+ } from '@osm-editor-kit/osm-data'
35
+
36
+ // Download from a URL that returns OSM JSON (throws when the request fails, for example HTTP 429)
37
+ const downloaded: ParsedOsmData = await downloadOsmData(
38
+ 'https://overpass-api.de/api/interpreter?data=[out:json];way(52.47,13.44,52.48,13.45)[highway];out;',
39
+ )
18
40
 
19
- const parsed = await downloadOsmData(overpassUrl)
20
- const combined = mergeParsedOsm(parsed, parseOsmResp(rawOsmResp))
41
+ // Or parse a response you already have
42
+ const raw: RawOsmData = { elements: [] }
43
+ const parsed = parseOsmResp(raw)
44
+
45
+ // Merge into one store; start from an empty store if you have nothing yet
46
+ const store = mergeParsedOsm(emptyParsedOsmData(), downloaded)
47
+ const combined = mergeParsedOsm(store, parsed)
48
+
49
+ combined.ways[42]?.tags.highway
50
+ combined.nodeCoords[10] // [lat, lon]
51
+ combined.waysInRelation[42] // true when a parsed relation lists way 42
21
52
  ```
22
53
 
23
- Fetch/parse/index only — not an OSM editor or tag writer.
54
+ Notes:
55
+
56
+ - `parseOsmResp` throws on element types other than `node`, `way`, and `relation`.
57
+ - `waysInRelation` only marks ways that appear in the response before the relation. Overpass lists ways before relations, so this works with its default output.
58
+ - Only nodes with tags are stored in `nodes`. All nodes are stored in `nodeCoords`.
59
+
60
+ ## License
61
+
62
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { downloadOsmData, emptyParsedOsmData, mergeParsedOsm, parseOsmResp } from './data-client';
2
2
  export type { LatLngLiteral, MapBounds } from './types/geo';
3
- export type { OsmElement, OsmNode, OsmObject, OsmRelation, OsmTags, OsmWay, RawOsmData, } from './types/osm-data';
3
+ export type { OsmElement, OsmNode, OsmObject, OsmRelation, OsmTags, OsmType, OsmWay, RawOsmData, RelationMember, } from './types/osm-data';
4
4
  export type { ParsedOsmData, WaysInRelation } from './types/osm-data-storage';
@@ -1,5 +1,5 @@
1
1
  export type OsmTags = Record<string, string>;
2
- type OsmType = 'node' | 'way' | 'relation';
2
+ export type OsmType = 'node' | 'way' | 'relation';
3
3
  export interface OsmObject {
4
4
  id: number;
5
5
  type: OsmType;
@@ -11,7 +11,7 @@ export interface OsmObject {
11
11
  changeset: number;
12
12
  tags: OsmTags;
13
13
  }
14
- interface RelationMember {
14
+ export interface RelationMember {
15
15
  type: OsmType;
16
16
  ref: number;
17
17
  role: string;
@@ -33,4 +33,3 @@ export type OsmElement = OsmNode | OsmWay | OsmRelation;
33
33
  export interface RawOsmData {
34
34
  elements: OsmElement[];
35
35
  }
36
- export {};
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@osm-editor-kit/osm-data",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "1.0.0",
4
4
  "description": "Download, parse, and merge OSM API/Overpass responses into an indexed in-memory store.",
5
+ "homepage": "https://github.com/osm-editor-kit/street-space-editor/tree/main/packages/osm-data",
5
6
  "license": "MIT",
6
7
  "author": "Tobias Jordans",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "git+https://github.com/osmberlin/street-space-editor.git",
10
+ "url": "git+https://github.com/osm-editor-kit/street-space-editor.git",
10
11
  "directory": "packages/osm-data"
11
12
  },
12
- "homepage": "https://github.com/osmberlin/street-space-editor/tree/main/packages/osm-data",
13
- "type": "module",
14
- "sideEffects": false,
15
13
  "files": [
16
14
  "dist"
17
15
  ],
16
+ "type": "module",
17
+ "sideEffects": false,
18
18
  "exports": {
19
19
  ".": {
20
20
  "types": "./dist/index.d.ts",
@@ -23,8 +23,7 @@
23
23
  "./package.json": "./package.json"
24
24
  },
25
25
  "publishConfig": {
26
- "access": "public",
27
- "tag": "alpha"
26
+ "access": "public"
28
27
  },
29
28
  "scripts": {
30
29
  "build": "tsup && rm -f .tsbuildinfo && tsc -p tsconfig.build.json",