@amalgm/live 0.2.27 → 0.2.29
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/PURPOSE.md +38 -25
- package/README.md +1 -2
- package/dist/contracts/index.d.ts +0 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +0 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/detection/record-proposal.d.ts +3 -2
- package/dist/detection/record-proposal.d.ts.map +1 -1
- package/dist/detection/record-proposal.js +9 -7
- package/dist/detection/record-proposal.js.map +1 -1
- package/dist/entities/cloud.d.ts.map +1 -1
- package/dist/entities/cloud.js +4 -1
- package/dist/entities/cloud.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/machines/index.d.ts +0 -2
- package/dist/machines/index.d.ts.map +1 -1
- package/dist/machines/index.js +0 -2
- package/dist/machines/index.js.map +1 -1
- package/dist/records/authority.d.ts +23 -0
- package/dist/records/authority.d.ts.map +1 -0
- package/dist/records/authority.js +28 -0
- package/dist/records/authority.js.map +1 -0
- package/dist/records/codec.d.ts +6 -0
- package/dist/records/codec.d.ts.map +1 -0
- package/dist/records/codec.js +42 -0
- package/dist/records/codec.js.map +1 -0
- package/dist/records/contracts.d.ts +46 -0
- package/dist/records/contracts.d.ts.map +1 -0
- package/dist/records/contracts.js +114 -0
- package/dist/records/contracts.js.map +1 -0
- package/dist/records/inbox.d.ts +18 -0
- package/dist/records/inbox.d.ts.map +1 -0
- package/dist/records/inbox.js +34 -0
- package/dist/records/inbox.js.map +1 -0
- package/dist/records/index.d.ts +7 -0
- package/dist/records/index.d.ts.map +1 -0
- package/dist/records/index.js +7 -0
- package/dist/records/index.js.map +1 -0
- package/dist/records/outbox.d.ts +20 -0
- package/dist/records/outbox.d.ts.map +1 -0
- package/dist/records/outbox.js +44 -0
- package/dist/records/outbox.js.map +1 -0
- package/dist/registration/user-ground.d.ts +4 -4
- package/dist/registration/user-ground.d.ts.map +1 -1
- package/dist/registration/user-ground.js +8 -3
- package/dist/registration/user-ground.js.map +1 -1
- package/dist-cjs/contracts/binding.js +26 -0
- package/dist-cjs/contracts/binding.js.map +1 -0
- package/dist-cjs/contracts/content.js +99 -0
- package/dist-cjs/contracts/content.js.map +1 -0
- package/dist-cjs/contracts/docs.js +56 -0
- package/dist-cjs/contracts/docs.js.map +1 -0
- package/dist-cjs/contracts/events.js +44 -0
- package/dist-cjs/contracts/events.js.map +1 -0
- package/dist-cjs/contracts/frames/gateway.js +39 -0
- package/dist-cjs/contracts/frames/gateway.js.map +1 -0
- package/dist-cjs/contracts/frames/stream.js +20 -0
- package/dist-cjs/contracts/frames/stream.js.map +1 -0
- package/dist-cjs/contracts/frames/tunnel.js +60 -0
- package/dist-cjs/contracts/frames/tunnel.js.map +1 -0
- package/dist-cjs/contracts/index.js +34 -0
- package/dist-cjs/contracts/index.js.map +1 -0
- package/dist-cjs/contracts/presence.js +38 -0
- package/dist-cjs/contracts/presence.js.map +1 -0
- package/dist-cjs/contracts/resources.js +114 -0
- package/dist-cjs/contracts/resources.js.map +1 -0
- package/dist-cjs/contracts/snapshot.js +31 -0
- package/dist-cjs/contracts/snapshot.js.map +1 -0
- package/dist-cjs/contracts/validate.js +34 -0
- package/dist-cjs/contracts/validate.js.map +1 -0
- package/dist-cjs/detection/adapter-contract.js +168 -0
- package/dist-cjs/detection/adapter-contract.js.map +1 -0
- package/dist-cjs/detection/batch.js +71 -0
- package/dist-cjs/detection/batch.js.map +1 -0
- package/dist-cjs/detection/classify.js +48 -0
- package/dist-cjs/detection/classify.js.map +1 -0
- package/dist-cjs/detection/content.js +122 -0
- package/dist-cjs/detection/content.js.map +1 -0
- package/dist-cjs/detection/continuity.js +88 -0
- package/dist-cjs/detection/continuity.js.map +1 -0
- package/dist-cjs/detection/diff.js +193 -0
- package/dist-cjs/detection/diff.js.map +1 -0
- package/dist-cjs/detection/echo.js +25 -0
- package/dist-cjs/detection/echo.js.map +1 -0
- package/dist-cjs/detection/enrollment.js +189 -0
- package/dist-cjs/detection/enrollment.js.map +1 -0
- package/dist-cjs/detection/index.js +57 -0
- package/dist-cjs/detection/index.js.map +1 -0
- package/dist-cjs/detection/record-proposal.js +170 -0
- package/dist-cjs/detection/record-proposal.js.map +1 -0
- package/dist-cjs/detection/refusal.js +44 -0
- package/dist-cjs/detection/refusal.js.map +1 -0
- package/dist-cjs/detection/repository.js +67 -0
- package/dist-cjs/detection/repository.js.map +1 -0
- package/dist-cjs/detection/territory.js +82 -0
- package/dist-cjs/detection/territory.js.map +1 -0
- package/dist-cjs/detection/watch-boundary.js +51 -0
- package/dist-cjs/detection/watch-boundary.js.map +1 -0
- package/dist-cjs/entities/bytes.js +92 -0
- package/dist-cjs/entities/bytes.js.map +1 -0
- package/dist-cjs/entities/cloud.js +174 -0
- package/dist-cjs/entities/cloud.js.map +1 -0
- package/dist-cjs/entities/index.js +39 -0
- package/dist-cjs/entities/index.js.map +1 -0
- package/dist-cjs/entities/moves.js +85 -0
- package/dist-cjs/entities/moves.js.map +1 -0
- package/dist-cjs/entities/repo-states.js +256 -0
- package/dist-cjs/entities/repo-states.js.map +1 -0
- package/dist-cjs/entities/rules.js +216 -0
- package/dist-cjs/entities/rules.js.map +1 -0
- package/dist-cjs/entities/types.js +44 -0
- package/dist-cjs/entities/types.js.map +1 -0
- package/dist-cjs/files/commands.js +120 -0
- package/dist-cjs/files/commands.js.map +1 -0
- package/dist-cjs/files/index.js +19 -0
- package/dist-cjs/files/index.js.map +1 -0
- package/dist-cjs/index.js +39 -0
- package/dist-cjs/index.js.map +1 -0
- package/dist-cjs/machines/arbitration.js +41 -0
- package/dist-cjs/machines/arbitration.js.map +1 -0
- package/dist-cjs/machines/backoff.js +38 -0
- package/dist-cjs/machines/backoff.js.map +1 -0
- package/dist-cjs/machines/bootstrap.js +110 -0
- package/dist-cjs/machines/bootstrap.js.map +1 -0
- package/dist-cjs/machines/chunks.js +72 -0
- package/dist-cjs/machines/chunks.js.map +1 -0
- package/dist-cjs/machines/index.js +28 -0
- package/dist-cjs/machines/index.js.map +1 -0
- package/dist-cjs/machines/presence.js +53 -0
- package/dist-cjs/machines/presence.js.map +1 -0
- package/dist-cjs/merge/index.js +25 -0
- package/dist-cjs/merge/index.js.map +1 -0
- package/dist-cjs/merge/merge3.js +191 -0
- package/dist-cjs/merge/merge3.js.map +1 -0
- package/dist-cjs/package.json +1 -0
- package/dist-cjs/records/authority.js +31 -0
- package/dist-cjs/records/authority.js.map +1 -0
- package/dist-cjs/records/codec.js +48 -0
- package/dist-cjs/records/codec.js.map +1 -0
- package/dist-cjs/records/contracts.js +121 -0
- package/dist-cjs/records/contracts.js.map +1 -0
- package/dist-cjs/records/inbox.js +37 -0
- package/dist-cjs/records/inbox.js.map +1 -0
- package/dist-cjs/records/index.js +23 -0
- package/dist-cjs/records/index.js.map +1 -0
- package/dist-cjs/records/outbox.js +48 -0
- package/dist-cjs/records/outbox.js.map +1 -0
- package/dist-cjs/registration/index.js +19 -0
- package/dist-cjs/registration/index.js.map +1 -0
- package/dist-cjs/registration/user-ground.js +183 -0
- package/dist-cjs/registration/user-ground.js.map +1 -0
- package/dist-cjs/transfer/artifacts.js +75 -0
- package/dist-cjs/transfer/artifacts.js.map +1 -0
- package/dist-cjs/transfer/batches.js +44 -0
- package/dist-cjs/transfer/batches.js.map +1 -0
- package/dist-cjs/transfer/download.js +88 -0
- package/dist-cjs/transfer/download.js.map +1 -0
- package/dist-cjs/transfer/index.js +21 -0
- package/dist-cjs/transfer/index.js.map +1 -0
- package/dist-cjs/transfer/parallel.js +35 -0
- package/dist-cjs/transfer/parallel.js.map +1 -0
- package/dist-cjs/transfer/upload.js +161 -0
- package/dist-cjs/transfer/upload.js.map +1 -0
- package/dist-cjs/watching/coverage.js +54 -0
- package/dist-cjs/watching/coverage.js.map +1 -0
- package/dist-cjs/watching/index.js +24 -0
- package/dist-cjs/watching/index.js.map +1 -0
- package/dist-cjs/watching/suspicion.js +105 -0
- package/dist-cjs/watching/suspicion.js.map +1 -0
- package/dist-cjs/workspace/api.js +66 -0
- package/dist-cjs/workspace/api.js.map +1 -0
- package/dist-cjs/workspace/identity.js +32 -0
- package/dist-cjs/workspace/identity.js.map +1 -0
- package/dist-cjs/workspace/index.js +14 -0
- package/dist-cjs/workspace/index.js.map +1 -0
- package/dist-cjs/workspace/memory-store.js +21 -0
- package/dist-cjs/workspace/memory-store.js.map +1 -0
- package/dist-cjs/workspace/registry.js +98 -0
- package/dist-cjs/workspace/registry.js.map +1 -0
- package/dist-cjs/workspace/types.js +3 -0
- package/dist-cjs/workspace/types.js.map +1 -0
- package/package.json +30 -8
- package/dist/contracts/mutation.d.ts +0 -51
- package/dist/contracts/mutation.d.ts.map +0 -1
- package/dist/contracts/mutation.js +0 -55
- package/dist/contracts/mutation.js.map +0 -1
- package/dist/machines/journal.d.ts +0 -63
- package/dist/machines/journal.d.ts.map +0 -1
- package/dist/machines/journal.js +0 -71
- package/dist/machines/journal.js.map +0 -1
- package/dist/machines/ordering.d.ts +0 -53
- package/dist/machines/ordering.d.ts.map +0 -1
- package/dist/machines/ordering.js +0 -87
- package/dist/machines/ordering.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"territory.js","sourceRoot":"","sources":["../../src/detection/territory.ts"],"names":[],"mappings":";AAAA,uEAAuE;;AAuBvE,8CAeC;AAWD,0CAkDC;AA7ED,oEAAoE;AACpE,SAAgB,iBAAiB,CAC/B,IAAmB,EACnB,MAAgC;IAEhC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,OAAO,MAAM,KAAK,IAAI,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,EAAE,CAAC,CAAC;QACrF,IAAI,CAAC,GAA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,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5D,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAiB,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,OAAO,GAAqB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,KAAK,MAAM,UAAU,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;QACzC,IAAI,UAAU;YAAE,GAAG,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The complete portable boundary from Watch into Detect and back.
|
|
4
|
+
*
|
|
5
|
+
* Watch contributes generation-stamped suspicion only. Detect retains that
|
|
6
|
+
* generation until Record has durably accepted every resulting proposal. A
|
|
7
|
+
* discovered directory creates a logical coverage request; the Watch host
|
|
8
|
+
* decides whether its backend needs another native handle.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.detectionBatch = detectionBatch;
|
|
12
|
+
exports.directoryCoverageRequests = directoryCoverageRequests;
|
|
13
|
+
const enrollment_js_1 = require("./enrollment.js");
|
|
14
|
+
const detectionRelativePath = (path) => {
|
|
15
|
+
const raw = String(path);
|
|
16
|
+
if (raw.startsWith('/') || /^[A-Za-z]:[\\/]/.test(raw) || raw.includes('\0')) {
|
|
17
|
+
throw new Error('detection path must be root-relative');
|
|
18
|
+
}
|
|
19
|
+
const normalized = (0, enrollment_js_1.normalizedRelativePath)(raw);
|
|
20
|
+
if (!normalized || normalized.split('/').some((segment) => segment === '.' || segment === '..')) {
|
|
21
|
+
throw new Error('detection path must be root-relative');
|
|
22
|
+
}
|
|
23
|
+
return normalized;
|
|
24
|
+
};
|
|
25
|
+
/** Freeze Watch's snapshot into Detection's input vocabulary. */
|
|
26
|
+
function detectionBatch(rootId, snapshot) {
|
|
27
|
+
if (!rootId)
|
|
28
|
+
throw new Error('detection batch root id is required');
|
|
29
|
+
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
|
|
30
|
+
throw new Error('detection batch generation is invalid');
|
|
31
|
+
}
|
|
32
|
+
const suspects = snapshot.paths === null
|
|
33
|
+
? null
|
|
34
|
+
: Object.freeze([...new Set(snapshot.paths.map(detectionRelativePath))]);
|
|
35
|
+
return Object.freeze({ rootId, generation: snapshot.generation, suspects });
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Tell Watch that newly enrolled directory ground now exists. This is emitted
|
|
39
|
+
* on every platform; only the Watch backend knows whether coverage expansion
|
|
40
|
+
* means another Linux inotify handle or merely a routing-table update.
|
|
41
|
+
*/
|
|
42
|
+
function directoryCoverageRequests(batch, createdDirectories) {
|
|
43
|
+
const paths = [...new Set(createdDirectories.map(detectionRelativePath))]
|
|
44
|
+
.sort();
|
|
45
|
+
return Object.freeze(paths.map((relPath) => Object.freeze({
|
|
46
|
+
kind: 'directory-discovered',
|
|
47
|
+
rootId: batch.rootId,
|
|
48
|
+
relPath,
|
|
49
|
+
})));
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=watch-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-boundary.js","sourceRoot":"","sources":["../../src/detection/watch-boundary.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AA+BH,wCAYC;AAOD,8DAWC;AA1DD,mDAAyD;AAEzD,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAU,EAAE;IACrD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;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;;;;GAIG;AACH,SAAgB,yBAAyB,CACvC,KAAqC,EACrC,kBAAqC;IAErC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC;SACtE,IAAI,EAAE,CAAC;IACV,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;QACxD,IAAI,EAAE,sBAA+B;QACrC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO;KACR,CAAC,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Portable byte codecs shared by the entity layer — UTF-8, standard base64
|
|
4
|
+
* (padded, as Node's `Buffer#toString('base64')` emits it), base64url, and
|
|
5
|
+
* hex. They exist so cloud.ts and repo-states.ts can produce byte-for-byte
|
|
6
|
+
* the same wire text the engine produces with Buffer, without src/
|
|
7
|
+
* importing any Node module (PURPOSE.md axiom 2).
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.bytesToBase64Url = exports.bytesToBase64 = exports.utf8Decode = exports.utf8Encode = void 0;
|
|
11
|
+
exports.base64ToBytes = base64ToBytes;
|
|
12
|
+
exports.hexToBytes = hexToBytes;
|
|
13
|
+
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
14
|
+
const BASE64_URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
15
|
+
const utf8Encode = (text) => new TextEncoder().encode(text);
|
|
16
|
+
exports.utf8Encode = utf8Encode;
|
|
17
|
+
const utf8Decode = (bytes) => new TextDecoder().decode(bytes);
|
|
18
|
+
exports.utf8Decode = utf8Decode;
|
|
19
|
+
function encode(bytes, alphabet, pad) {
|
|
20
|
+
// Write the ASCII result once. Building base64 through string appends makes
|
|
21
|
+
// V8 retain repository-sized ropes whose intermediate nodes can dwarf the
|
|
22
|
+
// parcel and exhaust the default heap.
|
|
23
|
+
const paddedLength = Math.ceil(bytes.length / 3) * 4;
|
|
24
|
+
const outputLength = pad ? paddedLength : Math.ceil(bytes.length * 4 / 3);
|
|
25
|
+
const out = new Uint8Array(outputLength);
|
|
26
|
+
let offset = 0;
|
|
27
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
28
|
+
const a = bytes[i];
|
|
29
|
+
const b = bytes[i + 1];
|
|
30
|
+
const c = bytes[i + 2];
|
|
31
|
+
out[offset++] = alphabet.charCodeAt(a >> 2);
|
|
32
|
+
out[offset++] = alphabet.charCodeAt(((a & 0x03) << 4) | ((b ?? 0) >> 4));
|
|
33
|
+
if (b === undefined) {
|
|
34
|
+
if (pad) {
|
|
35
|
+
out[offset++] = 61;
|
|
36
|
+
out[offset++] = 61;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
out[offset++] = alphabet.charCodeAt(((b & 0x0f) << 2) | ((c ?? 0) >> 6));
|
|
41
|
+
if (c === undefined) {
|
|
42
|
+
if (pad)
|
|
43
|
+
out[offset++] = 61;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
out[offset++] = alphabet.charCodeAt(c & 0x3f);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return new TextDecoder().decode(out);
|
|
51
|
+
}
|
|
52
|
+
/** Bytes → standard base64 with padding (Buffer's 'base64' spelling). */
|
|
53
|
+
const bytesToBase64 = (bytes) => encode(bytes, BASE64, true);
|
|
54
|
+
exports.bytesToBase64 = bytesToBase64;
|
|
55
|
+
/** Bytes → unpadded base64url (Buffer's 'base64url' spelling). */
|
|
56
|
+
const bytesToBase64Url = (bytes) => encode(bytes, BASE64_URL, false);
|
|
57
|
+
exports.bytesToBase64Url = bytesToBase64Url;
|
|
58
|
+
/** Standard base64 (padded or unpadded) → bytes. */
|
|
59
|
+
function base64ToBytes(text) {
|
|
60
|
+
const padding = text.indexOf('=');
|
|
61
|
+
const length = padding === -1 ? text.length : padding;
|
|
62
|
+
const out = new Uint8Array(Math.floor(length * 6 / 8));
|
|
63
|
+
let offset = 0;
|
|
64
|
+
let buffer = 0;
|
|
65
|
+
let bits = 0;
|
|
66
|
+
for (let index = 0; index < length; index += 1) {
|
|
67
|
+
const char = text[index];
|
|
68
|
+
const value = BASE64.indexOf(char);
|
|
69
|
+
if (value === -1) {
|
|
70
|
+
throw new Error(`expected standard base64 like "aGVsbG8=" — found ${JSON.stringify(char)}`);
|
|
71
|
+
}
|
|
72
|
+
buffer = (buffer << 6) | value;
|
|
73
|
+
bits += 6;
|
|
74
|
+
if (bits >= 8) {
|
|
75
|
+
bits -= 8;
|
|
76
|
+
out[offset++] = (buffer >> bits) & 0xff;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** Lowercase/uppercase hex → bytes. */
|
|
82
|
+
function hexToBytes(hex) {
|
|
83
|
+
if (hex.length % 2 !== 0 || /[^0-9a-f]/i.test(hex)) {
|
|
84
|
+
throw new Error(`expected even-length hex like "a1b2" — got ${JSON.stringify(hex)}`);
|
|
85
|
+
}
|
|
86
|
+
const out = new Uint8Array(hex.length / 2);
|
|
87
|
+
for (let i = 0; i < out.length; i += 1) {
|
|
88
|
+
out[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/entities/bytes.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA+CH,sCAqBC;AAGD,gCASC;AA9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Y,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,8CAA8C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The entity-cloud boundary's pure half (engine
|
|
4
|
+
* registration/entity-cloud.js): the snapshot codec, record assertions,
|
|
5
|
+
* equality, the private resource id, and the repo travel law — only
|
|
6
|
+
* logical graph facts, never a path, inode, watcher, or database row.
|
|
7
|
+
*
|
|
8
|
+
* Wire parity is the contract here: `stableJson`, record key order, and
|
|
9
|
+
* snapshot sorting reproduce the engine's bytes exactly, so a snapshot
|
|
10
|
+
* packed on either side hashes and compares identically.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.sameRecords = exports.sameRecord = exports.stableJson = exports.ENTITY_CLOUD_SCHEMA_VERSION = exports.ENTITY_CLOUD_CONTRACT = void 0;
|
|
14
|
+
exports.privateEntityResourceId = privateEntityResourceId;
|
|
15
|
+
exports.recordsAreSubset = recordsAreSubset;
|
|
16
|
+
exports.assertRecord = assertRecord;
|
|
17
|
+
exports.enclosedByRepositoryAncestor = enclosedByRepositoryAncestor;
|
|
18
|
+
exports.travelingRecords = travelingRecords;
|
|
19
|
+
exports.snapshotFromRecords = snapshotFromRecords;
|
|
20
|
+
exports.parseSnapshot = parseSnapshot;
|
|
21
|
+
const types_js_1 = require("./types.js");
|
|
22
|
+
const bytes_js_1 = require("./bytes.js");
|
|
23
|
+
/** `@1` could project arbitrary pre-cloud registrations. `@2` omitted the
|
|
24
|
+
* declared built-in tool entities, so its toolbox root could not prove the
|
|
25
|
+
* snapshot membership it named. A resource contract names immutable
|
|
26
|
+
* authority semantics: both remain quarantined rather than reinterpreted
|
|
27
|
+
* or overwritten. `@3` begins with the complete verified user home; later
|
|
28
|
+
* user ground enters exclusively through `amalgm register`. */
|
|
29
|
+
exports.ENTITY_CLOUD_CONTRACT = 'amalgm-entity-registry@3';
|
|
30
|
+
exports.ENTITY_CLOUD_SCHEMA_VERSION = 1;
|
|
31
|
+
/** A 64-hex content head (a SHA-256 naming immutable bytes). */
|
|
32
|
+
const CONTENT_HEAD = /^[0-9a-f]{64}$/;
|
|
33
|
+
/** The deterministic private entity-resource id for a user under the
|
|
34
|
+
* current contract: `pvr_` + the first 32 base64url characters of
|
|
35
|
+
* sha256("private-user:<userId>:<contract>"). */
|
|
36
|
+
function privateEntityResourceId(userId, sha256Hex) {
|
|
37
|
+
return `pvr_${(0, bytes_js_1.bytesToBase64Url)((0, bytes_js_1.hexToBytes)(sha256Hex(`private-user:${userId}:${exports.ENTITY_CLOUD_CONTRACT}`)))
|
|
38
|
+
.slice(0, 32)}`;
|
|
39
|
+
}
|
|
40
|
+
/** The one JSON spelling every snapshot comparison and checksum uses. */
|
|
41
|
+
const stableJson = (value) => JSON.stringify(value);
|
|
42
|
+
exports.stableJson = stableJson;
|
|
43
|
+
const sameRecord = (left, right) => (0, exports.stableJson)(left) === (0, exports.stableJson)(right);
|
|
44
|
+
exports.sameRecord = sameRecord;
|
|
45
|
+
/** Two record lists describe the same graph (normalized, sorted, compared whole). */
|
|
46
|
+
const sameRecords = (left, right) => (0, exports.sameRecord)(snapshotFromRecords(left), snapshotFromRecords(right));
|
|
47
|
+
exports.sameRecords = sameRecords;
|
|
48
|
+
/** Every record in `records` appears byte-identically in `expected`. */
|
|
49
|
+
function recordsAreSubset(records, expected) {
|
|
50
|
+
const expectedByUuid = new Map(snapshotFromRecords(expected).records.map((record) => [record.uuid, record]));
|
|
51
|
+
return snapshotFromRecords(records).records
|
|
52
|
+
.every((record) => (0, exports.sameRecord)(record, expectedByUuid.get(record.uuid)));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate one snapshot record and normalize it (UUIDs lowercased,
|
|
56
|
+
* transportVersion defaulted to null). Refusals: an invalid shape; a
|
|
57
|
+
* parentless record whose type no tree root wears; a transport head on
|
|
58
|
+
* anything but a repository.
|
|
59
|
+
*/
|
|
60
|
+
function assertRecord(value) {
|
|
61
|
+
const record = value;
|
|
62
|
+
if (!record || typeof record !== 'object'
|
|
63
|
+
|| typeof record.uuid !== 'string' || !types_js_1.UUID_PATTERN.test(record.uuid)
|
|
64
|
+
|| typeof record.type !== 'string' || !types_js_1.TYPES.has(record.type)
|
|
65
|
+
|| (record.parentUUID !== null && (typeof record.parentUUID !== 'string' || !types_js_1.UUID_PATTERN.test(record.parentUUID)))
|
|
66
|
+
|| typeof record.name !== 'string' || !record.name || record.name.includes('/') || record.name.includes('\0')
|
|
67
|
+
|| !['active', 'trashed', 'deleted'].includes(record.status)
|
|
68
|
+
|| typeof record.version !== 'string' || !/^[0-9a-f]{64}$/.test(record.version)
|
|
69
|
+
|| (record.payloadVersion !== null && typeof record.payloadVersion !== 'string')
|
|
70
|
+
|| (record.transportVersion !== undefined && record.transportVersion !== null
|
|
71
|
+
&& (typeof record.transportVersion !== 'string' || !CONTENT_HEAD.test(record.transportVersion)))) {
|
|
72
|
+
throw new Error('cloud entity snapshot has an invalid record');
|
|
73
|
+
}
|
|
74
|
+
if (record.parentUUID === null && !types_js_1.ROOT_TYPES.has(record.type)) {
|
|
75
|
+
throw new Error(`cloud entity ${record.uuid} is not a valid tree root`);
|
|
76
|
+
}
|
|
77
|
+
if (types_js_1.DERIVED_PAYLOAD.has(record.type) && record.payloadVersion !== null) {
|
|
78
|
+
throw new Error('workspace and folder payloads are derived membership, never transported heads');
|
|
79
|
+
}
|
|
80
|
+
const transportVersion = (record.transportVersion ?? null);
|
|
81
|
+
if (record.type !== 'repo.git' && transportVersion !== null) {
|
|
82
|
+
throw new Error('only repository entities may declare a transport head');
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
uuid: record.uuid.toLowerCase(),
|
|
86
|
+
type: record.type,
|
|
87
|
+
parentUUID: record.parentUUID === null ? null : record.parentUUID.toLowerCase(),
|
|
88
|
+
name: record.name,
|
|
89
|
+
status: record.status,
|
|
90
|
+
version: record.version,
|
|
91
|
+
payloadVersion: record.payloadVersion,
|
|
92
|
+
transportVersion,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The repo travel law: a record with a `repo.git` PROPER ancestor never
|
|
97
|
+
* travels to the cloud on its own. The repository is the sync boundary —
|
|
98
|
+
* its one Card + Checkpoint state carries the worktree's bytes AND its
|
|
99
|
+
* children's permanent UUIDs (the transport identity map), so a register
|
|
100
|
+
* or a rebase is one parcel, never one postcard per file. Repository
|
|
101
|
+
* boundaries are retained separately by `travelingRecords`: every `.git`
|
|
102
|
+
* starts a new parcel even when another repository encloses it.
|
|
103
|
+
* Missing ancestry keeps the record traveling rather than risking a
|
|
104
|
+
* silently unsynced entity.
|
|
105
|
+
*/
|
|
106
|
+
function enclosedByRepositoryAncestor(record, lookup) {
|
|
107
|
+
const seen = new Set([record.uuid]);
|
|
108
|
+
let parentUUID = record.parentUUID;
|
|
109
|
+
while (parentUUID !== null && parentUUID !== undefined) {
|
|
110
|
+
if (seen.has(parentUUID))
|
|
111
|
+
throw new Error(`cloud entity ${record.uuid} has a cyclic parent chain`);
|
|
112
|
+
seen.add(parentUUID);
|
|
113
|
+
const parent = lookup(parentUUID);
|
|
114
|
+
if (!parent)
|
|
115
|
+
return false;
|
|
116
|
+
if (parent.type === 'repo.git')
|
|
117
|
+
return true;
|
|
118
|
+
parentUUID = parent.parentUUID;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
/** Project a complete local entity graph onto the cloud registry. Ordinary
|
|
123
|
+
* repository children keep their local SQLite identities inside the nearest
|
|
124
|
+
* repository parcel. Every nested repository and the folder spine required to
|
|
125
|
+
* reach it remain graph records, so each `.git` owns and exposes exactly one
|
|
126
|
+
* independent transport without publishing per-file postcards. */
|
|
127
|
+
function travelingRecords(records) {
|
|
128
|
+
const snapshot = snapshotFromRecords(records);
|
|
129
|
+
const byUuid = new Map(snapshot.records.map((record) => [record.uuid, record]));
|
|
130
|
+
const traveling = new Set(snapshot.records
|
|
131
|
+
.filter((record) => !enclosedByRepositoryAncestor(record, (uuid) => byUuid.get(uuid)))
|
|
132
|
+
.map((record) => record.uuid));
|
|
133
|
+
for (const repository of snapshot.records.filter((record) => record.type === 'repo.git')) {
|
|
134
|
+
let cursor = repository;
|
|
135
|
+
while (cursor) {
|
|
136
|
+
traveling.add(cursor.uuid);
|
|
137
|
+
if (cursor.parentUUID === null)
|
|
138
|
+
break;
|
|
139
|
+
cursor = byUuid.get(cursor.parentUUID);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return snapshot.records.filter((record) => traveling.has(record.uuid));
|
|
143
|
+
}
|
|
144
|
+
/** Normalize records into the one canonical snapshot: asserted, sorted by
|
|
145
|
+
* uuid, duplicates refused. */
|
|
146
|
+
function snapshotFromRecords(records) {
|
|
147
|
+
const normalized = records.map(assertRecord)
|
|
148
|
+
.sort((left, right) => (left.uuid < right.uuid ? -1 : left.uuid > right.uuid ? 1 : 0));
|
|
149
|
+
if (new Set(normalized.map((record) => record.uuid)).size !== normalized.length) {
|
|
150
|
+
throw new Error('cloud entity snapshot has duplicate UUIDs');
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
schemaVersion: exports.ENTITY_CLOUD_SCHEMA_VERSION,
|
|
154
|
+
kind: 'amalgm-entity-registry',
|
|
155
|
+
records: normalized,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/** Parse snapshot bytes (or their UTF-8 text) back into the canonical form. */
|
|
159
|
+
function parseSnapshot(bytes) {
|
|
160
|
+
let snapshot;
|
|
161
|
+
try {
|
|
162
|
+
snapshot = JSON.parse(typeof bytes === 'string' ? bytes : (0, bytes_js_1.utf8Decode)(bytes));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
throw new Error('cloud entity snapshot is not JSON');
|
|
166
|
+
}
|
|
167
|
+
if (snapshot?.schemaVersion !== exports.ENTITY_CLOUD_SCHEMA_VERSION
|
|
168
|
+
|| snapshot?.kind !== 'amalgm-entity-registry'
|
|
169
|
+
|| !Array.isArray(snapshot.records)) {
|
|
170
|
+
throw new Error('cloud entity snapshot has an unsupported shape');
|
|
171
|
+
}
|
|
172
|
+
return snapshotFromRecords(snapshot.records);
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=cloud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../src/entities/cloud.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AA4CH,0DAGC;AAaD,4CAMC;AAQD,oCAqCC;AAkBD,oEAeC;AAOD,4CAiBC;AAID,kDAWC;AAGD,sCAaC;AArMD,yCAGoB;AACpB,yCAAsE;AAEtE;;;;;+DAK+D;AAClD,QAAA,qBAAqB,GAAG,0BAA0B,CAAC;AAEnD,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAE7C,gEAAgE;AAChE,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAsBtC;;iDAEiD;AACjD,SAAgB,uBAAuB,CAAC,MAAc,EAAE,SAAoB;IAC1E,OAAO,OAAO,IAAA,2BAAgB,EAAC,IAAA,qBAAU,EAA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CAAC,CAAC,CAAC,IAAA,qBAAU,EAAC,KAAK,CAAC,CAAoB,CAAC;IAClG,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,QAAQ,EAAE,aAAa,KAAK,mCAA2B;WACtD,QAAQ,EAAE,IAAI,KAAK,wBAAwB;WAC3C,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* entities/ — the Register/Record pure cores: the entity model's laws
|
|
4
|
+
* (engine docs/entity-model.md — two axioms, the six-field record) as
|
|
5
|
+
* portable functions. Store reads arrive through `EntityReadPort`, hashing
|
|
6
|
+
* through `Sha256Hex`; nothing here touches SQLite, node:crypto, or a
|
|
7
|
+
* filesystem. Hash formulas and id derivations are byte-for-byte the
|
|
8
|
+
* engine's, so records interoperate across the cloud boundary.
|
|
9
|
+
*
|
|
10
|
+
* - types.ts the alphabet, the six fields, UUID shape, injected ports
|
|
11
|
+
* - bytes.ts portable byte codecs (utf8, base64, base64url, hex)
|
|
12
|
+
* - rules.ts version formula, naming, lifecycle inheritance,
|
|
13
|
+
* slot/container laws, record builders
|
|
14
|
+
* - moves.ts batch move validation: permutations, acyclicity, adoption
|
|
15
|
+
* - cloud.ts entity-cloud snapshot codec + the repo travel law
|
|
16
|
+
* - repo-states.ts Card + Checkpoint state codec and id derivations
|
|
17
|
+
*/
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
30
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
__exportStar(require("./types.js"), exports);
|
|
34
|
+
__exportStar(require("./bytes.js"), exports);
|
|
35
|
+
__exportStar(require("./rules.js"), exports);
|
|
36
|
+
__exportStar(require("./moves.js"), exports);
|
|
37
|
+
__exportStar(require("./cloud.js"), exports);
|
|
38
|
+
__exportStar(require("./repo-states.js"), exports);
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;AAEH,6CAA2B;AAC3B,6CAA2B;AAC3B,6CAA2B;AAC3B,6CAA2B;AAC3B,6CAA2B;AAC3B,mDAAiC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Batch move validation — the entity model's one-truth-transition law for
|
|
4
|
+
* addresses (engine docs/entity-model.md, "Continuity"): the slot law and
|
|
5
|
+
* acyclicity are STATE invariants — they constrain the graph after the
|
|
6
|
+
* batch, never the order inside it — so movers may hold each other's slots
|
|
7
|
+
* (directories exchange addresses on disk, and detection reports the
|
|
8
|
+
* endpoints). A single move is a batch of one.
|
|
9
|
+
*
|
|
10
|
+
* A PARENTLESS mover is ADOPTION: the whole tree joins another under one
|
|
11
|
+
* parent update — a tree boundary is never an identity boundary, so this
|
|
12
|
+
* is the same lawful move, not a special ceremony. Adoption sheds the root
|
|
13
|
+
* shape in the SAME transition: workspace is the root type only, so a
|
|
14
|
+
* parentless workspace landing under a parent lands as a folder — one
|
|
15
|
+
* write, never a two-step that could tear into a nested workspace.
|
|
16
|
+
*
|
|
17
|
+
* This module validates and PLANS; the host's store applies the returned
|
|
18
|
+
* writes in one transaction.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.planMoveBatch = planMoveBatch;
|
|
22
|
+
const types_js_1 = require("./types.js");
|
|
23
|
+
const rules_js_1 = require("./rules.js");
|
|
24
|
+
/**
|
|
25
|
+
* Validate one batch of moves as one transition and return the writes to
|
|
26
|
+
* land together. Refused whole when any move breaks a law: a mover named
|
|
27
|
+
* twice, an inactive mover, an invalid name, a non-container target, two
|
|
28
|
+
* movers claiming one slot, an occupied slot outside the batch, a cycle in
|
|
29
|
+
* the post-state parent graph, or an inactive target chain.
|
|
30
|
+
*/
|
|
31
|
+
function planMoveBatch(moves, port) {
|
|
32
|
+
const byUuid = port.byUuid.bind(port);
|
|
33
|
+
const rows = new Map(); // uuid -> current row
|
|
34
|
+
const post = new Map(); // uuid -> its move
|
|
35
|
+
for (const move of moves) {
|
|
36
|
+
const { uuid, name } = move;
|
|
37
|
+
if (post.has(uuid))
|
|
38
|
+
throw new Error(`one batch moves ${uuid} once, not twice`);
|
|
39
|
+
const row = (0, rules_js_1.mustGet)(uuid, byUuid);
|
|
40
|
+
if (row.status !== 'active') {
|
|
41
|
+
throw new Error(`only an active entity moves: ${uuid} is ${row.status}`);
|
|
42
|
+
}
|
|
43
|
+
(0, rules_js_1.validName)(name);
|
|
44
|
+
rows.set(uuid, row);
|
|
45
|
+
post.set(uuid, move);
|
|
46
|
+
}
|
|
47
|
+
const postParentOf = (uuid) => post.get(uuid)?.parentUUID ?? (0, rules_js_1.mustGet)(uuid, byUuid).parentUuid;
|
|
48
|
+
const targets = new Set();
|
|
49
|
+
for (const { uuid, parentUUID, name } of moves) {
|
|
50
|
+
const parent = (0, rules_js_1.mustGet)(parentUUID, byUuid);
|
|
51
|
+
if (!types_js_1.CONTAINERS.has(parent.type)) {
|
|
52
|
+
throw new Error(`only containers hold active children: ${parentUUID} is ${parent.type}, not workspace/folder/repo.git`);
|
|
53
|
+
}
|
|
54
|
+
const slot = `${parentUUID}\0${name}`;
|
|
55
|
+
if (targets.has(slot))
|
|
56
|
+
throw new Error(`slot taken: two movers claim (${parentUUID}, ${name}) in one batch`);
|
|
57
|
+
targets.add(slot);
|
|
58
|
+
const occupant = port.activeChildByName(parentUUID, name);
|
|
59
|
+
if (occupant && occupant.uuid !== uuid && !post.has(occupant.uuid)) {
|
|
60
|
+
throw new Error(`slot taken: active entity ${occupant.uuid} already owns (${parentUUID}, ${name}) — move or trash it first`);
|
|
61
|
+
}
|
|
62
|
+
// The target parent's whole post-state chain: acyclic and effectively
|
|
63
|
+
// active, walked once.
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
let cursor = parentUUID;
|
|
66
|
+
while (cursor !== null) {
|
|
67
|
+
if (cursor === uuid) {
|
|
68
|
+
throw new Error(`the parent graph is acyclic: ${uuid} cannot live under itself`);
|
|
69
|
+
}
|
|
70
|
+
if (seen.has(cursor))
|
|
71
|
+
throw new Error(`registry corrupt: parent cycle at ${cursor}`);
|
|
72
|
+
seen.add(cursor);
|
|
73
|
+
if ((0, rules_js_1.mustGet)(cursor, byUuid).status !== 'active') {
|
|
74
|
+
throw new Error(`parent ${parentUUID} is not effectively active — restore it before putting entities under it`);
|
|
75
|
+
}
|
|
76
|
+
cursor = postParentOf(cursor);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return moves.map(({ uuid, parentUUID, name }) => {
|
|
80
|
+
const row = rows.get(uuid); // seated in the first pass
|
|
81
|
+
const adoptedWorkspace = row.parentUuid === null && row.type === 'workspace';
|
|
82
|
+
return { uuid, parentUuid: parentUUID, name, ...(adoptedWorkspace ? { type: 'folder' } : {}) };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=moves.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moves.js","sourceRoot":"","sources":["../../src/entities/moves.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AA4BH,sCAmDC;AA7ED,yCAA6E;AAC7E,yCAAgD;AAkBhD;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,KAA4B,EAAE,IAAoB;IAC9E,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC,CAAC,sBAAsB;IACjE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAsB,CAAC,CAAC,mBAAmB;IAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAC5B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,kBAAkB,CAAC,CAAC;QAC/E,MAAM,GAAG,GAAG,IAAA,kBAAO,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,IAAA,oBAAS,EAAC,IAAI,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CA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