Skip to content

Commit 0318b97

Browse files
authored
Add assembly status busy/terminal helpers (#280)
* Add assembly status helpers * Drop isAssemblyCompleted helper * docs: clarify changeset visibility for transloadit * fix: treat system errors as terminal * Apply suggestion from @kvz * chore: refresh transloadit parity baseline * docs: note how to accept intended parity drift
1 parent 4defbe9 commit 0318b97

File tree

6 files changed

+128
-18
lines changed

6 files changed

+128
-18
lines changed

.changeset/bright-sloths-care.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@transloadit/node": patch
3+
"@transloadit/zod": patch
4+
"@transloadit/types": patch
5+
"transloadit": patch
6+
---
7+
8+
Add assembly status helpers and expand busy status codes for consistent terminal checks.

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ Notes:
119119

120120
- **Lockstep versions:** Changesets use a fixed group, so version bumps and releases are always in lock‑step across `transloadit`, `@transloadit/node`, `@transloadit/types`, and `@transloadit/zod`.
121121
- **Legacy parity:** `transloadit` is generated from `@transloadit/node` artifacts via `scripts/prepare-transloadit.ts`, then verified with `yarn parity:transloadit`. Only `package.json` metadata drift is allowed; any other drift fails.
122+
- **Accepting intentional drift:** run `node scripts/prepare-transloadit.ts` before updating the parity baseline, then follow the parity tool instructions to regenerate `docs/fingerprint/*` so the baseline reflects the latest build.
122123
- **Experimental packages:** Scoped packages (`@transloadit/node`, `@transloadit/types`, `@transloadit/zod`) publish with the `experimental` dist-tag. The unscoped `transloadit` package remains stable.
124+
- **Changelog visibility:** Because versions are locked, a changeset that only lists scoped packages will still bump `transloadit` but may leave its changelog empty. If a change affects `transloadit` users (which happens because it is just a generated clone of `@transloadit/node`, so if it is affected, `transloadit` is too automatically), include `transloadit` in the changeset so the changelog entry is visible.

docs/fingerprint/transloadit-baseline.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"packageDir": "/Users/kvz/code/node-sdk/packages/transloadit",
2+
"packageDir": "/home/kvz/code/node-sdk/packages/transloadit",
33
"tarball": {
4-
"filename": "transloadit-4.1.3.tgz",
5-
"sizeBytes": 1112110,
6-
"sha256": "973f2846fe89338a05f6416d54722726d4ad7334181d02fd09b0838b30ab739e"
4+
"filename": "transloadit-4.1.4.tgz",
5+
"sizeBytes": 1112173,
6+
"sha256": "58d8c372fb4be8b14c7fcd2ba528846837b6d536ed80f2d55d36de6384f89684"
77
},
88
"packageJson": {
99
"name": "transloadit",
10-
"version": "4.1.3",
10+
"version": "4.1.4",
1111
"main": "./dist/Transloadit.js",
1212
"exports": {
1313
".": "./dist/Transloadit.js",
@@ -73,8 +73,8 @@
7373
},
7474
{
7575
"path": "dist/alphalib/types/assemblyStatus.js",
76-
"sizeBytes": 28422,
77-
"sha256": "aa59b5ea94ac88ab533233a76cd394f9d81d1631f3620cbe51e54261a96a07cb"
76+
"sizeBytes": 30275,
77+
"sha256": "965681e5d34df579fa11b8903c8fdf2823636be5830e97ab751fe5a531cad608"
7878
},
7979
{
8080
"path": "dist/alphalib/types/robots/audio-artwork.js",
@@ -614,7 +614,7 @@
614614
{
615615
"path": "package.json",
616616
"sizeBytes": 2201,
617-
"sha256": "4836303837df371e1cae0c1eab22c353d6efef46695047ddb428fc544df416a5"
617+
"sha256": "e0d0a327efa47840315ea7e37947e10feda0280754250302000ba016b388fa75"
618618
},
619619
{
620620
"path": "dist/alphalib/types/robots/_index.d.ts.map",
@@ -718,13 +718,13 @@
718718
},
719719
{
720720
"path": "dist/alphalib/types/assemblyStatus.d.ts.map",
721-
"sizeBytes": 73453,
722-
"sha256": "ba4ef1d696b4e2206f1f653816b4482e9c7d828e67932d3dc65c34901b8645ce"
721+
"sizeBytes": 74444,
722+
"sha256": "2a863f4791a4963c77806332af2a6353d158457b4c6a59ba5f7b6f271849643d"
723723
},
724724
{
725725
"path": "dist/alphalib/types/assemblyStatus.js.map",
726-
"sizeBytes": 31752,
727-
"sha256": "a34d73de1bfacf8481c2113ba52dca1c9323c0b72d2c85d1eedda9a5b04121d5"
726+
"sizeBytes": 32930,
727+
"sha256": "12d13cf45eaffea8afb16faaf9eac3bb9b0385e11a63606cfcddcc7a5c89c090"
728728
},
729729
{
730730
"path": "dist/alphalib/types/robots/audio-artwork.d.ts.map",
@@ -1903,13 +1903,13 @@
19031903
},
19041904
{
19051905
"path": "dist/alphalib/types/assemblyStatus.d.ts",
1906-
"sizeBytes": 4247223,
1907-
"sha256": "a73d095037fd45c143b9f2f11f0b95ba5d0eb788e566d2ece74752b6b84feec9"
1906+
"sizeBytes": 4249145,
1907+
"sha256": "85f796b227939cd5546c2ea92f2ae0b5929b6b3eabbb9b563df4079c61ea0463"
19081908
},
19091909
{
19101910
"path": "src/alphalib/types/assemblyStatus.ts",
1911-
"sizeBytes": 29509,
1912-
"sha256": "05e6b21ec4d572b95e0a6731633402a775de0aeb77b95c4cac87ac8cbcdab656"
1911+
"sizeBytes": 31951,
1912+
"sha256": "64f22e7547af8f406a7b4de333074bbbbe61ad4f2c3bb46ed076e682c466d5fa"
19131913
},
19141914
{
19151915
"path": "dist/alphalib/types/robots/audio-artwork.d.ts",

docs/fingerprint/transloadit-baseline.package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "transloadit",
3-
"version": "4.1.3",
3+
"version": "4.1.4",
44
"description": "Node.js SDK for Transloadit",
55
"type": "module",
66
"keywords": ["transloadit", "encoding", "transcoding", "video", "audio", "mp3"],

packages/node/src/alphalib/types/assemblyStatus.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { z } from 'zod'
22

3-
export const assemblyBusyCodeSchema = z.enum(['ASSEMBLY_UPLOADING'])
3+
export const assemblyBusyCodeSchema = z.enum([
4+
'ASSEMBLY_UPLOADING',
5+
'ASSEMBLY_EXECUTING',
6+
'ASSEMBLY_REPLAYING',
7+
])
48

59
export const assemblyStatusOkCodeSchema = z.enum([
610
'ASSEMBLY_CANCELED',
@@ -733,6 +737,79 @@ export function getOk(assembly: AssemblyStatus | undefined | null): string | und
733737
: undefined
734738
}
735739

740+
/**
741+
* Type guard to check if a status string is a busy (in-progress) state.
742+
*/
743+
export function isAssemblyBusyStatus(
744+
status: string | undefined | null,
745+
): status is z.infer<typeof assemblyBusyCodeSchema> {
746+
return Boolean(status) && assemblyBusyCodeSchema.safeParse(status).success
747+
}
748+
749+
/**
750+
* Type guard to check if a status string is an ok (non-error) state.
751+
*/
752+
export function isAssemblyOkStatus(
753+
status: string | undefined | null,
754+
): status is z.infer<typeof assemblyStatusOkCodeSchema> {
755+
return Boolean(status) && assemblyStatusOkCodeSchema.safeParse(status).success
756+
}
757+
758+
/**
759+
* Type guard to check if a status string is an error state.
760+
*/
761+
export function isAssemblyErrorStatus(
762+
status: string | undefined | null,
763+
): status is z.infer<typeof assemblyStatusErrCodeSchema> {
764+
return Boolean(status) && assemblyStatusErrCodeSchema.safeParse(status).success
765+
}
766+
767+
/**
768+
* Type guard to check if an assembly matches the system error shape.
769+
*/
770+
export function isAssemblySysError(
771+
assembly: AssemblyStatus | undefined | null,
772+
): assembly is z.infer<typeof assemblyStatusSysErrSchema> {
773+
return Boolean(assembly) && assemblyStatusSysErrSchema.safeParse(assembly).success
774+
}
775+
776+
/**
777+
* Type guard to check if a status string is terminal (ok, but not busy).
778+
*/
779+
export function isAssemblyTerminalOkStatus(
780+
status: string | undefined | null,
781+
): status is z.infer<typeof assemblyStatusOkCodeSchema> {
782+
return isAssemblyOkStatus(status) && !isAssemblyBusyStatus(status)
783+
}
784+
785+
/**
786+
* Returns true if the assembly is in a busy (in-progress) state.
787+
*/
788+
export function isAssemblyBusy(assembly: AssemblyStatus | undefined | null): boolean {
789+
return isAssemblyBusyStatus(getOk(assembly))
790+
}
791+
792+
/**
793+
* Returns true if the assembly is in a terminal ok state.
794+
*/
795+
export function isAssemblyTerminalOk(assembly: AssemblyStatus | undefined | null): boolean {
796+
return isAssemblyTerminalOkStatus(getOk(assembly))
797+
}
798+
799+
/**
800+
* Returns true if the assembly has a terminal error state.
801+
*/
802+
export function isAssemblyTerminalError(assembly: AssemblyStatus | undefined | null): boolean {
803+
return isAssemblyErrorStatus(getError(assembly)) || isAssemblySysError(assembly)
804+
}
805+
806+
/**
807+
* Returns true if the assembly is terminal (ok or error).
808+
*/
809+
export function isAssemblyTerminal(assembly: AssemblyStatus | undefined | null): boolean {
810+
return isAssemblyTerminalOk(assembly) || isAssemblyTerminalError(assembly)
811+
}
812+
736813
/**
737814
* This type and these functions below are compatibility helpers for
738815
* working with partial assembly status objects during the transition
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import type { AssemblyStatus } from '../../src/alphalib/types/assemblyStatus.ts'
4+
import {
5+
isAssemblySysError,
6+
isAssemblyTerminal,
7+
isAssemblyTerminalError,
8+
} from '../../src/alphalib/types/assemblyStatus.ts'
9+
10+
describe('assembly status helpers', () => {
11+
it('treats system error shapes as terminal errors', () => {
12+
const sysError = {
13+
errno: -2,
14+
code: 'ENOENT',
15+
syscall: 'stat',
16+
path: '/tmp/missing',
17+
} as AssemblyStatus
18+
19+
expect(isAssemblySysError(sysError)).toBe(true)
20+
expect(isAssemblyTerminalError(sysError)).toBe(true)
21+
expect(isAssemblyTerminal(sysError)).toBe(true)
22+
})
23+
})

0 commit comments

Comments
 (0)