@static-suite/static-suite-data-server 0.0.11 → 0.0.12

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
@@ -163,6 +163,52 @@ const results = store.data
163
163
  .items.filter(article => article.data.content.title.includes('foo'));
164
164
  ```
165
165
 
166
+ ### Getting a subset of files via HTTP
167
+
168
+ It is also possible to get a subset of files via HTTP, querying the HTTP endpoint `/subset` with the following options passed as query strings:
169
+
170
+ - `dir`: optional base directory to filter files. It requires a trailing slash, but not a leading slash, e.g.- `en/entity/node/article/`
171
+ - `variant`: Optional name of a variant file.
172
+ - Use `_main` to obtain the default variant.
173
+ - Use any other string, e.g.- `card`, to obtain the card variant.
174
+ - Use "null" to avoid searching for any variant.
175
+ - Defaults to `_main`.
176
+ - `ext`: Optional file extension, without dots. Defaults to `json`.
177
+ - `recursive`: Optional flag to search for files recursively. Defaults to `true`.
178
+ - `as`: Optional flag to get the subset as filenames or URLs. Possible values: `filename` or `url`. Defaults to `filename`.
179
+
180
+ #### Return value
181
+
182
+ An array of filenames in the subset.
183
+
184
+ ```http
185
+ // Get a subset of all nodes in English with "json" extension.
186
+ http://localhost:57471/subset?dir=en/entity/node/
187
+
188
+ // Return value
189
+ [
190
+ "en/entity/node/article/1.json",
191
+ "en/entity/node/page/4.json",
192
+ "en/entity/node/gallery/6.json",
193
+ ...
194
+ ]
195
+ ```
196
+
197
+ An array of URLs in the subset.
198
+
199
+ ```http
200
+ // Get a subset of all nodes in English with "json" extension.
201
+ http://localhost:57471/subset?dir=en/entity/node/&as=url
202
+
203
+ // Return value
204
+ [
205
+ "/path/to/public/url-1",
206
+ "/path/to/public/url-2",
207
+ "/path/to/public/url-3",
208
+ ...
209
+ ]
210
+ ```
211
+
166
212
  ### Indexes
167
213
 
168
214
  Apart from the main data Map, files are also automatically stored in two more maps (indexes) to be able to access them faster:
@@ -163,6 +163,52 @@ const results = store.data
163
163
  .items.filter(article => article.data.content.title.includes('foo'));
164
164
  ```
165
165
 
166
+ ### Getting a subset of files via HTTP
167
+
168
+ It is also possible to get a subset of files via HTTP, querying the HTTP endpoint `/subset` with the following options passed as query strings:
169
+
170
+ - `dir`: optional base directory to filter files. It requires a trailing slash, but not a leading slash, e.g.- `en/entity/node/article/`
171
+ - `variant`: Optional name of a variant file.
172
+ - Use `_main` to obtain the default variant.
173
+ - Use any other string, e.g.- `card`, to obtain the card variant.
174
+ - Use "null" to avoid searching for any variant.
175
+ - Defaults to `_main`.
176
+ - `ext`: Optional file extension, without dots. Defaults to `json`.
177
+ - `recursive`: Optional flag to search for files recursively. Defaults to `true`.
178
+ - `as`: Optional flag to get the subset as filenames or URLs. Possible values: `filename` or `url`. Defaults to `filename`.
179
+
180
+ #### Return value
181
+
182
+ An array of filenames in the subset.
183
+
184
+ ```http
185
+ // Get a subset of all nodes in English with "json" extension.
186
+ http://localhost:57471/subset?dir=en/entity/node/
187
+
188
+ // Return value
189
+ [
190
+ "en/entity/node/article/1.json",
191
+ "en/entity/node/page/4.json",
192
+ "en/entity/node/gallery/6.json",
193
+ ...
194
+ ]
195
+ ```
196
+
197
+ An array of URLs in the subset.
198
+
199
+ ```http
200
+ // Get a subset of all nodes in English with "json" extension.
201
+ http://localhost:57471/subset?dir=en/entity/node/&as=url
202
+
203
+ // Return value
204
+ [
205
+ "/path/to/public/url-1",
206
+ "/path/to/public/url-2",
207
+ "/path/to/public/url-3",
208
+ ...
209
+ ]
210
+ ```
211
+
166
212
  ### Indexes
167
213
 
168
214
  Apart from the main data Map, files are also automatically stored in two more maps (indexes) to be able to access them faster:
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/routes/index.ts"],"names":[],"mappings":"AAkCA,QAAA,MAAM,MAAM,4CAAW,CAAC;AAgCxB,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/routes/index.ts"],"names":[],"mappings":"AAmCA,QAAA,MAAM,MAAM,4CAAW,CAAC;AAiCxB,eAAe,MAAM,CAAC"}
@@ -12,6 +12,7 @@ const dump_1 = require("./dump");
12
12
  const dependency_1 = require("./dependency");
13
13
  const indexUrl_1 = require("./indexUrl");
14
14
  const indexUUID_1 = require("./indexUUID");
15
+ const subset_1 = require("./subset");
15
16
  const routes = (0, express_1.Router)();
16
17
  routes.get('/', home_1.home);
17
18
  routes.get('/docs', docs_1.docs);
@@ -42,4 +43,5 @@ routes.get('/dependency', dependency_1.dependencyIndex);
42
43
  routes.get(['/data/*', '/data'], data_1.data);
43
44
  routes.get(['/index/url/*', '/index/url'], indexUrl_1.indexUrl);
44
45
  routes.get(['/index/uuid/*', '/index/uuid'], indexUUID_1.indexUUID);
