@jpmorganchase/mosaic-core 0.1.0-beta.4 → 0.1.0-beta.41

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.
Files changed (71) hide show
  1. package/dist/PluginError.d.ts +2 -0
  2. package/dist/PluginError.js +1 -4
  3. package/dist/PluginError.js.map +1 -1
  4. package/dist/PullDocs.d.ts +22 -0
  5. package/dist/PullDocs.js +54 -76
  6. package/dist/PullDocs.js.map +1 -1
  7. package/dist/Source.d.ts +28 -0
  8. package/dist/Source.js +137 -136
  9. package/dist/Source.js.map +1 -1
  10. package/dist/SourceManager.d.ts +12 -0
  11. package/dist/SourceManager.js +85 -87
  12. package/dist/SourceManager.js.map +1 -1
  13. package/dist/WorkerSubscription.d.ts +16 -0
  14. package/dist/WorkerSubscription.js +43 -80
  15. package/dist/WorkerSubscription.js.map +1 -1
  16. package/dist/filesystems/FileAccess.d.ts +31 -0
  17. package/dist/filesystems/FileAccess.js +171 -185
  18. package/dist/filesystems/FileAccess.js.map +1 -1
  19. package/dist/filesystems/ImmutableVolume.d.ts +15 -0
  20. package/dist/filesystems/ImmutableVolume.js +15 -42
  21. package/dist/filesystems/ImmutableVolume.js.map +1 -1
  22. package/dist/filesystems/MutableVolume.d.ts +26 -0
  23. package/dist/filesystems/MutableVolume.js +22 -45
  24. package/dist/filesystems/MutableVolume.js.map +1 -1
  25. package/dist/filesystems/RestrictedVolume.d.ts +24 -0
  26. package/dist/filesystems/RestrictedVolume.js +17 -43
  27. package/dist/filesystems/RestrictedVolume.js.map +1 -1
  28. package/dist/filesystems/UnionFileAccess.d.ts +23 -0
  29. package/dist/filesystems/UnionFileAccess.js +20 -54
  30. package/dist/filesystems/UnionFileAccess.js.map +1 -1
  31. package/dist/filesystems/UnionVolume.d.ts +8 -0
  32. package/dist/filesystems/UnionVolume.js +14 -33
  33. package/dist/filesystems/UnionVolume.js.map +1 -1
  34. package/dist/helpers/createConfig.d.ts +2 -0
  35. package/dist/helpers/createConfig.js +12 -13
  36. package/dist/helpers/createConfig.js.map +1 -1
  37. package/dist/helpers/parsePluginModuleDefinitions.d.ts +13 -0
  38. package/dist/helpers/parsePluginModuleDefinitions.js +24 -0
  39. package/dist/helpers/parsePluginModuleDefinitions.js.map +1 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +2 -8
  42. package/dist/index.js.map +1 -1
  43. package/dist/operators/ObservableWorker.d.ts +3 -0
  44. package/dist/operators/ObservableWorker.js +9 -9
  45. package/dist/operators/ObservableWorker.js.map +1 -1
  46. package/dist/plugin/createPluginAPI.d.ts +2 -0
  47. package/dist/plugin/createPluginAPI.js +40 -39
  48. package/dist/plugin/createPluginAPI.js.map +1 -1
  49. package/dist/plugin/index.d.ts +3 -0
  50. package/dist/plugin/index.js +79 -60
  51. package/dist/plugin/index.js.map +1 -1
  52. package/dist/plugin/loadDefinitionModules.d.ts +2 -0
  53. package/dist/plugin/loadDefinitionModules.js +28 -38
  54. package/dist/plugin/loadDefinitionModules.js.map +1 -1
  55. package/dist/plugin/pluginRunner.d.ts +5 -0
  56. package/dist/plugin/pluginRunner.js +38 -45
  57. package/dist/plugin/pluginRunner.js.map +1 -1
  58. package/dist/plugin/serialiserRunner.d.ts +5 -0
  59. package/dist/plugin/serialiserRunner.js +26 -37
  60. package/dist/plugin/serialiserRunner.js.map +1 -1
  61. package/dist/worker/Source.worker.d.ts +1 -0
  62. package/dist/worker/Source.worker.js +48 -56
  63. package/dist/worker/Source.worker.js.map +1 -1
  64. package/dist/worker/helpers/createSourceObservable.d.ts +3 -0
  65. package/dist/worker/helpers/createSourceObservable.js +48 -64
  66. package/dist/worker/helpers/createSourceObservable.js.map +1 -1
  67. package/dist/worker/helpers/exponentialBackOffRetryStrategy.d.ts +9 -0
  68. package/dist/worker/helpers/exponentialBackOffRetryStrategy.js +18 -0
  69. package/dist/worker/helpers/exponentialBackOffRetryStrategy.js.map +1 -0
  70. package/package.json +20 -7
  71. package/CHANGELOG.md +0 -42
