contentbase 0.0.1 → 0.0.4
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/.mcp.json +9 -0
- package/CLI.md +593 -0
- package/MCP-DESCRIPTIONS-REVIEW.md +122 -0
- package/MCP-SERVER-SPEC.md +453 -0
- package/PRIMER.md +540 -0
- package/README.md +406 -13
- package/bun.lock +45 -6
- package/dist/cnotes +0 -0
- package/docs/README.md +110 -0
- package/docs/TABLE-OF-CONTENTS.md +7 -0
- package/docs/models.ts +38 -0
- package/models.ts +38 -0
- package/package.json +14 -4
- package/public/web-demo/index.html +813 -0
- package/scripts/examples/01-collection-setup.ts +46 -0
- package/scripts/examples/02-querying.ts +67 -0
- package/scripts/examples/03-sections.ts +36 -0
- package/scripts/examples/04-relationships.ts +54 -0
- package/scripts/examples/05-document-api.ts +54 -0
- package/scripts/examples/06-extract-sections.ts +55 -0
- package/scripts/examples/07-validation.ts +46 -0
- package/scripts/examples/08-serialization.ts +51 -0
- package/scripts/examples/lib/format.ts +87 -0
- package/scripts/examples/lib/setup.ts +21 -0
- package/scripts/examples/run-all.ts +43 -0
- package/showcases/node_modules/.cache/.repl_history +3 -0
- package/showcases/vinyl-collection/artists/nina-simone.mdx +1 -1
- package/src/__tests__/semantic-search.integration.test.ts +284 -0
- package/src/api/endpoints/actions.ts +34 -0
- package/src/api/endpoints/doc.ts +187 -0
- package/src/api/endpoints/docs-index.ts +26 -0
- package/src/api/endpoints/document.ts +171 -0
- package/src/api/endpoints/documents.ts +71 -0
- package/src/api/endpoints/inspect.ts +16 -0
- package/src/api/endpoints/models.ts +10 -0
- package/src/api/endpoints/query.ts +88 -0
- package/src/api/endpoints/root.ts +7 -0
- package/src/api/endpoints/search-reindex.ts +65 -0
- package/src/api/endpoints/search-status.ts +55 -0
- package/src/api/endpoints/search.ts +104 -0
- package/src/api/endpoints/semantic-search.ts +120 -0
- package/src/api/endpoints/text-search.ts +63 -0
- package/src/api/endpoints/validate.ts +34 -0
- package/src/api/helpers.ts +97 -0
- package/src/base-model.ts +12 -0
- package/src/cli/commands/action.ts +82 -44
- package/src/cli/commands/console.ts +124 -0
- package/src/cli/commands/create.ts +179 -53
- package/src/cli/commands/embed.ts +323 -0
- package/src/cli/commands/export.ts +58 -24
- package/src/cli/commands/extract.ts +174 -0
- package/src/cli/commands/help.ts +81 -0
- package/src/cli/commands/index.ts +17 -0
- package/src/cli/commands/init.ts +72 -48
- package/src/cli/commands/inspect.ts +56 -46
- package/src/cli/commands/mcp.ts +1219 -0
- package/src/cli/commands/search.ts +285 -0
- package/src/cli/commands/serve.ts +348 -0
- package/src/cli/commands/summary.ts +60 -0
- package/src/cli/commands/teach.ts +86 -0
- package/src/cli/commands/text-search.ts +134 -0
- package/src/cli/commands/validate.ts +126 -64
- package/src/cli/index.ts +88 -19
- package/src/cli/load-collection.ts +144 -17
- package/src/cli/registry.ts +28 -0
- package/src/collection.ts +455 -6
- package/src/define-model.ts +104 -7
- package/src/document.ts +47 -1
- package/src/extract-sections.ts +222 -0
- package/src/index.ts +20 -2
- package/src/model-instance.ts +35 -5
- package/src/node-shortcuts.ts +1 -1
- package/src/query/collection-query.ts +96 -9
- package/src/query/index.ts +7 -0
- package/src/query/query-dsl.ts +259 -0
- package/src/relationships/has-many.ts +39 -0
- package/src/relationships/index.ts +7 -2
- package/src/section.ts +2 -0
- package/src/types.ts +24 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/match-pattern.ts +65 -0
- package/src/validator.ts +18 -1
- package/test/collection.test.ts +118 -2
- package/test/extract-sections.test.ts +356 -0
- package/test/fixtures/sdlc/MODELS.md +106 -0
- package/test/fixtures/sdlc/SKILL.md +404 -0
- package/test/fixtures/sdlc/index.ts +9 -0
- package/test/fixtures/sdlc/models.ts +8 -6
- package/test/fixtures/sdlc/stories/authentication/a-user-should-be-able-to-login.mdx +20 -0
- package/test/fixtures/sdlc/templates/epic.md +23 -0
- package/test/fixtures/sdlc/templates/story.md +19 -0
- package/test/pattern.test.ts +191 -0
- package/test/query-dsl.test.ts +431 -0
- package/test/query.test.ts +29 -0
- package/test/relationships.test.ts +130 -0
- package/test/section.test.ts +65 -4
- package/test/table-of-contents.test.ts +135 -0
package/src/cli/commands/init.ts
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
async run({ args }) {
|
|
18
|
-
const name = (args.name as string) || "my-content";
|
|
19
|
-
const dir = path.resolve(process.cwd(), name);
|
|
20
|
-
|
|
21
|
-
await fs.mkdir(dir, { recursive: true });
|
|
22
|
-
await fs.mkdir(path.join(dir, "posts"), { recursive: true });
|
|
23
|
-
|
|
24
|
-
// Create a sample model file
|
|
25
|
-
await fs.writeFile(
|
|
26
|
-
path.join(dir, "models.ts"),
|
|
27
|
-
`import { defineModel, z } from "contentbase";
|
|
1
|
+
import fs from 'fs/promises'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { commands } from '../registry.js'
|
|
4
|
+
|
|
5
|
+
async function handler(_options: any, context: { container: any }) {
|
|
6
|
+
const name = (context.container.argv._[1] as string) || 'my-content'
|
|
7
|
+
const dir = path.resolve(process.cwd(), name)
|
|
8
|
+
|
|
9
|
+
await fs.mkdir(dir, { recursive: true })
|
|
10
|
+
await fs.mkdir(path.join(dir, 'posts'), { recursive: true })
|
|
11
|
+
|
|
12
|
+
await fs.writeFile(
|
|
13
|
+
path.join(dir, 'models.ts'),
|
|
14
|
+
`import { defineModel, z } from "contentbase";
|
|
28
15
|
|
|
29
16
|
export const Post = defineModel("Post", {
|
|
30
17
|
prefix: "posts",
|
|
@@ -34,13 +21,12 @@ export const Post = defineModel("Post", {
|
|
|
34
21
|
}),
|
|
35
22
|
});
|
|
36
23
|
`,
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
'utf8'
|
|
25
|
+
)
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`---
|
|
27
|
+
await fs.writeFile(
|
|
28
|
+
path.join(dir, 'posts', 'hello-world.md'),
|
|
29
|
+
`---
|
|
44
30
|
status: draft
|
|
45
31
|
author: me
|
|
46
32
|
---
|
|
@@ -49,13 +35,12 @@ author: me
|
|
|
49
35
|
|
|
50
36
|
Welcome to your contentbase project!
|
|
51
37
|
`,
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
'utf8'
|
|
39
|
+
)
|
|
54
40
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
`import { Collection } from "contentbase";
|
|
41
|
+
await fs.writeFile(
|
|
42
|
+
path.join(dir, 'index.ts'),
|
|
43
|
+
`import { Collection } from "contentbase";
|
|
59
44
|
import { Post } from "./models";
|
|
60
45
|
|
|
61
46
|
export const collection = new Collection({
|
|
@@ -64,12 +49,51 @@ export const collection = new Collection({
|
|
|
64
49
|
|
|
65
50
|
collection.register(Post);
|
|
66
51
|
`,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
'utf8'
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
console.log(`Created contentbase project at ${dir}`)
|
|
56
|
+
console.log(` ${name}/models.ts`)
|
|
57
|
+
console.log(` ${name}/index.ts`)
|
|
58
|
+
console.log(` ${name}/posts/hello-world.md`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
commands.register('init', {
|
|
62
|
+
description: 'Initialize a new contentbase project',
|
|
63
|
+
help: `# cnotes init
|
|
64
|
+
|
|
65
|
+
Scaffold a new contentbase project with a sample model and document.
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
\`\`\`
|
|
70
|
+
cnotes init [name]
|
|
71
|
+
\`\`\`
|
|
72
|
+
|
|
73
|
+
## Arguments
|
|
74
|
+
|
|
75
|
+
| Argument | Description | Default |
|
|
76
|
+
|----------|-------------|---------|
|
|
77
|
+
| \`name\` | Directory name for the project | \`my-content\` |
|
|
78
|
+
|
|
79
|
+
## What It Creates
|
|
80
|
+
|
|
81
|
+
- \`<name>/models.ts\` — Model definitions with a sample Post model
|
|
82
|
+
- \`<name>/index.ts\` — Collection entry point
|
|
83
|
+
- \`<name>/posts/hello-world.md\` — Sample document
|
|
84
|
+
|
|
85
|
+
## Examples
|
|
86
|
+
|
|
87
|
+
\`\`\`bash
|
|
88
|
+
# Create with default name
|
|
89
|
+
cnotes init
|
|
90
|
+
|
|
91
|
+
# Create with custom name
|
|
92
|
+
cnotes init docs
|
|
93
|
+
|
|
94
|
+
# Create in a subdirectory
|
|
95
|
+
cnotes init content/blog
|
|
96
|
+
\`\`\`
|
|
97
|
+
`,
|
|
98
|
+
handler,
|
|
99
|
+
})
|
|
@@ -1,46 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { commands } from '../registry.js'
|
|
3
|
+
import { loadCollection } from '../load-collection.js'
|
|
4
|
+
|
|
5
|
+
const argsSchema = z.object({
|
|
6
|
+
contentFolder: z.string().optional(),
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
async function handler(options: z.infer<typeof argsSchema>) {
|
|
10
|
+
const collection = await loadCollection({
|
|
11
|
+
contentFolder: options.contentFolder,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
console.log(collection.generateModelSummary())
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
commands.register('inspect', {
|
|
18
|
+
description: 'Display collection info and registered models',
|
|
19
|
+
help: `# cnotes inspect
|
|
20
|
+
|
|
21
|
+
Display a summary of the collection: registered models, their fields, sections, relationships, and document counts.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
\`\`\`
|
|
26
|
+
cnotes inspect [options]
|
|
27
|
+
\`\`\`
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
| Option | Description |
|
|
32
|
+
|--------|-------------|
|
|
33
|
+
| \`--contentFolder\` | Path to content folder |
|
|
34
|
+
|
|
35
|
+
## Output
|
|
36
|
+
|
|
37
|
+
Shows for each model:
|
|
38
|
+
- Prefix and document count
|
|
39
|
+
- Meta field definitions (name, type, required, default)
|
|
40
|
+
- Section headings
|
|
41
|
+
- Relationships (belongsTo, hasMany)
|
|
42
|
+
- Computed properties and named scopes
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
\`\`\`bash
|
|
47
|
+
# Inspect current directory's collection
|
|
48
|
+
cnotes inspect
|
|
49
|
+
|
|
50
|
+
# Inspect a specific content folder
|
|
51
|
+
cnotes inspect --contentFolder test/fixtures/sdlc
|
|
52
|
+
\`\`\`
|
|
53
|
+
`,
|
|
54
|
+
argsSchema,
|
|
55
|
+
handler,
|
|
56
|
+
})
|