Skip to content

Commit

Permalink
Fix checks
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Gieringer <78054+carlgieringer@users.noreply.github.com>
  • Loading branch information
carlgieringer committed May 26, 2023
1 parent 84d5a85 commit 2340641
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 138 deletions.
6 changes: 1 addition & 5 deletions howdju-client-common/lib/target.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as textPosition from "dom-anchor-text-position";
import * as textQuote from "dom-anchor-text-quote";

import {
CreateDomAnchor,
logger,
UrlTarget,
} from "howdju-common";
import { CreateDomAnchor, logger, UrlTarget } from "howdju-common";

import { nodeIsBefore, getPreviousLeafNode } from "./dom";
import { getCanonicalOrCurrentUrl } from "./location";
Expand Down
2 changes: 1 addition & 1 deletion howdju-common/lib/standaloneAjv.js

Large diffs are not rendered by default.

52 changes: 30 additions & 22 deletions howdju-common/lib/zodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
toString,
uniqWith,
} from "lodash";
import { z, ZodFormattedError } from "zod";
import { z } from "zod";

import { assert, mapValuesDeep } from "./general";
import { logger } from "./logger";
Expand Down Expand Up @@ -157,8 +157,8 @@ function makeCallableProxy<T>(): Callable<T, IssueDescriptorArg> {
* a client (they result in the same error message), we should remove them.
*/
export function removeZodErrorDupes<T, U>(
error: ZodFormattedError<T, U>
): FixedZodFormattedError<T, U> {
error: z.ZodFormattedError<T, U>
): ZodFormattedError<T, U> {
return mapValuesDeep(
error,
(val: any, key: string) => {
Expand All @@ -171,31 +171,39 @@ export function removeZodErrorDupes<T, U>(
return val;
},
{ mapArrays: false }
) as FixedZodFormattedError<T, U>;
) as ZodFormattedError<T, U>;
}

/**
* An object having the same shape as a model and possibly adding _errors to each field.
*
* This type is an alias for a ZodFormattedError having our custom issue format.
*/
export type ModelErrors<T> = FixedZodFormattedError<T, ZodCustomIssueFormat>;
export type ModelErrors<T> = ZodFormattedError<T, ZodCustomIssueFormat>;

// DO_NOT_MERGE fix in zod
type FixedZodFormattedError<T, U = string> = T extends (infer V)[] | undefined
? FixedZodFormattedError<V, U>[]
: {
_errors: U[];
} & (T extends [any, ...any[]]
? {
[K in keyof T]?: FixedZodFormattedError<T[K], U>;
}
: T extends any[]
? {
[k: number]: FixedZodFormattedError<T[number], U>;
}
: T extends object
? {
[K in keyof T]?: FixedZodFormattedError<T[K], U>;
/**
* A ZodFormattedError that supports optional arrays
*
* TODO(349) try to contribut this to zod
*/
export type ZodFormattedError<T, U = string> = {
_errors: U[];
} & (T extends [any, ...any[]]
? {
[K in keyof T]?: ZodFormattedError<T[K], U>;
}
: T extends any[]
? {
[k: number]: ZodFormattedError<T[number], U>;
}
: T extends (infer V)[] | undefined
?
| {
[k: number]: ZodFormattedError<V, U>;
}
: unknown);
| undefined
: T extends object
? {
[K in keyof T]?: ZodFormattedError<T[K], U>;
}
: unknown);
47 changes: 14 additions & 33 deletions howdju-common/lib/zodSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { keys, omit } from "lodash";
import { Moment } from "moment";
import { Simplify } from "type-fest";
import { z } from "zod";
import { schemaSettings } from "./schemas";

import { momentObject, urlString } from "./zodRefinements";
import { EntityName, EntityOrRef } from "./zodSchemaTypes";

Expand Down Expand Up @@ -335,20 +335,17 @@ export const CreateDomAnchor = DomAnchor.omit({
});
export type CreateDomAnchor = z.output<typeof CreateDomAnchor>;

/** @deprecated TODO(38) use DomAnchor instead. */
export const UrlTargetAnchor = DomAnchor;
/** @deprecated TODO(38) use DomAnchor instead. */
export type UrlTargetAnchor = DomAnchor;

/** @deprecated */
export const UrlTarget = Entity.extend({
anchors: z.array(UrlTargetAnchor),
anchors: z.array(DomAnchor),
});
/** @deprecated */
export type UrlTarget = z.infer<typeof UrlTarget>;

export const Url = Entity.extend({
url: urlString(),
canonicalUrl: urlString(),
// TODO(38) I don't think target should be part of URL. Targets should be related to URLs.
/** @deprecated TODO(38) replace with UrlLocator.anchors */
target: UrlTarget.optional(),
});
export type Url = z.infer<typeof Url>;
Expand All @@ -358,13 +355,6 @@ export type CreateUrl = z.infer<typeof CreateUrl>;
export const CreateUrlInput = CreateUrl;
export type CreateUrlInput = z.infer<typeof CreateUrlInput>;

// DO_NOT_MERGE replace with UrlLocator?
export const UrlAnchors = Entity.extend({
url: urlString(),
anchors: z.array(DomAnchor),
});
export type UrlAnchors = z.infer<typeof UrlAnchors>;

export const UrlLocator = Entity.extend({
url: Url,
anchors: z.array(DomAnchor).optional(),
Expand All @@ -373,7 +363,7 @@ export type UrlLocator = z.output<typeof UrlLocator>;

/** A reference to a part of a textual media. */
export const WritQuote = Entity.extend({
quoteText: z.string().min(1).max(schemaSettings.writQuoteQuoteTextMaxLength),
quoteText: z.string().min(1).max(4096),
writ: Writ,
urls: z.array(Url),
created: momentObject,
Expand Down Expand Up @@ -413,11 +403,11 @@ export const SourceExcerpt = z.discriminatedUnion("type", [
entity: VidSegment,
}),
]);
/** @deprecated */
/** @deprecated TODO(38) replace with MediaExcerpt */
export type SourceExcerpt = z.infer<typeof SourceExcerpt>;
/** @deprecated */
/** @deprecated TODO(38) replace with MediaExcerpt */
export type SourceExcerptType = SourceExcerpt["type"];
/** @deprecated */
/** @deprecated See SourceExcerpt */
export const SourceExcerptTypes = sourceExcerptTypes.Enum;

export const CreateUrlLocator = UrlLocator.omit({ id: true }).extend({
Expand Down Expand Up @@ -477,11 +467,7 @@ export type CreateMediaExcerptCitationInput = z.output<
typeof CreateMediaExcerptCitationInput
>;

/**
* A representation of an excerpt of some fixed media conveying speech.
*
* TODO replace SourceExcerpt with this.
*/
/** A representation of an excerpt of some fixed media conveying speech. */
export const MediaExcerpt = Entity.extend({
/**
* One or more local representations of the excerpt.
Expand Down Expand Up @@ -517,14 +503,8 @@ export const MediaExcerpt = Entity.extend({
* For textual media, this text must appear in the media. For audio and video media, this
* text must be a transcription of the speech that appears in the media.
*/
quotation: z
.string()
.min(1)
.max(schemaSettings.writQuoteQuoteTextMaxLength),
normalQuotation: z
.string()
.min(1)
.max(schemaSettings.writQuoteQuoteTextMaxLength),
quotation: z.string().min(1).max(4096),
normalQuotation: z.string().min(1).max(4096),
}),
/**
* Provides a procedure for locating the local representation in situ remotely.
Expand Down Expand Up @@ -673,14 +653,15 @@ export type Justification = Entity & {
type: "PROPOSITION_COMPOUND";
entity: PropositionCompound;
}
/* @deprecated TODO(38) Replace with MediaExcerpt */
| {
type: "SOURCE_EXCERPT";
entity: SourceExcerpt;
}
/**
* A quote from a written source
*
* @deprecated Use SOURCE_EXCERPT's WRIT_QUOTE type instead.
* @deprecated TODO(38) Replace with MediaExcerpt
*/
| {
type: "WRIT_QUOTE";
Expand Down
62 changes: 0 additions & 62 deletions howdju-service-common/lib/daos/DomAnchorsDao.ts

This file was deleted.

2 changes: 1 addition & 1 deletion howdju-service-common/lib/daos/MediaExcerptsDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export class MediaExcerptsDao {
const args: any[] = [mediaExcerpt.id, createUrlLocator.url.id];
let argIndex = 3;
createUrlLocator.anchors.forEach((a, i) => {
// DO_NOT_MERGE select remaining anchor fields and populate UrlLocator.anchors
selects.push(`
da${i}.created as da${i}_created,
da${i}.creator_user_id as da${i}_creator_user_id`);
Expand Down Expand Up @@ -275,6 +274,7 @@ export class MediaExcerptsDao {
if (!row) {
return undefined;
}

const urlLocatorId = row.url_locator_id;
const anchors: Partial<DomAnchor>[] = new Array(
createUrlLocator.anchors.length
Expand Down
2 changes: 1 addition & 1 deletion howdju-service-common/lib/services/PersorgsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class PersorgsService extends EntityService<
_userId: EntityId,
_now: Moment
): Promise<{ isExtant: boolean; persorg: PersorgOut }> {
// TODO replace bespoke readOrCreate methods with base class's implementation.
// TODO(361): replace bespoke readOrCreate methods with base class's implementation.
throw newUnimplementedError("doReadOrCreate is not implemented.");
}

Expand Down
10 changes: 8 additions & 2 deletions howdju-service-common/lib/services/joiErrors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ValidationError } from "joi";
import { z } from "zod";
import { ModelErrors, zodIssueFormatter } from "howdju-common";
import {
ZodFormattedError,
ModelErrors,
zodIssueFormatter,
} from "howdju-common";

/**
* Converts a Joi error to Zod's error format.
Expand All @@ -14,5 +18,7 @@ export function translateJoiToZodFormattedError<T>(
path,
message,
}));
return new z.ZodError<T>(issues).format(zodIssueFormatter);
return new z.ZodError<T>(issues).format(
zodIssueFormatter
) as ZodFormattedError<T, z.ZodIssue>;
}
2 changes: 1 addition & 1 deletion premiser-api/db/migrations/x099_add_appearances.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- DO_NOT_MERGE delete
-- TODO(20,38) delete this file

create table if not exists sentence_appearances (
sentence_appearance_id serial primary key,
Expand Down
6 changes: 3 additions & 3 deletions premiser-ui/src/CreatePropositionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ export default function CreatePropositionPage({ mode, location }: Props) {
)}
name={combineNames(speakersName, array(index))}
disabled={isSaving}
onPersorgNameAutocomplete={(persorg: PersorgOut) =>
onPersorgAutocomplete(persorg, index)
}
onPersorgNameAutocomplete={(
persorg: PersorgOut
) => onPersorgAutocomplete(persorg, index)}
onPropertyChange={onPropertyChange}
errors={errors.speakers?.[index]}
wasSubmitAttempted={wasSubmitAttempted}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ export function* submitMediaExcerptFromAnchorInfo() {

function toCreateMediaExcerptInput(payload: Payload): CreateMediaExcerptInput {
const { anchors, documentTitle, url } = payload;
const quoteText = anchors.map((a) => a.exactText.trim()).join("\n\n");
const quotation = anchors.map((a) => a.exactText.trim()).join("\n\n");
return {
localRep: {
writQuote: {
quoteText,
},
quotation,
},
// Should relate to localRep
remoteProcs: {
urlLocators: [{ url, anchors }],
locators: {
urlLocators: [{ url: { url }, anchors }],
},
sources: [
citations: [
{
source: { descriptionApa: documentTitle },
},
Expand Down

0 comments on commit 2340641

Please sign in to comment.