@hocuspocus/extension-logger 1.0.0-alpha.59 → 1.0.0-alpha.60
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 +14 -45
- package/dist/hocuspocus-logger.cjs.map +1 -1
- package/dist/hocuspocus-logger.esm.js +14 -45
- package/dist/hocuspocus-logger.esm.js.map +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +2 -8
- package/dist/packages/server/src/Hocuspocus.d.ts +5 -2
- package/dist/packages/server/src/types.d.ts +4 -0
- package/package.json +3 -3
- package/src/Logger.ts +17 -63
|
@@ -16,7 +16,6 @@ class Logger {
|
|
|
16
16
|
onDisconnect: true,
|
|
17
17
|
onUpgrade: true,
|
|
18
18
|
onRequest: true,
|
|
19
|
-
onListen: true,
|
|
20
19
|
onDestroy: true,
|
|
21
20
|
onConfigure: true,
|
|
22
21
|
log: console.log, // eslint-disable-line
|
|
@@ -26,6 +25,15 @@ class Logger {
|
|
|
26
25
|
...configuration,
|
|
27
26
|
};
|
|
28
27
|
}
|
|
28
|
+
async onConfigure(data) {
|
|
29
|
+
this.name = data.instance.configuration.name;
|
|
30
|
+
if (!this.configuration.onConfigure) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (this.configuration.prefix) {
|
|
34
|
+
console.warn('[hocuspocus warn] The Logger \'prefix\' is deprecated. Pass a \'name\' to the Hocuspocus configuration instead.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
29
37
|
async onLoadDocument(data) {
|
|
30
38
|
if (this.configuration.onLoadDocument) {
|
|
31
39
|
this.log(`Loaded document "${data.documentName}".`);
|
|
@@ -56,57 +64,18 @@ class Logger {
|
|
|
56
64
|
this.log(`Incoming HTTP Request to ${data.request.url}`);
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
|
-
async onListen(data) {
|
|
60
|
-
if (this.configuration.onListen) {
|
|
61
|
-
this.logRawText('Ready.');
|
|
62
|
-
this.logRawText();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
67
|
async onDestroy(data) {
|
|
66
68
|
if (this.configuration.onDestroy) {
|
|
67
69
|
this.log('Shut down.');
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
|
-
async onConfigure(data) {
|
|
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);
|
|
102
|
-
}
|
|
103
72
|
log(message) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (name) {
|
|
107
|
-
message = `[${name}] ${message}`;
|
|
73
|
+
const date = (new Date()).toISOString();
|
|
74
|
+
message = `${date} ${message}`;
|
|
75
|
+
if (this.name) {
|
|
76
|
+
message = `[${this.name}] ${message}`;
|
|
108
77
|
}
|
|
109
|
-
this.
|
|
78
|
+
this.configuration.log(message);
|
|
110
79
|
}
|
|
111
80
|
}
|
|
112
81
|
|
|
@@ -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
|
|
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 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 `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 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 onConfigure(data: onConfigurePayload) {\n this.name = data.instance.configuration.name\n\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\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 onDestroy(data: onDestroyPayload) {\n if (this.configuration.onDestroy) {\n this.log('Shut down.')\n }\n }\n\n private log(message: string) {\n const date = (new Date()).toISOString()\n message = `${date} ${message}`\n\n if (this.name) {\n message = `[${this.name}] ${message}`\n }\n\n this.configuration.log(message)\n }\n\n}\n"],"names":[],"mappings":";;;;MAyDa,MAAM;;;;IAmBjB,YAAY,aAA4C;QAlBxD,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,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,WAAW,CAAC,IAAwB;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAA;QAE5C,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE;YACnC,OAAM;SACP;QAED,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;YAC7B,OAAO,CAAC,IAAI,CAAC,iHAAiH,CAAC,CAAA;SAChI;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,MAAM,YAAY,CAAC,IAAyB;QAC1C,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;YACnC,IAAI,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,YAAY,WAAW,CAAC,CAAA;SACzD;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;SACnC;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,4BAA4B,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;SACzD;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;SACvB;KACF;IAEO,GAAG,CAAC,OAAe;QACzB,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,WAAW,EAAE,CAAA;QACvC,OAAO,GAAG,GAAG,IAAI,IAAI,OAAO,EAAE,CAAA;QAE9B,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,OAAO,GAAG,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAA;SACtC;QAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;KAChC;;;;;"}
|
|
@@ -12,7 +12,6 @@ class Logger {
|
|
|
12
12
|
onDisconnect: true,
|
|
13
13
|
onUpgrade: true,
|
|
14
14
|
onRequest: true,
|
|
15
|
-
onListen: true,
|
|
16
15
|
onDestroy: true,
|
|
17
16
|
onConfigure: true,
|
|
18
17
|
log: console.log, // eslint-disable-line
|
|
@@ -22,6 +21,15 @@ class Logger {
|
|
|
22
21
|
...configuration,
|
|
23
22
|
};
|
|
24
23
|
}
|
|
24
|
+
async onConfigure(data) {
|
|
25
|
+
this.name = data.instance.configuration.name;
|
|
26
|
+
if (!this.configuration.onConfigure) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (this.configuration.prefix) {
|
|
30
|
+
console.warn('[hocuspocus warn] The Logger \'prefix\' is deprecated. Pass a \'name\' to the Hocuspocus configuration instead.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
async onLoadDocument(data) {
|
|
26
34
|
if (this.configuration.onLoadDocument) {
|
|
27
35
|
this.log(`Loaded document "${data.documentName}".`);
|
|
@@ -52,57 +60,18 @@ class Logger {
|
|
|
52
60
|
this.log(`Incoming HTTP Request to ${data.request.url}`);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
async onListen(data) {
|
|
56
|
-
if (this.configuration.onListen) {
|
|
57
|
-
this.logRawText('Ready.');
|
|
58
|
-
this.logRawText();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
63
|
async onDestroy(data) {
|
|
62
64
|
if (this.configuration.onDestroy) {
|
|
63
65
|
this.log('Shut down.');
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
async onConfigure(data) {
|
|
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);
|
|
98
|
-
}
|
|
99
68
|
log(message) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (name) {
|
|
103
|
-
message = `[${name}] ${message}`;
|
|
69
|
+
const date = (new Date()).toISOString();
|
|
70
|
+
message = `${date} ${message}`;
|
|
71
|
+
if (this.name) {
|
|
72
|
+
message = `[${this.name}] ${message}`;
|
|
104
73
|
}
|
|
105
|
-
this.
|
|
74
|
+
this.configuration.log(message);
|
|
106
75
|
}
|
|
107
76
|
}
|
|
108
77
|
|
|
@@ -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
|
|
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 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 `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 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 onConfigure(data: onConfigurePayload) {\n this.name = data.instance.configuration.name\n\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\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 onDestroy(data: onDestroyPayload) {\n if (this.configuration.onDestroy) {\n this.log('Shut down.')\n }\n }\n\n private log(message: string) {\n const date = (new Date()).toISOString()\n message = `${date} ${message}`\n\n if (this.name) {\n message = `[${this.name}] ${message}`\n }\n\n this.configuration.log(message)\n }\n\n}\n"],"names":[],"mappings":"MAyDa,MAAM;;;;IAmBjB,YAAY,aAA4C;QAlBxD,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,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,WAAW,CAAC,IAAwB;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAA;QAE5C,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE;YACnC,OAAM;SACP;QAED,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;YAC7B,OAAO,CAAC,IAAI,CAAC,iHAAiH,CAAC,CAAA;SAChI;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,MAAM,YAAY,CAAC,IAAyB;QAC1C,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;YACnC,IAAI,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,YAAY,WAAW,CAAC,CAAA;SACzD;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;SACnC;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,4BAA4B,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;SACzD;KACF;IAED,MAAM,SAAS,CAAC,IAAsB;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;SACvB;KACF;IAEO,GAAG,CAAC,OAAe;QACzB,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,WAAW,EAAE,CAAA;QACvC,OAAO,GAAG,GAAG,IAAI,IAAI,OAAO,EAAE,CAAA;QAE9B,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,OAAO,GAAG,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAA;SACtC;QAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;KAChC;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload,
|
|
1
|
+
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
|
|
2
2
|
export interface LoggerConfiguration {
|
|
3
3
|
/**
|
|
4
4
|
* Prepend all logging message with a string.
|
|
@@ -30,10 +30,6 @@ export interface LoggerConfiguration {
|
|
|
30
30
|
* Whether to log something for the `onRequest` hook.
|
|
31
31
|
*/
|
|
32
32
|
onRequest: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Whether to log something for the `onListen` hook.
|
|
35
|
-
*/
|
|
36
|
-
onListen: boolean;
|
|
37
33
|
/**
|
|
38
34
|
* Whether to log something for the `onDestroy` hook.
|
|
39
35
|
*/
|
|
@@ -54,15 +50,13 @@ export declare class Logger implements Extension {
|
|
|
54
50
|
* Constructor
|
|
55
51
|
*/
|
|
56
52
|
constructor(configuration?: Partial<LoggerConfiguration>);
|
|
53
|
+
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
57
54
|
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
58
55
|
onChange(data: onChangePayload): Promise<void>;
|
|
59
56
|
onConnect(data: onConnectPayload): Promise<void>;
|
|
60
57
|
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
61
58
|
onUpgrade(data: onUpgradePayload): Promise<void>;
|
|
62
59
|
onRequest(data: onRequestPayload): Promise<void>;
|
|
63
|
-
onListen(data: onListenPayload): Promise<void>;
|
|
64
60
|
onDestroy(data: onDestroyPayload): Promise<void>;
|
|
65
|
-
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
66
|
-
private logRawText;
|
|
67
61
|
private log;
|
|
68
62
|
}
|
|
@@ -3,13 +3,15 @@ import WebSocket, { WebSocketServer } from 'ws';
|
|
|
3
3
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
4
|
import { Configuration, Hook } from './types';
|
|
5
5
|
import { MessageLogger } from './Debugger';
|
|
6
|
+
import { onListenPayload } from '.';
|
|
6
7
|
export declare const defaultConfiguration: {
|
|
7
8
|
name: null;
|
|
8
9
|
port: number;
|
|
9
10
|
timeout: number;
|
|
11
|
+
quiet: boolean;
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
|
-
* Hocuspocus
|
|
14
|
+
* Hocuspocus Server
|
|
13
15
|
*/
|
|
14
16
|
export declare class Hocuspocus {
|
|
15
17
|
configuration: Configuration;
|
|
@@ -25,7 +27,8 @@ export declare class Hocuspocus {
|
|
|
25
27
|
/**
|
|
26
28
|
* Start the server
|
|
27
29
|
*/
|
|
28
|
-
listen(): Promise<void>;
|
|
30
|
+
listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<void>;
|
|
31
|
+
private showStartScreen;
|
|
29
32
|
/**
|
|
30
33
|
* Get the total number of active documents
|
|
31
34
|
*/
|
|
@@ -67,6 +67,10 @@ export interface Configuration extends Extension {
|
|
|
67
67
|
* Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
|
|
68
68
|
*/
|
|
69
69
|
timeout: number;
|
|
70
|
+
/**
|
|
71
|
+
* By default, the servers show a start screen. If passed false, the server will start quietly.
|
|
72
|
+
*/
|
|
73
|
+
quiet: boolean;
|
|
70
74
|
/**
|
|
71
75
|
* Function which returns the (customized) document name based on the request
|
|
72
76
|
*/
|
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.60",
|
|
4
4
|
"description": "hocuspocus logging extension",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@hocuspocus/server": "^1.0.0-alpha.
|
|
31
|
+
"@hocuspocus/server": "^1.0.0-alpha.86"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "505fc82451201ef77847dc5bc9e92edb498dcb8e"
|
|
34
34
|
}
|
package/src/Logger.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
onLoadDocumentPayload,
|
|
7
7
|
onDestroyPayload,
|
|
8
8
|
onDisconnectPayload,
|
|
9
|
-
onListenPayload,
|
|
10
9
|
onRequestPayload,
|
|
11
10
|
onUpgradePayload,
|
|
12
11
|
} from '@hocuspocus/server'
|
|
@@ -42,10 +41,6 @@ export interface LoggerConfiguration {
|
|
|
42
41
|
* Whether to log something for the `onRequest` hook.
|
|
43
42
|
*/
|
|
44
43
|
onRequest: boolean,
|
|
45
|
-
/**
|
|
46
|
-
* Whether to log something for the `onListen` hook.
|
|
47
|
-
*/
|
|
48
|
-
onListen: boolean,
|
|
49
44
|
/**
|
|
50
45
|
* Whether to log something for the `onDestroy` hook.
|
|
51
46
|
*/
|
|
@@ -71,7 +66,6 @@ export class Logger implements Extension {
|
|
|
71
66
|
onDisconnect: true,
|
|
72
67
|
onUpgrade: true,
|
|
73
68
|
onRequest: true,
|
|
74
|
-
onListen: true,
|
|
75
69
|
onDestroy: true,
|
|
76
70
|
onConfigure: true,
|
|
77
71
|
log: console.log, // eslint-disable-line
|
|
@@ -87,6 +81,18 @@ export class Logger implements Extension {
|
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
83
|
|
|
84
|
+
async onConfigure(data: onConfigurePayload) {
|
|
85
|
+
this.name = data.instance.configuration.name
|
|
86
|
+
|
|
87
|
+
if (!this.configuration.onConfigure) {
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (this.configuration.prefix) {
|
|
92
|
+
console.warn('[hocuspocus warn] The Logger \'prefix\' is deprecated. Pass a \'name\' to the Hocuspocus configuration instead.')
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
90
96
|
async onLoadDocument(data: onLoadDocumentPayload) {
|
|
91
97
|
if (this.configuration.onLoadDocument) {
|
|
92
98
|
this.log(`Loaded document "${data.documentName}".`)
|
|
@@ -123,73 +129,21 @@ export class Logger implements Extension {
|
|
|
123
129
|
}
|
|
124
130
|
}
|
|
125
131
|
|
|
126
|
-
async onListen(data: onListenPayload) {
|
|
127
|
-
if (this.configuration.onListen) {
|
|
128
|
-
this.logRawText('Ready.')
|
|
129
|
-
this.logRawText()
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
132
|
async onDestroy(data: onDestroyPayload) {
|
|
134
133
|
if (this.configuration.onDestroy) {
|
|
135
134
|
this.log('Shut down.')
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
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
138
|
private log(message: string) {
|
|
184
|
-
|
|
139
|
+
const date = (new Date()).toISOString()
|
|
140
|
+
message = `${date} ${message}`
|
|
185
141
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (name) {
|
|
189
|
-
message = `[${name}] ${message}`
|
|
142
|
+
if (this.name) {
|
|
143
|
+
message = `[${this.name}] ${message}`
|
|
190
144
|
}
|
|
191
145
|
|
|
192
|
-
this.
|
|
146
|
+
this.configuration.log(message)
|
|
193
147
|
}
|
|
194
148
|
|
|
195
149
|
}
|