@itrocks/framework 1.0.0 → 1.0.2
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/README.md +2 -1
- package/cjs/property-select-provider.js +3 -2
- package/cjs/property-select.d.ts +14 -0
- package/cjs/property-select.js +57 -2
- package/docs/property-select.md +8 -3
- package/package.json +1 -1
- package/property-select-list.js +6 -2
- package/property-select-metadata.d.ts +6 -0
- package/property-select-metadata.js +11 -0
package/README.md
CHANGED
|
@@ -319,6 +319,7 @@ The browser `property-select-metadata.js` entry provides
|
|
|
319
319
|
Bootstrap binds list state transactions to the configured HTTP session store. Each list article receives its router
|
|
320
320
|
identity; selector state and list column settings share durable session coordination while retaining separate
|
|
321
321
|
namespaces.
|
|
322
|
-
The
|
|
322
|
+
The list HTML includes authorised selector metadata, advice, template and session state for mounting without
|
|
323
|
+
additional application requests.
|
|
323
324
|
A stable configured `session.secret` is needed to recognise existing cookies after a server restart.
|
|
324
325
|
See [property selector integration](docs/property-select.md) for route-backed metadata and access.
|
|
@@ -7,6 +7,7 @@ const composition_1 = require("@itrocks/composition");
|
|
|
7
7
|
const composition_2 = require("@itrocks/composition");
|
|
8
8
|
const property_select_1 = require("@itrocks/property-select");
|
|
9
9
|
const route_1 = require("@itrocks/route");
|
|
10
|
+
const translate_1 = require("@itrocks/translate");
|
|
10
11
|
const node_crypto_1 = require("node:crypto");
|
|
11
12
|
const reflect_class_1 = require("./reflect-class");
|
|
12
13
|
const reflect_property_1 = require("./reflect-property");
|
|
@@ -93,14 +94,14 @@ class ReflectionMetadataProvider {
|
|
|
93
94
|
}
|
|
94
95
|
aborted(signal);
|
|
95
96
|
const { displayOf: classDisplay } = require('@itrocks/class-view');
|
|
96
|
-
return { label: classDisplay(target) || target.name, path, properties, type: typeId(target) };
|
|
97
|
+
return { label: (0, translate_1.tr)(classDisplay(target) || target.name), path, properties, type: typeId(target) };
|
|
97
98
|
}
|
|
98
99
|
description(context, name, path, names) {
|
|
99
100
|
const { displayOf } = require('@itrocks/property-view');
|
|
100
101
|
const property = new reflect_property_1.ReflectProperty(context, name);
|
|
101
102
|
const fact = property.relation;
|
|
102
103
|
const description = {
|
|
103
|
-
kind: fact ? 'relation' : 'terminal', label: displayOf(context.type, name) || name,
|
|
104
|
+
kind: fact ? 'relation' : 'terminal', label: (0, translate_1.tr)(displayOf(context.type, name) || name),
|
|
104
105
|
name, order: names.indexOf(name), path
|
|
105
106
|
};
|
|
106
107
|
if (!fact)
|
package/cjs/property-select.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Request } from '@itrocks/action-request';
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
|
+
import { ObjectContext } from '@itrocks/property-select';
|
|
3
4
|
import { RootId } from '@itrocks/property-select';
|
|
5
|
+
import { StateRecord } from '@itrocks/property-select';
|
|
4
6
|
import { ReflectionMetadataProvider } from './property-select-provider';
|
|
5
7
|
export type MetadataRoot = {
|
|
6
8
|
advice?: readonly string[];
|
|
@@ -17,6 +19,18 @@ export type { MetadataErrorCode } from './property-select-provider';
|
|
|
17
19
|
export { ReflectionMetadataProvider } from './property-select-provider';
|
|
18
20
|
export declare function bindPropertySelect(): void;
|
|
19
21
|
export declare function createMetadataProvider(request: Request, root?: RootId): ReflectionMetadataProvider;
|
|
22
|
+
/** Prepare only the contexts used by restoration, suggestions and the bounded saved search. */
|
|
23
|
+
export declare function metadataBootstrap(request: Request, root: RootId, usedPaths: string[], record: StateRecord): Promise<{
|
|
24
|
+
contexts: ObjectContext[];
|
|
25
|
+
errors: [string, string][];
|
|
26
|
+
record: {
|
|
27
|
+
state: import("@itrocks/property-select").SelectorState;
|
|
28
|
+
revision: number;
|
|
29
|
+
};
|
|
30
|
+
template: string;
|
|
31
|
+
advice: readonly string[];
|
|
32
|
+
version: string;
|
|
33
|
+
}>;
|
|
20
34
|
export declare function metadataConfiguration(request: Request, root: RootId): Promise<{
|
|
21
35
|
advice: readonly string[];
|
|
22
36
|
version: string;
|
package/cjs/property-select.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReflectionMetadataProvider = exports.MetadataError = void 0;
|
|
4
4
|
exports.bindPropertySelect = bindPropertySelect;
|
|
5
5
|
exports.createMetadataProvider = createMetadataProvider;
|
|
6
|
+
exports.metadataBootstrap = metadataBootstrap;
|
|
6
7
|
exports.metadataConfiguration = metadataConfiguration;
|
|
7
8
|
exports.propertySelectDependsOn = propertySelectDependsOn;
|
|
8
9
|
const action_1 = require("@itrocks/action");
|
|
@@ -12,7 +13,9 @@ const fastify_1 = require("@itrocks/fastify");
|
|
|
12
13
|
const list_1 = require("@itrocks/list");
|
|
13
14
|
const selector_state_1 = require("@itrocks/list/selector-state");
|
|
14
15
|
const property_select_1 = require("@itrocks/property-select");
|
|
16
|
+
const property_select_2 = require("@itrocks/property-select");
|
|
15
17
|
const route_1 = require("@itrocks/route");
|
|
18
|
+
const promises_1 = require("node:fs/promises");
|
|
16
19
|
const property_select_provider_1 = require("./property-select-provider");
|
|
17
20
|
const property_select_provider_2 = require("./property-select-provider");
|
|
18
21
|
const dependencies = { advice: () => [], authorise: () => true };
|
|
@@ -35,7 +38,10 @@ function bindPropertySelect() {
|
|
|
35
38
|
return { authorise: async () => { } };
|
|
36
39
|
const provider = createMetadataProvider(request, root);
|
|
37
40
|
await provider.context(root, '');
|
|
38
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
authorise: async (path) => { await provider.resolve(root, path); },
|
|
43
|
+
bootstrap: (paths, state) => metadataBootstrap(request, root, paths, state), root
|
|
44
|
+
};
|
|
39
45
|
} });
|
|
40
46
|
// Loaded after composition; action classes never trigger the framework bootstrap.
|
|
41
47
|
route_1.routes.add('/property-select/template', '@itrocks/framework/property-select-actions:PropertySelectTemplate');
|
|
@@ -48,13 +54,62 @@ function createMetadataProvider(request, root = request.route) {
|
|
|
48
54
|
const roots = type ? { [root]: { type } } : {};
|
|
49
55
|
return new property_select_provider_2.ReflectionMetadataProvider(roots, (root, path) => dependencies.authorise(request, root, path));
|
|
50
56
|
}
|
|
57
|
+
/** Prepare only the contexts used by restoration, suggestions and the bounded saved search. */
|
|
58
|
+
async function metadataBootstrap(request, root, usedPaths, record) {
|
|
59
|
+
const provider = createMetadataProvider(request, root);
|
|
60
|
+
const configuration = await metadataConfiguration(request, root);
|
|
61
|
+
const contexts = new Map();
|
|
62
|
+
const errors = new Map();
|
|
63
|
+
const selector = new property_select_1.PropertySelect({
|
|
64
|
+
advice: configuration.advice, root, stateKey: root, stateMode: 'session', usedPaths,
|
|
65
|
+
metadata: {
|
|
66
|
+
context: async (root, path, signal) => {
|
|
67
|
+
try {
|
|
68
|
+
const context = await provider.context(root, path, signal);
|
|
69
|
+
contexts.set(path, context);
|
|
70
|
+
return context;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
errors.set(path, error instanceof Error ? error.message : 'Metadata unavailable');
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
resolve: (root, path, signal) => provider.resolve(root, path, signal)
|
|
78
|
+
},
|
|
79
|
+
stateStore: {
|
|
80
|
+
read: async () => record,
|
|
81
|
+
remove: async () => { throw new Error('Read-only bootstrap'); },
|
|
82
|
+
write: async () => { throw new Error('Read-only bootstrap'); }
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
await selector.mount();
|
|
87
|
+
if (selector.search.status === 'loading')
|
|
88
|
+
await new Promise(resolve => {
|
|
89
|
+
const unsubscribe = selector.subscribe(() => {
|
|
90
|
+
if (selector.search.status === 'loading')
|
|
91
|
+
return;
|
|
92
|
+
unsubscribe();
|
|
93
|
+
resolve();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
...configuration, contexts: [...contexts.values()], errors: [...errors],
|
|
98
|
+
record: { ...record, state: selector.snapshot() },
|
|
99
|
+
template: await (0, promises_1.readFile)(require.resolve('@itrocks/property-select/front/property-select.html'), 'utf8')
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
selector.dispose();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
51
106
|
async function metadataConfiguration(request, root) {
|
|
52
107
|
const provider = createMetadataProvider(request, root);
|
|
53
108
|
await provider.context(root, '');
|
|
54
109
|
const advice = [];
|
|
55
110
|
for (const path of await dependencies.advice(request, root)) {
|
|
56
111
|
try {
|
|
57
|
-
const canonical = (0,
|
|
112
|
+
const canonical = (0, property_select_2.normalisePath)(path);
|
|
58
113
|
if (!canonical)
|
|
59
114
|
continue;
|
|
60
115
|
const description = await provider.resolve(root, canonical);
|
package/docs/property-select.md
CHANGED
|
@@ -89,7 +89,8 @@ const context = await metadata.context('/invoice', '')
|
|
|
89
89
|
const configuration = await metadata.configuration('/invoice')
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
Options accept `endpoint` (default `/property-select`)
|
|
92
|
+
Options accept `endpoint` (default `/property-select`), a substitutable `fetch` function and an optional
|
|
93
|
+
`initial: { root, contexts, errors }` snapshot. The snapshot supplies authorised metadata for the current list response.
|
|
93
94
|
Requests use same-origin credentials and forward `AbortSignal`. A cancelled response is also checked after JSON
|
|
94
95
|
parsing. The selector's generation checks discard obsolete responses even when the network cannot be interrupted.
|
|
95
96
|
Session restoration, rendered controls, searching and host column integration belong to their respective adapters.
|
|
@@ -121,5 +122,9 @@ The `/property-select/template/html` action serves only the selector's exported
|
|
|
121
122
|
arbitrary HTML asset access. The view's optional template URL allows this transport while standalone hosts retain the
|
|
122
123
|
adjacent static template. Neither the view nor list imports server framework code.
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
The list access adapter supplies a request-scoped bootstrap. `metadataBootstrap(request, root, usedPaths, record)`
|
|
126
|
+
prepares the contexts needed by the restored branch, suggestions and bounded saved search, together with the selector
|
|
127
|
+
template and validated state. No business records are read. List adds the authoritative session revision and generation
|
|
128
|
+
to its encoded `data-selector-bootstrap` attribute. The browser consumes this response without configuration,
|
|
129
|
+
metadata, template or state requests on mount. New navigation and searches can fetch additional contexts lazily.
|
|
130
|
+
Column removal and reordering reuse existing contexts and cells; only configuration persistence requires a request.
|
package/package.json
CHANGED
package/property-select-list.js
CHANGED
|
@@ -11,10 +11,14 @@ async function activate(entry) {
|
|
|
11
11
|
return;
|
|
12
12
|
loadCss('/@itrocks/property-select/front/property-select.css');
|
|
13
13
|
loadCss('/@itrocks/table/column-add.css');
|
|
14
|
-
const
|
|
14
|
+
const initial = entry.article.dataset.selectorBootstrap
|
|
15
|
+
? JSON.parse(decodeURIComponent(entry.article.dataset.selectorBootstrap)) : undefined;
|
|
16
|
+
const metadata = new HttpMetadataProvider({
|
|
17
|
+
initial: initial && { ...initial, root: entry.article.dataset.propertyRoot }
|
|
18
|
+
});
|
|
15
19
|
let integration;
|
|
16
20
|
try {
|
|
17
|
-
const configuration = await metadata.configuration(entry.article.dataset.propertyRoot);
|
|
21
|
+
const configuration = initial ?? await metadata.configuration(entry.article.dataset.propertyRoot);
|
|
18
22
|
if (!entry.article.isConnected || mounted.has(entry.article))
|
|
19
23
|
return;
|
|
20
24
|
integration = new ListPropertySelect(entry.article, {
|
|
@@ -4,10 +4,16 @@ import type { PropertyDescription } from '@itrocks/property-select/property-sele
|
|
|
4
4
|
export type MetadataTransportOptions = {
|
|
5
5
|
endpoint?: string;
|
|
6
6
|
fetch?: typeof fetch;
|
|
7
|
+
initial?: {
|
|
8
|
+
contexts: ObjectContext[];
|
|
9
|
+
errors: [string, string][];
|
|
10
|
+
root: string;
|
|
11
|
+
};
|
|
7
12
|
};
|
|
8
13
|
export declare class HttpMetadataProvider implements MetadataProvider {
|
|
9
14
|
private readonly endpoint;
|
|
10
15
|
private readonly fetcher;
|
|
16
|
+
private readonly initial?;
|
|
11
17
|
constructor(options?: MetadataTransportOptions);
|
|
12
18
|
configuration(root: string, signal?: AbortSignal): Promise<{
|
|
13
19
|
advice: readonly string[];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export class HttpMetadataProvider {
|
|
2
2
|
endpoint;
|
|
3
3
|
fetcher;
|
|
4
|
+
initial;
|
|
4
5
|
constructor(options = {}) {
|
|
6
|
+
this.initial = options.initial;
|
|
5
7
|
this.endpoint = options.endpoint ?? '/property-select';
|
|
6
8
|
this.fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
7
9
|
}
|
|
@@ -9,6 +11,15 @@ export class HttpMetadataProvider {
|
|
|
9
11
|
return this.request('configuration', root, '', signal);
|
|
10
12
|
}
|
|
11
13
|
context(root, path, signal) {
|
|
14
|
+
signal?.throwIfAborted();
|
|
15
|
+
if (this.initial?.root === root) {
|
|
16
|
+
const context = this.initial.contexts.find(context => context.path === path);
|
|
17
|
+
if (context)
|
|
18
|
+
return Promise.resolve(structuredClone(context));
|
|
19
|
+
const error = this.initial.errors.find(([failed]) => failed === path);
|
|
20
|
+
if (error)
|
|
21
|
+
return Promise.reject(new Error(error[1]));
|
|
22
|
+
}
|
|
12
23
|
return this.request('context', root, path, signal);
|
|
13
24
|
}
|
|
14
25
|
async request(operation, root, path, signal) {
|