Skip to content

Commit

Permalink
feat: update Payload, add Type-Safe REST SDK package. (#82)
Browse files Browse the repository at this point in the history
* payload-53 update

* release 1.2.0-pre.0

* upd

* Bump payload

* feat: update payload, fully typed API client sdk package

* chore: docs + simplify fetcher
  • Loading branch information
r1tsuu authored Jul 4, 2024
1 parent df706ed commit 5ee60d4
Show file tree
Hide file tree
Showing 83 changed files with 1,899 additions and 1,370 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

#### 1. [Plugin Translator](packages/translator/) - automatic content translations / copying from other locales

#### 2. [Cached Local API](packages/cached-local-api/) - cache and automatically revalidate the Local API operations with support of `depth` using Next.js `unstable_cache`
#### 2. [Type-Safe API client for Payload](packages/sdk/) - API client for Payload with the same syntax as the Local API

#### 3. [Fields Select](packages/fields-select/) - select fields from Local API / REST API response like with GraphQL, as well with `defaultSelect` for relationship fields
#### 3. [Cached Local API](packages/cached-local-api/) - cache and automatically revalidate the Local API operations with support of `depth` using Next.js `unstable_cache`

#### 4. [Plugin Docs Reorder](packages/docs-reorder/) - reordering documents in a collection list view
#### 4. [Fields Select](packages/fields-select/) - select fields from Local API / REST API response like with GraphQL, as well with `defaultSelect` for relationship fields

#### 5. [Plugin Better Localized Fields](packages/better-localized-fields/) - Adds to every localized field locales tabs with a field's value on selected locale.
#### 5. [Plugin Docs Reorder](packages/docs-reorder/) - reordering documents in a collection list view

#### 6. [Plugin Better Use-As-Title](packages/better-use-as-title) - Better version of `useAsTitle` property that accepts function with document data as argument.
#### 6. [Plugin Better Localized Fields](packages/better-localized-fields/) - Adds to every localized field locales tabs with a field's value on selected locale.

#### 7. [Bump Payload CLI](packages/bump-payload/) - Bumps all Payload 3.0 related packages versions.
#### 7. [Plugin Better Use-As-Title](packages/better-use-as-title) - Better version of `useAsTitle` property that accepts function with document data as argument.

#### 8. [Plugin SEO](packages/seo) - Alternative version of [official](https://payloadcms.com/docs/plugins/seo) Payload plugin that comes with AI seo generating.
#### 8. [Bump Payload CLI](packages/bump-payload/) - Bumps all Payload 3.0 related packages versions.

#### 9. [Plugin SEO](packages/seo) - Alternative version of [official](https://payloadcms.com/docs/plugins/seo) Payload plugin that comes with AI seo generating.

## Note

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "payload-enchants",
"version": "1.1.41",
"version": "1.2.0",
"private": true,
"description": "",
"keywords": [],
Expand Down Expand Up @@ -29,28 +29,28 @@
"test": "cd test && pnpm test"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.2.3",
"@next/eslint-plugin-next": "^14.2.4",
"@swc/cli": "^0.1.65",
"@swc/core": "^1.5.7",
"@swc/core": "^1.6.3",
"@types/eslint": "8.56.6",
"@types/node": "^20.12.12",
"@types/node": "^20.14.7",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-perfectionist": "^2.10.0",
"eslint-plugin-perfectionist": "^2.11.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"jest": "^29.7.0",
"npkill": "^0.11.3",
"prettier": "^3.2.5",
"prettier": "^3.3.2",
"prettier-plugin-css-order": "^2.1.2",
"rimraf": "^5.0.7",
"sort-package-json": "^2.10.0",
"tsx": "^4.10.5",
"turbo": "^1.13.3",
"typescript": "^5.4.5"
"tsx": "^4.15.7",
"turbo": "^1.13.4",
"typescript": "^5.5.2"
},
"overrides": {
"@types/react": "npm:[email protected]",
Expand Down
18 changes: 9 additions & 9 deletions packages/better-localized-fields/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@payload-enchants/better-localized-fields",
"version": "1.1.41",
"version": "1.2.0",
"private": false,
"bugs": "https://github.com/r1tsuu/payload-enchants/issues",
"repository": "https://github.com/r1tsuu/payload-enchants",
Expand Down Expand Up @@ -43,21 +43,21 @@
"prepublishOnly": "pnpm clean && pnpm build"
},
"devDependencies": {
"@payloadcms/next": "3.0.0-beta.41",
"@payloadcms/translations": "3.0.0-beta.41",
"@payloadcms/ui": "3.0.0-beta.41",
"@payloadcms/next": "3.0.0-beta.58",
"@payloadcms/translations": "3.0.0-beta.58",
"@payloadcms/ui": "3.0.0-beta.58",
"react": "19.0.0-rc-f994737d14-20240522",
"react-dom": "19.0.0-rc-f994737d14-20240522",
"payload": "3.0.0-beta.41",
"payload": "3.0.0-beta.58",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
},
"peerDependencies": {
"@payloadcms/next": "^3.0.0-beta.41",
"@payloadcms/translations": "^3.0.0-beta.41",
"@payloadcms/ui": "^3.0.0-beta.41",
"@payloadcms/next": "^3.0.0-beta.58",
"@payloadcms/translations": "^3.0.0-beta.58",
"@payloadcms/ui": "^3.0.0-beta.58",
"flatley": "^5.2.0",
"payload": "^3.0.0-beta.41"
"payload": "^3.0.0-beta.58"
},
"publishConfig": {
"exports": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Row } from '@payloadcms/ui/fields/Row';
import type { Field } from 'payload/types';
import type { RowLabelProps } from '@payloadcms/ui';
import type { Field } from 'payload';

