@milaboratories/pl-middle-layer 1.67.5 → 1.68.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/block_registry/registry-v2-provider.d.ts +1 -3
- package/dist/block_registry/registry-v2-provider.d.ts.map +1 -1
- package/dist/block_registry/registry.d.ts +5 -9
- package/dist/block_registry/registry.d.ts.map +1 -1
- package/dist/block_registry/template_provider.d.ts +3 -5
- package/dist/block_registry/template_provider.d.ts.map +1 -1
- package/dist/block_registry/watcher.d.ts +4 -6
- package/dist/block_registry/watcher.d.ts.map +1 -1
- package/dist/block_registry/well_known_registries.d.ts +3 -5
- package/dist/block_registry/well_known_registries.d.ts.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/middle_layer/build_stamp.cjs +34 -0
- package/dist/middle_layer/build_stamp.cjs.map +1 -0
- package/dist/middle_layer/build_stamp.js +34 -0
- package/dist/middle_layer/build_stamp.js.map +1 -0
- package/dist/middle_layer/driver_kit.d.ts +3 -4
- package/dist/middle_layer/driver_kit.d.ts.map +1 -1
- package/dist/middle_layer/index.d.ts +3 -2
- package/dist/middle_layer/middle_layer.cjs +48 -0
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +23 -4
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +48 -0
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/ops.cjs +8 -2
- package/dist/middle_layer/ops.cjs.map +1 -1
- package/dist/middle_layer/ops.d.ts +70 -26
- package/dist/middle_layer/ops.d.ts.map +1 -1
- package/dist/middle_layer/ops.js +8 -2
- package/dist/middle_layer/ops.js.map +1 -1
- package/dist/middle_layer/project.cjs +163 -8
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +56 -7
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +165 -11
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_list.d.ts +5 -3
- package/dist/middle_layer/project_list.d.ts.map +1 -1
- package/dist/middle_layer/sharing_list.d.ts +3 -4
- package/dist/middle_layer/sharing_list.d.ts.map +1 -1
- package/dist/middle_layer/tree_snapshot_store.cjs +283 -0
- package/dist/middle_layer/tree_snapshot_store.cjs.map +1 -0
- package/dist/middle_layer/tree_snapshot_store.d.ts +143 -0
- package/dist/middle_layer/tree_snapshot_store.d.ts.map +1 -0
- package/dist/middle_layer/tree_snapshot_store.js +280 -0
- package/dist/middle_layer/tree_snapshot_store.js.map +1 -0
- package/dist/middle_layer/types.d.ts +1 -3
- package/dist/middle_layer/types.d.ts.map +1 -1
- package/dist/model/block_pack_spec.d.ts +13 -15
- package/dist/model/block_pack_spec.d.ts.map +1 -1
- package/dist/model/frontend.d.ts +1 -2
- package/dist/model/frontend.d.ts.map +1 -1
- package/dist/model/project_helper.d.ts +2 -4
- package/dist/model/project_helper.d.ts.map +1 -1
- package/dist/model/project_model.d.ts +12 -12
- package/dist/model/project_model.d.ts.map +1 -1
- package/dist/model/sharing_model.d.ts +24 -26
- package/dist/model/sharing_model.d.ts.map +1 -1
- package/dist/model/template_apply.d.ts +9 -8
- package/dist/model/template_apply.d.ts.map +1 -1
- package/dist/model/template_export.d.ts +2 -2
- package/dist/model/template_export.d.ts.map +1 -1
- package/dist/model/template_parser.d.ts +2 -4
- package/dist/model/template_parser.d.ts.map +1 -1
- package/dist/model/template_resolve.d.ts +10 -11
- package/dist/model/template_resolve.d.ts.map +1 -1
- package/dist/model/template_serializer.d.ts +6 -5
- package/dist/model/template_serializer.d.ts.map +1 -1
- package/dist/model/template_spec.d.ts +7 -9
- package/dist/model/template_spec.d.ts.map +1 -1
- package/dist/mutator/block-pack/block_pack.d.ts +2 -3
- package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
- package/dist/mutator/project.cjs +20 -3
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts +4 -3
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +20 -3
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/template/render_template.d.ts +1 -3
- package/dist/mutator/template/render_template.d.ts.map +1 -1
- package/dist/mutator/template/template_cache.d.ts +15 -16
- package/dist/mutator/template/template_cache.d.ts.map +1 -1
- package/dist/mutator/template/template_loading.d.ts +10 -12
- package/dist/mutator/template/template_loading.d.ts.map +1 -1
- package/dist/network_check/network_check.d.ts +3 -5
- package/dist/network_check/network_check.d.ts.map +1 -1
- package/dist/pool/data.d.ts +2 -4
- package/dist/pool/data.d.ts.map +1 -1
- package/dist/pool/driver.d.ts +6 -6
- package/dist/pool/driver.d.ts.map +1 -1
- package/dist/pool/index.d.ts +1 -0
- package/dist/pool/p_object_collection.d.ts +1 -3
- package/dist/pool/p_object_collection.d.ts.map +1 -1
- package/dist/pool/result_pool.d.ts +3 -1
- package/dist/worker/worker.d.ts +1 -1
- package/package.json +14 -14
- package/src/middle_layer/build_stamp.ts +36 -0
- package/src/middle_layer/index.ts +1 -0
- package/src/middle_layer/middle_layer.ts +77 -0
- package/src/middle_layer/ops.ts +46 -1
- package/src/middle_layer/project.ts +234 -14
- package/src/middle_layer/project_failsafe.test.ts +47 -0
- package/src/middle_layer/tree_snapshot_scenarios.test.ts +337 -0
- package/src/middle_layer/tree_snapshot_store.test.ts +331 -0
- package/src/middle_layer/tree_snapshot_store.ts +419 -0
- package/src/mutator/project.ts +27 -5
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { ML_BUILD_STAMP } from "./build_stamp.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createPathAtomically, ensureDirExists } from "@milaboratories/ts-helpers";
|
|
4
|
+
import fsp from "node:fs/promises";
|
|
5
|
+
import { parseSignedResourceId } from "@milaboratories/pl-client";
|
|
6
|
+
import { PERSISTED_TREE_SCHEMA_VERSION, decodePersistedTree, encodePersistedTree, readPersistedTreeHeader } from "@milaboratories/pl-tree";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
//#region src/middle_layer/tree_snapshot_store.ts
|
|
9
|
+
function initialStat() {
|
|
10
|
+
return {
|
|
11
|
+
reads: 0,
|
|
12
|
+
hits: 0,
|
|
13
|
+
restores: 0,
|
|
14
|
+
misses: {
|
|
15
|
+
absent: 0,
|
|
16
|
+
unreadable: 0,
|
|
17
|
+
"session-rotated": 0,
|
|
18
|
+
"not-a-snapshot": 0,
|
|
19
|
+
"unknown-schema": 0,
|
|
20
|
+
truncated: 0,
|
|
21
|
+
checksum: 0,
|
|
22
|
+
malformed: 0
|
|
23
|
+
},
|
|
24
|
+
writes: 0,
|
|
25
|
+
writeFailures: 0,
|
|
26
|
+
bytesWritten: 0,
|
|
27
|
+
discarded: 0,
|
|
28
|
+
evicted: 0,
|
|
29
|
+
evictedForSize: 0,
|
|
30
|
+
bytesEvicted: 0,
|
|
31
|
+
millisReading: 0,
|
|
32
|
+
millisWriting: 0
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const FILE_PREFIX = "tree.";
|
|
36
|
+
const FILE_SUFFIX = ".plts";
|
|
37
|
+
/** Keeps a filename to characters every filesystem we target accepts. */
|
|
38
|
+
function safe(part) {
|
|
39
|
+
return part.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
40
|
+
}
|
|
41
|
+
/** Names this class writes: a finished snapshot, or the staging file of a write killed before
|
|
42
|
+
* its rename. The directory is caller-supplied and only defaults to one of ours, so nothing
|
|
43
|
+
* failing this is ever deleted, by the purge or by the startup eviction. */
|
|
44
|
+
function isOurFile(name) {
|
|
45
|
+
if (!name.startsWith(FILE_PREFIX)) return false;
|
|
46
|
+
return name.endsWith(FILE_SUFFIX) || name.includes(`${FILE_SUFFIX}.tmp.`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Snapshots of project tree mirrors on the local filesystem.
|
|
50
|
+
*
|
|
51
|
+
* A snapshot is addressed by backend instance, authenticated user, root resource, build stamp
|
|
52
|
+
* and snapshot schema version. Everything except the root goes into the *scope*, which is
|
|
53
|
+
* fixed for the lifetime of a client; the root distinguishes one project from another, so
|
|
54
|
+
* there is one file per project per user per backend, rewritten in place.
|
|
55
|
+
*
|
|
56
|
+
* The session is deliberately not part of the key. It is witnessed inside the file and
|
|
57
|
+
* compared on read: a snapshot from an ended session is a miss, but the file is kept, because
|
|
58
|
+
* its bodies remain valid indefinitely and only its signatures have died. Deleting it would
|
|
59
|
+
* destroy the evidence a future signature refresh would repair.
|
|
60
|
+
*/
|
|
61
|
+
var TreeSnapshotStore = class TreeSnapshotStore {
|
|
62
|
+
ops;
|
|
63
|
+
scope;
|
|
64
|
+
stat = initialStat();
|
|
65
|
+
constructor(ops, scope) {
|
|
66
|
+
this.ops = ops;
|
|
67
|
+
this.scope = scope;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Builds a store for the given client, or returns undefined when nothing should be
|
|
71
|
+
* persisted for it.
|
|
72
|
+
*
|
|
73
|
+
* Returns undefined for an impersonated client: reading and writing under `asUser` would
|
|
74
|
+
* leave another user's mirror at rest under the admin's identity, usable only if the admin
|
|
75
|
+
* returned to that exact root. One condition removes both the hygiene question and the
|
|
76
|
+
* orphan one.
|
|
77
|
+
*/
|
|
78
|
+
static create(pl, ops) {
|
|
79
|
+
if (!ops.enabled) {
|
|
80
|
+
ops.logger.info("tree snapshots are disabled by configuration");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (pl.conf.asUser !== void 0) {
|
|
84
|
+
ops.logger.info("tree snapshots are disabled while the client is opened as another user");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const identity = createHash("sha256").update([
|
|
88
|
+
pl.conf.hostAndPort,
|
|
89
|
+
pl.serverInfo.instanceId ?? "",
|
|
90
|
+
pl.authUser ?? ""
|
|
91
|
+
].join("\0")).digest("hex").slice(0, 16);
|
|
92
|
+
return new TreeSnapshotStore(ops, `${PERSISTED_TREE_SCHEMA_VERSION}.${safe(ML_BUILD_STAMP)}.${identity}`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Removes this class's files from the snapshot directory. Run when snapshots are switched
|
|
96
|
+
* off, so a user who turns the kill switch off because the disk is full or unwritable
|
|
97
|
+
* actually gets the space back, rather than leaving up to the size ceiling stranded there
|
|
98
|
+
* indefinitely.
|
|
99
|
+
*
|
|
100
|
+
* Deliberately keyed on the setting rather than on "there is no store": a store is also
|
|
101
|
+
* absent for an impersonated client, and deleting there would destroy the operator's own
|
|
102
|
+
* snapshots from their ordinary sessions. Never throws.
|
|
103
|
+
*/
|
|
104
|
+
static async purge(dir, logger) {
|
|
105
|
+
try {
|
|
106
|
+
for (const name of await fsp.readdir(dir)) {
|
|
107
|
+
if (!isOurFile(name)) continue;
|
|
108
|
+
await fsp.rm(path.join(dir, name), { force: true }).catch(() => {});
|
|
109
|
+
}
|
|
110
|
+
await fsp.rmdir(dir).catch(() => {});
|
|
111
|
+
} catch (e) {
|
|
112
|
+
if (e?.code === "ENOENT") return;
|
|
113
|
+
logger.warn(`failed to clear the tree snapshot directory: ${e instanceof Error ? e.message : String(e)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getStats() {
|
|
117
|
+
return this.stat;
|
|
118
|
+
}
|
|
119
|
+
fileFor(root) {
|
|
120
|
+
const { globalId } = parseSignedResourceId(root);
|
|
121
|
+
return path.join(this.ops.dir, `${FILE_PREFIX}${this.scope}.${globalId}${FILE_SUFFIX}`);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reads the snapshot for a project root, or reports why there is nothing to restore.
|
|
125
|
+
*
|
|
126
|
+
* `root` is the id as resolved in the current session. Its signature is what the stored
|
|
127
|
+
* witness is compared against, so a rotated session is detected without inflating the
|
|
128
|
+
* payload, and no separate session lookup is needed anywhere.
|
|
129
|
+
*/
|
|
130
|
+
async read(root) {
|
|
131
|
+
const started = Date.now();
|
|
132
|
+
this.stat.reads++;
|
|
133
|
+
try {
|
|
134
|
+
const file = this.fileFor(root);
|
|
135
|
+
let bytes;
|
|
136
|
+
try {
|
|
137
|
+
bytes = await fsp.readFile(file);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
const absent = e?.code === "ENOENT";
|
|
140
|
+
if (!absent) this.ops.logger.warn(`tree snapshot exists but could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
141
|
+
return this.miss(absent ? "absent" : "unreadable");
|
|
142
|
+
}
|
|
143
|
+
const header = readPersistedTreeHeader(bytes);
|
|
144
|
+
if (!header.ok) return this.miss(header.reason);
|
|
145
|
+
const { signature } = parseSignedResourceId(root);
|
|
146
|
+
if (!Buffer.from(header.value.witness).equals(Buffer.from(signature))) return this.miss("session-rotated");
|
|
147
|
+
const decoded = await decodePersistedTree(bytes);
|
|
148
|
+
if (!decoded.ok) return this.miss(decoded.reason);
|
|
149
|
+
const now = /* @__PURE__ */ new Date();
|
|
150
|
+
await fsp.utimes(file, now, now).catch(() => {});
|
|
151
|
+
this.stat.hits++;
|
|
152
|
+
return {
|
|
153
|
+
ok: true,
|
|
154
|
+
tree: decoded.value
|
|
155
|
+
};
|
|
156
|
+
} finally {
|
|
157
|
+
this.stat.millisReading += Date.now() - started;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
miss(miss) {
|
|
161
|
+
this.stat.misses[miss]++;
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
miss
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** Recorded by the caller once it knows the tree accepted the snapshot. The store cannot
|
|
168
|
+
* tell on its own: it hands over bytes, and whether they become a tree is the tree's call. */
|
|
169
|
+
noteRestored() {
|
|
170
|
+
this.stat.restores++;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Writes a snapshot, replacing any previous one for the same project.
|
|
174
|
+
*
|
|
175
|
+
* Never throws and never rejects: a write is an optimisation, and a full disk or a
|
|
176
|
+
* permissions problem must not fail the operation that triggered it. Staged and renamed
|
|
177
|
+
* into place, so a process killed mid-write leaves the previous snapshot rather than a torn
|
|
178
|
+
* one.
|
|
179
|
+
*/
|
|
180
|
+
async write(root, snapshot, ops = {}) {
|
|
181
|
+
const started = Date.now();
|
|
182
|
+
try {
|
|
183
|
+
const bytes = await encodePersistedTree(snapshot, { compress: ops.compress });
|
|
184
|
+
await ensureDirExists(this.ops.dir);
|
|
185
|
+
const file = this.fileFor(root);
|
|
186
|
+
await createPathAtomically(this.ops.logger, file, async (tempPath) => {
|
|
187
|
+
await fsp.writeFile(tempPath, bytes, { flag: "wx" });
|
|
188
|
+
});
|
|
189
|
+
this.stat.writes++;
|
|
190
|
+
this.stat.bytesWritten += bytes.length;
|
|
191
|
+
return true;
|
|
192
|
+
} catch (e) {
|
|
193
|
+
this.stat.writeFailures++;
|
|
194
|
+
this.ops.logger.warn(`failed to write tree snapshot: ${e instanceof Error ? e.message : String(e)}`);
|
|
195
|
+
return false;
|
|
196
|
+
} finally {
|
|
197
|
+
this.stat.millisWriting += Date.now() - started;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Deletes the snapshot for a project. Used by the fail-safe, when a restored tree turns
|
|
201
|
+
* out not to match what the backend will serve. Never throws. */
|
|
202
|
+
async discard(root) {
|
|
203
|
+
try {
|
|
204
|
+
await fsp.rm(this.fileFor(root), { force: true });
|
|
205
|
+
this.stat.discarded++;
|
|
206
|
+
} catch (e) {
|
|
207
|
+
this.ops.logger.warn(`failed to discard tree snapshot: ${e instanceof Error ? e.message : String(e)}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Startup housekeeping. Drops every snapshot outside the current scope (another build,
|
|
212
|
+
* backend, user or schema version), then trims what is left to the size ceiling, least
|
|
213
|
+
* recently written first.
|
|
214
|
+
*
|
|
215
|
+
* Modification time stands in for recency of use: an open project is rewritten
|
|
216
|
+
* periodically, so the file's age tracks how recently the project was worked on. Read times
|
|
217
|
+
* would be a truer signal but atime is unreliable across platforms and mount options.
|
|
218
|
+
*
|
|
219
|
+
* Runs at startup only, so the ceiling bounds what a session starts with rather than capping
|
|
220
|
+
* it throughout: a long session opening many projects can exceed it until the next launch.
|
|
221
|
+
*
|
|
222
|
+
* Never throws: an unusable cache directory should cost the cache, not the startup.
|
|
223
|
+
*/
|
|
224
|
+
async evict() {
|
|
225
|
+
try {
|
|
226
|
+
await ensureDirExists(this.ops.dir);
|
|
227
|
+
const names = await fsp.readdir(this.ops.dir);
|
|
228
|
+
const current = [];
|
|
229
|
+
for (const name of names) {
|
|
230
|
+
const file = path.join(this.ops.dir, name);
|
|
231
|
+
const inScope = name.startsWith(`${FILE_PREFIX}${this.scope}.`) && name.endsWith(FILE_SUFFIX);
|
|
232
|
+
if (!inScope && !isOurFile(name)) continue;
|
|
233
|
+
let size = 0;
|
|
234
|
+
let mtimeMs = 0;
|
|
235
|
+
try {
|
|
236
|
+
const stat = await fsp.stat(file);
|
|
237
|
+
if (!stat.isFile()) continue;
|
|
238
|
+
size = stat.size;
|
|
239
|
+
mtimeMs = stat.mtimeMs;
|
|
240
|
+
} catch {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (inScope) {
|
|
244
|
+
current.push({
|
|
245
|
+
file,
|
|
246
|
+
size,
|
|
247
|
+
mtimeMs
|
|
248
|
+
});
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
await this.remove(file, size, false);
|
|
252
|
+
}
|
|
253
|
+
const ceiling = this.ops.maxSizeBytes;
|
|
254
|
+
let total = current.reduce((sum, e) => sum + e.size, 0);
|
|
255
|
+
if (total <= ceiling) return;
|
|
256
|
+
current.sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
257
|
+
for (const entry of current) {
|
|
258
|
+
if (total <= ceiling) break;
|
|
259
|
+
if (await this.remove(entry.file, entry.size, true)) total -= entry.size;
|
|
260
|
+
}
|
|
261
|
+
} catch (e) {
|
|
262
|
+
this.ops.logger.warn(`tree snapshot eviction failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async remove(file, size, forSize) {
|
|
266
|
+
try {
|
|
267
|
+
await fsp.rm(file, { force: true });
|
|
268
|
+
this.stat.evicted++;
|
|
269
|
+
this.stat.bytesEvicted += size;
|
|
270
|
+
if (forSize) this.stat.evictedForSize++;
|
|
271
|
+
return true;
|
|
272
|
+
} catch {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
//#endregion
|
|
278
|
+
export { TreeSnapshotStore };
|
|
279
|
+
|
|
280
|
+
//# sourceMappingURL=tree_snapshot_store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree_snapshot_store.js","names":[],"sources":["../../src/middle_layer/tree_snapshot_store.ts"],"sourcesContent":["import type { PersistedTree, PersistedTreeReadFailure } from \"@milaboratories/pl-tree\";\nimport {\n decodePersistedTree,\n encodePersistedTree,\n PERSISTED_TREE_SCHEMA_VERSION,\n readPersistedTreeHeader,\n} from \"@milaboratories/pl-tree\";\nimport type { PlClient, SignedResourceId } from \"@milaboratories/pl-client\";\nimport { parseSignedResourceId } from \"@milaboratories/pl-client\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { createPathAtomically, ensureDirExists } from \"@milaboratories/ts-helpers\";\nimport { createHash } from \"node:crypto\";\nimport fsp from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { ML_BUILD_STAMP } from \"./build_stamp\";\n\n/** Why a read did not produce a tree to restore from. Counted rather than inferred, because\n * \"no snapshot\" and \"a snapshot we refused\" are very different things when a warm reopen\n * fails to be warm and someone has to work out why. */\nexport type TreeSnapshotMiss =\n /** No file for this key: a first open, or the key moved (new build, new backend, new user). */\n | \"absent\"\n /** A file is there but could not be opened at all: permissions, a bad mount, an I/O error.\n * Distinct from `absent` because a first open and a broken cache directory need different\n * answers from whoever reads the counters. */\n | \"unreadable\"\n /** File exists, but its signatures belong to a session that has ended. Kept, not deleted. */\n | \"session-rotated\"\n /** File exists and could not be read. Carries the codec's reason. */\n | PersistedTreeReadFailure;\n\nexport type TreeSnapshotStat = {\n reads: number;\n /** Snapshots read successfully. A hit is not yet a warm open: the tree can still refuse to\n * apply it, which is what {@link restores} counts. */\n hits: number;\n /** Snapshots actually applied as a tree's initial state. This is the number that says a\n * reopen was warm. */\n restores: number;\n /** Miss counts by reason. */\n misses: Record<TreeSnapshotMiss, number>;\n writes: number;\n writeFailures: number;\n bytesWritten: number;\n /** Snapshots deleted by the fail-safe after a restored tree failed its first refresh. */\n discarded: number;\n /** Files removed at startup, and how many of those were dropped for being over the ceiling\n * rather than for belonging to another build, backend or user. */\n evicted: number;\n evictedForSize: number;\n bytesEvicted: number;\n millisReading: number;\n millisWriting: number;\n};\n\nfunction initialStat(): TreeSnapshotStat {\n return {\n reads: 0,\n hits: 0,\n restores: 0,\n misses: {\n absent: 0,\n unreadable: 0,\n \"session-rotated\": 0,\n \"not-a-snapshot\": 0,\n \"unknown-schema\": 0,\n truncated: 0,\n checksum: 0,\n malformed: 0,\n },\n writes: 0,\n writeFailures: 0,\n bytesWritten: 0,\n discarded: 0,\n evicted: 0,\n evictedForSize: 0,\n bytesEvicted: 0,\n millisReading: 0,\n millisWriting: 0,\n };\n}\n\nexport type TreeSnapshotStoreOps = {\n /** Directory holding the snapshots. One file per project. */\n readonly dir: string;\n /** Total bytes the directory may occupy after startup eviction. */\n readonly maxSizeBytes: number;\n readonly logger: MiLogger;\n};\n\nconst FILE_PREFIX = \"tree.\";\nconst FILE_SUFFIX = \".plts\";\n\n/** Keeps a filename to characters every filesystem we target accepts. */\nfunction safe(part: string): string {\n return part.replace(/[^A-Za-z0-9_-]/g, \"_\");\n}\n\n/** Names this class writes: a finished snapshot, or the staging file of a write killed before\n * its rename. The directory is caller-supplied and only defaults to one of ours, so nothing\n * failing this is ever deleted, by the purge or by the startup eviction. */\nfunction isOurFile(name: string): boolean {\n if (!name.startsWith(FILE_PREFIX)) return false;\n return name.endsWith(FILE_SUFFIX) || name.includes(`${FILE_SUFFIX}.tmp.`);\n}\n\n/**\n * Snapshots of project tree mirrors on the local filesystem.\n *\n * A snapshot is addressed by backend instance, authenticated user, root resource, build stamp\n * and snapshot schema version. Everything except the root goes into the *scope*, which is\n * fixed for the lifetime of a client; the root distinguishes one project from another, so\n * there is one file per project per user per backend, rewritten in place.\n *\n * The session is deliberately not part of the key. It is witnessed inside the file and\n * compared on read: a snapshot from an ended session is a miss, but the file is kept, because\n * its bodies remain valid indefinitely and only its signatures have died. Deleting it would\n * destroy the evidence a future signature refresh would repair.\n */\nexport class TreeSnapshotStore {\n private readonly stat = initialStat();\n\n private constructor(\n private readonly ops: TreeSnapshotStoreOps,\n /** Identifies backend, user, build and schema. Same for every project in this session. */\n private readonly scope: string,\n ) {}\n\n /**\n * Builds a store for the given client, or returns undefined when nothing should be\n * persisted for it.\n *\n * Returns undefined for an impersonated client: reading and writing under `asUser` would\n * leave another user's mirror at rest under the admin's identity, usable only if the admin\n * returned to that exact root. One condition removes both the hygiene question and the\n * orphan one.\n */\n public static create(\n pl: PlClient,\n ops: TreeSnapshotStoreOps & { readonly enabled: boolean },\n ): TreeSnapshotStore | undefined {\n if (!ops.enabled) {\n ops.logger.info(\"tree snapshots are disabled by configuration\");\n return undefined;\n }\n if (pl.conf.asUser !== undefined) {\n ops.logger.info(\"tree snapshots are disabled while the client is opened as another user\");\n return undefined;\n }\n\n // The backend *instance*, not merely its address: instanceId rotates whenever the backend\n // resets its database, which is exactly the case where the same address starts serving a\n // different state under reused global ids. Without it, a reset at a fixed address (a local\n // backend, whose working directory does not move) would be a key hit, and the only thing\n // left to catch it would be the witness, which is empty on both sides on a backend that\n // predates resource signatures.\n //\n // Hashed rather than spelled out: a login can be an email and an address can carry\n // characters a filename cannot. The hash only has to be stable and to differ when any part\n // differs, both of which it does. The NUL separator keeps the parts unambiguous.\n const identity = createHash(\"sha256\")\n .update([pl.conf.hostAndPort, pl.serverInfo.instanceId ?? \"\", pl.authUser ?? \"\"].join(\"\\0\"))\n .digest(\"hex\")\n .slice(0, 16);\n\n const scope = `${PERSISTED_TREE_SCHEMA_VERSION}.${safe(ML_BUILD_STAMP)}.${identity}`;\n return new TreeSnapshotStore(ops, scope);\n }\n\n /**\n * Removes this class's files from the snapshot directory. Run when snapshots are switched\n * off, so a user who turns the kill switch off because the disk is full or unwritable\n * actually gets the space back, rather than leaving up to the size ceiling stranded there\n * indefinitely.\n *\n * Deliberately keyed on the setting rather than on \"there is no store\": a store is also\n * absent for an impersonated client, and deleting there would destroy the operator's own\n * snapshots from their ordinary sessions. Never throws.\n */\n public static async purge(dir: string, logger: MiLogger): Promise<void> {\n try {\n // Deliberately NOT a recursive delete of `dir`. The path is caller-supplied and only\n // defaults to a directory of ours, so removing it wholesale would let a misconfigured\n // `treeSnapshotPath` take an unrelated directory with it, at the exact moment the user\n // reached for a switch labelled \"my disk is troublesome\". Only files this class writes\n // are removed, then the directory itself if that emptied it.\n for (const name of await fsp.readdir(dir)) {\n if (!isOurFile(name)) continue;\n await fsp.rm(path.join(dir, name), { force: true }).catch(() => {});\n }\n await fsp.rmdir(dir).catch(() => {\n // Still holds something that is not ours; leaving it is the point.\n });\n } catch (e: unknown) {\n if ((e as NodeJS.ErrnoException | null)?.code === \"ENOENT\") return;\n logger.warn(\n `failed to clear the tree snapshot directory: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n }\n\n public getStats(): Readonly<TreeSnapshotStat> {\n return this.stat;\n }\n\n private fileFor(root: SignedResourceId): string {\n // The root's global id, not the signed form: the signature changes every session while\n // the file must not.\n const { globalId } = parseSignedResourceId(root);\n return path.join(this.ops.dir, `${FILE_PREFIX}${this.scope}.${globalId}${FILE_SUFFIX}`);\n }\n\n /**\n * Reads the snapshot for a project root, or reports why there is nothing to restore.\n *\n * `root` is the id as resolved in the current session. Its signature is what the stored\n * witness is compared against, so a rotated session is detected without inflating the\n * payload, and no separate session lookup is needed anywhere.\n */\n public async read(\n root: SignedResourceId,\n ): Promise<{ ok: true; tree: PersistedTree } | { ok: false; miss: TreeSnapshotMiss }> {\n const started = Date.now();\n this.stat.reads++;\n try {\n const file = this.fileFor(root);\n let bytes: Buffer;\n try {\n bytes = await fsp.readFile(file);\n } catch (e: unknown) {\n // A missing file and an unreadable one both mean a cold open, but they are different\n // problems: one is an ordinary first open, the other is a cache directory that needs\n // attention, and the counters are the only place that difference is visible.\n const absent = (e as NodeJS.ErrnoException | null)?.code === \"ENOENT\";\n if (!absent)\n this.ops.logger.warn(\n `tree snapshot exists but could not be read: ${e instanceof Error ? e.message : String(e)}`,\n );\n return this.miss(absent ? \"absent\" : \"unreadable\");\n }\n\n const header = readPersistedTreeHeader(bytes);\n if (!header.ok) return this.miss(header.reason);\n\n // On a backend predating resource signatures both sides are empty and always match,\n // which is right: without signatures the ids are not session-bound in the first place.\n const { signature } = parseSignedResourceId(root);\n if (!Buffer.from(header.value.witness).equals(Buffer.from(signature)))\n // Kept, not deleted. See the class comment.\n return this.miss(\"session-rotated\");\n\n const decoded = await decodePersistedTree(bytes);\n if (!decoded.ok) return this.miss(decoded.reason);\n\n // Touched on a hit so the modification time tracks last *use*, which is what the size\n // trim is supposed to order by. Without this, a project reopened every day but never\n // changed is never rewritten, and so ages out ahead of one touched once and abandoned.\n const now = new Date();\n await fsp.utimes(file, now, now).catch(() => {\n // Ordering the trim is not worth failing a hit over.\n });\n\n this.stat.hits++;\n return { ok: true, tree: decoded.value };\n } finally {\n this.stat.millisReading += Date.now() - started;\n }\n }\n\n private miss(miss: TreeSnapshotMiss): { ok: false; miss: TreeSnapshotMiss } {\n this.stat.misses[miss]++;\n return { ok: false, miss };\n }\n\n /** Recorded by the caller once it knows the tree accepted the snapshot. The store cannot\n * tell on its own: it hands over bytes, and whether they become a tree is the tree's call. */\n public noteRestored(): void {\n this.stat.restores++;\n }\n\n /**\n * Writes a snapshot, replacing any previous one for the same project.\n *\n * Never throws and never rejects: a write is an optimisation, and a full disk or a\n * permissions problem must not fail the operation that triggered it. Staged and renamed\n * into place, so a process killed mid-write leaves the previous snapshot rather than a torn\n * one.\n */\n public async write(\n root: SignedResourceId,\n snapshot: PersistedTree,\n ops: { compress?: boolean } = {},\n ): Promise<boolean> {\n const started = Date.now();\n try {\n const bytes = await encodePersistedTree(snapshot, { compress: ops.compress });\n await ensureDirExists(this.ops.dir);\n\n const file = this.fileFor(root);\n await createPathAtomically(this.ops.logger, file, async (tempPath) => {\n // \"wx\" so a colliding temp name fails instead of overwriting another writer's file.\n await fsp.writeFile(tempPath, bytes, { flag: \"wx\" });\n });\n\n this.stat.writes++;\n this.stat.bytesWritten += bytes.length;\n return true;\n } catch (e: unknown) {\n this.stat.writeFailures++;\n this.ops.logger.warn(\n `failed to write tree snapshot: ${e instanceof Error ? e.message : String(e)}`,\n );\n return false;\n } finally {\n this.stat.millisWriting += Date.now() - started;\n }\n }\n\n /** Deletes the snapshot for a project. Used by the fail-safe, when a restored tree turns\n * out not to match what the backend will serve. Never throws. */\n public async discard(root: SignedResourceId): Promise<void> {\n try {\n await fsp.rm(this.fileFor(root), { force: true });\n this.stat.discarded++;\n } catch (e: unknown) {\n this.ops.logger.warn(\n `failed to discard tree snapshot: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n }\n\n /**\n * Startup housekeeping. Drops every snapshot outside the current scope (another build,\n * backend, user or schema version), then trims what is left to the size ceiling, least\n * recently written first.\n *\n * Modification time stands in for recency of use: an open project is rewritten\n * periodically, so the file's age tracks how recently the project was worked on. Read times\n * would be a truer signal but atime is unreliable across platforms and mount options.\n *\n * Runs at startup only, so the ceiling bounds what a session starts with rather than capping\n * it throughout: a long session opening many projects can exceed it until the next launch.\n *\n * Never throws: an unusable cache directory should cost the cache, not the startup.\n */\n public async evict(): Promise<void> {\n try {\n await ensureDirExists(this.ops.dir);\n const names = await fsp.readdir(this.ops.dir);\n\n const current: { file: string; size: number; mtimeMs: number }[] = [];\n\n for (const name of names) {\n const file = path.join(this.ops.dir, name);\n\n // Anything of ours not addressed to the current scope goes: another build, backend,\n // user or schema version, and also the staging files of a write that was killed\n // before its rename, which end in `.tmp.<hex>` rather than the suffix.\n const inScope =\n name.startsWith(`${FILE_PREFIX}${this.scope}.`) && name.endsWith(FILE_SUFFIX);\n\n // Out of scope is not the same as ours to delete: a `treeSnapshotPath` pointed at an\n // existing or shared directory would otherwise have every file in it removed at\n // startup. Same rule as `purge`, for the same reason.\n if (!inScope && !isOurFile(name)) continue;\n\n let size = 0;\n let mtimeMs = 0;\n try {\n const stat = await fsp.stat(file);\n if (!stat.isFile()) continue;\n size = stat.size;\n mtimeMs = stat.mtimeMs;\n } catch {\n continue; // vanished under us, or unreadable: nothing to account for\n }\n\n if (inScope) {\n current.push({ file, size, mtimeMs });\n continue;\n }\n\n await this.remove(file, size, false);\n }\n\n const ceiling = this.ops.maxSizeBytes;\n let total = current.reduce((sum, e) => sum + e.size, 0);\n if (total <= ceiling) return;\n\n // Oldest first, so the projects a user is actually working on are the ones that survive.\n current.sort((a, b) => a.mtimeMs - b.mtimeMs);\n for (const entry of current) {\n if (total <= ceiling) break;\n // Only a file that actually went stops counting against the ceiling. Subtracting\n // regardless would let one undeletable file end the trim early and leave the directory\n // over its limit.\n if (await this.remove(entry.file, entry.size, true)) total -= entry.size;\n }\n } catch (e: unknown) {\n this.ops.logger.warn(\n `tree snapshot eviction failed: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n }\n\n private async remove(file: string, size: number, forSize: boolean): Promise<boolean> {\n try {\n await fsp.rm(file, { force: true });\n this.stat.evicted++;\n this.stat.bytesEvicted += size;\n if (forSize) this.stat.evictedForSize++;\n return true;\n } catch {\n // A file we cannot delete is not worth failing startup over; it will be reconsidered\n // on the next one.\n return false;\n }\n }\n}\n"],"mappings":";;;;;;;;AAuDA,SAAS,cAAgC;CACvC,OAAO;EACL,OAAO;EACP,MAAM;EACN,UAAU;EACV,QAAQ;GACN,QAAQ;GACR,YAAY;GACZ,mBAAmB;GACnB,kBAAk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,KAAK,KAAK;GACV,KAAK,KAAK,gBAAgB;GAC1B,IAAI,SAAS,KAAK,KAAK;GACvB,OAAO;EACT,QAAQ;GAGN,OAAO;EACT;CACF;AACF"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { SynchronizedTreeOps, SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
2
2
|
import { Computable } from "@milaboratories/computable";
|
|
3
|
-
|
|
4
3
|
//#region src/middle_layer/types.d.ts
|
|
5
|
-
type TemporalSynchronizedTreeOps = Pick<SynchronizedTreeOps, "pollingInterval" | "stopPollingDelay" | "logStat" | "initialTreeLoadingTimeout" | "traversalMode">;
|
|
4
|
+
export type TemporalSynchronizedTreeOps = Pick<SynchronizedTreeOps, "pollingInterval" | "stopPollingDelay" | "logStat" | "initialTreeLoadingTimeout" | "traversalMode">;
|
|
6
5
|
//#endregion
|
|
7
|
-
export { TemporalSynchronizedTreeOps };
|
|
8
6
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/middle_layer/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/middle_layer/types.ts"],"mappings":";;;YAGY,8BAA8B,KACxC"}
|
|
@@ -2,31 +2,30 @@ import { CachedTemplate, ExplicitTemplate, PreparedTemplate } from "./template_s
|
|
|
2
2
|
import { BlockConfigContainer } from "@platforma-sdk/model";
|
|
3
3
|
import { BlockPackSpec } from "@milaboratories/pl-model-middle-layer";
|
|
4
4
|
import { ResourceType } from "@milaboratories/pl-client";
|
|
5
|
-
|
|
6
5
|
//#region src/model/block_pack_spec.d.ts
|
|
7
|
-
type FrontendSpec = FrontendFromUrl | FrontendFromFolder | FrontendFromLocalTgz;
|
|
8
|
-
interface FrontendFromUrlData {
|
|
6
|
+
export type FrontendSpec = FrontendFromUrl | FrontendFromFolder | FrontendFromLocalTgz;
|
|
7
|
+
export interface FrontendFromUrlData {
|
|
9
8
|
url: string;
|
|
10
9
|
}
|
|
11
|
-
declare const FrontendFromUrlResourceType: ResourceType;
|
|
10
|
+
export declare const FrontendFromUrlResourceType: ResourceType;
|
|
12
11
|
/** Directs user of the block pack to download the contents from the URL
|
|
13
12
|
* outside the pl infrastructure. */
|
|
14
|
-
interface FrontendFromUrl extends FrontendFromUrlData {
|
|
13
|
+
export interface FrontendFromUrl extends FrontendFromUrlData {
|
|
15
14
|
type: "url";
|
|
16
15
|
}
|
|
17
|
-
interface FrontendFromFolderData {
|
|
16
|
+
export interface FrontendFromFolderData {
|
|
18
17
|
path: string;
|
|
19
18
|
/** HMAC signature of the path using local secret encoded as hex. */
|
|
20
19
|
signature: string;
|
|
21
20
|
}
|
|
22
|
-
declare const FrontendFromFolderResourceType: ResourceType;
|
|
21
|
+
export declare const FrontendFromFolderResourceType: ResourceType;
|
|
23
22
|
/** Directs user of the block pack to load frontend from specific local
|
|
24
23
|
* folder. Signature allows to confirm that this is the same client who
|
|
25
24
|
* added the resource. */
|
|
26
|
-
interface FrontendFromFolder extends FrontendFromFolderData {
|
|
25
|
+
export interface FrontendFromFolder extends FrontendFromFolderData {
|
|
27
26
|
type: "local";
|
|
28
27
|
}
|
|
29
|
-
interface FrontendFromLocalTgzData {
|
|
28
|
+
export interface FrontendFromLocalTgzData {
|
|
30
29
|
/** Absolute path to a local `ui.tgz` archive. */
|
|
31
30
|
path: string;
|
|
32
31
|
/** Modification stamp of the source block; part of the cache key so the
|
|
@@ -35,17 +34,17 @@ interface FrontendFromLocalTgzData {
|
|
|
35
34
|
/** HMAC signature of `path + ":" + mtime` using local secret, encoded as hex. */
|
|
36
35
|
signature: string;
|
|
37
36
|
}
|
|
38
|
-
declare const FrontendFromLocalTgzResourceType: ResourceType;
|
|
37
|
+
export declare const FrontendFromLocalTgzResourceType: ResourceType;
|
|
39
38
|
/** Directs user of the block pack to lazily unpack the frontend from a local
|
|
40
39
|
* `ui.tgz` archive via the download driver — so it inherits the driver's
|
|
41
40
|
* usage-tracking and space recycling (unlike `local`, which serves a folder
|
|
42
41
|
* path directly). Used by the `from-pack-v2` loader for npm-consumed blocks. */
|
|
43
|
-
interface FrontendFromLocalTgz extends FrontendFromLocalTgzData {
|
|
42
|
+
export interface FrontendFromLocalTgz extends FrontendFromLocalTgzData {
|
|
44
43
|
type: "local-tgz";
|
|
45
44
|
}
|
|
46
45
|
/** Direct instructions to create block-pack from client. Currently, this
|
|
47
46
|
* is the only block-pack spec that can be directly materialized. */
|
|
48
|
-
interface BlockPackExplicit {
|
|
47
|
+
export interface BlockPackExplicit {
|
|
49
48
|
type: "explicit";
|
|
50
49
|
template: ExplicitTemplate;
|
|
51
50
|
config: BlockConfigContainer;
|
|
@@ -53,7 +52,7 @@ interface BlockPackExplicit {
|
|
|
53
52
|
source: BlockPackSpec;
|
|
54
53
|
}
|
|
55
54
|
/** Block-pack spec that can be materialized in pl. */
|
|
56
|
-
type BlockPackSpecPrepared = {
|
|
55
|
+
export type BlockPackSpecPrepared = {
|
|
57
56
|
type: "prepared";
|
|
58
57
|
template: PreparedTemplate | CachedTemplate;
|
|
59
58
|
config: BlockConfigContainer;
|
|
@@ -67,7 +66,6 @@ type BlockPackSpecPrepared = {
|
|
|
67
66
|
requiredCapabilities?: string[];
|
|
68
67
|
};
|
|
69
68
|
/** All block-pack specs. */
|
|
70
|
-
type BlockPackSpecAny = BlockPackSpecPrepared | BlockPackExplicit | BlockPackSpec;
|
|
69
|
+
export type BlockPackSpecAny = BlockPackSpecPrepared | BlockPackExplicit | BlockPackSpec;
|
|
71
70
|
//#endregion
|
|
72
|
-
export { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared, FrontendFromFolder, FrontendFromFolderData, FrontendFromFolderResourceType, FrontendFromLocalTgz, FrontendFromLocalTgzData, FrontendFromLocalTgzResourceType, FrontendFromUrl, FrontendFromUrlData, FrontendFromUrlResourceType, FrontendSpec };
|
|
73
71
|
//# sourceMappingURL=block_pack_spec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_pack_spec.d.ts","names":[],"sources":["../../src/model/block_pack_spec.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"block_pack_spec.d.ts","names":[],"sources":["../../src/model/block_pack_spec.ts"],"mappings":";;;;;YAKY,eAAe,kBAAkB,qBAAqB;iBAEjD;EACf;;qBAGW,6BAA6B;;;iBAIzB,wBAAwB;EACvC;;iBAGe;EACf;;EAEA;;qBAGW,gCAAgC;;;;iBAQ5B,2BAA2B;EAC1C;;iBAGe;;EAEf;;;EAGA;;EAEA;;qBAGW,kCAAkC;;;;;iBAS9B,6BAA6B;EAC5C;;;;iBAKe;EACf;EACA,UAAU;EACV,QAAQ;EACR,UAAU;EACV,QAAQ;;;YAIE;EACV;EACA,UAAU,mBAAmB;EAC7B,QAAQ;EACR,UAAU;EACV,QAAQ;;;;;;EAMR;;;YAIU,mBAAmB,wBAAwB,oBAAoB"}
|
package/dist/model/frontend.d.ts
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
/** Middle layer provides information about where frontend for a specific block
|
|
3
3
|
* was unpacked and basic meta information about the enclosed UI
|
|
4
4
|
* (i.e. SDK version). */
|
|
5
|
-
interface FrontendData {
|
|
5
|
+
export interface FrontendData {
|
|
6
6
|
/** URL of the frontend */
|
|
7
7
|
readonly url: string;
|
|
8
8
|
/** SDK version used by the UI */
|
|
9
9
|
readonly sdkVersion: string;
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
|
-
export { FrontendData };
|
|
13
12
|
//# sourceMappingURL=frontend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend.d.ts","names":[],"sources":["../../src/model/frontend.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"frontend.d.ts","names":[],"sources":["../../src/model/frontend.ts"],"mappings":";;;;iBAGiB;;WAEN;;WAGA"}
|
|
@@ -4,7 +4,6 @@ import { MiLogger } from "@milaboratories/ts-helpers";
|
|
|
4
4
|
import { StringifiedJson } from "@milaboratories/pl-model-common";
|
|
5
5
|
import { SignedResourceId } from "@milaboratories/pl-client";
|
|
6
6
|
import { QuickJSWASMModule } from "quickjs-emscripten";
|
|
7
|
-
|
|
8
7
|
//#region src/model/project_helper.d.ts
|
|
9
8
|
/**
|
|
10
9
|
* Result of VM-based storage migration.
|
|
@@ -13,14 +12,14 @@ import { QuickJSWASMModule } from "quickjs-emscripten";
|
|
|
13
12
|
* - Error result: { error: string } - serious failure (no context, etc.)
|
|
14
13
|
* - Success result: { newStorageJson: StringifiedJson<BlockStorage>, info: string } - migration succeeded
|
|
15
14
|
*/
|
|
16
|
-
type MigrationResult = {
|
|
15
|
+
export type MigrationResult = {
|
|
17
16
|
error: string;
|
|
18
17
|
} | {
|
|
19
18
|
error?: undefined;
|
|
20
19
|
newStorageJson: StringifiedJson<BlockStorage>;
|
|
21
20
|
info: string;
|
|
22
21
|
};
|
|
23
|
-
declare class ProjectHelper {
|
|
22
|
+
export declare class ProjectHelper {
|
|
24
23
|
private readonly quickJs;
|
|
25
24
|
readonly logger: MiLogger;
|
|
26
25
|
private readonly enrichmentTargetsCache;
|
|
@@ -181,5 +180,4 @@ declare class ProjectHelper {
|
|
|
181
180
|
migrateStorageInVM(blockConfig: BlockConfig, currentStorageJson: string | undefined): MigrationResult;
|
|
182
181
|
}
|
|
183
182
|
//#endregion
|
|
184
|
-
export { MigrationResult, ProjectHelper };
|
|
185
183
|
//# sourceMappingURL=project_helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_helper.d.ts","names":[],"sources":["../../src/model/project_helper.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"project_helper.d.ts","names":[],"sources":["../../src/model/project_helper.ts"],"mappings":";;;;;;;;;;;;;;YAgCY;EACN;;EACA;EAAmB,gBAAgB,gBAAgB;EAAe;;qBAsB3D;mBAaQ;WACD,QAAQ;mBAbT;EAWjB,YACmB,SAAS,mBACV,SAAQ;;;;;;;;;;;;EAkBnB,sBACL,aAAa,aACb,sBACC;;;;;;;;;EAgCI,4BAA4B,aAAa,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDtD,gCACL,aAAa,aACb,sBACC;UAsDK;EAaD,qBACL,mBAAmB,aACnB,qBACA;IAAQ,SAAS;IAAkB,cAAc;MAChD;;;;;;;;;;;EAqBI,sBAAsB,aAAa;;;;;;;;;;;;;;;;;;;;;;EA2CnC,2BACL,aAAa,aACb,kBACC;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDI,gCACL,aAAa,aACb,iBACA,UAAU,8BACT;;;;;;;;;;;;;;EA0EI,uBACL,aAAa,aACb,4BACA;IAAW;IAAmB;;;;;;;;;;EAwCzB,wBACL,aAAa,aACb,qCACC,gBAAgB;;;;;;;;;;;;;;;;EA0CZ,mBACL,aAAa,aACb,yCACC"}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
+
import "@platforma-sdk/model";
|
|
1
2
|
import { ProjectListEntry, ProjectMeta } from "@milaboratories/pl-model-middle-layer";
|
|
2
3
|
import { ProjectId as ProjectId$1 } from "@milaboratories/pl-model-common";
|
|
3
4
|
import { ResourceType } from "@milaboratories/pl-client";
|
|
4
|
-
|
|
5
5
|
//#region src/model/project_model.d.ts
|
|
6
6
|
interface ProjectListEntry$1 extends Omit<ProjectListEntry, "id"> {
|
|
7
7
|
/** Unique project identifier in middle layer. Use to operate with given project. */
|
|
8
8
|
id: ProjectId$1;
|
|
9
9
|
}
|
|
10
|
-
declare const ProjectResourceType: ResourceType;
|
|
11
|
-
declare const SchemaVersionKey = "SchemaVersion";
|
|
12
|
-
declare const SchemaVersionCurrent = "4";
|
|
13
|
-
declare const ProjectCreatedTimestamp = "ProjectCreated";
|
|
14
|
-
declare const ProjectLastModifiedTimestamp = "ProjectLastModified";
|
|
15
|
-
declare const ProjectMetaKey = "ProjectMeta";
|
|
16
|
-
declare const ProjectStructureKey = "ProjectStructure";
|
|
17
|
-
declare const BlockArgsAuthorKeyPrefix = "BlockArgsAuthor/";
|
|
18
|
-
declare const ProjectStructureAuthorKey = "ProjectStructureAuthor";
|
|
19
|
-
interface ProjectField {
|
|
10
|
+
export declare const ProjectResourceType: ResourceType;
|
|
11
|
+
export declare const SchemaVersionKey = "SchemaVersion";
|
|
12
|
+
export declare const SchemaVersionCurrent = "4";
|
|
13
|
+
export declare const ProjectCreatedTimestamp = "ProjectCreated";
|
|
14
|
+
export declare const ProjectLastModifiedTimestamp = "ProjectLastModified";
|
|
15
|
+
export declare const ProjectMetaKey = "ProjectMeta";
|
|
16
|
+
export declare const ProjectStructureKey = "ProjectStructure";
|
|
17
|
+
export declare const BlockArgsAuthorKeyPrefix = "BlockArgsAuthor/";
|
|
18
|
+
export declare const ProjectStructureAuthorKey = "ProjectStructureAuthor";
|
|
19
|
+
export interface ProjectField {
|
|
20
20
|
blockId: string;
|
|
21
21
|
fieldName: "blockPack" | "blockSettings" | "blockStorage" | "prodArgs" | "currentArgs" | "currentPrerunArgs" | "prodChainCtx" | "prodCtx" | "prodUiCtx" | "prodOutput" | "prodCtxPrevious" | "prodUiCtxPrevious" | "prodOutputPrevious" | "stagingCtx" | "stagingUiCtx" | "stagingOutput" | "stagingCtxPrevious" | "stagingUiCtxPrevious" | "stagingOutputPrevious";
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
|
-
export {
|
|
24
|
+
export { type ProjectId$1 as ProjectId, ProjectListEntry$1 as ProjectListEntry };
|
|
25
25
|
//# sourceMappingURL=project_model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_model.d.ts","names":[],"sources":["../../src/model/project_model.ts"],"mappings":";;;;;UAUiB,
|
|
1
|
+
{"version":3,"file":"project_model.d.ts","names":[],"sources":["../../src/model/project_model.ts"],"mappings":";;;;;UAUiB,2BAAyB,KAAK;;EAE7C,IAAI;;qBA+DO,qBAAqB;qBAErB;qBAGA;qBAEA;qBACA;qBACA;qBACA;qBAGA;qBAOA;iBAQI;EACf;EACA"}
|