@basemaps/lambda-tiler 7.4.0 → 7.6.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 (99) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/build/__tests__/config.data.d.ts +2 -0
  3. package/build/__tests__/config.data.js +24 -1
  4. package/build/__tests__/config.data.js.map +1 -1
  5. package/build/__tests__/index.test.js +1 -2
  6. package/build/__tests__/index.test.js.map +1 -1
  7. package/build/__tests__/tile.style.json.test.js +2 -2
  8. package/build/__tests__/tile.style.json.test.js.map +1 -1
  9. package/build/__tests__/wmts.capability.test.js +5 -2
  10. package/build/__tests__/wmts.capability.test.js.map +1 -1
  11. package/build/__tests__/xyz.util.js.map +1 -1
  12. package/build/cli/render.preview.js +5 -2
  13. package/build/cli/render.preview.js.map +1 -1
  14. package/build/cli/render.tile.js +1 -1
  15. package/build/cli/render.tile.js.map +1 -1
  16. package/build/index.js +1 -1
  17. package/build/index.js.map +1 -1
  18. package/build/routes/__tests__/attribution.test.js +1 -1
  19. package/build/routes/__tests__/attribution.test.js.map +1 -1
  20. package/build/routes/__tests__/health.test.js +1 -1
  21. package/build/routes/__tests__/health.test.js.map +1 -1
  22. package/build/routes/__tests__/imagery.test.js.map +1 -1
  23. package/build/routes/__tests__/memory.fs.d.ts +0 -2
  24. package/build/routes/__tests__/memory.fs.js +1 -1
  25. package/build/routes/__tests__/memory.fs.js.map +1 -1
  26. package/build/routes/__tests__/preview.index.test.js +1 -1
  27. package/build/routes/__tests__/preview.index.test.js.map +1 -1
  28. package/build/routes/__tests__/tile.json.test.js.map +1 -1
  29. package/build/routes/__tests__/tile.style.json.test.js +144 -11
  30. package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
  31. package/build/routes/__tests__/wmts.test.js +18 -2
  32. package/build/routes/__tests__/wmts.test.js.map +1 -1
  33. package/build/routes/attribution.d.ts +0 -1
  34. package/build/routes/config.js +1 -1
  35. package/build/routes/config.js.map +1 -1
  36. package/build/routes/health.d.ts +0 -1
  37. package/build/routes/ping.js +2 -2
  38. package/build/routes/ping.js.map +1 -1
  39. package/build/routes/preview.index.js +2 -1
  40. package/build/routes/preview.index.js.map +1 -1
  41. package/build/routes/preview.js +5 -3
  42. package/build/routes/preview.js.map +1 -1
  43. package/build/routes/sprites.js.map +1 -1
  44. package/build/routes/tile.style.json.d.ts +2 -2
  45. package/build/routes/tile.style.json.js +61 -10
  46. package/build/routes/tile.style.json.js.map +1 -1
  47. package/build/routes/tile.wmts.js +1 -0
  48. package/build/routes/tile.wmts.js.map +1 -1
  49. package/build/routes/tile.xyz.raster.d.ts +0 -1
  50. package/build/routes/tile.xyz.raster.js +6 -5
  51. package/build/routes/tile.xyz.raster.js.map +1 -1
  52. package/build/routes/version.js +2 -2
  53. package/build/routes/version.js.map +1 -1
  54. package/build/util/__test__/config.loader.test.js +12 -12
  55. package/build/util/__test__/config.loader.test.js.map +1 -1
  56. package/build/util/assets.provider.d.ts +0 -2
  57. package/build/util/config.cache.d.ts +0 -1
  58. package/build/util/config.cache.js.map +1 -1
  59. package/build/util/cotar.serve.d.ts +0 -2
  60. package/build/util/source.cache.d.ts +0 -1
  61. package/build/util/source.cache.js +5 -4
  62. package/build/util/source.cache.js.map +1 -1
  63. package/build/util/validate.js +1 -1
  64. package/build/util/validate.js.map +1 -1
  65. package/build/wmts.capability.d.ts +8 -4
  66. package/build/wmts.capability.js +18 -8
  67. package/build/wmts.capability.js.map +1 -1
  68. package/package.json +10 -10
  69. package/src/__tests__/config.data.ts +31 -2
  70. package/src/__tests__/index.test.ts +2 -3
  71. package/src/__tests__/tile.style.json.test.ts +2 -5
  72. package/src/__tests__/wmts.capability.test.ts +13 -10
  73. package/src/__tests__/xyz.util.ts +4 -4
  74. package/src/cli/render.preview.ts +5 -2
  75. package/src/cli/render.tile.ts +1 -1
  76. package/src/routes/__tests__/attribution.test.ts +7 -7
  77. package/src/routes/__tests__/health.test.ts +3 -3
  78. package/src/routes/__tests__/imagery.test.ts +1 -1
  79. package/src/routes/__tests__/memory.fs.ts +2 -2
  80. package/src/routes/__tests__/preview.index.test.ts +3 -3
  81. package/src/routes/__tests__/tile.json.test.ts +1 -1
  82. package/src/routes/__tests__/tile.style.json.test.ts +175 -15
  83. package/src/routes/__tests__/wmts.test.ts +23 -3
  84. package/src/routes/config.ts +1 -1
  85. package/src/routes/ping.ts +2 -2
  86. package/src/routes/preview.index.ts +2 -1
  87. package/src/routes/preview.ts +7 -5
  88. package/src/routes/sprites.ts +1 -1
  89. package/src/routes/tile.style.json.ts +73 -9
  90. package/src/routes/tile.wmts.ts +1 -0
  91. package/src/routes/tile.xyz.raster.ts +8 -6
  92. package/src/routes/version.ts +2 -2
  93. package/src/util/__test__/config.loader.test.ts +17 -20
  94. package/src/util/config.cache.ts +2 -1
  95. package/src/util/source.cache.ts +6 -4
  96. package/src/util/validate.ts +1 -1
  97. package/src/wmts.capability.ts +17 -9
  98. package/tsconfig.json +10 -10
  99. package/tsconfig.tsbuildinfo +1 -1
