polen 0.10.0 → 0.11.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api/api.d.ts +1 -0
- package/build/api/api.d.ts.map +1 -1
- package/build/api/api.js +1 -0
- package/build/api/api.js.map +1 -1
- package/build/api/config/configurator.d.ts +20 -22
- package/build/api/config/configurator.d.ts.map +1 -1
- package/build/api/config/configurator.js +27 -9
- package/build/api/config/configurator.js.map +1 -1
- package/build/api/config/merge.d.ts.map +1 -1
- package/build/api/config/merge.js +0 -11
- package/build/api/config/merge.js.map +1 -1
- package/build/api/content/metadata.d.ts +8 -2
- package/build/api/content/metadata.d.ts.map +1 -1
- package/build/api/content/metadata.js +1 -1
- package/build/api/content/metadata.js.map +1 -1
- package/build/api/schema/data-sources/memory/memory.d.ts +2 -2
- package/build/api/schema/data-sources/memory/memory.d.ts.map +1 -1
- package/build/api/schema/data-sources/memory/memory.js +1 -3
- package/build/api/schema/data-sources/memory/memory.js.map +1 -1
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts +7 -3
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js +15 -11
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js.map +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts +16 -7
- package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.js +26 -7
- package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
- package/build/api/schema/data-sources/schema-file/schema-file.d.ts +7 -2
- package/build/api/schema/data-sources/schema-file/schema-file.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-file/schema-file.js +13 -5
- package/build/api/schema/data-sources/schema-file/schema-file.js.map +1 -1
- package/build/api/schema/metadata.d.ts +16 -0
- package/build/api/schema/metadata.d.ts.map +1 -0
- package/build/api/schema/metadata.js +19 -0
- package/build/api/schema/metadata.js.map +1 -0
- package/build/api/schema/read.d.ts +3 -3
- package/build/api/schema/read.d.ts.map +1 -1
- package/build/api/schema/read.js.map +1 -1
- package/build/api/schema/schema.d.ts +33 -2
- package/build/api/schema/schema.d.ts.map +1 -1
- package/build/api/schema/schema.js +42 -0
- package/build/api/schema/schema.js.map +1 -1
- package/build/api/schema-source/index.d.ts +2 -0
- package/build/api/schema-source/index.d.ts.map +1 -0
- package/build/api/schema-source/index.js +2 -0
- package/build/api/schema-source/index.js.map +1 -0
- package/build/api/schema-source/schema-source.d.ts +33 -0
- package/build/api/schema-source/schema-source.d.ts.map +1 -0
- package/build/api/schema-source/schema-source.js +137 -0
- package/build/api/schema-source/schema-source.js.map +1 -0
- package/build/api/static/manifest.d.ts +1 -2
- package/build/api/static/manifest.d.ts.map +1 -1
- package/build/api/static/manifest.js +1 -1
- package/build/api/static/manifest.js.map +1 -1
- package/build/api/vite/plugins/core.d.ts +1 -0
- package/build/api/vite/plugins/core.d.ts.map +1 -1
- package/build/api/vite/plugins/core.js +21 -18
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/main.d.ts.map +1 -1
- package/build/api/vite/plugins/main.js +1 -8
- package/build/api/vite/plugins/main.js.map +1 -1
- package/build/api/vite/plugins/schema-assets.d.ts +22 -0
- package/build/api/vite/plugins/schema-assets.d.ts.map +1 -0
- package/build/api/vite/plugins/schema-assets.js +269 -0
- package/build/api/vite/plugins/schema-assets.js.map +1 -0
- package/build/api/vite/plugins/serve.d.ts.map +1 -1
- package/build/api/vite/plugins/serve.js +11 -0
- package/build/api/vite/plugins/serve.js.map +1 -1
- package/build/lib/graphql-change/change-groups.d.ts +2 -0
- package/build/lib/graphql-change/change-groups.d.ts.map +1 -1
- package/build/lib/graphql-change/change-groups.js +54 -0
- package/build/lib/graphql-change/change-groups.js.map +1 -1
- package/build/lib/kit-temp.d.ts +9 -0
- package/build/lib/kit-temp.d.ts.map +1 -1
- package/build/lib/kit-temp.js +12 -0
- package/build/lib/kit-temp.js.map +1 -1
- package/build/lib/path-map/path-map.d.ts.map +1 -1
- package/build/lib/path-map/path-map.js +3 -1
- package/build/lib/path-map/path-map.js.map +1 -1
- package/build/project-data.d.ts +3 -11
- package/build/project-data.d.ts.map +1 -1
- package/build/template/components/Changelog.d.ts +3 -3
- package/build/template/components/Changelog.d.ts.map +1 -1
- package/build/template/components/Changelog.js +8 -84
- package/build/template/components/Changelog.js.map +1 -1
- package/build/template/components/CodeBlock.d.ts +2 -0
- package/build/template/components/CodeBlock.d.ts.map +1 -1
- package/build/template/components/CodeBlock.js +1 -4
- package/build/template/components/CodeBlock.js.map +1 -1
- package/build/template/components/ComponentDispatch.d.ts +34 -0
- package/build/template/components/ComponentDispatch.d.ts.map +1 -0
- package/build/template/components/ComponentDispatch.js +33 -0
- package/build/template/components/ComponentDispatch.js.map +1 -0
- package/build/template/components/ReferenceLink.d.ts +19 -0
- package/build/template/components/ReferenceLink.d.ts.map +1 -0
- package/build/template/components/ReferenceLink.js +19 -0
- package/build/template/components/ReferenceLink.js.map +1 -0
- package/build/template/components/TypeAnnotation.d.ts.map +1 -1
- package/build/template/components/TypeAnnotation.js +3 -3
- package/build/template/components/TypeAnnotation.js.map +1 -1
- package/build/template/components/TypeFieldsLinkList.d.ts.map +1 -1
- package/build/template/components/TypeFieldsLinkList.js +4 -4
- package/build/template/components/TypeFieldsLinkList.js.map +1 -1
- package/build/template/components/TypeIndex.js +2 -2
- package/build/template/components/TypeIndex.js.map +1 -1
- package/build/template/components/VersionSelector.d.ts +7 -0
- package/build/template/components/VersionSelector.d.ts.map +1 -0
- package/build/template/components/VersionSelector.js +30 -0
- package/build/template/components/VersionSelector.js.map +1 -0
- package/build/template/components/graphql/type-link.d.ts.map +1 -1
- package/build/template/components/graphql/type-link.js +2 -2
- package/build/template/components/graphql/type-link.js.map +1 -1
- package/build/template/hooks/useVersionPath.d.ts +6 -0
- package/build/template/hooks/useVersionPath.d.ts.map +1 -0
- package/build/template/hooks/useVersionPath.js +10 -0
- package/build/template/hooks/useVersionPath.js.map +1 -0
- package/build/template/layouts/ChangelogLayout.d.ts.map +1 -0
- package/build/template/{components → layouts}/ChangelogLayout.js +1 -1
- package/build/template/layouts/ChangelogLayout.js.map +1 -0
- package/build/template/layouts/index.d.ts +1 -0
- package/build/template/layouts/index.d.ts.map +1 -1
- package/build/template/layouts/index.js +1 -0
- package/build/template/layouts/index.js.map +1 -1
- package/build/template/lib/fetch-text.d.ts +8 -0
- package/build/template/lib/fetch-text.d.ts.map +1 -0
- package/build/template/lib/fetch-text.js +14 -0
- package/build/template/lib/fetch-text.js.map +1 -0
- package/build/template/lib/polen-url.d.ts +14 -0
- package/build/template/lib/polen-url.d.ts.map +1 -1
- package/build/template/lib/polen-url.js +16 -0
- package/build/template/lib/polen-url.js.map +1 -1
- package/build/template/lib/schema-utils/constants.d.ts +5 -0
- package/build/template/lib/schema-utils/constants.d.ts.map +1 -0
- package/build/template/lib/schema-utils/constants.js +5 -0
- package/build/template/lib/schema-utils/constants.js.map +1 -0
- package/build/template/lib/schema-utils/schema-utils.d.ts +15 -0
- package/build/template/lib/schema-utils/schema-utils.d.ts.map +1 -0
- package/build/template/lib/schema-utils/schema-utils.js +37 -0
- package/build/template/lib/schema-utils/schema-utils.js.map +1 -0
- package/build/template/routes/changelog.d.ts +4 -3
- package/build/template/routes/changelog.d.ts.map +1 -1
- package/build/template/routes/changelog.js +13 -7
- package/build/template/routes/changelog.js.map +1 -1
- package/build/template/routes/pages.d.ts +10 -0
- package/build/template/routes/pages.d.ts.map +1 -0
- package/build/template/routes/pages.js +76 -0
- package/build/template/routes/pages.js.map +1 -0
- package/build/template/routes/reference.$type.$field.js +1 -1
- package/build/template/routes/reference.$type.$field.js.map +1 -1
- package/build/template/routes/reference.$type.d.ts +4 -0
- package/build/template/routes/reference.$type.d.ts.map +1 -1
- package/build/template/routes/reference.$type.js +2 -0
- package/build/template/routes/reference.$type.js.map +1 -1
- package/build/template/routes/reference.d.ts +9 -3
- package/build/template/routes/reference.d.ts.map +1 -1
- package/build/template/routes/reference.js +30 -8
- package/build/template/routes/reference.js.map +1 -1
- package/build/template/routes/reference.version.$version.$type.$field.d.ts +6 -0
- package/build/template/routes/reference.version.$version.$type.$field.d.ts.map +1 -0
- package/build/template/routes/reference.version.$version.$type.$field.js +32 -0
- package/build/template/routes/reference.version.$version.$type.$field.js.map +1 -0
- package/build/template/routes/reference.version.$version.$type.d.ts +11 -0
- package/build/template/routes/reference.version.$version.$type.d.ts.map +1 -0
- package/build/template/routes/reference.version.$version.$type.js +26 -0
- package/build/template/routes/reference.version.$version.$type.js.map +1 -0
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.js +8 -72
- package/build/template/routes/root.js.map +1 -1
- package/build/template/server/app.d.ts +22 -1
- package/build/template/server/app.d.ts.map +1 -1
- package/build/template/server/app.js +19 -9
- package/build/template/server/app.js.map +1 -1
- package/build/template/server/main.js +9 -1
- package/build/template/server/main.js.map +1 -1
- package/build/template/server/ssg/generate.js +2 -2
- package/build/template/server/ssg/generate.js.map +1 -1
- package/build/template/server/ssg/get-route-paths.d.ts +1 -1
- package/build/template/server/ssg/get-route-paths.d.ts.map +1 -1
- package/build/template/server/ssg/get-route-paths.js +51 -27
- package/build/template/server/ssg/get-route-paths.js.map +1 -1
- package/build/template/sources/schema-source.d.ts +15 -0
- package/build/template/sources/schema-source.d.ts.map +1 -0
- package/build/template/sources/schema-source.js +63 -0
- package/build/template/sources/schema-source.js.map +1 -0
- package/package.json +16 -17
- package/src/api/api.ts +1 -0
- package/src/api/config/configurator.ts +51 -32
- package/src/api/config/merge.ts +0 -16
- package/src/api/content/metadata.ts +1 -1
- package/src/api/schema/data-sources/memory/memory.ts +3 -5
- package/src/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.ts +29 -13
- package/src/api/schema/data-sources/schema-directory/schema-directory.ts +56 -16
- package/src/api/schema/data-sources/schema-file/schema-file.ts +16 -7
- package/src/api/schema/metadata.ts +23 -0
- package/src/api/schema/read.ts +3 -3
- package/src/api/schema/schema.ts +62 -2
- package/src/api/schema-source/index.ts +1 -0
- package/src/api/schema-source/schema-source.ts +189 -0
- package/src/api/static/manifest.ts +1 -1
- package/src/api/vite/plugins/core.ts +23 -18
- package/src/api/vite/plugins/main.ts +1 -9
- package/src/api/vite/plugins/schema-assets.ts +317 -0
- package/src/api/vite/plugins/serve.ts +15 -8
- package/src/lib/graphql-change/change-groups.ts +57 -0
- package/src/lib/kit-temp.ts +13 -0
- package/src/lib/path-map/$.test.ts +22 -19
- package/src/lib/path-map/path-map.ts +3 -1
- package/src/project-data.ts +3 -11
- package/src/template/components/Changelog.tsx +16 -67
- package/src/template/components/CodeBlock.tsx +3 -5
- package/src/template/components/ComponentDispatch.tsx +42 -0
- package/src/template/components/ReferenceLink.tsx +34 -0
- package/src/template/components/TypeAnnotation.tsx +5 -7
- package/src/template/components/TypeFieldsLinkList.tsx +20 -23
- package/src/template/components/TypeIndex.tsx +10 -12
- package/src/template/components/VersionSelector.tsx +50 -0
- package/src/template/components/graphql/type-link.tsx +4 -3
- package/src/template/hooks/useVersionPath.ts +10 -0
- package/src/template/{components → layouts}/ChangelogLayout.tsx +1 -1
- package/src/template/layouts/index.ts +1 -0
- package/src/template/lib/fetch-text.ts +13 -0
- package/src/template/lib/polen-url.ts +20 -0
- package/src/template/lib/schema-utils/constants.ts +4 -0
- package/src/template/lib/schema-utils/schema-utils.ts +42 -0
- package/src/template/routes/changelog.tsx +17 -8
- package/src/template/routes/pages.tsx +109 -0
- package/src/template/routes/reference.$type.$field.tsx +1 -1
- package/src/template/routes/reference.$type.tsx +2 -0
- package/src/template/routes/reference.tsx +38 -6
- package/src/template/routes/reference.version.$version.$type.$field.tsx +35 -0
- package/src/template/routes/reference.version.$version.$type.tsx +30 -0
- package/src/template/routes/root.tsx +8 -109
- package/src/template/server/app.ts +47 -14
- package/src/template/server/main.ts +9 -1
- package/src/template/server/ssg/generate.ts +2 -2
- package/src/template/server/ssg/get-route-paths.ts +53 -27
- package/src/template/sources/schema-source.ts +68 -0
- package/build/lib/graphql-document/$$.d.ts +0 -5
- package/build/lib/graphql-document/$$.d.ts.map +0 -1
- package/build/lib/graphql-document/$$.js +0 -5
- package/build/lib/graphql-document/$$.js.map +0 -1
- package/build/lib/graphql-document/$.d.ts +0 -2
- package/build/lib/graphql-document/$.d.ts.map +0 -1
- package/build/lib/graphql-document/$.js +0 -2
- package/build/lib/graphql-document/$.js.map +0 -1
- package/build/lib/graphql-document/analysis.d.ts +0 -44
- package/build/lib/graphql-document/analysis.d.ts.map +0 -1
- package/build/lib/graphql-document/analysis.js +0 -361
- package/build/lib/graphql-document/analysis.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts +0 -38
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocument.js +0 -151
- package/build/lib/graphql-document/components/GraphQLDocument.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts +0 -7
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js +0 -27
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts +0 -33
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js +0 -50
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js.map +0 -1
- package/build/lib/graphql-document/components/IdentifierLink.d.ts +0 -39
- package/build/lib/graphql-document/components/IdentifierLink.d.ts.map +0 -1
- package/build/lib/graphql-document/components/IdentifierLink.js +0 -75
- package/build/lib/graphql-document/components/IdentifierLink.js.map +0 -1
- package/build/lib/graphql-document/components/graphql-document-styles.d.ts +0 -5
- package/build/lib/graphql-document/components/graphql-document-styles.d.ts.map +0 -1
- package/build/lib/graphql-document/components/graphql-document-styles.js +0 -144
- package/build/lib/graphql-document/components/graphql-document-styles.js.map +0 -1
- package/build/lib/graphql-document/components/index.d.ts +0 -5
- package/build/lib/graphql-document/components/index.d.ts.map +0 -1
- package/build/lib/graphql-document/components/index.js +0 -5
- package/build/lib/graphql-document/components/index.js.map +0 -1
- package/build/lib/graphql-document/example.d.ts +0 -25
- package/build/lib/graphql-document/example.d.ts.map +0 -1
- package/build/lib/graphql-document/example.js +0 -140
- package/build/lib/graphql-document/example.js.map +0 -1
- package/build/lib/graphql-document/graphql-document.d.ts +0 -35
- package/build/lib/graphql-document/graphql-document.d.ts.map +0 -1
- package/build/lib/graphql-document/graphql-document.js +0 -36
- package/build/lib/graphql-document/graphql-document.js.map +0 -1
- package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts +0 -43
- package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts.map +0 -1
- package/build/lib/graphql-document/hooks/use-tooltip-state.js +0 -132
- package/build/lib/graphql-document/hooks/use-tooltip-state.js.map +0 -1
- package/build/lib/graphql-document/positioning-simple.d.ts +0 -63
- package/build/lib/graphql-document/positioning-simple.d.ts.map +0 -1
- package/build/lib/graphql-document/positioning-simple.js +0 -185
- package/build/lib/graphql-document/positioning-simple.js.map +0 -1
- package/build/lib/graphql-document/schema-context.d.ts +0 -8
- package/build/lib/graphql-document/schema-context.d.ts.map +0 -1
- package/build/lib/graphql-document/schema-context.js +0 -11
- package/build/lib/graphql-document/schema-context.js.map +0 -1
- package/build/lib/graphql-document/schema-integration.d.ts +0 -135
- package/build/lib/graphql-document/schema-integration.d.ts.map +0 -1
- package/build/lib/graphql-document/schema-integration.js +0 -328
- package/build/lib/graphql-document/schema-integration.js.map +0 -1
- package/build/lib/graphql-document/types.d.ts +0 -117
- package/build/lib/graphql-document/types.d.ts.map +0 -1
- package/build/lib/graphql-document/types.js +0 -2
- package/build/lib/graphql-document/types.js.map +0 -1
- package/build/template/components/ChangelogLayout.d.ts.map +0 -1
- package/build/template/components/ChangelogLayout.js.map +0 -1
- package/build/template/components/CodeHikePre.d.ts +0 -16
- package/build/template/components/CodeHikePre.d.ts.map +0 -1
- package/build/template/components/CodeHikePre.js +0 -37
- package/build/template/components/CodeHikePre.js.map +0 -1
- package/src/lib/graphql-document/$$.ts +0 -4
- package/src/lib/graphql-document/$.test.ts +0 -132
- package/src/lib/graphql-document/$.ts +0 -1
- package/src/lib/graphql-document/README.md +0 -102
- package/src/lib/graphql-document/analysis.ts +0 -415
- package/src/lib/graphql-document/components/GraphQLDocument.tsx +0 -265
- package/src/lib/graphql-document/components/GraphQLDocument.unit.test.ts +0 -188
- package/src/lib/graphql-document/components/GraphQLDocumentWithSchema.tsx +0 -46
- package/src/lib/graphql-document/components/GraphQLIdentifierPopover.tsx +0 -199
- package/src/lib/graphql-document/components/IdentifierLink.tsx +0 -160
- package/src/lib/graphql-document/components/graphql-document-styles.ts +0 -144
- package/src/lib/graphql-document/components/index.ts +0 -4
- package/src/lib/graphql-document/demo.md +0 -155
- package/src/lib/graphql-document/example.ts +0 -163
- package/src/lib/graphql-document/graphql-document.ts +0 -37
- package/src/lib/graphql-document/hooks/use-tooltip-state.test.ts +0 -76
- package/src/lib/graphql-document/hooks/use-tooltip-state.ts +0 -191
- package/src/lib/graphql-document/positioning-simple.test.ts +0 -248
- package/src/lib/graphql-document/positioning-simple.ts +0 -260
- package/src/lib/graphql-document/schema-context.tsx +0 -20
- package/src/lib/graphql-document/schema-integration.test.ts +0 -365
- package/src/lib/graphql-document/schema-integration.ts +0 -488
- package/src/lib/graphql-document/types.ts +0 -129
- package/src/template/components/CodeHikePre.tsx +0 -51
- /package/build/template/{components → layouts}/ChangelogLayout.d.ts +0 -0
@@ -2,16 +2,30 @@ import type { Content } from '#api/content/$'
|
|
2
2
|
import { GrafaidOld } from '#lib/grafaid-old/index'
|
3
3
|
import { createRoute } from '#lib/react-router-aid/react-router-aid'
|
4
4
|
import { createLoader, useLoaderData } from '#lib/react-router-loader/react-router-loader'
|
5
|
+
import { Box } from '@radix-ui/themes'
|
5
6
|
import { Outlet } from 'react-router'
|
6
|
-
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
7
7
|
import { MissingSchema } from '../components/MissingSchema.js'
|
8
|
+
import { VersionSelector } from '../components/VersionSelector.js'
|
9
|
+
import { useVersionPath } from '../hooks/useVersionPath.js'
|
8
10
|
import { SidebarLayout } from '../layouts/index.js'
|
11
|
+
import { VERSION_LATEST } from '../lib/schema-utils/constants.js'
|
12
|
+
import { schemaSource } from '../sources/schema-source.js'
|
9
13
|
import { reference$type } from './reference.$type.js'
|
14
|
+
import { referenceVersion$version$type } from './reference.version.$version.$type.js'
|
15
|
+
|
16
|
+
const loader = createLoader(async ({ params }) => {
|
17
|
+
// Handle both versioned and unversioned routes:
|
18
|
+
// - Versioned: /reference/version/:version/:type → params.version exists
|
19
|
+
// - Unversioned: /reference/:type → params.version is undefined, defaults to latest
|
20
|
+
const currentVersion = params.version ?? VERSION_LATEST
|
21
|
+
|
22
|
+
const schema = await schemaSource.get(currentVersion)
|
23
|
+
const availableVersions = schemaSource.versions
|
10
24
|
|
11
|
-
const loader = createLoader(() => {
|
12
|
-
const latestSchemaVersion = PROJECT_DATA.schema?.versions[0].after ?? null
|
13
25
|
return {
|
14
|
-
schema
|
26
|
+
schema,
|
27
|
+
currentVersion,
|
28
|
+
availableVersions,
|
15
29
|
}
|
16
30
|
})
|
17
31
|
|
@@ -28,6 +42,9 @@ const Component = () => {
|
|
28
42
|
const sidebarItems: Content.Item[] = []
|
29
43
|
const kindEntries = Object.entries(kindMap.list).filter(([_, types]) => types.length > 0)
|
30
44
|
|
45
|
+
// Build path prefix based on current version using new route structure
|
46
|
+
const versionPath = useVersionPath()
|
47
|
+
|
31
48
|
for (const [title, types] of kindEntries) {
|
32
49
|
sidebarItems.push({
|
33
50
|
type: `ItemSection` as const,
|
@@ -37,21 +54,36 @@ const Component = () => {
|
|
37
54
|
links: types.map(type => ({
|
38
55
|
type: `ItemLink` as const,
|
39
56
|
title: type.name,
|
40
|
-
pathExp: `reference/${type.name}`,
|
57
|
+
pathExp: `reference/${versionPath}${type.name}`,
|
41
58
|
})),
|
42
59
|
})
|
43
60
|
}
|
44
61
|
|
45
62
|
return (
|
46
63
|
<SidebarLayout sidebar={sidebarItems}>
|
64
|
+
<Box mb={`4`}>
|
65
|
+
<VersionSelector
|
66
|
+
availableVersions={data.availableVersions}
|
67
|
+
currentVersion={data.currentVersion}
|
68
|
+
/>
|
69
|
+
</Box>
|
47
70
|
<Outlet />
|
48
71
|
</SidebarLayout>
|
49
72
|
)
|
50
73
|
}
|
51
74
|
|
75
|
+
// Create the versioned reference route with explicit version prefix
|
76
|
+
const referenceVersioned = createRoute({
|
77
|
+
path: `version/:version`,
|
78
|
+
loader,
|
79
|
+
Component,
|
80
|
+
children: [referenceVersion$version$type],
|
81
|
+
})
|
82
|
+
|
83
|
+
// Create the main reference route with explicit version path and fallback type path
|
52
84
|
export const reference = createRoute({
|
53
85
|
path: `reference`,
|
54
86
|
loader,
|
55
87
|
Component,
|
56
|
-
children: [reference$type],
|
88
|
+
children: [referenceVersioned, reference$type],
|
57
89
|
})
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { Grafaid } from '#lib/grafaid/index'
|
2
|
+
import { createRoute } from '#lib/react-router-aid/react-router-aid'
|
3
|
+
import { useLoaderData } from '#lib/react-router-loader/react-router-loader'
|
4
|
+
import { useParams } from 'react-router'
|
5
|
+
import { Field } from '../components/Field.js'
|
6
|
+
import { MissingSchema } from '../components/MissingSchema.js'
|
7
|
+
import type { reference } from './reference.js'
|
8
|
+
|
9
|
+
const Component = () => {
|
10
|
+
const params = useParams() as { type: string; field: string; version: string }
|
11
|
+
const data = useLoaderData<typeof reference.loader>(`reference`)
|
12
|
+
if (!data.schema) {
|
13
|
+
return <MissingSchema />
|
14
|
+
}
|
15
|
+
|
16
|
+
const type = data.schema.getType(params.type)
|
17
|
+
if (!type) return `Could not find type ${params.type}`
|
18
|
+
if (!Grafaid.Schema.TypesLike.isFielded(type)) {
|
19
|
+
return `Type ${params.type} does not have fields`
|
20
|
+
}
|
21
|
+
|
22
|
+
const fields = type.getFields()
|
23
|
+
const field = fields[params.field]
|
24
|
+
if (!field) {
|
25
|
+
return `Could not find field ${params.field} on type ${params.type}`
|
26
|
+
}
|
27
|
+
|
28
|
+
return <Field data={field} />
|
29
|
+
}
|
30
|
+
|
31
|
+
export const referenceVersion$version$type$field = createRoute({
|
32
|
+
id: `reference-version-type-field`,
|
33
|
+
path: `:field`,
|
34
|
+
Component,
|
35
|
+
})
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { createRoute } from '#lib/react-router-aid/react-router-aid'
|
2
|
+
import { useLoaderData } from '#lib/react-router-loader/react-router-loader'
|
3
|
+
import { useParams } from 'react-router'
|
4
|
+
import { MissingSchema } from '../components/MissingSchema.js'
|
5
|
+
import { NamedType } from '../components/NamedType.js'
|
6
|
+
import type { reference } from './reference.js'
|
7
|
+
import { referenceVersion$version$type$field } from './reference.version.$version.$type.$field.js'
|
8
|
+
|
9
|
+
const Component = () => {
|
10
|
+
const params = useParams() as { type: string; version: string }
|
11
|
+
|
12
|
+
const data = useLoaderData<typeof reference.loader>(`reference`)
|
13
|
+
if (!data.schema) {
|
14
|
+
return <MissingSchema />
|
15
|
+
}
|
16
|
+
|
17
|
+
const type = data.schema.getType(params.type)
|
18
|
+
if (!type) {
|
19
|
+
return <div>Type not found: {params.type}</div>
|
20
|
+
}
|
21
|
+
|
22
|
+
return <NamedType data={type} />
|
23
|
+
}
|
24
|
+
|
25
|
+
export const referenceVersion$version$type = createRoute({
|
26
|
+
id: `reference-version-type`,
|
27
|
+
path: `:type`,
|
28
|
+
Component,
|
29
|
+
children: [referenceVersion$version$type$field],
|
30
|
+
})
|
@@ -1,38 +1,12 @@
|
|
1
1
|
import type { ReactRouter } from '#dep/react-router/index'
|
2
2
|
import { createRoute } from '#lib/react-router-aid/react-router-aid'
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
Badge,
|
7
|
-
Box,
|
8
|
-
Button,
|
9
|
-
Callout,
|
10
|
-
Card,
|
11
|
-
Code,
|
12
|
-
DataList,
|
13
|
-
Em,
|
14
|
-
Flex,
|
15
|
-
Heading,
|
16
|
-
Link,
|
17
|
-
Quote,
|
18
|
-
Separator,
|
19
|
-
Strong,
|
20
|
-
Table,
|
21
|
-
Tabs,
|
22
|
-
Text,
|
23
|
-
Theme,
|
24
|
-
Tooltip,
|
25
|
-
} from '@radix-ui/themes'
|
26
|
-
import { Link as LinkReactRouter, useLocation } from 'react-router'
|
3
|
+
import { Box, Flex, Theme } from '@radix-ui/themes'
|
4
|
+
import { Link as LinkReactRouter } from 'react-router'
|
27
5
|
import { Outlet, ScrollRestoration } from 'react-router'
|
28
6
|
import logoSrc from 'virtual:polen/project/assets/logo.svg'
|
29
7
|
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
30
|
-
import
|
31
|
-
import { routes } from 'virtual:polen/project/routes.jsx'
|
8
|
+
import PROJECT_SCHEMA from 'virtual:polen/project/schema.jsonsuper'
|
32
9
|
import { templateVariables } from 'virtual:polen/template/variables'
|
33
|
-
import { GraphQLSchemaProvider } from '../../lib/graphql-document/schema-context.js'
|
34
|
-
import { CodeBlock } from '../components/CodeBlock.js'
|
35
|
-
import { Pre } from '../components/CodeHikePre.js'
|
36
10
|
import { Link as PolenLink } from '../components/Link.js'
|
37
11
|
import { Logo } from '../components/Logo.js'
|
38
12
|
import { NotFound } from '../components/NotFound.js'
|
@@ -40,22 +14,14 @@ import { ThemeToggle } from '../components/ThemeToggle.js'
|
|
40
14
|
import { ThemeProvider, useTheme } from '../contexts/ThemeContext.js'
|
41
15
|
import { changelog } from './changelog.js'
|
42
16
|
import { index } from './index.js'
|
17
|
+
import { pages } from './pages.js'
|
43
18
|
import { reference } from './reference.js'
|
44
19
|
|
45
20
|
export const Component = () => {
|
46
|
-
const schema = PROJECT_DATA.schema?.versions[0]?.after || null
|
47
|
-
|
48
|
-
// Make schema available globally for MDX components
|
49
|
-
if (typeof window !== `undefined` && schema) {
|
50
|
-
;(window as any).__POLEN_GRAPHQL_SCHEMA__ = schema
|
51
|
-
}
|
52
|
-
|
53
21
|
return (
|
54
22
|
<>
|
55
23
|
<ThemeProvider>
|
56
|
-
<
|
57
|
-
<Layout />
|
58
|
-
</GraphQLSchemaProvider>
|
24
|
+
<Layout />
|
59
25
|
</ThemeProvider>
|
60
26
|
<ScrollRestoration />
|
61
27
|
</>
|
@@ -105,82 +71,15 @@ const Layout = () => {
|
|
105
71
|
py={{ initial: `4`, sm: `4`, md: `0` }}
|
106
72
|
>
|
107
73
|
{header}
|
108
|
-
<
|
109
|
-
components={{
|
110
|
-
// Map markdown elements to Radix with spacing
|
111
|
-
p: (props) => <Text as='p' mb='4' {...props} />,
|
112
|
-
h1: (props) => <Heading size='8' mt='6' mb='4' {...props} />,
|
113
|
-
h2: (props) => <Heading size='7' mt='6' mb='3' {...props} />,
|
114
|
-
h3: (props) => <Heading size='6' mt='5' mb='3' {...props} />,
|
115
|
-
h4: (props) => <Heading size='5' mt='5' mb='2' {...props} />,
|
116
|
-
h5: (props) => <Heading size='4' mt='4' mb='2' {...props} />,
|
117
|
-
h6: (props) => <Heading size='3' mt='4' mb='2' {...props} />,
|
118
|
-
strong: Strong,
|
119
|
-
em: Em,
|
120
|
-
code: Code,
|
121
|
-
blockquote: (props) => <Quote my='4' {...props} />,
|
122
|
-
a: Link,
|
123
|
-
hr: (props) => <Separator my='6' {...props} />,
|
124
|
-
pre: Pre,
|
125
|
-
table: Table.Root,
|
126
|
-
thead: Table.Header,
|
127
|
-
tbody: Table.Body,
|
128
|
-
tr: Table.Row,
|
129
|
-
th: Table.ColumnHeaderCell,
|
130
|
-
td: Table.Cell,
|
131
|
-
// Lists need spacing too
|
132
|
-
ul: (props) => <Box as='ul' mb='4' style={{ paddingLeft: '1.5rem' }} {...props} />,
|
133
|
-
ol: (props) => <Box as='ol' mb='4' style={{ paddingLeft: '1.5rem' }} {...props} />,
|
134
|
-
li: (props) => <Box as='li' mb='2' {...props} />,
|
135
|
-
|
136
|
-
// Direct Radix components for MDX
|
137
|
-
Badge,
|
138
|
-
Button,
|
139
|
-
// @ts-expect-error
|
140
|
-
Callout,
|
141
|
-
Card,
|
142
|
-
// @ts-expect-error
|
143
|
-
DataList,
|
144
|
-
// @ts-expect-error
|
145
|
-
Tabs,
|
146
|
-
Tooltip,
|
147
|
-
|
148
|
-
// Code Hike component
|
149
|
-
CodeBlock,
|
150
|
-
}}
|
151
|
-
>
|
152
|
-
<Outlet />
|
153
|
-
</MDXProvider>
|
74
|
+
<Outlet />
|
154
75
|
</Box>
|
155
76
|
</Theme>
|
156
77
|
)
|
157
78
|
}
|
158
79
|
|
159
|
-
const PagesLayout = () => {
|
160
|
-
const location = useLocation() // Add this line
|
161
|
-
|
162
|
-
// Build sidebar from pages catalog
|
163
|
-
// Get the top-level path segment (e.g., '/guide/foo' -> '/guide')
|
164
|
-
const pathSegments = location.pathname.split('/').filter(Boolean)
|
165
|
-
const topLevelPath = pathSegments[0] ? `/${pathSegments[0]}` : '/'
|
166
|
-
|
167
|
-
// Get the sidebar for this section
|
168
|
-
const sidebar = PROJECT_DATA_PAGES_CATALOG.sidebarIndex[topLevelPath]?.items || []
|
169
|
-
|
170
|
-
return (
|
171
|
-
<SidebarLayout sidebar={sidebar}>
|
172
|
-
<Outlet />
|
173
|
-
</SidebarLayout>
|
174
|
-
)
|
175
|
-
}
|
176
|
-
|
177
80
|
const children: ReactRouter.RouteObject[] = [
|
178
81
|
index,
|
179
|
-
|
180
|
-
// Pathless layout route - doesn't affect URL paths
|
181
|
-
Component: PagesLayout,
|
182
|
-
children: [...routes], // All MDX page routes go here
|
183
|
-
},
|
82
|
+
pages,
|
184
83
|
]
|
185
84
|
|
186
85
|
//
|
@@ -192,7 +91,7 @@ const children: ReactRouter.RouteObject[] = [
|
|
192
91
|
//
|
193
92
|
//
|
194
93
|
|
195
|
-
if (
|
94
|
+
if (PROJECT_SCHEMA) {
|
196
95
|
children.push(changelog)
|
197
96
|
children.push(reference)
|
198
97
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { Hono } from '#dep/hono/index'
|
2
2
|
import { createHtmlTransformer, type HtmlTransformer } from '#lib/html-utils/html-transformer'
|
3
3
|
import { serveStatic } from '@hono/node-server/serve-static'
|
4
|
-
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
5
4
|
import viteClientAssetManifest from 'virtual:polen/vite/client/manifest'
|
6
5
|
import { injectManifestIntoHtml } from './manifest.js'
|
7
6
|
import { PageMiddleware } from './middleware/page.js'
|
@@ -9,16 +8,60 @@ import { UnsupportedAssetsMiddleware } from './middleware/unsupported-assets.js'
|
|
9
8
|
import { createPolenDataInjector } from './transformers/inject-polen-data.js'
|
10
9
|
import { createThemeInitInjector } from './transformers/inject-theme-init.js'
|
11
10
|
|
11
|
+
export type App = Hono.Hono
|
12
|
+
|
12
13
|
export interface AppHooks {
|
13
14
|
transformHtml?: HtmlTransformer[]
|
14
15
|
}
|
15
16
|
|
16
17
|
export interface AppOptions {
|
17
18
|
hooks?: AppHooks
|
19
|
+
paths: {
|
20
|
+
base: string
|
21
|
+
assets: {
|
22
|
+
/**
|
23
|
+
* Directory path for serving static assets.
|
24
|
+
* MUST be a relative path from process.cwd() due to @hono/node-server constraints.
|
25
|
+
* Absolute paths are NOT supported by the serveStatic middleware.
|
26
|
+
*
|
27
|
+
* @example './node_modules/.vite/polen-assets'
|
28
|
+
* @example '../../../polen/node_modules/.vite/polen-assets'
|
29
|
+
* @example './dist/assets'
|
30
|
+
*/
|
31
|
+
directory: string
|
32
|
+
/**
|
33
|
+
* URL route prefix for serving assets
|
34
|
+
* @example '/assets'
|
35
|
+
*/
|
36
|
+
route: string
|
37
|
+
}
|
38
|
+
}
|
18
39
|
}
|
19
40
|
|
20
|
-
export const createApp = (options: AppOptions
|
21
|
-
const app = new Hono.Hono()
|
41
|
+
export const createApp = (options: AppOptions) => {
|
42
|
+
const app = new Hono.Hono().basePath(options.paths.base)
|
43
|
+
|
44
|
+
// Static file serving
|
45
|
+
app.use(`*`, UnsupportedAssetsMiddleware())
|
46
|
+
|
47
|
+
const assetsRoutePattern = `${options.paths.assets.route}/*`
|
48
|
+
|
49
|
+
app.use(
|
50
|
+
assetsRoutePattern,
|
51
|
+
serveStatic({
|
52
|
+
root: options.paths.assets.directory,
|
53
|
+
rewriteRequestPath: (path) => {
|
54
|
+
// When basePath is set, the full path including base is passed here
|
55
|
+
// We need to strip both the base path and the assets route
|
56
|
+
const basePath = options.paths.base === '/' ? '' : options.paths.base
|
57
|
+
const fullPrefix = `${basePath}${options.paths.assets.route}`
|
58
|
+
return path.replace(new RegExp(`^${fullPrefix}`), '')
|
59
|
+
},
|
60
|
+
onNotFound(path) {
|
61
|
+
console.log('not found', path)
|
62
|
+
},
|
63
|
+
}),
|
64
|
+
)
|
22
65
|
|
23
66
|
// Collect all HTML transformers
|
24
67
|
const htmlTransformers: HtmlTransformer[] = [
|
@@ -29,21 +72,11 @@ export const createApp = (options: AppOptions = {}) => {
|
|
29
72
|
...(options.hooks?.transformHtml || []),
|
30
73
|
]
|
31
74
|
|
32
|
-
// Core middleware
|
33
|
-
app.use(`*`, UnsupportedAssetsMiddleware())
|
34
|
-
|
35
|
-
// Production-specific setup
|
36
75
|
if (__BUILDING__) {
|
37
76
|
// Add manifest transformer
|
38
77
|
htmlTransformers.push(createHtmlTransformer((html, ___ctx) => {
|
39
|
-
return injectManifestIntoHtml(html, viteClientAssetManifest,
|
78
|
+
return injectManifestIntoHtml(html, viteClientAssetManifest, options.paths.base)
|
40
79
|
}))
|
41
|
-
|
42
|
-
// Static file serving
|
43
|
-
app.use(
|
44
|
-
PROJECT_DATA.server.static.route,
|
45
|
-
serveStatic({ root: PROJECT_DATA.server.static.directory }),
|
46
|
-
)
|
47
80
|
}
|
48
81
|
|
49
82
|
app.all(`*`, PageMiddleware(htmlTransformers))
|
@@ -12,7 +12,15 @@ if (__BUILDING__) {
|
|
12
12
|
break
|
13
13
|
case `ssr`:
|
14
14
|
const port = process.env[`PORT`] ? parseInt(process.env[`PORT`]) : PROJECT_DATA.server.port
|
15
|
-
const app = createApp(
|
15
|
+
const app = createApp({
|
16
|
+
paths: {
|
17
|
+
assets: {
|
18
|
+
directory: PROJECT_DATA.paths.project.relative.build.relative.assets.root,
|
19
|
+
route: PROJECT_DATA.server.routes.assets,
|
20
|
+
},
|
21
|
+
base: PROJECT_DATA.basePath,
|
22
|
+
},
|
23
|
+
})
|
16
24
|
serve({ fetch: app.fetch, port })
|
17
25
|
break
|
18
26
|
case `spa`:
|
@@ -14,7 +14,7 @@ import { getRoutesPaths } from './get-route-paths.js'
|
|
14
14
|
export const generate = async (view: ReactRouter.StaticHandler) => {
|
15
15
|
const debug = debugPolen.sub(`ssg`)
|
16
16
|
|
17
|
-
const routePaths = getRoutesPaths()
|
17
|
+
const routePaths = await getRoutesPaths()
|
18
18
|
const totalPaths = routePaths.length
|
19
19
|
debug(`start`, { totalPaths })
|
20
20
|
|
@@ -76,7 +76,7 @@ export const generate = async (view: ReactRouter.StaticHandler) => {
|
|
76
76
|
|
77
77
|
const ssgResult = await Hono.SSG.toSSG(batchApp, NodeFs, {
|
78
78
|
concurrency: 5, // Reduced concurrency for memory efficiency
|
79
|
-
dir: PROJECT_DATA.paths.relative.build.root,
|
79
|
+
dir: PROJECT_DATA.paths.project.relative.build.root,
|
80
80
|
})
|
81
81
|
|
82
82
|
if (!ssgResult.success) {
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
import { visit } from 'graphql'
|
3
|
-
// Or your specific import path for this type
|
1
|
+
import { Api } from '#api/index'
|
4
2
|
import { ReactRouterAid } from '#lib/react-router-aid/index'
|
3
|
+
import { visit } from 'graphql'
|
4
|
+
import * as NodeFs from 'node:fs/promises'
|
5
|
+
import * as NodePath from 'node:path'
|
5
6
|
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
6
7
|
import { routes } from '../../routes.js'
|
7
8
|
|
@@ -10,37 +11,62 @@ import { routes } from '../../routes.js'
|
|
10
11
|
// Maybe we can figure something out too.
|
11
12
|
const knownParameterizedRouteExpressions = {
|
12
13
|
reference_type: `/reference/:type`,
|
14
|
+
reference_versioned_type: `/reference/version/:version/:type`,
|
13
15
|
}
|
14
16
|
|
15
|
-
export const getRoutesPaths = (): string[] => {
|
17
|
+
export const getRoutesPaths = async (): Promise<string[]> => {
|
16
18
|
const paths = new Set<string>()
|
17
19
|
const routeExpressions = ReactRouterAid.getRouteExpressions(routes)
|
18
20
|
|
21
|
+
// Helper function to load schema from filesystem and add type paths
|
22
|
+
const addTypePathsForVersion = async (version: string, pathPrefix: string) => {
|
23
|
+
try {
|
24
|
+
const schemaFilePath = NodePath.join(PROJECT_DATA.paths.project.absolute.build.assets.schemas, `${version}.json`)
|
25
|
+
const schemaContent = await NodeFs.readFile(schemaFilePath, 'utf-8')
|
26
|
+
const schemaAst = JSON.parse(schemaContent)
|
27
|
+
|
28
|
+
visit(schemaAst, {
|
29
|
+
ObjectTypeDefinition(node) {
|
30
|
+
paths.add(`${pathPrefix}/${node.name.value}`)
|
31
|
+
},
|
32
|
+
InterfaceTypeDefinition(node) {
|
33
|
+
paths.add(`${pathPrefix}/${node.name.value}`)
|
34
|
+
},
|
35
|
+
EnumTypeDefinition(node) {
|
36
|
+
paths.add(`${pathPrefix}/${node.name.value}`)
|
37
|
+
},
|
38
|
+
InputObjectTypeDefinition(node) {
|
39
|
+
paths.add(`${pathPrefix}/${node.name.value}`)
|
40
|
+
},
|
41
|
+
UnionTypeDefinition(node) {
|
42
|
+
paths.add(`${pathPrefix}/${node.name.value}`)
|
43
|
+
},
|
44
|
+
ScalarTypeDefinition(node) {
|
45
|
+
paths.add(`${pathPrefix}/${node.name.value}`)
|
46
|
+
},
|
47
|
+
})
|
48
|
+
} catch (error) {
|
49
|
+
throw new Error(`SSG failed to load schema for version ${version}. Ensure schema assets are built. ${error}`)
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
const schemaMetadataPath = NodePath.join(PROJECT_DATA.paths.project.absolute.build.assets.schemas, 'metadata.json')
|
54
|
+
|
55
|
+
const schemaMetadata = await Api.Schema.getMetadata(schemaMetadataPath)
|
56
|
+
const { hasSchema, versions: availableVersions } = schemaMetadata
|
57
|
+
|
19
58
|
for (const exp of routeExpressions) {
|
20
59
|
if (exp === knownParameterizedRouteExpressions.reference_type) {
|
21
|
-
if (
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
EnumTypeDefinition(node) {
|
32
|
-
paths.add(`/reference/${node.name.value}`)
|
33
|
-
},
|
34
|
-
InputObjectTypeDefinition(node) {
|
35
|
-
paths.add(`/reference/${node.name.value}`)
|
36
|
-
},
|
37
|
-
UnionTypeDefinition(node) {
|
38
|
-
paths.add(`/reference/${node.name.value}`)
|
39
|
-
},
|
40
|
-
ScalarTypeDefinition(node) {
|
41
|
-
paths.add(`/reference/${node.name.value}`)
|
42
|
-
},
|
43
|
-
})
|
60
|
+
if (hasSchema) {
|
61
|
+
// Add paths for latest version (no version in URL)
|
62
|
+
await addTypePathsForVersion(Api.Schema.VERSION_LATEST, `/reference`)
|
63
|
+
}
|
64
|
+
} else if (exp === knownParameterizedRouteExpressions.reference_versioned_type) {
|
65
|
+
if (hasSchema) {
|
66
|
+
// Add paths for all versions using new route structure
|
67
|
+
for (const version of availableVersions) {
|
68
|
+
await addTypePathsForVersion(version, `/reference/version/${version}`)
|
69
|
+
}
|
44
70
|
}
|
45
71
|
} else if (ReactRouterAid.isParameterizedPath(exp)) {
|
46
72
|
throw new Error(`Unhandled parameterized path: ${exp}`)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
2
|
+
import PROJECT_SCHEMA_METADATA from 'virtual:polen/project/schema-metadata'
|
3
|
+
import { createSchemaSource } from '../../api/schema-source/index.js'
|
4
|
+
import { polenUrlPathAssets } from '../lib/polen-url.js'
|
5
|
+
|
6
|
+
// Environment-specific IO implementation
|
7
|
+
const io = import.meta.env.SSR
|
8
|
+
? {
|
9
|
+
// Server-side: Read from filesystem
|
10
|
+
read: async (path: string) => {
|
11
|
+
// Dynamic import to keep fs out of client bundle
|
12
|
+
const { readFile } = await import('node:fs/promises')
|
13
|
+
|
14
|
+
// Extract the path after the assets route
|
15
|
+
// e.g., "/assets/schemas/latest.json" -> "schemas/latest.json"
|
16
|
+
const assetsRoute = PROJECT_DATA.server.routes.assets
|
17
|
+
const routePattern = new RegExp(`^${assetsRoute}/(.+)$`)
|
18
|
+
const match = path.match(routePattern)
|
19
|
+
const assetPath = match ? match[1] : path
|
20
|
+
|
21
|
+
// In SSR, we need to read from the correct location
|
22
|
+
// During dev, assets are served from Polen's node_modules
|
23
|
+
// In production, they're in the build output directory
|
24
|
+
let fullPath: string
|
25
|
+
if (import.meta.env.DEV) {
|
26
|
+
// Development: Read from Polen's Vite cache
|
27
|
+
fullPath = `${PROJECT_DATA.paths.framework.devAssets.absolute}/${assetPath}`
|
28
|
+
} else {
|
29
|
+
// Production: Read from build output
|
30
|
+
// The server runs from the project root, and assets are in build/assets/
|
31
|
+
fullPath =
|
32
|
+
`${PROJECT_DATA.paths.project.relative.build.root}/${PROJECT_DATA.paths.project.relative.build.relative.assets.root}/${assetPath}`
|
33
|
+
}
|
34
|
+
|
35
|
+
return readFile(fullPath, 'utf-8')
|
36
|
+
},
|
37
|
+
}
|
38
|
+
: {
|
39
|
+
// Client-side: Fetch from HTTP
|
40
|
+
read: async (path: string) => {
|
41
|
+
const response = await fetch(path)
|
42
|
+
if (!response.ok) {
|
43
|
+
throw new Error(`Failed to fetch: ${path} (${response.status} ${response.statusText})`)
|
44
|
+
}
|
45
|
+
return response.text()
|
46
|
+
},
|
47
|
+
}
|
48
|
+
|
49
|
+
// Create and export the source object directly
|
50
|
+
export const schemaSource = createSchemaSource({
|
51
|
+
io,
|
52
|
+
versions: PROJECT_SCHEMA_METADATA.versions,
|
53
|
+
assetsPath: polenUrlPathAssets(),
|
54
|
+
})
|
55
|
+
|
56
|
+
// HMR cache invalidation for development
|
57
|
+
if (import.meta.hot) {
|
58
|
+
import.meta.hot.on('polen:schema-invalidate', () => {
|
59
|
+
console.log('[HMR] Schema cache invalidated')
|
60
|
+
schemaSource.clearCache()
|
61
|
+
|
62
|
+
// Brute force approach: reload the page to ensure fresh data
|
63
|
+
// This guarantees all components see the updated schema immediately
|
64
|
+
// TODO: When we have reactive data fetching, remove this reload
|
65
|
+
// and let the reactive system handle updates gracefully
|
66
|
+
window.location.reload()
|
67
|
+
})
|
68
|
+
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"$$.d.ts","sourceRoot":"","sources":["../../../src/lib/graphql-document/$$.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"$$.js","sourceRoot":"","sources":["../../../src/lib/graphql-document/$$.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"$.d.ts","sourceRoot":"","sources":["../../../src/lib/graphql-document/$.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"$.js","sourceRoot":"","sources":["../../../src/lib/graphql-document/$.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAA"}
|