metaowl 0.4.0 → 0.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.
- package/CHANGELOG.md +52 -0
- package/README.md +13 -15
- package/build/runtime/bin/metaowl-build.js +10 -0
- package/{bin → build/runtime/bin}/metaowl-create.js +96 -177
- package/build/runtime/bin/metaowl-dev.js +10 -0
- package/build/runtime/bin/metaowl-generate.js +231 -0
- package/build/runtime/bin/metaowl-lint.js +58 -0
- package/build/runtime/bin/utils.js +68 -0
- package/build/runtime/index.js +141 -0
- package/build/runtime/modules/app-mounter.js +65 -0
- package/build/runtime/modules/auto-import.js +140 -0
- package/build/runtime/modules/cache.js +49 -0
- package/build/runtime/modules/composables.js +353 -0
- package/build/runtime/modules/error-boundary.js +116 -0
- package/build/runtime/modules/fetch.js +31 -0
- package/build/runtime/modules/file-router.js +205 -0
- package/build/runtime/modules/forms.js +193 -0
- package/build/runtime/modules/i18n.js +167 -0
- package/build/runtime/modules/layouts.js +163 -0
- package/build/runtime/modules/link.js +141 -0
- package/build/runtime/modules/meta.js +117 -0
- package/build/runtime/modules/odoo-rpc.js +264 -0
- package/build/runtime/modules/pwa.js +262 -0
- package/build/runtime/modules/router.js +389 -0
- package/build/runtime/modules/seo.js +186 -0
- package/build/runtime/modules/store.js +196 -0
- package/build/runtime/modules/templates-manager.js +52 -0
- package/build/runtime/modules/test-utils.js +238 -0
- package/build/runtime/vite/plugin.js +183 -0
- package/eslint.js +29 -0
- package/package.json +29 -11
- package/CONTRIBUTING.md +0 -49
- package/bin/metaowl-build.js +0 -12
- package/bin/metaowl-dev.js +0 -12
- package/bin/metaowl-generate.js +0 -339
- package/bin/metaowl-lint.js +0 -71
- package/bin/utils.js +0 -82
- package/index.js +0 -328
- package/modules/app-mounter.js +0 -104
- package/modules/auto-import.js +0 -225
- package/modules/cache.js +0 -59
- package/modules/composables.js +0 -600
- package/modules/error-boundary.js +0 -228
- package/modules/fetch.js +0 -51
- package/modules/file-router.js +0 -478
- package/modules/forms.js +0 -353
- package/modules/i18n.js +0 -333
- package/modules/layouts.js +0 -431
- package/modules/link.js +0 -255
- package/modules/meta.js +0 -119
- package/modules/odoo-rpc.js +0 -511
- package/modules/pwa.js +0 -515
- package/modules/router.js +0 -769
- package/modules/seo.js +0 -501
- package/modules/store.js +0 -409
- package/modules/templates-manager.js +0 -89
- package/modules/test-utils.js +0 -532
- package/test/auto-import.test.js +0 -110
- package/test/cache.test.js +0 -55
- package/test/composables.test.js +0 -103
- package/test/dynamic-routes.test.js +0 -469
- package/test/error-boundary.test.js +0 -126
- package/test/fetch.test.js +0 -100
- package/test/file-router.test.js +0 -55
- package/test/forms.test.js +0 -203
- package/test/i18n.test.js +0 -188
- package/test/layouts.test.js +0 -395
- package/test/link.test.js +0 -189
- package/test/meta.test.js +0 -146
- package/test/odoo-rpc.test.js +0 -547
- package/test/pwa.test.js +0 -154
- package/test/router-guards.test.js +0 -229
- package/test/router.test.js +0 -77
- package/test/seo.test.js +0 -353
- package/test/store.test.js +0 -476
- package/test/templates-manager.test.js +0 -83
- package/test/test-utils.test.js +0 -314
- package/vite/plugin.js +0 -277
- package/vitest.config.js +0 -8
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module ErrorBoundary
|
|
3
|
-
*
|
|
4
|
-
* Error boundaries for OWL applications. Catches JavaScript errors anywhere
|
|
5
|
-
* in their child component tree, logs those errors, and displays a fallback UI.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Component-level error boundaries
|
|
9
|
-
* - Global error handler
|
|
10
|
-
* - Custom fallback components
|
|
11
|
-
* - Error logging hooks
|
|
12
|
-
* - Error page routing (404, 500)
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Wrap component with error boundary
|
|
16
|
-
* export default class MyPage extends Component {
|
|
17
|
-
* static template = 'MyPage'
|
|
18
|
-
* static errorBoundary = true
|
|
19
|
-
* static fallback = ErrorFallback
|
|
20
|
-
*
|
|
21
|
-
* onError(error, errorInfo) {
|
|
22
|
-
* console.error('Caught error:', error)
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* // Global error handler
|
|
27
|
-
* onError((error, context) => {
|
|
28
|
-
* sendToAnalytics(error, context)
|
|
29
|
-
* })
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import { Component } from '@odoo/owl'
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Global error handlers registry.
|
|
36
|
-
* @type {Function[]}
|
|
37
|
-
*/
|
|
38
|
-
const _globalErrorHandlers = []
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Global error context (component name, route, etc.)
|
|
42
|
-
* @type {object}
|
|
43
|
-
*/
|
|
44
|
-
let _errorContext = {}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Error boundary wrapper component.
|
|
48
|
-
* Renders children and catches errors during rendering/lifecycle.
|
|
49
|
-
*/
|
|
50
|
-
export class ErrorBoundary extends Component {
|
|
51
|
-
static template = xml`
|
|
52
|
-
<t t-if="state.hasError">
|
|
53
|
-
<t t-component="props.Fallback || fallback"
|
|
54
|
-
t-props="{ error: state.error, errorInfo: state.errorInfo }"/>
|
|
55
|
-
</t>
|
|
56
|
-
<t t-else="">
|
|
57
|
-
<t t-slot="default"/>
|
|
58
|
-
</t>
|
|
59
|
-
`
|
|
60
|
-
|
|
61
|
-
static defaultProps = {
|
|
62
|
-
Fallback: null
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
setup() {
|
|
66
|
-
this.state = useState({
|
|
67
|
-
hasError: false,
|
|
68
|
-
error: null,
|
|
69
|
-
errorInfo: null
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
onError(error, errorInfo) {
|
|
74
|
-
this.state.hasError = true
|
|
75
|
-
this.state.error = error
|
|
76
|
-
this.state.errorInfo = errorInfo
|
|
77
|
-
|
|
78
|
-
// Call global error handlers
|
|
79
|
-
for (const handler of _globalErrorHandlers) {
|
|
80
|
-
handler(error, { ..._errorContext, ...errorInfo })
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Default fallback component showing error details.
|
|
87
|
-
*/
|
|
88
|
-
export class DefaultErrorFallback extends Component {
|
|
89
|
-
static template = xml`
|
|
90
|
-
<div class="error-boundary-fallback">
|
|
91
|
-
<h2>Something went wrong</h2>
|
|
92
|
-
<t t-if="props.error">
|
|
93
|
-
<details>
|
|
94
|
-
<summary>Error details</summary>
|
|
95
|
-
<pre t-esc="props.error.stack || props.error.message || props.error"/>
|
|
96
|
-
</details>
|
|
97
|
-
</t>
|
|
98
|
-
</div>
|
|
99
|
-
`
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Register a global error handler.
|
|
104
|
-
*
|
|
105
|
-
* @param {Function} handler - (error, context) => void
|
|
106
|
-
* @returns {Function} Unsubscribe function
|
|
107
|
-
*/
|
|
108
|
-
export function onError(handler) {
|
|
109
|
-
_globalErrorHandlers.push(handler)
|
|
110
|
-
return () => {
|
|
111
|
-
const index = _globalErrorHandlers.indexOf(handler)
|
|
112
|
-
if (index > -1) {
|
|
113
|
-
_globalErrorHandlers.splice(index, 1)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Set global error context (e.g., current route, user info).
|
|
120
|
-
*
|
|
121
|
-
* @param {object} context
|
|
122
|
-
*/
|
|
123
|
-
export function setErrorContext(context) {
|
|
124
|
-
_errorContext = { ..._errorContext, ...context }
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Get current error context.
|
|
129
|
-
*
|
|
130
|
-
* @returns {object}
|
|
131
|
-
*/
|
|
132
|
-
export function getErrorContext() {
|
|
133
|
-
return { ..._errorContext }
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Clear global error context.
|
|
138
|
-
*/
|
|
139
|
-
export function clearErrorContext() {
|
|
140
|
-
_errorContext = {}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Capture and report an error manually.
|
|
145
|
-
*
|
|
146
|
-
* @param {Error} error
|
|
147
|
-
* @param {object} [context]
|
|
148
|
-
*/
|
|
149
|
-
export function captureError(error, context = {}) {
|
|
150
|
-
const fullContext = { ..._errorContext, ...context }
|
|
151
|
-
for (const handler of _globalErrorHandlers) {
|
|
152
|
-
handler(error, fullContext)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Error boundary decorator for component classes.
|
|
158
|
-
*
|
|
159
|
-
* @param {object} options
|
|
160
|
-
* @param {boolean} [options.enabled=true]
|
|
161
|
-
* @param {typeof Component} [options.Fallback]
|
|
162
|
-
* @returns {Function} Decorator
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* @errorBoundary({ Fallback: CustomFallback })
|
|
166
|
-
* export class MyComponent extends Component { }
|
|
167
|
-
*/
|
|
168
|
-
export function errorBoundary(options = {}) {
|
|
169
|
-
return function decorator(ComponentClass) {
|
|
170
|
-
ComponentClass.errorBoundary = true
|
|
171
|
-
if (options.Fallback) {
|
|
172
|
-
ComponentClass.fallback = options.Fallback
|
|
173
|
-
}
|
|
174
|
-
return ComponentClass
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Create an error boundary wrapper for a component.
|
|
180
|
-
*
|
|
181
|
-
* @param {typeof Component} ComponentClass
|
|
182
|
-
* @param {object} [options]
|
|
183
|
-
* @param {typeof Component} [options.Fallback]
|
|
184
|
-
* @returns {typeof Component} Wrapped component
|
|
185
|
-
*/
|
|
186
|
-
export function withErrorBoundary(ComponentClass, options = {}) {
|
|
187
|
-
return class extends Component {
|
|
188
|
-
static template = xml`
|
|
189
|
-
<ErrorBoundary Fallback="props.Fallback || fallback">
|
|
190
|
-
<t t-component="Component" t-props="props"/>
|
|
191
|
-
</ErrorBoundary>
|
|
192
|
-
`
|
|
193
|
-
|
|
194
|
-
static components = { ErrorBoundary }
|
|
195
|
-
|
|
196
|
-
setup() {
|
|
197
|
-
this.Component = ComponentClass
|
|
198
|
-
this.fallback = options.Fallback || DefaultErrorFallback
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Initialize global error handling.
|
|
205
|
-
* Sets up window.onerror and window.onunhandledrejection.
|
|
206
|
-
*/
|
|
207
|
-
export function initGlobalErrorHandling() {
|
|
208
|
-
// Catch global errors
|
|
209
|
-
window.onerror = (message, source, lineno, colno, error) => {
|
|
210
|
-
captureError(error || new Error(message), {
|
|
211
|
-
type: 'window.onerror',
|
|
212
|
-
source,
|
|
213
|
-
lineno,
|
|
214
|
-
colno
|
|
215
|
-
})
|
|
216
|
-
return false // Don't prevent default handling
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Catch unhandled promise rejections
|
|
220
|
-
window.onunhandledrejection = (event) => {
|
|
221
|
-
captureError(event.reason, {
|
|
222
|
-
type: 'unhandledrejection'
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Import at end to avoid circular dependency
|
|
228
|
-
import { useState, xml } from '@odoo/owl'
|
package/modules/fetch.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Fetch
|
|
3
|
-
*
|
|
4
|
-
* A static class wrapping the Fetch API with a configurable base URL and
|
|
5
|
-
* error handling. All internal requests automatically prepend the configured
|
|
6
|
-
* baseUrl and return parsed JSON.
|
|
7
|
-
*/
|
|
8
|
-
export default class Fetch {
|
|
9
|
-
static _baseUrl = ''
|
|
10
|
-
static _onError = null
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configure the Fetch helper. Call once in your metaowl.js before boot().
|
|
14
|
-
*
|
|
15
|
-
* @param {object} options
|
|
16
|
-
* @param {string} [options.baseUrl=''] - Base URL prepended to every internal request.
|
|
17
|
-
* @param {function} [options.onError] - Callback invoked on network errors.
|
|
18
|
-
*/
|
|
19
|
-
static configure({ baseUrl = '', onError = null } = {}) {
|
|
20
|
-
Fetch._baseUrl = baseUrl
|
|
21
|
-
Fetch._onError = onError
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Perform a fetch request.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} url - Path or full URL.
|
|
28
|
-
* @param {'GET'|'POST'|'PUT'|'PATCH'|'DELETE'} [method='GET']
|
|
29
|
-
* @param {object|null} [data=null] - Request body (JSON-serialised).
|
|
30
|
-
* @param {boolean} [internal=true] - Prepend baseUrl when true.
|
|
31
|
-
* @param {boolean} [triggerErrorHandler=true] - Call onError callback on failure.
|
|
32
|
-
* @returns {Promise<any|null>}
|
|
33
|
-
*/
|
|
34
|
-
static async url(url, method = 'GET', data = null, internal = true, triggerErrorHandler = true) {
|
|
35
|
-
const fullUrl = `${internal ? Fetch._baseUrl : ''}${url}`
|
|
36
|
-
|
|
37
|
-
const response = await fetch(fullUrl, {
|
|
38
|
-
method,
|
|
39
|
-
body: data ? JSON.stringify(data) : null
|
|
40
|
-
}).catch(error => {
|
|
41
|
-
console.warn('[metaowl] Fetch error:', error)
|
|
42
|
-
if (triggerErrorHandler && Fetch._onError) {
|
|
43
|
-
Fetch._onError(error)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
if (!response) return null
|
|
48
|
-
|
|
49
|
-
return response.json()
|
|
50
|
-
}
|
|
51
|
-
}
|