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