osu-stable-db 0.2.4 → 0.2.5

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/index.d.mts CHANGED
@@ -1,5 +1,69 @@
1
1
  import { C as UserPermissionFlags, S as UserPermission, _ as ScoreAdditionalModInfo, a as GameplayMode, b as ScoresDatabase, c as Grades, d as Mod, f as ModFlags, g as RankedStatuses, h as RankedStatus, i as DateTimeTicks, l as IntFloatPair, m as OsuDatabase, n as CollectionDatabase, o as GameplayModes, p as Mods, r as CollectionEntry, s as Grade, t as BeatmapEntry, u as MINIMUM_SUPPORTED_VERSION, v as ScoreEntry, w as UserPermissions, x as TimingPoint, y as ScoresBeatmapEntry } from "./types-DiZMN3fQ.mjs";
2
2
 
3
+ //#region src/core/utils.d.ts
4
+ declare const TICKS_PER_MILLISECOND = 10000n;
5
+ declare const UNIX_EPOCH_DATE_TIME_TICKS = 621355968000000000n;
6
+ declare const WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS = 504911232000000000n;
7
+ /**
8
+ * Converts .NET DateTime ticks to Unix epoch milliseconds.
9
+ */
10
+ declare function dateTimeTicksToUnixMilliseconds(ticks: DateTimeTicks): bigint;
11
+ /**
12
+ * Converts Unix epoch milliseconds to .NET DateTime ticks.
13
+ */
14
+ declare function unixMillisecondsToDateTimeTicks(milliseconds: bigint): DateTimeTicks;
15
+ /**
16
+ * Converts .NET DateTime ticks to Windows FILETIME ticks.
17
+ *
18
+ * scores.db stores replay timestamps as .NET DateTime ticks, while replay
19
+ * filenames under Data/r use FILETIME ticks starting at 1601-01-01.
20
+ */
21
+ declare function dateTimeTicksToWindowsFileTimeTicks(ticks: DateTimeTicks): bigint;
22
+ /**
23
+ * Converts .NET DateTime ticks to a JavaScript Date.
24
+ *
25
+ * JavaScript Date has millisecond precision, so sub-millisecond tick precision
26
+ * is truncated during conversion.
27
+ */
28
+ declare function dateTimeTicksToDate(ticks: DateTimeTicks): Date;
29
+ /**
30
+ * Converts a JavaScript Date to .NET DateTime ticks.
31
+ *
32
+ * JavaScript Date has millisecond precision, so the resulting tick value will
33
+ * always have its sub-millisecond portion set to zero.
34
+ */
35
+ declare function dateToDateTimeTicks(date: Date): DateTimeTicks;
36
+ /**
37
+ * Tests whether all bits from a mod mask are present in the flags value.
38
+ */
39
+ declare function hasMod(flags: ModFlags, mod: Mod): boolean;
40
+ /**
41
+ * Tests whether any bit from a mod mask is present in the flags value.
42
+ */
43
+ declare function hasAnyMod(flags: ModFlags, modMask: ModFlags): boolean;
44
+ /**
45
+ * Combines multiple mods into a single bitmask.
46
+ */
47
+ declare function combineMods(mods: Iterable<Mod>): ModFlags;
48
+ /**
49
+ * Expands a mod bitmask into its individual mod values.
50
+ */
51
+ declare function splitMods(flags: ModFlags): Mod[];
52
+ /**
53
+ * Returns the relative Songs path for a beatmap entry.
54
+ */
55
+ declare function getBeatmapRelativeOsuFilePath(beatmap: {
56
+ beatmapFolderName: string | null;
57
+ osuFileName: string | null;
58
+ }): string;
59
+ /**
60
+ * Returns the relative replay path for a score entry.
61
+ */
62
+ declare function getScoreRelativeOsrFilePath(score: {
63
+ beatmapMd5Hash: string | null;
64
+ replayTimestamp: DateTimeTicks;
65
+ }): string;
66
+ //#endregion
3
67
  //#region src/db/collection.d.ts
4
68
  declare function readCollectionDatabase(input: ArrayBuffer | Uint8Array): CollectionDatabase;
5
69
  declare function writeCollectionDatabase(database: CollectionDatabase): Uint8Array;
