@toa.io/extensions.exposition 0.24.0-alpha.21 → 0.24.0-alpha.23

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 (82) hide show
  1. package/components/context.toa.yaml +1 -1
  2. package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
  3. package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
  4. package/components/octets.storage/manifest.toa.yaml +1 -0
  5. package/components/octets.storage/operations/store.js +2 -2
  6. package/documentation/octets.md +89 -37
  7. package/features/cors.feature +33 -0
  8. package/features/octets.entries.feature +121 -0
  9. package/features/octets.feature +1 -27
  10. package/features/octets.meta.feature +65 -0
  11. package/features/octets.workflows.feature +105 -4
  12. package/features/routes.feature +37 -0
  13. package/features/steps/Captures.ts +3 -2
  14. package/features/steps/Components.ts +15 -8
  15. package/features/steps/HTTP.ts +1 -1
  16. package/features/steps/Parameters.ts +1 -1
  17. package/features/steps/components/octets.tester/manifest.toa.yaml +1 -0
  18. package/features/steps/components/octets.tester/operations/echo.js +7 -0
  19. package/features/steps/components/users/manifest.toa.yaml +3 -0
  20. package/features/steps/components/users.properties/manifest.toa.yaml +13 -0
  21. package/features/steps/tsconfig.json +1 -1
  22. package/features/vary.feature +1 -1
  23. package/package.json +8 -8
  24. package/schemas/octets/delete.cos.yaml +2 -1
  25. package/schemas/octets/list.cos.yaml +2 -1
  26. package/source/HTTP/Server.ts +32 -23
  27. package/source/HTTP/messages.ts +7 -1
  28. package/source/directives/cors/CORS.ts +25 -23
  29. package/source/directives/index.ts +1 -1
  30. package/source/directives/octets/Delete.ts +45 -6
  31. package/source/directives/octets/Fetch.ts +17 -18
  32. package/source/directives/octets/List.ts +36 -6
  33. package/source/directives/octets/Permute.ts +2 -2
  34. package/source/directives/octets/Store.ts +36 -94
  35. package/source/directives/octets/schemas.ts +11 -6
  36. package/source/directives/octets/workflow/Execution.ts +77 -0
  37. package/source/directives/octets/workflow/Workflow.ts +28 -0
  38. package/source/directives/octets/workflow/index.ts +1 -0
  39. package/source/manifest.test.ts +6 -14
  40. package/source/manifest.ts +9 -6
  41. package/source/schemas.ts +7 -3
  42. package/transpiled/HTTP/Server.d.ts +1 -1
  43. package/transpiled/HTTP/Server.js +22 -21
  44. package/transpiled/HTTP/Server.js.map +1 -1
  45. package/transpiled/HTTP/messages.d.ts +1 -0
  46. package/transpiled/HTTP/messages.js +4 -1
  47. package/transpiled/HTTP/messages.js.map +1 -1
  48. package/transpiled/directives/cors/CORS.d.ts +2 -5
  49. package/transpiled/directives/cors/CORS.js +18 -16
  50. package/transpiled/directives/cors/CORS.js.map +1 -1
  51. package/transpiled/directives/index.js +1 -1
  52. package/transpiled/directives/index.js.map +1 -1
  53. package/transpiled/directives/octets/Delete.d.ts +9 -1
  54. package/transpiled/directives/octets/Delete.js +30 -6
  55. package/transpiled/directives/octets/Delete.js.map +1 -1
  56. package/transpiled/directives/octets/Fetch.d.ts +4 -5
  57. package/transpiled/directives/octets/Fetch.js +11 -12
  58. package/transpiled/directives/octets/Fetch.js.map +1 -1
  59. package/transpiled/directives/octets/List.d.ts +6 -1
  60. package/transpiled/directives/octets/List.js +22 -4
  61. package/transpiled/directives/octets/List.js.map +1 -1
  62. package/transpiled/directives/octets/Permute.js +2 -2
  63. package/transpiled/directives/octets/Permute.js.map +1 -1
  64. package/transpiled/directives/octets/Store.d.ts +7 -19
  65. package/transpiled/directives/octets/Store.js +21 -66
  66. package/transpiled/directives/octets/Store.js.map +1 -1
  67. package/transpiled/directives/octets/schemas.d.ts +11 -6
  68. package/transpiled/directives/octets/schemas.js.map +1 -1
  69. package/transpiled/directives/octets/workflow/Execution.d.ts +24 -0
  70. package/transpiled/directives/octets/workflow/Execution.js +55 -0
  71. package/transpiled/directives/octets/workflow/Execution.js.map +1 -0
  72. package/transpiled/directives/octets/workflow/Workflow.d.ts +11 -0
  73. package/transpiled/directives/octets/workflow/Workflow.js +21 -0
  74. package/transpiled/directives/octets/workflow/Workflow.js.map +1 -0
  75. package/transpiled/directives/octets/workflow/index.d.ts +1 -0
  76. package/transpiled/directives/octets/workflow/index.js +6 -0
  77. package/transpiled/directives/octets/workflow/index.js.map +1 -0
  78. package/transpiled/manifest.js +10 -5
  79. package/transpiled/manifest.js.map +1 -1
  80. package/transpiled/schemas.d.ts +7 -3
  81. package/transpiled/schemas.js.map +1 -1
  82. package/transpiled/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,77 @@
