@sentio/sdk 1.19.2 → 1.19.4
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/lib/core/aptos-processor.d.ts +19 -0
- package/lib/core/aptos-processor.js +59 -1
- package/lib/core/aptos-processor.js.map +1 -1
- package/lib/core/generic-processor.test.js +1 -1
- package/lib/core/generic-processor.test.js.map +1 -1
- package/lib/core/logger.d.ts +5 -2
- package/lib/core/logger.js +10 -4
- package/lib/core/logger.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +165 -163
- package/lib/gen/processor/protos/processor.js +455 -482
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/processor-runner.js +1 -1
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.d.ts +13 -7
- package/lib/service.js +102 -18
- package/lib/service.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +15 -15
- package/lib/testing/test-processor-server.js +9 -4
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/tests/erc20.test.js +1 -1
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/logger.test.js +1 -1
- package/lib/tests/logger.test.js.map +1 -1
- package/lib/utils/erc20.test.js +0 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/package.json +1 -1
- package/src/core/aptos-processor.ts +70 -0
- package/src/core/generic-processor.test.ts +1 -1
- package/src/core/logger.ts +12 -4
- package/src/gen/processor/protos/processor.ts +606 -650
- package/src/processor-runner.ts +1 -1
- package/src/service.ts +126 -34
- package/src/testing/test-processor-server.ts +27 -32
- package/src/tests/erc20.test.ts +1 -1
- package/src/tests/logger.test.ts +1 -1
- package/src/utils/erc20.test.ts +1 -4
|
@@ -6,14 +6,33 @@ declare type IndexConfigure = {
|
|
|
6
6
|
startSeqNumber: Long;
|
|
7
7
|
endSeqNumber?: Long;
|
|
8
8
|
};
|
|
9
|
+
export interface AptosEventFilter {
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AptosCallFilter {
|
|
13
|
+
function: string;
|
|
14
|
+
typeArguments: string[] | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare class AptosEventHandler {
|
|
17
|
+
filters: AptosEventFilter[];
|
|
18
|
+
handler: (event: any) => Promise<ProcessResult>;
|
|
19
|
+
}
|
|
20
|
+
export declare class AptosCallHandler {
|
|
21
|
+
filters: AptosCallFilter[];
|
|
22
|
+
handler: (func: any) => Promise<ProcessResult>;
|
|
23
|
+
}
|
|
9
24
|
export declare class AptosBaseProcessor {
|
|
10
25
|
transactionHanlder: (transaction: any, ctx: AptosContext) => void;
|
|
11
26
|
address: string;
|
|
12
27
|
name: string;
|
|
13
28
|
config: IndexConfigure;
|
|
29
|
+
eventHandlers: AptosEventHandler[];
|
|
30
|
+
callHandlers: AptosCallHandler[];
|
|
14
31
|
constructor(options: AptosBindOptions);
|
|
15
32
|
bind(options: AptosBindOptions): void;
|
|
16
33
|
onTransaction(handler: (transaction: any, ctx: AptosContext) => void): this;
|
|
34
|
+
onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]): void;
|
|
35
|
+
onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]): void;
|
|
17
36
|
handleTransaction(txn: any, slot: Long): ProcessResult | null;
|
|
18
37
|
isBind(): boolean;
|
|
19
38
|
startSlot(startSlot: Long | number): this;
|
|
@@ -3,14 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AptosBaseProcessor = void 0;
|
|
6
|
+
exports.AptosBaseProcessor = exports.AptosCallHandler = exports.AptosEventHandler = void 0;
|
|
7
7
|
const context_1 = require("./context");
|
|
8
8
|
const long_1 = __importDefault(require("long"));
|
|
9
|
+
class AptosEventHandler {
|
|
10
|
+
filters;
|
|
11
|
+
handler;
|
|
12
|
+
}
|
|
13
|
+
exports.AptosEventHandler = AptosEventHandler;
|
|
14
|
+
class AptosCallHandler {
|
|
15
|
+
filters;
|
|
16
|
+
handler;
|
|
17
|
+
}
|
|
18
|
+
exports.AptosCallHandler = AptosCallHandler;
|
|
9
19
|
class AptosBaseProcessor {
|
|
10
20
|
transactionHanlder;
|
|
11
21
|
address;
|
|
12
22
|
name;
|
|
13
23
|
config = { startSeqNumber: new long_1.default(0) };
|
|
24
|
+
eventHandlers = [];
|
|
25
|
+
callHandlers = [];
|
|
14
26
|
constructor(options) {
|
|
15
27
|
if (options) {
|
|
16
28
|
this.bind(options);
|
|
@@ -34,6 +46,52 @@ class AptosBaseProcessor {
|
|
|
34
46
|
this.transactionHanlder = handler;
|
|
35
47
|
return this;
|
|
36
48
|
}
|
|
49
|
+
onEvent(handler, filter) {
|
|
50
|
+
let _filters = [];
|
|
51
|
+
if (Array.isArray(filter)) {
|
|
52
|
+
_filters = filter;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
_filters.push(filter);
|
|
56
|
+
}
|
|
57
|
+
this.eventHandlers.push({
|
|
58
|
+
handler: async function (event) {
|
|
59
|
+
const ctx = new context_1.AptosContext(this.address, event.slot);
|
|
60
|
+
if (event) {
|
|
61
|
+
handler(event, ctx);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
gauges: ctx.gauges,
|
|
65
|
+
counters: ctx.counters,
|
|
66
|
+
logs: ctx.logs,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
filters: _filters,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
onCall(handler, filter) {
|
|
73
|
+
let _filters = [];
|
|
74
|
+
if (Array.isArray(filter)) {
|
|
75
|
+
_filters = filter;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
_filters.push(filter);
|
|
79
|
+
}
|
|
80
|
+
this.callHandlers.push({
|
|
81
|
+
handler: async function (call) {
|
|
82
|
+
const ctx = new context_1.AptosContext(this.address, call.slot);
|
|
83
|
+
if (call) {
|
|
84
|
+
handler(call, ctx);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
gauges: ctx.gauges,
|
|
88
|
+
counters: ctx.counters,
|
|
89
|
+
logs: ctx.logs,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
filters: _filters,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
37
95
|
handleTransaction(txn, slot) {
|
|
38
96
|
const ctx = new context_1.AptosContext(this.address, slot);
|
|
39
97
|
if (txn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/core/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAwC;AAExC,gDAAuB;
|
|
1
|
+
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/core/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAwC;AAExC,gDAAuB;AAevB,MAAa,iBAAiB;IAC5B,OAAO,CAAoB;IAC3B,OAAO,CAAwC;CAChD;AAHD,8CAGC;AAED,MAAa,gBAAgB;IAC3B,OAAO,CAAmB;IAC1B,OAAO,CAAuC;CAC/C;AAHD,4CAGC;AAED,MAAa,kBAAkB;IACtB,kBAAkB,CAA+C;IACxE,OAAO,CAAQ;IACf,IAAI,CAAQ;IACZ,MAAM,GAAmB,EAAE,cAAc,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACxD,aAAa,GAAwB,EAAE,CAAA;IACvC,YAAY,GAAuB,EAAE,CAAA;IAErC,YAAY,OAAyB;QACnC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,IAAI,CAAC,OAAyB;QAC5B,IAAI,CAAC,OAAO,GAAG,OAA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AA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAtHD,gDAsHC","sourcesContent":["import { AptosBindOptions } from './bind-options'\nimport { AptosContext } from './context'\nimport { ProcessResult } from '..'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport interface AptosEventFilter {\n type: string\n}\nexport interface AptosCallFilter {\n function: string\n typeArguments: string[] | undefined\n}\n\nexport class AptosEventHandler {\n filters: AptosEventFilter[]\n handler: (event: any) => Promise<ProcessResult>\n}\n\nexport class AptosCallHandler {\n filters: AptosCallFilter[]\n handler: (func: any) => Promise<ProcessResult>\n}\n\nexport class AptosBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: AptosContext) => void\n address: string\n name: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n eventHandlers: AptosEventHandler[] = []\n callHandlers: AptosCallHandler[] = []\n\n constructor(options: AptosBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n bind(options: AptosBindOptions) {\n this.address = options.address\n this.name = options.name || this.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n }\n\n public onTransaction(handler: (transaction: any, ctx: AptosContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.transactionHanlder = handler\n\n return this\n }\n\n public onEvent(handler: (event: any, ctx: AptosContext) => void, filter: AptosEventFilter | AptosEventFilter[]) {\n let _filters: AptosEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n this.eventHandlers.push({\n handler: async function (event) {\n const ctx = new AptosContext(this.address, event.slot)\n if (event) {\n handler(event, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n }\n\n public onCall(handler: (func: any, ctx: AptosContext) => void, filter: AptosCallFilter | AptosCallFilter[]) {\n let _filters: AptosCallFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n this.callHandlers.push({\n handler: async function (call) {\n const ctx = new AptosContext(this.address, call.slot)\n if (call) {\n handler(call, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n filters: _filters,\n })\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new AptosContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
|
|
@@ -32,7 +32,7 @@ describe('Test Generic Processor', () => {
|
|
|
32
32
|
const counters = res.result?.counters;
|
|
33
33
|
(0, chai_1.expect)(counters).length(2);
|
|
34
34
|
(0, chai_1.expect)((0, testing_1.firstCounterValue)(res.result, 'event_num')).equals(1n);
|
|
35
|
-
(0, chai_1.expect)(counters?.[0].runtimeInfo?.from).equals(__1.HandlerType.
|
|
35
|
+
(0, chai_1.expect)(counters?.[0].runtimeInfo?.from).equals(__1.HandlerType.ETH_LOG);
|
|
36
36
|
});
|
|
37
37
|
test('Check log dispatch no buffer over rune', async () => {
|
|
38
38
|
const logStr = '{"address":"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f","topics":["0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081"],"data":"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24","blockNumber":"0xc9d6d7","transactionHash":"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2","transactionIndex":"0xf3","blockHash":"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6","logIndex":"0x14b","removed":false}';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic-processor.test.js","sourceRoot":"","sources":["../../src/core/generic-processor.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,0BAAgC;AAEhC,2DAAsD;AACtD,wCAAmE;AAEnE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAI,6BAAmB,CAAC,GAAG,EAAE;QAC3C,oCAAgB,CAAC,IAAI,CACnB;YACE,yEAAyE;YACzE,yEAAyE;SAC1E,EACD,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAC1D,CAAC,WAAW,CAAC,UAAU,GAAG,EAAE,GAAG;YAC9B,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;QAEF,oCAAgB,CAAC,IAAI,CAAC,oDAAoD,EAAE;YAC1E,OAAO,EAAE,4CAA4C;SACtD,CAAC,CAAC,WAAW,CAAC,UAAU,GAAG,EAAE,GAAG;YAC/B,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC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O,EAAE,OAAO,CAAC,CAAC,CAAA;QACtD,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAA;QACrC,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAC1B,IAAA,aAAM,EAAC,IAAA,2BAAiB,EAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC7D,IAAA,aAAM,EAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,eAAW,CAAC,OAAO,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,MAAM,GACV,ohBAAohB,CAAA;QACthB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACrD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,oEAAoE;QAC/E,gBAAgB,EAAE,GAAG;QACrB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,4CAA4C;QACrD,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE;YACN,oEAAoE;YACpE,oEAAoE;YACpE,oEAAoE;SACrE;QACD,eAAe,EAAE,oEAAoE;QACrF,QAAQ,EAAE,GAAG;KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { GenericProcessor } from './generic-processor'\nimport { TestProcessorServer, firstCounterValue } from '../testing'\n\ndescribe('Test Generic Processor', () => {\n const service = new TestProcessorServer(() => {\n GenericProcessor.bind(\n [\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed from, address indexed to, uint256 value)',\n ],\n { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }\n ).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('event_num').add(1)\n })\n\n GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {\n address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',\n }).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('wallet').add(1)\n })\n })\n\n beforeAll(async () => {\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[0].contract?.name).equals('Generic')\n })\n\n test('Check log dispatch', async () => {\n const res = await service.testLogs([logData, logData])\n const counters = res.result?.counters\n expect(counters).length(2)\n expect(firstCounterValue(res.result, 'event_num')).equals(1n)\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.ETH_LOG)\n })\n\n test('Check log dispatch no buffer over rune', async () => {\n const logStr =\n '{\"address\":\"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f\",\"topics\":[\"0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081\"],\"data\":\"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24\",\"blockNumber\":\"0xc9d6d7\",\"transactionHash\":\"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2\",\"transactionIndex\":\"0xf3\",\"blockHash\":\"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6\",\"logIndex\":\"0x14b\",\"removed\":false}'\n const res = await service.testLog(JSON.parse(logStr))\n console.log(JSON.stringify(res))\n })\n\n const logData = {\n blockNumber: 14213252,\n blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',\n transactionIndex: 347,\n removed: false,\n address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',\n data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n '0x0000000000000000000000000000000000000000000000000000000000000000',\n '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',\n ],\n transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',\n logIndex: 428,\n }\n})\n"]}
|
package/lib/core/logger.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { BaseContext } from './context';
|
|
2
2
|
import { Labels } from './metadata';
|
|
3
3
|
import { LogLevel } from '@sentio/sdk';
|
|
4
|
+
export declare type Attributes = Record<string, any>;
|
|
4
5
|
export declare class Logger {
|
|
5
6
|
private readonly ctx;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
private readonly name;
|
|
8
|
+
constructor(ctx: BaseContext, name?: string);
|
|
9
|
+
withName(name: string): Logger;
|
|
10
|
+
log(level: LogLevel, message: any, attributes?: Attributes): void;
|
|
8
11
|
info(msg: any, labels?: Labels): void;
|
|
9
12
|
warn(msg: any, labels?: Labels): void;
|
|
10
13
|
error(msg: any, labels?: Labels): void;
|
package/lib/core/logger.js
CHANGED
|
@@ -5,18 +5,24 @@ const metadata_1 = require("./metadata");
|
|
|
5
5
|
const sdk_1 = require("@sentio/sdk");
|
|
6
6
|
class Logger {
|
|
7
7
|
ctx;
|
|
8
|
-
|
|
8
|
+
name;
|
|
9
|
+
constructor(ctx, name = '') {
|
|
9
10
|
this.ctx = ctx;
|
|
11
|
+
this.name = name;
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
withName(name) {
|
|
14
|
+
return new Logger(this.ctx, name);
|
|
15
|
+
}
|
|
16
|
+
log(level, message, attributes = {}) {
|
|
13
17
|
if (typeof message !== 'string' && !(message instanceof String)) {
|
|
14
18
|
message = message.toString();
|
|
15
19
|
}
|
|
16
20
|
this.ctx.logs.push({
|
|
17
|
-
|
|
21
|
+
name: this.name,
|
|
22
|
+
metadata: (0, metadata_1.GetRecordMetaData)(this.ctx, undefined, {}),
|
|
18
23
|
level,
|
|
19
24
|
message,
|
|
25
|
+
attributes: JSON.stringify(attributes),
|
|
20
26
|
runtimeInfo: undefined,
|
|
21
27
|
});
|
|
22
28
|
}
|
package/lib/core/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,yCAAsD;AACtD,qCAAsC;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,yCAAsD;AACtD,qCAAsC;AAItC,MAAa,MAAM;IACA,GAAG,CAAa;IAChB,IAAI,CAAQ;IAE7B,YAAY,GAAgB,EAAE,IAAI,GAAG,EAAE;QACrC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAe,EAAE,OAAY,EAAE,aAAyB,EAAE;QAC5D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,YAAY,MAAM,CAAC,EAAE;YAC/D,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;SAC7B;QAED,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAA,4BAAiB,EAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC;YACpD,KAAK;YACL,OAAO;YACP,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;YACtC,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,SAAiB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,SAAiB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,GAAQ,EAAE,SAAiB,EAAE;QACjC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACvC,CAAC;IAED,QAAQ,CAAC,GAAQ,EAAE,SAAiB,EAAE;QACpC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;CACF;AA3CD,wBA2CC","sourcesContent":["import { BaseContext } from './context'\nimport { Labels, GetRecordMetaData } from './metadata'\nimport { LogLevel } from '@sentio/sdk'\n\nexport type Attributes = Record<string, any>\n\nexport class Logger {\n private readonly ctx: BaseContext\n private readonly name: string\n\n constructor(ctx: BaseContext, name = '') {\n this.ctx = ctx\n this.name = name\n }\n\n withName(name: string) {\n return new Logger(this.ctx, name)\n }\n\n log(level: LogLevel, message: any, attributes: Attributes = {}) {\n if (typeof message !== 'string' && !(message instanceof String)) {\n message = message.toString()\n }\n\n this.ctx.logs.push({\n name: this.name,\n metadata: GetRecordMetaData(this.ctx, undefined, {}),\n level,\n message,\n attributes: JSON.stringify(attributes),\n runtimeInfo: undefined,\n })\n }\n\n info(msg: any, labels: Labels = {}) {\n this.log(LogLevel.INFO, msg, labels)\n }\n\n warn(msg: any, labels: Labels = {}) {\n this.log(LogLevel.WARNING, msg, labels)\n }\n\n error(msg: any, labels: Labels = {}) {\n this.log(LogLevel.ERROR, msg, labels)\n }\n\n critical(msg: any, labels: Labels = {}) {\n this.log(LogLevel.CRITICAL, msg, labels)\n }\n}\n"]}
|