@antelopejs/interface-database 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 (90) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +45 -0
  3. package/dist/antelope.test.d.ts +2 -0
  4. package/dist/antelope.test.js +35 -0
  5. package/dist/antelope.test.js.map +1 -0
  6. package/dist/common.d.ts +58 -0
  7. package/dist/common.js +44 -0
  8. package/dist/common.js.map +1 -0
  9. package/dist/datum.d.ts +55 -0
  10. package/dist/datum.js +70 -0
  11. package/dist/datum.js.map +1 -0
  12. package/dist/index.d.ts +6 -0
  13. package/dist/index.js +19 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/query.d.ts +15 -0
  16. package/dist/query.js +79 -0
  17. package/dist/query.js.map +1 -0
  18. package/dist/schema.d.ts +102 -0
  19. package/dist/schema.js +88 -0
  20. package/dist/schema.js.map +1 -0
  21. package/dist/selection.d.ts +99 -0
  22. package/dist/selection.js +119 -0
  23. package/dist/selection.js.map +1 -0
  24. package/dist/stream.d.ts +185 -0
  25. package/dist/stream.js +221 -0
  26. package/dist/stream.js.map +1 -0
  27. package/dist/tests/aggregation_operations.test.d.ts +1 -0
  28. package/dist/tests/aggregation_operations.test.js +157 -0
  29. package/dist/tests/aggregation_operations.test.js.map +1 -0
  30. package/dist/tests/basic_operations.test.d.ts +1 -0
  31. package/dist/tests/basic_operations.test.js +216 -0
  32. package/dist/tests/basic_operations.test.js.map +1 -0
  33. package/dist/tests/between_operations.test.d.ts +1 -0
  34. package/dist/tests/between_operations.test.js +76 -0
  35. package/dist/tests/between_operations.test.js.map +1 -0
  36. package/dist/tests/change_feeds.test.d.ts +1 -0
  37. package/dist/tests/change_feeds.test.js +90 -0
  38. package/dist/tests/change_feeds.test.js.map +1 -0
  39. package/dist/tests/datasets/index.d.ts +4 -0
  40. package/dist/tests/datasets/index.js +22 -0
  41. package/dist/tests/datasets/index.js.map +1 -0
  42. package/dist/tests/datasets/orders.d.ts +62 -0
  43. package/dist/tests/datasets/orders.js +158 -0
  44. package/dist/tests/datasets/orders.js.map +1 -0
  45. package/dist/tests/datasets/products.d.ts +48 -0
  46. package/dist/tests/datasets/products.js +139 -0
  47. package/dist/tests/datasets/products.js.map +1 -0
  48. package/dist/tests/datasets/users.d.ts +50 -0
  49. package/dist/tests/datasets/users.js +145 -0
  50. package/dist/tests/datasets/users.js.map +1 -0
  51. package/dist/tests/datasets/vehicles.d.ts +23 -0
  52. package/dist/tests/datasets/vehicles.js +41 -0
  53. package/dist/tests/datasets/vehicles.js.map +1 -0
  54. package/dist/tests/date_operations.test.d.ts +1 -0
  55. package/dist/tests/date_operations.test.js +119 -0
  56. package/dist/tests/date_operations.test.js.map +1 -0
  57. package/dist/tests/do_operations.test.d.ts +1 -0
  58. package/dist/tests/do_operations.test.js +209 -0
  59. package/dist/tests/do_operations.test.js.map +1 -0
  60. package/dist/tests/filters.test.d.ts +1 -0
  61. package/dist/tests/filters.test.js +158 -0
  62. package/dist/tests/filters.test.js.map +1 -0
  63. package/dist/tests/group_operations.test.d.ts +1 -0
  64. package/dist/tests/group_operations.test.js +190 -0
  65. package/dist/tests/group_operations.test.js.map +1 -0
  66. package/dist/tests/instance_modes.test.d.ts +1 -0
  67. package/dist/tests/instance_modes.test.js +192 -0
  68. package/dist/tests/instance_modes.test.js.map +1 -0
  69. package/dist/tests/joins.test.d.ts +1 -0
  70. package/dist/tests/joins.test.js +163 -0
  71. package/dist/tests/joins.test.js.map +1 -0
  72. package/dist/tests/lookup_operations.test.d.ts +1 -0
  73. package/dist/tests/lookup_operations.test.js +103 -0
  74. package/dist/tests/lookup_operations.test.js.map +1 -0
  75. package/dist/tests/merge_operations.test.d.ts +1 -0
  76. package/dist/tests/merge_operations.test.js +216 -0
  77. package/dist/tests/merge_operations.test.js.map +1 -0
  78. package/dist/tests/row_level_operations.test.d.ts +1 -0
  79. package/dist/tests/row_level_operations.test.js +467 -0
  80. package/dist/tests/row_level_operations.test.js.map +1 -0
  81. package/dist/tests/sorting.test.d.ts +1 -0
  82. package/dist/tests/sorting.test.js +161 -0
  83. package/dist/tests/sorting.test.js.map +1 -0
  84. package/dist/tests/union_operations.test.d.ts +1 -0
  85. package/dist/tests/union_operations.test.js +129 -0
  86. package/dist/tests/union_operations.test.js.map +1 -0
  87. package/dist/valueproxy.d.ts +415 -0
  88. package/dist/valueproxy.js +562 -0
  89. package/dist/valueproxy.js.map +1 -0
  90. package/package.json +88 -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,45 @@
