@antelopejs/interface-database-decorators 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +42 -0
  3. package/dist/antelope.test.d.ts +2 -0
  4. package/dist/antelope.test.js +52 -0
  5. package/dist/antelope.test.js.map +1 -0
  6. package/dist/common.d.ts +22 -0
  7. package/dist/common.js +36 -0
  8. package/dist/common.js.map +1 -0
  9. package/dist/database.d.ts +2 -0
  10. package/dist/database.js +71 -0
  11. package/dist/database.js.map +1 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.js +24 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/model.d.ts +101 -0
  16. package/dist/model.js +161 -0
  17. package/dist/model.js.map +1 -0
  18. package/dist/modifiers/common.d.ts +87 -0
  19. package/dist/modifiers/common.js +370 -0
  20. package/dist/modifiers/common.js.map +1 -0
  21. package/dist/modifiers/encryption.d.ts +37 -0
  22. package/dist/modifiers/encryption.js +79 -0
  23. package/dist/modifiers/encryption.js.map +1 -0
  24. package/dist/modifiers/hash.d.ts +41 -0
  25. package/dist/modifiers/hash.js +54 -0
  26. package/dist/modifiers/hash.js.map +1 -0
  27. package/dist/modifiers/index.d.ts +4 -0
  28. package/dist/modifiers/index.js +21 -0
  29. package/dist/modifiers/index.js.map +1 -0
  30. package/dist/modifiers/localization.d.ts +43 -0
  31. package/dist/modifiers/localization.js +57 -0
  32. package/dist/modifiers/localization.js.map +1 -0
  33. package/dist/schema.d.ts +4 -0
  34. package/dist/schema.js +21 -0
  35. package/dist/schema.js.map +1 -0
  36. package/dist/table.d.ts +53 -0
  37. package/dist/table.js +63 -0
  38. package/dist/table.js.map +1 -0
  39. package/dist/tests/common.test.d.ts +1 -0
  40. package/dist/tests/common.test.js +52 -0
  41. package/dist/tests/common.test.js.map +1 -0
  42. package/dist/tests/database.test.d.ts +1 -0
  43. package/dist/tests/database.test.js +184 -0
  44. package/dist/tests/database.test.js.map +1 -0
  45. package/dist/tests/integration.test.d.ts +1 -0
  46. package/dist/tests/integration.test.js +399 -0
  47. package/dist/tests/integration.test.js.map +1 -0
  48. package/dist/tests/model.test.d.ts +1 -0
  49. package/dist/tests/model.test.js +186 -0
  50. package/dist/tests/model.test.js.map +1 -0
  51. package/dist/tests/modifiers/common.test.d.ts +1 -0
  52. package/dist/tests/modifiers/common.test.js +165 -0
  53. package/dist/tests/modifiers/common.test.js.map +1 -0
  54. package/dist/tests/modifiers/encryption.test.d.ts +1 -0
  55. package/dist/tests/modifiers/encryption.test.js +161 -0
  56. package/dist/tests/modifiers/encryption.test.js.map +1 -0
  57. package/dist/tests/modifiers/hash.test.d.ts +1 -0
  58. package/dist/tests/modifiers/hash.test.js +126 -0
  59. package/dist/tests/modifiers/hash.test.js.map +1 -0
  60. package/dist/tests/modifiers/localization.test.d.ts +1 -0
  61. package/dist/tests/modifiers/localization.test.js +175 -0
  62. package/dist/tests/modifiers/localization.test.js.map +1 -0
  63. package/dist/tests/schema.test.d.ts +1 -0
  64. package/dist/tests/schema.test.js +102 -0
  65. package/dist/tests/schema.test.js.map +1 -0
  66. package/dist/tests/table.test.d.ts +1 -0
  67. package/dist/tests/table.test.js +112 -0
  68. package/dist/tests/table.test.js.map +1 -0
  69. package/package.json +101 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright (c) 2025-present - AntelopeJS Team
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ ![Database decorators](.github/social-card.png)
2
+
3
+ # Interface Database Decorators
4
+
5
+ <div align="center">
6
+ <a href="./LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=for-the-badge&labelColor=000000"></a>
7
+ <a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
8
+ <a href="./docs/1.introduction.md"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
9
+ </div>
10
+
11
+ A structured framework for implementing database operations using TypeScript decorators. Interface Database Decorators offers a flexible, object-oriented approach to defining database tables, models, and operations with full type safety.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ ajs module imports add database-decorators@beta
17
+ ```
18
+
19
+ ## Documentation
20
+
21
+ Detailed documentation is available in the `docs` directory:
22
+
23
+ - [Introduction](./docs/1.introduction.md) - Overview and basic concepts
24
+ - [Table Definitions](./docs/2.table-definitions.md) - Defining database tables with decorators
25
+ - [Table Modifiers](./docs/3.table-modifiers.md) - Table modifiers for encryption, hashing, and localization
26
+ - [Data Models](./docs/4.data-models.md) - Creating and using data models
27
+ - [Parameter Decoration](./docs/5.parameter-decoration.md) - Parameter decorators for API controllers
28
+
29
+ ## Current Status
30
+
31
+ This is the development version (`beta`) of the Interface Database Decorators. It is currently in pre-release stage and may undergo changes before the final release. The interface is not considered stable for production use without understanding that breaking changes may occur.
32
+
33
+ ## Versions
34
+
35
+ | Version | Link | Status |
36
+ | ------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
37
+ | beta | [database-decorators@beta](https://github.com/AntelopeJS/database-decorators/tree/main/output/database-decorators/beta) | Waiting validation from community to go in v1 |
38
+ | 1 | _Not yet released_ | Planned stable release |
39
+
40
+ ## License
41
+
42
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@antelopejs/interface-core/config").ConfigInput;
2
+ export default _default;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_1 = require("@antelopejs/interface-core/config");
4
+ const mongodb_memory_server_core_1 = require("mongodb-memory-server-core");
5
+ let mongod;
6
+ exports.default = (0, config_1.defineConfig)({
7
+ name: "interface-database-decorators-test",
8
+ cacheFolder: ".antelope/cache",
9
+ modules: {
10
+ mongodb: {
11
+ source: {
12
+ type: "local",
13
+ path: "../mongodb",
14
+ installCommand: ["pnpm install", "npx tsc"],
15
+ },
16
+ },
17
+ database_decorators: {
18
+ source: {
19
+ type: "local",
20
+ path: "../database-decorators",
21
+ installCommand: ["pnpm install", "npx tsc"],
22
+ },
23
+ },
24
+ api: {
25
+ source: {
26
+ type: "local",
27
+ path: "../api",
28
+ installCommand: ["pnpm install", "npx tsc"],
29
+ },
30
+ config: {
31
+ servers: [{ protocol: "http", host: "127.0.0.1", port: 5010 }],
32
+ },
33
+ },
34
+ },
35
+ test: {
36
+ folder: "dist/tests",
37
+ async setup() {
38
+ mongod = await mongodb_memory_server_core_1.MongoMemoryServer.create();
39
+ return {
40
+ modules: {
41
+ mongodb: {
42
+ config: { url: mongod.getUri() },
43
+ },
44
+ },
45
+ };
46
+ },
47
+ async cleanup() {
48
+ await mongod.stop();
49
+ },
50
+ },
51
+ });
52
+ //# sourceMappingURL=antelope.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"antelope.test.js","sourceRoot":"","sources":["../src/antelope.test.ts"],"names":[],"mappings":";;AAAA,8DAAiE;AACjE,2EAA+D;AAE/D,IAAI,MAAyB,CAAC;AAE9B,kBAAe,IAAA,qBAAY,EAAC;IAC1B,IAAI,EAAE,oCAAoC;IAC1C,WAAW,EAAE,iBAAiB;IAC9B,OAAO,EAAE;QACP,OAAO,EAAE;YACP,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,YAAY;gBAClB,cAAc,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC;aAC5C;SACF;QACD,mBAAmB,EAAE;YACnB,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,wBAAwB;gBAC9B,cAAc,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC;aAC5C;SACF;QACD,GAAG,EAAE;YACH,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,QAAQ;gBACd,cAAc,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC;aAC5C;YACD,MAAM,EAAE;gBACN,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;aAC/D;SACF;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,YAAY;QACpB,KAAK,CAAC,KAAK;YACT,MAAM,GAAG,MAAM,8CAAiB,CAAC,MAAM,EAAE,CAAC;YAC1C,OAAO;gBACL,OAAO,EAAE;oBACP,OAAO,EAAE;wBACP,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE;qBACjC;iBACF;aACF,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,OAAO;YACX,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;KACF;CACF,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ export type Constructible<T = object, A extends unknown[] = unknown[]> = new (...args: A) => T;
2
+ export type DeepPartial<T> = {
3
+ [K in keyof T]?: T[K] extends Array<infer U1> ? Array<DeepPartial<U1>> : T[K] extends ReadonlyArray<infer U2> ? ReadonlyArray<DeepPartial<U2>> : T[K] extends object ? DeepPartial<T[K]> : T[K];
4
+ };
5
+ export type DatumGeneratorOutput = Record<string, unknown> | Array<Record<string, unknown>> | undefined;
6
+ export type DatumGenerator = (tableClass: Constructible) => DatumGeneratorOutput | Promise<DatumGeneratorOutput>;
7
+ export interface MetadataClass<TMetadata> extends Constructible<TMetadata> {
8
+ key: symbol;
9
+ }
10
+ /**
11
+ * Table class Metadata.
12
+ */
13
+ export declare class DatumStaticMetadata {
14
+ static key: symbol;
15
+ tableName?: string;
16
+ schemaName?: string;
17
+ readonly indexes: Record<string, Array<string>>;
18
+ primary: string;
19
+ generator?: DatumGenerator;
20
+ addIndex(key: string, group: string): void;
21
+ }
22
+ export declare function getMetadata<TMetadata, TTarget extends object>(target: TTarget, metadataClass: MetadataClass<TMetadata>, inherit?: boolean): TMetadata;
package/dist/common.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatumStaticMetadata = void 0;
4
+ exports.getMetadata = getMetadata;
5
+ /**
6
+ * Table class Metadata.
7
+ */
8
+ class DatumStaticMetadata {
9
+ static key = Symbol();
10
+ tableName;
11
+ schemaName;
12
+ indexes = {};
13
+ primary = "_id";
14
+ generator;
15
+ addIndex(key, group) {
16
+ if (!(group in this.indexes)) {
17
+ this.indexes[group] = [];
18
+ }
19
+ this.indexes[group].push(key);
20
+ }
21
+ }
22
+ exports.DatumStaticMetadata = DatumStaticMetadata;
23
+ function getMetadata(target, metadataClass, inherit = true) {
24
+ const existingMetadata = Reflect.getOwnMetadata(metadataClass.key, target);
25
+ if (existingMetadata) {
26
+ return existingMetadata;
27
+ }
28
+ const prototype = Object.getPrototypeOf(target);
29
+ const inheritedMetadata = inherit && prototype
30
+ ? Reflect.getOwnMetadata(metadataClass.key, prototype)
31
+ : undefined;
32
+ const metadata = inheritedMetadata ?? new metadataClass(target);
33
+ Reflect.defineMetadata(metadataClass.key, metadata, target);
34
+ return metadata;
35
+ }
36
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;;AA8CA,kCAsBC;AA1CD;;GAEG;AACH,MAAa,mBAAmB;IACvB,MAAM,CAAC,GAAG,GAAG,MAAM,EAAE,CAAC;IAEtB,SAAS,CAAU;IACnB,UAAU,CAAU;IACX,OAAO,GAAkC,EAAE,CAAC;IACrD,OAAO,GAAW,KAAK,CAAC;IACxB,SAAS,CAAkB;IAElC,QAAQ,CAAC,GAAW,EAAE,KAAa;QACjC,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;;AAdH,kDAeC;AAED,SAAgB,WAAW,CACzB,MAAe,EACf,aAAuC,EACvC,UAAmB,IAAI;IAEvB,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAE5D,CAAC;IACd,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAmB,CAAC;IAClE,MAAM,iBAAiB,GACrB,OAAO,IAAI,SAAS;QAClB,CAAC,CAAE,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,CAEtC;QAChB,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,QAAQ,GAAG,iBAAiB,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAChE,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5D,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type SchemaOptions } from "@antelopejs/interface-database";
2
+ export declare function CreateDatabaseSchemaInstance(schemaId: string, instanceId?: string, options?: SchemaOptions): Promise<void>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CreateDatabaseSchemaInstance = CreateDatabaseSchemaInstance;
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const interface_database_1 = require("@antelopejs/interface-database");
9
+ const common_1 = require("./common");
10
+ const common_2 = require("./modifiers/common");
11
+ const schema_1 = require("./schema");
12
+ async function CreateDatabaseSchemaInstance(schemaId, instanceId, options) {
13
+ const tables = (0, schema_1.getTablesForSchema)(schemaId);
14
+ (0, node_assert_1.default)(tables, `No tables registered for schema '${schemaId}'`);
15
+ const definition = buildSchemaDefinition(tables);
16
+ const schema = new interface_database_1.Schema(schemaId, definition, options);
17
+ await schema.createInstance(instanceId);
18
+ await insertAllFixtureData(schema, instanceId, tables);
19
+ }
20
+ function buildSchemaDefinition(tables) {
21
+ const definition = {};
22
+ for (const [tableName, tableClass] of Object.entries(tables)) {
23
+ const metadata = (0, common_1.getMetadata)(tableClass, common_1.DatumStaticMetadata);
24
+ const indexes = {};
25
+ for (const [group, fields] of Object.entries(metadata.indexes)) {
26
+ indexes[group] = {
27
+ fields: fields.length === 1 && fields[0] === group ? undefined : fields,
28
+ };
29
+ }
30
+ definition[tableName] = { fields: {}, indexes };
31
+ }
32
+ return definition;
33
+ }
34
+ async function insertAllFixtureData(schema, instanceId, tables) {
35
+ await Promise.all(Object.entries(tables).map(([tableName, tableClass]) => {
36
+ const metadata = (0, common_1.getMetadata)(tableClass, common_1.DatumStaticMetadata);
37
+ return insertFixtureData(schema, instanceId, tableName, tableClass, metadata.generator);
38
+ }));
39
+ }
40
+ async function insertFixtureData(schema, instanceId, tableName, tableClass, generator) {
41
+ if (!generator) {
42
+ return;
43
+ }
44
+ const count = await schema.instance(instanceId).table(tableName).count();
45
+ if (count > 0) {
46
+ return;
47
+ }
48
+ const fixtureData = await generator(tableClass);
49
+ const rows = toFixtureRows(fixtureData, tableClass);
50
+ if (rows.length === 0) {
51
+ return;
52
+ }
53
+ const payload = rows.length === 1 ? rows[0] : rows;
54
+ await schema.instance(instanceId).table(tableName).insert(payload);
55
+ }
56
+ function toFixtureRows(fixtureData, tableClass) {
57
+ const entries = fixtureData
58
+ ? Array.isArray(fixtureData)
59
+ ? fixtureData
60
+ : [fixtureData]
61
+ : [];
62
+ return entries.filter(isTableEntry).map((entry) => {
63
+ const instance = (0, common_2.fromPlainData)(entry, tableClass);
64
+ (0, common_2.triggerEvent)(instance, "insert");
65
+ return (0, common_2.toDatabase)(instance);
66
+ });
67
+ }
68
+ function isTableEntry(value) {
69
+ return typeof value === "object" && value !== null;
70
+ }
71
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;;;AAiBA,o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CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,aAAa,CACpB,WAAiC,EACjC,UAAwB;IAExB,MAAM,OAAO,GAAG,WAAW;QACzB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;YAC1B,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,CAAC,WAAW,CAAC;QACjB,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAChD,MAAM,QAAQ,GAAG,IAAA,sBAAa,EAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAA,qBAAY,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjC,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAe,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC"}
@@ -0,0 +1,7 @@
1
+ import "reflect-metadata";
2
+ export * from "./common";
3
+ export * from "./database";
4
+ export * from "./model";
5
+ export * from "./modifiers";
6
+ export * from "./schema";
7
+ export * from "./table";
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("reflect-metadata");
18
+ __exportStar(require("./common"), exports);
19
+ __exportStar(require("./database"), exports);
20
+ __exportStar(require("./model"), exports);
21
+ __exportStar(require("./modifiers"), exports);
22
+ __exportStar(require("./schema"), exports);
23
+ __exportStar(require("./table"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4BAA0B;AAE1B,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB"}
@@ -0,0 +1,101 @@
1
+ import { type RequestContext } from "@antelopejs/interface-api";
2
+ import { type Class } from "@antelopejs/interface-core/decorators";
3
+ import type * as DatabaseDev from "@antelopejs/interface-database";
4
+ import { type Constructible, type DeepPartial } from "./common";
5
+ export type DataModel<T = any> = {
6
+ readonly schemaName: string;
7
+ new (database: DatabaseDev.SchemaInstance<any>): {
8
+ readonly database: DatabaseDev.SchemaInstance<any>;
9
+ readonly table: DatabaseDev.Table<T>;
10
+ };
11
+ fromDatabase(obj: any): T | undefined;
12
+ fromPlainData(obj: any): T;
13
+ };
14
+ /**
15
+ * Utility Class factory to create a basic Data Model with 1 table.
16
+ *
17
+ * @param dataType Database Table class
18
+ * @param tableName Table name in Database
19
+ */
20
+ export declare function BasicDataModel<T extends object>(dataType: Constructible<T>, tableName?: string): {
21
+ new (database: DatabaseDev.SchemaInstance<any>): {
22
+ /**
23
+ * AQL Table reference.
24
+ */
25
+ readonly table: DatabaseDev.Table<T>;
26
+ readonly database: DatabaseDev.SchemaInstance<any>;
27
+ /**
28
+ * Get a single element from the table using its primary key.
29
+ *
30
+ * @param id Primary key value
31
+ * @returns Table class instance
32
+ */
33
+ get(id: string): PromiseLike<T | undefined>;
34
+ /**
35
+ * Get multiple elements from the table using a given index.
36
+ *
37
+ * @param index Index name
38
+ * @param keys Index value(s)
39
+ * @returns Array of Table class instances.
40
+ */
41
+ getBy(index: keyof T, ...keys: any[]): PromiseLike<T[]>;
42
+ /**
43
+ * Get all the elements from the table.
44
+ *
45
+ * @returns Array of Table class instances.
46
+ */
47
+ getAll(): PromiseLike<T[]>;
48
+ /**
49
+ * Insert some data into the table.
50
+ *
51
+ * @param obj Table class instance or plain data
52
+ * @param options Insert options
53
+ * @returns Insert result
54
+ */
55
+ insert(obj: DeepPartial<T> | Array<DeepPartial<T>>): Promise<string[]>;
56
+ /**
57
+ * Updates a single element in the table.
58
+ *
59
+ * @param id Primary key value
60
+ * @param obj Table class instance or plain data
61
+ * @param options Update options
62
+ * @returns Update result
63
+ */
64
+ update(id: string, obj: DeepPartial<T>): Promise<number>;
65
+ update(obj: DeepPartial<T>): Promise<number>;
66
+ /**
67
+ * Delete an element from the table.
68
+ *
69
+ * @param id Primary key value
70
+ * @returns Delete result
71
+ */
72
+ delete(id: string): Promise<number>;
73
+ };
74
+ readonly schemaName: string;
75
+ /**
76
+ * Converts some plain data into an instance of the Table class.
77
+ *
78
+ * @param obj Plain data object containing the table fields
79
+ * @returns Table class instance
80
+ */
81
+ fromPlainData(obj: any): T;
82
+ /**
83
+ * Converts an object acquired from the database into a Table class instance.
84
+ *
85
+ * @param obj Object resulting from a database get
86
+ * @returns Table class instance
87
+ */
88
+ fromDatabase(obj: any): T | undefined;
89
+ /**
90
+ * Converts a Table class instance into an object fit to be inserted in the database.
91
+ *
92
+ * @param obj Table class instance
93
+ * @returns Database-ready data
94
+ */
95
+ toDatabase(obj: any): Record<string, any>;
96
+ };
97
+ export declare function GetModel<M extends InstanceType<DataModel>>(cl: DataModel & Class<M>, instanceId?: string): M;
98
+ export declare const Model: (cl: DataModel<any> & Class<{
99
+ readonly database: DatabaseDev.SchemaInstance<any>;
100
+ readonly table: DatabaseDev.Table<any>;
101
+ }>, instanceIdOrCallback?: string | ((ctx: RequestContext) => string | undefined) | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;