taro-bluetooth-print 2.13.0 → 2.15.0
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/CHANGELOG.md +72 -90
- package/README.md +195 -248
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/adapters/AlipayAdapter.d.ts +0 -14
- package/dist/types/adapters/BaiduAdapter.d.ts +0 -14
- package/dist/types/adapters/BaseAdapter.d.ts +9 -3
- package/dist/types/adapters/ByteDanceAdapter.d.ts +0 -14
- package/dist/types/adapters/QQAdapter.d.ts +0 -18
- package/dist/types/adapters/TaroAdapter.d.ts +0 -14
- package/dist/types/core/BluetoothPrinter.d.ts +43 -287
- package/dist/types/drivers/{escPosDriver.d.ts → EscPosDriver.d.ts} +6 -0
- package/dist/types/drivers/GPrinterDriver.d.ts +1 -1
- package/dist/types/drivers/SprtDriver.d.ts +1 -1
- package/dist/types/drivers/XprinterDriver.d.ts +1 -1
- package/dist/types/drivers/index.d.ts +1 -1
- package/dist/types/encoding/index.d.ts +2 -2
- package/dist/types/errors/{baseError.d.ts → BaseError.d.ts} +6 -0
- package/dist/types/errors/CommandBuildError.d.ts +3 -17
- package/dist/types/errors/ConnectionError.d.ts +3 -20
- package/dist/types/errors/PrintJobError.d.ts +2 -18
- package/dist/types/errors/index.d.ts +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/plugins/PluginManager.d.ts +2 -2
- package/dist/types/plugins/{types.d.ts → PluginTypes.d.ts} +1 -1
- package/dist/types/plugins/builtin/LoggingPlugin.d.ts +1 -1
- package/dist/types/plugins/builtin/RetryPlugin.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/services/CommandBuilder.d.ts +8 -151
- package/dist/types/services/ConnectionManager.d.ts +6 -1
- package/dist/types/services/PrintHistory.d.ts +14 -27
- package/dist/types/services/PrintJobManager.d.ts +24 -140
- package/dist/types/utils/BoundedOrderedMap.d.ts +47 -0
- package/package.json +4 -2
- package/src/adapters/AdapterFactory.ts +1 -1
- package/src/adapters/AlipayAdapter.ts +3 -21
- package/src/adapters/BaiduAdapter.ts +3 -21
- package/src/adapters/BaseAdapter.ts +27 -18
- package/src/adapters/ByteDanceAdapter.ts +3 -21
- package/src/adapters/ChunkWriteStrategy.ts +1 -1
- package/src/adapters/QQAdapter.ts +3 -25
- package/src/adapters/ReactNativeAdapter.ts +7 -5
- package/src/adapters/TaroAdapter.ts +5 -20
- package/src/adapters/WebBluetoothAdapter.ts +1 -1
- package/src/config/PrinterConfigManager.ts +1 -1
- package/src/core/BluetoothPrinter.ts +114 -421
- package/src/device/DeviceManager.ts +1 -1
- package/src/device/MultiPrinterManager.ts +1 -1
- package/src/drivers/CpclDriver.ts +1 -1
- package/src/drivers/{escPosDriver.ts → EscPosDriver.ts} +14 -15
- package/src/drivers/GPrinterDriver.ts +1 -1
- package/src/drivers/SprtDriver.ts +1 -1
- package/src/drivers/XprinterDriver.ts +1 -1
- package/src/drivers/ZplDriver.ts +1 -1
- package/src/drivers/index.ts +1 -1
- package/src/encoding/EncodingService.ts +2 -2
- package/src/encoding/{gbk-table.ts → GbkTable.ts} +2 -2
- package/src/encoding/index.ts +2 -2
- package/src/errors/{baseError.ts → BaseError.ts} +9 -0
- package/src/errors/CommandBuildError.ts +19 -30
- package/src/errors/ConnectionError.ts +9 -37
- package/src/errors/PrintJobError.ts +10 -32
- package/src/errors/index.ts +1 -1
- package/src/factory/PrinterFactory.ts +1 -1
- package/src/index.ts +3 -2
- package/src/plugins/PluginManager.ts +7 -5
- package/src/plugins/{types.ts → PluginTypes.ts} +1 -1
- package/src/plugins/builtin/LoggingPlugin.ts +1 -1
- package/src/plugins/builtin/RetryPlugin.ts +2 -2
- package/src/plugins/index.ts +1 -1
- package/src/preview/PreviewRenderer.ts +1 -1
- package/src/queue/PrintQueue.ts +1 -1
- package/src/services/BatchPrintManager.ts +1 -1
- package/src/services/CloudPrintManager.ts +1 -1
- package/src/services/CommandBuilder.ts +35 -193
- package/src/services/ConnectionManager.ts +28 -21
- package/src/services/PrintHistory.ts +43 -120
- package/src/services/PrintJobManager.ts +148 -331
- package/src/services/PrintScheduler.ts +1 -1
- package/src/template/engines/TemplateRenderer.ts +1 -1
- package/src/utils/BoundedOrderedMap.ts +120 -0
- package/src/utils/image.ts +1 -1
- package/dist/types/utils/errorHandler.d.ts +0 -78
- package/dist/types/utils/validation.d.ts +0 -8
- package/src/utils/errorHandler.ts +0 -196
- package/src/utils/validation.ts +0 -9
- /package/dist/types/drivers/{barcode-helpers.d.ts → BarcodeHelpers.d.ts} +0 -0
- /package/dist/types/encoding/{gbk-data.d.ts → GbkData.d.ts} +0 -0
- /package/dist/types/encoding/{gbk-lite.d.ts → GbkLite.d.ts} +0 -0
- /package/dist/types/encoding/{gbk-table.d.ts → GbkTable.d.ts} +0 -0
- /package/dist/types/encoding/{korean-japanese.d.ts → KoreanJapanese.d.ts} +0 -0
- /package/src/drivers/{barcode-helpers.ts → BarcodeHelpers.ts} +0 -0
- /package/src/encoding/{gbk-data.ts → GbkData.ts} +0 -0
- /package/src/encoding/{gbk-lite.ts → GbkLite.ts} +0 -0
- /package/src/encoding/{korean-japanese.ts → KoreanJapanese.ts} +0 -0
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import { BluetoothPrintError } from './
|
|
2
|
-
/**
|
|
3
|
-
* Print job-related error codes
|
|
4
|
-
*/
|
|
1
|
+
import { BluetoothPrintError } from './BaseError';
|
|
5
2
|
export declare enum PrintJobErrorCode {
|
|
6
|
-
/** Print job failed */
|
|
7
3
|
FAILED = "PRINT_JOB_FAILED",
|
|
8
|
-
/** Print job is already in progress */
|
|
9
4
|
IN_PROGRESS = "PRINT_JOB_IN_PROGRESS",
|
|
10
|
-
/** Print job was cancelled */
|
|
11
5
|
CANCELLED = "PRINT_JOB_CANCELLED",
|
|
12
|
-
/** Print data is invalid */
|
|
13
6
|
INVALID_DATA = "INVALID_IMAGE_DATA",
|
|
14
|
-
/** Write operation failed */
|
|
15
7
|
WRITE_FAILED = "WRITE_FAILED",
|
|
16
|
-
/** Write operation timed out */
|
|
17
8
|
WRITE_TIMEOUT = "WRITE_TIMEOUT"
|
|
18
9
|
}
|
|
19
10
|
/**
|
|
20
|
-
* PrintJobError - Specialized error for print job failures
|
|
11
|
+
* PrintJobError - Specialized error for print job failures.
|
|
21
12
|
*
|
|
22
13
|
* @example
|
|
23
14
|
* ```typescript
|
|
@@ -31,12 +22,5 @@ export declare enum PrintJobErrorCode {
|
|
|
31
22
|
export declare class PrintJobError extends BluetoothPrintError {
|
|
32
23
|
readonly jobErrorCode: PrintJobErrorCode;
|
|
33
24
|
constructor(jobErrorCode: PrintJobErrorCode, message: string, originalError?: Error);
|
|
34
|
-
/**
|
|
35
|
-
* Converts PrintJobErrorCode to base ErrorCode
|
|
36
|
-
*/
|
|
37
|
-
private static _toBaseCode;
|
|
38
|
-
/**
|
|
39
|
-
* Checks if an error is a print job error
|
|
40
|
-
*/
|
|
41
25
|
static isPrintJobError(error: unknown): error is PrintJobError;
|
|
42
26
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
|
-
export { BluetoothPrintError, ErrorCode } from './
|
|
6
|
+
export { BluetoothPrintError, ErrorCode } from './BaseError';
|
|
7
7
|
export { ConnectionError, ConnectionErrorCode } from './ConnectionError';
|
|
8
8
|
export { PrintJobError, PrintJobErrorCode } from './PrintJobError';
|
|
9
9
|
export { CommandBuildError, CommandBuildErrorCode } from './CommandBuildError';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { TaroAdapter } from './adapters/TaroAdapter';
|
|
|
12
12
|
export { AlipayAdapter } from './adapters/AlipayAdapter';
|
|
13
13
|
export { BaiduAdapter } from './adapters/BaiduAdapter';
|
|
14
14
|
export { ByteDanceAdapter } from './adapters/ByteDanceAdapter';
|
|
15
|
+
export { QQAdapter } from './adapters/QQAdapter';
|
|
15
16
|
export { WebBluetoothAdapter } from './adapters/WebBluetoothAdapter';
|
|
16
17
|
export { AdapterFactory } from './adapters/AdapterFactory';
|
|
17
18
|
export { BaseAdapter } from './adapters/BaseAdapter';
|
|
@@ -41,7 +42,7 @@ export { ImageProcessing } from './utils/image';
|
|
|
41
42
|
export { PlatformType, detectPlatform, isPlatformSupported } from './utils/platform';
|
|
42
43
|
export { truncateString, truncateForLog, batchProcess, createLimitedLogger, generateSummary, } from './utils/outputLimiter';
|
|
43
44
|
export type { TruncateOptions } from './utils/outputLimiter';
|
|
44
|
-
export { BluetoothPrintError, ErrorCode } from './errors/
|
|
45
|
+
export { BluetoothPrintError, ErrorCode } from './errors/BaseError';
|
|
45
46
|
export { ConnectionError, ConnectionErrorCode } from './errors/ConnectionError';
|
|
46
47
|
export { PrintJobError, PrintJobErrorCode } from './errors/PrintJobError';
|
|
47
48
|
export { CommandBuildError, CommandBuildErrorCode } from './errors/CommandBuildError';
|
|
@@ -51,5 +52,5 @@ export type { PrinterConfig, AdapterConfig, DriverConfig, LoggingConfig, } from
|
|
|
51
52
|
export { PrinterConfigManager, printerConfigManager } from './config/PrinterConfigManager';
|
|
52
53
|
export type { SavedPrinter, GlobalConfig, IConfigStorage } from './config/PrinterConfigManager';
|
|
53
54
|
export { createLoggingPlugin, createRetryPlugin } from './plugins';
|
|
54
|
-
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './plugins/
|
|
55
|
+
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './plugins/PluginTypes';
|
|
55
56
|
export * from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Plugin, PluginHooks, PluginOptions } from './
|
|
2
|
-
import { BluetoothPrintError } from '../errors/
|
|
1
|
+
import { Plugin, PluginHooks, PluginOptions } from './PluginTypes';
|
|
2
|
+
import { BluetoothPrintError } from '../errors/BaseError';
|
|
3
3
|
import { PrinterState } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Manages plugins for BluetoothPrinter
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PluginFactory, PluginOptions } from '../
|
|
2
|
-
import { ErrorCode } from '../../errors/
|
|
1
|
+
import { PluginFactory, PluginOptions } from '../PluginTypes';
|
|
2
|
+
import { ErrorCode } from '../../errors/BaseError';
|
|
3
3
|
export interface RetryPluginOptions extends PluginOptions {
|
|
4
4
|
/** Maximum retry attempts (default: 3) */
|
|
5
5
|
maxRetries?: number;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Plugin System Exports
|
|
3
3
|
*/
|
|
4
4
|
export { PluginManager } from './PluginManager';
|
|
5
|
-
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './
|
|
5
|
+
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './PluginTypes';
|
|
6
6
|
export { createLoggingPlugin } from './builtin/LoggingPlugin';
|
|
7
7
|
export { createRetryPlugin } from './builtin/RetryPlugin';
|
|
@@ -6,178 +6,35 @@ import { BarcodeOptions } from '../barcode';
|
|
|
6
6
|
* Command Builder implementation
|
|
7
7
|
*/
|
|
8
8
|
export declare class CommandBuilder implements ICommandBuilder {
|
|
9
|
-
private driver;
|
|
10
|
-
private buffer;
|
|
11
|
-
private _cachedBuffer;
|
|
12
|
-
private readonly logger;
|
|
9
|
+
private readonly driver;
|
|
13
10
|
private readonly formatter;
|
|
14
11
|
private readonly barcodeGenerator;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @param driver - Printer driver instance
|
|
19
|
-
*/
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private buffer;
|
|
14
|
+
private cachedBuffer;
|
|
20
15
|
constructor(driver?: IPrinterDriver);
|
|
21
16
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
private invalidateCache;
|
|
26
|
-
/**
|
|
27
|
-
* Adds text to the print queue
|
|
28
|
-
*
|
|
29
|
-
* @param content - Text content
|
|
30
|
-
* @param encoding - Text encoding
|
|
31
|
-
* @returns this - For method chaining
|
|
17
|
+
* Push pre-built command chunks and invalidate the concat cache.
|
|
18
|
+
* Centralizes what was previously duplicated in every mutating method.
|
|
32
19
|
*/
|
|
20
|
+
private pushCommands;
|
|
33
21
|
text(content: string, encoding?: string): this;
|
|
34
|
-
/**
|
|
35
|
-
* Adds line feeds to the print queue
|
|
36
|
-
*
|
|
37
|
-
* @param lines - Number of lines to feed
|
|
38
|
-
* @returns this - For method chaining
|
|
39
|
-
*/
|
|
40
22
|
feed(lines?: number): this;
|
|
41
|
-
/**
|
|
42
|
-
* Adds a paper cut command to the print queue
|
|
43
|
-
*
|
|
44
|
-
* @returns this - For method chaining
|
|
45
|
-
*/
|
|
46
23
|
cut(): this;
|
|
47
|
-
/**
|
|
48
|
-
* Adds an image to the print queue
|
|
49
|
-
*
|
|
50
|
-
* @param data - Image data as Uint8Array
|
|
51
|
-
* @param width - Image width
|
|
52
|
-
* @param height - Image height
|
|
53
|
-
* @returns this - For method chaining
|
|
54
|
-
*/
|
|
55
24
|
image(data: Uint8Array, width: number, height: number): this;
|
|
56
|
-
/**
|
|
57
|
-
* Adds a QR code to the print queue
|
|
58
|
-
*
|
|
59
|
-
* @param content - QR code content
|
|
60
|
-
* @param options - QR code options
|
|
61
|
-
* @returns this - For method chaining
|
|
62
|
-
*/
|
|
63
25
|
qr(content: string, options?: IQrOptions): this;
|
|
64
26
|
/**
|
|
65
|
-
* Clears the print queue
|
|
66
|
-
*
|
|
67
|
-
* @returns this - For method chaining
|
|
27
|
+
* Clears the print queue and re-initializes the printer.
|
|
68
28
|
*/
|
|
69
29
|
clear(): this;
|
|
70
|
-
/**
|
|
71
|
-
* Sets text alignment
|
|
72
|
-
*
|
|
73
|
-
* @param alignment - Text alignment (left, center, right)
|
|
74
|
-
* @returns this - For method chaining
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* builder.align(TextAlign.CENTER).text('Centered Text');
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
30
|
align(alignment: TextAlign): this;
|
|
82
|
-
/**
|
|
83
|
-
* Sets character size (width and height scale)
|
|
84
|
-
*
|
|
85
|
-
* @param width - Width scale factor (1-8)
|
|
86
|
-
* @param height - Height scale factor (1-8)
|
|
87
|
-
* @returns this - For method chaining
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```typescript
|
|
91
|
-
* builder.setSize(2, 2).text('Double Size');
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
31
|
setSize(width: number, height: number): this;
|
|
95
|
-
/**
|
|
96
|
-
* Sets bold text mode
|
|
97
|
-
*
|
|
98
|
-
* @param enabled - Enable or disable bold
|
|
99
|
-
* @returns this - For method chaining
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* builder.setBold(true).text('Bold Text').setBold(false);
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
32
|
setBold(enabled: boolean): this;
|
|
107
|
-
/**
|
|
108
|
-
* Sets underline text mode
|
|
109
|
-
*
|
|
110
|
-
* @param enabled - Enable or disable underline
|
|
111
|
-
* @returns this - For method chaining
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* builder.setUnderline(true).text('Underlined').setUnderline(false);
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
33
|
setUnderline(enabled: boolean): this;
|
|
119
|
-
/**
|
|
120
|
-
* Sets inverse printing mode (white on black)
|
|
121
|
-
*
|
|
122
|
-
* @param enabled - Enable or disable inverse
|
|
123
|
-
* @returns this - For method chaining
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* builder.setInverse(true).text('Inverse Text').setInverse(false);
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
34
|
setInverse(enabled: boolean): this;
|
|
131
|
-
/**
|
|
132
|
-
* Sets multiple text style properties at once
|
|
133
|
-
*
|
|
134
|
-
* @param style - Text style configuration
|
|
135
|
-
* @returns this - For method chaining
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* builder.setStyle({ align: TextAlign.CENTER, bold: true, heightScale: 2 });
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
35
|
setStyle(style: TextStyle): this;
|
|
143
|
-
/**
|
|
144
|
-
* Resets all text formatting to default
|
|
145
|
-
*
|
|
146
|
-
* @returns this - For method chaining
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* builder.resetStyle().text('Normal Text');
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
36
|
resetStyle(): this;
|
|
154
|
-
/**
|
|
155
|
-
* Adds a 1D barcode to the print queue
|
|
156
|
-
*
|
|
157
|
-
* @param content - Barcode content/data
|
|
158
|
-
* @param options - Barcode options (format, height, width, showText, textPosition)
|
|
159
|
-
* @returns this - For method chaining
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* builder.barcode('1234567890128', {
|
|
164
|
-
* format: BarcodeFormat.EAN13,
|
|
165
|
-
* height: 80,
|
|
166
|
-
* showText: true
|
|
167
|
-
* });
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
37
|
barcode(content: string, options: BarcodeOptions): this;
|
|
171
|
-
/**
|
|
172
|
-
* Gets the current buffer
|
|
173
|
-
*
|
|
174
|
-
* @returns Uint8Array - Current print buffer
|
|
175
|
-
*/
|
|
176
38
|
getBuffer(): Uint8Array;
|
|
177
|
-
/**
|
|
178
|
-
* Gets the total number of bytes in the buffer
|
|
179
|
-
*
|
|
180
|
-
* @returns number - Total bytes
|
|
181
|
-
*/
|
|
182
39
|
getTotalBytes(): number;
|
|
183
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IPrinterAdapter, PrinterState } from '../types';
|
|
2
2
|
import { IConnectionManager } from './interfaces';
|
|
3
|
-
import { BluetoothPrintError } from '../errors/
|
|
3
|
+
import { BluetoothPrintError } from '../errors/BaseError';
|
|
4
4
|
import { EventEmitter } from '../core/EventEmitter';
|
|
5
5
|
/**
|
|
6
6
|
* Connection manager configuration
|
|
@@ -75,6 +75,11 @@ export declare class ConnectionManager extends EventEmitter<ConnectionManagerEve
|
|
|
75
75
|
retries?: number;
|
|
76
76
|
timeout?: number;
|
|
77
77
|
}): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Map a raw connect error to a typed BluetoothPrintError, distinguishing
|
|
80
|
+
* timeouts from generic failures.
|
|
81
|
+
*/
|
|
82
|
+
private classifyConnectError;
|
|
78
83
|
/**
|
|
79
84
|
* Disconnects from the current device
|
|
80
85
|
*/
|
|
@@ -42,23 +42,23 @@ export interface PrintHistoryStats {
|
|
|
42
42
|
failed: number;
|
|
43
43
|
/** Cancelled jobs */
|
|
44
44
|
cancelled: number;
|
|
45
|
-
/** Average duration in
|
|
45
|
+
/** Average duration in milliseconds */
|
|
46
46
|
avgDuration: number;
|
|
47
|
-
/** Total bytes
|
|
47
|
+
/** Total bytes */
|
|
48
48
|
totalBytes: number;
|
|
49
|
-
/** Success rate */
|
|
49
|
+
/** Success rate (0-100) */
|
|
50
50
|
successRate: number;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* History query options
|
|
54
54
|
*/
|
|
55
55
|
export interface HistoryQueryOptions {
|
|
56
56
|
/** Start date filter */
|
|
57
57
|
startDate?: number;
|
|
58
58
|
/** End date filter */
|
|
59
59
|
endDate?: number;
|
|
60
|
-
/** Status filter */
|
|
61
|
-
status?: PrintJobStatus | PrintJobStatus
|
|
60
|
+
/** Status filter (single or array) */
|
|
61
|
+
status?: PrintJobStatus | 'unknown' | Array<PrintJobStatus | 'unknown'>;
|
|
62
62
|
/** Device ID filter */
|
|
63
63
|
deviceId?: string;
|
|
64
64
|
/** Limit results */
|
|
@@ -67,17 +67,17 @@ export interface HistoryQueryOptions {
|
|
|
67
67
|
offset?: number;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Print History Service
|
|
70
|
+
* Print History Service.
|
|
71
|
+
*
|
|
72
|
+
* Backed by a {@link BoundedOrderedMap} that automatically evicts the oldest
|
|
73
|
+
* entries once capacity is exceeded.
|
|
71
74
|
*/
|
|
72
75
|
export declare class PrintHistory {
|
|
73
76
|
private readonly logger;
|
|
74
|
-
private readonly
|
|
77
|
+
private readonly store;
|
|
75
78
|
private counter;
|
|
76
79
|
/** Default maximum number of history entries */
|
|
77
80
|
private static readonly DEFAULT_MAX_ENTRIES;
|
|
78
|
-
private readonly maxEntries;
|
|
79
|
-
/** Ordered index of entry IDs by createdAt (ascending) for fast pruning */
|
|
80
|
-
private readonly orderedIds;
|
|
81
81
|
/**
|
|
82
82
|
* Creates a new PrintHistory instance
|
|
83
83
|
* @param maxEntries - Maximum number of entries to keep (default: 1000)
|
|
@@ -131,27 +131,14 @@ export declare class PrintHistory {
|
|
|
131
131
|
*/
|
|
132
132
|
export(): string;
|
|
133
133
|
/**
|
|
134
|
-
* Import history from JSON
|
|
134
|
+
* Import history from JSON. Rebuilds the underlying ordered index after bulk insert.
|
|
135
135
|
*/
|
|
136
136
|
import(json: string): number;
|
|
137
|
+
/** Total number of entries currently retained (≤ maxEntries). */
|
|
138
|
+
get size(): number;
|
|
137
139
|
/**
|
|
138
140
|
* Generate unique ID
|
|
139
141
|
*/
|
|
140
142
|
private generateId;
|
|
141
|
-
/**
|
|
142
|
-
* Enforce maximum entries limit using the ordered index.
|
|
143
|
-
* Instead of full-sorting, we use the pre-sorted index to find and remove the oldest entries.
|
|
144
|
-
*/
|
|
145
|
-
private enforceMaxEntries;
|
|
146
|
-
/**
|
|
147
|
-
* Binary search to find the insertion position for a given timestamp
|
|
148
|
-
* in the orderedIds array (ascending order).
|
|
149
|
-
*/
|
|
150
|
-
private findInsertPosition;
|
|
151
|
-
/**
|
|
152
|
-
* Rebuild the ordered index from the entries map.
|
|
153
|
-
* Used after bulk operations like import.
|
|
154
|
-
*/
|
|
155
|
-
private rebuildIndex;
|
|
156
143
|
}
|
|
157
144
|
export declare const printHistory: PrintHistory;
|
|
@@ -1,169 +1,53 @@
|
|
|
1
1
|
import { IAdapterOptions } from '../types';
|
|
2
2
|
import { IPrintJobManager, IConnectionManager } from './interfaces';
|
|
3
|
-
|
|
4
|
-
* Print Job Manager implementation
|
|
5
|
-
*/
|
|
3
|
+
export type JobState = 'in-progress' | 'paused' | 'completed' | 'cancelled';
|
|
6
4
|
export declare class PrintJobManager implements IPrintJobManager {
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
private static _cleanupTimer;
|
|
13
|
-
private static readonly CLEANUP_INTERVAL_MS;
|
|
14
|
-
private static readonly DEFAULT_EXPIRY_MS;
|
|
15
|
-
/** Start the auto-cleanup timer if not already running */
|
|
16
|
-
private static ensureCleanupTimer;
|
|
17
|
-
/**
|
|
18
|
-
* Get the static job state store (for backward compatibility)
|
|
19
|
-
* @deprecated Use instance-level store instead for multi-printer support
|
|
20
|
-
*/
|
|
21
|
-
private static get jobStateStore();
|
|
22
|
-
private adapter;
|
|
23
|
-
private connectionManager;
|
|
5
|
+
private readonly instanceJobStateStore;
|
|
6
|
+
private static staticJobStateStore;
|
|
7
|
+
private static cleanupTimer;
|
|
8
|
+
private readonly connectionManager;
|
|
9
|
+
private readonly adapter;
|
|
24
10
|
private jobBuffer;
|
|
25
11
|
private jobOffset;
|
|
26
|
-
private
|
|
27
|
-
private
|
|
12
|
+
private paused;
|
|
13
|
+
private inProgress;
|
|
28
14
|
private adapterOptions;
|
|
29
|
-
private readonly logger;
|
|
30
|
-
private onProgress?;
|
|
31
15
|
private jobId;
|
|
16
|
+
private onProgress?;
|
|
32
17
|
private onJobStateChange?;
|
|
33
|
-
|
|
34
|
-
* Sets the progress callback
|
|
35
|
-
*
|
|
36
|
-
* @param callback - Progress callback function
|
|
37
|
-
*/
|
|
38
|
-
setProgressCallback(callback?: (sent: number, total: number) => void): void;
|
|
39
|
-
/**
|
|
40
|
-
* Sets the job state change callback
|
|
41
|
-
*
|
|
42
|
-
* @param callback - Job state change callback function
|
|
43
|
-
*/
|
|
44
|
-
setJobStateCallback(callback?: (state: 'in-progress' | 'paused' | 'completed' | 'cancelled') => void): void;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a new PrintJobManager instance
|
|
47
|
-
*
|
|
48
|
-
* @param connectionManager - Connection manager instance
|
|
49
|
-
*/
|
|
18
|
+
private readonly logger;
|
|
50
19
|
constructor(connectionManager: IConnectionManager);
|
|
20
|
+
setProgressCallback(callback?: (sent: number, total: number) => void): void;
|
|
21
|
+
setJobStateCallback(callback?: (state: JobState) => void): void;
|
|
51
22
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @param buffer - Print data buffer
|
|
55
|
-
* @param options - Print job options
|
|
56
|
-
* @returns Promise<void>
|
|
23
|
+
* Wraps a raw error as BluetoothPrintError if it isn't already one.
|
|
57
24
|
*/
|
|
25
|
+
private wrapError;
|
|
58
26
|
start(buffer: Uint8Array, options?: {
|
|
59
27
|
jobId?: string;
|
|
60
28
|
}): Promise<void>;
|
|
61
|
-
/**
|
|
62
|
-
* Resumes a paused print job
|
|
63
|
-
*
|
|
64
|
-
* @param jobId - Job ID to resume (optional)
|
|
65
|
-
* @returns Promise<void>
|
|
66
|
-
*/
|
|
67
29
|
resume(jobId?: string): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Cancels the current print job
|
|
70
|
-
*/
|
|
71
30
|
cancel(): void;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
31
|
+
pause(): void;
|
|
32
|
+
isPaused(): boolean;
|
|
33
|
+
isInProgress(): boolean;
|
|
34
|
+
remaining(): number;
|
|
35
|
+
setOptions(options: IAdapterOptions): void;
|
|
36
|
+
destroy(): void;
|
|
77
37
|
private generateJobId;
|
|
78
|
-
/**
|
|
79
|
-
* Saves the current job state for resume later.
|
|
80
|
-
*
|
|
81
|
-
* Uses instance-level storage by default. Falls back to static store
|
|
82
|
-
* for backward compatibility.
|
|
83
|
-
*/
|
|
84
38
|
private saveJobState;
|
|
85
|
-
/**
|
|
86
|
-
* Loads a saved job state
|
|
87
|
-
*
|
|
88
|
-
* @param jobId - Job ID to load
|
|
89
|
-
*/
|
|
90
39
|
private loadJobState;
|
|
91
|
-
/**
|
|
92
|
-
* Clears the current job state
|
|
93
|
-
*/
|
|
94
40
|
private clearJobState;
|
|
95
41
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*/
|
|
99
|
-
destroy(): void;
|
|
100
|
-
/**
|
|
101
|
-
* Clean up expired job states from static store.
|
|
102
|
-
* Call this periodically to prevent memory leaks.
|
|
103
|
-
*
|
|
104
|
-
* @param maxAge - Maximum age in ms (default: 1 hour)
|
|
42
|
+
* Lazily start the auto-cleanup timer for the static store. The Node.js
|
|
43
|
+
* `unref()` call lets the process exit even if the timer is still scheduled.
|
|
105
44
|
*/
|
|
45
|
+
private static ensureCleanupTimer;
|
|
106
46
|
static cleanupExpiredJobs(maxAge?: number): number;
|
|
107
|
-
/**
|
|
108
|
-
* Stop the auto-cleanup timer. Useful for test teardown.
|
|
109
|
-
*/
|
|
110
47
|
static stopCleanupTimer(): void;
|
|
111
|
-
/**
|
|
112
|
-
* Get count of pending job states in static store.
|
|
113
|
-
* Useful for debugging memory usage.
|
|
114
|
-
*/
|
|
115
48
|
static getStaticStoreSize(): number;
|
|
116
|
-
/**
|
|
117
|
-
* Emits job state change event
|
|
118
|
-
*
|
|
119
|
-
* @param state - New job state
|
|
120
|
-
*/
|
|
121
|
-
private emitJobState;
|
|
122
|
-
/**
|
|
123
|
-
* Handles job completion: logs, resets state, and emits event.
|
|
124
|
-
* Shared by start() and resume() code paths.
|
|
125
|
-
*/
|
|
126
49
|
private completeJob;
|
|
127
|
-
|
|
128
|
-
* Pauses the current print job
|
|
129
|
-
*/
|
|
130
|
-
pause(): void;
|
|
131
|
-
/**
|
|
132
|
-
* Gets the number of bytes remaining to print
|
|
133
|
-
*
|
|
134
|
-
* @returns number - Bytes remaining
|
|
135
|
-
*/
|
|
136
|
-
remaining(): number;
|
|
137
|
-
/**
|
|
138
|
-
* Checks if the print job is paused
|
|
139
|
-
*
|
|
140
|
-
* @returns boolean - True if paused, false otherwise
|
|
141
|
-
*/
|
|
142
|
-
isPaused(): boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Checks if a print job is in progress
|
|
145
|
-
*
|
|
146
|
-
* @returns boolean - True if in progress, false otherwise
|
|
147
|
-
*/
|
|
148
|
-
isInProgress(): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Sets adapter options for write operations
|
|
151
|
-
*
|
|
152
|
-
* @param options - Adapter options
|
|
153
|
-
*/
|
|
154
|
-
setOptions(options: IAdapterOptions): void;
|
|
155
|
-
/**
|
|
156
|
-
* Processes the print job in chunks
|
|
157
|
-
* Supports pause/resume functionality
|
|
158
|
-
*
|
|
159
|
-
* @returns Promise<void>
|
|
160
|
-
*/
|
|
50
|
+
private emitJobState;
|
|
161
51
|
private processJob;
|
|
162
|
-
/**
|
|
163
|
-
* Gets the current device ID from the connection manager
|
|
164
|
-
*
|
|
165
|
-
* @returns string - Device ID
|
|
166
|
-
* @throws BluetoothPrintError if no device is connected
|
|
167
|
-
*/
|
|
168
52
|
private getDeviceId;
|
|
169
53
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded Ordered Map
|
|
3
|
+
*
|
|
4
|
+
* A `Map<K, V>` that enforces a maximum size, evicting the oldest entries
|
|
5
|
+
* (by `value.createdAt`) when capacity is exceeded. The underlying ordered
|
|
6
|
+
* index enables O(log n) insertion position lookup (binary search) and
|
|
7
|
+
* O(k) eviction of the k oldest entries.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam K - Key type
|
|
10
|
+
* @typeParam V - Value type (must carry a `createdAt: number` for ordering)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const map = new BoundedOrderedMap<string, PrintHistoryEntry>(1000);
|
|
15
|
+
* map.set('id-1', { id: 'id-1', createdAt: Date.now(), ... });
|
|
16
|
+
* const entry = map.get('id-1');
|
|
17
|
+
* map.size; // current entry count
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class BoundedOrderedMap<K, V extends {
|
|
21
|
+
createdAt: number;
|
|
22
|
+
}> {
|
|
23
|
+
private readonly maxEntries;
|
|
24
|
+
private readonly entries;
|
|
25
|
+
private readonly orderedIds;
|
|
26
|
+
constructor(maxEntries: number);
|
|
27
|
+
/** Insert or update an entry. Triggers eviction if size exceeds maxEntries. */
|
|
28
|
+
set(id: K, value: V): void;
|
|
29
|
+
get(id: K): V | undefined;
|
|
30
|
+
has(id: K): boolean;
|
|
31
|
+
delete(id: K): boolean;
|
|
32
|
+
clear(): void;
|
|
33
|
+
get size(): number;
|
|
34
|
+
get maxSize(): number;
|
|
35
|
+
values(): IterableIterator<V>;
|
|
36
|
+
keys(): IterableIterator<K>;
|
|
37
|
+
entriesIter(): IterableIterator<[K, V]>;
|
|
38
|
+
/**
|
|
39
|
+
* Re-sort the ordered index from the underlying entries. Call after bulk
|
|
40
|
+
* mutations that bypass `set()` (e.g. restoring from persistence).
|
|
41
|
+
*/
|
|
42
|
+
rebuildIndex(): void;
|
|
43
|
+
/** Trim oldest entries until size <= maxEntries. */
|
|
44
|
+
private enforceMaxEntries;
|
|
45
|
+
/** Binary search for the insertion position to keep orderedIds ascending. */
|
|
46
|
+
private findInsertPosition;
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taro-bluetooth-print",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Taro 蓝牙打印库 v2.6 - 轻量级、高性能、跨平台支持微信、支付宝、百度、字节跳动小程序及H5 Web Bluetooth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -99,5 +99,7 @@
|
|
|
99
99
|
"vite@<=6.4.1": ">=6.4.2",
|
|
100
100
|
"postcss@<8.5.10": ">=8.5.10"
|
|
101
101
|
}
|
|
102
|
-
}
|
|
102
|
+
},
|
|
103
|
+
"homepage": "https://agions.github.io/taro-bluetooth-print/",
|
|
104
|
+
"documentation": "https://agions.github.io/taro-bluetooth-print/"
|
|
103
105
|
}
|
|
@@ -12,7 +12,7 @@ import { ByteDanceAdapter } from './ByteDanceAdapter';
|
|
|
12
12
|
import { QQAdapter } from './QQAdapter';
|
|
13
13
|
import { WebBluetoothAdapter } from './WebBluetoothAdapter';
|
|
14
14
|
import { PlatformType, detectPlatform } from '@/utils/platform';
|
|
15
|
-
import { BluetoothPrintError, ErrorCode } from '@/errors/
|
|
15
|
+
import { BluetoothPrintError, ErrorCode } from '@/errors/BaseError';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Adapter factory class
|