astro 2.4.5 → 2.5.0

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.
Files changed (118) hide show
  1. package/astro-jsx.d.ts +5 -1
  2. package/dist/@types/astro.d.ts +130 -6
  3. package/dist/assets/generate.d.ts +22 -0
  4. package/dist/assets/generate.js +90 -0
  5. package/dist/assets/internal.d.ts +0 -21
  6. package/dist/assets/internal.js +0 -86
  7. package/dist/assets/vite-plugin-assets.js +5 -0
  8. package/dist/content/consts.d.ts +3 -1
  9. package/dist/content/consts.js +5 -1
  10. package/dist/content/runtime-assets.d.ts +1 -1
  11. package/dist/content/runtime.d.ts +61 -7
  12. package/dist/content/runtime.js +127 -4
  13. package/dist/content/template/virtual-mod.d.mts +4 -1
  14. package/dist/content/types-generator.js +155 -80
  15. package/dist/content/utils.d.ts +76 -23
  16. package/dist/content/utils.js +129 -65
  17. package/dist/content/vite-plugin-content-imports.js +110 -25
  18. package/dist/content/vite-plugin-content-virtual-mod.d.ts +4 -3
  19. package/dist/content/vite-plugin-content-virtual-mod.js +89 -45
  20. package/dist/core/app/common.js +2 -0
  21. package/dist/core/app/index.js +6 -4
  22. package/dist/core/app/types.d.ts +6 -1
  23. package/dist/core/build/generate.js +8 -9
  24. package/dist/core/build/index.d.ts +1 -1
  25. package/dist/core/build/plugins/plugin-pages.d.ts +0 -2
  26. package/dist/core/build/plugins/plugin-pages.js +3 -4
  27. package/dist/core/build/plugins/plugin-prerender.d.ts +0 -2
  28. package/dist/core/build/plugins/plugin-prerender.js +2 -2
  29. package/dist/core/build/plugins/plugin-ssr.d.ts +1 -4
  30. package/dist/core/build/plugins/plugin-ssr.js +4 -3
  31. package/dist/core/build/static-build.js +9 -7
  32. package/dist/core/client-directive/build.d.ts +4 -0
  33. package/dist/core/client-directive/build.js +28 -0
  34. package/dist/core/client-directive/default.d.ts +1 -0
  35. package/dist/core/client-directive/default.js +17 -0
  36. package/dist/core/client-directive/index.d.ts +2 -0
  37. package/dist/core/client-directive/index.js +6 -0
  38. package/dist/core/compile/compile.js +1 -0
  39. package/dist/core/config/config.js +6 -0
  40. package/dist/core/config/schema.d.ts +68 -12
  41. package/dist/core/config/schema.js +29 -3
  42. package/dist/core/config/settings.js +74 -2
  43. package/dist/core/config/vite-load.js +2 -1
  44. package/dist/core/constants.js +1 -1
  45. package/dist/core/dev/dev.js +1 -1
  46. package/dist/core/endpoint/dev/index.js +1 -1
  47. package/dist/core/endpoint/index.d.ts +1 -1
  48. package/dist/core/endpoint/index.js +16 -16
  49. package/dist/core/errors/errors-data.d.ts +55 -4
  50. package/dist/core/errors/errors-data.js +67 -7
  51. package/dist/core/errors/errors.d.ts +1 -0
  52. package/dist/core/errors/errors.js +5 -1
  53. package/dist/core/errors/index.d.ts +1 -1
  54. package/dist/core/errors/index.js +9 -1
  55. package/dist/core/errors/utils.d.ts +5 -0
  56. package/dist/core/errors/utils.js +14 -0
  57. package/dist/core/messages.js +2 -2
  58. package/dist/core/middleware/callMiddleware.d.ts +2 -1
  59. package/dist/core/middleware/callMiddleware.js +13 -3
  60. package/dist/core/render/core.js +1 -0
  61. package/dist/core/render/dev/environment.js +3 -1
  62. package/dist/core/render/dev/index.js +1 -1
  63. package/dist/core/render/environment.d.ts +1 -0
  64. package/dist/core/render/environment.js +2 -0
  65. package/dist/core/render/result.d.ts +1 -0
  66. package/dist/core/render/result.js +3 -2
  67. package/dist/core/routing/manifest/create.js +9 -2
  68. package/dist/core/sync/index.js +11 -1
  69. package/dist/core/util.js +2 -1
  70. package/dist/integrations/index.js +29 -3
  71. package/dist/jsx/babel.js +1 -2
  72. package/dist/prerender/utils.d.ts +3 -0
  73. package/dist/prerender/utils.js +10 -0
  74. package/dist/runtime/client/idle.d.ts +3 -0
  75. package/dist/runtime/client/idle.js +6 -3
  76. package/dist/runtime/client/idle.prebuilt.d.ts +1 -1
  77. package/dist/runtime/client/idle.prebuilt.js +1 -1
  78. package/dist/runtime/client/load.d.ts +3 -0
  79. package/dist/runtime/client/load.js +7 -6
  80. package/dist/runtime/client/load.prebuilt.d.ts +1 -1
  81. package/dist/runtime/client/load.prebuilt.js +1 -1
  82. package/dist/runtime/client/media.d.ts +6 -0
  83. package/dist/runtime/client/media.js +6 -3
  84. package/dist/runtime/client/media.prebuilt.d.ts +1 -1
  85. package/dist/runtime/client/media.prebuilt.js +1 -1
  86. package/dist/runtime/client/only.d.ts +6 -0
  87. package/dist/runtime/client/only.js +7 -6
  88. package/dist/runtime/client/only.prebuilt.d.ts +1 -1
  89. package/dist/runtime/client/only.prebuilt.js +1 -1
  90. package/dist/runtime/client/visible.d.ts +8 -0
  91. package/dist/runtime/client/visible.js +9 -6
  92. package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
  93. package/dist/runtime/client/visible.prebuilt.js +1 -1
  94. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  95. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  96. package/dist/runtime/server/endpoint.js +1 -1
  97. package/dist/runtime/server/hydration.d.ts +1 -2
  98. package/dist/runtime/server/hydration.js +4 -9
  99. package/dist/runtime/server/render/astro/instance.js +1 -2
  100. package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
  101. package/dist/runtime/server/render/astro/render-template.js +10 -2
  102. package/dist/runtime/server/render/common.js +1 -1
  103. package/dist/runtime/server/render/component.js +20 -6
  104. package/dist/runtime/server/render/page.js +5 -0
  105. package/dist/runtime/server/render/util.d.ts +12 -0
  106. package/dist/runtime/server/render/util.js +89 -1
  107. package/dist/runtime/server/scripts.d.ts +1 -2
  108. package/dist/runtime/server/scripts.js +13 -21
  109. package/dist/vite-plugin-astro-server/request.js +2 -1
  110. package/dist/vite-plugin-astro-server/route.js +4 -3
  111. package/dist/vite-plugin-jsx/index.js +1 -1
  112. package/dist/vite-plugin-scanner/index.js +6 -1
  113. package/dist/vite-plugin-scanner/scan.d.ts +1 -1
  114. package/dist/vite-plugin-scanner/scan.js +2 -2
  115. package/package.json +5 -3
  116. package/src/content/template/types.d.ts +108 -15
  117. package/src/content/template/virtual-mod.mjs +40 -16
  118. package/types.d.ts +6 -3
