Saxonberg Server API
    Preparing search index...

    Base for MongoDB-backed records. NOT in the Stuff hierarchy.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _id?: string

    MongoDB ObjectId (undefined until saved).

    class: string = ''

    Runtime backing class path (e.g. /obj/Avatar).

    createdAt: Date

    Created timestamp (set on construction).

    data: Record<string, unknown> = {}

    Pure hydration payload (mixin-field values, etc.).

    hydratorClass?: string

    Optional Hydrator class path. When ABSENT, the clone pipeline runs no hydrator and data is ignored. Templates that want generic mixin-field copy must opt in by naming '/lib/persistence/PersistentHydrator'.

    path: string = ''

    Canonical path identifier (e.g. /obj/Avatar/abc123, /narnia/castle).

    updatedAt: Date

    Last updated timestamp (set on every save).

    collectionName: string = 'domain'

    Collection name (must be overridden in subclass).

    persistentFields: string[] = ...

    Methods

    • Load data from a MongoDB document into this object.

      Symmetric to toDocument: marshallers transform their assigned fields' raw values via fromStored before bracket-assign hits the runtime setter.

      Parameters

      • doc: Record<string, unknown>

      Returns void

    • Save this object to MongoDB. Updates updatedAt automatically.

      Pre-resolves any registered field marshallers via the async resolver before the sync toDocument walk; the sync resolver lookup inside toDocument then always hits a populated cache.

      Returns Promise<void>

    • Convert this object to a plain document for MongoDB.

      Marshallers (declared via static fieldMarshallers on a mixin or class) intercept their assigned fields: the runtime value-object value is passed through marshaller.toStored before being written into the doc. Fields without a marshaller pass through bracket-read unchanged.

      Returns Record<string, unknown>

    • Materialize a doc as the right Template subclass.

      Folder classes (Zone subclasses, per ZoneApi.isFolderClass) become ZoneTemplate; everything else becomes LeafTemplate. The two subclasses share fields and persistence; the type distinction is what lets callers reason about folder-vs-leaf without sniffing class.

      Constructed with a plain new — a Template is a Document, not a registered Stuff, so there is no StuffApi.create and no registry entry to accumulate.

      Parameters

      • doc: DomainDoc

      Returns Promise<Template>

    • Find the Template at path, or null if none exists.

      Templates are unique by path (enforced by convention; the folder/leaf invariant prevents duplicates from making sense). Returns the first match if multiple somehow exist. Returns the right concrete subclass (ZoneTemplate / LeafTemplate) based on the doc's class field.

      Parameters

      • path: string

      Returns Promise<Template | null>

    • Find every Template whose path is in paths. Returns instances in the order Mongo provides them (no input-order guarantee). Missing paths are silently absent from the result — callers can compare result.length to paths.length. Same materialization rule as findByPath (each doc lands as its concrete subclass).

      Sits alongside findByPath / findDescendants because Template is abstract — the inherited Document.find does new this() which doesn't apply to abstract bases. Callers needing bulk-by-path (contacts roster name lookup, etc.) reach here instead of touching the persistence chokepoint.

      Parameters

      • paths: readonly string[]

      Returns Promise<Template[]>

    • Load a Template by _id and return it as the right subclass (ZoneTemplate / LeafTemplate).

      Distinct from the inherited Document.findById<T>: that method is generic over the calling class and does new this(), which is illegal on the abstract Template base. Concrete subclasses (ZoneTemplate.findById(id) / LeafTemplate.findById(id)) still work via the inherited generic — call them when you statically know the shape. Use Template.loadById when you have only the id and want subclass dispatch.

      Parameters

      • id: string

      Returns Promise<Template | null>

    • Wire the marshaller-resolution seam once at boot (and in tests). Keeps Document free of a StuffApi import while still reaching the Idea-rooted marshaller instances. sync mirrors StuffApi.findByTemplatePath (returns the registered instance or undefined); async mirrors StuffApi.singleton (resolves / lazy-clones the instance, warming the cache sync then hits).

      Parameters

      • sync: SyncMarshallerResolver
      • async: AsyncMarshallerResolver

      Returns void