@jpmorganchase/mosaic-source-local-folder 0.1.0-beta.4 → 0.1.0-beta.40

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.
@@ -1,7 +1,7 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { PathLike, WatchOptions } from 'fs';
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import { WatchOptions } from 'fs';
4
4
  import { Observable } from 'rxjs';
5
- export default function fromFsWatch(filename: PathLike, options?: WatchOptions | BufferEncoding | string | null | (WatchOptions & {
5
+ export default function fromFsWatch(filename: string, options?: WatchOptions | BufferEncoding | string | null | (WatchOptions & {
6
6
  encoding: 'buffer';
7
7
  }) | 'buffer'): Observable<unknown>;
@@ -1,10 +1,9 @@
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) => {
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) => {
8
7
  subscriber.next(filename);
9
8
  });
10
9
  watcher.once('error', (error) => {
@@ -18,5 +17,4 @@ function fromFsWatch(filename, options) {
18
17
  };
19
18
  });
20
19
  }
21
- exports.default = fromFsWatch;
22
20
  //# sourceMappingURL=fromFsWatch.js.map
@@ -1 +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;QAC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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 CHANGED
@@ -1,8 +1,27 @@
1
- import type Source from '@jpmorganchase/mosaic-types/dist/Source';
2
- export interface LocalFolderSourceOptions {
3
- extensions: string[];
4
- prefixDir?: string;
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
+ prefixDir?: string | undefined;
18
+ extensions: [string, ...string[]];
5
19
  rootDir: string;
6
- }
20
+ }, {
21
+ prefixDir?: string | undefined;
22
+ extensions: [string, ...string[]];
23
+ rootDir: string;
24
+ }>;
25
+ export declare type LocalFolderSourceOptions = z.infer<typeof schema>;
7
26
  declare const LocalFolderSource: Source<LocalFolderSourceOptions>;
8
27
  export default LocalFolderSource;
package/dist/index.js CHANGED
@@ -1,38 +1,55 @@
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"));
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
+ });
12
37
  const LocalFolderSource = {
13
38
  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), {
39
+ validateMosaicSchema(schema, options);
40
+ return merge(of(null), fromFsWatch(options.rootDir, { recursive: true })).pipe(delay(1000), switchMap(() => glob(createFileGlob('**', options.extensions), {
15
41
  cwd: options.rootDir,
16
42
  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)), {
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)), {
20
48
  lastModified: new Date(await getLastModifiedDate(fullPath)).getTime(),
21
- fullPath: `/${options.prefixDir ? path_1.default.join(options.prefixDir, filepath) : filepath}`.replace(/^\/{2,}/, '/')
49
+ fullPath: `/${options.prefixDir ? path.posix.join(options.prefixDir, filepath) : filepath}`.replace(/^\/{2,}/, '/')
22
50
  });
23
51
  }))));
24
52
  }
25
53
  };
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;
54
+ export default LocalFolderSource;
38
55
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,+BAA0E;AAC1E,0DAA6B;AAC7B,gDAAwB;AACxB,4CAAoB;AACpB,yDAAuC;AAKvC,gEAAwC;AAQxC,MAAM,iBAAiB,GAAqC;IAC1D,MAAM,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE;QAC5B,OAAO,IAAA,YAAK,EAAC,IAAA,SAAE,EAAC,IAAI,CAAC,EAAE,IAAA,qBAAW,EAAC,OAAO,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5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,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC5D,OAAO,WAAW,CAChB,EAAE,EACF,MAAM,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAC5E;gBACE,YAAY,EAAE,IAAI,IAAI,CAAC,MAAM,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE;gBACrE,QAAQ,EAAE,IACR,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QACrE,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;aAC3B,CACF,CAAC;QACJ,CAAC,CAAC,CACH,CACJ,CACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,27 +1,42 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-source-local-folder",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.40",
4
4
  "author": "",
5
5
  "description": "Mosaic local folder source for core file system",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./dist/index.js",
8
+ "type": "module",
8
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
+ }
16
+ },
9
17
  "engines": {
10
- "node": ">= 12.0.0"
18
+ "node": ">=16.10.0 || >=18.0.0"
11
19
  },
12
20
  "files": [
13
21
  "dist"
14
22
  ],
15
23
  "scripts": {
16
24
  "build": "tsc",
17
- "clean": "rm -fr dist"
25
+ "clean": "rm -fr dist",
26
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
18
27
  },
19
28
  "repository": {
20
29
  "type": "git",
21
- "url": "git@github.com:jpmorganchase/mosaic.git"
30
+ "url": "git@github.com:jpmorganchase/mosaic.git",
31
+ "directory": "packages/source-local-folder"
22
32
  },
23
33
  "dependencies": {
24
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.4",
25
- "rxjs": "^7.5.5"
34
+ "@jpmorganchase/mosaic-schemas": "^0.1.0-beta.40",
35
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.40",
36
+ "chokidar": "^3.5.3",
37
+ "fast-glob": "^3.2.12",
38
+ "lodash-es": "^4.17.21",
39
+ "rxjs": "^7.5.5",
40
+ "zod": "^3.19.1"
26
41
  }
27
- }
42
+ }
package/CHANGELOG.md DELETED
@@ -1,42 +0,0 @@
1
- # @jpmorganchase/mosaic-source-local-folder
2
-
3
- ## 0.1.0-beta.4
4
-
5
- ### Patch Changes
6
-
7
- - bd285df: added dist to package.json
8
- - Updated dependencies [bd285df]
9
- - @jpmorganchase/mosaic-types@0.1.0-beta.4
10
-
11
- ## 0.1.0-beta.3
12
-
13
- ### Patch Changes
14
-
15
- - 457df5e: switch to public package
16
- - Updated dependencies [457df5e]
17
- - @jpmorganchase/mosaic-types@0.1.0-beta.3
18
-
19
- ## 0.1.0-beta.2
20
-
21
- ### Patch Changes
22
-
23
- - e1bbbe7: Initial release of Mosaic Core file-system.
24
-
25
- Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
26
-
27
- - 4b2bc51: pipped to 0.1.0-beta.1 for publishing to NPM
28
- - Updated dependencies [e1bbbe7]
29
- - Updated dependencies [4b2bc51]
30
- - @jpmorganchase/mosaic-types@0.1.0-beta.2
31
-
32
- ## 0.1.0
33
-
34
- ### Patch Changes
35
-
36
- - e1bbbe7: Initial release of Mosaic Core file-system.
37
-
38
- Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
39
-
40
- - Updated dependencies [e1bbbe7]
41
- - Updated dependencies [bbc853c]
42
- - @jpmorganchase/mosaic-types@0.1.0