@osdk/functions 1.6.0-beta.3 → 1.6.0-beta.4

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/browser/aliases/custom.js +26 -0
  3. package/build/browser/aliases/custom.js.map +1 -0
  4. package/build/browser/aliases/environment.js +48 -0
  5. package/build/browser/aliases/environment.js.map +1 -0
  6. package/build/browser/aliases/index.js +19 -0
  7. package/build/browser/aliases/index.js.map +1 -0
  8. package/build/browser/aliases/loaders.js +66 -0
  9. package/build/browser/aliases/loaders.js.map +1 -0
  10. package/build/browser/aliases/model.js +26 -0
  11. package/build/browser/aliases/model.js.map +1 -0
  12. package/build/browser/aliases/types.js +30 -0
  13. package/build/browser/aliases/types.js.map +1 -0
  14. package/build/browser/edits/EditBatch.js.map +1 -1
  15. package/build/browser/index.js +1 -0
  16. package/build/browser/index.js.map +1 -1
  17. package/build/cjs/{EditBatch-CwPxevhT.d.cts → EditBatch-DenXqhoa.d.cts} +2 -2
  18. package/build/cjs/index.cjs +133 -0
  19. package/build/cjs/index.cjs.map +1 -1
  20. package/build/cjs/index.d.cts +21 -2
  21. package/build/cjs/public/experimental.d.cts +1 -1
  22. package/build/cjs/public/unstable-do-not-use.d.cts +1 -1
  23. package/build/esm/aliases/custom.js +26 -0
  24. package/build/esm/aliases/custom.js.map +1 -0
  25. package/build/esm/aliases/environment.js +48 -0
  26. package/build/esm/aliases/environment.js.map +1 -0
  27. package/build/esm/aliases/index.js +19 -0
  28. package/build/esm/aliases/index.js.map +1 -0
  29. package/build/esm/aliases/loaders.js +66 -0
  30. package/build/esm/aliases/loaders.js.map +1 -0
  31. package/build/esm/aliases/model.js +26 -0
  32. package/build/esm/aliases/model.js.map +1 -0
  33. package/build/esm/aliases/types.js +30 -0
  34. package/build/esm/aliases/types.js.map +1 -0
  35. package/build/esm/edits/EditBatch.js.map +1 -1
  36. package/build/esm/index.js +1 -0
  37. package/build/esm/index.js.map +1 -1
  38. package/build/types/aliases/custom.d.ts +3 -0
  39. package/build/types/aliases/custom.d.ts.map +1 -0
  40. package/build/types/aliases/environment.d.ts +6 -0
  41. package/build/types/aliases/environment.d.ts.map +1 -0
  42. package/build/types/aliases/index.d.ts +2 -0
  43. package/build/types/aliases/index.d.ts.map +1 -0
  44. package/build/types/aliases/loaders.d.ts +3 -0
  45. package/build/types/aliases/loaders.d.ts.map +1 -0
  46. package/build/types/aliases/model.d.ts +3 -0
  47. package/build/types/aliases/model.d.ts.map +1 -0
  48. package/build/types/aliases/types.d.ts +40 -0
  49. package/build/types/aliases/types.d.ts.map +1 -0
  50. package/build/types/edits/EditBatch.d.ts +2 -2
  51. package/build/types/edits/EditBatch.d.ts.map +1 -1
  52. package/build/types/index.d.ts +1 -0
  53. package/build/types/index.d.ts.map +1 -1
  54. package/package.json +4 -4
  55. package/build/browser/edits/createEditBatch.test.js +0 -519
  56. package/build/browser/edits/createEditBatch.test.js.map +0 -1
  57. package/build/browser/transactions/EditRequestManager.test.js +0 -311
  58. package/build/browser/transactions/EditRequestManager.test.js.map +0 -1
  59. package/build/esm/edits/createEditBatch.test.js +0 -519
  60. package/build/esm/edits/createEditBatch.test.js.map +0 -1
  61. package/build/esm/transactions/EditRequestManager.test.js +0 -311
  62. package/build/esm/transactions/EditRequestManager.test.js.map +0 -1
  63. package/build/types/edits/createEditBatch.test.d.ts +0 -1
  64. package/build/types/edits/createEditBatch.test.d.ts.map +0 -1
  65. package/build/types/transactions/EditRequestManager.test.d.ts +0 -1
  66. package/build/types/transactions/EditRequestManager.test.d.ts.map +0 -1
