3
3
* @module Adapters
4
4
*/
5
5
import type { Schema } from '../../Controllers/types' ;
6
- import { SchemaData } from '../../Controllers/SchemaController' ;
7
6
import SchemaCacheAdapter from './SchemaCacheAdapter' ;
7
+ import { injectDefaultSchema , SchemaData } from '../../Schema/SchemaData' ;
8
+ import { StorageAdapter } from '../Storage/StorageAdapter' ;
9
+ import type { ParseServerOptions } from '../../Options' ;
10
+ import { SchemaAndData } from './types' ;
8
11
9
12
/**
10
13
* @interface SchemaCacheAccess
11
14
*/
12
15
export class SchemaCacheAccess {
13
- constructor ( schemaCacheAdapter : SchemaCacheAdapter ) {
16
+ schemaCacheAdapter : SchemaCacheAdapter ;
17
+ dbAdapter: StorageAdapter ;
18
+ protectedFields: any ;
19
+
20
+ constructor ( schemaCacheAdapter : SchemaCacheAdapter , dbAdapter , options : ParseServerOptions ) {
14
21
this . schemaCacheAdapter = schemaCacheAdapter ;
22
+ this . dbAdapter = dbAdapter ;
23
+ this . protectedFields = options ? options . protectedFields : undefined ;
15
24
}
16
25
17
- setDataProvider (
18
- dataProvider : ( ) = > Promise < { allClasses : Array < Schema > , schemaData : SchemaData } >
19
- ) {
20
- this . schemaCacheAdapter . setDataProvider ( dataProvider ) ;
21
- }
26
+ async getSchemaAndData ( ) : Promise < SchemaAndData > {
27
+ const that = this ;
28
+ return this . schemaCacheAdapter . fetchSchema ( async ( ) => {
29
+ const rawAllSchemas = await that . dbAdapter . getAllClasses ( ) ;
30
+ const allSchemas = rawAllSchemas . map ( injectDefaultSchema ) ;
31
+
32
+ const schemaData = new SchemaData ( allSchemas , that . protectedFields ) ;
22
33
23
- async getSchemaAndData ( ) : Promise < { allClasses: Array < Schema > , schemaData : SchemaData } > {
24
- return this . schemaCacheAdapter . fetchSchema ( ) ;
34
+ return {
35
+ schemaData,
36
+ allClasses : allSchemas ,
37
+ } ;
38
+ } ) ;
25
39
}
26
40
27
41
async all ( ) : Promise < Array < Schema >> {
@@ -37,7 +51,7 @@ export class SchemaCacheAccess {
37
51
}
38
52
39
53
clear ( ) : Promise < void > {
40
- this . schemaCacheAdapter . clear ( ) ;
54
+ return this . schemaCacheAdapter . clear ( ) ;
41
55
}
42
56
43
57
async getSchemaData ( ) : Promise < SchemaData > {
0 commit comments