@antelopejs/interface-data-api 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.
- package/LICENSE +190 -0
- package/README.md +45 -0
- package/dist/antelope.test.d.ts +2 -0
- package/dist/antelope.test.js +59 -0
- package/dist/antelope.test.js.map +1 -0
- package/dist/components.d.ts +72 -0
- package/dist/components.js +344 -0
- package/dist/components.js.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +217 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata.d.ts +290 -0
- package/dist/metadata.js +444 -0
- package/dist/metadata.js.map +1 -0
- package/dist/tests/components/access_control.test.d.ts +1 -0
- package/dist/tests/components/access_control.test.js +138 -0
- package/dist/tests/components/access_control.test.js.map +1 -0
- package/dist/tests/components/listable.test.d.ts +1 -0
- package/dist/tests/components/listable.test.js +361 -0
- package/dist/tests/components/listable.test.js.map +1 -0
- package/dist/tests/components/mandatory.test.d.ts +1 -0
- package/dist/tests/components/mandatory.test.js +193 -0
- package/dist/tests/components/mandatory.test.js.map +1 -0
- package/dist/tests/components/per_action_access.test.d.ts +1 -0
- package/dist/tests/components/per_action_access.test.js +115 -0
- package/dist/tests/components/per_action_access.test.js.map +1 -0
- package/dist/tests/components/validator.test.d.ts +1 -0
- package/dist/tests/components/validator.test.js +178 -0
- package/dist/tests/components/validator.test.js.map +1 -0
- package/dist/tests/constants.d.ts +3 -0
- package/dist/tests/constants.js +7 -0
- package/dist/tests/constants.js.map +1 -0
- package/dist/tests/index/routes.test.d.ts +1 -0
- package/dist/tests/index/routes.test.js +210 -0
- package/dist/tests/index/routes.test.js.map +1 -0
- package/dist/tests/integration.test.d.ts +1 -0
- package/dist/tests/integration.test.js +838 -0
- package/dist/tests/integration.test.js.map +1 -0
- package/dist/tests/utils.d.ts +12 -0
- package/dist/tests/utils.js +70 -0
- package/dist/tests/utils.js.map +1 -0
- package/package.json +78 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DefaultRoutes = exports.RegisterDataController = void 0;
|
|
7
|
+
exports.DataController = DataController;
|
|
8
|
+
exports.GetDataControllerMeta = GetDataControllerMeta;
|
|
9
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
10
|
+
const interface_api_1 = require("@antelopejs/interface-api");
|
|
11
|
+
const interface_api_util_1 = require("@antelopejs/interface-api-util");
|
|
12
|
+
const interface_core_1 = require("@antelopejs/interface-core");
|
|
13
|
+
const decorators_1 = require("@antelopejs/interface-core/decorators");
|
|
14
|
+
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
15
|
+
const common_1 = require("@antelopejs/interface-database-decorators/modifiers/common");
|
|
16
|
+
const schema_1 = require("@antelopejs/interface-database-decorators/schema");
|
|
17
|
+
const components_1 = require("./components");
|
|
18
|
+
const metadata_1 = require("./metadata");
|
|
19
|
+
class TableHolder {
|
|
20
|
+
table;
|
|
21
|
+
}
|
|
22
|
+
function DataController(tableClass, def, base) {
|
|
23
|
+
const c = class extends base {
|
|
24
|
+
table;
|
|
25
|
+
};
|
|
26
|
+
const meta = (0, interface_core_1.GetMetadata)(c, metadata_1.DataAPIMeta);
|
|
27
|
+
const tableMetadata = (0, interface_database_decorators_1.getMetadata)(tableClass, interface_database_decorators_1.DatumStaticMetadata);
|
|
28
|
+
meta.schemaName = tableMetadata.schemaName || "default";
|
|
29
|
+
const databaseSchema = (0, schema_1.getTablesForSchema)(meta.schemaName);
|
|
30
|
+
(0, node_assert_1.default)(databaseSchema, "Non-existent Database Schema");
|
|
31
|
+
const tableName = Object.entries(databaseSchema).find(([, table]) => table === tableClass)?.[0];
|
|
32
|
+
(0, node_assert_1.default)(tableName, "Unregistered Database Table");
|
|
33
|
+
meta.tableClass = tableClass;
|
|
34
|
+
meta.tableName = tableName;
|
|
35
|
+
for (const [key, val] of Object.entries(def)) {
|
|
36
|
+
const entry = "func" in val
|
|
37
|
+
? { endpoint: key, callback: val }
|
|
38
|
+
: { endpoint: key, ...val };
|
|
39
|
+
meta.addEndpoint(key, entry);
|
|
40
|
+
// TODO?: should this go in addEndpoint?
|
|
41
|
+
c.prototype[key] = entry.callback.func;
|
|
42
|
+
}
|
|
43
|
+
return c;
|
|
44
|
+
}
|
|
45
|
+
exports.RegisterDataController = (0, decorators_1.MakeClassDecorator)((target) => {
|
|
46
|
+
const meta = (0, interface_core_1.GetMetadata)(target, metadata_1.DataAPIMeta);
|
|
47
|
+
for (const [key, entry] of Object.entries(meta.endpoints)) {
|
|
48
|
+
for (let i = 0; i < entry.callback.args.length; ++i) {
|
|
49
|
+
const arg = entry.callback.args[i];
|
|
50
|
+
if (Array.isArray(arg)) {
|
|
51
|
+
for (const step of arg) {
|
|
52
|
+
step(target.prototype, key, i);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
arg(target.prototype, key, i);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const meta = (0, interface_core_1.GetMetadata)(target, interface_api_1.ControllerMeta);
|
|
60
|
+
const fullLocation = `${meta.location}/${entry.endpoint ?? key}`.replace(/\/+/g, "/");
|
|
61
|
+
(0, interface_api_1.RegisterRoute)({
|
|
62
|
+
callback: (ctx) => {
|
|
63
|
+
ctx.dataAPIEntry = entry;
|
|
64
|
+
},
|
|
65
|
+
location: fullLocation,
|
|
66
|
+
method: entry.callback.method,
|
|
67
|
+
mode: "prefix",
|
|
68
|
+
parameters: [{ provider: (ctx) => ctx, modifiers: [] }],
|
|
69
|
+
properties: meta.computed_props,
|
|
70
|
+
proto: target.prototype,
|
|
71
|
+
});
|
|
72
|
+
(0, interface_api_1.Route)("handler", entry.callback.method, entry.endpoint)(target.prototype, key, {
|
|
73
|
+
value: entry.callback.func,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
function GetDataControllerMeta(thisObj) {
|
|
78
|
+
return (0, interface_core_1.GetMetadata)(Object.getPrototypeOf(thisObj).constructor, metadata_1.DataAPIMeta, true);
|
|
79
|
+
}
|
|
80
|
+
var DefaultRoutes;
|
|
81
|
+
(function (DefaultRoutes) {
|
|
82
|
+
class Methods {
|
|
83
|
+
async get(_reqCtx, params) {
|
|
84
|
+
const meta = GetDataControllerMeta(this);
|
|
85
|
+
const model = components_1.Query.GetModel(this, meta);
|
|
86
|
+
let query = components_1.Query.Get(model.table, params.id, params.index);
|
|
87
|
+
if (!params.noForeign) {
|
|
88
|
+
query = components_1.Query.Foreign(model.database, meta, query);
|
|
89
|
+
}
|
|
90
|
+
const dbResult = model.constructor.fromDatabase(await query);
|
|
91
|
+
(0, interface_api_util_1.assert)(dbResult, 404, "Not Found");
|
|
92
|
+
components_1.Validation.Unlock(this, meta, dbResult);
|
|
93
|
+
const results = await components_1.Query.ReadProperties(this, meta, dbResult, "get");
|
|
94
|
+
components_1.Validation.ClearInternal(meta, results);
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
async list(reqCtx, params) {
|
|
98
|
+
const meta = GetDataControllerMeta(this);
|
|
99
|
+
const model = components_1.Query.GetModel(this, meta);
|
|
100
|
+
const sort = params?.sortKey
|
|
101
|
+
? [params.sortKey, params.sortDirection]
|
|
102
|
+
: undefined;
|
|
103
|
+
let [query, queryTotal] = components_1.Query.List(this, meta, model.table, reqCtx, sort, params?.filters);
|
|
104
|
+
const pluck = meta.pluck[params.pluckMode ?? "list"];
|
|
105
|
+
(0, interface_api_util_1.assert)(params.noPluck || pluck, 400, `No fields found for pluckMode '${params.pluckMode ?? "list"}'`);
|
|
106
|
+
if (!params.noForeign) {
|
|
107
|
+
query = components_1.Query.Foreign(model.database, meta, query, params.noPluck ? undefined : pluck);
|
|
108
|
+
}
|
|
109
|
+
const offset = params.offset || 0;
|
|
110
|
+
const limit = params.limit || 10;
|
|
111
|
+
let queryPaged = query.slice(offset, limit);
|
|
112
|
+
if (!params.noPluck && pluck) {
|
|
113
|
+
queryPaged = queryPaged.pluck("_internal", ...pluck);
|
|
114
|
+
}
|
|
115
|
+
const [dbResult, dbTotal] = await Promise.all([queryPaged, queryTotal]);
|
|
116
|
+
const results = await Promise.all(dbResult.map((entry) => {
|
|
117
|
+
const entryInstance = model.constructor.fromDatabase(entry);
|
|
118
|
+
components_1.Validation.Unlock(this, meta, entryInstance);
|
|
119
|
+
return components_1.Query.ReadProperties(this, meta, entryInstance, "list");
|
|
120
|
+
}));
|
|
121
|
+
components_1.Validation.ClearInternal(meta, results);
|
|
122
|
+
return {
|
|
123
|
+
results,
|
|
124
|
+
total: dbTotal,
|
|
125
|
+
offset,
|
|
126
|
+
limit,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async new(_reqCtx, params, body) {
|
|
130
|
+
const meta = GetDataControllerMeta(this);
|
|
131
|
+
const data = JSON.parse(body.toString());
|
|
132
|
+
if (!params.noMandatory) {
|
|
133
|
+
components_1.Validation.MandatoryFields(meta, data, "new");
|
|
134
|
+
}
|
|
135
|
+
await components_1.Validation.ValidateTypes(meta, data);
|
|
136
|
+
const dbData = await components_1.Query.WriteProperties(this, meta, data, "new");
|
|
137
|
+
components_1.Validation.Lock(this, meta, dbData);
|
|
138
|
+
const model = components_1.Query.GetModel(this, meta);
|
|
139
|
+
(0, common_1.triggerEvent)(dbData, "insert");
|
|
140
|
+
const dbResult = await model.table.insert(dbData);
|
|
141
|
+
return dbResult;
|
|
142
|
+
}
|
|
143
|
+
async edit(_reqCtx, params, body) {
|
|
144
|
+
const meta = GetDataControllerMeta(this);
|
|
145
|
+
const data = JSON.parse(body.toString());
|
|
146
|
+
if (!params.noMandatory) {
|
|
147
|
+
components_1.Validation.MandatoryFields(meta, data, "edit");
|
|
148
|
+
}
|
|
149
|
+
await components_1.Validation.ValidateTypes(meta, data);
|
|
150
|
+
const model = components_1.Query.GetModel(this, meta);
|
|
151
|
+
const queryPrevious = components_1.Query.Get(model.table, params.id, params.index);
|
|
152
|
+
const dbResultPrevious = await queryPrevious;
|
|
153
|
+
const dbData = await components_1.Query.WriteProperties(this, meta, data, "edit", dbResultPrevious);
|
|
154
|
+
components_1.Validation.Lock(this, meta, dbData);
|
|
155
|
+
(0, common_1.triggerEvent)(dbData, "update");
|
|
156
|
+
await model.table.get(params.id).update(dbData);
|
|
157
|
+
}
|
|
158
|
+
async delete(_reqCtx, params) {
|
|
159
|
+
const meta = GetDataControllerMeta(this);
|
|
160
|
+
const model = components_1.Query.GetModel(this, meta);
|
|
161
|
+
const query = components_1.Query.Delete(model.table, params.id);
|
|
162
|
+
// Promise.all(ids.map(id => table.get(id).delete().then(() => true).catch(() => false)));
|
|
163
|
+
const dbResult = await query;
|
|
164
|
+
return dbResult;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
DefaultRoutes.Get = {
|
|
168
|
+
func: Methods.prototype.get,
|
|
169
|
+
args: [(0, interface_api_1.Context)(), components_1.Parameters.Get()],
|
|
170
|
+
method: "get",
|
|
171
|
+
};
|
|
172
|
+
DefaultRoutes.List = {
|
|
173
|
+
func: Methods.prototype.list,
|
|
174
|
+
args: [(0, interface_api_1.Context)(), components_1.Parameters.List()],
|
|
175
|
+
method: "get",
|
|
176
|
+
};
|
|
177
|
+
DefaultRoutes.New = {
|
|
178
|
+
func: Methods.prototype.new,
|
|
179
|
+
args: [(0, interface_api_1.Context)(), components_1.Parameters.New(), (0, interface_api_1.RawBody)()],
|
|
180
|
+
method: "post",
|
|
181
|
+
};
|
|
182
|
+
DefaultRoutes.Edit = {
|
|
183
|
+
func: Methods.prototype.edit,
|
|
184
|
+
args: [(0, interface_api_1.Context)(), components_1.Parameters.Edit(), (0, interface_api_1.RawBody)()],
|
|
185
|
+
method: "put",
|
|
186
|
+
};
|
|
187
|
+
DefaultRoutes.Delete = {
|
|
188
|
+
func: Methods.prototype.delete,
|
|
189
|
+
args: [(0, interface_api_1.Context)(), components_1.Parameters.Delete()],
|
|
190
|
+
method: "delete",
|
|
191
|
+
};
|
|
192
|
+
DefaultRoutes.All = {
|
|
193
|
+
get: DefaultRoutes.Get,
|
|
194
|
+
list: DefaultRoutes.List,
|
|
195
|
+
new: DefaultRoutes.New,
|
|
196
|
+
edit: DefaultRoutes.Edit,
|
|
197
|
+
delete: DefaultRoutes.Delete,
|
|
198
|
+
};
|
|
199
|
+
function WithOptions(callback, options, endpoint) {
|
|
200
|
+
if ("func" in callback) {
|
|
201
|
+
return {
|
|
202
|
+
endpoint,
|
|
203
|
+
options,
|
|
204
|
+
callback,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return {
|
|
209
|
+
endpoint: endpoint ?? callback.endpoint,
|
|
210
|
+
options: { ...(callback.options ?? {}), ...(options ?? {}) },
|
|
211
|
+
callback: callback.callback,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
DefaultRoutes.WithOptions = WithOptions;
|
|
216
|
+
})(DefaultRoutes || (exports.DefaultRoutes = DefaultRoutes = {}));
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAwDA,wCAqCC;AAyCD,sDAMC;AA5ID,8DAAkC;AAClC,6DAQmC;AACnC,uEAAwD;AACxD,+DAAyD;AACzD,sEAI+C;AAC/C,6FAGmD;AACnD,uFAA0F;AAC1F,6EAAsF;AACtF,6CAA6D;AAC7D,yCAAyC;AA4BzC,MAAe,WAAW;IACxB,KAAK,CAAmB;CACzB;AAED,SAAgB,cAAc,CAK5B,UAAa,EACb,GAAM,EACN,IAAU;IAEV,MAAM,CAAC,GAAG,KAAM,SAAQ,IAAI;QAC1B,KAAK,CAAmB;KACzB,CAAC;IACF,MAAM,IAAI,GA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MgB,aAAa,6BAAb,aAAa,QA+M7B"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import type { RequestContext } from "@antelopejs/interface-api";
|
|
2
|
+
import { type Class } from "@antelopejs/interface-core/decorators";
|
|
3
|
+
import type { ValueProxy, ValueProxyOrValue } from "@antelopejs/interface-database";
|
|
4
|
+
import { type Table } from "@antelopejs/interface-database-decorators";
|
|
5
|
+
import type { ContainerModifier } from "@antelopejs/interface-database-decorators/modifiers/common";
|
|
6
|
+
import type { DataControllerCallbackWithOptions } from ".";
|
|
7
|
+
/**
|
|
8
|
+
* Field access mode enum.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum AccessMode {
|
|
11
|
+
ReadOnly = 1,
|
|
12
|
+
WriteOnly = 2,
|
|
13
|
+
ReadWrite = 3
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* DataAPI Metadata field information.
|
|
17
|
+
*/
|
|
18
|
+
export interface FieldData {
|
|
19
|
+
/**
|
|
20
|
+
* Field name in-database.
|
|
21
|
+
*/
|
|
22
|
+
dbName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Field access mode.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link AccessMode}
|
|
27
|
+
*/
|
|
28
|
+
mode?: AccessMode;
|
|
29
|
+
/**
|
|
30
|
+
* Field access mode overrides per DataAPI action.
|
|
31
|
+
*/
|
|
32
|
+
modeOverrides?: Record<string, AccessMode>;
|
|
33
|
+
/**
|
|
34
|
+
* DB Fields that should be selected for this field.
|
|
35
|
+
*/
|
|
36
|
+
listable?: Record<string, string[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Set of api methods for which the field must be set.
|
|
39
|
+
*/
|
|
40
|
+
mandatory?: Set<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the DataAPI can be sorted using this field.
|
|
43
|
+
*/
|
|
44
|
+
sortable?: {
|
|
45
|
+
indexed?: boolean;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Foreign key reference.
|
|
49
|
+
*/
|
|
50
|
+
foreign?: [
|
|
51
|
+
table: string,
|
|
52
|
+
tableClass?: Class<Table>,
|
|
53
|
+
index?: string,
|
|
54
|
+
multi?: true,
|
|
55
|
+
pluck?: string[]
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Value validator callback.
|
|
59
|
+
*/
|
|
60
|
+
validator?: (value: unknown) => boolean | Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Field property descriptor.
|
|
63
|
+
*/
|
|
64
|
+
desc?: PropertyDescriptor;
|
|
65
|
+
/**
|
|
66
|
+
* Whether or not an `eq` filter with this field name can use an indexed lookup.
|
|
67
|
+
*/
|
|
68
|
+
indexable?: boolean;
|
|
69
|
+
}
|
|
70
|
+
type Comparison = "eq" | "ne" | "gt" | "ge" | "lt" | "le";
|
|
71
|
+
export type FilterValue = [value: string, mode: Comparison];
|
|
72
|
+
/**
|
|
73
|
+
* Filter callback.
|
|
74
|
+
*/
|
|
75
|
+
export type FilterFunction<T extends Record<string, any>, U extends Record<string, any> = Record<string, any>> = (context: RequestContext & {
|
|
76
|
+
this: T;
|
|
77
|
+
}, proxy: ValueProxy<any>, key: string, value: FilterValue[0], mode: FilterValue[1], row: ValueProxy<U>) => ValueProxyOrValue<boolean>;
|
|
78
|
+
export interface ReadableAccessFields {
|
|
79
|
+
getters: [string, FieldData][];
|
|
80
|
+
props: [string, FieldData][];
|
|
81
|
+
}
|
|
82
|
+
export interface WritableAccessFields {
|
|
83
|
+
setters: [string, FieldData][];
|
|
84
|
+
props: [string, FieldData][];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Metadata Class containing the DataAPI information.
|
|
88
|
+
*/
|
|
89
|
+
export declare class DataAPIMeta {
|
|
90
|
+
readonly target: Class;
|
|
91
|
+
/**
|
|
92
|
+
* Key symbol.
|
|
93
|
+
*/
|
|
94
|
+
static key: symbol;
|
|
95
|
+
readonly filters: Record<string, FilterFunction<any>>;
|
|
96
|
+
/**
|
|
97
|
+
* Fields information.
|
|
98
|
+
*/
|
|
99
|
+
readonly fields: Record<string, FieldData>;
|
|
100
|
+
/**
|
|
101
|
+
* Fields to pluck in listing endpoints.
|
|
102
|
+
*/
|
|
103
|
+
readonly pluck: Record<string, Set<string>>;
|
|
104
|
+
/**
|
|
105
|
+
* Key of the DataAPI class containing a database table instance.
|
|
106
|
+
*/
|
|
107
|
+
modelKey?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Keys of the DataAPI class containing database modifier keys.
|
|
110
|
+
*/
|
|
111
|
+
modifierKeys: Map<typeof ContainerModifier<any>, string>;
|
|
112
|
+
/**
|
|
113
|
+
* Schema name where the table is registered.
|
|
114
|
+
*/
|
|
115
|
+
schemaName: string;
|
|
116
|
+
/**
|
|
117
|
+
* Database Schema class.
|
|
118
|
+
*/
|
|
119
|
+
tableClass: Class;
|
|
120
|
+
/**
|
|
121
|
+
* Database Schema table name.
|
|
122
|
+
*/
|
|
123
|
+
tableName: string;
|
|
124
|
+
/**
|
|
125
|
+
* Readable fields.
|
|
126
|
+
*/
|
|
127
|
+
readonly readable: Record<string, ReadableAccessFields>;
|
|
128
|
+
/**
|
|
129
|
+
* Writeable fields.
|
|
130
|
+
*/
|
|
131
|
+
readonly writable: Record<string, WritableAccessFields>;
|
|
132
|
+
/**
|
|
133
|
+
* Registered DataAPI endpoints.
|
|
134
|
+
*/
|
|
135
|
+
readonly endpoints: Record<string, DataControllerCallbackWithOptions>;
|
|
136
|
+
constructor(target: Class);
|
|
137
|
+
inherit(parent: DataAPIMeta): void;
|
|
138
|
+
private field;
|
|
139
|
+
private recomputeListable;
|
|
140
|
+
private recomputeAccess;
|
|
141
|
+
/**
|
|
142
|
+
* Sets the access mode of the given field.
|
|
143
|
+
*
|
|
144
|
+
* @param name Field name
|
|
145
|
+
* @param mode Access mode
|
|
146
|
+
*/
|
|
147
|
+
setMode(name: string, mode: AccessMode, overrides?: Record<string, AccessMode>): this;
|
|
148
|
+
/**
|
|
149
|
+
* Sets whether a field should be included in list endpoints.
|
|
150
|
+
*
|
|
151
|
+
* @param name Field name
|
|
152
|
+
* @param requiredFields Boolean or table field list
|
|
153
|
+
* @param mode List mode (default: 'list')
|
|
154
|
+
*/
|
|
155
|
+
setListable(name: string, requiredFields: boolean | string[], mode?: string): this;
|
|
156
|
+
/**
|
|
157
|
+
* Sets whether or not this field must be present in requests for the given method.
|
|
158
|
+
*
|
|
159
|
+
* @param name Field name
|
|
160
|
+
* @param modes DataAPI methods
|
|
161
|
+
*/
|
|
162
|
+
setMandatory(name: string, modes: string[]): this;
|
|
163
|
+
/**
|
|
164
|
+
* Sets whether or not this field can be used to sort in list endpoints.
|
|
165
|
+
*
|
|
166
|
+
* @param name Field name
|
|
167
|
+
* @param active Sortable
|
|
168
|
+
* @param noIndex Ignore database indexes
|
|
169
|
+
* @returns
|
|
170
|
+
*/
|
|
171
|
+
setSortable(name: string, active: boolean, noIndex?: boolean): this;
|
|
172
|
+
/**
|
|
173
|
+
* Declares a field to be a foreign key.
|
|
174
|
+
*
|
|
175
|
+
* @param name Field name
|
|
176
|
+
* @param table Other table
|
|
177
|
+
* @param index Other table index
|
|
178
|
+
* @param multi Index is a multi index
|
|
179
|
+
*/
|
|
180
|
+
setForeign(name: string, table: string | Class<Table>, index?: string, multi?: boolean, pluck?: string[]): this;
|
|
181
|
+
/**
|
|
182
|
+
* Set the validation function of a field.
|
|
183
|
+
*
|
|
184
|
+
* @param name Field name
|
|
185
|
+
* @param validator Value validator callback
|
|
186
|
+
*/
|
|
187
|
+
setValidator(name: string, validator?: (value: unknown) => boolean | Promise<boolean>): this;
|
|
188
|
+
/**
|
|
189
|
+
* Updates the known field descriptor of this field.
|
|
190
|
+
*
|
|
191
|
+
* @param name Field name
|
|
192
|
+
* @param desc Field descriptor
|
|
193
|
+
*/
|
|
194
|
+
setDescriptor(name: string, desc?: PropertyDescriptor): this;
|
|
195
|
+
/**
|
|
196
|
+
* Creates a filter.
|
|
197
|
+
*
|
|
198
|
+
* @param name Filter name
|
|
199
|
+
* @param func Filter callback
|
|
200
|
+
* @param index
|
|
201
|
+
*/
|
|
202
|
+
setFilter(name: string, func: FilterFunction<Record<string, any>, Record<string, any>>, useIndex?: boolean): this;
|
|
203
|
+
/**
|
|
204
|
+
* Sets the key containing the database table instance.
|
|
205
|
+
*
|
|
206
|
+
* @param name Field name
|
|
207
|
+
*/
|
|
208
|
+
setModelKey(name: string): this;
|
|
209
|
+
/**
|
|
210
|
+
* Sets the key containing the key for the given database modifier.
|
|
211
|
+
*
|
|
212
|
+
* @param name Field name
|
|
213
|
+
* @param modifierClass Modifier
|
|
214
|
+
*/
|
|
215
|
+
setModifierKey(name: string, modifierClass: typeof ContainerModifier<any>): this;
|
|
216
|
+
/**
|
|
217
|
+
* Adds the given endpoint to the DataAPI
|
|
218
|
+
*
|
|
219
|
+
* @param key field name
|
|
220
|
+
* @param endpoint callback information
|
|
221
|
+
*/
|
|
222
|
+
addEndpoint(key: string, endpoint?: DataControllerCallbackWithOptions): void;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Sets the access mode of a DataAPI field.
|
|
226
|
+
*
|
|
227
|
+
* @param mode Access mode
|
|
228
|
+
*/
|
|
229
|
+
export declare const Access: (mode: AccessMode, overrides?: Record<string, AccessMode> | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
230
|
+
/**
|
|
231
|
+
* Sets the listable state of a DataAPI field.
|
|
232
|
+
*
|
|
233
|
+
* Listable fields will be included in list method calls.
|
|
234
|
+
*
|
|
235
|
+
* Listable getters must specificy the list of in-database field names they use.
|
|
236
|
+
*
|
|
237
|
+
* @param requiredFields Boolean or table field list
|
|
238
|
+
*/
|
|
239
|
+
export declare const Listable: (requiredFields?: boolean | string[] | undefined, mode?: string | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
240
|
+
/**
|
|
241
|
+
* Declares a field to be mandatory in calls to the given methods.
|
|
242
|
+
*
|
|
243
|
+
* @param modes DataAPI methods (ex: `new`, `edit`)
|
|
244
|
+
*/
|
|
245
|
+
export declare const Mandatory: (...args: string[]) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
246
|
+
/**
|
|
247
|
+
* Declares a field as being optional.
|
|
248
|
+
*
|
|
249
|
+
* This must be used on fields with no other decorators.
|
|
250
|
+
*/
|
|
251
|
+
export declare const Optional: () => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
252
|
+
/**
|
|
253
|
+
* Declares a field to be useable as the sorting key.
|
|
254
|
+
*
|
|
255
|
+
* @param options Options
|
|
256
|
+
*/
|
|
257
|
+
export declare const Sortable: (options?: {
|
|
258
|
+
noIndex?: boolean;
|
|
259
|
+
} | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
260
|
+
/**
|
|
261
|
+
* Declares a field to be a foreign key.
|
|
262
|
+
*
|
|
263
|
+
* @param table Other table
|
|
264
|
+
* @param index Other table index
|
|
265
|
+
* @param multi Index is a multi index
|
|
266
|
+
*/
|
|
267
|
+
export declare const Foreign: (table: string | Class<Table>, index?: string | undefined, multi?: boolean | undefined, pluck?: string[] | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
268
|
+
/**
|
|
269
|
+
* Set the validation function of a field.
|
|
270
|
+
*
|
|
271
|
+
* @param validator Value validator callback
|
|
272
|
+
*/
|
|
273
|
+
export declare const Validator: (validator: (val: unknown) => boolean | Promise<boolean>) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").MethodDecorator;
|
|
274
|
+
/**
|
|
275
|
+
* Creates a field filter.
|
|
276
|
+
*
|
|
277
|
+
* @param func Custom filter function
|
|
278
|
+
*/
|
|
279
|
+
export declare const Filter: <T extends Record<string, any>>(func?: FilterFunction<T, T>, useIndex?: boolean) => (target: T, propertyKey: string | symbol) => void;
|
|
280
|
+
/**
|
|
281
|
+
* Sets which field will contain the reference to the database model instance.
|
|
282
|
+
*/
|
|
283
|
+
export declare const ModelReference: () => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
284
|
+
/**
|
|
285
|
+
* Sets which field will contain the key for the given database modifier.
|
|
286
|
+
*
|
|
287
|
+
* @param modifierClass Modifier
|
|
288
|
+
*/
|
|
289
|
+
export declare const ModifierKey: (modifierClass: typeof ContainerModifier<any>) => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
290
|
+
export {};
|