Get prettier to uglify certain json files - prettier

We're using prettier to format code and this plugs into a pre commit hook.
I want it to do that, but for certain json files, I'd like it to minify the json instead. I can do that externally, but well I would rather have something that's already plugged in.
{
"semi": false,
"singleQuote": true,
"overrides": [
{
"files": "src/**/*.json",
"options": {
"parser": "json-stringify"
}
},
{
"files": "src/path/to/folder/**/*.json",
"options": {
"parser": "json-minify"// Some parser perhaps?
}
}
]
}

Related

How do i format the headers field in step function api invoke

I am trying to execute a AWS api via step function. I need to pass the authorizationToken value in the header field.
{
"ApiEndpoint": "ccqk9ijm0h.execute-api.ap-southeast-2.amazonaws.com",
"Method": "POST",
"Headers": {
"authorizationToken.$": [
"$.InputToken"
]
},
"Stage": "test",
"Path": "/",
"RequestBody": {
"productType": [],
"xxx.$": "$.xxx",
"yyy.$": "$.yyy",
"zzz.$": "$.zzz"
},
"AuthType": "IAM_ROLE"
}
I am getting the following error -
The value for the field 'authorizationToken.$' must be a STRING that contains a JSONPath but was an ARRAY (at /States/GetDeclarations/Parameters)
This is the default syntax for the API invoke -
"Headers": {
"Header1": [
"HeaderValue1"
],
"Header2": [
"HeaderValue2",
"HeaderValue3"
]
}
When i modify this to
"Headers": {
"authorizationToken": [
"1234"
],
"Header2": [
"HeaderValue2",
"HeaderValue3"
]
}
It works fine.
I need to make the value of "authorizationToken" a variable that takes its value from the input.
My Input data looks like this
{
"xxx": "123",
"yyy": "123",
"zzz": "123",
"InputToken": "123",
"aaa": "123"
}
You need to use the States.Array Intrinsic Function as I've shown below. This allows you to inject an array into a node in your Parameters block. In this case, you just want a single item in the array, but you can include multiple items as well (e.g., States.Array($.item1,$.item2,$.item3)).
Check out the other Intrinsic Functions as well, as they are handy for overcoming challenges like this.
{
"ApiEndpoint": "ccqk9ijm0h.execute-api.ap-southeast-2.amazonaws.com",
"Method": "POST",
"Headers": {
"authorizationToken.$": "States.Array($.InputToken)"
},
"Stage": "test",
"Path": "/",
"RequestBody": {
"productType": [],
"xxx.$": "$.xxx",
"yyy.$": "$.yyy",
"zzz.$": "$.zzz"
},
"AuthType": "IAM_ROLE"
}

How can I verify if a typescript file contains decorators with a regex? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I would like to check if a typescript file contains a decorated function or class without compiling it. Is there a regex or something equally fast that can detect if a typescript file contains a decorated class or function?
You can parse the file with a typescript parser. This will generate an AST (Abstract Syntax Tree) for you. From the resulting AST you can check if any decorators have been used in the file.
To go further into this, you can use the #typescript-eslint/parser parser for this, and its parse method.
// requires ES6+
import { parse } from '#typescript-eslint/parser';
const code = '#Component({key: "value"}) class Hello {}';
const ast = parse(code);
console.log(JSON.stringify(ast));
This returns you the following AST:
{
"type": "Program",
"body": [
{
"type": "ClassDeclaration",
"id": { "type": "Identifier", "name": "Hello" },
"body": { "type": "ClassBody", "body": [] },
"superClass": null,
"decorators": [
{
"type": "Decorator",
"expression": {
"type": "CallExpression",
"callee": { "type": "Identifier", "name": "Component" },
"arguments": [
{
"type": "ObjectExpression",
"properties": [
{
"type": "Property",
"key": { "type": "Identifier", "name": "key" },
"value": {
"type": "Literal",
"value": "value",
"raw": "\"value\""
},
"computed": false,
"method": false,
"shorthand": false,
"kind": "init"
}
]
}
],
"optional": false
}
}
]
}
],
"sourceType": "script"
}
The parse function also has multiple options, e.g. you can turn the range option to find out where exactly in the code the decorator is: parse(code, {range: true})
As suggested already, you could examine the AST. Here is an example of how you could do it: link. See the console for the two decorators identified.
The babel based visitor
export default function (babel) {
const { types: t } = babel;
return {
visitor: {
Identifier(path) {
if(t.isDecorator(path.parent)) {
console.log(path.node.name + " is a decorator")
}
}
}
};
}

How to skip particular set of test cases in a collection in terminal using newman?

