mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 20:45:00 +02:00
CF Transactor(initial) (#7037)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com> Signed-off-by: Nikolay Chunosov <Chunosov.N@gmail.com>
This commit is contained in:
@@ -1,142 +0,0 @@
|
||||
//
|
||||
// Copyright © 2022 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 {
|
||||
Class,
|
||||
Doc,
|
||||
DocumentQuery,
|
||||
DocumentUpdate,
|
||||
Domain,
|
||||
FindOptions,
|
||||
FindResult,
|
||||
Hierarchy,
|
||||
IndexingConfiguration,
|
||||
Iterator,
|
||||
MeasureContext,
|
||||
ModelDb,
|
||||
Ref,
|
||||
StorageIterator,
|
||||
toFindResult,
|
||||
Tx,
|
||||
TxResult,
|
||||
WorkspaceId,
|
||||
type Blob
|
||||
} from '@hcengineering/core'
|
||||
import { PlatformError, unknownError } from '@hcengineering/platform'
|
||||
import { DbAdapter, DbAdapterHandler, StorageAdapter, type StorageAdapterEx } from '@hcengineering/server-core'
|
||||
|
||||
class StorageBlobAdapter implements DbAdapter {
|
||||
constructor (
|
||||
readonly workspaceId: WorkspaceId,
|
||||
readonly client: StorageAdapterEx, // Should not be closed
|
||||
readonly ctx: MeasureContext
|
||||
) {}
|
||||
|
||||
async traverse<T extends Doc>(
|
||||
domain: Domain,
|
||||
query: DocumentQuery<T>,
|
||||
options?: Pick<FindOptions<T>, 'sort' | 'limit' | 'projection'>
|
||||
): Promise<Iterator<T>> {
|
||||
return {
|
||||
next: async () => {
|
||||
return toFindResult<T>([])
|
||||
},
|
||||
close: async () => {}
|
||||
}
|
||||
}
|
||||
|
||||
init?: ((domains?: string[], excludeDomains?: string[]) => Promise<void>) | undefined
|
||||
on?: ((handler: DbAdapterHandler) => void) | undefined
|
||||
|
||||
async rawFindAll<T extends Doc>(domain: Domain, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<T[]> {
|
||||
return []
|
||||
}
|
||||
|
||||
async rawUpdate<T extends Doc>(
|
||||
domain: Domain,
|
||||
query: DocumentQuery<T>,
|
||||
operations: DocumentUpdate<T>
|
||||
): Promise<void> {}
|
||||
|
||||
async rawDeleteMany<T extends Doc>(domain: Domain, query: DocumentQuery<T>): Promise<void> {}
|
||||
|
||||
async findAll<T extends Doc>(
|
||||
ctx: MeasureContext,
|
||||
_class: Ref<Class<T>>,
|
||||
query: DocumentQuery<T>,
|
||||
options?: FindOptions<T>
|
||||
): Promise<FindResult<T>> {
|
||||
return toFindResult([])
|
||||
}
|
||||
|
||||
async groupBy<T>(ctx: MeasureContext, domain: Domain, field: string): Promise<Map<T, number>> {
|
||||
return new Map()
|
||||
}
|
||||
|
||||
async tx (ctx: MeasureContext, ...tx: Tx[]): Promise<TxResult[]> {
|
||||
throw new PlatformError(unknownError('Direct Blob operations are not possible'))
|
||||
}
|
||||
|
||||
async createIndexes (domain: Domain, config: Pick<IndexingConfiguration<Doc>, 'indexes'>): Promise<void> {}
|
||||
async removeOldIndex (domain: Domain, deletePattern: RegExp[], keepPattern: RegExp[]): Promise<void> {}
|
||||
|
||||
async close (): Promise<void> {}
|
||||
|
||||
find (ctx: MeasureContext, domain: Domain): StorageIterator {
|
||||
return this.client.find(ctx, this.workspaceId)
|
||||
}
|
||||
|
||||
async load (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]): Promise<Doc[]> {
|
||||
const blobs: Blob[] = []
|
||||
for (const d of docs) {
|
||||
const bb = await this.client.stat(ctx, this.workspaceId, d)
|
||||
if (bb !== undefined) {
|
||||
blobs.push(bb)
|
||||
}
|
||||
}
|
||||
return blobs
|
||||
}
|
||||
|
||||
async upload (ctx: MeasureContext, domain: Domain, docs: Doc[]): Promise<void> {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
async clean (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]): Promise<void> {
|
||||
await this.client.remove(this.ctx, this.workspaceId, docs)
|
||||
}
|
||||
|
||||
async update (ctx: MeasureContext, domain: Domain, operations: Map<Ref<Doc>, DocumentUpdate<Doc>>): Promise<void> {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function createStorageDataAdapter (
|
||||
ctx: MeasureContext,
|
||||
hierarchy: Hierarchy,
|
||||
url: string,
|
||||
workspaceId: WorkspaceId,
|
||||
modelDb: ModelDb,
|
||||
storage: StorageAdapter
|
||||
): Promise<DbAdapter> {
|
||||
if (storage === undefined) {
|
||||
throw new Error('minio storage adapter require minio')
|
||||
}
|
||||
// We need to create bucket if it doesn't exist
|
||||
if (!(await storage.exists(ctx, workspaceId))) {
|
||||
await storage.make(ctx, workspaceId)
|
||||
}
|
||||
return new StorageBlobAdapter(workspaceId, storage as StorageAdapterEx, ctx)
|
||||
}
|
||||
@@ -15,5 +15,4 @@
|
||||
//
|
||||
|
||||
export * from './fallback'
|
||||
export * from './blobStorage'
|
||||
export * from './starter'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DatalakeService, type DatalakeConfig } from '@hcengineering/datalake'
|
||||
import { MinioConfig, MinioService, addMinioFallback } from '@hcengineering/minio'
|
||||
import { S3Service, type S3Config } from '@hcengineering/s3'
|
||||
import { CONFIG_KIND as DATALAKE_CONFIG_KIND, DatalakeService, type DatalakeConfig } from '@hcengineering/datalake'
|
||||
import { CONFIG_KIND as MINIO_CONFIG_KIND, MinioConfig, MinioService, addMinioFallback } from '@hcengineering/minio'
|
||||
import { CONFIG_KIND as S3_CONFIG_KIND, S3Service, type S3Config } from '@hcengineering/s3'
|
||||
import { StorageAdapter, StorageConfiguration, type StorageConfig } from '@hcengineering/server-core'
|
||||
import { FallbackStorageAdapter, buildStorage } from './fallback'
|
||||
|
||||
@@ -77,19 +77,19 @@ export function parseStorageEnv (storageEnv: string, storageConfig: StorageConfi
|
||||
|
||||
export function createStorageFromConfig (config: StorageConfig): StorageAdapter {
|
||||
const kind = config.kind
|
||||
if (kind === MinioService.config) {
|
||||
if (kind === MINIO_CONFIG_KIND) {
|
||||
const c = config as MinioConfig
|
||||
if (c.endpoint == null || c.accessKey == null || c.secretKey == null) {
|
||||
throw new Error('One of endpoint/accessKey/secretKey values are not specified')
|
||||
}
|
||||
return new MinioService(c)
|
||||
} else if (kind === S3Service.config) {
|
||||
} else if (kind === S3_CONFIG_KIND) {
|
||||
const c = config as S3Config
|
||||
if (c.endpoint == null || c.accessKey == null || c.secretKey == null) {
|
||||
throw new Error('One of endpoint/accessKey/secretKey values are not specified')
|
||||
}
|
||||
return new S3Service(c)
|
||||
} else if (kind === DatalakeService.config) {
|
||||
} else if (kind === DATALAKE_CONFIG_KIND) {
|
||||
const c = config as DatalakeConfig
|
||||
if (c.endpoint == null) {
|
||||
throw new Error('Endpoint value is not specified')
|
||||
|
||||
Reference in New Issue
Block a user