Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

413
Visualizações
¿Convertir código mecanografiado en código Javascript?

Estoy usando el tutorial Node Api de Shopify para crear una tienda Redis. Sin embargo, el bloque de código provisto está escrito a máquina y todo mi proyecto está escrito en javascript (React/nextjs). He estado trabajando durante algunas horas para intentar convertir el código para que sea utilizable, pero no puedo hacer que funcione correctamente en mi proyecto. Luchando seriamente con esto.

¿Cómo convertiría el siguiente bloque de código de mecanografiado a javascript?

 /* redis-store.ts */ // Import the Session type from the library, along with the Node redis package, and `promisify` from Node import {Session} from '@shopify/shopify-api/dist/auth/session'; import redis from 'redis'; import {promisify} from 'util'; class RedisStore { private client: redis.RedisClient; private getAsync; private setAsync; private delAsync; constructor() { // Create a new redis client this.client = redis.createClient(); // Use Node's `promisify` to have redis return a promise from the client methods this.getAsync = promisify(this.client.get).bind(this.client); this.setAsync = promisify(this.client.set).bind(this.client); this.delAsync = promisify(this.client.del).bind(this.client); } /* The storeCallback takes in the Session, and sets a stringified version of it on the redis store This callback is used for BOTH saving new Sessions and updating existing Sessions. If the session can be stored, return true Otherwise, return false */ storeCallback = async (session: Session) => { try { // Inside our try, we use the `setAsync` method to save our session. // This method returns a boolean (true if successful, false if not) return await this.setAsync(session.id, JSON.stringify(session)); } catch (err) { // throw errors, and handle them gracefully in your application throw new Error(err); } }; /* The loadCallback takes in the id, and uses the getAsync method to access the session data If a stored session exists, it's parsed and returned Otherwise, return undefined */ loadCallback = async (id: string) => { try { // Inside our try, we use `getAsync` to access the method by id // If we receive data back, we parse and return it // If not, we return `undefined` let reply = await this.getAsync(id); if (reply) { return JSON.parse(reply); } else { return undefined; } } catch (err) { throw new Error(err); } }; /* The deleteCallback takes in the id, and uses the redis `del` method to delete it from the store If the session can be deleted, return true Otherwise, return false */ deleteCallback = async (id: string) => { try { // Inside our try, we use the `delAsync` method to delete our session. // This method returns a boolean (true if successful, false if not) return await this.delAsync(id); } catch (err) { throw new Error(err); } }; } // Export the class export default RedisStore;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Simplemente guarde todo ese código mecanografiado en un archivo .ts (probablemente redis-store.ts). luego use el compilador de mecanografiado para convertir a su versión de javascript simplemente ejecutando el comando tsc como se muestra a continuación

 tsc redis-store.ts

para obtener más opciones de compilador, visite a continuación https://www.typescriptlang.org/docs/handbook/compiler-options.html

about 4 years ago · Juan Pablo Isaza Relatório

0

Básicamente, debe deshacerse de todos los tipos (sesión y cadena) y cambiar private a # , tal vez algo como esto:

 /* redis-store.js */ import redis from 'redis'; import {promisify} from 'util'; class RedisStore { #client; #getAsync; #setAsync; #delAsync; constructor() { // Create a new redis client this.client = redis.createClient(); this.getAsync = promisify(this.client.get).bind(this.client); this.setAsync = promisify(this.client.set).bind(this.client); this.delAsync = promisify(this.client.del).bind(this.client); } storeCallback = async (session) => { try { // Inside our try, we use the `setAsync` method to save our session. // This method returns a boolean (true if successful, false if not) return await this.setAsync(session.id, JSON.stringify(session)); } catch (err) { // throw errors, and handle them gracefully in your application throw new Error(err); } }; /* The loadCallback takes in the id, and uses the getAsync method to access the session data If a stored session exists, it's parsed and returned Otherwise, return undefined */ loadCallback = async (id) => { try { // Inside our try, we use `getAsync` to access the method by id // If we receive data back, we parse and return it // If not, we return `undefined` let reply = await this.getAsync(id); if (reply) { return JSON.parse(reply); } else { return undefined; } } catch (err) { throw new Error(err); } }; /* The deleteCallback takes in the id, and uses the redis `del` method to delete it from the store If the session can be deleted, return true Otherwise, return false */ deleteCallback = async (id) => { try { // Inside our try, we use the `delAsync` method to delete our session. // This method returns a boolean (true if successful, false if not) return await this.delAsync(id); } catch (err) { throw new Error(err); } }; } // Export the class export default RedisStore;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda