@gadicc/loom 2.3.1 → 2.4.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 (42) hide show
  1. package/.loom-source-manifest.json +7 -1
  2. package/esm/src/geo/client.d.ts +74 -0
  3. package/esm/src/geo/client.d.ts.map +1 -0
  4. package/esm/src/geo/client.js +135 -0
  5. package/esm/src/geo/client.js.map +1 -0
  6. package/esm/src/geo/mod.d.ts +5 -0
  7. package/esm/src/geo/mod.d.ts.map +1 -0
  8. package/esm/src/geo/mod.js +5 -0
  9. package/esm/src/geo/mod.js.map +1 -0
  10. package/esm/src/geo/place.d.ts +28 -0
  11. package/esm/src/geo/place.d.ts.map +1 -0
  12. package/esm/src/geo/place.js +41 -0
  13. package/esm/src/geo/place.js.map +1 -0
  14. package/esm/src/geo/places.d.ts +16 -0
  15. package/esm/src/geo/places.d.ts.map +1 -0
  16. package/esm/src/geo/places.js +154 -0
  17. package/esm/src/geo/places.js.map +1 -0
  18. package/esm/src/geo/placesFormat.d.ts +49 -0
  19. package/esm/src/geo/placesFormat.d.ts.map +1 -0
  20. package/esm/src/geo/placesFormat.js +38 -0
  21. package/esm/src/geo/placesFormat.js.map +1 -0
  22. package/esm/src/geo/preference.d.ts +15 -0
  23. package/esm/src/geo/preference.d.ts.map +1 -0
  24. package/esm/src/geo/preference.js +21 -0
  25. package/esm/src/geo/preference.js.map +1 -0
  26. package/esm/src/geo/timeZone.d.ts +20 -0
  27. package/esm/src/geo/timeZone.d.ts.map +1 -0
  28. package/esm/src/geo/timeZone.js +65 -0
  29. package/esm/src/geo/timeZone.js.map +1 -0
  30. package/esm/src/geo/vercel.d.ts +15 -0
  31. package/esm/src/geo/vercel.d.ts.map +1 -0
  32. package/esm/src/geo/vercel.js +64 -0
  33. package/esm/src/geo/vercel.js.map +1 -0
  34. package/package.json +26 -2
  35. package/source/src/geo/client.ts +241 -0
  36. package/source/src/geo/mod.ts +12 -0
  37. package/source/src/geo/place.ts +61 -0
  38. package/source/src/geo/places.ts +195 -0
  39. package/source/src/geo/placesFormat.ts +58 -0
  40. package/source/src/geo/preference.ts +24 -0
  41. package/source/src/geo/timeZone.ts +78 -0
  42. package/source/src/geo/vercel.ts +78 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 1,
