@antelopejs/interface-data-api 0.3.0 → 0.5.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 (124) hide show
  1. package/README.md +1 -1
  2. package/dist/components.d.ts +32 -9
  3. package/dist/components.js +113 -628
  4. package/dist/components.js.map +1 -1
  5. package/dist/index.d.ts +41 -36
  6. package/dist/index.js +94 -92
  7. package/dist/index.js.map +1 -1
  8. package/dist/internal/computed.d.ts +6 -0
  9. package/dist/internal/computed.js +43 -0
  10. package/dist/internal/computed.js.map +1 -0
  11. package/dist/internal/controller-types.d.ts +19 -0
  12. package/dist/internal/controller-types.js +4 -0
  13. package/dist/internal/controller-types.js.map +1 -0
  14. package/dist/internal/default-filter.d.ts +4 -0
  15. package/dist/internal/default-filter.js +19 -0
  16. package/dist/internal/default-filter.js.map +1 -0
  17. package/dist/internal/deferred-joined-stream.d.ts +11 -0
  18. package/dist/internal/deferred-joined-stream.js +112 -0
  19. package/dist/internal/deferred-joined-stream.js.map +1 -0
  20. package/dist/internal/field-types.d.ts +183 -0
  21. package/dist/internal/field-types.js +4 -0
  22. package/dist/internal/field-types.js.map +1 -0
  23. package/dist/internal/filters.d.ts +4 -0
  24. package/dist/internal/filters.js +15 -0
  25. package/dist/internal/filters.js.map +1 -0
  26. package/dist/internal/foreign.d.ts +6 -0
  27. package/dist/internal/foreign.js +116 -0
  28. package/dist/internal/foreign.js.map +1 -0
  29. package/dist/internal/guards.d.ts +20 -0
  30. package/dist/internal/guards.js +74 -0
  31. package/dist/internal/guards.js.map +1 -0
  32. package/dist/internal/joined.d.ts +28 -0
  33. package/dist/internal/joined.js +127 -0
  34. package/dist/internal/joined.js.map +1 -0
  35. package/dist/internal/list.d.ts +16 -0
  36. package/dist/internal/list.js +178 -0
  37. package/dist/internal/list.js.map +1 -0
  38. package/dist/internal/meta-records.d.ts +17 -0
  39. package/dist/internal/meta-records.js +73 -0
  40. package/dist/internal/meta-records.js.map +1 -0
  41. package/dist/internal/properties.d.ts +4 -0
  42. package/dist/internal/properties.js +43 -0
  43. package/dist/internal/properties.js.map +1 -0
  44. package/dist/internal/table-reference.d.ts +11 -0
  45. package/dist/internal/table-reference.js +46 -0
  46. package/dist/internal/table-reference.js.map +1 -0
  47. package/dist/internal/tables.d.ts +18 -0
  48. package/dist/internal/tables.js +37 -0
  49. package/dist/internal/tables.js.map +1 -0
  50. package/dist/internal/validation.d.ts +11 -0
  51. package/dist/internal/validation.js +88 -0
  52. package/dist/internal/validation.js.map +1 -0
  53. package/dist/metadata.d.ts +27 -228
  54. package/dist/metadata.js +61 -188
  55. package/dist/metadata.js.map +1 -1
  56. package/dist/tests/components/access_control.test.js +20 -20
  57. package/dist/tests/components/access_control.test.js.map +1 -1
  58. package/dist/tests/components/computed.test.js +28 -30
  59. package/dist/tests/components/computed.test.js.map +1 -1
  60. package/dist/tests/components/cross_instance.test.js +8 -6
  61. package/dist/tests/components/cross_instance.test.js.map +1 -1
  62. package/dist/tests/components/deferred_joined.test.js +56 -53
  63. package/dist/tests/components/deferred_joined.test.js.map +1 -1
  64. package/dist/tests/components/filter_options.test.js +8 -7
  65. package/dist/tests/components/filter_options.test.js.map +1 -1
  66. package/dist/tests/components/foreign_computed.test.js +14 -16
  67. package/dist/tests/components/foreign_computed.test.js.map +1 -1
  68. package/dist/tests/components/foreign_joined.test.js +19 -27
  69. package/dist/tests/components/foreign_joined.test.js.map +1 -1
  70. package/dist/tests/components/joined.test.js +41 -45
  71. package/dist/tests/components/joined.test.js.map +1 -1
  72. package/dist/tests/components/listable.test.js +59 -58
  73. package/dist/tests/components/listable.test.js.map +1 -1
  74. package/dist/tests/components/localized_sort.test.d.ts +1 -0
  75. package/dist/tests/components/localized_sort.test.js +131 -0
  76. package/dist/tests/components/localized_sort.test.js.map +1 -0
  77. package/dist/tests/components/mandatory.test.js +33 -28
  78. package/dist/tests/components/mandatory.test.js.map +1 -1
  79. package/dist/tests/components/modifier_key.test.js +19 -18
  80. package/dist/tests/components/modifier_key.test.js.map +1 -1
  81. package/dist/tests/components/parse_body.test.d.ts +1 -0
  82. package/dist/tests/components/parse_body.test.js +75 -0
  83. package/dist/tests/components/parse_body.test.js.map +1 -0
  84. package/dist/tests/components/parsed_value.test.js +27 -21
  85. package/dist/tests/components/parsed_value.test.js.map +1 -1
  86. package/dist/tests/components/partial_edit.test.js +33 -32
  87. package/dist/tests/components/partial_edit.test.js.map +1 -1
  88. package/dist/tests/components/per_action_access.test.js +12 -12
  89. package/dist/tests/components/per_action_access.test.js.map +1 -1
  90. package/dist/tests/components/validator.test.js +45 -37
  91. package/dist/tests/components/validator.test.js.map +1 -1
  92. package/dist/tests/helpers/other-instance.d.ts +11 -1
  93. package/dist/tests/helpers/other-instance.js +27 -5
  94. package/dist/tests/helpers/other-instance.js.map +1 -1
  95. package/dist/tests/index/get_guard.test.js +6 -6
  96. package/dist/tests/index/get_guard.test.js.map +1 -1
  97. package/dist/tests/index/inheritance.test.js +10 -9
  98. package/dist/tests/index/inheritance.test.js.map +1 -1
  99. package/dist/tests/index/routes.test.js +40 -44
  100. package/dist/tests/index/routes.test.js.map +1 -1
  101. package/dist/tests/integration.test.d.ts +1 -1
  102. package/dist/tests/integration.test.js +53 -729
  103. package/dist/tests/integration.test.js.map +1 -1
  104. package/dist/tests/internal/http.d.ts +23 -0
  105. package/dist/tests/internal/http.js +35 -0
  106. package/dist/tests/internal/http.js.map +1 -0
  107. package/dist/tests/internal/shop-api.d.ts +1 -0
  108. package/dist/tests/internal/shop-api.js +331 -0
  109. package/dist/tests/internal/shop-api.js.map +1 -0
  110. package/dist/tests/internal/shop-schema.d.ts +154 -0
  111. package/dist/tests/internal/shop-schema.js +387 -0
  112. package/dist/tests/internal/shop-schema.js.map +1 -0
  113. package/dist/tests/utils.d.ts +5 -5
  114. package/dist/tests/utils.js +1 -3
  115. package/dist/tests/utils.js.map +1 -1
  116. package/dist/tests/utils.test.js +10 -11
  117. package/dist/tests/utils.test.js.map +1 -1
  118. package/docs/3.routes.md +8 -3
  119. package/docs/5.validators.md +16 -7
  120. package/docs/6.listable.md +4 -0
  121. package/docs/8.filters.md +7 -3
  122. package/package.json +17 -6
  123. package/skills/data-api-interface/SKILL.md +4 -0
  124. package/skills/data-api-interface/cases.json +99 -0
