├── .gitignore ├── .vscode └── launch.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── bin └── dartion.dart ├── db.json ├── doc └── api │ ├── __404error.html │ ├── categories.json │ ├── dartion │ ├── Config-class.html │ ├── Config │ │ ├── Config.fromYaml.html │ │ ├── Config.html │ │ ├── auth.html │ │ ├── db.html │ │ ├── host.html │ │ ├── name.html │ │ ├── port.html │ │ ├── statics.html │ │ └── storage.html │ ├── ConfigRepository-class.html │ ├── ConfigRepository │ │ ├── ConfigRepository.html │ │ └── getConfig.html │ ├── DartIOServer-class.html │ ├── DartIOServer │ │ ├── DartIOServer.html │ │ ├── checkFile.html │ │ ├── config.html │ │ ├── getInstance.html │ │ ├── getSegment.html │ │ ├── getSlash.html │ │ ├── handleAuth.html │ │ ├── handleDelete.html │ │ ├── handleGet.html │ │ ├── handlePatch.html │ │ ├── handlePost.html │ │ ├── handlePut.html │ │ ├── handleRequest.html │ │ ├── handleUpload.html │ │ ├── middlewareJwt.html │ │ ├── start.html │ │ └── uuid.html │ ├── IConfigRepository-class.html │ ├── IConfigRepository │ │ ├── IConfigRepository.html │ │ └── getConfig.html │ └── dartion-library.html │ ├── index.html │ ├── index.json │ ├── search.html │ └── static-assets │ ├── docs.dart.js │ ├── docs.dart.js.map │ ├── favicon.png │ ├── github.css │ ├── highlight.pack.js │ ├── play_button.svg │ ├── readme.md │ ├── search.png │ └── styles.css ├── example ├── config.yaml ├── db.json ├── example.md └── public │ └── index.html ├── lib ├── dartion.dart └── src │ ├── config │ ├── config_model.dart │ ├── config_repository.dart │ ├── database.dart │ └── storage.dart │ ├── server │ ├── auth_service.dart │ └── dartio_server.dart │ └── templates │ └── templates.dart ├── pubspec.yaml ├── readme_assets └── logo-dartion.png ├── server ├── config.yaml ├── db.json └── public │ └── index.html └── test ├── config └── config_test.dart └── server └── auth_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub 2 | .dart_tool/ 3 | .packages 4 | # Remove the following pattern if you wish to check in your lock file 5 | pubspec.lock 6 | 7 | # Conventional directory for build outputs 8 | build/ 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "serve", 9 | "program": "bin/dartion.dart", 10 | "args": ["serve"], 11 | "request": "launch", 12 | "type": "dart" 13 | }, 14 | { 15 | "name": "init", 16 | "program": "bin/dartion.dart", 17 | "args": ["init", "example"], 18 | "request": "launch", 19 | "type": "dart" 20 | }, 21 | ] 22 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.2.0 - May 2023 2 | - Dart 3.0 support 3 | 4 | ## 1.1.0+1 - Jan 2023 5 | - Documentation fixes 6 | 7 | ## 1.1.0 - Jan 2023 8 | - Added Noslin22's HandleAuth fix 9 | - Fixed issue #6 (String fix) 10 | - Fixed issue #10 (Host fix) 11 | - Fixed Tests 12 | - Added Flutterando_analysis as the new linter package 13 | - 134 Linter fixes 14 | - Changed methods wrongly indicated as "formYaml" to "fromYaml" 15 | - Updated package dependencies 16 | - Added example.md 17 | - Erased a folder with no actual use 18 | - Added Flutterando style readme 19 | - Added 'Dart doc' documentation 20 | 21 | ## 1.0.7 - Nov 2021 22 | - Updated builds 23 | - Major changes 24 | - Several fixes 25 | 26 | ## 0.0.7 - Apr 2020 27 | - Added File upload (check documentation) 28 | 29 | ## 0.0.4 - Apr 2020 30 | - Initial version 31 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutterando_analysis/dart_package.yaml 2 | 3 | linter: 4 | rules: 5 | cascade_invocations: false -------------------------------------------------------------------------------- /bin/dartion.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:dartion/dartion.dart'; 4 | 5 | import 'package:dartion/src/templates/templates.dart' as template; 6 | 7 | String version = '1.1.0'; 8 | 9 | void main(List arguments) async { 10 | final arg = arguments.isEmpty ? '--version' : arguments[0]; 11 | 12 | if (arg == 'serve') { 13 | final server = await DartIOServer.getInstance(); 14 | await server.start(); 15 | } else if (arg == '--version' || arguments[0] == '-v') { 16 | stdout.write('Dartion v$version'); 17 | } else if (arg == 'upgrade') { 18 | Process.runSync('pub', ['global', 'activate', 'dartion'], runInShell: true); 19 | stdout.write('Upgrated!'); 20 | } else if (arg == 'init') { 21 | final dir = Directory(arguments.length > 1 ? arguments[1] : '.'); 22 | 23 | if (!dir.existsSync()) { 24 | dir.createSync(recursive: true); 25 | } 26 | 27 | stdout.write(dir.parent.path); 28 | if (dir.listSync().isNotEmpty) { 29 | stdout.write('Folder must be empty!'); 30 | return; 31 | } 32 | 33 | final db = File('${dir.path}/db.json'); 34 | db.createSync(recursive: true); 35 | db.writeAsStringSync(template.db); 36 | 37 | final config = File('${dir.path}/config.yaml'); 38 | config.createSync(recursive: true); 39 | config.writeAsStringSync(template.config); 40 | 41 | final index = File('${dir.path}/public/index.html'); 42 | index.createSync(recursive: true); 43 | index.writeAsStringSync(template.index); 44 | stdout.write('Dartion initialization finished!'); 45 | stdout.write('You can now use the command: dartion serve'); 46 | } else { 47 | exit(0); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /db.json: -------------------------------------------------------------------------------- 1 | {"users":[{"name":"Robert","email":"robert@gmail.com","password":"123"},{"name":"Calls","email":"calls@gmail.com","password":"1234"}],"products":[{"id":0,"title":"Flutter 2"},{"id":1,"title":"React Native"},{"title":"Ionic","id":2},{"id":3,"title":"Flutter 3"},{"id":3,"title":"Flutter 3"}],"cities":[{"name":"Manaus","id":0},{"name":"Fortaleza","id":1},{"name":"Maringá","id":2},{"name":"São Paulo","id":3}],"animals":[{"name":"Cachorro","id":0},{"name":"Gato","id":1},{"name":"Pato","id":2},{"name":"Galo","id":3}]} -------------------------------------------------------------------------------- /doc/api/__404error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | dartion - Dart API docs 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | menu 31 | 34 |
dartion
35 | 38 |
39 | 45 |
46 |
47 |
48 | 49 |
50 |

