fuma-content 0.0.2 → 1.0.1

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 (75) hide show
  1. package/dist/bin.d.ts +1 -0
  2. package/dist/bin.js +18 -0
  3. package/dist/build-mdx-I4NROXCF.js +8 -0
  4. package/dist/bun/index.d.ts +16 -0
  5. package/dist/bun/index.js +37 -0
  6. package/dist/bun-DMNX4PBC.js +40 -0
  7. package/dist/chunk-3VQS3KSP.js +39 -0
  8. package/dist/chunk-BTRE6MOX.js +16 -0
  9. package/dist/chunk-E4HRKSP4.js +24 -0
  10. package/dist/chunk-ERBMAQYP.js +33 -0
  11. package/dist/chunk-GGL4EF6H.js +38 -0
  12. package/dist/chunk-JBZTQ55D.js +30 -0
  13. package/dist/chunk-KH5GT2Y5.js +104 -0
  14. package/dist/chunk-LUM7SIZN.js +40 -0
  15. package/dist/chunk-MT7RY65Y.js +167 -0
  16. package/dist/chunk-NRZ4GE5O.js +207 -0
  17. package/dist/chunk-OQQNA7L7.js +412 -0
  18. package/dist/chunk-OUJENWQ4.js +45 -0
  19. package/dist/chunk-RMSV4HP6.js +85 -0
  20. package/dist/chunk-RXR7OL76.js +37 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-W6HENTK7.js +44 -0
  23. package/dist/chunk-XR5N6ZXJ.js +50 -0
  24. package/dist/collections/handlers/fs.d.ts +10 -0
  25. package/dist/collections/handlers/fs.js +6 -0
  26. package/dist/collections/index.d.ts +10 -0
  27. package/dist/collections/index.js +6 -0
  28. package/dist/collections/mdx/loader-webpack.d.ts +17 -0
  29. package/dist/collections/mdx/loader-webpack.js +39 -0
  30. package/dist/collections/mdx/runtime-browser.d.ts +55 -0
  31. package/dist/collections/mdx/runtime-browser.js +82 -0
  32. package/dist/collections/mdx/runtime-dynamic.d.ts +43 -0
  33. package/dist/collections/mdx/runtime-dynamic.js +96 -0
  34. package/dist/collections/mdx/runtime.d.ts +70 -0
  35. package/dist/collections/mdx/runtime.js +45 -0
  36. package/dist/collections/mdx.d.ts +10 -0
  37. package/dist/collections/mdx.js +291 -0
  38. package/dist/collections/meta/loader-webpack.d.ts +17 -0
  39. package/dist/collections/meta/loader-webpack.js +42 -0
  40. package/dist/collections/meta/runtime.d.ts +19 -0
  41. package/dist/collections/meta/runtime.js +18 -0
  42. package/dist/collections/meta.d.ts +10 -0
  43. package/dist/collections/meta.js +170 -0
  44. package/dist/collections/runtime/file-store.d.ts +19 -0
  45. package/dist/collections/runtime/file-store.js +7 -0
  46. package/dist/collections/runtime/store.d.ts +28 -0
  47. package/dist/collections/runtime/store.js +6 -0
  48. package/dist/config/index.d.ts +10 -0
  49. package/dist/config/index.js +7 -0
  50. package/dist/core-Bo8KaWQz.d.ts +411 -0
  51. package/dist/index.d.ts +15 -31
  52. package/dist/index.js +6 -49
  53. package/dist/load-from-file-HL2VEY3M.js +7 -0
  54. package/dist/loader-NFSL6P5I.js +7 -0
  55. package/dist/loader-T756NSCS.js +7 -0
  56. package/dist/next/index.cjs +594 -0
  57. package/dist/next/index.d.ts +27 -0
  58. package/dist/next/index.js +100 -0
  59. package/dist/node/loader.d.ts +5 -0
  60. package/dist/node/loader.js +47 -0
  61. package/dist/node-DCMYL4DL.js +34 -0
  62. package/dist/plugins/git.d.ts +10 -0
  63. package/dist/plugins/git.js +70 -0
  64. package/dist/plugins/json-schema.d.ts +10 -0
  65. package/dist/plugins/json-schema.js +59 -0
  66. package/dist/plugins/with-loader/index.d.ts +61 -0
  67. package/dist/plugins/with-loader/index.js +6 -0
  68. package/dist/plugins/with-loader/webpack.d.ts +27 -0
  69. package/dist/plugins/with-loader/webpack.js +12 -0
  70. package/dist/vite/index.d.ts +33 -0
  71. package/dist/vite/index.js +61 -0
  72. package/dist/vite-QCUPZHHB.js +32 -0
  73. package/package.json +104 -36
  74. package/dist/internal.d.ts +0 -114
  75. package/dist/internal.js +0 -420
