tensorlake 0.5.85 → 0.5.89

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
@@ -19,7 +19,7 @@ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TI
19
19
  var init_defaults = __esm({
20
20
  "src/defaults.ts"() {
21
21
  "use strict";
22
- SDK_VERSION = "0.5.85";
22
+ SDK_VERSION = "0.5.89";
23
23
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
24
24
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
25
25
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -6513,8 +6513,9 @@ function fileEntryFromWire(entry, dirPath) {
6513
6513
  return {
6514
6514
  name: entry.name,
6515
6515
  path: prefix ? `${prefix}/${entry.name}` : entry.name,
6516
- oid: entry.oid ?? "",
6517
- mode,
6516
+ contentId: entry.oid ?? "",
6517
+ kind: mode === GIT_MODE_DIR ? "directory" : mode === GIT_MODE_SYMLINK ? "symlink" : "file",
6518
+ executable: mode === 33261,
6518
6519
  size: entry.size ?? null,
6519
6520
  isDir: mode === GIT_MODE_DIR,
6520
6521
  isSymlink: mode === GIT_MODE_SYMLINK
@@ -6768,6 +6769,26 @@ var FilesystemClient = class {
6768
6769
  created.default_branch || "main"
6769
6770
  );
6770
6771
  }
6772
+ /**
6773
+ * Fork a filesystem at its live head or an explicit retained snapshot.
6774
+ * The server shares immutable content and publishes only metadata.
6775
+ */
6776
+ async fork(name, baseFilesystem, snapshot) {
6777
+ if (!name || !baseFilesystem) {
6778
+ throw new FilesystemError(
6779
+ "fork and base filesystem names must not be empty"
6780
+ );
6781
+ }
6782
+ await callNative2(
6783
+ () => this.native.forkFilesystem(
6784
+ name,
6785
+ baseFilesystem,
6786
+ snapshot ?? null
6787
+ ),
6788
+ new FilesystemNotFoundError(baseFilesystem)
6789
+ );
6790
+ return new Filesystem(this, this.native, this.cli, name, "main");
6791
+ }
6771
6792
  /** Return a handle to an existing filesystem (verifies it exists). */
6772
6793
  async get(name) {
6773
6794
  const traced = await callNative2(
@@ -6793,7 +6814,6 @@ var FilesystemClient = class {
6793
6814
  return (page.repos ?? []).map((repo) => ({
6794
6815
  name: String(repo.name ?? ""),
6795
6816
  fullName: String(repo.full_name ?? ""),
6796
- defaultBranch: String(repo.default_branch ?? "main"),
6797
6817
  status: String(repo.status ?? ""),
6798
6818
  kind: String(repo.kind ?? FILESYSTEM_REPO_KIND)
6799
6819
  }));
@@ -6873,13 +6893,92 @@ var Filesystem = class {
6873
6893
  content: toBuffer(data)
6874
6894
  }));
6875
6895
  const resolvedMessage = message || `write ${writes.length} file(s) via SDK`;
6896
+ return await this.publishChanges(
6897
+ writes,
6898
+ deletes,
6899
+ [],
6900
+ [],
6901
+ resolvedMessage
6902
+ );
6903
+ }
6904
+ /**
6905
+ * Stream one local file directly to object storage in bounded parts.
6906
+ * This is the memory-bounded API for multi-GiB files.
6907
+ */
6908
+ async writeFileFromPath(path2, localPath, message) {
6909
+ return await this.writeFilesFromPaths(
6910
+ /* @__PURE__ */ new Map([[path2, localPath]]),
6911
+ message
6912
+ );
6913
+ }
6914
+ /**
6915
+ * Atomically publish local files without loading their complete payloads
6916
+ * into JavaScript or Rust memory.
6917
+ */
6918
+ async writeFilesFromPaths(files, message) {
6919
+ const entries = files instanceof Map ? [...files.entries()] : Object.entries(files);
6920
+ if (entries.length === 0) {
6921
+ throw new FilesystemError("nothing to write: no local files given");
6922
+ }
6923
+ const writes = entries.map(([path2, localPath]) => ({ path: path2, localPath }));
6924
+ const resolvedMessage = message || `write ${writes.length} local file(s) via SDK`;
6925
+ const branch = await this.branch();
6926
+ const traced = await callNative2(
6927
+ () => this.native.pushFilesystemPaths(
6928
+ this.name,
6929
+ writes,
6930
+ resolvedMessage,
6931
+ branch,
6932
+ randomBytes(16).toString("hex")
6933
+ ),
6934
+ new FilesystemNotFoundError(this.name)
6935
+ );
6936
+ const report = JSON.parse(traced.json);
6937
+ const versionId = String(report.version_id ?? "");
6938
+ const previousVersionId = report.previous_version_id == null ? null : String(report.previous_version_id);
6939
+ return {
6940
+ versionId,
6941
+ previousVersionId,
6942
+ created: previousVersionId !== versionId,
6943
+ message: resolvedMessage
6944
+ };
6945
+ }
6946
+ /**
6947
+ * Move a file or directory without downloading or re-uploading its bytes.
6948
+ * The source removal and destination creation publish as one atomic snapshot.
6949
+ */
6950
+ async moveFile(from, to, message) {
6951
+ return await this.publishChanges(
6952
+ [],
6953
+ [],
6954
+ [{ from, to }],
6955
+ [],
6956
+ message || `move ${from} to ${to} via SDK`
6957
+ );
6958
+ }
6959
+ /**
6960
+ * Copy a file or directory by reusing immutable content references. No
6961
+ * payload bytes traverse the client, API server, or object store.
6962
+ */
6963
+ async copyFile(from, to, message) {
6964
+ return await this.publishChanges(
6965
+ [],
6966
+ [],
6967
+ [],
6968
+ [{ from, to }],
6969
+ message || `copy ${from} to ${to} via SDK`
6970
+ );
6971
+ }
6972
+ async publishChanges(writes, deletes, moves, copies, message) {
6876
6973
  const branch = await this.branch();
6877
6974
  const traced = await callNative2(
6878
6975
  () => this.native.pushFilesystemFiles(
6879
6976
  this.name,
6880
6977
  writes,
6881
6978
  deletes,
6882
- resolvedMessage,
6979
+ moves,
6980
+ copies,
6981
+ message,
6883
6982
  branch,
6884
6983
  // One key per logical write: a retried submit reattaches to the
6885
6984
  // same durable commit job instead of double-committing.
@@ -6888,16 +6987,16 @@ var Filesystem = class {
6888
6987
  new FilesystemNotFoundError(this.name)
6889
6988
  );
6890
6989
  const report = JSON.parse(traced.json);
6990
+ const versionId = String(report.version_id ?? "");
6991
+ const previousVersionId = report.previous_version_id == null ? null : String(report.previous_version_id);
6891
6992
  return {
6892
- commit: String(report.commit ?? ""),
6893
- tree: String(report.tree ?? ""),
6894
- refName: String(report.ref_name ?? ""),
6895
- parent: null,
6896
- created: report.created === void 0 ? true : Boolean(report.created),
6897
- message: resolvedMessage
6993
+ versionId,
6994
+ previousVersionId,
6995
+ created: previousVersionId !== versionId,
6996
+ message
6898
6997
  };
6899
6998
  }
6900
- /** Delete one file. Returns the snapshot the deletion produced. */
6999
+ /** Delete one file. Returns the durable version the deletion produced. */
6901
7000
  async deleteFile(path2, message) {
6902
7001
  return await this.writeFiles(
6903
7002
  /* @__PURE__ */ new Map(),
@@ -6908,40 +7007,90 @@ var Filesystem = class {
6908
7007
  /**
6909
7008
  * Return the filesystem's current version as a snapshot.
6910
7009
  *
6911
- * Writes already create snapshots implicitly; this pins the current head
6912
- * without changing any content.
7010
+ * Writes publish durable live versions. This retains the current head
7011
+ * permanently in one metadata-only server operation without changing or
7012
+ * copying any content.
6913
7013
  */
6914
- async snapshot(message = "") {
6915
- const status = await this.status();
6916
- if (!status.headCommit) {
6917
- throw new FilesystemError(
6918
- `filesystem ${this.name} is empty: write files first`
6919
- );
6920
- }
7014
+ async snapshot(message = "snapshot via SDK") {
7015
+ const resolvedMessage = message || "snapshot via SDK";
7016
+ const traced = await callNative2(
7017
+ () => this.native.retainFilesystemSnapshot(
7018
+ this.name,
7019
+ resolvedMessage,
7020
+ randomBytes(16).toString("hex")
7021
+ ),
7022
+ new FilesystemNotFoundError(this.name)
7023
+ );
7024
+ const retained = JSON.parse(traced.json);
6921
7025
  return {
6922
- commit: status.headCommit,
6923
- tree: "",
6924
- refName: `refs/heads/${status.defaultBranch}`,
6925
- parent: null,
6926
- created: false,
6927
- message
7026
+ id: String(retained.snapshot_id ?? ""),
7027
+ message: retained.message || resolvedMessage
6928
7028
  };
6929
7029
  }
7030
+ /** List explicitly retained snapshots without reading filesystem contents. */
7031
+ async listSnapshots() {
7032
+ const traced = await callNative2(
7033
+ () => this.native.listFilesystemSnapshots(this.name),
7034
+ new FilesystemNotFoundError(this.name)
7035
+ );
7036
+ const payload = JSON.parse(traced.json);
7037
+ return (payload.snapshots ?? []).map((snapshot) => ({
7038
+ id: String(snapshot.snapshot_id ?? ""),
7039
+ createdAt: new Date(Number(snapshot.created_at_ms ?? 0)),
7040
+ message: String(snapshot.message ?? "")
7041
+ }));
7042
+ }
7043
+ /** Delete one permanent retention point; shared/head-reachable bytes remain. */
7044
+ async deleteSnapshot(snapshot) {
7045
+ await callNative2(
7046
+ () => this.native.deleteFilesystemSnapshot(this.name, snapshot),
7047
+ new FilesystemNotFoundError(this.name)
7048
+ );
7049
+ }
6930
7050
  // -- reads --------------------------------------------------------------------
6931
7051
  /**
6932
- * Read a file's bytes at `version` (branch, ref, or snapshot commit;
6933
- * defaults to the filesystem's default branch).
7052
+ * Read a file's bytes at `version` (the current `main` head or a retained
7053
+ * snapshot id; defaults to the filesystem's current head).
6934
7054
  */
6935
7055
  async readFile(path2, version) {
7056
+ return (await this.readFileWithMetadata(path2, { version })).data;
7057
+ }
7058
+ /**
7059
+ * Read bytes and immutable metadata in one request. A range is executed by
7060
+ * Artifact Storage, so callers never download the unrequested remainder.
7061
+ */
7062
+ async readFileWithMetadata(path2, options = {}) {
6936
7063
  if (trimSlashes(path2) === "") {
6937
7064
  throw new FilesystemError("file path must not be empty");
6938
7065
  }
6939
- const resolvedVersion = version || await this.branch();
7066
+ const range = options.range;
7067
+ if (range !== void 0 && (!Number.isSafeInteger(range.offset) || range.offset < 0 || !Number.isSafeInteger(range.length) || range.length <= 0)) {
7068
+ throw new FilesystemError(
7069
+ "range requires a non-negative integer offset and positive integer length"
7070
+ );
7071
+ }
7072
+ const resolvedVersion = options.version || await this.branch();
6940
7073
  const traced = await callNative2(
6941
- () => this.native.readFilesystemFile(this.name, path2, resolvedVersion),
7074
+ () => this.native.readFilesystemFile(
7075
+ this.name,
7076
+ path2,
7077
+ resolvedVersion,
7078
+ range?.offset,
7079
+ range?.length
7080
+ ),
6942
7081
  new FileNotFoundInFilesystemError(this.name, path2)
6943
7082
  );
6944
- return new Uint8Array(traced.data);
7083
+ const fullSize = traced.fullSize;
7084
+ if (!traced.contentId || fullSize === void 0 || !Number.isSafeInteger(fullSize) || fullSize < 0 || traced.data.byteLength > fullSize) {
7085
+ throw new FilesystemError(
7086
+ "filesystem read response omitted content identity or total size"
7087
+ );
7088
+ }
7089
+ return {
7090
+ data: new Uint8Array(traced.data),
7091
+ contentId: traced.contentId,
7092
+ size: fullSize
7093
+ };
6945
7094
  }
6946
7095
  /** Read a file as UTF-8 text at `version`. Throws on non-UTF-8 content. */
6947
7096
  async readText(path2, version) {
@@ -6960,7 +7109,7 @@ var Filesystem = class {
6960
7109
  return (page.entries ?? []).map((entry) => fileEntryFromWire(entry, dirPath));
6961
7110
  }
6962
7111
  // -- status -------------------------------------------------------------------
6963
- /** Remote status: identity plus the current head snapshot. */
7112
+ /** Remote status: identity plus the current native version. */
6964
7113
  async status() {
6965
7114
  const metaTraced = await callNative2(
6966
7115
  () => this.native.filesystemMeta(this.name),
@@ -6969,14 +7118,14 @@ var Filesystem = class {
6969
7118
  const meta = JSON.parse(metaTraced.json);
6970
7119
  const defaultBranch = String(meta.default_branch || "main");
6971
7120
  this.defaultBranch = defaultBranch;
6972
- let headCommit = null;
7121
+ let versionId = null;
6973
7122
  let generation = null;
6974
7123
  try {
6975
7124
  const refTraced = await callNative2(
6976
7125
  () => this.native.filesystemRefStatus(this.name, defaultBranch)
6977
7126
  );
6978
7127
  const ref = JSON.parse(refTraced.json);
6979
- headCommit = ref.resolved_commit || ref.oid || null;
7128
+ versionId = ref.resolved_commit || ref.oid || null;
6980
7129
  generation = typeof ref.generation === "number" ? ref.generation : null;
6981
7130
  } catch (error) {
6982
7131
  if (!(error instanceof FilesystemAPIError) || error.statusCode !== 404) {
@@ -6986,8 +7135,7 @@ var Filesystem = class {
6986
7135
  return {
6987
7136
  name: this.name,
6988
7137
  status: String(meta.status ?? ""),
6989
- defaultBranch,
6990
- headCommit,
7138
+ versionId,
6991
7139
  generation
6992
7140
  };
6993
7141
  }