@adonisjs/content 1.1.1 → 1.3.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.
@@ -47,6 +47,45 @@ var Collection = class _Collection {
47
47
  static create(options) {
48
48
  return new _Collection(options);
49
49
  }
50
+ /**
51
+ * Creates multiple collection instances by mapping over sections.
52
+ * Useful for generating collections for different categories or sections.
53
+ *
54
+ * @param sections - Array of section identifiers
55
+ * @param callback - Function to create a collection for each section
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const collections = Collection.multi(
60
+ * ['api', 'guides', 'tutorials'],
61
+ * (section) => new Collection({
62
+ * schema: docsSchema,
63
+ * loader: loaders.jsonLoader(`./docs/${section}.json`),
64
+ * cache: true
65
+ * })
66
+ * )
67
+ * // Results in: { api: Collection, guides: Collection, tutorials: Collection }
68
+ * ```
69
+ */
70
+ static multi(sections, callback) {
71
+ return sections.reduce(
72
+ (result, section) => {
73
+ ;
74
+ result[section] = callback(section);
75
+ return result;
76
+ },
77
+ {
78
+ async load() {
79
+ const views = {};
80
+ for (let section of sections) {
81
+ ;
82
+ views[section] = await this[section].load();
83
+ }
84
+ return views;
85
+ }
86
+ }
87
+ );
88
+ }
50
89
  /**
51
90
  * Configures the Vite service instance for resolving asset paths.
52
91
  * This should be called once during application initialization.
package/build/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Collection
3
- } from "./chunk-ZX3KSI7U.js";
3
+ } from "./chunk-Q6QIMTOW.js";
4
4
  import "./chunk-LB6JFRVG.js";
5
5
 
6
6
  // configure.ts
@@ -1,6 +1,7 @@
1
1
  import { type ApplicationService } from '@adonisjs/core/types';
2
2
  declare module '@vinejs/vine' {
3
3
  interface VineString {
4
+ toContents(): this;
4
5
  /**
5
6
  * Converts a relative path to a Vite asset path.
6
7
  * This method transforms the path using Vite's asset resolution system.
@@ -1,14 +1,31 @@
1
1
  import {
2
2
  Collection
3
- } from "../chunk-ZX3KSI7U.js";
3
+ } from "../chunk-Q6QIMTOW.js";
4
4
  import "../chunk-LB6JFRVG.js";
5
5
 
6
6
  // providers/content_provider.ts
7
7
  import { resolve } from "path";
8
8
  import vine, { VineString } from "@vinejs/vine";
9
+ import { readFile } from "fs/promises";
9
10
  var toVitePath = vine.createRule(function vitePath(value, _, field) {
10
- field.mutate(field.meta.vite.assetPath(value), field);
11
+ if (typeof value === "string") {
12
+ field.mutate(
13
+ field.meta.vite.assetPath(value.replace(/^\.\/|^\//, "").replace(/\/$/, "")),
14
+ field
15
+ );
16
+ }
11
17
  });
18
+ var toContents = vine.createRule(
19
+ async function vitePath2(value, _, field) {
20
+ if (typeof value === "string") {
21
+ const absolutePath2 = resolve(field.meta.menuFileRoot, value);
22
+ field.mutate(await readFile(absolutePath2, "utf-8"), field);
23
+ }
24
+ },
25
+ {
26
+ isAsync: true
27
+ }
28
+ );
12
29
  var toAbsolutePath = vine.createRule(function absolutePath(value, _, field) {
13
30
  field.mutate(resolve(field.meta.menuFileRoot, value), field);
14
31
  });
@@ -18,6 +35,9 @@ VineString.macro("toVitePath", function() {
18
35
  VineString.macro("toAbsolutePath", function() {
19
36
  return this.use(toAbsolutePath());
20
37
  });
38
+ VineString.macro("toContents", function() {
39
+ return this.use(toContents());
40
+ });
21
41
  var ContentProvider = class {
22
42
  /**
23
43
  * Creates a new instance of the content provider.
@@ -1,6 +1,7 @@
1
1
  import { type Vite } from '@adonisjs/vite';
2
2
  import { type Infer, type SchemaTypes } from '@vinejs/vine/types';
3
3
  import { type CollectionOptions, type ViewFn, type ViewsToQueryMethods } from './types.js';
4
+ import { type Prettify } from '@adonisjs/core/types/common';
4
5
  /**
5
6
  * Manages a collection of data with schema validation and custom view functions.
6
7
  *
@@ -61,6 +62,35 @@ export declare class Collection<Schema extends SchemaTypes, Views extends Record
61
62
  * ```
62
63
  */
63
64
  static create<Schema extends SchemaTypes, Views extends Record<string, ViewFn<Schema, any, any>>>(options: CollectionOptions<Schema, Views>): Collection<Schema, Views>;
65
+ /**
66
+ * Creates multiple collection instances by mapping over sections.
67
+ * Useful for generating collections for different categories or sections.
68
+ *
69
+ * @param sections - Array of section identifiers
70
+ * @param callback - Function to create a collection for each section
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const collections = Collection.multi(
75
+ * ['api', 'guides', 'tutorials'],
76
+ * (section) => new Collection({
77
+ * schema: docsSchema,
78
+ * loader: loaders.jsonLoader(`./docs/${section}.json`),
79
+ * cache: true
80
+ * })
81
+ * )
82
+ * // Results in: { api: Collection, guides: Collection, tutorials: Collection }
83
+ * ```
84
+ */
85
+ static multi<Section extends string, Callback extends (section: Section) => Collection<any, any>>(sections: Section[], callback: Callback): {
86
+ [K in Section]: ReturnType<Callback>;
87
+ } & {
88
+ load(): Promise<{
89
+ [K in Section]: ReturnType<Callback> extends Collection<infer S, infer V> ? Prettify<{
90
+ all(): Infer<S>;
91
+ } & ViewsToQueryMethods<V>> : never;
92
+ }>;
93
+ };
64
94
  /**
65
95
  * Configures the Vite service instance for resolving asset paths.
66
96
  * This should be called once during application initialization.
@@ -106,7 +136,7 @@ export declare class Collection<Schema extends SchemaTypes, Views extends Record
106
136
  * const post = query.findBySlug('hello-world')
107
137
  * ```
108
138
  */
109
- load(): Promise<{
139
+ load(): Promise<Prettify<{
110
140
  all(): Infer<Schema>;
111
- } & ViewsToQueryMethods<Views>>;
141
+ } & ViewsToQueryMethods<Views>>>;
112
142
  }
