Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
webhooks.forEach(({ name, actions, examples }) => {
if (!examples) {
return;
}
const typeName = `WebhookPayload${pascalCase(name)}`;
tw.add(examples, {
rootTypeName: typeName,
namedKeyPaths: {
[`${typeName}.repository`]: "PayloadRepository",
// This prevents a naming colision between the payload of a `installation_repositories` event
// and the `repositories` attribute of a `installation` event
"WebhookPayloadInstallation.repositories":
"WebhookPayloadInstallation_Repositories"
}
});
const events = [
`'${name}'`,
...actions.map(action => `'${name}.${action}'`)
].join(" | ");
signatures.push(`
return str.replace(/^(_*)(.*)/, (_match, underscorePrefix, typeName) => `${underscorePrefix}${pascalCase(typeName || '')}`);
}
const hookFns = [
`export function use${operationName}(baseOptions?: ApolloReactHooks.${operationType}HookOptions<${operationResultType}, ${operationVariablesTypes}>) {
return ApolloReactHooks.use${operationType}<${operationResultType}, ${operationVariablesTypes}>(${this.getDocumentNodeVariable(node, documentVariableName)}, baseOptions);
}`,
];
if (this.config.addDocBlocks) {
hookFns.unshift(this._buildHooksJSDoc(node, operationName, operationType));
}
const hookResults = [`export type ${operationName}HookResult = ReturnType;`];
if (operationType === 'Query') {
const lazyOperationName: string = this.convertName(node.name.value, {
suffix: pascalCase('LazyQuery'),
useTypesPrefix: false,
});
hookFns.push(
`export function use${lazyOperationName}(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<${operationResultType}, ${operationVariablesTypes}>) {
return ApolloReactHooks.useLazyQuery<${operationResultType}, ${operationVariablesTypes}>(${this.getDocumentNodeVariable(node, documentVariableName)}, baseOptions);
}`
);
hookResults.push(`export type ${lazyOperationName}HookResult = ReturnType;`);
}
return [...hookFns, ...hookResults].join('\n');
}
const componentMatcher = (componentName: string, item: any) => {
const matchingPatterns = [
filename,
`/${componentName}.`,
`/${kebabCase(componentName)}.`,
`/${pascalCase(componentName)}.`,
]
return !!matchingPatterns.find(pattern => item.key.includes(pattern))
}
private _buildOperationHoc(node: OperationDefinitionNode, documentVariableName: string, operationResultType: string, operationVariablesTypes: string): string {
this.imports.add(this.getApolloReactCommonImport());
this.imports.add(this.getApolloReactHocImport());
const operationName: string = this.convertName(node.name.value, { useTypesPrefix: false });
const propsTypeName: string = this.convertName(node.name.value, { suffix: 'Props' });
const propsVar = `export type ${propsTypeName} = ${this._buildHocProps(node.name.value, node.operation)} | TChildProps;`;
const hocString = `export function with${operationName}(operationOptions?: ApolloReactHoc.OperationOption<
TProps,
${operationResultType},
${operationVariablesTypes},
${propsTypeName}>) {
return ApolloReactHoc.with${pascalCase(node.operation)}>(${this.getDocumentNodeVariable(node, documentVariableName)}, {
alias: '${camelCase(operationName)}',
...operationOptions
});
};`;
return [propsVar, hocString].filter(a => a).join('\n');
}
interf.members.forEach((member) => {
if (member.kind === 'property' && isExtractableType(member.type)) {
const name = `${componentName}${pascalCase(member.name)}`;
const extractedMember = createModuleMember(name, member.type);
if (extractedMember) {
extractedMember.flags = dom.DeclarationFlags.Export;
m.members.push(extractedMember);
member.type = createTypeReference(name, member.type);
}
}
});
}
$.rename(file => {
file.basename = `${pascalCase(file.basename)}`;
file.extname = '.js';
})
)
public changeCase (pattern?: 'pascalcase' | 'camelcase' | 'snakecase'): this {
switch (pattern) {
case 'camelcase':
this.input = camelCase(this.input)
return this
case 'pascalcase':
this.input = pascalCase(this.input)
return this
case 'snakecase':
this.input = snakeCase(this.input)
return this
default:
return this
}
}
private _buildHooks(node: OperationDefinitionNode, operationType: string, documentVariableName: string, operationResultType: string, operationVariablesTypes: string): string {
const operationName: string = this.convertName(node.name.value, { suffix: pascalCase(operationType), useTypesPrefix: false });
if (operationType === 'Mutation') {
return `
export function use${operationName}() {
return Urql.use${operationType}<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName});
};`;
}
if (operationType === 'Subscription') {
return `
export function use${operationName}(options: Omit, 'query'> = {}, handler?: Urql.SubscriptionHandler<${operationName}, TData>) {
return Urql.use${operationType}<${operationResultType}, TData, ${operationVariablesTypes}>({ query: ${documentVariableName}, ...options }, handler);
};`;
}
return `
export function toPascalCase(str: string) {
if (str.charAt(0) === '_') {
return str.replace(/^(_*)(.*)/, (_match, underscorePrefix, typeName) => `${underscorePrefix}${pascalCase(typeName || '')}`);
}
return pascalCase(str || '');
}