@adonisjs/content 1.3.0 → 1.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.
@@ -0,0 +1,66 @@
1
+ import { type SchemaTypes } from '@vinejs/vine/types';
2
+ import type { OssStatsOptions, LoaderContract } from '../types.ts';
3
+ /**
4
+ * A loader that aggregates open source statistics from multiple sources.
5
+ * Supports GitHub organization stars and npm package download counts.
6
+ * Provides caching and automatic refresh based on a schedule.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const loader = new OssStatsLoader({
11
+ * outputPath: './cache/oss-stats.json',
12
+ * refresh: 'daily',
13
+ * sources: [
14
+ * {
15
+ * type: 'github',
16
+ * org: 'adonisjs',
17
+ * ghToken: process.env.GITHUB_TOKEN
18
+ * },
19
+ * {
20
+ * type: 'npm',
21
+ * packages: [
22
+ * { name: '@adonisjs/core', startDate: '2020-01-01' }
23
+ * ]
24
+ * }
25
+ * ]
26
+ * })
27
+ * ```
28
+ */
29
+ export declare class OssStatsLoader<Schema extends SchemaTypes> implements LoaderContract<Schema> {
30
+ #private;
31
+ /**
32
+ * Creates a new OSS stats loader instance.
33
+ *
34
+ * @param options - Configuration options for loading OSS statistics
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const loader = new OssStatsLoader({
39
+ * outputPath: './cache/oss-stats.json',
40
+ * refresh: 'weekly',
41
+ * sources: [
42
+ * {
43
+ * type: 'github',
44
+ * org: 'adonisjs',
45
+ * ghToken: process.env.GITHUB_TOKEN
46
+ * }
47
+ * ]
48
+ * })
49
+ * ```
50
+ */
51
+ constructor(options: OssStatsOptions);
52
+ /**
53
+ * Loads and validates OSS statistics data.
54
+ * Uses cached data if available and not expired, otherwise fetches fresh data
55
+ * from configured sources and updates the cache.
56
+ *
57
+ * @param schema - VineJS schema to validate the statistics data against
58
+ * @param metadata - Optional metadata to pass to the validator
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const stats = await loader.load(ossStatsSchema)
63
+ * ```
64
+ */
65
+ load(schema: Schema, metadata?: any): Promise<import("@vinejs/vine/types").Infer<Schema>>;
66
+ }
@@ -251,6 +251,67 @@ export type GithubContributorsOptions = {
251
251
  /** How often to refresh the cached data */
252
252
  refresh: 'daily' | 'weekly' | 'monthly';
253
253
  };
254
+ /**
255
+ * Configuration options for loading and caching open source statistics from multiple sources.
256
+ * Supports aggregating data from GitHub organizations and npm package downloads.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * const options: OssStatsOptions = {
261
+ * outputPath: './cache/oss-stats.json',
262
+ * refresh: 'daily',
263
+ * sources: [
264
+ * {
265
+ * type: 'github',
266
+ * org: 'adonisjs',
267
+ * ghToken: process.env.GITHUB_TOKEN
268
+ * },
269
+ * {
270
+ * type: 'npm',
271
+ * packages: [
272
+ * { name: '@adonisjs/core', startDate: '2020-01-01' },
273
+ * { name: '@adonisjs/lucid', startDate: '2020-01-01' }
274
+ * ]
275
+ * }
276
+ * ]
277
+ * }
278
+ * ```
279
+ */
280
+ export type OssStatsOptions = {
281
+ /** Path where cached stats will be stored */
282
+ outputPath: string;
283
+ /** How often to refresh the cached data */
284
+ refresh: 'daily' | 'weekly' | 'monthly';
285
+ /** Array of data sources to aggregate statistics from */
286
+ sources: ({
287
+ /** Source type: GitHub organization statistics */
288
+ type: 'github';
289
+ /** GitHub organization name */
290
+ org: string;
291
+ /** GitHub personal access token for authentication */
292
+ ghToken: string;
293
+ } | {
294
+ /** Source type: npm package download statistics */
295
+ type: 'npm';
296
+ /** Array of npm packages with their tracking start dates */
297
+ packages: {
298
+ name: string;
299
+ startDate: string;
300
+ }[];
301
+ } | (() => Promise<{
302
+ key: string;
303
+ count: number;
304
+ }>))[];
305
+ };
306
+ /**
307
+ * Type representing the aggregated open source statistics
308
+ */
309
+ export type OssStats = {
310
+ /** Total GitHub stars across all sources */
311
+ stars: number;
312
+ /** Total npm package downloads across all sources */
313
+ installs: number;
314
+ } & Record<string, number>;
254
315
  /**
255
316
  * Represents a GitHub contributor with their profile information and contribution count.
256
317
  * This matches the shape returned by GitHub REST API /contributors endpoint.
@@ -68,3 +68,101 @@ export declare function fetchContributorsForOrg({ org, ghToken, }: GithubContrib
68
68
  * ```
69
69
  */
70
70
  export declare function mergeArrays<T, K extends keyof T>(existing: T[], fresh: T[], key: K): T[];
