@mailwoman/core 10.4.0 → 10.6.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/lib/api/ckan.ts +1 -1
- package/lib/decoder/serialize/json.ts +1 -1
- package/lib/env/env-file.ts +71 -0
- package/lib/env.ts +15 -9
- package/lib/fs/readers/stat.ts +16 -1
- package/lib/fs/readers.ts +15 -0
- package/lib/geocode/result.ts +46 -0
- package/lib/git.ts +357 -55
- package/lib/layers/manifest.ts +31 -0
- package/lib/layers/schema.ts +14 -0
- package/lib/license/docs-site.ts +1 -1
- package/lib/module/compiled-freshness.ts +5 -1
- package/lib/process.ts +320 -0
- package/lib/resources/git.ts +9 -5
- package/lib/types/classifier.ts +1 -1
- package/lib/utils/events.ts +23 -0
- package/out/api/ckan.d.ts +1 -1
- package/out/decoder/serialize/json.js +1 -1
- package/out/env/env-file.d.ts +26 -0
- package/out/env/env-file.d.ts.map +1 -0
- package/out/env/env-file.js +60 -0
- package/out/env/env-file.js.map +1 -0
- package/out/env.d.ts.map +1 -1
- package/out/env.js +15 -10
- package/out/env.js.map +1 -1
- package/out/fs/readers/stat.d.ts +9 -1
- package/out/fs/readers/stat.d.ts.map +1 -1
- package/out/fs/readers/stat.js +16 -0
- package/out/fs/readers/stat.js.map +1 -1
- package/out/fs/readers.d.ts +11 -0
- package/out/fs/readers.d.ts.map +1 -1
- package/out/fs/readers.js +14 -0
- package/out/fs/readers.js.map +1 -1
- package/out/geocode/result.d.ts +25 -0
- package/out/geocode/result.d.ts.map +1 -1
- package/out/geocode/result.js +40 -0
- package/out/geocode/result.js.map +1 -1
- package/out/git.d.ts +180 -4
- package/out/git.d.ts.map +1 -1
- package/out/git.js +227 -37
- package/out/git.js.map +1 -1
- package/out/layers/manifest.d.ts +19 -0
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +12 -0
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +10 -0
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +4 -0
- package/out/layers/schema.js.map +1 -1
- package/out/license/docs-site.d.ts +1 -1
- package/out/license/docs-site.js +1 -1
- package/out/module/compiled-freshness.d.ts.map +1 -1
- package/out/module/compiled-freshness.js +5 -1
- package/out/module/compiled-freshness.js.map +1 -1
- package/out/process.d.ts +146 -0
- package/out/process.d.ts.map +1 -1
- package/out/process.js +158 -0
- package/out/process.js.map +1 -1
- package/out/resources/git.d.ts +5 -1
- package/out/resources/git.d.ts.map +1 -1
- package/out/resources/git.js +8 -5
- package/out/resources/git.js.map +1 -1
- package/out/tools/coarse-placer/paths.d.ts +2 -2
- package/out/tools/coarse-placer/paths.js +2 -2
- package/out/tools/download/libpostal-resources.d.ts +2 -2
- package/out/tools/download/libpostal-resources.d.ts.map +1 -1
- package/out/tools/download/libpostal-resources.js +4 -4
- package/out/tools/download/libpostal-resources.js.map +1 -1
- package/out/types/classifier.d.ts +1 -1
- package/out/utils/events.d.ts +13 -0
- package/out/utils/events.d.ts.map +1 -1
- package/out/utils/events.js +19 -0
- package/out/utils/events.js.map +1 -1
- package/package.json +7 -7
- package/tools/coarse-placer/paths.ts +2 -2
- package/tools/download/libpostal-resources.ts +4 -4
package/lib/api/ckan.ts
CHANGED
|
@@ -34,7 +34,7 @@ import { type UnknownSpan, unknownSpans } from "#decoder/unknown-spans"
|
|
|
34
34
|
*/
|
|
35
35
|
export const DroppedSpanSchema = z.object({
|
|
36
36
|
/**
|
|
37
|
-
* The tag
|
|
37
|
+
* The tag the span holds.
|
|
38
38
|
*
|
|
39
39
|
* It is always one already present in the output, because a drop happens only when the slot was taken.
|
|
40
40
|
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { dirname, resolvePath } from "path-ts"
|
|
8
|
+
|
|
9
|
+
import { readLocalTextFileSync } from "#fs/readers"
|
|
10
|
+
import { isFileSync } from "#fs/readers/stat"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The `.env` file a process started in `workingDirectory` reads, or `null` when there is none.
|
|
14
|
+
*
|
|
15
|
+
* `process.loadEnvFile` reads the working directory's own `.env`.
|
|
16
|
+
* A git worktree has none, because the file is untracked and sits in the main checkout,
|
|
17
|
+
* so repository code run from a worktree would read the platform-default data root
|
|
18
|
+
* while the operator's data root is one `.git` pointer away.
|
|
19
|
+
*
|
|
20
|
+
* This resolves the file the way git resolves its common directory.
|
|
21
|
+
* A `.git` file in the working tree holds the path of the worktree's git directory.
|
|
22
|
+
*
|
|
23
|
+
* That directory's `commondir` file holds the path of the shared git directory.
|
|
24
|
+
* The main checkout is the shared directory's parent.
|
|
25
|
+
*
|
|
26
|
+
* A `.env` beside the working directory wins over the main checkout's, so a worktree can carry its own.
|
|
27
|
+
*
|
|
28
|
+
* The reads are synchronous because the env module folds the file into `process.env`
|
|
29
|
+
* at import time, ahead of any `await`.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveEnvFile(workingDirectory: string = process.cwd()): string | null {
|
|
32
|
+
const local = resolvePath(workingDirectory, ".env")
|
|
33
|
+
|
|
34
|
+
if (isFileSync(local)) return local
|
|
35
|
+
|
|
36
|
+
const mainCheckout = mainCheckoutOf(workingDirectory)
|
|
37
|
+
|
|
38
|
+
if (!mainCheckout) return null
|
|
39
|
+
|
|
40
|
+
const shared = resolvePath(mainCheckout, ".env")
|
|
41
|
+
|
|
42
|
+
return isFileSync(shared) ? shared : null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The line of a worktree's `.git` file that holds its git directory.
|
|
47
|
+
*/
|
|
48
|
+
const GIT_DIRECTORY_LINE = /^gitdir:[\t ]*(.+?)[\t ]*$/mu
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The main checkout of the repository whose worktree is `workingDirectory`,
|
|
52
|
+
* or `null` when the directory is not a worktree's root.
|
|
53
|
+
*/
|
|
54
|
+
function mainCheckoutOf(workingDirectory: string): string | null {
|
|
55
|
+
const pointer = resolvePath(workingDirectory, ".git")
|
|
56
|
+
|
|
57
|
+
if (!isFileSync(pointer)) return null
|
|
58
|
+
|
|
59
|
+
const gitDirectoryLine = GIT_DIRECTORY_LINE.exec(readLocalTextFileSync(pointer))
|
|
60
|
+
|
|
61
|
+
if (!gitDirectoryLine) return null
|
|
62
|
+
|
|
63
|
+
const gitDirectory = resolvePath(workingDirectory, gitDirectoryLine[1]!)
|
|
64
|
+
const commonDirectoryPath = resolvePath(gitDirectory, "commondir")
|
|
65
|
+
|
|
66
|
+
if (!isFileSync(commonDirectoryPath)) return null
|
|
67
|
+
|
|
68
|
+
const commonDirectory = resolvePath(gitDirectory, readLocalTextFileSync(commonDirectoryPath).trim())
|
|
69
|
+
|
|
70
|
+
return dirname(commonDirectory)
|
|
71
|
+
}
|
package/lib/env.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import type z from "zod"
|
|
8
8
|
|
|
9
|
+
import { resolveEnvFile } from "#env/env-file"
|
|
9
10
|
import { PrivateEnvSchema, PublicEnvSchema } from "#env/schema"
|
|
10
11
|
|
|
11
12
|
export { DefaultMailwomanPaths } from "#env/paths"
|
|
@@ -14,20 +15,25 @@ export { DefaultMailwomanPaths } from "#env/paths"
|
|
|
14
15
|
* The `.env` layer, folded into `process.env` when this module is evaluated — process-startup semantics.
|
|
15
16
|
*
|
|
16
17
|
* `process.loadEnvFile` is the runtime's own reader: synchronous, so the views below can expose
|
|
17
|
-
* synchronous getters without a top-level `await` (which the Docusaurus config loader cannot evaluate)
|
|
18
|
-
*
|
|
18
|
+
* synchronous getters without a top-level `await` (which the Docusaurus config loader cannot evaluate).
|
|
19
|
+
* `resolveEnvFile` picks the working directory's `.env`, or the main checkout's
|
|
20
|
+
* when the working directory is a git worktree, which carries no `.env` of its own.
|
|
21
|
+
*
|
|
19
22
|
* A variable already in `process.env` wins over the file.
|
|
20
23
|
* The views have always used this precedence.
|
|
21
24
|
*
|
|
22
25
|
* An absent `.env` is the common case and is not an error.
|
|
23
26
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const envFile = resolveEnvFile()
|
|
28
|
+
|
|
29
|
+
if (envFile) {
|
|
30
|
+
try {
|
|
31
|
+
// oxlint-disable-next-line sister-software/no-process-globals -- this module is the typed process.env boundary
|
|
32
|
+
process.loadEnvFile(envFile)
|
|
33
|
+
} catch {
|
|
34
|
+
// The file exists and the runtime could not read it.
|
|
35
|
+
// The process environment comes from `process.env` only.
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
/**
|
package/lib/fs/readers/stat.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { AssertionError } from "node:assert"
|
|
8
|
-
import type
|
|
8
|
+
import { type Dirent, type Mode, type Stats, statSync } from "node:fs"
|
|
9
9
|
import {
|
|
10
10
|
open as openNative,
|
|
11
11
|
access,
|
|
@@ -201,6 +201,21 @@ export function isFile(path: PathBuilderLike | URL): Promise<boolean> {
|
|
|
201
201
|
return tryStat(path).then((stats) => stats?.isFile() ?? false)
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Whether a path exists and is a file, read synchronously.
|
|
206
|
+
*
|
|
207
|
+
* The env module folds `.env` into `process.env` when it is imported,
|
|
208
|
+
* ahead of any `await`, so it cannot use {@linkcode isFile}.
|
|
209
|
+
* Every other caller can, and should.
|
|
210
|
+
*/
|
|
211
|
+
export function isFileSync(path: PathBuilderLike): boolean {
|
|
212
|
+
try {
|
|
213
|
+
return statSync(resolvePath(path)).isFile()
|
|
214
|
+
} catch {
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
204
219
|
/**
|
|
205
220
|
* Whether a path exists and is a symbolic link.
|
|
206
221
|
*/
|
package/lib/fs/readers.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* makes no blocking filesystem calls. The `debt` check in `lib/repo-health` counts any violations.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { readFileSync } from "node:fs"
|
|
11
12
|
import { readFile } from "node:fs/promises"
|
|
12
13
|
|
|
13
14
|
import { type PathBuilderLike, resolvePath } from "path-ts"
|
|
@@ -90,6 +91,20 @@ function readTarget(pathSegments: Array<PathBuilderLike | URL>): URL | string {
|
|
|
90
91
|
return resolvePath(...(pathSegments as PathBuilderLike[]))
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Read a local text file synchronously.
|
|
96
|
+
*
|
|
97
|
+
* The env module folds `.env` into `process.env` when it is imported, ahead of any `await`,
|
|
98
|
+
* so it cannot use {@linkcode readLocalTextFile}.
|
|
99
|
+
* Every other caller can, and should.
|
|
100
|
+
*
|
|
101
|
+
* @category Files
|
|
102
|
+
* @runtime node
|
|
103
|
+
*/
|
|
104
|
+
export function readLocalTextFileSync(...pathSegments: PathBuilderLike[]): string {
|
|
105
|
+
return readFileSync(resolvePath(...pathSegments), "utf8")
|
|
106
|
+
}
|
|
107
|
+
|
|
93
108
|
/**
|
|
94
109
|
* Read a local text file.
|
|
95
110
|
*
|
package/lib/geocode/result.ts
CHANGED
|
@@ -165,6 +165,43 @@ export const RooftopSchema = z.object({ localityNorm: z.string().nullable(), pos
|
|
|
165
165
|
|
|
166
166
|
export type Rooftop = z.infer<typeof RooftopSchema>
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* The register row that supplied an `address_point` or `interpolated` coordinate,
|
|
170
|
+
* as the row itself records it.
|
|
171
|
+
*/
|
|
172
|
+
export const CoordinateSourceSchema = z
|
|
173
|
+
.object({
|
|
174
|
+
/**
|
|
175
|
+
* The row's provenance stamp, verbatim: `openstreetmap:nz` for a row an operator built
|
|
176
|
+
* from an OpenStreetMap extract, `overture:NAD` for an Overture row, and so on.
|
|
177
|
+
*/
|
|
178
|
+
source: z.string(),
|
|
179
|
+
/**
|
|
180
|
+
* The data release the row came from, as the row records it, or null when the resolved
|
|
181
|
+
* tree carries none, as a tree a client sent to `/v1/resolve` may not.
|
|
182
|
+
*/
|
|
183
|
+
release: z.string().nullable(),
|
|
184
|
+
})
|
|
185
|
+
.meta({ id: "CoordinateSource", description: "The register row that supplied the coordinate." })
|
|
186
|
+
|
|
187
|
+
export type CoordinateSource = z.infer<typeof CoordinateSourceSchema>
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The service-level credit the OpenStreetMap Foundation's Geocoding Guideline asks
|
|
191
|
+
* of a public geocoder that serves OpenStreetMap data.
|
|
192
|
+
*/
|
|
193
|
+
export const OPENSTREETMAP_CREDIT = "© OpenStreetMap contributors, ODbL 1.0, https://www.openstreetmap.org/copyright"
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Whether a row's provenance stamp names an OpenStreetMap-derived row.
|
|
197
|
+
*
|
|
198
|
+
* `@mailwoman/osm` stamps every row it builds `openstreetmap:<cc>`, and a row the
|
|
199
|
+
* street-recovery pass placed `openstreetmap:<cc>#recovered`, so the prefix decides.
|
|
200
|
+
*/
|
|
201
|
+
export function isOpenStreetMapSource(source: string | null | undefined): boolean {
|
|
202
|
+
return typeof source === "string" && source.startsWith("openstreetmap:")
|
|
203
|
+
}
|
|
204
|
+
|
|
168
205
|
/**
|
|
169
206
|
* The poi.db entity that supplied a `venue`-tier coordinate.
|
|
170
207
|
*/
|
|
@@ -236,6 +273,15 @@ export const GeocodeResultSchema = z
|
|
|
236
273
|
*/
|
|
237
274
|
rooftop: RooftopSchema.nullable(),
|
|
238
275
|
|
|
276
|
+
/**
|
|
277
|
+
* The register row that supplied the coordinate, with its provenance stamp and release.
|
|
278
|
+
*
|
|
279
|
+
* Set on the `address_point` and `interpolated` tiers, whose coordinate comes from one register row.
|
|
280
|
+
* It is null on every other tier, including a coordinate a later pass moved to a venue
|
|
281
|
+
* or a plus code, because that coordinate no longer comes from the row.
|
|
282
|
+
*/
|
|
283
|
+
coordinate_source: CoordinateSourceSchema.nullable(),
|
|
284
|
+
|
|
239
285
|
/**
|
|
240
286
|
* The uncertainty radius in meters, or null when the tier reports none.
|
|
241
287
|
*/
|