@eluvio/elv-client-js 4.2.30 → 4.2.32

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.
@@ -0,0 +1,136 @@
1
+ // Query the published content of a tenant using the Fabric content index
2
+
3
+ const {NewOpt} = require("./lib/options");
4
+
5
+ const Utility = require("./lib/Utility");
6
+
7
+ const Client = require("./lib/concerns/Client");
8
+ const ArgOutfile = require("./lib/concerns/ArgOutfile");
9
+
10
+ // Joined into a single cell so the table keeps a stable, readable width
11
+ const Join = value => Array.isArray(value) ? value.join(", ") : value;
12
+
13
+ const FlattenMap = obj =>
14
+ Object.entries(obj || {}).map(([k, v]) => `${k}=${v}`).join(", ");
15
+
16
+ class TenantContent extends Utility {
17
+ blueprint() {
18
+ return {
19
+ concerns: [Client, ArgOutfile],
20
+ options: [
21
+ NewOpt("tenantId", {
22
+ descTemplate: "Tenant to query (should start with 'iten'). Defaults to the tenant of the current user",
23
+ type: "string"
24
+ }),
25
+ NewOpt("filter", {
26
+ descTemplate: "Filter expression(s) '<field>:<comparator>:<value>', combined with AND. " +
27
+ "Reserved fields: tag, group, unique_group.id, unique_group.type, lib/library (eq only), " +
28
+ "created_block_time. Any other name is a query field - prefix with 'qf.' to disambiguate. " +
29
+ "Comparators: co (or ::), nc, eq, ne, lt, le, gt, ge. " +
30
+ "e.g. --filter 'tag:eq:elv:media:live_stream' 'qf.date:ge:2026-09-01'",
31
+ string: true,
32
+ type: "array"
33
+ }),
34
+ NewOpt("sortBy", {
35
+ descTemplate: "Query field name to sort by (not a metadata path). Only one may be given. " +
36
+ "Also restricts results to objects that have the field",
37
+ type: "string"
38
+ }),
39
+ NewOpt("sortDescending", {
40
+ descTemplate: "Sort in descending order",
41
+ type: "boolean"
42
+ }),
43
+ NewOpt("include", {
44
+ descTemplate: "Index data to return with each result: tags, groups, uniquegroups, fields, " +
45
+ "type, name, all, none. Defaults to query fields only",
46
+ string: true,
47
+ type: "array"
48
+ }),
49
+ NewOpt("select", {
50
+ descTemplate: "Metadata subtree path(s) to include in each result. If omitted, no metadata is retrieved",
51
+ string: true,
52
+ type: "array"
53
+ }),
54
+ NewOpt("remove", {
55
+ descTemplate: "Metadata subtree path(s) to omit from each result. Only has an effect with --select",
56
+ string: true,
57
+ type: "array"
58
+ }),
59
+ NewOpt("start", {
60
+ descTemplate: "Index of the first object to retrieve",
61
+ type: "number"
62
+ }),
63
+ NewOpt("limit", {
64
+ descTemplate: "Maximum number of objects to return. Fabric default 100, capped at 998",
65
+ type: "number"
66
+ })
67
+ ]
68
+ };
69
+ }
70
+
71
+ async body() {
72
+ const logger = this.logger;
73
+ const client = await this.concerns.Client.get();
74
+
75
+ const {
76
+ tenantId, filter, sortBy, sortDescending, include, select, remove, start, limit
77
+ } = this.args;
78
+
79
+ const response = await client.TenantContent({
80
+ tenantId,
81
+ filter,
82
+ sortBy,
83
+ sortDescending,
84
+ include,
85
+ select,
86
+ remove,
87
+ start,
88
+ limit
89
+ });
90
+
91
+ const versions = response.versions || [];
92
+
93
+ logger.data("versions", versions);
94
+ logger.data("paging", response.paging);
95
+ logger.log(`Found ${versions.length} object(s)`);
96
+
97
+ if(this.args.outfile) {
98
+ this.concerns.ArgOutfile.writeJson({obj: response});
99
+ return;
100
+ }
101
+
102
+ // Only show columns that at least one result actually has
103
+ const rows = versions.map(v => {
104
+ const row = {object_id: v.id, hash: v.hash};
105
+ if(v.name !== undefined) row.name = v.name;
106
+ if(v.last_modified_at !== undefined) row.last_modified_at = v.last_modified_at;
107
+ if(v.query_fields !== undefined) row.query_fields = FlattenMap(v.query_fields);
108
+ if(v.tags !== undefined) row.tags = Join(v.tags);
109
+ if(v.groups !== undefined) row.groups = Join(v.groups);
110
+ if(v.unique_groups !== undefined) row.unique_groups = FlattenMap(v.unique_groups);
111
+ if(v.error) row.error = v.error;
112
+ return row;
113
+ });
114
+
115
+ if(rows.length > 0) {
116
+ logger.logTable({list: rows});
117
+ } else {
118
+ logger.warn("No content matched the query.");
119
+ }
120
+
121
+ if(response.paging) {
122
+ const {items, limit: pageLimit, current} = response.paging;
123
+ logger.log(`Showing ${current || 0}-${(current || 0) + versions.length} of ${items} (page size ${pageLimit})`);
124
+ }
125
+ }
126
+
127
+ header() {
128
+ return `Query content for tenant ${this.args.tenantId || "of current user"}`;
129
+ }
130
+ }
131
+
132
+ if(require.main === module) {
133
+ Utility.cmdLineInvoke(TenantContent);
134
+ } else {
135
+ module.exports = TenantContent;
136
+ }