mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-23 16:56:07 +00:00
elastic adapter
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
4f4a772630
commit
656d202dce
@ -1,6 +1,7 @@
|
||||
lockfileVersion: 5.3
|
||||
|
||||
specifiers:
|
||||
'@elastic/elasticsearch': ^7.14.0
|
||||
'@microsoft/api-extractor': ^7.18.4
|
||||
'@rush-temp/chunter': file:./projects/chunter.tgz
|
||||
'@rush-temp/chunter-assets': file:./projects/chunter-assets.tgz
|
||||
@ -114,6 +115,7 @@ specifiers:
|
||||
ws: ^8.0.0
|
||||
|
||||
dependencies:
|
||||
'@elastic/elasticsearch': 7.14.0
|
||||
'@microsoft/api-extractor': 7.18.4
|
||||
'@rush-temp/chunter': file:projects/chunter.tgz_6c259fadfeb3a4b20890aefe87070b8b
|
||||
'@rush-temp/chunter-assets': file:projects/chunter-assets.tgz
|
||||
@ -1496,8 +1498,8 @@ packages:
|
||||
resolution: {integrity: sha512-bLL69sKtd25w7p1nvg9pigE4gtKVpGTPojBFLMkGHXuUgap2sLqQt2qUnqmVCDfzGUL0DRNZP+1prIZJbMeAXg==}
|
||||
dev: false
|
||||
|
||||
/@types/node/16.6.2:
|
||||
resolution: {integrity: sha512-LSw8TZt12ZudbpHc6EkIyDM3nHVWKYrAvGy6EAJfNfjusbwnThqjqxUKKRwuV3iWYeW/LYMzNgaq3MaLffQ2xA==}
|
||||
/@types/node/16.7.1:
|
||||
resolution: {integrity: sha512-ncRdc45SoYJ2H4eWU9ReDfp3vtFqDYhjOsKlFFUDEn8V1Bgr2RjYal8YT5byfadWIRluhPFU6JiDOl0H6Sl87A==}
|
||||
dev: false
|
||||
|
||||
/@types/normalize-package-data/2.4.1:
|
||||
@ -7971,7 +7973,7 @@ packages:
|
||||
webpack: 5.48.0_webpack-cli@4.7.2
|
||||
dev: false
|
||||
|
||||
/ts-node/10.2.1_c780171742f6906a053a603dfa210a4e:
|
||||
/ts-node/10.2.1_f50b86b1778cd2aa4e5405c08bb39559:
|
||||
resolution: {integrity: sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
hasBin: true
|
||||
@ -7991,7 +7993,7 @@ packages:
|
||||
'@tsconfig/node12': 1.0.9
|
||||
'@tsconfig/node14': 1.0.1
|
||||
'@tsconfig/node16': 1.0.2
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
acorn: 8.4.1
|
||||
acorn-walk: 8.1.1
|
||||
arg: 4.1.3
|
||||
@ -8925,7 +8927,7 @@ packages:
|
||||
dev: false
|
||||
|
||||
file:projects/dev-client-resources.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-3rGAbc0Gij6DxJYQOzbc1T3I5RWk/CntgVrFIi2VrPq7VeD9HUjdiM7cIhXMeSQKxf6gA0k+p4aQl1tin/LDlQ==, tarball: file:projects/dev-client-resources.tgz}
|
||||
resolution: {integrity: sha512-JZd7JnNl0F7B0MiUEgUC+m4ybTfwWiaElpVzIZqAOla3+HX4nRmsz6LROVXM5Ps7cWmSuQv2xbj0QaMfpxFuIw==, tarball: file:projects/dev-client-resources.tgz}
|
||||
id: file:projects/dev-client-resources.tgz
|
||||
name: '@rush-temp/dev-client-resources'
|
||||
version: 0.0.0
|
||||
@ -8961,7 +8963,7 @@ packages:
|
||||
dev: false
|
||||
|
||||
file:projects/dev-server.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-zWgSI+/Md+5RDVJv95MoAxsolQFzv9PT74+4oHtvHTeyDL/tdILju649GDZs4oywwUCCX8pDE2gpH/81bJ6h2Q==, tarball: file:projects/dev-server.tgz}
|
||||
resolution: {integrity: sha512-BAPKHjgNSQ/aiCpN5mtcz2jPYWyW5VixN5f82GFavAhqBIZinpy6K1mjY92KRsgoKSlts8A4TA5LNncQgOdvjQ==, tarball: file:projects/dev-server.tgz}
|
||||
id: file:projects/dev-server.tgz
|
||||
name: '@rush-temp/dev-server'
|
||||
version: 0.0.0
|
||||
@ -9003,7 +9005,7 @@ packages:
|
||||
dev: false
|
||||
|
||||
file:projects/elastic.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-enIBquVzvr+/JruE2aO0Z3HbTB0Pp3vK0czoahfJEN95XYePU0IBkO3D+zLWRznNZ16mC4W5/uwBb2uS+VdG9A==, tarball: file:projects/elastic.tgz}
|
||||
resolution: {integrity: sha512-TJMFjRCKTFiVvTUmHZXH2Z6dFAqMiQiXrvRr33eIqL8/x3a8a3qXGfcoXUoC1tjPUPOLqU9lqxTcXBJDLPwKrg==, tarball: file:projects/elastic.tgz}
|
||||
id: file:projects/elastic.tgz
|
||||
name: '@rush-temp/elastic'
|
||||
version: 0.0.0
|
||||
@ -9074,13 +9076,13 @@ packages:
|
||||
name: '@rush-temp/model-all'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
eslint: 7.32.0
|
||||
eslint-plugin-import: 2.23.4_eslint@7.32.0
|
||||
eslint-plugin-node: 11.1.0_eslint@7.32.0
|
||||
eslint-plugin-promise: 4.3.1
|
||||
ts-node: 10.2.1_c780171742f6906a053a603dfa210a4e
|
||||
ts-node: 10.2.1_f50b86b1778cd2aa4e5405c08bb39559
|
||||
transitivePeerDependencies:
|
||||
- '@swc/core'
|
||||
- '@swc/wasm'
|
||||
@ -9515,7 +9517,7 @@ packages:
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
'@types/ws': 7.4.7
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
eslint: 7.32.0
|
||||
@ -9535,7 +9537,7 @@ packages:
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
'@types/ws': 7.4.7
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
eslint: 7.32.0
|
||||
@ -9555,7 +9557,7 @@ packages:
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
'@types/ws': 7.4.7
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
eslint: 7.32.0
|
||||
@ -9580,14 +9582,14 @@ packages:
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
'@types/ws': 7.4.7
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
eslint: 7.32.0
|
||||
eslint-plugin-import: 2.23.4_eslint@7.32.0
|
||||
eslint-plugin-node: 11.1.0_eslint@7.32.0
|
||||
eslint-plugin-promise: 4.3.1
|
||||
ts-node: 10.2.1_c780171742f6906a053a603dfa210a4e
|
||||
ts-node: 10.2.1_f50b86b1778cd2aa4e5405c08bb39559
|
||||
transitivePeerDependencies:
|
||||
- '@swc/core'
|
||||
- '@swc/wasm'
|
||||
@ -9728,7 +9730,7 @@ packages:
|
||||
'@types/express': 4.17.13
|
||||
'@types/express-fileupload': 1.1.7
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.6.2
|
||||
'@types/node': 16.7.1
|
||||
'@types/uuid': 8.3.1
|
||||
'@types/ws': 7.4.7
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
@ -9740,7 +9742,7 @@ packages:
|
||||
eslint-plugin-promise: 4.3.1
|
||||
express: 4.17.1
|
||||
express-fileupload: 1.2.1
|
||||
ts-node: 10.2.1_c780171742f6906a053a603dfa210a4e
|
||||
ts-node: 10.2.1_f50b86b1778cd2aa4e5405c08bb39559
|
||||
uuid: 8.3.2
|
||||
transitivePeerDependencies:
|
||||
- '@swc/core'
|
||||
@ -9839,23 +9841,23 @@ packages:
|
||||
dev: false
|
||||
|
||||
file:projects/workspace.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-q2/1LqGkYRwsMNbjDjy4ngJlBDAefFWXuEdVyIN0DyBjmBibnEVZuQayjBh5O7xUQYKlT0A7TdVn99hpIwixOA==, tarball: file:projects/workspace.tgz}
|
||||
resolution: {integrity: sha512-LyUaHX4Kqn0fMCMfSsN4nIqIFtRzbRruDdSv5bfyefDF4WUfrYUdy8IUwuWuwmq5NTr49jLg9oLCyAJZ059Ong==, tarball: file:projects/workspace.tgz}
|
||||
id: file:projects/workspace.tgz
|
||||
name: '@rush-temp/workspace'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.7.1
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
eslint: 7.32.0
|
||||
eslint-plugin-import: 2.23.4_eslint@7.32.0
|
||||
eslint-plugin-node: 11.1.0_eslint@7.32.0
|
||||
eslint-plugin-promise: 4.3.1
|
||||
mongodb: 4.1.0
|
||||
ts-node: 10.2.1_typescript@4.3.5
|
||||
ts-node: 10.2.1_f50b86b1778cd2aa4e5405c08bb39559
|
||||
transitivePeerDependencies:
|
||||
- '@swc/core'
|
||||
- '@swc/wasm'
|
||||
- '@types/node'
|
||||
- '@typescript-eslint/parser'
|
||||
- supports-color
|
||||
- typescript
|
||||
|
26
server/elastic/src/__tests__/adapter.test.ts
Normal file
26
server/elastic/src/__tests__/adapter.test.ts
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
||||
// Copyright © 2021 Hardcore Engineering Inc.
|
||||
//
|
||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. You may
|
||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
//
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { Hierarchy } from '@anticrm/core'
|
||||
import { createElasticAdapter } from '../adapter'
|
||||
|
||||
describe('client', () => {
|
||||
it('should create adapter', async () => {
|
||||
const hierarchy = new Hierarchy()
|
||||
const [adapter, tx] = await createElasticAdapter(hierarchy, 'http://localhost:9200/', 'ws1')
|
||||
console.log(adapter, tx)
|
||||
})
|
||||
})
|
86
server/elastic/src/adapter.ts
Normal file
86
server/elastic/src/adapter.ts
Normal file
@ -0,0 +1,86 @@
|
||||
//
|
||||
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
||||
// Copyright © 2021 Hardcore Engineering Inc.
|
||||
//
|
||||
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License. You may
|
||||
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
//
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import core, { TxProcessor, Hierarchy, DOMAIN_TX } from '@anticrm/core'
|
||||
import type { Tx, Doc, Ref, Class, DocumentQuery, FindOptions, FindResult, TxCreateDoc } from '@anticrm/core'
|
||||
import type { DbAdapter } from '@anticrm/server-core'
|
||||
|
||||
import { Client } from '@elastic/elasticsearch'
|
||||
|
||||
function translateDoc (doc: Doc): any {
|
||||
const obj = { id: doc._id, ...doc } as any
|
||||
delete obj._id
|
||||
return obj
|
||||
}
|
||||
|
||||
class ElasticAdapter extends TxProcessor implements DbAdapter {
|
||||
constructor (
|
||||
private readonly client: Client,
|
||||
private readonly db: string,
|
||||
private readonly hierarchy: Hierarchy
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
async init (): Promise<void> {}
|
||||
|
||||
async findAll<T extends Doc> (
|
||||
_class: Ref<Class<T>>,
|
||||
query: DocumentQuery<T>,
|
||||
options?: FindOptions<T>
|
||||
): Promise<FindResult<T>> {
|
||||
throw new Error('not implemented')
|
||||
}
|
||||
|
||||
override async tx (tx: Tx): Promise<void> {
|
||||
console.log(tx)
|
||||
await this.client.index({
|
||||
index: this.db + '_' + DOMAIN_TX,
|
||||
type: '_doc',
|
||||
body: translateDoc(tx)
|
||||
})
|
||||
if (tx.objectSpace !== core.space.Tx && tx.objectSpace !== core.space.Model) {
|
||||
await super.tx(tx)
|
||||
}
|
||||
}
|
||||
|
||||
protected override async txCreateDoc (tx: TxCreateDoc<Doc>): Promise<void> {
|
||||
const doc = TxProcessor.createDoc2Doc(tx)
|
||||
const domain = this.hierarchy.getDomain(doc._class)
|
||||
await this.client.index({
|
||||
index: this.db + '_' + domain,
|
||||
type: '_doc',
|
||||
body: translateDoc(doc)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createElasticAdapter (hierarchy: Hierarchy, url: string, dbName: string): Promise<[DbAdapter, Tx[]]> {
|
||||
const client = new Client({
|
||||
node: url
|
||||
})
|
||||
|
||||
return [new ElasticAdapter(client, dbName, hierarchy), []]
|
||||
|
||||
// const client = new MongoClient(url)
|
||||
// await client.connect()
|
||||
// const db = client.db(dbName)
|
||||
// const txes = await db.collection(DOMAIN_TX).find<Tx>({ objectSpace: core.space.Model }).sort({ _id: 1 }).toArray()
|
||||
// return [new MongoAdapter(db, hierarchy), txes]
|
||||
}
|
@ -14,7 +14,4 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const x = 42
|
||||
export { createElasticAdapter } from './adapter'
|
||||
|
Loading…
Reference in New Issue
Block a user