contentbase 0.4.3 → 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 +2 -2
- package/src/collection.ts +31 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contentbase",
|
|
3
|
-
"version": "0.4.
|
|
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,7 +21,7 @@
|
|
|
21
21
|
"release": "./scripts/release.sh"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"luca": ">= 3.0
|
|
24
|
+
"luca": ">= 3.3.0",
|
|
25
25
|
"gray-matter": "^4.0.3",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"mdast-util-gfm": "^3.1.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
|