Files
outline/server/commands/starCreator.ts
T
Tom MoorandClaude Opus 5.5 00b124d03c chore: Rename APIContext to Context and flatten its fields (#14684)
* chore: Rename APIContext to Context and flatten its fields

Auth and transaction now live directly on the context instead of in
ctx.state and a nested ctx.context, and model helpers read them directly.
APIContext remains as a deprecated alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf

* chore: Remove deprecated APIContext alias

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf

* fix: Read auth from context in OAuth provider callbacks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf

* chore: Add withUser and withTransaction context helpers

Replaces manual createContext rebuilds that copy fields from an existing context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf

* chore: Remove arbitrary property access from Koa context types

AppContext and Context no longer inherit the any index signature from
Koa's DefaultContext, custom fields are declared explicitly, and importing
Koa's loose Context type is disallowed by lint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-23 23:17:06 -05:00

75 lines
1.9 KiB
TypeScript

import fractionalIndex from "fractional-index";
import type { WhereOptions } from "sequelize";
import { Sequelize } from "sequelize";
import type { User } from "@server/models";
import { Star } from "@server/models";
import type { Context } from "@server/types";
type Props = {
/** The user creating the star */
user: User;
/** The document to star */
documentId?: string;
/** The collection to star */
collectionId?: string;
/** The sorted index for the star in the sidebar If no index is provided then it will be at the end */
index?: string;
/** The request context */
ctx: Context;
};
/**
* This command creates a "starred" document via the star relation. Stars are
* only visible to the user that created them.
*
* @param Props The properties of the star to create
* @returns Star The star that was created
*/
export default async function starCreator({
user,
documentId,
collectionId,
ctx,
...rest
}: Props): Promise<Star> {
let { index } = rest;
const where: WhereOptions<Star> = {
userId: user.id,
};
if (!index) {
const stars = await Star.findAll({
where,
attributes: ["id", "index", "updatedAt"],
limit: 1,
order: [
// using LC_COLLATE:"C" because we need byte order to drive the sorting
// find only the first star so we can create an index before it
Sequelize.literal('"star"."index" collate "C"'),
["updatedAt", "DESC"],
],
transaction: ctx.transaction,
});
// create a star at the beginning of the list
index = fractionalIndex(null, stars.length ? stars[0].index : null);
}
const [star] = await Star.findOrCreateWithCtx(ctx, {
where: documentId
? {
userId: user.id,
documentId,
}
: {
userId: user.id,
collectionId,
},
defaults: {
index,
},
});
return star;
}