@@ -0,0 +1,2 @@
1
+ export default class PluginError extends Error {
2
+ }
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class PluginError extends Error {
1
+ export default class PluginError extends Error {
4
2
  }
5
- exports.default = PluginError;
6
3
  //# sourceMappingURL=PluginError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PluginError.js","sourceRoot":"","sources":["../src/PluginError.ts"],"names":[],"mappings":";;AAAA,MAAqB,WAAY,SAAQ,KAAK;CAE7C;AAFD,8BAEC"}
1
+ {"version":3,"file":"PluginError.js","sourceRoot":"","sources":["../src/PluginError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,KAAK;CAAG"}
@@ -0,0 +1,22 @@
1
+ import { MosaicConfig, SourceModuleDefinition } from '@jpmorganchase/mosaic-types';
2
+ import UnionVolume from './filesystems/UnionVolume.js';
3
+ export default class PullDocs {
4
+ #private;
5
+ /**
6
+ *
7
+ * @param config.sources Sources are observables that emit pages
8
+ * @param config.plugins Plugins are modules with lifecycles methods for manipulating files and/or the virtual filesystem
9
+ * @param config.serialisers Serialisers are a form of plugin that tell PullDocs how to turn a file from/to a storable form for the filesystem - or back into a `Page` object
10
+ * @param config.ignorePages Page names to exclude from lazy loading / `$ref`s / `$tag`s / serialisers and also any plugins that expect pages as input. Example input would be "ignore-me.xml"
11
+ * @param config.pageExtensions Exts of files to treat as pages. Pages contain metadata and content, in any file format (as long as a serialiser exists to encode/decode them). They can be referenced via `$ref`s / `$tag`s and also support lazy loading
12
+ * @param config.schedule Schedule to re-pull content from remote sources
13
+ */
14
+ constructor(config: MosaicConfig);
15
+ get filesystem(): UnionVolume;
16
+ onSourceUpdate(callback: any): () => boolean;
17
+ start(): Promise<import("./Source.js").default[]>;
18
+ stop(): Promise<void>;
19
+ triggerWorkflow(name: string, filePath: string, data: any): Promise<unknown>;
20
+ addSource(sourceDefinition: SourceModuleDefinition): Promise<import("./Source.js").default>;
21
+ stopSource(id: symbol): Promise<void>;
22
+ }
package/dist/PullDocs.js CHANGED
@@ -1,39 +1,21 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
- };
16
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
17
- if (kind === "m") throw new TypeError("Private method is not writable");
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
19
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
20
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- var _PullDocs_instances, _PullDocs_sourceDefinitions, _PullDocs_sourceManager, _PullDocs_ufs, _PullDocs_vfs, _PullDocs_addSource;
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const unionfs_1 = require("unionfs");
28
- const SourceManager_1 = __importDefault(require("./SourceManager"));
1
+ import { createRequire } from 'node:module';
2
+ import { Union } from 'unionfs';
3
+ import { Volume } from 'memfs';
4
+ import { mosaicConfigSchema, validateMosaicSchema } from '@jpmorganchase/mosaic-schemas';
29
5
  // TODO:
30
6
  // Remove $ref /index resolution
31
- const MutableVolume_1 = __importDefault(require("./filesystems/MutableVolume"));
32
- const UnionFileAccess_1 = __importDefault(require("./filesystems/UnionFileAccess"));
33
- const UnionVolume_1 = __importDefault(require("./filesystems/UnionVolume"));
34
- const memfs_1 = require("memfs");
35
- const FileAccess_1 = __importDefault(require("./filesystems/FileAccess"));
36
- class PullDocs {
7
+ import FileAccess from './filesystems/FileAccess.js';
8
+ import MutableVolume from './filesystems/MutableVolume.js';
9
+ import UnionFileAccess from './filesystems/UnionFileAccess.js';
10
+ import UnionVolume from './filesystems/UnionVolume.js';
11
+ import SourceManager from './SourceManager.js';
12
+ import parsePluginModuleDefinitions from './helpers/parsePluginModuleDefinitions.js';
13
+ const require = createRequire(import.meta.url);
14
+ export default class PullDocs {
15
+ #sourceDefinitions;
16
+ #sourceManager;
17
+ #ufs = new Union();
18
+ #vfs;
37
19
  /**
38
20
  *
39
21
  * @param config.sources Sources are observables that emit pages
@@ -41,79 +23,75 @@ class PullDocs {
41
23
  * @param config.serialisers Serialisers are a form of plugin that tell PullDocs how to turn a file from/to a storable form for the filesystem - or back into a `Page` object
42
24
  * @param config.ignorePages Page names to exclude from lazy loading / `$ref`s / `$tag`s / serialisers and also any plugins that expect pages as input. Example input would be "ignore-me.xml"
43
25
  * @param config.pageExtensions Exts of files to treat as pages. Pages contain metadata and content, in any file format (as long as a serialiser exists to encode/decode them). They can be referenced via `$ref`s / `$tag`s and also support lazy loading
26
+ * @param config.schedule Schedule to re-pull content from remote sources
44
27
  */
45
28
  constructor(config) {
46
- _PullDocs_instances.add(this);
47
- _PullDocs_sourceDefinitions.set(this, void 0);
48
- _PullDocs_sourceManager.set(this, void 0);
49
- _PullDocs_ufs.set(this, new unionfs_1.Union());
50
- _PullDocs_vfs.set(this, void 0);
51
- const sharedFilesystem = new MutableVolume_1.default(new FileAccess_1.default(new memfs_1.Volume()), '*');
52
- __classPrivateFieldGet(this, _PullDocs_ufs, "f").use(sharedFilesystem);
53
- const { ignorePages = [], sources = [], plugins = [], serialisers = [], pageExtensions = ['.mdx'] } = config;
54
- __classPrivateFieldSet(this, _PullDocs_sourceDefinitions, sources, "f");
55
- __classPrivateFieldSet(this, _PullDocs_vfs, new UnionVolume_1.default(new UnionFileAccess_1.default(__classPrivateFieldGet(this, _PullDocs_ufs, "f")), '*'), "f");
56
- __classPrivateFieldSet(this, _PullDocs_sourceManager, new SourceManager_1.default(
29
+ const { ignorePages = [], sources = [], plugins = [], serialisers = [], pageExtensions = ['.mdx'], schedule } = validateMosaicSchema(mosaicConfigSchema, config, true);
30
+ const sharedFilesystem = new MutableVolume(new FileAccess(new Volume()), '*');
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ this.#ufs.use(sharedFilesystem);
33
+ this.#sourceDefinitions = sources.filter((source) => !source.disabled);
34
+ this.#vfs = new UnionVolume(new UnionFileAccess(this.#ufs), '*');
35
+ this.#sourceManager = new SourceManager(this.#vfs, sharedFilesystem,
57
36
  // Refs and aliases should be applied after all other plugins, so we add them manually with a negative priority
58
- plugins
37
+ parsePluginModuleDefinitions(plugins)
38
+ .filter((plugin) => !plugin.disabled)
59
39
  .concat({
60
- modulePath: require.resolve('@jpmorganchase/mosaic-plugins/dist/$TagPlugin'),
40
+ modulePath: require.resolve('@jpmorganchase/mosaic-plugins/$TagPlugin'),
61
41
  options: {}
62
42
  }, {
63
- modulePath: require.resolve('@jpmorganchase/mosaic-plugins/dist/$CodeModPlugin'),
43
+ modulePath: require.resolve('@jpmorganchase/mosaic-plugins/$CodeModPlugin'),
64
44
  options: {},
65
45
  // Make sure this happens as the very first plugin, so it can fix any page issues
66
46
  priority: Number.POSITIVE_INFINITY
67
47
  }, {
68
- modulePath: require.resolve('@jpmorganchase/mosaic-plugins/dist/$AliasPlugin'),
48
+ modulePath: require.resolve('@jpmorganchase/mosaic-plugins/$AliasPlugin'),
69
49
  options: {},
70
50
  priority: -1
71
51
  }, {
72
- modulePath: require.resolve('@jpmorganchase/mosaic-plugins/dist/$RefPlugin'),
52
+ modulePath: require.resolve('@jpmorganchase/mosaic-plugins/$RefPlugin'),
73
53
  options: {},
74
54
  priority: -1
75
55
  })
76
56
  .sort(({ priority: priorityA = 0 }, { priority: priorityB = 0 }) => priorityB - priorityA),
77
57
  // Auto add JSON serialiser
78
58
  serialisers.concat({
79
- modulePath: require.resolve('@jpmorganchase/mosaic-serialisers/dist/json'),
80
- filter: /\.json$/,
81
- options: {}
82
- }), pageExtensions, ignorePages, __classPrivateFieldGet(this, _PullDocs_vfs, "f"), sharedFilesystem), "f");
59
+ modulePath: require.resolve('@jpmorganchase/mosaic-serialisers/json'),
60
+ filter: /\.json$/
61
+ }), pageExtensions, ignorePages, schedule);
83
62
  }
