archetype 0.0.1-next.11
Install from the command line:
Learn more about npm packages
$ npm install @typematter/archetype@0.0.1-next.11
Install via package.json:
"@typematter/archetype": "0.0.1-next.11"
About this version
Archetype is a robust TypeScript library designed to define, load, and manage content schemas through archetypes. It supports both local and remote schema sources, ensuring flexibility and scalability for your content systems.
- Flexible Schema Loading: Supports loading archetype schemas from both local markdown files and remote URLs.
- Robust Error Handling: Custom error classes provide clear and specific error messages.
- Type-Safe: Built with TypeScript to ensure type safety across your project.
- Extensible Architecture: Easily extend or modify to fit your project's needs.
- Self-Validation: Archetypes can validate themselves and others, maintaining consistency.
npm install archetypeimport { createLocalStore } from '@typematter/archetype';
const localStore = createLocalStore('/path/to/archetypes');
await localStore
.load('post')
.then((archetype) => {
console.log('Loaded archetype:', archetype);
})
.catch((error) => {
console.error(error);
});import { createRemoteStore } from '@typematter/archetype';
const remoteStore = createRemoteStore('https://example.com/archetypes');
await remoteStore
.load('post')
.then((archetype) => {
console.log('Loaded archetype:', archetype);
})
.catch((error) => {
console.error(error);
});import { createValidator } from '@typematter/archetype';
const validator = createValidator({
store: localStore
});
const postArchetype = await validator.loadArchetype('post');const validationResult = await validator.validateArchetype(postArchetype);const frontmatter = {
title: 'Hello, World!',
date: '2021-01-01'
};
const validationResult = await validator.validateFrontmatter(frontmatter, 'post');interface Archetype {
name: string;
version: string;
schema: {
required: Record<string, SchemaField>;
optional: Record<string, SchemaField>;
};
extends?: string[];
}-
name: The name of the archetype. -
version: The version of the archetype. -
schema: The schema fields. -
extends: The name(s) of the archetype(s) this archetype extends.
interface ArchetypeStore {
load(name: string): Promise<Archetype>;
}-
load: Loads an archetype schema by name.
interface ArchetypeValidator {
readonly archetypeSchema: Readonly<Archetype>;
loadArchetype: (name: string) => Promise<Archetype>;
validateArchetype(archetype: unknown): Promise<ValidationResult>;
validateFrontmatter: (
frontmatter: unknown,
defaultArchetypeName?: string
) => Promise<ValidationResult>;
}-
archetypeSchema: The archetype schema. -
loadArchetype: Loads an archetype schema by name. -
validateArchetype: Validates an archetype object. -
validateFrontmatter: Validates frontmatter data.
interface ValidationError {
message: string;
path: string[];
}-
message: The error message. -
path: The path to the error.
interface ValidationResult {
valid: boolean;
errors: ValidationError[];
}-
valid: Whether the validation passed. -
errors: An array of validation errors.
interface ValidatorOptions {
store: ArchetypeStore;
cache?: boolean;
validation?: {
strictMode?: boolean;
allowUnknownFields?: boolean;
};
}-
store: The archetype store. -
cache: Whether to cache loaded archetypes. -
validation: Validation options.-
strictMode: Whether to enforce strict mode. -
allowUnknownFields: Whether to allow unknown fields.
-
class ArchetypeLoadError extends Error {
constructor(message: string, cause?: unknown);
}-
message: The error message. -
cause: The underlying cause of the error.
class LocalArchetypeLoadError extends ArchetypeLoadError {
constructor(message: string, cause?: unknown);
}-
message: The error message. -
cause: The underlying cause of the error.
class RemoteArchetypeLoadError extends ArchetypeLoadError {
constructor(message: string, statusText? string);
}-
message: The error message. -
statusText: The status text of the HTTP response.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature. - Commit your changes:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature/YourFeature. - Open a pull request.
Please ensure your code follows the project's coding standards and include relevant tests.
For questions or support, please open an issue on the GitHub repository.
Details
- archetype
-
typematter
- over 1 year ago
- MIT
- 17 dependencies
Assets
- archetype-0.0.1-next.11.tgz
Download activity
- Total downloads 0
- Last 30 days 0
- Last week 0
- Today 0