@socialgouv/kali-data 2.614.0 → 2.616.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/data/KALICONT000005635472.json +0 -1
- package/data/KALICONT000005635624.json +6 -6
- package/data/KALICONT000005635905.json +0 -1
- package/data/index.json +14 -42
- package/package.json +78 -77
- package/src/__tests__/index.test.js +15 -15
- package/src/helpers/__tests__/checkArticleIdOrCid.test.js +8 -8
- package/src/helpers/__tests__/isFile.test.js +14 -14
- package/src/helpers/checkArticleIdOrCid.js +6 -6
- package/src/helpers/isFile.js +1 -1
- package/src/helpers/withArticleIdOrCid.js +2 -2
- package/src/index.js +11 -11
- package/src/libs/__tests__/getAgreement.test.js +28 -28
- package/src/libs/__tests__/getAgreementArticlesWithParentSections.test.js +13 -13
- package/src/libs/__tests__/getAgreementArticlesWithPath.test.js +13 -13
- package/src/libs/__tests__/getAgreementIdFromIdOrIdcc.test.js +17 -17
- package/src/libs/__tests__/getAgreements.test.js +3 -3
- package/src/libs/__tests__/getArticleWithParentSections.test.js +19 -19
- package/src/libs/__tests__/getArticleWithPath.test.js +19 -19
- package/src/libs/__tests__/getArticles.test.js +3 -3
- package/src/libs/__tests__/getIndexedArticle.test.js +19 -19
- package/src/libs/__tests__/hasAgreement.test.js +23 -23
- package/src/libs/__tests__/hasArticle.test.js +14 -14
- package/src/libs/getAgreement.js +7 -7
- package/src/libs/getAgreementArticlesWithParentSections.js +22 -22
- package/src/libs/getAgreementArticlesWithPath.js +11 -11
- package/src/libs/getAgreementIdFromIdOrIdcc.js +18 -18
- package/src/libs/getAgreements.js +3 -3
- package/src/libs/getArticleWithParentSections.js +34 -34
- package/src/libs/getArticleWithPath.js +25 -25
- package/src/libs/getArticles.js +3 -3
- package/src/libs/getIndexedArticle.js +6 -6
- package/src/libs/hasAgreement.js +10 -9
- package/src/libs/hasArticle.js +6 -6
|
@@ -10,7 +10,7 @@ const INDEXED_AGREEMENTS = getAgreements();
|
|
|
10
10
|
* @returns {boolean}
|
|
11
11
|
*/
|
|
12
12
|
const isAgreementIdcc = idcc =>
|
|
13
|
-
|
|
13
|
+
typeof idcc === "number" || (typeof idcc === "string" && /^\d{4}$/.test(idcc));
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @param {string} id
|
|
@@ -27,27 +27,27 @@ const isAgreementId = id => typeof id === "string" && /^KALICONT\d{12}$/.test(id
|
|
|
27
27
|
* @returns {string}
|
|
28
28
|
*/
|
|
29
29
|
function getAgreementIdFromIdOrIdcc(agreementIdOrIdcc) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
if (isAgreementIdcc(agreementIdOrIdcc)) {
|
|
31
|
+
const idcc = Number(agreementIdOrIdcc);
|
|
32
|
+
const matchIdcc = ({ num }) => num === idcc;
|
|
33
|
+
const maybeAgreement = INDEXED_AGREEMENTS.find(matchIdcc);
|
|
34
|
+
if (maybeAgreement === undefined) {
|
|
35
|
+
throw new Error(`No agreement found with this IDCC (${idcc}).`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return maybeAgreement.id;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
if (typeof agreementIdOrIdcc !== "number" && isAgreementId(agreementIdOrIdcc)) {
|
|
42
|
+
const agreementId = agreementIdOrIdcc;
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return agreementId;
|
|
45
|
-
}
|
|
44
|
+
return agreementId;
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
throw new Error(
|
|
48
|
+
`<agreementIdOrIdcc> is malformed (${agreementIdOrIdcc}). ` +
|
|
49
|
+
`It must be a valid agreement IDCC (string | number) or ID (string: "KALICONT123456789012").`,
|
|
50
|
+
);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
module.exports = getAgreementIdFromIdOrIdcc;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
const INDEXED_AGREEMENTS =
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** @type {KaliData.IndexedAgreement[]} */
|
|
5
|
+
(require("../../data/index.json"));
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get the full list of indexed agreements.
|
|
@@ -10,7 +10,7 @@ const INDEXED_AGREEMENTS =
|
|
|
10
10
|
* @returns {KaliData.IndexedAgreement[]}
|
|
11
11
|
*/
|
|
12
12
|
function getAgreements() {
|
|
13
|
-
|
|
13
|
+
return INDEXED_AGREEMENTS;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
module.exports = getAgreements;
|
|
@@ -24,10 +24,10 @@ const getIndexedArticle = require("./getIndexedArticle");
|
|
|
24
24
|
* @returns {AgreementArticleWithParent=}
|
|
25
25
|
*/
|
|
26
26
|
const findArticleWithData = (agreement, data) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
unistUtilFind(agreement, {
|
|
28
|
+
data,
|
|
29
|
+
type: "article",
|
|
30
|
+
});
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @param {AgreementArticleWithParent} article
|
|
@@ -35,17 +35,17 @@ const findArticleWithData = (agreement, data) =>
|
|
|
35
35
|
* @returns {KaliData.AgreementArticleWithParentSections["sections"]}
|
|
36
36
|
*/
|
|
37
37
|
const getParentSectionsFromArticle = article => {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const sections = [];
|
|
39
|
+
let section = article.parent;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
while (section) {
|
|
42
|
+
const { data, type } = section;
|
|
43
|
+
sections.unshift({ data, type });
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
section = section.parent;
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
return sections;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
/**
|
|
@@ -58,34 +58,34 @@ const getParentSectionsFromArticle = article => {
|
|
|
58
58
|
* @deprecated Use `getArticleWithPath()` instead.
|
|
59
59
|
*/
|
|
60
60
|
function getArticleWithParentSections(articleIdOrCid) {
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
}
|
|
63
81
|
|
|
64
|
-
// First attempt with an article ID:
|
|
65
|
-
const maybeArticleWithId = findArticleWithData(agreement, { id: articleIdOrCid });
|
|
66
|
-
if (maybeArticleWithId !== undefined) {
|
|
67
82
|
/** @type {KaliData.AgreementArticleWithParentSections} */
|
|
68
83
|
const articleWithParentSections = {
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
...maybeArticleWithCid,
|
|
85
|
+
sections: getParentSectionsFromArticle(maybeArticleWithCid),
|
|
71
86
|
};
|
|
72
87
|
|
|
73
88
|
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
89
|
}
|
|
90
90
|
|
|
91
91
|
module.exports = getArticleWithParentSections;
|
|
@@ -12,10 +12,10 @@ const getIndexedArticle = require("./getIndexedArticle");
|
|
|
12
12
|
* @returns {KaliData.AgreementArticle=}
|
|
13
13
|
*/
|
|
14
14
|
const findArticleWithData = (agreement, data) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
unistUtilFind(agreement, {
|
|
16
|
+
data,
|
|
17
|
+
type: "article",
|
|
18
|
+
});
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Get an agreement article unist node with its parent sections path.
|
|
@@ -26,32 +26,32 @@ const findArticleWithData = (agreement, data) =>
|
|
|
26
26
|
* @returns {KaliData.AgreementArticleWithPath}
|
|
27
27
|
*/
|
|
28
28
|
function getArticleWithPath(articleIdOrCid) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const { agreementId, path } = getIndexedArticle(articleIdOrCid);
|
|
30
|
+
const agreement = getAgreement(agreementId);
|
|
31
|
+
|
|
32
|
+
// First attempt with an article ID:
|
|
33
|
+
const maybeArticleWithId = findArticleWithData(agreement, { id: articleIdOrCid });
|
|
34
|
+
if (maybeArticleWithId !== undefined) {
|
|
35
|
+
const articleWithPath = {
|
|
36
|
+
...maybeArticleWithId,
|
|
37
|
+
path,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return articleWithPath;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Second attempt with an article CID:
|
|
44
|
+
const maybeArticleWithCid = findArticleWithData(agreement, { cid: articleIdOrCid });
|
|
45
|
+
if (maybeArticleWithCid === undefined) {
|
|
46
|
+
throw new Error(`No agreement article found with this ID or CID (${articleIdOrCid}).`);
|
|
47
|
+
}
|
|
31
48
|
|
|
32
|
-
// First attempt with an article ID:
|
|
33
|
-
const maybeArticleWithId = findArticleWithData(agreement, { id: articleIdOrCid });
|
|
34
|
-
if (maybeArticleWithId !== undefined) {
|
|
35
49
|
const articleWithPath = {
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
...maybeArticleWithCid,
|
|
51
|
+
path,
|
|
38
52
|
};
|
|
39
53
|
|
|
40
54
|
return articleWithPath;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Second attempt with an article CID:
|
|
44
|
-
const maybeArticleWithCid = findArticleWithData(agreement, { cid: articleIdOrCid });
|
|
45
|
-
if (maybeArticleWithCid === undefined) {
|
|
46
|
-
throw new Error(`No agreement article found with this ID or CID (${articleIdOrCid}).`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const articleWithPath = {
|
|
50
|
-
...maybeArticleWithCid,
|
|
51
|
-
path,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return articleWithPath;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
module.exports = getArticleWithPath;
|
package/src/libs/getArticles.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
const INDEXED_ARTICLES =
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** @type {KaliData.IndexedArticle[]} */
|
|
5
|
+
(require("../../data/articles/index.json"));
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get the full list of indexed articles.
|
|
@@ -10,7 +10,7 @@ const INDEXED_ARTICLES =
|
|
|
10
10
|
* @returns {KaliData.IndexedArticle[]}
|
|
11
11
|
*/
|
|
12
12
|
function getArticles() {
|
|
13
|
-
|
|
13
|
+
return INDEXED_ARTICLES;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
module.exports = getArticles;
|
|
@@ -14,14 +14,14 @@ const INDEXED_ARTICLES = getArticles();
|
|
|
14
14
|
* @returns {KaliData.IndexedArticle}
|
|
15
15
|
*/
|
|
16
16
|
function getIndexedArticle(articleIdOrCid) {
|
|
17
|
-
|
|
17
|
+
checkArticleIdOrCid(articleIdOrCid);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const maybeIndexedArticle = INDEXED_ARTICLES.find(withArticleIdOrCid(articleIdOrCid));
|
|
20
|
+
if (maybeIndexedArticle === undefined) {
|
|
21
|
+
throw new Error(`No agreement article found with this ID or CID (${articleIdOrCid}).`);
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
return maybeIndexedArticle;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
module.exports = getIndexedArticle;
|
package/src/libs/hasAgreement.js
CHANGED
|
@@ -16,16 +16,17 @@ const INDEXED_AGREEMENTS = getAgreements();
|
|
|
16
16
|
* @returns {boolean}
|
|
17
17
|
*/
|
|
18
18
|
function hasAgreement(agreementIdOrIdcc) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
try {
|
|
20
|
+
const agreementId = getAgreementIdFromIdOrIdcc(agreementIdOrIdcc);
|
|
21
|
+
const maybeFilePath = path.join(__dirname, `../../data/${agreementId}.json`);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
return (
|
|
24
|
+
INDEXED_AGREEMENTS.find(({ id }) => id === agreementId) !== undefined &&
|
|
25
|
+
isFile(maybeFilePath)
|
|
26
|
+
);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
module.exports = hasAgreement;
|
package/src/libs/hasArticle.js
CHANGED
|
@@ -14,13 +14,13 @@ const INDEXED_ARTICLES = getArticles();
|
|
|
14
14
|
* @returns {boolean}
|
|
15
15
|
*/
|
|
16
16
|
function hasArticle(articleIdOrCid) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
try {
|
|
18
|
+
checkArticleIdOrCid(articleIdOrCid);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
return INDEXED_ARTICLES.find(withArticleIdOrCid(articleIdOrCid)) !== undefined;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
module.exports = hasArticle;
|