@hocuspocus/extension-logger 1.0.0-alpha.49 → 1.0.0-alpha.53
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/dist/demos/backend/src/{create-document.d.ts → load-document.d.ts} +0 -0
- package/dist/hocuspocus-logger.cjs +87 -12
- package/dist/hocuspocus-logger.cjs.map +1 -1
- package/dist/hocuspocus-logger.esm.js +87 -12
- package/dist/hocuspocus-logger.esm.js.map +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +68 -0
- package/dist/packages/extension-logger/src/index.d.ts +1 -0
- package/dist/packages/{monitor → extension-monitor}/src/Collector.d.ts +2 -2
- package/dist/packages/{monitor → extension-monitor}/src/Dashboard.d.ts +0 -0
- package/dist/packages/{monitor → extension-monitor}/src/Storage.d.ts +0 -0
- package/dist/packages/{monitor → extension-monitor}/src/index.d.ts +2 -2
- package/dist/packages/{redis → extension-redis}/src/Redis.d.ts +2 -2
- package/dist/packages/{redis → extension-redis}/src/RedisCluster.d.ts +0 -0
- package/dist/packages/{redis → extension-redis}/src/index.d.ts +0 -0
- package/dist/packages/{rocksdb → extension-rocksdb}/src/index.d.ts +3 -3
- package/dist/packages/{throttle → extension-throttle}/src/index.d.ts +0 -0
- package/dist/packages/{webhook → extension-webhook}/src/index.d.ts +3 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +1 -1
- package/dist/packages/server/src/Hocuspocus.d.ts +1 -0
- package/dist/packages/server/src/types.d.ts +10 -2
- package/package.json +11 -6
- package/src/Logger.ts +195 -0
- package/src/index.ts +1 -56
- package/dist/packages/logger/src/index.d.ts +0 -13
|
File without changes
|
|
@@ -3,35 +3,110 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
class Logger {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Constructor
|
|
8
|
+
*/
|
|
9
|
+
constructor(configuration) {
|
|
10
|
+
this.name = null;
|
|
11
|
+
this.configuration = {
|
|
12
|
+
prefix: null,
|
|
13
|
+
onLoadDocument: true,
|
|
14
|
+
onChange: true,
|
|
15
|
+
onConnect: true,
|
|
16
|
+
onDisconnect: true,
|
|
17
|
+
onUpgrade: true,
|
|
18
|
+
onRequest: true,
|
|
19
|
+
onListen: true,
|
|
20
|
+
onDestroy: true,
|
|
21
|
+
onConfigure: true,
|
|
22
|
+
log: console.log, // eslint-disable-line
|
|
23
|
+
};
|
|
24
|
+
this.configuration = {
|
|
25
|
+
...this.configuration,
|
|
26
|
+
...configuration,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async onLoadDocument(data) {
|
|
30
|
+
if (this.configuration.onLoadDocument) {
|
|
31
|
+
this.log(`Loaded document "${data.documentName}".`);
|
|
32
|
+
}
|
|
8
33
|
}
|
|
9
34
|
async onChange(data) {
|
|
10
|
-
|
|
35
|
+
if (this.configuration.onChange) {
|
|
36
|
+
this.log(`Document "${data.documentName}" changed.`);
|
|
37
|
+
}
|
|
11
38
|
}
|
|
12
39
|
async onConnect(data) {
|
|
13
|
-
|
|
40
|
+
if (this.configuration.onConnect) {
|
|
41
|
+
this.log(`New connection to "${data.documentName}".`);
|
|
42
|
+
}
|
|
14
43
|
}
|
|
15
44
|
async onDisconnect(data) {
|
|
16
|
-
|
|
45
|
+
if (this.configuration.onDisconnect) {
|
|
46
|
+
this.log(`Connection to "${data.documentName}" closed.`);
|
|
47
|
+
}
|
|
17
48
|
}
|
|
18
49
|
async onUpgrade(data) {
|
|
19
|
-
|
|
50
|
+
if (this.configuration.onUpgrade) {
|
|
51
|
+
this.log('Upgrading connection …');
|
|
52
|
+
}
|
|
20
53
|
}
|
|
21
54
|
async onRequest(data) {
|
|
22
|
-
|
|
55
|
+
if (this.configuration.onRequest) {
|
|
56
|
+
this.log(`Incoming HTTP Request to ${data.request.url}`);
|
|
57
|
+
}
|
|
23
58
|
}
|
|
24
59
|
async onListen(data) {
|
|
25
|
-
|
|
60
|
+
if (this.configuration.onListen) {
|
|
61
|
+
this.logRawText('Ready.');
|
|
62
|
+
this.logRawText();
|
|
63
|
+
}
|
|
26
64
|
}
|
|
27
65
|
async onDestroy(data) {
|
|
28
|
-
|
|
66
|
+
if (this.configuration.onDestroy) {
|
|
67
|
+
this.log('Shut down.');
|
|
68
|
+
}
|
|
29
69
|
}
|
|
30
70
|
async onConfigure(data) {
|
|
31
|
-
|
|
71
|
+
var _a;
|
|
72
|
+
if (!this.configuration.onConfigure) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (this.configuration.prefix) {
|
|
76
|
+
console.warn('[hocuspocus warn] The Logger \'prefix\' is deprecated. Pass a \'name\' to the Hocuspocus configuration instead.');
|
|
77
|
+
}
|
|
78
|
+
this.name = data.instance.configuration.name;
|
|
79
|
+
this.logRawText();
|
|
80
|
+
this.logRawText(`Hocuspocus v${data.version} running at:`);
|
|
81
|
+
this.logRawText();
|
|
82
|
+
this.logRawText(`> HTTP: http://127.0.0.1:${data.configuration.port}`);
|
|
83
|
+
this.logRawText(`> WebSocket: ws://127.0.0.1:${data.configuration.port}`);
|
|
84
|
+
const { instance } = data;
|
|
85
|
+
const extensions = (_a = instance.configuration) === null || _a === void 0 ? void 0 : _a.extensions.map(extension => {
|
|
86
|
+
var _a;
|
|
87
|
+
return (_a = extension.constructor) === null || _a === void 0 ? void 0 : _a.name;
|
|
88
|
+
}).filter(name => name).filter(name => name !== 'Object');
|
|
89
|
+
if (!extensions.length) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.logRawText();
|
|
93
|
+
this.logRawText('Extensions:');
|
|
94
|
+
extensions
|
|
95
|
+
.forEach(name => {
|
|
96
|
+
this.logRawText(`- ${name}`);
|
|
97
|
+
});
|
|
98
|
+
this.logRawText();
|
|
99
|
+
}
|
|
100
|
+
logRawText(message = '') {
|
|
101
|
+
this.configuration.log(message);
|
|
32
102
|
}
|
|
33
|
-
|
|
34
|
-
|
|
103
|
+
log(message) {
|
|
104
|
+
message = `[${(new Date()).toISOString()}] ${message}`;
|
|
105
|
+
const name = this.name ? this.name : this.configuration.prefix;
|
|
106
|
+
if (name) {
|
|
107
|
+
message = `[${name}] ${message}`;
|
|
108
|
+
}
|
|
109
|
+
this.logRawText(message);
|
|
35
110
|
}
|
|
36
111
|
}
|
|
37
112
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-logger.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"hocuspocus-logger.cjs","sources":["../src/Logger.ts"],"sourcesContent":["import {\n Extension,\n onChangePayload,\n onConfigurePayload,\n onConnectPayload,\n onLoadDocumentPayload,\n onDestroyPayload,\n onDisconnectPayload,\n onListenPayload,\n onRequestPayload,\n onUpgradePayload,\n} from '@hocuspocus/server'\n\nexport interface LoggerConfiguration {\n /**\n * Prepend all logging message with a string.\n *\n * @deprecated\n */\n prefix: null | string,\n /**\n * Whether to log something for the `onLoadDocument` hook.\n */\n onLoadDocument: boolean,\n /**\n * Whether to log something for the `onChange` hook.\n */\n onChange: boolean,\n /**\n * Whether to log something for the `onConnect` hook.\n */\n onConnect: boolean,\n /**\n * Whether to log something for the `onDisconnect` hook.\n */\n onDisconnect: boolean,\n /**\n * Whether to log something for the `onUpgrade` hook.\n */\n onUpgrade: boolean,\n /**\n * Whether to log something for the `onRequest` hook.\n */\n onRequest: boolean,\n /**\n * Whether to log something for the `onListen` hook.\n */\n onListen: boolean,\n /**\n * Whether to log something for the `onDestroy` hook.\n */\n onDestroy: boolean,\n /**\n * Whether to log something for the `onConfigure` hook.\n */\n onConfigure: boolean,\n /**\n * A log function, if none is provided output will go to console\n */\n log: (...args: any[]) => void,\n}\n\nexport class Logger implements Extension {\n name: string | null = null\n\n configuration: LoggerConfiguration = {\n prefix: null,\n onLoadDocument: true,\n onChange: true,\n onConnect: true,\n onDisconnect: true,\n onUpgrade: true,\n onRequest: true,\n onListen: true,\n onDestroy: true,\n onConfigure: true,\n log: console.log, // eslint-disable-line\n }\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<LoggerConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n async onLoadDocument(data: onLoadDocumentPayload) {\n if (this.configuration.onLoadDocument) {\n this.log(`Loaded document \"${data.documentName}\".`)\n }\n }\n\n async onChange(data: onChangePayload) {\n if (this.configuration.onChange) {\n this.log(`Document \"${data.documentName}\" changed.`)\n }\n }\n\n async onConnect(data: onConnectPayload) {\n if (this.configuration.onConnect) {\n this.log(`New connection to \"${data.documentName}\".`)\n }\n }\n\n async onDisconnect(data: onDisconnectPayload) {\n if (this.configuration.onDisconnect) {\n this.log(`Connection to \"${data.documentName}\" closed.`)\n }\n }\n\n async onUpgrade(data: onUpgradePayload) {\n if (this.configuration.onUpgrade) {\n this.log('Upgrading connection …')\n }\n }\n\n async onRequest(data: onRequestPayload) {\n if (this.configuration.onRequest) {\n this.log(`Incoming HTTP Request to ${data.request.url}`)\n }\n }\n\n async onListen(data: onListenPayload) {\n if (this.configuration.onListen) {\n this.logRawText('Ready.')\n this.logRawText()\n }\n }\n\n async onDestroy(data: onDestroyPayload) {\n if (this.configuration.onDestroy) {\n this.log('Shut down.')\n }\n }\n\n async onConfigure(data: onConfigurePayload) {\n if (!this.configuration.onConfigure) {\n return\n }\n\n if (this.configuration.prefix) {\n console.warn('[hocuspocus warn] The Logger \\'prefix\\' is deprecated. Pass a \\'name\\' to the Hocuspocus configuration instead.')\n }\n\n this.name = data.instance.configuration.name\n\n this.logRawText()\n this.logRawText(`Hocuspocus v${data.version} running at:`)\n this.logRawText()\n this.logRawText(`> HTTP: http://127.0.0.1:${data.configuration.port}`)\n this.logRawText(`> WebSocket: ws://127.0.0.1:${data.configuration.port}`)\n\n const { instance } = data\n\n const extensions = instance.configuration?.extensions.map(extension => {\n return extension.constructor?.name\n })\n .filter(name => name)\n .filter(name => name !== 'Object')\n\n if (!extensions.length) {\n return\n }\n\n this.logRawText()\n this.logRawText('Extensions:')\n\n extensions\n .forEach(name => {\n this.logRawText(`- ${name}`)\n })\n\n this.logRawText()\n }\n\n private logRawText(message = '') {\n this.configuration.log(message)\n }\n\n private log(message: string) {\n message = `[${(new Date()).toISOString()}] ${message}`\n\n const name = this.name ? this.name : this.configuration.prefix\n\n if (name) {\n message = `[${name}] ${message}`\n }\n\n this.logRawText(message)\n }\n\n}\n"],"names":[],"mappings":";;;;MA8Da,MAAM;;;;IAoBjB,YAAY,aAA4C;QAnBxD,SAAI,GAAkB,IAAI,CAAA;QAE1B,kBAAa,GAAwB;YACnC,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,IAAI;YACpB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI;YACf,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;IAED,MAAM,cAAc,CAAC,IAA2B;QAC9C,IAAI,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE;YACrC,IAAI,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA;SACpD;KACF;IAED,MAAM,QAAQ,CAAC,IAAqB;QAClC,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,IAAI,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,YAAY,YAAY,CAAC,CAAA;SACrD;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,sBAAsB,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA;SACtD;KACF;IAED,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}
|
|
@@ -1,33 +1,108 @@
|
|
|
1
1
|
class Logger {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Constructor
|
|
4
|
+
*/
|
|
5
|
+
constructor(configuration) {
|
|
6
|
+
this.name = null;
|
|
7
|
+
this.configuration = {
|
|
8
|
+
prefix: null,
|
|
9
|
+
onLoadDocument: true,
|
|
10
|
+
onChange: true,
|
|
11
|
+
onConnect: true,
|
|
12
|
+
onDisconnect: true,
|
|
13
|
+
onUpgrade: true,
|
|
14
|
+
onRequest: true,
|
|
15
|
+
onListen: true,
|
|
16
|
+
onDestroy: true,
|
|
17
|
+
onConfigure: true,
|
|
18
|
+
log: console.log, // eslint-disable-line
|
|
19
|
+
};
|
|
20
|
+
this.configuration = {
|
|
21
|
+
...this.configuration,
|
|
22
|
+
...configuration,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async onLoadDocument(data) {
|
|
26
|
+
if (this.configuration.onLoadDocument) {
|
|
27
|
+
this.log(`Loaded document "${data.documentName}".`);
|
|
28
|
+
}
|
|
4
29
|
}
|
|
5
30
|
async onChange(data) {
|
|
6
|
-
|
|
31
|
+
if (this.configuration.onChange) {
|
|
32
|
+
this.log(`Document "${data.documentName}" changed.`);
|
|
33
|
+
}
|
|
7
34
|
}
|
|
8
35
|
async onConnect(data) {
|
|
9
|
-
|
|
36
|
+
if (this.configuration.onConnect) {
|
|
37
|
+
this.log(`New connection to "${data.documentName}".`);
|
|
38
|
+
}
|
|
10
39
|
}
|
|
11
40
|
async onDisconnect(data) {
|
|
12
|
-
|
|
41
|
+
if (this.configuration.onDisconnect) {
|
|
42
|
+
this.log(`Connection to "${data.documentName}" closed.`);
|
|
43
|
+
}
|
|
13
44
|
}
|
|
14
45
|
async onUpgrade(data) {
|
|
15
|
-
|
|
46
|
+
if (this.configuration.onUpgrade) {
|
|
47
|
+
this.log('Upgrading connection …');
|
|
48
|
+
}
|
|
16
49
|
}
|
|
17
50
|
async onRequest(data) {
|
|
18
|
-
|
|
51
|
+
if (this.configuration.onRequest) {
|
|
52
|
+
this.log(`Incoming HTTP Request to ${data.request.url}`);
|
|
53
|
+
}
|
|
19
54
|
}
|
|
20
55
|
async onListen(data) {
|
|
21
|
-
|
|
56
|
+
if (this.configuration.onListen) {
|
|
57
|
+
this.logRawText('Ready.');
|
|
58
|
+
this.logRawText();
|
|
59
|
+
}
|
|
22
60
|
}
|
|
23
61
|
async onDestroy(data) {
|
|
24
|
-
|
|
62
|
+
if (this.configuration.onDestroy) {
|
|
63
|
+
this.log('Shut down.');
|
|
64
|
+
}
|
|
25
65
|
}
|
|
26
66
|
async onConfigure(data) {
|
|
27
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
if (!this.configuration.onConfigure) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (this.configuration.prefix) {
|
|
72
|
+
console.warn('[hocuspocus warn] The Logger \'prefix\' is deprecated. Pass a \'name\' to the Hocuspocus configuration instead.');
|
|
73
|
+
}
|
|
74
|
+
this.name = data.instance.configuration.name;
|
|
75
|
+
this.logRawText();
|
|
76
|
+
this.logRawText(`Hocuspocus v${data.version} running at:`);
|
|
77
|
+
this.logRawText();
|
|
78
|
+
this.logRawText(`> HTTP: http://127.0.0.1:${data.configuration.port}`);
|
|
79
|
+
this.logRawText(`> WebSocket: ws://127.0.0.1:${data.configuration.port}`);
|
|
80
|
+
const { instance } = data;
|
|
81
|
+
const extensions = (_a = instance.configuration) === null || _a === void 0 ? void 0 : _a.extensions.map(extension => {
|
|
82
|
+
var _a;
|
|
83
|
+
return (_a = extension.constructor) === null || _a === void 0 ? void 0 : _a.name;
|
|
84
|
+
}).filter(name => name).filter(name => name !== 'Object');
|
|
85
|
+
if (!extensions.length) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.logRawText();
|
|
89
|
+
this.logRawText('Extensions:');
|
|
90
|
+
extensions
|
|
91
|
+
.forEach(name => {
|
|
92
|
+
this.logRawText(`- ${name}`);
|
|
93
|
+
});
|
|
94
|
+
this.logRawText();
|
|
95
|
+
}
|
|
96
|
+
logRawText(message = '') {
|
|
97
|
+
this.configuration.log(message);
|
|
28
98
|
}
|
|
29
|
-
|
|
30
|
-
|
|
99
|
+
log(message) {
|
|
100
|
+
message = `[${(new Date()).toISOString()}] ${message}`;
|
|
101
|
+
const name = this.name ? this.name : this.configuration.prefix;
|
|
102
|
+
if (name) {
|
|
103
|
+
message = `[${name}] ${message}`;
|
|
104
|
+
}
|
|
105
|
+
this.logRawText(message);
|
|
31
106
|
}
|
|
32
107
|
}
|
|
33
108
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-logger.esm.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"hocuspocus-logger.esm.js","sources":["../src/Logger.ts"],"sourcesContent":["import {\n Extension,\n onChangePayload,\n onConfigurePayload,\n onConnectPayload,\n onLoadDocumentPayload,\n onDestroyPayload,\n onDisconnectPayload,\n onListenPayload,\n onRequestPayload,\n onUpgradePayload,\n} from '@hocuspocus/server'\n\nexport interface LoggerConfiguration {\n /**\n * Prepend all logging message with a string.\n *\n * @deprecated\n */\n prefix: null | string,\n /**\n * Whether to log something for the `onLoadDocument` hook.\n */\n onLoadDocument: boolean,\n /**\n * Whether to log something for the `onChange` hook.\n */\n onChange: boolean,\n /**\n * Whether to log something for the `onConnect` hook.\n */\n onConnect: boolean,\n /**\n * Whether to log something for the `onDisconnect` hook.\n */\n onDisconnect: boolean,\n /**\n * Whether to log something for the `onUpgrade` hook.\n */\n onUpgrade: boolean,\n /**\n * Whether to log something for the `onRequest` hook.\n */\n onRequest: boolean,\n /**\n * Whether to log something for the `onListen` hook.\n */\n onListen: boolean,\n /**\n * Whether to log something for the `onDestroy` hook.\n */\n onDestroy: boolean,\n /**\n * Whether to log something for the `onConfigure` hook.\n */\n onConfigure: boolean,\n /**\n * A log function, if none is provided output will go to console\n */\n log: (...args: any[]) => void,\n}\n\nexport class Logger implements Extension {\n name: string | null = null\n\n configuration: LoggerConfiguration = {\n prefix: null,\n onLoadDocument: true,\n onChange: true,\n onConnect: true,\n onDisconnect: true,\n onUpgrade: true,\n onRequest: true,\n onListen: true,\n onDestroy: true,\n onConfigure: true,\n log: console.log, // eslint-disable-line\n }\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<LoggerConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n async onLoadDocument(data: onLoadDocumentPayload) {\n if (this.configuration.onLoadDocument) {\n this.log(`Loaded document \"${data.documentName}\".`)\n }\n }\n\n async onChange(data: onChangePayload) {\n if (this.configuration.onChange) {\n this.log(`Document \"${data.documentName}\" changed.`)\n }\n }\n\n async onConnect(data: onConnectPayload) {\n if (this.configuration.onConnect) {\n this.log(`New connection to \"${data.documentName}\".`)\n }\n }\n\n async onDisconnect(data: onDisconnectPayload) {\n if (this.configuration.onDisconnect) {\n this.log(`Connection to \"${data.documentName}\" closed.`)\n }\n }\n\n async onUpgrade(data: onUpgradePayload) {\n if (this.configuration.onUpgrade) {\n this.log('Upgrading connection …')\n }\n }\n\n async onRequest(data: onRequestPayload) {\n if (this.configuration.onRequest) {\n this.log(`Incoming HTTP Request to ${data.request.url}`)\n }\n }\n\n async onListen(data: onListenPayload) {\n if (this.configuration.onListen) {\n this.logRawText('Ready.')\n this.logRawText()\n }\n }\n\n async onDestroy(data: onDestroyPayload) {\n if (this.configuration.onDestroy) {\n this.log('Shut down.')\n }\n }\n\n async onConfigure(data: onConfigurePayload) {\n if (!this.configuration.onConfigure) {\n return\n }\n\n if (this.configuration.prefix) {\n console.warn('[hocuspocus warn] The Logger \\'prefix\\' is deprecated. Pass a \\'name\\' to the Hocuspocus configuration instead.')\n }\n\n this.name = data.instance.configuration.name\n\n this.logRawText()\n this.logRawText(`Hocuspocus v${data.version} running at:`)\n this.logRawText()\n this.logRawText(`> HTTP: http://127.0.0.1:${data.configuration.port}`)\n this.logRawText(`> WebSocket: ws://127.0.0.1:${data.configuration.port}`)\n\n const { instance } = data\n\n const extensions = instance.configuration?.extensions.map(extension => {\n return extension.constructor?.name\n })\n .filter(name => name)\n .filter(name => name !== 'Object')\n\n if (!extensions.length) {\n return\n }\n\n this.logRawText()\n this.logRawText('Extensions:')\n\n extensions\n .forEach(name => {\n this.logRawText(`- ${name}`)\n })\n\n this.logRawText()\n }\n\n private logRawText(message = '') {\n this.configuration.log(message)\n }\n\n private log(message: string) {\n message = `[${(new Date()).toISOString()}] ${message}`\n\n const name = this.name ? this.name : this.configuration.prefix\n\n if (name) {\n message = `[${name}] ${message}`\n }\n\n this.logRawText(message)\n }\n\n}\n"],"names":[],"mappings":"MA8Da,MAAM;;;;IAoBjB,YAAY,aAA4C;QAnBxD,SAAI,GAAkB,IAAI,CAAA;QAE1B,kBAAa,GAAwB;YACnC,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,IAAI;YACpB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI;YACf,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAA;QAMC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;IAED,MAAM,cAAc,CAAC,IAA2B;QAC9C,IAAI,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE;YACrC,IAAI,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA;SACpD;KACF;IAED,MAAM,QAAQ,CAAC,IAAqB;QAClC,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC/B,IAAI,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,YAAY,YAAY,CAAC,CAAA;SACrD;KACF;IAED,MAAM,SAAS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AM,CAAA;QAE9D,IAAI,IAAI,EAAE;YACR,OAAO,GAAG,IAAI,IAAI,KAAK,OAAO,EAAE,CAAA;SACjC;QAED,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;KACzB;;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
|
|
2
|
+
export interface LoggerConfiguration {
|
|
3
|
+
/**
|
|
4
|
+
* Prepend all logging message with a string.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
8
|
+
prefix: null | string;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to log something for the `onLoadDocument` hook.
|
|
11
|
+
*/
|
|
12
|
+
onLoadDocument: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to log something for the `onChange` hook.
|
|
15
|
+
*/
|
|
16
|
+
onChange: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to log something for the `onConnect` hook.
|
|
19
|
+
*/
|
|
20
|
+
onConnect: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to log something for the `onDisconnect` hook.
|
|
23
|
+
*/
|
|
24
|
+
onDisconnect: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to log something for the `onUpgrade` hook.
|
|
27
|
+
*/
|
|
28
|
+
onUpgrade: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to log something for the `onRequest` hook.
|
|
31
|
+
*/
|
|
32
|
+
onRequest: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether to log something for the `onListen` hook.
|
|
35
|
+
*/
|
|
36
|
+
onListen: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to log something for the `onDestroy` hook.
|
|
39
|
+
*/
|
|
40
|
+
onDestroy: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to log something for the `onConfigure` hook.
|
|
43
|
+
*/
|
|
44
|
+
onConfigure: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* A log function, if none is provided output will go to console
|
|
47
|
+
*/
|
|
48
|
+
log: (...args: any[]) => void;
|
|
49
|
+
}
|
|
50
|
+
export declare class Logger implements Extension {
|
|
51
|
+
name: string | null;
|
|
52
|
+
configuration: LoggerConfiguration;
|
|
53
|
+
/**
|
|
54
|
+
* Constructor
|
|
55
|
+
*/
|
|
56
|
+
constructor(configuration?: Partial<LoggerConfiguration>);
|
|
57
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
58
|
+
onChange(data: onChangePayload): Promise<void>;
|
|
59
|
+
onConnect(data: onConnectPayload): Promise<void>;
|
|
60
|
+
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
61
|
+
onUpgrade(data: onUpgradePayload): Promise<void>;
|
|
62
|
+
onRequest(data: onRequestPayload): Promise<void>;
|
|
63
|
+
onListen(data: onListenPayload): Promise<void>;
|
|
64
|
+
onDestroy(data: onDestroyPayload): Promise<void>;
|
|
65
|
+
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
66
|
+
private logRawText;
|
|
67
|
+
private log;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Logger';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Configuration, onConnectPayload, onDisconnectPayload,
|
|
2
|
+
import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPayload, onChangePayload } from '@hocuspocus/server';
|
|
3
3
|
export declare class Collector {
|
|
4
4
|
serverConfiguration: Partial<Configuration>;
|
|
5
5
|
version: string;
|
|
@@ -30,7 +30,7 @@ export declare class Collector {
|
|
|
30
30
|
connectionCount(): {
|
|
31
31
|
count: string | number;
|
|
32
32
|
};
|
|
33
|
-
createDocument(data:
|
|
33
|
+
createDocument(data: onLoadDocumentPayload): {
|
|
34
34
|
action: string;
|
|
35
35
|
document: any;
|
|
36
36
|
documentName: string;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload,
|
|
2
|
+
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
4
|
import WebSocket from 'ws';
|
|
5
5
|
import { Storage } from './Storage';
|
|
@@ -32,7 +32,7 @@ export declare class Monitor implements Extension {
|
|
|
32
32
|
onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
|
|
33
33
|
onConnect(data: onConnectPayload): Promise<void>;
|
|
34
34
|
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
35
|
-
|
|
35
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
36
36
|
onChange(data: onChangePayload): Promise<void>;
|
|
37
37
|
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
38
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RedisPersistence } from 'y-redis';
|
|
2
|
-
import { Extension, onConnectPayload,
|
|
2
|
+
import { Extension, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
3
|
export interface Configuration {
|
|
4
4
|
}
|
|
5
5
|
export declare class Redis implements Extension {
|
|
@@ -10,7 +10,7 @@ export declare class Redis implements Extension {
|
|
|
10
10
|
* Constructor
|
|
11
11
|
*/
|
|
12
12
|
constructor(configuration?: Partial<Configuration>);
|
|
13
|
-
|
|
13
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<import("yjs").Doc | undefined>;
|
|
14
14
|
onConnect(data: onConnectPayload): Promise<void>;
|
|
15
15
|
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
16
16
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Extension,
|
|
1
|
+
import { Extension, onLoadDocumentPayload } from '@hocuspocus/server';
|
|
2
2
|
import { LeveldbPersistence } from 'y-leveldb';
|
|
3
3
|
export interface Configuration {
|
|
4
4
|
options: object | undefined;
|
|
@@ -12,9 +12,9 @@ export declare class RocksDB implements Extension {
|
|
|
12
12
|
*/
|
|
13
13
|
constructor(configuration?: Partial<Configuration>);
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* onLoadDocument hook
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
|
|
18
18
|
/**
|
|
19
19
|
* store updates in y-leveldb persistence
|
|
20
20
|
*/
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConnectPayload,
|
|
2
|
+
import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
3
|
import { Doc } from 'yjs';
|
|
4
4
|
import { Transformer } from '@hocuspocus/transformer';
|
|
5
5
|
import { AxiosResponse } from 'axios';
|
|
@@ -48,9 +48,9 @@ export declare class Webhook implements Extension {
|
|
|
48
48
|
*/
|
|
49
49
|
onChange(data: onChangePayload): Promise<void>;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* onLoadDocument hook
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
54
54
|
/**
|
|
55
55
|
* onConnect hook
|
|
56
56
|
*/
|
|
@@ -108,7 +108,7 @@ export interface HocuspocusProviderOptions {
|
|
|
108
108
|
export declare class HocuspocusProvider extends EventEmitter {
|
|
109
109
|
options: HocuspocusProviderOptions;
|
|
110
110
|
subscribedToBroadcastChannel: boolean;
|
|
111
|
-
webSocket:
|
|
111
|
+
webSocket: WebSocket | null;
|
|
112
112
|
shouldConnect: boolean;
|
|
113
113
|
status: WebSocketStatus;
|
|
114
114
|
isSynced: boolean;
|
|
@@ -34,7 +34,11 @@ export interface Extension {
|
|
|
34
34
|
onChange?(data: onChangePayload): Promise<any>;
|
|
35
35
|
onConnect?(data: onConnectPayload): Promise<any>;
|
|
36
36
|
onConfigure?(data: onConfigurePayload): Promise<any>;
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
39
|
+
*/
|
|
40
|
+
onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
41
|
+
onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
38
42
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
39
43
|
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
40
44
|
onListen?(data: onListenPayload): Promise<any>;
|
|
@@ -42,6 +46,10 @@ export interface Extension {
|
|
|
42
46
|
onUpgrade?(data: onUpgradePayload): Promise<any>;
|
|
43
47
|
}
|
|
44
48
|
export interface Configuration extends Extension {
|
|
49
|
+
/**
|
|
50
|
+
* A name for the instance, used for logging.
|
|
51
|
+
*/
|
|
52
|
+
name: string | null;
|
|
45
53
|
/**
|
|
46
54
|
* A list of hocuspocus extenions.
|
|
47
55
|
*/
|
|
@@ -73,7 +81,7 @@ export interface onConnectPayload {
|
|
|
73
81
|
socketId: string;
|
|
74
82
|
connection: ConnectionConfig;
|
|
75
83
|
}
|
|
76
|
-
export interface
|
|
84
|
+
export interface onLoadDocumentPayload {
|
|
77
85
|
context: any;
|
|
78
86
|
document: Document;
|
|
79
87
|
documentName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-logger",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.53",
|
|
4
4
|
"description": "hocuspocus logging extension",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -13,17 +13,22 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "dist/hocuspocus-logger.esm.js",
|
|
15
15
|
"module": "dist/hocuspocus-logger.esm.js",
|
|
16
|
-
"types": "dist/packages/logger/src/index.d.ts",
|
|
16
|
+
"types": "dist/packages/extension-logger/src/index.d.ts",
|
|
17
17
|
"exports": {
|
|
18
|
-
"
|
|
19
|
-
|
|
18
|
+
"development": {
|
|
19
|
+
"import": "./src"
|
|
20
|
+
},
|
|
21
|
+
"default": {
|
|
22
|
+
"import": "./dist/hocuspocus-logger.esm.js",
|
|
23
|
+
"require": "./dist/hocuspocus-logger.cjs"
|
|
24
|
+
}
|
|
20
25
|
},
|
|
21
26
|
"files": [
|
|
22
27
|
"src",
|
|
23
28
|
"dist"
|
|
24
29
|
],
|
|
25
30
|
"dependencies": {
|
|
26
|
-
"@hocuspocus/server": "^1.0.0-alpha.
|
|
31
|
+
"@hocuspocus/server": "^1.0.0-alpha.79"
|
|
27
32
|
},
|
|
28
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "f9f5acf828d4a1f5ae4df8188000b5c3873e18cf"
|
|
29
34
|
}
|
package/src/Logger.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
onChangePayload,
|
|
4
|
+
onConfigurePayload,
|
|
5
|
+
onConnectPayload,
|
|
6
|
+
onLoadDocumentPayload,
|
|
7
|
+
onDestroyPayload,
|
|
8
|
+
onDisconnectPayload,
|
|
9
|
+
onListenPayload,
|
|
10
|
+
onRequestPayload,
|
|
11
|
+
onUpgradePayload,
|
|
12
|
+
} from '@hocuspocus/server'
|
|
13
|
+
|
|
14
|
+
export interface LoggerConfiguration {
|
|
15
|
+
/**
|
|
16
|
+
* Prepend all logging message with a string.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
prefix: null | string,
|
|
21
|
+
/**
|
|
22
|
+
* Whether to log something for the `onLoadDocument` hook.
|
|
23
|
+
*/
|
|
24
|
+
onLoadDocument: boolean,
|
|
25
|
+
/**
|
|
26
|
+
* Whether to log something for the `onChange` hook.
|
|
27
|
+
*/
|
|
28
|
+
onChange: boolean,
|
|
29
|
+
/**
|
|
30
|
+
* Whether to log something for the `onConnect` hook.
|
|
31
|
+
*/
|
|
32
|
+
onConnect: boolean,
|
|
33
|
+
/**
|
|
34
|
+
* Whether to log something for the `onDisconnect` hook.
|
|
35
|
+
*/
|
|
36
|
+
onDisconnect: boolean,
|
|
37
|
+
/**
|
|
38
|
+
* Whether to log something for the `onUpgrade` hook.
|
|
39
|
+
*/
|
|
40
|
+
onUpgrade: boolean,
|
|
41
|
+
/**
|
|
42
|
+
* Whether to log something for the `onRequest` hook.
|
|
43
|
+
*/
|
|
44
|
+
onRequest: boolean,
|
|
45
|
+
/**
|
|
46
|
+
* Whether to log something for the `onListen` hook.
|
|
47
|
+
*/
|
|
48
|
+
onListen: boolean,
|
|
49
|
+
/**
|
|
50
|
+
* Whether to log something for the `onDestroy` hook.
|
|
51
|
+
*/
|
|
52
|
+
onDestroy: boolean,
|
|
53
|
+
/**
|
|
54
|
+
* Whether to log something for the `onConfigure` hook.
|
|
55
|
+
*/
|
|
56
|
+
onConfigure: boolean,
|
|
57
|
+
/**
|
|
58
|
+
* A log function, if none is provided output will go to console
|
|
59
|
+
*/
|
|
60
|
+
log: (...args: any[]) => void,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class Logger implements Extension {
|
|
64
|
+
name: string | null = null
|
|
65
|
+
|
|
66
|
+
configuration: LoggerConfiguration = {
|
|
67
|
+
prefix: null,
|
|
68
|
+
onLoadDocument: true,
|
|
69
|
+
onChange: true,
|
|
70
|
+
onConnect: true,
|
|
71
|
+
onDisconnect: true,
|
|
72
|
+
onUpgrade: true,
|
|
73
|
+
onRequest: true,
|
|
74
|
+
onListen: true,
|
|
75
|
+
onDestroy: true,
|
|
76
|
+
onConfigure: true,
|
|
77
|
+
log: console.log, // eslint-disable-line
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Constructor
|
|
82
|
+
*/
|
|
83
|
+
constructor(configuration?: Partial<LoggerConfiguration>) {
|
|
84
|
+
this.configuration = {
|
|
85
|
+
...this.configuration,
|
|
86
|
+
...configuration,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async onLoadDocument(data: onLoadDocumentPayload) {
|
|
91
|
+
if (this.configuration.onLoadDocument) {
|
|
92
|
+
this.log(`Loaded document "${data.documentName}".`)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async onChange(data: onChangePayload) {
|
|
97
|
+
if (this.configuration.onChange) {
|
|
98
|
+
this.log(`Document "${data.documentName}" changed.`)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async onConnect(data: onConnectPayload) {
|
|
103
|
+
if (this.configuration.onConnect) {
|
|
104
|
+
this.log(`New connection to "${data.documentName}".`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async onDisconnect(data: onDisconnectPayload) {
|
|
109
|
+
if (this.configuration.onDisconnect) {
|
|
110
|
+
this.log(`Connection to "${data.documentName}" closed.`)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async onUpgrade(data: onUpgradePayload) {
|
|
115
|
+
if (this.configuration.onUpgrade) {
|
|
116
|
+
this.log('Upgrading connection …')
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async onRequest(data: onRequestPayload) {
|
|
121
|
+
if (this.configuration.onRequest) {
|
|
122
|
+
this.log(`Incoming HTTP Request to ${data.request.url}`)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async onListen(data: onListenPayload) {
|
|
127
|
+
if (this.configuration.onListen) {
|
|
128
|
+
this.logRawText('Ready.')
|
|
129
|
+
this.logRawText()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async onDestroy(data: onDestroyPayload) {
|
|
134
|
+
if (this.configuration.onDestroy) {
|
|
135
|
+
this.log('Shut down.')
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async onConfigure(data: onConfigurePayload) {
|
|
140
|
+
if (!this.configuration.onConfigure) {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (this.configuration.prefix) {
|
|
145
|
+
console.warn('[hocuspocus warn] The Logger \'prefix\' is deprecated. Pass a \'name\' to the Hocuspocus configuration instead.')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
this.name = data.instance.configuration.name
|
|
149
|
+
|
|
150
|
+
this.logRawText()
|
|
151
|
+
this.logRawText(`Hocuspocus v${data.version} running at:`)
|
|
152
|
+
this.logRawText()
|
|
153
|
+
this.logRawText(`> HTTP: http://127.0.0.1:${data.configuration.port}`)
|
|
154
|
+
this.logRawText(`> WebSocket: ws://127.0.0.1:${data.configuration.port}`)
|
|
155
|
+
|
|
156
|
+
const { instance } = data
|
|
157
|
+
|
|
158
|
+
const extensions = instance.configuration?.extensions.map(extension => {
|
|
159
|
+
return extension.constructor?.name
|
|
160
|
+
})
|
|
161
|
+
.filter(name => name)
|
|
162
|
+
.filter(name => name !== 'Object')
|
|
163
|
+
|
|
164
|
+
if (!extensions.length) {
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.logRawText()
|
|
169
|
+
this.logRawText('Extensions:')
|
|
170
|
+
|
|
171
|
+
extensions
|
|
172
|
+
.forEach(name => {
|
|
173
|
+
this.logRawText(`- ${name}`)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
this.logRawText()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private logRawText(message = '') {
|
|
180
|
+
this.configuration.log(message)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private log(message: string) {
|
|
184
|
+
message = `[${(new Date()).toISOString()}] ${message}`
|
|
185
|
+
|
|
186
|
+
const name = this.name ? this.name : this.configuration.prefix
|
|
187
|
+
|
|
188
|
+
if (name) {
|
|
189
|
+
message = `[${name}] ${message}`
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.logRawText(message)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,56 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Extension,
|
|
3
|
-
onChangePayload,
|
|
4
|
-
onConfigurePayload,
|
|
5
|
-
onConnectPayload,
|
|
6
|
-
onCreateDocumentPayload,
|
|
7
|
-
onDestroyPayload,
|
|
8
|
-
onDisconnectPayload,
|
|
9
|
-
onListenPayload,
|
|
10
|
-
onRequestPayload,
|
|
11
|
-
onUpgradePayload,
|
|
12
|
-
} from '@hocuspocus/server'
|
|
13
|
-
|
|
14
|
-
export class Logger implements Extension {
|
|
15
|
-
|
|
16
|
-
async onCreateDocument(data: onCreateDocumentPayload) {
|
|
17
|
-
Logger.log(`Created document "${data.documentName}"`)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async onChange(data: onChangePayload) {
|
|
21
|
-
Logger.log(`Document "${data.documentName}" changed`)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async onConnect(data: onConnectPayload) {
|
|
25
|
-
Logger.log(`New connection to "${data.documentName}"`)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async onDisconnect(data: onDisconnectPayload) {
|
|
29
|
-
Logger.log(`Connection to "${data.documentName}" closed`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async onUpgrade(data: onUpgradePayload) {
|
|
33
|
-
Logger.log('Upgrading connection')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async onRequest(data: onRequestPayload) {
|
|
37
|
-
Logger.log(`Incoming HTTP Request to "${data.request.url}"`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async onListen(data: onListenPayload) {
|
|
41
|
-
Logger.log(`Listening on port "${data.port}"`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async onDestroy(data: onDestroyPayload) {
|
|
45
|
-
Logger.log('Server shutting down')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async onConfigure(data: onConfigurePayload) {
|
|
49
|
-
Logger.log('Server configured')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private static log(message: string) {
|
|
53
|
-
process.stdout.write(`[${(new Date()).toISOString()}] ${message} … \n`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
1
|
+
export * from './Logger'
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
|
|
2
|
-
export declare class Logger implements Extension {
|
|
3
|
-
onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
|
|
4
|
-
onChange(data: onChangePayload): Promise<void>;
|
|
5
|
-
onConnect(data: onConnectPayload): Promise<void>;
|
|
6
|
-
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
7
|
-
onUpgrade(data: onUpgradePayload): Promise<void>;
|
|
8
|
-
onRequest(data: onRequestPayload): Promise<void>;
|
|
9
|
-
onListen(data: onListenPayload): Promise<void>;
|
|
10
|
-
onDestroy(data: onDestroyPayload): Promise<void>;
|
|
11
|
-
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
12
|
-
private static log;
|
|
13
|
-
}
|