cocoda-sdk 1.0.13 → 2.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.
Files changed (36) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +74 -28
  3. package/dist/cjs/index.cjs +2673 -0
  4. package/dist/cocoda-sdk.js +33 -17423
  5. package/dist/cocoda-sdk.js.LICENSES.txt +105 -86
  6. package/dist/cocoda-sdk.js.map +7 -0
  7. package/dist/esm/errors/index.js +46 -0
  8. package/dist/esm/index.js +9 -0
  9. package/dist/esm/lib/CocodaSDK.js +269 -0
  10. package/dist/esm/providers/base-provider.js +368 -0
  11. package/dist/esm/providers/concept-api-provider.js +278 -0
  12. package/dist/esm/providers/index.js +20 -0
  13. package/dist/esm/providers/label-search-suggestion-provider.js +101 -0
  14. package/dist/esm/providers/loc-api-provider.js +185 -0
  15. package/dist/esm/providers/local-mappings-provider.js +337 -0
  16. package/dist/esm/providers/mappings-api-provider.js +264 -0
  17. package/dist/esm/providers/occurrences-api-provider.js +163 -0
  18. package/dist/esm/providers/reconciliation-api-provider.js +140 -0
  19. package/dist/esm/providers/skosmos-api-provider.js +345 -0
  20. package/{utils → dist/esm/utils}/index.js +40 -53
  21. package/dist/esm/utils/lodash.js +34 -0
  22. package/package.json +16 -17
  23. package/errors/index.js +0 -119
  24. package/index.js +0 -5
  25. package/lib/CocodaSDK.js +0 -360
  26. package/providers/base-provider.js +0 -581
  27. package/providers/concept-api-provider.js +0 -377
  28. package/providers/index.js +0 -34
  29. package/providers/label-search-suggestion-provider.js +0 -219
  30. package/providers/loc-api-provider.js +0 -275
  31. package/providers/local-mappings-provider.js +0 -459
  32. package/providers/mappings-api-provider.js +0 -396
  33. package/providers/occurrences-api-provider.js +0 -234
  34. package/providers/reconciliation-api-provider.js +0 -211
  35. package/providers/skosmos-api-provider.js +0 -441
  36. package/utils/lodash.js +0 -21