1
+ ![Database](.github/social-card.png)
2
+
3
+ # Interface Database
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/index.md"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
9
+ </div>
10
+
11
+ A database-agnostic query interface that provides consistent operations across different database implementations. Interface Database brings AQL (Antelope Query Language) to your projects, enabling you to write database code that works with multiple database backends.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ ajs module imports add database@beta
17
+ ```
18
+
19
+ ## Documentation
20
+
21
+ Detailed documentation is available in the `docs` directory:
22
+
23
+ - [Index](./docs/index.md) - Overview and documentation structure
24
+ - [Query Types](./docs/1.query_types/1.index.md) - Information about table, selection, and other query types
25
+ - [Operations](./docs/2.operations/1.index.md) - Database, table, and CRUD operations
26
+ - [Results](./docs/3.results/1.index.md) - Result types and handling
27
+
28
+ ## Inspiration
29
+
30
+ Interface Database is heavily inspired by [ReQL](https://rethinkdb.com/docs/introduction-to-reql/), the query language of [RethinkDB](https://rethinkdb.com/). As huge fans of ReQL's elegant chainable API and its ability to express complex queries in a native javascript like language format, we've adopted many of its design principles while expanding the concept to work with multiple database backends.
31
+
32
+ ## Current Status
33
+
34
+ This is the development version (`beta`) of the Interface Database. 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.
35
+
36
+ ## Versions
37
+
38
+ | Version | Link | Status |
39
+ | ------- | ----------------------------------------------------------------------------------------------- | --------------------------------------------- |
40
+ | beta | [database@beta](https://github.com/AntelopeJS/rethinkdb/tree/main/output/database/beta) | Waiting validation from community to go in v1 |
41
+ | 1 | _Not yet released_ | Planned stable release |
42
+
43
+ ## License
44
+
45
+ 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,35 @@
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-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
+ },
18
+ test: {
19
+ folder: "dist/tests",
20
+ async setup() {
21
+ mongod = await mongodb_memory_server_core_1.MongoMemoryReplSet.create({ replSet: { count: 1 } });
22
+ return {
23
+ modules: {
24
+ mongodb: {
25
+ config: { url: mongod.getUri() },
26
+ },
27
+ },
28
+ };
29
+ },
30
+ async cleanup() {
31
+ await mongod.stop();
32
+ },
33
+ },
34
+ });
35
+ //# 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,2EAAgE;AAEhE,IAAI,MAA0B,CAAC;AAE/B,kBAAe,IAAA,qBAAY,EAAC;IAC1B,IAAI,EAAE,yBAAyB;IAC/B,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;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,YAAY;QACpB,KAAK,CAAC,KAAK;YACT,MAAM,GAAG,MAAM,+CAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACpE,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,58 @@
1
+ import type { Class } from "@antelopejs/interface-core/decorators";
2
+ import type { Datum } from "./datum";
3
+ import type { Query } from "./query";
4
+ import type { ValueProxy, ValueProxyOrValue } from "./valueproxy";
5
+ /**
6
+ * Recursive Partial generic type
7
+ */
8
+ export type DeepPartial<T> = {
9
+ [K in keyof T]?: T[K] extends Array<infer U1> ? Array<DeepPartial<U1>> : T[K] extends ReadonlyArray<infer U2> ? ReadonlyArray<DeepPartial<U2>> : DeepPartial<T[K]>;
10
+ };
11
+ /**
12
+ * Change event
13
+ */
14
+ export interface Changes<T> {
15
+ /**
16
+ * The type of change that occured
17
+ *
18
+ * Possible values: added, removed, modified
19
+ */
20
+ changeType: "added" | "removed" | "modified";
21
+ /**
22
+ * Value prior to the change
23
+ */
24
+ oldValue?: T;
25
+ /**
26
+ * New value after the change
27
+ */
28
+ newValue?: T;
29
+ }
30
+ export interface InsertOptions {
31
+ conflict?: "update" | "replace";
32
+ }
33
+ export interface QueryStage {
34
+ stage: string;
35
+ options?: any;
36
+ args: any[];
37
+ }
38
+ export declare function QueryStage(stage: string, options?: any, ...args: any[]): {
39
+ stage: string;
40
+ options: any;
41
+ args: any[];
42
+ };
43
+ export declare class StagedObject {
44
+ protected readonly stages: QueryStage[];
45
+ constructor(newStage: QueryStage, previous?: StagedObject);
46
+ build(): QueryStage[];
47
+ protected stage(type: undefined, stage: string, options?: any, ...args: any[]): this;
48
+ protected stage<T extends StagedObject>(type: Class<T>, stage: string, options?: any, ...args: any[]): T;
49
+ private static nextargid;
50
+ protected callfunc<T extends StagedObject[]>(func: (...args: T) => any, ...args: (typeof StagedObject)[]): QueryStage;
51
+ }
52
+ export type Value<T> = Datum<T> | ValueProxyOrValue<T>;
53
+ type UnknownObject = Record<keyof any, unknown>;
54
+ type ExtractTypeObject<T extends UnknownObject> = T extends infer O ? {
55
+ [K in keyof O]: ExtractType<O[K]>;
56
+ } : never;
57
+ export type ExtractType<T> = T extends ValueProxy<infer A> ? A : T extends Query<infer A> ? A : T extends UnknownObject ? ExtractTypeObject<T> : T extends Array<infer A> ? Array<ExtractType<A>> : T;
58
+ export {};
package/dist/common.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StagedObject = void 0;
4
+ exports.QueryStage = QueryStage;
5
+ function QueryStage(stage, options, ...args) {
6
+ return {
7
+ stage,
8
+ options,
9
+ args,
10
+ };
11
+ }
12
+ class StagedObject {
13
+ stages;
14
+ constructor(newStage, previous) {
15
+ this.stages = previous ? [...previous.stages, newStage] : [newStage];
16
+ }
17
+ //@internal
18
+ build() {
19
+ return this.stages;
20
+ }
21
+ stage(type, stage, options, ...args) {
22
+ return new (type ?? this.constructor)({
23
+ stage,
24
+ options,
25
+ args,
26
+ }, this);
27
+ }
28
+ static nextargid = 0;
29
+ callfunc(func, ...args) {
30
+ const argNumbers = [];
31
+ const argValues = [];
32
+ for (let i = 0; i < args.length; ++i) {
33
+ const id = StagedObject.nextargid++;
34
+ argNumbers[i] = id;
35
+ argValues[i] = new args[i](QueryStage("arg", undefined, id));
36
+ }
37
+ return {
38
+ stage: "func", // TODO: using the query stage structure here doesnt make any sense
39
+ args: [argNumbers, func(...argValues)],
40
+ };
41
+ }
42
+ }
43
+ exports.StagedObject = StagedObject;
44
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;;AAgDA,gCAMC;AAND,SAAgB,UAAU,CAAC,KAAa,EAAE,OAAa,EAAE,GAAG,IAAW;IACrE,OAAO;QACL,KAAK;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC;AAED,MAAa,YAAY;IACJ,MAAM,CAAe;IAExC,YAAmB,QAAoB,EAAE,QAAuB;QAC9D,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACvE,CAAC;IAED,WAAW;IACJ,KAAK;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAcS,KAAK,CACb,IAA0B,EAC1B,KAAa,EACb,OAAa,EACb,GAAG,IAAW;QAEd,OAAO,IAAI,CAAC,IAAI,IAAK,IAAI,CAAC,WAAmC,CAAC,CAC5D;YACE,KAAK;YACL,OAAO;YACP,IAAI;SACL,EACD,IAAI,CACL,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;IACnB,QAAQ,CAChB,IAAyB,EACzB,GAAG,IAA6B;QAEhC,MAAM,UAAU,GAAa,EAAE,CAAC;QAChC,MAAM,SAAS,GAAmB,EAAE,CAAC;QACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACrC,MAAM,EAAE,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC;YACpC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;YACnB,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO;YACL,KAAK,EAAE,MAAM,EAAE,mEAAmE;YAClF,IAAI,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,GAAI,SAAe,CAAC,CAAC;SAC9C,CAAC;IACJ,CAAC;;AAxDH,oCAyDC"}
@@ -0,0 +1,55 @@
1
+ import type { ExtractType, Value } from "./common";
2
+ import { Query } from "./query";
3
+ import type { Selection } from "./selection";
4
+ import { ValueProxy } from "./valueproxy";
5
+ export declare class Datum<T> extends Query<T> {
6
+ /**
7
+ * Changes the type of this datum.
8
+ * This does not actually perform any conversion, it only changes the typescript type.
9
+ *
10
+ * @returns Same datum with a different type
11
+ */
12
+ cast<U>(): Datum<U>;
13
+ /**
14
+ * Indexes the datum.
15
+ *
16
+ * TODO: Better name?
17
+ * TODO: typing for compound keys (a.b.c)
18
+ *
19
+ * @param key Field name
20
+ * @param def Default value
21
+ * @returns New datum with the value
22
+ */
23
+ key<K extends keyof NonNullable<T>, U = undefined>(key: K, def?: U): Datum<U extends undefined ? NonNullable<T>[K] : U | NonNullable<NonNullable<T>[K]>>;
24
+ /**
25
+ * Defaults the datum to a given value if it is null.
26
+ *
27
+ * @param value Default value
28
+ * @returns Current datum or given value
29
+ */
30
+ default<U>(val: Value<U>): Datum<U | Exclude<T, null | undefined>>;
31
+ /**
32
+ * Run a mapping function on the datum.
33
+ *
34
+ * @param mapper Mapping function
35
+ * @returns New datum with the result of the mapper
36
+ */
37
+ do<U>(mapper: (val: ValueProxy<T>) => U): Datum<ExtractType<U>>;
38
+ /**
39
+ * Perform a foreign key lookup
40
+ *
41
+ * @param other Other table
42
+ * @param localKey Key in local object
43
+ * @param otherKey Key in other table
44
+ */
45
+ lookup<U = any, TK extends keyof T = keyof T>(other: Selection<U>, localKey: TK, otherKey: keyof U): Datum<Omit<T, TK> & Record<TK, T[TK] extends any[] ? U[] : U>>;
46
+ /**
47
+ * Plucks fields from the documents.
48
+ *
49
+ * TODO: Better typing
50
+ *
51
+ * @param fields Fields to keep
52
+ * @returns New datum
53
+ */
54
+ pluck(...fields: string[]): Datum<Partial<T>>;
55
+ }
package/dist/datum.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Datum = void 0;
4
+ const query_1 = require("./query");
5
+ const valueproxy_1 = require("./valueproxy");
6
+ class Datum extends query_1.Query {
7
+ /**
8
+ * Changes the type of this datum.
9
+ * This does not actually perform any conversion, it only changes the typescript type.
10
+ *
11
+ * @returns Same datum with a different type
12
+ */
13
+ cast() {
14
+ return this;
15
+ }
16
+ /**
17
+ * Indexes the datum.
18
+ *
19
+ * TODO: Better name?
20
+ * TODO: typing for compound keys (a.b.c)
21
+ *
22
+ * @param key Field name
23
+ * @param def Default value
24
+ * @returns New datum with the value
25
+ */
26
+ key(key, def) {
27
+ return this.stage((Datum), "key", undefined, key, def);
28
+ }
29
+ /**
30
+ * Defaults the datum to a given value if it is null.
31
+ *
32
+ * @param value Default value
33
+ * @returns Current datum or given value
34
+ */
35
+ default(val) {
36
+ return this.stage((Datum), "default", undefined, val);
37
+ }
38
+ /**
39
+ * Run a mapping function on the datum.
40
+ *
41
+ * @param mapper Mapping function
42
+ * @returns New datum with the result of the mapper
43
+ */
44
+ do(mapper) {
45
+ return this.stage((Datum), "map", undefined, this.callfunc(mapper, (valueproxy_1.ValueProxy)));
46
+ }
47
+ /**
48
+ * Perform a foreign key lookup
49
+ *
50
+ * @param other Other table
51
+ * @param localKey Key in local object
52
+ * @param otherKey Key in other table
53
+ */
54
+ lookup(other, localKey, otherKey) {
55
+ return this.stage((Datum), "lookup", { localKey, otherKey }, other);
56
+ }
57
+ /**
58
+ * Plucks fields from the documents.
59
+ *
60
+ * TODO: Better typing
61
+ *
62
+ * @param fields Fields to keep
63
+ * @returns New datum
64
+ */
65
+ pluck(...fields) {
66
+ return this.stage((Datum), "pluck", undefined, fields);
67
+ }
68
+ }
69
+ exports.Datum = Datum;
70
+ //# sourceMappingURL=datum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datum.js","sourceRoot":"","sources":["../src/datum.ts"],"names":[],"mappings":";;;AACA,mCAAgC;AAEhC,6CAA0C;AAE1C,MAAa,KAAS,SAAQ,aAAQ;IACpC;;;;;OAKG;IACI,IAAI;QACT,OAAO,IAA2B,CAAC;IACrC,CAAC;IAED;;;;;;;;;OASG;IACI,GAAG,CAAgD,GAAM,EAAE,GAAO;QACvE,OAAO,IAAI,CAAC,KAAK,CACf,CAAA,KAIC,CAAA,EACD,KAAK,EACL,SAAS,EACT,GAAG,EACH,GAAG,CACJ,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAI,GAAa;QAC7B,OAAO,IAAI,CAAC,KAAK,CACf,CAAA,KAAuC,CAAA,EACvC,SAAS,EACT,SAAS,EACT,GAAG,CACJ,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,EAAE,CAAI,MAAiC;QAC5C,OAAO,IAAI,CAAC,KAAK,CACf,CAAA,KAAqB,CAAA,EACrB,KAAK,EACL,SAAS,EACT,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA,uBAAa,CAAA,CAAC,CACrC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CACX,KAAmB,EACnB,QAAY,EACZ,QAAiB;QAEjB,OAAO,IAAI,CAAC,KAAK,CACf,CAAA,KAA8D,CAAA,EAC9D,QAAQ,EACR,EAAE,QAAQ,EAAE,QAAQ,EAAE,EACtB,KAAK,CACN,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,MAAgB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA,KAAiB,CAAA,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;CACF;AAhGD,sBAgGC"}
@@ -0,0 +1,6 @@
1
+ export { Datum } from "./datum";
2
+ export { Query } from "./query";
3
+ export { Schema, SchemaDefinition, SchemaInstance, SchemaOptions, } from "./schema";
4
+ export { Selection, SingleSelection, Table } from "./selection";
5
+ export { Stream } from "./stream";
6
+ export { ValueProxy, ValueProxyOrValue } from "./valueproxy";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueProxy = exports.Stream = exports.Table = exports.SingleSelection = exports.Selection = exports.SchemaInstance = exports.Schema = exports.Query = exports.Datum = void 0;
4
+ var datum_1 = require("./datum");
5
+ Object.defineProperty(exports, "Datum", { enumerable: true, get: function () { return datum_1.Datum; } });
6
+ var query_1 = require("./query");
7
+ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
8
+ var schema_1 = require("./schema");
9
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return schema_1.Schema; } });
10
+ Object.defineProperty(exports, "SchemaInstance", { enumerable: true, get: function () { return schema_1.SchemaInstance; } });
11
+ var selection_1 = require("./selection");
12
+ Object.defineProperty(exports, "Selection", { enumerable: true, get: function () { return selection_1.Selection; } });
13
+ Object.defineProperty(exports, "SingleSelection", { enumerable: true, get: function () { return selection_1.SingleSelection; } });
14
+ Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return selection_1.Table; } });
15
+ var stream_1 = require("./stream");
16
+ Object.defineProperty(exports, "Stream", { enumerable: true, get: function () { return stream_1.Stream; } });
17
+ var valueproxy_1 = require("./valueproxy");
18
+ Object.defineProperty(exports, "ValueProxy", { enumerable: true, get: function () { return valueproxy_1.ValueProxy; } });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAKkB;AAJhB,gGAAA,MAAM,OAAA;AAEN,wGAAA,cAAc,OAAA;AAGhB,yCAAgE;AAAvD,sGAAA,SAAS,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,kGAAA,KAAK,OAAA;AAC1C,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,2CAA6D;AAApD,wGAAA,UAAU,OAAA"}
@@ -0,0 +1,15 @@
1
+ import { StagedObject } from "./common";
2
+ export declare const RunQuery: (query: import("./common").QueryStage[]) => Promise<any>;
3
+ export declare const ReadCursor: (reqId: number, stages: import("./common").QueryStage[]) => Promise<IteratorResult<any, void>>;
4
+ export declare const CloseCursor: (reqId: number) => Promise<void>;
5
+ export declare class Query<T> extends StagedObject implements PromiseLike<T> {
6
+ /**
7
+ * Execute the query
8
+ *
9
+ * @returns Query result
10
+ */
11
+ run(): Promise<T>;
12
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
13
+ cursor(): AsyncGenerator<T extends Array<infer T1> ? T1 : T, void, unknown>;
14
+ [Symbol.asyncIterator](): AsyncGenerator<T extends (infer T1)[] ? T1 : T, void, unknown>;
15
+ }
package/dist/query.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Query = exports.CloseCursor = exports.ReadCursor = exports.RunQuery = void 0;
4
+ const interface_core_1 = require("@antelopejs/interface-core");
5
+ const common_1 = require("./common");
6
+ //@internal
7
+ exports.RunQuery = (0, interface_core_1.InterfaceFunction)();
8
+ //@internal
9
+ exports.ReadCursor = (0, interface_core_1.InterfaceFunction)();
10
+ //@internal
11
+ exports.CloseCursor = (0, interface_core_1.InterfaceFunction)();
12
+ let nextReqId = 0;
13
+ class IterableCursor {
14
+ stages;
15
+ reqId;
16
+ resolve;
17
+ reject;
18
+ constructor(stages) {
19
+ this.stages = stages;
20
+ this.reqId = nextReqId++;
21
+ }
22
+ next() {
23
+ return new Promise((resolve, reject) => {
24
+ this.resolve = resolve;
25
+ this.reject = reject;
26
+ void (0, exports.ReadCursor)(this.reqId, this.stages)
27
+ .then(resolve, reject)
28
+ .finally(() => {
29
+ this.resolve = undefined;
30
+ this.reject = undefined;
31
+ });
32
+ });
33
+ }
34
+ async return() {
35
+ const res = { done: true, value: undefined };
36
+ if (this.resolve) {
37
+ this.resolve(res);
38
+ this.resolve = undefined;
39
+ this.reject = undefined;
40
+ }
41
+ await (0, exports.CloseCursor)(this.reqId);
42
+ return res;
43
+ }
44
+ async throw(e) {
45
+ if (this.reject) {
46
+ this.reject(e);
47
+ this.resolve = undefined;
48
+ this.reject = undefined;
49
+ }
50
+ await (0, exports.CloseCursor)(this.reqId);
51
+ return { done: true, value: undefined };
52
+ }
53
+ [Symbol.asyncIterator]() {
54
+ return this;
55
+ }
56
+ }
57
+ class Query extends common_1.StagedObject {
58
+ /**
59
+ * Execute the query
60
+ *
61
+ * @returns Query result
62
+ */
63
+ run() {
64
+ return (0, exports.RunQuery)(this.stages);
65
+ }
66
+ // biome-ignore lint/suspicious/noThenProperty: PromiseLike requires a then method.
67
+ then(onfulfilled, onrejected) {
68
+ return this.run().then(onfulfilled, onrejected);
69
+ }
70
+ //TODO: core interface function for async generators
71
+ cursor() {
72
+ return new IterableCursor(this.stages);
73
+ }
74
+ [Symbol.asyncIterator]() {
75
+ return this.cursor();
76
+ }
77
+ }
78
+ exports.Query = Query;
79
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAC/D,qCAAwC;AAExC,WAAW;AACE,QAAA,QAAQ,GACnB,IAAA,kCAAiB,GAA0C,CAAC;AAC9D,WAAW;AACE,QAAA,UAAU,GACrB,IAAA,kCAAiB,GAEd,CAAC;AACN,WAAW;AACE,QAAA,WAAW,GAAG,IAAA,kCAAiB,GAA2B,CAAC;AAExE,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,MAAM,cAAc;IAKS;IAJnB,KAAK,CAAS;IACd,OAAO,CAA4C;IACnD,MAAM,CAAsB;IAEpC,YAA2B,MAA8B;QAA9B,WAAM,GAAN,MAAM,CAAwB;QACvD,IAAI,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC;IAC3B,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,KAAK,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;iBACrC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;iBACrB,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;gBACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YAC1B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,MAAM;QACjB,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC7C,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QAC1B,CAAC;QACD,MAAM,IAAA,mBAAW,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,CAAM;QACvB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACf,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QAC1B,CAAC;QACD,MAAM,IAAA,mBAAW,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC1C,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAa,KAAS,SAAQ,qBAAY;IACxC;;;;OAIG;IACI,GAAG;QACR,OAAO,IAAA,gBAAQ,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,mFAAmF;IAC5E,IAAI,CACT,WAAqE,EACrE,UAAuE;QAEvE,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;IAED,oDAAoD;IAE7C,MAAM;QAKX,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF;AA/BD,sBA+BC"}