@zthun/romulator-api 1.9.0 → 1.10.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/main.js CHANGED
@@ -3,12 +3,12 @@ import { ApiProperty, ApiParam, ApiBody, ApiQuery, ApiResponse, ApiTags, Documen
3
3
  import { InternalServerErrorException, NotFoundException, Injectable, Inject, Get, Query, Patch, UsePipes, ValidationPipe, Param, Body, Controller, Module, NotAcceptableException, StreamableFile, ForbiddenException, Req, Delete } from '@nestjs/common';
4
4
  import { ZFileSystemModule, ZFileSystemToken } from '@zthun/crumbtrail-nest';
5
5
  import { ZLoggerToken, ZLoggerModule } from '@zthun/lumberjacky-nest';
6
- import { ZDataSourceStaticOptionsBuilder, ZDataSearchFields, ZDataSourceStatic, ZPageBuilder, ZDataRequestBuilder, ZSortBuilder, ZFilterBinaryBuilder, ZFilterLogicBuilder } from '@zthun/helpful-query';
6
+ import { ZDataSourceStaticOptionsBuilder, ZDataSearchFields, ZDataSourceStatic, ZPageBuilder, ZDataRequestBuilder, ZSortBuilder, ZFilterBinaryBuilder } from '@zthun/helpful-query';
7
7
  import { IsDefined, IsObject, IsNotEmptyObject } from 'class-validator';
8
- import { firstDefined, createError, detokenize, firstTruthy, html } from '@zthun/helpful-fn';
8
+ import { firstDefined, createError, detokenize, firstTruthy, mib, html } from '@zthun/helpful-fn';
9
9
  import { ZLoggerContext, ZLogEntryBuilder } from '@zthun/lumberjacky-log';
10
- import { ZRomulatorConfigBuilder, ZRomulatorConfigId as ZRomulatorConfigId$1, ZRomulatorConfigGamesMetadata, ZRomulatorSystemBuilder, ZRomulatorSystemId, ZRomulatorConfigGamesBuilder, ZRomulatorGameBuilder, ZRomulatorMediaBuilder, isSystemId } from '@zthun/romulator-client';
11
- import { find, kebabCase, castArray, trimEnd, first, findIndex } from 'lodash-es';
10
+ import { ZRomulatorConfigBuilder, ZRomulatorConfigId as ZRomulatorConfigId$1, ZRomulatorConfigGamesMetadata, ZRomulatorSystemBuilder, ZRomulatorSystemId, ZRomulatorConfigGamesBuilder, ZRomulatorGameBuilder, isSystemId, ZRomulatorMediaBuilder } from '@zthun/romulator-client';
11
+ import { find, kebabCase, first, castArray, findIndex } from 'lodash-es';
12
12
  import { readFile, mkdir, writeFile, unlink } from 'node:fs/promises';
13
13
  import { resolve, dirname, basename, parse } from 'node:path';
14
14
  import { homedir } from 'node:os';
@@ -22,19 +22,19 @@ import { lookup } from 'mime-types';
22
22
  import { createReadStream } from 'node:fs';
23
23
  import { Readable } from 'node:stream';
24
24
 
25
- function _ts_decorate$h(decorators, target, key, desc) {
25
+ function _ts_decorate$i(decorators, target, key, desc) {
26
26
  var c = arguments.length, r = c < 3 ? target : desc, d;
27
27
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
28
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
29
  return c > 3 && r && Object.defineProperty(target, key, r), r;
30
30
  }
31
- function _ts_metadata$b(k, v) {
31
+ function _ts_metadata$c(k, v) {
32
32
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
33
  }
34
34
  class ZRomulatorConfigUpdateDto {
35
35
  contents;
36
36
  }
37
- _ts_decorate$h([
37
+ _ts_decorate$i([
38
38
  ApiProperty({
39
39
  type: "object",
40
40
  properties: {}
@@ -46,7 +46,7 @@ _ts_decorate$h([
46
46
  message: "The contents of the config must be an object "
47
47
  }),
48
48
  IsNotEmptyObject(),
49
- _ts_metadata$b("design:type", typeof T === "undefined" ? Object : T)
49
+ _ts_metadata$c("design:type", typeof T === "undefined" ? Object : T)
50
50
  ], ZRomulatorConfigUpdateDto.prototype, "contents", void 0);
51
51
 
52
52
  class ZDir {
@@ -73,16 +73,16 @@ class ZRomulatorConfigKnown {
73
73
  }
74
74
  }
75
75
 
76
- function _ts_decorate$g(decorators, target, key, desc) {
76
+ function _ts_decorate$h(decorators, target, key, desc) {
77
77
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
78
78
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
79
79
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
80
80
  return c > 3 && r && Object.defineProperty(target, key, r), r;
81
81
  }
82
- function _ts_metadata$a(k, v) {
82
+ function _ts_metadata$b(k, v) {
83
83
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
84
84
  }
85
- function _ts_param$9(paramIndex, decorator) {
85
+ function _ts_param$a(paramIndex, decorator) {
86
86
  return function(target, key) {
87
87
  decorator(target, key, paramIndex);
88
88
  };
@@ -164,25 +164,25 @@ class ZRomulatorConfigsService {
164
164
  return config;
165
165
  }
166
166
  }
167
- ZRomulatorConfigsService = _ts_decorate$g([
167
+ ZRomulatorConfigsService = _ts_decorate$h([
168
168
  Injectable(),
169
- _ts_param$9(0, Inject(ZLoggerToken)),
170
- _ts_metadata$a("design:type", Function),
171
- _ts_metadata$a("design:paramtypes", [
169
+ _ts_param$a(0, Inject(ZLoggerToken)),
170
+ _ts_metadata$b("design:type", Function),
171
+ _ts_metadata$b("design:paramtypes", [
172
172
  typeof IZLogger === "undefined" ? Object : IZLogger
173
173
  ])
174
174
  ], ZRomulatorConfigsService);
175
175
 
176
- function _ts_decorate$f(decorators, target, key, desc) {
176
+ function _ts_decorate$g(decorators, target, key, desc) {
177
177
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
178
178
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
179
179
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
180
180
  return c > 3 && r && Object.defineProperty(target, key, r), r;
181
181
  }
182
- function _ts_metadata$9(k, v) {
182
+ function _ts_metadata$a(k, v) {
183
183
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
184
184
  }
185
- function _ts_param$8(paramIndex, decorator) {
185
+ function _ts_param$9(paramIndex, decorator) {
186
186
  return function(target, key) {
187
187
  decorator(target, key, paramIndex);
188
188
  };
@@ -203,16 +203,16 @@ class ZRomulatorConfigsController {
203
203
  return await this._configs.get(identification);
204
204
  }
205
205
  }
206
- _ts_decorate$f([
206
+ _ts_decorate$g([
207
207
  Get(),
208
- _ts_param$8(0, Query()),
209
- _ts_metadata$9("design:type", Function),
210
- _ts_metadata$9("design:paramtypes", [
208
+ _ts_param$9(0, Query()),
209
+ _ts_metadata$a("design:type", Function),
210
+ _ts_metadata$a("design:paramtypes", [
211
211
  typeof IZDataRequestQuery === "undefined" ? Object : IZDataRequestQuery
212
212
  ]),
213
- _ts_metadata$9("design:returntype", Promise)
213
+ _ts_metadata$a("design:returntype", Promise)
214
214
  ], ZRomulatorConfigsController.prototype, "list", null);
215
- _ts_decorate$f([
215
+ _ts_decorate$g([
216
216
  ApiParam({
217
217
  type: "string",
218
218
  name: "identification",
@@ -229,39 +229,39 @@ _ts_decorate$f([
229
229
  skipNullProperties: false,
230
230
  skipUndefinedProperties: false
231
231
  })),
232
- _ts_param$8(0, Param("identification")),
233
- _ts_param$8(1, Body()),
234
- _ts_metadata$9("design:type", Function),
235
- _ts_metadata$9("design:paramtypes", [
232
+ _ts_param$9(0, Param("identification")),
233
+ _ts_param$9(1, Body()),
234
+ _ts_metadata$a("design:type", Function),
235
+ _ts_metadata$a("design:paramtypes", [
236
236
  typeof ZRomulatorConfigId === "undefined" ? Object : ZRomulatorConfigId,
237
237
  typeof ZRomulatorConfigUpdateDto === "undefined" ? Object : ZRomulatorConfigUpdateDto
238
238
  ]),
239
- _ts_metadata$9("design:returntype", Promise)
239
+ _ts_metadata$a("design:returntype", Promise)
240
240
  ], ZRomulatorConfigsController.prototype, "update", null);
241
- _ts_decorate$f([
241
+ _ts_decorate$g([
242
242
  ApiParam({
243
243
  type: "string",
244
244
  name: "identification",
245
245
  description: "The id of the config"
246
246
  }),
247
247
  Get(":identification"),
248
- _ts_param$8(0, Param("identification")),
249
- _ts_metadata$9("design:type", Function),
250
- _ts_metadata$9("design:paramtypes", [
248
+ _ts_param$9(0, Param("identification")),
249
+ _ts_metadata$a("design:type", Function),
250
+ _ts_metadata$a("design:paramtypes", [
251
251
  typeof ZRomulatorConfigId === "undefined" ? Object : ZRomulatorConfigId
252
252
  ]),
253
- _ts_metadata$9("design:returntype", Promise)
253
+ _ts_metadata$a("design:returntype", Promise)
254
254
  ], ZRomulatorConfigsController.prototype, "get", null);
255
- ZRomulatorConfigsController = _ts_decorate$f([
255
+ ZRomulatorConfigsController = _ts_decorate$g([
256
256
  Controller("configs"),
257
- _ts_param$8(0, Inject(ZRomulatorConfigsToken)),
258
- _ts_metadata$9("design:type", Function),
259
- _ts_metadata$9("design:paramtypes", [
257
+ _ts_param$9(0, Inject(ZRomulatorConfigsToken)),
258
+ _ts_metadata$a("design:type", Function),
259
+ _ts_metadata$a("design:paramtypes", [
260
260
  typeof IZRomulatorConfigsService === "undefined" ? Object : IZRomulatorConfigsService
261
261
  ])
262
262
  ], ZRomulatorConfigsController);
263
263
 
264
- function _ts_decorate$e(decorators, target, key, desc) {
264
+ function _ts_decorate$f(decorators, target, key, desc) {
265
265
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
266
266
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
267
267
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -269,7 +269,7 @@ function _ts_decorate$e(decorators, target, key, desc) {
269
269
  }
270
270
  class ZRomulatorConfigsModule {
271
271
  }
272
- ZRomulatorConfigsModule = _ts_decorate$e([
272
+ ZRomulatorConfigsModule = _ts_decorate$f([
273
273
  Module({
274
274
  imports: [
275
275
  ZFileSystemModule,
@@ -290,13 +290,13 @@ ZRomulatorConfigsModule = _ts_decorate$e([
290
290
  })
291
291
  ], ZRomulatorConfigsModule);
292
292
 
293
- function _ts_decorate$d(decorators, target, key, desc) {
293
+ function _ts_decorate$e(decorators, target, key, desc) {
294
294
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
295
295
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
296
296
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
297
297
  return c > 3 && r && Object.defineProperty(target, key, r), r;
298
298
  }
299
- function _ts_metadata$8(k, v) {
299
+ function _ts_metadata$9(k, v) {
300
300
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
301
301
  }
302
302
  const KnownSystem = "@zthunworks/romulator/known-system";
@@ -392,59 +392,59 @@ const KnownSystem = "@zthunworks/romulator/known-system";
392
392
  return null;
393
393
  }
394
394
  }
395
- _ts_decorate$d([
395
+ _ts_decorate$e([
396
396
  ZTag(KnownSystem),
397
- _ts_metadata$8("design:type", Function),
398
- _ts_metadata$8("design:paramtypes", []),
399
- _ts_metadata$8("design:returntype", void 0)
397
+ _ts_metadata$9("design:type", Function),
398
+ _ts_metadata$9("design:paramtypes", []),
399
+ _ts_metadata$9("design:returntype", void 0)
400
400
  ], ZRomulatorSystemKnown, "nes", null);
401
- _ts_decorate$d([
401
+ _ts_decorate$e([
402
402
  ZTag(KnownSystem),
403
- _ts_metadata$8("design:type", Function),
404
- _ts_metadata$8("design:paramtypes", []),
405
- _ts_metadata$8("design:returntype", void 0)
403
+ _ts_metadata$9("design:type", Function),
404
+ _ts_metadata$9("design:paramtypes", []),
405
+ _ts_metadata$9("design:returntype", void 0)
406
406
  ], ZRomulatorSystemKnown, "snes", null);
407
- _ts_decorate$d([
407
+ _ts_decorate$e([
408
408
  ZTag(KnownSystem),
409
- _ts_metadata$8("design:type", Function),
410
- _ts_metadata$8("design:paramtypes", []),
411
- _ts_metadata$8("design:returntype", void 0)
409
+ _ts_metadata$9("design:type", Function),
410
+ _ts_metadata$9("design:paramtypes", []),
411
+ _ts_metadata$9("design:returntype", void 0)
412
412
  ], ZRomulatorSystemKnown, "n64", null);
413
- _ts_decorate$d([
413
+ _ts_decorate$e([
414
414
  ZTag(KnownSystem),
415
- _ts_metadata$8("design:type", Function),
416
- _ts_metadata$8("design:paramtypes", []),
417
- _ts_metadata$8("design:returntype", void 0)
415
+ _ts_metadata$9("design:type", Function),
416
+ _ts_metadata$9("design:paramtypes", []),
417
+ _ts_metadata$9("design:returntype", void 0)
418
418
  ], ZRomulatorSystemKnown, "gc", null);
419
- _ts_decorate$d([
419
+ _ts_decorate$e([
420
420
  ZTag(KnownSystem),
421
- _ts_metadata$8("design:type", Function),
422
- _ts_metadata$8("design:paramtypes", []),
423
- _ts_metadata$8("design:returntype", void 0)
421
+ _ts_metadata$9("design:type", Function),
422
+ _ts_metadata$9("design:paramtypes", []),
423
+ _ts_metadata$9("design:returntype", void 0)
424
424
  ], ZRomulatorSystemKnown, "wii", null);
425
- _ts_decorate$d([
425
+ _ts_decorate$e([
426
426
  ZTag(KnownSystem),
427
- _ts_metadata$8("design:type", Function),
428
- _ts_metadata$8("design:paramtypes", []),
429
- _ts_metadata$8("design:returntype", void 0)
427
+ _ts_metadata$9("design:type", Function),
428
+ _ts_metadata$9("design:paramtypes", []),
429
+ _ts_metadata$9("design:returntype", void 0)
430
430
  ], ZRomulatorSystemKnown, "wiiu", null);
431
- _ts_decorate$d([
431
+ _ts_decorate$e([
432
432
  ZTag(KnownSystem),
433
- _ts_metadata$8("design:type", Function),
434
- _ts_metadata$8("design:paramtypes", []),
435
- _ts_metadata$8("design:returntype", void 0)
433
+ _ts_metadata$9("design:type", Function),
434
+ _ts_metadata$9("design:paramtypes", []),
435
+ _ts_metadata$9("design:returntype", void 0)
436
436
  ], ZRomulatorSystemKnown, "switch", null);
437
437
 
438
- function _ts_decorate$c(decorators, target, key, desc) {
438
+ function _ts_decorate$d(decorators, target, key, desc) {
439
439
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
440
440
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
441
441
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
442
442
  return c > 3 && r && Object.defineProperty(target, key, r), r;
443
443
  }
444
- function _ts_metadata$7(k, v) {
444
+ function _ts_metadata$8(k, v) {
445
445
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
446
446
  }
447
- function _ts_param$7(paramIndex, decorator) {
447
+ function _ts_param$8(paramIndex, decorator) {
448
448
  return function(target, key) {
449
449
  decorator(target, key, paramIndex);
450
450
  };
@@ -514,29 +514,29 @@ class ZRomulatorGamesService {
514
514
  ].filter((s)=>s.length).some((k)=>k.toLowerCase().includes(needle));
515
515
  }
516
516
  }
517
- ZRomulatorGamesService = _ts_decorate$c([
517
+ ZRomulatorGamesService = _ts_decorate$d([
518
518
  Injectable(),
519
- _ts_param$7(0, Inject(ZFileSystemToken)),
520
- _ts_param$7(1, Inject(ZRomulatorConfigsToken)),
521
- _ts_param$7(2, Inject(ZLoggerToken)),
522
- _ts_metadata$7("design:type", Function),
523
- _ts_metadata$7("design:paramtypes", [
519
+ _ts_param$8(0, Inject(ZFileSystemToken)),
520
+ _ts_param$8(1, Inject(ZRomulatorConfigsToken)),
521
+ _ts_param$8(2, Inject(ZLoggerToken)),
522
+ _ts_metadata$8("design:type", Function),
523
+ _ts_metadata$8("design:paramtypes", [
524
524
  typeof IZFileSystemService === "undefined" ? Object : IZFileSystemService,
525
525
  typeof IZRomulatorConfigsService === "undefined" ? Object : IZRomulatorConfigsService,
526
526
  typeof IZLogger === "undefined" ? Object : IZLogger
527
527
  ])
528
528
  ], ZRomulatorGamesService);
529
529
 
530
- function _ts_decorate$b(decorators, target, key, desc) {
530
+ function _ts_decorate$c(decorators, target, key, desc) {
531
531
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
532
532
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
533
533
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
534
534
  return c > 3 && r && Object.defineProperty(target, key, r), r;
535
535
  }
536
- function _ts_metadata$6(k, v) {
536
+ function _ts_metadata$7(k, v) {
537
537
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
538
538
  }
539
- function _ts_param$6(paramIndex, decorator) {
539
+ function _ts_param$7(paramIndex, decorator) {
540
540
  return function(target, key) {
541
541
  decorator(target, key, paramIndex);
542
542
  };
@@ -553,34 +553,34 @@ class ZRomulatorGamesController {
553
553
  return this._games.get(identification);
554
554
  }
555
555
  }
556
- _ts_decorate$b([
556
+ _ts_decorate$c([
557
557
  Get(),
558
- _ts_param$6(0, Query()),
559
- _ts_metadata$6("design:type", Function),
560
- _ts_metadata$6("design:paramtypes", [
558
+ _ts_param$7(0, Query()),
559
+ _ts_metadata$7("design:type", Function),
560
+ _ts_metadata$7("design:paramtypes", [
561
561
  typeof IZDataRequestQuery === "undefined" ? Object : IZDataRequestQuery
562
562
  ]),
563
- _ts_metadata$6("design:returntype", typeof Promise === "undefined" ? Object : Promise)
563
+ _ts_metadata$7("design:returntype", typeof Promise === "undefined" ? Object : Promise)
564
564
  ], ZRomulatorGamesController.prototype, "list", null);
565
- _ts_decorate$b([
565
+ _ts_decorate$c([
566
566
  Get(":identification"),
567
- _ts_param$6(0, Param("identification")),
568
- _ts_metadata$6("design:type", Function),
569
- _ts_metadata$6("design:paramtypes", [
567
+ _ts_param$7(0, Param("identification")),
568
+ _ts_metadata$7("design:type", Function),
569
+ _ts_metadata$7("design:paramtypes", [
570
570
  String
571
571
  ]),
572
- _ts_metadata$6("design:returntype", void 0)
572
+ _ts_metadata$7("design:returntype", void 0)
573
573
  ], ZRomulatorGamesController.prototype, "get", null);
574
- ZRomulatorGamesController = _ts_decorate$b([
574
+ ZRomulatorGamesController = _ts_decorate$c([
575
575
  Controller("games"),
576
- _ts_param$6(0, Inject(ZRomulatorGamesToken)),
577
- _ts_metadata$6("design:type", Function),
578
- _ts_metadata$6("design:paramtypes", [
576
+ _ts_param$7(0, Inject(ZRomulatorGamesToken)),
577
+ _ts_metadata$7("design:type", Function),
578
+ _ts_metadata$7("design:paramtypes", [
579
579
  typeof IZRomulatorGamesService === "undefined" ? Object : IZRomulatorGamesService
580
580
  ])
581
581
  ], ZRomulatorGamesController);
582
582
 
583
- function _ts_decorate$a(decorators, target, key, desc) {
583
+ function _ts_decorate$b(decorators, target, key, desc) {
584
584
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
585
585
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
586
586
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -588,7 +588,7 @@ function _ts_decorate$a(decorators, target, key, desc) {
588
588
  }
589
589
  class ZRomulatorGamesModule {
590
590
  }
591
- ZRomulatorGamesModule = _ts_decorate$a([
591
+ ZRomulatorGamesModule = _ts_decorate$b([
592
592
  Module({
593
593
  imports: [
594
594
  ZRomulatorConfigsModule,
@@ -607,29 +607,28 @@ ZRomulatorGamesModule = _ts_decorate$a([
607
607
  })
608
608
  ], ZRomulatorGamesModule);
609
609
 
610
- function _ts_decorate$9(decorators, target, key, desc) {
610
+ function _ts_decorate$a(decorators, target, key, desc) {
611
611
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
612
612
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
613
613
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
614
614
  return c > 3 && r && Object.defineProperty(target, key, r), r;
615
615
  }
616
- function _ts_metadata$5(k, v) {
616
+ function _ts_metadata$6(k, v) {
617
617
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
618
618
  }
619
- function _ts_param$5(paramIndex, decorator) {
619
+ function _ts_param$6(paramIndex, decorator) {
620
620
  return function(target, key) {
621
621
  decorator(target, key, paramIndex);
622
622
  };
623
623
  }
624
624
  const ZRomulatorFilesToken = Symbol("files");
625
- class ZRomulatorFilesService {
625
+ class ZRomulatorFilesRepository {
626
626
  _configs;
627
627
  _fileSystem;
628
628
  static MediaFolderName = ".media";
629
629
  static InfoFolderName = ".info";
630
630
  _repository = new ZFileRepository();
631
631
  _folderStream = new ZStreamFolder();
632
- _fileStream = new ZStreamFile();
633
632
  _globs;
634
633
  _systems;
635
634
  constructor(_configs, _fileSystem){
@@ -652,33 +651,16 @@ class ZRomulatorFilesService {
652
651
  }
653
652
  async mediaFolder() {
654
653
  const gamesFolder = await this.gamesFolder();
655
- return resolve(gamesFolder, ZRomulatorFilesService.MediaFolderName);
654
+ return resolve(gamesFolder, ZRomulatorFilesRepository.MediaFolderName);
656
655
  }
657
656
  async infoFolder() {
658
657
  const gamesFolder = await this.gamesFolder();
659
- return resolve(gamesFolder, ZRomulatorFilesService.InfoFolderName);
660
- }
661
- async contents(roots, path) {
662
- const repository = await this.seed();
663
- const folders = castArray(roots).map((root)=>`${trimEnd(root, "/")}/`);
664
- const byPaths = folders.map((folder)=>{
665
- const byPath = new ZFilterBinaryBuilder().subject("path");
666
- const pathFilter = path == null ? byPath.startsWith().value(folder) : byPath.equal().value(resolve(folder, path));
667
- return pathFilter.build();
668
- });
669
- const filter = byPaths.length > 1 ? new ZFilterLogicBuilder().or().clauses(byPaths).build() : first(byPaths);
670
- const sort = new ZSortBuilder().ascending("path").build();
671
- const request = new ZDataRequestBuilder().filter(filter).sort(sort).build();
672
- const nodes = await repository.retrieve(request);
673
- return path == null ? nodes : firstDefined(null, first(nodes));
674
- }
675
- async init() {
676
- await this.seed();
658
+ return resolve(gamesFolder, ZRomulatorFilesRepository.InfoFolderName);
677
659
  }
678
660
  async dispose() {
679
661
  await this._repository.reset();
680
662
  }
681
- async seed() {
663
+ async init() {
682
664
  const path = await this.gamesFolder();
683
665
  if (this._repository.path !== path) {
684
666
  await this._folderStream.write(await this.mediaFolder());
@@ -687,10 +669,20 @@ class ZRomulatorFilesService {
687
669
  }
688
670
  return this._repository;
689
671
  }
690
- async media(path) {
691
- return this.contents(await this.mediaFolder(), path);
672
+ async media() {
673
+ const repository = await this.init();
674
+ const folder = `${await this.mediaFolder()}/`;
675
+ const request = new ZDataRequestBuilder().filter(new ZFilterBinaryBuilder().subject("path").startsWith().value(folder).build()).sort(new ZSortBuilder().ascending("path").build()).build();
676
+ return repository.retrieve(request);
692
677
  }
693
- async systems(path) {
678
+ async info(id) {
679
+ // The info json files are json files that contain arrays of games grouped by systems,
680
+ // or systems.json which describes system information.
681
+ const folder = await this.infoFolder();
682
+ const path = resolve(folder, `${id}.json`);
683
+ return this._repository.get(path);
684
+ }
685
+ async systems(id) {
694
686
  // Systems use directories. There's a maximum limit of about 200 systems.
695
687
  // Since we don't actually need to read any metadata or scan through thousands
696
688
  // of unknown folders, we can use the supported system ids to just grab the
@@ -698,34 +690,93 @@ class ZRomulatorFilesService {
698
690
  // grab the systems from the file system and it should be fast enough. These are all
699
691
  // folders, so we don't even need the stats for them and we can assume folders.
700
692
  const games = await this.gamesFolder();
701
- const folders = path == null ? this._systems.map((s)=>`${s}/`) : resolve(games, path);
693
+ const folders = id == null ? this._systems.map((s)=>`${s}/`) : resolve(games, id);
702
694
  const items = await this._fileSystem.search(folders, {
703
695
  cwd: games,
704
696
  stat: false
705
697
  });
706
- return path == null ? items : firstDefined(null, first(items));
698
+ return id == null ? items : firstDefined(null, first(items));
707
699
  }
708
- async info(path) {
709
- return this.contents(await this.infoFolder(), path);
700
+ }
701
+ ZRomulatorFilesRepository = _ts_decorate$a([
702
+ Injectable(),
703
+ _ts_param$6(0, Inject(ZRomulatorConfigsToken)),
704
+ _ts_param$6(1, Inject(ZFileSystemToken)),
705
+ _ts_metadata$6("design:type", Function),
706
+ _ts_metadata$6("design:paramtypes", [
707
+ typeof IZRomulatorConfigsService === "undefined" ? Object : IZRomulatorConfigsService,
708
+ typeof IZFileSystemService === "undefined" ? Object : IZFileSystemService
709
+ ])
710
+ ], ZRomulatorFilesRepository);
711
+
712
+ function _ts_decorate$9(decorators, target, key, desc) {
713
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
714
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
715
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
716
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
717
+ }
718
+ function _ts_metadata$5(k, v) {
719
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
720
+ }
721
+ function _ts_param$5(paramIndex, decorator) {
722
+ return function(target, key) {
723
+ decorator(target, key, paramIndex);
724
+ };
725
+ }
726
+ const ZRomulatorFilesSystemsJsonRepositoryToken = Symbol("files-systems-json-repository");
727
+ class ZRomulatorFilesSystemsJsonRepository {
728
+ _files;
729
+ _logger;
730
+ _stream = new ZStreamFile({
731
+ cache: {
732
+ maxFiles: 1,
733
+ fileSize: BigInt(mib(5))
734
+ }
735
+ });
736
+ /**
737
+ * Initializes a new instance of this object.
738
+ */ constructor(_files, logger){
739
+ this._files = _files;
740
+ this._logger = new ZLoggerContext("ZRomulatorSystemsRepository", logger);
710
741
  }
711
- async games(path) {
712
- const root = await this.gamesFolder();
713
- return this.contents(this._systems.map((s)=>resolve(root, s)), path);
742
+ async _read() {
743
+ const info = await this._files.info("systems");
744
+ if (info == null) {
745
+ return [];
746
+ }
747
+ try {
748
+ const contents = await this._stream.read(info.path);
749
+ const json = JSON.parse(contents.toString());
750
+ return castArray(json);
751
+ } catch (e) {
752
+ const err = createError(e);
753
+ const msg = `Unable to read ${info.path}: ${err.message}`;
754
+ this._logger.log(new ZLogEntryBuilder().error().message(msg).build());
755
+ return [];
756
+ }
714
757
  }
715
- read(node) {
716
- return this._fileStream.read(node.path);
758
+ async systems() {
759
+ const candidates = await this._read();
760
+ function hasId(candidate) {
761
+ return Object.prototype.hasOwnProperty.call(candidate, "id");
762
+ }
763
+ const entries = candidates.filter((c)=>hasId(c)).filter((c)=>isSystemId(c.id)).map((c)=>[
764
+ c.id,
765
+ c
766
+ ]);
767
+ return Promise.resolve(new Map(entries));
717
768
  }
718
769
  }
719
- ZRomulatorFilesService = _ts_decorate$9([
770
+ ZRomulatorFilesSystemsJsonRepository = _ts_decorate$9([
720
771
  Injectable(),
721
- _ts_param$5(0, Inject(ZRomulatorConfigsToken)),
722
- _ts_param$5(1, Inject(ZFileSystemToken)),
772
+ _ts_param$5(0, Inject(ZRomulatorFilesToken)),
773
+ _ts_param$5(1, Inject(ZLoggerToken)),
723
774
  _ts_metadata$5("design:type", Function),
724
775
  _ts_metadata$5("design:paramtypes", [
725
- typeof IZRomulatorConfigsService === "undefined" ? Object : IZRomulatorConfigsService,
726
- typeof IZFileSystemService === "undefined" ? Object : IZFileSystemService
776
+ typeof IZRomulatorFilesRepository === "undefined" ? Object : IZRomulatorFilesRepository,
777
+ typeof IZLogger === "undefined" ? Object : IZLogger
727
778
  ])
728
- ], ZRomulatorFilesService);
779
+ ], ZRomulatorFilesSystemsJsonRepository);
729
780
 
730
781
  function _ts_decorate$8(decorators, target, key, desc) {
731
782
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -757,22 +808,28 @@ ZRomulatorFilesModule = _ts_decorate$8([
757
808
  Module({
758
809
  imports: [
759
810
  ZFileSystemModule,
760
- ZRomulatorConfigsModule
811
+ ZRomulatorConfigsModule,
812
+ ZLoggerModule
761
813
  ],
762
814
  providers: [
763
815
  {
764
816
  provide: ZRomulatorFilesToken,
765
- useClass: ZRomulatorFilesService
817
+ useClass: ZRomulatorFilesRepository
818
+ },
819
+ {
820
+ provide: ZRomulatorFilesSystemsJsonRepositoryToken,
821
+ useClass: ZRomulatorFilesSystemsJsonRepository
766
822
  }
767
823
  ],
768
824
  exports: [
769
- ZRomulatorFilesToken
825
+ ZRomulatorFilesToken,
826
+ ZRomulatorFilesSystemsJsonRepositoryToken
770
827
  ]
771
828
  }),
772
829
  _ts_param$4(0, Inject(ZRomulatorFilesToken)),
773
830
  _ts_metadata$4("design:type", Function),
774
831
  _ts_metadata$4("design:paramtypes", [
775
- typeof IZRomulatorFilesService === "undefined" ? Object : IZRomulatorFilesService
832
+ typeof IZRomulatorFilesRepository === "undefined" ? Object : IZRomulatorFilesRepository
776
833
  ])
777
834
  ], ZRomulatorFilesModule);
778
835
 
@@ -949,7 +1006,7 @@ ZRomulatorMediaService = _ts_decorate$6([
949
1006
  _ts_metadata$3("design:type", Function),
950
1007
  _ts_metadata$3("design:paramtypes", [
951
1008
  typeof IZRomulatorMediaGenerator === "undefined" ? Object : IZRomulatorMediaGenerator,
952
- typeof IZRomulatorFilesService === "undefined" ? Object : IZRomulatorFilesService,
1009
+ typeof IZRomulatorFilesRepository === "undefined" ? Object : IZRomulatorFilesRepository,
953
1010
  typeof IZLogger === "undefined" ? Object : IZLogger
954
1011
  ])
955
1012
  ], ZRomulatorMediaService);
@@ -1136,11 +1193,13 @@ function _ts_param$1(paramIndex, decorator) {
1136
1193
  }
1137
1194
  const ZRomulatorSystemsToken = Symbol("romulator-systems-service");
1138
1195
  class ZRomulatorSystemsService {
1139
- _files;
1196
+ _filesRepository;
1197
+ _systemsRepository;
1140
1198
  logger;
1141
1199
  _logger;
1142
- constructor(_files, logger){
1143
- this._files = _files;
1200
+ constructor(_filesRepository, _systemsRepository, logger){
1201
+ this._filesRepository = _filesRepository;
1202
+ this._systemsRepository = _systemsRepository;
1144
1203
  this.logger = logger;
1145
1204
  this._logger = new ZLoggerContext("ZRomulatorSystemsService", logger);
1146
1205
  }
@@ -1149,8 +1208,9 @@ class ZRomulatorSystemsService {
1149
1208
  const size = firstDefined(Infinity, req.size);
1150
1209
  let msg = `Retrieving systems page, ${page}, with size, ${size}.`;
1151
1210
  this._logger.log(new ZLogEntryBuilder().info().message(msg).build());
1152
- const folders = await this._files.systems();
1153
- const systems = await Promise.all(folders.map((folder)=>folder.path).map((path)=>basename(path)).filter((slug)=>isSystemId(slug)).map((slug)=>this._createSystemFromSlug(slug)));
1211
+ const folders = await this._filesRepository.systems();
1212
+ const lookup = await this._systemsRepository.systems();
1213
+ const systems = await Promise.all(folders.map((folder)=>folder.path).map((path)=>basename(path)).filter((slug)=>isSystemId(slug)).map((slug)=>new ZRomulatorSystemBuilder().id(slug).parse(lookup.get(slug)).build()));
1154
1214
  msg = `Found ${systems.length} systems`;
1155
1215
  this._logger.log(new ZLogEntryBuilder().info().message(msg).build());
1156
1216
  const sourceOptions = new ZDataSourceStaticOptionsBuilder().search(new ZDataSearchFields([
@@ -1169,41 +1229,25 @@ class ZRomulatorSystemsService {
1169
1229
  const message = `The specified system slug, ${id}, is not supported.`;
1170
1230
  throw new NotFoundException(message);
1171
1231
  }
1172
- const node = await this._files.systems(id);
1173
- if (node == null) {
1232
+ const system = await this._filesRepository.systems(id);
1233
+ if (system == null) {
1174
1234
  const message = `System with slug, ${id}, was not found.`;
1175
1235
  throw new NotFoundException(message);
1176
1236
  }
1177
- return this._createSystemFromSlug(id);
1178
- }
1179
- async _createSystemFromSlug(slug) {
1180
- const system = new ZRomulatorSystemBuilder().id(slug);
1181
- const path = `${slug}/info.json`;
1182
- const info = await this._files.info(path);
1183
- if (info == null) {
1184
- // Best we can do right now.
1185
- return system.build();
1186
- }
1187
- try {
1188
- const contents = await this._files.read(info);
1189
- const json = JSON.parse(contents.toString());
1190
- return system.assign(json).redact().build();
1191
- } catch (e) {
1192
- // Best we can do
1193
- const err = createError(e);
1194
- const msg = `Cannot read system metadata, ${err.message}`;
1195
- this._logger.log(new ZLogEntryBuilder().error().message(msg).build());
1196
- return system.build();
1197
- }
1237
+ const lookup = await this._systemsRepository.systems();
1238
+ const info = lookup.get(id);
1239
+ return new ZRomulatorSystemBuilder().id(id).parse(info).build();
1198
1240
  }
1199
1241
  }
1200
1242
  ZRomulatorSystemsService = _ts_decorate$3([
1201
1243
  Injectable(),
1202
1244
  _ts_param$1(0, Inject(ZRomulatorFilesToken)),
1203
- _ts_param$1(1, Inject(ZLoggerToken)),
1245
+ _ts_param$1(1, Inject(ZRomulatorFilesSystemsJsonRepositoryToken)),
1246
+ _ts_param$1(2, Inject(ZLoggerToken)),
1204
1247
  _ts_metadata$1("design:type", Function),
1205
1248
  _ts_metadata$1("design:paramtypes", [
1206
- typeof IZRomulatorFilesService === "undefined" ? Object : IZRomulatorFilesService,
1249
+ typeof IZRomulatorFilesRepository === "undefined" ? Object : IZRomulatorFilesRepository,
1250
+ typeof IZRomulatorFilesSystemsJsonRepository === "undefined" ? Object : IZRomulatorFilesSystemsJsonRepository,
1207
1251
  typeof IZLogger === "undefined" ? Object : IZLogger
1208
1252
  ])
1209
1253
  ], ZRomulatorSystemsService);
@@ -1288,6 +1332,9 @@ ZRomulatorSystemsModule = _ts_decorate$1([
1288
1332
  provide: ZRomulatorSystemsToken,
1289
1333
  useClass: ZRomulatorSystemsService
1290
1334
  }
1335
+ ],
1336
+ exports: [
1337
+ ZRomulatorSystemsToken
1291
1338
  ]
1292
1339
  })
1293
1340
  ], ZRomulatorSystemsModule);