@@ -1,4 +1,4 @@
1
- import { type Infer, type SchemaTypes } from '@vinejs/vine/types';
1
+ import { type SchemaTypes } from '@vinejs/vine/types';
2
2
  import type { GithubContributorsOptions, LoaderContract } from '../types.ts';
3
3
  /**
4
4
  * A loader that fetches GitHub contributors from all repositories in an organization.
@@ -45,5 +45,5 @@ export declare class GithubContributorsLoader<Schema extends SchemaTypes> implem
45
45
  * const contributors = await loader.load(contributorsSchema)
46
46
  * ```
47
47
  */
48
- load(schema: Schema, metadata?: any): Promise<Infer<Schema>>;
48
+ load(schema: Schema, metadata?: any): Promise<import("@vinejs/vine/types").Infer<Schema>>;
49
49
  }
@@ -1,4 +1,4 @@
1
- import { type Infer, type SchemaTypes } from '@vinejs/vine/types';
1
+ import { type SchemaTypes } from '@vinejs/vine/types';
2
2
  import type { GithubReleasesOptions, LoaderContract } from '../types.ts';
3
3
  /**
4
4
  * A loader that fetches GitHub releases from an organization's repositories.
@@ -48,5 +48,5 @@ export declare class GithubReleasesLoader<Schema extends SchemaTypes> implements
48
48
  * const releases = await loader.load(releasesSchema)
49
49
  * ```
50
50
  */
51
- load(schema: Schema, metadata?: any): Promise<Infer<Schema>>;
51
+ load(schema: Schema, metadata?: any): Promise<import("@vinejs/vine/types").Infer<Schema>>;
52
52
  }
@@ -1,4 +1,4 @@
1
- import { type Infer, type SchemaTypes } from '@vinejs/vine/types';
1
+ import { type SchemaTypes } from '@vinejs/vine/types';
2
2
  import type { GithubSponsorsOptions, LoaderContract } from '../types.ts';
