@owlmeans/client-entrypoint 0.1.18-rc.5 → 0.1.18-rc.50

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 (71) hide show
  1. package/README.md +170 -49
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/client-entrypoint/SKILL.md +33 -30
  4. package/build/consts.d.ts +2 -0
  5. package/build/consts.d.ts.map +1 -0
  6. package/build/consts.js +2 -0
  7. package/build/consts.js.map +1 -0
  8. package/build/entrypoint.d.ts +2 -3
  9. package/build/entrypoint.d.ts.map +1 -1
  10. package/build/entrypoint.js +27 -39
  11. package/build/entrypoint.js.map +1 -1
  12. package/build/failure.d.ts +5 -0
  13. package/build/failure.d.ts.map +1 -0
  14. package/build/failure.js +27 -0
  15. package/build/failure.js.map +1 -0
  16. package/build/helper/types.d.ts +10 -0
  17. package/build/helper/types.d.ts.map +1 -0
  18. package/build/helper/types.js +2 -0
  19. package/build/helper/types.js.map +1 -0
  20. package/build/helper.d.ts +5 -6
  21. package/build/helper.d.ts.map +1 -1
  22. package/build/helper.js +22 -34
  23. package/build/helper.js.map +1 -1
  24. package/build/index.d.ts +6 -2
  25. package/build/index.d.ts.map +1 -1
  26. package/build/index.js +5 -2
  27. package/build/index.js.map +1 -1
  28. package/build/protocol.d.ts +9 -0
  29. package/build/protocol.d.ts.map +1 -0
  30. package/build/protocol.js +15 -0
  31. package/build/protocol.js.map +1 -0
  32. package/build/stab.d.ts +4 -0
  33. package/build/stab.d.ts.map +1 -0
  34. package/build/stab.js +5 -0
  35. package/build/stab.js.map +1 -0
  36. package/build/types.d.ts +53 -9
  37. package/build/types.d.ts.map +1 -1
  38. package/build/utils/entrypoint.d.ts +2 -4
  39. package/build/utils/entrypoint.d.ts.map +1 -1
  40. package/build/utils/entrypoint.js +0 -9
  41. package/build/utils/entrypoint.js.map +1 -1
  42. package/build/utils/handler/types.d.ts +15 -0
  43. package/build/utils/handler/types.d.ts.map +1 -0
  44. package/build/utils/handler/types.js +2 -0
  45. package/build/utils/handler/types.js.map +1 -0
  46. package/build/utils/handler.d.ts +7 -5
  47. package/build/utils/handler.d.ts.map +1 -1
  48. package/build/utils/handler.js +126 -95
  49. package/build/utils/handler.js.map +1 -1
  50. package/build/utils/index.d.ts +1 -0
  51. package/build/utils/index.d.ts.map +1 -1
  52. package/build/utils/index.js.map +1 -1
  53. package/build/utils/types.local.d.ts +5 -0
  54. package/build/utils/types.local.d.ts.map +1 -0
  55. package/build/utils/types.local.js +2 -0
  56. package/build/utils/types.local.js.map +1 -0
  57. package/package.json +13 -12
  58. package/src/consts.ts +1 -0
  59. package/src/entrypoint.ts +37 -49
  60. package/src/failure.ts +26 -0
  61. package/src/helper/types.ts +10 -0
  62. package/src/helper.ts +30 -49
  63. package/src/index.ts +6 -2
  64. package/src/protocol.ts +39 -0
  65. package/src/stab.ts +6 -0
  66. package/src/types.ts +62 -11
  67. package/src/utils/entrypoint.ts +2 -17
  68. package/src/utils/handler/types.ts +15 -0
  69. package/src/utils/handler.ts +106 -77
  70. package/src/utils/index.ts +1 -0
  71. package/src/utils/types.local.ts +5 -0