package/README.md CHANGED
@@ -129,7 +129,7 @@ Use with `@antelopejs/core` 1.x and the following peer dependencies:
129
129
  | `@antelopejs/interface-api-util` | `>=0.1.3 <1.0.0` |
130
130
  | `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` |
131
131
  | `@antelopejs/interface-database` | `>=0.1.10 <1.0.0` |
132
- | `@antelopejs/interface-database-decorators` | `>=0.1.9 <1.0.0` |
132
+ | `@antelopejs/interface-database-decorators` | `>=0.1.10 <1.0.0` |
133
133
 
134
134
  ## Contributing
135
135
 
@@ -1,7 +1,8 @@
1
1
  import type { DataModel } from "@antelopejs/interface-database-decorators/model";
2
2
  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";
3
+ import type { Datum, SchemaInstance, Stream, Table, ValueProxy } from "@antelopejs/interface-database";
4
+ import "@antelopejs/interface-database";
5
+ import { type DataAPIMeta, type FieldFilter, type FieldValues } from "./metadata";
5
6
  export declare namespace Parameters {
6
7
  export function GetOptionOverrides<T extends Record<string, any>>(reqCtx: RequestContext): T;
7
8
  /**
@@ -72,7 +73,7 @@ export declare namespace Query {
72
73
  function Joined(db: SchemaInstance<any>, meta: DataAPIMeta, query: Datum<any>, only?: Set<string>): Datum<any>;
73
74
  function Computed(db: SchemaInstance<any>, meta: DataAPIMeta, query: Stream<any>, only?: Set<string>): Stream<any>;
74
75
  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>>;
76
+ function ReadProperties(obj: any, meta: DataAPIMeta, dbData: any, action?: string, onlyList?: boolean): Promise<FieldValues>;
76
77
  /**
77
78
  * Writes the writable fields of `bodyData` into a database row.
78
79
  *
@@ -83,7 +84,7 @@ export declare namespace Query {
83
84
  * row and only their setters run: an absent field keeps its stored value,
84
85
  * `null` clears it.
85
86
  */
86
- function WriteProperties(obj: any, meta: DataAPIMeta, bodyData: Record<string, any>, action?: string, existingDBData?: Record<string, any>): Promise<Record<string, any>>;
87
+ function WriteProperties(obj: any, meta: DataAPIMeta, bodyData: FieldValues, action?: string, existingDBData?: Record<string, any>): Promise<Record<string, any>>;
87
88
  function Get(table: Table<any>, id: string | ValueProxy<string>, index?: string): Datum<any>;
88
89
  interface ListOptions {
89
90
  /**
@@ -94,6 +95,13 @@ export declare namespace Query {
94
95
  */
95
96
  exposeDeferredJoined?: boolean;
96
97
  }
98
+ /** What {@link List} takes after the request context. */
99
+ type ListTail = [
100
+ sorting?: [string, "asc" | "desc" | undefined],
101
+ filters?: Record<string, FieldFilter>,
102
+ db?: SchemaInstance<any>,
103
+ options?: ListOptions
104
+ ];
97
105
  /**
98
106
  * Builds the filtered and sorted stream of a list request along with its
99
107
  * total count. Joined fields that no filter or sort references are not
@@ -104,7 +112,7 @@ export declare namespace Query {
104
112
  * since no lookup can be built without one — the raw stream is returned
105
113
  * and the third element names the joined fields left for the caller.
106
114
  */
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>];
115
+ function List<T extends Record<string, any>>(obj: any, meta: DataAPIMeta, request: Table<T>, reqCtx: RequestContext, ...[sorting, filters, db, options]: ListTail): [sorted: Stream<T>, total: Datum<number>, deferredJoined: Set<string>];
108
116
  /** How {@link ListPage} reads one page of a {@link List} stream. */
