@jpmorganchase/mosaic-core 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/package.json +36 -0
- package/src/PluginError.ts +3 -0
- package/src/PullDocs.ts +124 -0
- package/src/Source.ts +178 -0
- package/src/SourceManager.ts +196 -0
- package/src/WorkerSubscription.ts +80 -0
- package/src/__mocks__/Source.ts +29 -0
- package/src/__tests__/PullDocs.test.ts +96 -0
- package/src/__tests__/Source.test.ts +341 -0
- package/src/__tests__/SourceManager.test.ts +255 -0
- package/src/__tests__/WorkerSubscription.test.ts +308 -0
- package/src/filesystems/FileAccess.ts +256 -0
- package/src/filesystems/ImmutableVolume.ts +45 -0
- package/src/filesystems/MutableVolume.ts +51 -0
- package/src/filesystems/RestrictedVolume.ts +57 -0
- package/src/filesystems/UnionFileAccess.ts +77 -0
- package/src/filesystems/UnionVolume.ts +28 -0
- package/src/helpers/createConfig.ts +52 -0
- package/src/index.ts +1 -0
- package/src/operators/ObservableWorker.ts +24 -0
- package/src/plugin/createPluginAPI.ts +75 -0
- package/src/plugin/index.ts +41 -0
- package/src/plugin/loadDefinitionModules.ts +58 -0
- package/src/plugin/pluginRunner.ts +52 -0
- package/src/plugin/serialiserRunner.ts +36 -0
- package/src/worker/Source.worker.ts +124 -0
- package/src/worker/helpers/createSourceObservable.ts +84 -0
- package/tsconfig.example.json +6 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isObservable, map } from 'rxjs';
|
|
2
|
+
import type { Observable } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
import type WorkerData from '@jpmorganchase/mosaic-types/dist/WorkerData';
|
|
5
|
+
import type Source from '@jpmorganchase/mosaic-types/dist/Source';
|
|
6
|
+
import type Page from '@jpmorganchase/mosaic-types/dist/Page';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { escapeRegExp } from 'lodash';
|
|
9
|
+
|
|
10
|
+
export default async function createSourceObservable(
|
|
11
|
+
{ modulePath, options, pageExtensions, ignorePages }: WorkerData,
|
|
12
|
+
serialiser
|
|
13
|
+
): Promise<Observable<Page[]>> {
|
|
14
|
+
const api = await getSourceDefinitionExports(modulePath);
|
|
15
|
+
const source$ = api.create(options, { serialiser, pageExtensions });
|
|
16
|
+
|
|
17
|
+
if (!isObservable(source$)) {
|
|
18
|
+
throw new Error(`Source at '${modulePath}' did not return an Observable.`);
|
|
19
|
+
}
|
|
20
|
+
const isNonHiddenPage = createPageTest(ignorePages, pageExtensions);
|
|
21
|
+
|
|
22
|
+
// TODO: Move this formatter
|
|
23
|
+
return source$.pipe(
|
|
24
|
+
map((pages: Page[]) => {
|
|
25
|
+
return pages.reduce((pages, page) => {
|
|
26
|
+
if (!isNonHiddenPage(page.fullPath)) {
|
|
27
|
+
console.warn(
|
|
28
|
+
`File '${
|
|
29
|
+
page.fullPath
|
|
30
|
+
}' does not have a matching page file extension, it will be removed from the output.
|
|
31
|
+
|
|
32
|
+
NOTE: Only ${pageExtensions.join(
|
|
33
|
+
', '
|
|
34
|
+
)} extensions are supported (as per the value defined in PullDocs config \`pageExtensions\`). To add non-page files to the filesystem, start their names with a dot to indicate they are hidden files.`
|
|
35
|
+
);
|
|
36
|
+
return pages;
|
|
37
|
+
}
|
|
38
|
+
if (!page.fullPath) {
|
|
39
|
+
console.warn(
|
|
40
|
+
`Page '${page.fullPath}' is missing the \`fullPath\` property. It will be removed from the output.`
|
|
41
|
+
);
|
|
42
|
+
return pages;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return pages.concat({
|
|
46
|
+
...page,
|
|
47
|
+
title: page.title || page.fullPath,
|
|
48
|
+
fullPath: page.fullPath.toLowerCase(),
|
|
49
|
+
route: page.route
|
|
50
|
+
? page.route.toLowerCase()
|
|
51
|
+
: page.fullPath.toLowerCase()
|
|
52
|
+
});
|
|
53
|
+
}, []);
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function getSourceDefinitionExports(modulePath): Promise<Source> {
|
|
59
|
+
const { default: defaultProp }: { default: Source | { __esModule: boolean; default: Source } } =
|
|
60
|
+
await import(modulePath);
|
|
61
|
+
|
|
62
|
+
const api =
|
|
63
|
+
'default' in defaultProp && defaultProp.__esModule
|
|
64
|
+
? defaultProp.default
|
|
65
|
+
: (defaultProp as Source);
|
|
66
|
+
|
|
67
|
+
if (!api) {
|
|
68
|
+
throw new Error(`Could not resolve source '${modulePath}'.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (typeof api.create !== 'function') {
|
|
72
|
+
throw new Error(`Source '${modulePath}' does not have a valid \`create\` function.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return api;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createPageTest(ignorePages, pageExtensions) {
|
|
79
|
+
const extTest = new RegExp(`${pageExtensions.map(escapeRegExp).join('|')}$`);
|
|
80
|
+
const ignoreTest = new RegExp(`${ignorePages.map(escapeRegExp).join('|')}$`);
|
|
81
|
+
return file => {
|
|
82
|
+
return !ignoreTest.test(file) && extTest.test(file) && !path.basename(file).startsWith('.');
|
|
83
|
+
};
|
|
84
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"target": "es2015",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"moduleResolution": "NodeNext",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"rootDir": "./src"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*", "../common/src/types"],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"node_modules",
|
|
16
|
+
"src/**/__tests__/**/*",
|
|
17
|
+
"src/**/__mocks__/**/*",
|
|
18
|
+
"src/__tests__/**/*",
|
|
19
|
+
"src/__mocks__/**/*",
|
|
20
|
+
"**/dist/**/*"
|
|
21
|
+
]
|
|
22
|
+
}
|