contentbase 0.4.2 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentbase",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "repository": "https://github.com/soederpop/contentbase",
5
5
  "website": "https://contentbase.soederpop.com",
6
6
  "type": "module",
@@ -21,9 +21,10 @@
21
21
  "release": "./scripts/release.sh"
22
22
  },
23
23
  "dependencies": {
24
- "luca": ">= 3.0.2",
24
+ "luca": ">= 3.3.0",
25
25
  "gray-matter": "^4.0.3",
26
26
  "js-yaml": "^4.1.0",
27
+ "mdast-util-gfm": "^3.1.0",
27
28
  "mdast-util-mdxjs-esm": "^2.0.1",
28
29
  "mdast-util-to-markdown": "^2.1.2",
29
30
  "mdast-util-to-string": "^4.0.0",
package/src/collection.ts CHANGED
@@ -7,6 +7,8 @@ import { createModelInstance } from "./model-instance";
7
7
  import { pluralize } from "./utils/inflect";
8
8
  import { Base } from "./base-model";
9
9
  import { NodeStorageAdapter } from "./adapters/node-fs";
10
+ import { defineModel, type DefineModelConfig } from "./define-model";
11
+ import type { z } from "zod";
10
12
  import type {
11
13
  ModelDefinition,
12
14
  CollectionItem,
@@ -14,6 +16,7 @@ import type {
14
16
  InferModelInstance,
15
17
  HasManyDefinition,
16
18
  RelationshipDefinition,
19
+ SectionDefinition,
17
20
  StorageAdapter,
18
21
  } from "./types";
19
22
 
@@ -147,6 +150,34 @@ export class Collection {
147
150
  return this;
148
151
  }
149
152
 
153
+ /**
154
+ * Define a model and register it with this collection in one call.
155
+ * Returns the ModelDefinition (with full type inference), not the collection.
156
+ */
157
+ defineModel<
158
+ TName extends string,
159
+ TMeta extends z.ZodType = z.ZodObject<{}, z.core.$loose>,
160
+ TSections extends Record<string, SectionDefinition<any>> = Record<
161
+ string,
162
+ never
163
+ >,
164
+ TRelationships extends Record<
165
+ string,
166
+ RelationshipDefinition<any>
167
+ > = Record<string, never>,
168
+ TComputed extends Record<string, (self: any) => any> = Record<
169
+ string,
170
+ never
171
+ >,
172
+ >(
173
+ name: TName,
174
+ config?: DefineModelConfig<TMeta, TSections, TRelationships, TComputed>
175
+ ): ModelDefinition<TName, TMeta, TSections, TRelationships, TComputed> {
176
+ const definition = defineModel(name, config);
177
+ this.register(definition);
178
+ return definition;
179
+ }
180
+
150
181
  /** Get a model definition by name */
151
182
  getModelDefinition(
152
183
  name: string
@@ -1,9 +1,15 @@
1
1
  import { toMarkdown } from "mdast-util-to-markdown";
2
+ import { gfmToMarkdown } from "mdast-util-gfm";
2
3
  import type { Root } from "mdast";
3
4
 
4
5
  /**
5
6
  * Convert an MDAST tree back to a markdown string.
7
+ *
8
+ * The parse pipeline uses remark-gfm, so ASTs routinely contain GFM nodes
9
+ * (tables, strikethrough, task lists, footnotes). The serializer must carry
10
+ * the matching extensions or toMarkdown throws "Cannot handle unknown node"
11
+ * on any GFM content.
6
12
  */
7
13
  export function stringifyAst(ast: Root): string {
8
- return toMarkdown(ast);
14
+ return toMarkdown(ast, { extensions: [gfmToMarkdown()] });
9
15
  }