Skip to content

Commit

Permalink
feat(request): add clientResourceIdentifierSchema to allow for client…
Browse files Browse the repository at this point in the history
… created relations
  • Loading branch information
DASPRiD committed Mar 26, 2024
1 parent fce44be commit 0550abb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
parseListQuery,
relationship,
resourceIdentifierSchema,
clientResourceIdentifierSchema,
type Sort,
ZodValidationError,
} from "./request.js";
Expand Down
18 changes: 17 additions & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,26 @@ export const resourceIdentifierSchema = <TType extends string>(
id: z.string(),
});

type ClientResourceIdentifierSchema<TType extends string> = z.ZodObject<{
type: z.ZodType<TType>;
lid: z.ZodString;
}>;

export const clientResourceIdentifierSchema = <TType extends string>(
type: TType,
): ClientResourceIdentifierSchema<TType> =>
z.object({
type: fixedTypeSchema(type),
lid: z.string(),
});

type RelationshipDataSchema =
| ResourceIdentifierSchema<string>
| z.ZodArray<ResourceIdentifierSchema<string>>
| z.ZodNullable<ResourceIdentifierSchema<string>>;
| z.ZodNullable<ResourceIdentifierSchema<string>>
| ClientResourceIdentifierSchema<string>
| z.ZodArray<ClientResourceIdentifierSchema<string>>
| z.ZodNullable<ClientResourceIdentifierSchema<string>>;

type RelationshipSchema<TData extends RelationshipDataSchema> = z.ZodObject<{
data: TData;
Expand Down

0 comments on commit 0550abb

Please sign in to comment.