@static-suite/static-suite-data-server 0.0.21 → 0.0.22

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
@@ -15,6 +15,7 @@ Data Server supports static JSON includes (`entityInclude`, `configInclude`, `lo
15
15
  - `dumpDir` / `--dump-dir`: path to the directory where data from Static Suite is dumped after being processed by Data Server. Optional.
16
16
  - `queryDir` / `--query-dir`: path to the directory where queries are stored. Optional.
17
17
  - `hookDir` / `--hook-dir`: path to the directory where hooks are stored. Optional.
18
+ - `taskDir` / `--task-dir`: path to the directory where tasks are stored. Optional.
18
19
  - `logLevel` / `--log-level`: log level verbosity: `error`, `warn`, `info` or `debug`. Optional. Defaults to `info`.
19
20
  - `logFile` / `--log-file`: path to the log file. Data server logs its errors to the stdOut, but they can also be saved into a log file. Optional.
20
21
  - `logFileLevel` / `--log-file-level`: log level verbosity for the log file: `error`, `warn`, `info` or `debug`. Optional. Defaults to the value of `logLevel` / `--log-level`
@@ -344,7 +345,7 @@ Received parameters:
344
345
 
345
346
  - `config`: object with configuration options defined at Data Server start: `dataDir`, `workDir`, `queryDir`, etc
346
347
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
347
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
348
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
348
349
 
349
350
  #### `onStoreLoadStart({ store, logger, dependencyTagger }): void`
350
351
 
@@ -353,7 +354,7 @@ Called before the store starts loading for the first time.
353
354
  Received parameters:
354
355
 
355
356
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
356
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
357
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
357
358
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
358
359
 
359
360
  #### `onProcessFile({ store, logger, dependencyTagger, relativeFilepath, fileContent }): fileContent`
@@ -363,7 +364,7 @@ Called after a file is read from disk, before adding it to the store. It is aime
363
364
  Received parameters:
364
365
 
365
366
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
366
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
367
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
367
368
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
368
369
  - `relativeFilepath`: relative file path inside the data dir.
369
370
  - `fileContent`: file contents, an object with "raw" and "json" members.
@@ -379,7 +380,7 @@ Called after a file is added into the store for the first time.
379
380
  Received parameters:
380
381
 
381
382
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
382
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
383
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
383
384
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
384
385
  - `relativeFilepath`: relative file path inside the data dir.
385
386
  - `storeItem`: contents of the store item.
@@ -391,7 +392,7 @@ Called after the store finishes loading for the first time.
391
392
  Received parameters:
392
393
 
393
394
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
394
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
395
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
395
396
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
396
397
 
397
398
  #### `onStoreChangeStart({ store, logger, dependencyTagger, changedFiles }): void`
@@ -401,7 +402,7 @@ Called before the store starts updating.
401
402
  Received parameters:
402
403
 
403
404
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
404
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
405
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
405
406
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
406
407
  - `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
407
408
  - `fromUniqueId`: a unique id representing the date from which those changes are obtained.
@@ -417,7 +418,7 @@ Called before a file is updated in the store.
417
418
  Received parameters:
418
419
 
419
420
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
420
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
421
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
421
422
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
422
423
  - `relativeFilepath`: relative file path inside the data dir.
423
424
  - `storeItem`: contents of the store item.
@@ -429,7 +430,7 @@ Called after a file is updated in the store.
429
430
  Received parameters:
430
431
 
431
432
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
432
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
433
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
433
434
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
434
435
  - `relativeFilepath`: relative file path inside the data dir.
435
436
  - `storeItem`: contents of the store item.
@@ -442,7 +443,7 @@ Called after a file is deleted from the store.
442
443
  Received parameters:
443
444
 
444
445
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
445
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
446
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
446
447
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
447
448
  - `relativeFilepath`: relative file path inside the data dir.
448
449
  - `storeItem`: contents of the store item.
@@ -454,7 +455,7 @@ Called after the store ends updating.
454
455
  Received parameters:
455
456
 
456
457
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
457
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
458
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
458
459
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
459
460
  - `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
460
461
  - `fromUniqueId`: a unique id representing the date from which those changes are obtained.
@@ -591,6 +592,67 @@ const listContentsByTermId = ({ store, args }) => {
591
592
  module.exports.default = listContentsByTermId;
592
593
  ```
593
594
 
595
+ ## Tasks
596
+
597
+ Data Server allows the execution of custom tasks. Just like [queries](#queries) and [hooks](#hooks), tasks are stored in a file inside a directory defined by the `taskDir` / `--task-dir` option.
598
+
599
+ Each task is a file named `${queryId}.task.js`, and it must export a default function that receives an object as an argument, containing two keys (`store` and `args`):
600
+
601
+ - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
602
+
603
+ - `args`: object with arguments used by that task.
604
+
605
+ > PLEASE NOTE: since `store` is a shared object, you MUST NOT alter it from your tasks.
606
+
607
+ Tasks must return an object with the following keys:
608
+
609
+ - `result`: the list of returned results. It must be an structure representable as JSON (an object, array, string, etc)
610
+ - `contentType`: optional content-type for the `result` field. Defaults to `application/json`.
611
+ - `httpStatus`: optional HTTP status for the data available in "result". Defaults to 200.
612
+
613
+ Example: get customized content data
614
+
615
+ ```javascript
616
+ const getComponentChunkName = page => {
617
+ const bundle = page.data.content.bundle.replace(/_/g, '-');
618
+ return `component---src-views-${bundle}-${bundle}-jsx`;
619
+ };
620
+
621
+ const getPageDataObject = page => ({
622
+ componentChunkName: getComponentChunkName(page),
623
+ path: page.data.content.url.path,
624
+ result: {
625
+ pageContext: {
626
+ node: page,
627
+ },
628
+ },
629
+ staticQueryHashes: [],
630
+ });
631
+
632
+ const getPageData = ({ store, args }) => {
633
+ let pageData;
634
+ const pathFromArgs = args.path?.trim();
635
+ if (pathFromArgs) {
636
+ const path = pathFromArgs.trim().replace(/^\/+|\/+$/g, '');
637
+ const storeKey = path === 'index' ? '/' : `/${path}`;
638
+ const storeFile = store.index.url.get(storeKey);
639
+ if (storeFile !== undefined) {
640
+ pageData = getPageDataObject(storeFile);
641
+ }
642
+ }
643
+
644
+ const res = {
645
+ httpStatus: pageData ? 200 : 404,
646
+ result: pageData || 'not found',
647
+ contentType: pageData ? 'application/json' : 'text/plain',
648
+ };
649
+
650
+ return res;
651
+ };
652
+
653
+ module.exports.default = getPageData;
654
+ ```
655
+
594
656
  ## Dumps
595
657
 
596
658
  Data Server is able to detect when a file is being used (included) by other file. When a file changes, Data Server provides a list of all files affected by that change. This list can therefore be used to generate incremental builds of your site, building only the HTML pages for those changed files.
@@ -801,6 +863,7 @@ It watches for changes in the post processor and query files:
801
863
 
802
864
  - When a file inside the `queryDir` / `--query-dir` changes, all files inside that directory are reloaded to ensure any module or sub module is properly refreshed
803
865
  - When a file inside the `hookDir` / `--hook-dir` changes, all files inside that directory are reloaded, and the store is reloaded and passed again through all hooks, so any changes in them are applied to all data files.
866
+ - When a file inside the `taskDir` / `--task-dir` changes, all files inside that directory are reloaded.
804
867
 
805
868
  This is the intended mode when developing queries (executing it by directly requesting the HTTP endpoint to execute a query). This mode is not required for the develop phase of a SSG, since the SSG will get the data from the Data Server only once.
806
869
 
package/dist/bin/serve.js CHANGED
@@ -77,11 +77,6 @@ const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
77
77
  describe: 'Show help',
78
78
  type: 'boolean',
79
79
  },
80
- })
81
- .completion('completion', (_current, _argv, done) => {
82
- setTimeout(() => {
83
- done(['query-dir', 'data-dir']);
84
- }, 500);
85
80
  })
