rodrigo
rodrigo
Explore posts from servers
DTDrizzle Team
Created by rodrigo on 4/24/2024 in #help
classes to access db
Is this code possible? Copilot says it's valid but I cannot find it in the documentation
import { Model, STRING } from 'drizzle-orm';

class Organization extends Model {
static table = 'organizations';
static fields = {
id: {
type: STRING,
primaryKey: true,
},
name: {
type: STRING,
required: true,
},
};
}
...

async function createOrganization(name: string, adminUserId: string) {
const organization = new Organization();
organization.name = name;
organization.id = id;
await organization.save();
return organization;
}
import { Model, STRING } from 'drizzle-orm';

class Organization extends Model {
static table = 'organizations';
static fields = {
id: {
type: STRING,
primaryKey: true,
},
name: {
type: STRING,
required: true,
},
};
}
...

async function createOrganization(name: string, adminUserId: string) {
const organization = new Organization();
organization.name = name;
organization.id = id;
await organization.save();
return organization;
}
5 replies
CDCloudflare Developers
Created by rodrigo on 1/7/2024 in #workers-help
Custom Markdoc's components work on local with wrangler but fail online with Pages
I've create a custom Markdoc components following this guide: https://markdoc.dev/docs/examples/react In local, the component (Counter) works ok, and when consologing you get this:
{
'$$mdtype': 'Tag',
name: 'Counter',
attributes: [Object],
children: []
}
{
'$$mdtype': 'Tag',
name: 'Counter',
attributes: [Object],
children: []
}
But on deploying to Pages I get an error
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
and the console:
{
'$$mdtype': 'Tag',
name: '_R',
attributes: [Object],
children: []
}
{
'$$mdtype': 'Tag',
name: '_R',
attributes: [Object],
children: []
}
So it's like the render is working locally and not online. I've spotted the 'rendering error' in the transform method:
const ast = parse(markdown)
const config = {
tags: { counter, },

}
return transform(ast, config)
const ast = parse(markdown)
const config = {
tags: { counter, },

}
return transform(ast, config)
` What else can I do to debug it? Is the bug in Worker backend?? (because Markdoc works ok locally)
2 replies
CDCloudflare Developers
Created by rodrigo on 10/2/2023 in #workers-help
Stripe with Remix 2.0
I'm using Stripe with Remix on CF Pages, using this configuration:
export const stripe = (stripe_key) =>
new Stripe(stripe_key, {
apiVersion: '2023-08-16',
typescript: true,
httpClient: Stripe.createFetchHttpClient(),
})
export const stripe = (stripe_key) =>
new Stripe(stripe_key, {
apiVersion: '2023-08-16',
typescript: true,
httpClient: Stripe.createFetchHttpClient(),
})
` I've tried many ways but I always get this error:
node_modules/object-inspect/util.inspect.js:1:25:
1 │ module.exports = require('util').inspect;
╵ ~~~~~~

The package "util" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
node_modules/object-inspect/util.inspect.js:1:25:
1 │ module.exports = require('util').inspect;
╵ ~~~~~~

