2021-08-03 16:55:52 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020, 2021 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 { IntlString, Asset, Resource } from '@anticrm/platform'
|
|
|
|
|
2021-08-04 17:35:29 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Ref<T extends Doc> = string & { __ref: T }
|
2021-08-04 17:51:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type PrimitiveType = number | string | boolean | undefined | Ref<Doc>
|
2021-08-04 17:51:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Timestamp = number
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Obj {
|
|
|
|
_class: Ref<Class<this>>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Doc extends Obj {
|
|
|
|
_id: Ref<this>
|
|
|
|
space: Ref<Space>
|
|
|
|
modifiedOn: Timestamp
|
|
|
|
modifiedBy: Ref<Account>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type PropertyType = any
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface UXObject extends Obj {
|
|
|
|
label?: IntlString
|
|
|
|
icon?: Asset
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
export interface Type<T extends PropertyType> extends UXObject {}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Attribute<T extends PropertyType> extends Doc, UXObject {
|
|
|
|
attributeOf: Ref<Class<Obj>>
|
|
|
|
name: string
|
|
|
|
type: Type<T>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type AnyAttribute = Attribute<Type<any>>
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export enum ClassifierKind {
|
|
|
|
CLASS,
|
|
|
|
MIXIN
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Classifier extends Doc, UXObject {
|
|
|
|
kind: ClassifierKind
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Domain = string & { __domain: true }
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
export interface Class<T extends Obj> extends Classifier {
|
|
|
|
extends?: Ref<Class<Obj>>
|
|
|
|
domain?: Domain
|
|
|
|
triggers?: Trigger[]
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Mixin<T extends Doc> = Class<T>
|
|
|
|
|
|
|
|
// D A T A
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Data<T extends Doc> = Omit<T, keyof Doc>
|
|
|
|
|
|
|
|
// T Y P E S
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface RefTo<T extends Doc> extends Type<Ref<Class<T>>> {
|
|
|
|
to: Ref<Class<T>>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Bag<T extends PropertyType> = Record<string, T>
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface BagOf<T extends PropertyType> extends Type<Bag<T>> {
|
|
|
|
of: Type<T>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Arr<T extends PropertyType> = T[]
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface ArrOf<T extends PropertyType> extends Type<T[]> {
|
|
|
|
of: Type<T>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export const DOMAIN_MODEL = 'model' as Domain
|
|
|
|
|
|
|
|
// S E C U R I T Y
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Space extends Doc {
|
|
|
|
name: string
|
|
|
|
description: string
|
|
|
|
private: boolean
|
|
|
|
members: Arr<Ref<Account>>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Account extends Doc {}
|
|
|
|
|
|
|
|
// T X
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface TxFactory {
|
|
|
|
createTxCreateDoc: <T extends Doc>(_class: Ref<Class<T>>, space: Ref<Space>, attributes: Data<T>) => TxCreateDoc<T>
|
|
|
|
createTxMixin: <D extends Doc, M extends D>(objectId: Ref<D>, objectClass: Ref<Class<D>>, mixin: Ref<Mixin<M>>, attributes: ExtendedAttributes<D, M>) => TxMixin<D, M>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type Trigger = Resource<(tx: Tx, txFactory: TxFactory) => Promise<Tx[]>>
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface Tx<T extends Doc = Doc> extends Doc {
|
|
|
|
objectId: Ref<T>
|
|
|
|
objectClass: Ref<Class<T>>
|
|
|
|
objectSpace: Ref<Space>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface TxCreateDoc<T extends Doc> extends Tx<T> {
|
|
|
|
attributes: Data<T>
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export type ExtendedAttributes<D extends Doc, M extends D> = Omit<M, keyof D>
|
|
|
|
|
2021-08-04 17:51:42 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export interface TxMixin<D extends Doc, M extends D> extends Tx<D> {
|
|
|
|
mixin: Ref<Mixin<M>>
|
|
|
|
attributes: ExtendedAttributes<D, M>
|
|
|
|
}
|