@toa.io/extensions.origins 1.0.0-alpha.6 → 1.0.0-alpha.62
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/package.json +8 -7
- package/readme.md +39 -3
- package/source/Factory.ts +13 -18
- package/source/protocols/amqp/aspect.js +7 -23
- package/source/protocols/http/.aspect/permissions.js +3 -8
- package/source/protocols/http/aspect.js +5 -12
- package/source/protocols/index.ts +5 -6
- package/source/protocols/pubsub/Aspect.ts +87 -0
- package/source/protocols/pubsub/Origin.ts +10 -0
- package/source/protocols/pubsub/Topic.ts +23 -0
- package/source/protocols/pubsub/index.ts +8 -0
- package/transpiled/Factory.d.ts +2 -3
- package/transpiled/Factory.js +12 -15
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/protocols/amqp/aspect.d.ts +2 -2
- package/transpiled/protocols/amqp/aspect.js +7 -21
- package/transpiled/protocols/amqp/aspect.js.map +1 -1
- package/transpiled/protocols/http/.aspect/permissions.d.ts +1 -2
- package/transpiled/protocols/http/.aspect/permissions.js +1 -5
- package/transpiled/protocols/http/.aspect/permissions.js.map +1 -1
- package/transpiled/protocols/http/aspect.d.ts +2 -3
- package/transpiled/protocols/http/aspect.js +5 -10
- package/transpiled/protocols/http/aspect.js.map +1 -1
- package/transpiled/protocols/index.d.ts +3 -3
- package/transpiled/protocols/index.js +3 -2
- package/transpiled/protocols/index.js.map +1 -1
- package/transpiled/protocols/pubsub/Aspect.d.ts +13 -0
- package/transpiled/protocols/pubsub/Aspect.js +69 -0
- package/transpiled/protocols/pubsub/Aspect.js.map +1 -0
- package/transpiled/protocols/pubsub/Origin.d.ts +8 -0
- package/transpiled/protocols/pubsub/Origin.js +3 -0
- package/transpiled/protocols/pubsub/Origin.js.map +1 -0
- package/transpiled/protocols/pubsub/Topic.d.ts +8 -0
- package/transpiled/protocols/pubsub/Topic.js +19 -0
- package/transpiled/protocols/pubsub/Topic.js.map +1 -0
- package/transpiled/protocols/pubsub/index.d.ts +7 -0
- package/transpiled/protocols/pubsub/index.js +8 -0
- package/transpiled/protocols/pubsub/index.js.map +1 -0
- package/transpiled/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/extensions.origins",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.62",
|
|
4
4
|
"description": "Toa Origins",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"main": "transpiled/index.js",
|
|
18
18
|
"types": "transpiled/index.d.ts",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@toa.io/
|
|
22
|
-
"@toa.io/
|
|
23
|
-
"@toa.io/
|
|
24
|
-
"
|
|
20
|
+
"@google-cloud/pubsub": "4.3.3",
|
|
21
|
+
"@toa.io/core": "1.0.0-alpha.59",
|
|
22
|
+
"@toa.io/generic": "1.0.0-alpha.59",
|
|
23
|
+
"@toa.io/pointer": "1.0.0-alpha.61",
|
|
24
|
+
"@toa.io/schemas": "1.0.0-alpha.61",
|
|
25
|
+
"comq": "0.11.3",
|
|
25
26
|
"msgpackr": "1.10.1"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
@@ -31,5 +32,5 @@
|
|
|
31
32
|
"preset": "ts-jest",
|
|
32
33
|
"testEnvironment": "node"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0ddfa7893b630214d50334264a2220b3bb6b455e"
|
|
35
36
|
}
|
package/readme.md
CHANGED
|
@@ -62,11 +62,47 @@ async function transition (input, object, context) {
|
|
|
62
62
|
Uses [ComQ](https://github.com/toa-io/comq), thus, provides interface of `comq.IO` restricted
|
|
63
63
|
to `emit` and `request` methods.
|
|
64
64
|
|
|
65
|
+
## Google Pub/Sub Aspect
|
|
66
|
+
|
|
67
|
+
[Google Pub/Sub](https://cloud.google.com/pubsub) client.
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
async function transition (input, object, context) {
|
|
71
|
+
await context.pubsub.publish('topic', { message: 'Hello, World!' })
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Messages are batched with a maximum delay of 1 second.
|
|
76
|
+
|
|
77
|
+
### Pub/Sub credentials
|
|
78
|
+
|
|
79
|
+
Google Pub/Sub [URL](#context-annotation) must follow the following format:
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
my-topic: pubsub://{emulator_host?}/projects/{project}/topics/{topic}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
await context.pubsub.topic.publish({ message: 'Hello, World!' })
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
> Messages are published using JSON serialization.
|
|
90
|
+
|
|
91
|
+
For each `project`,
|
|
92
|
+
a secret `TOA_ORIGINS_PUBSUB__{project}`
|
|
93
|
+
with [ADC](https://cloud.google.com/docs/authentication/application-default-credentials) must be
|
|
94
|
+
deployed.
|
|
95
|
+
|
|
96
|
+
```shell
|
|
97
|
+
$ kubectl create secret generic toa-origins-pubsub
|
|
98
|
+
$ kubectl patch secret toa-origins-pubsub -p '{"data": {"project-name": "'"$(cat adc.json | base64)"'"}}'
|
|
99
|
+
```
|
|
100
|
+
|
|
65
101
|
## Manifest
|
|
66
102
|
|
|
67
103
|
`origins` manifest is a [Pointer](/libraries/pointer) with origin names as keys.
|
|
68
104
|
Its values can be overridden by the context [annotation](#context-annotation).
|
|
69
|
-
If the value is `null`, then it _must_ be
|
|
105
|
+
If the value is `null`, then it _must_ be overridden.
|
|
70
106
|
|
|
71
107
|
### `null` manifest
|
|
72
108
|
|
|
@@ -90,7 +126,7 @@ origins:
|
|
|
90
126
|
queues: amqps://amqp.azure.com
|
|
91
127
|
```
|
|
92
128
|
|
|
93
|
-
### HTTP URL
|
|
129
|
+
### HTTP URL permissions
|
|
94
130
|
|
|
95
131
|
The rules for arbitrary HTTP requests are stored in the `http` property of the corresponding
|
|
96
132
|
component as an object.
|
|
@@ -106,7 +142,7 @@ In cases where a URL matches multiple rules, denial takes priority.
|
|
|
106
142
|
# context.toa.yaml
|
|
107
143
|
origins:
|
|
108
144
|
dummies.dummy:
|
|
109
|
-
http:
|
|
145
|
+
.http:
|
|
110
146
|
/^https?:\/\/api.domain.com/: true
|
|
111
147
|
/^http:\/\/sandbox.domain.com/@staging: true # `staging` environment
|
|
112
148
|
/.*hackers.*/: false # deny
|
package/source/Factory.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { decode } from 'msgpackr'
|
|
2
2
|
import { resolve, type URIMap } from '@toa.io/pointer'
|
|
3
|
-
import { memo } from '@toa.io/generic'
|
|
4
3
|
import { type Protocol, protocols } from './protocols'
|
|
5
4
|
import { ENV_PREFIX, ID_PREFIX, PROPERTIES_SUFFIX } from './extension'
|
|
6
5
|
import type { Properties } from './annotation'
|
|
@@ -14,31 +13,29 @@ export class Factory implements extensions.Factory {
|
|
|
14
13
|
|
|
15
14
|
private createAspect (locator: Locator, manifest: Manifest, protocol: Protocol):
|
|
16
15
|
extensions.Aspect {
|
|
17
|
-
const
|
|
16
|
+
const declaration = this.resolve(locator, manifest, protocol)
|
|
18
17
|
|
|
19
|
-
return protocol.create(
|
|
18
|
+
return protocol.create(declaration)
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const allProperties = this.getProperties(locator)
|
|
21
|
+
private resolve (locator: Locator, manifest: Manifest, protocol: Protocol): Declaration {
|
|
22
|
+
const uris = this.getURIs(locator, manifest)
|
|
23
|
+
const allProperties = this.getProperties(locator)
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const origins = this.filterOrigins(uris, protocol.protocols)
|
|
26
|
+
const properties = allProperties['.' + protocol.id as keyof Properties] ?? {}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
})
|
|
28
|
+
return { origins, properties }
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
private
|
|
31
|
+
private getURIs (locator: Locator, manifest: Manifest): URIMap {
|
|
35
32
|
const map: URIMap = {}
|
|
36
33
|
|
|
37
34
|
if (manifest === null) return map
|
|
38
35
|
|
|
39
36
|
for (const [name, value] of Object.entries(manifest))
|
|
40
37
|
try {
|
|
41
|
-
map[name] =
|
|
38
|
+
map[name] = this.readOrigin(locator, name)
|
|
42
39
|
} catch {
|
|
43
40
|
// eslint-disable-next-line max-depth
|
|
44
41
|
if (value === null) throw new Error(`Origin value ${name} is not defined`)
|
|
@@ -62,10 +59,10 @@ export class Factory implements extensions.Factory {
|
|
|
62
59
|
return filtered
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
private
|
|
62
|
+
private readOrigin (locator: Locator, name: string): string[] {
|
|
66
63
|
const id = ID_PREFIX + locator.label
|
|
67
64
|
|
|
68
|
-
return
|
|
65
|
+
return resolve(id, name)
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
private getProperties (locator: Locator): Properties {
|
|
@@ -80,9 +77,7 @@ export class Factory implements extensions.Factory {
|
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
|
|
83
|
-
export interface
|
|
80
|
+
export interface Declaration {
|
|
84
81
|
origins: URIMap
|
|
85
82
|
properties: Record<string, boolean>
|
|
86
83
|
}
|
|
87
|
-
|
|
88
|
-
export type Resolver = () => Promise<Configuration>
|
|
@@ -7,20 +7,17 @@ const protocol = require('./index')
|
|
|
7
7
|
class Aspect extends Connector {
|
|
8
8
|
name = protocol.id
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
/** @type {Record<string, Partial<comq.IO>>} */
|
|
10
|
+
#declarations
|
|
13
11
|
#origins = {}
|
|
14
12
|
|
|
15
|
-
constructor (
|
|
13
|
+
constructor (origins) {
|
|
16
14
|
super()
|
|
17
15
|
|
|
18
|
-
this.#
|
|
16
|
+
this.#declarations = origins
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
async open () {
|
|
22
|
-
const
|
|
23
|
-
const promises = Object.entries(cfg.origins).map(this.#open)
|
|
20
|
+
const promises = Object.entries(this.#declarations).map(this.#open)
|
|
24
21
|
|
|
25
22
|
await Promise.all(promises)
|
|
26
23
|
}
|
|
@@ -42,7 +39,7 @@ class Aspect extends Connector {
|
|
|
42
39
|
#open = async ([origin, references]) => {
|
|
43
40
|
const io = await assert(...references)
|
|
44
41
|
|
|
45
|
-
this.#origins[origin] =
|
|
42
|
+
this.#origins[origin] = io
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
#close = async (io) => {
|
|
@@ -50,21 +47,8 @@ class Aspect extends Connector {
|
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @return {Partial<comq.IO>}
|
|
56
|
-
*/
|
|
57
|
-
function restrict (io) {
|
|
58
|
-
// noinspection JSUnresolvedReference
|
|
59
|
-
return {
|
|
60
|
-
request: (...args) => io.request(...args),
|
|
61
|
-
emit: (...args) => io.emit(...args),
|
|
62
|
-
close: () => io.close()
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function create (resolve) {
|
|
67
|
-
return new Aspect(resolve)
|
|
50
|
+
function create (declaration) {
|
|
51
|
+
return new Aspect(declaration.origins)
|
|
68
52
|
}
|
|
69
53
|
|
|
70
54
|
exports.create = create
|
|
@@ -12,16 +12,11 @@ class Permissions extends Connector {
|
|
|
12
12
|
|
|
13
13
|
#resolve
|
|
14
14
|
|
|
15
|
-
constructor (
|
|
15
|
+
constructor (properties) {
|
|
16
16
|
super()
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
async open () {
|
|
22
|
-
const { properties } = await this.#resolve()
|
|
23
|
-
|
|
24
|
-
if (properties !== undefined) this.#parse(properties)
|
|
18
|
+
if (properties !== undefined)
|
|
19
|
+
this.#parse(properties)
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
test (url) {
|
|
@@ -11,25 +11,18 @@ class Aspect extends Connector {
|
|
|
11
11
|
/** @readonly */
|
|
12
12
|
name = protocol.id
|
|
13
13
|
|
|
14
|
-
#resolve
|
|
15
14
|
#origins
|
|
16
15
|
#permissions
|
|
17
16
|
|
|
18
|
-
constructor (
|
|
17
|
+
constructor (origins, permissions) {
|
|
19
18
|
super()
|
|
20
19
|
|
|
21
|
-
this.#
|
|
20
|
+
this.#origins = origins
|
|
22
21
|
this.#permissions = permissions
|
|
23
22
|
|
|
24
23
|
this.depends(permissions)
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
async open () {
|
|
28
|
-
const { origins } = await this.#resolve()
|
|
29
|
-
|
|
30
|
-
this.#origins = origins
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
async invoke (name, path, request, options) {
|
|
34
27
|
let origin = this.#origins[name]
|
|
35
28
|
|
|
@@ -98,10 +91,10 @@ function isAbsoluteURL (path) {
|
|
|
98
91
|
|
|
99
92
|
const PLACEHOLDER = /\*/g
|
|
100
93
|
|
|
101
|
-
function create (
|
|
102
|
-
const permissions = new Permissions(
|
|
94
|
+
function create (declaration) {
|
|
95
|
+
const permissions = new Permissions(declaration.properties)
|
|
103
96
|
|
|
104
|
-
return new Aspect(
|
|
97
|
+
return new Aspect(declaration.origins, permissions)
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
exports.create = create
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { type Resolver } from '../Factory'
|
|
4
1
|
import amqp from './amqp'
|
|
5
2
|
import http from './http'
|
|
3
|
+
import pubsub from './pubsub'
|
|
4
|
+
import type { Declaration } from '../Factory'
|
|
6
5
|
import type { extensions } from '@toa.io/core'
|
|
7
6
|
|
|
8
|
-
export const protocols: Protocol[] = [http, amqp]
|
|
7
|
+
export const protocols: Protocol[] = [http, amqp, pubsub]
|
|
9
8
|
|
|
10
9
|
export interface Protocol {
|
|
11
10
|
id: ProtocolID
|
|
12
11
|
protocols: string[]
|
|
13
|
-
create: (
|
|
12
|
+
create: (declaration: Declaration) => extensions.Aspect
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export type ProtocolID = 'http' | 'amqp'
|
|
15
|
+
export type ProtocolID = 'http' | 'amqp' | 'pubsub'
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { Connector } from '@toa.io/core'
|
|
3
|
+
import { PubSub } from '@google-cloud/pubsub'
|
|
4
|
+
import { Topic } from './Topic'
|
|
5
|
+
import type { Origin } from './Origin'
|
|
6
|
+
import type { extensions } from '@toa.io/core'
|
|
7
|
+
import type { Declaration } from '../../Factory'
|
|
8
|
+
|
|
9
|
+
class Aspect extends Connector implements extensions.Aspect {
|
|
10
|
+
public readonly name = 'pubsub'
|
|
11
|
+
|
|
12
|
+
private readonly topics: Record<string, Topic>
|
|
13
|
+
|
|
14
|
+
public constructor (topics: Record<string, Topic>) {
|
|
15
|
+
super()
|
|
16
|
+
|
|
17
|
+
this.topics = topics
|
|
18
|
+
|
|
19
|
+
const values = Object.values(topics)
|
|
20
|
+
|
|
21
|
+
if (values.length > 0)
|
|
22
|
+
this.depends(values)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async invoke (method: Method, topic: string, message: unknown): Promise<string> {
|
|
26
|
+
assert(topic in this.topics, `Pub/Sub topic ${topic} is not defined`)
|
|
27
|
+
|
|
28
|
+
return await this.topics[topic][method](message)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Method = 'publish'
|
|
33
|
+
|
|
34
|
+
export function create (declaration: Declaration): Aspect {
|
|
35
|
+
const origins = toOrigins(declaration)
|
|
36
|
+
const topics = toTopics(origins)
|
|
37
|
+
|
|
38
|
+
return new Aspect(topics)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toOrigins (declaration: Declaration): Record<string, Origin> {
|
|
42
|
+
const origins: Record<string, Origin> = {}
|
|
43
|
+
|
|
44
|
+
for (const [name, references] of Object.entries(declaration.origins))
|
|
45
|
+
origins[name] = toOrigin(references[0])
|
|
46
|
+
|
|
47
|
+
return origins
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function toOrigin (reference: string): Origin {
|
|
51
|
+
const url = new URL(reference)
|
|
52
|
+
const [, , project, , topic] = url.pathname.split('/')
|
|
53
|
+
const suffix = project.replaceAll('-', '_').toUpperCase()
|
|
54
|
+
const json = process.env['TOA_ORIGINS_PUBSUB__' + suffix]
|
|
55
|
+
const credentials = json !== undefined ? JSON.parse(json) : undefined
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
endpoint: url.host,
|
|
59
|
+
credentials,
|
|
60
|
+
project,
|
|
61
|
+
topic
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toTopics (origins: Record<string, Origin>): Record<string, Topic> {
|
|
66
|
+
const pubsub: Record<string, PubSub> = {}
|
|
67
|
+
const topics: Record<string, Topic> = {}
|
|
68
|
+
|
|
69
|
+
for (const [name, origin] of Object.entries(origins)) {
|
|
70
|
+
if (!(origin.project in pubsub))
|
|
71
|
+
pubsub[origin.project] = createPubSub(origin)
|
|
72
|
+
|
|
73
|
+
topics[name] = new Topic(pubsub[origin.project], origin)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return topics
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function createPubSub (origin: Origin): PubSub {
|
|
80
|
+
console.info(`Using Pub/Sub project ${origin.project} as ${origin.credentials?.client_id ?? 'unauthenticated'} client`)
|
|
81
|
+
|
|
82
|
+
return new PubSub({
|
|
83
|
+
projectId: origin.project,
|
|
84
|
+
apiEndpoint: origin.endpoint,
|
|
85
|
+
credentials: origin.credentials
|
|
86
|
+
})
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClientConfig } from '@google-cloud/pubsub'
|
|
2
|
+
|
|
3
|
+
export interface Origin {
|
|
4
|
+
readonly project: string
|
|
5
|
+
readonly topic: string
|
|
6
|
+
readonly endpoint?: string
|
|
7
|
+
readonly credentials?: Credentials
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type Credentials = ClientConfig['credentials']
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Connector } from '@toa.io/core'
|
|
2
|
+
import type { Origin } from './Origin'
|
|
3
|
+
import type { PublishOptions, PubSub } from '@google-cloud/pubsub'
|
|
4
|
+
|
|
5
|
+
export class Topic extends Connector {
|
|
6
|
+
private readonly publisher
|
|
7
|
+
|
|
8
|
+
public constructor (pubsub: PubSub, origin: Origin) {
|
|
9
|
+
super()
|
|
10
|
+
|
|
11
|
+
const name = `projects/${origin.project}/topics/${origin.topic}`
|
|
12
|
+
|
|
13
|
+
this.publisher = pubsub.topic(name, OPTIONS)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public async publish (payload: unknown): Promise<string> {
|
|
17
|
+
const data = Buffer.from(JSON.stringify(payload))
|
|
18
|
+
|
|
19
|
+
return this.publisher.publishMessage({ data })
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const OPTIONS: PublishOptions = { batching: { maxMessages: 100, maxMilliseconds: 1000 } }
|
package/transpiled/Factory.d.ts
CHANGED
|
@@ -4,14 +4,13 @@ import type { Manifest } from './manifest';
|
|
|
4
4
|
export declare class Factory implements extensions.Factory {
|
|
5
5
|
aspect(locator: Locator, manifest: Manifest): extensions.Aspect[];
|
|
6
6
|
private createAspect;
|
|
7
|
-
private
|
|
7
|
+
private resolve;
|
|
8
8
|
private getURIs;
|
|
9
9
|
private filterOrigins;
|
|
10
10
|
private readOrigin;
|
|
11
11
|
private getProperties;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface Declaration {
|
|
14
14
|
origins: URIMap;
|
|
15
15
|
properties: Record<string, boolean>;
|
|
16
16
|
}
|
|
17
|
-
export type Resolver = () => Promise<Configuration>;
|
package/transpiled/Factory.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Factory = void 0;
|
|
4
4
|
const msgpackr_1 = require("msgpackr");
|
|
5
5
|
const pointer_1 = require("@toa.io/pointer");
|
|
6
|
-
const generic_1 = require("@toa.io/generic");
|
|
7
6
|
const protocols_1 = require("./protocols");
|
|
8
7
|
const extension_1 = require("./extension");
|
|
9
8
|
class Factory {
|
|
@@ -11,25 +10,23 @@ class Factory {
|
|
|
11
10
|
return protocols_1.protocols.map((protocol) => this.createAspect(locator, manifest, protocol));
|
|
12
11
|
}
|
|
13
12
|
createAspect(locator, manifest, protocol) {
|
|
14
|
-
const
|
|
15
|
-
return protocol.create(
|
|
13
|
+
const declaration = this.resolve(locator, manifest, protocol);
|
|
14
|
+
return protocol.create(declaration);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return { origins, properties };
|
|
24
|
-
});
|
|
16
|
+
resolve(locator, manifest, protocol) {
|
|
17
|
+
const uris = this.getURIs(locator, manifest);
|
|
18
|
+
const allProperties = this.getProperties(locator);
|
|
19
|
+
const origins = this.filterOrigins(uris, protocol.protocols);
|
|
20
|
+
const properties = allProperties['.' + protocol.id] ?? {};
|
|
21
|
+
return { origins, properties };
|
|
25
22
|
}
|
|
26
|
-
|
|
23
|
+
getURIs(locator, manifest) {
|
|
27
24
|
const map = {};
|
|
28
25
|
if (manifest === null)
|
|
29
26
|
return map;
|
|
30
27
|
for (const [name, value] of Object.entries(manifest))
|
|
31
28
|
try {
|
|
32
|
-
map[name] =
|
|
29
|
+
map[name] = this.readOrigin(locator, name);
|
|
33
30
|
}
|
|
34
31
|
catch {
|
|
35
32
|
// eslint-disable-next-line max-depth
|
|
@@ -48,9 +45,9 @@ class Factory {
|
|
|
48
45
|
}
|
|
49
46
|
return filtered;
|
|
50
47
|
}
|
|
51
|
-
|
|
48
|
+
readOrigin(locator, name) {
|
|
52
49
|
const id = extension_1.ID_PREFIX + locator.label;
|
|
53
|
-
return
|
|
50
|
+
return (0, pointer_1.resolve)(id, name);
|
|
54
51
|
}
|
|
55
52
|
getProperties(locator) {
|
|
56
53
|
const variable = extension_1.ENV_PREFIX + locator.uppercase + extension_1.PROPERTIES_SUFFIX;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;AAAA,uCAAiC;AACjC,6CAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;AAAA,uCAAiC;AACjC,6CAAsD;AACtD,2CAAsD;AACtD,2CAAsE;AAKtE,MAAa,OAAO;IACX,MAAM,CAAE,OAAgB,EAAE,QAAkB;QACjD,OAAO,qBAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;IACpF,CAAC;IAEO,YAAY,CAAE,OAAgB,EAAE,QAAkB,EAAE,QAAkB;QAE5E,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAE7D,OAAO,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IACrC,CAAC;IAEO,OAAO,CAAE,OAAgB,EAAE,QAAkB,EAAE,QAAkB;QACvE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,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,OAAO,QAAQ,CAAA;IACjB,CAAC;IAEO,UAAU,CAAE,OAAgB,EAAE,IAAY;QAChD,MAAM,EAAE,GAAG,qBAAS,GAAG,OAAO,CAAC,KAAK,CAAA;QAEpC,OAAO,IAAA,iBAAO,EAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IAC1B,CAAC;IAEO,aAAa,CAAE,OAAgB;QACrC,MAAM,QAAQ,GAAG,sBAAU,GAAG,OAAO,CAAC,SAAS,GAAG,6BAAiB,CAAA;QACnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAEnC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,EAAE,CAAA;QAElC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAE3C,OAAO,IAAA,iBAAM,EAAC,MAAM,CAAC,CAAA;IACvB,CAAC;CACF;AArED,0BAqEC"}
|
|
@@ -4,16 +4,14 @@ const { Connector } = require('@toa.io/core');
|
|
|
4
4
|
const protocol = require('./index');
|
|
5
5
|
class Aspect extends Connector {
|
|
6
6
|
name = protocol.id;
|
|
7
|
-
#
|
|
8
|
-
/** @type {Record<string, Partial<comq.IO>>} */
|
|
7
|
+
#declarations;
|
|
9
8
|
#origins = {};
|
|
10
|
-
constructor(
|
|
9
|
+
constructor(origins) {
|
|
11
10
|
super();
|
|
12
|
-
this.#
|
|
11
|
+
this.#declarations = origins;
|
|
13
12
|
}
|
|
14
13
|
async open() {
|
|
15
|
-
const
|
|
16
|
-
const promises = Object.entries(cfg.origins).map(this.#open);
|
|
14
|
+
const promises = Object.entries(this.#declarations).map(this.#open);
|
|
17
15
|
await Promise.all(promises);
|
|
18
16
|
}
|
|
19
17
|
async close() {
|
|
@@ -28,26 +26,14 @@ class Aspect extends Connector {
|
|
|
28
26
|
}
|
|
29
27
|
#open = async ([origin, references]) => {
|
|
30
28
|
const io = await assert(...references);
|
|
31
|
-
this.#origins[origin] =
|
|
29
|
+
this.#origins[origin] = io;
|
|
32
30
|
};
|
|
33
31
|
#close = async (io) => {
|
|
34
32
|
await io.close();
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* @return {Partial<comq.IO>}
|
|
40
|
-
*/
|
|
41
|
-
function restrict(io) {
|
|
42
|
-
// noinspection JSUnresolvedReference
|
|
43
|
-
return {
|
|
44
|
-
request: (...args) => io.request(...args),
|
|
45
|
-
emit: (...args) => io.emit(...args),
|
|
46
|
-
close: () => io.close()
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function create(resolve) {
|
|
50
|
-
return new Aspect(resolve);
|
|
35
|
+
function create(declaration) {
|
|
36
|
+
return new Aspect(declaration.origins);
|
|
51
37
|
}
|
|
52
38
|
exports.create = create;
|
|
53
39
|
//# sourceMappingURL=aspect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aspect.js","sourceRoot":"","sources":["../../../source/protocols/amqp/aspect.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAClC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAEnC,MAAM,MAAO,SAAQ,SAAS;IAC5B,IAAI,GAAG,QAAQ,CAAC,EAAE,CAAA;IAElB,
|
|
1
|
+
{"version":3,"file":"aspect.js","sourceRoot":"","sources":["../../../source/protocols/amqp/aspect.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAClC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,C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AA;IAED,MAAM,GAAG,KAAK,EAAE,EAAE,EAAE,EAAE;QACpB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC,CAAA;CACF;AAED,SAAS,MAAM,CAAE,WAAW;IAC1B,OAAO,IAAI,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACxC,CAAC;AAED,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA"}
|
|
@@ -7,12 +7,8 @@ class Permissions extends Connector {
|
|
|
7
7
|
/** @type {RegExp[]} */
|
|
8
8
|
#denials = [];
|
|
9
9
|
#resolve;
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(properties) {
|
|
11
11
|
super();
|
|
12
|
-
this.#resolve = resolve;
|
|
13
|
-
}
|
|
14
|
-
async open() {
|
|
15
|
-
const { properties } = await this.#resolve();
|
|
16
12
|
if (properties !== undefined)
|
|
17
13
|
this.#parse(properties);
|
|
18
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../../source/protocols/http/.aspect/permissions.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAC3C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAE7C,MAAM,WAAY,SAAQ,SAAS;IACjC,uBAAuB;IACvB,WAAW,GAAG,EAAE,CAAA;IAEhB,uBAAuB;IACvB,QAAQ,GAAG,EAAE,CAAA;IAEb,QAAQ,CAAA;IAER,YAAa,
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../../source/protocols/http/.aspect/permissions.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAC3C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,cAAc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AA+B,CAAC,CAAA;YAE3E,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;YAChD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAA;YAEpC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAE,KAAK,EAAE,IAAI;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAA;QAErD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;CACF;AAED,MAAM,UAAU,GAAG,yBAAyB,CAAA;AAE5C,OAAO,CAAC,WAAW,GAAG,WAAW,CAAA"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export function create(
|
|
1
|
+
export function create(declaration: any): Aspect;
|
|
2
2
|
declare class Aspect extends Connector {
|
|
3
|
-
constructor(
|
|
3
|
+
constructor(origins: any, permissions: any);
|
|
4
4
|
/** @readonly */
|
|
5
5
|
readonly name: "http";
|
|
6
|
-
open(): Promise<void>;
|
|
7
6
|
invoke(name: any, path: any, request: any, options: any): Promise<any>;
|
|
8
7
|
#private;
|
|
9
8
|
}
|