@data-fair/lib-common-types 1.19.10 → 1.20.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/access-ref/.type/index.d.ts +45 -0
- package/access-ref/.type/index.js +19 -0
- package/access-ref/.type/validate.js +538 -0
- package/access-ref/index.d.ts +14 -0
- package/access-ref/index.js +63 -0
- package/access-ref/schema.d.ts +148 -0
- package/access-ref/schema.js +97 -0
- package/package.json +1 -1
- package/processings.d.ts +25 -16
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
export const schemaExports: string[]
|
|
3
|
+
|
|
4
|
+
// see https://github.com/bcherny/json-schema-to-typescript/issues/439 if some types are not exported
|
|
5
|
+
export type AccessRef =
|
|
6
|
+
| UnMembreDeLOrganisation
|
|
7
|
+
| UnEmail
|
|
8
|
+
| UneOrganisationPartenaire
|
|
9
|
+
| UnRoleOuDepartementDeMonOrganisation;
|
|
10
|
+
export type AdresseMail = string;
|
|
11
|
+
|
|
12
|
+
export type UnMembreDeLOrganisation = {
|
|
13
|
+
mode: "member";
|
|
14
|
+
type: "user";
|
|
15
|
+
id: string;
|
|
16
|
+
[k: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export type UnEmail = {
|
|
19
|
+
mode: "member";
|
|
20
|
+
type: "user";
|
|
21
|
+
email: AdresseMail;
|
|
22
|
+
[k: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
export type UneOrganisationPartenaire = {
|
|
25
|
+
mode: "member";
|
|
26
|
+
type: "organization";
|
|
27
|
+
department?: "*";
|
|
28
|
+
roles?: unknown[];
|
|
29
|
+
id: string;
|
|
30
|
+
[k: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
export type UnRoleOuDepartementDeMonOrganisation = {
|
|
33
|
+
mode: "internal";
|
|
34
|
+
type: "organization";
|
|
35
|
+
id: string;
|
|
36
|
+
department?: string;
|
|
37
|
+
roles?: string[];
|
|
38
|
+
[k: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export declare function validate(data: any): data is AccessRef
|
|
43
|
+
export declare function assertValid(data: any, options?: import('@data-fair/lib-validation').AssertValidOptions): asserts data is AccessRef
|
|
44
|
+
export declare function returnValid(data: any, options?: import('@data-fair/lib-validation').AssertValidOptions): AccessRef
|
|
45
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import validate from './validate.js'
|
|
5
|
+
import { assertValid as assertValidGeneric } from '@data-fair/lib-validation'
|
|
6
|
+
|
|
7
|
+
export const schemaExports = [
|
|
8
|
+
"types",
|
|
9
|
+
"validate"
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
export { validate } from './validate.js'
|
|
13
|
+
export function assertValid(data, options) {
|
|
14
|
+
assertValidGeneric(validate, data, options)
|
|
15
|
+
}
|
|
16
|
+
export function returnValid(data, options) {
|
|
17
|
+
assertValid(data, options)
|
|
18
|
+
return data
|
|
19
|
+
}
|
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
export const validate = validate14;
|
|
6
|
+
export default validate14;
|
|
7
|
+
const schema16 = {"$id":"https://github.com/data-fair/lib/access-ref","x-exports":["types","validate"],"title":"Access Ref","type":"object","oneOf":[{"title":"Un membre de l'organisation","layout":{"if":"context.owner.type === 'organization'"},"required":["mode","type","id"],"properties":{"mode":{"type":"string","const":"member"},"type":{"type":"string","const":"user"},"id":{"type":"string","layout":{"getItems":{"url":"/simple-directory/api/organization/${context.owner.id}/members","itemsResults":"data.results","itemTitle":"item.name","itemValue":"item.id","itemIcon":"`/simple-directory/api/avatars/user/${item.id}/avatar.png`"}}}}},{"title":"Un email","required":["mode","type","email"],"properties":{"mode":{"type":"string","const":"member"},"type":{"type":"string","const":"user"},"email":{"type":"string","title":"Adresse mail"}}},{"title":"Une organisation partenaire","layout":{"if":"context.owner.type === 'organization'"},"required":["mode","type","id"],"properties":{"mode":{"type":"string","const":"member"},"type":{"type":"string","const":"organization"},"department":{"type":"string","const":"*"},"roles":{"type":"array","const":[]},"id":{"type":"string","layout":{"getItems":{"url":"/simple-directory/api/organization/${context.owner.id}/partners","itemsResults":"data.results","itemTitle":"item.name","itemValue":"item.id","itemIcon":"`/simple-directory/api/avatars/organization/${item.id}/avatar.png`"}}}}},{"title":"Un role ou département de mon organisation","layout":{"if":"context.owner.type === 'organization'"},"required":["mode","type","id"],"properties":{"mode":{"type":"string","const":"internal"},"type":{"type":"string","const":"organization"},"id":{"type":"string"},"department":{"type":"string","layout":{"getItems":{"url":"/simple-directory/api/organization/${context.owner.id}/departments","itemsResults":"[...data.results, {id: \"*\", name: \"Tous les départements\"}, {id: \"-\", name: \"Racine de l'organisation uniquement\"}]","itemTitle":"item.name","itemValue":"item.id"}}},"roles":{"type":"array","items":{"type":"string"},"layout":{"getItems":{"url":"/simple-directory/api/organization/${context.owner.id}/roles","itemsResults":"data.results","itemTitle":"item.name","itemValue":"item.id"}}}}}]};
|
|
8
|
+
const func0 = require("ajv/dist/runtime/equal").default;
|
|
9
|
+
|
|
10
|
+
function validate14(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){
|
|
11
|
+
/*# sourceURL="https://github.com/data-fair/lib/access-ref" */;
|
|
12
|
+
let vErrors = null;
|
|
13
|
+
let errors = 0;
|
|
14
|
+
if(!(data && typeof data == "object" && !Array.isArray(data))){
|
|
15
|
+
const err0 = {instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"};
|
|
16
|
+
if(vErrors === null){
|
|
17
|
+
vErrors = [err0];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
vErrors.push(err0);
|
|
21
|
+
}
|
|
22
|
+
errors++;
|
|
23
|
+
}
|
|
24
|
+
const _errs1 = errors;
|
|
25
|
+
let valid0 = false;
|
|
26
|
+
let passing0 = null;
|
|
27
|
+
const _errs2 = errors;
|
|
28
|
+
if(data && typeof data == "object" && !Array.isArray(data)){
|
|
29
|
+
if(data.mode === undefined){
|
|
30
|
+
const err1 = {instancePath,schemaPath:"#/oneOf/0/required",keyword:"required",params:{missingProperty: "mode"},message:"must have required property '"+"mode"+"'"};
|
|
31
|
+
if(vErrors === null){
|
|
32
|
+
vErrors = [err1];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
vErrors.push(err1);
|
|
36
|
+
}
|
|
37
|
+
errors++;
|
|
38
|
+
}
|
|
39
|
+
if(data.type === undefined){
|
|
40
|
+
const err2 = {instancePath,schemaPath:"#/oneOf/0/required",keyword:"required",params:{missingProperty: "type"},message:"must have required property '"+"type"+"'"};
|
|
41
|
+
if(vErrors === null){
|
|
42
|
+
vErrors = [err2];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
vErrors.push(err2);
|
|
46
|
+
}
|
|
47
|
+
errors++;
|
|
48
|
+
}
|
|
49
|
+
if(data.id === undefined){
|
|
50
|
+
const err3 = {instancePath,schemaPath:"#/oneOf/0/required",keyword:"required",params:{missingProperty: "id"},message:"must have required property '"+"id"+"'"};
|
|
51
|
+
if(vErrors === null){
|
|
52
|
+
vErrors = [err3];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
vErrors.push(err3);
|
|
56
|
+
}
|
|
57
|
+
errors++;
|
|
58
|
+
}
|
|
59
|
+
if(data.mode !== undefined){
|
|
60
|
+
let data0 = data.mode;
|
|
61
|
+
if(typeof data0 !== "string"){
|
|
62
|
+
const err4 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/0/properties/mode/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
63
|
+
if(vErrors === null){
|
|
64
|
+
vErrors = [err4];
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
vErrors.push(err4);
|
|
68
|
+
}
|
|
69
|
+
errors++;
|
|
70
|
+
}
|
|
71
|
+
if("member" !== data0){
|
|
72
|
+
const err5 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/0/properties/mode/const",keyword:"const",params:{allowedValue: "member"},message:"must be equal to constant"};
|
|
73
|
+
if(vErrors === null){
|
|
74
|
+
vErrors = [err5];
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
vErrors.push(err5);
|
|
78
|
+
}
|
|
79
|
+
errors++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if(data.type !== undefined){
|
|
83
|
+
let data1 = data.type;
|
|
84
|
+
if(typeof data1 !== "string"){
|
|
85
|
+
const err6 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/0/properties/type/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
86
|
+
if(vErrors === null){
|
|
87
|
+
vErrors = [err6];
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
vErrors.push(err6);
|
|
91
|
+
}
|
|
92
|
+
errors++;
|
|
93
|
+
}
|
|
94
|
+
if("user" !== data1){
|
|
95
|
+
const err7 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/0/properties/type/const",keyword:"const",params:{allowedValue: "user"},message:"must be equal to constant"};
|
|
96
|
+
if(vErrors === null){
|
|
97
|
+
vErrors = [err7];
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
vErrors.push(err7);
|
|
101
|
+
}
|
|
102
|
+
errors++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if(data.id !== undefined){
|
|
106
|
+
if(typeof data.id !== "string"){
|
|
107
|
+
const err8 = {instancePath:instancePath+"/id",schemaPath:"#/oneOf/0/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
108
|
+
if(vErrors === null){
|
|
109
|
+
vErrors = [err8];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
vErrors.push(err8);
|
|
113
|
+
}
|
|
114
|
+
errors++;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var _valid0 = _errs2 === errors;
|
|
119
|
+
if(_valid0){
|
|
120
|
+
valid0 = true;
|
|
121
|
+
passing0 = 0;
|
|
122
|
+
}
|
|
123
|
+
const _errs9 = errors;
|
|
124
|
+
if(data && typeof data == "object" && !Array.isArray(data)){
|
|
125
|
+
if(data.mode === undefined){
|
|
126
|
+
const err9 = {instancePath,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty: "mode"},message:"must have required property '"+"mode"+"'"};
|
|
127
|
+
if(vErrors === null){
|
|
128
|
+
vErrors = [err9];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
vErrors.push(err9);
|
|
132
|
+
}
|
|
133
|
+
errors++;
|
|
134
|
+
}
|
|
135
|
+
if(data.type === undefined){
|
|
136
|
+
const err10 = {instancePath,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty: "type"},message:"must have required property '"+"type"+"'"};
|
|
137
|
+
if(vErrors === null){
|
|
138
|
+
vErrors = [err10];
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
vErrors.push(err10);
|
|
142
|
+
}
|
|
143
|
+
errors++;
|
|
144
|
+
}
|
|
145
|
+
if(data.email === undefined){
|
|
146
|
+
const err11 = {instancePath,schemaPath:"#/oneOf/1/required",keyword:"required",params:{missingProperty: "email"},message:"must have required property '"+"email"+"'"};
|
|
147
|
+
if(vErrors === null){
|
|
148
|
+
vErrors = [err11];
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
vErrors.push(err11);
|
|
152
|
+
}
|
|
153
|
+
errors++;
|
|
154
|
+
}
|
|
155
|
+
if(data.mode !== undefined){
|
|
156
|
+
let data3 = data.mode;
|
|
157
|
+
if(typeof data3 !== "string"){
|
|
158
|
+
const err12 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/1/properties/mode/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
159
|
+
if(vErrors === null){
|
|
160
|
+
vErrors = [err12];
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
vErrors.push(err12);
|
|
164
|
+
}
|
|
165
|
+
errors++;
|
|
166
|
+
}
|
|
167
|
+
if("member" !== data3){
|
|
168
|
+
const err13 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/1/properties/mode/const",keyword:"const",params:{allowedValue: "member"},message:"must be equal to constant"};
|
|
169
|
+
if(vErrors === null){
|
|
170
|
+
vErrors = [err13];
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
vErrors.push(err13);
|
|
174
|
+
}
|
|
175
|
+
errors++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if(data.type !== undefined){
|
|
179
|
+
let data4 = data.type;
|
|
180
|
+
if(typeof data4 !== "string"){
|
|
181
|
+
const err14 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/1/properties/type/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
182
|
+
if(vErrors === null){
|
|
183
|
+
vErrors = [err14];
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
vErrors.push(err14);
|
|
187
|
+
}
|
|
188
|
+
errors++;
|
|
189
|
+
}
|
|
190
|
+
if("user" !== data4){
|
|
191
|
+
const err15 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/1/properties/type/const",keyword:"const",params:{allowedValue: "user"},message:"must be equal to constant"};
|
|
192
|
+
if(vErrors === null){
|
|
193
|
+
vErrors = [err15];
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
vErrors.push(err15);
|
|
197
|
+
}
|
|
198
|
+
errors++;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if(data.email !== undefined){
|
|
202
|
+
if(typeof data.email !== "string"){
|
|
203
|
+
const err16 = {instancePath:instancePath+"/email",schemaPath:"#/oneOf/1/properties/email/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
204
|
+
if(vErrors === null){
|
|
205
|
+
vErrors = [err16];
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
vErrors.push(err16);
|
|
209
|
+
}
|
|
210
|
+
errors++;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
var _valid0 = _errs9 === errors;
|
|
215
|
+
if(_valid0 && valid0){
|
|
216
|
+
valid0 = false;
|
|
217
|
+
passing0 = [passing0, 1];
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
if(_valid0){
|
|
221
|
+
valid0 = true;
|
|
222
|
+
passing0 = 1;
|
|
223
|
+
}
|
|
224
|
+
const _errs16 = errors;
|
|
225
|
+
if(data && typeof data == "object" && !Array.isArray(data)){
|
|
226
|
+
if(data.mode === undefined){
|
|
227
|
+
const err17 = {instancePath,schemaPath:"#/oneOf/2/required",keyword:"required",params:{missingProperty: "mode"},message:"must have required property '"+"mode"+"'"};
|
|
228
|
+
if(vErrors === null){
|
|
229
|
+
vErrors = [err17];
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
vErrors.push(err17);
|
|
233
|
+
}
|
|
234
|
+
errors++;
|
|
235
|
+
}
|
|
236
|
+
if(data.type === undefined){
|
|
237
|
+
const err18 = {instancePath,schemaPath:"#/oneOf/2/required",keyword:"required",params:{missingProperty: "type"},message:"must have required property '"+"type"+"'"};
|
|
238
|
+
if(vErrors === null){
|
|
239
|
+
vErrors = [err18];
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
vErrors.push(err18);
|
|
243
|
+
}
|
|
244
|
+
errors++;
|
|
245
|
+
}
|
|
246
|
+
if(data.id === undefined){
|
|
247
|
+
const err19 = {instancePath,schemaPath:"#/oneOf/2/required",keyword:"required",params:{missingProperty: "id"},message:"must have required property '"+"id"+"'"};
|
|
248
|
+
if(vErrors === null){
|
|
249
|
+
vErrors = [err19];
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
vErrors.push(err19);
|
|
253
|
+
}
|
|
254
|
+
errors++;
|
|
255
|
+
}
|
|
256
|
+
if(data.mode !== undefined){
|
|
257
|
+
let data6 = data.mode;
|
|
258
|
+
if(typeof data6 !== "string"){
|
|
259
|
+
const err20 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/2/properties/mode/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
260
|
+
if(vErrors === null){
|
|
261
|
+
vErrors = [err20];
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
vErrors.push(err20);
|
|
265
|
+
}
|
|
266
|
+
errors++;
|
|
267
|
+
}
|
|
268
|
+
if("member" !== data6){
|
|
269
|
+
const err21 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/2/properties/mode/const",keyword:"const",params:{allowedValue: "member"},message:"must be equal to constant"};
|
|
270
|
+
if(vErrors === null){
|
|
271
|
+
vErrors = [err21];
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
vErrors.push(err21);
|
|
275
|
+
}
|
|
276
|
+
errors++;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if(data.type !== undefined){
|
|
280
|
+
let data7 = data.type;
|
|
281
|
+
if(typeof data7 !== "string"){
|
|
282
|
+
const err22 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/2/properties/type/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
283
|
+
if(vErrors === null){
|
|
284
|
+
vErrors = [err22];
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
vErrors.push(err22);
|
|
288
|
+
}
|
|
289
|
+
errors++;
|
|
290
|
+
}
|
|
291
|
+
if("organization" !== data7){
|
|
292
|
+
const err23 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/2/properties/type/const",keyword:"const",params:{allowedValue: "organization"},message:"must be equal to constant"};
|
|
293
|
+
if(vErrors === null){
|
|
294
|
+
vErrors = [err23];
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
vErrors.push(err23);
|
|
298
|
+
}
|
|
299
|
+
errors++;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if(data.department !== undefined){
|
|
303
|
+
let data8 = data.department;
|
|
304
|
+
if(typeof data8 !== "string"){
|
|
305
|
+
const err24 = {instancePath:instancePath+"/department",schemaPath:"#/oneOf/2/properties/department/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
306
|
+
if(vErrors === null){
|
|
307
|
+
vErrors = [err24];
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
vErrors.push(err24);
|
|
311
|
+
}
|
|
312
|
+
errors++;
|
|
313
|
+
}
|
|
314
|
+
if("*" !== data8){
|
|
315
|
+
const err25 = {instancePath:instancePath+"/department",schemaPath:"#/oneOf/2/properties/department/const",keyword:"const",params:{allowedValue: "*"},message:"must be equal to constant"};
|
|
316
|
+
if(vErrors === null){
|
|
317
|
+
vErrors = [err25];
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
vErrors.push(err25);
|
|
321
|
+
}
|
|
322
|
+
errors++;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if(data.roles !== undefined){
|
|
326
|
+
let data9 = data.roles;
|
|
327
|
+
if(!(Array.isArray(data9))){
|
|
328
|
+
const err26 = {instancePath:instancePath+"/roles",schemaPath:"#/oneOf/2/properties/roles/type",keyword:"type",params:{type: "array"},message:"must be array"};
|
|
329
|
+
if(vErrors === null){
|
|
330
|
+
vErrors = [err26];
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
vErrors.push(err26);
|
|
334
|
+
}
|
|
335
|
+
errors++;
|
|
336
|
+
}
|
|
337
|
+
if(!func0(data9, schema16.oneOf[2].properties.roles.const)){
|
|
338
|
+
const err27 = {instancePath:instancePath+"/roles",schemaPath:"#/oneOf/2/properties/roles/const",keyword:"const",params:{allowedValue: schema16.oneOf[2].properties.roles.const},message:"must be equal to constant"};
|
|
339
|
+
if(vErrors === null){
|
|
340
|
+
vErrors = [err27];
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
vErrors.push(err27);
|
|
344
|
+
}
|
|
345
|
+
errors++;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if(data.id !== undefined){
|
|
349
|
+
if(typeof data.id !== "string"){
|
|
350
|
+
const err28 = {instancePath:instancePath+"/id",schemaPath:"#/oneOf/2/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
351
|
+
if(vErrors === null){
|
|
352
|
+
vErrors = [err28];
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
vErrors.push(err28);
|
|
356
|
+
}
|
|
357
|
+
errors++;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
var _valid0 = _errs16 === errors;
|
|
362
|
+
if(_valid0 && valid0){
|
|
363
|
+
valid0 = false;
|
|
364
|
+
passing0 = [passing0, 2];
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
if(_valid0){
|
|
368
|
+
valid0 = true;
|
|
369
|
+
passing0 = 2;
|
|
370
|
+
}
|
|
371
|
+
const _errs27 = errors;
|
|
372
|
+
if(data && typeof data == "object" && !Array.isArray(data)){
|
|
373
|
+
if(data.mode === undefined){
|
|
374
|
+
const err29 = {instancePath,schemaPath:"#/oneOf/3/required",keyword:"required",params:{missingProperty: "mode"},message:"must have required property '"+"mode"+"'"};
|
|
375
|
+
if(vErrors === null){
|
|
376
|
+
vErrors = [err29];
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
vErrors.push(err29);
|
|
380
|
+
}
|
|
381
|
+
errors++;
|
|
382
|
+
}
|
|
383
|
+
if(data.type === undefined){
|
|
384
|
+
const err30 = {instancePath,schemaPath:"#/oneOf/3/required",keyword:"required",params:{missingProperty: "type"},message:"must have required property '"+"type"+"'"};
|
|
385
|
+
if(vErrors === null){
|
|
386
|
+
vErrors = [err30];
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
vErrors.push(err30);
|
|
390
|
+
}
|
|
391
|
+
errors++;
|
|
392
|
+
}
|
|
393
|
+
if(data.id === undefined){
|
|
394
|
+
const err31 = {instancePath,schemaPath:"#/oneOf/3/required",keyword:"required",params:{missingProperty: "id"},message:"must have required property '"+"id"+"'"};
|
|
395
|
+
if(vErrors === null){
|
|
396
|
+
vErrors = [err31];
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
vErrors.push(err31);
|
|
400
|
+
}
|
|
401
|
+
errors++;
|
|
402
|
+
}
|
|
403
|
+
if(data.mode !== undefined){
|
|
404
|
+
let data11 = data.mode;
|
|
405
|
+
if(typeof data11 !== "string"){
|
|
406
|
+
const err32 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/3/properties/mode/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
407
|
+
if(vErrors === null){
|
|
408
|
+
vErrors = [err32];
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
vErrors.push(err32);
|
|
412
|
+
}
|
|
413
|
+
errors++;
|
|
414
|
+
}
|
|
415
|
+
if("internal" !== data11){
|
|
416
|
+
const err33 = {instancePath:instancePath+"/mode",schemaPath:"#/oneOf/3/properties/mode/const",keyword:"const",params:{allowedValue: "internal"},message:"must be equal to constant"};
|
|
417
|
+
if(vErrors === null){
|
|
418
|
+
vErrors = [err33];
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
vErrors.push(err33);
|
|
422
|
+
}
|
|
423
|
+
errors++;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if(data.type !== undefined){
|
|
427
|
+
let data12 = data.type;
|
|
428
|
+
if(typeof data12 !== "string"){
|
|
429
|
+
const err34 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/3/properties/type/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
430
|
+
if(vErrors === null){
|
|
431
|
+
vErrors = [err34];
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
vErrors.push(err34);
|
|
435
|
+
}
|
|
436
|
+
errors++;
|
|
437
|
+
}
|
|
438
|
+
if("organization" !== data12){
|
|
439
|
+
const err35 = {instancePath:instancePath+"/type",schemaPath:"#/oneOf/3/properties/type/const",keyword:"const",params:{allowedValue: "organization"},message:"must be equal to constant"};
|
|
440
|
+
if(vErrors === null){
|
|
441
|
+
vErrors = [err35];
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
vErrors.push(err35);
|
|
445
|
+
}
|
|
446
|
+
errors++;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if(data.id !== undefined){
|
|
450
|
+
if(typeof data.id !== "string"){
|
|
451
|
+
const err36 = {instancePath:instancePath+"/id",schemaPath:"#/oneOf/3/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
452
|
+
if(vErrors === null){
|
|
453
|
+
vErrors = [err36];
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
vErrors.push(err36);
|
|
457
|
+
}
|
|
458
|
+
errors++;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if(data.department !== undefined){
|
|
462
|
+
if(typeof data.department !== "string"){
|
|
463
|
+
const err37 = {instancePath:instancePath+"/department",schemaPath:"#/oneOf/3/properties/department/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
464
|
+
if(vErrors === null){
|
|
465
|
+
vErrors = [err37];
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
vErrors.push(err37);
|
|
469
|
+
}
|
|
470
|
+
errors++;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if(data.roles !== undefined){
|
|
474
|
+
let data15 = data.roles;
|
|
475
|
+
if(Array.isArray(data15)){
|
|
476
|
+
const len0 = data15.length;
|
|
477
|
+
for(let i0=0; i0<len0; i0++){
|
|
478
|
+
if(typeof data15[i0] !== "string"){
|
|
479
|
+
const err38 = {instancePath:instancePath+"/roles/" + i0,schemaPath:"#/oneOf/3/properties/roles/items/type",keyword:"type",params:{type: "string"},message:"must be string"};
|
|
480
|
+
if(vErrors === null){
|
|
481
|
+
vErrors = [err38];
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
vErrors.push(err38);
|
|
485
|
+
}
|
|
486
|
+
errors++;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
const err39 = {instancePath:instancePath+"/roles",schemaPath:"#/oneOf/3/properties/roles/type",keyword:"type",params:{type: "array"},message:"must be array"};
|
|
492
|
+
if(vErrors === null){
|
|
493
|
+
vErrors = [err39];
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
vErrors.push(err39);
|
|
497
|
+
}
|
|
498
|
+
errors++;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
var _valid0 = _errs27 === errors;
|
|
503
|
+
if(_valid0 && valid0){
|
|
504
|
+
valid0 = false;
|
|
505
|
+
passing0 = [passing0, 3];
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
if(_valid0){
|
|
509
|
+
valid0 = true;
|
|
510
|
+
passing0 = 3;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if(!valid0){
|
|
516
|
+
const err40 = {instancePath,schemaPath:"#/oneOf",keyword:"oneOf",params:{passingSchemas: passing0},message:"must match exactly one schema in oneOf"};
|
|
517
|
+
if(vErrors === null){
|
|
518
|
+
vErrors = [err40];
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
vErrors.push(err40);
|
|
522
|
+
}
|
|
523
|
+
errors++;
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
errors = _errs1;
|
|
527
|
+
if(vErrors !== null){
|
|
528
|
+
if(_errs1){
|
|
529
|
+
vErrors.length = _errs1;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
vErrors = null;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
validate14.errors = vErrors;
|
|
537
|
+
return errors === 0;
|
|
538
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AccessRef } from './.type/index.js';
|
|
2
|
+
import { type SessionStateAuthenticated } from '../session/index.js';
|
|
3
|
+
export * from './.type/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check if the current session matches an access ref.
|
|
6
|
+
*/
|
|
7
|
+
export declare const matchAccessRef: (session: SessionStateAuthenticated, accessRef: AccessRef) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Returns conditions to spread into a MongoDB $elemMatch for permissions array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* { permissions: { $elemMatch: { ...mongoFilterAccessRef(session), operation: 'read' } } }
|
|
13
|
+
*/
|
|
14
|
+
export declare const mongoFilterAccessRef: (session: SessionStateAuthenticated) => Record<string, any>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export * from './.type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if the current session matches an access ref.
|
|
4
|
+
*/
|
|
5
|
+
export const matchAccessRef = (session, accessRef) => {
|
|
6
|
+
// Check by user, not active account
|
|
7
|
+
if (accessRef.type === 'user') {
|
|
8
|
+
if (accessRef.id)
|
|
9
|
+
return session.user.id === accessRef.id;
|
|
10
|
+
if (accessRef.email)
|
|
11
|
+
return session.user.email === accessRef.email;
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
// Check by active account
|
|
15
|
+
if (accessRef.type === 'organization') {
|
|
16
|
+
if (session.account.type !== 'organization')
|
|
17
|
+
return false;
|
|
18
|
+
if (session.account.id !== accessRef.id)
|
|
19
|
+
return false;
|
|
20
|
+
// Check department: '*' matches all, specific dept must match
|
|
21
|
+
if (accessRef.department &&
|
|
22
|
+
accessRef.department !== '*' &&
|
|
23
|
+
session.account.department !== accessRef.department)
|
|
24
|
+
return false;
|
|
25
|
+
// Check roles: empty array matches all, non-empty must include current role
|
|
26
|
+
if (accessRef.roles &&
|
|
27
|
+
accessRef.roles.length > 0 &&
|
|
28
|
+
!accessRef.roles.includes(session.accountRole))
|
|
29
|
+
return false;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Returns conditions to spread into a MongoDB $elemMatch for permissions array.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* { permissions: { $elemMatch: { ...mongoFilterAccessRef(session), operation: 'read' } } }
|
|
39
|
+
*/
|
|
40
|
+
export const mongoFilterAccessRef = (session) => {
|
|
41
|
+
const userFilter = {
|
|
42
|
+
$or: [
|
|
43
|
+
{ 'access.type': 'user', 'access.id': session.user.id },
|
|
44
|
+
{ 'access.type': 'user', 'access.email': session.user.email }
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
if (session.account.type === 'user')
|
|
48
|
+
return userFilter;
|
|
49
|
+
const baseOrgFilter = {
|
|
50
|
+
'access.type': 'organization',
|
|
51
|
+
'access.id': session.account.id,
|
|
52
|
+
$or: [
|
|
53
|
+
{ 'access.roles': { $size: 0 } },
|
|
54
|
+
{ 'access.roles': { $in: [session.accountRole] } }
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
if (session.account.department)
|
|
58
|
+
baseOrgFilter['access.department'] = { $in: ['*', session.account.department] };
|
|
59
|
+
else
|
|
60
|
+
baseOrgFilter['access.department'] = { $in: ['-', '*'] };
|
|
61
|
+
userFilter.$or.push(baseOrgFilter);
|
|
62
|
+
return userFilter;
|
|
63
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
$id: string;
|
|
3
|
+
'x-exports': string[];
|
|
4
|
+
title: string;
|
|
5
|
+
type: string;
|
|
6
|
+
oneOf: ({
|
|
7
|
+
title: string;
|
|
8
|
+
layout: {
|
|
9
|
+
if: string;
|
|
10
|
+
};
|
|
11
|
+
required: string[];
|
|
12
|
+
properties: {
|
|
13
|
+
mode: {
|
|
14
|
+
type: string;
|
|
15
|
+
const: string;
|
|
16
|
+
};
|
|
17
|
+
type: {
|
|
18
|
+
type: string;
|
|
19
|
+
const: string;
|
|
20
|
+
};
|
|
21
|
+
id: {
|
|
22
|
+
type: string;
|
|
23
|
+
layout: {
|
|
24
|
+
getItems: {
|
|
25
|
+
url: string;
|
|
26
|
+
itemsResults: string;
|
|
27
|
+
itemTitle: string;
|
|
28
|
+
itemValue: string;
|
|
29
|
+
itemIcon: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
email?: undefined;
|
|
34
|
+
department?: undefined;
|
|
35
|
+
roles?: undefined;
|
|
36
|
+
};
|
|
37
|
+
} | {
|
|
38
|
+
title: string;
|
|
39
|
+
required: string[];
|
|
40
|
+
properties: {
|
|
41
|
+
mode: {
|
|
42
|
+
type: string;
|
|
43
|
+
const: string;
|
|
44
|
+
};
|
|
45
|
+
type: {
|
|
46
|
+
type: string;
|
|
47
|
+
const: string;
|
|
48
|
+
};
|
|
49
|
+
email: {
|
|
50
|
+
type: string;
|
|
51
|
+
title: string;
|
|
52
|
+
};
|
|
53
|
+
id?: undefined;
|
|
54
|
+
department?: undefined;
|
|
55
|
+
roles?: undefined;
|
|
56
|
+
};
|
|
57
|
+
layout?: undefined;
|
|
58
|
+
} | {
|
|
59
|
+
title: string;
|
|
60
|
+
layout: {
|
|
61
|
+
if: string;
|
|
62
|
+
};
|
|
63
|
+
required: string[];
|
|
64
|
+
properties: {
|
|
65
|
+
mode: {
|
|
66
|
+
type: string;
|
|
67
|
+
const: string;
|
|
68
|
+
};
|
|
69
|
+
type: {
|
|
70
|
+
type: string;
|
|
71
|
+
const: string;
|
|
72
|
+
};
|
|
73
|
+
department: {
|
|
74
|
+
type: string;
|
|
75
|
+
const: string;
|
|
76
|
+
layout?: undefined;
|
|
77
|
+
};
|
|
78
|
+
roles: {
|
|
79
|
+
type: string;
|
|
80
|
+
const: never[];
|
|
81
|
+
items?: undefined;
|
|
82
|
+
layout?: undefined;
|
|
83
|
+
};
|
|
84
|
+
id: {
|
|
85
|
+
type: string;
|
|
86
|
+
layout: {
|
|
87
|
+
getItems: {
|
|
88
|
+
url: string;
|
|
89
|
+
itemsResults: string;
|
|
90
|
+
itemTitle: string;
|
|
91
|
+
itemValue: string;
|
|
92
|
+
itemIcon: string;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
email?: undefined;
|
|
97
|
+
};
|
|
98
|
+
} | {
|
|
99
|
+
title: string;
|
|
100
|
+
layout: {
|
|
101
|
+
if: string;
|
|
102
|
+
};
|
|
103
|
+
required: string[];
|
|
104
|
+
properties: {
|
|
105
|
+
mode: {
|
|
106
|
+
type: string;
|
|
107
|
+
const: string;
|
|
108
|
+
};
|
|
109
|
+
type: {
|
|
110
|
+
type: string;
|
|
111
|
+
const: string;
|
|
112
|
+
};
|
|
113
|
+
id: {
|
|
114
|
+
type: string;
|
|
115
|
+
layout?: undefined;
|
|
116
|
+
};
|
|
117
|
+
department: {
|
|
118
|
+
type: string;
|
|
119
|
+
layout: {
|
|
120
|
+
getItems: {
|
|
121
|
+
url: string;
|
|
122
|
+
itemsResults: string;
|
|
123
|
+
itemTitle: string;
|
|
124
|
+
itemValue: string;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
const?: undefined;
|
|
128
|
+
};
|
|
129
|
+
roles: {
|
|
130
|
+
type: string;
|
|
131
|
+
items: {
|
|
132
|
+
type: string;
|
|
133
|
+
};
|
|
134
|
+
layout: {
|
|
135
|
+
getItems: {
|
|
136
|
+
url: string;
|
|
137
|
+
itemsResults: string;
|
|
138
|
+
itemTitle: string;
|
|
139
|
+
itemValue: string;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
const?: undefined;
|
|
143
|
+
};
|
|
144
|
+
email?: undefined;
|
|
145
|
+
};
|
|
146
|
+
})[];
|
|
147
|
+
};
|
|
148
|
+
export default _default;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* eslint-disable no-template-curly-in-string */
|
|
2
|
+
export default {
|
|
3
|
+
$id: 'https://github.com/data-fair/lib/access-ref',
|
|
4
|
+
'x-exports': ['types', 'validate'],
|
|
5
|
+
title: 'Access Ref',
|
|
6
|
+
type: 'object',
|
|
7
|
+
oneOf: [
|
|
8
|
+
{
|
|
9
|
+
title: "Un membre de l'organisation",
|
|
10
|
+
layout: { if: "context.owner.type === 'organization'" },
|
|
11
|
+
required: ['mode', 'type', 'id'],
|
|
12
|
+
properties: {
|
|
13
|
+
mode: { type: 'string', const: 'member' },
|
|
14
|
+
type: { type: 'string', const: 'user' },
|
|
15
|
+
id: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
layout: {
|
|
18
|
+
getItems: {
|
|
19
|
+
url: '/simple-directory/api/organization/${context.owner.id}/members',
|
|
20
|
+
itemsResults: 'data.results',
|
|
21
|
+
itemTitle: 'item.name',
|
|
22
|
+
itemValue: 'item.id',
|
|
23
|
+
itemIcon: '`/simple-directory/api/avatars/user/${item.id}/avatar.png`'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
title: 'Un email',
|
|
31
|
+
required: ['mode', 'type', 'email'],
|
|
32
|
+
properties: {
|
|
33
|
+
mode: { type: 'string', const: 'member' },
|
|
34
|
+
type: { type: 'string', const: 'user' },
|
|
35
|
+
email: { type: 'string', title: 'Adresse mail' }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: 'Une organisation partenaire',
|
|
40
|
+
layout: { if: "context.owner.type === 'organization'" },
|
|
41
|
+
required: ['mode', 'type', 'id'],
|
|
42
|
+
properties: {
|
|
43
|
+
mode: { type: 'string', const: 'member' },
|
|
44
|
+
type: { type: 'string', const: 'organization' },
|
|
45
|
+
department: { type: 'string', const: '*' },
|
|
46
|
+
roles: { type: 'array', const: [] },
|
|
47
|
+
id: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
layout: {
|
|
50
|
+
getItems: {
|
|
51
|
+
url: '/simple-directory/api/organization/${context.owner.id}/partners',
|
|
52
|
+
itemsResults: 'data.results',
|
|
53
|
+
itemTitle: 'item.name',
|
|
54
|
+
itemValue: 'item.id',
|
|
55
|
+
itemIcon: '`/simple-directory/api/avatars/organization/${item.id}/avatar.png`'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: 'Un role ou département de mon organisation',
|
|
63
|
+
layout: { if: "context.owner.type === 'organization'" },
|
|
64
|
+
required: ['mode', 'type', 'id'],
|
|
65
|
+
properties: {
|
|
66
|
+
mode: { type: 'string', const: 'internal' },
|
|
67
|
+
type: { type: 'string', const: 'organization' },
|
|
68
|
+
id: { type: 'string' },
|
|
69
|
+
department: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
layout: {
|
|
72
|
+
getItems: {
|
|
73
|
+
url: '/simple-directory/api/organization/${context.owner.id}/departments',
|
|
74
|
+
itemsResults: '[...data.results, {id: "*", name: "Tous les départements"}, {id: "-", name: "Racine de l\'organisation uniquement"}]',
|
|
75
|
+
itemTitle: 'item.name',
|
|
76
|
+
itemValue: 'item.id'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
roles: {
|
|
81
|
+
type: 'array',
|
|
82
|
+
items: {
|
|
83
|
+
type: 'string'
|
|
84
|
+
},
|
|
85
|
+
layout: {
|
|
86
|
+
getItems: {
|
|
87
|
+
url: '/simple-directory/api/organization/${context.owner.id}/roles',
|
|
88
|
+
itemsResults: 'data.results',
|
|
89
|
+
itemTitle: 'item.name',
|
|
90
|
+
itemValue: 'item.id'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
};
|
package/package.json
CHANGED
package/processings.d.ts
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
import type { AxiosInstance } from 'axios';
|
|
2
2
|
import type { DataFairWsClient } from '@data-fair/lib-node/ws-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Function to prepare a processing (trigger when the config is updated).
|
|
5
|
+
* It can be used to:
|
|
6
|
+
* - throw additional errors to validate the config
|
|
7
|
+
* - remove secrets from the config and store them in the secrets object
|
|
8
|
+
*/
|
|
9
|
+
export type PrepareFunction<TProcessingConfig = any> = (context: {
|
|
10
|
+
processingConfig: TProcessingConfig;
|
|
11
|
+
secrets: Record<string, string>;
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
processingConfig?: TProcessingConfig;
|
|
14
|
+
secrets?: Record<string, string>;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Function to execute the processing (triggered when the processing is started).
|
|
18
|
+
* This is the main function of the plugin where the business logic is implemented.
|
|
19
|
+
*
|
|
20
|
+
* @returns An object with a optional deleteOnComplete property to indicate that the last run should be deleted after completion.
|
|
21
|
+
*/
|
|
22
|
+
export type RunFunction<TProcessingConfig = any, TPluginConfig = any> = (context: ProcessingContext<TProcessingConfig, TPluginConfig>) => Promise<void | {
|
|
23
|
+
deleteOnComplete?: boolean;
|
|
24
|
+
}>;
|
|
3
25
|
/**
|
|
4
26
|
* Processing context.
|
|
5
27
|
*/
|
|
6
|
-
export interface ProcessingContext<
|
|
7
|
-
processingConfig:
|
|
8
|
-
pluginConfig:
|
|
28
|
+
export interface ProcessingContext<TProcessingConfig = any, TPluginConfig = any> {
|
|
29
|
+
processingConfig: TProcessingConfig;
|
|
30
|
+
pluginConfig: TPluginConfig;
|
|
9
31
|
secrets?: Record<string, string>;
|
|
10
32
|
processingId: string;
|
|
11
33
|
dir: string;
|
|
@@ -19,19 +41,6 @@ export interface ProcessingContext<TProcesssingConfig = any> {
|
|
|
19
41
|
dataset: any;
|
|
20
42
|
}) => Promise<void>;
|
|
21
43
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Function to prepare a processing (trigger when the config is updated).
|
|
24
|
-
* It can be used to:
|
|
25
|
-
* - throw additional errors to validate the config
|
|
26
|
-
* - remove secrets from the config and store them in the secrets object
|
|
27
|
-
*/
|
|
28
|
-
export type PrepareFunction<TProcesssingConfig = any> = (context: {
|
|
29
|
-
processingConfig: TProcesssingConfig;
|
|
30
|
-
secrets: Record<string, string>;
|
|
31
|
-
}) => Promise<{
|
|
32
|
-
processingConfig?: TProcesssingConfig;
|
|
33
|
-
secrets?: Record<string, string>;
|
|
34
|
-
}>;
|
|
35
44
|
/**
|
|
36
45
|
* Log functions.
|
|
37
46
|
*/
|