@jpmorganchase/mosaic-types 0.1.0-beta.3 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/IFileAccess.d.ts +45 -0
- package/dist/Meta.d.ts +5 -0
- package/dist/MutableData.d.ts +74 -0
- package/dist/Page.d.ts +20 -0
- package/dist/Plugin.d.ts +91 -0
- package/dist/PluginModuleDefinition.d.ts +19 -0
- package/dist/PullDocsConfig.d.ts +10 -0
- package/dist/Serialiser.d.ts +26 -0
- package/dist/SerialiserModuleDefinition.d.ts +4 -0
- package/dist/Source.d.ts +9 -0
- package/dist/SourceModuleDefinition.d.ts +5 -0
- package/dist/Volume.d.ts +130 -0
- package/dist/WorkerData.d.ts +15 -0
- package/dist/index.d.ts +13 -0
- package/package.json +7 -4
- package/.turbo/turbo-build.log +0 -2
- package/.turbo/turbo-clean.log +0 -2
- package/src/IFileAccess.ts +0 -42
- package/src/Meta.ts +0 -9
- package/src/MutableData.ts +0 -55
- package/src/Page.ts +0 -23
- package/src/Plugin.ts +0 -112
- package/src/PluginModuleDefinition.ts +0 -19
- package/src/PullDocsConfig.ts +0 -11
- package/src/Serialiser.ts +0 -31
- package/src/SerialiserModuleDefinition.ts +0 -7
- package/src/Source.ts +0 -13
- package/src/SourceModuleDefinition.ts +0 -8
- package/src/Volume.ts +0 -136
- package/src/WorkerData.ts +0 -18
- package/tsconfig.json +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @jpmorganchase/mosaic-types
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 61a246c: This releases add support for generate / build and serve snapshots
|
|
8
|
+
|
|
9
|
+
## 0.1.0-beta.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bd285df: added dist to package.json
|
|
14
|
+
|
|
3
15
|
## 0.1.0-beta.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { DirectoryJSON, IRealpathOptions, IMkdirOptions, IReaddirOptions, TData, TMode } from 'memfs/lib/volume';
|
|
3
|
+
import type { TDataOut } from 'memfs/lib/encoding';
|
|
4
|
+
import type Dirent from 'memfs/lib/Dirent';
|
|
5
|
+
import type Stats from 'memfs/lib/Stats';
|
|
6
|
+
import type { TStatNumber } from 'memfs/lib/Stats';
|
|
7
|
+
import type { IStatOptions } from 'memfs/lib/volume';
|
|
8
|
+
import type { PathLike, symlink } from 'fs';
|
|
9
|
+
import type { Page } from './Page';
|
|
10
|
+
import type { Options, Pattern, Entry } from 'fast-glob';
|
|
11
|
+
/**
|
|
12
|
+
* This is the core underlying filesystem, which directly interfaces with a memfs Volume to mutate the filesystem
|
|
13
|
+
*/
|
|
14
|
+
export interface IFileAccess {
|
|
15
|
+
glob(pattern: Pattern, options?: Omit<Options, 'absolute' | 'fs'>): Promise<string[] | Entry[]>;
|
|
16
|
+
mkdir(dir: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
|
|
17
|
+
readdir(dir: PathLike, options?: string | IReaddirOptions): Promise<TDataOut[] | Dirent[]>;
|
|
18
|
+
readFile(file: PathLike): Promise<TDataOut>;
|
|
19
|
+
realpath(target: string, options?: string | IRealpathOptions): Promise<TDataOut>;
|
|
20
|
+
stat(file: PathLike, options?: IStatOptions): Promise<Stats<TStatNumber>>;
|
|
21
|
+
unlink(target: PathLike): Promise<void>;
|
|
22
|
+
symlink(target: PathLike, alias: PathLike, type?: symlink.Type): Promise<void>;
|
|
23
|
+
writeFile(file: PathLike, data: TData): Promise<void>;
|
|
24
|
+
toJSON(): DirectoryJSON;
|
|
25
|
+
fromJSON(json: DirectoryJSON): void;
|
|
26
|
+
exists(file: PathLike): Promise<boolean>;
|
|
27
|
+
$$reset(): void;
|
|
28
|
+
$$freeze(): void;
|
|
29
|
+
readonly $$frozen: boolean;
|
|
30
|
+
$$unfreeze(): void;
|
|
31
|
+
$$clearCache(): void;
|
|
32
|
+
$$symlinksFromJSON(page: {
|
|
33
|
+
[key: string]: {
|
|
34
|
+
target: string;
|
|
35
|
+
type: string;
|
|
36
|
+
}[];
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
symlinksToJSON(): {
|
|
39
|
+
[key: string]: {
|
|
40
|
+
target: string;
|
|
41
|
+
type: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
$$addReadFileHook(hook: (result: Page, filepath: PathLike) => Promise<Page>): void;
|
|
45
|
+
}
|
package/dist/Meta.d.ts
ADDED
|
@@ -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<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> & AdditionalProps;
|
package/dist/Plugin.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
export declare type LoadedPlugin = Partial<Plugin> & PluginModuleDefinition;
|
|
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<ConfigData = {}, PluginOptions = {}, 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: Page[], {}: {
|
|
25
|
+
serialiser: Serialiser;
|
|
26
|
+
config: MutableData<ConfigData>;
|
|
27
|
+
pageExtensions: string[];
|
|
28
|
+
ignorePages: string[];
|
|
29
|
+
}, options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions): Promise<Page[]>;
|
|
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, {}: {
|
|
40
|
+
serialiser: Serialiser;
|
|
41
|
+
pageExtensions: string[];
|
|
42
|
+
ignorePages: string[];
|
|
43
|
+
config: MutableData<ConfigData>;
|
|
44
|
+
}, options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions): 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, {}: {
|
|
63
|
+
serialiser: Serialiser;
|
|
64
|
+
config: ImmutableData<ConfigData>;
|
|
65
|
+
globalFilesystem: IUnionVolume;
|
|
66
|
+
sharedFilesystem: IVolumeMutable;
|
|
67
|
+
globalConfig: ImmutableData<GlobalConfigData>;
|
|
68
|
+
pageExtensions: string[];
|
|
69
|
+
ignorePages: string[];
|
|
70
|
+
}, options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions): 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, {}: {
|
|
84
|
+
serialiser: Serialiser;
|
|
85
|
+
config: ImmutableData<ConfigData>;
|
|
86
|
+
globalFilesystem: IUnionVolume;
|
|
87
|
+
pageExtensions: string[];
|
|
88
|
+
ignorePages: string[];
|
|
89
|
+
}, options?: Pick<PluginModuleDefinition, 'options'> & PluginOptions): Promise<boolean>;
|
|
90
|
+
};
|
|
91
|
+
export declare type LifecycleMethod = keyof Plugin;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export 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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PluginModuleDefinition } from './PluginModuleDefinition';
|
|
2
|
+
import type { SerialiserModuleDefinition } from './SerialiserModuleDefinition';
|
|
3
|
+
import type { SourceModuleDefinition } from './SourceModuleDefinition';
|
|
4
|
+
export interface PullDocsConfig {
|
|
5
|
+
pageExtensions: Array<string>;
|
|
6
|
+
ignorePages?: Array<string>;
|
|
7
|
+
serialisers: Array<SerialiserModuleDefinition>;
|
|
8
|
+
plugins: Array<PluginModuleDefinition>;
|
|
9
|
+
sources: Array<SourceModuleDefinition>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TDataOut } from 'memfs/lib/encoding';
|
|
2
|
+
import type { Page } from './Page';
|
|
3
|
+
import type { SerialiserModuleDefinition } from './SerialiserModuleDefinition';
|
|
4
|
+
/**
|
|
5
|
+
* Serialisers are a form of plugin that tells PullDocs 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 PullDocs config file, to find a suitable parser.
|
|
9
|
+
*/
|
|
10
|
+
export declare type Serialiser = {
|
|
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<Page>;
|
|
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: Page) => Promise<TDataOut>;
|
|
25
|
+
};
|
|
26
|
+
export declare type LoadedSerialiser = Serialiser & SerialiserModuleDefinition;
|
package/dist/Source.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { Serialiser } from './Serialiser';
|
|
3
|
+
import type { Page } from './Page';
|
|
4
|
+
export declare type Source<Options = {}> = {
|
|
5
|
+
create(options: Options, { serialiser, pageExtensions }: {
|
|
6
|
+
pageExtensions: string[];
|
|
7
|
+
serialiser: Serialiser;
|
|
8
|
+
}): Observable<Page[]>;
|
|
9
|
+
};
|
package/dist/Volume.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { DirectoryJSON, IRealpathOptions, IMkdirOptions, IReaddirOptions, TData, TMode } from 'memfs/lib/volume';
|
|
3
|
+
import type { TDataOut } from 'memfs/lib/encoding';
|
|
4
|
+
import type Dirent from 'memfs/lib/Dirent';
|
|
5
|
+
import type Stats from 'memfs/lib/Stats';
|
|
6
|
+
import type { TStatNumber } from 'memfs/lib/Stats';
|
|
7
|
+
import type { IStatOptions } from 'memfs/lib/volume';
|
|
8
|
+
import type { PathLike, symlink } from 'fs';
|
|
9
|
+
import type { Options, Pattern, Entry } from 'fast-glob';
|
|
10
|
+
/**
|
|
11
|
+
* Volumes are lightweight decorators which wrap `FileAccess` and limit access to the underlying API for different use-cases
|
|
12
|
+
* Examples include disallowing mutation or allowing underlying functions like resetting
|
|
13
|
+
*/
|
|
14
|
+
export interface IVolume {
|
|
15
|
+
namespace: string;
|
|
16
|
+
reset?(): void;
|
|
17
|
+
toJSON(): DirectoryJSON;
|
|
18
|
+
symlinksToJSON(): {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
target: string;
|
|
21
|
+
type: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
fromJSON?(json: DirectoryJSON): void;
|
|
25
|
+
promises: {
|
|
26
|
+
exists(file: PathLike): Promise<boolean>;
|
|
27
|
+
glob(pattern: Pattern, options?: Options): Promise<string[] | Entry[]>;
|
|
28
|
+
mkdir(dir: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
|
|
29
|
+
readdir(dir: PathLike, options?: string | IReaddirOptions): Promise<TDataOut[] | Dirent[]>;
|
|
30
|
+
readFile(file: PathLike): Promise<TDataOut>;
|
|
31
|
+
realpath(target: string, options?: string | IRealpathOptions): Promise<TDataOut>;
|
|
32
|
+
stat(file: PathLike, options?: IStatOptions): Promise<Stats<TStatNumber>>;
|
|
33
|
+
symlink(target: PathLike, alias: PathLike, type?: symlink.Type): Promise<void>;
|
|
34
|
+
unlink(target: PathLike): Promise<void>;
|
|
35
|
+
writeFile(file: PathLike, data: TData): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface IVolumePartiallyMutable extends Omit<IVolume, 'reset' | 'fromJSON'> {
|
|
39
|
+
/**
|
|
40
|
+
* Functions that will be called after a page is read from the filesystem for the first time (since last cache clear).
|
|
41
|
+
* The value returned from this hook will *replace* the contents of the read file.
|
|
42
|
+
* @param hook Any function that invokes an `afterRead` plugin
|
|
43
|
+
* @returns Promise<Page>
|
|
44
|
+
*/
|
|
45
|
+
__internal_do_not_use_addReadFileHook(hook: (filepath: PathLike, fileData: TDataOut) => Promise<TDataOut>): void;
|
|
46
|
+
}
|
|
47
|
+
export interface IUnionVolume extends Omit<IVolumeImmutable, 'promises'> {
|
|
48
|
+
promises: Pick<IVolumeImmutable, 'promises'> & {
|
|
49
|
+
/**
|
|
50
|
+
* Reads a file
|
|
51
|
+
* @param file Path
|
|
52
|
+
* @returns Promise<TDataOut>
|
|
53
|
+
*/
|
|
54
|
+
readFile(file: PathLike): Promise<TDataOut>;
|
|
55
|
+
readFile(file: PathLike, options?: {
|
|
56
|
+
includeConflicts?: false;
|
|
57
|
+
}): Promise<TDataOut>;
|
|
58
|
+
/**
|
|
59
|
+
* Reads 1 or more files (if multiple files exist at the same location within the union filesystem)
|
|
60
|
+
* @param file Path
|
|
61
|
+
* @param options.includeConflicts If multiple files exist at the same location in the filesystem, return them all as an array
|
|
62
|
+
* @returns Promise<TDataOut[]>
|
|
63
|
+
*/
|
|
64
|
+
readFile(file: PathLike, options: {
|
|
65
|
+
includeConflicts: true;
|
|
66
|
+
}): Promise<TDataOut[]>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Scopes a filesystem to specific namespaces
|
|
70
|
+
* @param {string[]} namespaces Array of namespaces to limit this filesystem to
|
|
71
|
+
* @returns A new immutable union filesystem
|
|
72
|
+
*/
|
|
73
|
+
scope(namespaces: string[]): IUnionVolume;
|
|
74
|
+
}
|
|
75
|
+
export interface IVolumeMutable extends IVolume {
|
|
76
|
+
/**
|
|
77
|
+
* Functions that will be called after a page is read from the filesystem for the first time (since last cache clear).
|
|
78
|
+
* The value returned from this hook will *replace* the contents of the read file.
|
|
79
|
+
* @param hook Any function that invokes an `afterRead` plugin
|
|
80
|
+
* @returns Promise<Page>
|
|
81
|
+
*/
|
|
82
|
+
__internal_do_not_use_addReadFileHook(hook: (filepath: PathLike, fileData: TDataOut) => Promise<TDataOut>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Restricted filesystems can be written to, but cannot be frozen, updated or reset
|
|
85
|
+
*/
|
|
86
|
+
asRestricted(): IVolumePartiallyMutable;
|
|
87
|
+
/**
|
|
88
|
+
* ReadOnly filesystems cannot be mutated in any way, including freezing, updating or reseting
|
|
89
|
+
*/
|
|
90
|
+
asReadOnly(): IVolumeImmutable;
|
|
91
|
+
/**
|
|
92
|
+
* 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.
|
|
93
|
+
*/
|
|
94
|
+
clearCache(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Re-enables mutations on the underlying `FileAccess`.
|
|
97
|
+
*/
|
|
98
|
+
unfreeze(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Freezes an object, preventing all mutations on the underlying `FileAccess` object
|
|
101
|
+
* Freezing a filesystem indicates that the mutation period has ended and the file system can no longer be modified.
|
|
102
|
+
* When a filesystem is unfrozen, it is considered to be in flux, so may change as more plugins are called.
|
|
103
|
+
* When a filesystem is frozen, it is considered to be stable and ready to begin serving finalised versions of files.
|
|
104
|
+
*/
|
|
105
|
+
freeze(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Is this filesystem frozen/mutable?
|
|
108
|
+
* @returns {boolean}
|
|
109
|
+
*/
|
|
110
|
+
readonly frozen: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Appends content to the filesystem
|
|
113
|
+
* @param json A JSON blob in the form of {[fullPath]: "{fullPath: '', content: ''}"}
|
|
114
|
+
*/
|
|
115
|
+
fromJSON(json: DirectoryJSON): void;
|
|
116
|
+
symlinksFromJSON(json: {
|
|
117
|
+
[key: string]: {
|
|
118
|
+
target: string;
|
|
119
|
+
type: string;
|
|
120
|
+
}[];
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Completely resets the filesystem.
|
|
124
|
+
* This includes clearing page cache, erasing filesystem data, clearing symlinks etc
|
|
125
|
+
*/
|
|
126
|
+
reset(): void;
|
|
127
|
+
}
|
|
128
|
+
export interface IVolumeImmutable extends Omit<IVolumePartiallyMutable, 'fromJSON' | 'reset' | 'promises' | '__internal_do_not_use_addReadFileHook'> {
|
|
129
|
+
promises: Omit<IVolume['promises'], 'writeFile' | 'symlink' | 'mkdir' | 'unlink' | 'rmdir' | 'rm' | 'rename'>;
|
|
130
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SerialiserModuleDefinition } from './SerialiserModuleDefinition';
|
|
2
|
+
import type { PluginModuleDefinition } from './PluginModuleDefinition';
|
|
3
|
+
import type { SourceModuleDefinition } from './SourceModuleDefinition';
|
|
4
|
+
export declare type WorkerData<Options = {}> = {
|
|
5
|
+
options: Options & Pick<PluginModuleDefinition, 'options'> & Pick<SourceModuleDefinition, 'options'> & {
|
|
6
|
+
pageExtensions: string[];
|
|
7
|
+
};
|
|
8
|
+
name: string;
|
|
9
|
+
namespace: string;
|
|
10
|
+
pageExtensions: string[];
|
|
11
|
+
ignorePages: string[];
|
|
12
|
+
plugins: PluginModuleDefinition[];
|
|
13
|
+
serialisers: SerialiserModuleDefinition[];
|
|
14
|
+
modulePath: string;
|
|
15
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './IFileAccess';
|
|
2
|
+
export * from './Meta';
|
|
3
|
+
export * from './MutableData';
|
|
4
|
+
export * from './Page';
|
|
5
|
+
export * from './Plugin';
|
|
6
|
+
export * from './PluginModuleDefinition';
|
|
7
|
+
export * from './PullDocsConfig';
|
|
8
|
+
export * from './Serialiser';
|
|
9
|
+
export * from './SerialiserModuleDefinition';
|
|
10
|
+
export * from './Source';
|
|
11
|
+
export * from './SourceModuleDefinition';
|
|
12
|
+
export * from './Volume';
|
|
13
|
+
export * from './WorkerData';
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpmorganchase/mosaic-types",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"author": "",
|
|
5
|
-
"description": "",
|
|
5
|
+
"description": "Mosaic BitBucket source for core file system",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"types": "./dist
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">= 12.0.0"
|
|
10
10
|
},
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git@github.com:jpmorganchase/mosaic.git"
|
|
14
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
15
18
|
"scripts": {
|
|
16
19
|
"build": "tsc",
|
|
17
20
|
"clean": "rm -fr dist"
|
|
@@ -19,4 +22,4 @@
|
|
|
19
22
|
"devDependencies": {
|
|
20
23
|
"rxjs": "^7.5.5"
|
|
21
24
|
}
|
|
22
|
-
}
|
|
25
|
+
}
|
package/.turbo/turbo-build.log
DELETED
package/.turbo/turbo-clean.log
DELETED
package/src/IFileAccess.ts
DELETED
|
@@ -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;
|
package/src/MutableData.ts
DELETED
|
@@ -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
|
-
}
|
package/src/PullDocsConfig.ts
DELETED
|
@@ -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;
|
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;
|
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;
|