@owlmeans/client-entrypoint 0.1.18-rc.3 → 0.1.18-rc.30

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/build/types.d.ts CHANGED
@@ -1,33 +1,63 @@
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
3
  export interface ClientEntrypoint<T = {}, R extends ClientRequest = ClientRequest> extends CommonEntrypoint {
4
4
  route: ClientRouteModel;
5
+ /**
6
+ * Address the entrypoint and resolve to what it answered. The reply's error is thrown, so a
7
+ * caller that only needs the value never inspects an outcome.
8
+ */
5
9
  call: EntrypointCall<T, R>;
10
+ /**
11
+ * The same round trip as {@link ClientEntrypoint.call}, resolving to the value AND the outcome.
12
+ * Use it only where the outcome decides what happens next.
13
+ */
14
+ invoke: EntrypointInvoke<T, R>;
15
+ /**
16
+ * Build the URL this entrypoint addresses, with `:params` filled in and the query appended.
17
+ * Absolute when the route belongs to another service, or when `absolute` is asked for.
18
+ */
19
+ url: EntrypointUrl<R>;
6
20
  validate: EntrypointFilter<R>;
7
- getPath: (partial?: boolean) => string;
8
21
  request: (request?: Partial<R>) => R;
9
22
  }
23
+ /**
24
+ * The context-bound client view of a protocol. Unlike the legacy `ClientEntrypoint` generic,
25
+ * its request and reply types are read directly from the declaration and cannot be replaced at a
26
+ * call site.
27
+ */
28
+ export type ClientProtocolEntrypoint<Protocol extends EntrypointProtocolDeclaration> = Omit<ClientEntrypoint, 'call' | 'invoke' | 'url' | 'validate' | 'request'> & RegisteredEntrypoint<RequestOf<Protocol>, import('@owlmeans/entrypoint').ResponseOf<Protocol>> & {
29
+ readonly protocol: Protocol;
30
+ };
10
31
  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]>;
32
+ <Type extends T, R extends Req = Req>(req?: Partial<R>): Promise<Type>;
33
+ }
34
+ export interface EntrypointInvoke<T, Req extends ClientRequest = ClientRequest> {
35
+ <Type extends T, R extends Req = Req>(req?: Partial<R>): Promise<EntrypointReply<Type>>;
36
+ }
37
+ export interface EntrypointReply<T> {
38
+ value: T;
39
+ outcome: EntrypointOutcome;
40
+ }
41
+ export interface EntrypointUrl<Req extends ClientRequest = ClientRequest> {
42
+ <R extends Req = Req>(req?: Partial<R>, opts?: EntrypointUrlOptions): Promise<string>;
43
+ }
44
+ export interface EntrypointUrlOptions {
45
+ /** Force a fully qualified URL even when the route belongs to the current service. */
46
+ absolute?: boolean;
12
47
  }
13
48
  export interface EntrypointFilter<Req extends AbstractRequest = AbstractRequest> {
14
49
  <R extends Req>(req?: Partial<R>): Promise<boolean>;
15
50
  }
16
51
  export interface ClientRequest<T extends {} = {}> extends AbstractRequest<T> {
17
- full?: boolean;
18
52
  }
19
53
  export interface ClientEntrypointOptions extends CommonEntrypointOptions {
20
- /**
21
- * Force entrypoint to be elevated even if it is already elevated
22
- */
23
- force?: boolean;
24
54
  routeOptions?: ClientRouteOptions;
25
55
  validateOnCall?: boolean;
26
56
  }
27
57
  export interface EntrypointRef<T, R extends AbstractRequest = AbstractRequest> {
28
58
  ref?: ClientEntrypoint<T, R>;
29
59
  }
