@mailwoman/zoning 9.4.0 → 10.1.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.
Files changed (98) hide show
  1. package/README.md +169 -163
  2. package/lib/index.ts +89 -120
  3. package/lib/paths.ts +24 -0
  4. package/lib/ring-roles.ts +30 -71
  5. package/lib/rings.ts +2 -13
  6. package/lib/schema.ts +96 -114
  7. package/lib/vocabulary.ts +52 -130
  8. package/out/index.d.ts +75 -95
  9. package/out/index.d.ts.map +1 -1
  10. package/out/index.js +25 -82
  11. package/out/index.js.map +1 -1
  12. package/out/paths.d.ts +19 -0
  13. package/out/paths.d.ts.map +1 -0
  14. package/out/paths.js +21 -0
  15. package/out/paths.js.map +1 -0
  16. package/out/ring-roles.d.ts +16 -50
  17. package/out/ring-roles.d.ts.map +1 -1
  18. package/out/ring-roles.js +18 -51
  19. package/out/ring-roles.js.map +1 -1
  20. package/out/rings.d.ts +2 -13
  21. package/out/rings.d.ts.map +1 -1
  22. package/out/rings.js +2 -13
  23. package/out/rings.js.map +1 -1
  24. package/out/schema.d.ts +93 -108
  25. package/out/schema.d.ts.map +1 -1
  26. package/out/schema.js +16 -44
  27. package/out/schema.js.map +1 -1
  28. package/out/sdk/build-zoning.d.ts +58 -111
  29. package/out/sdk/build-zoning.d.ts.map +1 -1
  30. package/out/sdk/build-zoning.js +48 -137
  31. package/out/sdk/build-zoning.js.map +1 -1
  32. package/out/sdk/cells.d.ts +20 -61
  33. package/out/sdk/cells.d.ts.map +1 -1
  34. package/out/sdk/cells.js +13 -50
  35. package/out/sdk/cells.js.map +1 -1
  36. package/out/sdk/client.d.ts +23 -67
  37. package/out/sdk/client.d.ts.map +1 -1
  38. package/out/sdk/client.js +29 -77
  39. package/out/sdk/client.js.map +1 -1
  40. package/out/sdk/download.d.ts +7 -27
  41. package/out/sdk/download.d.ts.map +1 -1
  42. package/out/sdk/download.js +7 -27
  43. package/out/sdk/download.js.map +1 -1
  44. package/out/sdk/ingest/chunk.d.ts +106 -0
  45. package/out/sdk/ingest/chunk.d.ts.map +1 -0
  46. package/out/sdk/{ingest-chunk.js → ingest/chunk.js} +17 -50
  47. package/out/sdk/ingest/chunk.js.map +1 -0
  48. package/out/sdk/ingest/worker.d.ts +9 -0
  49. package/out/sdk/ingest/worker.d.ts.map +1 -0
  50. package/out/{scripts/ingest-chunk.js → sdk/ingest/worker.js} +5 -7
  51. package/out/sdk/ingest/worker.js.map +1 -0
  52. package/out/sdk/ingest.d.ts +54 -77
  53. package/out/sdk/ingest.d.ts.map +1 -1
  54. package/out/sdk/ingest.js +50 -87
  55. package/out/sdk/ingest.js.map +1 -1
  56. package/out/sdk/measure-resolutions.d.ts +6 -23
  57. package/out/sdk/measure-resolutions.d.ts.map +1 -1
  58. package/out/sdk/measure-resolutions.js +4 -21
  59. package/out/sdk/measure-resolutions.js.map +1 -1
  60. package/out/sdk/test-kit.d.ts +75 -0
  61. package/out/sdk/test-kit.d.ts.map +1 -0
  62. package/out/{test-kit.js → sdk/test-kit.js} +20 -43
  63. package/out/sdk/test-kit.js.map +1 -0
  64. package/out/sdk/verify.d.ts +74 -56
  65. package/out/sdk/verify.d.ts.map +1 -1
  66. package/out/sdk/verify.js +70 -57
  67. package/out/sdk/verify.js.map +1 -1
  68. package/out/vocabulary.d.ts +52 -120
  69. package/out/vocabulary.d.ts.map +1 -1
  70. package/out/vocabulary.js +47 -125
  71. package/out/vocabulary.js.map +1 -1
  72. package/package.json +37 -161
  73. package/{lib/sdk → sdk}/build-zoning.ts +100 -186
  74. package/{lib/sdk → sdk}/cells.ts +24 -63
  75. package/{lib/sdk → sdk}/client.ts +34 -82
  76. package/sdk/download.ts +58 -0
  77. package/{lib/sdk/ingest-chunk.ts → sdk/ingest/chunk.ts} +32 -61
  78. package/{lib/scripts/ingest-chunk.ts → sdk/ingest/worker.ts} +4 -6
  79. package/sdk/ingest.ts +366 -0
  80. package/{lib/sdk → sdk}/measure-resolutions.ts +8 -25
  81. package/{lib → sdk}/test-kit.ts +20 -43
  82. package/{lib/sdk → sdk}/verify.ts +102 -75
  83. package/lib/sdk/download.ts +0 -78
  84. package/lib/sdk/index.ts +0 -15
  85. package/lib/sdk/ingest.ts +0 -398
  86. package/out/scripts/ingest-chunk.d.ts +0 -11
  87. package/out/scripts/ingest-chunk.d.ts.map +0 -1
  88. package/out/scripts/ingest-chunk.js.map +0 -1
  89. package/out/sdk/index.d.ts +0 -15
  90. package/out/sdk/index.d.ts.map +0 -1
  91. package/out/sdk/index.js +0 -15
  92. package/out/sdk/index.js.map +0 -1
  93. package/out/sdk/ingest-chunk.d.ts +0 -130
  94. package/out/sdk/ingest-chunk.d.ts.map +0 -1
  95. package/out/sdk/ingest-chunk.js.map +0 -1
  96. package/out/test-kit.d.ts +0 -96
  97. package/out/test-kit.d.ts.map +0 -1
  98. package/out/test-kit.js.map +0 -1
