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

Function requireField

packages/orm/src/client/query-utils.ts:82–100  ·  view source on GitHub ↗
(schema: SchemaDef, modelOrType: string, field: string)

Source from the content-addressed store, hash-verified

80}
81
82export function requireField(schema: SchemaDef, modelOrType: string, field: string) {
83 const modelDef = getModel(schema, modelOrType);
84 if (modelDef) {
85 if (!modelDef.fields[field]) {
86 throw createInternalError(`Field "${field}" not found in model "${modelOrType}"`, modelOrType);
87 } else {
88 return modelDef.fields[field];
89 }
90 }
91 const typeDef = getTypeDef(schema, modelOrType);
92 if (typeDef) {
93 if (!typeDef.fields[field]) {
94 throw createInternalError(`Field "${field}" not found in type "${modelOrType}"`, modelOrType);
95 } else {
96 return typeDef.fields[field];
97 }
98 }
99 throw createInternalError(`Model or type "${modelOrType}" not found in schema`, modelOrType);
100}
101
102/**
103 * Gets all model fields, by default non-relation, non-computed, non-inherited, non-unsupported fields only.

Callers 15

buildRelationJSONFunction · 0.90
buildRelationObjectArgsFunction · 0.90
buildRelationJSONMethod · 0.90
buildFilterFunction · 0.90
buildCursorFilterFunction · 0.90
buildFieldRefFunction · 0.90
buildOrderByFunction · 0.90
applyFtsRelevanceOrderByFunction · 0.90
shouldOmitFieldFunction · 0.90

Calls 3

createInternalErrorFunction · 0.90
getModelFunction · 0.70
getTypeDefFunction · 0.70

Tested by

no test coverage detected