46
+ routes.get('/subset', subset_1.subset);
45
47
  exports.default = routes;
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from 'express';
2
+ declare const subset: (req: Request, res: Response) => void;
3
+ export { subset };
4
+ //# sourceMappingURL=subset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subset.d.ts","sourceRoot":"","sources":["../../../src/http/routes/subset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5C,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,KAAG,IAmC7C,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subset = void 0;
4
+ const store_1 = require("../../lib/store");
5
+ const dataDir_1 = require("../../lib/store/dataDir");
6
+ const subset = (req, res) => {
7
+ dataDir_1.dataDirManager.update();
8
+ const options = {};
9
+ if (req.query.dir) {
10
+ options.dir = req.query.dir;
11
+ }
12
+ if (req.query.variant) {
13
+ if (req.query.variant === 'null') {
14
+ options.variant = undefined;
15
+ }
16
+ else {
17
+ options.variant = req.query.variant;
18
+ }
19
+ }
20
+ if (req.query.ext) {
21
+ options.ext = req.query.ext;
22
+ }
23
+ if (req.query.recursive) {
24
+ options.recursive = req.query.recursive === 'true';
25
+ }
26
+ const returnedSubset = store_1.store.data.subset(options);
27
+ let result;
28
+ if (req.query.as === 'url') {
29
+ result = returnedSubset.items
30
+ .map(item => item.data?.content?.url?.path)
31
+ .filter(path => !!path);
32
+ }
33
+ else {
34
+ result = returnedSubset.filenames;
35
+ }
36
+ res.status(200);
37
+ res.set({
38
+ 'Content-Type': 'application/json',
39
+ });
40
+ res.send(result);
41
+ };
42
+ exports.subset = subset;
@@ -116,7 +116,7 @@ export type StoreSubsetOptions = {
116
116
  * Use null to avoid searching for any variant.
117
117
  * Defaults to '_main'.
118
118
  */
119
- variant?: string;
119
+ variant?: string | null;
120
120
  /**
121
121
  * Optional file extension, without dots. Defaults to 'json'.
122
122
  */
@@ -1 +1 @@
1
- {"version":3,"file":"store.types.d.ts","sourceRoot":"","sources":["../../../src/lib/store/store.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAAC;CAClD;AAED;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEtB;;WAEG;Q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AK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;;;;;OASG;IACH,GAAG,CAAC,gBAAgB,EAAE,MAAM,GAAG,YAAY,CAAC;IAE5C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IAEnC;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IAEnC;;;;;OAKG;IACH,aAAa,IAAI,YAAY,CAAC;IAE9B;;;;;;;;OAQG;IACH,uBAAuB,CACrB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,GAAG,GACf,YAAY,CAAC;IAEhB;;;;OAIG;IACH,KAAK,IAAI,YAAY,CAAC;CACvB,CAAC"}
@@ -435,7 +435,7 @@ declare type StoreSubsetOptions = {
435
435
  * Use null to avoid searching for any variant.
436
436
  * Defaults to '_main'.
437
437
  */
438
- variant?: string;
438
+ variant?: string | null;
439
439
  /**
440
440
  * Optional file extension, without dots. Defaults to 'json'.
441
441
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-suite/static-suite-data-server",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
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",
@@ -31,6 +31,7 @@ import {
31
31
  } from './dependency';
32
32
  import { indexUrl } from './indexUrl';
33
33
  import { indexUUID } from './indexUUID';
34
+ import { subset } from './subset';
34
35
 
35
36
  const routes = Router();
36
37
 
@@ -63,5 +64,6 @@ routes.get('/dependency', dependencyIndex);
63
64
  routes.get(['/data/*', '/data'], data);
64
65
  routes.get(['/index/url/*', '/index/url'], indexUrl);
65
66
  routes.get(['/index/uuid/*', '/index/uuid'], indexUUID);
67
+ routes.get('/subset', subset);
66
68
 
67
69
  export default routes;
@@ -0,0 +1,43 @@
1
+ import { Request, Response } from 'express';
2
+ import { StoreSubsetOptions } from 'lib/store/store.types';
3
+ import { store } from '../../lib/store';
4
+ import { dataDirManager } from '../../lib/store/dataDir';
5
+
6
+ const subset = (req: Request, res: Response): void => {
7
+ dataDirManager.update();
8
+ const options: StoreSubsetOptions = {};
9
+ if (req.query.dir) {
10
+ options.dir = req.query.dir as string;
11
+ }
12
+ if (req.query.variant) {
13
+ if (req.query.variant === 'null') {
14
+ options.variant = undefined;
15
+ } else {
16
+ options.variant = req.query.variant as string;
17
+ }
18
+ }
19
+ if (req.query.ext) {
20
+ options.ext = req.query.ext as string;
21
+ }
22
+ if (req.query.recursive) {
23
+ options.recursive = req.query.recursive === 'true';
24
+ }
25
+
26
+ const returnedSubset = store.data.subset(options);
27
+ let result;
28
+ if (req.query.as === 'url') {
29
+ result = returnedSubset.items
30
+ .map(item => item.data?.content?.url?.path)
31
+ .filter(path => !!path);
32
+ } else {
33
+ result = returnedSubset.filenames;
34
+ }
35
+
36
+ res.status(200);
37
+ res.set({
38
+ 'Content-Type': 'application/json',
39
+ });
40
+ res.send(result);
41
+ };
42
+
43
+ export { subset };
@@ -125,7 +125,7 @@ export type StoreSubsetOptions = {
125
125
  * Use null to avoid searching for any variant.
126
126
  * Defaults to '_main'.
127
127
  */
128
- variant?: string;
128
+ variant?: string | null;
129
129
 
130
130
  /**
131
131
  * Optional file extension, without dots. Defaults to 'json'.