@@ -3,27 +3,11 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * `@mailwoman/zoning/test-kit` — hand-built geometry for the fixture rung: zones in two plans over the same
7
- * ground, one with a hole encoded the way this service encodes them, one smaller than a cell, and one the
8
- * authority states as UNZONED.
6
+ * `@mailwoman/zoning/test-kit` provides hand-built geometry for fixture tests.
7
+ * It includes zones in two plans over the same ground. It includes a zone with a service-encoded hole.
8
+ * It includes a zone smaller than a cell and a zone the authority states as unzoned.
9
9
  *
10
- * A PACKAGE SUBPATH RATHER THAN A `test/` FILE, for the same reason `packages/mailwoman/lib/test-kit` is one:
11
- * the observation route's suite lives in another workspace, and a relative import across two TypeScript
12
- * projects is refused outright (`TS2878`) because the compiled layout would not match the source layout.
13
- *
14
- * NO NETWORK AND NO GDAL. The builder takes a {@linkcode ZoningFeatureSource}, so a fixture is a list of
15
- * features — which is what lets this rung exercise the ring-role resolution, the vocabulary census, the cell
16
- * classification, the coverage rows, the manifest and the seal on every machine rather than only the ones
17
- * with ogr2ogr.
18
- *
19
- * THE EXTERIOR RING IS THE CLOCKWISE ONE, WHICH IS THE INVERSE OF THE GEOJSON CONVENTION AND OF EVERY
20
- * SIBLING FIXTURE. `@mailwoman/spatial`'s `rectangleRing` winds counter-clockwise and its `reversedRing`
21
- * clockwise, so this file aliases them the other way round from the flood and coastal test kits: under this
22
- * service a clockwise ring is the EXTERIOR and a counter-clockwise one is a HOLE. A fixture that used the
23
- * sibling naming would build geometry the ingest reads inside-out, and every assertion on it would pass.
24
- *
25
- * THE COORDINATES ARE IN THE IRISH SEA east of Dublin — inside the Department's declared extent, so a
26
- * fixture stays in the coordinate space the product occupies, and clear of every real zoning polygon.
10
+ * Under this service a clockwise ring is the exterior and a counter-clockwise one is a hole, the inverse of the GeoJSON convention and of every sibling fixture.
27
11
  */
28
12
 
