document-drive 1.0.0-alpha.31 → 1.0.0-alpha.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-drive",
3
- "version": "1.0.0-alpha.31",
3
+ "version": "1.0.0-alpha.33",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "module": "./src/index.ts",
@@ -14,7 +14,8 @@
14
14
  "./storage/memory": "./src/storage/memory.ts",
15
15
  "./storage/prisma": "./src/storage/prisma.ts",
16
16
  "./utils": "./src/utils/index.ts",
17
- "./utils/graphql": "./src/utils/graphql.ts"
17
+ "./utils/graphql": "./src/utils/graphql.ts",
18
+ "./logger": "./src/utils/logger.ts"
18
19
  },
19
20
  "files": [
20
21
  "./src"
@@ -41,8 +42,7 @@
41
42
  "graphql-request": "^6.1.0",
42
43
  "json-stringify-deterministic": "^1.0.12",
43
44
  "nanoevents": "^9.0.0",
44
- "sanitize-filename": "^1.6.3",
45
- "winston": "^3.13.0"
45
+ "sanitize-filename": "^1.6.3"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@commitlint/cli": "^18.6.1",
@@ -35,6 +35,7 @@ import {
35
35
  isNoopUpdate
36
36
  } from '../utils';
37
37
  import { requestPublicDrive } from '../utils/graphql';
38
+ import { logger } from '../utils/logger';
38
39
  import {
39
40
  ConflictOperationError,
40
41
  MissingOperationError,
@@ -64,8 +65,6 @@ import {
64
65
  type SynchronizationUnit
65
66
  } from './types';
66
67
  import { filterOperationsByRevision } from './utils';
67
- import winston from 'winston';
68
- import { logger as defaultLogger, logger } from '../utils/logger';
69
68
 
70
69
  export * from './listener';
71
70
  export type * from './types';
@@ -122,16 +121,16 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
122
121
 
123
122
  const result = await (!strand.documentId
124
123
  ? this.addDriveOperations(
125
- strand.driveId,
126
- operations as Operation<DocumentDriveAction | BaseAction>[],
127
- false
128
- )
124
+ strand.driveId,
125
+ operations as Operation<DocumentDriveAction | BaseAction>[],
126
+ false
127
+ )
129
128
  : this.addOperations(
130
- strand.driveId,
131
- strand.documentId,
132
- operations,
133
- false
134
- ));
129
+ strand.driveId,
130
+ strand.documentId,
131
+ operations,
132
+ false
133
+ ));
135
134
 
136
135
  if (result.status === 'ERROR') {
137
136
  this.updateSyncStatus(strand.driveId, result.status, result.error);
@@ -247,10 +246,7 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
247
246
  (!documentType?.length ||
248
247
  documentType.includes(node.documentType) ||
249
248
  documentType.includes('*'))
250
- ) as Pick<
251
- FileNode,
252
- 'id' | 'documentType' | 'synchronizationUnits'
253
- >[];
249
+ ) as Pick<FileNode, 'id' | 'documentType' | 'synchronizationUnits'>[];
254
250
 
255
251
  // checks if document drive synchronization unit should be added
256
252
  if (
@@ -280,14 +276,14 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
280
276
  const nodeUnits =
281
277
  scope?.length || branch?.length
282
278
  ? node.synchronizationUnits.filter(
283
- unit =>
284
- (!scope?.length ||
285
- scope.includes(unit.scope) ||
286
- scope.includes('*')) &&
287
- (!branch?.length ||
288
- branch.includes(unit.branch) ||
289
- branch.includes('*'))
290
- )
279
+ unit =>
280
+ (!scope?.length ||
281
+ scope.includes(unit.scope) ||
282
+ scope.includes('*')) &&
283
+ (!branch?.length ||
284
+ branch.includes(unit.branch) ||
285
+ branch.includes('*'))
286
+ )
291
287
  : node.synchronizationUnits;
