Saxonberg Server API
    Preparing search index...

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

    Hierarchy (View Summary)

    Implements

    • User
    Index

    Constructors

    Properties

    _id?: string

    MongoDB ObjectId (undefined until saved).

    anonymous: boolean = false

    Runtime-only marker: this is an anonymous (guest) session with no persisted account. Never saved (not in persistentFields). Set on the ephemeral User the connect path builds for an anon: principal; Login.enter reads it to mint a throwaway guest avatar instead of loading a roster.

    createdAt: Date

    Created timestamp (set on construction).

    googleProfileId?: string

    Associated Google profile ID (MongoDB _id of the GoogleProfile doc). Optional: a Twitch-origin account may carry only twitchProfileId.

    playerIds: string[] = []

    IDs of this user's character slots. Each corresponds to an Avatar template at /obj/Avatar/<playerId> in the domain collection.

    This list is the authoritative "what does this user own" source. Appended on character creation; removed on character deletion.

    twitchProfileId?: string

    Associated Twitch profile ID (MongoDB _id of the TwitchProfile doc). Optional: a Google-origin account may carry only googleProfileId.

    updatedAt: Date

    Last updated timestamp (set on every save).

    ANONYMOUS_PREFIX: "anon:" = 'anon:'

    Session-principal id prefix that marks an anonymous (guest) login — a session with no persisted account behind it. The /auth/guest route mints anon:<nanoid> principals; the connect path recognizes the prefix and constructs an ephemeral, never-saved User instead of a Mongo lookup. This is the authentication axis (authed vs anonymous) — distinct from a character being a guest (Avatar.isGuest).

    collectionName: string = 'users'

    Collection name (must be overridden in subclass).

    persistentFields: string[] = ...

    Persistent fields copied to/from the MongoDB document.

    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

    • The at-least-one-provider invariant predicate — true iff the account is reachable through at least one login provider. Lives on the data object; the link/unlink paths defend the invariant by checking it.

      Returns boolean

    • 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>

    • Map a provider to its FK field name — the single source of truth for the computed-key access the provider-parameterized spine uses (User.find({ [User.profileFieldFor(provider)]: id })) and the at-least-one invariant. Two explicit fields, not a generic identities[] map (premature at N=2).

      Parameters

      • provider: AuthProvider

      Returns "googleProfileId" | "twitchProfileId"

    • 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