@@ -9,6 +9,7 @@ import { preload, renderPage } from "../core/render/dev/index.js";
9
9
  import { getParamsAndProps, GetParamsAndPropsError } from "../core/render/index.js";
10
10
  import { createRequest } from "../core/request.js";
11
11
  import { matchAllRoutes } from "../core/routing/index.js";
12
+ import { isHybridOutput } from "../prerender/utils.js";
12
13
  import { log404 } from "./common.js";
13
14
  import { handle404Response, writeSSRResult, writeWebResponse } from "./response.js";
14
15
  function getCustom404Route(manifest) {
@@ -28,7 +29,7 @@ async function matchRoute(pathname, env, manifest) {
28
29
  routeCache,
29
30
  pathname,
30
31
  logging,
31
- ssr: settings.config.output === "server"
32
+ ssr: settings.config.output === "server" || isHybridOutput(settings.config)
32
33
  });
33
34
  if (paramsAndPropsRes !== GetParamsAndPropsError.NoMatchingStaticPath) {
34
35
  return {
@@ -80,7 +81,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, env, manif
80
81
  const { config } = settings;
81
82
  const filePath = matchedRoute.filePath;
82
83
  const { route, preloadedComponent, mod } = matchedRoute;
83
- const buildingToSSR = config.output === "server";
84
+ const buildingToSSR = config.output === "server" || isHybridOutput(config);
84
85
  const request = createRequest({
85
86
  url,
86
87
  headers: buildingToSSR ? req.headers : new Headers(),
@@ -100,7 +101,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, env, manif
100
101
  routeCache: env.routeCache,
101
102
  pathname,
102
103
  logging,
103
- ssr: config.output === "server"
104
+ ssr: config.output === "server" || isHybridOutput(config)
104
105
  });
105
106
  const options = {
106
107
  env,
@@ -159,7 +159,7 @@ function jsx({ settings, logging }) {
159
159
  Unable to resolve a renderer that handles this file! With more than one renderer enabled, you should include an import or use a pragma comment.
160
160
  Add ${colors.cyan(
161
161
  IMPORT_STATEMENTS[defaultRendererName] || `import '${defaultRendererName}';`
162
- )} or ${colors.cyan(`/* jsxImportSource: ${defaultRendererName} */`)} to this file.
162
+ )} or ${colors.cyan(`/** @jsxImportSource: ${defaultRendererName} */`)} to this file.
163
163
  `
164
164
  );
165
165
  return null;
@@ -1,5 +1,6 @@
1
1
  import { normalizePath } from "vite";
2
2
  import { isEndpoint, isPage } from "../core/util.js";
3
+ import { isHybridOutput } from "../prerender/utils.js";
3
4
  import { scan } from "./scan.js";
4
5
  function astroScannerPlugin({ settings }) {
5
6
  return {
@@ -19,7 +20,11 @@ function astroScannerPlugin({ settings }) {
19
20
  const fileIsEndpoint = isEndpoint(fileURL, settings);
20
21
  if (!(fileIsPage || fileIsEndpoint))
21
22
  return;
22
- const pageOptions = await scan(code, id);
23
+ const hybridOutput = isHybridOutput(settings.config);
24
+ const pageOptions = await scan(code, id, hybridOutput);
25
+ if (typeof pageOptions.prerender === "undefined") {
26
+ pageOptions.prerender = hybridOutput ? true : false;
27
+ }
23
28
  const { meta = {} } = this.getModuleInfo(id) ?? {};
24
29
  return {
25
30
  code,
@@ -1,2 +1,2 @@
1
1
  import type { PageOptions } from '../vite-plugin-astro/types.js';
2
- export declare function scan(code: string, id: string): Promise<PageOptions>;
2
+ export declare function scan(code: string, id: string, isHybridOutput?: boolean): Promise<PageOptions>;
@@ -24,7 +24,7 @@ function isFalsy(value) {
24
24
  return value === "false" || value === "0";
25
25
  }
26
26
  let didInit = false;
27
- async function scan(code, id) {
27
+ async function scan(code, id, isHybridOutput = false) {
28
28
  if (!includesExport(code))
29
29
  return {};
30
30
  if (!didInit) {
@@ -41,7 +41,7 @@ async function scan(code, id) {
41
41
  if (prefix !== "const" || !(isTruthy(suffix) || isFalsy(suffix))) {
42
42
  throw new AstroError({
43
43
  ...AstroErrorData.InvalidPrerenderExport,
44
- message: AstroErrorData.InvalidPrerenderExport.message(prefix, suffix),
44
+ message: AstroErrorData.InvalidPrerenderExport.message(prefix, suffix, isHybridOutput),
45
45
  location: { file: id }
46
46
  });
47
47
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.4.5",
3
+ "version": "2.5.0",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -55,7 +55,6 @@
55
55
  "./assets/image-endpoint": "./dist/assets/image-endpoint.js",
56
56
  "./assets/services/sharp": "./dist/assets/services/sharp.js",
57
57
  "./assets/services/squoosh": "./dist/assets/services/squoosh.js",
58
- "./content/internal": "./dist/content/internal.js",
59
58
  "./content/runtime": "./dist/content/runtime.js",
60
59
  "./content/runtime-assets": "./dist/content/runtime-assets.js",
61
60
  "./debug": "./components/Debug.astro",
@@ -102,7 +101,7 @@
102
101
  "dependencies": {
103
102
  "@astrojs/compiler": "^1.4.0",
104
103
  "@astrojs/language-server": "^1.0.0",
105
- "@astrojs/markdown-remark": "^2.2.0",
104
+ "@astrojs/markdown-remark": "^2.2.1",
106
105
  "@astrojs/telemetry": "^2.1.1",
107
106
  "@astrojs/webapi": "^2.1.1",
108
107
  "@babel/core": "^7.18.2",
@@ -124,12 +123,14 @@
124
123
  "devalue": "^4.2.0",
125
124
  "diff": "^5.1.0",
126
125
  "es-module-lexer": "^1.1.0",
126
+ "esbuild": "^0.17.18",
127
127
  "estree-walker": "3.0.0",
128
128
  "execa": "^6.1.0",
129
129
  "fast-glob": "^3.2.11",
130
130
  "github-slugger": "^2.0.0",
131
131
  "gray-matter": "^4.0.3",
132
132
  "html-escaper": "^3.0.3",
133
+ "js-yaml": "^4.1.0",
133
134
  "kleur": "^4.1.4",
134
135
  "magic-string": "^0.27.0",
135
136
  "mime": "^3.0.0",
@@ -167,6 +168,7 @@
167
168
  "@types/estree": "^0.0.51",
168
169
  "@types/hast": "^2.3.4",
169
170
  "@types/html-escaper": "^3.0.0",
171
+ "@types/js-yaml": "^4.0.5",
170
172
  "@types/mime": "^2.0.3",
171
173
  "@types/mocha": "^9.1.1",
172
174
  "@types/prettier": "^2.6.3",
@@ -10,8 +10,7 @@ declare module 'astro:content' {
10
10
 
11
11
  declare module 'astro:content' {
12
12
  export { z } from 'astro/zod';
13
- export type CollectionEntry<C extends keyof typeof entryMap> =
14
- (typeof entryMap)[C][keyof (typeof entryMap)[C]];
13
+ export type CollectionEntry<C extends keyof AnyEntryMap> = AnyEntryMap[C][keyof AnyEntryMap[C]];
15
14
 
16
15
  // TODO: Remove this when having this fallback is no longer relevant. 2.3? 3.0? - erika, 2023-04-04
17
16
  /**
@@ -65,44 +64,138 @@ declare module 'astro:content' {
65
64
 
66
65
  export type SchemaContext = { image: ImageFunction };
67
66
 
68
- type BaseCollectionConfig<S extends BaseSchema> = {
67
+ type DataCollectionConfig<S extends BaseSchema> = {
68
+ type: 'data';
69
69
  schema?: S | ((context: SchemaContext) => S);
70
70
  };
71
+
72
+ type ContentCollectionConfig<S extends BaseSchema> = {
73
+ type?: 'content';
74
+ schema?: S | ((context: SchemaContext) => S);
75
+ };
76
+
77
+ type CollectionConfig<S> = ContentCollectionConfig<S> | DataCollectionConfig<S>;
78
+
71
79
  export function defineCollection<S extends BaseSchema>(
72
- input: BaseCollectionConfig<S>
73
- ): BaseCollectionConfig<S>;
80
+ input: CollectionConfig<S>
81
+ ): CollectionConfig<S>;
74
82
 
75
- type EntryMapKeys = keyof typeof entryMap;
76
83
  type AllValuesOf<T> = T extends any ? T[keyof T] : never;
77
- type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<(typeof entryMap)[C]>['slug'];
84
+ type ValidContentEntrySlug<C extends keyof ContentEntryMap> = AllValuesOf<
85
+ ContentEntryMap[C]
86
+ >['slug'];
78
87
 
79
88
  export function getEntryBySlug<
80
- C extends keyof typeof entryMap,
81
- E extends ValidEntrySlug<C> | (string & {})
89
+ C extends keyof ContentEntryMap,
90
+ E extends ValidContentEntrySlug<C> | (string & {})
82
91
  >(
83
92
  collection: C,
84
93
  // Note that this has to accept a regular string too, for SSR
85
94
  entrySlug: E
86
- ): E extends ValidEntrySlug<C>
95
+ ): E extends ValidContentEntrySlug<C>
87
96
  ? Promise<CollectionEntry<C>>
88
97
  : Promise<CollectionEntry<C> | undefined>;
89
- export function getCollection<C extends keyof typeof entryMap, E extends CollectionEntry<C>>(
98
+
99
+ export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>(
100
+ collection: C,
101
+ entryId: E
102
+ ): Promise<CollectionEntry<C>>;
103
+
104
+ export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>(
90
105
  collection: C,
91
106
  filter?: (entry: CollectionEntry<C>) => entry is E
92
107
  ): Promise<E[]>;
93
- export function getCollection<C extends keyof typeof entryMap>(
108
+ export function getCollection<C extends keyof AnyEntryMap>(
94
109
  collection: C,
95
110
  filter?: (entry: CollectionEntry<C>) => unknown
96
111
  ): Promise<CollectionEntry<C>[]>;
97
112
 
113
+ export function getEntry<
114
+ C extends keyof ContentEntryMap,
115
+ E extends ValidContentEntrySlug<C> | (string & {})
116
+ >(entry: {
117
+ collection: C;
118
+ slug: E;
119
+ }): E extends ValidContentEntrySlug<C>
120
+ ? Promise<CollectionEntry<C>>
121
+ : Promise<CollectionEntry<C> | undefined>;
122
+ export function getEntry<
123
+ C extends keyof DataEntryMap,
124
+ E extends keyof DataEntryMap[C] | (string & {})
125
+ >(entry: {
126
+ collection: C;
127
+ id: E;
128
+ }): E extends keyof DataEntryMap[C]
129
+ ? Promise<DataEntryMap[C][E]>
130
+ : Promise<CollectionEntry<C> | undefined>;
131
+ export function getEntry<
132
+ C extends keyof ContentEntryMap,
133
+ E extends ValidContentEntrySlug<C> | (string & {})
134
+ >(
135
+ collection: C,
136
+ slug: E
137
+ ): E extends ValidContentEntrySlug<C>
138
+ ? Promise<CollectionEntry<C>>
139
+ : Promise<CollectionEntry<C> | undefined>;
140
+ export function getEntry<
141
+ C extends keyof DataEntryMap,
142
+ E extends keyof DataEntryMap[C] | (string & {})
143
+ >(
144
+ collection: C,
145
+ id: E
146
+ ): E extends keyof DataEntryMap[C]
147
+ ? Promise<DataEntryMap[C][E]>
148
+ : Promise<CollectionEntry<C> | undefined>;
149
+
150
+ /** Resolve an array of entry references from the same collection */
151
+ export function getEntries<C extends keyof ContentEntryMap>(
152
+ entries: {
153
+ collection: C;
154
+ slug: ValidContentEntrySlug<C>;
155
+ }[]
156
+ ): Promise<CollectionEntry<C>[]>;
157
+ export function getEntries<C extends keyof DataEntryMap>(
158
+ entries: {
159
+ collection: C;
160
+ id: keyof DataEntryMap[C];
161
+ }[]
162
+ ): Promise<CollectionEntry<C>[]>;
163
+
164
+ export function reference<C extends keyof AnyEntryMap>(
165
+ collection: C
166
+ ): import('astro/zod').ZodEffects<
167
+ import('astro/zod').ZodString,
168
+ C extends keyof ContentEntryMap
169
+ ? {
170
+ collection: C;
171
+ slug: ValidContentEntrySlug<C>;
172
+ }
173
+ : {
174
+ collection: C;
175
+ id: keyof DataEntryMap[C];
176
+ }
177
+ >;
178
+ // Allow generic `string` to avoid excessive type errors in the config
179
+ // if `dev` is not running to update as you edit.
180
+ // Invalid collection names will be caught at build time.
181
+ export function reference<C extends string>(
182
+ collection: C
183
+ ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>;
184
+
98
185
  type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T;
99
- type InferEntrySchema<C extends keyof typeof entryMap> = import('astro/zod').infer<
186
+ type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer<
100
187
  ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']>
101
188
  >;
102
189
 
103
- const entryMap: {
104
- // @@ENTRY_MAP@@
190
+ type ContentEntryMap = {
191
+ // @@CONTENT_ENTRY_MAP@@
105
192
  };
106
193
 
194
+ type DataEntryMap = {
195
+ // @@DATA_ENTRY_MAP@@
196
+ };
197
+
198
+ type AnyEntryMap = ContentEntryMap & DataEntryMap;
199
+
107
200
  type ContentConfig = '@@CONTENT_CONFIG_TYPE@@';
108
201
  }
@@ -2,29 +2,34 @@
2
2
  import {
3
3
  createCollectionToGlobResultMap,
4
4
  createGetCollection,
5
+ createGetDataEntryById,
6
+ createGetEntries,
7
+ createGetEntry,
5
8
  createGetEntryBySlug,
9
+ createReference,
6
10
  } from 'astro/content/runtime';
7
11
 
8
12
  export { z } from 'astro/zod';
9
13
 
10
- export function defineCollection(config) {
11
- return config;
12
- }
13
-
14
- // TODO: Remove this when having this fallback is no longer relevant. 2.3? 3.0? - erika, 2023-04-04
15
- export const image = () => {
16
- throw new Error(
17
- 'Importing `image()` from `astro:content` is no longer supported. See https://docs.astro.build/en/guides/assets/#update-content-collections-schemas for our new import instructions.'
18
- );
19
- };
20
-
21
14
  const contentDir = '@@CONTENT_DIR@@';
22
15
 
23
- const entryGlob = import.meta.glob('@@ENTRY_GLOB_PATH@@', {
24
- query: { astroContent: true },
16
+ const contentEntryGlob = import.meta.glob('@@CONTENT_ENTRY_GLOB_PATH@@', {
17
+ query: { astroContentCollectionEntry: true },
18
+ });
19
+ const contentCollectionToEntryMap = createCollectionToGlobResultMap({
20
+ globResult: contentEntryGlob,
21
+ contentDir,
22
+ });
23
+
24
+ const dataEntryGlob = import.meta.glob('@@DATA_ENTRY_GLOB_PATH@@', {
25
+ query: { astroDataCollectionEntry: true },
26
+ });
27
+ const dataCollectionToEntryMap = createCollectionToGlobResultMap({
28
+ globResult: dataEntryGlob,
29
+ contentDir,
25
30
  });
26
31
  const collectionToEntryMap = createCollectionToGlobResultMap({
27
- globResult: entryGlob,
32
+ globResult: { ...contentEntryGlob, ...dataEntryGlob },
28
33
  contentDir,
29
34
  });
30
35
 
@@ -33,7 +38,7 @@ let lookupMap = {};
33
38
 
34
39
  function createGlobLookup(glob) {
35
40
  return async (collection, lookupId) => {
36
- const filePath = lookupMap[collection]?.[lookupId];
41
+ const filePath = lookupMap[collection]?.entries[lookupId];
37
42
 
38
43
  if (!filePath) return undefined;
39
44
  return glob[collection][filePath];
@@ -48,12 +53,31 @@ const collectionToRenderEntryMap = createCollectionToGlobResultMap({
48
53
  contentDir,
49
54
  });
50
55
 
56
+ export function defineCollection(config) {
57
+ if (!config.type) config.type = 'content';
58
+ return config;
59
+ }
60
+
51
61
  export const getCollection = createGetCollection({
52
- collectionToEntryMap,
62
+ contentCollectionToEntryMap,
63
+ dataCollectionToEntryMap,
53
64
  getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
54
65
  });
55
66
 
56
67
  export const getEntryBySlug = createGetEntryBySlug({
68
+ getEntryImport: createGlobLookup(contentCollectionToEntryMap),
69
+ getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
70
+ });
71
+
72
+ export const getDataEntryById = createGetDataEntryById({
73
+ dataCollectionToEntryMap,
74
+ });
75
+
76
+ export const getEntry = createGetEntry({
57
77
  getEntryImport: createGlobLookup(collectionToEntryMap),
58
78
  getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
59
79
  });
80
+
81
+ export const getEntries = createGetEntries(getEntry);
82
+
83
+ export const reference = createReference({ lookupMap });
package/types.d.ts CHANGED
@@ -9,6 +9,9 @@ export type HTMLAttributes<Tag extends HTMLTag> = Omit<
9
9
  keyof Omit<AstroBuiltinAttributes, 'class:list'>
10
10
  >;
11
11
 
12
- // TODO: Enable generic/polymorphic types once compiler output stabilizes in the Language Server
13
- // type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<(P & HTMLAttributes<P['as']>), 'as'> & { as?: P['as'] };
14
- // export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<Omit<P, 'as'> & { as: NonNullable<P['as']>}>;
12
+ type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<P & HTMLAttributes<P['as']>, 'as'> & {
13
+ as?: P['as'];
14
+ };
15
+ export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<
16
+ Omit<P, 'as'> & { as: NonNullable<P['as']> }
17
+ >;