@hybridly/core 0.0.1-alpha.4 → 0.0.1-alpha.5
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/index.cjs +6 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +6 -6
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,7 @@ const axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
|
12
12
|
const qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
13
13
|
|
|
14
14
|
const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
15
|
-
const HYBRIDLY_HEADER = "x-
|
|
15
|
+
const HYBRIDLY_HEADER = "x-hybrid";
|
|
16
16
|
const EXTERNAL_VISIT_HEADER = `${HYBRIDLY_HEADER}-external`;
|
|
17
17
|
const PARTIAL_COMPONENT_HEADER = `${HYBRIDLY_HEADER}-partial-component`;
|
|
18
18
|
const ONLY_DATA_HEADER = `${HYBRIDLY_HEADER}-only-data`;
|
|
@@ -36,7 +36,7 @@ const constants = {
|
|
|
36
36
|
SCROLL_REGION_ATTRIBUTE: SCROLL_REGION_ATTRIBUTE
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
class
|
|
39
|
+
class NotAHybridResponseError extends Error {
|
|
40
40
|
constructor(response) {
|
|
41
41
|
super();
|
|
42
42
|
this.response = response;
|
|
@@ -449,10 +449,10 @@ async function visit(options) {
|
|
|
449
449
|
});
|
|
450
450
|
return { response };
|
|
451
451
|
}
|
|
452
|
-
if (!
|
|
453
|
-
throw new
|
|
452
|
+
if (!isHybridResponse(response)) {
|
|
453
|
+
throw new NotAHybridResponseError(response);
|
|
454
454
|
}
|
|
455
|
-
utils.debug.router("The response respects the
|
|
455
|
+
utils.debug.router("The response respects the Hybridly protocol.");
|
|
456
456
|
const payload = response.data;
|
|
457
457
|
if ((options.only?.length ?? options.except?.length) && payload.view.name === context.view.name) {
|
|
458
458
|
utils.debug.router(`Merging ${options.only ? '"only"' : '"except"'} properties.`, payload.view.properties);
|
|
@@ -533,7 +533,7 @@ async function visit(options) {
|
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
|
-
function
|
|
536
|
+
function isHybridResponse(response) {
|
|
537
537
|
return !!response?.headers[HYBRIDLY_HEADER];
|
|
538
538
|
}
|
|
539
539
|
async function navigate(options) {
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ interface Hooks {
|
|
|
33
33
|
*/
|
|
34
34
|
abort: (context: InternalRouterContext) => MaybePromise<any>;
|
|
35
35
|
/**
|
|
36
|
-
* Called when a response to a request is not a valid
|
|
36
|
+
* Called when a response to a request is not a valid hybrid response.
|
|
37
37
|
*/
|
|
38
38
|
invalid: (response: AxiosResponse) => MaybePromise<void>;
|
|
39
39
|
/**
|
|
@@ -310,7 +310,7 @@ interface Errors {
|
|
|
310
310
|
* The hybridly router.
|
|
311
311
|
* This is the core function that you can use to navigate in
|
|
312
312
|
* your application. Make sure the routes you call return a
|
|
313
|
-
*
|
|
313
|
+
* hybrid response, otherwise you need to call `external`.
|
|
314
314
|
*
|
|
315
315
|
* @example
|
|
316
316
|
* router.get('/posts/edit', { post })
|
|
@@ -329,7 +329,7 @@ interface Authorizable<Authorizations extends Record<string, boolean>> {
|
|
|
329
329
|
declare function can<Authorizations extends Record<string, boolean>, Data extends Authorizable<Authorizations>, Action extends keyof Data['authorization']>(resource: Data, action: Action): Authorizations[Action];
|
|
330
330
|
|
|
331
331
|
declare const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
332
|
-
declare const HYBRIDLY_HEADER = "x-
|
|
332
|
+
declare const HYBRIDLY_HEADER = "x-hybrid";
|
|
333
333
|
declare const EXTERNAL_VISIT_HEADER: string;
|
|
334
334
|
declare const PARTIAL_COMPONENT_HEADER: string;
|
|
335
335
|
declare const ONLY_DATA_HEADER: string;
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import qs from 'qs';
|
|
|
3
3
|
import { debug, debounce, random, hasFiles, objectToFormData, when, merge, match, showResponseErrorModal } from '@hybridly/utils';
|
|
4
4
|
|
|
5
5
|
const STORAGE_EXTERNAL_KEY = "hybridly:external";
|
|
6
|
-
const HYBRIDLY_HEADER = "x-
|
|
6
|
+
const HYBRIDLY_HEADER = "x-hybrid";
|
|
7
7
|
const EXTERNAL_VISIT_HEADER = `${HYBRIDLY_HEADER}-external`;
|
|
8
8
|
const PARTIAL_COMPONENT_HEADER = `${HYBRIDLY_HEADER}-partial-component`;
|
|
9
9
|
const ONLY_DATA_HEADER = `${HYBRIDLY_HEADER}-only-data`;
|
|
@@ -27,7 +27,7 @@ const constants = {
|
|
|
27
27
|
SCROLL_REGION_ATTRIBUTE: SCROLL_REGION_ATTRIBUTE
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
class
|
|
30
|
+
class NotAHybridResponseError extends Error {
|
|
31
31
|
constructor(response) {
|
|
32
32
|
super();
|
|
33
33
|
this.response = response;
|
|
@@ -440,10 +440,10 @@ async function visit(options) {
|
|
|
440
440
|
});
|
|
441
441
|
return { response };
|
|
442
442
|
}
|
|
443
|
-
if (!
|
|
444
|
-
throw new
|
|
443
|
+
if (!isHybridResponse(response)) {
|
|
444
|
+
throw new NotAHybridResponseError(response);
|
|
445
445
|
}
|
|
446
|
-
debug.router("The response respects the
|
|
446
|
+
debug.router("The response respects the Hybridly protocol.");
|
|
447
447
|
const payload = response.data;
|
|
448
448
|
if ((options.only?.length ?? options.except?.length) && payload.view.name === context.view.name) {
|
|
449
449
|
debug.router(`Merging ${options.only ? '"only"' : '"except"'} properties.`, payload.view.properties);
|
|
@@ -524,7 +524,7 @@ async function visit(options) {
|
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
|
-
function
|
|
527
|
+
function isHybridResponse(response) {
|
|
528
528
|
return !!response?.headers[HYBRIDLY_HEADER];
|
|
529
529
|
}
|
|
530
530
|
async function navigate(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.5",
|
|
4
4
|
"description": "A solution to develop server-driven, client-rendered applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hybridly",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"axios": "^1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@hybridly/utils": "0.0.1-alpha.
|
|
39
|
+
"@hybridly/utils": "0.0.1-alpha.5",
|
|
40
40
|
"qs": "^6.11.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"axios": "^1.1.
|
|
43
|
+
"axios": "^1.1.3",
|
|
44
44
|
"defu": "^6.1.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|