@toa.io/extensions.exposition 1.0.0-alpha.3 → 1.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/components/identity.bans/manifest.toa.yaml +1 -0
  2. package/components/identity.basic/manifest.toa.yaml +1 -0
  3. package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
  4. package/components/identity.federation/manifest.toa.yaml +1 -0
  5. package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
  6. package/components/identity.roles/manifest.toa.yaml +1 -0
  7. package/components/identity.roles/operations/tsconfig.tsbuildinfo +1 -1
  8. package/components/identity.tokens/manifest.toa.yaml +1 -0
  9. package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
  10. package/components/octets.storage/manifest.toa.yaml +1 -0
  11. package/components/octets.storage/operations/store.js +1 -1
  12. package/documentation/components.md +5 -5
  13. package/documentation/query.md +45 -2
  14. package/features/body.feature +1 -1
  15. package/features/cors.feature +2 -2
  16. package/features/errors.feature +1 -1
  17. package/features/etag.feature +96 -0
  18. package/features/octets.entries.feature +1 -1
  19. package/features/steps/Gateway.ts +3 -0
  20. package/features/steps/components/echo/manifest.toa.yaml +1 -0
  21. package/features/steps/components/greeter/manifest.toa.yaml +1 -0
  22. package/features/steps/components/octets.tester/manifest.toa.yaml +1 -0
  23. package/features/steps/components/pots/manifest.toa.yaml +10 -3
  24. package/features/steps/components/sequences/manifest.toa.yaml +1 -0
  25. package/features/timing.feature +43 -0
  26. package/package.json +7 -10
  27. package/readme.md +7 -6
  28. package/schemas/annotation.cos.yaml +1 -0
  29. package/schemas/querystring.cos.yaml +1 -0
  30. package/source/Annotation.ts +1 -0
  31. package/source/Context.ts +6 -4
  32. package/source/Directive.test.ts +7 -7
  33. package/source/Directive.ts +16 -42
  34. package/source/Endpoint.ts +55 -6
  35. package/source/Factory.ts +17 -7
  36. package/source/Gateway.ts +38 -50
  37. package/source/HTTP/Context.ts +67 -0
  38. package/source/HTTP/Server.test.ts +1 -1
  39. package/source/HTTP/Server.ts +60 -95
  40. package/source/HTTP/Timing.ts +40 -0
  41. package/source/HTTP/index.ts +1 -0
  42. package/source/HTTP/messages.test.ts +27 -8
  43. package/source/HTTP/messages.ts +32 -48
  44. package/source/Mapping.ts +7 -8
  45. package/source/RTD/Context.ts +7 -10
  46. package/source/RTD/Directives.ts +28 -4
  47. package/source/RTD/Endpoint.ts +6 -4
  48. package/source/RTD/Match.ts +2 -7
  49. package/source/RTD/Method.ts +7 -13
  50. package/source/RTD/Node.ts +13 -14
  51. package/source/RTD/Tree.ts +17 -16
  52. package/source/RTD/factory.ts +2 -5
  53. package/source/deployment.ts +6 -0
  54. package/source/directives/auth/Anonymous.ts +3 -2
  55. package/source/directives/auth/Authorization.ts +7 -6
  56. package/source/directives/auth/Incept.ts +11 -6
  57. package/source/directives/auth/Role.ts +5 -3
  58. package/source/directives/auth/Scheme.ts +2 -2
  59. package/source/directives/cache/Cache.ts +4 -4
  60. package/source/directives/cache/Control.ts +5 -5
  61. package/source/directives/cache/types.ts +1 -1
  62. package/source/directives/cors/CORS.ts +18 -10
  63. package/source/directives/dev/Development.ts +3 -3
  64. package/source/directives/index.ts +2 -2
  65. package/source/directives/octets/Context.ts +1 -1
  66. package/source/directives/octets/Delete.ts +19 -9
  67. package/source/directives/octets/Fetch.ts +29 -14
  68. package/source/directives/octets/List.ts +14 -6
  69. package/source/directives/octets/Octets.ts +6 -5
  70. package/source/directives/octets/Permute.ts +12 -6
  71. package/source/directives/octets/Store.ts +25 -17
  72. package/source/directives/octets/Workflow.ts +3 -3
  73. package/source/directives/octets/workflows/Workflow.ts +2 -2
  74. package/source/directives/vary/Vary.ts +3 -3
  75. package/source/directives/vary/embeddings/Header.ts +2 -2
  76. package/source/directives/vary/embeddings/Language.ts +2 -2
  77. package/source/io.ts +2 -2
  78. package/transpiled/Annotation.d.ts +1 -0
  79. package/transpiled/Context.d.ts +6 -4
  80. package/transpiled/Directive.d.ts +8 -21
  81. package/transpiled/Directive.js +8 -11
  82. package/transpiled/Directive.js.map +1 -1
  83. package/transpiled/Endpoint.d.ts +7 -5
  84. package/transpiled/Endpoint.js +60 -2
  85. package/transpiled/Endpoint.js.map +1 -1
  86. package/transpiled/Factory.js +8 -2
  87. package/transpiled/Factory.js.map +1 -1
  88. package/transpiled/Gateway.d.ts +4 -8
  89. package/transpiled/Gateway.js +22 -32
  90. package/transpiled/Gateway.js.map +1 -1
  91. package/transpiled/HTTP/Context.d.ts +24 -0
  92. package/transpiled/HTTP/Context.js +47 -0
  93. package/transpiled/HTTP/Context.js.map +1 -0
  94. package/transpiled/HTTP/Server.d.ts +8 -7
  95. package/transpiled/HTTP/Server.js +68 -76
  96. package/transpiled/HTTP/Server.js.map +1 -1
  97. package/transpiled/HTTP/Timing.d.ts +10 -0
  98. package/transpiled/HTTP/Timing.js +29 -0
  99. package/transpiled/HTTP/Timing.js.map +1 -0
  100. package/transpiled/HTTP/index.d.ts +1 -0
  101. package/transpiled/HTTP/index.js +1 -0
  102. package/transpiled/HTTP/index.js.map +1 -1
  103. package/transpiled/HTTP/messages.d.ts +7 -21
  104. package/transpiled/HTTP/messages.js +24 -26
  105. package/transpiled/HTTP/messages.js.map +1 -1
  106. package/transpiled/Mapping.js +7 -7
  107. package/transpiled/Mapping.js.map +1 -1
  108. package/transpiled/RTD/Context.d.ts +7 -6
  109. package/transpiled/RTD/Directives.d.ts +19 -4
  110. package/transpiled/RTD/Endpoint.d.ts +6 -4
  111. package/transpiled/RTD/Match.d.ts +2 -4
  112. package/transpiled/RTD/Method.d.ts +7 -7
  113. package/transpiled/RTD/Method.js.map +1 -1
  114. package/transpiled/RTD/Node.d.ts +4 -6
  115. package/transpiled/RTD/Node.js +2 -1
  116. package/transpiled/RTD/Node.js.map +1 -1
  117. package/transpiled/RTD/Tree.d.ts +6 -6
  118. package/transpiled/RTD/Tree.js +4 -1
  119. package/transpiled/RTD/Tree.js.map +1 -1
  120. package/transpiled/RTD/factory.d.ts +2 -4
  121. package/transpiled/RTD/factory.js.map +1 -1
  122. package/transpiled/deployment.js +5 -0
  123. package/transpiled/deployment.js.map +1 -1
  124. package/transpiled/directives/auth/Anonymous.js +3 -4
  125. package/transpiled/directives/auth/Anonymous.js.map +1 -1
  126. package/transpiled/directives/auth/Authorization.d.ts +2 -3
  127. package/transpiled/directives/auth/Authorization.js +1 -1
  128. package/transpiled/directives/auth/Authorization.js.map +1 -1
  129. package/transpiled/directives/auth/Incept.d.ts +1 -1
  130. package/transpiled/directives/auth/Incept.js +11 -6
  131. package/transpiled/directives/auth/Incept.js.map +1 -1
  132. package/transpiled/directives/auth/Role.js +5 -3
  133. package/transpiled/directives/auth/Role.js.map +1 -1
  134. package/transpiled/directives/auth/Scheme.js +2 -2
  135. package/transpiled/directives/auth/Scheme.js.map +1 -1
  136. package/transpiled/directives/cache/Cache.d.ts +3 -3
  137. package/transpiled/directives/cache/Cache.js +2 -2
  138. package/transpiled/directives/cache/Cache.js.map +1 -1
  139. package/transpiled/directives/cache/Control.d.ts +3 -3
  140. package/transpiled/directives/cache/Control.js +3 -3
  141. package/transpiled/directives/cache/Control.js.map +1 -1
  142. package/transpiled/directives/cache/types.d.ts +1 -1
  143. package/transpiled/directives/cors/CORS.d.ts +2 -3
  144. package/transpiled/directives/cors/CORS.js +17 -10
  145. package/transpiled/directives/cors/CORS.js.map +1 -1
  146. package/transpiled/directives/dev/Development.d.ts +3 -3
  147. package/transpiled/directives/dev/Development.js.map +1 -1
  148. package/transpiled/directives/index.d.ts +2 -2
  149. package/transpiled/directives/index.js.map +1 -1
  150. package/transpiled/directives/octets/Context.d.ts +1 -1
  151. package/transpiled/directives/octets/Context.js.map +1 -1
  152. package/transpiled/directives/octets/Delete.d.ts +1 -1
  153. package/transpiled/directives/octets/Delete.js +19 -9
  154. package/transpiled/directives/octets/Delete.js.map +1 -1
  155. package/transpiled/directives/octets/Fetch.d.ts +1 -1
  156. package/transpiled/directives/octets/Fetch.js +28 -14
  157. package/transpiled/directives/octets/Fetch.js.map +1 -1
  158. package/transpiled/directives/octets/List.d.ts +1 -1
  159. package/transpiled/directives/octets/List.js +13 -6
  160. package/transpiled/directives/octets/List.js.map +1 -1
  161. package/transpiled/directives/octets/Octets.d.ts +2 -3
  162. package/transpiled/directives/octets/Octets.js +4 -2
  163. package/transpiled/directives/octets/Octets.js.map +1 -1
  164. package/transpiled/directives/octets/Permute.d.ts +1 -1
  165. package/transpiled/directives/octets/Permute.js +11 -6
  166. package/transpiled/directives/octets/Permute.js.map +1 -1
  167. package/transpiled/directives/octets/Store.d.ts +1 -1
  168. package/transpiled/directives/octets/Store.js +17 -12
  169. package/transpiled/directives/octets/Store.js.map +1 -1
  170. package/transpiled/directives/octets/Workflow.d.ts +1 -1
  171. package/transpiled/directives/octets/Workflow.js +3 -3
  172. package/transpiled/directives/octets/Workflow.js.map +1 -1
  173. package/transpiled/directives/octets/workflows/Workflow.d.ts +1 -1
  174. package/transpiled/directives/octets/workflows/Workflow.js +2 -2
  175. package/transpiled/directives/octets/workflows/Workflow.js.map +1 -1
  176. package/transpiled/directives/vary/Vary.d.ts +2 -2
  177. package/transpiled/directives/vary/Vary.js +1 -1
  178. package/transpiled/directives/vary/embeddings/Header.js +2 -2
  179. package/transpiled/directives/vary/embeddings/Header.js.map +1 -1
  180. package/transpiled/directives/vary/embeddings/Language.js +2 -2
  181. package/transpiled/directives/vary/embeddings/Language.js.map +1 -1
  182. package/transpiled/io.d.ts +2 -2
  183. package/transpiled/tsconfig.tsbuildinfo +1 -1
  184. package/source/HTTP/Server.fixtures.ts +0 -40
  185. package/transpiled/HTTP/Server.fixtures.d.ts +0 -10
  186. package/transpiled/HTTP/Server.fixtures.js +0 -31
  187. package/transpiled/HTTP/Server.fixtures.js.map +0 -1
