@owlmeans/route 0.1.18-rc.8 → 0.1.18
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/README.md +217 -70
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/route/SKILL.md +41 -26
- package/build/consts.d.ts +2 -3
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +1 -2
- package/build/consts.js.map +1 -1
- package/build/helper.d.ts +0 -6
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +0 -10
- package/build/helper.js.map +1 -1
- package/build/model.d.ts.map +1 -1
- package/build/model.js +4 -1
- package/build/model.js.map +1 -1
- package/build/types.d.ts +11 -14
- package/build/types.d.ts.map +1 -1
- package/build/utils/declaration/types.d.ts +9 -0
- package/build/utils/declaration/types.d.ts.map +1 -0
- package/build/utils/declaration/types.js +2 -0
- package/build/utils/declaration/types.js.map +1 -0
- package/build/utils/declaration.d.ts +4 -0
- package/build/utils/declaration.d.ts.map +1 -0
- package/build/utils/declaration.js +18 -0
- package/build/utils/declaration.js.map +1 -0
- package/build/utils/index.d.ts +4 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/route/types.d.ts +35 -0
- package/build/utils/route/types.d.ts.map +1 -0
- package/build/utils/route/types.js +2 -0
- package/build/utils/route/types.js.map +1 -0
- package/build/utils/route.d.ts +5 -28
- package/build/utils/route.d.ts.map +1 -1
- package/build/utils/route.js +76 -97
- package/build/utils/route.js.map +1 -1
- package/build/utils/service/types.d.ts +9 -0
- package/build/utils/service/types.d.ts.map +1 -0
- package/build/utils/service/types.js +2 -0
- package/build/utils/service/types.js.map +1 -0
- package/build/utils/service.d.ts +3 -4
- package/build/utils/service.d.ts.map +1 -1
- package/build/utils/service.js +7 -4
- package/build/utils/service.js.map +1 -1
- package/build/utils/types.local.d.ts +9 -0
- package/build/utils/types.local.d.ts.map +1 -0
- package/build/utils/types.local.js +2 -0
- package/build/utils/types.local.js.map +1 -0
- package/package.json +3 -3
- package/src/consts.ts +2 -3
- package/src/helper.ts +0 -13
- package/src/model.ts +5 -2
- package/src/types.ts +13 -14
- package/src/utils/declaration/types.ts +9 -0
- package/src/utils/declaration.ts +24 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/route/types.ts +35 -0
- package/src/utils/route.ts +85 -125
- package/src/utils/service/types.ts +9 -0
- package/src/utils/service.ts +12 -6
- package/src/utils/types.local.ts +10 -0
package/build/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { AppType } from '@owlmeans/context';
|
|
1
|
+
import type { AppType, EntrypointReference } from '@owlmeans/context';
|
|
2
2
|
import type { RouteProtocols, RouteMethod } from './consts';
|
|
3
|
+
/** A built-in or package-owned transport identifier. */
|
|
4
|
+
export type RouteProtocol = RouteProtocols | (string & {});
|
|
3
5
|
export interface BasicRoute {
|
|
4
6
|
type: AppType;
|
|
5
7
|
service?: string;
|
|
@@ -20,18 +22,10 @@ export interface RouteDeclaration extends BasicRoute {
|
|
|
20
22
|
parent?: string;
|
|
21
23
|
default?: boolean;
|
|
22
24
|
method?: RouteMethod;
|
|
23
|
-
protocol?:
|
|
25
|
+
protocol?: RouteProtocol;
|
|
24
26
|
secure?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
* process — which queues a given process consumes is configuration, never a declaration.
|
|
28
|
-
*/
|
|
29
|
-
queue?: string;
|
|
30
|
-
/**
|
|
31
|
-
* QUEUE routes only: whether the caller waits for the job's return value. `false` resolves as
|
|
32
|
-
* soon as the job is accepted, which is what a long pipeline wants; the default is to wait.
|
|
33
|
-
*/
|
|
34
|
-
reply?: boolean;
|
|
27
|
+
/** Transport-owned declaration data. The package defining `protocol` owns and validates it. */
|
|
28
|
+
protocolOptions?: unknown;
|
|
35
29
|
/** How long a caller waits for an answer, in milliseconds, when the transport supports it. */
|
|
36
30
|
timeout?: number;
|
|
37
31
|
}
|
|
@@ -49,7 +43,7 @@ export interface RouteAddress {
|
|
|
49
43
|
port?: number;
|
|
50
44
|
base?: string;
|
|
51
45
|
secure: boolean;
|
|
52
|
-
protocol:
|
|
46
|
+
protocol: RouteProtocol;
|
|
53
47
|
}
|
|
54
48
|
/**
|
|
55
49
|
* The model wrapping a declaration. It carries no resolution state of its own — every address
|
|
@@ -58,6 +52,9 @@ export interface RouteAddress {
|
|
|
58
52
|
export interface RouteModel {
|
|
59
53
|
route: RouteDeclaration;
|
|
60
54
|
}
|
|
61
|
-
export
|
|
55
|
+
export type RouteParent = string | EntrypointReference;
|
|
56
|
+
export interface RouteOptions extends Omit<Partial<RouteDeclaration>, 'parent'> {
|
|
57
|
+
/** A parent protocol is preferred in application declarations; strings remain adapter input. */
|
|
58
|
+
parent?: RouteParent;
|
|
62
59
|
}
|
|
63
60
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3D,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAE1D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY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../types.js';
|
|
2
|
+
/** Context-free edits and reads of one route declaration. */
|
|
3
|
+
export interface RouteDeclarationHelper {
|
|
4
|
+
/** Fills the declaration's unset fields from `overrides`, limited to `filter` keys when given. */
|
|
5
|
+
overrideParams: (route: RouteDeclaration, overrides?: Partial<RouteDeclaration>, filter?: string[]) => void;
|
|
6
|
+
/** `path` under the declaration's own `base`, when it has one. */
|
|
7
|
+
prependBase: (route: RouteDeclaration, path: string) => string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/declaration/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,6DAA6D;AAC7D,MAAM,WAAW,sBAAsB;IACrC,kGAAkG;IAClG,cAAc,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC3G,kEAAkE;IAClE,WAAW,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CAC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/declaration/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../src/utils/declaration.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAEpE,eAAO,MAAM,4BAA4B,QAAO,sBAgB/C,CAAA;AAED,eAAO,MAAM,sBAAsB,wBAAiC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizePath } from '../helper.js';
|
|
2
|
+
import { SEP } from '../consts.js';
|
|
3
|
+
export const createRouteDeclarationHelper = () => {
|
|
4
|
+
const overrideParams = (route, overrides, filter) => {
|
|
5
|
+
Object.entries(overrides ?? {}).forEach(([key, value]) => {
|
|
6
|
+
if (route[key] == null
|
|
7
|
+
&& (filter == null || filter.includes(key))) {
|
|
8
|
+
route[key] = value;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const prependBase = (route, path) => route.base != null && route.base.trim() !== ''
|
|
13
|
+
? SEP + normalizePath(route.base) + SEP + normalizePath(path)
|
|
14
|
+
: path;
|
|
15
|
+
return { overrideParams, prependBase };
|
|
16
|
+
};
|
|
17
|
+
export const routeDeclarationHelper = createRouteDeclarationHelper();
|
|
18
|
+
//# sourceMappingURL=declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.js","sourceRoot":"","sources":["../../src/utils/declaration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAGlC,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAA2B,EAAE;IACvE,MAAM,cAAc,GAAG,CAAC,KAAuB,EAAE,SAAqC,EAAE,MAAiB,EAAQ,EAAE;QACjH,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACvD,IAAI,KAAK,CAAC,GAA6B,CAAC,IAAI,IAAI;mBAC3C,CAAC,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC7C,KAAK,CAAC,GAA6B,CAA8C,GAAG,KAAK,CAAA;YAC5F,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,WAAW,GAAG,CAAC,KAAuB,EAAE,IAAY,EAAU,EAAE,CACpE,KAAK,CAAC,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;QAC5C,CAAC,CAAC,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC;QAC7D,CAAC,CAAC,IAAI,CAAA;IAEV,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,CAAA;AACxC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,4BAA4B,EAAE,CAAA"}
|
package/build/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
+
export type * from './route/types.js';
|
|
3
|
+
export type * from './declaration/types.js';
|
|
4
|
+
export type * from './service/types.js';
|
|
2
5
|
export * from './service.js';
|
|
3
6
|
export * from './route.js';
|
|
7
|
+
export * from './declaration.js';
|
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,mBAAmB,kBAAkB,CAAA;AACrC,mBAAmB,wBAAwB,CAAA;AAC3C,mBAAmB,oBAAoB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA"}
|
package/build/utils/index.js
CHANGED
package/build/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAI1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RouteAddress, RouteDeclaration, ResolvedServiceRoute } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Where routes answer, worked out on demand against the context that asks — a declaration states
|
|
4
|
+
* only what it contributes and every address question walks the parent chain through the context.
|
|
5
|
+
*/
|
|
6
|
+
export interface RouteAddressHelper {
|
|
7
|
+
/**
|
|
8
|
+
* The declaration of the route's parent entrypoint, or `null` for a root route.
|
|
9
|
+
*
|
|
10
|
+
* @throws {SyntaxError} when the parent provides no route or the parent chain is a cycle
|
|
11
|
+
*/
|
|
12
|
+
getParentRoute: (route: RouteDeclaration) => RouteDeclaration | null;
|
|
13
|
+
/**
|
|
14
|
+
* Pick the service route this declaration answers on: the one it names, else the default of its
|
|
15
|
+
* app type, else the first of its app type.
|
|
16
|
+
*
|
|
17
|
+
* @throws {SyntaxError}
|
|
18
|
+
*/
|
|
19
|
+
resolveService: (route: RouteDeclaration) => ResolvedServiceRoute;
|
|
20
|
+
/**
|
|
21
|
+
* The full path: every ancestor's declared segment, then this one. Walks the parent chain through
|
|
22
|
+
* the context, so a declaration always states only what it contributes.
|
|
23
|
+
*/
|
|
24
|
+
resolvePath: (route: RouteDeclaration) => string;
|
|
25
|
+
/** `base` + the full path — what a server mounts and a client requests. */
|
|
26
|
+
resolveMount: (route: RouteDeclaration) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Where the route answers. A backend caller reaching a service over its INTERNAL host is inside the
|
|
29
|
+
* cluster, so that hop is never TLS.
|
|
30
|
+
*/
|
|
31
|
+
resolveAddress: (route: RouteDeclaration) => RouteAddress;
|
|
32
|
+
/** Does this route belong to the service the asking context IS? */
|
|
33
|
+
isLocalRoute: (route: RouteDeclaration) => boolean;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/route/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAE1F;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,cAAc,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,gBAAgB,GAAG,IAAI,CAAA;IACpE;;;;;OAKG;IACH,cAAc,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,oBAAoB,CAAA;IACjE;;;OAGG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,MAAM,CAAA;IAChD,2EAA2E;IAC3E,YAAY,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,MAAM,CAAA;IACjD;;;OAGG;IACH,cAAc,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,YAAY,CAAA;IACzD,mEAAmE;IACnE,YAAY,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAA;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/route/types.ts"],"names":[],"mappings":""}
|
package/build/utils/route.d.ts
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
type
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
/**
|
|
7
|
-
* Pick the service route this declaration answers on: the one it names, else the default of its
|
|
8
|
-
* app type, else the first of its app type.
|
|
9
|
-
*
|
|
10
|
-
* @throws {SyntaxError}
|
|
11
|
-
*/
|
|
12
|
-
export declare const resolveService: <C extends Config, T extends BasicContext<C>>(context: T, route: RouteDeclaration) => ResolvedServiceRoute;
|
|
13
|
-
/**
|
|
14
|
-
* The full path: every ancestor's declared segment, then this one. Walks the parent chain through
|
|
15
|
-
* the context, so a declaration always states only what it contributes.
|
|
16
|
-
*/
|
|
17
|
-
export declare const resolvePath: <C extends Config, T extends BasicContext<C>>(context: T, route: RouteDeclaration) => string;
|
|
18
|
-
/** `base` + the full path — what a server mounts and a client requests. */
|
|
19
|
-
export declare const resolveMount: <C extends Config, T extends BasicContext<C>>(context: T, route: RouteDeclaration) => string;
|
|
20
|
-
/**
|
|
21
|
-
* Where the route answers. A backend caller reaching a service over its INTERNAL host is inside the
|
|
22
|
-
* cluster, so that hop is never TLS.
|
|
23
|
-
*/
|
|
24
|
-
export declare const resolveAddress: <C extends Config, T extends BasicContext<C>>(context: T, route: RouteDeclaration) => RouteAddress;
|
|
25
|
-
/** Does this route belong to the service the asking context IS? */
|
|
26
|
-
export declare const isLocalRoute: <C extends Config, T extends BasicContext<C>>(context: T, route: RouteDeclaration) => boolean;
|
|
27
|
-
export declare const prependBase: (route: RouteDeclaration, path: string) => string;
|
|
28
|
-
export {};
|
|
1
|
+
import type { BasicContext } from '@owlmeans/context';
|
|
2
|
+
import type { Config } from './types.local.js';
|
|
3
|
+
import type { RouteAddressHelper } from './route/types.js';
|
|
4
|
+
export declare const makeRouteAddressHelper: <C extends Config, T extends BasicContext<C>>(context: T) => RouteAddressHelper;
|
|
5
|
+
export declare const routeAddressOf: <C extends Config, T extends BasicContext<C>>(target: T) => RouteAddressHelper;
|
|
29
6
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/utils/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/utils/route.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAKrD,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,kBAAkB,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE1D,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,KAAG,kBAmGhG,CAAA;AAED,eAAO,MAAM,cAAc,GArGY,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,kCAqGV,CAAA"}
|
package/build/utils/route.js
CHANGED
|
@@ -1,104 +1,83 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { memoHelper } from '@owlmeans/context';
|
|
2
|
+
import { serviceRouteHelper } from './service.js';
|
|
2
3
|
import { normalizePath } from '../helper.js';
|
|
3
4
|
import { RouteProtocols, SEP } from '../consts.js';
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (parent.route == null) {
|
|
11
|
-
throw new SyntaxError('Parent entrypoint doesn\'t provide a route');
|
|
12
|
-
}
|
|
13
|
-
assertCycle(context, route, parent.route.route);
|
|
14
|
-
return parent.route.route;
|
|
15
|
-
};
|
|
16
|
-
export const overrideParams = (route, overrides, filter) => {
|
|
17
|
-
Object.entries(overrides ?? {}).forEach(([key, value]) => {
|
|
18
|
-
if (route[key] == null
|
|
19
|
-
&& (filter == null || filter.includes(key))) {
|
|
20
|
-
route[key] = value;
|
|
5
|
+
export const makeRouteAddressHelper = (context) => {
|
|
6
|
+
const { isServiceRoute, isServiceRouteResolved } = serviceRouteHelper;
|
|
7
|
+
const carrier = (alias) => context.entrypoint(alias);
|
|
8
|
+
const getParentRoute = (route) => {
|
|
9
|
+
if (route.parent == null) {
|
|
10
|
+
return null;
|
|
21
11
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @throws {SyntaxError}
|
|
29
|
-
*/
|
|
30
|
-
export const resolveService = (context, route) => {
|
|
31
|
-
if (context.cfg.services == null) {
|
|
32
|
-
throw new SyntaxError('Services aren\'t configured to resolve routes');
|
|
33
|
-
}
|
|
34
|
-
const named = context.cfg.services[route.service ?? context.cfg.service];
|
|
35
|
-
if (named != null && !isServiceRoute(named)) {
|
|
36
|
-
throw new SyntaxError('Service is not a valid service route');
|
|
37
|
-
}
|
|
38
|
-
const service = named?.type === route.type ? named
|
|
39
|
-
: Object.values(context.cfg.services).find((candidate) => {
|
|
40
|
-
const _candidate = candidate;
|
|
41
|
-
return _candidate.default === true && _candidate.type === route.type;
|
|
42
|
-
}) ?? Object.values(context.cfg.services).find((candidate) => candidate.type === route.type);
|
|
43
|
-
if (!isServiceRoute(service)) {
|
|
44
|
-
throw new SyntaxError('Service is not a valid service route');
|
|
45
|
-
}
|
|
46
|
-
if (!isServiceRouteResolved(service)) {
|
|
47
|
-
throw new SyntaxError('Service route is not resolved');
|
|
48
|
-
}
|
|
49
|
-
return service;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* The full path: every ancestor's declared segment, then this one. Walks the parent chain through
|
|
53
|
-
* the context, so a declaration always states only what it contributes.
|
|
54
|
-
*/
|
|
55
|
-
export const resolvePath = (context, route) => {
|
|
56
|
-
const parent = getParentRoute(context, route);
|
|
57
|
-
if (parent == null) {
|
|
58
|
-
return route.path;
|
|
59
|
-
}
|
|
60
|
-
const parentPath = resolvePath(context, parent);
|
|
61
|
-
return (parentPath.startsWith(SEP) ? SEP : '')
|
|
62
|
-
+ normalizePath(normalizePath(parentPath) + SEP + normalizePath(route.path));
|
|
63
|
-
};
|
|
64
|
-
/** `base` + the full path — what a server mounts and a client requests. */
|
|
65
|
-
export const resolveMount = (context, route) => {
|
|
66
|
-
const path = resolvePath(context, route);
|
|
67
|
-
const base = route.base ?? resolveService(context, route).base;
|
|
68
|
-
return base != null && base.trim() !== ''
|
|
69
|
-
? SEP + normalizePath(base) + SEP + normalizePath(path)
|
|
70
|
-
: path;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Where the route answers. A backend caller reaching a service over its INTERNAL host is inside the
|
|
74
|
-
* cluster, so that hop is never TLS.
|
|
75
|
-
*/
|
|
76
|
-
export const resolveAddress = (context, route) => {
|
|
77
|
-
const service = resolveService(context, route);
|
|
78
|
-
const host = route.host ?? service.host;
|
|
79
|
-
const internalHost = route.internalHost ?? service.internalHost;
|
|
80
|
-
return {
|
|
81
|
-
host,
|
|
82
|
-
port: route.port ?? service.port,
|
|
83
|
-
base: route.base ?? service.base,
|
|
84
|
-
secure: internalHost != null && internalHost === host ? false : route.secure ?? true,
|
|
85
|
-
protocol: route.protocol ?? RouteProtocols.WEB,
|
|
12
|
+
const parent = carrier(route.parent);
|
|
13
|
+
if (parent.route == null) {
|
|
14
|
+
throw new SyntaxError('Parent entrypoint doesn\'t provide a route');
|
|
15
|
+
}
|
|
16
|
+
assertCycle(route, parent.route.route);
|
|
17
|
+
return parent.route.route;
|
|
86
18
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
19
|
+
const resolveService = (route) => {
|
|
20
|
+
if (context.cfg.services == null) {
|
|
21
|
+
throw new SyntaxError('Services aren\'t configured to resolve routes');
|
|
22
|
+
}
|
|
23
|
+
const named = context.cfg.services[route.service ?? context.cfg.service];
|
|
24
|
+
if (named != null && !isServiceRoute(named)) {
|
|
25
|
+
throw new SyntaxError('Service is not a valid service route');
|
|
26
|
+
}
|
|
27
|
+
const service = named?.type === route.type ? named
|
|
28
|
+
: Object.values(context.cfg.services).find((candidate) => {
|
|
29
|
+
const _candidate = candidate;
|
|
30
|
+
return _candidate.default === true && _candidate.type === route.type;
|
|
31
|
+
}) ?? Object.values(context.cfg.services).find((candidate) => candidate.type === route.type);
|
|
32
|
+
if (!isServiceRoute(service)) {
|
|
33
|
+
throw new SyntaxError('Service is not a valid service route');
|
|
97
34
|
}
|
|
98
|
-
|
|
99
|
-
|
|
35
|
+
if (!isServiceRouteResolved(service)) {
|
|
36
|
+
throw new SyntaxError('Service route is not resolved');
|
|
37
|
+
}
|
|
38
|
+
return service;
|
|
39
|
+
};
|
|
40
|
+
const resolvePath = (route) => {
|
|
41
|
+
const parent = getParentRoute(route);
|
|
42
|
+
if (parent == null) {
|
|
43
|
+
return route.path;
|
|
44
|
+
}
|
|
45
|
+
const parentPath = resolvePath(parent);
|
|
46
|
+
return (parentPath.startsWith(SEP) ? SEP : '')
|
|
47
|
+
+ normalizePath(normalizePath(parentPath) + SEP + normalizePath(route.path));
|
|
48
|
+
};
|
|
49
|
+
const resolveMount = (route) => {
|
|
50
|
+
const path = resolvePath(route);
|
|
51
|
+
const base = route.base ?? resolveService(route).base;
|
|
52
|
+
return base != null && base.trim() !== ''
|
|
53
|
+
? SEP + normalizePath(base) + SEP + normalizePath(path)
|
|
54
|
+
: path;
|
|
55
|
+
};
|
|
56
|
+
const resolveAddress = (route) => {
|
|
57
|
+
const service = resolveService(route);
|
|
58
|
+
const host = route.host ?? service.host;
|
|
59
|
+
const internalHost = route.internalHost ?? service.internalHost;
|
|
60
|
+
return {
|
|
61
|
+
host,
|
|
62
|
+
port: route.port ?? service.port,
|
|
63
|
+
base: route.base ?? service.base,
|
|
64
|
+
secure: internalHost != null && internalHost === host ? false : route.secure ?? true,
|
|
65
|
+
protocol: route.protocol ?? RouteProtocols.WEB,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const isLocalRoute = (route) => (route.service ?? context.cfg.service) === context.cfg.service;
|
|
69
|
+
/**
|
|
70
|
+
* @throws {SyntaxError}
|
|
71
|
+
*/
|
|
72
|
+
const assertCycle = (route, parent) => {
|
|
73
|
+
while (parent.parent != null) {
|
|
74
|
+
if (parent.parent === route.alias) {
|
|
75
|
+
throw new SyntaxError(`Route parentship cycle detected. Parent: ${parent.alias} has his child as ancestor ${route.alias}`);
|
|
76
|
+
}
|
|
77
|
+
parent = carrier(parent.parent).route.route;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return { getParentRoute, resolveService, resolvePath, resolveMount, resolveAddress, isLocalRoute };
|
|
100
81
|
};
|
|
101
|
-
export const
|
|
102
|
-
? SEP + normalizePath(route.base) + SEP + normalizePath(path)
|
|
103
|
-
: path;
|
|
82
|
+
export const routeAddressOf = memoHelper.oncePer(makeRouteAddressHelper);
|
|
104
83
|
//# sourceMappingURL=route.js.map
|
package/build/utils/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/utils/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/utils/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAIlD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAA8C,OAAU,EAAsB,EAAE;IACpH,MAAM,EAAE,cAAc,EAAE,sBAAsB,EAAE,GAAG,kBAAkB,CAAA;IAErE,MAAM,OAAO,GAAG,CAAC,KAAa,EAAgB,EAAE,CAC9C,OAAO,CAAC,UAAU,CAAe,KAAK,CAAC,CAAA;IAEzC,MAAM,cAAc,GAAG,CAAC,KAAuB,EAA2B,EAAE;QAC1E,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YACzB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACpC,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AY,EAAE,CAAA;AACpG,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CommonServiceRoute, ResolvedServiceRoute } from '../../types.js';
|
|
2
|
+
/** Recognizes configured service routes. */
|
|
3
|
+
export interface ServiceRouteHelper {
|
|
4
|
+
/** Whether a configured value is a service route: it names a service and a known app type. */
|
|
5
|
+
isServiceRoute: (obj?: Object) => obj is CommonServiceRoute;
|
|
6
|
+
/** A service route is usable exactly when it knows the host it answers on. */
|
|
7
|
+
isServiceRouteResolved: (route: CommonServiceRoute) => route is ResolvedServiceRoute;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/service/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAE9E,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,cAAc,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,GAAG,IAAI,kBAAkB,CAAA;IAC3D,8EAA8E;IAC9E,sBAAsB,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,KAAK,IAAI,oBAAoB,CAAA;CACrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/service/types.ts"],"names":[],"mappings":""}
|
package/build/utils/service.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
export declare const isServiceRouteResolved: (route: CommonServiceRoute) => route is ResolvedServiceRoute;
|
|
1
|
+
import type { ServiceRouteHelper } from './service/types.js';
|
|
2
|
+
export declare const createServiceRouteHelper: () => ServiceRouteHelper;
|
|
3
|
+
export declare const serviceRouteHelper: ServiceRouteHelper;
|
|
5
4
|
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/utils/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/utils/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE5D,eAAO,MAAM,wBAAwB,QAAO,kBAS3C,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAA6B,CAAA"}
|
package/build/utils/service.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { AppType } from '@owlmeans/context';
|
|
2
|
-
export const
|
|
3
|
-
&& (
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export const createServiceRouteHelper = () => {
|
|
3
|
+
const isServiceRoute = (obj) => obj != null && ('type' in obj) && ('service' in obj)
|
|
4
|
+
&& (Object.values(AppType).includes(obj.type));
|
|
5
|
+
const isServiceRouteResolved = (route) => route.host != null && route.host.trim() !== '';
|
|
6
|
+
return { isServiceRoute, isServiceRouteResolved };
|
|
7
|
+
};
|
|
8
|
+
export const serviceRouteHelper = createServiceRouteHelper();
|
|
6
9
|
//# sourceMappingURL=service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/utils/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/utils/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAI3C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAuB,EAAE;IAC/D,MAAM,cAAc,GAAG,CAAC,GAAY,EAA6B,EAAE,CACjE,GAAG,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC;WACjD,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAe,CAAC,CAAC,CAAA;IAE3D,MAAM,sBAAsB,GAAG,CAAC,KAAyB,EAAiC,EAAE,CAC1F,KAAK,CAAC,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAA;IAEhD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,CAAA;AACnD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAwB,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BasicConfig, Contextual } from '@owlmeans/context';
|
|
2
|
+
import type { RouteModel } from '../types.js';
|
|
3
|
+
export type Config = BasicConfig;
|
|
4
|
+
/** What an entrypoint looks like from the route layer: something that carries a route model. */
|
|
5
|
+
export interface RouteCarrier extends Contextual {
|
|
6
|
+
_entrypoint: true;
|
|
7
|
+
route: RouteModel;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=types.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../../src/utils/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,MAAM,MAAM,GAAG,WAAW,CAAA;AAEhC,gGAAgG;AAChG,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,WAAW,EAAE,IAAI,CAAA;IACjB,KAAK,EAAE,UAAU,CAAA;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.js","sourceRoot":"","sources":["../../src/utils/types.local.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/route",
|
|
3
|
-
"version": "0.1.18
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@owlmeans/context": "^0.1.18
|
|
31
|
+
"@owlmeans/context": "^0.1.18"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@owlmeans/dep-config": "
|
|
34
|
+
"@owlmeans/dep-config": "^0.1.18",
|
|
35
35
|
"nodemon": "^3.1.14",
|
|
36
36
|
"typescript": "^7.0.2"
|
|
37
37
|
},
|
package/src/consts.ts
CHANGED
|
@@ -14,10 +14,9 @@ export const PARAM = ':'
|
|
|
14
14
|
/**
|
|
15
15
|
* How a route is carried. The protocol picks the transport that answers it — an application binds
|
|
16
16
|
* one by registering a service under `transportAlias(protocol)` — so a caller writes `call()` and
|
|
17
|
-
* never learns
|
|
17
|
+
* never learns which transport carried the work.
|
|
18
18
|
*/
|
|
19
19
|
export enum RouteProtocols {
|
|
20
20
|
WEB = 'http',
|
|
21
|
-
SOCKET = 'ws'
|
|
22
|
-
QUEUE = 'queue'
|
|
21
|
+
SOCKET = 'ws'
|
|
23
22
|
}
|
package/src/helper.ts
CHANGED
|
@@ -43,19 +43,6 @@ export const socket = (opts?: RouteOptions | string | null, secondary?: RouteOpt
|
|
|
43
43
|
return route
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
* A backend route carried by the queue rather than by HTTP. Everything else about it is a normal
|
|
48
|
-
* backend route — it has a path, a parent, guards and a filter — so the same declaration is served
|
|
49
|
-
* with `elevate(...)` and called with `call()`; only the transport underneath differs.
|
|
50
|
-
*/
|
|
51
|
-
export const job = (opts?: RouteOptions | string | null, secondary?: RouteOptions): Partial<RouteOptions> => {
|
|
52
|
-
const route = backend(opts, secondary)
|
|
53
|
-
|
|
54
|
-
route.protocol = RouteProtocols.QUEUE
|
|
55
|
-
|
|
56
|
-
return route
|
|
57
|
-
}
|
|
58
|
-
|
|
59
46
|
export const frontend = (opts?: RouteOptions | string | null, def?: RouteOptions | boolean): Partial<RouteOptions> => {
|
|
60
47
|
if (typeof def === 'boolean') {
|
|
61
48
|
opts = typeof opts === 'string' ? { parent: opts, default: def } : { default: def, ...(opts ?? {}) }
|
package/src/model.ts
CHANGED
|
@@ -4,12 +4,15 @@ import { AppType } from '@owlmeans/context'
|
|
|
4
4
|
|
|
5
5
|
export const makeRouteModel = (route: RouteDeclaration): RouteModel => ({ route })
|
|
6
6
|
|
|
7
|
-
export const createRoute: CreateRouteSignature<RouteDeclaration> = (alias, path, opts?) => {
|
|
7
|
+
export const createRoute: CreateRouteSignature<RouteDeclaration> = (alias, path, opts?): RouteDeclaration => {
|
|
8
|
+
const options = typeof opts === 'string' ? { parent: opts } : opts
|
|
9
|
+
const { parent, ...rest } = options ?? {}
|
|
8
10
|
const route: RouteDeclaration = {
|
|
9
11
|
alias,
|
|
10
12
|
type: AppType.Backend,
|
|
11
13
|
path,
|
|
12
|
-
...
|
|
14
|
+
...rest,
|
|
15
|
+
...(parent == null ? {} : { parent: typeof parent === 'string' ? parent : parent.alias }),
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
return route
|