initial update
This commit is contained in:
21
node_modules/@apollo/utils.printwithreducedwhitespace/LICENSE
generated
vendored
Normal file
21
node_modules/@apollo/utils.printwithreducedwhitespace/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
20
node_modules/@apollo/utils.printwithreducedwhitespace/README.md
generated
vendored
Normal file
20
node_modules/@apollo/utils.printwithreducedwhitespace/README.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# printWithReducedWhitespace
|
||||
|
||||
Prints a GraphQL AST with a minimal amount of whitespace. Consider using the
|
||||
[`stripIgnoredCharacters`](https://github.com/graphql/graphql-js/blob/e9a81f2ba9020ec5fd0f67f5553ccabe392e95e8/src/utilities/stripIgnoredCharacters.ts) function from `graphql` instead of this function.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { printWithReducedWhitespace } from "@apollo/utils.operationregistrysignature";
|
||||
|
||||
const signature = operationRegistrySignature(
|
||||
parse(`#graphql
|
||||
query Foo {
|
||||
bar
|
||||
}
|
||||
`),
|
||||
"Foo",
|
||||
{ preserveStringAndNumericLiterals: true },
|
||||
);
|
||||
```
|
||||
3
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.d.ts
generated
vendored
Normal file
3
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { type DocumentNode } from "graphql";
|
||||
export declare function printWithReducedWhitespace(ast: DocumentNode): string;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.d.ts.map
generated
vendored
Normal file
1
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAwB,MAAM,SAAS,CAAC;AAKhF,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CA2BpE"}
|
||||
23
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.js
generated
vendored
Normal file
23
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.printWithReducedWhitespace = void 0;
|
||||
const graphql_1 = require("graphql");
|
||||
function printWithReducedWhitespace(ast) {
|
||||
const sanitizedAST = (0, graphql_1.visit)(ast, {
|
||||
StringValue(node) {
|
||||
return {
|
||||
...node,
|
||||
value: Buffer.from(node.value, "utf8").toString("hex"),
|
||||
block: false,
|
||||
};
|
||||
},
|
||||
});
|
||||
const withWhitespace = (0, graphql_1.print)(sanitizedAST);
|
||||
const minimizedButStillHex = withWhitespace
|
||||
.replace(/\s+/g, " ")
|
||||
.replace(/([^_a-zA-Z0-9]) /g, (_, c) => c)
|
||||
.replace(/ ([^_a-zA-Z0-9])/g, (_, c) => c);
|
||||
return minimizedButStillHex.replace(/"([a-f0-9]+)"/g, (_, hex) => JSON.stringify(Buffer.from(hex, "hex").toString("utf8")));
|
||||
}
|
||||
exports.printWithReducedWhitespace = printWithReducedWhitespace;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/utils.printwithreducedwhitespace/dist/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAKhF,SAAgB,0BAA0B,CAAC,GAAiB;IAU1D,MAAM,YAAY,GAAG,IAAA,eAAK,EAAC,GAAG,EAAE;QAC9B,WAAW,CAAC,IAAqB;YAC/B,OAAO;gBACL,GAAG,IAAI;gBACP,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACtD,KAAK,EAAE,KAAK;aACb,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IACH,MAAM,cAAc,GAAG,IAAA,eAAK,EAAC,YAAY,CAAC,CAAC;IAC3C,MAAM,oBAAoB,GAAG,cAAc;SACxC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;SACzC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,OAAO,oBAAoB,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAC/D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CACzD,CAAC;AACJ,CAAC;AA3BD,gEA2BC"}
|
||||
26
node_modules/@apollo/utils.printwithreducedwhitespace/package.json
generated
vendored
Normal file
26
node_modules/@apollo/utils.printwithreducedwhitespace/package.json
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@apollo/utils.printwithreducedwhitespace",
|
||||
"version": "2.0.1",
|
||||
"description": "Print an AST with as little whitespace as possible",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/apollographql/apollo-utils.git",
|
||||
"directory": "packages/printWithReducedWhitespace/"
|
||||
},
|
||||
"keywords": [
|
||||
"apollo",
|
||||
"graphql",
|
||||
"typescript",
|
||||
"node"
|
||||
],
|
||||
"author": "Apollo <packages@apollographql.com>",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"graphql": "14.x || 15.x || 16.x"
|
||||
}
|
||||
}
|
||||
28
node_modules/@apollo/utils.printwithreducedwhitespace/src/__tests__/printWithReducedWhitespace.test.ts
generated
vendored
Normal file
28
node_modules/@apollo/utils.printwithreducedwhitespace/src/__tests__/printWithReducedWhitespace.test.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import gql from "graphql-tag";
|
||||
import { printWithReducedWhitespace } from "..";
|
||||
|
||||
describe("printWithReducedWhitespace", () => {
|
||||
it("removes whitespace", () => {
|
||||
// Note: there's a tab after "tab->", which prettier wants to keep as a
|
||||
// literal tab rather than \t. In the output, there should be a literal
|
||||
// backslash-t.
|
||||
const document = gql`
|
||||
query Foo($a: Int) {
|
||||
user(
|
||||
name: " tab-> yay"
|
||||
other: """
|
||||
apple
|
||||
bag
|
||||
cat
|
||||
"""
|
||||
) {
|
||||
name
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
expect(printWithReducedWhitespace(document)).toBe(
|
||||
`query Foo($a:Int){user(name:" tab->\\tyay"other:"apple\\n bag\\ncat"){name}}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
5
node_modules/@apollo/utils.printwithreducedwhitespace/src/__tests__/tsconfig.json
generated
vendored
Normal file
5
node_modules/@apollo/utils.printwithreducedwhitespace/src/__tests__/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.test.base",
|
||||
"include": ["**/*"],
|
||||
"references": [{ "path": "../../" }]
|
||||
}
|
||||
33
node_modules/@apollo/utils.printwithreducedwhitespace/src/index.ts
generated
vendored
Normal file
33
node_modules/@apollo/utils.printwithreducedwhitespace/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { visit, print, type DocumentNode, type StringValueNode } from "graphql";
|
||||
// Like the graphql-js print function, but deleting whitespace wherever
|
||||
// feasible. Specifically, all whitespace (outside of string literals) is
|
||||
// reduced to at most one space, and even that space is removed anywhere except
|
||||
// for between two alphanumerics.
|
||||
export function printWithReducedWhitespace(ast: DocumentNode): string {
|
||||
// In a GraphQL AST (which notably does not contain comments), the only place
|
||||
// where meaningful whitespace (or double quotes) can exist is in
|
||||
// StringNodes. So to print with reduced whitespace, we:
|
||||
// - temporarily sanitize strings by replacing their contents with hex
|
||||
// - use the default GraphQL printer
|
||||
// - minimize the whitespace with a simple regexp replacement
|
||||
// - convert strings back to their actual value
|
||||
// We normalize all strings to non-block strings for simplicity.
|
||||
|
||||
const sanitizedAST = visit(ast, {
|
||||
StringValue(node: StringValueNode): StringValueNode {
|
||||
return {
|
||||
...node,
|
||||
value: Buffer.from(node.value, "utf8").toString("hex"),
|
||||
block: false,
|
||||
};
|
||||
},
|
||||
});
|
||||
const withWhitespace = print(sanitizedAST);
|
||||
const minimizedButStillHex = withWhitespace
|
||||
.replace(/\s+/g, " ")
|
||||
.replace(/([^_a-zA-Z0-9]) /g, (_, c) => c)
|
||||
.replace(/ ([^_a-zA-Z0-9])/g, (_, c) => c);
|
||||
return minimizedButStillHex.replace(/"([a-f0-9]+)"/g, (_, hex) =>
|
||||
JSON.stringify(Buffer.from(hex, "hex").toString("utf8")),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user