84
63
  get filesystem() {
85
- return __classPrivateFieldGet(this, _PullDocs_vfs, "f");
64
+ return this.#vfs;
86
65
  }
87
66
  onSourceUpdate(callback) {
88
- return __classPrivateFieldGet(this, _PullDocs_sourceManager, "f").onSourceUpdate(callback);
67
+ return this.#sourceManager.onSourceUpdate(callback);
89
68
  }
90
- start() {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- return Promise.all(__classPrivateFieldGet(this, _PullDocs_sourceDefinitions, "f").map(source => __classPrivateFieldGet(this, _PullDocs_instances, "m", _PullDocs_addSource).call(this, source)));
93
- });
69
+ async start() {
70
+ return Promise.all(this.#sourceDefinitions.map(source => this.addSource(source)));
94
71
  }
95
- stop() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return __classPrivateFieldGet(this, _PullDocs_sourceManager, "f").destroyAll();
98
- });
72
+ async stop() {
73
+ return this.#sourceManager.destroyAll();
99
74
  }
100
- }
101
- exports.default = PullDocs;
102
- _PullDocs_sourceDefinitions = new WeakMap(), _PullDocs_sourceManager = new WeakMap(), _PullDocs_ufs = new WeakMap(), _PullDocs_vfs = new WeakMap(), _PullDocs_instances = new WeakSet(), _PullDocs_addSource = function _PullDocs_addSource(sourceDefinition) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- const source = yield __classPrivateFieldGet(this, _PullDocs_sourceManager, "f").addSource(sourceDefinition, {});
75
+ async triggerWorkflow(name, filePath, data) {
76
+ return this.#sourceManager.triggerWorkflow(name, filePath, data);
77
+ }
78
+ async addSource(sourceDefinition) {
79
+ const source = await this.#sourceManager.addSource(sourceDefinition, {});
105
80
  source.onError(error => {
106
- console.error(new Error(`Source '${source.id.description}' threw an exception. See below:`));
81
+ console.error(new Error(`[Mosaic] Source '${source.id.description}' threw an exception. See below:`));
107
82
  console.error(error);
108
83
  });
109
84
  source.onExit(() => {
110
- __classPrivateFieldGet(this, _PullDocs_ufs, "f").fss.splice(__classPrivateFieldGet(this, _PullDocs_ufs, "f").fss.indexOf(source.filesystem), 1);
111
- if (__classPrivateFieldGet(this, _PullDocs_ufs, "f").fss.length < 1) {
112
- console.debug("[PullDocs] All of my source have been terminated. That's sad :-(");
85
+ this.#ufs.fss.splice(this.#ufs.fss.indexOf(source.filesystem), 1);
86
+ if (this.#ufs.fss.length < 1) {
87
+ console.debug("[Mosaic] All of my source have been terminated. That's sad :-(");
113
88
  }
114
89
  });
115
- __classPrivateFieldGet(this, _PullDocs_ufs, "f").use(source.filesystem);
90
+ this.#ufs.use(source.filesystem);
116
91
  return source;
117
- });
118
- };
92
+ }
93
+ async stopSource(id) {
94
+ return this.#sourceManager.destroySource(id);
95
+ }
96
+ }
119
97
  //# sourceMappingURL=PullDocs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PullDocs.js","sourceRoot":"","sources":["../src/PullDocs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAgC;AAOhC,oEAA4C;AAE5C,QAAQ;AACR,gCAAgC;AAChC,gFAAwD;AACxD,oFAA4D;AAC5D,4EAAoD;AACpD,iCAA+B;AAC/B,0EAAkD;AAElD,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SAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;QACzE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACrB,OAAO,CAAC,KAAK,CACX,IAAI,KAAK,CAAC,oBAAoB,MAAM,CAAC,EAAE,CAAC,WAAW,kCAAkC,CAAC,CACvF,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;YAElE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC5B,OAAO,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;aACjF;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAiC,CAAC,CAAC;QAExD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import EventEmitter from 'events';