404: Something's gone wrong :-(

51 | 52 |
53 |

You've tried to visit a page that doesn't exist. Luckily this site 54 | has other pages.

55 |

If you were looking for something specific, try searching: 56 |

59 |

60 | 61 |
62 |
63 | 64 | 83 | 84 | 86 | 87 |
88 | 89 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /doc/api/categories.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/Config.fromYaml.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Config.fromYaml constructor - Config - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
Config.fromYaml
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

Config.fromYaml constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | Config.fromYaml(
  1. Map doc
  2. 60 |
) 61 |
62 | 63 | 64 |
65 |

Factory constructor to build your database configuration using a provided 66 | config.yaml file 67 | The config.yaml must have a layout like this one:

68 |
name: Test
 69 | port: 3031
 70 | db: db.json
 71 | statics: public
 72 | host: 0.0.0.0
 73 | auth:
 74 |   key: dasdrfgdfvkjbkhvjgfigiuhwiodfuhfiyq
 75 |   exp: 3600
 76 |   aud: test.dd
 77 |   scape:
 78 |     - animals
 79 |     - cities
 80 | 
81 |

Be aware that the Auth part is created from the Auth.fromYaml factory 82 | so it should have it's contents also ready if you are going to use the 83 | Auth Service in your database.

84 |
85 | 86 | 87 | 88 |
89 |

Implementation

90 |
factory Config.fromYaml(Map doc) {
 91 |   return Config(
 92 |     name: doc['name'],
 93 |     db: Database(doc['db']),
 94 |     port: doc['port'],
 95 |     statics: doc['statics'] ?? 'public',
 96 |     storage: doc['storage'] == null
 97 |         ? null
 98 |         : Storage.fromYaml(
 99 |             doc['storage'],
100 |           ),
101 |     auth: doc['auth'] == null
102 |         ? null
103 |         : AuthService.fromYaml(
104 |             doc['auth'],
105 |           ),
106 |     host: doc['host'],
107 |   );
108 | }
109 |
110 | 111 | 112 |
113 | 114 | 163 | 164 | 166 | 167 |
168 | 169 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/Config.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Config constructor - Config - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
Config
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

Config constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | Config(
  1. {String name = 'Dartion Server',
  2. 60 |
  3. required IDatabase db,
  4. 61 |
  5. required int port,
  6. 62 |
  7. String statics = 'public',
  8. 63 |
  9. AuthService? auth,
  10. 64 |
  11. Storage? storage,
  12. 65 |
  13. String? host}
  14. 66 |
) 67 |
68 | 69 | 70 |
71 |

Class constructor to create the server. Has some default configurations 72 | but it is advised to create a new instance using the factory so you can 73 | implement the configuration set up in your config.yaml file

74 |
75 | 76 | 77 | 78 |
79 |

Implementation

80 |
Config({
 81 |   this.name = 'Dartion Server',
 82 |   required this.db,
 83 |   required this.port,
 84 |   this.statics = 'public',
 85 |   this.auth,
 86 |   this.storage,
 87 |   this.host,
 88 | });
89 |
90 | 91 | 92 |
93 | 94 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/auth.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | auth property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
auth
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

auth property 54 | Null safety 55 |

56 | 57 |
58 | 59 | AuthService? 60 | auth 61 |
final
62 | 63 |
64 | 65 |
66 |

AuthService object

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final AuthService? auth;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/db.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | db property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
db
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

db property 54 | Null safety 55 |

56 | 57 |
58 | 59 | IDatabase 60 | db 61 |
final
62 | 63 |
64 | 65 |
66 |

IDatabase object

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final IDatabase db;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/host.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | host property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
host
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

host property 54 | Null safety 55 |

56 | 57 |
58 | 59 | String? 60 | host 61 |
final
62 | 63 |
64 | 65 |
66 |

Host's IP address

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final String? host;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/name.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | name property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
name
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

name property 54 | Null safety 55 |

56 | 57 |
58 | 59 | String 60 | name 61 |
final
62 | 63 |
64 | 65 |
66 |

Database name

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final String name;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/port.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | port property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
port
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

port property 54 | Null safety 55 |

56 | 57 |
58 | 59 | int 60 | port 61 |
final
62 | 63 |
64 | 65 |
66 |

The hosts port for database access

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final int port;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/statics.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | statics property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
statics
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

statics property 54 | Null safety 55 |

56 | 57 |
58 | 59 | String 60 | statics 61 |
final
62 | 63 |
64 | 65 |
66 |

Database statics, default to Public

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final String statics;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/Config/storage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | storage property - Config class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
storage
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

storage property 54 | Null safety 55 |

56 | 57 |
58 | 59 | Storage? 60 | storage 61 |
final
62 | 63 |
64 | 65 |
66 |

Storage object

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final Storage? storage;
73 |
74 | 75 | 76 |
77 | 78 | 127 | 128 | 130 | 131 |
132 | 133 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/api/dartion/ConfigRepository/ConfigRepository.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ConfigRepository constructor - ConfigRepository - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
ConfigRepository
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

ConfigRepository constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | ConfigRepository() 60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
69 | 70 | 112 | 113 | 115 | 116 |
117 | 118 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /doc/api/dartion/ConfigRepository/getConfig.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | getConfig method - ConfigRepository class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
getConfig
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

getConfig method 54 | Null safety 55 |

56 | 57 |
58 | 59 |
60 |
    61 |
  1. @override
  2. 62 |
63 |
64 | 65 | Future<Config> 66 | getConfig(
  1. String path
  2. 67 |
) 68 | 69 |
override
70 | 71 |
72 | 73 |
74 |

Gets the database configuration through the yaml file defined in it's 75 | parameter path (String)

76 |
77 | 78 | 79 | 80 |
81 |

Implementation

