• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WolferyScripting / WolferyJS / #17

01 Sep 2025 09:19PM UTC coverage: 63.335% (+3.5%) from 59.799%
#17

push

DonovanDMC
0.0.6

95 of 253 branches covered (37.55%)

Branch coverage included in aggregate %.

7592 of 11884 relevant lines covered (63.88%)

1.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/lib/models/BaseCollectionModel.ts
1
import type WolferyJS from "../WolferyJS.js";
1✔
2
import { ridOnlyClassAndList } from "../util/Util.js";
1✔
3
import CollectionListeners from "../util/CollectionListeners.js";
1✔
4
import type ResourceIDs from "../generated/ResourceIDs.js";
1✔
5
import {
1✔
6
    type AnyRes,
1✔
7
    copy,
1✔
8
    Properties,
1✔
9
    type ResClient,
1✔
10
    ResCollectionModel,
1✔
11
    type ResCollectionModelOptions,
1✔
12
    type ResRef
1✔
13
} from "resclient-ts";
1✔
14
import util, { type InspectOptions } from "node:util";
1✔
15

1✔
16
export default class BaseCollectionModel<T = unknown, R extends ResourceIDs.RIDFunction<Array<unknown>> = ResourceIDs.RIDFunction<Array<unknown>>> extends ResCollectionModel<T> {
1✔
17
    protected client!: WolferyJS;
1✔
18
    protected ridConstructor?: R;
1✔
19
    listeners!: CollectionListeners<this>;
1✔
20
    constructor(client: WolferyJS, api: ResClient, rid: string, validateItem: (item: T) => boolean, options?: ResCollectionModelOptions<T> & {
1✔
21
        ridConstructor?: R;
1✔
22
    }) {
1✔
23
        super(api, rid, validateItem, options);
1✔
24
        options = copy(options ?? {}, {
1!
25
            ridConstructor: { type: "?function" }
1✔
26
        });
1✔
27
        Properties.of(this)
1✔
28
            .readOnly("client", client)
1✔
29
            .readOnly("ridConstructor", options.ridConstructor)
1✔
30
            .readOnly("listeners", new CollectionListeners(this));
1✔
31
    }
1✔
32

1✔
33
    protected override async _listen(on: boolean, changes = true): Promise<void> {
1✔
34
        await super._listen(on, changes);
1✔
35
        if (on) this.listeners.activate();
1✔
36
        else this.listeners.deactivate();
×
37
    }
1✔
38

1✔
39
    async fetch(...args: R["__typesOnlyArgs"]): Promise<T extends ResRef<infer V> ? V : T> {
1✔
40
        if (!this.ridConstructor) throw new Error("RID constructor is not defined");
×
41
        const arg = this.ridConstructor.names.reduce((acc, name, index) => {
×
42
            acc[name] = args[index];
×
43
            return acc;
×
44
        }, {} as Record<string, unknown>);
×
45
        const rid = this.ridConstructor(arg);
×
46
        return this.api.get<AnyRes>(rid) as T extends ResRef<infer V> ? V : T;
×
47
    }
×
48
}
1✔
49

1✔
50
export function enableCustomInspectForCollectionModels(): void {
1✔
51
    if (util.inspect.custom in BaseCollectionModel.prototype) return;
4✔
52
    Object.defineProperty(BaseCollectionModel.prototype, util.inspect.custom, {
1✔
53
        value(this: BaseCollectionModel, depth: number, inspectOptions: InspectOptions, inspect: typeof util.inspect): string {
1✔
54
            return inspect(ridOnlyClassAndList(this.constructor as typeof BaseCollectionModel, this.rid, this.list), inspectOptions);
×
55
        }
×
56
    });
1✔
57
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc