@mailwoman/core 7.1.0 → 7.2.1
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/api/APIClient.ts +175 -0
- package/api/headless.ts +23 -0
- package/api/index.ts +11 -0
- package/api/responses.ts +135 -0
- package/coarse-placer/coarse-placer.ts +300 -0
- package/coarse-placer/featurize.ts +171 -0
- package/coarse-placer/tools/build-dataset.ts +223 -0
- package/coarse-placer/tools/build-outlier-exposure.ts +172 -0
- package/coarse-placer/tools/build-outlier-latin.ts +200 -0
- package/coarse-placer/tools/build-outlier-oa.ts +231 -0
- package/coarse-placer/tools/eval-latin-offmap.ts +140 -0
- package/coarse-placer/tools/eval-openset.ts +519 -0
- package/coarse-placer/tools/eval-quant-compare.ts +151 -0
- package/coarse-placer/tools/eval.ts +187 -0
- package/coarse-placer/tools/fnv-hash.ts +24 -0
- package/coarse-placer/tools/index.ts +23 -0
- package/coarse-placer/tools/probe-frontier.ts +216 -0
- package/coarse-placer/tools/quantize.ts +116 -0
- package/coarse-placer/tools/train.ts +244 -0
- package/collections.ts +134 -0
- package/db/schema.ts +21 -0
- package/decoder/build-tree.ts +228 -0
- package/decoder/calibration.ts +101 -0
- package/decoder/containment.ts +87 -0
- package/decoder/index.ts +17 -0
- package/decoder/proposals-to-tree.ts +83 -0
- package/decoder/resolve-proposal-overlaps.ts +79 -0
- package/decoder/serialize-json.ts +70 -0
- package/decoder/serialize-tuples.ts +61 -0
- package/decoder/serialize-xml.ts +209 -0
- package/decoder/types.ts +159 -0
- package/decoder/unknown-spans.ts +103 -0
- package/decoder/validate-tree.ts +100 -0
- package/env/index.ts +42 -0
- package/env/load.ts +14 -0
- package/env/paths.ts +40 -0
- package/env/schema.ts +125 -0
- package/errors/index.ts +9 -0
- package/errors/schema.ts +155 -0
- package/fs/node.ts +38 -0
- package/identifiers.ts +58 -0
- package/index.ts +13 -0
- package/kysley/adapter.ts +29 -0
- package/kysley/client.ts +30 -0
- package/kysley/dialect-config.ts +30 -0
- package/kysley/dialect.ts +67 -0
- package/kysley/driver.ts +175 -0
- package/layers/index.ts +12 -0
- package/layers/manifest.ts +154 -0
- package/layers/schema.ts +105 -0
- package/lifecycle/ServiceSymbol.ts +95 -0
- package/lifecycle/index.ts +11 -0
- package/lifecycle/lru-cache.ts +44 -0
- package/lifecycle/services.ts +322 -0
- package/locale/index.ts +9 -0
- package/locale/locale.ts +49 -0
- package/locale/profiles/en-us.ts +69 -0
- package/locale/profiles/fr-fr.ts +75 -0
- package/locale/profiles/index.ts +9 -0
- package/locale/profiles/ja-jp.ts +33 -0
- package/locale/registry.ts +68 -0
- package/logging/index.ts +8 -0
- package/logging/shared.ts +145 -0
- package/logging/utils.ts +46 -0
- package/objects.ts +211 -0
- package/out/layers/index.d.ts +12 -0
- package/out/layers/index.d.ts.map +1 -0
- package/out/layers/index.js +12 -0
- package/out/layers/index.js.map +1 -0
- package/out/layers/manifest.d.ts +64 -0
- package/out/layers/manifest.d.ts.map +1 -0
- package/out/layers/manifest.js +102 -0
- package/out/layers/manifest.js.map +1 -0
- package/out/layers/schema.d.ts +72 -0
- package/out/layers/schema.d.ts.map +1 -0
- package/out/layers/schema.js +61 -0
- package/out/layers/schema.js.map +1 -0
- package/out/pipeline/index.d.ts +1 -1
- package/out/pipeline/index.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +27 -0
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/types.d.ts +74 -4
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js.map +1 -1
- package/package.json +21 -21
- package/pipeline/index.ts +46 -0
- package/pipeline/reconcile-lookups.ts +108 -0
- package/pipeline/reconcile.ts +542 -0
- package/pipeline/runtime-pipeline.ts +732 -0
- package/pipeline/span-logit-aggregation.ts +151 -0
- package/pipeline/span-proposer.ts +587 -0
- package/pipeline/types.ts +348 -0
- package/policy/defaults.ts +35 -0
- package/policy/index.ts +10 -0
- package/policy/policy.ts +60 -0
- package/policy/proposal-collection.ts +64 -0
- package/policy/registry.ts +149 -0
- package/resolver/index.ts +29 -0
- package/resolver/types.ts +584 -0
- package/resources/LocaleIndex.ts +124 -0
- package/resources/ResourceMapCache.ts +126 -0
- package/resources/collections.ts +93 -0
- package/resources/debugging.ts +19 -0
- package/resources/git.ts +54 -0
- package/resources/index.ts +17 -0
- package/resources/languages/index.ts +49 -0
- package/resources/languages/types.gen.ts +1368 -0
- package/resources/libaddressinput.ts +105 -0
- package/resources/libpostal.ts +182 -0
- package/resources/locale.ts +23 -0
- package/resources/set.ts +179 -0
- package/resources/whosonfirst/DataSourceCache.ts +72 -0
- package/resources/whosonfirst/PlacetypeDataSource.ts +199 -0
- package/resources/whosonfirst/index.ts +10 -0
- package/resources/whosonfirst/loader.ts +157 -0
- package/resources/whosonfirst/placetypes/Placetype.ts +438 -0
- package/resources/whosonfirst/placetypes/admin.ts +173 -0
- package/resources/whosonfirst/placetypes/definition.ts +135 -0
- package/resources/whosonfirst/placetypes/graph.ts +0 -0
- package/resources/whosonfirst/placetypes/index.ts +12 -0
- package/resources/whosonfirst/placetypes/mermaid.ts +168 -0
- package/resources/whosonfirst/placetypes/tree.ts +46 -0
- package/routing/index.ts +208 -0
- package/scripting/index.ts +40 -0
- package/scripting/utils/index.ts +106 -0
- package/tokenization/Graph.ts +50 -0
- package/tokenization/Span.ts +297 -0
- package/tokenization/index.ts +9 -0
- package/tokenization/normalizer.ts +123 -0
- package/tools/download-libpostal-resources.ts +98 -0
- package/tools/download-ssl-address.ts +99 -0
- package/tools/generate-language-types.ts +194 -0
- package/tools/index.ts +13 -0
- package/types/Classification.ts +211 -0
- package/types/classifier.ts +133 -0
- package/types/component.ts +75 -0
- package/types/index.ts +10 -0
- package/types/mapping.ts +81 -0
- package/utils/data-root.ts +56 -0
- package/utils/hash.ts +27 -0
- package/utils/index.ts +14 -0
- package/utils/jsonl.ts +43 -0
- package/utils/python-json.ts +105 -0
- package/utils/python-random.ts +90 -0
- package/utils/repo.ts +118 -0
- package/utils/sealed-db.ts +85 -0
- package/utils/stats.ts +32 -0
- package/vitest.config.ts +53 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { BaseLogger as PinoBaseLogger, Level as PinoLevel, LogFn as PinoLogFn, Logger as PinoLogger } from "pino"
|
|
8
|
+
|
|
9
|
+
export type Logger = PinoLogger
|
|
10
|
+
|
|
11
|
+
export type Level = PinoLevel
|
|
12
|
+
|
|
13
|
+
export type LogFn = PinoLogFn
|
|
14
|
+
|
|
15
|
+
export type BaseLogger = Pick<PinoBaseLogger, Exclude<Level, "fatal">>
|
|
16
|
+
|
|
17
|
+
//#region Constants
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Labels log levels in the browser console.
|
|
21
|
+
*/
|
|
22
|
+
export const LogLevelLabel = {
|
|
23
|
+
info: "[INFO]",
|
|
24
|
+
warn: "[WARN]",
|
|
25
|
+
error: "[ERROR]",
|
|
26
|
+
debug: "[DEBUG]",
|
|
27
|
+
trace: "[TRACE]",
|
|
28
|
+
fatal: "[FATAL]",
|
|
29
|
+
} as const satisfies Record<Level, string>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Predefined log levels.
|
|
33
|
+
*/
|
|
34
|
+
export const LogLevels = Object.keys(LogLevelLabel) as Level[]
|
|
35
|
+
|
|
36
|
+
type LoggerFactory = (prefix?: string | null, ...args: string[]) => Logger
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Colors for log levels in the browser console.
|
|
40
|
+
*/
|
|
41
|
+
const LogLevelColors = {
|
|
42
|
+
info: `light-dark(#0043CE, #4589FF)`,
|
|
43
|
+
warn: `light-dark(#F1C21B, #F1C21B)`,
|
|
44
|
+
error: `light-dark(#DA1E28, #FA4D56)`,
|
|
45
|
+
debug: `light-dark(#8A3FFC, #A56EFF)`,
|
|
46
|
+
trace: `light-dark(#8A3FFC, #A56EFF)`,
|
|
47
|
+
fatal: `light-dark(#DA1E28, #FA4D56)`,
|
|
48
|
+
} as const
|
|
49
|
+
|
|
50
|
+
//#region Functions
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a logger with the given prefix.
|
|
54
|
+
*/
|
|
55
|
+
export const createConsoleLogger: LoggerFactory = (prefix, ...args) => {
|
|
56
|
+
const msgPrefix = prefix ? `(${prefix}):` : ":"
|
|
57
|
+
|
|
58
|
+
const logger: Partial<Logger> = {
|
|
59
|
+
msgPrefix,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (const level of LogLevels) {
|
|
63
|
+
const label = LogLevelLabel[level]
|
|
64
|
+
|
|
65
|
+
// @ts-expect-error Alias the log method to the appropriate console method,
|
|
66
|
+
// defaulting to console.log if the level is not supported.
|
|
67
|
+
const method = level in console ? console[level] : console.log
|
|
68
|
+
|
|
69
|
+
logger[level] = method.bind(console, `${label} ${msgPrefix}`, ...args)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return logger as Logger
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type BaseConsoleLogger = Record<Level, LogFn>
|
|
76
|
+
|
|
77
|
+
export type IRuntimeLogger = BaseConsoleLogger
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
|
|
81
|
+
//#region Functions
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates a logger with the given prefix.
|
|
85
|
+
*/
|
|
86
|
+
export function createLogger(prefix?: string, ...args: string[][]): Logger {
|
|
87
|
+
const msgPrefix = prefix ? `(${prefix}):` : ":"
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @type {Partial<Logger>}
|
|
91
|
+
*/
|
|
92
|
+
const logger: Partial<Logger> = {
|
|
93
|
+
msgPrefix,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const level of LogLevels) {
|
|
97
|
+
const label = LogLevelLabel[level]
|
|
98
|
+
const color = LogLevelColors[level]
|
|
99
|
+
|
|
100
|
+
// @ts-expect-error Alias the log method to the appropriate console method,
|
|
101
|
+
// defaulting to console.log if the level is not supported.
|
|
102
|
+
const method = level in console ? console[level] : console.log
|
|
103
|
+
|
|
104
|
+
logger[level] = method.bind(
|
|
105
|
+
console,
|
|
106
|
+
`%c${label}%c ${msgPrefix}%c`,
|
|
107
|
+
`font-weight: 700; color: ${color};`,
|
|
108
|
+
`font-weight: 600; color: CanvasText;`,
|
|
109
|
+
"",
|
|
110
|
+
...args
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return logger as Logger
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A singleton logger instance for the browser.
|
|
119
|
+
*
|
|
120
|
+
* ```js
|
|
121
|
+
* import { ConsoleLogger } from "@mailwoman/core/logging"
|
|
122
|
+
*
|
|
123
|
+
* ConsoleLogger.info("Hello, world!")
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @implements {IRuntimeLogger}
|
|
127
|
+
*/
|
|
128
|
+
export class ConsoleLogger {
|
|
129
|
+
static info: typeof console.info
|
|
130
|
+
static warn: typeof console.warn
|
|
131
|
+
static error: typeof console.error
|
|
132
|
+
static debug: typeof console.debug
|
|
133
|
+
static trace: typeof console.trace
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Creates a logger with the given prefix.
|
|
137
|
+
*/
|
|
138
|
+
static prefix(logPrefix: string) {
|
|
139
|
+
return createLogger(logPrefix)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
Object.assign(ConsoleLogger, createLogger())
|
|
144
|
+
|
|
145
|
+
//#endregion
|
package/logging/utils.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Casts an object to an array of log-friendly entries.
|
|
8
|
+
*
|
|
9
|
+
* @category Object
|
|
10
|
+
* @category Logger
|
|
11
|
+
*/
|
|
12
|
+
export function castToLoggableEntries<T extends Record<string, unknown>>(input: T) {
|
|
13
|
+
return Object.entries(input)
|
|
14
|
+
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
|
|
15
|
+
.filter(([_key, value]) => value && typeof value === "string") as [keyof T, string][]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for pretty-printing a logged object.
|
|
20
|
+
*
|
|
21
|
+
* @category Logger
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface StringifyLoggedObjectOptions {
|
|
25
|
+
description: string
|
|
26
|
+
showValues?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pretty-prints the public environment variables.
|
|
31
|
+
*
|
|
32
|
+
* @category Object
|
|
33
|
+
* @category Logger
|
|
34
|
+
*/
|
|
35
|
+
export function stringifyLoggedObject(
|
|
36
|
+
input: Record<string, unknown>,
|
|
37
|
+
{ description, showValues }: StringifyLoggedObjectOptions
|
|
38
|
+
): string {
|
|
39
|
+
const lines = castToLoggableEntries(input).map(([key, value]) => {
|
|
40
|
+
const printedValue = showValues ? value : new Array(value.length).fill("*").join("")
|
|
41
|
+
|
|
42
|
+
return `${key}: ${printedValue}`
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return description + "\n\n" + lines.join("\n") + "\n"
|
|
46
|
+
}
|
package/objects.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Utility functions for working with objects.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { JsonObject } from "type-fest"
|
|
10
|
+
|
|
11
|
+
import { isIterable } from "./collections.ts"
|
|
12
|
+
|
|
13
|
+
type SetLike<T> = { has(value: T): boolean } | Iterable<T>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Type-utility for extracting the string keys of an object.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type StringKeyOf<O> = Extract<keyof O, string>
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param input Source object.
|
|
24
|
+
* @param scalarEnum Unconstrained scalar enum whose values present in `input` will be used as keys, such as an
|
|
25
|
+
* enum-like object.
|
|
26
|
+
*
|
|
27
|
+
* @returns A subset of the source object with only properties present in `scalarEnum`.
|
|
28
|
+
*/
|
|
29
|
+
export function pick<O extends object, K extends string>(
|
|
30
|
+
input: O,
|
|
31
|
+
scalarEnum: Record<K, K>,
|
|
32
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
33
|
+
): Pick<O, StringKeyOf<O>>
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param input Source object.
|
|
37
|
+
* @param setLike Set-like object whose members represent the subset of keys to pick.
|
|
38
|
+
*
|
|
39
|
+
* @returns A subset of the source object with only properties present in `scalarEnum`.
|
|
40
|
+
*/
|
|
41
|
+
export function pick<O extends object, K extends keyof O>(
|
|
42
|
+
input: O,
|
|
43
|
+
setLike: SetLike<K>,
|
|
44
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
45
|
+
): Pick<O, K>
|
|
46
|
+
/**
|
|
47
|
+
* @param input Source object.
|
|
48
|
+
* @param scalarEnum Enum-like object whose members represent the subset of keys to pick.
|
|
49
|
+
*
|
|
50
|
+
* @returns A subset of the source object with only properties present in `scalarEnum`.
|
|
51
|
+
*/
|
|
52
|
+
export function pick<O extends object, K extends keyof O>(
|
|
53
|
+
input: O,
|
|
54
|
+
scalarEnum: Record<K, K>,
|
|
55
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
56
|
+
): Pick<O, StringKeyOf<O>>
|
|
57
|
+
/**
|
|
58
|
+
* @param input Source object.
|
|
59
|
+
* @param constraints Unconstrained iterable of keys to pick, such as in array or Map.
|
|
60
|
+
*
|
|
61
|
+
* @returns A subset of the source object with only properties present in `constraints`.
|
|
62
|
+
*/
|
|
63
|
+
export function pick<O extends object, K extends keyof O = StringKeyOf<O>>(
|
|
64
|
+
input: O,
|
|
65
|
+
constraints: Iterable<K>,
|
|
66
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
67
|
+
): Pick<O, K>
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param input Source object.
|
|
71
|
+
* @param constraints Enum-like object whose members represent the subset of keys to pick.
|
|
72
|
+
*
|
|
73
|
+
* @returns A subset of the source object with only properties present in `constraints`.
|
|
74
|
+
*/
|
|
75
|
+
export function pick<O extends object, K extends keyof O = StringKeyOf<O>>(
|
|
76
|
+
input: O,
|
|
77
|
+
constraints: Record<K, K>,
|
|
78
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
79
|
+
): Pick<O, K>
|
|
80
|
+
/**
|
|
81
|
+
* @param input Source object.
|
|
82
|
+
* @param keys Unconstrained iterable of keys to pick, such as in array or Map.
|
|
83
|
+
*
|
|
84
|
+
* @returns A subset of the source object with only properties present in `keys`.
|
|
85
|
+
*/
|
|
86
|
+
export function pick<O extends object, K extends string>(
|
|
87
|
+
input: O,
|
|
88
|
+
keys: Iterable<K>,
|
|
89
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
90
|
+
): Pick<O, StringKeyOf<O>>
|
|
91
|
+
/**
|
|
92
|
+
* @param input Source object.
|
|
93
|
+
* @param constraints Unconstrained iterable of keys to pick, such as in array or Map.
|
|
94
|
+
*
|
|
95
|
+
* @returns A subset of the source object with only properties present in `constraints`.
|
|
96
|
+
*/
|
|
97
|
+
export function pick<O extends object, K extends keyof O = StringKeyOf<O>>(
|
|
98
|
+
input: O,
|
|
99
|
+
constraints: Iterable<K> | Record<K, K> | SetLike<K>,
|
|
100
|
+
transform?: (value: O[keyof O], key: keyof O, input: O) => never
|
|
101
|
+
): Pick<O, K> {
|
|
102
|
+
const picked: Partial<Pick<O, keyof O>> = {}
|
|
103
|
+
|
|
104
|
+
if (!input) return picked as Pick<O, K>
|
|
105
|
+
|
|
106
|
+
if (!constraints) return input as Pick<O, K>
|
|
107
|
+
|
|
108
|
+
const keys = isIterable(constraints) ? Array.from(constraints) : Object.values(constraints)
|
|
109
|
+
|
|
110
|
+
for (const key of keys) {
|
|
111
|
+
const value = (input as never)[key]
|
|
112
|
+
picked[key as keyof O] = transform ? transform(value, key, input) : value
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return picked as Pick<O, K>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Type-predicate for checking if a value appears to be a record, i.e. an object that is not an array.
|
|
120
|
+
*
|
|
121
|
+
* @category Type Guard
|
|
122
|
+
* @category Object
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
export function isRecordLike(input: unknown): input is object {
|
|
126
|
+
return typeof input === "object" && input !== null && !Array.isArray(input)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Type-helper to remove nullability from an object's properties.
|
|
131
|
+
*
|
|
132
|
+
* @category Object
|
|
133
|
+
*/
|
|
134
|
+
export type NonNullableObject<T> = { [P in keyof T]-?: NonNullable<T[P]> } & NonNullable<T>
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Given an object, returns a new object with all nullable properties removed.
|
|
138
|
+
*
|
|
139
|
+
* This is useful for cleaning up objects before serializing them to JSON.
|
|
140
|
+
*
|
|
141
|
+
* @category Object
|
|
142
|
+
*/
|
|
143
|
+
export function omitNullable<T extends object>(input: T): NonNullableObject<T> {
|
|
144
|
+
const result: Record<string, unknown> = {}
|
|
145
|
+
|
|
146
|
+
for (const [key, currentValue] of Object.entries(input)) {
|
|
147
|
+
if (isRecordLike(currentValue)) {
|
|
148
|
+
const childResult = omitNullable(currentValue)
|
|
149
|
+
|
|
150
|
+
if (Object.keys(childResult).length > 0) {
|
|
151
|
+
result[key] = childResult
|
|
152
|
+
}
|
|
153
|
+
} else if (Array.isArray(currentValue)) {
|
|
154
|
+
const arr = currentValue
|
|
155
|
+
.map((entryValue) => (isRecordLike(entryValue) ? omitNullable(entryValue) : entryValue))
|
|
156
|
+
.filter((val) => val != null)
|
|
157
|
+
|
|
158
|
+
if (arr.length > 0) {
|
|
159
|
+
result[key] = arr
|
|
160
|
+
}
|
|
161
|
+
} else if (currentValue !== null) {
|
|
162
|
+
result[key] = currentValue
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result as NonNullableObject<T>
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Given serialized JSON, attempt to parse it.
|
|
171
|
+
*/
|
|
172
|
+
export function tryParsingJSON<T = unknown>(input: unknown, fallback?: undefined): T | undefined
|
|
173
|
+
export function tryParsingJSON<T = unknown>(input: unknown, fallback: null): T | null
|
|
174
|
+
export function tryParsingJSON<T = unknown, F = null>(input: unknown, fallback?: F): T | F {
|
|
175
|
+
if (typeof input !== "string") return (fallback ?? null) as F
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
return JSON.parse(input)
|
|
179
|
+
} catch {
|
|
180
|
+
return (fallback ?? null) as F
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export type FlattenObjectKeys<T extends JsonObject, Key = keyof T> = Key extends string
|
|
185
|
+
? T[Key] extends JsonObject
|
|
186
|
+
? `${Key}.${FlattenObjectKeys<T[Key]>}`
|
|
187
|
+
: `${Key}`
|
|
188
|
+
: never
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Flattens an object into a single-level object with dot-separated keys.
|
|
192
|
+
*/
|
|
193
|
+
export function flattenObject<T extends JsonObject>(
|
|
194
|
+
obj: T,
|
|
195
|
+
prefix: string[] = [],
|
|
196
|
+
current: Record<string, unknown> = {}
|
|
197
|
+
): Record<FlattenObjectKeys<T>, unknown> {
|
|
198
|
+
prefix = prefix || []
|
|
199
|
+
current = current || {}
|
|
200
|
+
|
|
201
|
+
// Remember kids, null is also an object!
|
|
202
|
+
if (typeof obj === "object" && obj !== null) {
|
|
203
|
+
Object.keys(obj).forEach((key) => {
|
|
204
|
+
;(flattenObject as typeof flattenObject)(obj[key] as JsonObject, prefix.concat(key), current)
|
|
205
|
+
})
|
|
206
|
+
} else {
|
|
207
|
+
current[prefix.join(".")] = obj
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return current
|
|
211
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The spatial-layer contract: manifest/coverage schema + IO. Every layer database — shipped,
|
|
7
|
+
* build-local, or private — embeds these tables. Spec:
|
|
8
|
+
* docs/superpowers/specs/2026-07-18-spatial-layers-and-poi-design.md §2.1.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./manifest.ts";
|
|
11
|
+
export * from "./schema.ts";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../layers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The spatial-layer contract: manifest/coverage schema + IO. Every layer database — shipped,
|
|
7
|
+
* build-local, or private — embeds these tables. Spec:
|
|
8
|
+
* docs/superpowers/specs/2026-07-18-spatial-layers-and-poi-design.md §2.1.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./manifest.js";
|
|
11
|
+
export * from "./schema.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../layers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Read/write helpers over the layer-contract tables. The parsed {@link LayerManifest} is the
|
|
7
|
+
* camelCase face of `layer_manifest`; validation happens at BOTH ends so a hand-built or
|
|
8
|
+
* corrupted layer fails loudly at open time rather than misbehaving downstream.
|
|
9
|
+
*/
|
|
10
|
+
import type { Kysely } from "kysely";
|
|
11
|
+
import { LayerFreshnessPolicy, LayerTier, type LayerContractDatabase } from "./schema.ts";
|
|
12
|
+
/** Which spine columns a layer carries. At least one key is required. */
|
|
13
|
+
export interface SpineKeys {
|
|
14
|
+
h3?: {
|
|
15
|
+
column: string;
|
|
16
|
+
resolution: number;
|
|
17
|
+
};
|
|
18
|
+
/** Column name holding WOF ids, when present. */
|
|
19
|
+
wofID?: string;
|
|
20
|
+
/** Column name holding `@mailwoman/address-id` keys, when present. */
|
|
21
|
+
addressID?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Parsed manifest — see {@link LayerManifestTable} for the storage form. */
|
|
24
|
+
export interface LayerManifest {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
schemaVersion: number;
|
|
28
|
+
tier: LayerTier;
|
|
29
|
+
license: string;
|
|
30
|
+
attribution?: string;
|
|
31
|
+
source: string;
|
|
32
|
+
sourceVintage: string;
|
|
33
|
+
buildCmd: string;
|
|
34
|
+
buildSHA: string;
|
|
35
|
+
freshnessPolicy: LayerFreshnessPolicy;
|
|
36
|
+
spineKeys: SpineKeys;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
}
|
|
39
|
+
export interface CoverageCell {
|
|
40
|
+
h3Cell: number;
|
|
41
|
+
completeness: number;
|
|
42
|
+
observedRows: number;
|
|
43
|
+
}
|
|
44
|
+
/** Insert the single manifest row. Call exactly once, from the layer's build script. */
|
|
45
|
+
export declare function writeLayerManifest(db: Kysely<LayerContractDatabase>, manifest: LayerManifest): Promise<void>;
|
|
46
|
+
/** Read + validate the manifest. Throws if the table is empty, multi-row, or invalid. */
|
|
47
|
+
export declare function readLayerManifest(db: Kysely<LayerContractDatabase>): Promise<LayerManifest>;
|
|
48
|
+
/**
|
|
49
|
+
* Rows per INSERT statement (3 bound params/row = 15,000 params/statement), kept safely under SQLite's default 32,766
|
|
50
|
+
* bound-variable ceiling — a continental-scale build's res-6 coverage cell count blows past that limit in a single
|
|
51
|
+
* `.values()` call (found 2026-07-19).
|
|
52
|
+
*/
|
|
53
|
+
export declare const COVERAGE_INSERT_BATCH = 5000;
|
|
54
|
+
/**
|
|
55
|
+
* Bulk-insert coverage cells (build-time; cold path, so Kysely inserts are fine), chunked to stay under SQLite's
|
|
56
|
+
* bound-variable limit.
|
|
57
|
+
*/
|
|
58
|
+
export declare function writeLayerCoverage(db: Kysely<LayerContractDatabase>, cells: CoverageCell[]): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Look up coverage for one short H3 cell. `undefined` = the cell was never surveyed (UNKNOWN) — callers must not
|
|
61
|
+
* conflate this with `{completeness: 0}`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function readLayerCoverage(db: Kysely<LayerContractDatabase>, h3Cell: number): Promise<CoverageCell | undefined>;
|
|
64
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../layers/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEzF,yEAAyE;AACzE,MAAM,WAAW,SAAS;IACzB,EAAE,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,oBAAoB,CAAA;IACrC,SAAS,EAAE,SAAS,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACpB;AAmBD,wFAAwF;AACxF,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,MAAM,CAAC,qBAAqB,CAAC,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBlH;AAED,yFAAyF;AACzF,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,MAAM,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CA0BjG;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,OAAQ,CAAA;AAE1C;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,MAAM,CAAC,qBAAqB,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhH;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACtC,EAAE,EAAE,MAAM,CAAC,qBAAqB,CAAC,EACjC,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAMnC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Read/write helpers over the layer-contract tables. The parsed {@link LayerManifest} is the
|
|
7
|
+
* camelCase face of `layer_manifest`; validation happens at BOTH ends so a hand-built or
|
|
8
|
+
* corrupted layer fails loudly at open time rather than misbehaving downstream.
|
|
9
|
+
*/
|
|
10
|
+
import { LayerFreshnessPolicy, LayerTier } from "./schema.js";
|
|
11
|
+
const TIERS = new Set(Object.values(LayerTier));
|
|
12
|
+
const POLICIES = new Set(Object.values(LayerFreshnessPolicy));
|
|
13
|
+
function assertManifestInvariants(manifest) {
|
|
14
|
+
if (!TIERS.has(manifest.tier)) {
|
|
15
|
+
throw new Error(`layer manifest: unknown tier ${JSON.stringify(manifest.tier)}`);
|
|
16
|
+
}
|
|
17
|
+
if (!POLICIES.has(manifest.freshnessPolicy)) {
|
|
18
|
+
throw new Error(`layer manifest: unknown freshness_policy ${JSON.stringify(manifest.freshnessPolicy)}`);
|
|
19
|
+
}
|
|
20
|
+
if (!manifest.spineKeys.h3 && !manifest.spineKeys.wofID && !manifest.spineKeys.addressID) {
|
|
21
|
+
throw new Error("layer manifest: at least one spine key (h3, wofID, addressID) is required");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Insert the single manifest row. Call exactly once, from the layer's build script. */
|
|
25
|
+
export async function writeLayerManifest(db, manifest) {
|
|
26
|
+
assertManifestInvariants(manifest);
|
|
27
|
+
await db
|
|
28
|
+
.insertInto("layer_manifest")
|
|
29
|
+
.values({
|
|
30
|
+
name: manifest.name,
|
|
31
|
+
version: manifest.version,
|
|
32
|
+
schema_version: manifest.schemaVersion,
|
|
33
|
+
tier: manifest.tier,
|
|
34
|
+
license: manifest.license,
|
|
35
|
+
attribution: manifest.attribution ?? null,
|
|
36
|
+
source: manifest.source,
|
|
37
|
+
source_vintage: manifest.sourceVintage,
|
|
38
|
+
build_cmd: manifest.buildCmd,
|
|
39
|
+
build_sha: manifest.buildSHA,
|
|
40
|
+
freshness_policy: manifest.freshnessPolicy,
|
|
41
|
+
spine_keys: JSON.stringify(manifest.spineKeys),
|
|
42
|
+
created_at: manifest.createdAt,
|
|
43
|
+
})
|
|
44
|
+
.execute();
|
|
45
|
+
}
|
|
46
|
+
/** Read + validate the manifest. Throws if the table is empty, multi-row, or invalid. */
|
|
47
|
+
export async function readLayerManifest(db) {
|
|
48
|
+
const rows = await db.selectFrom("layer_manifest").selectAll().execute();
|
|
49
|
+
if (rows.length !== 1) {
|
|
50
|
+
throw new Error(`layer manifest: expected exactly 1 row, found ${rows.length}`);
|
|
51
|
+
}
|
|
52
|
+
const row = rows[0];
|
|
53
|
+
const manifest = {
|
|
54
|
+
name: row.name,
|
|
55
|
+
version: row.version,
|
|
56
|
+
schemaVersion: row.schema_version,
|
|
57
|
+
tier: row.tier,
|
|
58
|
+
license: row.license,
|
|
59
|
+
...(row.attribution === null ? {} : { attribution: row.attribution }),
|
|
60
|
+
source: row.source,
|
|
61
|
+
sourceVintage: row.source_vintage,
|
|
62
|
+
buildCmd: row.build_cmd,
|
|
63
|
+
buildSHA: row.build_sha,
|
|
64
|
+
freshnessPolicy: row.freshness_policy,
|
|
65
|
+
spineKeys: JSON.parse(row.spine_keys),
|
|
66
|
+
createdAt: row.created_at,
|
|
67
|
+
};
|
|
68
|
+
assertManifestInvariants(manifest);
|
|
69
|
+
return manifest;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Rows per INSERT statement (3 bound params/row = 15,000 params/statement), kept safely under SQLite's default 32,766
|
|
73
|
+
* bound-variable ceiling — a continental-scale build's res-6 coverage cell count blows past that limit in a single
|
|
74
|
+
* `.values()` call (found 2026-07-19).
|
|
75
|
+
*/
|
|
76
|
+
export const COVERAGE_INSERT_BATCH = 5_000;
|
|
77
|
+
/**
|
|
78
|
+
* Bulk-insert coverage cells (build-time; cold path, so Kysely inserts are fine), chunked to stay under SQLite's
|
|
79
|
+
* bound-variable limit.
|
|
80
|
+
*/
|
|
81
|
+
export async function writeLayerCoverage(db, cells) {
|
|
82
|
+
if (cells.length === 0)
|
|
83
|
+
return;
|
|
84
|
+
for (let i = 0; i < cells.length; i += COVERAGE_INSERT_BATCH) {
|
|
85
|
+
const batch = cells.slice(i, i + COVERAGE_INSERT_BATCH);
|
|
86
|
+
await db
|
|
87
|
+
.insertInto("layer_coverage")
|
|
88
|
+
.values(batch.map((c) => ({ h3_cell: c.h3Cell, completeness: c.completeness, observed_rows: c.observedRows })))
|
|
89
|
+
.execute();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Look up coverage for one short H3 cell. `undefined` = the cell was never surveyed (UNKNOWN) — callers must not
|
|
94
|
+
* conflate this with `{completeness: 0}`.
|
|
95
|
+
*/
|
|
96
|
+
export async function readLayerCoverage(db, h3Cell) {
|
|
97
|
+
const row = await db.selectFrom("layer_coverage").selectAll().where("h3_cell", "=", h3Cell).executeTakeFirst();
|
|
98
|
+
if (!row)
|
|
99
|
+
return undefined;
|
|
100
|
+
return { h3Cell: row.h3_cell, completeness: row.completeness, observedRows: row.observed_rows };
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../layers/manifest.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Typed schema for the spatial-layer contract — the two tables EVERY layer database embeds,
|
|
7
|
+
* regardless of tier: `layer_manifest` (single-row identity/provenance/licensing record) and
|
|
8
|
+
* `layer_coverage` (per-H3-cell survey completeness). The contract is what lets shipped,
|
|
9
|
+
* build-local, and private layers share one query surface. Spec:
|
|
10
|
+
* docs/superpowers/specs/2026-07-18-spatial-layers-and-poi-design.md §2.1.
|
|
11
|
+
*
|
|
12
|
+
* Coverage carries the meaning-of-zero rule: a MISSING coverage row means "unmapped/unknown",
|
|
13
|
+
* never "surveyed and empty". Consumers must treat absence as absence of evidence.
|
|
14
|
+
*/
|
|
15
|
+
import { type Kysely } from "kysely";
|
|
16
|
+
/** Distribution tier of a layer. Shipped = permissive-license, published by us. */
|
|
17
|
+
export declare const LayerTier: {
|
|
18
|
+
readonly Shipped: "shipped";
|
|
19
|
+
/** Share-alike sources (ODbL): we ship the builder CLI, the user builds locally. */
|
|
20
|
+
readonly BuildLocal: "build-local";
|
|
21
|
+
/** The user's own data, conforming to the contract, never distributed. */
|
|
22
|
+
readonly Private: "private";
|
|
23
|
+
};
|
|
24
|
+
export type LayerTier = (typeof LayerTier)[keyof typeof LayerTier];
|
|
25
|
+
/** How a layer is kept current. */
|
|
26
|
+
export declare const LayerFreshnessPolicy: {
|
|
27
|
+
/** Immutable artifact; updates are full rebuilds (the gazetteer discipline). */
|
|
28
|
+
readonly Sealed: "sealed";
|
|
29
|
+
/** Periodically re-issued under the same name (e.g. registries of people/programs). */
|
|
30
|
+
readonly VersionedRefresh: "versioned-refresh";
|
|
31
|
+
};
|
|
32
|
+
export type LayerFreshnessPolicy = (typeof LayerFreshnessPolicy)[keyof typeof LayerFreshnessPolicy];
|
|
33
|
+
/** The single-row layer identity record. See {@link LayerManifest} for the parsed form. */
|
|
34
|
+
export interface LayerManifestTable {
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
37
|
+
schema_version: number;
|
|
38
|
+
/** One of {@link LayerTier}. */
|
|
39
|
+
tier: string;
|
|
40
|
+
/** SPDX-ish license expression, e.g. `CDLA-Permissive-2.0`, `ODbL-1.0`. */
|
|
41
|
+
license: string;
|
|
42
|
+
attribution: string | null;
|
|
43
|
+
source: string;
|
|
44
|
+
source_vintage: string;
|
|
45
|
+
build_cmd: string;
|
|
46
|
+
build_sha: string;
|
|
47
|
+
/** One of {@link LayerFreshnessPolicy}. */
|
|
48
|
+
freshness_policy: string;
|
|
49
|
+
/** JSON-encoded spine-key declaration (see `SpineKeys` in `manifest.ts`). */
|
|
50
|
+
spine_keys: string;
|
|
51
|
+
/** ISO-8601, supplied by the build script (never generated in-library). */
|
|
52
|
+
created_at: string;
|
|
53
|
+
}
|
|
54
|
+
/** Per-cell survey completeness. Missing row = unknown, NOT zero. */
|
|
55
|
+
export interface LayerCoverageTable {
|
|
56
|
+
/** 48-bit short H3 cell at the resolution declared by the manifest's spine keys. */
|
|
57
|
+
h3_cell: number;
|
|
58
|
+
/** Estimated completeness of the source survey in this cell, 0..1. */
|
|
59
|
+
completeness: number;
|
|
60
|
+
/** Rows this layer actually holds in the cell. */
|
|
61
|
+
observed_rows: number;
|
|
62
|
+
}
|
|
63
|
+
/** Pass to `new DatabaseClient<LayerContractDatabase>(...)` (or intersect into a layer's own schema). */
|
|
64
|
+
export interface LayerContractDatabase {
|
|
65
|
+
layer_manifest: LayerManifestTable;
|
|
66
|
+
layer_coverage: LayerCoverageTable;
|
|
67
|
+
}
|
|
68
|
+
/** Create `layer_manifest`. Single row enforced by `name` PK + the writer's insert-once discipline. */
|
|
69
|
+
export declare function createLayerManifestTable(db: Kysely<LayerContractDatabase>): Promise<void>;
|
|
70
|
+
/** Create `layer_coverage` — small fixed-width rows probed by PK, the WITHOUT ROWID sweet spot. */
|
|
71
|
+
export declare function createLayerCoverageTable(db: Kysely<LayerContractDatabase>): Promise<void>;
|
|
72
|
+
//# sourceMappingURL=schema.d.ts.map
|