@@ -30,4 +94,4 @@ type BeatmapScoreMatch = GeneratorYield<BeatmapScoreQuery['iterateBeatmapScores'
30
94
  declare function readScoresDatabase(input: ArrayBuffer | Uint8Array): ScoresDatabase;
31
95
  declare function writeScoresDatabase(database: ScoresDatabase): Uint8Array;
32
96
  //#endregion
33
- export { BeatmapEntry, BeatmapQuerySource, BeatmapScoreMatch, BeatmapScoreQuery, BeatmapScoresGroupMatch, CollectionDatabase, CollectionEntry, DateTimeTicks, GameplayMode, GameplayModes, Grade, Grades, IntFloatPair, MINIMUM_SUPPORTED_VERSION, Mod, ModFlags, Mods, OsuDatabase, RankedStatus, RankedStatuses, ScoreAdditionalModInfo, ScoreEntry, ScoreQuerySource, ScoresBeatmapEntry, ScoresDatabase, TimingPoint, UserPermission, UserPermissionFlags, UserPermissions, createBeatmapScoreQuery, readCollectionDatabase, readOsuDatabase, readScoresDatabase, writeCollectionDatabase, writeOsuDatabase, writeScoresDatabase };
97
+ export { BeatmapEntry, BeatmapQuerySource, BeatmapScoreMatch, BeatmapScoreQuery, BeatmapScoresGroupMatch, CollectionDatabase, CollectionEntry, DateTimeTicks, GameplayMode, GameplayModes, Grade, Grades, IntFloatPair, MINIMUM_SUPPORTED_VERSION, Mod, ModFlags, Mods, OsuDatabase, RankedStatus, RankedStatuses, ScoreAdditionalModInfo, ScoreEntry, ScoreQuerySource, ScoresBeatmapEntry, ScoresDatabase, TICKS_PER_MILLISECOND, TimingPoint, UNIX_EPOCH_DATE_TIME_TICKS, UserPermission, UserPermissionFlags, UserPermissions, WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS, combineMods, createBeatmapScoreQuery, dateTimeTicksToDate, dateTimeTicksToUnixMilliseconds, dateTimeTicksToWindowsFileTimeTicks, dateToDateTimeTicks, getBeatmapRelativeOsuFilePath, getScoreRelativeOsrFilePath, hasAnyMod, hasMod, readCollectionDatabase, readOsuDatabase, readScoresDatabase, splitMods, unixMillisecondsToDateTimeTicks, writeCollectionDatabase, writeOsuDatabase, writeScoresDatabase };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as readOsuDatabase, c as writeCollectionDatabase, d as MINIMUM_SUPPORTED_VERSION, f as Mods, i as createBeatmapScoreQuery, l as GameplayModes, m as UserPermissions, n as writeScoresDatabase, o as writeOsuDatabase, p as RankedStatuses, s as readCollectionDatabase, t as readScoresDatabase, u as Grades } from "./scores-CW2CUXZ-.mjs";
2
- export { GameplayModes, Grades, MINIMUM_SUPPORTED_VERSION, Mods, RankedStatuses, UserPermissions, createBeatmapScoreQuery, readCollectionDatabase, readOsuDatabase, readScoresDatabase, writeCollectionDatabase, writeOsuDatabase, writeScoresDatabase };
1
+ import { C as Grades, D as UserPermissions, E as RankedStatuses, S as GameplayModes, T as Mods, _ as getScoreRelativeOsrFilePath, a as writeOsuDatabase, b as splitMods, c as TICKS_PER_MILLISECOND, d as combineMods, f as dateTimeTicksToDate, g as getBeatmapRelativeOsuFilePath, h as dateToDateTimeTicks, i as readOsuDatabase, l as UNIX_EPOCH_DATE_TIME_TICKS, m as dateTimeTicksToWindowsFileTimeTicks, n as writeScoresDatabase, o as readCollectionDatabase, p as dateTimeTicksToUnixMilliseconds, r as createBeatmapScoreQuery, s as writeCollectionDatabase, t as readScoresDatabase, u as WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS, v as hasAnyMod, w as MINIMUM_SUPPORTED_VERSION, x as unixMillisecondsToDateTimeTicks, y as hasMod } from "./scores-Be-LBsWn.mjs";
2
+ export { GameplayModes, Grades, MINIMUM_SUPPORTED_VERSION, Mods, RankedStatuses, TICKS_PER_MILLISECOND, UNIX_EPOCH_DATE_TIME_TICKS, UserPermissions, WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS, combineMods, createBeatmapScoreQuery, dateTimeTicksToDate, dateTimeTicksToUnixMilliseconds, dateTimeTicksToWindowsFileTimeTicks, dateToDateTimeTicks, getBeatmapRelativeOsuFilePath, getScoreRelativeOsrFilePath, hasAnyMod, hasMod, readCollectionDatabase, readOsuDatabase, readScoresDatabase, splitMods, unixMillisecondsToDateTimeTicks, writeCollectionDatabase, writeOsuDatabase, writeScoresDatabase };
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as readOsuDatabase, c as writeCollectionDatabase, i as createBeatmapScoreQuery, n as writeScoresDatabase, o as writeOsuDatabase, r as dateTimeTicksToWindowsFileTimeTicks, s as readCollectionDatabase, t as readScoresDatabase } from "./scores-CW2CUXZ-.mjs";
1
+ import { _ as getScoreRelativeOsrFilePath, a as writeOsuDatabase, g as getBeatmapRelativeOsuFilePath, i as readOsuDatabase, n as writeScoresDatabase, o as readCollectionDatabase, r as createBeatmapScoreQuery, s as writeCollectionDatabase, t as readScoresDatabase } from "./scores-Be-LBsWn.mjs";
2
2
  import { readFile, writeFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  //#region src/node.ts
@@ -91,12 +91,10 @@ var OsuFolder = class {
91
91
  };
92
92
  }
