@rr0/cms 0.2.0 → 0.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.
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { brazilRegion } from "../../Brazil.js";
3
3
  import { BrazilRegionCode } from "../BrazilRegionCode.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const centralWest = brazilRegion(BrazilRegionCode.cw, new Place([PlaceLocation.fromDMS("14°47′S,53°31′O")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { brazilRegion } from "../../Brazil.js";
3
3
  import { BrazilRegionCode } from "../BrazilRegionCode.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const southEast = brazilRegion(BrazilRegionCode.se, new Place([PlaceLocation.fromDMS("14°47′S,53°31′O")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { UsaStates } from "../UsaStates.js";
3
3
  import { usaRegion } from "../../Usa.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const florida = usaRegion(UsaStates.fl, new Place([PlaceLocation.fromDMS("24°27'N,80° 02' W"), PlaceLocation.fromDMS("31° 00' N,87° 38' W")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { UsaStates } from "../UsaStates.js";
3
3
  import { usaRegion } from "../../Usa.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const hawaii = usaRegion(UsaStates.hi, new Place([PlaceLocation.fromDMS("21°28′00″N,157°58′00″W")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { UsaStates } from "../UsaStates.js";
3
3
  import { usaRegion } from "../../Usa.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const indiana = usaRegion(UsaStates.in, new Place([PlaceLocation.fromDMS("39°09′44″N,86°31′45″O")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { UsaStates } from "../UsaStates.js";
3
3
  import { usaRegion } from "../../Usa.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const virginia = usaRegion(UsaStates.va, new Place([PlaceLocation.fromDMS("38°0'N, 79°0'W")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { UsaStates } from "../UsaStates.js";
3
3
  import { usaRegion } from "../../Usa.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const washington = usaRegion(UsaStates.wa, new Place([PlaceLocation.fromDMS("45°33′ N,116°55′ W"), PlaceLocation.fromDMS("49°0' N,124°46′ W")]));
@@ -1,5 +1,4 @@
1
- import { Place } from "@rr0/place";
1
+ import { Place, PlaceLocation } from "@rr0/place";
2
2
  import { UsaStates } from "../UsaStates.js";
3
3
  import { usaRegion } from "../../Usa.js";
4
- import { PlaceLocation } from "@rr0/place";
5
4
  export const westVirginia = usaRegion(UsaStates.wv, new Place([PlaceLocation.fromDMS("38°51′27″N,82°7′43″W")]));
@@ -9,5 +9,5 @@ export declare class PeopleFactory extends TypedDataFactory<People, PeopleJson>
9
9
  * @param dirName
10
10
  */
11
11
  createFromDirName(dirName: string): People;
12
- createFromData(peopleJson: PeopleJson): People;
12
+ parse(peopleJson: PeopleJson): People;
13
13
  }
@@ -22,7 +22,7 @@ export class PeopleFactory extends TypedDataFactory {
22
22
  const id = path.basename(dirName);
23
23
  return new People(firstNames, lastName, undefined, undefined, undefined, false, undefined, undefined, undefined, id, dirName);
24
24
  }
25
- createFromData(peopleJson) {
25
+ parse(peopleJson) {
26
26
  const people = this.createFromDirName(peopleJson.dirName);
27
27
  peopleJson.name = people.name;
28
28
  Object.assign(people, super.parse(peopleJson));
@@ -49,17 +49,7 @@ export class PeopleFactory extends TypedDataFactory {
49
49
  }
50
50
  }
51
51
  people.title = people.firstAndLastName + (qualifier ? ` (${qualifier})` : "");
52
- const birthTime = peopleJson.birthTime;
53
- const events = peopleJson.events || [];
54
- if (birthTime) {
55
- delete peopleJson.birthTime;
56
- events.push({ type: "event", eventType: "birth", time: birthTime, events: [] });
57
- }
58
- const deathTime = peopleJson.deathTime;
59
- if (deathTime) {
60
- delete peopleJson.deathTime;
61
- events.push({ type: "event", eventType: "death", time: deathTime, events: [] });
62
- }
52
+ Object.assign(people, { events: peopleJson.events.map(this.eventFactory.parse) });
63
53
  return people;
64
54
  }
65
55
  }