30
- export interface RefedEntrypointHandler<T, R extends AbstractRequest = AbstractRequest> {
60
+ export interface RefedEntrypointHandler<T = {}, R extends AbstractRequest = AbstractRequest> {
31
61
  (ref: EntrypointRef<T, R>): EntrypointHandler;
32
62
  }
33
63
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","s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AAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACtF;AAED,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB,CAAC,GAAG,SAAS,eAAe,GAAG,eAAe;IAC7E,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACpD;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;CAC3E;AAED,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACtE,YAAY,CAAC,EAAE,kBAAkB,CAAA;IACjC,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe;IAC3E,GAAG,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC7B;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe;IACzF,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAA;CAC9C"}
@@ -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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AAA;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"}
@@ -1,6 +1,6 @@
1
1
  import type { AbstractRequest, EntrypointHandler } from '@owlmeans/entrypoint';
2
- import type { EntrypointCall, ClientEntrypointOptions, EntrypointRef, ClientRequest } from '../types.js';
2
+ import type { EntrypointInvoke, EntrypointUrlOptions, ClientEntrypointOptions, EntrypointRef, ClientRequest } from '../types.js';
3
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>;
4
+ export declare const apiInvoke: <T, R extends AbstractRequest = AbstractRequest>(ref: EntrypointRef<T, R>, opts?: ClientEntrypointOptions) => EntrypointInvoke<T, R>;
5
+ export declare const entrypointUrl: <T, R extends ClientRequest = ClientRequest>(ref: EntrypointRef<T, R>, req?: Partial<R>, opts?: EntrypointUrlOptions) => Promise<string>;
6
6
  //# 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,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,iBA0B9B,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,CACpB,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,EAC9C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,uBAAuB,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC,CAyDvD,CAAA;AAE3B,eAAO,MAAM,OAAO,EAAE,CACpB,CAAC,EAAE,CAAC,SAAS,aAAa,GAAG,aAAa,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,uBAAuB,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC,CA4BjF,CAAA"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/utils/handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAuB,MAAM,sBAAsB,CAAA;AAEnG,OAAO,KAAK,EAAoB,gBAAgB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAWlJ,eAAO,MAAM,UAAU,EAAE,CACvB,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,EAC9C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,iBAoC9B,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,CACtB,CAAC,EAAE,CAAC,SAAS,eAAe,GAAG,eAAe,EAC9C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,uBAAuB,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAwDvD,CAAA;AAE7B,eAAO,MAAM,aAAa,EAAE,CAC1B,CAAC,EAAE,CAAC,SAAS,aAAa,GAAG,aAAa,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAmC3F,CAAA"}
@@ -1,8 +1,8 @@
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
4
  import { extractParams } from '@owlmeans/client-route';
5
- import { PARAM } from '@owlmeans/route';
5
+ import { PARAM, RouteMethod, RouteProtocols } from '@owlmeans/route';
6
6
  import { stringify } from 'qs';
7
7
  import { assertContext } from '@owlmeans/context';
8
8
  import { makeSecurityHelper } from '@owlmeans/config';
@@ -13,20 +13,27 @@ export const apiHandler = (ref) => async (req, res) => {
13
13
  throw new SyntaxError('No webService provided');
14
14
  }
15
15
  const ep = context.entrypoint(req.alias);
16
- const route = await ep.route.resolve(context);
17
- let alias = typeof context.cfg.webService === 'string'
16
+ // A route names the protocol it answers on. Whatever is bound under that protocol takes the
17
+ // call, so a consumer writes `ep.call(...)` without learning which transport ran.
18
+ const transport = transportAlias(ep.route.route.protocol);
19
+ if (context.hasService(transport)) {
20
+ req.path = ep.path();
21
+ return context.service(transport).handle(req, res);
22
+ }
23
+ // Which web client carries this call is decided by the service the route answers on — the one it
24
+ // names, or the one the context picks for its app type when it names none.
25
+ const route = ep.service();
26
+ const alias = typeof context.cfg.webService === 'string'
18
27
  ? context.cfg.webService
19
- : (route.service != null
20
- ? context.cfg.webService[route.service] ?? context.cfg.webService[DEFAULT_KEY]
21
- : context.cfg.webService[DEFAULT_KEY]);
28
+ : context.cfg.webService[route.service] ?? context.cfg.webService[DEFAULT_KEY];
22
29
  if (alias == null) {
23
30
  throw new SyntaxError(`Can't cast web service alias for ${ep.alias} entrypoint`);
24
31
  }
25
32
  const service = context.service(alias);
26
- req.path = ep.getPath();
33
+ req.path = ep.path();
27
34
  return service.handler(req, res);
28
35
  };
