@rnzeus/atlas 0.1.1 → 0.1.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/hooks/use-path-navigation/hook.js +1 -1
- package/dist/services/navigation/chain-builder.js +1 -1
- package/dist/services/navigation/service.d.ts +2 -2
- package/dist/services/navigation/service.js +14 -4
- package/dist/services/transport/service.d.ts +1 -1
- package/dist/services/transport/service.js +2 -2
- package/package.json +1 -1
- package/dist/config/navigation.types.d.ts +0 -25
- package/dist/config/navigation.types.js +0 -1
- package/dist/services/navigation/zod-adapter.d.ts +0 -22
- package/dist/services/navigation/zod-adapter.js +0 -36
|
@@ -36,7 +36,7 @@ const usePathNavigation = () => {
|
|
|
36
36
|
// navigation (safe, path-based)
|
|
37
37
|
navigate: (path) => Navigation.navigate(path, navigation),
|
|
38
38
|
push: (path) => Navigation.push(path),
|
|
39
|
-
replace: (path) => Navigation.replace(path),
|
|
39
|
+
replace: (path) => Navigation.replace(path, navigation),
|
|
40
40
|
popTo: (path) => Navigation.popTo(path, navigation),
|
|
41
41
|
reset: (path) => Navigation.reset(path),
|
|
42
42
|
popToTop: () => Navigation.popToTop(navigation),
|
|
@@ -33,11 +33,11 @@ declare class NavService<T extends ParamListBase = ParamListBase> {
|
|
|
33
33
|
private buildParamsFromChain;
|
|
34
34
|
navigate: (path: BuiltPath, navigation?: NavLike) => void;
|
|
35
35
|
push: (path: BuiltPath) => void;
|
|
36
|
-
replace: (path: BuiltPath) => void;
|
|
36
|
+
replace: (path: BuiltPath, navigation?: NavLike) => void;
|
|
37
37
|
popTo: (path: BuiltPath, navigation?: NavLike) => void;
|
|
38
38
|
navigateUnsafe: (path: string, navigation?: NavLike) => void;
|
|
39
39
|
pushUnsafe: (path: string) => void;
|
|
40
|
-
replaceUnsafe: (path: string) => void;
|
|
40
|
+
replaceUnsafe: (path: string, navigation?: NavLike) => void;
|
|
41
41
|
popToTop: (navigation?: NavLike) => void;
|
|
42
42
|
popToUnsafe: (path: string, navigation?: NavLike) => void;
|
|
43
43
|
goBack: () => void;
|
|
@@ -12,8 +12,8 @@ class NavService {
|
|
|
12
12
|
this.push = (path) => {
|
|
13
13
|
this.pushUnsafe(path);
|
|
14
14
|
};
|
|
15
|
-
this.replace = (path) => {
|
|
16
|
-
this.replaceUnsafe(path);
|
|
15
|
+
this.replace = (path, navigation) => {
|
|
16
|
+
this.replaceUnsafe(path, navigation);
|
|
17
17
|
};
|
|
18
18
|
this.popTo = (path, navigation) => {
|
|
19
19
|
this.popToUnsafe(path, navigation);
|
|
@@ -66,8 +66,18 @@ class NavService {
|
|
|
66
66
|
this.pushUnsafe = (path) => {
|
|
67
67
|
this.pushOrReplace('push', path);
|
|
68
68
|
};
|
|
69
|
-
this.replaceUnsafe = (path) => {
|
|
70
|
-
this.pushOrReplace('replace', path);
|
|
69
|
+
this.replaceUnsafe = (path, navigation) => {
|
|
70
|
+
// this.pushOrReplace('replace', path);
|
|
71
|
+
if (!this.ensureRefReady() || !this.ensureLinking())
|
|
72
|
+
return;
|
|
73
|
+
const parsed = this.parsePath(path);
|
|
74
|
+
if (!parsed)
|
|
75
|
+
return;
|
|
76
|
+
if (navigation) {
|
|
77
|
+
navigation.dispatch(StackActions.replace(parsed.leaf.name, parsed.leaf.params));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.ref?.dispatch(StackActions.replace(parsed.leaf.name, parsed.leaf.params));
|
|
71
81
|
};
|
|
72
82
|
this.popToTop = (navigation) => {
|
|
73
83
|
if (navigation) {
|
|
@@ -3,7 +3,7 @@ export default abstract class Transport {
|
|
|
3
3
|
private headersDefault;
|
|
4
4
|
protected abstract get baseURL(): string;
|
|
5
5
|
protected abstract formatErrorMessage(data: unknown, status: number): string;
|
|
6
|
-
protected notify(_message: string): void;
|
|
6
|
+
protected notify(_message: string, _status?: number): void;
|
|
7
7
|
get headers(): HeadersInit_;
|
|
8
8
|
set headers(next: HeadersInit_);
|
|
9
9
|
protected request<T>(url: string, options?: TransportOptions, params?: Record<string, unknown> | null): Promise<T>;
|
|
@@ -14,7 +14,7 @@ export default class Transport {
|
|
|
14
14
|
this.put = this.transportMethods.put.bind(this.transportMethods);
|
|
15
15
|
this.delete = this.transportMethods.delete.bind(this.transportMethods);
|
|
16
16
|
}
|
|
17
|
-
notify(_message) {
|
|
17
|
+
notify(_message, _status) {
|
|
18
18
|
/* no-op */
|
|
19
19
|
}
|
|
20
20
|
get headers() {
|
|
@@ -50,7 +50,7 @@ export default class Transport {
|
|
|
50
50
|
const message = this.formatErrorMessage(responseData, response.status);
|
|
51
51
|
const transportErrorException = new TransportErrorException(response.status, message, responseData);
|
|
52
52
|
if (transportErrorException.isServerError()) {
|
|
53
|
-
this.notify(message);
|
|
53
|
+
this.notify(message, response.status);
|
|
54
54
|
}
|
|
55
55
|
throw transportErrorException;
|
|
56
56
|
}
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type RouteDef<P = undefined, Q = undefined> = {
|
|
2
|
-
path: string;
|
|
3
|
-
name: string;
|
|
4
|
-
linking: string;
|
|
5
|
-
key?: string;
|
|
6
|
-
__params?: P;
|
|
7
|
-
__query?: Q;
|
|
8
|
-
};
|
|
9
|
-
export type RouteParams<R> = R extends RouteDef<infer P, any> ? P : never;
|
|
10
|
-
export type RouteQuery<R> = R extends RouteDef<any, infer Q> ? Q : never;
|
|
11
|
-
export type BuiltPath<R extends RouteDef<any, any> = RouteDef<any, any>> = string & {
|
|
12
|
-
readonly __brand: 'BuiltPath';
|
|
13
|
-
readonly __route?: R;
|
|
14
|
-
};
|
|
15
|
-
export type StrictMode = 'off' | 'warn' | 'throw';
|
|
16
|
-
export type ValidationResult = {
|
|
17
|
-
ok: true;
|
|
18
|
-
} | {
|
|
19
|
-
ok: false;
|
|
20
|
-
message: string;
|
|
21
|
-
};
|
|
22
|
-
export type NavigationValidator = {
|
|
23
|
-
validateBuild?: <R extends RouteDef<any, any>>(route: R, params: unknown) => ValidationResult;
|
|
24
|
-
validateQuery?: <R extends RouteDef<any, any>>(route: R, query: unknown) => ValidationResult;
|
|
25
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { NavigationValidator, RouteDef } from '../../config/navigation.types';
|
|
2
|
-
export type SafeParseSchema<T = unknown> = {
|
|
3
|
-
safeParse: (input: unknown) => {
|
|
4
|
-
success: true;
|
|
5
|
-
data: T;
|
|
6
|
-
} | {
|
|
7
|
-
success: false;
|
|
8
|
-
error: {
|
|
9
|
-
issues?: any[];
|
|
10
|
-
message?: string;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type NavSchemaRegistry = {
|
|
15
|
-
params?: SafeParseSchema;
|
|
16
|
-
query?: SafeParseSchema;
|
|
17
|
-
};
|
|
18
|
-
export type NavSchemas = Record<string, NavSchemaRegistry>;
|
|
19
|
-
declare function createZodValidator(schemas: NavSchemas, opts?: {
|
|
20
|
-
keyOfRoute?: (r: RouteDef<any, any>) => string;
|
|
21
|
-
}): NavigationValidator;
|
|
22
|
-
export default createZodValidator;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
function issueMessage(err) {
|
|
2
|
-
const issues = err?.issues;
|
|
3
|
-
if (Array.isArray(issues) && issues.length) {
|
|
4
|
-
const first = issues[0];
|
|
5
|
-
const path = Array.isArray(first?.path) ? first.path.join('.') : '';
|
|
6
|
-
const msg = first?.message ?? 'Invalid';
|
|
7
|
-
return path ? `${path}: ${msg}` : msg;
|
|
8
|
-
}
|
|
9
|
-
return err?.message ?? 'Invalid';
|
|
10
|
-
}
|
|
11
|
-
function createZodValidator(schemas, opts) {
|
|
12
|
-
const keyOfRoute = opts?.keyOfRoute ?? (r => r.linking);
|
|
13
|
-
return {
|
|
14
|
-
validateBuild: (route, params) => {
|
|
15
|
-
const entry = schemas[keyOfRoute(route)];
|
|
16
|
-
const schema = entry?.params;
|
|
17
|
-
if (!schema)
|
|
18
|
-
return { ok: true };
|
|
19
|
-
const res = schema.safeParse(params);
|
|
20
|
-
if (res.success)
|
|
21
|
-
return { ok: true };
|
|
22
|
-
return { ok: false, message: `params invalid: ${issueMessage(res.error)}` };
|
|
23
|
-
},
|
|
24
|
-
validateQuery: (route, query) => {
|
|
25
|
-
const entry = schemas[keyOfRoute(route)];
|
|
26
|
-
const schema = entry?.query;
|
|
27
|
-
if (!schema)
|
|
28
|
-
return { ok: true };
|
|
29
|
-
const res = schema.safeParse(query);
|
|
30
|
-
if (res.success)
|
|
31
|
-
return { ok: true };
|
|
32
|
-
return { ok: false, message: `query invalid: ${issueMessage(res.error)}` };
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export default createZodValidator;
|