@antelopejs/interface-data-api 0.4.0 → 0.6.0

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 (165) hide show
  1. package/README.md +26 -22
  2. package/dist/antelope.test.js +1 -5
  3. package/dist/antelope.test.js.map +1 -1
  4. package/dist/components.d.ts +67 -39
  5. package/dist/components.js +106 -685
  6. package/dist/components.js.map +1 -1
  7. package/dist/index.d.ts +57 -68
  8. package/dist/index.js +114 -100
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal/computed.d.ts +6 -0
  11. package/dist/internal/computed.js +51 -0
  12. package/dist/internal/computed.js.map +1 -0
  13. package/dist/internal/controller-types.d.ts +34 -0
  14. package/dist/internal/controller-types.js +4 -0
  15. package/dist/internal/controller-types.js.map +1 -0
  16. package/dist/internal/default-filter.d.ts +4 -0
  17. package/dist/internal/default-filter.js +29 -0
  18. package/dist/internal/default-filter.js.map +1 -0
  19. package/dist/internal/deferred-joined-stream.d.ts +11 -0
  20. package/dist/internal/deferred-joined-stream.js +125 -0
  21. package/dist/internal/deferred-joined-stream.js.map +1 -0
  22. package/dist/internal/extractors.d.ts +25 -0
  23. package/dist/internal/extractors.js +31 -0
  24. package/dist/internal/extractors.js.map +1 -0
  25. package/dist/internal/field-types.d.ts +199 -0
  26. package/dist/internal/field-types.js +4 -0
  27. package/dist/internal/field-types.js.map +1 -0
  28. package/dist/internal/filters.d.ts +6 -0
  29. package/dist/internal/filters.js +22 -0
  30. package/dist/internal/filters.js.map +1 -0
  31. package/dist/internal/foreign.d.ts +6 -0
  32. package/dist/internal/foreign.js +116 -0
  33. package/dist/internal/foreign.js.map +1 -0
  34. package/dist/internal/guards.d.ts +39 -0
  35. package/dist/internal/guards.js +116 -0
  36. package/dist/internal/guards.js.map +1 -0
  37. package/dist/internal/joined.d.ts +28 -0
  38. package/dist/internal/joined.js +127 -0
  39. package/dist/internal/joined.js.map +1 -0
  40. package/dist/internal/list.d.ts +16 -0
  41. package/dist/internal/list.js +182 -0
  42. package/dist/internal/list.js.map +1 -0
  43. package/dist/internal/meta-records.d.ts +19 -0
  44. package/dist/internal/meta-records.js +78 -0
  45. package/dist/internal/meta-records.js.map +1 -0
  46. package/dist/internal/properties.d.ts +4 -0
  47. package/dist/internal/properties.js +45 -0
  48. package/dist/internal/properties.js.map +1 -0
  49. package/dist/internal/prototypes.d.ts +14 -0
  50. package/dist/internal/prototypes.js +38 -0
  51. package/dist/internal/prototypes.js.map +1 -0
  52. package/dist/internal/read-properties.d.ts +3 -0
  53. package/dist/internal/read-properties.js +29 -0
  54. package/dist/internal/read-properties.js.map +1 -0
  55. package/dist/internal/table-reference.d.ts +11 -0
  56. package/dist/internal/table-reference.js +46 -0
  57. package/dist/internal/table-reference.js.map +1 -0
  58. package/dist/internal/tables.d.ts +28 -0
  59. package/dist/internal/tables.js +48 -0
  60. package/dist/internal/tables.js.map +1 -0
  61. package/dist/internal/validation.d.ts +12 -0
  62. package/dist/internal/validation.js +100 -0
  63. package/dist/internal/validation.js.map +1 -0
  64. package/dist/metadata.d.ts +27 -228
  65. package/dist/metadata.js +84 -213
  66. package/dist/metadata.js.map +1 -1
  67. package/dist/tests/components/access_control.test.js +28 -20
  68. package/dist/tests/components/access_control.test.js.map +1 -1
  69. package/dist/tests/components/computed.test.js +36 -27
  70. package/dist/tests/components/computed.test.js.map +1 -1
  71. package/dist/tests/components/cross_instance.test.js +8 -6
  72. package/dist/tests/components/cross_instance.test.js.map +1 -1
  73. package/dist/tests/components/deferred_joined.test.js +57 -54
  74. package/dist/tests/components/deferred_joined.test.js.map +1 -1
  75. package/dist/tests/components/extract_generic.test.d.ts +1 -0
  76. package/dist/tests/components/extract_generic.test.js +64 -0
  77. package/dist/tests/components/extract_generic.test.js.map +1 -0
  78. package/dist/tests/components/filter_comparisons.test.d.ts +1 -0
  79. package/dist/tests/components/filter_comparisons.test.js +34 -0
  80. package/dist/tests/components/filter_comparisons.test.js.map +1 -0
  81. package/dist/tests/components/filter_list_route.test.d.ts +1 -0
  82. package/dist/tests/components/filter_list_route.test.js +182 -0
  83. package/dist/tests/components/filter_list_route.test.js.map +1 -0
  84. package/dist/tests/components/filter_options.test.js +11 -10
  85. package/dist/tests/components/filter_options.test.js.map +1 -1
  86. package/dist/tests/components/foreign_computed.test.js +23 -14
  87. package/dist/tests/components/foreign_computed.test.js.map +1 -1
  88. package/dist/tests/components/foreign_joined.test.js +31 -27
  89. package/dist/tests/components/foreign_joined.test.js.map +1 -1
  90. package/dist/tests/components/joined.test.js +59 -45
  91. package/dist/tests/components/joined.test.js.map +1 -1
  92. package/dist/tests/components/listable.test.js +78 -58
  93. package/dist/tests/components/listable.test.js.map +1 -1
  94. package/dist/tests/components/localized_sort.test.js +14 -11
  95. package/dist/tests/components/localized_sort.test.js.map +1 -1
  96. package/dist/tests/components/mandatory.test.js +25 -25
  97. package/dist/tests/components/mandatory.test.js.map +1 -1
  98. package/dist/tests/components/modifier_key.test.js +27 -18
  99. package/dist/tests/components/modifier_key.test.js.map +1 -1
  100. package/dist/tests/components/parse_body.test.d.ts +1 -0
  101. package/dist/tests/components/parse_body.test.js +76 -0
  102. package/dist/tests/components/parse_body.test.js.map +1 -0
  103. package/dist/tests/components/parsed_value.test.js +23 -21
  104. package/dist/tests/components/parsed_value.test.js.map +1 -1
  105. package/dist/tests/components/partial_edit.test.js +38 -32
  106. package/dist/tests/components/partial_edit.test.js.map +1 -1
  107. package/dist/tests/components/per_action_access.test.js +20 -12
  108. package/dist/tests/components/per_action_access.test.js.map +1 -1
  109. package/dist/tests/components/prototype_named_filter.test.d.ts +1 -0
  110. package/dist/tests/components/prototype_named_filter.test.js +87 -0
  111. package/dist/tests/components/prototype_named_filter.test.js.map +1 -0
  112. package/dist/tests/components/validator.test.js +45 -37
  113. package/dist/tests/components/validator.test.js.map +1 -1
  114. package/dist/tests/components/written_row.test.d.ts +1 -0
  115. package/dist/tests/components/written_row.test.js +99 -0
  116. package/dist/tests/components/written_row.test.js.map +1 -0
  117. package/dist/tests/helpers/other-instance.d.ts +11 -1
  118. package/dist/tests/helpers/other-instance.js +35 -9
  119. package/dist/tests/helpers/other-instance.js.map +1 -1
  120. package/dist/tests/index/field_decorator_target.test.d.ts +1 -0
  121. package/dist/tests/index/field_decorator_target.test.js +20 -0
  122. package/dist/tests/index/field_decorator_target.test.js.map +1 -0
  123. package/dist/tests/index/get_guard.test.js +6 -6
  124. package/dist/tests/index/get_guard.test.js.map +1 -1
  125. package/dist/tests/index/inheritance.test.js +14 -9
  126. package/dist/tests/index/inheritance.test.js.map +1 -1
  127. package/dist/tests/index/metadata_names.test.d.ts +1 -0
  128. package/dist/tests/index/metadata_names.test.js +91 -0
  129. package/dist/tests/index/metadata_names.test.js.map +1 -0
  130. package/dist/tests/index/routes.test.js +49 -44
  131. package/dist/tests/index/routes.test.js.map +1 -1
  132. package/dist/tests/integration.test.d.ts +1 -1
  133. package/dist/tests/integration.test.js +66 -729
  134. package/dist/tests/integration.test.js.map +1 -1
  135. package/dist/tests/internal/controller-fields.test.d.ts +1 -0
  136. package/dist/tests/internal/controller-fields.test.js +25 -0
  137. package/dist/tests/internal/controller-fields.test.js.map +1 -0
  138. package/dist/tests/internal/http.d.ts +35 -0
  139. package/dist/tests/internal/http.js +56 -0
  140. package/dist/tests/internal/http.js.map +1 -0
  141. package/dist/tests/internal/shop-api.d.ts +1 -0
  142. package/dist/tests/internal/shop-api.js +331 -0
  143. package/dist/tests/internal/shop-api.js.map +1 -0
  144. package/dist/tests/internal/shop-schema.d.ts +162 -0
  145. package/dist/tests/internal/shop-schema.js +387 -0
  146. package/dist/tests/internal/shop-schema.js.map +1 -0
  147. package/dist/tests/utils.d.ts +8 -10
  148. package/dist/tests/utils.js +1 -3
  149. package/dist/tests/utils.js.map +1 -1
  150. package/dist/tests/utils.test.js +10 -11
  151. package/dist/tests/utils.test.js.map +1 -1
  152. package/docs/1.introduction.md +38 -35
  153. package/docs/10.joined.md +51 -40
  154. package/docs/11.computed.md +91 -47
  155. package/docs/2.data-controllers.md +50 -42
  156. package/docs/3.routes.md +156 -134
  157. package/docs/4.access-rights.md +48 -44
  158. package/docs/5.validators.md +65 -47
  159. package/docs/6.listable.md +53 -49
  160. package/docs/7.foreign-keys.md +55 -48
  161. package/docs/8.filters.md +65 -54
  162. package/docs/9.modifiers.md +29 -25
  163. package/package.json +34 -13
  164. package/skills/data-api-interface/SKILL.md +13 -3
  165. package/skills/data-api-interface/cases.json +99 -0
