@orieljs/framework 0.1.0-alpha.0 → 0.1.0-alpha.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.
@@ -0,0 +1,350 @@
1
+ /** A typed, runtime-unique key for container bindings. */
2
+ interface Token$1<T> {
3
+ readonly id: symbol;
4
+ readonly description: string;
5
+ /** Phantom field: only carries T at the type level. Never set at runtime. */
6
+ readonly __type?: T;
7
+ }
8
+ type Class<T> = abstract new (...args: any[]) => T;
9
+ type Abstract<T> = Token$1<T> | Class<T>;
10
+ type Factory$1<T> = (container: Container) => T;
11
+ type Concrete<T> = Factory$1<T> | (new () => T);
12
+ interface Container {
13
+ /** New instance on every make(). A class with no concrete binds to itself (constructed with no args). Root only; throws on a scope. */
14
+ bind<T>(abstract: Abstract<T>, concrete?: Concrete<T>): void;
15
+ /** One instance for the life of this container and its scopes. Root only; throws on a scope. */
16
+ singleton<T>(abstract: Abstract<T>, concrete?: Concrete<T>): void;
17
+ /** One instance per scope (e.g. per HTTP request or queue job). Root only; throws on a scope. */
18
+ scoped<T>(abstract: Abstract<T>, concrete?: Concrete<T>): void;
19
+ /** Register an existing object as a shared instance. Returns it. On a scope it stays local to that scope. */
20
+ instance<T>(abstract: Abstract<T>, instance: T): T;
21
+ /** Resolve. Unbound classes are constructed with `new Class()`. Unbound tokens throw BindingResolutionError. */
22
+ make<T>(abstract: Abstract<T>): T;
23
+ bound(abstract: Abstract<unknown>): boolean;
24
+ resolved(abstract: Abstract<unknown>): boolean;
25
+ /** Decorate or replace an instance each time it's resolved (applied before resolving callbacks). Root only; throws on a scope. */
26
+ extend<T>(abstract: Abstract<T>, extender: (instance: T, container: Container) => T): void;
27
+ /** Called after each resolution of the abstract. Root only; throws on a scope. */
28
+ resolving<T>(abstract: Abstract<T>, callback: (instance: T, container: Container) => void): void;
29
+ forgetInstance(abstract: Abstract<unknown>): void;
30
+ /** A child container: shares bindings and singletons with its parent, and has its own scoped instances. Bindings can't be registered on it. */
31
+ createScope(): Container;
32
+ /** Run fn with this container as the "current" one for inject(), helpers and facades (AsyncLocalStorage). */
33
+ run<R>(fn: () => R): R;
34
+ }
35
+ declare const Container: Token$1<Container>;
36
+
37
+ interface ServiceProvider$1 {
38
+ /** Bind things into the container. Synchronous. Don't resolve other services here. */
39
+ register?(): void;
40
+ /** Runs after every provider is registered. May be async (e.g. importing route files). */
41
+ boot?(): void | Promise<void>;
42
+ }
43
+ type ServiceProviderClass = new (app: Application) => ServiceProvider$1;
44
+ interface Application extends Container {
45
+ readonly version: string;
46
+ basePath(path?: string): string;
47
+ appPath(path?: string): string;
48
+ bootstrapPath(path?: string): string;
49
+ configPath(path?: string): string;
50
+ databasePath(path?: string): string;
51
+ publicPath(path?: string): string;
52
+ resourcePath(path?: string): string;
53
+ storagePath(path?: string): string;
54
+ /** With no args returns the environment name. With args returns whether it matches any of them. */
55
+ environment(): string;
56
+ environment(...environments: string[]): boolean;
57
+ isProduction(): boolean;
58
+ isLocal(): boolean;
59
+ runningInConsole(): boolean;
60
+ /** Mark the app as running in the console (the CLI entry point calls this). Defaults to true. */
61
+ setRunningInConsole(value?: boolean): void;
62
+ runningUnitTests(): boolean;
63
+ /** Registers the provider. If the app is already booted, the provider is booted immediately. */
64
+ register(provider: ServiceProvider$1 | ServiceProviderClass): Promise<ServiceProvider$1>;
65
+ getProviders(): ServiceProvider$1[];
66
+ boot(): Promise<void>;
67
+ isBooted(): boolean;
68
+ booting(callback: (app: Application) => void | Promise<void>): void;
69
+ booted(callback: (app: Application) => void | Promise<void>): void;
70
+ /** Handle one HTTP request in a fresh request scope via the bound HttpKernel. */
71
+ handle(request: Request): Promise<Response>;
72
+ /** Register a callback that terminate() runs, in registration order. */
73
+ terminating(callback: () => void | Promise<void>): void;
74
+ terminate(): Promise<void>;
75
+ }
76
+ declare const Application: Token$1<Application>;
77
+
78
+ interface ConfigRepository {
79
+ has(key: string): boolean;
80
+ /** Dot notation: get('database.connections.sqlite.database'). */
81
+ get<T = unknown>(key: string, defaultValue?: T): T;
82
+ set(key: string, value: unknown): void;
83
+ set(values: Record<string, unknown>): void;
84
+ push(key: string, value: unknown): void;
85
+ all(): Record<string, unknown>;
86
+ }
87
+ declare const ConfigRepository: Token$1<ConfigRepository>;
88
+ interface ClassRegistry {
89
+ /** Registers under `name` (default: cls.name). Throws if the name is already taken by a different class. */
90
+ register(cls: Class<unknown>, name?: string): string;
91
+ nameOf(cls: Class<unknown>): string | undefined;
92
+ resolve<T = unknown>(name: string): Class<T>;
93
+ has(name: string): boolean;
94
+ }
95
+ declare const ClassRegistry: Token$1<ClassRegistry>;
96
+
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
+ interface Htmlable {
105
+ toHtml(): string;
106
+ }
107
+
108
+ interface View$1 extends Htmlable {
109
+ readonly name: string;
110
+ with(key: string | Record<string, unknown>, value?: unknown): this;
111
+ render(): Promise<string>;
112
+ }
113
+ /** Resolves 'posts.index' → resources/views/posts/index.tsx and renders it to HTML on the server. */
114
+ interface ViewFactory {
115
+ make(name: string, data?: Record<string, unknown>): View$1;
116
+ exists(name: string): boolean;
117
+ share(key: string | Record<string, unknown>, value?: unknown): void;
118
+ composer(views: string | string[], composer: (view: View$1) => void | Promise<void>): void;
119
+ }
120
+ declare const ViewFactory: Token<ViewFactory>;
121
+
122
+ type ErrorKind = 'Http' | 'Server' | 'ModelNotFound' | 'Validation' | 'Authentication' | 'Authorization' | 'TokenMismatch' | 'BindingResolution' | 'CircularDependency' | 'ContainerNotAvailable';
123
+ /** Every error thrown by the framework implements this. The exception handler switches on `kind`. */
124
+ interface OrielError extends Error {
125
+ readonly kind: ErrorKind;
126
+ /** HTTP status the error should render as, when relevant. */
127
+ readonly status?: number;
128
+ readonly headers?: Record<string, string>;
129
+ }
130
+
131
+ declare abstract class ServiceProvider implements ServiceProvider$1 {
132
+ protected readonly app: Application;
133
+ constructor(app: Application);
134
+ register(): void;
135
+ boot(): void | Promise<void>;
136
+ /** Package defaults under `key`; values the app already set win (shallow merge, like Laravel). */
137
+ protected mergeConfigFrom(defaults: Record<string, unknown>, key: string): void;
138
+ }
139
+
140
+ interface FacadeStatics<T> {
141
+ getFacadeRoot(): T;
142
+ /** Replace the instance in the current container (used by X.fake()). */
143
+ swap(instance: T): void;
144
+ }
145
+ type Facade<T, X = object> = T & X & FacadeStatics<T>;
146
+
147
+ /** Marks the objects jsx() returns (Symbol.for, so two copies of the package agree). */
148
+ declare const ELEMENT: unique symbol;
149
+ type Props = Record<string, unknown>;
150
+ /** Anything that can appear as a child: text is escaped, Htmlable is emitted as-is, promises are awaited. */
151
+ type Renderable = OrielElement | string | number | bigint | boolean | null | undefined | Htmlable | Promise<Renderable> | Iterable<Renderable>;
152
+ /** A function component. It may be async: the renderer awaits it. */
153
+ type Component<P = Props> = (props: P) => Renderable | Promise<Renderable>;
154
+ /**
155
+ * `<>…</>` and `<Fragment>`: renders its children only. A symbol at runtime; typed as a component so that
156
+ * `<Fragment>` type-checks as a JSX tag.
157
+ */
158
+ declare const Fragment: (props: {
159
+ children?: Renderable;
160
+ }) => Renderable;
161
+ type ElementType = string | Component<never>;
162
+ /** What `<div />` evaluates to: an inert description, rendered later by renderToString()/renderToStream(). */
163
+ interface OrielElement {
164
+ readonly [ELEMENT]: true;
165
+ readonly type: ElementType;
166
+ readonly props: Props;
167
+ readonly key: string | number | undefined;
168
+ }
169
+ declare function createElement(type: ElementType, props: Props | null | undefined, key?: string | number): OrielElement;
170
+ declare function isElement(value: unknown): value is OrielElement;
171
+
172
+ /** Markup that must not be escaped again (Laravel's Illuminate\Support\HtmlString). */
173
+ declare class HtmlString implements Htmlable {
174
+ private readonly html;
175
+ constructor(html?: string);
176
+ toHtml(): string;
177
+ toString(): string;
178
+ isEmpty(): boolean;
179
+ }
180
+ /** Marks trusted markup so the renderer emits it unescaped: {raw(markdownHtml)}. Never pass user input. */
181
+ declare function raw(html: string): HtmlString;
182
+ declare function isHtmlable(value: unknown): value is Htmlable;
183
+ /** Laravel's e(): htmlspecialchars(ENT_QUOTES, double-encode). Htmlable values pass through; null is ''. */
184
+ declare function e(value: unknown): string;
185
+
186
+ type ClassValue = string | number | null | undefined | false | ClassValue[] | Record<string, unknown>;
187
+ type StyleObject = Record<string, string | number | null | undefined | false>;
188
+ /** `class` accepts strings, arrays and `{ name: condition }` objects, like Blade's @class. */
189
+ declare function classNames(value: ClassValue): string;
190
+ /** `{ marginTop: 4, '--gap': '1rem' }` → `margin-top:4px;--gap:1rem`. */
191
+ declare function styleString(style: StyleObject): string;
192
+
193
+ /** Renders JSX (or any Renderable) to an HTML string. Async components and promises are awaited in order. */
194
+ declare function renderToString(node: Renderable): Promise<string>;
195
+ /** Renders to a UTF-8 byte stream, sending everything rendered so far each time rendering waits on a promise. */
196
+ declare function renderToStream(node: Renderable): ReadableStream<Uint8Array>;
197
+
198
+ /**
199
+ * The automatic JSX runtime (`jsxImportSource: "@orieljs/view"`). jsx() only describes elements; rendering
200
+ * (escaping, async components) happens in renderToString()/renderToStream().
201
+ */
202
+
203
+ declare function jsx(type: ElementType, props: Props | null, key?: string | number): OrielElement;
204
+ /** Same as jsx(); the compiler uses it when there are several static children. */
205
+ declare const jsxs: typeof jsx;
206
+ /** Attributes every intrinsic element accepts. Unknown attributes (hx-*, x-*, o:click, …) are allowed. */
207
+ interface HtmlAttributes {
208
+ children?: Renderable;
209
+ class?: ClassValue;
210
+ className?: ClassValue;
211
+ style?: string | StyleObject;
212
+ dangerouslySetInnerHTML?: {
213
+ __html: string;
214
+ };
215
+ [attribute: string]: unknown;
216
+ }
217
+ declare namespace JSX {
218
+ type Element = OrielElement;
219
+ /** Lets components be async: `async function Posts() { … }` is a valid element type. */
220
+ type ElementType = string | Component<never>;
221
+ interface ElementChildrenAttribute {
222
+ children: unknown;
223
+ }
224
+ interface IntrinsicAttributes {
225
+ key?: string | number;
226
+ }
227
+ interface IntrinsicElements {
228
+ [element: string]: HtmlAttributes;
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Programmer errors (Laravel throws InvalidArgumentException for these). Not an HTTP condition, so kind 'Server':
234
+ * the exception handler reports them and renders a 500 whose message is hidden unless app.debug is on.
235
+ */
236
+ declare class ViewRenderError extends Error implements OrielError {
237
+ readonly name: string;
238
+ readonly kind: ErrorKind;
239
+ readonly status = 500;
240
+ }
241
+ /** Laravel's "View [x] not found." (InvalidArgumentException). */
242
+ declare class ViewNotFoundError extends Error implements OrielError {
243
+ readonly view: string;
244
+ readonly searched: string[];
245
+ readonly name: string;
246
+ readonly kind: ErrorKind;
247
+ readonly status = 500;
248
+ constructor(view: string, searched?: string[]);
249
+ }
250
+ /** A view file that doesn't default-export a component. */
251
+ declare class InvalidViewError extends Error implements OrielError {
252
+ readonly name: string;
253
+ readonly kind: ErrorKind;
254
+ readonly status = 500;
255
+ }
256
+
257
+ /**
258
+ * Laravel's FileViewFinder: 'posts.index' → <location>/posts/index.<ext> for the first location and extension
259
+ * that exist. Found paths are cached; misses are not, so a view created later is found.
260
+ */
261
+ declare class FileViewFinder {
262
+ private readonly extensions;
263
+ static readonly defaultExtensions: string[];
264
+ private readonly locations;
265
+ private readonly hints;
266
+ private readonly views;
267
+ constructor(paths: string[], extensions?: string[]);
268
+ /** The absolute path of the view file. Throws ViewNotFoundError. */
269
+ find(name: string): string;
270
+ addLocation(path: string): void;
271
+ prependLocation(path: string): void;
272
+ /** Views under a namespace: addNamespace('mail', dir) makes 'mail::message' resolve to <dir>/message.tsx. */
273
+ addNamespace(namespace: string, hints: string | string[]): void;
274
+ replaceNamespace(namespace: string, hints: string | string[]): void;
275
+ getPaths(): string[];
276
+ getHints(): Record<string, string[]>;
277
+ /** Forget cached lookups. */
278
+ flush(): void;
279
+ /** [locations to search, relative file stem]. Dots become directories, so '..' can't climb out of a location. */
280
+ private parse;
281
+ }
282
+
283
+ /** What TsxView needs from its factory. */
284
+ interface ViewEnvironment {
285
+ getShared(): Record<string, unknown>;
286
+ callComposer(view: View$1): Promise<void>;
287
+ load(path: string, name: string): Promise<Component>;
288
+ }
289
+ /**
290
+ * One view: its name, file and data. render() runs the composers, imports the file and renders its default
291
+ * export with { ...shared, ...data } as props. toHtml() returns the HTML of the last render().
292
+ */
293
+ declare class TsxView implements View$1 {
294
+ private readonly environment;
295
+ readonly name: string;
296
+ readonly path: string;
297
+ private data;
298
+ private html;
299
+ constructor(environment: ViewEnvironment, name: string, path: string, data?: Record<string, unknown>);
300
+ with(key: string | Record<string, unknown>, value?: unknown): this;
301
+ /** The view's own data (Laravel's getData()). */
302
+ getData(): Record<string, unknown>;
303
+ /** Shared data overlaid with the view's data: exactly the props the component receives. */
304
+ gatherData(): Record<string, unknown>;
305
+ render(): Promise<string>;
306
+ toHtml(): string;
307
+ }
308
+
309
+ type Composer = (view: View$1) => void | Promise<void>;
310
+ /** Laravel's view Factory: finds views by dotted name, shares data app-wide and runs view composers. */
311
+ declare class Factory implements ViewFactory, ViewEnvironment {
312
+ private readonly finder;
313
+ private readonly shared;
314
+ private readonly composers;
315
+ constructor(finder: FileViewFinder);
316
+ /** Throws ViewNotFoundError ("View [x] not found.") when no file matches. */
317
+ make(name: string, data?: Record<string, unknown>): TsxView;
318
+ /** The first view that exists (Laravel's View::first()). */
319
+ first(names: string[], data?: Record<string, unknown>): TsxView;
320
+ exists(name: string): boolean;
321
+ /** App-wide data every view receives as props (view data wins on conflicts). */
322
+ share(key: string | Record<string, unknown>, value?: unknown): void;
323
+ getShared(): Record<string, unknown>;
324
+ /** Runs before matching views render. Patterns use `*` wildcards: 'posts.*', '*'. */
325
+ composer(views: string | string[], composer: Composer): void;
326
+ callComposer(view: View$1): Promise<void>;
327
+ /** Imports the view file (Node's module cache keeps it) and returns its default-export component. */
328
+ load(path: string, name: string): Promise<Component>;
329
+ addLocation(path: string): void;
330
+ addNamespace(namespace: string, hints: string | string[]): this;
331
+ getFinder(): FileViewFinder;
332
+ }
333
+
334
+ /** view() → the ViewFactory; view('posts.index', data) → a View to return from a route or render. */
335
+ declare function view(): ViewFactory;
336
+ declare function view(name: string, data?: Record<string, unknown>): View$1;
337
+ /** Blade's @csrf / csrf_field(): the hidden _token input for the current request's session. */
338
+ declare function csrfField(): HtmlString;
339
+ /** Blade's @method('PUT') / method_field(): spoofs PUT/PATCH/DELETE from an HTML form. */
340
+ declare function methodField(method: string): HtmlString;
341
+
342
+ /** The View facade: View.make(), View.exists(), View.share(), View.composer(), View.first(), View.addNamespace(). */
343
+ declare const View: Facade<Factory, object>;
344
+
345
+ /** Binds the ViewFactory (resources/views by default) and merges the `view` config, like Laravel's config/view.php. */
346
+ declare class ViewServiceProvider extends ServiceProvider {
347
+ register(): void;
348
+ }
349
+
350
+ export { Application as A, jsxs as B, ClassRegistry 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 ServiceProvider$1 as S, TsxView as T, View as V, type Class as a, type Abstract as b, ConfigRepository as c, type ClassValue as d, type Component as e, Fragment as f, HtmlString as g, type StyleObject as h, type ViewEnvironment as i, Factory as j, ViewNotFoundError as k, ViewRenderError as l, ViewServiceProvider as m, classNames as n, createElement as o, csrfField as p, e as q, isElement as r, isHtmlable as s, methodField as t, raw as u, renderToStream as v, renderToString as w, styleString as x, view as y, jsx as z };
@@ -0,0 +1 @@
1
+ export { f as Fragment, H as HtmlAttributes, J as JSX, z as jsx, B as jsxs } from './jsx-runtime-B8J6xq-7.js';
@@ -0,0 +1,13 @@
1
+ import {
2
+ Fragment,
3
+ jsx,
4
+ jsxs
5
+ } from "./chunk-WI7E7Q46.js";
6
+ import "./chunk-AI2RFMBT.js";
7
+ import "./chunk-K6MAA3RM.js";
8
+ export {
9
+ Fragment,
10
+ jsx,
11
+ jsxs
12
+ };
13
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}