@aiao/rxdb-client-generator 0.0.2 → 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.
package/index.js CHANGED
@@ -1,857 +1,6 @@
1
- import { PropertyType as u, RelationKind as m, getEntityMetadata as b, transitionMetadata as D } from "@aiao/rxdb";
2
- import { isNil as R, omit as S, isObject as _, isArray as x, isFunction as j } from "@aiao/utils";
3
- import { rxDBViteClientGenerator as W } from "./vite.js";
4
- const N = (s) => {
5
- const e = T(s), t = !!s.nullable;
6
- let n = !0;
7
- !t && Object.hasOwn(s, "default") && (n = !1);
8
- const i = {
9
- type: e,
10
- name: s.name,
11
- hasQuestionToken: t,
12
- hasExclamationToken: n,
13
- isReadonly: s.readonly
14
- };
15
- return R(s.default) || (i.initializer = k(s)), i;
16
- }, T = (s) => {
17
- let e = "any";
18
- switch (s.type) {
19
- case u.uuid:
20
- e = "UUID";
21
- break;
22
- case u.string:
23
- e = "string";
24
- break;
25
- case u.number:
26
- e = "number";
27
- break;
28
- case u.boolean:
29
- e = "boolean";
30
- break;
31
- case u.date:
32
- e = "Date";
33
- break;
34
- }
35
- return s.nullable && (e += " | null"), e;
36
- }, k = (s) => {
37
- switch (s.type) {
38
- case u.string:
39
- return `'${String(s.default)}'`;
40
- case u.date:
41
- return `new Date(${s.default.getTime()})`;
42
- default:
43
- return `${String(s.default)}`;
44
- }
45
- }, f = (s, e = /* @__PURE__ */ new Set()) => {
46
- if (_(s))
47
- for (const t in s)
48
- e.add(t), Object.prototype.hasOwnProperty.call(s, t) && f(Reflect.get(s, t), e);
49
- else if (x(s))
50
- for (const t of s)
51
- f(t, e);
52
- return e;
53
- }, E = /* @__PURE__ */ new Map();
54
- Object.keys(u).forEach((s) => {
55
- const e = u[s];
56
- E.set(e, s);
57
- });
58
- const O = /* @__PURE__ */ new Map();
59
- Object.keys(m).forEach((s) => {
60
- const e = m[s];
61
- O.set(e, s);
62
- });
63
- function A(s) {
64
- const e = S(s, ["propertyMap", "relationMap", "indexMap"]), t = f(e);
65
- let n = JSON.stringify(e, null, 2);
66
- return new Set(s.properties.map((r) => r.type)).forEach((r) => {
67
- const o = E.get(r);
68
- n = n.replaceAll(`"type": "${r}"`, `"type": PropertyType.${o}`);
69
- }), s.relations && new Set(s.relations.map((o) => o.kind)).forEach((o) => {
70
- const a = O.get(o);
71
- n = n.replaceAll(`"kind": "${o}"`, `"kind": RelationKind.${a}`);
72
- }), t.forEach((r) => {
73
- r.includes("-") || r.includes(" ") || (n = n.replaceAll(`"${r}":`, `${r}:`));
74
- }), n;
75
- }
76
- function C(s) {
77
- return s.startsWith("_") || s === "id" || s === "createdAt" || s === "updatedAt" || s === "removedAt";
78
- }
79
- const F = ({
80
- classProperties: s,
81
- metadata: e,
82
- file: t
83
- }) => {
84
- const { name: n } = e, i = t.addInterface({
85
- name: `${n}InitData`,
86
- isExported: !0,
87
- docs: ["初始化数据"]
88
- });
89
- e.propertyMap.values().filter((r) => C(r.name) === !1).forEach((r) => {
90
- const o = N(r), { initializer: a, ...p } = o;
91
- let c = r.displayName || r.name;
92
- a && (c += `
93
- @default ${a}`), i.addProperty({
94
- name: o.name,
95
- type: o.type,
96
- hasQuestionToken: !0,
97
- docs: [c]
98
- }), s.push({
99
- ...p,
100
- hasExclamationToken: !1,
101
- docs: [c]
102
- });
103
- });
104
- }, v = ({
105
- classProperties: s,
106
- metadata: e,
107
- rxdbNamedImports: t
108
- }) => {
109
- e.relationMap.values().forEach((n) => {
110
- switch (n.kind) {
111
- // 处理一对一和多对一关系
112
- // 这两种关系需要生成:
113
- // 1. 关系可观察对象属性(name$)- 用于访问关联实体
114
- // 2. 外键ID属性(nameId)- 存储关联实体的ID
115
- case m.ONE_TO_ONE:
116
- case m.MANY_TO_ONE:
117
- {
118
- const i = n.nullable ? `RelationEntityObservable<${n.mappedEntity} | null>` : `RelationEntityObservable<${n.mappedEntity}>`, r = n.displayName || n.name;
119
- s.push({
120
- name: n.name + "$",
121
- // 关系属性名使用$后缀,表示可观察对象
122
- type: i,
123
- isReadonly: !0,
124
- // 关系属性是只读的,通过set/remove方法修改
125
- docs: [r]
126
- }), s.push({
127
- name: n.name + "Id",
128
- // 外键ID属性
129
- type: "UUID",
130
- isReadonly: !0,
131
- docs: [r + " id"]
132
- }), t.add("RelationEntityObservable");
133
- }
134
- break;
135
- // 处理一对多和多对多关系
136
- // 这两种关系只需要生成关系可观察集合属性(name$)
137
- // 不需要外键ID属性,因为外键存储在关联实体或中间表中
138
- case m.ONE_TO_MANY:
139
- case m.MANY_TO_MANY:
140
- {
141
- const i = n.displayName || n.name, r = `RelationEntitiesObservable<${n.mappedEntity}>`;
142
- s.push({
143
- name: n.name + "$",
144
- // 关系集合属性名使用$后缀
145
- isReadonly: !0,
146
- // 关系属性是只读的,通过add/remove方法修改
147
- type: r,
148
- docs: [i]
149
- }), t.add("RelationEntitiesObservable");
150
- }
151
- break;
152
- }
153
- });
154
- }, M = (s) => Array.from(s.propertyMap.keys()).map((e) => {
155
- const t = s.propertyMap.get(e);
156
- let n = "";
157
- switch (t.type) {
158
- case u.uuid:
159
- n = "UUID";
160
- break;
161
- case u.string:
162
- n = "String";
163
- break;
164
- case u.number:
165
- case u.integer:
166
- n = "Number";
167
- break;
168
- case u.boolean:
169
- n = "Boolean";
170
- break;
171
- case u.date:
172
- n = "Date";
173
- break;
174
- default:
175
- throw new Error("Unknown property type: " + t.type);
176
- }
177
- if (!n) throw new Error("ruleName is empty");
178
- n += "Rules";
179
- const i = T(t);
180
- return {
181
- rule: n,
182
- entity: s.name,
183
- key: e,
184
- valueType: i
185
- };
186
- }), $ = (s, e, t, n = [], i = [], r = []) => (t = t ?? e, M(e).forEach(({ rule: o, entity: a, key: p, valueType: c }) => {
187
- r.length > 0 ? p = r.map((d) => d.key).join(".") + "." + p : c = void 0, i.push({
188
- rule: o,
189
- entity: a,
190
- key: p,
191
- valueType: c
192
- });
193
- }), e.foreignKeyNames.forEach((o) => {
194
- i.push({
195
- rule: "UUIDRules",
196
- entity: e.name,
197
- key: o
198
- });
199
- }), e.relationMap.keys().filter((o) => !n.includes(o)).forEach((o) => {
200
- const a = e.relationMap.get(o);
201
- if (!a)
202
- throw new Error("relation is empty");
203
- const p = [];
204
- switch (a.kind) {
205
- case m.ONE_TO_ONE:
206
- break;
207
- case m.ONE_TO_MANY:
208
- p.push(a.mappedProperty);
209
- break;
210
- case m.MANY_TO_ONE:
211
- break;
212
- case m.MANY_TO_MANY:
213
- p.push(a.mappedProperty);
214
- break;
215
- }
216
- const c = s.metadataMap.get(`${a.mappedNamespace}_${a.mappedEntity}`);
217
- if (!c)
218
- throw new Error(`generator_entity_rules: metadata "${a.mappedEntity}" not found`);
219
- if (r.find((h) => h.entity === e.name) || r.length && c === t) return;
220
- const l = [...r, { key: o, entity: e.name }];
221
- r.length < s.config.relationQueryDeep && $(s, c, t, p, i, l);
222
- }), i), I = ({
223
- classMethods: s,
224
- rxdbNamedImports: e,
225
- generator: t,
226
- metadata: n,
227
- file: i
228
- }) => {
229
- const { name: r } = n, a = $(t, n).map(({ rule: d, entity: l, key: h, valueType: y }) => (e.add(d), y ? (y === "UUID" && e.add("UUID"), `${d}<${l}, '${h}', ${y}>`) : `${d}<${l}, '${h}'>`));
230
- i.addTypeAlias({
231
- name: `${r}Rule`,
232
- type: `
233
- | ` + Array.from(new Set(a)).join(`
234
- | `),
235
- hasDeclareKeyword: !0,
236
- docs: ["rule"]
237
- }), i.addTypeAlias({
238
- name: `${r}RuleGroup`,
239
- type: `RuleGroup<${r}, keyof ${r}, ${r}Rule>`,
240
- hasDeclareKeyword: !0,
241
- docs: ["RuleGroup"],
242
- isExported: !0
243
- });
244
- const p = `${r}OrderByField`, c = Array.from(n.propertyMap.keys());
245
- i.addTypeAlias({
246
- name: p,
247
- type: c.map((d) => `"${d}"`).join(" | "),
248
- hasDeclareKeyword: !0,
249
- docs: ["OrderByField"]
250
- }), s.push({
251
- name: "get",
252
- returnType: `Observable<${r}>`,
253
- docs: [["查询", "@param id 实体的 id", "@param options 查询选项"].join(`
254
- `)],
255
- parameters: [
256
- {
257
- name: "id",
258
- type: "string"
259
- },
260
- {
261
- name: "options",
262
- hasQuestionToken: !0,
263
- type: "GetOptions"
264
- }
265
- ],
266
- isStatic: !0
267
- }), e.add("GetOptions"), s.push({
268
- name: "findOneOrFail",
269
- returnType: `Observable<${r}>`,
270
- docs: [["查询", "@param where 查询条件", "@param options 查询选项"].join(`
271
- `)],
272
- parameters: [
273
- {
274
- name: "where",
275
- type: `${r}RuleGroup`
276
- },
277
- {
278
- name: "options",
279
- hasQuestionToken: !0,
280
- type: `FindOneOrFailOptions<${p}>`
281
- }
282
- ],
283
- isStatic: !0
284
- }), e.add("FindOneOrFailOptions"), s.push({
285
- name: "find",
286
- returnType: `Observable<${r}[]>`,
287
- docs: [["查询", "@param where 查询条件", "@param options 查询选项"].join(`
288
- `)],
289
- parameters: [
290
- {
291
- name: "where",
292
- type: `${r}RuleGroup`
293
- },
294
- {
295
- name: "options",
296
- hasQuestionToken: !0,
297
- type: `FindOptions<${p}>`
298
- }
299
- ],
300
- isStatic: !0
301
- }), e.add("FindOptions"), s.push({
302
- name: "findOne",
303
- returnType: `Observable<${r} | undefined>`,
304
- docs: [["查询", "@param where 查询条件", "@param options 查询选项"].join(`
305
- `)],
306
- parameters: [
307
- {
308
- name: "where",
309
- type: `${r}RuleGroup`
310
- },
311
- {
312
- name: "options",
313
- hasQuestionToken: !0,
314
- type: `FindOneOptions<${p}>`
315
- }
316
- ],
317
- isStatic: !0
318
- }), e.add("FindOneOptions"), s.push({
319
- name: "findAll",
320
- returnType: `Observable<${r}[]>`,
321
- docs: [["查询", "@param where 查询条件", "@param options 查询选项"].join(`
322
- `)],
323
- parameters: [
324
- {
325
- name: "where",
326
- type: `${r}RuleGroup`
327
- },
328
- {
329
- name: "options",
330
- hasQuestionToken: !0,
331
- type: `FindAllOptions<${p}>`
332
- }
333
- ],
334
- isStatic: !0
335
- }), e.add("FindAllOptions"), s.push({
336
- name: "findByCursor",
337
- returnType: `Observable<${r}[]>`,
338
- docs: [["查询", "@param where 查询条件", "@param options 查询选项"].join(`
339
- `)],
340
- parameters: [
341
- {
342
- name: "where",
343
- type: `${r}RuleGroup`
344
- },
345
- {
346
- name: "options",
347
- hasQuestionToken: !0,
348
- type: `FindByCursorOptions<${p}>`
349
- }
350
- ],
351
- isStatic: !0
352
- }), e.add("FindByCursorOptions"), s.push({
353
- name: "count",
354
- returnType: "Observable<number>",
355
- docs: [["查询", "@param where 查询条件", "@param options 查询选项"].join(`
356
- `)],
357
- parameters: [
358
- {
359
- name: "where",
360
- type: `${r}RuleGroup`
361
- },
362
- {
363
- name: "options",
364
- hasQuestionToken: !0,
365
- type: "CountOptions"
366
- }
367
- ],
368
- isStatic: !0
369
- }), e.add("CountOptions"), s.push({
370
- name: "save",
371
- returnType: `Promise<${r}>`,
372
- docs: [["保存"].join(`
373
- `)]
374
- }), s.push({
375
- name: "remove",
376
- returnType: `Promise<${r}>`,
377
- docs: [["删除"].join(`
378
- `)]
379
- });
380
- }, P = ({
381
- metadata: s,
382
- classMethods: e,
383
- rxdbNamedImports: t,
384
- generator: n,
385
- file: i
386
- }) => {
387
- const { name: r } = s, a = $(n, s).filter(
388
- (p) => p.key.startsWith("children.") && p.key !== "children.id"
389
- ).map(({ rule: p, entity: c, key: d, valueType: l }) => (t.add(p), l ? (l === "UUID" && t.add("UUID"), `${p}<${c}, '${d}', ${l}>`) : `${p}<${c}, '${d}'>`));
390
- i.addTypeAlias({
391
- name: `${r}TreeRule`,
392
- type: `
393
- | ` + Array.from(new Set(a)).join(`
394
- | `),
395
- hasDeclareKeyword: !0,
396
- docs: ["TreeRule"]
397
- }), i.addTypeAlias({
398
- name: `${r}TreeRuleGroup`,
399
- type: `RuleGroup<${r}, keyof ${r}, ${r}TreeRule>`,
400
- hasDeclareKeyword: !0,
401
- docs: ["TreeRuleGroup"],
402
- isExported: !0
403
- }), e.push({
404
- name: "findDescendants",
405
- returnType: `Observable<${r}[]>`,
406
- docs: [["查询子孙实体", "@param options 查询选项"].join(`
407
- `)],
408
- parameters: [
409
- {
410
- name: "entity",
411
- type: `${r}`
412
- },
413
- {
414
- name: "where",
415
- type: `${r}TreeRuleGroup`
416
- },
417
- {
418
- name: "options",
419
- type: "FindTreeOptions",
420
- hasQuestionToken: !0
421
- }
422
- ],
423
- isStatic: !0
424
- }), e.push({
425
- name: "countDescendants",
426
- returnType: "Observable<number>",
427
- docs: [["查询子孙实体数量", "@param options 查询选项"].join(`
428
- `)],
429
- parameters: [
430
- {
431
- name: "entity",
432
- type: `${r}`
433
- },
434
- {
435
- name: "where",
436
- type: `${r}TreeRuleGroup`
437
- },
438
- {
439
- name: "options",
440
- type: "FindTreeOptions",
441
- hasQuestionToken: !0
442
- }
443
- ],
444
- isStatic: !0
445
- }), e.push({
446
- name: "findAncestors",
447
- returnType: `Observable<${r}[]>`,
448
- docs: [["查询祖先实体", "@param options 查询选项"].join(`
449
- `)],
450
- parameters: [
451
- {
452
- name: "entity",
453
- type: `${r}`
454
- },
455
- {
456
- name: "where",
457
- type: `${r}TreeRuleGroup`
458
- },
459
- {
460
- name: "options",
461
- type: "FindTreeOptions",
462
- hasQuestionToken: !0
463
- }
464
- ],
465
- isStatic: !0
466
- }), e.push({
467
- name: "countAncestors",
468
- returnType: "Observable<number>",
469
- docs: [["查询祖先实体数量", "@param options 查询选项"].join(`
470
- `)],
471
- parameters: [
472
- {
473
- name: "entity",
474
- type: `${r}`
475
- },
476
- {
477
- name: "where",
478
- type: `${r}TreeRuleGroup`
479
- },
480
- {
481
- name: "options",
482
- type: "FindTreeOptions",
483
- hasQuestionToken: !0
484
- }
485
- ],
486
- isStatic: !0
487
- }), t.add("FindTreeOptions");
488
- }, Q = (s, e, t) => {
489
- const n = /* @__PURE__ */ new Set(), { name: i } = e, r = e.extends[0];
490
- n.add(r);
491
- const o = t.addClass({
492
- name: i,
493
- isExported: !0,
494
- extends: r,
495
- decorators: [],
496
- hasDeclareKeyword: !0
497
- });
498
- o.addJsDoc(`
499
- ${e.displayName}`);
500
- const a = [], p = [];
501
- return F({
502
- classProperties: a,
503
- file: t,
504
- metadata: e
505
- }), v({
506
- classProperties: a,
507
- metadata: e,
508
- rxdbNamedImports: n
509
- }), I({
510
- classMethods: p,
511
- file: t,
512
- generator: s,
513
- metadata: e,
514
- rxdbNamedImports: n
515
- }), e.repository === "TreeRepository" && P({
516
- classMethods: p,
517
- metadata: e,
518
- file: t,
519
- generator: s,
520
- rxdbNamedImports: n
521
- }), o.addProperties(
522
- a.sort((c, d) => c.isReadonly && !d.isReadonly ? -1 : !c.isReadonly && d.isReadonly ? 1 : c.name.localeCompare(d.name))
523
- ), o.addConstructor({
524
- parameters: [
525
- {
526
- name: "initData",
527
- type: `${i}InitData`,
528
- hasQuestionToken: !0
529
- }
530
- ],
531
- docs: [["初始化数据", "@param initData 初始化数据"].join(`
532
- `)]
533
- }), o.addMethods(
534
- p.sort((c, d) => c.isStatic && !d.isStatic ? -1 : !c.isStatic && d.isStatic ? 1 : c.name.localeCompare(d.name))
535
- ), {
536
- rxdbNamedImports: n
537
- };
538
- };
539
- var w = /* @__PURE__ */ ((s) => (s.Var = "var", s.Let = "let", s.Const = "const", s))(w || {});
540
- class G {
541
- files = /* @__PURE__ */ new Map();
542
- createSourceFile(e, t) {
543
- const n = new g(e);
544
- return t && n.setContent(t), this.files.set(e, n), n;
545
- }
546
- addSourceFileAtPath(e) {
547
- const t = new g(e);
548
- return this.files.set(e, t), t;
549
- }
550
- getSourceFiles() {
551
- return Array.from(this.files.values());
552
- }
553
- }
554
- class g {
555
- filePath;
556
- classes = [];
557
- interfaces = [];
558
- modules = [];
559
- typeAliases = [];
560
- imports = [];
561
- variables = [];
562
- fileContent = "";
563
- constructor(e) {
564
- this.filePath = e;
565
- }
566
- addClass(e) {
567
- const t = new K(e);
568
- return this.classes.push(t), t;
569
- }
570
- addInterface(e) {
571
- return this.interfaces.push(e), {
572
- addProperty: (t) => {
573
- }
574
- };
575
- }
576
- addModule(e) {
577
- return this.modules.push(e), {
578
- addInterface: (t) => (this.modules[this.modules.length - 1].interfaces || (this.modules[this.modules.length - 1].interfaces = []), this.modules[this.modules.length - 1].interfaces.push(t), {
579
- addProperty: (n) => {
580
- const i = this.modules[this.modules.length - 1].interfaces[this.modules[this.modules.length - 1].interfaces.length - 1];
581
- i.properties || (i.properties = []), i.properties.push(n);
582
- }
583
- })
584
- };
585
- }
586
- addTypeAlias(e) {
587
- return this.typeAliases.push(e), e;
588
- }
589
- addImportDeclaration(e) {
590
- this.imports.push(e);
591
- }
592
- addVariableStatement(e) {
593
- this.variables.push(e);
594
- }
595
- getClasses() {
596
- return this.classes;
597
- }
598
- getFilePath() {
599
- return this.filePath;
600
- }
601
- getText() {
602
- if (this.fileContent)
603
- return this.fileContent;
604
- let e = "";
605
- return this.imports.forEach((t) => {
606
- t.namedImports && t.namedImports.length > 0 && (e += `import { ${t.namedImports.join(", ")} } from '${t.moduleSpecifier}';
607
- `);
608
- }), this.imports.length > 0 && (e += `
609
- `), this.typeAliases.forEach((t) => {
610
- t.docs && t.docs.length > 0 && (e += `/** ${t.docs.join(`
611
- `)} */
612
- `), t.hasDeclareKeyword && (e += "declare "), t.isExported && (e += "export "), e += `type ${t.name} = ${t.type};
613
-
614
- `;
615
- }), this.modules.forEach((t) => {
616
- t.docs && t.docs.length > 0 && (e += `/** ${t.docs.join(`
617
- `)} */
618
- `), t.hasDeclareKeyword && (e += "declare "), e += `module ${t.name} {
619
- `, t.interfaces && t.interfaces.length > 0 && t.interfaces.forEach((n) => {
620
- n.docs && n.docs.length > 0 && (e += ` /** ${n.docs.join(`
621
- `)} */
622
- `), e += ` interface ${n.name}`, n.extends && n.extends.length > 0 && (e += ` extends ${n.extends.join(", ")}`), e += ` {
623
- `, n.properties && n.properties.length > 0 && n.properties.forEach((i) => {
624
- i.docs && i.docs.length > 0 && (e += ` /** ${i.docs.join(`
625
- `)} */
626
- `), e += ` ${i.name}`, i.hasQuestionToken && (e += "?"), i.type && (e += `: ${i.type}`), e += `;
627
- `;
628
- }), e += ` }
629
- `;
630
- }), e += `}
631
-
632
- `;
633
- }), this.interfaces.forEach((t) => {
634
- t.docs && t.docs.length > 0 && (e += `/** ${t.docs.join(`
635
- `)} */
636
- `), t.isExported && (e += "export "), e += `interface ${t.name}`, t.extends && t.extends.length > 0 && (e += ` extends ${t.extends.join(", ")}`), e += ` {
637
- `, e += `}
638
-
639
- `;
640
- }), this.classes.forEach((t) => {
641
- const n = t.getName();
642
- if (n) {
643
- t.jsDoc && t.jsDoc.length > 0 ? e += `/**
644
- * ${t.jsDoc.join(`
645
- * `)}
646
- */
647
- ` : e += `/**
648
- * ${n}
649
- */
650
- `, e += `export declare class ${n}`;
651
- const i = t.getBaseClass();
652
- if (i) {
653
- const o = i.getName();
654
- o && (e += ` extends ${o}`);
655
- }
656
- const r = t.getImplements();
657
- if (r.length > 0 && (e += ` implements ${r.map((o) => o.getText()).join(", ")}`), e += ` {
658
- `, t.properties && t.properties.length > 0 && t.properties.forEach((o) => {
659
- o.docs && o.docs.length > 0 && (e += ` /** ${o.docs.join(`
660
- `)} */
661
- `), e += ` ${o.name}`, o.hasQuestionToken && (e += "?"), o.type && (e += `: ${o.type}`), o.initializer && (e += ` = ${o.initializer}`), e += `;
662
- `;
663
- }), t.constructorData) {
664
- const o = t.constructorData;
665
- o.docs && o.docs.length > 0 && (e += ` /**
666
- * ${o.docs.join(`
667
- * `)}
668
- */
669
- `), e += " constructor(", o.parameters && o.parameters.length > 0 && o.parameters.forEach((a, p) => {
670
- p > 0 && (e += ", "), e += a.name, a.hasQuestionToken && (e += "?"), a.type && (e += `: ${a.type}`);
671
- }), e += `);
672
- `;
673
- }
674
- t.methods && t.methods.length > 0 && t.methods.forEach((o) => {
675
- o.docs && o.docs.length > 0 && (e += ` /**
676
- * ${o.docs.join(`
677
- * `)}
678
- */
679
- `), o.isStatic && (e += " static "), e += `${o.name}(`, o.parameters && o.parameters.length > 0 && o.parameters.forEach((a, p) => {
680
- p > 0 && (e += ", "), e += a.name, a.hasQuestionToken && (e += "?"), a.type && (e += `: ${a.type}`);
681
- }), e += ")", o.returnType && (e += `: ${o.returnType}`), e += `;
682
- `;
683
- }), e += `}
684
-
685
- `;
686
- }
687
- }), this.variables.forEach((t) => {
688
- t.hasDeclareKeyword && (e += "declare "), t.isExported && (e += "export "), e += `${t.declarationKind} `, t.declarations.forEach((n, i) => {
689
- i > 0 && (e += ", "), e += n.name, n.type && (e += `: ${n.type}`), n.initializer && (e += ` = ${n.initializer}`);
690
- }), e += `;
691
-
692
- `;
693
- }), e;
694
- }
695
- setContent(e) {
696
- this.fileContent = e;
697
- }
698
- async save() {
699
- console.log(`SourceFile ${this.filePath} saved`);
700
- }
701
- saveSync() {
702
- console.log(`SourceFile ${this.filePath} saved synchronously`);
703
- }
704
- }
705
- class K {
706
- structure;
707
- decorators = [];
708
- properties = [];
709
- methods = [];
710
- constructorData;
711
- jsDoc = [];
712
- constructor(e) {
713
- this.structure = e;
714
- }
715
- addJsDoc(e) {
716
- this.jsDoc.push(e);
717
- }
718
- addProperties(e) {
719
- this.properties.push(...e);
720
- }
721
- addConstructor(e) {
722
- this.constructorData = e;
723
- }
724
- addMethods(e) {
725
- this.methods.push(...e);
726
- }
727
- getDecorators() {
728
- return this.decorators;
729
- }
730
- getName() {
731
- return this.structure.name;
732
- }
733
- getBaseClass() {
734
- return this.structure.extends ? {
735
- getName: () => this.structure.extends,
736
- getText: () => this.structure.extends,
737
- getDecorators: () => [],
738
- getImplements: () => [],
739
- getBaseClass: () => {
740
- }
741
- } : void 0;
742
- }
743
- getImplements() {
744
- return (this.structure.implements || []).map((e) => ({
745
- getName: () => e,
746
- getText: () => e,
747
- getDecorators: () => [],
748
- getImplements: () => [],
749
- getBaseClass: () => {
750
- }
751
- }));
752
- }
753
- getText() {
754
- return this.structure.name || "";
755
- }
756
- }
757
- const B = (s) => {
758
- const { project: e, metadataSet: t } = s, n = e.createSourceFile("types.d.ts"), r = n.addModule({
759
- name: '"@aiao/rxdb"',
760
- hasDeclareKeyword: !0,
761
- docs: ["rxdb"]
762
- }).addInterface({
763
- name: "RxDB",
764
- docs: ["RxDB"]
765
- }), o = /* @__PURE__ */ new Set(["EntityType", "RuleGroup"]);
766
- t.forEach((a) => {
767
- const { rxdbNamedImports: p } = Q(s, a, n);
768
- p.forEach((l) => o.add(l));
769
- const { name: c } = a, d = c;
770
- a.namespace && a.namespace !== "public" ? r.addProperty({
771
- name: a.namespace,
772
- type: `{
773
- ${d}: typeof ${d};
774
- }`,
775
- docs: [a.displayName]
776
- }) : r.addProperty({
777
- name: d,
778
- type: `typeof ${d}`,
779
- docs: [a.displayName]
780
- });
781
- }), n.addImportDeclaration({
782
- namedImports: Array.from(o).sort(),
783
- isTypeOnly: !0,
784
- moduleSpecifier: "@aiao/rxdb"
785
- }), n.addImportDeclaration({
786
- namedImports: ["Observable"],
787
- isTypeOnly: !0,
788
- moduleSpecifier: "rxjs"
789
- }), n.addVariableStatement({
790
- declarationKind: w.Const,
791
- hasDeclareKeyword: !0,
792
- isExported: !0,
793
- declarations: [
794
- {
795
- name: "ENTITIES",
796
- type: "EntityType[]"
797
- }
798
- ]
799
- });
800
- }, U = (s) => {
801
- const { project: e, metadataSet: t } = s;
802
- let n = "";
803
- const i = /* @__PURE__ */ new Set(["Entity", "__decorateClass"]), r = (a) => {
804
- for (const p of t.values())
805
- if (p.relations && p.namespace === a.mappedNamespace && p.name === a.mappedEntity)
806
- return p.relations.find((c) => c.kind === m.MANY_TO_MANY && c.mappedProperty === a.name);
807
- };
808
- t.forEach((a) => {
809
- a.relations.forEach((p) => {
810
- if (p.kind === m.MANY_TO_MANY && !r(p))
811
- throw new Error("mapped relation not found");
812
- });
813
- }), t.forEach((a) => {
814
- const p = a.extends[0], { name: c } = a, d = c, l = A(a);
815
- p && i.add(p), a.properties.length && i.add("PropertyType"), a.relations.length && i.add("RelationKind"), n += `
816
- let ${d} = class ${p ? "extends " + p : ""} {};`, n += `
817
- ${d} = __decorateClass(
818
- [
819
- Entity(${l})
820
- ],
821
- ${d}
822
- );`;
823
- }), n = `import { ${Array.from(i).sort().join(", ")} } from '@aiao/rxdb';` + n;
824
- const o = Array.from(t.values()).map((a) => a.name).sort().join(", ");
825
- n += `
826
- const ENTITIES = [ ${o} ];`, n += `
827
- export { ENTITIES, ${o} };`, e.createSourceFile("index.js", n);
828
- };
829
- class L {
830
- project;
831
- metadataSet = /* @__PURE__ */ new Set();
832
- metadataMap = /* @__PURE__ */ new Map();
833
- config = {
834
- relationQueryDeep: 2
835
- };
836
- constructor(e) {
837
- Object.assign(this.config, e), this.config.relationQueryDeep < 1 && (this.config.relationQueryDeep = 1), this.project = new G();
838
- }
839
- /**
840
- * 添加实体配置
841
- * @param value 实体
842
- */
843
- addEntity(e) {
844
- let t = e;
845
- j(e) ? t = b(e) : t = D(e), this.metadataSet.add(t), this.metadataMap.set(`${t.namespace}_${t.name}`, t);
846
- }
847
- /**
848
- * 执行生成器
849
- */
850
- exec() {
851
- B(this), U(this);
852
- }
853
- }
1
+ import { R as t } from "./build_rxdb_client_lib-BPIw_COZ.js";
2
+ import { rxDBViteClientGenerator as n } from "./vite.js";
854
3
  export {
855
- L as RxDBClientGenerator,
856
- W as rxDBViteClientGenerator
4
+ t as RxDBClientGenerator,
5
+ n as rxDBViteClientGenerator
857
6
  };