MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / injectCompoundId

Method injectCompoundId

packages/server/src/api/rest/index.ts:2023–2046  ·  view source on GitHub ↗
(model: string, items: unknown)

Source from the content-addressed store, hash-verified

2021 }
2022
2023 private injectCompoundId(model: string, items: unknown) {
2024 const typeInfo = this.getModelInfo(model);
2025 if (!typeInfo) {
2026 return;
2027 }
2028
2029 // recursively traverse the entity to create synthetic ID field for models with compound ID
2030 enumerate(items).forEach((item: any) => {
2031 if (!item) {
2032 return;
2033 }
2034
2035 if (typeInfo.idFields.length > 1) {
2036 item[this.makeIdKey(typeInfo.idFields)] = this.makeCompoundId(typeInfo.idFields, item);
2037 }
2038
2039 for (const [key, value] of Object.entries(item)) {
2040 if (typeInfo.relationships[key]) {
2041 // field is a relationship, recurse
2042 this.injectCompoundId(typeInfo.relationships[key].type, value);
2043 }
2044 }
2045 });
2046 }
2047
2048 private toPlainObject(data: any): any {
2049 if (data === undefined || data === null) {

Callers 1

serializeItemsMethod · 0.95

Calls 4

getModelInfoMethod · 0.95
makeIdKeyMethod · 0.95
makeCompoundIdMethod · 0.95
enumerateFunction · 0.90

Tested by

no test coverage detected