@oboapp/source-toplo-bg 0.1.0 → 0.2.0
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/README.md +15 -2
- package/dist/cjs/index.d.ts +7 -2
- package/dist/cjs/index.js +10 -6
- package/dist/cjs/toplo.d.ts +9 -0
- package/dist/cjs/toplo.js +20 -2
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +9 -4
- package/dist/esm/toplo.d.ts +9 -0
- package/dist/esm/toplo.js +20 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,8 +6,21 @@ Pass `createSource` and the isolated `metadata` entrypoint to Obo's scheduled so
|
|
|
6
6
|
|
|
7
7
|
The package preserves Bulgarian content formatting, publication dates, heating categories, empty detail links, timespan fallback rules, and precomputed geometry. It keeps the legacy handling of Point, LineString and Polygon features: fix swapped Sofia coordinates, discard invalid features, retain other valid features, and skip incidents whose features are all invalid. An empty FeatureCollection remains valid. The same Sofia bounds as the legacy validator are used to recognize swapped coordinates. Malformed incident blocks, invalid geometry and coordinate corrections emit warnings.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
An optional `onListing` callback observes the same fetched HTML before content parsing. It receives `{ html, observedAt }`, where `observedAt` is an ISO timestamp recorded after the response body is read. Return `{ count }` with a nonnegative safe integer for the complete listing, including incidents without usable geometry. The callback can be synchronous or asynchronous. A failed callback fails discovery, and cancellation is checked again after it completes.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
```typescript
|
|
12
|
+
const source = createSource(context, {
|
|
13
|
+
async onListing({ html, observedAt }) {
|
|
14
|
+
const count = await inspectCompleteListing(html, observedAt);
|
|
15
|
+
return { count };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The observer owns complete-listing validation before returning zero. A verified zero permits an empty discovery. Without an observer, or when it reports a positive count, a listing with no parsed incidents fails. A zero count that contradicts parsed incidents also fails. A positive count can exceed the geometry-filtered discovery count. Observation uses the existing response without another provider request. The package owns the request timeout and instance cache.
|
|
21
|
+
|
|
22
|
+
Dates in text use the process timezone, matching the existing crawler. Invalid or pre-2025 starts fall back to the current time for the timespan; missing or invalid ends fall back to the start. The original `datePublished` and title remain unchanged. Obo controls content validation before storage.
|
|
23
|
+
|
|
24
|
+
The frozen listing and expected content fixtures come from Obo's pre-refactor Toplo contract. Tests cover literal identity, content, geometry cleanup, large cached incidents, failure handling, cancellation, ESM/CommonJS entrypoints, listing observation and verified empty listings.
|
|
12
25
|
|
|
13
26
|
Obo owns deduplication, storage, scheduling, source ID and locality validation. Keep the existing `toplo-bg` job and emergent schedule when integrating. Publish this package through the reviewed release process in the repository's `RELEASING.md`, then install the exact npm version in a separate Obo integration PR. Roll back the integration by restoring the previous crawler entrypoint and redeploying; stored identifiers stay compatible.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { DataSource, SourceContext } from "@oboapp/source-sdk";
|
|
2
|
+
import type { ToploListingObserver } from "./toplo.js";
|
|
3
|
+
export type { ToploListingObservation, ToploListingResult, ToploListingObserver } from "./toplo.js";
|
|
4
|
+
export interface ToploSourceOptions {
|
|
5
|
+
onListing?: ToploListingObserver;
|
|
6
|
+
}
|
|
7
|
+
export declare function createSource(context: SourceContext, options?: ToploSourceOptions): DataSource;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSource = void 0;
|
|
4
|
-
const toplo_js_1 = require("./toplo.js");
|
|
5
|
-
const createSource = (context) => (0, toplo_js_1.createToploSource)({
|
|
6
|
-
fetch: (...args) => globalThis.fetch(...args),
|
|
7
|
-
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
8
|
-
});
|
|
9
3
|
exports.createSource = createSource;
|
|
4
|
+
const toplo_js_1 = require("./toplo.js");
|
|
5
|
+
function createSource(context, options = {}) {
|
|
6
|
+
return (0, toplo_js_1.createToploSource)({
|
|
7
|
+
fetch: (...args) => {
|
|
8
|
+
return globalThis.fetch(...args);
|
|
9
|
+
},
|
|
10
|
+
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
11
|
+
...(options.onListing === undefined ? {} : { onListing: options.onListing }),
|
|
12
|
+
});
|
|
13
|
+
}
|
package/dist/cjs/toplo.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { DataSource } from "@oboapp/source-sdk";
|
|
2
2
|
import type { ToploWarning } from "./geometry.js";
|
|
3
|
+
export interface ToploListingObservation {
|
|
4
|
+
readonly html: string;
|
|
5
|
+
readonly observedAt: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ToploListingResult {
|
|
8
|
+
readonly count: number;
|
|
9
|
+
}
|
|
10
|
+
export type ToploListingObserver = (listing: ToploListingObservation) => ToploListingResult | Promise<ToploListingResult>;
|
|
3
11
|
export interface ToploDependencies {
|
|
12
|
+
onListing?: ToploListingObserver;
|
|
4
13
|
fetch: typeof globalThis.fetch;
|
|
5
14
|
signal?: AbortSignal;
|
|
6
15
|
warn?: ToploWarning;
|
package/dist/cjs/toplo.js
CHANGED
|
@@ -5,7 +5,9 @@ const content_js_1 = require("./content.js");
|
|
|
5
5
|
const parser_js_1 = require("./parser.js");
|
|
6
6
|
const TARGET_URL = "https://toplo.bg/accidents-and-maintenance";
|
|
7
7
|
const defaults = {
|
|
8
|
-
fetch: (...args) =>
|
|
8
|
+
fetch: (...args) => {
|
|
9
|
+
return globalThis.fetch(...args);
|
|
10
|
+
},
|
|
9
11
|
};
|
|
10
12
|
/** Listing content stays in this scan's instance, including large geometries. */
|
|
11
13
|
function createToploSource(dependencies = defaults) {
|
|
@@ -32,12 +34,28 @@ function createToploSource(dependencies = defaults) {
|
|
|
32
34
|
}
|
|
33
35
|
const html = await response.text();
|
|
34
36
|
requestSignal.throwIfAborted();
|
|
37
|
+
let listedCount;
|
|
38
|
+
if (dependencies.onListing !== undefined) {
|
|
39
|
+
const observation = await dependencies.onListing({
|
|
40
|
+
html,
|
|
41
|
+
observedAt: new Date().toISOString(),
|
|
42
|
+
});
|
|
43
|
+
if (!observation || !Number.isSafeInteger(observation.count) || observation.count < 0) {
|
|
44
|
+
throw new TypeError("Toplo listing observer must return a nonnegative safe integer count");
|
|
45
|
+
}
|
|
46
|
+
listedCount = observation.count;
|
|
47
|
+
requestSignal.throwIfAborted();
|
|
48
|
+
}
|
|
35
49
|
for (const incident of (0, parser_js_1.parseIncidents)(html, dependencies.warn)) {
|
|
36
50
|
if (!incidents.has(incident.identifier)) {
|
|
37
51
|
incidents.set(incident.identifier, incident);
|
|
38
52
|
}
|
|
39
53
|
}
|
|
40
|
-
if (incidents.size
|
|
54
|
+
if (listedCount === 0 && incidents.size > 0) {
|
|
55
|
+
incidents.clear();
|
|
56
|
+
throw new Error("Toplo listing observer reported zero for a nonempty listing");
|
|
57
|
+
}
|
|
58
|
+
if (incidents.size === 0 && listedCount !== 0) {
|
|
41
59
|
throw new Error("No incidents found in HTML");
|
|
42
60
|
}
|
|
43
61
|
return {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { DataSource, SourceContext } from "@oboapp/source-sdk";
|
|
2
|
+
import type { ToploListingObserver } from "./toplo.js";
|
|
3
|
+
export type { ToploListingObservation, ToploListingResult, ToploListingObserver } from "./toplo.js";
|
|
4
|
+
export interface ToploSourceOptions {
|
|
5
|
+
onListing?: ToploListingObserver;
|
|
6
|
+
}
|
|
7
|
+
export declare function createSource(context: SourceContext, options?: ToploSourceOptions): DataSource;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { createToploSource } from "./toplo.js";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export function createSource(context, options = {}) {
|
|
3
|
+
return createToploSource({
|
|
4
|
+
fetch: (...args) => {
|
|
5
|
+
return globalThis.fetch(...args);
|
|
6
|
+
},
|
|
7
|
+
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
8
|
+
...(options.onListing === undefined ? {} : { onListing: options.onListing }),
|
|
9
|
+
});
|
|
10
|
+
}
|
package/dist/esm/toplo.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { DataSource } from "@oboapp/source-sdk";
|
|
2
2
|
import type { ToploWarning } from "./geometry.js";
|
|
3
|
+
export interface ToploListingObservation {
|
|
4
|
+
readonly html: string;
|
|
5
|
+
readonly observedAt: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ToploListingResult {
|
|
8
|
+
readonly count: number;
|
|
9
|
+
}
|
|
10
|
+
export type ToploListingObserver = (listing: ToploListingObservation) => ToploListingResult | Promise<ToploListingResult>;
|
|
3
11
|
export interface ToploDependencies {
|
|
12
|
+
onListing?: ToploListingObserver;
|
|
4
13
|
fetch: typeof globalThis.fetch;
|
|
5
14
|
signal?: AbortSignal;
|
|
6
15
|
warn?: ToploWarning;
|
package/dist/esm/toplo.js
CHANGED
|
@@ -2,7 +2,9 @@ import { buildContent } from "./content.js";
|
|
|
2
2
|
import { parseIncidents } from "./parser.js";
|
|
3
3
|
const TARGET_URL = "https://toplo.bg/accidents-and-maintenance";
|
|
4
4
|
const defaults = {
|
|
5
|
-
fetch: (...args) =>
|
|
5
|
+
fetch: (...args) => {
|
|
6
|
+
return globalThis.fetch(...args);
|
|
7
|
+
},
|
|
6
8
|
};
|
|
7
9
|
/** Listing content stays in this scan's instance, including large geometries. */
|
|
8
10
|
export function createToploSource(dependencies = defaults) {
|
|
@@ -29,12 +31,28 @@ export function createToploSource(dependencies = defaults) {
|
|
|
29
31
|
}
|
|
30
32
|
const html = await response.text();
|
|
31
33
|
requestSignal.throwIfAborted();
|
|
34
|
+
let listedCount;
|
|
35
|
+
if (dependencies.onListing !== undefined) {
|
|
36
|
+
const observation = await dependencies.onListing({
|
|
37
|
+
html,
|
|
38
|
+
observedAt: new Date().toISOString(),
|
|
39
|
+
});
|
|
40
|
+
if (!observation || !Number.isSafeInteger(observation.count) || observation.count < 0) {
|
|
41
|
+
throw new TypeError("Toplo listing observer must return a nonnegative safe integer count");
|
|
42
|
+
}
|
|
43
|
+
listedCount = observation.count;
|
|
44
|
+
requestSignal.throwIfAborted();
|
|
45
|
+
}
|
|
32
46
|
for (const incident of parseIncidents(html, dependencies.warn)) {
|
|
33
47
|
if (!incidents.has(incident.identifier)) {
|
|
34
48
|
incidents.set(incident.identifier, incident);
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
|
-
if (incidents.size
|
|
51
|
+
if (listedCount === 0 && incidents.size > 0) {
|
|
52
|
+
incidents.clear();
|
|
53
|
+
throw new Error("Toplo listing observer reported zero for a nonempty listing");
|
|
54
|
+
}
|
|
55
|
+
if (incidents.size === 0 && listedCount !== 0) {
|
|
38
56
|
throw new Error("No incidents found in HTML");
|
|
39
57
|
}
|
|
40
58
|
return {
|