@capgo/capacitor-fast-sql 8.0.24 → 8.0.25

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/README.md CHANGED
@@ -125,6 +125,26 @@ const db = await FastSQL.connect({
125
125
 
126
126
  If SQLCipher is not installed and `encrypted: true` is passed, the plugin returns a clear error message instead of crashing.
127
127
 
128
+ ## Web Platform
129
+
130
+ On the web, this plugin uses [sql.js](https://sql.js.org/) (SQLite compiled to WebAssembly) with IndexedDB for persistence.
131
+
132
+ By default, the plugin loads `sql-wasm.js` and `sql-wasm.wasm` from the cdnjs CDN. If you want to bundle these files with your web application (to avoid a CDN dependency), call `configureWeb()` once at startup **before** the first `connect()`:
133
+
134
+ ```typescript
135
+ import { CapgoCapacitorFastSql, FastSQL } from '@capgo/capacitor-fast-sql';
136
+
137
+ // Point to your locally bundled sql.js files
138
+ await CapgoCapacitorFastSql.configureWeb({
139
+ sqlJsUrl: '/assets/sql-wasm.js',
140
+ wasmUrl: '/assets/sql-wasm.wasm',
141
+ });
142
+
143
+ const db = await FastSQL.connect({ database: 'myapp' });
144
+ ```
145
+
146
+ `configureWeb()` is a no-op on iOS and Android — it is safe to call unconditionally.
147
+
128
148
  ## Usage
129
149
 
130
150
  ### Basic Example
@@ -219,6 +239,7 @@ await kv.remove('session');
219
239
  * [`commitTransaction(...)`](#committransaction)
220
240
  * [`rollbackTransaction(...)`](#rollbacktransaction)
221
241
  * [`getPluginVersion()`](#getpluginversion)
242
+ * [`configureWeb(...)`](#configureweb)
222
243
  * [Interfaces](#interfaces)
223
244
  * [Type Aliases](#type-aliases)
224
245
  * [Enums](#enums)
@@ -374,6 +395,27 @@ Get the native Capacitor plugin version.
374
395
  --------------------
375
396
 
376
397
 
398
+ ### configureWeb(...)
399
+
400
+ ```typescript
401
+ configureWeb(config: WebConfig) => Promise<void>
402
+ ```
403
+
404
+ Configure web-specific options for the sql.js WASM module.
405
+
406
+ Call this **before** the first `connect()` call to load sql.js from a
407
+ locally bundled path instead of the default CDN. This method is a no-op
408
+ on iOS and Android.
409
+
410
+ | Param | Type | Description |
411
+ | ------------ | ----------------------------------------------- | --------------------------- |
412
+ | **`config`** | <code><a href="#webconfig">WebConfig</a></code> | - Web configuration options |
413
+
414
+ **Since:** 0.0.1
415
+
416
+ --------------------
417
+
418
+
377
419
  ### Interfaces
378
420
 
379
421
 
@@ -480,6 +522,18 @@ buffer as needed.
480
522
  | **slice** | (begin: number, end?: number \| undefined) =&gt; <a href="#arraybuffer">ArrayBuffer</a> | Returns a section of an <a href="#arraybuffer">ArrayBuffer</a>. |
481
523
 
482
524
 
525
+ #### WebConfig
526
+
527
+ Web platform configuration for the sql.js WASM module.
528
+ Use with `configureWeb()` to load sql.js
529
+ from a locally bundled path instead of the default CDN.
530
+
531
+ | Prop | Type | Description |
532
+ | -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------- |
533
+ | **`sqlJsUrl`** | <code>string</code> | URL to the sql.js JavaScript file (`sql-wasm.js`). When omitted, the plugin loads from the cdnjs CDN. |
534
+ | **`wasmUrl`** | <code>string</code> | URL to the sql.js WebAssembly binary (`sql-wasm.wasm`). When omitted, the plugin loads from the cdnjs CDN. |
535
+
536
+
483
537
  ### Type Aliases
484
538
 
485
539
 
@@ -54,7 +54,7 @@ dependencies {
54
54
  implementation 'androidx.sqlite:sqlite:2.6.2'
55
55
  implementation 'com.google.code.gson:gson:2.13.2'
56
56
  implementation 'org.nanohttpd:nanohttpd:2.3.1'
57
- compileOnly 'net.zetetic:sqlcipher-android:4.13.0'
57
+ compileOnly 'net.zetetic:sqlcipher-android:4.14.0'
58
58
  testImplementation "junit:junit:$junitVersion"
59
59
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
60
60
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -19,7 +19,7 @@ import java.util.Map;
19
19
  @CapacitorPlugin(name = "CapgoCapacitorFastSql")
20
20
  public class CapgoCapacitorFastSqlPlugin extends Plugin {
21
21
 
22
- private final String pluginVersion = "8.0.24";
22
+ private final String pluginVersion = "8.0.25";
23
23
 
24
24
  private Map<String, DatabaseConnection> databases = new HashMap<>();
25
25
  private SQLHTTPServer server;
@@ -235,6 +235,12 @@ public class CapgoCapacitorFastSqlPlugin extends Plugin {
235
235
  }
236
236
  }
237
237
 
238
+ @PluginMethod
239
+ public void configureWeb(PluginCall call) {
240
+ // No-op on Android — web configuration is only relevant on the web platform.
241
+ call.resolve();
242
+ }
243
+
238
244
  @PluginMethod
239
245
  public void getPluginVersion(PluginCall call) {
240
246
  JSObject ret = new JSObject();
@@ -17,7 +17,7 @@ import org.json.JSONObject;
17
17
  public class EncryptedSQLDatabase implements DatabaseConnection {
18
18
 
19
19
  private SQLiteDatabase db;
20
- private boolean inTransaction = false;
20
+ private volatile boolean inTransaction = false;
21
21
 
22
22
  public EncryptedSQLDatabase(String path, String encryptionKey) throws Exception {
23
23
  if (encryptionKey == null || encryptionKey.isEmpty()) {
@@ -119,28 +119,27 @@ public class EncryptedSQLDatabase implements DatabaseConnection {
119
119
  }
120
120
  }
121
121
 
122
- public void beginTransaction() throws Exception {
122
+ public synchronized void beginTransaction() throws Exception {
123
123
  if (inTransaction) {
124
124
  throw new Exception("Transaction already active");
125
125
  }
126
- db.beginTransaction();
126
+ db.execSQL("BEGIN TRANSACTION");
127
127
  inTransaction = true;
128
128
  }
129
129
 
130
- public void commitTransaction() throws Exception {
130
+ public synchronized void commitTransaction() throws Exception {
131
131
  if (!inTransaction) {
132
132
  throw new Exception("No transaction active");
133
133
  }
134
- db.setTransactionSuccessful();
135
- db.endTransaction();
134
+ db.execSQL("COMMIT");
136
135
  inTransaction = false;
137
136
  }
138
137
 
139
- public void rollbackTransaction() throws Exception {
138
+ public synchronized void rollbackTransaction() throws Exception {
140
139
  if (!inTransaction) {
141
140
  throw new Exception("No transaction active");
142
141
  }
143
- db.endTransaction();
142
+ db.execSQL("ROLLBACK");
144
143
  inTransaction = false;
145
144
  }
146
145
 
@@ -18,7 +18,7 @@ import org.json.JSONObject;
18
18
  public class SQLDatabase implements DatabaseConnection {
19
19
 
20
20
  private SQLiteDatabase db;
21
- private boolean inTransaction = false;
21
+ private volatile boolean inTransaction = false;
22
22
 
23
23
  public SQLDatabase(String path) {
24
24
  this.db = SQLiteDatabase.openOrCreateDatabase(path, null);
@@ -113,28 +113,27 @@ public class SQLDatabase implements DatabaseConnection {
113
113
  }
114
114
  }
115
115
 
116
- public void beginTransaction() throws Exception {
116
+ public synchronized void beginTransaction() throws Exception {
117
117
  if (inTransaction) {
118
118
  throw new Exception("Transaction already active");
119
119
  }
120
- db.beginTransaction();
120
+ db.execSQL("BEGIN TRANSACTION");
121
121
  inTransaction = true;
122
122
  }
123
123
 
124
- public void commitTransaction() throws Exception {
124
+ public synchronized void commitTransaction() throws Exception {
125
125
  if (!inTransaction) {
126
126
  throw new Exception("No transaction active");
127
127
  }
128
- db.setTransactionSuccessful();
129
- db.endTransaction();
128
+ db.execSQL("COMMIT");
130
129
  inTransaction = false;
131
130
  }
132
131
 
133
- public void rollbackTransaction() throws Exception {
132
+ public synchronized void rollbackTransaction() throws Exception {
134
133
  if (!inTransaction) {
135
134
  throw new Exception("No transaction active");
136
135
  }
137
- db.endTransaction();
136
+ db.execSQL("ROLLBACK");
138
137
  inTransaction = false;
139
138
  }
140
139
 
@@ -59,6 +59,25 @@ export interface SQLConnectionOptions {
59
59
  */
60
60
  readOnly?: boolean;
61
61
  }
62
+ /**
63
+ * Web platform configuration for the sql.js WASM module.
64
+ * Use with `configureWeb()` to load sql.js
65
+ * from a locally bundled path instead of the default CDN.
66
+ */
67
+ export interface WebConfig {
68
+ /**
69
+ * URL to the sql.js JavaScript file (`sql-wasm.js`).
70
+ * When omitted, the plugin loads from the cdnjs CDN.
71
+ * @example '/assets/sql-wasm.js'
72
+ */
73
+ sqlJsUrl?: string;
74
+ /**
75
+ * URL to the sql.js WebAssembly binary (`sql-wasm.wasm`).
76
+ * When omitted, the plugin loads from the cdnjs CDN.
77
+ * @example '/assets/sql-wasm.wasm'
78
+ */
79
+ wasmUrl?: string;
80
+ }
62
81
  /**
63
82
  * Transaction isolation levels
64
83
  */
@@ -221,5 +240,26 @@ export interface CapgoCapacitorFastSqlPlugin {
221
240
  getPluginVersion(): Promise<{
222
241
  version: string;
223
242
  }>;
243
+ /**
244
+ * Configure web-specific options for the sql.js WASM module.
245
+ *
246
+ * Call this **before** the first `connect()` call to load sql.js from a
247
+ * locally bundled path instead of the default CDN. This method is a no-op
248
+ * on iOS and Android.
249
+ *
250
+ * @param config - Web configuration options
251
+ * @returns Promise that resolves when the configuration is applied
252
+ * @since 0.0.1
253
+ * @example
254
+ * ```typescript
255
+ * // Configure once at app startup (web only)
256
+ * await CapgoCapacitorFastSql.configureWeb({
257
+ * sqlJsUrl: '/assets/sql-wasm.js',
258
+ * wasmUrl: '/assets/sql-wasm.wasm',
259
+ * });
260
+ * const db = await FastSQL.connect({ database: 'myapp' });
261
+ * ```
262
+ */
263
+ configureWeb(config: WebConfig): Promise<void>;
224
264
  }
225
265
  //# sourceMappingURL=definitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,EAAE,MAAM,CA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E,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhG;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;;;;;;;;;;;;;;;OAiBG;IACH,mBAAmB,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElE;;;;;;;;;;;OAWG;IACH,gBAAgB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEjD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD"}
@@ -1,5 +1,5 @@
1
1
  import type { SQLConnectionOptions } from './definitions';
2
- import { SQLConnection } from './sql-connection';
2
+ import type { SQLConnection } from './sql-connection';
3
3
  /**
4
4
  * FastSQL - High-level API for managing SQL connections
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"fast-sql.d.ts","sourceRoot":"","sources":["../../src/fast-sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAyC;IAEnE;;;;;OAKG;WACU,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC;IAmB3E;;;;OAIG;WACU,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxD;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAI5D;;OAEG;WACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3C;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,IAAI,MAAM,EAAE;CAGpC"}
1
+ {"version":3,"file":"fast-sql.d.ts","sourceRoot":"","sources":["../../src/fast-sql.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD;;;;;GAKG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAyC;IAEnE;;;;;OAKG;WACU,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC;IAyB3E;;;;OAIG;WACU,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxD;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAI5D;;OAEG;WACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3C;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,IAAI,MAAM,EAAE;CAGpC"}
@@ -1,5 +1,7 @@
1
+ import { Capacitor } from '@capacitor/core';
2
+ import { NativeSQLConnection } from './native-sql-connection';
1
3
  import { CapgoCapacitorFastSql } from './plugin';
2
- import { SQLConnection } from './sql-connection';
4
+ import { WebSQLConnection } from './web-sql-connection';
3
5
  /**
4
6
  * FastSQL - High-level API for managing SQL connections
5
7
  *
@@ -21,8 +23,15 @@ export class FastSQL {
21
23
  }
22
24
  // Connect via native plugin
23
25
  const info = await CapgoCapacitorFastSql.connect(options);
24
- // Create connection instance
25
- const connection = new SQLConnection(info.database, info.port, info.token);
26
+ // Create connection instance appropriate for the current platform
27
+ let connection;
28
+ const platform = Capacitor.getPlatform();
29
+ if (platform === 'android' || platform === 'ios') {
30
+ connection = new NativeSQLConnection(info.database, info.port, info.token);
31
+ }
32
+ else {
33
+ connection = new WebSQLConnection(info.database, CapgoCapacitorFastSql);
34
+ }
26
35
  // Store connection
27
36
  this.connections.set(options.database, connection);
28
37
  return connection;
@@ -3,4 +3,3 @@
3
3
  * Import these separately: import { FastSQL, SQLConnection } from '@capgo/capacitor-fast-sql/helpers';
4
4
  */
5
5
  export { FastSQL } from './fast-sql';
6
- export { SQLConnection } from './sql-connection';
@@ -1,7 +1,9 @@
1
1
  export * from './definitions';
2
2
  export { CapgoCapacitorFastSql } from './plugin';
3
3
  export { FastSQL } from './fast-sql';
4
- export { SQLConnection } from './sql-connection';
4
+ export type { SQLConnection } from './sql-connection';
5
+ export { NativeSQLConnection } from './native-sql-connection';
6
+ export { WebSQLConnection } from './web-sql-connection';
5
7
  export { KeyValueStore } from './key-value';
6
8
  export type { KeyValueStoreOptions, KeyValueValue } from './key-value';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/esm/index.js CHANGED
@@ -2,5 +2,6 @@ export * from './definitions';
2
2
  export { CapgoCapacitorFastSql } from './plugin';
3
3
  // Re-export helper classes for convenience
4
4
  export { FastSQL } from './fast-sql';
5
- export { SQLConnection } from './sql-connection';
5
+ export { NativeSQLConnection } from './native-sql-connection';
6
+ export { WebSQLConnection } from './web-sql-connection';
6
7
  export { KeyValueStore } from './key-value';
@@ -0,0 +1,95 @@
1
+ import type { SQLValue, SQLRow, SQLResult, SQLBatchOperation } from './definitions';
2
+ import { IsolationLevel } from './definitions';
3
+ import type { SQLConnection } from './sql-connection';
4
+ /**
5
+ * SQL Connection class that uses HTTP protocol for efficient communication
6
+ * with native SQLite databases, bypassing Capacitor's standard bridge.
7
+ *
8
+ * Inspired by capacitor-blob-writer's approach to avoid serialization overhead.
9
+ */
10
+ export declare class NativeSQLConnection implements SQLConnection {
11
+ private port;
12
+ private token;
13
+ private database;
14
+ private baseUrl;
15
+ private inTransaction;
16
+ constructor(database: string, port: number, token: string);
17
+ /**
18
+ * Get the database name
19
+ */
20
+ getDatabaseName(): string;
21
+ /**
22
+ * Execute a SQL query via HTTP protocol for optimal performance
23
+ *
24
+ * @param statement - SQL statement to execute
25
+ * @param params - Parameters to bind to the statement
26
+ * @returns Query results
27
+ */
28
+ execute(statement: string, params?: SQLValue[]): Promise<SQLResult>;
29
+ /**
30
+ * Execute multiple SQL statements in a batch for better performance
31
+ *
32
+ * @param operations - Array of SQL operations to execute
33
+ * @returns Array of results for each operation
34
+ */
35
+ executeBatch(operations: SQLBatchOperation[]): Promise<SQLResult[]>;
36
+ /**
37
+ * Begin a transaction
38
+ *
39
+ * @param isolationLevel - Optional isolation level
40
+ */
41
+ beginTransaction(isolationLevel?: IsolationLevel): Promise<void>;
42
+ /**
43
+ * Commit the current transaction
44
+ */
45
+ commit(): Promise<void>;
46
+ /**
47
+ * Rollback the current transaction
48
+ */
49
+ rollback(): Promise<void>;
50
+ /**
51
+ * Execute operations within a transaction automatically
52
+ *
53
+ * @param callback - Function containing operations to execute
54
+ * @param isolationLevel - Optional isolation level
55
+ */
56
+ transaction<T>(callback: (conn: SQLConnection) => Promise<T>, isolationLevel?: IsolationLevel): Promise<T>;
57
+ /**
58
+ * Query helper for SELECT statements
59
+ *
60
+ * @param statement - SELECT statement
61
+ * @param params - Query parameters
62
+ * @returns Array of rows
63
+ */
64
+ query(statement: string, params?: SQLValue[]): Promise<SQLRow[]>;
65
+ /**
66
+ * Execute helper for INSERT/UPDATE/DELETE statements
67
+ *
68
+ * @param statement - SQL statement
69
+ * @param params - Statement parameters
70
+ * @returns Number of affected rows and insert ID if applicable
71
+ */
72
+ run(statement: string, params?: SQLValue[]): Promise<{
73
+ rowsAffected: number;
74
+ insertId?: number;
75
+ }>;
76
+ /**
77
+ * Serialize parameters for transmission
78
+ * Binary data (Uint8Array) is converted to base64 for JSON transport
79
+ */
80
+ private serializeParams;
81
+ /**
82
+ * Deserialize result from server
83
+ * Base64-encoded binary data is converted back to Uint8Array
84
+ */
85
+ private deserializeResult;
86
+ /**
87
+ * Convert Uint8Array to base64 string
88
+ */
89
+ private uint8ArrayToBase64;
90
+ /**
91
+ * Convert base64 string to Uint8Array
92
+ */
93
+ private base64ToUint8Array;
94
+ }
95
+ //# sourceMappingURL=native-sql-connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-sql-connection.d.ts","sourceRoot":"","sources":["../../src/native-sql-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAA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