@data-fair/lib-common-types 1.10.6 → 1.12.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.
@@ -5,9 +5,9 @@ export const schemaExports: string[]
5
5
  /**
6
6
  * The list of capabilities that a catalog can have.
7
7
  * - import: The plugin can list some resources organized in folders and import them
8
- * - search: The plugin can use a search param in the listResources method
9
- * - pagination: The plugin can paginate the results of the listResources method
10
- * - additionalFilters: The plugin can use additional filters in the listResources method
8
+ * - search: The plugin can use the search param 'q' in the list method
9
+ * - pagination: The plugin can paginate the results of the list method
10
+ * - additionalFilters: The plugin can use additional filters in the list method
11
11
  * - importConfig: The plugin gives an import configuration schema
12
12
  * - publishDataset: The plugin can publish a dataset
13
13
  * - deletePublication: The plugin can delete a dataset or a resource published in a remote catalog
@@ -65,19 +65,68 @@ export type Resource = {
65
65
  * The unique identifier of the resource, independent of the folder it is in
66
66
  */
67
67
  id: string;
68
+ /**
69
+ * The title of the resource
70
+ */
68
71
  title: string;
69
- type: "resource";
70
72
  description?: string;
73
+ /**
74
+ * The path to the downloaded resource file.
75
+ */
76
+ filePath: string;
77
+ /**
78
+ * The format of the resource, e.g. csv, json, xml, etc. It is displayed in the UI of catalogs.
79
+ */
71
80
  format: string;
72
- url: string;
73
- fileName?: string;
74
- mimeType?: string;
75
- size?: number;
76
- keywords?: string[];
81
+ /**
82
+ * The frequency of the resource updates, if available. It can be one of the following values: triennial, biennial, annual, semiannual, threeTimesAYear, quarterly, bimonthly, monthly, semimonthly, biweekly, threeTimesAMonth, weekly, semiweekly, threeTimesAWeek, daily, continuous or irregular.
83
+ */
84
+ frequency?:
85
+ | ""
86
+ | "triennial"
87
+ | "biennial"
88
+ | "annual"
89
+ | "semiannual"
90
+ | "threeTimesAYear"
91
+ | "quarterly"
92
+ | "bimonthly"
93
+ | "monthly"
94
+ | "semimonthly"
95
+ | "biweekly"
96
+ | "threeTimesAMonth"
97
+ | "weekly"
98
+ | "semiweekly"
99
+ | "threeTimesAWeek"
100
+ | "daily"
101
+ | "continuous"
102
+ | "irregular";
103
+ /**
104
+ * The URL of the image representing the resource, if available
105
+ */
77
106
  image?: string;
78
107
  license?: string;
79
- frequency?: string;
80
- private?: boolean;
108
+ /**
109
+ * The list of keywords associated with the resource, if available
110
+ */
111
+ keywords?: string[];
112
+ /**
113
+ * The Mime type of the resource, if available
114
+ */
115
+ mimeType?: string;
116
+ /**
117
+ * The URL where the original data can be found
118
+ */
119
+ origin?: string;
120
+ /**
121
+ * The schema of the resource, if available
122
+ */
123
+ schema?: {
124
+ [k: string]: unknown;
125
+ };
126
+ /**
127
+ * The size of the resource in bytes, if available. It is displayed in the UI of catalogs.
128
+ */
129
+ size?: number;
81
130
  }
82
131
  /**
83
132
  * A small object that contains the information needed to publish or update a dataset or a resource
@@ -86,10 +135,6 @@ export type Resource = {
86
135
  * via the `definition` "publication".
87
136
  */
