@resourcexjs/cli 2.5.5 → 2.5.7
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/index.js +1005 -84
- package/dist/index.js.map +8 -8
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -769,9 +769,975 @@ var init_prompt = __esm(() => {
|
|
|
769
769
|
kCancel = Symbol.for("cancel");
|
|
770
770
|
});
|
|
771
771
|
|
|
772
|
-
// ../../
|
|
772
|
+
// ../../packages/core/dist/index.js
|
|
773
|
+
import { gzip } from "zlib";
|
|
774
|
+
import { promisify } from "util";
|
|
775
|
+
import { gunzip } from "zlib";
|
|
776
|
+
import { promisify as promisify2 } from "util";
|
|
777
|
+
import { join, relative } from "path";
|
|
778
|
+
import { stat, readFile as readFile2, readdir } from "fs/promises";
|
|
779
|
+
import { createHash } from "crypto";
|
|
780
|
+
function define(input) {
|
|
781
|
+
if (input === null || typeof input !== "object") {
|
|
782
|
+
throw new DefinitionError("definition must be an object");
|
|
783
|
+
}
|
|
784
|
+
const obj = input;
|
|
785
|
+
if (!obj.name || typeof obj.name !== "string") {
|
|
786
|
+
throw new DefinitionError("name is required");
|
|
787
|
+
}
|
|
788
|
+
if (!obj.type || typeof obj.type !== "string") {
|
|
789
|
+
throw new DefinitionError("type is required");
|
|
790
|
+
}
|
|
791
|
+
const tagValue = obj.tag ?? obj.version;
|
|
792
|
+
if (tagValue !== undefined && typeof tagValue !== "string") {
|
|
793
|
+
throw new DefinitionError("tag must be a string");
|
|
794
|
+
}
|
|
795
|
+
const rxd = {
|
|
796
|
+
...obj,
|
|
797
|
+
name: obj.name,
|
|
798
|
+
type: obj.type,
|
|
799
|
+
tag: typeof tagValue === "string" ? tagValue : undefined,
|
|
800
|
+
registry: typeof obj.registry === "string" ? obj.registry : undefined,
|
|
801
|
+
path: typeof obj.path === "string" ? obj.path : undefined,
|
|
802
|
+
description: typeof obj.description === "string" ? obj.description : undefined,
|
|
803
|
+
author: typeof obj.author === "string" ? obj.author : undefined,
|
|
804
|
+
license: typeof obj.license === "string" ? obj.license : undefined,
|
|
805
|
+
keywords: Array.isArray(obj.keywords) ? obj.keywords : undefined,
|
|
806
|
+
repository: typeof obj.repository === "string" ? obj.repository : undefined
|
|
807
|
+
};
|
|
808
|
+
return rxd;
|
|
809
|
+
}
|
|
810
|
+
function manifest(rxd) {
|
|
811
|
+
return {
|
|
812
|
+
registry: rxd.registry,
|
|
813
|
+
path: rxd.path,
|
|
814
|
+
name: rxd.name,
|
|
815
|
+
type: rxd.type,
|
|
816
|
+
tag: rxd.tag ?? "latest"
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
function writeString(view, offset, size, value) {
|
|
820
|
+
if (value)
|
|
821
|
+
encoder.encodeInto(value, view.subarray(offset, offset + size));
|
|
822
|
+
}
|
|
823
|
+
function writeOctal(view, offset, size, value) {
|
|
824
|
+
if (value === undefined)
|
|
825
|
+
return;
|
|
826
|
+
const octalString = value.toString(8).padStart(size - 1, "0");
|
|
827
|
+
encoder.encodeInto(octalString, view.subarray(offset, offset + size - 1));
|
|
828
|
+
}
|
|
829
|
+
async function normalizeBody(body) {
|
|
830
|
+
if (body === null || body === undefined)
|
|
831
|
+
return EMPTY;
|
|
832
|
+
if (body instanceof Uint8Array)
|
|
833
|
+
return body;
|
|
834
|
+
if (typeof body === "string")
|
|
835
|
+
return encoder.encode(body);
|
|
836
|
+
if (body instanceof ArrayBuffer)
|
|
837
|
+
return new Uint8Array(body);
|
|
838
|
+
if (body instanceof Blob)
|
|
839
|
+
return new Uint8Array(await body.arrayBuffer());
|
|
840
|
+
throw new TypeError("Unsupported content type for entry body.");
|
|
841
|
+
}
|
|
842
|
+
function writeChecksum(block) {
|
|
843
|
+
block.fill(CHECKSUM_SPACE, USTAR_CHECKSUM_OFFSET, USTAR_CHECKSUM_OFFSET + USTAR_CHECKSUM_SIZE);
|
|
844
|
+
let checksum = 0;
|
|
845
|
+
for (const byte of block)
|
|
846
|
+
checksum += byte;
|
|
847
|
+
for (let i2 = USTAR_CHECKSUM_OFFSET + 6 - 1;i2 >= USTAR_CHECKSUM_OFFSET; i2--) {
|
|
848
|
+
block[i2] = (checksum & 7) + ASCII_ZERO;
|
|
849
|
+
checksum >>= 3;
|
|
850
|
+
}
|
|
851
|
+
block[USTAR_CHECKSUM_OFFSET + 6] = 0;
|
|
852
|
+
block[USTAR_CHECKSUM_OFFSET + 7] = CHECKSUM_SPACE;
|
|
853
|
+
}
|
|
854
|
+
function generatePax(header) {
|
|
855
|
+
const paxRecords = {};
|
|
856
|
+
if (header.name.length > USTAR_NAME_SIZE) {
|
|
857
|
+
if (findUstarSplit(header.name) === null)
|
|
858
|
+
paxRecords.path = header.name;
|
|
859
|
+
}
|
|
860
|
+
if (header.linkname && header.linkname.length > USTAR_NAME_SIZE)
|
|
861
|
+
paxRecords.linkpath = header.linkname;
|
|
862
|
+
if (header.uname && header.uname.length > USTAR_UNAME_SIZE)
|
|
863
|
+
paxRecords.uname = header.uname;
|
|
864
|
+
if (header.gname && header.gname.length > USTAR_GNAME_SIZE)
|
|
865
|
+
paxRecords.gname = header.gname;
|
|
866
|
+
if (header.uid != null && header.uid > USTAR_MAX_UID_GID)
|
|
867
|
+
paxRecords.uid = String(header.uid);
|
|
868
|
+
if (header.gid != null && header.gid > USTAR_MAX_UID_GID)
|
|
869
|
+
paxRecords.gid = String(header.gid);
|
|
870
|
+
if (header.size != null && header.size > USTAR_MAX_SIZE)
|
|
871
|
+
paxRecords.size = String(header.size);
|
|
872
|
+
if (header.pax)
|
|
873
|
+
Object.assign(paxRecords, header.pax);
|
|
874
|
+
const paxEntries = Object.entries(paxRecords);
|
|
875
|
+
if (paxEntries.length === 0)
|
|
876
|
+
return null;
|
|
877
|
+
const paxBody = encoder.encode(paxEntries.map(([key, value]) => {
|
|
878
|
+
const record = `${key}=${value}
|
|
879
|
+
`;
|
|
880
|
+
const partLength = encoder.encode(record).length + 1;
|
|
881
|
+
let totalLength = partLength + String(partLength).length;
|
|
882
|
+
totalLength = partLength + String(totalLength).length;
|
|
883
|
+
return `${totalLength} ${record}`;
|
|
884
|
+
}).join(""));
|
|
885
|
+
return {
|
|
886
|
+
paxHeader: createTarHeader({
|
|
887
|
+
name: decoder.decode(encoder.encode(`PaxHeader/${header.name}`).slice(0, 100)),
|
|
888
|
+
size: paxBody.length,
|
|
889
|
+
type: "pax-header",
|
|
890
|
+
mode: 420,
|
|
891
|
+
mtime: header.mtime,
|
|
892
|
+
uname: header.uname,
|
|
893
|
+
gname: header.gname,
|
|
894
|
+
uid: header.uid,
|
|
895
|
+
gid: header.gid
|
|
896
|
+
}),
|
|
897
|
+
paxBody
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
function findUstarSplit(path) {
|
|
901
|
+
if (path.length <= USTAR_NAME_SIZE)
|
|
902
|
+
return null;
|
|
903
|
+
const minSlashIndex = path.length - USTAR_NAME_SIZE - 1;
|
|
904
|
+
const slashIndex = path.lastIndexOf("/", USTAR_PREFIX_SIZE);
|
|
905
|
+
if (slashIndex > 0 && slashIndex >= minSlashIndex)
|
|
906
|
+
return {
|
|
907
|
+
prefix: path.slice(0, slashIndex),
|
|
908
|
+
name: path.slice(slashIndex + 1)
|
|
909
|
+
};
|
|
910
|
+
return null;
|
|
911
|
+
}
|
|
912
|
+
function createTarHeader(header) {
|
|
913
|
+
const view = new Uint8Array(BLOCK_SIZE);
|
|
914
|
+
const size = isBodyless(header) ? 0 : header.size ?? 0;
|
|
915
|
+
let name = header.name;
|
|
916
|
+
let prefix = "";
|
|
917
|
+
if (!header.pax?.path) {
|
|
918
|
+
const split = findUstarSplit(name);
|
|
919
|
+
if (split) {
|
|
920
|
+
name = split.name;
|
|
921
|
+
prefix = split.prefix;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
writeString(view, USTAR_NAME_OFFSET, USTAR_NAME_SIZE, name);
|
|
925
|
+
writeOctal(view, USTAR_MODE_OFFSET, USTAR_MODE_SIZE, header.mode ?? (header.type === DIRECTORY ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE));
|
|
926
|
+
writeOctal(view, USTAR_UID_OFFSET, USTAR_UID_SIZE, header.uid ?? 0);
|
|
927
|
+
writeOctal(view, USTAR_GID_OFFSET, USTAR_GID_SIZE, header.gid ?? 0);
|
|
928
|
+
writeOctal(view, USTAR_SIZE_OFFSET, USTAR_SIZE_SIZE, size);
|
|
929
|
+
writeOctal(view, USTAR_MTIME_OFFSET, USTAR_MTIME_SIZE, Math.floor((header.mtime?.getTime() ?? Date.now()) / 1000));
|
|
930
|
+
writeString(view, USTAR_TYPEFLAG_OFFSET, USTAR_TYPEFLAG_SIZE, TYPEFLAG[header.type ?? FILE]);
|
|
931
|
+
writeString(view, USTAR_LINKNAME_OFFSET, USTAR_LINKNAME_SIZE, header.linkname);
|
|
932
|
+
writeString(view, USTAR_MAGIC_OFFSET, USTAR_MAGIC_SIZE, "ustar\x00");
|
|
933
|
+
writeString(view, USTAR_VERSION_OFFSET, USTAR_VERSION_SIZE, USTAR_VERSION);
|
|
934
|
+
writeString(view, USTAR_UNAME_OFFSET, USTAR_UNAME_SIZE, header.uname);
|
|
935
|
+
writeString(view, USTAR_GNAME_OFFSET, USTAR_GNAME_SIZE, header.gname);
|
|
936
|
+
writeString(view, USTAR_PREFIX_OFFSET, USTAR_PREFIX_SIZE, prefix);
|
|
937
|
+
writeChecksum(view);
|
|
938
|
+
return view;
|
|
939
|
+
}
|
|
940
|
+
function getHeaderBlocks(header) {
|
|
941
|
+
const base = createTarHeader(header);
|
|
942
|
+
const pax = generatePax(header);
|
|
943
|
+
if (!pax)
|
|
944
|
+
return [base];
|
|
945
|
+
const paxPadding = -pax.paxBody.length & BLOCK_SIZE_MASK;
|
|
946
|
+
const paddingBlocks = paxPadding > 0 ? [ZERO_BLOCK.subarray(0, paxPadding)] : [];
|
|
947
|
+
return [
|
|
948
|
+
pax.paxHeader,
|
|
949
|
+
pax.paxBody,
|
|
950
|
+
...paddingBlocks,
|
|
951
|
+
base
|
|
952
|
+
];
|
|
953
|
+
}
|
|
954
|
+
function createTarPacker(onData, onError, onFinalize) {
|
|
955
|
+
let currentHeader = null;
|
|
956
|
+
let bytesWritten = 0;
|
|
957
|
+
let finalized = false;
|
|
958
|
+
return {
|
|
959
|
+
add(header) {
|
|
960
|
+
if (finalized) {
|
|
961
|
+
const error = /* @__PURE__ */ new Error("No new tar entries after finalize.");
|
|
962
|
+
onError(error);
|
|
963
|
+
throw error;
|
|
964
|
+
}
|
|
965
|
+
if (currentHeader !== null) {
|
|
966
|
+
const error = /* @__PURE__ */ new Error("Previous entry must be completed before adding a new one");
|
|
967
|
+
onError(error);
|
|
968
|
+
throw error;
|
|
969
|
+
}
|
|
970
|
+
try {
|
|
971
|
+
const size = isBodyless(header) ? 0 : header.size ?? 0;
|
|
972
|
+
const headerBlocks = getHeaderBlocks({
|
|
973
|
+
...header,
|
|
974
|
+
size
|
|
975
|
+
});
|
|
976
|
+
for (const block of headerBlocks)
|
|
977
|
+
onData(block);
|
|
978
|
+
currentHeader = {
|
|
979
|
+
...header,
|
|
980
|
+
size
|
|
981
|
+
};
|
|
982
|
+
bytesWritten = 0;
|
|
983
|
+
} catch (error) {
|
|
984
|
+
onError(error);
|
|
985
|
+
}
|
|
986
|
+
},
|
|
987
|
+
write(chunk) {
|
|
988
|
+
if (!currentHeader) {
|
|
989
|
+
const error = /* @__PURE__ */ new Error("No active tar entry.");
|
|
990
|
+
onError(error);
|
|
991
|
+
throw error;
|
|
992
|
+
}
|
|
993
|
+
if (finalized) {
|
|
994
|
+
const error = /* @__PURE__ */ new Error("Cannot write data after finalize.");
|
|
995
|
+
onError(error);
|
|
996
|
+
throw error;
|
|
997
|
+
}
|
|
998
|
+
const newTotal = bytesWritten + chunk.length;
|
|
999
|
+
if (newTotal > currentHeader.size) {
|
|
1000
|
+
const error = /* @__PURE__ */ new Error(`"${currentHeader.name}" exceeds given size of ${currentHeader.size} bytes.`);
|
|
1001
|
+
onError(error);
|
|
1002
|
+
throw error;
|
|
1003
|
+
}
|
|
1004
|
+
try {
|
|
1005
|
+
bytesWritten = newTotal;
|
|
1006
|
+
onData(chunk);
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
onError(error);
|
|
1009
|
+
}
|
|
1010
|
+
},
|
|
1011
|
+
endEntry() {
|
|
1012
|
+
if (!currentHeader) {
|
|
1013
|
+
const error = /* @__PURE__ */ new Error("No active entry to end.");
|
|
1014
|
+
onError(error);
|
|
1015
|
+
throw error;
|
|
1016
|
+
}
|
|
1017
|
+
if (finalized) {
|
|
1018
|
+
const error = /* @__PURE__ */ new Error("Cannot end entry after finalize.");
|
|
1019
|
+
onError(error);
|
|
1020
|
+
throw error;
|
|
1021
|
+
}
|
|
1022
|
+
try {
|
|
1023
|
+
if (bytesWritten !== currentHeader.size) {
|
|
1024
|
+
const error = /* @__PURE__ */ new Error(`Size mismatch for "${currentHeader.name}".`);
|
|
1025
|
+
onError(error);
|
|
1026
|
+
throw error;
|
|
1027
|
+
}
|
|
1028
|
+
const paddingSize = -currentHeader.size & BLOCK_SIZE_MASK;
|
|
1029
|
+
if (paddingSize > 0)
|
|
1030
|
+
onData(new Uint8Array(paddingSize));
|
|
1031
|
+
currentHeader = null;
|
|
1032
|
+
bytesWritten = 0;
|
|
1033
|
+
} catch (error) {
|
|
1034
|
+
onError(error);
|
|
1035
|
+
throw error;
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
finalize() {
|
|
1039
|
+
if (finalized) {
|
|
1040
|
+
const error = /* @__PURE__ */ new Error("Archive has already been finalized");
|
|
1041
|
+
onError(error);
|
|
1042
|
+
throw error;
|
|
1043
|
+
}
|
|
1044
|
+
if (currentHeader !== null) {
|
|
1045
|
+
const error = /* @__PURE__ */ new Error("Cannot finalize while an entry is still active");
|
|
1046
|
+
onError(error);
|
|
1047
|
+
throw error;
|
|
1048
|
+
}
|
|
1049
|
+
try {
|
|
1050
|
+
onData(EOF_BUFFER);
|
|
1051
|
+
finalized = true;
|
|
1052
|
+
if (onFinalize)
|
|
1053
|
+
onFinalize();
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
onError(error);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
function createTarPacker2() {
|
|
1061
|
+
let streamController;
|
|
1062
|
+
let packer;
|
|
1063
|
+
return {
|
|
1064
|
+
readable: new ReadableStream({ start(controller) {
|
|
1065
|
+
streamController = controller;
|
|
1066
|
+
packer = createTarPacker(controller.enqueue.bind(controller), controller.error.bind(controller), controller.close.bind(controller));
|
|
1067
|
+
} }),
|
|
1068
|
+
controller: {
|
|
1069
|
+
add(header) {
|
|
1070
|
+
const bodyless = isBodyless(header);
|
|
1071
|
+
const h2 = { ...header };
|
|
1072
|
+
if (bodyless)
|
|
1073
|
+
h2.size = 0;
|
|
1074
|
+
packer.add(h2);
|
|
1075
|
+
if (bodyless)
|
|
1076
|
+
packer.endEntry();
|
|
1077
|
+
return new WritableStream({
|
|
1078
|
+
write(chunk) {
|
|
1079
|
+
packer.write(chunk);
|
|
1080
|
+
},
|
|
1081
|
+
close() {
|
|
1082
|
+
if (!bodyless)
|
|
1083
|
+
packer.endEntry();
|
|
1084
|
+
},
|
|
1085
|
+
abort(reason) {
|
|
1086
|
+
streamController.error(reason);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
},
|
|
1090
|
+
finalize() {
|
|
1091
|
+
packer.finalize();
|
|
1092
|
+
},
|
|
1093
|
+
error(err) {
|
|
1094
|
+
streamController.error(err);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
async function streamToBuffer(stream) {
|
|
1100
|
+
const chunks = [];
|
|
1101
|
+
const reader = stream.getReader();
|
|
1102
|
+
let totalLength = 0;
|
|
1103
|
+
try {
|
|
1104
|
+
while (true) {
|
|
1105
|
+
const { done, value } = await reader.read();
|
|
1106
|
+
if (done)
|
|
1107
|
+
break;
|
|
1108
|
+
chunks.push(value);
|
|
1109
|
+
totalLength += value.length;
|
|
1110
|
+
}
|
|
1111
|
+
const result = new Uint8Array(totalLength);
|
|
1112
|
+
let offset = 0;
|
|
1113
|
+
for (const chunk of chunks) {
|
|
1114
|
+
result.set(chunk, offset);
|
|
1115
|
+
offset += chunk.length;
|
|
1116
|
+
}
|
|
1117
|
+
return result;
|
|
1118
|
+
} finally {
|
|
1119
|
+
reader.releaseLock();
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
async function packTar(entries) {
|
|
1123
|
+
const { readable, controller } = createTarPacker2();
|
|
1124
|
+
await (async () => {
|
|
1125
|
+
for (const entry of entries) {
|
|
1126
|
+
const entryStream = controller.add(entry.header);
|
|
1127
|
+
const body = "body" in entry ? entry.body : entry.data;
|
|
1128
|
+
if (!body) {
|
|
1129
|
+
await entryStream.close();
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
if (body instanceof ReadableStream)
|
|
1133
|
+
await body.pipeTo(entryStream);
|
|
1134
|
+
else if (body instanceof Blob)
|
|
1135
|
+
await body.stream().pipeTo(entryStream);
|
|
1136
|
+
else
|
|
1137
|
+
try {
|
|
1138
|
+
const chunk = await normalizeBody(body);
|
|
1139
|
+
if (chunk.length > 0) {
|
|
1140
|
+
const writer = entryStream.getWriter();
|
|
1141
|
+
await writer.write(chunk);
|
|
1142
|
+
await writer.close();
|
|
1143
|
+
} else
|
|
1144
|
+
await entryStream.close();
|
|
1145
|
+
} catch {
|
|
1146
|
+
throw new TypeError(`Unsupported content type for entry "${entry.header.name}".`);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
})().then(() => controller.finalize()).catch((err) => controller.error(err));
|
|
1150
|
+
return new Uint8Array(await streamToBuffer(readable));
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
class RXAImpl {
|
|
1154
|
+
_buffer;
|
|
1155
|
+
constructor(buffer) {
|
|
1156
|
+
this._buffer = buffer;
|
|
1157
|
+
}
|
|
1158
|
+
get stream() {
|
|
1159
|
+
const buffer = this._buffer;
|
|
1160
|
+
return new ReadableStream({
|
|
1161
|
+
start(controller) {
|
|
1162
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
1163
|
+
controller.close();
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
async buffer() {
|
|
1168
|
+
return this._buffer;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
async function archive(files) {
|
|
1172
|
+
const entries = Object.entries(files).map(([name, content]) => {
|
|
1173
|
+
return {
|
|
1174
|
+
header: { name, size: content.length, type: "file" },
|
|
1175
|
+
body: new Uint8Array(content)
|
|
1176
|
+
};
|
|
1177
|
+
});
|
|
1178
|
+
const tarBuffer = await packTar(entries);
|
|
1179
|
+
const gzipBuffer = await gzipAsync(Buffer.from(tarBuffer));
|
|
1180
|
+
return new RXAImpl(gzipBuffer);
|
|
1181
|
+
}
|
|
1182
|
+
function locate(rxm) {
|
|
1183
|
+
return {
|
|
1184
|
+
registry: rxm.registry,
|
|
1185
|
+
path: rxm.path,
|
|
1186
|
+
name: rxm.name,
|
|
1187
|
+
tag: rxm.tag
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
function resource(rxm, rxa) {
|
|
1191
|
+
const rxl = locate(rxm);
|
|
1192
|
+
return {
|
|
1193
|
+
locator: rxl,
|
|
1194
|
+
manifest: rxm,
|
|
1195
|
+
archive: rxa
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
class TypeHandlerChain {
|
|
1200
|
+
handlers = new Map;
|
|
1201
|
+
constructor() {
|
|
1202
|
+
for (const type of builtinTypes) {
|
|
1203
|
+
this.registerInternal(type);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
static create() {
|
|
1207
|
+
return new TypeHandlerChain;
|
|
1208
|
+
}
|
|
1209
|
+
registerInternal(type) {
|
|
1210
|
+
this.handlers.set(type.name, type);
|
|
1211
|
+
if (type.aliases) {
|
|
1212
|
+
for (const alias of type.aliases) {
|
|
1213
|
+
this.handlers.set(alias, type);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
register(type) {
|
|
1218
|
+
if (this.handlers.has(type.name)) {
|
|
1219
|
+
throw new ResourceTypeError(`Type '${type.name}' is already registered`);
|
|
1220
|
+
}
|
|
1221
|
+
this.handlers.set(type.name, type);
|
|
1222
|
+
if (type.aliases) {
|
|
1223
|
+
for (const alias of type.aliases) {
|
|
1224
|
+
if (this.handlers.has(alias)) {
|
|
1225
|
+
throw new ResourceTypeError(`Alias '${alias}' conflicts with existing type or alias`);
|
|
1226
|
+
}
|
|
1227
|
+
this.handlers.set(alias, type);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
canHandle(typeName) {
|
|
1232
|
+
return this.handlers.has(typeName);
|
|
1233
|
+
}
|
|
1234
|
+
getHandler(typeName) {
|
|
1235
|
+
const handler = this.handlers.get(typeName);
|
|
1236
|
+
if (!handler) {
|
|
1237
|
+
throw new ResourceTypeError(`Unsupported resource type: ${typeName}`);
|
|
1238
|
+
}
|
|
1239
|
+
return handler;
|
|
1240
|
+
}
|
|
1241
|
+
getHandlerOrUndefined(typeName) {
|
|
1242
|
+
return this.handlers.get(typeName);
|
|
1243
|
+
}
|
|
1244
|
+
getSupportedTypes() {
|
|
1245
|
+
return Array.from(this.handlers.keys());
|
|
1246
|
+
}
|
|
1247
|
+
clear() {
|
|
1248
|
+
this.handlers.clear();
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
class FolderLoader {
|
|
1253
|
+
async canLoad(source) {
|
|
1254
|
+
try {
|
|
1255
|
+
const stats = await stat(source);
|
|
1256
|
+
if (!stats.isDirectory()) {
|
|
1257
|
+
return false;
|
|
1258
|
+
}
|
|
1259
|
+
const manifestPath = join(source, "resource.json");
|
|
1260
|
+
const manifestStats = await stat(manifestPath);
|
|
1261
|
+
return manifestStats.isFile();
|
|
1262
|
+
} catch {
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
async load(folderPath) {
|
|
1267
|
+
const resourceJsonPath = join(folderPath, "resource.json");
|
|
1268
|
+
let resourceJson;
|
|
1269
|
+
try {
|
|
1270
|
+
resourceJson = await readFile2(resourceJsonPath, "utf-8");
|
|
1271
|
+
} catch (error) {
|
|
1272
|
+
throw new ResourceXError(`Failed to read resource.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
1273
|
+
}
|
|
1274
|
+
let json;
|
|
1275
|
+
try {
|
|
1276
|
+
json = JSON.parse(resourceJson);
|
|
1277
|
+
} catch (error) {
|
|
1278
|
+
throw new ResourceXError(`Invalid JSON in resource.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
1279
|
+
}
|
|
1280
|
+
const rxd = define(json);
|
|
1281
|
+
const files = await this.readFolderFiles(folderPath);
|
|
1282
|
+
if (Object.keys(files).length === 0) {
|
|
1283
|
+
throw new ResourceXError("No content files found in resource folder");
|
|
1284
|
+
}
|
|
1285
|
+
const rxm = manifest(rxd);
|
|
1286
|
+
const rxa = await archive(files);
|
|
1287
|
+
return resource(rxm, rxa);
|
|
1288
|
+
}
|
|
1289
|
+
async readFolderFiles(folderPath, basePath = folderPath) {
|
|
1290
|
+
const files = {};
|
|
1291
|
+
const entries = await readdir(folderPath, { withFileTypes: true });
|
|
1292
|
+
for (const entry of entries) {
|
|
1293
|
+
const fullPath = join(folderPath, entry.name);
|
|
1294
|
+
const relativePath = relative(basePath, fullPath);
|
|
1295
|
+
if (relativePath === "resource.json") {
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
if (entry.isFile()) {
|
|
1299
|
+
files[relativePath] = await readFile2(fullPath);
|
|
1300
|
+
} else if (entry.isDirectory()) {
|
|
1301
|
+
const subFiles = await this.readFolderFiles(fullPath, basePath);
|
|
1302
|
+
Object.assign(files, subFiles);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
return files;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
function computeDigest(data) {
|
|
1309
|
+
const hash = createHash("sha256").update(data).digest("hex");
|
|
1310
|
+
return `sha256:${hash}`;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
class MemoryRXAStore {
|
|
1314
|
+
blobs = new Map;
|
|
1315
|
+
async get(digest) {
|
|
1316
|
+
const blob = this.blobs.get(digest);
|
|
1317
|
+
if (!blob) {
|
|
1318
|
+
throw new RegistryError(`Blob not found: ${digest}`);
|
|
1319
|
+
}
|
|
1320
|
+
return blob;
|
|
1321
|
+
}
|
|
1322
|
+
async put(data) {
|
|
1323
|
+
const digest = computeDigest(data);
|
|
1324
|
+
if (!this.blobs.has(digest)) {
|
|
1325
|
+
this.blobs.set(digest, data);
|
|
1326
|
+
}
|
|
1327
|
+
return digest;
|
|
1328
|
+
}
|
|
1329
|
+
async has(digest) {
|
|
1330
|
+
return this.blobs.has(digest);
|
|
1331
|
+
}
|
|
1332
|
+
async delete(digest) {
|
|
1333
|
+
this.blobs.delete(digest);
|
|
1334
|
+
}
|
|
1335
|
+
async list() {
|
|
1336
|
+
return Array.from(this.blobs.keys());
|
|
1337
|
+
}
|
|
1338
|
+
clear() {
|
|
1339
|
+
this.blobs.clear();
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
class MemoryRXMStore {
|
|
1344
|
+
manifests = new Map;
|
|
1345
|
+
buildKey(name, tag, registry) {
|
|
1346
|
+
return registry ? `${registry}/${name}:${tag}` : `${name}:${tag}`;
|
|
1347
|
+
}
|
|
1348
|
+
async get(name, tag, registry) {
|
|
1349
|
+
const key = this.buildKey(name, tag, registry);
|
|
1350
|
+
return this.manifests.get(key) ?? null;
|
|
1351
|
+
}
|
|
1352
|
+
async put(manifest2) {
|
|
1353
|
+
const key = this.buildKey(manifest2.name, manifest2.tag, manifest2.registry);
|
|
1354
|
+
this.manifests.set(key, {
|
|
1355
|
+
...manifest2,
|
|
1356
|
+
updatedAt: new Date
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
async has(name, tag, registry) {
|
|
1360
|
+
const key = this.buildKey(name, tag, registry);
|
|
1361
|
+
return this.manifests.has(key);
|
|
1362
|
+
}
|
|
1363
|
+
async delete(name, tag, registry) {
|
|
1364
|
+
const key = this.buildKey(name, tag, registry);
|
|
1365
|
+
this.manifests.delete(key);
|
|
1366
|
+
}
|
|
1367
|
+
async listTags(name, registry) {
|
|
1368
|
+
const tags = [];
|
|
1369
|
+
for (const m2 of this.manifests.values()) {
|
|
1370
|
+
if (m2.name === name && m2.registry === registry) {
|
|
1371
|
+
tags.push(m2.tag);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return tags;
|
|
1375
|
+
}
|
|
1376
|
+
async listNames(registry, query) {
|
|
1377
|
+
const names = new Set;
|
|
1378
|
+
for (const m2 of this.manifests.values()) {
|
|
1379
|
+
if (registry !== undefined && m2.registry !== registry)
|
|
1380
|
+
continue;
|
|
1381
|
+
if (query && !m2.name.toLowerCase().includes(query.toLowerCase()))
|
|
1382
|
+
continue;
|
|
1383
|
+
names.add(m2.name);
|
|
1384
|
+
}
|
|
1385
|
+
return Array.from(names);
|
|
1386
|
+
}
|
|
1387
|
+
async search(options) {
|
|
1388
|
+
const { registry, query, limit, offset = 0 } = options ?? {};
|
|
1389
|
+
let results = Array.from(this.manifests.values());
|
|
1390
|
+
if (registry !== undefined) {
|
|
1391
|
+
if (registry === null) {
|
|
1392
|
+
results = results.filter((m2) => !m2.registry);
|
|
1393
|
+
} else {
|
|
1394
|
+
results = results.filter((m2) => m2.registry === registry);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
if (query) {
|
|
1398
|
+
const lowerQuery = query.toLowerCase();
|
|
1399
|
+
results = results.filter((m2) => m2.name.toLowerCase().includes(lowerQuery));
|
|
1400
|
+
}
|
|
1401
|
+
results = results.slice(offset);
|
|
1402
|
+
if (limit !== undefined) {
|
|
1403
|
+
results = results.slice(0, limit);
|
|
1404
|
+
}
|
|
1405
|
+
return results;
|
|
1406
|
+
}
|
|
1407
|
+
async deleteByRegistry(registry) {
|
|
1408
|
+
for (const [key, m2] of this.manifests.entries()) {
|
|
1409
|
+
if (m2.registry === registry) {
|
|
1410
|
+
this.manifests.delete(key);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
clear() {
|
|
1415
|
+
this.manifests.clear();
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
var ResourceXError, DefinitionError, BLOCK_SIZE = 512, BLOCK_SIZE_MASK = 511, DEFAULT_FILE_MODE = 420, DEFAULT_DIR_MODE = 493, USTAR_NAME_OFFSET = 0, USTAR_NAME_SIZE = 100, USTAR_MODE_OFFSET = 100, USTAR_MODE_SIZE = 8, USTAR_UID_OFFSET = 108, USTAR_UID_SIZE = 8, USTAR_GID_OFFSET = 116, USTAR_GID_SIZE = 8, USTAR_SIZE_OFFSET = 124, USTAR_SIZE_SIZE = 12, USTAR_MTIME_OFFSET = 136, USTAR_MTIME_SIZE = 12, USTAR_CHECKSUM_OFFSET = 148, USTAR_CHECKSUM_SIZE = 8, USTAR_TYPEFLAG_OFFSET = 156, USTAR_TYPEFLAG_SIZE = 1, USTAR_LINKNAME_OFFSET = 157, USTAR_LINKNAME_SIZE = 100, USTAR_MAGIC_OFFSET = 257, USTAR_MAGIC_SIZE = 6, USTAR_VERSION_OFFSET = 263, USTAR_VERSION_SIZE = 2, USTAR_UNAME_OFFSET = 265, USTAR_UNAME_SIZE = 32, USTAR_GNAME_OFFSET = 297, USTAR_GNAME_SIZE = 32, USTAR_PREFIX_OFFSET = 345, USTAR_PREFIX_SIZE = 155, USTAR_VERSION = "00", USTAR_MAX_UID_GID = 2097151, USTAR_MAX_SIZE = 8589934591, FILE = "file", LINK = "link", SYMLINK = "symlink", DIRECTORY = "directory", TYPEFLAG, ZERO_BLOCK, EMPTY, encoder, decoder, isBodyless = (header) => header.type === DIRECTORY || header.type === SYMLINK || header.type === LINK, CHECKSUM_SPACE = 32, ASCII_ZERO = 48, EOF_BUFFER, gzipAsync, gunzipAsync, ResourceTypeError, textType, jsonType, binaryType, builtinTypes, RegistryError;
|
|
1419
|
+
var init_dist = __esm(() => {
|
|
1420
|
+
ResourceXError = class ResourceXError extends Error {
|
|
1421
|
+
constructor(message, options) {
|
|
1422
|
+
super(message, options);
|
|
1423
|
+
this.name = "ResourceXError";
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
DefinitionError = class DefinitionError extends ResourceXError {
|
|
1427
|
+
constructor(message) {
|
|
1428
|
+
super(message);
|
|
1429
|
+
this.name = "DefinitionError";
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
TYPEFLAG = {
|
|
1433
|
+
file: "0",
|
|
1434
|
+
link: "1",
|
|
1435
|
+
symlink: "2",
|
|
1436
|
+
"character-device": "3",
|
|
1437
|
+
"block-device": "4",
|
|
1438
|
+
directory: "5",
|
|
1439
|
+
fifo: "6",
|
|
1440
|
+
"pax-header": "x",
|
|
1441
|
+
"pax-global-header": "g",
|
|
1442
|
+
"gnu-long-name": "L",
|
|
1443
|
+
"gnu-long-link-name": "K"
|
|
1444
|
+
};
|
|
1445
|
+
ZERO_BLOCK = new Uint8Array(BLOCK_SIZE);
|
|
1446
|
+
EMPTY = new Uint8Array(0);
|
|
1447
|
+
encoder = new TextEncoder;
|
|
1448
|
+
decoder = new TextDecoder;
|
|
1449
|
+
EOF_BUFFER = new Uint8Array(BLOCK_SIZE * 2);
|
|
1450
|
+
gzipAsync = promisify(gzip);
|
|
1451
|
+
gunzipAsync = promisify2(gunzip);
|
|
1452
|
+
ResourceTypeError = class ResourceTypeError extends ResourceXError {
|
|
1453
|
+
constructor(message) {
|
|
1454
|
+
super(message);
|
|
1455
|
+
this.name = "ResourceTypeError";
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
textType = {
|
|
1459
|
+
name: "text",
|
|
1460
|
+
aliases: ["txt", "plaintext"],
|
|
1461
|
+
description: "Plain text content",
|
|
1462
|
+
code: `// @resolver: text_type_default
|
|
1463
|
+
// src/builtins/text.type.ts
|
|
1464
|
+
var text_type_default = {
|
|
1465
|
+
name: "text",
|
|
1466
|
+
aliases: ["txt", "plaintext"],
|
|
1467
|
+
description: "Plain text content",
|
|
1468
|
+
async resolve(ctx) {
|
|
1469
|
+
const content = ctx.files["content"];
|
|
1470
|
+
return new TextDecoder().decode(content);
|
|
1471
|
+
}
|
|
1472
|
+
};`
|
|
1473
|
+
};
|
|
1474
|
+
jsonType = {
|
|
1475
|
+
name: "json",
|
|
1476
|
+
aliases: ["config", "manifest"],
|
|
1477
|
+
description: "JSON content",
|
|
1478
|
+
code: `// @resolver: json_type_default
|
|
1479
|
+
// src/builtins/json.type.ts
|
|
1480
|
+
var json_type_default = {
|
|
1481
|
+
name: "json",
|
|
1482
|
+
aliases: ["config", "manifest"],
|
|
1483
|
+
description: "JSON content",
|
|
1484
|
+
async resolve(ctx) {
|
|
1485
|
+
const content = ctx.files["content"];
|
|
1486
|
+
return JSON.parse(new TextDecoder().decode(content));
|
|
1487
|
+
}
|
|
1488
|
+
};`
|
|
1489
|
+
};
|
|
1490
|
+
binaryType = {
|
|
1491
|
+
name: "binary",
|
|
1492
|
+
aliases: ["bin", "blob", "raw"],
|
|
1493
|
+
description: "Binary content",
|
|
1494
|
+
code: `// @resolver: binary_type_default
|
|
1495
|
+
// src/builtins/binary.type.ts
|
|
1496
|
+
var binary_type_default = {
|
|
1497
|
+
name: "binary",
|
|
1498
|
+
aliases: ["bin", "blob", "raw"],
|
|
1499
|
+
description: "Binary content",
|
|
1500
|
+
async resolve(ctx) {
|
|
1501
|
+
return ctx.files["content"];
|
|
1502
|
+
}
|
|
1503
|
+
};`
|
|
1504
|
+
};
|
|
1505
|
+
builtinTypes = [textType, jsonType, binaryType];
|
|
1506
|
+
RegistryError = class RegistryError extends ResourceXError {
|
|
1507
|
+
constructor(message, options) {
|
|
1508
|
+
super(message, options);
|
|
1509
|
+
this.name = "RegistryError";
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
// ../../packages/node-provider/dist/index.js
|
|
773
1515
|
var exports_dist = {};
|
|
774
1516
|
__export(exports_dist, {
|
|
1517
|
+
NodeProvider: () => NodeProvider,
|
|
1518
|
+
FileSystemRXMStore: () => FileSystemRXMStore,
|
|
1519
|
+
FileSystemRXAStore: () => FileSystemRXAStore
|
|
1520
|
+
});
|
|
1521
|
+
import { homedir } from "os";
|
|
1522
|
+
import { join as join3 } from "path";
|
|
1523
|
+
import { mkdir, readFile, writeFile, unlink, readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
1524
|
+
import { join as join2 } from "path";
|
|
1525
|
+
import { mkdir as mkdir2, readFile as readFile22, writeFile as writeFile2, unlink as unlink2, readdir as readdir22, stat as stat22, rm } from "fs/promises";
|
|
1526
|
+
import { join as join22 } from "path";
|
|
1527
|
+
|
|
1528
|
+
class FileSystemRXAStore {
|
|
1529
|
+
basePath;
|
|
1530
|
+
constructor(basePath) {
|
|
1531
|
+
this.basePath = basePath;
|
|
1532
|
+
}
|
|
1533
|
+
getPath(digest) {
|
|
1534
|
+
const prefix = digest.substring(7, 9);
|
|
1535
|
+
return join2(this.basePath, prefix, digest);
|
|
1536
|
+
}
|
|
1537
|
+
async get(digest) {
|
|
1538
|
+
const path = this.getPath(digest);
|
|
1539
|
+
try {
|
|
1540
|
+
return await readFile(path);
|
|
1541
|
+
} catch (error) {
|
|
1542
|
+
throw new RegistryError(`Blob not found: ${digest}`);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
async put(data) {
|
|
1546
|
+
const digest = computeDigest(data);
|
|
1547
|
+
const path = this.getPath(digest);
|
|
1548
|
+
if (await this.has(digest)) {
|
|
1549
|
+
return digest;
|
|
1550
|
+
}
|
|
1551
|
+
const dir = join2(path, "..");
|
|
1552
|
+
await mkdir(dir, { recursive: true });
|
|
1553
|
+
await writeFile(path, data);
|
|
1554
|
+
return digest;
|
|
1555
|
+
}
|
|
1556
|
+
async has(digest) {
|
|
1557
|
+
const path = this.getPath(digest);
|
|
1558
|
+
try {
|
|
1559
|
+
await stat2(path);
|
|
1560
|
+
return true;
|
|
1561
|
+
} catch {
|
|
1562
|
+
return false;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
async delete(digest) {
|
|
1566
|
+
const path = this.getPath(digest);
|
|
1567
|
+
try {
|
|
1568
|
+
await unlink(path);
|
|
1569
|
+
} catch {}
|
|
1570
|
+
}
|
|
1571
|
+
async list() {
|
|
1572
|
+
const digests = [];
|
|
1573
|
+
try {
|
|
1574
|
+
const prefixes = await readdir2(this.basePath);
|
|
1575
|
+
for (const prefix of prefixes) {
|
|
1576
|
+
const prefixPath = join2(this.basePath, prefix);
|
|
1577
|
+
try {
|
|
1578
|
+
const files = await readdir2(prefixPath);
|
|
1579
|
+
for (const file of files) {
|
|
1580
|
+
if (file.startsWith("sha256:")) {
|
|
1581
|
+
digests.push(file);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
} catch {}
|
|
1585
|
+
}
|
|
1586
|
+
} catch {}
|
|
1587
|
+
return digests;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
class FileSystemRXMStore {
|
|
1592
|
+
basePath;
|
|
1593
|
+
constructor(basePath) {
|
|
1594
|
+
this.basePath = basePath;
|
|
1595
|
+
}
|
|
1596
|
+
getDir(name, registry) {
|
|
1597
|
+
const registryDir = registry ?? LOCAL_DIR;
|
|
1598
|
+
return join22(this.basePath, registryDir, name);
|
|
1599
|
+
}
|
|
1600
|
+
getPath(name, tag, registry) {
|
|
1601
|
+
return join22(this.getDir(name, registry), `${tag}.json`);
|
|
1602
|
+
}
|
|
1603
|
+
async get(name, tag, registry) {
|
|
1604
|
+
const path = this.getPath(name, tag, registry);
|
|
1605
|
+
try {
|
|
1606
|
+
const data = await readFile22(path, "utf-8");
|
|
1607
|
+
return JSON.parse(data);
|
|
1608
|
+
} catch {
|
|
1609
|
+
return null;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
async put(manifest2) {
|
|
1613
|
+
const path = this.getPath(manifest2.name, manifest2.tag, manifest2.registry);
|
|
1614
|
+
const dir = join22(path, "..");
|
|
1615
|
+
await mkdir2(dir, { recursive: true });
|
|
1616
|
+
await writeFile2(path, JSON.stringify(manifest2, null, 2), "utf-8");
|
|
1617
|
+
}
|
|
1618
|
+
async has(name, tag, registry) {
|
|
1619
|
+
const path = this.getPath(name, tag, registry);
|
|
1620
|
+
try {
|
|
1621
|
+
await stat22(path);
|
|
1622
|
+
return true;
|
|
1623
|
+
} catch {
|
|
1624
|
+
return false;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
async delete(name, tag, registry) {
|
|
1628
|
+
const path = this.getPath(name, tag, registry);
|
|
1629
|
+
try {
|
|
1630
|
+
await unlink2(path);
|
|
1631
|
+
} catch {}
|
|
1632
|
+
}
|
|
1633
|
+
async listTags(name, registry) {
|
|
1634
|
+
const dir = this.getDir(name, registry);
|
|
1635
|
+
const tags = [];
|
|
1636
|
+
try {
|
|
1637
|
+
const files = await readdir22(dir);
|
|
1638
|
+
for (const file of files) {
|
|
1639
|
+
if (file.endsWith(".json")) {
|
|
1640
|
+
tags.push(file.replace(".json", ""));
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
} catch {}
|
|
1644
|
+
return tags;
|
|
1645
|
+
}
|
|
1646
|
+
async listNames(registry, query) {
|
|
1647
|
+
const registryDir = registry ?? LOCAL_DIR;
|
|
1648
|
+
const basePath = join22(this.basePath, registryDir);
|
|
1649
|
+
const names = [];
|
|
1650
|
+
try {
|
|
1651
|
+
const entries = await readdir22(basePath);
|
|
1652
|
+
for (const entry of entries) {
|
|
1653
|
+
const entryPath = join22(basePath, entry);
|
|
1654
|
+
try {
|
|
1655
|
+
const entryStat = await stat22(entryPath);
|
|
1656
|
+
if (entryStat.isDirectory()) {
|
|
1657
|
+
if (!query || entry.toLowerCase().includes(query.toLowerCase())) {
|
|
1658
|
+
names.push(entry);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
} catch {}
|
|
1662
|
+
}
|
|
1663
|
+
} catch {}
|
|
1664
|
+
return names;
|
|
1665
|
+
}
|
|
1666
|
+
async search(options) {
|
|
1667
|
+
const { registry, query, limit, offset = 0 } = options ?? {};
|
|
1668
|
+
const results = [];
|
|
1669
|
+
let registryDirs = [];
|
|
1670
|
+
if (registry === null) {
|
|
1671
|
+
registryDirs = [LOCAL_DIR];
|
|
1672
|
+
} else if (registry !== undefined) {
|
|
1673
|
+
registryDirs = [registry];
|
|
1674
|
+
} else {
|
|
1675
|
+
try {
|
|
1676
|
+
registryDirs = await readdir22(this.basePath);
|
|
1677
|
+
} catch {
|
|
1678
|
+
return [];
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
for (const regDir of registryDirs) {
|
|
1682
|
+
const regPath = join22(this.basePath, regDir);
|
|
1683
|
+
try {
|
|
1684
|
+
const names = await readdir22(regPath);
|
|
1685
|
+
for (const name of names) {
|
|
1686
|
+
if (query && !name.toLowerCase().includes(query.toLowerCase())) {
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
const namePath = join22(regPath, name);
|
|
1690
|
+
try {
|
|
1691
|
+
const files = await readdir22(namePath);
|
|
1692
|
+
for (const file of files) {
|
|
1693
|
+
if (file.endsWith(".json")) {
|
|
1694
|
+
const filePath = join22(namePath, file);
|
|
1695
|
+
const data = await readFile22(filePath, "utf-8");
|
|
1696
|
+
const manifest2 = JSON.parse(data);
|
|
1697
|
+
results.push(manifest2);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
} catch {}
|
|
1701
|
+
}
|
|
1702
|
+
} catch {}
|
|
1703
|
+
}
|
|
1704
|
+
let paginated = results.slice(offset);
|
|
1705
|
+
if (limit !== undefined) {
|
|
1706
|
+
paginated = paginated.slice(0, limit);
|
|
1707
|
+
}
|
|
1708
|
+
return paginated;
|
|
1709
|
+
}
|
|
1710
|
+
async deleteByRegistry(registry) {
|
|
1711
|
+
const regPath = join22(this.basePath, registry);
|
|
1712
|
+
try {
|
|
1713
|
+
await rm(regPath, { recursive: true });
|
|
1714
|
+
} catch {}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
class NodeProvider {
|
|
1719
|
+
platform = "node";
|
|
1720
|
+
createStores(config) {
|
|
1721
|
+
const basePath = config.path ?? DEFAULT_BASE_PATH;
|
|
1722
|
+
return {
|
|
1723
|
+
rxaStore: new FileSystemRXAStore(join3(basePath, "blobs")),
|
|
1724
|
+
rxmStore: new FileSystemRXMStore(join3(basePath, "manifests"))
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
createLoader(_config) {
|
|
1728
|
+
return new FolderLoader;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
var LOCAL_DIR = "_local", DEFAULT_BASE_PATH;
|
|
1732
|
+
var init_dist2 = __esm(() => {
|
|
1733
|
+
init_dist();
|
|
1734
|
+
init_dist();
|
|
1735
|
+
DEFAULT_BASE_PATH = `${homedir()}/.resourcex`;
|
|
1736
|
+
});
|
|
1737
|
+
|
|
1738
|
+
// ../../node_modules/.bun/@hono+node-server@1.19.9+115df24086ffac64/node_modules/@hono/node-server/dist/index.mjs
|
|
1739
|
+
var exports_dist2 = {};
|
|
1740
|
+
__export(exports_dist2, {
|
|
775
1741
|
serve: () => serve,
|
|
776
1742
|
getRequestListener: () => getRequestListener,
|
|
777
1743
|
createAdaptorServer: () => createAdaptorServer,
|
|
@@ -1151,7 +2117,7 @@ var RequestError, toRequestError = (e2) => {
|
|
|
1151
2117
|
});
|
|
1152
2118
|
return server;
|
|
1153
2119
|
};
|
|
1154
|
-
var
|
|
2120
|
+
var init_dist3 = __esm(() => {
|
|
1155
2121
|
RequestError = class extends Error {
|
|
1156
2122
|
constructor(message, options) {
|
|
1157
2123
|
super(message, options);
|
|
@@ -2697,18 +3663,19 @@ async function runMain(cmd, opts = {}) {
|
|
|
2697
3663
|
}
|
|
2698
3664
|
|
|
2699
3665
|
// src/lib/client.ts
|
|
2700
|
-
|
|
3666
|
+
init_dist2();
|
|
3667
|
+
import { createResourceX, setProvider } from "resourcexjs";
|
|
2701
3668
|
|
|
2702
3669
|
// src/lib/paths.ts
|
|
2703
|
-
import { homedir } from "os";
|
|
2704
|
-
import { join } from "path";
|
|
2705
|
-
var RX_HOME = process.env.RX_HOME ||
|
|
3670
|
+
import { homedir as homedir2 } from "os";
|
|
3671
|
+
import { join as join4 } from "path";
|
|
3672
|
+
var RX_HOME = process.env.RX_HOME || join4(homedir2(), ".resourcex");
|
|
2706
3673
|
var PATHS = {
|
|
2707
3674
|
root: RX_HOME,
|
|
2708
|
-
config:
|
|
2709
|
-
local:
|
|
2710
|
-
cache:
|
|
2711
|
-
linked:
|
|
3675
|
+
config: join4(RX_HOME, "config.json"),
|
|
3676
|
+
local: join4(RX_HOME, "local"),
|
|
3677
|
+
cache: join4(RX_HOME, "cache"),
|
|
3678
|
+
linked: join4(RX_HOME, "linked")
|
|
2712
3679
|
};
|
|
2713
3680
|
|
|
2714
3681
|
// src/lib/config.ts
|
|
@@ -2735,6 +3702,7 @@ async function setConfig(key, value) {
|
|
|
2735
3702
|
}
|
|
2736
3703
|
|
|
2737
3704
|
// src/lib/client.ts
|
|
3705
|
+
setProvider(new NodeProvider);
|
|
2738
3706
|
async function getClient(options) {
|
|
2739
3707
|
const cfg = await getConfig();
|
|
2740
3708
|
return createResourceX({
|
|
@@ -2759,15 +3727,15 @@ var add = defineCommand({
|
|
|
2759
3727
|
async run({ args }) {
|
|
2760
3728
|
try {
|
|
2761
3729
|
const rx = await getClient();
|
|
2762
|
-
const
|
|
3730
|
+
const resource2 = await rx.add(args.path);
|
|
2763
3731
|
consola.success(`Added resource:
|
|
2764
3732
|
`);
|
|
2765
|
-
console.log(` Locator: ${
|
|
2766
|
-
console.log(` Name: ${
|
|
2767
|
-
console.log(` Type: ${
|
|
2768
|
-
console.log(` Tag: ${
|
|
2769
|
-
if (
|
|
2770
|
-
console.log(` Files: ${
|
|
3733
|
+
console.log(` Locator: ${resource2.locator}`);
|
|
3734
|
+
console.log(` Name: ${resource2.name}`);
|
|
3735
|
+
console.log(` Type: ${resource2.type}`);
|
|
3736
|
+
console.log(` Tag: ${resource2.tag}`);
|
|
3737
|
+
if (resource2.files?.length) {
|
|
3738
|
+
console.log(` Files: ${resource2.files.join(", ")}`);
|
|
2771
3739
|
}
|
|
2772
3740
|
} catch (error) {
|
|
2773
3741
|
consola.error(error instanceof Error ? error.message : "Failed to add resource");
|
|
@@ -2776,56 +3744,6 @@ var add = defineCommand({
|
|
|
2776
3744
|
}
|
|
2777
3745
|
});
|
|
2778
3746
|
|
|
2779
|
-
// src/commands/link.ts
|
|
2780
|
-
var link = defineCommand({
|
|
2781
|
-
meta: {
|
|
2782
|
-
name: "link",
|
|
2783
|
-
description: "Link resource directory for development"
|
|
2784
|
-
},
|
|
2785
|
-
args: {
|
|
2786
|
-
path: {
|
|
2787
|
-
type: "positional",
|
|
2788
|
-
description: "Path to resource directory",
|
|
2789
|
-
required: true
|
|
2790
|
-
}
|
|
2791
|
-
},
|
|
2792
|
-
async run({ args }) {
|
|
2793
|
-
try {
|
|
2794
|
-
const rx = await getClient();
|
|
2795
|
-
await rx.link(args.path);
|
|
2796
|
-
consola.success(`Linked: ${args.path}`);
|
|
2797
|
-
} catch (error) {
|
|
2798
|
-
consola.error(error instanceof Error ? error.message : "Failed to link resource");
|
|
2799
|
-
process.exit(1);
|
|
2800
|
-
}
|
|
2801
|
-
}
|
|
2802
|
-
});
|
|
2803
|
-
|
|
2804
|
-
// src/commands/unlink.ts
|
|
2805
|
-
var unlink = defineCommand({
|
|
2806
|
-
meta: {
|
|
2807
|
-
name: "unlink",
|
|
2808
|
-
description: "Unlink development directory"
|
|
2809
|
-
},
|
|
2810
|
-
args: {
|
|
2811
|
-
locator: {
|
|
2812
|
-
type: "positional",
|
|
2813
|
-
description: "Resource locator (e.g., hello:1.0.0)",
|
|
2814
|
-
required: true
|
|
2815
|
-
}
|
|
2816
|
-
},
|
|
2817
|
-
async run({ args }) {
|
|
2818
|
-
try {
|
|
2819
|
-
const rx = await getClient();
|
|
2820
|
-
await rx.unlink(args.locator);
|
|
2821
|
-
consola.success(`Unlinked: ${args.locator}`);
|
|
2822
|
-
} catch (error) {
|
|
2823
|
-
consola.error(error instanceof Error ? error.message : "Failed to unlink resource");
|
|
2824
|
-
process.exit(1);
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
});
|
|
2828
|
-
|
|
2829
3747
|
// src/commands/list.ts
|
|
2830
3748
|
var list = defineCommand({
|
|
2831
3749
|
meta: {
|
|
@@ -2875,25 +3793,25 @@ var info = defineCommand({
|
|
|
2875
3793
|
async run({ args }) {
|
|
2876
3794
|
try {
|
|
2877
3795
|
const rx = await getClient();
|
|
2878
|
-
const
|
|
3796
|
+
const resource2 = await rx.info(args.locator);
|
|
2879
3797
|
console.log();
|
|
2880
|
-
console.log(` ${
|
|
3798
|
+
console.log(` ${resource2.name}:${resource2.tag}`);
|
|
2881
3799
|
console.log(` ${"\u2500".repeat(40)}`);
|
|
2882
3800
|
console.log();
|
|
2883
|
-
console.log(` Locator: ${
|
|
2884
|
-
if (
|
|
2885
|
-
console.log(` Registry: ${
|
|
3801
|
+
console.log(` Locator: ${resource2.locator}`);
|
|
3802
|
+
if (resource2.registry) {
|
|
3803
|
+
console.log(` Registry: ${resource2.registry}`);
|
|
2886
3804
|
}
|
|
2887
|
-
if (
|
|
2888
|
-
console.log(` Path: ${
|
|
3805
|
+
if (resource2.path) {
|
|
3806
|
+
console.log(` Path: ${resource2.path}`);
|
|
2889
3807
|
}
|
|
2890
|
-
console.log(` Name: ${
|
|
2891
|
-
console.log(` Type: ${
|
|
2892
|
-
console.log(` Tag: ${
|
|
3808
|
+
console.log(` Name: ${resource2.name}`);
|
|
3809
|
+
console.log(` Type: ${resource2.type}`);
|
|
3810
|
+
console.log(` Tag: ${resource2.tag}`);
|
|
2893
3811
|
console.log();
|
|
2894
|
-
if (
|
|
3812
|
+
if (resource2.files?.length) {
|
|
2895
3813
|
console.log(` Files:`);
|
|
2896
|
-
printFileTree(
|
|
3814
|
+
printFileTree(resource2.files);
|
|
2897
3815
|
}
|
|
2898
3816
|
console.log();
|
|
2899
3817
|
} catch (error) {
|
|
@@ -3183,6 +4101,7 @@ var config = defineCommand({
|
|
|
3183
4101
|
});
|
|
3184
4102
|
|
|
3185
4103
|
// src/commands/server.ts
|
|
4104
|
+
import { join as join6 } from "path";
|
|
3186
4105
|
var server = defineCommand({
|
|
3187
4106
|
meta: {
|
|
3188
4107
|
name: "server",
|
|
@@ -3203,8 +4122,12 @@ var server = defineCommand({
|
|
|
3203
4122
|
const port = parseInt(args.port, 10);
|
|
3204
4123
|
const storagePath = args.storage || "./data";
|
|
3205
4124
|
const { createRegistryServer } = await import("@resourcexjs/server");
|
|
3206
|
-
const {
|
|
3207
|
-
const
|
|
4125
|
+
const { FileSystemRXAStore: FileSystemRXAStore2, FileSystemRXMStore: FileSystemRXMStore2 } = await Promise.resolve().then(() => (init_dist2(), exports_dist));
|
|
4126
|
+
const { serve: serve2 } = await Promise.resolve().then(() => (init_dist3(), exports_dist2));
|
|
4127
|
+
const app = createRegistryServer({
|
|
4128
|
+
rxaStore: new FileSystemRXAStore2(join6(storagePath, "blobs")),
|
|
4129
|
+
rxmStore: new FileSystemRXMStore2(join6(storagePath, "manifests"))
|
|
4130
|
+
});
|
|
3208
4131
|
consola.info(`Starting registry server...`);
|
|
3209
4132
|
console.log();
|
|
3210
4133
|
console.log(` Port: ${port}`);
|
|
@@ -3272,8 +4195,6 @@ var main = defineCommand({
|
|
|
3272
4195
|
},
|
|
3273
4196
|
subCommands: {
|
|
3274
4197
|
add,
|
|
3275
|
-
link,
|
|
3276
|
-
unlink,
|
|
3277
4198
|
list,
|
|
3278
4199
|
info,
|
|
3279
4200
|
remove,
|
|
@@ -3288,4 +4209,4 @@ var main = defineCommand({
|
|
|
3288
4209
|
});
|
|
3289
4210
|
runMain(main);
|
|
3290
4211
|
|
|
3291
|
-
//# debugId=
|
|
4212
|
+
//# debugId=806B8847021BED7E64756E2164756E21
|