@jpmorganchase/mosaic-source-local-folder 0.0.0-snapshot-20240604074928
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/fromFsWatch.d.ts +7 -0
- package/dist/fromFsWatch.js +20 -0
- package/dist/fromFsWatch.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { WatchOptions } from 'fs';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
export default function fromFsWatch(filename: string, options?: WatchOptions | BufferEncoding | string | null | (WatchOptions & {
|
|
6
|
+
encoding: 'buffer';
|
|
7
|
+
}) | 'buffer'): Observable<unknown>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { watch } from 'chokidar';
|
|
3
|
+
export default function fromFsWatch(filename, options) {
|
|
4
|
+
return new Observable(subscriber => {
|
|
5
|
+
const watcher = watch(filename, options);
|
|
6
|
+
watcher.on('all', (_eventType, filename) => {
|
|
7
|
+
subscriber.next(filename);
|
|
8
|
+
});
|
|
9
|
+
watcher.once('error', (error) => {
|
|
10
|
+
subscriber.error(error);
|
|
11
|
+
});
|
|
12
|
+
watcher.once('close', () => {
|
|
13
|
+
subscriber.complete();
|
|
14
|
+
});
|
|
15
|
+
return function unsubscribe() {
|
|
16
|
+
watcher.close();
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=fromFsWatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromFsWatch.js","sourceRoot":"","sources":["../src/fromFsWatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,QAAgB,EAChB,OAMY;IAEZ,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAc,CAAC,CAAC;QAEhD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;YACzC,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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Source } from '@jpmorganchase/mosaic-types';
|
|
3
|
+
export declare const schema: z.ZodObject<{
|
|
4
|
+
/**
|
|
5
|
+
* Collection of file extensions to look for
|
|
6
|
+
*/
|
|
7
|
+
extensions: z.ZodArray<z.ZodString, "atleastone">;
|
|
8
|
+
/**
|
|
9
|
+
* Add to use a folder prefix
|
|
10
|
+
*/
|
|
11
|
+
prefixDir: z.ZodOptional<z.ZodString>;
|
|
12
|
+
/**
|
|
13
|
+
* The root directory containing docs
|
|
14
|
+
*/
|
|
15
|
+
rootDir: z.ZodString;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
extensions: [string, ...string[]];
|
|
18
|
+
rootDir: string;
|
|
19
|
+
prefixDir?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
extensions: [string, ...string[]];
|
|
22
|
+
rootDir: string;
|
|
23
|
+
prefixDir?: string | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type LocalFolderSourceOptions = z.infer<typeof schema>;
|
|
26
|
+
declare const LocalFolderSource: Source<LocalFolderSourceOptions>;
|
|
27
|
+
export default LocalFolderSource;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { concatMap, delay, merge, of, switchMap } from 'rxjs';
|
|
2
|
+
import glob from 'fast-glob';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import { merge as lodashMerge } from 'lodash-es';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { validateMosaicSchema } from '@jpmorganchase/mosaic-schemas';
|
|
8
|
+
import fromFsWatch from './fromFsWatch.js';
|
|
9
|
+
async function getLastModifiedDate(fullPath) {
|
|
10
|
+
const resolvedRoute = await fs.promises.realpath(fullPath);
|
|
11
|
+
const stats = await fs.promises.stat(resolvedRoute);
|
|
12
|
+
return stats?.mtimeMs ? stats.mtimeMs : 0;
|
|
13
|
+
}
|
|
14
|
+
function createFileGlob(url, pageExtensions) {
|
|
15
|
+
if (pageExtensions.length === 1) {
|
|
16
|
+
return `${url}${pageExtensions[0]}`;
|
|
17
|
+
}
|
|
18
|
+
return `${url}{${pageExtensions.join(',')}}`;
|
|
19
|
+
}
|
|
20
|
+
export const schema = z.object({
|
|
21
|
+
/**
|
|
22
|
+
* Collection of file extensions to look for
|
|
23
|
+
*/
|
|
24
|
+
extensions: z
|
|
25
|
+
.string({ required_error: 'Please provide the collection of file extensions to look for' })
|
|
26
|
+
.array()
|
|
27
|
+
.nonempty(),
|
|
28
|
+
/**
|
|
29
|
+
* Add to use a folder prefix
|
|
30
|
+
*/
|
|
31
|
+
prefixDir: z.string().optional(),
|
|
32
|
+
/**
|
|
33
|
+
* The root directory containing docs
|
|
34
|
+
*/
|
|
35
|
+
rootDir: z.string({ required_error: 'Please provide a root directory name' })
|
|
36
|
+
});
|
|
37
|
+
const LocalFolderSource = {
|
|
38
|
+
create(options, { serialiser }) {
|
|
39
|
+
validateMosaicSchema(schema, options);
|
|
40
|
+
return merge(of(null), fromFsWatch(options.rootDir, { recursive: true })).pipe(delay(1000), switchMap(() => glob(createFileGlob('**', options.extensions), {
|
|
41
|
+
cwd: options.rootDir,
|
|
42
|
+
onlyFiles: true
|
|
43
|
+
})), concatMap(async (filepaths) =>
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
45
|
+
await Promise.all(filepaths.map(async (filepath) => {
|
|
46
|
+
const fullPath = path.posix.join(options.rootDir, filepath);
|
|
47
|
+
return lodashMerge({}, await serialiser.deserialise(fullPath, await fs.promises.readFile(fullPath)), {
|
|
48
|
+
lastModified: new Date(await getLastModifiedDate(fullPath)).getTime(),
|
|
49
|
+
fullPath: `/${options.prefixDir ? path.posix.join(options.prefixDir, filepath) : filepath}`.replace(/^\/{2,}/, '/')
|
|
50
|
+
});
|
|
51
|
+
}))));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export default LocalFolderSource;
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAc,EAAE,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,MAAM,K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+
"version": "0.0.0-snapshot-20240604074928",
|
|
4
|
+
"author": "",
|
|
5
|
+
"description": "Mosaic local folder source for core file system",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"node": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=16.10.0 || >=18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"clean": "rm -fr dist",
|
|
27
|
+
"lint": "eslint --ignore-pattern \"**/__tests__/**\""
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git@github.com:jpmorganchase/mosaic.git",
|
|
32
|
+
"directory": "packages/source-local-folder"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@jpmorganchase/mosaic-schemas": "0.0.0-snapshot-20240604074928",
|
|
36
|
+
"@jpmorganchase/mosaic-types": "0.0.0-snapshot-20240604074928",
|
|
37
|
+
"chokidar": "^3.5.3",
|
|
38
|
+
"fast-glob": "^3.2.12",
|
|
39
|
+
"lodash-es": "^4.17.21",
|
|
40
|
+
"rxjs": "^7.5.5",
|
|
41
|
+
"zod": "^3.22.3"
|
|
42
|
+
}
|
|
43
|
+
}
|