@@ -1,163 +1,150 @@
1
1
  const requestMethods = [
2
- // General
3
2
  {
4
3
  method: "getRegistries",
5
4
  fallback: [],
6
- type: "Registries",
5
+ type: "Registries"
7
6
  },
8
7
  {
9
8
  method: "getSchemes",
10
9
  fallback: [],
11
- type: "Schemes",
10
+ type: "Schemes"
12
11
  },
13
12
  {
14
13
  method: "vocSearch",
15
14
  fallback: [],
16
- type: "Schemes",
15
+ type: "Schemes"
17
16
  },
18
17
  {
19
18
  method: "getTypes",
20
19
  fallback: [],
21
- type: "Types",
20
+ type: "Types"
22
21
  },
23
22
  {
24
23
  method: "suggest",
25
- fallback: ["", [], [], []],
24
+ fallback: ["", [], [], []]
26
25
  },
27
26
  {
28
27
  method: "vocSuggest",
29
- fallback: ["", [], [], []],
28
+ fallback: ["", [], [], []]
30
29
  },
31
30
  {
32
31
  method: "getConcordances",
33
32
  fallback: [],
34
- type: "Concordances",
33
+ type: "Concordances"
35
34
  },
36
35
  {
37
36
  method: "getOccurrences",
38
37
  fallback: [],
39
- type: "Occurrences",
38
+ type: "Occurrences"
40
39
  },
41
- // Concepts
42
40
  {
43
41
  method: "getTop",
44
42
  fallback: [],
45
- type: "Concepts",
43
+ type: "Concepts"
46
44
  },
47
45
  {
48
46
  method: "getConcepts",
49
47
  fallback: [],
50
- type: "Concepts",
48
+ type: "Concepts"
51
49
  },
52
50
  {
53
51
  method: "getNarrower",
54
52
  fallback: [],
55
- type: "Concepts",
53
+ type: "Concepts"
56
54
  },
57
55
  {
58
56
  method: "getAncestors",
59
57
  fallback: [],
60
- type: "Concepts",
58
+ type: "Concepts"
61
59
  },
62
60
  {
63
61
  method: "search",
64
62
  fallback: [],
65
- type: "Concepts",
63
+ type: "Concepts"
66
64
  },
67
- // Mappings
68
65
  {
69
66
  method: "getMapping",
70
67
  fallback: null,
71
- type: "Mapping",
68
+ type: "Mapping"
72
69
  },
73
70
  {
74
71
  method: "getMappings",
75
72
  fallback: [],
76
- type: "Mappings",
73
+ type: "Mappings"
77
74
  },
78
75
  {
79
76
  method: "postMapping",
80
77
  fallback: null,
81
- type: "Mapping",
78
+ type: "Mapping"
82
79
  },
83
80
  {
84
81
  method: "postMappings",
85
82
  fallback: [],
86
- type: "Mapping",
83
+ type: "Mapping"
87
84
  },
88
85
  {
89
86
  method: "putMapping",
90
87
  fallback: null,
91
- type: "Mapping",
88
+ type: "Mapping"
92
89
  },
93
90
  {
94
91
  method: "patchMapping",
95
92
  fallback: null,
96
- type: "Mapping",
93
+ type: "Mapping"
97
94
  },
98
95
  {
99
96
  method: "deleteMapping",
100
- fallback: false,
97
+ fallback: false
101
98
  },
102
99
  {
103
100
  method: "deleteMappings",
104
- fallback: [],
101
+ fallback: []
105
102
  },
106
- // Annotations
107
- // {
108
- // method: "getAnnotation",
109
- // fallback: "",
110
- // },
111
103
  {
112
104
  method: "getAnnotations",
113
105
  fallback: [],
114
- type: "Annotations",
106
+ type: "Annotations"
115
107
  },
116
108
  {
117
109
  method: "postAnnotation",
118
110
  fallback: null,
119
- type: "Annotation",
111
+ type: "Annotation"
120
112
  },
121
113
  {
122
114
  method: "putAnnotation",
123
115
  fallback: null,
124
- type: "Annotation",
116
+ type: "Annotation"
125
117
  },
126
118
  {
127
119
  method: "patchAnnotation",
128
120
  fallback: null,
129
- type: "Annotation",
121
+ type: "Annotation"
130
122
  },
131
123
  {
132
124
  method: "deleteAnnotation",
133
- fallback: false,
134
- },
135
- ]
136
-
125
+ fallback: false
126
+ }
127
+ ];
137
128
  function concatUrl(...parts) {
138
- let [url, ...otherParts] = parts
129
+ let [url, ...otherParts] = parts;
139
130
  for (let part of otherParts) {
140
131
  if (!url.endsWith("/")) {
141
- url += "/"
132
+ url += "/";
142
133
  }
143
134
  if (part.startsWith("/")) {
144
- part = part.slice(1)
135
+ part = part.slice(1);
145
136
  }
146
- url += part
137
+ url += part;
147
138
  }
148
- return url
139
+ return url;
149
140
  }
150
-
151
-
152
- // Retain custom array properties
153
141
  function withCustomProps(arr, from) {
154
- arr._totalCount = from._totalCount
155
- arr._url = from._url
156
- return arr
142
+ arr._totalCount = from._totalCount;
143
+ arr._url = from._url;
144
+ return arr;
157
145
  }