3
3
  /**
4
4
  * A loader that fetches GitHub sponsors for a user or organization.
@@ -21,11 +21,6 @@ export declare class GithubSponsorsLoader<Schema extends SchemaTypes> implements
21
21
  * Creates a new GitHub sponsors loader instance.
22
22
  *
23
23
  * @param options - Configuration options for loading GitHub sponsors
24
- * @param options.login - GitHub username or organization name
25
- * @param options.isOrg - Whether the login is an organization (true) or user (false)
26
- * @param options.ghToken - GitHub personal access token for authentication
27
- * @param options.outputPath - Path where cached sponsors will be stored
28
- * @param options.refresh - Refresh schedule: 'daily', 'weekly', or 'monthly'
29
24
  *
30
25
  * @example
31
26
  * ```ts
@@ -52,5 +47,5 @@ export declare class GithubSponsorsLoader<Schema extends SchemaTypes> implements
52
47
  * const sponsors = await loader.load(sponsorsSchema)
53
48
  * ```
54
49
  */
55
- load(schema: Schema, metadata?: any): Promise<Infer<Schema>>;
50
+ load(schema: Schema, metadata?: any): Promise<import("@vinejs/vine/types").Infer<Schema>>;
56
51
  }
@@ -228,11 +228,6 @@ var GithubSponsorsLoader = class {
228
228
  * Creates a new GitHub sponsors loader instance.
229
229
  *
230
230
  * @param options - Configuration options for loading GitHub sponsors
231
- * @param options.login - GitHub username or organization name
232
- * @param options.isOrg - Whether the login is an organization (true) or user (false)
233
- * @param options.ghToken - GitHub personal access token for authentication
234
- * @param options.outputPath - Path where cached sponsors will be stored
235
- * @param options.refresh - Refresh schedule: 'daily', 'weekly', or 'monthly'
236
231
  *
237
232
  * @example
238
233
  * ```ts
@@ -4,9 +4,6 @@ import { type GithubSponsor, type GithubReleasesOptions, type GithubReleaseWithR
4
4
  * Handles pagination automatically to retrieve all sponsors across multiple requests.
5
5
  *
6
6
  * @param options - Configuration options for fetching sponsors
7
- * @param options.login - GitHub username or organization name
8
- * @param options.isOrg - Whether the login is an organization (true) or user (false)
9
- * @param options.ghToken - GitHub personal access token for authentication
10
7
  *
11
8
  * @example
12
9
  * ```ts
@@ -23,11 +20,6 @@ export declare function fetchAllSponsors({ login, isOrg, ghToken, }: GithubSpons
23
20
  * Handles pagination and supports filtering releases by name patterns.
24
21
  *
25
22
  * @param options - Configuration options for fetching releases
26
- * @param options.org - GitHub organization name
27
- * @param options.ghToken - GitHub personal access token for authentication
28
- * @param options.filters - Optional filters to include/exclude releases by name patterns
29
- * @param options.filters.nameIncludes - Array of substrings that release names must contain
30
- * @param options.filters.nameDoesntInclude - Array of substrings that release names must not contain
31
23
  *
32
24
  * @example
33
25
  * ```ts
@@ -48,16 +40,12 @@ export declare function fetchReleases({ org, ghToken, filters, }: GithubReleases
48
40
  * Handles errors gracefully by logging warnings for failed repositories.
49
41
  *
50
42
  * @param options - Configuration options for fetching contributors
51
- * @param options.org - GitHub organization name
52
- * @param options.ghToken - GitHub personal access token for authentication
53
43
  *
54
44
  * @example
55
45
  * ```ts
56
46
  * const contributors = await fetchContributorsForOrg({
57
47
  * org: 'adonisjs',
58
- * ghToken: process.env.GITHUB_TOKEN,
59
- * outputPath: './cache/contributors.json',
60
- * refresh: 'weekly'
48
+ * ghToken: process.env.GITHUB_TOKEN
61
49
  * })
62
50
  * ```
63
51
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/content",
3
3
  "description": "Content management for AdonisJS with schema validation, GitHub loaders, and custom queries",
4
- "version": "1.1.1",
4
+ "version": "1.3.0",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -14,7 +14,7 @@
14
14
  "main": "build/index.js",
15
15
  "exports": {
16
16
  "./loaders": "./build/src/loaders/main.js",
17
- "./types": "./build/types.js",
17
+ "./types": "./build/src/types.js",
18
18
  "./content_provider": "./build/providers/content_provider.js",
19
19
  ".": "./build/index.js"
20
20
  },