@misofm/partyos 0.1.0 → 0.3.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/README.md +62 -9
- package/dist/client.d.ts +8 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +25 -12
- package/dist/client.js.map +1 -1
- package/dist/deployments.d.ts +9 -1
- package/dist/deployments.d.ts.map +1 -1
- package/dist/deployments.js +14 -1
- package/dist/deployments.js.map +1 -1
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +3 -1
- package/dist/internal.js.map +1 -1
- package/dist/queries.d.ts +10 -16
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +41 -79
- package/dist/queries.js.map +1 -1
- package/dist/types.d.ts +12 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +15 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -1
- package/src/client.ts +28 -12
- package/src/deployments.ts +17 -1
- package/src/errors.ts +18 -0
- package/src/index.ts +1 -0
- package/src/internal.ts +4 -2
- package/src/queries.ts +71 -88
- package/src/types.ts +13 -10
package/dist/queries.js
CHANGED
|
@@ -1,123 +1,85 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Typed reads: fetch an on-chain object (or dynamic field) via the Core API, BCS-parse
|
|
4
|
+
// it through the generated struct, and map to the public camelCase types. Every read
|
|
5
|
+
// requires the `SuiClient` service (see `@misofm/effect`) instead of taking a client
|
|
6
|
+
// parameter; not-found and type-mismatch paths are typed failures, not thrown errors.
|
|
7
|
+
import { Effect, Option, Stream } from "effect";
|
|
3
8
|
import { deriveDynamicFieldID, deriveObjectID, normalizeStructTag } from "@mysten/sui/utils";
|
|
4
9
|
import { bcs } from "@mysten/sui/bcs";
|
|
10
|
+
import { assertObjectType, decodeBcs, getObjectContent, getObjectsContent, getOptionalObjectContent, listDynamicFields, } from "@misofm/effect";
|
|
5
11
|
import { MembershipKey as MembershipKeyBcs, Party as PartyBcs, PendingInviteKey as PendingInviteKeyBcs, PendingMembershipKey as PendingMembershipKeyBcs, } from "./contracts/partyos/party.js";
|
|
6
12
|
import { keyBytes, mapParty } from "./internal.js";
|
|
7
|
-
|
|
8
|
-
export function isNotFound(e) {
|
|
9
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
10
|
-
return /not\s*found|does not exist|no object/i.test(msg);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Reads an object's BCS content, or null when it does not exist. A missing
|
|
14
|
-
* object (e.g. an unset dynamic field) surfaces as a thrown "not found" from the
|
|
15
|
-
* Core API, not an empty result, so optional reads can treat it as absence.
|
|
16
|
-
*/
|
|
17
|
-
export async function getObjectContent(client, objectId) {
|
|
18
|
-
try {
|
|
19
|
-
const { object } = await client.core.getObject({ objectId, include: { content: true } });
|
|
20
|
-
return object?.content ?? null;
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
if (isNotFound(e))
|
|
24
|
-
return null;
|
|
25
|
-
throw e;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
13
|
+
import { Party } from "./types.js";
|
|
28
14
|
/** The `Party` struct tag of one partyos deployment. */
|
|
29
15
|
export function partyType(partyPackageId) {
|
|
30
16
|
return normalizeStructTag(`${partyPackageId}::party::Party`);
|
|
31
17
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function assertPartyType(objectId, type, partyPackageId) {
|
|
36
|
-
const expected = partyType(partyPackageId);
|
|
37
|
-
if (type === undefined || normalizeStructTag(type) !== expected) {
|
|
38
|
-
throw new Error(`Object ${objectId} is ${type ?? "of unknown type"}, not a ${expected}` +
|
|
39
|
-
(type?.endsWith("::party::Party") ? " (a Party from a different partyos deployment)" : ""));
|
|
40
|
-
}
|
|
18
|
+
/** Decodes one object's BCS content into a `Party`, mapping the generated parse output first. */
|
|
19
|
+
function decodeParty(objectId, content, expectedType) {
|
|
20
|
+
return decodeBcs({ parse: (bytes) => mapParty(objectId, PartyBcs.parse(bytes)) }, Party, content, { type: expectedType, objectId });
|
|
41
21
|
}
|
|
42
22
|
/** Fetches and parses a shared `Party` object of this deployment's partyos package. */
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
if (!object?.content)
|
|
54
|
-
throw new Error(`Party not found: ${partyId}`);
|
|
55
|
-
assertPartyType(partyId, object.type, partyPackageId);
|
|
56
|
-
return mapParty(partyId, PartyBcs.parse(object.content));
|
|
57
|
-
}
|
|
23
|
+
export const getPartyById = Effect.fn("getPartyById")(function* (partyId, partyPackageId) {
|
|
24
|
+
const expected = partyType(partyPackageId);
|
|
25
|
+
const object = yield* getObjectContent(partyId);
|
|
26
|
+
// A Party from another partyos package (a previous generation) parses
|
|
27
|
+
// identically but no deployed package accepts it, so the object's type is
|
|
28
|
+
// checked against the deployment before its content is trusted.
|
|
29
|
+
yield* assertObjectType(partyId, normalizeStructTag(object.type), expected);
|
|
30
|
+
return yield* decodeParty(partyId, object.content, expected);
|
|
31
|
+
});
|
|
58
32
|
/**
|
|
59
33
|
* Fetches and parses multiple shared `Party` objects in one Core request.
|
|
60
34
|
* Missing objects are skipped; an object of another type is an error.
|
|
61
35
|
*/
|
|
62
|
-
export
|
|
36
|
+
export const getPartiesByIds = Effect.fn("getPartiesByIds")(function* (partyIds, partyPackageId) {
|
|
63
37
|
if (partyIds.length === 0)
|
|
64
38
|
return {};
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
include: { content: true },
|
|
68
|
-
});
|
|
39
|
+
const expected = partyType(partyPackageId);
|
|
40
|
+
const contentById = yield* getObjectsContent([...new Set(partyIds)]);
|
|
69
41
|
const parties = {};
|
|
70
|
-
for (const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
assertPartyType(obj.objectId, obj.type, partyPackageId);
|
|
74
|
-
parties[obj.objectId] = mapParty(obj.objectId, PartyBcs.parse(obj.content));
|
|
42
|
+
for (const [objectId, { content, type }] of contentById) {
|
|
43
|
+
yield* assertObjectType(objectId, normalizeStructTag(type), expected);
|
|
44
|
+
parties[objectId] = yield* decodeParty(objectId, content, expected);
|
|
75
45
|
}
|
|
76
46
|
return parties;
|
|
77
|
-
}
|
|
47
|
+
});
|
|
78
48
|
/** Derives a party's `PartyAdminCap` id (it is a `derived_object` off the party UID). */
|
|
79
49
|
export function derivePartyAdminCapId(partyId, partyPackageId) {
|
|
80
50
|
return deriveObjectID(partyId, `${partyPackageId}::party::PartyAdminCapKey`, bcs.Address.serialize(partyId).toBytes());
|
|
81
51
|
}
|
|
82
52
|
// === Group membership reads ===
|
|
83
53
|
/** Collects the ids stored in every dynamic-field key of `parentId` whose type ends with `keySuffix`. */
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (const f of page.dynamicFields) {
|
|
90
|
-
if (typeof f.name?.type === "string" && f.name.type.endsWith(keySuffix) && f.name.bcs != null) {
|
|
91
|
-
const [id] = codec.parse(keyBytes(f.name.bcs));
|
|
92
|
-
ids.push(String(id));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
cursor = page.hasNextPage ? page.cursor : null;
|
|
96
|
-
} while (cursor);
|
|
97
|
-
return ids;
|
|
54
|
+
function collectKeyIds(parentId, keySuffix, codec) {
|
|
55
|
+
return listDynamicFields(parentId).pipe(Stream.filter((f) => typeof f.name?.type === "string" && f.name.type.endsWith(keySuffix) && f.name.bcs != null), Stream.map((f) => {
|
|
56
|
+
const [id] = codec.parse(keyBytes(f.name.bcs));
|
|
57
|
+
return String(id);
|
|
58
|
+
}), Stream.runCollect, Effect.map((chunk) => Array.from(chunk)));
|
|
98
59
|
}
|
|
99
60
|
/**
|
|
100
61
|
* The group ids a party currently belongs to, read from its `MembershipKey`
|
|
101
62
|
* dynamic fields (the member-side record). No indexer required.
|
|
102
63
|
*/
|
|
103
|
-
export
|
|
104
|
-
return collectKeyIds(
|
|
64
|
+
export function getMemberships(partyId) {
|
|
65
|
+
return collectKeyIds(partyId, "::party::MembershipKey", MembershipKeyBcs);
|
|
105
66
|
}
|
|
106
67
|
/** The member ids invited to a group but not yet accepted (its `PendingInviteKey` fields). */
|
|
107
|
-
export
|
|
108
|
-
return collectKeyIds(
|
|
68
|
+
export function getPendingInvites(groupId) {
|
|
69
|
+
return collectKeyIds(groupId, "::party::PendingInviteKey", PendingInviteKeyBcs);
|
|
109
70
|
}
|
|
110
71
|
/**
|
|
111
72
|
* The group ids that have invited a party but are still awaiting its response.
|
|
112
73
|
* This reads the member-side `PendingMembershipKey` inbox index, so it only
|
|
113
74
|
* enumerates the target party's dynamic fields.
|
|
114
75
|
*/
|
|
115
|
-
export
|
|
116
|
-
return collectKeyIds(
|
|
76
|
+
export function getPendingMemberships(partyId) {
|
|
77
|
+
return collectKeyIds(partyId, "::party::PendingMembershipKey", PendingMembershipKeyBcs);
|
|
117
78
|
}
|
|
118
79
|
/** Whether `memberId` currently holds a membership record for `groupId`. */
|
|
119
|
-
export
|
|
80
|
+
export const isMember = Effect.fn("isMember")(function* (memberId, groupId, partyPackageId) {
|
|
120
81
|
const fieldId = deriveDynamicFieldID(memberId, `${partyPackageId}::party::MembershipKey`, MembershipKeyBcs.serialize([groupId]).toBytes());
|
|
121
|
-
|
|
122
|
-
|
|
82
|
+
const content = yield* getOptionalObjectContent(fieldId);
|
|
83
|
+
return Option.isSome(content);
|
|
84
|
+
});
|
|
123
85
|
//# sourceMappingURL=queries.js.map
|
package/dist/queries.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,uFAAuF;AACvF,qFAAqF;AACrF,qFAAqF;AACrF,sFAAsF;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAElB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,IAAI,gBAAgB,EACjC,KAAK,IAAI,QAAQ,EACjB,gBAAgB,IAAI,mBAAmB,EACvC,oBAAoB,IAAI,uBAAuB,GAChD,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,wDAAwD;AACxD,MAAM,UAAU,SAAS,CAAC,cAAsB;IAC9C,OAAO,kBAAkB,CAAC,GAAG,cAAc,gBAAgB,CAAC,CAAC;AAC/D,CAAC;AAED,iGAAiG;AACjG,SAAS,WAAW,CAAC,QAAgB,EAAE,OAAmB,EAAE,YAAoB;IAC9E,OAAO,SAAS,CACd,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAC/D,KAAK,EACL,OAA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AE,wBAAwB,EAAE,gBAAgB,CAAC,CAAC;AAC5E,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,aAAa,CAAC,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,CAAC,CAAC;AAClF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,OAAO,aAAa,CAAC,OAAO,EAAE,+BAA+B,EAAE,uBAAuB,CAAC,CAAC;AAC1F,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EACrD,QAAgB,EAChB,OAAe,EACf,cAAsB;IAEtB,MAAM,OAAO,GAAG,oBAAoB,CAClC,QAAQ,EACR,GAAG,cAAc,wBAAwB,EACzC,gBAAgB,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAChD,CAAC;IACF,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const PartyKind: Schema.Literals<readonly ["individual", "group"]>;
|
|
3
|
+
export type PartyKind = typeof PartyKind.Type;
|
|
4
|
+
declare const Party_base: Schema.Class<Party, Schema.Struct<{
|
|
5
|
+
readonly id: Schema.String;
|
|
6
|
+
readonly kind: Schema.Literals<readonly ["individual", "group"]>;
|
|
5
7
|
/** Human-readable name (not verified). */
|
|
6
|
-
name:
|
|
8
|
+
readonly name: Schema.String;
|
|
7
9
|
/** Member party ids — present only when `kind === "group"`. */
|
|
8
|
-
members
|
|
10
|
+
readonly members: Schema.optional<Schema.$Array<Schema.String>>;
|
|
9
11
|
/** Unix ms when the party was created. */
|
|
10
|
-
createdAtMs:
|
|
12
|
+
readonly createdAtMs: Schema.Number;
|
|
13
|
+
}>, {}>;
|
|
14
|
+
export declare class Party extends Party_base {
|
|
11
15
|
}
|
|
16
|
+
export {};
|
|
12
17
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,SAAS,mDAA2C,CAAC;AAClE,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;;;;IAK5C,0CAA0C;;IAE1C,+DAA+D;;IAE/D,0CAA0C;;;AAP5C,qBAAa,KAAM,SAAQ,UASzB;CAAG"}
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
3
|
+
// Public, camelCase result types. The mapper in ./internal.ts turns the generated
|
|
4
|
+
// (snake_case, Move-shaped) parse output into the plain shape `Party` decodes from.
|
|
5
|
+
import { Schema } from "effect";
|
|
6
|
+
export const PartyKind = Schema.Literals(["individual", "group"]);
|
|
7
|
+
export class Party extends Schema.Class("@misofm/partyos/Party")({
|
|
8
|
+
id: Schema.String,
|
|
9
|
+
kind: PartyKind,
|
|
10
|
+
/** Human-readable name (not verified). */
|
|
11
|
+
name: Schema.String,
|
|
12
|
+
/** Member party ids — present only when `kind === "group"`. */
|
|
13
|
+
members: Schema.optional(Schema.Array(Schema.String)),
|
|
14
|
+
/** Unix ms when the party was created. */
|
|
15
|
+
createdAtMs: Schema.Number,
|
|
16
|
+
}) {
|
|
17
|
+
}
|
|
4
18
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,kFAAkF;AAClF,oFAAoF;AAEpF,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;AAGlE,MAAM,OAAO,KAAM,SAAQ,MAAM,CAAC,KAAK,CAAQ,uBAAuB,CAAC,CAAC;IACtE,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,IAAI,EAAE,SAAS;IACf,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACrD,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC,MAAM;CAC3B,CAAC;CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misofm/partyos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"packageManager": "bun@1.4.0",
|
|
5
5
|
"description": "Typed bindings, queries, and PTB builders for the PartyOS object model (Party identity, admin caps, and group membership) on Sui.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -50,6 +50,10 @@
|
|
|
50
50
|
"types": "./dist/deployments.d.ts",
|
|
51
51
|
"default": "./dist/deployments.js"
|
|
52
52
|
},
|
|
53
|
+
"./errors": {
|
|
54
|
+
"types": "./dist/errors.d.ts",
|
|
55
|
+
"default": "./dist/errors.js"
|
|
56
|
+
},
|
|
53
57
|
"./queries": {
|
|
54
58
|
"types": "./dist/queries.d.ts",
|
|
55
59
|
"default": "./dist/queries.js"
|
|
@@ -80,17 +84,20 @@
|
|
|
80
84
|
"package.json"
|
|
81
85
|
],
|
|
82
86
|
"dependencies": {
|
|
87
|
+
"@misofm/effect": "0.1.0",
|
|
83
88
|
"@mysten/bcs": "^2.1.1"
|
|
84
89
|
},
|
|
85
90
|
"devDependencies": {
|
|
86
91
|
"@mysten/sui": "2.29.0",
|
|
87
92
|
"@types/bun": "^1.4.0",
|
|
93
|
+
"effect": "4.0.0-rc.112",
|
|
88
94
|
"typedoc": "^0.28.20",
|
|
89
95
|
"typedoc-plugin-markdown": "^4.13.0",
|
|
90
96
|
"typescript": "^7.0.2"
|
|
91
97
|
},
|
|
92
98
|
"peerDependencies": {
|
|
93
99
|
"@mysten/sui": "2.29.0",
|
|
100
|
+
"effect": "4.0.0-rc.112",
|
|
94
101
|
"typescript": "^5.7 || ^6 || ^7"
|
|
95
102
|
},
|
|
96
103
|
"main": "./dist/index.js"
|
package/src/client.ts
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
// deployment. Consumers reach this through `client.partyos` after
|
|
6
6
|
// `$extend(partyos())`, or construct `PartyosClient` directly.
|
|
7
7
|
|
|
8
|
+
import { Effect } from "effect";
|
|
8
9
|
import type { ClientWithCoreApi, SuiClientRegistration } from "@mysten/sui/client";
|
|
10
|
+
import { SuiClient } from "@misofm/effect";
|
|
11
|
+
import type { BcsDecodeError, ObjectNotFoundError, ObjectTypeMismatchError, SuiRpcError } from "@misofm/effect";
|
|
9
12
|
import { getPartyDeployment, normalizePartyDeployment, type PartyDeployment } from "./deployments.ts";
|
|
10
13
|
import { PARTY_REF_RETURNING_CALLS } from "./contracts.ts";
|
|
11
14
|
import * as queries from "./queries.ts";
|
|
@@ -74,10 +77,12 @@ export function partyos<const Name extends string = "partyos">(
|
|
|
74
77
|
export class PartyosClient {
|
|
75
78
|
#client: ClientWithCoreApi;
|
|
76
79
|
#deployment: PartyDeployment;
|
|
80
|
+
#layer: ReturnType<typeof SuiClient.layer>;
|
|
77
81
|
|
|
78
82
|
constructor(client: ClientWithCoreApi, deployment: PartyDeployment) {
|
|
79
83
|
this.#client = client;
|
|
80
84
|
this.#deployment = normalizePartyDeployment(deployment);
|
|
85
|
+
this.#layer = SuiClient.layer(client);
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
/** The exact deployment selected for this client. */
|
|
@@ -89,32 +94,43 @@ export class PartyosClient {
|
|
|
89
94
|
return this.#deployment.partyos;
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
/** Provides the `SuiClient` service bound to this client, discharging `R`. */
|
|
98
|
+
#provide<A, E>(effect: Effect.Effect<A, E, SuiClient>): Effect.Effect<A, E> {
|
|
99
|
+
return effect.pipe(Effect.provide(this.#layer));
|
|
100
|
+
}
|
|
101
|
+
|
|
92
102
|
// === Queries ===
|
|
103
|
+
// Each method provides `SuiClient` internally, so callers get `Effect<A, E>`
|
|
104
|
+
// (R = never) and only need `Effect.runPromise` (or their own composition).
|
|
93
105
|
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
getPartyById(
|
|
107
|
+
partyId: string,
|
|
108
|
+
): Effect.Effect<Party, ObjectNotFoundError | ObjectTypeMismatchError | BcsDecodeError | SuiRpcError> {
|
|
109
|
+
return this.#provide(queries.getPartyById(partyId, this.#pkg));
|
|
96
110
|
}
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
getPartiesByIds(
|
|
112
|
+
partyIds: readonly string[],
|
|
113
|
+
): Effect.Effect<Partial<Record<string, Party>>, ObjectTypeMismatchError | BcsDecodeError | SuiRpcError> {
|
|
114
|
+
return this.#provide(queries.getPartiesByIds(partyIds, this.#pkg));
|
|
99
115
|
}
|
|
100
116
|
derivePartyAdminCapId(partyId: string): string {
|
|
101
117
|
return queries.derivePartyAdminCapId(partyId, this.#pkg);
|
|
102
118
|
}
|
|
103
119
|
/** Group ids a party belongs to (member-side membership records). */
|
|
104
|
-
|
|
105
|
-
return queries.getMemberships(
|
|
120
|
+
getMemberships(partyId: string): Effect.Effect<string[], SuiRpcError> {
|
|
121
|
+
return this.#provide(queries.getMemberships(partyId));
|
|
106
122
|
}
|
|
107
123
|
/** Member ids invited to a group but not yet accepted. */
|
|
108
|
-
|
|
109
|
-
return queries.getPendingInvites(
|
|
124
|
+
getPendingInvites(groupId: string): Effect.Effect<string[], SuiRpcError> {
|
|
125
|
+
return this.#provide(queries.getPendingInvites(groupId));
|
|
110
126
|
}
|
|
111
127
|
/** Group ids that have invited this party but are awaiting its response. */
|
|
112
|
-
|
|
113
|
-
return queries.getPendingMemberships(
|
|
128
|
+
getPendingMemberships(partyId: string): Effect.Effect<string[], SuiRpcError> {
|
|
129
|
+
return this.#provide(queries.getPendingMemberships(partyId));
|
|
114
130
|
}
|
|
115
131
|
/** Whether a party is a member of a group. */
|
|
116
|
-
|
|
117
|
-
return queries.isMember(
|
|
132
|
+
isMember(memberId: string, groupId: string): Effect.Effect<boolean, SuiRpcError> {
|
|
133
|
+
return this.#provide(queries.isMember(memberId, groupId, this.#pkg));
|
|
118
134
|
}
|
|
119
135
|
|
|
120
136
|
// === Transaction builders (thunks; the package id is bound from the client) ===
|
package/src/deployments.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { Effect } from "effect";
|
|
4
5
|
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
6
|
+
import { DeploymentError } from "@misofm/effect";
|
|
5
7
|
|
|
6
8
|
/** Sui networks for which this SDK may bundle a verified deployment. */
|
|
7
9
|
export type PartyosNetwork = "mainnet" | "testnet";
|
|
@@ -26,7 +28,7 @@ export type PartyDeployment = Readonly<Record<PartyosPackageName, string>>;
|
|
|
26
28
|
/** Verified immutable deployments bundled with this SDK release. */
|
|
27
29
|
export const PARTYOS_DEPLOYMENTS = Object.freeze({
|
|
28
30
|
testnet: Object.freeze({
|
|
29
|
-
partyos: "
|
|
31
|
+
partyos: "0x342425da86c4389c1f5558013251f18017ead98414db5644569890ba3a4a434c",
|
|
30
32
|
} as const),
|
|
31
33
|
} as const) satisfies Partial<Record<PartyosNetwork, PartyDeployment>>;
|
|
32
34
|
|
|
@@ -88,3 +90,17 @@ export function normalizePartyDeployment(deployment: unknown): PartyDeployment {
|
|
|
88
90
|
Object.fromEntries(CANONICAL_PARTYOS_PACKAGE_NAMES.map((name) => [name, deployment[name]])),
|
|
89
91
|
) as PartyDeployment;
|
|
90
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Effect counterpart to {@link normalizePartyDeployment}: validation is pure and
|
|
96
|
+
* synchronous, so this exists only for callers composing a config-loading
|
|
97
|
+
* pipeline out of Effects rather than throwing at a configuration boundary.
|
|
98
|
+
*/
|
|
99
|
+
export const validatePartyDeployment = Effect.fn("validatePartyDeployment")(function* (
|
|
100
|
+
input: unknown,
|
|
101
|
+
): Effect.fn.Return<PartyDeployment, DeploymentError> {
|
|
102
|
+
return yield* Effect.try({
|
|
103
|
+
try: () => normalizePartyDeployment(input),
|
|
104
|
+
catch: (cause) => new DeploymentError({ message: cause instanceof Error ? cause.message : String(cause) }),
|
|
105
|
+
});
|
|
106
|
+
});
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Party-specific tagged errors, plus the shared vocabulary re-exported so
|
|
5
|
+
// callers never need to reach into `@misofm/effect` directly. `getPartyById`
|
|
6
|
+
// and `getPartiesByIds` fail with the foundation's `ObjectNotFoundError` /
|
|
7
|
+
// `ObjectTypeMismatchError` — `PartyNotFoundError` below is offered for
|
|
8
|
+
// callers that want a party-scoped tag instead of pattern-matching the
|
|
9
|
+
// generic object vocabulary.
|
|
10
|
+
|
|
11
|
+
import { Schema } from "effect";
|
|
12
|
+
|
|
13
|
+
export * from "@misofm/effect/errors";
|
|
14
|
+
|
|
15
|
+
/** A party object does not exist (never existed, was deleted, or the id is not a party). */
|
|
16
|
+
export class PartyNotFoundError extends Schema.TaggedError<PartyNotFoundError>()("PartyNotFoundError", {
|
|
17
|
+
partyId: Schema.String,
|
|
18
|
+
}) {}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./transactions.ts";
|
|
|
10
10
|
export * from "./queries.ts";
|
|
11
11
|
export * from "./client.ts";
|
|
12
12
|
export * from "./deployments.ts";
|
|
13
|
+
export * from "./errors.ts";
|
|
13
14
|
|
|
14
15
|
// Generated, ABI-bound bindings (BCS structs + type-safe Move calls).
|
|
15
16
|
export * as contracts from "./contracts.ts";
|
package/src/internal.ts
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
// The single boundary between generated BCS-parse output (snake_case, Move-shaped)
|
|
5
|
-
// and the public camelCase types.
|
|
5
|
+
// and the public camelCase types. `mapParty` returns a plain object shaped like
|
|
6
|
+
// `Party`'s encoded form; `Schema.decodeUnknownEffect(Party)` (via `decodeBcs`)
|
|
7
|
+
// validates and constructs the class from it.
|
|
6
8
|
|
|
7
9
|
import { fromBase64 } from "@mysten/sui/utils";
|
|
8
10
|
import type { Party } from "./types.ts";
|
|
9
11
|
|
|
10
12
|
// deno-lint-ignore no-explicit-any -- generated parse output is loosely typed
|
|
11
|
-
export function mapParty(id: string, d: any): Party {
|
|
13
|
+
export function mapParty(id: string, d: any): typeof Party.Encoded {
|
|
12
14
|
const kind = d.kind;
|
|
13
15
|
const createdAtMs = Number(d.created_at_ms);
|
|
14
16
|
// PartyKind is `Individual | Group(VecSet<ID>)`. The enum parses to
|