• 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

65.12
/lib/collections/BaseCollection.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
    ResCollection,
1✔
11
    type ResRef
1✔
12
} from "resclient-ts";
1✔
13
import util, { type InspectOptions } from "node:util";
1✔
14

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

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

3✔
39
    get isPaginated(): boolean {
3✔
40
        return this.paginationOffset !== null || this.paginationLimit !== null;
×
41
    }
×
42

3✔
43
    get paginationLimit(): number | null {
3✔
44
        const match = this.rid.match(/limit=(\d+)/);
×
45
        return match ? Number(match[1]) : null;
×
46
    }
×
47

3✔
48
    get paginationOffset(): number | null {
3✔
49
        const match = this.rid.match(/offset=(\d+)/);
×
50
        return match ? Number(match[1]) : null;
×
51
    }
×
52

3✔
53
    async fetch(...args: R["__typesOnlyArgs"]): Promise<V extends ResRef<infer T> ? T : V> {
3✔
54
        if (!this.ridConstructor) throw new Error("RID constructor is not defined");
×
55
        const arg = this.ridConstructor.names.reduce((acc, name, index) => {
×
56
            acc[name] = args[index];
×
57
            return acc;
×
58
        }, {} as Record<string, unknown>);
×
59
        const rid = this.ridConstructor(arg);
×
60
        return this.api.get<AnyRes>(rid) as V extends ResRef<infer T> ? T : V;
×
61
    }
×
62

3✔
63
    async getNextPage(): Promise<this | null> {
3✔
64
        if (!this.isPaginated) return null;
×
65
        const offset = this.paginationOffset!;
×
66
        const limit = this.paginationLimit!;
×
67
        const nextOffset = offset + limit;
×
68
        const nextRid = this.rid.replace(/offset=\d+/, `offset=${nextOffset}`);
×
69
        return this.api.get<this>(nextRid);
×
70
    }
×
71
}
3✔
72

1✔
73
export function enableCustomInspectForCollections(): void {
1✔
74
    if (util.inspect.custom in BaseCollection.prototype) return;
4✔
75
    Object.defineProperty(BaseCollection.prototype, util.inspect.custom, {
1✔
76
        value(this: BaseCollection, depth: number, inspectOptions: InspectOptions, inspect: typeof util.inspect): string {
1✔
77
            return inspect(ridOnlyClassAndList(this.constructor as typeof BaseCollection, this.rid, this.list), inspectOptions);
×
78
        }
×
79
    });
1✔
80
}
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