@misofm/musicos 0.1.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 (103) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +75 -0
  3. package/dist/client.d.ts +309 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +216 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/contracts/musicos/composition.d.ts +195 -0
  8. package/dist/contracts/musicos/composition.d.ts.map +1 -0
  9. package/dist/contracts/musicos/composition.js +195 -0
  10. package/dist/contracts/musicos/composition.js.map +1 -0
  11. package/dist/contracts/musicos/deps/bps/bps.d.ts +17 -0
  12. package/dist/contracts/musicos/deps/bps/bps.d.ts.map +1 -0
  13. package/dist/contracts/musicos/deps/bps/bps.js +19 -0
  14. package/dist/contracts/musicos/deps/bps/bps.js.map +1 -0
  15. package/dist/contracts/musicos/recording.d.ts +238 -0
  16. package/dist/contracts/musicos/recording.d.ts.map +1 -0
  17. package/dist/contracts/musicos/recording.js +232 -0
  18. package/dist/contracts/musicos/recording.js.map +1 -0
  19. package/dist/contracts/musicos/release.d.ts +298 -0
  20. package/dist/contracts/musicos/release.d.ts.map +1 -0
  21. package/dist/contracts/musicos/release.js +298 -0
  22. package/dist/contracts/musicos/release.js.map +1 -0
  23. package/dist/contracts/musicos/track.d.ts +193 -0
  24. package/dist/contracts/musicos/track.d.ts.map +1 -0
  25. package/dist/contracts/musicos/track.js +197 -0
  26. package/dist/contracts/musicos/track.js.map +1 -0
  27. package/dist/contracts/utils/index.d.ts +104 -0
  28. package/dist/contracts/utils/index.d.ts.map +1 -0
  29. package/dist/contracts/utils/index.js +272 -0
  30. package/dist/contracts/utils/index.js.map +1 -0
  31. package/dist/contracts.d.ts +9 -0
  32. package/dist/contracts.d.ts.map +1 -0
  33. package/dist/contracts.js +14 -0
  34. package/dist/contracts.js.map +1 -0
  35. package/dist/deployments.d.ts +60 -0
  36. package/dist/deployments.d.ts.map +1 -0
  37. package/dist/deployments.js +109 -0
  38. package/dist/deployments.js.map +1 -0
  39. package/dist/events.d.ts +16 -0
  40. package/dist/events.d.ts.map +1 -0
  41. package/dist/events.js +25 -0
  42. package/dist/events.js.map +1 -0
  43. package/dist/execute.d.ts +49 -0
  44. package/dist/execute.d.ts.map +1 -0
  45. package/dist/execute.js +110 -0
  46. package/dist/execute.js.map +1 -0
  47. package/dist/index.d.ts +13 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +20 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/internal.d.ts +17 -0
  52. package/dist/internal.d.ts.map +1 -0
  53. package/dist/internal.js +46 -0
  54. package/dist/internal.js.map +1 -0
  55. package/dist/numeric.d.ts +5 -0
  56. package/dist/numeric.d.ts.map +1 -0
  57. package/dist/numeric.js +21 -0
  58. package/dist/numeric.js.map +1 -0
  59. package/dist/packages.d.ts +67 -0
  60. package/dist/packages.d.ts.map +1 -0
  61. package/dist/packages.js +85 -0
  62. package/dist/packages.js.map +1 -0
  63. package/dist/parsers.d.ts +9 -0
  64. package/dist/parsers.d.ts.map +1 -0
  65. package/dist/parsers.js +40 -0
  66. package/dist/parsers.js.map +1 -0
  67. package/dist/queries.d.ts +178 -0
  68. package/dist/queries.d.ts.map +1 -0
  69. package/dist/queries.js +611 -0
  70. package/dist/queries.js.map +1 -0
  71. package/dist/transactions.d.ts +136 -0
  72. package/dist/transactions.d.ts.map +1 -0
  73. package/dist/transactions.js +145 -0
  74. package/dist/transactions.js.map +1 -0
  75. package/dist/types.d.ts +194 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +4 -0
  78. package/dist/types.js.map +1 -0
  79. package/dist/view.d.ts +22 -0
  80. package/dist/view.d.ts.map +1 -0
  81. package/dist/view.js +42 -0
  82. package/dist/view.js.map +1 -0
  83. package/package.json +119 -0
  84. package/src/client.ts +341 -0
  85. package/src/contracts/musicos/composition.ts +280 -0
  86. package/src/contracts/musicos/deps/bps/bps.ts +22 -0
  87. package/src/contracts/musicos/recording.ts +308 -0
  88. package/src/contracts/musicos/release.ts +409 -0
  89. package/src/contracts/musicos/track.ts +255 -0
  90. package/src/contracts/utils/index.ts +428 -0
  91. package/src/contracts.ts +29 -0
  92. package/src/deployments.ts +166 -0
  93. package/src/events.ts +30 -0
  94. package/src/execute.ts +137 -0
  95. package/src/index.ts +21 -0
  96. package/src/internal.ts +78 -0
  97. package/src/numeric.ts +25 -0
  98. package/src/packages.ts +117 -0
  99. package/src/parsers.ts +66 -0
  100. package/src/queries.ts +928 -0
  101. package/src/transactions.ts +305 -0
  102. package/src/types.ts +222 -0
  103. package/src/view.ts +65 -0
