@socialgouv/kali-data-types 2.671.0 → 3.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socialgouv/kali-data-types",
3
- "version": "2.671.0",
3
+ "version": "3.0.0",
4
4
  "devDependencies": {
5
5
  "@babel/core": "^7.16.0",
6
6
  "@babel/plugin-transform-modules-commonjs": "^7.16.0",
@@ -44,6 +44,7 @@
44
44
  "scripts": {
45
45
  "data:check": "node -r esm ./scripts/check.js",
46
46
  "data:fetch": "node -r dotenv/config -r esm ./scripts/fetch.js dotenv_config_path=./.env",
47
+ "data:clean": "node -r esm ./scripts/clean.js",
47
48
  "data:list": "node -r esm ./scripts/list.js",
48
49
  "data:match": "node -r esm ./scripts/match.js",
49
50
  "data:update": "yarn data:fetch && yarn data:match && yarn data:list && yarn data:check",
@@ -11,11 +11,9 @@ test(`@socialgouv/kali-data`, () => {
11
11
  expect(Object.keys(kaliData)).toHaveLength(libNames.length);
12
12
 
13
13
  expect(kaliData.getAgreement).toBeInstanceOf(Function);
14
- expect(kaliData.getAgreementArticlesWithParentSections).toBeInstanceOf(Function);
15
14
  expect(kaliData.getAgreementArticlesWithPath).toBeInstanceOf(Function);
16
15
  expect(kaliData.getAgreementIdFromIdOrIdcc).toBeInstanceOf(Function);
17
16
  expect(kaliData.getAgreements).toBeInstanceOf(Function);
18
- expect(kaliData.getArticleWithParentSections).toBeInstanceOf(Function);
19
17
  expect(kaliData.getArticleWithPath).toBeInstanceOf(Function);
20
18
  expect(kaliData.getArticles).toBeInstanceOf(Function);
21
19
  expect(kaliData.getIndexedArticle).toBeInstanceOf(Function);
package/src/index.d.ts CHANGED
@@ -7,18 +7,6 @@
7
7
  */
8
8
  export function getAgreement(agreementIdOrIdcc: number | string): KaliData.Agreement;
9
9
 
10
- /**
11
- * Get a flat unist array of all the articles an agreement contains.
12
- * Each article includes a list of its parent sections.
13
- *
14
- * @see https://github.com/syntax-tree/unist
15
- *
16
- * @deprecated Use `getAgreementArticlesWithPath()` instead.
17
- */
18
- export function getAgreementArticlesWithParentSections(
19
- agreementIdOrIdcc: number | string,
20
- ): KaliData.AgreementArticleWithParentSections[];
21
-
22
10
  /**
23
11
  * Get a flat unist array of all the articles an agreement contains.
24
12
  * Each article includes its parent sections path, as an ordered list of their titles.
@@ -44,17 +32,6 @@ export function getAgreements(): KaliData.IndexedAgreement[];
44
32
  */
45
33
  export function getArticles(): KaliData.IndexedArticle[];
46
34
 
47
- /**
48
- * Get an agreement article unist node with its parent sections.
49
- *
50
- * @see https://github.com/syntax-tree/unist
51
- *
52
- * @deprecated Use `getArticleWithPath()` instead.
53
- */
54
- export function getArticleWithParentSections(
55
- articleIdOrCid: string,
56
- ): KaliData.AgreementArticleWithParentSections;
57
-
58
35
  /**
59
36
  * Get an agreement article unist node with its parent sections path.
60
37
  * The parent sections path is represented as an ordered array of their titles.
@@ -200,6 +177,7 @@ type IndexedAgreement = {
200
177
  title: string;
201
178
  url?: string;
202
179
  synonymes?: string[];
180
+ fetchArticles?: boolean;
203
181
  };
204
182
 
205
183
  type IndexedArticle = {
package/src/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  // @ts-check
2
2
 
3
3
  const getAgreement = require("./libs/getAgreement");
4
- const getAgreementArticlesWithParentSections = require("./libs/getAgreementArticlesWithParentSections");
5
4
  const getAgreementArticlesWithPath = require("./libs/getAgreementArticlesWithPath");
6
5
  const getAgreements = require("./libs/getAgreements");
7
- const getArticleWithParentSections = require("./libs/getArticleWithParentSections");
8
6
  const getArticleWithPath = require("./libs/getArticleWithPath");
9
7
  const getAgreementIdFromIdOrIdcc = require("./libs/getAgreementIdFromIdOrIdcc");
10
8
  const getArticles = require("./libs/getArticles");
@@ -15,12 +13,10 @@ const getAgreementsWithNoId = require("./libs/getAgreementsWithNoId");
15
13
 
16
14
  module.exports = {
17
15
  getAgreement,
18
- getAgreementArticlesWithParentSections,
19
16
  getAgreementArticlesWithPath,
20
17
  getAgreementIdFromIdOrIdcc,
21
18
  getAgreements,
22
19
  getAgreementsWithNoId,
23
- getArticleWithParentSections,
24
20
  getArticleWithPath,
25
21
  getArticles,
26
22
  getIndexedArticle,
@@ -3,18 +3,18 @@ import getArticleWithPath from "../getArticleWithPath";
3
3
  describe(`libs/getArticleWithPath()`, () => {
4
4
  describe(`should match properties`, () => {
5
5
  it(`with an existing main article ID`, () => {
6
- const received = getArticleWithPath("KALIARTI000005781818");
6
+ const received = getArticleWithPath("KALIARTI000043941797");
7
7
 
8
- expect(received.data.cid).toBe("KALIARTI000005781818");
9
- expect(received.data.id).toBe("KALIARTI000005781818");
8
+ expect(received.data.cid).toBe("KALIARTI000043941797");
9
+ expect(received.data.id).toBe("KALIARTI000043941797");
10
10
  expect(received.path.length).toBeGreaterThan(1);
11
11
  });
12
12
 
13
13
  it(`with an existing main article CID`, () => {
14
- const received = getArticleWithPath("KALIARTI000005781804");
14
+ const received = getArticleWithPath("KALIARTI000005849315");
15
15
 
16
- expect(received.data.cid).toBe("KALIARTI000005781804");
17
- expect(received.data.id).toBe("KALIARTI000045466361");
16
+ expect(received.data.cid).toBe("KALIARTI000005849315");
17
+ expect(received.data.id).toBe("KALIARTI000005849317");
18
18
  expect(received.path.length).toBeGreaterThan(1);
19
19
  });
20
20
 
@@ -1,23 +0,0 @@
1
- import getAgreementArticlesWithParentSections from "../getAgreementArticlesWithParentSections";
2
-
3
- describe(`libs/getAgreementArticlesWithParentSections()`, () => {
4
- describe(`should match snapshot`, () => {
5
- it(`with an existing agreement ID`, () => {
6
- const received = getAgreementArticlesWithParentSections("KALICONT000005635221");
7
-
8
- expect(received[0].sections.length).toBeGreaterThan(1);
9
- });
10
-
11
- it(`with an existing agreement IDCC (string)`, () => {
12
- const received = getAgreementArticlesWithParentSections("1480");
13
-
14
- expect(received[0].sections.length).toBeGreaterThan(1);
15
- });
16
-
17
- it(`with an existing agreement IDCC (number)`, () => {
18
- const received = getAgreementArticlesWithParentSections(1480);
19
-
20
- expect(received[0].sections.length).toBeGreaterThan(1);
21
- });
22
- });
23
- });
@@ -1,29 +0,0 @@
1
- import getArticleWithParentSections from "../getArticleWithParentSections";
2
-
3
- describe(`libs/getArticleWithParentSections()`, () => {
4
- describe(`should match properties`, () => {
5
- it(`with an existing main article ID`, () => {
6
- const received = getArticleWithParentSections("KALIARTI000005781804");
7
-
8
- expect(received.data.cid).toBe("KALIARTI000005781804");
9
- expect(received.data.id).toBe("KALIARTI000045466361");
10
- expect(received.sections.length).toBeGreaterThan(1);
11
- });
12
-
13
- it(`with an existing main article CID`, () => {
14
- const received = getArticleWithParentSections("KALIARTI000005781804");
15
-
16
- expect(received.data.cid).toBe("KALIARTI000005781804");
17
- expect(received.data.id).toBe("KALIARTI000045466361");
18
- expect(received.sections.length).toBeGreaterThan(1);
19
- });
20
-
21
- it(`with an existing additional article ID`, () => {
22
- const received = getArticleWithParentSections("KALIARTI000041787475");
23
-
24
- expect(received.data.cid).toBe("KALIARTI000041787475");
25
- expect(received.data.id).toBe("KALIARTI000041787475");
26
- expect(received.sections.length).toBeGreaterThan(1);
27
- });
28
- });
29
- });
@@ -1,43 +0,0 @@
1
- // @ts-check
2
-
3
- const unistUtilFlatFilter = require("unist-util-flat-filter");
4
-
5
- const getAgreement = require("./getAgreement");
6
- const getArticleWithParentSections = require("./getArticleWithParentSections");
7
-
8
- /**
9
- * Get a flat unist array of all the articles an agreement contains.
10
- * Each article includes a list of its parent sections.
11
- *
12
- * @param {number | string} agreementIdOrIdcc
13
- *
14
- * @returns {KaliData.AgreementArticleWithParentSections[]}
15
- *
16
- * @deprecated Use `getAgreementArticlesWithPath()` instead.
17
- */
18
- function getAgreementArticlesWithParentSections(agreementIdOrIdcc) {
19
- const agreement = getAgreement(agreementIdOrIdcc);
20
-
21
- const articles =
22
- /** @type {{ children: KaliData.AgreementArticle[], type: "root" }} */
23
- (/** @type {*} */ (unistUtilFlatFilter(agreement, { type: "article" })));
24
- const articleIds = articles.children.map(({ data: { id } }) => id);
25
-
26
- const articlesWithParentSections = articleIds.reduce(
27
- (prevArticlesWithParentSections, articleId) => {
28
- try {
29
- const articleWithParentSections = getArticleWithParentSections(articleId);
30
- // console.log(articleWithParentSections);
31
-
32
- return [...prevArticlesWithParentSections, articleWithParentSections];
33
- } catch (err) {
34
- return prevArticlesWithParentSections;
35
- }
36
- },
37
- [],
38
- );
39
-
40
- return articlesWithParentSections;
41
- }
42
-
43
- module.exports = getAgreementArticlesWithParentSections;
@@ -1,91 +0,0 @@
1
- // @ts-check
2
- /**
3
- * @typedef AgreementArticleWithParent
4
- * @property {"article"} type
5
- * @property {KaliData.AgreementArticleData} data
6
- * @property {AgreementSectionWithParent} parent
7
- *
8
- * @typedef AgreementSectionWithParent
9
- * @property {"section"} type
10
- * @property {KaliData.AgreementSectionData} data
11
- * @property {KaliData.AgreementArticle[]} children
12
- * @property {AgreementSectionWithParent} parent
13
- */
14
-
15
- const unistUtilFind = require("unist-util-find");
16
-
17
- const getAgreement = require("./getAgreement");
18
- const getIndexedArticle = require("./getIndexedArticle");
19
-
20
- /**
21
- * @param {KaliData.Agreement} agreement
22
- * @param {Partial<KaliData.AgreementArticleData>} data
23
- *
24
- * @returns {AgreementArticleWithParent=}
25
- */
26
- const findArticleWithData = (agreement, data) =>
27
- unistUtilFind(agreement, {
28
- data,
29
- type: "article",
30
- });
31
-
32
- /**
33
- * @param {AgreementArticleWithParent} article
34
- *
35
- * @returns {KaliData.AgreementArticleWithParentSections["sections"]}
36
- */
37
- const getParentSectionsFromArticle = article => {
38
- const sections = [];
39
- let section = article.parent;
40
-
41
- while (section) {
42
- const { data, type } = section;
43
- sections.unshift({ data, type });
44
-
45
- section = section.parent;
46
- }
47
-
48
- return sections;
49
- };
50
-
51
- /**
52
- * Get an agreement article unist node with its parent sections.
53
- *
54
- * @param {string} articleIdOrCid
55
- *
56
- * @returns {KaliData.AgreementArticleWithParentSections}
57
- *
58
- * @deprecated Use `getArticleWithPath()` instead.
59
- */
60
- function getArticleWithParentSections(articleIdOrCid) {
61
- const { agreementId } = getIndexedArticle(articleIdOrCid);
62
- const agreement = getAgreement(agreementId);
63
-
64
- // First attempt with an article ID:
65
- const maybeArticleWithId = findArticleWithData(agreement, { id: articleIdOrCid });
66
- if (maybeArticleWithId !== undefined) {
67
- /** @type {KaliData.AgreementArticleWithParentSections} */
68
- const articleWithParentSections = {
69
- ...maybeArticleWithId,
70
- sections: getParentSectionsFromArticle(maybeArticleWithId),
71
- };
72
-
73
- return articleWithParentSections;
74
- }
75
-
76
- // Second attempt with an article CID:
77
- const maybeArticleWithCid = findArticleWithData(agreement, { cid: articleIdOrCid });
78
- if (maybeArticleWithCid === undefined) {
79
- throw new Error(`No agreement article found with this ID or CID (${articleIdOrCid}).`);
80
- }
81
-
82
- /** @type {KaliData.AgreementArticleWithParentSections} */
83
- const articleWithParentSections = {
84
- ...maybeArticleWithCid,
85
- sections: getParentSectionsFromArticle(maybeArticleWithCid),
86
- };
87
-
88
- return articleWithParentSections;
89
- }
90
-
91
- module.exports = getArticleWithParentSections;