package/README.md CHANGED
@@ -1,24 +1,26 @@
1
- # @antelopejs/interface-data-api
1
+ # `@antelopejs/interface-data-api`
2
2
 
3
3
  <div align="center">
4
- <a href="https://www.npmjs.com/package/@antelopejs/interface-data-api"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/interface-data-api?style=for-the-badge&labelColor=000000&color=000000"></a>
5
- <a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/interface-data-api?style=for-the-badge&labelColor=000000&color=000000"></a>
6
- <a href="https://discord.gg/sjK28QHrA7"><img alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
7
- <a href="https://interfaces.antelopejs.com/docs/data-api"><img alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
4
+ <a href="https://www.npmjs.com/package/@antelopejs/interface-data-api"><img data-illustration alt="npm" src="https://img.shields.io/npm/v/@antelopejs/interface-data-api?style=for-the-badge&labelColor=000000&color=000000"></a>
5
+ <a href="./LICENSE"><img data-illustration alt="License" src="https://img.shields.io/npm/l/@antelopejs/interface-data-api?style=for-the-badge&labelColor=000000&color=000000"></a>
6
+ <a href="https://discord.gg/g4pFt6eXqu"><img data-illustration alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
7
+ <a href="https://interfaces.antelopejs.com/docs/data-api"><img data-illustration alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
8
8
  </div>
