@hocuspocus/extension-logger 1.0.0-alpha.63 → 1.0.0-alpha.67

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.
Files changed (80) hide show
  1. package/dist/hocuspocus-logger.cjs +6 -0
  2. package/dist/hocuspocus-logger.cjs.map +1 -1
  3. package/dist/hocuspocus-logger.esm.js +6 -0
  4. package/dist/hocuspocus-logger.esm.js.map +1 -1
  5. package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
  6. package/dist/packages/common/src/index.d.ts +1 -0
  7. package/dist/packages/extension-database/src/Database.d.ts +5 -9
  8. package/dist/packages/extension-logger/src/Logger.d.ts +5 -0
  9. package/dist/packages/extension-sqlite/src/SQLite.d.ts +4 -4
  10. package/dist/packages/extension-throttle/src/index.d.ts +6 -2
  11. package/dist/packages/extension-webhook/src/index.d.ts +1 -2
  12. package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
  13. package/dist/packages/provider/src/HocuspocusProvider.d.ts +7 -4
  14. package/dist/packages/provider/src/index.d.ts +0 -1
  15. package/dist/packages/provider/src/types.d.ts +10 -0
  16. package/dist/packages/server/src/Connection.d.ts +4 -4
  17. package/dist/packages/server/src/Debugger.d.ts +1 -2
  18. package/dist/packages/server/src/Document.d.ts +8 -5
  19. package/dist/packages/server/src/Hocuspocus.d.ts +23 -12
  20. package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
  21. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
  22. package/dist/packages/server/src/index.d.ts +7 -0
  23. package/dist/packages/server/src/types.d.ts +87 -15
  24. package/dist/tests/extension-logger/onListen.d.ts +1 -0
  25. package/dist/tests/extension-redis/onLoadDocument.d.ts +1 -0
  26. package/dist/tests/extension-redis/onSynced.d.ts +1 -0
  27. package/dist/tests/extension-redis-rewrite/closeConnections.d.ts +1 -0
  28. package/dist/tests/extension-redis-rewrite/getConnectionCount.d.ts +1 -0
  29. package/dist/tests/extension-redis-rewrite/getDocumentsCount.d.ts +1 -0
  30. package/dist/tests/extension-redis-rewrite/onAwarenessChange.d.ts +1 -0
  31. package/dist/tests/extension-redis-rewrite/onChange.d.ts +1 -0
  32. package/dist/tests/extension-redis-rewrite/onStoreDocument.d.ts +1 -0
  33. package/dist/tests/extension-rocksdb/onLoadDocument.d.ts +1 -0
  34. package/dist/tests/extension-throttle/configuration.d.ts +1 -0
  35. package/dist/tests/provider/configuration.d.ts +1 -0
  36. package/dist/tests/provider/observeDeep.d.ts +1 -0
  37. package/dist/tests/provider/onAuthenticated.d.ts +1 -0
  38. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
  39. package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
  40. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
  41. package/dist/tests/provider/onClose.d.ts +1 -0
  42. package/dist/tests/provider/onConnect.d.ts +1 -0
  43. package/dist/tests/provider/onDisconnect.d.ts +1 -0
  44. package/dist/tests/provider/onMessage.d.ts +1 -0
  45. package/dist/tests/provider/onOpen.d.ts +1 -0
  46. package/dist/tests/provider/onSynced.d.ts +1 -0
  47. package/dist/tests/server/address.d.ts +1 -0
  48. package/dist/tests/server/afterStoreDocument.d.ts +1 -0
  49. package/dist/tests/server/closeConnections.d.ts +1 -0
  50. package/dist/tests/server/getConnectionsCount.d.ts +1 -0
  51. package/dist/tests/server/getDocumentName.d.ts +1 -0
  52. package/dist/tests/server/getDocumentsCount.d.ts +1 -0
  53. package/dist/tests/server/getMessageLogs.d.ts +1 -0
  54. package/dist/tests/server/listen.d.ts +1 -0
  55. package/dist/tests/server/onAuthenticate.d.ts +1 -0
  56. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
  57. package/dist/tests/server/onChange.d.ts +1 -0
  58. package/dist/tests/server/onConfigure.d.ts +1 -0
  59. package/dist/tests/server/onConnect.d.ts +1 -0
  60. package/dist/tests/server/onDestroy.d.ts +1 -0
  61. package/dist/tests/server/onDisconnect.d.ts +1 -0
  62. package/dist/tests/server/onListen.d.ts +1 -0
  63. package/dist/tests/server/onLoadDocument.d.ts +1 -0
  64. package/dist/tests/server/onRequest.d.ts +1 -0
  65. package/dist/tests/server/onStoreDocument.d.ts +1 -0
  66. package/dist/tests/server/onUpgrade.d.ts +1 -0
  67. package/dist/tests/server/requiresAuthentication.d.ts +1 -0
  68. package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
  69. package/dist/tests/utils/createDirectory.d.ts +1 -0
  70. package/dist/tests/utils/flushRedis.d.ts +1 -0
  71. package/dist/tests/utils/index.d.ts +7 -0
  72. package/dist/tests/utils/newHocuspocus.d.ts +2 -0
  73. package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
  74. package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
  75. package/dist/tests/utils/removeDirectory.d.ts +1 -0
  76. package/dist/tests/utils/sleep.d.ts +1 -0
  77. package/package.json +3 -3
  78. package/src/Logger.ts +11 -0
  79. package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
  80. package/dist/packages/provider/src/utils/index.d.ts +0 -1