package/build/helper.js CHANGED
@@ -1,37 +1,25 @@
1
- import { entrypoint } from './entrypoint.js';
2
- import { isClientRouteModel } from '@owlmeans/client-route';
3
- import { normalizeHelperParams } from './utils/entrypoint.js';
4
- export const elevate = (entrypoints, alias, handler, opts) => {
5
- [handler, opts] = normalizeHelperParams(handler, opts);
6
- const idx = entrypoints.findIndex(({ route }) => route.route.alias === alias);
7
- if (idx === -1) {
8
- throw new SyntaxError(`Entrypoint with alias ${alias} not present`);
9
- }
10
- if (isClientRouteModel(entrypoints[idx].route) && opts?.force !== true) {
11
- throw new SyntaxError(`Entrypoint with alias ${alias} is already elevated`);
12
- }
13
- entrypoints[idx] = entrypoint(entrypoints[idx], handler, opts);
14
- return entrypoints;
15
- };
16
- export const stab = () => () => {
17
- return void 0;
18
- };
19
- export const provideRequest = (alias, path) => {
20
- const request = {
21
- alias,
22
- params: {},
23
- headers: {},
24
- query: {},
25
- path,
26
- canceled: false,
27
- cancel: () => request.canceled = true
1
+ export const createClientRequestHelper = () => {
2
+ const provideRequest = (alias, path) => {
3
+ const request = {
4
+ alias,
5
+ params: {},
6
+ headers: {},
7
+ query: {},
8
+ path,
9
+ canceled: false,
10
+ cancel: () => request.canceled = true
11
+ };
12
+ return request;
28
13
  };
29
- return request;
14
+ const pickPerSchema = (object, schema) => Object.keys(schema.properties).reduce((acc, key) => {
15
+ if (object[key] != null) {
16
+ acc[key] = object[key];
17
+ }
18
+ return acc;
19
+ }, {});
20
+ return { provideRequest, pickPerSchema };
30
21
  };
31
- export const pickPerSchema = (object, schema) => Object.keys(schema.properties).reduce((acc, key) => {
32
- if (object[key] != null) {
33
- acc[key] = object[key];
34
- }
35
- return acc;
36
- }, {});
22
+ export const clientRequestHelper = createClientRequestHelper();
23
+ /** @deprecated compat:factory-refactor — use `clientRequestHelper.provideRequest(…)` */
24
+ export const provideRequest = (alias, path) => clientRequestHelper.provideRequest(alias, path);
37
25
  //# sourceMappingURL=helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,WAA0D,EAC1D,KAAa,EACb,OAA0E,EAC1E,IAAwC,EACd,EAAE;IAC5B,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAEtD,MAAM,GAAG,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK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0B,CAAA;IACvE,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,EAAE,EAAgB,CACpB,CAAA"}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAwB,EAAE;IACjE,MAAM,cAAc,GAAG,CAAoB,KAAa,EAAE,IAAY,EAAsB,EAAE;QAC5F,MAAM,OAAO,GAAG;YACd,KAAK;YACL,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,EAAE;YACT,IAAI;YACJ,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,GAAG,IAAI;SACtC,CAAA;QAED,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;IAED,MAAM,aAAa,GAAG,CAAO,MAAS,EAAE,MAAyB,EAAc,EAAE,CAC/E,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CACnC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,IAAI,MAAM,CAAC,GAAc,CAAC,IAAI,IAAI,EAAE,CAAC;YACnC,GAAG,CAAC,GAAc,CAAC,GAAG,MAAM,CAAC,GAAc,CAA0B,CAAA;QACvE,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAgB,CACpB,CAAA;IAEH,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,EAAE,CAAA;AAE9D,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAoB,KAAa,EAAE,IAAY,EAAsB,EAAE,CAAC,mBAAmB,CAAC,cAAc,CAAI,KAAK,EAAE,IAAI,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- export * from './helper.js';
2
1
  export type * from './types.js';
3
- export * from './entrypoint.js';
2
+ export type * from './helper/types.js';
4
3
  export * from './errors.js';
4
+ export * from './failure.js';
5
+ export * from './consts.js';
6
+ export * from './protocol.js';
7
+ export { clientRequestHelper, createClientRequestHelper, provideRequest } from './helper.js';
8
+ export { stab } from './stab.js';
5
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,mBAAmB,YAAY,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,mBAAmB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}
package/build/index.js CHANGED
@@ -1,4 +1,7 @@
1
- export * from './helper.js';
2
- export * from './entrypoint.js';
3
1
  export * from './errors.js';
2
+ export * from './failure.js';
3
+ export * from './consts.js';
4
+ export * from './protocol.js';
5
+ export { clientRequestHelper, createClientRequestHelper, provideRequest } from './helper.js';
6
+ export { stab } from './stab.js';
4
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAE3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1,9 @@
1
+ import type { EntrypointProtocolDeclaration, EntrypointTree } from '@owlmeans/entrypoint';
2
+ import type { ClientEntrypointOptions, ClientProtocolEntrypoint, RefedEntrypointHandler } from './types.js';
3
+ /** Bind a shared protocol to the client context without changing the declaration itself. */
4
+ export declare const bind: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, options?: ClientEntrypointOptions) => ClientProtocolEntrypoint<Protocol>;
5
+ /** Materialize every protocol in an exported declaration tree for a browser context. */
6
+ export declare const bindAll: (tree: EntrypointTree) => ClientProtocolEntrypoint<EntrypointProtocolDeclaration>[];
7
+ /** Bind a frontend protocol to the component that renders it. */
8
+ export declare const bindScreen: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, handler: RefedEntrypointHandler, options?: ClientEntrypointOptions) => ClientProtocolEntrypoint<Protocol>;
9
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAEzF,OAAO,KAAK,EACV,uBAAuB,EAAE,wBAAwB,EAAE,sBAAsB,EAC1E,MAAM,YAAY,CAAA;AAEnB,4FAA4F;AAC5F,eAAO,MAAM,IAAI,GAAI,QAAQ,SAAS,6BAA6B,YACvD,QAAQ,YACR,uBAAuB,KAChC,wBAAwB,CAAC,QAAQ,CAQnC,CAAA;AAED,wFAAwF;AACxF,eAAO,MAAM,OAAO,SAAU,cAAc,KAAG,wBAAwB,CAAC,6BAA6B,CAAC,EACrD,CAAA;AAEjD,iEAAiE;AACjE,eAAO,MAAM,UAAU,GAAI,QAAQ,SAAS,6BAA6B,YAC7D,QAAQ,WACT,sBAAsB,YACrB,uBAAuB,KAChC,wBAAwB,CAAC,QAAQ,CAQnC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { materializeEntrypoint, protocols } from '@owlmeans/entrypoint';
2
+ import { bindMaterializedEntrypoint } from './entrypoint.js';
3
+ /** Bind a shared protocol to the client context without changing the declaration itself. */
4
+ export const bind = (protocol, options) => {
5
+ const bound = Object.assign(bindMaterializedEntrypoint(materializeEntrypoint(protocol), undefined, options), { protocol });
6
+ return bound;
7
+ };
8
+ /** Materialize every protocol in an exported declaration tree for a browser context. */
9
+ export const bindAll = (tree) => protocols(tree).map(protocol => bind(protocol));
10
+ /** Bind a frontend protocol to the component that renders it. */
11
+ export const bindScreen = (protocol, handler, options) => {
12
+ const bound = Object.assign(bindMaterializedEntrypoint(materializeEntrypoint(protocol), handler, options), { protocol });
13
+ return bound;
14
+ };
15
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAA;AAK5D,4FAA4F;AAC5F,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,QAAkB,EAClB,OAAiC,EACG,EAAE;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,0BAA0B,CACpD,qBAAqB,CAAC,QAAQ,CAAC,EAC/B,SAAS,EACT,OAAO,CACR,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAEhB,OAAO,KAA2C,CAAA;AACpD,CAAC,CAAA;AAED,wFAAwF;AACxF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAoB,EAA6D,EAAE,CACzG,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEjD,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,QAAkB,EAClB,OAA+B,EAC/B,OAAiC,EACG,EAAE;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,0BAA0B,CACpD,qBAAqB,CAAC,QAAQ,CAAC,EAC/B,OAAO,EACP,OAAO,CACR,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAEhB,OAAO,KAA2C,CAAA;AACpD,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { RefedEntrypointHandler } from './types.js';
2
+ /** The no-op handler of a URL-only frontend binding. */
3
+ export declare const stab: RefedEntrypointHandler<{}>;
4
+ //# sourceMappingURL=stab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stab.d.ts","sourceRoot":"","sources":["../src/stab.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD,wDAAwD;AACxD,eAAO,MAAM,IAAI,EAAE,sBAAsB,CAAC,EAAE,CAE3C,CAAA"}
package/build/stab.js ADDED
@@ -0,0 +1,5 @@
1
+ /** The no-op handler of a URL-only frontend binding. */
2
+ export const stab = () => () => {
3
+ return void 0;
4
+ };
5
+ //# sourceMappingURL=stab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stab.js","sourceRoot":"","sources":["../src/stab.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,MAAM,CAAC,MAAM,IAAI,GAA+B,GAAG,EAAE,CAAC,GAAG,EAAE;IACzD,OAAO,KAAK,CAAQ,CAAA;AACtB,CAAC,CAAA"}
package/build/types.d.ts CHANGED
@@ -1,33 +1,77 @@
1
1
  import type { ClientRouteModel, ClientRouteOptions } from '@owlmeans/client-route';