@@ -23,9 +23,12 @@ export declare class PeopleJson implements RR0DataJson {
23
23
  */
24
24
  discredited: boolean;
25
25
  /**
26
- * @deprecated Use a "birth"-typed sub-data instead.
26
+ * @deprecated Use a "birth"-typed event instead.
27
27
  */
28
28
  birthTime?: EdtfDate;
29
+ /**
30
+ * @deprecated Use a "death"-typed event instead.
31
+ */
29
32
  deathTime?: EdtfDate;
30
33
  gender?: Gender;
31
34
  id: string;
@@ -1,5 +1,5 @@
1
1
  import { beforeEach, describe, expect, test } from "@javarome/testscript";
2
- import { PlaceLocation, GooglePlaceService } from "@rr0/place";
2
+ import { GooglePlaceService, PlaceLocation } from "@rr0/place";
3
3
  describe("PlaceService", () => {
4
4
  const apiKey = process.env.GOOGLE_MAPS_API_KEY;
5
5
  if (!apiKey) {
@@ -1,7 +1,7 @@
1
1
  import { API } from "./API.js";
2
- import { RR0Data, RR0EventFactory, TypedDataFactory } from "@rr0/data";
2
+ import { RR0EventFactory, TypedDataFactory } from "@rr0/data";
3
3
  import { APIJson } from "./APIJson";
4
4
  export declare class APIFactory extends TypedDataFactory<API, APIJson> {
5
5
  constructor(eventFactory: RR0EventFactory);
6
- createFromData(data: RR0Data): API;
6
+ parse(apiJson: APIJson): API;
7
7
  }
@@ -3,9 +3,8 @@ export class APIFactory extends TypedDataFactory {
3
3
  constructor(eventFactory) {
4
4
  super(eventFactory, "api", ["index"]);
5
5
  }
6
- createFromData(data) {
7
- const api = { type: "api", id: data.id, dirName: data.dirName, url: data.url, events: data.events || [] };
8
- Object.assign(api, data);
9
- return api;
6
+ parse(apiJson) {
7
+ const events = apiJson.events.map(this.eventFactory.parse);
8
+ return { type: "api", id: apiJson.id, dirName: apiJson.dirName, url: apiJson.url, events };
10
9
  }
11
10
  }
@@ -1,5 +1,4 @@
1
- import { TimeContext } from "@rr0/time";
2
- import { Level2Date as EdtfDate } from "@rr0/time";
1
+ import { Level2Date as EdtfDate, TimeContext } from "@rr0/time";
3
2
  export type TimeUrlBuilderOptions = {
4
3
  rootDir: string;
5
4
  };
@@ -55,7 +55,17 @@ export class RR0HttpDatasource extends RR0Datasource {
55
55
  const sources = this.getSources(row, itemContext);
56
56
  const description = this.getDescription(row);
57
57
  const id = RR0HttpDatasource.id(itemTime.date, place);
58
- return { type: "event", eventType: "sighting", events: [], url: url.href, place, time: itemTime.date, description, sources, id };
58
+ return {
59
+ type: "event",
60
+ eventType: "sighting",
61
+ events: [],
62
+ url: url.href,
63
+ place,
64
+ time: itemTime.date,
65
+ description,
66
+ sources,
67
+ id
68
+ };
59
69
  }
60
70
  async readCases(context) {
61
71
  const queryUrl = this.queryUrl(context);
@@ -77,7 +87,13 @@ export class RR0HttpDatasource extends RR0Datasource {
77
87
  const pubItems = title.split(",");
78
88
  const timeStr = pubItems[pubItems.length - 1].trim();
79
89
  let publisher;
80
- const time = EdtfDate.fromString(timeStr);
90
+ let time;
91
+ try {
92
+ time = EdtfDate.fromString(timeStr);
93
+ }
94
+ catch (e) {
95
+ console.warn("Could not parse source time", e);
96
+ }
81
97
  if (time) {
82
98
  pubItems.pop();
83
99
  }
@@ -7,10 +7,10 @@ import { CityService } from "../../../org";
7
7
  import { RR0Datasource } from "./RR0Datasource";
8
8
  export declare class RR0Mapping implements RR0CaseMapping<RR0CaseSummary> {
9
9
  readonly actions: ChronologyReplacerActions;
10
+ static baseUrl: URL;
11
+ static searchPath: string;
10
12
  readonly datasource: RR0Datasource;
11
13
  readonly fileDatasource: RR0FileDatasource;
12
14
  readonly mapper: RR0CaseSummaryMapper;
13
- static baseUrl: URL;
14
- static searchPath: string;
15
15
  constructor(cityService: CityService, actions: ChronologyReplacerActions);
16
16
  }
@@ -16,7 +16,16 @@ export class SceauCaseSummaryRR0Mapper {
16
16
  const source = {
17
17
  previousSourceRefs: [], events: [],
18
18
  url: sourceCase.url, title: "cas n° " + id, authors: this.authors,
19
- publication: { publisher: this.copyright, time: new EdtfDate({ year: sourceTime.getFullYear(), month: sourceTime.getMonth(), day: sourceTime.getDate(), hour: sourceTime.getHours(), minute: sourceTime.getSeconds() }) }
19
+ publication: {
20
+ publisher: this.copyright,
21
+ time: new EdtfDate({
22
+ year: sourceTime.getFullYear(),
23
+ month: sourceTime.getMonth(),
24
+ day: sourceTime.getDate(),
25
+ hour: sourceTime.getHours(),
26
+ minute: sourceTime.getSeconds()
27
+ })
28
+ }
20
29
  };
21
30
  const cityName = sourceCase.ville;
22
31
  const city = this.cityService.find(context, cityName, undefined);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@rr0/cms",
3
3
  "type": "module",
4
4
  "author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
5
- "version": "0.2.0",
5
+ "version": "0.2.1",
6
6
  "description": "RR0 Content Management System (CMS)",
7
7
  "exports": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "build": "rm -Rf dist && tsc --project tsconfig.prod.json",
25
25
  "prepublishOnly": "npm run build",
26
26
  "test": "testscript",
27
- "test-one": "rm -Rf out && tsx src/time/datasource/CsvMapper.test.ts",
27
+ "test-one": "rm -Rf out && tsx src/RR0Build.test.ts",
28
28
  "test-ci": "rm -Rf out && testscript"
29
29
  },
30
30
  "dependencies": {