I am having a postman collection which consists of request and test cases for each requests. I have two test case for each request. one for validating status code and other for validating response time. I need to execute status code test case frequently and response time test case results occasionally.How to achieve it without modifying the collection for every run and is it achievable in providing any option in terminal?
collection.json
{
"name": "Metadata",
"item": [
{
"name": "info",
"event": [
{
"listen": "test",
"script": {
"id": "32cf67e7-5d42-4231-86fe-e7fffa32c855",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"pm.test(\"Response time is less than 300ms\", function () {",
" pm.expect(pm.response.responseTime).to.be.below(300);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{tokenAdmin}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/api/m0/metadata/info",
"host": [
"{{url}}"
],
"path": [
"api",
"m0",
"metadata",
"info"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
}
For a very basic flow, you can use moment to check which day it currently is and if that matches the condition, it will run the responseTime test.
let moment = require('moment'),
date = moment().format('dddd');
// Runs on each request
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// Only runs on a Friday
if (date === 'Friday') {
pm.test("Response time is less than 1000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(1000);
});
}
Moment has lots of different options available to you and might work if you want to only run that check at the end of the sprint or on a given day.

Cloud API Vision Results not appearing

I'm making a request with the google vision api that appears to have worked, I get an operation number back. The problem I am having is the I am not sure how to interpret the results and nothing appeared in the output folder after running the script.
This is the script I ran
https://vision.googleapis.com/v1/files:asyncBatchAnnotate
{
"requests":[
{
"inputConfig": {
"gcsSource": {
"uri": "gs://somebucket/1.pdf"
},
"mimeType": "application/pdf"
},
"features": [
{
"type": "DOCUMENT_TEXT_DETECTION"
}
],
"outputConfig": {
"gcsDestination": {
"uri": "gs://somebucket/output/"
},
"batchSize": 1
}
}
]
}
This returns back
{
"name": "operations/8b7534d4b21b825e"
}
and when I do a lookup on the operation I get this
https://vision.googleapis.com/v1/operations/8b7534d4b21b825e
{
"name": "operations/8b7534d4b21b825e",
"metadata": {
"#type": "type.googleapis.com/google.cloud.vision.v1.OperationMetadata",
"state": "CREATED",
"createTime": "2019-01-09T21:08:57.339363096Z",
"updateTime": "2019-01-09T21:08:57.339363096Z"
}
}
However the output folder is completely empty and I am not sure what to make of the state created.
According to this answer by a Google engineer, latency in the order of minutes (~10 minutes) is somewhat expected. I’ve done some tests myself, with small files and at moments delay can be up to 25 minutes, though in some cases it is much less.
When Vision API is done processing your request, you should get a response like the one below, for the get method:
{
"name": "operations/XXXxxxxXXXX",
"metadata": {
"#type": "type.googleapis.com/google.cloud.vision.v1.OperationMetadata",
"state": "DONE",
"createTime": "2019-01-09T23:08:37.312889645Z",
"updateTime": "2019-01-09T23:08:59.169306747Z"
},
"done": true,
"response": {
"#type": "type.googleapis.com/google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse",
"responses": [
{
"outputConfig": {
"gcsDestination": {
"uri": "gs://somebucket/output/"
}
}
}
]
}
}

How do you handle large relationship data attributes and compound documents?

If an article has several comments (think thousands over time). Should data.relationships.comments return with a limit?
{
"data": [
{
"type": "articles",
"id": 1,
"attributes": {
"title": "Some title",
},
"relationships": {
"comments": {
"links": {
"related": "https://www.foo.com/api/v1/articles/1/comments"
},
"data": [
{ "type": "comment", "id": "1" }
...
{ "type": "comment", "id": "2000" }
]
}
}
}
],
"included": [
{
"type": "comments",
"id": 1,
"attributes": {
"body": "Lorem ipusm",
}
},
.....
{
"type": "comments",
"id": 2000,
"attributes": {
"body": "Lorem ipusm",
}
},
]
}
This starts to feel concerning, when you think of compound documents (http://jsonapi.org/format/#document-compound-documents). Which means, the included section will list all comments as well, making the JSON payload quite large.
If you want to limit the number of records you get at a time from a long list use pagination (JSON API spec).
I would load the comments separately with store.query (ember docs), like so -
store.query('comments', { author_id: <author_id>, page: 3 });
which will return the relevant subset of comments.
If you don't initially want to make two requests per author, you could include the first 'page' in the authors request as you're doing now.
You may also want to look into an addon like Ember Infinity (untested), which will provide an infinite scrolling list and automatically make pagination requests.