@toa.io/core 1.0.0-alpha.292 → 1.0.0-alpha.293

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 (90) hide show
  1. package/package.json +10 -4
  2. package/CHANGELOG.md +0 -43
  3. package/source/assignment.ts +0 -27
  4. package/source/call.ts +0 -63
  5. package/source/cascade.ts +0 -32
  6. package/source/component.ts +0 -83
  7. package/source/composition.ts +0 -27
  8. package/source/connector.ts +0 -217
  9. package/source/context.ts +0 -68
  10. package/source/contract/contract.ts +0 -23
  11. package/source/contract/index.ts +0 -2
  12. package/source/contract/reply.ts +0 -56
  13. package/source/contract/request.ts +0 -140
  14. package/source/contract/schemas.ts +0 -39
  15. package/source/discovery.ts +0 -53
  16. package/source/effect.ts +0 -14
  17. package/source/emission.ts +0 -21
  18. package/source/entities/changeset.ts +0 -37
  19. package/source/entities/entity.ts +0 -137
  20. package/source/entities/factory.ts +0 -52
  21. package/source/entities/index.ts +0 -4
  22. package/source/entities/newid.ts +0 -9
  23. package/source/entities/set.ts +0 -27
  24. package/source/event.ts +0 -57
  25. package/source/exceptions.ts +0 -133
  26. package/source/exposition.ts +0 -33
  27. package/source/guard.ts +0 -16
  28. package/source/index.ts +0 -36
  29. package/source/locator.ts +0 -37
  30. package/source/observation.ts +0 -16
  31. package/source/operation.ts +0 -139
  32. package/source/outbox/index.ts +0 -1
  33. package/source/outbox/outbox.ts +0 -341
  34. package/source/query/criteria.ts +0 -90
  35. package/source/query/options.ts +0 -35
  36. package/source/query.ts +0 -67
  37. package/source/receiver.ts +0 -120
  38. package/source/reflection.ts +0 -20
  39. package/source/remote.ts +0 -20
  40. package/source/state.ts +0 -179
  41. package/source/transition.ts +0 -79
  42. package/source/transmission.ts +0 -38
  43. package/source/types/atomicity.ts +0 -63
  44. package/source/types/bindings.ts +0 -59
  45. package/source/types/bridges.ts +0 -54
  46. package/source/types/extensions.ts +0 -89
  47. package/source/types/index.ts +0 -14
  48. package/source/types/message.ts +0 -5
  49. package/source/types/operations.ts +0 -31
  50. package/source/types/outbox.ts +0 -35
  51. package/source/types/receiver.ts +0 -10
  52. package/source/types/request.ts +0 -54
  53. package/source/types/state.ts +0 -9
  54. package/source/types/storages.ts +0 -134
  55. package/source/unmanaged.ts +0 -8
  56. package/test/call.fixtures.js +0 -25
  57. package/test/call.test.js +0 -79
  58. package/test/component.fixtures.js +0 -18
  59. package/test/component.test.js +0 -57
  60. package/test/connector.fixtures.js +0 -56
  61. package/test/connector.test.js +0 -266
  62. package/test/context.fixtures.js +0 -14
  63. package/test/context.test.js +0 -40
  64. package/test/contract/conditions.test.js +0 -32
  65. package/test/contract/contract.fixtures.js +0 -28
  66. package/test/contract/request.test.js +0 -196
  67. package/test/discovery.test.js +0 -71
  68. package/test/emission.fixtures.js +0 -13
  69. package/test/emission.test.js +0 -60
  70. package/test/entities/entity.fixtures.js +0 -24
  71. package/test/entities/entity.test.js +0 -137
  72. package/test/entities/factory.fixtures.js +0 -31
  73. package/test/entities/factory.test.js +0 -99
  74. package/test/entities/set.fixtures.js +0 -9
  75. package/test/entities/set.test.js +0 -13
  76. package/test/event.fixtures.js +0 -24
  77. package/test/event.test.js +0 -162
  78. package/test/locator.test.js +0 -120
  79. package/test/outbox.test.js +0 -202
  80. package/test/query.fixtures.js +0 -96
  81. package/test/query.test.js +0 -183
  82. package/test/receiver.fixtures.js +0 -20
  83. package/test/receiver.test.js +0 -144
  84. package/test/reflection.test.js +0 -31
  85. package/test/state.fixtures.js +0 -49
  86. package/test/state.test.js +0 -162
  87. package/test/transmission.fixtures.js +0 -13
  88. package/test/transmission.test.js +0 -77
  89. package/tsconfig.json +0 -10
  90. package/tsconfig.tsbuildinfo +0 -1
