@misonetwork/sdk 0.3.1 → 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.
Files changed (60) hide show
  1. package/README.md +97 -503
  2. package/dist/client.d.ts +6 -55
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +7 -52
  5. package/dist/client.js.map +1 -1
  6. package/dist/contracts/miso/release.d.ts +34 -31
  7. package/dist/contracts/miso/release.d.ts.map +1 -1
  8. package/dist/contracts/miso/release.js +32 -29
  9. package/dist/contracts/miso/release.js.map +1 -1
  10. package/dist/contracts/miso/track.d.ts +66 -22
  11. package/dist/contracts/miso/track.d.ts.map +1 -1
  12. package/dist/contracts/miso/track.js +65 -20
  13. package/dist/contracts/miso/track.js.map +1 -1
  14. package/dist/contracts/utils/index.d.ts +44 -0
  15. package/dist/contracts/utils/index.d.ts.map +1 -1
  16. package/dist/contracts/utils/index.js +104 -2
  17. package/dist/contracts/utils/index.js.map +1 -1
  18. package/dist/contracts.d.ts +0 -1
  19. package/dist/contracts.d.ts.map +1 -1
  20. package/dist/contracts.js +0 -1
  21. package/dist/contracts.js.map +1 -1
  22. package/dist/internal.d.ts +0 -7
  23. package/dist/internal.d.ts.map +1 -1
  24. package/dist/internal.js +0 -22
  25. package/dist/internal.js.map +1 -1
  26. package/dist/parsers.d.ts +1 -4
  27. package/dist/parsers.d.ts.map +1 -1
  28. package/dist/parsers.js +0 -24
  29. package/dist/parsers.js.map +1 -1
  30. package/dist/queries.d.ts +31 -5
  31. package/dist/queries.d.ts.map +1 -1
  32. package/dist/queries.js +179 -56
  33. package/dist/queries.js.map +1 -1
  34. package/dist/transactions.d.ts +10 -71
  35. package/dist/transactions.d.ts.map +1 -1
  36. package/dist/transactions.js +15 -72
  37. package/dist/transactions.js.map +1 -1
  38. package/dist/types.d.ts +3 -40
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/view.d.ts +7 -7
  41. package/dist/view.d.ts.map +1 -1
  42. package/dist/view.js +9 -9
  43. package/dist/view.js.map +1 -1
  44. package/package.json +4 -4
  45. package/src/client.ts +82 -89
  46. package/src/contracts/miso/release.ts +39 -36
  47. package/src/contracts/miso/track.ts +81 -23
  48. package/src/contracts/utils/index.ts +156 -4
  49. package/src/contracts.ts +0 -1
  50. package/src/internal.ts +0 -24
  51. package/src/parsers.ts +0 -35
  52. package/src/queries.ts +357 -83
  53. package/src/transactions.ts +20 -112
  54. package/src/types.ts +3 -53
  55. package/src/view.ts +13 -13
  56. package/dist/contracts/miso/deal.d.ts +0 -184
  57. package/dist/contracts/miso/deal.d.ts.map +0 -1
  58. package/dist/contracts/miso/deal.js +0 -184
  59. package/dist/contracts/miso/deal.js.map +0 -1
  60. package/src/contracts/miso/deal.ts +0 -257
@@ -8,7 +8,7 @@ import {
8
8
  BcsEnum,
9
9
  BcsTuple,
10
10
  } from '@mysten/sui/bcs';