71
+ /**
72
+ * Aggregates total npm package downloads across multiple packages from their start dates to today.
73
+ * Fetches download statistics from the npm registry API for each package and sums them up.
74
+ *
75
+ * @param packages - Array of package objects containing name and start date for tracking downloads
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const total = await aggregateInstalls([
80
+ * { name: '@adonisjs/core', startDate: '2020-01-01' },
81
+ * { name: '@adonisjs/lucid', startDate: '2020-01-01' }
82
+ * ])
83
+ * console.log(`Total downloads: ${total}`)
84
+ * ```
85
+ */
86
+ export declare function aggregateInstalls(packages: {
87
+ name: string;
88
+ startDate: string;
89
+ }[]): Promise<number>;
90
+ /**
91
+ * Aggregates the total number of GitHub stars across all public, non-archived repositories
92
+ * in a GitHub organization. Uses pagination to fetch all repositories and sum their stars.
93
+ *
94
+ * @param options - Configuration object containing organization name and GitHub token
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const stars = await aggregateStars({
99
+ * org: 'adonisjs',
100
+ * ghToken: process.env.GITHUB_TOKEN
101
+ * })
102
+ * console.log(`Total stars: ${stars}`)
103
+ * ```
104
+ */
105
+ export declare function aggregateStars({ org, ghToken, }: {
106
+ org: string;
107
+ ghToken: string;
108
+ }): Promise<number>;
109
+ /**
110
+ * Creates a cache manager for storing and retrieving data with time-based expiration.
111
+ * The cache is persisted to disk as JSON and automatically expires based on the configured refresh interval.
112
+ *
113
+ * @param options - Configuration object for the cache
114
+ * @param options.key - The key name for storing the cached data in the JSON file
115
+ * @param options.outputPath - The file system path where the cache file will be stored
116
+ * @param options.contents - The initial contents (not used in the implementation, appears to be unused parameter)
117
+ * @param options.refresh - The refresh interval: 'daily', 'weekly', or 'monthly'
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const sponsorsCache = createCache({
122
+ * key: 'sponsors',
123
+ * outputPath: './cache/sponsors.json',
124
+ * contents: [],
125
+ * refresh: 'daily'
126
+ * })
127
+ *
128
+ * // Try to get cached data
129
+ * const cachedSponsors = await sponsorsCache.get()
130
+ * if (!cachedSponsors) {
131
+ * // Cache expired or doesn't exist, fetch fresh data
132
+ * const freshSponsors = await fetchAllSponsors({ ... })
133
+ * await sponsorsCache.put(freshSponsors)
134
+ * }
135
+ * ```
136
+ */
137
+ export declare function createCache<T>({ key, outputPath, refresh, }: {
138
+ key: string;
139
+ outputPath: string;
140
+ refresh: 'daily' | 'weekly' | 'monthly';
141
+ }): {
142
+ /**
143
+ * Retrieves cached data from disk if it exists and hasn't expired.
144
+ * Returns null if the cache doesn't exist, is expired, or the file is not found.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const data = await cache.get()
149
+ * if (data === null) {
150
+ * console.log('Cache expired or not found')
151
+ * }
152
+ * ```
153
+ */
154
+ get(): Promise<any>;
155
+ /**
156
+ * Saves data to the cache file with the current timestamp.
157
+ * Creates the directory structure if it doesn't exist.
158
+ *
159
+ * @param contents - The data to cache
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const freshData = await fetchDataFromAPI()
164
+ * await cache.put(freshData)
165
+ * ```
166
+ */
167
+ put(contents: T): Promise<T>;
168
+ };
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.3.0",
4
+ "version": "1.5.0",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -33,24 +33,24 @@
33
33
  "quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts"
34
34
  },
35
35
  "devDependencies": {
36
- "@adonisjs/assembler": "^8.0.0-next.19",
37
- "@adonisjs/core": "^7.0.0-next.10",
36
+ "@adonisjs/assembler": "^8.0.0-next.27",
37
+ "@adonisjs/core": "^7.0.0-next.16",
38
38
  "@adonisjs/eslint-config": "^3.0.0-next.4",
39
39
  "@adonisjs/prettier-config": "^1.4.5",
40
40
  "@adonisjs/tsconfig": "^2.0.0-next.3",
41
- "@adonisjs/vite": "^5.1.0-next.1",
42
- "@japa/assert": "^4.1.1",
43
- "@japa/expect-type": "^2.0.3",
44
- "@japa/file-system": "^2.3.2",
45
- "@japa/runner": "^4.4.0",
41
+ "@adonisjs/vite": "^5.1.0-next.2",
42
+ "@japa/assert": "^4.2.0",
43
+ "@japa/expect-type": "^2.0.4",
44
+ "@japa/file-system": "^3.0.0",
45
+ "@japa/runner": "^5.0.0",
46
46
  "@poppinss/ts-exec": "^1.4.1",
47
- "@release-it/conventional-changelog": "^10.0.1",
48
- "@types/node": "^24.10.1",
49
- "@vinejs/vine": "^4.1.0",
47
+ "@release-it/conventional-changelog": "^10.0.4",
48
+ "@types/node": "^25.0.3",
49
+ "@vinejs/vine": "^4.2.0",
50
50
  "c8": "^10.1.3",
51
- "eslint": "^9.39.1",
52
- "prettier": "^3.6.2",
53
- "release-it": "^19.0.6",
51
+ "eslint": "^9.39.2",
52
+ "prettier": "^3.7.4",
53
+ "release-it": "^19.2.2",
54
54
  "tsup": "^8.5.1",
55
55
  "typescript": "^5.9.3"
56
56
  },
@@ -60,8 +60,8 @@
60
60
  "dayjs": "^1.11.19"
61
61
  },
62
62
  "peerDependencies": {
63
- "@adonisjs/core": "^7.0.0-next.10",
64
63
  "@adonisjs/assembler": "^8.0.0-next.19",
64
+ "@adonisjs/core": "^7.0.0-next.10",
65
65
  "@adonisjs/vite": "^5.1.0-next.1",
66
66
  "@vinejs/vine": "^4.1.0"
67
67
  },