@crvouga/mockingbird-runtime 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/adapter-node.d.ts +38 -11
- package/dist/adapter-node.js +82 -174
- package/dist/adapter-node.js.map +4 -4
- package/dist/{chunk-4BRVNPWR.js → chunk-KD6FHYQP.js} +6 -6
- package/dist/{chunk-4BRVNPWR.js.map → chunk-KD6FHYQP.js.map} +2 -2
- package/dist/{chunk-LL6NKAJO.js → chunk-M4HUKBLC.js} +3 -2
- package/dist/chunk-M4HUKBLC.js.map +7 -0
- package/dist/chunk-RI2UQCHP.js +21 -0
- package/dist/chunk-RI2UQCHP.js.map +7 -0
- package/dist/{chunk-2Y25NPCV.js → chunk-U36J5GCB.js} +290 -1
- package/dist/{chunk-2Y25NPCV.js.map → chunk-U36J5GCB.js.map} +3 -3
- package/dist/{chunk-RO7FHXO3.js → chunk-ZQBZSSSP.js} +3 -3
- package/dist/core.d.ts +86 -2
- package/dist/core.js +23 -1
- package/dist/http-provider.js +7 -7
- package/dist/http-provider.js.map +1 -1
- package/dist/mqtt-broker/node.js +4 -4
- package/dist/mqtt-broker.js +4 -4
- package/dist/preview/artifacts.d.ts +4 -9
- package/dist/preview/artifacts.js +4 -16
- package/dist/preview/artifacts.js.map +2 -2
- package/dist/preview/bridge.d.ts +8 -8
- package/dist/preview/bridge.js +1 -1
- package/dist/preview/harness.d.ts +1 -1
- package/dist/preview/harness.js +10 -56
- package/dist/preview/harness.js.map +2 -2
- package/dist/preview/host.d.ts +4 -9
- package/dist/preview/host.js +30 -37
- package/dist/preview/host.js.map +2 -2
- package/dist/service/admin.js +2 -2
- package/dist/service.d.ts +3 -1
- package/dist/service.js +6 -4
- package/dist/ui.d.ts +1 -37
- package/dist/ui.js +2 -701
- package/dist/ui.js.map +3 -3
- package/package.json +7 -6
- package/dist/chunk-EBGYPQPA.js +0 -198
- package/dist/chunk-EBGYPQPA.js.map +0 -7
- package/dist/chunk-LL6NKAJO.js.map +0 -7
- /package/dist/{chunk-RO7FHXO3.js.map → chunk-ZQBZSSSP.js.map} +0 -0
|
@@ -772,6 +772,284 @@ function unpackValue(value) {
|
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
774
|
|
|
775
|
+
// ../core/dist/sha256.js
|
|
776
|
+
var K = Uint32Array.from([
|
|
777
|
+
1116352408,
|
|
778
|
+
1899447441,
|
|
779
|
+
3049323471,
|
|
780
|
+
3921009573,
|
|
781
|
+
961987163,
|
|
782
|
+
1508970993,
|
|
783
|
+
2453635748,
|
|
784
|
+
2870763221,
|
|
785
|
+
3624381080,
|
|
786
|
+
310598401,
|
|
787
|
+
607225278,
|
|
788
|
+
1426881987,
|
|
789
|
+
1925078388,
|
|
790
|
+
2162078206,
|
|
791
|
+
2614888103,
|
|
792
|
+
3248222580,
|
|
793
|
+
3835390401,
|
|
794
|
+
4022224774,
|
|
795
|
+
264347078,
|
|
796
|
+
604807628,
|
|
797
|
+
770255983,
|
|
798
|
+
1249150122,
|
|
799
|
+
1555081692,
|
|
800
|
+
1996064986,
|
|
801
|
+
2554220882,
|
|
802
|
+
2821834349,
|
|
803
|
+
2952996808,
|
|
804
|
+
3210313671,
|
|
805
|
+
3336571891,
|
|
806
|
+
3584528711,
|
|
807
|
+
113926993,
|
|
808
|
+
338241895,
|
|
809
|
+
666307205,
|
|
810
|
+
773529912,
|
|
811
|
+
1294757372,
|
|
812
|
+
1396182291,
|
|
813
|
+
1695183700,
|
|
814
|
+
1986661051,
|
|
815
|
+
2177026350,
|
|
816
|
+
2456956037,
|
|
817
|
+
2730485921,
|
|
818
|
+
2820302411,
|
|
819
|
+
3259730800,
|
|
820
|
+
3345764771,
|
|
821
|
+
3516065817,
|
|
822
|
+
3600352804,
|
|
823
|
+
4094571909,
|
|
824
|
+
275423344,
|
|
825
|
+
430227734,
|
|
826
|
+
506948616,
|
|
827
|
+
659060556,
|
|
828
|
+
883997877,
|
|
829
|
+
958139571,
|
|
830
|
+
1322822218,
|
|
831
|
+
1537002063,
|
|
832
|
+
1747873779,
|
|
833
|
+
1955562222,
|
|
834
|
+
2024104815,
|
|
835
|
+
2227730452,
|
|
836
|
+
2361852424,
|
|
837
|
+
2428436474,
|
|
838
|
+
2756734187,
|
|
839
|
+
3204031479,
|
|
840
|
+
3329325298
|
|
841
|
+
]);
|
|
842
|
+
var rotr = (value, bits) => value >>> bits | value << 32 - bits;
|
|
843
|
+
function sha256Hex(input) {
|
|
844
|
+
const padded = new Uint8Array((input.length + 8 >> 6) + 1 << 6);
|
|
845
|
+
padded.set(input);
|
|
846
|
+
padded[input.length] = 128;
|
|
847
|
+
const view = new DataView(padded.buffer);
|
|
848
|
+
view.setUint32(padded.length - 8, Math.floor(input.length * 8 / 4294967296));
|
|
849
|
+
view.setUint32(padded.length - 4, input.length * 8 >>> 0);
|
|
850
|
+
const h = Uint32Array.from([
|
|
851
|
+
1779033703,
|
|
852
|
+
3144134277,
|
|
853
|
+
1013904242,
|
|
854
|
+
2773480762,
|
|
855
|
+
1359893119,
|
|
856
|
+
2600822924,
|
|
857
|
+
528734635,
|
|
858
|
+
1541459225
|
|
859
|
+
]);
|
|
860
|
+
const w = new Uint32Array(64);
|
|
861
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
862
|
+
for (let i = 0; i < 16; i++)
|
|
863
|
+
w[i] = view.getUint32(offset + i * 4);
|
|
864
|
+
for (let i = 16; i < 64; i++) {
|
|
865
|
+
const w15 = w[i - 15] ?? 0;
|
|
866
|
+
const w2 = w[i - 2] ?? 0;
|
|
867
|
+
const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
|
|
868
|
+
const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
|
|
869
|
+
w[i] = (w[i - 16] ?? 0) + s0 + (w[i - 7] ?? 0) + s1 >>> 0;
|
|
870
|
+
}
|
|
871
|
+
let [a, b, c, d, e, f, g, hh] = h;
|
|
872
|
+
for (let i = 0; i < 64; i++) {
|
|
873
|
+
const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
874
|
+
const choice = e & f ^ ~e & g;
|
|
875
|
+
const t1 = hh + s1 + choice + (K[i] ?? 0) + (w[i] ?? 0) >>> 0;
|
|
876
|
+
const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
877
|
+
const majority = a & b ^ a & c ^ b & c;
|
|
878
|
+
const t2 = s0 + majority >>> 0;
|
|
879
|
+
hh = g;
|
|
880
|
+
g = f;
|
|
881
|
+
f = e;
|
|
882
|
+
e = d + t1 >>> 0;
|
|
883
|
+
d = c;
|
|
884
|
+
c = b;
|
|
885
|
+
b = a;
|
|
886
|
+
a = t1 + t2 >>> 0;
|
|
887
|
+
}
|
|
888
|
+
;
|
|
889
|
+
[a, b, c, d, e, f, g, hh].forEach((value, i) => {
|
|
890
|
+
h[i] = (h[i] ?? 0) + value >>> 0;
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
return [...h].map((word) => word.toString(16).padStart(8, "0")).join("");
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// ../core/dist/fleet-archive.js
|
|
897
|
+
function validateCompatibilityTags(tags) {
|
|
898
|
+
if (!tags || typeof tags !== "object" || Array.isArray(tags))
|
|
899
|
+
throw new Error("invalid archive compatibility tags");
|
|
900
|
+
const entries = Object.entries(tags);
|
|
901
|
+
if (entries.length > 32 || entries.some(([key, value]) => !/^[A-Za-z0-9_.-]{1,64}$/.test(key) || typeof value !== "string" || value.length < 1 || value.length > 256 || [...value].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)))
|
|
902
|
+
throw new Error("invalid archive compatibility tags");
|
|
903
|
+
}
|
|
904
|
+
function assertCompatibilityTags(tags, policy) {
|
|
905
|
+
if (tags !== void 0)
|
|
906
|
+
validateCompatibilityTags(tags);
|
|
907
|
+
if (!policy)
|
|
908
|
+
return;
|
|
909
|
+
validateCompatibilityTags(policy.tags);
|
|
910
|
+
if (policy.missing !== void 0 && !["allow", "reject"].includes(policy.missing))
|
|
911
|
+
throw new Error("invalid missing compatibility policy");
|
|
912
|
+
if (tags === void 0 && policy.missing === "allow")
|
|
913
|
+
return;
|
|
914
|
+
if (canonical(tags) !== canonical(policy.tags))
|
|
915
|
+
throw new Error("application archive compatibility mismatch");
|
|
916
|
+
}
|
|
917
|
+
function assertArchiveCompatibility(input, policy) {
|
|
918
|
+
const archive = validateArchive(input);
|
|
919
|
+
assertCompatibilityTags(archive.compatibility, policy);
|
|
920
|
+
return archive;
|
|
921
|
+
}
|
|
922
|
+
async function migrateApplicationArchive(input, migration) {
|
|
923
|
+
const source = assertArchiveCompatibility(input, migration.from);
|
|
924
|
+
validateCompatibilityTags(migration.to);
|
|
925
|
+
const transformed = await migration.transform(structuredClone(source));
|
|
926
|
+
const { sha256: _sha, ...content } = transformed;
|
|
927
|
+
return validateArchive(sealArchive({ ...content, compatibility: structuredClone(migration.to) }));
|
|
928
|
+
}
|
|
929
|
+
var canonical = (value) => {
|
|
930
|
+
if (Array.isArray(value))
|
|
931
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
932
|
+
if (value !== null && typeof value === "object")
|
|
933
|
+
return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
934
|
+
return JSON.stringify(value);
|
|
935
|
+
};
|
|
936
|
+
var digest = (value) => sha256Hex(new TextEncoder().encode(canonical(value)));
|
|
937
|
+
var sealArchive = (content) => ({
|
|
938
|
+
...content,
|
|
939
|
+
sha256: digest(content)
|
|
940
|
+
});
|
|
941
|
+
function validateArchive(value) {
|
|
942
|
+
if (!value || typeof value !== "object")
|
|
943
|
+
throw new Error("expected fleet archive");
|
|
944
|
+
const doc = value;
|
|
945
|
+
const { sha256, ...content } = doc;
|
|
946
|
+
if (doc.format !== "mockingbird.fleet/v1" || typeof doc.sourceId !== "string" || typeof doc.createdAt !== "string" || !doc.namespaces || typeof doc.namespaces !== "object" || Array.isArray(doc.namespaces) || sha256 !== digest(content))
|
|
947
|
+
throw new Error("unsupported or corrupt fleet archive");
|
|
948
|
+
if (doc.compatibility !== void 0)
|
|
949
|
+
validateCompatibilityTags(doc.compatibility);
|
|
950
|
+
for (const [namespace, entry] of Object.entries(doc.namespaces)) {
|
|
951
|
+
if (!/^[A-Za-z0-9_.-]{1,64}$/.test(namespace) || !entry || !Number.isFinite(entry.clock?.now) || typeof entry.clock?.frozen !== "boolean" || !entry.services || !Object.keys(entry.services).length)
|
|
952
|
+
throw new Error("invalid archive namespace");
|
|
953
|
+
for (const [name, child] of Object.entries(entry.services))
|
|
954
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name) || !child || child.version !== 1 || !["http", "postgres", "redis", "external"].includes(child.protocol))
|
|
955
|
+
throw new Error("unsupported archive service/version");
|
|
956
|
+
}
|
|
957
|
+
return doc;
|
|
958
|
+
}
|
|
959
|
+
function inspectArchive(input) {
|
|
960
|
+
const archive = validateArchive(input);
|
|
961
|
+
return {
|
|
962
|
+
format: archive.format,
|
|
963
|
+
createdAt: archive.createdAt,
|
|
964
|
+
sha256: archive.sha256,
|
|
965
|
+
...archive.compatibility ? { compatibility: archive.compatibility } : {},
|
|
966
|
+
namespaces: Object.fromEntries(Object.entries(archive.namespaces).map(([name, ns]) => [
|
|
967
|
+
name,
|
|
968
|
+
{
|
|
969
|
+
clock: ns.clock,
|
|
970
|
+
services: Object.fromEntries(Object.entries(ns.services).map(([service, state]) => [
|
|
971
|
+
service,
|
|
972
|
+
{
|
|
973
|
+
protocol: state.protocol,
|
|
974
|
+
version: state.version,
|
|
975
|
+
bytes: new TextEncoder().encode(canonical(state.state)).byteLength
|
|
976
|
+
}
|
|
977
|
+
]))
|
|
978
|
+
}
|
|
979
|
+
]))
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
function diffArchives(left, right, options = {}) {
|
|
983
|
+
const a = validateArchive(left), b = validateArchive(right);
|
|
984
|
+
const limit = Math.min(1e3, Math.max(1, options.limit ?? 100));
|
|
985
|
+
const changes = [];
|
|
986
|
+
let total = 0;
|
|
987
|
+
const walk = (namespace, service, path, before, after) => {
|
|
988
|
+
if (canonical(before) === canonical(after))
|
|
989
|
+
return;
|
|
990
|
+
if (before && after && typeof before === "object" && typeof after === "object" && !Array.isArray(before) && !Array.isArray(after)) {
|
|
991
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]))
|
|
992
|
+
walk(namespace, service, `${path}/${key}`, before[key], after[key]);
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
total++;
|
|
996
|
+
if (changes.length < limit)
|
|
997
|
+
changes.push({
|
|
998
|
+
namespace,
|
|
999
|
+
service,
|
|
1000
|
+
path,
|
|
1001
|
+
kind: before === void 0 ? "added" : after === void 0 ? "removed" : "changed",
|
|
1002
|
+
...options.values ? { before, after } : {}
|
|
1003
|
+
});
|
|
1004
|
+
};
|
|
1005
|
+
for (const ns of /* @__PURE__ */ new Set([...Object.keys(a.namespaces), ...Object.keys(b.namespaces)])) {
|
|
1006
|
+
if (options.namespace !== void 0 && options.namespace !== ns)
|
|
1007
|
+
continue;
|
|
1008
|
+
const an = a.namespaces[ns], bn = b.namespaces[ns];
|
|
1009
|
+
walk(ns, "$clock", "/clock", an?.clock, bn?.clock);
|
|
1010
|
+
for (const service of /* @__PURE__ */ new Set([
|
|
1011
|
+
...Object.keys(an?.services ?? {}),
|
|
1012
|
+
...Object.keys(bn?.services ?? {})
|
|
1013
|
+
])) {
|
|
1014
|
+
if (options.service !== void 0 && options.service !== service)
|
|
1015
|
+
continue;
|
|
1016
|
+
const x = an?.services[service], y = bn?.services[service];
|
|
1017
|
+
if (x && y && (x.protocol !== y.protocol || x.version !== y.version))
|
|
1018
|
+
throw new Error("incompatible snapshot comparison");
|
|
1019
|
+
const normalize = (state) => {
|
|
1020
|
+
if (state && typeof state === "object") {
|
|
1021
|
+
const obj = state;
|
|
1022
|
+
if (obj.format === "mockingbird.postgres/v1" && obj.inventory) {
|
|
1023
|
+
if (options.values)
|
|
1024
|
+
throw new Error("raw PostgreSQL row diff is unsupported; use bounded namespace inspection");
|
|
1025
|
+
const { databases: _databases, ...metadata } = obj;
|
|
1026
|
+
return metadata;
|
|
1027
|
+
}
|
|
1028
|
+
if (obj.$redis === "map" && Array.isArray(obj.value))
|
|
1029
|
+
return Object.fromEntries(obj.value.map((pair) => [
|
|
1030
|
+
typeof pair[0] === "string" ? pair[0] : canonical(pair[0]),
|
|
1031
|
+
normalize(pair[1])
|
|
1032
|
+
]));
|
|
1033
|
+
if (Array.isArray(state))
|
|
1034
|
+
return Object.fromEntries(state.map((value, index) => [String(index), normalize(value)]));
|
|
1035
|
+
}
|
|
1036
|
+
if (state && typeof state === "object" && Array.isArray(state.records)) {
|
|
1037
|
+
const { records, ...rest } = state;
|
|
1038
|
+
return {
|
|
1039
|
+
...rest,
|
|
1040
|
+
records: Object.fromEntries(records.map((r) => [`${r.collection}/${r.id}`, r]))
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
if (state && typeof state === "object" && !Array.isArray(state))
|
|
1044
|
+
return Object.fromEntries(Object.entries(state).map(([k, v]) => [k, normalize(v)]));
|
|
1045
|
+
return state;
|
|
1046
|
+
};
|
|
1047
|
+
walk(ns, service, "/state", normalize(x?.state), normalize(y?.state));
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
return { format: "mockingbird.fleet-diff/v1", total, truncated: total > changes.length, changes };
|
|
1051
|
+
}
|
|
1052
|
+
|
|
775
1053
|
// ../core/dist/fork-map.js
|
|
776
1054
|
var ForkMap = class _ForkMap {
|
|
777
1055
|
owner = {};
|
|
@@ -1278,6 +1556,17 @@ export {
|
|
|
1278
1556
|
openBufferedDurable,
|
|
1279
1557
|
packDurableRecord,
|
|
1280
1558
|
unpackDurableRecord,
|
|
1559
|
+
sha256Hex,
|
|
1560
|
+
validateCompatibilityTags,
|
|
1561
|
+
assertCompatibilityTags,
|
|
1562
|
+
assertArchiveCompatibility,
|
|
1563
|
+
migrateApplicationArchive,
|
|
1564
|
+
canonical,
|
|
1565
|
+
digest,
|
|
1566
|
+
sealArchive,
|
|
1567
|
+
validateArchive,
|
|
1568
|
+
inspectArchive,
|
|
1569
|
+
diffArchives,
|
|
1281
1570
|
ForkMap,
|
|
1282
1571
|
requestBaseUrl,
|
|
1283
1572
|
forwardMountContext,
|
|
@@ -1286,4 +1575,4 @@ export {
|
|
|
1286
1575
|
toFetchHandler,
|
|
1287
1576
|
fromFetchHandler
|
|
1288
1577
|
};
|
|
1289
|
-
//# sourceMappingURL=chunk-
|
|
1578
|
+
//# sourceMappingURL=chunk-U36J5GCB.js.map
|