@crowdedkingdoms/crowdyjs 8.0.1 → 8.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.
- package/README.md +41 -1
- package/dist/crowdy-client.d.ts +15 -0
- package/dist/crowdy-client.d.ts.map +1 -1
- package/dist/crowdy-client.js +17 -0
- package/dist/generated/graphql.d.ts +77 -0
- package/dist/generated/graphql.d.ts.map +1 -1
- package/dist/generated/graphql.js +7 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/kit/blueprints.d.ts +259 -0
- package/dist/kit/blueprints.d.ts.map +1 -0
- package/dist/kit/blueprints.js +480 -0
- package/dist/kit/index.d.ts +7 -0
- package/dist/kit/index.d.ts.map +1 -0
- package/dist/kit/index.js +6 -0
- package/dist/kit/inventory.d.ts +111 -0
- package/dist/kit/inventory.d.ts.map +1 -0
- package/dist/kit/inventory.js +158 -0
- package/dist/kit/kit.d.ts +96 -0
- package/dist/kit/kit.d.ts.map +1 -0
- package/dist/kit/kit.js +98 -0
- package/dist/kit/npcs.d.ts +182 -0
- package/dist/kit/npcs.d.ts.map +1 -0
- package/dist/kit/npcs.js +106 -0
- package/dist/kit/objects.d.ts +108 -0
- package/dist/kit/objects.d.ts.map +1 -0
- package/dist/kit/objects.js +110 -0
- package/dist/kit/shared.d.ts +32 -0
- package/dist/kit/shared.d.ts.map +1 -0
- package/dist/kit/shared.js +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { GameModelAPI } from '../domains/gameModel.js';
|
|
2
|
+
import type { Scalars, SeedPropertyInput } from '../generated/graphql.js';
|
|
3
|
+
import { type KitInvokeResult } from './shared.js';
|
|
4
|
+
/** Options for {@link ObjectsKit}. Must match the deployed lock blueprint. */
|
|
5
|
+
export interface ObjectsKitOptions {
|
|
6
|
+
/** The `objectTypeName` the lock blueprint was deployed with. Defaults to `'Lockable'`. */
|
|
7
|
+
objectTypeName?: string;
|
|
8
|
+
/** The `keyTypeName` the lock blueprint was deployed with. */
|
|
9
|
+
keyTypeName?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Runtime helpers for the {@link lockBlueprint} conventions: instantiate
|
|
13
|
+
* lockable world objects, grant key items, and operate the objects through
|
|
14
|
+
* their authority-gated `open`/`close` functions. Authorization is decided
|
|
15
|
+
* entirely server-side; a denied attempt resolves with `success: false`.
|
|
16
|
+
*
|
|
17
|
+
* Obtained via `client.kit(appId).objects` (or `client.kit(appId)
|
|
18
|
+
* .objectsFor('Door')` for a non-default type name).
|
|
19
|
+
*/
|
|
20
|
+
export declare class ObjectsKit {
|
|
21
|
+
private readonly appId;
|
|
22
|
+
private readonly gameModel;
|
|
23
|
+
private readonly names;
|
|
24
|
+
constructor(appId: Scalars['BigInt']['input'], gameModel: GameModelAPI, options?: ObjectsKitOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Instantiate a lockable object (admin/studio call — the type is
|
|
27
|
+
* admin-instantiable). For key-gated objects set `requiredKeyId` to the key
|
|
28
|
+
* id that opens it; for owner-gated objects set `ownerUserId`.
|
|
29
|
+
*/
|
|
30
|
+
create(input: {
|
|
31
|
+
displayName: string;
|
|
32
|
+
requiredKeyId?: string;
|
|
33
|
+
ownerUserId?: Scalars['BigInt']['input'];
|
|
34
|
+
properties?: SeedPropertyInput[];
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
__typename?: "GmContainer";
|
|
38
|
+
containerId: string;
|
|
39
|
+
appId: string;
|
|
40
|
+
sessionId: string | null;
|
|
41
|
+
typeName: string;
|
|
42
|
+
displayName: string;
|
|
43
|
+
description: string | null;
|
|
44
|
+
ownerUserId: string | null;
|
|
45
|
+
metadataJson: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Grant a player a key item (admin/studio call). Creates a key container
|
|
49
|
+
* owned by the player, with the owner mirrored into the `owner_user_id`
|
|
50
|
+
* property that the key condition policy reads.
|
|
51
|
+
*/
|
|
52
|
+
grantKey(input: {
|
|
53
|
+
keyId: string;
|
|
54
|
+
toUserId: Scalars['BigInt']['input'];
|
|
55
|
+
displayName?: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
__typename?: "GmContainer";
|
|
58
|
+
containerId: string;
|
|
59
|
+
appId: string;
|
|
60
|
+
sessionId: string | null;
|
|
61
|
+
typeName: string;
|
|
62
|
+
displayName: string;
|
|
63
|
+
description: string | null;
|
|
64
|
+
ownerUserId: string | null;
|
|
65
|
+
metadataJson: string;
|
|
66
|
+
}>;
|
|
67
|
+
/** List the key items a player holds. */
|
|
68
|
+
keysOf(userId: Scalars['BigInt']['input']): Promise<{
|
|
69
|
+
__typename?: "GmContainer";
|
|
70
|
+
containerId: string;
|
|
71
|
+
appId: string;
|
|
72
|
+
sessionId: string | null;
|
|
73
|
+
typeName: string;
|
|
74
|
+
displayName: string;
|
|
75
|
+
description: string | null;
|
|
76
|
+
ownerUserId: string | null;
|
|
77
|
+
metadataJson: string;
|
|
78
|
+
}[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Try to open an object. Pass `keyId` (the **container id** of a key the
|
|
81
|
+
* caller holds) when the object is key-gated; owner/grid/group authorities
|
|
82
|
+
* need no params. A denial is not an exception — check `success`.
|
|
83
|
+
*/
|
|
84
|
+
open(objectId: string, options?: {
|
|
85
|
+
keyId?: string;
|
|
86
|
+
}): Promise<KitInvokeResult<boolean>>;
|
|
87
|
+
/** Try to close an object; same authority as {@link open}. */
|
|
88
|
+
close(objectId: string, options?: {
|
|
89
|
+
keyId?: string;
|
|
90
|
+
}): Promise<KitInvokeResult<boolean>>;
|
|
91
|
+
/** Read whether an object is currently open. */
|
|
92
|
+
isOpen(objectId: string): Promise<boolean>;
|
|
93
|
+
/** List all objects of this lockable type. */
|
|
94
|
+
list(options?: {
|
|
95
|
+
sessionId?: string;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
__typename?: "GmContainer";
|
|
98
|
+
containerId: string;
|
|
99
|
+
appId: string;
|
|
100
|
+
sessionId: string | null;
|
|
101
|
+
typeName: string;
|
|
102
|
+
displayName: string;
|
|
103
|
+
description: string | null;
|
|
104
|
+
ownerUserId: string | null;
|
|
105
|
+
metadataJson: string;
|
|
106
|
+
}[]>;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../src/kit/objects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAErB,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,2FAA2F;IAC3F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,qBAAa,UAAU;IAInB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJ5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;gBAGf,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EACjC,SAAS,EAAE,YAAY,EACxC,OAAO,GAAE,iBAAsB;IAKjC;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;QACzC,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAC;QACjC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;IAwBD;;;;OAIG;IACG,QAAQ,CAAC,KAAK,EAAE;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;QACrC,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB;;;;;;;;;;;IAiBD,yCAAyC;IACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;;;;;;;;;;;IAU/C;;;;OAIG;IACG,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC/B,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IASpC,8DAA8D;IACxD,KAAK,CACT,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC/B,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IASpC,gDAAgD;IAC1C,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAShD,8CAA8C;IACxC,IAAI,CAAC,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO;;;;;;;;;;;CAOhD"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { lockNames } from './blueprints.js';
|
|
2
|
+
import { kitContainerProperties, kitInvoke, } from './shared.js';
|
|
3
|
+
/**
|
|
4
|
+
* Runtime helpers for the {@link lockBlueprint} conventions: instantiate
|
|
5
|
+
* lockable world objects, grant key items, and operate the objects through
|
|
6
|
+
* their authority-gated `open`/`close` functions. Authorization is decided
|
|
7
|
+
* entirely server-side; a denied attempt resolves with `success: false`.
|
|
8
|
+
*
|
|
9
|
+
* Obtained via `client.kit(appId).objects` (or `client.kit(appId)
|
|
10
|
+
* .objectsFor('Door')` for a non-default type name).
|
|
11
|
+
*/
|
|
12
|
+
export class ObjectsKit {
|
|
13
|
+
constructor(appId, gameModel, options = {}) {
|
|
14
|
+
this.appId = appId;
|
|
15
|
+
this.gameModel = gameModel;
|
|
16
|
+
this.names = lockNames(options.objectTypeName, options.keyTypeName);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Instantiate a lockable object (admin/studio call — the type is
|
|
20
|
+
* admin-instantiable). For key-gated objects set `requiredKeyId` to the key
|
|
21
|
+
* id that opens it; for owner-gated objects set `ownerUserId`.
|
|
22
|
+
*/
|
|
23
|
+
async create(input) {
|
|
24
|
+
const properties = [
|
|
25
|
+
{ key: 'is_open', valueType: 'bool', valueJson: 'false' },
|
|
26
|
+
...(input.requiredKeyId !== undefined
|
|
27
|
+
? [
|
|
28
|
+
{
|
|
29
|
+
key: 'required_key_id',
|
|
30
|
+
valueType: 'string',
|
|
31
|
+
valueJson: JSON.stringify(input.requiredKeyId),
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
: []),
|
|
35
|
+
...(input.properties ?? []),
|
|
36
|
+
];
|
|
37
|
+
return this.gameModel.createContainer({
|
|
38
|
+
appId: this.appId,
|
|
39
|
+
typeName: this.names.objectType,
|
|
40
|
+
displayName: input.displayName,
|
|
41
|
+
...(input.ownerUserId !== undefined ? { ownerUserId: input.ownerUserId } : {}),
|
|
42
|
+
...(input.sessionId !== undefined ? { sessionId: input.sessionId } : {}),
|
|
43
|
+
properties,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Grant a player a key item (admin/studio call). Creates a key container
|
|
48
|
+
* owned by the player, with the owner mirrored into the `owner_user_id`
|
|
49
|
+
* property that the key condition policy reads.
|
|
50
|
+
*/
|
|
51
|
+
async grantKey(input) {
|
|
52
|
+
return this.gameModel.createContainer({
|
|
53
|
+
appId: this.appId,
|
|
54
|
+
typeName: this.names.keyType,
|
|
55
|
+
displayName: input.displayName ?? `Key ${input.keyId}`,
|
|
56
|
+
ownerUserId: input.toUserId,
|
|
57
|
+
properties: [
|
|
58
|
+
{ key: 'key_id', valueType: 'string', valueJson: JSON.stringify(input.keyId) },
|
|
59
|
+
{
|
|
60
|
+
key: 'owner_user_id',
|
|
61
|
+
valueType: 'int',
|
|
62
|
+
valueJson: String(input.toUserId),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** List the key items a player holds. */
|
|
68
|
+
async keysOf(userId) {
|
|
69
|
+
const containers = await this.gameModel.containers({
|
|
70
|
+
appId: this.appId,
|
|
71
|
+
typeName: this.names.keyType,
|
|
72
|
+
});
|
|
73
|
+
return containers.filter((c) => c.ownerUserId != null && String(c.ownerUserId) === String(userId));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Try to open an object. Pass `keyId` (the **container id** of a key the
|
|
77
|
+
* caller holds) when the object is key-gated; owner/grid/group authorities
|
|
78
|
+
* need no params. A denial is not an exception — check `success`.
|
|
79
|
+
*/
|
|
80
|
+
async open(objectId, options = {}) {
|
|
81
|
+
return kitInvoke(this.gameModel, {
|
|
82
|
+
appId: String(this.appId),
|
|
83
|
+
functionName: this.names.openFn,
|
|
84
|
+
selfContainerId: objectId,
|
|
85
|
+
params: options.keyId !== undefined ? { key_id: options.keyId } : {},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Try to close an object; same authority as {@link open}. */
|
|
89
|
+
async close(objectId, options = {}) {
|
|
90
|
+
return kitInvoke(this.gameModel, {
|
|
91
|
+
appId: String(this.appId),
|
|
92
|
+
functionName: this.names.closeFn,
|
|
93
|
+
selfContainerId: objectId,
|
|
94
|
+
params: options.keyId !== undefined ? { key_id: options.keyId } : {},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Read whether an object is currently open. */
|
|
98
|
+
async isOpen(objectId) {
|
|
99
|
+
const props = await kitContainerProperties(this.gameModel, String(this.appId), objectId);
|
|
100
|
+
return props.is_open === true;
|
|
101
|
+
}
|
|
102
|
+
/** List all objects of this lockable type. */
|
|
103
|
+
async list(options = {}) {
|
|
104
|
+
return this.gameModel.containers({
|
|
105
|
+
appId: this.appId,
|
|
106
|
+
typeName: this.names.objectType,
|
|
107
|
+
...(options.sessionId !== undefined ? { sessionId: options.sessionId } : {}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { GameModelAPI } from '../domains/gameModel.js';
|
|
2
|
+
import type { GameModelInvokeMutation } from '../generated/graphql.js';
|
|
3
|
+
/** The raw server result of a `gameModelInvoke` call. */
|
|
4
|
+
export type RawInvokeResult = GameModelInvokeMutation['gameModelInvoke'];
|
|
5
|
+
/**
|
|
6
|
+
* A kit invoke outcome: the server's authority/evaluation verdict plus the
|
|
7
|
+
* parsed return value. Authority denials and expression errors are **not**
|
|
8
|
+
* exceptions — check {@link success}.
|
|
9
|
+
*/
|
|
10
|
+
export interface KitInvokeResult<T = unknown> {
|
|
11
|
+
/** `false` when the invoke policy denied the caller or the logic errored (rolled back). */
|
|
12
|
+
success: boolean;
|
|
13
|
+
/** The parsed `returnValueJson`, when present and `success` is true. */
|
|
14
|
+
returnValue?: T;
|
|
15
|
+
/** The server's error message when `success` is false. */
|
|
16
|
+
errorMessage?: string;
|
|
17
|
+
/** The full server result (event id, applied mutations, …). */
|
|
18
|
+
raw: RawInvokeResult;
|
|
19
|
+
}
|
|
20
|
+
/** Wrap a raw invoke result, parsing the JSON return value. */
|
|
21
|
+
export declare function toKitInvokeResult<T>(raw: RawInvokeResult): KitInvokeResult<T>;
|
|
22
|
+
/** Invoke a model function and wrap the result. */
|
|
23
|
+
export declare function kitInvoke<T = unknown>(gameModel: GameModelAPI, input: {
|
|
24
|
+
appId: string;
|
|
25
|
+
functionName: string;
|
|
26
|
+
selfContainerId: string;
|
|
27
|
+
params?: Record<string, unknown>;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
}): Promise<KitInvokeResult<T>>;
|
|
30
|
+
/** Read a container's visible properties as a parsed object. */
|
|
31
|
+
export declare function kitContainerProperties(gameModel: GameModelAPI, appId: string, containerId: string): Promise<Record<string, unknown>>;
|
|
32
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/kit/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,yDAAyD;AACzD,MAAM,MAAM,eAAe,GAAG,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,2FAA2F;IAC3F,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,CAAC,CAAC;IAChB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,GAAG,EAAE,eAAe,CAAC;CACtB;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,CAe7E;AAED,mDAAmD;AACnD,wBAAsB,SAAS,CAAC,CAAC,GAAG,OAAO,EACzC,SAAS,EAAE,YAAY,EACvB,KAAK,EAAE;IACL,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACA,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAS7B;AAED,gEAAgE;AAChE,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,YAAY,EACvB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAOlC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Wrap a raw invoke result, parsing the JSON return value. */
|
|
2
|
+
export function toKitInvokeResult(raw) {
|
|
3
|
+
let returnValue;
|
|
4
|
+
if (raw.success && raw.returnValueJson != null) {
|
|
5
|
+
try {
|
|
6
|
+
returnValue = JSON.parse(raw.returnValueJson);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
returnValue = undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
success: raw.success,
|
|
14
|
+
returnValue,
|
|
15
|
+
errorMessage: raw.errorMessage ?? undefined,
|
|
16
|
+
raw,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Invoke a model function and wrap the result. */
|
|
20
|
+
export async function kitInvoke(gameModel, input) {
|
|
21
|
+
const raw = await gameModel.invoke({
|
|
22
|
+
appId: input.appId,
|
|
23
|
+
functionName: input.functionName,
|
|
24
|
+
selfContainerId: input.selfContainerId,
|
|
25
|
+
paramsJson: JSON.stringify(input.params ?? {}),
|
|
26
|
+
...(input.sessionId !== undefined ? { sessionId: input.sessionId } : {}),
|
|
27
|
+
});
|
|
28
|
+
return toKitInvokeResult(raw);
|
|
29
|
+
}
|
|
30
|
+
/** Read a container's visible properties as a parsed object. */
|
|
31
|
+
export async function kitContainerProperties(gameModel, appId, containerId) {
|
|
32
|
+
const state = await gameModel.containerState({ appId, containerId });
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(state.propertiesJson);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
}
|