@sfxcode/nuxt-ui-mongocamp 1.3.0 → 1.3.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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +6 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +390 -0
  5. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +6 -0
  6. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +11 -1
  7. package/dist/runtime/components/MongocampBulkDelete.vue +1 -0
  8. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +11 -1
  9. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +29 -0
  10. package/dist/runtime/components/MongocampBulkEdit.vue +138 -0
  11. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +29 -0
  12. package/dist/runtime/components/MongocampCollectionData.vue +100 -1
  13. package/dist/runtime/components/MongocampCollectionInfos.vue +162 -0
  14. package/dist/runtime/components/MongocampFilterBuilder.d.vue.ts +1 -0
  15. package/dist/runtime/components/MongocampFilterBuilder.vue +33 -2
  16. package/dist/runtime/components/MongocampFilterBuilder.vue.d.ts +1 -0
  17. package/dist/runtime/components/MongocampImport.d.vue.ts +10 -0
  18. package/dist/runtime/components/MongocampImport.vue +479 -0
  19. package/dist/runtime/components/MongocampImport.vue.d.ts +10 -0
  20. package/dist/runtime/components/MongocampRoleGrants.vue +25 -0
  21. package/dist/runtime/components/MongocampRoles.vue +74 -0
  22. package/dist/runtime/composables/useMongocampAggregation.d.ts +28 -0
  23. package/dist/runtime/composables/useMongocampAggregation.js +99 -0
  24. package/dist/runtime/composables/useMongocampBulkDelete.d.ts +1 -1
  25. package/dist/runtime/composables/useMongocampImport.d.ts +14 -0
  26. package/dist/runtime/composables/useMongocampImport.js +25 -0
  27. package/dist/runtime/locales/de.json +147 -2
  28. package/dist/runtime/locales/en.json +147 -2
  29. package/dist/runtime/utils/aggregationErrors.d.ts +10 -0
  30. package/dist/runtime/utils/aggregationErrors.js +17 -0
  31. package/dist/runtime/utils/aggregationPipeline.d.ts +42 -0
  32. package/dist/runtime/utils/aggregationPipeline.js +118 -0
  33. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  34. package/dist/runtime/utils/aggregationResult.js +17 -0
  35. package/dist/runtime/utils/analyzeSamples.d.ts +27 -0
  36. package/dist/runtime/utils/analyzeSamples.js +92 -0
  37. package/dist/runtime/utils/batchInsert.d.ts +22 -0
  38. package/dist/runtime/utils/batchInsert.js +24 -0
  39. package/dist/runtime/utils/bulkDelete.d.ts +6 -1
  40. package/dist/runtime/utils/bulkDelete.js +28 -4
  41. package/dist/runtime/utils/bulkEdit.d.ts +27 -0
  42. package/dist/runtime/utils/bulkEdit.js +45 -0
  43. package/dist/runtime/utils/filterSuggestions.d.ts +8 -0
  44. package/dist/runtime/utils/filterSuggestions.js +15 -0
  45. package/dist/runtime/utils/importPipeline.d.ts +21 -0
  46. package/dist/runtime/utils/importPipeline.js +52 -0
  47. package/dist/runtime/utils/importRows.d.ts +36 -0
  48. package/dist/runtime/utils/importRows.js +228 -0
  49. package/dist/runtime/utils/objectId.d.ts +1 -0
  50. package/dist/runtime/utils/objectId.js +4 -0
  51. package/package.json +2 -2
