Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nextAppendPosition #25

Merged
merged 3 commits into from
Oct 26, 2024
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 index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
OwnerType,
UserMeta,
ObjectCallback,
DeleteObjectResult,
} from 'oss-interface';

export * from 'oss-interface';
Expand Down Expand Up @@ -892,7 +893,7 @@ export class Client implements IObjectSimple {
/**
* Delete an object from the bucket.
*/
delete(name: string, options?: RequestOptions): Promise<NormalSuccessResponse>;
delete(name: string, options?: RequestOptions): Promise<DeleteObjectResult>;

/**
* Copy an object from sourceName to name.
Expand Down
3 changes: 2 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
GetStreamResult,
CopyObjectOptions,
CopyAndPutMetaResult,
DeleteObjectResult,
Client,
ImageClient,
ClusterClient,
Expand Down Expand Up @@ -49,7 +50,7 @@ class SimpleClient implements IObjectSimple {
console.log(name, options);
return {} as any;
}
async delete(name: string, options?: RequestOptions): Promise<NormalSuccessResponse> {
async delete(name: string, options?: RequestOptions): Promise<DeleteObjectResult> {
console.log(name, options);
return {} as any;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ proto.requestError = async function requestError(result) {
err.code = info.Code;
err.requestId = info.RequestId;
err.hostId = info.HostId;
// https://help.aliyun.com/zh/oss/support/http-status-code-409#section-rmc-hvd-j38
if (info.Code === 'PositionNotEqualToLength' && result.headers && result.headers['x-oss-next-append-position']) {
err.nextAppendPosition = result.headers['x-oss-next-append-position'];
}
}

debug('generate error %j', err);
Expand Down
18 changes: 9 additions & 9 deletions test/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ describe('test/object.test.js', () => {
});
});

describe('list()', () => {
describe.skip('list()', () => {
// oss.jpg
// fun/test.jpg
// fun/movie/001.avi
Expand Down Expand Up @@ -1838,7 +1838,7 @@ describe('test/object.test.js', () => {
});
});

describe('listV2()', () => {
describe.skip('listV2()', () => {
let listPrefix;
before(async () => {
listPrefix = `${prefix}oss-client/listV2/`;
Expand Down Expand Up @@ -2075,13 +2075,13 @@ describe('test/object.test.js', () => {
it('should error when positio not match', async () => {
await store.append(name, Buffer.from('foo'));

try {
await store.append(name, Buffer.from('foo'));
throw new Error('should not run');
} catch (err) {
assert(err.message === 'Position is not equal to file length');
assert(err.name === 'PositionNotEqualToLengthError');
}
await assert.rejects(
store.append(name, Buffer.from('foo')),
err =>
err.message === 'Position is not equal to file length' &&
err.name === 'PositionNotEqualToLengthError' &&
err.nextAppendPosition === '3'
);
});

it('should use nextAppendPosition to append next', async () => {
Expand Down
Loading