The package "util" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
Is this related with ESM config in Remix 2.0. ? I thught Stripe was totally compatible with Workers...
9 replies
CDCloudflare Developers
Created by rodrigo on 7/25/2023 in #general-help
Call Azure function from a Worker
I need to call an Azure function (to run an script on NodeJS) from a CF Worker (Remix on Cf Pages). Is it possible? How can I do that?
7 replies
DTDrizzle Team
Created by rodrigo on 7/22/2023 in #help
Insert multiple rows + onConflictDoUpdate
Is it possible to insert multiple rows (array) and at the same time using the onConflictDoUpdate? I'm trying it out but I get this error:
TypeError: Cannot read properties of undefined (reading 'name')
at ghh5w224esf.js:70758:77
at Array.flatMap (<anonymous>)
at SQLiteAsyncDialect.buildUpdateSet (ghh5w224esf.js:70757:36)
at SQLiteInsert.onConflictDoUpdate (ghh5w224esf.js:70637:186)
at D1_DB.pushCourse (ghh5w224esf.js:79896:65)
at OrgCourseService.insertCoursesFromNtnIntoD1 (ghh5w224esf.js:79874:36)
at async action2 (ghh5w224esf.js:58503:35)
at async callRouteActionRR (ghh5w224esf.js:3315:16)
at async callLoaderOrAction (ghh5w224esf.js:2436:16)
at async submit2 (ghh5w224esf.js:2080:25) {
stack: TypeError: Cannot read properties of undefined (re…16)
at async submit2 (ghh5w224esf.js:2080:25),
message: Cannot read properties of undefined (reading 'name')
}
TypeError: Cannot read properties of undefined (reading 'name')
at ghh5w224esf.js:70758:77
at Array.flatMap (<anonymous>)
at SQLiteAsyncDialect.buildUpdateSet (ghh5w224esf.js:70757:36)
at SQLiteInsert.onConflictDoUpdate (ghh5w224esf.js:70637:186)
at D1_DB.pushCourse (ghh5w224esf.js:79896:65)
at OrgCourseService.insertCoursesFromNtnIntoD1 (ghh5w224esf.js:79874:36)
at async action2 (ghh5w224esf.js:58503:35)
at async callRouteActionRR (ghh5w224esf.js:3315:16)
at async callLoaderOrAction (ghh5w224esf.js:2436:16)
at async submit2 (ghh5w224esf.js:2080:25) {
stack: TypeError: Cannot read properties of undefined (re…16)
at async submit2 (ghh5w224esf.js:2080:25),
message: Cannot read properties of undefined (reading 'name')
}
4 replies
DTDrizzle Team
Created by rodrigo on 7/12/2023 in #help
Error when deploying migrations with GH Action in Cloudflare D!
I'm trying to run migrations within a turborepo against a Cloudflare D1 instance. The command to run is this: wrangler d1 migrations apply d1_turbolang --preview I can run it from local (VS code) but when put it into an Github Action I get this error

Run pnpm preview:d1:migrations:apply

> @turbolang/root@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang
> pnpm --filter remix-admin preview:d1:migrations:apply


> @turbolang/remix-admin@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang/apps/remix-admin
> wrangler d1 migrations apply d1_turbolang --preview

▲ [WARNING] Processing wrangler.toml configuration:
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------

undefined
/home/runner/work/turbolang/turbolang/apps/remix-admin:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @turbolang/remix-admin@ preview:d1:migrations:apply: `wrangler d1 migrations apply d1_turbolang --preview `
Exit status 1
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.

Run pnpm preview:d1:migrations:apply

> @turbolang/root@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang
> pnpm --filter remix-admin preview:d1:migrations:apply


> @turbolang/remix-admin@ preview:d1:migrations:apply /home/runner/work/turbolang/turbolang/apps/remix-admin
> wrangler d1 migrations apply d1_turbolang --preview

▲ [WARNING] Processing wrangler.toml configuration:
--------------------
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
🚧 To give feedback, visit https://discord.gg/cloudflaredev
--------------------

undefined
/home/runner/work/turbolang/turbolang/apps/remix-admin:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @turbolang/remix-admin@ preview:d1:migrations:apply: `wrangler d1 migrations apply d1_turbolang --preview `
Exit status 1
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.
The code in GH Action is :
- name: Deploying migrations to Staging
if: ${{ github.ref == 'refs/heads/dev' }}
run: pnpm preview:d1:migrations:apply
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploying migrations to Staging
if: ${{ github.ref == 'refs/heads/dev' }}
run: pnpm preview:d1:migrations:apply
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
Any ideas what might be wrong?
6 replies
CDCloudflare Developers
Created by rodrigo on 4/26/2023 in #pages-help
websocket abruptly closes
I'm using MS cognitive services with CloudFlare Pages and the websocket connection closes before covnerting text to audio and generting the file:
console.log(sdk.Diagnostics.SetLoggingLevel(sdk.LogLevel.Debug));

