Files
PaperClipAI/server/src/services/chat-channels/publications/order.ts
T
DottaandPaperclip eb06c9fedd refactor(server): split chat channel workflows into provider and shared modules (#16080)
Move provider operations into channel folders and shared chat work into named interaction, setup, admission, delivery and publication workflows. Consolidate reviewed PRs #16085, #16089, #16096 and #16105. Preserve upstream execution-default and recovery behavior. The main service is 7,917 lines.

All 55 current-head CI checks pass, with two optional Storybook skips. Greptile is 5/5 with no findings. All 1,294 current chat integration cases, repository-wide typecheck and build pass locally. Broad local tool-route timing/socket failures are recorded in the PR.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-13 07:26:32 -05:00

37 lines
796 B
TypeScript

import {
and,
eq,
lt,
or,
sql,
} from "drizzle-orm";
import { type AnyPgColumn } from "drizzle-orm/pg-core";
type PublicationOrderTable = {
createdAt: AnyPgColumn;
id: AnyPgColumn;
payload: AnyPgColumn;
};
function publicationTransportOrderKey(table: PublicationOrderTable) {
return sql<string>`coalesce(${table.payload}->'transportPart'->>'orderKey', ${table.id}::text)`;
}
function publicationPrecedes(
earlier: PublicationOrderTable,
later: PublicationOrderTable,
) {
return or(
lt(earlier.createdAt, later.createdAt),
and(
eq(earlier.createdAt, later.createdAt),
lt(
publicationTransportOrderKey(earlier),
publicationTransportOrderKey(later),
),
),
);
}
export { publicationTransportOrderKey, publicationPrecedes };