jazz-react-native 0.14.16 → 0.14.18

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > jazz-react-native@0.14.16 build /home/runner/_work/jazz/jazz/packages/jazz-react-native
2
+ > jazz-react-native@0.14.18 build /home/runner/_work/jazz/jazz/packages/jazz-react-native
3
3
  > rm -rf ./dist && tsc --sourceMap --outDir dist
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # jazz-browser
2
2
 
3
+ ## 0.14.18
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4b950bc]
8
+ - Updated dependencies [0d5ee3e]
9
+ - Updated dependencies [d6d9c0a]
10
+ - Updated dependencies [be7c4c2]
11
+ - Updated dependencies [c559054]
12
+ - jazz-tools@0.14.18
13
+ - jazz-react-native-core@0.14.18
14
+ - cojson@0.14.18
15
+ - cojson-storage@0.14.18
16
+
17
+ ## 0.14.17
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [e512df4]
22
+ - jazz-tools@0.14.17
23
+ - jazz-react-native-core@0.14.17
24
+
3
25
  ## 0.14.16
4
26
 
5
27
  ### Patch Changes
@@ -1,18 +1,12 @@
1
- import type { SQLResult, SQLRow, SQLiteAdapter } from "jazz-react-native-core";
2
- export declare class OPSQLiteAdapter implements SQLiteAdapter {
1
+ import { type SQLiteDatabaseDriverAsync } from "jazz-react-native-core";
2
+ export declare class OPSQLiteAdapter implements SQLiteDatabaseDriverAsync {
3
3
  private db;
4
4
  private dbName;
5
- private dbPath;
6
- private initializationPromise;
7
- private isInitialized;
8
5
  constructor(dbName?: string);
9
- private initializeInternal;
10
- private ensureInitialized;
11
6
  initialize(): Promise<void>;
12
- execute(sql: string, params?: unknown[]): Promise<SQLResult>;
13
- executeSync(sql: string, params?: unknown[]): {
14
- rows: SQLRow[];
15
- };
16
- transaction(callback: () => Promise<void>): Promise<void>;
7
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
8
+ get<T>(sql: string, params?: unknown[]): Promise<T | undefined>;
9
+ run(sql: string, params?: unknown[]): Promise<void>;
10
+ transaction(callback: () => unknown): Promise<void>;
17
11
  }
18
12
  //# sourceMappingURL=op-sqlite-adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"op-sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAK/E,qBAAa,eAAgB,YAAW,aAAa;IACnD,OAAO,CAAC,EAAE,CAA2B;IACrC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,aAAa,CAAS;gBAEX,MAAM,GAAE,MAAuB;YAMpC,kBAAkB;YAkFlB,iBAAiB;IAkBlB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAwBlE,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE;IAU1D,WAAW,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAMvE"}
1
+ {"version":3,"file":"op-sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAExE,qBAAa,eAAgB,YAAW,yBAAyB;IAC/D,OAAO,CAAC,EAAE,CAA2B;IACrC,OAAO,CAAC,MAAM,CAAS;gBAEJ,MAAM,GAAE,MAAuB;IAIrC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAUvD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAU/D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE;IAQnC,WAAW,CAAC,QAAQ,EAAE,MAAM,OAAO;CAWjD"}
@@ -4,124 +4,47 @@ import { Platform } from "react-native";
4
4
  export class OPSQLiteAdapter {
5
5
  db = null;
6
6
  dbName;
7
- dbPath;
8
- initializationPromise = null;
9
- isInitialized = false;
10
7
  constructor(dbName = "jazz-storage") {
11
8
  this.dbName = dbName;
12
- this.dbPath =
13
- Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
14
9
  }
15
- async initializeInternal() {
16
- try {
17
- // Open database first
18
- this.db = opSQLite.open({
19
- name: this.dbName,
20
- location: this.dbPath,
21
- });
22
- // Direct database operations during initialization - don't use execute()
23
- const db = this.db;
24
- if (!db)
25
- throw new Error("Failed to open database");
26
- await db.execute("PRAGMA journal_mode=WAL");
27
- const { rows } = await db.execute("PRAGMA user_version");
28
- const oldVersion = Number(rows[0]?.user_version) ?? 0;
29
- if (oldVersion === 0) {
30
- await db.execute(`CREATE TABLE IF NOT EXISTS transactions (
31
- ses INTEGER,
32
- idx INTEGER,
33
- tx TEXT NOT NULL,
34
- PRIMARY KEY (ses, idx)
35
- ) WITHOUT ROWID;`);
36
- await db.execute(`CREATE TABLE IF NOT EXISTS sessions (
37
- rowID INTEGER PRIMARY KEY,
38
- coValue INTEGER NOT NULL,
39
- sessionID TEXT NOT NULL,
40
- lastIdx INTEGER,
41
- lastSignature TEXT,
42
- UNIQUE (sessionID, coValue)
43
- );`);
44
- await db.execute(`CREATE INDEX IF NOT EXISTS sessionsByCoValue ON sessions (coValue);`);
45
- await db.execute(`CREATE TABLE IF NOT EXISTS coValues (
46
- rowID INTEGER PRIMARY KEY,
47
- id TEXT NOT NULL UNIQUE,
48
- header TEXT NOT NULL UNIQUE
49
- );`);
50
- await db.execute(`CREATE INDEX IF NOT EXISTS coValuesByID ON coValues (id);`);
51
- await db.execute("PRAGMA user_version = 1");
52
- }
53
- if (oldVersion <= 2) {
54
- await db.execute(`CREATE TABLE IF NOT EXISTS signatureAfter (
55
- ses INTEGER,
56
- idx INTEGER,
57
- signature TEXT NOT NULL,
58
- PRIMARY KEY (ses, idx)
59
- ) WITHOUT ROWID;`);
60
- await db.execute(`ALTER TABLE sessions ADD COLUMN bytesSinceLastSignature INTEGER;`);
61
- await db.execute("PRAGMA user_version = 3");
62
- }
63
- console.log("[OPSQLiteAdapter] initialization complete");
64
- }
65
- catch (e) {
66
- console.error("[OPSQLiteAdapter] initialization failed:", e);
67
- throw new Error(`Failed to initialize OPSQLiteAdapter: ${e instanceof Error ? e.message : String(e)}`);
68
- }
10
+ async initialize() {
11
+ const dbPath = Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
12
+ const db = (this.db = opSQLite.open({
13
+ name: this.dbName,
14
+ location: dbPath,
15
+ }));
16
+ await db.execute("PRAGMA journal_mode=WAL");
69
17
  }
70
- async ensureInitialized() {
71
- if (this.isInitialized)
72
- return;
73
- if (!this.initializationPromise) {
74
- this.initializationPromise = (async () => {
75
- try {
76
- await this.initializeInternal();
77
- this.isInitialized = true;
78
- }
79
- catch (error) {
80
- this.initializationPromise = null;
81
- throw error;
82
- }
83
- })();
18
+ async query(sql, params) {
19
+ if (!this.db) {
20
+ throw new Error("Database not initialized");
84
21
  }
85
- await this.initializationPromise;
22
+ const result = await this.db.execute(sql, params);
23
+ return result.rows;
86
24
  }
87
- async initialize() {
88
- await this.ensureInitialized();
25
+ async get(sql, params) {
26
+ if (!this.db) {
27
+ throw new Error("Database not initialized");
28
+ }
29
+ const result = await this.db.execute(sql, params);
30
+ return result.rows[0];
89
31
  }
90
- async execute(sql, params) {
91
- await this.ensureInitialized();
92
- const db = this.db;
93
- if (!db) {
94
- throw new Error("Database not available after initialization");
32
+ async run(sql, params) {
33
+ if (!this.db) {
34
+ throw new Error("Database not initialized");
95
35
  }
36
+ await this.db.executeRaw(sql, params);
37
+ }
38
+ async transaction(callback) {
39
+ await this.run("BEGIN TRANSACTION");
96
40
  try {
97
- const result = await db.execute(sql, params);
98
- return {
99
- rows: result.rows,
100
- insertId: result.rowsAffected > 0
101
- ? result.rows[0]?.rowid
102
- : undefined,
103
- rowsAffected: result.rowsAffected,
104
- };
41
+ await callback();
42
+ await this.run("COMMIT");
105
43
  }
106
44
  catch (error) {
107
- console.error("[OPSQLiteAdapter] SQL execution error:", error);
45
+ await this.run("ROLLBACK");
108
46
  throw error;
109
47
  }
110
48
  }
111
- executeSync(sql, params) {
112
- if (!this.isInitialized || !this.db) {
113
- throw new Error("Database not initialized. Call initialize() first.");
114
- }
115
- const result = this.db.executeSync(sql, params);
116
- return {
117
- rows: result.rows,
118
- };
119
- }
120
- async transaction(callback) {
121
- if (!this.db) {
122
- await this.ensureInitialized();
123
- }
124
- await this.db.transaction(callback);
125
- }
126
49
  }
127
50
  //# sourceMappingURL=op-sqlite-adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"op-sqlite-adapter.js","sourceRoot":"","sources":["../../src/storage/op-sqlite-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,MAAM,OAAO,eAAe;IAClB,EAAE,GAAsB,I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AAC;YACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAe,CAAC,CAAC;QAE3D,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAkB,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAkB;QAC9C,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,MAAe,CAAC,CAAC;IACjD,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,QAAuB;QAC9C,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAEpC,IAAI,CAAC;YACH,MAAM,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC3B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jazz-react-native",
3
- "version": "0.14.16",
3
+ "version": "0.14.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -28,10 +28,10 @@
28
28
  "@op-engineering/op-sqlite": "^11.4.8",
29
29
  "@scure/base": "1.2.1",
30
30
  "react-native-mmkv": "^3.2.0",
31
- "cojson": "0.14.16",
32
- "jazz-react-native-core": "0.14.16",
33
- "jazz-tools": "0.14.16",
34
- "cojson-storage": "0.14.16"
31
+ "cojson": "0.14.18",
32
+ "cojson-storage": "0.14.18",
33
+ "jazz-react-native-core": "0.14.18",
34
+ "jazz-tools": "0.14.18"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@react-native-community/netinfo": "*",
@@ -3,166 +3,69 @@ import {
3
3
  ANDROID_DATABASE_PATH,
4
4
  IOS_LIBRARY_PATH,
5
5
  } from "@op-engineering/op-sqlite";
6
- import type { SQLResult, SQLRow, SQLiteAdapter } from "jazz-react-native-core";
7
6
  import { Platform } from "react-native";
8
7
 
9
8
  type OPSQLiteDB = ReturnType<typeof opSQLite.open>;
10
9
 
11
- export class OPSQLiteAdapter implements SQLiteAdapter {
10
+ import { type SQLiteDatabaseDriverAsync } from "jazz-react-native-core";
11
+
12
+ export class OPSQLiteAdapter implements SQLiteDatabaseDriverAsync {
12
13
  private db: OPSQLiteDB | null = null;
13
14
  private dbName: string;
14
- private dbPath: string;
15
- private initializationPromise: Promise<void> | null = null;
16
- private isInitialized = false;
17
15
 
18
16
  public constructor(dbName: string = "jazz-storage") {
19
17
  this.dbName = dbName;
20
- this.dbPath =
21
- Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
22
18
  }
23
19
 
24
- private async initializeInternal() {
25
- try {
26
- // Open database first
27
- this.db = opSQLite.open({
28
- name: this.dbName,
29
- location: this.dbPath,
30
- });
31
-
32
- // Direct database operations during initialization - don't use execute()
33
- const db = this.db;
34
- if (!db) throw new Error("Failed to open database");
35
-
36
- await db.execute("PRAGMA journal_mode=WAL");
37
- const { rows } = await db.execute("PRAGMA user_version");
38
- const oldVersion = Number(rows[0]?.user_version) ?? 0;
39
-
40
- if (oldVersion === 0) {
41
- await db.execute(
42
- `CREATE TABLE IF NOT EXISTS transactions (
43
- ses INTEGER,
44
- idx INTEGER,
45
- tx TEXT NOT NULL,
46
- PRIMARY KEY (ses, idx)
47
- ) WITHOUT ROWID;`,
48
- );
49
-
50
- await db.execute(
51
- `CREATE TABLE IF NOT EXISTS sessions (
52
- rowID INTEGER PRIMARY KEY,
53
- coValue INTEGER NOT NULL,
54
- sessionID TEXT NOT NULL,
55
- lastIdx INTEGER,
56
- lastSignature TEXT,
57
- UNIQUE (sessionID, coValue)
58
- );`,
59
- );
60
-
61
- await db.execute(
62
- `CREATE INDEX IF NOT EXISTS sessionsByCoValue ON sessions (coValue);`,
63
- );
64
-
65
- await db.execute(
66
- `CREATE TABLE IF NOT EXISTS coValues (
67
- rowID INTEGER PRIMARY KEY,
68
- id TEXT NOT NULL UNIQUE,
69
- header TEXT NOT NULL UNIQUE
70
- );`,
71
- );
72
-
73
- await db.execute(
74
- `CREATE INDEX IF NOT EXISTS coValuesByID ON coValues (id);`,
75
- );
76
-
77
- await db.execute("PRAGMA user_version = 1");
78
- }
79
-
80
- if (oldVersion <= 2) {
81
- await db.execute(
82
- `CREATE TABLE IF NOT EXISTS signatureAfter (
83
- ses INTEGER,
84
- idx INTEGER,
85
- signature TEXT NOT NULL,
86
- PRIMARY KEY (ses, idx)
87
- ) WITHOUT ROWID;`,
88
- );
89
-
90
- await db.execute(
91
- `ALTER TABLE sessions ADD COLUMN bytesSinceLastSignature INTEGER;`,
92
- );
93
-
94
- await db.execute("PRAGMA user_version = 3");
95
- }
96
-
97
- console.log("[OPSQLiteAdapter] initialization complete");
98
- } catch (e) {
99
- console.error("[OPSQLiteAdapter] initialization failed:", e);
100
- throw new Error(
101
- `Failed to initialize OPSQLiteAdapter: ${e instanceof Error ? e.message : String(e)}`,
102
- );
103
- }
20
+ public async initialize(): Promise<void> {
21
+ const dbPath =
22
+ Platform.OS === "ios" ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH;
23
+
24
+ const db = (this.db = opSQLite.open({
25
+ name: this.dbName,
26
+ location: dbPath,
27
+ }));
28
+
29
+ await db.execute("PRAGMA journal_mode=WAL");
104
30
  }
105
31
 
106
- private async ensureInitialized() {
107
- if (this.isInitialized) return;
108
-
109
- if (!this.initializationPromise) {
110
- this.initializationPromise = (async () => {
111
- try {
112
- await this.initializeInternal();
113
- this.isInitialized = true;
114
- } catch (error) {
115
- this.initializationPromise = null;
116
- throw error;
117
- }
118
- })();
32
+ public async query<T>(sql: string, params?: unknown[]): Promise<T[]> {
33
+ if (!this.db) {
34
+ throw new Error("Database not initialized");
119
35
  }
120
36
 
121
- await this.initializationPromise;
122
- }
37
+ const result = await this.db.execute(sql, params as any[]);
123
38
 
124
- public async initialize(): Promise<void> {
125
- await this.ensureInitialized();
39
+ return result.rows as T[];
126
40
  }
127
41
 
128
- public async execute(sql: string, params?: unknown[]): Promise<SQLResult> {
129
- await this.ensureInitialized();
130
-
131
- const db = this.db;
132
- if (!db) {
133
- throw new Error("Database not available after initialization");
42
+ public async get<T>(sql: string, params?: unknown[]): Promise<T | undefined> {
43
+ if (!this.db) {
44
+ throw new Error("Database not initialized");
134
45
  }
135
46
 
136
- try {
137
- const result = await db.execute(sql, params as any[]);
138
- return {
139
- rows: result.rows as SQLRow[],
140
- insertId:
141
- result.rowsAffected > 0
142
- ? (result.rows[0]?.rowid as number)
143
- : undefined,
144
- rowsAffected: result.rowsAffected,
145
- };
146
- } catch (error) {
147
- console.error("[OPSQLiteAdapter] SQL execution error:", error);
148
- throw error;
149
- }
47
+ const result = await this.db.execute(sql, params as any[]);
48
+
49
+ return result.rows[0] as T | undefined;
150
50
  }
151
51
 
152
- public executeSync(sql: string, params?: unknown[]): { rows: SQLRow[] } {
153
- if (!this.isInitialized || !this.db) {
154
- throw new Error("Database not initialized. Call initialize() first.");
52
+ public async run(sql: string, params?: unknown[]) {
53
+ if (!this.db) {
54
+ throw new Error("Database not initialized");
155
55
  }
156
- const result = this.db.executeSync(sql, params as any[]);
157
- return {
158
- rows: result.rows as SQLRow[],
159
- };
56
+
57
+ await this.db.executeRaw(sql, params as any[]);
160
58
  }
161
59
 
162
- public async transaction(callback: () => Promise<void>): Promise<void> {
163
- if (!this.db) {
164
- await this.ensureInitialized();
60
+ public async transaction(callback: () => unknown) {
61
+ await this.run("BEGIN TRANSACTION");
62
+
63
+ try {
64
+ await callback();
65
+ await this.run("COMMIT");
66
+ } catch (error) {
67
+ await this.run("ROLLBACK");
68
+ throw error;
165
69
  }
166
- await this.db!.transaction(callback);
167
70
  }
168
71
  }