chiitiler 1.23.2 → 1.23.4

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/README.md CHANGED
@@ -108,6 +108,24 @@ const png = await getRenderedTileBuffer({
108
108
 
109
109
  Available renderers: `getRenderedTileBuffer`, `getRenderedClipBuffer`, `getRenderedCameraBuffer`, and their `*Stream` variants (`Sharp` instances for further piping).
110
110
 
111
+ Types are re-exported as well, so you can annotate call sites without depending on
112
+ `@maplibre/maplibre-gl-style-spec` resolution in your own tree:
113
+
114
+ ```ts
115
+ import type {
116
+ StyleSpecification,
117
+ GetRenderedTileOptions,
118
+ GetRenderedClipOptions,
119
+ GetRenderedCameraOptions,
120
+ SupportedFormat,
121
+ Cache,
122
+ } from 'chiitiler';
123
+ ```
124
+
125
+ Prefer chiitiler's `StyleSpecification` over importing it from
126
+ `@maplibre/maplibre-gl-style-spec` directly: if your tree resolves a different major of
127
+ that package, the two structurally-different types are not assignable to each other.
128
+
111
129
  chiitiler doesn't override the `User-Agent` on outbound HTTP requests by default, so the runtime's default is used (Node sends `node`). Some tile providers (e.g. OpenStreetMap) require an identifying User-Agent — set one with `setUserAgent('my-app/1.0')` or the `CHIITILER_USER_AGENT` environment variable.
112
130
 
113
131
  ## Configuration
@@ -121,8 +139,11 @@ All options can be set via CLI flag or environment variable.
121
139
  | `--port <n>` | `CHIITILER_PORT` | `3000` |
122
140
  | `--debug` | `CHIITILER_DEBUG` | `false` |
123
141
  | `--user-agent <ua>` | `CHIITILER_USER_AGENT` | (none) |
142
+ | `--prewarm` | `CHIITILER_PREWARM` | `false` |
124
143
  | — | `CHIITILER_PROCESSES` | `1` (set `0` for all CPUs) |
125
144
 
145
+ With prewarm enabled, one tile is rendered at startup **before** the server starts listening, so renderer initialization (GL context, sharp/libvips, JIT) doesn't hit the first request. On AWS Lambda with Lambda Web Adapter, the readiness check keeps this inside the INIT phase, which runs with a full CPU boost.
146
+
126
147
  ### Cache
127
148
 
128
149
  | Flag | Env | Default |
package/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import { Command } from 'commander';
3
3
  import { initServer } from './server/index.js';
4
4
  import * as caches from './cache/index.js';
5
5
  import { setUserAgent } from './source/userAgent.js';
6
+ import { prewarm } from './render/warmup.js';
6
7
  function parseCacheStrategy(method, options) {
7
8
  // command-line option
8
9
  if (method === 'memory')
@@ -71,6 +72,10 @@ function parsePort(port) {
71
72
  // undefined or invalid
72
73
  return 3000;
73
74
  }
75
+ function parsePrewarm(prewarmFlag) {
76
+ // command-line option, then env
77
+ return prewarmFlag === true || process.env.CHIITILER_PREWARM === 'true';
78
+ }
74
79
  function parseDebug(debug) {
75
80
  // command-line option
76
81
  if (debug)
@@ -101,8 +106,9 @@ export function createProgram() {
101
106
  .option('--gcs-api-endpoint <api-endpoint>', 'gcs api endpoint', '')
102
107
  .option('-p, --port <port>', 'port number')
103
108
  .option('--user-agent <user-agent>', 'User-Agent header for outbound HTTP requests')
109
+ .option('--prewarm', 'render one tile at startup before listening, to warm up the renderer')
104
110
  .option('-D, --debug', 'debug mode')
105
- .action((options) => {
111
+ .action(async (options) => {
106
112
  // env fallback (CHIITILER_USER_AGENT) is handled in userAgent.ts
107
113
  if (options.userAgent !== undefined)
108
114
  setUserAgent(options.userAgent);
@@ -130,6 +136,20 @@ export function createProgram() {
130
136
  console.log(`debug page: http://localhost:${serverOptions.port}/debug`);
131
137
  console.log(`editor page: http://localhost:${serverOptions.port}/editor`);
132
138
  }
139
+ // warm up BEFORE listening: Lambda Web Adapter polls the
140
+ // readiness check until the port opens, so work done here
141
+ // stays inside the INIT phase (full CPU boost)
142
+ if (parsePrewarm(options.prewarm)) {
143
+ const startedAt = Date.now();
144
+ try {
145
+ await prewarm(serverOptions.cache);
146
+ console.log(`prewarm done in ${Date.now() - startedAt}ms`);
147
+ }
148
+ catch (err) {
149
+ // 温まらないだけでサーバとしては動けるので起動は続行する
150
+ console.warn(`prewarm failed: ${err}`);
151
+ }
152
+ }
133
153
  const { start } = initServer(serverOptions);
134
154
  start();
135
155
  });
package/dist/index.d.ts CHANGED
@@ -7,3 +7,6 @@ export declare function getRenderedTileBuffer(options: GetRenderedTileOptions):
7
7
  export { getRenderedTile as getRenderedTileStream };
8
8
  export * as ChiitilerCache from './cache/index.js';
9
9
  export { setUserAgent } from './source/userAgent.js';
10
+ export type { GetRenderedClipOptions, GetRenderedTileOptions, GetRenderedCameraOptions, SupportedFormat, } from './render/index.js';
11
+ export type { Cache } from './cache/index.js';
12
+ export type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
@@ -0,0 +1,9 @@
1
+ import type { Cache } from '../cache/index.js';
2
+ /**
3
+ * Render one z0 tile ahead of the first request so that renderer
4
+ * initialization happens at startup — on AWS Lambda (with Lambda Web
5
+ * Adapter's readiness check) this moves the work into the INIT phase,
6
+ * which runs with a full CPU boost.
7
+ */
8
+ declare function prewarm(cache: Cache): Promise<void>;
9
+ export { prewarm };
@@ -0,0 +1,35 @@
1
+ import { getRenderedTile } from './index.js';
2
+ // スタイル固有のリソース(タイル/glyphs/sprite)は温まらないが、
3
+ // EGL/GLコンテキスト・Xvfb接続・sharp(libvips)・JITの初期化は共通で効く。
4
+ const MINIMAL_STYLE = {
5
+ version: 8,
6
+ sources: {},
7
+ layers: [
8
+ {
9
+ id: 'background',
10
+ type: 'background',
11
+ paint: { 'background-color': '#ffffff' },
12
+ },
13
+ ],
14
+ };
15
+ /**
16
+ * Render one z0 tile ahead of the first request so that renderer
17
+ * initialization happens at startup — on AWS Lambda (with Lambda Web
18
+ * Adapter's readiness check) this moves the work into the INIT phase,
19
+ * which runs with a full CPU boost.
20
+ */
21
+ async function prewarm(cache) {
22
+ const sharp = await getRenderedTile({
23
+ stylejson: MINIMAL_STYLE,
24
+ z: 0,
25
+ x: 0,
26
+ y: 0,
27
+ tileSize: 512,
28
+ cache,
29
+ margin: 0,
30
+ ext: 'png',
31
+ quality: 100,
32
+ });
33
+ await sharp.toBuffer(); // force the actual encode
34
+ }
35
+ export { prewarm };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.23.2",
4
+ "version": "1.23.4",
5
5
  "description": "Tiny map rendering server for MapLibre Style Spec",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -41,14 +41,13 @@
41
41
  "@hono/node-server": "^2.0.0",
42
42
  "@mapbox/tilebelt": "^2.0.3",
43
43
  "@maplibre/maplibre-gl-native": "^6.4.1",
44
- "@maplibre/maplibre-gl-style-spec": "^24.8.1",
44
+ "@maplibre/maplibre-gl-style-spec": "^26.4.2",
45
45
  "commander": "^14.0.3",
46
46
  "file-system-cache": "^2.4.7",
47
47
  "higuruma": "^0.1.6",
48
48
  "hono": "^4.12.14",
49
49
  "lightning-pool": "^4.12.0",
50
50
  "lru-cache": "^11.3.5",
51
- "maplibre-gl": "^5.23.0",
52
51
  "pmtiles": "^4.4.1",
53
52
  "sharp": "^0.35.3"
54
53
  }