@basemaps/lambda-tiler 7.0.0 → 7.1.1

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 (242) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/build/__tests__/config.data.d.ts +0 -1
  3. package/build/__tests__/config.data.js +2 -6
  4. package/build/__tests__/config.data.js.map +1 -1
  5. package/build/__tests__/index.test.d.ts +0 -1
  6. package/build/__tests__/index.test.js +28 -27
  7. package/build/__tests__/index.test.js.map +1 -1
  8. package/build/__tests__/tile.style.json.test.d.ts +0 -1
  9. package/build/__tests__/tile.style.json.test.js +38 -37
  10. package/build/__tests__/tile.style.json.test.js.map +1 -1
  11. package/build/__tests__/wmts.capability.test.d.ts +0 -1
  12. package/build/__tests__/wmts.capability.test.js +111 -122
  13. package/build/__tests__/wmts.capability.test.js.map +1 -1
  14. package/build/__tests__/xyz.util.d.ts +0 -1
  15. package/build/cli/render.preview.d.ts +0 -1
  16. package/build/cli/render.preview.js +13 -9
  17. package/build/cli/render.preview.js.map +1 -1
  18. package/build/cli/render.tile.d.ts +0 -1
  19. package/build/cli/render.tile.js +25 -17
  20. package/build/cli/render.tile.js.map +1 -1
  21. package/build/index.d.ts +0 -1
  22. package/build/index.js +24 -20
  23. package/build/index.js.map +1 -1
  24. package/build/routes/__tests__/attribution.test.d.ts +0 -1
  25. package/build/routes/__tests__/attribution.test.js +38 -37
  26. package/build/routes/__tests__/attribution.test.js.map +1 -1
  27. package/build/routes/__tests__/fonts.test.d.ts +0 -1
  28. package/build/routes/__tests__/fonts.test.js +61 -63
  29. package/build/routes/__tests__/fonts.test.js.map +1 -1
  30. package/build/routes/__tests__/health.test.d.ts +0 -1
  31. package/build/routes/__tests__/health.test.js +16 -16
  32. package/build/routes/__tests__/health.test.js.map +1 -1
  33. package/build/routes/__tests__/imagery.test.d.ts +0 -1
  34. package/build/routes/__tests__/imagery.test.js +10 -9
  35. package/build/routes/__tests__/imagery.test.js.map +1 -1
  36. package/build/routes/__tests__/memory.fs.d.ts +2 -3
  37. package/build/routes/__tests__/preview.index.test.d.ts +0 -1
  38. package/build/routes/__tests__/preview.index.test.js +88 -42
  39. package/build/routes/__tests__/preview.index.test.js.map +1 -1
  40. package/build/routes/__tests__/sprites.test.d.ts +0 -1
  41. package/build/routes/__tests__/sprites.test.js +34 -34
  42. package/build/routes/__tests__/sprites.test.js.map +1 -1
  43. package/build/routes/__tests__/tile.json.test.d.ts +0 -1
  44. package/build/routes/__tests__/tile.json.test.js +45 -51
  45. package/build/routes/__tests__/tile.json.test.js.map +1 -1
  46. package/build/routes/__tests__/tile.style.json.test.d.ts +0 -1
  47. package/build/routes/__tests__/tile.style.json.test.js +49 -50
  48. package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
  49. package/build/routes/__tests__/wmts.test.d.ts +0 -1
  50. package/build/routes/__tests__/wmts.test.js +27 -20
  51. package/build/routes/__tests__/wmts.test.js.map +1 -1
  52. package/build/routes/__tests__/xyz.test.d.ts +0 -1
  53. package/build/routes/__tests__/xyz.test.js +97 -49
  54. package/build/routes/__tests__/xyz.test.js.map +1 -1
  55. package/build/routes/attribution.d.ts +1 -1
  56. package/build/routes/attribution.js +4 -5
  57. package/build/routes/attribution.js.map +1 -1
  58. package/build/routes/config.d.ts +0 -1
  59. package/build/routes/config.js +1 -2
  60. package/build/routes/config.js.map +1 -1
  61. package/build/routes/fonts.d.ts +0 -1
  62. package/build/routes/fonts.js +2 -3
  63. package/build/routes/fonts.js.map +1 -1
  64. package/build/routes/health.d.ts +1 -2
  65. package/build/routes/health.js +5 -15
  66. package/build/routes/health.js.map +1 -1
  67. package/build/routes/imagery.d.ts +0 -1
  68. package/build/routes/imagery.js +1 -1
  69. package/build/routes/imagery.js.map +1 -1
  70. package/build/routes/ping.d.ts +0 -1
  71. package/build/routes/ping.js +1 -1
  72. package/build/routes/ping.js.map +1 -1
  73. package/build/routes/preview.d.ts +6 -5
  74. package/build/routes/preview.index.d.ts +0 -1
  75. package/build/routes/preview.index.js +6 -5
  76. package/build/routes/preview.index.js.map +1 -1
  77. package/build/routes/preview.js +35 -10
  78. package/build/routes/preview.js.map +1 -1
  79. package/build/routes/sprites.d.ts +0 -1
  80. package/build/routes/sprites.js +2 -4
  81. package/build/routes/sprites.js.map +1 -1
  82. package/build/routes/tile.json.d.ts +0 -1
  83. package/build/routes/tile.json.js +10 -5
  84. package/build/routes/tile.json.js.map +1 -1
  85. package/build/routes/tile.style.json.d.ts +1 -1
  86. package/build/routes/tile.style.json.js +79 -16
  87. package/build/routes/tile.style.json.js.map +1 -1
  88. package/build/routes/tile.wmts.d.ts +0 -1
  89. package/build/routes/tile.wmts.js +8 -9
  90. package/build/routes/tile.wmts.js.map +1 -1
  91. package/build/routes/tile.xyz.d.ts +0 -1
  92. package/build/routes/tile.xyz.js.map +1 -1
  93. package/build/routes/tile.xyz.raster.d.ts +7 -8
  94. package/build/routes/tile.xyz.raster.js +22 -15
  95. package/build/routes/tile.xyz.raster.js.map +1 -1
  96. package/build/routes/tile.xyz.vector.d.ts +0 -1
  97. package/build/routes/tile.xyz.vector.js +4 -3
  98. package/build/routes/tile.xyz.vector.js.map +1 -1
  99. package/build/routes/version.d.ts +0 -1
  100. package/build/routes/version.js +3 -4
  101. package/build/routes/version.js.map +1 -1
  102. package/build/util/__test__/config.loader.test.d.ts +0 -1
  103. package/build/util/__test__/config.loader.test.js +35 -34
  104. package/build/util/__test__/config.loader.test.js.map +1 -1
  105. package/build/util/__test__/filter.test.d.ts +0 -1
  106. package/build/util/__test__/filter.test.js +17 -16
  107. package/build/util/__test__/filter.test.js.map +1 -1
  108. package/build/util/__test__/validate.test.d.ts +0 -1
  109. package/build/util/__test__/validate.test.js +26 -43
  110. package/build/util/__test__/validate.test.js.map +1 -1
  111. package/build/util/assets.provider.d.ts +5 -5
  112. package/build/util/assets.provider.js +8 -8
  113. package/build/util/assets.provider.js.map +1 -1
  114. package/build/util/config.cache.d.ts +2 -2
  115. package/build/util/config.cache.js +14 -3
  116. package/build/util/config.cache.js.map +1 -1
  117. package/build/util/config.loader.d.ts +0 -1
  118. package/build/util/config.loader.js +11 -12
  119. package/build/util/config.loader.js.map +1 -1
  120. package/build/util/cotar.serve.d.ts +3 -3
  121. package/build/util/cotar.serve.js +2 -2
  122. package/build/util/cotar.serve.js.map +1 -1
  123. package/build/util/etag.d.ts +0 -1
  124. package/build/util/etag.js.map +1 -1
  125. package/build/util/filter.d.ts +0 -1
  126. package/build/util/filter.js +4 -5
  127. package/build/util/filter.js.map +1 -1
  128. package/build/util/response.d.ts +0 -1
  129. package/build/util/source.cache.d.ts +8 -9
  130. package/build/util/source.cache.js +27 -24
  131. package/build/util/source.cache.js.map +1 -1
  132. package/build/util/swapping.lru.d.ts +0 -1
  133. package/build/util/swapping.lru.js +48 -7
  134. package/build/util/swapping.lru.js.map +1 -1
  135. package/build/util/validate.d.ts +17 -5
  136. package/build/util/validate.js +51 -15
  137. package/build/util/validate.js.map +1 -1
  138. package/build/wmts.capability.d.ts +1 -2
  139. package/build/wmts.capability.js +81 -12
  140. package/build/wmts.capability.js.map +1 -1
  141. package/bundle.sh +2 -2
  142. package/package.json +16 -18
  143. package/scripts/create.deployment.package.mjs +4 -11
  144. package/src/__tests__/config.data.ts +2 -6
  145. package/src/__tests__/index.test.ts +29 -27
  146. package/src/__tests__/tile.style.json.test.ts +40 -37
  147. package/src/__tests__/wmts.capability.test.ts +139 -120
  148. package/src/cli/render.preview.ts +14 -9
  149. package/src/cli/render.tile.ts +27 -18
  150. package/src/index.ts +28 -23
  151. package/src/routes/__tests__/attribution.test.ts +40 -37
  152. package/src/routes/__tests__/fonts.test.ts +68 -64
  153. package/src/routes/__tests__/health.test.ts +18 -17
  154. package/src/routes/__tests__/imagery.test.ts +11 -9
  155. package/src/routes/__tests__/preview.index.test.ts +114 -40
  156. package/src/routes/__tests__/sprites.test.ts +39 -34
  157. package/src/routes/__tests__/tile.json.test.ts +41 -39
  158. package/src/routes/__tests__/tile.style.json.test.ts +49 -46
  159. package/src/routes/__tests__/wmts.test.ts +28 -20
  160. package/src/routes/__tests__/xyz.test.ts +134 -55
  161. package/src/routes/attribution.ts +2 -2
  162. package/src/routes/config.ts +1 -0
  163. package/src/routes/fonts.ts +3 -3
  164. package/src/routes/health.ts +7 -13
  165. package/src/routes/imagery.ts +2 -1
  166. package/src/routes/ping.ts +1 -1
  167. package/src/routes/preview.index.ts +9 -5
  168. package/src/routes/preview.ts +44 -15
  169. package/src/routes/sprites.ts +4 -5
  170. package/src/routes/tile.json.ts +9 -2
  171. package/src/routes/tile.style.json.ts +89 -13
  172. package/src/routes/tile.wmts.ts +4 -3
  173. package/src/routes/tile.xyz.raster.ts +30 -23
  174. package/src/routes/tile.xyz.ts +1 -0
  175. package/src/routes/tile.xyz.vector.ts +5 -3
  176. package/src/routes/version.ts +3 -3
  177. package/src/util/__test__/config.loader.test.ts +38 -34
  178. package/src/util/__test__/filter.test.ts +19 -16
  179. package/src/util/__test__/validate.test.ts +28 -43
  180. package/src/util/assets.provider.ts +10 -9
  181. package/src/util/config.cache.ts +4 -3
  182. package/src/util/config.loader.ts +13 -13
  183. package/src/util/cotar.serve.ts +3 -2
  184. package/src/util/source.cache.ts +15 -26
  185. package/src/util/validate.ts +61 -14
  186. package/src/wmts.capability.ts +3 -3
  187. package/tsconfig.json +1 -0
  188. package/tsconfig.tsbuildinfo +1 -1
  189. package/build/__tests__/config.data.d.ts.map +0 -1
  190. package/build/__tests__/index.test.d.ts.map +0 -1
  191. package/build/__tests__/tile.style.json.test.d.ts.map +0 -1
  192. package/build/__tests__/wmts.capability.test.d.ts.map +0 -1
  193. package/build/__tests__/xyz.util.d.ts.map +0 -1
  194. package/build/cli/render.preview.d.ts.map +0 -1
  195. package/build/cli/render.tile.d.ts.map +0 -1
  196. package/build/index.d.ts.map +0 -1
  197. package/build/routes/__tests__/attribution.test.d.ts.map +0 -1
  198. package/build/routes/__tests__/fonts.test.d.ts.map +0 -1
  199. package/build/routes/__tests__/health.test.d.ts.map +0 -1
  200. package/build/routes/__tests__/imagery.test.d.ts.map +0 -1
  201. package/build/routes/__tests__/memory.fs.d.ts.map +0 -1
  202. package/build/routes/__tests__/preview.index.test.d.ts.map +0 -1
  203. package/build/routes/__tests__/sprites.test.d.ts.map +0 -1
  204. package/build/routes/__tests__/tile.json.test.d.ts.map +0 -1
  205. package/build/routes/__tests__/tile.style.json.test.d.ts.map +0 -1
  206. package/build/routes/__tests__/wmts.test.d.ts.map +0 -1
  207. package/build/routes/__tests__/xyz.test.d.ts.map +0 -1
  208. package/build/routes/attribution.d.ts.map +0 -1
  209. package/build/routes/config.d.ts.map +0 -1
  210. package/build/routes/fonts.d.ts.map +0 -1
  211. package/build/routes/health.d.ts.map +0 -1
  212. package/build/routes/imagery.d.ts.map +0 -1
  213. package/build/routes/ping.d.ts.map +0 -1
  214. package/build/routes/preview.d.ts.map +0 -1
  215. package/build/routes/preview.index.d.ts.map +0 -1
  216. package/build/routes/sprites.d.ts.map +0 -1
  217. package/build/routes/tile.json.d.ts.map +0 -1
  218. package/build/routes/tile.style.json.d.ts.map +0 -1
  219. package/build/routes/tile.wmts.d.ts.map +0 -1
  220. package/build/routes/tile.xyz.d.ts.map +0 -1
  221. package/build/routes/tile.xyz.raster.d.ts.map +0 -1
  222. package/build/routes/tile.xyz.vector.d.ts.map +0 -1
  223. package/build/routes/version.d.ts.map +0 -1
  224. package/build/util/__test__/config.loader.test.d.ts.map +0 -1
  225. package/build/util/__test__/filter.test.d.ts.map +0 -1
  226. package/build/util/__test__/validate.test.d.ts.map +0 -1
  227. package/build/util/assets.provider.d.ts.map +0 -1
  228. package/build/util/config.cache.d.ts.map +0 -1
  229. package/build/util/config.loader.d.ts.map +0 -1
  230. package/build/util/cotar.serve.d.ts.map +0 -1
  231. package/build/util/etag.d.ts.map +0 -1
  232. package/build/util/filter.d.ts.map +0 -1
  233. package/build/util/response.d.ts.map +0 -1
  234. package/build/util/source.cache.d.ts.map +0 -1
  235. package/build/util/source.tracer.d.ts +0 -18
  236. package/build/util/source.tracer.d.ts.map +0 -1
  237. package/build/util/source.tracer.js +0 -26
  238. package/build/util/source.tracer.js.map +0 -1
  239. package/build/util/swapping.lru.d.ts.map +0 -1
  240. package/build/util/validate.d.ts.map +0 -1
  241. package/build/wmts.capability.d.ts.map +0 -1
  242. package/src/util/source.tracer.ts +0 -38
