@elaraai/e3-cloud-ui 0.0.0-stage → 1.0.90

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.
Files changed (63) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +256 -2
  3. package/dist/src/authoring/app.d.ts +84 -0
  4. package/dist/src/authoring/app.d.ts.map +1 -0
  5. package/dist/src/authoring/app.js +38 -0
  6. package/dist/src/authoring/app.js.map +1 -0
  7. package/dist/src/authoring/link.d.ts +206 -0
  8. package/dist/src/authoring/link.d.ts.map +1 -0
  9. package/dist/src/authoring/link.js +114 -0
  10. package/dist/src/authoring/link.js.map +1 -0
  11. package/dist/src/authoring/page.d.ts +115 -0
  12. package/dist/src/authoring/page.d.ts.map +1 -0
  13. package/dist/src/authoring/page.js +113 -0
  14. package/dist/src/authoring/page.js.map +1 -0
  15. package/dist/src/browser.d.ts +19 -0
  16. package/dist/src/browser.d.ts.map +1 -0
  17. package/dist/src/browser.js +19 -0
  18. package/dist/src/browser.js.map +1 -0
  19. package/dist/src/build.d.ts +67 -0
  20. package/dist/src/build.d.ts.map +1 -0
  21. package/dist/src/build.js +228 -0
  22. package/dist/src/build.js.map +1 -0
  23. package/dist/src/check/check.d.ts +46 -0
  24. package/dist/src/check/check.d.ts.map +1 -0
  25. package/dist/src/check/check.js +342 -0
  26. package/dist/src/check/check.js.map +1 -0
  27. package/dist/src/check/index.d.ts +19 -0
  28. package/dist/src/check/index.d.ts.map +1 -0
  29. package/dist/src/check/index.js +19 -0
  30. package/dist/src/check/index.js.map +1 -0
  31. package/dist/src/check/package-view.d.ts +85 -0
  32. package/dist/src/check/package-view.d.ts.map +1 -0
  33. package/dist/src/check/package-view.js +87 -0
  34. package/dist/src/check/package-view.js.map +1 -0
  35. package/dist/src/check/scan.d.ts +99 -0
  36. package/dist/src/check/scan.d.ts.map +1 -0
  37. package/dist/src/check/scan.js +223 -0
  38. package/dist/src/check/scan.js.map +1 -0
  39. package/dist/src/check/types-equal.d.ts +31 -0
  40. package/dist/src/check/types-equal.d.ts.map +1 -0
  41. package/dist/src/check/types-equal.js +35 -0
  42. package/dist/src/check/types-equal.js.map +1 -0
  43. package/dist/src/index.d.ts +28 -0
  44. package/dist/src/index.d.ts.map +1 -0
  45. package/dist/src/index.js +28 -0
  46. package/dist/src/index.js.map +1 -0
  47. package/dist/src/runtime.d.ts +7 -0
  48. package/dist/src/runtime.d.ts.map +1 -0
  49. package/dist/src/runtime.js +7 -0
  50. package/dist/src/runtime.js.map +1 -0
  51. package/dist/src/types.d.ts +7169 -0
  52. package/dist/src/types.d.ts.map +1 -0
  53. package/dist/src/types.js +156 -0
  54. package/dist/src/types.js.map +1 -0
  55. package/dist/test/acme.examples.d.ts +99 -0
  56. package/dist/test/acme.examples.d.ts.map +1 -0
  57. package/dist/test/acme.examples.js +100 -0
  58. package/dist/test/acme.examples.js.map +1 -0
  59. package/dist/test/pages.examples.d.ts +33 -0
  60. package/dist/test/pages.examples.d.ts.map +1 -0
  61. package/dist/test/pages.examples.js +127 -0
  62. package/dist/test/pages.examples.js.map +1 -0
  63. package/package.json +71 -3
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * The build: an app into its bundle.
7
+ *
8
+ * `buildApp` compiles each page's body to IR, reads its manifest, writes and
9
+ * record uses as e3-ui does (`deriveManifest`, `deriveUiAccess`), embeds the package
10
+ * exactly as `e3.export` writes it, stamps the e3 release that exported it,
11
+ * and runs the checks against that package, so a bundle that could
12
+ * deploy nowhere is refused here. `exportApp` writes the bundle as beast2.
13
+ *
14
+ * Node only: the package's zip is written by e3's export, through a file.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
19
+ import { tmpdir } from 'node:os';
20
+ import { join } from 'node:path';
21
+ import { inflateRawSync } from 'node:zlib';
22
+ import { StringType, decodeBeast2For, encodeBeast2For, none, some, variant } from '@elaraai/east';
23
+ import { export as exportPackage } from '@elaraai/e3';
24
+ import { appProblemLines } from '@elaraai/e3-cloud-types';
25
+ import { AppBundleType, AppType, } from './types.js';
26
+ import { checkApp } from './check/check.js';
27
+ import { readPackageView } from './check/package-view.js';
28
+ import { scanPage } from './check/scan.js';
29
+ /** An app the build refuses, with every problem. */
30
+ export class AppBuildError extends Error {
31
+ /** Why the app doesn't build */
32
+ problems;
33
+ constructor(app, pkg, problems) {
34
+ super([`Build refused: app ${app} doesn't fit ${pkg}`, ...appProblemLines(problems, { app, package: pkg }, ' ')].join('\n'));
35
+ this.name = 'AppBuildError';
36
+ this.problems = problems;
37
+ }
38
+ }
39
+ /**
40
+ * Reads a zip's entries, as e3's export writes one: stored or deflated, with
41
+ * a central directory and no ZIP64.
42
+ */
43
+ function readZip(zip) {
44
+ const view = new DataView(zip.buffer, zip.byteOffset, zip.byteLength);
45
+ let eocd = -1;
46
+ for (let i = zip.length - 22; i >= Math.max(0, zip.length - 22 - 0xffff); i--) {
47
+ if (view.getUint32(i, true) === 0x06054b50) {
48
+ eocd = i;
49
+ break;
50
+ }
51
+ }
52
+ if (eocd < 0)
53
+ throw new Error("the package's zip has no central directory");
54
+ const count = view.getUint16(eocd + 10, true);
55
+ let at = view.getUint32(eocd + 16, true);
56
+ if (at === 0xffffffff)
57
+ throw new Error("the package's zip is a ZIP64, which the build doesn't read");
58
+ const decoder = new TextDecoder();
59
+ const entries = new Map();
60
+ for (let n = 0; n < count; n++) {
61
+ if (view.getUint32(at, true) !== 0x02014b50)
62
+ throw new Error("the package's zip has a malformed central directory");
63
+ const method = view.getUint16(at + 10, true);
64
+ const compressed = view.getUint32(at + 20, true);
65
+ const nameLength = view.getUint16(at + 28, true);
66
+ const extraLength = view.getUint16(at + 30, true);
67
+ const commentLength = view.getUint16(at + 32, true);
68
+ const local = view.getUint32(at + 42, true);
69
+ const name = decoder.decode(zip.subarray(at + 46, at + 46 + nameLength));
70
+ const dataAt = local + 30 + view.getUint16(local + 26, true) + view.getUint16(local + 28, true);
71
+ const data = zip.subarray(dataAt, dataAt + compressed);
72
+ entries.set(name, method === 0 ? data : new Uint8Array(inflateRawSync(data)));
73
+ at += 46 + nameLength + extraLength + commentLength;
74
+ }
75
+ return entries;
76
+ }
77
+ const decodeString = decodeBeast2For(StringType);
78
+ /** Reads a package zip's objects, by hash, as e3's export lays them out. */
79
+ function zipObjectReader(entries) {
80
+ return (hash) => {
81
+ const object = entries.get(`objects/${hash.slice(0, 2)}/${hash.slice(2)}.beast2`);
82
+ return object === undefined ? Promise.reject(new Error(`the package's zip lacks object ${hash}`)) : Promise.resolve(object);
83
+ };
84
+ }
85
+ /** The Font Awesome solid icons, by every name they answer to, each to its own name. */
86
+ let solidIcons;
87
+ /** Font Awesome's solid icons, by name and alias. */
88
+ function fontAwesomeSolid() {
89
+ solidIcons ??= import('@fortawesome/free-solid-svg-icons').then((module) => {
90
+ const names = new Map();
91
+ for (const value of Object.values(module.fas)) {
92
+ const definition = value;
93
+ names.set(definition.iconName, definition.iconName);
94
+ for (const alias of definition.icon[2])
95
+ if (typeof alias === 'string')
96
+ names.set(alias, definition.iconName);
97
+ }
98
+ return names;
99
+ });
100
+ return solidIcons;
101
+ }
102
+ /** A page as the app stores it: its IR, manifest, writes and record uses. */
103
+ function pageValue(page, icons) {
104
+ const icon = page.icon === undefined ? none : some({ prefix: 'fas', name: icons.get(page.icon) ?? page.icon });
105
+ const parent = page.parent === undefined ? none : some(page.parent.name);
106
+ if (page.body.kind === 'task') {
107
+ return {
108
+ name: page.name, title: page.title, icon, parent,
109
+ body: variant('task', page.body.task.name),
110
+ bindings: { paths: [], functions: [], records: [], pages: [] },
111
+ writes: [],
112
+ recordUses: [],
113
+ };
114
+ }
115
+ const ir = page.body.build().toIR().ir;
116
+ // e3-ui's reading of the body, which the checks read again at every deploy
117
+ const scan = scanPage(ir);
118
+ return {
119
+ name: page.name, title: page.title, icon, parent,
120
+ body: variant('east', ir),
121
+ bindings: scan.manifest,
122
+ writes: [...scan.writes],
123
+ recordUses: [...scan.recordUses],
124
+ };
125
+ }
126
+ /**
127
+ * Builds an app into its bundle: the app, and its package as `e3.export`
128
+ * writes it.
129
+ *
130
+ * @param app - The app
131
+ * @param options - Function manifests for the package's export
132
+ * @returns The bundle
133
+ * @throws {AppBuildError} When the app doesn't fit its own package, or isn't a
134
+ * well-formed app, naming every problem
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * import ops from './src/apps/ops.js';
139
+ * const bundle = await buildApp(ops);
140
+ * ```
141
+ */
142
+ export async function buildApp(app, options = {}) {
143
+ const { config } = app;
144
+ const icons = await fontAwesomeSolid();
145
+ // The package, exactly as e3's export writes it
146
+ const dir = await mkdtemp(join(tmpdir(), 'e3-cloud-ui-build-'));
147
+ let zip;
148
+ try {
149
+ const path = join(dir, 'package.zip');
150
+ await exportPackage(config.package, path, options);
151
+ zip = new Uint8Array(await readFile(path));
152
+ }
153
+ finally {
154
+ await rm(dir, { recursive: true, force: true });
155
+ }
156
+ const entries = readZip(zip);
157
+ const release = entries.get('release.beast2');
158
+ const ref = entries.get(`packages/${config.package.name}/${config.package.version}.beast2`);
159
+ if (release === undefined || ref === undefined)
160
+ throw new Error(`the package's zip lacks its release or its ref`);
161
+ const pkg = { name: config.package.name, version: config.package.version, hash: decodeString(ref) };
162
+ const menu = config.menu.map((group) => ({
163
+ label: group.label === null ? none : some(group.label),
164
+ pages: group.pages.map((page) => page.name),
165
+ }));
166
+ const value = {
167
+ name: app.name,
168
+ title: config.title,
169
+ logo: config.logo === undefined ? none : some(config.logo),
170
+ home: config.home.name,
171
+ menu,
172
+ pages: config.pages.map((page) => pageValue(page, icons)),
173
+ package: pkg,
174
+ builtWith: decodeString(release),
175
+ };
176
+ const view = await readPackageView(zipObjectReader(entries), pkg);
177
+ const iconNames = new Set([...icons.keys()].map((name) => `fas:${name}`));
178
+ const problems = checkApp(value, view, { e3Version: null, icons: iconNames });
179
+ if (problems.length > 0)
180
+ throw new AppBuildError(app.name, `${pkg.name}@${pkg.version}`, problems);
181
+ return { app: value, package: zip };
182
+ }
183
+ const encodeBundle = encodeBeast2For(AppBundleType);
184
+ const decodeBundle = decodeBeast2For(AppBundleType);
185
+ const encodeApp = encodeBeast2For(AppType);
186
+ /**
187
+ * Builds an app and writes its bundle to a file, as beast2.
188
+ *
189
+ * @param app - The app
190
+ * @param path - Where to write the bundle
191
+ * @param options - Function manifests for the package's export
192
+ * @returns The bundle
193
+ * @throws {AppBuildError} When the app doesn't build
194
+ */
195
+ export async function exportApp(app, path, options = {}) {
196
+ const bundle = await buildApp(app, options);
197
+ await writeFile(path, encodeBundle(bundle));
198
+ return bundle;
199
+ }
200
+ /**
201
+ * Reads a bundle `exportApp` wrote.
202
+ *
203
+ * @param bytes - The bundle's bytes
204
+ * @returns The bundle
205
+ */
206
+ export function decodeAppBundle(bytes) {
207
+ return decodeBundle(bytes);
208
+ }
209
+ /**
210
+ * What the checks need of a bundle's package, read from its zip: what the
211
+ * build checks the app against.
212
+ *
213
+ * @param bundle - The bundle
214
+ * @returns Its package's view
215
+ */
216
+ export async function bundlePackageView(bundle) {
217
+ return readPackageView(zipObjectReader(readZip(bundle.package)), bundle.app.package);
218
+ }
219
+ /**
220
+ * An app as the object an app deploy uploads: the bundle without its package.
221
+ *
222
+ * @param app - The app
223
+ * @returns Its beast2 bytes
224
+ */
225
+ export function encodeAppObject(app) {
226
+ return encodeApp(app);
227
+ }
228
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,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,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IACnG,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AACtC,CAAC;AAED,MAAM,YAAY,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;AACpD,MAAM,YAAY,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;AACpD,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,IAAY,EAAE,UAA2B,EAAE;IACtF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAiB;IACvD,OAAO,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACvF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAQ;IACtC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ import { type AppProblem } from '@elaraai/e3-cloud-types';
6
+ import { type App, type Page } from '../types.js';
7
+ import { PageScanError, type PageScan } from './scan.js';
8
+ import { type PackageView } from './package-view.js';
9
+ /** What the checks hold an app to, beyond its package. */
10
+ export interface CheckPlatform {
11
+ /**
12
+ * The e3 release the app must have been built with: the platform's
13
+ * `E3_VERSION`, or the one a bundle is staged for. Null at the
14
+ * app's own build, where there is no platform.
15
+ */
16
+ readonly e3Version: string | null;
17
+ /**
18
+ * The icon names an icon may have, `prefix:name` (`fas:gauge-high`). The
19
+ * build gives Font Awesome's solid set; without it icons aren't checked.
20
+ */
21
+ readonly icons?: ReadonlySet<string>;
22
+ }
23
+ /** A page's scan, or why it can't be scanned. */
24
+ export declare function pageScan(page: Page): PageScan | PageScanError;
25
+ /**
26
+ * Whether an app is a well-formed app, whatever package it runs against: its
27
+ * names, pages, home, menu, parents, links, icons and logo.
28
+ *
29
+ * @param app - The app
30
+ * @param platform - The icon names an icon may have, if they are checked
31
+ * @returns Its problems; none for a well-formed app
32
+ */
33
+ export declare function validateApp(app: App, platform?: Pick<CheckPlatform, 'icons'>): AppProblem[];
34
+ /**
35
+ * Whether an app fits a package: the one function an app deploy, a
36
+ * workspace deploy or removal, a release, a copy and the app's own build
37
+ * run.
38
+ *
39
+ * @param app - The app
40
+ * @param pkg - What the checks need of the package it would run against
41
+ * @param platform - The e3 release it must have been built with, and the icon
42
+ * names an icon may have
43
+ * @returns Its problems, each once; none when it fits
44
+ */
45
+ export declare function checkApp(app: App, pkg: PackageView, platform: CheckPlatform): AppProblem[];
46
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../src/check/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAsC,KAAK,GAAG,EAAE,KAAK,IAAI,EAAkB,MAAM,aAAa,CAAC;AACtG,OAAO,EAAE,aAAa,EAAyB,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG3E,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACtC;AAKD,iDAAiD;AACjD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ,GAAG,aAAa,CAY7D;AA8DD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAM,GAAG,UAAU,EAAE,CAuF/F;AAuFD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,GAAG,UAAU,EAAE,CA4B1F"}
@@ -0,0 +1,342 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * The app checks: whether an app fits a package, as one pure function
7
+ * every path runs.
8
+ *
9
+ * Fail loudly: an app deploy is refused unless its
10
+ * workspace's package provides everything the app binds, with the same types,
11
+ * and a workspace deploy or removal that would break an app is refused. The
12
+ * app's build runs the same check against its own package, so a bundle that
13
+ * could deploy nowhere is refused before it leaves the author's machine. Every
14
+ * problem is an East value ({@link AppProblem}), named well enough to fix.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { PatchType, fromEastTypeValue, none, printFor, some, toEastTypeValue, variant, } from '@elaraai/east';
19
+ import { nameProblem } from '@elaraai/e3-types';
20
+ import { AppProblemType } from '@elaraai/e3-cloud-types';
21
+ import { APP_LOGO_MAX_BYTES, pageParamsType } from '../types.js';
22
+ import { PageScanError, scanPage, treePathKey } from './scan.js';
23
+ import { indexWindowTypeValue } from './package-view.js';
24
+ import { typeListsEqual, typeValuesEqual } from './types-equal.js';
25
+ /** A page's scan, once per page. */
26
+ const scans = new WeakMap();
27
+ /** A page's scan, or why it can't be scanned. */
28
+ export function pageScan(page) {
29
+ let scan = scans.get(page);
30
+ if (scan === undefined) {
31
+ try {
32
+ scan = scanPage(page.body.value);
33
+ }
34
+ catch (err) {
35
+ if (!(err instanceof PageScanError))
36
+ throw err;
37
+ scan = err;
38
+ }
39
+ scans.set(page, scan);
40
+ }
41
+ return scan;
42
+ }
43
+ /** Whether two lists of names hold the same names. */
44
+ function sameNames(a, b) {
45
+ const sa = new Set(a);
46
+ return sa.size === new Set(b).size && b.every((name) => sa.has(name));
47
+ }
48
+ /** Whether two lists of paths hold the same paths. */
49
+ function samePaths(a, b) {
50
+ return sameNames(a.map(treePathKey), b.map(treePathKey));
51
+ }
52
+ /** Whether a page's stored record uses are its body's. */
53
+ function sameRecordUses(a, b) {
54
+ if (a.length !== b.length)
55
+ return false;
56
+ const byRecord = new Map(b.map((use) => [use.record, use]));
57
+ return a.every((use) => {
58
+ const other = byRecord.get(use.record);
59
+ return other !== undefined && sameNames(use.mutations, other.mutations) && sameNames(use.indexes, other.indexes);
60
+ });
61
+ }
62
+ /** What differs between a page's stored manifest and what its body binds, or null when nothing does. */
63
+ function manifestDifference(page, scan) {
64
+ const stored = page.bindings;
65
+ if (!samePaths(stored.paths, scan.manifest.paths))
66
+ return 'its datasets';
67
+ if (!sameNames(stored.functions, scan.manifest.functions))
68
+ return 'its functions';
69
+ if (!sameNames(stored.records, scan.manifest.records))
70
+ return 'its records';
71
+ if (!samePaths(stored.pages, scan.manifest.pages))
72
+ return 'its paged sources';
73
+ if (!samePaths(page.writes, scan.writes))
74
+ return 'its writes';
75
+ if (!sameRecordUses(page.recordUses, scan.recordUses))
76
+ return 'its record uses';
77
+ return null;
78
+ }
79
+ /** Whether a logo's bytes are a PNG, JPEG, WebP or SVG. */
80
+ function logoKind(bytes) {
81
+ const at = (i) => bytes[i];
82
+ if (at(0) === 0x89 && at(1) === 0x50 && at(2) === 0x4e && at(3) === 0x47)
83
+ return 'png';
84
+ if (at(0) === 0xff && at(1) === 0xd8 && at(2) === 0xff)
85
+ return 'jpeg';
86
+ if (at(0) === 0x52 && at(1) === 0x49 && at(2) === 0x46 && at(3) === 0x46
87
+ && at(8) === 0x57 && at(9) === 0x45 && at(10) === 0x42 && at(11) === 0x50)
88
+ return 'webp';
89
+ const head = new TextDecoder().decode(bytes.subarray(0, Math.min(bytes.length, 1024))).replace(/^/, '').trimStart();
90
+ if ((head.startsWith('<svg') || head.startsWith('<?xml')) && head.includes('<svg'))
91
+ return 'svg';
92
+ return null;
93
+ }
94
+ /** The pages above a page, nearest first, as far as they go before a loop or a missing one. */
95
+ function parentsOf(page, byName) {
96
+ const chain = [];
97
+ const seen = new Set([page.name]);
98
+ let at = page.parent.type === 'some' ? page.parent.value : null;
99
+ while (at !== null) {
100
+ if (seen.has(at))
101
+ return { chain, loop: true };
102
+ seen.add(at);
103
+ chain.push(at);
104
+ const next = byName.get(at);
105
+ at = next === undefined || next.parent.type === 'none' ? null : next.parent.value;
106
+ }
107
+ return { chain, loop: false };
108
+ }
109
+ /**
110
+ * Whether an app is a well-formed app, whatever package it runs against: its
111
+ * names, pages, home, menu, parents, links, icons and logo.
112
+ *
113
+ * @param app - The app
114
+ * @param platform - The icon names an icon may have, if they are checked
115
+ * @returns Its problems; none for a well-formed app
116
+ */
117
+ export function validateApp(app, platform = {}) {
118
+ const problems = [];
119
+ const nameIssue = (kind, name) => {
120
+ const reason = nameProblem('workspace', name);
121
+ if (reason !== null)
122
+ problems.push(variant('invalid_name', { kind, name, reason }));
123
+ };
124
+ nameIssue('app', app.name);
125
+ const byName = new Map();
126
+ for (const page of app.pages) {
127
+ nameIssue('page', page.name);
128
+ if (byName.has(page.name))
129
+ problems.push(variant('duplicate_page', { page: page.name }));
130
+ else
131
+ byName.set(page.name, page);
132
+ }
133
+ // The home page, and the menu's: there, and with no params
134
+ const home = byName.get(app.home);
135
+ if (home === undefined)
136
+ problems.push(variant('missing_page', { page: app.home, from: 'home' }));
137
+ else if (pageParamsType(home) !== null)
138
+ problems.push(variant('page_takes_params', { page: app.home, as: 'the home page' }));
139
+ for (const group of app.menu) {
140
+ for (const name of group.pages) {
141
+ const page = byName.get(name);
142
+ if (page === undefined)
143
+ problems.push(variant('missing_page', { page: name, from: 'the menu' }));
144
+ else if (pageParamsType(page) !== null)
145
+ problems.push(variant('page_takes_params', { page: name, as: 'a menu page' }));
146
+ }
147
+ }
148
+ // Parents: there, and no loop (each loop once)
149
+ const loops = new Set();
150
+ for (const page of app.pages) {
151
+ if (page.parent.type === 'some' && !byName.has(page.parent.value)) {
152
+ problems.push(variant('missing_page', { page: page.parent.value, from: `${page.name}'s parent` }));
153
+ }
154
+ const { chain, loop } = parentsOf(page, byName);
155
+ if (loop) {
156
+ const pages = [page.name, ...chain];
157
+ const key = [...pages].sort().join('\u0000');
158
+ if (!loops.has(key)) {
159
+ loops.add(key);
160
+ problems.push(variant('parent_loop', { pages }));
161
+ }
162
+ }
163
+ }
164
+ // Icons, where the platform names them
165
+ if (platform.icons !== undefined) {
166
+ for (const page of app.pages) {
167
+ if (page.icon.type === 'none')
168
+ continue;
169
+ const { prefix, name } = page.icon.value;
170
+ if (prefix !== 'fas' || !platform.icons.has(`${prefix}:${name}`)) {
171
+ problems.push(variant('invalid_icon', { page: page.name, icon: `${prefix}:${name}` }));
172
+ }
173
+ }
174
+ }
175
+ if (app.logo.type === 'some') {
176
+ if (app.logo.value.length > APP_LOGO_MAX_BYTES) {
177
+ problems.push(variant('invalid_logo', { reason: `it's ${app.logo.value.length} bytes; a logo is at most ${APP_LOGO_MAX_BYTES}` }));
178
+ }
179
+ else if (logoKind(app.logo.value) === null) {
180
+ problems.push(variant('invalid_logo', { reason: "it isn't a PNG, JPEG, WebP or SVG" }));
181
+ }
182
+ }
183
+ // Links: to pages of the app, with their params
184
+ for (const page of app.pages) {
185
+ if (page.body.type !== 'east')
186
+ continue;
187
+ const scan = pageScan(page);
188
+ if (scan instanceof PageScanError)
189
+ continue;
190
+ for (const link of scan.links) {
191
+ const target = byName.get(link.target);
192
+ if (target === undefined) {
193
+ problems.push(variant('missing_page', { page: link.target, from: `a link on ${page.name}` }));
194
+ continue;
195
+ }
196
+ const expected = pageParamsType(target);
197
+ const matches = expected === null ? link.params === null : link.params !== null && typeValuesEqual(link.params, expected);
198
+ if (!matches) {
199
+ problems.push(variant('link_params', {
200
+ page: page.name,
201
+ target: target.name,
202
+ expected: expected === null ? none : some(expected),
203
+ actual: link.params === null ? none : some(link.params),
204
+ }));
205
+ }
206
+ }
207
+ }
208
+ return problems;
209
+ }
210
+ /** The patch dataset's type a `Data.bind` of type `T` writes through: `PatchType(T)`. */
211
+ function patchTypeOf(type) {
212
+ return toEastTypeValue(PatchType(fromEastTypeValue(type)));
213
+ }
214
+ /** A page's binds against a package's datasets, functions and records. */
215
+ function checkPage(page, scan, pkg, problems) {
216
+ const name = page.name;
217
+ for (const bind of scan.datasets) {
218
+ const dataset = pkg.datasets.get(treePathKey(bind.path));
219
+ if (dataset === undefined)
220
+ problems.push(variant('dataset_missing', { page: name, path: bind.path, expected: bind.type }));
221
+ else if (!typeValuesEqual(bind.type, dataset.type)) {
222
+ problems.push(variant('dataset_type', { page: name, path: bind.path, expected: bind.type, actual: dataset.type }));
223
+ }
224
+ if (bind.patch !== null) {
225
+ const patch = pkg.datasets.get(treePathKey(bind.patch));
226
+ const expected = patchTypeOf(bind.type);
227
+ if (patch === undefined)
228
+ problems.push(variant('dataset_missing', { page: name, path: bind.patch, expected }));
229
+ else if (!typeValuesEqual(expected, patch.type)) {
230
+ problems.push(variant('dataset_type', { page: name, path: bind.patch, expected, actual: patch.type }));
231
+ }
232
+ }
233
+ }
234
+ for (const path of scan.writes) {
235
+ const dataset = pkg.datasets.get(treePathKey(path));
236
+ if (dataset !== undefined && !dataset.writable)
237
+ problems.push(variant('dataset_not_writable', { page: name, path }));
238
+ }
239
+ for (const bind of scan.paged) {
240
+ if (bind.index === null) {
241
+ const dataset = pkg.datasets.get(treePathKey(bind.path));
242
+ if (dataset === undefined)
243
+ problems.push(variant('paged_missing', { page: name, path: bind.path, expected: bind.type }));
244
+ else if (!typeValuesEqual(bind.type, dataset.type)) {
245
+ problems.push(variant('paged_type', { page: name, path: bind.path, expected: bind.type, actual: dataset.type }));
246
+ }
247
+ continue;
248
+ }
249
+ const recordName = bind.path.length === 2 && bind.path[0].value === 'records' ? bind.path[1].value : null;
250
+ const record = recordName === null ? undefined : pkg.records.get(recordName);
251
+ if (record === undefined) {
252
+ problems.push(variant('record_missing', { page: name, record: recordName ?? treePathKey(bind.path) }));
253
+ continue;
254
+ }
255
+ const index = record.indexes.get(bind.index);
256
+ if (index === undefined) {
257
+ problems.push(variant('index_missing', { page: name, record: recordName, index: bind.index }));
258
+ continue;
259
+ }
260
+ const window = indexWindowTypeValue(record.state, index);
261
+ if (window === null || !typeValuesEqual(bind.type, window)) {
262
+ problems.push(variant('index_type', { page: name, record: recordName, index: bind.index, expected: bind.type, actual: window ?? record.state }));
263
+ }
264
+ }
265
+ for (const bind of scan.functions) {
266
+ const fn = pkg.functions.get(bind.name);
267
+ if (fn === undefined)
268
+ problems.push(variant('function_missing', { page: name, function: bind.name }));
269
+ else if (!typeListsEqual(bind.inputs, fn.inputs) || !typeValuesEqual(bind.output, fn.output)) {
270
+ problems.push(variant('function_signature', {
271
+ page: name, function: bind.name,
272
+ expected: { inputs: [...bind.inputs], output: bind.output },
273
+ actual: { inputs: [...fn.inputs], output: fn.output },
274
+ }));
275
+ }
276
+ }
277
+ for (const bind of scan.records) {
278
+ const record = pkg.records.get(bind.name);
279
+ if (record === undefined) {
280
+ problems.push(variant('record_missing', { page: name, record: bind.name }));
281
+ continue;
282
+ }
283
+ if (!typeValuesEqual(bind.state, record.state)) {
284
+ problems.push(variant('record_type', { page: name, record: bind.name, expected: bind.state, actual: record.state }));
285
+ }
286
+ for (const [mutation, args] of bind.mutations) {
287
+ const declared = record.mutations.get(mutation);
288
+ if (declared === undefined)
289
+ problems.push(variant('mutation_missing', { page: name, record: bind.name, mutation }));
290
+ else if (!typeListsEqual(args, declared)) {
291
+ problems.push(variant('mutation_signature', { page: name, record: bind.name, mutation, expected: [...args], actual: [...declared] }));
292
+ }
293
+ }
294
+ }
295
+ }
296
+ /** A problem's identity, so one reported by several binds is reported once: East's printed form of its value. */
297
+ const problemKey = printFor(AppProblemType);
298
+ /**
299
+ * Whether an app fits a package: the one function an app deploy, a
300
+ * workspace deploy or removal, a release, a copy and the app's own build
301
+ * run.
302
+ *
303
+ * @param app - The app
304
+ * @param pkg - What the checks need of the package it would run against
305
+ * @param platform - The e3 release it must have been built with, and the icon
306
+ * names an icon may have
307
+ * @returns Its problems, each once; none when it fits
308
+ */
309
+ export function checkApp(app, pkg, platform) {
310
+ const problems = validateApp(app, platform.icons === undefined ? {} : { icons: platform.icons });
311
+ for (const page of app.pages) {
312
+ if (page.body.type === 'task') {
313
+ const task = pkg.tasks.get(page.body.value);
314
+ if (task === undefined)
315
+ problems.push(variant('task_missing', { page: page.name, task: page.body.value }));
316
+ else if (!task.ui)
317
+ problems.push(variant('task_not_ui', { page: page.name, task: page.body.value }));
318
+ continue;
319
+ }
320
+ const scan = pageScan(page);
321
+ if (scan instanceof PageScanError) {
322
+ problems.push(variant('invalid_page', { page: page.name, reason: scan.message }));
323
+ continue;
324
+ }
325
+ const difference = manifestDifference(page, scan);
326
+ if (difference !== null)
327
+ problems.push(variant('manifest_mismatch', { page: page.name, detail: difference }));
328
+ checkPage(page, scan, pkg, problems);
329
+ }
330
+ if (platform.e3Version !== null && app.builtWith !== platform.e3Version) {
331
+ problems.push(variant('e3_version', { builtWith: app.builtWith, platform: platform.e3Version }));
332
+ }
333
+ const seen = new Set();
334
+ return problems.filter((problem) => {
335
+ const key = problemKey(problem);
336
+ if (seen.has(key))
337
+ return false;
338
+ seen.add(key);
339
+ return true;
340
+ });
341
+ }
342
+ //# sourceMappingURL=check.js.map