File tree Expand file tree Collapse file tree 6 files changed +75
-290
lines changed
Expand file tree Collapse file tree 6 files changed +75
-290
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import { ObjectQL } from '@objectql/core' ;
2- import { MetadataLoader } from './loader ' ;
3- import { registerObjectQLPlugins } from './plugins/objectql ' ;
2+ import { AppPlugin } from './plugins/app ' ;
3+ import { DataPlugin } from './plugins/data ' ;
44
55export class ObjectOS extends ObjectQL {
6- public readonly componentLoader : MetadataLoader ;
76
87 constructor ( config : { datasources ?: any , packages ?: string [ ] } = { } ) {
98 super ( {
109 datasources : config . datasources || { } ,
11- packages : config . packages
10+ packages : config . packages ,
11+ plugins : [ AppPlugin , DataPlugin ]
1212 } ) ;
13-
14- this . componentLoader = new MetadataLoader ( this . metadata as any ) ;
15- registerObjectQLPlugins ( this . componentLoader ) ;
1613 }
1714
1815 async init ( options ?: any ) {
Original file line number Diff line number Diff line change 1+ import * as yaml from 'js-yaml' ;
2+
3+ export const AppPlugin = {
4+ name : 'objectos-app-loader' ,
5+ setup ( app : any ) {
6+ app . addLoader ( {
7+ name : 'app' ,
8+ glob : [ '**/*.app.yml' , '**/*.app.yaml' ] ,
9+ handler : ( ctx : any ) => {
10+ try {
11+ const doc = yaml . load ( ctx . content ) as any ;
12+ const id = doc . code || doc . id || doc . name ;
13+ if ( id ) {
14+ ctx . registry . register ( 'app' , {
15+ type : 'app' ,
16+ id : id ,
17+ path : ctx . file ,
18+ package : ctx . packageName ,
19+ content : doc
20+ } ) ;
21+ }
22+ } catch ( e ) {
23+ console . error ( `Error loading app from ${ ctx . file } :` , e ) ;
24+ }
25+ }
26+ } ) ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ import * as yaml from 'js-yaml' ;
2+ import * as path from 'path' ;
3+
4+ export const DataPlugin = {
5+ name : 'objectos-data-loader' ,
6+ setup ( app : any ) {
7+ app . addLoader ( {
8+ name : 'data' ,
9+ glob : [ '**/*.data.yml' , '**/*.data.yaml' ] ,
10+ handler : ( ctx : any ) => {
11+ try {
12+ const content = ctx . content ;
13+ const data = yaml . load ( content ) ;
14+ if ( ! Array . isArray ( data ) ) return ;
15+
16+ const basename = path . basename ( ctx . file ) ;
17+ const objectName = basename . replace ( / \. d a t a \. y a ? m l $ / , '' ) ;
18+
19+ const entry = ctx . registry . getEntry ( 'object' , objectName ) ;
20+ if ( entry ) {
21+ const config = entry . content as any ;
22+ config . data = data ;
23+ } else {
24+ console . warn ( `Found data for unknown object '${ objectName } ' in ${ ctx . file } ` ) ;
25+ }
26+ } catch ( e ) {
27+ console . error ( `Error loading data from ${ ctx . file } :` , e ) ;
28+ }
29+ }
30+ } ) ;
31+ }
32+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ {
2+ "folders" : [
3+ {
4+ "path" : " ."
5+ },
6+ {
7+ "path" : " ../objectql"
8+ }
9+ ],
10+ "settings" : {}
11+ }
You can’t perform that action at this time.
0 commit comments