@mapcreator/api 5.0.0-alpha.73 → 5.0.0-alpha.75
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/LICENSE +29 -29
- package/README.md +86 -86
- package/cjs/api/choropleth.d.ts +79 -6
- package/cjs/api/choropleth.d.ts.map +1 -1
- package/cjs/api/choropleth.js +37 -18
- package/cjs/api/choropleth.js.map +1 -1
- package/esm/api/choropleth.d.ts +79 -6
- package/esm/api/choropleth.d.ts.map +1 -1
- package/esm/api/choropleth.js +34 -18
- package/esm/api/choropleth.js.map +1 -1
- package/package.json +80 -80
- package/src/README.md +126 -126
- package/src/api/choropleth.ts +154 -69
package/package.json
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mapcreator/api",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
4
|
-
"description": "Mapcreator JavaScript API",
|
|
5
|
-
"license": "BSD-3-Clause",
|
|
6
|
-
"main": "./cjs/index.js",
|
|
7
|
-
"types": "./cjs/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./esm/index.d.ts",
|
|
11
|
-
"import": "./esm/index.js",
|
|
12
|
-
"require": "./cjs/index.js"
|
|
13
|
-
},
|
|
14
|
-
"./oauth": {
|
|
15
|
-
"types": "./esm/oauth.d.ts",
|
|
16
|
-
"import": "./esm/oauth.js",
|
|
17
|
-
"require": "./cjs/oauth.js"
|
|
18
|
-
},
|
|
19
|
-
"./oauth.js": {
|
|
20
|
-
"types": "./esm/oauth.d.ts",
|
|
21
|
-
"import": "./esm/oauth.js",
|
|
22
|
-
"require": "./cjs/oauth.js"
|
|
23
|
-
},
|
|
24
|
-
"./utils": {
|
|
25
|
-
"types": "./esm/utils.d.ts",
|
|
26
|
-
"import": "./esm/utils.js",
|
|
27
|
-
"require": "./cjs/utils.js"
|
|
28
|
-
},
|
|
29
|
-
"./utils.js": {
|
|
30
|
-
"types": "./esm/utils.d.ts",
|
|
31
|
-
"import": "./esm/utils.js",
|
|
32
|
-
"require": "./cjs/utils.js"
|
|
33
|
-
},
|
|
34
|
-
"./package.json": "./package.json",
|
|
35
|
-
"./*": {
|
|
36
|
-
"types": "./esm/api/*.d.ts",
|
|
37
|
-
"import": "./esm/api/*.js",
|
|
38
|
-
"require": "./cjs/api/*.js"
|
|
39
|
-
},
|
|
40
|
-
"./*.js": {
|
|
41
|
-
"types": "./esm/api/*.d.ts",
|
|
42
|
-
"import": "./esm/api/*.js",
|
|
43
|
-
"require": "./cjs/api/*.js"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "tsc --outDir esm && tsc -m commonjs --outDir cjs",
|
|
48
|
-
"clean": "npx rimraf esm/ cjs/",
|
|
49
|
-
"lint": "eslint --ext .ts src",
|
|
50
|
-
"prepublishOnly": "npm run lint && npm run clean && npm run build",
|
|
51
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
52
|
-
},
|
|
53
|
-
"repository": {
|
|
54
|
-
"type": "git",
|
|
55
|
-
"url": "git+https://gitlab.com/mapcreator/api-wrapper.git"
|
|
56
|
-
},
|
|
57
|
-
"publishConfig": {
|
|
58
|
-
"registry": "https://registry.npmjs.org/"
|
|
59
|
-
},
|
|
60
|
-
"files": [
|
|
61
|
-
"cjs",
|
|
62
|
-
"esm",
|
|
63
|
-
"src"
|
|
64
|
-
],
|
|
65
|
-
"bugs": {
|
|
66
|
-
"url": "https://gitlab.com/mapcreator/api-wrapper/issues"
|
|
67
|
-
},
|
|
68
|
-
"homepage": "https://gitlab.com/mapcreator/api-wrapper#readme",
|
|
69
|
-
"dependencies": {
|
|
70
|
-
"@types/geojson": "^7946.0.14",
|
|
71
|
-
"type-fest": "^4.10"
|
|
72
|
-
},
|
|
73
|
-
"devDependencies": {
|
|
74
|
-
"@stylistic/eslint-plugin": "~1.5",
|
|
75
|
-
"@typescript-eslint/eslint-plugin": "~6.15",
|
|
76
|
-
"@typescript-eslint/parser": "~6.15",
|
|
77
|
-
"eslint": "~8.57",
|
|
78
|
-
"typescript": "~5.8.3"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@mapcreator/api",
|
|
3
|
+
"version": "5.0.0-alpha.75",
|
|
4
|
+
"description": "Mapcreator JavaScript API",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
6
|
+
"main": "./cjs/index.js",
|
|
7
|
+
"types": "./cjs/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./esm/index.d.ts",
|
|
11
|
+
"import": "./esm/index.js",
|
|
12
|
+
"require": "./cjs/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./oauth": {
|
|
15
|
+
"types": "./esm/oauth.d.ts",
|
|
16
|
+
"import": "./esm/oauth.js",
|
|
17
|
+
"require": "./cjs/oauth.js"
|
|
18
|
+
},
|
|
19
|
+
"./oauth.js": {
|
|
20
|
+
"types": "./esm/oauth.d.ts",
|
|
21
|
+
"import": "./esm/oauth.js",
|
|
22
|
+
"require": "./cjs/oauth.js"
|
|
23
|
+
},
|
|
24
|
+
"./utils": {
|
|
25
|
+
"types": "./esm/utils.d.ts",
|
|
26
|
+
"import": "./esm/utils.js",
|
|
27
|
+
"require": "./cjs/utils.js"
|
|
28
|
+
},
|
|
29
|
+
"./utils.js": {
|
|
30
|
+
"types": "./esm/utils.d.ts",
|
|
31
|
+
"import": "./esm/utils.js",
|
|
32
|
+
"require": "./cjs/utils.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
"./*": {
|
|
36
|
+
"types": "./esm/api/*.d.ts",
|
|
37
|
+
"import": "./esm/api/*.js",
|
|
38
|
+
"require": "./cjs/api/*.js"
|
|
39
|
+
},
|
|
40
|
+
"./*.js": {
|
|
41
|
+
"types": "./esm/api/*.d.ts",
|
|
42
|
+
"import": "./esm/api/*.js",
|
|
43
|
+
"require": "./cjs/api/*.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc --outDir esm && tsc -m commonjs --outDir cjs",
|
|
48
|
+
"clean": "npx rimraf esm/ cjs/",
|
|
49
|
+
"lint": "eslint --ext .ts src",
|
|
50
|
+
"prepublishOnly": "npm run lint && npm run clean && npm run build",
|
|
51
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://gitlab.com/mapcreator/api-wrapper.git"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"cjs",
|
|
62
|
+
"esm",
|
|
63
|
+
"src"
|
|
64
|
+
],
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://gitlab.com/mapcreator/api-wrapper/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://gitlab.com/mapcreator/api-wrapper#readme",
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@types/geojson": "^7946.0.14",
|
|
71
|
+
"type-fest": "^4.10"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@stylistic/eslint-plugin": "~1.5",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "~6.15",
|
|
76
|
+
"@typescript-eslint/parser": "~6.15",
|
|
77
|
+
"eslint": "~8.57",
|
|
78
|
+
"typescript": "~5.8.3"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/README.md
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
### Used type system
|
|
2
|
-
|
|
3
|
-
We use type declarations for both the data coming over the wire and the data used by the application. In general, these types differ only in the presence of additional fields in the data arriving over the network (like `created_at`), and used naming convention. Data over the network uses the so-called snake case.
|
|
4
|
-
|
|
5
|
-
All in all, we can use TypeScript's native mechanisms to convert one type to another and fully define just one type:
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import type { CamelCasedProperties } from 'type-fest';
|
|
9
|
-
|
|
10
|
-
type ApiType =
|
|
11
|
-
| ({
|
|
12
|
-
data: {
|
|
13
|
-
prop: unknown;
|
|
14
|
-
} & ApiCommonData;
|
|
15
|
-
} & Omit<ApiSuccess, 'data'>)
|
|
16
|
-
| ApiError;
|
|
17
|
-
|
|
18
|
-
type AppType = CamelCasedProperties<Omit<Exclude<ApiType, ApiError>['data'], keyof ApiCommonData>>;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
or in reverse order:
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import type { SnakeCasedProperties } from 'type-fest';
|
|
25
|
-
|
|
26
|
-
type AppType = {
|
|
27
|
-
prop: unknown;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type ApiType =
|
|
31
|
-
| ({
|
|
32
|
-
data: SnakeCasedProperties<AppType> & ApiCommonData;
|
|
33
|
-
} & Omit<ApiSuccess, 'data'>)
|
|
34
|
-
| ApiError;
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
But the decision was made not to do this, since it may be more difficult for the developer to make the conversion in their head than to see it in front of their eyes.
|
|
38
|
-
|
|
39
|
-
### Using a `request()`
|
|
40
|
-
|
|
41
|
-
The function has the following signature:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
async function request<I extends ApiCommon, O extends Record<string, unknown> | string>(
|
|
45
|
-
path: string,
|
|
46
|
-
body?: XMLHttpRequestBodyInit | Record<string | number, unknown> | null,
|
|
47
|
-
extraHeaders?: Record<string, string> | null,
|
|
48
|
-
extraOptions?: ExtraOptions<I, O>,
|
|
49
|
-
): Promise<O | O[]> { /* ... */ }
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Let's take it step by step.
|
|
53
|
-
|
|
54
|
-
`I extends ApiCommon` - represents the type of data we receive over the network.
|
|
55
|
-
|
|
56
|
-
`O extends Record<string, unknown> | string` - represents the data type that will be used in the application.
|
|
57
|
-
|
|
58
|
-
Ideally you should describe and convey both types. This will help to check the data types in the arguments passed.
|
|
59
|
-
See current data types for an example.
|
|
60
|
-
|
|
61
|
-
`path: string` - the path to the resource, must include the API version, but must not include the schema or authority.
|
|
62
|
-
Example: `/v1/jobs/12345`
|
|
63
|
-
|
|
64
|
-
`body?: XMLHttpRequestBodyInit | Record<string | number, unknown> | null` - any meaningful body type. In general,
|
|
65
|
-
the presence of an JSON object is assumed (or the absence of one for methods that only request data), but you can
|
|
66
|
-
also pass `Blob`, `FormData`, `URLSearchParams` or just `ArrayBuffer`. The required content type will be added to
|
|
67
|
-
the headers automatically.
|
|
68
|
-
|
|
69
|
-
`extraHeaders?: Record<string, string> | null` - the object with additional headers.
|
|
70
|
-
|
|
71
|
-
`extraOptions?: ExtraOptions<I, O>` - where `ExtraOptions<I, O>` is defined like this:
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
interface ExtraOptions<I extends ApiCommon, O extends Record<string, unknown> | string> {
|
|
75
|
-
method?: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
76
|
-
revivers?: O extends Record<string, unknown> ? Revivers<I, O> : never;
|
|
77
|
-
sendNull?: boolean;
|
|
78
|
-
withMeta?: boolean;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Most fields are self-explanatory.
|
|
83
|
-
|
|
84
|
-
`sendNull` can be used if you really want to pass `null` as body content.
|
|
85
|
-
|
|
86
|
-
`revivers` is used to specify an object that can modify the behavior of the internal handler of data coming over
|
|
87
|
-
the network. Let's take a closer look at this moment.
|
|
88
|
-
|
|
89
|
-
#### Revivers
|
|
90
|
-
|
|
91
|
-
By default, the `request()` function does the following things with data coming over the network:
|
|
92
|
-
|
|
93
|
-
- It removes `created_at`, `updated_at`, `deleted_at` fields from the output objects.
|
|
94
|
-
- It preserves all the remaining fields but converts their names into camelCase.
|
|
95
|
-
|
|
96
|
-
When passing an object with revivers you can a couple of things:
|
|
97
|
-
|
|
98
|
-
- You can list the fields that you want **to exclude** from the result object. To do this, the field must be assigned an
|
|
99
|
-
`undefined` value.
|
|
100
|
-
- You can **add** new fields or **modify** the type of existing ones. To do this, you need to pass a function as a field
|
|
101
|
-
value, which will receive the original object as input.
|
|
102
|
-
|
|
103
|
-
Example:
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
const jobRevivers: Revivers<ApiJob, Job> = {
|
|
107
|
-
user_id: undefined,
|
|
108
|
-
description: undefined,
|
|
109
|
-
share_token: undefined,
|
|
110
|
-
autosave_preview_path: undefined,
|
|
111
|
-
job_folder_id: undefined,
|
|
112
|
-
|
|
113
|
-
jobTypeId: () => 9,
|
|
114
|
-
createdAt: (data: ApiJobData) => data.created_at as string,
|
|
115
|
-
previewPath: (data: ApiJobData) => data.autosave_preview_path ?? undefined,
|
|
116
|
-
};
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
`user_id`, `description`, `share_token`, `autosave_preview_path`, `job_folder_id` fields will be excluded from the
|
|
120
|
-
result object.
|
|
121
|
-
|
|
122
|
-
`jobTypeId` will be always **9**.
|
|
123
|
-
|
|
124
|
-
`createdAt` will be returned (please note that that field is excluded by default)
|
|
125
|
-
|
|
126
|
-
`previewPath` - some actions will be performed with the source data.
|
|
1
|
+
### Used type system
|
|
2
|
+
|
|
3
|
+
We use type declarations for both the data coming over the wire and the data used by the application. In general, these types differ only in the presence of additional fields in the data arriving over the network (like `created_at`), and used naming convention. Data over the network uses the so-called snake case.
|
|
4
|
+
|
|
5
|
+
All in all, we can use TypeScript's native mechanisms to convert one type to another and fully define just one type:
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import type { CamelCasedProperties } from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type ApiType =
|
|
11
|
+
| ({
|
|
12
|
+
data: {
|
|
13
|
+
prop: unknown;
|
|
14
|
+
} & ApiCommonData;
|
|
15
|
+
} & Omit<ApiSuccess, 'data'>)
|
|
16
|
+
| ApiError;
|
|
17
|
+
|
|
18
|
+
type AppType = CamelCasedProperties<Omit<Exclude<ApiType, ApiError>['data'], keyof ApiCommonData>>;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
or in reverse order:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import type { SnakeCasedProperties } from 'type-fest';
|
|
25
|
+
|
|
26
|
+
type AppType = {
|
|
27
|
+
prop: unknown;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type ApiType =
|
|
31
|
+
| ({
|
|
32
|
+
data: SnakeCasedProperties<AppType> & ApiCommonData;
|
|
33
|
+
} & Omit<ApiSuccess, 'data'>)
|
|
34
|
+
| ApiError;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
But the decision was made not to do this, since it may be more difficult for the developer to make the conversion in their head than to see it in front of their eyes.
|
|
38
|
+
|
|
39
|
+
### Using a `request()`
|
|
40
|
+
|
|
41
|
+
The function has the following signature:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
async function request<I extends ApiCommon, O extends Record<string, unknown> | string>(
|
|
45
|
+
path: string,
|
|
46
|
+
body?: XMLHttpRequestBodyInit | Record<string | number, unknown> | null,
|
|
47
|
+
extraHeaders?: Record<string, string> | null,
|
|
48
|
+
extraOptions?: ExtraOptions<I, O>,
|
|
49
|
+
): Promise<O | O[]> { /* ... */ }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Let's take it step by step.
|
|
53
|
+
|
|
54
|
+
`I extends ApiCommon` - represents the type of data we receive over the network.
|
|
55
|
+
|
|
56
|
+
`O extends Record<string, unknown> | string` - represents the data type that will be used in the application.
|
|
57
|
+
|
|
58
|
+
Ideally you should describe and convey both types. This will help to check the data types in the arguments passed.
|
|
59
|
+
See current data types for an example.
|
|
60
|
+
|
|
61
|
+
`path: string` - the path to the resource, must include the API version, but must not include the schema or authority.
|
|
62
|
+
Example: `/v1/jobs/12345`
|
|
63
|
+
|
|
64
|
+
`body?: XMLHttpRequestBodyInit | Record<string | number, unknown> | null` - any meaningful body type. In general,
|
|
65
|
+
the presence of an JSON object is assumed (or the absence of one for methods that only request data), but you can
|
|
66
|
+
also pass `Blob`, `FormData`, `URLSearchParams` or just `ArrayBuffer`. The required content type will be added to
|
|
67
|
+
the headers automatically.
|
|
68
|
+
|
|
69
|
+
`extraHeaders?: Record<string, string> | null` - the object with additional headers.
|
|
70
|
+
|
|
71
|
+
`extraOptions?: ExtraOptions<I, O>` - where `ExtraOptions<I, O>` is defined like this:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
interface ExtraOptions<I extends ApiCommon, O extends Record<string, unknown> | string> {
|
|
75
|
+
method?: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
76
|
+
revivers?: O extends Record<string, unknown> ? Revivers<I, O> : never;
|
|
77
|
+
sendNull?: boolean;
|
|
78
|
+
withMeta?: boolean;
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Most fields are self-explanatory.
|
|
83
|
+
|
|
84
|
+
`sendNull` can be used if you really want to pass `null` as body content.
|
|
85
|
+
|
|
86
|
+
`revivers` is used to specify an object that can modify the behavior of the internal handler of data coming over
|
|
87
|
+
the network. Let's take a closer look at this moment.
|
|
88
|
+
|
|
89
|
+
#### Revivers
|
|
90
|
+
|
|
91
|
+
By default, the `request()` function does the following things with data coming over the network:
|
|
92
|
+
|
|
93
|
+
- It removes `created_at`, `updated_at`, `deleted_at` fields from the output objects.
|
|
94
|
+
- It preserves all the remaining fields but converts their names into camelCase.
|
|
95
|
+
|
|
96
|
+
When passing an object with revivers you can a couple of things:
|
|
97
|
+
|
|
98
|
+
- You can list the fields that you want **to exclude** from the result object. To do this, the field must be assigned an
|
|
99
|
+
`undefined` value.
|
|
100
|
+
- You can **add** new fields or **modify** the type of existing ones. To do this, you need to pass a function as a field
|
|
101
|
+
value, which will receive the original object as input.
|
|
102
|
+
|
|
103
|
+
Example:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const jobRevivers: Revivers<ApiJob, Job> = {
|
|
107
|
+
user_id: undefined,
|
|
108
|
+
description: undefined,
|
|
109
|
+
share_token: undefined,
|
|
110
|
+
autosave_preview_path: undefined,
|
|
111
|
+
job_folder_id: undefined,
|
|
112
|
+
|
|
113
|
+
jobTypeId: () => 9,
|
|
114
|
+
createdAt: (data: ApiJobData) => data.created_at as string,
|
|
115
|
+
previewPath: (data: ApiJobData) => data.autosave_preview_path ?? undefined,
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`user_id`, `description`, `share_token`, `autosave_preview_path`, `job_folder_id` fields will be excluded from the
|
|
120
|
+
result object.
|
|
121
|
+
|
|
122
|
+
`jobTypeId` will be always **9**.
|
|
123
|
+
|
|
124
|
+
`createdAt` will be returned (please note that that field is excluded by default)
|
|
125
|
+
|
|
126
|
+
`previewPath` - some actions will be performed with the source data.
|