@@ -1,16 +1,18 @@
1
- import { Env, LogConfig, V, fsa } from '@basemaps/shared';
1
+ import assert from 'node:assert';
2
+ import { afterEach, beforeEach, describe, it } from 'node:test';
3
+
4
+ import { ConfigProviderMemory, DefaultColorRampOutput, DefaultTerrainRgbOutput } from '@basemaps/config';
5
+ import { LocationUrl } from '@basemaps/geo';
6
+ import { Env, fsa, FsMemory, LogConfig, V } from '@basemaps/shared';
2
7
  import { LambdaAlbRequest, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
3
8
  import { ALBEvent, Context } from 'aws-lambda';
4
- import o from 'ospec';
5
9
 
6
- import { PreviewIndexGet, loadAndServeIndexHtml, previewIndexGet } from '../preview.index.js';
7
- import { LocationUrl } from '@basemaps/geo';
8
- import { FsMemory } from '@chunkd/source-memory';
9
- import { ConfigProviderMemory } from '@basemaps/config';
10
10
  import { FakeData } from '../../__tests__/config.data.js';
11
+ import { CachedConfig } from '../../util/config.cache.js';
12
+ import { loadAndServeIndexHtml, PreviewIndexGet, previewIndexGet } from '../preview.index.js';
11
13
 
12
- o.spec('/@*', async () => {
13
- o.specTimeout(1000);
14
+ describe('/@*', async () => {
15
+ // o.specTimeout(1000);
14
16
  const baseRequest: ALBEvent = {
15
17
  requestContext: null as any,
16
18
  httpMethod: 'get',
@@ -21,51 +23,63 @@ o.spec('/@*', async () => {
21
23
 
22
24
  const fsMem = new FsMemory();
23
25
  let lastLocation: string | undefined;
24
- o.beforeEach(() => {
26
+ beforeEach(async () => {
27
+ CachedConfig.cache.clear();
28
+
25
29
  fsa.register('memory://', fsMem);
30
+
31
+ const indexHtml = V('html', [
32
+ V('head', [
33
+ V('meta', { property: 'og:title', content: 'LINZ Basemaps' }),
34
+ V('meta', { property: 'og:image', content: '/basemaps-card.jpeg' }),
35
+ V('meta', { name: 'viewport' }),
36
+ ]),
37
+ ]).toString();
38
+ await fsa.write(new URL('memory://assets/index.html'), indexHtml);
39
+
26
40
  lastLocation = process.env[Env.StaticAssetLocation];
27
41
  });
28
- o.afterEach(() => {
42
+ afterEach(() => {
29
43
  if (lastLocation == null) delete process.env[Env.StaticAssetLocation];
30
44
  else process.env[Env.StaticAssetLocation] = lastLocation;
31
45
  });
32
46
 
33
- o('Should redirect on failure to load', async () => {
47
+ it('Should redirect on failure to load', async () => {
34
48
  const ctx: LambdaHttpRequest = new LambdaAlbRequest(baseRequest, {} as Context, LogConfig.get());
35
49
 
36
50
  const res = await loadAndServeIndexHtml(ctx);
37
- o(res.status).equals(302);
38
- o(res.header('location')).equals('/?');
51
+ assert.equal(res.status, 302);
52
+ assert.equal(res.header('location'), '/?');
39
53
  });
40
54
 
41
- o('Should redirect with querystring on failure to load', async () => {
55
+ it('Should redirect with querystring on failure to load', async () => {
42
56
  const evt: ALBEvent = { ...baseRequest, queryStringParameters: { config: 'config-latest.json' } };
43
57
  const ctx: LambdaHttpRequest = new LambdaAlbRequest(evt, {} as Context, LogConfig.get());
44
58
 
45
59
  const res = await loadAndServeIndexHtml(ctx);
46
- o(res.status).equals(302);
47
- o(res.header('location')).equals('/?config=config-latest.json');
60
+ assert.equal(res.status, 302);
61
+ assert.equal(res.header('location'), '/?config=config-latest.json');
48
62
  });
49
63
 
50
- o('Should redirect with querystring and location on failure to load', async () => {
64
+ it('Should redirect with querystring and location on failure to load', async () => {
51
65
  const evt: ALBEvent = { ...baseRequest, queryStringParameters: { config: 'config-latest.json' } };
52
66
  const loc = LocationUrl.fromSlug(evt.path);
53
67
  const ctx: LambdaHttpRequest = new LambdaAlbRequest(evt, {} as Context, LogConfig.get());
54
68
 
55
69
  const res = await loadAndServeIndexHtml(ctx, loc);
56
- o(res.status).equals(302);
57
- o(res.header('location')).equals('/?config=config-latest.json#@-41.8900012,174.0492432,z5');
70
+ assert.equal(res.status, 302);
71
+ assert.equal(res.header('location'), '/?config=config-latest.json#@-41.8900012,174.0492432,z5');
58
72
  });
59
73
 
60
- o('should redirect on failure to load index.html', async () => {
74
+ it('should redirect on failure to load index.html', async () => {
61
75
  const ctx: LambdaHttpRequest = new LambdaAlbRequest(baseRequest, {} as Context, LogConfig.get());
62
- process.env[Env.StaticAssetLocation] = 'memory://assets/';
76
+ process.env[Env.StaticAssetLocation] = 'memory://assets-missing/';
63
77
 
64
78
  const res = await loadAndServeIndexHtml(ctx);
65
- o(res.status).equals(302);
79
+ assert.equal(res.status, 302);
66
80
  });
67
81
 
68
- o('should redirect with new tags!', async () => {
82
+ it('should redirect with new tags!', async () => {
69
83
  const ctx = new LambdaAlbRequest(baseRequest, {} as Context, LogConfig.get());
70
84
  process.env[Env.StaticAssetLocation] = 'memory://assets/';
71
85
 
@@ -77,18 +91,20 @@ o.spec('/@*', async () => {
77
91
  ]),
78
92
  ]).toString();
79
93
 
80
- await fsa.write('memory://assets/index.html', indexHtml);
94
+ await fsa.write(new URL('memory://assets/index.html'), indexHtml);
81
95
 
82
96
  // Pass back the body un altered
83
97
  const res = await loadAndServeIndexHtml(ctx);
84
- o(getBody(res)?.toString()).equals(indexHtml);
98
+ assert.equal(getBody(res)?.toString(), indexHtml);
85
99
 
86
100
  // Replace og:title with a <fake tag />
87
101
  const resB = await loadAndServeIndexHtml(ctx, null, new Map([['og:title', '<fake tag />']]));
88
- o(getBody(resB)?.toString().includes('<fake tag />')).equals(true);
102
+ assert.equal(getBody(resB)?.toString().includes('<fake tag />'), true);
89
103
  });
90
104
 
91
- o('should include config url', async () => {
105
+ it('should include config url', async () => {
106
+ process.env[Env.StaticAssetLocation] = 'memory://assets/';
107
+
92
108
  const ctx = new LambdaAlbRequest(
93
109
  {
94
110
  ...baseRequest,
@@ -99,32 +115,90 @@ o.spec('/@*', async () => {
99
115
  ) as unknown as LambdaHttpRequest<PreviewIndexGet>;
100
116
  ctx.params = { location: '@-41.8900012,174.0492432,z5' };
101
117
 
102
- // Create a fake config to use
103
118
  const expectedConfig = new ConfigProviderMemory();
104
119
  expectedConfig.put(FakeData.tileSetRaster('imagery-name'));
105
- await fsa.write('memory://linz-basemaps/config-latest.json', JSON.stringify(expectedConfig.toJson()));
120
+ await fsa.write(new URL('memory://linz-basemaps/config-latest.json'), JSON.stringify(expectedConfig.toJson()));
121
+
122
+ const res = await previewIndexGet(ctx);
123
+ assert.equal(res.status, 200);
106
124
 
125
+ const ogImage = getBody(res)
126
+ ?.toString()
127
+ .split('\n')
128
+ .find((f) => f.includes('og:image'));
129
+ assert.equal(
130
+ ogImage,
131
+ '<meta name="twitter:image" property="og:image" content="/v1/preview/imagery-name/WebMercatorQuad/5/174.0492432/-41.8900012?config=QzX7ZsK6qG6p42wHZaF9dhihsgprX942gAuKwfryknM429iqxdDiRSGu" />',
132
+ );
133
+ });
134
+
135
+ it('should include default pipeline', { only: true }, async () => {
107
136
  process.env[Env.StaticAssetLocation] = 'memory://assets/';
108
137
 
109
- const indexHtml = V('html', [
110
- V('head', [
111
- V('meta', { property: 'og:title', content: 'LINZ Basemaps' }),
112
- V('meta', { property: 'og:image', content: '/basemaps-card.jepg' }),
113
- V('meta', { name: 'viewport' }),
114
- ]),
115
- ]).toString();
138
+ const ctx = new LambdaAlbRequest(
139
+ {
140
+ ...baseRequest,
141
+ queryStringParameters: { config: 'memory://linz-basemaps/config-latest.json', i: 'imagery-name' },
142
+ },
143
+ {} as Context,
144
+ LogConfig.get(),
145
+ ) as unknown as LambdaHttpRequest<PreviewIndexGet>;
146
+ ctx.params = { location: '@-41.8900012,174.0492432,z5' };
116
147
 
117
- await fsa.write('memory://assets/index.html', indexHtml);
148
+ const expectedConfig = new ConfigProviderMemory();
149
+ const ts = FakeData.tileSetRaster('imagery-name');
150
+ ts.outputs = [DefaultTerrainRgbOutput, DefaultColorRampOutput];
151
+ expectedConfig.put(ts);
152
+ await fsa.write(new URL('memory://linz-basemaps/config-latest.json'), JSON.stringify(expectedConfig.toJson()));
118
153
 
119
154
  const res = await previewIndexGet(ctx);
120
- o(res.status).equals(200);
155
+ assert.equal(res.status, 200, res.statusDescription);
121
156
 
122
157
  const ogImage = getBody(res)
123
158
  ?.toString()
124
159
  .split('\n')
125
160
  .find((f) => f.includes('og:image'));
126
- o(ogImage).equals(
127
- '<meta name="twitter:image" property="og:image" content="/v1/preview/imagery-name/WebMercatorQuad/5/174.0492432/-41.8900012?config=QzX7ZsK6qG6p42wHZaF9dhihsgprX942gAuKwfryknM429iqxdDiRSGu" />',
161
+
162
+ assert.equal(
163
+ ogImage,
164
+ '<meta name="twitter:image" property="og:image" content="/v1/preview/imagery-name/WebMercatorQuad/5/174.0492432/-41.8900012?config=QzX7ZsK6qG6p42wHZaF9dhihsgprX942gAuKwfryknM429iqxdDiRSGu&pipeline=terrain-rgb" />',
165
+ );
166
+ });
167
+
168
+ it('should include pipelines', async () => {
169
+ process.env[Env.StaticAssetLocation] = 'memory://assets/';
170
+
171
+ const ctx = new LambdaAlbRequest(
172
+ {
173
+ ...baseRequest,
174
+ queryStringParameters: {
175
+ config: 'memory://linz-basemaps/config-latest.json',
176
+ i: 'imagery-name',
177
+ pipeline: 'color-ramp',
178
+ },
179
+ },
180
+ {} as Context,
181
+ LogConfig.get(),
182
+ ) as unknown as LambdaHttpRequest<PreviewIndexGet>;
183
+ ctx.params = { location: '@-41.8900012,174.0492432,z5' };
184
+
185
+ const expectedConfig = new ConfigProviderMemory();
186
+ const ts = FakeData.tileSetRaster('imagery-name');
187
+ ts.outputs = [DefaultTerrainRgbOutput, DefaultColorRampOutput];
188
+ expectedConfig.put(ts);
189
+ await fsa.write(new URL('memory://linz-basemaps/config-latest.json'), JSON.stringify(expectedConfig.toJson()));
190
+
191
+ const res = await previewIndexGet(ctx);
192
+ assert.equal(res.status, 200, res.statusDescription);
193
+
194
+ const ogImage = getBody(res)
195
+ ?.toString()
196
+ .split('\n')
197
+ .find((f) => f.includes('og:image'));
198
+
199
+ assert.equal(
200
+ ogImage,
201
+ '<meta name="twitter:image" property="og:image" content="/v1/preview/imagery-name/WebMercatorQuad/5/174.0492432/-41.8900012?config=QzX7ZsK6qG6p42wHZaF9dhihsgprX942gAuKwfryknM429iqxdDiRSGu&pipeline=color-ramp" />',
128
202
  );
129
203
  });
130
204
  });
@@ -1,69 +1,74 @@
1
+ import assert from 'node:assert';
2
+ import { afterEach, before, beforeEach, describe, it } from 'node:test';
3
+
1
4
  import { ConfigProviderMemory } from '@basemaps/config';
2
- import { fsa } from '@chunkd/fs';
3
- import o from 'ospec';
5
+ import { fsa, FsMemory } from '@chunkd/fs';
4
6
  import { createSandbox } from 'sinon';
5
7
  import { gunzipSync, gzipSync } from 'zlib';
8
+
9
+ import { mockRequest } from '../../__tests__/xyz.util.js';
6
10
  import { handler } from '../../index.js';
7
11
  import { ConfigLoader } from '../../util/config.loader.js';
8
- import { mockRequest } from '../../__tests__/xyz.util.js';
9
- import { FsMemory } from '@chunkd/source-memory';
10
12
 
11
- o.spec('/v1/sprites', () => {
13
+ describe('/v1/sprites', () => {
12
14
  const memory = new FsMemory();
13
15
  const sandbox = createSandbox();
14
16
  const config = new ConfigProviderMemory();
15
17
 
16
- o.before(() => {
17
- fsa.register('memory://', memory);
18
+ before(() => {
19
+ fsa.register('fake-s3://assets/', memory);
18
20
  });
19
21
 
20
- o.beforeEach(() => {
21
- config.assets = 'memory://';
22
+ beforeEach(() => {
23
+ config.assets = 'fake-s3://assets/';
22
24
  sandbox.stub(ConfigLoader, 'getDefaultConfig').resolves(config);
23
25
  });
24
26
 
25
- o.afterEach(() => {
27
+ afterEach(() => {
26
28
  memory.files.clear();
27
29
  sandbox.restore();
28
30
  });
29
31
 
30
- o('should fetch a json document', async () => {
32
+ it('should fetch a json document', async () => {
31
33
  await Promise.all([
32
- fsa.write('memory://sprites/topographic.json', Buffer.from(JSON.stringify({ test: true }))),
33
- fsa.write('memory://sprites/topographic.png', Buffer.from('')),
34
+ fsa.write(new URL('fake-s3://assets/sprites/topographic.json'), Buffer.from(JSON.stringify({ test: true }))),
35
+ fsa.write(new URL('fake-s3://assets/sprites/topographic.png'), Buffer.from('')),
34
36
  ]);
35
37
  const res = await handler.router.handle(mockRequest('/v1/sprites/topographic.json'));
36
- o(res.status).equals(200);
37
- o(res.header('content-type')).equals('application/json');
38
- o(res.header('content-encoding')).equals(undefined);
39
- o(res.header('etag')).notEquals(undefined);
40
- o(res.header('cache-control')).equals('public, max-age=604800, stale-while-revalidate=86400');
38
+ assert.equal(res.status, 200);
39
+ assert.equal(res.header('content-type'), 'application/json');
40
+ assert.equal(res.header('content-encoding'), undefined);
41
+ assert.notEqual(res.header('etag'), undefined);
42
+ assert.equal(res.header('cache-control'), 'public, max-age=604800, stale-while-revalidate=86400');
41
43
 
42
- o(JSON.parse(Buffer.from(res.body, 'base64').toString())).deepEquals({ test: true });
44
+ assert.deepEqual(JSON.parse(Buffer.from(res.body, 'base64').toString()), { test: true });
43
45
  });
44
46
 
45
- o('should fetch a png', async () => {
47
+ it('should fetch a png', async () => {
46
48
  await Promise.all([
47
- fsa.write('memory://sprites/topographic.json', Buffer.from(JSON.stringify({ test: true }))),
48
- fsa.write('memory://sprites/topographic@2x.png', Buffer.from('')),
49
+ fsa.write(new URL('fake-s3://assets/sprites/topographic.json'), Buffer.from(JSON.stringify({ test: true }))),
50
+ fsa.write(new URL('fake-s3://assets/sprites/topographic@2x.png'), Buffer.from('')),
49
51
  ]);
50
52
  const res = await handler.router.handle(mockRequest('/v1/sprites/topographic@2x.png'));
51
- o(res.status).equals(200);
52
- o(res.header('content-type')).equals('image/png');
53
- o(res.header('etag')).notEquals(undefined);
54
- o(res.header('cache-control')).equals('public, max-age=604800, stale-while-revalidate=86400');
53
+ assert.equal(res.status, 200);
54
+ assert.equal(res.header('content-type'), 'image/png');
55
+ assert.notEqual(res.header('etag'), undefined);
56
+ assert.equal(res.header('cache-control'), 'public, max-age=604800, stale-while-revalidate=86400');
55
57
  });
56
58
 
57
- o('should detect gziped files and set content-encoding', async () => {
59
+ it('should detect gziped files and set content-encoding', async () => {
58
60
  await Promise.all([
59
- fsa.write('memory://sprites/topographic.json', gzipSync(Buffer.from(JSON.stringify({ test: true })))),
61
+ fsa.write(
62
+ new URL('fake-s3://assets/sprites/topographic.json'),
63
+ gzipSync(Buffer.from(JSON.stringify({ test: true }))),
64
+ ),
60
65
  ]);
61
66
  const res = await handler.router.handle(mockRequest('/v1/sprites/topographic.json'));
62
- o(res.status).equals(200);
63
- o(res.header('content-type')).equals('application/json');
64
- o(res.header('content-encoding')).equals('gzip');
65
- o(res.header('etag')).notEquals(undefined);
66
- o(res.header('cache-control')).equals('public, max-age=604800, stale-while-revalidate=86400');
67
- o(JSON.parse(gunzipSync(Buffer.from(res.body, 'base64')).toString())).deepEquals({ test: true });
67
+ assert.equal(res.status, 200);
68
+ assert.equal(res.header('content-type'), 'application/json');
69
+ assert.equal(res.header('content-encoding'), 'gzip');
70
+ assert.notEqual(res.header('etag'), undefined);
71
+ assert.equal(res.header('cache-control'), 'public, max-age=604800, stale-while-revalidate=86400');
72
+ assert.deepEqual(JSON.parse(gunzipSync(Buffer.from(res.body, 'base64')).toString()), { test: true });
68
73
  });
69
74
  });
@@ -1,68 +1,70 @@
1
+ import assert from 'node:assert';
2
+ import { afterEach, before, beforeEach, describe, it } from 'node:test';
3
+
1
4
  import { base58, ConfigProviderMemory } from '@basemaps/config';
2
5
  import { Env } from '@basemaps/shared';
3
- import { fsa } from '@chunkd/fs';
4
- import o from 'ospec';
6
+ import { fsa, FsMemory } from '@chunkd/fs';
5
7
  import sinon from 'sinon';
8
+
9
+ import { FakeData } from '../../__tests__/config.data.js';
10
+ import { Api, mockRequest, mockUrlRequest } from '../../__tests__/xyz.util.js';
6
11
  import { handler } from '../../index.js';
7
12
  import { ConfigLoader } from '../../util/config.loader.js';
8
13
  import { CoSources } from '../../util/source.cache.js';
9
- import { FakeData } from '../../__tests__/config.data.js';
10
- import { Api, mockRequest, mockUrlRequest } from '../../__tests__/xyz.util.js';
11
- import { FsMemory } from '@chunkd/source-memory';
12
14
 
13
- o.spec('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
15
+ describe('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
14
16
  const config = new ConfigProviderMemory();
15
17
  const sandbox = sinon.createSandbox();
16
18
 
17
- o.before(() => {
19
+ before(() => {
18
20
  process.env[Env.PublicUrlBase] = 'https://tiles.test';
19
21
  });
20
22
 
21
- o.beforeEach(() => {
23
+ beforeEach(() => {
22
24
  sandbox.stub(ConfigLoader, 'getDefaultConfig').resolves(config);
23
25
  config.objects.clear();
24
26
  CoSources.cache.clear();
25
27
  });
26
28
 
27
- o.afterEach(() => {
29
+ afterEach(() => {
28
30
  sandbox.restore();
29
31
  });
30
32
 
31
- o('should 404 if invalid url is given', async () => {
33
+ it('should 404 if invalid url is given', async () => {
32
34
  const request = mockRequest('/v1/tiles/tile.json', 'get', Api.header);
33
35
 
34
36
  const res = await handler.router.handle(request);
35
- o(res.status).equals(404);
37
+ assert.equal(res.status, 404);
36
38
  });
37
39
 
38
- o('should support utf8 tilesets', async () => {
40
+ it('should support utf8 tilesets', async () => {
39
41
  const request = mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `api=${Api.key}`);
40
- o(request.path).equals('/v1/tiles/%F0%9F%A6%84%20%F0%9F%8C%88/NZTM2000Quad/tile.json');
42
+ assert.equal(request.path, '/v1/tiles/%F0%9F%A6%84%20%F0%9F%8C%88/NZTM2000Quad/tile.json');
41
43
 
42
44
  const fakeTileSet = FakeData.tileSetRaster('🦄 🌈');
43
45
  config.put(fakeTileSet);
44
46
 
45
47
  const res = await handler.router.handle(request);
46
- o(res.status).equals(200);
48
+ assert.equal(res.status, 200);
47
49
  });
48
50
 
49
- o('should serve tile json for tile_set', async () => {
51
+ it('should serve tile json for tile_set', async () => {
50
52
  const request = mockRequest('/v1/tiles/aerial/NZTM2000Quad/tile.json', 'get', Api.header);
51
53
  const fakeTileSet = FakeData.tileSetRaster('aerial');
52
54
  config.put(fakeTileSet);
53
55
 
54
56
  const res = await handler.router.handle(request);
55
- o(res.status).equals(200);
56
- o(res.header('cache-control')).equals('no-store');
57
+ assert.equal(res.status, 200);
58
+ assert.equal(res.header('cache-control'), 'no-store');
57
59
 
58
60
  const body = Buffer.from(res.body ?? '', 'base64').toString();
59
- o(JSON.parse(body)).deepEquals({
61
+ assert.deepEqual(JSON.parse(body), {
60
62
  tiles: [`https://tiles.test/v1/tiles/aerial/NZTM2000Quad/{z}/{x}/{y}.webp?api=${Api.key}`],
61
63
  tilejson: '3.0.0',
62
64
  });
63
65
  });
64
66
 
65
- o('should use the correct format', async () => {
67
+ it('should use the correct format', async () => {
66
68
  const request = mockRequest('/v1/tiles/aerial/NZTM2000Quad/tile.json', 'get', Api.header);
67
69
  request.query.set('format', 'jpeg');
68
70
 
@@ -70,17 +72,17 @@ o.spec('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
70
72
  config.put(fakeTileSet);
71
73
 
72
74
  const res = await handler.router.handle(request);
73
- o(res.status).equals(200);
74
- o(res.header('cache-control')).equals('no-store');
75
+ assert.equal(res.status, 200);
76
+ assert.equal(res.header('cache-control'), 'no-store');
75
77
 
76
78
  const body = Buffer.from(res.body ?? '', 'base64').toString();
77
- o(JSON.parse(body)).deepEquals({
79
+ assert.deepEqual(JSON.parse(body), {
78
80
  tiles: [`https://tiles.test/v1/tiles/aerial/NZTM2000Quad/{z}/{x}/{y}.jpeg?api=${Api.key}`],
79
81
  tilejson: '3.0.0',
80
82
  });
81
83
  });
82
84
 
83
- o('should use the correct format when multiple set', async () => {
85
+ it('should use the correct format when multiple set', async () => {
84
86
  const request = mockRequest('/v1/tiles/aerial/NZTM2000Quad/tile.json', 'get', Api.header);
85
87
  request.query.append('format', 'png');
86
88
  request.query.append('format', 'jpeg');
@@ -89,32 +91,32 @@ o.spec('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
89
91
  config.put(fakeTileSet);
90
92
 
91
93
  const res = await handler.router.handle(request);
92
- o(res.status).equals(200);
93
- o(res.header('cache-control')).equals('no-store');
94
+ assert.equal(res.status, 200);
95
+ assert.equal(res.header('cache-control'), 'no-store');
94
96
 
95
97
  const body = Buffer.from(res.body ?? '', 'base64').toString();
96
- o(JSON.parse(body)).deepEquals({
98
+ assert.deepEqual(JSON.parse(body), {
97
99
  tiles: [`https://tiles.test/v1/tiles/aerial/NZTM2000Quad/{z}/{x}/{y}.png?api=${Api.key}`],
98
100
  tilejson: '3.0.0',
99
101
  });
100
102
  });
101
103
 
102
- o('should serve vector tiles', async () => {
104
+ it('should serve vector tiles', async () => {
103
105
  const request = mockRequest('/v1/tiles/topographic/EPSG:3857/tile.json', 'get', Api.header);
104
106
  const fakeTileSet = FakeData.tileSetVector('topographic');
105
107
  config.put(fakeTileSet);
106
108
 
107
109
  const res = await handler.router.handle(request);
108
- o(res.status).equals(200);
110
+ assert.equal(res.status, 200);
109
111
 
110
112
  const body = Buffer.from(res.body ?? '', 'base64').toString();
111
- o(JSON.parse(body)).deepEquals({
113
+ assert.deepEqual(JSON.parse(body), {
112
114
  tiles: [`https://tiles.test/v1/tiles/topographic/WebMercatorQuad/{z}/{x}/{y}.pbf?api=${Api.key}`],
113
115
  tilejson: '3.0.0',
114
116
  });
115
117
  });
116
118
 
117
- o('should serve vector tiles with min/max zoom', async () => {
119
+ it('should serve vector tiles with min/max zoom', async () => {
118
120
  const fakeTileSet = FakeData.tileSetVector('fake-vector');
119
121
  fakeTileSet.maxZoom = 15;
120
122
  fakeTileSet.minZoom = 3;
@@ -122,10 +124,10 @@ o.spec('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
122
124
  const request = mockRequest('/v1/tiles/fake-vector/WebMercatorQuad/tile.json', 'get', Api.header);
123
125
 
124
126
  const res = await handler.router.handle(request);
125
- o(res.status).equals(200);
127
+ assert.equal(res.status, 200);
126
128
 
127
129
  const body = Buffer.from(res.body ?? '', 'base64').toString();
128
- o(JSON.parse(body)).deepEquals({
130
+ assert.deepEqual(JSON.parse(body), {
129
131
  tiles: [`https://tiles.test/v1/tiles/fake-vector/WebMercatorQuad/{z}/{x}/{y}.pbf?api=${Api.key}`],
130
132
  maxzoom: 15,
131
133
  minzoom: 3,
@@ -133,25 +135,25 @@ o.spec('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
133
135
  });
134
136
  });
135
137
 
136
- o('should load from config bundle', async () => {
138
+ it('should load from config bundle', async () => {
137
139
  const memoryFs = new FsMemory();
138
140
  fsa.register('memory://', memoryFs);
139
141
  const fakeTileSet = FakeData.tileSetRaster('🦄 🌈');
140
142
 
141
143
  const cfgBundle = new ConfigProviderMemory();
142
144
  cfgBundle.put(fakeTileSet);
143
- memoryFs.write('memory://linz-basemaps/bar.json', JSON.stringify(cfgBundle.toJson()));
145
+ memoryFs.write(new URL('memory://linz-basemaps/bar.json'), JSON.stringify(cfgBundle.toJson()));
144
146
 
145
147
  const configLocation = base58.encode(Buffer.from('memory://linz-basemaps/bar.json'));
146
148
  const request = mockUrlRequest('/v1/tiles/🦄 🌈/NZTM2000Quad/tile.json', `?config=${configLocation}`, Api.header);
147
149
  const res = await handler.router.handle(request);
148
- o(res.status).equals(200);
150
+ assert.equal(res.status, 200);
149
151
 
150
152
  const body = JSON.parse(Buffer.from(res.body, 'base64').toString());
151
- o(body.tiles[0].includes(`config=${configLocation}`)).equals(true);
153
+ assert.equal(body.tiles[0].includes(`config=${configLocation}`), true);
152
154
  });
153
155
 
154
- o('should serve convert zoom to tile matrix', async () => {
156
+ it('should serve convert zoom to tile matrix', async () => {
155
157
  const fakeTileSet = FakeData.tileSetVector('fake-vector');
156
158
  fakeTileSet.maxZoom = 15;
157
159
  fakeTileSet.minZoom = 1;
@@ -160,10 +162,10 @@ o.spec('/v1/tiles/:tileSet/:tileMatrix/tile.json', () => {
160
162
  const request = mockRequest('/v1/tiles/fake-vector/NZTM2000Quad/tile.json', 'get', Api.header);
161
163
 
162
164
  const res = await handler.router.handle(request);
163
- o(res.status).equals(200);
165
+ assert.equal(res.status, 200);
164
166
 
165
167
  const body = Buffer.from(res.body ?? '', 'base64').toString();
166
- o(JSON.parse(body)).deepEquals({
168
+ assert.deepEqual(JSON.parse(body), {
167
169
  tiles: [`https://tiles.test/v1/tiles/fake-vector/NZTM2000Quad/{z}/{x}/{y}.pbf?api=${Api.key}`],
168
170
  maxzoom: 13,
169
171
  minzoom: 0,