GithubHelp home page GithubHelp logo

dart-neats's Introduction

Dart Neats Github Actions

A collection of a small neat packages for dart.

Disclaimer: This is not an officially supported Google product.

This repository is meant as a playground where small neat packages are cultivated. If package grows too large and complex and needs a dedicated issue tracker it should be moved to a dedicated repository.

Each folder in this repository contains a neat pub package. This project aims to use a separate package whenever it makes sense to have an independent major version. This often means splitting functionality into separate packages, which can be reused independently.

Package Description Version
acyclic_steps An explicit acyclic step dependency framework with concurrent evaluation and dependency injection. pub package
canonical_json Encoder and decoder for a canonical JSON format, useful when cryptographically hashing or signing JSON objects. pub package
chunked_stream Utilities for working with chunked streams, such as byte streams which is often given as a stream of byte chunks with type Stream<List<int>>. pub package
http_methods List of all HTTP methods registered with IANA as list of strings, and metadata such as whether a method idempotent. pub package
neat_cache A neat cache abstraction for wrapping in-memory or redis caches. pub package
neat_periodic_task Auxiliary classes for reliably running a periodic task in a long-running process such as web-server. pub package
pem PEM encoding/decoding of textual keys following RFC 7468, supporting both lax/strict-mode, and certificates chains of concatenated PEM blocks. pub package
retry Utility for wrapping an asynchronous function in automatic retry logic with exponential back-off, useful when making requests over network. pub package
safe_url_check Check if an untrusted URL is broken, without allowing connections to a private IP address. pub package
sanitize_html Function for sanitizing HTML to prevent XSS by restrict elements and attributes to a safe subset of allowed values. pub package
slugid A URL-safe base64 encoding for UUIDv4 stripped of padding. Useful when embedding short random UUIDs in URLs. pub package
vendor Utility for vendoring packages into a project and rewriting import/export statements. pub package

Repository Management

The root pubspec.yaml is only intended to lock the development dependencies for repository management. When adding new packages or changing mono_repo.yaml or mono_pkg.yaml in a package, make sure to run the following commands to update travis configuration.

  • pub get
  • pub run mono_repo travis

Contributing

We love patches and contributions, please refer to CONTRIBUTING.md for technicalities on CLA and community guidelines. As this project aims to build neat packages using other neat packages we might also accept proposals for new neat packages, though it's often easier to publish independently.

License

Unless stated otherwise contents in this repository is licensed under Apache License 2.0, see LICENSE.

dart-neats's People

Contributors

asartalo avatar bishop19 avatar bivens-dev avatar cachapa avatar dependabot[bot] avatar devoncarew avatar ditman avatar felangel avatar guilhem-martin avatar isoos avatar jason-cooke avatar jonasfj avatar kevmoo avatar natebosch avatar parlough avatar polina-c avatar sameerkash avatar sigurdm avatar simolus3 avatar srawlins avatar sushantchandla avatar szakarias avatar walnutdust avatar wapa5pow avatar xvrh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart-neats's Issues

shelf_router_generator fails to generate route when project has extension on String

If I define extension on String then route is failed to be generated with message "The shelf_router.Route annotation can only be used on shelf request handlers accept a shelf.Request parameter and/or a shelf.Request parameter and all string parameters in the route, the "<param_name>" parameter is not of type string"

shelf_router_generator: 0.7.2+2

unable to use server to serve a flutter web app

how would I go about serving my flutter app using shelf router? currently I am using it as my backend but when I put app.mount('/app/', createStaticHandler('public/web')); it only shows a blank page, when i go to check the source the javascript information is in there, is shelf_router unable to serve up flutter applications? thanks

Bug in ChunkedStreamIterator.substream

When you call ChunkedStreamIterator.substream, if the first time the wakeup function runs it manages to get size elements already, it resets _wakeup() to null.

However, since the stream controller runs _subscription.resume when something subscribes to it, _subscription tries to read in the next bit of data and finds a null wakeup but tries calling it anyways

