@jpmorganchase/mosaic-source-local-folder 0.1.0-beta.3
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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-clean.log +2 -0
- package/CHANGELOG.md +34 -0
- package/dist/fromFsWatch.d.ts +7 -0
- package/dist/fromFsWatch.js +22 -0
- package/dist/fromFsWatch.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/package.json +24 -0
- package/src/fromFsWatch.ts +31 -0
- package/src/index.ts +63 -0
- package/tsconfig.json +9 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @jpmorganchase/mosaic-source-local-folder
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 457df5e: switch to public package
|
|
8
|
+
- Updated dependencies [457df5e]
|
|
9
|
+
- @jpmorganchase/mosaic-types@0.1.0-beta.3
|
|
10
|
+
|
|
11
|
+
## 0.1.0-beta.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- e1bbbe7: Initial release of Mosaic Core file-system.
|
|
16
|
+
|
|
17
|
+
Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
|
|
18
|
+
|
|
19
|
+
- 4b2bc51: pipped to 0.1.0-beta.1 for publishing to NPM
|
|
20
|
+
- Updated dependencies [e1bbbe7]
|
|
21
|
+
- Updated dependencies [4b2bc51]
|
|
22
|
+
- @jpmorganchase/mosaic-types@0.1.0-beta.2
|
|
23
|
+
|
|
24
|
+
## 0.1.0
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- e1bbbe7: Initial release of Mosaic Core file-system.
|
|
29
|
+
|
|
30
|
+
Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [e1bbbe7]
|
|
33
|
+
- Updated dependencies [bbc853c]
|
|
34
|
+
- @jpmorganchase/mosaic-types@0.1.0
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { PathLike, WatchOptions } from 'fs';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
export default function fromFsWatch(filename: PathLike, options?: WatchOptions | BufferEncoding | string | null | (WatchOptions & {
|
|
6
|
+
encoding: 'buffer';
|
|
7
|
+
}) | 'buffer'): Observable<unknown>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("fs");
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
function fromFsWatch(filename, options) {
|
|
6
|
+
return new rxjs_1.Observable(subscriber => {
|
|
7
|
+
const watcher = (0, fs_1.watch)(filename, options, (_eventType, filename) => {
|
|
8
|
+
subscriber.next(filename);
|
|
9
|
+
});
|
|
10
|
+
watcher.once('error', (error) => {
|
|
11
|
+
subscriber.error(error);
|
|
12
|
+
});
|
|
13
|
+
watcher.once('close', () => {
|
|
14
|
+
subscriber.complete();
|
|
15
|
+
});
|
|
16
|
+
return function unsubscribe() {
|
|
17
|
+
watcher.close();
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.default = fromFsWatch;
|
|
22
|
+
//# sourceMappingURL=fromFsWatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromFsWatch.js","sourceRoot":"","sources":["../src/fromFsWatch.ts"],"names":[],"mappings":";;AAAA,2BAAmD;AACnD,+BAAkC;AAElC,SAAwB,WAAW,CACjC,QAAkB,EAClB,OAMY;IAEZ,OAAO,IAAI,iBAAU,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,OAAO,GAAG,IAAA,UAAK,EAAC,QAAQ,EAAE,OAAc,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;YACvE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;YACrC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;YACzB,UAAU,CAAC,QAAQ,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,WAAW;YACzB,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA3BD,8BA2BC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type Source from '@jpmorganchase/mosaic-types/dist/Source';
|
|
2
|
+
export interface LocalFolderSourceOptions {
|
|
3
|
+
extensions: string[];
|
|
4
|
+
prefixDir?: string;
|
|
5
|
+
rootDir: string;
|
|
6
|
+
}
|
|
7
|
+
declare const LocalFolderSource: Source<LocalFolderSourceOptions>;
|
|
8
|
+
export default LocalFolderSource;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
11
|
+
const fromFsWatch_1 = __importDefault(require("./fromFsWatch"));
|
|
12
|
+
const LocalFolderSource = {
|
|
13
|
+
create(options, { serialiser }) {
|
|
14
|
+
return (0, rxjs_1.merge)((0, rxjs_1.of)(null), (0, fromFsWatch_1.default)(options.rootDir, { recursive: true })).pipe((0, rxjs_1.delay)(1000), (0, rxjs_1.switchMap)(() => (0, fast_glob_1.default)(createFileGlob('**', options.extensions), {
|
|
15
|
+
cwd: options.rootDir,
|
|
16
|
+
onlyFiles: true
|
|
17
|
+
})), (0, rxjs_1.concatMap)(async (filepaths) => await Promise.all(filepaths.map(async (filepath) => {
|
|
18
|
+
const fullPath = path_1.default.join(options.rootDir, filepath);
|
|
19
|
+
return (0, merge_1.default)({}, await serialiser.deserialise(fullPath, await fs_1.default.promises.readFile(fullPath)), {
|
|
20
|
+
lastModified: new Date(await getLastModifiedDate(fullPath)).getTime(),
|
|
21
|
+
fullPath: `/${options.prefixDir ? path_1.default.join(options.prefixDir, filepath) : filepath}`.replace(/^\/{2,}/, '/')
|
|
22
|
+
});
|
|
23
|
+
}))));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
async function getLastModifiedDate(fullPath) {
|
|
27
|
+
const resolvedRoute = await fs_1.default.promises.realpath(fullPath);
|
|
28
|
+
const stats = await fs_1.default.promises.stat(resolvedRoute);
|
|
29
|
+
return (stats === null || stats === void 0 ? void 0 : stats.mtimeMs) ? stats.mtimeMs : 0;
|
|
30
|
+
}
|
|
31
|
+
function createFileGlob(url, pageExtensions) {
|
|
32
|
+
if (pageExtensions.length === 1) {
|
|
33
|
+
return `${url}${pageExtensions[0]}`;
|
|
34
|
+
}
|
|
35
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
36
|
+
}
|
|
37
|
+
exports.default = LocalFolderSource;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names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CAAC,SAAS,EAAE,GAAG,CAAC;aAC3B,CACF,CAAC;QACJ,CAAC,CAAC,CACH,CACJ,CACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,KAAK,UAAU,mBAAmB,CAAC,QAAgB;IACjD,MAAM,aAAa,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACpD,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,cAAc,CAAC,GAAW,EAAE,cAAwB;IAC3D,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,OAAO,GAAG,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;KACrC;IACD,OAAO,GAAG,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/C,CAAC;AAED,kBAAe,iBAAiB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jpmorganchase/mosaic-source-local-folder",
|
|
3
|
+
"version": "0.1.0-beta.3",
|
|
4
|
+
"author": "",
|
|
5
|
+
"description": "",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">= 12.0.0"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"clean": "rm -fr dist"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git@github.com:jpmorganchase/mosaic.git"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@jpmorganchase/mosaic-types": "^0.1.0-beta.3",
|
|
22
|
+
"rxjs": "^7.5.5"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PathLike, watch, WatchOptions } from 'fs';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
export default function fromFsWatch(
|
|
5
|
+
filename: PathLike,
|
|
6
|
+
options?:
|
|
7
|
+
| WatchOptions
|
|
8
|
+
| BufferEncoding
|
|
9
|
+
| string
|
|
10
|
+
| null
|
|
11
|
+
| (WatchOptions & { encoding: 'buffer' })
|
|
12
|
+
| 'buffer'
|
|
13
|
+
) {
|
|
14
|
+
return new Observable(subscriber => {
|
|
15
|
+
const watcher = watch(filename, options as any, (_eventType, filename) => {
|
|
16
|
+
subscriber.next(filename);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
watcher.once('error', (error: Error) => {
|
|
20
|
+
subscriber.error(error);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
watcher.once('close', () => {
|
|
24
|
+
subscriber.complete();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return function unsubscribe() {
|
|
28
|
+
watcher.close();
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { concatMap, delay, merge, Observable, of, switchMap } from 'rxjs';
|
|
2
|
+
import glob from 'fast-glob';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import lodashMerge from 'lodash/merge';
|
|
6
|
+
|
|
7
|
+
import type Source from '@jpmorganchase/mosaic-types/dist/Source';
|
|
8
|
+
import type Page from '@jpmorganchase/mosaic-types/dist/Page';
|
|
9
|
+
|
|
10
|
+
import fromFsWatch from './fromFsWatch';
|
|
11
|
+
|
|
12
|
+
export interface LocalFolderSourceOptions {
|
|
13
|
+
extensions: string[];
|
|
14
|
+
prefixDir?: string;
|
|
15
|
+
rootDir: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const LocalFolderSource: Source<LocalFolderSourceOptions> = {
|
|
19
|
+
create(options, { serialiser }): Observable<Page<{}>[]> {
|
|
20
|
+
return merge(of(null), fromFsWatch(options.rootDir, { recursive: true })).pipe(
|
|
21
|
+
delay(1000),
|
|
22
|
+
switchMap(() =>
|
|
23
|
+
glob(createFileGlob('**', options.extensions), {
|
|
24
|
+
cwd: options.rootDir,
|
|
25
|
+
onlyFiles: true
|
|
26
|
+
})
|
|
27
|
+
),
|
|
28
|
+
concatMap(
|
|
29
|
+
async (filepaths: string[]) =>
|
|
30
|
+
await Promise.all(
|
|
31
|
+
filepaths.map(async (filepath: string) => {
|
|
32
|
+
const fullPath = path.join(options.rootDir, filepath);
|
|
33
|
+
return lodashMerge(
|
|
34
|
+
{},
|
|
35
|
+
await serialiser.deserialise(fullPath, await fs.promises.readFile(fullPath)),
|
|
36
|
+
{
|
|
37
|
+
lastModified: new Date(await getLastModifiedDate(fullPath)).getTime(),
|
|
38
|
+
fullPath: `/${
|
|
39
|
+
options.prefixDir ? path.join(options.prefixDir, filepath) : filepath
|
|
40
|
+
}`.replace(/^\/{2,}/, '/')
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
})
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
async function getLastModifiedDate(fullPath: string) {
|
|
51
|
+
const resolvedRoute = await fs.promises.realpath(fullPath);
|
|
52
|
+
const stats = await fs.promises.stat(resolvedRoute);
|
|
53
|
+
return stats?.mtimeMs ? stats.mtimeMs : 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createFileGlob(url: string, pageExtensions: string[]) {
|
|
57
|
+
if (pageExtensions.length === 1) {
|
|
58
|
+
return `${url}${pageExtensions[0]}`;
|
|
59
|
+
}
|
|
60
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default LocalFolderSource;
|