@owlmeans/entrypoint 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.
- package/README.md +254 -70
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/entrypoint/SKILL.md +77 -130
- package/build/consts.d.ts +0 -5
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +0 -5
- package/build/consts.js.map +1 -1
- package/build/entrypoint.d.ts.map +1 -1
- package/build/entrypoint.js +18 -6
- package/build/entrypoint.js.map +1 -1
- package/build/filter/types.d.ts +16 -0
- package/build/filter/types.d.ts.map +1 -0
- package/build/filter/types.js +2 -0
- package/build/filter/types.js.map +1 -0
- package/build/filter.d.ts +3 -7
- package/build/filter.d.ts.map +1 -1
- package/build/filter.js +22 -18
- package/build/filter.js.map +1 -1
- package/build/helper.d.ts.map +1 -1
- package/build/index.d.ts +5 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -3
- package/build/index.js.map +1 -1
- package/build/materialize.d.ts +7 -0
- package/build/materialize.d.ts.map +1 -0
- package/build/materialize.js +34 -0
- package/build/materialize.js.map +1 -0
- package/build/protocol.d.ts +44 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +124 -0
- package/build/protocol.js.map +1 -0
- package/build/types.d.ts +169 -5
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +27 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/utils/entrypoint.d.ts.map +1 -1
- package/build/utils.d.ts +6 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +6 -0
- package/build/utils.js.map +1 -0
- package/package.json +6 -6
- package/src/consts.ts +0 -5
- package/src/entrypoint.ts +18 -8
- package/src/filter/types.ts +16 -0
- package/src/filter.ts +24 -17
- package/src/index.ts +5 -3
- package/src/materialize.ts +43 -0
- package/src/protocol.ts +191 -0
- package/src/types.local.ts +24 -0
- package/src/types.ts +200 -5
- package/src/utils.ts +5 -0
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,iBAAiB;IAC3B,EAAE,OAAO;IACT,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,iBAAiB;IAC3B,EAAE,OAAO;IACT,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB"}
|
package/build/consts.js
CHANGED
|
@@ -5,9 +5,4 @@ export var EntrypointOutcome;
|
|
|
5
5
|
EntrypointOutcome["Created"] = "created";
|
|
6
6
|
EntrypointOutcome["Finished"] = "finished";
|
|
7
7
|
})(EntrypointOutcome || (EntrypointOutcome = {}));
|
|
8
|
-
/**
|
|
9
|
-
* Service alias a transport registers under. The default protocol is the web one, so an application
|
|
10
|
-
* that binds nothing keeps talking HTTP.
|
|
11
|
-
*/
|
|
12
|
-
export const transportAlias = (protocol = 'http') => `transport:${protocol}`;
|
|
13
8
|
//# sourceMappingURL=consts.js.map
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,8BAAS,CAAA;IACT,0CAAqB,CAAA;IACrB,wCAAmB,CAAA;IACnB,0CAAqB,CAAA;AACvB,CAAC,EALW,iBAAiB,KAAjB,iBAAiB,QAK5B
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,8BAAS,CAAA;IACT,0CAAqB,CAAA;IACrB,wCAAmB,CAAA;IACnB,0CAAqB,CAAA;AACvB,CAAC,EALW,iBAAiB,KAAjB,iBAAiB,QAK5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGlD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAEjE,eAAO,MAAM,UAAU,EAAE,yBAAyB,CAAC,gBAAgB,CAkElE,CAAA"}
|
package/build/entrypoint.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { appendContextual } from '@owlmeans/context';
|
|
2
|
-
import {
|
|
2
|
+
import { routeAddressOf } from '@owlmeans/route/utils';
|
|
3
3
|
export const entrypoint = (route, opts) => {
|
|
4
4
|
const ep = appendContextual(route.route.alias, {
|
|
5
5
|
_entrypoint: true,
|
|
6
6
|
sticky: false,
|
|
7
7
|
route,
|
|
8
8
|
segment: () => ep.route.route.path,
|
|
9
|
-
path: () =>
|
|
10
|
-
mount: () =>
|
|
11
|
-
service: () =>
|
|
12
|
-
address: () =>
|
|
13
|
-
isLocal: () =>
|
|
9
|
+
path: () => routeAddressOf(ep.assertCtx()).resolvePath(ep.route.route),
|
|
10
|
+
mount: () => routeAddressOf(ep.assertCtx()).resolveMount(ep.route.route),
|
|
11
|
+
service: () => routeAddressOf(ep.assertCtx()).resolveService(ep.route.route),
|
|
12
|
+
address: () => routeAddressOf(ep.assertCtx()).resolveAddress(ep.route.route),
|
|
13
|
+
isLocal: () => routeAddressOf(ep.assertCtx()).isLocalRoute(ep.route.route),
|
|
14
14
|
parent: () => ep.route.route.parent == null ? null
|
|
15
15
|
: ep.assertCtx().entrypoint(ep.route.route.parent),
|
|
16
16
|
// Walked afresh on every call: a guard attached to an ancestor after this entrypoint was first
|
|
@@ -23,6 +23,18 @@ export const entrypoint = (route, opts) => {
|
|
|
23
23
|
}
|
|
24
24
|
return guards;
|
|
25
25
|
},
|
|
26
|
+
/**
|
|
27
|
+
* The gates standing over this entrypoint: its own, then an ancestor's for each gate service
|
|
28
|
+
* this entrypoint has not already named.
|
|
29
|
+
*
|
|
30
|
+
* KNOWN HAZARD, deliberately left alone: the dedup is by gate SERVICE, and two gates under one
|
|
31
|
+
* service are two different questions because their parameters differ — so a child that
|
|
32
|
+
* declares its own gate silently drops its ancestor's, which is the opposite of what
|
|
33
|
+
* "inherited" means. Anything that needs a group rule AND a member rule must therefore not
|
|
34
|
+
* express the group half as a gate under the same service. Changing this would widen every
|
|
35
|
+
* backend and socket entrypoint that today relies on the replacement, so it is a migration
|
|
36
|
+
* rather than a fix.
|
|
37
|
+
*/
|
|
26
38
|
getGates: () => {
|
|
27
39
|
const gates = ep.gate != null ? [[
|
|
28
40
|
ep.gate, ep.gateParams == null
|
package/build/entrypoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAGtD,MAAM,CAAC,MAAM,UAAU,GAAgD,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACrF,MAAM,EAAE,GAAqB,gBAAgB,CAAmB,KAAK,CAAC,KAAK,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
3
|
+
/** Builds the request/response schema filter of an entrypoint, one section at a time. */
|
|
4
|
+
export interface FilterHelper {
|
|
5
|
+
/** `filter` with its body schema set. */
|
|
6
|
+
body: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
7
|
+
/** `filter` with its query schema set. */
|
|
8
|
+
query: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
9
|
+
/** `filter` with its params schema set. */
|
|
10
|
+
params: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
11
|
+
/** `filter` with its response schema set — keyed by `code` when the filter already has responses. */
|
|
12
|
+
response: <T>(schema: JSONSchemaType<T>, code?: number, filter?: Filter) => Filter;
|
|
13
|
+
/** `filter` with its headers schema set. */
|
|
14
|
+
headers: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/filter/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IAC/D,0CAA0C;IAC1C,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IAChE,2CAA2C;IAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IACjE,qGAAqG;IACrG,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IAClF,4CAA4C;IAC5C,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/filter/types.ts"],"names":[],"mappings":""}
|
package/build/filter.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const query: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
5
|
-
export declare const params: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
6
|
-
export declare const response: <T>(schema: JSONSchemaType<T>, code?: number, filter?: Filter) => Filter;
|
|
7
|
-
export declare const headers: <T>(schema: JSONSchemaType<T>, filter?: Filter) => Filter;
|
|
1
|
+
import type { FilterHelper } from './filter/types.js';
|
|
2
|
+
export declare const createFilterHelper: () => FilterHelper;
|
|
3
|
+
export declare const filterHelper: FilterHelper;
|
|
8
4
|
//# sourceMappingURL=filter.d.ts.map
|
package/build/filter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,eAAO,MAAM,kBAAkB,QAAO,YA0BrC,CAAA;AAED,eAAO,MAAM,YAAY,cAAuB,CAAA"}
|
package/build/filter.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
export const createFilterHelper = () => {
|
|
2
|
+
const body = (schema, filter) => {
|
|
3
|
+
return { ...filter, body: schema };
|
|
4
|
+
};
|
|
5
|
+
const query = (schema, filter) => {
|
|
6
|
+
return { ...filter, query: schema };
|
|
7
|
+
};
|
|
8
|
+
const params = (schema, filter) => {
|
|
9
|
+
return { ...filter, params: schema };
|
|
10
|
+
};
|
|
11
|
+
const response = (schema, code, filter) => {
|
|
12
|
+
let _schema = schema;
|
|
13
|
+
if (filter?.response != null && code != null) {
|
|
14
|
+
_schema = { ...filter.response, [code]: schema };
|
|
15
|
+
}
|
|
16
|
+
return { ...filter, response: _schema };
|
|
17
|
+
};
|
|
18
|
+
const headers = (schema, filter) => {
|
|
19
|
+
return { ...filter, headers: schema };
|
|
20
|
+
};
|
|
21
|
+
return { body, query, params, response, headers };
|
|
19
22
|
};
|
|
23
|
+
export const filterHelper = createFilterHelper();
|
|
20
24
|
//# sourceMappingURL=filter.js.map
|
package/build/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAiB,EAAE;IACnD,MAAM,IAAI,GAAG,CAAI,MAAyB,EAAE,MAAe,EAAU,EAAE;QACrE,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAa,EAAE,CAAA;I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
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE9E,eAAO,MAAM,MAAM,WAAY,MAAM,SAAS,uBAAuB,KAAG,uBAAgD,CAAA;AAExH,eAAO,MAAM,KAAK,UAAW,MAAM,SAAS,uBAAuB,KAAG,uBACC,CAAA;AAEvE,eAAO,MAAM,IAAI,SAAU,MAAM,UAAU,MAAM,GAAG,MAAM,EAAE,SAAS,uBAAuB,KAAG,uBACtD,CAAA;AAEzC,eAAO,MAAM,eAAe,GAAI,CAAC,qBAAqB,OAAO,KAAG,gBAAgB,CAAC,CAAC,CAejF,CAAA"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type * from './types.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './filter.js';
|
|
4
|
-
export * from './helper.js';
|
|
2
|
+
export type * from './filter/types.js';
|
|
5
3
|
export * from './consts.js';
|
|
4
|
+
export * from './utils.js';
|
|
5
|
+
export * from './protocol.js';
|
|
6
|
+
export * from './materialize.js';
|
|
7
|
+
export { provideResponse } from './helper.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,
|
|
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,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * from './entrypoint.js';
|
|
2
|
-
export * from './filter.js';
|
|
3
|
-
export * from './helper.js';
|
|
4
1
|
export * from './consts.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
export * from './protocol.js';
|
|
4
|
+
export * from './materialize.js';
|
|
5
|
+
export { provideResponse } from './helper.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EntrypointProtocolDeclaration, MaterializedEntrypoint } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Make a local, mutable registration from a shared declaration. The protocol is never mutated;
|
|
4
|
+
* guards, route resolution and handlers belong exclusively to this materialized entrypoint.
|
|
5
|
+
*/
|
|
6
|
+
export declare const materializeEntrypoint: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol) => MaterializedEntrypoint<Protocol>;
|
|
7
|
+
//# sourceMappingURL=materialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materialize.d.ts","sourceRoot":"","sources":["../src/materialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmC,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAgCxH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,6BAA6B,YACxE,QAAQ,KACjB,sBAAsB,CAAC,QAAQ,CAGjC,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { entrypoint } from './entrypoint.js';
|
|
2
|
+
const filterOf = (protocol) => {
|
|
3
|
+
const request = protocol.contract?.requestSchemas;
|
|
4
|
+
const response = protocol.contract?.responseSchemas;
|
|
5
|
+
if (request == null && response == null)
|
|
6
|
+
return undefined;
|
|
7
|
+
return {
|
|
8
|
+
body: request?.body == null ? undefined : structuredClone(request.body),
|
|
9
|
+
params: request?.params == null ? undefined : structuredClone(request.params),
|
|
10
|
+
query: request?.query == null ? undefined : structuredClone(request.query),
|
|
11
|
+
headers: request?.headers == null ? undefined : structuredClone(request.headers),
|
|
12
|
+
// Fastify requires response serializers to be keyed by a status code. A protocol's
|
|
13
|
+
// ordinary response has no explicit outcome, so it is the normal successful 200 reply.
|
|
14
|
+
response: response == null ? undefined : {
|
|
15
|
+
...(response.default == null ? {} : { 200: structuredClone(response.default) }),
|
|
16
|
+
...Object.fromEntries(Object.entries(response.byStatus ?? {}).map(([status, schema]) => [
|
|
17
|
+
status, structuredClone(schema),
|
|
18
|
+
])),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const optionsOf = (protocol) => ({
|
|
23
|
+
sticky: protocol.sticky,
|
|
24
|
+
guards: [...protocol.guards],
|
|
25
|
+
gate: protocol.gate?.alias,
|
|
26
|
+
gateParams: protocol.gate == null ? undefined : [...protocol.gate.params],
|
|
27
|
+
filter: filterOf(protocol),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Make a local, mutable registration from a shared declaration. The protocol is never mutated;
|
|
31
|
+
* guards, route resolution and handlers belong exclusively to this materialized entrypoint.
|
|
32
|
+
*/
|
|
33
|
+
export const materializeEntrypoint = (protocol) => Object.assign(entrypoint({ route: { ...protocol.route.route } }, optionsOf(protocol)), { protocol });
|
|
34
|
+
//# sourceMappingURL=materialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;gBACtF,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;aAChC,CAAC,CAAC;SACJ;KACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,QAAuC,EAA2B,EAAE,CAAC,CAAC;IACvF,MAAM,EAAE,QAAQ,CAAC,MAAM;IACvB,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK;IAC1B,UAAU,EAAE,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;IACzE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC;CAC3B,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAAkB,EACgB,EAAE,CAAC,MAAM,CAAC,MAAM,CAClD,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,EACvE,EAAE,QAAQ,EAAE,CACb,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { EntrypointReference } from '@owlmeans/context';
|
|
2
|
+
import type { JSONSchemaType } from 'ajv';
|
|
3
|
+
import type { RouteModel } from '@owlmeans/route';
|
|
4
|
+
import type { EntrypointContract, EntrypointGate, EntrypointOptions, EntrypointProtocol, EntrypointProtocolDeclaration, EntrypointSchema, EntrypointTree, OpenRequest, OpenValue, RegisteredEntrypoint, RequestFromSources, RequestShape, RequestSources, ShapeSource, Typed } from './types.js';
|
|
5
|
+
export declare const schema: <T>(value: JSONSchemaType<T>) => EntrypointSchema<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Supplies type information where a response has no runtime schema, or attaches a type to an
|
|
8
|
+
* otherwise untyped schema literal at the declaration boundary.
|
|
9
|
+
*/
|
|
10
|
+
export declare function typed<T>(): Typed<T>;
|
|
11
|
+
export declare function typed<T>(schema: JSONSchemaType<T>): Typed<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Declare an exact request and response. The primary overload means a body request; use
|
|
14
|
+
* `contract.request` for independently-shaped request sections.
|
|
15
|
+
*/
|
|
16
|
+
export declare function contract(): EntrypointContract<{}, undefined>;
|
|
17
|
+
export declare function contract<Response>(response: ShapeSource<Response>): EntrypointContract<{}, Response>;
|
|
18
|
+
export declare function contract<Body extends OpenValue, Response>(body: ShapeSource<Body>, response: ShapeSource<Response>): EntrypointContract<{
|
|
19
|
+
body: Body;
|
|
20
|
+
}, Response>;
|
|
21
|
+
export declare namespace contract {
|
|
22
|
+
function request<Sources extends RequestSources, Response>(request: Sources, response: ShapeSource<Response>): EntrypointContract<RequestFromSources<Sources>, Response>;
|
|
23
|
+
}
|
|
24
|
+
/** Create an immutable protocol declaration from a route and its contract. */
|
|
25
|
+
export declare const protocol: <Request extends RequestShape, Response>(route: RouteModel, entrypointContract: EntrypointContract<Request, Response>, options?: EntrypointOptions) => EntrypointProtocol<Request, Response>;
|
|
26
|
+
export declare const openProtocol: (route: RouteModel, options?: EntrypointOptions) => EntrypointProtocol<OpenRequest, OpenValue>;
|
|
27
|
+
export declare const entrypointRef: <Request extends RequestShape = OpenRequest, Response = OpenValue>(alias: string) => EntrypointReference<RegisteredEntrypoint<Request, Response>>;
|
|
28
|
+
export declare const aliasOf: (reference: EntrypointReference | string) => string;
|
|
29
|
+
export declare const isEntrypointProtocol: (value: object) => value is EntrypointProtocolDeclaration;
|
|
30
|
+
/** Flatten an exported protocol tree for a layer-specific materializer. */
|
|
31
|
+
export declare const protocols: (tree: EntrypointTree) => EntrypointProtocolDeclaration[];
|
|
32
|
+
/**
|
|
33
|
+
* Rebuild an immutable protocol tree while transforming its declarations.
|
|
34
|
+
*
|
|
35
|
+
* Protocol consumers keep addressing declarations by their exported tree path; a cross-cutting
|
|
36
|
+
* concern such as a coguard therefore never needs to flatten the tree and recover declarations
|
|
37
|
+
* by alias.
|
|
38
|
+
*/
|
|
39
|
+
export declare const mapProtocols: <Tree extends EntrypointTree>(tree: Tree, mapper: (protocol: EntrypointProtocolDeclaration) => EntrypointProtocolDeclaration) => Tree;
|
|
40
|
+
/** Resolve the gates a protocol inherits through its route parents without materializing it. */
|
|
41
|
+
export declare const gatesOf: (protocol: EntrypointProtocolDeclaration, tree: EntrypointTree) => readonly EntrypointGate[];
|
|
42
|
+
/** Clone an immutable protocol while preserving its request/response pair. */
|
|
43
|
+
export declare const decorateEntrypoint: <Protocol extends EntrypointProtocolDeclaration>(protocol: Protocol, options: EntrypointOptions) => Protocol;
|
|
44
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,KAAK,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,YAAY,EAAE,cAAc,EAA0B,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAExT,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,KAAG,gBAAgB,CAAC,CAAC,CACzC,CAAA;AAE9B;;;GAGG;AACH,wBAAgB,K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,SAAS,SACrF,MAAM,KACZ,mBAAmB,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAgB,CAAA;AAE9E,eAAO,MAAM,OAAO,cAAe,mBAAmB,GAAG,MAAM,KAAG,MACL,CAAA;AAE7D,eAAO,MAAM,oBAAoB,UAAW,MAAM,KAAG,KAAK,IAAI,6BACL,CAAA;AAEzD,2EAA2E;AAC3E,eAAO,MAAM,SAAS,SAAU,cAAc,KAAG,6BAA6B,EAe7E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,IAAI,SAAS,cAAc,QAChD,IAAI,UACF,CAAC,QAAQ,EAAE,6BAA6B,KAAK,6BAA6B,KACjF,IAKO,CAAA;AAEV,gGAAgG;AAChG,eAAO,MAAM,OAAO,aACR,6BAA6B,QACjC,cAAc,KACnB,SAAS,cAAc,EAiBzB,CAAA;AAED,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,GAAI,QAAQ,SAAS,6BAA6B,YACrE,QAAQ,WACT,iBAAiB,KACzB,QAKD,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export const schema = (value) => value;
|
|
2
|
+
export function typed(schema) {
|
|
3
|
+
return schema == null
|
|
4
|
+
? { kind: 'entrypoint-type' }
|
|
5
|
+
: { kind: 'entrypoint-type', schema };
|
|
6
|
+
}
|
|
7
|
+
const schemaOf = (source) => {
|
|
8
|
+
if (source == null)
|
|
9
|
+
return undefined;
|
|
10
|
+
const schema = 'kind' in source && source.kind === 'entrypoint-type'
|
|
11
|
+
? source.schema
|
|
12
|
+
: source;
|
|
13
|
+
return schema == null ? undefined : structuredClone(schema);
|
|
14
|
+
};
|
|
15
|
+
const responseSchemasOf = (source) => {
|
|
16
|
+
const schema = schemaOf(source);
|
|
17
|
+
return schema == null ? undefined : { default: schema };
|
|
18
|
+
};
|
|
19
|
+
export function contract(first, second) {
|
|
20
|
+
const body = second == null ? undefined : first;
|
|
21
|
+
const response = second ?? first;
|
|
22
|
+
return {
|
|
23
|
+
kind: 'entrypoint-contract',
|
|
24
|
+
requestSchemas: { body: schemaOf(body) },
|
|
25
|
+
responseSchemas: responseSchemasOf(response),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
(function (contract) {
|
|
29
|
+
function request(request, response) {
|
|
30
|
+
return {
|
|
31
|
+
kind: 'entrypoint-contract',
|
|
32
|
+
requestSchemas: {
|
|
33
|
+
body: schemaOf(request.body),
|
|
34
|
+
params: schemaOf(request.params),
|
|
35
|
+
query: schemaOf(request.query),
|
|
36
|
+
headers: schemaOf(request.headers),
|
|
37
|
+
},
|
|
38
|
+
responseSchemas: responseSchemasOf(response),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
contract.request = request;
|
|
42
|
+
})(contract || (contract = {}));
|
|
43
|
+
const guardsOf = (guards) => guards == null
|
|
44
|
+
? []
|
|
45
|
+
: typeof guards === 'string' ? [guards] : [...guards];
|
|
46
|
+
const gateOf = (gate) => gate == null
|
|
47
|
+
? undefined
|
|
48
|
+
: {
|
|
49
|
+
alias: gate.alias,
|
|
50
|
+
params: gate.params == null ? [] : typeof gate.params === 'string' ? [gate.params] : [...gate.params],
|
|
51
|
+
};
|
|
52
|
+
/** Create an immutable protocol declaration from a route and its contract. */
|
|
53
|
+
export const protocol = (route, entrypointContract, options) => Object.freeze({
|
|
54
|
+
kind: 'entrypoint-protocol',
|
|
55
|
+
alias: route.route.alias,
|
|
56
|
+
route: Object.freeze({ route: Object.freeze({ ...route.route }) }),
|
|
57
|
+
contract: entrypointContract,
|
|
58
|
+
sticky: options?.sticky ?? false,
|
|
59
|
+
guards: Object.freeze(guardsOf(options?.guards)),
|
|
60
|
+
gate: gateOf(options?.gate),
|
|
61
|
+
});
|
|
62
|
+
export const openProtocol = (route, options) => Object.freeze({
|
|
63
|
+
kind: 'entrypoint-protocol',
|
|
64
|
+
alias: route.route.alias,
|
|
65
|
+
route: Object.freeze({ route: Object.freeze({ ...route.route }) }),
|
|
66
|
+
sticky: options?.sticky ?? false,
|
|
67
|
+
guards: Object.freeze(guardsOf(options?.guards)),
|
|
68
|
+
gate: gateOf(options?.gate),
|
|
69
|
+
});
|
|
70
|
+
export const entrypointRef = (alias) => ({ alias });
|
|
71
|
+
export const aliasOf = (reference) => typeof reference === 'string' ? reference : reference.alias;
|
|
72
|
+
export const isEntrypointProtocol = (value) => 'kind' in value && value.kind === 'entrypoint-protocol';
|
|
73
|
+
/** Flatten an exported protocol tree for a layer-specific materializer. */
|
|
74
|
+
export const protocols = (tree) => {
|
|
75
|
+
const result = [];
|
|
76
|
+
const visit = (node) => {
|
|
77
|
+
Object.values(node).forEach((entry) => {
|
|
78
|
+
if (isEntrypointProtocol(entry)) {
|
|
79
|
+
result.push(entry);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
visit(entry);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
visit(tree);
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Rebuild an immutable protocol tree while transforming its declarations.
|
|
91
|
+
*
|
|
92
|
+
* Protocol consumers keep addressing declarations by their exported tree path; a cross-cutting
|
|
93
|
+
* concern such as a coguard therefore never needs to flatten the tree and recover declarations
|
|
94
|
+
* by alias.
|
|
95
|
+
*/
|
|
96
|
+
export const mapProtocols = (tree, mapper) => Object.freeze(Object.fromEntries(Object.entries(tree).map(([key, entry]) => [
|
|
97
|
+
key,
|
|
98
|
+
isEntrypointProtocol(entry) ? mapper(entry) : mapProtocols(entry, mapper),
|
|
99
|
+
])));
|
|
100
|
+
/** Resolve the gates a protocol inherits through its route parents without materializing it. */
|
|
101
|
+
export const gatesOf = (protocol, tree) => {
|
|
102
|
+
const byAlias = new Map(protocols(tree).map(candidate => [candidate.alias, candidate]));
|
|
103
|
+
const result = [];
|
|
104
|
+
const visited = new Set();
|
|
105
|
+
let current = protocol;
|
|
106
|
+
while (current != null && !visited.has(current.alias)) {
|
|
107
|
+
visited.add(current.alias);
|
|
108
|
+
if (current.gate != null && !result.some(gate => gate.alias === current.gate.alias)) {
|
|
109
|
+
result.push(current.gate);
|
|
110
|
+
}
|
|
111
|
+
current = current.route.route.parent == null
|
|
112
|
+
? undefined
|
|
113
|
+
: byAlias.get(current.route.route.parent);
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
/** Clone an immutable protocol while preserving its request/response pair. */
|
|
118
|
+
export const decorateEntrypoint = (protocol, options) => Object.freeze({
|
|
119
|
+
...protocol,
|
|
120
|
+
sticky: options.sticky ?? protocol.sticky,
|
|
121
|
+
guards: options.guards == null ? protocol.guards : guardsOf(options.guards),
|
|
122
|
+
gate: options.gate == null ? protocol.gate : gateOf(options.gate),
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAI,KAAwB,EAAuB,EAAE,CACzE,KAA4B,CAAA;AAQ9B,MAAM,UAAU,KAAK,CAAI,MAA0B;IACjD,OAAO,MAAM,IAAI,IAAI;QACnB,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE;QAC7B,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAA;AACzC,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,MAAkC,EAA+B,EAAE;IACnF,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,SAAS,CAAA;IACpC,MAAM,MAAM,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB;QAClE,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,MAAM,CAAA;IAEV,OAAO,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,e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