@orieljs/live 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/LICENSE +202 -0
- package/README.md +47 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.js +1095 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @orieljs/live
|
|
2
|
+
|
|
3
|
+
Server-side Live components for Oriel: Livewire-style components written in TSX, with signed snapshots, actions, events and `Live.test()`. Live is part of `@orieljs/framework`, which every Oriel app already installs, and is re-exported from it. Its semantics follow Livewire 3. In an app, import it from `@orieljs/framework` only: `@orieljs/live` is also published on its own, but a separate copy doesn't share the framework's per-request state.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @orieljs/framework
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
// app/Live/Counter.tsx
|
|
11
|
+
import { Component } from '@orieljs/framework'
|
|
12
|
+
|
|
13
|
+
export default class Counter extends Component {
|
|
14
|
+
count = 0
|
|
15
|
+
|
|
16
|
+
increment() {
|
|
17
|
+
this.count++
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
render() {
|
|
21
|
+
return <button o:click="increment">{this.count}</button>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// routes/web.ts
|
|
28
|
+
import { Route } from '@orieljs/framework'
|
|
29
|
+
import Counter from '../app/Live/Counter'
|
|
30
|
+
|
|
31
|
+
Route.get('/counter', Counter)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Embed a component in any view with `<Live component={Counter} />`. In the browser, components are driven by `@orieljs/live-client`.
|
|
35
|
+
|
|
36
|
+
Known limitations:
|
|
37
|
+
|
|
38
|
+
- `o:navigate` does not run scripts in the new page.
|
|
39
|
+
- A DOM event whose name contains `-` can't be written as `o:<event>` in TSX, because modifiers are `-` segments (for example `o:model-live`).
|
|
40
|
+
|
|
41
|
+
Status: early alpha. APIs will change.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Oriel is open-source software licensed under the Apache License 2.0 (Apache-2.0; see `LICENSE` and `NOTICE`). The Oriel name and logo are trademarks; see [`TRADEMARKS.md`](https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
|
46
|
+
|
|
47
|
+
Website: https://orieljs.vercel.app
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { Class, Rules, MessageBag, LiveEffects, Htmlable, LiveSnapshot, LiveManager, Application, HttpRequest, LiveUpdateRequest, LiveUpdateResponse, OrielError, ErrorKind } from '@orieljs/contracts';
|
|
2
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
3
|
+
|
|
4
|
+
/** Marks Live component classes (Symbol.for, so two copies of the package agree). */
|
|
5
|
+
declare const COMPONENT: unique symbol;
|
|
6
|
+
/** A browser event queued by dispatch(). `to` is resolved to a component name when the effects are built. */
|
|
7
|
+
interface QueuedDispatch {
|
|
8
|
+
name: string;
|
|
9
|
+
params: Record<string, unknown>;
|
|
10
|
+
self?: true;
|
|
11
|
+
to?: string | Class<Component>;
|
|
12
|
+
}
|
|
13
|
+
/** The validation errors of a component (Laravel's MessageBag), for render(): `this.errors.first('title')`. */
|
|
14
|
+
declare class ErrorBag implements MessageBag {
|
|
15
|
+
private readonly messages;
|
|
16
|
+
constructor(messages: Record<string, string[]>);
|
|
17
|
+
has(key: string): boolean;
|
|
18
|
+
first(key?: string): string | undefined;
|
|
19
|
+
get(key: string): string[];
|
|
20
|
+
all(): string[];
|
|
21
|
+
any(): boolean;
|
|
22
|
+
isEmpty(): boolean;
|
|
23
|
+
count(): number;
|
|
24
|
+
toObject(): Record<string, string[]>;
|
|
25
|
+
}
|
|
26
|
+
/** What dispatch() returns: `this.dispatch('saved').self()` or `.to(Sidebar)`. */
|
|
27
|
+
declare class PendingEvent {
|
|
28
|
+
private readonly event;
|
|
29
|
+
constructor(event: QueuedDispatch);
|
|
30
|
+
/** Only this component's own listeners receive the event. */
|
|
31
|
+
self(): this;
|
|
32
|
+
/** Only components of this class (or registered name) receive the event. */
|
|
33
|
+
to(component: string | Class<Component>): this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A Live component (Livewire 3): public fields are its state, public methods are actions the browser can call, and
|
|
37
|
+
* render() returns its TSX. Lifecycle hooks, all optional: `boot()`, `mount(params)`, `hydrate()`, `dehydrate()`,
|
|
38
|
+
* `updating(name, value)`/`updated(name, value)` and per property `updatingTitle(value)`/`updatedTitle(value)`,
|
|
39
|
+
* `rendering()`/`rendered(html)`. Fields that must not be state use `#private` syntax.
|
|
40
|
+
*/
|
|
41
|
+
declare abstract class Component {
|
|
42
|
+
static readonly [COMPONENT] = true;
|
|
43
|
+
/** The view that wraps a full-page component (default: config `live.layout`). */
|
|
44
|
+
static layout?: string;
|
|
45
|
+
/** The page title passed to the layout as `title`. */
|
|
46
|
+
static title?: string;
|
|
47
|
+
/** Static fallbacks for runtimes without decorators: { event: 'method' }, locked names, computed getter names. */
|
|
48
|
+
static listeners?: Record<string, string>;
|
|
49
|
+
static locked?: string[];
|
|
50
|
+
static computed?: string[];
|
|
51
|
+
abstract render(): unknown;
|
|
52
|
+
getId(): string;
|
|
53
|
+
getName(): string;
|
|
54
|
+
/** Dispatches a browser event; every component listening for it (@On) runs its handler. */
|
|
55
|
+
dispatch(name: string, params?: Record<string, unknown>): PendingEvent;
|
|
56
|
+
/** Sends the browser to `url` after this request; `navigate` uses o:navigate instead of a full page load. */
|
|
57
|
+
redirect(url: string, options?: {
|
|
58
|
+
navigate?: boolean;
|
|
59
|
+
}): void;
|
|
60
|
+
redirectRoute(name: string, parameters?: unknown, options?: {
|
|
61
|
+
navigate?: boolean;
|
|
62
|
+
}): void;
|
|
63
|
+
/**
|
|
64
|
+
* Validates the public state. On success clears the error bag and returns the validated data; on failure fills the
|
|
65
|
+
* error bag and throws (the rest of the action is skipped and the component re-renders with `errors`).
|
|
66
|
+
*/
|
|
67
|
+
validate<T = Record<string, unknown>>(rules: Rules, messages?: Record<string, string>, attributes?: Record<string, string>): Promise<T>;
|
|
68
|
+
addError(key: string, message: string): void;
|
|
69
|
+
/** Clears every error, or only those of `keys`. */
|
|
70
|
+
resetErrorBag(...keys: string[]): void;
|
|
71
|
+
get errors(): ErrorBag;
|
|
72
|
+
/** Puts public properties (all of them when none are named) back to their initial values. */
|
|
73
|
+
reset(...properties: string[]): void;
|
|
74
|
+
/** Keeps the current HTML: the response carries the new state but no `html` effect. */
|
|
75
|
+
skipRender(): void;
|
|
76
|
+
/** A full-page component as a route action: Route.get('/counter', Counter). Route parameters go to mount(). */
|
|
77
|
+
__invoke(): Promise<unknown>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @On('post-created'): calls the method when the event is dispatched (by this or any component, or the browser). */
|
|
81
|
+
declare function On(event: string): (_method: unknown, context: ClassMethodDecoratorContext) => void;
|
|
82
|
+
/** @Locked: a property the browser can't change, or a method the browser can't call. */
|
|
83
|
+
declare function Locked(_target: unknown, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext): void;
|
|
84
|
+
/** @Computed: a getter cached for the rest of the request, never part of the component's state. */
|
|
85
|
+
declare function Computed<T>(getter: (this: object) => T, context: ClassGetterDecoratorContext): (this: object) => T;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Livewire's Livewire::test(): drives one component through the real mount → snapshot → checksum → update pipeline
|
|
89
|
+
* (no HTTP). Actions are async (`await counter.call('increment')`); assertions are sync and return `this`.
|
|
90
|
+
*/
|
|
91
|
+
declare class Testable<C extends Component = Component> {
|
|
92
|
+
#private;
|
|
93
|
+
private readonly manager;
|
|
94
|
+
private constructor();
|
|
95
|
+
/** Mounts `component` with `params`, as `<Live component={…} {...params} />` would. */
|
|
96
|
+
static create<C extends Component>(component: Class<C> | string, params?: Record<string, unknown>): Promise<Testable<C>>;
|
|
97
|
+
/** The component instance after the last request. */
|
|
98
|
+
instance(): C;
|
|
99
|
+
/** A public property (dotted paths reach into arrays and objects). */
|
|
100
|
+
get<T = unknown>(path: string): T;
|
|
101
|
+
/** The last rendered HTML, without the o:id, o:snapshot and o:effects attributes (Livewire strips them too). */
|
|
102
|
+
html(): string;
|
|
103
|
+
/** The effects of the last request. */
|
|
104
|
+
effects(): LiveEffects;
|
|
105
|
+
set(path: string | Record<string, unknown>, value?: unknown): Promise<this>;
|
|
106
|
+
call(method: string, ...params: unknown[]): Promise<this>;
|
|
107
|
+
toggle(path: string): Promise<this>;
|
|
108
|
+
/** Dispatches an event to this component, as the browser does for its listeners. */
|
|
109
|
+
dispatch(event: string, params?: Record<string, unknown>): Promise<this>;
|
|
110
|
+
refresh(): Promise<this>;
|
|
111
|
+
assertSet(path: string, value: unknown): this;
|
|
112
|
+
assertNotSet(path: string, value: unknown): this;
|
|
113
|
+
/** Each value, HTML-escaped, appears in the rendered HTML. */
|
|
114
|
+
assertSee(...values: string[]): this;
|
|
115
|
+
assertDontSee(...values: string[]): this;
|
|
116
|
+
/** Each value appears in the rendered HTML as written (not escaped). */
|
|
117
|
+
assertSeeHtml(...values: string[]): this;
|
|
118
|
+
assertDispatched(name: string, params?: Record<string, unknown>): this;
|
|
119
|
+
assertNotDispatched(name: string): this;
|
|
120
|
+
/** The error bag has errors for every key given (or any error at all with no keys). */
|
|
121
|
+
assertHasErrors(keys?: string | string[]): this;
|
|
122
|
+
/** No errors for the keys given (or none at all with no keys). */
|
|
123
|
+
assertHasNoErrors(keys?: string | string[]): this;
|
|
124
|
+
assertRedirect(url?: string): this;
|
|
125
|
+
assertNoRedirect(): this;
|
|
126
|
+
/** The last call returned `value`. */
|
|
127
|
+
assertReturned(value: unknown): this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Props of `<Live component={Counter} count={3} o:key="c1" />`: the rest become mount params. */
|
|
131
|
+
interface LiveProps {
|
|
132
|
+
component: Class<Component> | string;
|
|
133
|
+
/** Identifies a child inside its parent across re-renders (Livewire's :key / wire:key). */
|
|
134
|
+
'o:key'?: string | number;
|
|
135
|
+
[param: string]: unknown;
|
|
136
|
+
}
|
|
137
|
+
/** Blade's @livewire('counter', ['count' => 3], key('c1')): the component's first render, as trusted HTML. */
|
|
138
|
+
declare function live(component: Class<Component> | string, params?: Record<string, unknown>, key?: string | number): Promise<Htmlable>;
|
|
139
|
+
/** `<Live component={Counter} />` in any view or component. */
|
|
140
|
+
declare function LiveComponent({ component, 'o:key': key, children: _children, ...params }: LiveProps): Promise<Htmlable>;
|
|
141
|
+
/** The `<Live />` element, and the Live facade: Live.component(name, Class), Live.test(Component). */
|
|
142
|
+
declare const Live: typeof LiveComponent & {
|
|
143
|
+
/** Registers a component under a name (components in app/Live are registered at boot). */
|
|
144
|
+
component(name: string, component: Class<Component>): void;
|
|
145
|
+
/** Livewire::test(): mounts `component` for assertions. */
|
|
146
|
+
test<C extends Component>(component: Class<C> | string, params?: Record<string, unknown>): Promise<Testable<C>>;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
type Call = {
|
|
150
|
+
method: string;
|
|
151
|
+
params: unknown[];
|
|
152
|
+
};
|
|
153
|
+
/** One component after a mount or an update: the live instance (for Live.test), its snapshot, effects and HTML. */
|
|
154
|
+
interface ComponentResult {
|
|
155
|
+
instance: Component;
|
|
156
|
+
snapshot: LiveSnapshot;
|
|
157
|
+
effects: LiveEffects;
|
|
158
|
+
/** The rendered HTML with o:id (and, after a mount, o:snapshot/o:effects); undefined after skipRender(). */
|
|
159
|
+
html?: string;
|
|
160
|
+
tag?: string;
|
|
161
|
+
}
|
|
162
|
+
/** Livewire's update request handling and first render, on Oriel's contracts. */
|
|
163
|
+
declare class LiveComponentManager implements LiveManager {
|
|
164
|
+
private readonly app;
|
|
165
|
+
constructor(app: Application);
|
|
166
|
+
/** The request scope when there is one (sessions, the current route), else the application. */
|
|
167
|
+
private container;
|
|
168
|
+
private registry;
|
|
169
|
+
/** Live.component('counter', Counter): registers a component under a name the snapshots use. */
|
|
170
|
+
register(component: Class<unknown>, name?: string): void;
|
|
171
|
+
/** The registered name of a component class, registering it under its kebab-case class name the first time. */
|
|
172
|
+
nameOf(component: Class<Component>): string;
|
|
173
|
+
resolve(name: string): Class<Component>;
|
|
174
|
+
isLiveRequest(request: HttpRequest): boolean;
|
|
175
|
+
/** The first render: HTML with o:id, o:snapshot and o:effects on the root element. */
|
|
176
|
+
mount(component: string | Class<unknown>, params?: Record<string, unknown>, key?: string): Promise<string>;
|
|
177
|
+
mountComponent(component: string | Class<unknown>, params?: Record<string, unknown>, existing?: Component): Promise<ComponentResult>;
|
|
178
|
+
/** Applies each component's updates and calls, re-renders it and returns its new snapshot and effects. */
|
|
179
|
+
update(request: LiveUpdateRequest): Promise<LiveUpdateResponse>;
|
|
180
|
+
updateComponent(snapshotJson: string, updates: Record<string, unknown>, calls: Call[]): Promise<ComponentResult>;
|
|
181
|
+
/** The route action of POST /oriel/live/update. */
|
|
182
|
+
handle(request: HttpRequest): Promise<LiveUpdateResponse>;
|
|
183
|
+
/** A full-page component (Route.get('/counter', Counter)): mounted with the route parameters, inside the layout. */
|
|
184
|
+
page(component: Component): Promise<unknown>;
|
|
185
|
+
/** Parses and checks a snapshot: a bad checksum throws before anything is hydrated. */
|
|
186
|
+
private verify;
|
|
187
|
+
private key;
|
|
188
|
+
/** The request body, read from the raw JSON when the request has it, so TrimStrings can't alter typed values. */
|
|
189
|
+
private payload;
|
|
190
|
+
/** Makes every computed getter (static `computed` too) cache its value for the rest of the request. */
|
|
191
|
+
private prepareComputed;
|
|
192
|
+
private applyUpdate;
|
|
193
|
+
/** Runs one call from the browser: a magic action, an event, or a public method. Returns its return value. */
|
|
194
|
+
private call;
|
|
195
|
+
/** Renders the component (rendering/rendered hooks, nested children tracked) and checks for a single root. */
|
|
196
|
+
private render;
|
|
197
|
+
/** Dispatches, redirects: the effects every response carries. */
|
|
198
|
+
private effects;
|
|
199
|
+
/** dehydrate() hook, then the state as snapshot data, the error bag, and the checksum over both. */
|
|
200
|
+
private snapshot;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The URI the client runtime posts updates to. */
|
|
204
|
+
declare const UPDATE_URI = "/oriel/live/update";
|
|
205
|
+
/**
|
|
206
|
+
* Binds the LiveManager, merges the `live` config, registers POST /oriel/live/update (named `live.update`, in the `web`
|
|
207
|
+
* group: sessions and CSRF apply), the make:live command, and the components under app/Live.
|
|
208
|
+
*/
|
|
209
|
+
declare class LiveServiceProvider extends ServiceProvider {
|
|
210
|
+
register(): void;
|
|
211
|
+
boot(): Promise<void>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** A component's Livewire name from its path under app/Live: Posts/CreatePost.tsx → posts.create-post. */
|
|
215
|
+
declare function componentName(file: string): string;
|
|
216
|
+
|
|
217
|
+
/** A Live programming error (unsupported state, a missing root element, an unknown component): a 500. */
|
|
218
|
+
declare class LiveError extends Error implements OrielError {
|
|
219
|
+
readonly name: string;
|
|
220
|
+
readonly kind: ErrorKind;
|
|
221
|
+
readonly status: number;
|
|
222
|
+
}
|
|
223
|
+
/** A snapshot whose checksum doesn't match (tampered with, or signed with another APP_KEY). Nothing is hydrated. */
|
|
224
|
+
declare class CorruptComponentPayloadError extends LiveError {
|
|
225
|
+
readonly name: string;
|
|
226
|
+
readonly kind: ErrorKind;
|
|
227
|
+
readonly status: number;
|
|
228
|
+
constructor(component?: string);
|
|
229
|
+
}
|
|
230
|
+
/** The browser asked for a method that isn't a public action of the component. */
|
|
231
|
+
declare class MethodNotCallableError extends LiveError {
|
|
232
|
+
readonly name: string;
|
|
233
|
+
readonly kind: ErrorKind;
|
|
234
|
+
readonly status: number;
|
|
235
|
+
constructor(method: string, component: string);
|
|
236
|
+
}
|
|
237
|
+
/** The browser tried to set a property that is locked, computed, private (`_x`) or not declared. */
|
|
238
|
+
declare class PropertyNotUpdatableError extends LiveError {
|
|
239
|
+
readonly name: string;
|
|
240
|
+
readonly kind: ErrorKind;
|
|
241
|
+
readonly status: number;
|
|
242
|
+
constructor(path: string, component: string);
|
|
243
|
+
}
|
|
244
|
+
/** A snapshot names a component that isn't registered. */
|
|
245
|
+
declare class LiveComponentNotFoundError extends LiveError {
|
|
246
|
+
readonly name: string;
|
|
247
|
+
readonly kind: ErrorKind;
|
|
248
|
+
readonly status: number;
|
|
249
|
+
constructor(component: string);
|
|
250
|
+
}
|
|
251
|
+
/** An update request without the X-Oriel-Live header or with a malformed body. */
|
|
252
|
+
declare class InvalidLiveRequestError extends LiveError {
|
|
253
|
+
readonly name: string;
|
|
254
|
+
readonly kind: ErrorKind;
|
|
255
|
+
readonly status: number;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { Component, type ComponentResult, Computed, CorruptComponentPayloadError, ErrorBag, InvalidLiveRequestError, Live, LiveComponentManager, LiveComponentNotFoundError, LiveError, type LiveProps, LiveServiceProvider, Locked, MethodNotCallableError, On, PendingEvent, PropertyNotUpdatableError, Testable, UPDATE_URI, componentName, live };
|