@owlmeans/route 0.1.18-rc.9 → 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.
Files changed (61) hide show
  1. package/README.md +217 -70
  2. package/agent-meta/manifest.json +3 -3
  3. package/agent-meta/skills/route/SKILL.md +15 -17
  4. package/build/consts.d.ts +2 -3
  5. package/build/consts.d.ts.map +1 -1
  6. package/build/consts.js +1 -2
  7. package/build/consts.js.map +1 -1
  8. package/build/helper.d.ts +0 -6
  9. package/build/helper.d.ts.map +1 -1
  10. package/build/helper.js +0 -10
  11. package/build/helper.js.map +1 -1
  12. package/build/model.d.ts.map +1 -1
  13. package/build/model.js +4 -1
  14. package/build/model.js.map +1 -1
  15. package/build/types.d.ts +11 -14
  16. package/build/types.d.ts.map +1 -1
  17. package/build/utils/declaration/types.d.ts +9 -0
  18. package/build/utils/declaration/types.d.ts.map +1 -0
  19. package/build/utils/declaration/types.js +2 -0
  20. package/build/utils/declaration/types.js.map +1 -0
  21. package/build/utils/declaration.d.ts +4 -0
  22. package/build/utils/declaration.d.ts.map +1 -0
  23. package/build/utils/declaration.js +18 -0
  24. package/build/utils/declaration.js.map +1 -0
  25. package/build/utils/index.d.ts +4 -0
  26. package/build/utils/index.d.ts.map +1 -1
  27. package/build/utils/index.js +1 -0
  28. package/build/utils/index.js.map +1 -1
  29. package/build/utils/route/types.d.ts +35 -0
  30. package/build/utils/route/types.d.ts.map +1 -0
  31. package/build/utils/route/types.js +2 -0
  32. package/build/utils/route/types.js.map +1 -0
  33. package/build/utils/route.d.ts +5 -28
  34. package/build/utils/route.d.ts.map +1 -1
  35. package/build/utils/route.js +76 -97
  36. package/build/utils/route.js.map +1 -1
  37. package/build/utils/service/types.d.ts +9 -0
  38. package/build/utils/service/types.d.ts.map +1 -0
  39. package/build/utils/service/types.js +2 -0
  40. package/build/utils/service/types.js.map +1 -0
  41. package/build/utils/service.d.ts +3 -4
  42. package/build/utils/service.d.ts.map +1 -1
  43. package/build/utils/service.js +7 -4
  44. package/build/utils/service.js.map +1 -1
  45. package/build/utils/types.local.d.ts +9 -0
  46. package/build/utils/types.local.d.ts.map +1 -0
  47. package/build/utils/types.local.js +2 -0
  48. package/build/utils/types.local.js.map +1 -0
  49. package/package.json +3 -3
  50. package/src/consts.ts +2 -3
  51. package/src/helper.ts +0 -13
  52. package/src/model.ts +5 -2
  53. package/src/types.ts +13 -14
  54. package/src/utils/declaration/types.ts +9 -0
  55. package/src/utils/declaration.ts +24 -0
  56. package/src/utils/index.ts +4 -0
  57. package/src/utils/route/types.ts +35 -0
  58. package/src/utils/route.ts +85 -125
  59. package/src/utils/service/types.ts +9 -0
  60. package/src/utils/service.ts +12 -6
  61. package/src/utils/types.local.ts +10 -0
@@ -0,0 +1,4 @@
1
+ import type { RouteDeclarationHelper } from './declaration/types.js';
2
+ export declare const createRouteDeclarationHelper: () => RouteDeclarationHelper;
3
+ export declare const routeDeclarationHelper: RouteDeclarationHelper;
4
+ //# sourceMappingURL=declaration.d.ts.map
@@ -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"}
@@ -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"}
@@ -1,4 +1,5 @@
1
1
  export * from './types.js';
2
2
  export * from './service.js';
3
3
  export * from './route.js';
