🎥 Make videos programmatically with React
getting there
Jonny Burger3ee7f79b8819
diff --git a/packages/lambda/src/api/get-compositions-on-lambda.ts b/packages/lambda/src/api/get-compositions-on-lambda.tsindex 183e1ae000..8a79104cd6 100644--- a/packages/lambda/src/api/get-compositions-on-lambda.ts+++ b/packages/lambda/src/api/get-compositions-on-lambda.ts@@ -10,7 +10,6 @@ import type {VideoConfig} from 'remotion/no-react';import {VERSION} from 'remotion/version';import type {AwsRegion} from '../client';import {awsImplementation} from '../functions/aws-implementation';-import {callLambdaSync} from '../shared/call-lambda-sync';export type GetCompositionsOnLambdaInput = {chromiumOptions?: ChromiumOptions;@@ -66,7 +65,7 @@ export const getCompositionsOnLambda = async ({});try {- const res = await callLambdaSync({+ const res = await awsImplementation.callFunctionSync({functionName,type: ServerlessRoutines.compositions,payload: {diff --git a/packages/lambda/src/api/get-render-progress.ts b/packages/lambda/src/api/get-render-progress.tsindex c8d4d3de96..23d8e5b8ad 100644--- a/packages/lambda/src/api/get-render-progress.ts+++ b/packages/lambda/src/api/get-render-progress.ts@@ -8,7 +8,6 @@ import {import {getProgress} from '../functions/helpers/get-progress';import {parseFunctionName} from '../functions/helpers/parse-function-name';import type {AwsRegion} from '../regions';-import {callLambdaSync} from '../shared/call-lambda-sync';import type {RenderProgress} from '../shared/constants';import {getRenderProgressPayload} from './make-lambda-payload';@@ -56,12 +55,13 @@ export const getRenderProgress = async (});}- const result = await callLambdaSync<AwsProvider, ServerlessRoutines.status>({- functionName: input.functionName,- type: ServerlessRoutines.status,- payload: getRenderProgressPayload(input),- region: input.region,- timeoutInTest: 120000,- });+ const result =+ await awsImplementation.callFunctionSync<ServerlessRoutines.status>({+ functionName: input.functionName,+ type: ServerlessRoutines.status,+ payload: getRenderProgressPayload(input),+ region: input.region,+ timeoutInTest: 120000,+ });return result;};diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.tsindex daec6f09f3..9dd7fcbbd8 100644--- a/packages/lambda/src/api/render-media-on-lambda.ts+++ b/packages/lambda/src/api/render-media-on-lambda.ts@@ -17,9 +17,11 @@ import type {WebhookOption,} from '@remotion/serverless/client';import {ServerlessRoutines} from '@remotion/serverless/client';-import type {AwsProvider} from '../functions/aws-implementation';+import {+ awsImplementation,+ type AwsProvider,+} from '../functions/aws-implementation';import type {AwsRegion} from '../regions';-import {callLambdaSync} from '../shared/call-lambda-sync';import {getCloudwatchMethodUrl,getCloudwatchRendererUrl,@@ -88,7 +90,7 @@ export const internalRenderMediaOnLambdaRaw = async (const {functionName, region, rendererFunctionName} = input;try {- const res = await callLambdaSync({+ const res = await awsImplementation.callFunctionSync({functionName,type: ServerlessRoutines.start,payload: await makeLambdaRenderMediaPayload(input),diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.tsindex 7aa7caabd9..efdea652b0 100644--- a/packages/lambda/src/api/render-still-on-lambda.ts+++ b/packages/lambda/src/api/render-still-on-lambda.ts@@ -6,7 +6,6 @@ import type {import type {BrowserSafeApis} from '@remotion/renderer/client';import type {DownloadBehavior} from '@remotion/serverless/client';import {ServerlessRoutines} from '@remotion/serverless/client';-import {callLambdaWithStreaming} from '../shared/call-lambda-streaming';import {wrapWithErrorHandling} from '@remotion/renderer/error-handling';import type {@@ -14,7 +13,10 @@ import type {RenderStillLambdaResponsePayload,} from '@remotion/serverless';import type {OutNameInput, Privacy} from '@remotion/serverless/client';-import type {AwsProvider} from '../functions/aws-implementation';+import {+ awsImplementation,+ type AwsProvider,+} from '../functions/aws-implementation';import type {AwsRegion} from '../regions';import type {CostsInfo} from '../shared/constants';import {DEFAULT_MAX_RETRIES} from '../shared/constants';@@ -87,40 +89,41 @@ const internalRenderStillOnLambda = async (const res = await new Promise<RenderStillLambdaResponsePayload<AwsProvider>>((resolve, reject) => {- callLambdaWithStreaming<AwsProvider, ServerlessRoutines.still>({- functionName,- type: ServerlessRoutines.still,- payload,- region,- receivedStreamingPayload: ({message}) => {- if (message.type === 'render-id-determined') {- onInit?.({- renderId: message.payload.renderId,- cloudWatchLogs: getCloudwatchMethodUrl({- functionName,- method: ServerlessRoutines.still,- region,- rendererFunctionName: null,+ awsImplementation+ .callFunctionStreaming<ServerlessRoutines.still>({+ functionName,+ type: ServerlessRoutines.still,+ payload,+ region,+ receivedStreamingPayload: ({message}) => {+ if (message.type === 'render-id-determined') {+ onInit?.({renderId: message.payload.renderId,- }),- lambdaInsightsUrl: getLambdaInsightsUrl({- functionName,- region,- }),- });- }+ cloudWatchLogs: getCloudwatchMethodUrl({+ functionName,+ method: ServerlessRoutines.still,+ region,+ rendererFunctionName: null,+ renderId: message.payload.renderId,+ }),+ lambdaInsightsUrl: getLambdaInsightsUrl({+ functionName,+ region,+ }),+ });+ }- if (message.type === 'error-occurred') {- reject(new Error(message.payload.error));- }+ if (message.type === 'error-occurred') {+ reject(new Error(message.payload.error));+ }- if (message.type === 'still-rendered') {- resolve(message.payload);- }- },- timeoutInTest: 120000,- retriesRemaining: input.maxRetries,- })+ if (message.type === 'still-rendered') {+ resolve(message.payload);+ }+ },+ timeoutInTest: 120000,+ retriesRemaining: input.maxRetries,+ }).then(() => {reject(new Error('Expected response to be streamed'));})diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.tsindex 9df16aff02..6f29dc5055 100644--- a/packages/lambda/src/functions/aws-implementation.ts+++ b/packages/lambda/src/functions/aws-implementation.ts@@ -10,6 +10,9 @@ import {lambdaLsImplementation} from '../io/list-objects';import {lambdaReadFileImplementation} from '../io/read-file';import {lambdaWriteFileImplementation} from '../io/write-file';import type {AwsRegion} from '../regions';+import {callFunctionAsyncImplementation} from '../shared/call-lambda-async';+import {callFunctionWithStreamingImplementation} from '../shared/call-lambda-streaming';+import {callFunctionSyncImplementation} from '../shared/call-lambda-sync';import {convertToServeUrlImplementation} from '../shared/convert-to-serve-url';import {applyLifeCyleOperation} from '../shared/lifecycle-rules';import {randomHashImplementation} from '../shared/random-hash';@@ -90,4 +93,7 @@ export const awsImplementation: ProviderSpecifics<AwsProvider> = {getFolderFiles,makeArtifactWithDetails: makeAwsArtifact,validateDeleteAfter,+ callFunctionAsync: callFunctionAsyncImplementation,+ callFunctionStreaming: callFunctionWithStreamingImplementation,+ callFunctionSync: callFunctionSyncImplementation,};diff --git a/packages/lambda/src/functions/helpers/stream-renderer.ts b/packages/lambda/src/functions/helpers/stream-renderer.tsindex 883890838d..794155f8a9 100644--- a/packages/lambda/src/functions/helpers/stream-renderer.ts+++ b/packages/lambda/src/functions/helpers/stream-renderer.ts@@ -13,7 +13,6 @@ import type {ServerlessPayload} from '@remotion/serverless/client';import {ServerlessRoutines} from '@remotion/serverless/client';import {writeFileSync} from 'fs';import {join} from 'path';-import {callLambdaWithStreaming} from '../../shared/call-lambda-streaming';type StreamRendererResponse =| {@@ -161,15 +160,16 @@ const streamRenderer = <Provider extends CloudProvider>({throw new Error(`Unknown message type ${message.type}`);};- callLambdaWithStreaming({- functionName,- payload,- retriesRemaining: 1,- region: providerSpecifics.getCurrentRegionInFunction(),- timeoutInTest: 12000,- type: ServerlessRoutines.renderer,- receivedStreamingPayload,- })+ providerSpecifics+ .callFunctionStreaming({+ functionName,+ payload,+ retriesRemaining: 1,+ region: providerSpecifics.getCurrentRegionInFunction(),+ timeoutInTest: 12000,+ type: ServerlessRoutines.renderer,+ receivedStreamingPayload,+ }).then(() => {resolve({type: 'success',diff --git a/packages/lambda/src/functions/index.ts b/packages/lambda/src/functions/index.tsindex c3f4f6eb93..86fd8dd5bb 100644--- a/packages/lambda/src/functions/index.ts+++ b/packages/lambda/src/functions/index.ts@@ -1,6 +1,7 @@import {RenderInternals} from '@remotion/renderer';import type {CloudProvider,+ OrError,ProviderSpecifics,ResponseStream,ResponseStreamWriter,@@ -329,14 +330,6 @@ const innerHandler = async <Provider extends CloudProvider>({throw new Error(COMMAND_NOT_FOUND);};-export type OrError<T> =- | T- | {- type: 'error';- message: string;- stack: string;- };-export const innerRoutine = async <Provider extends CloudProvider>(params: ServerlessPayload<Provider>,responseStream: ResponseStream,diff --git a/packages/lambda/src/functions/start.ts b/packages/lambda/src/functions/start.tsindex bba6296199..053e72ac6c 100644--- a/packages/lambda/src/functions/start.ts+++ b/packages/lambda/src/functions/start.ts@@ -11,7 +11,6 @@ import {} from '@remotion/serverless/client';import {VERSION} from 'remotion/version';import type {AwsRegion} from '../regions';-import {callLambdaAsync} from '../shared/call-lambda-async';type Options = {expectedBucketOwner: string;@@ -124,7 +123,7 @@ export const startHandler = async <Provider extends CloudProvider>(metadata: params.metadata,};- await callLambdaAsync({+ await providerSpecifics.callFunctionAsync({functionName: process.env.AWS_LAMBDA_FUNCTION_NAME as string,type: ServerlessRoutines.launch,payload,diff --git a/packages/lambda/src/shared/__mocks__/aws-clients.ts b/packages/lambda/src/shared/__mocks__/aws-clients.tsdeleted file mode 100644index b12e3a9248..0000000000--- a/packages/lambda/src/shared/__mocks__/aws-clients.ts+++ /dev/null@@ -1,55 +0,0 @@-import type {LambdaClient} from '@aws-sdk/client-lambda';--import {ResponseStream} from '@remotion/serverless';-import type {getLambdaClient as original} from '../../shared/aws-clients';-import {mockImplementation} from '../../test/mock-implementation';--export const getLambdaClient: typeof original = (_region, timeoutInTest) => {- return {- config: {- requestHandler: {},- apiVersion: 'fake',- },- destroy: () => undefined,- middlewareStack: undefined,- send: async (params: {- input: {- FunctionName: undefined;- Payload: string;- InvocationType: 'Event' | 'RequestResponse' | undefined;- };- }) => {- const payload = JSON.parse(params.input.Payload);-- const {innerRoutine} = await import('../../functions/index');-- const responseStream = new ResponseStream();- const prom = innerRoutine(- payload,- responseStream,- {- invokedFunctionArn: 'arn:fake',- getRemainingTimeInMillis: () => timeoutInTest ?? 120000,- awsRequestId: 'fake',- },- mockImplementation,- );- if (- params.input.InvocationType === 'RequestResponse' ||- params.input.InvocationType === 'Event'- ) {- await prom;- return {Payload: responseStream.getBufferedData()};- }-- prom.then(() => {- responseStream._finish();- responseStream.end();- });- // When streaming, we should not consume the response- return {- EventStream: responseStream,- };- },- } as unknown as LambdaClient;-};diff --git a/packages/lambda/src/shared/call-lambda-async.ts b/packages/lambda/src/shared/call-lambda-async.tsindex f42094b172..ea5feef81c 100644--- a/packages/lambda/src/shared/call-lambda-async.ts+++ b/packages/lambda/src/shared/call-lambda-async.ts@@ -1,11 +1,10 @@import {InvokeCommand} from '@aws-sdk/client-lambda';-import type {CloudProvider} from '@remotion/serverless';+import type {CallFunctionOptions, CloudProvider} from '@remotion/serverless';import type {ServerlessRoutines} from '@remotion/serverless/client';import type {AwsRegion} from '../regions';import {getLambdaClient} from './aws-clients';-import type {CallLambdaOptions} from './call-lambda';-export const callLambdaAsync = async <+export const callFunctionAsyncImplementation = async <T extends ServerlessRoutines,Provider extends CloudProvider,>({@@ -13,7 +12,7 @@ export const callLambdaAsync = async <payload,region,timeoutInTest,-}: CallLambdaOptions<T, Provider>): Promise<void> => {+}: CallFunctionOptions<T, Provider>): Promise<void> => {const stringifiedPayload = JSON.stringify(payload);if (stringifiedPayload.length > 256 * 1024) {throw new Error(diff --git a/packages/lambda/src/shared/call-lambda-streaming.ts b/packages/lambda/src/shared/call-lambda-streaming.tsindex 8182cb35e9..6599201e43 100644--- a/packages/lambda/src/shared/call-lambda-streaming.ts+++ b/packages/lambda/src/shared/call-lambda-streaming.ts@@ -4,6 +4,7 @@ import {type InvokeWithResponseStreamResponseEvent,} from '@aws-sdk/client-lambda';import type {+ CallFunctionOptions,CloudProvider,OnMessage,StreamingMessage,@@ -19,7 +20,6 @@ import {import {makeStreamer} from '@remotion/streaming';import type {AwsRegion} from '../regions';import {getLambdaClient} from './aws-clients';-import type {CallLambdaOptions} from './call-lambda';const STREAM_STALL_TIMEOUT = 30000;const LAMBDA_STREAM_STALL = `AWS did not invoke Lambda in ${STREAM_STALL_TIMEOUT}ms`;@@ -85,7 +85,7 @@ const callLambdaWithStreamingWithoutRetry = async <region,timeoutInTest,receivedStreamingPayload,-}: CallLambdaOptions<T, Provider> & {+}: CallFunctionOptions<T, Provider> & {receivedStreamingPayload: OnMessage<Provider>;}): Promise<void> => {const res = await invokeStreamOrTimeout({@@ -173,11 +173,11 @@ const callLambdaWithStreamingWithoutRetry = async <clear();};-export const callLambdaWithStreaming = async <+export const callFunctionWithStreamingImplementation = async <Provider extends CloudProvider,T extends ServerlessRoutines,>(- options: CallLambdaOptions<T, Provider> & {+ options: CallFunctionOptions<T, Provider> & {receivedStreamingPayload: OnMessage<Provider>;retriesRemaining: number;},@@ -210,7 +210,7 @@ export const callLambdaWithStreaming = async <}console.error(err);- return callLambdaWithStreaming({+ return callFunctionWithStreamingImplementation({...options,retriesRemaining: options.retriesRemaining - 1,});diff --git a/packages/lambda/src/shared/call-lambda-sync.ts b/packages/lambda/src/shared/call-lambda-sync.tsindex 913908e913..37bd33c832 100644--- a/packages/lambda/src/shared/call-lambda-sync.ts+++ b/packages/lambda/src/shared/call-lambda-sync.ts@@ -1,11 +1,13 @@import {InvokeCommand} from '@aws-sdk/client-lambda';-import type {CloudProvider} from '@remotion/serverless';+import type {+ CallFunctionOptions,+ CloudProvider,+ OrError,+ ServerlessReturnValues,+} from '@remotion/serverless';import type {ServerlessRoutines} from '@remotion/serverless/client';-import type {OrError} from '../functions';import type {AwsRegion} from '../regions';import {getLambdaClient} from './aws-clients';-import type {CallLambdaOptions} from './call-lambda';-import type {LambdaReturnValues} from './return-values';const callLambdaSyncWithoutRetry = async <T extends ServerlessRoutines,@@ -15,8 +17,8 @@ const callLambdaSyncWithoutRetry = async <payload,region,timeoutInTest,-}: CallLambdaOptions<T, Provider>): Promise<- OrError<LambdaReturnValues<Provider>[T]>+}: CallFunctionOptions<T, Provider>): Promise<+ OrError<ServerlessReturnValues<Provider>[T]>> => {const Payload = JSON.stringify(payload);const res = await getLambdaClient(region as AwsRegion, timeoutInTest).send(@@ -30,18 +32,18 @@ const callLambdaSyncWithoutRetry = async <const decoded = new TextDecoder('utf-8').decode(res.Payload);try {- return JSON.parse(decoded) as OrError<LambdaReturnValues<Provider>[T]>;+ return JSON.parse(decoded) as OrError<ServerlessReturnValues<Provider>[T]>;} catch {throw new Error(`Invalid JSON: ${JSON.stringify(decoded)}`);}};-export const callLambdaSync = async <+export const callFunctionSyncImplementation = async <Provider extends CloudProvider,T extends ServerlessRoutines,>(- options: CallLambdaOptions<T, Provider>,-): Promise<LambdaReturnValues<Provider>[T]> => {+ options: CallFunctionOptions<T, Provider>,+): Promise<ServerlessReturnValues<Provider>[T]> => {const res = await callLambdaSyncWithoutRetry<T, Provider>(options);if (res.type === 'error') {const err = new Error(res.message);diff --git a/packages/lambda/src/shared/call-lambda.ts b/packages/lambda/src/shared/call-lambda.tsdeleted file mode 100644index c353e8d8b6..0000000000--- a/packages/lambda/src/shared/call-lambda.ts+++ /dev/null@@ -1,16 +0,0 @@-import type {CloudProvider} from '@remotion/serverless';-import type {- ServerlessPayloads,- ServerlessRoutines,-} from '@remotion/serverless/client';--export type CallLambdaOptions<- T extends ServerlessRoutines,- Provider extends CloudProvider,-> = {- functionName: string;- type: T;- payload: ServerlessPayloads<Provider>[T];- region: Provider['region'];- timeoutInTest: number;-};diff --git a/packages/lambda/src/shared/get-function-version.ts b/packages/lambda/src/shared/get-function-version.tsindex d6869366f4..d19b13c7bb 100644--- a/packages/lambda/src/shared/get-function-version.ts+++ b/packages/lambda/src/shared/get-function-version.ts@@ -1,7 +1,7 @@import type {LogLevel} from '@remotion/renderer';import {ServerlessRoutines} from '@remotion/serverless/client';+import {awsImplementation} from '../functions/aws-implementation';import type {AwsRegion} from '../regions';-import {callLambdaSync} from './call-lambda-sync';import {COMMAND_NOT_FOUND} from './constants';export const getFunctionVersion = async ({@@ -14,7 +14,7 @@ export const getFunctionVersion = async ({logLevel: LogLevel;}): Promise<string> => {try {- const result = await callLambdaSync({+ const result = await awsImplementation.callFunctionSync({functionName,payload: {logLevel,diff --git a/packages/lambda/src/shared/return-values.ts b/packages/lambda/src/shared/return-values.tsdeleted file mode 100644index 64fa0386ad..0000000000--- a/packages/lambda/src/shared/return-values.ts+++ /dev/null@@ -1,21 +0,0 @@-import type {- CloudProvider,- compositionsHandler,- infoHandler,-} from '@remotion/serverless';-import type {ServerlessRoutines} from '@remotion/serverless/client';-import type {launchHandler} from '../functions/launch';-import type {progressHandler} from '../functions/progress';-import type {rendererHandler} from '../functions/renderer';-import type {startHandler} from '../functions/start';-import type {stillHandler} from '../functions/still';--export interface LambdaReturnValues<Provider extends CloudProvider> {- [ServerlessRoutines.start]: ReturnType<typeof startHandler>;- [ServerlessRoutines.launch]: ReturnType<typeof launchHandler>;- [ServerlessRoutines.renderer]: ReturnType<typeof rendererHandler>;- [ServerlessRoutines.status]: ReturnType<typeof progressHandler<Provider>>;- [ServerlessRoutines.info]: ReturnType<typeof infoHandler<Provider>>;- [ServerlessRoutines.still]: ReturnType<typeof stillHandler>;- [ServerlessRoutines.compositions]: ReturnType<typeof compositionsHandler>;-}diff --git a/packages/lambda/src/test/integration/handlers.test.ts b/packages/lambda/src/test/integration/handlers.test.tsindex 929965cf07..42316151e5 100644--- a/packages/lambda/src/test/integration/handlers.test.ts+++ b/packages/lambda/src/test/integration/handlers.test.ts@@ -1,11 +1,11 @@import {ServerlessRoutines} from '@remotion/serverless/client';import {VERSION} from 'remotion/version';import {expect, test} from 'vitest';-import {callLambdaSync} from '../../shared/call-lambda-sync';+import {mockImplementation} from '../mock-implementation';test('Call function locally', async () => {expect(- await callLambdaSync({+ await mockImplementation.callFunctionSync({payload: {type: ServerlessRoutines.info,logLevel: 'info',diff --git a/packages/lambda/src/test/integration/renders/old-version.test.ts b/packages/lambda/src/test/integration/renders/old-version.test.tsindex 00de4ec526..13c4ced49b 100644--- a/packages/lambda/src/test/integration/renders/old-version.test.ts+++ b/packages/lambda/src/test/integration/renders/old-version.test.ts@@ -1,7 +1,7 @@import {RenderInternals} from '@remotion/renderer';import {ServerlessRoutines} from '@remotion/serverless/client';import {afterAll, expect, test} from 'vitest';-import {callLambdaSync} from '../../../shared/call-lambda-sync';+import {mockImplementation} from '../../mock-implementation';afterAll(async () => {await RenderInternals.killAllBrowsers();@@ -11,7 +11,7 @@ test('Should fail when using an incompatible version', async () => {process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '2048';try {- const aha = await callLambdaSync({+ const aha = await mockImplementation.callFunctionSync({type: ServerlessRoutines.launch,payload: {type: ServerlessRoutines.launch,diff --git a/packages/lambda/src/test/integration/simulate-lambda-render.ts b/packages/lambda/src/test/integration/simulate-lambda-render.tsindex 969d4abe62..e9f3121ff5 100644--- a/packages/lambda/src/test/integration/simulate-lambda-render.ts+++ b/packages/lambda/src/test/integration/simulate-lambda-render.ts@@ -5,15 +5,13 @@ import {VERSION} from 'remotion/version';import {makeLambdaRenderMediaPayload} from '../../api/make-lambda-payload';import type {RenderMediaOnLambdaInput} from '../../api/render-media-on-lambda';import {renderMediaOnLambdaOptionalToRequired} from '../../api/render-media-on-lambda';-import type {AwsProvider} from '../../functions/aws-implementation';-import {callLambdaSync} from '../../shared/call-lambda-sync';import {mockImplementation} from '../mock-implementation';const functionName = 'remotion-dev-render';const waitUntilDone = async (bucketName: string, renderId: string) => {while (true) {- const progress = await callLambdaSync({+ const progress = await mockImplementation.callFunctionSync({type: ServerlessRoutines.status,payload: {type: ServerlessRoutines.status,@@ -69,13 +67,14 @@ export const simulateLambdaRender = async (}),);- const res = await callLambdaSync<AwsProvider, ServerlessRoutines.start>({- type: ServerlessRoutines.start,- payload,- functionName: 'remotion-dev-lambda',- region: 'eu-central-1',- timeoutInTest: 120000,- });+ const res =+ await mockImplementation.callFunctionSync<ServerlessRoutines.start>({+ type: ServerlessRoutines.start,+ payload,+ functionName: 'remotion-dev-lambda',+ region: 'eu-central-1',+ timeoutInTest: 120000,+ });const progress = await waitUntilDone(res.bucketName, res.renderId);diff --git a/packages/lambda/src/test/integration/webhooks.test.ts b/packages/lambda/src/test/integration/webhooks.test.tsindex 8c772a1b14..b4dee22318 100644--- a/packages/lambda/src/test/integration/webhooks.test.ts+++ b/packages/lambda/src/test/integration/webhooks.test.ts@@ -4,7 +4,7 @@ import path from 'path';import {VERSION} from 'remotion/version';import {beforeAll, beforeEach, describe, expect, test, vi} from 'vitest';import {mockableHttpClients} from '../../functions/http-client';-import {callLambdaSync} from '../../shared/call-lambda-sync';+import {mockImplementation} from '../mock-implementation';const originalFetch = mockableHttpClients.http;beforeEach(() => {@@ -57,7 +57,7 @@ describe('Webhooks', () => {forceIPv4: false,});- const res = await callLambdaSync({+ const res = await mockImplementation.callFunctionSync({type: ServerlessRoutines.start,payload: {type: ServerlessRoutines.start,@@ -122,7 +122,7 @@ describe('Webhooks', () => {});const parsed = res;- await callLambdaSync({+ await mockImplementation.callFunctionSync({type: ServerlessRoutines.status,payload: {type: ServerlessRoutines.status,@@ -175,7 +175,7 @@ describe('Webhooks', () => {forceIPv4: false,});- await callLambdaSync({+ await mockImplementation.callFunctionSync({functionName: 'remotion-dev-lambda',region: 'us-east-1',type: ServerlessRoutines.launch,diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.tsindex 059f9fbaa5..c578518233 100644--- a/packages/lambda/src/test/mock-implementation.ts+++ b/packages/lambda/src/test/mock-implementation.ts@@ -2,6 +2,11 @@ import type {ProviderSpecifics} from '@remotion/serverless';import {Readable} from 'stream';import type {AwsProvider} from '../functions/aws-implementation';import {convertToServeUrlImplementation} from '../shared/convert-to-serve-url';+import {+ getMockCallFunctionAsync,+ getMockCallFunctionStreaming,+ getMockCallFunctionSync,+} from './mocks/aws-clients';import {addMockBucket,getMockBuckets,@@ -120,4 +125,7 @@ export const mockImplementation: ProviderSpecifics<AwsProvider> = {s3Key: 'key',}),validateDeleteAfter: () => {},+ callFunctionAsync: getMockCallFunctionAsync,+ callFunctionStreaming: getMockCallFunctionStreaming,+ callFunctionSync: getMockCallFunctionSync,};diff --git a/packages/lambda/src/test/mocks/aws-clients.ts b/packages/lambda/src/test/mocks/aws-clients.tsnew file mode 100644index 0000000000..4c8596b004--- /dev/null+++ b/packages/lambda/src/test/mocks/aws-clients.ts@@ -0,0 +1,88 @@+import type {+ CallFunctionAsync,+ CallFunctionOptions,+ CallFunctionStreaming,+ CallFunctionSync,+ OnMessage,+ ServerlessReturnValues,+ ServerlessRoutines,+} from '@remotion/serverless';+import {ResponseStream} from '@remotion/serverless';+import type {AwsProvider} from '../../functions/aws-implementation';+import {mockImplementation} from '../mock-implementation';++export const getMockCallFunctionStreaming: CallFunctionStreaming<+ AwsProvider+> = async <T extends ServerlessRoutines>(+ params: CallFunctionOptions<T, AwsProvider> & {+ receivedStreamingPayload: OnMessage<AwsProvider>;+ retriesRemaining: number;+ },+) => {+ const {innerRoutine} = await import('../../functions/index');++ const responseStream = new ResponseStream();+ await innerRoutine<AwsProvider>(+ params.payload,+ responseStream,+ {+ invokedFunctionArn: 'arn:fake',+ getRemainingTimeInMillis: () => params.timeoutInTest ?? 120000,+ awsRequestId: 'fake',+ },+ mockImplementation,+ );++ responseStream._finish();+ responseStream.end();+};++export const getMockCallFunctionAsync: CallFunctionAsync<AwsProvider> = async <+ T extends ServerlessRoutines,+>(+ params: CallFunctionOptions<T, AwsProvider>,+) => {+ const {innerRoutine} = await import('../../functions/index');++ const responseStream = new ResponseStream();+ await innerRoutine<AwsProvider>(+ params.payload,+ responseStream,+ {+ invokedFunctionArn: 'arn:fake',+ getRemainingTimeInMillis: () => params.timeoutInTest ?? 120000,+ awsRequestId: 'fake',+ },+ mockImplementation,+ );++ responseStream._finish();+ responseStream.end();+};++export const getMockCallFunctionSync: CallFunctionSync<AwsProvider> = async <+ T extends ServerlessRoutines,+>(+ params: CallFunctionOptions<T, AwsProvider>,+): Promise<ServerlessReturnValues<AwsProvider>[T]> => {+ const {innerRoutine} = await import('../../functions/index');++ const responseStream = new ResponseStream();+ await innerRoutine<AwsProvider>(+ params.payload,+ responseStream,+ {+ invokedFunctionArn: 'arn:fake',+ getRemainingTimeInMillis: () => params.timeoutInTest ?? 120000,+ awsRequestId: 'fake',+ },+ mockImplementation,+ );++ responseStream._finish();+ responseStream.end();++ return JSON.parse(+ new TextDecoder().decode(responseStream.getBufferedData()),+ ) as ServerlessReturnValues<AwsProvider>[T];+};diff --git a/packages/lambda/src/test/setup.ts b/packages/lambda/src/test/setup.tsindex 3fb988c311..33806afbf1 100644--- a/packages/lambda/src/test/setup.ts+++ b/packages/lambda/src/test/setup.ts@@ -18,9 +18,6 @@ vi.mock('../shared/bundle-site', () =>vi.mock('../shared/get-account-id', () =>vi.importActual('../shared/__mocks__/get-account-id'),);-vi.mock('../shared/aws-clients', () =>- vi.importActual('../shared/__mocks__/aws-clients'),-);vi.mock('../shared/read-dir', () =>vi.importActual('../shared/__mocks__/read-dir'),);diff --git a/packages/lambda/src/test/unit/handlers.test.ts b/packages/lambda/src/test/unit/handlers.test.tsindex 3fe5206045..2aa6b52011 100644--- a/packages/lambda/src/test/unit/handlers.test.ts+++ b/packages/lambda/src/test/unit/handlers.test.ts@@ -1,9 +1,9 @@import {ServerlessRoutines} from '@remotion/serverless/client';import {expect, test} from 'vitest';-import {callLambdaSync} from '../../shared/call-lambda-sync';+import {mockImplementation} from '../mock-implementation';test('Info handler should return version', async () => {- const response = await callLambdaSync({+ const response = await mockImplementation.callFunctionSync({type: ServerlessRoutines.info,payload: {logLevel: 'info',diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.tsindex e5e0358098..e15bbbc122 100644--- a/packages/serverless/src/index.ts+++ b/packages/serverless/src/index.ts@@ -1,6 +1,6 @@export {compositionsHandler} from './compositions';-export {PostRenderData} from './constants';+export {PostRenderData, ServerlessRoutines} from './constants';export {getCredentialsFromOutName} from './expected-out-name';export {forgetBrowserEventLoop,@@ -19,11 +19,16 @@ export {makeOverallRenderProgress,} from './overall-render-progress';export {+ BucketWithLocation,+ CallFunctionAsync,+ CallFunctionStreaming,+ CallFunctionSync,MakeArtifactWithDetails,ProviderSpecifics,WriteFileInput,} from './provider-implementation';export type {CleanupInfo, GenericRenderProgress} from './render-progress';+export {OrError, ServerlessReturnValues} from './return-values';export {deserializeArtifact, serializeArtifact} from './serialize-artifact';export {ResponseStream} from './streaming/response-stream';export {ResponseStreamWriter, streamWriter} from './streaming/stream-writer';diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.tsindex b98094bea3..735451fafd 100644--- a/packages/serverless/src/provider-implementation.ts+++ b/packages/serverless/src/provider-implementation.ts@@ -1,8 +1,19 @@import type {EmittedArtifact} from '@remotion/renderer';import type {Readable} from 'stream';-import type {CustomCredentials, DownloadBehavior, Privacy} from './constants';+import type {+ CustomCredentials,+ DownloadBehavior,+ Privacy,+ ServerlessRoutines,+} from './constants';import type {GetFolderFiles} from './get-files-in-folder';-import type {CloudProvider, ReceivedArtifact} from './types';+import type {ServerlessReturnValues} from './return-values';+import type {OnMessage} from './streaming/streaming';+import type {+ CallFunctionOptions,+ CloudProvider,+ ReceivedArtifact,+} from './types';export type BucketWithLocation<Provider extends CloudProvider> = {name: string;@@ -118,6 +129,35 @@ export type MakeArtifactWithDetails<Provider extends CloudProvider> = (params: {artifact: EmittedArtifact;}) => ReceivedArtifact<Provider>;+export type CallFunctionAsync<Provider extends CloudProvider> = <+ T extends ServerlessRoutines,+>({+ functionName,+ payload,+ region,+ timeoutInTest,+}: CallFunctionOptions<T, Provider>) => Promise<void>;++export type CallFunctionStreaming<Provider extends CloudProvider> = <+ T extends ServerlessRoutines,+>(+ options: CallFunctionOptions<T, Provider> & {+ receivedStreamingPayload: OnMessage<Provider>;+ retriesRemaining: number;+ },+) => Promise<void>;++export type CallFunctionSync<Provider extends CloudProvider> = <+ T extends ServerlessRoutines,+>({+ functionName,+ payload,+ region,+ timeoutInTest,+}: CallFunctionOptions<T, Provider>) => Promise<+ ServerlessReturnValues<Provider>[T]+>;+export type ProviderSpecifics<Provider extends CloudProvider> = {getChromiumPath: () => string | null;getCurrentRegionInFunction: () => Provider['region'];@@ -136,4 +176,7 @@ export type ProviderSpecifics<Provider extends CloudProvider> = {getFolderFiles: GetFolderFiles;makeArtifactWithDetails: MakeArtifactWithDetails<Provider>;validateDeleteAfter: (lifeCycleValue: unknown) => void;+ callFunctionAsync: CallFunctionAsync<Provider>;+ callFunctionStreaming: CallFunctionStreaming<Provider>;+ callFunctionSync: CallFunctionSync<Provider>;};diff --git a/packages/serverless/src/return-values.ts b/packages/serverless/src/return-values.tsnew file mode 100644index 0000000000..d5a3fba3e4--- /dev/null+++ b/packages/serverless/src/return-values.ts@@ -0,0 +1,45 @@+import type {VideoConfig} from 'remotion/no-react';+import type {ServerlessRoutines} from './constants';+import type {GenericRenderProgress} from './render-progress';+import type {CloudProvider} from './types';++export type OrError<T> =+ | T+ | {+ type: 'error';+ message: string;+ stack: string;+ };++export interface ServerlessReturnValues<Provider extends CloudProvider> {+ [ServerlessRoutines.start]: Promise<{+ type: 'success';+ bucketName: string;+ renderId: string;+ }>;+ [ServerlessRoutines.launch]: Promise<{+ type: 'success';+ }>;+ [ServerlessRoutines.renderer]: Promise<{+ type: 'success';+ }>;+ [ServerlessRoutines.status]: Promise<GenericRenderProgress<Provider>>;+ [ServerlessRoutines.info]: {+ version: string;+ type: 'success';+ };+ [ServerlessRoutines.still]: Promise<+ | {+ type: 'success';+ }+ | {+ type: 'error';+ message: string;+ stack: string;+ }+ >;+ [ServerlessRoutines.compositions]: Promise<{+ compositions: VideoConfig[];+ type: 'success';+ }>;+}diff --git a/packages/serverless/src/types.ts b/packages/serverless/src/types.tsindex 393ce2fdfc..5e25269f79 100644--- a/packages/serverless/src/types.ts+++ b/packages/serverless/src/types.ts@@ -1,3 +1,5 @@+import type {ServerlessPayloads, ServerlessRoutines} from './constants';+export interface CloudProvider<Region extends string = string,ReceivedArtifactType extends Record<string, unknown> = Record<@@ -47,3 +49,14 @@ export type ParsedTiming = {start: number;rendered: number;};++export type CallFunctionOptions<+ T extends ServerlessRoutines,+ Provider extends CloudProvider,+> = {+ functionName: string;+ type: T;+ payload: ServerlessPayloads<Provider>[T];+ region: Provider['region'];+ timeoutInTest: number;+};