-
Notifications
You must be signed in to change notification settings - Fork 579
feat: add data indexing API #1255
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
cd013af
3cb6708
41353f3
666daf1
f622f44
e500a78
77d6011
b4d8cc8
c4ad08b
8fed76e
c7a25fa
96ed6e2
4edb387
5fdbd7d
907679b
d6288a8
6fcf079
8dcdfe0
4539878
28bb997
7fefdc0
9d415be
06055d5
b8b8d1b
5b2aac2
3163622
f815df7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| export declare function openMetaQuery(this: any, bucketName: string, options?: {}): Promise<{ | ||
| res: any; | ||
| status: any; | ||
| }>; | ||
| export declare function getMetaQueryStatus(this: any, bucketName: string, options?: {}): Promise<{ | ||
| res: any; | ||
| status: any; | ||
| }>; | ||
| interface ISubQuerie { | ||
| field?: string; | ||
| value?: string; | ||
| operation: string; | ||
| subQueries?: ISubQuerie[]; | ||
| } | ||
| interface IAggregation { | ||
| field: string; | ||
| operation: string; | ||
| } | ||
| interface IMetaQuery { | ||
| nextToken?: string; | ||
| maxResults?: number; | ||
| query: ISubQuerie; | ||
| sort?: string; | ||
| order?: 'asc' | 'desc'; | ||
| aggregations?: IAggregation[]; | ||
| } | ||
| export declare function doMetaQuery(this: any, bucketName: string, queryParam: IMetaQuery, options?: {}): Promise<{ | ||
| res: any; | ||
| status: any; | ||
| }>; | ||
| export declare function closeMetaQuery(this: any, bucketName: string, options?: {}): Promise<{ | ||
| res: any; | ||
| status: any; | ||
| }>; | ||
| export {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.closeMetaQuery = exports.doMetaQuery = exports.getMetaQueryStatus = exports.openMetaQuery = void 0; | ||
| const checkBucketName_1 = require("../utils/checkBucketName"); | ||
| const obj2xml_1 = require("../utils/obj2xml"); | ||
| async function openMetaQuery(bucketName, options = {}) { | ||
| checkBucketName_1.checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('POST', bucketName, { metaQuery: '', comp: 'add' }, options); | ||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
| exports.openMetaQuery = openMetaQuery; | ||
| async function getMetaQueryStatus(bucketName, options = {}) { | ||
| checkBucketName_1.checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('GET', bucketName, 'metaQuery', options); | ||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
| exports.getMetaQueryStatus = getMetaQueryStatus; | ||
| async function doMetaQuery(bucketName, queryParam, options = {}) { | ||
| checkBucketName_1.checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('POST', bucketName, { metaQuery: '', comp: 'query' }, options); | ||
| const { aggregations } = queryParam; | ||
| let Aggregations; | ||
| if (aggregations && aggregations.length > 0) { | ||
| Aggregations = { | ||
| Aggregation: aggregations.map(item => ({ Field: item.field, Operation: item.operation })) | ||
| }; | ||
| } | ||
| const paramXMLObj = { | ||
| MetaQuery: { | ||
| NextToken: queryParam.nextToken, | ||
| MaxResults: queryParam.maxResults, | ||
| Query: JSON.stringify(queryParam.query), | ||
| Sort: queryParam.sort, | ||
| Order: queryParam.order, | ||
| Aggregations | ||
| } | ||
| }; | ||
| params.mime = 'xml'; | ||
| params.content = obj2xml_1.obj2xml(paramXMLObj); | ||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
| exports.doMetaQuery = doMetaQuery; | ||
| async function closeMetaQuery(bucketName, options = {}) { | ||
| checkBucketName_1.checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('POST', bucketName, { metaQuery: '', comp: 'delete' }, options); | ||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
| exports.closeMetaQuery = closeMetaQuery; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // https://help.aliyun.com/zh/oss/developer-reference/data-indexing | ||
| import { checkBucketName } from '../utils/checkBucketName'; | ||
| import { obj2xml } from '../utils/obj2xml'; | ||
|
|
||
| export async function openMetaQuery(this: any, bucketName: string, options = {}) { | ||
| checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('POST', bucketName, { metaQuery: '', comp: 'add' }, options); | ||
shungang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
|
|
||
| export async function getMetaQueryStatus(this: any, bucketName: string, options = {}) { | ||
| checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('GET', bucketName, 'metaQuery', options); | ||
|
|
||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
|
|
||
| interface ISubQuerie { | ||
shungang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // https://help.aliyun.com/zh/oss/developer-reference/appendix-supported-fields-and-operators | ||
| field?: string; | ||
| value?: string; | ||
| // 操作符。取值范围为eq(等于)、gt(大于)、gte(大于等于)、lt(小于)、 lte(小于等于)、match(模糊查询)、prefix(前缀查询)、and(逻辑与)、or(逻辑或)和not(逻辑非)。 | ||
| operation: string; | ||
| subQueries?: ISubQuerie[]; | ||
| } | ||
|
|
||
| interface IAggregation { | ||
| field: string; | ||
| operation: string; | ||
| } | ||
|
|
||
| interface IMetaQuery { | ||
| nextToken?: string; | ||
| maxResults?: number; | ||
| query: ISubQuerie; | ||
| sort?: string; | ||
| order?: 'asc' | 'desc'; | ||
| aggregations?: IAggregation[]; | ||
| } | ||
|
|
||
| export async function doMetaQuery(this: any, bucketName: string, queryParam: IMetaQuery, options = {}) { | ||
| checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('POST', bucketName, { metaQuery: '', comp: 'query' }, options); | ||
|
|
||
| const { aggregations } = queryParam; | ||
| let Aggregations; | ||
shungang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (aggregations && aggregations.length > 0) { | ||
| Aggregations = { | ||
| Aggregation: aggregations.map(item => ({ Field: item.field, Operation: item.operation })) | ||
| }; | ||
| } | ||
|
|
||
| const paramXMLObj = { | ||
| MetaQuery: { | ||
| NextToken: queryParam.nextToken, | ||
| MaxResults: queryParam.maxResults, | ||
| Query: JSON.stringify(queryParam.query), | ||
|
||
| Sort: queryParam.sort, | ||
| Order: queryParam.order, | ||
| Aggregations | ||
| } | ||
| }; | ||
| params.mime = 'xml'; | ||
| params.content = obj2xml(paramXMLObj); | ||
|
|
||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
|
|
||
| export async function closeMetaQuery(this: any, bucketName: string, options = {}) { | ||
| checkBucketName(bucketName); | ||
| const params = this._bucketRequestParams('POST', bucketName, { metaQuery: '', comp: 'delete' }, options); | ||
|
|
||
| const result = await this.request(params); | ||
| return { | ||
| res: result.res, | ||
| status: result.status | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ const cleanBucket = async store => { | |
| const uploads = result.uploads || []; | ||
| await Promise.all(uploads.map(_ => store.abortMultipartUpload(_.name, _.uploadId))); | ||
| }; | ||
|
|
||
| describe('browser', () => { | ||
| /* eslint require-yield: [0] */ | ||
| before(() => { | ||
|
|
@@ -2509,4 +2510,26 @@ describe('browser', () => { | |
| } | ||
| }); | ||
| }); | ||
|
|
||
| // oss server 不支持跨域 大概要到9月30号才上生产支持 跨域,后端是:云仁 | ||
|
||
| describe.skip('bucket data index', () => { | ||
| let store; | ||
| before(async () => { | ||
| store = oss({ ...ossConfig, refreshSTSTokenInterval: 1000 }); | ||
| }); | ||
|
|
||
| it('open meta query of bucket', async () => { | ||
| try { | ||
| // await store.listV2({ 'max-keys': 1 }); | ||
| // const result = await store.getMetaQueryStatus(stsConfig.bucket); // oss server does not support cross domain | ||
| const result = await store.openMetaQuery(stsConfig.bucket); | ||
| console.log('rr', result); | ||
| assert.strictEqual(result.status, 200); | ||
| assert.deepEqual(result.res.statusMessage, 'OK'); | ||
| } catch (error) { | ||
|
||
| console.log('bb', JSON.stringify(error), error); | ||
| assert.fail(error); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1480,4 +1480,63 @@ describe('test/bucket.test.js', () => { | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('openMetaQuery() openMetaQuery() doMetaQuery() closeMetaQuery()', () => { | ||
|
||
| it('open meta query of bucket', async () => { | ||
| try { | ||
| const result = await store.openMetaQuery(bucket); | ||
| assert.strictEqual(result.status, 200); | ||
| assert.deepEqual(result.res.statusMessage, 'OK'); | ||
| } catch (error) { | ||
| assert.fail(error); | ||
| } | ||
| }); | ||
|
|
||
| it('getMetaQueryStatus()', async () => { | ||
| try { | ||
| const result = await store.getMetaQueryStatus(bucket); | ||
| assert.strictEqual(result.status, 200); | ||
| assert.deepEqual(result.res.statusMessage, 'OK'); | ||
| } catch (error) { | ||
| assert.fail(error); | ||
| } | ||
| }); | ||
|
|
||
| it('doMetaQuery()', async () => { | ||
| try { | ||
| const queryParam = { | ||
| query: { operation: 'and', subQueries: [{ Field: 'Size', Value: '1048576', Operation: 'lt' }] } | ||
|
||
| }; | ||
| const result = await store.doMetaQuery(bucket, queryParam); | ||
| assert.strictEqual(result.status, 200); | ||
| assert.deepEqual(result.res.statusMessage, 'OK'); | ||
| } catch (error) { | ||
| assert.fail(error); | ||
| } | ||
| }); | ||
|
|
||
| it('doMetaQuery() Aggregations', async () => { | ||
| try { | ||
| const queryParam = { | ||
| query: { operation: 'and', subQueries: [{ Field: 'Size', Value: '1048576', Operation: 'lt' }] }, | ||
|
||
| aggregations: [{ field: 'Size', operation: 'sum' }] | ||
| }; | ||
| const result = await store.doMetaQuery(bucket, queryParam); | ||
| assert.strictEqual(result.status, 200); | ||
| assert.deepEqual(result.res.statusMessage, 'OK'); | ||
| } catch (error) { | ||
| assert.fail(error); | ||
| } | ||
| }); | ||
|
|
||
| it('closeMetaQuery()', async () => { | ||
shungang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| const result = await store.closeMetaQuery(bucket); | ||
| assert.strictEqual(result.status, 200); | ||
| assert.deepEqual(result.res.statusMessage, 'OK'); | ||
| } catch (error) { | ||
| assert.fail(error); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.