mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-14 04:08:19 +00:00
move triggers to server-core
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
d28082ee89
commit
9d1e483ef9
@ -20,7 +20,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anticrm/core": "~0.6.10",
|
"@anticrm/core": "~0.6.10",
|
||||||
"@anticrm/platform": "~0.6.5",
|
"@anticrm/platform": "~0.6.5",
|
||||||
"@anticrm/server-core": "~0.6.0",
|
"@anticrm/server-core": "~0.6.0"
|
||||||
"@anticrm/server": "~0.6.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions } from '@anticrm/core'
|
import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions } from '@anticrm/core'
|
||||||
import core, { ModelDb, TxDb, Hierarchy, DOMAIN_TX, TxFactory, ServerStorage } from '@anticrm/core'
|
import core, { ModelDb, TxDb, Hierarchy, DOMAIN_TX, TxFactory, ServerStorage } from '@anticrm/core'
|
||||||
import { Triggers } from '@anticrm/server'
|
import { Triggers } from '@anticrm/server-core'
|
||||||
|
|
||||||
import * as txJson from './model.tx.json'
|
import * as txJson from './model.tx.json'
|
||||||
|
|
||||||
|
@ -14,9 +14,11 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import type { Doc, Tx, TxCreateDoc, TxFactory, Ref, Class } from '@anticrm/core'
|
||||||
import type { Resource, Plugin } from '@anticrm/platform'
|
import type { Resource, Plugin } from '@anticrm/platform'
|
||||||
import { plugin } from '@anticrm/platform'
|
import { getResource, plugin } from '@anticrm/platform'
|
||||||
import type { Doc, Tx, TxFactory, Class, Ref } from '@anticrm/core'
|
|
||||||
|
import core from '@anticrm/core'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -24,12 +26,40 @@ import type { Doc, Tx, TxFactory, Class, Ref } from '@anticrm/core'
|
|||||||
export type TriggerFunc = (tx: Tx, txFactory: TxFactory) => Promise<Tx[]>
|
export type TriggerFunc = (tx: Tx, txFactory: TxFactory) => Promise<Tx[]>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export interface Trigger extends Doc {
|
export interface Trigger extends Doc {
|
||||||
trigger: Resource<TriggerFunc>
|
trigger: Resource<TriggerFunc>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export class Triggers {
|
||||||
|
private readonly triggers: TriggerFunc[] = []
|
||||||
|
|
||||||
|
constructor (private readonly txFactory: TxFactory) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async tx (tx: Tx): Promise<void> {
|
||||||
|
if (tx._class === core.class.TxCreateDoc) {
|
||||||
|
const createTx = tx as TxCreateDoc<Doc>
|
||||||
|
if (createTx.objectClass === serverCore.class.Trigger) {
|
||||||
|
const trigger = (createTx as TxCreateDoc<Trigger>).attributes.trigger
|
||||||
|
const func = await getResource(trigger)
|
||||||
|
this.triggers.push(func)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async apply (tx: Tx): Promise<Tx[]> {
|
||||||
|
const derived = this.triggers.map(trigger => trigger(tx, this.txFactory))
|
||||||
|
const result = await Promise.all(derived)
|
||||||
|
return result.flatMap(x => x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -38,8 +68,10 @@ export const serverCoreId = 'server-core' as Plugin
|
|||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export default plugin(serverCoreId, {
|
const serverCore = plugin(serverCoreId, {
|
||||||
class: {
|
class: {
|
||||||
Trigger: '' as Ref<Class<Trigger>>
|
Trigger: '' as Ref<Class<Trigger>>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default serverCore
|
||||||
|
@ -14,4 +14,4 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
export * from './triggers'
|
export const x = 42
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
//
|
|
||||||
// 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 type { Doc, Tx, TxCreateDoc, TxFactory } from '@anticrm/core'
|
|
||||||
import { getResource } from '@anticrm/platform'
|
|
||||||
|
|
||||||
import core from '@anticrm/core'
|
|
||||||
import serverCore, { Trigger, TriggerFunc } from '@anticrm/server-core'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export class Triggers {
|
|
||||||
private readonly triggers: TriggerFunc[] = []
|
|
||||||
|
|
||||||
constructor (private readonly txFactory: TxFactory) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async tx (tx: Tx): Promise<void> {
|
|
||||||
if (tx._class === core.class.TxCreateDoc) {
|
|
||||||
const createTx = tx as TxCreateDoc<Doc>
|
|
||||||
if (createTx.objectClass === serverCore.class.Trigger) {
|
|
||||||
const trigger = (createTx as TxCreateDoc<Trigger>).attributes.trigger
|
|
||||||
const func = await getResource(trigger)
|
|
||||||
this.triggers.push(func)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async apply (tx: Tx): Promise<Tx[]> {
|
|
||||||
const derived = this.triggers.map(trigger => trigger(tx, this.txFactory))
|
|
||||||
const result = await Promise.all(derived)
|
|
||||||
return result.flatMap(x => x)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user