@@ -1,60 +0,0 @@
1
- import { it, beforeEach, mock } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { isDeepStrictEqual } from 'node:util'
4
-
5
- import clone from 'clone-deep'
6
-
7
- import { Connector } from '../source/connector.js'
8
-
9
- // the fixtures are not connectors, so a dependency is recorded rather than linked
10
- const depends = mock.method(Connector.prototype, 'depends', () => undefined)
11
-
12
- const dependencies = (instance) =>
13
- depends.mock.calls
14
- .filter((call) => call.this === instance)
15
- .map((call) => call.arguments[0])
16
- import { Emission } from '../source/emission.js'
17
- import * as fixtures from './emission.fixtures.js'
18
-
19
- let emission, event
20
-
21
- beforeEach(async () => {
22
- resetCalls()
23
- depends.mock.resetCalls()
24
-
25
- emission = new Emission(fixtures.events)
26
- event = clone(fixtures.event)
27
-
28
- await emission.open()
29
- })
30
-
31
- it('should depend on events', () => {
32
- assert.ok(emission instanceof Connector)
33
- assert.ok(dependencies(emission).some((one) => isDeepStrictEqual(one, fixtures.events)))
34
- })
35
-
36
- it('should emit events', async () => {
37
- await emission.emit(event)
38
-
39
- for (const evt of fixtures.events) {
40
- assert.ok(
41
- evt.emit.mock.calls.some(
42
- (call) =>
43
- call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], event)
44
- )
45
- )
46
- }
47
- })
48
-
49
- function resetCalls(
50
- target = [assert, clone, depends, dependencies, fixtures],
51
- seen = new Set()
52
- ) {
53
- if (target === null || typeof target !== 'object' || seen.has(target)) return
54
-
55
- seen.add(target)
56
-
57
- for (const value of Object.values(target))
58
- if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
59
- else resetCalls(value, seen)
60
- }
@@ -1,24 +0,0 @@
1
- import { mock } from 'node:test'
2
-
3
- import { generate } from 'randomstring'
4
-
5
- // noinspection JSCheckFunctionSignatures
6
- export const schema = {
7
- fit: mock.fn((object) => (object.fail ? { [generate()]: generate() } : null)),
8
-
9
- defaults: mock.fn(() => ({ [generate()]: generate() }))
10
- }
11
-
12
- export const state = () => ({
13
- id: generate(),
14
- foo: generate(),
15
- CREATED: generate(),
16
- UPDATED: generate(),
17
- DELETED: generate(),
18
- VERSION: 0
19
- })
20
-
21
- export const failed = () => ({
22
- ...state(),
23
- fail: true
24
- })
@@ -1,137 +0,0 @@
1
- import { describe, it, beforeEach } from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import { Entity } from '../../source/entities/entity.js'
5
- import * as fixtures from './entity.fixtures.js'
6
-
7
- const BLANK = {}
8
-
9
- beforeEach(() => {
10
- resetCalls()
11
- })
12
-
13
- describe('argument', () => {
14
- it('should set state', () => {
15
- const state = fixtures.state()
16
- const entity = new Entity(fixtures.schema, BLANK, state)
17
-
18
- assert.deepStrictEqual(entity.get(), state)
19
- })
20
-
21
- it('should snapshot the record it may commit', () => {
22
- const record = fixtures.state()
23
- const entity = new Entity(fixtures.schema, BLANK, record)
24
-
25
- assert.notStrictEqual(entity.get(), record)
26
- assert.strictEqual(entity.event().origin, record)
27
- })
28
- })
29
-
30
- describe('blank', () => {
31
- it('should write what the component declares a record starts as', () => {
32
- const entity = new Entity(fixtures.schema, { foo: 'declared' })
33
- const state = entity.get()
34
-
35
- assert.strictEqual(state.foo, 'declared')
36
- assert.strictEqual(state.VERSION, 0)
37
- assert.strictEqual(state.DELETED, null)
38
- assert.strictEqual(typeof state.id, 'string')
39
- assert.strictEqual(entity.event().origin, null)
40
- })
41
-
42
- it('should not validate it', () => {
43
- const entity = new Entity(fixtures.schema, { fail: true })
44
-
45
- assert.strictEqual(entity.get().fail, true)
46
- assert.strictEqual(fixtures.schema.fit.mock.callCount(), 0)
47
- })
48
-
49
- it('should give every record its own copy', () => {
50
- const blank = { foo: { bar: 'nested' } }
51
- const one = new Entity(fixtures.schema, blank)
52
- const other = new Entity(fixtures.schema, blank)
53
-
54
- assert.notStrictEqual(one.get().foo, other.get().foo)
55
- assert.notStrictEqual(one.get().foo, blank.foo)
56
- })
57
- })
58
-
59
- describe('read-only', () => {
60
- it('should take the record as it came', () => {
61
- const record = fixtures.state()
62
- const entity = new Entity(fixtures.schema, BLANK, record, undefined, false)
63
-
64
- // no pre-image to diff against, hence no copy of it
65
- assert.strictEqual(entity.get(), record)
66
- })
67
-
68
- it('should still report a tombstone', () => {
69
- const record = { ...fixtures.state(), DELETED: Date.now() }
70
- const entity = new Entity(fixtures.schema, BLANK, record, undefined, false)
71
-
72
- assert.strictEqual(entity.deleted, true)
73
- })
74
-
75
- it('should refuse to be modified', () => {
76
- const entity = new Entity(fixtures.schema, BLANK, fixtures.state(), undefined, false)
77
-
78
- assert.throws(
79
- () => entity.set(entity.get()),
80
- (error) => /read-only/.test(error.message)
81
- )
82
- })
83
- })
84
-
85
- describe('tombstone', () => {
86
- it('should lift tombstone when transition leaves DELETED untouched', () => {
87
- const origin = fixtures.state()
88
- const entity = new Entity(fixtures.schema, BLANK, origin)
89
- const state = entity.get()
90
-
91
- state.foo = 'revived'
92
- entity.set(state)
93
-
94
- assert.strictEqual(entity.get().DELETED, null)
95
- assert.strictEqual(entity.deleted, false)
96
- assert.strictEqual(entity.event().state.DELETED, null)
97
- })
98
-
99
- it('should keep tombstone written by transition', () => {
100
- const origin = { ...fixtures.state(), DELETED: null }
101
- const entity = new Entity(fixtures.schema, BLANK, origin)
102
- const state = entity.get()
103
- const timestamp = Date.now()
104
-
105
- state.DELETED = timestamp
106
- entity.set(state)
107
-
108
- assert.strictEqual(entity.get().DELETED, timestamp)
109
- assert.strictEqual(entity.deleted, true)
110
- })
111
- })
112
-
113
- it('should provide event', () => {
114
- const origin = fixtures.state()
115
- const entity = new Entity(fixtures.schema, BLANK, origin)
116
- const state = entity.get()
117
-
118
- state.foo = 'new value'
119
- entity.set(state)
120
-
121
- const event = entity.event()
122
-
123
- assert.partialDeepStrictEqual(event, { state, origin })
124
- assert.strictEqual(event.state.foo, 'new value')
125
- assert.strictEqual(event.state.VERSION, 1)
126
- assert.notStrictEqual(event.origin.foo, 'new value')
127
- })
128
-
129
- function resetCalls(target = [assert, fixtures], seen = new Set()) {
130
- if (target === null || typeof target !== 'object' || seen.has(target)) return
131
-
132
- seen.add(target)
133
-
134
- for (const value of Object.values(target))
135
- if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
136
- else resetCalls(value, seen)
137
- }
@@ -1,31 +0,0 @@
1
- import { mock } from 'node:test'
2
-
3
- import randomstring from 'randomstring'
4
-
5
- const schemas = {
6
- entity: { [randomstring.generate()]: randomstring.generate() },
7
- changeset: { [randomstring.generate()]: randomstring.generate() }
8
- }
9
-
10
- const blank = { [randomstring.generate()]: randomstring.generate() }
11
- const storage = { id: mock.fn(() => randomstring.generate()) }
12
- const entity = { [randomstring.generate()]: randomstring.generate() }
13
- const set = Array.from(Array(5)).map((_, index) => ({
14
- id: index,
15
- [randomstring.generate()]: randomstring.generate()
16
- }))
17
-
18
- // node:test records a mock's calls but not the instances it constructed
19
- const entities = []
20
-
21
- const Entity = mock.fn(function () {
22
- this.id = randomstring.generate()
23
- entities.push(this)
24
- })
25
-
26
- const EntitySet = mock.fn(function () {})
27
-
28
- // named `mock` for its consumers, which is what node:test calls its own tracker
29
- const mocks = { Entity, EntitySet }
30
-
31
- export { schemas, blank, storage, entity, set, entities, mocks as mock }
@@ -1,99 +0,0 @@
1
- import { it, beforeEach, mock as mocking } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { isDeepStrictEqual } from 'node:util'
4
-
5
- import { generate } from 'randomstring'
6
-
7
- import * as fixtures from './factory.fixtures.js'
8
- const mock = fixtures.mock
9
-
10
- mocking.module('../../source/entities/entity.js', {
11
- namedExports: { Entity: mock.Entity }
12
- })
13
- mocking.module('../../source/entities/set.js', {
14
- namedExports: { EntitySet: mock.EntitySet }
15
- })
16
-
17
- const { Factory } = await import('../../source/entities/factory.js')
18
-
19
- let factory
20
-
21
- beforeEach(async () => {
22
- resetCalls()
23
- fixtures.entities.length = 0
24
-
25
- factory = new Factory(fixtures.schemas, fixtures.blank, () => fixtures.storage.id())
26
- })
27
-
28
- it('should create initial', () => {
29
- const id = generate()
30
- const initial = factory.init(id)
31
-
32
- assert.ok(initial instanceof mock.Entity)
33
- assert.ok(
34
- mock.Entity.mock.calls.some(
35
- (call) =>
36
- call.arguments.length === 4 &&
37
- isDeepStrictEqual(call.arguments[0], fixtures.schemas.entity) &&
38
- isDeepStrictEqual(call.arguments[1], fixtures.blank) &&
39
- isDeepStrictEqual(call.arguments[2], id) &&
40
- typeof call.arguments[3] === 'function'
41
- )
42
- )
43
- })
44
-
45
- it('should create instance', () => {
46
- const object = factory.object(fixtures.entity)
47
-
48
- assert.ok(object instanceof mock.Entity)
49
- assert.ok(
50
- mock.Entity.mock.calls.some(
51
- (call) =>
52
- call.arguments.length === 5 &&
53
- isDeepStrictEqual(call.arguments[0], fixtures.schemas.entity) &&
54
- isDeepStrictEqual(call.arguments[1], fixtures.blank) &&
55
- isDeepStrictEqual(call.arguments[2], fixtures.entity) &&
56
- typeof call.arguments[3] === 'function' &&
57
- isDeepStrictEqual(call.arguments[4], true)
58
- )
59
- )
60
- })
61
-
62
- it('should create set', () => {
63
- const objects = factory.objects(fixtures.set)
64
-
65
- assert.ok(objects instanceof mock.EntitySet)
66
-
67
- const instances = fixtures.set.map((entity, index) => {
68
- assert.ok(
69
- ((call) =>
70
- call.arguments.length === 5 &&
71
- isDeepStrictEqual(call.arguments[0], fixtures.schemas.entity) &&
72
- isDeepStrictEqual(call.arguments[1], fixtures.blank) &&
73
- isDeepStrictEqual(call.arguments[2], entity) &&
74
- typeof call.arguments[3] === 'function' &&
75
- isDeepStrictEqual(call.arguments[4], true))(
76
- mock.Entity.mock.calls[index + 1 - 1] ?? { arguments: [] }
77
- )
78
- )
79
-
80
- return fixtures.entities[index]
81
- })
82
-
83
- assert.ok(
84
- mock.EntitySet.mock.calls.some(
85
- (call) =>
86
- call.arguments.length === 1 && isDeepStrictEqual(call.arguments[0], instances)
87
- )
88
- )
89
- })
90
-
91
- function resetCalls(target = [assert, fixtures, mock], seen = new Set()) {
92
- if (target === null || typeof target !== 'object' || seen.has(target)) return
93
-
94
- seen.add(target)
95
-
96
- for (const value of Object.values(target))
97
- if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
98
- else resetCalls(value, seen)
99
- }
@@ -1,9 +0,0 @@
1
- import { mock } from 'node:test'
2
-
3
- import { generate } from 'randomstring'
4
-
5
- export const set = [
6
- { get: mock.fn(() => ({ [generate()]: generate() })) },
7
- { get: mock.fn(() => ({ [generate()]: generate() })) },
8
- { get: mock.fn(() => ({ [generate()]: generate() })) }
9
- ]
@@ -1,13 +0,0 @@
1
- import { it } from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import { EntitySet } from '../../source/entities/set.js'
5
- import * as fixtures from './set.fixtures.js'
6
-
7
- it('should provide state', () => {
8
- const set = new EntitySet(fixtures.set)
9
- const state = set.get()
10
- const expected = fixtures.set.map((entity) => entity.get.mock.calls[0].result)
11
-
12
- assert.deepStrictEqual(state, expected)
13
- })
@@ -1,24 +0,0 @@
1
- import { mock } from 'node:test'
2
-
3
- import { generate } from 'randomstring'
4
-
5
- export const definition = {
6
- conditioned: true,
7
- subjective: true
8
- }
9
-
10
- // noinspection JSCheckFunctionSignatures
11
- export const bridge = {
12
- condition: mock.fn(async (origin) => !origin.falsy),
13
- payload: mock.fn(async () => ({ [generate()]: generate() }))
14
- }
15
-
16
- export const binding = {
17
- emit: mock.fn()
18
- }
19
-
20
- export const event = {
21
- origin: { [generate()]: generate() },
22
- state: { [generate()]: generate() },
23
- changeset: { [generate()]: generate() }
24
- }
@@ -1,162 +0,0 @@
1
- import { describe, it, beforeEach, mock } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { isDeepStrictEqual } from 'node:util'
4
-
5
- import clone from 'clone-deep'
6
-
7
- import { Connector } from '../source/connector.js'
8
- import { Event } from '../source/event.js'
9
- import * as fixtures from './event.fixtures.js'
10
-
11
- let event, emit
12
-
13
- // the fixtures are not connectors, so the dependency is recorded rather than linked
14
- const depends = mock.method(Connector.prototype, 'depends', () => undefined)
15
-
16
- const dependencies = (instance) =>
17
- depends.mock.calls
18
- .filter((call) => call.this === instance)
19
- .map((call) => call.arguments[0])
20
-
21
- beforeEach(() => {
22
- resetCalls()
23
- depends.mock.resetCalls()
24
-
25
- event = new Event(fixtures.definition, fixtures.binding, fixtures.bridge)
26
- emit = () => event.emit(fixtures.event)
27
- })
28
-
29
- it('should depend on binding', () => {
30
- assert.ok(event instanceof Connector)
31
- assert.ok(dependencies(event).some((one) => isDeepStrictEqual(one, fixtures.binding)))
32
- })
33
-
34
- it('should depend on bridge if provided', () => {
35
- assert.ok(dependencies(event).some((one) => isDeepStrictEqual(one, fixtures.bridge)))
36
-
37
- const bridgeless = new Event(fixtures.definition, fixtures.binding)
38
-
39
- assert.ok(
40
- !dependencies(bridgeless).some((one) => isDeepStrictEqual(one, fixtures.bridge))
41
- )
42
- })
43
-
44
- describe('condition', () => {
45
- describe('conditioned', () => {
46
- it('should call condition', async () => {
47
- await emit()
48
-
49
- assert.ok(
50
- fixtures.bridge.condition.mock.calls.some(
51
- (call) =>
52
- call.arguments.length === 1 &&
53
- isDeepStrictEqual(call.arguments[0], fixtures.event)
54
- )
55
- )
56
- })
57
-
58
- it('should emit if condition returns true', async () => {
59
- await emit()
60
-
61
- const payload = await fixtures.bridge.payload.mock.calls[0].result
62
- assertEmitted(payload)
63
- })
64
-
65
- it('should not emit if condition returns false', async () => {
66
- const origin = clone(fixtures.event.origin)
67
-
68
- origin.falsy = true
69
-
70
- await event.emit(origin, fixtures.event.changeset, fixtures.event.state)
71
-
72
- assert.strictEqual(fixtures.binding.emit.mock.callCount(), 0)
73
- })
74
- })
75
-
76
- describe('unconditioned', () => {
77
- beforeEach(() => {
78
- const definition = clone(fixtures.definition)
79
-
80
- definition.conditioned = false
81
-
82
- event = new Event(definition, fixtures.binding, fixtures.bridge)
83
- })
84
-
85
- it('should not call condition', async () => {
86
- await event.emit(
87
- fixtures.event.origin,
88
- fixtures.event.changeset,
89
- fixtures.event.state
90
- )
91
-
92
- assert.ok(
93
- !fixtures.bridge.condition.mock.calls.some((call) => call.arguments.length === 0)
94
- )
95
-
96
- const payload = await fixtures.bridge.payload.mock.calls[0].result
97
- assertEmitted(payload)
98
- })
99
- })
100
- })
101
-
102
- describe('payload', () => {
103
- describe('subjective', () => {
104
- it('should emit payload', async () => {
105
- await emit()
106
-
107
- const payload = await fixtures.bridge.payload.mock.calls[0].result
108
- assertEmitted(payload)
109
- })
110
- })
111
-
112
- describe('objective', () => {
113
- beforeEach(() => {
114
- const definition = clone(fixtures.definition)
115
-
116
- definition.subjective = false
117
-
118
- event = new Event(definition, fixtures.binding, fixtures.bridge)
119
- emit = () => event.emit(fixtures.event)
120
- })
121
-
122
- it('should not call payload', async () => {
123
- await emit()
124
-
125
- assert.strictEqual(fixtures.bridge.payload.mock.callCount(), 0)
126
- })
127
-
128
- it('should return state as payload', async () => {
129
- await emit()
130
-
131
- const payload = fixtures.event.state
132
- assertEmitted(payload)
133
- })
134
- })
135
- })
136
-
137
- function resetCalls(
138
- target = [assert, clone, fixtures, depends, dependencies],
139
- seen = new Set()
140
- ) {
141
- if (target === null || typeof target !== 'object' || seen.has(target)) return
142
-
143
- seen.add(target)
144
-
145
- for (const value of Object.values(target))
146
- if (typeof value === 'function' && value.mock !== undefined) value.mock.resetCalls()
147
- else resetCalls(value, seen)
148
- }
149
-
150
- /** The message carries the payload and a telemetry token generated per emission. */
151
- function assertEmitted(payload) {
152
- const emitted = fixtures.binding.emit.mock.calls
153
- .map((call) => call.arguments[0])
154
- .filter((message) => isDeepStrictEqual(message.payload, payload))
155
-
156
- assert.notStrictEqual(emitted.length, 0)
157
-
158
- for (const message of emitted) {
159
- assert.strictEqual(typeof message.telemetry, 'string')
160
- assert.deepStrictEqual(Object.keys(message).sort(), ['payload', 'telemetry'])
161
- }
162
- }
@@ -1,120 +0,0 @@
1
- import { describe, it, beforeEach } from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import { generate } from 'randomstring'
5
- import { Locator } from '../source/locator.js'
6
-
7
- /** @type {string} */
8
- let name
9
-
10
- /** @type {string} */
11
- let namespace
12
-
13
- /** @type {import('@toa.io/core').Locator} */
14
- let locator
15
-
16
- beforeEach(() => {
17
- name = generate()
18
- namespace = generate()
19
-
20
- locator = new Locator(name, namespace)
21
- })
22
-
23
- it('should expose name and namespace', () => {
24
- assert.deepStrictEqual(locator.name, name)
25
- assert.deepStrictEqual(locator.namespace, namespace)
26
- })
27
-
28
- it('should expose id, label', () => {
29
- const id = locator.namespace + '.' + locator.name
30
- const label = locator.namespace.toLowerCase() + '-' + locator.name.toLowerCase()
31
-
32
- assert.deepStrictEqual(locator.id, id)
33
- assert.deepStrictEqual(locator.label, label)
34
- })
35
-
36
- it('should expose uppercase', () => {
37
- assert.deepStrictEqual(
38
- locator.uppercase,
39
- (locator.namespace + '_' + locator.name).toUpperCase()
40
- )
41
- })
42
-
43
- it('should throw if name is undefined', () => {
44
- assert.throws(() => new Locator(undefined, namespace), TypeError)
45
-
46
- // noinspection JSCheckFunctionSignatures
47
- assert.throws(() => new Locator(), TypeError)
48
- })
49
-
50
- it('should expose host', () => {
51
- assert.deepStrictEqual(locator.hostname(), (namespace + '-' + name).toLowerCase())
52
- })
53
-
54
- it('should expose host with given prefix', () => {
55
- const prefix = generate()
56
-
57
- assert.deepStrictEqual(
58
- locator.hostname(prefix),
59
- (prefix + '-' + namespace + '-' + name).toLowerCase()
60
- )
61
- })
62
-
63
- describe('global', () => {
64
- beforeEach(() => {
65
- locator = new Locator(name)
66
- })
67
-
68
- it('should not throw', () => undefined)
69
-
70
- it('should expose id', () => {
71
- assert.deepStrictEqual(locator.id, name)
72
- })
73
-
74
- it('should expose label', () => {
75
- assert.deepStrictEqual(locator.label, name.toLowerCase())
76
- })
77
-
78
- it('should expose uppercase', () => {
79
- assert.deepStrictEqual(locator.uppercase, name.toUpperCase())
80
- })
81
-
82
- it('should expose hostname', () => {
83
- const type = generate()
84
-
85
- assert.deepStrictEqual(locator.hostname(type), (type + '-' + name).toLowerCase())
86
- assert.deepStrictEqual(locator.hostname(), name.toLowerCase())
87
- })
88
- })
89
-
90
- describe('parse', () => {
91
- it('should be', async () => {
92
- assert.ok(Locator.parse instanceof Function)
93
- })
94
-
95
- const namespace = generate()
96
- const name = generate()
97
- const id = `${namespace}.${name}`
98
-
99
- it('should parse id', async () => {
100
- const locator = Locator.parse(id)
101
-
102
- assert.deepStrictEqual(locator.namespace, namespace)
103
- assert.deepStrictEqual(locator.name, name)
104
- })
105
-
106
- it('should parse endpoint', async () => {
107
- const endpoint = `${id}.${generate()}`
108
- const locator = Locator.parse(endpoint)
109
-
110
- assert.deepStrictEqual(locator.namespace, namespace)
111
- assert.deepStrictEqual(locator.name, name)
112
- })
113
-
114
- it('should parse token as global', async () => {
115
- const locator = Locator.parse(name)
116
-
117
- assert.strictEqual(locator.namespace, undefined)
118
- assert.deepStrictEqual(locator.name, name)
119
- })
120
- })