Skip to content

Commit

Permalink
small edits
Browse files Browse the repository at this point in the history
Reordered some of the types to be more consistent with the way things
are defined
  • Loading branch information
erikbrinkman committed Sep 22, 2024
1 parent 1f9303f commit 9f00f4b
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,15 @@ export interface EntryCommon {
visibleName: string;
/** the last modified timestamp */
lastModified: string;
/** true if the entry is starred in most ui elements */
pinned: boolean;
/**
* the parent of this entry
*
* There are two special parents, "" (empty string) for the root directory,
* and "trash" for the trash
*/
parent: string;
/** true if the entry is starred in most ui elements */
pinned: boolean;
/** the timestamp of the last time this entry was opened */
lastOpened: string;
parent?: string;
/** any tags the entry might have */
tags?: Tag[];
}
Expand All @@ -138,35 +136,23 @@ export interface DocumentType extends EntryCommon {
type: "DocumentType";
/** the type of the file */
fileType: "epub" | "pdf" | "notebook";
/** the timestamp of the last time this entry was opened */
lastOpened: string;
}

/** a remarkable entry for cloud items */
export type Entry = CollectionEntry | DocumentType;

/** an simple entry produced by the upload api */
export interface UploadEntry {
/** the document id */
docID: string;
/** the document hash */
hash: string;
}

const uploadEntry = properties({
docID: string(),
hash: string(),
}) satisfies CompiledSchema<UploadEntry, unknown>;

const commonProperties = {
id: string(),
hash: string(),
visibleName: string(),
lastModified: string(),
parent: string(),
pinned: boolean(),
lastOpened: string(),
} as const;

const commonOptionalProperties = {
parent: string(),
tags: elements(
properties({
name: string(),
Expand All @@ -178,14 +164,31 @@ const commonOptionalProperties = {
const entry = discriminator("type", {
CollectionType: properties(commonProperties, commonOptionalProperties, true),
DocumentType: properties(
{ ...commonProperties, fileType: enumeration("epub", "pdf", "notebook") },
{
...commonProperties,
lastOpened: string(),
fileType: enumeration("epub", "pdf", "notebook"),
},
commonOptionalProperties,
true,
),
}) satisfies CompiledSchema<Entry, unknown>;

const entries = elements(entry) satisfies CompiledSchema<Entry[], unknown>;

/** an simple entry produced by the upload api */
export interface UploadEntry {
/** the document id */
docID: string;
/** the document hash */
hash: string;
}

const uploadEntry = properties({
docID: string(),
hash: string(),
}) satisfies CompiledSchema<UploadEntry, unknown>;

/** the new hash of a modified entry */
export interface HashEntry {
/** the actual hash */
Expand Down

0 comments on commit 9f00f4b

Please sign in to comment.