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

typed-path-generator

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-path-generator - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

34

dist/cli/generate.js

@@ -12,13 +12,24 @@ "use strict";

function generateCode(paths, variableName) {
var _a = parse(paths), staticPath = _a.staticPath, pathFactory = _a.pathFactory, ParamsInterface = _a.ParamsInterface;
return outdent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n import { makePathsFrom, Params, RepeatParams } from \"typed-path-generator\"\n\n interface ", " ", "\n\n const ", " = ", ";\n\n const ", " = ", ";\n\n export {\n ", " as ", ",\n ", " as ", ",\n ", " as ", ",\n }\n "], ["\n import { makePathsFrom, Params, RepeatParams } from \"typed-path-generator\"\n\n interface ", " ", "\n\n const ", " = ", ";\n\n const ", " = ", ";\n\n export {\n ", " as ", ",\n ", " as ", ",\n ", " as ", ",\n }\n "])), VARIABLE_NAME.ParamsInterface, utils_1.codeStringify(ParamsInterface), VARIABLE_NAME.staticPath, utils_1.codeStringify(staticPath), VARIABLE_NAME.pathFactory, utils_1.codeStringify(pathFactory), VARIABLE_NAME.ParamsInterface, variableName.ParamsInterface, VARIABLE_NAME.staticPath, variableName.staticPath, VARIABLE_NAME.pathFactory, variableName.pathFactory);
var _a = parse(paths), staticPath = _a.staticPath, pathFactory = _a.pathFactory, ParamsInterface = _a.ParamsInterface, importInfo = _a.importInfo;
var usedImportKeys = Object.keys(importInfo).filter(function (key) { return !!importInfo[key]; });
var importString = usedImportKeys.length > 0
? "import { " + usedImportKeys.join(',') + " } from \"typed-path-generator\""
: '';
return outdent_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n\n interface ", " ", "\n\n const ", " = ", ";\n\n const ", " = ", ";\n\n export {\n ", " as ", ",\n ", " as ", ",\n ", " as ", ",\n }\n "], ["\n ", "\n\n interface ", " ", "\n\n const ", " = ", ";\n\n const ", " = ", ";\n\n export {\n ", " as ", ",\n ", " as ", ",\n ", " as ", ",\n }\n "])), importString, VARIABLE_NAME.ParamsInterface, utils_1.codeStringify(ParamsInterface), VARIABLE_NAME.staticPath, utils_1.codeStringify(staticPath), VARIABLE_NAME.pathFactory, utils_1.codeStringify(pathFactory), VARIABLE_NAME.ParamsInterface, variableName.ParamsInterface, VARIABLE_NAME.staticPath, variableName.staticPath, VARIABLE_NAME.pathFactory, variableName.pathFactory);
}
exports.generateCode = generateCode;
function parse(paths) {
var result = { ParamsInterface: {}, staticPath: {}, pathFactory: {} };
var result = {
ParamsInterface: {},
staticPath: {},
pathFactory: {},
importInfo: {},
};
utils_1.recursiveForEach(paths, function (pathString, currentRefPath) {
var _a = utils_1.convert(pathString), path = _a.path, paramsType = _a.paramsType;
var _a = utils_1.convert(pathString), path = _a.path, paramsTypeString = _a.paramsTypeString;
var mergedParamsType = utils_1.mergeTypeString.apply(void 0, Object.values(paramsTypeString));
var pathRef = [VARIABLE_NAME.staticPath].concat(currentRefPath).join('.');
var paramsRef = [VARIABLE_NAME.ParamsInterface].concat(currentRefPath).reduce(function (ref, nextPath) { return ref + "['" + nextPath + "']"; });
lodash_1.set(result.ParamsInterface, currentRefPath, paramsType || 'void');
updateImportInfo(paramsTypeString);
lodash_1.set(result.ParamsInterface, currentRefPath, mergedParamsType || 'void');
lodash_1.set(result.staticPath, currentRefPath, "'" + path + "'");

@@ -28,3 +39,16 @@ lodash_1.set(result.pathFactory, currentRefPath, "makePathsFrom<" + paramsRef + ">(" + pathRef + ")");

return result;
function updateImportInfo(_a) {
var required = _a.required, requiredRepeat = _a.requiredRepeat, optional = _a.optional, optionalRepeat = _a.optionalRepeat;
var importInfo = result.importInfo;
importInfo.makePathsFrom = true;
var isUsedParamsType = !!(required || optional);
if (isUsedParamsType && !importInfo.Params) {
importInfo.Params = true;
}
var isUsedRepeatParamsType = !!(requiredRepeat || optionalRepeat);
if (isUsedRepeatParamsType && !importInfo.RepeatParams) {
importInfo.RepeatParams = true;
}
}
}
var templateObject_1;

57

dist/cli/index.js

@@ -56,2 +56,3 @@ "use strict";

var program = require("commander");
var glob = require("glob");
var outdent_1 = require("outdent");

@@ -72,26 +73,11 @@ var chalk_1 = require("chalk");

return __awaiter(this, void 0, void 0, function () {
var startTime;
var _this = this;
var filePaths;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
startTime = Date.now();
return [4, Promise.all(program.args.map(function (arg) { return __awaiter(_this, void 0, void 0, function () {
var isFilePath;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
isFilePath = typeof arg === 'string';
if (!isFilePath) return [3, 2];
return [4, generateFile(arg)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2];
}
});
}); }))];
case 0: return [4, getFilePaths()];
case 1:
filePaths = _a.sent();
return [4, Promise.all(filePaths.map(function (filePath) { return generateFile(filePath); }))];
case 2:
_a.sent();
console.log("Done in " + ((Date.now() - startTime) / 1000).toFixed(2) + "s");
return [2];

@@ -102,2 +88,33 @@ }

}
function getFilePaths() {
return __awaiter(this, void 0, void 0, function () {
var globProcess;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Promise.all(program.args.map(function (arg) {
return new Promise(function (resolve) {
var isFilePath = typeof arg === 'string';
if (isFilePath) {
glob(arg, function (error, fileNames) {
if (error) {
console.warn(error);
resolve([]);
}
else {
resolve(fileNames);
}
});
}
else {
resolve([]);
}
});
}))];
case 1:
globProcess = _a.sent();
return [2, globProcess.reduce(function (result, fileNames) { return result.concat(fileNames); })];
}
});
});
}
function generateFile(filePath) {

@@ -104,0 +121,0 @@ return __awaiter(this, void 0, void 0, function () {

import { Options, YAML } from './types';
export interface ParamsTypeString {
required: string;
requiredRepeat: string;
optional: string;
optionalRepeat: string;
}
export declare const getDefaultOptions: () => Options;

@@ -8,3 +14,4 @@ export declare function codeStringify(code: object): string;

path: string;
paramsType: string;
paramsTypeString: ParamsTypeString;
};
export declare function mergeTypeString(...types: string[]): string;

@@ -14,4 +14,2 @@ "use strict";

}); };
var makeParamsTypeString = makeTypeString(path_utils_1.ParamsType.Params);
var makeRepeatParamsTypeString = makeTypeString(path_utils_1.ParamsType.RepeatParams);
function codeStringify(code) {

@@ -62,3 +60,3 @@ var replaceInfo = [];

path: pathString,
paramsType: getParamsTypeString(keys),
paramsTypeString: getParamsTypeString(keys),
};

@@ -68,2 +66,4 @@ }

function getParamsTypeString(keys) {
var makeParamsTypeString = makeTypeString(path_utils_1.ParamsType.Params);
var makeRepeatParamsTypeString = makeTypeString(path_utils_1.ParamsType.RepeatParams);
var _a = keys.reduce(function (_a, key) {

@@ -98,3 +98,8 @@ var requiredKeys = _a.requiredKeys, requiredRepeatKeys = _a.requiredRepeatKeys, optionalKeys = _a.optionalKeys, optionalRepeatKeys = _a.optionalRepeatKeys;

var optionalRepeat = partialTypeString(makeRepeatParamsTypeString(optionalRepeatKeys));
return mergeTypeString(required, requiredRepeat, optional, optionalRepeat);
return {
required: required,
requiredRepeat: requiredRepeat,
optional: optional,
optionalRepeat: optionalRepeat,
};
}

@@ -127,1 +132,2 @@ function partialTypeString(type) {

}
exports.mergeTypeString = mergeTypeString;
{
"name": "typed-path-generator",
"version": "1.1.1",
"version": "1.2.0",
"description": "Convert path `/user/:userID` to `({ userID: string | number }) => string`",

@@ -44,2 +44,3 @@ "main": "./dist/index.js",

"devDependencies": {
"@types/glob": "^7.1.1",
"@types/jest": "^24.0.9",

@@ -63,2 +64,3 @@ "@types/js-yaml": "^3.12.0",

"commander": "^2.19.0",
"glob": "^7.1.3",
"js-yaml": "^3.12.2",

@@ -65,0 +67,0 @@ "lodash": "^4.17.11",

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