@dbos-inc/postgres-datasource 3.0.11-preview.gc9233b8190 → 3.0.16-preview
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/dist/index.d.ts +12 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -42
- package/dist/index.js.map +1 -1
- package/index.ts +71 -53
- package/package.json +6 -5
- package/tests/config.test.ts +1 -1
- package/tests/datasource.test.ts +62 -24
- package/dist/tsconfig.tsbuildinfo +0 -1
package/tests/datasource.test.ts
CHANGED
|
@@ -43,14 +43,20 @@ describe('PostgresDataSource', () => {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
await PostgresDataSource.
|
|
46
|
+
await PostgresDataSource.initializeDBOSSchema(config);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterAll(async () => {
|
|
50
|
+
await userDB.end();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
beforeEach(async () => {
|
|
47
54
|
DBOS.setConfig({ name: 'pg-ds-test' });
|
|
48
55
|
await DBOS.launch();
|
|
49
56
|
});
|
|
50
57
|
|
|
51
|
-
|
|
58
|
+
afterEach(async () => {
|
|
52
59
|
await DBOS.shutdown();
|
|
53
|
-
await userDB.end();
|
|
54
60
|
});
|
|
55
61
|
|
|
56
62
|
test('insert dataSource.register function', async () => {
|
|
@@ -59,7 +65,7 @@ describe('PostgresDataSource', () => {
|
|
|
59
65
|
await userDB.query('DELETE FROM greetings WHERE name = $1', [user]);
|
|
60
66
|
const workflowID = randomUUID();
|
|
61
67
|
|
|
62
|
-
await expect(DBOS.withNextWorkflowID(workflowID, () =>
|
|
68
|
+
await expect(DBOS.withNextWorkflowID(workflowID, () => regInsertWorkflowReg(user))).resolves.toMatchObject({
|
|
63
69
|
user,
|
|
64
70
|
greet_count: 1,
|
|
65
71
|
});
|
|
@@ -81,10 +87,10 @@ describe('PostgresDataSource', () => {
|
|
|
81
87
|
await userDB.query('DELETE FROM greetings WHERE name = $1', [user]);
|
|
82
88
|
const workflowID = randomUUID();
|
|
83
89
|
|
|
84
|
-
const result = await DBOS.withNextWorkflowID(workflowID, () =>
|
|
90
|
+
const result = await DBOS.withNextWorkflowID(workflowID, () => regInsertWorkflowReg(user));
|
|
85
91
|
expect(result).toMatchObject({ user, greet_count: 1 });
|
|
86
92
|
|
|
87
|
-
await expect(DBOS.withNextWorkflowID(workflowID, () =>
|
|
93
|
+
await expect(DBOS.withNextWorkflowID(workflowID, () => regInsertWorkflowReg(user))).resolves.toMatchObject(result);
|
|
88
94
|
});
|
|
89
95
|
|
|
90
96
|
test('insert dataSource.runAsTx function', async () => {
|
|
@@ -93,7 +99,7 @@ describe('PostgresDataSource', () => {
|
|
|
93
99
|
await userDB.query('DELETE FROM greetings WHERE name = $1', [user]);
|
|
94
100
|
const workflowID = randomUUID();
|
|
95
101
|
|
|
96
|
-
await expect(DBOS.withNextWorkflowID(workflowID, () =>
|
|
102
|
+
await expect(DBOS.withNextWorkflowID(workflowID, () => regInsertWorkflowRunTx(user))).resolves.toMatchObject({
|
|
97
103
|
user,
|
|
98
104
|
greet_count: 1,
|
|
99
105
|
});
|
|
@@ -115,10 +121,10 @@ describe('PostgresDataSource', () => {
|
|
|
115
121
|
await userDB.query('DELETE FROM greetings WHERE name = $1', [user]);
|
|
116
122
|
const workflowID = randomUUID();
|
|
117
123
|
|
|
118
|
-
const result = await DBOS.withNextWorkflowID(workflowID, () =>
|
|
124
|
+
const result = await DBOS.withNextWorkflowID(workflowID, () => regInsertWorkflowRunTx(user));
|
|
119
125
|
expect(result).toMatchObject({ user, greet_count: 1 });
|
|
120
126
|
|
|
121
|
-
await expect(DBOS.withNextWorkflowID(workflowID, () =>
|
|
127
|
+
await expect(DBOS.withNextWorkflowID(workflowID, () => regInsertWorkflowRunTx(user))).resolves.toMatchObject(
|
|
122
128
|
result,
|
|
123
129
|
);
|
|
124
130
|
});
|
|
@@ -281,6 +287,40 @@ describe('PostgresDataSource', () => {
|
|
|
281
287
|
{ user, greet_count: 1 },
|
|
282
288
|
]);
|
|
283
289
|
});
|
|
290
|
+
|
|
291
|
+
test('invoke-reg-tx-fun-outside-wf', async () => {
|
|
292
|
+
const user = 'outsideWfUser' + Date.now();
|
|
293
|
+
const result = await regInsertFunction(user);
|
|
294
|
+
expect(result).toMatchObject({ user, greet_count: 1 });
|
|
295
|
+
|
|
296
|
+
const txResults = await userDB.query('SELECT * FROM dbos.transaction_completion WHERE output LIKE $1', [
|
|
297
|
+
`%${user}%`,
|
|
298
|
+
]);
|
|
299
|
+
expect(txResults.rows.length).toBe(0);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('invoke-reg-tx-static-method-outside-wf', async () => {
|
|
303
|
+
const user = 'outsideWfUser' + Date.now();
|
|
304
|
+
const result = await StaticClass.insertFunction(user);
|
|
305
|
+
expect(result).toMatchObject({ user, greet_count: 1 });
|
|
306
|
+
|
|
307
|
+
const txResults = await userDB.query('SELECT * FROM dbos.transaction_completion WHERE output LIKE $1', [
|
|
308
|
+
`%${user}%`,
|
|
309
|
+
]);
|
|
310
|
+
expect(txResults.rows.length).toBe(0);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('invoke-reg-tx-inst-method-outside-wf', async () => {
|
|
314
|
+
const user = 'outsideWfUser' + Date.now();
|
|
315
|
+
const instance = new InstanceClass();
|
|
316
|
+
const result = await instance.insertFunction(user);
|
|
317
|
+
expect(result).toMatchObject({ user, greet_count: 1 });
|
|
318
|
+
|
|
319
|
+
const txResults = await userDB.query('SELECT * FROM dbos.transaction_completion WHERE output LIKE $1', [
|
|
320
|
+
`%${user}%`,
|
|
321
|
+
]);
|
|
322
|
+
expect(txResults.rows.length).toBe(0);
|
|
323
|
+
});
|
|
284
324
|
});
|
|
285
325
|
|
|
286
326
|
export interface greetings {
|
|
@@ -300,13 +340,12 @@ async function insertFunction(user: string) {
|
|
|
300
340
|
}
|
|
301
341
|
|
|
302
342
|
async function errorFunction(user: string) {
|
|
303
|
-
const
|
|
343
|
+
const _result = await insertFunction(user);
|
|
304
344
|
throw new Error(`test error ${Date.now()}`);
|
|
305
|
-
return result;
|
|
306
345
|
}
|
|
307
346
|
|
|
308
347
|
async function readFunction(user: string) {
|
|
309
|
-
const rows = await
|
|
348
|
+
const rows = await dataSource.client<Pick<greetings, 'greet_count'>[]>`
|
|
310
349
|
SELECT greet_count
|
|
311
350
|
FROM greetings
|
|
312
351
|
WHERE name = ${user}`;
|
|
@@ -314,9 +353,9 @@ async function readFunction(user: string) {
|
|
|
314
353
|
return { user, greet_count: row?.greet_count, now: Date.now() };
|
|
315
354
|
}
|
|
316
355
|
|
|
317
|
-
const regInsertFunction = dataSource.registerTransaction(insertFunction
|
|
318
|
-
const regErrorFunction = dataSource.registerTransaction(errorFunction
|
|
319
|
-
const regReadFunction = dataSource.registerTransaction(readFunction,
|
|
356
|
+
const regInsertFunction = dataSource.registerTransaction(insertFunction);
|
|
357
|
+
const regErrorFunction = dataSource.registerTransaction(errorFunction);
|
|
358
|
+
const regReadFunction = dataSource.registerTransaction(readFunction, { readOnly: true });
|
|
320
359
|
|
|
321
360
|
class StaticClass {
|
|
322
361
|
static async insertFunction(user: string) {
|
|
@@ -328,8 +367,8 @@ class StaticClass {
|
|
|
328
367
|
}
|
|
329
368
|
}
|
|
330
369
|
|
|
331
|
-
StaticClass.insertFunction = dataSource.registerTransaction(StaticClass.insertFunction
|
|
332
|
-
StaticClass.readFunction = dataSource.registerTransaction(StaticClass.readFunction,
|
|
370
|
+
StaticClass.insertFunction = dataSource.registerTransaction(StaticClass.insertFunction);
|
|
371
|
+
StaticClass.readFunction = dataSource.registerTransaction(StaticClass.readFunction, { readOnly: true });
|
|
333
372
|
|
|
334
373
|
class InstanceClass {
|
|
335
374
|
async insertFunction(user: string) {
|
|
@@ -344,12 +383,11 @@ class InstanceClass {
|
|
|
344
383
|
InstanceClass.prototype.insertFunction = dataSource.registerTransaction(
|
|
345
384
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
346
385
|
InstanceClass.prototype.insertFunction,
|
|
347
|
-
'insertFunction',
|
|
348
386
|
);
|
|
349
387
|
InstanceClass.prototype.readFunction = dataSource.registerTransaction(
|
|
350
388
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
351
389
|
InstanceClass.prototype.readFunction,
|
|
352
|
-
|
|
390
|
+
{ readOnly: true },
|
|
353
391
|
);
|
|
354
392
|
|
|
355
393
|
async function insertWorkflowReg(user: string) {
|
|
@@ -357,7 +395,7 @@ async function insertWorkflowReg(user: string) {
|
|
|
357
395
|
}
|
|
358
396
|
|
|
359
397
|
async function insertWorkflowRunTx(user: string) {
|
|
360
|
-
return await dataSource.runTransaction(() => insertFunction(user), 'insertFunction');
|
|
398
|
+
return await dataSource.runTransaction(() => insertFunction(user), { name: 'insertFunction' });
|
|
361
399
|
}
|
|
362
400
|
|
|
363
401
|
async function errorWorkflowReg(user: string) {
|
|
@@ -365,7 +403,7 @@ async function errorWorkflowReg(user: string) {
|
|
|
365
403
|
}
|
|
366
404
|
|
|
367
405
|
async function errorWorkflowRunTx(user: string) {
|
|
368
|
-
return await dataSource.runTransaction(() => errorFunction(user), 'errorFunction');
|
|
406
|
+
return await dataSource.runTransaction(() => errorFunction(user), { name: 'errorFunction' });
|
|
369
407
|
}
|
|
370
408
|
|
|
371
409
|
async function readWorkflowReg(user: string) {
|
|
@@ -373,7 +411,7 @@ async function readWorkflowReg(user: string) {
|
|
|
373
411
|
}
|
|
374
412
|
|
|
375
413
|
async function readWorkflowRunTx(user: string) {
|
|
376
|
-
return await dataSource.runTransaction(() => readFunction(user), 'readFunction',
|
|
414
|
+
return await dataSource.runTransaction(() => readFunction(user), { name: 'readFunction', readOnly: true });
|
|
377
415
|
}
|
|
378
416
|
|
|
379
417
|
async function staticWorkflow(user: string) {
|
|
@@ -389,8 +427,8 @@ async function instanceWorkflow(user: string) {
|
|
|
389
427
|
return [result, readResult];
|
|
390
428
|
}
|
|
391
429
|
|
|
392
|
-
const
|
|
393
|
-
const
|
|
430
|
+
const regInsertWorkflowReg = DBOS.registerWorkflow(insertWorkflowReg, 'insertWorkflowReg');
|
|
431
|
+
const regInsertWorkflowRunTx = DBOS.registerWorkflow(insertWorkflowRunTx, 'insertWorkflowRunTx');
|
|
394
432
|
const regErrorWorkflowReg = DBOS.registerWorkflow(errorWorkflowReg, 'errorWorkflowReg');
|
|
395
433
|
const regErrorWorkflowRunTx = DBOS.registerWorkflow(errorWorkflowRunTx, 'errorWorkflowRunTx');
|
|
396
434
|
const regReadWorkflowReg = DBOS.registerWorkflow(readWorkflowReg, 'readWorkflowReg');
|