The short test case below fails:

  test('substream ends with first chunk (fails)', () async {
    final s = ChunkedStreamIterator(_chunkedStream([
      ['a', 'b', 'c'],
      ['1', '2'],
    ]));
    expect(await s.read(1), equals(['a']));
    final i = s.substream(2);
    print(await i.length);
  });

Is there a plan for null-safety on yaml_edit?

  • Is there a plan? Would love to use it.
  • I can also help if someone can point me in the right direction. I started doing this on a fork on my own but I got stuck on deepEqualsMap() on equality.dart and didn't know how to deal with mismatching types. I'm fairly new to Dart and generic programming in general.

Default behavior of (no) retryIf

Hello,

according to the v3.0.0 changelog, the behavior if we don't input any retryIf is to have any exception being considered for the retry.

Does this means that this code snippet:

final response = await retry(
  // Make a GET request
  () => http.get('https://google.com').timeout(Duration(seconds: 5)),
  // No explicit retry 
);

is the same as:

final response = await retry(
  // Make a GET request
  () => http.get('https://google.com').timeout(Duration(seconds: 5)),
  // Retry on Exception
  retryIf: (e) => e is Exception,
);

And also meaning that the call will be retried if:

  • it didn't answer within 5 seconds
  • it threw an(y) exception

thanks.

Middleware usage

Is there a way to use Middleware with this package?

And better to annotate a Route with some middleware we want to use for this route ?

shelf_router_generator is failing to build with dart 2.14.0-edge

➜  dart-services git:(master) ✗ dart --version                                          
Dart SDK version: 2.14.0-edge.a527411e5100a0a4f48c4009087a1b988aa784af (be) (Fri May 14 15:47:38 2021 +0000) on "macos_x64"
➜  dart-services git:(master) ✗ dart run build_runner build --delete-conflicting-outputs --verbose
Precompiling executable... (13.1s)
Precompiled build_runner:build_runner.
[INFO] Entrypoint:Generating build script...
[INFO] Entrypoint:Generating build script completed, took 438ms

[WARNING] Bootstrap:
Deleted previous snapshot due to missing asset graph.
[INFO] Bootstrap:Creating build script snapshot......
[FINE] Bootstrap:stdout: Info: Compiling without sound null safety
[INFO] Bootstrap:Creating build script snapshot... completed, took 13.1s

[INFO] Bootstrap:There was output on stdout while compiling the build script snapshot, run with `--verbose` to see it (you will need to run a `clean` first to re-snapshot).

