castle-web-sdk 0.4.45 → 0.4.47
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 +526 -53
- package/dist/agent.js +4 -4
- package/dist/avatar.d.ts +16 -0
- package/dist/avatar.js +31 -0
- package/dist/castle.d.ts +10 -1
- package/dist/castle.js +5 -0
- package/dist/commands.d.ts +237 -0
- package/dist/commands.js +16 -0
- package/dist/context.d.ts +6 -0
- package/dist/experiments.d.ts +15 -0
- package/dist/experiments.js +83 -0
- package/dist/hub.d.ts +89 -0
- package/dist/hub.js +120 -0
- package/dist/multiplayer.d.ts +86 -6
- package/dist/multiplayer.js +226 -9
- package/dist/save.d.ts +197 -0
- package/dist/save.js +526 -0
- package/dist/saveCoordinator.d.ts +39 -0
- package/dist/saveCoordinator.js +252 -0
- package/dist/server/hub.d.ts +256 -0
- package/dist/server/hub.js +195 -0
- package/dist/server/platformHandle.d.ts +80 -3
- package/dist/server/storage.d.ts +71 -4
- package/dist/server/storage.js +71 -5
- package/dist/server/wrapper.d.ts +123 -9
- package/dist/server/wrapper.js +478 -38
- package/dist/store.d.ts +3 -2
- package/dist/store.js +5 -0
- package/dist/transport.d.ts +2 -1
- package/dist/transport.js +13 -1
- package/package.json +1 -1
package/dist/save.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { CastleError } from "./errors";
|
|
2
|
+
import type { Json } from "./types";
|
|
3
|
+
export type SaveScope = "deck" | "user" | "private";
|
|
4
|
+
export interface SaveTarget {
|
|
5
|
+
scope: SaveScope;
|
|
6
|
+
/** A user target's player. Omitted means the current player. */
|
|
7
|
+
subject?: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
}
|
|
10
|
+
/** Opaque. A reset of the deck's storage makes every older revision stale. */
|
|
11
|
+
export type SaveRevision = string;
|
|
12
|
+
/** Opaque proof of the latest claim on a target. */
|
|
13
|
+
export type SaveWriter = string;
|
|
14
|
+
export type SaveRows = Record<string, Json>;
|
|
15
|
+
export type SaveSelection = {
|
|
16
|
+
prefix: string;
|
|
17
|
+
} | {
|
|
18
|
+
keys: string[];
|
|
19
|
+
};
|
|
20
|
+
export interface SaveReadTarget {
|
|
21
|
+
target: SaveTarget;
|
|
22
|
+
/** Omitted reads the whole target. */
|
|
23
|
+
select?: SaveSelection;
|
|
24
|
+
}
|
|
25
|
+
export interface SaveSnapshot {
|
|
26
|
+
access: string;
|
|
27
|
+
targets: {
|
|
28
|
+
target: SaveTarget;
|
|
29
|
+
/** Null means the target has never been initialized. */
|
|
30
|
+
revision: SaveRevision | null;
|
|
31
|
+
rows: SaveRows;
|
|
32
|
+
/** True when the rows cover the whole target, not a selection of it. */
|
|
33
|
+
complete: boolean;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
36
|
+
export interface SaveReceipt {
|
|
37
|
+
operationId: string;
|
|
38
|
+
access: string;
|
|
39
|
+
revisions: {
|
|
40
|
+
target: SaveTarget;
|
|
41
|
+
revision: SaveRevision;
|
|
42
|
+
}[];
|
|
43
|
+
writer?: SaveWriter;
|
|
44
|
+
}
|
|
45
|
+
export interface SaveCheck {
|
|
46
|
+
target: SaveTarget;
|
|
47
|
+
expectedRevision?: SaveRevision;
|
|
48
|
+
writer?: SaveWriter;
|
|
49
|
+
}
|
|
50
|
+
export interface SaveChange {
|
|
51
|
+
target: SaveTarget;
|
|
52
|
+
/** Null creates a target that has never been initialized. */
|
|
53
|
+
expectedRevision: SaveRevision | null;
|
|
54
|
+
writer?: SaveWriter;
|
|
55
|
+
put?: SaveRows;
|
|
56
|
+
remove?: string[];
|
|
57
|
+
/** Replaces every row of the target. Cannot be combined with put or remove. */
|
|
58
|
+
replace?: SaveRows;
|
|
59
|
+
}
|
|
60
|
+
export interface SaveTransactionInput {
|
|
61
|
+
operationId: string;
|
|
62
|
+
expectedAccess: string;
|
|
63
|
+
checks?: SaveCheck[];
|
|
64
|
+
changes: SaveChange[];
|
|
65
|
+
}
|
|
66
|
+
export interface SaveInitial {
|
|
67
|
+
target: SaveTarget;
|
|
68
|
+
rows: SaveRows;
|
|
69
|
+
}
|
|
70
|
+
export interface SaveClaimInput {
|
|
71
|
+
operationId: string;
|
|
72
|
+
expectedAccess?: string;
|
|
73
|
+
target: SaveTarget;
|
|
74
|
+
initial?: SaveInitial[];
|
|
75
|
+
/** Omitted loads the claimed and initial targets. */
|
|
76
|
+
load?: SaveReadTarget[];
|
|
77
|
+
}
|
|
78
|
+
export interface SaveInitializeInput {
|
|
79
|
+
operationId: string;
|
|
80
|
+
expectedAccess?: string;
|
|
81
|
+
initial: SaveInitial[];
|
|
82
|
+
/** Omitted loads the initial targets. */
|
|
83
|
+
load?: SaveReadTarget[];
|
|
84
|
+
}
|
|
85
|
+
export interface SaveOpened {
|
|
86
|
+
receipt: SaveReceipt;
|
|
87
|
+
snapshot: SaveSnapshot;
|
|
88
|
+
}
|
|
89
|
+
export interface SaveClaimed extends SaveOpened {
|
|
90
|
+
writer: SaveWriter;
|
|
91
|
+
}
|
|
92
|
+
export type SaveOperation = {
|
|
93
|
+
state: "committed";
|
|
94
|
+
receipt: SaveReceipt;
|
|
95
|
+
} | {
|
|
96
|
+
state: "unknown";
|
|
97
|
+
};
|
|
98
|
+
export type SaveVerb = "snapshot" | "transaction" | "claim" | "initialize" | "operation";
|
|
99
|
+
export interface SaveApi {
|
|
100
|
+
snapshot(input: {
|
|
101
|
+
targets: SaveReadTarget[];
|
|
102
|
+
}): Promise<SaveSnapshot>;
|
|
103
|
+
transaction(input: SaveTransactionInput): Promise<SaveReceipt>;
|
|
104
|
+
claim(input: SaveClaimInput): Promise<SaveClaimed>;
|
|
105
|
+
initialize(input: SaveInitializeInput): Promise<SaveOpened>;
|
|
106
|
+
operation(operationId: string): Promise<SaveOperation>;
|
|
107
|
+
}
|
|
108
|
+
export interface SaveBucketRead {
|
|
109
|
+
prefix: string;
|
|
110
|
+
select?: SaveSelection;
|
|
111
|
+
}
|
|
112
|
+
export interface SaveBucketApi {
|
|
113
|
+
/** This bucket's target for a prefix, for the root's multi-bucket calls. */
|
|
114
|
+
target(prefix: string): SaveTarget;
|
|
115
|
+
snapshot(input: SaveBucketRead): Promise<SaveSnapshot>;
|
|
116
|
+
transaction(input: {
|
|
117
|
+
operationId: string;
|
|
118
|
+
expectedAccess: string;
|
|
119
|
+
checks?: (Omit<SaveCheck, "target"> & {
|
|
120
|
+
prefix: string;
|
|
121
|
+
})[];
|
|
122
|
+
changes: (Omit<SaveChange, "target"> & {
|
|
123
|
+
prefix: string;
|
|
124
|
+
})[];
|
|
125
|
+
}): Promise<SaveReceipt>;
|
|
126
|
+
claim(input: {
|
|
127
|
+
operationId: string;
|
|
128
|
+
expectedAccess?: string;
|
|
129
|
+
prefix: string;
|
|
130
|
+
initial?: {
|
|
131
|
+
prefix: string;
|
|
132
|
+
rows: SaveRows;
|
|
133
|
+
}[];
|
|
134
|
+
load?: SaveBucketRead[];
|
|
135
|
+
}): Promise<SaveClaimed>;
|
|
136
|
+
initialize(input: {
|
|
137
|
+
operationId: string;
|
|
138
|
+
expectedAccess?: string;
|
|
139
|
+
initial: {
|
|
140
|
+
prefix: string;
|
|
141
|
+
rows: SaveRows;
|
|
142
|
+
}[];
|
|
143
|
+
load?: SaveBucketRead[];
|
|
144
|
+
}): Promise<SaveOpened>;
|
|
145
|
+
operation(operationId: string): Promise<SaveOperation>;
|
|
146
|
+
}
|
|
147
|
+
/** What a failed save says about itself, as the platform reports it. */
|
|
148
|
+
export interface SaveErrorEnvelope {
|
|
149
|
+
code: string;
|
|
150
|
+
message: string;
|
|
151
|
+
operationId?: string;
|
|
152
|
+
retryable: boolean;
|
|
153
|
+
/** "unknown" means the request may still have committed. */
|
|
154
|
+
committed: boolean | "unknown";
|
|
155
|
+
/** The stored receipt, when the operation committed earlier. */
|
|
156
|
+
receipt?: SaveReceipt;
|
|
157
|
+
retryAfterMs?: number;
|
|
158
|
+
target?: SaveTarget;
|
|
159
|
+
[detail: string]: unknown;
|
|
160
|
+
}
|
|
161
|
+
export declare class SaveError extends CastleError {
|
|
162
|
+
readonly operationId?: string;
|
|
163
|
+
readonly retryable: boolean;
|
|
164
|
+
readonly committed: boolean | "unknown";
|
|
165
|
+
readonly receipt?: SaveReceipt;
|
|
166
|
+
readonly retryAfterMs?: number;
|
|
167
|
+
readonly target?: SaveTarget;
|
|
168
|
+
constructor(envelope: SaveErrorEnvelope);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reads the envelope out of whatever a host or platform threw. A failure that
|
|
172
|
+
* does not say whether it committed is treated as one that might have.
|
|
173
|
+
*/
|
|
174
|
+
export declare function asSaveError(error: unknown, operationId?: string): SaveError;
|
|
175
|
+
/**
|
|
176
|
+
* A session server has no current player, so it names a user target's player
|
|
177
|
+
* and cannot reach private storage.
|
|
178
|
+
*/
|
|
179
|
+
export declare function validateSaveTarget(target: SaveTarget, server?: boolean): SaveTarget;
|
|
180
|
+
export declare function saveTargetKey(target: SaveTarget): string;
|
|
181
|
+
/**
|
|
182
|
+
* Finds the caller's own target for one the platform names. The platform
|
|
183
|
+
* fills in the current player as a user target's subject, so a target the
|
|
184
|
+
* caller left without a subject matches any subject.
|
|
185
|
+
*/
|
|
186
|
+
export declare function matchSaveTarget(target: SaveTarget, candidates: readonly SaveTarget[]): SaveTarget;
|
|
187
|
+
/** Validates and copies a request; the result is what goes on the wire. */
|
|
188
|
+
export declare function encodeSaveInput(verb: SaveVerb, input: Record<string, unknown>, server?: boolean): Record<string, unknown>;
|
|
189
|
+
/** Sends one encoded request; the transport behind it is the caller's. */
|
|
190
|
+
export type SaveCall = (verb: SaveVerb, input: Record<string, unknown>) => Promise<unknown>;
|
|
191
|
+
export declare function createSaveApi(call: SaveCall, server?: boolean): SaveApi;
|
|
192
|
+
export declare function createSaveBucket(api: SaveApi, scope: SaveScope, subject?: string): SaveBucketApi;
|
|
193
|
+
/**
|
|
194
|
+
* Refuses a request bigger than a transport carries. An atomic save is never
|
|
195
|
+
* split, so the whole encoded request has to fit.
|
|
196
|
+
*/
|
|
197
|
+
export declare function preflightSaveRequest(verb: SaveVerb, request: unknown, limitBytes: number): void;
|