Skip to content

Commit

Permalink
Merge pull request #633 from appwrite/feat-revert-offline
Browse files Browse the repository at this point in the history
Feat revert offline
  • Loading branch information
lohanidamodar authored Apr 6, 2023
2 parents af96e57 + c92cdf2 commit 0c86a8a
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 1,196 deletions.
20 changes: 0 additions & 20 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,6 @@ public function getFiles(): array
'destination' => '/lib/src/interceptor.dart',
'template' => 'flutter/lib/src/interceptor.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/src/offline_db_io.dart',
'template' => 'flutter/lib/src/offline_db_io.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/src/offline_db_stub.dart',
'template' => 'flutter/lib/src/offline_db_stub.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/src/offline_db_web.dart',
'template' => 'flutter/lib/src/offline_db_web.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/src/client_offline_mixin.dart',
'template' => 'flutter/lib/src/client_offline_mixin.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/{{ language.params.packageName }}.dart',
Expand Down
5 changes: 0 additions & 5 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ public function getMethods($service)
'query' => [],
'body' => [],
],
'offline' => [
'model' => $method['x-appwrite']['offline-model'] ?? '',
'key' => $method['x-appwrite']['offline-key'] ?? '',
'response-key' => $method['x-appwrite']['offline-response-key'] ?? '$id',
],
'emptyResponse' => $emptyResponse,
'responseModel' => $responseModel,
];
Expand Down
43 changes: 8 additions & 35 deletions templates/dart/lib/id.dart.twig
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
part of {{ language.params.packageName }};

class ID {
ID._();

// Generate a unique ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
static String _uniqid() {
final now = DateTime.now();
final secondsSinceEpoch = (now.millisecondsSinceEpoch / 1000).floor();
final msecs = now.microsecondsSinceEpoch - secondsSinceEpoch * 1000000;
return secondsSinceEpoch.toRadixString(16) +
msecs.toRadixString(16).padLeft(5, '0');
}

// Generate a unique ID with padding to have a longer ID
// Recreated from https://github.com/utopia-php/database/blob/main/src/Database/ID.php#L13
static String _unique({int padding = 7}) {
String id = _uniqid();

if (padding > 0) {
StringBuffer sb = StringBuffer();
for (var i = 0; i < padding; i++) {
sb.write(Random().nextInt(16).toRadixString(16));
}

id += sb.toString();
ID._();

static String unique() {
return 'unique()';
}

return id;
}

static String unique() {
return _unique();
}

static String custom(String id) {
return id;
}
}
static String custom(String id) {
return id;
}
}
1 change: 0 additions & 1 deletion templates/dart/lib/package.dart.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library {{ language.params.packageName }};

import 'dart:async';
import 'dart:math';
import 'dart:typed_data';

import 'src/enums.dart';
Expand Down
16 changes: 1 addition & 15 deletions templates/flutter/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@
{{~ utils.map_headers(method.headers) }}
};

final cacheModel = '{{method['offline']['model']}}'{% if method['offline']['model'] is not empty %}{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %}{% endif %};
final cacheKey = {% if method['offline']['key'] starts with '{' and method['offline']['key'] ends with '}' %}{{method['offline']['key'] | replace({'{': '', '}': ''}) | overrideIdentifier }}{% else %}'{{method['offline']['key']}}'{% endif %};
final cacheResponseIdKey = '{{method['offline']['response-key'] | escapeDollarSign}}';
final cacheResponseContainerKey = '{% for property in spec.definitions[method.responseModel].properties %}{% if property.sub_schema and property.type == 'array' %}{{property.name}}{% endif %}{% endfor %}';

final res = await client.call(
HttpMethod.{{ method.method | caseLower }},
path: path,
params: params,
headers: headers,
cacheModel: cacheModel,
cacheKey: cacheKey,
cacheResponseIdKey: cacheResponseIdKey,
cacheResponseContainerKey: cacheResponseContainerKey,
);
final res = await client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, headers: headers);

return {% if method.responseModel and method.responseModel != 'any' %}models.{{method.responseModel | caseUcfirst | overrideIdentifier}}.fromMap(res.data){% else %} res.data{% endif %};
2 changes: 1 addition & 1 deletion templates/flutter/example/pubspec.yaml.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: {{ language.params.packageName }}_example
environment:
sdk: ">=2.17.0 <3.0.0"
sdk: '>=2.17.0 <3.0.0'
13 changes: 6 additions & 7 deletions templates/flutter/lib/package.dart.twig
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
library {{ language.params.packageName }};