3
- "supportDigest": "8a037d6466febb97f71148bc0f9cdc764bc996bc26671e620ecfcf50aa496e88",
3
+ "supportDigest": "e29d259f4bd8b528cda46cf61289baf1345ab4d2452baea7afe16b06cb536d31",
4
4
  "supportSources": [
5
5
  "src/apiKeys/betterAuth.ts",
6
6
  "src/apiKeys/permissions.ts",
@@ -54,6 +54,9 @@
54
54
  "./src/apiKeys/mod.js": "src/apiKeys/mod.ts",
55
55
  "./src/clientData/mod.js": "src/clientData/mod.ts",
56
56
  "./src/files/mod.js": "src/files/mod.ts",
57
+ "./src/geo/mod.js": "src/geo/mod.ts",
58
+ "./src/geo/client.js": "src/geo/client.ts",
59
+ "./src/geo/places.js": "src/geo/places.ts",
57
60
  "./src/mail/mod.js": "src/mail/mod.ts",
58
61
  "./src/mail/postal.js": "src/mail/postal.ts",
59
62
  "./src/mui/apiKeys.js": "src/mui/apiKeys.tsx",
@@ -73,6 +76,9 @@
73
76
  ".": "mod.ts",
74
77
  "./release": "src/release/mod.ts",
75
78
  "./client-data": "src/clientData/mod.ts",
79
+ "./geo": "src/geo/mod.ts",
80
+ "./geo/client": "src/geo/client.ts",
81
+ "./geo/places": "src/geo/places.ts",
76
82
  "./files": "src/files/mod.ts",
77
83
  "./api-keys": "src/apiKeys/mod.ts",
78
84
  "./apiKeys": "src/apiKeys/mod.ts",
@@ -0,0 +1,74 @@
1
+ import { type Place } from "./place.js";
2
+ /** Recoverable acquisition failures; presentation and retry policy belong to apps. */
3
+ export type LocationFailure = "timeout" | "cancelled" | "denied" | "unavailable" | "unsupported" | "insecure";
4
+ /** A bounded one-shot request failed without changing the app's current location. */
5
+ export declare class LocationError extends Error {
6
+ readonly code: LocationFailure;
7
+ constructor(code: LocationFailure);
8
+ }
9
+ /** Request controls shared by network and device acquisition. */
10
+ export interface LocationRequest {
11
+ signal?: AbortSignal;
12
+ /** App-level wall-clock deadline, including permission waiting and body parsing. */
13
+ timeoutMs?: number;
14
+ }
15
+ /** A server response observation; city availability does not guarantee precision. */
16
+ export interface LocationObservation {
17
+ place: Place | null;
18
+ cityName?: string;
19
+ /** Browser receipt time, never claimed to be the IP provider's measurement time. */
20
+ checkedAt: number;
21
+ }
22
+ /** Validates the geo route response, keeping explicit null distinct from failure. */
23
+ export declare function toLocationObservation(body: unknown, checkedAt?: number): LocationObservation | null;
24
+ /** A same-origin geo request; no caching or preference side effects. */
25
+ export interface DetectionRequest extends LocationRequest {
26
+ endpoint?: string;
27
+ fetcher?: typeof fetch;
28
+ /** An app-owned early request, already carrying its actual response receipt time. */
29
+ early?: Promise<LocationObservation | null>;
30
+ }
31
+ /** Fetches fresh IP hints with a deadline even when fetch/body reading ignores abort. */
32
+ export declare function fetchDetectedPlace(options?: DetectionRequest): Promise<LocationObservation>;
33
+ /** A minimal browser position, also usable by injected test devices. */
34
+ export interface DevicePosition {
35
+ coords: {
36
+ latitude: number;
37
+ longitude: number;
38
+ };
39
+ timestamp: number;
40
+ }
41
+ /** Structural browser API: the shared package does not require DOM-only globals. */
42
+ export interface LocationDevice {
43
+ getCurrentPosition(success: (position: DevicePosition) => void, failure: (error: {
44
+ code: number;
45
+ }) => void, options: {
46
+ enableHighAccuracy: boolean;
47
+ maximumAge: number;
48
+ timeout: number;
49
+ }): void;
50
+ }
51
+ /** Device acquisition settings, independent of remembered browser permission. */
52
+ export interface DeviceRequest extends LocationRequest {
53
+ device?: LocationDevice;
54
+ secureContext?: boolean;
55
+ maximumAge?: number;
56
+ enableHighAccuracy?: boolean;
57
+ }
58
+ /** Raw coordinates with their device measurement time; apps choose stored precision. */
59
+ export interface DeviceLocation {
60
+ latitude: number;
61
+ longitude: number;
62
+ timestamp: number;
63
+ }
64
+ /**
65
+ * Called from an explicit user action only. A cancelled/timed-out request ignores
66
+ * late callbacks; the browser permission prompt itself cannot be dismissed here.
67
+ */
68
+ export declare function locateDevice(options?: DeviceRequest): Promise<DeviceLocation>;
69
+ /** Bounded city search, with app-owned debounce and cancellation of superseded queries. */
70
+ export declare function fetchPlaces(query: string, options?: LocationRequest & {
71
+ endpoint?: string;
72
+ fetcher?: typeof fetch;
73
+ }): Promise<Place[]>;
74
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../source/src/geo/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAW,MAAM,YAAY,CAAC;AAEjD,sFAAsF;AACtF,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,WAAW,GACX,QAAQ,GACR,aAAa,GACb,aAAa,GACb,UAAU,CAAC;AAEf,qFAAqF;AACrF,qBAAa,aAAc,SAAQ,KAAK;aACV,IAAI,EAAE,eAAe;gBAArB,IAAI,EAAE,eAAe;CAIlD;AAED,iEAAiE;AACjE,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAwCD,qFAAqF;AACrF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qFAAqF;AACrF,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,OAAO,EACb,SAAS,SAAa,GACrB,mBAAmB,GAAG,IAAI,CAc5B;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,qFAAqF;IACrF,KAAK,CAAC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,OAAO,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GAC5E,OAAO,CAAC,KAAK,EAAE,CAAC,CAsBlB"}
@@ -0,0 +1,135 @@
1
+ import { toPlace } from "./place.js";
2
+ /** A bounded one-shot request failed without changing the app's current location. */
3
+ export class LocationError extends Error {
4
+ code;
5
+ constructor(code) {
6
+ super(`Location ${code}`);
7
+ this.code = code;
8
+ this.name = "LocationError";
9
+ }
10
+ }
11
+ async function bounded(run, options, fallback) {
12
+ const controller = new AbortController();
13
+ let timer;
14
+ let abort;
15
+ const milliseconds = options.timeoutMs ?? fallback;
16
+ if (!Number.isFinite(milliseconds) || milliseconds <= 0)
17
+ throw new RangeError("Invalid location deadline");
18
+ if (options.signal?.aborted)
19
+ throw new LocationError("cancelled");
20
+ try {
21
+ const deadline = new Promise((_, reject) => {
22
+ abort = () => {
23
+ controller.abort();
24
+ reject(new LocationError("cancelled"));
25
+ };
26
+ options.signal?.addEventListener("abort", abort, { once: true });
27
+ timer = setTimeout(() => {
28
+ controller.abort();
29
+ reject(new LocationError("timeout"));
30
+ }, milliseconds);
31
+ });
32
+ return await Promise.race([
33
+ Promise.resolve().then(() => {
34
+ if (controller.signal.aborted)
35
+ throw new LocationError("cancelled");
36
+ return run(controller.signal);
37
+ }),
38
+ deadline,
39
+ ]);
40
+ }
41
+ finally {
42
+ clearTimeout(timer);
43
+ if (abort)
44
+ options.signal?.removeEventListener("abort", abort);
45
+ controller.abort();
46
+ }
47
+ }
48
+ /** Validates the geo route response, keeping explicit null distinct from failure. */
49
+ export function toLocationObservation(body, checkedAt = Date.now()) {
50
+ if (typeof body !== "object" || body === null || !Number.isFinite(checkedAt))
51
+ return null;
52
+ const value = body;
53
+ if (value.place === null)
54
+ return { place: null, checkedAt };
55
+ const place = toPlace(value.place);
56
+ if (!place)
57
+ return null;
58
+ const cityName = typeof value.cityName === "string" ? value.cityName.trim() : "";
59
+ return {
60
+ place,
61
+ checkedAt,
62
+ ...(cityName && cityName.length <= 200 ? { cityName } : {}),
63
+ };
64
+ }
65
+ /** Fetches fresh IP hints with a deadline even when fetch/body reading ignores abort. */
66
+ export function fetchDetectedPlace(options = {}) {
67
+ return bounded(async (signal) => {
68
+ if (options.early) {
69
+ const found = await options.early;
70
+ if (!found)
71
+ throw new LocationError("unavailable");
72
+ return found;
73
+ }
74
+ const response = await (options.fetcher ?? fetch)(options.endpoint ?? "/api/geo", { cache: "no-store", signal });
75
+ if (!response.ok)
76
+ throw new LocationError("unavailable");
77
+ const observation = toLocationObservation(await response.json());
78
+ if (!observation)
79
+ throw new LocationError("unavailable");
80
+ return observation;
81
+ }, options, 5000);
82
+ }
83
+ /**
84
+ * Called from an explicit user action only. A cancelled/timed-out request ignores
85
+ * late callbacks; the browser permission prompt itself cannot be dismissed here.
86
+ */
87
+ export function locateDevice(options = {}) {
88
+ const browser = globalThis;
89
+ if ((options.secureContext ?? browser.isSecureContext) === false)
90
+ return Promise.reject(new LocationError("insecure"));
91
+ const device = options.device ?? browser.navigator?.geolocation;
92
+ if (!device)
93
+ return Promise.reject(new LocationError("unsupported"));
94
+ return bounded((signal) => new Promise((resolve, reject) => {
95
+ device.getCurrentPosition((position) => {
96
+ if (signal.aborted)
97
+ return;
98
+ const { latitude, longitude } = position.coords;
99
+ if (!toPlace({ name: "device", latitude, longitude }) ||
100
+ !Number.isFinite(position.timestamp)) {
101
+ reject(new LocationError("unavailable"));
102
+ return;
103
+ }
104
+ resolve({ latitude, longitude, timestamp: position.timestamp });
105
+ }, (error) => {
106
+ if (!signal.aborted)
107
+ reject(new LocationError(error.code === 1
108
+ ? "denied"
109
+ : error.code === 3
110
+ ? "timeout"
111
+ : "unavailable"));
112
+ }, {
113
+ enableHighAccuracy: options.enableHighAccuracy ?? false,
114
+ maximumAge: options.maximumAge ?? 60_000,
115
+ timeout: options.timeoutMs ?? 12_000,
116
+ });
117
+ }), options, 12_000);
118
+ }
119
+ /** Bounded city search, with app-owned debounce and cancellation of superseded queries. */
120
+ export function fetchPlaces(query, options = {}) {
121
+ return bounded(async (signal) => {
122
+ const response = await (options.fetcher ?? fetch)(`${options.endpoint ?? "/api/places"}?q=${encodeURIComponent(query)}`, { signal });
123
+ if (!response.ok)
124
+ throw new LocationError("unavailable");
125
+ const body = await response.json();
126
+ if (typeof body !== "object" ||
127
+ body === null ||
128
+ !Array.isArray(body.places))
129
+ throw new LocationError("unavailable");
130
+ return body.places
131
+ .map(toPlace)
132
+ .filter((place) => place !== null);
133
+ }, options, 5000);
134
+ }
135
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../source/src/geo/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,YAAY,CAAC;AAWjD,qFAAqF;AACrF,MAAM,OAAO,aAAc,SAAQ,KAAK;IACV;IAA5B,YAA4B,IAAqB;QAC/C,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QADA,SAAI,GAAJ,IAAI,CAAiB;QAE/C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AASD,KAAK,UAAU,OAAO,CACpB,GAAwC,EACxC,OAAwB,EACxB,QAAgB;IAEhB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,KAAgD,CAAC;IACrD,IAAI,KAA+B,CAAC;IACpC,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC;IACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC;QACrD,MAAM,IAAI,UAAU,CAAC,2BAA2B,CAAC,CAAC;IACpD,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;IAClE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;YAChD,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AC,KAAK,KAAK,IAAI,CAAC,CAAC;IACvC,CAAC,EACD,OAAO,EACP,IAAI,CACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { type Place, toPlace } from "./place.js";
2
+ export { parseVercelLocation, type DetectedPlace, type HeaderReader, } from "./vercel.js";
3
+ export { AUTOMATIC_LOCATION, type LocationPreference, toLocationPreference, } from "./preference.js";
4
+ export { clocksDiffer, deviceTimeZone, utcOffsetMinutes } from "./timeZone.js";
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../source/src/geo/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { toPlace } from "./place.js";
2
+ export { parseVercelLocation, } from "./vercel.js";
3
+ export { AUTOMATIC_LOCATION, toLocationPreference, } from "./preference.js";
4
+ export { clocksDiffer, deviceTimeZone, utcOffsetMinutes } from "./timeZone.js";
5
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../source/src/geo/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,mBAAmB,GAGpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAElB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A place the planetary hours, the moon and the geomancy reading are
3
+ * computed for (plan 072). It comes from the visitor's IP (`/api/geo`),
4
+ * a search of the GeoNames cities (`/api/places`), or the device's own
5
+ * position, and is shared by the server routes and the browser.
6
+ */
7
+ export interface Place {
8
+ /** City or town, or "Your location" for the device's position. */
9
+ name: string;
10
+ /** First-level subdivision's name ("England", "Texas"), when known. */
11
+ region?: string;
12
+ /** ISO 3166-1 alpha-2 country code ("GB"), when known. */
13
+ country?: string;
14
+ /** Degrees, -90 to 90. */
15
+ latitude: number;
16
+ /** Degrees, -180 to 180. */
17
+ longitude: number;
18
+ /** IANA time zone ("Europe/London"), when known. */
19
+ timezone?: string;
20
+ }
21
+ /**
22
+ * The value as a `Place`, or null when it is not one: coordinates must be
23
+ * finite numbers in range and the name a non-empty string. Optional fields
24
+ * that are malformed are dropped rather than failing the place. Used on
25
+ * anything that crosses a boundary: stored JSON, another server's answer.
26
+ */
27
+ export declare function toPlace(value: unknown): Place | null;
28
+ //# sourceMappingURL=place.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.d.ts","sourceRoot":"","sources":["../../../source/src/geo/place.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACpB,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAUD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI,CAyBpD"}
@@ -0,0 +1,41 @@
1
+ const COUNTRY = /^[A-Z]{2}$/;
2
+ function optionalText(value, max) {
3
+ if (typeof value !== "string")
4
+ return undefined;
5
+ const text = value.trim();
6
+ return text && text.length <= max ? text : undefined;
7
+ }
8
+ /**
9
+ * The value as a `Place`, or null when it is not one: coordinates must be
10
+ * finite numbers in range and the name a non-empty string. Optional fields
11
+ * that are malformed are dropped rather than failing the place. Used on
12
+ * anything that crosses a boundary: stored JSON, another server's answer.
13
+ */
14
+ export function toPlace(value) {
15
+ if (typeof value !== "object" || value === null)
16
+ return null;
17
+ const v = value;
18
+ const name = optionalText(v.name, 200);
19
+ const { latitude, longitude } = v;
20
+ if (!name ||
21
+ typeof latitude !== "number" ||
22
+ typeof longitude !== "number" ||
23
+ !Number.isFinite(latitude) ||
24
+ !Number.isFinite(longitude) ||
25
+ Math.abs(latitude) > 90 ||
26
+ Math.abs(longitude) > 180) {
27
+ return null;
28
+ }
29
+ const place = { name, latitude, longitude };
30
+ const region = optionalText(v.region, 200);
31
+ if (region)
32
+ place.region = region;
33
+ if (typeof v.country === "string" && COUNTRY.test(v.country)) {
34
+ place.country = v.country;
35
+ }
36
+ const timezone = optionalText(v.timezone, 64);
37
+ if (timezone)
38
+ place.timezone = timezone;
39
+ return place;
40
+ }
41
+ //# sourceMappingURL=place.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.js","sourceRoot":"","sources":["../../../source/src/geo/place.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,GAAG,YAAY,CAAC;AAE7B,SAAS,YAAY,CAAC,KAAc,EAAE,GAAW;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED;;;;;GAKG;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+1,16 @@
1
+ import type { Place } from "./place.js";
2
+ export { foldPlaceName, PLACES_FORMAT, type PlacesHeader, } from "./placesFormat.js";
3
+ /** Longer queries are cut; no place name needs more. */
4
+ export declare const MAX_QUERY_LENGTH = 64;
5
+ /** The parsed places file and a search over it. */
6
+ export interface PlaceIndex {
7
+ size: number;
8
+ search(q: string, limit?: number): Place[];
9
+ }
10
+ /**
11
+ * Parses a places file (format in `placesFormat.ts`). Throws on a header
12
+ * it doesn't know or a row count that doesn't match, rather than serving
13
+ * a half-read list.
14
+ */
15
+ export declare function createPlaceIndex(text: string): PlaceIndex;
16
+ //# sourceMappingURL=places.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"places.d.ts","sourceRoot":"","sources":["../../../source/src/geo/places.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMxC,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,YAAY,GAClB,MAAM,mBAAmB,CAAC;AAa3B,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAuBnC,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE,CAAC;CAC5C;AAgCD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CA0GzD"}
@@ -0,0 +1,154 @@
1
+ import { foldPlaceName, PLACES_FORMAT, } from "./placesFormat.js";
2
+ export { foldPlaceName, PLACES_FORMAT, } from "./placesFormat.js";
3
+ /**
4
+ * Common names for a country that are neither its ISO code nor a prefix of
5
+ * its English name, so "london, uk" and "paris, usa" narrow as people type
6
+ * them.
7
+ */
8
+ const COUNTRY_ALIASES = {
9
+ uk: "GB",
10
+ usa: "US",
11
+ uae: "AE",
12
+ };
13
+ /** Longer queries are cut; no place name needs more. */
14
+ export const MAX_QUERY_LENGTH = 64;
15
+ const MAX_LIMIT = 50;
16
+ /** Ranks, best first; a row takes the best that applies. */
17
+ const EXACT = 0;
18
+ const PREFIX = 1; // also an exact alternate name ("munchen" → Munich)
19
+ const WORD_PREFIX = 2; // "york" in "new york"
20
+ const ALTERNATE_PREFIX = 3;
21
+ const DISTRICT = 4; // any match on a city's district ("Zürich (Kreis 11)")
22
+ function regionsOf(header) {
23
+ const names = new Intl.DisplayNames(["en"], { type: "region" });
24
+ const countryNames = new Map();
25
+ return header.regions.map(([country, name, code = ""]) => {
26
+ let countryName = countryNames.get(country);
27
+ if (countryName === undefined) {
28
+ try {
29
+ countryName = foldPlaceName(names.of(country) ?? country);
30
+ }
31
+ catch {
32
+ countryName = country.toLowerCase();
33
+ }
34
+ countryNames.set(country, countryName);
35
+ }
36
+ return {
37
+ country,
38
+ name,
39
+ folded: foldPlaceName(name),
40
+ countryName,
41
+ code: code.toLowerCase(),
42
+ };
43
+ });
44
+ }
45
+ /**
46
+ * Parses a places file (format in `placesFormat.ts`). Throws on a header
47
+ * it doesn't know or a row count that doesn't match, rather than serving
48
+ * a half-read list.
49
+ */
50
+ export function createPlaceIndex(text) {
51
+ const end = text.indexOf("\n");
52
+ const header = JSON.parse(text.slice(0, end));
53
+ if (header.format !== PLACES_FORMAT ||
54
+ !Array.isArray(header.timezones) ||
55
+ !Array.isArray(header.regions)) {
56
+ throw new Error("places: unknown file format");
57
+ }
58
+ const regions = regionsOf(header);
59
+ const rows = [];
60
+ for (const line of text.slice(end + 1).split("\n")) {
61
+ if (!line)
62
+ continue;
63
+ const [name, ascii, region, latitude, longitude, timezone, district, alts] = line.split("\t");
64
+ const r = regions[Number(region)];
65
+ const tz = header.timezones[Number(timezone)];
66
+ const lat = Number(latitude);
67
+ const lon = Number(longitude);
68
+ if (!name || !r || !tz || !Number.isFinite(lat) || !Number.isFinite(lon)) {
69
+ throw new Error(`places: bad row ${rows.length + 1}`);
70
+ }
71
+ const place = {
72
+ name,
73
+ ...(r.name ? { region: r.name } : {}),
74
+ country: r.country,
75
+ latitude: lat,
76
+ longitude: lon,
77
+ timezone: tz,
78
+ };
79
+ const folded = foldPlaceName(name);
80
+ const foldedAscii = ascii ? foldPlaceName(ascii) : folded;
81
+ rows.push({
82
+ place,
83
+ region: Number(region),
84
+ keys: foldedAscii === folded ? [folded] : [folded, foldedAscii],
85
+ alternates: alts ? alts.split("|") : [],
86
+ district: district === "1",
87
+ });
88
+ }
89
+ if (rows.length !== header.rows) {
90
+ throw new Error(`places: ${rows.length} rows, header says ${header.rows}`);
91
+ }
92
+ /** Which regions every "where" term after the first comma allows. */
93
+ function allowedRegions(wheres) {
94
+ if (!wheres.length)
95
+ return null;
96
+ return regions.map((r) => wheres.every((w) => r.country.toLowerCase() === w ||
97
+ COUNTRY_ALIASES[w] === r.country ||
98
+ // Exactly: "n" or "ni" is not Northern Ireland ("NIR").
99
+ (r.code !== "" && r.code === w) ||
100
+ r.countryName.startsWith(w) ||
101
+ r.folded.startsWith(w)));
102
+ }
103
+ function rank(row, q) {
104
+ if (row.keys.includes(q))
105
+ return EXACT;
106
+ if (row.keys.some((k) => k.startsWith(q)) || row.alternates.includes(q)) {
107
+ return PREFIX;
108
+ }
109
+ if (row.keys.some((k) => k.includes(` ${q}`) || k.includes(`-${q}`))) {
110
+ return WORD_PREFIX;
111
+ }
112
+ if (row.alternates.some((a) => a.startsWith(q)))
113
+ return ALTERNATE_PREFIX;
114
+ return -1;
115
+ }
116
+ return {
117
+ size: rows.length,
118
+ search(q, limit = 8) {
119
+ const text = q.trim().slice(0, MAX_QUERY_LENGTH);
120
+ if (text.length < 2)
121
+ return [];
122
+ const [first, ...rest] = text.split(",");
123
+ const name = foldPlaceName(first);
124
+ if (name.length < 2)
125
+ return [];
126
+ const allowed = allowedRegions(rest.map(foldPlaceName).filter((w) => w !== ""));
127
+ const max = Number.isFinite(limit)
128
+ ? Math.min(Math.max(Math.floor(limit), 1), MAX_LIMIT)
129
+ : 8;
130
+ // Rows are in population order, so each tier fills biggest first.
131
+ const tiers = [[], [], [], [], []];
132
+ for (const row of rows) {
133
+ if (allowed && !allowed[row.region])
134
+ continue;
135
+ let tier = rank(row, name);
136
+ if (tier < 0)
137
+ continue;
138
+ if (row.district)
139
+ tier = DISTRICT;
140
+ if (tiers[tier].length < max)
141
+ tiers[tier].push(row.place);
142
+ // Nothing found later can outrank a full first tier.
143
+ if (tiers[EXACT].length >= max)
144
+ break;
145
+ }
146
+ // Copies, so a caller can't change the index.
147
+ return tiers
148
+ .flat()
149
+ .slice(0, max)
150
+ .map((place) => ({ ...place }));
151
+ },
152
+ };
153
+ }
154
+ //# sourceMappingURL=places.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"places.js","sourceRoot":"","sources":["../../../source/src/geo/places.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,eAAe,GAA2B;IAC9C,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,wDAAwD;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,SAAS,GAAG,EAAE,CAAC;AA4BrB,4DAA4D;AAC5D,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,oDAAoD;AACtE,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,uBAAuB;AAC9C,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,uDAAuD;AAE3E,SAAS,SAAS,CAAC,MAAoB;IACrC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI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AAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The format of `places.tsv`, shared by the script that writes it
3
+ * (`scripts/geonames/build.ts`) and the search that reads it
4
+ * (`places.ts`). Pure and free of `server-only` so the build script can
5
+ * import it; nothing here holds the data itself.
6
+ *
7
+ * The file is one JSON header line, then one tab-separated line per place
8
+ * in descending population order (the order is the ranking, so there is
9
+ * no population column):
10
+ *
11
+ * ```
12
+ * {"format":2,...,"rows":N,"timezones":[...],"regions":[["GB","England","ENG"],["UA","Kyiv City"],...]}
13
+ * name ascii region latitude longitude timezone district alternates
14
+ * ```
15
+ *
16
+ * - `ascii`: GeoNames' ASCII name, empty when it equals `name`.
17
+ * - `region`, `timezone`: indexes into the header's lists.
18
+ * - `latitude`, `longitude`: degrees rounded to 3 decimals (~100 m).
19
+ * - `district`: `1` for a section of a city (GeoNames `PPLX`), else empty.
20
+ * - `alternates`: `|`-separated, already folded (`foldPlaceName`).
21
+ */
22
+ /** Bumped whenever a column or the header changes meaning. */
23
+ export declare const PLACES_FORMAT = 2;
24
+ /** The JSON header on the file's first line. */
25
+ export interface PlacesHeader {
26
+ format: typeof PLACES_FORMAT;
27
+ /** Which GeoNames files, from when. */
28
+ source: string;
29
+ /** Licence and a pointer to what was changed. */
30
+ license: string;
31
+ /** Number of place lines that follow. */
32
+ rows: number;
33
+ /** IANA time zones, indexed by the timezone column. */
34
+ timezones: string[];
35
+ /**
36
+ * `[country code, first-level region name or ""]`, indexed by the region
37
+ * column, with the region's code third when it is letters (GeoNames'
38
+ * admin1 code: "TX", "DC", "ENG"; not Canada's "08").
39
+ */
40
+ regions: ([string, string] | [string, string, string])[];
41
+ }
42
+ /**
43
+ * Lower case, without accents or repeated spaces, so "São Paulo", "sao
44
+ * paulo" and "SAO PAULO" compare equal. The build folds the alternates
45
+ * with this and the search folds names and queries with it, so the two
46
+ * must stay one function.
47
+ */
48
+ export declare function foldPlaceName(text: string): string;
49
+ //# sourceMappingURL=placesFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placesFormat.d.ts","sourceRoot":"","sources":["../../../source/src/geo/placesFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,8DAA8D;AAC9D,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,aAAa,CAAC;IAC7B,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;;;OAIG;IACH,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;CAC1D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOlD"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The format of `places.tsv`, shared by the script that writes it
3
+ * (`scripts/geonames/build.ts`) and the search that reads it
4
+ * (`places.ts`). Pure and free of `server-only` so the build script can
5
+ * import it; nothing here holds the data itself.
6
+ *
7
+ * The file is one JSON header line, then one tab-separated line per place
8
+ * in descending population order (the order is the ranking, so there is
9
+ * no population column):
10
+ *
11
+ * ```
12
+ * {"format":2,...,"rows":N,"timezones":[...],"regions":[["GB","England","ENG"],["UA","Kyiv City"],...]}
13
+ * name ascii region latitude longitude timezone district alternates
14
+ * ```
15
+ *
16
+ * - `ascii`: GeoNames' ASCII name, empty when it equals `name`.
17
+ * - `region`, `timezone`: indexes into the header's lists.
18
+ * - `latitude`, `longitude`: degrees rounded to 3 decimals (~100 m).
19
+ * - `district`: `1` for a section of a city (GeoNames `PPLX`), else empty.
20
+ * - `alternates`: `|`-separated, already folded (`foldPlaceName`).
21
+ */
22
+ /** Bumped whenever a column or the header changes meaning. */
23
+ export const PLACES_FORMAT = 2;
24
+ /**
25
+ * Lower case, without accents or repeated spaces, so "São Paulo", "sao
26
+ * paulo" and "SAO PAULO" compare equal. The build folds the alternates
27
+ * with this and the search folds names and queries with it, so the two
28
+ * must stay one function.
29
+ */
30
+ export function foldPlaceName(text) {
31
+ return text
32
+ .normalize("NFD")
33
+ .replace(/\p{M}/gu, "")
34
+ .toLowerCase()
35
+ .replace(/\s+/g, " ")
36
+ .trim();
37
+ }
38
+ //# sourceMappingURL=placesFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placesFormat.js","sourceRoot":"","sources":["../../../source/src/geo/placesFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAqB/B;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI;SACR,SAAS,CAAC,KAAK,CAAC;SAChB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;SACtB,WAAW,EAAE;SACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC"}