@misofm/partyos 0.2.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 +61 -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 +8 -0
- package/dist/deployments.d.ts.map +1 -1
- package/dist/deployments.js +13 -0
- 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 +16 -0
- 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/README.md
CHANGED
|
@@ -14,38 +14,90 @@ this package. Which Move package generates into which SDK is decided by
|
|
|
14
14
|
## Install
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
|
-
bun add @misofm/partyos @mysten/sui
|
|
17
|
+
bun add @misofm/partyos @misofm/effect effect @mysten/sui
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
`@mysten/sui`
|
|
20
|
+
`@mysten/sui` and `effect` (exactly `4.0.0-rc.112`) are peer dependencies.
|
|
21
21
|
|
|
22
22
|
## Use
|
|
23
23
|
|
|
24
|
+
Every read returns an `Effect` that requires the `SuiClient` service instead of
|
|
25
|
+
taking a client parameter — see [`@misofm/effect`](https://www.npmjs.com/package/@misofm/effect)
|
|
26
|
+
for the shared `SuiClient` service and error vocabulary every `@misofm/*` package
|
|
27
|
+
builds on.
|
|
28
|
+
|
|
29
|
+
### Through the client extension
|
|
30
|
+
|
|
31
|
+
`client.partyos.*` provides `SuiClient` internally (bound to the client it was
|
|
32
|
+
built from), so each method already returns `Effect<A, E>` with `R = never` —
|
|
33
|
+
just `Effect.runPromise` it:
|
|
34
|
+
|
|
24
35
|
```ts
|
|
36
|
+
import { Effect } from "effect";
|
|
25
37
|
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
26
38
|
import { Transaction } from "@mysten/sui/transactions";
|
|
27
39
|
import { partyos } from "@misofm/partyos";
|
|
28
40
|
|
|
29
41
|
const client = new SuiGrpcClient({ network: "testnet" }).$extend(partyos());
|
|
30
42
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
43
|
+
const program = Effect.gen(function* () {
|
|
44
|
+
const party = yield* client.partyos.getPartyById("0x...");
|
|
45
|
+
const groups = yield* client.partyos.getMemberships(party.id);
|
|
46
|
+
return { party, groups };
|
|
47
|
+
}).pipe(
|
|
48
|
+
Effect.catchTag("ObjectNotFoundError", (error) => Effect.succeed({ party: null, groups: [], missing: error })),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const { party, groups } = await Effect.runPromise(program);
|
|
33
52
|
|
|
34
53
|
const tx = new Transaction();
|
|
35
54
|
await client.partyos.tx.createIndividualParty({ name: "Ada", recipient: "0x..." })(tx);
|
|
36
55
|
```
|
|
37
56
|
|
|
38
57
|
Every builder under `tx` appends commands to a caller-owned `Transaction` and never
|
|
39
|
-
executes. `call` exposes the generated,
|
|
40
|
-
reference-returning views a PTB cannot use),
|
|
58
|
+
executes (`tx`/`call`/`bcs` stay synchronous). `call` exposes the generated,
|
|
59
|
+
package-bound Move calls (minus the reference-returning views a PTB cannot use),
|
|
60
|
+
and `bcs` the generated codecs.
|
|
61
|
+
|
|
62
|
+
### Free functions
|
|
63
|
+
|
|
64
|
+
The functions in `./queries` take no client parameter — they declare `SuiClient`
|
|
65
|
+
in their Effect's requirements, so provide it once at your program's boundary:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { Effect } from "effect";
|
|
69
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
70
|
+
import { SuiClient } from "@misofm/effect";
|
|
71
|
+
import { getPartyById } from "@misofm/partyos/queries";
|
|
72
|
+
|
|
73
|
+
const client = new SuiGrpcClient({ network: "testnet" });
|
|
74
|
+
|
|
75
|
+
const program = getPartyById("0x...", "0xPARTYOS_PACKAGE");
|
|
76
|
+
|
|
77
|
+
const party = await Effect.runPromise(program.pipe(Effect.provide(SuiClient.layer(client))));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Errors
|
|
81
|
+
|
|
82
|
+
Reads fail with the shared `@misofm/effect` vocabulary: `ObjectNotFoundError { objectId }`,
|
|
83
|
+
`ObjectTypeMismatchError { objectId, expected, actual }` (e.g. a `Party` object from a
|
|
84
|
+
different partyos deployment, or an id that is not a `Party` at all), `BcsDecodeError`,
|
|
85
|
+
and `SuiRpcError`. Recover from one with `Effect.catchTag("ObjectNotFoundError", ...)`
|
|
86
|
+
rather than an `isNotFound(error)` predicate. `./errors` re-exports the full
|
|
87
|
+
`@misofm/effect/errors` vocabulary plus `PartyNotFoundError { partyId }`, offered for
|
|
88
|
+
callers that want a party-scoped tag instead of pattern-matching the generic one.
|
|
89
|
+
`validatePartyDeployment` (in `./deployments`) fails with `DeploymentError { message }`.
|
|
41
90
|
|
|
42
91
|
## Deployment manifest
|
|
43
92
|
|
|
44
93
|
`PARTYOS_DEPLOYMENTS` bundles the verified testnet deployment: a single key, `partyos`.
|
|
45
94
|
Pass `partyos({ deployment })` for another network; a manifest with any other shape is
|
|
46
|
-
rejected before a Move target is constructed
|
|
95
|
+
rejected before a Move target is constructed (`assertPartyDeployment`/`normalizePartyDeployment`
|
|
96
|
+
throw synchronously; `validatePartyDeployment` is the Effect-returning counterpart for
|
|
97
|
+
callers composing a config-loading pipeline out of Effects).
|
|
47
98
|
|
|
48
99
|
## Subpaths
|
|
49
100
|
|
|
50
|
-
`@misofm/partyos` (everything), `/client`, `/deployments`, `/
|
|
51
|
-
`/types`, `/contracts` (curated bindings), `/contracts/*` (raw
|
|
101
|
+
`@misofm/partyos` (everything), `/client`, `/deployments`, `/errors`, `/queries`,
|
|
102
|
+
`/transactions`, `/types`, `/contracts` (curated bindings), `/contracts/*` (raw
|
|
103
|
+
generated modules).
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
1
2
|
import type { ClientWithCoreApi, SuiClientRegistration } from "@mysten/sui/client";
|
|
3
|
+
import type { BcsDecodeError, ObjectNotFoundError, ObjectTypeMismatchError, SuiRpcError } from "@misofm/effect";
|
|
2
4
|
import { type PartyDeployment } from "./deployments.ts";
|
|
3
5
|
import * as transactions from "./transactions.ts";
|
|
4
6
|
import type { TxThunk } from "./transactions.ts";
|
|
@@ -34,17 +36,17 @@ export declare class PartyosClient {
|
|
|
34
36
|
constructor(client: ClientWithCoreApi, deployment: PartyDeployment);
|
|
35
37
|
/** The exact deployment selected for this client. */
|
|
36
38
|
get deployment(): PartyDeployment;
|
|
37
|
-
getPartyById(partyId: string):
|
|
38
|
-
getPartiesByIds(partyIds: readonly string[]):
|
|
39
|
+
getPartyById(partyId: string): Effect.Effect<Party, ObjectNotFoundError | ObjectTypeMismatchError | BcsDecodeError | SuiRpcError>;
|
|
40
|
+
getPartiesByIds(partyIds: readonly string[]): Effect.Effect<Partial<Record<string, Party>>, ObjectTypeMismatchError | BcsDecodeError | SuiRpcError>;
|
|
39
41
|
derivePartyAdminCapId(partyId: string): string;
|
|
40
42
|
/** Group ids a party belongs to (member-side membership records). */
|
|
41
|
-
getMemberships(partyId: string):
|
|
43
|
+
getMemberships(partyId: string): Effect.Effect<string[], SuiRpcError>;
|
|
42
44
|
/** Member ids invited to a group but not yet accepted. */
|
|
43
|
-
getPendingInvites(groupId: string):
|
|
45
|
+
getPendingInvites(groupId: string): Effect.Effect<string[], SuiRpcError>;
|
|
44
46
|
/** Group ids that have invited this party but are awaiting its response. */
|
|
45
|
-
getPendingMemberships(partyId: string):
|
|
47
|
+
getPendingMemberships(partyId: string): Effect.Effect<string[], SuiRpcError>;
|
|
46
48
|
/** Whether a party is a member of a group. */
|
|
47
|
-
isMember(memberId: string, groupId: string):
|
|
49
|
+
isMember(memberId: string, groupId: string): Effect.Effect<boolean, SuiRpcError>;
|
|
48
50
|
get tx(): {
|
|
49
51
|
createIndividualParty: (p: Omit<transactions.CreatePartyParams, "partyPackageId">) => TxThunk;
|
|
50
52
|
createGroupParty: (p: Omit<transactions.CreatePartyParams, "partyPackageId">) => TxThunk;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAChH,OAAO,EAAgD,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGtG,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,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M,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,KAAG,OAAO;QAEjF,YAAY,MAAM,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,KAAG,OAAO;QAEnF,aAAa,MAAM,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,KAAG,OAAO;QAErF,YAAY,MAAM,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,KAAG,OAAO;QAEnF,UAAU,MAAM,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,KAAG,OAAO;QAE/E,YAAY,MAAM,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,KAAG,OAAO;MAGtF;IAID,IAAI,IAAI;QAEJ,KAAK;MAER;IAID,IAAI,GAAG;QAEH,KAAK;;;;;;;;;;;;;QACL,aAAa;;;;MAEhB;CACF;AAED,qGAAqG;AACrG,OAAO,EAAE,aAAa,IAAI,mBAAmB,EAAE,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Party queries and transaction builders bound to one verified partyos
|
|
4
|
+
// deployment. Consumers reach this through `client.partyos` after
|
|
5
|
+
// `$extend(partyos())`, or construct `PartyosClient` directly.
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { SuiClient } from "@misofm/effect";
|
|
3
8
|
import { getPartyDeployment, normalizePartyDeployment } from "./deployments.js";
|
|
4
9
|
import { PARTY_REF_RETURNING_CALLS } from "./contracts.js";
|
|
5
10
|
import * as queries from "./queries.js";
|
|
@@ -38,9 +43,11 @@ export function partyos(options = {}) {
|
|
|
38
43
|
export class PartyosClient {
|
|
39
44
|
#client;
|
|
40
45
|
#deployment;
|
|
46
|
+
#layer;
|
|
41
47
|
constructor(client, deployment) {
|
|
42
48
|
this.#client = client;
|
|
43
49
|
this.#deployment = normalizePartyDeployment(deployment);
|
|
50
|
+
this.#layer = SuiClient.layer(client);
|
|
44
51
|
}
|
|
45
52
|
/** The exact deployment selected for this client. */
|
|
46
53
|
get deployment() {
|
|
@@ -49,31 +56,37 @@ export class PartyosClient {
|
|
|
49
56
|
get #pkg() {
|
|
50
57
|
return this.#deployment.partyos;
|
|
51
58
|
}
|
|
59
|
+
/** Provides the `SuiClient` service bound to this client, discharging `R`. */
|
|
60
|
+
#provide(effect) {
|
|
61
|
+
return effect.pipe(Effect.provide(this.#layer));
|
|
62
|
+
}
|
|
52
63
|
// === Queries ===
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
// Each method provides `SuiClient` internally, so callers get `Effect<A, E>`
|
|
65
|
+
// (R = never) and only need `Effect.runPromise` (or their own composition).
|
|
66
|
+
getPartyById(partyId) {
|
|
67
|
+
return this.#provide(queries.getPartyById(partyId, this.#pkg));
|
|
55
68
|
}
|
|
56
|
-
|
|
57
|
-
return queries.getPartiesByIds(
|
|
69
|
+
getPartiesByIds(partyIds) {
|
|
70
|
+
return this.#provide(queries.getPartiesByIds(partyIds, this.#pkg));
|
|
58
71
|
}
|
|
59
72
|
derivePartyAdminCapId(partyId) {
|
|
60
73
|
return queries.derivePartyAdminCapId(partyId, this.#pkg);
|
|
61
74
|
}
|
|
62
75
|
/** Group ids a party belongs to (member-side membership records). */
|
|
63
|
-
|
|
64
|
-
return queries.getMemberships(
|
|
76
|
+
getMemberships(partyId) {
|
|
77
|
+
return this.#provide(queries.getMemberships(partyId));
|
|
65
78
|
}
|
|
66
79
|
/** Member ids invited to a group but not yet accepted. */
|
|
67
|
-
|
|
68
|
-
return queries.getPendingInvites(
|
|
80
|
+
getPendingInvites(groupId) {
|
|
81
|
+
return this.#provide(queries.getPendingInvites(groupId));
|
|
69
82
|
}
|
|
70
83
|
/** Group ids that have invited this party but are awaiting its response. */
|
|
71
|
-
|
|
72
|
-
return queries.getPendingMemberships(
|
|
84
|
+
getPendingMemberships(partyId) {
|
|
85
|
+
return this.#provide(queries.getPendingMemberships(partyId));
|
|
73
86
|
}
|
|
74
87
|
/** Whether a party is a member of a group. */
|
|
75
|
-
|
|
76
|
-
return queries.isMember(
|
|
88
|
+
isMember(memberId, groupId) {
|
|
89
|
+
return this.#provide(queries.isMember(memberId, groupId, this.#pkg));
|
|
77
90
|
}
|
|
78
91
|
// === Transaction builders (thunks; the package id is bound from the client) ===
|
|
79
92
|
get tx() {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,uEAAuE;AACvE,kEAAkE;AAClE,+DAA+D;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAwB,MAAM,kBAAkB,CAAC;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAGlD,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;AAWzD,qFAAqF;AACrF,MAAM,UAAU,iBAAiB,CAC/B,GAAM,EACN,GAAW,EACX,WAAW,GAAM,EAAkB;IAEnC,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;QACtD,IAAK,WAAiC,C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I,IAAI;QACN,OAAO;YACL,KAAK,EAAE,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,yBAAyB,CAAC;SACzE,CAAC;IACJ,CAAC;IAED,mEAAmE;IAEnE,IAAI,GAAG;QACL,OAAO;YACL,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,aAAa,EAAE,QAAQ,CAAC,aAAa;SACtC,CAAC;IACJ,CAAC;CACF;AAED,qGAAqG;AACrG,OAAO,EAAE,aAAa,IAAI,mBAAmB,EAAE,CAAC"}
|
package/dist/deployments.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { DeploymentError } from "@misofm/effect";
|
|
1
3
|
/** Sui networks for which this SDK may bundle a verified deployment. */
|
|
2
4
|
export type PartyosNetwork = "mainnet" | "testnet";
|
|
3
5
|
/**
|
|
@@ -29,5 +31,11 @@ export declare function getPartyDeployment(network: string): PartyDeployment;
|
|
|
29
31
|
export declare function assertPartyDeployment(deployment: unknown): asserts deployment is PartyDeployment;
|
|
30
32
|
/** Validate and snapshot an untrusted manifest so later caller mutation is inert. */
|
|
31
33
|
export declare function normalizePartyDeployment(deployment: unknown): PartyDeployment;
|
|
34
|
+
/**
|
|
35
|
+
* Effect counterpart to {@link normalizePartyDeployment}: validation is pure and
|
|
36
|
+
* synchronous, so this exists only for callers composing a config-loading
|
|
37
|
+
* pipeline out of Effects rather than throwing at a configuration boundary.
|
|
38
|
+
*/
|
|
39
|
+
export declare const validatePartyDeployment: (input: unknown) => Effect.Effect<Readonly<Record<"partyos", string>>, DeploymentError, never>;
|
|
32
40
|
export {};
|
|
33
41
|
//# sourceMappingURL=deployments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployments.d.ts","sourceRoot":"","sources":["../src/deployments.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deployments.d.ts","sourceRoot":"","sources":["../src/deployments.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnD;;;;;;GAMG;AACH,QAAA,MAAM,+BAA+B,YAAI,SAAS,CAAU,CAAC;AAE7D,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,+BAA+B,CAAC,CAAC,MAAM,CAAC,CAAC;AAElF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC;AAE3E,oEAAoE;AACpE,eAAO,MAAM,mBAAmB;;0BAEnB,oEAAoE;;EAEX,CAAC;AAEvE,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CASnE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,IAAI,eAAe,CAiChG;AAED,qFAAqF;AACrF,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,OAAO,GAAG,eAAe,CAK7E;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,gGAOlC,CAAC"}
|
package/dist/deployments.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Effect } from "effect";
|
|
3
4
|
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
5
|
+
import { DeploymentError } from "@misofm/effect";
|
|
4
6
|
/**
|
|
5
7
|
* The single independently published package required by this SDK surface:
|
|
6
8
|
* the `partyos` object-model package (module `party`).
|
|
@@ -60,4 +62,15 @@ export function normalizePartyDeployment(deployment) {
|
|
|
60
62
|
assertPartyDeployment(deployment);
|
|
61
63
|
return Object.freeze(Object.fromEntries(CANONICAL_PARTYOS_PACKAGE_NAMES.map((name) => [name, deployment[name]])));
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Effect counterpart to {@link normalizePartyDeployment}: validation is pure and
|
|
67
|
+
* synchronous, so this exists only for callers composing a config-loading
|
|
68
|
+
* pipeline out of Effects rather than throwing at a configuration boundary.
|
|
69
|
+
*/
|
|
70
|
+
export const validatePartyDeployment = Effect.fn("validatePartyDeployment")(function* (input) {
|
|
71
|
+
return yield* Effect.try({
|
|
72
|
+
try: () => normalizePartyDeployment(input),
|
|
73
|
+
catch: (cause) => new DeploymentError({ message: cause instanceof Error ? cause.message : String(cause) }),
|
|
74
|
+
});
|
|
75
|
+
});
|
|
63
76
|
//# sourceMappingURL=deployments.js.map
|
package/dist/deployments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployments.js","sourceRoot":"","sources":["../src/deployments.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"deployments.js","sourceRoot":"","sources":["../src/deployments.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;;;;;GAMG;AACH,MAAM,+BAA+B,GAAG,CAAC,SAAS,CAAU,CAAC;AAU7D,oEAAoE;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,oEAAoE;KACrE,CAAC;CACH,CAA4D,CAAC;AAEvE,0EAA0E;AAC1E,MAAM,UAA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_base: Schema.Class<PartyNotFoundError, Schema.TaggedStruct<"PartyNotFoundError", {
|
|
4
|
+
readonly partyId: Schema.String;
|
|
5
|
+
}>, import("effect/Cause").YieldableError>;
|
|
6
|
+
/** A party object does not exist (never existed, was deleted, or the id is not a party). */
|
|
7
|
+
export declare class PartyNotFoundError extends PartyNotFoundError_base {
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,cAAc,uBAAuB,CAAC;;;;AAEtC,4FAA4F;AAC5F,qBAAa,kBAAmB,SAAQ,uBAEtC;CAAG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Miso Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Party-specific tagged errors, plus the shared vocabulary re-exported so
|
|
4
|
+
// callers never need to reach into `@misofm/effect` directly. `getPartyById`
|
|
5
|
+
// and `getPartiesByIds` fail with the foundation's `ObjectNotFoundError` /
|
|
6
|
+
// `ObjectTypeMismatchError` — `PartyNotFoundError` below is offered for
|
|
7
|
+
// callers that want a party-scoped tag instead of pattern-matching the
|
|
8
|
+
// generic object vocabulary.
|
|
9
|
+
import { Schema } from "effect";
|
|
10
|
+
export * from "@misofm/effect/errors";
|
|
11
|
+
/** A party object does not exist (never existed, was deleted, or the id is not a party). */
|
|
12
|
+
export class PartyNotFoundError extends Schema.TaggedError()("PartyNotFoundError", {
|
|
13
|
+
partyId: Schema.String,
|
|
14
|
+
}) {
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,wEAAwE;AACxE,uEAAuE;AACvE,6BAA6B;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,cAAc,uBAAuB,CAAC;AAEtC,4FAA4F;AAC5F,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,WAAW,EAAsB,CAAC,oBAAoB,EAAE;IACrG,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAG5B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./transactions.js";
|
|
|
9
9
|
export * from "./queries.js";
|
|
10
10
|
export * from "./client.js";
|
|
11
11
|
export * from "./deployments.js";
|
|
12
|
+
export * from "./errors.js";
|
|
12
13
|
// Generated, ABI-bound bindings (BCS structs + type-safe Move calls).
|
|
13
14
|
export * as contracts from "./contracts.js";
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,+EAA+E;AAC/E,+EAA+E;AAC/E,yEAAyE;AACzE,6DAA6D;AAC7D,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,+EAA+E;AAC/E,+EAA+E;AAC/E,yEAAyE;AACzE,6DAA6D;AAC7D,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAE5B,sEAAsE;AACtE,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Party } from "./types.ts";
|
|
2
|
-
export declare function mapParty(id: string, d: any): Party;
|
|
2
|
+
export declare function mapParty(id: string, d: any): typeof Party.Encoded;
|
|
3
3
|
/** Normalizes a dynamic-field key's BCS bytes (Uint8Array or base64 string). */
|
|
4
4
|
export declare function keyBytes(bcs: unknown): Uint8Array;
|
|
5
5
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,GAAG,OAAO,KAAK,CAAC,OAAO,CAcjE;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAEjD"}
|
package/dist/internal.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// The single boundary between generated BCS-parse output (snake_case, Move-shaped)
|
|
4
|
-
// and the public camelCase types.
|
|
4
|
+
// and the public camelCase types. `mapParty` returns a plain object shaped like
|
|
5
|
+
// `Party`'s encoded form; `Schema.decodeUnknownEffect(Party)` (via `decodeBcs`)
|
|
6
|
+
// validates and constructs the class from it.
|
|
5
7
|
import { fromBase64 } from "@mysten/sui/utils";
|
|
6
8
|
// deno-lint-ignore no-explicit-any -- generated parse output is loosely typed
|
|
7
9
|
export function mapParty(id, d) {
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,mFAAmF;AACnF,
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,sCAAsC;AAEtC,mFAAmF;AACnF,gFAAgF;AAChF,gFAAgF;AAChF,8CAA8C;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CAAC,EAAU,EAAE,CAAM;IACzC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IACpB,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IAC5C,oEAAoE;IACpE,iFAAiF;IACjF,MAAM,YAAY,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACvF,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,YAAY,EAAE,QAAQ,IAAI,YAAY,IAAI,EAAE,CAAC;QAC9D,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAU,EAAE,EAAE,CAC3E,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAqB,EAAE,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,CACpE,CAAC;QACF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IACnE,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC;AAC/D,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAkB,CAAC;AACzE,CAAC"}
|
package/dist/queries.d.ts
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Reads an object's BCS content, or null when it does not exist. A missing
|
|
7
|
-
* object (e.g. an unset dynamic field) surfaces as a thrown "not found" from the
|
|
8
|
-
* Core API, not an empty result, so optional reads can treat it as absence.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getObjectContent(client: ClientWithCoreApi, objectId: string): Promise<Uint8Array | null>;
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type SuiClient } from "@misofm/effect";
|
|
3
|
+
import type { BcsDecodeError, ObjectNotFoundError, ObjectTypeMismatchError, SuiRpcError } from "@misofm/effect";
|
|
4
|
+
import { Party } from "./types.ts";
|
|
11
5
|
/** The `Party` struct tag of one partyos deployment. */
|
|
12
6
|
export declare function partyType(partyPackageId: string): string;
|
|
13
7
|
/** Fetches and parses a shared `Party` object of this deployment's partyos package. */
|
|
14
|
-
export declare
|
|
8
|
+
export declare const getPartyById: (partyId: string, partyPackageId: string) => Effect.Effect<Party, BcsDecodeError | ObjectNotFoundError | ObjectTypeMismatchError | SuiRpcError, SuiClient>;
|
|
15
9
|
/**
|
|
16
10
|
* Fetches and parses multiple shared `Party` objects in one Core request.
|
|
17
11
|
* Missing objects are skipped; an object of another type is an error.
|
|
18
12
|
*/
|
|
19
|
-
export declare
|
|
13
|
+
export declare const getPartiesByIds: (partyIds: readonly string[], partyPackageId: string) => Effect.Effect<Partial<Record<string, Party>>, BcsDecodeError | ObjectTypeMismatchError | SuiRpcError, SuiClient>;
|
|
20
14
|
/** Derives a party's `PartyAdminCap` id (it is a `derived_object` off the party UID). */
|
|
21
15
|
export declare function derivePartyAdminCapId(partyId: string, partyPackageId: string): string;
|
|
22
16
|
/**
|
|
23
17
|
* The group ids a party currently belongs to, read from its `MembershipKey`
|
|
24
18
|
* dynamic fields (the member-side record). No indexer required.
|
|
25
19
|
*/
|
|
26
|
-
export declare function getMemberships(
|
|
20
|
+
export declare function getMemberships(partyId: string): Effect.Effect<string[], SuiRpcError, SuiClient>;
|
|
27
21
|
/** The member ids invited to a group but not yet accepted (its `PendingInviteKey` fields). */
|
|
28
|
-
export declare function getPendingInvites(
|
|
22
|
+
export declare function getPendingInvites(groupId: string): Effect.Effect<string[], SuiRpcError, SuiClient>;
|
|
29
23
|
/**
|
|
30
24
|
* The group ids that have invited a party but are still awaiting its response.
|
|
31
25
|
* This reads the member-side `PendingMembershipKey` inbox index, so it only
|
|
32
26
|
* enumerates the target party's dynamic fields.
|
|
33
27
|
*/
|
|
34
|
-
export declare function getPendingMemberships(
|
|
28
|
+
export declare function getPendingMemberships(partyId: string): Effect.Effect<string[], SuiRpcError, SuiClient>;
|
|
35
29
|
/** Whether `memberId` currently holds a membership record for `groupId`. */
|
|
36
|
-
export declare
|
|
30
|
+
export declare const isMember: (memberId: string, groupId: string, partyPackageId: string) => Effect.Effect<boolean, SuiRpcError, SuiClient>;
|
|
37
31
|
//# sourceMappingURL=queries.d.ts.map
|
package/dist/queries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAGhD,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQhH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,wDAAwD;AACxD,wBAAgB,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAExD;AAYD,uFAAuF;AACvF,eAAO,MAAM,YAAY,4JAevB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,2KAiB1B,CAAC;AAEH,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAMrF;AAqBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,SAAS,CAAC,CAE/F;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,SAAS,CAAC,CAElG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,SAAS,CAAC,CAEtG;AAED,4EAA4E;AAC5E,eAAO,MAAM,QAAQ,+GAYnB,CAAC"}
|
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,gBAAg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AAQ,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";
|
|
@@ -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
|
package/src/queries.ts
CHANGED
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
// Typed reads: fetch an on-chain object (or dynamic field) via the Core API, BCS-parse
|
|
5
|
-
// it through the generated struct, and map to the public camelCase types.
|
|
5
|
+
// it through the generated struct, and map to the public camelCase types. Every read
|
|
6
|
+
// requires the `SuiClient` service (see `@misofm/effect`) instead of taking a client
|
|
7
|
+
// parameter; not-found and type-mismatch paths are typed failures, not thrown errors.
|
|
6
8
|
|
|
7
|
-
import
|
|
9
|
+
import { Effect, Option, Stream } from "effect";
|
|
8
10
|
import { deriveDynamicFieldID, deriveObjectID, normalizeStructTag } from "@mysten/sui/utils";
|
|
9
11
|
import { bcs } from "@mysten/sui/bcs";
|
|
12
|
+
import {
|
|
13
|
+
assertObjectType,
|
|
14
|
+
decodeBcs,
|
|
15
|
+
getObjectContent,
|
|
16
|
+
getObjectsContent,
|
|
17
|
+
getOptionalObjectContent,
|
|
18
|
+
listDynamicFields,
|
|
19
|
+
type SuiClient,
|
|
20
|
+
} from "@misofm/effect";
|
|
21
|
+
import type { BcsDecodeError, ObjectNotFoundError, ObjectTypeMismatchError, SuiRpcError } from "@misofm/effect";
|
|
10
22
|
import {
|
|
11
23
|
MembershipKey as MembershipKeyBcs,
|
|
12
24
|
Party as PartyBcs,
|
|
@@ -14,87 +26,63 @@ import {
|
|
|
14
26
|
PendingMembershipKey as PendingMembershipKeyBcs,
|
|
15
27
|
} from "./contracts/partyos/party.ts";
|
|
16
28
|
import { keyBytes, mapParty } from "./internal.ts";
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
/** True for the Core API's "object does not exist" error (a missing dynamic field). */
|
|
20
|
-
export function isNotFound(e: unknown): boolean {
|
|
21
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
22
|
-
return /not\s*found|does not exist|no object/i.test(msg);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Reads an object's BCS content, or null when it does not exist. A missing
|
|
27
|
-
* object (e.g. an unset dynamic field) surfaces as a thrown "not found" from the
|
|
28
|
-
* Core API, not an empty result, so optional reads can treat it as absence.
|
|
29
|
-
*/
|
|
30
|
-
export async function getObjectContent(client: ClientWithCoreApi, objectId: string): Promise<Uint8Array | null> {
|
|
31
|
-
try {
|
|
32
|
-
const { object } = await client.core.getObject({ objectId, include: { content: true } });
|
|
33
|
-
return object?.content ?? null;
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (isNotFound(e)) return null;
|
|
36
|
-
throw e;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
29
|
+
import { Party } from "./types.ts";
|
|
39
30
|
|
|
40
31
|
/** The `Party` struct tag of one partyos deployment. */
|
|
41
32
|
export function partyType(partyPackageId: string): string {
|
|
42
33
|
return normalizeStructTag(`${partyPackageId}::party::Party`);
|
|
43
34
|
}
|
|
44
35
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
(type?.endsWith("::party::Party") ? " (a Party from a different partyos deployment)" : ""),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
36
|
+
/** Decodes one object's BCS content into a `Party`, mapping the generated parse output first. */
|
|
37
|
+
function decodeParty(objectId: string, content: Uint8Array, expectedType: string) {
|
|
38
|
+
return decodeBcs(
|
|
39
|
+
{ parse: (bytes) => mapParty(objectId, PartyBcs.parse(bytes)) },
|
|
40
|
+
Party,
|
|
41
|
+
content,
|
|
42
|
+
{ type: expectedType, objectId },
|
|
43
|
+
);
|
|
56
44
|
}
|
|
57
45
|
|
|
58
46
|
/** Fetches and parses a shared `Party` object of this deployment's partyos package. */
|
|
59
|
-
export
|
|
60
|
-
client: ClientWithCoreApi,
|
|
47
|
+
export const getPartyById = Effect.fn("getPartyById")(function* (
|
|
61
48
|
partyId: string,
|
|
62
49
|
partyPackageId: string,
|
|
63
|
-
):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
): Effect.fn.Return<
|
|
51
|
+
Party,
|
|
52
|
+
ObjectNotFoundError | ObjectTypeMismatchError | BcsDecodeError | SuiRpcError,
|
|
53
|
+
SuiClient
|
|
54
|
+
> {
|
|
55
|
+
const expected = partyType(partyPackageId);
|
|
56
|
+
const object = yield* getObjectContent(partyId);
|
|
57
|
+
// A Party from another partyos package (a previous generation) parses
|
|
58
|
+
// identically but no deployed package accepts it, so the object's type is
|
|
59
|
+
// checked against the deployment before its content is trusted.
|
|
60
|
+
yield* assertObjectType(partyId, normalizeStructTag(object.type), expected);
|
|
61
|
+
return yield* decodeParty(partyId, object.content, expected);
|
|
62
|
+
});
|
|
75
63
|
|
|
76
64
|
/**
|
|
77
65
|
* Fetches and parses multiple shared `Party` objects in one Core request.
|
|
78
66
|
* Missing objects are skipped; an object of another type is an error.
|
|
79
67
|
*/
|
|
80
|
-
export
|
|
81
|
-
client: ClientWithCoreApi,
|
|
68
|
+
export const getPartiesByIds = Effect.fn("getPartiesByIds")(function* (
|
|
82
69
|
partyIds: readonly string[],
|
|
83
70
|
partyPackageId: string,
|
|
84
|
-
):
|
|
71
|
+
): Effect.fn.Return<
|
|
72
|
+
Partial<Record<string, Party>>,
|
|
73
|
+
ObjectTypeMismatchError | BcsDecodeError | SuiRpcError,
|
|
74
|
+
SuiClient
|
|
75
|
+
> {
|
|
85
76
|
if (partyIds.length === 0) return {};
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
include: { content: true },
|
|
89
|
-
});
|
|
77
|
+
const expected = partyType(partyPackageId);
|
|
78
|
+
const contentById = yield* getObjectsContent([...new Set(partyIds)]);
|
|
90
79
|
const parties: Partial<Record<string, Party>> = {};
|
|
91
|
-
for (const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
parties[obj.objectId] = mapParty(obj.objectId, PartyBcs.parse(obj.content));
|
|
80
|
+
for (const [objectId, { content, type }] of contentById) {
|
|
81
|
+
yield* assertObjectType(objectId, normalizeStructTag(type), expected);
|
|
82
|
+
parties[objectId] = yield* decodeParty(objectId, content, expected);
|
|
95
83
|
}
|
|
96
84
|
return parties;
|
|
97
|
-
}
|
|
85
|
+
});
|
|
98
86
|
|
|
99
87
|
/** Derives a party's `PartyAdminCap` id (it is a `derived_object` off the party UID). */
|
|
100
88
|
export function derivePartyAdminCapId(partyId: string, partyPackageId: string): string {
|
|
@@ -108,38 +96,33 @@ export function derivePartyAdminCapId(partyId: string, partyPackageId: string):
|
|
|
108
96
|
// === Group membership reads ===
|
|
109
97
|
|
|
110
98
|
/** Collects the ids stored in every dynamic-field key of `parentId` whose type ends with `keySuffix`. */
|
|
111
|
-
|
|
112
|
-
client: ClientWithCoreApi,
|
|
99
|
+
function collectKeyIds(
|
|
113
100
|
parentId: string,
|
|
114
101
|
keySuffix: string,
|
|
115
102
|
codec: { parse(bytes: Uint8Array): readonly unknown[] },
|
|
116
|
-
):
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
cursor = page.hasNextPage ? page.cursor : null;
|
|
128
|
-
} while (cursor);
|
|
129
|
-
return ids;
|
|
103
|
+
): Effect.Effect<string[], SuiRpcError, SuiClient> {
|
|
104
|
+
return listDynamicFields(parentId).pipe(
|
|
105
|
+
Stream.filter((f) => typeof f.name?.type === "string" && f.name.type.endsWith(keySuffix) && f.name.bcs != null),
|
|
106
|
+
Stream.map((f) => {
|
|
107
|
+
const [id] = codec.parse(keyBytes(f.name!.bcs));
|
|
108
|
+
return String(id);
|
|
109
|
+
}),
|
|
110
|
+
Stream.runCollect,
|
|
111
|
+
Effect.map((chunk) => Array.from(chunk)),
|
|
112
|
+
);
|
|
130
113
|
}
|
|
131
114
|
|
|
132
115
|
/**
|
|
133
116
|
* The group ids a party currently belongs to, read from its `MembershipKey`
|
|
134
117
|
* dynamic fields (the member-side record). No indexer required.
|
|
135
118
|
*/
|
|
136
|
-
export
|
|
137
|
-
return collectKeyIds(
|
|
119
|
+
export function getMemberships(partyId: string): Effect.Effect<string[], SuiRpcError, SuiClient> {
|
|
120
|
+
return collectKeyIds(partyId, "::party::MembershipKey", MembershipKeyBcs);
|
|
138
121
|
}
|
|
139
122
|
|
|
140
123
|
/** The member ids invited to a group but not yet accepted (its `PendingInviteKey` fields). */
|
|
141
|
-
export
|
|
142
|
-
return collectKeyIds(
|
|
124
|
+
export function getPendingInvites(groupId: string): Effect.Effect<string[], SuiRpcError, SuiClient> {
|
|
125
|
+
return collectKeyIds(groupId, "::party::PendingInviteKey", PendingInviteKeyBcs);
|
|
143
126
|
}
|
|
144
127
|
|
|
145
128
|
/**
|
|
@@ -147,21 +130,21 @@ export async function getPendingInvites(client: ClientWithCoreApi, groupId: stri
|
|
|
147
130
|
* This reads the member-side `PendingMembershipKey` inbox index, so it only
|
|
148
131
|
* enumerates the target party's dynamic fields.
|
|
149
132
|
*/
|
|
150
|
-
export
|
|
151
|
-
return collectKeyIds(
|
|
133
|
+
export function getPendingMemberships(partyId: string): Effect.Effect<string[], SuiRpcError, SuiClient> {
|
|
134
|
+
return collectKeyIds(partyId, "::party::PendingMembershipKey", PendingMembershipKeyBcs);
|
|
152
135
|
}
|
|
153
136
|
|
|
154
137
|
/** Whether `memberId` currently holds a membership record for `groupId`. */
|
|
155
|
-
export
|
|
156
|
-
client: ClientWithCoreApi,
|
|
138
|
+
export const isMember = Effect.fn("isMember")(function* (
|
|
157
139
|
memberId: string,
|
|
158
140
|
groupId: string,
|
|
159
141
|
partyPackageId: string,
|
|
160
|
-
):
|
|
142
|
+
): Effect.fn.Return<boolean, SuiRpcError, SuiClient> {
|
|
161
143
|
const fieldId = deriveDynamicFieldID(
|
|
162
144
|
memberId,
|
|
163
145
|
`${partyPackageId}::party::MembershipKey`,
|
|
164
146
|
MembershipKeyBcs.serialize([groupId]).toBytes(),
|
|
165
147
|
);
|
|
166
|
-
|
|
167
|
-
|
|
148
|
+
const content = yield* getOptionalObjectContent(fieldId);
|
|
149
|
+
return Option.isSome(content);
|
|
150
|
+
});
|
package/src/types.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
// Copyright (c) Miso Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
// Public, camelCase result types. The
|
|
5
|
-
// (snake_case, Move-shaped) parse output into
|
|
4
|
+
// Public, camelCase result types. The mapper in ./internal.ts turns the generated
|
|
5
|
+
// (snake_case, Move-shaped) parse output into the plain shape `Party` decodes from.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { Schema } from "effect";
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export const PartyKind = Schema.Literals(["individual", "group"]);
|
|
10
|
+
export type PartyKind = typeof PartyKind.Type;
|
|
11
|
+
|
|
12
|
+
export class Party extends Schema.Class<Party>("@misofm/partyos/Party")({
|
|
13
|
+
id: Schema.String,
|
|
14
|
+
kind: PartyKind,
|
|
12
15
|
/** Human-readable name (not verified). */
|
|
13
|
-
name:
|
|
16
|
+
name: Schema.String,
|
|
14
17
|
/** Member party ids — present only when `kind === "group"`. */
|
|
15
|
-
members
|
|
18
|
+
members: Schema.optional(Schema.Array(Schema.String)),
|
|
16
19
|
/** Unix ms when the party was created. */
|
|
17
|
-
createdAtMs:
|
|
18
|
-
}
|
|
20
|
+
createdAtMs: Schema.Number,
|
|
21
|
+
}) {}
|