@owlmeans/entrypoint 0.1.18-rc.39 → 0.1.18-rc.40
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 +2 -2
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/entrypoint/SKILL.md +1 -1
- 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/filter.d.ts +20 -5
- package/build/filter.d.ts.map +1 -1
- package/build/filter.js +7 -5
- package/build/filter.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/materialize.d.ts +1 -6
- package/build/materialize.d.ts.map +1 -1
- package/build/materialize.js.map +1 -1
- package/build/protocol.d.ts +3 -190
- package/build/protocol.d.ts.map +1 -1
- package/build/protocol.js.map +1 -1
- package/build/types.d.ts +168 -2
- 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.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 +5 -5
- package/src/consts.ts +0 -5
- package/src/filter.ts +9 -5
- package/src/index.ts +1 -0
- package/src/materialize.ts +1 -7
- package/src/protocol.ts +3 -214
- package/src/types.local.ts +24 -0
- package/src/types.ts +199 -2
- package/src/utils.ts +5 -0
package/build/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ResolvedServiceRoute, RouteAddress, RouteModel, RouteProtocol } from '@owlmeans/route';
|
|
2
|
-
import type { InitializedService, LazyService, BasicEntrypoint } from '@owlmeans/context';
|
|
3
|
-
import type { AnySchemaObject } from 'ajv';
|
|
2
|
+
import type { InitializedService, LazyService, BasicEntrypoint, EntrypointReference } from '@owlmeans/context';
|
|
3
|
+
import type { AnySchemaObject, JSONSchemaType } from 'ajv';
|
|
4
4
|
import type { EntrypointOutcome } from './consts.js';
|
|
5
5
|
import type { Auth } from '@owlmeans/auth';
|
|
6
|
+
import type { AnyShapeSource, entrypointSchemaType, SourceValue, TypeToken, UrlRequest } from './types.local.js';
|
|
7
|
+
import type { createFilterHelper } from './filter.js';
|
|
6
8
|
/**
|
|
7
9
|
* A URL unit: an immutable route declaration plus what guards, gates and schemas it answers under.
|
|
8
10
|
*
|
|
@@ -130,4 +132,168 @@ export interface EntrypointTransport extends InitializedService {
|
|
|
130
132
|
readonly protocol: RouteProtocol;
|
|
131
133
|
handle: EntrypointHandler;
|
|
132
134
|
}
|
|
135
|
+
/** A deliberately broad value used only by declarations without an I/O contract. */
|
|
136
|
+
export type OpenValue = object | string | number | boolean | bigint | null | undefined;
|
|
137
|
+
/** The four independent request sections an entrypoint may declare. */
|
|
138
|
+
export interface RequestShape {
|
|
139
|
+
body?: OpenValue;
|
|
140
|
+
params?: object;
|
|
141
|
+
query?: object;
|
|
142
|
+
headers?: object;
|
|
143
|
+
}
|
|
144
|
+
export interface RuntimeRequestSchemas {
|
|
145
|
+
body?: AnySchemaObject;
|
|
146
|
+
params?: AnySchemaObject;
|
|
147
|
+
query?: AnySchemaObject;
|
|
148
|
+
headers?: AnySchemaObject;
|
|
149
|
+
}
|
|
150
|
+
export interface RuntimeResponseSchemas {
|
|
151
|
+
default?: AnySchemaObject;
|
|
152
|
+
byStatus?: Readonly<Record<number, AnySchemaObject>>;
|
|
153
|
+
}
|
|
154
|
+
/** The runtime schemas and compile-time request/response pair attached to one protocol. */
|
|
155
|
+
export interface EntrypointContract<Request extends RequestShape, Response> {
|
|
156
|
+
readonly kind: 'entrypoint-contract';
|
|
157
|
+
readonly requestSchemas: RuntimeRequestSchemas;
|
|
158
|
+
readonly responseSchemas?: RuntimeResponseSchemas;
|
|
159
|
+
readonly requestType?: Request;
|
|
160
|
+
readonly responseType?: Response;
|
|
161
|
+
}
|
|
162
|
+
/** Runtime fields common to every protocol, regardless of its compile-time request/reply pair. */
|
|
163
|
+
export interface EntrypointProtocolDeclaration {
|
|
164
|
+
readonly kind: 'entrypoint-protocol';
|
|
165
|
+
readonly alias: string;
|
|
166
|
+
readonly route: RouteModel;
|
|
167
|
+
readonly contract?: Pick<EntrypointContract<RequestShape, OpenValue>, 'kind' | 'requestSchemas' | 'responseSchemas'>;
|
|
168
|
+
readonly sticky: boolean;
|
|
169
|
+
readonly guards: readonly string[];
|
|
170
|
+
readonly gate?: {
|
|
171
|
+
readonly alias: string;
|
|
172
|
+
readonly params: readonly string[];
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** A context-bound entrypoint made from an immutable protocol declaration. */
|
|
176
|
+
export type MaterializedEntrypoint<Protocol extends EntrypointProtocolDeclaration> = CommonEntrypoint & {
|
|
177
|
+
readonly protocol: Protocol;
|
|
178
|
+
};
|
|
179
|
+
/** The request accepted by a declaration that intentionally supplies no contract. */
|
|
180
|
+
export interface OpenRequest {
|
|
181
|
+
body?: object;
|
|
182
|
+
params?: object;
|
|
183
|
+
query?: object;
|
|
184
|
+
headers?: object;
|
|
185
|
+
}
|
|
186
|
+
/** Addressing and transport controls are never part of an entrypoint's payload contract. */
|
|
187
|
+
export interface CallOptions {
|
|
188
|
+
auth?: Auth;
|
|
189
|
+
host?: string;
|
|
190
|
+
base?: string | boolean;
|
|
191
|
+
unsecure?: boolean;
|
|
192
|
+
timeout?: number;
|
|
193
|
+
signal?: AbortSignal;
|
|
194
|
+
}
|
|
195
|
+
/** A type-only contract source, optionally paired with an AJV schema. */
|
|
196
|
+
export type Typed<T> = TypeToken & {
|
|
197
|
+
readonly value?: T;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* A JSON schema carrying the model type it validates. Use `schema<Model>(...)` once beside the
|
|
201
|
+
* model; every protocol that consumes it then infers the model without another generic.
|
|
202
|
+
*/
|
|
203
|
+
export type EntrypointSchema<T> = JSONSchemaType<T> & {
|
|
204
|
+
readonly [entrypointSchemaType]: T;
|
|
205
|
+
};
|
|
206
|
+
/** A schema or an explicit type-only source for one request/response value. */
|
|
207
|
+
export type ShapeSource<T> = EntrypointSchema<T> | JSONSchemaType<T> | Typed<T>;
|
|
208
|
+
export interface RequestSources {
|
|
209
|
+
body?: AnyShapeSource;
|
|
210
|
+
params?: AnyShapeSource;
|
|
211
|
+
query?: AnyShapeSource;
|
|
212
|
+
headers?: AnyShapeSource;
|
|
213
|
+
}
|
|
214
|
+
/** An access gate declared by a protocol, including inherited parent declarations. */
|
|
215
|
+
export interface EntrypointGate {
|
|
216
|
+
readonly alias: string;
|
|
217
|
+
readonly params: readonly string[];
|
|
218
|
+
}
|
|
219
|
+
export type RequestFromSources<Sources extends RequestSources> = (Sources extends {
|
|
220
|
+
body: infer Source;
|
|
221
|
+
} ? {
|
|
222
|
+
body: SourceValue<Source>;
|
|
223
|
+
} : {}) & (Sources extends {
|
|
224
|
+
params: infer Source;
|
|
225
|
+
} ? {
|
|
226
|
+
params: SourceValue<Source>;
|
|
227
|
+
} : {}) & (Sources extends {
|
|
228
|
+
query: infer Source;
|
|
229
|
+
} ? {
|
|
230
|
+
query: SourceValue<Source>;
|
|
231
|
+
} : {}) & (Sources extends {
|
|
232
|
+
headers: infer Source;
|
|
233
|
+
} ? {
|
|
234
|
+
headers: SourceValue<Source>;
|
|
235
|
+
} : {});
|
|
236
|
+
export interface EntrypointOptions {
|
|
237
|
+
sticky?: boolean;
|
|
238
|
+
guards?: string | readonly string[];
|
|
239
|
+
gate?: {
|
|
240
|
+
alias: string;
|
|
241
|
+
params?: string | readonly string[];
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export interface EntrypointResult<Response> {
|
|
245
|
+
value: Response;
|
|
246
|
+
outcome: EntrypointOutcome;
|
|
247
|
+
}
|
|
248
|
+
export type CallArguments<Request extends RequestShape> = {} extends Request ? [request?: Request & CallOptions] : [request: Request & CallOptions];
|
|
249
|
+
export type UrlArguments<Request extends RequestShape> = {} extends UrlRequest<Request> ? [request?: UrlRequest<Request> & CallOptions] : [request: UrlRequest<Request> & CallOptions];
|
|
250
|
+
export interface EntrypointRequestMeta {
|
|
251
|
+
alias: string;
|
|
252
|
+
auth?: Auth;
|
|
253
|
+
entity?: ResolvedEntity;
|
|
254
|
+
path: string;
|
|
255
|
+
canceled?: boolean;
|
|
256
|
+
cancel?: () => void;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* A protocol request at an implementation boundary.
|
|
260
|
+
*
|
|
261
|
+
* Transport metadata and empty request sections remain available to handlers; a declared section
|
|
262
|
+
* then refines that base shape to its protocol contract.
|
|
263
|
+
*/
|
|
264
|
+
export type HandlerRequest<Request extends RequestShape> = AbstractRequest & Request & EntrypointRequestMeta;
|
|
265
|
+
/**
|
|
266
|
+
* An immutable shared declaration. Its inherited reference type is what gives a context lookup
|
|
267
|
+
* the exact registered entrypoint type without a consumer-supplied generic.
|
|
268
|
+
*/
|
|
269
|
+
export interface EntrypointProtocol<Request extends RequestShape = RequestShape, Response = OpenValue> extends EntrypointProtocolDeclaration, EntrypointReference<RegisteredEntrypoint<Request, Response>> {
|
|
270
|
+
readonly contract?: EntrypointContract<Request, Response>;
|
|
271
|
+
}
|
|
272
|
+
/** The context-bound counterpart of an immutable protocol declaration. */
|
|
273
|
+
export interface RegisteredEntrypoint<Request extends RequestShape, Response> extends BasicEntrypoint {
|
|
274
|
+
readonly protocol: EntrypointProtocol<Request, Response>;
|
|
275
|
+
call: (...args: CallArguments<Request>) => Promise<Response>;
|
|
276
|
+
invoke: (...args: CallArguments<Request>) => Promise<EntrypointResult<Response>>;
|
|
277
|
+
url: (...args: UrlArguments<Request>) => Promise<string>;
|
|
278
|
+
validate: (...args: CallArguments<Request>) => Promise<boolean>;
|
|
279
|
+
}
|
|
280
|
+
export type RequestOf<Protocol extends EntrypointProtocolDeclaration> = Protocol extends EntrypointProtocol<infer Request, infer _Response> ? Request : OpenRequest;
|
|
281
|
+
export type ResponseOf<Protocol extends EntrypointProtocolDeclaration> = Protocol extends EntrypointProtocol<infer _Request, infer Response> ? Response : OpenValue;
|
|
282
|
+
export type BodyOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends {
|
|
283
|
+
body: infer Body;
|
|
284
|
+
} ? Body : OpenValue;
|
|
285
|
+
export type ParamsOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends {
|
|
286
|
+
params: infer Params;
|
|
287
|
+
} ? Params : object;
|
|
288
|
+
export type QueryOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends {
|
|
289
|
+
query: infer Query;
|
|
290
|
+
} ? Query : object;
|
|
291
|
+
export type HeadersOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends {
|
|
292
|
+
headers: infer Headers;
|
|
293
|
+
} ? Headers : object;
|
|
294
|
+
export type CallRequestOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> & CallOptions;
|
|
295
|
+
export interface EntrypointTree {
|
|
296
|
+
readonly [key: string]: EntrypointProtocolDeclaration | EntrypointTree;
|
|
297
|
+
}
|
|
298
|
+
export type FilterHelper = ReturnType<typeof createFilterHelper>;
|
|
133
299
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpG,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAA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chemaObject } from 'ajv';
|
|
2
|
+
import type { EntrypointSchema, OpenValue, RequestShape, Typed } from './types.js';
|
|
3
|
+
export interface TypeToken {
|
|
4
|
+
readonly kind: 'entrypoint-type';
|
|
5
|
+
readonly schema?: AnySchemaObject;
|
|
6
|
+
}
|
|
7
|
+
export declare const entrypointSchemaType: unique symbol;
|
|
8
|
+
export type AnyShapeSource = AnySchemaObject | TypeToken;
|
|
9
|
+
export type SourceValue<Source> = Source extends Typed<infer Value> ? Value : Source extends EntrypointSchema<infer Value> ? Value : Source extends JSONSchemaType<infer Value> ? Value extends OpenValue ? Value : OpenValue : OpenValue;
|
|
10
|
+
export type UrlRequest<Request extends RequestShape> = (Request extends {
|
|
11
|
+
params: infer Params;
|
|
12
|
+
} ? {
|
|
13
|
+
params: Params;
|
|
14
|
+
} : Request extends {
|
|
15
|
+
params?: infer Params;
|
|
16
|
+
} ? {
|
|
17
|
+
params?: Params;
|
|
18
|
+
} : {}) & (Request extends {
|
|
19
|
+
query: infer Query;
|
|
20
|
+
} ? {
|
|
21
|
+
query: Query;
|
|
22
|
+
} : Request extends {
|
|
23
|
+
query?: infer Query;
|
|
24
|
+
} ? {
|
|
25
|
+
query?: Query;
|
|
26
|
+
} : {});
|
|
27
|
+
//# sourceMappingURL=types.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAA;CAClC;AAED,MAAM,CAAC,OAAO,CAAC,MAAM,oBAAoB,EAAE,OAAO,MAAM,CAAA;AAExD,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,SAAS,CAAA;AAExD,MAAM,MAAM,WAAW,CAAC,MAAM,IAC5B,MAAM,SAAS,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,GACrC,MAAM,SAAS,gBAAgB,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,GAClD,MAAM,SAAS,cAAc,CAAC,MAAM,KAAK,CAAC,GACxC,KAAK,SAAS,SAAS,GAAG,KAAK,GAAG,SAAS,GAC3C,SAAS,CAAA;AAEnB,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,YAAY,IACjD,CAAC,OAAO,SAAS;IAAE,MAAM,EAAE,MAAM,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1D,OAAO,SAAS;IAAE,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,EAAE,CAAC,GACvE,CAAC,OAAO,SAAS;IAAE,KAAK,EAAE,MAAM,KAAK,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,GACxD,OAAO,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAA;CAAE,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,cAAc,cAAc,MAAM,WAAqC,CAAA"}
|
package/build/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAQ,GAAW,MAAM,EAAE,EAAE,CAAC,aAAa,QAAQ,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/entrypoint",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.40",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
32
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
33
|
-
"@owlmeans/route": "^0.1.18-rc.
|
|
34
|
-
"ajv": "^8.
|
|
31
|
+
"@owlmeans/auth": "^0.1.18-rc.39",
|
|
32
|
+
"@owlmeans/context": "^0.1.18-rc.33",
|
|
33
|
+
"@owlmeans/route": "^0.1.18-rc.34",
|
|
34
|
+
"ajv": "^8.20.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@owlmeans/dep-config": "workspace:*",
|
package/src/consts.ts
CHANGED
|
@@ -6,8 +6,3 @@ export enum EntrypointOutcome {
|
|
|
6
6
|
Finished = 'finished'
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Service alias a transport registers under. The default protocol is the web one, so an application
|
|
11
|
-
* that binds nothing keeps talking HTTP.
|
|
12
|
-
*/
|
|
13
|
-
export const transportAlias = (protocol: string = 'http') => `transport:${protocol}`
|
package/src/filter.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { JSONSchemaType } from 'ajv'
|
|
2
2
|
import type { Filter } from './types.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const body = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
5
5
|
return { ...filter, body: schema as any }
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const query = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
9
9
|
return { ...filter, query: schema as any }
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const params = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
13
13
|
return { ...filter, params: schema as any }
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const response = <T>(schema: JSONSchemaType<T>, code?: number, filter?: Filter): Filter => {
|
|
17
17
|
let _schema: any = schema
|
|
18
18
|
if (filter?.response != null && code != null) {
|
|
19
19
|
_schema = { ...filter.response, [code]: schema }
|
|
@@ -21,6 +21,10 @@ export const response = <T>(schema: JSONSchemaType<T>, code?: number, filter?: F
|
|
|
21
21
|
return { ...filter, response: _schema }
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const headers = <T>(schema: JSONSchemaType<T>, filter?: Filter): Filter => {
|
|
25
25
|
return { ...filter, headers: schema as any }
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
export const createFilterHelper = () => ({ body, query, params, response, headers })
|
|
29
|
+
|
|
30
|
+
export const filterHelper = createFilterHelper()
|
package/src/index.ts
CHANGED
package/src/materialize.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { entrypoint } from './entrypoint.js'
|
|
2
|
-
import type {
|
|
3
|
-
import type { EntrypointProtocolDeclaration } from './protocol.js'
|
|
4
|
-
|
|
5
|
-
/** A context-bound entrypoint made from an immutable protocol declaration. */
|
|
6
|
-
export type MaterializedEntrypoint<Protocol extends EntrypointProtocolDeclaration> = CommonEntrypoint & {
|
|
7
|
-
readonly protocol: Protocol
|
|
8
|
-
}
|
|
2
|
+
import type { CommonEntrypointOptions, Filter, EntrypointProtocolDeclaration, MaterializedEntrypoint } from './types.js'
|
|
9
3
|
|
|
10
4
|
const filterOf = (protocol: EntrypointProtocolDeclaration): Filter | undefined => {
|
|
11
5
|
const request = protocol.contract?.requestSchemas
|
package/src/protocol.ts
CHANGED
|
@@ -1,66 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BasicEntrypoint, EntrypointReference } from '@owlmeans/context'
|
|
1
|
+
import type { EntrypointReference } from '@owlmeans/context'
|
|
3
2
|
import type { JSONSchemaType, AnySchemaObject } from 'ajv'
|
|
4
3
|
import type { RouteModel } from '@owlmeans/route'
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { AbstractRequest } from './types.js'
|
|
8
|
-
|
|
9
|
-
/** A deliberately broad value used only by declarations without an I/O contract. */
|
|
10
|
-
export type OpenValue = object | string | number | boolean | bigint | null | undefined
|
|
11
|
-
|
|
12
|
-
/** The request accepted by a declaration that intentionally supplies no contract. */
|
|
13
|
-
export interface OpenRequest {
|
|
14
|
-
body?: object
|
|
15
|
-
params?: object
|
|
16
|
-
query?: object
|
|
17
|
-
headers?: object
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** The four independent request sections an entrypoint may declare. */
|
|
21
|
-
export interface RequestShape {
|
|
22
|
-
body?: OpenValue
|
|
23
|
-
params?: object
|
|
24
|
-
query?: object
|
|
25
|
-
headers?: object
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Addressing and transport controls are never part of an entrypoint's payload contract. */
|
|
29
|
-
export interface CallOptions {
|
|
30
|
-
auth?: Auth
|
|
31
|
-
host?: string
|
|
32
|
-
base?: string | boolean
|
|
33
|
-
unsecure?: boolean
|
|
34
|
-
timeout?: number
|
|
35
|
-
signal?: AbortSignal
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface TypeToken {
|
|
39
|
-
readonly kind: 'entrypoint-type'
|
|
40
|
-
readonly schema?: AnySchemaObject
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** A type-only contract source, optionally paired with an AJV schema. */
|
|
44
|
-
export type Typed<T> = TypeToken & { readonly value?: T }
|
|
45
|
-
|
|
46
|
-
declare const entrypointSchemaType: unique symbol
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* A JSON schema carrying the model type it validates. Use `schema<Model>(...)` once beside the
|
|
50
|
-
* model; every protocol that consumes it then infers the model without another generic.
|
|
51
|
-
*/
|
|
52
|
-
export type EntrypointSchema<T> = JSONSchemaType<T> & {
|
|
53
|
-
readonly [entrypointSchemaType]: T
|
|
54
|
-
}
|
|
4
|
+
import type { AnyShapeSource } from './types.local.js'
|
|
5
|
+
import type { EntrypointContract, EntrypointGate, EntrypointOptions, EntrypointProtocol, EntrypointProtocolDeclaration, EntrypointSchema, EntrypointTree, OpenRequest, OpenValue, RegisteredEntrypoint, RequestFromSources, RequestShape, RequestSources, RuntimeResponseSchemas, ShapeSource, Typed } from './types.js'
|
|
55
6
|
|
|
56
7
|
export const schema = <T>(value: JSONSchemaType<T>): EntrypointSchema<T> =>
|
|
57
8
|
value as EntrypointSchema<T>
|
|
58
9
|
|
|
59
|
-
/** A schema or an explicit type-only source for one request/response value. */
|
|
60
|
-
export type ShapeSource<T> = EntrypointSchema<T> | JSONSchemaType<T> | Typed<T>
|
|
61
|
-
|
|
62
|
-
type AnyShapeSource = AnySchemaObject | TypeToken
|
|
63
|
-
|
|
64
10
|
/**
|
|
65
11
|
* Supplies type information where a response has no runtime schema, or attaches a type to an
|
|
66
12
|
* otherwise untyped schema literal at the declaration boundary.
|
|
@@ -73,68 +19,6 @@ export function typed<T>(schema?: JSONSchemaType<T>): Typed<T> {
|
|
|
73
19
|
: { kind: 'entrypoint-type', schema }
|
|
74
20
|
}
|
|
75
21
|
|
|
76
|
-
export interface RequestSources {
|
|
77
|
-
body?: AnyShapeSource
|
|
78
|
-
params?: AnyShapeSource
|
|
79
|
-
query?: AnyShapeSource
|
|
80
|
-
headers?: AnyShapeSource
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface RuntimeRequestSchemas {
|
|
84
|
-
body?: AnySchemaObject
|
|
85
|
-
params?: AnySchemaObject
|
|
86
|
-
query?: AnySchemaObject
|
|
87
|
-
headers?: AnySchemaObject
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface RuntimeResponseSchemas {
|
|
91
|
-
default?: AnySchemaObject
|
|
92
|
-
byStatus?: Readonly<Record<number, AnySchemaObject>>
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** The runtime schemas and compile-time request/response pair attached to one protocol. */
|
|
96
|
-
export interface EntrypointContract<Request extends RequestShape, Response> {
|
|
97
|
-
readonly kind: 'entrypoint-contract'
|
|
98
|
-
readonly requestSchemas: RuntimeRequestSchemas
|
|
99
|
-
readonly responseSchemas?: RuntimeResponseSchemas
|
|
100
|
-
readonly requestType?: Request
|
|
101
|
-
readonly responseType?: Response
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Runtime fields common to every protocol, regardless of its compile-time request/reply pair. */
|
|
105
|
-
export interface EntrypointProtocolDeclaration {
|
|
106
|
-
readonly kind: 'entrypoint-protocol'
|
|
107
|
-
readonly alias: string
|
|
108
|
-
readonly route: RouteModel
|
|
109
|
-
readonly contract?: Pick<EntrypointContract<RequestShape, OpenValue>,
|
|
110
|
-
'kind' | 'requestSchemas' | 'responseSchemas'>
|
|
111
|
-
readonly sticky: boolean
|
|
112
|
-
readonly guards: readonly string[]
|
|
113
|
-
readonly gate?: {
|
|
114
|
-
readonly alias: string
|
|
115
|
-
readonly params: readonly string[]
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** An access gate declared by a protocol, including inherited parent declarations. */
|
|
120
|
-
export interface EntrypointGate {
|
|
121
|
-
readonly alias: string
|
|
122
|
-
readonly params: readonly string[]
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
type SourceValue<Source> =
|
|
126
|
-
Source extends Typed<infer Value> ? Value
|
|
127
|
-
: Source extends EntrypointSchema<infer Value> ? Value
|
|
128
|
-
: Source extends JSONSchemaType<infer Value>
|
|
129
|
-
? Value extends OpenValue ? Value : OpenValue
|
|
130
|
-
: OpenValue
|
|
131
|
-
|
|
132
|
-
type RequestFromSources<Sources extends RequestSources> =
|
|
133
|
-
(Sources extends { body: infer Source } ? { body: SourceValue<Source> } : {})
|
|
134
|
-
& (Sources extends { params: infer Source } ? { params: SourceValue<Source> } : {})
|
|
135
|
-
& (Sources extends { query: infer Source } ? { query: SourceValue<Source> } : {})
|
|
136
|
-
& (Sources extends { headers: infer Source } ? { headers: SourceValue<Source> } : {})
|
|
137
|
-
|
|
138
22
|
const schemaOf = (source: AnyShapeSource | undefined): AnySchemaObject | undefined => {
|
|
139
23
|
if (source == null) return undefined
|
|
140
24
|
const schema = 'kind' in source && source.kind === 'entrypoint-type'
|
|
@@ -189,97 +73,6 @@ export namespace contract {
|
|
|
189
73
|
}
|
|
190
74
|
}
|
|
191
75
|
|
|
192
|
-
export interface EntrypointOptions {
|
|
193
|
-
sticky?: boolean
|
|
194
|
-
guards?: string | readonly string[]
|
|
195
|
-
gate?: {
|
|
196
|
-
alias: string
|
|
197
|
-
params?: string | readonly string[]
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export interface EntrypointResult<Response> {
|
|
202
|
-
value: Response
|
|
203
|
-
outcome: EntrypointOutcome
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export type CallArguments<Request extends RequestShape> = {} extends Request
|
|
207
|
-
? [request?: Request & CallOptions]
|
|
208
|
-
: [request: Request & CallOptions]
|
|
209
|
-
|
|
210
|
-
type UrlRequest<Request extends RequestShape> =
|
|
211
|
-
(Request extends { params: infer Params } ? { params: Params }
|
|
212
|
-
: Request extends { params?: infer Params } ? { params?: Params } : {})
|
|
213
|
-
& (Request extends { query: infer Query } ? { query: Query }
|
|
214
|
-
: Request extends { query?: infer Query } ? { query?: Query } : {})
|
|
215
|
-
|
|
216
|
-
export type UrlArguments<Request extends RequestShape> = {} extends UrlRequest<Request>
|
|
217
|
-
? [request?: UrlRequest<Request> & CallOptions]
|
|
218
|
-
: [request: UrlRequest<Request> & CallOptions]
|
|
219
|
-
|
|
220
|
-
export interface EntrypointRequestMeta {
|
|
221
|
-
alias: string
|
|
222
|
-
auth?: Auth
|
|
223
|
-
entity?: ResolvedEntity
|
|
224
|
-
path: string
|
|
225
|
-
canceled?: boolean
|
|
226
|
-
cancel?: () => void
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* A protocol request at an implementation boundary.
|
|
231
|
-
*
|
|
232
|
-
* Transport metadata and empty request sections remain available to handlers; a declared section
|
|
233
|
-
* then refines that base shape to its protocol contract.
|
|
234
|
-
*/
|
|
235
|
-
export type HandlerRequest<Request extends RequestShape> = AbstractRequest & Request & EntrypointRequestMeta
|
|
236
|
-
|
|
237
|
-
/** The context-bound counterpart of an immutable protocol declaration. */
|
|
238
|
-
export interface RegisteredEntrypoint<Request extends RequestShape, Response> extends BasicEntrypoint {
|
|
239
|
-
readonly protocol: EntrypointProtocol<Request, Response>
|
|
240
|
-
call: (...args: CallArguments<Request>) => Promise<Response>
|
|
241
|
-
invoke: (...args: CallArguments<Request>) => Promise<EntrypointResult<Response>>
|
|
242
|
-
url: (...args: UrlArguments<Request>) => Promise<string>
|
|
243
|
-
validate: (...args: CallArguments<Request>) => Promise<boolean>
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* An immutable shared declaration. Its inherited reference type is what gives a context lookup
|
|
248
|
-
* the exact registered entrypoint type without a consumer-supplied generic.
|
|
249
|
-
*/
|
|
250
|
-
export interface EntrypointProtocol<
|
|
251
|
-
Request extends RequestShape = RequestShape,
|
|
252
|
-
Response = OpenValue,
|
|
253
|
-
> extends EntrypointProtocolDeclaration, EntrypointReference<RegisteredEntrypoint<Request, Response>> {
|
|
254
|
-
readonly contract?: EntrypointContract<Request, Response>
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export type RequestOf<Protocol extends EntrypointProtocolDeclaration> = Protocol extends EntrypointProtocol<infer Request, infer _Response>
|
|
258
|
-
? Request
|
|
259
|
-
: OpenRequest
|
|
260
|
-
|
|
261
|
-
export type ResponseOf<Protocol extends EntrypointProtocolDeclaration> = Protocol extends EntrypointProtocol<infer _Request, infer Response>
|
|
262
|
-
? Response
|
|
263
|
-
: OpenValue
|
|
264
|
-
|
|
265
|
-
export type BodyOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { body: infer Body }
|
|
266
|
-
? Body
|
|
267
|
-
: OpenValue
|
|
268
|
-
|
|
269
|
-
export type ParamsOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { params: infer Params }
|
|
270
|
-
? Params
|
|
271
|
-
: object
|
|
272
|
-
|
|
273
|
-
export type QueryOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { query: infer Query }
|
|
274
|
-
? Query
|
|
275
|
-
: object
|
|
276
|
-
|
|
277
|
-
export type HeadersOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> extends { headers: infer Headers }
|
|
278
|
-
? Headers
|
|
279
|
-
: object
|
|
280
|
-
|
|
281
|
-
export type CallRequestOf<Protocol extends EntrypointProtocolDeclaration> = RequestOf<Protocol> & CallOptions
|
|
282
|
-
|
|
283
76
|
const guardsOf = (guards: EntrypointOptions['guards']): readonly string[] => guards == null
|
|
284
77
|
? []
|
|
285
78
|
: typeof guards === 'string' ? [guards] : [...guards]
|
|
@@ -328,10 +121,6 @@ export const aliasOf = (reference: EntrypointReference | string): string =>
|
|
|
328
121
|
export const isEntrypointProtocol = (value: object): value is EntrypointProtocolDeclaration =>
|
|
329
122
|
'kind' in value && value.kind === 'entrypoint-protocol'
|
|
330
123
|
|
|
331
|
-
export interface EntrypointTree {
|
|
332
|
-
readonly [key: string]: EntrypointProtocolDeclaration | EntrypointTree
|
|
333
|
-
}
|
|
334
|
-
|
|
335
124
|
/** Flatten an exported protocol tree for a layer-specific materializer. */
|
|
336
125
|
export const protocols = (tree: EntrypointTree): EntrypointProtocolDeclaration[] => {
|
|
337
126
|
const result: EntrypointProtocolDeclaration[] = []
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { JSONSchemaType, AnySchemaObject } from 'ajv'
|
|
2
|
+
import type { EntrypointSchema, OpenValue, RequestShape, Typed } from './types.js'
|
|
3
|
+
|
|
4
|
+
export interface TypeToken {
|
|
5
|
+
readonly kind: 'entrypoint-type'
|
|
6
|
+
readonly schema?: AnySchemaObject
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare const entrypointSchemaType: unique symbol
|
|
10
|
+
|
|
11
|
+
export type AnyShapeSource = AnySchemaObject | TypeToken
|
|
12
|
+
|
|
13
|
+
export type SourceValue<Source> =
|
|
14
|
+
Source extends Typed<infer Value> ? Value
|
|
15
|
+
: Source extends EntrypointSchema<infer Value> ? Value
|
|
16
|
+
: Source extends JSONSchemaType<infer Value>
|
|
17
|
+
? Value extends OpenValue ? Value : OpenValue
|
|
18
|
+
: OpenValue
|
|
19
|
+
|
|
20
|
+
export type UrlRequest<Request extends RequestShape> =
|
|
21
|
+
(Request extends { params: infer Params } ? { params: Params }
|
|
22
|
+
: Request extends { params?: infer Params } ? { params?: Params } : {})
|
|
23
|
+
& (Request extends { query: infer Query } ? { query: Query }
|
|
24
|
+
: Request extends { query?: infer Query } ? { query?: Query } : {})
|