@causa/runtime-google 1.4.1 → 1.5.0

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.
@@ -1,21 +1,8 @@
1
- import { Database, Snapshot, Transaction } from '@google-cloud/spanner';
2
- import { type Type as ParamType } from '@google-cloud/spanner/build/src/codec.js';
1
+ import { Database } from '@google-cloud/spanner';
3
2
  import type { ExecuteSqlRequest, TimestampBounds } from '@google-cloud/spanner/build/src/transaction.js';
4
3
  import { type Type } from '@nestjs/common';
5
4
  import { SpannerTableCache } from './table-cache.js';
6
- import type { SpannerReadOnlyTransactionOption, SpannerReadWriteTransactionOption } from './types.js';
7
- /**
8
- * Any Spanner transaction that can be used for reading.
9
- */
10
- export type SpannerReadOnlyTransaction = Snapshot | Transaction;
11
- /**
12
- * A Spanner transaction that can be used for reading and writing.
13
- */
14
- export type SpannerReadWriteTransaction = Transaction;
15
- /**
16
- * A key for a Spanner row.
17
- */
18
- export type SpannerKey = (string | null)[];
5
+ import type { SpannerKey, SpannerReadOnlyTransaction, SpannerReadOnlyTransactionOption, SpannerReadWriteTransaction, SpannerReadWriteTransactionOption, SqlParamType, SqlStatement } from './types.js';
19
6
  /**
20
7
  * Options for {@link SpannerEntityManager.snapshot}.
21
8
  */
@@ -33,23 +20,6 @@ export type SnapshotFunction<T> = (snapshot: SpannerReadOnlyTransaction) => Prom
33
20
  * A function that can be passed to the {@link SpannerEntityManager.transaction} method.
34
21
  */
35
22
  export type SpannerTransactionFunction<T> = (transaction: SpannerReadWriteTransaction) => Promise<T>;
36
- /**
37
- * A SQL statement run using {@link SpannerEntityManager.query}.
38
- */
39
- export type SqlStatement = {
40
- /**
41
- * The SQL statement to run.
42
- */
43
- sql: string;
44
- /**
45
- * The values for the parameters referenced in the statement.
46
- */
47
- params?: Record<string, any>;
48
- /**
49
- * The types of the parameters in the statement.
50
- */
51
- types?: Record<string, ParamType>;
52
- };
53
23
  /**
54
24
  * Options for {@link SpannerEntityManager.query}.
55
25
  */
@@ -312,15 +282,15 @@ export declare class SpannerEntityManager {
312
282
  */
313
283
  batchSize: number;
314
284
  }, statement: SqlStatement): AsyncIterable<T[]>;