86
81
  .config(config)
87
82
  .parseSync();
@@ -15,6 +15,7 @@ Data Server supports static JSON includes (`entityInclude`, `configInclude`, `lo
15
15
  - `dumpDir` / `--dump-dir`: path to the directory where data from Static Suite is dumped after being processed by Data Server. Optional.
16
16
  - `queryDir` / `--query-dir`: path to the directory where queries are stored. Optional.
17
17
  - `hookDir` / `--hook-dir`: path to the directory where hooks are stored. Optional.
18
+ - `taskDir` / `--task-dir`: path to the directory where tasks are stored. Optional.
18
19
  - `logLevel` / `--log-level`: log level verbosity: `error`, `warn`, `info` or `debug`. Optional. Defaults to `info`.
19
20
  - `logFile` / `--log-file`: path to the log file. Data server logs its errors to the stdOut, but they can also be saved into a log file. Optional.
20
21
  - `logFileLevel` / `--log-file-level`: log level verbosity for the log file: `error`, `warn`, `info` or `debug`. Optional. Defaults to the value of `logLevel` / `--log-level`
@@ -344,7 +345,7 @@ Received parameters:
344
345
 
345
346
  - `config`: object with configuration options defined at Data Server start: `dataDir`, `workDir`, `queryDir`, etc
346
347
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
347
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
348
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
348
349
 
349
350
  #### `onStoreLoadStart({ store, logger, dependencyTagger }): void`
350
351
 
@@ -353,7 +354,7 @@ Called before the store starts loading for the first time.
353
354
  Received parameters:
354
355
 
355
356
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
356
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
357
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
357
358
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
358
359
 
359
360
  #### `onProcessFile({ store, logger, dependencyTagger, relativeFilepath, fileContent }): fileContent`
@@ -363,7 +364,7 @@ Called after a file is read from disk, before adding it to the store. It is aime
363
364
  Received parameters:
364
365
 
365
366
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
366
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
367
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
367
368
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
368
369
  - `relativeFilepath`: relative file path inside the data dir.
369
370
  - `fileContent`: file contents, an object with "raw" and "json" members.
@@ -379,7 +380,7 @@ Called after a file is added into the store for the first time.
379
380
  Received parameters:
380
381
 
381
382
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
382
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
383
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
383
384
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
384
385
  - `relativeFilepath`: relative file path inside the data dir.
385
386
  - `storeItem`: contents of the store item.
@@ -391,7 +392,7 @@ Called after the store finishes loading for the first time.
391
392
  Received parameters:
392
393
 
393
394
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
394
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
395
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
395
396
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
396
397
 
397
398
  #### `onStoreChangeStart({ store, logger, dependencyTagger, changedFiles }): void`
@@ -401,7 +402,7 @@ Called before the store starts updating.
401
402
  Received parameters:
402
403
 
403
404
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
404
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
405
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
405
406
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
406
407
  - `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
407
408
  - `fromUniqueId`: a unique id representing the date from which those changes are obtained.
@@ -417,7 +418,7 @@ Called before a file is updated in the store.
417
418
  Received parameters:
418
419
 
419
420
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
420
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
421
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
421
422
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
422
423
  - `relativeFilepath`: relative file path inside the data dir.
423
424
  - `storeItem`: contents of the store item.
@@ -429,7 +430,7 @@ Called after a file is updated in the store.
429
430
  Received parameters:
430
431
 
431
432
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
432
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
433
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
433
434
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
434
435
  - `relativeFilepath`: relative file path inside the data dir.
435
436
  - `storeItem`: contents of the store item.
@@ -442,7 +443,7 @@ Called after a file is deleted from the store.
442
443
  Received parameters:
443
444
 
444
445
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
445
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
446
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
446
447
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
447
448
  - `relativeFilepath`: relative file path inside the data dir.
448
449
  - `storeItem`: contents of the store item.
@@ -454,7 +455,7 @@ Called after the store ends updating.
454
455
  Received parameters:
455
456
 
456
457
  - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
457
- - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
458
+ - `logger`: the logger service with several functions to log messages: `error()`, `warn()`, `info()`, `error()`
458
459
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
459
460
  - `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
460
461
  - `fromUniqueId`: a unique id representing the date from which those changes are obtained.
@@ -591,6 +592,67 @@ const listContentsByTermId = ({ store, args }) => {
591
592
  module.exports.default = listContentsByTermId;
592
593
  ```
593
594
 
595
+ ## Tasks
596
+
597
+ Data Server allows the execution of custom tasks. Just like [queries](#queries) and [hooks](#hooks), tasks are stored in a file inside a directory defined by the `taskDir` / `--task-dir` option.
598
+
599
+ Each task is a file named `${queryId}.task.js`, and it must export a default function that receives an object as an argument, containing two keys (`store` and `args`):
600
+
601
+ - `store`: the object that holds all data. See [store internal structure](#store-internal-structure).
602
+
603
+ - `args`: object with arguments used by that task.
604
+
605
+ > PLEASE NOTE: since `store` is a shared object, you MUST NOT alter it from your tasks.
606
+
607
+ Tasks must return an object with the following keys:
608
+
609
+ - `result`: the list of returned results. It must be an structure representable as JSON (an object, array, string, etc)
610
+ - `contentType`: optional content-type for the `result` field. Defaults to `application/json`.
611
+ - `httpStatus`: optional HTTP status for the data available in "result". Defaults to 200.
612
+
613
+ Example: get customized content data
614
+
615
+ ```javascript
616
+ const getComponentChunkName = page => {
617
+ const bundle = page.data.content.bundle.replace(/_/g, '-');
618
+ return `component---src-views-${bundle}-${bundle}-jsx`;
619
+ };
620
+
621
+ const getPageDataObject = page => ({
622
+ componentChunkName: getComponentChunkName(page),
623
+ path: page.data.content.url.path,
624
+ result: {
625
+ pageContext: {
626
+ node: page,
627
+ },
628
+ },
629
+ staticQueryHashes: [],
630
+ });
631
+
632
+ const getPageData = ({ store, args }) => {
633
+ let pageData;
634
+ const pathFromArgs = args.path?.trim();
635
+ if (pathFromArgs) {
636
+ const path = pathFromArgs.trim().replace(/^\/+|\/+$/g, '');
637
+ const storeKey = path === 'index' ? '/' : `/${path}`;
638
+ const storeFile = store.index.url.get(storeKey);
639
+ if (storeFile !== undefined) {
640
+ pageData = getPageDataObject(storeFile);
641
+ }
642
+ }
643
+
644
+ const res = {
645
+ httpStatus: pageData ? 200 : 404,
646
+ result: pageData || 'not found',
647
+ contentType: pageData ? 'application/json' : 'text/plain',
648
+ };
649
+
650
+ return res;
651
+ };
652
+
653
+ module.exports.default = getPageData;
654
+ ```
655
+
594
656
  ## Dumps
595
657
 
596
658
  Data Server is able to detect when a file is being used (included) by other file. When a file changes, Data Server provides a list of all files affected by that change. This list can therefore be used to generate incremental builds of your site, building only the HTML pages for those changed files.
@@ -801,6 +863,7 @@ It watches for changes in the post processor and query files:
801
863
 
802
864
  - When a file inside the `queryDir` / `--query-dir` changes, all files inside that directory are reloaded to ensure any module or sub module is properly refreshed
803
865
  - When a file inside the `hookDir` / `--hook-dir` changes, all files inside that directory are reloaded, and the store is reloaded and passed again through all hooks, so any changes in them are applied to all data files.
866
+ - When a file inside the `taskDir` / `--task-dir` changes, all files inside that directory are reloaded.
804
867
 
805
868
  This is the intended mode when developing queries (executing it by directly requesting the HTTP endpoint to execute a query). This mode is not required for the develop phase of a SSG, since the SSG will get the data from the Data Server only once.
806
869
 
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/http/routes/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C,QAAA,MAAM,UAAU,QAAS,OAAO,OAAO,QAAQ,KAAG,IAMjD,CAAC;AAEF,QAAA,MAAM,QAAQ,QAAS,OAAO,OAAO,QAAQ,KAAG,IAQ/C,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/http/routes/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C,QAAA,MAAM,UAAU,QAAS,OAAO,OAAO,QAAQ,KAAG,IAMjD,CAAC;AAEF,QAAA,MAAM,QAAQ,QAAS,OAAO,OAAO,QAAQ,KAAG,IAa/C,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}
@@ -15,7 +15,11 @@ const runQuery = (req, res) => {
15
15
  const queryDefinition = req.originalUrl.replace(/^\/query\//, '');
16
16
  const response = query_1.queryRunner.run(queryDefinition);
17
17
  res.status(200);
18
- res.set('application/json');
18
+ res.set({
19
+ 'Content-Type': 'metadata' in response
20
+ ? response.metadata.contentType
21
+ : 'application/json',
22
+ });
19
23
  res.send(response);
20
24
  };
21
25
  exports.runQuery = runQuery;
@@ -1 +1 @@
1
- {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../../src/http/routes/task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C,QAAA,MAAM,SAAS,QAAS,OAAO,OAAO,QAAQ,KAAG,IAKhD,CAAC;AAEF,QAAA,MAAM,OAAO,QAAS,OAAO,OAAO,QAAQ,KAAG,IAW9C,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../../src/http/routes/task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C,QAAA,MAAM,SAAS,QAAS,OAAO,OAAO,QAAQ,KAAG,IAKhD,CAAC;AAEF,QAAA,MAAM,OAAO,QAAS,OAAO,OAAO,QAAQ,KAAG,IAoB9C,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC"}
@@ -15,8 +15,14 @@ const runTask = (req, res) => {
15
15
  const args = req.query;
16
16
  const taskId = req.params[0];
17
17
  const response = task_1.taskRunner.run(taskId, args);
18
- res.status(200);
19
- res.set('application/json');
20
- res.send(response);
18
+ res.status('metadata' in response && response.metadata.httpStatus
19
+ ? response.metadata.httpStatus
20
+ : 200);
21
+ res.set({
22
+ 'Content-Type': 'metadata' in response
23
+ ? response.metadata.contentType
24
+ : 'application/json',
25
+ });
26
+ res.send('data' in response ? response.data : response);
21
27
  };
22
28
  exports.runTask = runTask;
@@ -63,6 +63,12 @@ export type TaskModuleResult = {
63
63
  * @defaultValue 'application/json'
64
64
  */
65
65
  contentType?: string;
66
+ /**
67
+ * Optional HTTP status type for the data available in "result"
68
+ *
69
+ * @defaultValue 200
70
+ */
71
+ httpStatus?: number;
66
72
  };
67
73
  /**
68
74
  * A successful response returned after executing a task.
@@ -95,6 +101,12 @@ export type TaskSuccessfulResponse = {
95
101
  * Execution time taken by the task, in milliseconds.
96
102
  */
97
103
  execTimeMs: number;
104
+ /**
105
+ * Optional HTTP status type for the data available in "data"
106
+ *
107
+ * @defaultValue 200
108
+ */
109
+ httpStatus?: number;
98
110
  };
99
111
  };
100
112
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"task.types.d.ts","sourceRoot":"","sources":["../../../src/lib/task/task.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,GAAG,CACD,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,GACb,sBAAsB,GAAG,iBAAiB,CAAC;CAC/C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,MAAM,EAAE,GAAG,CAAC;IAEZ;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IAEV;;OAEG;IACH,QAAQ,EAAE;QACR;;;;;;;WAOG;QACH,WAAW,EAAE,MAAM,CAAC;QAEpB;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,gBAAgB,CAAC;CACtE,CAAC;AACF;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,iBAChB,sBAAsB,GAAG,iBAAiB,sCAED,CAAC"}
1
+ {"version":3,"file":"task.types.d.ts","sourceRoot":"","sources":["../../../src/lib/task/task.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,GAAG,CACD,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,GACb,sBAAsB,GAAG,iBAAiB,CAAC;CAC/C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,MAAM,EAAE,GAAG,CAAC;IAEZ;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IAEV;;OAEG;IACH,QAAQ,EAAE;QACR;;;;;;;WAOG;QACH,WAAW,EAAE,MAAM,CAAC;QAEpB;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;QAEnB;;;;WAIG;QACH,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,gBAAgB,CAAC;CACtE,CAAC;AACF;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,iBAChB,sBAAsB,GAAG,iBAAiB,sCAED,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"taskRunner.d.ts","sourceRoot":"","sources":["../../../src/lib/task/taskRunner.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EAIX,MAAM,cAAc,CAAC;AAkBtB,eAAO,MAAM,UAAU,EAAE,UAkDxB,CAAC"}
1
+ {"version":3,"file":"taskRunner.d.ts","sourceRoot":"","sources":["../../../src/lib/task/taskRunner.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EAIX,MAAM,cAAc,CAAC;AAkBtB,eAAO,MAAM,UAAU,EAAE,UAoDxB,CAAC"}
@@ -42,6 +42,7 @@ exports.taskRunner = {
42
42
  const taskResult = {
43
43
  result: undefined,
44
44
  contentType: undefined,
45
+ httpStatus: undefined,
45
46
  };
46
47
  try {
47
48
  const taskModule = taskModuleInfo.getModule();
@@ -51,6 +52,7 @@ exports.taskRunner = {
51
52
  });
52
53
  taskResult.result = taskResponse?.result;
53
54
  taskResult.contentType = taskResponse?.contentType || 'application/json';
55
+ taskResult.httpStatus = taskResponse?.httpStatus || 200;
54
56
  }
55
57
  catch (e) {
56
58
  // Log error and rethrow.
@@ -63,6 +65,7 @@ exports.taskRunner = {
63
65
  metadata: {
64
66
  contentType: taskResult.contentType || 'application/json',
65
67
  execTimeMs,
68
+ httpStatus: taskResult.httpStatus || 200,
66
69
  },
67
70
  };
68
71
  logger_1.logger.debug(`#${count} Task "${taskId}" took ${execTimeMs} ms.`);
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.47.9"
8
+ "packageVersion": "7.52.11"
9
9
  }
10
10
  ]
11
11
  }
@@ -540,6 +540,12 @@ declare type TaskSuccessfulResponse = {
540
540
  * Execution time taken by the task, in milliseconds.
541
541
  */
542
542
  execTimeMs: number;
543
+ /**
544
+ * Optional HTTP status type for the data available in "data"
545
+ *
546
+ * @defaultValue 200
547
+ */
548
+ httpStatus?: number;
543
549
  };
544
550
  };
545
551
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-suite/static-suite-data-server",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "A flexible, fast and developer friendly Data Server for Static Suite",
5
5
  "main": "./dist/lib/index.js",
6
6
  "typings": "./dist/lib/index.d.ts",
@@ -85,4 +85,4 @@
85
85
  "src/__tests__/mocks/*"
86
86
  ]
87
87
  }
