Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lite-v3/gql-normalizer

Package Overview
Dependencies
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lite-v3/gql-normalizer - npm Package Compare versions

Comparing version 0.1.0-beta-1 to 0.1.0-beta-2

dist/generator/getAliasName.d.ts

73

dist/cli.js

@@ -109,2 +109,11 @@ #!/usr/bin/env node

// src/generator/getAliasName.ts
function getAliasName(name, suffix) {
const isCamelCase = name.match(/[A-Z]/);
if (isCamelCase)
return `${name}${suffix}`;
return `${name}_${suffix}`;
}
var getAliasName_default = getAliasName;
// src/generator/index.constants.ts

@@ -159,6 +168,7 @@ var DEFAULT_FALLBACK = {

if (nextType === "Array") {
returnment += `(${validKey} || []).map(${validKey}_item => `;
const arrAlias = getAliasName_default(validKey, "item");
returnment += `(${validKey} || []).map(${arrAlias} => `;
if (typeof nextData === "string") {
const arrFallback = nextData ? nextData : `"${nextData}"`;
returnment += `${validKey}_item || ${arrFallback}),`;
returnment += `${arrAlias} || ${arrFallback}),`;
} else {

@@ -193,3 +203,3 @@ returnment += `{.{{arrayAsign}}`;

if (nextType === "Array") {
const arrayAssignment = `const { ${assign} } = ${nextKey}_item || {};`;
const arrayAssignment = `const { ${assign} } = ${getAliasName_default(validKey, "item")} || {};`;
returnment = returnment.replace(`.{{arrayAsign}}`, arrayAssignment);

@@ -200,3 +210,3 @@ returnment += `

} else {
const assignKey = prevData ? nextKey : "data";
const assignKey = prevData ? validKey : "data";
const currentAssignment = `const { ${assign} } = ${assignKey} || {};`;

@@ -280,3 +290,3 @@ const arrayAssign = newGroupAssign[arrayGroup];

const types = data.split("\n\n");
const constList = {};
const constList = { data: 1 };
for (const type of types) {

@@ -324,8 +334,8 @@ if (type.match(/(type|interface) /s)) {

if (keyType) {
if (constList[key.trim()]) {
const counter = constList[key.trim()];
alias = `${keyTrim}_${counter + 1}`;
constList[key.trim()] += 1;
if (constList[keyTrim]) {
const counter = constList[keyTrim];
alias = getAliasName_default(keyTrim, counter);
constList[keyTrim] += 1;
} else {
constList[key.trim()] = 1;
constList[keyTrim] = 1;
}

@@ -399,2 +409,23 @@ }

// src/helpers/logger.ts
var import_picocolors = __toESM(require("picocolors"));
// src/helpers/fn.ts
function compose(...funcs) {
return (value) => funcs.reduceRight((y, f) => f(y), value);
}
// src/helpers/logger.ts
var lOut = process.stdout.write.bind(process.stdout);
var lErr = process.stderr.write.bind(process.stderr);
function log(message) {
lOut(message);
}
function logSuccess(message) {
lOut(compose(import_picocolors.default.green)(message));
}
function logError(message) {
lErr(compose(import_picocolors.default.red)(message));
}
// src/cmd/handler/getTargetPath.ts

@@ -450,3 +481,2 @@ var import_inquirer = require("inquirer");

var import_walk_sync = __toESM(require("walk-sync"));
var lOut = process.stdout.write.bind(process.stdout);
function splitTypesPath(targetPath, originPath) {

@@ -471,3 +501,3 @@ const splittedPath = targetPath.replace(/\.[^/.]+$/, "").split("/");

function findFileInFolder(targetPath) {
lOut(`Finding GQL-types files inside ${targetPath}...
log(`Finding GQL-types files inside ${targetPath}...
`);

@@ -477,3 +507,3 @@ const paths = (0, import_walk_sync.default)(targetPath, {

});
lOut(`GQL-types file found count: ${paths.length}
log(`GQL-types file found: ${paths.length}
`);

@@ -506,3 +536,2 @@ return paths.map((path) => splitTypesPath(path, targetPath));

// src/cmd/handler/index.ts
var lOut2 = process.stdout.write.bind(process.stdout);
function handler() {

@@ -520,11 +549,11 @@ return __async(this, null, function* () {

const pathName = `${fileName}.${extension}`;
lOut2(`- Processing ${pathName}... `);
log(`- Processing ${pathName}... `);
const { success, error } = yield generator_default(pathData);
if (success) {
countSuccess += 1;
lOut2(`Done!
logSuccess(`Done!
`);
} else {
countError += 1;
lOut2(`Failed!
logError(`Failed!
-- ${error}

@@ -536,9 +565,11 @@ `);

const seconds = (endDate.getTime() - startDate.getTime()) / 1e3;
lOut2(`Parser took ${seconds}s to parse ${allPaths.length} GraphQL types file(s).
SUCCESS: ${countSuccess}.
FAILED: ${countError}.
log(`Parser took ${seconds}s to parse ${allPaths.length} GraphQL types file(s).
`);
logSuccess(`SUCCESS: ${countSuccess}.
`);
logError(`FAILED: ${countError}.
`);
} catch (e) {
const error = String(e);
lOut2(error);
logError(error);
}

@@ -545,0 +576,0 @@ });

{
"name": "@lite-v3/gql-normalizer",
"version": "0.1.0-beta-1",
"version": "0.1.0-beta-2",
"description": "Graphql code normalizer based on gql-types",

@@ -39,5 +39,5 @@ "repository": {

"eslint-plugin-import": "^2.25.4",
"@tokopedia/lite-testing": "^2.6.3",
"@tokopedia/lite-esbuild": "^0.0.3",
"@lite-v3/tsconfig": "^1.0.0",
"@tokopedia/lite-esbuild": "^0.0.3",
"@tokopedia/lite-testing": "^2.6.3",
"@tokopedia/lite-typescript": "1.8.2"

@@ -44,0 +44,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc