Socket
Socket
Sign inDemoInstall

@chnn/oats

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chnn/oats - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

28

dist/format.js

@@ -14,5 +14,6 @@ "use strict";

const code = type.charCodeAt(0);
// Assume that if a type starts with an alphabetical character, then it is a
// named type
return (code > 64 && code < 91) || (code > 96 && code < 123);
const startsAlphaNumeric = (code > 64 && code < 91) || (code > 96 && code < 123);
const includesUnion = type.includes("|");
const includesIntersection = type.includes("&");
return startsAlphaNumeric && !includesUnion && !includesIntersection;
}

@@ -41,7 +42,7 @@ exports.isTypeNamed = isTypeNamed;

const functionOutput = `
export function ${formatName(pathOp)}(
export const ${formatName(pathOp)} = (
params: ${paramsName(pathOp)},
options: RequestOptions = {}
): Promise<${resultName(pathOp)}> {
return request(
): Promise<${resultName(pathOp)}> =>
request(
"${pathOp.operation.toUpperCase()}",

@@ -52,3 +53,2 @@ ${formatURL(pathOp)},

) as Promise<${resultName(pathOp)}>
}
`.trim();

@@ -73,3 +73,3 @@ return `${formatPathOpTypes(pathOp)}\n\n${functionOutput}`;

async function request(
const request = async (
method: string,

@@ -79,3 +79,3 @@ url: string,

options: RequestOptions = {}
): Promise<any> {
): Promise<any> => {
const requestHeaders = new Headers(params.headers)

@@ -89,3 +89,3 @@ const contentType = requestHeaders.get("Content-Type") || ""

const query = params.query ? \`\${new URLSearchParams(params.query)}\` : ""
const query = params.query ? \`?\${new URLSearchParams(params.query)}\` : ""

@@ -130,5 +130,7 @@ const response = await fetch(\`\${url}\${query}\`, {

.map((p, i, ps) => {
const isGettingSingleResource = operation === "get" && i === ps.length - 2 && ps[i + 1].startsWith("{");
const isAddressingSingleResource = operation !== "get" && i === ps.length - 1;
if (isGettingSingleResource || isAddressingSingleResource) {
const isAddressingSingleResource = ["get", "patch", "put", "delete"].includes(operation) &&
i === ps.length - 2 &&
ps[i + 1].startsWith("{");
const isCreatingResource = operation === "post" && i === ps.length - 1;
if (isCreatingResource || isAddressingSingleResource) {
return depluralize(p);

@@ -135,0 +137,0 @@ }

@@ -205,3 +205,4 @@ "use strict";

const generator = new Generator(doc);
let messyOutput = Object.entries(generator.namedTypes)
let messyOutput = "// This file is generated by [oats][0] and should not be edited by hand.\n//\n// [0]: https://github.com/chnn/oats\n\n";
messyOutput += Object.entries(generator.namedTypes)
.map(([name, impl]) => format_1.formatTypeDeclaration(name, impl))

@@ -211,7 +212,13 @@ .join("\n\n");

messyOutput += "\n\n";
messyOutput += format_1.formatLib();
messyOutput += "\n\n";
messyOutput += generator.pathOps.map(op => format_1.formatPathOp(op)).join("\n\n");
messyOutput += "\n\n";
messyOutput += format_1.formatLib();
}
const prettierConfig = await prettier_1.resolveConfig(path.resolve(__dirname, "../.."));
// Assumes that the location of this module is in:
//
// $PROJECT/node_modules/@chnn/oats/dist
//
// We want to use `$PROJECT` as the location of the prettier config.
const prettierLocation = path.resolve(__dirname, "..", "..", "..", "..");
const prettierConfig = await prettier_1.resolveConfig(prettierLocation);
const output = prettier_1.format(messyOutput, {

@@ -218,0 +225,0 @@ ...prettierConfig,

{
"name": "@chnn/oats",
"version": "0.1.3",
"version": "0.2.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

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