@flowblade/core
v0.2.26
Published
Core contracts, interfaces and utilities
Downloads
265
Readme
@flowblade/core
Internal contracts and utilities for flowblade adapters. You generally don't have to install this package separately.
Install
yarn add @flowblade/coreUsage
QResult
This is specialized Result object for database interactions
Create a success QResult
const successResult = new QResult({
data: [{ name: "Seb" }],
meta: new QMeta({
spans: {
type: "sql",
timeMs: 13,
sql: "SELECT name FROM users",
affectedRows: 1,
params: [],
},
}),
});
// 👇 You can dereference, data, meta and error
const { data, meta, error } = result;
if (data) {
// typed in this case to { name: string}[]
console.log(data); // [{ name: 'Seb' }]
}
if (error) {
// typed in this case to QError
console.error(error); // QError object
}Create a failure QResult
const failureResult = new QResult<SuccessPayload, QError>({
error: {
message: "Error message",
},
});
failureResult.isError(); // 👈 true
failureResult.error; // 👈 QError
failureResult.data; // 👈 undefinedHelpers
result.map((row) => {
return { ...row, name: row.name.toUpperCase() };
});
result.getOrThrow(); // 👈 throw Error('Error message')
// 👇 Customize the error and throws
result.getOrThrow((qErr) => {
return new HttpServiceUnavailable({
cause: new Error(qErr.message),
});
});Bundle size
Bundle size is tracked by a size-limit configuration
| Scenario (esm) | Size (compressed) |
| ------------------------------------------ | ----------------: |
| import * from '@flowblade/core | ~ 2.04kB |
| import { QResult } from '@flowblade/core | ~ 1.63kB |
Compatibility
| Level | CI | Description | | ------------ | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Node | ✅ | CI for v20.x -> v25.x. | | Browser | ✅ | Tested with latest chrome (vitest/playwright) | | Browserslist | ✅ | > 95% on 01/2025. Chrome 96+, Firefox 90+, Edge 19+, ios 15+, Safari 15+ and Opera 77+ | | Edge | ✅ | Ensured on CI with @vercel/edge-runtime. | | Cloudflare | ✅ | Ensured with @cloudflare/vitest-pool-workers (see wrangler.toml | | Typescript | ✅ | TS 5.0 + / are-the-type-wrong checks on CI. | | ES2022 | ✅ | Dist files checked with es-check | | Performance | ✅ | Monitored with codspeed.io |
Contributors
Contributions are welcome. Have a look to the CONTRIBUTING document.
Sponsors
Sponsor, coffee, or star – All is spent for quality time with loved ones. Thanks ! 🙏❤️
Special thanks to
License
MIT © Sébastien Vanvelthem and contributors.
