From 698f5bd0f990ca2ff972dc8fba97caae711dc896 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 10 Jan 2024 12:37:03 +0100 Subject: [PATCH 1/5] fix(#12): remove communityId type for methods that use routes that only have mandatory communityId as a parameter such as pub.create --- src/lib/client-types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/client-types.ts b/src/lib/client-types.ts index 67ea4c9..94144c9 100644 --- a/src/lib/client-types.ts +++ b/src/lib/client-types.ts @@ -34,7 +34,7 @@ export type ProxiedFunction< : Partial> extends Omit ? // if there are no required arguments, you don't need to pass the body ( - input?: Prettify, //Prettify>, + input?: Prettify>, //Prettify>, rest?: Prettify>, ) => R : ( From fde12f55ff65c2aae999bc8b34a79060f2faf7d4 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 10 Jan 2024 14:03:17 +0100 Subject: [PATCH 2/5] fix: update core --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index 96f4fed..a90a7c9 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 96f4fed473fd5795981cb65d55d9871b026e7eab +Subproject commit a90a7c9b896b0224ad68d2a16e4a500b748130d8 From 41302ff85c49ded5b989e47727a6eb4155727121 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 10 Jan 2024 14:23:21 +0100 Subject: [PATCH 3/5] fix: improve types --- pnpm-lock.yaml | 12 ++++ readme.md | 150 ++++++++++++++++++---------------------- src/lib/client-types.ts | 39 +++++++---- 3 files changed, 103 insertions(+), 98 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8549670..61a6cc2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -783,6 +783,9 @@ importers: zod-to-json-schema: specifier: ^3.17.0 version: 3.21.4(zod@3.22.4) + zod-validation-error: + specifier: ^2.1.0 + version: 2.1.0(zod@3.22.4) zotero-api-client: specifier: ^0.40.0 version: 0.40.1 @@ -26939,6 +26942,15 @@ packages: zod: 3.22.4 dev: false + /zod-validation-error@2.1.0(zod@3.22.4): + resolution: {integrity: sha512-VJh93e2wb4c3tWtGgTa0OF/dTt/zoPCPzXq4V11ZjxmEAFaPi/Zss1xIZdEB5RD8GD00U0/iVXgqkF77RV7pdQ==} + engines: {node: '>=18.0.0'} + peerDependencies: + zod: ^3.18.0 + dependencies: + zod: 3.22.4 + dev: false + /zod@3.22.4: resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} dev: false diff --git a/readme.md b/readme.md index 757211c..94664e7 100644 --- a/readme.md +++ b/readme.md @@ -3240,7 +3240,6 @@ You need to be **logged in** and have access to this resource. accentTextColor: string avatar: null | string citeAs: null | string - communityId: string defaultPubCollections: null | string[] description: null | string domain: null | string @@ -3643,7 +3642,7 @@ You need to be **logged in** and have access to this resource. CitationStyle: | undefined | { - citationStyle: + citationStyle?: | 'acm-siggraph' | 'american-anthro' | 'apa' @@ -3657,12 +3656,18 @@ You need to be **logged in** and have access to this resource. | 'mla' | 'vancouver' | 'ama' - inlineCitationStyle: 'label' | 'count' | 'authorYear' | 'author' + | undefined + inlineCitationStyle?: + | 'label' + | 'count' + | 'authorYear' + | 'author' + | undefined } License: | undefined | { - kind: + kind?: | 'cc-by' | 'cc-0' | 'cc-by-nc' @@ -3671,30 +3676,53 @@ You need to be **logged in** and have access to this resource. | 'cc-by-nc-sa' | 'cc-by-sa' | 'copyright' - copyrightSelection: { - choice: 'infer-from-scope' | 'choose-here' - year: number | null - } + | undefined + copyrightSelection?: + | { + choice?: 'infer-from-scope' | 'choose-here' | undefined + year?: number | null | undefined + } + | undefined } NodeLabels: | undefined | { - image: { enabled: boolean; text: string } - video: { enabled: boolean; text: string } - audio: { enabled: boolean; text: string } - table: { enabled: boolean; text: string } - math: { enabled: boolean; text: string } - iframe: { enabled: boolean; text: string } + image?: + | { enabled?: boolean | undefined; text?: string | undefined } + | undefined + video?: + | { enabled?: boolean | undefined; text?: string | undefined } + | undefined + audio?: + | { enabled?: boolean | undefined; text?: string | undefined } + | undefined + table?: + | { enabled?: boolean | undefined; text?: string | undefined } + | undefined + math?: + | { enabled?: boolean | undefined; text?: string | undefined } + | undefined + iframe?: + | { enabled?: boolean | undefined; text?: string | undefined } + | undefined } PubEdgeDisplay: | undefined - | { defaultsToCarousel: boolean; descriptionIsVisible: boolean } + | { + defaultsToCarousel?: boolean | undefined + descriptionIsVisible?: boolean | undefined + } PubHeaderTheme: | undefined | { - backgroundImage: string - backgroundColor: string - textStyle: 'light' | 'dark' | 'black-blocks' | 'white-blocks' + backgroundImage?: string | undefined + backgroundColor?: string | undefined + textStyle?: + | 'light' + | 'dark' + | 'black-blocks' + | 'white-blocks' + | undefined } } scope: { @@ -4603,67 +4631,25 @@ You need to be **logged in** and have access to this resource. `input?` ```ts - - | { - avatar: null | string - collectionId: null | string - communityId: string - createPubToken: undefined - customPublishedAt: null | string - description: null | string - doi: null | string - downloads: - | null - | { - createdAt: string - type: 'formatted' - url: string - }[] - htmlDescription: null | string - htmlTitle: null | string - slug: string - title: string - } - | { - avatar: null | string - collectionId: undefined - communityId: string - createPubToken: null | string - customPublishedAt: null | string - description: null | string - doi: null | string - downloads: - | null - | { - createdAt: string - type: 'formatted' - url: string - }[] - htmlDescription: null | string - htmlTitle: null | string - slug: string - title: string - } - | { - avatar: null | string - collectionId: undefined - communityId: string - createPubToken: undefined - customPublishedAt: null | string - description: null | string - doi: null | string - downloads: - | null - | { - createdAt: string - type: 'formatted' - url: string - }[] - htmlDescription: null | string - htmlTitle: null | string - slug: string - title: string - } +{ + avatar: null | string + collectionId: null | string + createPubToken: null | string + customPublishedAt: null | string + description: null | string + doi: null | string + downloads: + | null + | { + createdAt: string + type: 'formatted' + url: string + }[] + htmlDescription: null | string + htmlTitle: null | string + slug: string + title: string +} ``` `rest?` @@ -4763,8 +4749,7 @@ You need to be **logged in** and have access to this resource. `input` ```ts -{ -} +;undefined | null | {} ``` `rest` @@ -4839,8 +4824,7 @@ You need to be **logged in** and have access to this resource. `input` ```ts -{ -} +;undefined | null | {} ``` `rest` diff --git a/src/lib/client-types.ts b/src/lib/client-types.ts index 94144c9..8a9910a 100644 --- a/src/lib/client-types.ts +++ b/src/lib/client-types.ts @@ -19,35 +19,44 @@ export type Prettify = { export type ProxiedFunction< F, IsGetRoute extends boolean = false, - Property extends 'body' | 'query' = IsGetRoute extends false + BodyOrQuery extends 'body' | 'query' = IsGetRoute extends false ? 'body' : 'query', -> = F extends (...args: infer A extends any[]) => infer R - ? A[0] extends { [K in Property]: infer B } +> = F extends (...args: infer Arguments extends any[]) => infer R + ? Arguments[0] extends { [K in BodyOrQuery]: infer B } ? // if only the body is required, make the second argument optional - Partial> extends Omit - ? FormData extends B + Partial> extends Omit< + Arguments[0], + BodyOrQuery + > + ? // form bodies look like FormData & {...}, we don't want to require the FormData part + FormData extends B ? ( input: Exclude, - rest?: Prettify>, + rest?: Prettify>, ) => R : Partial> extends Omit ? // if there are no required arguments, you don't need to pass the body ( input?: Prettify>, //Prettify>, - rest?: Prettify>, + rest?: Prettify>, ) => R : ( input: Prettify>, - rest?: Prettify>, + rest?: Prettify>, ) => R - : ( - input: Prettify>, - rest: Prettify>, - ) => R - : undefined extends A[0] - ? (input?: Prettify) => R - : (input: Prettify) => R + : FormData extends B + ? ( + input: Exclude, + rest: Prettify>, + ) => R + : ( + input: Prettify>, + rest: Prettify>, + ) => R + : undefined extends Arguments[0] + ? (input?: Prettify) => R + : (input: Prettify) => R : never export type ProxiedClient = { From cec60314025d3b88ebf9fc4196c44f242dbe34d6 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 10 Jan 2024 14:30:47 +0100 Subject: [PATCH 4/5] chore: update core to master! --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index a90a7c9..2dfe92a 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a90a7c9b896b0224ad68d2a16e4a500b748130d8 +Subproject commit 2dfe92a70d647278e512a91dfb060e4480739df2 From f4f12f04a08da662a1bfe28a89d0205c334960a4 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 10 Jan 2024 14:35:58 +0100 Subject: [PATCH 5/5] fix: add a test for importing to pub --- test/test.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test.test.ts b/test/test.test.ts index 8cf64b3..f8d5a8f 100644 --- a/test/test.test.ts +++ b/test/test.test.ts @@ -171,6 +171,7 @@ describe('PubPub', () => { // it('should be able to update a community', async () => {}) + let importedPubId: string it('should be able to import a pub', async () => { const { body } = await pubpub.pub.text.import({ files: [ @@ -190,6 +191,35 @@ describe('PubPub', () => { expect(JSON.stringify(doc)?.includes('heya')).toBeTruthy() expect(pub).toHaveProperty('title') expect(pub.title).toBe('imported pub') + + importedPubId = pub.id + }, 20000) + + it('should be able to import to a pub', async () => { + const { body } = await pubpub.pub.text.importToPub( + { + files: [ + { + blob: new Blob([':D'], { type: 'text/plain' }), + filename: 'happy.txt', + }, + ], + method: 'append', + }, + { + params: { + pubId: importedPubId, + }, + }, + ) + + const { doc, pub } = body + + expect(pub.id).toEqual(importedPubId) + + const stringDoc = JSON.stringify(doc) + expect(stringDoc).toContain(':D') + expect(stringDoc).toContain('heya') }, 20000) it('should be able to query things', async () => {