mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-27 20:14:57 +02:00
Fix cockroach (#6965)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -133,18 +133,6 @@ describe('memdb', () => {
|
||||
})
|
||||
const objClass = (await model.findAll(core.class.Class, { _id: core.class.Obj }))[0] as any
|
||||
expect(objClass['test:mixin:TestMixin'].arr).toEqual(expect.arrayContaining(['hello']))
|
||||
|
||||
await ops.updateDoc(test.mixin.TestMixin, core.space.Model, core.class.Obj as unknown as Ref<TestMixin>, {
|
||||
$pushMixin: {
|
||||
$mixin: test.mixin.TestMixin,
|
||||
values: {
|
||||
arr: 'there'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const objClass2 = (await model.findAll(core.class.Class, { _id: core.class.Obj }))[0] as any
|
||||
expect(objClass2['test:mixin:TestMixin'].arr).toEqual(expect.arrayContaining(['hello', 'there']))
|
||||
})
|
||||
|
||||
it('should allow delete', async () => {
|
||||
|
||||
@@ -116,37 +116,6 @@ function $update (document: Doc, keyval: Record<string, PropertyType>): void {
|
||||
}
|
||||
}
|
||||
|
||||
function $move (document: Doc, keyval: Record<string, PropertyType>): void {
|
||||
const doc = document as any
|
||||
for (const key in keyval) {
|
||||
if (doc[key] === undefined) {
|
||||
doc[key] = []
|
||||
}
|
||||
const arr = doc[key] as Array<any>
|
||||
const desc = keyval[key]
|
||||
doc[key] = (arr ?? []).filter((val) => val !== desc.$value)
|
||||
doc[key].splice(desc.$position, 0, desc.$value)
|
||||
}
|
||||
}
|
||||
|
||||
function $pushMixin (document: Doc, options: any): void {
|
||||
const doc = document as any
|
||||
const mixinId = options.$mixin
|
||||
if (mixinId === undefined) {
|
||||
throw new Error('$mixin must be specified for $push_mixin operation')
|
||||
}
|
||||
const mixin = doc[mixinId]
|
||||
const keyval = options.values
|
||||
for (const key in keyval) {
|
||||
const arr = mixin[key]
|
||||
if (arr == null) {
|
||||
mixin[key] = [keyval[key]]
|
||||
} else {
|
||||
arr.push(keyval[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function $inc (document: Doc, keyval: Record<string, number>): void {
|
||||
const doc = document as unknown as Record<string, number | undefined>
|
||||
for (const key in keyval) {
|
||||
@@ -180,8 +149,6 @@ const operators: Record<string, _OperatorFunc> = {
|
||||
$push,
|
||||
$pull,
|
||||
$update,
|
||||
$move,
|
||||
$pushMixin,
|
||||
$inc,
|
||||
$unset,
|
||||
$rename
|
||||
|
||||
@@ -247,7 +247,6 @@ export type OmitNever<T extends object> = Omit<T, KeysByType<T, never>>
|
||||
export interface PushOptions<T extends object> {
|
||||
$push?: Partial<OmitNever<ArrayAsElementPosition<Required<T>>>>
|
||||
$pull?: Partial<OmitNever<ArrayAsElement<Required<T>>>>
|
||||
$move?: Partial<OmitNever<ArrayMoveDescriptor<Required<T>>>>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,16 +268,6 @@ export interface SetEmbeddedOptions<T extends object> {
|
||||
$update?: Partial<OmitNever<ArrayAsElementUpdate<Required<T>>>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface PushMixinOptions<D extends Doc> {
|
||||
$pushMixin?: {
|
||||
$mixin: Ref<Mixin<D>>
|
||||
values: Partial<OmitNever<ArrayAsElement<D>>>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@@ -299,7 +288,6 @@ export interface SpaceUpdate {
|
||||
export type DocumentUpdate<T extends Doc> = Partial<Data<T>> &
|
||||
PushOptions<T> &
|
||||
SetEmbeddedOptions<T> &
|
||||
PushMixinOptions<T> &
|
||||
IncOptions<T> &
|
||||
SpaceUpdate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user