@hocuspocus/extension-logger 1.0.0-alpha.58 → 1.0.0-alpha.62
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 +15 -45
- package/dist/hocuspocus-logger.cjs.map +1 -1
- package/dist/hocuspocus-logger.esm.js +15 -45
- package/dist/hocuspocus-logger.esm.js.map +1 -1
- package/dist/packages/extension-database/src/Database.d.ts +36 -0
- package/dist/packages/extension-database/src/index.d.ts +1 -0
- package/dist/packages/extension-logger/src/Logger.d.ts +2 -8
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
- package/dist/packages/extension-webhook/src/index.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +10 -0
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +1 -1
- package/dist/packages/provider/src/index.d.ts +1 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +6 -3
- package/dist/packages/server/src/types.d.ts +6 -1
- package/dist/{demos/backend/src/express.d.ts → playground/backend/src/default.d.ts} +0 -0
- package/dist/{demos/backend/src/koa.d.ts → playground/backend/src/express.d.ts} +0 -0
- package/dist/{demos/backend/src/load-document.d.ts → playground/backend/src/koa.d.ts} +0 -0
- package/dist/{demos/backend/src/minimal.d.ts → playground/backend/src/load-document.d.ts} +0 -0
- package/dist/{demos → playground}/backend/src/monitor.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/redis.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/slow.d.ts +0 -0
- package/dist/{demos → playground}/backend/src/webhook.d.ts +0 -0
- package/package.json +3 -3
- package/src/Logger.ts +18 -62
|
@@ -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,19 @@ 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
|
-
|
|
73
|
+
const date = (new Date()).toISOString();
|
|
74
|
+
let meta = `${date}`;
|
|
75
|
+
if (this.name) {
|
|
76
|
+
meta = `${this.name} ${meta}`;
|
|
108
77
|
}
|
|
109
|
-
|
|
78
|
+
message = `[${meta}] ${message}`;
|
|
79
|
+
this.configuration.log(message);
|
|
110
80
|
}
|
|
111
81
|
}
|
|
112
82
|
|
|
@@ -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 let meta = `${date}`\n\n if (this.name) {\n meta = `${this.name} ${meta}`\n }\n\n message = `[${meta}] ${message}`\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,cA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AE,CAAA;QAEpB,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAA;SAC9B;QAED,OAAO,GAAG,IAAI,IAAI,KAAK,OAAO,EAAE,CAAA;QAEhC,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,19 @@ 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
|
-
|
|
69
|
+
const date = (new Date()).toISOString();
|
|
70
|
+
let meta = `${date}`;
|
|
71
|
+
if (this.name) {
|
|
72
|
+
meta = `${this.name} ${meta}`;
|
|
104
73
|
}
|
|
105
|
-
|
|
74
|
+
message = `[${meta}] ${message}`;
|
|
75
|
+
this.configuration.log(message);
|
|
106
76
|
}
|
|
107
77
|
}
|
|
108
78
|
|
|
@@ -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 let meta = `${date}`\n\n if (this.name) {\n meta = `${this.name} ${meta}`\n }\n\n message = `[${meta}] ${message}`\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;S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AAI,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,IAAI,IAAI,GAAG,GAAG,IAAI,EAAE,CAAA;QAEpB,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAA;SAC9B;QAED,OAAO,GAAG,IAAI,IAAI,KAAK,OAAO,EAAE,CAAA;QAEhC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;KAChC;;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server';
|
|
3
|
+
export interface DatabaseConfiguration {
|
|
4
|
+
/**
|
|
5
|
+
* Pass a Promise to retrieve updates from your database. The Promise should resolve to
|
|
6
|
+
* an array of items with Y.js-compatible binary data.
|
|
7
|
+
*/
|
|
8
|
+
fetchUpdates: ({ documentName }: {
|
|
9
|
+
documentName: string;
|
|
10
|
+
}) => Promise<Uint8Array[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Pass a function to store updates in your database.
|
|
13
|
+
*/
|
|
14
|
+
storeUpdate: ({ update, documentName }: {
|
|
15
|
+
update: Buffer;
|
|
16
|
+
documentName: string;
|
|
17
|
+
}) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare class Database implements Extension {
|
|
20
|
+
/**
|
|
21
|
+
* Default configuration
|
|
22
|
+
*/
|
|
23
|
+
configuration: DatabaseConfiguration;
|
|
24
|
+
/**
|
|
25
|
+
* Constructor
|
|
26
|
+
*/
|
|
27
|
+
constructor(configuration: Partial<DatabaseConfiguration>);
|
|
28
|
+
/**
|
|
29
|
+
* Get stored data from the database.
|
|
30
|
+
*/
|
|
31
|
+
onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Store new updates in the database.
|
|
34
|
+
*/
|
|
35
|
+
onChange({ document, documentName }: onChangePayload): Promise<void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Database';
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
|
|
2
|
+
import sqlite3 from 'sqlite3';
|
|
3
|
+
export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
4
|
+
/**
|
|
5
|
+
* Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
|
|
6
|
+
* string for an anonymous disk-based database. Anonymous databases are not persisted and
|
|
7
|
+
* when closing the database handle, their contents are lost.
|
|
8
|
+
*
|
|
9
|
+
* https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
|
|
10
|
+
*/
|
|
11
|
+
database: string;
|
|
12
|
+
/**
|
|
13
|
+
* The database schema to create.
|
|
14
|
+
*/
|
|
15
|
+
schema: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class SQLite extends Database {
|
|
18
|
+
db?: sqlite3.Database;
|
|
19
|
+
configuration: SQLiteConfiguration;
|
|
20
|
+
/**
|
|
21
|
+
* Constructor
|
|
22
|
+
*/
|
|
23
|
+
constructor(configuration?: Partial<SQLiteConfiguration>);
|
|
24
|
+
onListen(): Promise<void>;
|
|
25
|
+
onConfigure(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SQLite';
|
|
@@ -42,7 +42,7 @@ export declare class Webhook implements Extension {
|
|
|
42
42
|
/**
|
|
43
43
|
* Send a request to the given url containing the given data
|
|
44
44
|
*/
|
|
45
|
-
sendRequest(event: Events, payload: any): Promise<AxiosResponse<
|
|
45
|
+
sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
|
|
46
46
|
/**
|
|
47
47
|
* onChange hook
|
|
48
48
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderOptions } from './HocuspocusProvider';
|
|
2
|
+
export interface HocuspocusCloudProviderOptions extends HocuspocusProviderOptions {
|
|
3
|
+
/**
|
|
4
|
+
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
5
|
+
*/
|
|
6
|
+
key: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
9
|
+
constructor(options: HocuspocusCloudProviderOptions);
|
|
10
|
+
}
|
|
@@ -130,7 +130,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
130
130
|
get awareness(): Awareness;
|
|
131
131
|
checkConnection(): void;
|
|
132
132
|
forceSync(): void;
|
|
133
|
-
|
|
133
|
+
registerEventListeners(): void;
|
|
134
134
|
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
135
135
|
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
136
136
|
permissionDeniedHandler(reason: string): void;
|
|
@@ -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;
|
|
@@ -21,11 +23,12 @@ export declare class Hocuspocus {
|
|
|
21
23
|
* Configure the server
|
|
22
24
|
*/
|
|
23
25
|
configure(configuration: Partial<Configuration>): Hocuspocus;
|
|
24
|
-
get
|
|
26
|
+
get requiresAuthentication(): boolean;
|
|
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
|
*/
|
|
@@ -27,6 +27,7 @@ export interface AwarenessUpdate {
|
|
|
27
27
|
}
|
|
28
28
|
export interface ConnectionConfig {
|
|
29
29
|
readOnly: boolean;
|
|
30
|
+
requiresAuthentication: boolean;
|
|
30
31
|
isAuthenticated: boolean;
|
|
31
32
|
}
|
|
32
33
|
export interface Extension {
|
|
@@ -67,6 +68,10 @@ export interface Configuration extends Extension {
|
|
|
67
68
|
* Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
|
|
68
69
|
*/
|
|
69
70
|
timeout: number;
|
|
71
|
+
/**
|
|
72
|
+
* By default, the servers show a start screen. If passed false, the server will start quietly.
|
|
73
|
+
*/
|
|
74
|
+
quiet: boolean;
|
|
70
75
|
/**
|
|
71
76
|
* Function which returns the (customized) document name based on the request
|
|
72
77
|
*/
|
|
@@ -74,7 +79,7 @@ export interface Configuration extends Extension {
|
|
|
74
79
|
documentName: string;
|
|
75
80
|
request: IncomingMessage;
|
|
76
81
|
requestParameters: URLSearchParams;
|
|
77
|
-
}): string
|
|
82
|
+
}): string | Promise<string>;
|
|
78
83
|
}
|
|
79
84
|
export interface onAuthenticatePayload {
|
|
80
85
|
documentName: string;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
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.62",
|
|
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.88"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "09919438a0a220ffb7479afc562872c8726cc4b4"
|
|
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,23 @@ 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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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')
|
|
138
|
+
private log(message: string) {
|
|
139
|
+
const date = (new Date()).toISOString()
|
|
140
|
+
let meta = `${date}`
|
|
163
141
|
|
|
164
|
-
if (
|
|
165
|
-
|
|
142
|
+
if (this.name) {
|
|
143
|
+
meta = `${this.name} ${meta}`
|
|
166
144
|
}
|
|
167
145
|
|
|
168
|
-
|
|
169
|
-
this.logRawText('Extensions:')
|
|
146
|
+
message = `[${meta}] ${message}`
|
|
170
147
|
|
|
171
|
-
extensions
|
|
172
|
-
.forEach(name => {
|
|
173
|
-
this.logRawText(`- ${name}`)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
this.logRawText()
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private logRawText(message = '') {
|
|
180
148
|
this.configuration.log(message)
|
|
181
149
|
}
|
|
182
150
|
|
|
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
151
|
}
|