@aiao/rxdb-adapter-pglite 0.0.1 → 0.0.3

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 (2) hide show
  1. package/index.js +55 -55
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,66 +1,66 @@
1
- import { RxDBError as _, PropertyType as i, TransactionBeginEvent as b, TransactionCommitEvent as f, TransactionRollbackEvent as w, RxDBAdapterLocalBase as x, getEntityMetadata as E } from "@aiao/rxdb";
2
- import { Observable as $, shareReplay as T, switchMap as l, from as g, map as u, firstValueFrom as m } from "rxjs";
3
- import { isFunction as y, isString as R } from "@aiao/utils";
4
- import { PGlite as q } from "@electric-sql/pglite";
5
- class v extends _ {
1
+ import { RxDBError as b, PropertyType as r, TransactionBeginEvent as f, TransactionCommitEvent as w, TransactionRollbackEvent as x, RxDBAdapterLocalBase as $, getEntityMetadata as T } from "@aiao/rxdb";
2
+ import { Observable as g, shareReplay as _, switchMap as u, from as y, map as m, firstValueFrom as p } from "rxjs";
3
+ import { isFunction as R, isString as q } from "@aiao/utils";
4
+ import { PGlite as v } from "@electric-sql/pglite";
5
+ class a extends b {
6
6
  }
7
7
  const A = (s) => {
8
8
  switch (s.type) {
9
- case i.uuid:
9
+ case r.uuid:
10
10
  return "uuid";
11
- case i.string:
11
+ case r.string:
12
12
  return "varchar";
13
- case i.json:
13
+ case r.json:
14
14
  return "jsonb";
15
- case i.number:
15
+ case r.number:
16
16
  return "numeric";
17
- case i.integer:
17
+ case r.integer:
18
18
  return "integer";
19
- case i.boolean:
19
+ case r.boolean:
20
20
  return "boolean";
21
- case i.date:
21
+ case r.date:
22
22
  return "timestamptz";
23
23
  }
24
24
  }, L = (s) => {
25
25
  switch (s.type) {
26
- case i.uuid:
26
+ case r.uuid:
27
27
  return "uuid_ops";
28
- case i.string:
28
+ case r.string:
29
29
  return "bpchar_ops";
30
- case i.json:
30
+ case r.json:
31
31
  return "jsonb_ops";
32
- case i.number:
32
+ case r.number:
33
33
  return "numeric_ops";
34
- case i.integer:
34
+ case r.integer:
35
35
  return "int4_ops";
36
36
  default:
37
- throw new Error(`rxDBColumnTypeToPGliteTypeIndexName: type '${s.type}' not support`);
37
+ throw new a(`rxDBColumnTypeToPGliteTypeIndexName: type '${s.type}' not support`);
38
38
  }
39
39
  }, C = (s, e) => `idx_${s.namespace}_${s.name}_${e.name}`, D = (s, e) => {
40
40
  let t = `CREATE TABLE ${e.namespace}."${e.name}" (`;
41
- const r = [], c = [], p = [];
41
+ const i = [], l = [], h = [];
42
42
  e.propertyMap.forEach((n) => {
43
43
  let o = "";
44
44
  o += `"${n.name}"`;
45
- const d = A(n);
46
- if (n.primary ? n.type === i.integer ? o += " serial PRIMARY KEY" : o += ` ${d} PRIMARY KEY` : o += ` ${d}`, !n.nullable) o += " NOT NULL";
45
+ const E = A(n);
46
+ if (n.primary ? n.type === r.integer ? o += " serial PRIMARY KEY" : o += ` ${E} PRIMARY KEY` : o += ` ${E}`, !n.nullable) o += " NOT NULL";
47
47
  else if (Reflect.get(n, "default") !== void 0) {
48
- let a = n.default;
49
- y(n.default) && (a = n.default()), R(a) ? ["CURRENT_TIMESTAMP", "now()"].includes(a) ? o += " DEFAULT now()" : o += ` DEFAULT '${a}'` : o += ` DEFAULT ${String(a)}`;
48
+ let c = n.default;
49
+ R(n.default) && (c = n.default()), q(c) ? ["CURRENT_TIMESTAMP", "now()"].includes(c) ? o += " DEFAULT now()" : o += ` DEFAULT '${c}'` : o += ` DEFAULT ${String(c)}`;
50
50
  }
51
- n.unique && r.push(
51
+ n.unique && i.push(
52
52
  `CREATE UNIQUE INDEX "${C(e, n)}" on ${e.namespace}."${e.name}" ("${n.name}" ${L(n)});`
53
- ), p.push(o);
53
+ ), h.push(o);
54
54
  });
55
- const h = [...p, ...c];
56
- if (h.length)
57
- t += h.map((n) => `
55
+ const d = [...h, ...l];
56
+ if (d.length)
57
+ t += d.map((n) => `
58
58
  ${n}`).join(","), t += `
59
59
  );`;
60
60
  else
61
- throw new v("columns is empty!");
62
- return r.length && (t += `
63
- ` + r.join(`
61
+ throw new a("columns is empty!");
62
+ return i.length && (t += `
63
+ ` + i.join(`
64
64
  `)), t;
65
65
  }, M = (s, e) => "", P = (s, e) => {
66
66
  let t = "";
@@ -69,7 +69,7 @@ ${n}`).join(","), t += `
69
69
  class N {
70
70
  #e;
71
71
  async init(e, t) {
72
- return this.#e = new q({
72
+ return this.#e = new v({
73
73
  dataDir: t.store === "memory" ? void 0 : `idb://${e}`,
74
74
  database: e
75
75
  }), this.#e.waitReady;
@@ -80,8 +80,8 @@ class N {
80
80
  exec(e, t) {
81
81
  return this.#e.exec(e, t);
82
82
  }
83
- query(e, t, r) {
84
- return this.#e.query(e, t, r);
83
+ query(e, t, i) {
84
+ return this.#e.query(e, t, i);
85
85
  }
86
86
  describeQuery(e, t) {
87
87
  return this.#e.describeQuery(e, t);
@@ -93,78 +93,78 @@ class N {
93
93
  return this.#e.runExclusive(e);
94
94
  }
95
95
  disconnect() {
96
- throw new Error("Method not implemented.");
96
+ throw new a("Method not implemented.");
97
97
  }
98
98
  async version() {
99
99
  return (await this.#e.query("SELECT version()")).rows[0].version;
100
100
  }
101
101
  }
102
- class U extends x {
102
+ class U extends $ {
103
103
  constructor(e, t) {
104
104
  super(e), this.options = t;
105
105
  }
106
- #e = new $((e) => {
106
+ #e = new g((e) => {
107
107
  const t = new N();
108
108
  t.init(this.rxdb.options.dbName, this.options).then(() => e.next(t));
109
- }).pipe(T(1));
109
+ }).pipe(_(1));
110
110
  /**
111
111
  * 数据库版本
112
112
  */
113
113
  version$ = this.#e.pipe(
114
- l((e) => g(e.version())),
115
- T(1)
114
+ u((e) => y(e.version())),
115
+ _(1)
116
116
  );
117
117
  name = S;
118
118
  connect() {
119
- return this.#e.pipe(u(() => this));
119
+ return this.#e.pipe(m(() => this));
120
120
  }
121
121
  disconnect() {
122
- throw new Error("Method disconnect not implemented.");
122
+ throw new a("Method disconnect not implemented.");
123
123
  }
124
124
  /**
125
125
  * 获取版本
126
126
  */
127
127
  version() {
128
- return m(this.version$);
128
+ return p(this.version$);
129
129
  }
130
130
  getRepository(e) {
131
- throw new Error("Method getRepository not implemented.");
131
+ throw new a("Method getRepository not implemented.");
132
132
  }
133
133
  createTable(e) {
134
- const t = E(e), r = P(this, t);
135
- return t.log, m(this.#n(r).pipe(u(() => !0)));
134
+ const t = T(e), i = P(this, t);
135
+ return t.log, p(this.#n(i).pipe(m(() => !0)));
136
136
  }
137
137
  async isTableExisted(e) {
138
- return m(this.isTableExisted$(e));
138
+ return p(this.isTableExisted$(e));
139
139
  }
140
140
  /**
141
141
  * 判断表是否存在
142
142
  * @param EntityType
143
143
  */
144
144
  isTableExisted$(e) {
145
- const t = E(e);
145
+ const t = T(e);
146
146
  return this.#t(
147
147
  `SELECT EXISTS (
148
148
  SELECT 1
149
149
  FROM information_schema.tables
150
150
  WHERE table_schema = '${t.namespace}'
151
151
  AND table_name = '${t.name}');`
152
- ).pipe(u((r) => r.rows[0]?.exists));
152
+ ).pipe(m((i) => i.rows[0]?.exists));
153
153
  }
154
154
  transaction(e) {
155
- throw new Error("Method transaction not implemented.");
155
+ throw new a("Method transaction not implemented.");
156
156
  }
157
- #t(e, t, r) {
158
- return this.#e.pipe(l((c) => c.query(e, t, r)));
157
+ #t(e, t, i) {
158
+ return this.#e.pipe(u((l) => l.query(e, t, i)));
159
159
  }
160
160
  #n(e, t) {
161
- return this.#e.pipe(l((r) => r.exec(e, t)));
161
+ return this.#e.pipe(u((i) => i.exec(e, t)));
162
162
  }
163
163
  }
164
- new b();
165
164
  new f();
166
165
  new w();
166
+ new x();
167
167
  export {
168
168
  U as RxDBAdapterPGlite,
169
- v as RxdbAdapterPGliteError
169
+ a as RxdbAdapterPGliteError
170
170
  };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-adapter-pglite",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
7
7
  "dependencies": {
8
8
  "@electric-sql/pglite": "^0.3.6",
9
- "@aiao/rxdb": "0.0.1",
9
+ "@aiao/rxdb": "0.0.3",
10
10
  "rxjs": "~7.8.2",
11
- "@aiao/utils": "0.0.1"
11
+ "@aiao/utils": "0.0.3"
12
12
  },
13
13
  "publishConfig": {
14
14
  "access": "public"