11
- import { normalizeSuiAddress } from '@mysten/sui/utils';
11
+ import { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';
12
12
  import { type TransactionArgument, isArgument } from '@mysten/sui/transactions';
13
13
  import { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';
14
14
 
@@ -158,10 +158,140 @@ export function normalizeMoveArguments(
158
158
  return normalizedArgs;
159
159
  }
160
160
 
161
+ /* -------------------------- Move type tags -------------------------- */
162
+
163
+ /** A type argument: a type tag string, or a BCS type whose name is a Move type. */
164
+ export type TypeArgument = string | BcsType<any>;
165
+
166
+ export interface TypeTagOptions {
167
+ package?: string;
168
+ typeArguments?: readonly TypeArgument[];
169
+ }
170
+
171
+ /**
172
+ * `typeArguments` is required when the type's name contains unfilled
173
+ * `phantom X` parameters (at any depth). Everything else — argument arity,
174
+ * position contents, and tag validity — is validated at runtime.
175
+ */
176
+ type TypeTagParams<Name extends string> = Name extends `${string}phantom ${string}`
177
+ ? [options: TypeTagOptions & { typeArguments: readonly TypeArgument[] }]
178
+ : [options?: TypeTagOptions];
179
+
180
+ type ResolveTypeTagOptions<Name extends string> = { client: ClientWithCoreApi } & (
181
+ Name extends `${string}phantom ${string}`
182
+ ? TypeTagOptions & { typeArguments: readonly TypeArgument[] }
183
+ : TypeTagOptions
184
+ );
185
+
186
+ const HAS_PHANTOM_REGEX = /phantom [A-Za-z_$][A-Za-z0-9_$]*/;
187
+
188
+ function splitTopLevelTypeArgs(inner: string): string[] {
189
+ const parts: string[] = [];
190
+ let depth = 0;
191
+ let current = '';
192
+ for (const char of inner) {
193
+ if (char === ',' && depth === 0) {
194
+ parts.push(current.trim());
195
+ current = '';
196
+ continue;
197
+ }
198
+ if (char === '<') depth++;
199
+ if (char === '>') depth--;
200
+ current += char;
201
+ }
202
+ if (current) parts.push(current.trim());
203
+ return parts;
204
+ }
205
+
206
+ function buildTypeTag(name: string, options: TypeTagOptions | undefined): string {
207
+ const lt = name.indexOf('<');
208
+ const base = lt === -1 ? name : name.slice(0, lt);
209
+
210
+ if (base.split('::').length !== 3) {
211
+ throw new Error(`${name} is not a top-level Move type`);
212
+ }
213
+
214
+ let result = name;
215
+
216
+ if (options?.typeArguments) {
217
+ const baked = lt === -1 ? [] : splitTopLevelTypeArgs(name.slice(lt + 1, -1));
218
+ const supplied = options.typeArguments.map((arg) => {
219
+ if (typeof arg === 'string') {
220
+ return arg;
221
+ }
222
+ if (arg && typeof arg.serialize === 'function' && typeof arg.name === 'string') {
223
+ return arg.name;
224
+ }
225
+ throw new Error(`Invalid type argument ${stringify(arg)}`);
226
+ });
227
+
228
+ if (supplied.length !== baked.length) {
229
+ throw new Error(
230
+ `Expected ${baked.length} type arguments for ${base}, got ${supplied.length}`,
231
+ );
232
+ }
233
+
234
+ result = supplied.length === 0 ? base : `${base}<${supplied.join(', ')}>`;
235
+ }
236
+
237
+ if (HAS_PHANTOM_REGEX.test(result)) {
238
+ throw new Error(
239
+ options?.typeArguments
240
+ ? `A type argument contains an unfilled phantom parameter in ${result}`
241
+ : `Missing type arguments for ${result}`,
242
+ );
243
+ }
244
+
245
+ if (options?.package) {
246
+ const [, ...rest] = result.split('::');
247
+ result = [options.package, ...rest].join('::');
248
+ }
249
+
250
+ // fully validate address-only tags (MVR names can't be parsed as type tags)
251
+ if (!HAS_PHANTOM_REGEX.test(result) && !/[@/]/.test(result)) {
252
+ TypeTagSerializer.parseFromStr(result);
253
+ }
254
+
255
+ return result;
256
+ }
257
+
258
+ async function resolveBuiltTypeTag(
259
+ name: string,
260
+ options: { client: ClientWithCoreApi } & TypeTagOptions,
261
+ ): Promise<string> {
262
+ const { client, ...rest } = options;
263
+ const { type } = await client.core.mvr.resolveType({
264
+ type: buildTypeTag(name, rest),
265
+ });
266
+ return normalizeStructTag(type);
267
+ }
268
+
161
269
  export class MoveStruct<
162
270
  T extends Record<string, BcsType<any>>,
163
271
  const Name extends string = string,
164
272
  > extends BcsStruct<T, Name> {
273
+ /**
274
+ * Build the type tag for this struct.
275
+ *
276
+ * `typeArguments` is the full positional list, in Move declaration order, and
277
+ * is required when the struct has unfilled phantom parameters. The result may
278
+ * contain MVR names: those are valid in transaction `typeArguments`, but for
279
+ * queries or comparisons against on-chain data use `resolveTypeTag` instead.
280
+ */
281
+ typeTag(...args: TypeTagParams<Name>): string {
282
+ return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
283
+ }
284
+
285
+ /**
286
+ * Build the type tag for this struct, then resolve any MVR names through the
287
+ * client (using its configured overrides and the MVR API) and return the
288
+ * normalized, address-only form suitable for queries and comparisons against
289
+ * on-chain data.
290
+ */
291
+ async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
292
+ return resolveBuiltTypeTag(this.name, options as { client: ClientWithCoreApi } & TypeTagOptions);
293
+ }
294
+
165
295
  async get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
166
296
  objectId,
167
297
  ...options
@@ -210,16 +340,38 @@ export class MoveStruct<
210
340
  export class MoveEnum<
211
341
  T extends Record<string, BcsType<any> | null>,
212
342
  const Name extends string,
213
- > extends BcsEnum<T, Name> {}
343
+ > extends BcsEnum<T, Name> {
344
+ /** Build the type tag for this enum. See `MoveStruct.typeTag` for semantics. */
345
+ typeTag(...args: TypeTagParams<Name>): string {
346
+ return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
347
+ }
348
+
349
+ /** Build and resolve the type tag for this enum. See `MoveStruct.resolveTypeTag`. */
350
+ async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
351
+ return resolveBuiltTypeTag(this.name, options as { client: ClientWithCoreApi } & TypeTagOptions);
352
+ }
353
+ }
214
354
 
215
355
  export class MoveTuple<
216
356
  const T extends readonly BcsType<any>[],
217
357
  const Name extends string,
218
- > extends BcsTuple<T, Name> {}
358
+ > extends BcsTuple<T, Name> {
359
+ /** Build the type tag for this struct. See `MoveStruct.typeTag` for semantics. */
360
+ typeTag(...args: TypeTagParams<Name>): string {
361
+ return buildTypeTag(this.name, args[0] as TypeTagOptions | undefined);
362
+ }
363
+
364
+ /** Build and resolve the type tag for this struct. See `MoveStruct.resolveTypeTag`. */
365
+ async resolveTypeTag(options: ResolveTypeTagOptions<Name>): Promise<string> {
366
+ return resolveBuiltTypeTag(this.name, options as { client: ClientWithCoreApi } & TypeTagOptions);
367
+ }
368
+ }
219
369
 
220
370
  function stringify(val: unknown) {
221
371
  if (typeof val === 'object') {
222
- return JSON.stringify(val, (val: unknown) => val);
372
+ return JSON.stringify(val, (_key, value) =>
373
+ typeof value === 'bigint' ? value.toString() : value,
374
+ );
223
375
  }
224
376
  if (typeof val === 'bigint') {
225
377
  return val.toString();
package/src/contracts.ts CHANGED
@@ -10,5 +10,4 @@
10
10
  export * as composition from "./contracts/miso/composition.ts";
11
11
  export * as recording from "./contracts/miso/recording.ts";
12
12
  export * as release from "./contracts/miso/release.ts";
13
- export * as deal from "./contracts/miso/deal.ts";
14
13
  export * as track from "./contracts/miso/track.ts";
package/src/internal.ts CHANGED
@@ -78,27 +78,3 @@ export function mapRelease(id: string, d: Parsed): ReleaseType {
78
78
  tracks: (d.tracks ?? []).map(mapTrack),
79
79
  };
80
80
  }
81
-
82
- /**
83
- * Maps the deployed disc-based Release JSON shape to the SDK's flat Release
84
- * view. The current protocol source stores `tracks` directly, while the
85
- * existing testnet package stores `discs`; both represent one ordered
86
- * tracklist to SDK consumers.
87
- */
88
- export function mapDiscReleaseJson(id: string, d: Parsed): ReleaseType {
89
- const tracks = (d.discs ?? []).flatMap((disc: Parsed) => disc.tracks ?? []);
90
- const publishedAt = d.state?.["@variant"] === "Published" ? d.state.pos0 : null;
91
- return {
92
- id,
93
- state:
94
- publishedAt == null
95
- ? { type: "Initialized" }
96
- : { type: "Published", timestampMs: Number(publishedAt) },
97
- title: d.title,
98
- tracks: tracks.map((track: Parsed) => ({
99
- state: (track.state?.["@variant"] ?? "Unassigned") as TrackState,
100
- recordingId: track.recording_id,
101
- splitBps: { value: Number(track.split_bps?.pos0 ?? track.split_bps) },
102
- })),
103
- };
104
- }
package/src/parsers.ts CHANGED
@@ -11,19 +11,11 @@ import {
11
11
  } from "./contracts/miso/composition.ts";
12
12
  import { RecordingPublishedEvent as RecordingPublishedEventBcs } from "./contracts/miso/recording.ts";
13
13
  import { ReleasePublishedEvent as ReleasePublishedEventBcs } from "./contracts/miso/release.ts";
14
- import {
15
- DealCreatedEvent as DealCreatedEventBcs,
16
- DealAcceptedEvent as DealAcceptedEventBcs,
17
- DealRejectedEvent as DealRejectedEventBcs,
18
- } from "./contracts/miso/deal.ts";
19
14
  import type {
20
15
  CompositionPublishedEvent,
21
16
  CompositionRoyaltySetEvent,
22
17
  RecordingPublishedEvent,
23
18
  ReleasePublishedEvent,
24
- DealCreatedEvent,
25
- DealAcceptedEvent,
26
- DealRejectedEvent,
27
19
  } from "./types.ts";
28
20
 
29
21
  // === Composition ===
@@ -51,30 +43,3 @@ export function parseReleasePublishedEvent(bytes: Uint8Array): ReleasePublishedE
51
43
  const e = ReleasePublishedEventBcs.parse(bytes);
52
44
  return { releaseId: e.release_id };
53
45
  }
54
-
55
- // === Deal ===
56
-
57
- export function parseDealCreatedEvent(bytes: Uint8Array): DealCreatedEvent {
58
- const e = DealCreatedEventBcs.parse(bytes);
59
- return {
60
- dealId: e.deal_id,
61
- releaseId: e.release_id,
62
- trackSplitBps: { value: e.track_split_bps_value },
63
- };
64
- }
65
-
66
- export function parseDealAcceptedEvent(bytes: Uint8Array): DealAcceptedEvent {
67
- const e = DealAcceptedEventBcs.parse(bytes);
68
- return {
69
- dealId: e.deal_id,
70
- releaseId: e.release_id,
71
- };
72
- }
73
-
74
- export function parseDealRejectedEvent(bytes: Uint8Array): DealRejectedEvent {
75
- const e = DealRejectedEventBcs.parse(bytes);
76
- return {
77
- dealId: e.deal_id,
78
- releaseId: e.release_id,
79
- };
80
- }