@toa.io/bindings.amqp 0.20.0-dev.31 → 0.20.0-dev.34

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 (75) hide show
  1. package/package.json +16 -10
  2. package/readme.md +10 -45
  3. package/schemas/annotation.cos.yaml +2 -0
  4. package/source/broadcast.js +0 -5
  5. package/source/communication.js +49 -0
  6. package/source/constants.js +0 -1
  7. package/source/consumer.js +0 -5
  8. package/source/deployment/annotation.test.ts +40 -0
  9. package/source/deployment/annotation.ts +26 -0
  10. package/source/deployment/context.ts +112 -0
  11. package/source/deployment/index.ts +10 -0
  12. package/source/deployment/instance.ts +3 -0
  13. package/source/deployment/sources.ts +44 -0
  14. package/source/deployment.ts +14 -0
  15. package/source/emitter.js +0 -5
  16. package/source/factory.js +22 -30
  17. package/source/index.js +0 -2
  18. package/source/producer.js +0 -6
  19. package/source/receiver.js +0 -6
  20. package/transpiled/broadcast.d.ts +10 -0
  21. package/transpiled/broadcast.js +31 -0
  22. package/transpiled/broadcast.js.map +1 -0
  23. package/transpiled/communication.d.ts +9 -0
  24. package/transpiled/communication.js +37 -0
  25. package/transpiled/communication.js.map +1 -0
  26. package/transpiled/constants.d.ts +1 -0
  27. package/transpiled/constants.js +3 -0
  28. package/transpiled/constants.js.map +1 -0
  29. package/transpiled/consumer.d.ts +9 -0
  30. package/transpiled/consumer.js +23 -0
  31. package/transpiled/consumer.js.map +1 -0
  32. package/transpiled/deployment/annotation.d.ts +10 -0
  33. package/transpiled/deployment/annotation.js +43 -0
  34. package/transpiled/deployment/annotation.js.map +1 -0
  35. package/transpiled/deployment/context.d.ts +7 -0
  36. package/transpiled/deployment/context.js +86 -0
  37. package/transpiled/deployment/context.js.map +1 -0
  38. package/transpiled/deployment/index.d.ts +4 -0
  39. package/transpiled/deployment/index.js +34 -0
  40. package/transpiled/deployment/index.js.map +1 -0
  41. package/transpiled/deployment/instance.d.ts +2 -0
  42. package/transpiled/deployment/instance.js +3 -0
  43. package/transpiled/deployment/instance.js.map +1 -0
  44. package/transpiled/deployment/sources.d.ts +8 -0
  45. package/transpiled/deployment/sources.js +35 -0
  46. package/transpiled/deployment/sources.js.map +1 -0
  47. package/transpiled/deployment.d.ts +4 -0
  48. package/transpiled/deployment.js +38 -0
  49. package/transpiled/deployment.js.map +1 -0
  50. package/transpiled/emitter.d.ts +9 -0
  51. package/transpiled/emitter.js +24 -0
  52. package/transpiled/emitter.js.map +1 -0
  53. package/transpiled/factory.d.ts +13 -0
  54. package/transpiled/factory.js +46 -0
  55. package/transpiled/factory.js.map +1 -0
  56. package/transpiled/index.d.ts +5 -0
  57. package/transpiled/index.js +9 -0
  58. package/transpiled/index.js.map +1 -0
  59. package/transpiled/producer.d.ts +5 -0
  60. package/transpiled/producer.js +31 -0
  61. package/transpiled/producer.js.map +1 -0
  62. package/transpiled/queues.d.ts +6 -0
  63. package/transpiled/queues.js +10 -0
  64. package/transpiled/queues.js.map +1 -0
  65. package/transpiled/receiver.d.ts +5 -0
  66. package/transpiled/receiver.js +34 -0
  67. package/transpiled/receiver.js.map +1 -0
  68. package/tsconfig.json +12 -0
  69. package/source/annotation.js +0 -5
  70. package/source/deployment.js +0 -32
  71. package/source/pointer.js +0 -18
  72. package/test/annotations.test.js +0 -16
  73. package/test/deployment.test.js +0 -36
  74. package/test/factory.test.js +0 -190
  75. package/test/pointer.test.js +0 -59
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@toa.io/bindings.amqp",
3
- "version": "0.20.0-dev.31",
3
+ "version": "0.20.0-dev.34",
4
4
  "description": "Toa AMQP Binding",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
