@vryzel/file-next 0.5.2 → 0.6.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.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { b as FileSystemConfig, C as CreateFileSystemOptions, a as FileSystem, S as S3CompatibleAdapter, c as S3Key, R as Result, M as MetadataStore } from './filesystem-C0vVDtg4.cjs';
2
- export { d as CopyInput, e as CopyOutput, f as CreateNodeInput, g as Credentials, D as DeleteInput, h as DeleteNodeInput, i as DeleteOutput, E as ExistsInput, j as ExistsOutput, F as FileNode, G as GetMetadataInput, k as GetMetadataOutput, l as GetNodeInput, m as GetPathInput, n as GetPathOutput, o as GetPublicUrlInput, p as GetPublicUrlOutput, L as ListChildrenInput, q as ListChildrenOutput, r as ListInput, s as ListOutput, t as MoveInput, u as MoveNodeInput, v as MoveOutput, N as NodeKind, P as Path, w as Prefix, x as PresignedDownloadInput, y as PresignedDownloadOutput, z as PresignedUploadInput, A as PresignedUploadOutput, B as R2Config, H as ReadInput, I as ReadOutput, J as ReconcileResult, K as S3Config, O as SearchInput, Q as SetMetadataInput, V as SetMetadataOutput, W as StatInput, X as StatOutput, T as TenantId, Y as UpdateMetadataInput, U as UserId, Z as WriteInput, _ as WriteOutput, $ as andThen, a0 as asPath, a1 as asPrefix, a2 as asS3Key, a3 as asTenantId, a4 as asUserId, a5 as assertPath, a6 as assertPrefix, a7 as assertS3Key, a8 as assertTenantId, a9 as assertUserId, aa as err, ab as map, ac as mapErr, ad as ok, ae as parseFileSystemConfig, af as unwrap, ag as unwrapOr } from './filesystem-C0vVDtg4.cjs';
1
+ import { b as FileSystemConfig, C as CreateFileSystemOptions, a as FileSystem, S as S3CompatibleAdapter, c as S3Key, R as Result, M as MetadataStore } from './filesystem-CFRC-gky.cjs';
2
+ export { d as CopyInput, e as CopyOutput, f as CreateNodeInput, g as Credentials, D as DeleteInput, h as DeleteNodeInput, i as DeleteOutput, E as ExistsInput, j as ExistsOutput, F as FileNode, G as GetMetadataInput, k as GetMetadataOutput, l as GetNodeInput, m as GetPathInput, n as GetPathOutput, o as GetPublicUrlInput, p as GetPublicUrlOutput, L as ListChildrenInput, q as ListChildrenOutput, r as ListInput, s as ListOutput, t as MoveInput, u as MoveNodeInput, v as MoveOutput, N as NodeKind, P as Path, w as Prefix, x as PresignedDownloadInput, y as PresignedDownloadOutput, z as PresignedUploadInput, A as PresignedUploadOutput, B as R2Config, H as ReadInput, I as ReadOutput, J as ReconcileResult, K as S3Config, O as SearchInput, Q as SetMetadataInput, V as SetMetadataOutput, W as StatInput, X as StatOutput, T as TenantId, Y as UpdateMetadataInput, U as UserId, Z as WriteInput, _ as WriteOutput, $ as andThen, a0 as asPath, a1 as asPrefix, a2 as asS3Key, a3 as asTenantId, a4 as asUserId, a5 as assertPath, a6 as assertPrefix, a7 as assertS3Key, a8 as assertTenantId, a9 as assertUserId, aa as err, ab as map, ac as mapErr, ad as ok, ae as parseFileSystemConfig, af as unwrap, ag as unwrapOr } from './filesystem-CFRC-gky.cjs';
3
3
  import { FileSystemError } from './errors/index.cjs';
4
4
  export { FILE_SYSTEM_ERROR_CODES, FileSystemErrorCode, FileSystemErrorJson, FileSystemErrorOptions, RETRYABLE_BY_CODE, fromAws, fromPg, fromSqlite } from './errors/index.cjs';