82 |
@override
 83 | Future<Config> getConfig(String path) async {
 84 |   final yaml = File(path);
 85 |   late Map doc;
 86 |   if (yaml.existsSync()) {
 87 |     doc = loadYaml(await File(path).readAsString());
 88 |   } else {
 89 |     doc = loadYaml('''
 90 | name: Dartion Server
 91 | port: 3031
 92 | db: db.json
 93 | host: 0.0.0.0
 94 | ''');
 95 |   }
 96 | 
 97 |   return Config.fromYaml(doc);
 98 | }
99 |
100 | 101 | 102 |
103 | 104 | 146 | 147 | 149 | 150 |
151 | 152 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/DartIOServer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | DartIOServer constructor - DartIOServer - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
DartIOServer
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

DartIOServer constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | DartIOServer(
  1. {required Config config}
  2. 60 |
) 61 |
62 | 63 | 64 |
65 |

DartIoServer construtor class. Requires a config.yaml file.

66 |
67 | 68 | 69 | 70 |
71 |

Implementation

72 |
DartIOServer({required this.config});
73 |
74 | 75 | 76 |
77 | 78 | 136 | 137 | 139 | 140 |
141 | 142 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/checkFile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | checkFile method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
checkFile
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

checkFile method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | bool 61 | checkFile(
  1. dynamic request
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Method for checking a file. Uses the parameter request, but it's NOT a 70 | Shelf package request. It uses a dynamic parameter to get a 71 | uri.pathSegments

72 |
73 | 74 | 75 | 76 |
77 |

Implementation

78 |
bool checkFile(dynamic request) {
 79 |   if (request.uri.pathSegments.length >= 2) {
 80 |     return request.uri.pathSegments[request.uri.pathSegments.length - 2] ==
 81 |             'file' &&
 82 |         config.storage != null;
 83 |   }
 84 |   return false;
 85 | }
86 |
87 | 88 | 89 |
90 | 91 | 149 | 150 | 152 | 153 |
154 | 155 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/config.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | config property - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
config
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

config property 54 | Null safety 55 |

56 | 57 |
58 | 59 | Config 60 | config 61 |
final
62 | 63 |
64 | 65 |
66 |

Config class - defines database configuration

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
final Config config;
73 |
74 | 75 | 76 |
77 | 78 | 136 | 137 | 139 | 140 |
141 | 142 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/getInstance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | getInstance method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
getInstance
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

getInstance static method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future<DartIOServer> 61 | getInstance() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

Getter that uses the config.yaml data to return a DartIOServer instance

69 |
70 | 71 | 72 | 73 |
74 |

Implementation

75 |
static Future<DartIOServer> getInstance() async {
 76 |   return DartIOServer(
 77 |     config: await ConfigRepository().getConfig('config.yaml'),
 78 |   );
 79 | }
80 |
81 | 82 | 83 |
84 | 85 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/getSegment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | getSegment method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
getSegment
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

getSegment method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future 61 | getSegment(
  1. Request request
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Gets a segment of the requested url. Requires a http Request (from the 70 | Shelf package).

71 |
72 | 73 | 74 | 75 |
76 |

Implementation

77 |
Future<dynamic> getSegment(Request request) async {
 78 |   if (request.url.pathSegments.length > 1) {
 79 |     return config.db
 80 |         .get(request.url.pathSegments.first, request.url.pathSegments[1]);
 81 |   } else {
 82 |     return config.db.getAll(request.url.pathSegments[0]);
 83 |   }
 84 | }
85 |
86 | 87 | 88 |
89 | 90 | 148 | 149 | 151 | 152 |
153 | 154 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/getSlash.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | getSlash property - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
getSlash
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

getSlash property 54 | Null safety 55 |

56 | 57 | 58 | 59 |
60 | 61 |
62 | 63 | String 64 | getSlash 65 | 66 | 67 |
68 | 69 | 70 |
71 |

Getter used to change "" to "/" in paths if Windows is the platform.

72 |
73 | 74 | 75 |
76 |

Implementation

77 |
String get getSlash => Platform.isWindows ? r'\' : '/';
78 |
79 | 80 |
81 | 82 | 83 |
84 | 85 | 143 | 144 | 146 | 147 |
148 | 149 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/handleDelete.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | handleDelete method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
handleDelete
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

handleDelete method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future<Response> 61 | handleDelete(
  1. Request request
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Handles Delete http requisitions. Requires a http Request (from the Shelf 70 | package).

71 |
72 | 73 | 74 | 75 |
76 |

Implementation

77 |
Future<Response> handleDelete(Request request) async {
 78 |   if (!middlewareJwt(request)) {
 79 |     return Response.forbidden(jsonEncode({'error': 'middlewareJwt'}));
 80 |   }
 81 |   try {
 82 |     final key = request.url.pathSegments[0];
 83 |     final dynamic seg = await config.db.getAll(key);
 84 | 
 85 |     if (seg == null) {
 86 |       return Response.notFound(jsonEncode({'error': 'Not found'}));
 87 |     } else {
 88 |       (seg as List).removeWhere(
 89 |         (element) => element['id'] == request.url.pathSegments[1],
 90 |       );
 91 |       await config.db.save(key, seg);
 92 |       return Response.ok(
 93 |         jsonEncode({'data': 'ok!'}),
 94 |         headers: {'content-type': 'application/json'},
 95 |       );
 96 |     }
 97 |   } catch (e) {
 98 |     return Response.internalServerError(
 99 |       body: jsonEncode({'error': 'Internal Error'}),
100 |     );
101 |   }
102 | }
103 |
104 | 105 | 106 |
107 | 108 | 166 | 167 | 169 | 170 |
171 | 172 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/handleGet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | handleGet method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
handleGet
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

handleGet method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future<Response> 61 | handleGet(
  1. Request request
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Handles Get http requisitions. Requires a http Request (from the Shelf 70 | package).

71 |
72 | 73 | 74 | 75 |
76 |

Implementation

77 |
Future<Response> handleGet(Request request) async {
 78 |   if (!middlewareJwt(request)) {
 79 |     return Response.forbidden(jsonEncode({'error': 'middlewareJwt'}));
 80 |   }
 81 | 
 82 |   try {
 83 |     final dynamic seg = await getSegment(request);
 84 | 
 85 |     if (seg == null) {
 86 |       return Response.notFound(jsonEncode({'error': 'Not found'}));
 87 |     } else {
 88 |       return Response.ok(
 89 |         jsonEncode(seg),
 90 |         headers: {'content-type': 'application/json'},
 91 |       );
 92 |     }
 93 |   } catch (e) {
 94 |     return Response.notFound(jsonEncode({'error': 'Internal Error. $e'}));
 95 |   }
 96 | }
97 |
98 | 99 | 100 |
101 | 102 | 160 | 161 | 163 | 164 |
165 | 166 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/handlePost.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | handlePost method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
handlePost
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

handlePost method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future<Response> 61 | handlePost(
  1. Request request
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Handles Post http requisitions. Requires a http Request (from the Shelf 70 | package).

71 |
72 | 73 | 74 | 75 |
76 |

Implementation

77 |
Future<Response> handlePost(Request request) async {
 78 |   if (!middlewareJwt(request)) {
 79 |     return Response.forbidden(jsonEncode({'error': 'middlewareJwt'}));
 80 |   }
 81 |   try {
 82 |     final content = await request.readAsString(); /*2*/
 83 |     final data = jsonDecode(content) as Map;
 84 |     final key = request.url.pathSegments[0];
 85 |     final dynamic seg = await config.db.getAll(request.url.pathSegments[0]);
 86 | 
 87 |     if (seg == null) {
 88 |       return Response.notFound(jsonEncode({'error': 'Not found'}));
 89 |     } else {
 90 |       data['id'] = uuid.v1();
 91 |       seg.add(data);
 92 |       await config.db.save(key, seg);
 93 |       return Response.ok(
 94 |         jsonEncode(data),
 95 |         headers: {'content-type': 'application/json'},
 96 |       );
 97 |     }
 98 |   } catch (e) {
 99 |     return Response.notFound(jsonEncode({'error': 'Internal Error. $e'}));
100 |   }
101 | }
102 |
103 | 104 | 105 |
106 | 107 | 165 | 166 | 168 | 169 |
170 | 171 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/middlewareJwt.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | middlewareJwt method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
middlewareJwt
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

middlewareJwt method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | bool 61 | middlewareJwt(
  1. Request request
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Contains the logic used to validate a Jason Web Token

70 |
71 | 72 | 73 | 74 |
75 |

Implementation

76 |
bool middlewareJwt(Request request) {
 77 |   if (config.auth == null) {
 78 |     return true;
 79 |   }
 80 | 
 81 |   if (request.url.pathSegments.isEmpty ||
 82 |       config.auth?.scape?.contains(request.url.pathSegments[0]) == true) {
 83 |     return true;
 84 |   }
 85 | 
 86 |   final header = request.headers[HttpHeaders.authorizationHeader];
 87 |   if (header == null) {
 88 |     return false;
 89 |   }
 90 | 
 91 |   final token = header[0].replaceFirst('Bearer ', '');
 92 | 
 93 |   final valid = config.auth?.isValid(token, request.url.pathSegments[0]);
 94 | 
 95 |   if (valid != null) {
 96 |     return false;
 97 |   }
 98 | 
 99 |   return true;
100 | }
101 |
102 | 103 | 104 |
105 | 106 | 164 | 165 | 167 | 168 |
169 | 170 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/start.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | start method - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
start
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

start method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future 61 | start() 62 | 63 | 64 | 65 |
66 | 67 |
68 |

Initiates the server using the config.db.init, creating a handler 69 | (middleware) for the requests and starting a shelf server on the localhost

70 |
71 | 72 | 73 | 74 |
75 |

Implementation

76 |
Future start() async {
 77 |   await config.db.init();
 78 |   final handler =
 79 |       const Pipeline().addMiddleware(logRequests()).addHandler(handleRequest);
 80 | 
 81 |   _server = await shelf_io.serve(
 82 |     handler,
 83 |     config.host ?? InternetAddress.loopbackIPv4,
 84 |     config.port,
 85 |   );
 86 |   stdout.write('Server ${config.name} started...');
 87 |   stdout.write('Listening on ${_server.address.host}:${_server.port}');
 88 | }
89 |
90 | 91 | 92 |
93 | 94 | 152 | 153 | 155 | 156 |
157 | 158 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /doc/api/dartion/DartIOServer/uuid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | uuid property - DartIOServer class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
uuid
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

uuid property 54 | Null safety 55 |

56 | 57 |
58 | 59 | Uuid 60 | uuid 61 |
read / write
62 | 63 |
64 | 65 |
66 |

Uuid object from the package Uuid

67 |
68 | 69 | 70 |
71 |

Implementation

72 |
Uuid uuid = const Uuid();
73 |
74 | 75 | 76 |
77 | 78 | 136 | 137 | 139 | 140 |
141 | 142 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /doc/api/dartion/IConfigRepository/IConfigRepository.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | IConfigRepository constructor - IConfigRepository - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
IConfigRepository
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

IConfigRepository constructor 54 | Null safety 55 |

56 | 57 |
58 | 59 | IConfigRepository() 60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
69 | 70 | 112 | 113 | 115 | 116 |
117 | 118 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /doc/api/dartion/IConfigRepository/getConfig.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | getConfig method - IConfigRepository class - dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 36 |
getConfig
37 | 40 |
41 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |

getConfig abstract method 54 | Null safety 55 |

56 | 57 |
58 | 59 | 60 | Future<Config> 61 | getConfig(
  1. String path
  2. 62 |
) 63 | 64 | 65 | 66 |
67 | 68 |
69 |

Gets the database configuration through the yaml file defined in it's 70 | parameter path (String)

71 |
72 | 73 | 74 | 75 |
76 |

Implementation

77 |
Future<Config> getConfig(String path);
78 |
79 | 80 | 81 |
82 | 83 | 125 | 126 | 128 | 129 |
130 | 131 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /doc/api/dartion/dartion-library.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | dartion library - Dart API 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 |
29 | menu 30 | 34 |
dartion
35 | 38 |
39 | 45 |
46 |
47 |
48 | 49 |
50 | 51 |
52 |

dartion library 53 | Null safety 54 | 55 |

56 | 57 | 58 | 59 | 60 |
61 |

Classes

62 | 63 |
64 |
65 | Config 66 | 67 |
68 |
69 | Class that defines the main parameters of the database, such as 70 |
71 | 72 |
73 | ConfigRepository 74 | 75 |
76 |
77 | Class used to configure the database server through the yaml file 78 | defined in it's method getConfig parameter path (String) 79 |
80 | 81 |
82 | DartIOServer 83 | 84 |
85 |
86 | Class that defines the configuration and http server instance 87 |
88 | 89 |
90 | IConfigRepository 91 | 92 |
93 |
94 | Interface class to configure the database server through the yaml file 95 | defined in it's method getConfig parameter path (String) 96 |
97 | 98 |
99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
110 | 111 | 131 | 132 | 151 | 152 |
153 | 154 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /doc/api/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | dartion - Dart API docs 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | menu 31 | 35 |
dartion
36 | 39 |
40 | 46 |
47 |
48 |
49 | 50 |
51 |
52 | 53 | 73 | 74 | 76 | 77 |
78 | 79 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /doc/api/static-assets/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/dartion/929f8b9087dd1edba4a2919ef240c92ae4e0fec8/doc/api/static-assets/favicon.png -------------------------------------------------------------------------------- /doc/api/static-assets/github.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | github.com style (c) Vasily Polovnyov 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | color: #333; 12 | background: #f8f8f8; 13 | } 14 | 15 | .hljs-comment, 16 | .hljs-quote { 17 | color: #998; 18 | font-style: italic; 19 | } 20 | 21 | .hljs-keyword, 22 | .hljs-selector-tag, 23 | .hljs-subst { 24 | color: #333; 25 | font-weight: bold; 26 | } 27 | 28 | .hljs-number, 29 | .hljs-literal, 30 | .hljs-variable, 31 | .hljs-template-variable, 32 | .hljs-tag .hljs-attr { 33 | color: #008080; 34 | } 35 | 36 | .hljs-string, 37 | .hljs-doctag { 38 | color: #d14; 39 | } 40 | 41 | .hljs-title, 42 | .hljs-section, 43 | .hljs-selector-id { 44 | color: #900; 45 | font-weight: bold; 46 | } 47 | 48 | .hljs-subst { 49 | font-weight: normal; 50 | } 51 | 52 | .hljs-type, 53 | .hljs-class .hljs-title { 54 | color: #458; 55 | font-weight: bold; 56 | } 57 | 58 | .hljs-tag, 59 | .hljs-name, 60 | .hljs-attribute { 61 | color: #000080; 62 | font-weight: normal; 63 | } 64 | 65 | .hljs-regexp, 66 | .hljs-link { 67 | color: #009926; 68 | } 69 | 70 | .hljs-symbol, 71 | .hljs-bullet { 72 | color: #990073; 73 | } 74 | 75 | .hljs-built_in, 76 | .hljs-builtin-name { 77 | color: #0086b3; 78 | } 79 | 80 | .hljs-meta { 81 | color: #999; 82 | font-weight: bold; 83 | } 84 | 85 | .hljs-deletion { 86 | background: #fdd; 87 | } 88 | 89 | .hljs-addition { 90 | background: #dfd; 91 | } 92 | 93 | .hljs-emphasis { 94 | font-style: italic; 95 | } 96 | 97 | .hljs-strong { 98 | font-weight: bold; 99 | } 100 | -------------------------------------------------------------------------------- /doc/api/static-assets/play_button.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/api/static-assets/readme.md: -------------------------------------------------------------------------------- 1 | # highlight.js 2 | 3 | Generated from https://highlightjs.org/download/ on 2021-07-13 4 | 5 | **Included languages:** 6 | 7 | * bash 8 | * c 9 | * css 10 | * dart 11 | * diff 12 | * html, xml 13 | * java 14 | * javascript 15 | * json 16 | * kotlin 17 | * markdown 18 | * objective-c 19 | * plaintext 20 | * shell 21 | * swift 22 | * yaml 23 | -------------------------------------------------------------------------------- /doc/api/static-assets/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/dartion/929f8b9087dd1edba4a2919ef240c92ae4e0fec8/doc/api/static-assets/search.png -------------------------------------------------------------------------------- /example/config.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | port: 3031 3 | db: db.json 4 | statics: public/ 5 | host: 0.0.0.0 6 | 7 | # auth: 8 | # key: dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb 9 | # exp: 3600 10 | # scape: 11 | # - animals 12 | # - cities 13 | -------------------------------------------------------------------------------- /example/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "users": [ 3 | { 4 | "name": "Robert", 5 | "email": "robert@gmail.com", 6 | "password": "123" 7 | }, 8 | { 9 | "name": "Calls", 10 | "email": "calls@gmail.com", 11 | "password": "1234" 12 | } 13 | ], 14 | "products": [ 15 | { 16 | "id": 0, 17 | "title": "Flutter 2" 18 | }, 19 | { 20 | "id": 1, 21 | "title": "React Native" 22 | }, 23 | { 24 | "id": 2, 25 | "title": "Ionic" 26 | } 27 | ], 28 | "cities": [ 29 | { 30 | "name": "Manaus", 31 | "id": 0 32 | }, 33 | { 34 | "name": "Fortaleza", 35 | "id": 1 36 | }, 37 | { 38 | "name": "Maringá", 39 | "id": 2 40 | }, 41 | { 42 | "name": "São Paulo", 43 | "id": 3 44 | } 45 | ], 46 | "animals": [ 47 | { 48 | "name": "Cachorro", 49 | "id": 0 50 | }, 51 | { 52 | "name": "Gato", 53 | "id": 1 54 | }, 55 | { 56 | "name": "Pato", 57 | "id": 2 58 | }, 59 | { 60 | "name": "Galo", 61 | "id": 3 62 | } 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /example/example.md: -------------------------------------------------------------------------------- 1 | # Dartion - Usage Example 2 | 3 | ## Initiate Dartion 4 | 5 | **Init server**: 6 | 7 | Execute this command in an empty folder: 8 | 9 | ``` 10 | dartion init 11 | ``` 12 | 13 | This will create the files as you can see in the Example folder. 14 | The `config.yaml` is the file you want to change so you can add your own configurations. 15 | 16 | **Start server**: 17 | 18 | This command will boot the server based on the settings in `config.yaml`. 19 | 20 | ``` 21 | dartion serve 22 | ``` 23 | 24 | Remember to use it in the folder with the files you wish to use. 25 | If you start it using the Example folder you can run the Dartion tests for example. 26 | 27 | **Changing data**: 28 | 29 | The file `db.json` can be changed to add your own data to your mock server. 30 | 31 | **Interacting with the database**: 32 | 33 | Use the IDatabase class methods: 34 | init - to initialize the database 35 | save - to save an entry to the database 36 | getAll - get all entries from it 37 | get - get a single entry -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DartIO 7 | 8 | 9 |
10 |

Dartion server is ready for use.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /lib/dartion.dart: -------------------------------------------------------------------------------- 1 | export 'src/config/config_model.dart'; 2 | export 'src/config/config_repository.dart'; 3 | export 'src/server/dartio_server.dart'; 4 | -------------------------------------------------------------------------------- /lib/src/config/config_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartion/src/config/storage.dart'; 2 | import 'package:dartion/src/server/auth_service.dart'; 3 | 4 | import 'database.dart'; 5 | 6 | /// Class that defines the main parameters of the database, such as 7 | /// ```none 8 | /// name - the database name 9 | /// db - receives an IDatabase object (has methods like init, save...) 10 | /// port - the port for database access 11 | /// statics - receives a String, default is Public 12 | /// auth - receives an AuthService object 13 | /// Storage - receives a Storage object 14 | /// host - receives the ip address of the host 15 | /// ``` 16 | class Config { 17 | /// Database name 18 | final String name; 19 | 20 | /// IDatabase object 21 | final IDatabase db; 22 | 23 | /// The hosts port for database access 24 | final int port; 25 | 26 | /// Database statics, default to Public 27 | final String statics; 28 | 29 | /// AuthService object 30 | final AuthService? auth; 31 | 32 | /// Storage object 33 | final Storage? storage; 34 | 35 | /// Host's IP address 36 | final String? host; 37 | 38 | /// Class constructor to create the server. Has some default configurations 39 | /// but it is advised to create a new instance using the factory so you can 40 | /// implement the configuration set up in your config.yaml file 41 | Config({ 42 | this.name = 'Dartion Server', 43 | required this.db, 44 | required this.port, 45 | this.statics = 'public', 46 | this.auth, 47 | this.storage, 48 | this.host, 49 | }); 50 | 51 | /// Factory constructor to build your database configuration using a provided 52 | /// config.yaml file 53 | /// The config.yaml must have a layout like this one: 54 | /// ```yaml 55 | /// name: Test 56 | /// port: 3031 57 | /// db: db.json 58 | /// statics: public 59 | /// host: 0.0.0.0 60 | /// auth: 61 | /// key: dasdrfgdfvkjbkhvjgfigiuhwiodfuhfiyq 62 | /// exp: 3600 63 | /// aud: test.dd 64 | /// scape: 65 | /// - animals 66 | /// - cities 67 | /// ``` 68 | /// 69 | /// Be aware that the Auth part is created from the Auth.fromYaml factory 70 | /// so it should have it's contents also ready if you are going to use the 71 | /// Auth Service in your database. 72 | factory Config.fromYaml(Map doc) { 73 | return Config( 74 | name: doc['name'], 75 | db: Database(doc['db']), 76 | port: doc['port'], 77 | statics: doc['statics'] ?? 'public', 78 | storage: doc['storage'] == null 79 | ? null 80 | : Storage.fromYaml( 81 | doc['storage'], 82 | ), 83 | auth: doc['auth'] == null 84 | ? null 85 | : AuthService.fromYaml( 86 | doc['auth'], 87 | ), 88 | host: doc['host'], 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /lib/src/config/config_repository.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:yaml/yaml.dart'; 4 | 5 | import 'config_model.dart'; 6 | 7 | /// Interface class to configure the database server through the yaml file 8 | /// defined in it's method getConfig parameter path (String) 9 | abstract class IConfigRepository { 10 | /// Gets the database configuration through the yaml file defined in it's 11 | /// parameter path (String) 12 | Future getConfig(String path); 13 | } 14 | 15 | /// Class used to configure the database server through the yaml file 16 | /// defined in it's method getConfig parameter path (String) 17 | class ConfigRepository implements IConfigRepository { 18 | @override 19 | Future getConfig(String path) async { 20 | final yaml = File(path); 21 | late Map doc; 22 | if (yaml.existsSync()) { 23 | doc = loadYaml(await File(path).readAsString()); 24 | } else { 25 | doc = loadYaml(''' 26 | name: Dartion Server 27 | port: 3031 28 | db: db.json 29 | host: 0.0.0.0 30 | '''); 31 | } 32 | 33 | return Config.fromYaml(doc); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/config/database.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert' show jsonEncode, jsonDecode; 2 | import 'dart:io'; 3 | 4 | /// Interface class for the Database methods. There are 4 methods: 5 | /// ```none 6 | /// init - to initialize the database 7 | /// save - to save an entry to the database 8 | /// getAll - get all entries from it 9 | /// get - get a single entry 10 | /// ``` 11 | abstract class IDatabase { 12 | /// Starts the database based on the config.yaml settings defined by you. 13 | Future init(); 14 | 15 | /// Saves an entry to the database. Receives a key as String and a 16 | /// dynamic by default. The example uses a Map (see the Test 17 | /// folder to understand it). Your implementation of the mock database will 18 | /// define what to use as values. 19 | Future save(String key, dynamic seg); 20 | 21 | /// Gets all entries from the defined database based on a String query 22 | Future getAll(String query); 23 | 24 | /// Gets a single entry from the defined database based on a String query and 25 | /// a String id 26 | Future> get(String query, String id); 27 | } 28 | 29 | /// The class that defines the Database methods. 30 | /// Receives the database json through it's constructor as a String. 31 | /// There are 4 methods in this class: 32 | /// init - to initialize the database 33 | /// save - to save an entry to the database 34 | /// getAll - get all entries from it 35 | /// get - get a single entry 36 | class Database implements IDatabase { 37 | late Map _json; 38 | 39 | /// The defined path for the database file (db.json on the folder where the 40 | /// server was initialized, by default) 41 | final String path; 42 | 43 | /// Constructor method for creating a database instance 44 | Database(this.path); 45 | 46 | @override 47 | Future init() async { 48 | final db = File(path); 49 | if (db.existsSync()) { 50 | _json = jsonDecode(await db.readAsString()); 51 | } else { 52 | await db.create(recursive: true); 53 | await db.writeAsString('{}'); 54 | _json = {}; 55 | } 56 | } 57 | 58 | @override 59 | Future getAll(String query) async { 60 | final db = _json; 61 | return db[query] ?? []; 62 | } 63 | 64 | @override 65 | Future> get(String query, String id) async { 66 | final db = await getAll(query); 67 | return db.firstWhere((element) => element['id'].toString() == id); 68 | } 69 | 70 | @override 71 | Future save(String key, dynamic value) async { 72 | _json[key].add(value); 73 | await File(path).writeAsString(jsonEncode(_json)); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /lib/src/config/storage.dart: -------------------------------------------------------------------------------- 1 | /// Class used to mimic the data storage folder; Uses a String folder and a 2 | /// String name in it's constructor. 3 | class Storage { 4 | /// Storage folder 5 | final String folder; 6 | 7 | /// Storage name 8 | final String name; 9 | 10 | /// Storage constructor, requires a folder and a name, both as String params 11 | Storage({ 12 | required this.folder, 13 | required this.name, 14 | }); 15 | 16 | /// Factory constructor to build a mock Storage throught the config.yaml data 17 | factory Storage.fromYaml(Map doc) { 18 | return Storage( 19 | folder: doc['folder'], 20 | name: doc['name'], 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/server/auth_service.dart: -------------------------------------------------------------------------------- 1 | import 'package:jaguar_jwt/jaguar_jwt.dart'; 2 | 3 | /// This class mimics an Auth Service with tokens. Requires a String key, 4 | /// an int exp (expected response time), a List aud (defaults to 5 | /// test.dd in the configuration provided by this package) and another 6 | /// List of possible escape codes 7 | class AuthService { 8 | /// Auth service key 9 | final String key; 10 | 11 | /// Auth service expected time to response; Defaults to 3600ms in the 12 | /// config.yaml created initially 13 | final int exp; 14 | 15 | /// Auth service aud; Defaults to test.dd in the config.yaml created initially 16 | final List? aud; 17 | 18 | /// Possible escape codes for use with Authorizations 19 | final List? scape; 20 | 21 | /// Constructor method for the AuthService class. Requires a String key, 22 | /// an int exp (expected response time in seconds), a List aud 23 | /// (defaults to test.dd in the configuration provided by this package) and 24 | /// another List of routes that will not be affected by 25 | /// token protection 26 | AuthService({ 27 | required this.key, 28 | required this.exp, 29 | this.aud, 30 | this.scape, 31 | }); 32 | 33 | ///Factory constructor to build the AuthService through the config.yaml data 34 | ///received by a Map parameter. 35 | ///The config.yaml must have a layout like this one: 36 | /// ```yaml 37 | /// auth: 38 | /// key: dasdrfgdfvkjbkhvjgfigiuhwiodfuhfiyq 39 | /// exp: 3600 40 | /// aud: test.dd 41 | /// scape: 42 | /// - animals 43 | /// - cities 44 | /// ``` 45 | factory AuthService.fromYaml(Map doc) { 46 | return AuthService( 47 | key: doc['key'], 48 | exp: doc['exp'], 49 | aud: doc['aud'] == null 50 | ? null 51 | : (doc['aud'] as List) 52 | .map( 53 | (e) => '$e', 54 | ) 55 | .toList(), 56 | scape: doc['scape'] == null 57 | ? [] 58 | : (doc['scape'] as List) 59 | .map( 60 | (e) => '$e', 61 | ) 62 | .toList(), 63 | ); 64 | } 65 | 66 | /// Generates an AuthToken based on the integer id provided. 67 | String generateToken(int id) { 68 | final claimSet = JwtClaim( 69 | subject: '$id', 70 | issuer: 'dartio', 71 | maxAge: Duration(seconds: exp), 72 | ); 73 | 74 | return issueJwtHS256(claimSet, key); 75 | } 76 | 77 | /// Uses a try / catch to check the AuthToken validity. Receives a String 78 | /// token and a String route. 79 | String? isValid(String token, String route) { 80 | try { 81 | if (scape?.contains(route) == true) { 82 | return null; 83 | } 84 | final decClaimSet = verifyJwtHS256Signature(token, key); 85 | decClaimSet.validate(issuer: 'dartio'); 86 | return null; 87 | } on JwtException catch (e) { 88 | return e.message; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /lib/src/templates/templates.dart: -------------------------------------------------------------------------------- 1 | /// Default template for server configurations created by the 2 | /// dartion init command 3 | const String config = ''' 4 | name: Test 5 | port: 3031 6 | db: db.json 7 | statics: public/ 8 | 9 | # storage: 10 | # folder: storage/ 11 | # name: "file" 12 | 13 | # auth: 14 | # key: dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb 15 | # exp: 3600 16 | # scape: 17 | # - storage 18 | # - file 19 | '''; 20 | 21 | /// Default template for a mock database created by the dartion init command 22 | const String db = ''' 23 | { 24 | "users": [ 25 | { 26 | "id": "0", 27 | "name": "Robert", 28 | "email": "robert@gmail.com", 29 | "password": "123" 30 | }, 31 | { 32 | "id": "1", 33 | "name": "Carls", 34 | "email": "carls@gmail.com", 35 | "password": "1234" 36 | } 37 | ], 38 | "products": [ 39 | { 40 | "id": "0", 41 | "title": "Flutter 2" 42 | }, 43 | { 44 | "id": "1", 45 | "title": "React Native" 46 | }, 47 | { 48 | "title": "Ionic", 49 | "id": "2" 50 | } 51 | ] 52 | } 53 | '''; 54 | 55 | /// Default Template for the index.html created by the dartion init command 56 | const String index = ''' 57 | 58 | 59 | 60 | 61 | 62 | DartIO 63 | 64 | 65 |
66 |

Dartion is ready for use.

67 |
68 | 69 | 70 | '''; 71 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dartion 2 | description: Dartion is a RESTful mini web server based on JSON. Up your backend in 5 Seconds! 3 | version: 1.2.0 4 | homepage: https://github.com/Flutterando/dartion 5 | 6 | environment: 7 | sdk: '>=3.0.0 <4.0.0' 8 | 9 | dependencies: 10 | jaguar_jwt: ^3.0.0 11 | path: ^1.8.3 12 | shelf: ^1.4.0 13 | shelf_multipart: ^1.0.0 14 | shelf_router: ^1.1.3 15 | shelf_static: ^1.1.1 16 | uuid: ^3.0.7 17 | yaml: ^3.1.1 18 | 19 | dev_dependencies: 20 | flutterando_analysis: ^0.0.2 21 | test: ^1.24.3 22 | 23 | executables: 24 | dartion: dartion -------------------------------------------------------------------------------- /readme_assets/logo-dartion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flutterando/dartion/929f8b9087dd1edba4a2919ef240c92ae4e0fec8/readme_assets/logo-dartion.png -------------------------------------------------------------------------------- /server/config.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | port: 3031 3 | db: db.json 4 | statics: public 5 | host: 0.0.0.0 6 | 7 | auth: 8 | key: dasdrfgdfvkjbkhvjgfigiuhwiodfuhfiyq 9 | exp: 3600 10 | aud: test.dd 11 | scape: 12 | - animals 13 | - cities 14 | -------------------------------------------------------------------------------- /server/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "users": [ 3 | { 4 | "name": "Robert", 5 | "email": "robert@gmail.com", 6 | "password": "123" 7 | }, 8 | { 9 | "name": "Calls", 10 | "email": "calls@gmail.com", 11 | "password": "1234" 12 | } 13 | ], 14 | "products": [ 15 | { 16 | "id": 0, 17 | "title": "Flutter 2" 18 | }, 19 | { 20 | "id": 1, 21 | "title": "React Native" 22 | }, 23 | { 24 | "title": "Ionic", 25 | "id": 2 26 | } 27 | ], 28 | "cities": [ 29 | { 30 | "name": "Manaus", 31 | "id": 0 32 | }, 33 | { 34 | "name": "Fortaleza", 35 | "id": 1 36 | }, 37 | { 38 | "name": "Maringá", 39 | "id": 2 40 | }, 41 | { 42 | "name": "São Paulo", 43 | "id": 3 44 | } 45 | ], 46 | "animals": [ 47 | { 48 | "name": "Cachorro", 49 | "id": 0 50 | }, 51 | { 52 | "name": "Gato", 53 | "id": 1 54 | }, 55 | { 56 | "name": "Pato", 57 | "id": 2 58 | }, 59 | { 60 | "name": "Galo", 61 | "id": 3 62 | } 63 | ] 64 | } -------------------------------------------------------------------------------- /server/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DartIO 7 | 8 | 9 |
10 |

Dartion is ready for use.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /test/config/config_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:dartion/src/config/config_model.dart'; 2 | import 'package:dartion/src/config/config_repository.dart'; 3 | import 'package:dartion/src/config/database.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | late IConfigRepository rep; 8 | 9 | setUp(() { 10 | rep = ConfigRepository(); 11 | }); 12 | 13 | group('Config', () { 14 | test('get config', () async { 15 | final config = await rep.getConfig('/server/config.yaml'); 16 | 17 | expect(config, isA()); 18 | expect(config.name, 'Dartion Server'); 19 | expect(config.port, 3031); 20 | }); 21 | 22 | test('get all from db query', () async { 23 | final config = await rep.getConfig('/server/config.yaml'); 24 | await config.db.init(); 25 | 26 | expect(config.db, isA()); 27 | 28 | final products = await config.db.getAll('products'); 29 | expect(products, isA()); 30 | }); 31 | 32 | test('get db one item', () async { 33 | final config = await rep.getConfig('/server/config.yaml'); 34 | await config.db.init(); 35 | expect(config.db, isA()); 36 | 37 | final item = await config.db.get('products', '0'); 38 | expect(item['title'], 'Flutter 2'); 39 | }); 40 | 41 | test('save item to db', () async { 42 | final config = await rep.getConfig('/server/config.yaml'); 43 | await config.db.init(); 44 | expect(config.db, isA()); 45 | 46 | final item = await config.db.get('products', '0'); 47 | item['title'] = 'Flutter 2'; 48 | expect(item['title'], 'Flutter 2'); 49 | 50 | await config.db.save('products', {'id': 3, 'title': 'Flutter 3'}); 51 | final config2 = await rep.getConfig('/server/config.yaml'); 52 | await config2.db.init(); 53 | final item2 = await config2.db.get('products', '3'); 54 | expect(item2['title'], 'Flutter 3'); 55 | }); 56 | }); 57 | } 58 | -------------------------------------------------------------------------------- /test/server/auth_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'package:dartion/src/server/auth_service.dart'; 3 | import 'package:test/test.dart'; 4 | 5 | void main() { 6 | group('Auth', () { 7 | test('get token', () async { 8 | final service = AuthService( 9 | key: 'dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb', 10 | exp: 3600, 11 | aud: ['test.dd'], 12 | ); 13 | final token = service.generateToken(2); 14 | stdout.write(token); 15 | expect(token, isA()); 16 | }); 17 | test('check token invalid', () async { 18 | final service = AuthService( 19 | key: 'dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb', 20 | exp: 3600, 21 | aud: ['test.dd'], 22 | scape: [], 23 | ); 24 | 25 | expect( 26 | service.isValid( 27 | 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiYXVkaWVuY2UxLmV4Y' 28 | 'W1wbGUuY29tIiwiYXVkaWVuY2UyLmV4YW1wbGUuY29tIl0sImV4cCI6MTU4Nz' 29 | 'kzMTM2NSwiaWF0IjoxNTg3OTMxMzQ1LCJpc3MiOiJkYXJ0aW8iLCJzdWIiOiI' 30 | 'yIn0.YOcosusO4dg2gEk9SCy5R-fdiTDgoMxzioZ2DkOEpWQ', 31 | 'products', 32 | ), 33 | isA(), 34 | ); 35 | }); 36 | test('check token valid', () async { 37 | final service = AuthService( 38 | key: 'dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb', 39 | exp: 3600, 40 | aud: ['test.dd'], 41 | scape: [], 42 | ); 43 | 44 | final token = service.generateToken(2); 45 | expect(service.isValid(token, 'products'), null); 46 | }); 47 | test('check scaped route', () async { 48 | final service = AuthService( 49 | key: 'dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb', 50 | exp: 3600, 51 | aud: ['test.dd'], 52 | scape: ['test'], 53 | ); 54 | 55 | expect(service.isValid('fdsfewfdw', 'test'), null); 56 | }); 57 | }); 58 | } 59 | --------------------------------------------------------------------------------