1
- # @synstack/pattern
1
+ # @synstack/markdown-db
2
2
3
- Pattern-based configuration engine with query matching capabilities
3
+ Markdown database engine with query matching capabilities
4
4
5
5
## What is it for?
6
6
- Matches markdown files based on provided entry data
7
- - Supports hierarchical pattern inheritance
7
+ - Supports hierarchical entry inheritance
8
8
- Supports custom query engines and schema validation
9
9
10
10
``` typescript
11
- import { PatternEngine } from " @synstack/pattern " ;
11
+ import { MarkdownDb } from " @synstack/markdown-db " ;
12
12
import { fsDir } from " @synstack/fs" ;
13
13
import { z } from " zod" ;
14
14
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 " ));
17
17
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 );
20
20
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 ] );
23
23
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" );
26
26
```
27
27
28
28
## Installation
29
29
30
30
``` bash
31
31
# Using npm
32
- npm install @synstack/pattern @synstack/query zod
32
+ npm install @synstack/markdown-db @synstack/query zod
33
33
34
34
# Using yarn
35
- yarn add @synstack/pattern @synstack/query zod
35
+ yarn add @synstack/markdown-db @synstack/query zod
36
36
37
37
# Using pnpm
38
- pnpm add @synstack/pattern @synstack/query zod
38
+ pnpm add @synstack/markdown-db @synstack/query zod
39
39
```
40
40
41
41
## Features
42
42
43
- ### Pattern Organization
43
+ ### Entry Organization
44
44
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:
46
46
47
- #### Basic Pattern Example
47
+ #### Basic Entry Example
48
48
49
49
``` markdown
50
50
---
51
51
query:
52
52
always: true
53
53
---
54
54
55
- # Simple Pattern
55
+ # Simple Entry
56
56
57
- This is a basic pattern that always matches any input.
57
+ This is a basic entry that always matches any input.
58
58
```
59
59
60
- #### Complex Query Pattern
60
+ #### Complex Query Entry
61
61
62
62
``` markdown
63
63
---
@@ -75,13 +75,13 @@ priority: 1
75
75
76
76
# React Component Detection
77
77
78
- This pattern matches React component files that:
78
+ This entry matches React component files that:
79
79
- Contain the word 'component' in their path or content
80
80
- Have either .tsx or .jsx extension
81
81
- Do not contain 'deprecated' in their path or content
82
82
```
83
83
84
- #### Hierarchical Pattern Example
84
+ #### Hierarchical Entry Example
85
85
86
86
``` markdown
87
87
---
@@ -94,69 +94,69 @@ metadata:
94
94
95
95
# Level 1 Test Pattern
96
96
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.
99
99
```
100
100
101
- ### Pattern Directory Structure
101
+ ### Entry Directory Structure
102
102
103
- Organize your patterns in a directory structure like this:
103
+ Organize your entries in a directory structure like this:
104
104
105
105
```
106
- patterns /
106
+ entries /
107
107
├── simple/
108
- │ └── basic.md # Pattern name : "simple/basic"
108
+ │ └── basic.md # Entry ID : "simple/basic"
109
109
├── complex/
110
- │ └── with-query.md # Pattern name : "complex/with-query"
110
+ │ └── with-query.md # Entry ID : "complex/with-query"
111
111
├── components/
112
- │ ├── 0.components.md # Pattern name : "components" (numeric prefix removed)
112
+ │ ├── 0.components.md # Entry ID : "components" (numeric prefix removed)
113
113
│ ├── 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")
117
117
│ └── 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")
120
120
├── nested/
121
121
│ └── 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"
124
124
└── 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")
128
128
```
129
129
130
- ### Pattern Naming
130
+ ### Entry Naming
131
131
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:
133
133
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 `
137
137
138
138
#### Numeric Prefix Handling
139
139
140
140
Numeric prefixes are automatically removed from filenames to allow for ordering:
141
141
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 `
145
145
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.
147
147
148
148
#### Type Suffix Support
149
149
150
- Pattern files can include type suffixes for categorization:
150
+ Entry files can include type suffixes for categorization:
151
151
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 ` )
154
154
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.
156
156
157
157
### Query Integration
158
158
159
- The pattern engine integrates with ` @synstack/query ` for sophisticated matching:
159
+ The markdown database engine integrates with ` @synstack/query ` for sophisticated matching:
160
160
161
161
``` typescript
162
162
import { QueryEngine } from " @synstack/query" ;
@@ -166,27 +166,27 @@ const queryEngine = QueryEngine
166
166
.addPredicate (" status" , z .string (), (status ) => (input ) => input .status === status )
167
167
.addPredicate (" priority" , z .number (), (priority ) => (input ) => input .priority >= priority );
168
168
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 " ))
172
172
.setQueryEngine (queryEngine );
173
173
```
174
174
175
- ### Pattern Inheritance
175
+ ### Entry Inheritance
176
176
177
- Patterns support hierarchical inheritance where parent patterns are automatically applied:
177
+ Entries support hierarchical inheritance where parent entries are automatically applied:
178
178
179
179
``` 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" );
182
182
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 );
185
185
```
186
186
187
187
### Schema Validation
188
188
189
- Configure custom schema validation for pattern data:
189
+ Configure custom schema validation for entry data:
190
190
191
191
``` typescript
192
192
const customSchema = z .object ({
@@ -197,20 +197,20 @@ const customSchema = z.object({
197
197
});
198
198
199
199
const typedEngine = engine .setConfigSchema (customSchema );
200
- const patterns = await typedEngine .getPatterns (); // Fully typed patterns
200
+ const entries = await typedEngine .getEntries (); // Fully typed entries
201
201
```
202
202
203
- ### Pattern Management
203
+ ### Entry Management
204
204
205
205
``` typescript
206
- // Get all patterns
207
- const allPatterns = await engine .getPatterns ();
206
+ // Get all entries
207
+ const allEntries = await engine .getEntries ();
208
208
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 ();
211
211
212
- // Refresh patterns from filesystem
213
- await engine .refreshPatterns ();
212
+ // Refresh entries from filesystem
213
+ await engine .refreshEntries ();
214
214
215
215
// Get schema information
216
216
const schema = engine .schema ;
@@ -219,23 +219,23 @@ const jsonSchema = engine.jsonSchema;
219
219
220
220
## API Reference
221
221
222
- ### PatternEngine
222
+ ### MarkdownDb
223
223
224
224
#### Static Methods
225
225
226
- - ` PatternEngine .cwd(dir)` - Create a pattern engine for a directory
226
+ - ` MarkdownDb .cwd(dir)` - Create a markdown database for a directory
227
227
228
228
#### Instance Methods
229
229
230
230
- ` 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
239
239
- ` query ` - Access the underlying query engine
240
240
- ` schema ` - Get the configuration schema
241
241
- ` jsonSchema ` - Get JSON schema representation
@@ -244,8 +244,8 @@ const jsonSchema = engine.jsonSchema;
244
244
245
245
``` typescript
246
246
// Infer configuration type from engine
247
- type Config = PatternEngine .Config .Infer <typeof engine >;
247
+ type Config = MarkdownDb .Config .Infer <typeof engine >;
248
248
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 >;
251
251
```
0 commit comments