rvlib-shipkit 2.15.0 → 2.16.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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/checks/SK038-speaks-as.check.ts +66 -0
- package/src/cli/cmd_Drill.ts +219 -12
- package/src/cli/cmd_Media.ts +34 -8
- package/src/cli/cmd_Social.ts +19 -9
- package/src/cli/registry.ts +4 -1
- package/src/drill/card.ts +65 -0
- package/src/drill/clean.ts +17 -6
- package/src/drill/finish.ts +67 -0
- package/src/drill/render.ts +21 -2
- package/src/drill/run.ts +51 -2
- package/src/drill/score.ts +68 -0
- package/src/drill/seal.ts +259 -0
- package/src/home/home-paths.ts +10 -1
- package/src/init-repo.ts +14 -4
- package/src/media-store/content.ts +1 -1
- package/src/media-store/hand.ts +6 -1
- package/src/media-store/put.ts +11 -7
- package/src/media-store/space.ts +17 -3
- package/src/repo-config.ts +1 -1
- package/src/serve/hub-app/cols-svc.ts +2 -1
- package/src/social/house.ts +7 -5
package/src/media-store/hand.ts
CHANGED
|
@@ -6,11 +6,15 @@ import { join, resolve } from 'node:path'
|
|
|
6
6
|
import { shaOf, shaOfKey, typeOf } from './content.ts'
|
|
7
7
|
import { mediaDb } from './db.ts'
|
|
8
8
|
import type { MediaKind, MediaRow } from './kind.ts'
|
|
9
|
+
import { PUBLIC_PREFIX } from './space.ts'
|
|
9
10
|
|
|
10
11
|
/** a label `sk media put` takes: the key prefix in the Space */
|
|
11
12
|
export const LABEL = /^[a-z0-9-]+$/
|
|
12
13
|
export const DEFAULT_LABEL = 'files'
|
|
13
14
|
|
|
15
|
+
/** the label every `public/<label>/` key reads as (the first segment of its key) */
|
|
16
|
+
export const PUBLIC_LABEL = PUBLIC_PREFIX.slice(0, -1)
|
|
17
|
+
|
|
14
18
|
/** the stores the index holds rows of under this label */
|
|
15
19
|
function storesOf(label: string): string[] {
|
|
16
20
|
const db = mediaDb()
|
|
@@ -48,7 +52,8 @@ export function handKind(label: string): MediaKind {
|
|
|
48
52
|
return { rows, filled: 0, left: 0 }
|
|
49
53
|
},
|
|
50
54
|
async holds(store) {
|
|
51
|
-
|
|
55
|
+
// a public file is the repo's working copy, its URL is for those without one: never purged
|
|
56
|
+
return (row) => ({ pinned: label === PUBLIC_LABEL, used: statSync(join(store, row.item, row.name), { throwIfNoEntry: false })?.mtimeMs })
|
|
52
57
|
},
|
|
53
58
|
async beforePurge(store, _space, row) {
|
|
54
59
|
const sha = await shaOf(join(store, row.item, row.name))
|
package/src/media-store/put.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// a file put in the store by hand, and a fresh link to anything it holds (wiki tools/shipkit/media-store.md, Put a file
|
|
2
|
-
// from any repo): the one way a repo's agent keeps a file in the private Space
|
|
2
|
+
// from any repo): the one way a repo's agent keeps a file in the private Space, or publishes one under `public/`. The index row is written before the
|
|
3
3
|
// upload, so a failed upload waits for the daemon like any other; a link lasts at most 7 days, the object for good
|
|
4
4
|
import { realpathSync, statSync } from 'node:fs'
|
|
5
5
|
import { basename, dirname, join, relative } from 'node:path'
|
|
6
6
|
import { findRepoRoot } from '../ts/config.ts'
|
|
7
7
|
import { factOf, mediaKey, shaOf, shaOfKey, typeOf } from './content.ts'
|
|
8
8
|
import { mediaDb } from './db.ts'
|
|
9
|
-
import { DEFAULT_LABEL, LABEL } from './hand.ts'
|
|
9
|
+
import { DEFAULT_LABEL, LABEL, PUBLIC_LABEL } from './hand.ts'
|
|
10
10
|
import { confirmedUp } from './remote.ts'
|
|
11
|
-
import { machineSpace, SIGNED_MAX_S } from './space.ts'
|
|
11
|
+
import { machineSpace, PUBLIC_PREFIX, SIGNED_MAX_S } from './space.ts'
|
|
12
12
|
import { uploadOne } from './upload.ts'
|
|
13
13
|
|
|
14
14
|
/** a duration as seconds: `90s`, `30m`, `2h`, `7d`, or a bare number of seconds; never over 7 days */
|
|
@@ -29,6 +29,8 @@ export interface Put {
|
|
|
29
29
|
name: string
|
|
30
30
|
/** false: the Space already held this content */
|
|
31
31
|
sent: boolean
|
|
32
|
+
/** the permanent URL of a public put */
|
|
33
|
+
url?: string
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export interface Link {
|
|
@@ -56,17 +58,19 @@ function placeOf(file: string): { store: string; item: string; name: string } {
|
|
|
56
58
|
return { store, item: relative(store, dirname(real)), name: basename(real) }
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
/** the file kept by its content under the label: its index row first, then up at once, checked by a HEAD
|
|
60
|
-
|
|
61
|
+
/** the file kept by its content under the label: its index row first, then up at once, checked by a HEAD. `public`: under
|
|
62
|
+
* `public/<label>/`, read by anyone through its URL, never purged from the disk */
|
|
63
|
+
export async function putMedia(file: string, o: { kind?: string; public?: boolean } = {}): Promise<Put> {
|
|
61
64
|
const label = o.kind ?? DEFAULT_LABEL
|
|
62
65
|
if (!LABEL.test(label)) throw new Error(`--kind ${label}: a label is lowercase letters, digits and dashes`)
|
|
66
|
+
if (label === PUBLIC_LABEL) throw new Error(`--kind ${label}: the public folder is --public, under a label of its own`)
|
|
63
67
|
if ((await codeLabels()).has(label)) throw new Error(`--kind ${label}: that kind's files come from its own scan, never a hand put; pick another label`)
|
|
64
68
|
const st = statSync(file, { throwIfNoEntry: false })
|
|
65
69
|
if (!st?.isFile()) throw new Error(`${file}: no such file`)
|
|
66
70
|
const at = placeOf(file)
|
|
67
71
|
const path = join(at.store, at.item, at.name)
|
|
68
72
|
const fact = await factOf(path)
|
|
69
|
-
const key = mediaKey(label, fact, at.name)
|
|
73
|
+
const key = mediaKey(o.public ? `${PUBLIC_PREFIX}${label}` : label, fact, at.name)
|
|
70
74
|
const db = mediaDb()
|
|
71
75
|
if (!db) throw new Error('the media index does not open: nothing is put without its record')
|
|
72
76
|
db.transaction(() => {
|
|
@@ -76,7 +80,7 @@ export async function putMedia(file: string, o: { kind?: string } = {}): Promise
|
|
|
76
80
|
const { space, why } = await machineSpace()
|
|
77
81
|
if (!space) throw new Error(`${key} recorded, not up: ${why}; the daemon sends it once the Space answers`)
|
|
78
82
|
const sent = await uploadOne(space, { key, size: fact.size, path })
|
|
79
|
-
return { key, sha: fact.sha, size: fact.size, name: at.name, sent }
|
|
83
|
+
return { key, sha: fact.sha, size: fact.size, name: at.name, sent, ...(o.public ? { url: space.publicUrl(key) } : {}) }
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/** the key a reference names: a key, a sha (or 12 hex of one), or a file the store holds */
|
package/src/media-store/space.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// the private S3 bucket that keeps every media file of the machine's store (wiki tools/shipkit/media-store.md), named by
|
|
2
|
-
// the house config's `serve.mediaSpace`. Every object is PRIVATE
|
|
3
|
-
//
|
|
2
|
+
// the house config's `serve.mediaSpace`. Every object is PRIVATE but those under `public/`, and the key alone decides
|
|
3
|
+
// (`aclOf`); never a bucket policy, never a public listing. A page reads a private one through a URL signed for one hour,
|
|
4
|
+
// on the CDN edge. The key pair (`KEY:SECRET`) is read through the house's
|
|
4
5
|
// `credsReadCommand`, held in memory only: never written to a file, never printed
|
|
5
6
|
import { S3Client } from 'bun'
|
|
6
7
|
import { mkdirSync, renameSync, rmSync } from 'node:fs'
|
|
@@ -33,6 +34,12 @@ export interface SpaceConfig {
|
|
|
33
34
|
/** how long a signed URL stays good */
|
|
34
35
|
export const SIGNED_S = 3600
|
|
35
36
|
|
|
37
|
+
/** the folder whose objects anyone downloads by URL: nobody lists it (wiki tools/shipkit/media-store.md, Publish a file) */
|
|
38
|
+
export const PUBLIC_PREFIX = 'public/'
|
|
39
|
+
|
|
40
|
+
/** the ACL a key goes up with: public-read under `public/`, private everywhere else */
|
|
41
|
+
export const aclOf = (key: string): 'public-read' | 'private' => (key.startsWith(PUBLIC_PREFIX) ? 'public-read' : 'private')
|
|
42
|
+
|
|
36
43
|
export interface Space {
|
|
37
44
|
/** where the objects live, for a line a person reads (never a credential) */
|
|
38
45
|
readonly where: string
|
|
@@ -43,6 +50,8 @@ export interface Space {
|
|
|
43
50
|
* checks it against (a URL signed for the edge's own host answers SignatureDoesNotMatch). `as` signs a download
|
|
44
51
|
* under that file name: `response-content-disposition` and `response-content-type` ride in the signed query */
|
|
45
52
|
signed(key: string, seconds?: number, as?: { name: string; type: string }): string
|
|
53
|
+
/** the permanent URL of a `public/` object, on the CDN edge when the Space has one; throws for any other key */
|
|
54
|
+
publicUrl(key: string): string
|
|
46
55
|
/** the object written at `to`, through a file beside it renamed: no reader sees half of it */
|
|
47
56
|
get(key: string, to: string): Promise<void>
|
|
48
57
|
/** every object under the prefix, with its size, page after page (ListObjectsV2) */
|
|
@@ -100,7 +109,7 @@ export function spaceOf(c: SpaceConfig): Space {
|
|
|
100
109
|
return {
|
|
101
110
|
where: `${c.cdn ?? c.endpoint} (${c.bucket})`,
|
|
102
111
|
async put(key, file, type) {
|
|
103
|
-
await client.write(key, Bun.file(file), { type, acl:
|
|
112
|
+
await client.write(key, Bun.file(file), { type, acl: aclOf(key) })
|
|
104
113
|
},
|
|
105
114
|
async head(key) {
|
|
106
115
|
try {
|
|
@@ -116,6 +125,11 @@ export function spaceOf(c: SpaceConfig): Space {
|
|
|
116
125
|
if (edge && url.host === origin) url.host = edge
|
|
117
126
|
return url.toString()
|
|
118
127
|
},
|
|
128
|
+
publicUrl(key) {
|
|
129
|
+
if (aclOf(key) !== 'public-read') throw new Error(`${key}: private, it has no public URL (sk media link signs one)`)
|
|
130
|
+
const base = c.cdn ?? (c.path === true ? `${c.endpoint}/${c.bucket}` : c.endpoint)
|
|
131
|
+
return `${base.replace(/\/$/, '')}/${key}`
|
|
132
|
+
},
|
|
119
133
|
async get(key, to) {
|
|
120
134
|
mkdirSync(dirname(to), { recursive: true })
|
|
121
135
|
const tmp = `${to}.${process.pid}.get`
|
package/src/repo-config.ts
CHANGED
|
@@ -105,7 +105,7 @@ export type RepoConfig = {
|
|
|
105
105
|
/** retired with the v2 social contract: read by nothing; delete the line (`sk social migrate` moves the posts) */
|
|
106
106
|
social?: string[]
|
|
107
107
|
/** the identity that speaks for this repo in public, an id of the house repo's `.shipkit/identities/` (`sk
|
|
108
|
-
* identities`);
|
|
108
|
+
* identities`); required on a machine with identities (SK038). A draft may name another (wiki
|
|
109
109
|
* tools/shipkit/social.md) */
|
|
110
110
|
speaksAs?: string
|
|
111
111
|
/** machine-only state of this repo the backup keeps beyond its own rule (wiki tools/shipkit/media-store.md,
|
|
@@ -116,7 +116,8 @@ export class ColsSvc {
|
|
|
116
116
|
* screen does not name yet is kept at once, so the header's media link
|
|
117
117
|
* is there on the next load */
|
|
118
118
|
mediaListed(): void {
|
|
119
|
-
|
|
119
|
+
// a heartbeat can land after its page state is gone (a closed tab, a test's teardown)
|
|
120
|
+
const cat = this.st.media?.assets[0]?.cat ?? null
|
|
120
121
|
if (this.last != null && cat !== this.keptCat) this.keep(this.last, cat, true)
|
|
121
122
|
}
|
|
122
123
|
|
package/src/social/house.ts
CHANGED
|
@@ -5,20 +5,22 @@ import { homedir } from 'node:os'
|
|
|
5
5
|
import { join } from 'node:path'
|
|
6
6
|
import { houseRepos } from '../serve/project-gutter.ts'
|
|
7
7
|
|
|
8
|
-
export type HouseRepo = { name: string; path: string; speaksAs: string | undefined }
|
|
8
|
+
export type HouseRepo = { name: string; path: string; speaksAs: string | undefined; archived?: boolean }
|
|
9
9
|
|
|
10
10
|
/** `speaksAs: '<id>'` of a config's text, undefined when it names none */
|
|
11
11
|
export const speaksAsOfText = (text: string): string | undefined => /^\s*speaksAs:\s*['"]([a-z0-9-]+)['"]/m.exec(text)?.[1]
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/** the house repos seen from `cwd`, and with `archived` the archived ones too, marked */
|
|
14
|
+
export async function houseRepoRoots(cwd = process.cwd(), o: { archived?: boolean } = {}): Promise<HouseRepo[]> {
|
|
15
|
+
const { repos, archived } = houseRepos(cwd, homedir())
|
|
16
|
+
const old = new Set(archived.map((r) => r.path))
|
|
17
|
+
return [...repos, ...(o.archived === true ? archived : [])].map((r) => {
|
|
16
18
|
let text = ''
|
|
17
19
|
try {
|
|
18
20
|
text = readFileSync(join(r.path, 'repo.config.ts'), 'utf8')
|
|
19
21
|
} catch {
|
|
20
22
|
text = ''
|
|
21
23
|
}
|
|
22
|
-
return { name: r.name, path: r.path, speaksAs: speaksAsOfText(text) }
|
|
24
|
+
return { name: r.name, path: r.path, speaksAs: speaksAsOfText(text), ...(old.has(r.path) ? { archived: true } : {}) }
|
|
23
25
|
})
|
|
24
26
|
}
|