1
+ import { Readable } from 'stream'
2
+ import type { Unit } from './Workflow'
3
+ import type { Remotes } from '../../../Remotes'
4
+ import type { Component } from '@toa.io/core'
5
+ import type { Maybe } from '@toa.io/types'
6
+ import type { Entry } from '@toa.io/extensions.storages'
7
+
8
+ export class Execution extends Readable {
9
+ private readonly units: Unit[]
10
+ private readonly remotes: Remotes
11
+ private readonly context: Context
12
+ private readonly components: Record<string, Component> = {}
13
+ private readonly discovery: Record<string, Promise<Component>> = {}
14
+ private interrupted = false
15
+
16
+ public constructor (context: Context, units: Unit[], remotes: Remotes) {
17
+ super({ objectMode: true })
18
+
19
+ this.context = context
20
+ this.units = units
21
+ this.remotes = remotes
22
+
23
+ void this.run()
24
+ }
25
+
26
+ public override _read (): void {
27
+ }
28
+
29
+ private async run (): Promise<void> {
30
+ this.push(this.context.entry)
31
+
32
+ for (const unit of this.units) {
33
+ await this.execute(unit)
34
+
35
+ if (this.interrupted)
36
+ break
37
+ }
38
+
39
+ this.push(null)
40
+ }
41
+
42
+ private async execute (unit: Unit): Promise<void> {
43
+ const promises = Object.entries(unit).map(async ([step, endpoint]) => {
44
+ const result = await this.call(endpoint)
45
+
46
+ if (result instanceof Error) {
47
+ this.push({ error: { step, ...result } })
48
+ this.interrupted = true
49
+ } else
50
+ this.push({ [step]: result ?? null })
51
+ })
52
+
53
+ await Promise.all(promises)
54
+ }
55
+
56
+ private async call (endpoint: string): Promise<Maybe<unknown>> {
57
+ const [operation, component, namespace = 'default'] = endpoint.split('.').reverse()
58
+ const key = `${namespace}.${component}`
59
+
60
+ this.components[key] ??= await this.discover(key, namespace, component)
61
+
62
+ return await this.components[key].invoke(operation, { input: this.context })
63
+ }
64
+
65
+ private async discover (key: string, namespace: string, component: string): Promise<Component> {
66
+ if (this.discovery[key] === undefined)
67
+ this.discovery[key] = this.remotes.discover(namespace, component)
68
+
69
+ return await this.discovery[key]
70
+ }
71
+ }
72
+
73
+ export interface Context {
74
+ storage: string
75
+ path: string
76
+ entry: Entry
77
+ }
@@ -0,0 +1,28 @@
1
+ import { posix } from 'node:path'
2
+ import { match } from 'matchacho'
3
+ import { Execution } from './Execution'
4
+ import type { Input } from '../types'
5
+ import type { Entry } from '@toa.io/extensions.storages'
6
+ import type { Remotes } from '../../../Remotes'
7
+
8
+ export class Workflow {
9
+ private readonly units: Unit[]
10
+ private readonly remotes: Remotes
11
+
12
+ public constructor (units: Unit[] | Unit, remotes: Remotes) {
13
+ this.units = match<Unit[]>(units,
14
+ Array, (units: Unit[]) => units,
15
+ Object, (unit: Unit) => [unit])
16
+
17
+ this.remotes = remotes
18
+ }
19
+
20
+ public execute (request: Input, storage: string, entry: Entry): Execution {
21
+ const path = posix.join(request.path, entry.id)
22
+ const context = { storage, path, entry }
23
+
24
+ return new Execution(context, this.units, this.remotes)
25
+ }
26
+ }
27
+
28
+ export type Unit = Record<string, string>
@@ -0,0 +1 @@
1
+ export { Workflow, type Unit } from './Workflow'
@@ -21,16 +21,8 @@ it('should create branch', async () => {
21
21
  const node = manifest(declaration, mf)
22
22
 
23
23
  expect(node).toBeDefined()
24
-
25
- // namespace route
26
24
  expect(node.routes).toHaveLength(1)
27
- expect(node.routes[0].path).toBe('/' + namespace)
28
-
29
- const ns = node.routes[0].node
30
-
31
- // component route
32
- expect(ns.routes).toHaveLength(1)
33
- expect(ns.routes[0].path).toBe('/' + name)
25
+ expect(node.routes[0].path).toBe('/' + namespace + '/' + name)
34
26
  })