4
+ export * from './declaration.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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.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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/route/types.ts"],"names":[],"mappings":""}
@@ -1,29 +1,6 @@
1
- import type { BasicConfig, BasicContext } from '@owlmeans/context';
2
- import type { RouteAddress, RouteDeclaration, ResolvedServiceRoute } from '../types.js';
3
- type Config = BasicConfig;
4
- export declare const getParentRoute: <C extends Config, T extends BasicContext<C>>(context: T, route: RouteDeclaration) => RouteDeclaration | null;
5
- export declare const overrideParams: (route: RouteDeclaration, overrides?: Partial<RouteDeclaration>, filter?: string[]) => void;
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":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAc,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAkC,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAKvH,KAAK,MAAM,GAAG,WAAW,CAAA;AAWzB,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAC/D,CAAC,SAAS,gBAAgB,KAClC,gBAAgB,GAAG,IAWrB,CAAA;AAED,eAAO,MAAM,cAAc,UAAW,gBAAgB,cAAc,OAAO,CAAC,gBAAgB,CAAC,WAAW,MAAM,EAAE,SAO/G,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAC/D,CAAC,SAAS,gBAAgB,KAClC,oBA4BF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAC5D,CAAC,SAAS,gBAAgB,KAClC,MASF,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAC7D,CAAC,SAAS,gBAAgB,KAClC,MAOF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAC/D,CAAC,SAAS,gBAAgB,KAClC,YAYF,CAAA;AAED,mEAAmE;AACnE,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAC7D,CAAC,SAAS,gBAAgB,KAClC,OAAyE,CAAA;AAgB5E,eAAO,MAAM,WAAW,UAAW,gBAAgB,QAAQ,MAAM,WAGvD,CAAA"}
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"}
@@ -1,104 +1,83 @@
1
- import { isServiceRoute, isServiceRouteResolved } from './service.js';
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 carrier = (context, alias) => context.entrypoint(alias);
5
- export const getParentRoute = (context, route) => {
6
- if (route.parent == null) {
7
- return null;
8
- }
9
- const parent = carrier(context, route.parent);
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
- * Pick the service route this declaration answers on: the one it names, else the default of its
26
- * app type, else the first of its app type.
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
- /** Does this route belong to the service the asking context IS? */
89
- export const isLocalRoute = (context, route) => (route.service ?? context.cfg.service) === context.cfg.service;
90
- /**
91
- * @throws {SyntaxError}
92
- */
93
- const assertCycle = (context, route, parent) => {
94
- while (parent.parent != null) {
95
- if (parent.parent === route.alias) {
96
- throw new SyntaxError(`Route parentship cycle detected. Parent: ${parent.alias} has his child as ancestor ${route.alias}`);
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
- parent = carrier(context, parent.parent).route.route;
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 prependBase = (route, path) => route.base != null && route.base.trim() !== ''
102
- ? SEP + normalizePath(route.base) + SEP + normalizePath(path)
103
- : path;
82
+ export const routeAddressOf = memoHelper.oncePer(makeRouteAddressHelper);
104
83
  //# sourceMappingURL=route.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/utils/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,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C,MAAM,EAAE,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI;YACpF,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,cAAc,CAAC,GAAG;SAC/C,CAAA;IACH,CAAC,CAAA;IAED,MAAM,YAAY,GAAG,CAAC,KAAuB,EAAW,EAAE,CACxD,CAAC,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,OAAO,CAAA;IAEhE;;OAEG;IACH,MAAM,WAAW,GAAG,CAAC,KAAuB,EAAE,MAAwB,EAAQ,EAAE;QAC9E,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClC,MAAM,IAAI,WAAW,CAAC,4CAA4C,MAAM,CAAC,KAAK,8BAA8B,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;YAC5H,CAAC;YACD,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAA;QAC7C,CAAC;IACH,CAAC,CAAA;IAED,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/service/types.ts"],"names":[],"mappings":""}
@@ -1,5 +1,4 @@
1
- import type { ResolvedServiceRoute, CommonServiceRoute } from '../types.js';
2
- export declare const isServiceRoute: (obj?: Object) => obj is CommonServiceRoute;
3
- /** A service route is usable exactly when it knows the host it answers on. */
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":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE3E,eAAO,MAAM,cAAc,SAAU,MAAM,KAAG,GAAG,IAAI,kBAEM,CAAA;AAE3D,8EAA8E;AAC9E,eAAO,MAAM,sBAAsB,UAAW,kBAAkB,KAAG,KAAK,IAAI,oBAC5B,CAAA"}
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"}
@@ -1,6 +1,9 @@
1
1
  import { AppType } from '@owlmeans/context';
2
- export const isServiceRoute = (obj) => obj != null && ('type' in obj) && ('service' in obj)
3
- && (Object.values(AppType).includes(obj.type));
4
- /** A service route is usable exactly when it knows the host it answers on. */
5
- export const isServiceRouteResolved = (route) => route.host != null && route.host.trim() !== '';
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;AAG3C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAY,EAA6B,EAAE,CACxE,GAAG,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC;OACjD,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAe,CAAC,CAAC,CAAA;AAE3D,8EAA8E;AAC9E,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAyB,EAAiC,EAAE,CACjG,KAAK,CAAC,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.local.js.map
@@ -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-rc.9",
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-rc.8"
31
+ "@owlmeans/context": "^0.1.18"
32
32
  },
33
33
  "devDependencies": {
34
- "@owlmeans/dep-config": "workspace:*",
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 whether an HTTP request, a socket frame or a queued job did the work.
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
- ...(typeof opts === 'string' ? { parent: opts } : opts)
14
+ ...rest,
15
+ ...(parent == null ? {} : { parent: typeof parent === 'string' ? parent : parent.alias }),
13
16
  }
14
17
 
15
18
  return route
package/src/types.ts CHANGED
@@ -1,6 +1,9 @@
1
- import type { AppType } from '@owlmeans/context'
1
+ import type { AppType, EntrypointReference } from '@owlmeans/context'
2
2
  import type { RouteProtocols, RouteMethod } from './consts'
3
3
 
4
+ /** A built-in or package-owned transport identifier. */
5
+ export type RouteProtocol = RouteProtocols | (string & {})
6
+
4
7
  export interface BasicRoute {
5
8
  type: AppType
6
9
  service?: string
@@ -22,18 +25,10 @@ export interface RouteDeclaration extends BasicRoute {
22
25
  parent?: string
23
26
  default?: boolean
24
27
  method?: RouteMethod
25
- protocol?: RouteProtocols
28
+ protocol?: RouteProtocol
26
29
  secure?: boolean
27
- /**
28
- * QUEUE routes only: the queue that carries this entrypoint's jobs. It names an address, not a
29
- * process — which queues a given process consumes is configuration, never a declaration.
30
- */
31
- queue?: string
32
- /**
33
- * QUEUE routes only: whether the caller waits for the job's return value. `false` resolves as
34
- * soon as the job is accepted, which is what a long pipeline wants; the default is to wait.
35
- */
36
- reply?: boolean
30
+ /** Transport-owned declaration data. The package defining `protocol` owns and validates it. */
31
+ protocolOptions?: unknown
37
32
  /** How long a caller waits for an answer, in milliseconds, when the transport supports it. */
38
33
  timeout?: number
39
34
  }
@@ -54,7 +49,7 @@ export interface RouteAddress {
54
49
  port?: number
55
50
  base?: string
56
51
  secure: boolean
57
- protocol: RouteProtocols
52
+ protocol: RouteProtocol
58
53
  }
59
54
 
60
55
  /**
@@ -65,5 +60,9 @@ export interface RouteModel {
65
60
  route: RouteDeclaration
66
61
  }
67
62
 
68
- export interface RouteOptions extends Partial<RouteDeclaration> {
63
+ export type RouteParent = string | EntrypointReference
64
+
65
+ export interface RouteOptions extends Omit<Partial<RouteDeclaration>, 'parent'> {
66
+ /** A parent protocol is preferred in application declarations; strings remain adapter input. */
67
+ parent?: RouteParent
69
68
  }
@@ -0,0 +1,9 @@
1
+ import type { RouteDeclaration } from '../../types.js'
2
+
3
+ /** Context-free edits and reads of one route declaration. */
4
+ export interface RouteDeclarationHelper {
5
+ /** Fills the declaration's unset fields from `overrides`, limited to `filter` keys when given. */
6
+ overrideParams: (route: RouteDeclaration, overrides?: Partial<RouteDeclaration>, filter?: string[]) => void
7
+ /** `path` under the declaration's own `base`, when it has one. */
8
+ prependBase: (route: RouteDeclaration, path: string) => string
9
+ }
@@ -0,0 +1,24 @@
1
+ import type { RouteDeclaration } from '../types.js'
2
+ import { normalizePath } from '../helper.js'
3
+ import { SEP } from '../consts.js'
4
+ import type { RouteDeclarationHelper } from './declaration/types.js'
5
+
6
+ export const createRouteDeclarationHelper = (): RouteDeclarationHelper => {
7
+ const overrideParams = (route: RouteDeclaration, overrides?: Partial<RouteDeclaration>, filter?: string[]): void => {
8
+ Object.entries(overrides ?? {}).forEach(([key, value]) => {
9
+ if (route[key as keyof RouteDeclaration] == null
10
+ && (filter == null || filter.includes(key))) {
11
+ (route[key as keyof RouteDeclaration] as RouteDeclaration[keyof RouteDeclaration]) = value
12
+ }
13
+ })
14
+ }
15
+
16
+ const prependBase = (route: RouteDeclaration, path: string): string =>
17
+ route.base != null && route.base.trim() !== ''
18
+ ? SEP + normalizePath(route.base) + SEP + normalizePath(path)
19
+ : path
20
+
21
+ return { overrideParams, prependBase }
22
+ }
23
+
24
+ export const routeDeclarationHelper = createRouteDeclarationHelper()
@@ -1,4 +1,8 @@
1
1
 
2
2
  export * from './types.js'
3
+ export type * from './route/types.js'
4
+ export type * from './declaration/types.js'
5
+ export type * from './service/types.js'
3
6
  export * from './service.js'
4
7
  export * from './route.js'
8
+ export * from './declaration.js'