5
5
  import { ClassValue } from 'clsx';
6
- export { A as AuthContext, w as withAuth } from './with-auth-Dtn57B_S.cjs';
6
+ export { A as AuthContext, w as withAuth } from './with-auth-UBz99KZJ.cjs';
7
7
  import 'zod';
8
8
 
9
9
  /**
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { b as FileSystemConfig, C as CreateFileSystemOptions, a as FileSystem, S as S3CompatibleAdapter, c as S3Key, R as Result, M as MetadataStore } from './filesystem-Djiiu6YU.js';
2
- export { d as CopyInput, e as CopyOutput, f as CreateNodeInput, g as Credentials, D as DeleteInput, h as DeleteNodeInput, i as DeleteOutput, E as ExistsInput, j as ExistsOutput, F as FileNode, G as GetMetadataInput, k as GetMetadataOutput, l as GetNodeInput, m as GetPathInput, n as GetPathOutput, o as GetPublicUrlInput, p as GetPublicUrlOutput, L as ListChildrenInput, q as ListChildrenOutput, r as ListInput, s as ListOutput, t as MoveInput, u as MoveNodeInput, v as MoveOutput, N as NodeKind, P as Path, w as Prefix, x as PresignedDownloadInput, y as PresignedDownloadOutput, z as PresignedUploadInput, A as PresignedUploadOutput, B as R2Config, H as ReadInput, I as ReadOutput, J as ReconcileResult, K as S3Config, O as SearchInput, Q as SetMetadataInput, V as SetMetadataOutput, W as StatInput, X as StatOutput, T as TenantId, Y as UpdateMetadataInput, U as UserId, Z as WriteInput, _ as WriteOutput, $ as andThen, a0 as asPath, a1 as asPrefix, a2 as asS3Key, a3 as asTenantId, a4 as asUserId, a5 as assertPath, a6 as assertPrefix, a7 as assertS3Key, a8 as assertTenantId, a9 as assertUserId, aa as err, ab as map, ac as mapErr, ad as ok, ae as parseFileSystemConfig, af as unwrap, ag as unwrapOr } from './filesystem-Djiiu6YU.js';
1
+ import { b as FileSystemConfig, C as CreateFileSystemOptions, a as FileSystem, S as S3CompatibleAdapter, c as S3Key, R as Result, M as MetadataStore } from './filesystem-CF4TFF58.js';
2
+ export { d as CopyInput, e as CopyOutput, f as CreateNodeInput, g as Credentials, D as DeleteInput, h as DeleteNodeInput, i as DeleteOutput, E as ExistsInput, j as ExistsOutput, F as FileNode, G as GetMetadataInput, k as GetMetadataOutput, l as GetNodeInput, m as GetPathInput, n as GetPathOutput, o as GetPublicUrlInput, p as GetPublicUrlOutput, L as ListChildrenInput, q as ListChildrenOutput, r as ListInput, s as ListOutput, t as MoveInput, u as MoveNodeInput, v as MoveOutput, N as NodeKind, P as Path, w as Prefix, x as PresignedDownloadInput, y as PresignedDownloadOutput, z as PresignedUploadInput, A as PresignedUploadOutput, B as R2Config, H as ReadInput, I as ReadOutput, J as ReconcileResult, K as S3Config, O as SearchInput, Q as SetMetadataInput, V as SetMetadataOutput, W as StatInput, X as StatOutput, T as TenantId, Y as UpdateMetadataInput, U as UserId, Z as WriteInput, _ as WriteOutput, $ as andThen, a0 as asPath, a1 as asPrefix, a2 as asS3Key, a3 as asTenantId, a4 as asUserId, a5 as assertPath, a6 as assertPrefix, a7 as assertS3Key, a8 as assertTenantId, a9 as assertUserId, aa as err, ab as map, ac as mapErr, ad as ok, ae as parseFileSystemConfig, af as unwrap, ag as unwrapOr } from './filesystem-CF4TFF58.js';
3
3
  import { FileSystemError } from './errors/index.js';
4
4
  export { FILE_SYSTEM_ERROR_CODES, FileSystemErrorCode, FileSystemErrorJson, FileSystemErrorOptions, RETRYABLE_BY_CODE, fromAws, fromPg, fromSqlite } from './errors/index.js';
5
5
  import { ClassValue } from 'clsx';
6
- export { A as AuthContext, w as withAuth } from './with-auth-OZNiZGga.js';
6
+ export { A as AuthContext, w as withAuth } from './with-auth-BvFHyioA.js';
7
7
  import 'zod';
8
8
 
9
9
  /**
package/dist/index.js CHANGED
@@ -3077,10 +3077,16 @@ var createPresignedUploadUrl = async (client, config, input) => {
3077
3077
  const cmd = new PutObjectCommand({
3078
3078
  Bucket: config.bucket,
3079
3079
  Key: input.key,
3080
- ContentType: input.contentType
3080
+ ContentType: input.contentType,
3081
+ ContentLength: input.contentLength
3081
3082
  });
3082
3083
  const url = await getSignedUrl(client, cmd, { expiresIn: input.expiresIn ?? 900 });
3083
- return ok({ url, method: "PUT" });
3084
+ const requiredHeaders = {};
3085
+ if (input.contentType) requiredHeaders["Content-Type"] = input.contentType;
3086
+ if (input.contentLength != null) {
3087
+ requiredHeaders["Content-Length"] = String(input.contentLength);
3088
+ }
3089
+ return ok({ url, method: "PUT", requiredHeaders });
3084
3090
  } catch (e) {
3085
3091
  return err(fromAws(e));
3086
3092
  }
@@ -3387,11 +3393,17 @@ function createMemoryAdapter(options = {}) {
3387
3393
  };
3388
3394
  const createPresignedUploadUrl2 = async (input) => {
3389
3395
  const expiresIn = input.expiresIn ?? 900;
3396
+ const requiredHeaders = {};
3397
+ if (input.contentType) requiredHeaders["Content-Type"] = input.contentType;
3398
+ if (input.contentLength != null) {
3399
+ requiredHeaders["Content-Length"] = String(input.contentLength);
3400
+ }
3390
3401
  return {
3391
3402
  ok: true,
3392
3403
  value: {
3393
3404
  url: `in-memory://${bucket}/${input.key}?expiresIn=${expiresIn}`,
3394
- method: "PUT"
3405
+ method: "PUT",
3406
+ requiredHeaders
3395
3407
  }
3396
3408
  };
3397
3409
  };
@@ -3620,6 +3632,7 @@ var assemble = (adapter, config, options) => {
3620
3632
  metadata: options?.store,
3621
3633
  tenantId,
3622
3634
  quotaBytes: options?.quotaBytes,
3635
+ maxBytes: options?.maxBytes,
3623
3636
  forTenant
3624
3637
  });
3625
3638
  return {
@@ -3627,6 +3640,7 @@ var assemble = (adapter, config, options) => {
3627
3640
  config,
3628
3641
  metadata: options?.store,
3629
3642
  quotaBytes: options?.quotaBytes,
3643
+ maxBytes: options?.maxBytes,
3630
3644
  forTenant
3631
3645
  };
3632
3646
  };
@@ -4476,22 +4490,22 @@ var buildInner = (Database, options) => {
4476
4490
  const stmtUpdateSelfMove = db.prepare(`
4477
4491
  UPDATE nodes
4478
4492
  SET parent_id = ?, name = ?, path = ?, updated_at = ?
4479
- WHERE id = ?
4493
+ WHERE id = ? AND tenant_id = ?
4480
4494
  `);
4481
4495
  const stmtCascadeDescendants = db.prepare(`
4482
4496
  UPDATE nodes
4483
4497
  SET path = ? || SUBSTR(path, LENGTH(?) + 1), updated_at = ?
4484
- WHERE path LIKE ? || '/%'
4498
+ WHERE tenant_id = ? AND path LIKE ? || '/%' ESCAPE '\\'
4485
4499
  `);
4486
4500
  const stmtTombstone = db.prepare(`
4487
4501
  UPDATE nodes
4488
4502
  SET deleted_at = ?, updated_at = ?
4489
- WHERE id = ?
4503
+ WHERE id = ? AND tenant_id = ?
4490
4504
  `);
4491
4505
  const stmtTombstoneSubtree = db.prepare(`
4492
4506
  UPDATE nodes
4493
4507
  SET deleted_at = ?, updated_at = ?
4494
- WHERE (id = ? OR path LIKE ? || '/%')
4508
+ WHERE tenant_id = ? AND (id = ? OR path LIKE ? || '/%' ESCAPE '\\')
4495
4509
  AND deleted_at IS NULL
4496
4510
  `);
4497
4511
  const stmtHasLiveChild = db.prepare(`
@@ -4519,7 +4533,7 @@ var buildInner = (Database, options) => {
4519
4533
  WHERE nodes_fts MATCH ?
4520
4534
  AND n.tenant_id = ?
4521
4535
  AND n.deleted_at IS NULL
4522
- AND (n.id = ? OR n.path LIKE ? || '/%')
4536
+ AND (n.id = ? OR n.path LIKE ? || '/%' ESCAPE '\\')
4523
4537
  ORDER BY bm25(nodes_fts)
4524
4538
  LIMIT ?
4525
4539
  `);
@@ -4556,6 +4570,7 @@ var buildInner = (Database, options) => {
4556
4570
  retryable: false
4557
4571
  })
4558
4572
  );
4573
+ const escapeLike = (s) => s.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
4559
4574
  return {
4560
4575
  async createNode(input) {
4561
4576
  const normalized = normalizeNodeName(input.name);
@@ -4608,7 +4623,7 @@ var buildInner = (Database, options) => {
4608
4623
  return err(
4609
4624
  new FileSystemError({
4610
4625
  code: "InternalError",
4611
- message: `createNode failed: ${e.message}`,
4626
+ message: "createNode failed",
4612
4627
  retryable: false
4613
4628
  })
4614
4629
  );
@@ -4695,14 +4710,16 @@ var buildInner = (Database, options) => {
4695
4710
  newName,
4696
4711
  newPath,
4697
4712
  nowIso(),
4698
- input.id
4713
+ input.id,
4714
+ input.tenantId
4699
4715
  );
4700
4716
  if (current.path !== newPath) {
4701
4717
  stmtCascadeDescendants.run(
4702
4718
  newPath,
4703
4719
  current.path,
4704
4720
  nowIso(),
4705
- current.path
4721
+ input.tenantId,
4722
+ escapeLike(current.path)
4706
4723
  );
4707
4724
  }
4708
4725
  });
@@ -4720,7 +4737,7 @@ var buildInner = (Database, options) => {
4720
4737
  return err(
4721
4738
  new FileSystemError({
4722
4739
  code: "InternalError",
4723
- message: `moveNode failed: ${e.message}`,
4740
+ message: "moveNode failed",
4724
4741
  retryable: false
4725
4742
  })
4726
4743
  );
@@ -4754,9 +4771,9 @@ var buildInner = (Database, options) => {
4754
4771
  }
4755
4772
  const now = nowIso();
4756
4773
  if (input.recursive || node.kind === "file") {
4757
- stmtTombstoneSubtree.run(now, now, input.id, node.path);
4774
+ stmtTombstoneSubtree.run(now, now, input.tenantId, input.id, escapeLike(node.path));
4758
4775
  } else {
4759
- stmtTombstone.run(now, now, input.id);
4776
+ stmtTombstone.run(now, now, input.id, input.tenantId);
4760
4777
  }
4761
4778
  return ok(void 0);
4762
4779
  },
@@ -4773,19 +4790,19 @@ var buildInner = (Database, options) => {
4773
4790
  })
4774
4791
  );
4775
4792
  }
4776
- const like = `${node.path}/%`;
4793
+ const like = `${escapeLike(node.path)}/%`;
4777
4794
  const files = db.prepare(
4778
4795
  `SELECT s3_key FROM nodes
4779
4796
  WHERE tenant_id = ? AND deleted_at IS NOT NULL AND kind = 'file' AND s3_key != ''
4780
- AND (id = ? OR path LIKE ?)`
4797
+ AND (id = ? OR path LIKE ? ESCAPE '\\')`
4781
4798
  ).all(input.tenantId, input.id, like);
4782
4799
  db.prepare(
4783
4800
  `DELETE FROM shares WHERE tenant_id = ? AND node_id IN (
4784
- SELECT id FROM nodes WHERE tenant_id = ? AND deleted_at IS NOT NULL AND (id = ? OR path LIKE ?)
4801
+ SELECT id FROM nodes WHERE tenant_id = ? AND deleted_at IS NOT NULL AND (id = ? OR path LIKE ? ESCAPE '\\')
4785
4802
  )`
4786
4803
  ).run(input.tenantId, input.tenantId, input.id, like);
4787
4804
  db.prepare(
4788
- `DELETE FROM nodes WHERE tenant_id = ? AND deleted_at IS NOT NULL AND (id = ? OR path LIKE ?)`
4805
+ `DELETE FROM nodes WHERE tenant_id = ? AND deleted_at IS NOT NULL AND (id = ? OR path LIKE ? ESCAPE '\\')`
4789
4806
  ).run(input.tenantId, input.id, like);
4790
4807
  return ok({ s3Keys: files.map((row) => row.s3_key) });
4791
4808
  },
@@ -4825,7 +4842,7 @@ var buildInner = (Database, options) => {
4825
4842
  ftsQuery,
4826
4843
  input.tenantId,
4827
4844
  input.parentId,
4828
- parent.path,
4845
+ escapeLike(parent.path),
4829
4846
  limit
4830
4847
  );
4831
4848
  }
@@ -5297,7 +5314,7 @@ var buildInner2 = (pg, options) => {
5297
5314
  return err(
5298
5315
  new FileSystemError({
5299
5316
  code: "InternalError",
5300
- message: `createNode failed: ${e.message}`,
5317
+ message: "createNode failed",
5301
5318
  retryable: false
5302
5319
  })
5303
5320
  );
@@ -5414,16 +5431,16 @@ var buildInner2 = (pg, options) => {
5414
5431
  await client.query(
5415
5432
  `UPDATE "${schema}".nodes
5416
5433
  SET parent_id = $1, name = $2, path = $3, updated_at = now()
5417
- WHERE id = $4`,
5418
- [input.newParentId, newName, newPath, input.id]
5434
+ WHERE id = $4 AND tenant_id = $5`,
5435
+ [input.newParentId, newName, newPath, input.id, input.tenantId]
5419
5436
  );
5420
5437
  if (current.path !== newPath) {
5421
5438
  await client.query(
5422
5439
  `UPDATE "${schema}".nodes
5423
5440
  SET path = $1 || substring(path FROM length($2) + 1),
5424
5441
  updated_at = now()
5425
- WHERE path LIKE $2 || '/%'`,
5426
- [newPath, current.path]
5442
+ WHERE tenant_id = $3 AND path LIKE $4 || '/%' ESCAPE '\\'`,
5443
+ [newPath, current.path, input.tenantId, escapeLike(current.path)]
5427
5444
  );
5428
5445
  }
5429
5446
  });
@@ -5440,7 +5457,7 @@ var buildInner2 = (pg, options) => {
5440
5457
  return err(
5441
5458
  new FileSystemError({
5442
5459
  code: "InternalError",
5443
- message: `moveNode failed: ${e.message}`,
5460
+ message: "moveNode failed",
5444
5461
  retryable: false
5445
5462
  })
5446
5463
  );
@@ -5495,17 +5512,17 @@ var buildInner2 = (pg, options) => {
5495
5512
  input.tenantId,
5496
5513
  `UPDATE "${schema}".nodes
5497
5514
  SET deleted_at = now(), updated_at = now()
5498
- WHERE (id = $1 OR path LIKE $2 || '/%')
5515
+ WHERE tenant_id = $1 AND (id = $2 OR path LIKE $3 || '/%' ESCAPE '\\')
5499
5516
  AND deleted_at IS NULL`,
5500
- [input.id, node.path]
5517
+ [input.tenantId, input.id, escapeLike(node.path)]
5501
5518
  );
5502
5519
  } else {
5503
5520
  await q(
5504
5521
  input.tenantId,
5505
5522
  `UPDATE "${schema}".nodes
5506
5523
  SET deleted_at = now(), updated_at = now()
5507
- WHERE id = $1`,
5508
- [input.id]
5524
+ WHERE id = $1 AND tenant_id = $2`,
5525
+ [input.id, input.tenantId]
5509
5526
  );
5510
5527
  }
5511
5528
  return ok(void 0);
@@ -5528,26 +5545,26 @@ var buildInner2 = (pg, options) => {
5528
5545
  })
5529
5546
  );
5530
5547
  }
5531
- const like = `${node.path}/%`;
5548
+ const like = `${escapeLike(node.path)}/%`;
5532
5549
  const files = await q(
5533
5550
  input.tenantId,
5534
5551
  `SELECT s3_key FROM "${schema}".nodes
5535
5552
  WHERE tenant_id = $1 AND deleted_at IS NOT NULL AND kind = 'file' AND s3_key <> ''
5536
- AND (id = $2 OR path LIKE $3)`,
5553
+ AND (id = $2 OR path LIKE $3 ESCAPE '\\')`,
5537
5554
  [input.tenantId, input.id, like]
5538
5555
  );
5539
5556
  await q(
5540
5557
  input.tenantId,
5541
5558
  `DELETE FROM "${schema}".shares WHERE tenant_id = $1 AND node_id IN (
5542
5559
  SELECT id FROM "${schema}".nodes
5543
- WHERE tenant_id = $1 AND deleted_at IS NOT NULL AND (id = $2 OR path LIKE $3)
5560
+ WHERE tenant_id = $1 AND deleted_at IS NOT NULL AND (id = $2 OR path LIKE $3 ESCAPE '\\')
5544
5561
  )`,
5545
5562
  [input.tenantId, input.id, like]
5546
5563
  );
5547
5564
  await q(
5548
5565
  input.tenantId,
5549
5566
  `DELETE FROM "${schema}".nodes
5550
- WHERE tenant_id = $1 AND deleted_at IS NOT NULL AND (id = $2 OR path LIKE $3)`,
5567
+ WHERE tenant_id = $1 AND deleted_at IS NOT NULL AND (id = $2 OR path LIKE $3 ESCAPE '\\')`,
5551
5568
  [input.tenantId, input.id, like]
5552
5569
  );
5553
5570
  return ok({ s3Keys: files.rows.map((row) => row.s3_key) });
@@ -5621,11 +5638,11 @@ var buildInner2 = (pg, options) => {
5621
5638
  input.tenantId,
5622
5639
  `SELECT * FROM "${schema}".nodes
5623
5640
  WHERE tenant_id = $1 AND deleted_at IS NULL
5624
- AND (id = $2 OR path LIKE $3 || '/%')
5641
+ AND (id = $2 OR path LIKE $3 || '/%' ESCAPE '\\')
5625
5642
  AND name ILIKE $4 ESCAPE '\\'
5626
5643
  ORDER BY lower(name) ASC
5627
5644
  LIMIT $5`,
5628
- [input.tenantId, input.parentId, parent.path, pattern, limit]
5645
+ [input.tenantId, input.parentId, escapeLike(parent.path), pattern, limit]
5629
5646
  );
5630
5647
  }
5631
5648
  }