@@ -42,11 +42,11 @@ describe('ConfigLoader', () => {
42
42
  mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=notapath`, Api.header),
43
43
  )
44
44
  .then(() => null)
45
- .catch((e) => e);
45
+ .catch((e) => e as LambdaHttpResponse);
46
46
 
47
47
  assert.equal(error instanceof LambdaHttpResponse, true);
48
- assert.equal((error as LambdaHttpResponse).status, 400);
49
- assert.equal((error as LambdaHttpResponse).statusDescription, 'Invalid configuration location protocol:file:');
48
+ assert.equal(error?.status, 400);
49
+ assert.equal(error?.statusDescription, 'Invalid configuration location protocol:file:');
50
50
  });
51
51
 
52
52
  it('should Not working with wrong protocol', async () => {
@@ -54,11 +54,11 @@ describe('ConfigLoader', () => {
54
54
  mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=memory1://linz-basemaps/config`, Api.header),
55
55
  )
56
56
  .then(() => null)
57
- .catch((e) => e);
57
+ .catch((e) => e as LambdaHttpResponse);
58
58
 
59
59
  assert.equal(error instanceof LambdaHttpResponse, true);
60
- assert.equal((error as LambdaHttpResponse).status, 400);
61
- assert.equal((error as LambdaHttpResponse).statusDescription, 'Invalid configuration location protocol:memory1:');
60
+ assert.equal(error?.status, 400);
61
+ assert.equal(error?.statusDescription, 'Invalid configuration location protocol:memory1:');
62
62
  });
63
63
 
64
64
  it('should Not working with wrong s3 bucket', async () => {
@@ -66,28 +66,25 @@ describe('ConfigLoader', () => {
66
66
  mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=s3://wrong-bucket/config`, Api.header),
67
67
  )
68
68
  .then(() => null)
69
- .catch((e) => e);
69
+ .catch((e) => e as LambdaHttpResponse);
70
70
 
71
71
  assert.equal(error instanceof LambdaHttpResponse, true);
72
- assert.equal((error as LambdaHttpResponse).status, 400);
73
- assert.equal(
74
- (error as LambdaHttpResponse).statusDescription,
75
- 'Bucket: "wrong-bucket" is not a allowed bucket location',
76
- );
72
+ assert.equal(error?.status, 400);
73
+ assert.equal(error?.statusDescription, 'Bucket: "wrong-bucket" is not a allowed bucket location');
77
74
  });
78
75
 
79
76
  const location = new URL('memory://linz-basemaps/config.json');
80
77
 
81
78
  it('should Not working with no file in the path', async () => {
82
79
  const error = await ConfigLoader.load(
83
- mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${location}`, Api.header),
80
+ mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${location.href}`, Api.header),
84
81
  )
85
82
  .then(() => null)
86
- .catch((e) => e);
83
+ .catch((e) => e as LambdaHttpResponse);
87
84
 
88
85
  assert.equal(error instanceof LambdaHttpResponse, true);
89
- assert.equal((error as LambdaHttpResponse).status, 400);
90
- assert.equal((error as LambdaHttpResponse).statusDescription, `Invalid config location at ${location}`);
86
+ assert.equal(error?.status, 400);
87
+ assert.equal(error?.statusDescription, `Invalid config location at ${location.href}`);
91
88
  });
