@platonic-dice/dice 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/die-history/history-cache.d.ts +85 -0
- package/dist/components/die-history/history-cache.d.ts.map +1 -0
- package/dist/components/die-history/index.d.ts +3 -0
- package/dist/components/die-history/index.d.ts.map +1 -0
- package/dist/components/die-history/internal/index.d.ts +3 -0
- package/dist/components/die-history/internal/index.d.ts.map +1 -0
- package/dist/components/die-history/internal/roll-record-manager/index.d.ts +2 -0
- package/dist/components/die-history/internal/roll-record-manager/index.d.ts.map +1 -0
- package/dist/components/die-history/internal/roll-record-manager/internal/index.d.ts +2 -0
- package/dist/components/die-history/internal/roll-record-manager/internal/index.d.ts.map +1 -0
- package/dist/components/die-history/internal/roll-record-manager/internal/roll-record-storage.d.ts +37 -0
- package/dist/components/die-history/internal/roll-record-manager/internal/roll-record-storage.d.ts.map +1 -0
- package/dist/components/die-history/internal/roll-record-manager/roll-record-manager.d.ts +87 -0
- package/dist/components/die-history/internal/roll-record-manager/roll-record-manager.d.ts.map +1 -0
- package/dist/components/die-history/internal/roll-record-validator.d.ts +26 -0
- package/dist/components/die-history/internal/roll-record-validator.d.ts.map +1 -0
- package/dist/components/die-history/roll-record-factory.d.ts +90 -0
- package/dist/components/die-history/roll-record-factory.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/die.d.ts +197 -0
- package/dist/die.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/roll-record.types.d.ts +42 -0
- package/dist/types/roll-record.types.d.ts.map +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RollRecordManager } from "./internal/index.js";
|
|
2
|
+
import type { RollRecord } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* A wrapper for RollRecordManager that maintains multiple, independently capped histories.
|
|
5
|
+
*
|
|
6
|
+
* Useful for scenarios where a single RollRecordManager needs to support "history parking",
|
|
7
|
+
* such as storing separate roll histories per modifier or context.
|
|
8
|
+
*
|
|
9
|
+
* @template R - The type of roll records stored
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A wrapper for RollRecordManager that maintains multiple, independently capped histories.
|
|
13
|
+
*
|
|
14
|
+
* Useful for scenarios where a single RollRecordManager needs to support "history parking",
|
|
15
|
+
* such as storing separate roll histories per modifier or context.
|
|
16
|
+
*
|
|
17
|
+
* @template R - The type of roll records stored
|
|
18
|
+
*/
|
|
19
|
+
export declare class HistoryCache<R extends RollRecord = RollRecord> {
|
|
20
|
+
private readonly cache;
|
|
21
|
+
private readonly maxRecordsPerKey;
|
|
22
|
+
private readonly maxKeys;
|
|
23
|
+
private activeKey;
|
|
24
|
+
constructor({ maxRecordsPerKey, maxKeys, }?: {
|
|
25
|
+
maxRecordsPerKey?: number | undefined;
|
|
26
|
+
maxKeys?: number | undefined;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Sets the currently active history key. If the key does not exist it will be created.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} key - History key to activate.
|
|
32
|
+
*/
|
|
33
|
+
setActiveKey(key: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the currently active RollRecordManager for the active key.
|
|
36
|
+
*
|
|
37
|
+
* @returns {RollRecordManager<R> | undefined} The manager for the active key (if any).
|
|
38
|
+
*/
|
|
39
|
+
get activeManager(): RollRecordManager<R> | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Adds a roll record to the active history.
|
|
42
|
+
*
|
|
43
|
+
* @param {R} record - The roll record to add.
|
|
44
|
+
* @throws {Error} If no active history key is set.
|
|
45
|
+
*/
|
|
46
|
+
add(record: R): void;
|
|
47
|
+
/**
|
|
48
|
+
* Returns a copy of the roll records for the active key.
|
|
49
|
+
*
|
|
50
|
+
* @param {boolean} [verbose=false] - When true include timestamps.
|
|
51
|
+
* @returns {R[] | Omit<R, "timestamp">[]} Array of records for the active key.
|
|
52
|
+
*/
|
|
53
|
+
getAll(verbose?: boolean): R[] | Omit<R, "timestamp">[];
|
|
54
|
+
/**
|
|
55
|
+
* Clears all roll records for the active key.
|
|
56
|
+
*/
|
|
57
|
+
clearActive(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Clears all cached histories and resets the active key.
|
|
60
|
+
*/
|
|
61
|
+
clearAll(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a roll history report for all cached keys.
|
|
64
|
+
*
|
|
65
|
+
* @param {{limit?: number, verbose?: boolean}} [options] - Report options.
|
|
66
|
+
* @returns {Record<string, (R | Omit<R, "timestamp">)[]>} Map of key→records.
|
|
67
|
+
*/
|
|
68
|
+
report({ limit, verbose, }?: {
|
|
69
|
+
limit?: number;
|
|
70
|
+
verbose?: boolean;
|
|
71
|
+
}): Record<string, (R | Omit<R, "timestamp">)[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns a string summary of the cache.
|
|
74
|
+
*
|
|
75
|
+
* @returns {string} Summary containing number of keys and active key.
|
|
76
|
+
*/
|
|
77
|
+
toString(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Returns a JSON-friendly object mapping keys to arrays of RollRecords.
|
|
80
|
+
*
|
|
81
|
+
* @returns {Record<string, R[]>} The cache contents as plain arrays.
|
|
82
|
+
*/
|
|
83
|
+
toJSON(): Record<string, R[]>;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=history-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-cache.d.ts","sourceRoot":"","sources":["../../../src/components/die-history/history-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAuB,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;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
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/die-history/internal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/die-history/internal/roll-record-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/die-history/internal/roll-record-manager/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/dist/components/die-history/internal/roll-record-manager/internal/roll-record-storage.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RollRecord } from "../../../../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Simple in-memory storage for roll records with a fixed capacity.
|
|
4
|
+
*
|
|
5
|
+
* This class focuses solely on storage and eviction policy. It does not
|
|
6
|
+
* perform shape validation of records (delegated to validators elsewhere).
|
|
7
|
+
*/
|
|
8
|
+
export declare class RollRecordStorage<R extends RollRecord = RollRecord> {
|
|
9
|
+
private records;
|
|
10
|
+
private readonly maxRecords;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new storage container.
|
|
13
|
+
* @param maxRecords Maximum number of records to retain (FIFO eviction).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Create a new storage container.
|
|
17
|
+
*
|
|
18
|
+
* @param {number} [maxRecords=1000] Maximum number of records to retain (FIFO eviction).
|
|
19
|
+
*/
|
|
20
|
+
constructor(maxRecords?: number);
|
|
21
|
+
/** Number of records currently stored */
|
|
22
|
+
get size(): number;
|
|
23
|
+
/** Configured maximum number of records */
|
|
24
|
+
get maxRecordsCount(): number;
|
|
25
|
+
/** Returns a shallow copy of all records (timestamps preserved) */
|
|
26
|
+
get full(): R[];
|
|
27
|
+
/** Add a new record and evict oldest if capacity exceeded */
|
|
28
|
+
add(record: R): void;
|
|
29
|
+
/** Clear all stored records */
|
|
30
|
+
clear(): void;
|
|
31
|
+
/** Return the most recent N records in chronological order (oldest first) */
|
|
32
|
+
last(n?: number): R[];
|
|
33
|
+
/** JSON-friendly copy of stored records */
|
|
34
|
+
toJSON(): R[];
|
|
35
|
+
}
|
|
36
|
+
export default RollRecordStorage;
|
|
37
|
+
//# sourceMappingURL=roll-record-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roll-record-storage.d.ts","sourceRoot":"","sources":["../../../../../../src/components/die-history/internal/roll-record-manager/internal/roll-record-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAC9D,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC;;;OAGG;IACH;;;;OAIG;gBACS,UAAU,GAAE,MAAa;IAOrC,yCAAyC;IACzC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,2CAA2C;IAC3C,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,mEAAmE;IACnE,IAAI,IAAI,IAAI,CAAC,EAAE,CAEd;IAED,6DAA6D;IAC7D,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAWpB,+BAA+B;IAC/B,KAAK,IAAI,IAAI;IAIb,6EAA6E;IAC7E,IAAI,CAAC,CAAC,GAAE,MAAU,GAAG,CAAC,EAAE;IAUxB,2CAA2C;IAC3C,MAAM,IAAI,CAAC,EAAE;CAGd;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { RollRecord } from "../../../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default maximum number of roll records stored.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_MAX_RECORDS = 1000;
|
|
6
|
+
/**
|
|
7
|
+
* Utility class for managing roll history of Die and child/composite classes.
|
|
8
|
+
*
|
|
9
|
+
* Provides methods to add roll records, retrieve the last N rolls,
|
|
10
|
+
* produce history reports, and manage roll record storage.
|
|
11
|
+
*
|
|
12
|
+
* @template R Type of roll record, defaults to all RollRecord variants.
|
|
13
|
+
*/
|
|
14
|
+
export declare class RollRecordManager<R extends RollRecord = RollRecord> {
|
|
15
|
+
/** Internal storage of roll records */
|
|
16
|
+
private storage;
|
|
17
|
+
/** Maximum number of roll records to retain */
|
|
18
|
+
private maxRecords;
|
|
19
|
+
/**
|
|
20
|
+
* Create a RollRecordManager.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} [maxRecords=DEFAULT_MAX_RECORDS] - Maximum records to retain.
|
|
23
|
+
*/
|
|
24
|
+
constructor(maxRecords?: number);
|
|
25
|
+
/**
|
|
26
|
+
* Returns a copy of all roll records (including timestamps).
|
|
27
|
+
*
|
|
28
|
+
* @returns {R[]} All records (timestamps preserved).
|
|
29
|
+
*/
|
|
30
|
+
get full(): R[];
|
|
31
|
+
/**
|
|
32
|
+
* Returns a copy of all roll records with timestamps stripped.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Omit<R, "timestamp">[]} Records without timestamps.
|
|
35
|
+
*/
|
|
36
|
+
get all(): Omit<R, "timestamp">[];
|
|
37
|
+
/**
|
|
38
|
+
* Returns the number of roll records stored.
|
|
39
|
+
*
|
|
40
|
+
* @returns {number} Number of stored records.
|
|
41
|
+
*/
|
|
42
|
+
get length(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the configured maximum number of roll records.
|
|
45
|
+
*
|
|
46
|
+
* @returns {number} Maximum records configured.
|
|
47
|
+
*/
|
|
48
|
+
get maxRecordsCount(): number;
|
|
49
|
+
/**
|
|
50
|
+
* Adds a roll record to the history.
|
|
51
|
+
*
|
|
52
|
+
* @param {R} record - The record to add.
|
|
53
|
+
* @throws {TypeError} If the record is not a valid roll record shape.
|
|
54
|
+
*/
|
|
55
|
+
add(record: R): void;
|
|
56
|
+
/**
|
|
57
|
+
* Clears the roll history storage.
|
|
58
|
+
*/
|
|
59
|
+
clear(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the last N roll records.
|
|
62
|
+
*
|
|
63
|
+
* @param {number} [n=1] - Number of records to retrieve.
|
|
64
|
+
* @param {boolean} [verbose=false] - Include timestamps when true.
|
|
65
|
+
* @returns {(R | Omit<R, "timestamp">)[]} Array of records.
|
|
66
|
+
*/
|
|
67
|
+
last(n?: number, verbose?: boolean): (R | Omit<R, "timestamp">)[];
|
|
68
|
+
/**
|
|
69
|
+
* Produces a roll history report based on the given options.
|
|
70
|
+
*
|
|
71
|
+
* @param {{limit?: number; verbose?: boolean}} [options]
|
|
72
|
+
* @returns {(R | Omit<R, "timestamp">)[]} An array of records per options.
|
|
73
|
+
*/
|
|
74
|
+
report(options?: {
|
|
75
|
+
limit?: number;
|
|
76
|
+
verbose?: boolean;
|
|
77
|
+
}): (R | Omit<R, "timestamp">)[];
|
|
78
|
+
/**
|
|
79
|
+
* Human-readable string summary of roll history.
|
|
80
|
+
*
|
|
81
|
+
* @returns {string} Summary that contains last roll and counts.
|
|
82
|
+
*/
|
|
83
|
+
toString(): string;
|
|
84
|
+
/** Returns the full history as an array of records */
|
|
85
|
+
toJSON(): R[];
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=roll-record-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roll-record-manager.d.ts","sourceRoot":"","sources":["../../../../../src/components/die-history/internal/roll-record-manager/roll-record-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAU9C;;GAEG;AACH,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC;;;;;;;GAOG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAC9D,uCAAuC;IACvC,OAAO,CAAC,OAAO,CAAuB;IACtC,+CAA+C;IAC/C,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;OAIG;gBACS,UAAU,GAAE,MAA4B;IAKpD;;;;OAIG;IACH,IAAI,IAAI,IAAI,CAAC,EAAE,CAEd;IAED;;;;OAIG;IACH,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,CAEhC;IAED;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;OAIG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;;;;OAKG;IACH,GAAG,CAAC,MAAM,EAAE,CAAC;IAkBb;;OAEG;IACH,KAAK;IAIL;;;;;;OAMG;IACH,IAAI,CAAC,CAAC,GAAE,MAAU,EAAE,OAAO,UAAQ,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE;IAWlE;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE;IAMhC;;;;OAIG;IACH,QAAQ,IAAI,MAAM;IAUlB,sDAAsD;IACtD,MAAM,IAAI,CAAC,EAAE;CAId"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RollRecord, DieRollRecord, ModifiedDieRollRecord, TestDieRollRecord, ModifiedTestDieRollRecord } from "../../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime type-guards for RollRecord shapes.
|
|
4
|
+
* Kept intentionally small and side-effect free.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isDieRollRecord(record: RollRecord | null | undefined): record is DieRollRecord;
|
|
7
|
+
export declare function isModifiedDieRollRecord(record: RollRecord | null | undefined): record is ModifiedDieRollRecord;
|
|
8
|
+
export declare function isTargetDieRollRecord(record: RollRecord | null | undefined): record is TestDieRollRecord;
|
|
9
|
+
export declare function isModifiedTestDieRollRecord(record: RollRecord | null | undefined): record is ModifiedTestDieRollRecord;
|
|
10
|
+
/**
|
|
11
|
+
* Remove timestamp property from a record (immutable-friendly).
|
|
12
|
+
*
|
|
13
|
+
* @template R
|
|
14
|
+
* @param {R} record - The record to strip timestamp from.
|
|
15
|
+
* @returns {Omit<R, "timestamp">} The record without the timestamp property.
|
|
16
|
+
*/
|
|
17
|
+
export declare function stripTimestamp<R extends RollRecord>(record: R): Omit<R, "timestamp">;
|
|
18
|
+
declare const _default: {
|
|
19
|
+
isDieRollRecord: typeof isDieRollRecord;
|
|
20
|
+
isModifiedDieRollRecord: typeof isModifiedDieRollRecord;
|
|
21
|
+
isTargetDieRollRecord: typeof isTargetDieRollRecord;
|
|
22
|
+
isModifiedTestDieRollRecord: typeof isModifiedTestDieRollRecord;
|
|
23
|
+
stripTimestamp: typeof stripTimestamp;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
26
|
+
//# sourceMappingURL=roll-record-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roll-record-validator.d.ts","sourceRoot":"","sources":["../../../../src/components/die-history/internal/roll-record-validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACpC,MAAM,IAAI,aAAa,CAQzB;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACpC,MAAM,IAAI,qBAAqB,CAQjC;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACpC,MAAM,IAAI,iBAAiB,CAS7B;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACpC,MAAM,IAAI,yBAAyB,CASrC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,EACjD,MAAM,EAAE,CAAC,GACR,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,CAGtB;;;;;;;;AAED,wBAME"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { RollModifierFunction, RollModifierInstance, TestConditionsInstance } from "@platonic-dice/core";
|
|
2
|
+
import type { DieTypeValue, TestTypeValue, RollTypeValue } from "@platonic-dice/core";
|
|
3
|
+
import type { DieRollRecord, ModifiedDieRollRecord, TestDieRollRecord, ModifiedTestDieRollRecord } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Factory interface for producing RollRecord values.
|
|
6
|
+
*
|
|
7
|
+
* This module centralizes the creation of roll records (normal, modified
|
|
8
|
+
* and test rolls). The implementation intentionally keeps a small public
|
|
9
|
+
* surface: callers request a record and receive a validated object ready
|
|
10
|
+
* to be persisted in history. The default implementation delegates to the
|
|
11
|
+
* `@platonic-dice/core` roll functions and stamps records with the system
|
|
12
|
+
* clock. No constructor-based dependency injection is used here to keep
|
|
13
|
+
* the API simple; tests can still override behaviour by calling the
|
|
14
|
+
* factory methods directly.
|
|
15
|
+
*/
|
|
16
|
+
export interface IRollRecordFactory {
|
|
17
|
+
/**
|
|
18
|
+
* Create a simple numeric roll record for the given die.
|
|
19
|
+
*
|
|
20
|
+
* @param {DieTypeValue} dieType - The die type (e.g. `DieType.D6`).
|
|
21
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode (advantage/disadvantage).
|
|
22
|
+
* @returns {DieRollRecord} A validated die roll record containing `roll` and `timestamp`.
|
|
23
|
+
* @throws {TypeError} If `rollType` is not a valid `RollTypeValue`.
|
|
24
|
+
*/
|
|
25
|
+
createNormalRoll(dieType: DieTypeValue, rollType?: RollTypeValue): DieRollRecord;
|
|
26
|
+
/**
|
|
27
|
+
* Create a modified roll record. The modifier may be a numeric or
|
|
28
|
+
* functional modifier; the factory resolves base and modified values.
|
|
29
|
+
*
|
|
30
|
+
* @param {DieTypeValue} dieType - The die type to roll.
|
|
31
|
+
* @param {RollModifierFunction|RollModifierInstance} modifier - Modifier applied to the base roll.
|
|
32
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode.
|
|
33
|
+
* @returns {ModifiedDieRollRecord} A validated modified roll record.
|
|
34
|
+
*/
|
|
35
|
+
createModifiedRoll(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, rollType?: RollTypeValue): ModifiedDieRollRecord;
|
|
36
|
+
/**
|
|
37
|
+
* Create a test roll record. `testConditions` may be a plain object or
|
|
38
|
+
* a `TestConditionsInstance` — the core library will normalise and
|
|
39
|
+
* validate it. The returned record contains `roll` and `outcome`.
|
|
40
|
+
*
|
|
41
|
+
* @param {DieTypeValue} dieType - The die type to roll.
|
|
42
|
+
* @param {TestConditionsInstance|{ testType: TestTypeValue; [k: string]: any }} testConditions - Test descriptor or instance.
|
|
43
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode.
|
|
44
|
+
* @returns {TestDieRollRecord} A validated test roll record containing `roll`, `outcome`, and `timestamp`.
|
|
45
|
+
*/
|
|
46
|
+
createTestRoll(dieType: DieTypeValue, testConditions: TestConditionsInstance | {
|
|
47
|
+
testType: TestTypeValue;
|
|
48
|
+
[k: string]: any;
|
|
49
|
+
}, rollType?: RollTypeValue): TestDieRollRecord;
|
|
50
|
+
/**
|
|
51
|
+
* Create a modified test roll record. Combines modifier and test evaluation.
|
|
52
|
+
*
|
|
53
|
+
* @param {DieTypeValue} dieType - The die type to roll.
|
|
54
|
+
* @param {RollModifierFunction|RollModifierInstance} modifier - Modifier applied to the base roll.
|
|
55
|
+
* @param {TestConditionsInstance|{ testType: TestTypeValue; [k: string]: any }} testConditions - Test descriptor or instance.
|
|
56
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode.
|
|
57
|
+
* @param {{useNaturalCrits?: boolean}} [options] - Optional configuration for natural crits.
|
|
58
|
+
* @returns {ModifiedTestDieRollRecord} A validated modified test roll record containing `roll`, `modified`, `outcome`, and `timestamp`.
|
|
59
|
+
*/
|
|
60
|
+
createModifiedTestRoll(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, testConditions: TestConditionsInstance | {
|
|
61
|
+
testType: TestTypeValue;
|
|
62
|
+
[k: string]: any;
|
|
63
|
+
}, rollType?: RollTypeValue, options?: {
|
|
64
|
+
useNaturalCrits?: boolean;
|
|
65
|
+
}): ModifiedTestDieRollRecord;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Default implementation that delegates to `@platonic-dice/core` and uses
|
|
69
|
+
* the system clock. This keeps the public API simple and avoids DI.
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* Implementation of RollRecordFactory that delegates to @platonic-dice/core and uses the system clock.
|
|
73
|
+
* This keeps the public API simple and avoids DI.
|
|
74
|
+
*/
|
|
75
|
+
export declare class RollRecordFactory implements IRollRecordFactory {
|
|
76
|
+
createNormalRoll(dieType: DieTypeValue, rollType?: RollTypeValue): DieRollRecord;
|
|
77
|
+
createModifiedRoll(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, rollType?: RollTypeValue): ModifiedDieRollRecord;
|
|
78
|
+
createTestRoll(dieType: DieTypeValue, testConditions: TestConditionsInstance | {
|
|
79
|
+
testType: TestTypeValue;
|
|
80
|
+
[k: string]: any;
|
|
81
|
+
}, rollType?: RollTypeValue): TestDieRollRecord;
|
|
82
|
+
createModifiedTestRoll(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, testConditions: TestConditionsInstance | {
|
|
83
|
+
testType: TestTypeValue;
|
|
84
|
+
[k: string]: any;
|
|
85
|
+
}, rollType?: RollTypeValue, options?: {
|
|
86
|
+
useNaturalCrits?: boolean;
|
|
87
|
+
}): ModifiedTestDieRollRecord;
|
|
88
|
+
}
|
|
89
|
+
export default RollRecordFactory;
|
|
90
|
+
//# sourceMappingURL=roll-record-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roll-record-factory.d.ts","sourceRoot":"","sources":["../../../src/components/die-history/roll-record-factory.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAWrB;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;OAOG;IACH,gBAAgB,CACd,OAAO,EAAE,YAAY,EACrB,QAAQ,CAAC,EAAE,aAAa,GACvB,aAAa,CAAC;IAEjB;;;;;;;;OAQG;IACH,kBAAkB,CAChB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,oBAAoB,GAAG,oBAAoB,EACrD,QAAQ,CAAC,EAAE,aAAa,GACvB,qBAAqB,CAAC;IAEzB;;;;;;;;;OASG;IACH,cAAc,CACZ,OAAO,EAAE,YAAY,EACrB,cAAc,EACV,sBAAsB,GACtB;QAAE,QAAQ,EAAE,aAAa,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EACjD,QAAQ,CAAC,EAAE,aAAa,GACvB,iBAAiB,CAAC;IAErB;;;;;;;;;OASG;IACH,sBAAsB,CACpB,OAAO,EA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CAAC"}
|
package/dist/die.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { DieTypeValue, RollModifierFunction, RollModifierInstance, TestConditionsInstance } from "@platonic-dice/core";
|
|
2
|
+
import type { RollTypeValue, TestTypeValue } from "@platonic-dice/core";
|
|
3
|
+
import { HistoryCache } from "./components/index.js";
|
|
4
|
+
import type { RollRecord } from "./types/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Represents a single die with flexible history tracking.
|
|
7
|
+
*
|
|
8
|
+
* The Die class provides:
|
|
9
|
+
* - Normal rolls (numeric)
|
|
10
|
+
* - Modified rolls (numeric or functional modifiers)
|
|
11
|
+
* - Test rolls (success/failure evaluation)
|
|
12
|
+
*
|
|
13
|
+
* Each roll type is stored independently in a `RollHistoryCache`.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* ```ts
|
|
17
|
+
* const d20 = new Die(DieType.D20);
|
|
18
|
+
* const result = d20.roll(); // normal roll
|
|
19
|
+
* const modResult = d20.rollMod(n => n + 2); // modified roll
|
|
20
|
+
* const testResult = d20.rollTest({ testType: "AtLeast", target: 15 });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class Die {
|
|
24
|
+
private readonly typeValue;
|
|
25
|
+
private readonly rolls;
|
|
26
|
+
private resultValue?;
|
|
27
|
+
private readonly recordFactory;
|
|
28
|
+
/** Keys used internally for history separation */
|
|
29
|
+
private static readonly NORMAL_KEY;
|
|
30
|
+
private static readonly MODIFIER_KEY;
|
|
31
|
+
private static readonly TEST_KEY;
|
|
32
|
+
private static readonly MODIFIED_TEST_KEY;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new Die instance.
|
|
35
|
+
* @param type - The die type (must be a value from `DieType`)
|
|
36
|
+
* @param historyCache - Optional custom `RollHistoryCache` instance
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Create a new Die instance.
|
|
40
|
+
*
|
|
41
|
+
* @param {DieTypeValue} type - The die type (must be a value from `DieType`).
|
|
42
|
+
* @param {HistoryCache<RollRecord>} [historyCache] - Optional custom history cache instance.
|
|
43
|
+
* @throws {Error} If `type` is not a valid `DieType` value.
|
|
44
|
+
*/
|
|
45
|
+
constructor(type: DieTypeValue, historyCache?: HistoryCache<RollRecord>);
|
|
46
|
+
/**
|
|
47
|
+
* Notes on behavior and contracts
|
|
48
|
+
* - `resultValue` holds the most recent numeric value produced by a roll
|
|
49
|
+
* operation. It is updated from factory-produced records: for normal and
|
|
50
|
+
* test rolls it tracks `record.roll`; for modified rolls it tracks
|
|
51
|
+
* `record.modified`.
|
|
52
|
+
* - `rolls` is a `HistoryCache` that stores separate histories keyed by
|
|
53
|
+
* roll type (normal/modifier/test). Each public roll method sets the
|
|
54
|
+
* corresponding active key, creates a factory-produced record and adds
|
|
55
|
+
* it to the active history. Record shape validation happens at the
|
|
56
|
+
* `RollRecordManager.add()` boundary.
|
|
57
|
+
*/
|
|
58
|
+
/** The die type (e.g., `d6`, `d20`) */
|
|
59
|
+
get type(): DieTypeValue;
|
|
60
|
+
/** The most recent numeric roll result, or undefined if not rolled yet */
|
|
61
|
+
get result(): number | undefined;
|
|
62
|
+
/** Number of faces on this die */
|
|
63
|
+
get faceCount(): number;
|
|
64
|
+
/**
|
|
65
|
+
* Reset the most recent result.
|
|
66
|
+
* @param complete - If true, clears all histories for all roll types
|
|
67
|
+
*/
|
|
68
|
+
reset(complete?: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* Perform a normal die roll.
|
|
71
|
+
* @param rollType - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`)
|
|
72
|
+
* @returns The numeric result
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* Perform a normal die roll.
|
|
76
|
+
*
|
|
77
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`).
|
|
78
|
+
* @returns {number} The numeric result of the roll.
|
|
79
|
+
* @throws {Error} If `rollType` is provided but invalid.
|
|
80
|
+
*/
|
|
81
|
+
roll(rollType?: RollTypeValue): number;
|
|
82
|
+
/**
|
|
83
|
+
* Perform a roll with a modifier.
|
|
84
|
+
*
|
|
85
|
+
* @param modifier - Numeric or functional modifier (function `(n: number) => number` or `RollModifierInstance`)
|
|
86
|
+
* @param rollType - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`)
|
|
87
|
+
* @returns The modified numeric result
|
|
88
|
+
*
|
|
89
|
+
* Example:
|
|
90
|
+
* ```ts
|
|
91
|
+
* d20.rollMod(n => n + 2); // adds +2 to the roll
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Perform a roll with a modifier.
|
|
96
|
+
*
|
|
97
|
+
* @param {RollModifierFunction | RollModifierInstance} modifier - Numeric or functional modifier applied to the base roll.
|
|
98
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`).
|
|
99
|
+
* @returns {number} The modified numeric result.
|
|
100
|
+
* @example
|
|
101
|
+
* d20.rollMod(n => n + 2); // adds +2 to the roll
|
|
102
|
+
*/
|
|
103
|
+
rollMod(modifier: RollModifierFunction | RollModifierInstance, rollType?: RollTypeValue): number;
|
|
104
|
+
/**
|
|
105
|
+
* Perform a roll against test conditions (success/failure evaluation).
|
|
106
|
+
*
|
|
107
|
+
* @param testConditions - Test conditions (plain object or `TestConditionsInstance`)
|
|
108
|
+
* @param rollType - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`)
|
|
109
|
+
* @returns The base numeric roll
|
|
110
|
+
*
|
|
111
|
+
* Example:
|
|
112
|
+
* ```ts
|
|
113
|
+
* d20.rollTest({ testType: "AtLeast", target: 15 });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* Perform a roll against test conditions (success/failure evaluation).
|
|
118
|
+
*
|
|
119
|
+
* @param {TestConditionsInstance | { testType: TestTypeValue; [k: string]: any }} testConditions - Test conditions (plain object or normalized `TestConditions` instance).
|
|
120
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`).
|
|
121
|
+
* @returns {number} The base numeric roll used to evaluate the test.
|
|
122
|
+
* @throws {Error} If `testConditions` or `rollType` are invalid (delegated to core).
|
|
123
|
+
* @example
|
|
124
|
+
* d20.rollTest({ testType: "at_least", target: 15 });
|
|
125
|
+
*/
|
|
126
|
+
rollTest(testConditions: TestConditionsInstance | {
|
|
127
|
+
testType: TestTypeValue;
|
|
128
|
+
[k: string]: any;
|
|
129
|
+
}, rollType?: RollTypeValue): number;
|
|
130
|
+
/**
|
|
131
|
+
* Perform a roll with a modifier and evaluate against test conditions.
|
|
132
|
+
* Combines rollMod and rollTest functionality.
|
|
133
|
+
*
|
|
134
|
+
* @param {RollModifierFunction | RollModifierInstance} modifier - Numeric or functional modifier applied to the base roll.
|
|
135
|
+
* @param {TestConditionsInstance | { testType: TestTypeValue; [k: string]: any }} testConditions - Test conditions (plain object or normalized `TestConditions` instance).
|
|
136
|
+
* @param {RollTypeValue} [rollType] - Optional roll mode (`RollType.Advantage` / `RollType.Disadvantage`).
|
|
137
|
+
* @param {{useNaturalCrits?: boolean}} [options] - Optional configuration for natural crits behavior.
|
|
138
|
+
* @returns {number} The modified numeric result.
|
|
139
|
+
* @throws {Error} If inputs are invalid (delegated to core).
|
|
140
|
+
* @example
|
|
141
|
+
* d20.rollModTest(n => n + 5, { testType: "at_least", target: 15 });
|
|
142
|
+
*/
|
|
143
|
+
rollModTest(modifier: RollModifierFunction | RollModifierInstance, testConditions: TestConditionsInstance | {
|
|
144
|
+
testType: TestTypeValue;
|
|
145
|
+
[k: string]: any;
|
|
146
|
+
}, rollType?: RollTypeValue, options?: {
|
|
147
|
+
useNaturalCrits?: boolean;
|
|
148
|
+
}): number;
|
|
149
|
+
/**
|
|
150
|
+
* Retrieve roll history for a given key.
|
|
151
|
+
*
|
|
152
|
+
* @param key - `"normal" | "modifier" | "test"`
|
|
153
|
+
* @param verbose - Include timestamps if true
|
|
154
|
+
* @returns Array of roll records (timestamps included if verbose)
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
* Retrieve roll history for a given key.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} [key=Die.NORMAL_KEY] - One of "normal" | "modifier" | "test" | "modifiedTest".
|
|
160
|
+
* @param {boolean} [verbose=false] - Include timestamps when true.
|
|
161
|
+
* @returns {Array} Array of roll records (timestamps included when verbose).
|
|
162
|
+
*/
|
|
163
|
+
history(key?: string, verbose?: boolean): RollRecord[] | Omit<RollRecord, "timestamp">[];
|
|
164
|
+
/**
|
|
165
|
+
* Retrieve a roll report for a specific key.
|
|
166
|
+
*
|
|
167
|
+
* @param key - `"normal" | "modifier" | "test"`
|
|
168
|
+
* @param options - Optional report options (`limit` and `verbose`)
|
|
169
|
+
* @returns Array of roll records (subject to limit and verbose)
|
|
170
|
+
*/
|
|
171
|
+
/**
|
|
172
|
+
* Retrieve a roll report for a specific key.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} [key=Die.NORMAL_KEY] - History key to report on.
|
|
175
|
+
* @param {{limit?: number, verbose?: boolean}} [options] - Report options.
|
|
176
|
+
* @returns {Array} Array of roll records (subject to `limit` and `verbose`).
|
|
177
|
+
*/
|
|
178
|
+
report(key?: string, options?: {
|
|
179
|
+
limit?: number;
|
|
180
|
+
verbose?: boolean;
|
|
181
|
+
}): (RollRecord | Omit<RollRecord, "timestamp">)[];
|
|
182
|
+
/** Human-readable summary of the die */
|
|
183
|
+
/**
|
|
184
|
+
* Human-readable summary of the die
|
|
185
|
+
*
|
|
186
|
+
* @returns {string} Short description including last result if present.
|
|
187
|
+
*/
|
|
188
|
+
toString(): string;
|
|
189
|
+
/** JSON representation of all histories keyed by roll type */
|
|
190
|
+
/**
|
|
191
|
+
* JSON representation of all histories keyed by roll type
|
|
192
|
+
*
|
|
193
|
+
* @returns {Record<string, RollRecord[]>} Mapping of history keys to arrays of records.
|
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
|
+
/**
|
|
2
|
+
* @module @platonic-dice/dice
|
|
3
|
+
* @description
|
|
4
|
+
* Persistent dice objects with roll history and TypeScript support.
|
|
5
|
+
*/
|
|
6
|
+
export { Die } from "./die.js";
|
|
7
|
+
import core from "@platonic-dice/core";
|
|
8
|
+
export declare const DieType: Readonly<{
|
|
9
|
+
D4: "d4";
|
|
10
|
+
D6: "d6";
|
|
11
|
+
D8: "d8";
|
|
12
|
+
D10: "d10";
|
|
13
|
+
D12: "d12";
|
|
14
|
+
D20: "d20";
|
|
15
|
+
}>, RollType: Readonly<{
|
|
16
|
+
Advantage: "advantage";
|
|
17
|
+
Disadvantage: "disadvantage";
|
|
18
|
+
}>, rollModTest: typeof core.rollModTest;
|
|
19
|
+
export type { DieTypeValue, RollModifierFunction, RollModifierInstance, TestConditionsInstance, RollTypeValue, TestTypeValue, } from "@platonic-dice/core";
|
|
20
|
+
export type { RollRecord, DieRollRecord, ModifiedDieRollRecord, TestDieRollRecord, ModifiedTestDieRollRecord, } from "./types/roll-record.types.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAI/B,OAAO,IAAI,MAAM,qBAAqB,CAAC;AACvC,eAAO,MAAQ,OAAO;;;;;;;IAAE,QAAQ;;;IAAE,WAAW,yBAAS,CAAC;AACvD,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,EACb,aAAa,GACd,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EACV,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for roll records used across the dice package.
|
|
3
|
+
* These represent the persisted shape for normal, modified and test rolls.
|
|
4
|
+
*/
|
|
5
|
+
import type { OutcomeValue } from "@platonic-dice/core";
|
|
6
|
+
/**
|
|
7
|
+
* Simple die roll record.
|
|
8
|
+
*/
|
|
9
|
+
export interface DieRollRecord {
|
|
10
|
+
roll: number;
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Modified die roll record.
|
|
15
|
+
*/
|
|
16
|
+
export interface ModifiedDieRollRecord {
|
|
17
|
+
roll: number;
|
|
18
|
+
modified: number;
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Targeted test roll record (e.g., success/failure).
|
|
23
|
+
*/
|
|
24
|
+
export interface TestDieRollRecord {
|
|
25
|
+
roll: number;
|
|
26
|
+
outcome: OutcomeValue;
|
|
27
|
+
timestamp: Date;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Modified test roll record (combines modifier and test evaluation).
|
|
31
|
+
*/
|
|
32
|
+
export interface ModifiedTestDieRollRecord {
|
|
33
|
+
roll: number;
|
|
34
|
+
modified: number;
|
|
35
|
+
outcome: OutcomeValue;
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Union type for all possible roll records.
|
|
40
|
+
*/
|
|
41
|
+
export type RollRecord = DieRollRecord | ModifiedDieRollRecord | TestDieRollRecord | ModifiedTestDieRollRecord;
|
|
42
|
+
//# sourceMappingURL=roll-record.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roll-record.types.d.ts","sourceRoot":"","sources":["../../src/types/roll-record.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,qBAAqB,GACrB,iBAAiB,GACjB,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platonic-dice/dice",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"packageManager": "pnpm@8.15.9",
|
|
4
5
|
"description": "Persistent dice objects with roll history and TypeScript support.",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "dist/index.js",
|
|
@@ -34,16 +35,17 @@
|
|
|
34
35
|
"homepage": "https://github.com/sjs2k20/platonic-dice.git#readme",
|
|
35
36
|
"scripts": {
|
|
36
37
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
37
|
-
"prepublishOnly": "
|
|
38
|
+
"prepublishOnly": "pnpm run build",
|
|
38
39
|
"test": "vitest run",
|
|
39
40
|
"test:watch": "vitest"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@platonic-dice/core": "^2.
|
|
43
|
+
"@platonic-dice/core": "^2.2.2"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"tsc-alias": "^1.8.16",
|
|
46
47
|
"vite-tsconfig-paths": "^5.1.4",
|
|
47
|
-
"vitest": "^4.0.9"
|
|
48
|
+
"vitest": "^4.0.9",
|
|
49
|
+
"@types/node": "^22.13.8"
|
|
48
50
|
}
|
|
49
51
|
}
|