refactor(base): rename baseId to pageId in DTOs, schemas, and services

This commit is contained in:
Philipinho
2026-04-27 01:27:10 +01:00
parent 54de3a7791
commit a53dabae70
13 changed files with 77 additions and 77 deletions
+1 -1
View File
@@ -2,5 +2,5 @@ import { IsUUID } from 'class-validator';
export class BaseIdDto {
@IsUUID()
baseId: string;
pageId: string;
}
@@ -10,7 +10,7 @@ import { BASE_PROPERTY_TYPES } from '../base.schemas';
export class CreatePropertyDto {
@IsUUID()
baseId: string;
pageId: string;
@IsString()
@IsNotEmpty()
@@ -2,7 +2,7 @@ import { IsObject, IsOptional, IsString, IsUUID } from 'class-validator';
export class CreateRowDto {
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsObject()
@@ -9,7 +9,7 @@ import {
export class CreateViewDto {
@IsUUID()
baseId: string;
pageId: string;
@IsString()
@IsNotEmpty()
@@ -2,5 +2,5 @@ import { IsUUID } from 'class-validator';
export class ExportBaseCsvDto {
@IsUUID()
baseId: string;
pageId: string;
}
@@ -2,7 +2,7 @@ import { IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
export class UpdateBaseDto {
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsString()
@@ -12,7 +12,7 @@ export class UpdatePropertyDto {
propertyId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsString()
@@ -43,7 +43,7 @@ export class DeletePropertyDto {
propertyId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsString()
@@ -55,7 +55,7 @@ export class ReorderPropertyDto {
propertyId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsString()
@IsNotEmpty()
@@ -20,7 +20,7 @@ export class UpdateRowDto {
rowId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsObject()
cells: Record<string, unknown>;
@@ -35,7 +35,7 @@ export class DeleteRowDto {
rowId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsString()
@@ -47,7 +47,7 @@ export class RowIdDto {
rowId: string;
@IsUUID()
baseId: string;
pageId: string;
}
class SortDto {
@@ -60,7 +60,7 @@ class SortDto {
export class ListRowsDto {
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsUUID()
@@ -86,7 +86,7 @@ export class ListRowsDto {
export class CountRowsDto {
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsObject()
@@ -108,7 +108,7 @@ export class ReorderRowDto {
rowId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsString()
@IsNotEmpty()
@@ -121,7 +121,7 @@ export class ReorderRowDto {
export class DeleteRowsDto {
@IsUUID()
baseId: string;
pageId: string;
@IsArray()
@ArrayMinSize(1)
@@ -12,7 +12,7 @@ export class UpdateViewDto {
viewId: string;
@IsUUID()
baseId: string;
pageId: string;
@IsOptional()
@IsString()
@@ -33,5 +33,5 @@ export class DeleteViewDto {
viewId: string;
@IsUUID()
baseId: string;
pageId: string;
}
@@ -88,7 +88,7 @@ export class BasePropertyService {
async create(workspaceId: string, dto: CreatePropertyDto, actorId?: string) {
const type = dto.type as BasePropertyTypeValue;
await this.ensureNameUnique(dto.baseId, dto.name);
await this.ensureNameUnique(dto.pageId, dto.name);
let validatedTypeOptions: unknown;
if (type === 'formula') {
@@ -96,7 +96,7 @@ export class BasePropertyService {
if (typeof sourceCandidate !== 'string') {
throw new BadRequestException('formula.source is required');
}
const existing = await this.basePropertyRepo.findByPageId(dto.baseId);
const existing = await this.basePropertyRepo.findByPageId(dto.pageId);
const compiled = this.formulaService.compile(sourceCandidate, existing);
const candidate = {
id: 'pending',
@@ -113,14 +113,14 @@ export class BasePropertyService {
}
const lastPosition = await this.basePropertyRepo.getLastPosition(
dto.baseId,
dto.pageId,
);
const position = generateJitteredKeyBetween(lastPosition, null);
const created = await executeTx(this.db, async (trx) => {
const row = await this.basePropertyRepo.insertProperty(
{
pageId: dto.baseId,
pageId: dto.pageId,
name: dto.name,
type: dto.type,
position,
@@ -129,12 +129,12 @@ export class BasePropertyService {
},
trx,
);
await this.baseRepo.bumpSchemaVersion(dto.baseId, trx);
await this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
return row;
});
const event: BasePropertyCreatedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: actorId ?? null,
requestId: null,
@@ -190,12 +190,12 @@ export class BasePropertyService {
throw new NotFoundException('Property not found');
}
if (property.pageId !== dto.baseId) {
if (property.pageId !== dto.pageId) {
throw new BadRequestException('Property does not belong to this base');
}
if (dto.name !== undefined) {
await this.ensureNameUnique(dto.baseId, dto.name, dto.propertyId);
await this.ensureNameUnique(dto.pageId, dto.name, dto.propertyId);
}
// Block concurrent type changes — the worker still owns the previous
@@ -227,7 +227,7 @@ export class BasePropertyService {
if (typeof sourceCandidate !== 'string') {
throw new BadRequestException('formula.source is required');
}
const allProps = await this.basePropertyRepo.findByPageId(dto.baseId);
const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
const compiled = this.formulaService.compile(sourceCandidate, allProps);
const candidate = {
id: property.id,
@@ -272,13 +272,13 @@ export class BasePropertyService {
);
if (isTypeChange) {
await this.basePropertyRepo.bumpSchemaVersion(dto.propertyId, trx);
await this.baseRepo.bumpSchemaVersion(dto.baseId, trx);
await this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
}
});
if (newType === 'formula' && (isTypeChange || sourceChanged)) {
await this.formulaService.enqueueRecompute({
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
propertyIds: [dto.propertyId],
reason: isTypeChange ? 'formula_created' : 'formula_edited',
@@ -287,12 +287,12 @@ export class BasePropertyService {
}
if (isTypeChange && newType !== 'formula') {
const allProps = await this.basePropertyRepo.findByPageId(dto.baseId);
const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
const graph = new BaseFormulaGraph(allProps);
const affected = graph.affectedFormulas([dto.propertyId]);
if (affected.length > 0) {
await this.formulaService.enqueueRecompute({
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
propertyIds: affected,
reason: 'dep_type_changed',
@@ -306,7 +306,7 @@ export class BasePropertyService {
// --- Path 2 or 3: cell rewrite needed -------------------------------
const conversionPayload: IBaseTypeConversionJob = {
baseId: dto.baseId,
baseId: dto.pageId,
propertyId: dto.propertyId,
workspaceId,
fromType: oldType,
@@ -322,7 +322,7 @@ export class BasePropertyService {
// property set on 12 rows is trivial to convert inline; the previous
// count-all-live-rows check was routing those to the worker.
const rowsToConvert = await this.countRowsToConvert(
dto.baseId,
dto.pageId,
workspaceId,
dto.propertyId,
);
@@ -356,11 +356,11 @@ export class BasePropertyService {
trx,
);
await this.basePropertyRepo.bumpSchemaVersion(dto.propertyId, trx);
return this.baseRepo.bumpSchemaVersion(dto.baseId, trx);
return this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
});
tick('inline-tx-done');
const bumpEvent: BaseSchemaBumpedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: actorId ?? null,
requestId: null,
@@ -454,7 +454,7 @@ export class BasePropertyService {
const updated = await this.basePropertyRepo.findById(dto.propertyId);
if (updated) {
const event: BasePropertyUpdatedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: actorId ?? null,
requestId: dto.requestId ?? null,
@@ -492,7 +492,7 @@ export class BasePropertyService {
throw new NotFoundException('Property not found');
}
if (property.pageId !== dto.baseId) {
if (property.pageId !== dto.pageId) {
throw new BadRequestException('Property does not belong to this base');
}
@@ -502,7 +502,7 @@ export class BasePropertyService {
// Compute dependents BEFORE the delete — once soft-deleted the graph
// wouldn't include them.
const allProps = await this.basePropertyRepo.findByPageId(dto.baseId);
const allProps = await this.basePropertyRepo.findByPageId(dto.pageId);
const graph = new BaseFormulaGraph(allProps);
const affected = graph.affectedFormulas([dto.propertyId]);
@@ -511,11 +511,11 @@ export class BasePropertyService {
// fails, revert the soft-delete so the property isn't orphaned.
await executeTx(this.db, async (trx) => {
await this.basePropertyRepo.softDelete(dto.propertyId, trx);
await this.baseRepo.bumpSchemaVersion(dto.baseId, trx);
await this.baseRepo.bumpSchemaVersion(dto.pageId, trx);
});
const payload: IBaseCellGcJob = {
baseId: dto.baseId,
baseId: dto.pageId,
propertyId: dto.propertyId,
workspaceId,
};
@@ -542,7 +542,7 @@ export class BasePropertyService {
}
const event: BasePropertyDeletedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: actorId ?? null,
requestId: dto.requestId ?? null,
@@ -552,7 +552,7 @@ export class BasePropertyService {
if (affected.length > 0) {
await this.formulaService.enqueueRecompute({
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
propertyIds: affected,
reason: 'dep_deleted',
@@ -571,7 +571,7 @@ export class BasePropertyService {
throw new NotFoundException('Property not found');
}
if (property.pageId !== dto.baseId) {
if (property.pageId !== dto.pageId) {
throw new BadRequestException('Property does not belong to this base');
}
@@ -580,7 +580,7 @@ export class BasePropertyService {
});
const event: BasePropertyReorderedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: actorId ?? null,
requestId: dto.requestId ?? null,
@@ -72,18 +72,18 @@ export class BaseRowService {
const afterRow = await this.baseRowRepo.findById(dto.afterRowId, {
workspaceId,
});
if (!afterRow || afterRow.pageId !== dto.baseId) {
if (!afterRow || afterRow.pageId !== dto.pageId) {
throw new BadRequestException('Invalid afterRowId');
}
position = generateJitteredKeyBetween(afterRow.position, null);
} else {
const lastPosition = await this.baseRowRepo.getLastPosition(dto.baseId, {
const lastPosition = await this.baseRowRepo.getLastPosition(dto.pageId, {
workspaceId,
});
position = generateJitteredKeyBetween(lastPosition, null);
}
const properties = await this.basePropertyRepo.findByPageId(dto.baseId);
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
let validatedCells: Record<string, unknown> = {};
if (dto.cells && Object.keys(dto.cells).length > 0) {
@@ -104,7 +104,7 @@ export class BaseRowService {
const finalCells = { ...validatedCells, ...formulaPatch };
const created = await this.baseRowRepo.insertRow({
pageId: dto.baseId,
pageId: dto.pageId,
cells: finalCells as any,
position,
creatorId: userId,
@@ -112,7 +112,7 @@ export class BaseRowService {
});
const event: BaseRowCreatedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId,
requestId: dto.requestId ?? null,
@@ -132,7 +132,7 @@ export class BaseRowService {
}
async update(dto: UpdateRowDto, workspaceId: string, userId?: string) {
const properties = await this.basePropertyRepo.findByPageId(dto.baseId);
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const validatedCells = this.validateCells(dto.cells, properties);
const existing = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
@@ -151,7 +151,7 @@ export class BaseRowService {
dto.rowId,
finalCells,
{
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
actorId: userId,
},
@@ -162,7 +162,7 @@ export class BaseRowService {
}
const event: BaseRowUpdatedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId ?? null,
requestId: dto.requestId ?? null,
@@ -177,17 +177,17 @@ export class BaseRowService {
async delete(dto: DeleteRowDto, workspaceId: string, userId?: string) {
const row = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
if (!row || row.pageId !== dto.baseId) {
if (!row || row.pageId !== dto.pageId) {
throw new NotFoundException('Row not found');
}
await this.baseRowRepo.softDelete(dto.rowId, {
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
});
const event: BaseRowDeletedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId ?? null,
requestId: dto.requestId ?? null,
@@ -205,17 +205,17 @@ export class BaseRowService {
if (rows.length !== dto.rowIds.length) {
throw new NotFoundException('One or more rows not found');
}
if (rows.some((r) => r.pageId !== dto.baseId)) {
if (rows.some((r) => r.pageId !== dto.pageId)) {
throw new NotFoundException('Row does not belong to base');
}
await this.baseRowRepo.softDeleteMany(dto.rowIds, {
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
});
const event: BaseRowsDeletedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId ?? null,
requestId: dto.requestId ?? null,
@@ -229,7 +229,7 @@ export class BaseRowService {
pagination: PaginationOptions,
workspaceId: string,
) {
const properties = await this.basePropertyRepo.findByPageId(dto.baseId);
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const schema: PropertySchema = new Map(
properties.map((p) => [p.id, p]),
);
@@ -242,7 +242,7 @@ export class BaseRowService {
}));
return this.baseRowRepo.list({
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
filter,
sorts,
@@ -253,7 +253,7 @@ export class BaseRowService {
}
async count(dto: CountRowsDto, workspaceId: string) {
const properties = await this.basePropertyRepo.findByPageId(dto.baseId);
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
const schema: PropertySchema = new Map(properties.map((p) => [p.id, p]));
const filter = this.normaliseFilter({ filter: dto.filter });
@@ -268,7 +268,7 @@ export class BaseRowService {
if (useExact) {
const { value, capped } = await this.baseRowRepo.countExact({
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
filter,
search,
@@ -279,7 +279,7 @@ export class BaseRowService {
}
const estimate = await this.baseRowRepo.countEstimate({
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
filter,
search,
@@ -294,7 +294,7 @@ export class BaseRowService {
async reorder(dto: ReorderRowDto, workspaceId: string, userId?: string) {
const row = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
if (!row || row.pageId !== dto.baseId) {
if (!row || row.pageId !== dto.pageId) {
throw new NotFoundException('Row not found');
}
@@ -305,12 +305,12 @@ export class BaseRowService {
}
await this.baseRowRepo.updatePosition(dto.rowId, dto.position, {
pageId: dto.baseId,
pageId: dto.pageId,
workspaceId,
});
const event: BaseRowReorderedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId ?? null,
requestId: dto.requestId ?? null,
@@ -36,13 +36,13 @@ export class BaseViewService {
validatedConfig = result.data;
}
const lastPosition = await this.baseViewRepo.getLastPosition(dto.baseId, {
const lastPosition = await this.baseViewRepo.getLastPosition(dto.pageId, {
workspaceId,
});
const position = generateJitteredKeyBetween(lastPosition, null);
const created = await this.baseViewRepo.insertView({
pageId: dto.baseId,
pageId: dto.pageId,
name: dto.name,
type: dto.type ?? 'table',
position,
@@ -52,7 +52,7 @@ export class BaseViewService {
});
const event: BaseViewCreatedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId,
requestId: null,
@@ -69,7 +69,7 @@ export class BaseViewService {
throw new NotFoundException('View not found');
}
if (view.pageId !== dto.baseId) {
if (view.pageId !== dto.pageId) {
throw new BadRequestException('View does not belong to this base');
}
@@ -101,7 +101,7 @@ export class BaseViewService {
if (updated) {
const event: BaseViewUpdatedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId ?? null,
requestId: null,
@@ -119,11 +119,11 @@ export class BaseViewService {
throw new NotFoundException('View not found');
}
if (view.pageId !== dto.baseId) {
if (view.pageId !== dto.pageId) {
throw new BadRequestException('View does not belong to this base');
}
const viewCount = await this.baseViewRepo.countByPageId(dto.baseId, {
const viewCount = await this.baseViewRepo.countByPageId(dto.pageId, {
workspaceId,
});
if (viewCount <= 1) {
@@ -133,7 +133,7 @@ export class BaseViewService {
await this.baseViewRepo.deleteView(dto.viewId, { workspaceId });
const event: BaseViewDeletedEvent = {
baseId: dto.baseId,
baseId: dto.pageId,
workspaceId,
actorId: userId ?? null,
requestId: null,
@@ -91,7 +91,7 @@ export class BaseService {
}
async update(dto: UpdateBaseDto) {
const base = await this.baseRepo.findById(dto.baseId);
const base = await this.baseRepo.findById(dto.pageId);
if (!base) {
throw new NotFoundException('Base not found');
}
@@ -101,10 +101,10 @@ export class BaseService {
...(dto.name !== undefined && { title: dto.name }),
...(dto.icon !== undefined && { icon: dto.icon }),
},
dto.baseId,
dto.pageId,
);
return this.baseRepo.findById(dto.baseId);
return this.baseRepo.findById(dto.pageId);
}
async delete(baseId: string) {