@aiao/rxdb-client-generator 0.0.4 → 0.0.5

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,20 +1,20 @@
1
- import { PropertyType as u, RelationKind as h, getEntityMetadata as A, getEntityMetadataOptions as k, transitionMetadata as b, ENTITY_METADATA_MAP as C } from "@aiao/rxdb";
2
- import { isNil as j, omit as v, isObject as F, isArray as B, capitalizeFirst as g, unionBy as K, isFunction as Y } from "@aiao/utils";
3
- const U = (n) => {
4
- const e = N(n), t = !!n.nullable;
5
- let r = !0;
6
- !t && Object.hasOwn(n, "default") && (r = !1);
7
- const s = {
1
+ import { PropertyType as u, RelationKind as h, getEntityMetadata as k, getEntityMetadataOptions as C, transitionMetadata as b, ENTITY_METADATA_MAP as j } from "@aiao/rxdb";
2
+ import { isNil as v, omit as F, isObject as B, isArray as K, capitalizeFirst as g, unionBy as Y, isFunction as U } from "@aiao/utils";
3
+ const G = (s) => {
4
+ const e = N(s), t = !!s.nullable;
5
+ let n = !0;
6
+ !t && Object.hasOwn(s, "default") && (n = !1);
7
+ const r = {
8
8
  type: e,
9
- name: n.name,
9
+ name: s.name,
10
10
  hasQuestionToken: t,
11
- hasExclamationToken: r,
12
- isReadonly: n.readonly
11
+ hasExclamationToken: n,
12
+ isReadonly: s.readonly
13
13
  };
14
- return j(n.default) || (s.initializer = G(n)), s;
15
- }, N = (n) => {
14
+ return v(s.default) || (r.initializer = J(s)), r;
15
+ }, N = (s) => {
16
16
  let e = "any";
17
- switch (n.type) {
17
+ switch (s.type) {
18
18
  case u.uuid:
19
19
  e = "UUID";
20
20
  break;
@@ -31,64 +31,64 @@ const U = (n) => {
31
31
  e = "Date";
32
32
  break;
33
33
  }
34
- return n.nullable && (e += " | null"), e;
35
- }, G = (n) => {
36
- switch (n.type) {
34
+ return s.nullable && (e += " | null"), e;
35
+ }, J = (s) => {
36
+ switch (s.type) {
37
37
  case u.string:
38
- return `'${String(n.default)}'`;
38
+ return `'${String(s.default)}'`;
39
39
  case u.date:
40
- if (n.default)
40
+ if (s.default)
41
41
  return "new Date()";
42
42
  break;
43
43
  }
44
44
  return "";
45
- }, D = (n, e = /* @__PURE__ */ new Set()) => {
46
- if (F(n))
47
- for (const t in n)
48
- e.add(t), Object.prototype.hasOwnProperty.call(n, t) && D(Reflect.get(n, t), e);
49
- else if (B(n))
50
- for (const t of n)
51
- D(t, e);
45
+ }, _ = (s, e = /* @__PURE__ */ new Set()) => {
46
+ if (B(s))
47
+ for (const t in s)
48
+ e.add(t), Object.prototype.hasOwnProperty.call(s, t) && _(Reflect.get(s, t), e);
49
+ else if (K(s))
50
+ for (const t of s)
51
+ _(t, e);
52
52
  return e;
53
53
  }, x = /* @__PURE__ */ new Map();
54
- Object.keys(u).forEach((n) => {
55
- const e = u[n];
56
- x.set(e, n);
54
+ Object.keys(u).forEach((s) => {
55
+ const e = u[s];
56
+ x.set(e, s);
57
57
  });
58
58
  const I = /* @__PURE__ */ new Map();
59
- Object.keys(h).forEach((n) => {
60
- const e = h[n];
61
- I.set(e, n);
59
+ Object.keys(h).forEach((s) => {
60
+ const e = h[s];
61
+ I.set(e, s);
62
62
  });
63
- function J(n) {
64
- const e = v(n, ["propertyMap", "relationMap", "indexMap"]), t = D(e);
65
- let r = JSON.stringify(e, null, 2);
66
- return new Set(n.properties.map((i) => i.type)).forEach((i) => {
63
+ function Q(s) {
64
+ const e = F(s, ["propertyMap", "relationMap", "indexMap"]), t = _(e);
65
+ let n = JSON.stringify(e, null, 2);
66
+ return new Set(s.properties.map((i) => i.type)).forEach((i) => {
67
67
  const o = x.get(i);
68
- r = r.replaceAll(`"type": "${i}"`, `"type": PropertyType.${o}`);
69
- }), n.relations && new Set(n.relations.map((o) => o.kind)).forEach((o) => {
68
+ n = n.replaceAll(`"type": "${i}"`, `"type": PropertyType.${o}`);
69
+ }), s.relations && new Set(s.relations.map((o) => o.kind)).forEach((o) => {
70
70
  const a = I.get(o);
71
- r = r.replaceAll(`"kind": "${o}"`, `"kind": RelationKind.${a}`);
71
+ n = n.replaceAll(`"kind": "${o}"`, `"kind": RelationKind.${a}`);
72
72
  }), t.forEach((i) => {
73
- i.includes("-") || i.includes(" ") || (r = r.replaceAll(`"${i}":`, `${i}:`));
74
- }), r;
73
+ i.includes("-") || i.includes(" ") || (n = n.replaceAll(`"${i}":`, `${i}:`));
74
+ }), n;
75
75
  }
76
- const Q = ({
77
- classProperties: n,
76
+ const L = ({
77
+ classProperties: s,
78
78
  metadata: e,
79
79
  file: t,
80
- rxdbNamedImports: r
80
+ rxdbNamedImports: n
81
81
  }) => {
82
- const { name: s } = e, i = t.addInterface({
83
- name: `${s}InitData`,
82
+ const { name: r } = e, i = t.addInterface({
83
+ name: `${r}InitData`,
84
84
  isExported: !0,
85
85
  docs: ["初始化数据"]
86
86
  });
87
87
  Array.from(e.properties.values()).forEach((o) => {
88
- const a = U(o), { initializer: c, ...l } = a, d = [];
88
+ const a = G(o), { initializer: c, ...l } = a, d = [];
89
89
  switch (d.push(o.displayName || o.name), c && d.push(`@default ${c}`), a.type) {
90
90
  case "UUID":
91
- r.add("UUID");
91
+ n.add("UUID");
92
92
  break;
93
93
  }
94
94
  i.addProperty({
@@ -96,15 +96,15 @@ const Q = ({
96
96
  type: a.type,
97
97
  hasQuestionToken: !0,
98
98
  docs: d
99
- }), n.push({
99
+ }), s.push({
100
100
  ...l,
101
101
  hasExclamationToken: !1,
102
102
  docs: d
103
103
  });
104
104
  });
105
- }, S = (n) => {
105
+ }, S = (s) => {
106
106
  let e = "UUID";
107
- switch (n.propertyMap.get("id").type) {
107
+ switch (s.propertyMap.get("id").type) {
108
108
  case u.uuid:
109
109
  e = "UUID";
110
110
  break;
@@ -116,14 +116,14 @@ const Q = ({
116
116
  break;
117
117
  }
118
118
  return e;
119
- }, L = ({
120
- classProperties: n,
119
+ }, H = ({
120
+ classProperties: s,
121
121
  metadata: e,
122
122
  rxdbNamedImports: t,
123
- generator: r
123
+ generator: n
124
124
  }) => {
125
- Array.from(e.relationMap.values()).forEach((s) => {
126
- switch (s.kind) {
125
+ Array.from(e.relationMap.values()).forEach((r) => {
126
+ switch (r.kind) {
127
127
  // 处理一对一和多对一关系
128
128
  // 这两种关系需要生成:
129
129
  // 1. 关系可观察对象属性(name$)- 用于访问关联实体
@@ -131,22 +131,22 @@ const Q = ({
131
131
  case h.ONE_TO_ONE:
132
132
  case h.MANY_TO_ONE:
133
133
  {
134
- const i = s.nullable ? `RelationEntityObservable<${s.mappedEntity} | null>` : `RelationEntityObservable<${s.mappedEntity}>`, o = s.displayName || s.name;
135
- n.push({
136
- name: s.name + "$",
134
+ const i = r.nullable ? `RelationEntityObservable<${r.mappedEntity} | null>` : `RelationEntityObservable<${r.mappedEntity}>`, o = r.displayName || r.name;
135
+ s.push({
136
+ name: r.name + "$",
137
137
  // 关系属性名使用$后缀,表示可观察对象
138
138
  type: i,
139
139
  isReadonly: !0,
140
140
  // 关系属性是只读的,通过set/remove方法修改
141
141
  docs: [o]
142
142
  });
143
- const a = r.getMetadata(s.mappedEntity, s.mappedNamespace), c = S(a);
144
- n.push({
145
- name: s.name + "Id",
143
+ const a = n.getMetadata(r.mappedEntity, r.mappedNamespace), c = S(a);
144
+ s.push({
145
+ name: r.name + "Id",
146
146
  // 外键ID属性
147
147
  type: c,
148
148
  isReadonly: !0,
149
- hasQuestionToken: s.nullable,
149
+ hasQuestionToken: r.nullable,
150
150
  docs: [o + " id"]
151
151
  }), t.add("RelationEntityObservable");
152
152
  }
@@ -157,9 +157,9 @@ const Q = ({
157
157
  case h.ONE_TO_MANY:
158
158
  case h.MANY_TO_MANY:
159
159
  {
160
- const i = s.displayName || s.name, o = `RelationEntitiesObservable<${s.mappedEntity}>`;
161
- n.push({
162
- name: s.name + "$",
160
+ const i = r.displayName || r.name, o = `RelationEntitiesObservable<${r.mappedEntity}>`;
161
+ s.push({
162
+ name: r.name + "$",
163
163
  // 关系集合属性名使用$后缀
164
164
  isReadonly: !0,
165
165
  // 关系属性是只读的,通过add/remove方法修改
@@ -170,54 +170,54 @@ const Q = ({
170
170
  break;
171
171
  }
172
172
  });
173
- }, H = (n) => {
173
+ }, V = (s) => {
174
174
  const e = [];
175
- return Array.from(n.propertyMap.keys()).forEach((t) => {
176
- const r = n.propertyMap.get(t);
177
- let s = "";
178
- switch (r.type) {
175
+ return Array.from(s.propertyMap.keys()).forEach((t) => {
176
+ const n = s.propertyMap.get(t);
177
+ let r = "";
178
+ switch (n.type) {
179
179
  case u.uuid:
180
- s = "UUID";
180
+ r = "UUID";
181
181
  break;
182
182
  case u.string:
183
- s = "String";
183
+ r = "String";
184
184
  break;
185
185
  case u.number:
186
186
  case u.integer:
187
- s = "Number";
187
+ r = "Number";
188
188
  break;
189
189
  case u.boolean:
190
- s = "Boolean";
190
+ r = "Boolean";
191
191
  break;
192
192
  case u.date:
193
- s = "Date";
193
+ r = "Date";
194
194
  break;
195
195
  }
196
- if (s) {
197
- s += "Rules";
198
- const i = N(r);
196
+ if (r) {
197
+ r += "Rules";
198
+ const i = N(n);
199
199
  e.push({
200
- rule: s,
201
- entity: n.name,
200
+ rule: r,
201
+ entity: s.name,
202
202
  key: t,
203
203
  valueType: i
204
204
  });
205
205
  }
206
206
  }), e;
207
- }, _ = (n, e, t, r = [], s = [], i = []) => (t = t ?? e, H(e).forEach(({ rule: o, entity: a, key: c, valueType: l }) => {
208
- i.length > 0 ? c = i.map((d) => d.key).join(".") + "." + c : l = void 0, s.push({
207
+ }, D = (s, e, t, n = [], r = [], i = []) => (t = t ?? e, V(e).forEach(({ rule: o, entity: a, key: c, valueType: l }) => {
208
+ i.length > 0 ? c = i.map((d) => d.key).join(".") + "." + c : l = void 0, r.push({
209
209
  rule: o,
210
210
  entity: a,
211
211
  key: c,
212
212
  valueType: l
213
213
  });
214
214
  }), e.foreignKeyNames.forEach((o) => {
215
- s.push({
215
+ r.push({
216
216
  rule: "UUIDRules",
217
217
  entity: e.name,
218
218
  key: o
219
219
  });
220
- }), Array.from(e.relationMap.keys()).filter((o) => !r.includes(o)).forEach((o) => {
220
+ }), Array.from(e.relationMap.keys()).filter((o) => !n.includes(o)).forEach((o) => {
221
221
  const a = e.relationMap.get(o);
222
222
  if (!a)
223
223
  throw new Error("relation is empty");
@@ -234,31 +234,31 @@ const Q = ({
234
234
  c.push(a.mappedProperty);
235
235
  break;
236
236
  }
237
- const l = n.getMetadata(a.mappedEntity, a.mappedNamespace);
237
+ const l = s.getMetadata(a.mappedEntity, a.mappedNamespace);
238
238
  if (!l)
239
239
  throw new Error(`generator_entity_rules: metadata "${a.mappedEntity}" not found`);
240
240
  if (i.find(($) => $.entity === e.name) || i.length && l === t) return;
241
241
  const y = [...i, { key: o, entity: e.name }];
242
- i.length < n.config.relationQueryDeep && _(n, l, t, c, s, y);
243
- }), s), M = (n, e) => n.map(({ rule: t, entity: r, key: s, valueType: i }) => (e.add(t), i ? s.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${s}', ${i}>`) : `${t}<${r}, '${s}', ${i}>` : s.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${s}'>`) : `${t}<${r}, '${s}'>`)), V = ({
244
- classMethods: n,
242
+ i.length < s.config.relationQueryDeep && D(s, l, t, c, r, y);
243
+ }), r), M = (s, e) => s.map(({ rule: t, entity: n, key: r, valueType: i }) => (e.add(t), i ? r.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${r}', ${i}>`) : `${t}<${n}, '${r}', ${i}>` : r.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${r}'>`) : `${t}<${n}, '${r}'>`)), z = ({
244
+ classMethods: s,
245
245
  rxdbNamedImports: e,
246
246
  generator: t,
247
- metadata: r,
248
- file: s,
247
+ metadata: n,
248
+ file: r,
249
249
  staticTypesInterface: i,
250
250
  idType: o
251
251
  }) => {
252
- const { name: a } = r, c = _(t, r), l = M(c, e), d = `
252
+ const { name: a } = n, c = D(t, n), l = M(c, e), d = `
253
253
  |` + c.map((f) => `'${f.key}'`).join(`
254
254
  |`);
255
- s.addTypeAlias({
255
+ r.addTypeAlias({
256
256
  name: `${a}Rule`,
257
257
  type: Array.from(new Set(l)).join(`
258
258
  | `),
259
259
  hasDeclareKeyword: !0,
260
260
  docs: ["rule"]
261
- }), s.addTypeAlias({
261
+ }), r.addTypeAlias({
262
262
  name: `${a}RuleGroup`,
263
263
  type: `RuleGroupCustom<typeof ${a}, ${d},
264
264
  ${a}Rule>`,
@@ -266,8 +266,8 @@ ${a}Rule>`,
266
266
  docs: ["RuleGroupCustom"],
267
267
  isExported: !0
268
268
  });
269
- const y = `${a}OrderByField`, $ = Array.from(r.propertyMap.keys());
270
- s.addTypeAlias({
269
+ const y = `${a}OrderByField`, $ = Array.from(n.propertyMap.keys());
270
+ r.addTypeAlias({
271
271
  name: y,
272
272
  type: $.map((f) => `"${f}"`).join(" | "),
273
273
  hasDeclareKeyword: !0,
@@ -279,7 +279,7 @@ ${a}Rule>`,
279
279
  returnType: E,
280
280
  metHodDoc: P
281
281
  }) => {
282
- n.push({
282
+ s.push({
283
283
  name: f,
284
284
  returnType: `Observable<${E}>`,
285
285
  docs: [P || `${f} 查询`, "@param options 查询选项"],
@@ -294,7 +294,9 @@ ${a}Rule>`,
294
294
  name: `${f}Options`,
295
295
  type: T,
296
296
  docs: ["查询选项"]
297
- }), e.add(g(`${f}Options`));
297
+ });
298
+ const A = g(`${f}Options`);
299
+ T.includes(A) && e.add(g(`${f}Options`));
298
300
  };
299
301
  p({
300
302
  method: "get",
@@ -321,37 +323,37 @@ ${a}Rule>`,
321
323
  method: "count",
322
324
  options: `${g("count")}Options<typeof ${a},${a}RuleGroup>`,
323
325
  returnType: "number"
324
- }), n.push({
326
+ }), s.push({
325
327
  name: "save",
326
328
  returnType: `Promise<${a}>`,
327
329
  docs: ["保存"]
328
- }), n.push({
330
+ }), s.push({
329
331
  name: "remove",
330
332
  returnType: `Promise<${a}>`,
331
333
  docs: ["删除"]
332
- }), n.push({
334
+ }), s.push({
333
335
  name: "reset",
334
336
  returnType: "void",
335
337
  docs: ["重置数据"]
336
338
  });
337
- }, z = ({
338
- metadata: n,
339
+ }, q = ({
340
+ metadata: s,
339
341
  classMethods: e,
340
342
  rxdbNamedImports: t,
341
- generator: r,
342
- file: s,
343
+ generator: n,
344
+ file: r,
343
345
  staticTypesInterface: i
344
346
  }) => {
345
- const { name: o } = n, a = _(r, n).filter(
347
+ const { name: o } = s, a = D(n, s).filter(
346
348
  (p) => p.key.startsWith("children.") && p.key !== "children.id"
347
349
  ), c = M(a, t), l = a.map((p) => `'${p.key}'`).join(" | ");
348
- s.addTypeAlias({
350
+ r.addTypeAlias({
349
351
  name: `${o}TreeRule`,
350
352
  type: Array.from(new Set(c)).join(`
351
353
  | `),
352
354
  hasDeclareKeyword: !0,
353
355
  docs: ["TreeRule"]
354
- }), s.addTypeAlias({
356
+ }), r.addTypeAlias({
355
357
  name: `${o}TreeRuleGroup`,
356
358
  type: `RuleGroupCustom<typeof ${o}, ${l}, ${o}TreeRule>`,
357
359
  hasDeclareKeyword: !0,
@@ -423,11 +425,11 @@ ${a}Rule>`,
423
425
  returnType: "number",
424
426
  metHodDoc: "查询祖先实体数量"
425
427
  });
426
- }, q = (n, e, t) => {
427
- const r = /* @__PURE__ */ new Set(), { name: s } = e, i = e.extends[0] || "", o = ["IEntityStaticType"];
428
- i.includes("TreeAdjacencyListEntityBase") ? o.push("ITreeEntity") : i.includes("EntityBase") && o.push("IEntity"), r.add(i);
428
+ }, W = (s, e, t) => {
429
+ const n = /* @__PURE__ */ new Set(), { name: r } = e, i = e.extends[0] || "", o = ["IEntityStaticType"];
430
+ i.includes("TreeAdjacencyListEntityBase") ? o.push("ITreeEntity") : i.includes("EntityBase") && o.push("IEntity"), n.add(i);
429
431
  const a = t.addClass({
430
- name: s,
432
+ name: r,
431
433
  isExported: !0,
432
434
  extends: i,
433
435
  implements: o.sort(),
@@ -437,12 +439,12 @@ ${a}Rule>`,
437
439
  a.addJsDoc(`${e.displayName}`);
438
440
  const c = [];
439
441
  c.push({
440
- type: `${s}StaticTypes`,
442
+ type: `${r}StaticTypes`,
441
443
  name: "[ENTITY_STATIC_TYPES]",
442
444
  isStatic: !1
443
- }), r.add("ENTITY_STATIC_TYPES");
445
+ }), n.add("ENTITY_STATIC_TYPES");
444
446
  const l = t.addInterface({
445
- name: `${s}StaticTypes`,
447
+ name: `${r}StaticTypes`,
446
448
  docs: ["静态类型"],
447
449
  isExported: !0
448
450
  }), d = S(e);
@@ -452,30 +454,30 @@ ${a}Rule>`,
452
454
  docs: ["id 类型"]
453
455
  });
454
456
  const y = [];
455
- Q({
457
+ L({
456
458
  classProperties: c,
457
459
  file: t,
458
460
  metadata: e,
459
- rxdbNamedImports: r
460
- }), L({
461
+ rxdbNamedImports: n
462
+ }), H({
461
463
  classProperties: c,
462
464
  metadata: e,
463
- rxdbNamedImports: r,
464
- generator: n
465
- }), V({
465
+ rxdbNamedImports: n,
466
+ generator: s
467
+ }), z({
466
468
  classMethods: y,
467
469
  file: t,
468
- generator: n,
470
+ generator: s,
469
471
  metadata: e,
470
- rxdbNamedImports: r,
472
+ rxdbNamedImports: n,
471
473
  staticTypesInterface: l,
472
474
  idType: d
473
- }), e.repository === "TreeRepository" && z({
475
+ }), e.repository === "TreeRepository" && q({
474
476
  classMethods: y,
475
477
  metadata: e,
476
478
  file: t,
477
- generator: n,
478
- rxdbNamedImports: r,
479
+ generator: s,
480
+ rxdbNamedImports: n,
479
481
  staticTypesInterface: l
480
482
  }), a.addProperties(
481
483
  c.sort((p, m) => p.isReadonly && !m.isReadonly ? -1 : !p.isReadonly && m.isReadonly ? 1 : p.name.localeCompare(m.name))
@@ -483,25 +485,25 @@ ${a}Rule>`,
483
485
  parameters: [
484
486
  {
485
487
  name: "initData",
486
- type: `${s}InitData`,
488
+ type: `${r}InitData`,
487
489
  hasQuestionToken: !0
488
490
  }
489
491
  ],
490
492
  docs: ["初始化数据", "@param initData 初始化数据"]
491
493
  });
492
- const $ = K(y, (p) => p.name).sort(
494
+ const $ = Y(y, (p) => p.name).sort(
493
495
  (p, m) => p.isStatic && !m.isStatic ? -1 : !p.isStatic && m.isStatic ? 1 : p.name.localeCompare(m.name)
494
496
  );
495
497
  return a.addMethods($), {
496
- rxdbNamedImports: r
498
+ rxdbNamedImports: n
497
499
  };
498
500
  };
499
- var w = /* @__PURE__ */ ((n) => (n.Var = "var", n.Let = "let", n.Const = "const", n))(w || {});
500
- class W {
501
+ var w = /* @__PURE__ */ ((s) => (s.Var = "var", s.Let = "let", s.Const = "const", s))(w || {});
502
+ class X {
501
503
  files = /* @__PURE__ */ new Map();
502
504
  createSourceFile(e, t) {
503
- const r = new O(e);
504
- return t && r.setContent(t), this.files.set(e, r), r;
505
+ const n = new O(e);
506
+ return t && n.setContent(t), this.files.set(e, n), n;
505
507
  }
506
508
  addSourceFileAtPath(e) {
507
509
  const t = new O(e);
@@ -524,21 +526,21 @@ class O {
524
526
  this.filePath = e;
525
527
  }
526
528
  addClass(e) {
527
- const t = new Z(e);
529
+ const t = new ee(e);
528
530
  return this.classes.push(t), t;
529
531
  }
530
532
  addInterface(e) {
531
- let t = this.interfaces.find((r) => r.name === e.name);
532
- return t || (t = new X(e), this.interfaces.push(t)), t;
533
+ let t = this.interfaces.find((n) => n.name === e.name);
534
+ return t || (t = new Z(e), this.interfaces.push(t)), t;
533
535
  }
534
536
  addModule(e) {
535
537
  return this.modules.push(e), {
536
538
  addInterface: (t) => {
537
- const r = this.modules[this.modules.length - 1];
538
- return r.interfaces || (r.interfaces = []), r.interfaces.push(t), {
539
- addProperty: (s) => {
539
+ const n = this.modules[this.modules.length - 1];
540
+ return n.interfaces || (n.interfaces = []), n.interfaces.push(t), {
541
+ addProperty: (r) => {
540
542
  const i = this.modules[this.modules.length - 1], o = i.interfaces[i.interfaces.length - 1];
541
- o.properties || (o.properties = []), o.properties.push(s);
543
+ o.properties || (o.properties = []), o.properties.push(r);
542
544
  }
543
545
  };
544
546
  }
@@ -573,8 +575,8 @@ class O {
573
575
  `;
574
576
  }), this.modules.forEach((t) => {
575
577
  t.docs && t.docs.length > 0 && (e += this.renderJsDoc(t.docs, 0)), t.hasDeclareKeyword && (e += "declare "), e += `module ${t.name} {
576
- `, t.interfaces && t.interfaces.length > 0 && t.interfaces.forEach((r) => {
577
- e += this.renderInterfaceBlock(r, 2, !1);
578
+ `, t.interfaces && t.interfaces.length > 0 && t.interfaces.forEach((n) => {
579
+ e += this.renderInterfaceBlock(n, 2, !1);
578
580
  }), e += `}
579
581
 
580
582
  `;
@@ -582,12 +584,12 @@ class O {
582
584
  e += this.renderInterfaceBlock(t, 0, !0) + `
583
585
  `;
584
586
  }), this.classes.forEach((t) => {
585
- const r = t.getName();
586
- if (r) {
587
- t.jsDoc && t.jsDoc.length > 0 ? e += this.renderJsDoc(t.jsDoc) : e += this.renderJsDoc([r]), e += `export declare class ${r}`;
588
- const s = t.getBaseClass();
589
- if (s) {
590
- const o = s.getName();
587
+ const n = t.getName();
588
+ if (n) {
589
+ t.jsDoc && t.jsDoc.length > 0 ? e += this.renderJsDoc(t.jsDoc) : e += this.renderJsDoc([n]), e += `export declare class ${n}`;
590
+ const r = t.getBaseClass();
591
+ if (r) {
592
+ const o = r.getName();
591
593
  o && (e += ` extends ${o}`);
592
594
  }
593
595
  const i = t.getImplements();
@@ -624,53 +626,53 @@ class O {
624
626
  // Helpers: rendering
625
627
  // 通用参数渲染函数
626
628
  renderParameter(e, t) {
627
- let r = "";
628
- return t > 0 && (r += ", "), r += e.name, e.hasQuestionToken && (r += "?"), e.type && (r += `: ${e.type}`), r;
629
+ let n = "";
630
+ return t > 0 && (n += ", "), n += e.name, e.hasQuestionToken && (n += "?"), e.type && (n += `: ${e.type}`), n;
629
631
  }
630
632
  // 通用参数列表渲染函数
631
633
  renderParameterList(e) {
632
- return !e || e.length === 0 ? "" : e.map((t, r) => this.renderParameter(t, r)).join("");
634
+ return !e || e.length === 0 ? "" : e.map((t, n) => this.renderParameter(t, n)).join("");
633
635
  }
634
636
  // 通用变量声明渲染函数
635
637
  renderVariableDeclaration(e, t) {
636
- let r = "";
637
- return t > 0 && (r += ", "), r += e.name, e.type && (r += `: ${e.type}`), e.initializer && (r += ` = ${e.initializer}`), r;
638
+ let n = "";
639
+ return t > 0 && (n += ", "), n += e.name, e.type && (n += `: ${e.type}`), e.initializer && (n += ` = ${e.initializer}`), n;
638
640
  }
639
641
  // 通用变量声明列表渲染函数
640
642
  renderVariableDeclarationList(e) {
641
- return !e || e.length === 0 ? "" : e.map((t, r) => this.renderVariableDeclaration(t, r)).join("");
643
+ return !e || e.length === 0 ? "" : e.map((t, n) => this.renderVariableDeclaration(t, n)).join("");
642
644
  }
643
645
  // 通用JSDoc渲染函数
644
646
  renderJsDoc(e, t = 0) {
645
647
  if (!e || e.length === 0) return "";
646
- const r = " ".repeat(t);
647
- return `${r}/**
648
- ${r} * ${e.join(`
649
- ${r} * `)}
650
- ${r} */
648
+ const n = " ".repeat(t);
649
+ return `${n}/**
650
+ ${n} * ${e.join(`
651
+ ${n} * `)}
652
+ ${n} */
651
653
  `;
652
654
  }
653
655
  // 通用属性渲染函数
654
- renderProperty(e, t, r = !0) {
655
- let s = "";
656
- return e.docs && e.docs.length > 0 && (s += this.renderJsDoc(e.docs, t)), s += " ".repeat(t), e.isStatic && (s += "static "), s += e.name, e.hasQuestionToken && (s += "?"), e.type && (s += `: ${e.type}`), !r && e.initializer && (s += ` = ${e.initializer}`), s += `;
657
- `, s;
656
+ renderProperty(e, t, n = !0) {
657
+ let r = "";
658
+ return e.docs && e.docs.length > 0 && (r += this.renderJsDoc(e.docs, t)), r += " ".repeat(t), e.isStatic && (r += "static "), r += e.name, e.hasQuestionToken && (r += "?"), e.type && (r += `: ${e.type}`), !n && e.initializer && (r += ` = ${e.initializer}`), r += `;
659
+ `, r;
658
660
  }
659
661
  // 接口属性渲染(调用通用函数)
660
662
  renderInterfaceProperty(e, t) {
661
663
  return this.renderProperty(e, t);
662
664
  }
663
- renderInterfaceBlock(e, t, r) {
664
- const s = " ".repeat(t);
665
+ renderInterfaceBlock(e, t, n) {
666
+ const r = " ".repeat(t);
665
667
  let i = "";
666
- return e.docs && e.docs.length > 0 && (i += this.renderJsDoc(e.docs, t)), r && e.isExported ? i += `${s}export ` : i += s, i += `interface ${e.name}`, e.extends && e.extends.length > 0 && (i += ` extends ${e.extends.join(", ")}`), i += ` {
668
+ return e.docs && e.docs.length > 0 && (i += this.renderJsDoc(e.docs, t)), n && e.isExported ? i += `${r}export ` : i += r, i += `interface ${e.name}`, e.extends && e.extends.length > 0 && (i += ` extends ${e.extends.join(", ")}`), i += ` {
667
669
  `, e.properties && e.properties.length > 0 && e.properties.forEach((o) => {
668
670
  i += this.renderInterfaceProperty(o, t + 2);
669
- }), i += `${s}}
671
+ }), i += `${r}}
670
672
  `, i;
671
673
  }
672
674
  }
673
- class X {
675
+ class Z {
674
676
  name;
675
677
  extends;
676
678
  docs;
@@ -683,7 +685,7 @@ class X {
683
685
  this.properties.some((t) => t.name === e.name) || this.properties.push(e);
684
686
  }
685
687
  }
686
- class Z {
688
+ class ee {
687
689
  structure;
688
690
  decorators = [];
689
691
  properties = [];
@@ -735,8 +737,8 @@ class Z {
735
737
  return this.structure.name || "";
736
738
  }
737
739
  }
738
- const ee = (n) => {
739
- const { project: e, metadataSet: t } = n, r = e.createSourceFile("index.d.ts"), i = r.addModule({
740
+ const te = (s) => {
741
+ const { project: e, metadataSet: t } = s, n = e.createSourceFile("index.d.ts"), i = n.addModule({
740
742
  name: '"@aiao/rxdb"',
741
743
  hasDeclareKeyword: !0,
742
744
  docs: ["rxdb"]
@@ -744,14 +746,15 @@ const ee = (n) => {
744
746
  name: "RxDB",
745
747
  docs: ["RxDB"]
746
748
  }), o = /* @__PURE__ */ new Set([
747
- "UUID",
748
749
  "EntityType",
749
- "RuleGroupCustom",
750
+ "IEntity",
750
751
  "IEntityStaticType",
751
- "ITreeEntity"
752
+ "ITreeEntity",
753
+ "RuleGroupCustom",
754
+ "UUID"
752
755
  ]);
753
756
  t.forEach((a) => {
754
- const { rxdbNamedImports: c } = q(n, a, r);
757
+ const { rxdbNamedImports: c } = W(s, a, n);
755
758
  c.forEach((y) => o.add(y));
756
759
  const { name: l } = a, d = l;
757
760
  a.namespace && a.namespace !== "public" ? i.addProperty({
@@ -765,15 +768,15 @@ ${d}: typeof ${d};
765
768
  type: `typeof ${d}`,
766
769
  docs: [a.displayName]
767
770
  });
768
- }), r.addImportDeclaration({
771
+ }), n.addImportDeclaration({
769
772
  namedImports: Array.from(o).filter(Boolean).sort(),
770
773
  isTypeOnly: !0,
771
774
  moduleSpecifier: "@aiao/rxdb"
772
- }), r.addImportDeclaration({
775
+ }), n.addImportDeclaration({
773
776
  namedImports: ["Observable"],
774
777
  isTypeOnly: !0,
775
778
  moduleSpecifier: "rxjs"
776
- }), r.addVariableStatement({
779
+ }), n.addVariableStatement({
777
780
  declarationKind: w.Const,
778
781
  hasDeclareKeyword: !0,
779
782
  isExported: !0,
@@ -784,10 +787,10 @@ ${d}: typeof ${d};
784
787
  }
785
788
  ]
786
789
  });
787
- }, te = (n) => {
788
- const { project: e, metadataSet: t } = n;
789
- let r = "";
790
- const s = /* @__PURE__ */ new Set(["Entity", "__decorateClass"]), i = (a) => {
790
+ }, ne = (s) => {
791
+ const { project: e, metadataSet: t } = s;
792
+ let n = "";
793
+ const r = /* @__PURE__ */ new Set(["Entity", "__decorateClass"]), i = (a) => {
791
794
  for (const c of t.values())
792
795
  if (c.relations && c.namespace === a.mappedNamespace && c.name === a.mappedEntity)
793
796
  return c.relations.find((l) => l.kind === h.MANY_TO_MANY && l.mappedProperty === a.name);
@@ -798,22 +801,22 @@ ${d}: typeof ${d};
798
801
  throw new Error("mapped relation not found");
799
802
  });
800
803
  }), t.forEach((a) => {
801
- const c = a.extends[0], { name: l } = a, d = l, y = J(a);
802
- c && s.add(c), a.properties.length && s.add("PropertyType"), a.relations.length && s.add("RelationKind"), r += `
803
- let ${d} = class ${c ? "extends " + c : ""} {};`, r += `
804
+ const c = a.extends[0], { name: l } = a, d = l, y = Q(a);
805
+ c && r.add(c), a.properties.length && r.add("PropertyType"), a.relations.length && r.add("RelationKind"), n += `
806
+ let ${d} = class ${c ? "extends " + c : ""} {};`, n += `
804
807
  ${d} = __decorateClass(
805
808
  [
806
809
  Entity(${y})
807
810
  ],
808
811
  ${d}
809
812
  );`;
810
- }), r = `import { ${Array.from(s).sort().join(", ")} } from '@aiao/rxdb';` + r;
813
+ }), n = `import { ${Array.from(r).sort().join(", ")} } from '@aiao/rxdb';` + n;
811
814
  const o = Array.from(t.values()).map((a) => a.name).sort().join(", ");
812
- r += `
813
- const ENTITIES = [ ${o} ];`, r += `
814
- export { ENTITIES, ${o} };`, e.createSourceFile("index.js", r);
815
- }, R = (n, e = "public") => `${e}_${n}`;
816
- class ne {
815
+ n += `
816
+ const ENTITIES = [ ${o} ];`, n += `
817
+ export { ENTITIES, ${o} };`, e.createSourceFile("index.js", n);
818
+ }, R = (s, e = "public") => `${e}_${s}`;
819
+ class oe {
817
820
  metadataMap = /* @__PURE__ */ new Map();
818
821
  project;
819
822
  metadataSet = /* @__PURE__ */ new Set();
@@ -828,14 +831,14 @@ class ne {
828
831
  * @param value 实体
829
832
  */
830
833
  addEntity(e, t) {
831
- let r;
832
- if (Y(e))
833
- r = A(e);
834
+ let n;
835
+ if (U(e))
836
+ n = k(e);
834
837
  else {
835
- const s = e;
836
- t = t || s.extends?.length && k(s.extends[0]) || [], r = b(e, t);
838
+ const r = e;
839
+ t = t || r.extends?.length && C(r.extends[0]) || [], n = b(e, t);
837
840
  }
838
- this.metadataSet.add(r), this.metadataMap.set(`${r.namespace}_${r.name}`, r);
841
+ this.metadataSet.add(n), this.metadataMap.set(`${n.namespace}_${n.name}`, n);
839
842
  }
840
843
  getMetadata(e, t) {
841
844
  return this.metadataMap.get(R(e, t));
@@ -844,17 +847,17 @@ class ne {
844
847
  * 执行生成器
845
848
  */
846
849
  exec() {
847
- this.project = new W(), Object.values(C).forEach(
850
+ this.project = new X(), Object.values(j).forEach(
848
851
  (e) => e.forEach((t) => {
849
- const r = b(t);
850
- this.metadataMap.set(R(t.name, t.namespace), r);
852
+ const n = b(t);
853
+ this.metadataMap.set(R(t.name, t.namespace), n);
851
854
  })
852
- ), ee(this), te(this);
855
+ ), te(this), ne(this);
853
856
  }
854
857
  getSourceFiles() {
855
858
  return this.project.getSourceFiles();
856
859
  }
857
860
  }
858
861
  export {
859
- ne as R
862
+ oe as R
860
863
  };
@@ -3,7 +3,7 @@ import { resolve as b, join as E, dirname as _ } from "node:path";
3
3
  import { Project as g, Node as u } from "ts-morph";
4
4
  import { getEntityMetadataOptions as w, PropertyType as N, RelationKind as C } from "@aiao/rxdb";
5
5
  import { glob as O } from "glob";
6
- import { R as F } from "./RxDBClientGenerator-HeMQrLeK.js";
6
+ import { R as F } from "./RxDBClientGenerator-B3NS1KdI.js";
7
7
  const P = (r, s = new g()) => {
8
8
  const n = s.addSourceFileAtPath(r).getClasses(), c = /* @__PURE__ */ new Map();
9
9
  n.forEach((t) => {
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync as f } from "node:fs";
3
3
  import { resolve as c, dirname as a } from "node:path";
4
- import { b as g } from "./build_rxdb_client_lib-ClVnYEnB.js";
4
+ import { b as g } from "./build_rxdb_client_lib-D1VubBOB.js";
5
5
  async function u(s) {
6
6
  try {
7
7
  if (!f(s))
@@ -1 +1 @@
1
- {"version":3,"file":"generator_all_entity_definition.d.ts","sourceRoot":"","sources":["../src/generator_all_entity_definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAGpE;;GAEG;yBACa,WAAW,mBAAmB;AAA9C,wBAyEE"}
1
+ {"version":3,"file":"generator_all_entity_definition.d.ts","sourceRoot":"","sources":["../src/generator_all_entity_definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAGpE;;GAEG;yBACa,WAAW,mBAAmB;AAA9C,wBA0EE"}
@@ -1 +1 @@
1
- {"version":3,"file":"generator_repository_methods.d.ts","sourceRoot":"","sources":["../src/generator_repository_methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElD,OAA+B,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,0BAA0B,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAElH,eAAO,MAAM,WAAW,GAAI,aAAa,YAAY,EAAE,EAAE,kBAAkB,GAAG,CAAC,MAAM,CAAC,aAmBrF,CAAC;AAEF;;GAEG;yBACa,6FAQb;IACD,YAAY,EAAE,YAAY,CAAC,0BAA0B,CAAC,EAAE,CAAC;IACzD,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,oBAAoB,EAAE,cAAc,CAAC;IACrC,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAhBD,wBAsIE"}
1
+ {"version":3,"file":"generator_repository_methods.d.ts","sourceRoot":"","sources":["../src/generator_repository_methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElD,OAA+B,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,0BAA0B,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAElH,eAAO,MAAM,WAAW,GAAI,aAAa,YAAY,EAAE,EAAE,kBAAkB,GAAG,CAAC,MAAM,CAAC,aAmBrF,CAAC;AAEF;;GAEG;yBACa,6FAQb;IACD,YAAY,EAAE,YAAY,CAAC,0BAA0B,CAAC,EAAE,CAAC;IACzD,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,oBAAoB,EAAE,cAAc,CAAC;IACrC,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAhBD,wBA2IE"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { R as o } from "./RxDBClientGenerator-HeMQrLeK.js";
1
+ import { R as o } from "./RxDBClientGenerator-B3NS1KdI.js";
2
2
  export {
3
3
  o as RxDBClientGenerator
4
4
  };
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import { b as r } from "./build_rxdb_client_lib-ClVnYEnB.js";
1
+ import { b as r } from "./build_rxdb_client_lib-D1VubBOB.js";
2
2
  function l(t) {
3
3
  return {
4
4
  name: "rxdb-client-generator-vite-plugin",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-client-generator",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "ts-morph": "^27.0.0",
39
39
  "glob": "^10.4.5",
40
- "@aiao/rxdb": "0.0.4",
41
- "@aiao/utils": "0.0.4"
40
+ "@aiao/rxdb": "0.0.5",
41
+ "@aiao/utils": "0.0.5"
42
42
  }
43
43
  }