Skip to content

Commit d982cc5

Browse files
committed
remove resultField helper
1 parent abae35a commit d982cc5

File tree

2 files changed

+4
-69
lines changed

2 files changed

+4
-69
lines changed

packages/orm/src/client/plugin.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,6 @@ export function definePlugin<
121121
return plugin;
122122
}
123123

124-
/**
125-
* Defines a single extended result field with typed `compute` parameter.
126-
*
127-
* The `compute` callback receives an object whose keys match the `needs` declaration,
128-
* providing autocomplete and type checking for needed fields.
129-
*
130-
* @example
131-
* ```typescript
132-
* definePlugin({
133-
* id: 'my-plugin',
134-
* result: {
135-
* user: {
136-
* fullName: resultField({
137-
* needs: { firstName: true, lastName: true },
138-
* compute: (user) => `${user.firstName} ${user.lastName}`,
139-
* }),
140-
* },
141-
* },
142-
* });
143-
* ```
144-
*/
145-
export function resultField<const N extends Record<string, true>, R>(def: {
146-
needs: N;
147-
compute: (data: { [K in keyof N]: any }) => R;
148-
}): { needs: N; compute: (data: { [K in keyof N]: any }) => R } {
149-
return def;
150-
}
151-
152124
// #region OnProcedure hooks
153125

154126
type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;

tests/e2e/orm/plugin-infra/ext-result.test.ts

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { definePlugin, resultField, type ClientContract } from '@zenstackhq/orm';
1+
import { definePlugin, type ClientContract } from '@zenstackhq/orm';
22
import { createTestClient } from '@zenstackhq/testtools';
33
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
44
import { schema } from './ext-result/schema';
@@ -783,37 +783,6 @@ describe('Plugin extended result fields', () => {
783783
expect(_topLevel).toBe('ALICE');
784784
});
785785

786-
it('should support resultField helper for typed compute', async () => {
787-
const extDb = db.$use(
788-
definePlugin({
789-
id: 'typed-compute',
790-
result: {
791-
user: {
792-
upperName: resultField({
793-
needs: { name: true },
794-
compute: (user) => user.name.toUpperCase(),
795-
}),
796-
},
797-
post: {
798-
titleAndContent: resultField({
799-
needs: { title: true, content: true },
800-
compute: (post) => `${post.title}: ${post.content ?? 'no content'}`,
801-
}),
802-
},
803-
},
804-
}),
805-
);
806-
807-
await extDb.user.create({ data: { name: 'Alice' } });
808-
await extDb.post.create({ data: { title: 'Hello', content: 'World', authorId: 1 } });
809-
810-
const users = await extDb.user.findMany();
811-
expect(users[0]!.upperName).toBe('ALICE');
812-
813-
const posts = await extDb.post.findMany();
814-
expect(posts[0]!.titleAndContent).toBe('Hello: World');
815-
});
816-
817786
it('should ignore invalid model names in result config at runtime', async () => {
818787
const extDb = db.$use(
819788
definePlugin({
@@ -852,9 +821,7 @@ describe('Plugin extended result fields', () => {
852821
}),
853822
);
854823

855-
await expect(extDb.user.findMany()).rejects.toThrow(
856-
/conflicts with an existing model field/,
857-
);
824+
await expect(extDb.user.findMany()).rejects.toThrow(/conflicts with an existing model field/);
858825
});
859826

860827
it('should reject ext result fields with invalid needs field names', async () => {
@@ -872,9 +839,7 @@ describe('Plugin extended result fields', () => {
872839
}),
873840
);
874841

875-
await expect(extDb.user.findMany()).rejects.toThrow(
876-
/invalid need "nonExistentField"/,
877-
);
842+
await expect(extDb.user.findMany()).rejects.toThrow(/invalid need "nonExistentField"/);
878843
});
879844

880845
it('should reject ext result fields with relation fields in needs', async () => {
@@ -892,8 +857,6 @@ describe('Plugin extended result fields', () => {
892857
}),
893858
);
894859

895-
await expect(extDb.user.findMany()).rejects.toThrow(
896-
/invalid need "posts"/,
897-
);
860+
await expect(extDb.user.findMany()).rejects.toThrow(/invalid need "posts"/);
898861
});
899862
});

0 commit comments

Comments
 (0)