@causa/runtime-google 0.39.1 → 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 (73) 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/module.d.ts +14 -2
  5. package/dist/firebase/module.js +45 -16
  6. package/dist/firebase/testing.d.ts +7 -4
  7. package/dist/firebase/testing.js +12 -7
  8. package/dist/firestore/testing.d.ts +32 -17
  9. package/dist/firestore/testing.js +45 -29
  10. package/dist/identity-platform/testing.d.ts +21 -6
  11. package/dist/identity-platform/testing.js +34 -9
  12. package/dist/pubsub/publisher.module.d.ts +1 -1
  13. package/dist/pubsub/{testing/fixture.d.ts → testing.d.ts} +64 -48
  14. package/dist/pubsub/{testing/fixture.js → testing.js} +106 -73
  15. package/dist/spanner/column.decorator.d.ts +1 -11
  16. package/dist/spanner/column.decorator.js +2 -7
  17. package/dist/spanner/conversion.d.ts +5 -18
  18. package/dist/spanner/conversion.js +45 -125
  19. package/dist/spanner/entity-manager.d.ts +19 -23
  20. package/dist/spanner/entity-manager.js +26 -60
  21. package/dist/spanner/table-cache.js +0 -3
  22. package/dist/spanner/testing.d.ts +37 -18
  23. package/dist/spanner/testing.js +75 -10
  24. package/dist/spanner/types.d.ts +0 -6
  25. package/dist/testing.d.ts +36 -2
  26. package/dist/testing.js +33 -2
  27. package/dist/transaction/firestore-pubsub/index.d.ts +3 -2
  28. package/dist/transaction/firestore-pubsub/index.js +2 -1
  29. package/dist/transaction/firestore-pubsub/nestjs-collection-resolver.d.ts +1 -1
  30. package/dist/transaction/firestore-pubsub/nestjs-collection-resolver.js +0 -1
  31. package/dist/transaction/firestore-pubsub/readonly-state-transaction.d.ts +37 -0
  32. package/dist/transaction/firestore-pubsub/readonly-state-transaction.js +46 -0
  33. package/dist/transaction/firestore-pubsub/runner.d.ts +6 -4
  34. package/dist/transaction/firestore-pubsub/runner.js +16 -7
  35. package/dist/transaction/firestore-pubsub/state-transaction.d.ts +11 -49
  36. package/dist/transaction/firestore-pubsub/state-transaction.js +19 -42
  37. package/dist/transaction/firestore-pubsub/transaction.d.ts +15 -3
  38. package/dist/transaction/firestore-pubsub/transaction.js +21 -3
  39. package/dist/transaction/firestore-pubsub/types.d.ts +36 -0
  40. package/dist/transaction/firestore-pubsub/types.js +1 -0
  41. package/dist/transaction/index.d.ts +0 -3
  42. package/dist/transaction/index.js +0 -3
  43. package/dist/transaction/spanner-outbox/index.d.ts +3 -1
  44. package/dist/transaction/spanner-outbox/index.js +3 -0
  45. package/dist/transaction/spanner-outbox/readonly-transaction.d.ts +22 -0
  46. package/dist/transaction/spanner-outbox/readonly-transaction.js +25 -0
  47. package/dist/transaction/spanner-outbox/runner.d.ts +7 -18
  48. package/dist/transaction/spanner-outbox/runner.js +13 -6
  49. package/dist/transaction/{spanner-utils.js → spanner-outbox/spanner-utils.js} +1 -1
  50. package/dist/transaction/spanner-outbox/state-transaction.d.ts +20 -0
  51. package/dist/transaction/spanner-outbox/state-transaction.js +34 -0
  52. package/dist/transaction/spanner-outbox/transaction.d.ts +28 -0
  53. package/dist/transaction/spanner-outbox/transaction.js +38 -0
  54. package/package.json +37 -34
  55. package/dist/pubsub/testing/index.d.ts +0 -4
  56. package/dist/pubsub/testing/index.js +0 -2
  57. package/dist/pubsub/testing/requester.d.ts +0 -50
  58. package/dist/pubsub/testing/requester.js +0 -53
  59. package/dist/testing/google-app-fixture.d.ts +0 -191
  60. package/dist/testing/google-app-fixture.js +0 -200
  61. package/dist/testing/index.d.ts +0 -1
  62. package/dist/testing/index.js +0 -1
  63. package/dist/transaction/spanner-pubsub/index.d.ts +0 -2
  64. package/dist/transaction/spanner-pubsub/index.js +0 -2
  65. package/dist/transaction/spanner-pubsub/module.d.ts +0 -14
  66. package/dist/transaction/spanner-pubsub/module.js +0 -21
  67. package/dist/transaction/spanner-pubsub/runner.d.ts +0 -23
  68. package/dist/transaction/spanner-pubsub/runner.js +0 -69
  69. package/dist/transaction/spanner-state-transaction.d.ts +0 -20
  70. package/dist/transaction/spanner-state-transaction.js +0 -35
  71. package/dist/transaction/spanner-transaction.d.ts +0 -16
  72. package/dist/transaction/spanner-transaction.js +0 -20
  73. /package/dist/transaction/{spanner-utils.d.ts → spanner-outbox/spanner-utils.d.ts} +0 -0
