@realiizlabs/admin 0.15.8 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -151,6 +151,12 @@ interface PublishInput {
151
151
  } | null;
152
152
  /** Pictures chosen in this session, already shrunk in the browser; committed with the MDX. */
153
153
  images?: ImagePayload[];
154
+ /**
155
+ * The slug this item was opened as (edits only). When the new frontmatter produces a
156
+ * different file name — a date-prefixed event whose date moved — the old file is removed
157
+ * in the same commit, so an edit never leaves a stale copy behind.
158
+ */
159
+ replaces?: string | null;
154
160
  }
155
161
  type PublishResult = {
156
162
  ok: false;
@@ -249,6 +255,7 @@ declare function createStudio(config: StudioConfig): {
249
255
  pendingFor: (path: string) => Promise<PendingChange | null>;
250
256
  pathOf: (typeId: string, slug: string) => Promise<string | null>;
251
257
  listItems: (typeId: string) => Promise<ListItem[]>;
258
+ listSlugs: (typeId: string) => Promise<string[]>;
252
259
  countItems: (typeId: string) => Promise<number>;
253
260
  readItem: (typeId: string, slug: string, opts?: {
254
261
  ref?: string;
@@ -151,6 +151,12 @@ interface PublishInput {
151
151
  } | null;
152
152
  /** Pictures chosen in this session, already shrunk in the browser; committed with the MDX. */
153
153
  images?: ImagePayload[];
154
+ /**
155
+ * The slug this item was opened as (edits only). When the new frontmatter produces a
156
+ * different file name — a date-prefixed event whose date moved — the old file is removed
157
+ * in the same commit, so an edit never leaves a stale copy behind.
158
+ */
159
+ replaces?: string | null;
154
160
  }
155
161
  type PublishResult = {
156
162
  ok: false;
@@ -249,6 +255,7 @@ declare function createStudio(config: StudioConfig): {
249
255
  pendingFor: (path: string) => Promise<PendingChange | null>;
250
256
  pathOf: (typeId: string, slug: string) => Promise<string | null>;
251
257
  listItems: (typeId: string) => Promise<ListItem[]>;
258
+ listSlugs: (typeId: string) => Promise<string[]>;
252
259
  countItems: (typeId: string) => Promise<number>;
253
260
  readItem: (typeId: string, slug: string, opts?: {
254
261
  ref?: string;
@@ -404,6 +404,10 @@ function makeReaders(config, registry, pending) {
404
404
  const entries = await listDirectory(repo(), e.folder);
405
405
  return entries.find((x) => registry.slugOf(e, x.name) === slug)?.path ?? null;
406
406
  };
407
+ const listSlugs = async (typeId) => {
408
+ const items = await listItems(typeId);
409
+ return items.filter((i) => !i.isNew).map((i) => i.slug).sort();
410
+ };
407
411
  const listItems = async (typeId) => {
408
412
  const e = need(typeId);
409
413
  const ctx = repo();
@@ -479,7 +483,7 @@ function makeReaders(config, registry, pending) {
479
483
  }
480
484
  };
481
485
  const prStatus = (number) => getPullRequestStatus(repo(), number);
482
- return { pathOf, listItems, countItems, readItem, lastAuthor, getPullRequest: getPullRequest2, prStatus };
486
+ return { pathOf, listItems, listSlugs, countItems, readItem, lastAuthor, getPullRequest: getPullRequest2, prStatus };
483
487
  }
484
488
 
485
489
  // src/git/branch.ts
@@ -500,11 +504,10 @@ async function createBranch(ctx, branch) {
500
504
  return { branch, baseSha };
501
505
  }
502
506
  async function deleteBranch(ctx, branch) {
503
- await ghFetchOrThrow(
504
- ctx,
505
- "DELETE",
506
- `${repoPath(ctx)}/git/refs/heads/${encodeURIComponent(branch)}`
507
- );
507
+ const path = `${repoPath(ctx)}/git/refs/heads/${encodeURIComponent(branch)}`;
508
+ const res = await ghFetch(ctx, "DELETE", path);
509
+ if (res.ok || res.status === 404 || res.status === 422) return;
510
+ throw toError(res, path);
508
511
  }
509
512
 
510
513
  // src/git/files.ts
@@ -602,18 +605,22 @@ ${input.body.trim()}
602
605
  if (!pictures.ok) return { ok: false, error: pictures.error };
603
606
  const files = [{ path, content }, ...pictures.files];
604
607
  const repo = config.env().repo;
608
+ const oldPath = input.replaces ? await readers.pathOf(entry.id, input.replaces).catch(() => null) : null;
609
+ const remove = oldPath && oldPath !== path ? [oldPath] : [];
610
+ const renamed = remove.length ? `
611
+ Renamed from \`${oldPath}\` to \`${path}\`` : "";
605
612
  if (input.existing && await stillOpen(input.existing.number)) {
606
- await writeFiles(repo, input.existing.branch, files, `Update: ${title}`);
613
+ await writeFiles(repo, input.existing.branch, files, `Update: ${title}`, { remove });
607
614
  redirect(`/admin/pr/${input.existing.number}`);
608
615
  }
609
616
  const branch = `admin/${entry.id}/${fileName.replace(/\.mdx$/, "")}-${stamp()}`;
610
617
  await createBranch(repo, branch);
611
- await writeFiles(repo, branch, files, `Publish: ${title}`);
618
+ await writeFiles(repo, branch, files, `Publish: ${title}`, { remove });
612
619
  const pr = await openPullRequest(repo, branch, {
613
620
  title: `Publish: ${title}`,
614
621
  body: `Published from the dashboard by ${user.email ?? user.id}.
615
622
 
616
- File: \`${path}\``
623
+ File: \`${path}\`${renamed}`
617
624
  });
618
625
  redirect(`/admin/pr/${pr.number}`);
619
626
  };
@@ -1104,7 +1111,7 @@ function makeHandlers(ctx) {
1104
1111
  }
1105
1112
 
1106
1113
  // src/version.ts
1107
- var ADMIN_VERSION = "0.15.8" ;
1114
+ var ADMIN_VERSION = "0.16.0" ;
1108
1115
 
1109
1116
  // src/studio/update.ts
1110
1117
  var PACKAGE_NAME = "@realiizlabs/admin";