suppa-mcp-2 1.0.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/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/auth.js +612 -0
- package/dist/bin.js +11 -0
- package/dist/config.js +168 -0
- package/dist/httpClient.js +269 -0
- package/dist/registry.js +111 -0
- package/dist/server.js +1533 -0
- package/dist/store.js +120 -0
- package/dist/tenants.js +408 -0
- package/dist/tools/automation.js +776 -0
- package/dist/tools/docs.js +534 -0
- package/dist/tools/entity.js +831 -0
- package/dist/tools/forms.js +550 -0
- package/dist/tools/migrate.js +936 -0
- package/dist/tools/nameMap.js +134 -0
- package/dist/tools/tasks.js +423 -0
- package/dist/tools/v1Fields.js +0 -0
- package/dist/tools/workspace.js +121 -0
- package/dist/utils.js +391 -0
- package/package.json +26 -0
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity, Schema, Fields, and Enums tools.
|
|
3
|
+
*
|
|
4
|
+
* Faithful 1:1 port of the Python `suppa_mcp/tools/entity.py`.
|
|
5
|
+
*
|
|
6
|
+
* NOTE ON CONFIRM-GATING: in the Python package the approval gate for
|
|
7
|
+
* update_record / delete_record lives in the SERVER layer (server.py wraps the
|
|
8
|
+
* tool with a `confirm` parameter and returns confirm_required(...) before
|
|
9
|
+
* calling into this module). This module — like entity.py — performs the write
|
|
10
|
+
* directly; the ported offline tests call updateRecord without confirm and
|
|
11
|
+
* expect the write to proceed. The confirmRequired gate is applied by the tool
|
|
12
|
+
* registration layer, not here.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, statSync } from "node:fs";
|
|
15
|
+
import { basename } from "node:path";
|
|
16
|
+
import { makeRequest, makeRequestRawBytes, searchEntity, selectEntity, insertEntity, updateEntity, removeEntity, } from "../httpClient.js";
|
|
17
|
+
import { buildFileUpload, makeFilter, jsonResponse, parseJsonParam } from "../utils.js";
|
|
18
|
+
// Builder field types that accept file uploads.
|
|
19
|
+
export const FILE_FIELD_TYPES = ["file", "multi-file"];
|
|
20
|
+
export const RELATION_FIELD_TYPES = [
|
|
21
|
+
"many-to-one",
|
|
22
|
+
"one-to-many",
|
|
23
|
+
"many-to-many",
|
|
24
|
+
"many-to-many-backref",
|
|
25
|
+
];
|
|
26
|
+
// Every type the 2.0 builder accepts — used to reject typos client-side with a
|
|
27
|
+
// clear message instead of an opaque server 400.
|
|
28
|
+
export const VALID_FIELD_TYPES = [
|
|
29
|
+
"text",
|
|
30
|
+
"numeric",
|
|
31
|
+
"integer",
|
|
32
|
+
"serial",
|
|
33
|
+
"boolean",
|
|
34
|
+
"timestamp",
|
|
35
|
+
"json",
|
|
36
|
+
"uuid",
|
|
37
|
+
"multi-language",
|
|
38
|
+
"icon",
|
|
39
|
+
"enum",
|
|
40
|
+
"multi-enum",
|
|
41
|
+
"file",
|
|
42
|
+
"multi-file",
|
|
43
|
+
...RELATION_FIELD_TYPES,
|
|
44
|
+
];
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Tools
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Keys kept per entity in the default (slim) list_entities output. The raw
|
|
49
|
+
// schema listing can carry full field definitions per entity — hundreds of KB
|
|
50
|
+
// the model rarely needs at the listing stage (describe_entity has the rest).
|
|
51
|
+
const _ENTITY_SUMMARY_KEYS = [
|
|
52
|
+
"id",
|
|
53
|
+
"name",
|
|
54
|
+
"title",
|
|
55
|
+
"alias",
|
|
56
|
+
"titleFieldName",
|
|
57
|
+
"system",
|
|
58
|
+
"builtin",
|
|
59
|
+
"description",
|
|
60
|
+
];
|
|
61
|
+
/**
|
|
62
|
+
* List all entities (tables) available on the platform.
|
|
63
|
+
*
|
|
64
|
+
* Default output is a slim summary per entity; pass full=True for the raw rows.
|
|
65
|
+
*/
|
|
66
|
+
export async function listEntities(search = "", full = false) {
|
|
67
|
+
let result = await makeRequest("GET", "/api/core/schema");
|
|
68
|
+
if (Array.isArray(result) && search) {
|
|
69
|
+
const searchLower = search.toLowerCase();
|
|
70
|
+
result = result.filter((e) => e !== null &&
|
|
71
|
+
typeof e === "object" &&
|
|
72
|
+
!Array.isArray(e) &&
|
|
73
|
+
(String(e.name ?? "").toLowerCase().includes(searchLower) ||
|
|
74
|
+
String(e.title ?? "").toLowerCase().includes(searchLower)));
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(result) && !full) {
|
|
77
|
+
result = result.map((e) => {
|
|
78
|
+
if (e !== null && typeof e === "object" && !Array.isArray(e)) {
|
|
79
|
+
const src = e;
|
|
80
|
+
const slim = {};
|
|
81
|
+
for (const k of _ENTITY_SUMMARY_KEYS) {
|
|
82
|
+
if (k in src) {
|
|
83
|
+
slim[k] = src[k];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return slim;
|
|
87
|
+
}
|
|
88
|
+
return e;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return jsonResponse(result);
|
|
92
|
+
}
|
|
93
|
+
/** Get full schema of an entity including all fields, relations, and their types. */
|
|
94
|
+
export async function describeEntity(entityName) {
|
|
95
|
+
const result = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
96
|
+
return jsonResponse(result);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Search records of any entity with filters.
|
|
100
|
+
* filters_json: JSON array of filter objects [{field, value, comparator}].
|
|
101
|
+
* fields_json: JSON object specifying which fields to return.
|
|
102
|
+
* order_by: 'field:direction' (e.g. 'createdAt:desc').
|
|
103
|
+
* match_any: when True, filters are combined with OR instead of AND.
|
|
104
|
+
*
|
|
105
|
+
* Returns {"records": [...], "returned": N, "has_more": bool, "next_offset": int|null}.
|
|
106
|
+
*/
|
|
107
|
+
export async function searchRecords(entityName, filtersJson = "[]", fieldsJson = '{"id": true}', limit = 20, offset = 0, search = "", orderBy = "createdAt:desc", matchAny = false) {
|
|
108
|
+
let filters;
|
|
109
|
+
let fields;
|
|
110
|
+
try {
|
|
111
|
+
filters = parseJsonParam(filtersJson, "filters_json");
|
|
112
|
+
fields = parseJsonParam(fieldsJson, "fields_json");
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
|
|
116
|
+
}
|
|
117
|
+
// Tolerate common near-miss shapes instead of erroring:
|
|
118
|
+
// a single filter object -> one-element list; a list of field names -> projection.
|
|
119
|
+
if (filters !== null && typeof filters === "object" && !Array.isArray(filters)) {
|
|
120
|
+
filters = [filters];
|
|
121
|
+
}
|
|
122
|
+
if (Array.isArray(fields)) {
|
|
123
|
+
const proj = {};
|
|
124
|
+
for (const f of fields) {
|
|
125
|
+
proj[String(f)] = true;
|
|
126
|
+
}
|
|
127
|
+
fields = proj;
|
|
128
|
+
}
|
|
129
|
+
const idx = orderBy.indexOf(":");
|
|
130
|
+
const field = idx === -1 ? orderBy : orderBy.slice(0, idx);
|
|
131
|
+
const rawDir = idx === -1 ? "" : orderBy.slice(idx + 1);
|
|
132
|
+
const direction = rawDir.trim().toLowerCase() || "desc";
|
|
133
|
+
if (direction !== "asc" && direction !== "desc") {
|
|
134
|
+
return jsonResponse({
|
|
135
|
+
error: `order_by direction must be 'asc' or 'desc', got '${direction}'.`,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const order = [{ field: field.trim() || "createdAt", order: direction }];
|
|
139
|
+
// Fetch one extra row so the agent learns whether another page exists.
|
|
140
|
+
// Cap at 500/page: larger responses blow the model's context — page instead.
|
|
141
|
+
limit = Math.max(1, Math.min(limit, 500));
|
|
142
|
+
const rows = await searchEntity(entityName, filters, fields, limit + 1, offset, order, search, matchAny ? "or" : "and");
|
|
143
|
+
const hasMore = rows.length > limit;
|
|
144
|
+
return jsonResponse({
|
|
145
|
+
records: rows.slice(0, limit),
|
|
146
|
+
returned: Math.min(rows.length, limit),
|
|
147
|
+
has_more: hasMore,
|
|
148
|
+
next_offset: hasMore ? offset + limit : null,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** Get a single record of any entity by its numeric id. */
|
|
152
|
+
export async function getRecord(entityName, recordId, fieldsJson = '{"id": true}') {
|
|
153
|
+
let fields;
|
|
154
|
+
try {
|
|
155
|
+
fields = parseJsonParam(fieldsJson, "fields_json", "object");
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
|
|
159
|
+
}
|
|
160
|
+
const result = await selectEntity(entityName, [makeFilter("id", recordId)], fields);
|
|
161
|
+
if (result === null) {
|
|
162
|
+
return jsonResponse({
|
|
163
|
+
error: `No record ${recordId} in '${entityName}' (wrong id, deleted, or no access).`,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return jsonResponse(result);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a new entity (database table) on the platform.
|
|
170
|
+
*
|
|
171
|
+
* By default also creates the display-title field named by title_field_name
|
|
172
|
+
* (type title_field_type, default 'multi-language') so records have a label
|
|
173
|
+
* and the entity's titleFieldName resolves to a real field. Pass
|
|
174
|
+
* auto_title_field=False when the caller adds its own fields (e.g. migration),
|
|
175
|
+
* to avoid a type clash with a field of the same name added later.
|
|
176
|
+
*/
|
|
177
|
+
export async function createEntity(name, title, titleFieldName = "title", autoTitleField = true, titleFieldType = "multi-language") {
|
|
178
|
+
const body = {
|
|
179
|
+
name,
|
|
180
|
+
title: isPlainObject(title) ? title : { en: title },
|
|
181
|
+
titleFieldName,
|
|
182
|
+
fields: [],
|
|
183
|
+
};
|
|
184
|
+
const result = await makeRequest("POST", "/api/core/builder/create-entity", body);
|
|
185
|
+
let titleFieldResult = null;
|
|
186
|
+
if (autoTitleField && titleFieldName) {
|
|
187
|
+
titleFieldResult = _parseMaybe(await addField(name, titleFieldName, titleFieldType, title));
|
|
188
|
+
}
|
|
189
|
+
// NOTE: we deliberately do NOT auto-set the representative field here. The only
|
|
190
|
+
// builder endpoint that accepts it (POST /builder/{entity}/update with
|
|
191
|
+
// {representativeField:{id}}) proved unreliable in live testing (worked on some
|
|
192
|
+
// entities, returned HTTP 500 on others) — too risky to run on every create.
|
|
193
|
+
// Use suppa_set_title_field explicitly, or set the representative in the UI.
|
|
194
|
+
return jsonResponse({ entity: result, title_field: titleFieldResult });
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Create a tabular part (ТЧ / "таблична частина") — an owned child sub-table
|
|
198
|
+
* of parent_entity, NOT a standalone entity.
|
|
199
|
+
*
|
|
200
|
+
* Use this (instead of create_entity) whenever a child holds repeating rows that
|
|
201
|
+
* belong to ONE parent record: invoice line-items, "X by category" breakdowns,
|
|
202
|
+
* per-period rows, etc. Creating those as a separate entity is wrong — they must
|
|
203
|
+
* be a tabular part so they nest under the parent and are edited inline.
|
|
204
|
+
*
|
|
205
|
+
* The platform creates the child with ``type="tabular-part"``, auto-adds a system
|
|
206
|
+
* ``owner`` (many-to-one → parent) field, and lists it under the parent's
|
|
207
|
+
* ``/tabular-parts``. Add data fields afterwards with add_field, exactly like a
|
|
208
|
+
* normal entity.
|
|
209
|
+
*
|
|
210
|
+
* By the platform convention the stored entity name is ``parent_entity + name``
|
|
211
|
+
* (concatenated, as the builder UI does); if ``name`` already starts with the
|
|
212
|
+
* parent name it is not prefixed again. Pass ``full_name`` to set the exact
|
|
213
|
+
* stored name yourself.
|
|
214
|
+
*/
|
|
215
|
+
export async function createTabularPart(parentEntity, name, title, titleFieldName = "title", autoTitleField = true, titleFieldType = "multi-language", fullName) {
|
|
216
|
+
let entityName;
|
|
217
|
+
if (fullName) {
|
|
218
|
+
entityName = fullName;
|
|
219
|
+
}
|
|
220
|
+
else if (name.startsWith(parentEntity)) {
|
|
221
|
+
entityName = name;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
entityName = parentEntity + name;
|
|
225
|
+
}
|
|
226
|
+
const body = {
|
|
227
|
+
name: entityName,
|
|
228
|
+
title: isPlainObject(title) ? title : { en: title },
|
|
229
|
+
titleFieldName,
|
|
230
|
+
type: "tabular-part",
|
|
231
|
+
relationEntityName: parentEntity,
|
|
232
|
+
fields: [],
|
|
233
|
+
};
|
|
234
|
+
const result = await makeRequest("POST", "/api/core/builder/create-entity", body);
|
|
235
|
+
let titleFieldResult = null;
|
|
236
|
+
if (autoTitleField && titleFieldName) {
|
|
237
|
+
titleFieldResult = _parseMaybe(await addField(entityName, titleFieldName, titleFieldType, title));
|
|
238
|
+
}
|
|
239
|
+
return jsonResponse({
|
|
240
|
+
tabular_part: result,
|
|
241
|
+
entity_name: entityName,
|
|
242
|
+
parent_entity: parentEntity,
|
|
243
|
+
title_field: titleFieldResult,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* List the tabular parts (owned child sub-tables) of an entity.
|
|
248
|
+
*
|
|
249
|
+
* Calls ``GET /api/core/schema/{entity}/tabular-parts``. Each result has
|
|
250
|
+
* ``type="tabular-part"`` and a ``relationEntity`` pointing back to the parent.
|
|
251
|
+
*/
|
|
252
|
+
export async function listTabularParts(entityName) {
|
|
253
|
+
const result = await makeRequest("GET", `/api/core/schema/${entityName}/tabular-parts`);
|
|
254
|
+
return jsonResponse(result);
|
|
255
|
+
}
|
|
256
|
+
/** Parse a tool's JSON-string return back to data (for nesting in a response). */
|
|
257
|
+
function _parseMaybe(result) {
|
|
258
|
+
if (typeof result !== "string") {
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
return JSON.parse(result);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** Return the numeric id of a field on an entity, or None if absent. */
|
|
269
|
+
async function _fieldId(entityName, fieldName) {
|
|
270
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
271
|
+
for (const f of _extractFields(schema)) {
|
|
272
|
+
if (f.name === fieldName) {
|
|
273
|
+
return f.id;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Make `field_name` the entity's representative (display-title) field.
|
|
280
|
+
*
|
|
281
|
+
* Uses ``POST /api/core/builder/{entity}/update`` with
|
|
282
|
+
* ``{"representativeField": {"id": <fieldId>}}``. CAVEAT: in live testing this
|
|
283
|
+
* endpoint was unreliable — it set the representative on some entities but
|
|
284
|
+
* returned HTTP 500 on others — so the error is surfaced (not swallowed) and
|
|
285
|
+
* callers must treat it as best-effort. The schema read is eventually-
|
|
286
|
+
* consistent, so confirmation polls up to ``verify_tries`` times. Returns
|
|
287
|
+
* ``[confirmed, representative_value, error_or_None]``.
|
|
288
|
+
*/
|
|
289
|
+
async function _setRepresentative(entityName, fieldName, verifyTries = 1) {
|
|
290
|
+
const fid = await _fieldId(entityName, fieldName);
|
|
291
|
+
if (fid === null || fid === undefined) {
|
|
292
|
+
return [false, null, `field '${fieldName}' not found on '${entityName}'`];
|
|
293
|
+
}
|
|
294
|
+
let error = null;
|
|
295
|
+
try {
|
|
296
|
+
await makeRequest("POST", `/api/core/builder/${entityName}/update`, {
|
|
297
|
+
representativeField: { id: fid },
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
catch (ex) {
|
|
301
|
+
error = ex instanceof Error ? ex.message : String(ex);
|
|
302
|
+
}
|
|
303
|
+
let rep = null;
|
|
304
|
+
const tries = Math.max(1, verifyTries);
|
|
305
|
+
for (let i = 0; i < tries; i++) {
|
|
306
|
+
let schema;
|
|
307
|
+
try {
|
|
308
|
+
schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
309
|
+
}
|
|
310
|
+
catch (ex) {
|
|
311
|
+
error = error || (ex instanceof Error ? ex.message : String(ex));
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
rep =
|
|
315
|
+
schema !== null && typeof schema === "object" && !Array.isArray(schema)
|
|
316
|
+
? schema.representativeField
|
|
317
|
+
: null;
|
|
318
|
+
if (rep !== null && typeof rep === "object" && !Array.isArray(rep) && rep.id === fid) {
|
|
319
|
+
return [true, rep, null];
|
|
320
|
+
}
|
|
321
|
+
if (i + 1 < tries) {
|
|
322
|
+
await sleep(2000);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return [false, rep, error];
|
|
326
|
+
}
|
|
327
|
+
function sleep(ms) {
|
|
328
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Make `field_name` the entity's display-title (representative) field.
|
|
332
|
+
*
|
|
333
|
+
* Creates the field (multi-language) if it is missing, then makes a BEST-EFFORT
|
|
334
|
+
* attempt to set it as the entity's representative via the builder update
|
|
335
|
+
* endpoint. That endpoint proved unreliable in live testing (HTTP 500 on some
|
|
336
|
+
* entities), so a failure here does not raise — it is reported in the result,
|
|
337
|
+
* and the field is still created. Set the representative in the UI if the API
|
|
338
|
+
* attempt fails.
|
|
339
|
+
*/
|
|
340
|
+
export async function setTitleField(entityName, fieldName) {
|
|
341
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
342
|
+
const existing = new Set(_extractFields(schema).map((f) => f.name));
|
|
343
|
+
let created = null;
|
|
344
|
+
if (!existing.has(fieldName)) {
|
|
345
|
+
created = _parseMaybe(await addField(entityName, fieldName, "multi-language", fieldName));
|
|
346
|
+
}
|
|
347
|
+
const [confirmed, rep, error] = await _setRepresentative(entityName, fieldName, 5);
|
|
348
|
+
let note = null;
|
|
349
|
+
if (!confirmed) {
|
|
350
|
+
note =
|
|
351
|
+
"Representative not confirmed via API — the builder update endpoint " +
|
|
352
|
+
"is unreliable (often HTTP 500). The field exists; set it as the " +
|
|
353
|
+
"display field in the UI. " +
|
|
354
|
+
(error ? `(error: ${error})` : "");
|
|
355
|
+
}
|
|
356
|
+
return jsonResponse({
|
|
357
|
+
entity: entityName,
|
|
358
|
+
title_field: fieldName,
|
|
359
|
+
field_created: created,
|
|
360
|
+
representative_set: confirmed,
|
|
361
|
+
representative_value: rep,
|
|
362
|
+
error,
|
|
363
|
+
note,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Add a field to an existing entity.
|
|
368
|
+
*
|
|
369
|
+
* field_type: a real Suppa 2.0 type — text, numeric, integer, serial, boolean,
|
|
370
|
+
* timestamp, json, uuid, multi-language, icon, enum, multi-enum, file, multi-file,
|
|
371
|
+
* one-to-many, many-to-one, many-to-many, many-to-many-backref.
|
|
372
|
+
* There is NO date/datetime/richtext/email/url/phone/string type:
|
|
373
|
+
* - date-only → field_type='timestamp' with sub_type='date'
|
|
374
|
+
* - localized → field_type='multi-language'
|
|
375
|
+
* The legacy alias 'relation' is accepted and mapped to 'many-to-one'.
|
|
376
|
+
* For relation fields, provide relation_entity. For enum fields, provide enum_name.
|
|
377
|
+
* Constraints: max_length/min_length (text), decimal_places (numeric),
|
|
378
|
+
* min_value/max_value/only_positive (numeric).
|
|
379
|
+
*/
|
|
380
|
+
export async function addField(entityName, fieldName, fieldType, title, opts = {}) {
|
|
381
|
+
const { required = false, unique = false, relationEntity = null, enumName = null, subType = null, maxLength = null, minLength = null, decimalPlaces = null, minValue = null, maxValue = null, onlyPositive = false, } = opts;
|
|
382
|
+
// The platform has no relation type literally called "relation"; a foreign
|
|
383
|
+
// key is "many-to-one" with the target entity in `relationTarget`.
|
|
384
|
+
let resolvedType = fieldType === "relation" ? "many-to-one" : fieldType;
|
|
385
|
+
if (relationEntity && !RELATION_FIELD_TYPES.includes(resolvedType)) {
|
|
386
|
+
resolvedType = "many-to-one";
|
|
387
|
+
}
|
|
388
|
+
// Validate client-side: the builder's own errors for these are opaque.
|
|
389
|
+
if (!VALID_FIELD_TYPES.includes(resolvedType)) {
|
|
390
|
+
return jsonResponse({
|
|
391
|
+
error: `Unknown field_type '${fieldType}'. There is no date/datetime/` +
|
|
392
|
+
"richtext/email/url/phone/string type — use 'timestamp' " +
|
|
393
|
+
"(+sub_type='date' for date-only) or 'multi-language'.",
|
|
394
|
+
valid_types: [...VALID_FIELD_TYPES],
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
if (RELATION_FIELD_TYPES.includes(resolvedType) && !relationEntity) {
|
|
398
|
+
return jsonResponse({
|
|
399
|
+
error: `Field type '${resolvedType}' is a relation — pass relation_entity ` +
|
|
400
|
+
"with the target entity name (e.g. relation_entity='Users').",
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if ((resolvedType === "enum" || resolvedType === "multi-enum") && !enumName) {
|
|
404
|
+
return jsonResponse({
|
|
405
|
+
error: `Field type '${resolvedType}' requires enum_name — the qualified ` +
|
|
406
|
+
`'${entityName}.${fieldName}'-style enum key. Create its values ` +
|
|
407
|
+
"with suppa_add_enum_values.",
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
const fieldDef = {
|
|
411
|
+
name: fieldName,
|
|
412
|
+
type: resolvedType,
|
|
413
|
+
title: isPlainObject(title) ? title : { en: title || fieldName },
|
|
414
|
+
required,
|
|
415
|
+
unique,
|
|
416
|
+
};
|
|
417
|
+
if (subType) {
|
|
418
|
+
fieldDef.subType = subType;
|
|
419
|
+
}
|
|
420
|
+
// max_length / min_length of 0 means "no limit" in the source — omit them.
|
|
421
|
+
if (maxLength !== null && maxLength !== undefined && maxLength > 0) {
|
|
422
|
+
fieldDef.maxLength = maxLength;
|
|
423
|
+
}
|
|
424
|
+
if (minLength !== null && minLength !== undefined && minLength > 0) {
|
|
425
|
+
fieldDef.minLength = minLength;
|
|
426
|
+
}
|
|
427
|
+
if (decimalPlaces !== null && decimalPlaces !== undefined) {
|
|
428
|
+
fieldDef.decimalPlaces = decimalPlaces;
|
|
429
|
+
}
|
|
430
|
+
if (minValue !== null && minValue !== undefined) {
|
|
431
|
+
fieldDef.minValue = minValue;
|
|
432
|
+
}
|
|
433
|
+
if (maxValue !== null && maxValue !== undefined) {
|
|
434
|
+
fieldDef.maxValue = maxValue;
|
|
435
|
+
}
|
|
436
|
+
if (onlyPositive) {
|
|
437
|
+
fieldDef.isOnlyPositive = true;
|
|
438
|
+
}
|
|
439
|
+
if (relationEntity) {
|
|
440
|
+
fieldDef.relationTarget = relationEntity;
|
|
441
|
+
}
|
|
442
|
+
if (enumName) {
|
|
443
|
+
fieldDef.enumName = enumName;
|
|
444
|
+
}
|
|
445
|
+
// Correct endpoint is /builder/{Entity}/add-fields and the body is the bare
|
|
446
|
+
// array of field defs (the old /builder/add-fields with an {entityName,fields}
|
|
447
|
+
// wrapper 404s).
|
|
448
|
+
const result = await makeRequest("POST", `/api/core/builder/${entityName}/add-fields`, [
|
|
449
|
+
fieldDef,
|
|
450
|
+
]);
|
|
451
|
+
return jsonResponse(result);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Add values to an enum (lookup table). values: comma-separated list of values to add.
|
|
455
|
+
*
|
|
456
|
+
* enum_name must be the qualified ``Entity.field`` key (e.g. ``Receipts.type``).
|
|
457
|
+
* Values that already exist in the enum are skipped, so a retried call can't
|
|
458
|
+
* create duplicate rows.
|
|
459
|
+
*/
|
|
460
|
+
export async function addEnumValues(enumName, values) {
|
|
461
|
+
const valueList = values
|
|
462
|
+
.split(",")
|
|
463
|
+
.map((v) => v.trim())
|
|
464
|
+
.filter((v) => v);
|
|
465
|
+
if (valueList.length === 0) {
|
|
466
|
+
return jsonResponse({ error: "No values provided — pass a comma-separated list." });
|
|
467
|
+
}
|
|
468
|
+
const existingRows = await searchEntity("Enums", [makeFilter("name", enumName)], { id: true, value: true }, 1000);
|
|
469
|
+
const existing = new Set(existingRows
|
|
470
|
+
.filter((r) => r !== null && typeof r === "object")
|
|
471
|
+
.map((r) => String(r.value)));
|
|
472
|
+
const newValues = valueList.filter((v) => !existing.has(v));
|
|
473
|
+
const skipped = valueList.filter((v) => existing.has(v));
|
|
474
|
+
let result = [];
|
|
475
|
+
if (newValues.length > 0) {
|
|
476
|
+
// The /api/core/data-bulk/{entity} endpoint returns 201 but silently
|
|
477
|
+
// persists nothing; the regular insert action actually stores the batch.
|
|
478
|
+
result = await insertEntity("Enums", newValues.map((v) => ({ name: enumName, value: v })));
|
|
479
|
+
}
|
|
480
|
+
return jsonResponse({
|
|
481
|
+
added: newValues,
|
|
482
|
+
skipped_existing: skipped,
|
|
483
|
+
result,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* List the real Suppa 2.0 builder field types.
|
|
488
|
+
*
|
|
489
|
+
* Note: 2.0 has no date/datetime/richtext/email/url/phone/string type —
|
|
490
|
+
* use timestamp(+subType='date') for dates and multi-language for localized text.
|
|
491
|
+
*/
|
|
492
|
+
export async function listFieldTypes() {
|
|
493
|
+
const types = [
|
|
494
|
+
{ type: "text", description: "Single-/multi-line text (max_length/min_length optional)" },
|
|
495
|
+
{ type: "integer", description: "Whole number" },
|
|
496
|
+
{
|
|
497
|
+
type: "numeric",
|
|
498
|
+
description: "Decimal number (decimal_places/min_value/max_value optional)",
|
|
499
|
+
},
|
|
500
|
+
{ type: "serial", description: "Auto-incrementing integer" },
|
|
501
|
+
{ type: "boolean", description: "True/false" },
|
|
502
|
+
{ type: "timestamp", description: "Date+time; for date-only set sub_type='date'" },
|
|
503
|
+
{ type: "multi-language", description: "Localized text object ({en, uk, ...})" },
|
|
504
|
+
{ type: "json", description: "JSON object/array" },
|
|
505
|
+
{ type: "uuid", description: "UUID value" },
|
|
506
|
+
{ type: "icon", description: "Icon reference" },
|
|
507
|
+
{ type: "enum", description: "Single lookup value (requires enum_name)" },
|
|
508
|
+
{ type: "multi-enum", description: "Multiple lookup values" },
|
|
509
|
+
{
|
|
510
|
+
type: "many-to-one",
|
|
511
|
+
description: "Relation: many records → one target (requires relation_entity)",
|
|
512
|
+
},
|
|
513
|
+
{ type: "one-to-many", description: "Relation: one record → many targets" },
|
|
514
|
+
{ type: "many-to-many", description: "Relation: many ↔ many" },
|
|
515
|
+
{ type: "many-to-many-backref", description: "Back-reference side of a many-to-many" },
|
|
516
|
+
{ type: "file", description: "Single file attachment" },
|
|
517
|
+
{ type: "multi-file", description: "Multiple file attachments" },
|
|
518
|
+
];
|
|
519
|
+
return jsonResponse(types);
|
|
520
|
+
}
|
|
521
|
+
// Field types whose values MUST be reference objects. A bare number/string for
|
|
522
|
+
// these returns HTTP 201 but the platform silently stores NULL (verified live
|
|
523
|
+
// via scripts/silent_error_probe.py) — the worst failure mode an agent can hit.
|
|
524
|
+
const _SINGLE_REF_TYPES = ["enum", "many-to-one"];
|
|
525
|
+
const _MULTI_REF_TYPES = [
|
|
526
|
+
"multi-enum",
|
|
527
|
+
"many-to-many",
|
|
528
|
+
"many-to-many-backref",
|
|
529
|
+
"one-to-many",
|
|
530
|
+
];
|
|
531
|
+
/**
|
|
532
|
+
* Detect relation/enum values the platform would silently store as NULL.
|
|
533
|
+
*
|
|
534
|
+
* Conservative on purpose: only flags values whose field type is positively
|
|
535
|
+
* identified as a reference type AND whose shape is definitely wrong. If the
|
|
536
|
+
* schema can't be read, validation is skipped — never block a write on a
|
|
537
|
+
* transient schema error.
|
|
538
|
+
*/
|
|
539
|
+
async function _refShapeProblems(entityName, fields) {
|
|
540
|
+
let defs;
|
|
541
|
+
try {
|
|
542
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
543
|
+
defs = _extractFields(schema);
|
|
544
|
+
}
|
|
545
|
+
catch {
|
|
546
|
+
return [];
|
|
547
|
+
}
|
|
548
|
+
const types = {};
|
|
549
|
+
for (const f of defs) {
|
|
550
|
+
if (f.name) {
|
|
551
|
+
types[f.name] = String(f.type ?? "").trim().toLowerCase().replace(/_/g, "-");
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const isRef = (v) => v !== null &&
|
|
555
|
+
typeof v === "object" &&
|
|
556
|
+
!Array.isArray(v) &&
|
|
557
|
+
v.id !== null &&
|
|
558
|
+
v.id !== undefined;
|
|
559
|
+
const problems = [];
|
|
560
|
+
for (const [key, val] of Object.entries(fields)) {
|
|
561
|
+
const ftype = types[key] || "";
|
|
562
|
+
if (val === null) {
|
|
563
|
+
// explicit clear is fine
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
if (_SINGLE_REF_TYPES.includes(ftype) && !isRef(val)) {
|
|
567
|
+
problems.push(`'${key}' is a ${ftype} field — write it as {"id": N} ` +
|
|
568
|
+
`(got ${_truncJson(val)}). A bare value ` +
|
|
569
|
+
"returns 201 but the platform silently stores NULL.");
|
|
570
|
+
}
|
|
571
|
+
else if (_MULTI_REF_TYPES.includes(ftype) &&
|
|
572
|
+
!(isRef(val) || (Array.isArray(val) && val.every((x) => isRef(x))))) {
|
|
573
|
+
problems.push(`'${key}' is a ${ftype} field — write it as [{"id": N}, ...] ` +
|
|
574
|
+
`(got ${_truncJson(val)}).`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return problems;
|
|
578
|
+
}
|
|
579
|
+
/** JSON-encode a value non-ASCII-literal and truncate to 60 chars (Python json.dumps[:60]). */
|
|
580
|
+
function _truncJson(val) {
|
|
581
|
+
return jsonResponse(val).slice(0, 60);
|
|
582
|
+
}
|
|
583
|
+
async function _refuseSilentNull(entityName, fields) {
|
|
584
|
+
const problems = await _refShapeProblems(entityName, fields);
|
|
585
|
+
if (problems.length > 0) {
|
|
586
|
+
return jsonResponse({
|
|
587
|
+
error: "Refused: these values would be SILENTLY stored as NULL by the platform.",
|
|
588
|
+
problems,
|
|
589
|
+
hint: "Look up ids via suppa_search_records (Enums for enum values; the " +
|
|
590
|
+
'target entity for relations), then re-send as {"id": N}.',
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Create a new record in any entity. fields_json: JSON object of field values.
|
|
597
|
+
*
|
|
598
|
+
* Relation/enum values are shape-checked against the schema first — a bare
|
|
599
|
+
* number/string for those fields is refused with guidance, because the
|
|
600
|
+
* platform would return 201 and silently store NULL.
|
|
601
|
+
*/
|
|
602
|
+
export async function createRecord(entityName, fieldsJson) {
|
|
603
|
+
let fields;
|
|
604
|
+
try {
|
|
605
|
+
fields = parseJsonParam(fieldsJson, "fields_json", "object");
|
|
606
|
+
}
|
|
607
|
+
catch (e) {
|
|
608
|
+
return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
|
|
609
|
+
}
|
|
610
|
+
const refusal = await _refuseSilentNull(entityName, fields);
|
|
611
|
+
if (refusal) {
|
|
612
|
+
return refusal;
|
|
613
|
+
}
|
|
614
|
+
const result = await insertEntity(entityName, [fields]);
|
|
615
|
+
return jsonResponse(result && result.length ? result[0] : null);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Update a record in any entity. fields_json: JSON object of field values to update.
|
|
619
|
+
*
|
|
620
|
+
* Relation/enum values are shape-checked against the schema first (see
|
|
621
|
+
* create_record) — malformed shapes are refused instead of silently nulled.
|
|
622
|
+
* Returns an explicit status: {updated:true, id, entity, changedFields} on
|
|
623
|
+
* success, or {updated:false, reason} when the platform reports no change.
|
|
624
|
+
*/
|
|
625
|
+
export async function updateRecord(entityName, recordId, fieldsJson) {
|
|
626
|
+
let fields;
|
|
627
|
+
try {
|
|
628
|
+
fields = parseJsonParam(fieldsJson, "fields_json", "object");
|
|
629
|
+
}
|
|
630
|
+
catch (e) {
|
|
631
|
+
return jsonResponse({ error: e instanceof Error ? e.message : String(e) });
|
|
632
|
+
}
|
|
633
|
+
const refusal = await _refuseSilentNull(entityName, fields);
|
|
634
|
+
if (refusal) {
|
|
635
|
+
return refusal;
|
|
636
|
+
}
|
|
637
|
+
const result = await updateEntity(entityName, recordId, fields);
|
|
638
|
+
if (!result || (Array.isArray(result) && result.length === 0)) {
|
|
639
|
+
return jsonResponse({
|
|
640
|
+
updated: false,
|
|
641
|
+
id: recordId,
|
|
642
|
+
entity: entityName,
|
|
643
|
+
reason: "Platform returned no row — record id may not exist, be " +
|
|
644
|
+
"deleted, or the values matched the stored ones (no-op).",
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
return jsonResponse({
|
|
648
|
+
updated: true,
|
|
649
|
+
id: recordId,
|
|
650
|
+
entity: entityName,
|
|
651
|
+
changedFields: Object.keys(fields),
|
|
652
|
+
result: Array.isArray(result) && result.length ? result[0] : result,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Pull the field list out of an entity schema, tolerant of response shape.
|
|
657
|
+
*
|
|
658
|
+
* The schema endpoint may return the field list directly, or a dict carrying it
|
|
659
|
+
* under ``fields``/``properties``/``columns``, or a name→def mapping.
|
|
660
|
+
*/
|
|
661
|
+
function _extractFields(schema) {
|
|
662
|
+
if (Array.isArray(schema)) {
|
|
663
|
+
return schema.filter((f) => f !== null && typeof f === "object" && !Array.isArray(f));
|
|
664
|
+
}
|
|
665
|
+
if (schema !== null && typeof schema === "object") {
|
|
666
|
+
const obj = schema;
|
|
667
|
+
for (const key of ["fields", "properties", "columns"]) {
|
|
668
|
+
const val = obj[key];
|
|
669
|
+
if (Array.isArray(val)) {
|
|
670
|
+
return val.filter((f) => f !== null && typeof f === "object" && !Array.isArray(f));
|
|
671
|
+
}
|
|
672
|
+
if (val !== null && typeof val === "object") {
|
|
673
|
+
// name -> definition mapping
|
|
674
|
+
const out = [];
|
|
675
|
+
for (const [name, fdef] of Object.entries(val)) {
|
|
676
|
+
if (fdef !== null && typeof fdef === "object" && !Array.isArray(fdef)) {
|
|
677
|
+
const d = fdef;
|
|
678
|
+
out.push({ ...d, name: d.name ?? name });
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return out;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return [];
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Names of file-type fields, definite matches first.
|
|
689
|
+
*
|
|
690
|
+
* A field is a definite match when its type is exactly ``file``/``multi-file``;
|
|
691
|
+
* we also accept any other type ending in ``file`` as a tolerant fallback.
|
|
692
|
+
*/
|
|
693
|
+
function _fileFields(fields) {
|
|
694
|
+
const definite = [];
|
|
695
|
+
const fuzzy = [];
|
|
696
|
+
for (const f of fields) {
|
|
697
|
+
const name = f.name;
|
|
698
|
+
if (!name) {
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
const ftype = String(f.type ?? "").trim().toLowerCase().replace(/_/g, "-");
|
|
702
|
+
if (FILE_FIELD_TYPES.includes(ftype)) {
|
|
703
|
+
definite.push(name);
|
|
704
|
+
}
|
|
705
|
+
else if (ftype.endsWith("file")) {
|
|
706
|
+
fuzzy.push(name);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return [...definite, ...fuzzy];
|
|
710
|
+
}
|
|
711
|
+
/** Resolve an entity's numeric id (per-tenant) from its schema or the list. */
|
|
712
|
+
async function _resolveEntityId(entityName, schema) {
|
|
713
|
+
if (schema !== null && typeof schema === "object" && !Array.isArray(schema)) {
|
|
714
|
+
const id = schema.id;
|
|
715
|
+
if (id !== null && id !== undefined) {
|
|
716
|
+
const n = Number(id);
|
|
717
|
+
if (!Number.isNaN(n)) {
|
|
718
|
+
return Math.trunc(n);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const listing = await makeRequest("GET", "/api/core/schema");
|
|
723
|
+
if (Array.isArray(listing)) {
|
|
724
|
+
for (const e of listing) {
|
|
725
|
+
if (e !== null &&
|
|
726
|
+
typeof e === "object" &&
|
|
727
|
+
!Array.isArray(e) &&
|
|
728
|
+
String(e.name ?? "") === entityName &&
|
|
729
|
+
e.id !== null &&
|
|
730
|
+
e.id !== undefined) {
|
|
731
|
+
const n = Number(e.id);
|
|
732
|
+
return Number.isNaN(n) ? null : Math.trunc(n);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Upload a local file and attach it to a record (instance) of any entity.
|
|
740
|
+
*
|
|
741
|
+
* Detects the entity's file/attachment field automatically: if ``field_name`` is
|
|
742
|
+
* omitted it inspects the schema and uses the single file-type field (``file`` or
|
|
743
|
+
* ``multi-file``). When several file fields exist you must pass ``field_name``.
|
|
744
|
+
* Provide the absolute ``file_path``.
|
|
745
|
+
*/
|
|
746
|
+
export async function attachFileToRecord(entityName, recordId, filePath, fieldName) {
|
|
747
|
+
if (!(existsSync(filePath) && statSync(filePath).isFile())) {
|
|
748
|
+
return jsonResponse({ error: `File not found: ${filePath}` });
|
|
749
|
+
}
|
|
750
|
+
const schema = await makeRequest("GET", `/api/core/schema/${entityName}`);
|
|
751
|
+
const fields = _extractFields(schema);
|
|
752
|
+
if (fields.length === 0) {
|
|
753
|
+
return jsonResponse({ error: `Could not read schema for entity '${entityName}'.` });
|
|
754
|
+
}
|
|
755
|
+
const fileFieldNames = _fileFields(fields);
|
|
756
|
+
if (fieldName) {
|
|
757
|
+
if (!new Set(fields.map((f) => f.name)).has(fieldName)) {
|
|
758
|
+
return jsonResponse({
|
|
759
|
+
error: `Field '${fieldName}' does not exist on '${entityName}'.`,
|
|
760
|
+
file_fields_available: fileFieldNames,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
if (fileFieldNames.length === 0) {
|
|
766
|
+
return jsonResponse({
|
|
767
|
+
error: `Entity '${entityName}' has no file/attachment field to attach to. ` +
|
|
768
|
+
"Add a 'file' or 'multi-file' field first (suppa_add_field).",
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
if (fileFieldNames.length > 1) {
|
|
772
|
+
return jsonResponse({
|
|
773
|
+
error: `Entity '${entityName}' has multiple file fields; specify field_name.`,
|
|
774
|
+
file_fields_available: fileFieldNames,
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
fieldName = fileFieldNames[0];
|
|
778
|
+
}
|
|
779
|
+
const entityId = await _resolveEntityId(entityName, schema);
|
|
780
|
+
if (entityId === null) {
|
|
781
|
+
return jsonResponse({ error: `Could not resolve numeric id for entity '${entityName}'.` });
|
|
782
|
+
}
|
|
783
|
+
const meta = {
|
|
784
|
+
entityId,
|
|
785
|
+
recordId: Math.trunc(recordId),
|
|
786
|
+
entityFieldName: fieldName,
|
|
787
|
+
entityName,
|
|
788
|
+
type: null,
|
|
789
|
+
};
|
|
790
|
+
// Keep the error contract consistent with the validation branches above: a
|
|
791
|
+
// failed build (too large) or upload (HTTP/connection error raised by
|
|
792
|
+
// make_request_raw_bytes) returns a structured error rather than throwing.
|
|
793
|
+
try {
|
|
794
|
+
const { body, contentType } = buildFileUpload(meta, filePath);
|
|
795
|
+
const result = await makeRequestRawBytes("POST", "/api/core/files/upload", body, contentType);
|
|
796
|
+
return jsonResponse({
|
|
797
|
+
status: "ok",
|
|
798
|
+
entity: entityName,
|
|
799
|
+
record_id: Math.trunc(recordId),
|
|
800
|
+
field: fieldName,
|
|
801
|
+
file: basename(filePath),
|
|
802
|
+
result,
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
catch (e) {
|
|
806
|
+
return jsonResponse({
|
|
807
|
+
error: `Upload failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
808
|
+
entity: entityName,
|
|
809
|
+
record_id: Math.trunc(recordId),
|
|
810
|
+
field: fieldName,
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Delete a record (instance) from any entity.
|
|
816
|
+
*
|
|
817
|
+
* Removes a single instance, NOT the entity/schema. By design this module is
|
|
818
|
+
* add-only at the schema level (create_entity / add_field / add_enum_values) —
|
|
819
|
+
* there is no update-entity or remove-field operation, so fields can only be
|
|
820
|
+
* removed manually via the Suppa UI. Do not add one here.
|
|
821
|
+
*/
|
|
822
|
+
export async function deleteRecord(entityName, recordId) {
|
|
823
|
+
const result = await removeEntity(entityName, [makeFilter("id", recordId)]);
|
|
824
|
+
return jsonResponse(result);
|
|
825
|
+
}
|
|
826
|
+
// ---------------------------------------------------------------------------
|
|
827
|
+
// helpers
|
|
828
|
+
// ---------------------------------------------------------------------------
|
|
829
|
+
function isPlainObject(v) {
|
|
830
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
831
|
+
}
|