const prom = new Promise((resolve, reject) => {
const synthesizer = new sdk.SpeechSynthesizer(speechConfig, null);

synthesizer.speakSsmlAsync(
ssml,
async (result) => {
console.log('RESULT', result);
if (result.errorDetails) {
console.log('1 if ');
console.log('ERROR', result.errorDetails);
synthesizer.close();
} else {
console.log('2 if');
const file = new File([result.audioData], fileName, {
type: 'audio/mp3',
lastModified: Date.now()
});
const res = await context.env.R2_IGLSBKT.put(fileName, file);
console.log('res R2', res);
synthesizer.close();
resolve(fileName);
}
},
(error) => {
console.log('err', error);
synthesizer.close();
}
);
});

await context.waitUntil(prom);
console.log(sdk.Diagnostics.SetLoggingLevel(sdk.LogLevel.Debug));

const prom = new Promise((resolve, reject) => {
const synthesizer = new sdk.SpeechSynthesizer(speechConfig, null);

synthesizer.speakSsmlAsync(
ssml,
async (result) => {
console.log('RESULT', result);
if (result.errorDetails) {
console.log('1 if ');
console.log('ERROR', result.errorDetails);
synthesizer.close();
} else {
console.log('2 if');
const file = new File([result.audioData], fileName, {
type: 'audio/mp3',
lastModified: Date.now()
});
const res = await context.env.R2_IGLSBKT.put(fileName, file);
console.log('res R2', res);
synthesizer.close();
resolve(fileName);
}
},
(error) => {
console.log('err', error);
synthesizer.close();
}
);
});

await context.waitUntil(prom);
I got this error:
(log) ERROR websocket send error: Websocket not ready 7E9767F5499D4D44AB1AEADF2328152C DA30C36F329148D58231F50472556959 Error
at $e.sendRawMessage (functionsWorker-0.04974505925468953.js:33452:129)
at $e.<anonymous> (functionsWorker-0.04974505925468953.js:33474:22)
at Generator.next (<anonymous>)
at c (functionsWorker-0.04974505925468953.js:33336:13)
(log) ERROR websocket send error: Websocket not ready 7E9767F5499D4D44AB1AEADF2328152C DA30C36F329148D58231F50472556959 Error
at $e.sendRawMessage (functionsWorker-0.04974505925468953.js:33452:129)
at $e.<anonymous> (functionsWorker-0.04974505925468953.js:33474:22)
at Generator.next (<anonymous>)
at c (functionsWorker-0.04974505925468953.js:33336:13)
My understanding is that WaitUntil kept the task running in the background until completion. Why then does the ws end before completion? How can I keep running in the background? (I'm in Unbound mode)
13 replies
CDCloudflare Developers
Created by rodrigo on 3/16/2023 in #workers-help
Microsoft Cognitive Services
I've opened an issue with Microsoft to check if MS cognitive services SDK works with Workers. https://github.com/microsoft/cognitive-services-speech-sdk-js/issues/645 They've fixed/remove code that was giving me the TypeError: globalThis.XMLHttpRequest is not a constructor error. But now it seems the sdk cannot connect to Azure's wss server. I'm not sure why but I've read here that wrangler doesn't work with wss but only with ws. Is that right?
2 replies
CDCloudflare Developers
Created by rodrigo on 2/8/2023 in #workers-help
Multiple reads with flareutils `list`
I'm trying to launch several flareutil list in parallel
await Promise.all(
arrPrefix.map(async (prefix) => {
const values = await serviceBKV.list({
prefix
});
await Promise.all(
arrPrefix.map(async (prefix) => {
const values = await serviceBKV.list({
prefix
});
I'm getting this error because I understand within list it's writing a Response: TypeError: Body has already been used. It can only be used once. Use tee() first if you need to read it twice What can I do to launch several list in parallel?
2 replies
CDCloudflare Developers
Created by rodrigo on 2/5/2023 in #pages-help
how to debug a function
I'm creating a webhook in Supabase to update a CF Worker KV. The point is that for every post request I can get the payload data but I cannot get any more info apart that post request is cancelled
"outcome": "canceled"
"outcome": "canceled"
I mean, I create conselo.log but this info doesn't show up in the request Real-time Logs. How can I get debug info in the log?
18 replies