@@ -6,6 +6,7 @@ import TableGroup from './tableGroup';
66import Table from './table' ;
77import StickyNote from './stickyNote' ;
88import Element from './element' ;
9+ import Policy from './policy' ;
910import {
1011 DEFAULT_SCHEMA_NAME , TABLE , TABLE_GROUP , ENUM , REF , NOTE ,
1112} from './config' ;
@@ -24,6 +25,7 @@ class Database extends Element {
2425 aliases = [ ] ,
2526 records = [ ] ,
2627 tablePartials = [ ] ,
28+ policies = [ ] ,
2729 } ) {
2830 super ( ) ;
2931 this . dbState = new DbState ( ) ;
@@ -39,6 +41,7 @@ class Database extends Element {
3941 this . aliases = aliases ;
4042 this . records = [ ] ;
4143 this . tablePartials = [ ] ;
44+ this . policies = [ ] ;
4245
4346 // The global array containing references with 1 endpoint being a field injected from a partial to a table
4447 // These refs are add to this array when resolving partials in tables (`Table.processPartials()`)
@@ -48,6 +51,7 @@ class Database extends Element {
4851 this . processNotes ( notes ) ;
4952 this . processRecords ( records ) ;
5053 this . processTablePartials ( tablePartials ) ;
54+ this . processPolicies ( policies ) ;
5155 this . processSchemas ( schemas ) ;
5256 this . processSchemaElements ( enums , ENUM ) ;
5357 this . processSchemaElements ( tables , TABLE ) ;
@@ -93,6 +97,12 @@ class Database extends Element {
9397 } ) ;
9498 }
9599
100+ processPolicies ( rawPolicies ) {
101+ rawPolicies . forEach ( ( rawPolicy ) => {
102+ this . policies . push ( new Policy ( { ...rawPolicy , database : this } ) ) ;
103+ } ) ;
104+ }
105+
96106 pushNote ( note ) {
97107 this . checkNote ( note ) ;
98108 this . notes . push ( note ) ;
@@ -233,13 +243,15 @@ class Database extends Element {
233243 schemas : this . schemas . map ( ( s ) => s . export ( ) ) ,
234244 notes : this . notes . map ( ( n ) => n . export ( ) ) ,
235245 records : this . records . map ( ( r ) => ( { ...r } ) ) ,
246+ policies : this . policies . map ( ( p ) => p . export ( ) ) ,
236247 } ;
237248 }
238249
239250 exportChildIds ( ) {
240251 return {
241252 schemaIds : this . schemas . map ( ( s ) => s . id ) ,
242253 noteIds : this . notes . map ( ( n ) => n . id ) ,
254+ policyIds : this . policies . map ( ( p ) => p . id ) ,
243255 } ;
244256 }
245257
@@ -266,12 +278,14 @@ class Database extends Element {
266278 fields : { } ,
267279 records : { } ,
268280 tablePartials : { } ,
281+ policies : { } ,
269282 } ;
270283
271284 this . schemas . forEach ( ( schema ) => schema . normalize ( normalizedModel ) ) ;
272285 this . notes . forEach ( ( note ) => note . normalize ( normalizedModel ) ) ;
273286 this . records . forEach ( ( record ) => { normalizedModel . records [ record . id ] = { ...record } ; } ) ;
274287 this . tablePartials . forEach ( ( tablePartial ) => tablePartial . normalize ( normalizedModel ) ) ;
288+ this . policies . forEach ( ( policy ) => policy . normalize ( normalizedModel ) ) ;
275289 return normalizedModel ;
276290 }
277291}
0 commit comments