@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.
- package/README.md +1 -1
- package/dist/components.d.ts +32 -9
- package/dist/components.js +113 -628
- package/dist/components.js.map +1 -1
- package/dist/index.d.ts +41 -36
- package/dist/index.js +94 -92
- package/dist/index.js.map +1 -1
- package/dist/internal/computed.d.ts +6 -0
- package/dist/internal/computed.js +43 -0
- package/dist/internal/computed.js.map +1 -0
- package/dist/internal/controller-types.d.ts +19 -0
- package/dist/internal/controller-types.js +4 -0
- package/dist/internal/controller-types.js.map +1 -0
- package/dist/internal/default-filter.d.ts +4 -0
- package/dist/internal/default-filter.js +19 -0
- package/dist/internal/default-filter.js.map +1 -0
- package/dist/internal/deferred-joined-stream.d.ts +11 -0
- package/dist/internal/deferred-joined-stream.js +112 -0
- package/dist/internal/deferred-joined-stream.js.map +1 -0
- package/dist/internal/field-types.d.ts +183 -0
- package/dist/internal/field-types.js +4 -0
- package/dist/internal/field-types.js.map +1 -0
- package/dist/internal/filters.d.ts +4 -0
- package/dist/internal/filters.js +15 -0
- package/dist/internal/filters.js.map +1 -0
- package/dist/internal/foreign.d.ts +6 -0
- package/dist/internal/foreign.js +116 -0
- package/dist/internal/foreign.js.map +1 -0
- package/dist/internal/guards.d.ts +20 -0
- package/dist/internal/guards.js +74 -0
- package/dist/internal/guards.js.map +1 -0
- package/dist/internal/joined.d.ts +28 -0
- package/dist/internal/joined.js +127 -0
- package/dist/internal/joined.js.map +1 -0
- package/dist/internal/list.d.ts +16 -0
- package/dist/internal/list.js +178 -0
- package/dist/internal/list.js.map +1 -0
- package/dist/internal/meta-records.d.ts +17 -0
- package/dist/internal/meta-records.js +73 -0
- package/dist/internal/meta-records.js.map +1 -0
- package/dist/internal/properties.d.ts +4 -0
- package/dist/internal/properties.js +43 -0
- package/dist/internal/properties.js.map +1 -0
- package/dist/internal/table-reference.d.ts +11 -0
- package/dist/internal/table-reference.js +46 -0
- package/dist/internal/table-reference.js.map +1 -0
- package/dist/internal/tables.d.ts +18 -0
- package/dist/internal/tables.js +37 -0
- package/dist/internal/tables.js.map +1 -0
- package/dist/internal/validation.d.ts +11 -0
- package/dist/internal/validation.js +88 -0
- package/dist/internal/validation.js.map +1 -0
- package/dist/metadata.d.ts +27 -228
- package/dist/metadata.js +61 -188
- package/dist/metadata.js.map +1 -1
- package/dist/tests/components/access_control.test.js +20 -20
- package/dist/tests/components/access_control.test.js.map +1 -1
- package/dist/tests/components/computed.test.js +28 -30
- package/dist/tests/components/computed.test.js.map +1 -1
- package/dist/tests/components/cross_instance.test.js +8 -6
- package/dist/tests/components/cross_instance.test.js.map +1 -1
- package/dist/tests/components/deferred_joined.test.js +56 -53
- package/dist/tests/components/deferred_joined.test.js.map +1 -1
- package/dist/tests/components/filter_options.test.js +8 -7
- package/dist/tests/components/filter_options.test.js.map +1 -1
- package/dist/tests/components/foreign_computed.test.js +14 -16
- package/dist/tests/components/foreign_computed.test.js.map +1 -1
- package/dist/tests/components/foreign_joined.test.js +19 -27
- package/dist/tests/components/foreign_joined.test.js.map +1 -1
- package/dist/tests/components/joined.test.js +41 -45
- package/dist/tests/components/joined.test.js.map +1 -1
- package/dist/tests/components/listable.test.js +59 -58
- package/dist/tests/components/listable.test.js.map +1 -1
- package/dist/tests/components/localized_sort.test.d.ts +1 -0
- package/dist/tests/components/localized_sort.test.js +131 -0
- package/dist/tests/components/localized_sort.test.js.map +1 -0
- package/dist/tests/components/mandatory.test.js +33 -28
- package/dist/tests/components/mandatory.test.js.map +1 -1
- package/dist/tests/components/modifier_key.test.js +19 -18
- package/dist/tests/components/modifier_key.test.js.map +1 -1
- package/dist/tests/components/parse_body.test.d.ts +1 -0
- package/dist/tests/components/parse_body.test.js +75 -0
- package/dist/tests/components/parse_body.test.js.map +1 -0
- package/dist/tests/components/parsed_value.test.js +27 -21
- package/dist/tests/components/parsed_value.test.js.map +1 -1
- package/dist/tests/components/partial_edit.test.js +33 -32
- package/dist/tests/components/partial_edit.test.js.map +1 -1
- package/dist/tests/components/per_action_access.test.js +12 -12
- package/dist/tests/components/per_action_access.test.js.map +1 -1
- package/dist/tests/components/validator.test.js +45 -37
- package/dist/tests/components/validator.test.js.map +1 -1
- package/dist/tests/helpers/other-instance.d.ts +11 -1
- package/dist/tests/helpers/other-instance.js +27 -5
- package/dist/tests/helpers/other-instance.js.map +1 -1
- package/dist/tests/index/get_guard.test.js +6 -6
- package/dist/tests/index/get_guard.test.js.map +1 -1
- package/dist/tests/index/inheritance.test.js +10 -9
- package/dist/tests/index/inheritance.test.js.map +1 -1
- package/dist/tests/index/routes.test.js +40 -44
- package/dist/tests/index/routes.test.js.map +1 -1
- package/dist/tests/integration.test.d.ts +1 -1
- package/dist/tests/integration.test.js +53 -729
- package/dist/tests/integration.test.js.map +1 -1
- package/dist/tests/internal/http.d.ts +23 -0
- package/dist/tests/internal/http.js +35 -0
- package/dist/tests/internal/http.js.map +1 -0
- package/dist/tests/internal/shop-api.d.ts +1 -0
- package/dist/tests/internal/shop-api.js +331 -0
- package/dist/tests/internal/shop-api.js.map +1 -0
- package/dist/tests/internal/shop-schema.d.ts +154 -0
- package/dist/tests/internal/shop-schema.js +387 -0
- package/dist/tests/internal/shop-schema.js.map +1 -0
- package/dist/tests/utils.d.ts +5 -5
- package/dist/tests/utils.js +1 -3
- package/dist/tests/utils.js.map +1 -1
- package/dist/tests/utils.test.js +10 -11
- package/dist/tests/utils.test.js.map +1 -1
- package/docs/3.routes.md +8 -3
- package/docs/5.validators.md +16 -7
- package/docs/6.listable.md +4 -0
- package/docs/8.filters.md +7 -3
- package/package.json +17 -6
- package/skills/data-api-interface/SKILL.md +4 -0
- 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.
|
|
132
|
+
| `@antelopejs/interface-database-decorators` | `>=0.1.10 <1.0.0` |
|
|
133
133
|
|
|
134
134
|
## Contributing
|
|
135
135
|
|
package/dist/components.d.ts
CHANGED
|
@@ -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 {
|
|
4
|
-
import
|
|
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<
|
|
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:
|
|
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
|
|
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 =
|
|
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
|
|
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:
|
|
199
|
+
function ClearInternal(meta: DataAPIMeta, obj: FieldValues | FieldValues[]): void;
|
|
177
200
|
}
|