@causa/runtime-google 0.40.0 → 1.0.0-rc.1

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 (71) hide show
  1. package/README.md +7 -14
  2. package/dist/app-check/testing.d.ts +7 -3
  3. package/dist/app-check/testing.js +9 -6
  4. package/dist/firebase/testing.d.ts +7 -4
  5. package/dist/firebase/testing.js +12 -7
  6. package/dist/firestore/testing.d.ts +32 -17
  7. package/dist/firestore/testing.js +45 -29
  8. package/dist/identity-platform/testing.d.ts +21 -6
  9. package/dist/identity-platform/testing.js +34 -9
  10. package/dist/pubsub/publisher.module.d.ts +1 -1
  11. package/dist/pubsub/{testing/fixture.d.ts → testing.d.ts} +64 -48
  12. package/dist/pubsub/{testing/fixture.js → testing.js} +106 -73
  13. package/dist/spanner/column.decorator.d.ts +1 -11
  14. package/dist/spanner/column.decorator.js +2 -7
  15. package/dist/spanner/conversion.d.ts +5 -18
  16. package/dist/spanner/conversion.js +45 -125
  17. package/dist/spanner/entity-manager.d.ts +19 -23
  18. package/dist/spanner/entity-manager.js +26 -60
  19. package/dist/spanner/table-cache.js +0 -3
  20. package/dist/spanner/testing.d.ts +37 -18
  21. package/dist/spanner/testing.js +75 -10
  22. package/dist/spanner/types.d.ts +0 -6
  23. package/dist/testing.d.ts +36 -2
  24. package/dist/testing.js +33 -2
  25. package/dist/transaction/firestore-pubsub/index.d.ts +3 -2
  26. package/dist/transaction/firestore-pubsub/index.js +2 -1
  27. package/dist/transaction/firestore-pubsub/nestjs-collection-resolver.d.ts +1 -1
  28. package/dist/transaction/firestore-pubsub/nestjs-collection-resolver.js +0 -1
  29. package/dist/transaction/firestore-pubsub/readonly-state-transaction.d.ts +37 -0
  30. package/dist/transaction/firestore-pubsub/readonly-state-transaction.js +46 -0
  31. package/dist/transaction/firestore-pubsub/runner.d.ts +6 -4
  32. package/dist/transaction/firestore-pubsub/runner.js +16 -7
  33. package/dist/transaction/firestore-pubsub/state-transaction.d.ts +11 -49
  34. package/dist/transaction/firestore-pubsub/state-transaction.js +19 -42
  35. package/dist/transaction/firestore-pubsub/transaction.d.ts +15 -3
  36. package/dist/transaction/firestore-pubsub/transaction.js +21 -3
  37. package/dist/transaction/firestore-pubsub/types.d.ts +36 -0
  38. package/dist/transaction/firestore-pubsub/types.js +1 -0
  39. package/dist/transaction/index.d.ts +0 -3
  40. package/dist/transaction/index.js +0 -3
  41. package/dist/transaction/spanner-outbox/index.d.ts +3 -1
  42. package/dist/transaction/spanner-outbox/index.js +3 -0
  43. package/dist/transaction/spanner-outbox/readonly-transaction.d.ts +22 -0
  44. package/dist/transaction/spanner-outbox/readonly-transaction.js +25 -0
  45. package/dist/transaction/spanner-outbox/runner.d.ts +7 -18
  46. package/dist/transaction/spanner-outbox/runner.js +13 -6
  47. package/dist/transaction/{spanner-utils.js → spanner-outbox/spanner-utils.js} +1 -1
  48. package/dist/transaction/spanner-outbox/state-transaction.d.ts +20 -0
  49. package/dist/transaction/spanner-outbox/state-transaction.js +34 -0
  50. package/dist/transaction/spanner-outbox/transaction.d.ts +28 -0
  51. package/dist/transaction/spanner-outbox/transaction.js +38 -0
  52. package/package.json +24 -21
  53. package/dist/pubsub/testing/index.d.ts +0 -4
  54. package/dist/pubsub/testing/index.js +0 -2
  55. package/dist/pubsub/testing/requester.d.ts +0 -50
  56. package/dist/pubsub/testing/requester.js +0 -53
  57. package/dist/testing/google-app-fixture.d.ts +0 -191
  58. package/dist/testing/google-app-fixture.js +0 -200
  59. package/dist/testing/index.d.ts +0 -1
  60. package/dist/testing/index.js +0 -1
  61. package/dist/transaction/spanner-pubsub/index.d.ts +0 -2
  62. package/dist/transaction/spanner-pubsub/index.js +0 -2
  63. package/dist/transaction/spanner-pubsub/module.d.ts +0 -14
  64. package/dist/transaction/spanner-pubsub/module.js +0 -21
  65. package/dist/transaction/spanner-pubsub/runner.d.ts +0 -23
  66. package/dist/transaction/spanner-pubsub/runner.js +0 -69
  67. package/dist/transaction/spanner-state-transaction.d.ts +0 -20
  68. package/dist/transaction/spanner-state-transaction.js +0 -35
  69. package/dist/transaction/spanner-transaction.d.ts +0 -16
  70. package/dist/transaction/spanner-transaction.js +0 -20
  71. /package/dist/transaction/{spanner-utils.d.ts → spanner-outbox/spanner-utils.d.ts} +0 -0
