@pwfabric/pack 0.0.0-stage → 1.0.0-rc.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/COMPAT.md +136 -0
- package/LICENSE +202 -0
- package/README.md +34 -2
- package/dist/archive.d.ts +57 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +151 -0
- package/dist/archive.js.map +1 -0
- package/dist/content.d.ts +35 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +49 -0
- package/dist/content.js.map +1 -0
- package/dist/folder.d.ts +28 -0
- package/dist/folder.d.ts.map +1 -0
- package/dist/folder.js +85 -0
- package/dist/folder.js.map +1 -0
- package/dist/hash.d.ts +22 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +41 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +54 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +94 -0
- package/dist/manifest.js.map +1 -0
- package/dist/media.d.ts +78 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +135 -0
- package/dist/media.js.map +1 -0
- package/dist/paths.d.ts +45 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +126 -0
- package/dist/paths.js.map +1 -0
- package/dist/tar.d.ts +40 -0
- package/dist/tar.d.ts.map +1 -0
- package/dist/tar.js +277 -0
- package/dist/tar.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +64 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +267 -0
- package/dist/validate.js.map +1 -0
- package/package.json +54 -3
package/dist/content.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Root files that are pack content besides `pwpack.json`: the pack's own documentation and terms. */
|
|
2
|
+
export const PACK_DOC_FILES = new Set(['LICENSE', 'NOTICE', 'README.md']);
|
|
3
|
+
/** Root directories of the canonical folder. */
|
|
4
|
+
export const PACK_ROOT_DIRS = new Set(['app', 'atoms', 'media']);
|
|
5
|
+
/**
|
|
6
|
+
* Root directories of the legacy rootless layout: the atom families of
|
|
7
|
+
* `classifyPackPath` (and its shared-code root `lib`). Root `test/` is not
|
|
8
|
+
* among them — in a source folder it is the author's tooling; a pack that
|
|
9
|
+
* ships its tests keeps them under `atoms/test/`.
|
|
10
|
+
*/
|
|
11
|
+
export const ROOTLESS_FAMILY_DIRS = new Set([
|
|
12
|
+
'blocks',
|
|
13
|
+
'capabilities',
|
|
14
|
+
'connectors',
|
|
15
|
+
'providers',
|
|
16
|
+
'appearance',
|
|
17
|
+
'patterns',
|
|
18
|
+
'icons',
|
|
19
|
+
'surfaces',
|
|
20
|
+
'auth',
|
|
21
|
+
'lib',
|
|
22
|
+
]);
|
|
23
|
+
/** True when `path` (a safe pack path) is pack content. */
|
|
24
|
+
export function isPackContentPath(path) {
|
|
25
|
+
const slash = path.indexOf('/');
|
|
26
|
+
if (slash === -1)
|
|
27
|
+
return path === 'pwpack.json' || PACK_DOC_FILES.has(path);
|
|
28
|
+
const top = path.slice(0, slash);
|
|
29
|
+
return PACK_ROOT_DIRS.has(top) || ROOTLESS_FAMILY_DIRS.has(top);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The pack content of a folder: `pwpack.json`, `LICENSE`, `NOTICE` and
|
|
33
|
+
* `README.md` at the root; everything under `app/`, `atoms/` and `media/`;
|
|
34
|
+
* and, for the legacy rootless layout, everything under a root atom-family
|
|
35
|
+
* directory (`blocks/`, `capabilities/`, `connectors/`, `providers/`,
|
|
36
|
+
* `appearance/`, `patterns/`, `icons/`, `surfaces/`, `auth/`, `lib/`).
|
|
37
|
+
* Everything else is dropped. Bytes are shared, not copied.
|
|
38
|
+
*
|
|
39
|
+
* The content hash (`hashPack`) is computed over this, so a pack hashes the
|
|
40
|
+
* same whether it was read from its source folder or from its archive.
|
|
41
|
+
*/
|
|
42
|
+
export function packContent(folder) {
|
|
43
|
+
const files = new Map();
|
|
44
|
+
for (const [path, bytes] of folder.files)
|
|
45
|
+
if (isPackContentPath(path))
|
|
46
|
+
files.set(path, bytes);
|
|
47
|
+
return { files };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAUA,sGAAsG;AACtG,MAAM,CAAC,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;AAE9F,gDAAgD;AAChD,MAAM,CAAC,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;AAErF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IAC/D,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,UAAU;IACV,OAAO;IACP,UAAU;IACV,MAAM;IACN,KAAK;CACN,CAAC,CAAA;AAEF,2DAA2D;AAC3D,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/B,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,KAAK,aAAa,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC3E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IAChC,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACjE,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC5C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC3C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK;QAAE,IAAI,iBAAiB,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC7F,OAAO,EAAE,KAAK,EAAE,CAAA;AAClB,CAAC"}
|
package/dist/folder.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PackFolder } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Entry names skipped anywhere in the walk: dependency and build output, VCS
|
|
4
|
+
* metadata and the junk files operating systems drop into folders.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_IGNORED_NAMES: ReadonlySet<string>;
|
|
7
|
+
export interface ReadFolderOptions {
|
|
8
|
+
/** Entry names to skip at any depth. Replaces {@link DEFAULT_IGNORED_NAMES}. */
|
|
9
|
+
readonly ignore?: ReadonlySet<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Walk `dir` into memory.
|
|
13
|
+
*
|
|
14
|
+
* Paths are POSIX and relative to `dir`; bytes are taken as they are on disk
|
|
15
|
+
* (no line-ending or Unicode normalisation). Skipped: names in the ignore set
|
|
16
|
+
* at any depth, and `*.pwpack` archives directly at the root (a folder's own
|
|
17
|
+
* packed output never packs itself). Refused with {@link PackError}: a
|
|
18
|
+
* symbolic link or junction (`LINK_ENTRY`), anything that is neither a file
|
|
19
|
+
* nor a directory (`UNSUPPORTED_ENTRY`), and a name that cannot be a safe
|
|
20
|
+
* pack path, e.g. one containing a backslash (`UNSAFE_PATH`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function readFolder(dir: string, options?: ReadFolderOptions): Promise<PackFolder>;
|
|
23
|
+
/**
|
|
24
|
+
* A {@link PackFolder} from a `path → content` record. Strings are encoded
|
|
25
|
+
* as UTF-8 exactly as given; bytes are copied. Paths must already be safe.
|
|
26
|
+
*/
|
|
27
|
+
export declare function packFromRecord(record: Readonly<Record<string, string | Uint8Array>>): PackFolder;
|
|
28
|
+
//# sourceMappingURL=folder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../src/folder.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAGvD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,CAOpD,CAAA;AAEF,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACtC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CA8BlG;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,GAAG,UAAU,CAShG"}
|
package/dist/folder.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folder ⇄ memory: walk a pwpack folder on disk into a {@link PackFolder},
|
|
3
|
+
* and build one from a plain path → content record.
|
|
4
|
+
*
|
|
5
|
+
* @module @pwfabric/pack/folder
|
|
6
|
+
*/
|
|
7
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { PackError } from './types.js';
|
|
10
|
+
import { compareBytes, unsafePathReason } from './paths.js';
|
|
11
|
+
/**
|
|
12
|
+
* Entry names skipped anywhere in the walk: dependency and build output, VCS
|
|
13
|
+
* metadata and the junk files operating systems drop into folders.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_IGNORED_NAMES = new Set([
|
|
16
|
+
'node_modules',
|
|
17
|
+
'dist',
|
|
18
|
+
'.git',
|
|
19
|
+
'.DS_Store',
|
|
20
|
+
'Thumbs.db',
|
|
21
|
+
'desktop.ini',
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* Walk `dir` into memory.
|
|
25
|
+
*
|
|
26
|
+
* Paths are POSIX and relative to `dir`; bytes are taken as they are on disk
|
|
27
|
+
* (no line-ending or Unicode normalisation). Skipped: names in the ignore set
|
|
28
|
+
* at any depth, and `*.pwpack` archives directly at the root (a folder's own
|
|
29
|
+
* packed output never packs itself). Refused with {@link PackError}: a
|
|
30
|
+
* symbolic link or junction (`LINK_ENTRY`), anything that is neither a file
|
|
31
|
+
* nor a directory (`UNSUPPORTED_ENTRY`), and a name that cannot be a safe
|
|
32
|
+
* pack path, e.g. one containing a backslash (`UNSAFE_PATH`).
|
|
33
|
+
*/
|
|
34
|
+
export async function readFolder(dir, options = {}) {
|
|
35
|
+
const ignore = options.ignore ?? DEFAULT_IGNORED_NAMES;
|
|
36
|
+
const st = await stat(dir).catch(() => null);
|
|
37
|
+
if (!st?.isDirectory())
|
|
38
|
+
throw new PackError('NOT_A_DIRECTORY', `not a directory: ${dir}`);
|
|
39
|
+
const files = new Map();
|
|
40
|
+
const walk = async (abs, rel) => {
|
|
41
|
+
const entries = await readdir(abs, { withFileTypes: true });
|
|
42
|
+
entries.sort((a, b) => compareBytes(a.name, b.name));
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (ignore.has(entry.name))
|
|
45
|
+
continue;
|
|
46
|
+
const relPath = rel ? `${rel}/${entry.name}` : entry.name;
|
|
47
|
+
const reason = unsafePathReason(relPath);
|
|
48
|
+
if (reason)
|
|
49
|
+
throw new PackError('UNSAFE_PATH', `${relPath}: ${reason}`, relPath);
|
|
50
|
+
const full = join(abs, entry.name);
|
|
51
|
+
if (entry.isSymbolicLink()) {
|
|
52
|
+
throw new PackError('LINK_ENTRY', `${relPath} is a symbolic link; a pack folder carries files only`, relPath);
|
|
53
|
+
}
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
await walk(full, relPath);
|
|
56
|
+
}
|
|
57
|
+
else if (entry.isFile()) {
|
|
58
|
+
if (!rel && entry.name.endsWith('.pwpack'))
|
|
59
|
+
continue;
|
|
60
|
+
files.set(relPath, new Uint8Array(await readFile(full)));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new PackError('UNSUPPORTED_ENTRY', `${relPath} is neither a file nor a directory`, relPath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
await walk(dir, '');
|
|
68
|
+
return { files };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A {@link PackFolder} from a `path → content` record. Strings are encoded
|
|
72
|
+
* as UTF-8 exactly as given; bytes are copied. Paths must already be safe.
|
|
73
|
+
*/
|
|
74
|
+
export function packFromRecord(record) {
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
const files = new Map();
|
|
77
|
+
for (const [path, value] of Object.entries(record)) {
|
|
78
|
+
const reason = unsafePathReason(path);
|
|
79
|
+
if (reason)
|
|
80
|
+
throw new PackError('UNSAFE_PATH', `${path}: ${reason}`, path);
|
|
81
|
+
files.set(path, typeof value === 'string' ? encoder.encode(value) : new Uint8Array(value));
|
|
82
|
+
}
|
|
83
|
+
return { files };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=folder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folder.js","sourceRoot":"","sources":["../src/folder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,E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E,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;QACrC,IAAI,MAAM;YAAE,MAAM,IAAI,SAAS,CAAC,aAAa,EAAE,GAAG,IAAI,KAAK,MAAM,EAAE,EAAE,IAAI,CAAC,CAAA;QAC1E,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5F,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAA;AAClB,CAAC"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PackFolder } from './types.js';
|
|
2
|
+
/** Lower-case hex sha256 of `data`. */
|
|
3
|
+
export declare function sha256Hex(data: Uint8Array | string): string;
|
|
4
|
+
/**
|
|
5
|
+
* The pack's content hash: `sha256:` + sha256 over one line per file of the
|
|
6
|
+
* pack content (`packContent`: an author's tooling does not count),
|
|
7
|
+
* `<path>\0<sha256-hex of the bytes>\n`, lines in byte order of the path.
|
|
8
|
+
*
|
|
9
|
+
* Depends only on the pack content's paths and bytes — not on archive
|
|
10
|
+
* framing, compression, platform, zlib build or tooling beside the pack — so
|
|
11
|
+
* the same pack hashes the same whether it was read from its source folder
|
|
12
|
+
* or from any archive layout `readPwpack` accepts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hashPack(pack: PackFolder): string;
|
|
15
|
+
/**
|
|
16
|
+
* The archive hash existing producers record as `contentHash`: `sha256:` +
|
|
17
|
+
* sha256 of the compressed archive bytes. It changes whenever the archive
|
|
18
|
+
* framing does (wrapper directory, mtimes, gzip level, OS byte), so two
|
|
19
|
+
* archives of the same folder can differ here while {@link hashPack} agrees.
|
|
20
|
+
*/
|
|
21
|
+
export declare function legacyContentHash(archive: Uint8Array): string;
|
|
22
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI5C,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAOjD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAE7D"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content identity of a pack.
|
|
3
|
+
*
|
|
4
|
+
* @module @pwfabric/pack/hash
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { sortedPaths } from './paths.js';
|
|
8
|
+
import { isPackContentPath } from './content.js';
|
|
9
|
+
/** Lower-case hex sha256 of `data`. */
|
|
10
|
+
export function sha256Hex(data) {
|
|
11
|
+
return createHash('sha256').update(data).digest('hex');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The pack's content hash: `sha256:` + sha256 over one line per file of the
|
|
15
|
+
* pack content (`packContent`: an author's tooling does not count),
|
|
16
|
+
* `<path>\0<sha256-hex of the bytes>\n`, lines in byte order of the path.
|
|
17
|
+
*
|
|
18
|
+
* Depends only on the pack content's paths and bytes — not on archive
|
|
19
|
+
* framing, compression, platform, zlib build or tooling beside the pack — so
|
|
20
|
+
* the same pack hashes the same whether it was read from its source folder
|
|
21
|
+
* or from any archive layout `readPwpack` accepts.
|
|
22
|
+
*/
|
|
23
|
+
export function hashPack(pack) {
|
|
24
|
+
const h = createHash('sha256');
|
|
25
|
+
for (const path of sortedPaths(pack.files.keys())) {
|
|
26
|
+
if (!isPackContentPath(path))
|
|
27
|
+
continue;
|
|
28
|
+
h.update(`${path}\0${sha256Hex(pack.files.get(path))}\n`, 'utf8');
|
|
29
|
+
}
|
|
30
|
+
return `sha256:${h.digest('hex')}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The archive hash existing producers record as `contentHash`: `sha256:` +
|
|
34
|
+
* sha256 of the compressed archive bytes. It changes whenever the archive
|
|
35
|
+
* framing does (wrapper directory, mtimes, gzip level, OS byte), so two
|
|
36
|
+
* archives of the same folder can differ here while {@link hashPack} agrees.
|
|
37
|
+
*/
|
|
38
|
+
export function legacyContentHash(archive) {
|
|
39
|
+
return `sha256:${sha256Hex(archive)}`;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,uCAAuC;AACvC,MAAM,UAAU,SAAS,CAAC,IAAyB;IACjD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACxD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAgB;IACvC,MAAM,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC9B,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;YAAE,SAAQ;QACtC,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACjF,CAAC;IACD,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAmB;IACnD,OAAO,UAAU,SAAS,CAAC,OAAO,CAAC,EAAE,CAAA;AACvC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pwfabric/pack — the single reader and writer of the
|
|
3
|
+
* pwpack folder and its `.pwpack` archive.
|
|
4
|
+
*
|
|
5
|
+
* A pwpack is a rootless folder: `pwpack.json` (identity), `app/` (an app's
|
|
6
|
+
* own declaration), `atoms/` (reusable parts) and `media/` (content files:
|
|
7
|
+
* images, video, fonts) with `media/provenance.json`. `<name>-<version>.pwpack` is the deterministic
|
|
8
|
+
* gzipped tar of that folder.
|
|
9
|
+
*
|
|
10
|
+
* readFolder(dir) folder on disk → PackFolder
|
|
11
|
+
* readPwpack(bytes) .pwpack bytes → PackFolder
|
|
12
|
+
* writePwpack(pack) PackFolder → deterministic .pwpack bytes
|
|
13
|
+
* validatePack(pack) PackFolder → structured issues
|
|
14
|
+
* packContent(pack) PackFolder → the part that is the pack (no tooling)
|
|
15
|
+
* hashPack(pack) PackFolder → content hash of the pack content (framing-independent)
|
|
16
|
+
* deriveManifest(...) PackFolder → PwpackManifest
|
|
17
|
+
* mediaDeclarations() PackFolder → media declarations + bytes + provenance
|
|
18
|
+
*
|
|
19
|
+
* @module @pwfabric/pack
|
|
20
|
+
*/
|
|
21
|
+
export { PackError, type PackErrorCode, type PackFolder, type PackIssue, type PackIssueSeverity } from './types.js';
|
|
22
|
+
export { compareBytes, findCaseConflicts, findPathConflict, foldPath, isSafePackPath, unsafePathReason, } from './paths.js';
|
|
23
|
+
export { isPackContentPath, PACK_DOC_FILES, PACK_ROOT_DIRS, packContent, ROOTLESS_FAMILY_DIRS } from './content.js';
|
|
24
|
+
export { DEFAULT_IGNORED_NAMES, packFromRecord, readFolder, type ReadFolderOptions } from './folder.js';
|
|
25
|
+
export { DEFAULT_LIMITS, GZIP_LEVEL, GZIP_OS_UNIX, readPwpack, writePwpack, type PwpackLimits, } from './archive.js';
|
|
26
|
+
export { DIR_MODE, FILE_MODE, FIXED_MTIME } from './tar.js';
|
|
27
|
+
export { hashPack, legacyContentHash, sha256Hex } from './hash.js';
|
|
28
|
+
export { deriveAtoms, deriveManifest, IDENTITY_FILE, type DeriveManifestOptions, } from './manifest.js';
|
|
29
|
+
export { LEGACY_ASSETS_DIR, MEDIA_DECLARATIONS_DIR, MEDIA_DIR, MEDIA_PROVENANCE_FILE, mediaDeclarations, readMediaProvenance, type PackMedia, type PackMediaDeclaration, type ProvenanceRead, } from './media.js';
|
|
30
|
+
export { ATOM_FAMILIES, SUPPORTED_FORMAT_MAJOR, validatePack, type PackLayout, type PackValidation, } from './validate.js';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnH,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnH,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACvG,OAAO,EACL,cAAc,EACd,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,KAAK,YAAY,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EACL,WAAW,EACX,cAAc,EACd,aAAa,EACb,KAAK,qBAAqB,GAC3B,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pwfabric/pack — the single reader and writer of the
|
|
3
|
+
* pwpack folder and its `.pwpack` archive.
|
|
4
|
+
*
|
|
5
|
+
* A pwpack is a rootless folder: `pwpack.json` (identity), `app/` (an app's
|
|
6
|
+
* own declaration), `atoms/` (reusable parts) and `media/` (content files:
|
|
7
|
+
* images, video, fonts) with `media/provenance.json`. `<name>-<version>.pwpack` is the deterministic
|
|
8
|
+
* gzipped tar of that folder.
|
|
9
|
+
*
|
|
10
|
+
* readFolder(dir) folder on disk → PackFolder
|
|
11
|
+
* readPwpack(bytes) .pwpack bytes → PackFolder
|
|
12
|
+
* writePwpack(pack) PackFolder → deterministic .pwpack bytes
|
|
13
|
+
* validatePack(pack) PackFolder → structured issues
|
|
14
|
+
* packContent(pack) PackFolder → the part that is the pack (no tooling)
|
|
15
|
+
* hashPack(pack) PackFolder → content hash of the pack content (framing-independent)
|
|
16
|
+
* deriveManifest(...) PackFolder → PwpackManifest
|
|
17
|
+
* mediaDeclarations() PackFolder → media declarations + bytes + provenance
|
|
18
|
+
*
|
|
19
|
+
* @module @pwfabric/pack
|
|
20
|
+
*/
|
|
21
|
+
export { PackError } from './types.js';
|
|
22
|
+
export { compareBytes, findCaseConflicts, findPathConflict, foldPath, isSafePackPath, unsafePathReason, } from './paths.js';
|
|
23
|
+
export { isPackContentPath, PACK_DOC_FILES, PACK_ROOT_DIRS, packContent, ROOTLESS_FAMILY_DIRS } from './content.js';
|
|
24
|
+
export { DEFAULT_IGNORED_NAMES, packFromRecord, readFolder } from './folder.js';
|
|
25
|
+
export { DEFAULT_LIMITS, GZIP_LEVEL, GZIP_OS_UNIX, readPwpack, writePwpack, } from './archive.js';
|
|
26
|
+
export { DIR_MODE, FILE_MODE, FIXED_MTIME } from './tar.js';
|
|
27
|
+
export { hashPack, legacyContentHash, sha256Hex } from './hash.js';
|
|
28
|
+
export { deriveAtoms, deriveManifest, IDENTITY_FILE, } from './manifest.js';
|
|
29
|
+
export { LEGACY_ASSETS_DIR, MEDIA_DECLARATIONS_DIR, MEDIA_DIR, MEDIA_PROVENANCE_FILE, mediaDeclarations, readMediaProvenance, } from './media.js';
|
|
30
|
+
export { ATOM_FAMILIES, SUPPORTED_FORMAT_MAJOR, validatePack, } from './validate.js';
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAA+E,MAAM,YAAY,CAAA;AACnH,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnH,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAA;AACvG,OAAO,EACL,cAAc,EACd,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,GAEZ,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EACL,WAAW,EACX,cAAc,EACd,aAAa,GAEd,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,GAIpB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,YAAY,GAGb,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The derived manifest: what a build computes from the folder, never what a
|
|
3
|
+
* person writes.
|
|
4
|
+
*
|
|
5
|
+
* @module @pwfabric/pack/manifest
|
|
6
|
+
*/
|
|
7
|
+
import { type AtomRef, type PwpackManifest } from '@pwfabric/contracts';
|
|
8
|
+
import { type PackFolder } from './types.js';
|
|
9
|
+
/** The identity file at the root of a pack folder. */
|
|
10
|
+
export declare const IDENTITY_FILE = "pwpack.json";
|
|
11
|
+
/** One classified file: its atom, and the directory that holds the atom. */
|
|
12
|
+
export interface AtomOccurrence {
|
|
13
|
+
readonly ref: AtomRef;
|
|
14
|
+
/** Atom directory: the path minus its file name. Files of one atom share it. */
|
|
15
|
+
readonly dir: string;
|
|
16
|
+
}
|
|
17
|
+
/** Every file that classifies as an atom, in byte order of the path. */
|
|
18
|
+
export declare function atomOccurrences(pack: PackFolder): AtomOccurrence[];
|
|
19
|
+
/**
|
|
20
|
+
* The pack's atoms, one per `kind:id`, as `PwpackManifest.atoms` carries them.
|
|
21
|
+
*
|
|
22
|
+
* Classification is the contracts' `classifyAtom`, so the canonical
|
|
23
|
+
* (`atoms/blocks/…`) and legacy rootless (`blocks/…`) layouts both count.
|
|
24
|
+
* When several files classify as the same atom, the first in byte order of
|
|
25
|
+
* the path wins (so an `auth/AuthProvider.knowledge.json` is the auth atom,
|
|
26
|
+
* not `AuthProvider.tsx`). `relPath` is the path as it is in this pack;
|
|
27
|
+
* `contentHash` is the bare hex sha256 of that file. Sorted by kind, then
|
|
28
|
+
* id, in byte order.
|
|
29
|
+
*/
|
|
30
|
+
export declare function deriveAtoms(pack: PackFolder): AtomRef[];
|
|
31
|
+
/** `pwpack.json` as an object, or `null` when it is absent or not a JSON object. */
|
|
32
|
+
export declare function readIdentityJson(pack: PackFolder): Record<string, unknown> | null;
|
|
33
|
+
/** Text without a leading byte-order mark. */
|
|
34
|
+
export declare function stripBom(text: string): string;
|
|
35
|
+
export interface DeriveManifestOptions {
|
|
36
|
+
/** The `.pwpack` bytes the manifest describes; `contentHash` and `storageRef` are taken from them. */
|
|
37
|
+
readonly archive: Uint8Array;
|
|
38
|
+
/** Overrides `pwpack.json` `id`. */
|
|
39
|
+
readonly id?: string;
|
|
40
|
+
/** Overrides `pwpack.json` `version`. */
|
|
41
|
+
readonly version?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A full `PwpackManifest` for a pack and its archive.
|
|
45
|
+
*
|
|
46
|
+
* `id` / `version` come from the options or `pwpack.json`; `license` from
|
|
47
|
+
* `pwpack.json` when it parses. `contentHash` is {@link legacyContentHash} of
|
|
48
|
+
* the archive and `storageRef` is `pwpacks/<slug>/<version>/<first 12 hex>.tgz`
|
|
49
|
+
* with `slug` = the id without its leading `@`, `/` turned into `-` — the
|
|
50
|
+
* values existing publishers record. Throws `IDENTITY_REQUIRED` when no id or
|
|
51
|
+
* version can be found.
|
|
52
|
+
*/
|
|
53
|
+
export declare function deriveManifest(pack: PackFolder, options: DeriveManifestOptions): PwpackManifest;
|
|
54
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAyC,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAIvD,sDAAsD;AACtD,eAAO,MAAM,aAAa,gBAAgB,CAAA;AAE1C,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;IACrB,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,EAAE,CAWlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,EAAE,CAOvD;AAED,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CASjF;AAED,8CAA8C;AAC9C,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,MAAM,WAAW,qBAAqB;IACpC,sGAAsG;IACtG,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;IAC5B,oCAAoC;IACpC,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAmB/F"}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The derived manifest: what a build computes from the folder, never what a
|
|
3
|
+
* person writes.
|
|
4
|
+
*
|
|
5
|
+
* @module @pwfabric/pack/manifest
|
|
6
|
+
*/
|
|
7
|
+
import { classifyAtom, safeParsePwpackIdentity } from '@pwfabric/contracts';
|
|
8
|
+
import { PackError } from './types.js';
|
|
9
|
+
import { compareBytes, sortedPaths } from './paths.js';
|
|
10
|
+
import { legacyContentHash, sha256Hex } from './hash.js';
|
|
11
|
+
/** The identity file at the root of a pack folder. */
|
|
12
|
+
export const IDENTITY_FILE = 'pwpack.json';
|
|
13
|
+
/** Every file that classifies as an atom, in byte order of the path. */
|
|
14
|
+
export function atomOccurrences(pack) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const path of sortedPaths(pack.files.keys())) {
|
|
17
|
+
const atom = classifyAtom(path);
|
|
18
|
+
if (!atom)
|
|
19
|
+
continue;
|
|
20
|
+
out.push({
|
|
21
|
+
ref: { kind: atom.kind, id: atom.id, relPath: path, contentHash: sha256Hex(pack.files.get(path)) },
|
|
22
|
+
dir: path.slice(0, path.lastIndexOf('/') + 1),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The pack's atoms, one per `kind:id`, as `PwpackManifest.atoms` carries them.
|
|
29
|
+
*
|
|
30
|
+
* Classification is the contracts' `classifyAtom`, so the canonical
|
|
31
|
+
* (`atoms/blocks/…`) and legacy rootless (`blocks/…`) layouts both count.
|
|
32
|
+
* When several files classify as the same atom, the first in byte order of
|
|
33
|
+
* the path wins (so an `auth/AuthProvider.knowledge.json` is the auth atom,
|
|
34
|
+
* not `AuthProvider.tsx`). `relPath` is the path as it is in this pack;
|
|
35
|
+
* `contentHash` is the bare hex sha256 of that file. Sorted by kind, then
|
|
36
|
+
* id, in byte order.
|
|
37
|
+
*/
|
|
38
|
+
export function deriveAtoms(pack) {
|
|
39
|
+
const byKey = new Map();
|
|
40
|
+
for (const { ref } of atomOccurrences(pack)) {
|
|
41
|
+
const key = `${ref.kind}:${ref.id}`;
|
|
42
|
+
if (!byKey.has(key))
|
|
43
|
+
byKey.set(key, ref);
|
|
44
|
+
}
|
|
45
|
+
return [...byKey.values()].sort((a, b) => compareBytes(a.kind, b.kind) || compareBytes(a.id, b.id));
|
|
46
|
+
}
|
|
47
|
+
/** `pwpack.json` as an object, or `null` when it is absent or not a JSON object. */
|
|
48
|
+
export function readIdentityJson(pack) {
|
|
49
|
+
const bytes = pack.files.get(IDENTITY_FILE);
|
|
50
|
+
if (!bytes)
|
|
51
|
+
return null;
|
|
52
|
+
try {
|
|
53
|
+
const value = JSON.parse(stripBom(new TextDecoder().decode(bytes)));
|
|
54
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Text without a leading byte-order mark. */
|
|
61
|
+
export function stripBom(text) {
|
|
62
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A full `PwpackManifest` for a pack and its archive.
|
|
66
|
+
*
|
|
67
|
+
* `id` / `version` come from the options or `pwpack.json`; `license` from
|
|
68
|
+
* `pwpack.json` when it parses. `contentHash` is {@link legacyContentHash} of
|
|
69
|
+
* the archive and `storageRef` is `pwpacks/<slug>/<version>/<first 12 hex>.tgz`
|
|
70
|
+
* with `slug` = the id without its leading `@`, `/` turned into `-` — the
|
|
71
|
+
* values existing publishers record. Throws `IDENTITY_REQUIRED` when no id or
|
|
72
|
+
* version can be found.
|
|
73
|
+
*/
|
|
74
|
+
export function deriveManifest(pack, options) {
|
|
75
|
+
const raw = readIdentityJson(pack);
|
|
76
|
+
const id = options.id ?? (typeof raw?.['id'] === 'string' ? raw['id'] : undefined);
|
|
77
|
+
const version = options.version ?? (typeof raw?.['version'] === 'string' ? raw['version'] : undefined);
|
|
78
|
+
if (!id || !version) {
|
|
79
|
+
throw new PackError('IDENTITY_REQUIRED', 'a manifest needs an id and a version (from pwpack.json or the options)');
|
|
80
|
+
}
|
|
81
|
+
const parsed = raw ? safeParsePwpackIdentity(raw) : null;
|
|
82
|
+
const license = parsed?.ok ? parsed.value.license : undefined;
|
|
83
|
+
const contentHash = legacyContentHash(options.archive);
|
|
84
|
+
const slug = id.replace(/^@/, '').replace(/\//g, '-');
|
|
85
|
+
return {
|
|
86
|
+
id,
|
|
87
|
+
version,
|
|
88
|
+
atoms: deriveAtoms(pack),
|
|
89
|
+
contentHash,
|
|
90
|
+
storageRef: `pwpacks/${slug}/${version}/${contentHash.slice('sha256:'.length, 'sha256:'.length + 12)}.tgz`,
|
|
91
|
+
...(license ? { license } : {}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAqC,MAAM,qBAAqB,CAAA;AAC9G,OAAO,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAExD,sDAAsD;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAA;AAS1C,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAAC,IAAgB;IAC9C,MAAM,GAAG,GAAqB,EAAE,CAAA;IA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GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtG,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CAAC,mBAAmB,EAAE,wEAAwE,CAAC,CAAA;IACpH,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACxD,MAAM,OAAO,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;IAC7D,MAAM,WAAW,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACtD,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACrD,OAAO;QACL,EAAE;QACF,OAAO;QACP,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC;QACxB,WAAW;QACX,UAAU,EAAE,WAAW,IAAI,IAAI,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM;QAC1G,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChC,CAAA;AACH,CAAC"}
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media: an app's media declarations and the bytes they name.
|
|
3
|
+
*
|
|
4
|
+
* app/media/<key>.json one declaration: which image or file, which page slots
|
|
5
|
+
* media/<name> the bytes (images, video, fonts)
|
|
6
|
+
* media/provenance.json where each file under media/ came from, and its hash
|
|
7
|
+
*
|
|
8
|
+
* {@link mediaDeclarations} is the one reader of that layout, so a host that
|
|
9
|
+
* ingests a pack, a generator that writes one and the CLI that serves one do
|
|
10
|
+
* not each re-implement it.
|
|
11
|
+
*
|
|
12
|
+
* @module @pwfabric/pack/media
|
|
13
|
+
*/
|
|
14
|
+
import { type MediaDeclaration, type MediaProvenance, type MediaProvenanceEntry } from '@pwfabric/contracts';
|
|
15
|
+
import type { PackFolder, PackIssue } from './types.js';
|
|
16
|
+
/** The provenance record of the media a pack carries. */
|
|
17
|
+
export declare const MEDIA_PROVENANCE_FILE = "media/provenance.json";
|
|
18
|
+
/** Where media bytes live. */
|
|
19
|
+
export declare const MEDIA_DIR = "media/";
|
|
20
|
+
/** Where media declarations live: `app/media/<key>.json`. */
|
|
21
|
+
export declare const MEDIA_DECLARATIONS_DIR = "app/media/";
|
|
22
|
+
/** A folder no pack may carry: declarations and bytes live in `app/media/` and `media/`. */
|
|
23
|
+
export declare const LEGACY_ASSETS_DIR = "app/assets/";
|
|
24
|
+
/** One declaration, with the bytes it names when the pack carries them. */
|
|
25
|
+
export interface PackMediaDeclaration {
|
|
26
|
+
/** The declaration's key: its file name without `.json`. */
|
|
27
|
+
readonly key: string;
|
|
28
|
+
/** The declaration file, `app/media/<key>.json`. */
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly declaration: MediaDeclaration;
|
|
31
|
+
/** Pack path of the bytes `file` names, when the pack carries them (`media/hero.webp`). */
|
|
32
|
+
readonly filePath?: string;
|
|
33
|
+
readonly bytes?: Uint8Array;
|
|
34
|
+
/** The provenance entry for `filePath`, when `media/provenance.json` is valid and lists it. */
|
|
35
|
+
readonly provenance?: MediaProvenanceEntry;
|
|
36
|
+
}
|
|
37
|
+
export interface PackMedia {
|
|
38
|
+
/** Valid declarations, in byte order of their path. Invalid ones are reported in `issues` and left out. */
|
|
39
|
+
readonly declarations: readonly PackMediaDeclaration[];
|
|
40
|
+
/** `media/provenance.json`, when present and valid. */
|
|
41
|
+
readonly provenance: MediaProvenance | null;
|
|
42
|
+
/** What `validatePack` reports about media declarations. */
|
|
43
|
+
readonly issues: readonly PackIssue[];
|
|
44
|
+
}
|
|
45
|
+
/** `media/provenance.json`, parsed: absent, invalid (with its issues) or valid. */
|
|
46
|
+
export type ProvenanceRead = {
|
|
47
|
+
readonly state: 'absent';
|
|
48
|
+
} | {
|
|
49
|
+
readonly state: 'invalid';
|
|
50
|
+
readonly issues: readonly string[];
|
|
51
|
+
} | {
|
|
52
|
+
readonly state: 'valid';
|
|
53
|
+
readonly value: MediaProvenance;
|
|
54
|
+
};
|
|
55
|
+
/** Read and check `media/provenance.json`. */
|
|
56
|
+
export declare function readMediaProvenance(pack: PackFolder): ProvenanceRead;
|
|
57
|
+
/**
|
|
58
|
+
* The pack's media declarations (`app/media/<key>.json`), each with the bytes
|
|
59
|
+
* its `file` names (a pack path, `media/<name>`) and that file's provenance
|
|
60
|
+
* entry.
|
|
61
|
+
*
|
|
62
|
+
* Findings (also reported by `validatePack`, all errors unless noted):
|
|
63
|
+
* - `LEGACY_ASSETS_FOLDER` — a file under `app/assets/`. Nothing there is
|
|
64
|
+
* read: declarations belong in `app/media/`, bytes in `media/`.
|
|
65
|
+
* - `MEDIA_DECLARATION_INVALID` — a declaration that parses as JSON but
|
|
66
|
+
* breaks its schema; it is left out. (Not JSON at all is `JSON_INVALID`,
|
|
67
|
+
* reported by `validatePack`.)
|
|
68
|
+
* - `MEDIA_FILE_MISSING` — `file` names bytes the pack does not carry.
|
|
69
|
+
* - `MEDIA_FILE_UNRECORDED` — `file`'s bytes have no entry in
|
|
70
|
+
* `media/provenance.json`. Not reported when the record is itself invalid
|
|
71
|
+
* (`MEDIA_PROVENANCE_INVALID` covers it).
|
|
72
|
+
* - `APP_UNEXPECTED_FILE` (warning) — a file under `app/media/` that is not
|
|
73
|
+
* `<key>.json`.
|
|
74
|
+
*
|
|
75
|
+
* Never throws for content problems.
|
|
76
|
+
*/
|
|
77
|
+
export declare function mediaDeclarations(pack: PackFolder): PackMedia;
|
|
78
|
+
//# sourceMappingURL=media.d.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