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 { KeysByType } from 'simplytyped'
|
2022-01-13 09:06:50 +00:00
|
|
|
import type { Account, Arr, AttachedDoc, Class, Data, Doc, Domain, Mixin, PropertyType, Ref, Space } from './classes'
|
2021-08-03 16:55:52 +00:00
|
|
|
import core from './component'
|
2021-11-26 11:05:18 +00:00
|
|
|
import { _getOperator } from './operator'
|
2022-01-11 09:10:50 +00:00
|
|
|
import { _toDoc } from './proxy'
|
2022-01-13 09:06:50 +00:00
|
|
|
import type { TxResult } from './storage'
|
2022-01-11 09:10:50 +00:00
|
|
|
import { generateId } from './utils'
|
2021-08-03 16:55:52 +00:00
|
|
|
|
2021-08-05 06:47:54 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 12:39:43 +00:00
|
|
|
export interface Tx extends Doc {
|
|
|
|
objectSpace: Ref<Space> // space where transaction will operate
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface TxCUD<T extends Doc> extends Tx {
|
2021-08-05 06:47:54 +00:00
|
|
|
objectId: Ref<T>
|
|
|
|
objectClass: Ref<Class<T>>
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 12:39:43 +00:00
|
|
|
export interface TxCreateDoc<T extends Doc> extends TxCUD<T> {
|
2021-08-05 06:47:54 +00:00
|
|
|
attributes: Data<T>
|
|
|
|
}
|
|
|
|
|
2021-10-30 10:13:55 +00:00
|
|
|
/**
|
2021-11-16 18:34:20 +00:00
|
|
|
*
|
|
|
|
* Will perform create/update/delete of attached documents.
|
|
|
|
*
|
2021-10-30 10:13:55 +00:00
|
|
|
* @public
|
|
|
|
*/
|
2021-11-16 18:34:20 +00:00
|
|
|
export interface TxCollectionCUD<T extends Doc, P extends AttachedDoc> extends TxCUD<T> {
|
2021-10-30 10:13:55 +00:00
|
|
|
collection: string
|
2021-11-16 18:34:20 +00:00
|
|
|
tx: TxCUD<P>
|
2021-10-30 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 10:53:11 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface TxPutBag<T extends PropertyType> extends TxCUD<Doc> {
|
|
|
|
bag: string
|
|
|
|
key: string
|
|
|
|
value: T
|
|
|
|
}
|
|
|
|
|
2021-10-07 20:01:17 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface TxBulkWrite extends Tx {
|
|
|
|
txes: TxCUD<Doc>[]
|
|
|
|
}
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type MixinData<D extends Doc, M extends D> = Omit<M, keyof D> & PushOptions<Omit<M, keyof D>> & IncOptions<Omit<M, keyof D>>
|
|
|
|
|
2021-08-05 06:47:54 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export type MixinUpdate<D extends Doc, M extends D> = Partial<Omit<M, keyof D>> & PushOptions<Omit<M, keyof D>> & IncOptions<Omit<M, keyof D>>
|
2021-08-05 06:47:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-30 09:04:32 +00:00
|
|
|
* Define Create/Update for mixin attributes.
|
2021-08-05 06:47:54 +00:00
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 12:39:43 +00:00
|
|
|
export interface TxMixin<D extends Doc, M extends D> extends TxCUD<D> {
|
2021-08-05 06:47:54 +00:00
|
|
|
mixin: Ref<Mixin<M>>
|
2021-12-30 09:04:32 +00:00
|
|
|
attributes: MixinUpdate<D, M>
|
2021-08-05 06:47:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export type ArrayAsElement<T> = {
|
2021-08-03 16:55:52 +00:00
|
|
|
[P in keyof T]: T[P] extends Arr<infer X> ? X : never
|
|
|
|
}
|
|
|
|
|
2021-09-22 08:41:03 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface Position<X extends PropertyType> {
|
|
|
|
$each: X[]
|
|
|
|
$position: number
|
|
|
|
}
|
|
|
|
|
2021-10-09 11:17:00 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface MoveDescriptor<X extends PropertyType> {
|
|
|
|
$value: X
|
|
|
|
$position: number
|
|
|
|
}
|
|
|
|
|
2021-09-22 08:41:03 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export type ArrayAsElementPosition<T extends object> = {
|
2021-09-22 08:41:03 +00:00
|
|
|
[P in keyof T]: T[P] extends Arr<infer X> ? X | Position<X> : never
|
|
|
|
}
|
|
|
|
|
2021-10-09 11:17:00 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export type ArrayMoveDescriptor<T extends object> = {
|
2021-10-09 11:17:00 +00:00
|
|
|
[P in keyof T]: T[P] extends Arr<infer X> ? MoveDescriptor<X> : never
|
|
|
|
}
|
|
|
|
|
2021-09-26 10:48:15 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export type NumberProperties<T extends object> = {
|
2021-09-26 10:48:15 +00:00
|
|
|
[P in keyof T]: T[P] extends number | undefined ? T[P] : never
|
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type OmitNever<T extends object> = Omit<T, KeysByType<T, never>>
|
2021-08-03 16:55:52 +00:00
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export interface PushOptions<T extends object> {
|
2021-09-22 08:41:03 +00:00
|
|
|
$push?: Partial<OmitNever<ArrayAsElementPosition<T>>>
|
|
|
|
$pull?: Partial<OmitNever<ArrayAsElement<T>>>
|
2021-10-09 11:17:00 +00:00
|
|
|
$move?: Partial<OmitNever<ArrayMoveDescriptor<T>>>
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 09:15:09 +00:00
|
|
|
export interface PushMixinOptions<D extends Doc> {
|
|
|
|
$pushMixin?: {
|
|
|
|
$mixin: Ref<Mixin<D>>
|
|
|
|
values: Partial<OmitNever<ArrayAsElement<D>>>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-30 09:04:32 +00:00
|
|
|
export interface IncOptions<T extends object> {
|
2021-09-26 10:48:15 +00:00
|
|
|
$inc?: Partial<OmitNever<NumberProperties<T>>>
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-12-13 09:05:46 +00:00
|
|
|
export interface SpaceUpdate {
|
|
|
|
space?: Ref<Space>
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type DocumentUpdate<T extends Doc> = Partial<Data<T>> & PushOptions<T> & PushMixinOptions<T> & IncOptions<T> & SpaceUpdate
|
2021-08-03 16:55:52 +00:00
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 12:39:43 +00:00
|
|
|
export interface TxUpdateDoc<T extends Doc> extends TxCUD<T> {
|
2021-08-03 16:55:52 +00:00
|
|
|
operations: DocumentUpdate<T>
|
2021-10-13 19:54:11 +00:00
|
|
|
retrieve?: boolean
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 12:39:43 +00:00
|
|
|
export interface TxRemoveDoc<T extends Doc> extends TxCUD<T> {
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-03 16:55:52 +00:00
|
|
|
export const DOMAIN_TX = 'tx' as Domain
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface WithTx {
|
2021-10-13 16:46:48 +00:00
|
|
|
tx: (tx: Tx) => Promise<TxResult>
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-09-15 10:53:11 +00:00
|
|
|
export abstract class TxProcessor implements WithTx {
|
2021-10-13 16:46:48 +00:00
|
|
|
async tx (tx: Tx): Promise<TxResult> {
|
2021-08-03 16:55:52 +00:00
|
|
|
switch (tx._class) {
|
|
|
|
case core.class.TxCreateDoc:
|
|
|
|
return await this.txCreateDoc(tx as TxCreateDoc<Doc>)
|
2021-11-16 18:34:20 +00:00
|
|
|
case core.class.TxCollectionCUD:
|
|
|
|
return await this.txCollectionCUD(tx as TxCollectionCUD<Doc, AttachedDoc>)
|
2021-08-03 16:55:52 +00:00
|
|
|
case core.class.TxUpdateDoc:
|
|
|
|
return await this.txUpdateDoc(tx as TxUpdateDoc<Doc>)
|
|
|
|
case core.class.TxRemoveDoc:
|
|
|
|
return await this.txRemoveDoc(tx as TxRemoveDoc<Doc>)
|
|
|
|
case core.class.TxMixin:
|
|
|
|
return await this.txMixin(tx as TxMixin<Doc, Doc>)
|
2021-09-15 10:53:11 +00:00
|
|
|
case core.class.TxPutBag:
|
|
|
|
return await this.txPutBag(tx as TxPutBag<PropertyType>)
|
2021-10-07 20:01:17 +00:00
|
|
|
case core.class.TxBulkWrite:
|
|
|
|
return await this.txBulkWrite(tx as TxBulkWrite)
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
2021-08-05 12:39:43 +00:00
|
|
|
throw new Error('TxProcessor: unhandled transaction class: ' + tx._class)
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:34:20 +00:00
|
|
|
static createDoc2Doc<T extends Doc>(tx: TxCreateDoc<T>): T {
|
2021-08-03 16:55:52 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
|
|
return {
|
|
|
|
_id: tx.objectId,
|
|
|
|
_class: tx.objectClass,
|
|
|
|
space: tx.objectSpace,
|
|
|
|
modifiedBy: tx.modifiedBy,
|
|
|
|
modifiedOn: tx.modifiedOn,
|
|
|
|
...tx.attributes
|
|
|
|
} as T
|
|
|
|
}
|
|
|
|
|
2021-12-30 09:04:32 +00:00
|
|
|
static updateDoc2Doc<T extends Doc>(rawDoc: T, tx: TxUpdateDoc<T>): T {
|
2022-01-11 09:10:50 +00:00
|
|
|
const doc = _toDoc(rawDoc)
|
2021-11-25 11:07:44 +00:00
|
|
|
const ops = tx.operations as any
|
|
|
|
for (const key in ops) {
|
|
|
|
if (key.startsWith('$')) {
|
|
|
|
const operator = _getOperator(key)
|
|
|
|
operator(doc, ops[key])
|
|
|
|
} else {
|
|
|
|
(doc as any)[key] = ops[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
doc.modifiedBy = tx.modifiedBy
|
|
|
|
doc.modifiedOn = tx.modifiedOn
|
2021-12-30 09:04:32 +00:00
|
|
|
return rawDoc
|
|
|
|
}
|
|
|
|
|
|
|
|
static updateMixin4Doc<D extends Doc, M extends D>(rawDoc: D, mixinClass: Ref<Class<M>>, operations: MixinUpdate<D, M>): D {
|
|
|
|
const ops = operations as any
|
2022-01-11 09:10:50 +00:00
|
|
|
const doc = _toDoc(rawDoc)
|
2021-12-30 09:04:32 +00:00
|
|
|
const mixin = (doc as any)[mixinClass] ?? {}
|
|
|
|
for (const key in ops) {
|
|
|
|
if (key.startsWith('$')) {
|
|
|
|
const operator = _getOperator(key)
|
|
|
|
operator(mixin, ops[key])
|
|
|
|
} else {
|
|
|
|
mixin[key] = ops[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(doc as any)[mixinClass] = mixin
|
|
|
|
return rawDoc
|
2021-11-25 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 16:46:48 +00:00
|
|
|
protected abstract txCreateDoc (tx: TxCreateDoc<Doc>): Promise<TxResult>
|
|
|
|
protected abstract txPutBag (tx: TxPutBag<PropertyType>): Promise<TxResult>
|
|
|
|
protected abstract txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<TxResult>
|
|
|
|
protected abstract txRemoveDoc (tx: TxRemoveDoc<Doc>): Promise<TxResult>
|
|
|
|
protected abstract txMixin (tx: TxMixin<Doc, Doc>): Promise<TxResult>
|
2021-10-07 20:01:17 +00:00
|
|
|
|
2021-11-16 18:34:20 +00:00
|
|
|
protected txCollectionCUD (tx: TxCollectionCUD<Doc, AttachedDoc>): Promise<TxResult> {
|
|
|
|
// We need update only create transactions to contain attached, attachedToClass.
|
|
|
|
if (tx.tx._class === core.class.TxCreateDoc) {
|
|
|
|
const createTx = tx.tx as TxCreateDoc<AttachedDoc>
|
|
|
|
const d: TxCreateDoc<AttachedDoc> = {
|
|
|
|
...createTx,
|
|
|
|
attributes: {
|
|
|
|
...createTx.attributes,
|
|
|
|
attachedTo: tx.objectId,
|
2021-11-17 08:47:30 +00:00
|
|
|
attachedToClass: tx.objectClass,
|
|
|
|
collection: tx.collection
|
2021-11-16 18:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.txCreateDoc(d)
|
|
|
|
}
|
|
|
|
return this.tx(tx.tx)
|
2021-10-30 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 16:46:48 +00:00
|
|
|
protected async txBulkWrite (bulkTx: TxBulkWrite): Promise<TxResult> {
|
2021-10-07 20:01:17 +00:00
|
|
|
for (const tx of bulkTx.txes) {
|
|
|
|
await this.tx(tx)
|
|
|
|
}
|
2021-10-13 16:46:48 +00:00
|
|
|
return {}
|
2021-10-07 20:01:17 +00:00
|
|
|
}
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:24:30 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2021-08-05 07:23:13 +00:00
|
|
|
export class TxFactory {
|
|
|
|
constructor (readonly account: Ref<Account>) {}
|
2021-08-03 16:55:52 +00:00
|
|
|
|
2021-08-05 07:23:13 +00:00
|
|
|
createTxCreateDoc<T extends Doc>(_class: Ref<Class<T>>, space: Ref<Space>, attributes: Data<T>, objectId?: Ref<T>): TxCreateDoc<T> {
|
|
|
|
return {
|
2021-08-03 16:55:52 +00:00
|
|
|
_id: generateId(),
|
|
|
|
_class: core.class.TxCreateDoc,
|
|
|
|
space: core.space.Tx,
|
2021-08-05 07:23:13 +00:00
|
|
|
objectId: objectId ?? generateId(),
|
2021-08-03 16:55:52 +00:00
|
|
|
objectClass: _class,
|
|
|
|
objectSpace: space,
|
2021-08-05 07:23:13 +00:00
|
|
|
modifiedOn: Date.now(),
|
|
|
|
modifiedBy: this.account,
|
2021-08-03 16:55:52 +00:00
|
|
|
attributes
|
|
|
|
}
|
2021-10-30 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:34:20 +00:00
|
|
|
createTxCollectionCUD<T extends Doc, P extends AttachedDoc>(
|
|
|
|
_class: Ref<Class<T>>,
|
|
|
|
objectId: Ref<T>,
|
|
|
|
space: Ref<Space>,
|
|
|
|
collection: string,
|
|
|
|
tx: TxCUD<P>
|
|
|
|
): TxCollectionCUD<T, P> {
|
2021-10-30 10:13:55 +00:00
|
|
|
return {
|
|
|
|
_id: generateId(),
|
2021-11-16 18:34:20 +00:00
|
|
|
_class: core.class.TxCollectionCUD,
|
2021-10-30 10:13:55 +00:00
|
|
|
space: core.space.Tx,
|
2021-11-16 18:34:20 +00:00
|
|
|
objectId,
|
2021-10-30 10:13:55 +00:00
|
|
|
objectClass: _class,
|
|
|
|
objectSpace: space,
|
|
|
|
modifiedOn: Date.now(),
|
|
|
|
modifiedBy: this.account,
|
|
|
|
collection,
|
2021-11-16 18:34:20 +00:00
|
|
|
tx
|
2021-10-30 10:13:55 +00:00
|
|
|
}
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 10:53:11 +00:00
|
|
|
createTxPutBag <P extends PropertyType>(
|
|
|
|
_class: Ref<Class<Doc>>,
|
|
|
|
space: Ref<Space>,
|
|
|
|
objectId: Ref<Doc>,
|
|
|
|
bag: string,
|
|
|
|
key: string,
|
|
|
|
value: P
|
|
|
|
): TxPutBag<P> {
|
|
|
|
return {
|
|
|
|
_id: generateId(),
|
2021-09-15 17:03:34 +00:00
|
|
|
_class: core.class.TxPutBag,
|
2021-09-15 10:53:11 +00:00
|
|
|
space: core.space.Tx,
|
|
|
|
modifiedBy: this.account,
|
|
|
|
modifiedOn: Date.now(),
|
|
|
|
objectId,
|
|
|
|
objectClass: _class,
|
|
|
|
objectSpace: space,
|
|
|
|
bag,
|
|
|
|
key,
|
|
|
|
value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-05 07:23:13 +00:00
|
|
|
createTxUpdateDoc <T extends Doc>(
|
2021-08-03 16:55:52 +00:00
|
|
|
_class: Ref<Class<T>>,
|
|
|
|
space: Ref<Space>,
|
|
|
|
objectId: Ref<T>,
|
2021-10-13 19:54:11 +00:00
|
|
|
operations: DocumentUpdate<T>,
|
|
|
|
retrieve?: boolean
|
2021-08-05 07:23:13 +00:00
|
|
|
): TxUpdateDoc<T> {
|
|
|
|
return {
|
2021-08-03 16:55:52 +00:00
|
|
|
_id: generateId(),
|
|
|
|
_class: core.class.TxUpdateDoc,
|
|
|
|
space: core.space.Tx,
|
2021-08-05 07:23:13 +00:00
|
|
|
modifiedBy: this.account,
|
2021-08-03 16:55:52 +00:00
|
|
|
modifiedOn: Date.now(),
|
|
|
|
objectId,
|
|
|
|
objectClass: _class,
|
|
|
|
objectSpace: space,
|
2021-10-13 19:54:11 +00:00
|
|
|
operations,
|
|
|
|
retrieve
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-05 07:23:13 +00:00
|
|
|
createTxRemoveDoc<T extends Doc> (
|
2021-08-03 16:55:52 +00:00
|
|
|
_class: Ref<Class<T>>,
|
|
|
|
space: Ref<Space>,
|
|
|
|
objectId: Ref<T>
|
2021-08-05 07:23:13 +00:00
|
|
|
): TxRemoveDoc<T> {
|
|
|
|
return {
|
2021-08-03 16:55:52 +00:00
|
|
|
_id: generateId(),
|
|
|
|
_class: core.class.TxRemoveDoc,
|
|
|
|
space: core.space.Tx,
|
2021-08-05 07:23:13 +00:00
|
|
|
modifiedBy: this.account,
|
2021-08-03 16:55:52 +00:00
|
|
|
modifiedOn: Date.now(),
|
|
|
|
objectId,
|
|
|
|
objectClass: _class,
|
|
|
|
objectSpace: space
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-30 09:04:32 +00:00
|
|
|
createTxMixin<D extends Doc, M extends D>(objectId: Ref<D>, objectClass: Ref<Class<D>>, objectSpace: Ref<Space>, mixin: Ref<Mixin<M>>, attributes: MixinUpdate<D, M>): TxMixin<D, M> {
|
2021-08-03 16:55:52 +00:00
|
|
|
return {
|
|
|
|
_id: generateId(),
|
|
|
|
_class: core.class.TxMixin,
|
|
|
|
space: core.space.Tx,
|
|
|
|
modifiedBy: this.account,
|
|
|
|
modifiedOn: Date.now(),
|
|
|
|
objectId,
|
|
|
|
objectClass,
|
2021-12-30 09:04:32 +00:00
|
|
|
objectSpace,
|
2021-08-03 16:55:52 +00:00
|
|
|
mixin,
|
2021-12-30 09:04:32 +00:00
|
|
|
attributes: attributes
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-07 20:01:17 +00:00
|
|
|
|
|
|
|
createTxBulkWrite (space: Ref<Space>, txes: TxCUD<Doc>[]): TxBulkWrite {
|
|
|
|
return {
|
|
|
|
_id: generateId(),
|
|
|
|
_class: core.class.TxBulkWrite,
|
|
|
|
space: core.space.Tx,
|
|
|
|
modifiedBy: this.account,
|
|
|
|
modifiedOn: Date.now(),
|
|
|
|
objectSpace: space,
|
|
|
|
txes
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 16:55:52 +00:00
|
|
|
}
|