ropegeo-common 1.20.0 → 1.20.2
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/models/measurements/timeMeasurement.d.ts +5 -0
- package/dist/models/measurements/timeMeasurement.d.ts.map +1 -1
- package/dist/models/measurements/timeMeasurement.js +55 -9
- package/dist/models/previews/offlinePagePreview.d.ts +8 -0
- package/dist/models/previews/offlinePagePreview.d.ts.map +1 -1
- package/dist/models/previews/offlinePagePreview.js +35 -0
- package/package.json +1 -1
|
@@ -17,6 +17,11 @@ export declare class TimeMeasurement extends Measurement {
|
|
|
17
17
|
constructor(value: number, unit: TimeMeasurementUnit);
|
|
18
18
|
toMeasurementSystem(system: TimeMeasurementSystem, unitName?: string): TimeMeasurement;
|
|
19
19
|
protected abbreviate(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Renders the value in a human-friendly unit derived from the stored unit and magnitude
|
|
22
|
+
* (e.g. 90 minutes → `1.5h`) without changing {@link unit}.
|
|
23
|
+
*/
|
|
24
|
+
toString(showUnitName?: boolean): string;
|
|
20
25
|
private toFreedom;
|
|
21
26
|
static fromResult(json: unknown): TimeMeasurement;
|
|
22
27
|
static coerce(value: unknown, defaultUnit: TimeMeasurementUnit): TimeMeasurement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeMeasurement.d.ts","sourceRoot":"","sources":["../../../src/models/measurements/timeMeasurement.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"timeMeasurement.d.ts","sourceRoot":"","sources":["../../../src/models/measurements/timeMeasurement.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,WAAW,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IACzB,iBAAiB,EAAE,UAAU,CAAC;IAC9B,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;CACtC,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,aAAa,CAAC;AACjE,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,SAAS,CAAC;AAE3D,2EAA2E;AAC3E,eAAO,MAAM,OAAO,EAAE,cAAmE,CAAC;AAC1F,eAAO,MAAM,KAAK,EAAE,cAAiE,CAAC;AACtF,eAAO,MAAM,IAAI,EAAE,cAAgE,CAAC;AA8CpF,0FAA0F;AAC1F,qBAAa,eAAgB,SAAQ,WAAW;IAC5C,QAAQ,CAAC,eAAe,EAAG,MAAM,CAAU;IAC3C,SAAiB,IAAI,EAAE,mBAAmB,CAAC;gBAE/B,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB;IAIpD,mBAAmB,CAAC,MAAM,EAAE,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,eAAe;IAgBtF,SAAS,CAAC,UAAU,IAAI,MAAM;IAI9B;;;OAGG;IACH,QAAQ,CAAC,YAAY,UAAO,GAAG,MAAM;IAYrC,OAAO,CAAC,SAAS;IAcjB,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe;IAkBjD,MAAM,CAAC,MAAM,CACT,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,mBAAmB,GACjC,eAAe,GAAG,IAAI;CAiB5B"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TimeMeasurement = exports.DAYS = exports.HOURS = exports.MINUTES = void 0;
|
|
4
4
|
const measurement_1 = require("./measurement");
|
|
5
|
+
const measurementValue_1 = require("./measurementValue");
|
|
5
6
|
/** Convenience unit descriptors for the units RopeWiki stores times in. */
|
|
6
7
|
exports.MINUTES = { measurementSystem: 'Standard', name: 'minutes' };
|
|
7
8
|
exports.HOURS = { measurementSystem: 'Standard', name: 'hours' };
|
|
@@ -61,16 +62,22 @@ class TimeMeasurement extends measurement_1.Measurement {
|
|
|
61
62
|
return new TimeMeasurement(value, { measurementSystem: 'Standard', name: targetName });
|
|
62
63
|
}
|
|
63
64
|
abbreviate() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
return abbreviateStandardUnit(this.unit.name);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Renders the value in a human-friendly unit derived from the stored unit and magnitude
|
|
69
|
+
* (e.g. 90 minutes → `1.5h`) without changing {@link unit}.
|
|
70
|
+
*/
|
|
71
|
+
toString(showUnitName = true) {
|
|
72
|
+
if (this.unit.measurementSystem === measurement_1.FREEDOM_MEASUREMENT_SYSTEM) {
|
|
73
|
+
return super.toString(showUnitName);
|
|
74
|
+
}
|
|
75
|
+
const { value, unit } = displayUnitAndValue(this.value, this.unit.name);
|
|
76
|
+
const formatted = (0, measurementValue_1.formatMeasurementValue)(value);
|
|
77
|
+
if (!showUnitName) {
|
|
78
|
+
return formatted;
|
|
73
79
|
}
|
|
80
|
+
return `${formatted}${abbreviateStandardUnit(unit)}`;
|
|
74
81
|
}
|
|
75
82
|
toFreedom(unit, unitName) {
|
|
76
83
|
const seconds = this.value * SECONDS_PER_UNIT[unit.name];
|
|
@@ -115,6 +122,45 @@ class TimeMeasurement extends measurement_1.Measurement {
|
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
exports.TimeMeasurement = TimeMeasurement;
|
|
125
|
+
function abbreviateStandardUnit(name) {
|
|
126
|
+
switch (name) {
|
|
127
|
+
case 'minutes':
|
|
128
|
+
return 'min';
|
|
129
|
+
case 'hours':
|
|
130
|
+
return 'h';
|
|
131
|
+
case 'days':
|
|
132
|
+
return 'd';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Picks a display unit and scaled value for {@link TimeMeasurement.toString}. */
|
|
136
|
+
function displayUnitAndValue(value, baseUnit) {
|
|
137
|
+
switch (baseUnit) {
|
|
138
|
+
case 'minutes':
|
|
139
|
+
if (value >= 60 * 24) {
|
|
140
|
+
return { value: value / (60 * 24), unit: 'days' };
|
|
141
|
+
}
|
|
142
|
+
if (value >= 60) {
|
|
143
|
+
return { value: value / 60, unit: 'hours' };
|
|
144
|
+
}
|
|
145
|
+
return { value, unit: 'minutes' };
|
|
146
|
+
case 'hours':
|
|
147
|
+
if (value >= 24) {
|
|
148
|
+
return { value: value / 24, unit: 'days' };
|
|
149
|
+
}
|
|
150
|
+
if (value < 1) {
|
|
151
|
+
return { value: value * 60, unit: 'minutes' };
|
|
152
|
+
}
|
|
153
|
+
return { value, unit: 'hours' };
|
|
154
|
+
case 'days':
|
|
155
|
+
if (value < 1 / 24) {
|
|
156
|
+
return { value: value * 24 * 60, unit: 'minutes' };
|
|
157
|
+
}
|
|
158
|
+
if (value < 1) {
|
|
159
|
+
return { value: value * 24, unit: 'hours' };
|
|
160
|
+
}
|
|
161
|
+
return { value, unit: 'days' };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
118
164
|
function assertStandardUnit(name) {
|
|
119
165
|
if (!STANDARD_NAMES.includes(name)) {
|
|
120
166
|
throw new Error(`TimeMeasurement: "${name}" is not a valid Standard unit (expected one of [${STANDARD_NAMES.join(', ')}])`);
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { PagePreview } from './pagePreview';
|
|
2
|
+
import { DownloadJob } from '../../download/downloadJob';
|
|
3
|
+
import type { DownloadJobConfig } from '../../download/types';
|
|
2
4
|
export declare class OfflinePagePreview extends PagePreview {
|
|
3
5
|
readonly fetchType: "offline";
|
|
4
6
|
downloadedImagePath: string | null;
|
|
5
7
|
constructor(id: string, source: import('../pageDataSource').PageDataSource, downloadedImagePath: string | null, rating: number | null, ratingCount: number | null, title: string, regions: string[], aka: string[], difficultyRating: import('../difficulty/difficultyRating').DifficultyRating, mapData: string | null, externalLink: string | null, permit: import('../permitStatus').PermitStatus | null);
|
|
8
|
+
/**
|
|
9
|
+
* Re-downloads the page bundle by id/source (fetch-page-json path). Offline previews carry no
|
|
10
|
+
* `downloadFolder`, so this always uses the page-JSON fetch phase. Enables re-downloading a saved
|
|
11
|
+
* page whose bundle was removed (its preview stays offline while `downloadedPageViewPath` is null).
|
|
12
|
+
*/
|
|
13
|
+
toDownloadJob(config: DownloadJobConfig): DownloadJob;
|
|
6
14
|
static fromResult(result: unknown): OfflinePagePreview;
|
|
7
15
|
}
|
|
8
16
|
//# sourceMappingURL=offlinePagePreview.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offlinePagePreview.d.ts","sourceRoot":"","sources":["../../../src/models/previews/offlinePagePreview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"offlinePagePreview.d.ts","sourceRoot":"","sources":["../../../src/models/previews/offlinePagePreview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAS9D,qBAAa,kBAAmB,SAAQ,WAAW;IAC/C,QAAQ,CAAC,SAAS,EAAG,SAAS,CAAU;IACxC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;gBAG/B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,OAAO,mBAAmB,EAAE,cAAc,EAClD,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAClC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,GAAG,EAAE,MAAM,EAAE,EACb,gBAAgB,EAAE,OAAO,gCAAgC,EAAE,gBAAgB,EAC3E,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,YAAY,EAAE,MAAM,GAAG,IAAI,EAC3B,MAAM,EAAE,OAAO,iBAAiB,EAAE,YAAY,GAAG,IAAI;IAkBzD;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW;IAyBrD,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,kBAAkB;CAUzD"}
|
|
@@ -2,12 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OfflinePagePreview = void 0;
|
|
4
4
|
const pagePreview_1 = require("./pagePreview");
|
|
5
|
+
const downloadJob_1 = require("../../download/downloadJob");
|
|
6
|
+
const downloadPhase_1 = require("../../download/downloadPhase");
|
|
7
|
+
const downloadPhaseTitles_1 = require("../../download/helpers/downloadPhaseTitles");
|
|
8
|
+
const downloadDependencyKeys_1 = require("../../download/dependencies/downloadDependencyKeys");
|
|
9
|
+
const fetchPageJsonTaskDependency_1 = require("../../download/dependencies/fetchPageJsonTaskDependency");
|
|
10
|
+
const fetchPageJsonTask_1 = require("../../download/tasks/fetchPageJsonTask");
|
|
11
|
+
const pageDataSource_1 = require("../pageDataSource");
|
|
12
|
+
const pageViewType_1 = require("../pageViews/pageViewType");
|
|
5
13
|
class OfflinePagePreview extends pagePreview_1.PagePreview {
|
|
6
14
|
constructor(id, source, downloadedImagePath, rating, ratingCount, title, regions, aka, difficultyRating, mapData, externalLink, permit) {
|
|
7
15
|
super(id, source, rating, ratingCount, title, regions, aka, difficultyRating, mapData, externalLink, permit);
|
|
8
16
|
this.fetchType = 'offline';
|
|
9
17
|
this.downloadedImagePath = downloadedImagePath;
|
|
10
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Re-downloads the page bundle by id/source (fetch-page-json path). Offline previews carry no
|
|
21
|
+
* `downloadFolder`, so this always uses the page-JSON fetch phase. Enables re-downloading a saved
|
|
22
|
+
* page whose bundle was removed (its preview stays offline while `downloadedPageViewPath` is null).
|
|
23
|
+
*/
|
|
24
|
+
toDownloadJob(config) {
|
|
25
|
+
const pageViewType = this.source === pageDataSource_1.PageDataSource.Ropewiki
|
|
26
|
+
? pageViewType_1.PageViewType.Ropewiki
|
|
27
|
+
: null;
|
|
28
|
+
if (pageViewType == null) {
|
|
29
|
+
throw new Error(`Unsupported page preview source "${String(this.source)}"`);
|
|
30
|
+
}
|
|
31
|
+
const fetchPageTask = new fetchPageJsonTask_1.FetchPageJsonTask();
|
|
32
|
+
const fetchPagePhase = new downloadPhase_1.DownloadPhase({
|
|
33
|
+
title: (0, downloadPhaseTitles_1.titleForPhase)([fetchPageTask]),
|
|
34
|
+
tasks: [fetchPageTask],
|
|
35
|
+
});
|
|
36
|
+
return new downloadJob_1.DownloadJob({
|
|
37
|
+
pageId: this.id,
|
|
38
|
+
pageViewType,
|
|
39
|
+
config,
|
|
40
|
+
phases: [(0, downloadPhaseTitles_1.buildDeleteStoredPagePhase)(), fetchPagePhase],
|
|
41
|
+
taskDependencies: {
|
|
42
|
+
[downloadDependencyKeys_1.DownloadDependencyKeys.FetchPageJson]: fetchPageJsonTaskDependency_1.FetchPageJsonTaskDependency.fromPreview(this, config),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
11
46
|
static fromResult(result) {
|
|
12
47
|
if (result == null || typeof result !== 'object') {
|
|
13
48
|
throw new Error('OfflinePagePreview result must be an object');
|