@orieljs/framework 0.1.0-alpha.1 → 0.1.0-alpha.3
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/dist/{chunk-K6MAA3RM.js → chunk-3ZRPBRAE.js} +3 -1
- package/dist/chunk-3ZRPBRAE.js.map +1 -0
- package/dist/{chunk-AI2RFMBT.js → chunk-HU43NADT.js} +2 -2
- package/dist/chunk-I2OMKIQZ.js +4693 -0
- package/dist/chunk-I2OMKIQZ.js.map +1 -0
- package/dist/chunk-IRHK7GH7.js +745 -0
- package/dist/chunk-IRHK7GH7.js.map +1 -0
- package/dist/chunk-S7YC43IH.js +93 -0
- package/dist/chunk-S7YC43IH.js.map +1 -0
- package/dist/{chunk-WI7E7Q46.js → chunk-TIE5OAMF.js} +3 -3
- package/dist/{chunk-BZPCRKFQ.js → chunk-UPZAML2Q.js} +729 -17
- package/dist/chunk-UPZAML2Q.js.map +1 -0
- package/dist/chunk-WEGTH46M.js +478 -0
- package/dist/chunk-WEGTH46M.js.map +1 -0
- package/dist/contracts.d.ts +111 -21
- package/dist/contracts.js +3 -1
- package/dist/index.d-DOlTeG-8.d.ts +99 -0
- package/dist/index.d.ts +1979 -1090
- package/dist/index.js +1482 -64
- package/dist/index.js.map +1 -1
- package/dist/{jsx-runtime-B8J6xq-7.d.ts → jsx-runtime-CZ6JqBQo.d.ts} +6 -11
- package/dist/jsx-runtime-WKTl3EEw.d.ts +254 -0
- package/dist/jsx-runtime.d.ts +3 -1
- package/dist/jsx-runtime.js +3 -3
- package/dist/testing--F6FODc_.d.ts +2068 -0
- package/dist/testing.d.ts +3 -1408
- package/dist/testing.js +13 -3
- package/package.json +31 -28
- package/dist/chunk-BZPCRKFQ.js.map +0 -1
- package/dist/chunk-K6MAA3RM.js.map +0 -1
- /package/dist/{chunk-AI2RFMBT.js.map → chunk-HU43NADT.js.map} +0 -0
- /package/dist/{chunk-WI7E7Q46.js.map → chunk-TIE5OAMF.js.map} +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { Token as Token$1 } from './contracts.js';
|
|
2
|
+
|
|
1
3
|
/** A typed, runtime-unique key for container bindings. */
|
|
2
|
-
interface Token
|
|
4
|
+
interface Token<T> {
|
|
3
5
|
readonly id: symbol;
|
|
4
6
|
readonly description: string;
|
|
5
7
|
/** Phantom field: only carries T at the type level. Never set at runtime. */
|
|
6
8
|
readonly __type?: T;
|
|
7
9
|
}
|
|
8
10
|
type Class<T> = abstract new (...args: any[]) => T;
|
|
9
|
-
type Abstract<T> = Token
|
|
11
|
+
type Abstract<T> = Token<T> | Class<T>;
|
|
10
12
|
type Factory$1<T> = (container: Container) => T;
|
|
11
13
|
type Concrete<T> = Factory$1<T> | (new () => T);
|
|
12
14
|
interface Container {
|
|
@@ -32,7 +34,7 @@ interface Container {
|
|
|
32
34
|
/** Run fn with this container as the "current" one for inject(), helpers and facades (AsyncLocalStorage). */
|
|
33
35
|
run<R>(fn: () => R): R;
|
|
34
36
|
}
|
|
35
|
-
declare const Container: Token
|
|
37
|
+
declare const Container: Token<Container>;
|
|
36
38
|
|
|
37
39
|
interface ServiceProvider$1 {
|
|
38
40
|
/** Bind things into the container. Synchronous. Don't resolve other services here. */
|
|
@@ -94,13 +96,6 @@ interface ClassRegistry {
|
|
|
94
96
|
}
|
|
95
97
|
declare const ClassRegistry: Token$1<ClassRegistry>;
|
|
96
98
|
|
|
97
|
-
/** A typed, runtime-unique key for container bindings. */
|
|
98
|
-
interface Token<T> {
|
|
99
|
-
readonly id: symbol;
|
|
100
|
-
readonly description: string;
|
|
101
|
-
/** Phantom field: only carries T at the type level. Never set at runtime. */
|
|
102
|
-
readonly __type?: T;
|
|
103
|
-
}
|
|
104
99
|
interface Htmlable {
|
|
105
100
|
toHtml(): string;
|
|
106
101
|
}
|
|
@@ -117,7 +112,7 @@ interface ViewFactory {
|
|
|
117
112
|
share(key: string | Record<string, unknown>, value?: unknown): void;
|
|
118
113
|
composer(views: string | string[], composer: (view: View$1) => void | Promise<void>): void;
|
|
119
114
|
}
|
|
120
|
-
declare const ViewFactory: Token<ViewFactory>;
|
|
115
|
+
declare const ViewFactory: Token$1<ViewFactory>;
|
|
121
116
|
|
|
122
117
|
type ErrorKind = 'Http' | 'Server' | 'ModelNotFound' | 'Validation' | 'Authentication' | 'Authorization' | 'TokenMismatch' | 'BindingResolution' | 'CircularDependency' | 'ContainerNotAvailable';
|
|
123
118
|
/** Every error thrown by the framework implements this. The exception handler switches on `kind`. */
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { Token } from './contracts.js';
|
|
2
|
+
import { S as ServiceProvider$1, A as Application } from './index.d-DOlTeG-8.js';
|
|
3
|
+
|
|
4
|
+
interface Htmlable {
|
|
5
|
+
toHtml(): string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface View$1 extends Htmlable {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
with(key: string | Record<string, unknown>, value?: unknown): this;
|
|
11
|
+
render(): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
/** Resolves 'posts.index' → resources/views/posts/index.tsx and renders it to HTML on the server. */
|
|
14
|
+
interface ViewFactory {
|
|
15
|
+
make(name: string, data?: Record<string, unknown>): View$1;
|
|
16
|
+
exists(name: string): boolean;
|
|
17
|
+
share(key: string | Record<string, unknown>, value?: unknown): void;
|
|
18
|
+
composer(views: string | string[], composer: (view: View$1) => void | Promise<void>): void;
|
|
19
|
+
/** Renders TSX (an element, a string, an Htmlable, a View, promises of them) to HTML, like Blade::render(). */
|
|
20
|
+
renderToString(node: unknown): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
declare const ViewFactory: Token<ViewFactory>;
|
|
23
|
+
|
|
24
|
+
type ErrorKind = 'Http' | 'Server' | 'ModelNotFound' | 'Validation' | 'Authentication' | 'Authorization' | 'TokenMismatch' | 'BindingResolution' | 'CircularDependency' | 'ContainerNotAvailable';
|
|
25
|
+
/** Every error thrown by the framework implements this. The exception handler switches on `kind`. */
|
|
26
|
+
interface OrielError extends Error {
|
|
27
|
+
readonly kind: ErrorKind;
|
|
28
|
+
/** HTTP status the error should render as, when relevant. */
|
|
29
|
+
readonly status?: number;
|
|
30
|
+
readonly headers?: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare abstract class ServiceProvider implements ServiceProvider$1 {
|
|
34
|
+
protected readonly app: Application;
|
|
35
|
+
constructor(app: Application);
|
|
36
|
+
register(): void;
|
|
37
|
+
boot(): void | Promise<void>;
|
|
38
|
+
/** Package defaults under `key`; values the app already set win (shallow merge, like Laravel). */
|
|
39
|
+
protected mergeConfigFrom(defaults: Record<string, unknown>, key: string): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface FacadeStatics<T> {
|
|
43
|
+
getFacadeRoot(): T;
|
|
44
|
+
/** Replace the instance in the current container (used by X.fake()). */
|
|
45
|
+
swap(instance: T): void;
|
|
46
|
+
}
|
|
47
|
+
type Facade<T, X = object> = T & X & FacadeStatics<T>;
|
|
48
|
+
|
|
49
|
+
/** Marks the objects jsx() returns (Symbol.for, so two copies of the package agree). */
|
|
50
|
+
declare const ELEMENT: unique symbol;
|
|
51
|
+
type Props = Record<string, unknown>;
|
|
52
|
+
/** Anything that can appear as a child: text is escaped, Htmlable is emitted as-is, promises are awaited. */
|
|
53
|
+
type Renderable = OrielElement | string | number | bigint | boolean | null | undefined | Htmlable | Promise<Renderable> | Iterable<Renderable>;
|
|
54
|
+
/** A function component. It may be async: the renderer awaits it. */
|
|
55
|
+
type Component<P = Props> = (props: P) => Renderable | Promise<Renderable>;
|
|
56
|
+
/**
|
|
57
|
+
* `<>…</>` and `<Fragment>`: renders its children only. A symbol at runtime; typed as a component so that
|
|
58
|
+
* `<Fragment>` type-checks as a JSX tag.
|
|
59
|
+
*/
|
|
60
|
+
declare const Fragment: (props: {
|
|
61
|
+
children?: Renderable;
|
|
62
|
+
}) => Renderable;
|
|
63
|
+
type ElementType = string | Component<never>;
|
|
64
|
+
/** What `<div />` evaluates to: an inert description, rendered later by renderToString()/renderToStream(). */
|
|
65
|
+
interface OrielElement {
|
|
66
|
+
readonly [ELEMENT]: true;
|
|
67
|
+
readonly type: ElementType;
|
|
68
|
+
readonly props: Props;
|
|
69
|
+
readonly key: string | number | undefined;
|
|
70
|
+
}
|
|
71
|
+
declare function createElement(type: ElementType, props: Props | null | undefined, key?: string | number): OrielElement;
|
|
72
|
+
declare function isElement(value: unknown): value is OrielElement;
|
|
73
|
+
|
|
74
|
+
/** Markup that must not be escaped again (Laravel's Illuminate\Support\HtmlString). */
|
|
75
|
+
declare class HtmlString implements Htmlable {
|
|
76
|
+
private readonly html;
|
|
77
|
+
constructor(html?: string);
|
|
78
|
+
toHtml(): string;
|
|
79
|
+
toString(): string;
|
|
80
|
+
isEmpty(): boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Marks trusted markup so the renderer emits it unescaped: {raw(markdownHtml)}. Never pass user input. */
|
|
83
|
+
declare function raw(html: string): HtmlString;
|
|
84
|
+
declare function isHtmlable(value: unknown): value is Htmlable;
|
|
85
|
+
/** Laravel's e(): htmlspecialchars(ENT_QUOTES, double-encode). Htmlable values pass through; null is ''. */
|
|
86
|
+
declare function e(value: unknown): string;
|
|
87
|
+
|
|
88
|
+
type ClassValue = string | number | null | undefined | false | ClassValue[] | Record<string, unknown>;
|
|
89
|
+
type StyleObject = Record<string, string | number | null | undefined | false>;
|
|
90
|
+
/** `class` accepts strings, arrays and `{ name: condition }` objects, like Blade's @class. */
|
|
91
|
+
declare function classNames(value: ClassValue): string;
|
|
92
|
+
/** `{ marginTop: 4, '--gap': '1rem' }` → `margin-top:4px;--gap:1rem`. */
|
|
93
|
+
declare function styleString(style: StyleObject): string;
|
|
94
|
+
|
|
95
|
+
/** Renders JSX (or any Renderable) to an HTML string. Async components and promises are awaited in order. */
|
|
96
|
+
declare function renderToString(node: Renderable): Promise<string>;
|
|
97
|
+
/** Renders to a UTF-8 byte stream, sending everything rendered so far each time rendering waits on a promise. */
|
|
98
|
+
declare function renderToStream(node: Renderable): ReadableStream<Uint8Array>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The automatic JSX runtime (`jsxImportSource: "@orieljs/view"`). jsx() only describes elements; rendering
|
|
102
|
+
* (escaping, async components) happens in renderToString()/renderToStream().
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
declare function jsx(type: ElementType, props: Props | null, key?: string | number): OrielElement;
|
|
106
|
+
/** Same as jsx(); the compiler uses it when there are several static children. */
|
|
107
|
+
declare const jsxs: typeof jsx;
|
|
108
|
+
/** Attributes every intrinsic element accepts. Unknown attributes (hx-*, x-*, o:click, …) are allowed. */
|
|
109
|
+
interface HtmlAttributes {
|
|
110
|
+
children?: Renderable;
|
|
111
|
+
class?: ClassValue;
|
|
112
|
+
className?: ClassValue;
|
|
113
|
+
style?: string | StyleObject;
|
|
114
|
+
dangerouslySetInnerHTML?: {
|
|
115
|
+
__html: string;
|
|
116
|
+
};
|
|
117
|
+
[attribute: string]: unknown;
|
|
118
|
+
}
|
|
119
|
+
declare namespace JSX {
|
|
120
|
+
type Element = OrielElement;
|
|
121
|
+
/** Lets components be async: `async function Posts() { … }` is a valid element type. */
|
|
122
|
+
type ElementType = string | Component<never>;
|
|
123
|
+
interface ElementChildrenAttribute {
|
|
124
|
+
children: unknown;
|
|
125
|
+
}
|
|
126
|
+
interface IntrinsicAttributes {
|
|
127
|
+
key?: string | number;
|
|
128
|
+
}
|
|
129
|
+
interface IntrinsicElements {
|
|
130
|
+
[element: string]: HtmlAttributes;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Programmer errors (Laravel throws InvalidArgumentException for these). Not an HTTP condition, so kind 'Server':
|
|
136
|
+
* the exception handler reports them and renders a 500 whose message is hidden unless app.debug is on.
|
|
137
|
+
*/
|
|
138
|
+
declare class ViewRenderError extends Error implements OrielError {
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly kind: ErrorKind;
|
|
141
|
+
readonly status = 500;
|
|
142
|
+
}
|
|
143
|
+
/** Laravel's "View [x] not found." (InvalidArgumentException). */
|
|
144
|
+
declare class ViewNotFoundError extends Error implements OrielError {
|
|
145
|
+
readonly view: string;
|
|
146
|
+
readonly searched: string[];
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly kind: ErrorKind;
|
|
149
|
+
readonly status = 500;
|
|
150
|
+
constructor(view: string, searched?: string[]);
|
|
151
|
+
}
|
|
152
|
+
/** A view file that doesn't default-export a component. */
|
|
153
|
+
declare class InvalidViewError extends Error implements OrielError {
|
|
154
|
+
readonly name: string;
|
|
155
|
+
readonly kind: ErrorKind;
|
|
156
|
+
readonly status = 500;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Laravel's FileViewFinder: 'posts.index' → <location>/posts/index.<ext> for the first location and extension
|
|
161
|
+
* that exist. Found paths are cached; misses are not, so a view created later is found.
|
|
162
|
+
*/
|
|
163
|
+
declare class FileViewFinder {
|
|
164
|
+
private readonly extensions;
|
|
165
|
+
static readonly defaultExtensions: string[];
|
|
166
|
+
private readonly locations;
|
|
167
|
+
private readonly hints;
|
|
168
|
+
private readonly views;
|
|
169
|
+
constructor(paths: string[], extensions?: string[]);
|
|
170
|
+
/** The absolute path of the view file. Throws ViewNotFoundError. */
|
|
171
|
+
find(name: string): string;
|
|
172
|
+
addLocation(path: string): void;
|
|
173
|
+
prependLocation(path: string): void;
|
|
174
|
+
/** Views under a namespace: addNamespace('mail', dir) makes 'mail::message' resolve to <dir>/message.tsx. */
|
|
175
|
+
addNamespace(namespace: string, hints: string | string[]): void;
|
|
176
|
+
replaceNamespace(namespace: string, hints: string | string[]): void;
|
|
177
|
+
getPaths(): string[];
|
|
178
|
+
getHints(): Record<string, string[]>;
|
|
179
|
+
/** Forget cached lookups. */
|
|
180
|
+
flush(): void;
|
|
181
|
+
/** [locations to search, relative file stem]. Dots become directories, so '..' can't climb out of a location. */
|
|
182
|
+
private parse;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** What TsxView needs from its factory. */
|
|
186
|
+
interface ViewEnvironment {
|
|
187
|
+
getShared(): Record<string, unknown>;
|
|
188
|
+
callComposer(view: View$1): Promise<void>;
|
|
189
|
+
load(path: string, name: string): Promise<Component>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* One view: its name, file and data. render() runs the composers, imports the file and renders its default
|
|
193
|
+
* export with { ...shared, ...data } as props. toHtml() returns the HTML of the last render().
|
|
194
|
+
*/
|
|
195
|
+
declare class TsxView implements View$1 {
|
|
196
|
+
private readonly environment;
|
|
197
|
+
readonly name: string;
|
|
198
|
+
readonly path: string;
|
|
199
|
+
private data;
|
|
200
|
+
private html;
|
|
201
|
+
constructor(environment: ViewEnvironment, name: string, path: string, data?: Record<string, unknown>);
|
|
202
|
+
with(key: string | Record<string, unknown>, value?: unknown): this;
|
|
203
|
+
/** The view's own data (Laravel's getData()). */
|
|
204
|
+
getData(): Record<string, unknown>;
|
|
205
|
+
/** Shared data overlaid with the view's data: exactly the props the component receives. */
|
|
206
|
+
gatherData(): Record<string, unknown>;
|
|
207
|
+
render(): Promise<string>;
|
|
208
|
+
toHtml(): string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type Composer = (view: View$1) => void | Promise<void>;
|
|
212
|
+
/** Laravel's view Factory: finds views by dotted name, shares data app-wide and runs view composers. */
|
|
213
|
+
declare class Factory implements ViewFactory, ViewEnvironment {
|
|
214
|
+
private readonly finder;
|
|
215
|
+
private readonly shared;
|
|
216
|
+
private readonly composers;
|
|
217
|
+
constructor(finder: FileViewFinder);
|
|
218
|
+
/** Throws ViewNotFoundError ("View [x] not found.") when no file matches. */
|
|
219
|
+
make(name: string, data?: Record<string, unknown>): TsxView;
|
|
220
|
+
/** The first view that exists (Laravel's View::first()). */
|
|
221
|
+
first(names: string[], data?: Record<string, unknown>): TsxView;
|
|
222
|
+
exists(name: string): boolean;
|
|
223
|
+
/** App-wide data every view receives as props (view data wins on conflicts). */
|
|
224
|
+
share(key: string | Record<string, unknown>, value?: unknown): void;
|
|
225
|
+
getShared(): Record<string, unknown>;
|
|
226
|
+
/** Runs before matching views render. Patterns use `*` wildcards: 'posts.*', '*'. */
|
|
227
|
+
composer(views: string | string[], composer: Composer): void;
|
|
228
|
+
callComposer(view: View$1): Promise<void>;
|
|
229
|
+
/** Renders TSX, a string, an Htmlable or a View (or promises of them) to HTML, like Laravel's Blade::render(). */
|
|
230
|
+
renderToString(node: unknown): Promise<string>;
|
|
231
|
+
/** Imports the view file (Node's module cache keeps it) and returns its default-export component. */
|
|
232
|
+
load(path: string, name: string): Promise<Component>;
|
|
233
|
+
addLocation(path: string): void;
|
|
234
|
+
addNamespace(namespace: string, hints: string | string[]): this;
|
|
235
|
+
getFinder(): FileViewFinder;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** view() → the ViewFactory; view('posts.index', data) → a View to return from a route or render. */
|
|
239
|
+
declare function view(): ViewFactory;
|
|
240
|
+
declare function view(name: string, data?: Record<string, unknown>): View$1;
|
|
241
|
+
/** Blade's @csrf / csrf_field(): the hidden _token input for the current request's session. */
|
|
242
|
+
declare function csrfField(): HtmlString;
|
|
243
|
+
/** Blade's @method('PUT') / method_field(): spoofs PUT/PATCH/DELETE from an HTML form. */
|
|
244
|
+
declare function methodField(method: string): HtmlString;
|
|
245
|
+
|
|
246
|
+
/** The View facade: View.make(), View.exists(), View.share(), View.composer(), View.first(), View.addNamespace(). */
|
|
247
|
+
declare const View: Facade<Factory, object>;
|
|
248
|
+
|
|
249
|
+
/** Binds the ViewFactory (resources/views by default) and merges the `view` config, like Laravel's config/view.php. */
|
|
250
|
+
declare class ViewServiceProvider extends ServiceProvider {
|
|
251
|
+
register(): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { type ClassValue as C, ELEMENT as E, FileViewFinder as F, type HtmlAttributes as H, InvalidViewError as I, JSX as J, type OrielElement as O, type Props as P, type Renderable as R, type StyleObject as S, TsxView as T, View as V, Fragment as a, HtmlString as b, type Component as c, type ViewEnvironment as d, Factory as e, ViewNotFoundError as f, ViewRenderError as g, ViewServiceProvider as h, classNames as i, createElement as j, csrfField as k, e as l, isElement as m, isHtmlable as n, methodField as o, renderToStream as p, renderToString as q, raw as r, styleString as s, jsx as t, jsxs as u, view as v };
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a as Fragment, H as HtmlAttributes, J as JSX, t as jsx, u as jsxs } from './jsx-runtime-WKTl3EEw.js';
|
|
2
|
+
import './contracts.js';
|
|
3
|
+
import './index.d-DOlTeG-8.js';
|
package/dist/jsx-runtime.js
CHANGED