29
- export const apiCall = (ref, opts) => (async (req, res) => {
36
+ export const apiInvoke = (ref, opts) => (async (req) => {
30
37
  const ep = ref.ref;
31
38
  if (ep == null) {
32
39
  throw new SyntaxError('Try to make API call before the entrypoint is created');
@@ -35,19 +42,22 @@ export const apiCall = (ref, opts) => (async (req, res) => {
35
42
  if (ctx == null) {
36
43
  throw new SyntaxError(`No context provided in apiCall for ${ep.alias} entrypoint`);
37
44
  }
38
- await ep.route.resolve(ctx);
39
45
  if (req?.canceled) {
40
- return;
46
+ return { value: null, outcome: EntrypointOutcome.Ok };
41
47
  }
42
48
  const request = {
43
49
  alias: ep.alias,
44
50
  params: req?.params ?? {},
45
- body: req?.body,
51
+ // JSON transports must send a body for mutation methods even when the contract has no
52
+ // payload. Keeping that rule here makes every typed caller use `call({ params })`, never
53
+ // an SDK-specific `{ body: {} }` workaround.
54
+ body: req?.body ?? ([RouteMethod.POST, RouteMethod.PUT, RouteMethod.PATCH]
55
+ .includes(ep.route.route.method ?? RouteMethod.GET) ? {} : undefined),
46
56
  headers: req?.headers ?? {},
47
57
  query: req?.query ?? {},
48
58
  host: req?.host,
49
59
  base: req?.base,
50
- path: ep.getPath(),
60
+ path: ep.path(),
51
61
  timeout: req?.timeout,
52
62
  signal: req?.signal,
53
63
  };
@@ -67,10 +77,6 @@ export const apiCall = (ref, opts) => (async (req, res) => {
67
77
  throw e;
68
78
  }
69
79
  }
70
- if (res != null) {
71
- await apiHandler(ref)(request, res);
72
- return;
73
- }
74
80
  const reply = provideResponse();
75
81
  if (ctx == null && ep.ctx == null) {
76
82
  throw new SyntaxError(`Use entrypoint ${ep.alias} without context`);
@@ -79,28 +85,36 @@ export const apiCall = (ref, opts) => (async (req, res) => {
79
85
  if (reply.error != null) {
80
86
  throw reply.error;
81
87
  }
82
- return [reply.value ?? null, reply.outcome ?? EntrypointOutcome.Ok];
88
+ return { value: reply.value ?? null, outcome: reply.outcome ?? EntrypointOutcome.Ok };
83
89
  });
84
- export const urlCall = ref => async (req, res) => {
90
+ export const entrypointUrl = async (ref, req, opts) => {
85
91
  const ep = ref.ref;
86
92
  if (ep == null) {
87
93
  throw new SyntaxError('Try to make URL before the entrypoint is created');
88
94
  }
89
95
  const ctx = ep.ctx;
90
96
  if (ctx == null) {
91
- throw new SyntaxError(`No context provided in urlCall for ${ep.alias} entrypoint`);
97
+ throw new SyntaxError(`No context provided in entrypointUrl for ${ep.alias} entrypoint`);
92
98
  }
93
- await ep.route.resolve(ctx);
94
- const pathParams = extractParams(ep.getPath());
99
+ // The base is left off here: an in-service URL is addressed relative to it, and the absolute
100
+ // branch below has `makeUrl` prepend it.
101
+ const epPath = ep.path();
102
+ const pathParams = extractParams(epPath);
95
103
  let path = pathParams.reduce((p, param) => {
96
104
  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)) {
105
+ }, epPath) + (req?.query != null ? `?${stringify(req?.query)}` : '');
106
+ // A socket address is always absolute, whoever owns the route. `new WebSocket(path)` resolves a
107
+ // relative value against the PAGE's origin, which in a split deployment is the web host and not
108
+ // the service that answers the upgrade — so the handshake goes somewhere that never speaks it
109
+ // and dies on a gateway timeout. Only a same-origin HTTP route benefits from staying relative.
110
+ const socket = ep.route.route.protocol === RouteProtocols.SOCKET;
111
+ // Locality is a question about the RESOLVED service, not about what the declaration happens to
112
+ // name: a route that names no service belongs to the asking context, and addressing it absolutely
113
+ // would turn in-app navigation into a full page load.
114
+ if (socket || !ep.isLocal() || opts?.absolute === true) {
100
115
  const helper = makeSecurityHelper(ctx);
101
- path = helper.makeUrl(ep.route.route, path, { host: req?.host, base: req?.base, forceUnsecure: req?.unsecure });
116
+ path = helper.makeUrl(ep.address(), path, { host: req?.host, base: req?.base, forceUnsecure: req?.unsecure });
102
117
  }
103
- res?.resolve(path, EntrypointOutcome.Ok);
104
- return [path, EntrypointOutcome.Ok];
118
+ return path;
105
119
  };
106
120
  //# sourceMappingURL=handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/utils/handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAGrD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAKrD,MAAM,CAAC,MAAM,UAAU,GAE4B,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAC7E,MAAM,QAAQ,GAAG,iCAAiC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAA;IAClE,MAAM,OAAO,GAAG,aAAa,CAAkB,GAAG,CAAC,GAAG,EAAE,G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AAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QACxC,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,KAAK,GAAG,KAAK,EAAE,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,KAAgC,CAAC,EAAE,CAAC,CAAA;IAC5F,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAEpE,gGAAgG;IAChG,gGAAgG;IAChG,8FAA8F;IAC9F,+FAA+F;IAC/F,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,KAAK,cAAc,CAAC,MAAM,CAAA;IAEhE,+FAA+F;IAC/F,kGAAkG;IAClG,sDAAsD;IACtD,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvD,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;QACtC,IAAI,GAAG,MAAM,CAAC,OAAO,CACnB,EAAE,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,QAAQ,EAAE,CACvF,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/client-entrypoint",
3
- "version": "0.1.18-rc.3",
3
+ "version": "0.1.18-rc.30",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -28,15 +28,15 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@owlmeans/api": "^0.1.18-rc.3",
32
- "@owlmeans/client-config": "^0.1.18-rc.3",
33
- "@owlmeans/client-context": "^0.1.18-rc.3",
34
- "@owlmeans/client-route": "^0.1.18-rc.3",
35
- "@owlmeans/config": "^0.1.18-rc.3",
36
- "@owlmeans/context": "^0.1.18-rc.3",
37
- "@owlmeans/entrypoint": "^0.1.18-rc.3",
38
- "@owlmeans/error": "^0.1.18-rc.3",
39
- "@owlmeans/route": "^0.1.18-rc.3",
31
+ "@owlmeans/api": "^0.1.18-rc.30",
32
+ "@owlmeans/client-config": "^0.1.18-rc.30",
33
+ "@owlmeans/client-context": "^0.1.18-rc.31",
34
+ "@owlmeans/client-route": "^0.1.18-rc.31",
35
+ "@owlmeans/config": "^0.1.18-rc.30",
36
+ "@owlmeans/context": "^0.1.18-rc.26",
37
+ "@owlmeans/entrypoint": "^0.1.18-rc.29",
38
+ "@owlmeans/error": "^0.1.18-rc.28",
39
+ "@owlmeans/route": "^0.1.18-rc.27",
40
40
  "ajv-formats": "^3.0.1",
41
41
  "qs": "^6.13.0"
42
42
  },
package/src/entrypoint.ts CHANGED
@@ -1,60 +1,54 @@
1
- import type { ClientRouteModel } from '@owlmeans/client-route'
2
1
  import type { ClientEntrypoint, ClientEntrypointOptions, EntrypointRef, RefedEntrypointHandler } from './types.js'
3
2
  import type { AbstractRequest, CommonEntrypoint } from '@owlmeans/entrypoint'
4
- import { isEntrypoint, makeBasicEntrypoint, normalizeHelperParams, validate } from './utils/entrypoint.js'
5
- import { isClientRouteModel, route } from '@owlmeans/client-route'
6
- import { apiCall, apiHandler, urlCall } from './utils/handler.js'
3
+ import { validate } from './utils/entrypoint.js'
4
+ import { route } from '@owlmeans/client-route'
5
+ import { apiInvoke, apiHandler, entrypointUrl } from './utils/handler.js'
7
6
  import { AppType } from '@owlmeans/context'
8
- import type { BasicContext } from '@owlmeans/context'
9
- import { normalizePath } from '@owlmeans/route'
10
- import type { CommonRouteModel } from '@owlmeans/route'
11
7
  import { provideRequest } from './helper.js'
12
8
 
13
- export const entrypoint = <T, R extends AbstractRequest = AbstractRequest>(
14
- arg: CommonEntrypoint | ClientRouteModel | CommonRouteModel,
15
- handler?: RefedEntrypointHandler<T, R> | ClientEntrypointOptions | boolean,
16
- opts?: ClientEntrypointOptions | boolean
9
+ /** Attach client behaviour to an entrypoint already materialized from a protocol. */
10
+ export const bindMaterializedEntrypoint = <T, R extends AbstractRequest = AbstractRequest>(
11
+ arg: CommonEntrypoint,
12
+ handler?: RefedEntrypointHandler<T, R>,
13
+ opts?: ClientEntrypointOptions,
17
14
  ): ClientEntrypoint<T, R> => {
18
15
  const entrypointHandle: EntrypointRef<T, R> = { ref: undefined }
19
16
 
20
17
  let _entrypoint: ClientEntrypoint<T, R>
21
18
 
22
- ;[handler, opts] = normalizeHelperParams(handler, opts)
23
-
24
- const _handler = handler as RefedEntrypointHandler<T, R> | undefined ??
25
- (('route' in arg.route ? arg.route.route.type : arg.route.type)
26
- === AppType.Backend ? apiHandler : undefined)
27
-
28
- if (isEntrypoint(arg)) {
29
- assertExplicitHandler(arg.route.route.type, handler as RefedEntrypointHandler<T, R>)
30
- const routeModel = route(arg.route, opts?.routeOptions)
31
- _entrypoint = arg as ClientEntrypoint<T, R>
32
- _entrypoint.route = routeModel
33
- _entrypoint.guards = opts?.guards ?? arg.guards
34
- _entrypoint.filter = opts?.filter ?? arg.filter
35
- _entrypoint.gate = opts?.gate ?? arg.gate
36
- _entrypoint.gateParams = opts?.gateParams ?? arg.gateParams
37
- } else if (isClientRouteModel(arg)) {
38
- assertExplicitHandler(arg.route.type, handler as RefedEntrypointHandler<T, R>)
39
- _entrypoint = makeBasicEntrypoint(arg, { ...opts }) as ClientEntrypoint<T, R>
40
- _entrypoint.route = arg
41
- } else {
42
- assertExplicitHandler(arg.route.type, handler as RefedEntrypointHandler<T, R>)
43
- const _route = route(arg, opts?.routeOptions)
44
- _entrypoint = makeBasicEntrypoint(_route, { ...opts }) as ClientEntrypoint<T, R>
45
- _entrypoint.route = _route
46
- }
47
-
48
- _entrypoint.getPath = (partial?: boolean) =>
49
- partial === true ? normalizePath(_entrypoint.route.route.partialPath) : _entrypoint.route.route.path
19
+ const _handler = handler ?? (arg.route.route.type === AppType.Backend ? apiHandler : undefined)
20
+
21
+ assertExplicitHandler(arg.route.route.type, handler)
22
+ const routeModel = route(arg.route, opts?.routeOptions)
23
+ _entrypoint = arg as ClientEntrypoint<T, R>
24
+ _entrypoint.route = routeModel
25
+ // Binding adds guards, it never swaps them: what the declaration carries still applies.
26
+ _entrypoint.guards = [...new Set([...(arg.guards ?? []), ...(opts?.guards ?? [])])]
27
+ _entrypoint.filter = opts?.filter ?? arg.filter
28
+ _entrypoint.gate = opts?.gate ?? arg.gate
29
+ _entrypoint.gateParams = opts?.gateParams ?? arg.gateParams
30
+
31
+ _entrypoint.url = ((req?: Partial<R>, urlOpts?: { absolute?: boolean }) =>
32
+ entrypointUrl<T, R>(entrypointHandle, req as never, urlOpts)) as ClientEntrypoint<T, R>['url']
33
+
34
+ // An entrypoint carrying a renderer IS a screen: it is addressed by URL, never called over the
35
+ // wire. Saying so here turns what used to be a URL-shaped answer from `call()` into a report.
36
+ _entrypoint.invoke = (handler != null
37
+ ? (async () => {
38
+ throw new SyntaxError(
39
+ `Entrypoint ${_entrypoint.alias} renders a screen - address it with url() instead of call()/invoke()`
40
+ )
41
+ })
42
+ : apiInvoke<T, R>(entrypointHandle, opts)) as ClientEntrypoint<T, R>['invoke']
50
43
 
51
- _entrypoint.call = handler != null ? urlCall<T, R>(entrypointHandle, opts) : apiCall<T, R>(entrypointHandle, opts)
44
+ _entrypoint.call = (async (req?: Partial<R>) =>
45
+ (await _entrypoint.invoke(req)).value) as ClientEntrypoint<T, R>['call']
52
46
 
53
47
  _entrypoint.request = ((request: R): R => {
54
48
  if (entrypointHandle.ref == null) {
55
49
  throw SyntaxError(`Try to request uninitialized entrypoint ${JSON.stringify(arg)}`)
56
50
  }
57
- const _request = provideRequest(entrypointHandle.ref.getAlias(), entrypointHandle.ref.getPath()) as R
51
+ const _request = provideRequest(entrypointHandle.ref.alias, entrypointHandle.ref.path()) as R
58
52
 
59
53
  request != null && Object.entries(request).forEach(([key, value]) => {
60
54
  _request[key as keyof R] = value
@@ -67,13 +61,6 @@ export const entrypoint = <T, R extends AbstractRequest = AbstractRequest>(
67
61
 
68
62
  _entrypoint.validate = validate(entrypointHandle)
69
63
 
70
- _entrypoint.reinitializeContext = <T>(context: BasicContext<any>) => {
71
- const newEntrypoint = entrypoint(_entrypoint.route, handler, opts)
72
- newEntrypoint.ctx = context
73
-
74
- return newEntrypoint as T
75
- }
76
-
77
64
  entrypointHandle.ref = _entrypoint
78
65
 
79
66
  return _entrypoint
package/src/helper.ts CHANGED
@@ -1,31 +1,7 @@
1
- import type { ClientEntrypoint, ClientEntrypointOptions, RefedEntrypointHandler } from './types.js'
2
- import { entrypoint } from './entrypoint.js'
3
- import { isClientRouteModel } from '@owlmeans/client-route'
4
- import type { AbstractRequest, CommonEntrypoint } from '@owlmeans/entrypoint'
5
- import { normalizeHelperParams } from './utils/entrypoint.js'
1
+ import type { RefedEntrypointHandler } from './types.js'
2
+ import type { AbstractRequest } from '@owlmeans/entrypoint'
6
3
  import type { JSONSchemaType } from "ajv"
7
4
 
8
- export const elevate = <T = {}, R extends AbstractRequest = AbstractRequest>(
9
- entrypoints: (CommonEntrypoint | ClientEntrypoint<T, R>)[],
10
- alias: string,
11
- handler?: RefedEntrypointHandler<T, R> | ClientEntrypointOptions | boolean,
12
- opts?: ClientEntrypointOptions | boolean
13
- ): ClientEntrypoint<T, R>[] => {
14
- [handler, opts] = normalizeHelperParams(handler, opts)
15
-
16
- const idx = entrypoints.findIndex(({ route }) => route.route.alias === alias)
17
- if (idx === -1) {
18
- throw new SyntaxError(`Entrypoint with alias ${alias} not present`)
19
- }
20
- if (isClientRouteModel(entrypoints[idx].route) && opts?.force !== true) {
21
- throw new SyntaxError(`Entrypoint with alias ${alias} is already elevated`)
22
- }
23
-
24
- entrypoints[idx] = entrypoint(entrypoints[idx], handler, opts)
25
-
26
- return entrypoints as ClientEntrypoint<T, R>[]
27
- }
28
-
29
5
  export const stab: RefedEntrypointHandler<{}> = () => () => {
30
6
  return void 0 as any
31
7
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- export * from './helper.js'
3
2
  export type * from './types.js'
4
- export * from './entrypoint.js'
5
3
  export * from './errors.js'
4
+ export * from './protocol.js'
5
+ export { pickPerSchema, provideRequest, stab } from './helper.js'
@@ -0,0 +1,39 @@
1
+ import { materializeEntrypoint, protocols } from '@owlmeans/entrypoint'
2
+ import type { EntrypointProtocolDeclaration, EntrypointTree } from '@owlmeans/entrypoint'
3
+ import { bindMaterializedEntrypoint } from './entrypoint.js'
4
+ import type {
5
+ ClientEntrypointOptions, ClientProtocolEntrypoint, RefedEntrypointHandler,
6
+ } from './types.js'
7
+
8
+ /** Bind a shared protocol to the client context without changing the declaration itself. */
9
+ export const bind = <Protocol extends EntrypointProtocolDeclaration>(
10
+ protocol: Protocol,
11
+ options?: ClientEntrypointOptions,
12
+ ): ClientProtocolEntrypoint<Protocol> => {
13
+ const bound = Object.assign(bindMaterializedEntrypoint(
14
+ materializeEntrypoint(protocol),
15
+ undefined,
16
+ options,
17
+ ), { protocol })
18
+
19
+ return bound as ClientProtocolEntrypoint<Protocol>
20
+ }
21
+
22
+ /** Materialize every protocol in an exported declaration tree for a browser context. */
23
+ export const bindAll = (tree: EntrypointTree): ClientProtocolEntrypoint<EntrypointProtocolDeclaration>[] =>
24
+ protocols(tree).map(protocol => bind(protocol))
25
+
26
+ /** Bind a frontend protocol to the component that renders it. */
27
+ export const bindScreen = <Protocol extends EntrypointProtocolDeclaration>(
28
+ protocol: Protocol,
29
+ handler: RefedEntrypointHandler,
30
+ options?: ClientEntrypointOptions,
31
+ ): ClientProtocolEntrypoint<Protocol> => {
32
+ const bound = Object.assign(bindMaterializedEntrypoint(
33
+ materializeEntrypoint(protocol),
34
+ handler,
35
+ options,
36
+ ), { protocol })
37
+
38
+ return bound as ClientProtocolEntrypoint<Protocol>
39
+ }