Skip to content
Draft
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
21 changes: 19 additions & 2 deletions packages/hub/src/lib/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,26 @@ export type CommitParams = {
*/
useXet?: boolean;
// Credentials are optional due to custom fetch functions or cookie auth

/**
* If queued, will not return commit information in the output
*/
mode?: "queued" | "immediate";
} & Partial<CredentialsParams>;

export interface CommitOutput {
pullRequestUrl?: string;
commit: {
/**
* Unset if queued commit, or empty commit
*/
commit?: {
oid: string;
url: string;
};
hookOutput: string;
/**
* Unset if queued commit, or empty commit
*/
hookOutput?: string;
}

function isFileOperation(op: CommitOperation): op is CommitBlob {
Expand Down Expand Up @@ -640,6 +651,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
summary: params.title,
description: params.description,
parentCommit: params.parentCommit,
mode: params.mode,
} satisfies ApiCommitHeader,
},
...((await Promise.all(
Expand Down Expand Up @@ -692,6 +704,11 @@ export async function* commitIter(params: CommitParams): AsyncGenerator<CommitPr
throw await createApiError(res);
}

if (res.status === 202) {
// Queued commit
returnCallback({});
}

const json = await res.json();

returnCallback({
Expand Down
2 changes: 2 additions & 0 deletions packages/hub/src/lib/delete-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function deleteFile(
branch?: CommitParams["branch"];
isPullRequest?: CommitParams["isPullRequest"];
parentCommit?: CommitParams["parentCommit"];
mode?: CommitParams["mode"];
} & CredentialsParams
): Promise<CommitOutput> {
return commit({
Expand All @@ -31,5 +32,6 @@ export function deleteFile(
isPullRequest: params.isPullRequest,
parentCommit: params.parentCommit,
fetch: params.fetch,
mode: params.mode,
});
}
2 changes: 2 additions & 0 deletions packages/hub/src/lib/delete-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function deleteFiles(
branch?: CommitParams["branch"];
isPullRequest?: CommitParams["isPullRequest"];
parentCommit?: CommitParams["parentCommit"];
mode?: CommitParams["mode"];
fetch?: CommitParams["fetch"];
} & CredentialsParams
): Promise<CommitOutput> {
Expand All @@ -29,5 +30,6 @@ export function deleteFiles(
isPullRequest: params.isPullRequest,
parentCommit: params.parentCommit,
fetch: params.fetch,
mode: params.mode,
});
}
2 changes: 2 additions & 0 deletions packages/hub/src/lib/upload-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function uploadFile(
useWebWorkers?: CommitParams["useWebWorkers"];
abortSignal?: CommitParams["abortSignal"];
useXet?: CommitParams["useXet"];
mode?: CommitParams["mode"];
} & Partial<CredentialsParams>
): Promise<CommitOutput> {
const path =
Expand Down Expand Up @@ -45,5 +46,6 @@ export function uploadFile(
useWebWorkers: params.useWebWorkers,
abortSignal: params.abortSignal,
useXet: params.useXet,
mode: params.mode,
});
}
2 changes: 2 additions & 0 deletions packages/hub/src/lib/upload-files-with-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function* uploadFilesWithProgress(
abortSignal?: CommitParams["abortSignal"];
maxFolderDepth?: CommitParams["maxFolderDepth"];
useXet?: CommitParams["useXet"];
mode?: CommitParams["mode"];
/**
* Set this to true in order to have progress events for hashing
*/
Expand All @@ -53,6 +54,7 @@ export async function* uploadFilesWithProgress(
useWebWorkers: params.useWebWorkers,
abortSignal: params.abortSignal,
useXet: params.useXet,
mode: params.mode,
fetch: async (input, init) => {
if (!init) {
return fetch(input);
Expand Down
2 changes: 2 additions & 0 deletions packages/hub/src/lib/upload-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function uploadFiles(
fetch?: CommitParams["fetch"];
useWebWorkers?: CommitParams["useWebWorkers"];
maxFolderDepth?: CommitParams["maxFolderDepth"];
mode?: CommitParams["mode"];
abortSignal?: CommitParams["abortSignal"];
useXet?: CommitParams["useXet"];
} & Partial<CredentialsParams>
Expand All @@ -37,5 +38,6 @@ export function uploadFiles(
useWebWorkers: params.useWebWorkers,
abortSignal: params.abortSignal,
useXet: params.useXet,
mode: params.mode,
});
}
6 changes: 6 additions & 0 deletions packages/hub/src/types/api/api-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ export interface ApiCommitHeader {
* - When committing on a branch: Will make sure that there were no intermediate commits
*/
parentCommit?: string;
/**
* queued => commit is pending
* immediate => commit is processed immediately
* flush => all pending commits are processed and merged into one commit
*/
mode?: "queued" | "immediate" | "flush";
}

export interface ApiCommitDeletedEntry {
Expand Down
Loading