29
13
  import {
@@ -37,12 +21,12 @@ import type { ZoningFeatureSource, ZoningSourceFeature } from "#sdk/ingest"
37
21
  import { GZT_SOURCE_EPSG, GZT_UNZONED_LOCAL_CODE } from "#vocabulary"
38
22
 
39
23
  /**
40
- * The exterior ring builder, under THIS service's convention. Clockwise.
24
+ * The exterior ring builder under this service's convention.
41
25
  */
42
26
  export const exteriorRing = clockwiseRing
43
27
 
44
28
  /**
45
- * The hole ring builder, under THIS service's convention. Counter-clockwise.
29
+ * The hole ring builder under this service's convention.
46
30
  */
47
31
  export const holeRing = counterClockwiseRing
48
32
 
@@ -52,22 +36,18 @@ export const holeRing = counterClockwiseRing
52
36
  export const FIXTURE_ORIGIN = { lon: -5.99, lat: 53.3 } as const
53
37
 
54
38
  /**
55
- * Side of a fixture zone, in degrees. About 1.1 km at this latitude — several res-10 cells across, so a zone has a real
56
- * interior AND a real fringe.
39
+ * Side of a fixture zone in degrees.
57
40
  */
58
41
  export const FIXTURE_SIDE = 0.01
59
42
 
60
43
  /**
61
- * The fixture authority and its two plans.
44
+ * The fixture authority's code and name.
62
45
  */
63
46
  export const FIXTURE_AUTHORITY = { code: "Fx", name: "Fixture County Council" } as const
64
47
 
65
48
  /**
66
- * The two plans the fixture set uses, shaped like the real product's: a Development Plan and a Local Area Plan, each
67
- * with its own stated window, both able to zone the same ground.
68
- *
69
- * The dates are in the source's own RFC 1123 form, because that is what the export publishes and this layer carries
70
- * them as published rather than re-formatting them.
49
+ * The two plans the fixture set uses, shaped like the real product's, with dates
50
+ * preserved as published in the source's own RFC 1123 form.
71
51
  */
72
52
  export const FIXTURE_PLANS = {
73
53
  development: {
@@ -113,18 +93,16 @@ export function fixtureFeature(
113
93
  crosswalkDescription: "Existing residential",
114
94
  crosswalkRollup: "RE",
115
95
  ...overrides,
116
- // RESOLVED THROUGH THE REAL RESOLVER, never hand-assembled: a fixture that nested its own holes would test the
117
- // assertion rather than the resolution, and the resolution is the part of this layer no sibling already has.
96
+ // Resolved through the real resolver rather than hand-assembled.
118
97
  rings: resolveRingRoles(polygons, String(objectID)),
119
98
  }
120
99
  }
121
100
 
122
101
  /**
123
- * The fixture set: two adjacent zones, one of them holed the way this service encodes holes; a second plan over the
124
- * SAME ground as the first; a zone smaller than a cell; and a zone the authority states as unzoned.
102
+ * The fixture set has two adjacent zones and one with a service-encoded hole.
125
103
  *
126
- * THE OVERLAP BETWEEN PLANS IS THE POINT. A point inside the first zone must answer with BOTH rows, each naming its own
127
- * plan — which is what proves a plan is part of the claim rather than a parameter of it.
104
+ * It has a second plan over the same ground.
105
+ * It has a zone smaller than a cell and a zone the authority states as unzoned.
128
106
  */
129
107
  export function fixtureFeatures(): ZoningSourceFeature[] {
130
108
  const { lon, lat } = FIXTURE_ORIGIN
@@ -132,8 +110,8 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
132
110
  const zoneA = exteriorRing(lon, lat, lon + FIXTURE_SIDE, lat + FIXTURE_SIDE)
133
111
  const zoneB = exteriorRing(lon + FIXTURE_SIDE, lat, lon + 2 * FIXTURE_SIDE, lat + FIXTURE_SIDE)
134
112
 
135
- // THE HOLE IS A SEPARATE PART, not a nested ring — which is how the real service encodes it on the features that carry
136
- // one, and the encoding a nesting-aware reader turns into a second zoned area.
113
+ // The real service encodes the hole as a separate part.
114
+ // It does not nest the hole ring.
137
115
  const holed: MultiPolygonRings = [
138
116
  [exteriorRing(lon, lat + 2 * FIXTURE_SIDE, lon + FIXTURE_SIDE, lat + 3 * FIXTURE_SIDE)],
139
117
  [
@@ -146,8 +124,8 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
146
124
  ],
147
125
  ]
148
126
 
149
- // About 5.5 m across — smaller than a res-11 cell, let alone a res-9 one. `polygonToCells` returns nothing for a shape
150
- // this size, so it is the fixture that proves the index takes cell-touches-polygon rather than centre-in-polygon.
127
+ // Smaller than a res-11 cell, so `polygonToCells` returns no cell and the index must
128
+ // cover it by cell-touches-polygon rather than center-in-polygon.
151
129
  const sliver = exteriorRing(lon + 3 * FIXTURE_SIDE, lat, lon + 3 * FIXTURE_SIDE + 0.00005, lat + 0.00005)
152
130
 
153
131
  const unzoned = exteriorRing(lon + 4 * FIXTURE_SIDE, lat, lon + 5 * FIXTURE_SIDE, lat + FIXTURE_SIDE)
@@ -174,7 +152,7 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
174
152
  crosswalkCode: "N1.1",
175
153
  crosswalkDescription: "Road",
176
154
  }),
177
- // The authority states unzoned land POSITIVELY, and uses a code its own domain never declares for it.
155
+ // The authority marks land as unzoned with a code its own domain does not declare.
178
156
  fixtureFeature(5, [[unzoned]], {
179
157
  localCode: GZT_UNZONED_LOCAL_CODE,
180
158
  localDescription: "Unzoned",
@@ -182,8 +160,7 @@ export function fixtureFeatures(): ZoningSourceFeature[] {
182
160
  crosswalkDescription: null,
183
161
  crosswalkRollup: "N/A",
184
162
  }),
185
- // The SAME ground as zone A under a second plan, and the same local code mapped to a DIFFERENT generic type — which
186
- // is the shape that makes the crosswalk non-functional over an (authority, code) pair.
163
+ // The same ground as zone A under a second plan, with the same local code mapped to a different generic type.
187
164
  fixtureFeature(6, [[zoneA]], {
188
165
  planID: localAreaPlan.id,
189
166
  planName: localAreaPlan.name,
@@ -3,37 +3,34 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * The two-path agreement check, and its negative half.
6
+ * The check compares the artifact with a second path. A separate half tests locations outside its coverage.
7
7
  *
8
- * POSITIVE HALF. A sample of points is answered from the sealed artifact and then re-asked of the
9
- * Department's own feature service — the same authority, a different distribution channel, and geometry
10
- * this package has never touched. The point test is run again on the service's own rings, so what is
11
- * compared is a verdict against a verdict rather than a file against itself. That is what makes it a check
12
- * on OUR CONVERSION rather than on the authority.
8
+ * The positive half samples points from the sealed artifact and asks the Department's feature service about them.
9
+ * The service supplies geometry through a separate distribution channel. This package has not touched that geometry.
10
+ * The check runs the point test on the service's rings. It compares two verdicts from the same authority.
11
+ * This measures our conversion against the authority's published geometry.
13
12
  *
14
- * AND THE SERVICE ANSWERS IN THE PUBLISHER'S OWN RING CONVENTION, so the comparison exercises the hole
15
- * handling twice over. `outSR=4326` on the query path returns the same clockwise-exterior rings the bulk
16
- * export carries, so this side re-derives the roles the same way the ingest did — and a point inside a hole
17
- * comes back OUTSIDE on both paths or on neither.
13
+ * The service returns geometry in the publisher's ring convention. `outSR=4326` returns the same clockwise-exterior
14
+ * rings as the bulk export. This path re-derives ring roles as ingest does. A point inside a hole then falls outside
15
+ * on both paths or inside on both paths.
18
16
  *
19
- * NEGATIVE HALF, AND IT MATTERS MORE HERE THAN FOR ANY SIBLING LAYER. Donegal is the one local authority of
20
- * 31 the Department does not publish, and Northern Ireland is outside the product entirely — so points in
21
- * both must come back `unknown` with NO designation. A positive-only check would pass on an artifact that
22
- * reported the whole island as zoned, and this layer's entire coverage posture exists because an absent
23
- * polygon is not a statement.
17
+ * The negative half checks locations outside the publication area. The Department omits Donegal, one of 31 local
18
+ * authorities. The product also excludes Northern Ireland. Points in both areas must return `unknown` with no
19
+ * designation. A positive-only check could pass an artifact that reports the whole island as zoned. The layer treats
20
+ * a missing polygon as no zoning statement.
24
21
  *
25
- * THE CHANNELS DIFFER IN COORDINATE PRECISION AND THAT IS WHY A BOUNDARY POINT IS NOT A FAILURE. The
26
- * archive publishes nine decimals through this package's ingest; the service's own JSON rounds. A point
27
- * within roughly a metre of a zone boundary can land on opposite sides of two renderings of the same edge.
28
- * Those are reported as `boundary_tolerance` with their distance to the nearest edge, and the count is part
29
- * of the receipt.
22
+ * The channels use different coordinate precision. A boundary-point disagreement therefore does not establish a
23
+ * conversion defect. The archive publishes nine decimals through this package's ingest. The service rounds its JSON.
24
+ * A point within roughly a meter of a zone boundary can fall on opposite sides of the two rendered edges. The check
25
+ * reports these cases as `boundary_tolerance` with the distance to the nearest edge. The receipt includes their count.
30
26
  *
31
- * THE DISTANCE IS TO THE EDGE, NOT TO THE NEAREST VERTEX. A point a centimetre from a long edge can be
32
- * metres from every vertex of it — a sibling layer's one near-miss read 1.58 m to vertices and 0.009 m to
33
- * edges, an overstatement of 175-fold — so measuring vertices makes the boundary tolerance far stricter than
34
- * it reads, which is how a rendering difference gets reported as a conversion defect.
27
+ * The distance measures to the edge rather than to the nearest vertex. A point a centimeter from a long edge can be
28
+ * meters from every vertex. In one sibling-layer near-miss, vertex distance measured 1.58 m and edge distance
29
+ * measured 0.009 m. The vertex measurement overstated distance by 175 times. It would make the stated boundary
30
+ * tolerance stricter and report a rendering difference as a conversion defect.
35
31
  */
36
32
 
33
+ import { stringifyJSON } from "@mailwoman/core/json"
37
34
  import {
38
35
  nearestRingEdgeMetres,
39
36
  pointInEncodedRings,
@@ -43,6 +40,7 @@ import {
43
40
  type PolygonRings,
44
41
  } from "@mailwoman/spatial"
45
42
  import { DatabaseClient } from "@mailwoman/sqlite/client"
43
+ import type { PathBuilderLike } from "path-ts"
46
44
 
47
45
  import { ZoningLookup, ZoningReadingKind, type ZoningReading } from "#index"
48
46
  import { resolveRingRoles } from "#rings"
@@ -50,7 +48,8 @@ import type { ZoningDatabase } from "#schema"
50
48
  import type { GZTClient } from "#sdk/client"
51
49
 
52
50
  /**
53
- * One point, both verdicts, and whether they agree.
51
+ * Records one point and both verdicts.
52
+ * It also records whether they agree.
54
53
  */
55
54
  export interface AgreementRow {
56
55
  label: string
@@ -65,18 +64,23 @@ export interface AgreementRow {
65
64
  */
66
65
  serviceInside: boolean
67
66
  /**
68
- * The local code the SERVICE reports at the point, where it reports one. Compared verbatim against the artifact's,
69
- * because carrying the code verbatim is what this layer is for: two paths that agree on containment and disagree on
70
- * the code would be a silent vocabulary defect.
67
+ * The local code the service reports at the point, where it reports one.
68
+ *
69
+ * Compared verbatim against the artifact's, because carrying the code verbatim
70
+ * is what this layer is for: two paths that agree on containment and disagree
71
+ * on the code would be a silent vocabulary defect.
71
72
  */
72
73
  serviceLocalCode?: string
73
74
  outcome: "agree" | "disagree" | "boundary_tolerance"
74
75
  /**
75
- * Metres from the point to the nearest EDGE of any polygon the service returned nearby.
76
+ * Meters from the point to the nearest edge of any polygon the service returned nearby.
77
+ *
78
+ * Every row includes this distance.
79
+ * It separates a real defect from a difference caused by the two channels
80
+ * rendering the same edge differently.
76
81
  *
77
- * Carried on every row rather than only the tolerated ones, because it is what separates a real defect from the two
78
- * channels rendering the same edge differently — and a receipt that omits it forces a re-run. `undefined` means the
79
- * service returned no polygon at all near the point.
82
+ * A receipt without it forces a re-run.
83
+ * `undefined` means the service returned no polygon at all near the point.
80
84
  */
81
85
  nearestEdgeMetres?: number
82
86
  }
@@ -91,7 +95,8 @@ export interface OutsideRow {
91
95
  kind: string
92
96
  designations: number
93
97
  /**
94
- * True when the artifact answered `unknown` with no designation — the only acceptable reading here.
98
+ * True when the artifact answered `unknown` with no designation.
99
+ * The only acceptable reading here.
95
100
  */
96
101
  passed: boolean
97
102
  }
@@ -110,12 +115,18 @@ export interface VerifyZoningResult {
110
115
  }
111
116
 
112
117
  /**
113
- * Points this product's publication does not reach, named. Each is a place, not a bare pair of numbers: a coordinate a
114
- * reader cannot name is a coordinate nobody can check.
118
+ * Point identifiers for locations outside this product's publication area.
119
+ *
120
+ * Each is a place rather than a bare pair of numbers: a coordinate a reader a
121
+ * coordinate without a reference source cannot be checked.
122
+ *
123
+ * The check requires points from two populations.
124
+ * The Donegal points are the case this layer's coverage posture exists for.
125
+ *
126
+ * The Department has not published that authority's zoning.
127
+ * A builder that reads the absence as "unrestricted" would answer these points confidently.
115
128
  *
116
- * TWO POPULATIONS, AND BOTH ARE LOAD-BEARING. The Donegal points are the case this layer's coverage posture exists for
117
- * — the Department has not published that authority's zoning, and a builder that read absence as "unrestricted" would
118
- * answer them confidently. The Northern Irish points confirm the artifact is clipped to the Republic rather than to the
129
+ * The Northern Irish points confirm the artifact is clipped to the Republic rather than to the
119
130
  * island: zoning there is a different jurisdiction's instrument under a different planning act.
120
131
  */
121
132
  export const OUTSIDE_PUBLICATION_POINTS: ReadonlyArray<{ label: string; latitude: number; longitude: number }> = [
@@ -128,23 +139,28 @@ export const OUTSIDE_PUBLICATION_POINTS: ReadonlyArray<{ label: string; latitude
128
139
  ]
129
140
 
130
141
  /**
131
- * Half-width of the bounding box the service is asked for, in degrees. About 11 m at this latitude — wide enough that a
132
- * polygon containing the point is certainly returned, narrow enough that the response stays small.
142
+ * Half-width of the bounding box the service is asked for, in degrees.
143
+ *
144
+ * About 11 m at this latitude — wide enough that a polygon containing the point is
145
+ * certainly returned, narrow enough that the response stays small.
133
146
  */
134
147
  const PROBE_HALF_WIDTH_DEGREES = 0.0001
135
148
 
136
149
  /**
137
- * How close to a service-polygon edge a disagreement is attributed to the channels' differing coordinate precision
138
- * rather than to the conversion.
150
+ * How close to a service-polygon edge a disagreement is attributed to the channels'
151
+ * differing coordinate precision rather than to the conversion.
152
+ *
153
+ * Half a meter.
154
+ * The two channels render the same edge from the same source coordinates through different
155
+ * rounding, so a point between the two renderings lands on opposite sides.
139
156
  *
140
- * Half a metre. The two channels render the same edge from the same source coordinates through different rounding, so a
141
- * point between the two renderings lands on opposite sides; half a metre is far below any real zoning boundary and far
142
- * above the rounding difference.
157
+ * Half a meter is far below any real zoning boundary and far above the rounding difference.
143
158
  */
144
159
  const BOUNDARY_TOLERANCE_METRES = 0.5
145
160
 
146
161
  /**
147
- * One feature as the service publishes it — the only shape the comparison reads.
162
+ * One feature as the service publishes it.
163
+ * The only shape the comparison reads.
148
164
  */
149
165
  export interface ServiceFeature {
150
166
  properties?: Record<string, unknown>
@@ -152,31 +168,37 @@ export interface ServiceFeature {
152
168
  }
153
169
 
154
170
  /**
155
- * The ONE call the verification makes against the service: the features it publishes near a point.
171
+ * The one call the verification makes against the service: the features it publishes near a point.
172
+ *
173
+ * The function exposes only the service read.
174
+ * This keeps the check's own logic testable.
156
175
  *
157
- * A function rather than the client, and that is what makes the check's own logic testable. The comparison's value is
158
- * that it decides which of three outcomes a point gets; expressed against an HTTP client it could only ever be watched
159
- * on a live run, and a scripted reader lets those decisions be pinned. {@link createServiceReader} builds the real
160
- * one.
176
+ * The comparison's value is that it decides which of three outcomes a point gets.
177
+ *
178
+ * An HTTP client would let tests observe these decisions only during a live run.
179
+ * A scripted reader pins the decisions. {@link createServiceReader} builds the real reader.
161
180
  */
162
181
  export type ServiceFeatureReader = (latitude: number, longitude: number) => Promise<ServiceFeature[]>
163
182
 
164
183
  /**
165
184
  * The reader the live check uses: a bounding-box query against the Department's own service.
166
185
  *
167
- * The service answers a BOX, not a point, so this returns what it published nearby and the containment decision is made
168
- * in {@link readServiceContainment} against those rings — comparing the artifact's verdict against a bare "the service
169
- * returned something here" would pass on any polygon within eleven metres.
186
+ * The service answers a BOX rather than a point, so this returns what it published nearby
187
+ * and the containment decision is made in {@link readServiceContainment} against
188
+ * those rings — comparing the artifact's verdict against a bare "the service returned
189
+ * something here" would pass on any polygon within eleven meters.
170
190
  */
171
191
  export function createServiceReader(client: Pick<GZTClient, "readFeaturesNear">): ServiceFeatureReader {
172
192
  return async (latitude, longitude) => client.readFeaturesNear(latitude, longitude, PROBE_HALF_WIDTH_DEGREES)
173
193
  }
174
194
 
175
195
  export interface VerifyZoningOptions {
176
- databasePath: string
196
+ databasePath: PathBuilderLike
177
197
  readServiceFeatures: ServiceFeatureReader
178
198
  /**
179
- * Points to re-ask the service about. A caller samples them from the artifact — see {@link sampleAgreementPoints}.
199
+ * Points to re-ask the service about.
200
+ *
201
+ * A caller samples them from the artifact — see {@link sampleAgreementPoints}.
180
202
  */
181
203
  points: ReadonlyArray<{ label: string; latitude: number; longitude: number; localCode?: string }>
182
204
  outsidePoints?: ReadonlyArray<{ label: string; latitude: number; longitude: number }>
@@ -248,8 +270,9 @@ export async function verifyZoningDatabase(options: VerifyZoningOptions): Promis
248
270
  }
249
271
 
250
272
  /**
251
- * Whether the SERVICE's own geometry contains the point, decided here with the same ring-role resolution and the same
252
- * even-odd rule the artifact's reader uses — so what is compared is a verdict against a verdict.
273
+ * Whether the service's own geometry contains the point, decided here with the same
274
+ * ring-role resolution and the same even-odd rule the artifact's reader uses.
275
+ * So what is compared is a verdict against a verdict.
253
276
  */
254
277
  async function readServiceContainment(
255
278
  readServiceFeatures: ServiceFeatureReader,
@@ -278,14 +301,15 @@ async function readServiceContainment(
278
301
  nearest = distance
279
302
  }
280
303
 
281
- // THE SERVICE'S RINGS GET THE SAME ROLE RESOLUTION THE INGEST GAVE THE ARCHIVE'S. The publisher uses one convention on
282
- // both channels, so reading this side as nested GeoJSON would answer "inside" for a point in a hole and report the
283
- // artifact as wrong at exactly the locations the hole handling exists for.
304
+ // the service'S rings GET the same role resolution the ingest gave the archive'S.
305
+ // The publisher uses one convention on both channels, so reading this side as nested
306
+ // GeoJSON would answer "inside" for a point in a hole and report the artifact as
307
+ // wrong at exactly the locations the hole handling exists for.
284
308
  const resolved = resolveRingRoles(raw, `service feature near ${latitude},${longitude}`)
285
309
 
286
- // ENCODED AND RE-READ RATHER THAN RAY-CAST DIRECTLY, deliberately: the artifact answers through
287
- // `pointInEncodedRings`, and running the service's geometry through a different predicate would compare two answers
288
- // that were never asked the same question.
310
+ // encoded and RE-read rather than RAY-cast directly, deliberately: the artifact answers
311
+ // through `pointInEncodedRings`, and running the service's geometry through a different
312
+ // predicate would compare two answers that were never asked the same question.
289
313
  if (pointInEncodedRings(encodeRings(resolved.polygons), longitude, latitude)) {
290
314
  inside = true
291
315
 
@@ -305,24 +329,27 @@ async function readServiceContainment(
305
329
  }
306
330
 
307
331
  /**
308
- * Draw a reproducible sample of points from the artifact — interior points of stored polygons, spread across
309
- * authorities.
332
+ * Draw a reproducible sample of points from the artifact — interior points of
333
+ * stored polygons, spread across authorities.
310
334
  *
311
- * SPREAD ACROSS AUTHORITIES RATHER THAN DRAWN FROM ONE, because 30 local authorities publish 581 distinct local codes
312
- * between them and a sample from one would verify one authority's conversion while reporting on all of them. The stride
313
- * discipline — keys chosen before any geometry is read, deterministic rather than random — is
314
- * `strideSampleInteriorPoints`'s.
335
+ * Spread across authorities rather than drawn from one, because 30 local authorities
336
+ * publish 581 distinct local codes between them and a sample from one would verify
337
+ * one authority's conversion while reporting on all of them.
338
+ * The stride discipline — keys chosen before any geometry is read, deterministic
339
+ * rather than random — is `strideSampleInteriorPoints`'s.
315
340
  */
316
341
  export function sampleAgreementPoints(
317
- databasePath: string,
342
+ databasePath: PathBuilderLike,
318
343
  options: { count?: number } = {}
319
344
  ): Array<{ label: string; latitude: number; longitude: number; localCode: string }> {
320
345
  const count = options.count ?? 48
321
346
  using database = new DatabaseClient<ZoningDatabase>(databasePath, { readOnly: true })
322
347
 
323
- // ORDERED BY THE AUTHORITY FIRST, so a stride walks across the 30 of them rather than down one. A stride over
324
- // `area_id` alone would follow the publisher's own feature numbering, which is grouped by authority — and would draw
325
- // every sample from whichever authorities happen to sit on the stride.
348
+ // Sort by authority so the stride samples across the 30 authorities
349
+ // instead of sampling one authority repeatedly.
350
+ // A stride over `area_id` by itself would follow the publisher's feature numbering.
351
+ // That numbering is grouped by authority, so the stride would select only the
352
+ // authorities that fall on its positions.
326
353
  const areaIDs = (
327
354
  database.prepare("SELECT area_id FROM zoning_area ORDER BY jurisdiction_id, area_id").all() as Array<{
328
355
  area_id: string
@@ -349,7 +376,7 @@ export function sampleAgreementPoints(
349
376
  | undefined,
350
377
  gridSteps: 17,
351
378
  toPoint: (area, interior) => ({
352
- label: `${area.jurisdiction_id} ${JSON.stringify(area.local_code)} polygon ${area.area_id}`,
379
+ label: `${area.jurisdiction_id} ${stringifyJSON(area.local_code)} polygon ${area.area_id}`,
353
380
  localCode: area.local_code,
354
381
  ...interior,
355
382
  }),
@@ -1,78 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Acquire the Department's bulk GeoJSON export — a 247,452,342-byte file streamed to disk.
7
- *
8
- * THIS IS A FILE TRANSFER, NOT AN API REQUEST, AND IT KEEPS RAW `fetch` ON PURPOSE. The repo's rule sends
9
- * HTTP clients through `@mailwoman/core/api`'s `APIClient`, and the rule draws its line at what that class
10
- * is for: pacing, bounded retry, response caching and error mapping over small bodies and repeated calls.
11
- * None of it applies here. Caching a 247 MB body through a JSON-validating disk cache would write a second,
12
- * unreadable copy of a file already on disk; there is nothing to pace, because this runs once per product
13
- * vintage; and axios buffers any non-stream response type in memory. `packages/osm/lib/sdk/fetch.ts`,
14
- * `packages/tiger/lib/sdk/download.ts`, `packages/flood/lib/sdk/download.ts` and `packages/coastal/lib/sdk/download.ts`
15
- * are the existing transfers that say the same thing in the same place. The JOB that produces this URL, and
16
- * every other metadata read around it, DO go through `APIClient` — see `client.ts`.
17
- *
18
- * THE RESULT URL REDIRECTS AND THE FETCH MUST FOLLOW IT. The Hub download job answers
19
- * `{"status":"Completed","resultUrl":…}`; the result URL itself 302s to the generated file. Node's `fetch`
20
- * follows redirects by default, and the option is passed explicitly anyway — a transfer that stopped at the
21
- * redirect would write a short body to disk and report a successful download.
22
- *
23
- * FRESHNESS IS THE ITEM'S OWN MODIFIED DATE, NEVER A LENGTH PROBE. The cache is keyed on the vintage the
24
- * item declares, so a re-run against the same vintage never re-transfers and a new vintage never overwrites
25
- * the old one in place.
26
- */
27
-
28
- import { tryStat } from "@mailwoman/core/fs/readers"
29
- import { makeDirectories } from "@mailwoman/core/fs/writers"
30
- import { streamToDisk } from "@mailwoman/core/utils"
31
- import { join } from "path-ts"
32
-
33
- /**
34
- * The file name one vintage's export is kept under.
35
- */
36
- export const GZT_EXPORT_FILE = "gzt-current-plan.geojson"
37
-
38
- export interface DownloadZoningExportOptions {
39
- /**
40
- * The Hub job's `resultUrl`, read rather than assembled — it carries a generated file id with no relationship to the
41
- * item id, so a hard-coded URL survives a republish by pointing at a file that is no longer the product.
42
- */
43
- url: string
44
- /**
45
- * The product vintage the cache is keyed on.
46
- */
47
- vintage: string
48
- cacheRoot: string
49
- onProgress?: (message: string) => void
50
- }
51
-
52
- /**
53
- * Download the bulk export for one product vintage, returning the path of the GeoJSON file.
54
- *
55
- * Downloads to a `.part` file and renames only on a clean finish, so an interrupted transfer never presents as a
56
- * complete export — the same discipline the database build uses, for the same reason.
57
- */
58
- export async function downloadZoningExport(options: DownloadZoningExportOptions): Promise<string> {
59
- const vintageDir = join(options.cacheRoot, options.vintage)
60
- const exportPath = join(vintageDir, GZT_EXPORT_FILE)
61
-
62
- if (await tryStat(exportPath)) {
63
- options.onProgress?.(`export for ${options.vintage} already downloaded`)
64
-
65
- return exportPath
66
- }
67
-
68
- await makeDirectories(vintageDir)
69
-
70
- await streamToDisk({
71
- url: options.url,
72
- destination: exportPath,
73
- context: "zoning download",
74
- ...(options.onProgress ? { onProgress: options.onProgress } : {}),
75
- })
76
-
77
- return exportPath
78
- }
package/lib/sdk/index.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- * @file The acquisition + build surface for the Irish zoning layer. The READER is the package root.
6
- */
7
-
8
- export * from "#sdk/build-zoning"
9
- export * from "#sdk/cells"
10
- export * from "#sdk/client"
11
- export * from "#sdk/download"
12
- export * from "#sdk/ingest"
13
- export * from "#sdk/ingest-chunk"
14
- export * from "#sdk/measure-resolutions"
15
- export * from "#sdk/verify"