contentbase 0.1.4 → 0.1.5

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.1.4",
3
+ "version": "0.1.5",
4
4
  "repository": "https://github.com/soederpop/contentbase",
5
5
  "website": "https://contentbase.soederpop.com",
6
6
  "type": "module",
@@ -91,7 +91,8 @@ export function createModelInstance<
91
91
  document,
92
92
  collection,
93
93
  bt,
94
- createModelInstance
94
+ createModelInstance,
95
+ definition
95
96
  );
96
97
  }
97
98
  }
@@ -1,3 +1,4 @@
1
+ import { matchPatterns } from "../utils/match-pattern";
1
2
  import type { Document } from "../document";
2
3
  import type { Collection } from "../collection";
3
4
  import type {
@@ -16,24 +17,32 @@ export class BelongsToRelationship<
16
17
  #collection: Collection;
17
18
  #definition: BelongsToDefinition<TTarget>;
18
19
  #factory: ModelInstanceFactory;
20
+ #sourceDef: ModelDefinition<any, any, any, any, any>;
19
21
 
20
22
  constructor(
21
23
  document: Document,
22
24
  collection: Collection,
23
25
  definition: BelongsToDefinition<TTarget>,
24
- factory: ModelInstanceFactory
26
+ factory: ModelInstanceFactory,
27
+ sourceDef: ModelDefinition<any, any, any, any, any>
25
28
  ) {
26
29
  this.#document = document;
27
30
  this.#collection = collection;
28
31
  this.#definition = definition;
29
32
  this.#factory = factory;
33
+ this.#sourceDef = sourceDef;
30
34
  }
31
35
 
32
36
  fetch(): InferModelInstance<TTarget> {
33
37
  const targetDef = this.#definition.target();
38
+ // Merge pattern-inferred meta with raw frontmatter, same as createModelInstance does
39
+ const patternMeta = this.#sourceDef.pattern
40
+ ? matchPatterns(this.#sourceDef.pattern, this.#document.id) ?? {}
41
+ : {};
42
+ const mergedMeta = { ...(this.#sourceDef.defaults ?? {}), ...patternMeta, ...this.#document.meta };
34
43
  const foreignKeyValue = this.#definition.foreignKey({
35
44
  id: this.#document.id,
36
- meta: this.#document.meta,
45
+ meta: mergedMeta,
37
46
  });
38
47
 
39
48
  const relatedId = `${targetDef.prefix}/${foreignKeyValue}`;
@@ -1,5 +1,6 @@
1
1
  import { toString } from "mdast-util-to-string";
2
2
  import { kebabCase } from "../utils/inflect";
3
+ import { matchPatterns } from "../utils/match-pattern";
3
4
  import type { Document } from "../document";
4
5
  import type { Collection } from "../collection";
5
6
  import type {
@@ -140,7 +141,13 @@ export class HasManyRelationship<
140
141
  for (const pathId of this.#collection.available) {
141
142
  if (!pathId.startsWith(prefix + "/")) continue;
142
143
  const doc = this.#collection.document(pathId);
143
- if (doc.meta[fk] === slug) {
144
+ // Check raw frontmatter first, then fall back to pattern-inferred meta
145
+ let fkValue = doc.meta[fk];
146
+ if (fkValue === undefined && targetDef.pattern) {
147
+ const patternMeta = matchPatterns(targetDef.pattern, pathId);
148
+ if (patternMeta) fkValue = patternMeta[fk];
149
+ }
150
+ if (fkValue === slug) {
144
151
  results.push(this.#factory(doc, targetDef, this.#collection));
145
152
  }
146
153
  }