@crossworks/app-build 0.500.31 → 0.500.35
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 +2 -2
- package/src/build-runtime.ts +2 -0
- package/src/build.test.ts +22 -0
- package/src/kit.test.ts +47 -2
- package/src/kit.ts +45 -2
- package/src/runtime-exports.fixture.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossworks/app-build",
|
|
3
|
-
"version": "0.500.
|
|
3
|
+
"version": "0.500.35",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@babel/parser": "7.29.9",
|
|
15
15
|
"@dnd-kit/core": "6.3.1",
|
|
16
16
|
"@dnd-kit/sortable": "10.0.0",
|
|
17
|
-
"@mantle/share-ui": "npm:@crossworks/share-ui@0.500.
|
|
17
|
+
"@mantle/share-ui": "npm:@crossworks/share-ui@0.500.35",
|
|
18
18
|
"@tailwindcss/oxide": "^4.3.3",
|
|
19
19
|
"@tanstack/react-table": "9.3.1",
|
|
20
20
|
"@tanstack/react-virtual": "3.14.24",
|
package/src/build-runtime.ts
CHANGED
|
@@ -70,6 +70,7 @@ const ENTRY_SRC: Record<string, string> = {
|
|
|
70
70
|
label: KIT['@/components/ui/label']!,
|
|
71
71
|
badge: KIT['@/components/ui/badge']!,
|
|
72
72
|
separator: KIT['@/components/ui/separator']!,
|
|
73
|
+
loading: KIT['@/components/ui/loading']!,
|
|
73
74
|
host: KIT['@host']!,
|
|
74
75
|
};
|
|
75
76
|
|
|
@@ -87,6 +88,7 @@ export const RUNTIME_SPECIFIERS: Record<string, string> = {
|
|
|
87
88
|
'@/components/ui/label': 'label',
|
|
88
89
|
'@/components/ui/badge': 'badge',
|
|
89
90
|
'@/components/ui/separator': 'separator',
|
|
91
|
+
'@/components/ui/loading': 'loading',
|
|
90
92
|
'@host': 'host',
|
|
91
93
|
};
|
|
92
94
|
|
package/src/build.test.ts
CHANGED
|
@@ -53,6 +53,28 @@ describe('buildApp — happy path', () => {
|
|
|
53
53
|
expect(res.errors).toEqual([]);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
+
it('an app may import the kit Loading by name, and a default import is refused', async () => {
|
|
57
|
+
const named = await buildApp(
|
|
58
|
+
app({
|
|
59
|
+
'App.tsx':
|
|
60
|
+
"import { Loading } from '@/components/ui/loading';\n" +
|
|
61
|
+
'export default function App() { return <Loading label="Loading readings" />; }\n',
|
|
62
|
+
}),
|
|
63
|
+
{ runtimeExports: RT },
|
|
64
|
+
);
|
|
65
|
+
expect(named.errors).toEqual([]);
|
|
66
|
+
expect(named.ok).toBe(true);
|
|
67
|
+
const asDefault = await buildApp(
|
|
68
|
+
app({
|
|
69
|
+
'App.tsx':
|
|
70
|
+
"import Loading from '@/components/ui/loading';\n" +
|
|
71
|
+
'export default function App() { return <Loading />; }\n',
|
|
72
|
+
}),
|
|
73
|
+
{ runtimeExports: RT },
|
|
74
|
+
);
|
|
75
|
+
expect(asDefault.ok).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
56
78
|
it('resolves relative imports, including index files', async () => {
|
|
57
79
|
const src = app({
|
|
58
80
|
'App.tsx':
|
package/src/kit.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { KIT } from './kit';
|
|
3
3
|
|
|
4
|
-
// The @host kit module is a string mirror of packages/
|
|
4
|
+
// The @host kit module is a string mirror of packages/share-ui/src/app-bridge-protocol.ts
|
|
5
5
|
// (the sandbox can't import host code, so the shapes are duplicated by design).
|
|
6
6
|
// These are drift tripwires: if a bridge kind is renamed or dropped on either
|
|
7
7
|
// side, the app-facing API silently stops matching what the host answers.
|
|
@@ -9,7 +9,7 @@ describe('@host kit ↔ bridge protocol mirror', () => {
|
|
|
9
9
|
const HOST = KIT['@host']!;
|
|
10
10
|
|
|
11
11
|
it('exposes the core bridge kinds', () => {
|
|
12
|
-
for (const kind of ['tool.call', 'db.query', 'db.exec']) {
|
|
12
|
+
for (const kind of ['tool.call', 'db.query', 'db.exec', 'db.batch']) {
|
|
13
13
|
expect(HOST).toContain(`kind: '${kind}'`);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
@@ -37,6 +37,51 @@ describe('@host kit ↔ bridge protocol mirror', () => {
|
|
|
37
37
|
await expect(make({})()).rejects.toThrow(/not available/);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
it('a rejected call carries the broker reason, so an app can read err.reason', () => {
|
|
41
|
+
expect(HOST).toContain('{ reason: m.reason }');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('host.db.batch posts its statements and its guard, and no word of its own', () => {
|
|
45
|
+
expect(HOST).toContain("kind: 'db.batch', statements, guard: opts?.guard");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('host.db.batch refuses a misspelt guard, and posts nothing', async () => {
|
|
49
|
+
const start = HOST.indexOf('batch: (statements, opts) => {');
|
|
50
|
+
const end = HOST.indexOf('\n },\n', start);
|
|
51
|
+
const source = HOST.slice(start + 'batch: '.length, end) + '}';
|
|
52
|
+
const posted: unknown[] = [];
|
|
53
|
+
const batch = new Function('post', `return ${source};`)((m: unknown) => {
|
|
54
|
+
posted.push(m);
|
|
55
|
+
return Promise.resolve('sent');
|
|
56
|
+
}) as (s: unknown[], o?: unknown) => Promise<unknown>;
|
|
57
|
+
await expect(batch([], { gaurd: {} })).rejects.toThrow(/gaurd/);
|
|
58
|
+
await expect(batch([], { sql: 'SELECT 1', params: [] })).rejects.toThrow(/params/);
|
|
59
|
+
// The key is right, its value is not: state.gaurd was undefined.
|
|
60
|
+
await expect(batch([], { guard: undefined })).rejects.toThrow(/nothing else/);
|
|
61
|
+
await expect(batch([], true)).rejects.toThrow(/nothing else/);
|
|
62
|
+
expect(posted).toEqual([]);
|
|
63
|
+
await expect(batch([])).resolves.toBe('sent');
|
|
64
|
+
await expect(batch([], { guard: { sql: 'SELECT 1' } })).resolves.toBe('sent');
|
|
65
|
+
expect(posted).toHaveLength(2);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Loading is small, labelled for a screen reader, theme-only and still under reduced motion', () => {
|
|
69
|
+
const LOADING = KIT['@/components/ui/loading']!;
|
|
70
|
+
expect(LOADING).toContain('export function Loading(');
|
|
71
|
+
expect(LOADING).toContain('role="status"');
|
|
72
|
+
expect(LOADING).toContain('sr-only');
|
|
73
|
+
expect(LOADING).toContain('aria-hidden="true"');
|
|
74
|
+
expect(LOADING).toContain('prefers-reduced-motion:reduce');
|
|
75
|
+
expect(LOADING).toContain('bg-primary');
|
|
76
|
+
expect(LOADING).toContain('text-muted-foreground');
|
|
77
|
+
// Never a full-screen state, never a hard-coded colour, no import but the kit's.
|
|
78
|
+
expect(LOADING).not.toMatch(/fixed|absolute|inset-0|min-h-screen|h-screen|#[0-9a-f]{3,6}/i);
|
|
79
|
+
expect([...LOADING.matchAll(/from '([^']+)'/g)].map((m) => m[1])).toEqual([
|
|
80
|
+
'react',
|
|
81
|
+
'@/lib/utils',
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
40
85
|
it('exposes the team-hub namespace with the enumerated hub kinds', () => {
|
|
41
86
|
expect(HOST).toContain("kind: 'hub.get'");
|
|
42
87
|
// All nav intents post the SAME event kind with the target shapes the
|
package/src/kit.ts
CHANGED
|
@@ -142,13 +142,45 @@ export function Separator({ className, orientation = 'horizontal', ...p }) {
|
|
|
142
142
|
}
|
|
143
143
|
`;
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* The app's own loader: the app is on screen and fetches its data. Four level
|
|
147
|
+
* bars, so a person can tell this stage from the host's loader (the orb over
|
|
148
|
+
* the whole frame, before the app shows). Small and inline: it stands where the
|
|
149
|
+
* data will be, and it never covers the screen. Its keyframes ride in a style
|
|
150
|
+
* tag because an app's stylesheet is utilities only (css.ts).
|
|
151
|
+
*/
|
|
152
|
+
const LOADING = `
|
|
153
|
+
import * as React from 'react';
|
|
154
|
+
import { cn } from '@/lib/utils';
|
|
155
|
+
const STYLE =
|
|
156
|
+
'@keyframes mantle-kit-level{0%,100%{transform:scaleY(.3);opacity:.45}50%{transform:scaleY(1);opacity:1}}' +
|
|
157
|
+
'.mantle-kit-level{transform-origin:bottom;animation:mantle-kit-level 900ms ease-in-out infinite}' +
|
|
158
|
+
'@media (prefers-reduced-motion:reduce){.mantle-kit-level{animation:none;transform:scaleY(.7);opacity:.8}}';
|
|
159
|
+
const BARS = [0, 120, 240, 360];
|
|
160
|
+
export function Loading({ label, className, ...p }) {
|
|
161
|
+
return (
|
|
162
|
+
<>
|
|
163
|
+
<style>{STYLE}</style>
|
|
164
|
+
<div role="status" className={cn('inline-flex items-center gap-3 text-sm text-muted-foreground', className)} {...p}>
|
|
165
|
+
<span aria-hidden="true" className="inline-flex h-6 items-end gap-1">
|
|
166
|
+
{BARS.map((delay) => (
|
|
167
|
+
<span key={delay} className="mantle-kit-level h-6 w-1.5 rounded-sm bg-primary" style={{ animationDelay: delay + 'ms' }} />
|
|
168
|
+
))}
|
|
169
|
+
</span>
|
|
170
|
+
{label ? <span>{label}</span> : <span className="sr-only">Loading</span>}
|
|
171
|
+
</div>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
|
|
145
177
|
/**
|
|
146
178
|
* The host bridge — the app's ONLY door to data + storage. Posts typed requests
|
|
147
179
|
* to the parent and awaits a correlated response. The app holds no secrets; the
|
|
148
180
|
* host resolves them server-side. `__mount` (used by the generated entry) wires
|
|
149
181
|
* the React root, an error boundary, the ready signal, and auto-resize.
|
|
150
182
|
*
|
|
151
|
-
* Mirrors
|
|
183
|
+
* Mirrors packages/share-ui/src/app-bridge-protocol.ts — keep the message shapes in sync.
|
|
152
184
|
*/
|
|
153
185
|
const HOST = `
|
|
154
186
|
import * as React from 'react';
|
|
@@ -181,7 +213,7 @@ window.addEventListener('message', (e) => {
|
|
|
181
213
|
const p = pending.get(m.id);
|
|
182
214
|
pending.delete(m.id);
|
|
183
215
|
if (m.ok) p.resolve(m.output);
|
|
184
|
-
else p.reject(new Error(m.error || 'bridge error'));
|
|
216
|
+
else p.reject(Object.assign(new Error(m.error || 'bridge error'), { reason: m.reason }));
|
|
185
217
|
}
|
|
186
218
|
});
|
|
187
219
|
|
|
@@ -223,6 +255,16 @@ export const host = {
|
|
|
223
255
|
db: {
|
|
224
256
|
query: (sql, params) => post({ kind: 'db.query', sql, params: params ?? [] }),
|
|
225
257
|
exec: (sql, params) => post({ kind: 'db.exec', sql, params: params ?? [] }),
|
|
258
|
+
batch: (statements, opts) => {
|
|
259
|
+
// A misspelt or empty guard must not run the writes with no check.
|
|
260
|
+
const fine =
|
|
261
|
+
opts === undefined ||
|
|
262
|
+
(opts && typeof opts === 'object' && Object.keys(opts).every((k) => k === 'guard') && (!('guard' in opts) || opts.guard));
|
|
263
|
+
if (!fine) {
|
|
264
|
+
return Promise.reject(new Error('host.db.batch takes { guard: { sql, params } } and nothing else, not: ' + JSON.stringify(opts)));
|
|
265
|
+
}
|
|
266
|
+
return post({ kind: 'db.batch', statements, guard: opts?.guard });
|
|
267
|
+
},
|
|
226
268
|
},
|
|
227
269
|
ui: {
|
|
228
270
|
resize: (h) => window.parent.postMessage({ v: 1, kind: 'resize', height: h }, '*'),
|
|
@@ -313,6 +355,7 @@ export const KIT: Record<string, string> = {
|
|
|
313
355
|
'@/components/ui/label': LABEL,
|
|
314
356
|
'@/components/ui/badge': BADGE,
|
|
315
357
|
'@/components/ui/separator': SEPARATOR,
|
|
358
|
+
'@/components/ui/loading': LOADING,
|
|
316
359
|
'@host': HOST,
|
|
317
360
|
};
|
|
318
361
|
|
|
@@ -27,6 +27,7 @@ export const RUNTIME_EXPORTS_FIXTURE: Record<string, string[]> = {
|
|
|
27
27
|
'@/components/ui/label': ['Label'],
|
|
28
28
|
'@/components/ui/badge': ['Badge'],
|
|
29
29
|
'@/components/ui/separator': ['Separator'],
|
|
30
|
+
'@/components/ui/loading': ['Loading'],
|
|
30
31
|
'@host': ['__mount', 'host'],
|
|
31
32
|
'motion/react': ['motion', 'AnimatePresence', 'animate', 'useAnimate', 'useReducedMotion'],
|
|
32
33
|
'@tanstack/react-table': [
|