2
- import type { AbstractRequest, AbstractResponse, CommonEntrypoint, CommonEntrypointOptions, EntrypointHandler, EntrypointOutcome } from '@owlmeans/entrypoint';
2
+ import type { AbstractRequest, CommonEntrypoint, CommonEntrypointOptions, EntrypointHandler, EntrypointOutcome, EntrypointProtocolDeclaration, RegisteredEntrypoint, RequestOf } from '@owlmeans/entrypoint';
3
+ import type { LazyService } from '@owlmeans/context';
3
4
  export interface ClientEntrypoint<T = {}, R extends ClientRequest = ClientRequest> extends CommonEntrypoint {
4
5
  route: ClientRouteModel;
6
+ /**
7
+ * Address the entrypoint and resolve to what it answered. The reply's error is thrown, so a
8
+ * caller that only needs the value never inspects an outcome.
9
+ */
5
10
  call: EntrypointCall<T, R>;
11
+ /**
12
+ * The same round trip as {@link ClientEntrypoint.call}, resolving to the value AND the outcome.
13
+ * Use it only where the outcome decides what happens next.
14
+ */
15
+ invoke: EntrypointInvoke<T, R>;
16
+ /**
17
+ * Build the URL this entrypoint addresses, with `:params` filled in and the query appended.
18
+ * Absolute when the route belongs to another service, or when `absolute` is asked for.
19
+ */
20
+ url: EntrypointUrl<R>;
6
21
  validate: EntrypointFilter<R>;
7
- getPath: (partial?: boolean) => string;
8
22
  request: (request?: Partial<R>) => R;
9
23
  }
