Skip to content

Commit 830b1a5

Browse files
committed
update readme
1 parent c2b1b41 commit 830b1a5

File tree

1 file changed

+86
-86
lines changed

1 file changed

+86
-86
lines changed

packages/markdown-db/README.md

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
# @synstack/pattern
1+
# @synstack/markdown-db
22

3-
Pattern-based configuration engine with query matching capabilities
3+
Markdown database engine with query matching capabilities
44

55
## What is it for?
66
- Matches markdown files based on provided entry data
7-
- Supports hierarchical pattern inheritance
7+
- Supports hierarchical entry inheritance
88
- Supports custom query engines and schema validation
99

1010
```typescript
11-
import { PatternEngine } from "@synstack/pattern";
11+
import { MarkdownDb } from "@synstack/markdown-db";
1212
import { fsDir } from "@synstack/fs";
1313
import { z } from "zod";
1414

15-
// Create a pattern engine for a directory containing .md pattern files
16-
const engine = PatternEngine.cwd(fsDir("./patterns"));
15+
// Create a markdown database for a directory containing .md files
16+
const engine = MarkdownDb.cwd(fsDir("./entries"));
1717

18-
// Find all patterns that match specific input
19-
const matchingPatterns = await engine.matchingPatterns(inputData);
18+
// Find all entries that match specific input
19+
const matchingEntries = await engine.match(inputData);
2020

21-
// Get pattern names that match
22-
const patternNames = await engine.matchingPatternNames(inputData);
21+
// Match multiple inputs and get deduplicated results sorted by file path
22+
const allMatches = await engine.matchAll([inputData1, inputData2]);
2323

24-
// Get a specific pattern by name
25-
const pattern = await engine.getPatternByName("complex/with-query");
24+
// Get a specific entry by id
25+
const entry = await engine.getEntryById("complex/with-query");
2626
```
2727

2828
## Installation
2929

3030
```bash
3131
# Using npm
32-
npm install @synstack/pattern @synstack/query zod
32+
npm install @synstack/markdown-db @synstack/query zod
3333

3434
# Using yarn
35-
yarn add @synstack/pattern @synstack/query zod
35+
yarn add @synstack/markdown-db @synstack/query zod
3636

3737
# Using pnpm
38-
pnpm add @synstack/pattern @synstack/query zod
38+
pnpm add @synstack/markdown-db @synstack/query zod
3939
```
4040

4141
## Features
4242

43-
### Pattern Organization
43+
### Entry Organization
4444

45-
Patterns are organized as markdown files with YAML frontmatter containing configuration data and queries:
45+
Entries are organized as markdown files with YAML frontmatter containing configuration data and queries:
4646

47-
#### Basic Pattern Example
47+
#### Basic Entry Example
4848

4949
```markdown
5050
---
5151
query:
5252
always: true
5353
---
5454

55-
# Simple Pattern
55+
# Simple Entry
5656

57-
This is a basic pattern that always matches any input.
57+
This is a basic entry that always matches any input.
5858
```
5959

60-
#### Complex Query Pattern
60+
#### Complex Query Entry
6161

6262
```markdown
6363
---
@@ -75,13 +75,13 @@ priority: 1
7575

7676
# React Component Detection
7777

78-
This pattern matches React component files that:
78+
This entry matches React component files that:
7979
- Contain the word 'component' in their path or content
8080
- Have either .tsx or .jsx extension
8181
- Do not contain 'deprecated' in their path or content
8282
```
8383

84-
#### Hierarchical Pattern Example
84+
#### Hierarchical Entry Example
8585

8686
```markdown
8787
---
@@ -94,69 +94,69 @@ metadata:
9494

9595
# Level 1 Test Pattern
9696

97-
Pattern that matches when input contains "test1".
98-
This pattern inherits from parent patterns in the directory hierarchy.
97+
Entry that matches when input contains "test1".
98+
This entry inherits from parent entries in the directory hierarchy.
9999
```
100100

101-
### Pattern Directory Structure
101+
### Entry Directory Structure
102102

103-
Organize your patterns in a directory structure like this:
103+
Organize your entries in a directory structure like this:
104104

