@adobe/data 0.9.70 → 0.9.72
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 +1 -1
- package/references/data-lit/package.json +1 -1
- package/references/data-lit/src/elements/database-element.ts +17 -7
- package/references/data-lit/src/elements/database-element.type-test.ts +13 -0
- package/references/data-lit-tictactoe/package.json +1 -1
- package/references/data-react/package.json +1 -1
- package/references/data-react-hello/package.json +1 -1
- package/references/data-react-pixie/package.json +1 -1
package/package.json
CHANGED
|
@@ -10,22 +10,32 @@ import { attachDecorator, withHooks } from '../index.js';
|
|
|
10
10
|
export abstract class DatabaseElement<P extends Database.Plugin> extends LitElement {
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* this
|
|
13
|
+
* Internal DI seam — prefer `service`. Set by an ancestor via injection or
|
|
14
|
+
* created from `plugin` on connect. Bootstrap containers (those that own a
|
|
15
|
+
* controller or drive a streaming async-generator transaction) and ancestor
|
|
16
|
+
* injection use this; ordinary consumers inject and read through `service`
|
|
17
|
+
* instead.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately documented in prose rather than with the internal JSDoc tag:
|
|
20
|
+
* this package emits with `stripInternal`, so that tag would erase this
|
|
21
|
+
* declaration from the public `.d.ts`. It must survive because
|
|
22
|
+
* `findAncestorDatabase` duck-types `element.database` across instances and
|
|
23
|
+
* bootstrap subclasses read it directly.
|
|
17
24
|
*/
|
|
18
25
|
@property({ type: Object, reflect: false })
|
|
19
26
|
database!: Database.Plugin.ToDatabase<P>;
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
|
-
* UI-restricted view of
|
|
23
|
-
*
|
|
24
|
-
*
|
|
29
|
+
* UI-restricted view of the database for rendering. Inject the full database by
|
|
30
|
+
* assigning here (`element.service = db`); reads return the restricted view where
|
|
31
|
+
* every mutator is fire-and-forget `void`.
|
|
25
32
|
*/
|
|
26
33
|
get service(): UIService.FromService<Database.Plugin.ToDatabase<P>> {
|
|
27
34
|
return UIService.restrict(this.database);
|
|
28
35
|
}
|
|
36
|
+
set service(db: Database.Plugin.ToDatabase<P>) {
|
|
37
|
+
this.database = db;
|
|
38
|
+
}
|
|
29
39
|
|
|
30
40
|
constructor() {
|
|
31
41
|
super();
|
|
@@ -37,6 +37,19 @@ class _CountElement extends DatabaseElement<typeof plugin> {
|
|
|
37
37
|
type ServiceType = _CountElement["service"];
|
|
38
38
|
type RawDatabase = Database.Plugin.ToDatabase<typeof plugin>;
|
|
39
39
|
|
|
40
|
+
// 0. `service` is a read/write accessor: the getter returns the restricted view,
|
|
41
|
+
// while the setter accepts the full database (injection). The divergent
|
|
42
|
+
// get/set types are intentional (legal since TS 5.1).
|
|
43
|
+
const _injectFullDatabase = (el: _CountElement, db: RawDatabase): void => {
|
|
44
|
+
el.service = db;
|
|
45
|
+
};
|
|
46
|
+
// A side effect of the divergence: `el.service = el.service` is a type error,
|
|
47
|
+
// since the restricted getter type is not assignable to the full setter type.
|
|
48
|
+
const _rejectRestrictedAssignment = (el: _CountElement): void => {
|
|
49
|
+
// @ts-expect-error restricted view is not assignable back to the full database
|
|
50
|
+
el.service = el.service;
|
|
51
|
+
};
|
|
52
|
+
|
|
40
53
|
// 1. The exposed service type is the UIService-restricted view of the database.
|
|
41
54
|
type _CheckRestricted = Assert<Equal<ServiceType, UIService.FromService<RawDatabase>>>;
|
|
42
55
|
|