@resourcexjs/core 2.17.2 → 2.19.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 CHANGED
@@ -13,10 +13,6 @@ var __export = (target, all) => {
13
13
  });
14
14
  };
15
15
 
16
- // src/model/archive.ts
17
- import { promisify } from "node:util";
18
- import { gzip } from "node:zlib";
19
-
20
16
  // ../../node_modules/.bun/modern-tar@0.7.3/node_modules/modern-tar/dist/unpacker-BpPBxY8N.js
21
17
  var BLOCK_SIZE = 512;
22
18
  var BLOCK_SIZE_MASK = 511;
@@ -995,7 +991,28 @@ async function unpackTar(archive, options = {}) {
995
991
  }
996
992
 
997
993
  // src/model/archive.ts
998
- var gzipAsync = promisify(gzip);
994
+ async function gzipCompress(data) {
995
+ const cs = new CompressionStream("gzip");
996
+ const writer = cs.writable.getWriter();
997
+ writer.write(data);
998
+ writer.close();
999
+ const reader = cs.readable.getReader();
1000
+ const chunks = [];
1001
+ while (true) {
1002
+ const { done, value } = await reader.read();
1003
+ if (done)
1004
+ break;
1005
+ chunks.push(value);
1006
+ }
1007
+ const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
1008
+ const result = new Uint8Array(totalLength);
1009
+ let offset = 0;
1010
+ for (const chunk of chunks) {
1011
+ result.set(chunk, offset);
1012
+ offset += chunk.length;
1013
+ }
1014
+ return Buffer.from(result);
1015
+ }
999
1016
 
1000
1017
  class RXAImpl {
1001
1018
  _buffer;
@@ -1023,7 +1040,7 @@ async function archive(files) {
1023
1040
  };
1024
1041
  });
1025
1042
  const tarBuffer = await packTar(entries);
1026
- const gzipBuffer = await gzipAsync(Buffer.from(tarBuffer));
1043
+ const gzipBuffer = await gzipCompress(new Uint8Array(tarBuffer));
1027
1044
  return new RXAImpl(gzipBuffer);
1028
1045
  }
1029
1046
  // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/external.js
@@ -1283,7 +1300,7 @@ __export(exports_core2, {
1283
1300
  safeDecode: () => safeDecode,
1284
1301
  registry: () => registry,
1285
1302
  regexes: () => exports_regexes,
1286
- process: () => process2,
1303
+ process: () => process,
1287
1304
  prettifyError: () => prettifyError,
1288
1305
  parseAsync: () => parseAsync,
1289
1306
  parse: () => parse,
@@ -11747,7 +11764,7 @@ function initializeContext(params) {
11747
11764
  external: params?.external ?? undefined
11748
11765
  };
11749
11766
  }
11750
- function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11767
+ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
11751
11768
  var _a2;
11752
11769
  const def = schema._zod.def;
11753
11770
  const seen = ctx.seen.get(schema);
@@ -11784,7 +11801,7 @@ function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11784
11801
  if (parent) {
11785
11802
  if (!result.ref)
11786
11803
  result.ref = parent;
11787
- process2(parent, ctx, params);
11804
+ process(parent, ctx, params);
11788
11805
  ctx.seen.get(parent).isParent = true;
11789
11806
  }
11790
11807
  }
@@ -12060,14 +12077,14 @@ function isTransforming(_schema, _ctx) {
12060
12077
  }
12061
12078
  var createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
12062
12079
  const ctx = initializeContext({ ...params, processors });
12063
- process2(schema, ctx);
12080
+ process(schema, ctx);
12064
12081
  extractDefs(ctx, schema);
12065
12082
  return finalize(ctx, schema);
12066
12083
  };
12067
12084
  var createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
12068
12085
  const { libraryOptions, target } = params ?? {};
12069
12086
  const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
12070
- process2(schema, ctx);
12087
+ process(schema, ctx);
12071
12088
  extractDefs(ctx, schema);
12072
12089
  return finalize(ctx, schema);
12073
12090
  };
@@ -12318,7 +12335,7 @@ var arrayProcessor = (schema, ctx, _json, params) => {
12318
12335
  if (typeof maximum === "number")
12319
12336
  json.maxItems = maximum;
12320
12337
  json.type = "array";
12321
- json.items = process2(def.element, ctx, { ...params, path: [...params.path, "items"] });
12338
+ json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
12322
12339
  };
