typeorm 0.3.18-dev.0f11739 → 0.3.18-dev.173910e
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/browser/cache/DbQueryResultCache.js +3 -0
- package/browser/cache/DbQueryResultCache.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachQueryRunner.js +8 -0
- package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
- package/browser/driver/cordova/CordovaQueryRunner.js +8 -0
- package/browser/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/browser/driver/expo/ExpoQueryRunner.js +9 -2
- package/browser/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/browser/driver/mysql/MysqlQueryRunner.js +9 -1
- package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
- package/browser/driver/oracle/OracleQueryRunner.js +8 -0
- package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
- package/browser/driver/postgres/PostgresQueryRunner.js +8 -0
- package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/browser/driver/react-native/ReactNativeQueryRunner.js +10 -2
- package/browser/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/browser/driver/sap/SapQueryRunner.js +9 -3
- package/browser/driver/sap/SapQueryRunner.js.map +1 -1
- package/browser/driver/spanner/SpannerQueryRunner.js +6 -0
- package/browser/driver/spanner/SpannerQueryRunner.js.map +1 -1
- package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
- package/browser/driver/sqlite/SqliteQueryRunner.js +61 -46
- package/browser/driver/sqlite/SqliteQueryRunner.js.map +1 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js +11 -3
- package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerQueryRunner.js +6 -0
- package/browser/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
- package/browser/metadata/ColumnMetadata.js +4 -0
- package/browser/metadata/ColumnMetadata.js.map +1 -1
- package/browser/metadata/EntityMetadata.d.ts +3 -3
- package/browser/metadata/EntityMetadata.js +7 -3
- package/browser/metadata/EntityMetadata.js.map +1 -1
- package/browser/persistence/EntityPersistExecutor.js +1 -1
- package/browser/persistence/EntityPersistExecutor.js.map +1 -1
- package/browser/query-builder/QueryExpressionMap.d.ts +2 -1
- package/browser/query-builder/QueryExpressionMap.js +0 -4
- package/browser/query-builder/QueryExpressionMap.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +1 -1
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.d.ts +9 -0
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +28 -0
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/browser/subscriber/Broadcaster.d.ts +10 -0
- package/browser/subscriber/Broadcaster.js +46 -0
- package/browser/subscriber/Broadcaster.js.map +1 -1
- package/browser/subscriber/EntitySubscriberInterface.d.ts +9 -0
- package/browser/subscriber/EntitySubscriberInterface.js.map +1 -1
- package/browser/subscriber/event/QueryEvent.d.ts +50 -0
- package/browser/subscriber/event/QueryEvent.js +3 -0
- package/browser/subscriber/event/QueryEvent.js.map +1 -0
- package/cache/DbQueryResultCache.js +3 -0
- package/cache/DbQueryResultCache.js.map +1 -1
- package/driver/cockroachdb/CockroachQueryRunner.js +8 -0
- package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
- package/driver/cordova/CordovaQueryRunner.js +8 -0
- package/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/driver/expo/ExpoQueryRunner.js +9 -2
- package/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/driver/mysql/MysqlQueryRunner.js +9 -1
- package/driver/mysql/MysqlQueryRunner.js.map +1 -1
- package/driver/oracle/OracleQueryRunner.js +8 -0
- package/driver/oracle/OracleQueryRunner.js.map +1 -1
- package/driver/postgres/PostgresQueryRunner.js +8 -0
- package/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/driver/react-native/ReactNativeQueryRunner.js +10 -2
- package/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/driver/sap/SapQueryRunner.js +9 -3
- package/driver/sap/SapQueryRunner.js.map +1 -1
- package/driver/spanner/SpannerQueryRunner.js +6 -0
- package/driver/spanner/SpannerQueryRunner.js.map +1 -1
- package/driver/sqlite/SqliteDriver.js.map +1 -1
- package/driver/sqlite/SqliteQueryRunner.js +61 -46
- package/driver/sqlite/SqliteQueryRunner.js.map +1 -1
- package/driver/sqljs/SqljsQueryRunner.js +11 -3
- package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/driver/sqlserver/SqlServerQueryRunner.js +6 -0
- package/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
- package/metadata/ColumnMetadata.js +4 -0
- package/metadata/ColumnMetadata.js.map +1 -1
- package/metadata/EntityMetadata.d.ts +3 -3
- package/metadata/EntityMetadata.js +7 -3
- package/metadata/EntityMetadata.js.map +1 -1
- package/package.json +1 -1
- package/persistence/EntityPersistExecutor.js +1 -1
- package/persistence/EntityPersistExecutor.js.map +1 -1
- package/query-builder/QueryExpressionMap.d.ts +2 -1
- package/query-builder/QueryExpressionMap.js +0 -4
- package/query-builder/QueryExpressionMap.js.map +1 -1
- package/query-builder/SelectQueryBuilder.js +1 -1
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.d.ts +9 -0
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +28 -0
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/subscriber/Broadcaster.d.ts +10 -0
- package/subscriber/Broadcaster.js +46 -0
- package/subscriber/Broadcaster.js.map +1 -1
- package/subscriber/EntitySubscriberInterface.d.ts +9 -0
- package/subscriber/EntitySubscriberInterface.js.map +1 -1
- package/subscriber/event/QueryEvent.d.ts +50 -0
- package/subscriber/event/QueryEvent.js +4 -0
- package/subscriber/event/QueryEvent.js.map +1 -0
|
@@ -7,6 +7,7 @@ import { InsertEvent } from "./event/InsertEvent";
|
|
|
7
7
|
import { LoadEvent } from "./event/LoadEvent";
|
|
8
8
|
import { SoftRemoveEvent } from "./event/SoftRemoveEvent";
|
|
9
9
|
import { RecoverEvent } from "./event/RecoverEvent";
|
|
10
|
+
import { AfterQueryEvent, BeforeQueryEvent } from "./event/QueryEvent";
|
|
10
11
|
/**
|
|
11
12
|
* Classes that implement this interface are subscribers that subscribe for the specific events in the ORM.
|
|
12
13
|
*/
|
|
@@ -25,6 +26,14 @@ export interface EntitySubscriberInterface<Entity = any> {
|
|
|
25
26
|
* compilation for existing subscribers).
|
|
26
27
|
*/
|
|
27
28
|
afterLoad?(entity: Entity, event?: LoadEvent<Entity>): Promise<any> | void;
|
|
29
|
+
/**
|
|
30
|
+
* Called before query is executed.
|
|
31
|
+
*/
|
|
32
|
+
beforeQuery?(event: BeforeQueryEvent<Entity>): Promise<any> | void;
|
|
33
|
+
/**
|
|
34
|
+
* Called after query is executed.
|
|
35
|
+
*/
|
|
36
|
+
afterQuery?(event: AfterQueryEvent<Entity>): Promise<any> | void;
|
|
28
37
|
/**
|
|
29
38
|
* Called before entity is inserted to the database.
|
|
30
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/subscriber/EntitySubscriberInterface.ts"],"names":[],"mappings":"","file":"EntitySubscriberInterface.js","sourcesContent":["import { TransactionCommitEvent } from \"./event/TransactionCommitEvent\"\nimport { TransactionRollbackEvent } from \"./event/TransactionRollbackEvent\"\nimport { TransactionStartEvent } from \"./event/TransactionStartEvent\"\nimport { UpdateEvent } from \"./event/UpdateEvent\"\nimport { RemoveEvent } from \"./event/RemoveEvent\"\nimport { InsertEvent } from \"./event/InsertEvent\"\nimport { LoadEvent } from \"./event/LoadEvent\"\nimport { SoftRemoveEvent } from \"./event/SoftRemoveEvent\"\nimport { RecoverEvent } from \"./event/RecoverEvent\"\n\n/**\n * Classes that implement this interface are subscribers that subscribe for the specific events in the ORM.\n */\nexport interface EntitySubscriberInterface<Entity = any> {\n /**\n * Returns the class of the entity to which events will listen.\n * If this method is omitted, then subscriber will listen to events of all entities.\n */\n listenTo?(): Function | string\n\n /**\n * Called after entity is loaded from the database.\n *\n * For backward compatibility this signature is slightly different from the\n * others. `event` was added later but is always provided (it is only\n * optional in the signature so that its introduction does not break\n * compilation for existing subscribers).\n */\n afterLoad?(entity: Entity, event?: LoadEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is inserted to the database.\n */\n beforeInsert?(event: InsertEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is inserted to the database.\n */\n afterInsert?(event: InsertEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is updated in the database.\n */\n beforeUpdate?(event: UpdateEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is updated in the database.\n */\n afterUpdate?(event: UpdateEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is removed from the database.\n */\n beforeRemove?(event: RemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is soft removed from the database.\n */\n beforeSoftRemove?(event: SoftRemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is recovered in the database.\n */\n beforeRecover?(event: RecoverEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is removed from the database.\n */\n afterRemove?(event: RemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is soft removed from the database.\n */\n afterSoftRemove?(event: SoftRemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is recovered in the database.\n */\n afterRecover?(event: RecoverEvent<Entity>): Promise<any> | void\n\n /**\n * Called before transaction is started.\n */\n beforeTransactionStart?(event: TransactionStartEvent): Promise<any> | void\n\n /**\n * Called after transaction is started.\n */\n afterTransactionStart?(event: TransactionStartEvent): Promise<any> | void\n\n /**\n * Called before transaction is committed.\n */\n beforeTransactionCommit?(event: TransactionCommitEvent): Promise<any> | void\n\n /**\n * Called after transaction is committed.\n */\n afterTransactionCommit?(event: TransactionCommitEvent): Promise<any> | void\n\n /**\n * Called before transaction rollback.\n */\n beforeTransactionRollback?(\n event: TransactionRollbackEvent,\n ): Promise<any> | void\n\n /**\n * Called after transaction rollback.\n */\n afterTransactionRollback?(\n event: TransactionRollbackEvent,\n ): Promise<any> | void\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/subscriber/EntitySubscriberInterface.ts"],"names":[],"mappings":"","file":"EntitySubscriberInterface.js","sourcesContent":["import { TransactionCommitEvent } from \"./event/TransactionCommitEvent\"\nimport { TransactionRollbackEvent } from \"./event/TransactionRollbackEvent\"\nimport { TransactionStartEvent } from \"./event/TransactionStartEvent\"\nimport { UpdateEvent } from \"./event/UpdateEvent\"\nimport { RemoveEvent } from \"./event/RemoveEvent\"\nimport { InsertEvent } from \"./event/InsertEvent\"\nimport { LoadEvent } from \"./event/LoadEvent\"\nimport { SoftRemoveEvent } from \"./event/SoftRemoveEvent\"\nimport { RecoverEvent } from \"./event/RecoverEvent\"\nimport { AfterQueryEvent, BeforeQueryEvent } from \"./event/QueryEvent\"\n\n/**\n * Classes that implement this interface are subscribers that subscribe for the specific events in the ORM.\n */\nexport interface EntitySubscriberInterface<Entity = any> {\n /**\n * Returns the class of the entity to which events will listen.\n * If this method is omitted, then subscriber will listen to events of all entities.\n */\n listenTo?(): Function | string\n\n /**\n * Called after entity is loaded from the database.\n *\n * For backward compatibility this signature is slightly different from the\n * others. `event` was added later but is always provided (it is only\n * optional in the signature so that its introduction does not break\n * compilation for existing subscribers).\n */\n afterLoad?(entity: Entity, event?: LoadEvent<Entity>): Promise<any> | void\n\n /**\n * Called before query is executed.\n */\n beforeQuery?(event: BeforeQueryEvent<Entity>): Promise<any> | void\n\n /**\n * Called after query is executed.\n */\n afterQuery?(event: AfterQueryEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is inserted to the database.\n */\n beforeInsert?(event: InsertEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is inserted to the database.\n */\n afterInsert?(event: InsertEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is updated in the database.\n */\n beforeUpdate?(event: UpdateEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is updated in the database.\n */\n afterUpdate?(event: UpdateEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is removed from the database.\n */\n beforeRemove?(event: RemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is soft removed from the database.\n */\n beforeSoftRemove?(event: SoftRemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called before entity is recovered in the database.\n */\n beforeRecover?(event: RecoverEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is removed from the database.\n */\n afterRemove?(event: RemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is soft removed from the database.\n */\n afterSoftRemove?(event: SoftRemoveEvent<Entity>): Promise<any> | void\n\n /**\n * Called after entity is recovered in the database.\n */\n afterRecover?(event: RecoverEvent<Entity>): Promise<any> | void\n\n /**\n * Called before transaction is started.\n */\n beforeTransactionStart?(event: TransactionStartEvent): Promise<any> | void\n\n /**\n * Called after transaction is started.\n */\n afterTransactionStart?(event: TransactionStartEvent): Promise<any> | void\n\n /**\n * Called before transaction is committed.\n */\n beforeTransactionCommit?(event: TransactionCommitEvent): Promise<any> | void\n\n /**\n * Called after transaction is committed.\n */\n afterTransactionCommit?(event: TransactionCommitEvent): Promise<any> | void\n\n /**\n * Called before transaction rollback.\n */\n beforeTransactionRollback?(\n event: TransactionRollbackEvent,\n ): Promise<any> | void\n\n /**\n * Called after transaction rollback.\n */\n afterTransactionRollback?(\n event: TransactionRollbackEvent,\n ): Promise<any> | void\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { EntityManager } from "../../entity-manager/EntityManager";
|
|
2
|
+
import { DataSource } from "../../data-source/DataSource";
|
|
3
|
+
import { QueryRunner } from "../../query-runner/QueryRunner";
|
|
4
|
+
/**
|
|
5
|
+
* BeforeQueryEvent is an object that broadcaster sends to the entity subscriber before query is ran against the database.
|
|
6
|
+
*/
|
|
7
|
+
export interface QueryEvent<Entity> {
|
|
8
|
+
/**
|
|
9
|
+
* Connection used in the event.
|
|
10
|
+
*/
|
|
11
|
+
connection: DataSource;
|
|
12
|
+
/**
|
|
13
|
+
* QueryRunner used in the event transaction.
|
|
14
|
+
* All database operations in the subscribed event listener should be performed using this query runner instance.
|
|
15
|
+
*/
|
|
16
|
+
queryRunner: QueryRunner;
|
|
17
|
+
/**
|
|
18
|
+
* EntityManager used in the event transaction.
|
|
19
|
+
* All database operations in the subscribed event listener should be performed using this entity manager instance.
|
|
20
|
+
*/
|
|
21
|
+
manager: EntityManager;
|
|
22
|
+
/**
|
|
23
|
+
* Query that is being executed.
|
|
24
|
+
*/
|
|
25
|
+
query: string;
|
|
26
|
+
/**
|
|
27
|
+
* Parameters used in the query.
|
|
28
|
+
*/
|
|
29
|
+
parameters?: any[];
|
|
30
|
+
}
|
|
31
|
+
export interface BeforeQueryEvent<Entity> extends QueryEvent<Entity> {
|
|
32
|
+
}
|
|
33
|
+
export interface AfterQueryEvent<Entity> extends QueryEvent<Entity> {
|
|
34
|
+
/**
|
|
35
|
+
* Whether the query was successful.
|
|
36
|
+
*/
|
|
37
|
+
success: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The duration of the query execution.
|
|
40
|
+
*/
|
|
41
|
+
executionTime?: number;
|
|
42
|
+
/**
|
|
43
|
+
* The raw results from the database if the query was successful.
|
|
44
|
+
*/
|
|
45
|
+
rawResults?: any;
|
|
46
|
+
/**
|
|
47
|
+
* The error thrown if the query was unsuccessful.
|
|
48
|
+
*/
|
|
49
|
+
error?: any;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../browser/src/subscriber/event/QueryEvent.ts"],"names":[],"mappings":"","file":"QueryEvent.js","sourcesContent":["import { EntityManager } from \"../../entity-manager/EntityManager\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\n\n/**\n * BeforeQueryEvent is an object that broadcaster sends to the entity subscriber before query is ran against the database.\n */\nexport interface QueryEvent<Entity> {\n /**\n * Connection used in the event.\n */\n connection: DataSource\n\n /**\n * QueryRunner used in the event transaction.\n * All database operations in the subscribed event listener should be performed using this query runner instance.\n */\n queryRunner: QueryRunner\n\n /**\n * EntityManager used in the event transaction.\n * All database operations in the subscribed event listener should be performed using this entity manager instance.\n */\n manager: EntityManager\n\n /**\n * Query that is being executed.\n */\n query: string\n\n /**\n * Parameters used in the query.\n */\n parameters?: any[]\n}\n\nexport interface BeforeQueryEvent<Entity> extends QueryEvent<Entity> {}\n\nexport interface AfterQueryEvent<Entity> extends QueryEvent<Entity> {\n /**\n * Whether the query was successful.\n */\n success: boolean\n\n /**\n * The duration of the query execution.\n */\n executionTime?: number\n\n /**\n * The raw results from the database if the query was successful.\n */\n rawResults?: any\n\n /**\n * The error thrown if the query was unsuccessful.\n */\n error?: any\n}\n"],"sourceRoot":"../.."}
|
|
@@ -120,12 +120,14 @@ class DbQueryResultCache {
|
|
|
120
120
|
? new MssqlParameter_1.MssqlParameter(options.identifier, "nvarchar")
|
|
121
121
|
: options.identifier,
|
|
122
122
|
})
|
|
123
|
+
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
|
123
124
|
.getRawOne();
|
|
124
125
|
}
|
|
125
126
|
else if (options.query) {
|
|
126
127
|
if (this.connection.driver.options.type === "oracle") {
|
|
127
128
|
return qb
|
|
128
129
|
.where(`dbms_lob.compare(${qb.escape("cache")}.${qb.escape("query")}, :query) = 0`, { query: options.query })
|
|
130
|
+
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
|
129
131
|
.getRawOne();
|
|
130
132
|
}
|
|
131
133
|
return qb
|
|
@@ -135,6 +137,7 @@ class DbQueryResultCache {
|
|
|
135
137
|
? new MssqlParameter_1.MssqlParameter(options.query, "nvarchar")
|
|
136
138
|
: options.query,
|
|
137
139
|
})
|
|
140
|
+
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
|
138
141
|
.getRawOne();
|
|
139
142
|
}
|
|
140
143
|
return Promise.resolve(undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cache/DbQueryResultCache.ts"],"names":[],"mappings":";;;AAEA,uEAAmE;AAEnE,yDAAqD;AAGrD,+BAAmC;AAEnC;;GAEG;AACH,MAAa,kBAAkB;IAW3B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,CAAA;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAA;QAChD,MAAM,YAAY,GACd,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC7C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK;YAC/B,CAAC,CAAC,EAAE,CAAA;QACZ,MAAM,cAAc,GAAG,YAAY,CAAC,SAAS,IAAI,oBAAoB,CAAA;QAErE,IAAI,CAAC,wBAAwB,GAAG,QAAQ,CAAA;QACxC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAA;QACpC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAC9D,cAAc,EACd,MAAM,EACN,QAAQ,CACX,CAAA;IACL,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,OAAO,KAAmB,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,UAAU,KAAmB,CAAC;IAEpC;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,WAAyB;QACvC,WAAW,G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IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,WAAqB,EACrB,WAAyB;QAEzB,IAAI,YAAY,GAAgB,WAAW,IAAI,IAAI,CAAC,cAAc,EAAE,CAAA;QACpE,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACpD,OAAO,EAAE;iBACJ,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC;iBAChC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;gBAC/C,UAAU;aACb,CAAC;iBACD,OAAO,EAAE,CAAA;QAClB,CAAC,CAAC,CACL,CAAA;QAED,IAAI,CAAC,WAAW,EAAE;YACd,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;SAC/B;IACL,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACO,cAAc,CAAC,WAAyB;QAC9C,IAAI,WAAW;YAAE,OAAO,WAAW,CAAA;QAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;IAC9C,CAAC;CACJ;AA/TD,gDA+TC","file":"DbQueryResultCache.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { v4 as uuidv4 } from \"uuid\"\n\n/**\n * Caches query result into current database, into separate table called \"query-result-cache\".\n */\nexport class DbQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Private properties\n // -------------------------------------------------------------------------\n\n private queryResultCacheTable: string\n\n private queryResultCacheDatabase?: string\n\n private queryResultCacheSchema?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {\n const { schema } = this.connection.driver.options as any\n const database = this.connection.driver.database\n const cacheOptions =\n typeof this.connection.options.cache === \"object\"\n ? this.connection.options.cache\n : {}\n const cacheTableName = cacheOptions.tableName || \"query-result-cache\"\n\n this.queryResultCacheDatabase = database\n this.queryResultCacheSchema = schema\n this.queryResultCacheTable = this.connection.driver.buildTableName(\n cacheTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {}\n\n /**\n * Disconnects with given cache provider.\n */\n async disconnect(): Promise<void> {}\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner?: QueryRunner): Promise<void> {\n queryRunner = this.getQueryRunner(queryRunner)\n const driver = this.connection.driver\n const tableExist = await queryRunner.hasTable(\n this.queryResultCacheTable,\n ) // todo: table name should be configurable\n if (tableExist) return\n\n await queryRunner.createTable(\n new Table({\n database: this.queryResultCacheDatabase,\n schema: this.queryResultCacheSchema,\n name: this.queryResultCacheTable,\n columns: [\n {\n name: \"id\",\n isPrimary: true,\n isNullable: false,\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheId,\n }),\n generationStrategy:\n driver.options.type === \"spanner\"\n ? \"uuid\"\n : \"increment\",\n isGenerated: true,\n },\n {\n name: \"identifier\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheIdentifier,\n }),\n isNullable: true,\n },\n {\n name: \"time\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheTime,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"duration\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheDuration,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"query\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheQuery,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"result\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheResult,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n queryRunner = this.getQueryRunner(queryRunner)\n const qb = this.connection\n .createQueryBuilder(queryRunner)\n .select()\n .from(this.queryResultCacheTable, \"cache\")\n\n if (options.identifier) {\n return qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\n \"identifier\",\n )} = :identifier`,\n )\n .setParameters({\n identifier:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.identifier, \"nvarchar\")\n : options.identifier,\n })\n .getRawOne()\n } else if (options.query) {\n if (this.connection.driver.options.type === \"oracle\") {\n return qb\n .where(\n `dbms_lob.compare(${qb.escape(\"cache\")}.${qb.escape(\n \"query\",\n )}, :query) = 0`,\n { query: options.query },\n )\n .getRawOne()\n }\n\n return qb\n .where(`${qb.escape(\"cache\")}.${qb.escape(\"query\")} = :query`)\n .setParameters({\n query:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.query, \"nvarchar\")\n : options.query,\n })\n .getRawOne()\n }\n\n return Promise.resolve(undefined)\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n const duration =\n typeof savedCache.duration === \"string\"\n ? parseInt(savedCache.duration)\n : savedCache.duration\n return (\n (typeof savedCache.time === \"string\"\n ? parseInt(savedCache.time as any)\n : savedCache.time)! +\n duration <\n new Date().getTime()\n )\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const shouldCreateQueryRunner =\n queryRunner === undefined ||\n queryRunner?.getReplicationMode() === \"slave\"\n\n if (queryRunner === undefined || shouldCreateQueryRunner) {\n queryRunner = this.connection.createQueryRunner(\"master\")\n }\n\n let insertedValues: ObjectLiteral = options\n if (this.connection.driver.options.type === \"mssql\") {\n // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table\n insertedValues = {\n identifier: new MssqlParameter(options.identifier, \"nvarchar\"),\n time: new MssqlParameter(options.time, \"bigint\"),\n duration: new MssqlParameter(options.duration, \"int\"),\n query: new MssqlParameter(options.query, \"nvarchar\"),\n result: new MssqlParameter(options.result, \"nvarchar\"),\n }\n }\n\n if (savedCache && savedCache.identifier) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n qb.where(`${qb.escape(\"identifier\")} = :condition`, {\n condition: insertedValues.identifier,\n })\n await qb.execute()\n } else if (savedCache && savedCache.query) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n if (this.connection.driver.options.type === \"oracle\") {\n qb.where(`dbms_lob.compare(\"query\", :condition) = 0`, {\n condition: insertedValues.query,\n })\n } else {\n qb.where(`${qb.escape(\"query\")} = :condition`, {\n condition: insertedValues.query,\n })\n }\n\n await qb.execute()\n } else {\n // Spanner does not support auto-generated columns\n if (\n this.connection.driver.options.type === \"spanner\" &&\n !insertedValues.id\n ) {\n insertedValues.id = uuidv4()\n }\n\n // otherwise insert\n await queryRunner.manager\n .createQueryBuilder()\n .insert()\n .into(this.queryResultCacheTable)\n .values(insertedValues)\n .execute()\n }\n\n if (shouldCreateQueryRunner) {\n await queryRunner.release()\n }\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner: QueryRunner): Promise<void> {\n return this.getQueryRunner(queryRunner).clearTable(\n this.queryResultCacheTable,\n )\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n let _queryRunner: QueryRunner = queryRunner || this.getQueryRunner()\n await Promise.all(\n identifiers.map((identifier) => {\n const qb = _queryRunner.manager.createQueryBuilder()\n return qb\n .delete()\n .from(this.queryResultCacheTable)\n .where(`${qb.escape(\"identifier\")} = :identifier`, {\n identifier,\n })\n .execute()\n }),\n )\n\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a query runner to work with.\n */\n protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner {\n if (queryRunner) return queryRunner\n\n return this.connection.createQueryRunner()\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../../src/cache/DbQueryResultCache.ts"],"names":[],"mappings":";;;AAEA,uEAAmE;AAEnE,yDAAqD;AAGrD,+BAAmC;AAEnC;;GAEG;AACH,MAAa,kBAAkB;IAW3B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,CAAA;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAA;QAChD,MAAM,YAAY,GACd,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC7C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK;YAC/B,CAAC,CAAC,EAAE,CAAA;QACZ,MAAM,cAAc,GAAG,YAAY,CAAC,SAAS,IAAI,oBAAoB,CAAA;QAErE,IAAI,CAAC,wBAAwB,GAAG,QAAQ,CAAA;QACxC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAA;QACpC,IAAI,CAAC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AiB,EAAE,CAAA;IAC9C,CAAC;CACJ;AAlUD,gDAkUC","file":"DbQueryResultCache.js","sourcesContent":["import { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { QueryResultCache } from \"./QueryResultCache\"\nimport { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { v4 as uuidv4 } from \"uuid\"\n\n/**\n * Caches query result into current database, into separate table called \"query-result-cache\".\n */\nexport class DbQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Private properties\n // -------------------------------------------------------------------------\n\n private queryResultCacheTable: string\n\n private queryResultCacheDatabase?: string\n\n private queryResultCacheSchema?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {\n const { schema } = this.connection.driver.options as any\n const database = this.connection.driver.database\n const cacheOptions =\n typeof this.connection.options.cache === \"object\"\n ? this.connection.options.cache\n : {}\n const cacheTableName = cacheOptions.tableName || \"query-result-cache\"\n\n this.queryResultCacheDatabase = database\n this.queryResultCacheSchema = schema\n this.queryResultCacheTable = this.connection.driver.buildTableName(\n cacheTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {}\n\n /**\n * Disconnects with given cache provider.\n */\n async disconnect(): Promise<void> {}\n\n /**\n * Creates table for storing cache if it does not exist yet.\n */\n async synchronize(queryRunner?: QueryRunner): Promise<void> {\n queryRunner = this.getQueryRunner(queryRunner)\n const driver = this.connection.driver\n const tableExist = await queryRunner.hasTable(\n this.queryResultCacheTable,\n ) // todo: table name should be configurable\n if (tableExist) return\n\n await queryRunner.createTable(\n new Table({\n database: this.queryResultCacheDatabase,\n schema: this.queryResultCacheSchema,\n name: this.queryResultCacheTable,\n columns: [\n {\n name: \"id\",\n isPrimary: true,\n isNullable: false,\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheId,\n }),\n generationStrategy:\n driver.options.type === \"spanner\"\n ? \"uuid\"\n : \"increment\",\n isGenerated: true,\n },\n {\n name: \"identifier\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheIdentifier,\n }),\n isNullable: true,\n },\n {\n name: \"time\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheTime,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"duration\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheDuration,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"query\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheQuery,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"result\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheResult,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n queryRunner = this.getQueryRunner(queryRunner)\n const qb = this.connection\n .createQueryBuilder(queryRunner)\n .select()\n .from(this.queryResultCacheTable, \"cache\")\n\n if (options.identifier) {\n return qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\n \"identifier\",\n )} = :identifier`,\n )\n .setParameters({\n identifier:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.identifier, \"nvarchar\")\n : options.identifier,\n })\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n } else if (options.query) {\n if (this.connection.driver.options.type === \"oracle\") {\n return qb\n .where(\n `dbms_lob.compare(${qb.escape(\"cache\")}.${qb.escape(\n \"query\",\n )}, :query) = 0`,\n { query: options.query },\n )\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n }\n\n return qb\n .where(`${qb.escape(\"cache\")}.${qb.escape(\"query\")} = :query`)\n .setParameters({\n query:\n this.connection.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.query, \"nvarchar\")\n : options.query,\n })\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n }\n\n return Promise.resolve(undefined)\n }\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n const duration =\n typeof savedCache.duration === \"string\"\n ? parseInt(savedCache.duration)\n : savedCache.duration\n return (\n (typeof savedCache.time === \"string\"\n ? parseInt(savedCache.time as any)\n : savedCache.time)! +\n duration <\n new Date().getTime()\n )\n }\n\n /**\n * Stores given query result in the cache.\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const shouldCreateQueryRunner =\n queryRunner === undefined ||\n queryRunner?.getReplicationMode() === \"slave\"\n\n if (queryRunner === undefined || shouldCreateQueryRunner) {\n queryRunner = this.connection.createQueryRunner(\"master\")\n }\n\n let insertedValues: ObjectLiteral = options\n if (this.connection.driver.options.type === \"mssql\") {\n // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table\n insertedValues = {\n identifier: new MssqlParameter(options.identifier, \"nvarchar\"),\n time: new MssqlParameter(options.time, \"bigint\"),\n duration: new MssqlParameter(options.duration, \"int\"),\n query: new MssqlParameter(options.query, \"nvarchar\"),\n result: new MssqlParameter(options.result, \"nvarchar\"),\n }\n }\n\n if (savedCache && savedCache.identifier) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n qb.where(`${qb.escape(\"identifier\")} = :condition`, {\n condition: insertedValues.identifier,\n })\n await qb.execute()\n } else if (savedCache && savedCache.query) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n if (this.connection.driver.options.type === \"oracle\") {\n qb.where(`dbms_lob.compare(\"query\", :condition) = 0`, {\n condition: insertedValues.query,\n })\n } else {\n qb.where(`${qb.escape(\"query\")} = :condition`, {\n condition: insertedValues.query,\n })\n }\n\n await qb.execute()\n } else {\n // Spanner does not support auto-generated columns\n if (\n this.connection.driver.options.type === \"spanner\" &&\n !insertedValues.id\n ) {\n insertedValues.id = uuidv4()\n }\n\n // otherwise insert\n await queryRunner.manager\n .createQueryBuilder()\n .insert()\n .into(this.queryResultCacheTable)\n .values(insertedValues)\n .execute()\n }\n\n if (shouldCreateQueryRunner) {\n await queryRunner.release()\n }\n }\n\n /**\n * Clears everything stored in the cache.\n */\n async clear(queryRunner: QueryRunner): Promise<void> {\n return this.getQueryRunner(queryRunner).clearTable(\n this.queryResultCacheTable,\n )\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n let _queryRunner: QueryRunner = queryRunner || this.getQueryRunner()\n await Promise.all(\n identifiers.map((identifier) => {\n const qb = _queryRunner.manager.createQueryBuilder()\n return qb\n .delete()\n .from(this.queryResultCacheTable)\n .where(`${qb.escape(\"identifier\")} = :identifier`, {\n identifier,\n })\n .execute()\n }),\n )\n\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a query runner to work with.\n */\n protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner {\n if (queryRunner) return queryRunner\n\n return this.connection.createQueryRunner()\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -20,6 +20,7 @@ const TableExclusion_1 = require("../../schema-builder/table/TableExclusion");
|
|
|
20
20
|
const error_1 = require("../../error");
|
|
21
21
|
const MetadataTableType_1 = require("../types/MetadataTableType");
|
|
22
22
|
const InstanceChecker_1 = require("../../util/InstanceChecker");
|
|
23
|
+
const BroadcasterResult_1 = require("../../subscriber/BroadcasterResult");
|
|
23
24
|
const VersionUtils_1 = require("../../util/VersionUtils");
|
|
24
25
|
/**
|
|
25
26
|
* Runs queries on a single postgres database connection.
|
|
@@ -197,7 +198,9 @@ class CockroachQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
197
198
|
if (this.isReleased)
|
|
198
199
|
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
|
|
199
200
|
const databaseConnection = await this.connect();
|
|
201
|
+
const broadcasterResult = new BroadcasterResult_1.BroadcasterResult();
|
|
200
202
|
this.driver.connection.logger.logQuery(query, parameters, this);
|
|
203
|
+
this.broadcaster.broadcastBeforeQueryEvent(broadcasterResult, query, parameters);
|
|
201
204
|
const queryStartTime = +new Date();
|
|
202
205
|
if (this.isTransactionActive && this.storeQueries) {
|
|
203
206
|
this.queries.push({ query, parameters });
|
|
@@ -229,6 +232,7 @@ class CockroachQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
229
232
|
default:
|
|
230
233
|
result.raw = raw.rows;
|
|
231
234
|
}
|
|
235
|
+
this.broadcaster.broadcastAfterQueryEvent(broadcasterResult, query, parameters, true, queryExecutionTime, raw, undefined);
|
|
232
236
|
if (useStructuredResult) {
|
|
233
237
|
return result;
|
|
234
238
|
}
|
|
@@ -260,9 +264,13 @@ class CockroachQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
|
260
264
|
}
|
|
261
265
|
else {
|
|
262
266
|
this.driver.connection.logger.logQueryError(err, query, parameters, this);
|
|
267
|
+
this.broadcaster.broadcastAfterQueryEvent(broadcasterResult, query, parameters, false, undefined, undefined, err);
|
|
263
268
|
throw new QueryFailedError_1.QueryFailedError(query, parameters, err);
|
|
264
269
|
}
|
|
265
270
|
}
|
|
271
|
+
finally {
|
|
272
|
+
await broadcasterResult.wait();
|
|
273
|
+
}
|
|
266
274
|
}
|
|
267
275
|
/**
|
|
268
276
|
* Returns raw data stream.
|