@@ -0,0 +1,45 @@
1
+ import {
2
+ FileCollectionStore
3
+ } from "../../chunk-RXR7OL76.js";
4
+ import "../../chunk-3VQS3KSP.js";
5
+
6
+ // src/collections/mdx/runtime.ts
7
+ function mdxStore(_name, base, _input) {
8
+ const input = _input;
9
+ const merged = input;
10
+ for (const [key, value] of Object.entries(input)) {
11
+ merged[key] = {
12
+ id: key,
13
+ compiled: value
14
+ };
15
+ }
16
+ return new FileCollectionStore(base, merged);
17
+ }
18
+ function mdxStoreLazy(_name, base, _input) {
19
+ const input = _input;
20
+ const merged = {};
21
+ for (const [key, value] of Object.entries(input.head)) {
22
+ merged[key] = {
23
+ id: key,
24
+ frontmatter: value,
25
+ load: input.body[key]
26
+ };
27
+ }
28
+ return new FileCollectionStore(base, merged);
29
+ }
30
+ function $attachCompiled() {
31
+ return (data) => data;
32
+ }
33
+ function $extractedReferences() {
34
+ return $attachCompiled();
35
+ }
36
+ function $versionControl() {
37
+ return $attachCompiled();
38
+ }
39
+ export {
40
+ $attachCompiled,
41
+ $extractedReferences,
42
+ $versionControl,
43
+ mdxStore,
44
+ mdxStoreLazy
45
+ };
@@ -0,0 +1,10 @@
1
+ export { E as ExtractedReference, M as MDXCollection, p as MDXCollectionConfig, o as MDXCollectionHandler, q as defineMDX } from '../core-Bo8KaWQz.js';
2
+ import '@mdx-js/mdx';
3
+ import 'vfile';
4
+ import '@standard-schema/spec';
5
+ import 'chokidar';
6
+ import 'unified';
7
+ import 'mdast';
8
+ import 'vite';
9
+ import 'next';
10
+ import 'node:module';
@@ -0,0 +1,291 @@
1
+ import {
2
+ withLoader
3
+ } from "../chunk-ERBMAQYP.js";
4
+ import {
5
+ buildFileHandler
6
+ } from "../chunk-E4HRKSP4.js";
7
+ import {
8
+ createCollection
9
+ } from "../chunk-BTRE6MOX.js";
10
+ import {
11
+ slash
12
+ } from "../chunk-MT7RY65Y.js";
13
+ import "../chunk-JBZTQ55D.js";
14
+
15
+ // src/collections/mdx.ts
16
+ import path from "path";
17
+ var mdxTypeInfo = {
18
+ id: "mdx",
19
+ plugins: [plugin()]
20
+ };
21
+ var RuntimePaths = {
22
+ browser: "fuma-content/collections/mdx/runtime-browser",
23
+ dynamic: "fuma-content/collections/mdx/runtime-dynamic",
24
+ server: "fuma-content/collections/mdx/runtime"
25
+ };
26
+ function defineMDX(config) {
27
+ const { lazy = false, dynamic = false } = config;
28
+ return createCollection(mdxTypeInfo, (collection, options) => {
29
+ collection.handlers.fs = buildFileHandler(options, config, ["mdx", "md"]);
30
+ collection.handlers.mdx = {
31
+ cwd: options.workspace ? path.resolve(options.workspace.dir) : process.cwd(),
32
+ postprocess: config.postprocess,
33
+ getMDXOptions: config.options,
34
+ dynamic,
35
+ lazy,
36
+ onGenerateStore(initializer) {
37
+ const mdxHandler = collection.handlers.mdx;
38
+ if (mdxHandler?.postprocess?.extractLinkReferences) {
39
+ this.codegen.addNamedImport(
40
+ ["$extractedReferences"],
41
+ RuntimePaths[this.environment]
42
+ );
43
+ initializer += ".$data($extractedReferences())";
44
+ }
45
+ return initializer;
46
+ }
47
+ };
48
+ collection.handlers["version-control"] = {
49
+ client({ client }) {
50
+ const mdxHandler = collection.handlers.mdx;
51
+ if (!mdxHandler) return;
52
+ const { onGenerateStore, vfile } = mdxHandler;
53
+ mdxHandler.onGenerateStore = function(initializer) {
54
+ this.codegen.addNamedImport(
55
+ ["$versionControl"],
56
+ RuntimePaths[this.environment]
57
+ );
58
+ initializer += ".$data($versionControl())";
59
+ return onGenerateStore?.call(this, initializer) ?? initializer;
60
+ };
61
+ mdxHandler.vfile = async function(file) {
62
+ const vcData = await client.getFileData({ filePath: file.path });
63
+ file.data["mdx-export"] ??= [];
64
+ file.data["mdx-export"].push(
65
+ {
66
+ name: "lastModified",
67
+ value: vcData.lastModified
68
+ },
69
+ {
70
+ name: "creationDate",
71
+ value: vcData.creationDate
72
+ }
73
+ );
74
+ if (vfile) return vfile?.call(this, file);
75
+ return file;
76
+ };
77
+ }
78
+ };
79
+ });
80
+ }
81
+ function plugin() {
82
+ const mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
83
+ function generateDocCollectionFrontmatterGlob(context, collection, eager = false) {
84
+ const handler = collection.handlers.fs;
85
+ if (!handler) return "";
86
+ return context.codegen.generateGlobImport(handler.patterns, {
87
+ query: {
88
+ collection: collection.name,
89
+ only: "frontmatter",
90
+ workspace: context.workspace
91
+ },
92
+ import: "frontmatter",
93
+ base: handler.dir,
94
+ eager
95
+ });
96
+ }
97
+ function generateDocCollectionGlob(context, collection, eager = false) {
98
+ const handler = collection.handlers.fs;
99
+ if (!handler) return "";
100
+ return context.codegen.generateGlobImport(handler.patterns, {
101
+ query: {
102
+ collection: collection.name,
103
+ workspace: context.workspace
104
+ },
105
+ base: handler.dir,
106
+ eager
107
+ });
108
+ }
109
+ async function generateCollectionStoreServer(context, collection) {
110
+ const mdxHandler = collection.handlers.mdx;
111
+ const fsHandler = collection.handlers.fs;
112
+ if (!fsHandler || !mdxHandler) return;
113
+ const { core, codegen } = context;
114
+ const runtimePath = RuntimePaths.server;
115
+ const base2 = slash(path.relative(process.cwd(), fsHandler.dir));
116
+ let initializer;
117
+ codegen.addNamespaceImport(
118
+ "Config",
119
+ codegen.formatImportPath(core.getOptions().configPath),
120
+ true
121
+ );
122
+ if (mdxHandler.lazy) {
123
+ codegen.addNamedImport(["mdxStoreLazy"], runtimePath);
124
+ const [headGlob, bodyGlob] = await Promise.all([
125
+ generateDocCollectionFrontmatterGlob(context, collection, true),
126
+ generateDocCollectionGlob(context, collection)
127
+ ]);
128
+ initializer = `mdxStoreLazy<typeof Config, "${collection.name}">("${collection.name}", "${base2}", { head: ${headGlob}, body: ${bodyGlob} })`;
129
+ } else {
130
+ codegen.addNamedImport(["mdxStore"], runtimePath);
131
+ initializer = `mdxStore<typeof Config, "${collection.name}">("${collection.name}", "${base2}", ${await generateDocCollectionGlob(context, collection, true)})`;
132
+ }
133
+ initializer = mdxHandler.onGenerateStore?.call(
134
+ { ...context, environment: "server" },
135
+ initializer
136
+ ) ?? initializer;
137
+ codegen.push(`export const ${collection.name} = ${initializer};`);
138
+ }
139
+ async function generateCollectionStoreBrowser(context, collection) {
140
+ const mdxHandler = collection.handlers.mdx;
141
+ const fsHandler = collection.handlers.fs;
142
+ if (!fsHandler || !mdxHandler) return;
143
+ const { core, codegen } = context;
144
+ const runtimePath = RuntimePaths.browser;
145
+ codegen.addNamedImport(["mdxStoreBrowser"], runtimePath);
146
+ codegen.addNamespaceImport(
147
+ "Config",
148
+ codegen.formatImportPath(core.getOptions().configPath),
149
+ true
150
+ );
151
+ let initializer = `mdxStoreBrowser<typeof Config, "${collection.name}">("${collection.name}", ${await generateDocCollectionGlob(context, collection)})`;
152
+ initializer = mdxHandler.onGenerateStore?.call(
153
+ { ...context, environment: "browser" },
154
+ initializer
155
+ ) ?? initializer;
156
+ codegen.push(`export const ${collection.name} = ${initializer};`);
157
+ }
158
+ async function generateCollectionStoreDynamic(context, collection) {
159
+ const mdxHandler = collection.handlers.mdx;
160
+ const fsHandler = collection.handlers.fs;
161
+ if (!fsHandler || !mdxHandler || !mdxHandler.dynamic) return;
162
+ const { core, codegen } = context;
163
+ const { configPath, workspace, outDir } = core.getOptions();
164
+ const runtimePath = RuntimePaths.dynamic;
165
+ const base2 = slash(path.relative(process.cwd(), fsHandler.dir));
166
+ codegen.addNamespaceImport(
167
+ "Config",
168
+ codegen.formatImportPath(core.getOptions().configPath)
169
+ );
170
+ codegen.addNamedImport(["mdxStoreDynamic"], runtimePath);
171
+ const coreOptions = {
172
+ configPath,
173
+ workspace,
174
+ outDir
175
+ };
176
+ let initializer = `mdxStoreDynamic<typeof Config, "${collection.name}">(Config, ${JSON.stringify(
177
+ coreOptions
178
+ )}, "${collection.name}", "${base2}", ${await generateDocCollectionFrontmatterGlob(context, collection, true)})`;
179
+ initializer = mdxHandler.onGenerateStore?.call(
180
+ { ...context, environment: "dynamic" },
181
+ initializer
182
+ ) ?? initializer;
183
+ codegen.push(`export const ${collection.name} = ${initializer};`);
184
+ }
185
+ const base = {
186
+ name: "mdx",
187
+ configureServer(server) {
188
+ if (!server.watcher) return;
189
+ server.watcher.on("all", async (event, file) => {
190
+ const updatedCollection = this.core.getCollections().find((collection) => {
191
+ const handlers = collection.handlers;
192
+ if (!handlers.mdx || !handlers.fs) return false;
193
+ if (event === "change" && !handlers.mdx.dynamic) return false;
194
+ return handlers.fs.hasFile(file);
195
+ });
196
+ if (!updatedCollection) return;
197
+ await this.core.emit({
198
+ filterPlugin: (plugin2) => plugin2.name === base.name,
199
+ filterWorkspace: () => false,
200
+ write: true
201
+ });
202
+ });
203
+ },
204
+ emit() {
205
+ return Promise.all([
206
+ this.createCodeGenerator("mdx.ts", async (ctx) => {
207
+ for (const collection of this.core.getCollections()) {
208
+ await generateCollectionStoreServer(ctx, collection);
209
+ }
210
+ }),
211
+ this.createCodeGenerator("mdx-browser.ts", async (ctx) => {
212
+ for (const collection of this.core.getCollections()) {
213
+ await generateCollectionStoreBrowser(ctx, collection);
214
+ }
215
+ ctx.codegen.push(
216
+ `export { useRenderer } from "${RuntimePaths.browser}";`
217
+ );
218
+ }),
219
+ this.createCodeGenerator("mdx-dynamic.ts", async (ctx) => {
220
+ for (const collection of this.core.getCollections()) {
221
+ await generateCollectionStoreDynamic(ctx, collection);
222
+ }
223
+ })
224
+ ]);
225
+ },
226
+ next: {
227
+ config(nextConfig) {
228
+ const { configPath, outDir } = this.core.getOptions();
229
+ const loaderPath = "fuma-content/collections/mdx/loader-webpack";
230
+ const loaderOptions = {
231
+ configPath,
232
+ outDir,
233
+ absoluteCompiledConfigPath: path.resolve(
234
+ this.core.getCompiledConfigPath()
235
+ ),
236
+ isDev: process.env.NODE_ENV === "development"
237
+ };
238
+ return {
239
+ ...nextConfig,
240
+ turbopack: {
241
+ ...nextConfig.turbopack,
242
+ rules: {
243
+ ...nextConfig.turbopack?.rules,
244
+ "*.{md,mdx}": {
245
+ loaders: [
246
+ {
247
+ loader: loaderPath,
248
+ options: loaderOptions
249
+ }
250
+ ],
251
+ as: "*.js"
252
+ }
253
+ }
254
+ },
255
+ pageExtensions: [
256
+ ...nextConfig.pageExtensions ?? ["js", "jsx", "tsx", "ts"],
257
+ "mdx",
258
+ "md"
259
+ ],
260
+ webpack(config, options) {
261
+ config.module ||= {};
262
+ config.module.rules ||= [];
263
+ config.module.rules.push({
264
+ test: mdxLoaderGlob,
265
+ use: [
266
+ options.defaultLoaders.babel,
267
+ {
268
+ loader: loaderPath,
269
+ options: loaderOptions
270
+ }
271
+ ]
272
+ });
273
+ return nextConfig.webpack?.(config, options) ?? config;
274
+ }
275
+ };
276
+ }
277
+ }
278
+ };
279
+ return withLoader(base, {
280
+ test: mdxLoaderGlob,
281
+ async createLoader() {
282
+ const { createMdxLoader } = await import("../loader-NFSL6P5I.js");
283
+ return createMdxLoader({
284
+ getCore: () => this.core
285
+ });
286
+ }
287
+ });
288
+ }
289
+ export {
290
+ defineMDX
291
+ };
@@ -0,0 +1,17 @@
1
+ import { LoaderContext } from 'webpack';
2
+ import { WebpackLoaderOptions } from '../../plugins/with-loader/webpack.js';
3
+ import '../../plugins/with-loader/index.js';
4
+ import '../../core-Bo8KaWQz.js';
5
+ import 'chokidar';
6
+ import '@mdx-js/mdx';
7
+ import 'vfile';
8
+ import '@standard-schema/spec';
9
+ import 'unified';
10
+ import 'mdast';
11
+ import 'vite';
12
+ import 'next';
13
+ import 'node:module';
14
+
15
+ declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string): Promise<void>;
16
+
17
+ export { loader as default };
@@ -0,0 +1,42 @@
1
+ import {
2
+ createMetaLoader
3
+ } from "../../chunk-RMSV4HP6.js";
4
+ import {
5
+ getCore,
6
+ toWebpack
7
+ } from "../../chunk-XR5N6ZXJ.js";
8
+ import "../../chunk-OUJENWQ4.js";
9
+ import {
10
+ createDynamicCore
11
+ } from "../../chunk-GGL4EF6H.js";
12
+ import "../../chunk-NRZ4GE5O.js";
13
+ import "../../chunk-MT7RY65Y.js";
14
+ import "../../chunk-JBZTQ55D.js";
15
+
16
+ // src/collections/meta/loader-webpack.ts
17
+ var instance;
18
+ async function loader(source) {
19
+ const callback = this.async();
20
+ const options = this.getOptions();
21
+ this.cacheable(true);
22
+ this.addDependency(options.absoluteCompiledConfigPath);
23
+ if (!instance) {
24
+ instance = toWebpack(
25
+ createMetaLoader(
26
+ createDynamicCore({
27
+ core: getCore(options),
28
+ buildConfig: false,
29
+ mode: options.isDev ? "dev" : "production"
30
+ }),
31
+ {
32
+ json: "json",
33
+ yaml: "js"
34
+ }
35
+ )
36
+ );
37
+ }
38
+ await instance.call(this, source, callback);
39
+ }
40
+ export {
41
+ loader as default
42
+ };
@@ -0,0 +1,19 @@
1
+ import { GetCollectionConfig } from '../../index.js';
2
+ import { FileCollectionStore } from '../runtime/file-store.js';
3
+ import { b as MetaCollection } from '../../core-Bo8KaWQz.js';
4
+ import '../runtime/store.js';
5
+ import 'chokidar';
6
+ import '@mdx-js/mdx';
7
+ import 'vfile';
8
+ import '@standard-schema/spec';
9
+ import 'unified';
10
+ import 'mdast';
11
+ import 'vite';
12
+ import 'next';
13
+ import 'node:module';
14
+
15
+ declare function metaStore<Config, Name extends string>(_name: Name, base: string, input: Record<string, unknown>): FileCollectionStore<{
16
+ data: GetCollectionConfig<Config, Name> extends MetaCollection<infer Data> ? Data : never;
17
+ }>;
18
+
19
+ export { metaStore };
@@ -0,0 +1,18 @@
1
+ import {
2
+ FileCollectionStore
3
+ } from "../../chunk-RXR7OL76.js";
4
+ import "../../chunk-3VQS3KSP.js";
5
+
6
+ // src/collections/meta/runtime.ts
7
+ function metaStore(_name, base, input) {
8
+ const merged = input;
9
+ for (const [key, value] of Object.entries(input)) {
10
+ merged[key] = {
11
+ data: value
12
+ };
13
+ }
14
+ return new FileCollectionStore(base, merged);
15
+ }
16
+ export {
17
+ metaStore
18
+ };
@@ -0,0 +1,10 @@
1
+ export { b as MetaCollection, t as MetaCollectionConfig, s as MetaCollectionHandler, r as MetaContext, u as defineMeta } from '../core-Bo8KaWQz.js';
2
+ import '@standard-schema/spec';
3
+ import 'chokidar';
4
+ import '@mdx-js/mdx';
5
+ import 'vfile';
6
+ import 'unified';
7
+ import 'mdast';
8
+ import 'vite';
9
+ import 'next';
10
+ import 'node:module';
@@ -0,0 +1,170 @@
1
+ import {
2
+ withLoader
3
+ } from "../chunk-ERBMAQYP.js";
4
+ import {
5
+ buildFileHandler
6
+ } from "../chunk-E4HRKSP4.js";
7
+ import {
8
+ createCollection
9
+ } from "../chunk-BTRE6MOX.js";
10
+
11
+ // src/collections/meta.ts
12
+ import path from "path";
13
+ var metaTypeInfo = {
14
+ id: "meta",
15
+ plugins: [plugin()]
16
+ };
17
+ function defineMeta(config) {
18
+ return createCollection(metaTypeInfo, (collection, options) => {
19
+ const handlers = collection.handlers;
20
+ handlers.fs = buildFileHandler(options, config, ["json", "yaml"]);
21
+ handlers.meta = {
22
+ schema: config.schema
23
+ };
24
+ handlers["json-schema"] = {
25
+ async create() {
26
+ const { z, ZodType } = await import("zod");
27
+ if (config.schema instanceof ZodType)
28
+ return z.toJSONSchema(config.schema, {
29
+ io: "input",
30
+ unrepresentable: "any"
31
+ });
32
+ else
33
+ return config.schema["~standard"]?.jsonSchema.input({
34
+ target: "draft-2020-12"
35
+ });
36
+ }
37
+ };
38
+ });
39
+ }
40
+ function plugin() {
41
+ const metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
42
+ async function generateCollectionStore(context, collection) {
43
+ const fsHandler = collection.handlers.fs;
44
+ if (!fsHandler) return;
45
+ const { codegen, core } = context;
46
+ codegen.addNamedImport(
47
+ ["metaStore"],
48
+ "fuma-content/collections/meta/runtime"
49
+ );
50
+ codegen.addNamespaceImport(
51
+ "Config",
52
+ codegen.formatImportPath(core.getOptions().configPath),
53
+ true
54
+ );
55
+ const base2 = path.relative(process.cwd(), fsHandler.dir);
56
+ const glob = await codegen.generateGlobImport(fsHandler.patterns, {
57
+ query: {
58
+ collection: collection.name,
59
+ workspace: context.workspace
60
+ },
61
+ import: "default",
62
+ base: fsHandler.dir,
63
+ eager: true
64
+ });
65
+ const initializer = `metaStore<typeof Config, "${collection.name}">("${collection.name}", "${base2}", ${glob})`;
66
+ codegen.push(`export const ${collection.name} = ${initializer};`);
67
+ }
68
+ const base = {
69
+ name: "meta",
70
+ configureServer(server) {
71
+ if (!server.watcher) return;
72
+ server.watcher.on("all", async (event, file) => {
73
+ if (event === "change") return;
74
+ const updatedCollection = this.core.getCollections().find((collection) => {
75
+ const handlers = collection.handlers;
76
+ if (!handlers.meta || !handlers.fs) return false;
77
+ return handlers.fs.hasFile(file);
78
+ });
79
+ if (!updatedCollection) return;
80
+ await this.core.emit({
81
+ filterPlugin: (plugin2) => plugin2.name === "meta",
82
+ filterWorkspace: () => false,
83
+ write: true
84
+ });
85
+ });
86
+ },
87
+ emit() {
88
+ return Promise.all([
89
+ this.createCodeGenerator("meta.ts", async (ctx) => {
90
+ for (const collection of this.core.getCollections()) {
91
+ await generateCollectionStore(ctx, collection);
92
+ }
93
+ })
94
+ ]);
95
+ },
96
+ next: {
97
+ config(nextConfig) {
98
+ const { configPath, outDir } = this.core.getOptions();
99
+ const loaderPath = "fuma-content/collections/meta/loader-webpack";
100
+ const loaderOptions = {
101
+ configPath,
102
+ outDir,
103
+ absoluteCompiledConfigPath: path.resolve(
104
+ this.core.getCompiledConfigPath()
105
+ ),
106
+ isDev: process.env.NODE_ENV === "development"
107
+ };
108
+ return {
109
+ ...nextConfig,
110
+ turbopack: {
111
+ ...nextConfig.turbopack,
112
+ rules: {
113
+ ...nextConfig.turbopack?.rules,
114
+ "*.json": {
115
+ loaders: [
116
+ {
117
+ loader: loaderPath,
118
+ options: loaderOptions
119
+ }
120
+ ],
121
+ as: "*.json"
122
+ },
123
+ "*.yaml": {
124
+ loaders: [
125
+ {
126
+ loader: loaderPath,
127
+ options: loaderOptions
128
+ }
129
+ ],
130
+ as: "*.js"
131
+ }
132
+ }
133
+ },
134
+ webpack(config, options) {
135
+ config.module ||= {};
136
+ config.module.rules ||= [];
137
+ config.module.rules.push({
138
+ test: metaLoaderGlob,
139
+ enforce: "pre",
140
+ use: [
141
+ {
142
+ loader: loaderPath,
143
+ options: loaderOptions
144
+ }
145
+ ]
146
+ });
147
+ return nextConfig.webpack?.(config, options) ?? config;
148
+ }
149
+ };
150
+ }
151
+ }
152
+ };
153
+ return withLoader(base, {
154
+ test: metaLoaderGlob,
155
+ async createLoader(environment) {
156
+ const { createMetaLoader } = await import("../loader-T756NSCS.js");
157
+ return createMetaLoader(
158
+ {
159
+ getCore: () => this.core
160
+ },
161
+ {
162
+ json: environment === "vite" ? "json" : "js"
163
+ }
164
+ );
165
+ }
166
+ });
167
+ }
168
+ export {
169
+ defineMeta
170
+ };
@@ -0,0 +1,19 @@
1
+ import { SimpleCollectionStore } from './store.js';
2
+
3
+ interface FileInfo {
4
+ /**
5
+ * path relative to content directory
6
+ */
7
+ path: string;
8
+ /**
9
+ * the full file path in file system
10
+ */
11
+ fullPath: string;
12
+ }
13
+ declare class FileCollectionStore<V> extends SimpleCollectionStore<FileInfo & V> {
14
+ constructor(base: string, glob: Record<string, V>);
15
+ transform<T>(fn: (input: FileInfo & V) => FileInfo & T): FileCollectionStore<T>;
16
+ $data<T>(_cast: (input: FileInfo & V) => FileInfo & T): FileCollectionStore<T>;
17
+ }
18
+
19
+ export { FileCollectionStore, type FileInfo };
@@ -0,0 +1,7 @@
1
+ import {
2
+ FileCollectionStore
3
+ } from "../../chunk-RXR7OL76.js";
4
+ import "../../chunk-3VQS3KSP.js";
5
+ export {
6
+ FileCollectionStore
7
+ };
@@ -0,0 +1,28 @@
1
+ type Awaitable<T> = T | PromiseLike<T>;
2
+ interface CollectionStore<Id, Data> {
3
+ /**
4
+ * type-only operation to change data type, doesn't do any runtime transformation.
5
+ */
6
+ $data: <T>(_cast: (input: Data) => T) => CollectionStore<Id, T>;
7
+ get: (id: Id) => Awaitable<Data | undefined>;
8
+ list: () => Awaitable<Data[]>;
9
+ /**
10
+ * For typescript to infer data types, can be anything
11
+ */
12
+ $inferData: Data;
13
+ }
14
+ declare class SimpleCollectionStore<Data> implements CollectionStore<string, Data> {
15
+ private readonly dataMap;
16
+ private readonly dataList;
17
+ constructor(input: Map<string, Data>);
18
+ get(id: string): Data | undefined;
19
+ list(): Data[];
20
+ $data<T>(_cast: (input: Data) => T): SimpleCollectionStore<T>;
21
+ /**
22
+ * in-place transformation on all data
23
+ */
24
+ transform<T>(fn: (input: Data) => T): SimpleCollectionStore<T>;
25
+ get $inferData(): Data;
26
+ }
27
+
28
+ export { type CollectionStore, SimpleCollectionStore };
@@ -0,0 +1,6 @@
1
+ import {
2
+ SimpleCollectionStore
3
+ } from "../../chunk-3VQS3KSP.js";
4
+ export {
5
+ SimpleCollectionStore
6
+ };