@mapka/tilestats 0.0.0-stage → 0.1.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/dist/schema.js ADDED
@@ -0,0 +1,91 @@
1
+ import { z } from "zod";
2
+ /** Names for the `$defs` of the generated JSON Schema, and extra keywords zod cannot express. */
3
+ export const jsonSchemaMetadata = z.registry();
4
+ const count = z.int().min(0).register(jsonSchemaMetadata, { id: "count" });
5
+ const positive = z.int().min(1);
6
+ const ZoomCountsSchema = z
7
+ .record(z.string().regex(/^(0|[1-9]\d*)$/), count)
8
+ .register(jsonSchemaMetadata, { id: "zoomCounts" });
9
+ const GeometrySchema = z
10
+ .strictObject({ Point: count, LineString: count, Polygon: count })
11
+ .register(jsonSchemaMetadata, { id: "geometry" });
12
+ const TypesSchema = z
13
+ .strictObject({ string: count, number: count, bigint: count, boolean: count })
14
+ .register(jsonSchemaMetadata, { id: "types" });
15
+ // Output values
16
+ export const RawIntegerSchema = z.custom(value => JSON.isRawJSON(value), {
17
+ error: "Expected an integer written with JSON.rawJSON",
18
+ });
19
+ const OutputValueSchema = z
20
+ .union([z.string(), z.number(), z.boolean(), RawIntegerSchema])
21
+ .register(jsonSchemaMetadata, { id: "value" });
22
+ const BoundSchema = z.union([z.number(), RawIntegerSchema]).register(jsonSchemaMetadata, { id: "bound" });
23
+ const ValuesSchema = z
24
+ .discriminatedUnion("exact", [
25
+ z.strictObject({
26
+ exact: z.literal(true),
27
+ distinct: count,
28
+ top: z.array(z.tuple([OutputValueSchema, positive])),
29
+ }),
30
+ z.strictObject({ exact: z.literal(false), distinct: count, examples: z.array(OutputValueSchema) }),
31
+ ])
32
+ .register(jsonSchemaMetadata, { id: "values" });
33
+ const PlainBodySchema = z.strictObject({
34
+ type: z.enum(["string", "boolean", "mixed"]),
35
+ types: TypesSchema,
36
+ values: ValuesSchema,
37
+ });
38
+ const NumericBodySchema = z.strictObject({
39
+ type: z.enum(["integer", "number"]),
40
+ types: TypesSchema,
41
+ min: BoundSchema,
42
+ max: BoundSchema,
43
+ values: ValuesSchema,
44
+ });
45
+ const MixedNumericBodySchema = z.strictObject({
46
+ type: z.literal("mixed-numeric"),
47
+ types: TypesSchema,
48
+ min: BoundSchema,
49
+ max: BoundSchema,
50
+ integer: z.boolean(),
51
+ values: ValuesSchema,
52
+ });
53
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- the zod type is the inferred one
54
+ function vectorStatsSchema(mode, counts) {
55
+ const named = { attribute: z.string(), present: counts };
56
+ const attribute = z
57
+ .discriminatedUnion("type", [
58
+ z.strictObject({ ...named, ...PlainBodySchema.shape }),
59
+ z.strictObject({ ...named, ...NumericBodySchema.shape }),
60
+ z.strictObject({ ...named, ...MixedNumericBodySchema.shape }),
61
+ ])
62
+ .register(jsonSchemaMetadata, { id: `${mode}Attribute` });
63
+ const layer = z
64
+ .strictObject({
65
+ layer: z.string(),
66
+ count: counts,
67
+ geometry: GeometrySchema,
68
+ attributes: z.array(attribute),
69
+ })
70
+ .register(jsonSchemaMetadata, { id: `${mode}Layer` });
71
+ return z.strictObject({ version: z.literal(1), counts: z.literal(mode), layers: z.array(layer) });
72
+ }
73
+ const ZoomVectorStatsSchema = vectorStatsSchema("zoom", ZoomCountsSchema);
74
+ const TotalVectorStatsSchema = vectorStatsSchema("total", count);
75
+ export const VectorStatsSchema = z.discriminatedUnion("counts", [ZoomVectorStatsSchema, TotalVectorStatsSchema]);
76
+ // Options
77
+ const LimitsSchema = z
78
+ .strictObject({
79
+ maxAttributes: positive.default(1000),
80
+ maxDistinct: positive.default(1000),
81
+ maxTop: positive.default(100),
82
+ maxExamples: positive.default(10),
83
+ maxStringLength: positive.default(256),
84
+ })
85
+ .refine(limits => limits.maxTop <= limits.maxDistinct, {
86
+ path: ["maxTop"],
87
+ error: "maxTop must not exceed maxDistinct",
88
+ });
89
+ /** Any subset of the limits; the rest take their defaults. */
90
+ export const OptionsSchema = z.strictObject({ limits: LimitsSchema.prefault({})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C,CAAC,CAAC;AAEL,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Tile } from "./formats.ts";
2
+ /** Every stored tile of the archive at `path`, one at a time, decoded by the reader its extension names. */
3
+ export declare function decode(path: string): Iterable<Tile>;
4
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/sources/decode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIzC,4GAA4G;AAC5G,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CASnD"}
@@ -0,0 +1,15 @@
1
+ import { extname } from "node:path";
2
+ import { readMbtiles } from "./mbtiles.js";
3
+ import { readPmtiles } from "./pmtiles.js";
4
+ /** Every stored tile of the archive at `path`, one at a time, decoded by the reader its extension names. */
5
+ export function decode(path) {
6
+ switch (extname(path).toLowerCase()) {
7
+ case ".pmtiles":
8
+ return readPmtiles(path);
9
+ case ".mbtiles":
10
+ return readMbtiles(path);
11
+ default:
12
+ throw new TypeError("unsupported archive: expected .pmtiles or .mbtiles");
13
+ }
14
+ }
15
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/sources/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,4GAA4G;AAC5G,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACpC,KAAK,UAAU;YACb,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;QAC3B,KAAK,UAAU;YACb,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;QAC3B;YACE,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ export type GeometryType = "Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon";
2
+ /** A feature decoded from a tile. Its property values are untyped until the stats normalize them. */
3
+ export interface TileFeature {
4
+ layer: string;
5
+ geometry: GeometryType | null;
6
+ properties: Record<string, unknown>;
7
+ }
8
+ /** How many tiles of one zoom use a stored tile. */
9
+ export interface ZoomWeight {
10
+ zoom: number;
11
+ tiles: number;
12
+ }
13
+ /** The features of one stored tile, decoded as they are iterated, and the tiles that use it. */
14
+ export interface Tile {
15
+ readonly zooms: readonly ZoomWeight[];
16
+ readonly features: Iterable<TileFeature>;
17
+ }
18
+ export type Decoder = (bytes: Uint8Array) => Iterable<TileFeature>;
19
+ /** Geometry is never loaded: only its type is read. */
20
+ export declare function decodeMvt(bytes: Uint8Array): Generator<TileFeature>;
21
+ /**
22
+ * MLT is columnar: a table is a layer, each property is a column with a value per feature, null where the feature has
23
+ * none. Nulls are left out, as MVT leaves out a missing property. Shared-dictionary children are already their own
24
+ * columns (`name:` + `en` is `name:en`).
25
+ */
26
+ export declare function decodeMlt(bytes: Uint8Array): Generator<TileFeature>;
27
+ //# sourceMappingURL=formats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/sources/formats.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,iBAAiB,GAAG,SAAS,GAAG,cAAc,CAAC;AAElH,qGAAqG;AACrG,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,oDAAoD;AACpD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gGAAgG;AAChG,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;CAC1C;AAED,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,QAAQ,CAAC,WAAW,CAAC,CAAC;AAQnE,uDAAuD;AACvD,wBAAiB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,CAYpE;AAED;;;;GAIG;AACH,wBAAiB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,CAgBpE"}
@@ -0,0 +1,45 @@
1
+ import { VectorTile } from "@mapbox/vector-tile";
2
+ import { PbfReader } from "pbf";
3
+ import { decodeTile } from "../../vendor/mlt.js";
4
+ // Indexed by the MVT geometry type.
5
+ const mvtGeometries = [null, "Point", "LineString", "Polygon"];
6
+ // Indexed by the MLT geometry type.
7
+ const mltGeometries = ["Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon"];
8
+ /** Geometry is never loaded: only its type is read. */
9
+ export function* decodeMvt(bytes) {
10
+ const tile = new VectorTile(new PbfReader(bytes));
11
+ for (const layer of Object.values(tile.layers)) {
12
+ for (let i = 0; i < layer.length; i++) {
13
+ const { type, properties } = layer.feature(i);
14
+ yield {
15
+ layer: layer.name,
16
+ geometry: mvtGeometries[type],
17
+ properties,
18
+ };
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * MLT is columnar: a table is a layer, each property is a column with a value per feature, null where the feature has
24
+ * none. Nulls are left out, as MVT leaves out a missing property. Shared-dictionary children are already their own
25
+ * columns (`name:` + `en` is `name:en`).
26
+ */
27
+ export function* decodeMlt(bytes) {
28
+ for (const { name, numFeatures, geometryVector, propertyVectors } of decodeTile(bytes)) {
29
+ for (let i = 0; i < numFeatures; i++) {
30
+ const properties = {};
31
+ for (const column of propertyVectors) {
32
+ const value = column.getValue(i);
33
+ if (value !== null) {
34
+ properties[column.name] = value;
35
+ }
36
+ }
37
+ yield {
38
+ layer: name,
39
+ geometry: mltGeometries[geometryVector.geometryType(i)] ?? null,
40
+ properties
41
+ };
42
+ }
43
+ }
44
+ }
45
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sourceRoot":"","sources":["../../src/sources/formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAyBjD,oCAAoC;AACpC,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,CAAU,CAAC;AAExE,oCAAoC;AACpC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,CAAU,CAAC;AAEnH,uDAAuD;AACvD,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,KAAiB;IAC1C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC9C,MAAM;gBACJ,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,QAAQ,EAAE,aAAa,CAAC,IAAI,CAAC;gBAC7B,UAAU;aACX,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,KAAiB;IAC1C,KAAK,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACvF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,UAAU,GAA4B,EAAE,CAAC;YAC/C,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;gBACrC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACjC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;gBAClC,CAAC;YACH,CAAC;YACD,MAAM;gBACJ,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,aAAa,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI;gBAC/D,UAAU;aAAE,CAAC;QACjB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Tile } from "./formats.ts";
2
+ /** Every stored tile, once for each zoom whose addresses use it. */
3
+ export declare function readMbtiles(path: string): Generator<Tile>;
4
+ //# sourceMappingURL=mbtiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mbtiles.d.ts","sourceRoot":"","sources":["../../src/sources/mbtiles.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,IAAI,EAAE,MAAM,cAAc,CAAC;AAuD7E,oEAAoE;AACpE,wBAAiB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAU1D"}
@@ -0,0 +1,118 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ import { DatabaseSync } from "node:sqlite";
54
+ import { gunzipSync } from "node:zlib";
55
+ import { decodeMlt, decodeMvt } from "./formats.js";
56
+ /** A plain `tiles` table: every address has its own row. */
57
+ const tilesQuery = "SELECT tile_data AS data, zoom_level AS zoom, 1 AS tiles FROM tiles";
58
+ /** `map` addresses the deduplicated tiles in `images` (mbutil, Martin). */
59
+ const mapImagesQuery = `
60
+ SELECT images.tile_data AS data, usage.zoom, usage.tiles
61
+ FROM (SELECT tile_id, zoom_level AS zoom, count(*) AS tiles FROM map GROUP BY tile_id, zoom_level) AS usage
62
+ JOIN images USING (tile_id)`;
63
+ /** `tiles_shallow` addresses the deduplicated tiles in `tiles_data` (Planetiler). */
64
+ const tilesShallowQuery = `
65
+ SELECT tiles_data.tile_data AS data, usage.zoom, usage.tiles
66
+ FROM (SELECT tile_data_id, zoom_level AS zoom, count(*) AS tiles FROM tiles_shallow GROUP BY tile_data_id, zoom_level) AS usage
67
+ JOIN tiles_data USING (tile_data_id)`;
68
+ function queryOf(db) {
69
+ const tables = new Set(db.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map(row => row.name));
70
+ if (tables.has("map") && tables.has("images")) {
71
+ return mapImagesQuery;
72
+ }
73
+ if (tables.has("tiles_shallow") && tables.has("tiles_data")) {
74
+ return tilesShallowQuery;
75
+ }
76
+ return tilesQuery;
77
+ }
78
+ /** The spec names MVT `pbf`; writers name MLT `mlt` (Martin) or by its media type (Planetiler). */
79
+ function decoderOf(db) {
80
+ const format = db.prepare("SELECT value FROM metadata WHERE name = 'format'").get()?.value;
81
+ switch (format) {
82
+ case "pbf":
83
+ case "mvt":
84
+ return decodeMvt;
85
+ case "mlt":
86
+ case "application/vnd.maplibre-tile":
87
+ return decodeMlt;
88
+ default:
89
+ throw new Error(`unsupported tile format ${String(format)}`);
90
+ }
91
+ }
92
+ /** MBTiles does not record compression; a gzipped tile starts with the gzip magic, an uncompressed one cannot. */
93
+ function gunzip(bytes) {
94
+ return bytes[0] === 0x1f && bytes[1] === 0x8b ? gunzipSync(bytes) : bytes;
95
+ }
96
+ /** Every stored tile, once for each zoom whose addresses use it. */
97
+ export function* readMbtiles(path) {
98
+ const env_1 = { stack: [], error: void 0, hasError: false };
99
+ try {
100
+ const db = __addDisposableResource(env_1, new DatabaseSync(path, { readOnly: true }), false);
101
+ const decode = decoderOf(db);
102
+ const rows = db.prepare(queryOf(db)).iterate();
103
+ for (const { data, zoom, tiles } of rows) {
104
+ yield {
105
+ zooms: [{ zoom, tiles }],
106
+ features: decode(gunzip(data)),
107
+ };
108
+ }
109
+ }
110
+ catch (e_1) {
111
+ env_1.error = e_1;
112
+ env_1.hasError = true;
113
+ }
114
+ finally {
115
+ __disposeResources(env_1);
116
+ }
117
+ }
118
+ //# sourceMappingURL=mbtiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mbtiles.js","sourceRoot":"","sources":["../../src/sources/mbtiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAgB,SAAS,EAAE,SAAS,EAAa,MAAM,cAAc,CAAC;AAS7E,4DAA4D;AAC5D,MAAM,UAAU,GAAG,qEAAqE,CAAC;AAEzF,2EAA2E;AAC3E,MAAM,cAAc,GAAG;;;8BAGO,CAAC;AAE/B,qFAAqF;AACrF,MAAM,iBAAiB,GAAG;;;uCAGa,CAAC;AAExC,SAAS,OAAO,CAAC,EAAgB;IAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,qDAAqD,CAAC,C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M,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAuB,CAAC;QACpE,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC;YACzC,MAAM;gBACJ,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;gBACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aAC/B,CAAC;QACJ,CAAC;;;;;;;;;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Tile } from "./formats.ts";
2
+ /** Every stored tile, leaf directories depth-first, so tiles come in tile-id order. */
3
+ export declare function readPmtiles(path: string): Generator<Tile>;
4
+ //# sourceMappingURL=pmtiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pmtiles.d.ts","sourceRoot":"","sources":["../../src/sources/pmtiles.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,IAAI,EAAmB,MAAM,cAAc,CAAC;AAmI9F,uFAAuF;AACvF,wBAAiB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CA2B1D"}
@@ -0,0 +1,189 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ import { closeSync, openSync, readSync } from "node:fs";
54
+ import { brotliDecompressSync, gunzipSync, zstdDecompressSync } from "node:zlib";
55
+ import { decodeMlt, decodeMvt } from "./formats.js";
56
+ // PMTiles v3: https://github.com/protomaps/PMTiles/blob/main/spec/v3/spec.md
57
+ const headerLength = 127;
58
+ const compression = { gzip: 2, brotli: 3, zstd: 4 };
59
+ const tileType = { mvt: 1, mlt: 6 };
60
+ /** The fields of the fixed 127-byte little-endian header that a walk needs. */
61
+ function readHeader(bytes) {
62
+ const view = new DataView(bytes.buffer, bytes.byteOffset, headerLength);
63
+ const uint64 = (at) => Number(view.getBigUint64(at, true));
64
+ return {
65
+ rootDirectoryOffset: uint64(8),
66
+ rootDirectoryLength: uint64(16),
67
+ leafDirectoriesOffset: uint64(40),
68
+ tileDataOffset: uint64(56),
69
+ internalCompression: bytes[97],
70
+ tileCompression: bytes[98],
71
+ tileType: bytes[99],
72
+ };
73
+ }
74
+ /** Reads varints one after another, multiplying instead of shifting because offsets pass 2^32. */
75
+ function varintReader(bytes) {
76
+ let position = 0;
77
+ return () => {
78
+ let value = 0;
79
+ for (let scale = 1;; scale *= 128) {
80
+ const byte = bytes[position++];
81
+ value += (byte & 0x7f) * scale;
82
+ if (byte < 0x80) {
83
+ return value;
84
+ }
85
+ }
86
+ };
87
+ }
88
+ /** A count, then columns of varints: tile-id deltas, run lengths, lengths, offsets + 1 (0: after the previous). */
89
+ function readDirectory(bytes) {
90
+ const next = varintReader(bytes);
91
+ const count = next();
92
+ const column = () => Array.from({ length: count }, next);
93
+ const tileIds = column();
94
+ const runLengths = column();
95
+ const lengths = column();
96
+ const offsets = column();
97
+ for (let i = 1; i < count; i++) {
98
+ tileIds[i] += tileIds[i - 1];
99
+ }
100
+ for (let i = 0; i < count; i++) {
101
+ offsets[i] = offsets[i] === 0 ? offsets[i - 1] + lengths[i - 1] : offsets[i] - 1;
102
+ }
103
+ return tileIds.map((tileId, i) => ({
104
+ tileId,
105
+ runLength: runLengths[i],
106
+ length: lengths[i],
107
+ offset: offsets[i],
108
+ }));
109
+ }
110
+ /** The decoder for the tile type the header names. */
111
+ function decoderOf(type) {
112
+ switch (type) {
113
+ case tileType.mvt:
114
+ return decodeMvt;
115
+ case tileType.mlt:
116
+ return decodeMlt;
117
+ default:
118
+ throw new Error(`unsupported tile type ${type}`);
119
+ }
120
+ }
121
+ /** Decompresses by the type the header names; uncompressed bytes pass through. */
122
+ function decompress(bytes, type) {
123
+ switch (type) {
124
+ case compression.gzip:
125
+ return gunzipSync(bytes);
126
+ case compression.brotli:
127
+ return brotliDecompressSync(bytes);
128
+ case compression.zstd:
129
+ return zstdDecompressSync(bytes);
130
+ default:
131
+ return bytes;
132
+ }
133
+ }
134
+ /** Tile ids count up through the zooms, so zoom z starts after 4^0 + … + 4^(z-1) ids. */
135
+ function firstTileId(zoom) {
136
+ return (4 ** zoom - 1) / 3;
137
+ }
138
+ /** How many tile ids of each zoom a run covers, as a run can cross into the next zoom. */
139
+ function zoomWeights({ tileId, runLength }) {
140
+ const weights = [];
141
+ const end = tileId + runLength;
142
+ let zoom = 0;
143
+ for (let id = tileId; id < end;) {
144
+ while (firstTileId(zoom + 1) <= id) {
145
+ zoom++;
146
+ }
147
+ const next = Math.min(end, firstTileId(zoom + 1));
148
+ weights.push({ zoom, tiles: next - id });
149
+ id = next;
150
+ }
151
+ return weights;
152
+ }
153
+ /** Every stored tile, leaf directories depth-first, so tiles come in tile-id order. */
154
+ export function* readPmtiles(path) {
155
+ const env_1 = { stack: [], error: void 0, hasError: false };
156
+ try {
157
+ const stack = __addDisposableResource(env_1, new DisposableStack(), false);
158
+ const fd = stack.adopt(openSync(path, "r"), closeSync);
159
+ const read = (offset, length) => {
160
+ const bytes = new Uint8Array(length);
161
+ readSync(fd, bytes, 0, length, offset);
162
+ return bytes;
163
+ };
164
+ const header = readHeader(read(0, headerLength));
165
+ const decode = decoderOf(header.tileType);
166
+ /** The tiles of one directory, and of the leaf directories it points to. */
167
+ function* walk(offset, length) {
168
+ for (const entry of readDirectory(decompress(read(offset, length), header.internalCompression))) {
169
+ if (entry.runLength === 0) {
170
+ yield* walk(header.leafDirectoriesOffset + entry.offset, entry.length);
171
+ continue;
172
+ }
173
+ yield {
174
+ zooms: zoomWeights(entry),
175
+ features: decode(decompress(read(header.tileDataOffset + entry.offset, entry.length), header.tileCompression)),
176
+ };
177
+ }
178
+ }
179
+ yield* walk(header.rootDirectoryOffset, header.rootDirectoryLength);
180
+ }
181
+ catch (e_1) {
182
+ env_1.error = e_1;
183
+ env_1.hasError = true;
184
+ }
185
+ finally {
186
+ __disposeResources(env_1);
187
+ }
188
+ }
189
+ //# sourceMappingURL=pmtiles.js.map
@@ -0,0 +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Q,CAAC,CAAC;QAE1C,4EAA4E;QAC5E,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAc,EAAE,MAAc;YAC3C,KAAK,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC;gBAChG,IAAI,KAAK,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;oBAC1B,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;oBACvE,SAAS;gBACX,CAAC;gBACD,MAAM;oBACJ,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC;oBACzB,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;iBAC/G,CAAC;YACJ,CAAC;QACH,CAAC;QAED,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC;;;;;;;;;AACtE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type Options, type VectorStats } from "./schema.ts";
2
+ import type { TileFeature } from "./sources/formats.ts";
3
+ export type { GeometryType } from "./sources/formats.ts";
4
+ /** null and undefined are absent, as are NaN and the infinities. */
5
+ export type Value = string | number | boolean | bigint | null | undefined;
6
+ /** A feature as a caller gives it. */
7
+ export interface Feature extends TileFeature {
8
+ properties: Record<string, Value>;
9
+ }
10
+ export type FeatureInput = Iterable<Feature> | AsyncIterable<Feature>;
11
+ /** The vectorstats of the archive at `path`, or of a stream of features. */
12
+ export declare function tilestats(path: string, options?: Options): Promise<VectorStats<"zoom">>;
13
+ export declare function tilestats(features: FeatureInput, options?: Options): Promise<VectorStats<"total">>;
14
+ export declare function tilestats(input: string | FeatureInput, options?: Options): Promise<VectorStats>;
15
+ //# sourceMappingURL=tilestats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tilestats.d.ts","sourceRoot":"","sources":["../src/tilestats.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,OAAO,EAKZ,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAgB,WAAW,EAAc,MAAM,sBAAsB,CAAC;AAElF,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,oEAAoE;AACpE,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1E,sCAAsC;AACtC,MAAM,WAAW,OAAQ,SAAQ,WAAW;IAC1C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AA8UtE,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACzF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AACpG,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC"}