package/package.json ADDED
@@ -0,0 +1,119 @@
1
+ {
2
+ "name": "@misofm/musicos",
3
+ "version": "0.1.0",
4
+ "packageManager": "bun@1.4.0",
5
+ "description": "Typed bindings, queries, event decoders, and PTB builders for the Miso object model (Composition, Recording, Release, Track) on Sui.",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/misofm/sdks.git"
10
+ },
11
+ "homepage": "https://github.com/misofm/sdks#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/misofm/sdks/issues"
14
+ },
15
+ "keywords": [
16
+ "sui",
17
+ "move",
18
+ "miso",
19
+ "music",
20
+ "blockchain",
21
+ "sdk",
22
+ "object-model",
23
+ "composition",
24
+ "recording",
25
+ "release"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "type": "module",
33
+ "sideEffects": false,
34
+ "scripts": {
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "bun test",
37
+ "docs": "typedoc",
38
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
39
+ "prepack": "rm -rf dist && tsc -p tsconfig.build.json",
40
+ "prepare": "rm -rf dist && tsc -p tsconfig.build.json --noCheck"
41
+ },
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/index.js"
46
+ },
47
+ "./client": {
48
+ "types": "./dist/client.d.ts",
49
+ "default": "./dist/client.js"
50
+ },
51
+ "./deployments": {
52
+ "types": "./dist/deployments.d.ts",
53
+ "default": "./dist/deployments.js"
54
+ },
55
+ "./queries": {
56
+ "types": "./dist/queries.d.ts",
57
+ "default": "./dist/queries.js"
58
+ },
59
+ "./transactions": {
60
+ "types": "./dist/transactions.d.ts",
61
+ "default": "./dist/transactions.js"
62
+ },
63
+ "./execute": {
64
+ "types": "./dist/execute.d.ts",
65
+ "default": "./dist/execute.js"
66
+ },
67
+ "./view": {
68
+ "types": "./dist/view.d.ts",
69
+ "default": "./dist/view.js"
70
+ },
71
+ "./types": {
72
+ "types": "./dist/types.d.ts",
73
+ "default": "./dist/types.js"
74
+ },
75
+ "./parsers": {
76
+ "types": "./dist/parsers.d.ts",
77
+ "default": "./dist/parsers.js"
78
+ },
79
+ "./events": {
80
+ "types": "./dist/events.d.ts",
81
+ "default": "./dist/events.js"
82
+ },
83
+ "./packages": {
84
+ "types": "./dist/packages.d.ts",
85
+ "default": "./dist/packages.js"
86
+ },
87
+ "./contracts": {
88
+ "types": "./dist/contracts.d.ts",
89
+ "default": "./dist/contracts.js"
90
+ },
91
+ "./contracts/*": {
92
+ "types": "./dist/contracts/*.d.ts",
93
+ "default": "./dist/contracts/*.js"
94
+ },
95
+ "./package.json": "./package.json"
96
+ },
97
+ "files": [
98
+ "dist",
99
+ "src",
100
+ "README.md",
101
+ "LICENSE",
102
+ "package.json"
103
+ ],
104
+ "dependencies": {
105
+ "@mysten/bcs": "^2.1.1"
106
+ },
107
+ "devDependencies": {
108
+ "@mysten/sui": "2.29.0",
109
+ "@types/bun": "^1.4.0",
110
+ "typedoc": "^0.28.20",
111
+ "typedoc-plugin-markdown": "^4.13.0",
112
+ "typescript": "^7.0.2"
113
+ },
114
+ "peerDependencies": {
115
+ "@mysten/sui": "2.29.0",
116
+ "typescript": "^5.7 || ^6 || ^7"
117
+ },
118
+ "main": "./dist/index.js"
119
+ }
package/src/client.ts ADDED
@@ -0,0 +1,341 @@
1
+ // Copyright (c) Miso Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type {
5
+ ClientWithCoreApi,
6
+ SuiClientRegistration,
7
+ } from "@mysten/sui/client";
8
+ import type { SuiGraphQLClient } from "@mysten/sui/graphql";
9
+ import {
10
+ getMisoDeployment,
11
+ normalizeMisoDeployment,
12
+ normalizeMisoProtocolDeployment,
13
+ protocolDeployment,
14
+ type MisoDeployment,
15
+ type MisoProtocolDeployment,
16
+ } from "./deployments.ts";
17
+ import { bindModulePackage, MisoPackageBindings, REF_RETURNING_CALLS } from "./packages.ts";
18
+ import * as parsers from "./parsers.ts";
19
+ import { eventParsers } from "./events.ts";
20
+ import * as queries from "./queries.ts";
21
+ import * as view from "./view.ts";
22
+ import type {
23
+ Composition,
24
+ CompositionAdminCap,
25
+ Recording,
26
+ RecordingAdminCap,
27
+ Release,
28
+ ReleaseAdminCap,
29
+ } from "./types.ts";
30
+
31
+ // Generated call modules (type-safe Move calls) and BCS structs.
32
+ import * as composition from "./contracts/musicos/composition.ts";
33
+ import * as recording from "./contracts/musicos/recording.ts";
34
+ import * as release from "./contracts/musicos/release.ts";
35
+ import * as track from "./contracts/musicos/track.ts";
36
+
37
+ export interface MisoOptions<Name extends string = "miso"> {
38
+ /** Name for the client extension. Defaults to "miso". */
39
+ name?: Name;
40
+ /**
41
+ * Explicit core-only deployment or complete package manifest. Omit only after
42
+ * this SDK has a verified bundled manifest for the client's network.
43
+ */
44
+ deployment?: MisoProtocolDeployment | MisoDeployment;
45
+ /** @deprecated Use `deployment`. Retained for compatibility with pre-0.4 callers. */
46
+ misoPackageId?: string;
47
+ /**
48
+ * Optional GraphQL client, required ONLY for the global type-discovery reads
49
+ * the Core API cannot express: `getCompositionByShareType`,
50
+ * `getRecordingByShareType`. Everything else — including every
51
+ * `getOwned*AdminCaps` — goes over the Core API.
52
+ */
53
+ graphqlClient?: SuiGraphQLClient;
54
+ }
55
+
56
+ function isFullDeployment(
57
+ deployment: MisoProtocolDeployment | MisoDeployment,
58
+ ): deployment is MisoDeployment {
59
+ return "musicos" in deployment;
60
+ }
61
+
62
+ /**
63
+ * Creates a Miso client extension for use with `$extend()`.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const client = new SuiGrpcClient({ network: 'testnet' })
68
+ * .$extend(miso());
69
+ * const composition = await client.miso.getCompositionById('0x...');
70
+ * ```
71
+ */
72
+ export function miso<const Name extends string = "miso">(
73
+ options: MisoOptions<Name> = {},
74
+ ): SuiClientRegistration<ClientWithCoreApi, Name, MisoProtocolClient> {
75
+ const name = (options.name ?? "miso") as Name;
76
+ return {
77
+ name,
78
+ register: (client) => {
79
+ const supplied = options.deployment;
80
+ const packageDeployment =
81
+ supplied && isFullDeployment(supplied)
82
+ ? normalizeMisoDeployment(supplied)
83
+ : !supplied && !options.misoPackageId
84
+ ? getMisoDeployment(client.network)
85
+ : undefined;
86
+ const deployment = supplied
87
+ ? isFullDeployment(supplied)
88
+ ? protocolDeployment(packageDeployment!)
89
+ : normalizeMisoProtocolDeployment(supplied)
90
+ : options.misoPackageId
91
+ ? normalizeMisoProtocolDeployment({ packageId: options.misoPackageId })
92
+ : protocolDeployment(packageDeployment!);
93
+ return new MisoProtocolClient(client, {
94
+ deployment,
95
+ packageDeployment,
96
+ graphqlClient: options.graphqlClient,
97
+ });
98
+ },
99
+ };
100
+ }
101
+
102
+ export interface MisoProtocolClientOptions {
103
+ deployment: MisoProtocolDeployment;
104
+ packageDeployment?: MisoDeployment;
105
+ graphqlClient?: SuiGraphQLClient;
106
+ }
107
+
108
+ export class MisoProtocolClient {
109
+ #client: ClientWithCoreApi;
110
+ #graphqlClient?: SuiGraphQLClient;
111
+ #deployment: MisoProtocolDeployment;
112
+ #packageDeployment?: MisoDeployment;
113
+
114
+ constructor(client: ClientWithCoreApi, options: MisoProtocolClientOptions) {
115
+ this.#client = client;
116
+ this.#graphqlClient = options.graphqlClient;
117
+ this.#deployment = normalizeMisoProtocolDeployment(options.deployment);
118
+ this.#packageDeployment = options.packageDeployment
119
+ ? normalizeMisoDeployment(options.packageDeployment)
120
+ : undefined;
121
+ }
122
+
123
+ /** The exact deployment selected for this client. */
124
+ get deployment(): MisoProtocolDeployment {
125
+ return this.#deployment;
126
+ }
127
+
128
+ /**
129
+ * Complete package-bound calls and BCS codecs, available only when `miso()`
130
+ * was given a full fresh deployment manifest.
131
+ */
132
+ get packages(): MisoPackageBindings {
133
+ if (!this.#packageDeployment) {
134
+ throw new Error(
135
+ "@misofm/musicos: full package bindings require a complete MisoDeployment. " +
136
+ "Pass the verified post-publish manifest to miso({ deployment }).",
137
+ );
138
+ }
139
+ return new MisoPackageBindings(this.#packageDeployment);
140
+ }
141
+
142
+ get #misoPackageId(): string {
143
+ return this.#deployment.packageId;
144
+ }
145
+
146
+ // === Composition ===
147
+
148
+ async getCompositionById(compositionId: string): Promise<Composition> {
149
+ return queries.getCompositionById(this.#client, compositionId);
150
+ }
151
+ async getCompositionsByIds(
152
+ ids: string[],
153
+ ): Promise<Record<string, Composition>> {
154
+ return queries.getCompositionsByIds(this.#client, ids);
155
+ }
156
+ async getWorksByIds(ids: queries.WorkIds): Promise<queries.WorksById> {
157
+ return queries.getWorksByIds(this.#client, ids);
158
+ }
159
+ async getWorkAddressesByShareTypes(
160
+ shareTypes: queries.WorkShareTypes,
161
+ ): Promise<queries.WorkAddressesByShareType> {
162
+ return queries.getWorkAddressesByShareTypes(
163
+ this.#requireGraphQL(),
164
+ shareTypes,
165
+ this.#misoPackageId,
166
+ );
167
+ }
168
+ async getCompositionShareType(compositionId: string): Promise<string> {
169
+ return queries.getCompositionShareType(this.#client, compositionId);
170
+ }
171
+ async getCompositionByShareType(shareType: string): Promise<Composition> {
172
+ return queries.getCompositionByShareType(
173
+ this.#client,
174
+ this.#requireGraphQL(),
175
+ shareType,
176
+ this.#misoPackageId,
177
+ );
178
+ }
179
+ async getCompositionAdminCapById(
180
+ adminCapId: string,
181
+ ): Promise<CompositionAdminCap> {
182
+ return queries.getCompositionAdminCapById(this.#client, adminCapId);
183
+ }
184
+ async getOwnedCompositionAdminCaps(
185
+ owner: string,
186
+ ): Promise<CompositionAdminCap[]> {
187
+ return queries.getOwnedCompositionAdminCaps(
188
+ this.#client,
189
+ owner,
190
+ this.#misoPackageId,
191
+ );
192
+ }
193
+ deriveCompositionAdminCapId(compositionId: string): string {
194
+ return queries.deriveCompositionAdminCapId(
195
+ compositionId,
196
+ this.#misoPackageId,
197
+ );
198
+ }
199
+
200
+ // === Recording ===
201
+
202
+ async getRecordingById(recordingId: string): Promise<Recording> {
203
+ return queries.getRecordingById(this.#client, recordingId);
204
+ }
205
+ async getRecordingsByIds(ids: string[]): Promise<Record<string, Recording>> {
206
+ return queries.getRecordingsByIds(this.#client, ids);
207
+ }
208
+ async getRecordingShareType(recordingId: string): Promise<string> {
209
+ return queries.getRecordingShareType(this.#client, recordingId);
210
+ }
211
+ async getRecordingByShareType(shareType: string): Promise<Recording> {
212
+ return queries.getRecordingByShareType(
213
+ this.#client,
214
+ this.#requireGraphQL(),
215
+ shareType,
216
+ this.#misoPackageId,
217
+ );
218
+ }
219
+ async getRecordingAdminCapById(
220
+ adminCapId: string,
221
+ ): Promise<RecordingAdminCap> {
222
+ return queries.getRecordingAdminCapById(this.#client, adminCapId);
223
+ }
224
+ async getOwnedRecordingAdminCaps(
225
+ owner: string,
226
+ ): Promise<RecordingAdminCap[]> {
227
+ return queries.getOwnedRecordingAdminCaps(
228
+ this.#client,
229
+ owner,
230
+ this.#misoPackageId,
231
+ );
232
+ }
233
+ deriveRecordingAdminCapId(recordingId: string): string {
234
+ return queries.deriveRecordingAdminCapId(recordingId, this.#misoPackageId);
235
+ }
236
+
237
+ // === Release ===
238
+
239
+ async getReleaseById(releaseId: string): Promise<Release> {
240
+ return queries.getReleaseById(this.#client, releaseId);
241
+ }
242
+ /** Read the shared canonical core `miso::release::ReleaseRegistry`. */
243
+ async getReleaseRegistryById(registryId: string) {
244
+ return queries.getReleaseRegistryById(this.#client, registryId);
245
+ }
246
+ async getReleasesByIds(ids: string[]): Promise<Record<string, Release>> {
247
+ return queries.getReleasesByIds(this.#client, ids);
248
+ }
249
+ async getReleaseAdminCapById(adminCapId: string): Promise<ReleaseAdminCap> {
250
+ return queries.getReleaseAdminCapById(this.#client, adminCapId);
251
+ }
252
+ deriveReleaseAdminCapId(releaseId: string): string {
253
+ return queries.deriveReleaseAdminCapId(releaseId, this.#misoPackageId);
254
+ }
255
+ async getOwnedReleaseAdminCaps(owner: string): Promise<ReleaseAdminCap[]> {
256
+ return queries.getOwnedReleaseAdminCaps(
257
+ this.#client,
258
+ owner,
259
+ this.#misoPackageId,
260
+ );
261
+ }
262
+ // === Share Currency ===
263
+
264
+ async getShareCurrencyType(shareCurrencyId: string): Promise<string> {
265
+ return queries.getShareCurrencyType(this.#client, shareCurrencyId);
266
+ }
267
+ /**
268
+ * The `TreasuryCap<shareType>` owned by `owner`. Takes the share TYPE — if you
269
+ * hold only the `Currency` object id, resolve it first with
270
+ * {@link getShareCurrencyType}.
271
+ */
272
+ async getShareCurrencyTreasuryCap(
273
+ shareType: string,
274
+ owner: string,
275
+ ): Promise<string> {
276
+ return queries.getShareCurrencyTreasuryCap(this.#client, shareType, owner);
277
+ }
278
+
279
+ // === Simulate-based reads (view) ===
280
+
281
+ get view() {
282
+ const client = this.#client;
283
+ const misoPackageId = this.#misoPackageId;
284
+ return {
285
+ deriveTargetReleaseId: (params: view.DeriveTargetReleaseIdParams) =>
286
+ view.deriveTargetReleaseId(client, misoPackageId, params),
287
+ };
288
+ }
289
+
290
+ // === Generated type-safe Move calls (for tx.add) ===
291
+
292
+ get call() {
293
+ const pkg = this.#misoPackageId;
294
+ return {
295
+ composition: bindModulePackage(composition, pkg, REF_RETURNING_CALLS.composition),
296
+ recording: bindModulePackage(recording, pkg, REF_RETURNING_CALLS.recording),
297
+ release: bindModulePackage(release, pkg, REF_RETURNING_CALLS.release),
298
+ track: bindModulePackage(track, pkg),
299
+ };
300
+ }
301
+
302
+ // === Generated BCS structs (for parsing object/event content) ===
303
+
304
+ get bcs() {
305
+ return {
306
+ Composition: composition.Composition,
307
+ Recording: recording.Recording,
308
+ Release: release.Release,
309
+ Track: track.Track,
310
+ CompositionPublishedEvent: composition.CompositionPublishedEvent,
311
+ RecordingPublishedEvent: recording.RecordingPublishedEvent,
312
+ ReleasePublishedEvent: release.ReleasePublishedEvent,
313
+ };
314
+ }
315
+
316
+ // === Event parsers ===
317
+
318
+ get parse() {
319
+ return {
320
+ compositionPublishedEvent: parsers.parseCompositionPublishedEvent,
321
+ recordingPublishedEvent: parsers.parseRecordingPublishedEvent,
322
+ compositionSharesGrantedEvent:
323
+ parsers.parseCompositionSharesGrantedEvent,
324
+ releasePublishedEvent: parsers.parseReleasePublishedEvent,
325
+ releaseRegistryCreatedEvent: parsers.parseReleaseRegistryCreatedEvent,
326
+ events: eventParsers,
327
+ };
328
+ }
329
+
330
+ #requireGraphQL(): SuiGraphQLClient {
331
+ if (!this.#graphqlClient) {
332
+ throw new Error(
333
+ "GraphQL client required. Pass graphqlClient to miso() options.",
334
+ );
335
+ }
336
+ return this.#graphqlClient;
337
+ }
338
+ }
339
+
340
+ /** @deprecated Prefer the layer-specific `MisoProtocolClient` name. */
341
+ export { MisoProtocolClient as MisoClient };