convex-verify 1.1.0 → 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 +148 -80
- package/dist/core/index.d.mts +14 -55
- package/dist/core/index.d.ts +14 -55
- package/dist/core/index.js +492 -92
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +491 -92
- 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 +378 -271
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -267
- 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 +1 -16
- 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-BOb1Kw1A.d.ts +0 -47
- package/dist/plugin-DlsboiCF.d.mts +0 -47
- 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-DvJMYubf.d.mts +0 -151
- package/dist/types-DvJMYubf.d.ts +0 -151
package/dist/core/index.js
CHANGED
|
@@ -20,20 +20,359 @@ 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
|
-
createExtension: () =>
|
|
24
|
-
isExtension: () =>
|
|
23
|
+
createExtension: () => createExtension2,
|
|
24
|
+
isExtension: () => isExtension2,
|
|
25
25
|
normalizeIndexConfigEntry: () => normalizeIndexConfigEntry,
|
|
26
|
-
runExtensions: () =>
|
|
26
|
+
runExtensions: () => runExtensions2,
|
|
27
|
+
stripProtectedPatchColumns: () => stripProtectedPatchColumns,
|
|
27
28
|
verifyConfig: () => verifyConfig
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(core_exports);
|
|
30
31
|
|
|
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
|
+
};
|
|
49
|
+
}
|
|
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;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
column,
|
|
68
|
+
value
|
|
69
|
+
};
|
|
70
|
+
}).filter((e) => !!e);
|
|
71
|
+
if (allOrNothing && columnData.length !== lengthOfFields) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
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
|
+
});
|
|
362
|
+
return {
|
|
363
|
+
_type: "uniqueColumn",
|
|
364
|
+
config,
|
|
365
|
+
verify
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
|
|
31
369
|
// src/core/plugin.ts
|
|
32
|
-
function createExtension(verify) {
|
|
370
|
+
function createExtension(schemaOrVerify, verify) {
|
|
371
|
+
const extensionVerify = typeof verify === "function" ? verify : schemaOrVerify;
|
|
33
372
|
return {
|
|
34
373
|
_type: "extension",
|
|
35
374
|
verify(input) {
|
|
36
|
-
return
|
|
375
|
+
return extensionVerify(input);
|
|
37
376
|
}
|
|
38
377
|
};
|
|
39
378
|
}
|
|
@@ -53,53 +392,77 @@ async function runExtensions(extensions, input) {
|
|
|
53
392
|
|
|
54
393
|
// src/core/verifyConfig.ts
|
|
55
394
|
var verifyConfig = (_schema, configs) => {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
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 } : {}
|
|
85
423
|
};
|
|
424
|
+
const customExtensions = configs.extensions ?? [];
|
|
86
425
|
const insert = async (ctx, tableName, data, options) => {
|
|
87
426
|
let verifiedData = data;
|
|
88
|
-
if (
|
|
89
|
-
verifiedData = await
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
427
|
+
if (builtins.defaultValues) {
|
|
428
|
+
verifiedData = await builtins.defaultValues.verify({
|
|
429
|
+
ctx,
|
|
430
|
+
tableName,
|
|
431
|
+
operation: "insert",
|
|
432
|
+
onFail: options?.onFail,
|
|
433
|
+
schema: _schema,
|
|
434
|
+
data: verifiedData
|
|
435
|
+
});
|
|
436
|
+
}
|
|
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
|
+
});
|
|
103
466
|
}
|
|
104
467
|
return await ctx.db.insert(tableName, verifiedData);
|
|
105
468
|
};
|
|
@@ -107,26 +470,52 @@ var verifyConfig = (_schema, configs) => {
|
|
|
107
470
|
let verifiedData = data;
|
|
108
471
|
const removedProtectedColumns = /* @__PURE__ */ new Set();
|
|
109
472
|
const stripProtectedColumns = () => {
|
|
110
|
-
|
|
473
|
+
if (!builtins.protectedColumns) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const filtered = stripProtectedPatchColumns(
|
|
477
|
+
builtins.protectedColumns.config,
|
|
478
|
+
tableName,
|
|
479
|
+
verifiedData
|
|
480
|
+
);
|
|
111
481
|
for (const column of filtered.removedColumns) {
|
|
112
482
|
removedProtectedColumns.add(column);
|
|
113
483
|
}
|
|
114
484
|
verifiedData = filtered.filteredData;
|
|
115
485
|
};
|
|
116
486
|
stripProtectedColumns();
|
|
117
|
-
if (
|
|
118
|
-
verifiedData = await runExtensions(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
});
|
|
130
519
|
}
|
|
131
520
|
stripProtectedColumns();
|
|
132
521
|
if (removedProtectedColumns.size > 0) {
|
|
@@ -141,50 +530,61 @@ var verifyConfig = (_schema, configs) => {
|
|
|
141
530
|
};
|
|
142
531
|
const dangerouslyPatch = async (ctx, tableName, id, data, options) => {
|
|
143
532
|
let verifiedData = data;
|
|
144
|
-
if (
|
|
145
|
-
verifiedData = await runExtensions(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
});
|
|
157
565
|
}
|
|
158
566
|
await ctx.db.patch(id, verifiedData);
|
|
159
567
|
};
|
|
160
568
|
return {
|
|
161
569
|
insert,
|
|
162
570
|
patch,
|
|
163
|
-
dangerouslyPatch
|
|
571
|
+
dangerouslyPatch,
|
|
572
|
+
verify,
|
|
573
|
+
config
|
|
164
574
|
};
|
|
165
575
|
};
|
|
166
576
|
|
|
167
|
-
// src/core/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
index: entry,
|
|
172
|
-
identifiers: defaultIdentifiers
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
const { index, identifiers, ...rest } = entry;
|
|
176
|
-
return {
|
|
177
|
-
index: String(index),
|
|
178
|
-
identifiers: identifiers?.map(String) ?? defaultIdentifiers,
|
|
179
|
-
...rest
|
|
180
|
-
};
|
|
181
|
-
}
|
|
577
|
+
// src/core/index.ts
|
|
578
|
+
var createExtension2 = createExtension;
|
|
579
|
+
var isExtension2 = isExtension;
|
|
580
|
+
var runExtensions2 = runExtensions;
|
|
182
581
|
// Annotate the CommonJS export names for ESM import in node:
|
|
183
582
|
0 && (module.exports = {
|
|
184
583
|
createExtension,
|
|
185
584
|
isExtension,
|
|
186
585
|
normalizeIndexConfigEntry,
|
|
187
586
|
runExtensions,
|
|
587
|
+
stripProtectedPatchColumns,
|
|
188
588
|
verifyConfig
|
|
189
589
|
});
|
|
190
590
|
//# sourceMappingURL=index.js.map
|