88
137
  export type Publication = {
89
- /**
90
- * The URL of the publication site where the user will be redirected from the remote catalog
91
- */
92
- publicationSite?: string;
93
138
  /**
94
139
  * Dataset from the remote catalog, used if a local dataset is published as a dataset on a remote catalog. If it is defined during publication, then the remote dataset must be updated.
95
140
  */
@@ -13,6 +13,29 @@ type BaseCatalogPlugin<TCatalogConfig, TCapabilities extends Capability[]> = {
13
13
  configSchema: TCatalogConfig;
14
14
  /** Function to validates the catalog configuration. */
15
15
  assertConfigValid(catalogConfig: any): asserts catalogConfig is TCatalogConfig;
16
+ /**
17
+ * Prepare function to extract secrets to cipher from the configuration,
18
+ * and dynamically update capabilities.
19
+ * This function is called when the catalog configuration is updated.
20
+ * It can be used to:
21
+ * - throw additional errors to validate the config
22
+ * - remove secrets from the config and store them in the secrets object :<br>
23
+ * This function must copy the configuration fields to be encrypted into the secret object,
24
+ * then replace these fields in the configuration with ****.
25
+ * If the received configuration already contains ****, the secret should not be copied.
26
+ * If the field is empty, it should delete the secret.
27
+ * - update the capabilities of the catalog based on the configuration
28
+ *
29
+ * @param context.catalogConfig The catalog configuration, that can contain secrets to extract
30
+ * @param context.capabilities The actuals capabilities of the catalog
31
+ * @param context.secrets The actuals deciphered secrets of the catalog
32
+ * @returns A promise that resolves to an object containing the catalog configuration, capabilities, and secrets.
33
+ */
34
+ prepare: (context: PrepareContext<TCatalogConfig, TCapabilities>) => Promise<{
35
+ catalogConfig?: TCatalogConfig;
36
+ capabilities?: TCapabilities;
37
+ secrets?: Record<string, string>;
38
+ }>;
16
39
  };
17
40
  /**
18
41
  * Type for catalog implementations that support listing and retrieving resources.
@@ -24,19 +47,22 @@ type BaseCatalogPlugin<TCatalogConfig, TCapabilities extends Capability[]> = {
24
47
  type WithImport<TCatalogConfig, TCapabilities extends Capability[]> = {
25
48
  /** List available folders and resources in the catalog. */
26
49
  list: (context: ListContext<TCatalogConfig, TCapabilities>) => Promise<{
50
+ /** The total number of items in the current folder */
27
51
  count: number;
28
- results: (Folder | Resource)[];
52
+ /** The list of folders and resources in the current folder, filtered with the search and pagination parameters */
53
+ results: (Folder | Pick<Resource, 'id' | 'title' | 'description' | 'format' | 'mimeType' | 'origin' | 'size'> & {
54
+ type: 'resource';
55
+ })[];
56
+ /** The path to the current folder, including the current folder itself, used to navigate back */
29
57
  path: Folder[];
30
58
  }>;
31
- /** Get informations about a specific resource. */
32
- getResource: (catalogConfig: TCatalogConfig, resourceId: string) => Promise<Resource | undefined>;
33
59
  /**
34
- * Download the resource to a temporary file from a context
35
- * @returns The path to the downloaded resource file, or undefined if the download failed
60
+ * Download the resource to a temporary file and return the metadata of the resource.
61
+ * @returns A promise that resolves to the metadata of the resource, including the path to the downloaded file.
36
62
  */
37
- downloadResource: (context: DownloadResourceContext<TCatalogConfig>) => Promise<string | undefined>;
63
+ getResource: (context: GetResourceContext<TCatalogConfig>) => Promise<Resource | undefined>;
38
64
  } & (Includes<TCapabilities, 'additionalFilters'> extends true ? {
39
- filtersSchema: Record<string, any>;
65
+ listFiltersSchema: Record<string, any>;
40
66
  } : {}) & (Includes<TCapabilities, 'importConfig'> extends true ? {
41
67
  importConfigSchema: Record<string, any>;
42
68
  } : {});
@@ -46,9 +72,10 @@ type WithPublishDataset<TCatalogConfig> = {
46
72
  * @param catalogConfig The configuration of the catalog
47
73
  * @param dataset The datafair dataset to publish
48
74
  * @param publication The publication to process
75
+ * @param publicationSite The site where the user will be redirected from the remote dataset
49
76
  * @returns A promise that is resolved when the dataset is published
50
77
  */
51
- publishDataset: (catalogConfig: TCatalogConfig, dataset: object, publication: Publication) => Promise<Publication>;
78
+ publishDataset: (context: PublishDatasetContext<TCatalogConfig>) => Promise<Publication>;
52
79
  };
