convex-verify 1.0.5 → 1.2.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/README.md +271 -235
- package/dist/core/index.d.mts +14 -85
- package/dist/core/index.d.ts +14 -85
- package/dist/core/index.js +520 -83
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +516 -80
- package/dist/core/index.mjs.map +1 -1
- package/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +386 -233
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +383 -226
- package/dist/index.mjs.map +1 -1
- package/dist/types-B8ZkLuJ2.d.mts +141 -0
- package/dist/types-B8ZkLuJ2.d.ts +141 -0
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/verifyConfig-CTrtqMr_.d.ts +94 -0
- package/dist/verifyConfig-Kn3Ikj00.d.mts +94 -0
- package/package.json +5 -22
- package/dist/configs/index.d.mts +0 -51
- package/dist/configs/index.d.ts +0 -51
- package/dist/configs/index.js +0 -38
- package/dist/configs/index.js.map +0 -1
- package/dist/configs/index.mjs +0 -11
- package/dist/configs/index.mjs.map +0 -1
- package/dist/plugin-BjJ7yjrc.d.ts +0 -141
- package/dist/plugin-mHMV2-SG.d.mts +0 -141
- package/dist/plugins/index.d.mts +0 -85
- package/dist/plugins/index.d.ts +0 -85
- package/dist/plugins/index.js +0 -312
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/index.mjs +0 -284
- package/dist/plugins/index.mjs.map +0 -1
- package/dist/transforms/index.d.mts +0 -38
- package/dist/transforms/index.d.ts +0 -38
- package/dist/transforms/index.js +0 -46
- package/dist/transforms/index.js.map +0 -1
- package/dist/transforms/index.mjs +0 -19
- package/dist/transforms/index.mjs.map +0 -1
- package/dist/types-_64SXyva.d.mts +0 -151
- package/dist/types-_64SXyva.d.ts +0 -151
package/dist/core/index.js
CHANGED
|
@@ -20,101 +20,548 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/core/index.ts
|
|
21
21
|
var core_exports = {};
|
|
22
22
|
__export(core_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
createExtension: () => createExtension2,
|
|
24
|
+
isExtension: () => isExtension2,
|
|
25
25
|
normalizeIndexConfigEntry: () => normalizeIndexConfigEntry,
|
|
26
|
-
|
|
26
|
+
runExtensions: () => runExtensions2,
|
|
27
|
+
stripProtectedPatchColumns: () => stripProtectedPatchColumns,
|
|
27
28
|
verifyConfig: () => verifyConfig
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(core_exports);
|
|
30
31
|
|
|
31
|
-
// src/core/
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// src/core/builtins.ts
|
|
33
|
+
var import_values = require("convex/values");
|
|
34
|
+
|
|
35
|
+
// src/core/types.ts
|
|
36
|
+
function normalizeIndexConfigEntry(entry, defaultIdentifiers = ["_id"]) {
|
|
37
|
+
if (typeof entry === "string") {
|
|
38
|
+
return {
|
|
39
|
+
index: entry,
|
|
40
|
+
identifiers: defaultIdentifiers
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const { index, identifiers, ...rest } = entry;
|
|
44
|
+
return {
|
|
45
|
+
index: String(index),
|
|
46
|
+
identifiers: identifiers?.map(String) ?? defaultIdentifiers,
|
|
47
|
+
...rest
|
|
48
|
+
};
|
|
34
49
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
|
|
51
|
+
// src/utils/helpers.ts
|
|
52
|
+
var getTableIndexes = (schema, tableName) => {
|
|
53
|
+
return schema.tables[tableName][" indexes"]();
|
|
54
|
+
};
|
|
55
|
+
var constructColumnData = (fields, data, {
|
|
56
|
+
allowNullishValue = false,
|
|
57
|
+
allOrNothing = true
|
|
58
|
+
}) => {
|
|
59
|
+
const lengthOfFields = fields.length;
|
|
60
|
+
const columnData = fields.map((_, index) => {
|
|
61
|
+
const column = fields?.[index];
|
|
62
|
+
const value = data?.[column];
|
|
63
|
+
if (!column || !allowNullishValue && (value === void 0 || value === null)) {
|
|
64
|
+
return;
|
|
41
65
|
}
|
|
66
|
+
return {
|
|
67
|
+
column,
|
|
68
|
+
value
|
|
69
|
+
};
|
|
70
|
+
}).filter((e) => !!e);
|
|
71
|
+
if (allOrNothing && columnData.length !== lengthOfFields) {
|
|
72
|
+
return null;
|
|
42
73
|
}
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
74
|
+
return columnData.length > 0 ? columnData : null;
|
|
75
|
+
};
|
|
76
|
+
var constructIndexData = (schema, tableName, indexConfig) => {
|
|
77
|
+
if (!indexConfig) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const tableConfig = indexConfig?.[tableName];
|
|
81
|
+
if (!tableConfig) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return tableConfig.map((entry) => {
|
|
85
|
+
const normalized = normalizeIndexConfigEntry(entry);
|
|
86
|
+
const { index, identifiers, ...rest } = normalized;
|
|
87
|
+
const fields = getTableIndexes(schema, tableName).find(
|
|
88
|
+
(i) => i.indexDescriptor == index
|
|
89
|
+
)?.fields;
|
|
90
|
+
if (!fields) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Error in 'constructIndexData()'. No fields found for index: [${index}]`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const identifierMap = new Map(
|
|
96
|
+
[...identifiers, "_id"].map((i) => [String(i), String(i)])
|
|
97
|
+
);
|
|
98
|
+
return {
|
|
99
|
+
name: index,
|
|
100
|
+
fields,
|
|
101
|
+
identifiers: Array.from(identifierMap.values()),
|
|
102
|
+
...rest
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// src/core/builtins.ts
|
|
108
|
+
var stripProtectedPatchColumns = (protectedColumns, tableName, data) => {
|
|
109
|
+
const protectedKeys = protectedColumns[tableName] ?? [];
|
|
110
|
+
if (protectedKeys.length === 0) {
|
|
111
|
+
return {
|
|
112
|
+
filteredData: data,
|
|
113
|
+
removedColumns: []
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const protectedKeyStrings = protectedKeys.map(String);
|
|
117
|
+
const protectedKeySet = new Set(protectedKeyStrings);
|
|
118
|
+
const removedColumns = protectedKeyStrings.filter((key) => key in data);
|
|
119
|
+
if (removedColumns.length === 0) {
|
|
120
|
+
return {
|
|
121
|
+
filteredData: data,
|
|
122
|
+
removedColumns
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const filteredData = Object.fromEntries(
|
|
126
|
+
Object.entries(data).filter(([key]) => !protectedKeySet.has(key))
|
|
127
|
+
);
|
|
128
|
+
return {
|
|
129
|
+
filteredData,
|
|
130
|
+
removedColumns
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
var buildDefaultValuesVerifier = (config) => {
|
|
134
|
+
const verify = (async (...args) => {
|
|
135
|
+
const input = args.length === 2 ? {
|
|
136
|
+
tableName: args[0],
|
|
137
|
+
operation: "insert",
|
|
138
|
+
data: args[1]
|
|
139
|
+
} : args[0];
|
|
140
|
+
if (input.operation === "patch") {
|
|
141
|
+
return input.data;
|
|
142
|
+
}
|
|
143
|
+
const resolvedConfig = typeof config === "function" ? await config() : config;
|
|
144
|
+
return {
|
|
145
|
+
...resolvedConfig[input.tableName] ?? {},
|
|
146
|
+
...input.data
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
_type: "defaultValues",
|
|
151
|
+
config,
|
|
152
|
+
verify
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
var buildProtectedColumnsVerifier = (config) => {
|
|
156
|
+
const verify = (async (...args) => {
|
|
157
|
+
const input = args.length === 2 ? {
|
|
158
|
+
tableName: args[0],
|
|
159
|
+
operation: "patch",
|
|
160
|
+
data: args[1]
|
|
161
|
+
} : args[0];
|
|
162
|
+
if (input.operation === "insert") {
|
|
163
|
+
return input.data;
|
|
164
|
+
}
|
|
165
|
+
return stripProtectedPatchColumns(config, input.tableName, input.data).filteredData;
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
_type: "protectedColumns",
|
|
169
|
+
config,
|
|
170
|
+
verify
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
var buildUniqueRowVerifier = (schema, config) => {
|
|
174
|
+
const uniqueRowError = (message) => {
|
|
175
|
+
throw new import_values.ConvexError({
|
|
176
|
+
message,
|
|
177
|
+
code: "UNIQUE_ROW_VERIFICATION_ERROR"
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
const verify = (async (...args) => {
|
|
181
|
+
const input = args.length === 3 ? {
|
|
182
|
+
ctx: args[0],
|
|
183
|
+
tableName: args[1],
|
|
184
|
+
operation: "insert",
|
|
185
|
+
data: args[2]
|
|
186
|
+
} : args.length === 4 ? {
|
|
187
|
+
ctx: args[0],
|
|
188
|
+
tableName: args[1],
|
|
189
|
+
operation: "patch",
|
|
190
|
+
patchId: args[2],
|
|
191
|
+
data: args[3]
|
|
192
|
+
} : args[0];
|
|
193
|
+
const { ctx, tableName, operation, patchId, onFail, data } = input;
|
|
194
|
+
const indexesData = constructIndexData(schema, tableName, config);
|
|
195
|
+
if (!indexesData) {
|
|
196
|
+
return data;
|
|
197
|
+
}
|
|
198
|
+
for (const indexInfo of indexesData) {
|
|
199
|
+
const { name, fields, identifiers } = indexInfo;
|
|
200
|
+
if (fields.length < 2) {
|
|
201
|
+
uniqueRowError(
|
|
202
|
+
`Error in 'verifyRowUniqueness()'. There must be two columns to test against. If you are attempting to enforce a unique column, use the 'uniqueColumn' config option.`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
const columnData = constructColumnData(fields, data, {});
|
|
206
|
+
const getExisting = async (cd) => {
|
|
207
|
+
let existingByIndex = [];
|
|
208
|
+
if (cd) {
|
|
209
|
+
existingByIndex = await ctx.db.query(tableName).withIndex(
|
|
210
|
+
name,
|
|
211
|
+
(q) => cd.reduce((query, { column, value }) => query.eq(column, value), q)
|
|
212
|
+
).collect();
|
|
213
|
+
}
|
|
214
|
+
if (existingByIndex.length > 1) {
|
|
215
|
+
console.warn(
|
|
216
|
+
`There was more than one existing result found for index ${name}. Check the following IDs:`,
|
|
217
|
+
existingByIndex.map((row) => row._id)
|
|
218
|
+
);
|
|
219
|
+
console.warn(
|
|
220
|
+
"It is recommended that you triage the rows listed above since they have data that go against a rule of row uniqueness."
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
return existingByIndex.length > 0 ? existingByIndex[0] : null;
|
|
224
|
+
};
|
|
225
|
+
const existing = await getExisting(columnData);
|
|
226
|
+
if (operation === "insert") {
|
|
227
|
+
if (!existing) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
onFail?.({
|
|
231
|
+
uniqueRow: {
|
|
232
|
+
existingData: existing
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
uniqueRowError(
|
|
236
|
+
`Unable to [${operation}] document. In table [${tableName}], there is an existing row that has the same data combination in the columns: [${fields.join(", ")}].`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (!patchId) {
|
|
240
|
+
uniqueRowError("Unable to patch document without an id.");
|
|
241
|
+
}
|
|
242
|
+
const matchedToExisting = (_existing, _data) => {
|
|
243
|
+
let idMatchedToExisting = null;
|
|
244
|
+
if (_existing) {
|
|
245
|
+
for (const identifier of identifiers) {
|
|
246
|
+
if (_existing[identifier] !== void 0 && _data[identifier] !== void 0 && _existing[identifier] === _data[identifier] || identifier === "_id" && _existing[identifier] === patchId) {
|
|
247
|
+
idMatchedToExisting = String(identifier);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return idMatchedToExisting;
|
|
253
|
+
};
|
|
254
|
+
const checkExisting = (_existing, _data) => {
|
|
255
|
+
const matchedId = matchedToExisting(_existing, _data);
|
|
256
|
+
if (!_existing || matchedId) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
onFail?.({
|
|
260
|
+
uniqueRow: {
|
|
261
|
+
existingData: _existing
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
uniqueRowError(
|
|
265
|
+
`In '${tableName}' table, there already exists a value match of the columns: [${fields.join(",")}].`
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
if (!existing && !columnData) {
|
|
269
|
+
const match = await ctx.db.get(patchId);
|
|
270
|
+
if (!match) {
|
|
271
|
+
uniqueRowError(`No document found for id ${patchId}`);
|
|
272
|
+
}
|
|
273
|
+
const extensiveColumnData = constructColumnData(
|
|
274
|
+
fields,
|
|
275
|
+
{
|
|
276
|
+
...match,
|
|
277
|
+
...data
|
|
278
|
+
},
|
|
279
|
+
{}
|
|
280
|
+
);
|
|
281
|
+
if (!extensiveColumnData) {
|
|
282
|
+
uniqueRowError("Incomplete data when there should have been enough.");
|
|
283
|
+
}
|
|
284
|
+
const extensiveExisting = await getExisting(extensiveColumnData);
|
|
285
|
+
checkExisting(extensiveExisting, data);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
checkExisting(existing, data);
|
|
289
|
+
}
|
|
290
|
+
return data;
|
|
291
|
+
});
|
|
292
|
+
return {
|
|
293
|
+
_type: "uniqueRow",
|
|
294
|
+
config,
|
|
295
|
+
verify
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
var buildUniqueColumnVerifier = (config) => {
|
|
299
|
+
const uniqueColumnError = (message) => {
|
|
300
|
+
throw new import_values.ConvexError({
|
|
301
|
+
message,
|
|
302
|
+
code: "UNIQUE_COLUMN_VERIFICATION_ERROR"
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
const verify = (async (...args) => {
|
|
306
|
+
const input = args.length === 3 ? {
|
|
307
|
+
ctx: args[0],
|
|
308
|
+
tableName: args[1],
|
|
309
|
+
operation: "insert",
|
|
310
|
+
data: args[2]
|
|
311
|
+
} : args.length === 4 ? {
|
|
312
|
+
ctx: args[0],
|
|
313
|
+
tableName: args[1],
|
|
314
|
+
operation: "patch",
|
|
315
|
+
patchId: args[2],
|
|
316
|
+
data: args[3]
|
|
317
|
+
} : args[0];
|
|
318
|
+
const { ctx, tableName, patchId, onFail, data } = input;
|
|
319
|
+
const tableConfig = config[tableName];
|
|
320
|
+
if (!tableConfig) {
|
|
321
|
+
return data;
|
|
322
|
+
}
|
|
323
|
+
for (const entry of tableConfig) {
|
|
324
|
+
const { index, identifiers } = normalizeIndexConfigEntry(
|
|
325
|
+
entry
|
|
326
|
+
);
|
|
327
|
+
const columnName = index.replace("by_", "");
|
|
328
|
+
const value = data[columnName];
|
|
329
|
+
if (value === void 0 || value === null) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const existing = await ctx.db.query(tableName).withIndex(index, (q) => q.eq(columnName, value)).unique();
|
|
333
|
+
if (!existing) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
let isOwnDocument = false;
|
|
337
|
+
for (const identifier of identifiers) {
|
|
338
|
+
if (identifier === "_id" && patchId && existing._id === patchId) {
|
|
339
|
+
isOwnDocument = true;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
if (existing[identifier] !== void 0 && data[identifier] !== void 0 && existing[identifier] === data[identifier]) {
|
|
343
|
+
isOwnDocument = true;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (isOwnDocument) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
onFail?.({
|
|
351
|
+
uniqueColumn: {
|
|
352
|
+
conflictingColumn: columnName,
|
|
353
|
+
existingData: existing
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
uniqueColumnError(
|
|
357
|
+
`In [${tableName}] table, there already exists value "${value}" in column [${columnName}].`
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
return data;
|
|
361
|
+
});
|
|
46
362
|
return {
|
|
47
|
-
_type:
|
|
363
|
+
_type: "uniqueColumn",
|
|
48
364
|
config,
|
|
49
365
|
verify
|
|
50
366
|
};
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// src/core/plugin.ts
|
|
370
|
+
function createExtension(schemaOrVerify, verify) {
|
|
371
|
+
const extensionVerify = typeof verify === "function" ? verify : schemaOrVerify;
|
|
372
|
+
return {
|
|
373
|
+
_type: "extension",
|
|
374
|
+
verify(input) {
|
|
375
|
+
return extensionVerify(input);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function isExtension(value) {
|
|
380
|
+
return typeof value === "object" && value !== null && "verify" in value && typeof value.verify === "function";
|
|
381
|
+
}
|
|
382
|
+
async function runExtensions(extensions, input) {
|
|
383
|
+
let verifiedData = input.data;
|
|
384
|
+
for (const extension of extensions) {
|
|
385
|
+
verifiedData = await extension.verify({
|
|
386
|
+
...input,
|
|
387
|
+
data: verifiedData
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return verifiedData;
|
|
51
391
|
}
|
|
52
392
|
|
|
53
393
|
// src/core/verifyConfig.ts
|
|
54
394
|
var verifyConfig = (_schema, configs) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
395
|
+
const builtins = {
|
|
396
|
+
...configs.defaultValues ? {
|
|
397
|
+
defaultValues: buildDefaultValuesVerifier(configs.defaultValues)
|
|
398
|
+
} : {},
|
|
399
|
+
...configs.protectedColumns ? {
|
|
400
|
+
protectedColumns: buildProtectedColumnsVerifier(configs.protectedColumns)
|
|
401
|
+
} : {},
|
|
402
|
+
...configs.uniqueRow ? {
|
|
403
|
+
uniqueRow: buildUniqueRowVerifier(
|
|
404
|
+
_schema,
|
|
405
|
+
configs.uniqueRow
|
|
406
|
+
)
|
|
407
|
+
} : {},
|
|
408
|
+
...configs.uniqueColumn ? {
|
|
409
|
+
uniqueColumn: buildUniqueColumnVerifier(configs.uniqueColumn)
|
|
410
|
+
} : {}
|
|
411
|
+
};
|
|
412
|
+
const verify = {
|
|
413
|
+
...builtins.defaultValues ? { defaultValues: builtins.defaultValues.verify } : {},
|
|
414
|
+
...builtins.protectedColumns ? { protectedColumns: builtins.protectedColumns.verify } : {},
|
|
415
|
+
...builtins.uniqueRow ? { uniqueRow: builtins.uniqueRow.verify } : {},
|
|
416
|
+
...builtins.uniqueColumn ? { uniqueColumn: builtins.uniqueColumn.verify } : {}
|
|
417
|
+
};
|
|
418
|
+
const config = {
|
|
419
|
+
...configs.defaultValues ? { defaultValues: configs.defaultValues } : {},
|
|
420
|
+
...configs.protectedColumns ? { protectedColumns: configs.protectedColumns } : {},
|
|
421
|
+
...configs.uniqueRow ? { uniqueRow: configs.uniqueRow } : {},
|
|
422
|
+
...configs.uniqueColumn ? { uniqueColumn: configs.uniqueColumn } : {}
|
|
423
|
+
};
|
|
424
|
+
const customExtensions = configs.extensions ?? [];
|
|
62
425
|
const insert = async (ctx, tableName, data, options) => {
|
|
63
426
|
let verifiedData = data;
|
|
64
|
-
if (
|
|
65
|
-
verifiedData = await
|
|
427
|
+
if (builtins.defaultValues) {
|
|
428
|
+
verifiedData = await builtins.defaultValues.verify({
|
|
429
|
+
ctx,
|
|
66
430
|
tableName,
|
|
67
|
-
|
|
68
|
-
|
|
431
|
+
operation: "insert",
|
|
432
|
+
onFail: options?.onFail,
|
|
433
|
+
schema: _schema,
|
|
434
|
+
data: verifiedData
|
|
435
|
+
});
|
|
69
436
|
}
|
|
70
|
-
if (
|
|
71
|
-
verifiedData = await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
437
|
+
if (customExtensions.length > 0) {
|
|
438
|
+
verifiedData = await runExtensions(customExtensions, {
|
|
439
|
+
ctx,
|
|
440
|
+
tableName,
|
|
441
|
+
operation: "insert",
|
|
442
|
+
onFail: options?.onFail,
|
|
443
|
+
schema: _schema,
|
|
444
|
+
data: verifiedData
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
if (builtins.uniqueRow) {
|
|
448
|
+
verifiedData = await builtins.uniqueRow.verify({
|
|
449
|
+
ctx,
|
|
450
|
+
tableName,
|
|
451
|
+
operation: "insert",
|
|
452
|
+
onFail: options?.onFail,
|
|
453
|
+
schema: _schema,
|
|
454
|
+
data: verifiedData
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
if (builtins.uniqueColumn) {
|
|
458
|
+
verifiedData = await builtins.uniqueColumn.verify({
|
|
459
|
+
ctx,
|
|
460
|
+
tableName,
|
|
461
|
+
operation: "insert",
|
|
462
|
+
onFail: options?.onFail,
|
|
463
|
+
schema: _schema,
|
|
464
|
+
data: verifiedData
|
|
465
|
+
});
|
|
82
466
|
}
|
|
83
467
|
return await ctx.db.insert(tableName, verifiedData);
|
|
84
468
|
};
|
|
85
469
|
const patch = async (ctx, tableName, id, data, options) => {
|
|
86
470
|
let verifiedData = data;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
onFail: options?.onFail,
|
|
96
|
-
schema: _schema
|
|
97
|
-
},
|
|
471
|
+
const removedProtectedColumns = /* @__PURE__ */ new Set();
|
|
472
|
+
const stripProtectedColumns = () => {
|
|
473
|
+
if (!builtins.protectedColumns) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const filtered = stripProtectedPatchColumns(
|
|
477
|
+
builtins.protectedColumns.config,
|
|
478
|
+
tableName,
|
|
98
479
|
verifiedData
|
|
99
480
|
);
|
|
481
|
+
for (const column of filtered.removedColumns) {
|
|
482
|
+
removedProtectedColumns.add(column);
|
|
483
|
+
}
|
|
484
|
+
verifiedData = filtered.filteredData;
|
|
485
|
+
};
|
|
486
|
+
stripProtectedColumns();
|
|
487
|
+
if (customExtensions.length > 0) {
|
|
488
|
+
verifiedData = await runExtensions(customExtensions, {
|
|
489
|
+
ctx,
|
|
490
|
+
tableName,
|
|
491
|
+
operation: "patch",
|
|
492
|
+
patchId: id,
|
|
493
|
+
onFail: options?.onFail,
|
|
494
|
+
schema: _schema,
|
|
495
|
+
data: verifiedData
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
if (builtins.uniqueRow) {
|
|
499
|
+
verifiedData = await builtins.uniqueRow.verify({
|
|
500
|
+
ctx,
|
|
501
|
+
tableName,
|
|
502
|
+
operation: "patch",
|
|
503
|
+
patchId: id,
|
|
504
|
+
onFail: options?.onFail,
|
|
505
|
+
schema: _schema,
|
|
506
|
+
data: verifiedData
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
if (builtins.uniqueColumn) {
|
|
510
|
+
verifiedData = await builtins.uniqueColumn.verify({
|
|
511
|
+
ctx,
|
|
512
|
+
tableName,
|
|
513
|
+
operation: "patch",
|
|
514
|
+
patchId: id,
|
|
515
|
+
onFail: options?.onFail,
|
|
516
|
+
schema: _schema,
|
|
517
|
+
data: verifiedData
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
stripProtectedColumns();
|
|
521
|
+
if (removedProtectedColumns.size > 0) {
|
|
522
|
+
options?.onFail?.({
|
|
523
|
+
editableColumn: {
|
|
524
|
+
removedColumns: [...removedProtectedColumns],
|
|
525
|
+
filteredData: verifiedData
|
|
526
|
+
}
|
|
527
|
+
});
|
|
100
528
|
}
|
|
101
529
|
await ctx.db.patch(id, verifiedData);
|
|
102
530
|
};
|
|
103
531
|
const dangerouslyPatch = async (ctx, tableName, id, data, options) => {
|
|
104
532
|
let verifiedData = data;
|
|
105
|
-
if (
|
|
106
|
-
verifiedData = await
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
533
|
+
if (customExtensions.length > 0) {
|
|
534
|
+
verifiedData = await runExtensions(customExtensions, {
|
|
535
|
+
ctx,
|
|
536
|
+
tableName,
|
|
537
|
+
operation: "patch",
|
|
538
|
+
patchId: id,
|
|
539
|
+
onFail: options?.onFail,
|
|
540
|
+
schema: _schema,
|
|
541
|
+
data: verifiedData
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
if (builtins.uniqueRow) {
|
|
545
|
+
verifiedData = await builtins.uniqueRow.verify({
|
|
546
|
+
ctx,
|
|
547
|
+
tableName,
|
|
548
|
+
operation: "patch",
|
|
549
|
+
patchId: id,
|
|
550
|
+
onFail: options?.onFail,
|
|
551
|
+
schema: _schema,
|
|
552
|
+
data: verifiedData
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
if (builtins.uniqueColumn) {
|
|
556
|
+
verifiedData = await builtins.uniqueColumn.verify({
|
|
557
|
+
ctx,
|
|
558
|
+
tableName,
|
|
559
|
+
operation: "patch",
|
|
560
|
+
patchId: id,
|
|
561
|
+
onFail: options?.onFail,
|
|
562
|
+
schema: _schema,
|
|
563
|
+
data: verifiedData
|
|
564
|
+
});
|
|
118
565
|
}
|
|
119
566
|
await ctx.db.patch(id, verifiedData);
|
|
120
567
|
};
|
|
@@ -122,32 +569,22 @@ var verifyConfig = (_schema, configs) => {
|
|
|
122
569
|
insert,
|
|
123
570
|
patch,
|
|
124
571
|
dangerouslyPatch,
|
|
125
|
-
|
|
126
|
-
|
|
572
|
+
verify,
|
|
573
|
+
config
|
|
127
574
|
};
|
|
128
575
|
};
|
|
129
576
|
|
|
130
|
-
// src/core/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
index: entry,
|
|
135
|
-
identifiers: defaultIdentifiers
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
const { index, identifiers, ...rest } = entry;
|
|
139
|
-
return {
|
|
140
|
-
index: String(index),
|
|
141
|
-
identifiers: identifiers?.map(String) ?? defaultIdentifiers,
|
|
142
|
-
...rest
|
|
143
|
-
};
|
|
144
|
-
}
|
|
577
|
+
// src/core/index.ts
|
|
578
|
+
var createExtension2 = createExtension;
|
|
579
|
+
var isExtension2 = isExtension;
|
|
580
|
+
var runExtensions2 = runExtensions;
|
|
145
581
|
// Annotate the CommonJS export names for ESM import in node:
|
|
146
582
|
0 && (module.exports = {
|
|
147
|
-
|
|
148
|
-
|
|
583
|
+
createExtension,
|
|
584
|
+
isExtension,
|
|
149
585
|
normalizeIndexConfigEntry,
|
|
150
|
-
|
|
586
|
+
runExtensions,
|
|
587
|
+
stripProtectedPatchColumns,
|
|
151
588
|
verifyConfig
|
|
152
589
|
});
|
|
153
590
|
//# sourceMappingURL=index.js.map
|