24
+ /**
25
+ * The context-bound client view of a protocol. Unlike the legacy `ClientEntrypoint` generic,
26
+ * its request and reply types are read directly from the declaration and cannot be replaced at a
27
+ * call site.
28
+ */
29
+ export interface ClientProtocolEntrypoint<Protocol extends EntrypointProtocolDeclaration> extends Omit<ClientEntrypoint, 'call' | 'invoke' | 'url' | 'validate' | 'request'>, RegisteredEntrypoint<RequestOf<Protocol>, import('@owlmeans/entrypoint').ResponseOf<Protocol>> {
30
+ readonly protocol: Protocol;
31
+ }
10
32
  export interface EntrypointCall<T, Req extends ClientRequest = ClientRequest> {
11
- <Type extends T, R extends Req = Req, P extends AbstractResponse<Type> = AbstractResponse<Type>>(req?: Partial<R>, res?: P): Promise<[Type, EntrypointOutcome]>;
33
+ <Type extends T, R extends Req = Req>(req?: Partial<R>): Promise<Type>;
34
+ }
35
+ export interface EntrypointInvoke<T, Req extends ClientRequest = ClientRequest> {
36
+ <Type extends T, R extends Req = Req>(req?: Partial<R>): Promise<EntrypointReply<Type>>;
37
+ }
38
+ export interface EntrypointReply<T> {
39
+ value: T;
40
+ outcome: EntrypointOutcome;
41
+ }
42
+ export interface EntrypointUrl<Req extends ClientRequest = ClientRequest> {
43
+ <R extends Req = Req>(req?: Partial<R>, opts?: EntrypointUrlOptions): Promise<string>;
44
+ }
45
+ export interface EntrypointUrlOptions {
46
+ /** Force a fully qualified URL even when the route belongs to the current service. */
47
+ absolute?: boolean;
12
48
  }
13
49
  export interface EntrypointFilter<Req extends AbstractRequest = AbstractRequest> {
14
50
  <R extends Req>(req?: Partial<R>): Promise<boolean>;
15
51
  }
16
52
  export interface ClientRequest<T extends {} = {}> extends AbstractRequest<T> {
17
- full?: boolean;
18
53
  }
19
54
  export interface ClientEntrypointOptions extends CommonEntrypointOptions {
20
- /**
21
- * Force entrypoint to be elevated even if it is already elevated
22
- */
23
- force?: boolean;
24
55
  routeOptions?: ClientRouteOptions;
25
56
  validateOnCall?: boolean;
26
57
  }
27
58
  export interface EntrypointRef<T, R extends AbstractRequest = AbstractRequest> {
28
59
  ref?: ClientEntrypoint<T, R>;
29
60
  }