53
80
  type WithDeletePublication<TCatalogConfig> = {
54
81
  /**
@@ -57,39 +84,130 @@ type WithDeletePublication<TCatalogConfig> = {
57
84
  * @param datasetId The id of the remoteDataset to delete, or the dataset where the resource to delete is
58
85
  * @param resourceId The id of the resource to delete
59
86
  */
60
- deleteDataset: (catalogConfig: TCatalogConfig, datasetId: string, resourceId?: string) => Promise<void>;
87
+ deleteDataset: (context: DeletePublicationContext<TCatalogConfig>) => Promise<void>;
88
+ };
89
+ /**
90
+ * Context for preparing a catalog configuration.
91
+ * @template TCatalogConfig - The type of the catalog configuration.
92
+ * @template TCapabilities - The capabilities of the catalog.
93
+ * @property catalogConfig - The catalog configuration, that can contain secrets to extract.
94
+ * @property capabilities - The actuals capabilities of the catalog.
95
+ * @property secrets - The actuals deciphered secrets of the catalog, if any.
96
+ */
97
+ export type PrepareContext<TCatalogConfig, TCapabilities extends Capability[]> = {
98
+ /** The catalog configuration, that can contain secrets to extract */
99
+ catalogConfig: TCatalogConfig;
100
+ /** The actuals capabilities of the catalog */
101
+ capabilities: TCapabilities;
102
+ /** The actuals deciphered secrets of the catalog */
103
+ secrets: Record<string, string>;
61
104
  };
62
105
  export type ListContext<TCatalogConfig, TCapabilities extends Capability[]> = {
63
106
  /** The catalog configuration */
64
107
  catalogConfig: TCatalogConfig;
108
+ /** The deciphered secrets of the catalog */
109
+ secrets: Record<string, string>;
65
110
  /** The specific import configuration, if applicable */
66
111
  params: ListParams<TCapabilities>;
67
112
  };
113
+ /**
114
+ * Parameters for listing resources in a catalog.
115
+ * @template TCapabilities - The capabilities of the catalog.
116
+ * @property currentFolderId - The ID of the current folder used to list subfolders and resources.
117
+ * @property q - The search field to filter resources when the 'search' capability is included.
118
+ * @property page - The page number for pagination when the 'pagination' capability is included.
119
+ * @property size - The number of items per page for pagination when the 'pagination' capability is included.
120
+ * @property others - Additional filters for the list method when the 'additionalFilters' capability is included.
121
+ */
68
122
  type ListParams<TCapabilities extends Capability[]> = {
69
123
  /** The current level folder is used to list subfolders and resources. */
70
124
  currentFolderId?: string;
71
- } & (Includes<TCapabilities, 'search'> extends true ? SearchParams : {}) & (Includes<TCapabilities, 'pagination'> extends true ? PaginationParams : {}) & (Includes<TCapabilities, 'additionalFilters'> extends true ? Record<string, string> : {});
125
+ } & (Includes<TCapabilities, 'search'> extends true ? SearchParams : {}) & (Includes<TCapabilities, 'pagination'> extends true ? PaginationParams : {}) & (Includes<TCapabilities, 'additionalFilters'> extends true ? Record<string, string | number> : {});
126
+ /** The params q is used to search resources */
72
127
  type SearchParams = {
73
128
  q?: string;
74
129
  };
130
+ /** The params page and size are used for pagination */
75
131
  type PaginationParams = {
76
132
  page?: number;
77
133
  size?: number;
78
134
  };
