speed 1.1.2 → 1.1.7

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/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## SpeedSQL
2
+
3
+ SQL injection for NestJS, similar mybatis.
4
+
1
5
  ### Introduction
2
6
 
3
7
  - Follow NestJS Module injection mode.
@@ -7,6 +11,20 @@
7
11
  - Support for Entity Injection.
8
12
  - Support the Connection pools by mysql2 within.
9
13
 
14
+ ### Support Decorators
15
+
16
+ `@Param`, `@ResultType`, `@Select`, `@Insert`, `@Update`, `@Delete`.
17
+
18
+ ### Install as a dependency
19
+
20
+ Setup SpeedSQL (NPM named `speed`) as dependency in *package.json* file `dependencies`
21
+
22
+ ```
23
+ "dependencies": {
24
+ "speed": "latest"
25
+ }
26
+ ```
27
+
10
28
  ### Quick Start
11
29
 
12
30
  - Prepare some entities and configurations.
@@ -109,7 +127,6 @@ export class AppController {
109
127
 
110
128
  @Get()
111
129
  async getHello() {
112
- //const word = await this.appService.getMyWord(new ParamDto('world', 20));
113
130
  await this.appService.setUserAge("zzz", 20);
114
131
  return "hello world";
115
132
  }
@@ -173,6 +190,8 @@ export class AppModule {}
173
190
 
174
191
  ### Parameter with named (for Prepared Statements)
175
192
 
193
+ `@Param` define the named parameters.
194
+
176
195
  As with MyBatis, SpeedSQL is possible to pass a value to a bind parameter as a named parameter to ensure readability and prevent SQL Injection attacks.
177
196
 
178
197
  Unlike [Prepared Statements](https://github.com/sidorares/node-mysql2#using-prepared-statements) in mysql2, SpeedSQL can be pass param value with named to make SQL more clearer.
@@ -228,11 +247,13 @@ So we can start to use.
228
247
  const users: UserDto[] = await this.appService.getRecords('zzz', 10);
229
248
  ```
230
249
 
231
- ### Select
250
+ ### @Select
251
+
252
+ SpeedSQL uses ```@ResultType``` to annotate the resulting entity.
232
253
 
233
- SpeedSQL uses ```@resultType``` to annotate the resulting entity.
254
+ `@ResultType` define the data entity for @Selete returns.
234
255
 
235
- Select returns an array of annotated entity (```@resultType```).
256
+ Select returns an array of annotated entity (```@ResultType```).
236
257
 
237
258
  - Create a entity:
238
259
 
@@ -264,7 +285,7 @@ getRecords(@Param('uid') uid:number, @Param('name') name:string): UserDto[] {ret
264
285
  ```
265
286
 
266
287
 
267
- ### Insert
288
+ ### @Insert
268
289
 
269
290
  Parameter with named is also supported in ```@Insert```.
270
291
 
@@ -277,7 +298,7 @@ import { Insert } from 'speed';
277
298
  addUser(user: UserDto): number {return;}
278
299
  ```
279
300
 
280
- ### Update and Delete
301
+ ### @Update and @Delete
281
302
 
282
303
  Parameter with named is also supported in ```@Update``` and ```@Delete```.
283
304
 
package/index.js CHANGED
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- __export(require("./speed.decorator"));
6
- __export(require("./speed.service"));
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./speed.decorator"), exports);
14
+ __exportStar(require("./speed.service"), exports);
15
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;AAAA,uCAAkC;AAClC,qCAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "speed",
3
- "version": "1.1.2",
4
- "description": "SQL injection for nestjs, like mybatis.",
3
+ "version": "1.1.7",
4
+ "description": "SQL injection for NestJS, similar mybatis.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
7
7
  "repository": {
@@ -1,57 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t;
12
- return { next: verb(0), "throw": verb(1), "return": verb(2) };
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [0, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var speed_service_1 = require("./speed.service");
38
- var paramMetadataKey = Symbol('param');
39
- function log(message) {
40
- var optionalParams = [];
41
- for (var _i = 1; _i < arguments.length; _i++) {
42
- optionalParams[_i - 1] = arguments[_i];
43
- }
44
- console.log.apply(console, [message].concat(optionalParams));
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Delete = exports.Update = exports.Insert = exports.Select = exports.ResultType = exports.Param = exports.log = void 0;
4
+ const speed_service_1 = require("./speed.service");
5
+ const paramMetadataKey = Symbol('param');
6
+ function log(message, ...optionalParams) {
7
+ console.log(message, ...optionalParams);
45
8
  }
46
9
  exports.log = log;
47
10
  function ResultType(constructorFunction) {
48
- var newConstructorFunction = function () {
49
- var args = [];
50
- for (var _i = 0; _i < arguments.length; _i++) {
51
- args[_i] = arguments[_i];
52
- }
53
- var func = function () {
54
- return new (constructorFunction.bind.apply(constructorFunction, [void 0].concat(args)))();
11
+ const newConstructorFunction = function (...args) {
12
+ const func = function () {
13
+ return new constructorFunction(...args);
55
14
  };
56
15
  func.prototype = constructorFunction.prototype;
57
16
  return new func();
@@ -59,103 +18,62 @@ function ResultType(constructorFunction) {
59
18
  newConstructorFunction.prototype = constructorFunction.prototype;
60
19
  return function (target, propertyKey) {
61
20
  speed_service_1.resultTypeMap.set([target.constructor.name, propertyKey].toString(), newConstructorFunction());
62
- //never return
63
21
  };
64
22
  }
65
23
  exports.ResultType = ResultType;
66
24
  function Param(name) {
67
25
  return function (target, propertyKey, parameterIndex) {
68
- var existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey) || [];
26
+ const existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey) || [];
69
27
  existingParameters.push([name, parameterIndex]);
70
28
  Reflect.defineMetadata(paramMetadataKey, existingParameters, target, propertyKey);
71
29
  };
72
30
  }
73
31
  exports.Param = Param;
74
32
  function convertSQLParams(args, target, propertyKey, decoratorSQL) {
75
- var queryValues = [];
76
- var argsVal;
33
+ const queryValues = [];
34
+ let argsVal;
77
35
  if (typeof args[0] === 'object') {
78
- argsVal = new Map(Object.getOwnPropertyNames(args[0]).map(function (valName) { return [
36
+ argsVal = new Map(Object.getOwnPropertyNames(args[0]).map((valName) => [
79
37
  valName,
80
38
  args[0][valName],
81
- ]; }));
39
+ ]));
82
40
  }
83
41
  else {
84
- var existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey);
85
- argsVal = new Map(existingParameters.map(function (_a) {
86
- var argName = _a[0], argIdx = _a[1];
87
- return [argName, args[argIdx]];
88
- }));
42
+ const existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey);
43
+ argsVal = new Map(existingParameters.map(([argName, argIdx]) => [argName, args[argIdx]]));
89
44
  }
90
- var regExp = /#{(\w+)}/g;
91
- decoratorSQL.matchAll(regExp).slice().forEach(function (match) {
92
- var replaceTag = match[0], matchName = match[1];
45
+ const regExp = /#{(\w+)}/;
46
+ let match;
47
+ while (match = regExp.exec(decoratorSQL)) {
48
+ const [replaceTag, matchName] = match;
93
49
  decoratorSQL = decoratorSQL.replace(new RegExp(replaceTag, 'g'), '?');
94
50
  queryValues.push(argsVal.get(matchName));
95
- });
51
+ }
96
52
  return [decoratorSQL, queryValues];
97
53
  }
98
- function queryForExecute(sql, args, target, propertyKey) {
99
- return __awaiter(this, void 0, void 0, function () {
100
- var sqlValues, newSql, result, _a;
101
- return __generator(this, function (_b) {
102
- switch (_b.label) {
103
- case 0:
104
- sqlValues = [];
105
- newSql = sql;
106
- if (args.length > 0) {
107
- _a = convertSQLParams(args, target, propertyKey, sql), newSql = _a[0], sqlValues = _a[1];
108
- }
109
- return [4 /*yield*/, speed_service_1.speedPromisePool.query(newSql, sqlValues)];
110
- case 1:
111
- result = (_b.sent())[0];
112
- return [2 /*return*/, result];
113
- }
114
- });
115
- });
54
+ async function queryForExecute(sql, args, target, propertyKey) {
55
+ let sqlValues = [];
56
+ let newSql = sql;
57
+ if (args.length > 0) {
58
+ [newSql, sqlValues] = convertSQLParams(args, target, propertyKey, sql);
59
+ }
60
+ const [result] = await speed_service_1.speedPromisePool.query(newSql, sqlValues);
61
+ return result;
116
62
  }
117
63
  function Insert(sql) {
118
64
  return function (target, propertyKey, descriptor) {
119
- var _this = this;
120
- descriptor.value = function () {
121
- var args = [];
122
- for (var _i = 0; _i < arguments.length; _i++) {
123
- args[_i] = arguments[_i];
124
- }
125
- return __awaiter(_this, void 0, void 0, function () {
126
- var result;
127
- return __generator(this, function (_a) {
128
- switch (_a.label) {
129
- case 0: return [4 /*yield*/, queryForExecute(sql, args, target, propertyKey)];
130
- case 1:
131
- result = _a.sent();
132
- return [2 /*return*/, result.insertId];
133
- }
134
- });
135
- });
65
+ descriptor.value = async (...args) => {
66
+ const result = await queryForExecute(sql, args, target, propertyKey);
67
+ return result.insertId;
136
68
  };
137
69
  };
138
70
  }
139
71
  exports.Insert = Insert;
140
72
  function Update(sql) {
141
73
  return function (target, propertyKey, descriptor) {
142
- var _this = this;
143
- descriptor.value = function () {
144
- var args = [];
145
- for (var _i = 0; _i < arguments.length; _i++) {
146
- args[_i] = arguments[_i];
147
- }
148
- return __awaiter(_this, void 0, void 0, function () {
149
- var result;
150
- return __generator(this, function (_a) {
151
- switch (_a.label) {
152
- case 0: return [4 /*yield*/, queryForExecute(sql, args, target, propertyKey)];
153
- case 1:
154
- result = _a.sent();
155
- return [2 /*return*/, result.affectedRows];
156
- }
157
- });
158
- });
74
+ descriptor.value = async (...args) => {
75
+ const result = await queryForExecute(sql, args, target, propertyKey);
76
+ return result.affectedRows;
159
77
  };
160
78
  };
161
79
  }
@@ -163,46 +81,29 @@ exports.Update = Update;
163
81
  exports.Delete = Update;
164
82
  function Select(sql) {
165
83
  return function (target, propertyKey, descriptor) {
166
- var _this = this;
167
- descriptor.value = function () {
168
- var args = [];
169
- for (var _i = 0; _i < arguments.length; _i++) {
170
- args[_i] = arguments[_i];
84
+ descriptor.value = async (...args) => {
85
+ let sqlValues = [];
86
+ if (args.length > 0) {
87
+ [sql, sqlValues] = convertSQLParams(args, target, propertyKey, sql);
88
+ }
89
+ const [rows] = await speed_service_1.speedPromisePool.query(sql, sqlValues);
90
+ if (Object.keys(rows).length === 0) {
91
+ return;
171
92
  }
172
- return __awaiter(_this, void 0, void 0, function () {
173
- var sqlValues, rows, records, resultType, _loop_1, rowIndex, _a;
174
- return __generator(this, function (_b) {
175
- switch (_b.label) {
176
- case 0:
177
- sqlValues = [];
178
- if (args.length > 0) {
179
- _a = convertSQLParams(args, target, propertyKey, sql), sql = _a[0], sqlValues = _a[1];
180
- }
181
- return [4 /*yield*/, speed_service_1.speedPromisePool.query(sql, sqlValues)];
182
- case 1:
183
- rows = (_b.sent())[0];
184
- if (Object.keys(rows).length === 0) {
185
- return [2 /*return*/];
186
- }
187
- records = [];
188
- resultType = speed_service_1.resultTypeMap.get([target.constructor.name, propertyKey].toString());
189
- _loop_1 = function (rowIndex) {
190
- var entity = Object.create(resultType);
191
- Object.getOwnPropertyNames(resultType).forEach(function (propertyRow) {
192
- if (rows[rowIndex].hasOwnProperty(propertyRow)) {
193
- Object.defineProperty(entity, propertyRow, Object.getOwnPropertyDescriptor(rows[rowIndex], propertyRow));
194
- }
195
- });
196
- records.push(entity);
197
- };
198
- for (rowIndex in rows) {
199
- _loop_1(rowIndex);
200
- }
201
- return [2 /*return*/, records];
93
+ const records = [];
94
+ const resultType = speed_service_1.resultTypeMap.get([target.constructor.name, propertyKey].toString());
95
+ for (const rowIndex in rows) {
96
+ const entity = Object.create(resultType);
97
+ Object.getOwnPropertyNames(resultType).forEach(function (propertyRow) {
98
+ if (rows[rowIndex].hasOwnProperty(propertyRow)) {
99
+ Object.defineProperty(entity, propertyRow, Object.getOwnPropertyDescriptor(rows[rowIndex], propertyRow));
202
100
  }
203
101
  });
204
- });
102
+ records.push(entity);
103
+ }
104
+ return records;
205
105
  };
206
106
  };
207
107
  }
208
108
  exports.Select = Select;
109
+ //# sourceMappingURL=speed.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"speed.decorator.js","sourceRoot":"","sources":["speed.decorator.ts"],"names":[],"mappings":";AAAA,mDAAkE;AAGlE,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAEzC,aAAa,OAAa,EAAE,GAAG,cAAqB;IAClD,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC1C,CAAC;AAgKQ,kBAAG;AA9JZ,oBAAoB,mBAAmB;IACrC,MAAM,sBAAsB,GAAQ,UAAU,GAAG,IAAI;QACnD,MAAM,IAAI,GAAQ;YAChB,MAAM,CAAC,IAAI,mBAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC;QAC/C,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;IACpB,CAAC,CAAC;IACF,sBAAsB,CAAC,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC;IACjE,MAAM,CAAC,UAAU,MAAM,EAAE,WAAmB;QAC1C,6BAAa,CAAC,GAAG,CACb,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,QAAQ,EAAE,EACjD,sBAAsB,EAAE,CAC3B,CAAC;IAEJ,CAAC,CAAC;AACJ,CAAC;AA8IoB,gCAAU;AA5I/B,eAAe,IAAY;IACzB,MAAM,CAAC,UACH,MAAW,EACX,WAA4B,EAC5B,cAAsB;QAExB,MAAM,kBAAkB,GACpB,OAAO,CAAC,cAAc,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC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AO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACtB;YACD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAEgC,wBAAM"}
@@ -68,12 +68,18 @@ function convertSQLParams(
68
68
  existingParameters.map(([argName, argIdx]) => [argName, args[argIdx]]),
69
69
  );
70
70
  }
71
- const regExp = /#{(\w+)}/g;
72
- [...decoratorSQL.matchAll(regExp)].forEach((match) => {
71
+ const regExp = /#{(\w+)}/;
72
+ let match;
73
+ while(match = regExp.exec(decoratorSQL)){
73
74
  const [replaceTag, matchName] = match;
74
75
  decoratorSQL = decoratorSQL.replace(new RegExp(replaceTag, 'g'), '?');
75
76
  queryValues.push(argsVal.get(matchName));
76
- });
77
+ }
78
+ // [...decoratorSQL.matchAll(regExp)].forEach((match) => {
79
+ // const [replaceTag, matchName] = match;
80
+ // decoratorSQL = decoratorSQL.replace(new RegExp(replaceTag, 'g'), '?');
81
+ // queryValues.push(argsVal.get(matchName));
82
+ // });
77
83
  return [decoratorSQL, queryValues];
78
84
  }
79
85
 
package/speed.service.js CHANGED
@@ -5,25 +5,33 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  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;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
8
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
9
12
  return function (target, key) { decorator(target, key, paramIndex); }
10
13
  };
11
- var common_1 = require("@nestjs/common");
12
- var mysql2_1 = require("mysql2");
13
- exports.createPool = mysql2_1.createPool;
14
- var speedPromisePool;
14
+ var _a;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Pool = exports.createPool = exports.resultTypeMap = exports.speedPromisePool = exports.SpeedService = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const mysql2_1 = require("mysql2");
19
+ Object.defineProperty(exports, "Pool", { enumerable: true, get: function () { return mysql2_1.Pool; } });
20
+ Object.defineProperty(exports, "createPool", { enumerable: true, get: function () { return mysql2_1.createPool; } });
21
+ let speedPromisePool;
15
22
  exports.speedPromisePool = speedPromisePool;
16
- var resultTypeMap = new Map();
23
+ const resultTypeMap = new Map();
17
24
  exports.resultTypeMap = resultTypeMap;
18
- var SpeedService = (function () {
19
- function SpeedService(pool) {
25
+ let SpeedService = class SpeedService {
26
+ constructor(pool) {
20
27
  this.pool = pool;
21
28
  exports.speedPromisePool = speedPromisePool = pool.promise();
22
29
  }
23
- return SpeedService;
24
- }());
30
+ };
25
31
  SpeedService = __decorate([
26
- common_1.Injectable(),
27
- __param(0, common_1.Inject('SPEED_POOL'))
32
+ (0, common_1.Injectable)(),
33
+ __param(0, (0, common_1.Inject)('SPEED_POOL')),
34
+ __metadata("design:paramtypes", [typeof (_a = typeof mysql2_1.Pool !== "undefined" && mysql2_1.Pool) === "function" ? _a : Object])
28
35
  ], SpeedService);
29
36
  exports.SpeedService = SpeedService;
37
+ //# sourceMappingURL=speed.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"speed.service.js","sourceRoot":"","sources":["speed.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,mCAA0C;AAYA,yCAAU;AATpD,IAAI,gBAA6B,CAAC;AASzB,4CAAgB;AARzB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAe,CAAC;AAQlB,sCAAa;AALxC,IAAa,YAAY,GAAzB;IACI,YAA0C,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAChD,2BAAA,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IACtC,CAAC;CACJ,CAAA;AAJY,YAAY;IADxB,mBAAU,EAAE;IAEI,WAAA,eAAM,CAAC,YAAY,CAAC,CAAA;;GADxB,YAAY,CAIxB;AAJY,oCAAY"}
1
+ {"version":3,"file":"speed.service.js","sourceRoot":"","sources":["speed.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,mCAA0C;AAYY,qFAZ7C,aAAI,OAY6C;AAAhB,2FAZ3B,mBAAU,OAY2B;AATpD,IAAI,gBAA6B,CAAC;AASzB,4CAAgB;AARzB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAe,CAAC;AAQlB,sCAAa;AALxC,IAAa,YAAY,GAAzB,MAAa,YAAY;IACrB,YAA0C,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAChD,2BAAA,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IACtC,CAAC;CACJ,CAAA;AAJY,YAAY;IADxB,IAAA,mBAAU,GAAE;IAEI,WAAA,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;yDAAe,aAAI,oBAAJ,aAAI;GAD3C,YAAY,CAIxB;AAJY,oCAAY"}