7
- "main": "source/index.js",
8
7
  "repository": {
9
8
  "type": "git",
10
9
  "url": "git+https://github.com/toa-io/toa.git"
@@ -15,15 +14,22 @@
15
14
  "publishConfig": {
16
15
  "access": "public"
17
16
  },
17
+ "main": "transpiled/index.js",
18
+ "types": "transpiled/index.d.ts",
19
+ "dependencies": {
20
+ "@toa.io/console": "0.20.0-dev.34",
21
+ "@toa.io/core": "0.20.0-dev.34",
22
+ "@toa.io/generic": "0.20.0-dev.34",
23
+ "@toa.io/pointer": "0.20.0-dev.34",
24
+ "comq": "0.8.0"
25
+ },
18
26
  "scripts": {
19
- "test": "echo \"Error: run tests from root\" && exit 1"
27
+ "prepublishOnly": "npm run transpile",
28
+ "transpile": "tsc"
20
29
  },
21
- "dependencies": {
22
- "@toa.io/console": "0.20.0-dev.31",
23
- "@toa.io/core": "0.20.0-dev.31",
24
- "@toa.io/generic": "0.20.0-dev.31",
25
- "@toa.io/generics.amqp": "0.20.0-dev.31",
26
- "@toa.io/pointer": "0.20.0-dev.31"
30
+ "jest": {
31
+ "preset": "ts-jest",
32
+ "testEnvironment": "node"
27
33
  },
28
- "gitHead": "f9ad6bf2bab1298b96ca52557b7e36b6041cfc88"
34
+ "gitHead": "7035b1985fe9bb844069308a272d061bfbd38bf0"
29
35
  }
package/readme.md CHANGED
@@ -1,54 +1,19 @@
1
- # Toa AMQP Binding
1
+ # Toa AMQP binding
2
2
 
3
3
  AMQP asynchronous binding on top of [ComQ](/libraries/comq).
4
4
 
5
- ## Deployment
6
-
7
- AMQP deployment must be declared with
8
- the [Pointer annotation](/libraries/pointer/readme.md#annotation). Either `system` or `default`
9
- pointers must be defined.
10
-
11
- Well-known annotation shortcut `amqp` is available.
12
-
13
- ```yaml
14
- # context.toa.yaml
15
- annotations:
16
- "@toa.io/bindings.amqp":
17
- system: url0 # the runtime
18
- default: url1 # all undeclared
19
- dummies: url2 # namespace-wide
20
- dummies.dummy1: url # component exclusive
21
- ```
22
-
23
- ### Concise Declaration
24
-
25
- Well-known shortcut `amqp` is available. The next two declarations are equivalent:
5
+ ## Annotation
26
6
 
27
7
  ```yaml
28
- # context.toa.yaml
29
- annotations:
30
- "@toa.io/bindings.amqp":
31
- system: url0
32
- dummies: url1
33
- ```
34
-
35
- ```yaml
36
- # context.toa.yaml
37
8
  amqp:
38
- system: url0
39
- dummies: url1
9
+ context:
10
+ .: amqp://com.example.com
11
+ dummies.dummy: amqp://dummmy.example.com
12
+ sources:
13
+ somewhere: amqp://queues.somewhere.com
40
14
  ```
41
15
 
42
- `string` annotation value is considered as `default`. The next two declarations are equivalent:
16
+ Context annotaition is a [Pointer](/libraries/pointer) with `amqp-context` ID.
43
17
 
44
- ```yaml
45
- # context.toa.yaml
46
- annotations:
47
- "@toa.io/bindings.amqp":
48
- default: url1
49
- ```
50
-
51
- ```yaml
52
- # context.toa.yaml
53
- amqp: url1
54
- ```
18
+ Sources annotation is a set of Pointers, declared by components consuming foreign events.
19
+ Each Pointer ID is as follows: `amqp-sources-{source}`.
@@ -0,0 +1,2 @@
1
+ context*: <string>
2
+ sources: <string>
@@ -17,11 +17,6 @@ class Broadcast extends Connector {
17
17
  /** @type {string} */
18
18
  #group
19
19
 
20
- /**
21
- * @param {toa.amqp.Communication} comm
22
- * @param {toa.core.Locator} locator
23
- * @param {string} [group]
24
- */
25
20
  constructor (comm, locator, group) {
26
21
  super()
27
22
 
@@ -0,0 +1,49 @@
1
+ 'use strict'
2
+
3
+ const { assert } = require('comq')
4
+ const { Connector } = require('@toa.io/core')
5
+
6
+ class Communication extends Connector {
7
+ #resolve
8
+
9
+ /** @type {comq.IO} */
10
+ #io
11
+
12
+ constructor (resolve) {
13
+ super()
14
+
15
+ this.#resolve = resolve
16
+ }
17
+
18
+ async open () {
19
+ const references = await this.#resolve()
20
+
21
+ this.#io = await assert(...references)
22
+ }
23
+
24
+ async close () {
25
+ await this.#io.seal()
26
+ }
27
+
28
+ async dispose () {
29
+ if (this.#io !== undefined) await this.#io.close()
30
+ }
31
+
32
+ async reply (queue, process) {
33
+ await this.#io.reply(queue, process)
34
+ }
35
+
36
+ async request (queue, request) {
37
+ return this.#io.request(queue, request)
38
+ }
39
+
40
+ async emit (exchange, message, properties) {
41
+ await this.#io.emit(exchange, message, properties)
42
+ }
43
+
44
+ async consume (exchange, group, consumer) {
45
+ await this.#io.consume(exchange, group, consumer)
46
+ }
47
+ }
48
+
49
+ exports.Communication = Communication
@@ -1,4 +1,3 @@
1
1
  'use strict'
2
2
 
3
- exports.PREFIX = 'bindings-amqp'
4
3
  exports.SYSTEM = 'system'
@@ -13,11 +13,6 @@ class Consumer extends Connector {
13
13
  /** @type {toa.amqp.Communication} */
14
14
  #comm
15
15
 
16
- /**
17
- * @param {toa.amqp.Communication} comm
18
- * @param {toa.core.Locator} locator
19
- * @param {string} endpoint
20
- */
21
16
  constructor (comm, locator, endpoint) {
22
17
  super()
23
18
 
@@ -0,0 +1,40 @@
1
+ import { generate } from 'randomstring'
2
+ import { normalize } from './annotation'
3
+
4
+ it('should expand string', async () => {
5
+ const declaration = uri()
6
+ const annotation = normalize(declaration)
7
+
8
+ expect(annotation).toMatchObject({
9
+ context: {
10
+ '.': [declaration]
11
+ }
12
+ })
13
+ })
14
+
15
+ it('should expand context default', async () => {
16
+ const declaration = { context: uri() }
17
+ const annotation = normalize(declaration)
18
+
19
+ expect(annotation).toMatchObject({
20
+ context: {
21
+ '.': [declaration.context]
22
+ }
23
+ })
24
+ })
25
+
26
+ it('should expand context with sources', async () => {
27
+ const declaration = { context: uri(), sources: { foo: [uri()] } }
28
+ const annotation = normalize(declaration)
29
+
30
+ expect(annotation).toMatchObject({
31
+ context: {
32
+ '.': [declaration.context]
33
+ },
34
+ sources: declaration.sources
35
+ })
36
+ })
37
+
38
+ function uri (): string {
39
+ return 'http://host-' + generate()
40
+ }
@@ -0,0 +1,26 @@
1
+ import * as pointer from '@toa.io/pointer'
2
+ import { type URIMap } from '@toa.io/pointer'
3
+
4
+ export function normalize (declaration: string | Declaration): Annotation {
5
+ const annotation = expand(declaration)
6
+ const context = pointer.normalize(annotation.context)
7
+ const sources = pointer.normalize(annotation.sources)
8
+
9
+ return { context, sources }
10
+ }
11
+
12
+ function expand (declaration: string | Declaration): Declaration {
13
+ if (typeof declaration === 'string') return { context: { '.': [declaration] } }
14
+ else if (Array.isArray(declaration)) return { context: { '.': declaration } }
15
+ else return declaration
16
+ }
17
+
18
+ export interface Annotation {
19
+ context: URIMap
20
+ sources?: URIMap
21
+ }
22
+
23
+ export interface Declaration {
24
+ context: string | Record<string, string | string[]>
25
+ sources?: Record<string, string | string[]>
26
+ }
@@ -0,0 +1,112 @@
1
+ import { type Dependency, type Variable } from '@toa.io/operations'
2
+ import { encode, decode } from '@toa.io/generic'
3
+ import { resolveRecord, naming } from '@toa.io/pointer'
4
+ import { type Locator } from '@toa.io/core'
5
+ import { type AnnotationRecord } from '@toa.io/pointer/transpiled/Deployment'
6
+ import { dedupe } from '@toa.io/dns'
7
+ import { type Annotation } from './annotation'
8
+
9
+ export function createDependency (context: Context): Dependency {
10
+ const global: Variable[] = []
11
+ const variables = { global }
12
+
13
+ const contextVariables = createVariables(context)
14
+
15
+ global.push(...contextVariables)
16
+
17
+ return { variables }
18
+ }
19
+
20
+ export async function resolveURIs (locator: Locator): Promise<string[]> {
21
+ if (process.env.TOA_DEV === '1') return ['amqp://developer:secret@localhost']
22
+
23
+ const value = process.env[VARIABLE]
24
+
25
+ if (value === undefined) throw new Error(`Environment variable ${VARIABLE} is not specified`)
26
+
27
+ const map = decode(value)
28
+ const record = resolveRecord(map, locator.id)
29
+
30
+ return await parseRecord(record)
31
+ }
32
+
33
+ function createVariables (context: Context): Variable[] {
34
+ const variables: Variable[] = []
35
+ const uris = encode(context)
36
+
37
+ const contextVariable: Variable = {
38
+ name: VARIABLE,
39
+ value: uris
40
+ }
41
+
42
+ const secrets = createSecrets(context)
43
+
44
+ variables.push(contextVariable, ...secrets)
45
+
46
+ return variables
47
+ }
48
+
49
+ function createSecrets (context: Context): Variable[] {
50
+ const secrets: Variable[] = []
51
+
52
+ for (const key of Object.keys(context)) {
53
+ const keySecrets = createKeySecrets(key)
54
+
55
+ secrets.push(...keySecrets)
56
+ }
57
+
58
+ return secrets
59
+ }
60
+
61
+ function createKeySecrets (key: string): Variable[] {
62
+ const username = createSecretVariable(key, 'username')
63
+ const password = createSecretVariable(key, 'password')
64
+
65
+ return [username, password]
66
+ }
67
+
68
+ function createSecretVariable (key: string, secretKey: string): Variable {
69
+ const varKey = key === '.' ? '' : key
70
+ const varName = naming.nameVariable(ID, varKey, secretKey.toUpperCase())
71
+ const secName = naming.nameSecret(ID, key)
72
+
73
+ return {
74
+ name: varName,
75
+ secret: {
76
+ name: secName,
77
+ key: secretKey
78
+ }
79
+ }
80
+ }
81
+
82
+ async function parseRecord (record: AnnotationRecord): Promise<string[]> {
83
+ const unique = await dedupe(record.references)
84
+ const urls = new Array(unique.length)
85
+ const key = record.key === '.' ? '' : record.key
86
+ const username = readEnv(key, 'USERNAME')
87
+ const password = readEnv(key, 'PASSWORD')
88
+
89
+ for (let i = 0; i < record.references.length; i++) {
90
+ const url = new URL(record.references[i])
91
+
92
+ url.username = username
93
+ url.password = password
94
+
95
+ urls[i] = url.href
96
+ }
97
+
98
+ return urls
99
+ }
100
+
101
+ function readEnv (key: string, name: string): string {
102
+ const variable = naming.nameVariable(ID, key, name)
103
+ const value = process.env[variable]
104
+
105
+ if (value === undefined) throw new Error(variable + ' is not set')
106
+ else return value
107
+ }
108
+
109
+ const ID = 'amqp-context'
110
+ const VARIABLE = 'TOA_AMQP_CONTEXT'
111
+
112
+ type Context = Annotation['context']
@@ -0,0 +1,10 @@
1
+ import { type Dependency } from '@toa.io/operations'
2
+ import { type Declaration, normalize } from './annotation'
3
+ import * as sources from './sources'
4
+ import { type Instance } from './instance'
5
+
6
+ export function deployment (instances: Instance[], declaration: Declaration): Dependency {
7
+ const annotation = normalize(declaration)
8
+
9
+ return sources.createDependency(annotation.sources, instances)
10
+ }
@@ -0,0 +1,3 @@
1
+ import { type context } from '@toa.io/norm'
2
+
3
+ export type Instance = context.Dependency
@@ -0,0 +1,44 @@
1
+ import { createVariables, resolve, type Request } from '@toa.io/pointer'
2
+ import { type component } from '@toa.io/norm'
3
+ import { type Dependency } from '@toa.io/operations'
4
+ import { type Locator } from '@toa.io/core'
5
+ import { type Instance } from './instance'
6
+ import { type Annotation } from './annotation'
7
+
8
+ export function createDependency (sources: Sources, instances: Instance[]): Dependency {
9
+ const requests = []
10
+
11
+ for (const instance of instances) {
12
+ const request = createRequest(instance)
13
+
14
+ if (request !== null) requests.push(request)
15
+ }
16
+
17
+ const variables = createVariables(ID, sources, requests)
18
+
19
+ return { variables }
20
+ }
21
+
22
+ export async function resolveURIs (locator: Locator, label: string): Promise<string[]> {
23
+ return await resolve(ID, locator.id)
24
+ }
25
+
26
+ function createRequest (instance: Instance): Request | null {
27
+ const group = instance.locator.label
28
+ const selectors = createSelectors(instance.component)
29
+
30
+ if (selectors === null) return null
31
+ else return { group, selectors }
32
+ }
33
+
34
+ function createSelectors (component: component.Component): string[] | null {
35
+ if (component.receivers === undefined) return null
36
+
37
+ const sources = Object.values(component.receivers).map((receiver) => receiver.source)
38
+
39
+ return sources.filter((source) => source !== undefined) as string[]
40
+ }
41
+
42
+ const ID = 'amqp-sources'
43
+
44
+ type Sources = Annotation['sources']
@@ -0,0 +1,14 @@
1
+ import { type Dependency } from '@toa.io/operations'
2
+ import { merge } from '@toa.io/generic'
3
+ import { type Declaration, normalize } from './deployment/annotation'
4
+ import * as sources from './deployment/sources'
5
+ import * as context from './deployment/context'
6
+ import { type Instance } from './deployment/instance'
7
+
8
+ export function deployment (instances: Instance[], declaration: Declaration): Dependency {
9
+ const annotation = normalize(declaration)
10
+ const contextDependency = context.createDependency(annotation.context)
11
+ const sourcesDependency = sources.createDependency(annotation.sources, instances)
12
+
13
+ return merge(contextDependency, sourcesDependency)
14
+ }
package/source/emitter.js CHANGED
@@ -14,11 +14,6 @@ class Emitter extends Connector {
14
14
  /** @type {toa.amqp.Communication} */
15
15
  #comm
16
16
 
17
- /**
18
- * @param {toa.amqp.Communication} comm
19
- * @param {toa.core.Locator} locator
20
- * @param {string} label
21
- */
22
17
  constructor (comm, locator, label) {
23
18
  super()
24
19
 
package/source/factory.js CHANGED
@@ -1,70 +1,62 @@
1
1
  'use strict'
2
2
 
3
3
  const { Locator } = require('@toa.io/core')
4
- const { connector } = require('@toa.io/generics.amqp')
5
4
 
6
5
  const { Producer } = require('./producer')
7
6
  const { Consumer } = require('./consumer')
8
7
  const { Emitter } = require('./emitter')
9
8
  const { Receiver } = require('./receiver')
10
9
  const { Broadcast } = require('./broadcast')
10
+ const context = require('./deployment/context')
11
+ const sources = require('./deployment/sources')
11
12
 
12
- const { SYSTEM, PREFIX } = require('./constants')
13
+ const { SYSTEM } = require('./constants')
14
+ const { Communication } = require('./communication')
13
15
 
14
- /**
15
- * @implements {toa.core.bindings.Factory}
16
- */
17
16
  class Factory {
18
17
  producer (locator, endpoints, component) {
19
- const comm = this.#getCommunication(locator)
18
+ const comm = this.#getContext(locator)
20
19
 
21
20
  return new Producer(comm, locator, endpoints, component)
22
21
  }
23
22
 
24
23
  consumer (locator, endpoint) {
25
- const comm = this.#getCommunication(locator)
24
+ const comm = this.#getContext(locator)
26
25
 
27
26
  return new Consumer(comm, locator, endpoint)
28
27
  }
29
28
 
30
- /**
31
- * @param {toa.core.Locator} locator
32
- * @param {string} label
33
- * @return {Emitter}
34
- */
35
29
  emitter (locator, label) {
36
- const comm = this.#getCommunication(locator)
30
+ const comm = this.#getContext(locator)
37
31
 
38
32
  return new Emitter(comm, locator, label)
39
33
  }
40
34
 
41
- /**
42
- * @param {toa.core.Locator} source
43
- * @param {string} label
44
- * @param {string} group
45
- * @param {toa.core.Receiver} receiver
46
- * @return {Receiver}
47
- */
48
- receiver (source, label, group, receiver) {
49
- const comm = this.#getCommunication(source)
35
+ receiver (locator, label, group, receiver) {
36
+ const comm = this.#getSource(locator, label)
50
37
 
51
38
  return new Receiver(comm, label, group, receiver)
52
39
  }
53
40
 
54
41
  broadcast (name, group) {
55
42
  const locator = new Locator(name, SYSTEM)
56
- const comm = this.#getCommunication(locator)
43
+ const comm = this.#getContext(locator)
57
44
 
58
45
  return new Broadcast(comm, locator, group)
59
46
  }
60
47
 
61
- /**
62
- *
63
- * @param {toa.core.Locator} source
64
- * @return {toa.amqp.Communication}
65
- */
66
- #getCommunication (source) {
67
- return connector(PREFIX, source)
48
+ #getContext (locator) {
49
+ const resolve = async () => context.resolveURIs(locator)
50
+
51
+ return new Communication(resolve)
52
+ }
53
+
54
+ #getSource (locator, label) {
55
+ const resolve = (locator.namespace === undefined)
56
+ ? async () => sources.resolveURIs(locator, label)
57
+ : async () => context.resolveURIs(locator)
58
+
59
+ return new Communication(resolve)
68
60
  }
69
61
  }
70
62
 
package/source/index.js CHANGED
@@ -1,13 +1,11 @@
1
1
  'use strict'
2
2
 
3
3
  const { deployment } = require('./deployment')
4
- const { annotation } = require('./annotation')
5
4
  const { Factory } = require('./factory')
6
5
 
7
6
  /** @type {toa.core.bindings.Properties} */
8
7
  const properties = { async: true }
9
8
 
10
9
  exports.properties = properties
11
- exports.annotation = annotation
12
10
  exports.deployment = deployment
13
11
  exports.Factory = Factory
@@ -17,12 +17,6 @@ class Producer extends Connector {
17
17
  /** @type {toa.core.Component} */
18
18
  #component
19
19
 
20
- /**
21
- * @param {toa.amqp.Communication} comm
22
- * @param {toa.core.Locator} locator
23
- * @param {string[]} endpoints
24
- * @param {toa.core.Component} component
25
- */
26
20
  constructor (comm, locator, endpoints, component) {
27
21
  super()
28
22
 
@@ -15,12 +15,6 @@ class Receiver extends Connector {
15
15
  /** @type {toa.core.Receiver} */
16
16
  #receiver
17
17
 
18
- /**
19
- * @param {toa.amqp.Communication} comm
20
- * @param {string} exchange
21
- * @param {string} group
22
- * @param {toa.core.Receiver} receiver
23
- */
24
18
  constructor (comm, exchange, group, receiver) {
25
19
  super()
26
20
 
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @implements {toa.core.bindings.Broadcast}
3
+ */
4
+ export class Broadcast extends Connector implements toa.core.bindings.Broadcast {
5
+ constructor(comm: any, locator: any, group: any);
6
+ transmit(label: any, payload: any): Promise<void>;
7
+ receive(label: any, callback: any): Promise<void>;
8
+ #private;
9
+ }
10
+ import { Connector } from "@toa.io/core";
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ const { Connector } = require('@toa.io/core');
3
+ const { name } = require('./queues');
4
+ /**
5
+ * @implements {toa.core.bindings.Broadcast}
6
+ */
7
+ class Broadcast extends Connector {
8
+ /** @type {toa.amqp.Communication} */
9
+ #comm;
10
+ /** @type {toa.core.Locator} */
11
+ #locator;
12
+ /** @type {string} */
13
+ #group;
14
+ constructor(comm, locator, group) {
15
+ super();
16
+ this.#comm = comm;
17
+ this.#locator = locator;
18
+ this.#group = group;
19
+ this.depends(comm);
20
+ }
21
+ async transmit(label, payload) {
22
+ const exchange = name(this.#locator, label);
23
+ await this.#comm.emit(exchange, payload);
24
+ }
25
+ async receive(label, callback) {
26
+ const exchange = name(this.#locator, label);
27
+ await this.#comm.consume(exchange, this.#group, callback);
28
+ }
29
+ }
30
+ exports.Broadcast = Broadcast;
31
+ //# sourceMappingURL=broadcast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../source/broadcast.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAE7C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAEpC;;GAEG;AACH,MAAM,SAAU,SAAQ,SAAS;IAC/B,qCAAqC;IACrC,KAAK,CAAA;IAEL,+BAA+B;IAC/B,QAAQ,CAAA;IAER,qBAAqB;IACrB,MAAM,CAAA;IAEN,YAAa,IAAI,EAAE,OAAO,EAAE,KAAK;QAC/B,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QAEnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAE,KAAK,EAAE,OAAO;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QAE3C,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,OAAO,CAAE,KAAK,EAAE,QAAQ;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QAE3C,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC3D,CAAC;CACF;AAED,OAAO,CAAC,SAAS,GAAG,SAAS,CAAA"}
@@ -0,0 +1,9 @@
1
+ export class Communication extends Connector {
2
+ constructor(resolve: any);
3
+ reply(queue: any, process: any): Promise<void>;
4
+ request(queue: any, request: any): Promise<any>;
5
+ emit(exchange: any, message: any, properties: any): Promise<void>;
6
+ consume(exchange: any, group: any, consumer: any): Promise<void>;
7
+ #private;
8
+ }
9
+ import { Connector } from "@toa.io/core";