@@ -0,0 +1,36 @@
1
+ import type { Type } from '@nestjs/common';
2
+ import type { CollectionReference } from 'firebase-admin/firestore';
3
+ import type { SoftDeletedFirestoreCollectionMetadata } from './soft-deleted-collection.decorator.js';
4
+ /**
5
+ * The Firestore collections that should be used to create document references for a given document type.
6
+ */
7
+ export type FirestoreCollectionsForDocumentType<T> = {
8
+ /**
9
+ * The regular collection, where documents are stored when they are not deleted.
10
+ */
11
+ readonly activeCollection: CollectionReference<T>;
12
+ /**
13
+ * Configuration about the soft-delete collection, where documents are stored when their `deletedAt` field is not
14
+ * `null`. This can be `null` if the document type does not declare a soft-delete collection.
15
+ */
16
+ readonly softDelete: ({
17
+ /**
18
+ * The collection where soft-deleted documents are stored.
19
+ */
20
+ collection: CollectionReference<T>;
21
+ } & Pick<SoftDeletedFirestoreCollectionMetadata, 'expirationDelay' | 'expirationField'>) | null;
22
+ };
23
+ /**
24
+ * A resolver that returns the Firestore collections for a given document type.
25
+ * This allows using the {@link FirestoreStateTransaction} in various contexts, such as in a NestJS module. It also
26
+ * enables testing with temporary collections.
27
+ */
28
+ export interface FirestoreCollectionResolver {
29
+ /**
30
+ * Returns the Firestore collections for a given document type.
31
+ *
32
+ * @param documentType The type of document.
33
+ * @returns The Firestore collections for the given document type.
34
+ */
35
+ getCollectionsForType<T>(documentType: Type<T>): FirestoreCollectionsForDocumentType<T>;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,2 @@
1
1
  export * from './firestore-pubsub/index.js';
2
2
  export * from './spanner-outbox/index.js';
3
- export * from './spanner-pubsub/index.js';
4
- export { SpannerStateTransaction } from './spanner-state-transaction.js';
5
- export { SpannerTransaction } from './spanner-transaction.js';
@@ -1,5 +1,2 @@
1
1
  export * from './firestore-pubsub/index.js';
2
2
  export * from './spanner-outbox/index.js';
3
- export * from './spanner-pubsub/index.js';
4
- export { SpannerStateTransaction } from './spanner-state-transaction.js';
5
- export { SpannerTransaction } from './spanner-transaction.js';
@@ -1,5 +1,7 @@
1
1
  export { SpannerOutboxEvent } from './event.js';
2
2
  export { SpannerOutboxTransactionModule } from './module.js';
3
+ export * from './readonly-transaction.js';
3
4
  export { SpannerOutboxTransactionRunner } from './runner.js';
4
- export type { SpannerOutboxTransaction, SpannerOutboxTransactionOption, } from './runner.js';
5
5
  export { SpannerOutboxSender } from './sender.js';
6
+ export { SpannerStateTransaction } from './state-transaction.js';
7
+ export * from './transaction.js';
@@ -1,4 +1,7 @@
1
1
  export { SpannerOutboxEvent } from './event.js';
2
2
  export { SpannerOutboxTransactionModule } from './module.js';
3
+ export * from './readonly-transaction.js';
3
4
  export { SpannerOutboxTransactionRunner } from './runner.js';
4
5
  export { SpannerOutboxSender } from './sender.js';
6
+ export { SpannerStateTransaction } from './state-transaction.js';
7
+ export * from './transaction.js';
@@ -0,0 +1,22 @@
1
+ import type { ReadOnlyStateTransaction, ReadOnlyTransactionOption } from '@causa/runtime';
2
+ import type { Type } from '@nestjs/common';
3
+ import { SpannerEntityManager, type SpannerReadOnlyTransaction, type SpannerReadWriteTransaction } from '../../spanner/index.js';
4
+ /**
5
+ * Option for a function that accepts a {@link SpannerReadOnlyStateTransaction}.
6
+ */
7
+ export type SpannerReadOnlyStateTransactionOption = ReadOnlyTransactionOption<SpannerReadOnlyStateTransaction>;
8
+ /**
9
+ * A {@link ReadOnlyStateTransaction} that uses Spanner for state storage.
10
+ */
11
+ export declare class SpannerReadOnlyStateTransaction implements ReadOnlyStateTransaction {
12
+ readonly entityManager: SpannerEntityManager;
13
+ readonly spannerTransaction: SpannerReadWriteTransaction | SpannerReadOnlyTransaction;
14
+ /**
15
+ * Creates a new {@link SpannerReadOnlyStateTransaction}.
16
+ *
17
+ * @param entityManager The {@link SpannerEntityManager} to use to access entities in the state.
18
+ * @param spannerTransaction The {@link SpannerReadWriteTransaction} or {@link SpannerReadOnlyTransaction} to use.
19
+ */
20
+ constructor(entityManager: SpannerEntityManager, spannerTransaction: SpannerReadWriteTransaction | SpannerReadOnlyTransaction);
21
+ get<T extends object>(type: Type<T>, entity: Partial<T>): Promise<T | undefined>;
22
+ }
@@ -0,0 +1,25 @@
1
+ import { SpannerEntityManager, } from '../../spanner/index.js';
2
+ /**
3
+ * A {@link ReadOnlyStateTransaction} that uses Spanner for state storage.
4
+ */
5
+ export class SpannerReadOnlyStateTransaction {
6
+ entityManager;
7
+ spannerTransaction;
8
+ /**
9
+ * Creates a new {@link SpannerReadOnlyStateTransaction}.
10
+ *
11
+ * @param entityManager The {@link SpannerEntityManager} to use to access entities in the state.
12
+ * @param spannerTransaction The {@link SpannerReadWriteTransaction} or {@link SpannerReadOnlyTransaction} to use.
13
+ */
14
+ constructor(entityManager, spannerTransaction) {
15
+ this.entityManager = entityManager;
16
+ this.spannerTransaction = spannerTransaction;
17
+ }
18
+ async get(type, entity) {
19
+ const primaryKey = this.entityManager.getPrimaryKey(entity, type);
20
+ return await this.entityManager.findOneByKey(type, primaryKey, {
21
+ transaction: this.spannerTransaction,
22
+ includeSoftDeletes: true,
23
+ });
24
+ }
25
+ }
@@ -1,28 +1,17 @@
1
- import { OutboxTransactionRunner, type OutboxEvent, type OutboxEventTransaction } from '@causa/runtime';
1
+ import { OutboxTransactionRunner, type OutboxEvent, type OutboxEventTransaction, type ReadWriteTransactionOptions, type TransactionFn } from '@causa/runtime';
2
2
  import { Logger } from '@causa/runtime/nestjs';
3
3
  import type { Type } from '@nestjs/common';
4
4
  import { SpannerEntityManager } from '../../spanner/index.js';
5
- import { SpannerTransaction } from '../spanner-transaction.js';
5
+ import { SpannerReadOnlyStateTransaction } from './readonly-transaction.js';
6
6
  import { SpannerOutboxSender } from './sender.js';
7
+ import { SpannerOutboxTransaction } from './transaction.js';
7
8
  /**
8
- * A {@link SpannerTransaction} that uses an {@link OutboxEventTransaction}.
9
- */
10
- export type SpannerOutboxTransaction = SpannerTransaction<OutboxEventTransaction>;
11
- /**
12
- * Option for a function that accepts a {@link SpannerOutboxTransaction}.
13
- */
14
- export type SpannerOutboxTransactionOption = {
15
- /**
16
- * The transaction to use.
17
- */
18
- readonly transaction?: SpannerOutboxTransaction;
19
- };
20
- /**
21
- * An {@link OutboxTransactionRunner} that uses a {@link SpannerTransaction} to run transactions.
9
+ * An {@link OutboxTransactionRunner} that uses a {@link SpannerOutboxTransaction} to run transactions.
22
10
  * Events are stored in a Spanner table before being published.
23
11
  */
24
- export declare class SpannerOutboxTransactionRunner extends OutboxTransactionRunner<SpannerOutboxTransaction> {
12
+ export declare class SpannerOutboxTransactionRunner extends OutboxTransactionRunner<SpannerOutboxTransaction, SpannerReadOnlyStateTransaction> {
25
13
  readonly entityManager: SpannerEntityManager;
26
14
  constructor(entityManager: SpannerEntityManager, outboxEventType: Type<OutboxEvent>, sender: SpannerOutboxSender, logger: Logger);
27
- protected runStateTransaction<RT>(eventTransactionFactory: () => OutboxEventTransaction, runFn: (transaction: SpannerOutboxTransaction) => Promise<RT>): Promise<RT>;
15
+ protected runReadOnly<RT>(runFn: TransactionFn<SpannerReadOnlyStateTransaction, RT>): Promise<RT>;
16
+ protected runStateTransaction<RT>(eventTransactionFactory: () => OutboxEventTransaction, options: ReadWriteTransactionOptions, runFn: TransactionFn<SpannerOutboxTransaction, RT>): Promise<RT>;
28
17
  }
@@ -1,12 +1,13 @@
1
1
  import { OutboxTransactionRunner, } from '@causa/runtime';
2
2
  import { Logger } from '@causa/runtime/nestjs';
3
3
  import { SpannerEntityManager } from '../../spanner/index.js';
4
- import { SpannerStateTransaction } from '../spanner-state-transaction.js';
5
- import { SpannerTransaction } from '../spanner-transaction.js';
6
- import { throwRetryableInTransactionIfNeeded } from '../spanner-utils.js';
4
+ import { SpannerReadOnlyStateTransaction } from './readonly-transaction.js';
7
5
  import { SpannerOutboxSender } from './sender.js';
6
+ import { throwRetryableInTransactionIfNeeded } from './spanner-utils.js';
7
+ import { SpannerStateTransaction } from './state-transaction.js';
8
+ import { SpannerOutboxTransaction } from './transaction.js';
8
9
  /**
9
- * An {@link OutboxTransactionRunner} that uses a {@link SpannerTransaction} to run transactions.
10
+ * An {@link OutboxTransactionRunner} that uses a {@link SpannerOutboxTransaction} to run transactions.
10
11
  * Events are stored in a Spanner table before being published.
11
12
  */
12
13
  export class SpannerOutboxTransactionRunner extends OutboxTransactionRunner {
@@ -15,11 +16,17 @@ export class SpannerOutboxTransactionRunner extends OutboxTransactionRunner {
15
16
  super(outboxEventType, sender, logger);
16
17
  this.entityManager = entityManager;
17
18
  }
18
- async runStateTransaction(eventTransactionFactory, runFn) {
19
+ async runReadOnly(runFn) {
20
+ return await this.entityManager.snapshot(async (dbTransaction) => {
21
+ const transaction = new SpannerReadOnlyStateTransaction(this.entityManager, dbTransaction);
22
+ return await runFn(transaction);
23
+ });
24
+ }
25
+ async runStateTransaction(eventTransactionFactory, options, runFn) {
19
26
  return await this.entityManager.transaction(async (dbTransaction) => {
20
27
  const stateTransaction = new SpannerStateTransaction(this.entityManager, dbTransaction);
21
28
  const eventTransaction = eventTransactionFactory();
22
- const transaction = new SpannerTransaction(stateTransaction, eventTransaction);
29
+ const transaction = new SpannerOutboxTransaction(stateTransaction, eventTransaction, options.publishOptions);
23
30
  try {
24
31
  return await runFn(transaction);
25
32
  }
@@ -1,6 +1,6 @@
1
1
  import { TransactionOldTimestampError } from '@causa/runtime';
2
2
  import { setTimeout } from 'timers/promises';
3
- import { TemporarySpannerError } from '../spanner/index.js';
3
+ import { TemporarySpannerError } from '../../spanner/index.js';
4
4
  /**
5
5
  * The delay, in milliseconds, over which a timestamp issue is deemed irrecoverable.
6
6
  */
@@ -0,0 +1,20 @@
1
+ import type { StateTransaction } from '@causa/runtime';
2
+ import type { Type } from '@nestjs/common';
3
+ import { SpannerEntityManager, type SpannerReadWriteTransaction } from '../../spanner/index.js';
4
+ import { SpannerReadOnlyStateTransaction } from './readonly-transaction.js';
5
+ /**
6
+ * A {@link StateTransaction} that uses Spanner for state storage.
7
+ */
8
+ export declare class SpannerStateTransaction extends SpannerReadOnlyStateTransaction implements StateTransaction {
9
+ readonly entityManager: SpannerEntityManager;
10
+ readonly spannerTransaction: SpannerReadWriteTransaction;
11
+ /**
12
+ * Creates a new {@link SpannerStateTransaction}.
13
+ *
14
+ * @param entityManager The {@link SpannerEntityManager} to use to access entities in the state.
15
+ * @param spannerTransaction The {@link SpannerReadWriteTransaction} to use for the transaction.
16
+ */
17
+ constructor(entityManager: SpannerEntityManager, spannerTransaction: SpannerReadWriteTransaction);
18
+ set<T extends object>(entity: T): Promise<void>;
19
+ delete<T extends object>(typeOrEntity: Type<T> | T, key?: Partial<T>): Promise<void>;
20
+ }
@@ -0,0 +1,34 @@
1
+ import { SpannerEntityManager, } from '../../spanner/index.js';
2
+ import { SpannerReadOnlyStateTransaction } from './readonly-transaction.js';
3
+ /**
4
+ * A {@link StateTransaction} that uses Spanner for state storage.
5
+ */
6
+ export class SpannerStateTransaction extends SpannerReadOnlyStateTransaction {
7
+ entityManager;
8
+ spannerTransaction;
9
+ /**
10
+ * Creates a new {@link SpannerStateTransaction}.
11
+ *
12
+ * @param entityManager The {@link SpannerEntityManager} to use to access entities in the state.
13
+ * @param spannerTransaction The {@link SpannerReadWriteTransaction} to use for the transaction.
14
+ */
15
+ constructor(entityManager, spannerTransaction) {
16
+ super(entityManager, spannerTransaction);
17
+ this.entityManager = entityManager;
18
+ this.spannerTransaction = spannerTransaction;
19
+ }
20
+ async set(entity) {
21
+ await this.entityManager.replace(entity, {
22
+ transaction: this.spannerTransaction,
23
+ });
24
+ }
25
+ async delete(typeOrEntity, key) {
26
+ const type = (key === undefined ? typeOrEntity.constructor : typeOrEntity);
27
+ key ??= typeOrEntity;
28
+ const primaryKey = this.entityManager.getPrimaryKey(key, type);
29
+ await this.entityManager.delete(type, primaryKey, {
30
+ transaction: this.spannerTransaction,
31
+ includeSoftDeletes: true,
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,28 @@
1
+ import { OutboxEventTransaction, Transaction, type OutboxTransaction, type PublishOptions, type TransactionOption } from '@causa/runtime';
2
+ import type { Type } from '@nestjs/common';
3
+ import { SpannerEntityManager, type SpannerReadWriteTransaction } from '../../spanner/index.js';
4
+ import type { SpannerStateTransaction } from './state-transaction.js';
5
+ /**
6
+ * Option for a function that accepts a {@link SpannerOutboxTransaction}.
7
+ */
8
+ export type SpannerOutboxTransactionOption = TransactionOption<SpannerOutboxTransaction>;
9
+ /**
10
+ * A {@link Transaction} that uses Spanner for state (and outbox) storage, and Pub/Sub for event publishing.
11
+ */
12
+ export declare class SpannerOutboxTransaction extends Transaction implements OutboxTransaction {
13
+ readonly stateTransaction: SpannerStateTransaction;
14
+ readonly eventTransaction: OutboxEventTransaction;
15
+ constructor(stateTransaction: SpannerStateTransaction, eventTransaction: OutboxEventTransaction, publishOptions?: PublishOptions);
16
+ /**
17
+ * The underlying {@link SpannerTransaction} used by the state transaction.
18
+ */
19
+ get spannerTransaction(): SpannerReadWriteTransaction;
20
+ /**
21
+ * The underlying {@link SpannerEntityManager} used by the state transaction.
22
+ */
23
+ get entityManager(): SpannerEntityManager;
24
+ set<T extends object>(entity: T): Promise<void>;
25
+ delete<T extends object>(type: Type<T> | T, key?: Partial<T>): Promise<void>;
26
+ get<T extends object>(type: Type<T>, entity: Partial<T>): Promise<T | undefined>;
27
+ publish(topic: string, event: object, options?: PublishOptions): Promise<void>;
28
+ }
@@ -0,0 +1,38 @@
1
+ import { OutboxEventTransaction, Transaction, } from '@causa/runtime';
2
+ import { SpannerEntityManager, } from '../../spanner/index.js';
3
+ /**
4
+ * A {@link Transaction} that uses Spanner for state (and outbox) storage, and Pub/Sub for event publishing.
5
+ */
6
+ export class SpannerOutboxTransaction extends Transaction {
7
+ stateTransaction;
8
+ eventTransaction;
9
+ constructor(stateTransaction, eventTransaction, publishOptions = {}) {
10
+ super(publishOptions);
11
+ this.stateTransaction = stateTransaction;
12
+ this.eventTransaction = eventTransaction;
13
+ }
14
+ /**
15
+ * The underlying {@link SpannerTransaction} used by the state transaction.
16
+ */
17
+ get spannerTransaction() {
18
+ return this.stateTransaction.spannerTransaction;
19
+ }
20
+ /**
21
+ * The underlying {@link SpannerEntityManager} used by the state transaction.
22
+ */
23
+ get entityManager() {
24
+ return this.stateTransaction.entityManager;
25
+ }
26
+ set(entity) {
27
+ return this.stateTransaction.set(entity);
28
+ }
29
+ delete(type, key) {
30
+ return this.stateTransaction.delete(type, key);
31
+ }
32
+ get(type, entity) {
33
+ return this.stateTransaction.get(type, entity);
34
+ }
35
+ publish(topic, event, options) {
36
+ return this.eventTransaction.publish(topic, event, options);
37
+ }
38
+ }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@causa/runtime-google",
3
- "version": "0.39.1",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "An extension to the Causa runtime SDK (`@causa/runtime`), providing Google-specific features.",
5
- "repository": "github:causa-io/runtime-typescript-google",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/causa-io/runtime-typescript-google.git"
8
+ },
6
9
  "license": "ISC",
7
10
  "type": "module",
8
11
  "engines": {
9
- "node": ">=16"
12
+ "node": ">=20"
10
13
  },
11
14
  "main": "dist/index.js",
12
15
  "types": "dist/index.d.ts",
@@ -29,49 +32,49 @@
29
32
  "test:cov": "npm run test -- --coverage"
30
33
  },
31
34
  "dependencies": {
32
- "@causa/runtime": ">= 0.27.1 < 1.0.0",
33
- "@google-cloud/precise-date": "^4.0.0",
34
- "@google-cloud/pubsub": "^4.10.0",
35
- "@google-cloud/spanner": "^7.18.1",
36
- "@google-cloud/tasks": "^5.5.2",
37
- "@grpc/grpc-js": "^1.12.6",
38
- "@nestjs/common": "^11.0.11",
39
- "@nestjs/config": "^4.0.1",
40
- "@nestjs/core": "^11.0.11",
35
+ "@causa/runtime": ">= 1.0.0-rc",
36
+ "@google-cloud/precise-date": "^5.0.0",
37
+ "@google-cloud/pubsub": "^5.1.0",
38
+ "@google-cloud/spanner": "^8.0.0",
39
+ "@google-cloud/tasks": "^6.1.0",
40
+ "@grpc/grpc-js": "^1.13.4",
41
+ "@nestjs/common": "^11.1.3",
42
+ "@nestjs/config": "^4.0.2",
43
+ "@nestjs/core": "^11.1.3",
41
44
  "@nestjs/passport": "^11.0.5",
42
45
  "@nestjs/terminus": "^11.0.0",
43
46
  "class-transformer": "^0.5.1",
44
- "class-validator": "^0.14.1",
45
- "express": "^5.0.1",
46
- "firebase-admin": "^13.1.0",
47
+ "class-validator": "^0.14.2",
48
+ "express": "^5.1.0",
49
+ "firebase-admin": "^13.4.0",
47
50
  "jsonwebtoken": "^9.0.2",
48
51
  "passport-http-bearer": "^1.0.1",
49
- "pino": "^9.6.0",
52
+ "pino": "^9.7.0",
50
53
  "reflect-metadata": "^0.2.2"
51
54
  },
52
55
  "devDependencies": {
53
- "@nestjs/testing": "^11.0.11",
54
- "@swc/core": "^1.11.7",
55
- "@swc/jest": "^0.2.37",
56
- "@tsconfig/node22": "^22.0.0",
57
- "@types/jest": "^29.5.14",
58
- "@types/jsonwebtoken": "^9.0.9",
59
- "@types/node": "^22.13.9",
56
+ "@nestjs/testing": "^11.1.3",
57
+ "@swc/core": "^1.12.11",
58
+ "@swc/jest": "^0.2.39",
59
+ "@tsconfig/node22": "^22.0.2",
60
+ "@types/jest": "^30.0.0",
61
+ "@types/jsonwebtoken": "^9.0.10",
62
+ "@types/node": "^22.16.2",
60
63
  "@types/passport-http-bearer": "^1.0.41",
61
- "@types/supertest": "^6.0.2",
64
+ "@types/supertest": "^6.0.3",
62
65
  "@types/uuid": "^10.0.0",
63
- "dotenv": "^16.4.7",
64
- "eslint": "^9.21.0",
65
- "eslint-config-prettier": "^10.0.2",
66
- "eslint-plugin-prettier": "^5.2.3",
67
- "jest": "^29.7.0",
68
- "jest-extended": "^4.0.2",
66
+ "dotenv": "^17.1.0",
67
+ "eslint": "^9.30.1",
68
+ "eslint-config-prettier": "^10.1.5",
69
+ "eslint-plugin-prettier": "^5.5.1",
70
+ "jest": "^30.0.4",
71
+ "jest-extended": "^6.0.0",
69
72
  "rimraf": "^6.0.1",
70
- "supertest": "^7.0.0",
71
- "ts-jest": "^29.2.6",
73
+ "supertest": "^7.1.3",
74
+ "ts-jest": "^29.4.0",
72
75
  "ts-node": "^10.9.2",
73
- "typescript": "^5.8.2",
74
- "typescript-eslint": "^8.26.0",
76
+ "typescript": "^5.8.3",
77
+ "typescript-eslint": "^8.36.0",
75
78
  "uuid": "^11.1.0"
76
79
  }
77
80
  }
@@ -1,4 +0,0 @@
1
- export { PubSubFixture } from './fixture.js';
2
- export type { ReceivedPubSubEvent } from './fixture.js';
3
- export { makePubSubRequester } from './requester.js';
4
- export type { EventRequester, EventRequesterOptions } from './requester.js';
@@ -1,2 +0,0 @@
1
- export { PubSubFixture } from './fixture.js';
2
- export { makePubSubRequester } from './requester.js';
@@ -1,50 +0,0 @@
1
- import { type ObjectSerializer } from '@causa/runtime';
2
- import { type INestApplication } from '@nestjs/common';
3
- /**
4
- * Options when making a request to an endpoint handling Pub/Sub events using an {@link EventRequester}.
5
- */
6
- export type EventRequesterOptions = {
7
- /**
8
- * The attributes to add to the Pub/Sub message.
9
- * Using `undefined` values allows removing the attributes set by default.
10
- */
11
- attributes?: Record<string, string | undefined>;
12
- /**
13
- * The expected status code when making the request.
14
- * Default is `200`.
15
- */
16
- expectedStatus?: number;
17
- /**
18
- * The time to set as the publication time of the Pub/Sub message.
19
- */
20
- publishTime?: Date;
21
- };
22
- /**
23
- * A function that makes a query to an endpoint handling Pub/Sub events and tests the response.
24
- */
25
- export type EventRequester = (endpoint: string, event: object, options?: EventRequesterOptions) => Promise<void>;
26
- /**
27
- * Creates an {@link EventRequester} for a NestJS HTTP application handling Pub/Sub messages.
28
- * If the `event` passed to the {@link EventRequester} conforms to the `Event` interface (if it has `producedAt`, `name`
29
- * and / or `id` properties), the default attributes are set in the Pub/Sub message. Default attributes can be
30
- * overridden (or removed by passing `undefined`) using {@link EventRequesterOptions.attributes}.
31
- *
32
- * @param app The NestJS application handling events.
33
- * @param options Options when creating the requester.
34
- * @returns The {@link EventRequester}.
35
- */
36
- export declare function makePubSubRequester(app: INestApplication, options?: {
37
- /**
38
- * The prefix added to all routes handling events.
39
- * Used when constructing the request to the HTTP application.
40
- */
41
- routePrefix?: string;
42
- /**
43
- * The serializer to use to serialize events.
44
- */
45
- serializer?: ObjectSerializer;
46
- /**
47
- * The default expected status code when making a request.
48
- */
49
- expectedStatus?: number;
50
- }): EventRequester;
@@ -1,53 +0,0 @@
1
- import { JsonObjectSerializer } from '@causa/runtime';
2
- import { HttpStatus } from '@nestjs/common';
3
- import supertest from 'supertest';
4
- import * as uuid from 'uuid';
5
- /**
6
- * Creates an {@link EventRequester} for a NestJS HTTP application handling Pub/Sub messages.
7
- * If the `event` passed to the {@link EventRequester} conforms to the `Event` interface (if it has `producedAt`, `name`
8
- * and / or `id` properties), the default attributes are set in the Pub/Sub message. Default attributes can be
9
- * overridden (or removed by passing `undefined`) using {@link EventRequesterOptions.attributes}.
10
- *
11
- * @param app The NestJS application handling events.
12
- * @param options Options when creating the requester.
13
- * @returns The {@link EventRequester}.
14
- */
15
- export function makePubSubRequester(app, options = {}) {
16
- const request = supertest(app.getHttpServer());
17
- const routePrefix = options.routePrefix ?? '';
18
- const serializer = options.serializer ?? new JsonObjectSerializer();
19
- return async (endpoint, event, requestOptions) => {
20
- const messageId = uuid.v4();
21
- const publishTime = (requestOptions?.publishTime ?? new Date()).toISOString();
22
- const buffer = await serializer.serialize(event);
23
- const data = buffer.toString('base64');
24
- // Default attributes if the event conforms to the `Event` interface.
25
- const defaultAttributes = {};
26
- if ('producedAt' in event && event.producedAt instanceof Date) {
27
- defaultAttributes.producedAt = event.producedAt.toISOString();
28
- }
29
- if ('name' in event && typeof event.name === 'string') {
30
- defaultAttributes.eventName = event.name;
31
- }
32
- if ('id' in event && typeof event.id === 'string') {
33
- defaultAttributes.eventId = event.id;
34
- }
35
- const attributes = { ...defaultAttributes, ...requestOptions?.attributes };
36
- await request
37
- .post(`${routePrefix}${endpoint}`)
38
- .send({
39
- message: {
40
- messageId,
41
- message_id: messageId,
42
- publishTime,
43
- publish_time: publishTime,
44
- attributes,
45
- data,
46
- },
47
- subscription: 'subscription',
48
- })
49
- .expect(requestOptions?.expectedStatus ??
50
- options.expectedStatus ??
51
- HttpStatus.OK);
52
- };
53
- }