Skip to content

Commit

Permalink
Merge branch 'master' into feature/rust-codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Jun 12, 2024
2 parents 9c395dd + 3583696 commit 46502c2
Show file tree
Hide file tree
Showing 96 changed files with 9,816 additions and 5,690 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ build
**/.tmp
**/*.dart_tool
.nx/cache
.nx/workspace-data

**/target
**/.gradle
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/dist
/coverage
/.nx/cache
/tests/test-files
/tests/test-files
/.nx/workspace-data
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Below are the language client generators that are planned to have first party su
| [Dart](languages/dart/dart-codegen/) |||
| Rust | 🚧 | 🚧 |
| [Kotlin](languages/kotlin/kotlin-codegen/) |||
| Swift | | |
| Swift | 🚧 | 🚧 |
| Go | | |
| Python | | |

Expand Down Expand Up @@ -50,22 +50,17 @@ Before running this command. Make sure you have an arri config created already.

```ts
// arri.config.ts
import {
defineConfig,
dartClientGenerator,
kotlinClientGenerator,
typescriptClientGenerator,
} from "arri";
import { defineConfig, generators } from "arri";

export default defineConfig({
generators: [
dartClientGenerator({
generators.dartClient({
// options
}),
kotlinClientGenerator({
generators.kotlinClient({
// options
}),
typescriptClientGenerator({
generators.typescriptClient({
// options
}),
],
Expand Down Expand Up @@ -133,7 +128,7 @@ JSON app definitions are something that would normally be automatically generate

```json
{
"arriSchemaVersion": "<current-schema-version>",
"schemaVersion": "<current-schema-version>",
"procedures": {
"sayHello": {
"transport": "http",
Expand Down
5 changes: 2 additions & 3 deletions internal/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"name": "internal-scripts",
"targets": {
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"executor": "nx:run-commands",
"options": {
"lintFilePatterns": ["internal/**/*.ts"]
"command": "pnpm eslint internal"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/generate-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const BookParams = a.object(
type BookParams = a.infer<typeof BookParams>;

const def: AppDefinition = {
arriSchemaVersion: "0.0.5",
schemaVersion: "0.0.6",
info: {
version: "20",
},
Expand Down
106 changes: 105 additions & 1 deletion languages/dart/dart-client/lib/arri_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,109 @@ export "errors.dart";
export 'parsing.dart';
export 'request.dart';
export 'sse.dart';
export 'utils.dart';
export 'ws.dart';

abstract class ArriModel {
Map<String, dynamic> toJson();
String toJsonString();
String toUrlQueryParams();
ArriModel copyWith();
List<Object?> get props;
}

bool listsAreEqual(List? list1, List? list2, {bool log = false}) {
if (list1 == null || list2 == null) {
return list1 == null && list2 == null;
}
final length = list1.length;
if (list2.length != length) return false;
for (var i = 0; i < length; i++) {
final item1 = list1[i];
final item2 = list2[i];
if (log) {
print("1 $item1");
print("2 $item2");
}
if (item1 is Map) {
if (!mapsAreEqual(item1, item2, log: log)) {
if (log) print("$item1 != $item2");
return false;
}
} else if (item1 is List) {
if (!listsAreEqual(item1, item2, log: log)) return false;
} else if (item1.runtimeType != item2.runtimeType) {
if (log) print("$item1 != $item2");
return false;
} else if (item1 is DateTime) {
if (!item1.isAtSameMomentAs(item2)) {
if (log) print("$item1 != $item2");
return false;
}
} else if (item1 != item2) {
if (log) print("$item1 != $item2");
return false;
}
}
return true;
}

bool mapsAreEqual(Map? map1, Map? map2, {bool log = false}) {
if (map1 == null || map2 == null) {
return map1 == null && map2 == null;
}
final length = map1.length;
if (map2.length != length) return false;
for (final entry in map1.entries) {
if (!map2.containsKey(entry.key)) return false;
final value1 = entry.value;
final value2 = map2[entry.key];

if (value1 is Map) {
if (!mapsAreEqual(value1, value2, log: log)) return false;
} else if (value1 is List) {
if (!listsAreEqual(value1, value2, log: log)) return false;
} else if (value1.runtimeType != value2.runtimeType) {
if (log) print("$value1 != $value2");
return false;
} else if (value1 is DateTime) {
if (!value1.isAtSameMomentAs(value2)) {
if (log) print("$value1 != $value2");
return false;
}
} else if (value1 != value2) {
if (log) print("$value1 != $value2");
return false;
}
}
return true;
}

int listToHashCode(List items) {
int result = 0;
for (final item in items) {
if (item is List) {
result += listToHashCode(item);
} else if (item is Map) {
result += mapToHashCode(item);
} else {
result += item.hashCode;
}
}
return result;
}

int mapToHashCode(Map input) {
int result = 0;
for (final entry in input.entries) {
result += entry.key.hashCode;
final value = entry.value;
if (value is List) {
result += listToHashCode(value);
} else if (value is Map) {
result += mapToHashCode(value);
} else {
result += value.hashCode;
}
}
return result;
}
62 changes: 17 additions & 45 deletions languages/dart/dart-client/lib/sse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import 'package:arri_client/errors.dart';
import 'package:arri_client/request.dart';
import 'package:http/http.dart' as http;

typedef SseHookOnData<T> = void Function(T data, EventSource<T> connection);
typedef SseHookOnMessage<T> = void Function(T data, EventSource<T> connection);
typedef SseHookOnError<T> = void Function(
ArriError error, EventSource<T> connection);
typedef SseHookOnConnectionError<T> = void Function(
ArriError error, EventSource<T> connection);
typedef SseHookOnOpen<T> = void Function(
http.StreamedResponse response, EventSource<T> connection);
typedef SseHookOnClose<T> = void Function(EventSource<T> connection);
Expand All @@ -23,11 +21,10 @@ EventSource<T> parsedArriSseRequest<T>(
FutureOr<Map<String, String>> Function()? headers,
Duration? retryDelay,
int? maxRetryCount,
SseHookOnData<T>? onData,
SseHookOnError<T>? onError,
SseHookOnConnectionError<T>? onConnectionError,
SseHookOnMessage<T>? onMessage,
SseHookOnOpen<T>? onOpen,
SseHookOnClose<T>? onClose,
SseHookOnError<T>? onError,
String? lastEventId,
String? clientVersion,
}) {
Expand All @@ -46,12 +43,11 @@ EventSource<T> parsedArriSseRequest<T>(
},
retryDelay: retryDelay ?? Duration.zero,
maxRetryCount: maxRetryCount,
onData: onData,
onError: onError,
onConnectionError: onConnectionError,
onClose: onClose,
onOpen: onOpen,
lastEventId: lastEventId,
onMessage: onMessage,
onOpen: onOpen,
onClose: onClose,
onError: onError,
);
}

Expand All @@ -71,9 +67,8 @@ class EventSource<T> {
bool _closedByClient = false;

// hooks
late final void Function(T data) _onData;
late final void Function(T data) _onMessage;
late final void Function(ArriError error) _onError;
late final void Function(ArriError error) _onConnectionError;
late final void Function(http.StreamedResponse response) _onOpen;
late final void Function() _onClose;

Expand All @@ -87,11 +82,10 @@ class EventSource<T> {
Duration retryDelay = Duration.zero,
int? maxRetryCount,
// hooks
SseHookOnData<T>? onData,
SseHookOnError<T>? onError,
SseHookOnConnectionError<T>? onConnectionError,
SseHookOnClose<T>? onClose,
SseHookOnMessage<T>? onMessage,
SseHookOnOpen<T>? onOpen,
SseHookOnClose<T>? onClose,
SseHookOnError<T>? onError,
this.lastEventId,
}) : _headers = headers,
_params = params,
Expand All @@ -100,18 +94,14 @@ class EventSource<T> {
this._httpClient = httpClient ?? http.Client();

// set hooks
_onData = (data) {
onData?.call(data, this);
_onMessage = (data) {
onMessage?.call(data, this);
_streamController?.add(data);
};
_onError = (err) {
onError?.call(err, this);
_streamController?.addError(err);
};
_onConnectionError = (err) {
onConnectionError?.call(err, this);
_streamController?.addError(err);
};
_onOpen = (response) {
onOpen?.call(response, this);
};
Expand Down Expand Up @@ -198,10 +188,7 @@ class EventSource<T> {
case SseRawEvent<T>():
break;
case SseMessageEvent<T>():
_onData(event.data);
break;
case SseErrorEvent<T>():
_onError(event.data);
_onMessage(event.data);
break;
case SseDoneEvent<T>():
close();
Expand Down Expand Up @@ -229,17 +216,17 @@ class EventSource<T> {
return;
}
if (err is ArriError) {
_onConnectionError.call(err);
_onError.call(err);
} else if (err is http.ClientException) {
_onConnectionError(
_onError(
ArriError(
code: 0,
message: err.message,
data: err,
),
);
} else {
_onConnectionError.call(
_onError.call(
ArriError(
code: 0,
message: "Unknown error connecting to $url",
Expand Down Expand Up @@ -339,8 +326,6 @@ sealed class SseEvent<TData> {
switch (sse.event) {
case "message":
return SseMessageEvent.fromRawSseEvent(sse, parser);
case "error":
return SseErrorEvent.fromRawSseEvent(sse);
case "done":
return SseDoneEvent.fromRawSseEvent(sse);
default:
Expand Down Expand Up @@ -393,19 +378,6 @@ class SseMessageEvent<TData> extends SseEvent<TData> {
}
}

class SseErrorEvent<TData> extends SseEvent<TData> {
final ArriError data;
const SseErrorEvent({super.id, super.event, required this.data});

factory SseErrorEvent.fromRawSseEvent(SseRawEvent event) {
return SseErrorEvent(
id: event.id,
event: event.event,
data: ArriError.fromString(event.data),
);
}
}

class SseDoneEvent<TData> extends SseEvent<TData> {
final String data = "";
const SseDoneEvent({super.id, super.event});
Expand Down
4 changes: 0 additions & 4 deletions languages/dart/dart-client/lib/utils.dart

This file was deleted.

2 changes: 1 addition & 1 deletion languages/dart/dart-client/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: arri_client
description: Client library needed for the code generated by the arri server library.
version: "0.49.1"
version: "0.51.0"
repository: https://github.com/modiimedia/arri
issue_tracker: https://github.com/modiimedia/arri/issues
environment:
Expand Down
Loading

0 comments on commit 46502c2

Please sign in to comment.