@@ -1,21 +0,0 @@
1
- import { SpannerPubSubTransactionRunner } from './runner.js';
2
- /**
3
- * The module exposing the {@link SpannerPubSubTransactionRunner}.
4
- * This modules assumes that the `SpannerModule` and `PubSubPublisherModule` are available.
5
- */
6
- export class SpannerPubSubTransactionModule {
7
- /**
8
- * Create a global module that provides the {@link SpannerPubSubTransactionRunner}.
9
- * This modules assumes that the `SpannerModule` and `PubSubPublisherModule` are available.
10
- *
11
- * @returns The module.
12
- */
13
- static forRoot() {
14
- return {
15
- module: SpannerPubSubTransactionModule,
16
- global: true,
17
- providers: [SpannerPubSubTransactionRunner],
18
- exports: [SpannerPubSubTransactionRunner],
19
- };
20
- }
21
- }
@@ -1,23 +0,0 @@
1
- import { TransactionRunner } from '@causa/runtime';
2
- import { Logger } from '@causa/runtime/nestjs';
3
- import { PubSubPublisher } from '../../pubsub/index.js';
4
- import { SpannerEntityManager } from '../../spanner/index.js';
5
- import { SpannerTransaction } from '../spanner-transaction.js';
6
- /**
7
- * A {@link TransactionRunner} that uses Spanner for state and Pub/Sub for events.
8
- * A Spanner transaction is used as the main transaction. If it succeeds, events are published to Pub/Sub outside of it.
9
- */
10
- export declare class SpannerPubSubTransactionRunner extends TransactionRunner<SpannerTransaction> {
11
- readonly entityManager: SpannerEntityManager;
12
- readonly publisher: PubSubPublisher;
13
- private readonly logger;
14
- /**
15
- * Creates a new {@link SpannerPubSubTransactionRunner}.
16
- *
17
- * @param entityManager The {@link SpannerEntityManager} to use for the transaction.
18
- * @param publisher The {@link PubSubPublisher} to use for the transaction.
19
- * @param logger The {@link Logger} to use.
20
- */
21
- constructor(entityManager: SpannerEntityManager, publisher: PubSubPublisher, logger: Logger);
22
- run<T>(runFn: (transaction: SpannerTransaction) => Promise<T>): Promise<[T]>;
23
- }
@@ -1,69 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var SpannerPubSubTransactionRunner_1;
11
- import { BufferEventTransaction, TransactionRunner } from '@causa/runtime';
12
- import { Logger } from '@causa/runtime/nestjs';
13
- import { Injectable } from '@nestjs/common';
14
- import { PubSubPublisher } from '../../pubsub/index.js';
15
- import { SpannerEntityManager } from '../../spanner/index.js';
16
- import { SpannerStateTransaction } from '../spanner-state-transaction.js';
17
- import { SpannerTransaction } from '../spanner-transaction.js';
18
- import { throwRetryableInTransactionIfNeeded } from '../spanner-utils.js';
19
- /**
20
- * A {@link TransactionRunner} that uses Spanner for state and Pub/Sub for events.
21
- * A Spanner transaction is used as the main transaction. If it succeeds, events are published to Pub/Sub outside of it.
22
- */
23
- let SpannerPubSubTransactionRunner = SpannerPubSubTransactionRunner_1 = class SpannerPubSubTransactionRunner extends TransactionRunner {
24
- entityManager;
25
- publisher;
26
- logger;
27
- /**
28
- * Creates a new {@link SpannerPubSubTransactionRunner}.
29
- *
30
- * @param entityManager The {@link SpannerEntityManager} to use for the transaction.
31
- * @param publisher The {@link PubSubPublisher} to use for the transaction.
32
- * @param logger The {@link Logger} to use.
33
- */
34
- constructor(entityManager, publisher, logger) {
35
- super();
36
- this.entityManager = entityManager;
37
- this.publisher = publisher;
38
- this.logger = logger;
39
- this.logger.setContext(SpannerPubSubTransactionRunner_1.name);
40
- }
41
- async run(runFn) {
42
- this.logger.info('Creating a Spanner Pub/Sub transaction.');
43
- const { result, eventTransaction } = await this.entityManager.transaction(async (dbTransaction) => {
44
- const stateTransaction = new SpannerStateTransaction(this.entityManager, dbTransaction);
45
- // This must be inside the Spanner transaction because staged messages should be cleared when the transaction is retried.
46
- const eventTransaction = new BufferEventTransaction(this.publisher);
47
- const transaction = new SpannerTransaction(stateTransaction, eventTransaction);
48
- try {
49
- const result = await runFn(transaction);
50
- this.logger.info('Committing the Spanner transaction.');
51
- return { result, eventTransaction };
52
- }
53
- catch (error) {
54
- await throwRetryableInTransactionIfNeeded(error);
55
- throw error;
56
- }
57
- });
58
- this.logger.info('Publishing Pub/Sub events.');
59
- await eventTransaction.commit();
60
- return [result];
61
- }
62
- };
63
- SpannerPubSubTransactionRunner = SpannerPubSubTransactionRunner_1 = __decorate([
64
- Injectable(),
65
- __metadata("design:paramtypes", [SpannerEntityManager,
66
- PubSubPublisher,
67
- Logger])
68
- ], SpannerPubSubTransactionRunner);
69
- export { SpannerPubSubTransactionRunner };
@@ -1,20 +0,0 @@
1
- import type { FindReplaceStateTransaction } from '@causa/runtime';
2
- import type { Type } from '@nestjs/common';
3
- import { SpannerEntityManager, type SpannerReadWriteTransaction } from '../spanner/index.js';
4
- /**
5
- * A {@link FindReplaceStateTransaction} that uses Spanner for state storage.
6
- */
7
- export declare class SpannerStateTransaction implements FindReplaceStateTransaction {
8
- readonly entityManager: SpannerEntityManager;
9
- readonly transaction: SpannerReadWriteTransaction;
10
- /**
11
- * Creates a new {@link SpannerStateTransaction}.
12
- *
13
- * @param entityManager The {@link SpannerEntityManager} to use to access entities in the state.
14
- * @param transaction The {@link SpannerReadWriteTransaction} to use for the transaction.
15
- */
16
- constructor(entityManager: SpannerEntityManager, transaction: SpannerReadWriteTransaction);
17
- replace<T extends object>(entity: T): Promise<void>;
18
- deleteWithSameKeyAs<T extends object>(type: Type<T>, key: Partial<T>): Promise<void>;
19
- findOneWithSameKeyAs<T extends object>(type: Type<T>, entity: Partial<T>): Promise<T | undefined>;
20
- }
@@ -1,35 +0,0 @@
1
- import { SpannerEntityManager, } from '../spanner/index.js';
2
- /**
3
- * A {@link FindReplaceStateTransaction} that uses Spanner for state storage.
4
- */
5
- export class SpannerStateTransaction {
6
- entityManager;
7
- transaction;
8
- /**
9
- * Creates a new {@link SpannerStateTransaction}.
10
- *
11
- * @param entityManager The {@link SpannerEntityManager} to use to access entities in the state.
12
- * @param transaction The {@link SpannerReadWriteTransaction} to use for the transaction.
13
- */
14
- constructor(entityManager, transaction) {
15
- this.entityManager = entityManager;
16
- this.transaction = transaction;
17
- }
18
- async replace(entity) {
19
- await this.entityManager.replace(entity, { transaction: this.transaction });
20
- }
21
- async deleteWithSameKeyAs(type, key) {
22
- const primaryKey = this.entityManager.getPrimaryKey(key, type);
23
- await this.entityManager.delete(type, primaryKey, {
24
- transaction: this.transaction,
25
- includeSoftDeletes: true,
26
- });
27
- }
28
- async findOneWithSameKeyAs(type, entity) {
29
- const primaryKey = this.entityManager.getPrimaryKey(entity, type);
30
- return await this.entityManager.findOneByKey(type, primaryKey, {
31
- transaction: this.transaction,
32
- includeSoftDeletes: true,
33
- });
34
- }
35
- }
@@ -1,16 +0,0 @@
1
- import { type EventTransaction, Transaction } from '@causa/runtime';
2
- import { SpannerEntityManager, type SpannerReadWriteTransaction } from '../spanner/index.js';
3
- import { SpannerStateTransaction } from './spanner-state-transaction.js';
4
- /**
5
- * A {@link Transaction} that uses Spanner for state storage, and any available {@link EventTransaction} implementation.
6
- */
7
- export declare class SpannerTransaction<ET extends EventTransaction = EventTransaction> extends Transaction<SpannerStateTransaction, ET> {
8
- /**
9
- * The underlying {@link SpannerTransaction} used by the state transaction.
10
- */
11
- get spannerTransaction(): SpannerReadWriteTransaction;
12
- /**
13
- * The underlying {@link SpannerEntityManager} used by the state transaction.
14
- */
15
- get entityManager(): SpannerEntityManager;
16
- }
@@ -1,20 +0,0 @@
1
- import { Transaction } from '@causa/runtime';
2
- import { SpannerEntityManager, } from '../spanner/index.js';
3
- import { SpannerStateTransaction } from './spanner-state-transaction.js';
4
- /**
5
- * A {@link Transaction} that uses Spanner for state storage, and any available {@link EventTransaction} implementation.
6
- */
7
- export class SpannerTransaction extends Transaction {
8
- /**
9
- * The underlying {@link SpannerTransaction} used by the state transaction.
10
- */
11
- get spannerTransaction() {
12
- return this.stateTransaction.transaction;
13
- }
14
- /**
15
- * The underlying {@link SpannerEntityManager} used by the state transaction.
16
- */
17
- get entityManager() {
18
- return this.stateTransaction.entityManager;
19
- }
20
- }