@substrat-run/kernel 0.219.0 → 0.221.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/dist/adopt-major.d.ts +150 -0
- package/dist/adopt-major.d.ts.map +1 -0
- package/dist/adopt-major.js +150 -0
- package/dist/adopt-major.js.map +1 -0
- package/dist/app-environments.d.ts +113 -0
- package/dist/app-environments.d.ts.map +1 -0
- package/dist/app-environments.js +239 -0
- package/dist/app-environments.js.map +1 -0
- package/dist/broker-relay-scope.d.ts +53 -0
- package/dist/broker-relay-scope.d.ts.map +1 -0
- package/dist/broker-relay-scope.js +77 -0
- package/dist/broker-relay-scope.js.map +1 -0
- package/dist/broker-relay.d.ts +5 -1
- package/dist/broker-relay.d.ts.map +1 -1
- package/dist/broker-relay.js.map +1 -1
- package/dist/broker-schema.d.ts.map +1 -1
- package/dist/broker-schema.js +12 -0
- package/dist/broker-schema.js.map +1 -1
- package/dist/carried-copy.d.ts.map +1 -1
- package/dist/carried-copy.js +3 -0
- package/dist/carried-copy.js.map +1 -1
- package/dist/connect-intent.d.ts +24 -0
- package/dist/connect-intent.d.ts.map +1 -0
- package/dist/connect-intent.js +25 -0
- package/dist/connect-intent.js.map +1 -0
- package/dist/connection-context.d.ts +30 -0
- package/dist/connection-context.d.ts.map +1 -1
- package/dist/connection-context.js.map +1 -1
- package/dist/delivery-broker.d.ts +77 -1
- package/dist/delivery-broker.d.ts.map +1 -1
- package/dist/delivery-broker.js +112 -8
- package/dist/delivery-broker.js.map +1 -1
- package/dist/delivery-contract.d.ts +36 -0
- package/dist/delivery-contract.d.ts.map +1 -0
- package/dist/delivery-contract.js +84 -0
- package/dist/delivery-contract.js.map +1 -0
- package/dist/directory-lake-keep.d.ts.map +1 -1
- package/dist/directory-lake-keep.js +5 -0
- package/dist/directory-lake-keep.js.map +1 -1
- package/dist/email-intent.d.ts +32 -0
- package/dist/email-intent.d.ts.map +1 -1
- package/dist/email-intent.js +66 -1
- package/dist/email-intent.js.map +1 -1
- package/dist/entity-trash.d.ts +45 -0
- package/dist/entity-trash.d.ts.map +1 -1
- package/dist/entity-trash.js +52 -0
- package/dist/entity-trash.js.map +1 -1
- package/dist/index.d.ts +19 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/permission-checker.d.ts.map +1 -1
- package/dist/permission-checker.js +4 -2
- package/dist/permission-checker.js.map +1 -1
- package/dist/release-within-major.d.ts +173 -0
- package/dist/release-within-major.d.ts.map +1 -0
- package/dist/release-within-major.js +283 -0
- package/dist/release-within-major.js.map +1 -0
- package/dist/reserved-roles.d.ts +12 -1
- package/dist/reserved-roles.d.ts.map +1 -1
- package/dist/reserved-roles.js.map +1 -1
- package/dist/schedule-due.d.ts +88 -0
- package/dist/schedule-due.d.ts.map +1 -0
- package/dist/schedule-due.js +116 -0
- package/dist/schedule-due.js.map +1 -0
- package/dist/schedule-state.d.ts +1 -1
- package/dist/schedule-state.d.ts.map +1 -1
- package/dist/schedule-state.js +6 -0
- package/dist/schedule-state.js.map +1 -1
- package/dist/scope-copy.d.ts.map +1 -1
- package/dist/scope-copy.js +13 -1
- package/dist/scope-copy.js.map +1 -1
- package/dist/scope-host.d.ts +202 -2
- package/dist/scope-host.d.ts.map +1 -1
- package/dist/scope-host.js.map +1 -1
- package/dist/scope-identity.d.ts +10 -1
- package/dist/scope-identity.d.ts.map +1 -1
- package/dist/scope-identity.js +12 -3
- package/dist/scope-identity.js.map +1 -1
- package/dist/scope-store.d.ts +30 -6
- package/dist/scope-store.d.ts.map +1 -1
- package/dist/scope-store.js +30 -1
- package/dist/scope-store.js.map +1 -1
- package/dist/scope-types.d.ts +161 -0
- package/dist/scope-types.d.ts.map +1 -0
- package/dist/scope-types.js +227 -0
- package/dist/scope-types.js.map +1 -0
- package/dist/store-proof.d.ts +45 -0
- package/dist/store-proof.d.ts.map +1 -0
- package/dist/store-proof.js +97 -0
- package/dist/store-proof.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* K-65 between majors (#3539 part 3): the rules behind an install's move from an earlier major of a
|
|
3
|
+
* listed app to the newest one, the refusal of a bind that would name a version of another major,
|
|
4
|
+
* and the notice each install is shown. Pure, so both the control plane and a test can hold them.
|
|
5
|
+
*
|
|
6
|
+
* An install of a listed app follows its publisher within its major (K-65). A new major is served
|
|
7
|
+
* from a script of its own (#3539 part 2), and the installs of the earlier major stay on theirs.
|
|
8
|
+
* An install moves to the new major only when its tenant chooses to, through the hop K-33 already
|
|
9
|
+
* has: export from the script that holds its data, restore into the new major's script, then flip
|
|
10
|
+
* the route. These rules are what the control plane judges before anything moves.
|
|
11
|
+
*/
|
|
12
|
+
import type { EarlierMajor } from '@substrat-run/contracts';
|
|
13
|
+
/** The `reason` a move between majors carries when the two majors' migrations cannot be judged compatible. */
|
|
14
|
+
export declare const MAJOR_MIGRATIONS_DIVERGE_REASON = "major_migrations_diverge";
|
|
15
|
+
/** The `reason` a bind carries when it would name a version of another major than its script serves. */
|
|
16
|
+
export declare const CROSS_MAJOR_BIND_REASON = "cross_major_bind";
|
|
17
|
+
/** A vertical's serving state, as the rules here read it: the newest major's script, and the earlier ones'. */
|
|
18
|
+
export interface MajorsServed {
|
|
19
|
+
/** The newest major's serving script and the version it runs, with that version's label. */
|
|
20
|
+
readonly current: {
|
|
21
|
+
readonly ref: string;
|
|
22
|
+
readonly versionId: string;
|
|
23
|
+
readonly version: string;
|
|
24
|
+
} | null;
|
|
25
|
+
/** Every earlier major still served, oldest first (`verticals.earlier_majors`). */
|
|
26
|
+
readonly earlier: readonly EarlierMajor[];
|
|
27
|
+
}
|
|
28
|
+
/** Which major a serving script serves, and the version it runs: the current one, an earlier one, or none. */
|
|
29
|
+
export type ScriptMajor = {
|
|
30
|
+
readonly kind: 'current';
|
|
31
|
+
readonly major: number | null;
|
|
32
|
+
readonly versionId: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'earlier';
|
|
35
|
+
readonly major: number;
|
|
36
|
+
readonly versionId: string;
|
|
37
|
+
readonly entry: EarlierMajor;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The major `ref` serves, or `null` when it is none of the vertical's serving scripts (a scope on
|
|
41
|
+
* per-version dispatch, or one pinned to a script the directory no longer names). The current
|
|
42
|
+
* major's number is read from its version label, so a label that is not semver gives `null`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function scriptMajorOf(ref: string | null | undefined, served: MajorsServed): ScriptMajor | null;
|
|
45
|
+
/** One side of a move between majors: the version a script runs, and the migrations stored for it. */
|
|
46
|
+
export interface MajorSide {
|
|
47
|
+
readonly major: number;
|
|
48
|
+
readonly version: string;
|
|
49
|
+
/** The version's stored migrations (`versionMigrations`), or `null` when none are stored to show. */
|
|
50
|
+
readonly migrations: readonly {
|
|
51
|
+
readonly moduleId: string;
|
|
52
|
+
readonly version: string;
|
|
53
|
+
readonly sql: string;
|
|
54
|
+
}[] | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Why a scope that ran `from`'s migrations cannot be moved onto a script that runs `to`'s, or `null`
|
|
58
|
+
* when it can. Judged before anything moves, because the scope's journal travels with its data, and
|
|
59
|
+
* the destination's next migration pass fails the scope closed on a journal it cannot trust (#2066)
|
|
60
|
+
* — after the route has flipped, which is the one place the move must not fail.
|
|
61
|
+
*
|
|
62
|
+
* For every module both versions register, `from`'s authored migrations, in order, must be the
|
|
63
|
+
* first of `to`'s, with the same SQL: the append-only rule `lint:migration-ledger` holds within a
|
|
64
|
+
* lineage, applied across the two majors. `to` then applies only what follows them. A module that
|
|
65
|
+
* only `from` registers is left behind: its journal rows and tables stay, and nothing runs them. A
|
|
66
|
+
* migration the kernel derives from a declaration (`search/…`, `state/…`, `list/…`) is never compared,
|
|
67
|
+
* as `migrationSetDigest` does not compare it. A side whose migrations are not stored cannot be
|
|
68
|
+
* judged, and is refused: nothing else can say the move is safe.
|
|
69
|
+
*/
|
|
70
|
+
export declare function majorMigrationsRefusal(input: {
|
|
71
|
+
readonly vertical: string;
|
|
72
|
+
readonly from: MajorSide;
|
|
73
|
+
readonly to: MajorSide;
|
|
74
|
+
}): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Why binding a scope pinned to `servingRef` to `target` is refused, or `null` (K-65, #3539 part 3).
|
|
77
|
+
*
|
|
78
|
+
* A scope on a serving script runs what that script runs, whatever version it is bound to: the bind
|
|
79
|
+
* moves only its pointer. Within one major that pointer is the install's acknowledgement of what it
|
|
80
|
+
* already runs. Bound to a version of ANOTHER major, it would name code the scope does not run, and
|
|
81
|
+
* an Update would read as a move to the new major while the scope stayed on the old one. The move
|
|
82
|
+
* between majors is its own act, which carries the data (`adopt-major`).
|
|
83
|
+
*
|
|
84
|
+
* Judged only for a vertical that serves more than one major, on a scope pinned to one of its
|
|
85
|
+
* serving scripts, and only when both majors can be read. Everything else is not refused here.
|
|
86
|
+
*/
|
|
87
|
+
export declare function crossMajorBindRefusal(input: {
|
|
88
|
+
readonly vertical: string;
|
|
89
|
+
readonly scopeId: string;
|
|
90
|
+
readonly servingRef: string | null | undefined;
|
|
91
|
+
readonly served: MajorsServed;
|
|
92
|
+
readonly target: {
|
|
93
|
+
readonly versionId: string;
|
|
94
|
+
readonly version: string;
|
|
95
|
+
};
|
|
96
|
+
}): string | null;
|
|
97
|
+
/** One version, as a notice names it. */
|
|
98
|
+
export interface NoticeVersion {
|
|
99
|
+
readonly versionId: string;
|
|
100
|
+
readonly version: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* What an install is told about its app's releases (K-65, #3539 part 3). Derived from the directory
|
|
104
|
+
* on every read, never stored: a row per install per release is the directory growing with tenants
|
|
105
|
+
* times time, which the target architecture refuses to deepen.
|
|
106
|
+
*/
|
|
107
|
+
export interface InstallReleaseNotice {
|
|
108
|
+
/** What the install runs, and its major (`null` when the label is not semver). Null when nothing can be named. */
|
|
109
|
+
readonly running: (NoticeVersion & {
|
|
110
|
+
readonly major: number | null;
|
|
111
|
+
}) | null;
|
|
112
|
+
/**
|
|
113
|
+
* A release within the install's major that already runs for it, and that its version pointer has
|
|
114
|
+
* not caught up with: the install follows its publisher within a major, so the update was applied,
|
|
115
|
+
* and this is it being told. `badge` is K-33's: `schema-change` when the two versions' migration
|
|
116
|
+
* digests differ, else `code-only`. Null when the pointer names what runs, or another major.
|
|
117
|
+
*/
|
|
118
|
+
readonly update: {
|
|
119
|
+
readonly from: NoticeVersion;
|
|
120
|
+
readonly to: NoticeVersion;
|
|
121
|
+
readonly badge: 'code-only' | 'schema-change';
|
|
122
|
+
} | null;
|
|
123
|
+
/**
|
|
124
|
+
* A newer major, served beside the install's own, that the install moves to only by its tenant's
|
|
125
|
+
* choice (`adopt-major`). `endsAt` is when the install's own major stops being served, as recorded
|
|
126
|
+
* at the new major's release; what happens then is not decided (K-65). Null on the newest major.
|
|
127
|
+
*/
|
|
128
|
+
readonly newerMajor: (NoticeVersion & {
|
|
129
|
+
readonly major: number | null;
|
|
130
|
+
readonly endsAt: string;
|
|
131
|
+
}) | null;
|
|
132
|
+
}
|
|
133
|
+
/** A version as the notice reads it: its label and its migration digest. */
|
|
134
|
+
export interface NoticeVersionFacts {
|
|
135
|
+
readonly version: string;
|
|
136
|
+
readonly migrationDigest: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The notice for one install. `versions` holds the facts of every version named here that the
|
|
140
|
+
* reader could find; a version it could not find is left out of the notice rather than guessed.
|
|
141
|
+
*/
|
|
142
|
+
export declare function installReleaseNoticeOf(input: {
|
|
143
|
+
readonly scope: {
|
|
144
|
+
readonly verticalVersionId?: string | null | undefined;
|
|
145
|
+
readonly servingRef?: string | null | undefined;
|
|
146
|
+
};
|
|
147
|
+
readonly served: MajorsServed;
|
|
148
|
+
readonly versions: ReadonlyMap<string, NoticeVersionFacts>;
|
|
149
|
+
}): InstallReleaseNotice;
|
|
150
|
+
//# sourceMappingURL=adopt-major.d.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C,GAAG,IAAI,CAAC;IAC7E;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;QAC7B,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC;QAC3B,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,eAAe,CAAC;KAC/C,GAAG,IAAI,CAAC;IACT;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,CAAC,aAAa,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CAC1G;AAED,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;QAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,CAAC;IAC5H,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAC5D,GAAG,oBAAoB,CAiCvB"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { isDerivedMigrationVersion } from './migration-digest.js';
|
|
2
|
+
import { majorOf } from './release-within-major.js';
|
|
3
|
+
/** The `reason` a move between majors carries when the two majors' migrations cannot be judged compatible. */
|
|
4
|
+
export const MAJOR_MIGRATIONS_DIVERGE_REASON = 'major_migrations_diverge';
|
|
5
|
+
/** The `reason` a bind carries when it would name a version of another major than its script serves. */
|
|
6
|
+
export const CROSS_MAJOR_BIND_REASON = 'cross_major_bind';
|
|
7
|
+
/**
|
|
8
|
+
* The major `ref` serves, or `null` when it is none of the vertical's serving scripts (a scope on
|
|
9
|
+
* per-version dispatch, or one pinned to a script the directory no longer names). The current
|
|
10
|
+
* major's number is read from its version label, so a label that is not semver gives `null`.
|
|
11
|
+
*/
|
|
12
|
+
export function scriptMajorOf(ref, served) {
|
|
13
|
+
if (!ref)
|
|
14
|
+
return null;
|
|
15
|
+
if (served.current && ref === served.current.ref) {
|
|
16
|
+
return { kind: 'current', major: majorOf(served.current.version), versionId: served.current.versionId };
|
|
17
|
+
}
|
|
18
|
+
const entry = served.earlier.find((m) => m.ref === ref);
|
|
19
|
+
return entry ? { kind: 'earlier', major: entry.major, versionId: entry.versionId, entry } : null;
|
|
20
|
+
}
|
|
21
|
+
/** How many divergent migrations a refusal names before it counts the rest. */
|
|
22
|
+
const NAMED = 5;
|
|
23
|
+
/**
|
|
24
|
+
* Why a scope that ran `from`'s migrations cannot be moved onto a script that runs `to`'s, or `null`
|
|
25
|
+
* when it can. Judged before anything moves, because the scope's journal travels with its data, and
|
|
26
|
+
* the destination's next migration pass fails the scope closed on a journal it cannot trust (#2066)
|
|
27
|
+
* — after the route has flipped, which is the one place the move must not fail.
|
|
28
|
+
*
|
|
29
|
+
* For every module both versions register, `from`'s authored migrations, in order, must be the
|
|
30
|
+
* first of `to`'s, with the same SQL: the append-only rule `lint:migration-ledger` holds within a
|
|
31
|
+
* lineage, applied across the two majors. `to` then applies only what follows them. A module that
|
|
32
|
+
* only `from` registers is left behind: its journal rows and tables stay, and nothing runs them. A
|
|
33
|
+
* migration the kernel derives from a declaration (`search/…`, `state/…`, `list/…`) is never compared,
|
|
34
|
+
* as `migrationSetDigest` does not compare it. A side whose migrations are not stored cannot be
|
|
35
|
+
* judged, and is refused: nothing else can say the move is safe.
|
|
36
|
+
*/
|
|
37
|
+
export function majorMigrationsRefusal(input) {
|
|
38
|
+
const { vertical, from, to } = input;
|
|
39
|
+
const subject = `moving an install of '${vertical}' from major ${from.major} (${from.version}) to major ${to.major} (${to.version})`;
|
|
40
|
+
const missing = [from, to].filter((s) => s.migrations === null).map((s) => s.version);
|
|
41
|
+
if (missing.length > 0) {
|
|
42
|
+
return (`${subject} is refused: no migrations are stored for ${missing.join(' and ')} (pushed before they were carried, or ` +
|
|
43
|
+
`over the push's caps), so whether its scopes can run the newer major's migrations cannot be judged. Nothing was moved.`);
|
|
44
|
+
}
|
|
45
|
+
const byModule = (ms) => {
|
|
46
|
+
const out = new Map();
|
|
47
|
+
for (const m of ms ?? []) {
|
|
48
|
+
if (isDerivedMigrationVersion(m.version))
|
|
49
|
+
continue;
|
|
50
|
+
const list = out.get(m.moduleId) ?? [];
|
|
51
|
+
list.push(m);
|
|
52
|
+
out.set(m.moduleId, list);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
};
|
|
56
|
+
const before = byModule(from.migrations);
|
|
57
|
+
const after = byModule(to.migrations);
|
|
58
|
+
const diverged = [];
|
|
59
|
+
for (const [moduleId, applied] of before) {
|
|
60
|
+
const next = after.get(moduleId);
|
|
61
|
+
if (!next)
|
|
62
|
+
continue;
|
|
63
|
+
for (let i = 0; i < applied.length; i++) {
|
|
64
|
+
const a = applied[i];
|
|
65
|
+
const b = next[i];
|
|
66
|
+
if (!b) {
|
|
67
|
+
diverged.push(`${moduleId}@${a.version} is not in major ${to.major}`);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (b.version !== a.version) {
|
|
71
|
+
diverged.push(`${moduleId}@${a.version} is followed in major ${to.major} by ${moduleId}@${b.version} in its place`);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (b.sql !== a.sql) {
|
|
75
|
+
diverged.push(`${moduleId}@${a.version} has different SQL in major ${to.major}`);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (diverged.length === 0)
|
|
81
|
+
return null;
|
|
82
|
+
const more = diverged.length > NAMED ? `; and ${diverged.length - NAMED} more` : '';
|
|
83
|
+
return (`${subject} is refused: its scopes have applied migrations major ${to.major} does not continue from ` +
|
|
84
|
+
`(${diverged.slice(0, NAMED).join('; ')}${more}). The newer major's next migration pass would fail the scope closed ` +
|
|
85
|
+
`after its route had moved. A migration is never edited, removed or renumbered once shipped: the publisher releases a ` +
|
|
86
|
+
`major whose migrations continue from the earlier one's. Nothing was moved.`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Why binding a scope pinned to `servingRef` to `target` is refused, or `null` (K-65, #3539 part 3).
|
|
90
|
+
*
|
|
91
|
+
* A scope on a serving script runs what that script runs, whatever version it is bound to: the bind
|
|
92
|
+
* moves only its pointer. Within one major that pointer is the install's acknowledgement of what it
|
|
93
|
+
* already runs. Bound to a version of ANOTHER major, it would name code the scope does not run, and
|
|
94
|
+
* an Update would read as a move to the new major while the scope stayed on the old one. The move
|
|
95
|
+
* between majors is its own act, which carries the data (`adopt-major`).
|
|
96
|
+
*
|
|
97
|
+
* Judged only for a vertical that serves more than one major, on a scope pinned to one of its
|
|
98
|
+
* serving scripts, and only when both majors can be read. Everything else is not refused here.
|
|
99
|
+
*/
|
|
100
|
+
export function crossMajorBindRefusal(input) {
|
|
101
|
+
const { vertical, scopeId, served, target } = input;
|
|
102
|
+
if (served.earlier.length === 0)
|
|
103
|
+
return null;
|
|
104
|
+
const on = scriptMajorOf(input.servingRef, served);
|
|
105
|
+
if (!on || on.major === null)
|
|
106
|
+
return null;
|
|
107
|
+
const targetMajor = majorOf(target.version);
|
|
108
|
+
if (targetMajor === null || targetMajor === on.major)
|
|
109
|
+
return null;
|
|
110
|
+
return (`binding scope ${scopeId} of '${vertical}' to ${target.version} is refused: the scope is served by major ${on.major}'s ` +
|
|
111
|
+
`script, so it would still run major ${on.major} while its version said major ${targetMajor} (K-65). A move to ` +
|
|
112
|
+
`another major carries the scope's data onto that major's script: POST /tenants/:tenantId/scopes/:scopeId/adopt-major.`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The notice for one install. `versions` holds the facts of every version named here that the
|
|
116
|
+
* reader could find; a version it could not find is left out of the notice rather than guessed.
|
|
117
|
+
*/
|
|
118
|
+
export function installReleaseNoticeOf(input) {
|
|
119
|
+
const { scope, served, versions } = input;
|
|
120
|
+
const on = scriptMajorOf(scope.servingRef, served);
|
|
121
|
+
const runningId = on ? on.versionId : (scope.verticalVersionId ?? null);
|
|
122
|
+
const runningFacts = runningId ? versions.get(runningId) : undefined;
|
|
123
|
+
const running = runningId && runningFacts
|
|
124
|
+
? { versionId: runningId, version: runningFacts.version, major: majorOf(runningFacts.version) }
|
|
125
|
+
: null;
|
|
126
|
+
let update = null;
|
|
127
|
+
const boundId = scope.verticalVersionId ?? null;
|
|
128
|
+
const boundFacts = boundId ? versions.get(boundId) : undefined;
|
|
129
|
+
if (running && runningFacts && boundId && boundFacts && boundId !== running.versionId
|
|
130
|
+
&& majorOf(boundFacts.version) === running.major) {
|
|
131
|
+
update = {
|
|
132
|
+
from: { versionId: boundId, version: boundFacts.version },
|
|
133
|
+
to: { versionId: running.versionId, version: running.version },
|
|
134
|
+
badge: boundFacts.migrationDigest === runningFacts.migrationDigest ? 'code-only' : 'schema-change',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
let newerMajor = null;
|
|
138
|
+
const current = served.current;
|
|
139
|
+
const currentFacts = current ? versions.get(current.versionId) : undefined;
|
|
140
|
+
if (on?.kind === 'earlier' && current && currentFacts) {
|
|
141
|
+
newerMajor = {
|
|
142
|
+
versionId: current.versionId,
|
|
143
|
+
version: currentFacts.version,
|
|
144
|
+
major: majorOf(currentFacts.version),
|
|
145
|
+
endsAt: on.entry.endsAt,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return { running, update, newerMajor };
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=adopt-major.js.map
|
|
@@ -0,0 +1 @@
|
|
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,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,IAAI,EAAE,EAAE,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,YAAY,EAAE,CAAC;QACtD,UAAU,GAAG;YACX,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,OAAO,EAAE,YAAY,CAAC,OAAO;YAC7B,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;YACpC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM;SACxB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An app's environments (D-83, #3530 step 3), written once so both adapters' directories cannot
|
|
3
|
+
* disagree about any of it.
|
|
4
|
+
*
|
|
5
|
+
* **Production is never stored.** It is what runs: the tenant's installs of the app, the serving
|
|
6
|
+
* script and the channel `prod`. `environmentsOf` answers it first, read off the scopes, so an app
|
|
7
|
+
* that runs today reads as production with no row, no backfill and no step by anyone.
|
|
8
|
+
*
|
|
9
|
+
* **A named environment is a row over a tagged, pinned preview.** `app_environments` holds the name
|
|
10
|
+
* per (tenant, app). Its scope is the preview whose slug is `<app>--<name>` (`previewScopeSlug`, the
|
|
11
|
+
* rule the preview routes look a tag up by), resolved at read, not stored: a `--refresh` reaps the
|
|
12
|
+
* old preview and mints a new scope id under the same tag, and the environment follows it. A row is
|
|
13
|
+
* written only over a preview that exists, is active and is pinned (no expiry), so an environment is
|
|
14
|
+
* never a pointer without scopes, which is what `dev` and `staging` were when #509 retired them.
|
|
15
|
+
*
|
|
16
|
+
* **A named environment may serve from a script of its own** (#3530 step 4). Its first serve uploads
|
|
17
|
+
* a version onto a fresh script and moves the preview's data there once; every later serve replaces
|
|
18
|
+
* that script in place and moves only the version pointer, as production's serve does (K-33). The
|
|
19
|
+
* record is four columns on the row (`APP_ENVIRONMENT_SERVING_COLUMNS`), NULL until the first serve,
|
|
20
|
+
* so a row from before reads as an environment with no script, which is what it is. The script is
|
|
21
|
+
* fixed for the environment's life: a serve that names another one is refused.
|
|
22
|
+
*
|
|
23
|
+
* What is deliberately not here: edges, connections and a broker per environment (D-83 steps 5 and
|
|
24
|
+
* 6). A named environment's scope is a preview, so it is inert wherever it is served from.
|
|
25
|
+
*/
|
|
26
|
+
import { type AppEnvironment, type EnvironmentServing, type ScopeId, type TenantId } from '@substrat-run/contracts';
|
|
27
|
+
import type { SwitchSql } from './system-switch.js';
|
|
28
|
+
/** Directory-owned, on both adapters. One row per named environment; production has none. */
|
|
29
|
+
export declare const APP_ENVIRONMENTS_DDL = "\n CREATE TABLE IF NOT EXISTS app_environments (\n tenant_id TEXT NOT NULL,\n vertical TEXT NOT NULL,\n name TEXT NOT NULL,\n created_at TEXT NOT NULL,\n created_by TEXT NOT NULL,\n PRIMARY KEY (tenant_id, vertical, name)\n );\n";
|
|
30
|
+
/**
|
|
31
|
+
* #3530 step 4: what an environment's own serving script runs, ALTERed onto `app_environments` by
|
|
32
|
+
* both adapters (and copied into the K-68 objects' column list), all NULL until its first serve.
|
|
33
|
+
* `serving_ref` is the script; `serving_version_id` the version last uploaded onto it;
|
|
34
|
+
* `serving_do_classes` (JSON array) and `serving_migration_tag` what the next in-place upload diffs
|
|
35
|
+
* its Durable Object migrations against, as `verticals.serving_*` are for production.
|
|
36
|
+
*/
|
|
37
|
+
export declare const APP_ENVIRONMENT_SERVING_COLUMNS: readonly ['serving_ref TEXT', 'serving_version_id TEXT', 'serving_do_classes TEXT', 'serving_migration_tag TEXT', 'serve_claim TEXT', 'serve_claimed_until TEXT'];
|
|
38
|
+
/**
|
|
39
|
+
* SQL: joins `ae`, the environment whose own script the scope `s` is served from, to a read over
|
|
40
|
+
* `scopes s`. Null for every scope that is not on one: production's installs, a preview on its
|
|
41
|
+
* version's script, a fork on its copy's. Keyed by the table's primary key prefix, so it is a range
|
|
42
|
+
* read of one tenant's environments of one app, empty for an app that has none.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ENVIRONMENT_SCRIPT_JOIN_SQL = "LEFT JOIN app_environments ae ON ae.tenant_id = s.tenant_id AND ae.vertical = s.vertical AND ae.serving_ref = s.serving_ref";
|
|
45
|
+
/**
|
|
46
|
+
* A preview's scope slug: `<app>--<tag>`, the app's last path segment (`t-acme/crm` → `crm`). The
|
|
47
|
+
* preview routes find a tag by it, and an environment finds its preview by it.
|
|
48
|
+
*/
|
|
49
|
+
export declare const previewScopeSlug: (vertical: string, tag: string) => string;
|
|
50
|
+
/**
|
|
51
|
+
* The app's environments in the tenant: production first, always, then each named one by name.
|
|
52
|
+
* A tenant with no install of the app still has production, with no scopes.
|
|
53
|
+
*/
|
|
54
|
+
export declare function environmentsOf(sql: SwitchSql, tenantId: TenantId, vertical: string): AppEnvironment[];
|
|
55
|
+
/** Whether `tag` names one of the app's environments in the tenant: the preview routes keep it pinned. */
|
|
56
|
+
export declare function isEnvironmentTag(sql: SwitchSql, tenantId: string, vertical: string, tag: string): boolean;
|
|
57
|
+
export interface DefineEnvironmentInput {
|
|
58
|
+
tenantId: TenantId;
|
|
59
|
+
vertical: string;
|
|
60
|
+
name: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Name the app's preview tagged `name` an environment. Read, decided and written in the caller's
|
|
64
|
+
* one directory transaction. Refuses a name that is not a label or is `prod`, a preview that does
|
|
65
|
+
* not exist, is not active, or expires. Defining a name that is already an environment changes
|
|
66
|
+
* nothing (`created: false`).
|
|
67
|
+
*/
|
|
68
|
+
export declare function defineEnvironmentIn(sql: SwitchSql, input: DefineEnvironmentInput, stamp: {
|
|
69
|
+
at: string;
|
|
70
|
+
by: string;
|
|
71
|
+
}): {
|
|
72
|
+
environment: AppEnvironment;
|
|
73
|
+
created: boolean;
|
|
74
|
+
scopeId: ScopeId;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Take the name off: the row goes, and the preview stays, an ordinary pinned preview again. Removing
|
|
78
|
+
* production is refused; a name that is no environment is `removed: false`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function removeEnvironmentIn(sql: SwitchSql, input: DefineEnvironmentInput): {
|
|
81
|
+
removed: boolean;
|
|
82
|
+
scopeId: ScopeId | null;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Record what an environment's own script now runs (#3530 step 4), written only after the upload
|
|
86
|
+
* landed, in the caller's one directory transaction with its admin row. A compare-and-set on
|
|
87
|
+
* `expected`, the record the caller's upload diffed its migrations from (null: the first serve), as
|
|
88
|
+
* `setVerticalServing` is for production: `moved: false`, with nothing written, when the row holds
|
|
89
|
+
* another record now. Refused: a name that is no environment (`not_found`); another script than the
|
|
90
|
+
* one the environment already serves from (`conflict`, since the data lives there); a class set
|
|
91
|
+
* that drops a class the script already has (`validation_failed`: a class's storage cannot go).
|
|
92
|
+
*/
|
|
93
|
+
export declare function setEnvironmentServingIn(sql: SwitchSql, input: DefineEnvironmentInput, next: EnvironmentServing, expected: EnvironmentServing | null,
|
|
94
|
+
/** The serve's claim (`claimEnvironmentServeIn`): the record lands only while it is still the one held. */
|
|
95
|
+
claim?: string): {
|
|
96
|
+
moved: boolean;
|
|
97
|
+
before: EnvironmentServing | null;
|
|
98
|
+
scopeId: ScopeId | null;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Take the environment's serve lease (#3530 step 4), so its serves run one at a time: a serve uploads
|
|
102
|
+
* onto the script before it records what it uploaded, and two at once could leave the script running
|
|
103
|
+
* the one whose record lost. True when `claim` now holds it: none was held, the one held has lapsed
|
|
104
|
+
* (`until` before `now`), or it is `claim`'s own (renewed). False while another live claim holds it.
|
|
105
|
+
* `not_found` for a name that is no environment.
|
|
106
|
+
*/
|
|
107
|
+
export declare function claimEnvironmentServeIn(sql: SwitchSql, input: DefineEnvironmentInput, claim: string, at: {
|
|
108
|
+
now: string;
|
|
109
|
+
until: string;
|
|
110
|
+
}): boolean;
|
|
111
|
+
/** Give the serve lease back. Only `claim`'s own: a lapsed claim taken over since is left to its holder. */
|
|
112
|
+
export declare function releaseEnvironmentServeIn(sql: SwitchSql, input: DefineEnvironmentInput, claim: string): void;
|
|
113
|
+
//# sourceMappingURL=app-environments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-environments.d.ts","sourceRoot":"","sources":["../src/app-environments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAA0D,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAE5K,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,6PAShC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,YAC1C,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,4BAA4B,EAI5B,kBAAkB,EAClB,0BAA0B,CAClB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,gIACuF,CAAC;AAyBhI;;;GAGG;AACH,eAAO,MAAM,gBAAgB,aAAc,MAAM,OAAO,MAAM,KAAG,MAAiD,CAAC;AAwBnH;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAwBrG;AAED,0GAA0G;AAC1G,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzG;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,I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