@misofm/sdk 0.4.0 → 0.5.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/catalog.d.ts +4 -17
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +46 -58
- package/dist/catalog.js.map +1 -1
- package/dist/cover.d.ts +10 -0
- package/dist/cover.d.ts.map +1 -1
- package/dist/cover.js +66 -19
- package/dist/cover.js.map +1 -1
- package/dist/credits.d.ts +10 -0
- package/dist/credits.d.ts.map +1 -1
- package/dist/credits.js +149 -39
- package/dist/credits.js.map +1 -1
- package/dist/drop.d.ts +7 -0
- package/dist/drop.d.ts.map +1 -1
- package/dist/drop.js +84 -34
- package/dist/drop.js.map +1 -1
- package/dist/pressing.d.ts.map +1 -1
- package/dist/pressing.js +59 -16
- package/dist/pressing.js.map +1 -1
- package/dist/read/artist.d.ts +1 -6
- package/dist/read/artist.d.ts.map +1 -1
- package/dist/read/artist.js +39 -22
- package/dist/read/artist.js.map +1 -1
- package/dist/read/catalog.d.ts +24 -3
- package/dist/read/catalog.d.ts.map +1 -1
- package/dist/read/catalog.js +190 -89
- package/dist/read/catalog.js.map +1 -1
- package/dist/read/index.d.ts +5 -3
- package/dist/read/index.d.ts.map +1 -1
- package/dist/read/index.js +2 -2
- package/dist/read/index.js.map +1 -1
- package/dist/read/types.d.ts +12 -1
- package/dist/read/types.d.ts.map +1 -1
- package/dist/read/works.d.ts +3 -2
- package/dist/read/works.d.ts.map +1 -1
- package/dist/read/works.js +158 -48
- package/dist/read/works.js.map +1 -1
- package/package.json +1 -1
- package/src/catalog.ts +71 -77
- package/src/cover.ts +107 -26
- package/src/credits.ts +353 -89
- package/src/drop.ts +150 -40
- package/src/pressing.ts +146 -36
- package/src/read/artist.ts +73 -34
- package/src/read/catalog.ts +324 -89
- package/src/read/index.ts +23 -2
- package/src/read/types.ts +16 -2
- package/src/read/works.ts +224 -59
package/dist/read/works.js
CHANGED
|
@@ -1,67 +1,172 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
4
|
+
import { contracts, extractTypeParams2, getCompositionsByIds, } from "@misonetwork/sdk";
|
|
5
|
+
/** Resolve all work share types in one aliased GraphQL request. */
|
|
5
6
|
export async function getWorkAddressesByShareTypes(client, shareTypes, misoPackageId) {
|
|
6
7
|
const compositions = [...new Set(shareTypes.compositions)];
|
|
7
|
-
const
|
|
8
|
+
const recordings = new Set(shareTypes.recordings);
|
|
8
9
|
const out = { compositions: {}, recordings: {} };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
if (compositions.length === 0 && recordings.size === 0)
|
|
11
|
+
return out;
|
|
12
|
+
const declarations = [];
|
|
13
|
+
const selections = [];
|
|
14
|
+
const variables = {};
|
|
15
|
+
compositions.forEach((shareType, index) => {
|
|
16
|
+
const variable = `compositionType${index}`;
|
|
17
|
+
declarations.push(`$${variable}: String!`);
|
|
18
|
+
selections.push(`composition${index}: objects(first: 1, filter: { type: $${variable} }) { nodes { address } }`);
|
|
19
|
+
variables[variable] =
|
|
20
|
+
`${misoPackageId}::composition::Composition<${shareType}>`;
|
|
21
|
+
});
|
|
22
|
+
if (recordings.size > 0) {
|
|
23
|
+
declarations.push("$recordingType: String!");
|
|
24
|
+
selections.push(`recordings: objects(first: 50, filter: { type: $recordingType }) {
|
|
25
|
+
pageInfo { hasNextPage endCursor }
|
|
26
|
+
nodes { address asMoveObject { contents { type { repr } } } }
|
|
27
|
+
}`);
|
|
28
|
+
variables.recordingType = `${misoPackageId}::recording::Recording`;
|
|
29
|
+
}
|
|
30
|
+
const result = await client.query({
|
|
31
|
+
query: `query WorkAddressesByShareTypes(${declarations.join(", ")}) {
|
|
32
|
+
${selections.join("\n")}
|
|
33
|
+
}`,
|
|
34
|
+
variables,
|
|
35
|
+
});
|
|
36
|
+
if (result.errors?.length) {
|
|
37
|
+
throw new AggregateError(result.errors.map((error) => new Error(error.message)), "Work type discovery failed");
|
|
38
|
+
}
|
|
39
|
+
compositions.forEach((shareType, index) => {
|
|
40
|
+
const address = result.data?.[`composition${index}`]?.nodes[0]?.address;
|
|
24
41
|
if (address)
|
|
25
42
|
out.compositions[shareType] = address;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
query: `query RecordingsByType($type: String!) {
|
|
31
|
-
objects(filter: { type: $type }) {
|
|
32
|
-
nodes { address asMoveObject { contents { type { repr } } } }
|
|
33
|
-
}
|
|
34
|
-
}`,
|
|
35
|
-
variables: { type },
|
|
36
|
-
});
|
|
37
|
-
if (result.errors?.length)
|
|
38
|
-
throw new Error(result.errors[0].message);
|
|
39
|
-
for (const node of result.data?.objects?.nodes ?? []) {
|
|
40
|
-
const repr = node.asMoveObject?.contents?.type.repr;
|
|
43
|
+
});
|
|
44
|
+
const readRecordingPage = (page) => {
|
|
45
|
+
for (const node of page?.nodes ?? []) {
|
|
46
|
+
const repr = node.asMoveObject?.contents?.type?.repr;
|
|
41
47
|
if (!repr)
|
|
42
48
|
continue;
|
|
43
|
-
let recordingShareType;
|
|
44
49
|
try {
|
|
45
|
-
[
|
|
50
|
+
const [shareType] = extractTypeParams2(repr);
|
|
51
|
+
if (recordings.has(shareType))
|
|
52
|
+
out.recordings[shareType] = node.address;
|
|
46
53
|
}
|
|
47
54
|
catch {
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
if (recordingShareType && recordingSet.has(recordingShareType)) {
|
|
51
|
-
out.recordings[recordingShareType] = node.address;
|
|
55
|
+
// Ignore objects whose deployed type does not match the Recording ABI.
|
|
52
56
|
}
|
|
53
57
|
}
|
|
58
|
+
};
|
|
59
|
+
let page = result.data?.recordings;
|
|
60
|
+
readRecordingPage(page);
|
|
61
|
+
while (page?.pageInfo?.hasNextPage &&
|
|
62
|
+
page.pageInfo.endCursor &&
|
|
63
|
+
Object.keys(out.recordings).length < recordings.size) {
|
|
64
|
+
const next = await client.query({
|
|
65
|
+
query: `query RecordingWorkAddresses($recordingType: String!, $cursor: String!) {
|
|
66
|
+
recordings: objects(first: 50, after: $cursor, filter: { type: $recordingType }) {
|
|
67
|
+
pageInfo { hasNextPage endCursor }
|
|
68
|
+
nodes { address asMoveObject { contents { type { repr } } } }
|
|
69
|
+
}
|
|
70
|
+
}`,
|
|
71
|
+
variables: {
|
|
72
|
+
recordingType: variables.recordingType,
|
|
73
|
+
cursor: page.pageInfo.endCursor,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (next.errors?.length) {
|
|
77
|
+
throw new AggregateError(next.errors.map((error) => new Error(error.message)), "Recording type discovery failed");
|
|
78
|
+
}
|
|
79
|
+
page = next.data?.recordings;
|
|
80
|
+
readRecordingPage(page);
|
|
54
81
|
}
|
|
55
82
|
return out;
|
|
56
83
|
}
|
|
57
|
-
|
|
84
|
+
function workState(value) {
|
|
85
|
+
return value?.$kind === "Published"
|
|
86
|
+
? { type: "Published", timestampMs: Number(value.Published) }
|
|
87
|
+
: { type: "Initialized" };
|
|
88
|
+
}
|
|
89
|
+
function parseComposition(id, content) {
|
|
90
|
+
const value = contracts.composition.Composition.parse(content);
|
|
91
|
+
return {
|
|
92
|
+
id,
|
|
93
|
+
state: workState(value.state),
|
|
94
|
+
title: String(value.title),
|
|
95
|
+
royaltyRate: {
|
|
96
|
+
value: Number(Array.isArray(value.royalty_rate)
|
|
97
|
+
? value.royalty_rate[0]
|
|
98
|
+
: value.royalty_rate),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function parseRecording(id, content) {
|
|
103
|
+
const value = contracts.recording.Recording.parse(content);
|
|
104
|
+
return { id, state: workState(value.state) };
|
|
105
|
+
}
|
|
106
|
+
export function parseReleaseObject(id, content, json) {
|
|
107
|
+
const deployed = json;
|
|
108
|
+
if (deployed?.discs) {
|
|
109
|
+
const tracks = deployed.discs.flatMap((disc) => disc.tracks ?? []);
|
|
110
|
+
const publishedAt = deployed.state?.["@variant"] === "Published" ? deployed.state.pos0 : null;
|
|
111
|
+
return {
|
|
112
|
+
id,
|
|
113
|
+
state: publishedAt == null
|
|
114
|
+
? { type: "Initialized" }
|
|
115
|
+
: { type: "Published", timestampMs: Number(publishedAt) },
|
|
116
|
+
title: String(deployed.title ?? ""),
|
|
117
|
+
tracks: tracks.map((track) => ({
|
|
118
|
+
state: (track.state?.["@variant"] ?? "Unassigned"),
|
|
119
|
+
recordingId: String(track.recording_id),
|
|
120
|
+
splitBps: { value: Number(track.split_bps?.pos0 ?? track.split_bps) },
|
|
121
|
+
})),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const value = contracts.release.Release.parse(content);
|
|
125
|
+
return {
|
|
126
|
+
id,
|
|
127
|
+
state: workState(value.state),
|
|
128
|
+
title: String(value.title),
|
|
129
|
+
tracks: (value.tracks ?? []).map((track) => ({
|
|
130
|
+
state: (track.state?.$kind ?? "Unassigned"),
|
|
131
|
+
recordingId: String(track.recording_id),
|
|
132
|
+
splitBps: {
|
|
133
|
+
value: Number(Array.isArray(track.split_bps) ? track.split_bps[0] : track.split_bps),
|
|
134
|
+
},
|
|
135
|
+
})),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Fetch and parse heterogeneous works through one Core bulk request. */
|
|
58
139
|
export async function getWorksByIds(client, ids) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
140
|
+
const kinds = new Map();
|
|
141
|
+
for (const [kind, objectIds] of Object.entries(ids)) {
|
|
142
|
+
for (const objectId of objectIds) {
|
|
143
|
+
const normalized = normalizeSuiAddress(objectId);
|
|
144
|
+
const previous = kinds.get(normalized);
|
|
145
|
+
if (previous && previous !== kind) {
|
|
146
|
+
throw new Error(`Work ${normalized} was requested as both ${previous} and ${kind}`);
|
|
147
|
+
}
|
|
148
|
+
kinds.set(normalized, kind);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const out = { compositions: {}, recordings: {}, releases: {} };
|
|
152
|
+
if (kinds.size === 0)
|
|
153
|
+
return out;
|
|
154
|
+
const { objects } = await client.core.getObjects({
|
|
155
|
+
objectIds: [...kinds.keys()],
|
|
156
|
+
include: { content: true, json: true },
|
|
157
|
+
});
|
|
158
|
+
for (const object of objects) {
|
|
159
|
+
if (object instanceof Error || !object.content)
|
|
160
|
+
continue;
|
|
161
|
+
const kind = kinds.get(normalizeSuiAddress(object.objectId));
|
|
162
|
+
if (kind === "compositions")
|
|
163
|
+
out.compositions[object.objectId] = parseComposition(object.objectId, object.content);
|
|
164
|
+
else if (kind === "recordings")
|
|
165
|
+
out.recordings[object.objectId] = parseRecording(object.objectId, object.content);
|
|
166
|
+
else if (kind === "releases")
|
|
167
|
+
out.releases[object.objectId] = parseReleaseObject(object.objectId, object.content, object.json);
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
65
170
|
}
|
|
66
171
|
/**
|
|
67
172
|
* Resolve display titles for both deployed recording layouts. Older recordings
|
|
@@ -71,7 +176,10 @@ export async function getRecordingTitles(client, graphql, recordingIds, misoPack
|
|
|
71
176
|
const ids = [...new Set(recordingIds)];
|
|
72
177
|
if (ids.length === 0)
|
|
73
178
|
return {};
|
|
74
|
-
const { objects } = await client.core.getObjects({
|
|
179
|
+
const { objects } = await client.core.getObjects({
|
|
180
|
+
objectIds: ids,
|
|
181
|
+
include: { json: true },
|
|
182
|
+
});
|
|
75
183
|
const titles = {};
|
|
76
184
|
const compositionShareByRecording = {};
|
|
77
185
|
for (const object of objects) {
|
|
@@ -97,7 +205,9 @@ export async function getRecordingTitles(client, graphql, recordingIds, misoPack
|
|
|
97
205
|
const compositions = await getCompositionsByIds(client, Object.values(addresses.compositions).filter((id) => !!id));
|
|
98
206
|
for (const [recordingId, shareType] of Object.entries(compositionShareByRecording)) {
|
|
99
207
|
const compositionId = addresses.compositions[shareType];
|
|
100
|
-
const title = compositionId
|
|
208
|
+
const title = compositionId
|
|
209
|
+
? compositions[compositionId]?.title
|
|
210
|
+
: undefined;
|
|
101
211
|
if (title)
|
|
102
212
|
titles[recordingId] = title;
|
|
103
213
|
}
|
package/dist/read/works.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"works.js","sourceRoot":"","sources":["../../src/read/works.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAItC,OAAO,
|
|
1
|
+
{"version":3,"file":"works.js","sourceRoot":"","sources":["../../src/read/works.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAItC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,oBAAoB,GAKrB,MAAM,kBAAkB,CAAC;AAsB1B,mEAAmE;AACnE,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,MAAwB,EACxB,UAA0B,EAC1B,aAAqB;IAErB,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,GAAG,GAA6B,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;IAC3E,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAEnE,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,UAAU,GAAa,EAAE,CAAC;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,EACvD,aAAa,CACd,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,oBAAoB,CAC7C,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACzE,CAAC;IACF,KAAK,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CACnD,2BAA2B,CAC5B,EAAE,CAAC;QACF,MAAM,aAAa,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,aAAa;YACzB,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,KAAK;YACpC,CAAC,CAAC,SAAS,CAAC;QACd,IAAI,KAAK;YAAE,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/src/catalog.ts
CHANGED
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
import type { ClientWithCoreApi } from "@mysten/sui/client";
|
|
15
15
|
import type { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
16
16
|
import {
|
|
17
|
-
|
|
17
|
+
extractTypeParams2,
|
|
18
18
|
getOwnedRecordingAdminCaps,
|
|
19
|
-
|
|
20
|
-
getRecordingShareTypes,
|
|
19
|
+
getRecordingsByIds,
|
|
21
20
|
getReleaseById,
|
|
22
21
|
type Recording,
|
|
23
22
|
} from "@misonetwork/sdk";
|
|
23
|
+
import { getWorkAddressesByShareTypes } from "./read/works.ts";
|
|
24
24
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
getCompositionCreditsByIds,
|
|
26
|
+
getRecordingCreditsByIds,
|
|
27
27
|
type CreditView,
|
|
28
28
|
type RecordingCreditsView,
|
|
29
29
|
} from "./credits.ts";
|
|
@@ -85,51 +85,60 @@ export async function getTrackCreditsByRecordingIds(
|
|
|
85
85
|
options: GetReleaseTrackCreditsOptions,
|
|
86
86
|
): Promise<Record<string, ReleaseTrackCredits>> {
|
|
87
87
|
const recordingIds = [...new Set(recordingIdsInput)];
|
|
88
|
+
if (recordingIds.length === 0) return {};
|
|
88
89
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
90
|
+
const [recordingCreditsById, recordingObjects] = await Promise.all([
|
|
91
|
+
getRecordingCreditsByIds(
|
|
92
|
+
client,
|
|
93
|
+
recordingIds,
|
|
94
|
+
options.recordingCreditsPackageId,
|
|
95
|
+
),
|
|
96
|
+
client.core.getObjects({ objectIds: recordingIds }),
|
|
97
|
+
]);
|
|
98
|
+
const recordingReads = recordingObjects.objects.map((object, index) => {
|
|
99
|
+
const recordingId = recordingIds[index]!;
|
|
100
|
+
if (object instanceof Error) throw object;
|
|
101
|
+
const [, compositionShareType] = extractTypeParams2(object.type);
|
|
102
|
+
return {
|
|
103
|
+
recordingId,
|
|
104
|
+
recordingCredits: recordingCreditsById[recordingId] ?? null,
|
|
105
|
+
compositionShareType,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
98
108
|
|
|
99
|
-
const compositionShareTypes = [
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
107
|
-
if (!compositionId) throw new Error(`Composition not found for share type: ${shareType}`);
|
|
108
|
-
return [shareType, compositionId] as const;
|
|
109
|
-
}),
|
|
109
|
+
const compositionShareTypes = [
|
|
110
|
+
...new Set(recordingReads.map((read) => read.compositionShareType)),
|
|
111
|
+
];
|
|
112
|
+
const addresses = await getWorkAddressesByShareTypes(
|
|
113
|
+
graphqlClient,
|
|
114
|
+
{ compositions: compositionShareTypes, recordings: [] },
|
|
115
|
+
options.misoPackageId,
|
|
110
116
|
);
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
for (const shareType of compositionShareTypes) {
|
|
118
|
+
if (!addresses.compositions[shareType]) {
|
|
119
|
+
throw new Error(`Composition not found for share type: ${shareType}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const compositionIds = [
|
|
123
|
+
...new Set(
|
|
124
|
+
Object.values(addresses.compositions).filter(
|
|
125
|
+
(id): id is string => id !== undefined,
|
|
126
|
+
),
|
|
127
|
+
),
|
|
128
|
+
];
|
|
129
|
+
const compositionCreditsById = await getCompositionCreditsByIds(
|
|
130
|
+
client,
|
|
131
|
+
compositionIds,
|
|
132
|
+
options.compositionCreditsPackageId,
|
|
123
133
|
);
|
|
124
|
-
const compositionCreditsById = new Map(compositionCreditEntries);
|
|
125
134
|
|
|
126
135
|
return Object.fromEntries(
|
|
127
136
|
recordingReads.map((read) => {
|
|
128
|
-
const compositionId =
|
|
137
|
+
const compositionId = addresses.compositions[read.compositionShareType]!;
|
|
129
138
|
return [
|
|
130
139
|
read.recordingId,
|
|
131
140
|
{
|
|
132
|
-
compositionCredits: compositionCreditsById
|
|
141
|
+
compositionCredits: compositionCreditsById[compositionId] ?? [],
|
|
133
142
|
recordingCredits: read.recordingCredits ?? EMPTY_RECORDING_CREDITS,
|
|
134
143
|
},
|
|
135
144
|
];
|
|
@@ -139,9 +148,8 @@ export async function getTrackCreditsByRecordingIds(
|
|
|
139
148
|
|
|
140
149
|
export interface GetAdministeredRecordingsOptions {
|
|
141
150
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* concurrent requests as they have recordings. Defaults to 10.
|
|
151
|
+
* @deprecated Resolution is batched; this option is retained for source
|
|
152
|
+
* compatibility and no longer affects request concurrency.
|
|
145
153
|
*/
|
|
146
154
|
concurrency?: number;
|
|
147
155
|
}
|
|
@@ -149,20 +157,8 @@ export interface GetAdministeredRecordingsOptions {
|
|
|
149
157
|
/**
|
|
150
158
|
* Every `Recording` administered by `owner`.
|
|
151
159
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* The second stage needs GraphQL and is inherently one lookup per cap, because
|
|
156
|
-
* `RecordingAdminCap` carries no back-pointer to its recording — unlike
|
|
157
|
-
* `ReleaseAdminCap`, which stores `release_id` and can therefore be resolved
|
|
158
|
-
* entirely over the Core API. The caps are derived objects (recording → cap via
|
|
159
|
-
* `deriveObjectID`), and that derivation cannot be inverted, so the share type
|
|
160
|
-
* is the only link back. Adding a `recording_id: ID` field to
|
|
161
|
-
* `RecordingAdminCap` on the protocol side would make this a pure Core-API
|
|
162
|
-
* batch read and remove both the GraphQL dependency and the fan-out.
|
|
163
|
-
*
|
|
164
|
-
* Until then the lookups run concurrently in bounded batches rather than
|
|
165
|
-
* serially.
|
|
160
|
+
* Three bounded stages: list the owner's `RecordingAdminCap`s, resolve every
|
|
161
|
+
* share type in one aliased GraphQL query, then batch-fetch the recordings.
|
|
166
162
|
*/
|
|
167
163
|
export async function getAdministeredRecordings(
|
|
168
164
|
client: ClientWithCoreApi,
|
|
@@ -171,25 +167,23 @@ export async function getAdministeredRecordings(
|
|
|
171
167
|
misoPackageId: string,
|
|
172
168
|
options: GetAdministeredRecordingsOptions = {},
|
|
173
169
|
): Promise<Recording[]> {
|
|
174
|
-
|
|
170
|
+
void options;
|
|
175
171
|
const caps = await getOwnedRecordingAdminCaps(client, owner, misoPackageId);
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
return recordings;
|
|
172
|
+
if (caps.length === 0) return [];
|
|
173
|
+
const addresses = await getWorkAddressesByShareTypes(
|
|
174
|
+
graphqlClient,
|
|
175
|
+
{ compositions: [], recordings: caps.map((cap) => cap.shareType) },
|
|
176
|
+
misoPackageId,
|
|
177
|
+
);
|
|
178
|
+
const byId = await getRecordingsByIds(
|
|
179
|
+
client,
|
|
180
|
+
Object.values(addresses.recordings).filter(
|
|
181
|
+
(id): id is string => id !== undefined,
|
|
182
|
+
),
|
|
183
|
+
);
|
|
184
|
+
return caps.flatMap((cap) => {
|
|
185
|
+
const id = addresses.recordings[cap.shareType];
|
|
186
|
+
const recording = id ? byId[id] : undefined;
|
|
187
|
+
return recording ? [recording] : [];
|
|
188
|
+
});
|
|
195
189
|
}
|