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

Function createClientProxy

packages/orm/src/client/client-impl.ts:509–542  ·  view source on GitHub ↗
(client: ClientImpl)

Source from the content-addressed store, hash-verified

507}
508
509function createClientProxy(client: ClientImpl): ClientImpl {
510 const resultProcessor = new ResultProcessor(client.$schema, client.$options);
511
512 return new Proxy(client, {
513 get: (target, prop, receiver) => {
514 if (typeof prop === 'string' && prop.startsWith('$')) {
515 // Check for plugin-provided members (search in reverse order so later plugins win)
516 const plugins = target.$options.plugins ?? [];
517 for (let i = plugins.length - 1; i >= 0; i--) {
518 const plugin = plugins[i];
519 const clientMembers = plugin?.client as Record<string, unknown> | undefined;
520 if (clientMembers && prop in clientMembers) {
521 return clientMembers[prop];
522 }
523 }
524 // Fall through to built-in $ methods
525 return Reflect.get(target, prop, receiver);
526 }
527
528 if (typeof prop === 'string') {
529 const model = Object.keys(client.$schema.models).find((m) => m.toLowerCase() === prop.toLowerCase());
530 if (model) {
531 // Check if model is allowed by slicing configuration
532 if (!isModelIncluded(client.$options, model)) {
533 return undefined;
534 }
535 return createModelCrudHandler(client as any, model, client.inputValidator, resultProcessor);
536 }
537 }
538
539 return Reflect.get(target, prop, receiver);
540 },
541 }) as unknown as ClientImpl;
542}
543
544/**
545 * Checks if a model should be included based on slicing configuration.

Callers 1

constructorMethod · 0.85

Calls 3

createModelCrudHandlerFunction · 0.85
findMethod · 0.80
isModelIncludedFunction · 0.70

Tested by

no test coverage detected