@prisma-psm/pg 1.0.6 → 1.0.8

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 (47) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +2 -2
  3. package/src/index.ts +6 -4
  4. package/src/parser/backup/engine.d.ts.map +1 -1
  5. package/src/parser/backup/engine.js +36 -21
  6. package/src/parser/backup/engine.js.map +1 -1
  7. package/src/parser/backup/engine.ts +36 -16
  8. package/src/parser/notice.js +1 -1
  9. package/src/parser/notice.ts +2 -2
  10. package/src/parser/parser.d.ts +1 -0
  11. package/src/parser/parser.d.ts.map +1 -1
  12. package/src/parser/parser.js +3 -1
  13. package/src/parser/parser.js.map +1 -1
  14. package/src/parser/parser.ts +12 -2
  15. package/src/parser/schama.d.ts +3 -0
  16. package/src/parser/schama.d.ts.map +1 -0
  17. package/src/parser/schama.js +16 -0
  18. package/src/parser/schama.js.map +1 -0
  19. package/src/parser/schama.ts +14 -0
  20. package/src/parser/sql.d.ts.map +1 -1
  21. package/src/parser/sql.js +3 -0
  22. package/src/parser/sql.js.map +1 -1
  23. package/src/parser/sql.ts +7 -2
  24. package/src/parser/sys.js +2 -2
  25. package/src/parser/sys.ts +3 -3
  26. package/src/parser/table/engine.js +2 -2
  27. package/src/parser/table/engine.ts +3 -3
  28. package/src/sql/catalog-maps.d.ts +1 -0
  29. package/src/sql/catalog-maps.d.ts.map +1 -0
  30. package/src/sql/catalog-maps.js +283 -0
  31. package/src/sql/catalog-maps.js.map +1 -0
  32. package/src/sql/catalog-maps.ts +281 -0
  33. package/src/sql/sql-builder.d.ts +1 -0
  34. package/src/sql/sql-builder.d.ts.map +1 -0
  35. package/src/sql/sql-builder.js +256 -0
  36. package/src/sql/sql-builder.js.map +1 -0
  37. package/src/sql/sql-builder.ts +254 -0
  38. package/src/utils/escape.d.ts +5 -1
  39. package/src/utils/escape.d.ts.map +1 -1
  40. package/src/utils/escape.js +328 -4
  41. package/src/utils/escape.js.map +1 -1
  42. package/src/utils/escape.ts +331 -4
  43. package/src/utils/script-util.d.ts +26 -0
  44. package/src/utils/script-util.d.ts.map +1 -0
  45. package/src/utils/script-util.js +95 -0
  46. package/src/utils/script-util.js.map +1 -0
  47. package/src/utils/script-util.ts +105 -0
