Skip to content

Commit

Permalink
feat!: add support for Astro version 4.0 which is now the minimum req…
Browse files Browse the repository at this point in the history
…uired version
  • Loading branch information
HiDeoo committed Jan 4, 2024
1 parent 7cc3a4e commit eb26cc5
Show file tree
Hide file tree
Showing 8 changed files with 2,168 additions and 1,077 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ The Astro Content Devtools are available through an Astro component using [Solid
- 🗜️ Filterable list of collection entry files.
- 📏 Responsive and resizable UI.

> [!WARNING]
> The Astro Content Devtools are not compatible with Astro data content collections.
> [!WARNING]
> 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.
## Installation

Install the Astro Content Devtools package and its peer dependencies using your favorite package manager, e.g. with [pnpm](https://pnpm.io):
Expand Down
8 changes: 5 additions & 3 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0 && astro check && tsc --noEmit"
},
"devDependencies": {
"@astrojs/solid-js": "2.1.0",
"astro": "2.1.3",
"@astrojs/check": "0.3.4",
"@astrojs/solid-js": "4.0.0",
"astro": "4.1.0",
"astro-content-devtools": "workspace:*",
"solid-js": "1.6.15"
"solid-js": "1.8.5",
"typescript": "5.0.2"
},
"engines": {
"node": ">=18"
Expand Down
6 changes: 6 additions & 0 deletions packages/astro-content-devtools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ The Astro Content Devtools are available through an Astro component using [Solid
- 🗜️ Filterable list of collection entry files.
- 📏 Responsive and resizable UI.

> [!WARNING]
> The Astro Content Devtools are not compatible with Astro data content collections.
> [!WARNING]
> 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.
## Installation

Install the Astro Content Devtools package and its peer dependencies using your favorite package manager, e.g. with [pnpm](https://pnpm.io):
Expand Down
18 changes: 10 additions & 8 deletions packages/astro-content-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0 && astro check && tsc --noEmit"
},
"dependencies": {
"zod": "3.21.4",
"zod-to-json-schema": "3.20.4"
"zod": "3.22.4",
"zod-to-json-schema": "3.22.3"
},
"devDependencies": {
"@playwright/test": "1.32.1",
"@astrojs/check": "0.3.4",
"@playwright/test": "1.40.1",
"@types/node": "18.15.10",
"astro": "2.1.3",
"solid-js": "1.6.15"
"astro": "4.1.0",
"solid-js": "1.8.5",
"typescript": "5.0.2"
},
"peerDependencies": {
"@astrojs/solid-js": ">=2.0.0",
"astro": ">=2.0.0",
"solid-js": ">=1.0.0"
"@astrojs/solid-js": ">=4.0.0",
"astro": ">=4.0.0",
"solid-js": ">=1.8.5"
},
"engines": {
"node": ">=18"
Expand Down
4 changes: 2 additions & 2 deletions packages/astro-content-devtools/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export default defineConfig({
],
testDir: 'tests',
use: {
baseURL: 'http://localhost:3000',
baseURL: 'http://localhost:4321',
},
webServer: {
command: 'pnpm run dev',
cwd: '../../demo',
reuseExistingServer: !process.env.CI,
url: 'http://localhost:3000',
url: 'http://localhost:4321',
},
workers: process.env.CI ? 1 : undefined,
})
16 changes: 11 additions & 5 deletions packages/astro-content-devtools/src/libs/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { getCollection, getEntryBySlug } from 'astro:content'
import { type JsonSchema } from './schema'

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

const collections: Collections = {}

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

if (collectionConfig.schema) {
config.schema = zodToJsonSchema(collectionConfig.schema, { $refStrategy: 'none', errorMessages: false })
const schema = collectionConfig.schema
config.schema = zodToJsonSchema(typeof schema === 'function' ? schema({}) : schema, {
$refStrategy: 'none',
errorMessages: false,
})
}

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

interface AstroCollectionConfig {
schema?: AstroCollectionSchema
// eslint-disable-next-line @typescript-eslint/no-explicit-any
schema?: AstroCollectionSchema | ((context: any) => AstroCollectionSchema)
type?: 'content' | 'data'
}

type AstroCollectionSchema = AstroCollectionSchemaWithoutEffects | ZodEffects<AstroCollectionSchemaWithoutEffects>

type AstroCollectionSchemaWithoutEffects =
| AnyZodObject
| ZodUnion<[AnyZodObject, ...AnyZodObject[]]>
| ZodUnion<[AstroCollectionSchemaWithoutEffects, ...AstroCollectionSchemaWithoutEffects[]]>
| ZodDiscriminatedUnion<string, AnyZodObject[]>
| ZodIntersection<AnyZodObject, AnyZodObject>
| ZodIntersection<AstroCollectionSchemaWithoutEffects, AstroCollectionSchemaWithoutEffects>
46 changes: 24 additions & 22 deletions packages/astro-content-devtools/src/libs/schema.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import type { JsonSchema7AnyType } from 'zod-to-json-schema/src/parsers/any'
import type { JsonSchema7ArrayType } from 'zod-to-json-schema/src/parsers/array'
import type { JsonSchema7BigintType } from 'zod-to-json-schema/src/parsers/bigint'
import type { JsonSchema7BooleanType } from 'zod-to-json-schema/src/parsers/boolean'
import type { JsonSchema7DateType } from 'zod-to-json-schema/src/parsers/date'
import type { JsonSchema7EnumType } from 'zod-to-json-schema/src/parsers/enum'
import type { JsonSchema7AllOfType } from 'zod-to-json-schema/src/parsers/intersection'
import type { JsonSchema7LiteralType } from 'zod-to-json-schema/src/parsers/literal'
import type { JsonSchema7MapType } from 'zod-to-json-schema/src/parsers/map'
import type { JsonSchema7NativeEnumType } from 'zod-to-json-schema/src/parsers/nativeEnum'
import type { JsonSchema7NullType } from 'zod-to-json-schema/src/parsers/null'
import type { JsonSchema7NullableType } from 'zod-to-json-schema/src/parsers/nullable'
import type { JsonSchema7NumberType } from 'zod-to-json-schema/src/parsers/number'
import type { JsonSchema7ObjectType } from 'zod-to-json-schema/src/parsers/object'
import type { JsonSchema7RecordType } from 'zod-to-json-schema/src/parsers/record'
import type { JsonSchema7SetType } from 'zod-to-json-schema/src/parsers/set'
import type { JsonSchema7StringType } from 'zod-to-json-schema/src/parsers/string'
import type { JsonSchema7TupleType } from 'zod-to-json-schema/src/parsers/tuple'
import type { JsonSchema7UndefinedType } from 'zod-to-json-schema/src/parsers/undefined'
import type { JsonSchema7UnionType } from 'zod-to-json-schema/src/parsers/union'
import type { JsonSchema7UnknownType } from 'zod-to-json-schema/src/parsers/unknown'
import type {
JsonSchema7AnyType,
JsonSchema7ArrayType,
JsonSchema7BigintType,
JsonSchema7BooleanType,
JsonSchema7DateType,
JsonSchema7EnumType,
JsonSchema7AllOfType,
JsonSchema7LiteralType,
JsonSchema7MapType,
JsonSchema7NativeEnumType,
JsonSchema7NullType,
JsonSchema7NullableType,
JsonSchema7NumberType,
JsonSchema7ObjectType,
JsonSchema7RecordType,
JsonSchema7SetType,
JsonSchema7StringType,
JsonSchema7TupleType,
JsonSchema7UndefinedType,
JsonSchema7UnionType,
JsonSchema7UnknownType,
} from 'zod-to-json-schema'

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

export function isUnknownSchema(schema: JsonSchema): schema is UnknownSchemaType {
return Object.keys(schema).length === 0
return Object.keys(schema as object).length === 0
}

export function isNullSchema(schema: JsonSchema): schema is NullSchemaType {
Expand Down
Loading

0 comments on commit eb26cc5

Please sign in to comment.