30
- export interface RefedEntrypointHandler<T, R extends AbstractRequest = AbstractRequest> {
61
+ export interface RefedEntrypointHandler<T = {}, R extends AbstractRequest = AbstractRequest> {
31
62
  (ref: EntrypointRef<T, R>): EntrypointHandler;
32
63
  }
64
+ export interface EntrypointFailure {
65
+ alias: string;
66
+ request: AbstractRequest;
67
+ error: unknown;
68
+ }
69
+ export interface EntrypointFailurePlugin {
70
+ alias: string;
71
+ onFailure: (failure: EntrypointFailure) => void | Promise<void>;
72
+ }
73
+ export interface EntrypointFailureService extends LazyService {
74
+ registerPlugin: (plugin: EntrypointFailurePlugin) => void;
75
+ notify: (failure: EntrypointFailure) => Promise<void>;
76
+ }
33
77
  //# sourceMappingURL=types.d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AAED,MAAM,WAAW,wBAAyB,SAAQ,WAAW;IAC3D,cAAc,EAAE,CAAC,MAAM,EAAE,uBAAuB,KAAK,IAAI,CAAA;IACzD,MAAM,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACtD"}
@@ -1,12 +1,10 @@
1
- import type { EntrypointFilter, ClientEntrypointOptions } from '../types.js';
1
+ import type { EntrypointFilter } from '../types.js';
2
2
  import type { AbstractRequest } from '@owlmeans/entrypoint';
3
- import type { EntrypointRef, RefedEntrypointHandler } from '../types.js';
4
- export { entrypoint as makeBasicEntrypoint } from '@owlmeans/entrypoint';
3
+ import type { EntrypointRef } from '../types.js';
5
4
  export { isEntrypoint } from '@owlmeans/entrypoint/utils';
6
5
  /**
7
6
  * @throws {SyntaxError} if data shape doesn't match validation
8
7
  * @throws {ClientValidationError} if request is not valid
9
8
  */
10
9
  export declare const validate: <T, R extends AbstractRequest = AbstractRequest>(ref: EntrypointRef<T, R>) => EntrypointFilter;
11
- export declare const normalizeHelperParams: <T, R extends AbstractRequest = AbstractRequest>(handler?: RefedEntrypointHandler<T, R> | ClientEntrypointOptions | boolean, opts?: ClientEntrypointOptions | boolean) => [RefedEntrypointHandler<T, R> | undefined, ClientEntrypointOptions | undefined];
12
10
  //# sourceMappingURL=entrypoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../src/utils/entrypoint.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAGxE,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAKzD;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,gBAiClG,CAAA;AAEH,eAAO,MAAM,qBAAqB,GAAI,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,YACxE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,uBAAuB,GAAG,OAAO,SACnE,uBAAuB,GAAG,OAAO,KACvC,CAAC,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAAE,uBAAuB,GAAG,SAAS,CAShF,CAAA"}
1
+ {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../src/utils/entrypoint.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGhD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAKzD;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,gBAiClG,CAAA"}
@@ -1,7 +1,6 @@
1
1
  import Ajv from 'ajv';
2
2
  import { ClientValidationError } from '../errors.js';
3
3
  import formatsPlugin from 'ajv-formats';
4
- export { entrypoint as makeBasicEntrypoint } from '@owlmeans/entrypoint';
5
4
  export { isEntrypoint } from '@owlmeans/entrypoint/utils';
6
5
  const ajv = new Ajv({ strict: false });
7
6
  formatsPlugin(ajv);
@@ -40,12 +39,4 @@ export const validate = (ref) => async (req) => {
40
39
  }
41
40
  return true;
42
41
  };
43
- export const normalizeHelperParams = (handler, opts) => {
44
- if (typeof handler !== 'function' && handler != null) {
45
- opts = handler;
46
- handler = undefined;
47
- }
48
- opts = typeof opts === 'boolean' ? { validateOnCall: opts } : opts;
49
- return [handler, opts];
50
- };
51
42
  //# sourceMappingURL=entrypoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../../src/utils/entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAGpD,OAAO,aAAa,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;AACtC,aAAa,CAAC,GAAU,CAAC,CAAA;AAEzB;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GACnB,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACrB,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,CAAA;IAClB,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,WAAW,CAAC,gDAAgD,CAAC,CAAA;IACzE,CAAC;IACD,IAAI,GAAG,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,WAAW,CAAC,gEAAgE,CAAC,CAAA;IACzF,CAAC;IACD,IAAI,EAAE,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,WAAW,CAAC,cAAc,GAAG,CAAC,KAAK,oCAAoC,CAAC,CAAA;IACpF,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,EA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AAE,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAClH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE;QAC3B,IAAI,GAAG,CAAC,GAAuB,CAAC,IAAI,IAAI,EAAE,CAAC;YACzC,MAAM,IAAI,WAAW,CAAC,mCAAmC,GAAG,EAAE,CAAC,CAAA;QACjE,CAAC;QAED,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACtC,UAAU,CAAC,GAAG,CAAC,GAAuB,CAAC,CAAC,CAAA;QACxC,IAAI,UAAU,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAA;QACb,CAAC;aAAM,CAAC;YACN,OAAO,UAAU,CAAC,MAAM,CAAA;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC,CAAA;IACL,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,IAAI,CAAmB,CAAA;QAE1F,MAAM,IAAI,qBAAqB,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;IACnF,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import type { AbstractRequest, EntrypointHandler } from '@owlmeans/entrypoint';
2
+ import type { ClientEntrypointOptions, EntrypointInvoke, EntrypointUrlOptions } from '../../types.js';
3
+ /** How a client entrypoint reaches its backend: the handler, the round trip and the address. */
4
+ export interface ApiCallHelper<T, R extends AbstractRequest = AbstractRequest> {
5
+ /**
6
+ * The handler that carries the entrypoint's call: the transport service bound to its route's
7
+ * protocol, else the API client of the web service its route answers on.
8
+ */
9
+ apiHandler: EntrypointHandler;
10
+ /** The round trip behind `invoke()`: builds the request, validates it on demand and notifies failure observers. */
11
+ apiInvoke: (opts?: ClientEntrypointOptions) => EntrypointInvoke<T, R>;
12
+ /** The address behind `url()`: `:params` filled in, the query appended, absolute when the route is not local. */
13
+ entrypointUrl: (req?: Partial<R>, opts?: EntrypointUrlOptions) => Promise<string>;
14
+ }
15
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/handler/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAErG,gGAAgG;AAChG,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe;IAC3E;;;OAGG;IACH,UAAU,EAAE,iBAAiB,CAAA;IAC7B,mHAAmH;IACnH,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,uBAAuB,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACrE,iHAAiH;IACjH,aAAa,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAClF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/handler/types.ts"],"names":[],"mappings":""}
@@ -1,6 +1,8 @@
1
- import type { AbstractRequest, EntrypointHandler } from '@owlmeans/entrypoint';
2
- import type { EntrypointCall, ClientEntrypointOptions, EntrypointRef, ClientRequest } from '../types.js';
3
- export declare const apiHandler: <T, R extends AbstractRequest = AbstractRequest>(ref: EntrypointRef<T, R>) => EntrypointHandler;
4
- export declare const apiCall: <T, R extends AbstractRequest = AbstractRequest>(ref: EntrypointRef<T, R>, opts?: ClientEntrypointOptions) => EntrypointCall<T, R>;
5
- export declare const urlCall: <T, R extends ClientRequest = ClientRequest>(ref: EntrypointRef<T, R>, opts?: ClientEntrypointOptions) => EntrypointCall<T, R>;
1
+ import { type AbstractRequest } from '@owlmeans/entrypoint';
2
+ import type { EntrypointUrlOptions, EntrypointRef, ClientRequest } from '../types.js';
3
+ import type { ApiCallHelper } from './handler/types.js';
4
+ export declare const makeApiCallHelper: <T, R extends AbstractRequest = AbstractRequest>(ref: EntrypointRef<T, R>) => ApiCallHelper<T, R>;
5
+ export declare const apiCallOf: <T, R extends AbstractRequest = AbstractRequest<{}>>(target: EntrypointRef<T, R>) => ApiCallHelper<T, R>;
6
+ /** @deprecated compat:factory-refactor — use `makeApiCallHelper(ref).entrypointUrl(…)` */
7
+ export declare const entrypointUrl: <T, R extends ClientRequest = ClientRequest>(ref: EntrypointRef<T, R>, req?: Partial<R>, opts?: EntrypointUrlOptions) => Promise<string>;
6
8
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/utils/handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE9E,OAAO,KAAK,EAAoB,cAAc,EAAE,uBAAuB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAW1H,eAAO,MAAM,UAAU,EAAE,CACvB,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,EAC9C,GAAG,EAAE,aA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+1,137 @@
1
1
  import { DEFAULT_KEY } from '@owlmeans/client-config';
2
- import { EntrypointOutcome, provideResponse } from '@owlmeans/entrypoint';
2
+ import { EntrypointOutcome, provideResponse, transportAlias } from '@owlmeans/entrypoint';
3
3
  import { validate } from './entrypoint.js';
4
- import { extractParams } from '@owlmeans/client-route';
5
- import { PARAM } from '@owlmeans/route';
4
+ import { clientRouteHelper } from '@owlmeans/client-route';
5
+ import { PARAM, RouteMethod, RouteProtocols } from '@owlmeans/route';
6
6
  import { stringify } from 'qs';
7
- import { assertContext } from '@owlmeans/context';
7
+ import { assertContext, memoHelper } from '@owlmeans/context';
8
8
  import { makeSecurityHelper } from '@owlmeans/config';
9
- export const apiHandler = (ref) => async (req, res) => {
10
- const location = `client-entrypoint:api-handler:${ref.ref?.alias}`;
11
- const context = assertContext(ref.ref?.ctx, location);
12
- if (context.cfg.webService == null) {
13
- throw new SyntaxError('No webService provided');
14
- }
15
- const ep = context.entrypoint(req.alias);
16
- const route = await ep.route.resolve(context);
17
- let alias = typeof context.cfg.webService === 'string'
18
- ? context.cfg.webService
19
- : (route.service != null
20
- ? context.cfg.webService[route.service] ?? context.cfg.webService[DEFAULT_KEY]
21
- : context.cfg.webService[DEFAULT_KEY]);
22
- if (alias == null) {
23
- throw new SyntaxError(`Can't cast web service alias for ${ep.alias} entrypoint`);
24
- }
25
- const service = context.service(alias);
26
- req.path = ep.getPath();
27
- return service.handler(req, res);
28
- };
29
- export const apiCall = (ref, opts) => (async (req, res) => {
30
- const ep = ref.ref;
31
- if (ep == null) {
32
- throw new SyntaxError('Try to make API call before the entrypoint is created');
33
- }
34
- const ctx = ep.ctx;
35
- if (ctx == null) {
36
- throw new SyntaxError(`No context provided in apiCall for ${ep.alias} entrypoint`);
37
- }
38
- await ep.route.resolve(ctx);
39
- if (req?.canceled) {
40
- return;
41
- }
42
- const request = {
43
- alias: ep.alias,
44
- params: req?.params ?? {},
45
- body: req?.body,
46
- headers: req?.headers ?? {},
47
- query: req?.query ?? {},
48
- host: req?.host,
49
- base: req?.base,
50
- path: ep.getPath(),
51
- timeout: req?.timeout,
52
- signal: req?.signal,
9
+ import { ENTRYPOINT_FAILURE_SERVICE } from '../consts.js';
10
+ import { logger } from '@owlmeans/log';
11
+ const log = logger('client-entrypoint');
12
+ export const makeApiCallHelper = (ref) => {
13
+ const apiHandler = async (req, res) => {
14
+ const location = `client-entrypoint:api-handler:${ref.ref?.alias}`;
15
+ const context = assertContext(ref.ref?.ctx, location);
16
+ if (context.cfg.webService == null) {
17
+ throw new SyntaxError('No webService provided');
18
+ }
19
+ const ep = context.entrypoint(req.alias);
20
+ // A route names the protocol it answers on. Whatever is bound under that protocol takes the
21
+ // call, so a consumer writes `ep.call(...)` without learning which transport ran.
22
+ const transport = transportAlias(ep.route.route.protocol);
23
+ if (context.hasService(transport)) {
24
+ req.path = ep.path();
25
+ return context.service(transport).handle(req, res);
26
+ }
27
+ // Which web client carries this call is decided by the service the route answers on — the one it
28
+ // names, or the one the context picks for its app type when it names none.
29
+ const route = ep.service();
30
+ const alias = typeof context.cfg.webService === 'string'
31
+ ? context.cfg.webService
32
+ : context.cfg.webService[route.service] ?? context.cfg.webService[DEFAULT_KEY];
33
+ if (alias == null) {
34
+ throw new SyntaxError(`Can't cast web service alias for ${ep.alias} entrypoint`);
35
+ }
36
+ const service = context.service(alias);
37
+ req.path = ep.path();
38
+ return service.handler(req, res);
53
39
  };
54
- if (req?.cancel != null) {
55
- const cancel = req.cancel;
56
- req.cancel = () => {
57
- cancel();
58
- request.canceled = true;
40
+ const apiInvoke = (opts) => (async (req) => {
41
+ const ep = ref.ref;
42
+ if (ep == null) {
43
+ throw new SyntaxError('Try to make API call before the entrypoint is created');
44
+ }
45
+ const ctx = ep.ctx;
46
+ if (ctx == null) {
47
+ throw new SyntaxError(`No context provided in apiCall for ${ep.alias} entrypoint`);
48
+ }
49
+ if (req?.canceled) {
50
+ return { value: null, outcome: EntrypointOutcome.Ok };
51
+ }
52
+ const request = {
53
+ alias: ep.alias,
54
+ params: req?.params ?? {},
55
+ // JSON transports must send a body for mutation methods even when the contract has no
56
+ // payload. Keeping that rule here makes every typed caller use `call({ params })`, never
57
+ // an SDK-specific `{ body: {} }` workaround.
58
+ body: req?.body ?? ([RouteMethod.POST, RouteMethod.PUT, RouteMethod.PATCH]
59
+ .includes(ep.route.route.method ?? RouteMethod.GET) ? {} : undefined),
60
+ headers: req?.headers ?? {},
61
+ query: req?.query ?? {},
62
+ host: req?.host,
63
+ base: req?.base,
64
+ path: ep.path(),
65
+ timeout: req?.timeout,
66
+ signal: req?.signal,
59
67
  };
60
- }
61
- if (opts?.validateOnCall) {
68
+ if (req?.cancel != null) {
69
+ const cancel = req.cancel;
70
+ req.cancel = () => {
71
+ cancel();
72
+ request.canceled = true;
73
+ };
74
+ }
75
+ if (opts?.validateOnCall) {
76
+ try {
77
+ await validate(ref)(request);
78
+ }
79
+ catch (e) {
80
+ log.error('Request validation failed', { alias: ep.alias, error: e });
81
+ throw e;
82
+ }
83
+ }
84
+ const reply = provideResponse();
85
+ if (ctx == null && ep.ctx == null) {
86
+ throw new SyntaxError(`Use entrypoint ${ep.alias} without context`);
87
+ }
62
88
  try {
63
- await validate(ref)(request);
89
+ await apiHandler(request, reply);
90
+ if (reply.error != null)
91
+ throw reply.error;
92
+ }
93
+ catch (error) {
94
+ if (ctx.hasService(ENTRYPOINT_FAILURE_SERVICE)) {
95
+ await ctx.service(ENTRYPOINT_FAILURE_SERVICE)
96
+ .notify({ alias: ep.alias, request, error });
97
+ }
98
+ throw error;
64
99
  }
65
- catch (e) {
66
- console.error(e);
67
- throw e;
100
+ return { value: reply.value ?? null, outcome: reply.outcome ?? EntrypointOutcome.Ok };
101
+ });
102
+ const entrypointUrl = async (req, opts) => {
103
+ const ep = ref.ref;
104
+ if (ep == null) {
105
+ throw new SyntaxError('Try to make URL before the entrypoint is created');
68
106
  }
69
- }
70
- if (res != null) {
71
- await apiHandler(ref)(request, res);
72
- return;
73
- }
74
- const reply = provideResponse();
75
- if (ctx == null && ep.ctx == null) {
76
- throw new SyntaxError(`Use entrypoint ${ep.alias} without context`);
77
- }
78
- await apiHandler(ref)(request, reply);
79
- if (reply.error != null) {
80
- throw reply.error;
81
- }
82
- return [reply.value ?? null, reply.outcome ?? EntrypointOutcome.Ok];
83
- });
84
- export const urlCall = ref => async (req, res) => {
85
- const ep = ref.ref;
86
- if (ep == null) {
87
- throw new SyntaxError('Try to make URL before the entrypoint is created');
88
- }
89
- const ctx = ep.ctx;
90
- if (ctx == null) {
91
- throw new SyntaxError(`No context provided in urlCall for ${ep.alias} entrypoint`);
92
- }
93
- await ep.route.resolve(ctx);
94
- const pathParams = extractParams(ep.getPath());
95
- let path = pathParams.reduce((p, param) => {
96
- return p.replace(`${PARAM}${param}`, `${req?.params?.[param]}`);
97
- }, ep.getPath()) + (req?.query != null ? `?${stringify(req?.query)}` : '');
98
- if (ep.route.route.service !== null && (ctx.cfg.service !== ep.route.route.service
99
- || req?.full === true)) {
100
- const helper = makeSecurityHelper(ctx);
101
- path = helper.makeUrl(ep.route.route, path, { host: req?.host, base: req?.base, forceUnsecure: req?.unsecure });
102
- }
103
- res?.resolve(path, EntrypointOutcome.Ok);
104
- return [path, EntrypointOutcome.Ok];
107
+ const ctx = ep.ctx;
108
+ if (ctx == null) {
109
+ throw new SyntaxError(`No context provided in entrypointUrl for ${ep.alias} entrypoint`);
110
+ }
111
+ // The base is left off here: an in-service URL is addressed relative to it, and the absolute
112
+ // branch below has `makeUrl` prepend it.
113
+ const epPath = ep.path();
114
+ const pathParams = clientRouteHelper.extractParams(epPath);
115
+ let path = pathParams.reduce((p, param) => {
116
+ return p.replace(`${PARAM}${param}`, `${req?.params?.[param]}`);
117
+ }, epPath) + (req?.query != null ? `?${stringify(req?.query)}` : '');
118
+ // A socket address is always absolute, whoever owns the route. `new WebSocket(path)` resolves a
119
+ // relative value against the PAGE's origin, which in a split deployment is the web host and not
120
+ // the service that answers the upgrade — so the handshake goes somewhere that never speaks it
121
+ // and dies on a gateway timeout. Only a same-origin HTTP route benefits from staying relative.
122
+ const socket = ep.route.route.protocol === RouteProtocols.SOCKET;
123
+ // Locality is a question about the RESOLVED service, not about what the declaration happens to
124
+ // name: a route that names no service belongs to the asking context, and addressing it absolutely
125
+ // would turn in-app navigation into a full page load.
126
+ if (socket || !ep.isLocal() || opts?.absolute === true) {
127
+ const helper = makeSecurityHelper(ctx);
128
+ path = helper.makeUrl(ep.address(), path, { host: req?.host, base: req?.base, forceUnsecure: req?.unsecure });
129
+ }
130
+ return path;
131
+ };
132
+ return { apiHandler, apiInvoke, entrypointUrl };
105
133
  };
134
+ export const apiCallOf = memoHelper.oncePer(makeApiCallHelper);
135
+ /** @deprecated compat:factory-refactor — use `makeApiCallHelper(ref).entrypointUrl(…)` */
136
+ export const entrypointUrl = (ref, req, opts) => makeApiCallHelper(ref).entrypointUrl(req, opts);
106
137
  //# sourceMappingURL=handler.js.map