Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cursor/rules/coding-style.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ description:
globs:
alwaysApply: true
---

Coding style:

- Favor `async run() {` over `run = async () => {` inside ES6 classes
Expand All @@ -14,6 +15,6 @@ Coding style:
- Do not wrap each function body and function call in `try`/`catch` blocks. It pollutes the code. Assume we will always have an e.g. `main().catch((err) => { console.error(err); process.exit(1) })` to catch us. I repeat: Avoid over-use of try-catch such as `try { // foo } catch (err) { console.error('error while foo'); throw err }`, assume we catch errors on a higher level and do not need the extra explananation.
- Before creating new files and new code, see if we can leverage existing work, maybe slighty adapt that without breaking BC, to keep things DRY.
- Favor early exits, so quickly `continue`, `return false` (or `throw` if needed), over nesting everything in positive conditions, creating christmas trees.
- Use Prettier with 100 char line width, single quotes for JS/TS, semi: false
- Use Biome with 100 char line width, single quotes for JS/TS, semi: false
- Use descriptive names: PascalCase for components/types, camelCase for variables/methods/schemas
- Alphabetize imports, group by source type (built-in/external/internal)
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

52 changes: 0 additions & 52 deletions .eslintrc.cjs

This file was deleted.

17 changes: 3 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ on:
- '*'

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack yarn
- run: corepack yarn lint:js

pack:
runs-on: ubuntu-latest
steps:
Expand All @@ -33,15 +23,15 @@ jobs:
name: package
path: '*.tgz'

prettier:
biome:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack yarn
- run: corepack yarn lint:formatting
- run: corepack yarn lint:js

typescript:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -96,9 +86,8 @@ jobs:
release:
runs-on: ubuntu-latest
needs:
- eslint
- pack
- prettier
- biome
- typescript
- vitest
if: startsWith(github.ref, 'refs/tags/')
Expand Down
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc.json

This file was deleted.

18 changes: 17 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"[javascript][typescript]": {
"editor.codeActionsOnSave": {
"source.fixAll.biome": "explicit",
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"eslint.format.enable": false,
"[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[javascript]": { "editor.defaultFormatter": "biomejs.biome" },
"[javascriptreact]": { "editor.defaultFormatter": "biomejs.biome" },
"[json]": { "editor.defaultFormatter": "biomejs.biome" },
"[liquid]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[markdown]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[typescript]": { "editor.defaultFormatter": "biomejs.biome" },
"[typescriptreact]": { "editor.defaultFormatter": "biomejs.biome" },
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ yarn upgrade-interactive

## Linting

This project is linted using [ESLint](https://eslint.org). You can lint the project by running:
This project is linted using Biome. You can lint the project by running:

```sh
yarn lint:js
```

## Formatting

This project is formatted using [Prettier](https://prettier.io). You can format the project:
This project is formatted using Biome. You can format the project:

```sh
yarn fix:formatting
yarn fix:js
```

## Testing
Expand Down
69 changes: 69 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
"files": {
"includes": [
"**",
"!coverage",
"!dist",
"!node_modules",
"!fixture",
"!.vscode",
"!src/alphalib"
]
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto"
},
"assist": { "actions": { "source": { "organizeImports": "on" } } },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "warn",
"noImplicitAnyLet": "error",
"noConfusingVoidType": "warn",
"noAssignInExpressions": "off",
"noTemplateCurlyInString": "off"
},
"correctness": {
"noInvalidUseBeforeDeclaration": "warn"
},
"complexity": {
"useLiteralKeys": "off",
"noForEach": "warn"
},
"style": {
"noParameterAssign": "warn",
"noUnusedTemplateLiteral": "off",
"useAsConstAssertion": "error",
"useDefaultParameterLast": "error",
"useEnumInitializers": "error",
"useSelfClosingElements": "error",
"useSingleVarDeclarator": "error",
"useNumberNamespace": "error",
"noInferrableTypes": "error",
"noUselessElse": "error"
}
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
}
}
8 changes: 6 additions & 2 deletions examples/convert_to_webp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
//
import { Transloadit } from 'transloadit'

const { TRANSLOADIT_KEY, TRANSLOADIT_SECRET } = process.env
if (TRANSLOADIT_KEY == null || TRANSLOADIT_SECRET == null) {
throw new Error('Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET')
}
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
authKey: TRANSLOADIT_KEY,
authSecret: TRANSLOADIT_SECRET,
})

