@osm-editor-kit/osm-data 0.1.0-alpha.0 → 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,18 +1,62 @@
1
1
  # `@osm-editor-kit/osm-data`
2
2
 
3
- **Status:** First npm **alpha** (`0.1.0-alpha.0`). Publish with `bun run packages:release -- --publish-only` after `npm login`.
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
+
5
+ > [!NOTE]
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
+ ```
4
13
 
5
14
  ## What it does
6
15
 
7
- Download OSM JSON from a URL (Overpass or API) and parse it into indexed in-memory stores for ways, relations, tagged nodes, node coordinates, and ways-in-relation lookup. Exports shared TypeScript types and merges multiple fetches with version-aware updates.
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.
8
23
 
9
24
  ## Usage
10
25
 
11
26
  ```ts
12
- 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
+ )
13
40
 
14
- const parsed = await downloadOsmData(overpassUrl)
15
- 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
16
52
  ```
17
53
 
18
- 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,19 +1,20 @@
1
1
  {
2
2
  "name": "@osm-editor-kit/osm-data",
3
- "version": "0.1.0-alpha.0",
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
- "type": "module",
13
- "sideEffects": false,
14
13
  "files": [
15
14
  "dist"
16
15
  ],
16
+ "type": "module",
17
+ "sideEffects": false,
17
18
  "exports": {
18
19
  ".": {
19
20
  "types": "./dist/index.d.ts",
@@ -22,8 +23,7 @@
22
23
  "./package.json": "./package.json"
23
24
  },
24
25
  "publishConfig": {
25
- "access": "public",
26
- "tag": "alpha"
26
+ "access": "public"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsup && rm -f .tsbuildinfo && tsc -p tsconfig.build.json",