2021-08-11 09:35:56 +00:00
|
|
|
//
|
2022-04-14 05:30:30 +00:00
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
2021-08-11 09:35:56 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
2024-11-13 14:25:57 +00:00
|
|
|
import type { Account, Doc, DocIndexState, Domain, Ref } from './classes'
|
2024-09-09 08:40:49 +00:00
|
|
|
import { MeasureContext } from './measurements'
|
2024-09-11 08:31:26 +00:00
|
|
|
import { DocumentQuery, FindOptions } from './storage'
|
|
|
|
import type { DocumentUpdate, Tx } from './tx'
|
2024-09-09 08:40:49 +00:00
|
|
|
import type { WorkspaceIdWithUrl } from './utils'
|
2021-08-11 09:35:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2022-05-23 15:53:33 +00:00
|
|
|
export interface DocInfo {
|
|
|
|
id: string
|
|
|
|
hash: string
|
|
|
|
size: number // Aprox size
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface StorageIterator {
|
2024-09-17 06:02:35 +00:00
|
|
|
next: (ctx: MeasureContext) => Promise<DocInfo[]>
|
2024-04-08 04:41:14 +00:00
|
|
|
close: (ctx: MeasureContext) => Promise<void>
|
2022-05-23 15:53:33 +00:00
|
|
|
}
|
|
|
|
|
2024-07-08 17:04:05 +00:00
|
|
|
export type BroadcastTargets = Record<string, (tx: Tx) => string[] | undefined>
|
|
|
|
|
2024-09-09 08:40:49 +00:00
|
|
|
export interface SessionData {
|
|
|
|
broadcast: {
|
2024-07-08 17:04:05 +00:00
|
|
|
txes: Tx[]
|
|
|
|
targets: BroadcastTargets // A set of broadcast filters if required
|
|
|
|
}
|
2024-09-09 08:40:49 +00:00
|
|
|
contextCache: Map<string, any>
|
|
|
|
removedMap: Map<Ref<Doc>, Doc>
|
|
|
|
|
|
|
|
userEmail: string
|
|
|
|
sessionId: string
|
|
|
|
admin?: boolean
|
|
|
|
|
2024-09-11 08:31:26 +00:00
|
|
|
isTriggerCtx?: boolean
|
|
|
|
|
2024-09-09 08:40:49 +00:00
|
|
|
account: Account
|
|
|
|
|
|
|
|
getAccount: (account: Ref<Account>) => Account | undefined
|
|
|
|
|
|
|
|
workspace: WorkspaceIdWithUrl
|
|
|
|
branding: Branding | null
|
2024-11-11 12:20:10 +00:00
|
|
|
|
2024-11-13 14:25:57 +00:00
|
|
|
fulltextUpdates?: Map<Ref<DocIndexState>, DocIndexState>
|
2024-05-09 09:06:28 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 15:53:33 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface LowLevelStorage {
|
|
|
|
// Low level streaming API to retrieve information
|
2024-05-30 09:19:23 +00:00
|
|
|
// If recheck is passed, all %hash% for documents, will be re-calculated.
|
|
|
|
find: (ctx: MeasureContext, domain: Domain, recheck?: boolean) => StorageIterator
|
2022-06-01 12:05:07 +00:00
|
|
|
|
|
|
|
// Load passed documents from domain
|
2024-04-08 04:41:14 +00:00
|
|
|
load: (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]) => Promise<Doc[]>
|
2022-06-01 12:05:07 +00:00
|
|
|
|
|
|
|
// Upload new versions of documents
|
|
|
|
// docs - new/updated version of documents.
|
2024-04-08 04:41:14 +00:00
|
|
|
upload: (ctx: MeasureContext, domain: Domain, docs: Doc[]) => Promise<void>
|
2022-06-01 12:05:07 +00:00
|
|
|
|
|
|
|
// Remove a list of documents.
|
2024-04-08 04:41:14 +00:00
|
|
|
clean: (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]) => Promise<void>
|
2024-07-26 16:03:09 +00:00
|
|
|
|
|
|
|
// Low level direct group API
|
2024-11-11 12:20:10 +00:00
|
|
|
groupBy: <T, P extends Doc>(
|
|
|
|
ctx: MeasureContext,
|
|
|
|
domain: Domain,
|
|
|
|
field: string,
|
|
|
|
query?: DocumentQuery<P>
|
|
|
|
) => Promise<Map<T, number>>
|
2024-09-11 08:31:26 +00:00
|
|
|
|
|
|
|
// migrations
|
|
|
|
rawFindAll: <T extends Doc>(domain: Domain, query: DocumentQuery<T>, options?: FindOptions<T>) => Promise<T[]>
|
|
|
|
|
|
|
|
rawUpdate: <T extends Doc>(domain: Domain, query: DocumentQuery<T>, operations: DocumentUpdate<T>) => Promise<void>
|
|
|
|
|
2024-10-26 14:17:37 +00:00
|
|
|
rawDeleteMany: <T extends Doc>(domain: Domain, query: DocumentQuery<T>) => Promise<void>
|
|
|
|
|
2024-09-11 08:31:26 +00:00
|
|
|
// Traverse documents
|
|
|
|
traverse: <T extends Doc>(
|
|
|
|
domain: Domain,
|
|
|
|
query: DocumentQuery<T>,
|
|
|
|
options?: Pick<FindOptions<T>, 'sort' | 'limit' | 'projection'>
|
|
|
|
) => Promise<Iterator<T>>
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Iterator<T extends Doc> {
|
|
|
|
next: (count: number) => Promise<T[] | null>
|
|
|
|
close: () => Promise<void>
|
2022-05-23 15:53:33 +00:00
|
|
|
}
|
2024-06-20 13:13:57 +00:00
|
|
|
|
|
|
|
export interface Branding {
|
|
|
|
key?: string
|
|
|
|
front?: string
|
|
|
|
title?: string
|
|
|
|
language?: string
|
|
|
|
initWorkspace?: string
|
|
|
|
lastNameFirst?: string
|
2024-07-02 14:07:24 +00:00
|
|
|
protocol?: string
|
2024-06-20 13:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type BrandingMap = Record<string, Branding>
|