@toa.io/core 1.0.0-alpha.29 → 1.0.0-alpha.291
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/CHANGELOG.md +35 -0
- package/package.json +22 -12
- package/source/assignment.ts +27 -0
- package/source/call.ts +63 -0
- package/source/cascade.ts +32 -0
- package/source/component.ts +83 -0
- package/source/composition.ts +27 -0
- package/source/connector.ts +217 -0
- package/source/context.ts +68 -0
- package/source/contract/contract.ts +23 -0
- package/source/contract/index.ts +2 -0
- package/source/contract/reply.ts +56 -0
- package/source/contract/request.ts +140 -0
- package/source/contract/schemas.ts +39 -0
- package/source/discovery.ts +53 -0
- package/source/effect.ts +14 -0
- package/source/emission.ts +21 -0
- package/source/entities/changeset.ts +37 -0
- package/source/entities/entity.ts +137 -0
- package/source/entities/factory.ts +52 -0
- package/source/entities/index.ts +4 -0
- package/source/entities/newid.ts +9 -0
- package/source/entities/set.ts +27 -0
- package/source/event.ts +57 -0
- package/source/exceptions.ts +133 -0
- package/source/exposition.ts +33 -0
- package/source/guard.ts +16 -0
- package/source/index.ts +36 -0
- package/source/locator.ts +37 -0
- package/source/observation.ts +16 -0
- package/source/operation.ts +139 -0
- package/source/outbox/index.ts +1 -0
- package/source/outbox/outbox.ts +341 -0
- package/source/query/criteria.ts +90 -0
- package/source/query/options.ts +35 -0
- package/source/query.ts +67 -0
- package/source/receiver.ts +120 -0
- package/source/reflection.ts +20 -0
- package/source/remote.ts +20 -0
- package/source/state.ts +179 -0
- package/source/transition.ts +79 -0
- package/source/transmission.ts +38 -0
- package/source/types/atomicity.ts +63 -0
- package/source/types/bindings.ts +59 -0
- package/source/types/bridges.ts +54 -0
- package/source/types/extensions.ts +89 -0
- package/source/types/index.ts +14 -0
- package/{types/message.d.ts → source/types/message.ts} +2 -0
- package/source/types/operations.ts +31 -0
- package/source/types/outbox.ts +35 -0
- package/source/types/receiver.ts +10 -0
- package/source/types/request.ts +54 -0
- package/source/types/state.ts +9 -0
- package/source/types/storages.ts +134 -0
- package/source/unmanaged.ts +8 -0
- package/test/call.fixtures.js +10 -12
- package/test/call.test.js +42 -9
- package/test/component.fixtures.js +5 -8
- package/test/component.test.js +27 -10
- package/test/connector.fixtures.js +29 -13
- package/test/connector.test.js +128 -38
- package/test/context.fixtures.js +8 -12
- package/test/context.test.js +19 -8
- package/test/contract/conditions.test.js +15 -9
- package/test/contract/contract.fixtures.js +11 -16
- package/test/contract/request.test.js +130 -46
- package/test/discovery.test.js +71 -0
- package/test/emission.fixtures.js +6 -10
- package/test/emission.test.js +37 -12
- package/test/entities/entity.fixtures.js +11 -16
- package/test/entities/entity.test.js +105 -50
- package/test/entities/factory.fixtures.js +26 -13
- package/test/entities/factory.test.js +68 -17
- package/test/entities/set.fixtures.js +6 -8
- package/test/entities/set.test.js +6 -5
- package/test/event.fixtures.js +9 -14
- package/test/event.test.js +78 -34
- package/test/locator.test.js +32 -25
- package/test/outbox.test.js +202 -0
- package/test/query.fixtures.js +1 -5
- package/test/query.test.js +111 -14
- package/test/receiver.fixtures.js +9 -12
- package/test/receiver.test.js +80 -31
- package/test/reflection.test.js +9 -8
- package/test/state.fixtures.js +33 -31
- package/test/state.test.js +135 -19
- package/test/transmission.fixtures.js +4 -6
- package/test/transmission.test.js +47 -16
- package/transpiled/assignment.d.ts +6 -0
- package/transpiled/assignment.js +20 -0
- package/transpiled/assignment.js.map +1 -0
- package/transpiled/call.d.ts +10 -0
- package/transpiled/call.js +52 -0
- package/transpiled/call.js.map +1 -0
- package/transpiled/cascade.d.ts +7 -0
- package/transpiled/cascade.js +28 -0
- package/transpiled/cascade.js.map +1 -0
- package/transpiled/component.d.ts +15 -0
- package/transpiled/component.js +61 -0
- package/transpiled/component.js.map +1 -0
- package/transpiled/composition.d.ts +6 -0
- package/transpiled/composition.js +23 -0
- package/transpiled/composition.js.map +1 -0
- package/transpiled/connector.d.ts +47 -0
- package/transpiled/connector.js +185 -0
- package/transpiled/connector.js.map +1 -0
- package/transpiled/context.d.ts +18 -0
- package/transpiled/context.js +42 -0
- package/transpiled/context.js.map +1 -0
- package/transpiled/contract/contract.d.ts +10 -0
- package/transpiled/contract/contract.js +14 -0
- package/transpiled/contract/contract.js.map +1 -0
- package/transpiled/contract/index.d.ts +2 -0
- package/transpiled/contract/index.js +3 -0
- package/transpiled/contract/index.js.map +1 -0
- package/transpiled/contract/reply.d.ts +7 -0
- package/transpiled/contract/reply.js +48 -0
- package/transpiled/contract/reply.js.map +1 -0
- package/transpiled/contract/request.d.ts +29 -0
- package/transpiled/contract/request.js +103 -0
- package/transpiled/contract/request.js.map +1 -0
- package/transpiled/contract/schemas.d.ts +4 -0
- package/transpiled/contract/schemas.js +36 -0
- package/transpiled/contract/schemas.js.map +1 -0
- package/transpiled/discovery.d.ts +12 -0
- package/transpiled/discovery.js +34 -0
- package/transpiled/discovery.js.map +1 -0
- package/transpiled/effect.d.ts +5 -0
- package/transpiled/effect.js +11 -0
- package/transpiled/effect.js.map +1 -0
- package/transpiled/emission.d.ts +8 -0
- package/transpiled/emission.js +14 -0
- package/transpiled/emission.js.map +1 -0
- package/transpiled/entities/changeset.d.ts +10 -0
- package/transpiled/entities/changeset.js +27 -0
- package/transpiled/entities/changeset.js.map +1 -0
- package/transpiled/entities/entity.d.ts +19 -0
- package/transpiled/entities/entity.js +109 -0
- package/transpiled/entities/entity.js.map +1 -0
- package/transpiled/entities/factory.d.ts +22 -0
- package/transpiled/entities/factory.js +34 -0
- package/transpiled/entities/factory.js.map +1 -0
- package/transpiled/entities/index.d.ts +4 -0
- package/transpiled/entities/index.js +5 -0
- package/transpiled/entities/index.js.map +1 -0
- package/transpiled/entities/newid.d.ts +1 -0
- package/transpiled/entities/newid.js +7 -0
- package/transpiled/entities/newid.js.map +1 -0
- package/transpiled/entities/set.d.ts +10 -0
- package/transpiled/entities/set.js +19 -0
- package/transpiled/entities/set.js.map +1 -0
- package/transpiled/event.d.ts +14 -0
- package/transpiled/event.js +38 -0
- package/transpiled/event.js.map +1 -0
- package/transpiled/exceptions.d.ts +61 -0
- package/transpiled/exceptions.js +93 -0
- package/transpiled/exceptions.js.map +1 -0
- package/transpiled/exposition.d.ts +18 -0
- package/transpiled/exposition.js +18 -0
- package/transpiled/exposition.js.map +1 -0
- package/transpiled/guard.d.ts +7 -0
- package/transpiled/guard.js +12 -0
- package/transpiled/guard.js.map +1 -0
- package/transpiled/index.d.ts +35 -0
- package/transpiled/index.js +29 -0
- package/transpiled/index.js.map +1 -0
- package/transpiled/locator.d.ts +12 -0
- package/transpiled/locator.js +32 -0
- package/transpiled/locator.js.map +1 -0
- package/transpiled/observation.d.ts +5 -0
- package/transpiled/observation.js +12 -0
- package/transpiled/observation.js.map +1 -0
- package/transpiled/operation.d.ts +49 -0
- package/transpiled/operation.js +78 -0
- package/transpiled/operation.js.map +1 -0
- package/transpiled/outbox/index.d.ts +1 -0
- package/transpiled/outbox/index.js +2 -0
- package/transpiled/outbox/index.js.map +1 -0
- package/transpiled/outbox/outbox.d.ts +46 -0
- package/transpiled/outbox/outbox.js +268 -0
- package/transpiled/outbox/outbox.js.map +1 -0
- package/transpiled/query/criteria.d.ts +6 -0
- package/transpiled/query/criteria.js +74 -0
- package/transpiled/query/criteria.js.map +1 -0
- package/transpiled/query/options.d.ts +3 -0
- package/transpiled/query/options.js +27 -0
- package/transpiled/query/options.js.map +1 -0
- package/transpiled/query.d.ts +9 -0
- package/transpiled/query.js +57 -0
- package/transpiled/query.js.map +1 -0
- package/transpiled/receiver.d.ts +20 -0
- package/transpiled/receiver.js +92 -0
- package/transpiled/receiver.js.map +1 -0
- package/transpiled/reflection.d.ts +9 -0
- package/transpiled/reflection.js +13 -0
- package/transpiled/reflection.js.map +1 -0
- package/transpiled/remote.d.ts +10 -0
- package/transpiled/remote.js +12 -0
- package/transpiled/remote.js.map +1 -0
- package/transpiled/state.d.ts +33 -0
- package/transpiled/state.js +126 -0
- package/transpiled/state.js.map +1 -0
- package/transpiled/transition.d.ts +14 -0
- package/transpiled/transition.js +51 -0
- package/transpiled/transition.js.map +1 -0
- package/transpiled/transmission.d.ts +8 -0
- package/transpiled/transmission.js +30 -0
- package/transpiled/transmission.js.map +1 -0
- package/transpiled/types/atomicity.d.ts +56 -0
- package/transpiled/types/atomicity.js +2 -0
- package/transpiled/types/atomicity.js.map +1 -0
- package/transpiled/types/bindings.d.ts +42 -0
- package/transpiled/types/bindings.js +2 -0
- package/transpiled/types/bindings.js.map +1 -0
- package/transpiled/types/bridges.d.ts +38 -0
- package/transpiled/types/bridges.js +2 -0
- package/transpiled/types/bridges.js.map +1 -0
- package/transpiled/types/extensions.d.ts +62 -0
- package/transpiled/types/extensions.js +2 -0
- package/transpiled/types/extensions.js.map +1 -0
- package/transpiled/types/index.d.ts +13 -0
- package/transpiled/types/index.js +8 -0
- package/transpiled/types/index.js.map +1 -0
- package/transpiled/types/message.d.ts +5 -0
- package/transpiled/types/message.js +2 -0
- package/transpiled/types/message.js.map +1 -0
- package/transpiled/types/operations.d.ts +15 -0
- package/transpiled/types/operations.js +2 -0
- package/transpiled/types/operations.js.map +1 -0
- package/transpiled/types/outbox.d.ts +28 -0
- package/transpiled/types/outbox.js +2 -0
- package/transpiled/types/outbox.js.map +1 -0
- package/transpiled/types/receiver.d.ts +9 -0
- package/transpiled/types/receiver.js +2 -0
- package/transpiled/types/receiver.js.map +1 -0
- package/transpiled/types/request.d.ts +55 -0
- package/transpiled/types/request.js +2 -0
- package/transpiled/types/request.js.map +1 -0
- package/transpiled/types/state.d.ts +9 -0
- package/transpiled/types/state.js +2 -0
- package/transpiled/types/state.js.map +1 -0
- package/transpiled/types/storages.d.ts +111 -0
- package/transpiled/types/storages.js +2 -0
- package/transpiled/types/storages.js.map +1 -0
- package/transpiled/unmanaged.d.ts +5 -0
- package/transpiled/unmanaged.js +7 -0
- package/transpiled/unmanaged.js.map +1 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/assignment.js +0 -31
- package/src/call.js +0 -42
- package/src/cascade.js +0 -36
- package/src/component.js +0 -41
- package/src/composition.js +0 -25
- package/src/connector.js +0 -183
- package/src/context.js +0 -55
- package/src/contract/conditions.js +0 -21
- package/src/contract/index.js +0 -7
- package/src/contract/reply.js +0 -25
- package/src/contract/request.js +0 -67
- package/src/contract/schemas/error.yaml +0 -9
- package/src/contract/schemas/index.js +0 -7
- package/src/contract/schemas/query.yaml +0 -30
- package/src/discovery.js +0 -44
- package/src/emission.js +0 -23
- package/src/entities/changeset.js +0 -43
- package/src/entities/entity.js +0 -73
- package/src/entities/factory.js +0 -33
- package/src/entities/index.js +0 -5
- package/src/entities/set.js +0 -15
- package/src/event.js +0 -40
- package/src/exceptions.js +0 -100
- package/src/exposition.js +0 -27
- package/src/index.js +0 -47
- package/src/locator.js +0 -54
- package/src/observation.js +0 -20
- package/src/operation.js +0 -69
- package/src/query/criteria.js +0 -41
- package/src/query/options.js +0 -40
- package/src/query.js +0 -41
- package/src/receiver.js +0 -65
- package/src/reflection.js +0 -28
- package/src/remote.js +0 -17
- package/src/state.js +0 -99
- package/src/transition.js +0 -73
- package/src/transmission.js +0 -33
- package/types/bindings.d.ts +0 -40
- package/types/bridges.ts +0 -30
- package/types/component.d.ts +0 -9
- package/types/connector.d.ts +0 -18
- package/types/context.d.ts +0 -21
- package/types/entity.d.ts +0 -46
- package/types/event.d.ts +0 -11
- package/types/exception.d.ts +0 -4
- package/types/extensions.d.ts +0 -29
- package/types/index.ts +0 -14
- package/types/locator.d.ts +0 -13
- package/types/operations.d.ts +0 -2
- package/types/query.d.ts +0 -15
- package/types/receiver.d.ts +0 -12
- package/types/reflection.d.ts +0 -14
- package/types/request.d.ts +0 -23
- package/types/state.d.ts +0 -35
- package/types/storages.d.ts +0 -71
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
export class Emission extends Connector {
|
|
3
|
+
#events;
|
|
4
|
+
constructor(events) {
|
|
5
|
+
super();
|
|
6
|
+
this.#events = events;
|
|
7
|
+
this.depends(events);
|
|
8
|
+
}
|
|
9
|
+
async emit(event) {
|
|
10
|
+
const emission = this.#events.map((e) => e.emit(event));
|
|
11
|
+
await Promise.all(emission);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=emission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emission.js","sourceRoot":"","sources":["../source/emission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAI1C,MAAM,OAAO,QAAS,SAAQ,SAAS;IAC5B,OAAO,CAAS;IAEzB,YAAmB,MAAe;QAChC,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACtB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,KAAiB;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAEvD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Schema } from '@toa.io/schemas';
|
|
2
|
+
import type { Query, Record } from '../types/storages.js';
|
|
3
|
+
export declare class Changeset {
|
|
4
|
+
#private;
|
|
5
|
+
readonly query: Query;
|
|
6
|
+
constructor(schema: Schema, query: Query);
|
|
7
|
+
get(): object;
|
|
8
|
+
set(value: Record): void;
|
|
9
|
+
export(): object;
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EntityContractException } from '../exceptions.js';
|
|
2
|
+
export class Changeset {
|
|
3
|
+
query;
|
|
4
|
+
/** the changeset schema: the entity's properties, none of them required */
|
|
5
|
+
#schema;
|
|
6
|
+
#state;
|
|
7
|
+
constructor(schema, query) {
|
|
8
|
+
this.query = query;
|
|
9
|
+
this.#schema = schema;
|
|
10
|
+
this.#state = {};
|
|
11
|
+
}
|
|
12
|
+
get() {
|
|
13
|
+
return this.#state;
|
|
14
|
+
}
|
|
15
|
+
set(value) {
|
|
16
|
+
const error = this.#schema.fit(value);
|
|
17
|
+
if (error !== null)
|
|
18
|
+
throw new EntityContractException(error, value);
|
|
19
|
+
delete value.VERSION;
|
|
20
|
+
value.UPDATED = Date.now();
|
|
21
|
+
this.#state = value;
|
|
22
|
+
}
|
|
23
|
+
export() {
|
|
24
|
+
return this.#state;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=changeset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changeset.js","sourceRoot":"","sources":["../../source/entities/changeset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAI1D,MAAM,OAAO,SAAS;IACJ,KAAK,CAAO;IAE5B,2EAA2E;IAClE,OAAO,CAAQ;IACxB,MAAM,CAAiB;IAEvB,YAAmB,MAAc,EAAE,KAAY;QAC7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAElB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;IAClB,CAAC;IAEM,GAAG;QACR,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAEM,GAAG,CAAC,KAAa;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAErC,IAAI,KAAK,KAAK,IAAI;YAAE,MAAM,IAAI,uBAAuB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAEnE,OAAQ,KAAyB,CAAC,OAAO,CAAA;QACzC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAE1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Schema } from '@toa.io/schemas';
|
|
2
|
+
import type { Guard } from '../guard.js';
|
|
3
|
+
import type { Record } from '../types/storages.js';
|
|
4
|
+
import type { Event } from '../types/state.js';
|
|
5
|
+
export declare class Entity {
|
|
6
|
+
#private;
|
|
7
|
+
deleted: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* A record makes an entity of what a storage holds; a string, or nothing at all, makes a
|
|
10
|
+
* blank one under that identity, out of what the component declared a record starts as.
|
|
11
|
+
*
|
|
12
|
+
* @param blank what the component declares a record holds before anything is written to it
|
|
13
|
+
* @param mutable whether the entity may be modified and committed
|
|
14
|
+
*/
|
|
15
|
+
constructor(schema: Schema, blank: object, argument?: Record | string, guards?: Guard[], mutable?: boolean);
|
|
16
|
+
get(): Record;
|
|
17
|
+
set(value: Record): void;
|
|
18
|
+
event(input?: object): Event;
|
|
19
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { EntityContractException, EntityGuardException } from '../exceptions.js';
|
|
2
|
+
import { newid } from './newid.js';
|
|
3
|
+
export class Entity {
|
|
4
|
+
deleted = false;
|
|
5
|
+
#schema;
|
|
6
|
+
#blank;
|
|
7
|
+
#guards;
|
|
8
|
+
#origin = null;
|
|
9
|
+
#state;
|
|
10
|
+
#mutable = true;
|
|
11
|
+
/**
|
|
12
|
+
* A record makes an entity of what a storage holds; a string, or nothing at all, makes a
|
|
13
|
+
* blank one under that identity, out of what the component declared a record starts as.
|
|
14
|
+
*
|
|
15
|
+
* @param blank what the component declares a record holds before anything is written to it
|
|
16
|
+
* @param mutable whether the entity may be modified and committed
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line max-params
|
|
19
|
+
constructor(schema, blank, argument, guards, mutable = true) {
|
|
20
|
+
this.#schema = schema;
|
|
21
|
+
this.#blank = blank;
|
|
22
|
+
this.#guards = guards;
|
|
23
|
+
if (typeof argument === 'object')
|
|
24
|
+
this.#acquire(argument, mutable);
|
|
25
|
+
else
|
|
26
|
+
this.#write(this.#compose(argument ?? newid()));
|
|
27
|
+
}
|
|
28
|
+
get() {
|
|
29
|
+
return this.#state;
|
|
30
|
+
}
|
|
31
|
+
set(value) {
|
|
32
|
+
if (!this.#mutable)
|
|
33
|
+
throw new Error('Entity acquired by a read-only operation cannot be modified');
|
|
34
|
+
this.#guard(value);
|
|
35
|
+
const error = this.#schema.fit(value);
|
|
36
|
+
if (error !== null)
|
|
37
|
+
throw new EntityContractException(error, value);
|
|
38
|
+
this.#revive(value);
|
|
39
|
+
this.#write(value);
|
|
40
|
+
}
|
|
41
|
+
event(input) {
|
|
42
|
+
return {
|
|
43
|
+
origin: this.#origin,
|
|
44
|
+
state: this.#state,
|
|
45
|
+
trailers: this.#state._trailers,
|
|
46
|
+
input
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The origin is the pre-image a commit diffs the new state against. An operation that
|
|
51
|
+
* cannot commit has nothing to diff, so it takes the record as it came from the storage
|
|
52
|
+
* instead of paying for a deep copy of every record it read.
|
|
53
|
+
*/
|
|
54
|
+
#acquire(record, mutable) {
|
|
55
|
+
this.#mutable = mutable;
|
|
56
|
+
if (!mutable) {
|
|
57
|
+
this.#write(record);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.#write(structuredClone(record));
|
|
61
|
+
this.#origin = record;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A blank is not validated: what the component declared is fitted once, at boot, and the
|
|
65
|
+
* system properties are the runtime's own. It is copied because every entity the component
|
|
66
|
+
* makes is written over its own.
|
|
67
|
+
*/
|
|
68
|
+
#compose(id) {
|
|
69
|
+
return { id, VERSION: 0, DELETED: null, ...structuredClone(this.#blank) };
|
|
70
|
+
}
|
|
71
|
+
#guard(value) {
|
|
72
|
+
if (this.#guards === undefined)
|
|
73
|
+
return;
|
|
74
|
+
for (const guard of this.#guards) {
|
|
75
|
+
const ok = guard.fit(value, this.#origin);
|
|
76
|
+
if (ok === false)
|
|
77
|
+
throw new EntityGuardException(guard.name, value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// deletion is only expressed as a new DELETED timestamp,
|
|
81
|
+
// so committing over a tombstone without touching it means revival
|
|
82
|
+
#revive(value) {
|
|
83
|
+
if (this.#origin?.DELETED == null || value.DELETED !== this.#origin.DELETED)
|
|
84
|
+
return;
|
|
85
|
+
value.DELETED = null;
|
|
86
|
+
this.deleted = false;
|
|
87
|
+
}
|
|
88
|
+
#write(value) {
|
|
89
|
+
if (!('_trailers' in value))
|
|
90
|
+
Object.defineProperty(value, '_trailers', {
|
|
91
|
+
writable: false,
|
|
92
|
+
configurable: false,
|
|
93
|
+
enumerable: false,
|
|
94
|
+
value: {}
|
|
95
|
+
});
|
|
96
|
+
if (!('CREATED' in value)) {
|
|
97
|
+
value.CREATED = Date.now();
|
|
98
|
+
value.UPDATED ??= value.CREATED;
|
|
99
|
+
}
|
|
100
|
+
if ('DELETED' in value && value.DELETED !== null)
|
|
101
|
+
this.deleted = true;
|
|
102
|
+
if (this.#state !== undefined) {
|
|
103
|
+
value.UPDATED = Date.now();
|
|
104
|
+
value.VERSION++;
|
|
105
|
+
}
|
|
106
|
+
this.#state = value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../source/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAMlC,MAAM,OAAO,MAAM;IACV,OAAO,GAAG,KAAK,CAAA;IAEb,OAAO,C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AAK,CAAC;YACzB,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE;gBACxC,QAAQ,EAAE,KAAK;gBACf,YAAY,EAAE,KAAK;gBACnB,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,EAAE;aACV,CAAC,CAAA;QAEJ,IAAI,CAAC,CAAC,SAAS,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAC1B,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAAA;QACjC,CAAC;QAED,IAAI,SAAS,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI;YAAE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAErE,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YAC1B,KAAK,CAAC,OAAO,EAAE,CAAA;QACjB,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Entity } from './entity.js';
|
|
2
|
+
import { EntitySet } from './set.js';
|
|
3
|
+
import { Changeset } from './changeset.js';
|
|
4
|
+
import type { Schema } from '@toa.io/schemas';
|
|
5
|
+
import type { Guard } from '../guard.js';
|
|
6
|
+
import type { Query, Record } from '../types/storages.js';
|
|
7
|
+
/** The two schemas a component's records are held to, and what a new one starts as. */
|
|
8
|
+
export interface Schemas {
|
|
9
|
+
/** what a stored record must fit */
|
|
10
|
+
entity: Schema;
|
|
11
|
+
/** what a changeset must fit: the same properties, none of them required */
|
|
12
|
+
changeset: Schema;
|
|
13
|
+
}
|
|
14
|
+
export declare class Factory {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(schemas: Schemas, blank: object, guards?: Guard[]);
|
|
17
|
+
fit(values: object): void;
|
|
18
|
+
init(id?: string): Entity;
|
|
19
|
+
object(record: Record, mutable?: boolean): Entity;
|
|
20
|
+
objects(recordset: Record[], init?: string[], mutable?: boolean): EntitySet;
|
|
21
|
+
changeset(query: Query): Changeset;
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
export class Factory {
|
|
6
|
+
#schemas;
|
|
7
|
+
#blank;
|
|
8
|
+
#guards;
|
|
9
|
+
constructor(schemas, blank, guards) {
|
|
10
|
+
this.#schemas = schemas;
|
|
11
|
+
this.#blank = blank;
|
|
12
|
+
this.#guards = guards;
|
|
13
|
+
}
|
|
14
|
+
fit(values) {
|
|
15
|
+
this.#schemas.entity.validate({ id: newid(), ...this.#blank, ...values }, 'Entity');
|
|
16
|
+
}
|
|
17
|
+
init(id) {
|
|
18
|
+
return new Entity(this.#schemas.entity, this.#blank, id, this.#guards);
|
|
19
|
+
}
|
|
20
|
+
object(record, mutable = true) {
|
|
21
|
+
return new Entity(this.#schemas.entity, this.#blank, record, this.#guards, mutable);
|
|
22
|
+
}
|
|
23
|
+
objects(recordset, init, mutable = true) {
|
|
24
|
+
const set = recordset.map((record) => this.object(record, mutable));
|
|
25
|
+
if (init !== undefined)
|
|
26
|
+
for (const id of init)
|
|
27
|
+
set.unshift(this.init(id));
|
|
28
|
+
return new EntitySet(set);
|
|
29
|
+
}
|
|
30
|
+
changeset(query) {
|
|
31
|
+
return new Changeset(this.#schemas.changeset, query);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../source/entities/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAA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AAE,IAAI,IAAI;gBAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;QAEzE,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAEM,SAAS,CAAC,KAAY;QAC3B,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function newid(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newid.js","sourceRoot":"","sources":["../../source/entities/newid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,UAAU,KAAK;IACnB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAE5B,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IAEvB,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Entity } from './entity.js';
|
|
2
|
+
import type { Record } from '../types/storages.js';
|
|
3
|
+
import type { Event } from '../types/state.js';
|
|
4
|
+
export declare class EntitySet {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(set: Entity[]);
|
|
7
|
+
get(): Record[];
|
|
8
|
+
set(values: Record[]): void;
|
|
9
|
+
events(input?: object): Event[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SystemException } from '../exceptions.js';
|
|
2
|
+
export class EntitySet {
|
|
3
|
+
#set;
|
|
4
|
+
constructor(set) {
|
|
5
|
+
this.#set = set;
|
|
6
|
+
}
|
|
7
|
+
get() {
|
|
8
|
+
return this.#set.map((entity) => entity.get());
|
|
9
|
+
}
|
|
10
|
+
set(values) {
|
|
11
|
+
if (values.length !== this.#set.length)
|
|
12
|
+
throw new SystemException('Objects array must not be modified');
|
|
13
|
+
values.forEach((value, index) => this.#set[index].set(value));
|
|
14
|
+
}
|
|
15
|
+
events(input) {
|
|
16
|
+
return this.#set.map((entity) => entity.event(input));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.js","sourceRoot":"","sources":["../../source/entities/set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAKlD,MAAM,OAAO,SAAS;IACX,IAAI,CAAU;IAEvB,YAAmB,GAAa;QAC9B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;IACjB,CAAC;IAEM,GAAG;QACR,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IAChD,CAAC;IAEM,GAAG,CAAC,MAAgB;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM;YACpC,MAAM,IAAI,eAAe,CAAC,oCAAoC,CAAC,CAAA;QAEjE,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/D,CAAC;IAEM,MAAM,CAAC,KAAc;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Emitter } from './types/bindings.js';
|
|
3
|
+
import type { Event as Bridge } from './types/bridges.js';
|
|
4
|
+
import type { Event as StateEvent } from './types/state.js';
|
|
5
|
+
export interface Definition {
|
|
6
|
+
conditioned?: boolean;
|
|
7
|
+
subjective?: boolean;
|
|
8
|
+
label?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class Event extends Connector {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(definition: Definition, emitter: Emitter, bridge?: Bridge);
|
|
13
|
+
emit(event: StateEvent): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { console, current, encode } from 'openspan';
|
|
2
|
+
import { Connector } from './connector.js';
|
|
3
|
+
export class Event extends Connector {
|
|
4
|
+
#emitter;
|
|
5
|
+
#bridge;
|
|
6
|
+
#conditioned;
|
|
7
|
+
#subjective;
|
|
8
|
+
#label;
|
|
9
|
+
constructor(definition, emitter, bridge) {
|
|
10
|
+
super();
|
|
11
|
+
this.#conditioned = definition.conditioned;
|
|
12
|
+
this.#subjective = definition.subjective;
|
|
13
|
+
this.#label = definition.label ?? 'event';
|
|
14
|
+
this.#emitter = emitter;
|
|
15
|
+
this.#bridge = bridge;
|
|
16
|
+
this.depends(emitter);
|
|
17
|
+
if (bridge !== undefined)
|
|
18
|
+
this.depends(bridge);
|
|
19
|
+
}
|
|
20
|
+
async emit(event) {
|
|
21
|
+
if (this.#conditioned === false || (await this.#bridge?.condition(event)) === true) {
|
|
22
|
+
const payload = this.#subjective === true ? await this.#bridge?.payload(event) : event.state;
|
|
23
|
+
const message = { payload };
|
|
24
|
+
const options = {
|
|
25
|
+
name: `${this.#label} publish`,
|
|
26
|
+
kind: 'producer',
|
|
27
|
+
attributes: { 'messaging.destination.name': this.#label }
|
|
28
|
+
};
|
|
29
|
+
await console.span(options, async () => {
|
|
30
|
+
const context = current();
|
|
31
|
+
if (context !== undefined)
|
|
32
|
+
message.telemetry = encode(context);
|
|
33
|
+
await this.#emitter.emit(message);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../source/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAY1C,MAAM,OAAO,KAAM,SAAQ,SAAS;IACzB,QAAQ,CAAS;IACjB,OAAO,CAAoB;IAC3B,YAAY,CAAqB;IACjC,WAAW,CAAqB;IAChC,MAAM,CAAQ;IAEvB,YAAmB,UAAsB,EAAE,OAAgB,EAAE,MAAe;QAC1E,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,WAAW,CAAA;QAC1C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,UAAU,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,KAAK,IAAI,OAAO,CAAA;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAErB,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,KAAiB;QACjC,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACnF,MAAM,OAAO,GACX,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAA;YAE9E,MAAM,OAAO,GAAY,EAAE,OAAO,EAAE,CAAA;YAEpC,MAAM,OAAO,GAAgB;gBAC3B,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,UAAU;gBAC9B,IAAI,EAAE,UAAU;gBAChB,UAAU,EAAE,EAAE,4BAA4B,EAAE,IAAI,CAAC,MAAM,EAAE;aAC1D,CAAA;YAED,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;gBACrC,MAAM,OAAO,GAAG,OAAO,EAAE,CAAA;gBAEzB,IAAI,OAAO,KAAK,SAAS;oBAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;gBAE9D,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACnC,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { SchemaError } from '@toa.io/schemas';
|
|
2
|
+
export declare const codes: {
|
|
3
|
+
System: number;
|
|
4
|
+
Contract: number;
|
|
5
|
+
RequestSyntax: number;
|
|
6
|
+
RequestContract: number;
|
|
7
|
+
RequestConflict: number;
|
|
8
|
+
ResponseContract: number;
|
|
9
|
+
EntityContract: number;
|
|
10
|
+
EntityGuard: number;
|
|
11
|
+
QuerySyntax: number;
|
|
12
|
+
State: number;
|
|
13
|
+
StateNotFound: number;
|
|
14
|
+
StatePrecondition: number;
|
|
15
|
+
StateConcurrency: number;
|
|
16
|
+
StateInitialization: number;
|
|
17
|
+
Duplicate: number;
|
|
18
|
+
Communication: number;
|
|
19
|
+
Transmission: number;
|
|
20
|
+
};
|
|
21
|
+
export declare class Exception {
|
|
22
|
+
readonly code: number;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
/** what a contract exception copies off the schema error it refused with */
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
constructor(code: number, message: string, cause?: unknown);
|
|
28
|
+
}
|
|
29
|
+
export declare class SystemException extends Exception {
|
|
30
|
+
readonly stack?: string;
|
|
31
|
+
constructor(error: Error | string);
|
|
32
|
+
}
|
|
33
|
+
export declare class ContractException extends Exception {
|
|
34
|
+
constructor(code: number | undefined, error: SchemaError | string | null, cause?: unknown);
|
|
35
|
+
}
|
|
36
|
+
export declare class RequestContractException extends ContractException {
|
|
37
|
+
constructor(error: SchemaError | string, cause?: unknown);
|
|
38
|
+
}
|
|
39
|
+
export declare class ResponseContractException extends ContractException {
|
|
40
|
+
constructor(error: SchemaError | string, cause?: unknown);
|
|
41
|
+
}
|
|
42
|
+
export declare class EntityContractException extends ContractException {
|
|
43
|
+
constructor(error: SchemaError | string, cause?: unknown);
|
|
44
|
+
}
|
|
45
|
+
export declare class EntityGuardException extends ContractException {
|
|
46
|
+
constructor(name: string, cause?: unknown);
|
|
47
|
+
}
|
|
48
|
+
type Derived = new (message?: string, cause?: unknown) => Exception;
|
|
49
|
+
export declare const RequestSyntaxException: Derived;
|
|
50
|
+
export declare const RequestConflictException: Derived;
|
|
51
|
+
export declare const QuerySyntaxException: Derived;
|
|
52
|
+
export declare const StateException: Derived;
|
|
53
|
+
export declare const StateNotFoundException: Derived;
|
|
54
|
+
export declare const StatePreconditionException: Derived;
|
|
55
|
+
export declare const StateConcurrencyException: Derived;
|
|
56
|
+
export declare const StateInitializationException: Derived;
|
|
57
|
+
export declare const DuplicateException: Derived;
|
|
58
|
+
export declare const CommunicationException: Derived;
|
|
59
|
+
export declare const TransmissionException: Derived;
|
|
60
|
+
export declare const names: Record<string, string>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { swap } from '@toa.io/generic';
|
|
2
|
+
export const codes = {
|
|
3
|
+
System: 0,
|
|
4
|
+
Contract: 200,
|
|
5
|
+
RequestSyntax: 201,
|
|
6
|
+
RequestContract: 202,
|
|
7
|
+
RequestConflict: 203,
|
|
8
|
+
ResponseContract: 211,
|
|
9
|
+
EntityContract: 212,
|
|
10
|
+
EntityGuard: 213,
|
|
11
|
+
QuerySyntax: 221,
|
|
12
|
+
State: 300,
|
|
13
|
+
StateNotFound: 302,
|
|
14
|
+
StatePrecondition: 303,
|
|
15
|
+
StateConcurrency: 304,
|
|
16
|
+
StateInitialization: 305,
|
|
17
|
+
Duplicate: 306,
|
|
18
|
+
Communication: 400,
|
|
19
|
+
Transmission: 401
|
|
20
|
+
};
|
|
21
|
+
export class Exception {
|
|
22
|
+
code;
|
|
23
|
+
message;
|
|
24
|
+
cause;
|
|
25
|
+
constructor(code, message, cause) {
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.message = message;
|
|
28
|
+
if (cause !== undefined)
|
|
29
|
+
this.cause = cause;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class SystemException extends Exception {
|
|
33
|
+
stack;
|
|
34
|
+
constructor(error) {
|
|
35
|
+
super(codes.System, typeof error === 'string' ? error : error.message);
|
|
36
|
+
if (typeof error !== 'string' && error.stack !== undefined)
|
|
37
|
+
this.stack = error.stack;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class ContractException extends Exception {
|
|
41
|
+
constructor(code, error, cause) {
|
|
42
|
+
super(code ?? codes.Contract, typeof error === 'string' ? error : (error?.message ?? ''), cause);
|
|
43
|
+
if (typeof error === 'object' && error !== null)
|
|
44
|
+
for (const k of ['keyword', 'property', 'schema', 'path', 'params'])
|
|
45
|
+
if (k in error)
|
|
46
|
+
this[k] = error[k];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class RequestContractException extends ContractException {
|
|
50
|
+
constructor(error, cause) {
|
|
51
|
+
super(codes.RequestContract, error, cause);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export class ResponseContractException extends ContractException {
|
|
55
|
+
constructor(error, cause) {
|
|
56
|
+
super(codes.ResponseContract, error, cause);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class EntityContractException extends ContractException {
|
|
60
|
+
constructor(error, cause) {
|
|
61
|
+
super(codes.EntityContract, error, cause);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class EntityGuardException extends ContractException {
|
|
65
|
+
constructor(name, cause) {
|
|
66
|
+
super(codes.EntityGuard, name, cause);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function derive(name) {
|
|
70
|
+
const classname = name + 'Exception';
|
|
71
|
+
const derived = class extends Exception {
|
|
72
|
+
constructor(message, cause) {
|
|
73
|
+
super(codes[name], message === undefined ? classname : `${classname}: ${message}`, cause);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// the name is the class's own, and a class expression has none worth reporting
|
|
77
|
+
Object.defineProperty(derived, 'name', { value: classname });
|
|
78
|
+
return derived;
|
|
79
|
+
}
|
|
80
|
+
export const RequestSyntaxException = derive('RequestSyntax');
|
|
81
|
+
export const RequestConflictException = derive('RequestConflict');
|
|
82
|
+
export const QuerySyntaxException = derive('QuerySyntax');
|
|
83
|
+
export const StateException = derive('State');
|
|
84
|
+
export const StateNotFoundException = derive('StateNotFound');
|
|
85
|
+
export const StatePreconditionException = derive('StatePrecondition');
|
|
86
|
+
export const StateConcurrencyException = derive('StateConcurrency');
|
|
87
|
+
export const StateInitializationException = derive('StateInitialization');
|
|
88
|
+
export const DuplicateException = derive('Duplicate');
|
|
89
|
+
export const CommunicationException = derive('Communication');
|
|
90
|
+
export const TransmissionException = derive('Transmission');
|
|
91
|
+
export const names = swap(codes);
|
|
92
|
+
// #endregion
|
|
93
|
+
//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;AAC7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AAE3D,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;AAChC,aAAa"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
import type { Locator } from './locator.js';
|
|
3
|
+
interface Manifest {
|
|
4
|
+
namespace: string;
|
|
5
|
+
name: string;
|
|
6
|
+
entity?: object;
|
|
7
|
+
operations?: object;
|
|
8
|
+
events?: object;
|
|
9
|
+
}
|
|
10
|
+
export declare class Exposition extends Connector {
|
|
11
|
+
#private;
|
|
12
|
+
readonly locator: Locator;
|
|
13
|
+
constructor(locator: Locator, manifest: Manifest);
|
|
14
|
+
invoke(): Promise<{
|
|
15
|
+
output: Partial<Manifest>;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Connector } from './connector.js';
|
|
2
|
+
export class Exposition extends Connector {
|
|
3
|
+
locator;
|
|
4
|
+
#exposition;
|
|
5
|
+
constructor(locator, manifest) {
|
|
6
|
+
super();
|
|
7
|
+
this.locator = locator;
|
|
8
|
+
this.#exposition = expose(manifest);
|
|
9
|
+
}
|
|
10
|
+
async invoke() {
|
|
11
|
+
return { output: this.#exposition };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function expose(manifest) {
|
|
15
|
+
const { namespace, name, entity, operations, events } = manifest;
|
|
16
|
+
return { namespace, name, entity, operations, events };
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=exposition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exposition.js","sourceRoot":"","sources":["../source/exposition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAW1C,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvB,OAAO,CAAS;IAEvB,WAAW,CAAmB;IAEvC,YAAmB,OAAgB,EAAE,QAAkB;QACrD,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACrC,CAAC;IAEM,KAAK,CAAC,MAAM;QACjB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,CAAA;IACrC,CAAC;CACF;AAED,SAAS,MAAM,CAAC,QAAkB;IAChC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAA;IAEhE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;AACxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../source/guard.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,KAAK;IACA,IAAI,CAAQ;IAEnB,OAAO,CAAQ;IAExB,YAAmB,IAAY,EAAE,MAAc;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAEM,GAAG,CAAC,KAAa,EAAE,MAAqB;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACxC,CAAC;CACF"}
|