@@ -9,11 +9,10 @@ import { WorkflowDirective } from './Workflow'
9
9
  import type { Output } from '../../io'
10
10
  import type { Component } from '@toa.io/core'
11
11
  import type { Remotes } from '../../Remotes'
12
- import type { Family } from '../../Directive'
12
+ import type { Parameter, DirectiveFamily } from '../../RTD'
13
13
  import type { Directive, Input } from './types'
14
- import type { Parameter } from '../../RTD'
15
14
 
16
- export class Octets implements Family<Directive> {
15
+ export class Octets implements DirectiveFamily<Directive> {
17
16
  public readonly name: string = 'octets'
18
17
  public readonly mandatory: boolean = false
19
18
 
@@ -46,15 +45,17 @@ export class Octets implements Family<Directive> {
46
45
  if (action === null)
47
46
  return null
48
47
 
48
+ // noinspection PointlessBooleanExpressionJS
49
49
  if (context === null)
50
50
  throw new Error('Octets context is not defined.')
51
51
 
52
- const targeted = input.path[input.path.length - 1] !== '/'
52
+ const targeted = input.request.url[input.request.url.length - 1] !== '/'
53
53
 
54
54
  if (targeted !== action.targeted)
55
55
  throw new NotFound(`Trailing slash is ${action.targeted ? 'redundant' : 'required'}.`)
56
56
 
57
- return await action.apply(context.storage, input, parameters)
57
+ // noinspection JSObjectNullOrUndefined
58
+ return action.apply(context.storage, input, parameters)
58
59
  }
59
60
  }
60
61
 
@@ -18,16 +18,22 @@ export class Permute implements Directive {
18
18
  this.discovery = discovery
19
19
  }
20
20
 
21
- public async apply (storage: string, request: Input): Promise<Output> {
21
+ public async apply (storage: string, input: Input): Promise<Output> {
22
22
  this.storage ??= await this.discovery
23
23
 
24
- if (request.encoder === null)
24
+ if (input.encoder === null)
25
25
  throw new NotAcceptable()
26
26
 
27
- const path = request.url
28
- const list = await request.parse()
29
- const input = { storage, path, list }
30
- const error = await this.storage.invoke<Maybe<unknown>>('permute', { input })
27
+ const path = input.request.url
28
+ const list = await input.body()
29
+
30
+ const error = await this.storage.invoke<Maybe<unknown>>('permute', {
31
+ input: {
32
+ storage,
33
+ path,
34
+ list
35
+ }
36
+ })
31
37
 
32
38
  if (error instanceof Error)
33
39
  throw new NotFound()
@@ -36,45 +36,51 @@ export class Store implements Directive {
36
36
 
37
37
  this.discovery.storage = discovery
38
38
 
39
- cors.allowHeader('content-meta')
39
+ cors.allow('content-meta')
40
40
  }
41
41
 
42
- public async apply (storage: string, request: Input, parameters: Parameter[]): Promise<Output> {
42
+ public async apply (storage: string, input: Input, parameters: Parameter[]): Promise<Output> {
43
43
  this.storage ??= await this.discovery.storage
44
44
 
45
- const input: StoreInput = { storage, request }
46
- const meta = request.headers['content-meta']
45
+ const request: StoreRequest = {
46
+ input: {
47
+ storage,
48
+ request: input.request
49
+ }
50
+ }
51
+
52
+ const meta = input.request.headers['content-meta']
47
53
 
48
54
  if (this.accept !== undefined)
49
- input.accept = this.accept
55
+ request.input.accept = this.accept
50
56
 
51
57
  if (meta !== undefined)
52
- input.meta = this.parseMeta(meta)
58
+ request.input.meta = this.parseMeta(meta)
53
59
 
54
- const entry = await this.storage.invoke<Entry>('store', { input })
60
+ const entry = await this.storage.invoke<Entry>('store', request)
55
61
 
56
62
  return match<Output>(entry,
57
63
  Error, (error: ErrorType) => this.throw(error),
58
- () => this.reply(request, storage, entry, parameters))
64
+ () => this.reply(input, storage, entry, parameters))
59
65
  }
60
66
 
61
67
  // eslint-disable-next-line max-params
62
- private reply (request: Input, storage: string, entry: Entry, parameters: Parameter[]): Output {
68
+ private reply (input: Input, storage: string, entry: Entry, parameters: Parameter[]): Output {
63
69
  const body = this.workflow === undefined
64
70
  ? entry
65
- : this.execute(request, storage, entry, parameters)
71
+ : this.execute(input, storage, entry, parameters)
66
72
 
67
73
  return { body }
68
74
  }
69
75
 
70
76
  // eslint-disable-next-line max-params
71
77
  private execute
72
- (request: Input, storage: string, entry: Entry, parameters: Parameter[]): Readable {
78
+ (input: Input, storage: string, entry: Entry, parameters: Parameter[]): Readable {
73
79
  const stream = new PassThrough({ objectMode: true })
74
80
 
75
81
  stream.push(entry)
76
82
 
77
- this.workflow!.execute(request, storage, entry, parameters).pipe(stream)
83
+ this.workflow!.execute(input, storage, entry, parameters).pipe(stream)
78
84
 
79
85
  return stream
80
86
  }
@@ -108,9 +114,11 @@ export interface Options {
108
114
  workflow?: Unit[] | Unit
109
115
  }
110
116
 
111
- interface StoreInput {
112
- storage: string
113
- request: Input
114
- accept?: string
115
- meta?: Record<string, string>
117
+ interface StoreRequest {
118
+ input: {
119
+ storage: string
120
+ request: Input['request']
121
+ accept?: string
122
+ meta?: Record<string, string>
123
+ }
116
124
  }
@@ -24,18 +24,18 @@ export class WorkflowDirective implements Directive {
24
24
  this.discovery = discovery
25
25
  }
26
26
 
27
- public async apply (storage: string, request: Input, parameters: Parameter[]): Promise<Output> {
27
+ public async apply (storage: string, input: Input, parameters: Parameter[]): Promise<Output> {
28
28
  this.storage ??= await this.discovery
29
29
 
30
30
  const entry = await this.storage.invoke<Maybe<Entry>>('get',
31
- { input: { storage, path: request.url } })
31
+ { input: { storage, path: input.request.url } })
32
32
 
33
33
  if (entry instanceof Error)
34
34
  throw new NotFound()
35
35
 
36
36
  return {
37
37
  status: 202,
38
- body: this.workflow.execute(request, storage, entry, parameters)
38
+ body: this.workflow.execute(input, storage, entry, parameters)
39
39
  }
40
40
  }
41
41
  }
@@ -21,8 +21,8 @@ export class Workflow {
21
21
 
22
22
  // eslint-disable-next-line max-params
23
23
  public execute
24
- (request: Input, storage: string, entry: Entry, params: Parameter[]): Execution {
25
- const path = posix.join(request.path, entry.id)
24
+ (input: Input, storage: string, entry: Entry, params: Parameter[]): Execution {
25
+ const path = posix.join(input.request.url, entry.id)
26
26
  const parameters: Record<string, string> = {}
27
27
 
28
28
  for (const { name, value } of params)
@@ -3,10 +3,10 @@ import { properties, Property } from './Properties'
3
3
  import { Embed } from './Embed'
4
4
  import type { Properties } from './Properties'
5
5
  import type { Directive } from './Directive'
6
- import type { Family } from '../../Directive'
6
+ import type { DirectiveFamily } from '../../RTD'
7
7
  import type { Input, Output } from '../../io'
8
8
 
9
- export class Vary implements Family {
9
+ export class Vary implements DirectiveFamily {
10
10
  public readonly name = 'vary'
11
11
  public readonly mandatory = false
12
12
 
@@ -21,7 +21,7 @@ export class Vary implements Family {
21
21
 
22
22
  public preflight (instances: Array<Directive | Property>, request: Input): Output {
23
23
  /*
24
- To stop consructing `properties` object on each request, Directive Families must be refactored
24
+ To stop constructing `properties` object on each request, Directive Families must be refactored
25
25
  from singleton factories to per-Node instances on the Tree.
26
26
  */
27
27
  const properties: Properties = {}
@@ -8,11 +8,11 @@ export class Header implements Embedding {
8
8
  public constructor (name: string) {
9
9
  this.name = name
10
10
 
11
- cors.allowHeader(this.name)
11
+ cors.allow(this.name)
12
12
  }
13
13
 
14
14
  public resolve (input: Input): string | undefined {
15
- const value = input.headers[this.name]
15
+ const value = input.request.headers[this.name]
16
16
 
17
17
  if (value === undefined)
18
18
  return value
@@ -7,7 +7,7 @@ import type { Input } from '../../../io'
7
7
 
8
8
  export class Language implements Embedding {
9
9
  public constructor () {
10
- cors.allowHeader('accept-language')
10
+ cors.allow('accept-language')
11
11
  }
12
12
 
13
13
  public resolve (input: Input, properties: Properties): string | undefined {
@@ -17,7 +17,7 @@ export class Language implements Embedding {
17
17
  assert.ok(properties.languages.length > 0,
18
18
  'List of supported languages is empty.')
19
19
 
20
- const negotiator = new Negotiator(input)
20
+ const negotiator = new Negotiator(input.request)
21
21
  const language = negotiator.language(properties.languages) ?? properties.languages[0]
22
22
 
23
23
  input.pipelines.response.push((response) => {
package/source/io.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IncomingMessage, OutgoingMessage } from './HTTP'
1
+ import type { Context, OutgoingMessage } from './HTTP'
2
2
 
3
- export type Input = IncomingMessage
3
+ export type Input = Context
4
4
  export type Output = OutgoingMessage | null
@@ -3,5 +3,6 @@ export interface Annotation {
3
3
  class?: string;
4
4
  annotations?: Record<string, string>;
5
5
  debug: boolean;
6
+ trace: boolean;
6
7
  '/'?: object;
7
8
  }
@@ -1,5 +1,7 @@
1
- import { type Endpoint } from './Endpoint';
2
- import { type Directives } from './Directive';
3
- import { type Branch } from './Branch';
4
1
  import type * as RTD from './RTD';
5
- export type Context = RTD.Context<Endpoint, Directives, Branch>;
2
+ export type Context = RTD.Context<Extension>;
3
+ interface Extension {
4
+ namespace: string;
5
+ component: string;
6
+ }
7
+ export {};
@@ -1,31 +1,18 @@
1
- import type { IncomingMessage, OutgoingMessage } from './HTTP';
1
+ import type { Context, OutgoingMessage } from './HTTP';
2
2
  import type { Remotes } from './Remotes';
3
3
  import type { Output } from './io';
4
4
  import type * as RTD from './RTD';
5
- export declare class Directives implements RTD.Directives<Directives> {
5
+ export declare class Directives implements RTD.Directives {
6
6
  private readonly sets;
7
- constructor(sets: DirectiveSet[]);
8
- preflight(request: IncomingMessage, parameters: RTD.Parameter[]): Promise<Output>;
9
- settle(request: IncomingMessage, response: OutgoingMessage): Promise<void>;
10
- merge(directives: Directives): void;
7
+ constructor(sets: RTD.DirectiveSet[]);
8
+ preflight(context: Context, parameters: RTD.Parameter[]): Promise<Output>;
9
+ settle(context: Context, response: OutgoingMessage): Promise<void>;
11
10
  }
12
- export declare class DirectivesFactory implements RTD.DirectivesFactory<Directives> {
13
- private readonly remtoes;
11
+ export declare class DirectivesFactory implements RTD.DirectiveFactory {
12
+ private readonly remotes;
14
13
  private readonly families;
15
14
  private readonly mandatory;
16
- constructor(families: Family[], remotes: Remotes);
15
+ constructor(families: RTD.DirectiveFamily[], remotes: Remotes);
17
16
  create(declarations: RTD.syntax.Directive[]): Directives;
18
17
  }
19
18
  export declare const shortcuts: RTD.syntax.Shortcuts;
20
- export interface Family<TDirective = any, TExtension = any> {
21
- readonly name: string;
22
- readonly mandatory: boolean;
23
- create: (name: string, value: any, remotes: Remotes) => TDirective;
24
- preflight?: (directives: TDirective[], request: IncomingMessage & TExtension, parameters: RTD.Parameter[]) => Output | Promise<Output>;
25
- settle?: (directives: TDirective[], request: IncomingMessage & TExtension, response: OutgoingMessage) => void | Promise<void>;
26
- }
27
- interface DirectiveSet {
28
- family: Family;
29
- directives: any[];
30
- }
31
- export {};
@@ -6,30 +6,27 @@ class Directives {
6
6
  constructor(sets) {
7
7
  this.sets = sets;
8
8
  }
9
- async preflight(request, parameters) {
9
+ async preflight(context, parameters) {
10
10
  for (const set of this.sets) {
11
11
  if (set.family.preflight === undefined)
12
12
  continue;
13
- const output = await set.family.preflight(set.directives, request, parameters);
13
+ const output = await set.family.preflight(set.directives, context, parameters);
14
14
  if (output !== null) {
15
- await this.settle(request, output);
15
+ await this.settle(context, output);
16
16
  return output;
17
17
  }
18
18
  }
19
19
  return null;
20
20
  }
21
- async settle(request, response) {
21
+ async settle(context, response) {
22
22
  for (const set of this.sets)
23
23
  if (set.family.settle !== undefined)
24
- await set.family.settle(set.directives, request, response);
25
- }
26
- merge(directives) {
27
- this.sets.push(...directives.sets);
24
+ await set.family.settle(set.directives, context, response);
28
25
  }
29
26
  }
30
27
  exports.Directives = Directives;
31
28
  class DirectivesFactory {
32
- remtoes;
29
+ remotes;
33
30
  families = {};
34
31
  mandatory = [];
35
32
  constructor(families, remotes) {
@@ -38,7 +35,7 @@ class DirectivesFactory {
38
35
  if (family.mandatory)
39
36
  this.mandatory.push(family.name);
40
37
  }
41
- this.remtoes = remotes;
38
+ this.remotes = remotes;
42
39
  }
43
40
  create(declarations) {
44
41
  const groups = {};
@@ -48,7 +45,7 @@ class DirectivesFactory {
48
45
  const family = this.families[declaration.family];
49
46
  if (family === undefined)
50
47
  throw new Error(`Directive family '${declaration.family}' is not found.`);
51
- const directive = family.create(declaration.name, declaration.value, this.remtoes);
48
+ const directive = family.create(declaration.name, declaration.value, this.remotes);
52
49
  groups[family.name] ??= [];
53
50
  groups[family.name].push(directive);
54
51
  mandatory.delete(family.name);
@@ -1 +1 @@
1
- {"version":3,"file":"Directive.js","sourceRoot":"","sources":["../source/Directive.ts"],"names":[],"mappings":";;;AAKA,MAAa,UAAU;IACJ,IAAI,CAAgB;IAErC,YAAoB,IAAoB;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,SAAS,CAAE,OAAwB,EAAE,UAA2B;QAC3E,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,GAAG,CAAC,M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+ import { type Component } from '@toa.io/core';
2
2
  import { type Remotes } from './Remotes';
3
3
  import { Mapping } from './Mapping';
4
4
  import { type Context } from './Context';
5
+ import * as http from './HTTP';
5
6
  import type * as RTD from './RTD';
6
- import type * as http from './HTTP';
7
- export declare class Endpoint implements RTD.Endpoint<Endpoint> {
7
+ export declare class Endpoint implements RTD.Endpoint {
8
8
  private readonly endpoint;
9
9
  private readonly mapping;
10
10
  private readonly discovery;
11
11
  private remote;
12
12
  constructor(endpoint: string, mapping: Mapping, discovery: Promise<Component>);
13
- call(body: any, query: http.Query, parameters: RTD.Parameter[]): Promise<Reply>;
13
+ call(context: http.Context, parameters: RTD.Parameter[]): Promise<http.OutgoingMessage>;
14
14
  close(): Promise<void>;
15
+ private query;
16
+ private version;
15
17
  }
16
- export declare class EndpointsFactory implements RTD.EndpointsFactory<Endpoint> {
18
+ export declare class EndpointsFactory implements RTD.EndpointsFactory {
17
19
  private readonly remotes;
18
20
  constructor(remotes: Remotes);
19
21
  create(method: RTD.syntax.Method, context: Context): Endpoint;
@@ -1,7 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.EndpointsFactory = exports.Endpoint = void 0;
4
27
  const Mapping_1 = require("./Mapping");
28
+ const http = __importStar(require("./HTTP"));
5
29
  class Endpoint {
6
30
  endpoint;
7
31
  mapping;
@@ -12,15 +36,48 @@ class Endpoint {
12
36
  this.mapping = mapping;
13
37
  this.discovery = discovery;
14
38
  }
15
- async call(body, query, parameters) {
39
+ async call(context, parameters) {
40
+ const body = await context.body();
41
+ const query = this.query(context);
16
42
  const request = this.mapping.fit(body, query, parameters);
17
43
  this.remote ??= await this.discovery;
18
- return await this.remote.invoke(this.endpoint, request);
44
+ const reply = await this.remote.invoke(this.endpoint, request);
45
+ if (reply instanceof Error)
46
+ throw new http.Conflict(reply);
47
+ const message = {};
48
+ if (typeof reply === 'object' && reply !== null && '_version' in reply) {
49
+ const etag = context.request.headers['if-none-match'];
50
+ message.headers ??= new Headers();
51
+ if (etag !== undefined && reply._version === this.version(etag)) {
52
+ message.status = 304;
53
+ message.headers.set('etag', etag);
54
+ return message;
55
+ }
56
+ else {
57
+ message.headers.set('etag', `"${reply._version.toString()}"`);
58
+ delete reply._version;
59
+ }
60
+ }
61
+ message.body = reply;
62
+ return message;
19
63
  }
20
64
  async close() {
21
65
  this.remote ??= await this.discovery;
22
66
  await this.remote.disconnect(INTERRUPT);
23
67
  }
68
+ query(context) {
69
+ const query = Object.fromEntries(context.url.searchParams);
70
+ const etag = context.request.headers['if-match'];
71
+ if (etag !== undefined)
72
+ query.version = this.version(etag);
73
+ return query;
74
+ }
75
+ version(etag) {
76
+ const match = etag.match(ETAG);
77
+ if (match === null)
78
+ throw new http.BadRequest('Invalid ETag.');
79
+ return Number.parseInt(match.groups.version);
80
+ }
24
81
  }
25
82
  exports.Endpoint = Endpoint;
26
83
  class EndpointsFactory {
@@ -41,5 +98,6 @@ class EndpointsFactory {
41
98
  }
42
99
  }
43
100
  exports.EndpointsFactory = EndpointsFactory;
101
+ const ETAG = /^"(?<version>\d{1,32})"$/;
44
102
  const INTERRUPT = true;
45
103
  //# sourceMappingURL=Endpoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Endpoint.js","sourceRoot":"","sources":["../source/Endpoint.ts"],"names":[],"mappings":";;;AAEA,uCAAmC;AAKnC,MAAa,QAAQ;IACF,QAAQ,CAAQ;IAChB,OAAO,CAAS;IAChB,SAAS,CAAoB;IACtC,MAAM,GAAqB,IAAI,CAAA;IAEvC,YAAoB,QAAgB,EAAE,OAAgB,EAAE,SAA6B;QACnF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEM,KAAK,CAAC,IAAI,CAAE,IAAS,EAAE,KAAiB,EAAE,UAA2B;QAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;QAEzD,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,SAAS,CAAA;QAEpC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,SAAS,CAAA;QAEpC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IACzC,CAAC;CACF;AAzBD,4BAyBC;AAED,MAAa,gBAAgB;IACV,OAAO,CAAS;IAEjC,YAAoB,OAAgB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEM,MAAM,CAAE,MAAyB,EAAE,OAAgB;QACxD,IAAI,MA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AAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAA;QAC1E,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAA;QAE1E,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS;YACpD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAElE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAE7D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;IAClE,CAAC;CACF;AAtBD,4CAsBC;AAED,MAAM,IAAI,GAAG,0BAA0B,CAAA;AAEvC,MAAM,SAAS,GAAG,IAAI,CAAA"}
@@ -46,8 +46,13 @@ class Factory {
46
46
  }
47
47
  service() {
48
48
  const debug = process.env.TOA_EXPOSITION_DEBUG === '1';
49
+ const trace = process.env.TOA_EXPOSITION_TRACE === '1';
49
50
  const broadcast = this.boot.bindings.broadcast(CHANNEL);
50
- const server = HTTP_1.Server.create({ methods: RTD_1.syntax.verbs, debug });
51
+ const server = HTTP_1.Server.create({
52
+ methods: RTD_1.syntax.verbs,
53
+ debug,
54
+ trace
55
+ });
51
56
  const remotes = new Remotes_1.Remotes(this.boot);
52
57
  const node = root.resolve();
53
58
  const methods = new Endpoint_1.EndpointsFactory(remotes);
@@ -55,9 +60,10 @@ class Factory {
55
60
  const interception = new Interception_1.Interception(directives_1.interceptors);
56
61
  const tree = new RTD_1.Tree(node, methods, directives);
57
62
  const composition = new Composition_1.Composition(this.boot);
58
- const gateway = new Gateway_1.Gateway(broadcast, server, tree, interception);
63
+ const gateway = new Gateway_1.Gateway(broadcast, tree, interception);
59
64
  gateway.depends(remotes);
60
65
  gateway.depends(composition);
66
+ server.attach(gateway.process.bind(gateway));
61
67
  server.depends(gateway);
62
68
  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indings, Connector } from '@toa.io/core';
2
2
  import * as http from './HTTP';
3
- import type { Interceptor } from './Interception';
3
+ import type { Interception } from './Interception';
4
4
  import type { Tree } from './RTD';
5
5
  import type { Label } from './discovery';
6
- import type { Endpoint } from './Endpoint';
7
- import type { Directives } from './Directive';
8
6
  export declare class Gateway extends Connector {
9
7
  private readonly broadcast;
10
8
  private readonly tree;
11
9
  private readonly interceptor;
12
- private readonly server;
13
- constructor(broadcast: Broadcast, server: http.Server, tree: Tree<Endpoint, Directives>, interception: Interceptor);
10
+ constructor(broadcast: Broadcast, tree: Tree, interception: Interception);
11
+ process(context: http.Context): Promise<http.OutgoingMessage>;
14
12
  protected open(): Promise<void>;
15
13
  protected dispose(): void;
16
- private process;
17
14
  private call;
18
15
  private discover;
19
16
  private merge;
20
17
  }
21
- type Broadcast = bindings.Broadcast<Label>;
22
- export {};
18
+ export type Broadcast = bindings.Broadcast<Label>;