@gravito/monolith 1.0.0-alpha.6 → 1.0.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.
- package/CHANGELOG.md +9 -0
- package/README.md +1 -1
- package/README.zh-TW.md +1 -1
- package/dist/index.cjs +428 -0
- package/dist/index.d.cts +168 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.js +309 -5521
- package/ion/src/index.js +2 -2
- package/package.json +29 -15
- package/src/ContentManager.ts +76 -6
- package/src/Controller.ts +82 -0
- package/src/FormRequest.ts +86 -0
- package/src/Router.ts +35 -0
- package/src/Sanitizer.ts +32 -0
- package/src/index.ts +6 -2
- package/src/middleware/TrimStrings.ts +39 -0
- package/tests/ecommerce_integration.test.ts +58 -0
- package/tests/extra.test.ts +135 -0
- package/tests/mvc.test.ts +150 -0
- package/tsconfig.json +3 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as _gravito_core from '@gravito/core';
|
|
2
|
+
import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
3
|
+
import { TSchema } from '@gravito/mass';
|
|
4
|
+
export { Schema } from '@gravito/mass';
|
|
5
|
+
import { Hono } from 'hono';
|
|
6
|
+
|
|
7
|
+
interface ContentItem {
|
|
8
|
+
slug: string;
|
|
9
|
+
body: string;
|
|
10
|
+
excerpt?: string;
|
|
11
|
+
meta: Record<string, any>;
|
|
12
|
+
raw: string;
|
|
13
|
+
}
|
|
14
|
+
interface CollectionConfig {
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
declare class ContentManager {
|
|
18
|
+
private rootDir;
|
|
19
|
+
private collections;
|
|
20
|
+
private cache;
|
|
21
|
+
private renderer;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new ContentManager instance.
|
|
24
|
+
*
|
|
25
|
+
* @param rootDir - The root directory of the application.
|
|
26
|
+
*/
|
|
27
|
+
constructor(rootDir: string);
|
|
28
|
+
/**
|
|
29
|
+
* Register a new content collection.
|
|
30
|
+
*
|
|
31
|
+
* @param name - The name of the collection.
|
|
32
|
+
* @param config - The collection configuration.
|
|
33
|
+
*/
|
|
34
|
+
defineCollection(name: string, config: CollectionConfig): void;
|
|
35
|
+
/**
|
|
36
|
+
* Find a single content item.
|
|
37
|
+
*
|
|
38
|
+
* @param collectionName - The collection name (e.g. 'docs').
|
|
39
|
+
* @param slug - The file slug (e.g. 'installation').
|
|
40
|
+
* @param locale - The locale (e.g. 'en'). Defaults to 'en'.
|
|
41
|
+
* @returns A promise resolving to the ContentItem or null if not found.
|
|
42
|
+
* @throws {Error} If the collection is not defined.
|
|
43
|
+
*/
|
|
44
|
+
find(collectionName: string, slug: string, locale?: string): Promise<ContentItem | null>;
|
|
45
|
+
/**
|
|
46
|
+
* List all items in a collection for a locale.
|
|
47
|
+
* Useful for generating sitemaps or index pages.
|
|
48
|
+
*
|
|
49
|
+
* @param collectionName - The collection name.
|
|
50
|
+
* @param locale - The locale. Defaults to 'en'.
|
|
51
|
+
* @returns A promise resolving to an array of ContentItems.
|
|
52
|
+
* @throws {Error} If the collection is not defined.
|
|
53
|
+
*/
|
|
54
|
+
list(collectionName: string, locale?: string): Promise<ContentItem[]>;
|
|
55
|
+
private sanitizeSegment;
|
|
56
|
+
private escapeHtml;
|
|
57
|
+
private isSafeUrl;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Utility to clean up request data.
|
|
62
|
+
*/
|
|
63
|
+
declare class Sanitizer {
|
|
64
|
+
/**
|
|
65
|
+
* Recursively trim strings and convert empty strings to null.
|
|
66
|
+
*/
|
|
67
|
+
static clean(data: any): any;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare abstract class BaseController {
|
|
71
|
+
protected sanitizer: Sanitizer;
|
|
72
|
+
call(ctx: GravitoContext, method: string): Promise<Response>;
|
|
73
|
+
}
|
|
74
|
+
declare abstract class Controller {
|
|
75
|
+
protected context: GravitoContext;
|
|
76
|
+
/**
|
|
77
|
+
* Set the request context for this controller instance.
|
|
78
|
+
*/
|
|
79
|
+
setContext(context: GravitoContext): this;
|
|
80
|
+
/**
|
|
81
|
+
* Return a JSON response.
|
|
82
|
+
*/
|
|
83
|
+
protected json(data: any, status?: number): Response;
|
|
84
|
+
/**
|
|
85
|
+
* Return a text response.
|
|
86
|
+
*/
|
|
87
|
+
protected text(text: string, status?: number): Response;
|
|
88
|
+
/**
|
|
89
|
+
* Redirect to a given URL.
|
|
90
|
+
*/
|
|
91
|
+
protected redirect(url: string, status?: number): Response;
|
|
92
|
+
/**
|
|
93
|
+
* Get an item from the context variables.
|
|
94
|
+
*/
|
|
95
|
+
protected get(key: string): any;
|
|
96
|
+
/**
|
|
97
|
+
* Get the request object.
|
|
98
|
+
*/
|
|
99
|
+
protected get request(): _gravito_core.GravitoRequest;
|
|
100
|
+
/**
|
|
101
|
+
* Validate the request against a schema.
|
|
102
|
+
*/
|
|
103
|
+
protected validate(_schema: any, source?: 'json' | 'query' | 'form'): Promise<any>;
|
|
104
|
+
/**
|
|
105
|
+
* Resolve a controller action into a handler compatible with GravitoContext.
|
|
106
|
+
*/
|
|
107
|
+
static call(method: string): any;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare abstract class FormRequest {
|
|
111
|
+
protected context: GravitoContext;
|
|
112
|
+
/**
|
|
113
|
+
* Define the validation schema.
|
|
114
|
+
*/
|
|
115
|
+
abstract schema(): TSchema;
|
|
116
|
+
/**
|
|
117
|
+
* Define the source of data (json, query, form, etc.).
|
|
118
|
+
*/
|
|
119
|
+
source(): 'json' | 'query' | 'form';
|
|
120
|
+
/**
|
|
121
|
+
* Determine if the user is authorized to make this request.
|
|
122
|
+
*/
|
|
123
|
+
authorize(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Set the context.
|
|
126
|
+
*/
|
|
127
|
+
setContext(context: GravitoContext): this;
|
|
128
|
+
/**
|
|
129
|
+
* Get the validated data.
|
|
130
|
+
*/
|
|
131
|
+
validated(): any;
|
|
132
|
+
/**
|
|
133
|
+
* Static helper to create a middleware from this request class.
|
|
134
|
+
*/
|
|
135
|
+
static middleware(): any;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare class RouterHelper {
|
|
139
|
+
/**
|
|
140
|
+
* Register standard resource routes for a controller.
|
|
141
|
+
*
|
|
142
|
+
* GET /prefix -> index
|
|
143
|
+
* GET /prefix/create -> create
|
|
144
|
+
* POST /prefix -> store
|
|
145
|
+
* GET /prefix/:id -> show
|
|
146
|
+
* GET /prefix/:id/edit -> edit
|
|
147
|
+
* PUT /prefix/:id -> update
|
|
148
|
+
* DELETE /prefix/:id -> destroy
|
|
149
|
+
*/
|
|
150
|
+
static resource(app: Hono<any, any, any>, prefix: string, controller: any): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare module '@gravito/core' {
|
|
154
|
+
interface Variables {
|
|
155
|
+
content: ContentManager;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
interface ContentConfig {
|
|
159
|
+
root?: string;
|
|
160
|
+
collections?: Record<string, CollectionConfig>;
|
|
161
|
+
}
|
|
162
|
+
declare class OrbitMonolith implements GravitoOrbit {
|
|
163
|
+
private config;
|
|
164
|
+
constructor(config?: ContentConfig);
|
|
165
|
+
install(core: PlanetCore): void;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { BaseController, type CollectionConfig, type ContentConfig, type ContentItem, ContentManager, Controller, FormRequest, OrbitMonolith, RouterHelper as Route };
|