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

Function collectExtResultFieldDefs

packages/orm/src/client/client-impl.ts:936–967  ·  view source on GitHub ↗

* Collects extended result field definitions from all plugins for a given model.

(
    model: string,
    schema: SchemaDef,
    plugins: AnyPlugin[],
)

Source from the content-addressed store, hash-verified

934 * Collects extended result field definitions from all plugins for a given model.
935 */
936function collectExtResultFieldDefs(
937 model: string,
938 schema: SchemaDef,
939 plugins: AnyPlugin[],
940): Map<string, ExtResultFieldDef> {
941 const defs = new Map<string, ExtResultFieldDef>();
942 for (const plugin of plugins) {
943 const resultConfig = plugin.result;
944 if (resultConfig) {
945 const modelConfig = resultConfig[lowerCaseFirst(model)];
946 if (modelConfig) {
947 for (const [fieldName, fieldDef] of Object.entries(modelConfig)) {
948 if (getField(schema, model, fieldName)) {
949 throw new Error(
950 `Plugin "${plugin.id}" registers ext result field "${fieldName}" on model "${model}" which conflicts with an existing model field`,
951 );
952 }
953 for (const needField of Object.keys((fieldDef as ExtResultFieldDef).needs ?? {})) {
954 const needDef = getField(schema, model, needField);
955 if (!needDef || needDef.relation) {
956 throw new Error(
957 `Plugin "${plugin.id}" registers ext result field "${fieldName}" on model "${model}" with invalid need "${needField}"`,
958 );
959 }
960 }
961 defs.set(fieldName, fieldDef as ExtResultFieldDef);
962 }
963 }
964 }
965 }
966 return defs;
967}
968
969/**
970 * Prepares query args for extended result fields (recursive):

Callers 2

prepareArgsForExtResultFunction · 0.85
applyExtResultFunction · 0.85

Calls 2

lowerCaseFirstFunction · 0.90
getFieldFunction · 0.90

Tested by

no test coverage detected