@spellkave/session 0.0.0-stage → 0.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/LICENSE +89 -0
- package/bin/spellkave-session-daemon.js +5 -0
- package/package.json +58 -4
- package/src/acting-context.ts +222 -0
- package/src/authoring/caller-tools.ts +227 -0
- package/src/authoring/index.ts +28 -0
- package/src/authoring/live-applyset-port.ts +432 -0
- package/src/authoring/live-author-target.ts +995 -0
- package/src/authoring/live-can-i-port.ts +152 -0
- package/src/authoring/live-exploration-port.ts +274 -0
- package/src/authoring/live-grants-port.ts +172 -0
- package/src/authoring/live-scenes-port.ts +84 -0
- package/src/authoring/live-scoped-instance-port.ts +355 -0
- package/src/binding.ts +125 -0
- package/src/index.ts +24 -0
- package/src/live/discovery-closure-walk.ts +318 -0
- package/src/live/kernel-convergence-support.ts +122 -0
- package/src/live/seed.ts +37 -0
- package/src/live/support.ts +82 -0
- package/src/node/client.ts +233 -0
- package/src/node/connection-controller.ts +469 -0
- package/src/node/daemon-entry.ts +57 -0
- package/src/node/daemon.ts +629 -0
- package/src/node/index.ts +110 -0
- package/src/node/live-delta.ts +229 -0
- package/src/node/observability.ts +481 -0
- package/src/node/paths.ts +83 -0
- package/src/node/player-run-observer.ts +122 -0
- package/src/node/protocol.ts +200 -0
- package/src/node/spawn.ts +225 -0
- package/src/node/world-events.ts +270 -0
- package/src/player-tools/delta-tracker.ts +1 -0
- package/src/player-tools/index.ts +10 -0
- package/src/player-tools/node-adapter.ts +9 -0
- package/src/player-tools/observation.ts +1 -0
- package/src/player-tools/player-host.ts +92 -0
- package/src/player-tools/push-events.ts +1 -0
- package/src/player-tools/query-protocol.ts +1 -0
- package/src/player-tools/refusal-prose.ts +1 -0
- package/src/player-tools/resolution.ts +1 -0
- package/src/player-tools/tool-registry.ts +1 -0
- package/src/player-tools/tools.ts +42 -0
- package/src/player-tools/world-events.ts +119 -0
- package/src/session.ts +604 -0
- package/README.md +0 -3
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// The live `ApplysetPort` (ADR-0145) the two applyset tools
|
|
2
|
+
// (`spellkave_applyset_diff` / `_apply`) bind against: it reads the applyset
|
|
3
|
+
// memory over an SDK session and sends one `r_apply_bundle` call. Shared by
|
|
4
|
+
// `sk` (one connection per invocation) and the Pi extension (the connected
|
|
5
|
+
// session).
|
|
6
|
+
|
|
7
|
+
import { enqueueAndWaitManifestApply, snapshotDb } from "@spellkave/sdk";
|
|
8
|
+
import {
|
|
9
|
+
type ApplyBundleCall,
|
|
10
|
+
type ApplysetPort,
|
|
11
|
+
collectLivePlaces,
|
|
12
|
+
collectWorldRows,
|
|
13
|
+
resolveAuthoredEntityId,
|
|
14
|
+
type SnapshotLike,
|
|
15
|
+
} from "@spellkave/tool-authoring";
|
|
16
|
+
import type { ScopedSnapshotPort } from "@spellkave/world-author";
|
|
17
|
+
|
|
18
|
+
/** The baseline tables share one required, coherent subscription. */
|
|
19
|
+
// ci-allow(raw-sql): indexed publisher views and caller-filtered authority views required by the authoring port
|
|
20
|
+
const applysetQuery = (table: string) => `SELECT * FROM ${table}`;
|
|
21
|
+
const BASELINE_QUERIES = [
|
|
22
|
+
"operator_manifest_applyset",
|
|
23
|
+
"operator_manifest_applyset_part",
|
|
24
|
+
"operator_manifest_applyset_export_hash",
|
|
25
|
+
].map(applysetQuery);
|
|
26
|
+
const AUTHORITY_QUERIES = [
|
|
27
|
+
"visible_capability",
|
|
28
|
+
"visible_actor_identity",
|
|
29
|
+
"actor",
|
|
30
|
+
"visible_role_binding",
|
|
31
|
+
"extent_kind_definition",
|
|
32
|
+
"world_time",
|
|
33
|
+
"role_definition",
|
|
34
|
+
"role_aggregation",
|
|
35
|
+
"capability_definition",
|
|
36
|
+
].map(applysetQuery);
|
|
37
|
+
|
|
38
|
+
type Session = Parameters<typeof snapshotDb>[0] & {
|
|
39
|
+
readsAsPublisher?: boolean;
|
|
40
|
+
authenticatedIdentity?: unknown;
|
|
41
|
+
conn: {
|
|
42
|
+
isActive?: boolean;
|
|
43
|
+
subscriptionBuilder(): {
|
|
44
|
+
onApplied(cb: () => void): {
|
|
45
|
+
onError(cb: (ctx: { event?: Error }) => void): { subscribe(queries: string[]): unknown };
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
reducers: {
|
|
49
|
+
rApplyBundleScoped(args: {
|
|
50
|
+
deltaToml: string;
|
|
51
|
+
applyset: string;
|
|
52
|
+
rootPath: string;
|
|
53
|
+
partsJson: string;
|
|
54
|
+
expectedGeneration: bigint;
|
|
55
|
+
force: boolean;
|
|
56
|
+
bundleIds: string[];
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
rApplyBundle(args: {
|
|
59
|
+
deltaToml: string;
|
|
60
|
+
applyset: string;
|
|
61
|
+
rootPath: string;
|
|
62
|
+
partsJson: string;
|
|
63
|
+
expectedGeneration: bigint;
|
|
64
|
+
force: boolean;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
interface RawEntry {
|
|
71
|
+
kind: string;
|
|
72
|
+
key: string;
|
|
73
|
+
bundleId?: string | null;
|
|
74
|
+
hash: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function rows(handle: { iter(): Iterable<unknown> } | undefined): Record<string, unknown>[] {
|
|
78
|
+
return handle === undefined ? [] : ([...handle.iter()] as Record<string, unknown>[]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function identityText(value: unknown): string {
|
|
82
|
+
if (
|
|
83
|
+
typeof value === "object" &&
|
|
84
|
+
value !== null &&
|
|
85
|
+
"toHexString" in value &&
|
|
86
|
+
typeof value.toHexString === "function"
|
|
87
|
+
)
|
|
88
|
+
return value.toHexString();
|
|
89
|
+
return String(value ?? "");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** SpacetimeDB sum types arrive as `{ tag }`; older snapshots as a bare string. */
|
|
93
|
+
function baseState(value: unknown): "known" | "unknown" {
|
|
94
|
+
const tag =
|
|
95
|
+
typeof value === "object" && value !== null ? (value as { tag?: unknown }).tag : value;
|
|
96
|
+
return tag === "Unknown" ? "unknown" : "known";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type ApplysetPortSession = Session;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* `session` is a value or a thunk (a host whose connection comes and goes
|
|
103
|
+
* wires a thunk); `rootPathFor` is the host's root-path rule
|
|
104
|
+
* (`applysetRootPath` in `@spellkave/tool-node/authoring`).
|
|
105
|
+
*/
|
|
106
|
+
export function createLiveApplysetPort(deps: {
|
|
107
|
+
session: Session | (() => Session);
|
|
108
|
+
rootPathFor: (absoluteRootFile: string) => string;
|
|
109
|
+
/** `sk` sets this after passing the five `entity_definition_initial_*`
|
|
110
|
+
* tables in `readerManifests`. Pi does not. */
|
|
111
|
+
definitionTablesSubscribed?: boolean;
|
|
112
|
+
scopedSnapshot?: ScopedSnapshotPort;
|
|
113
|
+
}): ApplysetPort {
|
|
114
|
+
const current = (): Session =>
|
|
115
|
+
typeof deps.session === "function" ? (deps.session as () => Session)() : deps.session;
|
|
116
|
+
const baselines = new WeakMap<Session, Promise<void>>();
|
|
117
|
+
const authority = new WeakMap<Session, Promise<void>>();
|
|
118
|
+
const failed = new WeakSet<Session>();
|
|
119
|
+
const publisher = (session: Session): void => {
|
|
120
|
+
if (session.readsAsPublisher !== true)
|
|
121
|
+
throw Object.assign(new Error("baseline_unavailable: publisher baseline access required"), {
|
|
122
|
+
code: "baseline_unavailable",
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const subscribe = (
|
|
126
|
+
session: Session,
|
|
127
|
+
cache: WeakMap<Session, Promise<void>>,
|
|
128
|
+
queries: string[],
|
|
129
|
+
): Promise<void> => {
|
|
130
|
+
let pending = cache.get(session);
|
|
131
|
+
if (!pending) {
|
|
132
|
+
pending = new Promise<void>((resolve, reject) => {
|
|
133
|
+
session.conn
|
|
134
|
+
.subscriptionBuilder()
|
|
135
|
+
.onApplied(() => resolve())
|
|
136
|
+
.onError((ctx) => {
|
|
137
|
+
failed.add(session);
|
|
138
|
+
reject(
|
|
139
|
+
new Error(
|
|
140
|
+
`reader_unavailable: required authoring views unavailable: ${ctx.event?.message ?? "subscription refused"}`,
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
})
|
|
144
|
+
.subscribe(queries);
|
|
145
|
+
});
|
|
146
|
+
cache.set(session, pending);
|
|
147
|
+
}
|
|
148
|
+
return pending;
|
|
149
|
+
};
|
|
150
|
+
const readBaseline = async (session: Session) => {
|
|
151
|
+
publisher(session);
|
|
152
|
+
await subscribe(session, baselines, BASELINE_QUERIES);
|
|
153
|
+
if (failed.has(session) || current() !== session || session.conn.isActive === false)
|
|
154
|
+
throw new Error("reader_unavailable: connection changed");
|
|
155
|
+
const db = snapshotDb(session) as Record<string, { iter(): Iterable<unknown> } | undefined>;
|
|
156
|
+
const required = (snake: string, camel: string) => {
|
|
157
|
+
const handle = db[snake] ?? db[camel];
|
|
158
|
+
if (!handle) throw new Error("reader_unavailable: required publisher baseline view missing");
|
|
159
|
+
return rows(handle);
|
|
160
|
+
};
|
|
161
|
+
// No asynchronous boundary between these copies: all three were installed together.
|
|
162
|
+
return {
|
|
163
|
+
db,
|
|
164
|
+
roots: required("operator_manifest_applyset", "operatorManifestApplyset"),
|
|
165
|
+
parts: required("operator_manifest_applyset_part", "operatorManifestApplysetPart"),
|
|
166
|
+
hashes: required(
|
|
167
|
+
"operator_manifest_applyset_export_hash",
|
|
168
|
+
"operatorManifestApplysetExportHash",
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
readScopedSnapshot: deps.scopedSnapshot?.read.bind(deps.scopedSnapshot),
|
|
174
|
+
readApplyset: async (applyset) => {
|
|
175
|
+
const session = current();
|
|
176
|
+
const { db, roots, parts: baselineParts, hashes } = await readBaseline(session);
|
|
177
|
+
const head = roots.find((row) => row.applyset === applyset);
|
|
178
|
+
if (head === undefined) return null;
|
|
179
|
+
const parts = baselineParts
|
|
180
|
+
.filter((row) => row.applyset === applyset)
|
|
181
|
+
.map((row) => ({
|
|
182
|
+
path: String(row.partPath ?? row.part_path),
|
|
183
|
+
entries: (row.entries as RawEntry[]).map((entry) => ({
|
|
184
|
+
kind: entry.kind,
|
|
185
|
+
key: entry.key,
|
|
186
|
+
bundle_id: entry.bundleId ?? null,
|
|
187
|
+
hash: entry.hash,
|
|
188
|
+
})),
|
|
189
|
+
}));
|
|
190
|
+
return {
|
|
191
|
+
root_path: String(head.rootPath ?? head.root_path),
|
|
192
|
+
generation: Number(head.generation),
|
|
193
|
+
base_state: baseState(head.baseState ?? head.base_state),
|
|
194
|
+
parts,
|
|
195
|
+
export_hashes: hashes
|
|
196
|
+
.filter((r) => r.applyset === applyset)
|
|
197
|
+
.map((r) => ({
|
|
198
|
+
kind: String(r.kind),
|
|
199
|
+
key: String(r.key),
|
|
200
|
+
export_hash: String(r.exportHash ?? r.export_hash),
|
|
201
|
+
})),
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
readExtentScope: async () => {
|
|
205
|
+
const session = current();
|
|
206
|
+
const { db, roots, parts: baselineParts } = await readBaseline(session);
|
|
207
|
+
await subscribe(session, authority, AUTHORITY_QUERIES);
|
|
208
|
+
const bindings = rows(db.visible_role_binding ?? db.visibleRoleBinding);
|
|
209
|
+
const controlledActors = new Set(
|
|
210
|
+
rows(db.visible_actor_identity ?? db.visibleActorIdentity)
|
|
211
|
+
.filter(
|
|
212
|
+
(row) => identityText(row.identity) === identityText(session.authenticatedIdentity),
|
|
213
|
+
)
|
|
214
|
+
.map((row) => String(row.actorId)),
|
|
215
|
+
);
|
|
216
|
+
const controlledBodies = new Set(
|
|
217
|
+
rows(db.actor)
|
|
218
|
+
.filter((row) => controlledActors.has(String(row.actorId)))
|
|
219
|
+
.map((row) => String(row.currentBody)),
|
|
220
|
+
);
|
|
221
|
+
const presenceBodies = new Set(bindings.map((row) => String(row.presenceEntityId)));
|
|
222
|
+
const tick = BigInt(String(rows(db.world_time ?? db.worldTime)[0]?.tick ?? 0));
|
|
223
|
+
const grants = rows(db.visible_capability ?? db.visibleCapability).filter(
|
|
224
|
+
(row) =>
|
|
225
|
+
row.capabilityId === "frontier.apply_manifest" &&
|
|
226
|
+
controlledBodies.has(String(row.entityId)) &&
|
|
227
|
+
(row.expiresAtTick == null || BigInt(String(row.expiresAtTick)) > tick),
|
|
228
|
+
);
|
|
229
|
+
// A caller with no apply grant reaches the existing server authority refusal.
|
|
230
|
+
// This preserves prune visibility/force diagnostics without granting admission.
|
|
231
|
+
if (session.readsAsPublisher !== true && grants.length === 0) return undefined;
|
|
232
|
+
// The server retains this adapter for the deployed direct-grant catalog until .67.
|
|
233
|
+
if (
|
|
234
|
+
session.readsAsPublisher !== true &&
|
|
235
|
+
grants.some((row) => !presenceBodies.has(String(row.entityId)))
|
|
236
|
+
)
|
|
237
|
+
return undefined;
|
|
238
|
+
const definitions = rows(db.extent_kind_definition ?? db.extentKindDefinition);
|
|
239
|
+
const bundleExtents = grants
|
|
240
|
+
.filter(
|
|
241
|
+
(grant) =>
|
|
242
|
+
bindings.some(
|
|
243
|
+
(binding) =>
|
|
244
|
+
`role_binding:${String(binding.bindingId)}` === grant.source &&
|
|
245
|
+
(binding.expiresAtTick == null || BigInt(String(binding.expiresAtTick)) > tick) &&
|
|
246
|
+
String(binding.presenceEntityId) === String(grant.entityId),
|
|
247
|
+
) &&
|
|
248
|
+
definitions.some(
|
|
249
|
+
(kind) =>
|
|
250
|
+
kind.kindId === grant.extentKindRef &&
|
|
251
|
+
(kind.resolutionShape as { tag?: string })?.tag === "Bundle",
|
|
252
|
+
),
|
|
253
|
+
)
|
|
254
|
+
.map((row) => String(row.extentRef))
|
|
255
|
+
.filter((reference) => reference.length > 0);
|
|
256
|
+
const parts = baselineParts;
|
|
257
|
+
return {
|
|
258
|
+
publisher: session.readsAsPublisher === true,
|
|
259
|
+
bundle_extents: bundleExtents,
|
|
260
|
+
memory: roots.map((root) => ({
|
|
261
|
+
applyset: String(root.applyset),
|
|
262
|
+
bundle_ids: (root.bundleIds as string[] | undefined) ?? null,
|
|
263
|
+
entries: parts
|
|
264
|
+
.filter((part) => part.applyset === root.applyset)
|
|
265
|
+
.flatMap((part) =>
|
|
266
|
+
(part.entries as RawEntry[]).map((entry) => ({
|
|
267
|
+
kind: entry.kind,
|
|
268
|
+
key: entry.key,
|
|
269
|
+
bundle_id: entry.bundleId ?? null,
|
|
270
|
+
hash: entry.hash,
|
|
271
|
+
})),
|
|
272
|
+
),
|
|
273
|
+
})),
|
|
274
|
+
};
|
|
275
|
+
},
|
|
276
|
+
readAuthoritySnapshot: async () => {
|
|
277
|
+
const session = current();
|
|
278
|
+
await subscribe(session, authority, AUTHORITY_QUERIES);
|
|
279
|
+
const db = snapshotDb(session) as Record<string, { iter(): Iterable<unknown> } | undefined>;
|
|
280
|
+
const actors = new Set(
|
|
281
|
+
rows(db.visible_actor_identity ?? db.visibleActorIdentity)
|
|
282
|
+
.filter(
|
|
283
|
+
(row) => identityText(row.identity) === identityText(session.authenticatedIdentity),
|
|
284
|
+
)
|
|
285
|
+
.map((row) => String(row.actorId)),
|
|
286
|
+
);
|
|
287
|
+
const bodies = new Set(
|
|
288
|
+
rows(db.actor)
|
|
289
|
+
.filter((row) => actors.has(String(row.actorId)))
|
|
290
|
+
.map((row) => String(row.currentBody)),
|
|
291
|
+
);
|
|
292
|
+
const bindings = rows(db.visible_role_binding ?? db.visibleRoleBinding);
|
|
293
|
+
const presences = new Set(bindings.map((row) => String(row.presenceEntityId)));
|
|
294
|
+
const tick = Number(rows(db.world_time ?? db.worldTime)[0]?.tick ?? 0);
|
|
295
|
+
const live = (expiry: unknown) =>
|
|
296
|
+
expiry == null || Number(expiry) === 0 || tick < Number(expiry);
|
|
297
|
+
const grants = rows(db.visible_capability ?? db.visibleCapability).filter(
|
|
298
|
+
(row) =>
|
|
299
|
+
bodies.has(String(row.entityId)) &&
|
|
300
|
+
(row.expiresAtTick == null || tick < Number(row.expiresAtTick)) &&
|
|
301
|
+
(!String(row.source).startsWith("role_binding:") ||
|
|
302
|
+
bindings.some(
|
|
303
|
+
(binding) =>
|
|
304
|
+
`role_binding:${String(binding.bindingId)}` === row.source &&
|
|
305
|
+
String(binding.presenceEntityId) === String(row.entityId) &&
|
|
306
|
+
live(binding.expiresAtTick),
|
|
307
|
+
)),
|
|
308
|
+
);
|
|
309
|
+
return {
|
|
310
|
+
publisher: session.readsAsPublisher === true,
|
|
311
|
+
scoped: !grants.some(
|
|
312
|
+
(row) =>
|
|
313
|
+
row.capabilityId === "frontier.apply_manifest" && !presences.has(String(row.entityId)),
|
|
314
|
+
),
|
|
315
|
+
extent_shapes: Object.fromEntries(
|
|
316
|
+
rows(db.extent_kind_definition ?? db.extentKindDefinition).map((row) => [
|
|
317
|
+
String(row.kindId),
|
|
318
|
+
String((row.resolutionShape as { tag?: string })?.tag ?? row.resolutionShape)
|
|
319
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
320
|
+
.toLowerCase(),
|
|
321
|
+
]),
|
|
322
|
+
),
|
|
323
|
+
complete: [
|
|
324
|
+
"visible_role_binding",
|
|
325
|
+
"role_definition",
|
|
326
|
+
"role_aggregation",
|
|
327
|
+
"capability_definition",
|
|
328
|
+
"visible_capability",
|
|
329
|
+
"visible_actor_identity",
|
|
330
|
+
"actor",
|
|
331
|
+
"world_time",
|
|
332
|
+
].every((name) => db[name] !== undefined),
|
|
333
|
+
tick,
|
|
334
|
+
grants: grants.map((row) => ({
|
|
335
|
+
capability_id: String(row.capabilityId),
|
|
336
|
+
extent_kind_ref: String(row.extentKindRef),
|
|
337
|
+
extent_ref: String(row.extentRef),
|
|
338
|
+
expires_at_tick: row.expiresAtTick == null ? null : Number(row.expiresAtTick),
|
|
339
|
+
})),
|
|
340
|
+
role_definitions: rows(db.role_definition ?? db.roleDefinition).map((row) => ({
|
|
341
|
+
role_id: String(row.roleId),
|
|
342
|
+
bundle_id: String(row.bundleId),
|
|
343
|
+
display_name: String(row.displayName),
|
|
344
|
+
description: String(row.description),
|
|
345
|
+
capability_ids: row.capabilityIds as string[],
|
|
346
|
+
})),
|
|
347
|
+
role_aggregations: rows(db.role_aggregation ?? db.roleAggregation).map((row) => ({
|
|
348
|
+
role_id: String(row.roleId),
|
|
349
|
+
bundle_id: String(row.bundleId),
|
|
350
|
+
description: String(row.description),
|
|
351
|
+
capability_ids: row.capabilityIds as string[],
|
|
352
|
+
})),
|
|
353
|
+
capability_definitions: rows(db.capability_definition ?? db.capabilityDefinition).map(
|
|
354
|
+
(row) => ({
|
|
355
|
+
capability_id: String(row.capabilityId),
|
|
356
|
+
bundle_id: String(row.bundleId),
|
|
357
|
+
actor_kind: String(row.actorKind),
|
|
358
|
+
display_name: String(row.displayName),
|
|
359
|
+
description: String(row.description),
|
|
360
|
+
default_visibility: String(
|
|
361
|
+
(row.defaultVisibility as { tag?: string })?.tag ?? row.defaultVisibility ?? "Public",
|
|
362
|
+
).toLowerCase(),
|
|
363
|
+
}),
|
|
364
|
+
),
|
|
365
|
+
bindings: bindings.map((row) => ({
|
|
366
|
+
binding_id: String(row.bindingId),
|
|
367
|
+
bundle_id: String(row.bundleId),
|
|
368
|
+
role_id: String(row.roleId),
|
|
369
|
+
extent_kind_ref: String(row.extentKindRef),
|
|
370
|
+
extent_ref: String(row.extentRef),
|
|
371
|
+
realised: String(row.presenceEntityId) !== "0",
|
|
372
|
+
})),
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
applyBundle: async (call: ApplyBundleCall) => {
|
|
376
|
+
const session = current();
|
|
377
|
+
publisher(session);
|
|
378
|
+
const db = snapshotDb(session);
|
|
379
|
+
const result = await enqueueAndWaitManifestApply({
|
|
380
|
+
digestHandle: db.manifest_apply_digest,
|
|
381
|
+
outcomeHandle: db.manifest_apply_outcome,
|
|
382
|
+
enqueue: () =>
|
|
383
|
+
call.bundleIds === undefined
|
|
384
|
+
? session.conn.reducers.rApplyBundle({
|
|
385
|
+
...call,
|
|
386
|
+
expectedGeneration: BigInt(call.expectedGeneration),
|
|
387
|
+
})
|
|
388
|
+
: session.conn.reducers.rApplyBundleScoped({
|
|
389
|
+
...call,
|
|
390
|
+
bundleIds: call.bundleIds,
|
|
391
|
+
expectedGeneration: BigInt(call.expectedGeneration),
|
|
392
|
+
}),
|
|
393
|
+
label: "sk apply",
|
|
394
|
+
});
|
|
395
|
+
return result.ok ? { ok: true } : { ok: false, detail: result.detail };
|
|
396
|
+
},
|
|
397
|
+
rootPathFor: deps.rootPathFor,
|
|
398
|
+
readsAsPublisher: () => current().readsAsPublisher === true,
|
|
399
|
+
worldRows: (entityId) => {
|
|
400
|
+
const session = current();
|
|
401
|
+
if (session.readsAsPublisher !== true || deps.definitionTablesSubscribed !== true) {
|
|
402
|
+
return "not_subscribed";
|
|
403
|
+
}
|
|
404
|
+
return collectWorldRows(snapshotDb(session) as SnapshotLike, entityId);
|
|
405
|
+
},
|
|
406
|
+
authoredEntityId: (bundleId, entityKey) => {
|
|
407
|
+
const session = current();
|
|
408
|
+
if (session.readsAsPublisher !== true || deps.definitionTablesSubscribed !== true) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
return resolveAuthoredEntityId(snapshotDb(session) as SnapshotLike, bundleId, entityKey);
|
|
412
|
+
},
|
|
413
|
+
livePlaces: () => {
|
|
414
|
+
const session = current();
|
|
415
|
+
if (session.readsAsPublisher !== true || deps.definitionTablesSubscribed !== true) {
|
|
416
|
+
return "not_subscribed";
|
|
417
|
+
}
|
|
418
|
+
return collectLivePlaces(snapshotDb(session) as SnapshotLike);
|
|
419
|
+
},
|
|
420
|
+
publisherIdentity: () => {
|
|
421
|
+
const identity: unknown = current().authenticatedIdentity;
|
|
422
|
+
if (typeof identity === "string") return identity.replace(/^0x/i, "").toLowerCase();
|
|
423
|
+
if (identity && typeof identity === "object" && "toHexString" in identity) {
|
|
424
|
+
const hex = (identity as { toHexString?: () => string }).toHexString;
|
|
425
|
+
if (typeof hex === "function") {
|
|
426
|
+
return hex.call(identity).replace(/^0x/i, "").toLowerCase();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return identity === undefined || identity === null ? null : String(identity);
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
}
|