105105
```
106-
patterns/
106+
entries/
107107
├── simple/
108-
│ └── basic.md # Pattern name: "simple/basic"
108+
│ └── basic.md # Entry ID: "simple/basic"
109109
├── complex/
110-
│ └── with-query.md # Pattern name: "complex/with-query"
110+
│ └── with-query.md # Entry ID: "complex/with-query"
111111
├── components/
112-
│ ├── 0.components.md # Pattern name: "components" (numeric prefix removed)
112+
│ ├── 0.components.md # Entry ID: "components" (numeric prefix removed)
113113
│ ├── button/
114-
│ │ ├── 0.button.md # Pattern name: "components/button"
115-
│ │ ├── primary.md # Pattern name: "components/button/primary"
116-
│ │ └── button.theme.md # Pattern name: "components/button" (type: "theme")
114+
│ │ ├── 0.button.md # Entry ID: "components/button"
115+
│ │ ├── primary.md # Entry ID: "components/button/primary"
116+
│ │ └── button.theme.md # Entry ID: "components/button" (type: "theme")
117117
│ └── form/
118-
│ ├── input.md # Pattern name: "components/form/input"
119-
│ └── input.validation.md # Pattern name: "components/form/input" (type: "validation")
118+
│ ├── input.md # Entry ID: "components/form/input"
119+
│ └── input.validation.md # Entry ID: "components/form/input" (type: "validation")
120120
├── nested/
121121
│ └── level1/
122-
│ ├── level1.md # Pattern name: "nested/level1/level1"
123-
│ └── pattern1.md # Pattern name: "nested/level1/pattern1"
122+
│ ├── level1.md # Entry ID: "nested/level1/level1"
123+
│ └── pattern1.md # Entry ID: "nested/level1/pattern1"
124124
└── user/
125-
├── active.md # Pattern name: "user/active"
126-
├── inactive.md # Pattern name: "user/inactive"
127-
└── user.permissions.md # Pattern name: "user" (type: "permissions")
125+
├── active.md # Entry ID: "user/active"
126+
├── inactive.md # Entry ID: "user/inactive"
127+
└── user.permissions.md # Entry ID: "user" (type: "permissions")
128128
```
129129

130-
### Pattern Naming
130+
### Entry Naming
131131

132-
Pattern files are automatically named based on their directory structure and filename:
132+
Entry files are automatically named based on their directory structure and filename:
133133

134-
- `patterns/user/active.md`Pattern name: `user/active`
135-
- `patterns/complex/with-query.md`Pattern name: `complex/with-query`
136-
- `patterns/nested/level1/pattern1.md`Pattern name: `nested/level1/pattern1`
134+
- `entries/user/active.md`Entry ID: `user/active`
135+
- `entries/complex/with-query.md`Entry ID: `complex/with-query`
136+
- `entries/nested/level1/pattern1.md`Entry ID: `nested/level1/pattern1`
137137

138138
#### Numeric Prefix Handling
139139

140140
Numeric prefixes are automatically removed from filenames to allow for ordering:
141141

142-
- `patterns/components/0.components.md`Pattern name: `components`
143-
- `patterns/components/button/0.button.md`Pattern name: `components/button`
144-
- `patterns/components/button/primary.md`Pattern name: `components/button/primary`
142+
- `entries/components/0.components.md`Entry ID: `components`
143+
- `entries/components/button/0.button.md`Entry ID: `components/button`
144+
- `entries/components/button/primary.md`Entry ID: `components/button/primary`
145145

146-
This allows you to control the processing order of patterns while keeping clean, meaningful names.
146+
This allows you to control the processing order of entries while keeping clean, meaningful names.
147147

148148
#### Type Suffix Support
149149

150-
Pattern files can include type suffixes for categorization:
150+
Entry files can include type suffixes for categorization:
151151

152-
- `patterns/button.primary.md`Pattern name: `button` (type: `primary`)
153-
- `patterns/form.validation.md`Pattern name: `form` (type: `validation`)
152+
- `entries/button.primary.md`Entry ID: `button` (type: `primary`)
153+
- `entries/form.validation.md`Entry ID: `form` (type: `validation`)
154154

155-
The type information is available in the pattern metadata for advanced filtering and organization.
155+
The type information is available in the entry metadata for advanced filtering and organization.
156156

157157
### Query Integration
158158

159-
The pattern engine integrates with `@synstack/query` for sophisticated matching:
159+
The markdown database engine integrates with `@synstack/query` for sophisticated matching:
160160

161161
```typescript
162162
import { QueryEngine } from "@synstack/query";
@@ -166,27 +166,27 @@ const queryEngine = QueryEngine
166166
.addPredicate("status", z.string(), (status) => (input) => input.status === status)
167167
.addPredicate("priority", z.number(), (priority) => (input) => input.priority >= priority);
168168

169-
// Apply custom query engine to pattern engine
170-
const engine = PatternEngine
171-
.cwd(dir("./patterns"))
169+
// Apply custom query engine to markdown database
170+
const engine = MarkdownDb
171+
.cwd(dir("./entries"))
172172
.setQueryEngine(queryEngine);
173173
```
174174