88
- }
88
+ }
package/src/bin/serve.ts CHANGED
@@ -79,11 +79,6 @@ const argv = yargs(hideBin(process.argv))
79
79
  type: 'boolean',
80
80
  },
81
81
  })
82
- .completion('completion', (_current, _argv, done) => {
83
- setTimeout(() => {
84
- done(['query-dir', 'data-dir']);
85
- }, 500);
86
- })
87
82
  .config(config)
88
83
  .parseSync();
89
84
 
@@ -20,7 +20,12 @@ const runQuery = (req: Request, res: Response): void => {
20
20
  const response: QuerySuccessfulResponse | QueryErrorResponse =
21
21
  queryRunner.run(queryDefinition);
22
22
  res.status(200);
23
- res.set('application/json');
23
+ res.set({
24
+ 'Content-Type':
25
+ 'metadata' in response
26
+ ? response.metadata.contentType
27
+ : 'application/json',
28
+ });
24
29
  res.send(response);
25
30
  };
26
31
 
@@ -21,9 +21,18 @@ const runTask = (req: Request, res: Response): void => {
21
21
  taskId,
22
22
  args,
23
23
  );
24
- res.status(200);
25
- res.set('application/json');
26
- res.send(response);
24
+ res.status(
25
+ 'metadata' in response && response.metadata.httpStatus
26
+ ? response.metadata.httpStatus
27
+ : 200,
28
+ );
29
+ res.set({
30
+ 'Content-Type':
31
+ 'metadata' in response
32
+ ? response.metadata.contentType
33
+ : 'application/json',
34
+ });
35
+ res.send('data' in response ? response.data : response);
27
36
  };