292
288
  if (!nodeUnits.length) {
293
289
  continue;
@@ -581,11 +577,11 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
581
577
  e instanceof OperationError
582
578
  ? e
583
579
  : new OperationError(
584
- 'ERROR',
585
- operation,
586
- (e as Error).message,
587
- (e as Error).cause
588
- );
580
+ 'ERROR',
581
+ operation,
582
+ (e as Error).message,
583
+ (e as Error).cause
584
+ );
589
585
  }
590
586
  break;
591
587
  }
@@ -879,11 +875,11 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
879
875
  error instanceof OperationError
880
876
  ? error
881
877
  : new OperationError(
882
- 'ERROR',
883
- undefined,
884
- (error as Error).message,
885
- (error as Error).cause
886
- );
878
+ 'ERROR',
879
+ undefined,
880
+ (error as Error).message,
881
+ (error as Error).cause
882
+ );
887
883
 
888
884
  return {
889
885
  status: operationError.status,
@@ -1047,11 +1043,11 @@ export class DocumentDriveServer extends BaseDocumentDriveServer {
1047
1043
  error instanceof OperationError
1048
1044
  ? error
1049
1045
  : new OperationError(
1050
- 'ERROR',
1051
- undefined,
1052
- (error as Error).message,
1053
- (error as Error).cause
1054
- );
1046
+ 'ERROR',
1047
+ undefined,
1048
+ (error as Error).message,
1049
+ (error as Error).cause
1050
+ );
1055
1051
 
1056
1052
  return {
1057
1053
  status: operationError.status,
@@ -19,9 +19,6 @@ import type {
19
19
  import { Unsubscribe } from 'nanoevents';
20
20
  import { OperationError } from './error';
21
21
  import { ITransmitter } from './listener/transmitter/types';
22
- import winston from 'winston';
23
- import { logger as defaultLogger } from '../utils/logger';
24
-
25
22
 
26
23
  export type DriveInput = State<
27
24
  Omit<DocumentDriveState, '__typename' | 'id' | 'nodes'> & { id?: string },
@@ -270,7 +267,7 @@ export abstract class BaseListenerManager {
270
267
 
271
268
  constructor(
272
269
  drive: BaseDocumentDriveServer,
273
- listenerState = new Map<string, Map<string, ListenerState>>(),
270
+ listenerState = new Map<string, Map<string, ListenerState>>()
274
271
  ) {
275
272
  this.drive = drive;
276
273
  this.listenerState = listenerState;
@@ -1,8 +1,44 @@
1
- import winston from 'winston';
2
-
3
- export const logger = winston.createLogger({
4
- level: 'info',
5
- defaultMeta: { service: "document-drive" },
6
- // format: winston.format.colorize(),
7
- transports: [new winston.transports.Console()],
8
- });
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ export type ILogger = Pick<Console, 'log' | 'info' | 'warn' | 'error' | 'debug' | 'trace'>;
3
+ class Logger implements ILogger {
4
+ #logger: ILogger = console;
5
+
6
+ set logger(logger: ILogger) {
7
+ this.#logger = logger;
8
+ }
9
+
10
+ log(...data: any[]): void {
11
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
12
+ return this.#logger.log(...data);
13
+ }
14
+
15
+ info(...data: any[]): void {
16
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
17
+ return this.#logger.info(...data);
18
+ }
19
+
20
+ warn(...data: any[]): void {
21
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
22
+ return this.#logger.warn(...data);
23
+ }
24
+
25
+ error(...data: any[]): void {
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
27
+ return this.#logger.error(...data);
28
+ }
29
+
30
+ debug(...data: any[]): void {
31
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
32
+ return this.#logger.debug(...data);
33
+ }
34
+
35
+ trace(...data: any[]): void {
36
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
37
+ return this.#logger.trace(...data);
38
+ }
39
+ }
40
+
41
+ const loggerInstance = new Logger();
42
+
43
+ export const logger: ILogger = loggerInstance;
44
+ export const setLogger = (logger: ILogger) => (loggerInstance.logger = logger);