@resourcexjs/cli 2.14.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +39 -567
- package/dist/index.js.map +4 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -774,374 +774,9 @@ import { promisify } from "util";
|
|
|
774
774
|
import { gzip } from "zlib";
|
|
775
775
|
import { promisify as promisify2 } from "util";
|
|
776
776
|
import { gunzip } from "zlib";
|
|
777
|
-
import { readdir, readFile, stat } from "fs/promises";
|
|
778
|
-
import { join, relative } from "path";
|
|
779
777
|
import { readdir as readdir2, readFile as readFile2, stat as stat2 } from "fs/promises";
|
|
780
778
|
import { join as join2, relative as relative2 } from "path";
|
|
781
779
|
import { createHash } from "crypto";
|
|
782
|
-
function writeString(view, offset, size, value) {
|
|
783
|
-
if (value)
|
|
784
|
-
encoder.encodeInto(value, view.subarray(offset, offset + size));
|
|
785
|
-
}
|
|
786
|
-
function writeOctal(view, offset, size, value) {
|
|
787
|
-
if (value === undefined)
|
|
788
|
-
return;
|
|
789
|
-
const octalString = value.toString(8).padStart(size - 1, "0");
|
|
790
|
-
encoder.encodeInto(octalString, view.subarray(offset, offset + size - 1));
|
|
791
|
-
}
|
|
792
|
-
async function normalizeBody(body) {
|
|
793
|
-
if (body === null || body === undefined)
|
|
794
|
-
return EMPTY;
|
|
795
|
-
if (body instanceof Uint8Array)
|
|
796
|
-
return body;
|
|
797
|
-
if (typeof body === "string")
|
|
798
|
-
return encoder.encode(body);
|
|
799
|
-
if (body instanceof ArrayBuffer)
|
|
800
|
-
return new Uint8Array(body);
|
|
801
|
-
if (body instanceof Blob)
|
|
802
|
-
return new Uint8Array(await body.arrayBuffer());
|
|
803
|
-
throw new TypeError("Unsupported content type for entry body.");
|
|
804
|
-
}
|
|
805
|
-
function writeChecksum(block) {
|
|
806
|
-
block.fill(CHECKSUM_SPACE, USTAR_CHECKSUM_OFFSET, USTAR_CHECKSUM_OFFSET + USTAR_CHECKSUM_SIZE);
|
|
807
|
-
let checksum = 0;
|
|
808
|
-
for (const byte of block)
|
|
809
|
-
checksum += byte;
|
|
810
|
-
for (let i2 = USTAR_CHECKSUM_OFFSET + 6 - 1;i2 >= USTAR_CHECKSUM_OFFSET; i2--) {
|
|
811
|
-
block[i2] = (checksum & 7) + ASCII_ZERO;
|
|
812
|
-
checksum >>= 3;
|
|
813
|
-
}
|
|
814
|
-
block[USTAR_CHECKSUM_OFFSET + 6] = 0;
|
|
815
|
-
block[USTAR_CHECKSUM_OFFSET + 7] = CHECKSUM_SPACE;
|
|
816
|
-
}
|
|
817
|
-
function generatePax(header) {
|
|
818
|
-
const paxRecords = {};
|
|
819
|
-
if (header.name.length > USTAR_NAME_SIZE) {
|
|
820
|
-
if (findUstarSplit(header.name) === null)
|
|
821
|
-
paxRecords.path = header.name;
|
|
822
|
-
}
|
|
823
|
-
if (header.linkname && header.linkname.length > USTAR_NAME_SIZE)
|
|
824
|
-
paxRecords.linkpath = header.linkname;
|
|
825
|
-
if (header.uname && header.uname.length > USTAR_UNAME_SIZE)
|
|
826
|
-
paxRecords.uname = header.uname;
|
|
827
|
-
if (header.gname && header.gname.length > USTAR_GNAME_SIZE)
|
|
828
|
-
paxRecords.gname = header.gname;
|
|
829
|
-
if (header.uid != null && header.uid > USTAR_MAX_UID_GID)
|
|
830
|
-
paxRecords.uid = String(header.uid);
|
|
831
|
-
if (header.gid != null && header.gid > USTAR_MAX_UID_GID)
|
|
832
|
-
paxRecords.gid = String(header.gid);
|
|
833
|
-
if (header.size != null && header.size > USTAR_MAX_SIZE)
|
|
834
|
-
paxRecords.size = String(header.size);
|
|
835
|
-
if (header.pax)
|
|
836
|
-
Object.assign(paxRecords, header.pax);
|
|
837
|
-
const paxEntries = Object.entries(paxRecords);
|
|
838
|
-
if (paxEntries.length === 0)
|
|
839
|
-
return null;
|
|
840
|
-
const paxBody = encoder.encode(paxEntries.map(([key, value]) => {
|
|
841
|
-
const record = `${key}=${value}
|
|
842
|
-
`;
|
|
843
|
-
const partLength = encoder.encode(record).length + 1;
|
|
844
|
-
let totalLength = partLength + String(partLength).length;
|
|
845
|
-
totalLength = partLength + String(totalLength).length;
|
|
846
|
-
return `${totalLength} ${record}`;
|
|
847
|
-
}).join(""));
|
|
848
|
-
return {
|
|
849
|
-
paxHeader: createTarHeader({
|
|
850
|
-
name: decoder.decode(encoder.encode(`PaxHeader/${header.name}`).slice(0, 100)),
|
|
851
|
-
size: paxBody.length,
|
|
852
|
-
type: "pax-header",
|
|
853
|
-
mode: 420,
|
|
854
|
-
mtime: header.mtime,
|
|
855
|
-
uname: header.uname,
|
|
856
|
-
gname: header.gname,
|
|
857
|
-
uid: header.uid,
|
|
858
|
-
gid: header.gid
|
|
859
|
-
}),
|
|
860
|
-
paxBody
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
function findUstarSplit(path) {
|
|
864
|
-
if (path.length <= USTAR_NAME_SIZE)
|
|
865
|
-
return null;
|
|
866
|
-
const minSlashIndex = path.length - USTAR_NAME_SIZE - 1;
|
|
867
|
-
const slashIndex = path.lastIndexOf("/", USTAR_PREFIX_SIZE);
|
|
868
|
-
if (slashIndex > 0 && slashIndex >= minSlashIndex)
|
|
869
|
-
return {
|
|
870
|
-
prefix: path.slice(0, slashIndex),
|
|
871
|
-
name: path.slice(slashIndex + 1)
|
|
872
|
-
};
|
|
873
|
-
return null;
|
|
874
|
-
}
|
|
875
|
-
function createTarHeader(header) {
|
|
876
|
-
const view = new Uint8Array(BLOCK_SIZE);
|
|
877
|
-
const size = isBodyless(header) ? 0 : header.size ?? 0;
|
|
878
|
-
let name = header.name;
|
|
879
|
-
let prefix = "";
|
|
880
|
-
if (!header.pax?.path) {
|
|
881
|
-
const split = findUstarSplit(name);
|
|
882
|
-
if (split) {
|
|
883
|
-
name = split.name;
|
|
884
|
-
prefix = split.prefix;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
writeString(view, USTAR_NAME_OFFSET, USTAR_NAME_SIZE, name);
|
|
888
|
-
writeOctal(view, USTAR_MODE_OFFSET, USTAR_MODE_SIZE, header.mode ?? (header.type === DIRECTORY ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE));
|
|
889
|
-
writeOctal(view, USTAR_UID_OFFSET, USTAR_UID_SIZE, header.uid ?? 0);
|
|
890
|
-
writeOctal(view, USTAR_GID_OFFSET, USTAR_GID_SIZE, header.gid ?? 0);
|
|
891
|
-
writeOctal(view, USTAR_SIZE_OFFSET, USTAR_SIZE_SIZE, size);
|
|
892
|
-
writeOctal(view, USTAR_MTIME_OFFSET, USTAR_MTIME_SIZE, Math.floor((header.mtime?.getTime() ?? Date.now()) / 1000));
|
|
893
|
-
writeString(view, USTAR_TYPEFLAG_OFFSET, USTAR_TYPEFLAG_SIZE, TYPEFLAG[header.type ?? FILE]);
|
|
894
|
-
writeString(view, USTAR_LINKNAME_OFFSET, USTAR_LINKNAME_SIZE, header.linkname);
|
|
895
|
-
writeString(view, USTAR_MAGIC_OFFSET, USTAR_MAGIC_SIZE, "ustar\x00");
|
|
896
|
-
writeString(view, USTAR_VERSION_OFFSET, USTAR_VERSION_SIZE, USTAR_VERSION);
|
|
897
|
-
writeString(view, USTAR_UNAME_OFFSET, USTAR_UNAME_SIZE, header.uname);
|
|
898
|
-
writeString(view, USTAR_GNAME_OFFSET, USTAR_GNAME_SIZE, header.gname);
|
|
899
|
-
writeString(view, USTAR_PREFIX_OFFSET, USTAR_PREFIX_SIZE, prefix);
|
|
900
|
-
writeChecksum(view);
|
|
901
|
-
return view;
|
|
902
|
-
}
|
|
903
|
-
function getHeaderBlocks(header) {
|
|
904
|
-
const base = createTarHeader(header);
|
|
905
|
-
const pax = generatePax(header);
|
|
906
|
-
if (!pax)
|
|
907
|
-
return [base];
|
|
908
|
-
const paxPadding = -pax.paxBody.length & BLOCK_SIZE_MASK;
|
|
909
|
-
const paddingBlocks = paxPadding > 0 ? [ZERO_BLOCK.subarray(0, paxPadding)] : [];
|
|
910
|
-
return [
|
|
911
|
-
pax.paxHeader,
|
|
912
|
-
pax.paxBody,
|
|
913
|
-
...paddingBlocks,
|
|
914
|
-
base
|
|
915
|
-
];
|
|
916
|
-
}
|
|
917
|
-
function createTarPacker(onData, onError, onFinalize) {
|
|
918
|
-
let currentHeader = null;
|
|
919
|
-
let bytesWritten = 0;
|
|
920
|
-
let finalized = false;
|
|
921
|
-
return {
|
|
922
|
-
add(header) {
|
|
923
|
-
if (finalized) {
|
|
924
|
-
const error = /* @__PURE__ */ new Error("No new tar entries after finalize.");
|
|
925
|
-
onError(error);
|
|
926
|
-
throw error;
|
|
927
|
-
}
|
|
928
|
-
if (currentHeader !== null) {
|
|
929
|
-
const error = /* @__PURE__ */ new Error("Previous entry must be completed before adding a new one");
|
|
930
|
-
onError(error);
|
|
931
|
-
throw error;
|
|
932
|
-
}
|
|
933
|
-
try {
|
|
934
|
-
const size = isBodyless(header) ? 0 : header.size ?? 0;
|
|
935
|
-
const headerBlocks = getHeaderBlocks({
|
|
936
|
-
...header,
|
|
937
|
-
size
|
|
938
|
-
});
|
|
939
|
-
for (const block of headerBlocks)
|
|
940
|
-
onData(block);
|
|
941
|
-
currentHeader = {
|
|
942
|
-
...header,
|
|
943
|
-
size
|
|
944
|
-
};
|
|
945
|
-
bytesWritten = 0;
|
|
946
|
-
} catch (error) {
|
|
947
|
-
onError(error);
|
|
948
|
-
}
|
|
949
|
-
},
|
|
950
|
-
write(chunk) {
|
|
951
|
-
if (!currentHeader) {
|
|
952
|
-
const error = /* @__PURE__ */ new Error("No active tar entry.");
|
|
953
|
-
onError(error);
|
|
954
|
-
throw error;
|
|
955
|
-
}
|
|
956
|
-
if (finalized) {
|
|
957
|
-
const error = /* @__PURE__ */ new Error("Cannot write data after finalize.");
|
|
958
|
-
onError(error);
|
|
959
|
-
throw error;
|
|
960
|
-
}
|
|
961
|
-
const newTotal = bytesWritten + chunk.length;
|
|
962
|
-
if (newTotal > currentHeader.size) {
|
|
963
|
-
const error = /* @__PURE__ */ new Error(`"${currentHeader.name}" exceeds given size of ${currentHeader.size} bytes.`);
|
|
964
|
-
onError(error);
|
|
965
|
-
throw error;
|
|
966
|
-
}
|
|
967
|
-
try {
|
|
968
|
-
bytesWritten = newTotal;
|
|
969
|
-
onData(chunk);
|
|
970
|
-
} catch (error) {
|
|
971
|
-
onError(error);
|
|
972
|
-
}
|
|
973
|
-
},
|
|
974
|
-
endEntry() {
|
|
975
|
-
if (!currentHeader) {
|
|
976
|
-
const error = /* @__PURE__ */ new Error("No active entry to end.");
|
|
977
|
-
onError(error);
|
|
978
|
-
throw error;
|
|
979
|
-
}
|
|
980
|
-
if (finalized) {
|
|
981
|
-
const error = /* @__PURE__ */ new Error("Cannot end entry after finalize.");
|
|
982
|
-
onError(error);
|
|
983
|
-
throw error;
|
|
984
|
-
}
|
|
985
|
-
try {
|
|
986
|
-
if (bytesWritten !== currentHeader.size) {
|
|
987
|
-
const error = /* @__PURE__ */ new Error(`Size mismatch for "${currentHeader.name}".`);
|
|
988
|
-
onError(error);
|
|
989
|
-
throw error;
|
|
990
|
-
}
|
|
991
|
-
const paddingSize = -currentHeader.size & BLOCK_SIZE_MASK;
|
|
992
|
-
if (paddingSize > 0)
|
|
993
|
-
onData(new Uint8Array(paddingSize));
|
|
994
|
-
currentHeader = null;
|
|
995
|
-
bytesWritten = 0;
|
|
996
|
-
} catch (error) {
|
|
997
|
-
onError(error);
|
|
998
|
-
throw error;
|
|
999
|
-
}
|
|
1000
|
-
},
|
|
1001
|
-
finalize() {
|
|
1002
|
-
if (finalized) {
|
|
1003
|
-
const error = /* @__PURE__ */ new Error("Archive has already been finalized");
|
|
1004
|
-
onError(error);
|
|
1005
|
-
throw error;
|
|
1006
|
-
}
|
|
1007
|
-
if (currentHeader !== null) {
|
|
1008
|
-
const error = /* @__PURE__ */ new Error("Cannot finalize while an entry is still active");
|
|
1009
|
-
onError(error);
|
|
1010
|
-
throw error;
|
|
1011
|
-
}
|
|
1012
|
-
try {
|
|
1013
|
-
onData(EOF_BUFFER);
|
|
1014
|
-
finalized = true;
|
|
1015
|
-
if (onFinalize)
|
|
1016
|
-
onFinalize();
|
|
1017
|
-
} catch (error) {
|
|
1018
|
-
onError(error);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
function createTarPacker2() {
|
|
1024
|
-
let streamController;
|
|
1025
|
-
let packer;
|
|
1026
|
-
return {
|
|
1027
|
-
readable: new ReadableStream({ start(controller) {
|
|
1028
|
-
streamController = controller;
|
|
1029
|
-
packer = createTarPacker(controller.enqueue.bind(controller), controller.error.bind(controller), controller.close.bind(controller));
|
|
1030
|
-
} }),
|
|
1031
|
-
controller: {
|
|
1032
|
-
add(header) {
|
|
1033
|
-
const bodyless = isBodyless(header);
|
|
1034
|
-
const h2 = { ...header };
|
|
1035
|
-
if (bodyless)
|
|
1036
|
-
h2.size = 0;
|
|
1037
|
-
packer.add(h2);
|
|
1038
|
-
if (bodyless)
|
|
1039
|
-
packer.endEntry();
|
|
1040
|
-
return new WritableStream({
|
|
1041
|
-
write(chunk) {
|
|
1042
|
-
packer.write(chunk);
|
|
1043
|
-
},
|
|
1044
|
-
close() {
|
|
1045
|
-
if (!bodyless)
|
|
1046
|
-
packer.endEntry();
|
|
1047
|
-
},
|
|
1048
|
-
abort(reason) {
|
|
1049
|
-
streamController.error(reason);
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1052
|
-
},
|
|
1053
|
-
finalize() {
|
|
1054
|
-
packer.finalize();
|
|
1055
|
-
},
|
|
1056
|
-
error(err) {
|
|
1057
|
-
streamController.error(err);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
async function streamToBuffer(stream) {
|
|
1063
|
-
const chunks = [];
|
|
1064
|
-
const reader = stream.getReader();
|
|
1065
|
-
let totalLength = 0;
|
|
1066
|
-
try {
|
|
1067
|
-
while (true) {
|
|
1068
|
-
const { done, value } = await reader.read();
|
|
1069
|
-
if (done)
|
|
1070
|
-
break;
|
|
1071
|
-
chunks.push(value);
|
|
1072
|
-
totalLength += value.length;
|
|
1073
|
-
}
|
|
1074
|
-
const result = new Uint8Array(totalLength);
|
|
1075
|
-
let offset = 0;
|
|
1076
|
-
for (const chunk of chunks) {
|
|
1077
|
-
result.set(chunk, offset);
|
|
1078
|
-
offset += chunk.length;
|
|
1079
|
-
}
|
|
1080
|
-
return result;
|
|
1081
|
-
} finally {
|
|
1082
|
-
reader.releaseLock();
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
async function packTar(entries) {
|
|
1086
|
-
const { readable, controller } = createTarPacker2();
|
|
1087
|
-
await (async () => {
|
|
1088
|
-
for (const entry of entries) {
|
|
1089
|
-
const entryStream = controller.add(entry.header);
|
|
1090
|
-
const body = "body" in entry ? entry.body : entry.data;
|
|
1091
|
-
if (!body) {
|
|
1092
|
-
await entryStream.close();
|
|
1093
|
-
continue;
|
|
1094
|
-
}
|
|
1095
|
-
if (body instanceof ReadableStream)
|
|
1096
|
-
await body.pipeTo(entryStream);
|
|
1097
|
-
else if (body instanceof Blob)
|
|
1098
|
-
await body.stream().pipeTo(entryStream);
|
|
1099
|
-
else
|
|
1100
|
-
try {
|
|
1101
|
-
const chunk = await normalizeBody(body);
|
|
1102
|
-
if (chunk.length > 0) {
|
|
1103
|
-
const writer = entryStream.getWriter();
|
|
1104
|
-
await writer.write(chunk);
|
|
1105
|
-
await writer.close();
|
|
1106
|
-
} else
|
|
1107
|
-
await entryStream.close();
|
|
1108
|
-
} catch {
|
|
1109
|
-
throw new TypeError(`Unsupported content type for entry "${entry.header.name}".`);
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
})().then(() => controller.finalize()).catch((err) => controller.error(err));
|
|
1113
|
-
return new Uint8Array(await streamToBuffer(readable));
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
class RXAImpl {
|
|
1117
|
-
_buffer;
|
|
1118
|
-
constructor(buffer) {
|
|
1119
|
-
this._buffer = buffer;
|
|
1120
|
-
}
|
|
1121
|
-
get stream() {
|
|
1122
|
-
const buffer = this._buffer;
|
|
1123
|
-
return new ReadableStream({
|
|
1124
|
-
start(controller) {
|
|
1125
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
1126
|
-
controller.close();
|
|
1127
|
-
}
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
async buffer() {
|
|
1131
|
-
return this._buffer;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
async function archive(files) {
|
|
1135
|
-
const entries = Object.entries(files).map(([name, content]) => {
|
|
1136
|
-
return {
|
|
1137
|
-
header: { name, size: content.length, type: "file" },
|
|
1138
|
-
body: new Uint8Array(content)
|
|
1139
|
-
};
|
|
1140
|
-
});
|
|
1141
|
-
const tarBuffer = await packTar(entries);
|
|
1142
|
-
const gzipBuffer = await gzipAsync(Buffer.from(tarBuffer));
|
|
1143
|
-
return new RXAImpl(gzipBuffer);
|
|
1144
|
-
}
|
|
1145
780
|
function $constructor(name, initializer, params) {
|
|
1146
781
|
function init2(inst, def) {
|
|
1147
782
|
if (!inst._zod) {
|
|
@@ -4829,121 +4464,6 @@ function bigint3(params) {
|
|
|
4829
4464
|
function date4(params) {
|
|
4830
4465
|
return _coercedDate(ZodDate, params);
|
|
4831
4466
|
}
|
|
4832
|
-
function define(input) {
|
|
4833
|
-
if (input === null || typeof input !== "object") {
|
|
4834
|
-
throw new DefinitionError("definition must be an object");
|
|
4835
|
-
}
|
|
4836
|
-
let validated;
|
|
4837
|
-
try {
|
|
4838
|
-
validated = RXDSchema.parse(input);
|
|
4839
|
-
} catch (e2) {
|
|
4840
|
-
throw new DefinitionError(`Invalid definition: ${e2 instanceof Error ? e2.message : String(e2)}`);
|
|
4841
|
-
}
|
|
4842
|
-
const rxd = Object.assign(Object.create(null), {
|
|
4843
|
-
name: validated.name,
|
|
4844
|
-
type: validated.type,
|
|
4845
|
-
tag: validated.tag ?? validated.version ?? undefined,
|
|
4846
|
-
registry: validated.registry,
|
|
4847
|
-
path: validated.path,
|
|
4848
|
-
description: validated.description,
|
|
4849
|
-
author: validated.author,
|
|
4850
|
-
license: validated.license,
|
|
4851
|
-
keywords: validated.keywords,
|
|
4852
|
-
repository: validated.repository
|
|
4853
|
-
});
|
|
4854
|
-
return rxd;
|
|
4855
|
-
}
|
|
4856
|
-
function locate(rxm) {
|
|
4857
|
-
return {
|
|
4858
|
-
registry: rxm.definition.registry,
|
|
4859
|
-
path: rxm.definition.path,
|
|
4860
|
-
name: rxm.definition.name,
|
|
4861
|
-
tag: rxm.definition.tag
|
|
4862
|
-
};
|
|
4863
|
-
}
|
|
4864
|
-
function manifest(rxd) {
|
|
4865
|
-
return {
|
|
4866
|
-
definition: {
|
|
4867
|
-
name: rxd.name,
|
|
4868
|
-
type: rxd.type,
|
|
4869
|
-
tag: rxd.tag ?? "latest",
|
|
4870
|
-
registry: rxd.registry,
|
|
4871
|
-
path: rxd.path,
|
|
4872
|
-
description: rxd.description,
|
|
4873
|
-
author: rxd.author,
|
|
4874
|
-
license: rxd.license,
|
|
4875
|
-
keywords: rxd.keywords,
|
|
4876
|
-
repository: rxd.repository
|
|
4877
|
-
},
|
|
4878
|
-
archive: {},
|
|
4879
|
-
source: {}
|
|
4880
|
-
};
|
|
4881
|
-
}
|
|
4882
|
-
function resource(rxm, rxa) {
|
|
4883
|
-
const rxi = locate(rxm);
|
|
4884
|
-
return {
|
|
4885
|
-
identifier: rxi,
|
|
4886
|
-
manifest: rxm,
|
|
4887
|
-
archive: rxa
|
|
4888
|
-
};
|
|
4889
|
-
}
|
|
4890
|
-
|
|
4891
|
-
class FolderLoader {
|
|
4892
|
-
async canLoad(source) {
|
|
4893
|
-
try {
|
|
4894
|
-
const stats = await stat(source);
|
|
4895
|
-
if (!stats.isDirectory()) {
|
|
4896
|
-
return false;
|
|
4897
|
-
}
|
|
4898
|
-
const manifestPath = join(source, "resource.json");
|
|
4899
|
-
const manifestStats = await stat(manifestPath);
|
|
4900
|
-
return manifestStats.isFile();
|
|
4901
|
-
} catch {
|
|
4902
|
-
return false;
|
|
4903
|
-
}
|
|
4904
|
-
}
|
|
4905
|
-
async load(folderPath) {
|
|
4906
|
-
const resourceJsonPath = join(folderPath, "resource.json");
|
|
4907
|
-
let resourceJson;
|
|
4908
|
-
try {
|
|
4909
|
-
resourceJson = await readFile(resourceJsonPath, "utf-8");
|
|
4910
|
-
} catch (error48) {
|
|
4911
|
-
throw new ResourceXError(`Failed to read resource.json: ${error48 instanceof Error ? error48.message : String(error48)}`);
|
|
4912
|
-
}
|
|
4913
|
-
let json2;
|
|
4914
|
-
try {
|
|
4915
|
-
json2 = JSON.parse(resourceJson);
|
|
4916
|
-
} catch (error48) {
|
|
4917
|
-
throw new ResourceXError(`Invalid JSON in resource.json: ${error48 instanceof Error ? error48.message : String(error48)}`);
|
|
4918
|
-
}
|
|
4919
|
-
const rxd = define(json2);
|
|
4920
|
-
const files = await this.readFolderFiles(folderPath);
|
|
4921
|
-
if (Object.keys(files).length === 0) {
|
|
4922
|
-
throw new ResourceXError("No content files found in resource folder");
|
|
4923
|
-
}
|
|
4924
|
-
const rxm = manifest(rxd);
|
|
4925
|
-
const rxa = await archive(files);
|
|
4926
|
-
return resource(rxm, rxa);
|
|
4927
|
-
}
|
|
4928
|
-
async readFolderFiles(folderPath, basePath = folderPath) {
|
|
4929
|
-
const files = {};
|
|
4930
|
-
const entries = await readdir(folderPath, { withFileTypes: true });
|
|
4931
|
-
for (const entry of entries) {
|
|
4932
|
-
const fullPath = join(folderPath, entry.name);
|
|
4933
|
-
const relativePath = relative(basePath, fullPath);
|
|
4934
|
-
if (relativePath === "resource.json") {
|
|
4935
|
-
continue;
|
|
4936
|
-
}
|
|
4937
|
-
if (entry.isFile()) {
|
|
4938
|
-
files[relativePath] = await readFile(fullPath);
|
|
4939
|
-
} else if (entry.isDirectory()) {
|
|
4940
|
-
const subFiles = await this.readFolderFiles(fullPath, basePath);
|
|
4941
|
-
Object.assign(files, subFiles);
|
|
4942
|
-
}
|
|
4943
|
-
}
|
|
4944
|
-
return files;
|
|
4945
|
-
}
|
|
4946
|
-
}
|
|
4947
4467
|
|
|
4948
4468
|
class FolderSourceLoader {
|
|
4949
4469
|
async canLoad(source) {
|
|
@@ -4962,31 +4482,6 @@ class FolderSourceLoader {
|
|
|
4962
4482
|
const files = await this.readFolderFiles(source);
|
|
4963
4483
|
return { source, files };
|
|
4964
4484
|
}
|
|
4965
|
-
async isFresh(source, cachedAt) {
|
|
4966
|
-
try {
|
|
4967
|
-
const maxMtime = await this.getMaxMtime(source);
|
|
4968
|
-
return maxMtime <= cachedAt;
|
|
4969
|
-
} catch {
|
|
4970
|
-
return false;
|
|
4971
|
-
}
|
|
4972
|
-
}
|
|
4973
|
-
async getMaxMtime(folderPath) {
|
|
4974
|
-
let max = new Date(0);
|
|
4975
|
-
const entries = await readdir2(folderPath, { withFileTypes: true });
|
|
4976
|
-
for (const entry of entries) {
|
|
4977
|
-
const fullPath = join2(folderPath, entry.name);
|
|
4978
|
-
if (entry.isFile()) {
|
|
4979
|
-
const stats = await stat2(fullPath);
|
|
4980
|
-
if (stats.mtime > max)
|
|
4981
|
-
max = stats.mtime;
|
|
4982
|
-
} else if (entry.isDirectory()) {
|
|
4983
|
-
const subMax = await this.getMaxMtime(fullPath);
|
|
4984
|
-
if (subMax > max)
|
|
4985
|
-
max = subMax;
|
|
4986
|
-
}
|
|
4987
|
-
}
|
|
4988
|
-
return max;
|
|
4989
|
-
}
|
|
4990
4485
|
async readFolderFiles(folderPath, basePath = folderPath) {
|
|
4991
4486
|
const files = {};
|
|
4992
4487
|
const entries = await readdir2(folderPath, { withFileTypes: true });
|
|
@@ -5187,7 +4682,7 @@ var __defProp2, __export2 = (target, all) => {
|
|
|
5187
4682
|
configurable: true,
|
|
5188
4683
|
set: (newValue) => all[name] = () => newValue
|
|
5189
4684
|
});
|
|
5190
|
-
}, BLOCK_SIZE = 512,
|
|
4685
|
+
}, BLOCK_SIZE = 512, ZERO_BLOCK, EMPTY, encoder, decoder, EOF_BUFFER, gzipAsync, exports_external, exports_core2, NEVER, $brand, $ZodAsyncError, $ZodEncodeError, globalConfig, exports_util, EVALUATING, captureStackTrace, allowsEval, getParsedType = (data) => {
|
|
5191
4686
|
const t2 = typeof data;
|
|
5192
4687
|
switch (t2) {
|
|
5193
4688
|
case "undefined":
|
|
@@ -10865,22 +10360,9 @@ var __defProp2, __export2 = (target, all) => {
|
|
|
10865
10360
|
Codec: ZodCodec,
|
|
10866
10361
|
Boolean: ZodBoolean,
|
|
10867
10362
|
String: ZodString
|
|
10868
|
-
}, ...args), ZodIssueCode, ZodFirstPartyTypeKind, z2, RECOGNIZED_KEYS, exports_coerce, ResourceXError,
|
|
10363
|
+
}, ...args), ZodIssueCode, ZodFirstPartyTypeKind, z2, RECOGNIZED_KEYS, exports_coerce, ResourceXError, RXDSchema, gunzipAsync, RegistryError, textType, jsonType, binaryType, skillType, builtinTypes, ResourceTypeError;
|
|
10869
10364
|
var init_dist = __esm(() => {
|
|
10870
10365
|
__defProp2 = Object.defineProperty;
|
|
10871
|
-
TYPEFLAG = {
|
|
10872
|
-
file: "0",
|
|
10873
|
-
link: "1",
|
|
10874
|
-
symlink: "2",
|
|
10875
|
-
"character-device": "3",
|
|
10876
|
-
"block-device": "4",
|
|
10877
|
-
directory: "5",
|
|
10878
|
-
fifo: "6",
|
|
10879
|
-
"pax-header": "x",
|
|
10880
|
-
"pax-global-header": "g",
|
|
10881
|
-
"gnu-long-name": "L",
|
|
10882
|
-
"gnu-long-link-name": "K"
|
|
10883
|
-
};
|
|
10884
10366
|
ZERO_BLOCK = new Uint8Array(BLOCK_SIZE);
|
|
10885
10367
|
EMPTY = new Uint8Array(0);
|
|
10886
10368
|
encoder = new TextEncoder;
|
|
@@ -14854,17 +14336,10 @@ var init_dist = __esm(() => {
|
|
|
14854
14336
|
this.name = "ResourceXError";
|
|
14855
14337
|
}
|
|
14856
14338
|
};
|
|
14857
|
-
DefinitionError = class DefinitionError extends ResourceXError {
|
|
14858
|
-
constructor(message) {
|
|
14859
|
-
super(message);
|
|
14860
|
-
this.name = "DefinitionError";
|
|
14861
|
-
}
|
|
14862
|
-
};
|
|
14863
14339
|
RXDSchema = exports_external.object({
|
|
14864
14340
|
name: exports_external.string().min(1).max(128),
|
|
14865
14341
|
type: exports_external.string().min(1).max(64),
|
|
14866
14342
|
tag: exports_external.string().max(64).optional(),
|
|
14867
|
-
version: exports_external.string().max(64).optional(),
|
|
14868
14343
|
registry: exports_external.string().max(256).optional(),
|
|
14869
14344
|
path: exports_external.string().max(256).optional(),
|
|
14870
14345
|
description: exports_external.string().max(1024).optional(),
|
|
@@ -14984,13 +14459,13 @@ __export(exports_dist, {
|
|
|
14984
14459
|
});
|
|
14985
14460
|
import { createHash as createHash2 } from "crypto";
|
|
14986
14461
|
import { createReadStream } from "fs";
|
|
14987
|
-
import { mkdir, readdir
|
|
14988
|
-
import { join
|
|
14989
|
-
import { mkdir as mkdir2, readdir as readdir22, readFile
|
|
14462
|
+
import { mkdir, readdir, stat, unlink, writeFile } from "fs/promises";
|
|
14463
|
+
import { join } from "path";
|
|
14464
|
+
import { mkdir as mkdir2, readdir as readdir22, readFile, rm, stat as stat22, unlink as unlink2, writeFile as writeFile2 } from "fs/promises";
|
|
14990
14465
|
import { join as join22 } from "path";
|
|
14991
14466
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
14992
14467
|
import { homedir } from "os";
|
|
14993
|
-
import { dirname, join as
|
|
14468
|
+
import { dirname, join as join3 } from "path";
|
|
14994
14469
|
|
|
14995
14470
|
class FileSystemRXAStore {
|
|
14996
14471
|
basePath;
|
|
@@ -14999,7 +14474,7 @@ class FileSystemRXAStore {
|
|
|
14999
14474
|
}
|
|
15000
14475
|
getPath(digest) {
|
|
15001
14476
|
const prefix = digest.substring(7, 9);
|
|
15002
|
-
return
|
|
14477
|
+
return join(this.basePath, prefix, digest);
|
|
15003
14478
|
}
|
|
15004
14479
|
async get(digest) {
|
|
15005
14480
|
if (!isValidDigest(digest)) {
|
|
@@ -15031,7 +14506,7 @@ class FileSystemRXAStore {
|
|
|
15031
14506
|
if (await this.has(digest)) {
|
|
15032
14507
|
return digest;
|
|
15033
14508
|
}
|
|
15034
|
-
const dir =
|
|
14509
|
+
const dir = join(path, "..");
|
|
15035
14510
|
await mkdir(dir, { recursive: true });
|
|
15036
14511
|
await writeFile(path, data);
|
|
15037
14512
|
return digest;
|
|
@@ -15039,7 +14514,7 @@ class FileSystemRXAStore {
|
|
|
15039
14514
|
async has(digest) {
|
|
15040
14515
|
const path = this.getPath(digest);
|
|
15041
14516
|
try {
|
|
15042
|
-
await
|
|
14517
|
+
await stat(path);
|
|
15043
14518
|
return true;
|
|
15044
14519
|
} catch {
|
|
15045
14520
|
return false;
|
|
@@ -15054,11 +14529,11 @@ class FileSystemRXAStore {
|
|
|
15054
14529
|
async list() {
|
|
15055
14530
|
const digests = [];
|
|
15056
14531
|
try {
|
|
15057
|
-
const prefixes = await
|
|
14532
|
+
const prefixes = await readdir(this.basePath);
|
|
15058
14533
|
for (const prefix of prefixes) {
|
|
15059
|
-
const prefixPath =
|
|
14534
|
+
const prefixPath = join(this.basePath, prefix);
|
|
15060
14535
|
try {
|
|
15061
|
-
const files = await
|
|
14536
|
+
const files = await readdir(prefixPath);
|
|
15062
14537
|
for (const file2 of files) {
|
|
15063
14538
|
if (file2.startsWith("sha256:")) {
|
|
15064
14539
|
digests.push(file2);
|
|
@@ -15086,17 +14561,17 @@ class FileSystemRXMStore {
|
|
|
15086
14561
|
async get(name, tag, registry2) {
|
|
15087
14562
|
const path = this.getPath(name, tag, registry2);
|
|
15088
14563
|
try {
|
|
15089
|
-
const data = await
|
|
14564
|
+
const data = await readFile(path, "utf-8");
|
|
15090
14565
|
return JSON.parse(data);
|
|
15091
14566
|
} catch {
|
|
15092
14567
|
return null;
|
|
15093
14568
|
}
|
|
15094
14569
|
}
|
|
15095
|
-
async put(
|
|
15096
|
-
const path = this.getPath(
|
|
14570
|
+
async put(manifest) {
|
|
14571
|
+
const path = this.getPath(manifest.name, manifest.tag, manifest.registry);
|
|
15097
14572
|
const dir = join22(path, "..");
|
|
15098
14573
|
await mkdir2(dir, { recursive: true });
|
|
15099
|
-
await writeFile2(path, JSON.stringify(
|
|
14574
|
+
await writeFile2(path, JSON.stringify(manifest, null, 2), "utf-8");
|
|
15100
14575
|
}
|
|
15101
14576
|
async has(name, tag, registry2) {
|
|
15102
14577
|
const path = this.getPath(name, tag, registry2);
|
|
@@ -15134,7 +14609,7 @@ class FileSystemRXMStore {
|
|
|
15134
14609
|
async getLatest(name, registry2) {
|
|
15135
14610
|
const dir = this.getDir(name, registry2);
|
|
15136
14611
|
try {
|
|
15137
|
-
return (await
|
|
14612
|
+
return (await readFile(join22(dir, LATEST_FILE), "utf-8")).trim();
|
|
15138
14613
|
} catch {
|
|
15139
14614
|
return null;
|
|
15140
14615
|
}
|
|
@@ -15188,9 +14663,9 @@ class FileSystemRXMStore {
|
|
|
15188
14663
|
for (const file2 of files) {
|
|
15189
14664
|
if (file2.endsWith(".json")) {
|
|
15190
14665
|
const filePath = join22(namePath, file2);
|
|
15191
|
-
const data = await
|
|
15192
|
-
const
|
|
15193
|
-
results.push(
|
|
14666
|
+
const data = await readFile(filePath, "utf-8");
|
|
14667
|
+
const manifest = JSON.parse(data);
|
|
14668
|
+
results.push(manifest);
|
|
15194
14669
|
}
|
|
15195
14670
|
}
|
|
15196
14671
|
} catch {}
|
|
@@ -15216,13 +14691,10 @@ class NodeProvider {
|
|
|
15216
14691
|
createStores(config2) {
|
|
15217
14692
|
const basePath = config2.path ?? DEFAULT_BASE_PATH;
|
|
15218
14693
|
return {
|
|
15219
|
-
rxaStore: new FileSystemRXAStore(
|
|
15220
|
-
rxmStore: new FileSystemRXMStore(
|
|
14694
|
+
rxaStore: new FileSystemRXAStore(join3(basePath, "blobs")),
|
|
14695
|
+
rxmStore: new FileSystemRXMStore(join3(basePath, "manifests"))
|
|
15221
14696
|
};
|
|
15222
14697
|
}
|
|
15223
|
-
createLoader(_config) {
|
|
15224
|
-
return new FolderLoader;
|
|
15225
|
-
}
|
|
15226
14698
|
createSourceLoader(_config) {
|
|
15227
14699
|
return new FolderSourceLoader;
|
|
15228
14700
|
}
|
|
@@ -15232,7 +14704,7 @@ class NodeProvider {
|
|
|
15232
14704
|
return { registry: envRegistry };
|
|
15233
14705
|
}
|
|
15234
14706
|
const basePath = config2.path ?? DEFAULT_BASE_PATH;
|
|
15235
|
-
const configPath =
|
|
14707
|
+
const configPath = join3(basePath, "config.json");
|
|
15236
14708
|
try {
|
|
15237
14709
|
if (existsSync(configPath)) {
|
|
15238
14710
|
const raw = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
@@ -15249,7 +14721,7 @@ class NodeProvider {
|
|
|
15249
14721
|
}
|
|
15250
14722
|
configPath(config2) {
|
|
15251
14723
|
const basePath = config2.path ?? DEFAULT_BASE_PATH;
|
|
15252
|
-
return
|
|
14724
|
+
return join3(basePath, "config.json");
|
|
15253
14725
|
}
|
|
15254
14726
|
readConfig(config2) {
|
|
15255
14727
|
const configPath = this.configPath(config2);
|
|
@@ -17252,14 +16724,14 @@ import { createResourceX, setProvider } from "resourcexjs";
|
|
|
17252
16724
|
|
|
17253
16725
|
// src/lib/paths.ts
|
|
17254
16726
|
import { homedir as homedir2 } from "os";
|
|
17255
|
-
import { join as
|
|
17256
|
-
var RX_HOME = process.env.RESOURCEX_HOME || process.env.RX_HOME ||
|
|
16727
|
+
import { join as join4 } from "path";
|
|
16728
|
+
var RX_HOME = process.env.RESOURCEX_HOME || process.env.RX_HOME || join4(homedir2(), ".deepractice", "resourcex");
|
|
17257
16729
|
var PATHS = {
|
|
17258
16730
|
root: RX_HOME,
|
|
17259
|
-
config:
|
|
17260
|
-
local:
|
|
17261
|
-
cache:
|
|
17262
|
-
linked:
|
|
16731
|
+
config: join4(RX_HOME, "config.json"),
|
|
16732
|
+
local: join4(RX_HOME, "local"),
|
|
16733
|
+
cache: join4(RX_HOME, "cache"),
|
|
16734
|
+
linked: join4(RX_HOME, "linked")
|
|
17263
16735
|
};
|
|
17264
16736
|
|
|
17265
16737
|
// src/lib/config.ts
|
|
@@ -17389,13 +16861,13 @@ var add = defineCommand({
|
|
|
17389
16861
|
async run({ args }) {
|
|
17390
16862
|
try {
|
|
17391
16863
|
const rx = await getClient();
|
|
17392
|
-
const
|
|
16864
|
+
const resource = await rx.add(args.path);
|
|
17393
16865
|
consola.success(`Added resource:
|
|
17394
16866
|
`);
|
|
17395
|
-
console.log(` Locator: ${
|
|
17396
|
-
console.log(` Name: ${
|
|
17397
|
-
console.log(` Type: ${
|
|
17398
|
-
console.log(` Tag: ${
|
|
16867
|
+
console.log(` Locator: ${resource.locator}`);
|
|
16868
|
+
console.log(` Name: ${resource.definition.name}`);
|
|
16869
|
+
console.log(` Type: ${resource.definition.type}`);
|
|
16870
|
+
console.log(` Tag: ${resource.definition.tag}`);
|
|
17399
16871
|
} catch (error48) {
|
|
17400
16872
|
consola.error(error48 instanceof Error ? error48.message : "Failed to add resource");
|
|
17401
16873
|
process.exit(1);
|
|
@@ -17509,13 +16981,13 @@ var info = defineCommand({
|
|
|
17509
16981
|
async run({ args }) {
|
|
17510
16982
|
try {
|
|
17511
16983
|
const rx = await getClient();
|
|
17512
|
-
const
|
|
17513
|
-
const { definition, source } =
|
|
16984
|
+
const resource = await rx.info(args.locator);
|
|
16985
|
+
const { definition, source } = resource;
|
|
17514
16986
|
console.log();
|
|
17515
16987
|
console.log(` ${definition.name}:${definition.tag}`);
|
|
17516
16988
|
console.log(` ${"\u2500".repeat(40)}`);
|
|
17517
16989
|
console.log();
|
|
17518
|
-
console.log(` Locator: ${
|
|
16990
|
+
console.log(` Locator: ${resource.locator}`);
|
|
17519
16991
|
if (definition.registry) {
|
|
17520
16992
|
console.log(` Registry: ${definition.registry}`);
|
|
17521
16993
|
}
|
|
@@ -17988,4 +17460,4 @@ var main = defineCommand({
|
|
|
17988
17460
|
});
|
|
17989
17461
|
runMain(main);
|
|
17990
17462
|
|
|
17991
|
-
//# debugId=
|
|
17463
|
+
//# debugId=17116DDBA925B5B364756E2164756E21
|