Skip to content

Commit 0550abb

Browse files
committed
feat(request): add clientResourceIdentifierSchema to allow for client created relations
1 parent fce44be commit 0550abb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
parseListQuery,
1515
relationship,
1616
resourceIdentifierSchema,
17+
clientResourceIdentifierSchema,
1718
type Sort,
1819
ZodValidationError,
1920
} from "./request.js";

src/request.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,26 @@ export const resourceIdentifierSchema = <TType extends string>(
129129
id: z.string(),
130130
});
131131

132+
type ClientResourceIdentifierSchema<TType extends string> = z.ZodObject<{
133+
type: z.ZodType<TType>;
134+
lid: z.ZodString;
135+
}>;
136+
137+
export const clientResourceIdentifierSchema = <TType extends string>(
138+
type: TType,
139+
): ClientResourceIdentifierSchema<TType> =>
140+
z.object({
141+
type: fixedTypeSchema(type),
142+
lid: z.string(),
143+
});
144+
132145
type RelationshipDataSchema =
133146
| ResourceIdentifierSchema<string>
134147
| z.ZodArray<ResourceIdentifierSchema<string>>
135-
| z.ZodNullable<ResourceIdentifierSchema<string>>;
148+
| z.ZodNullable<ResourceIdentifierSchema<string>>
149+
| ClientResourceIdentifierSchema<string>
150+
| z.ZodArray<ClientResourceIdentifierSchema<string>>
151+
| z.ZodNullable<ClientResourceIdentifierSchema<string>>;
136152

137153
type RelationshipSchema<TData extends RelationshipDataSchema> = z.ZodObject<{
138154
data: TData;

0 commit comments

Comments
 (0)