@tempo-kit/plugin-geo 0.0.0-stage → 3.0.0-rc.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/CHANGELOG.md +125 -0
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/dist/index.d.ts +678 -0
- package/dist/index.global.min.js +1 -0
- package/dist/index.js +5316 -0
- package/dist/install.d.ts +3 -0
- package/dist/install.global.min.js +1 -0
- package/dist/install.js +5319 -0
- package/package.json +62 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
import { TempoPlugin } from 'tempo-kit/plugin/sdk';
|
|
2
|
+
export { LocaleSyncMode, resolveCulturalLocale } from 'tempo-fns';
|
|
3
|
+
|
|
4
|
+
declare module '#library/type.library.js' {
|
|
5
|
+
interface TypeValueMap<T> {
|
|
6
|
+
BoundedCache: {
|
|
7
|
+
type: 'BoundedCache';
|
|
8
|
+
value: BoundedCache<any, any>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Type guard predicate checking if a value is an authentic BoundedCache instance */
|
|
13
|
+
type BoundedCacheTypeGuard = <Key = string, Val = string>(val: unknown) => val is BoundedCache<Key, Val>;
|
|
14
|
+
/**
|
|
15
|
+
* ## BoundedCache
|
|
16
|
+
* High-performance Map implementation enforcing maximum capacity (LRU) and TTL eviction.
|
|
17
|
+
* Supports static keys (immortal glossary definitions) and date-salt staleness purging.
|
|
18
|
+
*/
|
|
19
|
+
declare class BoundedCache<K = string, V = string> extends Map<K, V> {
|
|
20
|
+
#private;
|
|
21
|
+
maxSize: number;
|
|
22
|
+
ttl: number;
|
|
23
|
+
/** Type guard to check if a value is an authentic BoundedCache instance */
|
|
24
|
+
static isBoundedCache: BoundedCacheTypeGuard;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a bounded cache with configurable capacity and entry lifetime.
|
|
27
|
+
*
|
|
28
|
+
* @param maxSize - Maximum number of non-static entries retained
|
|
29
|
+
* @param ttl - Default time-to-live for entries in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
constructor(maxSize?: number, ttl?: number);
|
|
32
|
+
/**
|
|
33
|
+
* Purges TTL-expired entries.
|
|
34
|
+
*/
|
|
35
|
+
evictExpired(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Register an immortal static key (e.g. business glossary term).
|
|
38
|
+
* Static keys bypass TTL expiration and LRU capacity eviction.
|
|
39
|
+
*/
|
|
40
|
+
setStatic(key: K, value: V): this;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a key is a static key.
|
|
43
|
+
*/
|
|
44
|
+
isStatic(key: K): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves a value from the cache by key. Evaluates TTL expiration via `#expires`
|
|
47
|
+
* specifically for the requested key, and updates LRU ordering by deleting and re-inserting
|
|
48
|
+
* the key in the underlying Map. Leaves the expiration deadline unchanged.
|
|
49
|
+
*
|
|
50
|
+
* @param key - The cache key to retrieve
|
|
51
|
+
* @returns The cached value, or undefined if not found or expired
|
|
52
|
+
*/
|
|
53
|
+
get(key: K): V | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a key exists in the cache and is not expired.
|
|
56
|
+
* Automatically evicts expired entries on access.
|
|
57
|
+
*
|
|
58
|
+
* @param key - The cache key to check
|
|
59
|
+
* @returns True if the key exists and is not expired, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
has(key: K): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the number of entries in the cache after evicting expired entries.
|
|
64
|
+
*/
|
|
65
|
+
get size(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Executes a callback for each cache entry after evicting expired entries.
|
|
68
|
+
*
|
|
69
|
+
* @param callbackfn - Function to execute for each entry
|
|
70
|
+
* @param thisArg - Optional value to use as `this` when executing the callback
|
|
71
|
+
*/
|
|
72
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
73
|
+
/**
|
|
74
|
+
* Sets a key-value pair in the cache, enforcing LRU eviction.
|
|
75
|
+
* If finite-TTL is configured, entries retain their original absolute expiration deadline
|
|
76
|
+
* unless an explicit `ttl` override is passed.
|
|
77
|
+
* If the cache exceeds maxSize, the oldest non-static entry is removed.
|
|
78
|
+
*
|
|
79
|
+
* @param key - The cache key to set
|
|
80
|
+
* @param value - The value to store
|
|
81
|
+
* @param ttl - Optional custom time-to-live in milliseconds for this specific entry
|
|
82
|
+
* @returns This cache instance for chaining
|
|
83
|
+
*/
|
|
84
|
+
set(key: K, value: V, ttl?: number): this;
|
|
85
|
+
/**
|
|
86
|
+
* Deletes a key from the cache, removing its expiration and static key markers.
|
|
87
|
+
*
|
|
88
|
+
* @param key - The cache key to delete
|
|
89
|
+
* @returns True if the key was deleted, false if it did not exist
|
|
90
|
+
*/
|
|
91
|
+
delete(key: K): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Deletes all cache entries whose keys start with the specified prefix.
|
|
94
|
+
* The prefix comparison is case-insensitive.
|
|
95
|
+
*
|
|
96
|
+
* @param prefix - The prefix string to match against cache keys
|
|
97
|
+
* @returns The number of entries deleted
|
|
98
|
+
*/
|
|
99
|
+
deletePrefix(prefix: string): number;
|
|
100
|
+
/**
|
|
101
|
+
* Purges cache entries.
|
|
102
|
+
* If `count` is specified, evicts up to `count` oldest non-static entries.
|
|
103
|
+
* If omitted, clears all entries, including static entries.
|
|
104
|
+
*
|
|
105
|
+
* @param count - Optional number of entries to evict. If omitted, clears all entries.
|
|
106
|
+
*/
|
|
107
|
+
clear(count?: number): void;
|
|
108
|
+
/**
|
|
109
|
+
* Returns an iterator of cache keys after evicting expired entries.
|
|
110
|
+
*
|
|
111
|
+
* @returns Iterator of cache keys
|
|
112
|
+
*/
|
|
113
|
+
keys(): MapIterator<K>;
|
|
114
|
+
/**
|
|
115
|
+
* Returns an iterator of cache values after evicting expired entries.
|
|
116
|
+
*
|
|
117
|
+
* @returns Iterator of cache values
|
|
118
|
+
*/
|
|
119
|
+
values(): MapIterator<V>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns an iterator of cache entries after evicting expired entries.
|
|
122
|
+
*
|
|
123
|
+
* @returns Iterator of [key, value] pairs
|
|
124
|
+
*/
|
|
125
|
+
entries(): MapIterator<[K, V]>;
|
|
126
|
+
/**
|
|
127
|
+
* Returns an iterator of cache entries after evicting expired entries, making the cache iterable.
|
|
128
|
+
*
|
|
129
|
+
* @returns Iterator of [key, value] pairs
|
|
130
|
+
*/
|
|
131
|
+
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
132
|
+
/**
|
|
133
|
+
* Returns a plain key-value object of all active non-expired cache entries.
|
|
134
|
+
* Filters out non-string keys to prevent lossy key conversions or collisions (e.g. numeric 1 vs string "1").
|
|
135
|
+
*/
|
|
136
|
+
toJSON(): Record<string, V>;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a BoundedCache from an iterable of key-value pairs.
|
|
139
|
+
*
|
|
140
|
+
* @param entries - Iterable of [key, value] pairs to populate the cache
|
|
141
|
+
* @param maxSize - Maximum number of entries (default: 1000)
|
|
142
|
+
* @param ttl - Time-to-live in milliseconds (default: 24 hours)
|
|
143
|
+
* @returns A new BoundedCache instance
|
|
144
|
+
*/
|
|
145
|
+
static fromEntries<K = string, V = string>(entries: Iterable<readonly [K, V]>, maxSize?: number, ttl?: number): BoundedCache<K, V>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Supported hemisphere zones including the equatorial band.
|
|
150
|
+
*/
|
|
151
|
+
type GeoSphere = 'north' | 'south' | 'equator';
|
|
152
|
+
interface GeoLookupResult {
|
|
153
|
+
lat?: number | undefined;
|
|
154
|
+
lng?: number | undefined;
|
|
155
|
+
latitude?: number | undefined;
|
|
156
|
+
longitude?: number | undefined;
|
|
157
|
+
elevation?: number | undefined;
|
|
158
|
+
sphere?: GeoSphere | string | undefined;
|
|
159
|
+
country?: string | undefined;
|
|
160
|
+
city?: string | undefined;
|
|
161
|
+
timezone?: string | undefined;
|
|
162
|
+
status?: string | undefined;
|
|
163
|
+
error?: string | undefined;
|
|
164
|
+
[key: string]: any;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Standard interface for pluggable geocoding and geolocation providers.
|
|
168
|
+
*/
|
|
169
|
+
interface GeoProvider {
|
|
170
|
+
/** Unique identifier or provider name */
|
|
171
|
+
readonly name: string;
|
|
172
|
+
/** Resolves geographic coordinates and location metadata */
|
|
173
|
+
lookup(opts?: Record<string, any>): Promise<GeoLookupResult | null>;
|
|
174
|
+
/** Optional reverse geocoding from coordinates to location details */
|
|
175
|
+
reverseGeocode?(coords: CoordinateInput, opts?: Record<string, any>): Promise<GeoConfig | null>;
|
|
176
|
+
/** Optional forward geocoding from place/address query to coordinates */
|
|
177
|
+
forwardGeocode?(query: string, opts?: Record<string, any>): Promise<ResolvedCoordinates | null>;
|
|
178
|
+
}
|
|
179
|
+
interface ResolvedCoordinates extends GeoConfig {
|
|
180
|
+
lat: number;
|
|
181
|
+
lng: number;
|
|
182
|
+
[key: string]: any;
|
|
183
|
+
}
|
|
184
|
+
interface GeoOptions {
|
|
185
|
+
/** Latitude coordinate in degrees */
|
|
186
|
+
latitude?: number | undefined;
|
|
187
|
+
/** Latitude coordinate alias in degrees @internal */
|
|
188
|
+
lat?: number | undefined;
|
|
189
|
+
/** Longitude coordinate in degrees */
|
|
190
|
+
longitude?: number | undefined;
|
|
191
|
+
/** Longitude coordinate alias in degrees @internal */
|
|
192
|
+
lng?: number | undefined;
|
|
193
|
+
/** Longitude coordinate alias in degrees @internal */
|
|
194
|
+
lon?: number | undefined;
|
|
195
|
+
/** Longitude coordinate alias in degrees @internal */
|
|
196
|
+
long?: number | undefined;
|
|
197
|
+
/** Altitude / Elevation in meters above sea level */
|
|
198
|
+
elevation?: number | undefined;
|
|
199
|
+
/** Inferred or explicit hemisphere ('north' | 'south' | 'equator') */
|
|
200
|
+
sphere?: GeoSphere | string | undefined;
|
|
201
|
+
/** ISO country code (e.g. 'US', 'AU') */
|
|
202
|
+
country?: string | undefined;
|
|
203
|
+
/** City or locality name */
|
|
204
|
+
city?: string | undefined;
|
|
205
|
+
/** IANA Time Zone ID (e.g. 'Australia/Sydney') */
|
|
206
|
+
timezone?: string | undefined;
|
|
207
|
+
/** Time zone alias @internal */
|
|
208
|
+
tz?: string | undefined;
|
|
209
|
+
/** Custom or future string/number key property */
|
|
210
|
+
[key: string]: any;
|
|
211
|
+
/** Custom symbol key property */
|
|
212
|
+
[key: symbol]: any;
|
|
213
|
+
}
|
|
214
|
+
interface GeoConfig {
|
|
215
|
+
/** Latitude coordinate in degrees (-90 to 90) */
|
|
216
|
+
readonly latitude?: number | undefined;
|
|
217
|
+
/** Longitude coordinate in degrees (-180 to 180) */
|
|
218
|
+
readonly longitude?: number | undefined;
|
|
219
|
+
/** Altitude / Elevation in meters above sea level */
|
|
220
|
+
readonly elevation?: number | undefined;
|
|
221
|
+
/** Inferred or explicit hemisphere ('north' | 'south' | 'equator') */
|
|
222
|
+
readonly sphere?: GeoSphere | string | undefined;
|
|
223
|
+
/** ISO country code (e.g. 'US', 'AU') */
|
|
224
|
+
readonly country?: string | undefined;
|
|
225
|
+
/** City or locality name */
|
|
226
|
+
readonly city?: string | undefined;
|
|
227
|
+
/** IANA Time Zone ID (e.g. 'Australia/Sydney') */
|
|
228
|
+
readonly timezone?: string | undefined;
|
|
229
|
+
/** Custom or future string/number key property */
|
|
230
|
+
readonly [key: string]: any;
|
|
231
|
+
/** Custom symbol key property */
|
|
232
|
+
readonly [key: symbol]: any;
|
|
233
|
+
}
|
|
234
|
+
interface CoordinateInput {
|
|
235
|
+
geo?: GeoOptions | undefined;
|
|
236
|
+
latitude?: number | undefined;
|
|
237
|
+
lat?: number | undefined;
|
|
238
|
+
longitude?: number | undefined;
|
|
239
|
+
lng?: number | undefined;
|
|
240
|
+
lon?: number | undefined;
|
|
241
|
+
long?: number | undefined;
|
|
242
|
+
elevation?: number | undefined;
|
|
243
|
+
sphere?: GeoSphere | string | undefined;
|
|
244
|
+
country?: string | undefined;
|
|
245
|
+
city?: string | undefined;
|
|
246
|
+
timezone?: string | undefined;
|
|
247
|
+
tz?: string | undefined;
|
|
248
|
+
config?: Record<string, any> | undefined;
|
|
249
|
+
[key: string]: any;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Canonical geographic property keys used for property segregation and custom key preservation.
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
declare const GEO_PROPERTIES: readonly ["latitude", "lat", "longitude", "lng", "lon", "long", "elevation", "sphere", "country", "city", "timezone", "tz"];
|
|
256
|
+
/**
|
|
257
|
+
* Extracts and coerces latitude and longitude from input object (options, config, or instance)
|
|
258
|
+
* into a canonical `{ latitude, longitude, ... }` GeoConfig object.
|
|
259
|
+
* Enforces coordinate boundaries (-90 to 90 for lat, -180 to 180 for lng), 3-decimal rounding,
|
|
260
|
+
* and automatic hemisphere inference ('north' | 'south' | 'equator').
|
|
261
|
+
*
|
|
262
|
+
* @param input - Optional object containing coordinate or geo properties
|
|
263
|
+
*/
|
|
264
|
+
declare const coerceGeo: (input?: any) => GeoConfig | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Synchronously retrieves stashed geolocation from storage or memory cache if present.
|
|
267
|
+
* Supports optional tenant key or options object for multi-tenant isolation.
|
|
268
|
+
*
|
|
269
|
+
* @param keyOrOpts - Optional tenant key or lookup options containing key/ip
|
|
270
|
+
* @returns Cached GeoConfig or undefined
|
|
271
|
+
*/
|
|
272
|
+
declare const getStashedGeo: (keyOrOpts?: string | Record<string, any>) => GeoConfig | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* Explicitly stashes geolocation coordinates in storage with an optional TTL (default: 24 hours).
|
|
275
|
+
* Supports optional tenant key or options object for multi-tenant isolation.
|
|
276
|
+
*
|
|
277
|
+
* @param coords - Geolocation coordinates and metadata to stash
|
|
278
|
+
* @param ttl - Time-to-live in milliseconds (default: 24 hours)
|
|
279
|
+
* @param keyOrOpts - Optional tenant key or lookup options containing key/ip
|
|
280
|
+
*/
|
|
281
|
+
declare const stashGeo: (coords: GeoConfig, ttl?: number, keyOrOpts?: string | Record<string, any>) => void;
|
|
282
|
+
/**
|
|
283
|
+
* Clears stashed geolocation coordinates from storage.
|
|
284
|
+
* Supports optional tenant key or options object for multi-tenant isolation.
|
|
285
|
+
*
|
|
286
|
+
* @param keyOrOpts - Optional tenant key or lookup options containing key/ip
|
|
287
|
+
*/
|
|
288
|
+
declare const clearStashedGeo: (keyOrOpts?: string | Record<string, any>) => void;
|
|
289
|
+
/**
|
|
290
|
+
* Sets the active custom geolocation provider gateway.
|
|
291
|
+
*
|
|
292
|
+
* @param provider - GeoProvider implementation or undefined to restore default provider
|
|
293
|
+
*/
|
|
294
|
+
declare function setGeoProvider(provider?: GeoProvider): void;
|
|
295
|
+
/**
|
|
296
|
+
* Gets the currently registered custom geolocation provider.
|
|
297
|
+
*/
|
|
298
|
+
declare function getGeoProvider(): GeoProvider | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* Universal geolocation lookup dispatcher.
|
|
301
|
+
* Automatically delegates to custom provider, browser `geoLocation()`, or server `serverGeoLocation()`.
|
|
302
|
+
* When coordinates are resolved, stashes the result in storage with a 24-hour TTL for fast cached lookups.
|
|
303
|
+
*
|
|
304
|
+
* @param opts - Lookup options passed down to environment handler (e.g. `{ refresh: true, key: 'tenant-1', provider }`)
|
|
305
|
+
*/
|
|
306
|
+
declare const geoLookup: (opts?: Record<string, any>) => Promise<GeoLookupResult>;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Reverse geocodes coordinates to address or location metadata using the active or provided GeoProvider.
|
|
310
|
+
* Employs 2-decimal spatial deduplication with BoundedCache (24h TTL).
|
|
311
|
+
*
|
|
312
|
+
* @param coords - Coordinate input
|
|
313
|
+
* @param opts - Options including optional provider override and { refresh: true }
|
|
314
|
+
*/
|
|
315
|
+
declare function reverseGeocode(coords: CoordinateInput, opts?: Record<string, any>): Promise<GeoConfig | null>;
|
|
316
|
+
/**
|
|
317
|
+
* Forward geocodes an address or place query string into coordinates using the active or provided GeoProvider.
|
|
318
|
+
*
|
|
319
|
+
* @param query - Address or place search query
|
|
320
|
+
* @param opts - Options including optional provider override
|
|
321
|
+
*/
|
|
322
|
+
declare function forwardGeocode(query: string, opts?: Record<string, any>): Promise<ResolvedCoordinates | null>;
|
|
323
|
+
/**
|
|
324
|
+
* Universal coordinate resolver.
|
|
325
|
+
* Extracts latitude and longitude from input object (instance, config, options),
|
|
326
|
+
* or triggers `geoLookup()` if coordinates are omitted.
|
|
327
|
+
* Supports opt-in reverse lookup (`{ reverse: true }`).
|
|
328
|
+
* Enforces 3-decimal rounding and returns rich metadata when resolved.
|
|
329
|
+
*
|
|
330
|
+
* @param input - Optional object containing coordinate properties
|
|
331
|
+
* @param opts - Fallback geoLookup options if coordinates are missing from input
|
|
332
|
+
*/
|
|
333
|
+
declare const resolveGeoCoordinates: (input?: CoordinateInput, opts?: Record<string, any>) => Promise<ResolvedCoordinates | null>;
|
|
334
|
+
|
|
335
|
+
/** Generic Record */ type Property<T> = Record<PropertyKey, T>;
|
|
336
|
+
/** Generic Record or Array */ type Obj = Property<any> | Array<any>;
|
|
337
|
+
/** Own properties of an Array, Object, Map or Enum */
|
|
338
|
+
type WellKnownSymbols = {
|
|
339
|
+
[K in keyof SymbolConstructor]: SymbolConstructor[K] extends symbol ? SymbolConstructor[K] : never;
|
|
340
|
+
}[keyof SymbolConstructor];
|
|
341
|
+
/** Detects if T is an Enumify proxy object or contains Enumify type branding */
|
|
342
|
+
type IsEnumProxy<T> = [
|
|
343
|
+
T
|
|
344
|
+
] extends [{
|
|
345
|
+
readonly [Symbol.toStringTag]: 'Enumify';
|
|
346
|
+
}] ? true : [
|
|
347
|
+
T
|
|
348
|
+
] extends [{
|
|
349
|
+
[Symbol.toStringTag]: 'Enumify';
|
|
350
|
+
}] ? true : false;
|
|
351
|
+
/** Extracts the keys of an object type, returning numeric indices for array types or string/symbol keys excluding ignored keys for objects */
|
|
352
|
+
type KeyOf<T extends Obj> = IsEnumProxy<T> extends true ? (T extends {
|
|
353
|
+
[Symbol.iterator](): IterableIterator<readonly [infer K extends PropertyKey, any]>;
|
|
354
|
+
} ? K : Exclude<Extract<keyof T, string | symbol>, WellKnownSymbols>) : T extends Array<any> ? number : Exclude<Extract<keyof T, string | symbol>, WellKnownSymbols>;
|
|
355
|
+
/** Extracts the value types from an object or array (including readonly arrays) */
|
|
356
|
+
type ValueOf<T extends Obj | readonly any[]> = IsEnumProxy<T> extends true ? (T extends {
|
|
357
|
+
[Symbol.iterator](): IterableIterator<readonly [any, infer V]>;
|
|
358
|
+
} ? V : T[KeyOf<T> & keyof T]) : T extends readonly any[] ? T[number] : T[KeyOf<T> & keyof T];
|
|
359
|
+
/** Parses a string literal type into a numeric literal type */
|
|
360
|
+
type ParseInt<T> = T extends `${infer N extends number}` ? N : never;
|
|
361
|
+
type TupleEntry<T extends readonly unknown[], I extends unknown[] = [], R = never> = T extends readonly [infer Head, ...infer Tail] ? TupleEntry<Tail, [...I, unknown], R | [`${I["length"]}`, Head]> : R;
|
|
362
|
+
type ObjectEntry<T extends Property<any>> = T extends object ? {
|
|
363
|
+
[K in keyof T]: [T[K]] extends [never] ? never : [K, Required<T>[K]];
|
|
364
|
+
}[keyof T] extends infer E ? E extends [infer K extends string | number, infer V] ? [`${K}`, V] : E extends [infer K extends symbol, infer V] ? [K, V] : never : never : never;
|
|
365
|
+
/** if T extends readonly[] => [number, T], if T extends {} => [key:string, T] */
|
|
366
|
+
type Entry<T extends Property<any>> = T extends readonly [unknown, ...unknown[]] ? TupleEntry<T> : T extends ReadonlyArray<infer U> ? [`${number}`, U] : ObjectEntry<T>;
|
|
367
|
+
/** assign array indexes as values in an object */
|
|
368
|
+
type Index<T extends readonly any[]> = {
|
|
369
|
+
[K in Entry<T> as `${K[1]}`]: ParseInt<K[0]>;
|
|
370
|
+
};
|
|
371
|
+
/** reverse a Record */
|
|
372
|
+
type Invert<T extends Record<keyof T, keyof any>> = {
|
|
373
|
+
[K in keyof T as T[K]]: K;
|
|
374
|
+
};
|
|
375
|
+
type LooseProperty = (PropertyKey & {});
|
|
376
|
+
/** Loose property key */
|
|
377
|
+
type LooseKey<K extends PropertyKey = string> = K | LooseProperty;
|
|
378
|
+
|
|
379
|
+
declare module '#library/type.library.js' {
|
|
380
|
+
interface TypeValueMap<T> {
|
|
381
|
+
Enumify: {
|
|
382
|
+
type: 'Enumify';
|
|
383
|
+
value: Enum.wrap<T>;
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/** key to use for identifying Enumify objects */
|
|
388
|
+
declare const tag = "Enumify";
|
|
389
|
+
/** Enum iterator & metadata methods */
|
|
390
|
+
type EnumMethods<T extends Property<any> = any> = {
|
|
391
|
+
/** iterate through all Enum entries */
|
|
392
|
+
readonly [Symbol.iterator]: () => IterableIterator<readonly [KeyOf<T>, ValueOf<T>]>;
|
|
393
|
+
/** used to identify the Enumify type */
|
|
394
|
+
readonly [Symbol.toStringTag]: typeof tag;
|
|
395
|
+
};
|
|
396
|
+
/** Enum properties with symbol metadata */
|
|
397
|
+
type EnumifyType<T extends Property<any> = any> = Readonly<T> & EnumMethods<T>;
|
|
398
|
+
/** Check if a value is a genuine Enum instance (mirrors Array.isArray) */
|
|
399
|
+
declare function isEnum<T extends Property<any> = any>(val: unknown): val is Enum.wrap<T>;
|
|
400
|
+
/**
|
|
401
|
+
* # Enum
|
|
402
|
+
* Static reflection and helper suite for Enumify objects.
|
|
403
|
+
* Immune to member property shadowing and replaces legacy prototype methods.
|
|
404
|
+
*/
|
|
405
|
+
declare const enumMethods: {
|
|
406
|
+
/** Create a frozen Enum instance from a dictionary or string array (preferred over `enumify`) */
|
|
407
|
+
from: typeof enumify;
|
|
408
|
+
/** Check if a value is a genuine Enum instance (mirrors Array.isArray) */
|
|
409
|
+
isEnum: typeof isEnum;
|
|
410
|
+
/** Check if a key exists in an Enum or any inherited parent Enum */
|
|
411
|
+
has<T extends Property<any>>(enumObj: T, key: LooseKey<KeyOf<T>> | PropertyKey): key is KeyOf<T>;
|
|
412
|
+
/** Check if a key exists directly as an own property on an Enum (mirrors Object.hasOwn) */
|
|
413
|
+
hasOwn<T extends Property<any>>(enumObj: T, key: LooseKey<KeyOf<T>> | PropertyKey): key is KeyOf<T>;
|
|
414
|
+
/** Safely retrieve a member value by key, returning undefined if absent */
|
|
415
|
+
get<T extends Property<any>>(enumObj: T, key: LooseKey<KeyOf<T>> | PropertyKey): ValueOf<T> | undefined;
|
|
416
|
+
/** Safely extract all enum member keys, immune to shadowing */
|
|
417
|
+
keys<T extends Property<any>>(enumObj: T): readonly KeyOf<T>[];
|
|
418
|
+
/** Safely extract all enum member values, immune to shadowing */
|
|
419
|
+
values<T extends Property<any>>(enumObj: T): readonly ValueOf<T>[];
|
|
420
|
+
/** Safely extract [key, value] pairs, immune to shadowing */
|
|
421
|
+
entries<T extends Property<any>>(enumObj: T): readonly (readonly [KeyOf<T>, ValueOf<T>])[];
|
|
422
|
+
/** Safely look up the key corresponding to a given value (reverse mapping) */
|
|
423
|
+
keyOf<T extends Property<any>>(enumObj: T, search: LooseKey<ValueOf<T>> | any): KeyOf<T> | undefined;
|
|
424
|
+
/** Safely check if a value exists in an enum */
|
|
425
|
+
includes<T extends Property<any>>(enumObj: T, search: LooseKey<ValueOf<T>> | any): boolean;
|
|
426
|
+
/** Safely count total entries in an enum */
|
|
427
|
+
count<T extends Property<any>>(enumObj: T): number;
|
|
428
|
+
/**
|
|
429
|
+
* Safely invert an enum into a Value -> Key lookup dictionary.
|
|
430
|
+
* Supports aliased enums (last-key-wins on duplicate values).
|
|
431
|
+
*/
|
|
432
|
+
invert<T extends Property<any>>(enumObj: T): Readonly<Invert<T>>;
|
|
433
|
+
/** Extend a base enum by inheriting from it via prototype delegation */
|
|
434
|
+
extend: typeof extendEnum;
|
|
435
|
+
/** Merge two or more enums or dictionaries left-to-right into a flat Enum */
|
|
436
|
+
merge: typeof mergeEnum;
|
|
437
|
+
/** Custom instance-of check supporting `val instanceof Enum` or predicate checking */
|
|
438
|
+
[Symbol.hasInstance](instance: any): boolean;
|
|
439
|
+
};
|
|
440
|
+
type enumMethods = typeof enumMethods;
|
|
441
|
+
declare function extendEnum<T extends Property<any>, const E extends readonly any[]>(enumObj: T, list: E, frozen?: boolean): Enum.wrap<Omit<T, keyof Index<E>> & Index<E>>;
|
|
442
|
+
declare function extendEnum<T extends Property<any>, const E extends Property<any>>(enumObj: T, list: E, frozen?: boolean): Enum.wrap<Omit<T, keyof E> & E>;
|
|
443
|
+
type NormalizeMergeSource<S> = S extends readonly any[] ? Index<S> : S;
|
|
444
|
+
type MergeDynamic<H, E> = {
|
|
445
|
+
[K in keyof H]: K extends keyof E ? H[K] | E[K] : H[K];
|
|
446
|
+
} & {
|
|
447
|
+
[K in Exclude<keyof E, keyof H>]?: E[K];
|
|
448
|
+
};
|
|
449
|
+
/** @internal */
|
|
450
|
+
type MergeSources<T extends readonly Property<any>[]> = T extends readonly [] ? {} : T extends readonly [infer Head extends Property<any>, ...infer Tail extends readonly Property<any>[]] ? Tail extends readonly [] ? NormalizeMergeSource<Head> : Tail extends readonly [any, ...any[]] ? Omit<NormalizeMergeSource<Head>, keyof MergeSources<Tail>> & MergeSources<Tail> : Tail extends readonly (infer Elem extends Property<any>)[] ? MergeDynamic<NormalizeMergeSource<Head>, NormalizeMergeSource<Elem>> : NormalizeMergeSource<Head> : T extends readonly (infer Elem extends Property<any>)[] ? Partial<NormalizeMergeSource<Elem>> : {};
|
|
451
|
+
declare function mergeEnum<const T extends readonly Property<any>[]>(...sources: T): Enum.wrap<MergeSources<T>>;
|
|
452
|
+
declare const Enum: Readonly<enumMethods>;
|
|
453
|
+
/** namespace for Enum type-helpers */
|
|
454
|
+
declare namespace Enum {
|
|
455
|
+
/** Enum properties & methods */ type wrap<T = any> = T extends Property<any> ? EnumifyType<T> : any;
|
|
456
|
+
/** Enum static method keys */ type methods = keyof enumMethods;
|
|
457
|
+
/** Enum own properties */ type props<T = any> = Readonly<T>;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* @internal Prefer `Enum.from(...)`.
|
|
461
|
+
* # Enumify
|
|
462
|
+
* create a Proxy-based Registry (Enum) from an Object or Array.
|
|
463
|
+
* Enums are immutable (frozen) and provide methods for iteration, search, and extension.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const Status = Enum.from(['Active', 'Inactive', 'Pending']);
|
|
468
|
+
* console.log(Status.Active); // 0
|
|
469
|
+
* console.log(Enum.has(Status, 'Active')); // true
|
|
470
|
+
* console.log(Enum.keys(Status)); // ['Active', 'Inactive', 'Pending']
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
declare function enumify<const T extends readonly any[]>(list: T, frozen?: boolean): Enum.wrap<Index<T>>;
|
|
474
|
+
declare function enumify<const T extends Property<any>>(list: T, frozen?: boolean): Enum.wrap<T>;
|
|
475
|
+
|
|
476
|
+
declare module '#library/type.library.js' {
|
|
477
|
+
interface TypeValueMap<T> {
|
|
478
|
+
Logger: {
|
|
479
|
+
type: 'Logger';
|
|
480
|
+
value: Logger;
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/** Type guard predicate checking if a value is an authentic Logger instance */
|
|
485
|
+
type LoggerTypeGuard = (val: unknown) => val is Logger;
|
|
486
|
+
/**
|
|
487
|
+
* Enumeration of available log levels from lowest to highest verbosity.
|
|
488
|
+
*/
|
|
489
|
+
declare const LOG: EnumifyType<Index<readonly ["Off", "Error", "Warn", "Info", "Debug", "Trace"]>>;
|
|
490
|
+
/**
|
|
491
|
+
* Type representing a numeric log level value.
|
|
492
|
+
*/
|
|
493
|
+
type LOG = ValueOf<typeof LOG>;
|
|
494
|
+
/**
|
|
495
|
+
* Type representing any valid debug level specification (numeric or method string).
|
|
496
|
+
*/
|
|
497
|
+
type DebugLevel = LOG | Method;
|
|
498
|
+
declare const Method: {
|
|
499
|
+
readonly Off: "off";
|
|
500
|
+
readonly Log: "log";
|
|
501
|
+
readonly Info: "info";
|
|
502
|
+
readonly Warn: "warn";
|
|
503
|
+
readonly Debug: "debug";
|
|
504
|
+
readonly Trace: "trace";
|
|
505
|
+
readonly Error: "error";
|
|
506
|
+
};
|
|
507
|
+
type Method = ValueOf<typeof Method>;
|
|
508
|
+
/**
|
|
509
|
+
* A lightweight, dependency-free namespaced logger.
|
|
510
|
+
* Decoupled from error handling and boundaries, utilizing standard `console` methods.
|
|
511
|
+
* Supports configurable log levels and structured object output.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts
|
|
515
|
+
* const log = new Logger('App', LOG.Debug);
|
|
516
|
+
* log.info('Started'); // [App] Started
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
declare class Logger {
|
|
520
|
+
#private;
|
|
521
|
+
/** Type guard to check if a value is an authentic Logger instance */
|
|
522
|
+
static isLogger: LoggerTypeGuard;
|
|
523
|
+
/** The current verbosity level */
|
|
524
|
+
level: LOG;
|
|
525
|
+
constructor(namespace: string, level?: LOG);
|
|
526
|
+
/** console.log */ log: (...msg: any[]) => void;
|
|
527
|
+
/** console.info */ info: (...msg: any[]) => void;
|
|
528
|
+
/** console.warn */ warn: (...msg: any[]) => void;
|
|
529
|
+
/** console.debug */ debug: (...msg: any[]) => void;
|
|
530
|
+
/** console.trace */ trace: (...msg: any[]) => void;
|
|
531
|
+
/** console.error */ error: (...msg: any[]) => void;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
interface ServerMapOpts {
|
|
535
|
+
endpoint?: string;
|
|
536
|
+
timeout?: number;
|
|
537
|
+
catch?: boolean;
|
|
538
|
+
debug?: DebugLevel;
|
|
539
|
+
ip?: string;
|
|
540
|
+
}
|
|
541
|
+
interface ServerGeolocationResult {
|
|
542
|
+
lat?: number;
|
|
543
|
+
lng?: number;
|
|
544
|
+
latitude?: number;
|
|
545
|
+
longitude?: number;
|
|
546
|
+
country?: string;
|
|
547
|
+
city?: string;
|
|
548
|
+
timezone?: string;
|
|
549
|
+
query?: string;
|
|
550
|
+
status?: string;
|
|
551
|
+
error?: string;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Perform server-side IP geolocation query via HTTP fetchRequest.
|
|
555
|
+
*
|
|
556
|
+
* @param opts - Options including custom endpoint URL and timeout
|
|
557
|
+
* @returns Geolocation result object with coordinates and location info
|
|
558
|
+
*/
|
|
559
|
+
declare const serverGeoLocation: (opts?: ServerMapOpts) => Promise<ServerGeolocationResult>;
|
|
560
|
+
/**
|
|
561
|
+
* Normalize coordinates or resolve default IP location on server.
|
|
562
|
+
*
|
|
563
|
+
* @param coords - Optional coordinate input
|
|
564
|
+
* @param opts - Server map options
|
|
565
|
+
*/
|
|
566
|
+
declare const serverGeoCoords: (coords?: {
|
|
567
|
+
latitude?: number;
|
|
568
|
+
lat?: number;
|
|
569
|
+
longitude?: number;
|
|
570
|
+
lng?: number;
|
|
571
|
+
lon?: number;
|
|
572
|
+
long?: number;
|
|
573
|
+
}, opts?: ServerMapOpts) => Promise<{
|
|
574
|
+
lat: number;
|
|
575
|
+
lng: number;
|
|
576
|
+
} | null>;
|
|
577
|
+
/**
|
|
578
|
+
* Determine Hemisphere ('north' | 'south' | null) for server coordinates.
|
|
579
|
+
*
|
|
580
|
+
* @param coords - Optional coordinates
|
|
581
|
+
* @param opts - Options
|
|
582
|
+
*/
|
|
583
|
+
declare const serverMapHemisphere: (coords?: {
|
|
584
|
+
latitude?: number;
|
|
585
|
+
lat?: number;
|
|
586
|
+
longitude?: number;
|
|
587
|
+
lng?: number;
|
|
588
|
+
lon?: number;
|
|
589
|
+
long?: number;
|
|
590
|
+
}, opts?: ServerMapOpts) => Promise<"north" | "south" | null>;
|
|
591
|
+
|
|
592
|
+
interface MapOpts {
|
|
593
|
+
catch?: boolean;
|
|
594
|
+
debug?: DebugLevel;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Attempt geolocation via navigator.getCurrentPosition().
|
|
598
|
+
*
|
|
599
|
+
* @param opts - Options for the geolocation attempt
|
|
600
|
+
* @returns A promise resolving to the device's coordinates
|
|
601
|
+
* @example
|
|
602
|
+
* ```ts
|
|
603
|
+
* const pos = await geoLocation();
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
declare const geoLocation: (opts?: MapOpts) => Promise<GeolocationPosition & {
|
|
607
|
+
error?: GeolocationPositionError["message"] | "NOT_SUPPORTED";
|
|
608
|
+
}>;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Control and execution options filtered out when preserving caller-defined custom metadata.
|
|
612
|
+
*/
|
|
613
|
+
declare const NON_GEO_CONTROL_KEYS: readonly ["setTimezone", "setLocale", "refresh", "ttl", "endpoint", "timeout", "maxBytes", "highAccuracy", "catch", "debug", "geo", "provider", "fallback", "reverse", "autoReverse"];
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Cohesive static namespace for geolocation operations on Tempo.
|
|
617
|
+
*/
|
|
618
|
+
interface TempoGeoNamespace {
|
|
619
|
+
/** Asynchronous universal geolocation lookup (browser hardware, server IP, or custom provider) with 24h caching */
|
|
620
|
+
readonly lookup: typeof geoLookup;
|
|
621
|
+
/** Asynchronously resolves coordinates from an instance, config, or ambient storage */
|
|
622
|
+
readonly resolve: typeof resolveGeoCoordinates;
|
|
623
|
+
/** Coerces coordinates and configurations into a canonical GeoConfig object */
|
|
624
|
+
readonly coerce: typeof coerceGeo;
|
|
625
|
+
/** Retrieves cached coordinates from storage */
|
|
626
|
+
readonly get: typeof getStashedGeo;
|
|
627
|
+
/** Explicitly sets coordinates into storage with optional TTL (default 24h) and multi-tenant partitioning */
|
|
628
|
+
readonly set: typeof stashGeo;
|
|
629
|
+
/** Clears cached coordinates from storage */
|
|
630
|
+
readonly clear: typeof clearStashedGeo;
|
|
631
|
+
/** Gets the currently registered custom geolocation provider */
|
|
632
|
+
readonly getProvider: typeof getGeoProvider;
|
|
633
|
+
/** Sets the active custom geolocation provider gateway */
|
|
634
|
+
readonly setProvider: typeof setGeoProvider;
|
|
635
|
+
/** Forward geocodes an address or place query string into coordinates using the active provider */
|
|
636
|
+
readonly forward: typeof forwardGeocode;
|
|
637
|
+
/** Reverse geocodes coordinates to address or location metadata using the active provider */
|
|
638
|
+
readonly reverse: typeof reverseGeocode;
|
|
639
|
+
/** Low-level server-side IP geolocation handler */
|
|
640
|
+
readonly server: typeof serverGeoLocation;
|
|
641
|
+
/** Low-level browser geolocation API handler */
|
|
642
|
+
readonly browser: typeof geoLocation;
|
|
643
|
+
/** Current ambient or global coordinates snapshot (reads getStashedGeo() ?? Tempo.config.geo) */
|
|
644
|
+
readonly current: GeoConfig | undefined;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Options for configuring the Geo plugin.
|
|
648
|
+
*/
|
|
649
|
+
type GeoPluginOptions = Partial<GeoConfig> & {
|
|
650
|
+
timeout?: number;
|
|
651
|
+
highAccuracy?: boolean;
|
|
652
|
+
provider?: GeoProvider;
|
|
653
|
+
[key: string]: any;
|
|
654
|
+
};
|
|
655
|
+
/**
|
|
656
|
+
* GeoPlugin installs geolocation lookup and coordinate resolution helpers onto Tempo under the `Tempo.geo` namespace.
|
|
657
|
+
*/
|
|
658
|
+
declare const GeoPlugin: TempoPlugin<GeoPluginOptions>;
|
|
659
|
+
declare const geoPlugin: TempoPlugin<GeoPluginOptions>;
|
|
660
|
+
|
|
661
|
+
declare module 'tempo-kit' {
|
|
662
|
+
interface Tempo {
|
|
663
|
+
/**
|
|
664
|
+
* Asynchronously resolves coordinates for this instance and returns a new Tempo instance with geo set.
|
|
665
|
+
*/
|
|
666
|
+
geoLocate(opts?: Record<string, any>): Promise<Tempo>;
|
|
667
|
+
/**
|
|
668
|
+
* Resolves coordinates for this instance via explicit coordinates or automatic IP/hardware lookup.
|
|
669
|
+
*/
|
|
670
|
+
geoLookup(opts?: Record<string, any>): Promise<ResolvedCoordinates | null>;
|
|
671
|
+
}
|
|
672
|
+
namespace Tempo {
|
|
673
|
+
let geo: TempoGeoNamespace;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export { GEO_PROPERTIES, GeoPlugin, NON_GEO_CONTROL_KEYS, clearStashedGeo, coerceGeo, GeoPlugin as default, forwardGeocode, geoLocation, geoLookup, geoPlugin, getGeoProvider, getStashedGeo, resolveGeoCoordinates, reverseGeocode, serverGeoCoords, serverGeoLocation, serverMapHemisphere, setGeoProvider, stashGeo };
|
|
678
|
+
export type { CoordinateInput, GeoConfig, GeoLookupResult, GeoPluginOptions, GeoProvider, ResolvedCoordinates, ServerGeolocationResult, ServerMapOpts, TempoGeoNamespace };
|