forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(storage): omit subPathStrategy when prefix is defined (aws-amplif…
…y#13618) * fix(storage): omit subPathStrategy when prefix is defined (aws-amplify#13606) * fix: omit subPathStrategy on prefix * chore: fix build * chore: address feedback * chore: omit subpathStrategy from options * chore: add unit tests * chore: update tests * chore: fix test * chore: move subpathstrategy to service options * chore: update comment * chore: fix type
- Loading branch information
Showing
6 changed files
with
185 additions
and
12 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
packages/storage/__tests__/providers/s3/types/list.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* eslint-disable unused-imports/no-unused-vars */ | ||
|
||
import { StorageAccessLevel } from '@aws-amplify/core'; | ||
|
||
import { | ||
ListAllInput, | ||
ListAllOutput, | ||
ListAllWithPathInput, | ||
ListAllWithPathOutput, | ||
ListOutputItem, | ||
ListOutputItemWithPath, | ||
ListPaginateInput, | ||
ListPaginateOutput, | ||
ListPaginateWithPathInput, | ||
ListPaginateWithPathOutput, | ||
} from '../../../../src/providers/s3/types'; | ||
import { StorageSubpathStrategy } from '../../../../src/types'; | ||
|
||
import { Equal, Expect } from './utils'; | ||
|
||
interface Input { | ||
targetIdentityId?: string; | ||
prefix?: string; | ||
path: string; | ||
subpathStrategy?: StorageSubpathStrategy; | ||
nextToken: string; | ||
pageSize: number; | ||
useAccelerateEndpoint: boolean; | ||
accessLevel: StorageAccessLevel; | ||
listAll: boolean; | ||
} | ||
|
||
interface Output { | ||
listOutputItems: ListOutputItem[]; | ||
listOutputItemsWithPath: ListOutputItemWithPath[]; | ||
excludedSubpaths: string[]; | ||
nextToken: string; | ||
} | ||
|
||
describe('List API input types', () => { | ||
test('should compile', () => { | ||
function handleTest({ | ||
targetIdentityId, | ||
prefix, | ||
path, | ||
subpathStrategy, | ||
nextToken, | ||
pageSize, | ||
useAccelerateEndpoint, | ||
accessLevel, | ||
}: Input) { | ||
const listPaginateInput: ListPaginateInput = { | ||
prefix, | ||
options: { | ||
accessLevel: 'protected', | ||
targetIdentityId, | ||
// @ts-expect-error subpathStrategy is not part of this input | ||
subpathStrategy, | ||
}, | ||
}; | ||
|
||
const listAllInput: ListAllInput = { | ||
prefix, | ||
options: { | ||
listAll: true, | ||
accessLevel: 'protected', | ||
targetIdentityId, | ||
// @ts-expect-error subpathStrategy is not part of this input | ||
subpathStrategy, | ||
}, | ||
}; | ||
|
||
const listPaginateWithPathInput: ListPaginateWithPathInput = { | ||
path, | ||
options: { | ||
subpathStrategy, | ||
useAccelerateEndpoint, | ||
pageSize, | ||
nextToken, | ||
}, | ||
}; | ||
|
||
const listAllWithPathInput: ListAllWithPathInput = { | ||
path, | ||
options: { | ||
listAll: true, | ||
subpathStrategy, | ||
useAccelerateEndpoint, | ||
// @ts-expect-error pageSize is not part of this input | ||
pageSize, | ||
}, | ||
}; | ||
|
||
type Tests = [ | ||
Expect<Equal<typeof listPaginateInput, ListPaginateInput>>, | ||
Expect<Equal<typeof listAllInput, ListAllInput>>, | ||
Expect< | ||
Equal<typeof listPaginateWithPathInput, ListPaginateWithPathInput> | ||
>, | ||
Expect<Equal<typeof listAllWithPathInput, ListAllWithPathInput>>, | ||
]; | ||
type Result = Expect<Equal<Tests, [true, true, true, true]>>; | ||
} | ||
}); | ||
}); | ||
|
||
describe('List API ouput types', () => { | ||
test('should compile', () => { | ||
function handleTest({ | ||
listOutputItems, | ||
nextToken, | ||
excludedSubpaths, | ||
listOutputItemsWithPath, | ||
}: Output) { | ||
const listPaginateOutput: ListPaginateOutput = { | ||
items: listOutputItems, | ||
nextToken, | ||
// @ts-expect-error excludeSubpaths is not part of this output | ||
excludedSubpaths, | ||
}; | ||
|
||
const listAllOutput: ListAllOutput = { | ||
items: listOutputItems, | ||
// @ts-expect-error excludeSubpaths is not part of this output | ||
excludedSubpaths, | ||
}; | ||
|
||
const listPaginateWithPathOutput: ListPaginateWithPathOutput = { | ||
items: listOutputItemsWithPath, | ||
nextToken, | ||
excludedSubpaths, | ||
}; | ||
|
||
const listAllWithPathOutput: ListAllWithPathOutput = { | ||
items: listOutputItemsWithPath, | ||
excludedSubpaths, | ||
}; | ||
|
||
type Tests = [ | ||
Expect<Equal<typeof listPaginateOutput, ListPaginateOutput>>, | ||
Expect<Equal<typeof listAllOutput, ListAllOutput>>, | ||
Expect< | ||
Equal<typeof listPaginateWithPathOutput, ListPaginateWithPathOutput> | ||
>, | ||
Expect<Equal<typeof listAllWithPathOutput, ListAllWithPathOutput>>, | ||
]; | ||
|
||
type Result = Expect<Equal<Tests, [true, true, true, true]>>; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export type Expect<T extends true> = T; | ||
|
||
export type Equal<X, Y> = X extends Y ? true : false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters