@hocuspocus/extension-logger 1.0.0-alpha.50 → 1.0.0-alpha.54
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/hocuspocus-logger.cjs +72 -13
- package/dist/hocuspocus-logger.cjs.map +1 -1
- package/dist/hocuspocus-logger.esm.js +72 -13
- package/dist/hocuspocus-logger.esm.js.map +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +44 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +1 -0
- package/dist/packages/server/src/types.d.ts +9 -0
- package/package.json +10 -5
- package/src/Logger.ts +126 -13
|
@@ -7,8 +7,19 @@ class Logger {
|
|
|
7
7
|
* Constructor
|
|
8
8
|
*/
|
|
9
9
|
constructor(configuration) {
|
|
10
|
+
this.name = null;
|
|
10
11
|
this.configuration = {
|
|
11
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
|
|
12
23
|
};
|
|
13
24
|
this.configuration = {
|
|
14
25
|
...this.configuration,
|
|
@@ -16,38 +27,86 @@ class Logger {
|
|
|
16
27
|
};
|
|
17
28
|
}
|
|
18
29
|
async onLoadDocument(data) {
|
|
19
|
-
this.
|
|
30
|
+
if (this.configuration.onLoadDocument) {
|
|
31
|
+
this.log(`Loaded document "${data.documentName}".`);
|
|
32
|
+
}
|
|
20
33
|
}
|
|
21
34
|
async onChange(data) {
|
|
22
|
-
this.
|
|
35
|
+
if (this.configuration.onChange) {
|
|
36
|
+
this.log(`Document "${data.documentName}" changed.`);
|
|
37
|
+
}
|
|
23
38
|
}
|
|
24
39
|
async onConnect(data) {
|
|
25
|
-
this.
|
|
40
|
+
if (this.configuration.onConnect) {
|
|
41
|
+
this.log(`New connection to "${data.documentName}".`);
|
|
42
|
+
}
|
|
26
43
|
}
|
|
27
44
|
async onDisconnect(data) {
|
|
28
|
-
this.
|
|
45
|
+
if (this.configuration.onDisconnect) {
|
|
46
|
+
this.log(`Connection to "${data.documentName}" closed.`);
|
|
47
|
+
}
|
|
29
48
|
}
|
|
30
49
|
async onUpgrade(data) {
|
|
31
|
-
this.
|
|
50
|
+
if (this.configuration.onUpgrade) {
|
|
51
|
+
this.log('Upgrading connection …');
|
|
52
|
+
}
|
|
32
53
|
}
|
|
33
54
|
async onRequest(data) {
|
|
34
|
-
this.
|
|
55
|
+
if (this.configuration.onRequest) {
|
|
56
|
+
this.log(`Incoming HTTP Request to ${data.request.url}`);
|
|
57
|
+
}
|
|
35
58
|
}
|
|
36
59
|
async onListen(data) {
|
|
37
|
-
this.
|
|
60
|
+
if (this.configuration.onListen) {
|
|
61
|
+
this.logRawText('Ready.');
|
|
62
|
+
this.logRawText();
|
|
63
|
+
}
|
|
38
64
|
}
|
|
39
65
|
async onDestroy(data) {
|
|
40
|
-
this.
|
|
66
|
+
if (this.configuration.onDestroy) {
|
|
67
|
+
this.log('Shut down.');
|
|
68
|
+
}
|
|
41
69
|
}
|
|
42
70
|
async onConfigure(data) {
|
|
43
|
-
|
|
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);
|
|
44
102
|
}
|
|
45
103
|
log(message) {
|
|
46
|
-
message = `[${(new Date()).toISOString()}] ${message}
|
|
47
|
-
|
|
48
|
-
|
|
104
|
+
message = `[${(new Date()).toISOString()}] ${message}`;
|
|
105
|
+
const name = this.name ? this.name : this.configuration.prefix;
|
|
106
|
+
if (name) {
|
|
107
|
+
message = `[${name}] ${message}`;
|
|
49
108
|
}
|
|
50
|
-
|
|
109
|
+
this.logRawText(message);
|
|
51
110
|
}
|
|
52
111
|
}
|
|
53
112
|
|
|
@@ -1 +1 @@
|
|
|
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 prefix: null | string,\n}\n\nexport class Logger implements Extension {\n configuration: LoggerConfiguration = {\n prefix: null,\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 this.log(`Loaded document \"${data.documentName}\"
|
|
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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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
|
|
8
19
|
};
|
|
9
20
|
this.configuration = {
|
|
10
21
|
...this.configuration,
|
|
@@ -12,38 +23,86 @@ class Logger {
|
|
|
12
23
|
};
|
|
13
24
|
}
|
|
14
25
|
async onLoadDocument(data) {
|
|
15
|
-
this.
|
|
26
|
+
if (this.configuration.onLoadDocument) {
|
|
27
|
+
this.log(`Loaded document "${data.documentName}".`);
|
|
28
|
+
}
|
|
16
29
|
}
|
|
17
30
|
async onChange(data) {
|
|
18
|
-
this.
|
|
31
|
+
if (this.configuration.onChange) {
|
|
32
|
+
this.log(`Document "${data.documentName}" changed.`);
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
35
|
async onConnect(data) {
|
|
21
|
-
this.
|
|
36
|
+
if (this.configuration.onConnect) {
|
|
37
|
+
this.log(`New connection to "${data.documentName}".`);
|
|
38
|
+
}
|
|
22
39
|
}
|
|
23
40
|
async onDisconnect(data) {
|
|
24
|
-
this.
|
|
41
|
+
if (this.configuration.onDisconnect) {
|
|
42
|
+
this.log(`Connection to "${data.documentName}" closed.`);
|
|
43
|
+
}
|
|
25
44
|
}
|
|
26
45
|
async onUpgrade(data) {
|
|
27
|
-
this.
|
|
46
|
+
if (this.configuration.onUpgrade) {
|
|
47
|
+
this.log('Upgrading connection …');
|
|
48
|
+
}
|
|
28
49
|
}
|
|
29
50
|
async onRequest(data) {
|
|
30
|
-
this.
|
|
51
|
+
if (this.configuration.onRequest) {
|
|
52
|
+
this.log(`Incoming HTTP Request to ${data.request.url}`);
|
|
53
|
+
}
|
|
31
54
|
}
|
|
32
55
|
async onListen(data) {
|
|
33
|
-
this.
|
|
56
|
+
if (this.configuration.onListen) {
|
|
57
|
+
this.logRawText('Ready.');
|
|
58
|
+
this.logRawText();
|
|
59
|
+
}
|
|
34
60
|
}
|
|
35
61
|
async onDestroy(data) {
|
|
36
|
-
this.
|
|
62
|
+
if (this.configuration.onDestroy) {
|
|
63
|
+
this.log('Shut down.');
|
|
64
|
+
}
|
|
37
65
|
}
|
|
38
66
|
async onConfigure(data) {
|
|
39
|
-
|
|
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);
|
|
40
98
|
}
|
|
41
99
|
log(message) {
|
|
42
|
-
message = `[${(new Date()).toISOString()}] ${message}
|
|
43
|
-
|
|
44
|
-
|
|
100
|
+
message = `[${(new Date()).toISOString()}] ${message}`;
|
|
101
|
+
const name = this.name ? this.name : this.configuration.prefix;
|
|
102
|
+
if (name) {
|
|
103
|
+
message = `[${name}] ${message}`;
|
|
45
104
|
}
|
|
46
|
-
|
|
105
|
+
this.logRawText(message);
|
|
47
106
|
}
|
|
48
107
|
}
|
|
49
108
|
|
|
@@ -1 +1 @@
|
|
|
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 prefix: null | string,\n}\n\nexport class Logger implements Extension {\n configuration: LoggerConfiguration = {\n prefix: null,\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 this.log(`Loaded document \"${data.documentName}\"
|
|
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,C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,GAAG,EAAE;QAC7B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;KAChC;IAEO,GAAG,CAAC,OAAe;QACzB,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,CAAA;QAEtD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAA;QAE9D,IAAI,IAAI,EAAE;YACR,OAAO,GAAG,IAAI,IAAI,KAAK,OAAO,EAAE,CAAA;SACjC;QAED,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;KACzB;;;;;"}
|
|
@@ -2,10 +2,53 @@ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoa
|
|
|
2
2
|
export interface LoggerConfiguration {
|
|
3
3
|
/**
|
|
4
4
|
* Prepend all logging message with a string.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated
|
|
5
7
|
*/
|
|
6
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;
|
|
7
49
|
}
|
|
8
50
|
export declare class Logger implements Extension {
|
|
51
|
+
name: string | null;
|
|
9
52
|
configuration: LoggerConfiguration;
|
|
10
53
|
/**
|
|
11
54
|
* Constructor
|
|
@@ -20,5 +63,6 @@ export declare class Logger implements Extension {
|
|
|
20
63
|
onListen(data: onListenPayload): Promise<void>;
|
|
21
64
|
onDestroy(data: onDestroyPayload): Promise<void>;
|
|
22
65
|
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
66
|
+
private logRawText;
|
|
23
67
|
private log;
|
|
24
68
|
}
|
|
@@ -45,7 +45,16 @@ export interface Extension {
|
|
|
45
45
|
onRequest?(data: onRequestPayload): Promise<any>;
|
|
46
46
|
onUpgrade?(data: onUpgradePayload): Promise<any>;
|
|
47
47
|
}
|
|
48
|
+
export declare type Hook = 'onAuthenticate' | 'onChange' | 'onConnect' | 'onConfigure' |
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
51
|
+
*/
|
|
52
|
+
'onCreateDocument' | 'onLoadDocument' | 'onDestroy' | 'onDisconnect' | 'onListen' | 'onRequest' | 'onUpgrade';
|
|
48
53
|
export interface Configuration extends Extension {
|
|
54
|
+
/**
|
|
55
|
+
* A name for the instance, used for logging.
|
|
56
|
+
*/
|
|
57
|
+
name: string | null;
|
|
49
58
|
/**
|
|
50
59
|
* A list of hocuspocus extenions.
|
|
51
60
|
*/
|
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.54",
|
|
4
4
|
"description": "hocuspocus logging extension",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -15,15 +15,20 @@
|
|
|
15
15
|
"module": "dist/hocuspocus-logger.esm.js",
|
|
16
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.80"
|
|
27
32
|
},
|
|
28
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "f85955a7cca23b23044b0579e96fc8d17c107a4c"
|
|
29
34
|
}
|
package/src/Logger.ts
CHANGED
|
@@ -14,13 +14,67 @@ import {
|
|
|
14
14
|
export interface LoggerConfiguration {
|
|
15
15
|
/**
|
|
16
16
|
* Prepend all logging message with a string.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated
|
|
17
19
|
*/
|
|
18
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,
|
|
19
61
|
}
|
|
20
62
|
|
|
21
63
|
export class Logger implements Extension {
|
|
64
|
+
name: string | null = null
|
|
65
|
+
|
|
22
66
|
configuration: LoggerConfiguration = {
|
|
23
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
|
|
24
78
|
}
|
|
25
79
|
|
|
26
80
|
/**
|
|
@@ -34,49 +88,108 @@ export class Logger implements Extension {
|
|
|
34
88
|
}
|
|
35
89
|
|
|
36
90
|
async onLoadDocument(data: onLoadDocumentPayload) {
|
|
37
|
-
this.
|
|
91
|
+
if (this.configuration.onLoadDocument) {
|
|
92
|
+
this.log(`Loaded document "${data.documentName}".`)
|
|
93
|
+
}
|
|
38
94
|
}
|
|
39
95
|
|
|
40
96
|
async onChange(data: onChangePayload) {
|
|
41
|
-
this.
|
|
97
|
+
if (this.configuration.onChange) {
|
|
98
|
+
this.log(`Document "${data.documentName}" changed.`)
|
|
99
|
+
}
|
|
42
100
|
}
|
|
43
101
|
|
|
44
102
|
async onConnect(data: onConnectPayload) {
|
|
45
|
-
this.
|
|
103
|
+
if (this.configuration.onConnect) {
|
|
104
|
+
this.log(`New connection to "${data.documentName}".`)
|
|
105
|
+
}
|
|
46
106
|
}
|
|
47
107
|
|
|
48
108
|
async onDisconnect(data: onDisconnectPayload) {
|
|
49
|
-
this.
|
|
109
|
+
if (this.configuration.onDisconnect) {
|
|
110
|
+
this.log(`Connection to "${data.documentName}" closed.`)
|
|
111
|
+
}
|
|
50
112
|
}
|
|
51
113
|
|
|
52
114
|
async onUpgrade(data: onUpgradePayload) {
|
|
53
|
-
this.
|
|
115
|
+
if (this.configuration.onUpgrade) {
|
|
116
|
+
this.log('Upgrading connection …')
|
|
117
|
+
}
|
|
54
118
|
}
|
|
55
119
|
|
|
56
120
|
async onRequest(data: onRequestPayload) {
|
|
57
|
-
this.
|
|
121
|
+
if (this.configuration.onRequest) {
|
|
122
|
+
this.log(`Incoming HTTP Request to ${data.request.url}`)
|
|
123
|
+
}
|
|
58
124
|
}
|
|
59
125
|
|
|
60
126
|
async onListen(data: onListenPayload) {
|
|
61
|
-
this.
|
|
127
|
+
if (this.configuration.onListen) {
|
|
128
|
+
this.logRawText('Ready.')
|
|
129
|
+
this.logRawText()
|
|
130
|
+
}
|
|
62
131
|
}
|
|
63
132
|
|
|
64
133
|
async onDestroy(data: onDestroyPayload) {
|
|
65
|
-
this.
|
|
134
|
+
if (this.configuration.onDestroy) {
|
|
135
|
+
this.log('Shut down.')
|
|
136
|
+
}
|
|
66
137
|
}
|
|
67
138
|
|
|
68
139
|
async onConfigure(data: onConfigurePayload) {
|
|
69
|
-
this.
|
|
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)
|
|
70
181
|
}
|
|
71
182
|
|
|
72
183
|
private log(message: string) {
|
|
73
|
-
message = `[${(new Date()).toISOString()}] ${message}
|
|
184
|
+
message = `[${(new Date()).toISOString()}] ${message}`
|
|
74
185
|
|
|
75
|
-
|
|
76
|
-
|
|
186
|
+
const name = this.name ? this.name : this.configuration.prefix
|
|
187
|
+
|
|
188
|
+
if (name) {
|
|
189
|
+
message = `[${name}] ${message}`
|
|
77
190
|
}
|
|
78
191
|
|
|
79
|
-
|
|
192
|
+
this.logRawText(message)
|
|
80
193
|
}
|
|
81
194
|
|
|
82
195
|
}
|