@@ -12,6 +12,7 @@ class Logger {
12
12
  prefix: null,
13
13
  onLoadDocument: true,
14
14
  onChange: true,
15
+ onStoreDocument: true,
15
16
  onConnect: true,
16
17
  onDisconnect: true,
17
18
  onUpgrade: true,
@@ -44,6 +45,11 @@ class Logger {
44
45
  this.log(`Document "${data.documentName}" changed.`);
45
46
  }
46
47
  }
48
+ async onStoreDocument(data) {
49
+ if (this.configuration.onStoreDocument) {
50
+ this.log(`Store "${data.documentName}".`);
51
+ }
52
+ }
47
53
  async onConnect(data) {
48
54
  if (this.configuration.onConnect) {
49
55
  this.log(`New connection to "${data.documentName}".`);
@@ -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 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;KAC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,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;;;;;"}
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 `onStoreDocument` hook.\n */\n onStoreDocument: 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 onStoreDocument: 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 onStoreDocument(data: onDisconnectPayload) {\n if (this.configuration.onStoreDocument) {\n this.log(`Store \"${data.documentName}\".`)\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":";;;;MA6Da,MAAM;;;;IAoBjB,YAAY,aAA4C;QAnBxD,SAAI,GAAkB,IAAI,CAAA;QAE1B,kBAAa,GAAwB;YACnC,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,IAAI;YACpB,QAAQ,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AAY,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,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;;;;;"}
@@ -8,6 +8,7 @@ class Logger {
8
8
  prefix: null,
9
9
  onLoadDocument: true,
10
10
  onChange: true,
11
+ onStoreDocument: true,
11
12
  onConnect: true,
12
13
  onDisconnect: true,
13
14
  onUpgrade: true,
@@ -40,6 +41,11 @@ class Logger {
40
41
  this.log(`Document "${data.documentName}" changed.`);
41
42
  }
42
43
  }
44
+ async onStoreDocument(data) {
45
+ if (this.configuration.onStoreDocument) {
46
+ this.log(`Store "${data.documentName}".`);
47
+ }
48
+ }
43
49
  async onConnect(data) {
44
50
  if (this.configuration.onConnect) {
45
51
  this.log(`New connection to "${data.documentName}".`);
@@ -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 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,G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AAE;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;;;;;"}
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 `onStoreDocument` hook.\n */\n onStoreDocument: 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 onStoreDocument: 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 onStoreDocument(data: onDisconnectPayload) {\n if (this.configuration.onStoreDocument) {\n this.log(`Store \"${data.documentName}\".`)\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":"MA6Da,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,eAAe,EAAE,IAAI;YACrB,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,GA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AI,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,3 @@
1
+ export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
2
+ clientId: number;
3
+ }[];
@@ -1,2 +1,3 @@
1
1
  export * from './auth';
2
2
  export * from './CloseEvents';
3
+ export * from './awarenessStatesToArray';
@@ -1,20 +1,16 @@
1
- /// <reference types="node" />
2
- import { Extension, onChangePayload, onLoadDocumentPayload } from '@hocuspocus/server';
1
+ import { Extension, onChangePayload, onLoadDocumentPayload, storePayload } from '@hocuspocus/server';
3
2
  export interface DatabaseConfiguration {
4
3
  /**
5
4
  * Pass a Promise to retrieve updates from your database. The Promise should resolve to
6
5
  * an array of items with Y.js-compatible binary data.
7
6
  */
8
- fetchUpdates: ({ documentName }: {
7
+ fetch: ({ documentName }: {
9
8
  documentName: string;
10
- }) => Promise<Uint8Array[]>;
9
+ }) => Promise<Uint8Array | null>;
11
10
  /**
12
11
  * Pass a function to store updates in your database.
13
12
  */
14
- storeUpdate: ({ update, documentName }: {
15
- update: Buffer;
16
- documentName: string;
17
- }) => void;
13
+ store: (data: storePayload) => void;
18
14
  }
19
15
  export declare class Database implements Extension {
20
16
  /**
@@ -32,5 +28,5 @@ export declare class Database implements Extension {
32
28
  /**
33
29
  * Store new updates in the database.
34
30
  */
35
- onChange({ document, documentName }: onChangePayload): Promise<void>;
31
+ onStoreDocument(data: onChangePayload): Promise<void>;
36
32
  }
@@ -14,6 +14,10 @@ export interface LoggerConfiguration {
14
14
  * Whether to log something for the `onChange` hook.
15
15
  */
16
16
  onChange: boolean;
17
+ /**
18
+ * Whether to log something for the `onStoreDocument` hook.
19
+ */
20
+ onStoreDocument: boolean;
17
21
  /**
18
22
  * Whether to log something for the `onConnect` hook.
19
23
  */
@@ -53,6 +57,7 @@ export declare class Logger implements Extension {
53
57
  onConfigure(data: onConfigurePayload): Promise<void>;
54
58
  onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
55
59
  onChange(data: onChangePayload): Promise<void>;
60
+ onStoreDocument(data: onDisconnectPayload): Promise<void>;
56
61
  onConnect(data: onConnectPayload): Promise<void>;
57
62
  onDisconnect(data: onDisconnectPayload): Promise<void>;
58
63
  onUpgrade(data: onUpgradePayload): Promise<void>;
@@ -1,5 +1,8 @@
1
1
  import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
2
2
  import sqlite3 from 'sqlite3';
3
+ export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
4
+ export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
5
+ export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
3
6
  export interface SQLiteConfiguration extends DatabaseConfiguration {
4
7
  /**
5
8
  * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
@@ -17,10 +20,7 @@ export interface SQLiteConfiguration extends DatabaseConfiguration {
17
20
  export declare class SQLite extends Database {
18
21
  db?: sqlite3.Database;
19
22
  configuration: SQLiteConfiguration;
20
- /**
21
- * Constructor
22
- */
23
23
  constructor(configuration?: Partial<SQLiteConfiguration>);
24
- onListen(): Promise<void>;
25
24
  onConfigure(): Promise<void>;
25
+ onListen(): Promise<void>;
26
26
  }
@@ -1,12 +1,16 @@
1
1
  import { Extension, onConnectPayload } from '@hocuspocus/server';
2
- export interface Configuration {
2
+ export interface ThrottleConfiguration {
3
3
  throttle: number | null | false;
4
4
  banTime: number;
5
5
  }
6
6
  export declare class Throttle implements Extension {
7
- configuration: Configuration;
7
+ configuration: ThrottleConfiguration;
8
8
  connectionsByIp: Map<string, Array<number>>;
9
9
  bannedIps: Map<string, number>;
10
+ /**
11
+ * Constructor
12
+ */
13
+ constructor(configuration?: Partial<ThrottleConfiguration>);
10
14
  /**
11
15
  * Throttle requests
12
16
  * @private
@@ -3,7 +3,6 @@ import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, on
3
3
  import { Doc } from 'yjs';
4
4
  import { Transformer } from '@hocuspocus/transformer';
5
5
  import { AxiosResponse } from 'axios';
6
- import Timeout = NodeJS.Timeout;
7
6
  export declare enum Events {
8
7
  onChange = "change",
9
8
  onConnect = "connect",
@@ -24,7 +23,7 @@ export interface Configuration {
24
23
  export declare class Webhook implements Extension {
25
24
  configuration: Configuration;
26
25
  debounced: Map<string, {
27
- timeout: Timeout;
26
+ timeout: NodeJS.Timeout;
28
27
  start: number;
29
28
  }>;
30
29
  /**
@@ -5,5 +5,5 @@ export default class EventEmitter {
5
5
  on(event: string, fn: Function): this;
6
6
  protected emit(event: string, ...args: any): this;
7
7
  off(event: string, fn?: Function): this;
8
- protected removeAllListeners(): void;
8
+ removeAllListeners(): void;
9
9
  }
@@ -1,10 +1,11 @@
1
1
  import * as Y from 'yjs';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import * as mutex from 'lib0/mutex';
4
- import { Event, CloseEvent, MessageEvent } from 'ws';
4
+ import type { Event, CloseEvent, MessageEvent } from 'ws';
5
5
  import EventEmitter from './EventEmitter';
6
6
  import { OutgoingMessage } from './OutgoingMessage';
7
7
  import { ConstructableOutgoingMessage } from './types';
8
+ import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
8
9
  export declare enum WebSocketStatus {
9
10
  Connecting = "connecting",
10
11
  Connected = "connected",
@@ -99,12 +100,14 @@ export interface CompleteHocuspocusProviderConfiguration {
99
100
  onMessage: (event: MessageEvent) => void;
100
101
  onOutgoingMessage: (message: OutgoingMessage) => void;
101
102
  onStatus: (status: any) => void;
102
- onSynced: () => void;
103
+ onSynced: ({ state }: {
104
+ state: boolean;
105
+ }) => void;
103
106
  onDisconnect: (event: CloseEvent) => void;
104
107
  onClose: (event: CloseEvent) => void;
105
108
  onDestroy: () => void;
106
- onAwarenessUpdate: (states: any) => void;
107
- onAwarenessChange: (states: any) => void;
109
+ onAwarenessUpdate: ({ states }: onAwarenessUpdateParameters) => void;
110
+ onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void;
108
111
  /**
109
112
  * Don’t output any warnings.
110
113
  */
@@ -1,4 +1,3 @@
1
1
  export * from './HocuspocusProvider';
2
2
  export * from './HocuspocusCloudProvider';
3
3
  export * from './types';
4
- export * from './utils';
@@ -32,3 +32,13 @@ export interface Constructable<T> {
32
32
  new (...args: any): T;
33
33
  }
34
34
  export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
35
+ export declare type onAwarenessUpdateParameters = {
36
+ states: StatesArray;
37
+ };
38
+ export declare type onAwarenessChangeParameters = {
39
+ states: StatesArray;
40
+ };
41
+ export declare type StatesArray = {
42
+ clientId: number;
43
+ [key: string | number]: any;
44
+ }[];
@@ -4,8 +4,8 @@ import WebSocket from 'ws';
4
4
  import { IncomingMessage as HTTPIncomingMessage } from 'http';
5
5
  import { CloseEvent } from '@hocuspocus/common';
6
6
  import Document from './Document';
7
- import { MessageLogger } from './Debugger';
8
- declare class Connection {
7
+ import { Debugger } from './Debugger';
8
+ export declare class Connection {
9
9
  webSocket: WebSocket;
10
10
  context: any;
11
11
  document: Document;
@@ -17,11 +17,11 @@ declare class Connection {
17
17
  socketId: string;
18
18
  lock: AsyncLock;
19
19
  readOnly: Boolean;
20
- debugger: MessageLogger;
20
+ logger: Debugger;
21
21
  /**
22
22
  * Constructor.
23
23
  */
24
- constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly?: boolean);
24
+ constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
25
25
  /**
26
26
  * Set a callback that will be triggered when the connection is closed
27
27
  */
@@ -1,4 +1,4 @@
1
- export declare class MessageLogger {
1
+ export declare class Debugger {
2
2
  logs: any[];
3
3
  listen: boolean;
4
4
  output: boolean;
@@ -12,4 +12,3 @@ export declare class MessageLogger {
12
12
  logs: any[];
13
13
  };
14
14
  }
15
- export declare const Debugger: MessageLogger;
@@ -3,20 +3,23 @@ import { Awareness } from 'y-protocols/awareness';
3
3
  import { Doc } from 'yjs';
4
4
  import { mutex } from 'lib0/mutex.js';
5
5
  import Connection from './Connection';
6
- import { MessageLogger } from './Debugger';
7
- declare class Document extends Doc {
6
+ import { Debugger } from './Debugger';
7
+ export declare class Document extends Doc {
8
8
  awareness: Awareness;
9
9
  callbacks: {
10
10
  onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
11
11
  };
12
- connections: Map<any, any>;
12
+ connections: Map<WebSocket, {
13
+ clients: Set<any>;
14
+ connection: Connection;
15
+ }>;
13
16
  name: string;
14
17
  mux: mutex;
15
- debugger: MessageLogger;
18
+ logger: Debugger;
16
19
  /**
17
20
  * Constructor.
18
21
  */
19
- constructor(name: string);
22
+ constructor(name: string, logger: Debugger);
20
23
  /**
21
24
  * Check if the Document is empty
22
25
  */
@@ -1,13 +1,16 @@
1
1
  /// <reference types="node" />
2
- import WebSocket, { WebSocketServer } from 'ws';
2
+ import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
3
3
  import { IncomingMessage, Server as HTTPServer } from 'http';
4
4
  import { Configuration, Hook } from './types';
5
- import { MessageLogger } from './Debugger';
5
+ import Document from './Document';
6
+ import { Debugger } from './Debugger';
6
7
  import { onListenPayload } from '.';
7
8
  export declare const defaultConfiguration: {
8
9
  name: null;
9
10
  port: number;
10
11
  timeout: number;
12
+ debounce: number;
13
+ maxDebounce: number;
11
14
  quiet: boolean;
12
15
  };
13
16
  /**
@@ -15,10 +18,11 @@ export declare const defaultConfiguration: {
15
18
  */
16
19
  export declare class Hocuspocus {
17
20
  configuration: Configuration;
18
- documents: Map<any, any>;
21
+ documents: Map<string, Document>;
19
22
  httpServer?: HTTPServer;
20
23
  webSocketServer?: WebSocketServer;
21
- debugger: MessageLogger;
24
+ debugger: Debugger;
25
+ constructor(configuration?: Partial<Configuration>);
22
26
  /**
23
27
  * Configure the server
24
28
  */
@@ -27,7 +31,11 @@ export declare class Hocuspocus {
27
31
  /**
28
32
  * Start the server
29
33
  */
30
- listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<void>;
34
+ listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<Hocuspocus>;
35
+ get address(): AddressInfo;
36
+ get URL(): string;
37
+ get webSocketURL(): string;
38
+ get httpURL(): string;
31
39
  private showStartScreen;
32
40
  /**
33
41
  * Get the total number of active documents
@@ -58,32 +66,35 @@ export declare class Hocuspocus {
58
66
  handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
59
67
  /**
60
68
  * Handle update of the given document
61
- * @private
62
69
  */
63
70
  private handleDocumentUpdate;
71
+ timers: Map<string, {
72
+ timeout: NodeJS.Timeout;
73
+ start: number;
74
+ }>;
75
+ /**
76
+ * debounce the given function, using the given identifier
77
+ */
78
+ debounce(id: string, func: Function, immediately?: boolean): void;
64
79
  /**
65
80
  * Create a new document by the given request
66
- * @private
67
81
  */
68
82
  private createDocument;
69
83
  /**
70
84
  * Create a new connection by the given request and document
71
- * @private
72
85
  */
73
86
  private createConnection;
74
87
  /**
75
- * Run the given hook on all configured extensions
76
- * Runs the given callback after each hook
88
+ * Run the given hook on all configured extensions.
89
+ * Runs the given callback after each hook.
77
90
  */
78
91
  hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
79
92
  /**
80
93
  * Get parameters by the given request
81
- * @private
82
94
  */
83
95
  private static getParameters;
84
96
  /**
85
97
  * Get document name by the given request
86
- * @private
87
98
  */
88
99
  private getDocumentNameFromRequest;
89
100
  enableDebugging(): void;
@@ -1,10 +1,13 @@
1
+ import { Awareness } from 'y-protocols/awareness';
1
2
  import Connection from './Connection';
2
3
  import { IncomingMessage } from './IncomingMessage';
3
- import { MessageLogger } from './Debugger';
4
+ import { Debugger } from './Debugger';
5
+ import Document from './Document';
4
6
  export declare class MessageReceiver {
5
7
  message: IncomingMessage;
6
- debugger: MessageLogger;
7
- constructor(message: IncomingMessage);
8
- apply(connection: Connection): void;
9
- readSyncMessage(message: IncomingMessage, connection: Connection): 0 | 1 | 2;
8
+ logger: Debugger;
9
+ constructor(message: IncomingMessage, logger: Debugger);
10
+ apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): 0 | 2 | 1;
12
+ applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
10
13
  }
@@ -8,6 +8,7 @@ export declare class OutgoingMessage {
8
8
  constructor();
9
9
  createSyncMessage(): OutgoingMessage;
10
10
  createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
11
+ writeQueryAwareness(): OutgoingMessage;
11
12
  writeAuthenticated(): OutgoingMessage;
12
13
  writePermissionDenied(reason: string): OutgoingMessage;
13
14
  writeFirstSyncStepFor(document: Document): OutgoingMessage;
@@ -1,2 +1,9 @@
1
1
  export * from './Hocuspocus';
2
+ export * from './Connection';
3
+ export * from './Document';
4
+ export * from './IncomingMessage';
5
+ export * from './OutgoingMessage';
2
6
  export * from './types';
7
+ export * from './MessageReceiver';
8
+ export * from './Document';
9
+ export * from './Connection';
@@ -2,13 +2,15 @@
2
2
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
3
3
  import { URLSearchParams } from 'url';
4
4
  import { Socket } from 'net';
5
+ import { Awareness } from 'y-protocols/awareness';
5
6
  import Document from './Document';
6
7
  import { Hocuspocus } from './Hocuspocus';
7
8
  export declare enum MessageType {
8
9
  Unknown = -1,
9
10
  Sync = 0,
10
11
  Awareness = 1,
11
- Auth = 2
12
+ Auth = 2,
13
+ QueryAwareness = 3
12
14
  }
13
15
  /**
14
16
  * State of the WebSocket connection.
@@ -31,26 +33,32 @@ export interface ConnectionConfiguration {
31
33
  isAuthenticated: boolean;
32
34
  }
33
35
  export interface Extension {
34
- onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
35
- onChange?(data: onChangePayload): Promise<any>;
36
- onConnect?(data: onConnectPayload): Promise<any>;
36
+ priority?: number;
37
37
  onConfigure?(data: onConfigurePayload): Promise<any>;
38
+ onListen?(data: onListenPayload): Promise<any>;
39
+ onUpgrade?(data: onUpgradePayload): Promise<any>;
40
+ onConnect?(data: onConnectPayload): Promise<any>;
41
+ connected?(data: connectedPayload): Promise<any>;
42
+ onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
38
43
  /**
39
44
  * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
40
45
  */
41
46
  onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
42
47
  onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
43
- onDestroy?(data: onDestroyPayload): Promise<any>;
44
- onDisconnect?(data: onDisconnectPayload): Promise<any>;
45
- onListen?(data: onListenPayload): Promise<any>;
48
+ afterLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
49
+ onChange?(data: onChangePayload): Promise<any>;
50
+ onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;
51
+ afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>;
52
+ onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
46
53
  onRequest?(data: onRequestPayload): Promise<any>;
47
- onUpgrade?(data: onUpgradePayload): Promise<any>;
54
+ onDisconnect?(data: onDisconnectPayload): Promise<any>;
55
+ onDestroy?(data: onDestroyPayload): Promise<any>;
48
56
  }
49
- export declare type Hook = 'onAuthenticate' | 'onChange' | 'onConnect' | 'onConfigure' |
57
+ export declare type Hook = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
50
58
  /**
51
59
  * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
52
60
  */
53
- 'onCreateDocument' | 'onLoadDocument' | 'onDestroy' | 'onDisconnect' | 'onListen' | 'onRequest' | 'onUpgrade';
61
+ 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
54
62
  export interface Configuration extends Extension {
55
63
  /**
56
64
  * A name for the instance, used for logging.
@@ -68,6 +76,15 @@ export interface Configuration extends Extension {
68
76
  * Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
69
77
  */
70
78
  timeout: number;
79
+ /**
80
+ * Debounces the call of the `onStoreDocument` hook for the given amount of time in ms.
81
+ * Otherwise every single update would be persisted.
82
+ */
83
+ debounce: number;
84
+ /**
85
+ * Makes sure to call `onStoreDocument` at least in the given amount of time (ms).
86
+ */
87
+ maxDebounce: number;
71
88
  /**
72
89
  * By default, the servers show a start screen. If passed false, the server will start quietly.
73
90
  */
@@ -75,11 +92,12 @@ export interface Configuration extends Extension {
75
92
  /**
76
93
  * Function which returns the (customized) document name based on the request
77
94
  */
78
- getDocumentName?(data: {
79
- documentName: string;
80
- request: IncomingMessage;
81
- requestParameters: URLSearchParams;
82
- }): string | Promise<string>;
95
+ getDocumentName?(data: getDocumentNamePayload): string | Promise<string>;
96
+ }
97
+ export interface getDocumentNamePayload {
98
+ documentName: string;
99
+ request: IncomingMessage;
100
+ requestParameters: URLSearchParams;
83
101
  }
84
102
  export interface onAuthenticatePayload {
85
103
  documentName: string;
@@ -99,6 +117,15 @@ export interface onConnectPayload {
99
117
  socketId: string;
100
118
  connection: ConnectionConfiguration;
101
119
  }
120
+ export interface connectedPayload {
121
+ documentName: string;
122
+ instance: Hocuspocus;
123
+ request: IncomingMessage;
124
+ requestHeaders: IncomingHttpHeaders;
125
+ requestParameters: URLSearchParams;
126
+ socketId: string;
127
+ connection: ConnectionConfiguration;
128
+ }
102
129
  export interface onLoadDocumentPayload {
103
130
  context: any;
104
131
  document: Document;
@@ -109,6 +136,16 @@ export interface onLoadDocumentPayload {
109
136
  socketId: string;
110
137
  connection: ConnectionConfiguration;
111
138
  }
139
+ export interface afterLoadDocumentPayload {
140
+ context: any;
141
+ document: Document;
142
+ documentName: string;
143
+ instance: Hocuspocus;
144
+ requestHeaders: IncomingHttpHeaders;
145
+ requestParameters: URLSearchParams;
146
+ socketId: string;
147
+ connection: ConnectionConfiguration;
148
+ }
112
149
  export interface onChangePayload {
113
150
  clientsCount: number;
114
151
  context: any;
@@ -120,6 +157,41 @@ export interface onChangePayload {
120
157
  update: Uint8Array;
121
158
  socketId: string;
122
159
  }
160
+ export interface onStoreDocumentPayload {
161
+ clientsCount: number;
162
+ context: any;
163
+ document: Document;
164
+ documentName: string;
165
+ instance: Hocuspocus;
166
+ requestHeaders: IncomingHttpHeaders;
167
+ requestParameters: URLSearchParams;
168
+ socketId: string;
169
+ }
170
+ export interface afterStoreDocumentPayload extends onStoreDocumentPayload {
171
+ }
172
+ export interface onAwarenessUpdatePayload {
173
+ clientsCount: number;
174
+ context: any;
175
+ document: Document;
176
+ documentName: string;
177
+ instance: Hocuspocus;
178
+ requestHeaders: IncomingHttpHeaders;
179
+ requestParameters: URLSearchParams;
180
+ update: Uint8Array;
181
+ socketId: string;
182
+ added: number[];
183
+ updated: number[];
184
+ removed: number[];
185
+ awareness: Awareness;
186
+ states: StatesArray;
187
+ }
188
+ export declare type StatesArray = {
189
+ clientId: number;
190
+ [key: string | number]: any;
191
+ }[];
192
+ export interface storePayload extends onStoreDocumentPayload {
193
+ state: Buffer;
194
+ }
123
195
  export interface onDisconnectPayload {
124
196
  clientsCount: number;
125
197
  context: any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const createDirectory: (dir: string) => void;
@@ -0,0 +1 @@
1
+ export declare const flushRedis: () => Promise<string>;
@@ -0,0 +1,7 @@
1
+ export * from './createDirectory';
2
+ export * from './flushRedis';
3
+ export * from './newHocuspocus';
4
+ export * from './newHocuspocusProvider';
5
+ export * from './redisConnectionSettings';
6
+ export * from './removeDirectory';
7
+ export * from './sleep';
@@ -0,0 +1,2 @@
1
+ import { Hocuspocus, Configuration } from '@hocuspocus/server';
2
+ export declare const newHocuspocus: (options?: Partial<Configuration> | undefined) => Hocuspocus;
@@ -0,0 +1,3 @@
1
+ import { HocuspocusProvider, HocuspocusProviderConfiguration } from '@hocuspocus/provider';
2
+ import { Hocuspocus } from '@hocuspocus/server';
3
+ export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<Omit<HocuspocusProviderConfiguration, 'url'>>) => HocuspocusProvider;
@@ -0,0 +1,4 @@
1
+ export declare const redisConnectionSettings: {
2
+ host: string;
3
+ port: number;
4
+ };
@@ -0,0 +1 @@
1
+ export declare const removeDirectory: (dir: string) => void;
@@ -0,0 +1 @@
1
+ export declare const sleep: (time: number) => Promise<unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-logger",
3
- "version": "1.0.0-alpha.63",
3
+ "version": "1.0.0-alpha.67",
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.89"
31
+ "@hocuspocus/server": "^1.0.0-alpha.93"
32
32
  },
33
- "gitHead": "87b715d1d28c603702879f4413c17d2c4a38c51a"
33
+ "gitHead": "05a7eb3d660175613d2fe7b6d9ec030e8e509683"
34
34
  }
package/src/Logger.ts CHANGED
@@ -25,6 +25,10 @@ export interface LoggerConfiguration {
25
25
  * Whether to log something for the `onChange` hook.
26
26
  */
27
27
  onChange: boolean,
28
+ /**
29
+ * Whether to log something for the `onStoreDocument` hook.
30
+ */
31
+ onStoreDocument: boolean,
28
32
  /**
29
33
  * Whether to log something for the `onConnect` hook.
30
34
  */
@@ -62,6 +66,7 @@ export class Logger implements Extension {
62
66
  prefix: null,
63
67
  onLoadDocument: true,
64
68
  onChange: true,
69
+ onStoreDocument: true,
65
70
  onConnect: true,
66
71
  onDisconnect: true,
67
72
  onUpgrade: true,
@@ -105,6 +110,12 @@ export class Logger implements Extension {
105
110
  }
106
111
  }
107
112
 
113
+ async onStoreDocument(data: onDisconnectPayload) {
114
+ if (this.configuration.onStoreDocument) {
115
+ this.log(`Store "${data.documentName}".`)
116
+ }
117
+ }
118
+
108
119
  async onConnect(data: onConnectPayload) {
109
120
  if (this.configuration.onConnect) {
110
121
  this.log(`New connection to "${data.documentName}".`)
@@ -1,4 +0,0 @@
1
- declare const _default: (states: Map<number, Record<string, any>>) => {
2
- clientId: number;
3
- }[];
4
- export default _default;
@@ -1 +0,0 @@
1
- export { default as awarenessStatesToArray } from './awarenessStatesToArray';