Skip to content

Commit 18d14a7

Browse files
authored
Merge pull request #762 from gadget-inc/revert-754-record-reload
Revert "Give records a reference to the model manager which loaded them"
2 parents 8eebf6b + 88c16c5 commit 18d14a7

28 files changed

+190
-307
lines changed

packages/api-client-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gadgetinc/api-client-core",
3-
"version": "0.15.39",
3+
"version": "0.15.40",
44
"files": [
55
"Readme.md",
66
"dist/**/*"

packages/api-client-core/spec/GadgetRecord.spec.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AnyPublicModelManager } from "../src/AnyModelManager.js";
21
import { ChangeTracking, GadgetRecord } from "../src/GadgetRecord.js";
32
interface SampleBaseRecord {
43
id?: string;
@@ -39,8 +38,6 @@ const expectPersistedChanges = (record: GadgetRecord<SampleBaseRecord>, ...prope
3938
return _expectChanges(record, ChangeTracking.SinceLastPersisted, ...properties);
4039
};
4140

42-
const mockModelManager: AnyPublicModelManager = {} as any;
43-
4441
describe("GadgetRecord", () => {
4542
let productBaseRecord: SampleBaseRecord;
4643
beforeAll(() => {
@@ -51,16 +48,6 @@ describe("GadgetRecord", () => {
5148
};
5249
});
5350

54-
it("can be constructed with a base record and no model manager for backwards compatibility", () => {
55-
const product = new GadgetRecord<SampleBaseRecord>(productBaseRecord);
56-
expect(product.id).toEqual("123");
57-
expect(product.name).toEqual("A cool product");
58-
});
59-
60-
it("can be constructed with a base record and a model manager", () => {
61-
new GadgetRecord<SampleBaseRecord>(productBaseRecord, mockModelManager);
62-
});
63-
6451
it("should respond toJSON, which returns the inner __gadget.fields properties", () => {
6552
const product = new GadgetRecord<SampleBaseRecord>(productBaseRecord);
6653
expect(product.toJSON()).toEqual({

packages/api-client-core/spec/operationRunners.spec.ts

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { diff } from "@n1ru4l/json-patch-plus";
44
import { CombinedError } from "@urql/core";
55
import nock from "nock";
66
import { BackgroundActionHandle } from "../src/BackgroundActionHandle.js";
7-
import type { AnyPublicModelManager, GadgetErrorGroup, LimitToKnownKeys } from "../src/index.js";
7+
import type { AnyModelManager, GadgetErrorGroup, LimitToKnownKeys } from "../src/index.js";
88
import {
99
GadgetConnection,
1010
actionRunner,
@@ -48,7 +48,6 @@ describe("type checks", () => {
4848
// eslint-disable-next-line jest/no-export
4949
describe("operationRunners", () => {
5050
let connection: GadgetConnection;
51-
let manager: AnyPublicModelManager;
5251
let query: string | undefined;
5352
let mockUrqlClient: MockUrqlClient;
5453

@@ -61,26 +60,25 @@ describe("operationRunners", () => {
6160
},
6261
});
6362
jest.spyOn(connection, "currentClient" as any, "get").mockReturnValue(mockUrqlClient as any);
64-
manager = { connection } as AnyPublicModelManager;
6563
});
6664

6765
describe("findOneRunner", () => {
6866
test("can execute a findOne operation against a model", async () => {
6967
const promise = findOneRunner({ connection }, "widget", "123", { id: true, name: true }, "widget");
7068

7169
expect(query).toMatchInlineSnapshot(`
72-
"query widget($id: GadgetID!) {
73-
widget(id: $id) {
74-
id
75-
name
76-
__typename
77-
}
78-
gadgetMeta {
79-
hydrations(modelName:
80-
"widget")
81-
}
82-
}"
83-
`);
70+
"query widget($id: GadgetID!) {
71+
widget(id: $id) {
72+
id
73+
name
74+
__typename
75+
}
76+
gadgetMeta {
77+
hydrations(modelName:
78+
"widget")
79+
}
80+
}"
81+
`);
8482

8583
mockUrqlClient.executeQuery.pushResponse("widget", {
8684
data: {
@@ -318,32 +316,32 @@ describe("operationRunners", () => {
318316

319317
describe("findManyRunner", () => {
320318
test("can execute a findMany operation against a model", async () => {
321-
const promise = findManyRunner({ connection } as AnyPublicModelManager, "widgets", { id: true, name: true }, "widget");
319+
const promise = findManyRunner({ connection } as AnyModelManager, "widgets", { id: true, name: true }, "widget");
322320

323321
expect(query).toMatchInlineSnapshot(`
324-
"query widgets($after: String, $first: Int, $before: String, $last: Int) {
325-
widgets(after: $after, first: $first, before: $before, last: $last) {
326-
pageInfo {
327-
hasNextPage
328-
hasPreviousPage
329-
startCursor
330-
endCursor
331-
}
332-
edges {
333-
cursor
334-
node {
335-
id
336-
name
337-
__typename
338-
}
339-
}
340-
}
341-
gadgetMeta {
342-
hydrations(modelName:
343-
"widget")
344-
}
345-
}"
346-
`);
322+
"query widgets($after: String, $first: Int, $before: String, $last: Int) {
323+
widgets(after: $after, first: $first, before: $before, last: $last) {
324+
pageInfo {
325+
hasNextPage
326+
hasPreviousPage
327+
startCursor
328+
endCursor
329+
}
330+
edges {
331+
cursor
332+
node {
333+
id
334+
name
335+
__typename
336+
}
337+
}
338+
}
339+
gadgetMeta {
340+
hydrations(modelName:
341+
"widget")
342+
}
343+
}"
344+
`);
347345

348346
mockUrqlClient.executeQuery.pushResponse("widgets", {
349347
data: {
@@ -371,7 +369,7 @@ describe("operationRunners", () => {
371369

372370
test("can execute a findMany operation against a namespaced model", async () => {
373371
const promise = findManyRunner(
374-
{ connection } as AnyPublicModelManager,
372+
{ connection } as AnyModelManager,
375373
"widgets",
376374
{ id: true, name: true },
377375
"widget",
@@ -438,7 +436,7 @@ describe("operationRunners", () => {
438436

439437
test("can execute a findMany operation against a namespaced model when the namespace is a string", async () => {
440438
const promise = findManyRunner(
441-
{ connection } as AnyPublicModelManager,
439+
{ connection } as AnyModelManager,
442440
"widgets",
443441
{ id: true, name: true },
444442
"widget",
@@ -504,7 +502,9 @@ describe("operationRunners", () => {
504502
describe("actionRunner", () => {
505503
test("can run a single create action", async () => {
506504
const promise = actionRunner<{ id: string; name: string }>(
507-
manager,
505+
{
506+
connection,
507+
},
508508
"createWidget",
509509
{ id: true, name: true },
510510
"widget",
@@ -544,7 +544,9 @@ describe("operationRunners", () => {
544544

545545
test("can run a single update action", async () => {
546546
const promise = actionRunner<{ id: string; name: string }>(
547-
manager,
547+
{
548+
connection,
549+
},
548550
"updateWidget",
549551
{ id: true, name: true },
550552
"widget",
@@ -589,7 +591,9 @@ describe("operationRunners", () => {
589591

590592
test("can run a single action with an object result type", async () => {
591593
const promise = actionRunner(
592-
manager,
594+
{
595+
connection,
596+
},
593597
"upsertWidget",
594598
{ id: true, name: true, eventAt: true },
595599
"widget",
@@ -642,7 +646,9 @@ describe("operationRunners", () => {
642646

643647
test("can run a single action with an object result type that has an inner return type", async () => {
644648
const promise = actionRunner(
645-
manager,
649+
{
650+
connection,
651+
},
646652
"upsertWidget",
647653
{ id: true, name: true, eventAt: true },
648654
"widget",
@@ -687,7 +693,9 @@ describe("operationRunners", () => {
687693

688694
test("can run an action with hasReturnType", async () => {
689695
const promise = actionRunner(
690-
manager,
696+
{
697+
connection,
698+
},
691699
"createWidget",
692700
{ id: true, name: true },
693701
"widget",
@@ -725,7 +733,9 @@ describe("operationRunners", () => {
725733

726734
test("can throw the error returned by the server for a single action", async () => {
727735
const promise = actionRunner<{ id: string; name: string }>(
728-
manager,
736+
{
737+
connection,
738+
},
729739
"updateWidget",
730740
{ id: true, name: true },
731741
"widget",
@@ -770,7 +780,9 @@ describe("operationRunners", () => {
770780

771781
test("can run a bulk action by ids", async () => {
772782
const promise = actionRunner<{ id: string; name: string }>(
773-
manager,
783+
{
784+
connection,
785+
},
774786
"bulkFlipWidgets",
775787
{ id: true, name: true },
776788
"widget",
@@ -818,7 +830,9 @@ describe("operationRunners", () => {
818830

819831
test("can run a bulk action with params", async () => {
820832
const promise = actionRunner<{ id: string; name: string }>(
821-
manager,
833+
{
834+
connection,
835+
},
822836
"bulkCreateWidgets",
823837
{ id: true, name: true },
824838
"widget",
@@ -866,7 +880,9 @@ describe("operationRunners", () => {
866880

867881
test("can run a bulk action with a returnType", async () => {
868882
const promise = actionRunner(
869-
manager,
883+
{
884+
connection,
885+
},
870886
"bulkCreateWidgets",
871887
{ id: true, name: true },
872888
"widget",
@@ -905,7 +921,9 @@ describe("operationRunners", () => {
905921

906922
test("can run a bulk action with an object returnType", async () => {
907923
const promise = actionRunner(
908-
manager,
924+
{
925+
connection,
926+
},
909927
"bulkUpsertWidgets",
910928
{ id: true, name: true },
911929
"widget",
@@ -952,7 +970,9 @@ describe("operationRunners", () => {
952970

953971
test("throws a nice error when a bulk action returns errors", async () => {
954972
const promise = actionRunner<{ id: string; name: string }>(
955-
manager,
973+
{
974+
connection,
975+
},
956976
"bulkCreateWidgets",
957977
{ id: true, name: true },
958978
"widget",
@@ -990,7 +1010,9 @@ describe("operationRunners", () => {
9901010

9911011
test("throws a nice error when a bulk action returns errors and data", async () => {
9921012
const promise = actionRunner<{ id: string; name: string }>(
993-
manager,
1013+
{
1014+
connection,
1015+
},
9941016
"bulkCreateWidgets",
9951017
{ id: true, name: true },
9961018
"widget",
@@ -1035,7 +1057,9 @@ describe("operationRunners", () => {
10351057

10361058
test("returns undefined when bulk action does not have a result", async () => {
10371059
const promise = actionRunner<{ id: string; name: string }>(
1038-
manager,
1060+
{
1061+
connection,
1062+
},
10391063
"bulkDeleteWidgets",
10401064
null,
10411065
"widget",
@@ -1934,7 +1958,7 @@ describe("operationRunners", () => {
19341958
test("can run a live findMany", async () => {
19351959
const iterator = asyncIterableToIterator(
19361960
findManyRunner<{ id: string; name: string }, { live: true }>(
1937-
{ connection } as AnyPublicModelManager,
1961+
{ connection } as AnyModelManager,
19381962
"widgets",
19391963
{ id: true, name: true },
19401964
"widget",

packages/api-client-core/src/AnyModelManager.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)