slopkit 0.3.0 → 0.4.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/DEPS.md +5 -3
- package/README.md +93 -1
- package/RULES.md +26 -6
- package/dist/api.d.ts +93 -0
- package/dist/api.js +111 -0
- package/dist/client.d.ts +5 -1
- package/dist/conformance/agent-access.test.d.ts +1 -0
- package/dist/conformance/agent-access.test.js +74 -0
- package/dist/conformance/paging-state.test.js +1 -0
- package/dist/conformance/states.test.js +19 -8
- package/dist/server/auth.d.ts +4 -3
- package/dist/server/auth.js +14 -6
- package/dist/server/cli.d.ts +117 -0
- package/dist/server/cli.js +1534 -0
- package/dist/server/config.d.ts +4 -1
- package/dist/server/config.js +2 -2
- package/dist/server/keys.d.ts +17 -0
- package/dist/server/keys.js +127 -0
- package/dist/server/store.d.ts +101 -0
- package/dist/server/store.js +347 -0
- package/dist/server/sync.d.ts +158 -0
- package/dist/server/sync.js +293 -0
- package/dist/server/web.d.ts +54 -5
- package/dist/server/web.js +236 -28
- package/dist/states.d.ts +52 -4
- package/dist/states.js +20 -0
- package/dist/sync.d.ts +2 -0
- package/dist/sync.js +1 -0
- package/dist/test/agents.d.ts +19 -0
- package/dist/test/agents.js +62 -0
- package/dist/test/page.d.ts +91 -0
- package/dist/test/page.js +763 -0
- package/dist/test/states.d.ts +44 -7
- package/dist/test/states.js +152 -0
- package/dist/web/replica.d.ts +7 -0
- package/dist/web/replica.js +214 -43
- package/dist/web/runtime.d.ts +102 -0
- package/dist/web/runtime.js +335 -0
- package/package.json +39 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { WebConfig } from "./config.ts";
|
|
2
|
+
import { Jobs } from "./jobs.ts";
|
|
3
|
+
import type { Job, JobEnd } from "./jobs.ts";
|
|
4
|
+
import { Log } from "./log.ts";
|
|
5
|
+
import type { Logger } from "./log.ts";
|
|
6
|
+
/** What a release says of itself: its version and the store schema it writes (`<name> version --json`). */
|
|
7
|
+
export type ReleaseInfo = {
|
|
8
|
+
version: string;
|
|
9
|
+
schema: number;
|
|
10
|
+
};
|
|
11
|
+
export type Installed = {
|
|
12
|
+
ok: true;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
reason: string;
|
|
16
|
+
tail: string[];
|
|
17
|
+
};
|
|
18
|
+
/** The automatic rollback that put `version` in place, if it is the one running: what it replaced and when. */
|
|
19
|
+
export declare function rolledBackTo(home: string, version: string): {
|
|
20
|
+
from: string;
|
|
21
|
+
at: string;
|
|
22
|
+
} | null;
|
|
23
|
+
/** Whether a server holds the home's lock, without creating the lock file. */
|
|
24
|
+
export declare function running(home: string): boolean;
|
|
25
|
+
/** What an update job leaves when done: the release it installed and the version it replaced. */
|
|
26
|
+
export type UpdateResult = {
|
|
27
|
+
release?: string;
|
|
28
|
+
from?: string;
|
|
29
|
+
};
|
|
30
|
+
/** How one update job ended, as a server reports it. */
|
|
31
|
+
export type UpdateRecord = {
|
|
32
|
+
job: number;
|
|
33
|
+
release: string;
|
|
34
|
+
from: string;
|
|
35
|
+
result: "installed" | "failed";
|
|
36
|
+
reason: string | null;
|
|
37
|
+
at: string;
|
|
38
|
+
};
|
|
39
|
+
/** An update job (`slopkit/server/jobs`, kind `update`): one open at a time; every tap while it is open joins it. */
|
|
40
|
+
export declare const UPDATE_KIND = "update";
|
|
41
|
+
/** An update job asked for, and whether it is still due to run. */
|
|
42
|
+
export type AskedUpdate = {
|
|
43
|
+
id: number;
|
|
44
|
+
due: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** Ask for an update to `release` from `version` (joins one already open): the job's id, and whether still due. */
|
|
47
|
+
export declare function askUpdate(jobs: Jobs<UpdateResult>, release: string, version: string, by: {
|
|
48
|
+
client: string;
|
|
49
|
+
id: number;
|
|
50
|
+
}, now?: number): AskedUpdate;
|
|
51
|
+
/** Claim the asked update before the server stops: running, "installing <release> from <version>", committed. */
|
|
52
|
+
export declare function beginUpdate(jobs: Jobs<UpdateResult>, version: string): {
|
|
53
|
+
id: number;
|
|
54
|
+
release: string;
|
|
55
|
+
from: string;
|
|
56
|
+
} | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* At start, before serving: how an update job a stop left running is settled. The install began: installed when this
|
|
59
|
+
* is another version than the one it replaced (the reconciliation read), else failed as interrupted.
|
|
60
|
+
*/
|
|
61
|
+
export declare function recoverUpdate(job: Job<UpdateResult>, version: string): JobEnd<UpdateResult>;
|
|
62
|
+
/** At start, after running jobs are settled: an update still due failed, nothing changed. Returns how many. */
|
|
63
|
+
export declare function settleAskedUpdates(jobs: Jobs<UpdateResult>): number;
|
|
64
|
+
/** The newest `kept` finished updates, newest first. */
|
|
65
|
+
export declare function updateRecords(jobs: Jobs<UpdateResult>, kept: number): UpdateRecord[];
|
|
66
|
+
/** The open update job's id, if one is asked or installing. */
|
|
67
|
+
export declare function updating(jobs: Jobs<UpdateResult>): number | null;
|
|
68
|
+
/** The newer `edge` commit when this is an edge build behind it; a hint only, nothing installs it. */
|
|
69
|
+
export declare function newerEdge(root: URL | string, env?: Readonly<Record<string, string | undefined>>): Promise<string | undefined>;
|
|
70
|
+
/** What an app's `serve` gets: its home, what it is, the log, the web settings, and a way to ask for an update. */
|
|
71
|
+
export type ServeContext = {
|
|
72
|
+
home: string;
|
|
73
|
+
version: string;
|
|
74
|
+
log: Log;
|
|
75
|
+
/** The server's own log lines (`server`). */
|
|
76
|
+
say: Logger;
|
|
77
|
+
/** `web.json`, or why the web is off. */
|
|
78
|
+
web: WebConfig | {
|
|
79
|
+
off: string;
|
|
80
|
+
};
|
|
81
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
82
|
+
/** Stop the server for the update the app's store has asked (`askUpdate`), then start the same command again. */
|
|
83
|
+
update: () => void;
|
|
84
|
+
};
|
|
85
|
+
/** What an app's `serve` hands back once it serves. */
|
|
86
|
+
export type Served = {
|
|
87
|
+
/** Its web server's address, when it has one. */
|
|
88
|
+
url?: string;
|
|
89
|
+
close: () => Promise<void>;
|
|
90
|
+
/** The asked update job, claimed running before anything stops (`beginUpdate`). */
|
|
91
|
+
claim?: () => {
|
|
92
|
+
id: number;
|
|
93
|
+
release: string;
|
|
94
|
+
} | undefined;
|
|
95
|
+
};
|
|
96
|
+
export type CliOptions = {
|
|
97
|
+
/** The binary's name: `<NAME>_HOME`, `~/.<name>`, `<name>.sqlite`, `<name>.tgz`. */
|
|
98
|
+
name: string;
|
|
99
|
+
/** The installed package's directory (`new URL("../", import.meta.url)`). */
|
|
100
|
+
root: URL | string;
|
|
101
|
+
/** The store schema this release writes (`schemaVersion`). */
|
|
102
|
+
schema: number;
|
|
103
|
+
/** What `serve` does, for the help: "<name> serve: Run the server on the home: <serves>". */
|
|
104
|
+
serves: string;
|
|
105
|
+
serve: (context: ServeContext) => Promise<Served>;
|
|
106
|
+
/** The app's own commands, beside the kit's. */
|
|
107
|
+
commands?: Record<string, {
|
|
108
|
+
usage: string;
|
|
109
|
+
help: string;
|
|
110
|
+
run: (args: string[], home: string) => Promise<number>;
|
|
111
|
+
}>;
|
|
112
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
113
|
+
/** How long a server stays up before its release is proven here (default an hour). */
|
|
114
|
+
provenAfterMs?: number;
|
|
115
|
+
};
|
|
116
|
+
/** Run the command line: the exit code. */
|
|
117
|
+
export declare function runCli(args: readonly string[], options: CliOptions): Promise<number>;
|