1
1
import { Schema as InternalSchema } from './schema-analyzer' ;
2
2
import convertors from './schema-convertors' ;
3
- import { ExtendedJSONSchema , MongodbJSONSchema , StandardJSONSchema } from './types' ;
3
+ import { ExtendedJSONSchema , MongoDBJSONSchema , StandardJSONSchema } from './types' ;
4
4
5
5
export interface SchemaAccessor {
6
6
getStandardJsonSchema : ( ) => Promise < StandardJSONSchema > ;
7
- getMongodbJsonSchema : ( ) => Promise < MongodbJSONSchema > ;
7
+ getMongoDBJsonSchema : ( ) => Promise < MongoDBJSONSchema > ;
8
8
getExtendedJsonSchema : ( ) => Promise < ExtendedJSONSchema > ;
9
9
getInternalSchema : ( ) => Promise < InternalSchema > ;
10
10
}
11
11
12
+ type Options = {
13
+ signal ?: AbortSignal ;
14
+ }
15
+
12
16
/**
13
17
* Accessor for different schema formats.
14
18
* Internal schema is provided at initialization,
@@ -18,31 +22,29 @@ export interface SchemaAccessor {
18
22
export class InternalSchemaBasedAccessor implements SchemaAccessor {
19
23
private internalSchema : InternalSchema ;
20
24
private standardJSONSchema ?: StandardJSONSchema ;
21
- private mongodbJSONSchema ?: MongodbJSONSchema ;
25
+ private mongodbJSONSchema ?: MongoDBJSONSchema ;
22
26
private extendedJSONSchema ?: ExtendedJSONSchema ;
23
- private signal ?: AbortSignal ;
24
27
25
- constructor ( internalSchema : InternalSchema , signal ?: AbortSignal ) {
26
- this . signal = signal ;
28
+ constructor ( internalSchema : InternalSchema ) {
27
29
this . internalSchema = internalSchema ;
28
30
}
29
31
30
- async getInternalSchema ( ) : Promise < InternalSchema > {
32
+ async getInternalSchema ( options ?: Options ) : Promise < InternalSchema > {
31
33
return this . internalSchema ;
32
34
}
33
35
34
- async getStandardJsonSchema ( ) : Promise < StandardJSONSchema > {
36
+ async getStandardJsonSchema ( options : Options = { } ) : Promise < StandardJSONSchema > {
35
37
if ( this . standardJSONSchema ) return this . standardJSONSchema ;
36
- return this . standardJSONSchema = await convertors . internalSchemaToStandard ( this . internalSchema , { signal : this . signal } ) ;
38
+ return this . standardJSONSchema = await convertors . internalSchemaToStandard ( this . internalSchema , options ) ;
37
39
}
38
40
39
- async getMongodbJsonSchema ( ) : Promise < MongodbJSONSchema > {
41
+ async getMongoDBJsonSchema ( options : Options = { } ) : Promise < MongoDBJSONSchema > {
40
42
if ( this . mongodbJSONSchema ) return this . mongodbJSONSchema ;
41
- return this . mongodbJSONSchema = await convertors . internalSchemaToMongodb ( this . internalSchema , { signal : this . signal } ) ;
43
+ return this . mongodbJSONSchema = await convertors . internalSchemaToMongoDB ( this . internalSchema , options ) ;
42
44
}
43
45
44
- async getExtendedJsonSchema ( ) : Promise < ExtendedJSONSchema > {
46
+ async getExtendedJsonSchema ( options : Options = { } ) : Promise < ExtendedJSONSchema > {
45
47
if ( this . extendedJSONSchema ) return this . extendedJSONSchema ;
46
- return this . extendedJSONSchema = await convertors . internalSchemaToExtended ( this . internalSchema , { signal : this . signal } ) ;
48
+ return this . extendedJSONSchema = await convertors . internalSchemaToExtended ( this . internalSchema , options ) ;
47
49
}
48
50
}
0 commit comments