Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ jobs:
with:
node-version: '22'
- run: npm ci
- run: npm run build
- run: npm run test

- run: npm run build

- uses: oven-sh/setup-bun@v2
- run: bun run build:binary
1,171 changes: 595 additions & 576 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"access": "public"
},
"scripts": {
"build": "tsup",
"dev": "export $(grep -v '^#' .env | xargs) && tsup --watch",
"build": "tsc --noEmit && tsup",
"dev": "export $(grep -v '^#' .env | xargs) && (tsc --noEmit --watch --preserveWatchOutput & tsup --watch)",
"cli": "node dist/cli.js",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
Expand All @@ -37,8 +37,9 @@
"updatedocs": "tsx scripts/update-docs.ts",
"postinstall": "node postinstall.cjs",
"generate:registry": "tsx scripts/generate-registry.ts",
"build:binary": "npm run generate:registry && tsx scripts/build-binaries.ts",
"build:binary:current": "npm run generate:registry && bun build src/cli-binary.ts --compile --outfile=bin/tigris",
"build:binary": "npm run generate:registry && tsc --noEmit -p tsconfig.binary.json && tsx scripts/build-binaries.ts",
"build:binary:current": "npm run generate:registry && tsc --noEmit -p tsconfig.binary.json && bun build src/cli-binary.ts --compile --outfile=bin/tigris",
"dev:binary": "npm run generate:registry && tsc --noEmit --watch --preserveWatchOutput -p tsconfig.binary.json & bun build src/cli-binary.ts --compile --watch --outfile=bin/tigris",
"prepublishOnly": "npm run build",
"clean": "rm -rf dist",
"semantic-release": "semantic-release",
Expand Down Expand Up @@ -82,7 +83,7 @@
"@aws-sdk/credential-providers": "^3.1000.0",
"@smithy/shared-ini-file-loader": "^4.4.5",
"@tigrisdata/iam": "^1.3.0",
"@tigrisdata/storage": "^2.15.2",
"@tigrisdata/storage": "^2.15.5",
"axios": "^1.13.6",
"commander": "^14.0.3",
"enquirer": "^2.4.1",
Expand Down
4 changes: 4 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.yaml' {
const content: string;
export default content;
}
19 changes: 7 additions & 12 deletions src/lib/buckets/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
printFailure,
msg,
} from '../../utils/messages.js';
import { buildBucketInfo } from '../../utils/bucket-info.js';

const context = msg('buckets', 'get');

