@johnhenry/sitefile 0.0.0-stage → 0.0.1
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/CHANGELOG.md +152 -0
- package/LICENSE +21 -0
- package/README.md +513 -2
- package/lib/src/archive-writers.d.ts +31 -0
- package/lib/src/archive-writers.js +197 -0
- package/lib/src/attest.d.ts +126 -0
- package/lib/src/attest.js +220 -0
- package/lib/src/bake.d.ts +74 -0
- package/lib/src/bake.js +372 -0
- package/lib/src/base-image.d.ts +76 -0
- package/lib/src/base-image.js +138 -0
- package/lib/src/build-args.d.ts +26 -0
- package/lib/src/build-args.js +164 -0
- package/lib/src/cache-limit.d.ts +54 -0
- package/lib/src/cache-limit.js +239 -0
- package/lib/src/casefold-data.d.ts +2 -0
- package/lib/src/casefold-data.js +217 -0
- package/lib/src/cbor.d.ts +39 -0
- package/lib/src/cbor.js +174 -0
- package/lib/src/checklinks.d.ts +42 -0
- package/lib/src/checklinks.js +120 -0
- package/lib/src/cli/bake.d.ts +2 -0
- package/lib/src/cli/bake.js +179 -0
- package/lib/src/cli/build-image.d.ts +21 -0
- package/lib/src/cli/build-image.js +42 -0
- package/lib/src/cli/cache.d.ts +8 -0
- package/lib/src/cli/cache.js +119 -0
- package/lib/src/cli/common.d.ts +29 -0
- package/lib/src/cli/common.js +100 -0
- package/lib/src/cli/git-context.d.ts +18 -0
- package/lib/src/cli/git-context.js +48 -0
- package/lib/src/cli/images.d.ts +6 -0
- package/lib/src/cli/images.js +285 -0
- package/lib/src/cli/index.d.ts +10 -0
- package/lib/src/cli/index.js +95 -0
- package/lib/src/cli/network.d.ts +34 -0
- package/lib/src/cli/network.js +56 -0
- package/lib/src/cli/outdated.d.ts +5 -0
- package/lib/src/cli/outdated.js +99 -0
- package/lib/src/cli/registry.d.ts +2 -0
- package/lib/src/cli/registry.js +127 -0
- package/lib/src/cli/serve-worker.d.ts +2 -0
- package/lib/src/cli/serve-worker.js +42 -0
- package/lib/src/cli/servers.d.ts +15 -0
- package/lib/src/cli/servers.js +467 -0
- package/lib/src/cli/vendor.d.ts +2 -0
- package/lib/src/cli/vendor.js +97 -0
- package/lib/src/cli/watch.d.ts +26 -0
- package/lib/src/cli/watch.js +81 -0
- package/lib/src/cli.d.ts +12 -0
- package/lib/src/cli.js +522 -0
- package/lib/src/csv.d.ts +27 -0
- package/lib/src/csv.js +117 -0
- package/lib/src/deflate.d.ts +76 -0
- package/lib/src/deflate.js +604 -0
- package/lib/src/digest.d.ts +3 -0
- package/lib/src/digest.js +7 -0
- package/lib/src/errors.d.ts +56 -0
- package/lib/src/errors.js +29 -0
- package/lib/src/executor.d.ts +393 -0
- package/lib/src/executor.js +2201 -0
- package/lib/src/explain.d.ts +64 -0
- package/lib/src/explain.js +445 -0
- package/lib/src/export-formats.d.ts +23 -0
- package/lib/src/export-formats.js +63 -0
- package/lib/src/exporter.d.ts +103 -0
- package/lib/src/exporter.js +676 -0
- package/lib/src/fingerprint.d.ts +40 -0
- package/lib/src/fingerprint.js +168 -0
- package/lib/src/frontmatter.d.ts +22 -0
- package/lib/src/frontmatter.js +45 -0
- package/lib/src/index.d.ts +13 -0
- package/lib/src/index.js +13 -0
- package/lib/src/language/ast.d.ts +360 -0
- package/lib/src/language/ast.js +57 -0
- package/lib/src/language/parser.d.ts +3 -0
- package/lib/src/language/parser.js +612 -0
- package/lib/src/language/scanner.d.ts +110 -0
- package/lib/src/language/scanner.js +449 -0
- package/lib/src/language/validate.d.ts +13 -0
- package/lib/src/language/validate.js +367 -0
- package/lib/src/links.d.ts +79 -0
- package/lib/src/links.js +583 -0
- package/lib/src/lint.d.ts +10 -0
- package/lib/src/lint.js +223 -0
- package/lib/src/markdown.d.ts +29 -0
- package/lib/src/markdown.js +612 -0
- package/lib/src/media.d.ts +82 -0
- package/lib/src/media.js +650 -0
- package/lib/src/memo.d.ts +57 -0
- package/lib/src/memo.js +93 -0
- package/lib/src/oci.d.ts +178 -0
- package/lib/src/oci.js +380 -0
- package/lib/src/outdated.d.ts +46 -0
- package/lib/src/outdated.js +195 -0
- package/lib/src/pages.d.ts +10 -0
- package/lib/src/pages.js +54 -0
- package/lib/src/paths.d.ts +39 -0
- package/lib/src/paths.js +101 -0
- package/lib/src/planner.d.ts +297 -0
- package/lib/src/planner.js +410 -0
- package/lib/src/plugins/cache.d.ts +96 -0
- package/lib/src/plugins/cache.js +325 -0
- package/lib/src/plugins/exec.d.ts +51 -0
- package/lib/src/plugins/exec.js +144 -0
- package/lib/src/plugins/host.d.ts +75 -0
- package/lib/src/plugins/host.js +277 -0
- package/lib/src/plugins/wasm.d.ts +23 -0
- package/lib/src/plugins/wasm.js +249 -0
- package/lib/src/profile.d.ts +42 -0
- package/lib/src/profile.js +68 -0
- package/lib/src/ref.d.ts +40 -0
- package/lib/src/ref.js +79 -0
- package/lib/src/registry-auth.d.ts +32 -0
- package/lib/src/registry-auth.js +151 -0
- package/lib/src/registry-cache.d.ts +71 -0
- package/lib/src/registry-cache.js +333 -0
- package/lib/src/registry-ops.d.ts +51 -0
- package/lib/src/registry-ops.js +248 -0
- package/lib/src/registry.d.ts +115 -0
- package/lib/src/registry.js +524 -0
- package/lib/src/render.d.ts +134 -0
- package/lib/src/render.js +576 -0
- package/lib/src/resources/archive.d.ts +11 -0
- package/lib/src/resources/archive.js +306 -0
- package/lib/src/resources/bundle-data.d.ts +16 -0
- package/lib/src/resources/bundle-data.js +50 -0
- package/lib/src/resources/convert.d.ts +12 -0
- package/lib/src/resources/convert.js +63 -0
- package/lib/src/resources/documents.d.ts +35 -0
- package/lib/src/resources/documents.js +122 -0
- package/lib/src/resources/git.d.ts +103 -0
- package/lib/src/resources/git.js +720 -0
- package/lib/src/resources/https.d.ts +74 -0
- package/lib/src/resources/https.js +413 -0
- package/lib/src/resources/ignore.d.ts +33 -0
- package/lib/src/resources/ignore.js +119 -0
- package/lib/src/resources/local.d.ts +64 -0
- package/lib/src/resources/local.js +248 -0
- package/lib/src/resources/lockfile.d.ts +52 -0
- package/lib/src/resources/lockfile.js +172 -0
- package/lib/src/resources/netpolicy.d.ts +6 -0
- package/lib/src/resources/netpolicy.js +82 -0
- package/lib/src/resources/network.d.ts +70 -0
- package/lib/src/resources/network.js +304 -0
- package/lib/src/resources/types.d.ts +69 -0
- package/lib/src/resources/types.js +13 -0
- package/lib/src/resources/vendor.d.ts +94 -0
- package/lib/src/resources/vendor.js +296 -0
- package/lib/src/resources/wbn-reader.d.ts +44 -0
- package/lib/src/resources/wbn-reader.js +302 -0
- package/lib/src/schema.d.ts +25 -0
- package/lib/src/schema.js +169 -0
- package/lib/src/secrets.d.ts +21 -0
- package/lib/src/secrets.js +103 -0
- package/lib/src/serve-rules.d.ts +29 -0
- package/lib/src/serve-rules.js +123 -0
- package/lib/src/server.d.ts +45 -0
- package/lib/src/server.js +246 -0
- package/lib/src/servers.d.ts +85 -0
- package/lib/src/servers.js +225 -0
- package/lib/src/site.d.ts +60 -0
- package/lib/src/site.js +169 -0
- package/lib/src/store.d.ts +151 -0
- package/lib/src/store.js +596 -0
- package/lib/src/tree.d.ts +50 -0
- package/lib/src/tree.js +134 -0
- package/lib/src/values.d.ts +7 -0
- package/lib/src/values.js +37 -0
- package/lib/src/vendor.d.ts +19 -0
- package/lib/src/vendor.js +145 -0
- package/lib/src/watch.d.ts +44 -0
- package/lib/src/watch.js +137 -0
- package/lib/src/wbn.d.ts +26 -0
- package/lib/src/wbn.js +241 -0
- package/lib/src/yaml.d.ts +34 -0
- package/lib/src/yaml.js +562 -0
- package/package.json +59 -4
package/lib/src/csv.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SitefileError } from './errors.js';
|
|
2
|
+
export function parseCsv(text, file, options = {}) {
|
|
3
|
+
const header = options.header ?? true;
|
|
4
|
+
const delim = options.delimiter ?? ',';
|
|
5
|
+
const rows = tokenize(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text, file, delim);
|
|
6
|
+
if (!header)
|
|
7
|
+
return rows.map((r) => r.fields);
|
|
8
|
+
const head = rows[0];
|
|
9
|
+
if (!head)
|
|
10
|
+
return [];
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
head.fields.forEach((name, i) => {
|
|
13
|
+
const span = { file, line: head.line, column: head.cols[i] };
|
|
14
|
+
if (name === '')
|
|
15
|
+
throw new SitefileError('E_DATA', `empty CSV column name in header (column ${i + 1})`, span);
|
|
16
|
+
if (seen.has(name))
|
|
17
|
+
throw new SitefileError('E_DATA', `duplicate CSV column name '${name}'`, span);
|
|
18
|
+
seen.add(name);
|
|
19
|
+
});
|
|
20
|
+
return rows.slice(1).map((row) => {
|
|
21
|
+
if (row.fields.length !== head.fields.length) {
|
|
22
|
+
throw new SitefileError('E_DATA', `expected ${head.fields.length} field${head.fields.length === 1 ? '' : 's'} but found ${row.fields.length}`, { file, line: row.line, column: 1 });
|
|
23
|
+
}
|
|
24
|
+
// fromEntries defines own data properties, so `__proto__` is safe.
|
|
25
|
+
return Object.fromEntries(head.fields.map((name, i) => [name, row.fields[i]]));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function parseCsvRecords(text, file) {
|
|
29
|
+
return parseCsv(text, file, { header: true });
|
|
30
|
+
}
|
|
31
|
+
function tokenize(text, file, delim) {
|
|
32
|
+
const n = text.length;
|
|
33
|
+
const rows = [];
|
|
34
|
+
let i = 0;
|
|
35
|
+
let line = 1;
|
|
36
|
+
let lineStart = 0;
|
|
37
|
+
const fail = (detail, l, index, ls) => {
|
|
38
|
+
throw new SitefileError('E_DATA', detail, { file, line: l, column: index - ls + 1 });
|
|
39
|
+
};
|
|
40
|
+
while (i < n) {
|
|
41
|
+
// Skip fully empty lines.
|
|
42
|
+
if (text[i] === '\n') {
|
|
43
|
+
i++;
|
|
44
|
+
line++;
|
|
45
|
+
lineStart = i;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (text[i] === '\r' && text[i + 1] === '\n') {
|
|
49
|
+
i += 2;
|
|
50
|
+
line++;
|
|
51
|
+
lineStart = i;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const row = { fields: [], cols: [], line };
|
|
55
|
+
for (;;) {
|
|
56
|
+
row.cols.push(i - lineStart + 1);
|
|
57
|
+
let field = '';
|
|
58
|
+
if (text[i] === '"') {
|
|
59
|
+
const qLine = line;
|
|
60
|
+
const qIndex = i;
|
|
61
|
+
const qStart = lineStart;
|
|
62
|
+
i++;
|
|
63
|
+
for (;;) {
|
|
64
|
+
if (i >= n)
|
|
65
|
+
return fail('unterminated quoted field', qLine, qIndex, qStart);
|
|
66
|
+
const c = text[i];
|
|
67
|
+
if (c === '"') {
|
|
68
|
+
if (text[i + 1] === '"') {
|
|
69
|
+
field += '"';
|
|
70
|
+
i += 2;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
i++;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
if (c === '\n') {
|
|
77
|
+
line++;
|
|
78
|
+
lineStart = i + 1;
|
|
79
|
+
}
|
|
80
|
+
field += c;
|
|
81
|
+
i++;
|
|
82
|
+
}
|
|
83
|
+
const after = text[i];
|
|
84
|
+
const atEnd = i >= n || after === delim || after === '\n' || (after === '\r' && text[i + 1] === '\n');
|
|
85
|
+
if (!atEnd)
|
|
86
|
+
return fail('unexpected character after closing quote', line, i, lineStart);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const s = i;
|
|
90
|
+
while (i < n) {
|
|
91
|
+
const c = text[i];
|
|
92
|
+
if (c === delim || c === '\n' || (c === '\r' && text[i + 1] === '\n'))
|
|
93
|
+
break;
|
|
94
|
+
if (c === '"')
|
|
95
|
+
return fail('quote inside an unquoted field', line, i, lineStart);
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
field = text.slice(s, i);
|
|
99
|
+
}
|
|
100
|
+
row.fields.push(field);
|
|
101
|
+
if (i >= n)
|
|
102
|
+
break;
|
|
103
|
+
if (text[i] === delim) {
|
|
104
|
+
i++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// Record terminator.
|
|
108
|
+
i += text[i] === '\r' ? 2 : 1;
|
|
109
|
+
line++;
|
|
110
|
+
lineStart = i;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
rows.push(row);
|
|
114
|
+
}
|
|
115
|
+
return rows;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=csv.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic DEFLATE (RFC 1951) and gzip (RFC 1952) encoder.
|
|
3
|
+
*
|
|
4
|
+
* `rust/src/deflate.rs` implements the same algorithm and must produce the same
|
|
5
|
+
* bytes for every input, so that archives and OCI layers (and therefore image
|
|
6
|
+
* IDs) are identical between the two implementations. Any change here must be
|
|
7
|
+
* made in both files, and the differential fixtures regenerated
|
|
8
|
+
* (`node rust/tests/fixtures/deflate/generate.mjs`). Decompression is not
|
|
9
|
+
* affected: any inflater reads this output.
|
|
10
|
+
*
|
|
11
|
+
* Specification (every choice below is part of the output format):
|
|
12
|
+
*
|
|
13
|
+
* LZ77 matching
|
|
14
|
+
* - Window 32768 bytes; matches are 3..258 bytes at distance 1..32768.
|
|
15
|
+
* - Hash of position p (only when p + 3 <= n): x = d[p] << 16 | d[p+1] << 8 | d[p+2];
|
|
16
|
+
* h = (x * 0x9E3779B1 mod 2^32) >> 17 (15 bits). `head[h]` holds the most
|
|
17
|
+
* recent inserted position with that hash, `prev[p & 32767]` the position
|
|
18
|
+
* that was in `head[h]` when p was inserted (-1 = none).
|
|
19
|
+
* - findMatch(p): if p + 3 > n, no match. Otherwise walk the chain starting
|
|
20
|
+
* at head[h(p)]: candidate c is considered while c >= 0, p - c <= 32768 and
|
|
21
|
+
* fewer than MAX_CHAIN (64) candidates have been considered; the next
|
|
22
|
+
* candidate is prev[c & 32767], and the walk stops if that is not < c.
|
|
23
|
+
* For each candidate, len = length of the common prefix of d[c..] and
|
|
24
|
+
* d[p..], at most min(258, n - p). A candidate replaces the best only if
|
|
25
|
+
* len > bestLen (so on ties the nearest wins); the walk stops once
|
|
26
|
+
* bestLen >= 258 (or reaches min(258, n - p)). Then p is inserted.
|
|
27
|
+
* A best match of length 3 at distance > 4096 is dropped (no match).
|
|
28
|
+
* - Every position p with p + 3 <= n is inserted exactly once, in increasing
|
|
29
|
+
* order, before findMatch is called for any later position.
|
|
30
|
+
* - Parsing (lazy, one position at a time): at p, m = findMatch(p). If
|
|
31
|
+
* m.len < 3: literal d[p], p += 1. Otherwise, while m.len < LAZY_LIMIT (16)
|
|
32
|
+
* and p + 1 < n: m2 = findMatch(p + 1), searching at most MAX_CHAIN / 4 (16)
|
|
33
|
+
* candidates when m.len >= GOOD_LENGTH (8); if m2.len > m.len, emit literal
|
|
34
|
+
* d[p], p += 1, m = m2 and repeat; else stop. Then emit match m at p, insert
|
|
35
|
+
* the positions up to p + m.len - 1 that are not yet inserted, p += m.len.
|
|
36
|
+
*
|
|
37
|
+
* Blocks
|
|
38
|
+
* - Symbols (literals and length/distance pairs) are buffered. At the start
|
|
39
|
+
* of each parsing step (p < n), if the buffer holds >= BLOCK_SYMBOLS (16384)
|
|
40
|
+
* symbols it is written as a non-final block. When the input is exhausted
|
|
41
|
+
* the remaining symbols (none only for empty input) are written as the
|
|
42
|
+
* final block (BFINAL = 1).
|
|
43
|
+
* - Each block is written as whichever of stored, fixed Huffman or dynamic
|
|
44
|
+
* Huffman takes the fewest bits, given the current bit position; on a tie
|
|
45
|
+
* the earlier of stored, fixed, dynamic wins. Stored is a candidate only
|
|
46
|
+
* when the block covers <= 65535 input bytes; its cost is 3 header bits,
|
|
47
|
+
* padding to a byte boundary, 32 bits of LEN/NLEN and 8 bits per byte.
|
|
48
|
+
* - Huffman code lengths (literal/length tree max 15 bits, distance tree max
|
|
49
|
+
* 15, code-length tree max 7) come from package-merge: leaves are the
|
|
50
|
+
* symbols with nonzero frequency sorted by (frequency, symbol); L - 1 times,
|
|
51
|
+
* pair consecutive items of the previous list (dropping an odd last item)
|
|
52
|
+
* into packages and merge them with the leaves by weight, a leaf before a
|
|
53
|
+
* package on equal weight; a symbol's length is the number of times it
|
|
54
|
+
* occurs in the first 2k - 2 items of the final list (k = leaf count). If
|
|
55
|
+
* fewer than two symbols are used, the used one (if any) and the lowest
|
|
56
|
+
* unused symbols are added until there are two, each with length 1.
|
|
57
|
+
* Codes are canonical (RFC 1951 3.2.2).
|
|
58
|
+
* - Dynamic header: HLIT = max(257, last used literal/length symbol + 1),
|
|
59
|
+
* HDIST = max(1, last used distance symbol + 1) (an unused tree still has
|
|
60
|
+
* two length-1 codes, so this is at least 2); HCLEN = max(4, last nonzero
|
|
61
|
+
* entry in the order 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 + 1).
|
|
62
|
+
* The HLIT + HDIST lengths form one sequence, run-length coded left to
|
|
63
|
+
* right: for value v with run r of equal values starting here, if v = 0:
|
|
64
|
+
* r >= 11 → 18 (min(r, 138)), r >= 3 → 17 (r), else a single 0; if v != 0:
|
|
65
|
+
* emit v once, then while the rest of the run is >= 3, 16 (min(rest, 6)).
|
|
66
|
+
*
|
|
67
|
+
* gzip: header 1f 8b 08, FLG 0, MTIME 0, XFL 0, OS 3 (Unix), then the raw
|
|
68
|
+
* deflate stream, CRC-32 and ISIZE (little-endian).
|
|
69
|
+
*/
|
|
70
|
+
/** Package-merge length-limited Huffman code lengths. */
|
|
71
|
+
export declare function codeLengths(freq: ArrayLike<number>, maxBits: number): Uint8Array;
|
|
72
|
+
/** Raw DEFLATE stream (zip method 8). */
|
|
73
|
+
export declare function deflateRaw(data: Uint8Array): Uint8Array;
|
|
74
|
+
export declare function crc32(data: Uint8Array): number;
|
|
75
|
+
/** gzip member with a fixed header (no mtime, no name, XFL 0, OS 3). */
|
|
76
|
+
export declare function gzip(data: Uint8Array): Uint8Array;
|