35
27
 
36
28
  it('should not create node for default namespace', async () => {
@@ -43,16 +35,16 @@ it('should not create node for default namespace', async () => {
43
35
  })
44
36
 
45
37
  it('should throw on invalid declaration type', async () => {
46
- expect(() => manifest('hello' as unknown as object, mf)).toThrow('RTD parse error')
38
+ expect(() => manifest('hello' as unknown as object, mf))
39
+ .toThrow('Exposition declaration must be an object')
47
40
  })
48
41
 
49
42
  it('should set namespace and component', async () => {
50
43
  const node = manifest(declaration, mf)
51
44
 
52
- const ns = node.routes[0].node
53
- const cm = ns.routes[0].node
54
- const root = cm.routes[0].node
55
- const GET = root.methods[0]
45
+ const root = node.routes[0].node
46
+ const intemediate = root.routes[0].node
47
+ const GET = intemediate.methods[0]
56
48
 
57
49
  expect(GET.mapping?.namespace).toBe(namespace)
58
50
  expect(GET.mapping?.component).toBe(name)
@@ -1,25 +1,28 @@
1
+ import assert from 'node:assert'
1
2
  import { parse, type Node, type Method, type Query } from './RTD/syntax'
2
3
  import { shortcuts } from './Directive'
3
4
  import * as schemas from './schemas'
4
5
  import type { Manifest } from '@toa.io/norm'
5
6
 
6
7
  export function manifest (declaration: object, manifest: Manifest): Node {
7
- declaration = wrap(manifest.name, declaration)
8
+ assert.ok(typeof declaration === 'object' && declaration !== null,
9
+ 'Exposition declaration must be an object')
8
10
 
9
- if (manifest.namespace !== undefined && manifest.namespace !== 'default')
10
- declaration = wrap(manifest.namespace, declaration)
11
+ declaration = wrap(declaration, manifest.namespace, manifest.name)
11
12
 
12
13
  const node = parse(declaration, shortcuts)
13
14
 
14
15
  concretize(node, manifest)
15
-
16
16
  schemas.node.validate(node)
17
17
 
18
18
  return node
19
19
  }
20
20
 
21
- function wrap (segment: string, declaration: object): object {
22
- return { ['/' + segment]: { protected: true, ...declaration } }
21
+ function wrap (declaration: object, namespace: string, name: string): object {
22
+ const path = (namespace === undefined || namespace === 'default' ? '' : '/' + namespace) +
23
+ '/' + name
24
+
25
+ return { [path]: { protected: true, ...declaration } }
23
26
  }
24
27
 
25
28
  function concretize (node: Node, manifest: Manifest): void {
package/source/schemas.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  import { resolve } from 'node:path'
2
2
  import schemas from '@toa.io/schemas'
3
+ import type { Query } from './HTTP'
4
+ import type { Node } from './RTD'
5
+ import type { Schema } from '@toa.io/schemas'
6
+ import type { Annotation } from './Annotation'
3
7
 
4
8
  const path = resolve(__dirname, '../schemas')
5
9
  const namespace = schemas.namespace(path)
6
10
 
7
- export const querystring = namespace.schema('querystring')
8
- export const annotaion = namespace.schema('annotation')
9
- export const node = namespace.schema('node')
11
+ export const querystring: Schema<Query> = namespace.schema('querystring')
12
+ export const annotaion: Schema<Annotation> = namespace.schema('annotation')
13
+ export const node: Schema<Node> = namespace.schema('node')
@@ -1,10 +1,10 @@
1
1
  import { Connector } from '@toa.io/core';
2
2
  import { type IncomingMessage, type OutgoingMessage } from './messages';
3
3
  export declare class Server extends Connector {
4
+ private server?;
4
5
  private readonly app;
5
6
  private readonly debug;
6
7
  private readonly requestedPort;
7
- private server?;
8
8
  private constructor();
9
9
  get port(): number;
10
10
  static create(options?: Partial<Properties>): Server;
@@ -14,15 +14,15 @@ const messages_1 = require("./messages");
14
14
  const exceptions_1 = require("./exceptions");
15
15
  const formats_1 = require("./formats");
16
16
  class Server extends core_1.Connector {
17
+ server;
17
18
  app;
18
19
  debug;
19
20
  requestedPort;
20
- server;
21
- constructor(app, debug, requestedPort) {
21
+ constructor(app, debug, port) {
22
22
  super();
23
23
  this.app = app;
24
24
  this.debug = debug;
25
- this.requestedPort = requestedPort;
25
+ this.requestedPort = port;
26
26
  }
27
27
  get port() {
28
28
  if (this.server === undefined)
@@ -38,7 +38,6 @@ class Server extends core_1.Connector {
38
38
  : { ...DEFAULTS, ...options };
39
39
  const app = (0, express_1.default)();
40
40
  app.disable('x-powered-by');
41
- // app.use(cors(CORS))
42
41
  app.use(supportedMethods(properties.methods));
43
42
  return new Server(app, properties.debug, properties.port);
44
43
  }
@@ -65,7 +64,7 @@ class Server extends core_1.Connector {
65
64
  }
66
65
  extend(request) {
67
66
  const message = request;
68
- message.encoder = negotiate(request);
67
+ negotiate(request, message);
69
68
  message.pipelines = { body: [], response: [] };
70
69
  message.parse = async () => {
71
70
  const value = await (0, messages_1.read)(request);
@@ -77,8 +76,6 @@ class Server extends core_1.Connector {
77
76
  }
78
77
  success(request, response) {
79
78
  return (message) => {
80
- for (const transform of request.pipelines.response)
81
- transform(message);
82
79
  let status = message.status;
83
80
  if (status === undefined)
84
81
  if (message.body === null)
@@ -90,11 +87,7 @@ class Server extends core_1.Connector {
90
87
  else
91
88
  status = 200;
92
89
  response.status(status);
93
- message.headers?.forEach((value, key) => response.set(key, value));
94
- if (message.body !== undefined && message.body !== null)
95
- (0, messages_1.write)(request, response, message);
96
- else
97
- response.end();
90
+ (0, messages_1.write)(request, response, message);
98
91
  };
99
92
  }
100
93
  fail(request, response) {
@@ -105,15 +98,13 @@ class Server extends core_1.Connector {
105
98
  ? exception.status
106
99
  : 500;
107
100
  response.status(status);
108
- const outputAllowed = exception instanceof exceptions_1.ClientError || this.debug;
109
- if (outputAllowed) {
110
- const body = exception instanceof exceptions_1.Exception
101
+ const message = {};
102
+ const verbose = exception instanceof exceptions_1.ClientError || this.debug;
103
+ if (verbose)
104
+ message.body = exception instanceof exceptions_1.Exception
111
105
  ? exception.body
112
106
  : (exception.stack ?? exception.message);
113
- (0, messages_1.write)(request, response, { body });
114
- }
115
- else
116
- response.end();
107
+ (0, messages_1.write)(request, response, message);
117
108
  };
118
109
  }
119
110
  }
@@ -126,10 +117,19 @@ function supportedMethods(methods) {
126
117
  res.sendStatus(501);
127
118
  };
128
119
  }
129
- function negotiate(request) {
120
+ function negotiate(request, message) {
121
+ if (request.headers.accept !== undefined) {
122
+ const match = SUBTYPE.exec(request.headers.accept);
123
+ if (match !== null) {
124
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
+ const { type, subtype, suffix } = match.groups;
126
+ request.headers.accept = `${type}/${suffix}`;
127
+ message.subtype = subtype;
128
+ }
129
+ }
130
130
  const negotiator = new negotiator_1.default(request);
131
131
  const mediaType = negotiator.mediaType(formats_1.types);
132
- return mediaType === undefined ? null : formats_1.formats[mediaType];
132
+ message.encoder = mediaType === undefined ? null : formats_1.formats[mediaType];
133
133
  }
134
134
  // https://github.com/whatwg/fetch/issues/1254
135
135
  async function adam(request) {
@@ -145,4 +145,5 @@ const DEFAULTS = {
145
145
  debug: false,
146
146
  port: 8000
147
147
  };
148
+ const SUBTYPE = /^(?<type>\w{1,32})\/(vnd\.toa\.(?<subtype>\S{1,32})\+)(?<suffix>\S{1,32})$/;
148
149
  //# sourceMappingURL=Server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Server.js","sourceRoot":"","sources":["../../source/HTTP/Server.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,sDAAwB;AACxB,sDAA6B;AAC7B,uCAAwC;AACxC,6CAAwC;AACxC,4DAAmC;AACnC,yCAAoF;AACpF,6CAAqD;AACrD,uCAA0C;AAK1C,MAAa,MAAO,SAAQ,gBAAS;IAGG;IACnB;IACA;IAJX,MAAM,CAAc;IAE5B,YAAsC,GAAY,EAC/B,KAAc,EACd,aAAqB;QACtC,KAAK,EAAE,CAAA;QAH6B,QAAG,GAAH,GAAG,CAAS;QAC/B,UAAK,GAAL,KAAK,CAAS;QACd,kBAAa,GAAb,aAAa,CAAQ;IAExC,CAAC;IAED,IAAW,IAAI;QACb,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,aAAa,CAAA;QAExD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAA;QAErC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ;YACjD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAEvD,OAAO,OAAO,CAAC,IAAI,CAAA;IACrB,CAAC;IAEM,MAAM,CAAC,MAAM,CAAE,OAA6B;QACjD,MAAM,UAAU,GAAG,OAAO,KAAK,SAAS;YACtC,CAAC,CAAC,QAAQ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AAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAO,CAAC,SAAS,CAAC,CAAA;AACvE,CAAC;AAED,8CAA8C;AAC9C,KAAK,UAAU,IAAI,CAAE,OAAgB;IACnC,MAAM,SAAS,GAAG,IAAA,gBAAM,GAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,iBAAE,CAAC,iBAAiB,CAAC,iBAAE,CAAC,OAAO,CAAC,CAAA;IAEhD,OAAO;SACJ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC;SAC7B,IAAI,CAAC,OAAO,CAAC,CAAA;IAEhB,OAAO,MAAM,SAAS,CAAA;AACxB,CAAC;AAED,MAAM,QAAQ,GAAe;IAC3B,OAAO,EAAE,IAAI,GAAG,CAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC9E,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;CACX,CAAA;AAUD,MAAM,OAAO,GAAG,4EAA4E,CAAA"}
@@ -13,6 +13,7 @@ export interface IncomingMessage extends Request {
13
13
  query: Query;
14
14
  parse: <T>() => Promise<T>;
15
15
  encoder: Format | null;
16
+ subtype: string | null;
16
17
  pipelines: {
17
18
  body: Array<(input: unknown) => unknown>;
18
19
  response: Array<(output: OutgoingMessage) => void>;
@@ -6,6 +6,9 @@ const streams_1 = require("@toa.io/streams");
6
6
  const formats_1 = require("./formats");
7
7
  const exceptions_1 = require("./exceptions");
8
8
  function write(request, response, message) {
9
+ for (const transform of request.pipelines.response)
10
+ transform(message);
11
+ message.headers?.forEach((value, key) => response.set(key, value));
9
12
  if (message.body instanceof node_stream_1.Readable)
10
13
  stream(message, request, response);
11
14
  else
@@ -29,7 +32,7 @@ async function read(request) {
29
32
  }
30
33
  exports.read = read;
31
34
  function send(message, request, response) {
32
- if (message.body === undefined) {
35
+ if (message.body === undefined || message.body === null) {
33
36
  response.end();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,CAAA;AACtB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,MAAM,CAAC,CAAA;AAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAA"}
@@ -1,14 +1,11 @@
1
- import type { OutgoingMessage } from '../../HTTP';
2
1
  import type { Input, Output } from '../../io';
3
- import type { Family } from '../../Directive';
4
2
  import type { Interceptor } from '../../Interception';
5
- export declare class CORS implements Family, Interceptor {
3
+ export declare class CORS implements Interceptor {
6
4
  readonly name = "cors";
7
5
  readonly mandatory = true;
8
6
  private readonly allowedHeaders;
9
7
  private readonly headers;
10
- create(): null;
11
- settle(_: unknown[], input: Input, output: OutgoingMessage): void;
12
8
  intercept(input: Input): Output;
13
9
  allowHeader(header: string): void;
10
+ private preflightResponse;
14
11
  }
@@ -13,30 +13,32 @@ class CORS {
13
13
  'cache-control': 'public, max-age=3600',
14
14
  vary: 'origin'
15
15
  });
16
- create() {
16
+ intercept(input) {
17
+ const origin = input.headers.origin;
18
+ if (origin === undefined)
19
+ return null;
20
+ if (input.method === 'OPTIONS')
21
+ return this.preflightResponse(origin);
22
+ input.pipelines.response.push((output) => {
23
+ output.headers ??= new Headers();
24
+ output.headers.set('access-control-allow-origin', origin);
25
+ output.headers.set('access-control-expose-headers', 'authorization, content-type, content-length, etag');
26
+ if (input.method === 'GET' || input.method === 'HEAD' || input.method === 'OPTIONS')
27
+ output.headers.append('vary', 'origin');
28
+ });
17
29
  return null;
18
30
  }
19
- settle(_, input, output) {
20
- if (input.headers.origin === undefined)
21
- return;
22
- output.headers ??= new Headers();
23
- output.headers.set('access-control-allow-origin', input.headers.origin);
24
- output.headers.set('access-control-expose-headers', 'authorization, content-type, content-length, etag');
25
- output.headers.append('vary', 'origin');
31
+ allowHeader(header) {
32
+ this.allowedHeaders.add(header.toLowerCase());
33
+ this.headers.set('access-control-allow-headers', Array.from(this.allowedHeaders).join(', '));
26
34
  }
27
- intercept(input) {
28
- if (input.method !== 'OPTIONS' || input.headers.origin === undefined)
29
- return null;
30
- this.headers.set('access-control-allow-origin', input.headers.origin);
35
+ preflightResponse(origin) {
36
+ this.headers.set('access-control-allow-origin', origin);
31
37
  return {
32
38
  status: 204,
33
39
  headers: this.headers
34
40
  };
35
41
  }
36
- allowHeader(header) {
37
- this.allowedHeaders.add(header.toLowerCase());
38
- this.headers.set('access-control-allow-headers', Array.from(this.allowedHeaders).join(', '));
39
- }
40
42
  }
41
43
  exports.CORS = CORS;
42
44
  //# sourceMappingURL=CORS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CORS.js","sourceRoot":"","sources":["../../../source/directives/cors/CORS.ts"],"names":[],"mappings":";;;AAKA,MAAa,IAAI;IACC,IAAI,GAAG,MAAM,CAAA;IACb,SAAS,GAAG,IAAI,CAAA;IAEf,cAAc,GAAG,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,eAAe,EAAE,cAAc,CAAC,CAAC,CAAA;IAE7E,OAAO,GAAG,IAAI,OAAO,CAAC;QACrC,8BAA8B,EAAE,+BAA+B;QAC/D,kCAAkC,EAAE,MAAM;QAC1C,8BAA8B,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1E,wBAAwB,EAAE,MAAM;QAChC,eAAe,EAAE,sBAAsB;QACvC,IAAI,EAAE,QAAQ;KACf,CAAC,CAAA;IAEK,MAAM;QACX,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,MAAM,CAAE,CAAY,EAAE,KAAY,EAAE,MAAuB;QAChE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS;YACpC,OAAM;QAER,MAAM,CAAC,OAAO,KAAK,IAAI,OAAO,EAAE,CAAA;QAChC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACvE,MAAM,C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AM,EAAE,GAAG;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAA;IACH,CAAC;CACF;AAlDD,oBAkDC"}
@@ -7,6 +7,6 @@ const cache_1 = require("./cache");
7
7
  const octets_1 = require("./octets");
8
8
  const cors_1 = require("./cors");
9
9
  const vary_1 = require("./vary");
10
- exports.families = [auth_1.authorization, cache_1.cache, octets_1.octets, cors_1.cors, vary_1.vary, dev_1.dev];
10
+ exports.families = [auth_1.authorization, cache_1.cache, octets_1.octets, vary_1.vary, dev_1.dev];
11
11
  exports.interceptors = [cors_1.cors];
12
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/directives/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,iCAAsC;AACtC,mCAA+B;AAC/B,qCAAiC;AACjC,iCAA6B;AAC7B,iCAA6B;AAIhB,QAAA,QAAQ,GAAa,CAAC,oBAAa,EAAE,aAAK,EAAE,eAAM,EAAE,WAAI,EAAE,WAAI,EAAE,SAAG,CAAC,CAAA;AACpE,QAAA,YAAY,GAAkB,CAAC,WAAI,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/directives/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,iCAAsC;AACtC,mCAA+B;AAC/B,qCAAiC;AACjC,iCAA6B;AAC7B,iCAA6B;AAIhB,QAAA,QAAQ,GAAa,CAAC,oBAAa,EAAE,aAAK,EAAE,eAAM,EAAE,WAAI,EAAE,SAAG,CAAC,CAAA;AAC9D,QAAA,YAAY,GAAkB,CAAC,WAAI,CAAC,CAAA"}
@@ -1,10 +1,18 @@
1
+ import type { Unit } from './workflow';
1
2
  import type { Component } from '@toa.io/core';
2
3
  import type { Output } from '../../io';
3
4
  import type { Directive, Input } from './types';
5
+ import type { Remotes } from '../../Remotes';
4
6
  export declare class Delete implements Directive {
5
7
  readonly targeted = true;
8
+ private readonly workflow?;
6
9
  private readonly discovery;
7
10
  private storage;
8
- constructor(value: null, discovery: Promise<Component>);
11
+ constructor(options: Options | null, discovery: Promise<Component>, remotes: Remotes);
9
12
  apply(storage: string, request: Input): Promise<Output>;
13
+ private delete;
14
+ private execute;
15
+ }
16
+ export interface Options {
17
+ workflow?: Unit[] | Unit;
10
18
  }
@@ -24,23 +24,47 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Delete = void 0;
27
+ const stream_1 = require("stream");
27
28
  const HTTP_1 = require("../../HTTP");
28
29
  const schemas = __importStar(require("./schemas"));
30
+ const workflow_1 = require("./workflow");
29
31
  class Delete {
30
32
  targeted = true;
33
+ workflow;
31
34
  discovery;
32
35
  storage = null;
33
- constructor(value, discovery) {
34
- schemas.remove.validate(value);
36
+ constructor(options, discovery, remotes) {
37
+ schemas.remove.validate(options);
38
+ if (options?.workflow !== undefined)
39
+ this.workflow = new workflow_1.Workflow(options.workflow, remotes);
35
40
  this.discovery = discovery;
36
41
  }
37
42
  async apply(storage, request) {
38
43
  this.storage ??= await this.discovery;
39
- const input = { storage, path: request.path };
40
- const error = await this.storage.invoke('delete', { input });
41
- if (error instanceof Error)
44
+ const entry = await this.storage.invoke('get', { input: { storage, path: request.url } });
45
+ if (entry instanceof Error)
42
46
  throw new HTTP_1.NotFound();
43
- return {};
47
+ const output = {};
48
+ if (this.workflow !== undefined) {
49
+ output.status = 202;
50
+ output.body = stream_1.Readable.from(this.execute(request, storage, entry));
51
+ }
52
+ else
53
+ await this.delete(storage, request);
54
+ return output;
55
+ }
56
+ async delete(storage, request) {
57
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
58
+ await this.storage.invoke('delete', { input: { storage, path: request.url } });
59
+ }
60
+ async *execute(request, storage, entry) {
61
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
+ for await (const chunk of this.workflow.execute(request, storage, entry)) {
63
+ yield chunk;
64
+ if (typeof chunk === 'object' && chunk !== null && 'error' in chunk)
65
+ return;
66
+ }
67
+ await this.delete(storage, request);
44
68
  }
45
69
  }
46
70
  exports.Delete = Delete;
@@ -1 +1 @@
1
- {"version":3,"file":"Delete.js","sourceRoot":"","sources":["../../../source/directives/octets/Delete.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,mDAAoC;AAMpC,MAAa,MAAM;IACD,QAAQ,GAAG,IAAI,CAAA;IAEd,SAAS,CAAoB;IACtC,OAAO,GAAqB,IAAI,CAAA;IAExC,YAAoB,KAAW,EAAE,SAA6B;QAC5D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEM,KAAK,CAAC,KAAK,CAAE,OAAe,EAAE,OAAc;QACjD,IAAI,CAAC,OAAO,KAAK,MAAM,IAAI,CAAC,SAAS,CAAA;QAErC,MAAM,KAAK,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAA;QAC7C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAiB,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAE5E,IAAI,KAAK,YAAY,KAAK;YACxB,MAAM,IAAI,eAAQ,EAAE,CAAA;QAEtB,OAAO,EAAE,CAAA;IACX,CAAC;CACF;AAvBD,wBAuBC"}
1
+ {"version":3,"file":"Delete.js","sourceRoot":"","sources":["../../../source/directives/octets/Delete.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAiC;AACjC,qCAAqC;AACrC,mDAAoC;AACpC,yCAAqC;AASrC,MAAa,MAAM;IACD,QAAQ,GAAG,IAAI,CAAA;IAEd,QAAQ,CAAW;IACnB,SAAS,CAAoB;IACtC,OAAO,GAAqB,IAAI,CAAA;IAExC,YAAoB,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AC9C,CAAC;IAEO,KAAK,CAAC,CAAE,OAAO,CAAE,OAAc,EAAE,OAAe,EAAE,KAAY;QACpE,oEAAoE;QACpE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,QAAS,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;YAC1E,MAAM,KAAK,CAAA;YAEX,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK;gBACjE,OAAM;QACV,CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACrC,CAAC;CACF;AArDD,wBAqDC"}
@@ -6,13 +6,12 @@ export declare class Fetch implements Directive {
6
6
  private readonly permissions;
7
7
  private readonly discovery;
8
8
  private storage;
9
- constructor(permissions: Partial<Permissions> | null, discovery: Promise<Component>);
9
+ constructor(permissions: Permissions | null, discovery: Promise<Component>);
10
10
  apply(storage: string, request: Input): Promise<Output>;
11
11
  private fetch;
12
12
  private get;
13
13
  }
14
- interface Permissions {
15
- blob: boolean;
16
- meta: boolean;
14
+ export interface Permissions {
15
+ blob?: boolean;
16
+ meta?: boolean;
17
17
  }
18
- export {};
@@ -39,16 +39,18 @@ class Fetch {
39
39
  }
40
40
  async apply(storage, request) {
41
41
  this.storage ??= await this.discovery;
42
- if (request.url.slice(-5) === ':meta')
43
- return await this.get(storage, request);
44
- else
45
- return await this.fetch(storage, request);
46
- }
47
- async fetch(storage, request) {
48
- const filename = node_path_1.posix.basename(request.url);
49
- const variant = filename.includes('.');
42
+ const variant = node_path_1.posix.basename(request.url).includes('.');
43
+ const metadata = request.subtype === 'octets.entry';
44
+ if (!variant && metadata)
45
+ if (this.permissions.meta)
46
+ return this.get(storage, request);
47
+ else
48
+ throw new HTTP_1.Forbidden('Metadata is not accessible.');
50
49
  if (!variant && !this.permissions.blob)
51
50
  throw new HTTP_1.Forbidden('BLOB variant must be specified.');
51
+ return await this.fetch(storage, request);
52
+ }
53
+ async fetch(storage, request) {
52
54
  if ('if-none-match' in request.headers)
53
55
  return { status: 304 };
54
56
  const input = { storage, path: request.url };
@@ -63,10 +65,7 @@ class Fetch {
63
65
  return { headers, body: result.stream };
64
66
  }
65
67
  async get(storage, request) {
66
- if (!this.permissions.meta)
67
- throw new HTTP_1.Forbidden('Metadata is not accessible.');
68
- const path = request.url.slice(0, -5);
69
- const input = { storage, path };
68
+ const input = { storage, path: request.url };
70
69
  const entry = await this.storage.invoke('get', { input });
71
70
  if (entry instanceof Error)
72
71
  throw new HTTP_1.NotFound();