[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Building new asset graph...
[INFO] BuildDefinition:Building new asset graph completed, took 689ms

[INFO] BuildDefinition:Checking for unexpected pre-existing outputs....
[INFO] BuildDefinition:Checking for unexpected pre-existing outputs. completed, took 1ms

[INFO] Build:Running build...
[WARNING] shelf_router_generator:shelf_router on bin/server_cloud_run.dart:
Your current `analyzer` version may not fully support your current SDK version.

Please try upgrading to the latest `analyzer` by running `flutter packages upgrade`.

Analyzer language version: 2.12.0
SDK language version: 2.14.0

If you are getting this message and have the latest analyzer please file
an issue at https://github.com/dart-lang/sdk/issues/new with the title
"No published analyzer available for language version 2.14.0".
Please search the issue tracker first and thumbs up and/or subscribe to
existing issues if present to avoid duplicates.

[INFO] build_resolvers:Generating SDK summary...
[SEVERE] shelf_router_generator:shelf_router on bin/server_cloud_run.dart:

Bad state: Unexpected diagnostics:
/Users/brettmorgan/flutter/bin/cache/dart-sdk/lib/core/int.dart:117:18 - Operator declarations must be preceded by the keyword 'operator'.
/Users/brettmorgan/flutter/bin/cache/dart-sdk/lib/core/int.dart:117:18 - A function body must be provided.
/Users/brettmorgan/flutter/bin/cache/dart-sdk/lib/core/int.dart:117:16 - Methods must have an explicit list of parameters.
package:analyzer/dart/sdk/build_sdk_summary.dart 212:7   _Builder._parse
package:analyzer/dart/sdk/build_sdk_summary.dart 147:36  _Builder._addLibrary
package:analyzer/dart/sdk/build_sdk_summary.dart 143:9   _Builder._addLibrary
package:analyzer/dart/sdk/build_sdk_summary.dart 143:9   _Builder._addLibrary
package:analyzer/dart/sdk/build_sdk_summary.dart 143:9   _Builder._addLibrary
dart:core                                                List.forEach
package:analyzer/dart/sdk/build_sdk_summary.dart 101:20  _Builder.build
package:analyzer/dart/sdk/build_sdk_summary.dart 75:5    buildSdkSummary
package:build_resolvers/src/resolver.dart 389:36         _defaultSdkSummaryGenerator
package:build_resolvers/src/resolver.dart 327:11         AnalyzerResolvers._ensureInitialized.<fn>
package:build_resolvers/src/resolver.dart 334:5          AnalyzerResolvers.get
package:build                                            _DelayedResolver.isLibrary
package:source_gen/src/builder.dart 75:10                _Builder.build

Error in README example

README says:

var app = Router();
var server = await io.serve(app.handler, 'localhost', 8080);

but Router does not have a handler, and i believe it should say:

var app = Router();
var server = await io.serve(app, 'localhost', 8080);

This works, but Router is not a Handler, so not sure why it works??

Retry: Retry If Retruned Object Meets a Condition

Hi,

I'd like to retry if the returned object meets a condition.

Example:

      final response = await retry(
      // Make a GET request
      () => http.get('https://google.com'),
      // Retry on Exception
      retryIf: (e) => e is SocketException,
      retryIfReturnedObject: (o) => o == "retry-please"
  );

is this possible?
Thanks

Reponse class in route handler

Currently router handlers only receive Request class as argument and we have to import shelf package everywhere to send a response. It would be great If route handlers are also provided with Response class as argument

//Current 
router = Router();
router.get('/', (Request request) {
    return Response.ok('Home Page');
  });

// Proposed
router.get('/', (Request request, Response response) {
    return response.ok('Home Page');
  });

Can i use shelf_static and shelf_web_socket with shelf_router?

Can i use shelf_static and shelf_web_socket with shelf_router?

Maybe you could add an example for this?

I tried the following without success:

  var router = Router();

  router.mount('/', createFileHandler('web/index.html'));

  router.mount('/web/', createStaticHandler('web'));

  router.mount('/ws/', webSocketHandler((webSocket) {
    webSocket.stream.listen((message) {
      webSocket.sink.add("echo $message");
    });
  }));

  final server = await io.serve(router, address.address, port);

yaml_edit: unable to update empty value nodes

Unable to update an empty node

Sample Code

void main() {
  final doc = YamlEditor('''
dependencies:
''');
  doc.update(['dependencies'], {'test': '^1.14.4'});

  print(doc);
}

Stack trace

Unhandled exception:
RangeError: Invalid value: Not greater than or equal to 0: -1
#0      RangeError.checkNotNegative (dart:core/errors.dart:376:20)
#1      new SourceEdit._ (package:yaml_edit/src/source_edit.dart:50:16)
#2      new SourceEdit (package:yaml_edit/src/source_edit.dart:43:18)
#3      _replaceInBlockMap (package:yaml_edit/src/map_mutations.dart:172:10)
#4      updateInMap (package:yaml_edit/src/map_mutations.dart:43:14)
#5      YamlEditor.update (package:yaml_edit/src/editor.dart:278:27)
#6      main (file:///home/garett/Development/dart-neats/yaml_edit/example/example.dart:7:7)
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Using `router.get` should add a default handler for `router.head`

We should add default handlers for HEAD when we have handlers for GET.
Probably we can just serve the response from the GET handler if there is no other handler registered that handles the HEAD request.

// when writing
router.get('/', myHandler);
// we should implicitly add:
router.head('/', myHandler); // if and only if, no other registered handler matches the HEAD request.

@isoos, does this sound like a reasonable solution to you? I think this might solve some problems for us in pub.dev.

Trailing comma in mount force us to use trailing comma eveytime for root url

  • Explain the issue,
    I can't send GET requests to /book but I can send GET requests to /book/

I think the trailing comma in mount is the issue

  • Using bullet points!
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';

const _hostname = 'localhost';
final _port = 8080;

void main(List<String> args) async {
  
  final route1 = Router();
  route1.get('/', (Request request) {
    return Response.ok('home');
  });

  final route = Router();
  route.mount('/book/', route1);

  final server = await IOServer.bind(_hostname, _port);
  server.mount(route);
}

I come up with a simple example that can demonstrate this issue easily.
Thank you

How to handle 404 page by shelf_router?

As the example code of shelf_router, there are two routers. If we try to access other router, server will return a error: Internal Server Error.
How to handle 404 page by shelf_router ?

import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

var app = Router();

app.get('/hello', (Request request) {
  return Response.ok('hello-world');
});

app.get('/user/<user>', (Request request, String user) {
  return Response.ok('hello $user');
});

var server = await io.serve(app.handler, 'localhost', 8080);

[sanitize_html] <font> tag hides text

When I use this code, sanitizeHtml removes both font tags and all contents inside fonts.
printed string is <p dir="ltr"></p>

var detail = "<p dir=\"ltr\" style=\"margin: 0in 0in 0pt;\">" +
      "<font color=\"#000000\">" +
      "<font face=\"Calibri\">" +
      "<font size=\"3\">This is detail content.</font></font></font></p>" ;
     
print(sanitizeHtml(detail)); 

Route will download response if umlaut is in response

If you have an umlaut (ö,ä,ü) in your response, the response won't be displayed in the browser. Instead it'll be downloaded as a file.

import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf_io.dart' as io;


class Api {

  Handler get handler {
    final router = Router();

    router.get('/without/<name>/<yas>', (Request req) {
      var name = params(req, 'name');
      var yas = params(req, 'yas');
      return Response.ok('I am a normal response $name $yas');
    });

    router.get('/with/<name>/<yas>', (Request req) {
      var name = params(req, 'name');
      var yas = params(req, 'yas');
      return Response.ok('I am a file ü $name $yas');
    });

    return router.handler;
  }
}

void main() async {
  final service = Api();
  final server = await io.serve(service.handler, 'localhost', 8080);
  print('Server running on localhost:${server.port}');
}

Update Route.mount to accept handler

To add a middleware on the router, you need a pipeline which is an type of handler. But currently you can only use routers for a mount: The shelf_router.Route.mount annotation can only be used on a getter that returns shelf_router.Router (

'The shelf_router.Route.mount annotation can only be used on a '
).

It would be awesome if

const _routerType = g.TypeChecker.fromRuntime(shelf_router.Router);
accepts Handler, like the method in shelf_router:
void mount(String prefix, Handler handler) {

i can't use Handler from Router()

when i use shelf-router package , i need to use Router().handler but i can't the error 'handler is not defined in Router()'

//Example

var app = Router();
app.handler ; error in this line

can't access boundary or do not know where it is

I am trying to get a file from the client server side, I have been piecing together code but cannot request.headers.contentType.paramers['boundary]; I know it is found in the core which shelf_router is built upon, is there any way I can access this information going about it a different way? I am able to get the data using this code below

  var dataBytes = <int>[];

  await for (var data in req.read()) {
    dataBytes.addAll(data);
  }

but unsure how to use mime to convert this to it correct type, i would use another package but I already built a ton upon shelf_router so I would like to stick with it, thanks

How to catch the last exception at maxAttempts?

Hello,

I'd like to know how to handle the case when an exception is thrown for the last attempt.

With maxAttempts set to, say, 3, let's consider the following responses:

  1. Exception -> retry
  2. Exception -> retry
  3. Exception -> give up

Do I have a way to catch the exception only if this is the last attempt? Should I surround the whole retry part with a try/catch?

try {
  final response = await retry(
  // Make a GET request
  () => http.get('https://google.com').timeout(Duration(seconds: 5)),
  // Retry on Exception
  retryIf: (e) => true,
  );
}
catch(e,st) {
  // do something with $e
}

Thanks.

Nested `ChunkedStreamIterator` propagates pausing

If we were to call ChunkedStreamIterator on a ChunkedStreamIterator.substream, the pausing propagates, leading to more pauses than expected on the parent ChunkStreamIterator.

  test('pause propagation', () async {
    final s = ChunkedStreamIterator(_chunkedStream([
      ['a', 'b', 'c'],
      ['1'],
      ['2'],
    ]));
    expect(await s.read(1), equals(['a']));
    final sub = s.substream(3);
    final c = ChunkedStreamIterator(sub);
    expect(await c.read(3), ['b', 'c', '1']);  /// Line (a)
    expect(await c.read(1), []); /// This line makes no difference to the result.
    expect(await s.read(1), equals(['2']));
  });

I think the following program flow is what causes the error:

  1. In Line (a), the parent ChunkedStreamIterator, s, pauses after delivering the ['1'] block.
  2. At the same time, since c has delivered its full length, c will be reset.
  3. reset calls _subscription.pause, which calls pause in the substream controller for sub.
  4. The controller for sub pauses the original stream subscription in s.

The end result of this is that s's stream subscription is paused multiple times, which causes future reads on s to fail because the subscription still remains paused.

Request: way to list registered routes

Use case

Whenever I start the server, I'd like to log the list of registered routes. They tend not to change when I run my app, we can think of it as constant. This would allow me to print debug info during development and a way to verify changes in endpoints a CI script can use to verify changes post-deploy.

Current situation

Currently, Router has no way to allow access to added/mounted routes.

@sealed
class Router {
  final List<RouterEntry> _routes = [];

Proposal

A method or public function that can return an immutable list of RouterEntries. Something along these lines:

UnmodifiableListView<PrintableRouterEntry> getRoutes(Router router) {
  return UnmodifiableListView(router._routes.map((r) => PrintableRouterEntry(r)));
}

class PrintableRouterEntry {
  /* ... */
}

Exception while closing redis connection

Error: Bad state: StreamSink is bound to a stream
at _StreamSinkImpl.close (native)
at _Socket.close (native)
at RespClient.close (package:neat_cache/src/providers/resp.dart:224)
at RedisCacheProvider._withResp (package:neat_cache/src/providers/redis.dart:138)
at StackZoneSpecification._registerUnaryCallback.<fn> (unknown location)

Move ChunkStreamIterator to package:async

Let's propose ChunkStreamIterator for package:async.

TODOs:

  • Document what happens when calling read before previous call is done (pretty sure it's a StateError, let's also test this).
  • Consider adding an optional makeList function or listBuilder abstraction in place of the extension for ChunkedStreamIteratorByteStreamExt

Null Safety Migration?

Is any plan to move this lib to null safety?
All its dependencies are already moved.

Thank you

wrapAsYamlNode should maybe call .toJson()

I think the idea with wrapAsYamlNode was that you could pass it any value that json.encode (from dart:convert) would accept, and then this would wrap it as a YamlNode.

However, reading docs for jsonEncode I realize that unless some toEncodable function is given, json.encode will default to calling .toJson() on objects. This is in turn used by package:json_serializable which generates code that helps users add a .toJson() on their custom objects, making it possible to pass these objects to json.encode.

I wonder if we should consider calling .toJson() instead of throwing:

Invalid argument (value): Not a valid scalar type!: Instance of MyCustomObject
  package:yaml_edit/src/utils.dart 51:3   assertValidScalar
  package:yaml_edit/src/wrap.dart 73:5    wrapAsYamlNode
  package:yaml_edit/src/wrap.dart 126:28  new YamlMapWrap
  package:yaml_edit/src/wrap.dart 68:12   wrapAsYamlNode
  package:yaml_edit/src/wrap.dart 126:28  new YamlMapWrap
  package:yaml_edit/src/wrap.dart 68:12   wrapAsYamlNode

If we do this, we should certainly document it, and probably give an example. I doubt it is possible to gracefully test if the object has a .toJson() method, even accessing the property like object.toJson is Function is liable to throw and complain that no getter exists for toJson (if the method isn't present).

EDIT: It seems json.encode just catches all errors / exceptions when calling .toJson and then rethrows them as an exception saying: Converting object to an encodable object failed: Instance of MyCustomObject.

We could also consider adding a toEncodable function as an optional parameter similar to jsonEncode.

@walnutdust, any thoughts?

Error with route that is not found - read method can only be called once on a shelf.Request/shelf.Response Object

When using the router, for items which cannot be found an error is being produced by default.

The default handler simply returns the same response every time it is called, meaning that the second time it is returned, it throws an error.

This is the line in question:

static Response _defaultNotFound(Request request) => routeNotFound;

and

Router({Handler notFoundHandler = _defaultNotFound})
    : _notFoundHandler = notFoundHandler;

Mounts should not require trailing slashes

  • When using the mount function a trailing slash is required.
  • This makes it impossible to have a mounted route that does not require that a tailing slash be required
  • In example below the URL "/product" would result in a 404
  • "/product/" would return the expected result
void main(List<String> args) async {
  load();

  var router = Router();

  router.mount('/auth/', AuthRoutes().router);
  router.mount('/product/', ProductRoutes().router);

  // Final route to return a not found
  router.all('/<.*>', (request) => shelf.Response.notFound(''));

  var handler = const shelf.Pipeline()
    .addMiddleware(shelf.logRequests())
    .addMiddleware(shelf.createMiddleware(requestHandler: AuthManager.handle))
    .addMiddleware(shelf.createMiddleware(requestHandler: ProductController.SecureMiddleware))
    .addHandler(router.handler);

  await io.serve(handler, 'localhost', int.parse(env['PORT'])).then((server) {
    print('Server running on port ${server.port}');
  });

}

class ProductRoutes {

  static FutureOr<Response> middleware(Request request) async {
    print("ProductRoutes Middleware");
    return null;
  }

  Router get router {
    final router = Router();

    var c = ProductController();

    router.get('/', c.GetList);
    router.get('/<product_id>', c.GetById);

    return router;
  }

}

shelf_router_generator: upgrade dependencies

Current constraints block its use on pub site:

Because every version of shelf_router_generator depends on analyzer ^0.35.0 and pana 0.12.16 depends on analyzer ^0.36.0, shelf_router_generator is incompatible with pana 0.12.16.
So, because pub_dartlang_org depends on both pana 0.12.16 and shelf_router_generator ^0.7.0+1, version solving failed.

Change default sleep timer to maximum 30 seconds.

Refer to the documentation saying that the sleep time has been fixed. Is that possible to customize this sleep time and make it to maximum only 30000 ms (30 seconds) when going up to 10 or 15 attempts? Thank you.

////

Defaults to 8 attempts, sleeping as following after 1st, 2nd, 3rd, ..., 7th attempt:

400 ms +/- 25%
800 ms +/- 25%
1600 ms +/- 25%
3200 ms +/- 25%
6400 ms +/- 25%
12800 ms +/- 25%
25600 ms +/- 25%

////

yaml_edit issues with empty maps in block style

Example

void main() {
  test('block problems', () {
    final e = YamlEditor('');
    e.update(
      [],
      wrapAsYamlNode(
        {'key': {}},
        collectionStyle: CollectionStyle.BLOCK,
      ),
    );
    return e.toString();
  });
}

Causes:

  Assertion failed: (package:yaml_edit) Failed to produce valid YAML after modification.

  # YAML before edit:
  > 
  
  # YAML after edit:
  > key:
  > {}
  
  Please file an issue at:
  https://github.com/google/dart-neats/issues/new?labels=pkg%3Ayaml_edit%2C+pending-triage&template=yaml_edit.md
  
  package:yaml_edit/src/editor.dart 585:7   YamlEditor._performEdit
  package:yaml_edit/src/editor.dart 258:14  YamlEditor.update

Expected out:

key: {}

Block style should be used as far as possible.. but it's clearly not possible to use block style for encoding the empty map.

Alternatively, we should do:

key:
  {}

This would also be acceptable.

/cc @walnutdust

flutter_test is no longer compatible with pem

  • flutter_test is no longer compatible with pem, since flutter_test requires petitparser ^3.0.0, and pem depends on petitparser ^2.1.1.
  • I'm currently using the latest stable version of the Flutter SDK: Flutter 1.17.5

Split stream using a delimiter?

Is it possible to split an incoming stream by using a delimiter?

I have a stream of bytes I want to read that are exactly 154 bytes long, but due to BLE limitations are transmitted in 7 chunks of 20 and 1 chunk of 14.

Sometimes when I connect to the data stream, the buffered information doesn't start reading the information from the start of the packet, and will instead split the packet and overflow.

Eg. (Instead of 7 * 20 + 1 * 14, I'll get 3 * 20 + 1 * 14 + 4 * 20)

Example code:

StreamSubscription<List<int>> data;
ChunkedStreamIterator<int> dataChunked;
 ...
if (c.uuid == new Guid("0000ffe1-0000-1000-8000-00805f9b34fb")) {
          await c.setNotifyValue(true);
          dataChunked = ChunkedStreamIterator(c.value);
          //Also works, dataChunked = ChunkedStreamIterator(bufferChunkedStream(c.value, bufferSize: 154));
      while (true) {
            var data = await dataChunked.read(154); // read whole packet
            if (data.length < 0) {
              print('End of file reached');
              break;
            }
            parseData(data); //Splits data into sublists
            setState(() {
              buffer = data;
              count++;
            });
      }
} else {print("Nope"); }

Only use self-closing tags for void-elements

This is likely the cause of: dart-lang/pub-dev#2405

For a list of void-element see: https://www.w3.org/TR/html5/syntax.html#void-elements

In particular:

Tags are used to delimit the start and end of elements in the markup. Raw text, escapable raw text, and normal elements have a start tag to indicate where they begin, and an end tag to indicate where they end. The start and end tags of certain normal elements can be omitted, as described below in the section on [[#optional tags]]. Those that cannot be omitted must not be omitted. Void elements only have a start tag; end tags must not be specified for void elements. Foreign elements must either have a start tag and an end tag, or a start tag that is marked as self-closing, in which case they must not have an end tag.

It's clear that void-elements cannot have closing tags, but that for all other tags it is better to have <b></b> than <b/> as the latter is not allowed.

Unable to mount multiple handlers to the same prefix

This was originally posted as an issue with shelf, but I guess this is the right place for this:

Say that I have two services (an authentication service and a profiles service, in my case) and an API service that is meant to bind it all together into a final handler. If I want to prefix the two services with an /api' prefix, by mounting both to /api/ in the API service, only the first handler will be accessible when running the server.

I have tested that everything works, otherwise, by mounting the two services to different prefixes, so the issue seems to lie in the fact that the mounts are both to the same prefix...

This seems like a bug to me, as it is normal practice in libraries like express, which shelf seems to emulate...

Also, when I remap the authentication service to / and keep the profiles service at /api/, the latter will only work if it is mapped before the former. Very strange behavior, if you ask me....

class AuthenticationService {
  AuthenticationService();

  Handler get handler {
    final router = Router();

    /* Various handlers mapped to /login, /register etc */

    return router;
  }
}

class ProfileService {
  ProfileService();

  Handler get handler {
    final router = Router();

    /* Various handlers, all mapped to /profile, but with different methods */

    return router;
  }
}

class ApiService {
  Handler get handler {
    final router = Router();

    final authenticationService = AuthenticationService();
    final profileService = ProfileService();

    router.mount('/api/', profileService.handler); // Only this will work. If I change the order, it is always the first mount that works....
    router.mount('/api/', authenticationService.handler);

    return router;
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.