(client: ClientImpl)
| 507 | } |
| 508 | |
| 509 | function 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. |
no test coverage detected