109
117
  interface ListPageOptions {
110
118
  offset: number;
@@ -139,17 +147,32 @@ export declare namespace Query {
139
147
  }
140
148
  export declare namespace Validation {
141
149
  /** A request body, parsed. */
142
- type RequestBody = Record<string, any>;
150
+ type RequestBody = FieldValues;
151
+ /** The `code` of a 400 naming the mandatory fields a body lacks. */
152
+ const MISSING_MANDATORY_FIELDS = "missing_mandatory_fields";
153
+ /** The `code` of a 400 naming the fields whose validator refused the value. */
154
+ const INVALID_FIELD_TYPES = "invalid_field_types";
155
+ /**
156
+ * The body of a 400 refusing some fields of a request body: what went
157
+ * wrong (`code`) and the fields concerned, for the client to word it and
158
+ * show it under each one.
159
+ */
160
+ interface FieldsErrorBody {
161
+ code: typeof MISSING_MANDATORY_FIELDS | typeof INVALID_FIELD_TYPES;
162
+ fields: string[];
163
+ }
143
164
  /**
144
165
  * Rejects with 400 the request bodies missing a field mandatory for `type`.
145
166
  * On `edit`, a mandatory field is missing when the body clears it (`null`,
146
167
  * `""` or `[]`); a field absent from the body keeps its stored value. On any
147
- * other action, it is missing when absent from the body.
168
+ * other action, it is missing when absent from the body. The body of the
169
+ * 400 is a {@link FieldsErrorBody} with {@link MISSING_MANDATORY_FIELDS}.
148
170
  */
149
171
  function MandatoryFields(meta: DataAPIMeta, obj: any, type: string): void;
150
172
  /**
151
173
  * Runs the validator of each field present in `obj` and rejects with 400
152
- * when one fails. Returns a copy of `obj` where each validated field holds
174
+ * when one fails, with a {@link FieldsErrorBody} of
175
+ * {@link INVALID_FIELD_TYPES}. Returns a copy of `obj` where each validated field holds
153
176
  * the value its validator parsed (see {@link FieldValidationResult}).
154
177
  */
155
178
  function ValidateTypes(meta: DataAPIMeta, obj: RequestBody): Promise<RequestBody>;
@@ -173,5 +196,5 @@ export declare namespace Validation {
173
196
  function Lock(obj: any, meta: DataAPIMeta, data: any): void;
174
197
  function Unlock(obj: any, meta: DataAPIMeta, dbData: any): void;
175
198
  function UnlockRequest<T extends {}, K extends keyof T>(obj: any, meta: DataAPIMeta, row: ValueProxy<T>, field: K): ValueProxy<T[K]>;
176
- function ClearInternal(meta: DataAPIMeta, obj: Record<string, any> | Array<Record<string, any>>): void;
199
+ function ClearInternal(meta: DataAPIMeta, obj: FieldValues | FieldValues[]): void;
177
200
  }