import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'src/enums.dart';
import 'src/service.dart';
import 'src/input_file.dart';
import 'models.dart' as models;
import 'src/upload_progress.dart';

export 'src/response.dart';
export 'src/client.dart';
export 'src/exception.dart';
export 'src/input_file.dart';
export 'src/realtime.dart';
export 'src/realtime_message.dart';
export 'src/realtime_subscription.dart';
export 'src/response.dart';
export 'src/upload_progress.dart';
export 'src/realtime_subscription.dart';
export 'src/realtime_message.dart';
export 'src/input_file.dart';

part 'id.dart';
part 'permission.dart';
part 'query.dart';
part 'permission.dart';
part 'role.dart';
part 'id.dart';
{% for service in spec.services %}
part 'services/{{service.name | caseDash}}.dart';
{% endfor %}
32 changes: 7 additions & 25 deletions templates/flutter/lib/src/client.dart.twig
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import 'enums.dart';
import 'client_stub.dart'
if (dart.library.html) 'client_browser.dart'
if (dart.library.io) 'client_io.dart';
import 'enums.dart';
import 'response.dart';
import 'upload_progress.dart';

abstract class Client {
static const int CHUNK_SIZE = 5 * 1024 * 1024;
static const int CHUNK_SIZE = 5*1024*1024;
late Map<String, String> config;
late String _endPoint;
late String? _endPointRealtime;

String get endPoint => _endPoint;
String? get endPointRealtime => _endPointRealtime;

factory Client({
String endPoint = '{{ spec.endpoint }}',
bool selfSigned = false,
}) =>
factory Client(
{String endPoint = '{{ spec.endpoint }}',
bool selfSigned = false}) =>
createClient(endPoint: endPoint, selfSigned: selfSigned);

Future webAuth(Uri url, {String? callbackUrlScheme});
Expand All @@ -39,34 +38,17 @@ abstract class Client {

{% for header in spec.global.headers %}
{% if header.description %}
/// {{header.description}}
/// {{header.description}}
{% endif %}
Client set{{header.key | caseUcfirst}}(value);
{% endfor %}

Client addHeader(String key, String value);

Future<Response> call(
HttpMethod method, {
Future<Response> call(HttpMethod method, {
String path = '',
Map<String, String> headers = const {},
Map<String, dynamic> params = const {},
ResponseType? responseType,
String cacheModel = '',
String cacheKey = '',
String cacheResponseIdKey = '',
String cacheResponseContainerKey = '',
Map<String, Object?>? previous,
});

Future<Client> setOfflinePersistency({
bool status = true,
void Function(Object)? onWriteQueueError,
});

bool getOfflinePersistency();

Client setOfflineCacheSize(int kbytes);

int getOfflineCacheSize();
}
26 changes: 3 additions & 23 deletions templates/flutter/lib/src/client_base.dart.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'response.dart';
import 'client.dart';
import 'enums.dart';
import 'response.dart';

abstract class ClientBase implements Client {
abstract class ClientBase implements Client {
{% for header in spec.global.headers %}
{% if header.description %}
/// {{header.description}}
{% endif %}
@override
ClientBase set{{header.key | caseUcfirst}}(value);

{% endfor %}

@override
ClientBase setSelfSigned({bool status = true});

Expand All @@ -30,25 +30,5 @@ abstract class ClientBase implements Client {
Map<String, String> headers = const {},
Map<String, dynamic> params = const {},
ResponseType? responseType,
String cacheModel = '',
String cacheKey = '',
String cacheResponseIdKey = '',
String cacheResponseContainerKey = '',
Map<String, Object?>? previous,
});

@override
Future<ClientBase> setOfflinePersistency({
bool status = true,
void Function(Object)? onWriteQueueError,
});

@override
bool getOfflinePersistency();

@override
ClientBase setOfflineCacheSize(int kbytes);

@override
int getOfflineCacheSize();
}
Loading

0 comments on commit 0c86a8a

Please sign in to comment.