93
93
  getOsuFilePath(beatmap) {
94
- if (beatmap.beatmapFolderName === null || beatmap.osuFileName === null) throw new Error("Beatmap entry is missing beatmapFolderName or osuFileName");
95
- return join(this.folderPath, "Songs", beatmap.beatmapFolderName, beatmap.osuFileName);
94
+ return join(this.folderPath, getBeatmapRelativeOsuFilePath(beatmap));
96
95
  }
97
96
  getOsrFilePath(score) {
98
- if (score.beatmapMd5Hash === null) throw new Error("Score entry is missing beatmapMd5Hash");
99
- return join(this.folderPath, "Data", "r", `${score.beatmapMd5Hash}-${dateTimeTicksToWindowsFileTimeTicks(score.replayTimestamp)}.osr`);
97
+ return join(this.folderPath, getScoreRelativeOsrFilePath(score));
100
98
  }
101
99
  };
102
100
  //#endregion
@@ -98,6 +98,93 @@ const Mods = {
98
98
  Mirror: 1073741824
99
99
  };
100
100
  //#endregion
101
+ //#region src/core/utils.ts
102
+ const TICKS_PER_MILLISECOND = 10000n;
103
+ const UNIX_EPOCH_DATE_TIME_TICKS = 621355968000000000n;
104
+ const WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS = 504911232000000000n;
105
+ const orderedMods = Object.values(Mods).filter((value) => value !== Mods.None);
106
+ /**
107
+ * Converts .NET DateTime ticks to Unix epoch milliseconds.
108
+ */
109
+ function dateTimeTicksToUnixMilliseconds(ticks) {
110
+ return (ticks - UNIX_EPOCH_DATE_TIME_TICKS) / TICKS_PER_MILLISECOND;
111
+ }
112
+ /**
113
+ * Converts Unix epoch milliseconds to .NET DateTime ticks.
114
+ */
115
+ function unixMillisecondsToDateTimeTicks(milliseconds) {
116
+ return milliseconds * TICKS_PER_MILLISECOND + UNIX_EPOCH_DATE_TIME_TICKS;
117
+ }
118
+ /**
119
+ * Converts .NET DateTime ticks to Windows FILETIME ticks.
120
+ *
121
+ * scores.db stores replay timestamps as .NET DateTime ticks, while replay
122
+ * filenames under Data/r use FILETIME ticks starting at 1601-01-01.
123
+ */
124
+ function dateTimeTicksToWindowsFileTimeTicks(ticks) {
125
+ return ticks - WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS;
126
+ }
127
+ /**
128
+ * Converts .NET DateTime ticks to a JavaScript Date.
129
+ *
130
+ * JavaScript Date has millisecond precision, so sub-millisecond tick precision
131
+ * is truncated during conversion.
132
+ */
133
+ function dateTimeTicksToDate(ticks) {
134
+ return new Date(Number(dateTimeTicksToUnixMilliseconds(ticks)));
135
+ }
136
+ /**
137
+ * Converts a JavaScript Date to .NET DateTime ticks.
138
+ *
139
+ * JavaScript Date has millisecond precision, so the resulting tick value will
140
+ * always have its sub-millisecond portion set to zero.
141
+ */
142
+ function dateToDateTimeTicks(date) {
143
+ return unixMillisecondsToDateTimeTicks(BigInt(date.getTime()));
144
+ }
145
+ /**
146
+ * Tests whether all bits from a mod mask are present in the flags value.
147
+ */
148
+ function hasMod(flags, mod) {
149
+ return (flags & mod) === mod;
150
+ }
151
+ /**
152
+ * Tests whether any bit from a mod mask is present in the flags value.
153
+ */
154
+ function hasAnyMod(flags, modMask) {
155
+ return (flags & modMask) !== 0;
156
+ }
157
+ /**
158
+ * Combines multiple mods into a single bitmask.
159
+ */
160
+ function combineMods(mods) {
161
+ let flags = Mods.None;
162
+ for (const mod of mods) flags |= mod;
163
+ return flags;
164
+ }
165
+ /**
166
+ * Expands a mod bitmask into its individual mod values.
167
+ */
168
+ function splitMods(flags) {
169
+ const result = [];
170
+ for (const mod of orderedMods) if (hasMod(flags, mod)) result.push(mod);
171
+ return result;
172
+ }
173
+ /**
174
+ * Returns the relative Songs path for a beatmap entry.
175
+ */
176
+ function getBeatmapRelativeOsuFilePath(beatmap) {
177
+ if (beatmap.beatmapFolderName === null || beatmap.osuFileName === null) throw new Error("Beatmap entry is missing beatmapFolderName or osuFileName");
178
+ return `Songs/${beatmap.beatmapFolderName}/${beatmap.osuFileName}`;
179
+ }
180
+ /**
181
+ * Returns the relative replay path for a score entry.
182
+ */
183
+ function getScoreRelativeOsrFilePath(score) {
184
+ if (score.beatmapMd5Hash === null) throw new Error("Score entry is missing beatmapMd5Hash");
185
+ return `Data/r/${score.beatmapMd5Hash}-${dateTimeTicksToWindowsFileTimeTicks(score.replayTimestamp)}.osr`;
186
+ }
187
+ //#endregion
101
188
  //#region src/core/binary.ts
