@toa.io/core 1.0.0-alpha.292 → 1.0.0-alpha.299
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 +10 -4
- package/transpiled/call.js +12 -0
- package/transpiled/call.js.map +1 -1
- package/transpiled/component.js +31 -4
- package/transpiled/component.js.map +1 -1
- package/transpiled/context.d.ts +5 -0
- package/transpiled/context.js +6 -0
- package/transpiled/context.js.map +1 -1
- package/transpiled/emission.d.ts +4 -2
- package/transpiled/emission.js +4 -2
- package/transpiled/emission.js.map +1 -1
- package/transpiled/entities/entity.js +34 -6
- package/transpiled/entities/entity.js.map +1 -1
- package/transpiled/entities/factory.d.ts +5 -0
- package/transpiled/entities/factory.js +6 -2
- package/transpiled/entities/factory.js.map +1 -1
- package/transpiled/event.d.ts +2 -2
- package/transpiled/event.js +6 -1
- package/transpiled/event.js.map +1 -1
- package/transpiled/exceptions.d.ts +19 -0
- package/transpiled/exceptions.js +74 -2
- package/transpiled/exceptions.js.map +1 -1
- package/transpiled/index.d.ts +2 -1
- package/transpiled/index.js +2 -1
- package/transpiled/index.js.map +1 -1
- package/transpiled/{outbox/outbox.d.ts → outbox.d.ts} +6 -7
- package/transpiled/outbox.js +424 -0
- package/transpiled/outbox.js.map +1 -0
- package/transpiled/query/options.js +1 -1
- package/transpiled/query/options.js.map +1 -1
- package/transpiled/receiver.js +14 -1
- package/transpiled/receiver.js.map +1 -1
- package/transpiled/remote.js +2 -3
- package/transpiled/remote.js.map +1 -1
- package/transpiled/state.d.ts +1 -1
- package/transpiled/trail.d.ts +49 -0
- package/transpiled/trail.js +98 -0
- package/transpiled/trail.js.map +1 -0
- package/transpiled/types/bindings.d.ts +22 -0
- package/transpiled/types/extensions.d.ts +13 -2
- package/transpiled/types/message.d.ts +5 -0
- package/transpiled/types/outbox.d.ts +29 -3
- package/transpiled/types/request.d.ts +5 -0
- package/transpiled/types/storages.d.ts +20 -0
- package/CHANGELOG.md +0 -43
- package/source/assignment.ts +0 -27
- package/source/call.ts +0 -63
- package/source/cascade.ts +0 -32
- package/source/component.ts +0 -83
- package/source/composition.ts +0 -27
- package/source/connector.ts +0 -217
- package/source/context.ts +0 -68
- package/source/contract/contract.ts +0 -23
- package/source/contract/index.ts +0 -2
- package/source/contract/reply.ts +0 -56
- package/source/contract/request.ts +0 -140
- package/source/contract/schemas.ts +0 -39
- package/source/discovery.ts +0 -53
- package/source/effect.ts +0 -14
- package/source/emission.ts +0 -21
- package/source/entities/changeset.ts +0 -37
- package/source/entities/entity.ts +0 -137
- package/source/entities/factory.ts +0 -52
- package/source/entities/index.ts +0 -4
- package/source/entities/newid.ts +0 -9
- package/source/entities/set.ts +0 -27
- package/source/event.ts +0 -57
- package/source/exceptions.ts +0 -133
- package/source/exposition.ts +0 -33
- package/source/guard.ts +0 -16
- package/source/index.ts +0 -36
- package/source/locator.ts +0 -37
- package/source/observation.ts +0 -16
- package/source/operation.ts +0 -139
- package/source/outbox/index.ts +0 -1
- package/source/outbox/outbox.ts +0 -341
- package/source/query/criteria.ts +0 -90
- package/source/query/options.ts +0 -35
- package/source/query.ts +0 -67
- package/source/receiver.ts +0 -120
- package/source/reflection.ts +0 -20
- package/source/remote.ts +0 -20
- package/source/state.ts +0 -179
- package/source/transition.ts +0 -79
- package/source/transmission.ts +0 -38
- package/source/types/atomicity.ts +0 -63
- package/source/types/bindings.ts +0 -59
- package/source/types/bridges.ts +0 -54
- package/source/types/extensions.ts +0 -89
- package/source/types/index.ts +0 -14
- package/source/types/message.ts +0 -5
- package/source/types/operations.ts +0 -31
- package/source/types/outbox.ts +0 -35
- package/source/types/receiver.ts +0 -10
- package/source/types/request.ts +0 -54
- package/source/types/state.ts +0 -9
- package/source/types/storages.ts +0 -134
- package/source/unmanaged.ts +0 -8
- package/test/call.fixtures.js +0 -25
- package/test/call.test.js +0 -79
- package/test/component.fixtures.js +0 -18
- package/test/component.test.js +0 -57
- package/test/connector.fixtures.js +0 -56
- package/test/connector.test.js +0 -266
- package/test/context.fixtures.js +0 -14
- package/test/context.test.js +0 -40
- package/test/contract/conditions.test.js +0 -32
- package/test/contract/contract.fixtures.js +0 -28
- package/test/contract/request.test.js +0 -196
- package/test/discovery.test.js +0 -71
- package/test/emission.fixtures.js +0 -13
- package/test/emission.test.js +0 -60
- package/test/entities/entity.fixtures.js +0 -24
- package/test/entities/entity.test.js +0 -137
- package/test/entities/factory.fixtures.js +0 -31
- package/test/entities/factory.test.js +0 -99
- package/test/entities/set.fixtures.js +0 -9
- package/test/entities/set.test.js +0 -13
- package/test/event.fixtures.js +0 -24
- package/test/event.test.js +0 -162
- package/test/locator.test.js +0 -120
- package/test/outbox.test.js +0 -202
- package/test/query.fixtures.js +0 -96
- package/test/query.test.js +0 -183
- package/test/receiver.fixtures.js +0 -20
- package/test/receiver.test.js +0 -144
- package/test/reflection.test.js +0 -31
- package/test/state.fixtures.js +0 -49
- package/test/state.test.js +0 -162
- package/test/transmission.fixtures.js +0 -13
- package/test/transmission.test.js +0 -77
- package/transpiled/outbox/index.d.ts +0 -1
- package/transpiled/outbox/index.js +0 -2
- package/transpiled/outbox/index.js.map +0 -1
- package/transpiled/outbox/outbox.js +0 -268
- package/transpiled/outbox/outbox.js.map +0 -1
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { EntityContractException, EntityGuardException } from '../exceptions.js'
|
|
2
|
-
import { newid } from './newid.js'
|
|
3
|
-
import type { Schema } from '@toa.io/schemas'
|
|
4
|
-
import type { Guard } from '../guard.js'
|
|
5
|
-
import type { Record } from '../types/storages.js'
|
|
6
|
-
import type { Event } from '../types/state.js'
|
|
7
|
-
|
|
8
|
-
export class Entity {
|
|
9
|
-
public deleted = false
|
|
10
|
-
|
|
11
|
-
readonly #schema: Schema
|
|
12
|
-
readonly #blank: object
|
|
13
|
-
readonly #guards: Guard[] | undefined
|
|
14
|
-
#origin: Record | null = null
|
|
15
|
-
#state!: Record
|
|
16
|
-
#mutable = true
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A record makes an entity of what a storage holds; a string, or nothing at all, makes a
|
|
20
|
-
* blank one under that identity, out of what the component declared a record starts as.
|
|
21
|
-
*
|
|
22
|
-
* @param blank what the component declares a record holds before anything is written to it
|
|
23
|
-
* @param mutable whether the entity may be modified and committed
|
|
24
|
-
*/
|
|
25
|
-
// eslint-disable-next-line max-params
|
|
26
|
-
public constructor(
|
|
27
|
-
schema: Schema,
|
|
28
|
-
blank: object,
|
|
29
|
-
argument?: Record | string,
|
|
30
|
-
guards?: Guard[],
|
|
31
|
-
mutable = true
|
|
32
|
-
) {
|
|
33
|
-
this.#schema = schema
|
|
34
|
-
this.#blank = blank
|
|
35
|
-
this.#guards = guards
|
|
36
|
-
|
|
37
|
-
if (typeof argument === 'object') this.#acquire(argument, mutable)
|
|
38
|
-
else this.#write(this.#compose(argument ?? newid()))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public get(): Record {
|
|
42
|
-
return this.#state
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public set(value: Record): void {
|
|
46
|
-
if (!this.#mutable)
|
|
47
|
-
throw new Error('Entity acquired by a read-only operation cannot be modified')
|
|
48
|
-
|
|
49
|
-
this.#guard(value)
|
|
50
|
-
|
|
51
|
-
const error = this.#schema.fit(value)
|
|
52
|
-
|
|
53
|
-
if (error !== null) throw new EntityContractException(error, value)
|
|
54
|
-
|
|
55
|
-
this.#revive(value)
|
|
56
|
-
this.#write(value)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public event(input?: object): Event {
|
|
60
|
-
return {
|
|
61
|
-
origin: this.#origin,
|
|
62
|
-
state: this.#state,
|
|
63
|
-
trailers: this.#state._trailers,
|
|
64
|
-
input
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The origin is the pre-image a commit diffs the new state against. An operation that
|
|
70
|
-
* cannot commit has nothing to diff, so it takes the record as it came from the storage
|
|
71
|
-
* instead of paying for a deep copy of every record it read.
|
|
72
|
-
*/
|
|
73
|
-
#acquire(record: Record, mutable: boolean): void {
|
|
74
|
-
this.#mutable = mutable
|
|
75
|
-
|
|
76
|
-
if (!mutable) {
|
|
77
|
-
this.#write(record)
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.#write(structuredClone(record))
|
|
83
|
-
this.#origin = record
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* A blank is not validated: what the component declared is fitted once, at boot, and the
|
|
88
|
-
* system properties are the runtime's own. It is copied because every entity the component
|
|
89
|
-
* makes is written over its own.
|
|
90
|
-
*/
|
|
91
|
-
#compose(id: string): Record {
|
|
92
|
-
return { id, VERSION: 0, DELETED: null, ...structuredClone(this.#blank) } as Record
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
#guard(value: Record): void {
|
|
96
|
-
if (this.#guards === undefined) return
|
|
97
|
-
|
|
98
|
-
for (const guard of this.#guards) {
|
|
99
|
-
const ok = guard.fit(value, this.#origin)
|
|
100
|
-
|
|
101
|
-
if (ok === false) throw new EntityGuardException(guard.name, value)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// deletion is only expressed as a new DELETED timestamp,
|
|
106
|
-
// so committing over a tombstone without touching it means revival
|
|
107
|
-
#revive(value: Record): void {
|
|
108
|
-
if (this.#origin?.DELETED == null || value.DELETED !== this.#origin.DELETED) return
|
|
109
|
-
|
|
110
|
-
value.DELETED = null
|
|
111
|
-
this.deleted = false
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
#write(value: Record): void {
|
|
115
|
-
if (!('_trailers' in value))
|
|
116
|
-
Object.defineProperty(value, '_trailers', {
|
|
117
|
-
writable: false,
|
|
118
|
-
configurable: false,
|
|
119
|
-
enumerable: false,
|
|
120
|
-
value: {}
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
if (!('CREATED' in value)) {
|
|
124
|
-
value.CREATED = Date.now()
|
|
125
|
-
value.UPDATED ??= value.CREATED
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if ('DELETED' in value && value.DELETED !== null) this.deleted = true
|
|
129
|
-
|
|
130
|
-
if (this.#state !== undefined) {
|
|
131
|
-
value.UPDATED = Date.now()
|
|
132
|
-
value.VERSION++
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.#state = value
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { newid } from './newid.js'
|
|
2
|
-
import { Entity } from './entity.js'
|
|
3
|
-
import { EntitySet } from './set.js'
|
|
4
|
-
import { Changeset } from './changeset.js'
|
|
5
|
-
import type { Schema } from '@toa.io/schemas'
|
|
6
|
-
import type { Guard } from '../guard.js'
|
|
7
|
-
import type { Query, Record } from '../types/storages.js'
|
|
8
|
-
|
|
9
|
-
/** The two schemas a component's records are held to, and what a new one starts as. */
|
|
10
|
-
export interface Schemas {
|
|
11
|
-
/** what a stored record must fit */
|
|
12
|
-
entity: Schema
|
|
13
|
-
|
|
14
|
-
/** what a changeset must fit: the same properties, none of them required */
|
|
15
|
-
changeset: Schema
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class Factory {
|
|
19
|
-
readonly #schemas: Schemas
|
|
20
|
-
readonly #blank: object
|
|
21
|
-
readonly #guards: Guard[] | undefined
|
|
22
|
-
|
|
23
|
-
public constructor(schemas: Schemas, blank: object, guards?: Guard[]) {
|
|
24
|
-
this.#schemas = schemas
|
|
25
|
-
this.#blank = blank
|
|
26
|
-
this.#guards = guards
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public fit(values: object): void {
|
|
30
|
-
this.#schemas.entity.validate({ id: newid(), ...this.#blank, ...values }, 'Entity')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public init(id?: string): Entity {
|
|
34
|
-
return new Entity(this.#schemas.entity, this.#blank, id, this.#guards)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public object(record: Record, mutable = true): Entity {
|
|
38
|
-
return new Entity(this.#schemas.entity, this.#blank, record, this.#guards, mutable)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public objects(recordset: Record[], init?: string[], mutable = true): EntitySet {
|
|
42
|
-
const set = recordset.map((record) => this.object(record, mutable))
|
|
43
|
-
|
|
44
|
-
if (init !== undefined) for (const id of init) set.unshift(this.init(id))
|
|
45
|
-
|
|
46
|
-
return new EntitySet(set)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public changeset(query: Query): Changeset {
|
|
50
|
-
return new Changeset(this.#schemas.changeset, query)
|
|
51
|
-
}
|
|
52
|
-
}
|
package/source/entities/index.ts
DELETED
package/source/entities/newid.ts
DELETED
package/source/entities/set.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { SystemException } from '../exceptions.js'
|
|
2
|
-
import type { Entity } from './entity.js'
|
|
3
|
-
import type { Record } from '../types/storages.js'
|
|
4
|
-
import type { Event } from '../types/state.js'
|
|
5
|
-
|
|
6
|
-
export class EntitySet {
|
|
7
|
-
readonly #set: Entity[]
|
|
8
|
-
|
|
9
|
-
public constructor(set: Entity[]) {
|
|
10
|
-
this.#set = set
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public get(): Record[] {
|
|
14
|
-
return this.#set.map((entity) => entity.get())
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public set(values: Record[]): void {
|
|
18
|
-
if (values.length !== this.#set.length)
|
|
19
|
-
throw new SystemException('Objects array must not be modified')
|
|
20
|
-
|
|
21
|
-
values.forEach((value, index) => this.#set[index].set(value))
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public events(input?: object): Event[] {
|
|
25
|
-
return this.#set.map((entity) => entity.event(input))
|
|
26
|
-
}
|
|
27
|
-
}
|
package/source/event.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { console, current, encode, type SpanOptions } from 'openspan'
|
|
2
|
-
import { Connector } from './connector.js'
|
|
3
|
-
import type { Emitter } from './types/bindings.js'
|
|
4
|
-
import type { Event as Bridge } from './types/bridges.js'
|
|
5
|
-
import type { Message } from './types/message.js'
|
|
6
|
-
import type { Event as StateEvent } from './types/state.js'
|
|
7
|
-
|
|
8
|
-
export interface Definition {
|
|
9
|
-
conditioned?: boolean
|
|
10
|
-
subjective?: boolean
|
|
11
|
-
label?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Event extends Connector {
|
|
15
|
-
readonly #emitter: Emitter
|
|
16
|
-
readonly #bridge: Bridge | undefined
|
|
17
|
-
readonly #conditioned: boolean | undefined
|
|
18
|
-
readonly #subjective: boolean | undefined
|
|
19
|
-
readonly #label: string
|
|
20
|
-
|
|
21
|
-
public constructor(definition: Definition, emitter: Emitter, bridge?: Bridge) {
|
|
22
|
-
super()
|
|
23
|
-
|
|
24
|
-
this.#conditioned = definition.conditioned
|
|
25
|
-
this.#subjective = definition.subjective
|
|
26
|
-
this.#label = definition.label ?? 'event'
|
|
27
|
-
this.#emitter = emitter
|
|
28
|
-
this.#bridge = bridge
|
|
29
|
-
|
|
30
|
-
this.depends(emitter)
|
|
31
|
-
|
|
32
|
-
if (bridge !== undefined) this.depends(bridge)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public async emit(event: StateEvent): Promise<void> {
|
|
36
|
-
if (this.#conditioned === false || (await this.#bridge?.condition(event)) === true) {
|
|
37
|
-
const payload =
|
|
38
|
-
this.#subjective === true ? await this.#bridge?.payload(event) : event.state
|
|
39
|
-
|
|
40
|
-
const message: Message = { payload }
|
|
41
|
-
|
|
42
|
-
const options: SpanOptions = {
|
|
43
|
-
name: `${this.#label} publish`,
|
|
44
|
-
kind: 'producer',
|
|
45
|
-
attributes: { 'messaging.destination.name': this.#label }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
await console.span(options, async () => {
|
|
49
|
-
const context = current()
|
|
50
|
-
|
|
51
|
-
if (context !== undefined) message.telemetry = encode(context)
|
|
52
|
-
|
|
53
|
-
await this.#emitter.emit(message)
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
package/source/exceptions.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { swap } from '@toa.io/generic'
|
|
2
|
-
import type { SchemaError } from '@toa.io/schemas'
|
|
3
|
-
|
|
4
|
-
export const codes = {
|
|
5
|
-
System: 0,
|
|
6
|
-
|
|
7
|
-
Contract: 200,
|
|
8
|
-
RequestSyntax: 201,
|
|
9
|
-
RequestContract: 202,
|
|
10
|
-
RequestConflict: 203,
|
|
11
|
-
ResponseContract: 211,
|
|
12
|
-
EntityContract: 212,
|
|
13
|
-
EntityGuard: 213,
|
|
14
|
-
QuerySyntax: 221,
|
|
15
|
-
|
|
16
|
-
State: 300,
|
|
17
|
-
StateNotFound: 302,
|
|
18
|
-
StatePrecondition: 303,
|
|
19
|
-
StateConcurrency: 304,
|
|
20
|
-
StateInitialization: 305,
|
|
21
|
-
Duplicate: 306,
|
|
22
|
-
|
|
23
|
-
Communication: 400,
|
|
24
|
-
Transmission: 401
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class Exception {
|
|
28
|
-
public readonly code: number
|
|
29
|
-
public readonly message: string
|
|
30
|
-
public cause?: unknown;
|
|
31
|
-
|
|
32
|
-
/** what a contract exception copies off the schema error it refused with */
|
|
33
|
-
[key: string]: unknown
|
|
34
|
-
|
|
35
|
-
public constructor(code: number, message: string, cause?: unknown) {
|
|
36
|
-
this.code = code
|
|
37
|
-
this.message = message
|
|
38
|
-
|
|
39
|
-
if (cause !== undefined) this.cause = cause
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class SystemException extends Exception {
|
|
44
|
-
public readonly stack?: string
|
|
45
|
-
|
|
46
|
-
public constructor(error: Error | string) {
|
|
47
|
-
super(codes.System, typeof error === 'string' ? error : error.message)
|
|
48
|
-
|
|
49
|
-
if (typeof error !== 'string' && error.stack !== undefined) this.stack = error.stack
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class ContractException extends Exception {
|
|
54
|
-
public constructor(
|
|
55
|
-
code: number | undefined,
|
|
56
|
-
error: SchemaError | string | null,
|
|
57
|
-
cause?: unknown
|
|
58
|
-
) {
|
|
59
|
-
super(
|
|
60
|
-
code ?? codes.Contract,
|
|
61
|
-
typeof error === 'string' ? error : (error?.message ?? ''),
|
|
62
|
-
cause
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
if (typeof error === 'object' && error !== null)
|
|
66
|
-
for (const k of ['keyword', 'property', 'schema', 'path', 'params'] as const)
|
|
67
|
-
if (k in error) this[k] = (error as unknown as Record<string, unknown>)[k]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export class RequestContractException extends ContractException {
|
|
72
|
-
public constructor(error: SchemaError | string, cause?: unknown) {
|
|
73
|
-
super(codes.RequestContract, error, cause)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export class ResponseContractException extends ContractException {
|
|
78
|
-
public constructor(error: SchemaError | string, cause?: unknown) {
|
|
79
|
-
super(codes.ResponseContract, error, cause)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class EntityContractException extends ContractException {
|
|
84
|
-
public constructor(error: SchemaError | string, cause?: unknown) {
|
|
85
|
-
super(codes.EntityContract, error, cause)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export class EntityGuardException extends ContractException {
|
|
90
|
-
public constructor(name: string, cause?: unknown) {
|
|
91
|
-
super(codes.EntityGuard, name, cause)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// #region exports
|
|
96
|
-
|
|
97
|
-
// a module's exports are static, so the ones that follow a code are named rather
|
|
98
|
-
// than generated onto the namespace
|
|
99
|
-
type Derived = new (message?: string, cause?: unknown) => Exception
|
|
100
|
-
|
|
101
|
-
function derive(name: keyof typeof codes): Derived {
|
|
102
|
-
const classname = name + 'Exception'
|
|
103
|
-
|
|
104
|
-
const derived = class extends Exception {
|
|
105
|
-
public constructor(message?: string, cause?: unknown) {
|
|
106
|
-
super(
|
|
107
|
-
codes[name],
|
|
108
|
-
message === undefined ? classname : `${classname}: ${message}`,
|
|
109
|
-
cause
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// the name is the class's own, and a class expression has none worth reporting
|
|
115
|
-
Object.defineProperty(derived, 'name', { value: classname })
|
|
116
|
-
|
|
117
|
-
return derived
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export const RequestSyntaxException = derive('RequestSyntax')
|
|
121
|
-
export const RequestConflictException = derive('RequestConflict')
|
|
122
|
-
export const QuerySyntaxException = derive('QuerySyntax')
|
|
123
|
-
export const StateException = derive('State')
|
|
124
|
-
export const StateNotFoundException = derive('StateNotFound')
|
|
125
|
-
export const StatePreconditionException = derive('StatePrecondition')
|
|
126
|
-
export const StateConcurrencyException = derive('StateConcurrency')
|
|
127
|
-
export const StateInitializationException = derive('StateInitialization')
|
|
128
|
-
export const DuplicateException = derive('Duplicate')
|
|
129
|
-
export const CommunicationException = derive('Communication')
|
|
130
|
-
export const TransmissionException = derive('Transmission')
|
|
131
|
-
|
|
132
|
-
export const names = swap(codes)
|
|
133
|
-
// #endregion
|
package/source/exposition.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Connector } from './connector.js'
|
|
2
|
-
import type { Locator } from './locator.js'
|
|
3
|
-
|
|
4
|
-
interface Manifest {
|
|
5
|
-
namespace: string
|
|
6
|
-
name: string
|
|
7
|
-
entity?: object
|
|
8
|
-
operations?: object
|
|
9
|
-
events?: object
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class Exposition extends Connector {
|
|
13
|
-
public readonly locator: Locator
|
|
14
|
-
|
|
15
|
-
readonly #exposition: Partial<Manifest>
|
|
16
|
-
|
|
17
|
-
public constructor(locator: Locator, manifest: Manifest) {
|
|
18
|
-
super()
|
|
19
|
-
|
|
20
|
-
this.locator = locator
|
|
21
|
-
this.#exposition = expose(manifest)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public async invoke(): Promise<{ output: Partial<Manifest> }> {
|
|
25
|
-
return { output: this.#exposition }
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function expose(manifest: Manifest): Partial<Manifest> {
|
|
30
|
-
const { namespace, name, entity, operations, events } = manifest
|
|
31
|
-
|
|
32
|
-
return { namespace, name, entity, operations, events }
|
|
33
|
-
}
|
package/source/guard.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Guard as Bridge } from './types/bridges.js'
|
|
2
|
-
|
|
3
|
-
export class Guard {
|
|
4
|
-
public readonly name: string
|
|
5
|
-
|
|
6
|
-
readonly #bridge: Bridge
|
|
7
|
-
|
|
8
|
-
public constructor(name: string, bridge: Bridge) {
|
|
9
|
-
this.name = name
|
|
10
|
-
this.#bridge = bridge
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public fit(state: object, origin: object | null): boolean {
|
|
14
|
-
return this.#bridge.fit(state, origin)
|
|
15
|
-
}
|
|
16
|
-
}
|
package/source/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export { Assignment } from './assignment.js'
|
|
2
|
-
export { Call } from './call.js'
|
|
3
|
-
export { Cascade } from './cascade.js'
|
|
4
|
-
export { Component } from './component.js'
|
|
5
|
-
export { Composition } from './composition.js'
|
|
6
|
-
export { Connector } from './connector.js'
|
|
7
|
-
export { Context } from './context.js'
|
|
8
|
-
export { Discovery } from './discovery.js'
|
|
9
|
-
export { Effect } from './effect.js'
|
|
10
|
-
export { Emission } from './emission.js'
|
|
11
|
-
export { Event } from './event.js'
|
|
12
|
-
export { Exposition } from './exposition.js'
|
|
13
|
-
export { Locator } from './locator.js'
|
|
14
|
-
export { Observation } from './observation.js'
|
|
15
|
-
export { Outbox } from './outbox/index.js'
|
|
16
|
-
export { Operation } from './operation.js'
|
|
17
|
-
export { Query } from './query.js'
|
|
18
|
-
export { Receiver } from './receiver.js'
|
|
19
|
-
export { Reflection } from './reflection.js'
|
|
20
|
-
export { Remote } from './remote.js'
|
|
21
|
-
export { State } from './state.js'
|
|
22
|
-
export { Transition } from './transition.js'
|
|
23
|
-
export { Transmission } from './transmission.js'
|
|
24
|
-
export { Unmanaged } from './unmanaged.js'
|
|
25
|
-
export { Guard } from './guard.js'
|
|
26
|
-
export * as entities from './entities/index.js'
|
|
27
|
-
export * as exceptions from './exceptions.js'
|
|
28
|
-
export * as contract from './contract/index.js'
|
|
29
|
-
|
|
30
|
-
export type { Exception } from './exceptions.js'
|
|
31
|
-
export type { Invocable } from './component.js'
|
|
32
|
-
export type { Explicable } from './remote.js'
|
|
33
|
-
export type { Scoped, Store } from './operation.js'
|
|
34
|
-
export type { Source as ReflectionSource } from './reflection.js'
|
|
35
|
-
export type { Explanation } from './contract/request.js'
|
|
36
|
-
export type { JSONSchema } from './contract/schemas.js'
|
package/source/locator.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { concat } from '@toa.io/generic'
|
|
2
|
-
|
|
3
|
-
/** Where a component is, as every name derived from it. */
|
|
4
|
-
export class Locator {
|
|
5
|
-
public readonly name: string
|
|
6
|
-
public readonly namespace: string | undefined
|
|
7
|
-
|
|
8
|
-
public readonly id: string
|
|
9
|
-
public readonly label: string
|
|
10
|
-
public readonly uppercase: string
|
|
11
|
-
public readonly lowercase: string
|
|
12
|
-
|
|
13
|
-
public constructor(name: string, namespace?: string) {
|
|
14
|
-
if (name === undefined) throw new TypeError('Locator name must be defined')
|
|
15
|
-
|
|
16
|
-
this.name = name
|
|
17
|
-
this.namespace = namespace
|
|
18
|
-
|
|
19
|
-
this.id = concat(namespace, '.') + name
|
|
20
|
-
this.label = (concat(namespace, '-') + name).toLowerCase()
|
|
21
|
-
this.uppercase = (concat(namespace, '_') + name).toUpperCase()
|
|
22
|
-
this.lowercase = (concat(namespace, '_') + name).toLowerCase()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static parse(string: string): Locator {
|
|
26
|
-
const [namespace, name] = string.split(DOT)
|
|
27
|
-
|
|
28
|
-
if (name === undefined) return new Locator(namespace)
|
|
29
|
-
else return new Locator(name, namespace)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public hostname(prefix?: string): string {
|
|
33
|
-
return concat(prefix?.toLowerCase(), '-') + this.label
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const DOT = '.'
|
package/source/observation.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Operation } from './operation.js'
|
|
2
|
-
import type { Store } from './operation.js'
|
|
3
|
-
import type { Entity } from './entities/entity.js'
|
|
4
|
-
|
|
5
|
-
export class Observation extends Operation {
|
|
6
|
-
protected override async run(store: Store): Promise<void> {
|
|
7
|
-
const scope = store.scope as Entity | null
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
scope === null ||
|
|
11
|
-
(scope?.deleted === true && (store.request.query as any)?.options?.deleted !== true)
|
|
12
|
-
)
|
|
13
|
-
store.reply = null
|
|
14
|
-
else await super.run(store)
|
|
15
|
-
}
|
|
16
|
-
}
|