@emanuelsan/mosaic-js
Version:
Composable Markdown-based AI instruction engine for Node.js
48 lines • 2.49 kB
TypeScript
import { Effect, Context, Schema } from 'effect';
declare const Directory_base: Context.TagClass<Directory, "Directory", {
readonly templateDir: Effect.Effect<string>;
}>;
export declare class Directory extends Directory_base {
}
declare const TemplateSelectorTypeSchema: Schema.Literal<["relative", "root", "id"]>;
type TemplateSelectorType = typeof TemplateSelectorTypeSchema.Type;
export type TemplateSelectorValidation = {
valid: boolean;
type?: TemplateSelectorType;
};
declare const SelectorValidationSchema: Schema.Union<[Schema.Struct<{
valid: Schema.Literal<[true]>;
type: Schema.Literal<["relative", "root", "id"]>;
}>, Schema.Struct<{
valid: Schema.Literal<[false]>;
}>]>;
type SelectorValidation = typeof SelectorValidationSchema.Type;
/**
* Effectful function that validates a MosaicJS template selector string and determines its type.
* Accepts a selector and returns an Effect that, when executed, yields an object indicating whether the selector is valid,
* and if valid, specifies its type ('relative', 'root', or 'id').
*
* Supported selector formats:
* - Relative path (e.g., 'some-dir/core-instructions')
* - Root path prefixed with '@' (e.g., '@root-block', '@namespace/path')
* - ID selector prefixed with '#' (e.g., '#some-id')
*
* Returns: Effect<SelectorValidation>
*/
export declare const isValidTemplateSelector: (selector: string) => Effect.Effect<SelectorValidation>;
/**
* Effectful function that normalizes a validated MosaicJS template selector to a relative path string.
*
* This is an unsafe function: it expects the provided selector to be already validated and of a correct type.
* The function uses the selector type to determine how to normalize:
* - For 'id' selectors (e.g., '#some-id'), it resolves the corresponding markdown file and returns the path relative to the template directory.
* - For 'root' selectors (e.g., '@root-block'), it removes the '@' prefix and returns the path as relative to root.
* - For 'relative' selectors, it returns the selector as-is.
*
* Context: Requires access to the template directory from the Directory context.
* Returns: Effect<string | null>
*/
export declare const normalizeSelector: (selector: string, type: TemplateSelectorType) => Effect.Effect<string | null, never, Directory>;
export declare const normalizeToRelativeSelector: (selector: string) => Effect.Effect<string | null, never, Directory>;
export {};
//# sourceMappingURL=normalizeToRelativeSelector.d.ts.map