Fixed library nodes not having a default schema

This commit is contained in:
ThaumRystra
2025-05-02 13:37:11 +02:00
parent 8453bd9d86
commit d42d2a724e
13 changed files with 134 additions and 91 deletions

View File

@@ -3,8 +3,8 @@ import { TreeDoc, treeDocFields, Reference } from '/imports/api/parenting/ChildS
import { getProperties } from '/imports/api/engine/loadCreatures';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
export function getCollectionByName(name: string): Mongo.Collection<TreeDoc> {
const collection = Mongo.Collection.get<TreeDoc>(name)
export function getCollectionByName<T = TreeDoc>(name: string): Mongo.Collection<T> {
const collection = Mongo.Collection.get<T>(name)
if (!collection) {
throw new Meteor.Error('bad-collection-reference',
`Parent references collection ${name}, which does not exist`
@@ -27,8 +27,8 @@ export function fetchDocByRefAsync(ref: Reference, options?: Mongo.Options<objec
return doc;
}
export function fetchDocByRef(ref: Reference, options?: Mongo.Options<object>): TreeDoc {
const doc: TreeDoc = getCollectionByName(ref.collection).findOne(ref.id, options);
export function fetchDocByRef<T extends object = TreeDoc>(ref: Reference, options?: Mongo.Options<object>): T {
const doc: T = getCollectionByName<T>(ref.collection).findOne(ref.id, options);
assertDocFound(doc, ref);
return doc;
}