Skip to content

Commit eb26cc5

Browse files
committedJan 4, 2024
feat!: add support for Astro version 4.0 which is now the minimum required version
1 parent 7cc3a4e commit eb26cc5

File tree

8 files changed

+2168
-1077
lines changed

8 files changed

+2168
-1077
lines changed
 

‎README.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ The Astro Content Devtools are available through an Astro component using [Solid
3333
- 🗜️ Filterable list of collection entry files.
3434
- 📏 Responsive and resizable UI.
3535

36+
> [!WARNING]
37+
> The Astro Content Devtools are not compatible with Astro data content collections.
38+
39+
> [!WARNING]
40+
> Now that Astro 4.0 has a built-in [Dev Toolbar](https://astro.build/blog/astro-4/#the-astro-dev-toolbar), this package should be refactored to a Dev Toolbar App.
41+
3642
## Installation
3743

3844
Install the Astro Content Devtools package and its peer dependencies using your favorite package manager, e.g. with [pnpm](https://pnpm.io):

‎demo/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0 && astro check && tsc --noEmit"
1414
},
1515
"devDependencies": {
16-
"@astrojs/solid-js": "2.1.0",
17-
"astro": "2.1.3",
16+
"@astrojs/check": "0.3.4",
17+
"@astrojs/solid-js": "4.0.0",
18+
"astro": "4.1.0",
1819
"astro-content-devtools": "workspace:*",
19-
"solid-js": "1.6.15"
20+
"solid-js": "1.8.5",
21+
"typescript": "5.0.2"
2022
},
2123
"engines": {
2224
"node": ">=18"

‎packages/astro-content-devtools/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ The Astro Content Devtools are available through an Astro component using [Solid
3333
- 🗜️ Filterable list of collection entry files.
3434
- 📏 Responsive and resizable UI.
3535

36+
> [!WARNING]
37+
> The Astro Content Devtools are not compatible with Astro data content collections.
38+
39+
> [!WARNING]
40+
> Now that Astro 4.0 has a built-in [Dev Toolbar](https://astro.build/blog/astro-4/#the-astro-dev-toolbar), this package should be refactored to a Dev Toolbar App.
41+
3642
## Installation
3743

3844
Install the Astro Content Devtools package and its peer dependencies using your favorite package manager, e.g. with [pnpm](https://pnpm.io):

‎packages/astro-content-devtools/package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@
1313
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0 && astro check && tsc --noEmit"
1414
},
1515
"dependencies": {
16-
"zod": "3.21.4",
17-
"zod-to-json-schema": "3.20.4"
16+
"zod": "3.22.4",
17+
"zod-to-json-schema": "3.22.3"
1818
},
1919
"devDependencies": {
20-
"@playwright/test": "1.32.1",
20+
"@astrojs/check": "0.3.4",
21+
"@playwright/test": "1.40.1",
2122
"@types/node": "18.15.10",
22-
"astro": "2.1.3",
23-
"solid-js": "1.6.15"
23+
"astro": "4.1.0",
24+
"solid-js": "1.8.5",
25+
"typescript": "5.0.2"
2426
},
2527
"peerDependencies": {
26-
"@astrojs/solid-js": ">=2.0.0",
27-
"astro": ">=2.0.0",
28-
"solid-js": ">=1.0.0"
28+
"@astrojs/solid-js": ">=4.0.0",
29+
"astro": ">=4.0.0",
30+
"solid-js": ">=1.8.5"
2931
},
3032
"engines": {
3133
"node": ">=18"

‎packages/astro-content-devtools/playwright.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export default defineConfig({
1010
],
1111
testDir: 'tests',
1212
use: {
13-
baseURL: 'http://localhost:3000',
13+
baseURL: 'http://localhost:4321',
1414
},
1515
webServer: {
1616
command: 'pnpm run dev',
1717
cwd: '../../demo',
1818
reuseExistingServer: !process.env.CI,
19-
url: 'http://localhost:3000',
19+
url: 'http://localhost:4321',
2020
},
2121
workers: process.env.CI ? 1 : undefined,
2222
})

‎packages/astro-content-devtools/src/libs/content.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import { getCollection, getEntryBySlug } from 'astro:content'
44
import { type JsonSchema } from './schema'
55

66
export async function parseAstroCollections(astroCollections: AstroCollections): Promise<Collections> {
7-
const { default: zodToJsonSchema } = await import('zod-to-json-schema')
7+
const { zodToJsonSchema } = await import('zod-to-json-schema')
88

99
const collections: Collections = {}
1010

1111
for (const [collectionName, collectionConfig] of Object.entries(astroCollections)) {
1212
const config: CollectionConfig = {}
1313

1414
if (collectionConfig.schema) {
15-
config.schema = zodToJsonSchema(collectionConfig.schema, { $refStrategy: 'none', errorMessages: false })
15+
const schema = collectionConfig.schema
16+
config.schema = zodToJsonSchema(typeof schema === 'function' ? schema({}) : schema, {
17+
$refStrategy: 'none',
18+
errorMessages: false,
19+
})
1620
}
1721

1822
collections[collectionName] = config
@@ -46,13 +50,15 @@ export interface CollectionEntry {
4650
export type AstroCollections = Record<CollectionName, AstroCollectionConfig>
4751

4852
interface AstroCollectionConfig {
49-
schema?: AstroCollectionSchema
53+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54+
schema?: AstroCollectionSchema | ((context: any) => AstroCollectionSchema)
55+
type?: 'content' | 'data'
5056
}
5157

5258
type AstroCollectionSchema = AstroCollectionSchemaWithoutEffects | ZodEffects<AstroCollectionSchemaWithoutEffects>
5359

5460
type AstroCollectionSchemaWithoutEffects =
5561
| AnyZodObject
56-
| ZodUnion<[AnyZodObject, ...AnyZodObject[]]>
62+
| ZodUnion<[AstroCollectionSchemaWithoutEffects, ...AstroCollectionSchemaWithoutEffects[]]>
5763
| ZodDiscriminatedUnion<string, AnyZodObject[]>
58-
| ZodIntersection<AnyZodObject, AnyZodObject>
64+
| ZodIntersection<AstroCollectionSchemaWithoutEffects, AstroCollectionSchemaWithoutEffects>

‎packages/astro-content-devtools/src/libs/schema.ts

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
import type { JsonSchema7AnyType } from 'zod-to-json-schema/src/parsers/any'
2-
import type { JsonSchema7ArrayType } from 'zod-to-json-schema/src/parsers/array'
3-
import type { JsonSchema7BigintType } from 'zod-to-json-schema/src/parsers/bigint'
4-
import type { JsonSchema7BooleanType } from 'zod-to-json-schema/src/parsers/boolean'
5-
import type { JsonSchema7DateType } from 'zod-to-json-schema/src/parsers/date'
6-
import type { JsonSchema7EnumType } from 'zod-to-json-schema/src/parsers/enum'
7-
import type { JsonSchema7AllOfType } from 'zod-to-json-schema/src/parsers/intersection'
8-
import type { JsonSchema7LiteralType } from 'zod-to-json-schema/src/parsers/literal'
9-
import type { JsonSchema7MapType } from 'zod-to-json-schema/src/parsers/map'
10-
import type { JsonSchema7NativeEnumType } from 'zod-to-json-schema/src/parsers/nativeEnum'
11-
import type { JsonSchema7NullType } from 'zod-to-json-schema/src/parsers/null'
12-
import type { JsonSchema7NullableType } from 'zod-to-json-schema/src/parsers/nullable'
13-
import type { JsonSchema7NumberType } from 'zod-to-json-schema/src/parsers/number'
14-
import type { JsonSchema7ObjectType } from 'zod-to-json-schema/src/parsers/object'
15-
import type { JsonSchema7RecordType } from 'zod-to-json-schema/src/parsers/record'
16-
import type { JsonSchema7SetType } from 'zod-to-json-schema/src/parsers/set'
17-
import type { JsonSchema7StringType } from 'zod-to-json-schema/src/parsers/string'
18-
import type { JsonSchema7TupleType } from 'zod-to-json-schema/src/parsers/tuple'
19-
import type { JsonSchema7UndefinedType } from 'zod-to-json-schema/src/parsers/undefined'
20-
import type { JsonSchema7UnionType } from 'zod-to-json-schema/src/parsers/union'
21-
import type { JsonSchema7UnknownType } from 'zod-to-json-schema/src/parsers/unknown'
1+
import type {
2+
JsonSchema7AnyType,
3+
JsonSchema7ArrayType,
4+
JsonSchema7BigintType,
5+
JsonSchema7BooleanType,
6+
JsonSchema7DateType,
7+
JsonSchema7EnumType,
8+
JsonSchema7AllOfType,
9+
JsonSchema7LiteralType,
10+
JsonSchema7MapType,
11+
JsonSchema7NativeEnumType,
12+
JsonSchema7NullType,
13+
JsonSchema7NullableType,
14+
JsonSchema7NumberType,
15+
JsonSchema7ObjectType,
16+
JsonSchema7RecordType,
17+
JsonSchema7SetType,
18+
JsonSchema7StringType,
19+
JsonSchema7TupleType,
20+
JsonSchema7UndefinedType,
21+
JsonSchema7UnionType,
22+
JsonSchema7UnknownType,
23+
} from 'zod-to-json-schema'
2224

2325
export function isObjectSchema(schema: JsonSchema): schema is ObjectSchemaType {
2426
return isTypedSchema(schema) && schema.type === 'object' && 'properties' in schema
@@ -92,7 +94,7 @@ export function isUndefinedSchema(schema: JsonSchema): schema is UndefinedSchema
9294
}
9395

9496
export function isUnknownSchema(schema: JsonSchema): schema is UnknownSchemaType {
95-
return Object.keys(schema).length === 0
97+
return Object.keys(schema as object).length === 0
9698
}
9799

98100
export function isNullSchema(schema: JsonSchema): schema is NullSchemaType {

‎pnpm-lock.yaml

+2,104-1,037
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.