@@ -1,311 +0,0 @@
1
- /*
2
- * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import { LegacyFauxFoundry, MockOntologiesV2, startNodeApiServer } from "@osdk/shared.test";
18
- import pDefer from "p-defer";
19
- import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
20
- import { createWriteableClient } from "./createWriteableClient.js";
21
- import { EditRequestManager } from "./EditRequestManager.js";
22
- describe("EditRequestManager", () => {
23
- let client;
24
- let apiServer;
25
- let baseUrl;
26
- let maybeDeferServer;
27
- let mockedRequestHandler;
28
- let editRequestManager;
29
- beforeAll(() => {
30
- const testSetup = startNodeApiServer(new LegacyFauxFoundry(), createWriteableClient.bind(null, "transaction"));
31
- ({
32
- client,
33
- apiServer
34
- } = testSetup);
35
- baseUrl = testSetup.fauxFoundry.baseUrl;
36
- mockedRequestHandler = vi.fn(async () => {
37
- if (maybeDeferServer) {
38
- await maybeDeferServer.promise;
39
- }
40
- return {
41
- status: 200,
42
- body: {}
43
- };
44
- });
45
- apiServer.use(MockOntologiesV2.OntologyTransactions.postEdits(baseUrl, mockedRequestHandler));
46
- return () => {
47
- apiServer.close();
48
- };
49
- });
50
- beforeEach(() => {
51
- editRequestManager = new EditRequestManager(client);
52
- vi.restoreAllMocks();
53
- });
54
- const addLinkEdit = {
55
- type: "addLink",
56
- primaryKey: "test-primary-key",
57
- linkedObjectPrimaryKey: "test-linked-object-primary-key",
58
- linkType: "test-link-type",
59
- objectType: "test-object-type"
60
- };
61
- const addObjectEdit = {
62
- type: "addObject",
63
- objectType: "test-object-type",
64
- properties: {}
65
- };
66
- it("will stage single edits in a row", async () => {
67
- await editRequestManager.postEdit(addLinkEdit);
68
- expect(mockedRequestHandler).toHaveBeenCalledTimes(1);
69
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
70
- {
71
- "edits": [
72
- {
73
- "linkType": "test-link-type",
74
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
75
- "objectType": "test-object-type",
76
- "primaryKey": "test-primary-key",
77
- "type": "addLink",
78
- },
79
- ],
80
- }
81
- `);
82
- await editRequestManager.postEdit(addObjectEdit);
83
- expect(mockedRequestHandler).toHaveBeenCalledTimes(2);
84
- expect(await mockedRequestHandler.mock.calls[1][0].request.json()).toMatchInlineSnapshot(`
85
- {
86
- "edits": [
87
- {
88
- "objectType": "test-object-type",
89
- "properties": {},
90
- "type": "addObject",
91
- },
92
- ],
93
- }
94
- `);
95
- });
96
- it("stages multiple edits from the same tick in one request in order", async () => {
97
- void editRequestManager.postEdit(addLinkEdit);
98
- void editRequestManager.postEdit(addObjectEdit);
99
- await editRequestManager.postEdit(addObjectEdit);
100
- expect(mockedRequestHandler).toHaveBeenCalledTimes(1);
101
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
102
- {
103
- "edits": [
104
- {
105
- "linkType": "test-link-type",
106
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
107
- "objectType": "test-object-type",
108
- "primaryKey": "test-primary-key",
109
- "type": "addLink",
110
- },
111
- {
112
- "objectType": "test-object-type",
113
- "properties": {},
114
- "type": "addObject",
115
- },
116
- {
117
- "objectType": "test-object-type",
118
- "properties": {},
119
- "type": "addObject",
120
- },
121
- ],
122
- }
123
- `);
124
- await editRequestManager.postEdit(addLinkEdit);
125
- expect(mockedRequestHandler).toHaveBeenCalledTimes(2);
126
- expect(await mockedRequestHandler.mock.calls[1][0].request.json()).toMatchInlineSnapshot(`
127
- {
128
- "edits": [
129
- {
130
- "linkType": "test-link-type",
131
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
132
- "objectType": "test-object-type",
133
- "primaryKey": "test-primary-key",
134
- "type": "addLink",
135
- },
136
- ],
137
- }
138
- `);
139
- });
140
- it("handles edits posted while a request is in flight", async () => {
141
- maybeDeferServer = pDefer();
142
- void editRequestManager.postEdit(addLinkEdit);
143
- await new Promise(resolve => setTimeout(resolve, 0)); // Ensure the initial request is in flight
144
- const secondPromise = editRequestManager.postEdit(addObjectEdit);
145
- void editRequestManager.postEdit(addObjectEdit);
146
- maybeDeferServer.resolve();
147
- await secondPromise; // Awaiting the second edit should ensure the first resolves first and should also resolve the third since it was dispatched in the same tick
148
-
149
- expect(mockedRequestHandler).toHaveBeenCalledTimes(2);
150
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
151
- {
152
- "edits": [
153
- {
154
- "linkType": "test-link-type",
155
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
156
- "objectType": "test-object-type",
157
- "primaryKey": "test-primary-key",
158
- "type": "addLink",
159
- },
160
- ],
161
- }
162
- `);
163
- expect(await mockedRequestHandler.mock.calls[1][0].request.json()).toMatchInlineSnapshot(`
164
- {
165
- "edits": [
166
- {
167
- "objectType": "test-object-type",
168
- "properties": {},
169
- "type": "addObject",
170
- },
171
- {
172
- "objectType": "test-object-type",
173
- "properties": {},
174
- "type": "addObject",
175
- },
176
- ],
177
- }
178
- `);
179
- });
180
- describe("flushPendingEdits", () => {
181
- it("immediately dispatches pending edits without timeout", async () => {
182
- void editRequestManager.postEdit(addLinkEdit);
183
- void editRequestManager.postEdit(addObjectEdit);
184
- expect(mockedRequestHandler).toHaveBeenCalledTimes(0);
185
- await editRequestManager.flushPendingEdits();
186
- expect(mockedRequestHandler).toHaveBeenCalledTimes(1);
187
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
188
- {
189
- "edits": [
190
- {
191
- "linkType": "test-link-type",
192
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
193
- "objectType": "test-object-type",
194
- "primaryKey": "test-primary-key",
195
- "type": "addLink",
196
- },
197
- {
198
- "objectType": "test-object-type",
199
- "properties": {},
200
- "type": "addObject",
201
- },
202
- ],
203
- }
204
- `);
205
- });
206
- it("waits for in-flight and queued requests to complete", async () => {
207
- maybeDeferServer = pDefer();
208
- const firstEdit = editRequestManager.postEdit(addLinkEdit);
209
- await new Promise(resolve => setTimeout(resolve, 0));
210
- const secondEdit = editRequestManager.postEdit(addObjectEdit);
211
- const flushPromise = editRequestManager.flushPendingEdits();
212
- expect(mockedRequestHandler).toHaveBeenCalledTimes(1);
213
- maybeDeferServer.resolve();
214
- await Promise.all([firstEdit, secondEdit, flushPromise]);
215
- expect(mockedRequestHandler).toHaveBeenCalledTimes(2);
216
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
217
- {
218
- "edits": [
219
- {
220
- "linkType": "test-link-type",
221
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
222
- "objectType": "test-object-type",
223
- "primaryKey": "test-primary-key",
224
- "type": "addLink",
225
- },
226
- ],
227
- }
228
- `);
229
- expect(await mockedRequestHandler.mock.calls[1][0].request.json()).toMatchInlineSnapshot(`
230
- {
231
- "edits": [
232
- {
233
- "objectType": "test-object-type",
234
- "properties": {},
235
- "type": "addObject",
236
- },
237
- ],
238
- }
239
- `);
240
- });
241
- it("does nothing when there are no pending edits", async () => {
242
- await editRequestManager.flushPendingEdits();
243
- expect(mockedRequestHandler).not.toHaveBeenCalled();
244
- });
245
- it("cancels timeout and immediately dispatches edits", async () => {
246
- const clearTimeoutSpy = vi.spyOn(global, "clearTimeout");
247
- void editRequestManager.postEdit(addLinkEdit);
248
- await editRequestManager.flushPendingEdits();
249
- expect(clearTimeoutSpy).toHaveBeenCalled();
250
- expect(mockedRequestHandler).toHaveBeenCalledTimes(1);
251
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
252
- {
253
- "edits": [
254
- {
255
- "linkType": "test-link-type",
256
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
257
- "objectType": "test-object-type",
258
- "primaryKey": "test-primary-key",
259
- "type": "addLink",
260
- },
261
- ],
262
- }
263
- `);
264
- clearTimeoutSpy.mockRestore();
265
- });
266
- it("ensures all requests complete when multiple edits are queued", async () => {
267
- maybeDeferServer = pDefer();
268
- const firstEdit = editRequestManager.postEdit(addLinkEdit);
269
- await new Promise(resolve => setTimeout(resolve, 0));
270
- const secondEdit = editRequestManager.postEdit(addObjectEdit);
271
- await new Promise(resolve => setTimeout(resolve, 0));
272
- const thirdEdit = editRequestManager.postEdit(addLinkEdit);
273
- const flushPromise = editRequestManager.flushPendingEdits();
274
- maybeDeferServer.resolve();
275
- await Promise.all([firstEdit, secondEdit, thirdEdit, flushPromise]);
276
- expect(mockedRequestHandler).toHaveBeenCalledTimes(2);
277
- expect(await mockedRequestHandler.mock.calls[0][0].request.json()).toMatchInlineSnapshot(`
278
- {
279
- "edits": [
280
- {
281
- "linkType": "test-link-type",
282
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
283
- "objectType": "test-object-type",
284
- "primaryKey": "test-primary-key",
285
- "type": "addLink",
286
- },
287
- ],
288
- }
289
- `);
290
- expect(await mockedRequestHandler.mock.calls[1][0].request.json()).toMatchInlineSnapshot(`
291
- {
292
- "edits": [
293
- {
294
- "linkType": "test-link-type",
295
- "linkedObjectPrimaryKey": "test-linked-object-primary-key",
296
- "objectType": "test-object-type",
297
- "primaryKey": "test-primary-key",
298
- "type": "addLink",
299
- },
300
- {
301
- "objectType": "test-object-type",
302
- "properties": {},
303
- "type": "addObject",
304
- },
305
- ],
306
- }
307
- `);
308
- });
309
- });
310
- });
311
- //# sourceMappingURL=EditRequestManager.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EditRequestManager.test.js","names":["LegacyFauxFoundry","MockOntologiesV2","startNodeApiServer","pDefer","beforeAll","beforeEach","describe","expect","it","vi","createWriteableClient","EditRequestManager","client","apiServer","baseUrl","maybeDeferServer","mockedRequestHandler","editRequestManager","testSetup","bind","fauxFoundry","fn","promise","status","body","use","OntologyTransactions","postEdits","close","restoreAllMocks","addLinkEdit","type","primaryKey","linkedObjectPrimaryKey","linkType","objectType","addObjectEdit","properties","postEdit","toHaveBeenCalledTimes","mock","calls","request","json","toMatchInlineSnapshot","Promise","resolve","setTimeout","secondPromise","flushPendingEdits","firstEdit","secondEdit","flushPromise","all","not","toHaveBeenCalled","clearTimeoutSpy","spyOn","global","mockRestore","thirdEdit"],"sources":["EditRequestManager.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { TransactionEdit } from \"@osdk/foundry.ontologies\";\nimport type { SetupServer } from \"@osdk/shared.test\";\nimport {\n LegacyFauxFoundry,\n MockOntologiesV2,\n startNodeApiServer,\n} from \"@osdk/shared.test\";\nimport type { DeferredPromise } from \"p-defer\";\nimport pDefer from \"p-defer\";\nimport type { Mock } from \"vitest\";\nimport { beforeAll, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { createWriteableClient } from \"./createWriteableClient.js\";\nimport { EditRequestManager } from \"./EditRequestManager.js\";\nimport type { WriteableClient } from \"./WriteableClient.js\";\n\ndescribe(\"EditRequestManager\", () => {\n let client: WriteableClient<any>;\n let apiServer: SetupServer;\n let baseUrl: string;\n let maybeDeferServer: DeferredPromise<void> | undefined;\n let mockedRequestHandler: Mock<\n Parameters<typeof MockOntologiesV2.OntologyTransactions.postEdits>[1]\n >;\n let editRequestManager: EditRequestManager;\n\n beforeAll(() => {\n const testSetup = startNodeApiServer(\n new LegacyFauxFoundry(),\n createWriteableClient.bind(null, \"transaction\"),\n );\n ({ client, apiServer } = testSetup);\n baseUrl = testSetup.fauxFoundry.baseUrl;\n\n mockedRequestHandler = vi.fn<\n Parameters<typeof MockOntologiesV2.OntologyTransactions.postEdits>[1]\n >(async () => {\n if (maybeDeferServer) {\n await maybeDeferServer.promise;\n }\n return {\n status: 200,\n body: {},\n };\n });\n apiServer.use(\n MockOntologiesV2.OntologyTransactions.postEdits(\n baseUrl,\n mockedRequestHandler,\n ),\n );\n\n return () => {\n apiServer.close();\n };\n });\n\n beforeEach(() => {\n editRequestManager = new EditRequestManager(client);\n vi.restoreAllMocks();\n });\n\n const addLinkEdit: TransactionEdit = {\n type: \"addLink\",\n primaryKey: \"test-primary-key\",\n linkedObjectPrimaryKey: \"test-linked-object-primary-key\",\n linkType: \"test-link-type\",\n objectType: \"test-object-type\",\n };\n\n const addObjectEdit: TransactionEdit = {\n type: \"addObject\",\n objectType: \"test-object-type\",\n properties: {},\n };\n\n it(\"will stage single edits in a row\", async () => {\n await editRequestManager.postEdit(addLinkEdit);\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(1);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(\n `\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n ],\n }\n `,\n );\n\n await editRequestManager.postEdit(addObjectEdit);\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(2);\n expect(await mockedRequestHandler.mock.calls[1][0].request.json())\n .toMatchInlineSnapshot(\n `\n {\n \"edits\": [\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n ],\n }\n `,\n );\n });\n\n it(\"stages multiple edits from the same tick in one request in order\", async () => {\n void editRequestManager.postEdit(addLinkEdit);\n void editRequestManager.postEdit(addObjectEdit);\n await editRequestManager.postEdit(addObjectEdit);\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(1);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(\n `\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n ],\n }\n `,\n );\n\n await editRequestManager.postEdit(addLinkEdit);\n expect(mockedRequestHandler).toHaveBeenCalledTimes(2);\n expect(await mockedRequestHandler.mock.calls[1][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n ],\n }\n `);\n });\n\n it(\"handles edits posted while a request is in flight\", async () => {\n maybeDeferServer = pDefer();\n void editRequestManager.postEdit(\n addLinkEdit,\n );\n await new Promise(resolve => setTimeout(resolve, 0)); // Ensure the initial request is in flight\n const secondPromise: Promise<void> = editRequestManager.postEdit(\n addObjectEdit,\n );\n void editRequestManager.postEdit(addObjectEdit);\n maybeDeferServer.resolve();\n\n await secondPromise; // Awaiting the second edit should ensure the first resolves first and should also resolve the third since it was dispatched in the same tick\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(2);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(\n `\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n ],\n }\n `,\n );\n expect(await mockedRequestHandler.mock.calls[1][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n ],\n }\n `);\n });\n\n describe(\"flushPendingEdits\", () => {\n it(\"immediately dispatches pending edits without timeout\", async () => {\n void editRequestManager.postEdit(addLinkEdit);\n void editRequestManager.postEdit(addObjectEdit);\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(0);\n\n await editRequestManager.flushPendingEdits();\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(1);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n ],\n }\n `);\n });\n\n it(\"waits for in-flight and queued requests to complete\", async () => {\n maybeDeferServer = pDefer();\n const firstEdit = editRequestManager.postEdit(addLinkEdit);\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const secondEdit = editRequestManager.postEdit(addObjectEdit);\n\n const flushPromise = editRequestManager.flushPendingEdits();\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(1);\n\n maybeDeferServer.resolve();\n await Promise.all([firstEdit, secondEdit, flushPromise]);\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(2);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n ],\n }\n `);\n expect(await mockedRequestHandler.mock.calls[1][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n ],\n }\n `);\n });\n\n it(\"does nothing when there are no pending edits\", async () => {\n await editRequestManager.flushPendingEdits();\n\n expect(mockedRequestHandler).not.toHaveBeenCalled();\n });\n\n it(\"cancels timeout and immediately dispatches edits\", async () => {\n const clearTimeoutSpy = vi.spyOn(global, \"clearTimeout\");\n\n void editRequestManager.postEdit(addLinkEdit);\n\n await editRequestManager.flushPendingEdits();\n\n expect(clearTimeoutSpy).toHaveBeenCalled();\n expect(mockedRequestHandler).toHaveBeenCalledTimes(1);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n ],\n }\n `);\n\n clearTimeoutSpy.mockRestore();\n });\n\n it(\"ensures all requests complete when multiple edits are queued\", async () => {\n maybeDeferServer = pDefer();\n const firstEdit = editRequestManager.postEdit(addLinkEdit);\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const secondEdit = editRequestManager.postEdit(addObjectEdit);\n await new Promise(resolve => setTimeout(resolve, 0));\n\n const thirdEdit = editRequestManager.postEdit(addLinkEdit);\n\n const flushPromise = editRequestManager.flushPendingEdits();\n\n maybeDeferServer.resolve();\n await Promise.all([firstEdit, secondEdit, thirdEdit, flushPromise]);\n\n expect(mockedRequestHandler).toHaveBeenCalledTimes(2);\n expect(await mockedRequestHandler.mock.calls[0][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n ],\n }\n `);\n expect(await mockedRequestHandler.mock.calls[1][0].request.json())\n .toMatchInlineSnapshot(`\n {\n \"edits\": [\n {\n \"linkType\": \"test-link-type\",\n \"linkedObjectPrimaryKey\": \"test-linked-object-primary-key\",\n \"objectType\": \"test-object-type\",\n \"primaryKey\": \"test-primary-key\",\n \"type\": \"addLink\",\n },\n {\n \"objectType\": \"test-object-type\",\n \"properties\": {},\n \"type\": \"addObject\",\n },\n ],\n }\n `);\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SACEA,iBAAiB,EACjBC,gBAAgB,EAChBC,kBAAkB,QACb,mBAAmB;AAE1B,OAAOC,MAAM,MAAM,SAAS;AAE5B,SAASC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACxE,SAASC,qBAAqB,QAAQ,4BAA4B;AAClE,SAASC,kBAAkB,QAAQ,yBAAyB;AAG5DL,QAAQ,CAAC,oBAAoB,EAAE,MAAM;EACnC,IAAIM,MAA4B;EAChC,IAAIC,SAAsB;EAC1B,IAAIC,OAAe;EACnB,IAAIC,gBAAmD;EACvD,IAAIC,oBAEH;EACD,IAAIC,kBAAsC;EAE1Cb,SAAS,CAAC,MAAM;IACd,MAAMc,SAAS,GAAGhB,kBAAkB,CAClC,IAAIF,iBAAiB,CAAC,CAAC,EACvBU,qBAAqB,CAACS,IAAI,CAAC,IAAI,EAAE,aAAa,CAChD,CAAC;IACD,CAAC;MAAEP,MAAM;MAAEC;IAAU,CAAC,GAAGK,SAAS;IAClCJ,OAAO,GAAGI,SAAS,CAACE,WAAW,CAACN,OAAO;IAEvCE,oBAAoB,GAAGP,EAAE,CAACY,EAAE,CAE1B,YAAY;MACZ,IAAIN,gBAAgB,EAAE;QACpB,MAAMA,gBAAgB,CAACO,OAAO;MAChC;MACA,OAAO;QACLC,MAAM,EAAE,GAAG;QACXC,IAAI,EAAE,CAAC;MACT,CAAC;IACH,CAAC,CAAC;IACFX,SAAS,CAACY,GAAG,CACXxB,gB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kB,CAACqB,QAAQ,CAACF,aAAa,CAAC;MAC7D,MAAM,IAAIS,OAAO,CAACC,OAAO,IAAIC,UAAU,CAACD,OAAO,EAAE,CAAC,CAAC,CAAC;MAEpD,MAAMc,SAAS,GAAG3C,kBAAkB,CAACqB,QAAQ,CAACR,WAAW,CAAC;MAE1D,MAAMsB,YAAY,GAAGnC,kBAAkB,CAACgC,iBAAiB,CAAC,CAAC;MAE3DlC,gBAAgB,CAAC+B,OAAO,CAAC,CAAC;MAC1B,MAAMD,OAAO,CAACQ,GAAG,CAAC,CAACH,SAAS,EAAEC,UAAU,EAAES,SAAS,EAAER,YAAY,CAAC,CAAC;MAEnE7C,MAAM,CAACS,oBAAoB,CAAC,CAACuB,qBAAqB,CAAC,CAAC,CAAC;MACrDhC,MAAM,CAAC,MAAMS,oBAAoB,CAACwB,IAAI,CAACC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAC/DC,qBAAqB,CAAC;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,CAAC;MACJrC,MAAM,CAAC,MAAMS,oBAAoB,CAACwB,IAAI,CAACC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAC/DC,qBAAqB,CAAC;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,CAAC;IACN,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- {"mappings":"","names":[],"sources":["../../../src/edits/createEditBatch.test.ts"],"version":3,"file":"createEditBatch.test.d.ts"}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- {"mappings":"","names":[],"sources":["../../../src/transactions/EditRequestManager.test.ts"],"version":3,"file":"EditRequestManager.test.d.ts"}