const filePath = process.argv[2]
Expand Down
19 changes: 11 additions & 8 deletions examples/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-len */
// Run this file as:
//
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node template_api.js
Expand All @@ -7,11 +6,15 @@
//
// yarn prepack
//
import { CreateTemplateCredentialParams, Transloadit } from 'transloadit'
import { type CreateTemplateCredentialParams, Transloadit } from 'transloadit'

const { TRANSLOADIT_KEY, TRANSLOADIT_SECRET } = process.env
if (TRANSLOADIT_KEY == null || TRANSLOADIT_SECRET == null) {
throw new Error('Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET')
}
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
authKey: TRANSLOADIT_KEY,
authSecret: TRANSLOADIT_SECRET,
})

const firstName = 'myProductionS3'
Expand Down Expand Up @@ -54,23 +57,23 @@ console.log('TemplateCredential created successfully:', createTemplateCredential
// with Credentials, there is `ok`, `message`, `credentials` <-- and a single object nested directly under it, which is unexpected with that plural imho. Same is true for created, updated, fetched

console.log(
`==> editTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`
`==> editTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`,
)
const editResult = await transloadit.editTemplateCredential(
createTemplateCredentialResult.credential.id,
{
...credentialParams,
name: secondName,
}
},
)
console.log('Successfully edited credential', editResult)
// ^-- see create

console.log(
`==> getTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`
`==> getTemplateCredential: ${createTemplateCredentialResult.credential.id} (${createTemplateCredentialResult.credential.name})`,
)
const getTemplateCredentialResult = await transloadit.getTemplateCredential(
createTemplateCredentialResult.credential.id
createTemplateCredentialResult.credential.id,
)
console.log('Successfully fetched credential', getTemplateCredentialResult)
// ^-- not working at al, getting a 404. looking at the API, this is not implemented yet
12 changes: 8 additions & 4 deletions examples/face_detect_download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
// Then it will download the result as a file in the current directory
// See https://transloadit.com/demos/artificial-intelligence/detect-faces-in-images/

import got from 'got'
import assert from 'node:assert'
import { createWriteStream } from 'node:fs'
import got from 'got'
import { Transloadit } from 'transloadit'
import assert from 'assert'

const { TRANSLOADIT_KEY, TRANSLOADIT_SECRET } = process.env
if (TRANSLOADIT_KEY == null || TRANSLOADIT_SECRET == null) {
throw new Error('Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET')
}
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
authKey: TRANSLOADIT_KEY,
authSecret: TRANSLOADIT_SECRET,
})

const filePath = process.argv[2]
Expand Down
13 changes: 8 additions & 5 deletions examples/fetch_costs_of_all_assemblies_in_timeframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const params = {
page: 1,
}

const { TRANSLOADIT_KEY, TRANSLOADIT_SECRET } = process.env
if (TRANSLOADIT_KEY == null || TRANSLOADIT_SECRET == null) {
throw new Error('Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET')
}
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
authKey: TRANSLOADIT_KEY,
authSecret: TRANSLOADIT_SECRET,
})

let totalBytes = 0

let lastCount
let lastCount: number
do {
console.log('Processing page', params.page)
const { count, items } = await transloadit.listAssemblies(params)
Expand All @@ -34,7 +38,6 @@ do {

await pMap(
items,
// eslint-disable-next-line no-loop-func
async (assembly) => {
const assemblyFull = await transloadit.getAssembly(assembly.id)
// console.log(assemblyFull.assembly_id)
Expand All @@ -43,7 +46,7 @@ do {

totalBytes += bytesUsage || 0
},
{ concurrency: 20 }
{ concurrency: 20 },
)
} while (lastCount > 0)

Expand Down
8 changes: 6 additions & 2 deletions examples/rasterize_svg_to_png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
//
import { Transloadit } from 'transloadit'

const { TRANSLOADIT_KEY, TRANSLOADIT_SECRET } = process.env
if (TRANSLOADIT_KEY == null || TRANSLOADIT_SECRET == null) {
throw new Error('Please set TRANSLOADIT_KEY and TRANSLOADIT_SECRET')
}
const transloadit = new Transloadit({
authKey: process.env.TRANSLOADIT_KEY!,
authSecret: process.env.TRANSLOADIT_SECRET!,
authKey: TRANSLOADIT_KEY,
authSecret: TRANSLOADIT_SECRET,
})

const filePath = process.argv[2]
Expand Down
Loading