@@ -16,6 +16,7 @@ const RESERVED_WORDS = new Set([
16
16
 
17
17
  const IDENTIFIER_REGEX = /^[a-z_][a-z0-9_$]*$/i; // Regra para identificadores PostgreSQL
18
18
 
19
+
19
20
  export function oid(string: string): string {
20
21
  if (!string){
21
22
  throw new Error("Invalid Object identifier name!");
@@ -30,7 +31,333 @@ export function oid(string: string): string {
30
31
 
31
32
  return pg.escapeIdentifier(string);
32
33
  }
33
- export function val(string: string) {
34
- if (string === null || string === undefined) return 'null';
35
- return pg.escapeLiteral(string);
36
- }
34
+ export function lit(string: string, type?:string ) {
35
+ let _type = "";
36
+ if ( !!type && typeof type === "string" ) _type = `::${type}`;
37
+ if (string === null || string === undefined) return `null${_type}`;
38
+ return `${pg.escapeLiteral(string)}${_type}`;
39
+ }
40
+
41
+ export const VARCHAR="varchar";
42
+ export const TEXT="text";
43
+ export const DOUBLE="double precision";
44
+ export const NUMERIC="numeric";
45
+
46
+ //
47
+ // import PGDataType from "../sql/catalog-maps";
48
+ //
49
+
50
+ //
51
+ //
52
+ //
53
+
54
+ //
55
+ //
56
+ // export function ObjectArray <T>( value:{[p:string]:T}, callback:( key, value:T )=> void){
57
+ // if( !value ) return;
58
+ // Object.entries( value ).forEach( ([key, value ]) => {
59
+ // callback( key, value );
60
+ // })
61
+ // }
62
+ //
63
+ //
64
+ // export function literalArray( value:any, type:string, recursive?:boolean, recursiveSystanx?:boolean ):string {
65
+ // if( value === null || value === undefined ) return `null`;
66
+ // if( !Array.isArray( value ) ) throw new Error( `Value of ${ value?.toString?.() } is not array` );
67
+ // let cast = ( next:any )=>{
68
+ // let isArray:boolean;
69
+ // if( recursive && Array.isArray( next ) ){
70
+ // next = next.map( element => cast( element ) );
71
+ // isArray = true;
72
+ // } else if( recursive && !!next && typeof next === "object" && !Array.isArray( next ) ){
73
+ // ObjectArray( next, ( key, element ) => {
74
+ // next[ key ] = cast( element );
75
+ // });
76
+ // }
77
+ // let literal = JSON.stringify( next );
78
+ // if( recursive && recursiveSystanx && isArray ) literal = `{${literal.substring(1, literal.length-1 )}}`;
79
+ // return literal;
80
+ // }
81
+ //
82
+ // let result = cast( value );
83
+ // result = `{${result.substring(1, result.length-1 )}}`;
84
+ // return result;
85
+ // }
86
+ //
87
+ //
88
+ // export class Escape<S> {
89
+ // type:string;
90
+ // mode:"type"|"identifier"|"unsafe"|"keyword"|"literal";
91
+ // value:S;
92
+ // asArray:boolean
93
+ // variadic:boolean
94
+ // constructor(type: string, mode: "type" | "identifier" | "unsafe" | "keyword"|"literal", value: S, array:boolean, variadic:boolean ) {
95
+ // if( mode === "identifier" && !value ) throw new Error ( "Valor invalido para identifier");
96
+ // if( typeof value === "number" && Number.isNaN( value ) ) throw new Error( `Number values is NaN!` );
97
+ //
98
+ // this.type = type;
99
+ // this.mode = mode;
100
+ // this.value = value;
101
+ // this.asArray = array;
102
+ // this.variadic = variadic;
103
+ //
104
+ // try {
105
+ // JSON.stringify( this.value );
106
+ // } catch (e) {
107
+ // console.error( `Parse value error: Value`, this.value );
108
+ // throw e;
109
+ // }
110
+ // }
111
+ //
112
+ // literal(){
113
+ // if( this.mode === "unsafe" ) return this.value;
114
+ // if( this.mode === "keyword" ) return this.value;
115
+ // if( this.mode === "literal" ) return lit( this.value?.toString?.()||null );
116
+ //
117
+ // // console.log( "//Resolve nulls")
118
+ // if( this.value === null || this.value === undefined ) return `null`;
119
+ //
120
+ // // console.log( "//Resolve JSON arrays", this.asArray, this.type)
121
+ // if( this.asArray && [ "json", "jsonb" ].includes( this.type ) ) return literalArray( this.value, this.type, false, false );
122
+ //
123
+ // // console.log( "//Resolve arrays", this.asArray, this.type)
124
+ // if( this.asArray ) return literalArray( this.value, this.type, true, true );
125
+ //
126
+ // // console.log( "//Resolve numbers types")
127
+ // if( typeof this.value === "number" ) return `${ this.value }`;
128
+ //
129
+ // // console.log("//Resolve string")
130
+ // if( typeof this.value === "string" ) return this.value;
131
+ //
132
+ // // console.log( "//Resolve boolean")
133
+ // if( typeof this.value === "boolean" ) return `${Boolean(this.value)}`;
134
+ //
135
+ // // console.log("//Resolve other types")
136
+ // if( typeof this.value === "object" ) return JSON.stringify( this.value );
137
+ //
138
+ // throw new Error( `Valor não esperado para ser tratado ${ this.value } as type ${ this.type } in mode ${ this.mode }!` );
139
+ // }
140
+ // }
141
+ //
142
+ // export const TypeFamilyCollection = {
143
+ // UUID :[ "uuid" ] as const,
144
+ // Integer :[ "int2", "smallint", "int", "int4", "integer", "int8", "bigint" ] as const,
145
+ // Real :[ "double", "numeric", "float", "money" ] as const,
146
+ // Text :[ "varchar", "character varying", "text" ] as const,
147
+ // Document : [ "json", "jsonb" ] as const,
148
+ // DocumentArray : [ "json_array", "jsonb_array" ] as const,
149
+ // Time :[ "time", "timetz" ] as const,
150
+ // Date :[ "date" ] as const,
151
+ // DateTime :[ "timestamp", "timestamptz" ] as const,
152
+ // Boolean: [ "boolean", "bool" ] as const
153
+ // } as const;
154
+ //
155
+ // type EscapeMap = {
156
+ // [ K in typeof TypeFamilyCollection[keyof typeof TypeFamilyCollection ][number]&keyof PGDataType]:(
157
+ // args: PGDataType[K]|(PGDataType[K])[]
158
+ // ) => Escape<PGDataType[K]>
159
+ // } & {
160
+ // identifier( object:string):Escape<string>
161
+ // unsafe( expression:string):Escape<string>
162
+ // keyword( keyword:string):Escape<string>
163
+ // literal( keyword:string):Escape<string>
164
+ // any<T>( object:T ):Escape<T>
165
+ // anyOf<T>( object:T, format:string ):Escape<T>
166
+ // }
167
+ //
168
+ // let checkIsValidNumber=( arg )=>{
169
+ // if( arg === null ) return true;
170
+ // let num:number = Number( arg );
171
+ // return !Number.isNaN( num ) && Number.isFinite( num);
172
+ // }
173
+ //
174
+ //
175
+ // function transformValues( array, transform:( original )=> any ){
176
+ // return array.map( check => {
177
+ // if( check === undefined || check === null ) return null;
178
+ // if( Array.isArray( check ) ) return transformValues( check, transform );
179
+ // return transform(check);
180
+ // });
181
+ // }
182
+ //
183
+ // function hasInvalidValueInArray( array:any[], check:( arg )=> boolean ){
184
+ // return !!array.find(value => {
185
+ // if (value === null) return false;
186
+ // if (Array.isArray(value)) return hasInvalidValueInArray(value, check);
187
+ // let valid = check(value);
188
+ // return !valid;
189
+ // });
190
+ // }
191
+ //
192
+ // function createEscape( value, type, variadic, transform:( original )=>any, check:( arg )=> boolean ){
193
+ // if( value === null || value === undefined )
194
+ // return new Escape( type, "type", value, false, variadic );
195
+ // if( Array.isArray( value ) ){
196
+ // let array = transformValues( value, transform );
197
+ // if( hasInvalidValueInArray( array , check ) ) throw new Error( `Invalid scape value ${ value } ${type} in array` );
198
+ // return new Escape( type, "type", value, true, variadic );
199
+ // }
200
+ // let checked = transformValues([ value ], transform );
201
+ // if( hasInvalidValueInArray( checked, check ) ) throw new Error( `Invalid scape value ${ value } TO ${type}` );
202
+ // return new Escape( type, "type", checked[ 0 ], false, false );
203
+ // }
204
+ // export const SQL:EscapeMap= {} as any;
205
+ //
206
+ // [
207
+ // TypeFamilyCollection.Integer,
208
+ // TypeFamilyCollection.Real,
209
+ // ].forEach( collection => {
210
+ // collection.forEach( type => {
211
+ // SQL[ type ] = ( value, variadic )=>{
212
+ // return createEscape(value, type, variadic, original => Number(original), checkIsValidNumber);
213
+ // }
214
+ // });
215
+ // });
216
+ //
217
+ //
218
+ // [
219
+ // TypeFamilyCollection.Text,
220
+ // TypeFamilyCollection.UUID,
221
+ // ].forEach( collection => {
222
+ // collection.forEach( type => {
223
+ // SQL[ type ] = (( value, variadic )=>{
224
+ // return createEscape( value, type, variadic, original => original, arg => typeof arg === "string" );
225
+ // }) as any
226
+ // });
227
+ // });
228
+ //
229
+ //
230
+ //
231
+ // [
232
+ // TypeFamilyCollection.Document,
233
+ // ].forEach( collection => {
234
+ // collection.forEach( type => {
235
+ // SQL[ type ] = (( value, variadic )=>{
236
+ // let escape = createEscape( value, type, variadic, original => original, arg => true );
237
+ // escape.asArray = false;
238
+ // return escape;
239
+ // }) as any
240
+ //
241
+ // SQL[ `${type}_array` ] = (( value, variadic )=>{
242
+ // let escape = createEscape( value, type, variadic, original => original, arg => true );
243
+ // escape.asArray = true;
244
+ // return escape;
245
+ // }) as any
246
+ // });
247
+ // });
248
+ //
249
+ // [
250
+ // TypeFamilyCollection.Time,
251
+ // TypeFamilyCollection.Date,
252
+ // TypeFamilyCollection.DateTime
253
+ // ].forEach( collection => {
254
+ // collection.forEach( type => {
255
+ // SQL[ type ] = ( value, variadic )=>{
256
+ // return createEscape( value, type, variadic, original => original, arg => true );
257
+ // }
258
+ // });
259
+ // });
260
+ //
261
+ // [
262
+ // TypeFamilyCollection.Boolean
263
+ // ].forEach( collection => {
264
+ // collection.forEach( type => {
265
+ // SQL[ type ] =( ( value, variadic )=>{
266
+ // return createEscape( value, type, variadic, original => !!original, arg => true );
267
+ // }) as any
268
+ // });
269
+ // });
270
+ //
271
+ //
272
+ //
273
+ // export function anyNumber( value ){
274
+ // if( Number.isNaN( value ) ) return SQL.numeric( value );
275
+ // let _asReal = ()=>{
276
+ //
277
+ // /*
278
+ // //TODO reforçar outras validação para double precision|real|decimal
279
+ // decimal variable user-specified precision, exact up to 131072 digits before the decimal point; up to 16383 digits after the decimal point
280
+ // numeric variable user-specified precision, exact up to 131072 digits before the decimal point; up to 16383 digits after the decimal point
281
+ // real 4 bytes variable-precision, inexact 6 decimal digits precision
282
+ // double precision 8 bytes variable-precision, inexact 15 decimal digits precision
283
+ // */
284
+ // return SQL.numeric( value );
285
+ // }
286
+ // let _asInteger = ()=>{
287
+ // let _subtype:("numeric"|"integer"|"bigint") & keyof typeof SQL = "integer";
288
+ // /*
289
+ // //TODO reforçar outras validação para smallint|integer|bigint
290
+ // smallint 2 bytes small-range integer -32768 to +32767
291
+ // integer 4 bytes typical choice for integer -2147483648 to +2147483647
292
+ // bigint 8 bytes large-range integer -9223372036854775808 to 9223372036854775807
293
+ // */
294
+ //
295
+ // if( value >= -2147483648 && value <= +2147483647 ) _subtype = "integer";
296
+ // else if( value >= -9223372036854775808 && value <= 9223372036854775807 ) _subtype = "bigint";
297
+ // else _subtype = "numeric";
298
+ // // @ts-ignore
299
+ // return SQL[_subtype]( value );
300
+ // }
301
+ //
302
+ // let parts = `${ value }`.split(".");
303
+ // if( parts.length === 2 ) return _asReal()
304
+ // else return _asInteger();
305
+ //
306
+ // }
307
+ //
308
+ // export function anyObject( value:any ){
309
+ // if( Array.isArray( value ) ) {
310
+ // let _determineType = ( next:any[] )=>{
311
+ // let determined = next.map( element => {
312
+ // if( typeof element === "string" ) return "text";
313
+ // if( typeof element === "boolean" ) return "boolean";
314
+ // if( typeof element === "number" ) return "number";
315
+ // if( !element && typeof element === "object" && !Array.isArray( element ) ) return "jsonb";
316
+ // if( Array.isArray( element ) ) return _determineType( element );
317
+ // }).filter( determined => !!determined );
318
+ // if( determined.length ) return determined[0];
319
+ // return null;
320
+ // };
321
+ //
322
+ // let type = _determineType( value );
323
+ // if( !type ) type = "text";
324
+ // return SQL[type](value);
325
+ // } else return SQL.jsonb( value );
326
+ // }
327
+ //
328
+ //
329
+ //
330
+ // //Any Type Scape
331
+ // SQL["any"]=<T>( value:T )=>{
332
+ // if( value === null || value === undefined ) return SQL.text( value as string );
333
+ // if( typeof value === "string" ) return SQL.text( value );
334
+ // if( typeof value === "boolean" ) return SQL.boolean( value );
335
+ // if( typeof value === "number" ) return anyNumber( value );
336
+ // if( typeof value === "object" ) return anyObject( value );
337
+ // throw new Error( `Valor não esperado para ser tratado ${ value }!` );
338
+ // }
339
+ //
340
+ // //Any Type Scape
341
+ // SQL["anyOf"]=<T>( value:T, format:string )=>{
342
+ // let any = SQL.any( value );
343
+ // any.type = format;
344
+ // return any;
345
+ // }
346
+ //
347
+ //
348
+ // //Special Scape
349
+ // SQL["identifier"]=( value:string )=>{
350
+ // if( !value ) throw new Error( "Invalid Value for Identifier" );
351
+ // return new Escape( null, "identifier", value, false, false );
352
+ // }
353
+ //
354
+ // SQL["unsafe"]=( value:string )=>{
355
+ // return new Escape( null, "unsafe", value, false, false );
356
+ // }
357
+ //
358
+ // SQL["keyword"]=( value:string )=>{
359
+ // return new Escape( null, "keyword", value, false, false );
360
+ // }
361
+ // SQL["literal"]=( value:string )=>{
362
+ // return new Escape( null, "literal", value, false, false );
363
+ // }
@@ -0,0 +1,26 @@
1
+ export type ScriptLine = {
2
+ line: number;
3
+ filename: string;
4
+ error: Error;
5
+ column: number;
6
+ func: string;
7
+ };
8
+ export type TempScriptOptions = {
9
+ encoding?: BufferEncoding;
10
+ extension?: string;
11
+ prefix?: string;
12
+ suffix?: string;
13
+ noCreate?: boolean;
14
+ };
15
+ declare class TSUtil {
16
+ typescriptOf(filename: string): string;
17
+ private __lineOf;
18
+ javascriptLineOf(): ScriptLine;
19
+ private __tsLine;
20
+ typescriptLineOf(goBack?: number): ScriptLine;
21
+ lineOf(goBack?: number): ScriptLine;
22
+ urlOf(line: ScriptLine): string;
23
+ }
24
+ export declare const scriptUtil: TSUtil;
25
+ export {};
26
+ //# sourceMappingURL=script-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-util.d.ts","sourceRoot":"","sources":["script-util.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG;IACrB,IAAI,EAAC,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAC,KAAK,CAAC;IACZ,MAAM,EAAC,MAAM,CAAC;IACd,IAAI,EAAC,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC5B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,SAAS,CAAC,EAAC,MAAM,CAAC;IAClB,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,QAAQ,CAAC,EAAC,OAAO,CAAA;CACpB,CAAA;AAMD,cAAM,MAAM;IACR,YAAY,CAAE,QAAQ,EAAC,MAAM;IAK3B,OAAO,CAAC,QAAQ;IA4BhB,gBAAgB;IAEhB,OAAO,CAAC,QAAQ;IA4BhB,gBAAgB,CAAE,MAAM,CAAC,EAAC,MAAM,GAAG,UAAU;IAE7C,MAAM,CAAE,MAAM,CAAC,EAAC,MAAM,GAAG,UAAU;IAKrC,KAAK,CAAE,IAAI,EAAC,UAAU;CAOzB;AAED,eAAO,MAAM,UAAU,QAAe,CAAC"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.scriptUtil = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const REG_EXP_LINE_FUNCTION = /(.+?) \((.+?):(\d+):(\d+)\)/;
10
+ const REG_EXP_LINE_SIMPLE = /at (.+):(\d+):(\d+)/;
11
+ class TSUtil {
12
+ typescriptOf(filename) {
13
+ let basename = path_1.default.basename(filename, ".js");
14
+ let tsFile = path_1.default.join(path_1.default.dirname(filename), `${basename}.ts`);
15
+ if (fs_1.default.existsSync(tsFile))
16
+ return tsFile;
17
+ return null;
18
+ }
19
+ __lineOf(error, goBack) {
20
+ const stackLines = error.stack.split('\n')
21
+ .filter(value => REG_EXP_LINE_FUNCTION.test(value)
22
+ || REG_EXP_LINE_SIMPLE.test(value));
23
+ let line = stackLines[1 + (goBack || 0)];
24
+ if (!stackLines.length)
25
+ return;
26
+ if (!line)
27
+ return;
28
+ let filename, row, column, func;
29
+ let match = line.match(REG_EXP_LINE_FUNCTION);
30
+ if (match) {
31
+ [, func, filename, row, column] = match;
32
+ }
33
+ else {
34
+ match = REG_EXP_LINE_SIMPLE.exec(line);
35
+ [, filename, row, column] = match || [];
36
+ }
37
+ if (!match)
38
+ return null;
39
+ return {
40
+ error: error,
41
+ line: parseInt(row),
42
+ column: parseInt(column),
43
+ filename: filename,
44
+ func: func
45
+ };
46
+ }
47
+ javascriptLineOf() {
48
+ return this.__lineOf(new Error());
49
+ }
50
+ __tsLine(error, goBack) {
51
+ const sourceMapSupport = require('source-map-support');
52
+ let line = this.__lineOf(error, goBack);
53
+ let typescriptName = this.typescriptOf(line.filename);
54
+ const sourceMap = sourceMapSupport.retrieveSourceMap(line.filename);
55
+ if (!sourceMap && !!(line === null || line === void 0 ? void 0 : line.line) && !!line.filename && line.filename.endsWith(".ts"))
56
+ return { ts: line };
57
+ if (sourceMap) {
58
+ const sourceMapping = sourceMapSupport.mapSourcePosition({
59
+ line: line.line,
60
+ column: 0, // Normalmente, você pode manter a coluna como 0 para obter a coluna correspondente.
61
+ source: typescriptName // Substitua 'seuarquivo.ts' pelo nome correto do arquivo TypeScript.
62
+ });
63
+ return {
64
+ js: line,
65
+ ts: {
66
+ error: error,
67
+ line: sourceMapping.line,
68
+ column: 0,
69
+ func: null,
70
+ filename: typescriptName
71
+ }
72
+ };
73
+ }
74
+ return { js: line };
75
+ }
76
+ typescriptLineOf(goBack) {
77
+ var _a;
78
+ return (_a = this.__tsLine(new Error(), goBack)) === null || _a === void 0 ? void 0 : _a.ts;
79
+ }
80
+ lineOf(goBack) {
81
+ let line = this.__tsLine(new Error(), goBack);
82
+ if (line.ts)
83
+ return line.ts;
84
+ else if (line.js)
85
+ return line.js;
86
+ }
87
+ urlOf(line) {
88
+ let file = line.filename;
89
+ let _line = line.line;
90
+ let column = line.column;
91
+ return `${new URL(`file://${file}:${_line}:${column}`).href}`;
92
+ }
93
+ }
94
+ exports.scriptUtil = new TSUtil();
95
+ //# sourceMappingURL=script-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-util.js","sourceRoot":"","sources":["script-util.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AAkBpB,MAAM,qBAAqB,GAAG,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oBACC,KAAK,EAAC,KAAK;oBACX,IAAI,EAAE,aAAa,CAAC,IAAI;oBACxB,MAAM,EAAE,CAAC;oBACT,IAAI,EAAE,IAAI;oBACV,QAAQ,EAAE,cAAc;iBAC3B;aACJ,CAAA;QACL,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACxB,CAAC;IAAC,gBAAgB,CAAE,MAAc;;QAC9B,OAAO,MAAA,IAAI,CAAC,QAAQ,CAAE,IAAI,KAAK,EAAE,EAAE,MAAM,CAAC,0CAAE,EAAE,CAAC;IACnD,CAAC;IAAC,MAAM,CAAE,MAAc;QACpB,IAAI,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAE,IAAI,KAAK,EAAE,EAAE,MAAM,CAAE,CAAC;QAChD,IAAI,IAAI,CAAC,EAAE;YAAG,OAAO,IAAI,CAAC,EAAE,CAAC;aACxB,IAAI,IAAI,CAAC,EAAE;YAAG,OAAO,IAAI,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,KAAK,CAAE,IAAe;QAClB,IAAI,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;QACzB,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,OAAO,GAAI,IAAI,GAAG,CAAC,UAAU,IAAI,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC,CAAC,IAAK,EAAE,CAAC;IACpE,CAAC;CAEJ;AAEY,QAAA,UAAU,GAAG,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1,105 @@
1
+ import Path from "path";
2
+ import fs from "fs";
3
+
4
+ export type ScriptLine = {
5
+ line:number,
6
+ filename: string,
7
+ error:Error,
8
+ column:number,
9
+ func:string
10
+ }
11
+
12
+ export type TempScriptOptions = {
13
+ encoding?: BufferEncoding;
14
+ extension?:string,
15
+ prefix?:string,
16
+ suffix?:string,
17
+ noCreate?:boolean
18
+ }
19
+
20
+ const REG_EXP_LINE_FUNCTION = /(.+?) \((.+?):(\d+):(\d+)\)/;
21
+ const REG_EXP_LINE_SIMPLE = /at (.+):(\d+):(\d+)/;
22
+
23
+
24
+ class TSUtil {
25
+ typescriptOf( filename:string ){
26
+ let basename = Path.basename( filename, ".js" );
27
+ let tsFile = Path.join( Path.dirname( filename ), `${basename}.ts` );
28
+ if( fs.existsSync( tsFile ) ) return tsFile;
29
+ return null;
30
+ } private __lineOf( error:Error, goBack?:number ):ScriptLine{
31
+ const stackLines = error.stack.split('\n')
32
+ .filter(
33
+ value => REG_EXP_LINE_FUNCTION.test( value )
34
+ || REG_EXP_LINE_SIMPLE.test( value )
35
+ );
36
+
37
+ let line = stackLines[1 + (goBack||0)];
38
+ if( !stackLines.length ) return;
39
+ if( !line ) return;
40
+
41
+ let filename, row, column, func;
42
+ let match = line.match(REG_EXP_LINE_FUNCTION);
43
+ if ( match ) {
44
+ [, func, filename, row, column] = match;
45
+ } else {
46
+ match = REG_EXP_LINE_SIMPLE.exec(line);
47
+ [, filename, row, column ] = match||[];
48
+ }
49
+
50
+ if( !match ) return null;
51
+ return {
52
+ error: error,
53
+ line: parseInt( row ),
54
+ column: parseInt( column ),
55
+ filename: filename,
56
+ func: func
57
+ }
58
+ } javascriptLineOf(){
59
+ return this.__lineOf( new Error() );
60
+ } private __tsLine( error:Error, goBack:number ):{
61
+ ts?:ScriptLine,
62
+ js?:ScriptLine
63
+ }{
64
+ const sourceMapSupport = require( 'source-map-support' );
65
+ let line = this.__lineOf( error, goBack );
66
+ let typescriptName = this.typescriptOf( line.filename);
67
+ const sourceMap = sourceMapSupport.retrieveSourceMap( line.filename );
68
+ if( !sourceMap && !!line?.line && !!line.filename && line.filename.endsWith(".ts")) return { ts:line };
69
+
70
+ if (sourceMap) {
71
+ const sourceMapping = sourceMapSupport.mapSourcePosition({
72
+ line: line.line,
73
+ column: 0, // Normalmente, você pode manter a coluna como 0 para obter a coluna correspondente.
74
+ source: typescriptName // Substitua 'seuarquivo.ts' pelo nome correto do arquivo TypeScript.
75
+ });
76
+ return {
77
+ js: line,
78
+ ts:{
79
+ error:error,
80
+ line: sourceMapping.line,
81
+ column: 0,
82
+ func: null,
83
+ filename: typescriptName
84
+ }
85
+ }
86
+ }
87
+ return { js: line };
88
+ } typescriptLineOf( goBack?:number ):ScriptLine{
89
+ return this.__tsLine( new Error(), goBack)?.ts;
90
+ } lineOf( goBack?:number ):ScriptLine {
91
+ let line = this.__tsLine( new Error(), goBack );
92
+ if( line.ts ) return line.ts;
93
+ else if( line.js ) return line.js;
94
+ }
95
+ urlOf( line:ScriptLine ){
96
+ let file = line.filename;
97
+ let _line = line.line;
98
+ let column = line.column;
99
+ return `${ new URL(`file://${file}:${_line}:${column}`).href }`;
100
+ }
101
+
102
+ }
103
+
104
+ export const scriptUtil = new TSUtil();
105
+