@kubohiroya/turbowarp-title-menu 0.4.0 → 0.6.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.ja.md +43 -2
- package/README.md +66 -3
- package/dist/extension-manifest.json +19 -0
- package/dist/lib/composition.js +2 -0
- package/dist/lib/extension-cache-dialog.js +389 -0
- package/dist/lib/extension-cache.js +91 -0
- package/dist/lib/locales.js +91 -2
- package/dist/turbowarp-title-menu.js +933 -11
- package/dist/types/composition.d.ts +4 -0
- package/dist/types/extension-cache-dialog.d.ts +76 -0
- package/dist/types/extension-cache.d.ts +89 -0
- package/dist/types/locales.d.ts +22 -0
- package/package.json +15 -7
- package/src/block-definitions.json +22 -0
- package/src/composition.ts +16 -0
- package/src/extension-cache-dialog.ts +525 -0
- package/src/extension-cache.ts +187 -0
- package/src/extension.ts +81 -1
- package/src/index.ts +4 -0
- package/src/locales.ts +100 -2
|
@@ -6,5 +6,9 @@ export { createDslStore, defaultDslSort, DslStoreError, readDslFile } from './ds
|
|
|
6
6
|
export type { DslFileRecord, DslFileSummary, DslSort, DslSortDirection, DslSortField, DslStore, DslStoreErrorCode, DslStoreOptions } from './dsl-store.js';
|
|
7
7
|
export { dslOpenEventName, dslReloadEventName } from './events.js';
|
|
8
8
|
export type { DslSourceEventDetail } from './events.js';
|
|
9
|
+
export { createExtensionCache, ExtensionCacheError, SHARED_BUCKET } from './extension-cache.js';
|
|
10
|
+
export type { CachedDigestSummary, CachedProjectSummary, CacheReleaseResult, ExtensionCache, ExtensionCacheErrorCode, ExtensionCacheOptions, ExtensionCacheTotals } from './extension-cache.js';
|
|
11
|
+
export { createExtensionCacheDialog } from './extension-cache-dialog.js';
|
|
12
|
+
export type { ExtensionCacheDialog, ExtensionCacheDialogLocaleText, ExtensionCacheDialogOptions } from './extension-cache-dialog.js';
|
|
9
13
|
export { createTitleDialog } from './title-dialog.js';
|
|
10
14
|
export type { TitleDialog, TitleDialogOptions, TitleDialogLocaleText } from './title-dialog.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { CachedDigestSummary, CachedProjectSummary, CacheReleaseResult, ExtensionCacheTotals } from './extension-cache';
|
|
2
|
+
/**
|
|
3
|
+
* The stage-mounted manager for cached extension bytes.
|
|
4
|
+
*
|
|
5
|
+
* Like the DSL file dialog, this owns presentation and interaction state only — which bucket is
|
|
6
|
+
* expanded and which row is awaiting confirmation — while every cache operation is a
|
|
7
|
+
* caller-supplied callback. That is what keeps this file free of any knowledge of how the Loader
|
|
8
|
+
* stores anything.
|
|
9
|
+
*
|
|
10
|
+
* Two things the wording must not overstate, both of which the locale text carries:
|
|
11
|
+
*
|
|
12
|
+
* - **A bucket is a claim, not ownership.** Entries are keyed by the digest of their bytes, so
|
|
13
|
+
* releasing a project drops the digests that project named and may take bytes another project
|
|
14
|
+
* would have reused. It costs a re-fetch and nothing else, and the notice says exactly that.
|
|
15
|
+
* - **A project URI is what the project called itself.** Nothing verifies it, so a project can
|
|
16
|
+
* file its bytes under another project's URI. Only the ledger is wrong if it does: the Loader
|
|
17
|
+
* re-checks SHA-256 on every hit, so a mislabelled bucket can still never hand over the wrong
|
|
18
|
+
* bytes. The notice states this the same way the DSL dialog and the security dialog state that
|
|
19
|
+
* an author's name is self-declared.
|
|
20
|
+
*
|
|
21
|
+
* The list is readable because each row shows the title beside the URI. The URI is an opaque UUID
|
|
22
|
+
* path by design, so it is the title that tells an operator which project a row is.
|
|
23
|
+
*/
|
|
24
|
+
export interface ExtensionCacheDialogLocaleText {
|
|
25
|
+
title: string;
|
|
26
|
+
/** Why releasing is safe, and why neither the URI nor the bucket proves anything. */
|
|
27
|
+
notice: string;
|
|
28
|
+
/** Total line. `{entries}` and `{bytes}` are substituted. */
|
|
29
|
+
total: string;
|
|
30
|
+
/** Row label for the bucket that belongs to no one project. */
|
|
31
|
+
shared: string;
|
|
32
|
+
/** Row label when no host recorded a title for the URI. */
|
|
33
|
+
untitled: string;
|
|
34
|
+
/** `{entries}` is substituted. */
|
|
35
|
+
entryCount: string;
|
|
36
|
+
expand: string;
|
|
37
|
+
collapse: string;
|
|
38
|
+
release: string;
|
|
39
|
+
confirmRelease: string;
|
|
40
|
+
cancel: string;
|
|
41
|
+
close: string;
|
|
42
|
+
refresh: string;
|
|
43
|
+
empty: string;
|
|
44
|
+
/** Result line after a release. `{released}` and `{freed}` are substituted. */
|
|
45
|
+
releaseResult: string;
|
|
46
|
+
/** `{date}` is substituted. */
|
|
47
|
+
lastUsed: string;
|
|
48
|
+
/** `{bytes}` is substituted with the decompressed size of one digest. */
|
|
49
|
+
originalSize: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ExtensionCacheDialogOptions {
|
|
52
|
+
document?: Document;
|
|
53
|
+
mount?: HTMLElement;
|
|
54
|
+
locales: Record<string, ExtensionCacheDialogLocaleText>;
|
|
55
|
+
initialLocale?: string;
|
|
56
|
+
listProjects(): Promise<readonly CachedProjectSummary[]>;
|
|
57
|
+
listDigests(bucket: string): Promise<readonly CachedDigestSummary[]>;
|
|
58
|
+
totals(): Promise<ExtensionCacheTotals>;
|
|
59
|
+
onReleaseProject(bucket: string): CacheReleaseResult | Promise<CacheReleaseResult>;
|
|
60
|
+
onReleaseDigest(bucket: string, key: string): CacheReleaseResult | Promise<CacheReleaseResult>;
|
|
61
|
+
describeError?(error: unknown): string;
|
|
62
|
+
formatSize?(byteLength: number): string;
|
|
63
|
+
formatDate?(epochMilliseconds: number): string;
|
|
64
|
+
onError?(error: unknown): void;
|
|
65
|
+
}
|
|
66
|
+
export interface ExtensionCacheDialog {
|
|
67
|
+
readonly element: HTMLElement;
|
|
68
|
+
readonly locale: string;
|
|
69
|
+
readonly expanded: string | null;
|
|
70
|
+
show(locale?: string): Promise<string>;
|
|
71
|
+
hide(): void;
|
|
72
|
+
refresh(): Promise<void>;
|
|
73
|
+
setLocale(locale: string): string;
|
|
74
|
+
dispose(): void;
|
|
75
|
+
}
|
|
76
|
+
export declare function createExtensionCacheDialog(options: ExtensionCacheDialogOptions): ExtensionCacheDialog;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { SHARED_BUCKET } from '@kubohiroya/turbowarp-extension-loader/indexeddb-cache';
|
|
2
|
+
/**
|
|
3
|
+
* A read-and-release view over the extension bytes the Loader caches in IndexedDB.
|
|
4
|
+
*
|
|
5
|
+
* Every operation goes through `@kubohiroya/turbowarp-extension-loader/indexeddb-cache`. This
|
|
6
|
+
* package never opens that database by name and never names its object stores: a second package
|
|
7
|
+
* that knew the schema would be a second place to change when the schema moves, and the
|
|
8
|
+
* cross-layer mismatch that follows is a bug this family has already paid for more than once.
|
|
9
|
+
* The Loader owns the store; this module owns only the screen in front of it.
|
|
10
|
+
*
|
|
11
|
+
* What the cache records is a *claim*, not ownership. Entries are addressed by the SHA-256 of
|
|
12
|
+
* their bytes, so one copy can be claimed by several projects, and the cache does not record who
|
|
13
|
+
* fetched it first. Releasing a project therefore means "drop the digests this project named",
|
|
14
|
+
* which may take bytes another project would have reused. Nothing is lost for good — a dropped
|
|
15
|
+
* digest is fetched again on the next open — and the wording on screen promises no more than that.
|
|
16
|
+
*/
|
|
17
|
+
export type ExtensionCacheErrorCode = 'unavailable' | 'failed';
|
|
18
|
+
export declare class ExtensionCacheError extends Error {
|
|
19
|
+
readonly code: ExtensionCacheErrorCode;
|
|
20
|
+
constructor(code: ExtensionCacheErrorCode, message: string, cause?: unknown);
|
|
21
|
+
}
|
|
22
|
+
/** One bucket of cached bytes: a project that claims them, or the shared bucket. */
|
|
23
|
+
export interface CachedProjectSummary {
|
|
24
|
+
/** The bucket name the Loader filed the claims under: a project URI, or the shared bucket. */
|
|
25
|
+
readonly bucket: string;
|
|
26
|
+
/** True for the bucket that belongs to no one project, which carries no URI to show. */
|
|
27
|
+
readonly shared: boolean;
|
|
28
|
+
/** A human-readable name a host recorded for this URI. Self-declared and unverified. */
|
|
29
|
+
readonly title?: string;
|
|
30
|
+
readonly entries: number;
|
|
31
|
+
readonly bytes: number;
|
|
32
|
+
}
|
|
33
|
+
/** One cached digest as it is claimed by one bucket. */
|
|
34
|
+
export interface CachedDigestSummary {
|
|
35
|
+
/** The SHA-256 digest of the extension bytes, which is also the cache key. */
|
|
36
|
+
readonly key: string;
|
|
37
|
+
/** Stored (compressed) size, which is what the quota counts. */
|
|
38
|
+
readonly bytes: number;
|
|
39
|
+
/** Size of the JavaScript the digest decompresses to. */
|
|
40
|
+
readonly originalBytes: number;
|
|
41
|
+
readonly lastAccess: number;
|
|
42
|
+
}
|
|
43
|
+
/** What a release actually did, so the screen can report it instead of guessing. */
|
|
44
|
+
export interface CacheReleaseResult {
|
|
45
|
+
readonly released: number;
|
|
46
|
+
readonly freed: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ExtensionCacheTotals {
|
|
49
|
+
readonly entries: number;
|
|
50
|
+
readonly bytes: number;
|
|
51
|
+
}
|
|
52
|
+
export interface ExtensionCacheOptions {
|
|
53
|
+
readonly indexedDB?: IDBFactory;
|
|
54
|
+
/**
|
|
55
|
+
* The database the Loader was configured with, when the host chose one.
|
|
56
|
+
*
|
|
57
|
+
* Left out, the Loader's own default applies. This module deliberately does not spell that
|
|
58
|
+
* default: knowing the name is the Loader's business, and a copy here would be one more thing
|
|
59
|
+
* to keep in step.
|
|
60
|
+
*/
|
|
61
|
+
readonly databaseName?: string;
|
|
62
|
+
/**
|
|
63
|
+
* A title for one bucket, read at list time.
|
|
64
|
+
*
|
|
65
|
+
* Bucket names are project URIs, and a project URI is deliberately opaque — a UUID path, so
|
|
66
|
+
* that it does not have to change when the project is renamed. Nobody reads that; people read
|
|
67
|
+
* titles. The cache cannot supply one, so the host does, and passing a lookup the host keeps
|
|
68
|
+
* updating is enough because it is consulted on every listing.
|
|
69
|
+
*
|
|
70
|
+
* The screen never fetches the URI to discover a title. A project URI serves nothing until its
|
|
71
|
+
* author publishes, so an unpublished project answers 404 — and a screen that treated that as
|
|
72
|
+
* meaningful would invite operators to clear the cache of every project still being written.
|
|
73
|
+
*/
|
|
74
|
+
titleFor?(bucket: string): string | undefined;
|
|
75
|
+
}
|
|
76
|
+
export interface ExtensionCache {
|
|
77
|
+
/** Every bucket that holds something, most storage first, with the shared bucket at the top. */
|
|
78
|
+
listProjects(): Promise<CachedProjectSummary[]>;
|
|
79
|
+
/** What one bucket claims, most recently used first. */
|
|
80
|
+
listDigests(bucket: string): Promise<CachedDigestSummary[]>;
|
|
81
|
+
/** Drop every digest one bucket claims; bytes another bucket still claims stay. */
|
|
82
|
+
releaseProject(bucket: string): Promise<CacheReleaseResult>;
|
|
83
|
+
/** Drop named digests from one bucket, under the same rule. */
|
|
84
|
+
releaseDigests(bucket: string, keys: readonly string[]): Promise<CacheReleaseResult>;
|
|
85
|
+
totals(): Promise<ExtensionCacheTotals>;
|
|
86
|
+
close(): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
export { SHARED_BUCKET };
|
|
89
|
+
export declare function createExtensionCache(options?: ExtensionCacheOptions): ExtensionCache;
|
package/dist/types/locales.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { DslFilesDialogLocaleText } from './dsl-files-dialog';
|
|
2
|
+
import type { ExtensionCacheDialogLocaleText } from './extension-cache-dialog';
|
|
2
3
|
import type { TitleDialogLocaleText } from './title-dialog';
|
|
3
4
|
export type SupportedLocale = 'en' | 'ja';
|
|
4
5
|
export interface MenuActionLabels {
|
|
5
6
|
files: string;
|
|
7
|
+
cache: string;
|
|
6
8
|
reload: string;
|
|
7
9
|
about: string;
|
|
8
10
|
close: string;
|
|
@@ -10,5 +12,25 @@ export interface MenuActionLabels {
|
|
|
10
12
|
export declare const titleLocales: Readonly<Record<SupportedLocale, TitleDialogLocaleText>>;
|
|
11
13
|
export declare const menuLocales: Readonly<Record<SupportedLocale, MenuActionLabels>>;
|
|
12
14
|
export declare const dslFilesLocales: Readonly<Record<SupportedLocale, DslFilesDialogLocaleText>>;
|
|
15
|
+
/**
|
|
16
|
+
* Wording for the extension cache screen.
|
|
17
|
+
*
|
|
18
|
+
* The notice is the load-bearing part, and it says three things on purpose. Releasing is phrased
|
|
19
|
+
* as letting go of what a project *names*, never as deleting what it owns, because the cache is
|
|
20
|
+
* addressed by content and one copy can be claimed by several projects. It states that nothing is
|
|
21
|
+
* lost for good, so that an operator freeing space is not frightened into leaving it alone. And it
|
|
22
|
+
* states that a project URI is self-declared, the same admission the DSL dialog and the security
|
|
23
|
+
* dialog make about an author's name — the Loader re-checks every digest on use, so a project
|
|
24
|
+
* that files its bytes under somebody else's URI corrupts this list and nothing else.
|
|
25
|
+
*/
|
|
26
|
+
export declare const extensionCacheLocales: Readonly<Record<SupportedLocale, ExtensionCacheDialogLocaleText>>;
|
|
27
|
+
/**
|
|
28
|
+
* Turns a cache failure into operator-facing text.
|
|
29
|
+
*
|
|
30
|
+
* Only the codes this package assigns itself are translated. A failure raised inside IndexedDB
|
|
31
|
+
* keeps its own message, because inventing a friendlier sentence for an unclassified error would
|
|
32
|
+
* hide the one detail that makes it reportable.
|
|
33
|
+
*/
|
|
34
|
+
export declare function describeCacheError(locale: SupportedLocale, error: unknown): string;
|
|
13
35
|
/** Turns a store error code into operator-facing text, falling back to the raw message. */
|
|
14
36
|
export declare function describeStoreError(locale: SupportedLocale, error: unknown): string;
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-title-menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Reusable title, application menu, and DSL source storage controls for TurboWarp.",
|
|
5
|
-
"author":
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Hiroya Kubo",
|
|
7
|
+
"email": "hiroya@cuc.ac.jp",
|
|
8
|
+
"url": "https://github.com/kubohiroya"
|
|
9
|
+
},
|
|
6
10
|
"license": "MPL-2.0",
|
|
7
11
|
"homepage": "https://github.com/kubohiroya/turbowarp-title-menu#readme",
|
|
8
12
|
"repository": {
|
|
@@ -64,13 +68,16 @@
|
|
|
64
68
|
"docs:check": "pnpm run docs && git diff --exit-code -- README.md",
|
|
65
69
|
"repo:check": "node scripts/check-repo.mjs",
|
|
66
70
|
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
67
|
-
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
68
|
-
"check:dist": "pnpm run build && node scripts/check-dist.mjs"
|
|
71
|
+
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check && pnpm run samples:check",
|
|
72
|
+
"check:dist": "pnpm run build && node scripts/check-dist.mjs",
|
|
73
|
+
"samples:build": "node scripts/build-samples.mjs",
|
|
74
|
+
"samples:check": "node scripts/build-samples.mjs --check && node --test scripts/verify-samples.mjs",
|
|
75
|
+
"pages:build": "node scripts/prepare-pages.mjs"
|
|
69
76
|
},
|
|
70
77
|
"devDependencies": {
|
|
71
78
|
"@eslint/js": "^9.39.5",
|
|
72
|
-
"@kubohiroya/turbowarp-extension-manifest": "0.
|
|
73
|
-
"@kubohiroya/vite-plugin-turbowarp-extension": "0.
|
|
79
|
+
"@kubohiroya/turbowarp-extension-manifest": "0.5.0",
|
|
80
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "0.11.0",
|
|
74
81
|
"@types/node": "^24.13.3",
|
|
75
82
|
"eslint": "^9.39.5",
|
|
76
83
|
"fake-indexeddb": "6.2.5",
|
|
@@ -80,6 +87,7 @@
|
|
|
80
87
|
"vitest": "^4.1.10"
|
|
81
88
|
},
|
|
82
89
|
"dependencies": {
|
|
83
|
-
"@kubohiroya/turbowarp-app-shell": "0.
|
|
90
|
+
"@kubohiroya/turbowarp-app-shell": "0.6.1",
|
|
91
|
+
"@kubohiroya/turbowarp-extension-loader": "0.12.0"
|
|
84
92
|
}
|
|
85
93
|
}
|
|
@@ -116,6 +116,28 @@
|
|
|
116
116
|
"blockType": "REPORTER",
|
|
117
117
|
"text": "last DSL storage error",
|
|
118
118
|
"description": "Returns the most recent DSL storage failure in the interface language, or an empty string."
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"opcode": "showExtensionCache",
|
|
122
|
+
"blockType": "COMMAND",
|
|
123
|
+
"text": "show extension cache manager",
|
|
124
|
+
"description": "Shows the dialog that lists the cached extension bytes per project and releases them."
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"opcode": "setCachedProjectTitle",
|
|
128
|
+
"blockType": "COMMAND",
|
|
129
|
+
"text": "label cached project [URI] as [TITLE]",
|
|
130
|
+
"description": "Records a readable title to show beside a project URI in the extension cache manager. A project URI is deliberately opaque, so without a title the rows cannot be told apart; the title is self-declared and is never checked against the URI.",
|
|
131
|
+
"arguments": {
|
|
132
|
+
"URI": {
|
|
133
|
+
"type": "STRING",
|
|
134
|
+
"defaultValue": "https://example.com/turbowarp-plus-projects/ab/cd/project"
|
|
135
|
+
},
|
|
136
|
+
"TITLE": {
|
|
137
|
+
"type": "STRING",
|
|
138
|
+
"defaultValue": "My project"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
119
141
|
}
|
|
120
142
|
]
|
|
121
143
|
}
|
package/src/composition.ts
CHANGED
|
@@ -22,5 +22,21 @@ export type {
|
|
|
22
22
|
} from './dsl-store.js';
|
|
23
23
|
export {dslOpenEventName, dslReloadEventName} from './events.js';
|
|
24
24
|
export type {DslSourceEventDetail} from './events.js';
|
|
25
|
+
export {createExtensionCache, ExtensionCacheError, SHARED_BUCKET} from './extension-cache.js';
|
|
26
|
+
export type {
|
|
27
|
+
CachedDigestSummary,
|
|
28
|
+
CachedProjectSummary,
|
|
29
|
+
CacheReleaseResult,
|
|
30
|
+
ExtensionCache,
|
|
31
|
+
ExtensionCacheErrorCode,
|
|
32
|
+
ExtensionCacheOptions,
|
|
33
|
+
ExtensionCacheTotals
|
|
34
|
+
} from './extension-cache.js';
|
|
35
|
+
export {createExtensionCacheDialog} from './extension-cache-dialog.js';
|
|
36
|
+
export type {
|
|
37
|
+
ExtensionCacheDialog,
|
|
38
|
+
ExtensionCacheDialogLocaleText,
|
|
39
|
+
ExtensionCacheDialogOptions
|
|
40
|
+
} from './extension-cache-dialog.js';
|
|
25
41
|
export {createTitleDialog} from './title-dialog.js';
|
|
26
42
|
export type {TitleDialog, TitleDialogOptions, TitleDialogLocaleText} from './title-dialog.js';
|