315
- static readonly ParamTypeFloat64Array: ParamType;
316
- static readonly ParamTypeInt64Array: ParamType;
317
- static readonly ParamTypeNumericArray: ParamType;
318
- static readonly ParamTypeBoolArray: ParamType;
319
- static readonly ParamTypeStringArray: ParamType;
320
- static readonly ParamTypeBytesArray: ParamType;
321
- static readonly ParamTypeJsonArray: ParamType;
322
- static readonly ParamTypeTimestampArray: ParamType;
323
- static readonly ParamTypeDateArray: ParamType;
285
+ static readonly ParamTypeFloat64Array: SqlParamType;
286
+ static readonly ParamTypeInt64Array: SqlParamType;
287
+ static readonly ParamTypeNumericArray: SqlParamType;
288
+ static readonly ParamTypeBoolArray: SqlParamType;
289
+ static readonly ParamTypeStringArray: SqlParamType;
290
+ static readonly ParamTypeBytesArray: SqlParamType;
291
+ static readonly ParamTypeJsonArray: SqlParamType;
292
+ static readonly ParamTypeTimestampArray: SqlParamType;
293
+ static readonly ParamTypeDateArray: SqlParamType;
324
294
  /**
325
295
  * Converts the given entity or array of entities to Spanner objects, grouping them by table name.
326
296
  *
@@ -8,8 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { EntityNotFoundError } from '@causa/runtime';
11
- import { Database, Snapshot, Transaction } from '@google-cloud/spanner';
12
- import {} from '@google-cloud/spanner/build/src/codec.js';
11
+ import { Database, Snapshot } from '@google-cloud/spanner';
13
12
  import { Injectable } from '@nestjs/common';
14
13
  import { copyInstanceWithMissingColumnsToNull, instanceToSpannerObject, spannerObjectToInstance, updateInstanceByColumn, } from './conversion.js';
15
14
  import { convertSpannerToEntityError } from './error-converter.js';
@@ -303,6 +302,10 @@ let SpannerEntityManager = class SpannerEntityManager {
303
302
  jsonOptions: { wrapNumbers: entityType != null },
304
303
  });
305
304
  for await (const row of stream) {
305
+ // `undefined` may be sent by the `PartialResultStream` to test whether the consumer can accept more data.
306
+ if (row === undefined) {
307
+ continue;
308
+ }
306
309
  yield entityType ? spannerObjectToInstance(row, entityType) : row;
307
310
  }
308
311
  }
@@ -1,7 +1,6 @@
1
1
  export { SpannerColumn } from './column.decorator.js';
2
2
  export { catchSpannerDatabaseErrors, getDefaultSpannerDatabaseForCloudFunction, SPANNER_SESSION_POOL_OPTIONS_FOR_CLOUD_FUNCTIONS, SPANNER_SESSION_POOL_OPTIONS_FOR_SERVICE, } from './database.js';
3
3
  export { SpannerEntityManager } from './entity-manager.js';
4
- export type { SpannerKey, SpannerReadOnlyTransaction, SpannerReadWriteTransaction, SqlStatement, } from './entity-manager.js';
5
4
  export * from './errors.js';
6
5
  export { SpannerHealthIndicator } from './healthcheck.js';
7
6
  export { SpannerModule } from './module.js';
@@ -1,5 +1,5 @@
1
1
  import type { Type } from '@nestjs/common';
2
- import type { SpannerKey } from './entity-manager.js';
2
+ import type { SpannerKey } from './types.js';
3
3
  /**
4
4
  * A function that, given an entity, returns its primary key as a {@link SpannerKey}.
5
5
  */