12323
12340
  var objectProcessor = (schema, ctx, _json, params) => {
12324
12341
  const json = _json;
@@ -12327,7 +12344,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
12327
12344
  json.properties = {};
12328
12345
  const shape = def.shape;
12329
12346
  for (const key in shape) {
12330
- json.properties[key] = process2(shape[key], ctx, {
12347
+ json.properties[key] = process(shape[key], ctx, {
12331
12348
  ...params,
12332
12349
  path: [...params.path, "properties", key]
12333
12350
  });
@@ -12350,7 +12367,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
12350
12367
  if (ctx.io === "output")
12351
12368
  json.additionalProperties = false;
12352
12369
  } else if (def.catchall) {
12353
- json.additionalProperties = process2(def.catchall, ctx, {
12370
+ json.additionalProperties = process(def.catchall, ctx, {
12354
12371
  ...params,
12355
12372
  path: [...params.path, "additionalProperties"]
12356
12373
  });
@@ -12359,7 +12376,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
12359
12376
  var unionProcessor = (schema, ctx, json, params) => {
12360
12377
  const def = schema._zod.def;
12361
12378
  const isExclusive = def.inclusive === false;
12362
- const options = def.options.map((x, i) => process2(x, ctx, {
12379
+ const options = def.options.map((x, i) => process(x, ctx, {
12363
12380
  ...params,
12364
12381
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
12365
12382
  }));
@@ -12371,11 +12388,11 @@ var unionProcessor = (schema, ctx, json, params) => {
12371
12388
  };
12372
12389
  var intersectionProcessor = (schema, ctx, json, params) => {
12373
12390
  const def = schema._zod.def;
12374
- const a = process2(def.left, ctx, {
12391
+ const a = process(def.left, ctx, {
12375
12392
  ...params,
12376
12393
  path: [...params.path, "allOf", 0]
12377
12394
  });
12378
- const b = process2(def.right, ctx, {
12395
+ const b = process(def.right, ctx, {
12379
12396
  ...params,
12380
12397
  path: [...params.path, "allOf", 1]
12381
12398
  });
@@ -12392,11 +12409,11 @@ var tupleProcessor = (schema, ctx, _json, params) => {
12392
12409
  json.type = "array";
12393
12410
  const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
12394
12411
  const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
12395
- const prefixItems = def.items.map((x, i) => process2(x, ctx, {
12412
+ const prefixItems = def.items.map((x, i) => process(x, ctx, {
12396
12413
  ...params,
12397
12414
  path: [...params.path, prefixPath, i]
12398
12415
  }));
12399
- const rest = def.rest ? process2(def.rest, ctx, {
12416
+ const rest = def.rest ? process(def.rest, ctx, {
12400
12417
  ...params,
12401
12418
  path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
12402
12419
  }) : null;
@@ -12436,7 +12453,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
12436
12453
  const keyBag = keyType._zod.bag;
12437
12454
  const patterns = keyBag?.patterns;
12438
12455
  if (def.mode === "loose" && patterns && patterns.size > 0) {
12439
- const valueSchema = process2(def.valueType, ctx, {
12456
+ const valueSchema = process(def.valueType, ctx, {
12440
12457
  ...params,
12441
12458
  path: [...params.path, "patternProperties", "*"]
12442
12459
  });
@@ -12446,12 +12463,12 @@ var recordProcessor = (schema, ctx, _json, params) => {
12446
12463
  }
12447
12464
  } else {
12448
12465
  if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
12449
- json.propertyNames = process2(def.keyType, ctx, {
12466
+ json.propertyNames = process(def.keyType, ctx, {
12450
12467
  ...params,
12451
12468
  path: [...params.path, "propertyNames"]
12452
12469
  });
12453
12470
  }
12454
- json.additionalProperties = process2(def.valueType, ctx, {
12471
+ json.additionalProperties = process(def.valueType, ctx, {
12455
12472
  ...params,
12456
12473
  path: [...params.path, "additionalProperties"]
12457
12474
  });
@@ -12466,7 +12483,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
12466
12483
  };
12467
12484
  var nullableProcessor = (schema, ctx, json, params) => {
12468
12485
  const def = schema._zod.def;
12469
- const inner = process2(def.innerType, ctx, params);
12486
+ const inner = process(def.innerType, ctx, params);
12470
12487
  const seen = ctx.seen.get(schema);
12471
12488
  if (ctx.target === "openapi-3.0") {
12472
12489
  seen.ref = def.innerType;
@@ -12477,20 +12494,20 @@ var nullableProcessor = (schema, ctx, json, params) => {
12477
12494
  };
12478
12495
  var nonoptionalProcessor = (schema, ctx, _json, params) => {
12479
12496
  const def = schema._zod.def;
12480
- process2(def.innerType, ctx, params);
12497
+ process(def.innerType, ctx, params);
12481
12498
  const seen = ctx.seen.get(schema);
12482
12499
  seen.ref = def.innerType;
12483
12500
  };
12484
12501
  var defaultProcessor = (schema, ctx, json, params) => {
12485
12502
  const def = schema._zod.def;
12486
- process2(def.innerType, ctx, params);
12503
+ process(def.innerType, ctx, params);
12487
12504
  const seen = ctx.seen.get(schema);
12488
12505
  seen.ref = def.innerType;
12489
12506
  json.default = JSON.parse(JSON.stringify(def.defaultValue));
12490
12507
  };
12491
12508
  var prefaultProcessor = (schema, ctx, json, params) => {
12492
12509
  const def = schema._zod.def;
12493
- process2(def.innerType, ctx, params);
12510
+ process(def.innerType, ctx, params);
12494
12511
  const seen = ctx.seen.get(schema);
12495
12512
  seen.ref = def.innerType;
12496
12513
  if (ctx.io === "input")
@@ -12498,7 +12515,7 @@ var prefaultProcessor = (schema, ctx, json, params) => {
12498
12515
  };
12499
12516
  var catchProcessor = (schema, ctx, json, params) => {
12500
12517
  const def = schema._zod.def;
12501
- process2(def.innerType, ctx, params);
12518
+ process(def.innerType, ctx, params);
12502
12519
  const seen = ctx.seen.get(schema);
12503
12520
  seen.ref = def.innerType;
12504
12521
  let catchValue;
@@ -12512,32 +12529,32 @@ var catchProcessor = (schema, ctx, json, params) => {
12512
12529
  var pipeProcessor = (schema, ctx, _json, params) => {
12513
12530
  const def = schema._zod.def;
12514
12531
  const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
12515
- process2(innerType, ctx, params);
12532
+ process(innerType, ctx, params);
12516
12533
  const seen = ctx.seen.get(schema);
12517
12534
  seen.ref = innerType;
12518
12535
  };
12519
12536
  var readonlyProcessor = (schema, ctx, json, params) => {
12520
12537
  const def = schema._zod.def;
12521
- process2(def.innerType, ctx, params);
12538
+ process(def.innerType, ctx, params);
12522
12539
  const seen = ctx.seen.get(schema);
12523
12540
  seen.ref = def.innerType;
12524
12541
  json.readOnly = true;
12525
12542
  };
12526
12543
  var promiseProcessor = (schema, ctx, _json, params) => {
12527
12544
  const def = schema._zod.def;
12528
- process2(def.innerType, ctx, params);
12545
+ process(def.innerType, ctx, params);
12529
12546
  const seen = ctx.seen.get(schema);
12530
12547
  seen.ref = def.innerType;
12531
12548
  };
12532
12549
  var optionalProcessor = (schema, ctx, _json, params) => {
12533
12550
  const def = schema._zod.def;
12534
- process2(def.innerType, ctx, params);
12551
+ process(def.innerType, ctx, params);
12535
12552
  const seen = ctx.seen.get(schema);
12536
12553
  seen.ref = def.innerType;
12537
12554
  };
12538
12555
  var lazyProcessor = (schema, ctx, _json, params) => {
12539
12556
  const innerType = schema._zod.innerType;
12540
- process2(innerType, ctx, params);
12557
+ process(innerType, ctx, params);
12541
12558
  const seen = ctx.seen.get(schema);
12542
12559
  seen.ref = innerType;
12543
12560
  };
@@ -12589,7 +12606,7 @@ function toJSONSchema(input, params) {
12589
12606
  const defs = {};
12590
12607
  for (const entry of registry2._idmap.entries()) {
12591
12608
  const [_, schema] = entry;
12592
- process2(schema, ctx2);
12609
+ process(schema, ctx2);
12593
12610
  }
12594
12611
  const schemas = {};
12595
12612
  const external = {
@@ -12612,7 +12629,7 @@ function toJSONSchema(input, params) {
12612
12629
  return { schemas };
12613
12630
  }
12614
12631
  const ctx = initializeContext({ ...params, processors: allProcessors });
12615
- process2(input, ctx);
12632
+ process(input, ctx);
12616
12633
  extractDefs(ctx, input);
12617
12634
  return finalize(ctx, input);
12618
12635
  }
@@ -12658,7 +12675,7 @@ class JSONSchemaGenerator {
12658
12675
  });
12659
12676
  }
12660
12677
  process(schema, _params = { path: [], schemaPath: [] }) {
12661
- return process2(schema, this.ctx, _params);
12678
+ return process(schema, this.ctx, _params);
12662
12679
  }
12663
12680
  emit(schema, _params) {
12664
12681
  if (_params) {
@@ -14634,12 +14651,31 @@ function define(input) {
14634
14651
  return rxd;
14635
14652
  }
14636
14653
  // src/model/extract.ts
14637
- import { promisify as promisify2 } from "node:util";
14638
- import { gunzip } from "node:zlib";
14639
- var gunzipAsync = promisify2(gunzip);
14654
+ async function gzipDecompress(data) {
14655
+ const ds = new DecompressionStream("gzip");
14656
+ const writer = ds.writable.getWriter();
14657
+ writer.write(data);
14658
+ writer.close();
14659
+ const reader = ds.readable.getReader();
14660
+ const chunks = [];
14661
+ while (true) {
14662
+ const { done, value } = await reader.read();
14663
+ if (done)
14664
+ break;
14665
+ chunks.push(value);
14666
+ }
14667
+ const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
14668
+ const result = new Uint8Array(totalLength);
14669
+ let offset = 0;
14670
+ for (const chunk of chunks) {
14671
+ result.set(chunk, offset);
14672
+ offset += chunk.length;
14673
+ }
14674
+ return Buffer.from(result);
14675
+ }
14640
14676
  async function extract(rxa) {
14641
14677
  const buffer = await rxa.buffer();
14642
- const tarBuffer = await gunzipAsync(buffer);
14678
+ const tarBuffer = await gzipDecompress(new Uint8Array(buffer));
14643
14679
  const entries = await unpackTar(tarBuffer);
14644
14680
  const files = {};
14645
14681
  for (const entry of entries) {
@@ -14696,7 +14732,6 @@ function manifest(rxd) {
14696
14732
  };
14697
14733
  }
14698
14734
  // src/model/parse.ts
14699
- import { normalize } from "node:path";
14700
14735
  var MAX_LOCATOR_LENGTH = 256;
14701
14736
  var DANGEROUS_PATTERNS = /[;|&$`\n\0\r]/;
14702
14737
  function validateLocatorSecurity(locator) {
@@ -14718,8 +14753,21 @@ function validateLocatorSecurity(locator) {
14718
14753
  if (namePathPart.includes("..")) {
14719
14754
  throw new LocatorError("Path traversal detected", locator);
14720
14755
  }
14721
- const pathNormalized = normalize(decoded);
14722
- if (pathNormalized.startsWith("..") || pathNormalized.includes("/..") || pathNormalized.includes("\\..") || pathNormalized.startsWith("/") || pathNormalized.startsWith("\\")) {
14756
+ const segments = decoded.split("/");
14757
+ const stack = [];
14758
+ for (const seg of segments) {
14759
+ if (seg === "..") {
14760
+ if (stack.length > 0)
14761
+ stack.pop();
14762
+ else {
14763
+ throw new LocatorError("Path traversal detected", locator);
14764
+ }
14765
+ } else if (seg !== "." && seg !== "") {
14766
+ stack.push(seg);
14767
+ }
14768
+ }
14769
+ const pathNormalized = stack.join("/");
14770
+ if (pathNormalized.startsWith("/") || pathNormalized.startsWith("\\")) {
14723
14771
  throw new LocatorError("Path traversal detected", locator);
14724
14772
  }
14725
14773
  if (DANGEROUS_PATTERNS.test(decoded)) {
@@ -14864,15 +14912,13 @@ function generateDefinition(result) {
14864
14912
  return define(input);
14865
14913
  }
14866
14914
  // src/detector/PrototypeDetector.ts
14867
- import { basename } from "node:path";
14868
-
14869
14915
  class PrototypeDetector {
14870
14916
  name = "prototype";
14871
14917
  detect(files, source) {
14872
14918
  if (!files["prototype.json"]) {
14873
14919
  return null;
14874
14920
  }
14875
- const name = basename(source);
14921
+ const name = source.split("/").pop() ?? source;
14876
14922
  return {
14877
14923
  type: "prototype",
14878
14924
  name,
@@ -14913,15 +14959,13 @@ class ResourceJsonDetector {
14913
14959
  }
14914
14960
  }
14915
14961
  // src/detector/SkillDetector.ts
14916
- import { basename as basename2 } from "node:path";
14917
-
14918
14962
  class SkillDetector {
14919
14963
  name = "skill";
14920
14964
  detect(files, source) {
14921
14965
  if (!files["SKILL.md"]) {
14922
14966
  return null;
14923
14967
  }
14924
- const name = basename2(source);
14968
+ const name = source.split("/").pop() ?? source;
14925
14969
  const content = files["SKILL.md"].toString("utf-8");
14926
14970
  const description = this.extractDescription(content);
14927
14971
  return {
@@ -14966,101 +15010,6 @@ class TypeDetectorChain {
14966
15010
  throw new ResourceXError(`Cannot detect resource type from source: ${source}. ` + `No detector matched. ` + `Files: [${Object.keys(files).join(", ")}]`);
14967
15011
  }
14968
15012
  }
14969
- // src/loader/FolderLoader.ts
14970
- import { readdir, readFile, stat } from "node:fs/promises";
14971
- import { join, relative } from "node:path";
14972
- class FolderLoader {
14973
- async canLoad(source) {
14974
- try {
14975
- const stats = await stat(source);
14976
- if (!stats.isDirectory()) {
14977
- return false;
14978
- }
14979
- const manifestPath = join(source, "resource.json");
14980
- const manifestStats = await stat(manifestPath);
14981
- return manifestStats.isFile();
14982
- } catch {
14983
- return false;
14984
- }
14985
- }
14986
- async load(folderPath) {
14987
- const resourceJsonPath = join(folderPath, "resource.json");
14988
- let resourceJson;
14989
- try {
14990
- resourceJson = await readFile(resourceJsonPath, "utf-8");
14991
- } catch (error48) {
14992
- throw new ResourceXError(`Failed to read resource.json: ${error48 instanceof Error ? error48.message : String(error48)}`);
14993
- }
14994
- let json2;
14995
- try {
14996
- json2 = JSON.parse(resourceJson);
14997
- } catch (error48) {
14998
- throw new ResourceXError(`Invalid JSON in resource.json: ${error48 instanceof Error ? error48.message : String(error48)}`);
14999
- }
15000
- const rxd = define(json2);
15001
- const files = await this.readFolderFiles(folderPath);
15002
- if (Object.keys(files).length === 0) {
15003
- throw new ResourceXError("No content files found in resource folder");
15004
- }
15005
- const rxm = manifest(rxd);
15006
- const rxa = await archive(files);
15007
- return resource(rxm, rxa);
15008
- }
15009
- async readFolderFiles(folderPath, basePath = folderPath) {
15010
- const files = {};
15011
- const entries = await readdir(folderPath, { withFileTypes: true });
15012
- for (const entry of entries) {
15013
- const fullPath = join(folderPath, entry.name);
15014
- const relativePath = relative(basePath, fullPath);
15015
- if (relativePath === "resource.json") {
15016
- continue;
15017
- }
15018
- if (entry.isFile()) {
15019
- files[relativePath] = await readFile(fullPath);
15020
- } else if (entry.isDirectory()) {
15021
- const subFiles = await this.readFolderFiles(fullPath, basePath);
15022
- Object.assign(files, subFiles);
15023
- }
15024
- }
15025
- return files;
15026
- }
15027
- }
15028
- // src/loader/FolderSourceLoader.ts
15029
- import { readdir as readdir2, readFile as readFile2, stat as stat2 } from "node:fs/promises";
15030
- import { join as join2, relative as relative2 } from "node:path";
15031
- class FolderSourceLoader {
15032
- async canLoad(source) {
15033
- try {
15034
- const stats = await stat2(source);
15035
- return stats.isDirectory();
15036
- } catch {
15037
- return false;
15038
- }
15039
- }
15040
- async load(source) {
15041
- const canLoad = await this.canLoad(source);
15042
- if (!canLoad) {
15043
- throw new ResourceXError(`Source is not a directory: ${source}`);
15044
- }
15045
- const files = await this.readFolderFiles(source);
15046
- return { source, files };
15047
- }
15048
- async readFolderFiles(folderPath, basePath = folderPath) {
15049
- const files = {};
15050
- const entries = await readdir2(folderPath, { withFileTypes: true });
15051
- for (const entry of entries) {
15052
- const fullPath = join2(folderPath, entry.name);
15053
- const relativePath = relative2(basePath, fullPath);
15054
- if (entry.isFile()) {
15055
- files[relativePath] = await readFile2(fullPath);
15056
- } else if (entry.isDirectory()) {
15057
- const subFiles = await this.readFolderFiles(fullPath, basePath);
15058
- Object.assign(files, subFiles);
15059
- }
15060
- }
15061
- return files;
15062
- }
15063
- }
15064
15013
  // src/loader/GitHubSourceLoader.ts
15065
15014
  function parseGitHubUrl(url2) {
15066
15015
  const match = url2.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)\/(.+)$/);
@@ -15130,55 +15079,20 @@ class GitHubSourceLoader {
15130
15079
  }
15131
15080
  // src/loader/loadResource.ts
15132
15081
  async function loadResource(source, config2) {
15133
- const loader = config2?.loader ?? new FolderLoader;
15082
+ const loader = config2.loader;
15134
15083
  const canLoad = await loader.canLoad(source);
15135
15084
  if (!canLoad) {
15136
15085
  throw new ResourceXError(`Cannot load resource from: ${source}`);
15137
15086
  }
15138
15087
  return loader.load(source);
15139
15088
  }
15140
- // src/loader/NpmSourceLoader.ts
15141
- import { dirname, join as join3 } from "node:path";
15142
- import { fileURLToPath, pathToFileURL } from "node:url";
15143
- var NPM_PREFIX = "npm:";
15144
-
15145
- class NpmSourceLoader {
15146
- folder = new FolderSourceLoader;
15147
- canLoad(source) {
15148
- return source.startsWith(NPM_PREFIX);
15149
- }
15150
- async load(source) {
15151
- if (!this.canLoad(source)) {
15152
- throw new ResourceXError(`Not an npm source: ${source}`);
15153
- }
15154
- const packageName = source.slice(NPM_PREFIX.length);
15155
- if (!packageName) {
15156
- throw new ResourceXError(`Empty package name in npm source: ${source}`);
15157
- }
15158
- const packageDir = this.resolvePackageDir(packageName);
15159
- const rxs = await this.folder.load(packageDir);
15160
- return { source, files: rxs.files };
15161
- }
15162
- resolvePackageDir(packageName) {
15163
- const entry = globalThis.Bun?.main ?? process.argv[1] ?? join3(process.cwd(), "noop.js");
15164
- const parent = pathToFileURL(entry).href;
15165
- try {
15166
- const url2 = import.meta.resolve(`${packageName}/package.json`, parent);
15167
- return dirname(fileURLToPath(url2));
15168
- } catch {
15169
- throw new ResourceXError(`Cannot resolve npm package: ${packageName}`);
15170
- }
15171
- }
15172
- }
15173
15089
  // src/loader/SourceLoaderChain.ts
15174
15090
  class SourceLoaderChain {
15175
15091
  loaders = [];
15176
15092
  constructor() {}
15177
15093
  static create() {
15178
15094
  const chain = new SourceLoaderChain;
15179
- chain.loaders.push(new FolderSourceLoader);
15180
15095
  chain.loaders.push(new GitHubSourceLoader);
15181
- chain.loaders.push(new NpmSourceLoader);
15182
15096
  return chain;
15183
15097
  }
15184
15098
  register(loader) {
@@ -15314,16 +15228,17 @@ function withRegistryValidation(registry2, trustedRegistry) {
15314
15228
  var DomainValidation = RegistryValidation;
15315
15229
  var withDomainValidation = withRegistryValidation;
15316
15230
  // src/registry/store/digest.ts
15317
- import { createHash } from "node:crypto";
15318
- function computeDigest(data) {
15319
- const hash2 = createHash("sha256").update(data).digest("hex");
15320
- return `sha256:${hash2}`;
15231
+ async function computeDigest(data) {
15232
+ const hash2 = await crypto.subtle.digest("SHA-256", data);
15233
+ const hex3 = [...new Uint8Array(hash2)].map((b) => b.toString(16).padStart(2, "0")).join("");
15234
+ return `sha256:${hex3}`;
15321
15235
  }
15322
- function computeArchiveDigest(files) {
15236
+ async function computeArchiveDigest(files) {
15323
15237
  const entries = Object.keys(files).sort().map((name) => `${name}:${files[name]}`).join(`
15324
15238
  `);
15325
- const hash2 = createHash("sha256").update(entries).digest("hex");
15326
- return `sha256:${hash2}`;
15239
+ const hash2 = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(entries));
15240
+ const hex3 = [...new Uint8Array(hash2)].map((b) => b.toString(16).padStart(2, "0")).join("");
15241
+ return `sha256:${hex3}`;
15327
15242
  }
15328
15243
  function isValidDigest(digest) {
15329
15244
  return /^sha256:[a-f0-9]{64}$/.test(digest);
@@ -15372,7 +15287,7 @@ class CASRegistry {
15372
15287
  repository: storedRxm.repository
15373
15288
  },
15374
15289
  archive: {
15375
- digest: storedRxm.digest ?? computeArchiveDigest(storedRxm.files)
15290
+ digest: storedRxm.digest ?? await computeArchiveDigest(storedRxm.files)
15376
15291
  },
15377
15292
  source: {}
15378
15293
  };
@@ -15386,7 +15301,7 @@ class CASRegistry {
15386
15301
  const digest2 = await this.rxaStore.put(content);
15387
15302
  fileDigests[filename] = digest2;
15388
15303
  }
15389
- const digest = computeArchiveDigest(fileDigests);
15304
+ const digest = await computeArchiveDigest(fileDigests);
15390
15305
  const storedRxm = {
15391
15306
  registry: rxr.manifest.definition.registry,
15392
15307
  path: rxr.manifest.definition.path,
@@ -15477,137 +15392,6 @@ class CASRegistry {
15477
15392
  return this.rxaStore.put(data);
15478
15393
  }
15479
15394
  }
15480
- // src/registry/registries/LinkedRegistry.ts
15481
- import { lstat, mkdir, readdir as readdir3, readlink, rm, symlink } from "node:fs/promises";
15482
- import { join as join4, resolve as resolvePath } from "node:path";
15483
- class LinkedRegistry {
15484
- basePath;
15485
- constructor(basePath) {
15486
- this.basePath = basePath;
15487
- }
15488
- buildLinkPath(rxi) {
15489
- const registry2 = rxi.registry ?? "localhost";
15490
- const tag = rxi.tag ?? "latest";
15491
- let linkPath = join4(this.basePath, registry2);
15492
- if (rxi.path) {
15493
- linkPath = join4(linkPath, rxi.path);
15494
- }
15495
- return join4(linkPath, rxi.name, tag);
15496
- }
15497
- async isSymlink(path) {
15498
- try {
15499
- const stats = await lstat(path);
15500
- return stats.isSymbolicLink();
15501
- } catch {
15502
- return false;
15503
- }
15504
- }
15505
- async get(rxi) {
15506
- const linkPath = this.buildLinkPath(rxi);
15507
- if (!await this.isSymlink(linkPath)) {
15508
- throw new RegistryError(`Linked resource not found: ${format(rxi)}`);
15509
- }
15510
- const targetPath = await readlink(linkPath);
15511
- return loadResource(targetPath);
15512
- }
15513
- async put(_rxr) {
15514
- throw new RegistryError("LinkedRegistry does not support put(). Use link() instead.");
15515
- }
15516
- async has(rxi) {
15517
- const linkPath = this.buildLinkPath(rxi);
15518
- return this.isSymlink(linkPath);
15519
- }
15520
- async remove(rxi) {
15521
- const linkPath = this.buildLinkPath(rxi);
15522
- if (await this.isSymlink(linkPath)) {
15523
- await rm(linkPath);
15524
- }
15525
- }
15526
- async list(options) {
15527
- const { query, limit, offset = 0 } = options ?? {};
15528
- const identifiers = [];
15529
- try {
15530
- await this.scanSymlinks(this.basePath, "", identifiers);
15531
- } catch {
15532
- return [];
15533
- }
15534
- let filtered = identifiers;
15535
- if (query) {
15536
- const lowerQuery = query.toLowerCase();
15537
- filtered = identifiers.filter((rxi) => {
15538
- const searchText = `${rxi.registry ?? ""} ${rxi.path ?? ""} ${rxi.name}`.toLowerCase();
15539
- return searchText.includes(lowerQuery);
15540
- });
15541
- }
15542
- let result = filtered.slice(offset);
15543
- if (limit !== undefined) {
15544
- result = result.slice(0, limit);
15545
- }
15546
- return result;
15547
- }
15548
- async link(devPath) {
15549
- const rxr = await loadResource(devPath);
15550
- const linkPath = this.buildLinkPath(rxr.identifier);
15551
- try {
15552
- const stats = await lstat(linkPath);
15553
- if (stats.isSymbolicLink() || stats.isDirectory()) {
15554
- await rm(linkPath, { recursive: true });
15555
- }
15556
- } catch {}
15557
- const parentPath = join4(linkPath, "..");
15558
- await mkdir(parentPath, { recursive: true });
15559
- const absolutePath = resolvePath(devPath);
15560
- await symlink(absolutePath, linkPath);
15561
- return rxr.identifier;
15562
- }
15563
- async unlink(rxi) {
15564
- return this.remove(rxi);
15565
- }
15566
- async scanSymlinks(dirPath, relativePath, identifiers) {
15567
- let entries;
15568
- try {
15569
- entries = await readdir3(dirPath);
15570
- } catch {
15571
- return;
15572
- }
15573
- for (const entry of entries) {
15574
- const fullPath = join4(dirPath, entry);
15575
- const relPath = relativePath ? `${relativePath}/${entry}` : entry;
15576
- try {
15577
- const stats = await lstat(fullPath);
15578
- if (stats.isSymbolicLink()) {
15579
- const rxi = this.parsePathToRXI(relPath);
15580
- if (rxi) {
15581
- identifiers.push(rxi);
15582
- }
15583
- } else if (stats.isDirectory()) {
15584
- await this.scanSymlinks(fullPath, relPath, identifiers);
15585
- }
15586
- } catch {}
15587
- }
15588
- }
15589
- parsePathToRXI(relPath) {
15590
- const parts = relPath.split("/");
15591
- if (parts.length < 3) {
15592
- return null;
15593
- }
15594
- const tag = parts.pop();
15595
- const name = parts.pop();
15596
- const registry2 = parts.shift();
15597
- const path = parts.length > 0 ? parts.join("/") : undefined;
15598
- let locatorStr = registry2;
15599
- if (path)
15600
- locatorStr += `/${path}`;
15601
- locatorStr += `/${name}`;
15602
- if (tag !== "latest")
15603
- locatorStr += `:${tag}`;
15604
- try {
15605
- return parse5(locatorStr);
15606
- } catch {
15607
- return null;
15608
- }
15609
- }
15610
- }
15611
15395
  // src/registry/store/MemoryRXAStore.ts
15612
15396
  class MemoryRXAStore {
15613
15397
  blobs = new Map;
@@ -15619,7 +15403,7 @@ class MemoryRXAStore {
15619
15403
  return blob;
15620
15404
  }
15621
15405
  async put(data) {
15622
- const digest = computeDigest(data);
15406
+ const digest = await computeDigest(data);
15623
15407
  if (!this.blobs.has(digest)) {
15624
15408
  this.blobs.set(digest, data);
15625
15409
  }
@@ -15852,44 +15636,6 @@ var builtinTypes = [
15852
15636
  skillType,
15853
15637
  prototypeType
15854
15638
  ];
15855
- // src/type/bundler.ts
15856
- import { readFile as readFile3 } from "node:fs/promises";
15857
- import { isAbsolute, resolve } from "node:path";
15858
- async function bundleResourceType(sourcePath, basePath) {
15859
- const fullPath = isAbsolute(sourcePath) ? sourcePath : resolve(basePath ?? process.cwd(), sourcePath);
15860
- const source = await readFile3(fullPath, "utf-8");
15861
- const result = await Bun.build({
15862
- stdin: {
15863
- contents: source,
15864
- resolveDir: resolve(fullPath, ".."),
15865
- loader: "ts"
15866
- },
15867
- target: "bun",
15868
- format: "esm",
15869
- minify: false
15870
- });
15871
- if (!result.success) {
15872
- const errors3 = result.logs.map((log) => log.message).join(`
15873
- `);
15874
- throw new Error(`Failed to bundle ${sourcePath}: ${errors3}`);
15875
- }
15876
- const bundledCode = await result.outputs[0].text();
15877
- const tempModule = await import(fullPath);
15878
- const typeSource = tempModule.default;
15879
- if (!typeSource.name) {
15880
- throw new Error(`Resource type at ${sourcePath} must have a name`);
15881
- }
15882
- if (typeof typeSource.resolve !== "function") {
15883
- throw new Error(`Resource type at ${sourcePath} must have a resolve function`);
15884
- }
15885
- return {
15886
- name: typeSource.name,
15887
- aliases: typeSource.aliases,
15888
- description: typeSource.description ?? "",
15889
- schema: typeSource.schema,
15890
- code: bundledCode
15891
- };
15892
- }
15893
15639
  // src/type/errors.ts
15894
15640
  class ResourceTypeError extends ResourceXError {
15895
15641
  constructor(message) {
@@ -15970,7 +15716,6 @@ export {
15970
15716
  discoverRegistry,
15971
15717
  define,
15972
15718
  computeDigest,
15973
- bundleResourceType,
15974
15719
  builtinTypes,
15975
15720
  binaryType,
15976
15721
  archive,
@@ -15988,14 +15733,11 @@ export {
15988
15733
  MemoryRXAStore,
15989
15734
  ManifestError,
15990
15735
  LocatorError,
15991
- LinkedRegistry,
15992
15736
  GitHubSourceLoader,
15993
- FolderSourceLoader,
15994
- FolderLoader,
15995
15737
  DomainValidation,
15996
15738
  DefinitionError,
15997
15739
  ContentError,
15998
15740
  CASRegistry
15999
15741
  };
16000
15742
 
16001
- //# debugId=124BD7881166D2C664756E2164756E21
15743
+ //# debugId=72D5E1C3B1B1B3BE64756E2164756E21