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

Method getIdFields

packages/server/src/api/rest/index.ts:1813–1835  ·  view source on GitHub ↗
(model: string)

Source from the content-addressed store, hash-verified

1811 }
1812
1813 private getIdFields(model: string): FieldDef[] {
1814 const modelDef = this.requireModel(model);
1815 const modelLower = lowerCaseFirst(model);
1816 if (!(modelLower in this.externalIdMapping)) {
1817 return Object.values(modelDef.fields).filter((f) => modelDef.idFields.includes(f.name));
1818 }
1819
1820 // map external ID name to unique constraint field
1821 const externalIdName = this.externalIdMapping[modelLower];
1822 for (const [name, info] of Object.entries(modelDef.uniqueFields)) {
1823 if (name === externalIdName) {
1824 if (typeof info.type === 'string') {
1825 // single unique field
1826 return [this.requireField(model, name)];
1827 } else {
1828 // compound unique fields
1829 return Object.keys(info).map((f) => this.requireField(model, f));
1830 }
1831 }
1832 }
1833
1834 throw new Error(`Model ${model} does not have unique key ${externalIdName}`);
1835 }
1836
1837 private requireField(model: string, field: string): FieldDef {
1838 const modelDef = this.requireModel(model);

Callers 4

buildTypeMapMethod · 0.95
buildSerializersMethod · 0.95
getIdMethod · 0.95
buildFilterMethod · 0.95

Calls 3

requireModelMethod · 0.95
requireFieldMethod · 0.95
lowerCaseFirstFunction · 0.90

Tested by

no test coverage detected