@aiao/rxdb-client-generator 0.0.9 → 0.0.11

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,23 +1,23 @@
1
- import { PropertyType as d, RelationKind as f, ENTITY_BASE_METADATA_OPTIONS as E, TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS as N, getEntityMetadata as B, transitionMetadata as A } from "@aiao/rxdb";
2
- import { omit as K, isObject as G, isArray as F, isNil as V, unionBy as v, capitalizeFirst as D, isFunction as U } from "@aiao/utils";
3
- const Y = (r, e) => {
4
- const t = T(r, e), s = !!r.nullable;
1
+ import { PropertyType as d, RelationKind as f, ENTITY_BASE_METADATA_OPTIONS as R, TREE_ADJACENCY_LIST_ENTITY_BASE_OPTIONS as P, getEntityMetadata as K, transitionMetadata as O } from "@aiao/rxdb";
2
+ import { omit as F, isNil as V, unionBy as v, capitalizeFirst as b, isFunction as U } from "@aiao/utils";
3
+ const J = (r, e) => {
4
+ const t = $(r, e), s = !!r.nullable;
5
5
  let a = !0;
6
6
  !s && Object.hasOwn(r, "default") && (a = !1);
7
- const o = {
7
+ const i = {
8
8
  type: t,
9
9
  name: r.name,
10
10
  hasQuestionToken: s,
11
11
  hasExclamationToken: a,
12
12
  isReadonly: r.readonly
13
13
  };
14
- return V(r.default) || (o.initializer = H(r)), o;
15
- }, R = (r, e) => `${e.name}${r.name.charAt(0).toUpperCase() + r.name.slice(1)}KeyValue`, J = (r, e) => r.type !== d.keyValue || !("properties" in r) || !r.properties || r.properties.length === 0 ? "KeyValue" : R(r, e), L = (r, e) => r.type !== d.keyValue || !("properties" in r) || !r.properties || r.properties.length === 0 ? [] : r.properties.map((t) => ({
14
+ return V(r.default) || (i.initializer = Q(r)), i;
15
+ }, M = (r, e) => `${e.name}${r.name.charAt(0).toUpperCase() + r.name.slice(1)}KeyValue`, L = (r, e) => r.type !== d.keyValue || !("properties" in r) || !r.properties || r.properties.length === 0 ? "KeyValue" : M(r, e), H = (r, e) => r.type !== d.keyValue || !("properties" in r) || !r.properties || r.properties.length === 0 ? [] : r.properties.map((t) => ({
16
16
  name: t.name,
17
- type: T(t, e),
17
+ type: $(t, e),
18
18
  hasQuestionToken: t.nullable || !1,
19
19
  docs: t.displayName ? [t.displayName] : void 0
20
- })), T = (r, e) => {
20
+ })), $ = (r, e) => {
21
21
  let t = "any";
22
22
  switch (r.type) {
23
23
  case d.uuid:
@@ -45,14 +45,14 @@ const Y = (r, e) => {
45
45
  t = "number[]";
46
46
  break;
47
47
  case d.keyValue:
48
- t = J(r, e);
48
+ t = L(r, e);
49
49
  break;
50
50
  case d.json:
51
51
  t = "Record<string, any>";
52
52
  break;
53
53
  }
54
54
  return r.nullable && (t += " | null"), t;
55
- }, H = (r) => {
55
+ }, Q = (r) => {
56
56
  switch (r.type) {
57
57
  case d.string:
58
58
  return `'${String(r.default)}'`;
@@ -62,38 +62,40 @@ const Y = (r, e) => {
62
62
  break;
63
63
  }
64
64
  return "";
65
- }, I = (r, e = /* @__PURE__ */ new Set()) => {
66
- if (G(r))
67
- for (const t in r)
68
- e.add(t), Object.prototype.hasOwnProperty.call(r, t) && I(Reflect.get(r, t), e);
69
- else if (F(r))
70
- for (const t of r)
71
- I(t, e);
65
+ }, D = (r, e = /* @__PURE__ */ new Set()) => {
66
+ if (r == null) return e;
67
+ if (typeof r == "object")
68
+ if (Array.isArray(r))
69
+ for (const t of r)
70
+ D(t, e);
71
+ else
72
+ for (const t in r)
73
+ Object.prototype.hasOwnProperty.call(r, t) && (e.add(t), D(r[t], e));
72
74
  return e;
73
75
  }, w = /* @__PURE__ */ new Map();
74
76
  Object.keys(d).forEach((r) => {
75
77
  const e = d[r];
76
- w.set(e, r);
78
+ typeof e == "string" && w.set(e, r);
77
79
  });
78
- const O = /* @__PURE__ */ new Map();
80
+ const j = /* @__PURE__ */ new Map();
79
81
  Object.keys(f).forEach((r) => {
80
82
  const e = f[r];
81
- O.set(e, r);
83
+ typeof e == "string" && j.set(e, r);
82
84
  });
83
- function Q(r) {
84
- const e = K(r, ["propertyMap", "relationMap", "indexMap"]), t = I(e);
85
+ function q(r) {
86
+ const e = F(r, ["propertyMap", "relationMap", "indexMap"]), t = D(e);
85
87
  let s = JSON.stringify(e, null, 2);
86
- return new Set(r.properties.map((o) => o.type).filter(Boolean)).forEach((o) => {
87
- const n = w.get(o);
88
- s = s.replaceAll(`"type": "${o}"`, `"type": PropertyType.${n}`);
88
+ return new Set(r.properties.map((i) => i.type).filter(Boolean)).forEach((i) => {
89
+ const n = w.get(i);
90
+ n && (s = s.replaceAll(`"type": "${i}"`, `"type": PropertyType.${n}`));
89
91
  }), r.relations && new Set(r.relations.map((n) => n.kind)).forEach((n) => {
90
- const i = O.get(n);
91
- s = s.replaceAll(`"kind": "${n}"`, `"kind": RelationKind.${i}`);
92
- }), t.forEach((o) => {
93
- o.includes("-") || o.includes(" ") || (s = s.replaceAll(`"${o}":`, `${o}:`));
92
+ const o = j.get(n);
93
+ o && (s = s.replaceAll(`"kind": "${n}"`, `"kind": RelationKind.${o}`));
94
+ }), t.forEach((i) => {
95
+ i.includes("-") || i.includes(" ") || (s = s.replaceAll(`"${i}":`, `${i}:`));
94
96
  }), s;
95
97
  }
96
- const q = ({
98
+ const z = ({
97
99
  classProperties: r,
98
100
  metadata: e,
99
101
  file: t,
@@ -103,19 +105,19 @@ const q = ({
103
105
  name: `${e.name}InitData`,
104
106
  isExported: !0,
105
107
  docs: ["初始化数据"]
106
- }), o = (n, i = !1) => {
108
+ }), i = (n, o = !1) => {
107
109
  if (n.type === d.keyValue && "properties" in n && n.properties && n.properties.length > 0) {
108
- const y = R(n, e), g = t.addInterface({
110
+ const y = M(n, e), g = t.addInterface({
109
111
  name: y,
110
112
  isExported: !0,
111
113
  docs: [n.displayName || `${n.name} keyValue 类型`]
112
114
  });
113
- L(n, e).forEach((m) => {
115
+ H(n, e).forEach((m) => {
114
116
  g.addProperty(m);
115
117
  });
116
118
  }
117
- const c = Y(n, e), { initializer: u, ...h } = c, l = [];
118
- l.push(n.displayName || n.name), u && l.push(`@default ${u}`), c.type === "UUID" && s.add("UUID"), i || a.addProperty({
119
+ const c = J(n, e), { initializer: u, ...h } = c, l = [];
120
+ l.push(n.displayName || n.name), u && l.push(`@default ${u}`), c.type === "UUID" && s.add("UUID"), o || a.addProperty({
119
121
  name: c.name,
120
122
  type: c.type,
121
123
  hasQuestionToken: !0,
@@ -127,27 +129,25 @@ const q = ({
127
129
  docs: l
128
130
  });
129
131
  };
130
- Array.from(e.properties.values()).forEach((n) => {
131
- o(n);
132
+ e.properties.forEach((n) => {
133
+ i(n);
132
134
  }), Array.from(e.computedPropertyMap.values()).forEach((n) => {
133
- let i = e.features || {};
134
- e.repository === "GraphRepository" || e.extends.includes("GraphRepository") ? i = e.features?.graph || {} : (e.repository === "TreeRepository" || e.extends.includes("TreeRepository")) && (i = e.features?.tree || {}), i[n.name] && o(n, !0);
135
+ let o = e.features || {};
136
+ e.repository === "GraphRepository" || e.extends.includes("GraphRepository") ? o = e.features?.graph || {} : (e.repository === "TreeRepository" || e.extends.includes("TreeRepository")) && (o = e.features?.tree || {}), o[n.name] && i(n, !0);
135
137
  });
136
- }, z = (r) => {
138
+ }, S = (r) => {
137
139
  const e = r.propertyMap.get("id");
138
- let t = "UUID";
139
- switch (e?.type) {
140
+ if (!e) return "UUID";
141
+ switch (e.type) {
140
142
  case d.uuid:
141
- t = "UUID";
142
- break;
143
+ return "UUID";
143
144
  case d.string:
144
- t = "string";
145
- break;
145
+ return "string";
146
146
  case d.integer:
147
- t = "number";
148
- break;
147
+ return "number";
148
+ default:
149
+ return "UUID";
149
150
  }
150
- return t;
151
151
  }, W = ({
152
152
  classProperties: r,
153
153
  metadata: e,
@@ -163,16 +163,16 @@ const q = ({
163
163
  case f.ONE_TO_ONE:
164
164
  case f.MANY_TO_ONE:
165
165
  {
166
- const o = `RelationEntityObservable<typeof ${a.mappedEntity}>`, n = a.displayName || a.name;
166
+ const i = `RelationEntityObservable<typeof ${a.mappedEntity}>`, n = a.displayName || a.name;
167
167
  r.push({
168
168
  name: a.name + "$",
169
169
  // 关系属性名使用$后缀,表示可观察对象
170
- type: o,
170
+ type: i,
171
171
  isReadonly: !0,
172
172
  // 关系属性是只读的,通过set/remove方法修改
173
173
  docs: [n]
174
174
  });
175
- const i = s.getMetadata(a.mappedEntity, a.mappedNamespace), c = z(i);
175
+ const o = s.getMetadata(a.mappedEntity, a.mappedNamespace), c = S(o);
176
176
  r.push({
177
177
  name: a.name + "Id",
178
178
  // 外键ID属性
@@ -191,31 +191,31 @@ const q = ({
191
191
  case f.ONE_TO_MANY:
192
192
  case f.MANY_TO_MANY:
193
193
  {
194
- const o = a.displayName || a.name, n = `RelationEntitiesObservable<${a.mappedEntity}>`;
194
+ const i = a.displayName || a.name, n = `RelationEntitiesObservable<${a.mappedEntity}>`;
195
195
  r.push({
196
196
  name: a.name + "$",
197
197
  // 关系集合属性名使用$后缀
198
198
  isReadonly: !0,
199
199
  // 关系属性是只读的,通过add/remove方法修改
200
200
  type: n,
201
- docs: [o]
201
+ docs: [i]
202
202
  }), t.add("RelationEntitiesObservable");
203
203
  }
204
204
  break;
205
205
  }
206
206
  });
207
207
  }, Z = (r, e, t) => {
208
- const s = /* @__PURE__ */ new Set(), { name: a } = e, o = e.extends[0] || "", n = [];
209
- o.includes("TreeAdjacencyListEntityBase") ? n.push("ITreeEntity") : o.includes("EntityBase") && n.push("IEntity"), s.add(o);
210
- const i = t.addClass({
208
+ const s = /* @__PURE__ */ new Set(), { name: a } = e, i = e.extends[0] || "", n = [];
209
+ i.includes("TreeAdjacencyListEntityBase") ? n.push("ITreeEntity") : i.includes("EntityBase") && n.push("IEntity"), s.add(i);
210
+ const o = t.addClass({
211
211
  name: a,
212
212
  isExported: !0,
213
- extends: o,
213
+ extends: i,
214
214
  implements: n.sort(),
215
215
  decorators: [],
216
216
  hasDeclareKeyword: !0
217
217
  });
218
- i.addJsDoc(`${e.displayName}`);
218
+ o.addJsDoc(`${e.displayName}`);
219
219
  const c = [];
220
220
  c.push({
221
221
  type: `${a}StaticTypes`,
@@ -227,7 +227,7 @@ const q = ({
227
227
  docs: ["静态类型"],
228
228
  isExported: !0
229
229
  }), h = [];
230
- q({
230
+ z({
231
231
  classProperties: c,
232
232
  file: t,
233
233
  metadata: e,
@@ -238,10 +238,10 @@ const q = ({
238
238
  rxdbNamedImports: s,
239
239
  generator: r
240
240
  });
241
- const l = e.repository || "Repository", y = r.getRepositoryGenerator(l);
241
+ const l = e.repository || I, y = r.getRepositoryGenerator(l);
242
242
  if (y) {
243
- if (l !== "Repository") {
244
- const p = r.getRepositoryGenerator("Repository");
243
+ if (l !== I) {
244
+ const p = r.getRepositoryGenerator(I);
245
245
  p && p.generate({
246
246
  metadata: e,
247
247
  classProperties: c,
@@ -262,9 +262,9 @@ const q = ({
262
262
  staticTypesInterface: u
263
263
  });
264
264
  }
265
- i.addProperties(
265
+ o.addProperties(
266
266
  c.sort((p, m) => p.isStatic && !m.isStatic ? -1 : !p.isStatic && m.isStatic ? 1 : p.isReadonly && !m.isReadonly ? -1 : !p.isReadonly && m.isReadonly ? 1 : p.name.localeCompare(m.name))
267
- ), i.addConstructor({
267
+ ), o.addConstructor({
268
268
  parameters: [
269
269
  {
270
270
  name: "initData",
@@ -277,7 +277,7 @@ const q = ({
277
277
  const g = v(h, (p) => p.name).sort(
278
278
  (p, m) => p.isStatic && !m.isStatic ? -1 : !p.isStatic && m.isStatic ? 1 : p.name.localeCompare(m.name)
279
279
  );
280
- return i.addMethods(g), {
280
+ return o.addMethods(g), {
281
281
  rxdbNamedImports: s
282
282
  };
283
283
  }, X = {
@@ -290,7 +290,7 @@ const q = ({
290
290
  [d.stringArray]: "StringArray",
291
291
  [d.numberArray]: "NumberArray",
292
292
  [d.keyValue]: "KeyValue"
293
- }, M = (r) => X[r] ?? null, j = (r, e, t) => {
293
+ }, A = (r) => X[r] ?? null, C = (r, e, t) => {
294
294
  const s = r.length > 0 ? r.map((a) => a.key).join(".") + "." : "";
295
295
  return t ? `${s}${e}.${t}` : `${s}${e}`;
296
296
  }, ee = (r, e, t) => {
@@ -303,41 +303,41 @@ const q = ({
303
303
  s = "number";
304
304
  break;
305
305
  case d.keyValue:
306
- s = `Partial<${R(r, e)}>`;
306
+ s = `Partial<${M(r, e)}>`;
307
307
  break;
308
308
  default:
309
- t.length > 0 && (s = T(r, e));
309
+ t.length > 0 && (s = $(r, e));
310
310
  }
311
311
  return s;
312
- }, b = (r, e, t, s, a) => ({
312
+ }, E = (r, e, t, s, a) => ({
313
313
  rule: `${r}Rules`,
314
314
  entity: e,
315
315
  key: t,
316
316
  valueType: s,
317
317
  subRuleGroup: a
318
318
  }), te = (r, e, t, s, a) => {
319
- r.type !== d.keyValue || !("properties" in r) || !r.properties || r.properties.forEach((o) => {
320
- const n = M(o.type);
319
+ r.type !== d.keyValue || !("properties" in r) || !r.properties || r.properties.forEach((i) => {
320
+ const n = A(i.type);
321
321
  if (!n) return;
322
- const i = j(t, s, o.name), c = T(o, e);
323
- a.push(b(n, e.name, i, c));
322
+ const o = C(t, s, i.name), c = $(i, e);
323
+ a.push(E(n, e.name, o, c));
324
324
  });
325
325
  }, se = (r, e = []) => {
326
326
  const t = [];
327
327
  return Array.from(r.propertyMap.keys()).forEach((s) => {
328
- const a = r.propertyMap.get(s), o = M(a.type);
329
- if (o) {
330
- const n = ee(a, r, e), i = j(e, s);
331
- t.push(b(o, r.name, i, n));
328
+ const a = r.propertyMap.get(s), i = A(a.type);
329
+ if (i) {
330
+ const n = ee(a, r, e), o = C(e, s);
331
+ t.push(E(i, r.name, o, n));
332
332
  }
333
333
  te(a, r, e, s, t);
334
334
  }), t;
335
335
  }, re = (r, e, t) => {
336
336
  e.foreignKeyNames.forEach((s) => {
337
- const a = s.replace(/Id$/, ""), o = e.foreignKeyRelationMap.get(a);
338
- if (!o) return;
339
- const i = r.getMetadata(o.mappedEntity, o.mappedNamespace)?.propertyMap.get("id")?.type, c = i && M(i) || "UUID";
340
- t.push(b(c, e.name, s));
337
+ const a = e.foreignKeyRelationMap.get(s);
338
+ if (!a) return;
339
+ const n = r.getMetadata(a.mappedEntity, a.mappedNamespace)?.propertyMap.get("id")?.type, o = n && A(n) || "UUID";
340
+ t.push(E(o, e.name, s));
341
341
  });
342
342
  }, ne = (r) => {
343
343
  switch (r.kind) {
@@ -347,26 +347,26 @@ const q = ({
347
347
  default:
348
348
  return [];
349
349
  }
350
- }, oe = (r, e, t, s) => !!(r.some((o) => o.entity === s.name) || r.length > 0 && e === t), ie = (r, e, t, s, a, o) => {
350
+ }, oe = (r, e, t, s) => !!(r.some((i) => i.entity === s.name) || r.length > 0 && e === t), ie = (r, e, t, s, a, i) => {
351
351
  Array.from(e.relationMap.keys()).filter((n) => !s.includes(n)).forEach((n) => {
352
- const i = e.relationMap.get(n);
353
- if (!i)
352
+ const o = e.relationMap.get(n);
353
+ if (!o)
354
354
  throw new Error("relation is empty");
355
- const c = r.getMetadata(i.mappedEntity, i.mappedNamespace);
355
+ const c = r.getMetadata(o.mappedEntity, o.mappedNamespace);
356
356
  if (!c)
357
- throw new Error(`generator_entity_rules: metadata "${i.mappedEntity}" not found`);
358
- if (oe(o, c, t, e))
357
+ throw new Error(`generator_entity_rules: metadata "${o.mappedEntity}" not found`);
358
+ if (oe(i, c, t, e))
359
359
  return;
360
- if (o.length === 0) {
360
+ if (i.length === 0) {
361
361
  const l = `${c.name}RuleGroup`;
362
- a.push(b("RelationExists", e.name, n, void 0, l));
362
+ a.push(E("RelationExists", e.name, n, void 0, l));
363
363
  }
364
- if (o.length >= r.config.relationQueryDeep)
364
+ if (i.length >= r.config.relationQueryDeep)
365
365
  return;
366
- const u = ne(i), h = [...o, { key: n, entity: e.name }];
367
- S(r, c, t, u, a, h);
366
+ const u = ne(o), h = [...i, { key: n, entity: e.name }];
367
+ N(r, c, t, u, a, h);
368
368
  });
369
- }, S = (r, e, t, s = [], a = [], o = []) => (t = t ?? e, a.push(...se(e, o)), re(r, e, a), ie(r, e, t, s, a, o), a), _ = (r, e) => r.map(({ rule: t, entity: s, key: a, valueType: o, subRuleGroup: n }) => (e.add(t), n ? `${t}<'${a}', ${n}>` : o ? a.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${a}', ${o}>`) : `${t}<${s}, '${a}', ${o}>` : a.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${a}'>`) : `${t}<${s}, '${a}'>`));
369
+ }, N = (r, e, t, s = [], a = [], i = []) => (t = t ?? e, a.push(...se(e, i)), re(r, e, a), ie(r, e, t, s, a, i), a), k = (r, e) => r.map(({ rule: t, entity: s, key: a, valueType: i, subRuleGroup: n }) => (e.add(t), n ? `${t}<'${a}', ${n}>` : i ? a.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${a}', ${i}>`) : `${t}<${s}, '${a}', ${i}>` : a.includes(".") ? (e.add(`Relation${t}`), `Relation${t}<'${a}'>`) : `${t}<${s}, '${a}'>`));
370
370
  class ae {
371
371
  generate(e) {
372
372
  this.generateProperties(e), this.generateMethods(e);
@@ -394,7 +394,7 @@ class ae {
394
394
  * 共享工具:添加静态查询方法
395
395
  */
396
396
  addStaticMethod(e, t) {
397
- const { classMethods: s, staticTypesInterface: a, rxdbNamedImports: o } = e, n = [t.metHodDoc || `${t.method} 查询`, "@param options 查询选项"];
397
+ const { classMethods: s, staticTypesInterface: a, rxdbNamedImports: i } = e, n = [t.metHodDoc || `${t.method} 查询`, "@param options 查询选项"];
398
398
  t.example && n.push("@example", t.example), s.push({
399
399
  name: t.method,
400
400
  returnType: `Observable<${t.returnType}>`,
@@ -412,9 +412,9 @@ class ae {
412
412
  type: t.options,
413
413
  docs: ["查询选项"]
414
414
  });
415
- const i = t.options.match(/\b([A-Z]\w+Options)\b/g);
416
- i && i.forEach((c) => {
417
- !/^[a-z]/.test(c) && c.match(/^(Find|Count|Get)/) && o.add(c);
415
+ const o = t.options.match(/\b([A-Z]\w+Options)\b/g);
416
+ o && o.forEach((c) => {
417
+ !/^[a-z]/.test(c) && c.match(/^(Find|Count|Get)/) && i.add(c);
418
418
  });
419
419
  }
420
420
  /**
@@ -431,22 +431,19 @@ class ae {
431
431
  * 共享工具:获取 ID 类型
432
432
  */
433
433
  getIdType(e) {
434
- const t = e.propertyMap.get("id");
435
- if (!t) return "UUID";
436
- const { type: s } = t;
437
- return s === "uuid" ? "UUID" : s === "string" ? "string" : s === "number" || s === "integer" ? "number" : "UUID";
434
+ return S(e);
438
435
  }
439
436
  }
440
- class k extends ae {
437
+ class B extends ae {
441
438
  name = "Repository";
442
439
  generateMethods(e) {
443
- const { metadata: t, file: s, rxdbNamedImports: a, staticTypesInterface: o } = e, { name: n } = t, i = this.getIdType(t);
444
- o.addProperty({
440
+ const { metadata: t, file: s, rxdbNamedImports: a, staticTypesInterface: i } = e, { name: n } = t, o = S(t);
441
+ i.addProperty({
445
442
  name: "idType",
446
- type: i,
443
+ type: o,
447
444
  docs: ["id 类型"]
448
445
  });
449
- const c = S(e.generator, t), u = _(c, a), h = `
446
+ const c = N(e.generator, t), u = k(c, a), h = `
450
447
  |` + c.map((p) => `'${p.key}'`).join(`
451
448
  |`);
452
449
  s.addTypeAlias({
@@ -473,11 +470,11 @@ ${n}Rule>`,
473
470
  });
474
471
  const g = (p) => ({
475
472
  method: p,
476
- options: `${D(p)}Options<typeof ${n},${n}RuleGroup,${l}>`
473
+ options: `${b(p)}Options<typeof ${n},${n}RuleGroup,${l}>`
477
474
  });
478
475
  this.addStaticMethod(e, {
479
476
  method: "get",
480
- options: `${i}`,
477
+ options: `${o}`,
481
478
  returnType: n,
482
479
  metHodDoc: "根据 ID 获取单个实体",
483
480
  example: `${n}.get('123').subscribe(entity => console.log(entity));`,
@@ -514,7 +511,7 @@ ${n}Rule>`,
514
511
  optionsIsRequired: !0
515
512
  }), this.addStaticMethod(e, {
516
513
  method: "count",
517
- options: `${D("count")}Options<typeof ${n},${n}RuleGroup>`,
514
+ options: `${b("count")}Options<typeof ${n},${n}RuleGroup>`,
518
515
  returnType: "number",
519
516
  metHodDoc: "统计实体数量",
520
517
  example: `${n}.count({ where: { combinator: 'and', rules: [] } }).subscribe(total => console.log(total));`,
@@ -534,69 +531,69 @@ ${n}Rule>`,
534
531
  });
535
532
  }
536
533
  }
537
- class ce extends k {
534
+ class ce extends B {
538
535
  name = "TreeRepository";
539
536
  generateMethods(e) {
540
- const { metadata: t, rxdbNamedImports: s, generator: a, file: o, staticTypesInterface: n } = e, { name: i } = t, c = S(a, t).filter(
537
+ const { metadata: t, rxdbNamedImports: s, generator: a, file: i, staticTypesInterface: n } = e, { name: o } = t, c = N(a, t).filter(
541
538
  (y) => y.key.startsWith("children.") && y.key !== "children.id"
542
- ), u = _(c, s), h = c.map((y) => `'${y.key}'`).join(" | ");
543
- o.addTypeAlias({
544
- name: `${i}TreeRule`,
539
+ ), u = k(c, s), h = c.map((y) => `'${y.key}'`).join(" | ");
540
+ i.addTypeAlias({
541
+ name: `${o}TreeRule`,
545
542
  type: Array.from(new Set(u)).join(`
546
543
  | `),
547
544
  hasDeclareKeyword: !0,
548
545
  docs: ["TreeRule"]
549
- }), o.addTypeAlias({
550
- name: `${i}TreeRuleGroup`,
551
- type: `RuleGroupBase<typeof ${i}, ${h}, ${i}TreeRule>`,
546
+ }), i.addTypeAlias({
547
+ name: `${o}TreeRuleGroup`,
548
+ type: `RuleGroupBase<typeof ${o}, ${h}, ${o}TreeRule>`,
552
549
  hasDeclareKeyword: !0,
553
550
  docs: ["TreeRuleGroup"],
554
551
  isExported: !0
555
552
  }), n.addProperty({
556
553
  name: "entity",
557
- type: `${i}`,
554
+ type: `${o}`,
558
555
  docs: ["查询的实体"]
559
- }), s.add(D("FindTreeOptions"));
560
- const l = `FindTreeOptions<typeof ${i},${i}TreeRuleGroup>`;
556
+ }), s.add(b("FindTreeOptions"));
557
+ const l = `FindTreeOptions<typeof ${o},${o}TreeRuleGroup>`;
561
558
  this.addStaticMethod(e, {
562
559
  method: "findDescendants",
563
560
  options: l,
564
- returnType: `${i}[]`,
561
+ returnType: `${o}[]`,
565
562
  metHodDoc: "查询子孙实体(包含自身)",
566
563
  example: `// 查询某节点的所有后代
567
- ${i}.findDescendants({ entityId: root.id }).subscribe(list => console.log(list));
564
+ ${o}.findDescendants({ entityId: root.id }).subscribe(list => console.log(list));
568
565
 
569
566
  // 仅查询直接子节点(level 1)
570
- ${i}.findDescendants({ entityId: root.id, level: 1 }).subscribe(children => console.log(children));`
567
+ ${o}.findDescendants({ entityId: root.id, level: 1 }).subscribe(children => console.log(children));`
571
568
  }), this.addStaticMethod(e, {
572
569
  method: "countDescendants",
573
570
  options: l,
574
571
  returnType: "number",
575
572
  metHodDoc: "统计子孙实体数量(不包含自身)",
576
573
  example: `// 统计某节点下的后代数量
577
- ${i}.countDescendants({ entityId: root.id }).subscribe(count => console.log(count));`
574
+ ${o}.countDescendants({ entityId: root.id }).subscribe(count => console.log(count));`
578
575
  }), this.addStaticMethod(e, {
579
576
  method: "findAncestors",
580
577
  options: l,
581
- returnType: `${i}[]`,
578
+ returnType: `${o}[]`,
582
579
  metHodDoc: "查询祖先实体(包含自身)",
583
580
  example: `// 查询某节点的所有祖先(面包屑导航)
584
- ${i}.findAncestors({ entityId: grand.id }).subscribe(ancestors => console.log(ancestors));
581
+ ${o}.findAncestors({ entityId: grand.id }).subscribe(ancestors => console.log(ancestors));
585
582
 
586
583
  // 仅查询直接父节点(level 1)
587
- ${i}.findAncestors({ entityId: grand.id, level: 1 }).subscribe(parents => console.log(parents));`
584
+ ${o}.findAncestors({ entityId: grand.id, level: 1 }).subscribe(parents => console.log(parents));`
588
585
  }), this.addStaticMethod(e, {
589
586
  method: "countAncestors",
590
587
  options: l,
591
588
  returnType: "number",
592
589
  metHodDoc: "统计祖先实体数量(不包含自身)",
593
590
  example: `// 统计某节点的祖先层级深度
594
- ${i}.countAncestors({ entityId: grand.id }).subscribe(depth => console.log(depth));`
591
+ ${o}.countAncestors({ entityId: grand.id }).subscribe(depth => console.log(depth));`
595
592
  });
596
593
  }
597
594
  }
598
- var C = /* @__PURE__ */ ((r) => (r.Var = "var", r.Let = "let", r.Const = "const", r))(C || {});
599
- class $ {
595
+ var G = /* @__PURE__ */ ((r) => (r.Var = "var", r.Let = "let", r.Const = "const", r))(G || {});
596
+ class T {
600
597
  /**
601
598
  * 渲染单个参数
602
599
  */
@@ -628,7 +625,7 @@ class $ {
628
625
  */
629
626
  static renderJsDoc(e, t = 0) {
630
627
  if (!e?.length) return "";
631
- const s = " ".repeat(t), a = e.map((o) => `${s} * ${o}`).join(`
628
+ const s = " ".repeat(t), a = e.map((i) => `${s} * ${i}`).join(`
632
629
  `);
633
630
  return `${s}/**
634
631
  ${a}
@@ -639,20 +636,20 @@ ${s} */
639
636
  * 渲染属性
640
637
  */
641
638
  static renderProperty(e, t, s = !0) {
642
- const a = " ".repeat(t), o = [];
643
- return e.docs?.length && o.push(this.renderJsDoc(e.docs, t)), o.push(a), e.isStatic && o.push("static "), e.isReadonly && o.push("readonly "), o.push(e.name), e.hasQuestionToken && o.push("?"), e.type && o.push(`: ${e.type}`), !s && e.initializer && o.push(` = ${e.initializer}`), o.push(`;
644
- `), o.join("");
639
+ const a = " ".repeat(t), i = [];
640
+ return e.docs?.length && i.push(this.renderJsDoc(e.docs, t)), i.push(a), e.isStatic && i.push("static "), e.isReadonly && i.push("readonly "), i.push(e.name), e.hasQuestionToken && i.push("?"), e.type && i.push(`: ${e.type}`), !s && e.initializer && i.push(` = ${e.initializer}`), i.push(`;
641
+ `), i.join("");
645
642
  }
646
643
  /**
647
644
  * 渲染接口块
648
645
  */
649
646
  static renderInterfaceBlock(e, t, s) {
650
- const a = " ".repeat(t), o = [];
651
- return e.docs?.length && o.push(this.renderJsDoc(e.docs, t)), o.push(a), s && e.isExported && o.push("export "), o.push(`interface ${e.name}`), e.extends?.length && o.push(` extends ${e.extends.join(", ")}`), o.push(` {
647
+ const a = " ".repeat(t), i = [];
648
+ return e.docs?.length && i.push(this.renderJsDoc(e.docs, t)), i.push(a), s && e.isExported && i.push("export "), i.push(`interface ${e.name}`), e.extends?.length && i.push(` extends ${e.extends.join(", ")}`), i.push(` {
652
649
  `), e.properties?.length && e.properties.forEach((n) => {
653
- o.push(this.renderProperty(n, t + 2));
654
- }), o.push(`${a}}
655
- `), o.join("");
650
+ i.push(this.renderProperty(n, t + 2));
651
+ }), i.push(`${a}}
652
+ `), i.join("");
656
653
  }
657
654
  /**
658
655
  * 渲染导入声明
@@ -698,28 +695,28 @@ ${s} */
698
695
  if (!t) return "";
699
696
  const s = [], a = e.jsDoc?.length ? e.jsDoc : [t];
700
697
  s.push(this.renderJsDoc(a)), s.push(`export declare class ${t}`);
701
- const o = e.getBaseClass();
702
- if (o) {
703
- const i = o.getName();
704
- i && s.push(` extends ${i}`);
698
+ const i = e.getBaseClass();
699
+ if (i) {
700
+ const o = i.getName();
701
+ o && s.push(` extends ${o}`);
705
702
  }
706
703
  const n = e.getImplements();
707
704
  if (n.length) {
708
- const i = n.map((c) => c.getText()).join(", ");
709
- s.push(` implements ${i}`);
705
+ const o = n.map((c) => c.getText()).join(", ");
706
+ s.push(` implements ${o}`);
710
707
  }
711
708
  if (s.push(` {
712
- `), e.properties?.length && e.properties.forEach((i) => {
713
- s.push(this.renderProperty(i, 2, !1));
709
+ `), e.properties?.length && e.properties.forEach((o) => {
710
+ s.push(this.renderProperty(o, 2, !1));
714
711
  }), e.constructorData) {
715
- const { parameters: i, docs: c } = e.constructorData;
716
- c?.length && s.push(this.renderJsDoc(c, 2)), s.push(` constructor(${this.renderParameterList(i)});
712
+ const { parameters: o, docs: c } = e.constructorData;
713
+ c?.length && s.push(this.renderJsDoc(c, 2)), s.push(` constructor(${this.renderParameterList(o)});
717
714
  `);
718
715
  }
719
- return e.methods?.length && e.methods.forEach((i) => {
720
- i.docs?.length && s.push(this.renderJsDoc(i.docs, 2));
716
+ return e.methods?.length && e.methods.forEach((o) => {
717
+ o.docs?.length && s.push(this.renderJsDoc(o.docs, 2));
721
718
  const c = [" "];
722
- i.isStatic && c.push("static "), c.push(`${i.name}(${this.renderParameterList(i.parameters)})`), i.returnType && c.push(`: ${i.returnType}`), c.push(`;
719
+ o.isStatic && c.push("static "), c.push(`${o.name}(${this.renderParameterList(o.parameters)})`), o.returnType && c.push(`: ${o.returnType}`), c.push(`;
723
720
  `), s.push(c.join(""));
724
721
  }), s.push(`}
725
722
 
@@ -803,7 +800,7 @@ class pe {
803
800
  return this.structure.name || "";
804
801
  }
805
802
  }
806
- class P {
803
+ class _ {
807
804
  filePath;
808
805
  classes = [];
809
806
  interfaces = [];
@@ -829,7 +826,7 @@ class P {
829
826
  const s = this.modules[this.modules.length - 1];
830
827
  return s.interfaces || (s.interfaces = []), s.interfaces.push(t), {
831
828
  addProperty: (a) => {
832
- const o = this.modules[this.modules.length - 1], n = o.interfaces[o.interfaces.length - 1];
829
+ const i = this.modules[this.modules.length - 1], n = i.interfaces[i.interfaces.length - 1];
833
830
  n.properties || (n.properties = []), n.properties.push(a);
834
831
  }
835
832
  };
@@ -853,13 +850,13 @@ class P {
853
850
  }
854
851
  getText() {
855
852
  return this.fileContent ? this.fileContent : [
856
- $.renderImports(this.imports),
857
- $.renderTypeAliases(this.typeAliases),
858
- $.renderModules(this.modules),
859
- this.interfaces.map((t) => $.renderInterfaceBlock(t, 0, !0) + `
853
+ T.renderImports(this.imports),
854
+ T.renderTypeAliases(this.typeAliases),
855
+ T.renderModules(this.modules),
856
+ this.interfaces.map((t) => T.renderInterfaceBlock(t, 0, !0) + `
860
857
  `).join(""),
861
- this.classes.map((t) => $.renderClass(t)).join(""),
862
- $.renderVariables(this.variables)
858
+ this.classes.map((t) => T.renderClass(t)).join(""),
859
+ T.renderVariables(this.variables)
863
860
  ].join("");
864
861
  }
865
862
  setContent(e) {
@@ -875,28 +872,28 @@ class P {
875
872
  class le {
876
873
  files = /* @__PURE__ */ new Map();
877
874
  createSourceFile(e, t) {
878
- const s = new P(e);
875
+ const s = new _(e);
879
876
  return t && s.setContent(t), this.files.set(e, s), s;
880
877
  }
881
878
  addSourceFileAtPath(e) {
882
- const t = new P(e);
879
+ const t = new _(e);
883
880
  return this.files.set(e, t), t;
884
881
  }
885
882
  getSourceFiles() {
886
883
  return Array.from(this.files.values());
887
884
  }
888
885
  }
889
- const x = (r, e = "public") => `${e}_${r}`;
890
- class ye {
886
+ const Y = "public", I = "Repository", ge = "TreeRepository", Te = "GraphRepository", ue = "EntityBase", he = "TreeAdjacencyListEntityBase", ye = "TreeEntityBase", x = (r, e = Y) => `${e}_${r}`;
887
+ class $e {
891
888
  /**
892
889
  * Repository 生成器注册表
893
890
  * 用于支持可扩展的 Repository 类型
894
891
  */
895
892
  repositoryGenerators = /* @__PURE__ */ new Map();
896
893
  entityMetadataOptionsMap = /* @__PURE__ */ new Map([
897
- ["EntityBase", [E]],
898
- ["TreeAdjacencyListEntityBase", [N, E]],
899
- ["TreeEntityBase", [N, E]]
894
+ [ue, [R]],
895
+ [he, [P, R]],
896
+ [ye, [P, R]]
900
897
  ]);
901
898
  metadataOptionsSet = /* @__PURE__ */ new Set();
902
899
  metadataSet = /* @__PURE__ */ new Set();
@@ -906,7 +903,7 @@ class ye {
906
903
  relationQueryDeep: 3
907
904
  };
908
905
  constructor(e) {
909
- Object.assign(this.config, e), this.config.relationQueryDeep < 1 && (this.config.relationQueryDeep = 1), this.registerRepositoryGenerator(new k()), this.registerRepositoryGenerator(new ce());
906
+ Object.assign(this.config, e), this.config.relationQueryDeep < 1 && (this.config.relationQueryDeep = 1), this.registerRepositoryGenerator(new B()), this.registerRepositoryGenerator(new ce());
910
907
  }
911
908
  /**
912
909
  * 添加实体配置
@@ -915,10 +912,10 @@ class ye {
915
912
  addEntity(e, t) {
916
913
  let s;
917
914
  if (U(e))
918
- s = B(e);
915
+ s = K(e);
919
916
  else {
920
917
  const a = e;
921
- t = t || a.extends?.length && this.entityMetadataOptionsMap.get(a.extends[0]) || [], s = A(e, t);
918
+ t = t || a.extends?.length && this.entityMetadataOptionsMap.get(a.extends[0]) || [], s = O(e, t);
922
919
  }
923
920
  this.metadataSet.add(s), this.metadataMap.set(`${s.namespace}_${s.name}`, s);
924
921
  }
@@ -927,7 +924,7 @@ class ye {
927
924
  }
928
925
  registerAbstractMetadata(e, t) {
929
926
  this.entityMetadataOptionsMap.set(e, t), t.forEach((s) => {
930
- const a = A(s);
927
+ const a = O(s);
931
928
  this.metadataMap.set(x(s.name, s.namespace), a);
932
929
  });
933
930
  }
@@ -969,21 +966,21 @@ class ye {
969
966
  generateEntityJsFile() {
970
967
  const { project: e, metadataSet: t } = this;
971
968
  let s = "";
972
- const a = /* @__PURE__ */ new Set(["Entity", "__decorateClass"]), o = (i) => {
973
- const c = this.getMetadata(i.mappedEntity, i.mappedNamespace);
969
+ const a = /* @__PURE__ */ new Set(["Entity", "__decorateClass"]), i = (o) => {
970
+ const c = this.getMetadata(o.mappedEntity, o.mappedNamespace);
974
971
  if (c?.relations)
975
972
  return c.relations.find(
976
- (u) => u.kind === f.MANY_TO_MANY && u.name === i.mappedProperty && u.mappedProperty === i.name
973
+ (u) => u.kind === f.MANY_TO_MANY && u.name === o.mappedProperty && u.mappedProperty === o.name
977
974
  );
978
975
  };
979
- t.forEach((i) => {
980
- i.relations.forEach((c) => {
981
- if (c.kind === f.MANY_TO_MANY && !o(c))
976
+ t.forEach((o) => {
977
+ o.relations.forEach((c) => {
978
+ if (c.kind === f.MANY_TO_MANY && !i(c))
982
979
  throw new Error("mapped relation not found");
983
980
  });
984
- }), t.forEach((i) => {
985
- const c = i.extends[0], { name: u } = i, h = u, l = Q(i);
986
- c && a.add(c), i.properties.length && a.add("PropertyType"), i.relations.length && a.add("RelationKind"), s += `
981
+ }), t.forEach((o) => {
982
+ const c = o.extends[0], { name: u } = o, h = u, l = q(o);
983
+ c && a.add(c), o.properties.length && a.add("PropertyType"), o.relations.length && a.add("RelationKind"), s += `
987
984
  let ${h} = class ${c ? "extends " + c : ""} {};`, s += `
988
985
  ${h} = __decorateClass(
989
986
  [
@@ -992,7 +989,7 @@ ${h} = __decorateClass(
992
989
  ${h}
993
990
  );`;
994
991
  }), s = `import { ${Array.from(a).sort().join(", ")} } from '@aiao/rxdb';` + s;
995
- const n = Array.from(t.values()).map((i) => i.name).sort().join(", ");
992
+ const n = Array.from(t.values()).map((o) => o.name).sort().join(", ");
996
993
  s += `
997
994
  const ENTITIES = [ ${n} ];`, s += `
998
995
  export { ENTITIES, ${n} };`, e.createSourceFile("index.js", s);
@@ -1002,7 +999,7 @@ export { ENTITIES, ${n} };`, e.createSourceFile("index.js", s);
1002
999
  * @private
1003
1000
  */
1004
1001
  generateAllEntityDefinition() {
1005
- const { project: e, metadataSet: t } = this, s = e.createSourceFile("index.d.ts"), o = s.addModule({
1002
+ const { project: e, metadataSet: t } = this, s = e.createSourceFile("index.d.ts"), i = s.addModule({
1006
1003
  name: '"@aiao/rxdb"',
1007
1004
  hasDeclareKeyword: !0,
1008
1005
  docs: ["rxdb"]
@@ -1010,20 +1007,20 @@ export { ENTITIES, ${n} };`, e.createSourceFile("index.js", s);
1010
1007
  name: "RxDB",
1011
1008
  docs: ["RxDB"]
1012
1009
  }), n = /* @__PURE__ */ new Set(["EntityType", "IEntity", "ITreeEntity", "RuleGroupBase", "UUID"]);
1013
- t.forEach((i) => {
1014
- const { rxdbNamedImports: c } = Z(this, i, s);
1010
+ t.forEach((o) => {
1011
+ const { rxdbNamedImports: c } = Z(this, o, s);
1015
1012
  c.forEach((l) => n.add(l));
1016
- const { name: u } = i, h = u;
1017
- i.namespace && i.namespace !== "public" ? o.addProperty({
1018
- name: i.namespace,
1013
+ const { name: u } = o, h = u;
1014
+ o.namespace && o.namespace !== Y ? i.addProperty({
1015
+ name: o.namespace,
1019
1016
  type: `{
1020
1017
  ${h}: typeof ${h};
1021
1018
  }`,
1022
- docs: [i.displayName]
1023
- }) : o.addProperty({
1019
+ docs: [o.displayName]
1020
+ }) : i.addProperty({
1024
1021
  name: h,
1025
1022
  type: `typeof ${h}`,
1026
- docs: [i.displayName]
1023
+ docs: [o.displayName]
1027
1024
  });
1028
1025
  }), s.addImportDeclaration({
1029
1026
  namedImports: Array.from(n).filter(Boolean).sort(),
@@ -1034,7 +1031,7 @@ ${h}: typeof ${h};
1034
1031
  isTypeOnly: !0,
1035
1032
  moduleSpecifier: "rxjs"
1036
1033
  }), s.addVariableStatement({
1037
- declarationKind: C.Const,
1034
+ declarationKind: G.Const,
1038
1035
  hasDeclareKeyword: !0,
1039
1036
  isExported: !0,
1040
1037
  declarations: [
@@ -1047,6 +1044,10 @@ ${h}: typeof ${h};
1047
1044
  }
1048
1045
  }
1049
1046
  export {
1050
- ae as R,
1051
- ye as a
1047
+ Y as N,
1048
+ Te as R,
1049
+ I as a,
1050
+ ge as b,
1051
+ ae as c,
1052
+ $e as d
1052
1053
  };