export default async function get(options: Record<string, unknown>) {
printStart(context);

const name = getOption<string>(options, ['name']);
const format = getOption<string>(options, ['format']) || 'table';

if (!name) {
printFailure(context, 'Bucket name is required');
Expand All @@ -32,20 +34,13 @@ export default async function get(options: Record<string, unknown>) {

const info = [
{ property: 'Name', value: name },
{
property: 'Snapshots Enabled',
value: data.isSnapshotEnabled ? 'Yes' : 'No',
},
{ property: 'Has Forks', value: data.hasForks ? 'Yes' : 'No' },
...(data.sourceBucketName
? [{ property: 'Source Bucket', value: data.sourceBucketName }]
: []),
...(data.sourceBucketSnapshot
? [{ property: 'Source Snapshot', value: data.sourceBucketSnapshot }]
: []),
...buildBucketInfo(data).map(({ label, value }) => ({
property: label,
value,
})),
];

const output = formatOutput(info, 'table', 'bucket', 'property', [
const output = formatOutput(info, format, 'bucket', 'property', [
{ key: 'property', header: 'Property' },
{ key: 'value', header: 'Value' },
]);
Expand Down
11 changes: 8 additions & 3 deletions src/lib/buckets/set-transition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { getOption } from '../../utils/options.js';
import { getStorageConfig } from '../../auth/s3-client.js';
import { getSelectedOrganization } from '../../auth/storage.js';
import { setBucketLifecycle } from '@tigrisdata/storage';
import {
setBucketLifecycle,
type BucketLifecycleRule,
} from '@tigrisdata/storage';
import {
printStart,
printSuccess,
Expand Down Expand Up @@ -96,10 +99,12 @@ export default async function setTransitions(options: Record<string, unknown>) {
: {}),
};

const rule = {
const rule: BucketLifecycleRule = {
...(enable ? { enabled: true } : {}),
...(disable ? { enabled: false } : {}),
...(storageClass ? { storageClass } : {}),
...(storageClass
? { storageClass: storageClass as BucketLifecycleRule['storageClass'] }
: {}),
...(days !== undefined ? { days: Number(days) } : {}),
...(date !== undefined ? { date } : {}),
};
Expand Down
43 changes: 5 additions & 38 deletions src/lib/stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
printFailure,
msg,
} from '../utils/messages.js';
import { buildBucketInfo } from '../utils/bucket-info.js';

const context = msg('stat');

Expand Down Expand Up @@ -70,44 +71,10 @@ export default async function stat(options: {
process.exit(1);
}

const info = [
{
metric: 'Number of Objects',
value: data.sizeInfo.numberOfObjects?.toString() ?? 'N/A',
},
{
metric: 'Total Size',
value:
data.sizeInfo.size !== undefined
? formatSize(data.sizeInfo.size)
: 'N/A',
},
{
metric: 'All Versions Count',
value: data.sizeInfo.numberOfObjectsAllVersions?.toString() ?? 'N/A',
},
{
metric: 'Snapshots Enabled',
value: data.isSnapshotEnabled ? 'Yes' : 'No',
},
{ metric: 'Default Tier', value: data.settings.defaultTier },
{
metric: 'Allow Object ACL',
value: data.settings.allowObjectAcl ? 'Yes' : 'No',
},
{ metric: 'Has Forks', value: data.forkInfo?.hasChildren ? 'Yes' : 'No' },
];

if (data.forkInfo?.parents?.length) {
info.push({
metric: 'Forked From',
value: data.forkInfo.parents[0].bucketName,
});
info.push({
metric: 'Fork Snapshot',
value: data.forkInfo.parents[0].snapshot,
});
}
const info = buildBucketInfo(data).map(({ label, value }) => ({
metric: label,
value,
}));

const output = formatOutput(info, format, 'bucket-info', 'info', [
{ key: 'metric', header: 'Metric' },
Expand Down
103 changes: 103 additions & 0 deletions src/utils/bucket-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import type { BucketInfoResponse } from '@tigrisdata/storage';
import { formatSize } from './format.js';

export function buildBucketInfo(data: BucketInfoResponse) {
const info: { label: string; value: string }[] = [
{
label: 'Number of Objects',
value: data.sizeInfo.numberOfObjects?.toString() ?? 'N/A',
},
{
label: 'Total Size',
value:
data.sizeInfo.size !== undefined
? formatSize(data.sizeInfo.size)
: 'N/A',
},
{
label: 'All Versions Count',
value: data.sizeInfo.numberOfObjectsAllVersions?.toString() ?? 'N/A',
},
{ label: 'Default Tier', value: data.settings.defaultTier },
{
label: 'Snapshots Enabled',
value: data.isSnapshotEnabled ? 'Yes' : 'No',
},
{
label: 'Delete Protection',
value: data.settings.deleteProtection ? 'Yes' : 'No',
},
{
label: 'Allow Object ACL',
value: data.settings.allowObjectAcl ? 'Yes' : 'No',
},
{
label: 'Custom Domain',
value: data.settings.customDomain ?? 'None',
},
{
label: 'Has Forks',
value: data.forkInfo?.hasChildren ? 'Yes' : 'No',
},
];

if (data.forkInfo?.parents?.length) {
info.push({
label: 'Forked From',
value: data.forkInfo.parents[0].bucketName,
});
info.push({
label: 'Fork Snapshot',
value: data.forkInfo.parents[0].snapshot,
});
}

if (data.settings.ttlConfig) {
info.push({
label: 'TTL',
value: data.settings.ttlConfig.enabled
? data.settings.ttlConfig.days
? `${data.settings.ttlConfig.days} days`
: (data.settings.ttlConfig.date ?? 'Enabled')
: 'Disabled',
});
}

if (data.settings.lifecycleRules?.length) {
info.push({
label: 'Lifecycle Rules',
value: data.settings.lifecycleRules
.map(
(r) =>
`${r.storageClass}${r.days ? ` after ${r.days}d` : ''}${r.enabled ? '' : ' (disabled)'}`
)
.join(', '),
});
}

if (data.settings.corsRules.length) {
Comment thread
designcode marked this conversation as resolved.
Resolved
info.push({
label: 'CORS Rules',
value: `${data.settings.corsRules.length} rule(s)`,
});
}

if (data.settings.notifications) {
info.push({
label: 'Notifications',
value:
data.settings.notifications.enabled !== false ? 'Enabled' : 'Disabled',
});
}

if (data.settings.dataMigration) {
info.push({
label: 'Data Migration',
value: data.settings.dataMigration.endpoint
? `${data.settings.dataMigration.name ?? 'N/A'} (${data.settings.dataMigration.endpoint})`
: (data.settings.dataMigration.name ?? 'Configured'),
});
}

return info;
}
5 changes: 5 additions & 0 deletions tsconfig.binary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": []
}
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"allowJs": true,
"strict": true,
"noEmit": true,
"resolveJsonModule": true,
"moduleDetection": "force"
},
"include": ["src"]
}
"include": ["src"],
"exclude": ["src/cli-binary.ts", "src/specs-embedded.ts", "src/command-registry.ts"]
}
Loading