92
89
 
93
90
  it('should get expected config file', async () => {
@@ -96,7 +93,7 @@ describe('ConfigLoader', () => {
96
93
  await fsa.write(location, Buffer.from(JSON.stringify(expectedConfig.toJson())));
97
94
 
98
95
  const provider = await ConfigLoader.load(
99
- mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${location}`, Api.header),
96
+ mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${location.href}`, Api.header),
100
97
  );
101
98
 
102
99
  assert.deepEqual(await provider.Imagery.get('aerial'), await expectedConfig.Imagery.get('aerial'));
@@ -124,10 +121,10 @@ describe('ConfigLoader', () => {
124
121
  mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${deletedLocation}`, Api.header),
125
122
  )
126
123
  .then(() => null)
127
- .catch((e) => e);
124
+ .catch((e) => e as LambdaHttpResponse);
128
125
 
129
126
  assert.equal(error instanceof LambdaHttpResponse, true);
130
- assert.equal((error as LambdaHttpResponse).status, 400);
131
- assert.equal((error as LambdaHttpResponse).statusDescription, `Invalid config location at ${deletedLocation}`);
127
+ assert.equal(error?.status, 400);
128
+ assert.equal(error?.statusDescription, `Invalid config location at ${deletedLocation}`);
132
129
  });
133
130
  });
@@ -1,5 +1,6 @@
1
1
  import { ConfigBundled, ConfigProviderMemory } from '@basemaps/config';
2
2
  import { fsa } from '@basemaps/shared';
3
+ import { FsError } from '@chunkd/fs';
3
4
 
4
5
  import { SwappingLru } from './swapping.lru.js';
5
6
 
@@ -15,7 +16,7 @@ class LruConfig {
15
16
  return configProvider;
16
17
  })
17
18
  .catch((e) => {
18
- if (e.code === 404) return null;
19
+ if ((e as FsError).code === 404) return null;
19
20
  throw e;
20
21
  });
21
22
  }
@@ -20,7 +20,9 @@ class LruStrutObj<T extends LruStrut> {
20
20
  ob: T;
21
21
  constructor(ob: T) {
22
22
  this.ob = ob;
23
- if (this.ob._value == null) this.ob.value.then((c) => (this.ob._value = c));
23
+ if (this.ob._value == null) {
24
+ void this.ob.value.then((c) => (this.ob._value = c));
25
+ }
24
26
  }
25
27
 
26
28
  size = 1;
@@ -37,7 +39,7 @@ export class SourceCache {
37
39
 
38
40
  if (existing != null) {
39
41
  if (existing.type === 'cog') return existing.value;
40
- throw new Error(`Existing object of type: ${existing.type} made for location: ${location}`);
42
+ throw new Error(`Existing object of type: ${existing.type} made for location: ${location.href}`);
41
43
  }
42
44
  const value = Tiff.create(fsa.source(location));
43
45
  this.cache.set(location.href, new LruStrutObj({ type: 'cog', value }));
@@ -48,8 +50,8 @@ export class SourceCache {
48
50
  const existing = this.cache.get(location.href)?.ob;
49
51
 
50
52
  if (existing != null) {
51
- if (existing.type === 'cotar') return existing.value as Promise<Cotar>;
52
- throw new Error(`Existing object of type: ${existing.type} made for location: ${location}`);
53
+ if (existing.type === 'cotar') return existing.value;
54
+ throw new Error(`Existing object of type: ${existing.type} made for location: ${location.href}`);
53
55
  }
54
56
  const value = Cotar.fromTar(fsa.source(location));
55
57
  this.cache.set(location.href, new LruStrutObj({ type: 'cotar', value }));
@@ -138,7 +138,7 @@ export const Validate = {
138
138
  }
139
139
  // If the tileset has pipelines defined the user MUST specify which one
140
140
  if (tileSet.outputs) {
141
- throw new LambdaHttpResponse(404, 'TileSet needs pipeline: ' + tileSet.outputs.map((f) => f.name));
141
+ throw new LambdaHttpResponse(404, 'TileSet needs pipeline: ' + tileSet.outputs.map((f) => f.name).join(', '));
142
142
  }
143
143
 
144
144
  // Generate a default RGBA configuration
@@ -38,14 +38,15 @@ export interface WmtsBuilderParams {
38
38
  apiKey?: string;
39
39
  /** Config location */
40
40
  config?: string | null;
41
- /** Specific DateRange filter for the wmts layers */
42
- filters?: Record<string, string | undefined>;
41
+ /** Default pipeline to use */
42
+ pipeline?: string;
43
43
  }
44
44
 
45
45
  export class WmtsBuilder {
46
46
  httpBase: string;
47
47
  apiKey?: string;
48
48
  config?: string | null;
49
+ pipeline?: string;
49
50
  filters?: Record<string, string | undefined>;
50
51
 
51
52
  /** All the imagery used by the tileSet and tileMatrixes */
@@ -58,7 +59,7 @@ export class WmtsBuilder {
58
59
  this.httpBase = params.httpBase;
59
60
  this.apiKey = params.apiKey;
60
61
  this.config = params.config;
61
- this.filters = params.filters;
62
+ this.pipeline = params.pipeline;
62
63
  }
63
64
 
64
65
  addImagery(...imagery: ConfigImagery[]): void {
@@ -153,17 +154,17 @@ export class WmtsBuilder {
153
154
  return V('Style', { isDefault: 'true' }, [V('ows:Title', 'Default Style'), V('ows:Identifier', 'default')]);
154
155
  }
155
156
 
156
- buildResourceUrl(tileSetId: string, suffix: string, addFilter = false): VNodeElement {
157
+ buildResourceUrl(tileSetId: string, suffix: string): VNodeElement {
157
158
  return V('ResourceURL', {
158
159
  format: 'image/' + suffix,
159
160
  resourceType: 'tile',
160
- template: this.buildTileUrl(tileSetId, suffix, addFilter),
161
+ template: this.buildTileUrl(tileSetId, suffix),
161
162
  });
162
163
  }
163
164
 
164
- buildTileUrl(tileSetId: string, suffix: string, addFilter = false): string {
165
- let query = { api: this.apiKey, config: this.config };
166
- if (addFilter) query = { api: this.apiKey, config: this.config, ...this.filters };
165
+ buildTileUrl(tileSetId: string, suffix: string): string {
166
+ // TODO this should restrict the output formats to supported formats in pipelines
167
+ const query = { api: this.apiKey, config: this.config, pipeline: this.pipeline };
167
168
 
168
169
  return [
169
170
  this.httpBase,
@@ -239,6 +240,8 @@ export interface WmtsCapabilitiesParams {
239
240
  formats: ImageFormat[];
240
241
  /** Specific layers to add to the WMTS */
241
242
  layers?: ConfigLayer[];
243
+ /** Default output pipeline to use */
244
+ pipeline?: string | null;
242
245
  }
243
246
 
244
247
  /**
@@ -277,6 +280,10 @@ export class WmtsCapabilities extends WmtsBuilder {
277
280
  this.provider = provider;
278
281
  }
279
282
 
283
+ addPipeline(pipeline: string): void {
284
+ this.pipeline = pipeline;
285
+ }
286
+
280
287
  toProviderVNode(provider?: WmtsProvider): VNodeElement[] | [] {
281
288
  if (provider == null) return [];
282
289
  const { serviceIdentification, serviceProvider } = provider;
@@ -338,7 +345,7 @@ export class WmtsCapabilities extends WmtsBuilder {
338
345
  this.buildStyle(),
339
346
  ...this.buildFormats(),
340
347
  ...this.buildTileMatrixLink(tileSet),
341
- ...this.getFormats().map((fmt) => this.buildResourceUrl(layerNameId, fmt, true)),
348
+ ...this.getFormats().map((fmt) => this.buildResourceUrl(layerNameId, fmt)),
342
349
  ]);
343
350
  }
344
351
 
@@ -408,5 +415,6 @@ export class WmtsCapabilities extends WmtsBuilder {
408
415
  this.addTileSet(params.tileSet);
409
416
  this.addLayers(params.layers);
410
417
  this.addProvider(params.provider);
418
+ if (params.pipeline) this.addPipeline(params.pipeline);
411
419
  }
412
420
  }
package/tsconfig.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./build"
4
+ "outDir": "./build",
5
+ "rootDir": "./src"
6
6
  },
7
- "include": ["src/**/*"],
7
+ "include": ["src"],
8
8
  "references": [
9
- { "path": "../config" },
10
- { "path": "../config-loader/" },
11
- { "path": "../shared" },
12
- { "path": "../geo" },
13
- { "path": "../tiler" },
14
- { "path": "../tiler-sharp" },
15
- { "path": "../attribution" }
9
+ { "path": "../config/tsconfig.json" },
10
+ { "path": "../config-loader/tsconfig.json" },
11
+ { "path": "../shared/tsconfig.json" },
12
+ { "path": "../geo/tsconfig.json" },
13
+ { "path": "../tiler/tsconfig.json" },
14
+ { "path": "../tiler-sharp/tsconfig.json" },
15
+ { "path": "../attribution/tsconfig.json" }
16
16
  ]
17
17
  }