102
189
  var BinaryReader$1 = class extends BinaryReader {
103
190
  readDateTimeTicks() {
@@ -387,25 +474,6 @@ function createBeatmapScoreQuery(beatmapsSource, scoresSource) {
387
474
  };
388
475
  }
389
476
  //#endregion
390
- //#region src/core/utils.ts
391
- const WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS = 504911232000000000n;
392
- Object.values(Mods).filter((value) => value !== Mods.None);
393
- /**
394
- * Converts .NET DateTime ticks to Windows FILETIME ticks.
395
- *
396
- * scores.db stores replay timestamps as .NET DateTime ticks, while replay
397
- * filenames under Data/r use FILETIME ticks starting at 1601-01-01.
398
- */
399
- function dateTimeTicksToWindowsFileTimeTicks(ticks) {
400
- return ticks - WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS;
401
- }
402
- /**
403
- * Tests whether all bits from a mod mask are present in the flags value.
404
- */
405
- function hasMod(flags, mod) {
406
- return (flags & mod) === mod;
407
- }
408
- //#endregion
409
477
  //#region src/db/scores.ts
410
478
  function readScoreAdditionalModInfo(reader) {
411
479
  return { targetPracticeAccuracy: reader.readDouble() };
@@ -512,4 +580,4 @@ function writeScoresDatabase(database) {
512
580
  return writer.toUint8Array();
513
581
  }
514
582
  //#endregion
515
- export { readOsuDatabase as a, writeCollectionDatabase as c, MINIMUM_SUPPORTED_VERSION as d, Mods as f, createBeatmapScoreQuery as i, GameplayModes as l, UserPermissions as m, writeScoresDatabase as n, writeOsuDatabase as o, RankedStatuses as p, dateTimeTicksToWindowsFileTimeTicks as r, readCollectionDatabase as s, readScoresDatabase as t, Grades as u };
583
+ export { Grades as C, UserPermissions as D, RankedStatuses as E, GameplayModes as S, Mods as T, getScoreRelativeOsrFilePath as _, writeOsuDatabase as a, splitMods as b, TICKS_PER_MILLISECOND as c, combineMods as d, dateTimeTicksToDate as f, getBeatmapRelativeOsuFilePath as g, dateToDateTimeTicks as h, readOsuDatabase as i, UNIX_EPOCH_DATE_TIME_TICKS as l, dateTimeTicksToWindowsFileTimeTicks as m, writeScoresDatabase as n, readCollectionDatabase as o, dateTimeTicksToUnixMilliseconds as p, createBeatmapScoreQuery as r, writeCollectionDatabase as s, readScoresDatabase as t, WINDOWS_FILE_TIME_EPOCH_DATE_TIME_TICKS as u, hasAnyMod as v, MINIMUM_SUPPORTED_VERSION as w, unixMillisecondsToDateTimeTicks as x, hasMod as y };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "osu-stable-db",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "description": "TypeScript reader and writer for osu!stable database files.",
6
6
  "author": "zzzzv",
7
7
  "license": "MIT",