@mailwoman/zoning 9.2.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 (82) hide show
  1. package/README.md +315 -0
  2. package/lib/index.ts +616 -0
  3. package/lib/ring-roles.ts +233 -0
  4. package/lib/rings.ts +34 -0
  5. package/lib/schema.ts +449 -0
  6. package/lib/scripts/ingest-chunk.ts +41 -0
  7. package/lib/sdk/build-zoning.ts +790 -0
  8. package/lib/sdk/cells.ts +276 -0
  9. package/lib/sdk/client.ts +335 -0
  10. package/lib/sdk/download.ts +78 -0
  11. package/lib/sdk/index.ts +15 -0
  12. package/lib/sdk/ingest-chunk.ts +360 -0
  13. package/lib/sdk/ingest.ts +402 -0
  14. package/lib/sdk/measure-resolutions.ts +100 -0
  15. package/lib/sdk/verify.ts +350 -0
  16. package/lib/test-kit.ts +207 -0
  17. package/lib/vocabulary.ts +342 -0
  18. package/out/index.d.ts +257 -0
  19. package/out/index.d.ts.map +1 -0
  20. package/out/index.js +325 -0
  21. package/out/index.js.map +1 -0
  22. package/out/ring-roles.d.ts +88 -0
  23. package/out/ring-roles.d.ts.map +1 -0
  24. package/out/ring-roles.js +151 -0
  25. package/out/ring-roles.js.map +1 -0
  26. package/out/rings.d.ts +22 -0
  27. package/out/rings.d.ts.map +1 -0
  28. package/out/rings.js +22 -0
  29. package/out/rings.js.map +1 -0
  30. package/out/schema.d.ts +325 -0
  31. package/out/schema.d.ts.map +1 -0
  32. package/out/schema.js +186 -0
  33. package/out/schema.js.map +1 -0
  34. package/out/scripts/ingest-chunk.d.ts +11 -0
  35. package/out/scripts/ingest-chunk.d.ts.map +1 -0
  36. package/out/scripts/ingest-chunk.js +36 -0
  37. package/out/scripts/ingest-chunk.js.map +1 -0
  38. package/out/sdk/build-zoning.d.ts +283 -0
  39. package/out/sdk/build-zoning.d.ts.map +1 -0
  40. package/out/sdk/build-zoning.js +462 -0
  41. package/out/sdk/build-zoning.js.map +1 -0
  42. package/out/sdk/cells.d.ts +137 -0
  43. package/out/sdk/cells.d.ts.map +1 -0
  44. package/out/sdk/cells.js +176 -0
  45. package/out/sdk/cells.js.map +1 -0
  46. package/out/sdk/client.d.ts +151 -0
  47. package/out/sdk/client.d.ts.map +1 -0
  48. package/out/sdk/client.js +239 -0
  49. package/out/sdk/client.js.map +1 -0
  50. package/out/sdk/download.d.ts +51 -0
  51. package/out/sdk/download.d.ts.map +1 -0
  52. package/out/sdk/download.js +57 -0
  53. package/out/sdk/download.js.map +1 -0
  54. package/out/sdk/index.d.ts +15 -0
  55. package/out/sdk/index.d.ts.map +1 -0
  56. package/out/sdk/index.js +15 -0
  57. package/out/sdk/index.js.map +1 -0
  58. package/out/sdk/ingest-chunk.d.ts +130 -0
  59. package/out/sdk/ingest-chunk.d.ts.map +1 -0
  60. package/out/sdk/ingest-chunk.js +206 -0
  61. package/out/sdk/ingest-chunk.js.map +1 -0
  62. package/out/sdk/ingest.d.ts +191 -0
  63. package/out/sdk/ingest.d.ts.map +1 -0
  64. package/out/sdk/ingest.js +238 -0
  65. package/out/sdk/ingest.js.map +1 -0
  66. package/out/sdk/measure-resolutions.d.ts +51 -0
  67. package/out/sdk/measure-resolutions.d.ts.map +1 -0
  68. package/out/sdk/measure-resolutions.js +64 -0
  69. package/out/sdk/measure-resolutions.js.map +1 -0
  70. package/out/sdk/verify.d.ts +176 -0
  71. package/out/sdk/verify.d.ts.map +1 -0
  72. package/out/sdk/verify.js +202 -0
  73. package/out/sdk/verify.js.map +1 -0
  74. package/out/test-kit.d.ts +97 -0
  75. package/out/test-kit.d.ts.map +1 -0
  76. package/out/test-kit.js +180 -0
  77. package/out/test-kit.js.map +1 -0
  78. package/out/vocabulary.d.ts +221 -0
  79. package/out/vocabulary.d.ts.map +1 -0
  80. package/out/vocabulary.js +299 -0
  81. package/out/vocabulary.js.map +1 -0
  82. package/package.json +245 -0
