Files
Tom Moor 0139b91b5d chore: Replace lodash with es-toolkit (#12281)
* chore: Replace lodash with es-toolkit

Migrate all direct lodash imports to es-toolkit/compat for a smaller,
faster, lodash-compatible utility library. Transitive lodash usage from
other packages remains unchanged.

* fix: Restore isPlainObject semantics in CanCan policy

The lodash migration aliased `isObject` to `lodash/isPlainObject` and
the codemod incorrectly mapped the local name to es-toolkit's `isObject`,
which also returns true for arrays and functions. This caused condition
objects in policy definitions to be skipped, breaking authorization
checks across the codebase.

* fix: Restore unicode-aware length counting in validators

es-toolkit/compat's size() returns string.length, while lodash's _.size()
counts unicode code points. Switch to [...value].length to preserve the
previous behavior so multi-byte characters like emoji count as one.
2026-05-06 21:03:47 -04:00

63 lines
1.8 KiB
TypeScript

import { isEmpty } from "es-toolkit/compat";
import { z } from "zod";
import { SubscriptionType } from "@shared/types";
import { ValidateDocumentId } from "@server/validation";
import { BaseSchema } from "../schema";
const SubscriptionBody = z
.object({
event: z.literal(SubscriptionType.Document),
collectionId: z.uuid().optional(),
documentId: z
.string()
.refine(ValidateDocumentId.isValid, {
message: ValidateDocumentId.message,
})
.optional(),
})
.refine((obj) => !(isEmpty(obj.collectionId) && isEmpty(obj.documentId)), {
error: "one of collectionId or documentId is required",
})
.refine((obj) => !(!isEmpty(obj.collectionId) && !isEmpty(obj.documentId)), {
error: "only one of collectionId or documentId may be provided",
});
export const SubscriptionsListSchema = BaseSchema.extend({
body: SubscriptionBody,
});
export type SubscriptionsListReq = z.infer<typeof SubscriptionsListSchema>;
export const SubscriptionsInfoSchema = BaseSchema.extend({
body: SubscriptionBody,
});
export type SubscriptionsInfoReq = z.infer<typeof SubscriptionsInfoSchema>;
export const SubscriptionsCreateSchema = BaseSchema.extend({
body: SubscriptionBody,
});
export type SubscriptionsCreateReq = z.infer<typeof SubscriptionsCreateSchema>;
export const SubscriptionsDeleteSchema = BaseSchema.extend({
body: z.object({
id: z.uuid(),
}),
});
export type SubscriptionsDeleteReq = z.infer<typeof SubscriptionsDeleteSchema>;
export const SubscriptionsDeleteTokenSchema = BaseSchema.extend({
query: z.object({
follow: z.string().prefault(""),
userId: z.uuid(),
documentId: z.uuid(),
token: z.string(),
}),
});
export type SubscriptionsDeleteTokenReq = z.infer<
typeof SubscriptionsDeleteTokenSchema
>;