mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 04:25:03 +02:00
initial dev-storage implementation
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Generated
+29
-6
@@ -3,13 +3,15 @@ lockfileVersion: 5.3
|
||||
specifiers:
|
||||
'@microsoft/api-extractor': ^7.18.4
|
||||
'@rush-temp/core': file:./projects/core.tgz
|
||||
'@rush-temp/dev-storage': file:./projects/dev-storage.tgz
|
||||
'@rush-temp/platform': file:./projects/platform.tgz
|
||||
'@rush-temp/platform-rig': file:./projects/platform-rig.tgz
|
||||
'@rush-temp/server': file:./projects/server.tgz
|
||||
'@rush-temp/server-ws': file:./projects/server-ws.tgz
|
||||
'@rushstack/heft': ^0.35.0
|
||||
'@rushstack/heft-jest-plugin': ~0.1.15
|
||||
'@types/heft-jest': ^1.0.2
|
||||
'@types/node': ^16.4.10
|
||||
'@types/ws': ^7.4.7
|
||||
'@typescript-eslint/eslint-plugin': '4'
|
||||
'@typescript-eslint/parser': ^4.0.0
|
||||
eslint: ^7.32.0
|
||||
@@ -26,13 +28,15 @@ specifiers:
|
||||
dependencies:
|
||||
'@microsoft/api-extractor': 7.18.4
|
||||
'@rush-temp/core': file:projects/core.tgz_6c259fadfeb3a4b20890aefe87070b8b
|
||||
'@rush-temp/dev-storage': file:projects/dev-storage.tgz_6c259fadfeb3a4b20890aefe87070b8b
|
||||
'@rush-temp/platform': file:projects/platform.tgz_6c259fadfeb3a4b20890aefe87070b8b
|
||||
'@rush-temp/platform-rig': file:projects/platform-rig.tgz_6ab28797e7a22071465f7d680ae81ae5
|
||||
'@rush-temp/server': file:projects/server.tgz_6c259fadfeb3a4b20890aefe87070b8b
|
||||
'@rush-temp/server-ws': file:projects/server-ws.tgz_6c259fadfeb3a4b20890aefe87070b8b
|
||||
'@rushstack/heft': 0.35.0
|
||||
'@rushstack/heft-jest-plugin': 0.1.15_@rushstack+heft@0.35.0
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@types/node': 16.4.10
|
||||
'@types/ws': 7.4.7
|
||||
'@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea
|
||||
'@typescript-eslint/parser': 4.28.5_eslint@7.32.0+typescript@4.3.5
|
||||
eslint: 7.32.0
|
||||
@@ -5197,6 +5201,25 @@ packages:
|
||||
- typescript
|
||||
dev: false
|
||||
|
||||
file:projects/dev-storage.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-Jf/W4dvCH5kUvK2ItxuijWJM4IGZf8Hi1noFrzk9PLL+2WNrD5t7sPB9c/lv4KzKEhX5gTV4ZkLBHNyD+lo2oQ==, tarball: file:projects/dev-storage.tgz}
|
||||
id: file:projects/dev-storage.tgz
|
||||
name: '@rush-temp/dev-storage'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
'@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
|
||||
simplytyped: 3.3.0_typescript@4.3.5
|
||||
transitivePeerDependencies:
|
||||
- '@typescript-eslint/parser'
|
||||
- supports-color
|
||||
- typescript
|
||||
dev: false
|
||||
|
||||
file:projects/platform-rig.tgz_6ab28797e7a22071465f7d680ae81ae5:
|
||||
resolution: {integrity: sha512-VwGZVPcf2apIoa4sxQkIvW90B4otxf7ayw1jlTiZKQsQfwnLRKXvInMbIIAP0zCPRWIZdXXBYpUDm3dOJ/2bYQ==, tarball: file:projects/platform-rig.tgz}
|
||||
id: file:projects/platform-rig.tgz
|
||||
@@ -5240,10 +5263,10 @@ packages:
|
||||
- typescript
|
||||
dev: false
|
||||
|
||||
file:projects/server.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-RNLOYCrfV7DpGNDy74lWtChPLzJkaP/Tb10vh3usOUf8kjByj8MXjhnKRgb8ZMn2MkkquQ+Pdz5Hi/tfcSsvxw==, tarball: file:projects/server.tgz}
|
||||
id: file:projects/server.tgz
|
||||
name: '@rush-temp/server'
|
||||
file:projects/server-ws.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-FPRBEhZQsqM1RubaIKALYn07JyvdHC23q2lG6gdEbMDtPAo4p7lO7KeUp6ObshvRfLx7+50Idl8c8xDBGbz41Q==, tarball: file:projects/server-ws.tgz}
|
||||
id: file:projects/server-ws.tgz
|
||||
name: '@rush-temp/server-ws'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@types/heft-jest': 1.0.2
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@anticrm/dev-storage",
|
||||
"version": "0.6.0",
|
||||
"main": "lib/index.js",
|
||||
"author": "Anticrm Platform Contributors",
|
||||
"license": "EPL-2.0",
|
||||
"scripts": {
|
||||
"build": "heft build",
|
||||
"build:docs": "api-extractor run --local",
|
||||
"test": "jest",
|
||||
"lint": "ts-standard src",
|
||||
"lint:fix": "eslint --fix ./src",
|
||||
"format": "prettier --write 'src/**/*.{ts*,js*,yml}' && ts-standard --fix src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@anticrm/platform-rig":"~0.6.0",
|
||||
"@types/heft-jest":"^1.0.2",
|
||||
"@typescript-eslint/eslint-plugin":"4",
|
||||
"eslint-plugin-import":"2",
|
||||
"eslint-plugin-promise":"4",
|
||||
"eslint-plugin-node":"11",
|
||||
"eslint":"^7.32.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anticrm/core": "~0.6.0",
|
||||
"@anticrm/platform": "~0.6.0"
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,6 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
// import { start } from './server'
|
||||
|
||||
// const mongodbUri = process.env.MONGODB_URI || 'mongodb://localhost:27017'
|
||||
|
||||
// console.log('mongodb uri: ...' + mongodbUri.substring(25))
|
||||
|
||||
// start(18080, mongodbUri)
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// Copyright © 2020 Anticrm Platform Contributors.
|
||||
//
|
||||
// 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 type {
|
||||
Tx,
|
||||
Storage,
|
||||
Ref,
|
||||
Doc,
|
||||
Class,
|
||||
DocumentQuery,
|
||||
FindResult,
|
||||
FindOptions
|
||||
} from '@anticrm/core'
|
||||
import { getResource } from '@anticrm/platform'
|
||||
import core, { ModelDb, TxDb, Hierarchy, DOMAIN_TX, DefaultTxFactory } from '@anticrm/core'
|
||||
|
||||
async function getModel (): Promise<Tx[]> {
|
||||
return import('./model.tx.json') as unknown as Tx[]
|
||||
}
|
||||
|
||||
class DevStorage implements Storage {
|
||||
private readonly txFactory: DefaultTxFactory
|
||||
|
||||
constructor (
|
||||
private readonly hierarchy: Hierarchy,
|
||||
private readonly txdb: TxDb,
|
||||
private readonly modeldb: ModelDb,
|
||||
private readonly handler: (tx: Tx) => void) {
|
||||
this.txFactory = new DefaultTxFactory(core.account.System)
|
||||
}
|
||||
|
||||
async findAll<T extends Doc> (
|
||||
_class: Ref<Class<T>>,
|
||||
query: DocumentQuery<T>,
|
||||
options?: FindOptions<T>
|
||||
): Promise<FindResult<T>> {
|
||||
const domain = this.hierarchy.getClass(_class).domain
|
||||
if (domain === DOMAIN_TX) return await this.txdb.findAll(_class, query, options)
|
||||
return await this.modeldb.findAll(_class, query, options)
|
||||
}
|
||||
|
||||
async tx (tx: Tx): Promise<void> {
|
||||
if (tx.objectSpace === core.space.Model) {
|
||||
this.hierarchy.tx(tx)
|
||||
}
|
||||
await Promise.all([this.modeldb.tx(tx), this.txdb.tx(tx)])
|
||||
// invoke triggers
|
||||
const triggers = this.hierarchy.getClass(tx.objectClass).triggers
|
||||
if (triggers !== undefined) {
|
||||
for (const trigger of triggers) {
|
||||
const impl = await getResource(trigger)
|
||||
const txes = await impl(tx, this.txFactory)
|
||||
for (const tx of txes) {
|
||||
await Promise.all([this.modeldb.tx(tx), this.txdb.tx(tx)])
|
||||
this.handler(tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function connect (handler: (tx: Tx) => void): Promise<Storage> {
|
||||
const txes = await getModel()
|
||||
|
||||
const hierarchy = new Hierarchy()
|
||||
for (const tx of txes) hierarchy.tx(tx)
|
||||
|
||||
const transactions = new TxDb(hierarchy)
|
||||
const model = new ModelDb(hierarchy)
|
||||
for (const tx of txes) {
|
||||
await Promise.all([transactions.tx(tx), model.tx(tx)])
|
||||
}
|
||||
|
||||
return new DevStorage(hierarchy, transactions, model, handler)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./node_modules/@anticrm/platform-rig/profiles/default/tsconfig.json",
|
||||
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./lib"
|
||||
}
|
||||
}
|
||||
@@ -462,15 +462,14 @@
|
||||
"shouldPublish": true
|
||||
},
|
||||
{
|
||||
"packageName": "@anticrm/server",
|
||||
"projectFolder": "server/server",
|
||||
"packageName": "@anticrm/server-ws",
|
||||
"projectFolder": "server/ws",
|
||||
"shouldPublish": true
|
||||
},
|
||||
{
|
||||
"packageName": "@anticrm/dev-storage",
|
||||
"projectFolder": "dev/storage",
|
||||
"shouldPublish": true
|
||||
}
|
||||
//
|
||||
// {
|
||||
// "packageName": "my-toolchain",
|
||||
// "projectFolder": "tools/my-toolchain",
|
||||
// "reviewCategory": "tools"
|
||||
// }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
extends: ['./node_modules/@anticrm/platform-rig/profiles/default/config/eslint.config.json'],
|
||||
parserOptions: {
|
||||
project: './tsconfig.json'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// The "rig.json" file directs tools to look for their config files in an external package.
|
||||
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
|
||||
|
||||
/**
|
||||
* (Required) The name of the rig package to inherit from.
|
||||
* It should be an NPM package name with the "-rig" suffix.
|
||||
*/
|
||||
"rigPackageName": "@anticrm/platform-rig"
|
||||
|
||||
/**
|
||||
* (Optional) Selects a config profile from the rig package. The name must consist of
|
||||
* lowercase alphanumeric words separated by hyphens, for example "sample-profile".
|
||||
* If omitted, then the "default" profile will be used."
|
||||
*/
|
||||
// "rigProfile": "your-profile-name"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@anticrm/server",
|
||||
"name": "@anticrm/server-ws",
|
||||
"version": "0.6.0",
|
||||
"main": "lib/index.js",
|
||||
"author": "Anticrm Platform Contributors",
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
export { start } from './server'
|
||||
@@ -38,9 +38,9 @@ async function handleRequest<S> (service: S, ws: WebSocket, msg: string): Promis
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param serviceFactory
|
||||
* @param port
|
||||
* @param host
|
||||
* @param serviceFactory -
|
||||
* @param port -
|
||||
* @param host -
|
||||
*/
|
||||
export function start<S> (serviceFactory: () => Promise<S>, port: number, host?: string): void {
|
||||
// console.log('starting server on port ' + port + '...')
|
||||
Reference in New Issue
Block a user