@@ -24,20 +24,27 @@ function makeDatabaseParameters(options) {
24
24
  * @returns The database object.
25
25
  */
26
26
  export async function createDatabase(options = {}) {
27
- const { name, sourceDatabaseName, instance } = makeDatabaseParameters(options);
28
- const [databases] = await instance.getDatabases();
29
- const existingDatabase = databases.find((d) => d.formattedName_.split('/').pop() === name);
30
- await existingDatabase?.delete();
31
- const [database, operation] = await instance.createDatabase(name);
32
- await operation.promise();
27
+ const { name, sourceDatabaseName, instance, spanner } = makeDatabaseParameters(options);
28
+ const [{ formattedName_: parent }] = await instance.get();
29
+ const adminClient = spanner.getDatabaseAdminClient();
30
+ const [databases] = await adminClient.listDatabases({ parent });
31
+ const existingDatabase = databases.find((d) => d.name?.split('/').pop() === name);
32
+ if (existingDatabase) {
33
+ await adminClient.dropDatabase({ database: existingDatabase.name });
34
+ }
35
+ let extraStatements;
33
36
  if (sourceDatabaseName) {
34
37
  const sourceDatabase = instance.database(sourceDatabaseName);
35
- const [schema] = await sourceDatabase.getSchema();
38
+ [extraStatements] = await sourceDatabase.getSchema();
36
39
  await sourceDatabase.close();
37
- const [updateOperation] = await database.updateSchema(schema);
38
- await updateOperation.promise();
39
40
  }
40
- return database;
41
+ const [operation] = await adminClient.createDatabase({
42
+ parent,
43
+ createStatement: `CREATE DATABASE \`${name}\``,
44
+ extraStatements,
45
+ });
46
+ await operation.promise();
47
+ return instance.database(name);
41
48
  }
42
49
  /**
43
50
  * A {@link Fixture} that creates a temporary Spanner database and injects it into the NestJS application.
@@ -1,6 +1,19 @@
1
- import { protos } from '@google-cloud/spanner';
2
- import type { SpannerReadOnlyTransaction, SpannerReadWriteTransaction } from './entity-manager.js';
1
+ import { protos, Snapshot, Transaction } from '@google-cloud/spanner';
2
+ import type { Type } from '@google-cloud/spanner/build/src/codec.js';
3
+ export type SqlParamType = Type;
3
4
  export declare const SpannerRequestPriority: typeof protos.google.spanner.v1.RequestOptions.Priority;
5
+ /**
6
+ * A key for a Spanner row.
7
+ */
8
+ export type SpannerKey = (string | null)[];
9
+ /**
10
+ * Any Spanner transaction that can be used for reading.
11
+ */
12
+ export type SpannerReadOnlyTransaction = Snapshot | Transaction;
13
+ /**
14
+ * A Spanner transaction that can be used for reading and writing.
15
+ */
16
+ export type SpannerReadWriteTransaction = Transaction;
4
17
  /**
5
18
  * Option for a function that accepts a Spanner read-only transaction.
6
19
  */
@@ -29,3 +42,28 @@ export type SpannerReadWriteTransactionOption = {
29
42
  */
30
43
  readonly tag?: string;
31
44
  };
45
+ /**
46
+ * Parameters for a SQL statement run using `SpannerEntityManager.query`.
47
+ */
48
+ export type SqlStatementParams = Record<string, any>;
49
+ /**
50
+ * Types for parameters in a SQL statement run using `SpannerEntityManager.query`.
51
+ */
52
+ export type SqlStatementTypes = Record<string, SqlParamType>;
53
+ /**
54
+ * A SQL statement run using `SpannerEntityManager.query`.
55
+ */
56
+ export type SqlStatement = {
57
+ /**
58
+ * The SQL statement to run.
59
+ */
60
+ sql: string;
61
+ /**
62
+ * The values for the parameters referenced in the statement.
63
+ */
64
+ params?: SqlStatementParams;
65
+ /**
66
+ * The types of the parameters in the statement.
67
+ */
68
+ types?: SqlStatementTypes;
69
+ };
@@ -1,2 +1,2 @@
1
- import { protos } from '@google-cloud/spanner';
1
+ import { protos, Snapshot, Transaction } from '@google-cloud/spanner';
2
2
  export const SpannerRequestPriority = protos.google.spanner.v1.RequestOptions.Priority;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/runtime-google",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "An extension to the Causa runtime SDK (`@causa/runtime`), providing Google-specific features.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -56,7 +56,7 @@
56
56
  "@nestjs/testing": "^11.1.9",
57
57
  "@swc/core": "^1.15.2",
58
58
  "@swc/jest": "^0.2.39",
59
- "@tsconfig/node20": "^20.1.7",
59
+ "@tsconfig/node20": "^20.1.8",
60
60
  "@types/jest": "^30.0.0",
61
61
  "@types/jsonwebtoken": "^9.0.10",
62
62
  "@types/node": "^20.19.25",
@@ -70,10 +70,10 @@
70
70
  "jest": "^30.2.0",
71
71
  "jest-extended": "^7.0.0",
72
72
  "pino-pretty": "^13.1.2",
73
- "rimraf": "^6.1.0",
73
+ "rimraf": "^6.1.2",
74
74
  "supertest": "^7.1.4",
75
75
  "typescript": "^5.9.3",
76
- "typescript-eslint": "^8.46.4",
76
+ "typescript-eslint": "^8.47.0",
77
77
  "uuid": "^13.0.0"
78
78
  }
79
79
  }