@spawnco/sdk-types 0.0.1
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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/v1.d.ts +157 -0
- package/dist/v1.d.ts.map +1 -0
- package/dist/v1.js +1 -0
- package/package.json +38 -0
- package/src/index.ts +1 -0
- package/src/v1.ts +158 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v1';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v1.js';
|
package/dist/v1.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
type Scope = "global" | `room:${string}` | `user:${string}`;
|
|
2
|
+
type Cost = {
|
|
3
|
+
readUnits?: number;
|
|
4
|
+
writeUnits?: number;
|
|
5
|
+
usd?: number;
|
|
6
|
+
};
|
|
7
|
+
type Item = {
|
|
8
|
+
id: string;
|
|
9
|
+
data: unknown;
|
|
10
|
+
};
|
|
11
|
+
type Balance = Record<string, number>;
|
|
12
|
+
interface User {
|
|
13
|
+
id: string;
|
|
14
|
+
username: string;
|
|
15
|
+
avatarURL: string;
|
|
16
|
+
isGuest: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface UserModule {
|
|
19
|
+
me(): Promise<User>;
|
|
20
|
+
upgradeGuest(): Promise<User>;
|
|
21
|
+
}
|
|
22
|
+
interface StorageKV {
|
|
23
|
+
get<T = unknown>(key: string, opts?: {
|
|
24
|
+
scope?: Scope;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
value: T | null;
|
|
27
|
+
rev?: string;
|
|
28
|
+
}>;
|
|
29
|
+
put<T = unknown>(key: string, value: T, opts?: {
|
|
30
|
+
scope?: Scope;
|
|
31
|
+
rev?: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
rev: string;
|
|
34
|
+
cost: Cost;
|
|
35
|
+
}>;
|
|
36
|
+
del(key: string, opts?: {
|
|
37
|
+
scope?: Scope;
|
|
38
|
+
rev?: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
cost: Cost;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
interface StorageObj {
|
|
44
|
+
get<T = unknown>(key: string, opts?: {
|
|
45
|
+
scope?: Scope;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
value: T | null;
|
|
48
|
+
rev?: string;
|
|
49
|
+
}>;
|
|
50
|
+
set<T = unknown>(key: string, value: T, opts?: {
|
|
51
|
+
scope?: Scope;
|
|
52
|
+
rev?: string;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
rev: string;
|
|
55
|
+
cost: Cost;
|
|
56
|
+
}>;
|
|
57
|
+
del(key: string, opts?: {
|
|
58
|
+
scope?: Scope;
|
|
59
|
+
rev?: string;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
cost: Cost;
|
|
62
|
+
}>;
|
|
63
|
+
}
|
|
64
|
+
interface StorageLedger {
|
|
65
|
+
append<T>(stream: string, data: T): Promise<{
|
|
66
|
+
id: string;
|
|
67
|
+
ts: number;
|
|
68
|
+
data: T;
|
|
69
|
+
cost: Cost;
|
|
70
|
+
}>;
|
|
71
|
+
query<T>(stream: string, cursor?: string, limit?: number): Promise<{
|
|
72
|
+
entries: {
|
|
73
|
+
id: string;
|
|
74
|
+
ts: number;
|
|
75
|
+
data: T;
|
|
76
|
+
}[];
|
|
77
|
+
next?: string;
|
|
78
|
+
cost: Cost;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
interface StorageModule {
|
|
82
|
+
kv: StorageKV;
|
|
83
|
+
obj: StorageObj;
|
|
84
|
+
ledger: StorageLedger;
|
|
85
|
+
}
|
|
86
|
+
interface RoomInstance {
|
|
87
|
+
id: string;
|
|
88
|
+
state(): any;
|
|
89
|
+
broadcast<T>(type: string, payload: T): void;
|
|
90
|
+
on<T = any>(type: string, cb: (payload: T, peerId: string) => void): void;
|
|
91
|
+
unsubscribe<T = any>(type: string, cb: (payload: T, peerId: string) => void): void;
|
|
92
|
+
leave(): void;
|
|
93
|
+
}
|
|
94
|
+
interface RoomModule {
|
|
95
|
+
quick(): Promise<RoomInstance>;
|
|
96
|
+
create(opts?: {
|
|
97
|
+
maxPlayers?: number;
|
|
98
|
+
meta?: any;
|
|
99
|
+
}): Promise<string>;
|
|
100
|
+
join(roomId: string): Promise<RoomInstance>;
|
|
101
|
+
}
|
|
102
|
+
interface EconomyModule {
|
|
103
|
+
catalog(): Promise<{
|
|
104
|
+
id: string;
|
|
105
|
+
priceSBX: number;
|
|
106
|
+
meta?: any;
|
|
107
|
+
}[]>;
|
|
108
|
+
buy(itemId: string): Promise<{
|
|
109
|
+
ok: boolean;
|
|
110
|
+
receipt: string;
|
|
111
|
+
}>;
|
|
112
|
+
balance(kind?: "sbx" | "usd"): Promise<number>;
|
|
113
|
+
}
|
|
114
|
+
interface InventoryState {
|
|
115
|
+
items: Item[];
|
|
116
|
+
balances: Balance;
|
|
117
|
+
rev: string;
|
|
118
|
+
}
|
|
119
|
+
interface InventoryModule {
|
|
120
|
+
list(): Promise<InventoryState>;
|
|
121
|
+
claim(dropId: string, opts?: {
|
|
122
|
+
rev?: string;
|
|
123
|
+
}): Promise<InventoryState>;
|
|
124
|
+
on(event: "update", cb: (diff: Partial<InventoryState>) => void): void;
|
|
125
|
+
}
|
|
126
|
+
export interface SpawnClientSDK__V1 {
|
|
127
|
+
user: UserModule;
|
|
128
|
+
storage: StorageModule;
|
|
129
|
+
room: RoomModule;
|
|
130
|
+
economy: EconomyModule;
|
|
131
|
+
inventory: InventoryModule;
|
|
132
|
+
ai?: never;
|
|
133
|
+
auction?: never;
|
|
134
|
+
}
|
|
135
|
+
export interface SpawnClientSDK__V0 {
|
|
136
|
+
ready: () => Promise<boolean>;
|
|
137
|
+
user: UserModule;
|
|
138
|
+
}
|
|
139
|
+
interface WorkerInventory {
|
|
140
|
+
applyDiff(userId: string, diff: {
|
|
141
|
+
addItems?: Item[];
|
|
142
|
+
removeItems?: string[];
|
|
143
|
+
incBalance?: Balance;
|
|
144
|
+
}): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
interface WorkerEconomy {
|
|
147
|
+
creditSBX(userId: string, amount: number): Promise<void>;
|
|
148
|
+
grant(userId: string, itemOrCoins: string | number): Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
export interface SpawnServerSDK__V1 {
|
|
151
|
+
storage: StorageModule;
|
|
152
|
+
room: RoomModule;
|
|
153
|
+
inventory: WorkerInventory;
|
|
154
|
+
economy: WorkerEconomy;
|
|
155
|
+
}
|
|
156
|
+
export {};
|
|
157
|
+
//# sourceMappingURL=v1.d.ts.map
|
package/dist/v1.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../src/v1.ts"],"names":[],"mappings":"AACA,KAAK,KAAK,GAAG,QAAQ,GAAG,QAAQ,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,CAAC;AAC5D,KAAK,IAAI,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACtE,KAAK,IAAI,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAC1C,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtC,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,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CAAC;IACjB,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,aAAa,CAAC;CACxB"}
|
package/dist/v1.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spawnco/sdk-types",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "TypeScript type definitions for Spawn SDK",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup --watch"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"spawn",
|
|
25
|
+
"sdk",
|
|
26
|
+
"types",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"author": "Spawn",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"typescript": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v1';
|
package/src/v1.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Common types
|
|
2
|
+
type Scope = "global" | `room:${string}` | `user:${string}`;
|
|
3
|
+
type Cost = { readUnits?: number; writeUnits?: number; usd?: number };
|
|
4
|
+
type Item = { id: string; data: unknown };
|
|
5
|
+
type Balance = Record<string, number>;
|
|
6
|
+
|
|
7
|
+
interface User {
|
|
8
|
+
id: string;
|
|
9
|
+
username: string;
|
|
10
|
+
avatarURL: string;
|
|
11
|
+
isGuest: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// User module
|
|
15
|
+
interface UserModule {
|
|
16
|
+
me(): Promise<User>;
|
|
17
|
+
upgradeGuest(): Promise<User>; // prompts sign-in
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Storage module
|
|
21
|
+
interface StorageKV {
|
|
22
|
+
get<T = unknown>(
|
|
23
|
+
key: string,
|
|
24
|
+
opts?: { scope?: Scope }
|
|
25
|
+
): Promise<{ value: T | null; rev?: string }>;
|
|
26
|
+
put<T = unknown>(
|
|
27
|
+
key: string,
|
|
28
|
+
value: T,
|
|
29
|
+
opts?: { scope?: Scope; rev?: string }
|
|
30
|
+
): Promise<{ rev: string; cost: Cost }>;
|
|
31
|
+
del(
|
|
32
|
+
key: string,
|
|
33
|
+
opts?: { scope?: Scope; rev?: string }
|
|
34
|
+
): Promise<{ cost: Cost }>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface StorageObj {
|
|
38
|
+
get<T = unknown>(
|
|
39
|
+
key: string,
|
|
40
|
+
opts?: { scope?: Scope }
|
|
41
|
+
): Promise<{ value: T | null; rev?: string }>;
|
|
42
|
+
set<T = unknown>(
|
|
43
|
+
key: string,
|
|
44
|
+
value: T,
|
|
45
|
+
opts?: { scope?: Scope; rev?: string }
|
|
46
|
+
): Promise<{ rev: string; cost: Cost }>;
|
|
47
|
+
del(
|
|
48
|
+
key: string,
|
|
49
|
+
opts?: { scope?: Scope; rev?: string }
|
|
50
|
+
): Promise<{ cost: Cost }>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface StorageLedger {
|
|
54
|
+
append<T>(
|
|
55
|
+
stream: string,
|
|
56
|
+
data: T
|
|
57
|
+
): Promise<{
|
|
58
|
+
id: string;
|
|
59
|
+
ts: number;
|
|
60
|
+
data: T;
|
|
61
|
+
cost: Cost;
|
|
62
|
+
}>;
|
|
63
|
+
query<T>(
|
|
64
|
+
stream: string,
|
|
65
|
+
cursor?: string,
|
|
66
|
+
limit?: number
|
|
67
|
+
): Promise<{
|
|
68
|
+
entries: { id: string; ts: number; data: T }[];
|
|
69
|
+
next?: string;
|
|
70
|
+
cost: Cost;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface StorageModule {
|
|
75
|
+
kv: StorageKV;
|
|
76
|
+
obj: StorageObj;
|
|
77
|
+
ledger: StorageLedger;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Room module
|
|
81
|
+
interface RoomInstance {
|
|
82
|
+
id: string;
|
|
83
|
+
state(): any;
|
|
84
|
+
broadcast<T>(type: string, payload: T): void;
|
|
85
|
+
on<T = any>(type: string, cb: (payload: T, peerId: string) => void): void;
|
|
86
|
+
unsubscribe<T = any>(
|
|
87
|
+
type: string,
|
|
88
|
+
cb: (payload: T, peerId: string) => void
|
|
89
|
+
): void;
|
|
90
|
+
leave(): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface RoomModule {
|
|
94
|
+
quick(): Promise<RoomInstance>;
|
|
95
|
+
create(opts?: { maxPlayers?: number; meta?: any }): Promise<string>;
|
|
96
|
+
join(roomId: string): Promise<RoomInstance>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Economy module
|
|
100
|
+
interface EconomyModule {
|
|
101
|
+
catalog(): Promise<{ id: string; priceSBX: number; meta?: any }[]>;
|
|
102
|
+
buy(itemId: string): Promise<{ ok: boolean; receipt: string }>;
|
|
103
|
+
balance(kind?: "sbx" | "usd"): Promise<number>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Inventory module
|
|
107
|
+
interface InventoryState {
|
|
108
|
+
items: Item[];
|
|
109
|
+
balances: Balance;
|
|
110
|
+
rev: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface InventoryModule {
|
|
114
|
+
list(): Promise<InventoryState>;
|
|
115
|
+
claim(dropId: string, opts?: { rev?: string }): Promise<InventoryState>;
|
|
116
|
+
on(event: "update", cb: (diff: Partial<InventoryState>) => void): void;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Client SDK interface
|
|
120
|
+
export interface SpawnClientSDK__V1 {
|
|
121
|
+
user: UserModule;
|
|
122
|
+
storage: StorageModule;
|
|
123
|
+
room: RoomModule;
|
|
124
|
+
economy: EconomyModule;
|
|
125
|
+
inventory: InventoryModule;
|
|
126
|
+
// Reserved for future use
|
|
127
|
+
ai?: never;
|
|
128
|
+
auction?: never;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface SpawnClientSDK__V0 {
|
|
132
|
+
ready: () => Promise<boolean>;
|
|
133
|
+
user: UserModule;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Worker interface
|
|
137
|
+
interface WorkerInventory {
|
|
138
|
+
applyDiff(
|
|
139
|
+
userId: string,
|
|
140
|
+
diff: {
|
|
141
|
+
addItems?: Item[];
|
|
142
|
+
removeItems?: string[];
|
|
143
|
+
incBalance?: Balance;
|
|
144
|
+
}
|
|
145
|
+
): Promise<void>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
interface WorkerEconomy {
|
|
149
|
+
creditSBX(userId: string, amount: number): Promise<void>;
|
|
150
|
+
grant(userId: string, itemOrCoins: string | number): Promise<void>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface SpawnServerSDK__V1 {
|
|
154
|
+
storage: StorageModule;
|
|
155
|
+
room: RoomModule;
|
|
156
|
+
inventory: WorkerInventory;
|
|
157
|
+
economy: WorkerEconomy;
|
|
158
|
+
}
|