@voltro/plugin-inventory 0.0.0-stage → 0.87.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/CHANGELOG.md +24329 -0
- package/LICENSE +61 -0
- package/README.md +441 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +7737 -0
- package/dist/capture.js +53 -0
- package/dist/catalog.d.ts +63 -0
- package/dist/catalog.js +5 -0
- package/dist/cmsCatalog.d.ts +95 -0
- package/dist/cmsCatalog.js +80 -0
- package/dist/components.d.ts +247 -0
- package/dist/components.js +321 -0
- package/dist/crafting.d.ts +211 -0
- package/dist/crafting.js +193 -0
- package/dist/declarationFixtures.js +66 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +22 -0
- package/dist/index.d.ts +576 -0
- package/dist/index.js +8 -0
- package/dist/inventoryPort.fixture.js +66 -0
- package/dist/inventoryPresentation.js +109 -0
- package/dist/inventoryStore.js +1576 -0
- package/dist/inventoryUiCopy.js +63 -0
- package/dist/item.d.ts +73 -0
- package/dist/item.js +105 -0
- package/dist/plugin.js +407 -0
- package/dist/port.js +5 -0
- package/dist/reservation.js +85 -0
- package/dist/rpc.d.ts +145 -0
- package/dist/rpc.js +135 -0
- package/dist/server.d.ts +816 -0
- package/dist/server.js +4 -0
- package/dist/sqlCatalog.js +185 -0
- package/dist/strategies.d.ts +64 -0
- package/dist/strategies.js +47 -0
- package/dist/systemFixtures.js +172 -0
- package/dist/tables.entity.js +164 -0
- package/dist/testing.d.ts +448 -0
- package/dist/testing.js +4 -0
- package/dist/web.d.ts +60 -0
- package/dist/web.js +7 -0
- package/package.json +104 -4
|
@@ -0,0 +1,1576 @@
|
|
|
1
|
+
import { InventoryError as e, inventoryError as t } from "./errors.js";
|
|
2
|
+
import { identifier as n, integer as r, jsonData as i, list as a, object as o } from "./capture.js";
|
|
3
|
+
import { captureCraftPayment as s, captureCraftPlan as c, defineRecipe as l, resolveCraftPlan as u, resolveCraftingOptions as d } from "./crafting.js";
|
|
4
|
+
import { captureCatalogItem as f, captureItemContracts as p, validateInstanceAttributes as m } from "./item.js";
|
|
5
|
+
import { captureInventoryReservationTransferInput as h, captureInventoryReserveTransferInput as g, captureReservationItems as _ } from "./reservation.js";
|
|
6
|
+
import { inventoryItemsTable as v, inventoryLedgerTable as y, inventoryLoadoutsTable as b, inventoryOperationsTable as x, inventoryRecipesTable as S, inventorySubjectsTable as C } from "./tables.entity.js";
|
|
7
|
+
import { catalogScope as w, inventoryHash as T, inventoryIo as E, inventoryKey as D } from "./sqlCatalog.js";
|
|
8
|
+
import { defaultExpiryPolicy as O, defaultStackPolicy as k, resolveExpiry as A, resolveStack as ee } from "./strategies.js";
|
|
9
|
+
import { Effect as j, Result as M } from "effect";
|
|
10
|
+
import { and as N, eq as P, inSet as F, queryFor as I } from "@voltro/database";
|
|
11
|
+
import { executeSqlMutations as L, prepareSqlMutation as te, prepareSqlMutationGroup as ne } from "@voltro/database/sql";
|
|
12
|
+
//#region src/inventoryStore.ts
|
|
13
|
+
var R = (e) => {
|
|
14
|
+
let i = o(e, [
|
|
15
|
+
"items",
|
|
16
|
+
"catalogSource",
|
|
17
|
+
"channel",
|
|
18
|
+
"locale",
|
|
19
|
+
"allowedServices",
|
|
20
|
+
"slotSets",
|
|
21
|
+
"maxInstances",
|
|
22
|
+
"maxLedgerRows",
|
|
23
|
+
"now",
|
|
24
|
+
"stackPolicy",
|
|
25
|
+
"expiryPolicy",
|
|
26
|
+
"crafting"
|
|
27
|
+
]), s = i.crafting === void 0 ? void 0 : d(i.crafting);
|
|
28
|
+
if (s?.service) throw t("invalid_input");
|
|
29
|
+
let c = p(i.items), l = o(i.catalogSource);
|
|
30
|
+
if (s?.recipes.some((e) => [...e.inputs, ...e.outputs].some((e) => !c.some((t) => t.id === e.itemId)))) throw t("invalid_input");
|
|
31
|
+
let u = i.now ?? Date.now, f = i.stackPolicy ?? k, m = i.expiryPolicy ?? O;
|
|
32
|
+
if (s?.version === "default.v1" && (f !== k || m !== O) || typeof l.read != "function" || typeof u != "function" || typeof f != "function" || typeof m != "function") throw t("invalid_input");
|
|
33
|
+
let h = o(i.slotSets ?? {}), g = Object.create(null);
|
|
34
|
+
if (Object.keys(h).length > 32) throw t("limit_exceeded");
|
|
35
|
+
for (let [e, r] of Object.entries(h)) {
|
|
36
|
+
let i = a(r, 64).map(n);
|
|
37
|
+
if (i.length === 0 || new Set(i).size !== i.length) throw t("invalid_slot");
|
|
38
|
+
g[n(e)] = Object.freeze(i);
|
|
39
|
+
}
|
|
40
|
+
let _ = a(i.allowedServices ?? [], 256).map(n);
|
|
41
|
+
if (new Set(_).size !== _.length) throw t("invalid_input");
|
|
42
|
+
return Object.freeze({
|
|
43
|
+
items: c,
|
|
44
|
+
catalogSource: Object.freeze({ read: l.read.bind(i.catalogSource) }),
|
|
45
|
+
channel: n(i.channel),
|
|
46
|
+
locale: n(i.locale),
|
|
47
|
+
slotSets: Object.freeze(g),
|
|
48
|
+
allowedServices: Object.freeze(_),
|
|
49
|
+
maxInstances: r(i.maxInstances ?? 4096, 1, 1e4),
|
|
50
|
+
maxLedgerRows: r(i.maxLedgerRows ?? 1e4, 1, 1e5),
|
|
51
|
+
crafting: s,
|
|
52
|
+
now: u,
|
|
53
|
+
stackPolicy: f,
|
|
54
|
+
expiryPolicy: m
|
|
55
|
+
});
|
|
56
|
+
}, z = (e) => {
|
|
57
|
+
let r = o(e, ["ownerKind", "ownerId"]);
|
|
58
|
+
if (r.ownerKind !== "player" && r.ownerKind !== "guild") throw t("invalid_input");
|
|
59
|
+
return Object.freeze({
|
|
60
|
+
ownerKind: r.ownerKind,
|
|
61
|
+
ownerId: n(r.ownerId)
|
|
62
|
+
});
|
|
63
|
+
}, B = (e) => {
|
|
64
|
+
let n = e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : NaN;
|
|
65
|
+
if (!Number.isSafeInteger(n) || n < 0 || n > 864e13) throw t("invalid_record");
|
|
66
|
+
return n;
|
|
67
|
+
}, V = (d, p) => {
|
|
68
|
+
let O = R(p), V = new Set(O.allowedServices), re = () => r(O.now(), 0, 864e13), H = (e) => e.type === "system" || e.type === "service" && V.has(e.service), U = (e) => {
|
|
69
|
+
if (e.type !== "user") throw t("forbidden");
|
|
70
|
+
return {
|
|
71
|
+
tenantId: n(e.tenantId),
|
|
72
|
+
owner: z({
|
|
73
|
+
ownerKind: "player",
|
|
74
|
+
ownerId: e.id
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
}, W = (e, t) => D("ivs_", e, t.ownerKind, t.ownerId), ie = (e, t) => N(P("tenantId", e), P("ownerKind", t.ownerKind), P("ownerId", t.ownerId)), G = async (e, t) => {
|
|
78
|
+
let n = W(e, t);
|
|
79
|
+
try {
|
|
80
|
+
await d.insertIgnore(C.tableName, {
|
|
81
|
+
id: n,
|
|
82
|
+
tenantId: e,
|
|
83
|
+
...t,
|
|
84
|
+
erased: !1,
|
|
85
|
+
admission: 0,
|
|
86
|
+
sequence: 0
|
|
87
|
+
}, { conflictColumns: ["id"] });
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if (!(await d.query(I(C).where(P("id", n)).limit(1).descriptor))[0]) throw e;
|
|
90
|
+
}
|
|
91
|
+
}, ae = (e, n, r, i = !1) => {
|
|
92
|
+
if (e) {
|
|
93
|
+
if (e.tenantId !== n || e.ownerKind !== r.ownerKind) throw t("invalid_record");
|
|
94
|
+
if (e.erased === !0) {
|
|
95
|
+
if (i && e.ownerId === null) return;
|
|
96
|
+
throw t("erased");
|
|
97
|
+
}
|
|
98
|
+
if (e.ownerId !== r.ownerId || e.erased !== !1) throw t("invalid_record");
|
|
99
|
+
}
|
|
100
|
+
}, K = async (e, n, r, i = !1) => {
|
|
101
|
+
let a = W(n, r);
|
|
102
|
+
if (await e.updateMany(C.tableName, { admission: 0 }, { where: P("id", a) }) !== 1) throw t("unavailable");
|
|
103
|
+
let o = (await e.query(I(C).where(P("id", a)).limit(1).descriptor))[0];
|
|
104
|
+
if (!o) throw t("invalid_record");
|
|
105
|
+
return ae(o, n, r, i), o;
|
|
106
|
+
}, q = async (e, n, r, i, a) => {
|
|
107
|
+
let o = await e.query(I(n).where(ie(r, i)).orderBy("id", "asc").limit(a + 1).descriptor);
|
|
108
|
+
if (o.length > a) throw t("limit_exceeded");
|
|
109
|
+
if (o.some((e) => e.tenantId !== r || e.ownerKind !== i.ownerKind || e.ownerId !== i.ownerId)) throw t("invalid_record");
|
|
110
|
+
return o;
|
|
111
|
+
}, J = (e) => {
|
|
112
|
+
let a = O.items.find((t) => t.id === e.itemId && t.schemaVersion === e.schemaVersion);
|
|
113
|
+
if (!a || typeof e.locked != "boolean") throw t("invalid_record");
|
|
114
|
+
let o = n(e.id), s = r(e.qty, 1, a.maxStack), c = B(e.acquiredAt), l = e.expiresAt === null ? null : B(e.expiresAt);
|
|
115
|
+
if (!/^ivi_[0-9a-f]{56}$/.test(o) || l !== null && l <= c) throw t("invalid_record");
|
|
116
|
+
let u = i(e.attributes);
|
|
117
|
+
return m(a, O.items, u), Object.freeze({
|
|
118
|
+
id: o,
|
|
119
|
+
itemId: a.id,
|
|
120
|
+
schemaVersion: a.schemaVersion,
|
|
121
|
+
qty: s,
|
|
122
|
+
attributes: u,
|
|
123
|
+
acquiredAt: c,
|
|
124
|
+
expiresAt: l,
|
|
125
|
+
locked: e.locked,
|
|
126
|
+
source: n(e.source)
|
|
127
|
+
});
|
|
128
|
+
}, oe = (e) => ({
|
|
129
|
+
id: e.id,
|
|
130
|
+
itemId: e.itemId,
|
|
131
|
+
schemaVersion: e.schemaVersion,
|
|
132
|
+
qty: e.qty,
|
|
133
|
+
attributes: e.attributes,
|
|
134
|
+
acquiredAt: new Date(e.acquiredAt),
|
|
135
|
+
expiresAt: e.expiresAt === null ? null : new Date(e.expiresAt),
|
|
136
|
+
locked: e.locked,
|
|
137
|
+
source: e.source
|
|
138
|
+
}), Y = (e, i) => {
|
|
139
|
+
let c = o(e.receipt, [
|
|
140
|
+
"operationId",
|
|
141
|
+
"kind",
|
|
142
|
+
"changes",
|
|
143
|
+
"at"
|
|
144
|
+
]);
|
|
145
|
+
if (c.operationId !== e.id || c.kind !== i) throw t("invalid_record");
|
|
146
|
+
let u = r(c.at, 0, 864e13);
|
|
147
|
+
if (B(e.createdAt) > u) throw t("invalid_record");
|
|
148
|
+
let d = a(c.changes, O.maxInstances).map((e) => {
|
|
149
|
+
let t = o(e, ["instanceId", "delta"]);
|
|
150
|
+
return Object.freeze({
|
|
151
|
+
instanceId: n(t.instanceId),
|
|
152
|
+
delta: r(t.delta, -1e6, 1e6)
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
if (new Set(d.map((e) => e.instanceId)).size !== d.length) throw t("invalid_record");
|
|
156
|
+
if (i === "reserve" || i === "release") {
|
|
157
|
+
let n = ce(e, i, u);
|
|
158
|
+
if (d.length !== n.selections.length || d.some((e, t) => e.delta !== 0 || e.instanceId !== n.selections[t]?.instanceId)) throw t("invalid_record");
|
|
159
|
+
} else if (e.reservation !== null) throw t("invalid_record");
|
|
160
|
+
if (i === "transfer-out" || i === "transfer-in") {
|
|
161
|
+
let n = Z(e, i, u);
|
|
162
|
+
if (d.length !== n.selections.length || d.some((e, t) => {
|
|
163
|
+
let r = n.selections[t];
|
|
164
|
+
return !r || e.instanceId !== (i === "transfer-out" ? r.instanceId : r.destinationId) || e.delta !== (i === "transfer-out" ? -r.qty : r.qty);
|
|
165
|
+
})) throw t("invalid_record");
|
|
166
|
+
} else if (e.transfer !== null) throw t("invalid_record");
|
|
167
|
+
if (i === "craft") {
|
|
168
|
+
let t = o(e.craft, [
|
|
169
|
+
"intent",
|
|
170
|
+
"recipe",
|
|
171
|
+
"version",
|
|
172
|
+
"batches",
|
|
173
|
+
"catalogRevision",
|
|
174
|
+
"excludedIds",
|
|
175
|
+
"plan",
|
|
176
|
+
"payment"
|
|
177
|
+
]);
|
|
178
|
+
s(t.payment, l(t.recipe), r(t.batches, 1, 1e3));
|
|
179
|
+
}
|
|
180
|
+
return Object.freeze({
|
|
181
|
+
operationId: String(e.id),
|
|
182
|
+
kind: i,
|
|
183
|
+
changes: Object.freeze(d),
|
|
184
|
+
at: u
|
|
185
|
+
});
|
|
186
|
+
}, X = (e, t) => D("ivz_", e, t), se = (e, t, n, r) => D("ivo_", e, t.ownerKind, t.ownerId, X(n, r)), ce = (e, i, s) => {
|
|
187
|
+
let c = o(e.reservation, [
|
|
188
|
+
"intent",
|
|
189
|
+
"reservationId",
|
|
190
|
+
"catalogRevision",
|
|
191
|
+
"selections"
|
|
192
|
+
]), l = o(c.intent, [
|
|
193
|
+
"tenantId",
|
|
194
|
+
"owner",
|
|
195
|
+
"requestId",
|
|
196
|
+
"kind",
|
|
197
|
+
"payload"
|
|
198
|
+
]), u = z(l.owner), d = n(l.tenantId), p = n(c.reservationId), m = o(l.payload, i === "reserve" ? ["reservationId", "items"] : ["reservationId"]);
|
|
199
|
+
if (l.kind !== i || m.reservationId !== p || l.requestId !== X(i, p) || e.id !== se(d, u, i, p) || e.tenantId !== d || e.ownerKey !== W(d, u) || T(l) !== e.digest) throw t("invalid_record");
|
|
200
|
+
let h = Object.freeze(a(c.selections, 32).map((e) => {
|
|
201
|
+
let a = o(e, [
|
|
202
|
+
"instanceId",
|
|
203
|
+
"qty",
|
|
204
|
+
"item",
|
|
205
|
+
"before"
|
|
206
|
+
]), c = o(a.before, [
|
|
207
|
+
"id",
|
|
208
|
+
"itemId",
|
|
209
|
+
"schemaVersion",
|
|
210
|
+
"qty",
|
|
211
|
+
"attributes",
|
|
212
|
+
"acquiredAt",
|
|
213
|
+
"expiresAt",
|
|
214
|
+
"locked",
|
|
215
|
+
"source"
|
|
216
|
+
]), l = r(c.acquiredAt, 0, s), u = c.expiresAt === null ? null : r(c.expiresAt, l + 1, 864e13), d = J({
|
|
217
|
+
...c,
|
|
218
|
+
acquiredAt: new Date(l),
|
|
219
|
+
expiresAt: u === null ? null : new Date(u)
|
|
220
|
+
}), p = f(a.item, O.items), m = n(a.instanceId), h = r(a.qty, 1, d.qty);
|
|
221
|
+
if (!p.tradable || p.id !== d.itemId || p.schemaVersion !== d.schemaVersion || m !== d.id || d.locked !== (i === "release") || i === "reserve" && d.expiresAt !== null && d.expiresAt <= s) throw t("invalid_record");
|
|
222
|
+
return Object.freeze({
|
|
223
|
+
instanceId: m,
|
|
224
|
+
qty: h,
|
|
225
|
+
item: p,
|
|
226
|
+
before: d
|
|
227
|
+
});
|
|
228
|
+
})), g = _(h.map((e) => ({
|
|
229
|
+
instanceId: e.instanceId,
|
|
230
|
+
qty: e.qty
|
|
231
|
+
})));
|
|
232
|
+
if (T(g) !== T(h.map((e) => ({
|
|
233
|
+
instanceId: e.instanceId,
|
|
234
|
+
qty: e.qty
|
|
235
|
+
}))) || i === "reserve" && T(g) !== T(_(m.items))) throw t("invalid_record");
|
|
236
|
+
let v = i === "reserve" ? n(c.catalogRevision) : c.catalogRevision === null ? null : (() => {
|
|
237
|
+
throw t("invalid_record");
|
|
238
|
+
})();
|
|
239
|
+
return Object.freeze({
|
|
240
|
+
intent: {
|
|
241
|
+
tenantId: d,
|
|
242
|
+
owner: u,
|
|
243
|
+
requestId: n(l.requestId),
|
|
244
|
+
kind: i,
|
|
245
|
+
payload: m
|
|
246
|
+
},
|
|
247
|
+
reservationId: p,
|
|
248
|
+
catalogRevision: v,
|
|
249
|
+
selections: h
|
|
250
|
+
});
|
|
251
|
+
}, le = async (e, n, r, i) => {
|
|
252
|
+
let a = (await e.query(I(x).where(P("id", se(n, r, "reserve", i))).limit(1).descriptor))[0];
|
|
253
|
+
if (!a || a.state !== "committed") throw t("not_found");
|
|
254
|
+
let o = Y(a, "reserve"), s = ce(a, "reserve", o.at);
|
|
255
|
+
if (s.intent.tenantId !== n || T(s.intent.owner) !== T(r) || s.reservationId !== i) throw t("invalid_record");
|
|
256
|
+
return {
|
|
257
|
+
receipt: o,
|
|
258
|
+
accepted: s
|
|
259
|
+
};
|
|
260
|
+
}, ue = async (e, r) => {
|
|
261
|
+
let { tenantId: i, owner: s, kind: c, payload: l } = e, u = n(l.reservationId);
|
|
262
|
+
if (c === "release") return d.transactional(async (n) => {
|
|
263
|
+
await K(n, i, s);
|
|
264
|
+
let a = await le(n, i, s, u);
|
|
265
|
+
if (a.receipt.at > r) throw t("invalid_record");
|
|
266
|
+
let o = (await q(n, v, i, s, O.maxInstances)).map(J), c = Object.freeze(a.accepted.selections.map((e) => {
|
|
267
|
+
let n = Object.freeze({
|
|
268
|
+
...e.before,
|
|
269
|
+
locked: !0
|
|
270
|
+
}), r = o.find((t) => t.id === e.instanceId);
|
|
271
|
+
if (!r || T(r) !== T(n)) throw t("conflict");
|
|
272
|
+
return Object.freeze({
|
|
273
|
+
...e,
|
|
274
|
+
before: n
|
|
275
|
+
});
|
|
276
|
+
}));
|
|
277
|
+
return Object.freeze({
|
|
278
|
+
intent: e,
|
|
279
|
+
reservationId: u,
|
|
280
|
+
catalogRevision: null,
|
|
281
|
+
selections: c
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
if (c !== "reserve") throw t("invalid_input");
|
|
285
|
+
let p = await j.runPromise(j.result(O.catalogSource.read(w({
|
|
286
|
+
tenantId: i,
|
|
287
|
+
channel: O.channel,
|
|
288
|
+
locale: O.locale
|
|
289
|
+
}))));
|
|
290
|
+
if (M.isFailure(p)) throw p.failure;
|
|
291
|
+
let m = o(p.success, ["revision", "items"]), h = n(m.revision), g = a(m.items, 1e4).map((e) => f(e, O.items));
|
|
292
|
+
if (new Set(g.map((e) => e.id)).size !== g.length) throw t("invalid_record");
|
|
293
|
+
let y = _(l.items);
|
|
294
|
+
return d.transactional(async (n) => {
|
|
295
|
+
await K(n, i, s);
|
|
296
|
+
let a = (await q(n, v, i, s, O.maxInstances)).map(J), o = await q(n, b, i, s, 2048), c = Object.freeze(y.map((e) => {
|
|
297
|
+
let n = a.find((t) => t.id === e.instanceId);
|
|
298
|
+
if (!n) throw t("not_found");
|
|
299
|
+
if (n.locked || o.some((e) => e.instanceId === n.id)) throw t("locked");
|
|
300
|
+
if (n.acquiredAt > r || n.expiresAt !== null && n.expiresAt <= r) throw t("expired");
|
|
301
|
+
if (e.qty > n.qty) throw t("insufficient_items");
|
|
302
|
+
let i = g.find((e) => e.id === n.itemId && e.schemaVersion === n.schemaVersion);
|
|
303
|
+
if (!i || !i.tradable) throw t("invalid_item");
|
|
304
|
+
return Object.freeze({
|
|
305
|
+
...e,
|
|
306
|
+
item: i,
|
|
307
|
+
before: n
|
|
308
|
+
});
|
|
309
|
+
}));
|
|
310
|
+
return Object.freeze({
|
|
311
|
+
intent: e,
|
|
312
|
+
reservationId: u,
|
|
313
|
+
catalogRevision: h,
|
|
314
|
+
selections: c
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}, de = (e, t, n) => e === "transfer-out" ? D("ivz_", e, t) : D("ivz_", e, t, n), Z = (e, i, s) => {
|
|
318
|
+
let c = o(e.transfer, ["intent"]), l = o(c.intent, [
|
|
319
|
+
"tenantId",
|
|
320
|
+
"owner",
|
|
321
|
+
"requestId",
|
|
322
|
+
"kind",
|
|
323
|
+
"payload"
|
|
324
|
+
]), u = z(l.owner), d = n(l.tenantId), p = W(d, u), m = o(l.payload, [
|
|
325
|
+
"reservationId",
|
|
326
|
+
"peerKey",
|
|
327
|
+
"peerOperationId",
|
|
328
|
+
"selections"
|
|
329
|
+
]), h = n(m.reservationId), g = n(m.peerKey), v = n(m.peerOperationId), y = i === "transfer-out" ? p : g, b = i === "transfer-out" ? g : p;
|
|
330
|
+
if (!/^ivs_[a-f0-9]{56}$/.test(g) || !/^ivo_[a-f0-9]{56}$/.test(v) || g === p || l.kind !== i || l.requestId !== de(i, h, y) || e.id !== D("ivo_", d, u.ownerKind, u.ownerId, n(l.requestId)) || e.tenantId !== d || e.ownerKey !== p || T(l) !== e.digest) throw t("invalid_record");
|
|
331
|
+
let x = Object.freeze(a(m.selections, 32).map((e) => {
|
|
332
|
+
let i = o(e, [
|
|
333
|
+
"instanceId",
|
|
334
|
+
"qty",
|
|
335
|
+
"item",
|
|
336
|
+
"before",
|
|
337
|
+
"destinationId"
|
|
338
|
+
]), a = o(i.before, [
|
|
339
|
+
"id",
|
|
340
|
+
"itemId",
|
|
341
|
+
"schemaVersion",
|
|
342
|
+
"qty",
|
|
343
|
+
"attributes",
|
|
344
|
+
"acquiredAt",
|
|
345
|
+
"expiresAt",
|
|
346
|
+
"locked",
|
|
347
|
+
"source"
|
|
348
|
+
]), c = r(a.acquiredAt, 0, s), l = a.expiresAt === null ? null : r(a.expiresAt, c + 1, 864e13), u = J({
|
|
349
|
+
...a,
|
|
350
|
+
acquiredAt: new Date(c),
|
|
351
|
+
expiresAt: l === null ? null : new Date(l)
|
|
352
|
+
}), p = f(i.item, O.items), m = r(i.qty, 1, u.qty), g = n(i.instanceId), _ = n(i.destinationId), v = m === u.qty ? u.id : D("ivi_", "reservation.transfer", d, h, y, b, u.id);
|
|
353
|
+
if (g !== u.id || _ !== v || !u.locked || !p.tradable || p.id !== u.itemId || p.schemaVersion !== u.schemaVersion || u.expiresAt !== null && u.expiresAt <= s) throw t("invalid_record");
|
|
354
|
+
return Object.freeze({
|
|
355
|
+
instanceId: g,
|
|
356
|
+
qty: m,
|
|
357
|
+
item: p,
|
|
358
|
+
before: u,
|
|
359
|
+
destinationId: _
|
|
360
|
+
});
|
|
361
|
+
})), S = _(x.map((e) => ({
|
|
362
|
+
instanceId: e.instanceId,
|
|
363
|
+
qty: e.qty
|
|
364
|
+
})));
|
|
365
|
+
if (T(S) !== T(x.map((e) => ({
|
|
366
|
+
instanceId: e.instanceId,
|
|
367
|
+
qty: e.qty
|
|
368
|
+
}))) || new Set(x.map((e) => e.destinationId)).size !== x.length) throw t("invalid_record");
|
|
369
|
+
return Object.freeze({
|
|
370
|
+
intent: {
|
|
371
|
+
tenantId: d,
|
|
372
|
+
owner: u,
|
|
373
|
+
requestId: n(l.requestId),
|
|
374
|
+
kind: i,
|
|
375
|
+
payload: m
|
|
376
|
+
},
|
|
377
|
+
reservationId: h,
|
|
378
|
+
peerKey: g,
|
|
379
|
+
peerOperationId: v,
|
|
380
|
+
selections: x
|
|
381
|
+
});
|
|
382
|
+
}, fe = (e) => e.map((e) => ({
|
|
383
|
+
instanceId: e.instanceId,
|
|
384
|
+
qty: e.qty,
|
|
385
|
+
item: e.item,
|
|
386
|
+
before: e.before
|
|
387
|
+
})), pe = (e) => Object.freeze({
|
|
388
|
+
...e.before,
|
|
389
|
+
id: e.destinationId,
|
|
390
|
+
qty: e.qty,
|
|
391
|
+
locked: !1
|
|
392
|
+
}), me = async (e, n, r) => {
|
|
393
|
+
let i = n.intent.kind;
|
|
394
|
+
if (i !== "transfer-out" && i !== "transfer-in") throw t("invalid_record");
|
|
395
|
+
let a = i === "transfer-out" ? "transfer-in" : "transfer-out", o = (await e.query(I(x).where(P("id", n.peerOperationId)).limit(1).descriptor))[0];
|
|
396
|
+
if (!o || o.tenantId !== n.intent.tenantId || o.state !== "committed" && o.state !== "erased" || o.state === "committed" && o.ownerKey !== n.peerKey || o.state === "erased" && (o.ownerKey !== null || o.receipt !== null || o.transfer !== null || o.digest !== null)) throw t("invalid_record");
|
|
397
|
+
let s, c = null;
|
|
398
|
+
if (o.state === "committed") {
|
|
399
|
+
let e = Y(o, a), l = Z(o, a, e.at);
|
|
400
|
+
s = e.at, c = e;
|
|
401
|
+
let u = D("ivo_", n.intent.tenantId, n.intent.owner.ownerKind, n.intent.owner.ownerId, n.intent.requestId);
|
|
402
|
+
if (l.reservationId !== n.reservationId || l.peerOperationId !== u || l.peerKey !== W(n.intent.tenantId, n.intent.owner) || T(l.selections) !== T(n.selections) || (i === "transfer-out" ? e.at < r : e.at > r)) throw t("invalid_record");
|
|
403
|
+
}
|
|
404
|
+
let l = await e.query(I(y).where(N(P("tenantId", n.intent.tenantId), P("operationId", n.peerOperationId))).limit(33).descriptor);
|
|
405
|
+
if (l.length !== n.selections.length || !Number.isSafeInteger(o.sequence)) throw t("invalid_record");
|
|
406
|
+
for (let [e, r] of n.selections.entries()) {
|
|
407
|
+
let i = l.find((t) => t.id === D("ivg_", n.peerOperationId, String(e))), c = a === "transfer-out" ? r.instanceId : r.destinationId, u = a === "transfer-out" ? -r.qty : r.qty, d = a === "transfer-in" ? pe(r) : r.qty === r.before.qty ? null : Object.freeze({
|
|
408
|
+
...r.before,
|
|
409
|
+
qty: r.before.qty - r.qty,
|
|
410
|
+
locked: !1
|
|
411
|
+
});
|
|
412
|
+
if (!i || i.operationId !== n.peerOperationId || i.sequence !== o.sequence || i.itemId !== r.before.itemId || i.delta !== u || o.state === "committed" && (i.instanceId !== c || i.reason !== "transferred" || i.refKind !== "inventory.reservation" || i.refId !== n.reservationId || B(i.at) !== s || T(i.after) !== T(d)) || o.state === "erased" && (i.instanceId !== null || i.after !== null || i.actor !== null || i.refId !== null || i.refKind !== null || i.ownerId !== null || i.ownerKind !== null)) throw t("invalid_record");
|
|
413
|
+
}
|
|
414
|
+
return c;
|
|
415
|
+
}, he = (e) => e.map((e) => ({
|
|
416
|
+
id: n(e.id),
|
|
417
|
+
slotSet: n(e.slotSet),
|
|
418
|
+
slot: n(e.slot),
|
|
419
|
+
instanceId: n(e.instanceId)
|
|
420
|
+
})), ge = (e, t) => D("ivr_", e, t.id, String(t.version)), _e = async (e, n, r, i) => {
|
|
421
|
+
let a = (await e.query(I(S).where(P("id", ge(n, r))).limit(1).descriptor))[0];
|
|
422
|
+
if (!a || a.tenantId !== n || a.recipeId !== r.id || a.version !== r.version || a.rulesVersion !== i || T(a.definition) !== T(r)) throw t("conflict");
|
|
423
|
+
}, ve = async (e, i) => {
|
|
424
|
+
let { tenantId: s, owner: c, payload: p } = e, h = l(p.recipe), g = n(p.version), _ = r(p.batches, 1, h.maxBatches);
|
|
425
|
+
if (!O.crafting) throw t("unavailable");
|
|
426
|
+
await d.insertIgnore(S.tableName, {
|
|
427
|
+
id: ge(s, h),
|
|
428
|
+
tenantId: s,
|
|
429
|
+
recipeId: h.id,
|
|
430
|
+
version: h.version,
|
|
431
|
+
definition: h,
|
|
432
|
+
rulesVersion: g
|
|
433
|
+
}, { conflictColumns: ["id"] }), await _e(d, s, h, g);
|
|
434
|
+
let y = await j.runPromise(j.result(O.catalogSource.read(w({
|
|
435
|
+
tenantId: s,
|
|
436
|
+
channel: O.channel,
|
|
437
|
+
locale: O.locale
|
|
438
|
+
}))));
|
|
439
|
+
if (M.isFailure(y)) throw y.failure;
|
|
440
|
+
let x = o(y.success, ["revision", "items"]), C = n(x.revision), E = a(x.items, 1e4).map((e) => f(e, O.items));
|
|
441
|
+
if (new Set(E.map((e) => e.id)).size !== E.length) throw t("invalid_record");
|
|
442
|
+
let k = await d.transactional(async (e) => {
|
|
443
|
+
let t = await K(e, s, c), n = await q(e, v, s, c, O.maxInstances), i = he(await q(e, b, s, c, 2048));
|
|
444
|
+
return {
|
|
445
|
+
owned: n.map(J),
|
|
446
|
+
slots: i,
|
|
447
|
+
sequence: r(t.sequence, 0, 2147483646)
|
|
448
|
+
};
|
|
449
|
+
});
|
|
450
|
+
if (k.owned.some((e) => e.acquiredAt > i)) throw t("invalid_record");
|
|
451
|
+
let N = Object.freeze([...new Set(k.slots.map((e) => e.instanceId))]), P = u({
|
|
452
|
+
recipe: h,
|
|
453
|
+
batches: _,
|
|
454
|
+
at: i,
|
|
455
|
+
available: k.owned,
|
|
456
|
+
excludedIds: N
|
|
457
|
+
}, O.crafting.craftResolver), F = [], I = new Set(P.consume.map((e) => e.instanceId)), L = new Map(k.owned.map((e) => [e.id, e])), te = [], ne = D("ivo_", s, c.ownerKind, c.ownerId, e.requestId);
|
|
458
|
+
for (let e of P.consume) {
|
|
459
|
+
let t = L.get(e.instanceId), n = t.qty === e.qty ? null : Object.freeze({
|
|
460
|
+
...t,
|
|
461
|
+
qty: t.qty - e.qty
|
|
462
|
+
});
|
|
463
|
+
F.push({
|
|
464
|
+
instanceId: t.id,
|
|
465
|
+
delta: -e.qty,
|
|
466
|
+
after: n
|
|
467
|
+
}), n ? L.set(t.id, n) : L.delete(t.id);
|
|
468
|
+
}
|
|
469
|
+
for (let [e, n] of P.outputs.entries()) {
|
|
470
|
+
let r = E.find((e) => e.id === n.itemId);
|
|
471
|
+
if (!r) throw t("not_found");
|
|
472
|
+
let a = m(r, O.items, n.attributes === void 0 ? r.instanceDefaults : n.attributes), o = A({
|
|
473
|
+
item: r,
|
|
474
|
+
acquiredAt: i
|
|
475
|
+
}, O.expiryPolicy);
|
|
476
|
+
te.push(Object.freeze({
|
|
477
|
+
itemId: n.itemId,
|
|
478
|
+
qty: n.qty,
|
|
479
|
+
attributes: a
|
|
480
|
+
}));
|
|
481
|
+
let s = [...L.values()].filter((e) => !I.has(e.id) && e.itemId === r.id && e.schemaVersion === r.schemaVersion && !e.locked && e.expiresAt === o && (e.expiresAt === null || e.expiresAt > i) && T(e.attributes) === T(a)), c = ee({
|
|
482
|
+
item: r,
|
|
483
|
+
quantity: n.qty,
|
|
484
|
+
available: s.map((e) => ({
|
|
485
|
+
id: e.id,
|
|
486
|
+
quantity: e.qty
|
|
487
|
+
}))
|
|
488
|
+
}, O.stackPolicy);
|
|
489
|
+
for (let e of c.existing) {
|
|
490
|
+
let t = L.get(e.id), n = Object.freeze({
|
|
491
|
+
...t,
|
|
492
|
+
qty: t.qty + e.add
|
|
493
|
+
});
|
|
494
|
+
F.push({
|
|
495
|
+
instanceId: t.id,
|
|
496
|
+
delta: e.add,
|
|
497
|
+
after: n
|
|
498
|
+
}), L.set(t.id, n);
|
|
499
|
+
}
|
|
500
|
+
for (let [n, s] of c.create.entries()) {
|
|
501
|
+
let c = D("ivi_", ne, "craft", String(e), String(n)), l = Object.freeze({
|
|
502
|
+
id: c,
|
|
503
|
+
itemId: r.id,
|
|
504
|
+
schemaVersion: r.schemaVersion,
|
|
505
|
+
qty: s,
|
|
506
|
+
attributes: a,
|
|
507
|
+
acquiredAt: i,
|
|
508
|
+
expiresAt: o,
|
|
509
|
+
locked: !1,
|
|
510
|
+
source: "crafted"
|
|
511
|
+
});
|
|
512
|
+
if (L.has(c)) throw t("invalid_record");
|
|
513
|
+
F.push({
|
|
514
|
+
instanceId: c,
|
|
515
|
+
delta: s,
|
|
516
|
+
after: l
|
|
517
|
+
}), L.set(c, l);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (L.size > O.maxInstances || new Set(F.map((e) => e.instanceId)).size !== F.length) throw t("limit_exceeded");
|
|
521
|
+
return {
|
|
522
|
+
sequence: k.sequence,
|
|
523
|
+
basis: T({
|
|
524
|
+
owned: k.owned,
|
|
525
|
+
slots: k.slots
|
|
526
|
+
}),
|
|
527
|
+
changes: F,
|
|
528
|
+
accepted: {
|
|
529
|
+
intent: e,
|
|
530
|
+
recipe: h,
|
|
531
|
+
version: g,
|
|
532
|
+
batches: _,
|
|
533
|
+
catalogRevision: C,
|
|
534
|
+
excludedIds: N,
|
|
535
|
+
payment: null,
|
|
536
|
+
plan: {
|
|
537
|
+
consume: P.consume,
|
|
538
|
+
outputs: te
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}, Q = (e, i) => {
|
|
543
|
+
let { tenantId: c, owner: u, requestId: p, kind: h, payload: g } = i, _ = D("ivo_", c, u.ownerKind, u.ownerId, p), S = T(i);
|
|
544
|
+
return E(async () => {
|
|
545
|
+
await G(c, u);
|
|
546
|
+
let E = (await d.transactional(async (e) => {
|
|
547
|
+
await K(e, c, u);
|
|
548
|
+
let n = (await e.query(I(x).where(P("id", _)).limit(1).descriptor))[0];
|
|
549
|
+
if (n?.state === "committed") {
|
|
550
|
+
if (n.tenantId !== c || n.ownerKey !== W(c, u) || n.digest !== S) throw t("conflict");
|
|
551
|
+
return Y(n, h);
|
|
552
|
+
}
|
|
553
|
+
}))?.at ?? re(), F = await d.transactional(async (e) => {
|
|
554
|
+
await K(e, c, u);
|
|
555
|
+
let n = (await e.query(I(x).where(P("id", _)).limit(1).descriptor))[0];
|
|
556
|
+
if (n) {
|
|
557
|
+
if (n.tenantId !== c || n.ownerKey !== W(c, u)) throw t("invalid_record");
|
|
558
|
+
if (n.state === "committed" && n.digest !== S) throw t("conflict");
|
|
559
|
+
return n;
|
|
560
|
+
}
|
|
561
|
+
if ((await e.query(I(x).where(N(P("tenantId", c), P("ownerKey", W(c, u)))).limit(O.maxLedgerRows + 1).descriptor)).length >= O.maxLedgerRows) throw t("limit_exceeded");
|
|
562
|
+
let r = {
|
|
563
|
+
id: _,
|
|
564
|
+
tenantId: c,
|
|
565
|
+
ownerKey: W(c, u),
|
|
566
|
+
sequence: null,
|
|
567
|
+
state: "pending",
|
|
568
|
+
digest: null,
|
|
569
|
+
receipt: null,
|
|
570
|
+
craft: null,
|
|
571
|
+
reservation: null,
|
|
572
|
+
transfer: null,
|
|
573
|
+
admission: 0,
|
|
574
|
+
createdAt: new Date(E)
|
|
575
|
+
};
|
|
576
|
+
return await e.insert(x.tableName, r), r;
|
|
577
|
+
}), L;
|
|
578
|
+
if (h === "grant" && F?.state !== "committed") {
|
|
579
|
+
let e = await j.runPromise(j.result(O.catalogSource.read(w({
|
|
580
|
+
tenantId: c,
|
|
581
|
+
channel: O.channel,
|
|
582
|
+
locale: O.locale
|
|
583
|
+
}))));
|
|
584
|
+
if (M.isFailure(e)) throw e.failure;
|
|
585
|
+
let r = o(e.success, ["revision", "items"]);
|
|
586
|
+
n(r.revision);
|
|
587
|
+
let i = a(r.items, 1e4).map((e) => f(e, O.items));
|
|
588
|
+
if (new Set(i.map((e) => e.id)).size !== i.length) throw t("invalid_record");
|
|
589
|
+
if (L = i.find((e) => e.id === g.itemId), !L) throw t("not_found");
|
|
590
|
+
}
|
|
591
|
+
let R;
|
|
592
|
+
if (h === "grant" && F.state !== "committed") {
|
|
593
|
+
if (!L) throw t("unavailable");
|
|
594
|
+
let e = m(L, O.items, g.attributes === void 0 ? L.instanceDefaults : g.attributes), n = A({
|
|
595
|
+
item: L,
|
|
596
|
+
acquiredAt: E
|
|
597
|
+
}, O.expiryPolicy);
|
|
598
|
+
if (O.stackPolicy === k) R = Object.freeze({
|
|
599
|
+
attributes: e,
|
|
600
|
+
expiresAt: n
|
|
601
|
+
});
|
|
602
|
+
else {
|
|
603
|
+
let i = await d.transactional(async (e) => (await K(e, c, u), (await q(e, v, c, u, O.maxInstances)).map(J)));
|
|
604
|
+
if (i.some((e) => e.acquiredAt > E)) throw t("invalid_record");
|
|
605
|
+
let a = i.filter((t) => t.itemId === L.id && t.schemaVersion === L.schemaVersion && !t.locked && t.expiresAt === n && (t.expiresAt === null || t.expiresAt > E) && T(t.attributes) === T(e)), o = ee({
|
|
606
|
+
item: L,
|
|
607
|
+
quantity: r(g.qty, 1, 1e6),
|
|
608
|
+
available: a.map((e) => ({
|
|
609
|
+
id: e.id,
|
|
610
|
+
quantity: e.qty
|
|
611
|
+
}))
|
|
612
|
+
}, O.stackPolicy);
|
|
613
|
+
R = Object.freeze({
|
|
614
|
+
attributes: e,
|
|
615
|
+
expiresAt: n,
|
|
616
|
+
basis: T(i),
|
|
617
|
+
stack: o
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
let z = (e) => e().catch(async (e) => {
|
|
622
|
+
if ((await d.transactional(async (e) => (await K(e, c, u), (await e.query(I(x).where(P("id", _)).limit(1).descriptor))[0])))?.state !== "committed") throw e;
|
|
623
|
+
}), V = h === "craft" && F.state !== "committed" ? await z(() => ve(i, E)) : void 0, H = (h === "reserve" || h === "release") && F.state !== "committed" ? await z(() => ue(i, E)) : void 0, U = (h === "transfer-out" || h === "transfer-in") && F.state !== "committed" ? Z({
|
|
624
|
+
id: _,
|
|
625
|
+
tenantId: c,
|
|
626
|
+
ownerKey: W(c, u),
|
|
627
|
+
digest: S,
|
|
628
|
+
transfer: { intent: i }
|
|
629
|
+
}, h, E) : void 0, ae = te(d, async (i) => {
|
|
630
|
+
let a = await K(i, c, u);
|
|
631
|
+
if (await i.updateMany(x.tableName, { admission: 0 }, { where: P("id", _) }) !== 1) throw t("unavailable");
|
|
632
|
+
let s = (await i.query(I(x).where(P("id", _)).limit(1).descriptor))[0];
|
|
633
|
+
if (!s || s.tenantId !== c || s.ownerKey !== W(c, u)) throw t("invalid_record");
|
|
634
|
+
if (s.state === "erased") throw t("erased");
|
|
635
|
+
if (s.state === "committed") {
|
|
636
|
+
if (s.digest !== S) throw t("conflict");
|
|
637
|
+
return Y(s, h);
|
|
638
|
+
}
|
|
639
|
+
if (s.state !== "pending" || s.sequence !== null || s.digest !== null || s.receipt !== null || B(s.createdAt) > E) throw t("invalid_record");
|
|
640
|
+
let d = r(a.sequence, 0, 2147483646) + 1;
|
|
641
|
+
if ((await i.query(I(y).where(N(P("tenantId", c), P("operationId", _))).limit(1).descriptor)).length) throw t("invalid_record");
|
|
642
|
+
let f = await q(i, v, c, u, O.maxInstances), p = f.map(J);
|
|
643
|
+
if (p.some((e) => e.acquiredAt > E)) throw t("invalid_record");
|
|
644
|
+
if ((await i.query(I(x).where(N(P("tenantId", c), P("ownerKey", W(c, u)))).limit(O.maxLedgerRows + 1).descriptor)).length > O.maxLedgerRows) throw t("limit_exceeded");
|
|
645
|
+
let m = await q(i, y, c, u, O.maxLedgerRows), w = [], k = h === "transfer-out" || h === "transfer-in" ? "transferred" : h === "reserve" ? "reserved" : h === "release" ? "released" : h === "craft" ? "crafted" : h === "grant" || h === "consume" ? n(g.reason) : h === "expire" ? "expired" : "equipped", A = h === "reserve" || h === "release" || h === "transfer-out" || h === "transfer-in" ? {
|
|
646
|
+
kind: "inventory.reservation",
|
|
647
|
+
id: n(g.reservationId)
|
|
648
|
+
} : h === "craft" ? {
|
|
649
|
+
kind: "recipe",
|
|
650
|
+
id: n(o(g.recipe).id)
|
|
651
|
+
} : h === "grant" || h === "consume" ? o(g.ref, ["kind", "id"]) : null;
|
|
652
|
+
if (h === "transfer-out" || h === "transfer-in") {
|
|
653
|
+
if (!U) throw t("unavailable");
|
|
654
|
+
if (h === "transfer-out") {
|
|
655
|
+
let e = await le(i, c, u, U.reservationId);
|
|
656
|
+
if (e.receipt.at > E || T(e.accepted.selections.map((e) => ({
|
|
657
|
+
...e,
|
|
658
|
+
before: {
|
|
659
|
+
...e.before,
|
|
660
|
+
locked: !0
|
|
661
|
+
}
|
|
662
|
+
}))) !== T(fe(U.selections)) || (await i.query(I(x).where(P("id", se(c, u, "release", U.reservationId))).limit(1).descriptor))[0]?.state === "committed") throw t("conflict");
|
|
663
|
+
let n = await q(i, b, c, u, 2048);
|
|
664
|
+
for (let e of U.selections) {
|
|
665
|
+
let r = p.find((t) => t.id === e.instanceId);
|
|
666
|
+
if (!r || T(r) !== T(e.before) || n.some((e) => e.instanceId === r.id)) throw t("conflict");
|
|
667
|
+
w.push({
|
|
668
|
+
instanceId: r.id,
|
|
669
|
+
delta: -e.qty,
|
|
670
|
+
after: r.qty === e.qty ? null : Object.freeze({
|
|
671
|
+
...r,
|
|
672
|
+
qty: r.qty - e.qty,
|
|
673
|
+
locked: !1
|
|
674
|
+
})
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
} else {
|
|
678
|
+
if (await me(i, U, E), p.length + U.selections.length > O.maxInstances) throw t("limit_exceeded");
|
|
679
|
+
for (let e of U.selections) {
|
|
680
|
+
if ((await i.query(I(v).where(P("id", e.destinationId)).limit(1).descriptor))[0]) throw t("conflict");
|
|
681
|
+
w.push({
|
|
682
|
+
instanceId: e.destinationId,
|
|
683
|
+
delta: e.qty,
|
|
684
|
+
after: pe(e)
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
} else if (h === "reserve" || h === "release") {
|
|
689
|
+
if (!H) throw t("unavailable");
|
|
690
|
+
if (h === "release") {
|
|
691
|
+
let e = await le(i, c, u, H.reservationId);
|
|
692
|
+
if (e.receipt.at > E || T(e.accepted.selections.map((e) => ({
|
|
693
|
+
...e,
|
|
694
|
+
before: {
|
|
695
|
+
...e.before,
|
|
696
|
+
locked: !0
|
|
697
|
+
}
|
|
698
|
+
}))) !== T(H.selections)) throw t("conflict");
|
|
699
|
+
}
|
|
700
|
+
let e = await q(i, b, c, u, 2048);
|
|
701
|
+
for (let n of H.selections) {
|
|
702
|
+
let r = p.find((e) => e.id === n.instanceId);
|
|
703
|
+
if (!r || T(r) !== T(n.before) || e.some((e) => e.instanceId === n.instanceId)) throw t("conflict");
|
|
704
|
+
if (h === "reserve" && r.expiresAt !== null && r.expiresAt <= E) throw t("expired");
|
|
705
|
+
w.push({
|
|
706
|
+
instanceId: r.id,
|
|
707
|
+
delta: 0,
|
|
708
|
+
after: Object.freeze({
|
|
709
|
+
...r,
|
|
710
|
+
locked: h === "reserve"
|
|
711
|
+
})
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
} else if (h === "craft") {
|
|
715
|
+
if (!V || V.sequence !== a.sequence || V.basis !== T({
|
|
716
|
+
owned: p,
|
|
717
|
+
slots: he(await q(i, b, c, u, 2048))
|
|
718
|
+
})) throw t("conflict");
|
|
719
|
+
await _e(i, c, l(g.recipe), n(g.version)), w.push(...V.changes);
|
|
720
|
+
} else if (h === "grant") {
|
|
721
|
+
if (!L || !R) throw t("unavailable");
|
|
722
|
+
if (R.basis !== void 0 && R.basis !== T(p)) throw t("conflict");
|
|
723
|
+
let { attributes: e, expiresAt: n } = R, i = p.filter((t) => t.itemId === L?.id && t.schemaVersion === L.schemaVersion && !t.locked && t.expiresAt === n && (t.expiresAt === null || t.expiresAt > E) && T(t.attributes) === T(e)), a = R.stack ?? ee({
|
|
724
|
+
item: L,
|
|
725
|
+
quantity: r(g.qty, 1, 1e6),
|
|
726
|
+
available: i.map((e) => ({
|
|
727
|
+
id: e.id,
|
|
728
|
+
quantity: e.qty
|
|
729
|
+
}))
|
|
730
|
+
});
|
|
731
|
+
if (p.length + a.create.length > O.maxInstances) throw t("limit_exceeded");
|
|
732
|
+
for (let e of a.existing) {
|
|
733
|
+
let n = p.find((t) => t.id === e.id);
|
|
734
|
+
if (!n) throw t("invalid_record");
|
|
735
|
+
w.push({
|
|
736
|
+
instanceId: e.id,
|
|
737
|
+
delta: e.add,
|
|
738
|
+
after: Object.freeze({
|
|
739
|
+
...n,
|
|
740
|
+
qty: n.qty + e.add
|
|
741
|
+
})
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
for (let [t, r] of a.create.entries()) {
|
|
745
|
+
let i = D("ivi_", _, String(t));
|
|
746
|
+
w.push({
|
|
747
|
+
instanceId: i,
|
|
748
|
+
delta: r,
|
|
749
|
+
after: Object.freeze({
|
|
750
|
+
id: i,
|
|
751
|
+
itemId: L.id,
|
|
752
|
+
schemaVersion: L.schemaVersion,
|
|
753
|
+
qty: r,
|
|
754
|
+
attributes: e,
|
|
755
|
+
acquiredAt: E,
|
|
756
|
+
expiresAt: n,
|
|
757
|
+
locked: !1,
|
|
758
|
+
source: k
|
|
759
|
+
})
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
} else if (h === "consume") {
|
|
763
|
+
let e = p.find((e) => e.id === g.instanceId);
|
|
764
|
+
if (!e) throw t("not_found");
|
|
765
|
+
if (e.locked) throw t("locked");
|
|
766
|
+
if (e.expiresAt !== null && e.expiresAt <= E) throw t("expired");
|
|
767
|
+
let n = r(g.qty, 1, 1e6);
|
|
768
|
+
if (n > e.qty) throw t("insufficient_items");
|
|
769
|
+
w.push({
|
|
770
|
+
instanceId: e.id,
|
|
771
|
+
delta: -n,
|
|
772
|
+
after: e.qty === n ? null : Object.freeze({
|
|
773
|
+
...e,
|
|
774
|
+
qty: e.qty - n
|
|
775
|
+
})
|
|
776
|
+
});
|
|
777
|
+
} else if (h === "expire") {
|
|
778
|
+
let e = r(g.until, 0, E);
|
|
779
|
+
for (let n of p) if (n.expiresAt !== null && n.expiresAt <= e) {
|
|
780
|
+
if (n.locked) throw t("locked");
|
|
781
|
+
w.push({
|
|
782
|
+
instanceId: n.id,
|
|
783
|
+
delta: -n.qty,
|
|
784
|
+
after: null
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
} else {
|
|
788
|
+
let e = n(g.slotSet), r = n(g.slot), a = g.instanceId;
|
|
789
|
+
if (!O.slotSets[e]?.includes(r)) throw t("invalid_slot");
|
|
790
|
+
let o = D("ivl_", c, u.ownerKind, u.ownerId, e, r), s = (await i.query(I(b).where(P("id", o)).limit(1).descriptor))[0];
|
|
791
|
+
if (s && (s.tenantId !== c || s.ownerKind !== u.ownerKind || s.ownerId !== u.ownerId || s.slotSet !== e || s.slot !== r)) throw t("invalid_record");
|
|
792
|
+
if (a === null) {
|
|
793
|
+
if (s) {
|
|
794
|
+
let e = p.find((e) => e.id === s.instanceId);
|
|
795
|
+
if (!e) throw t("invalid_record");
|
|
796
|
+
await i.delete(b.tableName, o), w.push({
|
|
797
|
+
instanceId: e.id,
|
|
798
|
+
delta: 0,
|
|
799
|
+
after: e
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
} else {
|
|
803
|
+
let n = p.find((e) => e.id === a);
|
|
804
|
+
if (!n) throw t("not_found");
|
|
805
|
+
if (n.locked) throw t("locked");
|
|
806
|
+
if (n.expiresAt !== null && n.expiresAt <= E) throw t("expired");
|
|
807
|
+
if (O.items.find((e) => e.id === n.itemId && e.schemaVersion === n.schemaVersion)?.equipSlot !== r) throw t("invalid_slot");
|
|
808
|
+
s ? await i.update(b.tableName, o, { instanceId: n.id }) : await i.insert(b.tableName, {
|
|
809
|
+
id: o,
|
|
810
|
+
tenantId: c,
|
|
811
|
+
...u,
|
|
812
|
+
slotSet: e,
|
|
813
|
+
slot: r,
|
|
814
|
+
instanceId: n.id
|
|
815
|
+
}), w.push({
|
|
816
|
+
instanceId: n.id,
|
|
817
|
+
delta: 0,
|
|
818
|
+
after: n
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (m.length + w.length > O.maxLedgerRows) throw t("limit_exceeded");
|
|
823
|
+
for (let [r, a] of w.entries()) {
|
|
824
|
+
let o = f.find((e) => e.id === a.instanceId);
|
|
825
|
+
if (h !== "equip") {
|
|
826
|
+
if (a.after === null) {
|
|
827
|
+
if (!o) throw t("invalid_record");
|
|
828
|
+
await i.delete(v.tableName, a.instanceId), await i.deleteMany(b.tableName, { where: N(ie(c, u), P("instanceId", a.instanceId)) });
|
|
829
|
+
} else o ? await i.update(v.tableName, a.instanceId, oe(a.after)) : await i.insert(v.tableName, {
|
|
830
|
+
tenantId: c,
|
|
831
|
+
...u,
|
|
832
|
+
...oe(a.after)
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
let s = a.after?.itemId ?? n(o?.itemId);
|
|
836
|
+
await i.insert(y.tableName, {
|
|
837
|
+
id: D("ivg_", _, String(r)),
|
|
838
|
+
tenantId: c,
|
|
839
|
+
...u,
|
|
840
|
+
operationId: _,
|
|
841
|
+
sequence: d,
|
|
842
|
+
instanceId: a.instanceId,
|
|
843
|
+
itemId: s,
|
|
844
|
+
delta: a.delta,
|
|
845
|
+
after: a.after,
|
|
846
|
+
reason: k,
|
|
847
|
+
refKind: A ? n(A.kind) : null,
|
|
848
|
+
refId: A ? n(A.id) : null,
|
|
849
|
+
actor: n(e.id),
|
|
850
|
+
at: new Date(E)
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
let j = Object.freeze({
|
|
854
|
+
operationId: _,
|
|
855
|
+
kind: h,
|
|
856
|
+
changes: Object.freeze(w.map(({ instanceId: e, delta: t }) => Object.freeze({
|
|
857
|
+
instanceId: e,
|
|
858
|
+
delta: t
|
|
859
|
+
}))),
|
|
860
|
+
at: E
|
|
861
|
+
});
|
|
862
|
+
return await i.update(x.tableName, _, {
|
|
863
|
+
state: "committed",
|
|
864
|
+
sequence: d,
|
|
865
|
+
digest: S,
|
|
866
|
+
receipt: j,
|
|
867
|
+
craft: V?.accepted ?? null,
|
|
868
|
+
reservation: H ?? null,
|
|
869
|
+
transfer: U ? { intent: U.intent } : null
|
|
870
|
+
}), await i.update(C.tableName, W(c, u), { sequence: d }), j;
|
|
871
|
+
}), X = h === "craft" ? l(g.recipe) : void 0;
|
|
872
|
+
if (X?.cost && F.state !== "committed") {
|
|
873
|
+
let n = O.crafting?.economy;
|
|
874
|
+
if (!n || !V) throw t("unavailable");
|
|
875
|
+
let i = r(g.batches, 1, X.maxBatches), a = await j.runPromise(j.result(n.prepareTransfer(e, {
|
|
876
|
+
tenantId: c,
|
|
877
|
+
requestId: D("ivc_", c, u.ownerKind, u.ownerId, p),
|
|
878
|
+
currency: X.cost.currency,
|
|
879
|
+
amount: (BigInt(X.cost.amount) * BigInt(i)).toString(),
|
|
880
|
+
from: {
|
|
881
|
+
kind: "wallet",
|
|
882
|
+
...u
|
|
883
|
+
},
|
|
884
|
+
to: {
|
|
885
|
+
kind: "system",
|
|
886
|
+
id: O.crafting.systemAccount
|
|
887
|
+
},
|
|
888
|
+
reason: "crafting.cost",
|
|
889
|
+
ref: {
|
|
890
|
+
kind: "inventory.craft",
|
|
891
|
+
id: _
|
|
892
|
+
}
|
|
893
|
+
})));
|
|
894
|
+
if (M.isFailure(a)) throw t(a.failure.code === "insufficient_funds" ? "insufficient_funds" : "payment_refused");
|
|
895
|
+
return ne(d, [a.success, ae], async (e, [n, r]) => {
|
|
896
|
+
let a = s(n, X, i), c = (await e.query(I(x).where(P("id", _)).limit(1).descriptor))[0];
|
|
897
|
+
if (!c || c.state !== "committed" || c.digest !== S) throw t("invalid_record");
|
|
898
|
+
let l = o(c.craft, [
|
|
899
|
+
"intent",
|
|
900
|
+
"recipe",
|
|
901
|
+
"version",
|
|
902
|
+
"batches",
|
|
903
|
+
"catalogRevision",
|
|
904
|
+
"excludedIds",
|
|
905
|
+
"plan",
|
|
906
|
+
"payment"
|
|
907
|
+
]);
|
|
908
|
+
if (l.payment !== null) {
|
|
909
|
+
if (T(s(l.payment, X, i)) !== T(a)) throw t("conflict");
|
|
910
|
+
} else {
|
|
911
|
+
if (T(l) !== T(V.accepted)) throw t("invalid_record");
|
|
912
|
+
await e.update(x.tableName, _, { craft: {
|
|
913
|
+
...l,
|
|
914
|
+
payment: a
|
|
915
|
+
} });
|
|
916
|
+
}
|
|
917
|
+
return r;
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
return ae;
|
|
921
|
+
});
|
|
922
|
+
}, ye = (n, r) => j.flatMap(Q(n, r), (n) => j.tryPromise({
|
|
923
|
+
try: async () => (await L(d, [n]))[0],
|
|
924
|
+
catch: (n) => {
|
|
925
|
+
if (n instanceof e) return n;
|
|
926
|
+
if (r.kind !== "craft" || !o(r.payload.recipe).cost) return t("unavailable");
|
|
927
|
+
let i = typeof n == "object" && n ? Object.getOwnPropertyDescriptor(n, "code") : void 0;
|
|
928
|
+
return t(i && "value" in i && i.value === "insufficient_funds" ? "insufficient_funds" : "payment_refused");
|
|
929
|
+
}
|
|
930
|
+
})), $ = (n) => {
|
|
931
|
+
try {
|
|
932
|
+
return n();
|
|
933
|
+
} catch (n) {
|
|
934
|
+
return j.fail(n instanceof e ? n : t("invalid_input"));
|
|
935
|
+
}
|
|
936
|
+
}, be = (e, r) => $(() => {
|
|
937
|
+
let i = structuredClone(e), { tenantId: a, owner: o } = U(i), s = r === void 0 ? void 0 : n(r);
|
|
938
|
+
if (s !== void 0 && !O.slotSets[s]) throw t("invalid_slot");
|
|
939
|
+
return E(async () => {
|
|
940
|
+
let e = re(), r = (await d.query(I(C).where(P("id", W(a, o))).limit(1).descriptor))[0];
|
|
941
|
+
ae(r, a, o);
|
|
942
|
+
let i = (await q(d, v, a, o, O.maxInstances)).map(J).filter((t) => t.expiresAt === null || t.expiresAt > e);
|
|
943
|
+
if (s === void 0) return Object.freeze(i);
|
|
944
|
+
let c = await q(d, b, a, o, 2048);
|
|
945
|
+
return Object.freeze(c.filter((e) => e.slotSet === s).flatMap((e) => {
|
|
946
|
+
let r = n(e.slot), c = n(e.instanceId), l = i.find((e) => e.id === c);
|
|
947
|
+
if (!O.slotSets[s]?.includes(r) || e.id !== D("ivl_", a, o.ownerKind, o.ownerId, s, r)) throw t("invalid_record");
|
|
948
|
+
if (!l) return [];
|
|
949
|
+
if (O.items.find((e) => e.id === l.itemId && e.schemaVersion === l.schemaVersion)?.equipSlot !== r) throw t("invalid_record");
|
|
950
|
+
return [Object.freeze({
|
|
951
|
+
slotSet: s,
|
|
952
|
+
slot: r,
|
|
953
|
+
instanceId: c
|
|
954
|
+
})];
|
|
955
|
+
}));
|
|
956
|
+
});
|
|
957
|
+
}), xe = (e) => {
|
|
958
|
+
let r = o(e, [
|
|
959
|
+
"subjectId",
|
|
960
|
+
"tenantId",
|
|
961
|
+
"kind"
|
|
962
|
+
]);
|
|
963
|
+
if (r.kind !== "user" && r.kind !== "guest") throw t("forbidden");
|
|
964
|
+
return {
|
|
965
|
+
tenantId: n(r.tenantId),
|
|
966
|
+
owner: z({
|
|
967
|
+
ownerKind: "player",
|
|
968
|
+
ownerId: r.subjectId
|
|
969
|
+
})
|
|
970
|
+
};
|
|
971
|
+
}, Se = (e, i, u, f) => $(() => {
|
|
972
|
+
let p = structuredClone(e), m = n(i), h = z(u);
|
|
973
|
+
if (!H(p)) throw t("forbidden");
|
|
974
|
+
return E(async () => (await G(m, h), d.transactional(async (e) => {
|
|
975
|
+
let i = await K(e, m, h), u = await q(e, y, m, h, O.maxLedgerRows), d = await e.query(I(x).where(N(P("tenantId", m), P("ownerKey", W(m, h)))).limit(O.maxLedgerRows + 1).descriptor);
|
|
976
|
+
if (d.length > O.maxLedgerRows) throw t("limit_exceeded");
|
|
977
|
+
let p = d.filter((e) => e.state === "committed").sort((e, t) => Number(e.sequence) - Number(t.sequence)), g = new Set(p.map((e) => e.id)), _ = /* @__PURE__ */ new Map();
|
|
978
|
+
for (let e of u) {
|
|
979
|
+
if (!g.has(e.operationId)) throw t("invalid_record");
|
|
980
|
+
let n = _.get(e.operationId) ?? /* @__PURE__ */ new Map();
|
|
981
|
+
if (n.has(e.id)) throw t("invalid_record");
|
|
982
|
+
n.set(e.id, e), _.set(e.operationId, n);
|
|
983
|
+
}
|
|
984
|
+
if (p.length !== r(i.sequence, 0, 2147483647)) throw t("invalid_record");
|
|
985
|
+
let S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Map();
|
|
986
|
+
for (let [i, u] of p.entries()) {
|
|
987
|
+
if (u.sequence !== i + 1 || u.tenantId !== m || u.ownerKey !== W(m, h) || typeof u.digest != "string" || !/^[0-9a-f]{64}$/.test(u.digest)) throw t("invalid_record");
|
|
988
|
+
let d = o(u.receipt, [
|
|
989
|
+
"operationId",
|
|
990
|
+
"kind",
|
|
991
|
+
"changes",
|
|
992
|
+
"at"
|
|
993
|
+
]);
|
|
994
|
+
if (d.kind !== "grant" && d.kind !== "consume" && d.kind !== "equip" && d.kind !== "expire" && d.kind !== "craft" && d.kind !== "reserve" && d.kind !== "release" && d.kind !== "transfer-out" && d.kind !== "transfer-in") throw t("invalid_record");
|
|
995
|
+
let f = Y(u, d.kind), p = _.get(u.id) ?? /* @__PURE__ */ new Map();
|
|
996
|
+
if (p.size !== f.changes.length) throw t("invalid_record");
|
|
997
|
+
if (f.kind === "craft") {
|
|
998
|
+
let i = o(u.craft, [
|
|
999
|
+
"intent",
|
|
1000
|
+
"recipe",
|
|
1001
|
+
"version",
|
|
1002
|
+
"batches",
|
|
1003
|
+
"catalogRevision",
|
|
1004
|
+
"excludedIds",
|
|
1005
|
+
"plan",
|
|
1006
|
+
"payment"
|
|
1007
|
+
]), d = l(i.recipe), g = n(i.version), _ = r(i.batches, 1, d.maxBatches), v = Object.freeze(a(i.excludedIds, 2048).map(n)), y = o(i.intent, [
|
|
1008
|
+
"tenantId",
|
|
1009
|
+
"owner",
|
|
1010
|
+
"requestId",
|
|
1011
|
+
"kind",
|
|
1012
|
+
"payload"
|
|
1013
|
+
]), b = o(y.payload, [
|
|
1014
|
+
"recipe",
|
|
1015
|
+
"version",
|
|
1016
|
+
"batches"
|
|
1017
|
+
]);
|
|
1018
|
+
n(i.catalogRevision);
|
|
1019
|
+
let x = s(i.payment, d, _);
|
|
1020
|
+
if (x) {
|
|
1021
|
+
if (C.has(x.txId)) throw t("invalid_record");
|
|
1022
|
+
C.add(x.txId);
|
|
1023
|
+
}
|
|
1024
|
+
if (y.tenantId !== m || T(z(y.owner)) !== T(h) || y.kind !== "craft" || D("ivo_", m, h.ownerKind, h.ownerId, n(y.requestId)) !== u.id || T(y) !== u.digest || b.batches !== _ || b.version !== g || T(b.recipe) !== T(d) || v.some((e) => !S.has(e))) throw t("invalid_record");
|
|
1025
|
+
await _e(e, m, d, g);
|
|
1026
|
+
let w = c(i.plan, {
|
|
1027
|
+
recipe: d,
|
|
1028
|
+
batches: _,
|
|
1029
|
+
at: f.at,
|
|
1030
|
+
available: [...S.values()],
|
|
1031
|
+
excludedIds: v
|
|
1032
|
+
}), E = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Set();
|
|
1033
|
+
for (let e of p.values()) {
|
|
1034
|
+
if (e.reason !== "crafted" || e.refKind !== "recipe" || e.refId !== d.id) throw t("invalid_record");
|
|
1035
|
+
let i = r(e.delta, -1e6, 1e6), a = n(e.instanceId);
|
|
1036
|
+
if (i < 0) {
|
|
1037
|
+
let e = w.consume.find((e) => e.instanceId === a);
|
|
1038
|
+
if (!e || -i !== e.qty || O.has(a)) throw t("invalid_record");
|
|
1039
|
+
O.add(a);
|
|
1040
|
+
} else {
|
|
1041
|
+
let n = w.outputs.find((t) => t.itemId === e.itemId);
|
|
1042
|
+
if (!i || !n || w.consume.some((e) => e.instanceId === a) || T(o(e.after).attributes) !== T(n.attributes)) throw t("invalid_record");
|
|
1043
|
+
E.set(n.itemId, (E.get(n.itemId) ?? 0) + i);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
if (O.size !== w.consume.length || w.outputs.some((e) => E.get(e.itemId) !== e.qty)) throw t("invalid_record");
|
|
1047
|
+
} else if (u.craft !== null) throw t("invalid_record");
|
|
1048
|
+
if (f.kind === "reserve" || f.kind === "release") {
|
|
1049
|
+
let e = ce(u, f.kind, f.at), n = w.get(e.reservationId);
|
|
1050
|
+
if (e.selections.length !== f.changes.length) throw t("invalid_record");
|
|
1051
|
+
if (f.kind === "reserve") {
|
|
1052
|
+
if (n) throw t("invalid_record");
|
|
1053
|
+
w.set(e.reservationId, {
|
|
1054
|
+
admission: e,
|
|
1055
|
+
at: f.at,
|
|
1056
|
+
released: !1
|
|
1057
|
+
});
|
|
1058
|
+
} else {
|
|
1059
|
+
if (!n || n.released || n.at > f.at || T(n.admission.selections.map((e) => ({
|
|
1060
|
+
...e,
|
|
1061
|
+
before: {
|
|
1062
|
+
...e.before,
|
|
1063
|
+
locked: !0
|
|
1064
|
+
}
|
|
1065
|
+
}))) !== T(e.selections)) throw t("invalid_record");
|
|
1066
|
+
n.released = !0;
|
|
1067
|
+
}
|
|
1068
|
+
for (let [n, r] of e.selections.entries()) {
|
|
1069
|
+
let i = S.get(r.instanceId), a = f.changes[n], o = p.get(D("ivg_", f.operationId, String(n)));
|
|
1070
|
+
if (!i || T(i) !== T(r.before) || a?.instanceId !== r.instanceId || a.delta !== 0 || !o || o.reason !== (f.kind === "reserve" ? "reserved" : "released") || o.refKind !== "inventory.reservation" || o.refId !== e.reservationId) throw t("invalid_record");
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
let g = f.kind === "transfer-out" || f.kind === "transfer-in" ? Z(u, f.kind, f.at) : void 0;
|
|
1074
|
+
if (g) {
|
|
1075
|
+
if (await me(e, g, f.at), f.kind === "transfer-out") {
|
|
1076
|
+
let e = w.get(g.reservationId);
|
|
1077
|
+
if (!e || e.released || e.at > f.at || T(e.admission.selections.map((e) => ({
|
|
1078
|
+
...e,
|
|
1079
|
+
before: {
|
|
1080
|
+
...e.before,
|
|
1081
|
+
locked: !0
|
|
1082
|
+
}
|
|
1083
|
+
}))) !== T(fe(g.selections))) throw t("invalid_record");
|
|
1084
|
+
e.released = !0;
|
|
1085
|
+
}
|
|
1086
|
+
for (let [e, n] of g.selections.entries()) {
|
|
1087
|
+
let r = S.get(f.kind === "transfer-out" ? n.instanceId : n.destinationId), i = p.get(D("ivg_", f.operationId, String(e)));
|
|
1088
|
+
if ((f.kind === "transfer-out" ? !r || T(r) !== T(n.before) : r !== void 0) || !i || i.reason !== "transferred" || i.refKind !== "inventory.reservation" || i.refId !== g.reservationId) throw t("invalid_record");
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
for (let [e, n] of f.changes.entries()) {
|
|
1092
|
+
let i = p.get(D("ivg_", f.operationId, String(e)));
|
|
1093
|
+
if (!i || i.sequence !== u.sequence || i.instanceId !== n.instanceId || i.delta !== n.delta || B(i.at) !== f.at) throw t("invalid_record");
|
|
1094
|
+
let a = S.get(n.instanceId), s = (a?.qty ?? 0) + n.delta;
|
|
1095
|
+
if (f.kind === "grant" && n.delta <= 0 || (f.kind === "consume" || f.kind === "expire" || f.kind === "transfer-out") && n.delta >= 0 || f.kind === "transfer-in" && n.delta <= 0 || (f.kind === "equip" || f.kind === "reserve" || f.kind === "release") && n.delta !== 0 || s < 0 || !a && f.kind !== "grant" && !(f.kind === "craft" && n.delta > 0) && f.kind !== "transfer-in") throw t("invalid_record");
|
|
1096
|
+
if (s === 0) {
|
|
1097
|
+
if (i.after !== null || !a || i.itemId !== a.itemId) throw t("invalid_record");
|
|
1098
|
+
S.delete(n.instanceId);
|
|
1099
|
+
} else {
|
|
1100
|
+
let c = o(i.after, [
|
|
1101
|
+
"id",
|
|
1102
|
+
"itemId",
|
|
1103
|
+
"schemaVersion",
|
|
1104
|
+
"qty",
|
|
1105
|
+
"attributes",
|
|
1106
|
+
"acquiredAt",
|
|
1107
|
+
"expiresAt",
|
|
1108
|
+
"locked",
|
|
1109
|
+
"source"
|
|
1110
|
+
]), l = r(c.acquiredAt, 0, f.at), u = c.expiresAt === null ? null : r(c.expiresAt, l + 1, 864e13), d = J({
|
|
1111
|
+
...c,
|
|
1112
|
+
acquiredAt: new Date(l),
|
|
1113
|
+
expiresAt: u === null ? null : new Date(u)
|
|
1114
|
+
});
|
|
1115
|
+
if (d.id !== n.instanceId || d.itemId !== i.itemId || d.qty !== s || !a && f.kind !== "transfer-in" && d.acquiredAt !== f.at || a && T({
|
|
1116
|
+
...a,
|
|
1117
|
+
qty: s,
|
|
1118
|
+
...f.kind === "reserve" || f.kind === "release" || f.kind === "transfer-out" ? { locked: f.kind === "reserve" } : {}
|
|
1119
|
+
}) !== T(d) || f.kind === "transfer-in" && T(d) !== T(pe(g.selections[e]))) throw t("invalid_record");
|
|
1120
|
+
S.set(d.id, d);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
if (S.size > O.maxInstances) throw t("limit_exceeded");
|
|
1125
|
+
let E = await q(e, v, m, h, O.maxInstances), k = !1;
|
|
1126
|
+
try {
|
|
1127
|
+
k = E.length === S.size && E.every((e) => {
|
|
1128
|
+
let t = J(e), n = S.get(t.id);
|
|
1129
|
+
return n !== void 0 && T(t) === T(n);
|
|
1130
|
+
});
|
|
1131
|
+
} catch {
|
|
1132
|
+
k = !1;
|
|
1133
|
+
}
|
|
1134
|
+
if (f && !k) {
|
|
1135
|
+
await e.deleteMany(v.tableName, { where: ie(m, h) });
|
|
1136
|
+
for (let t of S.values()) await e.insert(v.tableName, {
|
|
1137
|
+
tenantId: m,
|
|
1138
|
+
...h,
|
|
1139
|
+
...oe(t)
|
|
1140
|
+
});
|
|
1141
|
+
let t = await q(e, b, m, h, 2048);
|
|
1142
|
+
for (let r of t) S.has(n(r.instanceId)) || await e.delete(b.tableName, String(r.id));
|
|
1143
|
+
k = !0;
|
|
1144
|
+
}
|
|
1145
|
+
return Object.freeze({
|
|
1146
|
+
instances: S.size,
|
|
1147
|
+
ledgerRows: u.length,
|
|
1148
|
+
matches: k
|
|
1149
|
+
});
|
|
1150
|
+
})));
|
|
1151
|
+
}), Ce = (e, r) => $(() => {
|
|
1152
|
+
let { tenantId: i, owner: a } = xe(e);
|
|
1153
|
+
return E(async () => (await G(i, a), d.transactional(async (e) => {
|
|
1154
|
+
await K(e, i, a, !0);
|
|
1155
|
+
let o = await q(e, v, i, a, O.maxInstances), s = await q(e, b, i, a, 2048), c = await q(e, y, i, a, O.maxLedgerRows), l = await e.query(I(x).where(N(P("tenantId", i), P("ownerKey", W(i, a)))).limit(O.maxLedgerRows + 1).descriptor);
|
|
1156
|
+
if (l.length > O.maxLedgerRows) throw t("limit_exceeded");
|
|
1157
|
+
if (!r) return {
|
|
1158
|
+
items: o.map(J),
|
|
1159
|
+
loadouts: s.map((e) => ({
|
|
1160
|
+
slotSet: e.slotSet,
|
|
1161
|
+
slot: e.slot,
|
|
1162
|
+
instanceId: e.instanceId
|
|
1163
|
+
})),
|
|
1164
|
+
ledger: c.map((e) => ({
|
|
1165
|
+
operationId: e.operationId,
|
|
1166
|
+
sequence: e.sequence,
|
|
1167
|
+
instanceId: e.instanceId,
|
|
1168
|
+
itemId: e.itemId,
|
|
1169
|
+
delta: e.delta,
|
|
1170
|
+
reason: e.reason,
|
|
1171
|
+
after: e.after,
|
|
1172
|
+
refKind: e.refKind,
|
|
1173
|
+
refId: e.refId,
|
|
1174
|
+
actor: e.actor,
|
|
1175
|
+
at: B(e.at)
|
|
1176
|
+
})),
|
|
1177
|
+
requests: l.map((e) => ({
|
|
1178
|
+
operationId: e.id,
|
|
1179
|
+
state: e.state,
|
|
1180
|
+
sequence: e.sequence,
|
|
1181
|
+
digest: e.digest,
|
|
1182
|
+
receipt: e.receipt,
|
|
1183
|
+
craft: e.craft,
|
|
1184
|
+
reservation: e.reservation,
|
|
1185
|
+
transfer: e.transfer,
|
|
1186
|
+
createdAt: B(e.createdAt)
|
|
1187
|
+
})),
|
|
1188
|
+
craft: l.filter((e) => e.craft !== null).map((e) => e.craft),
|
|
1189
|
+
reservations: l.filter((e) => e.reservation !== null).map((e) => e.reservation),
|
|
1190
|
+
transfers: l.filter((e) => e.transfer !== null).map((e) => e.transfer)
|
|
1191
|
+
};
|
|
1192
|
+
let u = [.../* @__PURE__ */ new Set([...c.map((e) => n(e.operationId)), ...l.map((e) => n(e.id))])];
|
|
1193
|
+
for (let t = 0; t < u.length; t += 128) await e.updateMany(x.tableName, {
|
|
1194
|
+
state: "erased",
|
|
1195
|
+
ownerKey: null,
|
|
1196
|
+
digest: null,
|
|
1197
|
+
receipt: null,
|
|
1198
|
+
craft: null,
|
|
1199
|
+
reservation: null,
|
|
1200
|
+
transfer: null
|
|
1201
|
+
}, { where: N(P("tenantId", i), F("id", u.slice(t, t + 128))) });
|
|
1202
|
+
await e.updateMany(y.tableName, {
|
|
1203
|
+
ownerId: null,
|
|
1204
|
+
ownerKind: null,
|
|
1205
|
+
instanceId: null,
|
|
1206
|
+
after: null,
|
|
1207
|
+
refKind: null,
|
|
1208
|
+
refId: null,
|
|
1209
|
+
actor: null
|
|
1210
|
+
}, { where: ie(i, a) }), await e.deleteMany(b.tableName, { where: ie(i, a) }), await e.deleteMany(v.tableName, { where: ie(i, a) }), await e.update(C.tableName, W(i, a), {
|
|
1211
|
+
erased: !0,
|
|
1212
|
+
ownerId: null
|
|
1213
|
+
});
|
|
1214
|
+
})));
|
|
1215
|
+
}), we = (e, i) => {
|
|
1216
|
+
let a = structuredClone(e), s = o(i, [
|
|
1217
|
+
"tenantId",
|
|
1218
|
+
"owner",
|
|
1219
|
+
"recipeId",
|
|
1220
|
+
"requestId",
|
|
1221
|
+
"batches"
|
|
1222
|
+
]);
|
|
1223
|
+
if (!H(a)) throw t("forbidden");
|
|
1224
|
+
if (!O.crafting) throw t("unavailable");
|
|
1225
|
+
let c = O.crafting.recipes.find((e) => e.id === n(s.recipeId));
|
|
1226
|
+
if (!c) throw t("not_found");
|
|
1227
|
+
return {
|
|
1228
|
+
who: a,
|
|
1229
|
+
operation: {
|
|
1230
|
+
tenantId: n(s.tenantId),
|
|
1231
|
+
owner: z(s.owner),
|
|
1232
|
+
requestId: n(s.requestId),
|
|
1233
|
+
kind: "craft",
|
|
1234
|
+
payload: Object.freeze({
|
|
1235
|
+
recipe: c,
|
|
1236
|
+
version: O.crafting.version,
|
|
1237
|
+
batches: r(s.batches ?? 1, 1, c.maxBatches)
|
|
1238
|
+
})
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
}, Te = (e, a) => {
|
|
1242
|
+
let s = structuredClone(e), c = o(a, [
|
|
1243
|
+
"tenantId",
|
|
1244
|
+
"owner",
|
|
1245
|
+
"requestId",
|
|
1246
|
+
"itemId",
|
|
1247
|
+
"qty",
|
|
1248
|
+
"attributes",
|
|
1249
|
+
"reason",
|
|
1250
|
+
"ref"
|
|
1251
|
+
]);
|
|
1252
|
+
if (!H(s)) throw t("forbidden");
|
|
1253
|
+
let l = o(c.ref, ["kind", "id"]);
|
|
1254
|
+
return {
|
|
1255
|
+
who: s,
|
|
1256
|
+
operation: {
|
|
1257
|
+
tenantId: n(c.tenantId),
|
|
1258
|
+
owner: z(c.owner),
|
|
1259
|
+
requestId: n(c.requestId),
|
|
1260
|
+
kind: "grant",
|
|
1261
|
+
payload: Object.freeze({
|
|
1262
|
+
itemId: n(c.itemId),
|
|
1263
|
+
qty: r(c.qty, 1, 1e6),
|
|
1264
|
+
...c.attributes === void 0 ? {} : { attributes: i(c.attributes) },
|
|
1265
|
+
reason: n(c.reason),
|
|
1266
|
+
ref: Object.freeze({
|
|
1267
|
+
kind: n(l.kind),
|
|
1268
|
+
id: n(l.id)
|
|
1269
|
+
})
|
|
1270
|
+
})
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
}, Ee = (e, r, i) => {
|
|
1274
|
+
let a = structuredClone(e), s = o(r, i === "reserve" ? [
|
|
1275
|
+
"tenantId",
|
|
1276
|
+
"owner",
|
|
1277
|
+
"reservationId",
|
|
1278
|
+
"items"
|
|
1279
|
+
] : [
|
|
1280
|
+
"tenantId",
|
|
1281
|
+
"owner",
|
|
1282
|
+
"reservationId"
|
|
1283
|
+
]);
|
|
1284
|
+
if (!H(a)) throw t("forbidden");
|
|
1285
|
+
let c = n(s.tenantId), l = z(s.owner), u = n(s.reservationId);
|
|
1286
|
+
return {
|
|
1287
|
+
who: a,
|
|
1288
|
+
operation: Object.freeze({
|
|
1289
|
+
tenantId: c,
|
|
1290
|
+
owner: l,
|
|
1291
|
+
requestId: X(i, u),
|
|
1292
|
+
kind: i,
|
|
1293
|
+
payload: Object.freeze({
|
|
1294
|
+
reservationId: u,
|
|
1295
|
+
...i === "reserve" ? { items: _(s.items) } : {}
|
|
1296
|
+
})
|
|
1297
|
+
})
|
|
1298
|
+
};
|
|
1299
|
+
}, De = (e, r) => $(() => {
|
|
1300
|
+
let { operation: i } = Ee(e, r, "release"), { tenantId: a, owner: o, payload: s } = i, c = n(s.reservationId);
|
|
1301
|
+
return E(() => d.transactional(async (e) => {
|
|
1302
|
+
let n = (await e.query(I(C).where(P("id", W(a, o))).limit(1).descriptor))[0];
|
|
1303
|
+
ae(n, a, o);
|
|
1304
|
+
let r = (await e.query(I(x).where(P("id", se(a, o, "reserve", c))).limit(1).descriptor))[0];
|
|
1305
|
+
if (!r || r.state === "pending") {
|
|
1306
|
+
if (r && (r.tenantId !== a || r.ownerKey !== W(a, o) || r.reservation !== null || r.craft !== null || r.transfer !== null || r.receipt !== null || r.digest !== null || r.sequence !== null)) throw t("invalid_record");
|
|
1307
|
+
return Object.freeze({
|
|
1308
|
+
reservationId: c,
|
|
1309
|
+
state: "not-observed",
|
|
1310
|
+
items: Object.freeze([]),
|
|
1311
|
+
reserve: null,
|
|
1312
|
+
release: null,
|
|
1313
|
+
transfer: null
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
if (!n || r.state !== "committed") throw t("invalid_record");
|
|
1317
|
+
let i = await le(e, a, o, c), s = Object.freeze(i.accepted.selections.map((e) => Object.freeze({
|
|
1318
|
+
qty: e.qty,
|
|
1319
|
+
instance: Object.freeze({
|
|
1320
|
+
...e.before,
|
|
1321
|
+
locked: !0
|
|
1322
|
+
})
|
|
1323
|
+
}))), l = (await e.query(I(x).where(P("id", D("ivo_", a, o.ownerKind, o.ownerId, de("transfer-out", c, W(a, o))))).limit(1).descriptor))[0];
|
|
1324
|
+
if (l && l.state !== "pending" && l.state !== "committed") throw t("invalid_record");
|
|
1325
|
+
let u = (await e.query(I(x).where(P("id", se(a, o, "release", c))).limit(1).descriptor))[0];
|
|
1326
|
+
if (l?.state === "committed" && u && u.state !== "pending") throw t("invalid_record");
|
|
1327
|
+
if (l?.state === "committed") {
|
|
1328
|
+
let n = Y(l, "transfer-out"), r = Z(l, "transfer-out", n.at);
|
|
1329
|
+
if (n.at < i.receipt.at || T(fe(r.selections)) !== T(i.accepted.selections.map((e) => ({
|
|
1330
|
+
...e,
|
|
1331
|
+
before: {
|
|
1332
|
+
...e.before,
|
|
1333
|
+
locked: !0
|
|
1334
|
+
}
|
|
1335
|
+
})))) throw t("invalid_record");
|
|
1336
|
+
let a = await me(e, r, n.at);
|
|
1337
|
+
return Object.freeze({
|
|
1338
|
+
reservationId: c,
|
|
1339
|
+
state: "transferred",
|
|
1340
|
+
items: s,
|
|
1341
|
+
reserve: i.receipt,
|
|
1342
|
+
release: null,
|
|
1343
|
+
transfer: Object.freeze({
|
|
1344
|
+
from: n,
|
|
1345
|
+
to: a
|
|
1346
|
+
})
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
if (u && u.state !== "pending" && u.state !== "committed") throw t("invalid_record");
|
|
1350
|
+
if (u?.state === "committed") {
|
|
1351
|
+
let e = Y(u, "release"), n = ce(u, "release", e.at);
|
|
1352
|
+
if (e.at < i.receipt.at || T(n.selections) !== T(i.accepted.selections.map((e) => ({
|
|
1353
|
+
...e,
|
|
1354
|
+
before: {
|
|
1355
|
+
...e.before,
|
|
1356
|
+
locked: !0
|
|
1357
|
+
}
|
|
1358
|
+
})))) throw t("invalid_record");
|
|
1359
|
+
return Object.freeze({
|
|
1360
|
+
reservationId: c,
|
|
1361
|
+
state: "released",
|
|
1362
|
+
items: s,
|
|
1363
|
+
reserve: i.receipt,
|
|
1364
|
+
release: e,
|
|
1365
|
+
transfer: null
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
return Object.freeze({
|
|
1369
|
+
reservationId: c,
|
|
1370
|
+
state: "reserved",
|
|
1371
|
+
items: s,
|
|
1372
|
+
reserve: i.receipt,
|
|
1373
|
+
release: null,
|
|
1374
|
+
transfer: null
|
|
1375
|
+
});
|
|
1376
|
+
}));
|
|
1377
|
+
}), Oe = (e, t) => j.map(De(e, t), (e) => Object.freeze({
|
|
1378
|
+
reservationId: e.reservationId,
|
|
1379
|
+
state: e.state,
|
|
1380
|
+
items: e.state === "reserved" ? e.items : Object.freeze([])
|
|
1381
|
+
})), ke = async (e, n, r) => {
|
|
1382
|
+
let { tenantId: i, from: a, to: o, reservationId: s } = n, c = W(i, a), l = W(i, o), u = de("transfer-out", s, c), f = de("transfer-in", s, c), p = D("ivo_", i, a.ownerKind, a.ownerId, u), m = D("ivo_", i, o.ownerKind, o.ownerId, f), h = Object.freeze(r.map((e) => Object.freeze({
|
|
1383
|
+
...e,
|
|
1384
|
+
before: Object.freeze({
|
|
1385
|
+
...e.before,
|
|
1386
|
+
locked: !0
|
|
1387
|
+
}),
|
|
1388
|
+
destinationId: e.qty === e.before.qty ? e.instanceId : D("ivi_", "reservation.transfer", i, s, c, l, e.instanceId)
|
|
1389
|
+
}))), g = Object.freeze({
|
|
1390
|
+
tenantId: i,
|
|
1391
|
+
owner: a,
|
|
1392
|
+
requestId: u,
|
|
1393
|
+
kind: "transfer-out",
|
|
1394
|
+
payload: Object.freeze({
|
|
1395
|
+
reservationId: s,
|
|
1396
|
+
peerKey: l,
|
|
1397
|
+
peerOperationId: m,
|
|
1398
|
+
selections: h
|
|
1399
|
+
})
|
|
1400
|
+
}), _ = Object.freeze({
|
|
1401
|
+
tenantId: i,
|
|
1402
|
+
owner: o,
|
|
1403
|
+
requestId: f,
|
|
1404
|
+
kind: "transfer-in",
|
|
1405
|
+
payload: Object.freeze({
|
|
1406
|
+
reservationId: s,
|
|
1407
|
+
peerKey: c,
|
|
1408
|
+
peerOperationId: p,
|
|
1409
|
+
selections: h
|
|
1410
|
+
})
|
|
1411
|
+
}), v = await j.runPromise(j.result(Q(e, g)));
|
|
1412
|
+
if (M.isFailure(v)) throw v.failure;
|
|
1413
|
+
let y = await j.runPromise(j.result(Q(e, _)));
|
|
1414
|
+
if (M.isFailure(y)) throw y.failure;
|
|
1415
|
+
let b = te(d, async (e) => {
|
|
1416
|
+
for (let t of [a, o].sort((e, t) => W(i, e) < W(i, t) ? -1 : 1)) await K(e, i, t);
|
|
1417
|
+
});
|
|
1418
|
+
return ne(d, [
|
|
1419
|
+
b,
|
|
1420
|
+
v.success,
|
|
1421
|
+
y.success
|
|
1422
|
+
], async (e, [, n, r]) => {
|
|
1423
|
+
let i = (await e.query(I(x).where(P("id", p)).limit(1).descriptor))[0], a = (await e.query(I(x).where(P("id", m)).limit(1).descriptor))[0];
|
|
1424
|
+
if (!i || !a) throw t("invalid_record");
|
|
1425
|
+
return await me(e, Z(i, "transfer-out", n.at), n.at), await me(e, Z(a, "transfer-in", r.at), r.at), Object.freeze({
|
|
1426
|
+
reservationId: s,
|
|
1427
|
+
from: n,
|
|
1428
|
+
to: r
|
|
1429
|
+
});
|
|
1430
|
+
});
|
|
1431
|
+
}, Ae = (e, n) => $(() => {
|
|
1432
|
+
let r = structuredClone(e), i = h(n), { tenantId: a, from: o, to: s, reservationId: c } = i;
|
|
1433
|
+
if (!H(r)) throw t("forbidden");
|
|
1434
|
+
return E(async () => {
|
|
1435
|
+
await G(a, o), await G(a, s);
|
|
1436
|
+
let e = await d.transactional(async (e) => {
|
|
1437
|
+
for (let t of [o, s].sort((e, t) => W(a, e) < W(a, t) ? -1 : 1)) await K(e, a, t);
|
|
1438
|
+
return le(e, a, o, c);
|
|
1439
|
+
});
|
|
1440
|
+
return ke(r, i, e.accepted.selections);
|
|
1441
|
+
});
|
|
1442
|
+
}), je = (e, n) => $(() => {
|
|
1443
|
+
let r = structuredClone(e), i = g(n), { tenantId: a, from: o, to: s, reservationId: c } = i;
|
|
1444
|
+
if (!H(r)) throw t("forbidden");
|
|
1445
|
+
let { operation: l } = Ee(r, {
|
|
1446
|
+
tenantId: a,
|
|
1447
|
+
owner: o,
|
|
1448
|
+
reservationId: c,
|
|
1449
|
+
items: i.items
|
|
1450
|
+
}, "reserve");
|
|
1451
|
+
return E(async () => {
|
|
1452
|
+
await G(a, o), await G(a, s);
|
|
1453
|
+
let e = await j.runPromise(j.result(Q(r, l)));
|
|
1454
|
+
if (M.isFailure(e)) throw e.failure;
|
|
1455
|
+
let t = await d.transactional(async (e) => {
|
|
1456
|
+
for (let t of [o, s].sort((e, t) => W(a, e) < W(a, t) ? -1 : 1)) await K(e, a, t);
|
|
1457
|
+
return (await e.query(I(x).where(P("id", se(a, o, "reserve", c))).limit(1).descriptor))[0]?.state === "committed" ? (await le(e, a, o, c)).accepted : void 0;
|
|
1458
|
+
}) ?? await ue(l, re()), n = await ke(r, i, t.selections);
|
|
1459
|
+
return ne(d, [e.success, n], async (e, [t, n]) => Object.freeze({
|
|
1460
|
+
reserve: t,
|
|
1461
|
+
transfer: n
|
|
1462
|
+
}));
|
|
1463
|
+
});
|
|
1464
|
+
}), Me = (e, i) => {
|
|
1465
|
+
let a = structuredClone(e), s = o(i, [
|
|
1466
|
+
"tenantId",
|
|
1467
|
+
"owner",
|
|
1468
|
+
"requestId",
|
|
1469
|
+
"instanceId",
|
|
1470
|
+
"qty",
|
|
1471
|
+
"reason",
|
|
1472
|
+
"ref"
|
|
1473
|
+
]);
|
|
1474
|
+
if (!H(a)) throw t("forbidden");
|
|
1475
|
+
let c = o(s.ref, ["kind", "id"]);
|
|
1476
|
+
return {
|
|
1477
|
+
who: a,
|
|
1478
|
+
operation: {
|
|
1479
|
+
tenantId: n(s.tenantId),
|
|
1480
|
+
owner: z(s.owner),
|
|
1481
|
+
requestId: n(s.requestId),
|
|
1482
|
+
kind: "consume",
|
|
1483
|
+
payload: Object.freeze({
|
|
1484
|
+
instanceId: n(s.instanceId),
|
|
1485
|
+
qty: r(s.qty, 1, 1e6),
|
|
1486
|
+
reason: n(s.reason),
|
|
1487
|
+
ref: Object.freeze({
|
|
1488
|
+
kind: n(c.kind),
|
|
1489
|
+
id: n(c.id)
|
|
1490
|
+
})
|
|
1491
|
+
})
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
};
|
|
1495
|
+
return Object.freeze({
|
|
1496
|
+
prepareReservationTransfer: Ae,
|
|
1497
|
+
prepareReserveTransfer: je,
|
|
1498
|
+
prepareReserve: (e, t) => $(() => {
|
|
1499
|
+
let { who: n, operation: r } = Ee(e, t, "reserve");
|
|
1500
|
+
return Q(n, r);
|
|
1501
|
+
}),
|
|
1502
|
+
prepareRelease: (e, t) => $(() => {
|
|
1503
|
+
let { who: n, operation: r } = Ee(e, t, "release");
|
|
1504
|
+
return Q(n, r);
|
|
1505
|
+
}),
|
|
1506
|
+
reservation: Oe,
|
|
1507
|
+
reservationEvidence: De,
|
|
1508
|
+
prepareCraft: (e, t) => $(() => {
|
|
1509
|
+
let { who: n, operation: r } = we(e, t);
|
|
1510
|
+
return Q(n, r);
|
|
1511
|
+
}),
|
|
1512
|
+
prepareGrant: (e, t) => $(() => {
|
|
1513
|
+
let { who: n, operation: r } = Te(e, t);
|
|
1514
|
+
return Q(n, r);
|
|
1515
|
+
}),
|
|
1516
|
+
craft: (e, t) => $(() => {
|
|
1517
|
+
let { who: n, operation: r } = we(e, t);
|
|
1518
|
+
return ye(n, r);
|
|
1519
|
+
}),
|
|
1520
|
+
grant: (e, t) => $(() => {
|
|
1521
|
+
let { who: n, operation: r } = Te(e, t);
|
|
1522
|
+
return ye(n, r);
|
|
1523
|
+
}),
|
|
1524
|
+
prepareConsume: (e, t) => $(() => {
|
|
1525
|
+
let { who: n, operation: r } = Me(e, t);
|
|
1526
|
+
return Q(n, r);
|
|
1527
|
+
}),
|
|
1528
|
+
consume: (e, t) => $(() => {
|
|
1529
|
+
let { who: n, operation: r } = Me(e, t);
|
|
1530
|
+
return ye(n, r);
|
|
1531
|
+
}),
|
|
1532
|
+
expire: (e, i) => $(() => {
|
|
1533
|
+
let a = structuredClone(e), s = o(i, [
|
|
1534
|
+
"tenantId",
|
|
1535
|
+
"owner",
|
|
1536
|
+
"requestId",
|
|
1537
|
+
"until"
|
|
1538
|
+
]);
|
|
1539
|
+
if (!H(a)) throw t("forbidden");
|
|
1540
|
+
return ye(a, {
|
|
1541
|
+
tenantId: n(s.tenantId),
|
|
1542
|
+
owner: z(s.owner),
|
|
1543
|
+
requestId: n(s.requestId),
|
|
1544
|
+
kind: "expire",
|
|
1545
|
+
payload: Object.freeze({ until: r(s.until, 0, 864e13) })
|
|
1546
|
+
});
|
|
1547
|
+
}),
|
|
1548
|
+
equip: (e, t) => $(() => {
|
|
1549
|
+
let r = structuredClone(e), { tenantId: i, owner: a } = U(r), s = o(t, [
|
|
1550
|
+
"slotSet",
|
|
1551
|
+
"slot",
|
|
1552
|
+
"instanceId",
|
|
1553
|
+
"requestId"
|
|
1554
|
+
]);
|
|
1555
|
+
return ye(r, {
|
|
1556
|
+
tenantId: i,
|
|
1557
|
+
owner: a,
|
|
1558
|
+
requestId: n(s.requestId),
|
|
1559
|
+
kind: "equip",
|
|
1560
|
+
payload: Object.freeze({
|
|
1561
|
+
slotSet: n(s.slotSet),
|
|
1562
|
+
slot: n(s.slot),
|
|
1563
|
+
instanceId: s.instanceId === null ? null : n(s.instanceId)
|
|
1564
|
+
})
|
|
1565
|
+
});
|
|
1566
|
+
}),
|
|
1567
|
+
mine: (e) => be(e),
|
|
1568
|
+
loadout: (e, t) => be(e, t),
|
|
1569
|
+
exportSubject: (e) => Ce(e, !1),
|
|
1570
|
+
eraseSubject: (e) => j.asVoid(Ce(e, !0)),
|
|
1571
|
+
auditInventory: (e, t, n) => Se(e, t, n, !1),
|
|
1572
|
+
rebuildInventory: (e, t, n) => Se(e, t, n, !0)
|
|
1573
|
+
});
|
|
1574
|
+
};
|
|
1575
|
+
//#endregion
|
|
1576
|
+
export { V as dataStoreInventory, z as inventoryOwner, R as resolveInventoryOptions };
|