Skip to content

Commit

Permalink
fix: fix event spaceis
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Oct 18, 2024
1 parent 038f7a9 commit 4b42997
Show file tree
Hide file tree
Showing 33 changed files with 207 additions and 116 deletions.
7 changes: 5 additions & 2 deletions packages/base/src/events/base-created.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export type IBaseCreatedEventPayload = z.infer<typeof baseCreatedEventPayload>
export class BaseCreatedEvent extends BaseEvent<IBaseCreatedEventPayload, typeof EVT_BASE_CREATED> {
name = EVT_BASE_CREATED

constructor(public readonly payload: IBaseCreatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IBaseCreatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
4 changes: 2 additions & 2 deletions packages/base/src/events/base-updated.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type IBaseUpdatedEventPayload = z.infer<typeof baseUpdatedEventPayload>
export class BaseUpdatedEvent extends BaseEvent<IBaseUpdatedEventPayload, typeof EVT_BASE_UPDATED> {
name = EVT_BASE_UPDATED

constructor(public readonly payload: IBaseUpdatedEventPayload) {
super(payload, undefined)
constructor(public readonly payload: IBaseUpdatedEventPayload, spaceId: string ) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/space/src/events/space-created.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export type ISpaceCreatedEventPayload = z.infer<typeof spaceCreatedEventPayload>
export class SpaceCreatedEvent extends BaseEvent<ISpaceCreatedEventPayload, typeof EVT_SPACE_CREATED> {
name = EVT_SPACE_CREATED

constructor(public readonly payload: ISpaceCreatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISpaceCreatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/space/src/events/space-updated.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export type ISpaceUpdatedEventPayload = z.infer<typeof spaceUpdatedEventPayload>
export class SpaceUpdatedEvent extends BaseEvent<ISpaceUpdatedEventPayload, typeof EVT_SPACE_UPDATED> {
name = EVT_SPACE_UPDATED

constructor(public readonly payload: ISpaceUpdatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISpaceUpdatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/field-created.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export type IFieldCreatedEventPayload = z.infer<typeof fieldCreatedEventPayload>
export class FieldCreatedEvent extends BaseEvent<IFieldCreatedEventPayload, typeof EVT_FIELD_CREATED> {
name = EVT_FIELD_CREATED

constructor(public readonly payload: IFieldCreatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IFieldCreatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/field-deleted.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export type IFieldDeletedEventPayload = z.infer<typeof fieldDeletedEventPayload>
export class FieldDeletedEvent extends BaseEvent<IFieldDeletedEventPayload, typeof EVT_FIELD_DELETED> {
name = EVT_FIELD_DELETED

constructor(public readonly payload: IFieldDeletedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IFieldDeletedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/field-updated.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export type IFieldUpdatedEventPayload = z.infer<typeof fieldUpdatedEventPayload>
export class FieldUpdatedEvent extends BaseEvent<IFieldUpdatedEventPayload, typeof EVT_FIELD_UPDATED> {
name = EVT_FIELD_UPDATED

constructor(public readonly payload: IFieldUpdatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IFieldUpdatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-table-form.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export type ISetTableFormEventPayload = z.infer<typeof setTableFormEventPayload>
export class SetTableFormEvent extends BaseEvent<ISetTableFormEventPayload, typeof EVT_SET_TABLE_VIEW> {
name = EVT_SET_TABLE_VIEW

constructor(public readonly payload: ISetTableFormEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetTableFormEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-table-rls.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export type ISetTableRLSEventPayload = z.infer<typeof setTableRLSEventPayload>
export class SetTableRLSEvent extends BaseEvent<ISetTableRLSEventPayload, typeof EVT_SET_TABLE_RLS> {
name = EVT_SET_TABLE_RLS

constructor(public readonly payload: ISetTableRLSEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetTableRLSEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-view-aggregate.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export type ISetViewAggregateEventPayload = z.infer<typeof setViewAggregateEvent
export class SetViewAggregateEvent extends BaseEvent<ISetViewAggregateEventPayload, typeof EVT_SET_VIEW_COLOR> {
name = EVT_SET_VIEW_COLOR

constructor(public readonly payload: ISetViewAggregateEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetViewAggregateEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-view-color.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export type ISetViewColorEventPayload = z.infer<typeof setViewColorEventPayload>
export class SetViewColorEvent extends BaseEvent<ISetViewColorEventPayload, typeof EVT_SET_VIEW_COLOR> {
name = EVT_SET_VIEW_COLOR

constructor(public readonly payload: ISetViewColorEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetViewColorEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-view-fields.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export type ISetViewFieldsEventPayload = z.infer<typeof setViewFieldsEventPayloa
export class SetViewFieldsEvent extends BaseEvent<ISetViewFieldsEventPayload, typeof EVT_SET_VIEW_FIELDS> {
name = EVT_SET_VIEW_FIELDS

constructor(public readonly payload: ISetViewFieldsEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetViewFieldsEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-view-filter.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export type ISetViewFilterEventPayload = z.infer<typeof setViewFilterEventPayloa
export class SetViewFilterEvent extends BaseEvent<ISetViewFilterEventPayload, typeof EVT_SET_VIEW_FILTER> {
name = EVT_SET_VIEW_FILTER

constructor(public readonly payload: ISetViewFilterEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetViewFilterEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-view-option.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export type ISetViewOptionEventPayload = z.infer<typeof setViewOptionEventPayloa
export class SetViewOptionEvent extends BaseEvent<ISetViewOptionEventPayload, typeof EVT_SET_VIEW_OPTION> {
name = EVT_SET_VIEW_OPTION

constructor(public readonly payload: ISetViewOptionEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetViewOptionEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/set-view-sort.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export type ISetViewSortEventPayload = z.infer<typeof setViewSortEventPayload>
export class SetViewSortEvent extends BaseEvent<ISetViewSortEventPayload, typeof EVT_SET_VIEW_SORT> {
name = EVT_SET_VIEW_SORT

constructor(public readonly payload: ISetViewSortEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ISetViewSortEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/table-created.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export type ITableCreatedEventPayload = z.infer<typeof tableCreatedEventPayload>
export class TableCreatedEvent extends BaseEvent<ITableCreatedEventPayload, typeof EVT_TABLE_CREATED> {
name = EVT_TABLE_CREATED

constructor(public readonly payload: ITableCreatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: ITableCreatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/view-created.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export type IViewCreatedEventPayload = z.infer<typeof viewCreatedEventPayload>
export class ViewCreatedEvent extends BaseEvent<IViewCreatedEventPayload, typeof EVT_VIEW_CREATED> {
name = EVT_VIEW_CREATED

constructor(public readonly payload: IViewCreatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IViewCreatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/view-deleted.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export type IViewDeletedEventPayload = z.infer<typeof viewDeletedEventPayload>
export class ViewDeletedEvent extends BaseEvent<IViewDeletedEventPayload, typeof EVT_VIEW_DELETED> {
name = EVT_VIEW_DELETED

constructor(public readonly payload: IViewDeletedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IViewDeletedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
7 changes: 5 additions & 2 deletions packages/table/src/events/view-updated.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export type IViewUpdatedEventPayload = z.infer<typeof viewUpdatedEventPayload>
export class ViewUpdatedEvent extends BaseEvent<IViewUpdatedEventPayload, typeof EVT_VIEW_UPDATED> {
name = EVT_VIEW_UPDATED

constructor(public readonly payload: IViewUpdatedEventPayload) {
super(payload, undefined)
constructor(
public readonly payload: IViewUpdatedEventPayload,
spaceId: string,
) {
super(payload, undefined, spaceId)
}
}
15 changes: 9 additions & 6 deletions packages/table/src/methods/create-field.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ export function $createFieldSpec(this: TableDo, field: Field): Option<TableComos

applyRules(new FieldNameShouldBeUnique(this.schema), new FieldIdShouldBeUnique(this.schema))

const event = new FieldCreatedEvent({
tableId: this.id.value,
field: createFieldSpec.field.toJSON(),
views: this.views.toJSON(),
forms: formAddFieldSpec?.forms.toJSON(),
})
const event = new FieldCreatedEvent(
{
tableId: this.id.value,
field: createFieldSpec.field.toJSON(),
views: this.views.toJSON(),
forms: formAddFieldSpec?.forms.toJSON(),
},
this.spaceId,
)
this.addDomainEvent(event)

return Some(spec)
Expand Down
11 changes: 7 additions & 4 deletions packages/table/src/methods/create-view.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export function createViewMethod(
const names = this.views.views.map((v) => v.name.value)
applyRules(new ViewNameShouldBeUnique(names))

const event = new ViewCreatedEvent({
tableId: this.id.value,
view: view.toJSON(),
})
const event = new ViewCreatedEvent(
{
tableId: this.id.value,
view: view.toJSON(),
},
this.spaceId,
)
this.addDomainEvent(event)

return { spec: Some(spec), view }
Expand Down
11 changes: 7 additions & 4 deletions packages/table/src/methods/delete-field.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ export function deleteFieldMethod(this: TableDo, dto: IDeleteFieldDTO): [Field,

spec.mutate(this)

const event = new FieldDeletedEvent({
tableId: this.id.value,
field: field.toJSON(),
})
const event = new FieldDeletedEvent(
{
tableId: this.id.value,
field: field.toJSON(),
},
this.spaceId,
)
this.addDomainEvent(event)

return [field, Some(spec)]
Expand Down
11 changes: 7 additions & 4 deletions packages/table/src/methods/delete-view.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export function deleteViewMethod(this: TableDo, dto: IDeleteViewDTO): Option<Tab
if (spec.isSome()) {
spec.unwrap().mutate(this)

const event = new ViewDeletedEvent({
tableId: this.id.value,
viewId: view.id.value,
})
const event = new ViewDeletedEvent(
{
tableId: this.id.value,
viewId: view.id.value,
},
this.spaceId,
)
this.addDomainEvent(event)
}

Expand Down
11 changes: 7 additions & 4 deletions packages/table/src/methods/duplicate-view.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ export function duplicateViewMethod(
if (spec.isSome()) {
spec.unwrap().mutate(this)

const event = new ViewCreatedEvent({
tableId: this.id.value,
view: view.toJSON(),
})
const event = new ViewCreatedEvent(
{
tableId: this.id.value,
view: view.toJSON(),
},
this.spaceId,
)
this.addDomainEvent(event)
}

Expand Down
13 changes: 8 additions & 5 deletions packages/table/src/methods/set-table-form.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ export function setTableForm(this: TableDo, dto: ISetTableFormDTO): Option<Table
if (!spec) return None
spec.mutate(this)

const event = new SetTableFormEvent({
tableId: this.id.value,
previous: spec.previous ?? null,
form: spec.form.toJSON(),
})
const event = new SetTableFormEvent(
{
tableId: this.id.value,
previous: spec.previous ?? null,
form: spec.form.toJSON(),
},
this.spaceId,
)
this.addDomainEvent(event)

return Some(spec)
Expand Down
16 changes: 9 additions & 7 deletions packages/table/src/methods/set-view-aggregate.method.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Option } from "@undb/domain"
import type { ISetViewAggregateDTO } from "../dto"
import { SetViewAggregateEvent } from "../events"
import { ViewIdVo } from "../modules"
import type { TableComositeSpecification } from "../specifications"
import type { TableDo } from "../table.do"

Expand All @@ -12,12 +11,15 @@ export function setViewAggregate(this: TableDo, dto: ISetViewAggregateDTO): Opti
if (spec.isSome()) {
spec.unwrap().mutate(this)

const event = new SetViewAggregateEvent({
tableId: this.id.value,
viewId: view.id.value,
previous: spec.unwrap().previous.into(null) ?? null,
aggregate: view.aggregate.into(null)?.value ?? null,
})
const event = new SetViewAggregateEvent(
{
tableId: this.id.value,
viewId: view.id.value,
previous: spec.unwrap().previous.into(null) ?? null,
aggregate: view.aggregate.into(null)?.value ?? null,
},
this.spaceId,
)
this.addDomainEvent(event)
}

Expand Down
Loading

0 comments on commit 4b42997

Please sign in to comment.