import { LocalesDataProvider } from './providers/LocalesData/provider';
import { getClientProps } from './utils/getClientProps';
Expand All @@ -13,9 +13,7 @@ export const attachLocalesProvider = (entity: { fields: Field[] }) => {
{
admin: {
components: {
Field: (props) => (
<LocalesDataProvider {...(getClientProps(props) as React.ComponentProps<typeof Row>)} />
),
Field: (props) => <LocalesDataProvider {...(getClientProps(props) as RowLabelProps)} />,
},
},
fields: mainFields,
Expand Down
4 changes: 2 additions & 2 deletions packages/better-localized-fields/src/attachLocalizedField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Field } from 'payload/types';
import { isReactClientComponent } from 'payload/utilities';
import type { Field } from 'payload';
import { isReactClientComponent } from 'payload/shared';

import { LocalizedField } from './components/LocalizedField';
import type { BetterLocalizedFieldsOptions } from './types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RichTextAdapter } from 'payload/types';
import type { RichTextAdapter } from 'payload';

import { LocalizedField } from './components/LocalizedField';
import type { BetterLocalizedFieldsOptions } from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import './index.scss';

import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
import {
useConfig,
useDocumentInfo,
useFieldComponents,
useFieldProps,
useLocale,
withCondition,
} from '@payloadcms/ui';
import { FormContext, FormFieldsContext, FormWatchContext } from '@payloadcms/ui/forms/Form';
import { withCondition } from '@payloadcms/ui/forms/withCondition';
import { useConfig } from '@payloadcms/ui/providers/Config';
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
import { useFieldComponents } from '@payloadcms/ui/providers/FieldComponents';
import { useLocale } from '@payloadcms/ui/providers/Locale';
import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
import { reduceFieldsToValues } from '@payloadcms/ui/shared';
import type { ComponentProps, CSSProperties, ReactElement, ReactNode } from 'react';
import { cloneElement, useEffect, useState } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion packages/better-localized-fields/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'payload/config';
import type { Plugin } from 'payload';

import { attachLocalesProvider } from './attachLocalesProvider';
// import { attachLocalizedFieldToEditor } from './attachLocalizedFieldToEditor';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import type { FormState } from 'payload/types';
import type { FormState } from 'payload';
import { createContext, useContext } from 'react';

export const LocalesDataContext = createContext<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import './index.scss';

import { getTranslation } from '@payloadcms/translations';
import type { Row } from '@payloadcms/ui/fields/Row';
import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
import { RenderFields } from '@payloadcms/ui/forms/RenderFields';
import { useConfig } from '@payloadcms/ui/providers/Config';
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
import { useLocale } from '@payloadcms/ui/providers/Locale';
import { useTranslation } from '@payloadcms/ui/providers/Translation';
import { getFormState } from '@payloadcms/ui/utilities/getFormState';
import type { FormState } from 'payload/types';
import {
RenderFields,
useConfig,
useDocumentInfo,
useFieldProps,
useLocale,
useTranslation,
} from '@payloadcms/ui';
import { getFormState } from '@payloadcms/ui/shared';
import type { FormState, RowLabelComponent } from 'payload';
import type { ComponentProps } from 'react';
import React, { useEffect, useState } from 'react';

import { LocalesDataContext } from './context';

export const LocalesDataProvider = (props: React.ComponentProps<typeof Row>) => {
export const LocalesDataProvider = (props: ComponentProps<RowLabelComponent>) => {
const { fieldMap, forceRender = false } = props;

const [localesFormState, setLocalesFormState] = useState<
Expand Down
2 changes: 1 addition & 1 deletion packages/better-localized-fields/src/traverseFields.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Field } from 'payload/types';
import type { Field } from 'payload';

import { attachLocalizedField } from './attachLocalizedField';
import type { BetterLocalizedFieldsOptions } from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// @ts-expect-error err
import flatleyImport from 'flatley';
import type { FormState } from 'payload/types';
import type { FormState } from 'payload';

const { unflatten } = flatleyImport;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** Copy of ui/src/forms/Form/getSiblingData.ts as its not exported */

import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
import { reduceFieldsToValues } from '@payloadcms/ui/shared';
// @ts-expect-error package no types
import flatleyImport from 'flatley';
import type { Data, FormState } from 'payload/types';
import type { Data, FormState } from 'payload';

const { unflatten } = flatleyImport;

Expand Down
14 changes: 7 additions & 7 deletions packages/better-use-as-title/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@payload-enchants/better-use-as-title",
"version": "1.1.41",
"version": "1.2.0",
"private": false,
"bugs": "https://github.com/r1tsuu/payload-enchants/issues",
"repository": "https://github.com/r1tsuu/payload-enchants",
Expand Down Expand Up @@ -28,17 +28,17 @@
"prepublishOnly": "pnpm clean && pnpm build"
},
"devDependencies": {
"@payloadcms/ui": "3.0.0-beta.41",
"@payloadcms/ui": "3.0.0-beta.58",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"payload": "3.0.0-beta.41",
"typescript": "^5.4.5",
"payload": "3.0.0-beta.58",
"react": "19.0.0-rc-f994737d14-20240522",
"react-dom": "19.0.0-rc-f994737d14-20240522"
"react-dom": "19.0.0-rc-f994737d14-20240522",
"typescript": "^5.5.2"
},
"peerDependencies": {
"@payloadcms/ui": "^3.0.0-beta.41",
"payload": "^3.0.0-beta.41"
"@payloadcms/ui": "^3.0.0-beta.58",
"payload": "^3.0.0-beta.58"
},
"publishConfig": {
"exports": {
Expand Down
6 changes: 2 additions & 4 deletions packages/better-use-as-title/src/index.client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use client';

import { useAllFormFields } from '@payloadcms/ui/forms/Form';
import { useConfig } from '@payloadcms/ui/providers/Config';
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
import { useAllFormFields, useConfig, useDocumentInfo } from '@payloadcms/ui';
import { reduceFieldsToValues } from '@payloadcms/ui/shared';
import { useEffect, useRef } from 'react';

export const InjectCustomUseAsTitle = () => {
Expand Down
12 changes: 5 additions & 7 deletions packages/better-use-as-title/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import type { GeneratedTypes } from 'payload';
import type { Plugin } from 'payload/config';
import type { PayloadRequest, TextField } from 'payload/types';
import { deepMerge } from 'payload/utilities';
import type { PayloadRequest, Plugin, TextField, TypedCollection } from 'payload';
import { deepMerge } from 'payload/shared';

import { InjectCustomUseAsTitle } from './index.client';

export type BetterUseAsTitleArgs<T extends keyof GeneratedTypes['collections']> = {
export type BetterUseAsTitleArgs<T extends keyof TypedCollection> = {
collections: {
fieldOverride?: Partial<TextField>;
slug: T;
useAsTitle: (args: {
data: GeneratedTypes['collections'][T];
data: TypedCollection[T];
req: PayloadRequest;
}) => Promise<string> | string;
}[];
fieldOverride?: Partial<TextField>;
};

export const betterUseAsTitle =
<T extends keyof GeneratedTypes['collections']>(args: BetterUseAsTitleArgs<T>): Plugin =>
<T extends keyof TypedCollection>(args: BetterUseAsTitleArgs<T>): Plugin =>
(config) => {
if (!config.collections) return config;

Expand Down
4 changes: 2 additions & 2 deletions packages/bump-payload/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bump-payload",
"version": "1.1.41",
"version": "1.2.0",
"private": false,
"bugs": "https://github.com/r1tsuu/payload-enchants/issues",
"repository": "https://github.com/r1tsuu/payload-enchants",
Expand All @@ -22,7 +22,7 @@
"prepublishOnly": "pnpm clean && pnpm build"
},
"dependencies": {
"@npmcli/package-json": "^5.1.0"
"@npmcli/package-json": "^5.2.0"
},
"devDependencies": {
"@types/npmcli__package-json": "^4.0.4"
Expand Down
8 changes: 4 additions & 4 deletions packages/cached-local-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@payload-enchants/cached-local-api",
"version": "1.1.41",
"version": "1.2.0",
"private": false,
"bugs": "https://github.com/r1tsuu/payload-enchants/issues",
"repository": "https://github.com/r1tsuu/payload-enchants",
Expand Down Expand Up @@ -33,11 +33,11 @@
"prepublishOnly": "pnpm clean && pnpm build"
},
"devDependencies": {
"payload": "3.0.0-beta.41",
"typescript": "^5.4.5"
"payload": "3.0.0-beta.58",
"typescript": "^5.5.2"
},
"peerDependencies": {
"payload": "^3.0.0-beta.41"
"payload": "^3.0.0-beta.58"
},
"publishConfig": {
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions packages/cached-local-api/src/operations/count.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GeneratedTypes, Payload } from 'payload';
import type { CollectionSlug, Payload } from 'payload';

import type { Count, CountArgs, SanitizedArgsContext } from '../types';

Expand All @@ -9,7 +9,7 @@ export const buildCount = ({
ctx: SanitizedArgsContext;
payload: Payload;
}): Count => {
return async function count<T extends keyof GeneratedTypes['collections']>(args: CountArgs<T>) {
return async function count<T extends CollectionSlug>(args: CountArgs<T>) {
const shouldCache = (await ctx.shouldCacheCountOperation(args)) && !ctx.disableCache;

if (!shouldCache) return payload.count(args);
Expand Down
4 changes: 2 additions & 2 deletions packages/cached-local-api/src/operations/find.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GeneratedTypes, Payload } from 'payload';
import type { CollectionSlug, Payload } from 'payload';

import { populateDocRelationships } from '../populate';
import type { Find, FindArgs, SanitizedArgsContext } from '../types';
Expand All @@ -10,7 +10,7 @@ export const buildFind = ({
ctx: SanitizedArgsContext;
payload: Payload;
}): Find => {
return async function find<T extends keyof GeneratedTypes['collections']>(args: FindArgs<T>) {
return async function find<T extends CollectionSlug>(args: FindArgs<T>) {
const shouldCache = (await ctx.shouldCacheFindOperation(args)) && !ctx.disableCache;

if (!shouldCache) return payload.find(args);
Expand Down
Loading

0 comments on commit 5ee60d4

Please sign in to comment.