3
+ import type { IUnionVolume, IVolumeImmutable, MutableData, PluginModuleDefinition, Serialiser, SerialiserModuleDefinition, SourceModuleDefinition, SourceWorkflow } from '@jpmorganchase/mosaic-types';
4
+ import MutableVolume from './filesystems/MutableVolume.js';
5
+ export default class Source {
6
+ #private;
7
+ config: MutableData<Record<string, unknown>>;
8
+ serialiser: Serialiser;
9
+ namespace: string;
10
+ id: symbol;
11
+ filesystem: MutableVolume;
12
+ constructor({ modulePath, namespace, schedule }: SourceModuleDefinition, mergedOptions: Record<string, unknown>, pageExtensions: string[], ignorePages: string[], globalFilesystem: IUnionVolume, workflows?: SourceWorkflow[]);
13
+ onUpdate(callback: any): () => EventEmitter;
14
+ onError(callback: any): () => EventEmitter;
15
+ onStart(callback: any): () => EventEmitter;
16
+ onExit(callback: any): () => EventEmitter;
17
+ stop(): void;
18
+ /**
19
+ * Called when another source (not this one) has changed.
20
+ * This source can then ask its plugins if they also want to clear their cache in response to the other source's change.
21
+ */
22
+ requestCacheClear(updatedSourceFilesystem: IVolumeImmutable): Promise<void>;
23
+ use(plugins?: PluginModuleDefinition[], serialisers?: SerialiserModuleDefinition[]): Promise<void>;
24
+ invokeAfterUpdate(sharedFilesystem: any, globalConfig: any): Promise<void>;
25
+ start(): Promise<void>;
26
+ isOwner(filePath: string): Promise<any>;
27
+ triggerWorkflow(name: string, filePath: string, data: unknown): Promise<any>;
28
+ }
package/dist/Source.js CHANGED
@@ -1,165 +1,166 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- var _Source_instances, _Source_emitter, _Source_modulePath, _Source_plugins, _Source_serialisers, _Source_worker, _Source_globalFilesystem, _Source_pluginApi, _Source_mergedOptions, _Source_pageExtensions, _Source_ignorePages, _Source_createWorker;
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const events_1 = __importDefault(require("events"));
28
- const memfs_1 = require("memfs");
29
- const util_1 = __importDefault(require("util"));
30
- const md5_1 = __importDefault(require("md5"));
31
- const path_1 = __importDefault(require("path"));
32
- const plugin_1 = require("./plugin");
33
- const WorkerSubscription_1 = __importDefault(require("./WorkerSubscription"));
34
- const WorkerSubscription_2 = require("./WorkerSubscription");
35
- const createConfig_1 = __importDefault(require("./helpers/createConfig"));
36
- const MutableVolume_1 = __importDefault(require("./filesystems/MutableVolume"));
37
- const FileAccess_1 = __importDefault(require("./filesystems/FileAccess"));
38
- class Source {
39
- constructor({ modulePath, namespace }, mergedOptions, pageExtensions, ignorePages, globalFilesystem) {
40
- _Source_instances.add(this);
41
- _Source_emitter.set(this, new events_1.default());
42
- _Source_modulePath.set(this, void 0);
43
- _Source_plugins.set(this, []);
44
- _Source_serialisers.set(this, []);
45
- _Source_worker.set(this, void 0);
46
- _Source_globalFilesystem.set(this, void 0);
47
- _Source_pluginApi.set(this, void 0);
48
- _Source_mergedOptions.set(this, void 0);
49
- _Source_pageExtensions.set(this, void 0);
50
- _Source_ignorePages.set(this, void 0);
51
- __classPrivateFieldSet(this, _Source_modulePath, modulePath, "f");
52
- __classPrivateFieldSet(this, _Source_mergedOptions, mergedOptions, "f");
53
- __classPrivateFieldSet(this, _Source_globalFilesystem, globalFilesystem, "f");
54
- __classPrivateFieldSet(this, _Source_ignorePages, ignorePages, "f");
1
+ import EventEmitter from 'events';
2
+ import md5 from 'md5';
3
+ import { Volume } from 'memfs';
4
+ import path from 'path';
5
+ import util from 'util';
6
+ import FileAccess from './filesystems/FileAccess.js';
7
+ import MutableVolume from './filesystems/MutableVolume.js';
8
+ import createConfig from './helpers/createConfig.js';
9
+ import { bindPluginMethods, bindSerialiser } from './plugin/index.js';
10
+ import WorkerSubscription, { EVENT } from './WorkerSubscription.js';
11
+ export default class Source {
12
+ #emitter = new EventEmitter();
13
+ #modulePath;
14
+ #plugins = [];
15
+ #serialisers = [];
16
+ #worker;
17
+ #globalFilesystem;
18
+ #pluginApi;
19
+ #mergedOptions;
20
+ #pageExtensions;
21
+ #ignorePages;
22
+ #workflows = [];
23
+ #schedule;
24
+ config;
25
+ serialiser;
26
+ namespace;
27
+ id;
28
+ filesystem;
29
+ constructor({ modulePath, namespace, schedule }, mergedOptions, pageExtensions, ignorePages, globalFilesystem, workflows = []) {
30
+ this.#modulePath = modulePath;
31
+ this.#mergedOptions = mergedOptions;
32
+ this.#globalFilesystem = globalFilesystem;
33
+ this.#ignorePages = ignorePages;
34
+ this.#workflows = workflows;
35
+ this.#schedule = schedule;
55
36
  this.namespace = namespace;
56
- this.id = Symbol(`${path_1.default.basename(path_1.default.dirname(path_1.default.resolve(modulePath, '../')))}#${(0, md5_1.default)(util_1.default.inspect(__classPrivateFieldGet(this, _Source_mergedOptions, "f"), { sorted: true })).substring(0, 8)}`);
57
- this.filesystem = new MutableVolume_1.default(new FileAccess_1.default(new memfs_1.Volume()), this.namespace);
58
- __classPrivateFieldSet(this, _Source_pageExtensions, pageExtensions, "f");
37
+ this.id = Symbol(`${path.basename(path.dirname(path.resolve(modulePath, '../')))}#${md5(util.inspect(this.#mergedOptions, { sorted: true })).substring(0, 8)}`);
38
+ this.filesystem = new MutableVolume(new FileAccess(new Volume()), this.namespace);
39
+ this.#pageExtensions = pageExtensions;
59
40
  }
60
41
  onUpdate(callback) {
61
- __classPrivateFieldGet(this, _Source_emitter, "f").on(WorkerSubscription_2.EVENT.UPDATE, callback);
62
- return () => __classPrivateFieldGet(this, _Source_emitter, "f").off(WorkerSubscription_2.EVENT.UPDATE, callback);
42
+ this.#emitter.on(EVENT.UPDATE, callback);
43
+ return () => this.#emitter.off(EVENT.UPDATE, callback);
63
44
  }
64
45
  onError(callback) {
65
- __classPrivateFieldGet(this, _Source_emitter, "f").once(WorkerSubscription_2.EVENT.ERROR, callback);
66
- return () => __classPrivateFieldGet(this, _Source_emitter, "f").off(WorkerSubscription_2.EVENT.ERROR, callback);
46
+ this.#emitter.once(EVENT.ERROR, callback);
47
+ return () => this.#emitter.off(EVENT.ERROR, callback);
67
48
  }
68
49
  onStart(callback) {
69
- __classPrivateFieldGet(this, _Source_emitter, "f").once(WorkerSubscription_2.EVENT.START, callback);
70
- return () => __classPrivateFieldGet(this, _Source_emitter, "f").off(WorkerSubscription_2.EVENT.START, callback);
50
+ this.#emitter.once(EVENT.START, callback);
51
+ return () => this.#emitter.off(EVENT.START, callback);
71
52
  }
72
53
  onExit(callback) {
73
- __classPrivateFieldGet(this, _Source_emitter, "f").once(WorkerSubscription_2.EVENT.EXIT, callback);
74
- return () => __classPrivateFieldGet(this, _Source_emitter, "f").off(WorkerSubscription_2.EVENT.EXIT, callback);
54
+ this.#emitter.once(EVENT.EXIT, callback);
55
+ return () => this.#emitter.off(EVENT.EXIT, callback);
75
56
  }
76
57
  stop() {
77
- if (__classPrivateFieldGet(this, _Source_worker, "f") && __classPrivateFieldGet(this, _Source_worker, "f").closed) {
58
+ if (this.#worker && this.#worker.closed) {
78
59
  throw new Error('Cannot stop source that has not started');
79
60
  }
80
- if (__classPrivateFieldGet(this, _Source_worker, "f")) {
81
- __classPrivateFieldGet(this, _Source_worker, "f").stop();
61
+ if (this.#worker) {
62
+ this.#worker.stop();
82
63
  }
83
64
  }
84
65
  /**
85
66
  * Called when another source (not this one) has changed.
86
67
  * This source can then ask its plugins if they also want to clear their cache in response to the other source's change.
87
68
  */
88
- requestCacheClear(updatedSourceFilesystem) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const initTime = new Date().getTime();
91
- const shouldInvokeAfterUpdate = yield __classPrivateFieldGet(this, _Source_pluginApi, "f").shouldClearCache(updatedSourceFilesystem, {
92
- globalFilesystem: __classPrivateFieldGet(this, _Source_globalFilesystem, "f"),
93
- pageExtensions: __classPrivateFieldGet(this, _Source_pageExtensions, "f"),
94
- ignorePages: __classPrivateFieldGet(this, _Source_ignorePages, "f"),
95
- serialiser: this.serialiser,
96
- config: this.config.asReadOnly()
97
- });
98
- const timeTaken = new Date().getTime() - initTime;
99
- if (timeTaken > 400) {
100
- console.warn(`Lifecycle phase 'shouldClearCache' for source '${this.id.description}' took ${timeTaken}ms to complete. The method is async, so this may not be an accurate measurement of execution time, but consider optimising this method if it is performing intensive operations.`);
101
- }
102
- if (shouldInvokeAfterUpdate === true) {
103
- this.filesystem.clearCache();
104
- }
69
+ async requestCacheClear(updatedSourceFilesystem) {
70
+ const initTime = new Date().getTime();
71
+ const shouldInvokeAfterUpdate = await this.#pluginApi.shouldClearCache(updatedSourceFilesystem, {
72
+ globalFilesystem: this.#globalFilesystem,
73
+ pageExtensions: this.#pageExtensions,
74
+ ignorePages: this.#ignorePages,
75
+ serialiser: this.serialiser,
76
+ config: this.config.asReadOnly()
105
77
  });
78
+ const timeTaken = new Date().getTime() - initTime;
79
+ if (timeTaken > 400) {
80
+ console.warn(`Lifecycle phase 'shouldClearCache' for source '${this.id.description}' took ${timeTaken}ms to complete. The method is async, so this may not be an accurate measurement of execution time, but consider optimising this method if it is performing intensive operations.`);
81
+ }
82
+ if (shouldInvokeAfterUpdate === true) {
83
+ this.filesystem.clearCache();
84
+ }
85
+ }
86
+ async use(plugins = [], serialisers = []) {
87
+ if (this.namespace.startsWith('preview-')) {
88
+ console.log('[Mosaic] Preview source detected, filtering plugins to use.');
89
+ this.#plugins.push(...plugins.filter(plugin => !plugin.previewDisabled));
90
+ }
91
+ else {
92
+ this.#plugins.push(...plugins);
93
+ }
94
+ this.#serialisers.push(...serialisers);
106
95
  }
107
- use(plugins = [], serialisers = []) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- __classPrivateFieldGet(this, _Source_plugins, "f").push(...plugins);
110
- __classPrivateFieldGet(this, _Source_serialisers, "f").push(...serialisers);
96
+ async invokeAfterUpdate(sharedFilesystem, globalConfig) {
97
+ const initTime = new Date().getTime();
98
+ await this.#pluginApi.afterUpdate(this.filesystem.asRestricted(), {
99
+ globalFilesystem: this.#globalFilesystem,
100
+ sharedFilesystem,
101
+ globalConfig,
102
+ pageExtensions: this.#pageExtensions,
103
+ ignorePages: this.#ignorePages,
104
+ serialiser: this.serialiser,
105
+ config: this.config.asReadOnly()
111
106
  });
107
+ const timeTaken = new Date().getTime() - initTime;
108
+ if (timeTaken > 800) {
109
+ console.warn(`Lifecycle phase 'afterUpdate' for source '${this.id.description}' took ${timeTaken / 1000}s to complete. The method is async, so this may not be an accurate measurement of execution time, but consider optimising this method if it is performing intensive operations.`);
110
+ }
112
111
  }
113
- invokeAfterUpdate(sharedFilesystem, globalConfig) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- const initTime = new Date().getTime();
116
- yield __classPrivateFieldGet(this, _Source_pluginApi, "f").afterUpdate(this.filesystem.asRestricted(), {
117
- globalFilesystem: __classPrivateFieldGet(this, _Source_globalFilesystem, "f"),
118
- sharedFilesystem,
119
- globalConfig,
120
- pageExtensions: __classPrivateFieldGet(this, _Source_pageExtensions, "f"),
121
- ignorePages: __classPrivateFieldGet(this, _Source_ignorePages, "f"),
122
- serialiser: this.serialiser,
123
- config: this.config.asReadOnly()
124
- });
125
- const timeTaken = new Date().getTime() - initTime;
126
- if (timeTaken > 800) {
127
- console.warn(`Lifecycle phase 'afterUpdate' for source '${this.id.description}' took ${timeTaken / 1000}s to complete. The method is async, so this may not be an accurate measurement of execution time, but consider optimising this method if it is performing intensive operations.`);
128
- }
112
+ #createWorker() {
113
+ const worker = new WorkerSubscription({
114
+ modulePath: this.#modulePath,
115
+ name: this.id.description,
116
+ options: this.#mergedOptions,
117
+ namespace: this.namespace,
118
+ pageExtensions: this.#pageExtensions,
119
+ ignorePages: this.#ignorePages,
120
+ plugins: this.#plugins,
121
+ serialisers: this.#serialisers,
122
+ schedule: this.#schedule
129
123
  });
124
+ worker.once(EVENT.ERROR, error => this.#emitter.emit(EVENT.ERROR, error));
125
+ worker.once(EVENT.EXIT, () => {
126
+ this.#emitter.emit(EVENT.EXIT);
127
+ this.#emitter.removeAllListeners();
128
+ // this.filesystem.reset();
129
+ this.filesystem = null;
130
+ });
131
+ worker.once(EVENT.START, () => this.#emitter.emit(EVENT.START));
132
+ return worker;
130
133
  }
131
- start() {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- this.serialiser = yield (0, plugin_1.bindSerialiser)(__classPrivateFieldGet(this, _Source_serialisers, "f"));
134
- __classPrivateFieldSet(this, _Source_pluginApi, yield (0, plugin_1.bindPluginMethods)(__classPrivateFieldGet(this, _Source_plugins, "f")), "f");
135
- __classPrivateFieldSet(this, _Source_worker, __classPrivateFieldGet(this, _Source_instances, "m", _Source_createWorker).call(this), "f");
136
- __classPrivateFieldGet(this, _Source_worker, "f").on(WorkerSubscription_2.EVENT.UPDATE, ({ data: { pages, symlinks, data } }) => __awaiter(this, void 0, void 0, function* () {
137
- this.config = (0, createConfig_1.default)(data);
138
- __classPrivateFieldGet(this, _Source_emitter, "f").emit(WorkerSubscription_2.EVENT.UPDATE, { pages, symlinks, data });
139
- }));
134
+ async start() {
135
+ this.serialiser = await bindSerialiser(this.#serialisers);
136
+ this.#pluginApi = await bindPluginMethods(this.#plugins);
137
+ this.#worker = this.#createWorker();
138
+ this.#worker.on(EVENT.UPDATE, async ({ data: { pages, symlinks, data } }) => {
139
+ this.config = createConfig(data);
140
+ this.#emitter.emit(EVENT.UPDATE, { pages, symlinks, data });
140
141
  });
141
142
  }
143
+ async isOwner(filePath) {
144
+ const isFileInSource = await this.filesystem.promises.exists(filePath);
145
+ return isFileInSource;
146
+ }
147
+ async triggerWorkflow(name, filePath, data) {
148
+ const foundWorkflows = this.#workflows.filter(workflow => workflow.name === name);
149
+ if (foundWorkflows.length === 0) {
150
+ return {
151
+ error: `[Mosaic] Workflow ${name} not found for ${this.id.description.toString()}`
152
+ };
153
+ }
154
+ if (foundWorkflows.length > 1) {
155
+ return {
156
+ error: `[Mosaic] Multiple workflows with "${name}" found for ${this.id.description.toString()}`
157
+ };
158
+ }
159
+ const triggeredWorkflow = foundWorkflows[0];
160
+ if (triggeredWorkflow) {
161
+ return triggeredWorkflow.action(this.#mergedOptions, triggeredWorkflow.options, filePath, data);
162
+ }
163
+ return false;
164
+ }
142
165
  }
143
- exports.default = Source;
144
- _Source_emitter = new WeakMap(), _Source_modulePath = new WeakMap(), _Source_plugins = new WeakMap(), _Source_serialisers = new WeakMap(), _Source_worker = new WeakMap(), _Source_globalFilesystem = new WeakMap(), _Source_pluginApi = new WeakMap(), _Source_mergedOptions = new WeakMap(), _Source_pageExtensions = new WeakMap(), _Source_ignorePages = new WeakMap(), _Source_instances = new WeakSet(), _Source_createWorker = function _Source_createWorker() {
145
- const worker = new WorkerSubscription_1.default({
146
- modulePath: __classPrivateFieldGet(this, _Source_modulePath, "f"),
147
- name: this.id.description,
148
- options: __classPrivateFieldGet(this, _Source_mergedOptions, "f"),
149
- namespace: this.namespace,
150
- pageExtensions: __classPrivateFieldGet(this, _Source_pageExtensions, "f"),
151
- ignorePages: __classPrivateFieldGet(this, _Source_ignorePages, "f"),
152
- plugins: __classPrivateFieldGet(this, _Source_plugins, "f"),
153
- serialisers: __classPrivateFieldGet(this, _Source_serialisers, "f")
154
- });
155
- worker.once(WorkerSubscription_2.EVENT.ERROR, error => __classPrivateFieldGet(this, _Source_emitter, "f").emit(WorkerSubscription_2.EVENT.ERROR, error));
156
- worker.once(WorkerSubscription_2.EVENT.EXIT, () => {
157
- __classPrivateFieldGet(this, _Source_emitter, "f").emit(WorkerSubscription_2.EVENT.EXIT);
158
- __classPrivateFieldGet(this, _Source_emitter, "f").removeAllListeners();
159
- //this.filesystem.reset();
160
- this.filesystem = null;
161
- });
162
- worker.once(WorkerSubscription_2.EVENT.START, () => __classPrivateFieldGet(this, _Source_emitter, "f").emit(WorkerSubscription_2.EVENT.START));
163
- return worker;
164
- };
165
166
  //# sourceMappingURL=Source.js.map