28
37
 
29
38
  export { taskIndex, runTask };
@@ -70,6 +70,13 @@ export type TaskModuleResult = {
70
70
  * @defaultValue 'application/json'
71
71
  */
72
72
  contentType?: string;
73
+
74
+ /**
75
+ * Optional HTTP status type for the data available in "result"
76
+ *
77
+ * @defaultValue 200
78
+ */
79
+ httpStatus?: number;
73
80
  };
74
81
 
75
82
  /**
@@ -105,6 +112,13 @@ export type TaskSuccessfulResponse = {
105
112
  * Execution time taken by the task, in milliseconds.
106
113
  */
107
114
  execTimeMs: number;
115
+
116
+ /**
117
+ * Optional HTTP status type for the data available in "data"
118
+ *
119
+ * @defaultValue 200
120
+ */
121
+ httpStatus?: number;
108
122
  };
109
123
  };
110
124
 
@@ -46,6 +46,7 @@ export const taskRunner: TaskRunner = {
46
46
  const taskResult: TaskModuleResult = {
47
47
  result: undefined,
48
48
  contentType: undefined,
49
+ httpStatus: undefined,
49
50
  };
50
51
  try {
51
52
  const taskModule = taskModuleInfo.getModule();
@@ -54,8 +55,8 @@ export const taskRunner: TaskRunner = {
54
55
  args,
55
56
  });
56
57
  taskResult.result = taskResponse?.result;
57
-
58
58
  taskResult.contentType = taskResponse?.contentType || 'application/json';
59
+ taskResult.httpStatus = taskResponse?.httpStatus || 200;
59
60
  } catch (e) {
60
61
  // Log error and rethrow.
61
62
  logger.error(
@@ -69,6 +70,7 @@ export const taskRunner: TaskRunner = {
69
70
  metadata: {
70
71
  contentType: taskResult.contentType || 'application/json',
71
72
  execTimeMs,
73
+ httpStatus: taskResult.httpStatus || 200,
72
74
  },
73
75
  };
74
76