158
-
159
- module.exports = {
160
- requestMethods,
146
+ export {
161
147
  concatUrl,
162
- withCustomProps,
163
- }
148
+ requestMethods,
149
+ withCustomProps
150
+ };
@@ -0,0 +1,34 @@
1
+ import {
2
+ get,
3
+ set,
4
+ uniq,
5
+ intersection,
6
+ union,
7
+ forOwn,
8
+ isArray,
9
+ isObject,
10
+ isString,
11
+ isEmpty,
12
+ isEqual,
13
+ merge,
14
+ last,
15
+ omit,
16
+ concat
17
+ } from "lodash-es";
18
+ export {
19
+ concat,
20
+ forOwn,
21
+ get,
22
+ intersection,
23
+ isArray,
24
+ isEmpty,
25
+ isEqual,
26
+ isObject,
27
+ isString,
28
+ last,
29
+ merge,
30
+ omit,
31
+ set,
32
+ union,
33
+ uniq
34
+ };
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "cocoda-sdk",
3
- "version": "1.0.13",
3
+ "version": "2.0.0",
4
4
  "description": "SDK for Cocoda",
5
- "main": "index.js",
6
- "browser": "dist/cocoda-sdk.js",
7
- "browserslist": "> 1.5%, not dead",
5
+ "main": "dist/cjs/index.cjs",
6
+ "module": "dist/esm/index.js",
7
+ "jsdelivr": "dist/cocoda-sdk.js",
8
+ "unpkg": "dist/cocoda-sdk.js",
9
+ "sideEffects": false,
10
+ "browserslist": "defaults and not ie<=11 and supports es6",
11
+ "type": "module",
8
12
  "files": [
9
13
  "dist",
10
14
  "lib",
@@ -17,7 +21,7 @@
17
21
  "lint": "eslint ./**/*.js ./**/.*.js",
18
22
  "fix": "eslint --fix ./**/*.js ./**/.*.js",
19
23
  "lint-staged": "lint-staged",
20
- "build": "rollup -c",
24
+ "build": "node --experimental-json-modules build.js",
21
25
  "release": "npm run build && npm test && git checkout dev && git pull && npm version $SEMVER && git push && git checkout master && git merge dev && git push --follow-tags && git checkout dev",
22
26
  "release:patch": "SEMVER=patch npm run release",
23
27
  "release:minor": "SEMVER=minor npm run release",
@@ -46,28 +50,23 @@
46
50
  },
47
51
  "homepage": "https://github.com/gbv/cocoda-sdk#readme",
48
52
  "devDependencies": {
49
- "@babel/core": "^7.15.0",
50
- "@babel/helper-define-map": "^7.14.5",
51
- "@babel/preset-env": "^7.15.0",
52
- "@rollup/plugin-babel": "^5.3.0",
53
- "@rollup/plugin-commonjs": "^20.0.0",
54
- "@rollup/plugin-json": "^4.1.0",
55
- "@rollup/plugin-node-resolve": "^13.0.4",
56
53
  "axios-mock-adapter": "^1.20.0",
54
+ "esbuild": "^0.12.28",
55
+ "esbuild-plugin-ifdef": "^1.0.1",
57
56
  "eslint": "^7.32.0",
58
57
  "eslint-config-gbv": "^1.0.3",
58
+ "glob": "^7.1.7",
59
+ "license-checker": "^25.0.1",
59
60
  "lint-staged": "^11.1.2",
60
61
  "mocha": "^9.1.1",
61
62
  "mocha-eslint": "^7.0.0",
62
- "pre-commit": "^1.2.2",
63
- "rollup": "^2.56.3",
64
- "rollup-plugin-license": "^2.5.0"
63
+ "pre-commit": "^1.2.2"
65
64
  },
66
65
  "dependencies": {
67
- "axios": "^0.21.1",
66
+ "axios": "^0.21.4",
68
67
  "jskos-tools": "^1.0.17",
69
68
  "localforage": "^1.10.0",
70
- "lodash": "^4.17.21",
69
+ "lodash-es": "^4.17.21",
71
70
  "uuid": "^8.3.2"
72
71
  }
73
72
  }
