@jpmorganchase/mosaic-types 0.1.0-beta.3 → 0.1.0-beta.30

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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * [[`ContentProps`]] specifies the page source/content
3
+ */
4
+ export interface ContentProps {
5
+ /** Page source, which will be page type specific */
6
+ source?: Record<string, unknown>;
7
+ /** Page type */
8
+ type?: string;
9
+ /** Raw page content, includes markdown and frontmatter */
10
+ raw?: string;
11
+ }
@@ -0,0 +1,40 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { Options, Pattern, Entry } from 'fast-glob';
3
+ import type { DirectoryJSON, IRealpathOptions, IMkdirOptions, IReaddirOptions, IStatOptions, TData, TMode, TDataOut, Dirent, Stats, TStatNumber } from 'memfs';
4
+ import type { PathLike, symlink } from 'fs';
5
+ import type { Page } from './Page.js';
6
+ /**
7
+ * This is the core underlying filesystem, which directly interfaces with a memfs Volume to mutate the filesystem
8
+ */
9
+ export interface IFileAccess {
10
+ glob(pattern: Pattern, options?: Omit<Options, 'absolute' | 'fs'>): Promise<string[] | Entry[]>;
11
+ mkdir(dir: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
12
+ readdir(dir: PathLike, options?: string | IReaddirOptions): Promise<TDataOut[] | Dirent[]>;
13
+ readFile(file: PathLike): Promise<TDataOut>;
14
+ realpath(target: string, options?: string | IRealpathOptions): Promise<TDataOut>;
15
+ stat(file: PathLike, options?: IStatOptions): Promise<Stats<TStatNumber>>;
16
+ unlink(target: PathLike): Promise<void>;
17
+ symlink(target: PathLike, alias: PathLike, type?: symlink.Type): Promise<void>;
18
+ writeFile(file: PathLike, data: TData): Promise<void>;
19
+ toJSON(): DirectoryJSON;
20
+ fromJSON(json: DirectoryJSON): void;
21
+ exists(file: PathLike): Promise<boolean>;
22
+ $$reset(): void;
23
+ $$freeze(): void;
24
+ readonly $$frozen: boolean;
25
+ $$unfreeze(): void;
26
+ $$clearCache(): void;
27
+ $$symlinksFromJSON(page: {
28
+ [key: string]: {
29
+ target: string;
30
+ type: string;
31
+ }[];
32
+ }): Promise<void>;
33
+ symlinksToJSON(): {
34
+ [key: string]: {
35
+ target: string;
36
+ type: string;
37
+ }[];
38
+ };
39
+ $$addReadFileHook(hook: (result: Page, filepath: PathLike) => Promise<Page>): void;
40
+ }
package/dist/Meta.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare type Meta<AdditionalProps> = {
2
+ title?: string;
3
+ route: string;
4
+ lastModified: Date;
5
+ } & Record<string, unknown> & AdditionalProps;
package/dist/Mode.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Mosaic mode dictates how content is loaded
3
+ *
4
+ * `active`
5
+ * In this mode, content is pulled from configured data sources and updates in real-time.
6
+ * After content is updated, Mosaic plugins create an enhanced, in-memory file object, representing the content
7
+ *
8
+ * `snapshot-file`
9
+ * In this mode, previously created snapshot files are loaded from a local directory.
10
+ *
11
+ * `snapshot-s3`
12
+ * In this mode, previously created snapshot files are loaded from an S3 bucket.
13
+ *
14
+ * (A snapshot is an immutable/persisted copy of `active` content, created separately)
15
+ */
16
+ export declare type MosaicMode = 'active' | 'snapshot-file' | 'snapshot-s3';
@@ -0,0 +1,74 @@
1
+ export interface Aliases {
2
+ [key: string]: Set<string>;
3
+ }
4
+ export interface FSRef {
5
+ $$path?: string | string[];
6
+ $$value?: string;
7
+ }
8
+ export interface GlobalRefs {
9
+ [key: string]: FSRef;
10
+ }
11
+ export interface ScopedRefs {
12
+ [key: string]: FSRef;
13
+ }
14
+ export interface BaseData {
15
+ refs?: ScopedRefs | [];
16
+ globalRefs?: GlobalRefs | [];
17
+ aliases?: Aliases | [];
18
+ }
19
+ export declare type MutableData<T = {}> = ImmutableData<T> & {
20
+ /**
21
+ * Set arbitrary data onto the config object. This value will persist across plugins and
22
+ * also be sent to the parent process when it executes plugins there as well.
23
+ * Values can be retrieved from `data`.
24
+ * This data is one-way, it can only be set/mutated in the child process lifecycle stages
25
+ * This will be reset everytime the relevant source receives new pages
26
+ * @param data Data to MERGE into the existing blob
27
+ */
28
+ setData(data: Partial<T>, overwrite?: boolean): void;
29
+ /**
30
+ * Helper function for declaring new aliases that will be applied by the AliasPlugin.
31
+ * Values can be retrieved from `data.aliases`
32
+ * This will be reset everytime the relevant source receives new pages
33
+ * @param fullPath The file/fullPath the alias will point to
34
+ * @param aliases Array of aliases to use when pointing to this page
35
+ */
36
+ setAliases(targetPath: string, aliases: string[]): void;
37
+ /**
38
+ * Helper function for declaring new tags (which are basically aliases to /.tags) that will be applied by the AliasPlugin.
39
+ * Values can be retrieved from `data.aliases`
40
+ * This will be reset everytime the relevant source receives new pages
41
+ * @param fullPath The file/fullPath the alias will point to
42
+ * @param tags Array of tag names to use when pointing to this page
43
+ */
44
+ setTags(targetPath: string, tags: string[]): void;
45
+ /**
46
+ * Helper function for declaring new refs that will be applied by the RefPlugin
47
+ * This will be reset everytime the relevant source receives new pages
48
+ * Values can be retrieved from `data.refs`
49
+ * @param targetPath The file/fullPath to write the ref to
50
+ * @param targetPropPath The path to the property where the ref will be applied
51
+ * @param refValue The value of the ref (can be a wildcard)
52
+ */
53
+ setRef(targetFilepath: string, targetPropPath: string | string[], refValue: string): void;
54
+ /**
55
+ * Same as `setRef`, but do not pre-resolve this ref - wait until the file is read and use the global filesystem for it
56
+ * @param targetPath The file/fullPath to write the ref to
57
+ * @param targetPropPath The path to the property where the ref will be applied
58
+ * @param refValue The value of the ref (can be a wildcard)
59
+ */
60
+ setGlobalRef(targetFilepath: string, targetPropPath: string | string[], refValue: string): void;
61
+ /**
62
+ * This object, but without the mutation methods like `setAliases`, `setData` etc
63
+ */
64
+ asReadOnly(): ImmutableData<T>;
65
+ };
66
+ export declare type ImmutableData<T = {}> = {
67
+ readonly data: Readonly<T & {
68
+ readonly refs: string[];
69
+ readonly aliases: Set<{
70
+ $$path: string[];
71
+ $$value: string;
72
+ }>;
73
+ }>;
74
+ };
package/dist/Page.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `Page` is a type, which at a minimum has a `fullPath`, but can also contain metadata and `content`
3
+ */
4
+ export declare type Page = {
5
+ fullPath: string;
6
+ title?: string;
7
+ /**
8
+ * Friendly fullPaths are the shortest possible paths that will point to a page.
9
+ * They are useful for creating more user-friendly links on pages, rather than using a full filesystem path.
10
+ * They originally start as the same as `fullPath`, but can be modified by plugins whenever they make a change to how a page resolves.
11
+ * e.g. The `PagesWithoutFileExtPlugin` modifies the friendly fullPath after it creates aliases for every page (to allow
12
+ * them to be referenced without a file extension). Another example would be a plugin that allows `/index` to be
13
+ * automatically added if a fullPath points to a directory -- the `route` could then be modified by that
14
+ * plugin to remove `/index`
15
+ */
16
+ route?: string;
17
+ lastModified?: Date;
18
+ type?: string;
19
+ content?: string;
20
+ };
@@ -0,0 +1,113 @@
1
+ import type { IUnionVolume, IVolumeImmutable, IVolumeMutable, IVolumePartiallyMutable } from './Volume.js';
2
+ import type { PluginModuleDefinition } from './index.js';
3
+ import type { Serialiser } from './Serialiser.js';
4
+ import type { Page } from './Page.js';
5
+ import type { MutableData, ImmutableData } from './MutableData.js';
6
+ export declare type LoadedPlugin = Partial<Plugin<Page>> & PluginModuleDefinition;
7
+ export declare type LifecycleMethod = keyof Plugin<Page>;
8
+ /**
9
+ * Plugins are lifecycle-based hooks that are called on every source at different stages.
10
+ * Consumers will never need to invoke a lifecycle method; but for technical clarity - when a lifecycle method is called,
11
+ * it will trigger `pluginRunner` which executes it on every source automatically.
12
+ */
13
+ export declare type Plugin<TPage extends Page = Page, TOptions = Record<string, unknown>, ConfigData = Record<string, unknown>, GlobalConfigData = ConfigData> = {
14
+ /**
15
+ * Plugin lifecycle method that triggers inside child processes.
16
+ * The first lifecycle hook to trigger after receiving pages from a source. The pages can safely be mutated and will be reflected in the final
17
+ * filesystem that gets generated.
18
+ * @param pages Array of pages from the source
19
+ * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
20
+ * @param param.config A mutable object for sharing data with other lifecycle phases of all plugins for this source (including in the main thread) in this plugin
21
+ * @param options The options passed in when declaring the plugin
22
+ * @returns {Promise<Page[]>} Must re-return an array of `Page` objects, modified or not
23
+ */
24
+ $afterSource?: (pages: TPage[], helpers: {
25
+ serialiser: Serialiser<TPage>;
26
+ config: MutableData<ConfigData>;
27
+ pageExtensions: string[];
28
+ ignorePages: string[];
29
+ }, options?: TOptions) => Promise<Array<TPage>>;
30
+ /**
31
+ * Plugin lifecycle method that triggers inside child processes.
32
+ * Calls after a filesystem has been built up from the source pages.
33
+ * @param mutableFilesystem Mutable virtual filesystem instance with all of this source's pages inside (and symlinks applied)
34
+ * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
35
+ * @param param.config A mutable object for sharing data with other lifecycle phases of all plugins for this source (including in the main thread) in this plugin
36
+ * @param options The options passed in when declaring the plugin
37
+ * @returns {void} No return expected
38
+ */
39
+ $beforeSend?: (mutableFilesystem: IVolumePartiallyMutable, helpers: {
40
+ serialiser: Serialiser<TPage>;
41
+ pageExtensions: string[];
42
+ ignorePages: string[];
43
+ config: MutableData<ConfigData>;
44
+ }, options?: TOptions) => Promise<void>;
45
+ /**
46
+ * Plugin lifecycle method that triggers inside the main process.
47
+ * Calls after the filesystem and symlinks have been reconstructed due to a change to the current source. This happens in the main thread.
48
+ * Pages will NOT be cached when read at this stage, to allow for reading content and writing a new copy of it without the cached version taking effect.
49
+ * This method is safe to use with lazy loading, as the filesystem should return the full page when read.
50
+ * NOTE: Plugin methods that trigger inside the parent process should be async and highly optimised to avoid holding up the main thread.
51
+ * You should also be mindful of race conditions when reading / writing to the global filesystem from this method - as other plugins may
52
+ * also have a read copy of the same file and it could end up out of sync.
53
+ * @param mutableFilesystem Mutable filesystem instance with all of this source's pages inside (and symlinks re-applied)
54
+ * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
55
+ * @param param.config An immutable object for reading data from other lifecycle phases of all plugins for this source in the child process for this plugin. Shared only with this source.
56
+ * @param param.globalConfig An immutable object for reading data from other lifecycle phases of all plugins. Shared across all sources.
57
+ * @param param.sharedFilesystem Mutable filesystem instance independent of any sources. Useful for global pages, like sitemaps
58
+ * @param param.globalFilesystem Immutable union filesystem instance with all source's pages (and symlinks applied)
59
+ * @param options The options passed in when declaring the plugin
60
+ * @returns {void} No return expected
61
+ */
62
+ afterUpdate?: (mutableFilesystem: IVolumePartiallyMutable, helpers: {
63
+ serialiser: Serialiser<TPage>;
64
+ config: ImmutableData<ConfigData>;
65
+ globalFilesystem: IUnionVolume;
66
+ sharedFilesystem: IVolumeMutable;
67
+ globalConfig: ImmutableData<GlobalConfigData>;
68
+ pageExtensions: string[];
69
+ ignorePages: string[];
70
+ }, options?: TOptions) => Promise<void>;
71
+ /**
72
+ * Plugin lifecycle method that triggers inside the main process everytime ANY source emits new pages.
73
+ * This method should return a boolean that will indicate if this source should clear page caches.
74
+ * This method calls whenever another source (not this one) has changed.
75
+ * Returning `undefined`, false or no value, will result in the cache to be retained
76
+ * @param updatedSourceFilesystem Immutable filesystem for the source that changed
77
+ * @param param.config An immutable object for reading data from other lifecycle phases of all plugins for this source in the child process for this plugin
78
+ * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
79
+ * @param param.globalFilesystem Immutable union filesystem instance with all source's pages (and symlinks applied)
80
+ * @param options The options passed in when declaring the plugin
81
+ * @returns {Promise<boolean>} A boolean indicating whether to clear the cache for this source
82
+ */
83
+ shouldClearCache?: (updatedSourceFilesystem: IVolumeImmutable, helpers: {
84
+ serialiser: Serialiser<TPage>;
85
+ config: ImmutableData<ConfigData>;
86
+ globalFilesystem: IUnionVolume;
87
+ pageExtensions: string[];
88
+ ignorePages: string[];
89
+ }, options?: TOptions) => Promise<boolean>;
90
+ /**
91
+ * Plugin lifecycle method that triggers inside the main process whenever a request to save content is made.
92
+ * This method should return the result of the save
93
+ * Returning `undefined`, false or no value, will result in the plugin runner discarding the result.
94
+ * @param path the route of the content being edited.
95
+ * @param data the data from the the request
96
+ * @param sourceOptions options used to create the source that is running the plugin
97
+ * @param mutableFilesystem Mutable filesystem instance with all of this source's pages inside (and symlinks re-applied)
98
+ * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
99
+ * @param param.config An immutable object for reading data from other lifecycle phases of all plugins for this source in the child process for this plugin. Shared only with this source.
100
+ * @param param.sharedFilesystem Mutable filesystem instance independent of any sources. Useful for global pages, like sitemaps
101
+ * @param param.namespace The namespace of the source running the plugin
102
+ * @param options The options passed in when declaring the plugin
103
+ * @returns {Promise<unknown>} The result of the save
104
+ */
105
+ saveContent?(path: string, data: unknown, sourceOptions: unknown, helpers: {
106
+ serialiser: Serialiser<TPage>;
107
+ config: ImmutableData<ConfigData>;
108
+ sharedFilesystem: IVolumeMutable;
109
+ pageExtensions: string[];
110
+ ignorePages: string[];
111
+ namespace: string;
112
+ }, options?: TOptions): Promise<unknown>;
113
+ };
@@ -0,0 +1,26 @@
1
+ import type { TDataOut } from 'memfs';
2
+ import type { SerialiserModuleDefinition } from './index.js';
3
+ import type { Page } from './Page.js';
4
+ /**
5
+ * Serialisers are a form of plugin that tells Mosaic how to turn a file from/to a storable form for the filesystem
6
+ * or a `Page` object.
7
+ * For technical clarity - when a parser method is called, it will trigger `parserRunner` which checks the `fullPath` against
8
+ * the `test` option that was passed in the Mosaic config file, to find a suitable parser.
9
+ */
10
+ export declare type Serialiser<TPage extends Page = Page> = {
11
+ /**
12
+ * Method to turn a raw page (e.g. an MDX file) into a `Page` object
13
+ * @param fullPath Route on virtual disk (should be full fullPath, not an alias)
14
+ * @param page Page in string or buffer form (i.e. an MDX page with frontmatter or a JSON file as a string)
15
+ * @returns Page object in the `Page` format
16
+ */
17
+ deserialise: (fullPath: string, page: TDataOut) => Promise<TPage>;
18
+ /**
19
+ * Method to load a raw page from disk (e.g. an MDX file) and return into a `Page` object
20
+ * @param fullPath Route on virtual disk (should be full fullPath, not an alias)
21
+ * @param page Page in `Page` form
22
+ * @returns Page content
23
+ */
24
+ serialise: (fullPath: string, page: TPage) => Promise<TDataOut>;
25
+ };
26
+ export declare type LoadedSerialiser = Serialiser & SerialiserModuleDefinition;
@@ -0,0 +1,39 @@
1
+ export declare type JWT = {
2
+ exp: number;
3
+ UserID?: string;
4
+ JPMCIdentifier?: string;
5
+ UID?: string;
6
+ EmployeeCorporateID?: string;
7
+ CostCenter?: string;
8
+ Country?: string;
9
+ CountryCode?: string;
10
+ Department?: string;
11
+ DisplayName?: string;
12
+ Email?: string;
13
+ EmployeeType?: string;
14
+ FirstName?: string;
15
+ LastName?: string;
16
+ LOB?: string;
17
+ LocationCode?: string;
18
+ };
19
+ export declare type Session = {
20
+ isLoggedIn: boolean;
21
+ accessToken?: string;
22
+ isCypressSession?: boolean;
23
+ expires?: number;
24
+ user?: {
25
+ avatarUrl: string;
26
+ sid: string;
27
+ country?: string;
28
+ countryCode?: string;
29
+ costCenter?: string;
30
+ department?: string;
31
+ displayName?: string;
32
+ email?: string;
33
+ employeeType?: string;
34
+ firstName?: string;
35
+ lastName?: string;
36
+ lob?: string;
37
+ locationCode?: string;
38
+ };
39
+ };
@@ -0,0 +1,9 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { Serialiser } from './Serialiser.js';
3
+ import type { Page } from './Page.js';
4
+ export declare type Source<Options = {}> = {
5
+ create(options: Options, { serialiser, pageExtensions }: {
6
+ pageExtensions: string[];
7
+ serialiser: Serialiser;
8
+ }): Observable<Page[]>;
9
+ };
@@ -0,0 +1,6 @@
1
+ export declare type SourceWorkflowAction<TSourceOptions, TOptions> = (sourceOptions: TSourceOptions, workflowOptions: TOptions, ...args: any[]) => Promise<unknown>;
2
+ export declare type SourceWorkflow<TSourceOptions = unknown, TOptions = unknown> = {
3
+ name: string;
4
+ options?: TOptions;
5
+ action: SourceWorkflowAction<TSourceOptions, TOptions>;
6
+ };
@@ -0,0 +1,125 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { DirectoryJSON, IRealpathOptions, IMkdirOptions, IReaddirOptions, IStatOptions, TData, TMode, TDataOut, Dirent, Stats, TStatNumber } from 'memfs';
3
+ import type { PathLike, symlink } from 'fs';
4
+ import type { Options, Pattern, Entry } from 'fast-glob';
5
+ /**
6
+ * Volumes are lightweight decorators which wrap `FileAccess` and limit access to the underlying API for different use-cases
7
+ * Examples include disallowing mutation or allowing underlying functions like resetting
8
+ */
9
+ export interface IVolume {
10
+ namespace: string;
11
+ reset?(): void;
12
+ toJSON(): DirectoryJSON;
13
+ symlinksToJSON(): {
14
+ [key: string]: {
15
+ target: string;
16
+ type: string;
17
+ }[];
18
+ };
19
+ fromJSON?(json: DirectoryJSON): void;
20
+ promises: {
21
+ exists(file: PathLike): Promise<boolean>;
22
+ glob(pattern: Pattern, options?: Options): Promise<string[] | Entry[]>;
23
+ mkdir(dir: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
24
+ readdir(dir: PathLike, options?: string | IReaddirOptions): Promise<TDataOut[] | Dirent[]>;
25
+ readFile(file: PathLike): Promise<TDataOut>;
26
+ realpath(target: string, options?: string | IRealpathOptions): Promise<TDataOut>;
27
+ stat(file: PathLike, options?: IStatOptions): Promise<Stats<TStatNumber>>;
28
+ symlink(target: PathLike, alias: PathLike, type?: symlink.Type): Promise<void>;
29
+ unlink(target: PathLike): Promise<void>;
30
+ writeFile(file: PathLike, data: TData): Promise<void>;
31
+ };
32
+ }
33
+ export interface IVolumePartiallyMutable extends Omit<IVolume, 'reset' | 'fromJSON'> {
34
+ /**
35
+ * Functions that will be called after a page is read from the filesystem for the first time (since last cache clear).
36
+ * The value returned from this hook will *replace* the contents of the read file.
37
+ * @param hook Any function that invokes an `afterRead` plugin
38
+ * @returns Promise<Page>
39
+ */
40
+ __internal_do_not_use_addReadFileHook(hook: (filepath: PathLike, fileData: TDataOut) => Promise<TDataOut>): void;
41
+ }
42
+ export interface IUnionVolume extends Omit<IVolumeImmutable, 'promises'> {
43
+ promises: Pick<IVolumeImmutable, 'promises'> & {
44
+ /**
45
+ * Reads a file
46
+ * @param file Path
47
+ * @returns Promise<TDataOut>
48
+ */
49
+ readFile(file: PathLike): Promise<TDataOut>;
50
+ readFile(file: PathLike, options?: {
51
+ includeConflicts?: false;
52
+ }): Promise<TDataOut>;
53
+ /**
54
+ * Reads 1 or more files (if multiple files exist at the same location within the union filesystem)
55
+ * @param file Path
56
+ * @param options.includeConflicts If multiple files exist at the same location in the filesystem, return them all as an array
57
+ * @returns Promise<TDataOut[]>
58
+ */
59
+ readFile(file: PathLike, options: {
60
+ includeConflicts: true;
61
+ }): Promise<TDataOut[]>;
62
+ };
63
+ /**
64
+ * Scopes a filesystem to specific namespaces
65
+ * @param {string[]} namespaces Array of namespaces to limit this filesystem to
66
+ * @returns A new immutable union filesystem
67
+ */
68
+ scope(namespaces: string[]): IUnionVolume;
69
+ }
70
+ export interface IVolumeMutable extends IVolume {
71
+ /**
72
+ * Functions that will be called after a page is read from the filesystem for the first time (since last cache clear).
73
+ * The value returned from this hook will *replace* the contents of the read file.
74
+ * @param hook Any function that invokes an `afterRead` plugin
75
+ * @returns Promise<Page>
76
+ */
77
+ __internal_do_not_use_addReadFileHook(hook: (filepath: PathLike, fileData: TDataOut) => Promise<TDataOut>): void;
78
+ /**
79
+ * Restricted filesystems can be written to, but cannot be frozen, updated or reset
80
+ */
81
+ asRestricted(): IVolumePartiallyMutable;
82
+ /**
83
+ * ReadOnly filesystems cannot be mutated in any way, including freezing, updating or reseting
84
+ */
85
+ asReadOnly(): IVolumeImmutable;
86
+ /**
87
+ * Clears the filesystem's internal page cache - used when the cache may be outdated due to a source emiting new data or a dependency changing.
88
+ */
89
+ clearCache(): void;
90
+ /**
91
+ * Re-enables mutations on the underlying `FileAccess`.
92
+ */
93
+ unfreeze(): void;
94
+ /**
95
+ * Freezes an object, preventing all mutations on the underlying `FileAccess` object
96
+ * Freezing a filesystem indicates that the mutation period has ended and the file system can no longer be modified.
97
+ * When a filesystem is unfrozen, it is considered to be in flux, so may change as more plugins are called.
98
+ * When a filesystem is frozen, it is considered to be stable and ready to begin serving finalised versions of files.
99
+ */
100
+ freeze(): void;
101
+ /**
102
+ * Is this filesystem frozen/mutable?
103
+ * @returns {boolean}
104
+ */
105
+ readonly frozen: boolean;
106
+ /**
107
+ * Appends content to the filesystem
108
+ * @param json A JSON blob in the form of {[fullPath]: "{fullPath: '', content: ''}"}
109
+ */
110
+ fromJSON(json: DirectoryJSON): void;
111
+ symlinksFromJSON(json: {
112
+ [key: string]: {
113
+ target: string;
114
+ type: string;
115
+ }[];
116
+ }): Promise<void>;
117
+ /**
118
+ * Completely resets the filesystem.
119
+ * This includes clearing page cache, erasing filesystem data, clearing symlinks etc
120
+ */
121
+ reset(): void;
122
+ }
123
+ export interface IVolumeImmutable extends Omit<IVolumePartiallyMutable, 'fromJSON' | 'reset' | 'promises' | '__internal_do_not_use_addReadFileHook'> {
124
+ promises: Omit<IVolume['promises'], 'writeFile' | 'symlink' | 'mkdir' | 'unlink' | 'rmdir' | 'rm' | 'rename'>;
125
+ }
@@ -0,0 +1,13 @@
1
+ import type { SerialiserModuleDefinition, PluginModuleDefinition, SourceModuleDefinition } from './index.js';
2
+ export declare type WorkerData<Options = {}> = {
3
+ options: Options & Pick<PluginModuleDefinition, 'options'> & Pick<SourceModuleDefinition, 'options'> & {
4
+ pageExtensions: string[];
5
+ };
6
+ name: string;
7
+ namespace: string;
8
+ pageExtensions: string[];
9
+ ignorePages: string[];
10
+ plugins: PluginModuleDefinition[];
11
+ serialisers: SerialiserModuleDefinition[];
12
+ modulePath: string;
13
+ };
@@ -0,0 +1,14 @@
1
+ import type { SerialiserModuleDefinition, MosaicConfig, PluginModuleDefinition, SourceModuleDefinition, SourceWorkflow } from '@jpmorganchase/mosaic-schemas';
2
+ export * from './Content.js';
3
+ export * from './IFileAccess.js';
4
+ export * from './Meta.js';
5
+ export * from './MutableData.js';
6
+ export * from './Page.js';
7
+ export * from './Plugin.js';
8
+ export * from './Serialiser.js';
9
+ export * from './Source.js';
10
+ export * from './Volume.js';
11
+ export * from './WorkerData.js';
12
+ export * from './Mode.js';
13
+ export * from './Session.js';
14
+ export { SerialiserModuleDefinition, MosaicConfig, PluginModuleDefinition, SourceModuleDefinition, SourceWorkflow };
package/package.json CHANGED
@@ -1,22 +1,36 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-types",
3
- "version": "0.1.0-beta.3",
4
- "author": "",
5
- "description": "",
3
+ "version": "0.1.0-beta.30",
4
+ "description": "Mosaic BitBucket source for core file system",
6
5
  "license": "Apache-2.0",
7
- "types": "./dist/**",
6
+ "author": "",
7
+ "type": "module",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
8
14
  "engines": {
9
- "node": ">= 12.0.0"
15
+ "node": ">=16.10.0 || >=18.0.0"
10
16
  },
11
17
  "repository": {
12
18
  "type": "git",
13
- "url": "git@github.com:jpmorganchase/mosaic.git"
19
+ "url": "git@github.com:jpmorganchase/mosaic.git",
20
+ "directory": "packages/types"
14
21
  },
22
+ "files": [
23
+ "dist"
24
+ ],
15
25
  "scripts": {
16
26
  "build": "tsc",
17
- "clean": "rm -fr dist"
27
+ "clean": "rm -fr dist",
28
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
18
29
  },
19
30
  "devDependencies": {
20
- "rxjs": "^7.5.5"
31
+ "@jpmorganchase/mosaic-schemas": "^0.1.0-beta.30",
32
+ "memfs": "^3.4.12",
33
+ "rxjs": "^7.5.5",
34
+ "zod": "^3.19.1"
21
35
  }
22
- }
36
+ }
@@ -1,2 +0,0 @@
1
- @jpmorganchase/mosaic-types:build: cache hit, replaying output 9084cbc397462f27
2
- @jpmorganchase/mosaic-types:build: $ tsc
@@ -1,2 +0,0 @@
1
- @jpmorganchase/mosaic-types:clean: cache hit, replaying output cf8c2b7775336107
2
- @jpmorganchase/mosaic-types:clean: $ rm -fr dist
package/CHANGELOG.md DELETED
@@ -1,25 +0,0 @@
1
- # @jpmorganchase/mosaic-types
2
-
3
- ## 0.1.0-beta.3
4
-
5
- ### Patch Changes
6
-
7
- - 457df5e: switch to public package
8
-
9
- ## 0.1.0-beta.2
10
-
11
- ### Patch Changes
12
-
13
- - e1bbbe7: Initial release of Mosaic Core file-system.
14
-
15
- Mosaic is a content aggregating service which pulls content from heterogeneous data sources.
16
-
17
- - 4b2bc51: pipped to 0.1.0-beta.1 for publishing to NPM
18
-
19
- ## 0.1.0
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.
@@ -1,42 +0,0 @@
1
- import type {
2
- DirectoryJSON,
3
- IRealpathOptions,
4
- IMkdirOptions,
5
- IReaddirOptions,
6
- TData,
7
- TMode
8
- } from 'memfs/lib/volume';
9
- import type { TDataOut } from 'memfs/lib/encoding';
10
- import type Dirent from 'memfs/lib/Dirent';
11
- import type Stats from 'memfs/lib/Stats';
12
- import type { TStatNumber } from 'memfs/lib/Stats';
13
- import type { IStatOptions } from 'memfs/lib/volume';
14
- import type { PathLike, symlink } from 'fs';
15
- import type Page from './Page';
16
- import type { Options, Pattern, Entry } from 'fast-glob';
17
-
18
- /**
19
- * This is the core underlying filesystem, which directly interfaces with a memfs Volume to mutate the filesystem
20
- */
21
- export default interface IFileAccess {
22
- glob(pattern: Pattern, options?: Omit<Options, 'absolute' | 'fs'>): Promise<string[] | Entry[]>;
23
- mkdir(dir: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
24
- readdir(dir: PathLike, options?: string | IReaddirOptions): Promise<TDataOut[] | Dirent[]>;
25
- readFile(file: PathLike): Promise<TDataOut>;
26
- realpath(target: string, options?: string | IRealpathOptions): Promise<TDataOut>;
27
- stat(file: PathLike, options?: IStatOptions): Promise<Stats<TStatNumber>>;
28
- unlink(target: PathLike): Promise<void>;
29
- symlink(target: PathLike, alias: PathLike, type?: symlink.Type): Promise<void>;
30
- writeFile(file: PathLike, data: TData): Promise<void>;
31
- toJSON(): DirectoryJSON;
32
- fromJSON(json: DirectoryJSON): void;
33
- exists(file: PathLike): Promise<boolean>;
34
- $$reset(): void;
35
- $$freeze(): void;
36
- get $$frozen(): boolean;
37
- $$unfreeze(): void;
38
- $$clearCache(): void;
39
- $$symlinksFromJSON(page: { [key: string]: { target: string; type: string }[] }): Promise<void>;
40
- symlinksToJSON(): { [key: string]: { target: string; type: string }[] };
41
- $$addReadFileHook(hook: (result: Page, filepath: PathLike) => Promise<Page>): void;
42
- }
package/src/Meta.ts DELETED
@@ -1,9 +0,0 @@
1
- type Meta<AdditionalProps> = {
2
- title?: string;
3
- // `route` is a fullPath that points to the page, similar to how `page`.`fullPath` does - but this may be an alias instead,
4
- // so it can be used for presenting more aesthetic URLs etc when used as a site href
5
- route: string;
6
- lastModified: Date;
7
- } & Record<string, unknown> &
8
- AdditionalProps;
9
- export default Meta;
@@ -1,55 +0,0 @@
1
- type MutableData<T = {}> = ImmutableData<T> & {
2
- /**
3
- * Set arbitrary data onto the config object. This value will persist across plugins and
4
- * also be sent to the parent process when it executes plugins there as well.
5
- * Values can be retrieved from `data`.
6
- * This data is one-way, it can only be set/mutated in the child process lifecycle stages
7
- * This will be reset everytime the relevant source receives new pages
8
- * @param data Data to MERGE into the existing blob
9
- */
10
- setData(data: Partial<T>, overwrite?: boolean): void;
11
- /**
12
- * Helper function for declaring new aliases that will be applied by the AliasPlugin.
13
- * Values can be retrieved from `data.aliases`
14
- * This will be reset everytime the relevant source receives new pages
15
- * @param fullPath The file/fullPath the alias will point to
16
- * @param aliases Array of aliases to use when pointing to this page
17
- */
18
- setAliases(targetPath: string, aliases: string[]): void;
19
- /**
20
- * Helper function for declaring new tags (which are basically aliases to /.tags) that will be applied by the AliasPlugin.
21
- * Values can be retrieved from `data.aliases`
22
- * This will be reset everytime the relevant source receives new pages
23
- * @param fullPath The file/fullPath the alias will point to
24
- * @param tags Array of tag names to use when pointing to this page
25
- */
26
- setTags(targetPath: string, tags: string[]): void;
27
- /**
28
- * Helper function for declaring new refs that will be applied by the RefPlugin
29
- * This will be reset everytime the relevant source receives new pages
30
- * Values can be retrieved from `data.refs`
31
- * @param targetPath The file/fullPath to write the ref to
32
- * @param targetPropPath The path to the property where the ref will be applied
33
- * @param refValue The value of the ref (can be a wildcard)
34
- */
35
- setRef(targetFilepath: string, targetPropPath: string | string[], refValue: string): void;
36
- /**
37
- * Same as `setRef`, but do not pre-resolve this ref - wait until the file is read and use the global filesystem for it
38
- * @param targetPath The file/fullPath to write the ref to
39
- * @param targetPropPath The path to the property where the ref will be applied
40
- * @param refValue The value of the ref (can be a wildcard)
41
- */
42
- setGlobalRef(targetFilepath: string, targetPropPath: string | string[], refValue: string): void;
43
- /**
44
- * This object, but without the mutation methods like `setAliases`, `setData` etc
45
- */
46
- asReadOnly(): ImmutableData<T>;
47
- };
48
-
49
- export type ImmutableData<T = {}> = {
50
- readonly data: Readonly<
51
- T & { readonly refs: string[]; readonly aliases: Set<{ $$path: string[]; $$value: string }> }
52
- >;
53
- };
54
-
55
- export default MutableData;
package/src/Page.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * `Page` is a type, which at a minimum has a `fullPath`, but can also contain metadata and `content`
3
- */
4
- type Page<AdditionalProps = {}> = {
5
- fullPath: string;
6
- title?: string;
7
- /**
8
- * Friendly fullPaths are the shortest possible paths that will point to a page.
9
- * They are useful for creating more user-friendly links on pages, rather than using a full filesystem path.
10
- * They originally start as the same as `fullPath`, but can be modified by plugins whenever they make a change to how a page resolves.
11
- * e.g. The `PagesWithoutFileExtPlugin` modifies the friendly fullPath after it creates aliases for every page (to allow
12
- * them to be referenced without a file extension). Another example would be a plugin that allows `/index` to be
13
- * automatically added if a fullPath points to a directory -- the `route` could then be modified by that
14
- * plugin to remove `/index`
15
- */
16
- route?: string;
17
- lastModified?: Date;
18
- type?: string;
19
- content?: string;
20
- } & Record<string, unknown> &
21
- AdditionalProps;
22
-
23
- export default Page;
package/src/Plugin.ts DELETED
@@ -1,112 +0,0 @@
1
- import type Page from './Page';
2
- import type MutableData from './MutableData';
3
- import type PluginModuleDefinition from './PluginModuleDefinition';
4
- import type { ImmutableData } from './MutableData';
5
- import type { IUnionVolume, IVolumeImmutable, IVolumeMutable, IVolumePartiallyMutable } from './Volume';
6
- import type Serialiser from './Serialiser';
7
-
8
- export type LoadedPlugin = Partial<Plugin> & PluginModuleDefinition;
9
-
10
- /**
11
- * Plugins are lifecycle-based hooks that are called on every source at different stages.
12
- * Consumers will never need to invoke a lifecycle method; but for technical clarity - when a lifecycle method is called,
13
- * it will trigger `pluginRunner` which executes it on every source automatically.
14
- */
15
- type Plugin<ConfigData = {}, PluginOptions = {}, GlobalConfigData = ConfigData> = {
16
- /**
17
- * Plugin lifecycle method that triggers inside child processes.
18
- * The first lifecycle hook to trigger after receiving pages from a source. The pages can safely be mutated and will be reflected in the final
19
- * filesystem that gets generated.
20
- * @param pages Array of pages from the source
21
- * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
22
- * @param param.config A mutable object for sharing data with other lifecycle phases of all plugins for this source (including in the main thread) in this plugin
23
- * @param options The options passed in when declaring the plugin
24
- * @returns {Promise<Page[]>} Must re-return an array of `Page` objects, modified or not
25
- */
26
- $afterSource?(
27
- pages: Page[],
28
- {}: {
29
- serialiser: Serialiser;
30
- config: MutableData<ConfigData>;
31
- pageExtensions: string[];
32
- ignorePages: string[];
33
- },
34
- options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions
35
- ): Promise<Page[]>;
36
- /**
37
- * Plugin lifecycle method that triggers inside child processes.
38
- * Calls after a filesystem has been built up from the source pages.
39
- * @param mutableFilesystem Mutable virtual filesystem instance with all of this source's pages inside (and symlinks applied)
40
- * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
41
- * @param param.config A mutable object for sharing data with other lifecycle phases of all plugins for this source (including in the main thread) in this plugin
42
- * @param options The options passed in when declaring the plugin
43
- * @returns {void} No return expected
44
- */
45
- $beforeSend?(
46
- mutableFilesystem: IVolumePartiallyMutable,
47
- {}: {
48
- serialiser: Serialiser;
49
- pageExtensions: string[];
50
- ignorePages: string[];
51
- config: MutableData<ConfigData>;
52
- },
53
- options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions
54
- ): Promise<void>;
55
- /**
56
- * Plugin lifecycle method that triggers inside the main process.
57
- * Calls after the filesystem and symlinks have been reconstructed due to a change to the current source. This happens in the main thread.
58
- * Pages will NOT be cached when read at this stage, to allow for reading content and writing a new copy of it without the cached version taking effect.
59
- * This method is safe to use with lazy loading, as the filesystem should return the full page when read.
60
- * NOTE: Plugin methods that trigger inside the parent process should be async and highly optimised to avoid holding up the main thread.
61
- * You should also be mindful of race conditions when reading / writing to the global filesystem from this method - as other plugins may
62
- * also have a read copy of the same file and it could end up out of sync.
63
- * @param mutableFilesystem Mutable filesystem instance with all of this source's pages inside (and symlinks re-applied)
64
- * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
65
- * @param param.config An immutable object for reading data from other lifecycle phases of all plugins for this source in the child process for this plugin. Shared only with this source.
66
- * @param param.globalConfig An immutable object for reading data from other lifecycle phases of all plugins. Shared across all sources.
67
- * @param param.sharedFilesystem Mutable filesystem instance independent of any sources. Useful for global pages, like sitemaps
68
- * @param param.globalFilesystem Immutable union filesystem instance with all source's pages (and symlinks applied)
69
- * @param options The options passed in when declaring the plugin
70
- * @returns {void} No return expected
71
- */
72
- afterUpdate?(
73
- mutableFilesystem: IVolumePartiallyMutable,
74
- {}: {
75
- serialiser: Serialiser;
76
- config: ImmutableData<ConfigData>;
77
- globalFilesystem: IUnionVolume;
78
- sharedFilesystem: IVolumeMutable;
79
- globalConfig: ImmutableData<GlobalConfigData>;
80
- pageExtensions: string[];
81
- ignorePages: string[];
82
- },
83
- options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions
84
- ): Promise<void>;
85
- /**
86
- * Plugin lifecycle method that triggers inside the main process everytime ANY source emits new pages.
87
- * This method should return a boolean that will indicate if this source should clear page caches.
88
- * This method calls whenever another source (not this one) has changed.
89
- * Returning `undefined`, false or no value, will result in the cache to be retained
90
- * @param updatedSourceFilesystem Immutable filesystem for the source that changed
91
- * @param param.config An immutable object for reading data from other lifecycle phases of all plugins for this source in the child process for this plugin
92
- * @param param.serialiser A matching `Serialiser` for serialising/deserialising pages when reading/writing to the filesystem
93
- * @param param.globalFilesystem Immutable union filesystem instance with all source's pages (and symlinks applied)
94
- * @param options The options passed in when declaring the plugin
95
- * @returns {Promise<boolean>} A boolean indicating whether to clear the cache for this source
96
- */
97
- shouldClearCache?(
98
- updatedSourceFilesystem: IVolumeImmutable,
99
- {}: {
100
- serialiser: Serialiser;
101
- config: ImmutableData<ConfigData>;
102
- globalFilesystem: IUnionVolume;
103
- pageExtensions: string[];
104
- ignorePages: string[];
105
- },
106
- options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions
107
- ): Promise<boolean>;
108
- };
109
-
110
- export type LifecycleMethod = keyof Plugin;
111
-
112
- export default Plugin;
@@ -1,19 +0,0 @@
1
- export default interface PluginModuleDefinition {
2
- /**
3
- * Options to pass to the plugin lifecycle methods.
4
- */
5
- options: Record<string, unknown>;
6
- /**
7
- * The importance of this plugin. This highest number plugin will be run first
8
- */
9
- priority?: number;
10
- /**
11
- * Exclude this plugin when running `mosaic build`
12
- */
13
- runTimeOnly?: boolean;
14
- /**
15
- * Path to the JS file for this plugin (can either export a `default` module with lifecycle methods,
16
- * or export the methods individually)
17
- */
18
- modulePath: string;
19
- }
@@ -1,11 +0,0 @@
1
- import PluginModuleDefinition from './PluginModuleDefinition';
2
- import SerialiserModuleDefinition from './SerialiserModuleDefinition';
3
- import SourceModuleDefinition from './SourceModuleDefinition';
4
-
5
- export interface PullDocsConfig {
6
- pageExtensions: Array<string>;
7
- ignorePages?: Array<string>;
8
- serialisers: Array<SerialiserModuleDefinition>;
9
- plugins: Array<PluginModuleDefinition>;
10
- sources: Array<SourceModuleDefinition>;
11
- }
package/src/Serialiser.ts DELETED
@@ -1,31 +0,0 @@
1
- import type { TDataOut } from 'memfs/lib/encoding';
2
-
3
- import type Page from './Page';
4
- import type SerialiserModuleDefinition from './SerialiserModuleDefinition';
5
-
6
- /**
7
- * Serialisers are a form of plugin that tells PullDocs how to turn a file from/to a storable form for the filesystem
8
- * or a `Page` object.
9
- * For technical clarity - when a parser method is called, it will trigger `parserRunner` which checks the `fullPath` against
10
- * the `test` option that was passed in the PullDocs config file, to find a suitable parser.
11
- */
12
- export type Serialiser = {
13
- /**
14
- * Method to turn a raw page (e.g. an MDX file) into a `Page` object
15
- * @param fullPath Route on virtual disk (should be full fullPath, not an alias)
16
- * @param page Page in string or buffer form (i.e. an MDX page with frontmatter or a JSON file as a string)
17
- * @returns Page object in the `Page` format
18
- */
19
- deserialise: (fullPath: string, page: TDataOut) => Promise<Page>;
20
- /**
21
- * Method to load a raw page from disk (e.g. an MDX file) and return into a `Page` object
22
- * @param fullPath Route on virtual disk (should be full fullPath, not an alias)
23
- * @param page Page in `Page` form
24
- * @returns Page content
25
- */
26
- serialise: (fullPath: string, page: Page) => Promise<TDataOut>;
27
- };
28
-
29
- export type LoadedSerialiser = Serialiser & SerialiserModuleDefinition;
30
-
31
- export default Serialiser;
@@ -1,7 +0,0 @@
1
- import PluginModuleDefinition from './PluginModuleDefinition';
2
-
3
- type SerialiserModuleDefinition = PluginModuleDefinition & {
4
- filter: RegExp;
5
- };
6
-
7
- export default SerialiserModuleDefinition;
package/src/Source.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { Observable } from 'rxjs';
2
-
3
- import type Serialiser from './Serialiser';
4
- import type Page from './Page';
5
-
6
- type Source<Options = {}> = {
7
- create(
8
- options: Options,
9
- { serialiser, pageExtensions }: { pageExtensions: string[]; serialiser: Serialiser }
10
- ): Observable<Page[]>;
11
- };
12
-
13
- export default Source;
@@ -1,8 +0,0 @@
1
- import type PluginModuleDefinition from './PluginModuleDefinition';
2
-
3
- type SourceModuleDefinition = PluginModuleDefinition & {
4
- namespace: string;
5
- cache?: boolean;
6
- };
7
-
8
- export default SourceModuleDefinition;
package/src/Volume.ts DELETED
@@ -1,136 +0,0 @@
1
- import type {
2
- DirectoryJSON,
3
- IRealpathOptions,
4
- IMkdirOptions,
5
- IReaddirOptions,
6
- TData,
7
- TMode
8
- } from 'memfs/lib/volume';
9
- import type { TDataOut } from 'memfs/lib/encoding';
10
- import type Dirent from 'memfs/lib/Dirent';
11
- import type Stats from 'memfs/lib/Stats';
12
- import type { TStatNumber } from 'memfs/lib/Stats';
13
- import type { IStatOptions } from 'memfs/lib/volume';
14
- import type { PathLike, symlink } from 'fs';
15
- import type { Options, Pattern, Entry } from 'fast-glob';
16
-
17
- /**
18
- * Volumes are lightweight decorators which wrap `FileAccess` and limit access to the underlying API for different use-cases
19
- * Examples include disallowing mutation or allowing underlying functions like resetting
20
- */
21
- interface IVolume {
22
- namespace: string;
23
- reset?(): void;
24
- toJSON(): DirectoryJSON;
25
- symlinksToJSON(): { [key: string]: { target: string; type: string }[] };
26
- fromJSON?(json: DirectoryJSON): void;
27
- promises: {
28
- exists(file: PathLike): Promise<boolean>;
29
- glob(pattern: Pattern, options?: Options): Promise<string[] | Entry[]>;
30
- mkdir(dir: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
31
- readdir(dir: PathLike, options?: string | IReaddirOptions): Promise<TDataOut[] | Dirent[]>;
32
- readFile(file: PathLike): Promise<TDataOut>;
33
- realpath(target: string, options?: string | IRealpathOptions): Promise<TDataOut>;
34
- stat(file: PathLike, options?: IStatOptions): Promise<Stats<TStatNumber>>;
35
- symlink(target: PathLike, alias: PathLike, type?: symlink.Type): Promise<void>;
36
- unlink(target: PathLike): Promise<void>;
37
- writeFile(file: PathLike, data: TData): Promise<void>;
38
- };
39
- }
40
- export interface IVolumePartiallyMutable extends Omit<IVolume, 'reset' | 'fromJSON'> {
41
- /**
42
- * Functions that will be called after a page is read from the filesystem for the first time (since last cache clear).
43
- * The value returned from this hook will *replace* the contents of the read file.
44
- * @param hook Any function that invokes an `afterRead` plugin
45
- * @returns Promise<Page>
46
- */
47
- __internal_do_not_use_addReadFileHook(
48
- hook: (filepath: PathLike, fileData: TDataOut) => Promise<TDataOut>
49
- ): void;
50
- }
51
-
52
- export interface IUnionVolume extends Omit<IVolumeImmutable, 'promises'> {
53
- promises: Pick<IVolumeImmutable, 'promises'> & {
54
- /**
55
- * Reads a file
56
- * @param file Path
57
- * @returns Promise<TDataOut>
58
- */
59
- readFile(file: PathLike): Promise<TDataOut>;
60
- readFile(file: PathLike, options?: { includeConflicts?: false }): Promise<TDataOut>;
61
- /**
62
- * Reads 1 or more files (if multiple files exist at the same location within the union filesystem)
63
- * @param file Path
64
- * @param options.includeConflicts If multiple files exist at the same location in the filesystem, return them all as an array
65
- * @returns Promise<TDataOut[]>
66
- */
67
- readFile(file: PathLike, options: { includeConflicts: true }): Promise<TDataOut[]>;
68
- };
69
- /**
70
- * Scopes a filesystem to specific namespaces
71
- * @param {string[]} namespaces Array of namespaces to limit this filesystem to
72
- * @returns A new immutable union filesystem
73
- */
74
- scope(namespaces: string[]): IUnionVolume;
75
- }
76
-
77
- export interface IVolumeMutable extends IVolume {
78
- /**
79
- * Functions that will be called after a page is read from the filesystem for the first time (since last cache clear).
80
- * The value returned from this hook will *replace* the contents of the read file.
81
- * @param hook Any function that invokes an `afterRead` plugin
82
- * @returns Promise<Page>
83
- */
84
- __internal_do_not_use_addReadFileHook(
85
- hook: (filepath: PathLike, fileData: TDataOut) => Promise<TDataOut>
86
- ): void;
87
- /**
88
- * Restricted filesystems can be written to, but cannot be frozen, updated or reset
89
- */
90
- asRestricted(): IVolumePartiallyMutable;
91
- /**
92
- * ReadOnly filesystems cannot be mutated in any way, including freezing, updating or reseting
93
- */
94
- asReadOnly(): IVolumeImmutable;
95
- /**
96
- * Clears the filesystem's internal page cache - used when the cache may be outdated due to a source emiting new data or a dependency changing.
97
- */
98
- clearCache(): void;
99
- /**
100
- * Re-enables mutations on the underlying `FileAccess`.
101
- */
102
- unfreeze(): void;
103
- /**
104
- * Freezes an object, preventing all mutations on the underlying `FileAccess` object
105
- * Freezing a filesystem indicates that the mutation period has ended and the file system can no longer be modified.
106
- * When a filesystem is unfrozen, it is considered to be in flux, so may change as more plugins are called.
107
- * When a filesystem is frozen, it is considered to be stable and ready to begin serving finalised versions of files.
108
- */
109
- freeze(): void;
110
- /**
111
- * Is this filesystem frozen/mutable?
112
- * @returns {boolean}
113
- */
114
- get frozen(): boolean;
115
- /**
116
- * Appends content to the filesystem
117
- * @param json A JSON blob in the form of {[fullPath]: "{fullPath: '', content: ''}"}
118
- */
119
- fromJSON(json: DirectoryJSON): void;
120
- symlinksFromJSON(json: { [key: string]: { target: string; type: string }[] }): Promise<void>;
121
- /**
122
- * Completely resets the filesystem.
123
- * This includes clearing page cache, erasing filesystem data, clearing symlinks etc
124
- */
125
- reset(): void;
126
- }
127
- export interface IVolumeImmutable
128
- extends Omit<
129
- IVolumePartiallyMutable,
130
- 'fromJSON' | 'reset' | 'promises' | '__internal_do_not_use_addReadFileHook'
131
- > {
132
- promises: Omit<
133
- IVolume['promises'],
134
- 'writeFile' | 'symlink' | 'mkdir' | 'unlink' | 'rmdir' | 'rm' | 'rename'
135
- >;
136
- }
package/src/WorkerData.ts DELETED
@@ -1,18 +0,0 @@
1
- import type SerialiserModuleDefinition from './SerialiserModuleDefinition';
2
- import type PluginModuleDefinition from './PluginModuleDefinition';
3
- import type SourceModuleDefinition from './SourceModuleDefinition';
4
-
5
- type WorkerData<Options = {}> = {
6
- options: Options & Pick<PluginModuleDefinition, 'options'> & Pick<SourceModuleDefinition, 'options'> & {
7
- pageExtensions: string[]
8
- };
9
- name: string;
10
- namespace: string;
11
- pageExtensions: string[];
12
- ignorePages: string[];
13
- plugins: PluginModuleDefinition[];
14
- serialisers: SerialiserModuleDefinition[];
15
- modulePath: string;
16
- };
17
-
18
- export default WorkerData;
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../../tsconfig",
3
- "compilerOptions": {
4
- "emitDeclarationOnly": true,
5
- "rootDir": "./src",
6
- "outDir": "./dist"
7
- },
8
- "include": ["src"],
9
- "exclude": ["src/**/__tests__/**/*", "src/__tests__/**/*"]
10
- }