|
|
@ -96,23 +96,23 @@ export default class Source implements SourceType { |
|
|
|
insertObj.meta = stringifyMetaProp(insertObj); |
|
|
|
insertObj.meta = stringifyMetaProp(insertObj); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
insertObj.order = await ncMeta.metaGetNextOrder(MetaTable.BASES, { |
|
|
|
insertObj.order = await ncMeta.metaGetNextOrder(MetaTable.SOURCES, { |
|
|
|
base_id: source.baseId, |
|
|
|
base_id: source.baseId, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const { id } = await ncMeta.metaInsert2( |
|
|
|
const { id } = await ncMeta.metaInsert2( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.SOURCES, |
|
|
|
insertObj, |
|
|
|
insertObj, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const returnBase = await this.get(context, id, false, ncMeta); |
|
|
|
const returnBase = await this.get(context, id, false, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.appendToList( |
|
|
|
await NocoCache.appendToList( |
|
|
|
CacheScope.BASE, |
|
|
|
CacheScope.SOURCE, |
|
|
|
[source.baseId], |
|
|
|
[source.baseId], |
|
|
|
`${CacheScope.BASE}:${id}`, |
|
|
|
`${CacheScope.SOURCE}:${id}`, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return returnBase; |
|
|
|
return returnBase; |
|
|
@ -167,7 +167,7 @@ export default class Source implements SourceType { |
|
|
|
|
|
|
|
|
|
|
|
// if order is missing (possible in old versions), get next order
|
|
|
|
// if order is missing (possible in old versions), get next order
|
|
|
|
if (!oldSource.order && !updateObj.order) { |
|
|
|
if (!oldSource.order && !updateObj.order) { |
|
|
|
updateObj.order = await ncMeta.metaGetNextOrder(MetaTable.BASES, { |
|
|
|
updateObj.order = await ncMeta.metaGetNextOrder(MetaTable.SOURCES, { |
|
|
|
base_id: oldSource.base_id, |
|
|
|
base_id: oldSource.base_id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -189,7 +189,7 @@ export default class Source implements SourceType { |
|
|
|
|
|
|
|
|
|
|
|
// if order is 1 for non-default source, move it to last
|
|
|
|
// if order is 1 for non-default source, move it to last
|
|
|
|
if (oldSource.order <= 1 && !updateObj.order) { |
|
|
|
if (oldSource.order <= 1 && !updateObj.order) { |
|
|
|
updateObj.order = await ncMeta.metaGetNextOrder(MetaTable.BASES, { |
|
|
|
updateObj.order = await ncMeta.metaGetNextOrder(MetaTable.SOURCES, { |
|
|
|
base_id: oldSource.base_id, |
|
|
|
base_id: oldSource.base_id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -198,13 +198,13 @@ export default class Source implements SourceType { |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.SOURCES, |
|
|
|
prepareForDb(updateObj), |
|
|
|
prepareForDb(updateObj), |
|
|
|
oldSource.id, |
|
|
|
oldSource.id, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.update( |
|
|
|
await NocoCache.update( |
|
|
|
`${CacheScope.BASE}:${sourceId}`, |
|
|
|
`${CacheScope.SOURCE}:${sourceId}`, |
|
|
|
prepareForResponse(updateObj), |
|
|
|
prepareForResponse(updateObj), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -226,20 +226,20 @@ export default class Source implements SourceType { |
|
|
|
args: { baseId: string }, |
|
|
|
args: { baseId: string }, |
|
|
|
ncMeta = Noco.ncMeta, |
|
|
|
ncMeta = Noco.ncMeta, |
|
|
|
): Promise<Source[]> { |
|
|
|
): Promise<Source[]> { |
|
|
|
const cachedList = await NocoCache.getList(CacheScope.BASE, [args.baseId]); |
|
|
|
const cachedList = await NocoCache.getList(CacheScope.SOURCE, [args.baseId]); |
|
|
|
let { list: sourceDataList } = cachedList; |
|
|
|
let { list: sourceDataList } = cachedList; |
|
|
|
const { isNoneList } = cachedList; |
|
|
|
const { isNoneList } = cachedList; |
|
|
|
if (!isNoneList && !sourceDataList.length) { |
|
|
|
if (!isNoneList && !sourceDataList.length) { |
|
|
|
const qb = ncMeta |
|
|
|
const qb = ncMeta |
|
|
|
.knex(MetaTable.BASES) |
|
|
|
.knex(MetaTable.SOURCES) |
|
|
|
.select(`${MetaTable.BASES}.*`) |
|
|
|
.select(`${MetaTable.SOURCES}.*`) |
|
|
|
.where(`${MetaTable.BASES}.base_id`, context.base_id) |
|
|
|
.where(`${MetaTable.SOURCES}.base_id`, context.base_id) |
|
|
|
.where((whereQb) => { |
|
|
|
.where((whereQb) => { |
|
|
|
whereQb |
|
|
|
whereQb |
|
|
|
.where(`${MetaTable.BASES}.deleted`, false) |
|
|
|
.where(`${MetaTable.SOURCES}.deleted`, false) |
|
|
|
.orWhereNull(`${MetaTable.BASES}.deleted`); |
|
|
|
.orWhereNull(`${MetaTable.SOURCES}.deleted`); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.orderBy(`${MetaTable.BASES}.order`, 'asc'); |
|
|
|
.orderBy(`${MetaTable.SOURCES}.order`, 'asc'); |
|
|
|
|
|
|
|
|
|
|
|
this.extendQb(qb, context); |
|
|
|
this.extendQb(qb, context); |
|
|
|
|
|
|
|
|
|
|
@ -250,7 +250,7 @@ export default class Source implements SourceType { |
|
|
|
source.meta = parseMetaProp(source, 'meta'); |
|
|
|
source.meta = parseMetaProp(source, 'meta'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.setList(CacheScope.BASE, [args.baseId], sourceDataList); |
|
|
|
await NocoCache.setList(CacheScope.SOURCE, [args.baseId], sourceDataList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sourceDataList.sort( |
|
|
|
sourceDataList.sort( |
|
|
@ -271,23 +271,23 @@ export default class Source implements SourceType { |
|
|
|
let sourceData = |
|
|
|
let sourceData = |
|
|
|
id && |
|
|
|
id && |
|
|
|
(await NocoCache.get( |
|
|
|
(await NocoCache.get( |
|
|
|
`${CacheScope.BASE}:${id}`, |
|
|
|
`${CacheScope.SOURCE}:${id}`, |
|
|
|
CacheGetType.TYPE_OBJECT, |
|
|
|
CacheGetType.TYPE_OBJECT, |
|
|
|
)); |
|
|
|
)); |
|
|
|
if (!sourceData) { |
|
|
|
if (!sourceData) { |
|
|
|
const qb = ncMeta |
|
|
|
const qb = ncMeta |
|
|
|
.knex(MetaTable.BASES) |
|
|
|
.knex(MetaTable.SOURCES) |
|
|
|
.select(`${MetaTable.BASES}.*`) |
|
|
|
.select(`${MetaTable.SOURCES}.*`) |
|
|
|
.where(`${MetaTable.BASES}.id`, id) |
|
|
|
.where(`${MetaTable.SOURCES}.id`, id) |
|
|
|
.where(`${MetaTable.BASES}.base_id`, context.base_id); |
|
|
|
.where(`${MetaTable.SOURCES}.base_id`, context.base_id); |
|
|
|
|
|
|
|
|
|
|
|
this.extendQb(qb, context); |
|
|
|
this.extendQb(qb, context); |
|
|
|
|
|
|
|
|
|
|
|
if (!force) { |
|
|
|
if (!force) { |
|
|
|
qb.where((whereQb) => { |
|
|
|
qb.where((whereQb) => { |
|
|
|
whereQb |
|
|
|
whereQb |
|
|
|
.where(`${MetaTable.BASES}.deleted`, false) |
|
|
|
.where(`${MetaTable.SOURCES}.deleted`, false) |
|
|
|
.orWhereNull(`${MetaTable.BASES}.deleted`); |
|
|
|
.orWhereNull(`${MetaTable.SOURCES}.deleted`); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -297,7 +297,7 @@ export default class Source implements SourceType { |
|
|
|
sourceData.meta = parseMetaProp(sourceData, 'meta'); |
|
|
|
sourceData.meta = parseMetaProp(sourceData, 'meta'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.set(`${CacheScope.BASE}:${id}`, sourceData); |
|
|
|
await NocoCache.set(`${CacheScope.SOURCE}:${id}`, sourceData); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.castType(sourceData); |
|
|
|
return this.castType(sourceData); |
|
|
|
} |
|
|
|
} |
|
|
@ -476,12 +476,12 @@ export default class Source implements SourceType { |
|
|
|
const res = await ncMeta.metaDelete( |
|
|
|
const res = await ncMeta.metaDelete( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.SOURCES, |
|
|
|
this.id, |
|
|
|
this.id, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.BASE}:${this.id}`, |
|
|
|
`${CacheScope.SOURCE}:${this.id}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -506,7 +506,7 @@ export default class Source implements SourceType { |
|
|
|
await Source.update(context, this.id, { deleted: true }, ncMeta); |
|
|
|
await Source.update(context, this.id, { deleted: true }, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
`${CacheScope.BASE}:${this.id}`, |
|
|
|
`${CacheScope.SOURCE}:${this.id}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -528,14 +528,14 @@ export default class Source implements SourceType { |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.SOURCES, |
|
|
|
{ |
|
|
|
{ |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
}, |
|
|
|
}, |
|
|
|
this.id, |
|
|
|
this.id, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.update(`${CacheScope.BASE}:${this.id}`, { |
|
|
|
await NocoCache.update(`${CacheScope.SOURCE}:${this.id}`, { |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -550,14 +550,14 @@ export default class Source implements SourceType { |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
context.workspace_id, |
|
|
|
context.workspace_id, |
|
|
|
context.base_id, |
|
|
|
context.base_id, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.SOURCES, |
|
|
|
{ |
|
|
|
{ |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
}, |
|
|
|
}, |
|
|
|
this.id, |
|
|
|
this.id, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.update(`${CacheScope.BASE}:${this.id}`, { |
|
|
|
await NocoCache.update(`${CacheScope.SOURCE}:${this.id}`, { |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
erd_uuid: this.erd_uuid, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -581,7 +581,7 @@ export default class Source implements SourceType { |
|
|
|
`${MetaTable.INTEGRATIONS}.title as integration_title`, |
|
|
|
`${MetaTable.INTEGRATIONS}.title as integration_title`, |
|
|
|
).leftJoin( |
|
|
|
).leftJoin( |
|
|
|
MetaTable.INTEGRATIONS, |
|
|
|
MetaTable.INTEGRATIONS, |
|
|
|
`${MetaTable.BASES}.fk_integration_id`, |
|
|
|
`${MetaTable.SOURCES}.fk_integration_id`, |
|
|
|
`${MetaTable.INTEGRATIONS}.id`, |
|
|
|
`${MetaTable.INTEGRATIONS}.id`, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|