175-
### Pattern Inheritance
175+
### Entry Inheritance
176176

177-
Patterns support hierarchical inheritance where parent patterns are automatically applied:
177+
Entries support hierarchical inheritance where parent entries are automatically applied:
178178

179179
```typescript
180-
// Get parent patterns for a specific pattern
181-
const parentPatterns = await engine.getParentPatterns("nested/level1/pattern1");
180+
// Get parent entries for a specific entry
181+
const parentEntries = await engine.getParentEntries("nested/level1/pattern1");
182182

183-
// Parent patterns are automatically combined during matching
184-
const matches = await engine.matchingPatterns(inputData);
183+
// Parent entries are automatically combined during matching
184+
const matches = await engine.match(inputData);
185185
```
186186

187187
### Schema Validation
188188

189-
Configure custom schema validation for pattern data:
189+
Configure custom schema validation for entry data:
190190

191191
```typescript
192192
const customSchema = z.object({
@@ -197,20 +197,20 @@ const customSchema = z.object({
197197
});
198198

199199
const typedEngine = engine.setConfigSchema(customSchema);
200-
const patterns = await typedEngine.getPatterns(); // Fully typed patterns
200+
const entries = await typedEngine.getEntries(); // Fully typed entries
201201
```
202202

203-
### Pattern Management
203+
### Entry Management
204204

205205
```typescript
206-
// Get all patterns
207-
const allPatterns = await engine.getPatterns();
206+
// Get all entries
207+
const allEntries = await engine.getEntries();
208208

209-
// Get patterns as a map for quick lookup
210-
const patternsMap = await engine.getPatternsMap();
209+
// Get entries as a map for quick lookup
210+
const entriesMap = await engine.getEntriesMap();
211211

212-
// Refresh patterns from filesystem
213-
await engine.refreshPatterns();
212+
// Refresh entries from filesystem
213+
await engine.refreshEntries();
214214

215215
// Get schema information
216216
const schema = engine.schema;
@@ -219,23 +219,23 @@ const jsonSchema = engine.jsonSchema;
219219

220220
## API Reference
221221

222-
### PatternEngine
222+
### MarkdownDb
223223

224224
#### Static Methods
225225

226-
- `PatternEngine.cwd(dir)` - Create a pattern engine for a directory
226+
- `MarkdownDb.cwd(dir)` - Create a markdown database for a directory
227227

228228
#### Instance Methods
229229

230230
- `setQueryEngine(queryEngine)` - Set custom query engine for matching
231-
- `setConfigSchema(schema)` - Set custom schema for pattern validation
232-
- `getPatterns()` - Get all patterns
233-
- `getPatternsMap()` - Get patterns as a Map for quick lookup
234-
- `getPatternByName(name)` - Get a specific pattern by name
235-
- `getParentPatterns(patternName)` - Get parent patterns for hierarchical matching
236-
- `matchingPatterns(input)` - Find patterns that match the input
237-
- `matchingPatternNames(input)` - Get names of matching patterns
238-
- `refreshPatterns()` - Reload patterns from filesystem
231+
- `setConfigSchema(schema)` - Set custom schema for entry validation
232+
- `getEntries()` - Get all entries
233+
- `getEntriesMap()` - Get entries as a Map for quick lookup
234+
- `getEntryById(id)` - Get a specific entry by ID
235+
- `getParentEntries(entryId)` - Get parent entries for hierarchical matching
236+
- `match(input)` - Find entries that match the input
237+
- `matchAll(inputs)` - Find entries that match any of the inputs (deduplicated and sorted)
238+
- `refreshEntries()` - Reload entries from filesystem
239239
- `query` - Access the underlying query engine
240240
- `schema` - Get the configuration schema
241241
- `jsonSchema` - Get JSON schema representation
@@ -244,8 +244,8 @@ const jsonSchema = engine.jsonSchema;
244244

245245
```typescript
246246
// Infer configuration type from engine
247-
type Config = PatternEngine.Config.Infer<typeof engine>;
247+
type Config = MarkdownDb.Config.Infer<typeof engine>;
248248

249-
// Infer pattern type from engine
250-
type Pattern = PatternEngine.Pattern.Infer<typeof engine>;
249+
// Infer entry type from engine
250+
type Entry = MarkdownDb.Entry.Infer<typeof engine>;
251251
```

0 commit comments

Comments
 (0)