@@ -0,0 +1,228 @@
1
+ import { isIsoDateTimeString } from "./isoDate.js";
2
+ import { isObjectIdHex } from "./objectId.js";
3
+ export const DEFAULT_IMPORT_LIMITS = { maxRows: 1e4, maxBytes: 5 * 1024 * 1024 };
4
+ const MAX_DEPTH = 64;
5
+ function isPlainObject(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ function stripBom(text) {
9
+ return text.charCodeAt(0) === 65279 ? text.slice(1) : text;
10
+ }
11
+ function fileError(code, message) {
12
+ return { rows: [], errors: [{ rowIndex: -1, code, message }], truncated: false };
13
+ }
14
+ export function parseJsonRows(text, limits = DEFAULT_IMPORT_LIMITS) {
15
+ if (text.length > limits.maxBytes) return fileError("file-too-large", `File is larger than ${limits.maxBytes} bytes`);
16
+ let parsed;
17
+ try {
18
+ parsed = JSON.parse(stripBom(text));
19
+ } catch (e) {
20
+ return fileError("invalid-json", `Invalid JSON: ${e instanceof Error ? e.message : String(e)}`);
21
+ }
22
+ if (!Array.isArray(parsed)) return fileError("not-array", "Expected a JSON array of objects");
23
+ const report = { rows: [], errors: [], truncated: false, sourceIndexes: [] };
24
+ parsed.forEach((item, rowIndex) => {
25
+ if (isPlainObject(item)) {
26
+ report.rows.push(item);
27
+ report.sourceIndexes.push(rowIndex);
28
+ } else report.errors.push({ rowIndex, code: "not-object", message: "Row is not an object" });
29
+ });
30
+ return report;
31
+ }
32
+ function splitCsv(text, delimiter) {
33
+ const records = [];
34
+ let record = [];
35
+ let field = "";
36
+ let inQuotes = false;
37
+ let fieldStart = true;
38
+ for (let i = 0; i < text.length; i++) {
39
+ const ch = text[i];
40
+ if (inQuotes) {
41
+ if (ch === '"') {
42
+ if (text[i + 1] === '"') {
43
+ field += '"';
44
+ i++;
45
+ } else {
46
+ inQuotes = false;
47
+ }
48
+ } else {
49
+ field += ch;
50
+ }
51
+ continue;
52
+ }
53
+ if (ch === '"' && fieldStart) {
54
+ inQuotes = true;
55
+ fieldStart = false;
56
+ } else if (ch === delimiter) {
57
+ record.push(field);
58
+ field = "";
59
+ fieldStart = true;
60
+ } else if (ch === "\r" || ch === "\n") {
61
+ if (ch === "\r" && text[i + 1] === "\n") i++;
62
+ record.push(field);
63
+ records.push(record);
64
+ record = [];
65
+ field = "";
66
+ fieldStart = true;
67
+ } else {
68
+ field += ch;
69
+ fieldStart = false;
70
+ }
71
+ }
72
+ if (inQuotes) return null;
73
+ if (field !== "" || record.length > 0) {
74
+ record.push(field);
75
+ records.push(record);
76
+ }
77
+ return records.filter((r) => !(r.length === 1 && r[0] === ""));
78
+ }
79
+ export function parseCsvRows(text, delimiter = ",", limits = DEFAULT_IMPORT_LIMITS) {
80
+ const fail = (code, message) => ({ rows: [], errors: [{ rowIndex: -1, code, message }], truncated: false });
81
+ if (delimiter.length !== 1 || /["\r\n]/.test(delimiter)) return fail("invalid-delimiter", "Delimiter must be a single character other than a quote or line break");
82
+ if (text.length > limits.maxBytes) return fail("file-too-large", `File is larger than ${limits.maxBytes} bytes`);
83
+ const records = splitCsv(stripBom(text), delimiter);
84
+ if (!records) return fail("invalid-csv", "A quoted field is not closed");
85
+ const [headerRecord, ...dataRecords] = records;
86
+ if (!headerRecord) return fail("invalid-csv", "The file has no header row");
87
+ const columns = headerRecord.map((name) => name.trim());
88
+ if (columns.includes("")) return fail("invalid-header", "The header row has an empty column name");
89
+ const duplicate = columns.find((name, i) => columns.indexOf(name) !== i);
90
+ if (duplicate !== void 0) return fail("invalid-header", `Duplicate column name "${duplicate}"`);
91
+ const report = { rows: [], columns, errors: [], truncated: false, sourceIndexes: [] };
92
+ dataRecords.forEach((fields, rowIndex) => {
93
+ if (fields.length > columns.length) {
94
+ report.errors.push({ rowIndex, code: "field-count", message: `Row has ${fields.length} fields, expected ${columns.length}` });
95
+ return;
96
+ }
97
+ const row = {};
98
+ columns.forEach((name, i) => {
99
+ row[name] = fields[i] ?? "";
100
+ });
101
+ report.rows.push(row);
102
+ report.sourceIndexes.push(rowIndex);
103
+ });
104
+ return report;
105
+ }
106
+ function forbiddenKeyPath(value, path, depth) {
107
+ if (depth > MAX_DEPTH) return { path, tooDeep: true };
108
+ if (Array.isArray(value)) {
109
+ for (let i = 0; i < value.length; i++) {
110
+ const found = forbiddenKeyPath(value[i], `${path}[${i}]`, depth + 1);
111
+ if (found) return found;
112
+ }
113
+ return void 0;
114
+ }
115
+ if (!isPlainObject(value)) return void 0;
116
+ for (const [key, inner] of Object.entries(value)) {
117
+ const keyPath = path ? `${path}.${key}` : key;
118
+ if (key === "__proto__" || key.startsWith("$")) return { path: keyPath, tooDeep: false };
119
+ const found = forbiddenKeyPath(inner, keyPath, depth + 1);
120
+ if (found) return found;
121
+ }
122
+ return void 0;
123
+ }
124
+ export function validateRows(rows, limits = DEFAULT_IMPORT_LIMITS) {
125
+ const report = { rows: [], errors: [], truncated: false, sourceIndexes: [] };
126
+ rows.forEach((row, rowIndex) => {
127
+ if (rowIndex >= limits.maxRows) return;
128
+ if (Object.keys(row).length === 0) {
129
+ report.errors.push({ rowIndex, code: "empty-row", message: "Row has no fields" });
130
+ return;
131
+ }
132
+ if ("_id" in row && !isObjectIdHex(row._id)) {
133
+ report.errors.push({ rowIndex, column: "_id", code: "invalid-id", message: "_id must be a 24-character hex string" });
134
+ return;
135
+ }
136
+ const bad = forbiddenKeyPath(row, "", 0);
137
+ if (bad) {
138
+ report.errors.push(bad.tooDeep ? { rowIndex, column: bad.path, code: "too-deep", message: `Row is nested deeper than ${MAX_DEPTH} levels` } : { rowIndex, column: bad.path, code: "forbidden-key", message: `Key "${bad.path}" is not allowed` });
139
+ return;
140
+ }
141
+ report.rows.push(row);
142
+ report.sourceIndexes.push(rowIndex);
143
+ });
144
+ if (rows.length > limits.maxRows) {
145
+ report.truncated = true;
146
+ report.errors.push({ rowIndex: -1, code: "too-many-rows", message: `Only the first ${limits.maxRows} of ${rows.length} rows are kept` });
147
+ }
148
+ return report;
149
+ }
150
+ const TRUE_VALUES = ["true", "1", "yes"];
151
+ const FALSE_VALUES = ["false", "0", "no"];
152
+ const NUMBER_PATTERN = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
153
+ const INTEGER_PATTERN = /^[+-]?\d+$/;
154
+ function coerceDate(text) {
155
+ if (!isIsoDateTimeString(text)) throw new Error("not an ISO date");
156
+ let iso = text.replace(" ", "T");
157
+ const timePart = iso.split("T")[1];
158
+ if (timePart === void 0) iso += "T00:00:00Z";
159
+ else if (!/(?:Z|[+-]\d{2}:?\d{2})$/.test(timePart)) iso += "Z";
160
+ return new Date(iso).toISOString();
161
+ }
162
+ function coerceValue(text, type) {
163
+ try {
164
+ switch (type) {
165
+ case "number": {
166
+ if (!NUMBER_PATTERN.test(text)) return { error: { code: "invalid-number", message: "Not a number" } };
167
+ const asNumber = Number(text);
168
+ if (!Number.isFinite(asNumber)) return { error: { code: "invalid-number", message: "Number out of range" } };
169
+ if (INTEGER_PATTERN.test(text) && !Number.isSafeInteger(asNumber)) {
170
+ return { error: { code: "unsafe-integer", message: "Integer is beyond \xB1(2^53 \u2212 1) and would lose precision; import it as text" } };
171
+ }
172
+ return { value: asNumber };
173
+ }
174
+ case "boolean": {
175
+ const lower = text.toLowerCase();
176
+ if (TRUE_VALUES.includes(lower)) return { value: true };
177
+ if (FALSE_VALUES.includes(lower)) return { value: false };
178
+ return { error: { code: "invalid-boolean", message: "Expected true/false, 1/0 or yes/no" } };
179
+ }
180
+ case "date-time":
181
+ return { value: coerceDate(text) };
182
+ case "json":
183
+ return { value: JSON.parse(text) };
184
+ default:
185
+ return { value: text };
186
+ }
187
+ } catch (e) {
188
+ const message = e instanceof Error ? e.message : String(e);
189
+ const code = type === "date-time" ? "invalid-date" : "invalid-json-value";
190
+ return { error: { code, message } };
191
+ }
192
+ }
193
+ export function coerceRow(row, columnTypes, options = {}) {
194
+ const result = { row: {}, errors: [] };
195
+ for (const [column, value] of Object.entries(row)) {
196
+ if (typeof value !== "string") {
197
+ result.row[column] = value;
198
+ continue;
199
+ }
200
+ const type = columnTypes[column] ?? "string";
201
+ const text = type === "string" ? value : value.trim();
202
+ if (text === "") {
203
+ if (type === "string" && options.emptyCells === "empty-string") result.row[column] = "";
204
+ continue;
205
+ }
206
+ const { value: converted, error } = coerceValue(text, type);
207
+ if (error) result.errors.push({ column, ...error });
208
+ else result.row[column] = converted;
209
+ }
210
+ return result;
211
+ }
212
+ export function inferColumnTypes(rows, columns) {
213
+ const types = {};
214
+ for (const column of columns) {
215
+ const values = rows.map((row) => row[column]).filter((value) => typeof value === "string" && value.trim() !== "").map((value) => value.trim());
216
+ if (values.length === 0) types[column] = "string";
217
+ else if (values.every((v) => /^(?:true|false|yes|no)$/i.test(v))) types[column] = "boolean";
218
+ else if (values.every(isPlainNumberText)) types[column] = "number";
219
+ else if (values.every(isIsoDateTimeString)) types[column] = "date-time";
220
+ else types[column] = "string";
221
+ }
222
+ return types;
223
+ }
224
+ function isPlainNumberText(text) {
225
+ if (!NUMBER_PATTERN.test(text)) return false;
226
+ if (/^[+-]?0\d/.test(text)) return false;
227
+ return !INTEGER_PATTERN.test(text) || Number.isSafeInteger(Number(text));
228
+ }
@@ -0,0 +1 @@
1
+ export declare function isObjectIdHex(value: unknown): value is string;
@@ -0,0 +1,4 @@
1
+ const OBJECT_ID_PATTERN = /^[0-9a-f]{24}$/i;
2
+ export function isObjectIdHex(value) {
3
+ return typeof value === "string" && OBJECT_ID_PATTERN.test(value);
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-ui-mongocamp",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A Nuxt module that wraps @sfxcode/nuxt-mongocamp-server with ready-made UI components, composables, and a runtime plugin",
5
5
  "repository": "sfxcode/nuxt-ui-mongocamp",
6
6
  "homepage": "https://sfxcode.github.io/nuxt-ui-mongocamp/",
@@ -44,7 +44,7 @@
44
44
  "dev": "npm run dev:prepare && nuxt dev playground",
45
45
  "dev:build": "nuxt build playground",
46
46
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
47
- "release": "npm run lint && npm run test && npm run prepack && changelogen --minor --release && npm publish && git push --follow-tags",
47
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --patch --release && npm publish && git push --follow-tags",
48
48
  "lint": "eslint .",
49
49
  "test": "vitest run --project unit --project components",
50
50
  "test:watch": "vitest watch",