dadi / web

Web is a drop in front end for websites and web apps. Consumes data from DADI API and others
https://dadi.cloud/en/web/
Other
48 stars 16 forks source link

Dependency in maintenance #447

Closed jimlambie closed 5 years ago

jimlambie commented 5 years ago

The circular-json dependency reports it is in maintenance and a new module should be used in its place:

> circular-json@0.5.7 postinstall /dadi/sandbox/web/node_modules/circular-json
> echo ''; echo "\x1B[1mCircularJSON\x1B[0m is in \x1B[4mmaintenance only\x1B[0m, \x1B[1mflatted\x1B[0m is its successor."; echo ''

\x1B[1mCircularJSON\x1B[0m is in \x1B[4mmaintenance only\x1B[0m, \x1B[1mflatted\x1B[0m is its successor.
philip-hunt commented 5 years ago

The new dependancy package is called Flatted. While this contains the same function definitions, the functionality has changed and the response object is different. It now returns a stringified object wrapped in [] (see https://github.com/WebReflection/flatted/blob/master/index.js#L66).

Because the response object is a string, it would require some hacky code to manipulate it into a useable response.

Is it worth moving the original package functionality into web as a util?

jimlambie commented 5 years ago

@philip-hunt remind me where we use the current circular-json dependency, and I may be able to confirm. I believe circular-json returns the same sort of response, doesn't it? The idea is to not keep adding nested objects, and rather stop the tree building by adding a string to say "I'm not repeating myself"

philip-hunt commented 5 years ago

@jimlambie yes I believe that is correct, it's used just before we output a json response here: https://github.com/dadi/web/blob/master/dadi/lib/view/send.js#L19

Here's a comparison of the output formats for both libraries. Both are strings so it wouldn't make sense to try and convert the Flatted output to the original CircularJSON.

CircularJSON:

{ "result": "success", "message": "Cache cleared successfully" }

Flatted:

[{ "result": "1", "message": "2" },"success","Cache cleared successfully"]

jimlambie commented 5 years ago

Ah @philip-hunt I see what you mean... perhaps we need something simpler for this then - we've used https://github.com/moll/json-stringify-safe before with good results.

Should produce something like: {"a":"[Circular ~]"} which is closer to the circular-json response?

jimlambie commented 5 years ago

Closed by https://github.com/dadi/web/commit/84bbff3329a3242adac9a5333176d5ea600a35fe, thanks @philip-hunt