package/errors/index.js DELETED
@@ -1,119 +0,0 @@
1
- /**
2
- * CDKError superclass.
3
- *
4
- * @category Errors
5
- */
6
- class CDKError extends Error {
7
-
8
- /**
9
- * CDKError constructor.
10
- *
11
- * @param {Object} options
12
- * @param {string} [options.message=""] message for the error
13
- * @param {Error} [options.relatedError=null] related error
14
- * @param {number} [options.code] HTTP status code for the error
15
- */
16
- constructor({ message = "", relatedError = null, code = null } = {}) {
17
- if (!message && relatedError && relatedError.message) {
18
- message = relatedError.message
19
- }
20
- super(message)
21
- this.name = this.constructor.name
22
- this.relatedError = relatedError
23
- this.code = code
24
- }
25
- }
26
-
27
- /**
28
- * MethodNotImplementedError is thrown when the called method is valid, but not implemented for the current provider.
29
- *
30
- * @category Errors
31
- */
32
- class MethodNotImplementedError extends CDKError {
33
-
34
- /**
35
- * MethodNotImplementedError constructor.
36
- *
37
- * @param {Object} config
38
- * @param {string} config.method method that this error refers to
39
- * @param {string} [config.message=""] message for the error
40
- */
41
- constructor({ method, message = "", ...options }) {
42
- options.message = `Method not implemented: ${method} (${message})`
43
- super(options)
44
- }
45
- }
46
-
47
- /**
48
- * InvalidOrMissingParameterError is thrown when a parameter is missing or is not valid for the request.
49
- *
50
- * @category Errors
51
- */
52
- class InvalidOrMissingParameterError extends CDKError {
53
-
54
- /**
55
- * InvalidOrMissingParameterError constructor.
56
- *
57
- * @param {Object} config
58
- * @param {string} config.parameter parameter that this error refers to
59
- * @param {string} [config.message=""] message for the error
60
- */
61
- constructor({ parameter, message = "", ...options }) {
62
- options.message = `Invalid or missing parameter: ${parameter} (${message})`
63
- super(options)
64
- }
65
- }
66
-
67
- /**
68
- * InvalidRequestError is thrown when the server responded with a 4xx error (i.e. it's a problem on the client side).
69
- *
70
- * @category Errors
71
- */
72
- class InvalidRequestError extends CDKError {}
73
-
74
- /**
75
- * BackendError is thrown when the server responded with a 5xx error (i.e. it's a problem on the server side).
76
- *
77
- * @category Errors
78
- */
79
- class BackendError extends CDKError {}
80
-
81
- /**
82
- * BackendUnavailableError is thrown when the server did not respond, but the client's internet connection seems to be working.
83
- *
84
- * @category Errors
85
- */
86
- class BackendUnavailableError extends CDKError {}
87
-
88
- /**
89
- * NetworkError is thrown when the request could not be performend (e.g. the network was not available).
90
- *
91
- * @category Errors
92
- */
93
- class NetworkError extends CDKError {}
94
-
95
- /**
96
- * MissingApiUrlError is thrown when the called method is valid, but the required API URL is not available for the current registry.
97
- *
98
- * @category Errors
99
- */
100
- class MissingApiUrlError extends CDKError {}
101
-
102
- /**
103
- * InvalidProviderError is thrown when a provider is added to the provider list that does not inherit from BaseProvider.
104
- *
105
- * @category Errors
106
- */
107
- class InvalidProviderError extends CDKError {}
108
-
109
- module.exports = {
110
- CDKError,
111
- MethodNotImplementedError,
112
- InvalidOrMissingParameterError,
113
- BackendError,
114
- BackendUnavailableError,
115
- NetworkError,
116
- InvalidRequestError,
117
- MissingApiUrlError,
118
- InvalidProviderError,
119
- }
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- const CDK = require("./lib/CocodaSDK")
2
-
3
- // Create and export a default instance
4
- const cdk = new CDK()
5
- module.exports = cdk