Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions core/actions/corePubFields.ts

This file was deleted.

4 changes: 4 additions & 0 deletions core/actions/pushToV6/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const action = defineAction({
authToken: z.string().describe("PubPub v6 API auth token"),
title: z.string().describe("Title of the Pub"),
content: z.string().describe("Content of the Pub"),
idField: z
.string()
.regex(/\w+:\w+/)
.describe("Field on this pub to write to id to|ID Field"),
}),
},
description: "Sync a PubPub Platform pub to v6",
Expand Down
17 changes: 9 additions & 8 deletions core/actions/pushToV6/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { ClientExceptionOptions } from "~/lib/serverActions";
import { db } from "~/kysely/database";
import { autoRevalidate } from "~/lib/server/cache/autoRevalidate";
import { isClientExceptionOptions } from "~/lib/serverActions";
import * as corePubFields from "../corePubFields";
import { defineRun } from "../types";

const authError = {
Expand Down Expand Up @@ -159,14 +158,16 @@ const updateV6PubText = async (
}
};

const updateV6PubId = async (pubId: PubsId, v6PubId: string, lastModifiedBy: LastModifiedBy) => {
const updateV6PubId = async (
pubId: PubsId,
v6PubId: string,
lastModifiedBy: LastModifiedBy,
idField: string
) => {
await autoRevalidate(
db
.with("field", (db) =>
db
.selectFrom("pub_fields")
.select("id")
.where("slug", "=", corePubFields.v6PubId.slug)
db.selectFrom("pub_fields").select("id").where("slug", "=", idField)
)
.insertInto("pub_values")
.values((eb) => ({
Expand All @@ -188,7 +189,7 @@ export const run = defineRun<typeof action>(async ({ pub, config, args, lastModi

let v6Pub: { id: string };

const v6PubId = pub.values.find((value) => value.fieldSlug === corePubFields.v6PubId.slug)
const v6PubId = pub.values.find((value) => value.fieldSlug === config.idField)
?.value as string;
// Fetch the pub if the v7 pub already had a v6 pub id
if (v6PubId) {
Expand Down Expand Up @@ -220,7 +221,7 @@ export const run = defineRun<typeof action>(async ({ pub, config, args, lastModi
v6Pub = createV6PubResponse;

// Update the v6 pub id in the v7 pub
await updateV6PubId(pub.id, v6Pub.id, lastModifiedBy);
await updateV6PubId(pub.id, v6Pub.id, lastModifiedBy, config.idField);
}

// Update the v6 pub content
Expand Down
13 changes: 2 additions & 11 deletions core/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import type { Dependency, FieldConfig, FieldConfigItem } from "ui/auto-form";
import type * as Icons from "ui/icon";
import { Event } from "db/public";

import type { CorePubField } from "./corePubFields";
import type { ClientExceptionOptions } from "~/lib/serverActions";

export type ActionPubType = CorePubField[];

type ZodObjectOrWrapped = z.ZodObject<any, any> | z.ZodEffects<z.ZodObject<any, any>>;
export type ZodObjectOrWrappedOrOptional = ZodObjectOrWrapped | z.ZodOptional<ZodObjectOrWrapped>;

Expand All @@ -28,11 +25,7 @@ export type ActionPub = ProcessedPub<{
}>;

export type RunProps<T extends Action> =
T extends Action<
infer P extends ActionPubType,
infer C,
infer A extends ZodObjectOrWrappedOrOptional
>
T extends Action<infer C, infer A extends ZodObjectOrWrappedOrOptional>
? {
config: C["_output"] & { pubFields: { [K in keyof C["_output"]]?: string[] } };
configFieldOverrides: Set<string>;
Expand Down Expand Up @@ -67,7 +60,6 @@ export type TokenDef = {
};

export type Action<
P extends ActionPubType = ActionPubType,
C extends ZodObjectOrWrapped = ZodObjectOrWrapped,
A extends ZodObjectOrWrappedOrOptional = ZodObjectOrWrappedOrOptional,
N extends ActionName = ActionName,
Expand Down Expand Up @@ -139,12 +131,11 @@ export type Action<
};

export const defineAction = <
T extends ActionPubType,
C extends ZodObjectOrWrapped,
A extends ZodObjectOrWrappedOrOptional,
N extends ActionName,
>(
action: Action<T, C, A, N>
action: Action<C, A, N>
) => action;

export type ActionSuccess = {
Expand Down
Loading