9
9
 
10
- CRUD REST endpoints generated from a database table: declare a data controller and its fields, and get `get`, `list`, `new`, `edit` and `delete` routes with access rules, validation and pagination.
10
+ The AntelopeJS interface that generates CRUD REST endpoints from a database table. Declare a data controller and its fields, and it serves the `get`, `list`, `new`, `edit` and `delete` routes with access rules, validation and pagination.
11
+
12
+ Part of [AntelopeJS](https://github.com/AntelopeJS/antelopejs). Used by [AntelopeJS DMS](https://github.com/AntelopeJS/dms), the open-source back office for your PostgreSQL, MongoDB or RethinkDB database.
11
13
 
12
14
  ## What it offers
13
15
 
14
16
  - `DataController` and `@RegisterDataController()` turn a table class into a controller with the default routes you pick from `DefaultRoutes`.
15
- - `@Access`, `@Mandatory` and `@Validator` decide which fields each route reads and writes, and check them.
17
+ - `@Access` decides which fields each route reads and writes. `@Mandatory` and `@Validator` check the written values.
16
18
  - `@Listable`, `@Sortable` and `@Filter` shape the paginated `list` route.
17
19
  - `@Foreign`, `@Joined` and `@Computed` resolve references, flatten remote fields and add values computed in the database.
18
20
 
19
21
  ## Implementations
20
22
 
21
- The package runs in your module and has no implementing module of its own. The project needs modules that implement the interfaces it builds on:
23
+ The package runs in your module and has no implementing module of its own. The project needs modules that implement the interfaces it builds on.
22
24
 
23
25
  | Interface | Module |
24
26
  | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
@@ -27,13 +29,13 @@ The package runs in your module and has no implementing module of its own. The p
27
29
 
28
30
  ## Install
29
31
 
30
- Add the package and the interfaces your controllers import to your module:
32
+ Add the package and its peer interfaces to your module.
31
33
 
32
34
  ```bash
33
- pnpm add @antelopejs/interface-data-api @antelopejs/interface-api @antelopejs/interface-database-decorators
35
+ pnpm add @antelopejs/interface-data-api @antelopejs/interface-api @antelopejs/interface-api-util @antelopejs/interface-core @antelopejs/interface-database @antelopejs/interface-database-decorators
34
36
  ```
35
37
 
36
- Then add the implementations to the project:
38
+ Then add the implementations to the project.
37
39
 
38
40
  ```bash
39
41
  ajs project modules add @antelopejs/api @antelopejs/mongodb
@@ -101,7 +103,7 @@ export async function construct() {
101
103
  }
102
104
  ```
103
105
 
104
- The controller serves `GET /tasks/get?id=`, `GET /tasks/list`, `POST /tasks/new`, `PUT /tasks/edit?id=` and `DELETE /tasks/delete?id=`. Fields without `@Access` stay out of every response.
106
+ The controller serves `GET /tasks/get?id=`, `GET /tasks/list`, `POST /tasks/new`, `PUT /tasks/edit?id=` and `DELETE /tasks/delete?id=`. A field without `@Access` stays out of every response and every write, unless `@Joined` or `@Computed` makes it read-only.
105
107
 
106
108
  ## Documentation
107
109
 
@@ -119,21 +121,23 @@ The controller serves `GET /tasks/get?id=`, `GET /tasks/list`, `POST /tasks/new`
119
121
 
120
122
  ## Compatibility
121
123
 
122
- Use with `@antelopejs/core` 1.x and the following peer dependencies:
124
+ The package declares these `@antelopejs/*` peer dependencies.
125
+
126
+ <!-- antelopejs-docs-compat:start -->
123
127
 
124
- <!-- docs-compat: ./package.json#peerDependencies -->
128
+ | Package | Supported | Tested with |
129
+ | ------------------------------------------- | ----------------- | ----------- |
130
+ | `@antelopejs/interface-api` | `>=0.3.0 <1.0.0` | `0.2.0` |
131
+ | `@antelopejs/interface-api-util` | `>=0.1.3 <1.0.0` | `0.3.0` |
132
+ | `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` | `0.4.0` |
133
+ | `@antelopejs/interface-database` | `>=0.1.10 <1.0.0` | `0.3.0` |
134
+ | `@antelopejs/interface-database-decorators` | `>=0.1.10 <1.0.0` | `0.2.0` |
125
135
 
126
- | Package | Range |
127
- | ------------------------------------------- | ----------------- |
128
- | `@antelopejs/interface-api` | `>=0.0.15 <1.0.0` |
129
- | `@antelopejs/interface-api-util` | `>=0.1.3 <1.0.0` |
130
- | `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` |
131
- | `@antelopejs/interface-database` | `>=0.1.10 <1.0.0` |
132
- | `@antelopejs/interface-database-decorators` | `>=0.1.10 <1.0.0` |
136
+ <!-- antelopejs-docs-compat:end -->
133
137
 
134
138
  ## Contributing
135
139
 
136
- Read [CONTRIBUTING.md](./CONTRIBUTING.md) before you open a pull request. The local checks are:
140
+ Read [CONTRIBUTING.md](./CONTRIBUTING.md) before you open a pull request. Run the local checks with these commands.
137
141
 
138
142
  ```bash
139
143
  pnpm install
@@ -22,11 +22,7 @@ exports.default = (0, config_1.defineConfig)({
22
22
  },
23
23
  },
24
24
  api: {
25
- source: {
26
- type: "package",
27
- package: "@antelopejs/api",
28
- version: "1.3.0",
29
- },
25
+ source: { type: "local", path: "node_modules/@antelopejs/api" },
30
26
  config: {
31
27
  publicBaseUrl: "http://127.0.0.1:5010",
32
28
  servers: [{ protocol: "http", host: "127.0.0.1", port: 5010 }],
@@ -1 +1 @@
1
- {"version":3,"file":"antelope.test.js","sourceRoot":"","sources":["../src/antelope.test.ts"],"names":[],"mappings":";;AAAA,2EAA+D;AAC/D,8DAAiE;AAEjE,IAAI,MAAyB,CAAC;AAE9B,kBAAe,IAAA,qBAAY,EAAC;IAC1B,IAAI,EAAE,yBAAyB;IAC/B,WAAW,EAAE,iBAAiB;IAC9B,OAAO,EAAE;QACP,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE;YACpC,eAAe,EAAE;gBACf,2BAA2B,EAAE,KAAK;gBAClC,gCAAgC,EAAE,SAAS;aAC5C;SACF;QACD,OAAO,EAAE;YACP,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,qBAAqB;gBAC9B,OAAO,EAAE,OAAO;aACjB;SACF;QACD,GAAG,EAAE;YACH,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,iBAAiB;gBAC1B,OAAO,EAAE,OAAO;aACjB;YACD,MAAM,EAAE;gBACN,aAAa,EAAE,uBAAuB;gBACtC,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,QAAQ,EAAE,iBAAiB,EAAE;qBAC9D;iBACF;aACF,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,OAAO;YACX,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;KACF;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"antelope.test.js","sourceRoot":"","sources":["../src/antelope.test.ts"],"names":[],"mappings":";;AAAA,2EAA+D;AAC/D,8DAAiE;AAEjE,IAAI,MAAyB,CAAC;AAE9B,kBAAe,IAAA,qBAAY,EAAC;IAC1B,IAAI,EAAE,yBAAyB;IAC/B,WAAW,EAAE,iBAAiB;IAC9B,OAAO,EAAE;QACP,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE;YACpC,eAAe,EAAE;gBACf,2BAA2B,EAAE,KAAK;gBAClC,gCAAgC,EAAE,SAAS;aAC5C;SACF;QACD,OAAO,EAAE;YACP,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,qBAAqB;gBAC9B,OAAO,EAAE,OAAO;aACjB;SACF;QACD,GAAG,EAAE;YACH,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,8BAA8B,EAAE;YAC/D,MAAM,EAAE;gBACN,aAAa,EAAE,uBAAuB;gBACtC,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,QAAQ,EAAE,iBAAiB,EAAE;qBAC9D;iBACF;aACF,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,OAAO;YACX,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;KACF;CACF,CAAC,CAAC"}
@@ -1,9 +1,20 @@
1
- import type { DataModel } from "@antelopejs/interface-database-decorators/model";
2
1
  import { type RequestContext } from "@antelopejs/interface-api";
3
- import { type Datum, type SchemaInstance, Stream, type Table, type ValueProxy } from "@antelopejs/interface-database";
4
- import { type DataAPIMeta, type FieldFilter } from "./metadata";
2
+ import type { Datum, SchemaInstance, Stream, Table, ValueProxy } from "@antelopejs/interface-database";
3
+ import "@antelopejs/interface-database";
4
+ import { type DataAPIMeta, type DataControllerCallbackWithOptions, type DataControllerInstance, type FieldFilter, type FieldValues, type RowFields } from "./metadata";
5
+ import * as extractors from "./internal/extractors";
6
+ import * as tables from "./internal/tables";
5
7
  export declare namespace Parameters {
6
- export function GetOptionOverrides<T extends Record<string, any>>(reqCtx: RequestContext): T;
8
+ /**
9
+ * A request context as a data route holds it: {@link RegisterDataController}
10
+ * sets the route's entry on it. `Options` is what the route's parameter
11
+ * reads, which `WithOptions` wrote.
12
+ */
13
+ interface DataRequestContext<Options = any> extends RequestContext {
14
+ dataAPIEntry?: DataControllerCallbackWithOptions<Options>;
15
+ }
16
+ /** The options the route's `WithOptions` set, none when it set none. */
17
+ function GetOptionOverrides<Options>(reqCtx: DataRequestContext<Options>): Partial<Options>;
7
18
  /**
8
19
  * Extracts request filters and mandatory route filters, with route field
9
20
  * keys winning. A field the request filters once (`?filter_status=open`)
@@ -11,19 +22,27 @@ export declare namespace Parameters {
11
22
  * (`?filter_age=ge:18&filter_age=lt:65`) gets them all, which a row must
12
23
  * all pass. Returns fresh tuples.
13
24
  */
14
- export function ExtractFilters(reqCtx: RequestContext, meta: DataAPIMeta): Record<string, FieldFilter>;
15
- const converters: {
16
- number: (val: string) => number;
17
- int: (val: string) => number;
18
- bool: (val: string) => boolean;
19
- string: (val: string) => string;
25
+ function ExtractFilters(reqCtx: DataRequestContext<ListParameters>, meta: DataAPIMeta): Record<string, FieldFilter>;
26
+ type ParameterExtractor<Value> = extractors.ParameterExtractor<Value>;
27
+ type ParameterExtractors<T> = extractors.ParameterExtractors<T>;
28
+ const FromSearch: {
29
+ number: extractors.ParameterExtractor<number>;
30
+ int: extractors.ParameterExtractor<number>;
31
+ bool: extractors.ParameterExtractor<boolean>;
32
+ string: extractors.ParameterExtractor<string>;
33
+ numbers: extractors.ParameterExtractor<number[]>;
34
+ ints: extractors.ParameterExtractor<number[]>;
35
+ bools: extractors.ParameterExtractor<boolean[]>;
36
+ strings: extractors.ParameterExtractor<string[]>;
20
37
  };
21
- type ConvertersKey = keyof typeof converters;
22
- type GenericParams<T extends Record<string, any>> = {
23
- [K in keyof T]: ConvertersKey | `multi:${ConvertersKey}` | ((reqCtx: RequestContext, meta: DataAPIMeta) => any);
24
- };
25
- export function ExtractGeneric<T extends Record<string, any>>(reqCtx: RequestContext, meta: DataAPIMeta, dynamic: GenericParams<Partial<T>>): Partial<T>;
26
- export interface ListParameters {
38
+ /**
39
+ * Builds a route's parameters: the options its `WithOptions` set, then each
40
+ * extracted field those options leave out. An extractor of `undefined` is
41
+ * skipped like an absent key. {@link ExtractFilters} also runs for a route
42
+ * that sets `filters`, since it combines them with the request's.
43
+ */
44
+ function ExtractGeneric<T extends Record<string, any>>(reqCtx: DataRequestContext<T>, meta: DataAPIMeta, dynamic: ParameterExtractors<T>): Partial<T>;
45
+ interface ListParameters {
27
46
  /**
28
47
  * The filters of the request, by field; a row passes every filter of
29
48
  * every field. Mandatory route filters when supplied through
@@ -39,40 +58,42 @@ export declare namespace Parameters {
39
58
  noPluck?: boolean;
40
59
  pluckMode?: string;
41
60
  }
42
- export const List: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
43
- export interface GetParameters {
61
+ const List: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
62
+ interface GetParameters {
44
63
  id: string;
45
64
  index?: string;
46
65
  noForeign?: string;
47
66
  }
48
- export const Get: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
49
- export interface NewParameters {
67
+ const Get: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
68
+ interface NewParameters {
50
69
  noMandatory?: string;
51
70
  }
52
- export const New: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
53
- export interface EditParameters {
71
+ const New: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
72
+ interface EditParameters {
54
73
  id: string;
55
74
  index?: string;
56
75
  noMandatory?: string;
57
76
  }
58
- export const Edit: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
59
- export interface DeleteParameters {
77
+ const Edit: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
78
+ interface DeleteParameters {
60
79
  id: string[];
61
80
  }
62
- export const Delete: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
63
- export {};
81
+ const Delete: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;
64
82
  }
65
83
  export declare namespace Query {
66
- function GetModel(obj: any, meta: DataAPIMeta): InstanceType<DataModel> & {
67
- constructor: DataModel;
68
- };
84
+ /**
85
+ * The database model a controller holds under its `@ModelReference` field,
86
+ * typed by the table rows it reads.
87
+ */
88
+ type ModelInstance = tables.ModelInstance;
89
+ function GetModel(obj: DataControllerInstance, meta: DataAPIMeta): ModelInstance;
69
90
  function Foreign(db: SchemaInstance<any>, meta: DataAPIMeta, query: Stream<any>, pluck?: Set<string>): Stream<any>;
70
91
  function Foreign(db: SchemaInstance<any>, meta: DataAPIMeta, query: Datum<any>, pluck?: Set<string>): Datum<any>;
71
92
  function Joined(db: SchemaInstance<any>, meta: DataAPIMeta, query: Stream<any>, only?: Set<string>): Stream<any>;
72
93
  function Joined(db: SchemaInstance<any>, meta: DataAPIMeta, query: Datum<any>, only?: Set<string>): Datum<any>;
73
94
  function Computed(db: SchemaInstance<any>, meta: DataAPIMeta, query: Stream<any>, only?: Set<string>): Stream<any>;
74
95
  function Computed(db: SchemaInstance<any>, meta: DataAPIMeta, query: Datum<any>, only?: Set<string>): Datum<any>;
75
- function ReadProperties(obj: any, meta: DataAPIMeta, dbData: any, action?: string, onlyList?: boolean): Promise<Record<string, any>>;
96
+ function ReadProperties(obj: DataControllerInstance, meta: DataAPIMeta, dbData: RowFields, action?: string, onlyList?: boolean): Promise<RowFields>;
76
97
  /**
77
98
  * Writes the writable fields of `bodyData` into a database row.
78
99
  *
@@ -83,8 +104,8 @@ export declare namespace Query {
83
104
  * row and only their setters run: an absent field keeps its stored value,
84
105
  * `null` clears it.
85
106
  */
86
- function WriteProperties(obj: any, meta: DataAPIMeta, bodyData: Record<string, any>, action?: string, existingDBData?: Record<string, any>): Promise<Record<string, any>>;
87
- function Get(table: Table<any>, id: string | ValueProxy<string>, index?: string): Datum<any>;
107
+ function WriteProperties(obj: DataControllerInstance, meta: DataAPIMeta, bodyData: FieldValues, action?: string, existingDBData?: RowFields): Promise<RowFields>;
108
+ function Get<T extends object>(table: Table<T>, id: string | ValueProxy<string>, index?: string): import("@antelopejs/interface-database").SingleSelection<T> | Datum<T | null>;
88
109
  interface ListOptions {
89
110
  /**
90
111
  * Return the joined field names {@link List} did not materialize as the
@@ -94,6 +115,13 @@ export declare namespace Query {
94
115
  */
95
116
  exposeDeferredJoined?: boolean;
96
117
  }
118
+ /** What {@link List} takes after the request context. */
119
+ type ListTail = [
120
+ sorting?: [string, "asc" | "desc" | undefined],
121
+ filters?: Record<string, FieldFilter>,
122
+ db?: SchemaInstance<any>,
123
+ options?: ListOptions
124
+ ];
97
125
  /**
98
126
  * Builds the filtered and sorted stream of a list request along with its
99
127
  * total count. Joined fields that no filter or sort references are not
@@ -104,7 +132,7 @@ export declare namespace Query {
104
132
  * since no lookup can be built without one — the raw stream is returned
105
133
  * and the third element names the joined fields left for the caller.
106
134
  */
107
- function List<T extends Record<string, any>>(obj: any, meta: DataAPIMeta, request: Table<T>, reqCtx: RequestContext, sorting?: [string, "asc" | "desc" | undefined], filters?: Record<string, FieldFilter>, db?: SchemaInstance<any>, options?: ListOptions): [sorted: Stream<T>, total: Datum<number>, deferredJoined: Set<string>];
135
+ function List<T extends Record<string, any>>(obj: DataControllerInstance, meta: DataAPIMeta, request: Table<T>, reqCtx: RequestContext, ...[sorting, filters, db, options]: ListTail): [sorted: Stream<T>, total: Datum<number>, deferredJoined: Set<string>];
108
136
  /** How {@link ListPage} reads one page of a {@link List} stream. */
109
137
  interface ListPageOptions {
110
138
  offset: number;
@@ -139,7 +167,7 @@ export declare namespace Query {
139
167
  }
140
168
  export declare namespace Validation {
141
169
  /** A request body, parsed. */
142
- type RequestBody = Record<string, any>;
170
+ type RequestBody = FieldValues;
143
171
  /** The `code` of a 400 naming the mandatory fields a body lacks. */
144
172
  const MISSING_MANDATORY_FIELDS = "missing_mandatory_fields";
145
173
  /** The `code` of a 400 naming the fields whose validator refused the value. */
@@ -160,7 +188,7 @@ export declare namespace Validation {
160
188
  * other action, it is missing when absent from the body. The body of the
161
189
  * 400 is a {@link FieldsErrorBody} with {@link MISSING_MANDATORY_FIELDS}.
162
190
  */
163
- function MandatoryFields(meta: DataAPIMeta, obj: any, type: string): void;
191
+ function MandatoryFields(meta: DataAPIMeta, obj: RequestBody, type: string): void;
164
192
  /**
165
193
  * Runs the validator of each field present in `obj` and rejects with 400
166
194
  * when one fails, with a {@link FieldsErrorBody} of
@@ -185,8 +213,8 @@ export declare namespace Validation {
185
213
  * untouched keeps its stored locked value: read while locked it would be
186
214
  * `undefined`, and locking it again would store that over it.
187
215
  */
188
- function Lock(obj: any, meta: DataAPIMeta, data: any): void;
189
- function Unlock(obj: any, meta: DataAPIMeta, dbData: any): void;
190
- function UnlockRequest<T extends {}, K extends keyof T>(obj: any, meta: DataAPIMeta, row: ValueProxy<T>, field: K): ValueProxy<T[K]>;
191
- function ClearInternal(meta: DataAPIMeta, obj: Record<string, any> | Array<Record<string, any>>): void;
216
+ function Lock(obj: DataControllerInstance, meta: DataAPIMeta, data: RowFields): void;
217
+ function Unlock(obj: DataControllerInstance, meta: DataAPIMeta, dbData: RowFields): void;
218
+ function UnlockRequest<T extends {}, K extends keyof T>(obj: DataControllerInstance, meta: DataAPIMeta, row: ValueProxy<T>, field: K): ValueProxy<T[K]>;
219
+ function ClearInternal(meta: DataAPIMeta, obj: RowFields | RowFields[]): void;
192
220
  }