Skip to content

Commit b69ed08

Browse files
fix: add removeinterfacename for global as collection (#46)
* fix: add removeinterfacename for global as collection * chore: Include dist for direct comsuption from github * chore: remove console.log * chore: remove console.log and build to dist * Remove dist/ * DRY port number * Remove console.log --------- Co-authored-by: Jan Buchar <Teyras@gmail.com>
1 parent 02c0ee0 commit b69ed08

9 files changed

Lines changed: 65 additions & 7 deletions

File tree

dev/app/(payload)/layout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ type Args = {
1414
children: React.ReactNode
1515
}
1616

17-
const serverFunction: ServerFunctionClient = async args =>
18-
handleServerFunctions({
17+
const serverFunction: ServerFunctionClient = async args => {
18+
'use server'
19+
return handleServerFunctions({
1920
...args,
2021
config,
2122
importMap,
2223
})
24+
}
2325

2426
const Layout = ({ children }: Args) => (
2527
<RootLayout config={config} importMap={importMap} serverFunction={serverFunction}>

dev/blocks/MediaBlock/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Block } from 'payload'
2+
3+
export const MediaBlock: Block = {
4+
slug: 'mediaBlock',
5+
interfaceName: 'MediaBlock',
6+
fields: [
7+
{
8+
name: 'media',
9+
type: 'upload',
10+
relationTo: 'media',
11+
required: true,
12+
},
13+
],
14+
}

dev/collections/Pages.ts

Whitespace-only changes.

dev/collections/Posts.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { MediaBlock } from '../blocks/MediaBlock/config.js'
4+
5+
export const Posts: CollectionConfig = {
6+
slug: 'posts',
7+
admin: {
8+
useAsTitle: 'title',
9+
defaultColumns: ['title', 'updatedAt'],
10+
},
11+
fields: [
12+
{
13+
name: 'title',
14+
type: 'text',
15+
required: true,
16+
},
17+
{
18+
name: 'content',
19+
type: 'blocks',
20+
blocks: [MediaBlock],
21+
},
22+
],
23+
}

dev/globals/FeaturedPet.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MediaBlock } from 'blocks/MediaBlock/config.js'
12
import type { GlobalConfig } from 'payload'
23

34
export const FeaturedPet: GlobalConfig = {
@@ -6,5 +7,11 @@ export const FeaturedPet: GlobalConfig = {
67
fields: [
78
{ name: 'pet', type: 'relationship', relationTo: 'pets', required: true },
89
{ name: 'blurb', type: 'text' },
10+
11+
{
12+
name: 'content',
13+
type: 'blocks',
14+
blocks: [MediaBlock],
15+
},
916
],
1017
}

dev/payload.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { testEmailAdapter } from './helpers/testEmailAdapter.js'
1010
import { seed } from './seed.js'
1111

1212
import { Categories, Pets } from './collections/Pets.js'
13+
import { Posts } from './collections/Posts.js'
1314
import { Users } from './collections/Users.js'
1415
import { FeaturedPet } from './globals/FeaturedPet.js'
1516

@@ -28,6 +29,7 @@ export default buildConfig({
2829
},
2930
},
3031
collections: [
32+
Posts,
3133
Pets,
3234
Categories,
3335
Users,

dev/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import open from 'open'
88

99
const dirname = path.dirname(fileURLToPath(import.meta.url))
1010

11+
const port = 3005
12+
1113
const opts: NextServerOptions = {
1214
dev: true,
1315
dir: dirname,
16+
port,
1417
}
1518

1619
// @ts-expect-error next types do not import
@@ -19,11 +22,11 @@ const handle = app.getRequestHandler()
1922

2023
await app.prepare()
2124

22-
await open('http://localhost:3000/admin')
25+
await open(`http://localhost:${port}/admin`)
2326

2427
const server = createServer((req, res) => {
2528
const parsedUrl = parse(req.url!, true)
2629
void handle(req, res, parsedUrl)
2730
})
2831

29-
server.listen(3000)
32+
server.listen(port)

dev/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"noEmit": true,
2323
"emitDeclarationOnly": false,
2424
"incremental": true,
25-
"moduleResolution": "node",
25+
"moduleResolution": "nodenext",
2626
"resolveJsonModule": true,
2727
"isolatedModules": true
2828
}

src/openapi/generators.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const adjustRefTargets = (
6565
})
6666
}
6767

68-
const removeInterfaceNames = (target: SanitizedCollectionConfig) =>
68+
const removeInterfaceNames = (target: SanitizedCollectionConfig | SanitizedGlobalConfig) =>
6969
create(target, draft =>
7070
visitObjectNodes(draft, (subject, key) => {
7171
if (key === 'interfaceName') {
@@ -90,6 +90,7 @@ const generateSchemaObject = (config: SanitizedConfig, collection: Collection):
9090
'text',
9191
undefined,
9292
)
93+
9394
return {
9495
...schema,
9596
title: collectionName(collection).singular,
@@ -494,7 +495,13 @@ const generateGlobalSchemas = (
494495
config: SanitizedConfig,
495496
global: SanitizedGlobalConfig,
496497
): Record<string, JSONSchema4> => {
497-
const schema = entityToJSONSchema(config, global, new Map(), 'text', undefined)
498+
const schema = entityToJSONSchema(
499+
config,
500+
removeInterfaceNames(global),
501+
new Map(),
502+
'text',
503+
undefined,
504+
)
498505

499506
return {
500507
[componentName('schemas', globalName(global))]: { ...schema, title: globalName(global) },

0 commit comments

Comments
 (0)