package/lib/schema.ts ADDED
@@ -0,0 +1,449 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Typed schema for `zoning-ireland.db` — the two-tier polygon layer: the authority's unsimplified rings as
7
+ * the truth table, an H3 cell table above them as the summary, the plan and jurisdiction a zone belongs to,
8
+ * the published vocabularies, and the layer-contract tables from `@mailwoman/core/layers`.
9
+ *
10
+ * THE LOCAL CODE IS `NOT NULL` AND THE CROSSWALK IS NULLABLE, WHICH IS THE VOCABULARY DECISION AS A
11
+ * CONSTRAINT. A source with no crosswalk produces a complete row; a source with no local code does not. The
12
+ * Department's own item description is what this transcribes: its national scheme "complements (rather than
13
+ * replaces) the existing statutory zoning used for each individual plan".
14
+ *
15
+ * `provenance_grade` IS A COLUMN WITH A `CHECK`, NOT A CONVENTION. `NOT NULL` alone accepts `''`, and a
16
+ * blank matches neither half of every read that splits on grade — so the constraint refuses a blank as well
17
+ * as an unknown value. This is `packages/filer`'s discipline applied unchanged, and the reason it is
18
+ * compulsory here is licensing as much as epistemics: an observed land-use layer is ODbL, and merging one
19
+ * of its rows into this table would relicense the table.
20
+ *
21
+ * `signed_area_m2` IS THE INGEST'S OWN RECEIPT AND ITS SIGN IS LOAD-BEARING. The service encodes hole roles
22
+ * by ring orientation with clockwise as the exterior, so a correctly-read feature stores a POSITIVE signed
23
+ * sum; the national total of those sums is what the build compares against the Department's own
24
+ * `Shape__Area` statistic. Read with the holes it is 5,444.5 km²; read without them, 5,666.6 km².
25
+ *
26
+ * `WITHOUT ROWID` ON THE CELL TABLE AND NEVER ON THE GEOMETRY TABLE. Small fixed-width rows probed by their
27
+ * exact primary key belong in the B-tree; a row carrying a geometry blob does not — clustering it into the
28
+ * B-tree makes every index page a geometry page.
29
+ *
30
+ * THE WHOLE-CELL SET IS COMPACTED PER FEATURE, SO IT IS MIXED-RESOLUTION. A row therefore carries its own
31
+ * `resolution`, and a probe walks `cellToParent` from the index resolution up to the coarsest resolution
32
+ * present. `layer_coverage` is NOT compacted and stays single-resolution, because `recoverShortCellResolution`
33
+ * recovers one resolution from the stored cells and throws on a table that mixes them.
34
+ */
35
+
36
+ import type { LayerContractDatabase } from "@mailwoman/core/layers"
37
+ import { sql, type Kysely } from "kysely"
38
+
39
+ /**
40
+ * Whether an H3 cell lies wholly inside a zoning polygon, or is crossed by its boundary.
41
+ */
42
+ export const ZoningCellContainment = {
43
+ /**
44
+ * Every point in the cell is inside the zone. Answered from the index alone, with no geometry read.
45
+ */
46
+ Whole: "whole",
47
+ /**
48
+ * The zone boundary crosses the cell. The index has narrowed the candidate polygons; the point test decides.
49
+ */
50
+ Partial: "partial",
51
+ } as const
52
+
53
+ export type ZoningCellContainment = (typeof ZoningCellContainment)[keyof typeof ZoningCellContainment]
54
+
55
+ /**
56
+ * One authority zoning polygon, verbatim. A plain rowid table: it holds a geometry blob, which is the one shape
57
+ * `WITHOUT ROWID` hurts.
58
+ */
59
+ export interface ZoningAreaTable {
60
+ /**
61
+ * The authority's own feature id, as published. Unique across the product — measured, `OBJECTID` runs 1 to 85,330
62
+ * with no repeat — so it needs no scoping prefix, and a prefix would put this package's key into a column that claims
63
+ * to be the publisher's.
64
+ */
65
+ area_id: string
66
+ /**
67
+ * The authority that adopted the plan. FK to `zoning_jurisdiction`.
68
+ */
69
+ jurisdiction_id: string
70
+ /**
71
+ * The plan this zone belongs to. FK to `zoning_plan`. A zone without a plan is not a claim: it exists inside a named
72
+ * Development Plan or Local Area Plan with a stated validity window, and a layer that dropped the plan and kept the
73
+ * zone would be answering a question no authority asked.
74
+ */
75
+ plan_id: string
76
+ /**
77
+ * `ZONE_ORIG` — THE AUTHORITY'S OWN ZONE CODE, VERBATIM, in its own spelling including case and trailing space.
78
+ * Compared case-insensitively where it must be compared; never stored normalized.
79
+ */
80
+ local_code: string
81
+ /**
82
+ * `ZONE_DESC` — the authority's own description of that code.
83
+ */
84
+ local_description: string | null
85
+ /**
86
+ * `ZONE_LINK` — the authority's own link to the plan text. A live host, unlike the crosswalk's.
87
+ */
88
+ local_code_url: string | null
89
+ /**
90
+ * `ZONE_GZT` — the Department's national generic type, BESIDE the local code and never instead of it. NULL where a
91
+ * publisher ships no crosswalk.
92
+ */
93
+ crosswalk_code: string | null
94
+ /**
95
+ * Which crosswalk `crosswalk_code` belongs to. NULL with the above.
96
+ */
97
+ crosswalk_scheme: string | null
98
+ /**
99
+ * `GZT_DESC` — the Department's own description of the generic type, as published on the row.
100
+ */
101
+ crosswalk_description: string | null
102
+ /**
103
+ * `SZO` — a coarser code from the SAME authority, carried as published rather than derived.
104
+ */
105
+ crosswalk_rollup: string | null
106
+ /**
107
+ * One of {@link ProvenanceGrade}. `NOT NULL` with a `CHECK` that refuses a blank.
108
+ */
109
+ provenance_grade: string
110
+ min_lat: number
111
+ min_lon: number
112
+ max_lat: number
113
+ max_lon: number
114
+ /**
115
+ * How many rings the source published for this feature — with `signed_area_m2`, the ingest's own receipt that the
116
+ * orientation was read rather than assumed.
117
+ */
118
+ ring_count: number
119
+ /**
120
+ * The signed ring sum, in square metres, POSITIVE under this service's clockwise-exterior convention.
121
+ */
122
+ signed_area_m2: number
123
+ /**
124
+ * The authority's ring coordinates, UNSIMPLIFIED, with hole roles RESOLVED — see `ring-roles.ts` for the resolution
125
+ * and `rings.ts` for the layout and the point test.
126
+ */
127
+ rings: Uint8Array
128
+ }
129
+
130
+ /**
131
+ * The plan a zone lives inside.
132
+ */
133
+ export interface ZoningPlanTable {
134
+ plan_id: string
135
+ jurisdiction_id: string
136
+ /**
137
+ * `PLAN_NAME`, verbatim — "Fingal Development Plan 2023-2029".
138
+ */
139
+ plan_name: string
140
+ /**
141
+ * `PLAN_LEVEL` — the Department's own vocabulary: `DP`, `LAP` or `SDZ`.
142
+ */
143
+ plan_level: string
144
+ valid_from: string | null
145
+ /**
146
+ * `PLAN_TO`, the plan's own stated end.
147
+ */
148
+ valid_to: string | null
149
+ /**
150
+ * `CURRENT_PLAN`, carried as published.
151
+ *
152
+ * IT DOES NOT MEAN "IN FORCE TODAY". Every row of the Current layer carries `1`, which the domain defines as `Current
153
+ * plan` against `Expired and not replaced` and `Expired and replaced` — so it means "not superseded". Whether the
154
+ * plan's own window has closed is `valid_to`, and it is a separate fact.
155
+ */
156
+ current_plan: number
157
+ }
158
+
159
+ /**
160
+ * Who adopted the plan.
161
+ */
162
+ export interface ZoningJurisdictionTable {
163
+ jurisdiction_id: string
164
+ name: string
165
+ /**
166
+ * The publisher's own code, verbatim. `Fl` for Fingal against `CL`, `CO`, `DU` for the rest — DO NOT REPAIR.
167
+ */
168
+ source_code: string
169
+ country: string
170
+ }
171
+
172
+ /**
173
+ * A publisher's declared vocabulary, as shipped, per scheme — plus the values the DATA uses that the publisher never
174
+ * declared.
175
+ */
176
+ export interface ZoningVocabularyTable {
177
+ /**
178
+ * `IE-GZT`, `IE-SZO`, `IE-PLAN-LEVEL`, or `IE-LOCAL:<authority code>`.
179
+ */
180
+ scheme: string
181
+ code: string
182
+ /**
183
+ * The publisher's own words. For an observed-but-undeclared code this is the description the data carries on its
184
+ * rows, or the code itself where the data carries none — never a label this package wrote.
185
+ */
186
+ label: string
187
+ /**
188
+ * The publisher's own definition, where it is retrievable.
189
+ */
190
+ definition: string | null
191
+ /**
192
+ * NULL for the Irish generic types. Every one of the 85,330 rows links its definition to `viewer.myplan.ie`, which
193
+ * has no A or AAAA record, and three candidate replacements on the live host answer HTTP 404 — so the definitions
194
+ * behind the 54 code-to-label pairs were not retrievable and this column is not filled in with a plausible one.
195
+ */
196
+ definition_url: string | null
197
+ /**
198
+ * `1` where the publisher DECLARES this code in its own domain, `0` where the code appears only in the data.
199
+ *
200
+ * FOLDING THE TWO WOULD EITHER HIDE A SOURCE-SCHEMA CHANGE OR INVENT A DECLARATION. Ireland declares 54 generic types
201
+ * and its data uses 55: `N/A` appears on 4 rows and in no domain.
202
+ */
203
+ declared: number
204
+ /**
205
+ * How many rows of this artifact carry the code. A census a reader checks a closed domain against, rather than a
206
+ * claim about the world.
207
+ */
208
+ observed_rows: number
209
+ }
210
+
211
+ /**
212
+ * A publisher's OWN mapping between two schemes, where it publishes one AS A TABLE.
213
+ *
214
+ * EMPTY FOR IRELAND, AND THE EMPTINESS IS A MEASUREMENT. The Department's generic type is assigned PER POLYGON, not per
215
+ * code: 52 of the 795 (authority, local code) pairs take more than one generic type inside a single authority — Cork
216
+ * County Council's `Special Policy Area` takes 14 and its `Green Infrastructure` 12 — so the mapping is not a function
217
+ * of the pair and no edge table can carry it without inventing one. The mapping lives on `zoning_area`, per row, where
218
+ * the Department put it. {@linkcode assertCrosswalkIsNotATable} refuses a build that would write edges while such a
219
+ * pair exists.
220
+ */
221
+ export interface ZoningCrosswalkEdgeTable {
222
+ from_scheme: string
223
+ from_code: string
224
+ to_scheme: string
225
+ to_code: string
226
+ /**
227
+ * The body that authored THIS edge. Never us.
228
+ */
229
+ authored_by: string
230
+ }
231
+
232
+ /**
233
+ * Per (cell, polygon): does the polygon cover the whole cell, or only part of it?
234
+ *
235
+ * KEYED ON THE POLYGON RATHER THAN ON A CODE, because a zoning answer IS the polygon — its local code, its plan and its
236
+ * authority are per feature, and two authorities' plans can name the same code for different things.
237
+ */
238
+ export interface ZoningCellTable {
239
+ /**
240
+ * 48-bit short H3 cell. Mixed-resolution: `whole` rows are compacted parent-ward, `partial` rows stay at the
241
+ * resolution the feature was indexed at.
242
+ */
243
+ h3_cell: number
244
+ /**
245
+ * The resolution this row's cell was captured at. A short cell does not name its own resolution, and a table that
246
+ * mixes them cannot be probed without it.
247
+ */
248
+ resolution: number
249
+ area_id: string
250
+ /**
251
+ * One of {@link ZoningCellContainment}.
252
+ */
253
+ containment: string
254
+ }
255
+
256
+ /**
257
+ * The authority's own statement of what it MAPPED — one row per statement, never derived from the zoning polygons.
258
+ *
259
+ * EMPTY IN THIS EDITION, AND ITS EMPTINESS IS THE CLAIM. The Department states "Awaiting data for some Local
260
+ * Authorities
261
+ *
262
+ * - Please see map viewer for coverage details" and publishes that detail only inside a map application, so there is no
263
+ * footprint to record and `layer_coverage` carries `basis = source_present`. Donegal County Council's absence — the
264
+ * one local authority of 31 missing from the layer — was recovered by measuring `LA_CODE`, not read from a
265
+ * statement.
266
+ *
267
+ * Deriving a footprint from the union of the zoning polygons is forbidden: the union of zoned areas is not the area the
268
+ * authority examined, and the difference is the whole content of a negative answer. One authority's drafting convention
269
+ * moves the national zoned-area figure by 41% on its own — Meath County Council zones its entire rural remainder as one
270
+ * 2,232 km² polygon, against 32.5 km² for the next largest in the country — so the union is not even a stable shape.
271
+ */
272
+ export interface ZoningMappedExtentTable {
273
+ extent_id: string
274
+ source: string
275
+ statement: string
276
+ statement_url: string
277
+ effective_date: string | null
278
+ min_lat: number
279
+ min_lon: number
280
+ max_lat: number
281
+ max_lon: number
282
+ }
283
+
284
+ /**
285
+ * Pass to `new DatabaseClient<ZoningDatabase>(...)`.
286
+ */
287
+ export interface ZoningDatabase extends LayerContractDatabase {
288
+ zoning_area: ZoningAreaTable
289
+ zoning_plan: ZoningPlanTable
290
+ zoning_jurisdiction: ZoningJurisdictionTable
291
+ zoning_vocabulary: ZoningVocabularyTable
292
+ zoning_crosswalk_edge: ZoningCrosswalkEdgeTable
293
+ zoning_cell: ZoningCellTable
294
+ zoning_mapped_extent: ZoningMappedExtentTable
295
+ }
296
+
297
+ /**
298
+ * The slice of a Kysely handle the DDL touches. Same reasoning as `LayerContractHandle`: Kysely is invariant in its
299
+ * schema parameter, so naming only the members these functions call lets a caller pass its own wider handle.
300
+ */
301
+ export type ZoningSchemaHandle = Pick<Kysely<ZoningDatabase>, "schema">
302
+
303
+ /**
304
+ * Create `zoning_area`. A PLAIN rowid table on purpose — the `rings` blob is exactly the payload `WITHOUT ROWID`
305
+ * penalizes.
306
+ */
307
+ export async function createZoningAreaTable(db: ZoningSchemaHandle): Promise<void> {
308
+ await db.schema
309
+ .createTable("zoning_area")
310
+ .addColumn("area_id", "text", (c) => c.primaryKey())
311
+ .addColumn("jurisdiction_id", "text", (c) => c.notNull())
312
+ .addColumn("plan_id", "text", (c) => c.notNull())
313
+ .addColumn("local_code", "text", (c) => c.notNull())
314
+ .addColumn("local_description", "text")
315
+ .addColumn("local_code_url", "text")
316
+ .addColumn("crosswalk_code", "text")
317
+ .addColumn("crosswalk_scheme", "text")
318
+ .addColumn("crosswalk_description", "text")
319
+ .addColumn("crosswalk_rollup", "text")
320
+ .addColumn("provenance_grade", "text", (c) => c.notNull())
321
+ .addColumn("min_lat", "real", (c) => c.notNull())
322
+ .addColumn("min_lon", "real", (c) => c.notNull())
323
+ .addColumn("max_lat", "real", (c) => c.notNull())
324
+ .addColumn("max_lon", "real", (c) => c.notNull())
325
+ .addColumn("ring_count", "integer", (c) => c.notNull())
326
+ .addColumn("signed_area_m2", "real", (c) => c.notNull())
327
+ .addColumn("rings", "blob", (c) => c.notNull())
328
+ // ONE GRADE PER CLAIM, AND A BLANK IS NOT ONE. `NOT NULL` alone accepts `''`, which matches neither half of every
329
+ // read that splits on grade — so the value set and the blank are refused separately, and the second half is the one
330
+ // a schema without it loses.
331
+ .addCheckConstraint(
332
+ "zoning_area_provenance_grade_declared",
333
+ sql`provenance_grade in ('authoritative', 'inferred') and trim(provenance_grade) != ''`
334
+ )
335
+ // The local code is what this layer exists to repeat, so an empty one is refused at the storage layer rather than
336
+ // only at the ingest: a blank would read as a zone the authority named nothing.
337
+ .addCheckConstraint("zoning_area_local_code_not_blank", sql`trim(local_code) != ''`)
338
+ .execute()
339
+ }
340
+
341
+ /**
342
+ * Create `zoning_plan`.
343
+ */
344
+ export async function createZoningPlanTable(db: ZoningSchemaHandle): Promise<void> {
345
+ await db.schema
346
+ .createTable("zoning_plan")
347
+ .addColumn("plan_id", "text", (c) => c.primaryKey())
348
+ .addColumn("jurisdiction_id", "text", (c) => c.notNull())
349
+ .addColumn("plan_name", "text", (c) => c.notNull())
350
+ .addColumn("plan_level", "text", (c) => c.notNull())
351
+ .addColumn("valid_from", "text")
352
+ .addColumn("valid_to", "text")
353
+ .addColumn("current_plan", "integer", (c) => c.notNull())
354
+ .execute()
355
+ }
356
+
357
+ /**
358
+ * Create `zoning_jurisdiction`.
359
+ */
360
+ export async function createZoningJurisdictionTable(db: ZoningSchemaHandle): Promise<void> {
361
+ await db.schema
362
+ .createTable("zoning_jurisdiction")
363
+ .addColumn("jurisdiction_id", "text", (c) => c.primaryKey())
364
+ .addColumn("name", "text", (c) => c.notNull())
365
+ .addColumn("source_code", "text", (c) => c.notNull())
366
+ .addColumn("country", "text", (c) => c.notNull())
367
+ .execute()
368
+ }
369
+
370
+ /**
371
+ * Create `zoning_vocabulary`.
372
+ */
373
+ export async function createZoningVocabularyTable(db: ZoningSchemaHandle): Promise<void> {
374
+ await db.schema
375
+ .createTable("zoning_vocabulary")
376
+ .addColumn("scheme", "text", (c) => c.notNull())
377
+ .addColumn("code", "text", (c) => c.notNull())
378
+ .addColumn("label", "text", (c) => c.notNull())
379
+ .addColumn("definition", "text")
380
+ .addColumn("definition_url", "text")
381
+ .addColumn("declared", "integer", (c) => c.notNull())
382
+ .addColumn("observed_rows", "integer", (c) => c.notNull())
383
+ .addPrimaryKeyConstraint("zoning_vocabulary_pk", ["scheme", "code"])
384
+ .execute()
385
+ }
386
+
387
+ /**
388
+ * Create `zoning_crosswalk_edge`. Created empty for Ireland — see the interface's docstring.
389
+ */
390
+ export async function createZoningCrosswalkEdgeTable(db: ZoningSchemaHandle): Promise<void> {
391
+ await db.schema
392
+ .createTable("zoning_crosswalk_edge")
393
+ .addColumn("from_scheme", "text", (c) => c.notNull())
394
+ .addColumn("from_code", "text", (c) => c.notNull())
395
+ .addColumn("to_scheme", "text", (c) => c.notNull())
396
+ .addColumn("to_code", "text", (c) => c.notNull())
397
+ .addColumn("authored_by", "text", (c) => c.notNull())
398
+ .addPrimaryKeyConstraint("zoning_crosswalk_edge_pk", ["from_scheme", "from_code", "to_scheme", "to_code"])
399
+ .execute()
400
+ }
401
+
402
+ /**
403
+ * Create `zoning_cell` — the summary tier. Small fixed-width rows probed by their exact primary key, which is the
404
+ * `WITHOUT ROWID` shape.
405
+ */
406
+ export async function createZoningCellTable(db: ZoningSchemaHandle): Promise<void> {
407
+ await db.schema
408
+ .createTable("zoning_cell")
409
+ .addColumn("h3_cell", "integer", (c) => c.notNull())
410
+ .addColumn("resolution", "integer", (c) => c.notNull())
411
+ .addColumn("area_id", "text", (c) => c.notNull())
412
+ .addColumn("containment", "text", (c) => c.notNull())
413
+ .addPrimaryKeyConstraint("zoning_cell_pk", ["h3_cell", "area_id"])
414
+ // `WITHOUT ROWID` has no first-class builder; the raw modifier is the idiomatic fallback.
415
+ .modifyEnd(sql`without rowid`)
416
+ .execute()
417
+ }
418
+
419
+ /**
420
+ * Create `zoning_mapped_extent`. Created empty, and the reader refuses a stronger coverage basis while it stays that
421
+ * way — see the interface's docstring.
422
+ */
423
+ export async function createZoningMappedExtentTable(db: ZoningSchemaHandle): Promise<void> {
424
+ await db.schema
425
+ .createTable("zoning_mapped_extent")
426
+ .addColumn("extent_id", "text", (c) => c.primaryKey())
427
+ .addColumn("source", "text", (c) => c.notNull())
428
+ .addColumn("statement", "text", (c) => c.notNull())
429
+ .addColumn("statement_url", "text", (c) => c.notNull())
430
+ .addColumn("effective_date", "text")
431
+ .addColumn("min_lat", "real", (c) => c.notNull())
432
+ .addColumn("min_lon", "real", (c) => c.notNull())
433
+ .addColumn("max_lat", "real", (c) => c.notNull())
434
+ .addColumn("max_lon", "real", (c) => c.notNull())
435
+ .execute()
436
+ }
437
+
438
+ /**
439
+ * Every domain table this layer owns, in dependency order.
440
+ */
441
+ export async function createZoningTables(db: ZoningSchemaHandle): Promise<void> {
442
+ await createZoningJurisdictionTable(db)
443
+ await createZoningPlanTable(db)
444
+ await createZoningAreaTable(db)
445
+ await createZoningVocabularyTable(db)
446
+ await createZoningCrosswalkEdgeTable(db)
447
+ await createZoningCellTable(db)
448
+ await createZoningMappedExtentTable(db)
449
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * One chunk of the zoning ingest, as its own process — spawned by `buildZoningDatabase`, never run by
7
+ * hand. The process boundary and the stdout contract live with `runIngestChunkScript`; what stays here is
8
+ * only this product's flags and its feature-source constructor.
9
+ */
10
+
11
+ import { requiredArgument } from "@mailwoman/core/scripting/arguments"
12
+ import { INGEST_CHUNK_FLAGS, runIngestChunkScript } from "@mailwoman/core/scripting/ingest-chunk-script"
13
+ import type { DatabaseClient } from "@mailwoman/sqlite/client"
14
+
15
+ import type { ZoningDatabase } from "#schema"
16
+ import { createExportFeatureSource } from "#sdk/ingest"
17
+ import { ingestZoningChunk } from "#sdk/ingest-chunk"
18
+
19
+ await runIngestChunkScript({
20
+ context: "zoning ingest-chunk",
21
+ options: {
22
+ ...INGEST_CHUNK_FLAGS,
23
+ export: { type: "string" },
24
+ "object-id-from": { type: "string" },
25
+ "object-id-to": { type: "string" },
26
+ },
27
+ run: async (database: DatabaseClient<ZoningDatabase>, values, chunk) =>
28
+ ingestZoningChunk(database, {
29
+ source: await createExportFeatureSource({
30
+ exportPath: requiredArgument("zoning ingest-chunk", "export", values.export),
31
+ ...(values["object-id-from"] === undefined ? {} : { objectIDFrom: Number(values["object-id-from"]) }),
32
+ ...(values["object-id-to"] === undefined ? {} : { objectIDTo: Number(values["object-id-to"]) }),
33
+ // A RANGE's own count is not knowable up front — the source reports a layer's total and nothing narrower — so
34
+ // the chunk asserts nothing about its size and the PARENT checks the sum against the whole file.
35
+ declaredFeatureCount: 0,
36
+ }),
37
+ indexResolution: chunk.indexResolution,
38
+ coverageResolution: chunk.coverageResolution,
39
+ onProgress: chunk.onProgress,
40
+ }),
41
+ })