Skip to content

Commit 3a5e059

Browse files
committed
rename arg in setRecord to value
1 parent 581ef8c commit 3a5e059

16 files changed

+71
-71
lines changed

packages/stash/src/actions/decodeKey.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("decodeKey", () => {
2020
const stash = createStash(config);
2121
const table = config.namespaces.namespace1.tables.table1;
2222
const key = { field2: 1, field3: 2n };
23-
setRecord({ stash, table, key, record: { field1: "hello" } });
23+
setRecord({ stash, table, key, value: { field1: "hello" } });
2424

2525
const encodedKey = encodeKey({ table, key });
2626
attest<typeof key>(decodeKey({ stash, table, encodedKey })).equals({ field2: 1, field3: 2n });

packages/stash/src/actions/deleteRecord.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ describe("deleteRecord", () => {
2929
stash,
3030
table,
3131
key: { field2: 1, field3: 2 },
32-
record: { field1: "hello" },
32+
value: { field1: "hello" },
3333
});
3434

3535
setRecord({
3636
stash,
3737
table,
3838
key: { field2: 3, field3: 1 },
39-
record: { field1: "world" },
39+
value: { field1: "world" },
4040
});
4141

4242
deleteRecord({

packages/stash/src/actions/getKeys.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe("getKeys", () => {
2323
const table = config.tables.test;
2424
const stash = createStash(config);
2525

26-
setRecord({ stash, table, key: { player: 1, match: 2 }, record: { x: 3, y: 4 } });
27-
setRecord({ stash, table, key: { player: 5, match: 6 }, record: { x: 7, y: 8 } });
26+
setRecord({ stash, table, key: { player: 1, match: 2 }, value: { x: 3, y: 4 } });
27+
setRecord({ stash, table, key: { player: 5, match: 6 }, value: { x: 7, y: 8 } });
2828

2929
attest<{ [encodedKey: string]: { player: number; match: number } }>(getKeys({ stash, table })).snap({
3030
"1|2": { player: 1, match: 2 },

packages/stash/src/actions/getRecord.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ describe("getRecord", () => {
2929
stash,
3030
table,
3131
key: { field2: 1, field3: 2 },
32-
record: { field1: "hello" },
32+
value: { field1: "hello" },
3333
});
3434

3535
setRecord({
3636
stash,
3737
table,
3838
key: { field2: 2, field3: 1 },
39-
record: { field1: "world" },
39+
value: { field1: "world" },
4040
});
4141

4242
attest(

packages/stash/src/actions/getRecords.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe("getRecords", () => {
2323
const table = config.tables.test;
2424
const stash = createStash(config);
2525

26-
setRecord({ stash, table, key: { player: 1, match: 2 }, record: { x: 3n, y: 4n } });
27-
setRecord({ stash, table, key: { player: 5, match: 6 }, record: { x: 7n, y: 8n } });
26+
setRecord({ stash, table, key: { player: 1, match: 2 }, value: { x: 3n, y: 4n } });
27+
setRecord({ stash, table, key: { player: 5, match: 6 }, value: { x: 7n, y: 8n } });
2828

2929
attest<{ [encodedKey: string]: { player: number; match: number; x: bigint; y: bigint } }>(
3030
getRecords({ stash, table }),

packages/stash/src/actions/getTable.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("getTable", () => {
5252
});
5353

5454
const key = { field2: 1, field3: 2n };
55-
table.setRecord({ key, record: { field1: "hello" } });
55+
table.setRecord({ key, value: { field1: "hello" } });
5656

5757
const encodedKey = table.encodeKey({ key });
5858
attest<typeof key>(table.decodeKey({ encodedKey })).equals({ field2: 1, field3: 2n });
@@ -151,8 +151,8 @@ describe("getTable", () => {
151151
}),
152152
});
153153

154-
table.setRecord({ key: { player: 1, match: 2 }, record: { x: 3, y: 4 } });
155-
table.setRecord({ key: { player: 5, match: 6 }, record: { x: 7, y: 8 } });
154+
table.setRecord({ key: { player: 1, match: 2 }, value: { x: 3, y: 4 } });
155+
table.setRecord({ key: { player: 5, match: 6 }, value: { x: 7, y: 8 } });
156156

157157
attest<{ [encodedKey: string]: { player: number; match: number } }>(table.getKeys()).snap({
158158
"1|2": { player: 1, match: 2 },
@@ -203,8 +203,8 @@ describe("getTable", () => {
203203
const stash = createStash();
204204
const table = stash.getTable({ table: config });
205205

206-
table.setRecord({ key: { player: 1, match: 2 }, record: { x: 3n, y: 4n } });
207-
table.setRecord({ key: { player: 5, match: 6 }, record: { x: 7n, y: 8n } });
206+
table.setRecord({ key: { player: 1, match: 2 }, value: { x: 3n, y: 4n } });
207+
table.setRecord({ key: { player: 5, match: 6 }, value: { x: 7n, y: 8n } });
208208

209209
attest<{ [encodedKey: string]: { player: number; match: number; x: bigint; y: bigint } }>(
210210
table.getRecords(),
@@ -239,7 +239,7 @@ describe("getTable", () => {
239239
table.setRecord({
240240
// @ts-expect-error Property 'field2' is missing in type '{ field3: number; }'
241241
key: { field3: 2 },
242-
record: { field1: "" },
242+
value: { field1: "" },
243243
}),
244244
)
245245
.throws("Provided key is missing field field2.")
@@ -249,15 +249,15 @@ describe("getTable", () => {
249249
table.setRecord({
250250
// @ts-expect-error Type 'string' is not assignable to type 'number'.
251251
key: { field2: 1, field3: "invalid" },
252-
record: { field1: "" },
252+
value: { field1: "" },
253253
}),
254254
).type.errors(`Type 'string' is not assignable to type 'number'.`);
255255

256256
attest(() =>
257257
table.setRecord({
258258
key: { field2: 1, field3: 2 },
259259
// @ts-expect-error Type 'number' is not assignable to type 'string'.
260-
record: { field1: 1 },
260+
value: { field1: 1 },
261261
}),
262262
).type.errors(`Type 'number' is not assignable to type 'string'.`);
263263
});
@@ -314,7 +314,7 @@ describe("getTable", () => {
314314

315315
table1.subscribe({ subscriber });
316316

317-
table1.setRecord({ key: { a: "0x00" }, record: { b: 1n, c: 2 } });
317+
table1.setRecord({ key: { a: "0x00" }, value: { b: 1n, c: 2 } });
318318

319319
expect(subscriber).toHaveBeenCalledTimes(1);
320320
expect(subscriber).toHaveBeenNthCalledWith(1, {
@@ -325,10 +325,10 @@ describe("getTable", () => {
325325
});
326326

327327
// Expect unrelated updates to not notify subscribers
328-
table2.setRecord({ key: { a: "0x01" }, record: { b: 1n, c: 2 } });
328+
table2.setRecord({ key: { a: "0x01" }, value: { b: 1n, c: 2 } });
329329
expect(subscriber).toHaveBeenCalledTimes(1);
330330

331-
table1.setRecord({ key: { a: "0x00" }, record: { b: 1n, c: 3 } });
331+
table1.setRecord({ key: { a: "0x00" }, value: { b: 1n, c: 3 } });
332332

333333
expect(subscriber).toHaveBeenCalledTimes(2);
334334
expect(subscriber).toHaveBeenNthCalledWith(2, {

packages/stash/src/actions/runQuery.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ describe("runQuery", () => {
4545
const items = ["0xgold", "0xsilver"] as const;
4646
const num = 5;
4747
for (let i = 0; i < num; i++) {
48-
setRecord({ stash, table: Position, key: { player: `0x${String(i)}` }, record: { x: i, y: num - i } });
48+
setRecord({ stash, table: Position, key: { player: `0x${String(i)}` }, value: { x: i, y: num - i } });
4949
if (i > 2) {
50-
setRecord({ stash, table: Health, key: { player: `0x${String(i)}` }, record: { health: i } });
50+
setRecord({ stash, table: Health, key: { player: `0x${String(i)}` }, value: { health: i } });
5151
}
5252
for (const item of items) {
53-
setRecord({ stash, table: Inventory, key: { player: `0x${String(i)}`, item }, record: { amount: i } });
53+
setRecord({ stash, table: Inventory, key: { player: `0x${String(i)}`, item }, value: { amount: i } });
5454
}
5555
}
5656
});

packages/stash/src/actions/setRecord.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ describe("setRecord", () => {
2727
stash,
2828
table,
2929
key: { field2: 1, field3: 2 },
30-
record: { field1: "hello" },
30+
value: { field1: "hello" },
3131
});
3232

3333
setRecord({
3434
stash,
3535
table,
3636
key: { field2: 2, field3: 1 },
37-
record: { field1: "world" },
37+
value: { field1: "world" },
3838
});
3939

4040
attest(stash.get().records).snap({
@@ -71,7 +71,7 @@ describe("setRecord", () => {
7171
table,
7272
// @ts-expect-error Property 'field2' is missing in type '{ field3: number; }'
7373
key: { field3: 2 },
74-
record: { field1: "" },
74+
value: { field1: "" },
7575
}),
7676
)
7777
.throws("Provided key is missing field field2.")
@@ -83,7 +83,7 @@ describe("setRecord", () => {
8383
table,
8484
// @ts-expect-error Type 'string' is not assignable to type 'number'.
8585
key: { field2: 1, field3: "invalid" },
86-
record: { field1: "" },
86+
value: { field1: "" },
8787
}),
8888
).type.errors(`Type 'string' is not assignable to type 'number'.`);
8989

@@ -93,7 +93,7 @@ describe("setRecord", () => {
9393
table,
9494
key: { field2: 1, field3: 2 },
9595
// @ts-expect-error Type 'number' is not assignable to type 'string'.
96-
record: { field1: 1 },
96+
value: { field1: 1 },
9797
}),
9898
).type.errors(`Type 'number' is not assignable to type 'string'.`);
9999
});

packages/stash/src/actions/setRecord.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ export type SetRecordArgs<table extends Table = Table> = {
66
stash: Stash;
77
table: table;
88
key: Key<table>;
9-
record: Partial<TableRecord<table>>;
9+
value: Partial<TableRecord<table>>;
1010
};
1111

1212
export type SetRecordResult = void;
1313

14-
export function setRecord<table extends Table>({ stash, table, key, record }: SetRecordArgs<table>): SetRecordResult {
14+
export function setRecord<table extends Table>({ stash, table, key, value }: SetRecordArgs<table>): SetRecordResult {
1515
setRecords({
1616
stash,
1717
table,
1818
records: [
1919
// Stored record should include key
20-
{ ...record, ...key },
20+
{ ...value, ...key },
2121
],
2222
});
2323
}

packages/stash/src/actions/subscribeQuery.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ describe("defineQuery", () => {
3737
const items = ["0xgold", "0xsilver"] as const;
3838
const num = 5;
3939
for (let i = 0; i < num; i++) {
40-
setRecord({ stash, table: Position, key: { player: `0x${String(i)}` }, record: { x: i, y: num - i } });
40+
setRecord({ stash, table: Position, key: { player: `0x${String(i)}` }, value: { x: i, y: num - i } });
4141
if (i > 2) {
42-
setRecord({ stash, table: Health, key: { player: `0x${String(i)}` }, record: { health: i } });
42+
setRecord({ stash, table: Health, key: { player: `0x${String(i)}` }, value: { health: i } });
4343
}
4444
for (const item of items) {
45-
setRecord({ stash, table: Inventory, key: { player: `0x${String(i)}`, item }, record: { amount: i } });
45+
setRecord({ stash, table: Inventory, key: { player: `0x${String(i)}`, item }, value: { amount: i } });
4646
}
4747
}
4848
});
@@ -54,7 +54,7 @@ describe("defineQuery", () => {
5454
"0x4": { player: "0x4" },
5555
});
5656

57-
setRecord({ stash, table: Health, key: { player: `0x2` }, record: { health: 2 } });
57+
setRecord({ stash, table: Health, key: { player: `0x2` }, value: { health: 2 } });
5858

5959
attest(result.keys).snap({
6060
"0x2": { player: "0x2" },
@@ -69,7 +69,7 @@ describe("defineQuery", () => {
6969
const result = subscribeQuery({ stash, query: [Matches(Position, { x: 4 }), In(Health)] });
7070
result.subscribe(subscriber);
7171

72-
setRecord({ stash, table: Position, key: { player: "0x4" }, record: { y: 2 } });
72+
setRecord({ stash, table: Position, key: { player: "0x4" }, value: { y: 2 } });
7373

7474
expect(subscriber).toBeCalledTimes(1);
7575
attest(lastUpdate).snap({
@@ -94,7 +94,7 @@ describe("defineQuery", () => {
9494
const result = subscribeQuery({ stash, query: [In(Position), In(Health)] });
9595
result.subscribe(subscriber);
9696

97-
setRecord({ stash, table: Health, key: { player: `0x2` }, record: { health: 2 } });
97+
setRecord({ stash, table: Health, key: { player: `0x2` }, value: { health: 2 } });
9898

9999
expect(subscriber).toBeCalledTimes(1);
100100
attest(lastUpdate).snap({

packages/stash/src/actions/subscribeStore.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("subscribeStore", () => {
3232

3333
subscribeStore({ stash, subscriber });
3434

35-
setRecord({ stash, table: config.tables.namespace1__table1, key: { a: "0x00" }, record: { b: 1n, c: 2 } });
35+
setRecord({ stash, table: config.tables.namespace1__table1, key: { a: "0x00" }, value: { b: 1n, c: 2 } });
3636

3737
expect(subscriber).toHaveBeenCalledTimes(1);
3838
expect(subscriber).toHaveBeenNthCalledWith(1, {
@@ -49,7 +49,7 @@ describe("subscribeStore", () => {
4949
},
5050
});
5151

52-
setRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" }, record: { b: 1n, c: 2 } });
52+
setRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" }, value: { b: 1n, c: 2 } });
5353

5454
expect(subscriber).toHaveBeenCalledTimes(2);
5555
expect(subscriber).toHaveBeenNthCalledWith(2, {
@@ -66,7 +66,7 @@ describe("subscribeStore", () => {
6666
},
6767
});
6868

69-
setRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" }, record: { b: 1n, c: 3 } });
69+
setRecord({ stash, table: config.tables.namespace2__table2, key: { a: "0x01" }, value: { b: 1n, c: 3 } });
7070

7171
expect(subscriber).toHaveBeenCalledTimes(3);
7272
expect(subscriber).toHaveBeenNthCalledWith(3, {

packages/stash/src/actions/subscribeTable.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("subscribeTable", () => {
3434

3535
subscribeTable({ stash, table: table1, subscriber });
3636

37-
setRecord({ stash, table: table1, key: { a: "0x00" }, record: { b: 1n, c: 2 } });
37+
setRecord({ stash, table: table1, key: { a: "0x00" }, value: { b: 1n, c: 2 } });
3838

3939
expect(subscriber).toHaveBeenCalledTimes(1);
4040
expect(subscriber).toHaveBeenNthCalledWith(1, {
@@ -45,10 +45,10 @@ describe("subscribeTable", () => {
4545
});
4646

4747
// Expect unrelated updates to not notify subscribers
48-
setRecord({ stash, table: table2, key: { a: "0x01" }, record: { b: 1n, c: 2 } });
48+
setRecord({ stash, table: table2, key: { a: "0x01" }, value: { b: 1n, c: 2 } });
4949
expect(subscriber).toHaveBeenCalledTimes(1);
5050

51-
setRecord({ stash, table: table1, key: { a: "0x00" }, record: { b: 1n, c: 3 } });
51+
setRecord({ stash, table: table1, key: { a: "0x00" }, value: { b: 1n, c: 3 } });
5252

5353
expect(subscriber).toHaveBeenCalledTimes(2);
5454
expect(subscriber).toHaveBeenNthCalledWith(2, {

packages/stash/src/bench.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ for (let i = 0; i < numItems; i++) {
4242
filledStore.setRecord({
4343
table: config.tables.Position,
4444
key: { player: `0x${i}` },
45-
record: { x: i, y: i },
45+
value: { x: i, y: i },
4646
});
4747
}
4848
bench("setRecord", () => {
4949
filledStore.setRecord({
5050
table: config.tables.Position,
5151
key: { player: `0x0` },
52-
record: { x: 1, y: 1 },
52+
value: { x: 1, y: 1 },
5353
});
5454
}).mark({ mean: [1.2, "us"], median: [1, "us"] });
5555

@@ -58,7 +58,7 @@ bench("10x setRecord", () => {
5858
filledStore.setRecord({
5959
table: config.tables.Position,
6060
key: { player: `0x${i}` },
61-
record: { x: i + 1, y: i + 1 },
61+
value: { x: i + 1, y: i + 1 },
6262
});
6363
}
6464
}).mark({ mean: [13, "us"], median: [12, "us"] });

packages/stash/src/boundTable.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("BoundTable", () => {
2424

2525
describe("setRecord", () => {
2626
it("should set a record in the table", () => {
27-
table.setRecord({ key: { field1: 1 }, record: { field2: "0x00" } });
27+
table.setRecord({ key: { field1: 1 }, value: { field2: "0x00" } });
2828
attest(stash.get().records).snap({ namespace1: { table1: { "1": { field1: 1, field2: "0x00" } } } });
2929
});
3030

@@ -33,15 +33,15 @@ describe("BoundTable", () => {
3333
table.setRecord({
3434
key: { field1: 1 },
3535
// @ts-expect-error Type '"world"' is not assignable to type '`0x${string}`'
36-
record: { field2: "world" },
36+
value: { field2: "world" },
3737
}),
3838
).type.errors("Type '\"world\"' is not assignable to type '`0x${string}`'");
3939
});
4040
});
4141

4242
describe("getRecord", () => {
4343
it("should get a record from the table", () => {
44-
table.setRecord({ key: { field1: 2 }, record: { field2: "0x01" } });
44+
table.setRecord({ key: { field1: 2 }, value: { field2: "0x01" } });
4545
attest(table.getRecord({ key: { field1: 2 } })).snap({ field1: 2, field2: "0x01" });
4646
});
4747
});

0 commit comments

Comments
 (0)