@antelopejs/interface-data-api 0.4.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/dist/components.d.ts +15 -7
- package/dist/components.js +98 -645
- 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.js +10 -11
- package/dist/tests/components/localized_sort.test.js.map +1 -1
- package/dist/tests/components/mandatory.test.js +25 -25
- 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 +23 -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 +12 -3
- package/docs/8.filters.md +7 -3
- package/package.json +14 -3
- package/skills/data-api-interface/SKILL.md +4 -0
- package/skills/data-api-interface/cases.json +99 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @internal @packageDocumentation */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.targetTable = targetTable;
|
|
5
|
+
exports.pluckedTable = pluckedTable;
|
|
6
|
+
exports.Get = Get;
|
|
7
|
+
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
8
|
+
const guards_1 = require("./guards");
|
|
9
|
+
function isTableClass(value) {
|
|
10
|
+
return ((0, guards_1.isFunction)(value) &&
|
|
11
|
+
"table" in value &&
|
|
12
|
+
(0, guards_1.isFunction)(value.table) &&
|
|
13
|
+
"with" in value &&
|
|
14
|
+
(0, guards_1.isFunction)(value.with));
|
|
15
|
+
}
|
|
16
|
+
function targetTable(sourceDb, target) {
|
|
17
|
+
if (!target.schemaName)
|
|
18
|
+
return sourceDb.table(target.table);
|
|
19
|
+
(0, interface_api_util_1.assert)(isTableClass(target.tableClass), 500, `Table "${target.table}" of schema "${target.schemaName}" has no registered table class`);
|
|
20
|
+
return target.tableClass.table();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The lookup side of a relation: `table` reduced to `fields`, with the
|
|
24
|
+
* internal fields the modifiers keep. A plucked table is a staged selection
|
|
25
|
+
* the database accepts wherever it takes a table, but its type is a stream.
|
|
26
|
+
*/
|
|
27
|
+
function pluckedTable(table, ...fields) {
|
|
28
|
+
// SAFETY: pluck returns a Stream, which has none of Table's own methods; pluckedTable is only called in joined.ts and foreign.ts to build the right-hand side of lookup, and lookup reads that argument only through its stage list (build()), which the pluck stage extends.
|
|
29
|
+
return table.pluck("_internal", ...fields);
|
|
30
|
+
}
|
|
31
|
+
function Get(table, id, index) {
|
|
32
|
+
if (!index)
|
|
33
|
+
return table.get(id);
|
|
34
|
+
const key = (0, guards_1.isString)(id) ? id : id.cast();
|
|
35
|
+
return table.getAll(key, index).nth(0);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../src/internal/tables.ts"],"names":[],"mappings":";AAAA,sCAAsC;;AAkCtC,kCAWC;AAOD,oCAMC;AAED,kBAQC;AAlED,uEAAwD;AAUxD,qCAAgD;AAUhD,SAAS,YAAY,CACnB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/interface-database";
|
|
3
|
+
import type { Validation } from "../components";
|
|
4
|
+
import type { DataAPIMeta } from "../metadata";
|
|
5
|
+
type RequestBody = Validation.RequestBody;
|
|
6
|
+
type WrittenBody = Validation.WrittenBody;
|
|
7
|
+
export declare function ParseBody(body: WrittenBody): RequestBody;
|
|
8
|
+
export declare function Unlock(obj: any, meta: DataAPIMeta, dbData: any): void;
|
|
9
|
+
export declare function UnlockRequest<T extends {}, K extends keyof T>(obj: any, meta: DataAPIMeta, row: ValueProxy<T>, field: K): ValueProxy<T[K]>;
|
|
10
|
+
export declare function ClearInternal(meta: DataAPIMeta, obj: Parameters<typeof Validation.ClearInternal>[1]): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @internal @packageDocumentation */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ParseBody = ParseBody;
|
|
5
|
+
exports.Unlock = Unlock;
|
|
6
|
+
exports.UnlockRequest = UnlockRequest;
|
|
7
|
+
exports.ClearInternal = ClearInternal;
|
|
8
|
+
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
9
|
+
const common_1 = require("@antelopejs/interface-database-decorators/modifiers/common");
|
|
10
|
+
const guards_1 = require("./guards");
|
|
11
|
+
function ParseBody(body) {
|
|
12
|
+
let data = body;
|
|
13
|
+
if (Buffer.isBuffer(body)) {
|
|
14
|
+
try {
|
|
15
|
+
data = JSON.parse(body.toString());
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
(0, interface_api_util_1.assert)(false, 400, "Invalid JSON body.");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
(0, interface_api_util_1.assert)((0, guards_1.isFieldValues)(data), 400, "The request body must be a JSON object.");
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function Unlock(obj, meta, dbData) {
|
|
25
|
+
for (const [name, field] of Object.entries(meta.fields)) {
|
|
26
|
+
if (field.foreign && (0, guards_1.isObject)(dbData[name]) && field.foreign[1]) {
|
|
27
|
+
const foreignSchema = field.foreign[1];
|
|
28
|
+
dbData[name] = Array.isArray(dbData[name])
|
|
29
|
+
? dbData[name].map((entry) => (0, common_1.fromDatabase)(entry, foreignSchema))
|
|
30
|
+
: (0, common_1.fromDatabase)(dbData[name], field.foreign[1]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const [modifier, field] of meta.modifierKeys.entries()) {
|
|
34
|
+
const key = obj[field];
|
|
35
|
+
(0, common_1.unlock)(dbData, modifier, undefined, key);
|
|
36
|
+
for (const [foreign, fieldData] of Object.entries(meta.fields)) {
|
|
37
|
+
if (fieldData.foreign && (0, guards_1.isObject)(dbData[foreign])) {
|
|
38
|
+
(0, common_1.unlock)(dbData[foreign], modifier, undefined, key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function UnlockRequest(obj, meta, row, field) {
|
|
44
|
+
const modifiers = Array.from(meta.modifierKeys.entries()).map(([modifier, field]) => ({
|
|
45
|
+
modifier,
|
|
46
|
+
args: [obj[field]],
|
|
47
|
+
}));
|
|
48
|
+
return (0, common_1.unlockrequest)(meta.tableClass, row, field, modifiers);
|
|
49
|
+
}
|
|
50
|
+
function ClearInternal(meta, obj) {
|
|
51
|
+
const results = Array.isArray(obj) ? obj : [obj];
|
|
52
|
+
const foreignFields = Object.entries(meta.fields).filter(([, field]) => field.foreign);
|
|
53
|
+
for (const entry of results) {
|
|
54
|
+
delete entry._internal;
|
|
55
|
+
for (const [name, { foreign }] of foreignFields) {
|
|
56
|
+
if (foreign &&
|
|
57
|
+
(0, guards_1.isObject)(entry[name]) &&
|
|
58
|
+
(!Array.isArray(entry[name]) ||
|
|
59
|
+
entry[name][0] === null ||
|
|
60
|
+
(0, guards_1.isObject)(entry[name][0]))) {
|
|
61
|
+
const processForeign = (data) => {
|
|
62
|
+
const plain = (0, common_1.toPlainData)(data);
|
|
63
|
+
if (!foreign?.[4]) {
|
|
64
|
+
return plain;
|
|
65
|
+
}
|
|
66
|
+
const targetJoined = foreign[6];
|
|
67
|
+
if (targetJoined?.length) {
|
|
68
|
+
const joinedNames = new Set(targetJoined.map((g) => g.name));
|
|
69
|
+
const physicalKeys = foreign[4].filter((k) => !joinedNames.has(k));
|
|
70
|
+
if (physicalKeys.length > 0 &&
|
|
71
|
+
physicalKeys.every((k) => plain[k] === null || plain[k] === undefined)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const plainPlucked = {};
|
|
76
|
+
for (const key of foreign[4]) {
|
|
77
|
+
plainPlucked[key] = plain[key];
|
|
78
|
+
}
|
|
79
|
+
return plainPlucked;
|
|
80
|
+
};
|
|
81
|
+
entry[name] = Array.isArray(entry[name])
|
|
82
|
+
? entry[name].map(processForeign)
|
|
83
|
+
: processForeign(entry[name]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/internal/validation.ts"],"names":[],"mappings":";AAAA,sCAAsC;;AAkBtC,8BAWC;AAED,wBAkBC;AAED,sCAaC;AAED,sCAiDC;AAjHD,uEAAwD;AAExD,uFAKoE;AAIpE,qCAAmD;AAKnD,SAAgB,SAAS,CAAC,IAAiB;IACzC,IAAI,IAAI,GAAY,IAAI,CAAC;IACzB,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,IAAA,2BAAM,EAAC,KAAK,EAAE,GAAG,EAAE,oBAAoB,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IACD,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CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;oBACjC,CAAC;oBACD,OAAO,YAAY,CAAC;gBACtB,CAAC,CAAC;gBACF,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACtC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC;oBACjC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/metadata.d.ts
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import type { RequestContext } from "@antelopejs/interface-api";
|
|
2
1
|
import type { ContainerModifier } from "@antelopejs/interface-database-decorators/modifiers/common";
|
|
3
|
-
import type { Query, SchemaInstance, ValueProxy, ValueProxyOrValue } from "@antelopejs/interface-database";
|
|
4
2
|
import { type Table } from "@antelopejs/interface-database-decorators";
|
|
5
|
-
import { type Class
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
export type DataControllerCallbackWithOptions<O = any> = {
|
|
12
|
-
endpoint?: string;
|
|
13
|
-
options?: Partial<O>;
|
|
14
|
-
callback: DataControllerCallback<O>;
|
|
15
|
-
};
|
|
16
|
-
export type ExtractCallback<T> = T extends DataControllerCallbackWithOptions ? T["callback"]["func"] : T extends DataControllerCallback ? T["func"] : never;
|
|
17
|
-
export type DataControllerDef = {
|
|
18
|
-
[name: string]: DataControllerCallback | DataControllerCallbackWithOptions;
|
|
19
|
-
};
|
|
20
|
-
export type ExtractDefCallbacks<T extends {}> = {
|
|
21
|
-
[K in keyof T]: ExtractCallback<T[K]>;
|
|
22
|
-
};
|
|
3
|
+
import { type Class } from "@antelopejs/interface-core/decorators";
|
|
4
|
+
import type { DataControllerCallbackWithOptions } from "./internal/controller-types";
|
|
5
|
+
import type { FieldValidator, FieldData, ComputedExpression, ComputedOptions, FilterValue, FieldFilter, FilterFunction, ForeignOptions, ReadableAccessFields, WritableAccessFields } from "./internal/field-types";
|
|
6
|
+
export type { DataControllerCallback, DataControllerCallbackWithOptions, ExtractCallback, DataControllerDef, ExtractDefCallbacks, } from "./internal/controller-types";
|
|
7
|
+
export type { ForeignJoinedRef, FieldParseSuccess, FieldParseFailure, FieldParseResult, FieldValidationResult, FieldValue, FieldValues, ForeignOptions, FieldValidator, FieldData, ComputedExpression, ComputedOptions, ComputedFieldData, FilterValue, FieldFilter, FilterFunction, ReadableAccessFields, WritableAccessFields, } from "./internal/field-types";
|
|
23
8
|
/**
|
|
24
9
|
* Field access mode enum.
|
|
25
10
|
*/
|
|
@@ -28,126 +13,6 @@ export declare enum AccessMode {
|
|
|
28
13
|
WriteOnly = 2,
|
|
29
14
|
ReadWrite = 3
|
|
30
15
|
}
|
|
31
|
-
/**
|
|
32
|
-
* A `@Joined` field declared on the target of a relation, captured so the
|
|
33
|
-
* foreign lookup can re-materialize it (joined fields are not physical columns,
|
|
34
|
-
* so a plain pluck of the target table would return them empty).
|
|
35
|
-
*/
|
|
36
|
-
export interface ForeignJoinedRef {
|
|
37
|
-
name: string;
|
|
38
|
-
table: string;
|
|
39
|
-
tableClass?: Class<Table>;
|
|
40
|
-
localKey: string;
|
|
41
|
-
remoteField: string;
|
|
42
|
-
remoteIndex: string;
|
|
43
|
-
schemaName?: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* DataAPI Metadata field information.
|
|
47
|
-
*/
|
|
48
|
-
/** Parse outcome accepting the field value, carrying the value to write. */
|
|
49
|
-
export interface FieldParseSuccess {
|
|
50
|
-
success: true;
|
|
51
|
-
data: unknown;
|
|
52
|
-
}
|
|
53
|
-
/** Parse outcome rejecting the field value. */
|
|
54
|
-
export interface FieldParseFailure {
|
|
55
|
-
success: false;
|
|
56
|
-
}
|
|
57
|
-
/** Parse outcome of a field value, shaped like the result of zod's `safeParse`. */
|
|
58
|
-
export type FieldParseResult = FieldParseSuccess | FieldParseFailure;
|
|
59
|
-
/**
|
|
60
|
-
* Outcome of a field validator: `true`/`false` accepts or rejects the raw
|
|
61
|
-
* value, which is then written as received; a {@link FieldParseResult}
|
|
62
|
-
* accepts or rejects it, and on success its `data` is written instead of the
|
|
63
|
-
* raw value.
|
|
64
|
-
*/
|
|
65
|
-
export type FieldValidationResult = boolean | FieldParseResult;
|
|
66
|
-
/** Field value validator, see {@link FieldValidationResult}. */
|
|
67
|
-
export type FieldValidator = (value: unknown) => FieldValidationResult | Promise<FieldValidationResult>;
|
|
68
|
-
export interface FieldData {
|
|
69
|
-
/**
|
|
70
|
-
* Field name in-database.
|
|
71
|
-
*/
|
|
72
|
-
dbName?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Field access mode.
|
|
75
|
-
*
|
|
76
|
-
* @see {@link AccessMode}
|
|
77
|
-
*/
|
|
78
|
-
mode?: AccessMode;
|
|
79
|
-
/**
|
|
80
|
-
* Field access mode overrides per DataAPI action.
|
|
81
|
-
*/
|
|
82
|
-
modeOverrides?: Record<string, AccessMode>;
|
|
83
|
-
/**
|
|
84
|
-
* DB Fields that should be selected for this field.
|
|
85
|
-
*/
|
|
86
|
-
listable?: Record<string, string[]>;
|
|
87
|
-
/**
|
|
88
|
-
* Set of api methods for which the field must be set.
|
|
89
|
-
*/
|
|
90
|
-
mandatory?: Set<string>;
|
|
91
|
-
/**
|
|
92
|
-
* Whether the DataAPI can be sorted using this field.
|
|
93
|
-
*/
|
|
94
|
-
sortable?: {
|
|
95
|
-
indexed?: boolean;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Foreign key reference.
|
|
99
|
-
*
|
|
100
|
-
* `schemaName` is set when the target lives in another schema than the
|
|
101
|
-
* controller's table; runtime resolves the foreign lookup against that
|
|
102
|
-
* schema's default instance instead of the source instance.
|
|
103
|
-
*/
|
|
104
|
-
foreign?: [
|
|
105
|
-
table: string,
|
|
106
|
-
tableClass?: Class<Table>,
|
|
107
|
-
index?: string,
|
|
108
|
-
multi?: true,
|
|
109
|
-
pluck?: string[],
|
|
110
|
-
schemaName?: string,
|
|
111
|
-
targetJoined?: ForeignJoinedRef[]
|
|
112
|
-
];
|
|
113
|
-
/**
|
|
114
|
-
* Joined-from-other-table reference.
|
|
115
|
-
*
|
|
116
|
-
* Imports a single scalar field from another table at query time and
|
|
117
|
-
* flattens it into the row, enabling sort/search/filter natively in DB.
|
|
118
|
-
*
|
|
119
|
-
* `schemaName` is set when the target lives in another schema than the
|
|
120
|
-
* controller's table; runtime resolves the join against that schema's
|
|
121
|
-
* default instance instead of the source instance.
|
|
122
|
-
*/
|
|
123
|
-
joined?: {
|
|
124
|
-
table: string;
|
|
125
|
-
tableClass?: Class<Table>;
|
|
126
|
-
localKey: string;
|
|
127
|
-
remoteField: string;
|
|
128
|
-
remoteIndex: string;
|
|
129
|
-
schemaName?: string;
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* In-database computed value.
|
|
133
|
-
*
|
|
134
|
-
* The expression is merged into each row at query time, enabling sort,
|
|
135
|
-
* filter, and pagination natively in DB.
|
|
136
|
-
*/
|
|
137
|
-
computed?: ComputedFieldData;
|
|
138
|
-
/**
|
|
139
|
-
* Value validator callback.
|
|
140
|
-
*/
|
|
141
|
-
validator?: FieldValidator;
|
|
142
|
-
/**
|
|
143
|
-
* Field property descriptor.
|
|
144
|
-
*/
|
|
145
|
-
desc?: PropertyDescriptor;
|
|
146
|
-
/**
|
|
147
|
-
* Whether or not an `eq` filter with this field name can use an indexed lookup.
|
|
148
|
-
*/
|
|
149
|
-
indexable?: boolean;
|
|
150
|
-
}
|
|
151
16
|
/**
|
|
152
17
|
* The access a field has in one data API action (`get`, `list`, `new`,
|
|
153
18
|
* `edit`…): its {@link FieldData.modeOverrides} entry for that action, else
|
|
@@ -155,102 +20,35 @@ export interface FieldData {
|
|
|
155
20
|
* field's own mode.
|
|
156
21
|
*/
|
|
157
22
|
export declare function GetEffectiveMode(field: Pick<FieldData, "mode" | "modeOverrides">, action?: string): AccessMode | undefined;
|
|
158
|
-
/**
|
|
159
|
-
* In-database computed field expression.
|
|
160
|
-
*
|
|
161
|
-
* Receives the row proxy and the schema instance of the controller's table.
|
|
162
|
-
* May return a row-local expression (built from `row`) or a per-row subquery
|
|
163
|
-
* (ex: an aggregate over another table).
|
|
164
|
-
*/
|
|
165
|
-
export type ComputedExpression = (row: ValueProxy<Record<string, any>>, db: SchemaInstance<any>) => ValueProxyOrValue<unknown> | Query<unknown>;
|
|
166
|
-
/**
|
|
167
|
-
* Computed field options.
|
|
168
|
-
*/
|
|
169
|
-
export interface ComputedOptions {
|
|
170
|
-
/**
|
|
171
|
-
* Fallback merged over the computed value when the expression yields null
|
|
172
|
-
* (ex: `0` for an aggregate count over an empty set).
|
|
173
|
-
*/
|
|
174
|
-
default?: unknown;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Computed field information.
|
|
178
|
-
*/
|
|
179
|
-
export interface ComputedFieldData extends ComputedOptions {
|
|
180
|
-
expr: ComputedExpression;
|
|
181
|
-
}
|
|
182
|
-
type Comparison = "eq" | "ne" | "gt" | "ge" | "lt" | "le";
|
|
183
|
-
export type FilterValue = [value: string, mode: Comparison];
|
|
184
|
-
/**
|
|
185
|
-
* The filters of one field in a list request: one {@link FilterValue}, or
|
|
186
|
-
* several a row must all pass (`?filter_age=ge:18&filter_age=lt:65`).
|
|
187
|
-
*/
|
|
188
|
-
export type FieldFilter = FilterValue | FilterValue[];
|
|
189
23
|
/** The filters of one field as a list, whether it holds one or several. */
|
|
190
24
|
export declare function FilterValuesOf(filter: FieldFilter): FilterValue[];
|
|
191
|
-
/**
|
|
192
|
-
* Filter callback.
|
|
193
|
-
*/
|
|
194
|
-
export type FilterFunction<T extends Record<string, any>, U extends Record<string, any> = Record<string, any>> = (context: RequestContext & {
|
|
195
|
-
this: T;
|
|
196
|
-
}, proxy: ValueProxy<any>, key: string, value: FilterValue[0], mode: FilterValue[1], row: ValueProxy<U>) => ValueProxyOrValue<boolean>;
|
|
197
|
-
export interface ReadableAccessFields {
|
|
198
|
-
getters: [string, FieldData][];
|
|
199
|
-
props: [string, FieldData][];
|
|
200
|
-
}
|
|
201
|
-
export interface WritableAccessFields {
|
|
202
|
-
setters: [string, FieldData][];
|
|
203
|
-
props: [string, FieldData][];
|
|
204
|
-
}
|
|
205
25
|
/**
|
|
206
26
|
* Metadata Class containing the DataAPI information.
|
|
207
27
|
*/
|
|
208
28
|
export declare class DataAPIMeta {
|
|
209
29
|
readonly target: Class;
|
|
210
|
-
/**
|
|
211
|
-
* Key symbol.
|
|
212
|
-
*/
|
|
30
|
+
/** Key symbol. */
|
|
213
31
|
static key: symbol;
|
|
214
|
-
readonly filters: Record<string, FilterFunction<any>>;
|
|
215
|
-
/**
|
|
216
|
-
* Fields information.
|
|
217
|
-
*/
|
|
32
|
+
readonly filters: Record<string, FilterFunction<any, any>>;
|
|
33
|
+
/** Fields information. */
|
|
218
34
|
readonly fields: Record<string, FieldData>;
|
|
219
|
-
/**
|
|
220
|
-
* Fields to pluck in listing endpoints.
|
|
221
|
-
*/
|
|
35
|
+
/** Fields to pluck in listing endpoints. */
|
|
222
36
|
readonly pluck: Record<string, Set<string>>;
|
|
223
|
-
/**
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Keys of the DataAPI class containing database modifier keys.
|
|
229
|
-
*/
|
|
230
|
-
modifierKeys: Map<typeof ContainerModifier<any>, string>;
|
|
231
|
-
/**
|
|
232
|
-
* Schema name where the table is registered.
|
|
233
|
-
*/
|
|
37
|
+
/** Key of the DataAPI class containing a database table instance. */
|
|
38
|
+
modelKey?: PropertyKey;
|
|
39
|
+
/** Keys of the DataAPI class containing database modifier keys. */
|
|
40
|
+
modifierKeys: Map<typeof ContainerModifier<any>, PropertyKey>;
|
|
41
|
+
/** Schema name where the table is registered. */
|
|
234
42
|
schemaName: string;
|
|
235
|
-
/**
|
|
236
|
-
* Database Schema class.
|
|
237
|
-
*/
|
|
43
|
+
/** Database Schema class. */
|
|
238
44
|
tableClass: Class;
|
|
239
|
-
/**
|
|
240
|
-
* Database Schema table name.
|
|
241
|
-
*/
|
|
45
|
+
/** Database Schema table name. */
|
|
242
46
|
tableName: string;
|
|
243
|
-
/**
|
|
244
|
-
* Readable fields.
|
|
245
|
-
*/
|
|
47
|
+
/** Readable fields. */
|
|
246
48
|
readonly readable: Record<string, ReadableAccessFields>;
|
|
247
|
-
/**
|
|
248
|
-
* Writeable fields.
|
|
249
|
-
*/
|
|
49
|
+
/** Writeable fields. */
|
|
250
50
|
readonly writable: Record<string, WritableAccessFields>;
|
|
251
|
-
/**
|
|
252
|
-
* Registered DataAPI endpoints.
|
|
253
|
-
*/
|
|
51
|
+
/** Registered DataAPI endpoints. */
|
|
254
52
|
readonly endpoints: Record<string, DataControllerCallbackWithOptions>;
|
|
255
53
|
constructor(target: Class);
|
|
256
54
|
inherit(parent: DataAPIMeta): void;
|
|
@@ -285,7 +83,6 @@ export declare class DataAPIMeta {
|
|
|
285
83
|
* @param name Field name
|
|
286
84
|
* @param active Sortable
|
|
287
85
|
* @param noIndex Ignore database indexes
|
|
288
|
-
* @returns
|
|
289
86
|
*/
|
|
290
87
|
setSortable(name: string, active: boolean, noIndex?: boolean): this;
|
|
291
88
|
/**
|
|
@@ -325,8 +122,11 @@ export declare class DataAPIMeta {
|
|
|
325
122
|
* @param table Other table
|
|
326
123
|
* @param index Other table index
|
|
327
124
|
* @param multi Index is a multi index
|
|
125
|
+
* @param targetMeta Metadata of the target's data controller. Its `@Joined`
|
|
126
|
+
* fields that `pluck` names, or all of them when `pluck` is unset, are
|
|
127
|
+
* resolved on the relation unless it is `multi`.
|
|
328
128
|
*/
|
|
329
|
-
setForeign(name: string, table: string | Class<Table>, index
|
|
129
|
+
setForeign(name: string, table: string | Class<Table>, ...[index, multi, pluck, schema, targetMeta]: ForeignOptions): this;
|
|
330
130
|
/**
|
|
331
131
|
* Set the validation function of a field.
|
|
332
132
|
*
|
|
@@ -348,20 +148,20 @@ export declare class DataAPIMeta {
|
|
|
348
148
|
* @param func Filter callback
|
|
349
149
|
* @param index
|
|
350
150
|
*/
|
|
351
|
-
setFilter(name: string, func: FilterFunction<
|
|
151
|
+
setFilter(name: string, func: FilterFunction<any, any>, useIndex?: boolean): this;
|
|
352
152
|
/**
|
|
353
153
|
* Sets the key containing the database table instance.
|
|
354
154
|
*
|
|
355
155
|
* @param name Field name
|
|
356
156
|
*/
|
|
357
|
-
setModelKey(name:
|
|
157
|
+
setModelKey(name: PropertyKey): this;
|
|
358
158
|
/**
|
|
359
159
|
* Sets the key containing the key for the given database modifier.
|
|
360
160
|
*
|
|
361
161
|
* @param name Field name
|
|
362
162
|
* @param modifierClass Modifier
|
|
363
163
|
*/
|
|
364
|
-
setModifierKey(name:
|
|
164
|
+
setModifierKey(name: PropertyKey, modifierClass: typeof ContainerModifier<any>): this;
|
|
365
165
|
/**
|
|
366
166
|
* Adds the given endpoint to the DataAPI
|
|
367
167
|
*
|
|
@@ -463,7 +263,7 @@ export declare const Validator: (validator: FieldValidator) => import("@antelope
|
|
|
463
263
|
* to true for the default filter and false for custom filters. An indexed
|
|
464
264
|
* equality lookup uses the raw string and bypasses the callback.
|
|
465
265
|
*/
|
|
466
|
-
export declare
|
|
266
|
+
export declare function Filter<T extends Record<string, any>>(func?: FilterFunction<T, T>, useIndex?: boolean): (target: T, propertyKey: string | symbol) => void;
|
|
467
267
|
/**
|
|
468
268
|
* Sets which field will contain the reference to the database model instance.
|
|
469
269
|
*/
|
|
@@ -475,4 +275,3 @@ export declare const ModelReference: () => import("@antelopejs/interface-core/de
|
|
|
475
275
|
*/
|
|
476
276
|
export declare const ModifierKey: (modifierClass: typeof ContainerModifier<any>) => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
477
277
|
export declare function GetDataControllerMeta(thisObj: any): DataAPIMeta;
|
|
478
|
-
export {};
|