79
- export type DownloadResourceContext<TCatalogConfig> = {
135
+ /**
136
+ * Context for get and downloading a resource.
137
+ * @template TCatalogConfig - The type of the catalog configuration.
138
+ * @property catalogConfig - The catalog configuration.
139
+ * @property secrets - The deciphered secrets of the catalog.
140
+ * @property importConfig - The specific import configuration, if applicable.
141
+ * @property resourceId - The ID of the remote resource to download.
142
+ * @property tmpDir - The path to the working directory where the resource will be downloaded.
143
+ */
144
+ export type GetResourceContext<TCatalogConfig> = {
80
145
  /** The catalog configuration */
81
146
  catalogConfig: TCatalogConfig;
147
+ /** The deciphered secrets of the catalog */
148
+ secrets: Record<string, string>;
82
149
  /** The specific import configuration, if applicable */
83
150
  importConfig: Record<string, any>;
84
151
  /** The ID of the remote resource to download */
85
152
  resourceId: string;
86
- /** The path to the working directory */
153
+ /** The path to the working directory where the resource will be downloaded */
87
154
  tmpDir: string;
88
155
  };
156
+ /**
157
+ * Context for publishing a dataset.
158
+ * @template TCatalogConfig - The type of the catalog configuration.
159
+ * @property catalogConfig - The catalog configuration.
160
+ * @property secrets - The deciphered secrets of the catalog.
161
+ * @property dataset - The datafair dataset to publish.
162
+ * @property publication - The publication to process.
163
+ * @property publicationSite - The site where the user will be redirected from the remote dataset.
164
+ * @property publicationSite.title - The title of the publication site.
165
+ * @property publicationSite.url - The URL of the publication site.
166
+ * @property publicationSite.datasetUrlTemplate - The template for the URL to view the dataset in the publication site, using url-template syntax.
167
+ */
168
+ export type PublishDatasetContext<TCatalogConfig> = {
169
+ /** The catalog configuration */
170
+ catalogConfig: TCatalogConfig;
171
+ /** The deciphered secrets of the catalog */
172
+ secrets: Record<string, string>;
173
+ /** The datafair dataset to publish */
174
+ dataset: Record<string, any>;
175
+ /** The publication to process */
176
+ publication: Publication;
177
+ /** The site where the user will be redirected from the remote dataset. */
178
+ publicationSite: {
179
+ /** The title of the publication site */
180
+ title: string;
181
+ /** The URL of the publication site */
182
+ url: string;
183
+ /** The template for the URL to view the dataset in the publication site, using url-template syntax. */
184
+ datasetUrlTemplate: string;
185
+ };
186
+ };
187
+ /**
188
+ * Context for deleting a publication.
189
+ * @template TCatalogConfig - The type of the catalog configuration.
190
+ * @property catalogConfig - The catalog configuration.
191
+ * @property secrets - The deciphered secrets of the catalog.
192
+ * @property datasetId - The ID of the remote dataset to delete, or the dataset where the resource to delete is.
193
+ * @property resourceId - The ID of the resource to delete, if applicable.
194
+ */
195
+ export type DeletePublicationContext<TCatalogConfig> = {
196
+ /** The catalog configuration */
197
+ catalogConfig: TCatalogConfig;
198
+ /** The deciphered secrets of the catalog */
199
+ secrets: Record<string, string>;
200
+ /** The ID of the remote dataset to delete, or the dataset where the resource to delete is */
201
+ datasetId: string;
202
+ /** The ID of the resource to delete, if applicable */
203
+ resourceId?: string;
204
+ };
89
205
  /**
90
206
  * The metadata of the catalog plugin.
91
207
  * @template TCapabilities - This ensures that the `capabilities` field in the metadata is of the same type as `TCapabilities`.
208
+ * @property capabilities - The capabilities of the catalog plugin, which is an array of `Capability` types.
92
209
  */
93
210
  export type CatalogMetadata<TCapabilities extends Capability[]> = Metadata & {
211
+ /** The capabilities of the catalog plugin */
94
212
  capabilities: TCapabilities;
95
213
  };
@@ -61,45 +61,54 @@ declare const _default: {
61
61
  };
62
62
  title: {
63
63
  type: string;
64
- };
65
- type: {
66
- const: string;
64
+ description: string;
67
65
  };
68
66
  description: {
69
67
  type: string;
70
68
  };
71
- format: {
69
+ filePath: {
72
70
  type: string;
71
+ description: string;
73
72
  };
74
- url: {
73
+ format: {
75
74
  type: string;
75
+ description: string;
76
76
  };
77
- fileName: {
77
+ frequency: {
78
78
  type: string;
79
+ description: string;
80
+ enum: string[];
79
81
  };
80
- mimeType: {
82
+ image: {
81
83
  type: string;
84
+ description: string;
82
85
  };
83
- size: {
86
+ license: {
84
87
  type: string;
85
88
  };
86
89
  keywords: {
87
90
  type: string;
91
+ description: string;
88
92
  items: {
89
93
  type: string;
90
94
  };
91
95
  };
92
- image: {
96
+ mimeType: {
93
97
  type: string;
98
+ description: string;
94
99
  };
95
- license: {
100
+ origin: {
96
101
  type: string;
102
+ description: string;
97
103
  };
98
- frequency: {
104
+ schema: {
99
105
  type: string;
106
+ additionalProperties: boolean;
107
+ description: string;
100
108
  };
101
- private: {
109
+ size: {
102
110
  type: string;
111
+ description: string;
103
112
  };
104
113
  };
105
114
  };
@@ -108,10 +117,6 @@ declare const _default: {
108
117
  additionalProperties: boolean;
109
118
  description: string;
110
119
  properties: {
111
- publicationSite: {
112
- type: string;
113
- description: string;
114
- };
115
120
  remoteDataset: {
116
121
  type: string;
117
122
  required: string[];
package/catalog/schema.js CHANGED
@@ -9,9 +9,9 @@ export default {
9
9
  type: 'string',
10
10
  description: `The list of capabilities that a catalog can have.
11
11
  - import: The plugin can list some resources organized in folders and import them
12
- - search: The plugin can use a search param in the listResources method
13
- - pagination: The plugin can paginate the results of the listResources method
14
- - additionalFilters: The plugin can use additional filters in the listResources method
12
+ - search: The plugin can use the search param 'q' in the list method
13
+ - pagination: The plugin can paginate the results of the list method
14
+ - additionalFilters: The plugin can use additional filters in the list method
15
15
  - importConfig: The plugin gives an import configuration schema
16
16
  - publishDataset: The plugin can publish a dataset
17
17
  - deletePublication: The plugin can delete a dataset or a resource published in a remote catalog`,
@@ -67,7 +67,7 @@ export default {
67
67
  resource: {
68
68
  type: 'object',
69
69
  description: 'The normalized resource to import from a remote catalog to Data Fair',
70
- required: ['id', 'title', 'type', 'format', 'url'],
70
+ required: ['id', 'title', 'filePath', 'format'],
71
71
  additionalProperties: false,
72
72
  properties: {
73
73
  id: {
@@ -75,46 +75,56 @@ export default {
75
75
  description: 'The unique identifier of the resource, independent of the folder it is in'
76
76
  },
77
77
  title: {
78
- type: 'string'
79
- },
80
- type: {
81
- const: 'resource',
78
+ type: 'string',
79
+ description: 'The title of the resource'
82
80
  },
83
81
  description: {
84
82
  type: 'string',
85
83
  },
84
+ filePath: {
85
+ type: 'string',
86
+ description: 'The path to the downloaded resource file.',
87
+ },
86
88
  format: {
87
- type: 'string'
89
+ type: 'string',
90
+ description: 'The format of the resource, e.g. csv, json, xml, etc. It is displayed in the UI of catalogs.',
88
91
  },
89
- url: {
90
- type: 'string'
92
+ // https://www.w3.org/TR/vocab-dcat-2/#Property:dataset_frequency and https://www.dublincore.org/specifications/dublin-core/collection-description/frequency/
93
+ frequency: {
94
+ type: 'string',
95
+ description: 'The frequency of the resource updates, if available. It can be one of the following values: triennial, biennial, annual, semiannual, threeTimesAYear, quarterly, bimonthly, monthly, semimonthly, biweekly, threeTimesAMonth, weekly, semiweekly, threeTimesAWeek, daily, continuous or irregular.',
96
+ enum: ['', 'triennial', 'biennial', 'annual', 'semiannual', 'threeTimesAYear', 'quarterly', 'bimonthly', 'monthly', 'semimonthly', 'biweekly', 'threeTimesAMonth', 'weekly', 'semiweekly', 'threeTimesAWeek', 'daily', 'continuous', 'irregular']
91
97
  },
92
- fileName: {
93
- type: 'string'
98
+ image: {
99
+ type: 'string',
100
+ description: 'The URL of the image representing the resource, if available'
94
101
  },
95
- mimeType: {
102
+ license: {
96
103
  type: 'string'
97
104
  },
98
- size: {
99
- type: 'number'
100
- },
101
105
  keywords: {
102
106
  type: 'array',
107
+ description: 'The list of keywords associated with the resource, if available',
103
108
  items: {
104
109
  type: 'string'
105
110
  }
106
111
  },
107
- image: {
108
- type: 'string'
112
+ mimeType: {
113
+ type: 'string',
114
+ description: 'The Mime type of the resource, if available'
109
115
  },
110
- license: {
111
- type: 'string'
116
+ origin: {
117
+ type: 'string',
118
+ description: 'The URL where the original data can be found'
112
119
  },
113
- frequency: {
114
- type: 'string'
120
+ schema: {
121
+ type: 'object',
122
+ additionalProperties: true,
123
+ description: 'The schema of the resource, if available'
115
124
  },
116
- private: {
117
- type: 'boolean'
125
+ size: {
126
+ type: 'number',
127
+ description: 'The size of the resource in bytes, if available. It is displayed in the UI of catalogs.'
118
128
  }
119
129
  }
120
130
  },
@@ -123,10 +133,6 @@ export default {
123
133
  additionalProperties: false,
124
134
  description: 'A small object that contains the information needed to publish or update a dataset or a resource',
125
135
  properties: {
126
- publicationSite: {
127
- type: 'string',
128
- description: 'The URL of the publication site where the user will be redirected from the remote catalog'
129
- },
130
136
  remoteDataset: {
131
137
  type: 'object',
132
138
  required: ['id'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-common-types",
3
- "version": "1.10.6",
3
+ "version": "1.12.0",
4
4
  "description": "Shared schemas and built type definitions in the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "scripts": {