@yodaos-pkg/aix 0.11.0 → 0.13.0
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 +110 -6
- package/index.d.ts +103 -2
- package/index.js +212 -5
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/pkg/README.md +110 -6
- package/pkg/aix_web.d.ts +35 -13
- package/pkg/aix_web.js +128 -2
- package/pkg/aix_web_bg.wasm +0 -0
- package/pkg/aix_web_bg.wasm.d.ts +20 -13
- package/pkg/package.json +1 -1
- package/pkg-reader/README.md +110 -6
- package/pkg-reader/aix_web.d.ts +2 -0
- package/pkg-reader/aix_web.js +11 -1
- package/pkg-reader/aix_web_bg.wasm +0 -0
- package/pkg-reader/aix_web_bg.wasm.d.ts +1 -0
- package/pkg-reader/package.json +1 -1
- package/workers/progressive-worker.d.ts +1 -0
- package/workers/progressive-worker.js +57 -0
package/README.md
CHANGED
|
@@ -32,8 +32,9 @@ async function fromFile(file: File) {
|
|
|
32
32
|
|
|
33
33
|
## WASM Loading
|
|
34
34
|
|
|
35
|
-
`AIX.From()` and all instance methods initialize a separate reader-only WASM.
|
|
35
|
+
By default, `AIX.From()` and all instance methods initialize a separate reader-only WASM.
|
|
36
36
|
They do not load image codecs, script minification, or source/schema checking.
|
|
37
|
+
The optional `AIX.From(data, limits, true)` check also loads the full tooling module.
|
|
37
38
|
The first pack, optimize, or source-check call lazily loads the full module;
|
|
38
39
|
concurrent tooling calls share initialization. Existing reader instances remain
|
|
39
40
|
valid after tooling loads, and tooling-only calls do not fetch reader WASM.
|
|
@@ -74,6 +75,35 @@ separate budgets. This policy applies to readers, not `AIX.optimize`.
|
|
|
74
75
|
Direct WASM consumers can call `AixReaderWasm.with_limits(data, limits)` using
|
|
75
76
|
the same fields. The existing `new AixReaderWasm(data)` constructor is unchanged.
|
|
76
77
|
|
|
78
|
+
## Open and Check
|
|
79
|
+
|
|
80
|
+
Pass `true` as the third `AIX.From` argument to run the source checker before
|
|
81
|
+
receiving the package. The second argument remains the optional read limits;
|
|
82
|
+
pass `undefined` there when no limits are needed.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { AIX, AixCheckError } from '@yodaos-pkg/aix';
|
|
86
|
+
|
|
87
|
+
async function openCheckedPackage(file: File) {
|
|
88
|
+
try {
|
|
89
|
+
return await AIX.From(file, undefined, true);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof AixCheckError) console.table(error.diagnostics);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Warnings alone pass. Error diagnostics reject with the exported `AixCheckError`
|
|
98
|
+
(`name: 'AixCheckError'`), an `Error` subclass with the complete `CheckReport` in
|
|
99
|
+
`report` and the same diagnostic array in `diagnostics`, including warnings.
|
|
100
|
+
The check uses `checkFromSource` on the package's source files without running
|
|
101
|
+
project code. It adds work and retains extracted check inputs; read limits still
|
|
102
|
+
apply but do not bound total checker memory. Archive, extraction, loading, and
|
|
103
|
+
collection failures retain their original operation errors rather than a check
|
|
104
|
+
report. Omitting the third argument or passing `false` preserves the existing
|
|
105
|
+
reader-only behavior.
|
|
106
|
+
|
|
77
107
|
## Check Source Files
|
|
78
108
|
|
|
79
109
|
The Web SDK and npm CLI use the same complete in-memory check engine:
|
|
@@ -218,8 +248,10 @@ files and wants to invoke the low-level packer directly.
|
|
|
218
248
|
|
|
219
249
|
The main class to interact with an AIX package.
|
|
220
250
|
|
|
221
|
-
#### `static async From(data: Uint8Array | File): Promise<AIX>`
|
|
251
|
+
#### `static async From(data: Uint8Array | File, limits?: AixReadLimits, check?: boolean): Promise<AIX>`
|
|
222
252
|
Initializes the WASM module and creates an AIX instance from the given `.aix` file content. It supports both `Uint8Array` and the standard Web `File` object.
|
|
253
|
+
`check` defaults to `false`. Set it to `true` to check before returning and reject
|
|
254
|
+
with `AixCheckError` when errors are reported; see [Open and Check](#open-and-check).
|
|
223
255
|
```typescript
|
|
224
256
|
// From Uint8Array
|
|
225
257
|
const aix = await AIX.From(new Uint8Array(buffer));
|
|
@@ -254,6 +286,17 @@ Extracts the navigation bar title from the `app.json`.
|
|
|
254
286
|
const title = aix.getTitle();
|
|
255
287
|
```
|
|
256
288
|
|
|
289
|
+
#### `getPermissions(): string[]`
|
|
290
|
+
Returns the permission names declared in `app.json.permissions`, preserving their
|
|
291
|
+
order, duplicates, and custom names. An omitted or empty list returns `[]`.
|
|
292
|
+
Throws if `app.json` is missing, unreadable, invalid, or `permissions` is not an
|
|
293
|
+
array of strings. This reads declarations without querying authorization or
|
|
294
|
+
prompting for access.
|
|
295
|
+
```typescript
|
|
296
|
+
const permissions = aix.getPermissions();
|
|
297
|
+
// e.g. ['GEOLOCATION', 'CAMERA']
|
|
298
|
+
```
|
|
299
|
+
|
|
257
300
|
#### `getPages(): PageInfo[]`
|
|
258
301
|
Returns information about all pages defined in the package, including their paths, titles, and data schemas.
|
|
259
302
|
```typescript
|
|
@@ -280,8 +323,8 @@ const widgets = aix.getWidgets('en-US');
|
|
|
280
323
|
|
|
281
324
|
Returns `{ pages, tools, diagnostics }` synchronously. Missing/unreadable resources,
|
|
282
325
|
UTF-8 errors, and malformed page metadata produce `{ path, message }` diagnostics,
|
|
283
|
-
one per failed page.
|
|
284
|
-
pages
|
|
326
|
+
one per failed page. Both result lists put the default page first when it resolves
|
|
327
|
+
and keep the other pages in declaration order. A valid empty page list has no diagnostics;
|
|
285
328
|
invalid/unreadable `app.json.pages` produces an `app.json` diagnostic.
|
|
286
329
|
|
|
287
330
|
```typescript
|
|
@@ -309,7 +352,7 @@ Exported `MetadataResolution` has `pages: PageInfo[]`, `tools: Tool[]`, and
|
|
|
309
352
|
string fields.
|
|
310
353
|
|
|
311
354
|
#### `getTools(): Tool[]`
|
|
312
|
-
Generates
|
|
355
|
+
Generates OpenAI-compatible tools with `_blank` or `_current`. Pages can declare `target` in page JSON or `<script def>` and use `_inline` as an alias for `_current`. A valid `entryPagePath` or an explicit page target places the default page first with `_blank`. When both fields are omitted, only a first page without parameters is inferred as `_blank`.
|
|
313
356
|
```typescript
|
|
314
357
|
const tools = aix.getTools();
|
|
315
358
|
/*
|
|
@@ -318,7 +361,7 @@ const tools = aix.getTools();
|
|
|
318
361
|
target: "_blank",
|
|
319
362
|
layout: { width: 480, height: 168 },
|
|
320
363
|
function: {
|
|
321
|
-
name: "
|
|
364
|
+
name: "pages/index/index",
|
|
322
365
|
description: "Home",
|
|
323
366
|
parameters: { ... }
|
|
324
367
|
}
|
|
@@ -410,3 +453,64 @@ The output will be generated in the `dist` directory, including WASM binaries an
|
|
|
410
453
|
## License
|
|
411
454
|
|
|
412
455
|
MIT
|
|
456
|
+
|
|
457
|
+
## Progressive Assets
|
|
458
|
+
|
|
459
|
+
Declare the asset in an ESM module or Ink script.
|
|
460
|
+
|
|
461
|
+
```js
|
|
462
|
+
import video from './assets/clip.mp4' with {
|
|
463
|
+
type: 'video',
|
|
464
|
+
progressive: 'prefer',
|
|
465
|
+
};
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
The imported value is an opaque `AssetRef`. Pass it to Ink's video or audio consumer. The CLI and Web SDK embed complete assets by default. A Web
|
|
469
|
+
pack caller can choose remote delivery after it stores all prepared objects.
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
const packed = await AIX.packFromSource(files, {
|
|
473
|
+
signal: controller.signal,
|
|
474
|
+
async onProgressiveAsset(candidate, context) {
|
|
475
|
+
if (!candidate.progressiveSupport.supported || !shouldUpload(candidate)) {
|
|
476
|
+
return { delivery: 'embedded' };
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const plan = await context.prepare();
|
|
480
|
+
const receipt = await uploadVerifiedObjects(plan.remoteObjects, {
|
|
481
|
+
assetVersion: plan.assetVersion,
|
|
482
|
+
signal: context.signal,
|
|
483
|
+
});
|
|
484
|
+
return { delivery: 'progressive', planId: plan.id, receipt };
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
The caller owns upload policy, credentials, and cleanup of uploads left
|
|
490
|
+
unreferenced by a failed pack. Return a receipt only after durable storage has
|
|
491
|
+
verified every object. Receipt URLs must be final, immutable HTTPS locators
|
|
492
|
+
without credentials, query strings, or fragments. A rejected callback, invalid
|
|
493
|
+
receipt, or abort fails the pack. `packed.progressiveAssets` reports the
|
|
494
|
+
selected delivery mode and any source bytes retained for ordinary imports.
|
|
495
|
+
|
|
496
|
+
The media profile accepts ordinary MP4/M4A and prepared fMP4 with
|
|
497
|
+
finite H.264 video, AAC-LC audio, or both. The packer copies encoded samples
|
|
498
|
+
into keyframe-aligned fragments and preserves a single continuous rate-one
|
|
499
|
+
edit per track. Incompatible codecs or timelines can be converted upstream
|
|
500
|
+
or embedded. The Ink runtime must support the selected profile.
|
|
501
|
+
|
|
502
|
+
The browser integration test runs a local HTTPS Studio stand-in. It receives
|
|
503
|
+
object bytes over HTTP PUT, verifies length and SHA-256 on disk, and issues
|
|
504
|
+
receipts only after the entire inventory is present. Set `INK_WEB_DIST` to a
|
|
505
|
+
built Ink Web SDK to also test browser playback and offline reopening through the same object server.
|
|
506
|
+
|
|
507
|
+
In [Play's Build view](https://yodaos-project.github.io/aix/play?mode=build),
|
|
508
|
+
select a project directory and choose **Build and download**. Play calls
|
|
509
|
+
`onProgressiveAsset` for each declared asset and simulates the upload for
|
|
510
|
+
supported media. The downloaded package contains placeholder URLs you can
|
|
511
|
+
view in Inspect.
|
|
512
|
+
|
|
513
|
+
```sh
|
|
514
|
+
npm run build
|
|
515
|
+
AIX_TEST_BROWSER_CHANNEL=chrome node scripts/test-progressive.js
|
|
516
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import type { CheckOptions, CheckReport } from './check/types.js';
|
|
1
|
+
import type { CheckDiagnostic, CheckOptions, CheckReport } from './check/types.js';
|
|
2
2
|
export type { CheckDiagnostic, CheckOptions, CheckProgressEvent, CheckReport, CheckResult } from './check/types.js';
|
|
3
|
+
/** A package failed the optional source check in AIX.From(). */
|
|
4
|
+
export declare class AixCheckError extends Error {
|
|
5
|
+
readonly report: CheckReport;
|
|
6
|
+
constructor(report: CheckReport);
|
|
7
|
+
/** All check diagnostics, including warnings. */
|
|
8
|
+
get diagnostics(): CheckDiagnostic[];
|
|
9
|
+
}
|
|
3
10
|
export interface AixInputFile {
|
|
4
11
|
path: string;
|
|
5
12
|
data: Uint8Array;
|
|
@@ -28,8 +35,90 @@ export interface PackResult {
|
|
|
28
35
|
data: Uint8Array;
|
|
29
36
|
report: OptimizeReport;
|
|
30
37
|
warnings: string[];
|
|
38
|
+
progressiveAssets: ProgressiveAssetReport[];
|
|
39
|
+
}
|
|
40
|
+
export type AssetRef = `aix-asset:${string}`;
|
|
41
|
+
export type ProgressiveAssetKind = 'audio' | 'video';
|
|
42
|
+
export interface ProgressiveAssetCandidate {
|
|
43
|
+
id: string;
|
|
44
|
+
kind: ProgressiveAssetKind;
|
|
45
|
+
sourcePath: string;
|
|
46
|
+
sourceSha256: string;
|
|
47
|
+
sourceSize: number;
|
|
48
|
+
references: {
|
|
49
|
+
path: string;
|
|
50
|
+
line: number;
|
|
51
|
+
column: number;
|
|
52
|
+
}[];
|
|
53
|
+
format: string;
|
|
54
|
+
dependencies: string[];
|
|
55
|
+
progressiveSupport: {
|
|
56
|
+
supported: boolean;
|
|
57
|
+
profile?: string;
|
|
58
|
+
requiredCapabilities: string[];
|
|
59
|
+
features: string[];
|
|
60
|
+
reason?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface ProgressiveAssetObject {
|
|
64
|
+
id: string;
|
|
65
|
+
size: number;
|
|
66
|
+
sha256: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ProgressiveAssetPlan {
|
|
69
|
+
id: string;
|
|
70
|
+
assetVersion: string;
|
|
71
|
+
profile: string;
|
|
72
|
+
localMetadata: Record<string, Omit<ProgressiveAssetObject, 'id'>>;
|
|
73
|
+
layout: {
|
|
74
|
+
init: string;
|
|
75
|
+
tracks: Record<string, {
|
|
76
|
+
kind: ProgressiveAssetKind;
|
|
77
|
+
timescale: number;
|
|
78
|
+
}>;
|
|
79
|
+
fragments: {
|
|
80
|
+
object: string;
|
|
81
|
+
ranges: Record<string, {
|
|
82
|
+
start: number;
|
|
83
|
+
end: number;
|
|
84
|
+
presentation_start: number;
|
|
85
|
+
presentation_end: number;
|
|
86
|
+
}>;
|
|
87
|
+
}[];
|
|
88
|
+
};
|
|
89
|
+
remoteObjects: (ProgressiveAssetObject & {
|
|
90
|
+
bytes: Uint8Array;
|
|
91
|
+
})[];
|
|
92
|
+
}
|
|
93
|
+
export interface ProgressiveAssetUploadReceipt {
|
|
94
|
+
uploadId: string;
|
|
95
|
+
assetVersion: string;
|
|
96
|
+
objects: (ProgressiveAssetObject & {
|
|
97
|
+
url: string;
|
|
98
|
+
})[];
|
|
99
|
+
}
|
|
100
|
+
export type ProgressiveAssetDecision = {
|
|
101
|
+
delivery: 'embedded';
|
|
102
|
+
} | {
|
|
103
|
+
delivery: 'progressive';
|
|
104
|
+
planId: string;
|
|
105
|
+
receipt: ProgressiveAssetUploadReceipt;
|
|
106
|
+
};
|
|
107
|
+
export interface ProgressiveAssetPackContext {
|
|
108
|
+
signal: AbortSignal;
|
|
109
|
+
prepare(): Promise<ProgressiveAssetPlan>;
|
|
110
|
+
}
|
|
111
|
+
export interface ProgressiveAssetReport {
|
|
112
|
+
id: string;
|
|
113
|
+
kind: ProgressiveAssetKind;
|
|
114
|
+
sourcePath: string;
|
|
115
|
+
delivery: 'embedded' | 'progressive';
|
|
116
|
+
assetVersion?: string;
|
|
117
|
+
retainedSourceBytes: number;
|
|
31
118
|
}
|
|
32
119
|
export interface PackOptions {
|
|
120
|
+
onProgressiveAsset?: (candidate: ProgressiveAssetCandidate, context: ProgressiveAssetPackContext) => ProgressiveAssetDecision | Promise<ProgressiveAssetDecision>;
|
|
121
|
+
signal?: AbortSignal;
|
|
33
122
|
buildId?: string;
|
|
34
123
|
/** Stable normalized project ID; reuse across builds. */
|
|
35
124
|
agentId?: string;
|
|
@@ -132,8 +221,14 @@ export declare class AIX {
|
|
|
132
221
|
* Values must be non-negative safe integers. Without limits, retains the
|
|
133
222
|
* historical unlimited policy. Input bytes and caller-retained copies are
|
|
134
223
|
* outside these budgets.
|
|
224
|
+
* @param check Run the source checker before returning; defaults to false.
|
|
225
|
+
* Error diagnostics reject with AixCheckError; warnings alone are accepted.
|
|
135
226
|
*/
|
|
136
|
-
static From(data: Uint8Array | File, limits?: AixReadLimits): Promise<AIX>;
|
|
227
|
+
static From(data: Uint8Array | File, limits?: AixReadLimits, check?: boolean): Promise<AIX>;
|
|
228
|
+
/** Lists the Progressive Assets declared in the same normalized inputs as {@link pack}. */
|
|
229
|
+
static listProgressiveAssets(files: AixInputFile[], options?: {
|
|
230
|
+
signal?: AbortSignal;
|
|
231
|
+
}): Promise<ProgressiveAssetCandidate[]>;
|
|
137
232
|
static pack(files: AixInputFile[], options?: PackOptions): Promise<PackResult>;
|
|
138
233
|
/**
|
|
139
234
|
* Packs an in-memory application source tree.
|
|
@@ -165,6 +260,12 @@ export declare class AIX {
|
|
|
165
260
|
* Get the title from app.json.
|
|
166
261
|
*/
|
|
167
262
|
getTitle(): string | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Get permission names declared in app.json, in declaration order.
|
|
265
|
+
* Missing declarations return []; invalid configuration throws.
|
|
266
|
+
* This does not query runtime or device authorization.
|
|
267
|
+
*/
|
|
268
|
+
getPermissions(): string[];
|
|
168
269
|
/**
|
|
169
270
|
* Get all pages from app.json and pages/*.json.
|
|
170
271
|
*/
|
package/index.js
CHANGED
|
@@ -18,6 +18,19 @@ function loadTooling() {
|
|
|
18
18
|
throw error;
|
|
19
19
|
}));
|
|
20
20
|
}
|
|
21
|
+
/** A package failed the optional source check in AIX.From(). */
|
|
22
|
+
export class AixCheckError extends Error {
|
|
23
|
+
constructor(report) {
|
|
24
|
+
const count = report.diagnostics.filter(diagnostic => diagnostic.severity === 'error').length;
|
|
25
|
+
super(`AIX check failed with ${count} ${count === 1 ? 'error' : 'errors'}`);
|
|
26
|
+
this.report = report;
|
|
27
|
+
this.name = 'AixCheckError';
|
|
28
|
+
}
|
|
29
|
+
/** All check diagnostics, including warnings. */
|
|
30
|
+
get diagnostics() {
|
|
31
|
+
return this.report.diagnostics;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
21
34
|
function generateBuildId() {
|
|
22
35
|
const cryptoApi = globalThis.crypto;
|
|
23
36
|
if (typeof cryptoApi?.randomUUID === 'function') {
|
|
@@ -68,8 +81,10 @@ export class AIX {
|
|
|
68
81
|
* Values must be non-negative safe integers. Without limits, retains the
|
|
69
82
|
* historical unlimited policy. Input bytes and caller-retained copies are
|
|
70
83
|
* outside these budgets.
|
|
84
|
+
* @param check Run the source checker before returning; defaults to false.
|
|
85
|
+
* Error diagnostics reject with AixCheckError; warnings alone are accepted.
|
|
71
86
|
*/
|
|
72
|
-
static async From(data, limits) {
|
|
87
|
+
static async From(data, limits, check = false) {
|
|
73
88
|
await initializeReader();
|
|
74
89
|
let buffer;
|
|
75
90
|
if (data instanceof Uint8Array) {
|
|
@@ -82,14 +97,46 @@ export class AIX {
|
|
|
82
97
|
const reader = limits === undefined
|
|
83
98
|
? new AixReaderWasm(buffer)
|
|
84
99
|
: AixReaderWasm.with_limits(buffer, limits);
|
|
85
|
-
|
|
100
|
+
try {
|
|
101
|
+
if (check) {
|
|
102
|
+
const files = reader.list()
|
|
103
|
+
.filter(entry => !entry.name.endsWith('/') && entry.name !== 'VERSION'
|
|
104
|
+
&& !entry.name.startsWith('META-INF/aix/'))
|
|
105
|
+
.map(entry => ({ path: entry.name, data: reader.read_file(entry.name) }));
|
|
106
|
+
const report = await AIX.checkFromSource(files);
|
|
107
|
+
if (report.diagnostics.some(diagnostic => diagnostic.severity === 'error')) {
|
|
108
|
+
throw new AixCheckError(report);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return new AIX(reader);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
reader.free();
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Lists the Progressive Assets declared in the same normalized inputs as {@link pack}. */
|
|
119
|
+
static async listProgressiveAssets(files, options) {
|
|
120
|
+
const signal = options?.signal ?? new AbortController().signal;
|
|
121
|
+
signal.throwIfAborted();
|
|
122
|
+
const session = await openPackSession(snapshotFiles(files), false, signal, () => { });
|
|
123
|
+
try {
|
|
124
|
+
signal.throwIfAborted();
|
|
125
|
+
return session.candidates;
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
session.close();
|
|
129
|
+
}
|
|
86
130
|
}
|
|
87
131
|
static async pack(files, options) {
|
|
132
|
+
if (options?.onProgressiveAsset || options?.signal) {
|
|
133
|
+
return stagedPack(files, options, false);
|
|
134
|
+
}
|
|
88
135
|
const tooling = await loadTooling();
|
|
89
136
|
const buildId = options?.buildId ?? generateBuildId();
|
|
90
137
|
const optimize = options?.optimize === false ? undefined : options?.optimize;
|
|
91
138
|
const result = tooling.pack_aix(files, buildId, options?.engine, optimize, options?.agentId);
|
|
92
|
-
return
|
|
139
|
+
return packResult(result);
|
|
93
140
|
}
|
|
94
141
|
/**
|
|
95
142
|
* Packs an in-memory application source tree.
|
|
@@ -99,13 +146,16 @@ export class AIX {
|
|
|
99
146
|
* `.aixignore` files are honored, and the rule files are omitted.
|
|
100
147
|
*/
|
|
101
148
|
static async packFromSource(files, options) {
|
|
149
|
+
if (options?.onProgressiveAsset || options?.signal) {
|
|
150
|
+
return stagedPack(files, options, true);
|
|
151
|
+
}
|
|
102
152
|
const tooling = await loadTooling();
|
|
103
153
|
const buildId = options?.buildId ?? generateBuildId();
|
|
104
154
|
const optimize = options?.optimize === false ? undefined : options?.optimize;
|
|
105
155
|
const result = options?.onProgress
|
|
106
156
|
? getPackFromSourceWithProgress(tooling)(files, buildId, options.engine, optimize, options.onProgress, options.agentId)
|
|
107
157
|
: getPackFromSource(tooling)(files, buildId, options?.engine, optimize, options?.agentId);
|
|
108
|
-
return
|
|
158
|
+
return packResult(result);
|
|
109
159
|
}
|
|
110
160
|
static async packFromFiles(files, options) {
|
|
111
161
|
const sourceFiles = await Promise.all(files.map(async (file) => ({
|
|
@@ -120,7 +170,7 @@ export class AIX {
|
|
|
120
170
|
? data
|
|
121
171
|
: new Uint8Array(await data.arrayBuffer());
|
|
122
172
|
const result = tooling.optimize_aix(buffer, options);
|
|
123
|
-
return
|
|
173
|
+
return packResult(result);
|
|
124
174
|
}
|
|
125
175
|
/**
|
|
126
176
|
* List all files in the AIX package.
|
|
@@ -154,6 +204,14 @@ export class AIX {
|
|
|
154
204
|
getTitle() {
|
|
155
205
|
return this.reader.get_title();
|
|
156
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Get permission names declared in app.json, in declaration order.
|
|
209
|
+
* Missing declarations return []; invalid configuration throws.
|
|
210
|
+
* This does not query runtime or device authorization.
|
|
211
|
+
*/
|
|
212
|
+
getPermissions() {
|
|
213
|
+
return this.reader.get_permissions();
|
|
214
|
+
}
|
|
157
215
|
/**
|
|
158
216
|
* Get all pages from app.json and pages/*.json.
|
|
159
217
|
*/
|
|
@@ -200,3 +258,152 @@ function getPackFromSourceWithProgress(tooling) {
|
|
|
200
258
|
}
|
|
201
259
|
return packFromSourceWithProgress;
|
|
202
260
|
}
|
|
261
|
+
function packResult(result) {
|
|
262
|
+
try {
|
|
263
|
+
return {
|
|
264
|
+
data: result.data,
|
|
265
|
+
report: result.report,
|
|
266
|
+
warnings: result.warnings ?? [],
|
|
267
|
+
progressiveAssets: result.progressiveAssets ?? [],
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
result.free?.();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function openPackSession(files, fromSource, signal, progress) {
|
|
275
|
+
let worker;
|
|
276
|
+
if (typeof Worker !== 'undefined' && typeof document !== 'undefined') {
|
|
277
|
+
try {
|
|
278
|
+
worker = new Worker(new URL('./workers/progressive-worker.js', import.meta.url), { type: 'module' });
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// A host can forbid workers. Use its existing WASM event loop.
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (!worker) {
|
|
285
|
+
const tooling = await loadTooling();
|
|
286
|
+
signal.throwIfAborted();
|
|
287
|
+
const session = new tooling.ProgressivePackWasm(files, fromSource);
|
|
288
|
+
try {
|
|
289
|
+
return {
|
|
290
|
+
candidates: session.candidates(),
|
|
291
|
+
prepare: async (id) => session.prepare(id),
|
|
292
|
+
finalize: async (decisions, buildId, engine, optimize, agentId) => packResult(session.finalize(decisions, buildId, engine, optimize, agentId, progress)),
|
|
293
|
+
close: () => session.free(),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
session.free();
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const port = worker;
|
|
302
|
+
const call = (request, transfer = []) => untilAborted(signal, () => new Promise((resolve, reject) => {
|
|
303
|
+
port.onmessage = ({ data }) => {
|
|
304
|
+
if (data.progress) {
|
|
305
|
+
try {
|
|
306
|
+
progress(data.progress);
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
reject(error);
|
|
310
|
+
port.terminate();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (data.error !== undefined) {
|
|
314
|
+
reject(new Error(data.error));
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
resolve(data.result);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
port.onerror = (event) => reject(new Error(event.message || 'Progressive Asset worker failed'));
|
|
321
|
+
port.onmessageerror = () => reject(new Error('Invalid Progressive Asset worker reply'));
|
|
322
|
+
port.postMessage(request, transfer);
|
|
323
|
+
}));
|
|
324
|
+
try {
|
|
325
|
+
const candidates = await call({ type: 'open', files, fromSource }, files.map((file) => file.data.buffer));
|
|
326
|
+
return {
|
|
327
|
+
candidates,
|
|
328
|
+
prepare: (id) => call({ type: 'prepare', id }),
|
|
329
|
+
finalize: (decisions, buildId, engine, optimize, agentId) => call({ type: 'finalize', decisions, buildId, engine, optimize, agentId }),
|
|
330
|
+
close: () => port.terminate(),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
port.terminate();
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function snapshotFiles(files) {
|
|
339
|
+
return files.map(({ path, data }) => ({ path, data: Uint8Array.from(data) }));
|
|
340
|
+
}
|
|
341
|
+
async function stagedPack(files, options, fromSource) {
|
|
342
|
+
const { onProgress, onProgressiveAsset, engine, agentId } = options;
|
|
343
|
+
const buildId = options.buildId ?? generateBuildId();
|
|
344
|
+
const optimize = options.optimize ? { ...options.optimize } : undefined;
|
|
345
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
346
|
+
signal.throwIfAborted();
|
|
347
|
+
const snapshot = snapshotFiles(files);
|
|
348
|
+
const progress = (event) => {
|
|
349
|
+
signal.throwIfAborted();
|
|
350
|
+
onProgress?.(event);
|
|
351
|
+
signal.throwIfAborted();
|
|
352
|
+
};
|
|
353
|
+
progress({ type: 'transferring_files_to_wasm' });
|
|
354
|
+
if (fromSource)
|
|
355
|
+
progress({ type: 'collecting_source_inputs' });
|
|
356
|
+
const session = await openPackSession(snapshot, fromSource, signal, progress);
|
|
357
|
+
try {
|
|
358
|
+
const decisions = Object.create(null);
|
|
359
|
+
if (onProgressiveAsset) {
|
|
360
|
+
for (const candidate of session.candidates) {
|
|
361
|
+
signal.throwIfAborted();
|
|
362
|
+
const id = candidate.id;
|
|
363
|
+
let active = true;
|
|
364
|
+
let plan;
|
|
365
|
+
const prepare = async () => {
|
|
366
|
+
signal.throwIfAborted();
|
|
367
|
+
if (!active)
|
|
368
|
+
throw new Error('Progressive Asset callback has finished');
|
|
369
|
+
plan ?? (plan = session.prepare(id));
|
|
370
|
+
void plan.catch(() => { });
|
|
371
|
+
// The upload may mutate or transfer the caller's copy. The pack
|
|
372
|
+
// session and subsequent prepare calls keep the original bytes.
|
|
373
|
+
return structuredClone(await plan);
|
|
374
|
+
};
|
|
375
|
+
try {
|
|
376
|
+
const decision = await untilAborted(signal, () => onProgressiveAsset(candidate, { signal, prepare }));
|
|
377
|
+
if (!decision || !['embedded', 'progressive'].includes(decision.delivery)) {
|
|
378
|
+
throw new Error('Invalid Progressive Asset delivery decision');
|
|
379
|
+
}
|
|
380
|
+
if (plan)
|
|
381
|
+
await plan;
|
|
382
|
+
decisions[id] = structuredClone(decision);
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
active = false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
signal.throwIfAborted();
|
|
390
|
+
return await session.finalize(decisions, buildId, engine, optimize, agentId);
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
session.close();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function untilAborted(signal, work) {
|
|
397
|
+
return new Promise((resolve, reject) => {
|
|
398
|
+
if (signal.aborted) {
|
|
399
|
+
reject(signal.reason);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const onAbort = () => reject(signal.reason);
|
|
403
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
404
|
+
Promise.resolve().then(() => {
|
|
405
|
+
signal.throwIfAborted();
|
|
406
|
+
return work();
|
|
407
|
+
}).then(resolve, reject).finally(() => signal.removeEventListener('abort', onAbort));
|
|
408
|
+
});
|
|
409
|
+
}
|
package/jsr.json
CHANGED